]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/contrib/gcc/config/alpha/alpha.c
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / contrib / gcc / config / alpha / alpha.c
1 /* Subroutines used for code generation on the DEC Alpha.
2    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3    2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 
4    Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "regs.h"
31 #include "hard-reg-set.h"
32 #include "real.h"
33 #include "insn-config.h"
34 #include "conditions.h"
35 #include "output.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "recog.h"
39 #include "expr.h"
40 #include "optabs.h"
41 #include "reload.h"
42 #include "obstack.h"
43 #include "except.h"
44 #include "function.h"
45 #include "toplev.h"
46 #include "ggc.h"
47 #include "integrate.h"
48 #include "tm_p.h"
49 #include "target.h"
50 #include "target-def.h"
51 #include "debug.h"
52 #include "langhooks.h"
53 #include <splay-tree.h>
54 #include "cfglayout.h"
55
56 /* Specify which cpu to schedule for.  */
57
58 enum processor_type alpha_cpu;
59 static const char * const alpha_cpu_name[] = 
60 {
61   "ev4", "ev5", "ev6"
62 };
63
64 /* Specify how accurate floating-point traps need to be.  */
65
66 enum alpha_trap_precision alpha_tp;
67
68 /* Specify the floating-point rounding mode.  */
69
70 enum alpha_fp_rounding_mode alpha_fprm;
71
72 /* Specify which things cause traps.  */
73
74 enum alpha_fp_trap_mode alpha_fptm;
75
76 /* Specify bit size of immediate TLS offsets.  */
77
78 int alpha_tls_size = 32;
79
80 /* Strings decoded into the above options.  */
81
82 const char *alpha_cpu_string;   /* -mcpu= */
83 const char *alpha_tune_string;  /* -mtune= */
84 const char *alpha_tp_string;    /* -mtrap-precision=[p|s|i] */
85 const char *alpha_fprm_string;  /* -mfp-rounding-mode=[n|m|c|d] */
86 const char *alpha_fptm_string;  /* -mfp-trap-mode=[n|u|su|sui] */
87 const char *alpha_mlat_string;  /* -mmemory-latency= */
88 const char *alpha_tls_size_string; /* -mtls-size=[16|32|64] */
89
90 /* Save information from a "cmpxx" operation until the branch or scc is
91    emitted.  */
92
93 struct alpha_compare alpha_compare;
94
95 /* Nonzero if inside of a function, because the Alpha asm can't
96    handle .files inside of functions.  */
97
98 static int inside_function = FALSE;
99
100 /* The number of cycles of latency we should assume on memory reads.  */
101
102 int alpha_memory_latency = 3;
103
104 /* Whether the function needs the GP.  */
105
106 static int alpha_function_needs_gp;
107
108 /* The alias set for prologue/epilogue register save/restore.  */
109
110 static GTY(()) int alpha_sr_alias_set;
111
112 /* The assembler name of the current function.  */
113
114 static const char *alpha_fnname;
115
116 /* The next explicit relocation sequence number.  */
117 extern GTY(()) int alpha_next_sequence_number;
118 int alpha_next_sequence_number = 1;
119
120 /* The literal and gpdisp sequence numbers for this insn, as printed
121    by %# and %* respectively.  */
122 extern GTY(()) int alpha_this_literal_sequence_number;
123 extern GTY(()) int alpha_this_gpdisp_sequence_number;
124 int alpha_this_literal_sequence_number;
125 int alpha_this_gpdisp_sequence_number;
126
127 /* Costs of various operations on the different architectures.  */
128
129 struct alpha_rtx_cost_data
130 {
131   unsigned char fp_add;
132   unsigned char fp_mult;
133   unsigned char fp_div_sf;
134   unsigned char fp_div_df;
135   unsigned char int_mult_si;
136   unsigned char int_mult_di;
137   unsigned char int_shift;
138   unsigned char int_cmov;
139 };
140
141 static struct alpha_rtx_cost_data const alpha_rtx_cost_data[PROCESSOR_MAX] =
142 {
143   { /* EV4 */
144     COSTS_N_INSNS (6),          /* fp_add */
145     COSTS_N_INSNS (6),          /* fp_mult */
146     COSTS_N_INSNS (34),         /* fp_div_sf */
147     COSTS_N_INSNS (63),         /* fp_div_df */
148     COSTS_N_INSNS (23),         /* int_mult_si */
149     COSTS_N_INSNS (23),         /* int_mult_di */
150     COSTS_N_INSNS (2),          /* int_shift */
151     COSTS_N_INSNS (2),          /* int_cmov */
152   },
153   { /* EV5 */
154     COSTS_N_INSNS (4),          /* fp_add */
155     COSTS_N_INSNS (4),          /* fp_mult */
156     COSTS_N_INSNS (15),         /* fp_div_sf */
157     COSTS_N_INSNS (22),         /* fp_div_df */
158     COSTS_N_INSNS (8),          /* int_mult_si */
159     COSTS_N_INSNS (12),         /* int_mult_di */
160     COSTS_N_INSNS (1) + 1,      /* int_shift */
161     COSTS_N_INSNS (1),          /* int_cmov */
162   },
163   { /* EV6 */
164     COSTS_N_INSNS (4),          /* fp_add */
165     COSTS_N_INSNS (4),          /* fp_mult */
166     COSTS_N_INSNS (12),         /* fp_div_sf */
167     COSTS_N_INSNS (15),         /* fp_div_df */
168     COSTS_N_INSNS (7),          /* int_mult_si */
169     COSTS_N_INSNS (7),          /* int_mult_di */
170     COSTS_N_INSNS (1),          /* int_shift */
171     COSTS_N_INSNS (2),          /* int_cmov */
172   },
173 };
174
175 /* Get the number of args of a function in one of two ways.  */
176 #if TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK
177 #define NUM_ARGS current_function_args_info.num_args
178 #else
179 #define NUM_ARGS current_function_args_info
180 #endif
181
182 #define REG_PV 27
183 #define REG_RA 26
184
185 /* Declarations of static functions.  */
186 static struct machine_function *alpha_init_machine_status (void);
187 static rtx alpha_emit_xfloating_compare (enum rtx_code, rtx, rtx);
188
189 #if TARGET_ABI_OPEN_VMS
190 static void alpha_write_linkage (FILE *, const char *, tree);
191 #endif
192
193 static void unicosmk_output_deferred_case_vectors (FILE *);
194 static void unicosmk_gen_dsib (unsigned long *);
195 static void unicosmk_output_ssib (FILE *, const char *);
196 static int unicosmk_need_dex (rtx);
197 \f
198 /* Parse target option strings.  */
199
200 void
201 override_options (void)
202 {
203   int i;
204   static const struct cpu_table {
205     const char *const name;
206     const enum processor_type processor;
207     const int flags;
208   } cpu_table[] = {
209 #define EV5_MASK (MASK_CPU_EV5)
210 #define EV6_MASK (MASK_CPU_EV6|MASK_BWX|MASK_MAX|MASK_FIX)
211     { "ev4",    PROCESSOR_EV4, 0 },
212     { "ev45",   PROCESSOR_EV4, 0 },
213     { "21064",  PROCESSOR_EV4, 0 },
214     { "ev5",    PROCESSOR_EV5, EV5_MASK },
215     { "21164",  PROCESSOR_EV5, EV5_MASK },
216     { "ev56",   PROCESSOR_EV5, EV5_MASK|MASK_BWX },
217     { "21164a", PROCESSOR_EV5, EV5_MASK|MASK_BWX },
218     { "pca56",  PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX },
219     { "21164PC",PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX },
220     { "21164pc",PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX },
221     { "ev6",    PROCESSOR_EV6, EV6_MASK },
222     { "21264",  PROCESSOR_EV6, EV6_MASK },
223     { "ev67",   PROCESSOR_EV6, EV6_MASK|MASK_CIX },
224     { "21264a", PROCESSOR_EV6, EV6_MASK|MASK_CIX },
225     { 0, 0, 0 }
226   };
227                   
228   /* Unicos/Mk doesn't have shared libraries.  */
229   if (TARGET_ABI_UNICOSMK && flag_pic)
230     {
231       warning ("-f%s ignored for Unicos/Mk (not supported)",
232                (flag_pic > 1) ? "PIC" : "pic");
233       flag_pic = 0;
234     }
235
236   /* On Unicos/Mk, the native compiler consistently generates /d suffices for 
237      floating-point instructions.  Make that the default for this target.  */
238   if (TARGET_ABI_UNICOSMK)
239     alpha_fprm = ALPHA_FPRM_DYN;
240   else
241     alpha_fprm = ALPHA_FPRM_NORM;
242
243   alpha_tp = ALPHA_TP_PROG;
244   alpha_fptm = ALPHA_FPTM_N;
245
246   /* We cannot use su and sui qualifiers for conversion instructions on 
247      Unicos/Mk.  I'm not sure if this is due to assembler or hardware
248      limitations.  Right now, we issue a warning if -mieee is specified
249      and then ignore it; eventually, we should either get it right or
250      disable the option altogether.  */
251
252   if (TARGET_IEEE)
253     {
254       if (TARGET_ABI_UNICOSMK)
255         warning ("-mieee not supported on Unicos/Mk");
256       else
257         {
258           alpha_tp = ALPHA_TP_INSN;
259           alpha_fptm = ALPHA_FPTM_SU;
260         }
261     }
262
263   if (TARGET_IEEE_WITH_INEXACT)
264     {
265       if (TARGET_ABI_UNICOSMK)
266         warning ("-mieee-with-inexact not supported on Unicos/Mk");
267       else
268         {
269           alpha_tp = ALPHA_TP_INSN;
270           alpha_fptm = ALPHA_FPTM_SUI;
271         }
272     }
273
274   if (alpha_tp_string)
275     {
276       if (! strcmp (alpha_tp_string, "p"))
277         alpha_tp = ALPHA_TP_PROG;
278       else if (! strcmp (alpha_tp_string, "f"))
279         alpha_tp = ALPHA_TP_FUNC;
280       else if (! strcmp (alpha_tp_string, "i"))
281         alpha_tp = ALPHA_TP_INSN;
282       else
283         error ("bad value `%s' for -mtrap-precision switch", alpha_tp_string);
284     }
285
286   if (alpha_fprm_string)
287     {
288       if (! strcmp (alpha_fprm_string, "n"))
289         alpha_fprm = ALPHA_FPRM_NORM;
290       else if (! strcmp (alpha_fprm_string, "m"))
291         alpha_fprm = ALPHA_FPRM_MINF;
292       else if (! strcmp (alpha_fprm_string, "c"))
293         alpha_fprm = ALPHA_FPRM_CHOP;
294       else if (! strcmp (alpha_fprm_string,"d"))
295         alpha_fprm = ALPHA_FPRM_DYN;
296       else
297         error ("bad value `%s' for -mfp-rounding-mode switch",
298                alpha_fprm_string);
299     }
300
301   if (alpha_fptm_string)
302     {
303       if (strcmp (alpha_fptm_string, "n") == 0)
304         alpha_fptm = ALPHA_FPTM_N;
305       else if (strcmp (alpha_fptm_string, "u") == 0)
306         alpha_fptm = ALPHA_FPTM_U;
307       else if (strcmp (alpha_fptm_string, "su") == 0)
308         alpha_fptm = ALPHA_FPTM_SU;
309       else if (strcmp (alpha_fptm_string, "sui") == 0)
310         alpha_fptm = ALPHA_FPTM_SUI;
311       else
312         error ("bad value `%s' for -mfp-trap-mode switch", alpha_fptm_string);
313     }
314
315   if (alpha_tls_size_string)
316     {
317       if (strcmp (alpha_tls_size_string, "16") == 0)
318         alpha_tls_size = 16;
319       else if (strcmp (alpha_tls_size_string, "32") == 0)
320         alpha_tls_size = 32;
321       else if (strcmp (alpha_tls_size_string, "64") == 0)
322         alpha_tls_size = 64;
323       else
324         error ("bad value `%s' for -mtls-size switch", alpha_tls_size_string);
325     }
326
327   alpha_cpu
328     = TARGET_CPU_DEFAULT & MASK_CPU_EV6 ? PROCESSOR_EV6
329       : (TARGET_CPU_DEFAULT & MASK_CPU_EV5 ? PROCESSOR_EV5 : PROCESSOR_EV4);
330
331   if (alpha_cpu_string)
332     {
333       for (i = 0; cpu_table [i].name; i++)
334         if (! strcmp (alpha_cpu_string, cpu_table [i].name))
335           {
336             alpha_cpu = cpu_table [i].processor;
337             target_flags &= ~ (MASK_BWX | MASK_MAX | MASK_FIX | MASK_CIX
338                                | MASK_CPU_EV5 | MASK_CPU_EV6);
339             target_flags |= cpu_table [i].flags;
340             break;
341           }
342       if (! cpu_table [i].name)
343         error ("bad value `%s' for -mcpu switch", alpha_cpu_string);
344     }
345
346   if (alpha_tune_string)
347     {
348       for (i = 0; cpu_table [i].name; i++)
349         if (! strcmp (alpha_tune_string, cpu_table [i].name))
350           {
351             alpha_cpu = cpu_table [i].processor;
352             break;
353           }
354       if (! cpu_table [i].name)
355         error ("bad value `%s' for -mcpu switch", alpha_tune_string);
356     }
357
358   /* Do some sanity checks on the above options.  */
359
360   if (TARGET_ABI_UNICOSMK && alpha_fptm != ALPHA_FPTM_N)
361     {
362       warning ("trap mode not supported on Unicos/Mk");
363       alpha_fptm = ALPHA_FPTM_N;
364     }
365
366   if ((alpha_fptm == ALPHA_FPTM_SU || alpha_fptm == ALPHA_FPTM_SUI)
367       && alpha_tp != ALPHA_TP_INSN && ! TARGET_CPU_EV6)
368     {
369       warning ("fp software completion requires -mtrap-precision=i");
370       alpha_tp = ALPHA_TP_INSN;
371     }
372
373   if (TARGET_CPU_EV6)
374     {
375       /* Except for EV6 pass 1 (not released), we always have precise
376          arithmetic traps.  Which means we can do software completion
377          without minding trap shadows.  */
378       alpha_tp = ALPHA_TP_PROG;
379     }
380
381   if (TARGET_FLOAT_VAX)
382     {
383       if (alpha_fprm == ALPHA_FPRM_MINF || alpha_fprm == ALPHA_FPRM_DYN)
384         {
385           warning ("rounding mode not supported for VAX floats");
386           alpha_fprm = ALPHA_FPRM_NORM;
387         }
388       if (alpha_fptm == ALPHA_FPTM_SUI)
389         {
390           warning ("trap mode not supported for VAX floats");
391           alpha_fptm = ALPHA_FPTM_SU;
392         }
393       if (target_flags_explicit & MASK_LONG_DOUBLE_128)
394         warning ("128-bit long double not supported for VAX floats");
395       target_flags &= ~MASK_LONG_DOUBLE_128;
396     }
397
398   {
399     char *end;
400     int lat;
401
402     if (!alpha_mlat_string)
403       alpha_mlat_string = "L1";
404
405     if (ISDIGIT ((unsigned char)alpha_mlat_string[0])
406         && (lat = strtol (alpha_mlat_string, &end, 10), *end == '\0'))
407       ;
408     else if ((alpha_mlat_string[0] == 'L' || alpha_mlat_string[0] == 'l')
409              && ISDIGIT ((unsigned char)alpha_mlat_string[1])
410              && alpha_mlat_string[2] == '\0')
411       {
412         static int const cache_latency[][4] = 
413         {
414           { 3, 30, -1 },        /* ev4 -- Bcache is a guess */
415           { 2, 12, 38 },        /* ev5 -- Bcache from PC164 LMbench numbers */
416           { 3, 12, 30 },        /* ev6 -- Bcache from DS20 LMbench.  */
417         };
418
419         lat = alpha_mlat_string[1] - '0';
420         if (lat <= 0 || lat > 3 || cache_latency[alpha_cpu][lat-1] == -1)
421           {
422             warning ("L%d cache latency unknown for %s",
423                      lat, alpha_cpu_name[alpha_cpu]);
424             lat = 3;
425           }
426         else
427           lat = cache_latency[alpha_cpu][lat-1];
428       }
429     else if (! strcmp (alpha_mlat_string, "main"))
430       {
431         /* Most current memories have about 370ns latency.  This is
432            a reasonable guess for a fast cpu.  */
433         lat = 150;
434       }
435     else
436       {
437         warning ("bad value `%s' for -mmemory-latency", alpha_mlat_string);
438         lat = 3;
439       }
440
441     alpha_memory_latency = lat;
442   }
443
444   /* Default the definition of "small data" to 8 bytes.  */
445   if (!g_switch_set)
446     g_switch_value = 8;
447
448   /* Infer TARGET_SMALL_DATA from -fpic/-fPIC.  */
449   if (flag_pic == 1)
450     target_flags |= MASK_SMALL_DATA;
451   else if (flag_pic == 2)
452     target_flags &= ~MASK_SMALL_DATA;
453
454   /* Align labels and loops for optimal branching.  */
455   /* ??? Kludge these by not doing anything if we don't optimize and also if
456      we are writing ECOFF symbols to work around a bug in DEC's assembler.  */
457   if (optimize > 0 && write_symbols != SDB_DEBUG)
458     {
459       if (align_loops <= 0)
460         align_loops = 16;
461       if (align_jumps <= 0)
462         align_jumps = 16;
463     }
464   if (align_functions <= 0)
465     align_functions = 16;
466
467   /* Acquire a unique set number for our register saves and restores.  */
468   alpha_sr_alias_set = new_alias_set ();
469
470   /* Register variables and functions with the garbage collector.  */
471
472   /* Set up function hooks.  */
473   init_machine_status = alpha_init_machine_status;
474
475   /* Tell the compiler when we're using VAX floating point.  */
476   if (TARGET_FLOAT_VAX)
477     {
478       REAL_MODE_FORMAT (SFmode) = &vax_f_format;
479       REAL_MODE_FORMAT (DFmode) = &vax_g_format;
480       REAL_MODE_FORMAT (TFmode) = NULL;
481     }
482 }
483 \f
484 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones.  */
485
486 int
487 zap_mask (HOST_WIDE_INT value)
488 {
489   int i;
490
491   for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
492        i++, value >>= 8)
493     if ((value & 0xff) != 0 && (value & 0xff) != 0xff)
494       return 0;
495
496   return 1;
497 }
498
499 /* Returns 1 if OP is either the constant zero or a register.  If a
500    register, it must be in the proper mode unless MODE is VOIDmode.  */
501
502 int
503 reg_or_0_operand (rtx op, enum machine_mode mode)
504 {
505   return op == CONST0_RTX (mode) || register_operand (op, mode);
506 }
507
508 /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
509    any register.  */
510
511 int
512 reg_or_6bit_operand (rtx op, enum machine_mode mode)
513 {
514   return ((GET_CODE (op) == CONST_INT
515            && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
516           || register_operand (op, mode));
517 }
518
519
520 /* Return 1 if OP is an 8-bit constant or any register.  */
521
522 int
523 reg_or_8bit_operand (rtx op, enum machine_mode mode)
524 {
525   return ((GET_CODE (op) == CONST_INT
526            && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
527           || register_operand (op, mode));
528 }
529
530 /* Return 1 if OP is a constant or any register.  */
531
532 int
533 reg_or_const_int_operand (rtx op, enum machine_mode mode)
534 {
535   return GET_CODE (op) == CONST_INT || register_operand (op, mode);
536 }
537
538 /* Return 1 if OP is an 8-bit constant.  */
539
540 int
541 cint8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
542 {
543   return ((GET_CODE (op) == CONST_INT
544            && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100));
545 }
546
547 /* Return 1 if the operand is a valid second operand to an add insn.  */
548
549 int
550 add_operand (rtx op, enum machine_mode mode)
551 {
552   if (GET_CODE (op) == CONST_INT)
553     /* Constraints I, J, O and P are covered by K.  */
554     return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
555             || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
556
557   return register_operand (op, mode);
558 }
559
560 /* Return 1 if the operand is a valid second operand to a sign-extending
561    add insn.  */
562
563 int
564 sext_add_operand (rtx op, enum machine_mode mode)
565 {
566   if (GET_CODE (op) == CONST_INT)
567     return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
568             || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'));
569
570   return reg_not_elim_operand (op, mode);
571 }
572
573 /* Return 1 if OP is the constant 4 or 8.  */
574
575 int
576 const48_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
577 {
578   return (GET_CODE (op) == CONST_INT
579           && (INTVAL (op) == 4 || INTVAL (op) == 8));
580 }
581
582 /* Return 1 if OP is a valid first operand to an AND insn.  */
583
584 int
585 and_operand (rtx op, enum machine_mode mode)
586 {
587   if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
588     return (zap_mask (CONST_DOUBLE_LOW (op))
589             && zap_mask (CONST_DOUBLE_HIGH (op)));
590
591   if (GET_CODE (op) == CONST_INT)
592     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
593             || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
594             || zap_mask (INTVAL (op)));
595
596   return register_operand (op, mode);
597 }
598
599 /* Return 1 if OP is a valid first operand to an IOR or XOR insn.  */
600
601 int
602 or_operand (rtx op, enum machine_mode mode)
603 {
604   if (GET_CODE (op) == CONST_INT)
605     return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
606             || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
607
608   return register_operand (op, mode);
609 }
610
611 /* Return 1 if OP is a constant that is the width, in bits, of an integral
612    mode smaller than DImode.  */
613
614 int
615 mode_width_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
616 {
617   return (GET_CODE (op) == CONST_INT
618           && (INTVAL (op) == 8 || INTVAL (op) == 16
619               || INTVAL (op) == 32 || INTVAL (op) == 64));
620 }
621
622 /* Return 1 if OP is a constant that is the width of an integral machine mode
623    smaller than an integer.  */
624
625 int
626 mode_mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
627 {
628   if (GET_CODE (op) == CONST_INT)
629     {
630       HOST_WIDE_INT value = INTVAL (op);
631
632       if (value == 0xff)
633         return 1;
634       if (value == 0xffff)
635         return 1;
636       if (value == 0xffffffff)
637         return 1;
638       if (value == -1)
639         return 1;
640     }
641   else if (HOST_BITS_PER_WIDE_INT == 32 && GET_CODE (op) == CONST_DOUBLE)
642     {
643       if (CONST_DOUBLE_LOW (op) == 0xffffffff && CONST_DOUBLE_HIGH (op) == 0)
644         return 1;
645     }
646
647   return 0;
648 }
649
650 /* Return 1 if OP is a multiple of 8 less than 64.  */
651
652 int
653 mul8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
654 {
655   return (GET_CODE (op) == CONST_INT
656           && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
657           && (INTVAL (op) & 7) == 0);
658 }
659
660 /* Return 1 if OP is the zero constant for MODE.  */
661
662 int
663 const0_operand (rtx op, enum machine_mode mode)
664 {
665   return op == CONST0_RTX (mode);
666 }
667
668 /* Return 1 if OP is a hard floating-point register.  */
669
670 int
671 hard_fp_register_operand (rtx op, enum machine_mode mode)
672 {
673   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
674     return 0;
675
676   if (GET_CODE (op) == SUBREG)
677     op = SUBREG_REG (op);
678   return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == FLOAT_REGS;
679 }
680
681 /* Return 1 if OP is a hard general register.  */
682
683 int
684 hard_int_register_operand (rtx op, enum machine_mode mode)
685 {
686   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
687     return 0;
688
689   if (GET_CODE (op) == SUBREG)
690     op = SUBREG_REG (op);
691   return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS;
692 }
693
694 /* Return 1 if OP is a register or a constant integer.  */
695
696
697 int
698 reg_or_cint_operand (rtx op, enum machine_mode mode)
699 {
700      return (GET_CODE (op) == CONST_INT
701              || register_operand (op, mode));
702 }
703
704 /* Return 1 if OP is something that can be reloaded into a register;
705    if it is a MEM, it need not be valid.  */
706
707 int
708 some_operand (rtx op, enum machine_mode mode)
709 {
710   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
711     return 0;
712
713   switch (GET_CODE (op))
714     {
715     case REG:
716     case MEM:
717     case CONST_INT:
718     case CONST_DOUBLE:
719     case CONST_VECTOR:
720     case LABEL_REF:
721     case SYMBOL_REF:
722     case CONST:
723     case HIGH:
724       return 1;
725
726     case SUBREG:
727       return some_operand (SUBREG_REG (op), VOIDmode);
728
729     default:
730       break;
731     }
732
733   return 0;
734 }
735
736 /* Likewise, but don't accept constants.  */
737
738 int
739 some_ni_operand (rtx op, enum machine_mode mode)
740 {
741   if (GET_MODE (op) != mode && mode != VOIDmode)
742     return 0;
743
744   if (GET_CODE (op) == SUBREG)
745     op = SUBREG_REG (op);
746
747   return (GET_CODE (op) == REG || GET_CODE (op) == MEM);
748 }
749
750 /* Return 1 if OP is a valid operand for the source of a move insn.  */
751
752 int
753 input_operand (rtx op, enum machine_mode mode)
754 {
755   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
756     return 0;
757
758   if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
759     return 0;
760
761   switch (GET_CODE (op))
762     {
763     case LABEL_REF:
764     case SYMBOL_REF:
765     case CONST:
766       if (TARGET_EXPLICIT_RELOCS)
767         {
768           /* We don't split symbolic operands into something unintelligable
769              until after reload, but we do not wish non-small, non-global
770              symbolic operands to be reconstructed from their high/lo_sum
771              form.  */
772           return (small_symbolic_operand (op, mode)
773                   || global_symbolic_operand (op, mode)
774                   || gotdtp_symbolic_operand (op, mode)
775                   || gottp_symbolic_operand (op, mode));
776         }
777
778       /* This handles both the Windows/NT and OSF cases.  */
779       return mode == ptr_mode || mode == DImode;
780
781     case HIGH:
782       return (TARGET_EXPLICIT_RELOCS
783               && local_symbolic_operand (XEXP (op, 0), mode));
784
785     case REG:
786     case ADDRESSOF:
787       return 1;
788
789     case SUBREG:
790       if (register_operand (op, mode))
791         return 1;
792       /* ... fall through ...  */
793     case MEM:
794       return ((TARGET_BWX || (mode != HImode && mode != QImode))
795               && general_operand (op, mode));
796
797     case CONST_DOUBLE:
798     case CONST_VECTOR:
799       return op == CONST0_RTX (mode);
800
801     case CONST_INT:
802       return mode == QImode || mode == HImode || add_operand (op, mode);
803
804     case CONSTANT_P_RTX:
805       return 1;
806
807     default:
808       break;
809     }
810
811   return 0;
812 }
813
814 /* Return 1 if OP is a SYMBOL_REF for a function known to be in this
815    file, and in the same section as the current function.  */
816
817 int
818 samegp_function_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
819 {
820   if (GET_CODE (op) != SYMBOL_REF)
821     return false;
822
823   /* Easy test for recursion.  */
824   if (op == XEXP (DECL_RTL (current_function_decl), 0))
825     return true;
826
827   /* Functions that are not local can be overridden, and thus may
828      not share the same gp.  */
829   if (! SYMBOL_REF_LOCAL_P (op))
830     return false;
831
832   /* If -msmall-data is in effect, assume that there is only one GP
833      for the module, and so any local symbol has this property.  We
834      need explicit relocations to be able to enforce this for symbols
835      not defined in this unit of translation, however.  */
836   if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
837     return true;
838
839   /* Functions that are not external are defined in this UoT,
840      and thus must share the same gp.  */
841   return ! SYMBOL_REF_EXTERNAL_P (op);
842 }
843
844 /* Return 1 if OP is a SYMBOL_REF for which we can make a call via bsr.  */
845
846 int
847 direct_call_operand (rtx op, enum machine_mode mode)
848 {
849   tree op_decl, cfun_sec, op_sec;
850
851   /* Must share the same GP.  */
852   if (!samegp_function_operand (op, mode))
853     return false;
854
855   /* If profiling is implemented via linker tricks, we can't jump
856      to the nogp alternate entry point.  Note that current_function_profile
857      would not be correct, since that doesn't indicate if the target
858      function uses profiling.  */
859   /* ??? TARGET_PROFILING_NEEDS_GP isn't really the right test,
860      but is approximately correct for the OSF ABIs.  Don't know
861      what to do for VMS, NT, or UMK.  */
862   if (!TARGET_PROFILING_NEEDS_GP && profile_flag)
863     return false;
864
865   /* Must be a function.  In some cases folks create thunks in static
866      data structures and then make calls to them.  If we allow the
867      direct call, we'll get an error from the linker about !samegp reloc
868      against a symbol without a .prologue directive.  */
869   if (!SYMBOL_REF_FUNCTION_P (op))
870     return false;
871   
872   /* Must be "near" so that the branch is assumed to reach.  With
873      -msmall-text, this is assumed true of all local symbols.  Since
874      we've already checked samegp, locality is already assured.  */
875   if (TARGET_SMALL_TEXT)
876     return true;
877
878   /* Otherwise, a decl is "near" if it is defined in the same section.  */
879   if (flag_function_sections)
880     return false;
881
882   op_decl = SYMBOL_REF_DECL (op);
883   if (DECL_ONE_ONLY (current_function_decl)
884       || (op_decl && DECL_ONE_ONLY (op_decl)))
885     return false;
886
887   cfun_sec = DECL_SECTION_NAME (current_function_decl);
888   op_sec = op_decl ? DECL_SECTION_NAME (op_decl) : NULL;
889   return ((!cfun_sec && !op_sec)
890           || (cfun_sec && op_sec
891               && strcmp (TREE_STRING_POINTER (cfun_sec),
892                          TREE_STRING_POINTER (op_sec)) == 0));
893 }
894
895 /* Return true if OP is a LABEL_REF, or SYMBOL_REF or CONST referencing
896    a (non-tls) variable known to be defined in this file.  */
897
898 int
899 local_symbolic_operand (rtx op, enum machine_mode mode)
900 {
901   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
902     return 0;
903
904   if (GET_CODE (op) == LABEL_REF)
905     return 1;
906
907   if (GET_CODE (op) == CONST
908       && GET_CODE (XEXP (op, 0)) == PLUS
909       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
910     op = XEXP (XEXP (op, 0), 0);
911
912   if (GET_CODE (op) != SYMBOL_REF)
913     return 0;
914
915   return SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
916 }
917
918 /* Return true if OP is a SYMBOL_REF or CONST referencing a variable
919    known to be defined in this file in the small data area.  */
920
921 int
922 small_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
923 {
924   if (! TARGET_SMALL_DATA)
925     return 0;
926
927   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
928     return 0;
929
930   if (GET_CODE (op) == CONST
931       && GET_CODE (XEXP (op, 0)) == PLUS
932       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
933     op = XEXP (XEXP (op, 0), 0);
934
935   if (GET_CODE (op) != SYMBOL_REF)
936     return 0;
937
938   /* ??? There's no encode_section_info equivalent for the rtl
939      constant pool, so SYMBOL_FLAG_SMALL never gets set.  */
940   if (CONSTANT_POOL_ADDRESS_P (op))
941     return GET_MODE_SIZE (get_pool_mode (op)) <= g_switch_value;
942
943   return (SYMBOL_REF_LOCAL_P (op)
944           && SYMBOL_REF_SMALL_P (op)
945           && SYMBOL_REF_TLS_MODEL (op) == 0);
946 }
947
948 /* Return true if OP is a SYMBOL_REF or CONST referencing a variable
949    not known (or known not) to be defined in this file.  */
950
951 int
952 global_symbolic_operand (rtx op, enum machine_mode mode)
953 {
954   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
955     return 0;
956
957   if (GET_CODE (op) == CONST
958       && GET_CODE (XEXP (op, 0)) == PLUS
959       && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
960     op = XEXP (XEXP (op, 0), 0);
961
962   if (GET_CODE (op) != SYMBOL_REF)
963     return 0;
964
965   return !SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
966 }
967
968 /* Return 1 if OP is a valid operand for the MEM of a CALL insn.  */
969
970 int
971 call_operand (rtx op, enum machine_mode mode)
972 {
973   if (mode != Pmode)
974     return 0;
975
976   if (GET_CODE (op) == REG)
977     {
978       if (TARGET_ABI_OSF)
979         {
980           /* Disallow virtual registers to cope with pathological test cases
981              such as compile/930117-1.c in which the virtual reg decomposes
982              to the frame pointer.  Which is a hard reg that is not $27.  */
983           return (REGNO (op) == 27 || REGNO (op) > LAST_VIRTUAL_REGISTER);
984         }
985       else
986         return 1;
987     }
988   if (TARGET_ABI_UNICOSMK)
989     return 0;
990   if (GET_CODE (op) == SYMBOL_REF)
991     return 1;
992
993   return 0;
994 }
995
996 /* Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
997    possibly with an offset.  */
998
999 int
1000 symbolic_operand (rtx op, enum machine_mode mode)
1001 {
1002   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1003     return 0;
1004   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
1005     return 1;
1006   if (GET_CODE (op) == CONST
1007       && GET_CODE (XEXP (op,0)) == PLUS
1008       && GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF
1009       && GET_CODE (XEXP (XEXP (op,0), 1)) == CONST_INT)
1010     return 1;
1011   return 0;
1012 }
1013
1014 /* Return true if OP is valid for a particular TLS relocation.  */
1015
1016 static int
1017 tls_symbolic_operand_1 (rtx op, enum machine_mode mode, int size, int unspec)
1018 {
1019   if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1020     return 0;
1021
1022   if (GET_CODE (op) != CONST)
1023     return 0;
1024   op = XEXP (op, 0);
1025
1026   if (GET_CODE (op) != UNSPEC || XINT (op, 1) != unspec)
1027     return 0;
1028   op = XVECEXP (op, 0, 0);
1029
1030   if (GET_CODE (op) != SYMBOL_REF)
1031     return 0;
1032
1033   if (SYMBOL_REF_LOCAL_P (op))
1034     {
1035       if (alpha_tls_size > size)
1036         return 0;
1037     }
1038   else
1039     {
1040       if (size != 64)
1041         return 0;
1042     }
1043
1044   switch (SYMBOL_REF_TLS_MODEL (op))
1045     {
1046     case TLS_MODEL_LOCAL_DYNAMIC:
1047       return unspec == UNSPEC_DTPREL;
1048     case TLS_MODEL_INITIAL_EXEC:
1049       return unspec == UNSPEC_TPREL && size == 64;
1050     case TLS_MODEL_LOCAL_EXEC:
1051       return unspec == UNSPEC_TPREL;
1052     default:
1053       abort ();
1054     }
1055 }
1056
1057 /* Return true if OP is valid for 16-bit DTP relative relocations.  */
1058
1059 int
1060 dtp16_symbolic_operand (rtx op, enum machine_mode mode)
1061 {
1062   return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_DTPREL);
1063 }
1064
1065 /* Return true if OP is valid for 32-bit DTP relative relocations.  */
1066
1067 int
1068 dtp32_symbolic_operand (rtx op, enum machine_mode mode)
1069 {
1070   return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_DTPREL);
1071 }
1072
1073 /* Return true if OP is valid for 64-bit DTP relative relocations.  */
1074
1075 int
1076 gotdtp_symbolic_operand (rtx op, enum machine_mode mode)
1077 {
1078   return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_DTPREL);
1079 }
1080
1081 /* Return true if OP is valid for 16-bit TP relative relocations.  */
1082
1083 int
1084 tp16_symbolic_operand (rtx op, enum machine_mode mode)
1085 {
1086   return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_TPREL);
1087 }
1088
1089 /* Return true if OP is valid for 32-bit TP relative relocations.  */
1090
1091 int
1092 tp32_symbolic_operand (rtx op, enum machine_mode mode)
1093 {
1094   return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_TPREL);
1095 }
1096
1097 /* Return true if OP is valid for 64-bit TP relative relocations.  */
1098
1099 int
1100 gottp_symbolic_operand (rtx op, enum machine_mode mode)
1101 {
1102   return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_TPREL);
1103 }
1104
1105 /* Return 1 if OP is a valid Alpha comparison operator.  Here we know which
1106    comparisons are valid in which insn.  */
1107
1108 int
1109 alpha_comparison_operator (rtx op, enum machine_mode mode)
1110 {
1111   enum rtx_code code = GET_CODE (op);
1112
1113   if (mode != GET_MODE (op) && mode != VOIDmode)
1114     return 0;
1115
1116   return (code == EQ || code == LE || code == LT
1117           || code == LEU || code == LTU);
1118 }
1119
1120 /* Return 1 if OP is a valid Alpha comparison operator against zero. 
1121    Here we know which comparisons are valid in which insn.  */
1122
1123 int
1124 alpha_zero_comparison_operator (rtx op, enum machine_mode mode)
1125 {
1126   enum rtx_code code = GET_CODE (op);
1127
1128   if (mode != GET_MODE (op) && mode != VOIDmode)
1129     return 0;
1130
1131   return (code == EQ || code == NE || code == LE || code == LT
1132           || code == LEU || code == LTU);
1133 }
1134
1135 /* Return 1 if OP is a valid Alpha swapped comparison operator.  */
1136
1137 int
1138 alpha_swapped_comparison_operator (rtx op, enum machine_mode mode)
1139 {
1140   enum rtx_code code = GET_CODE (op);
1141
1142   if ((mode != GET_MODE (op) && mode != VOIDmode)
1143       || GET_RTX_CLASS (code) != '<')
1144     return 0;
1145
1146   code = swap_condition (code);
1147   return (code == EQ || code == LE || code == LT
1148           || code == LEU || code == LTU);
1149 }
1150
1151 /* Return 1 if OP is a signed comparison operation.  */
1152
1153 int
1154 signed_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1155 {
1156   enum rtx_code code = GET_CODE (op);
1157
1158   if (mode != GET_MODE (op) && mode != VOIDmode)
1159     return 0;
1160
1161   return (code == EQ || code == NE
1162           || code == LE || code == LT
1163           || code == GE || code == GT);
1164 }
1165
1166 /* Return 1 if OP is a valid Alpha floating point comparison operator.
1167    Here we know which comparisons are valid in which insn.  */
1168
1169 int
1170 alpha_fp_comparison_operator (rtx op, enum machine_mode mode)
1171 {
1172   enum rtx_code code = GET_CODE (op);
1173
1174   if (mode != GET_MODE (op) && mode != VOIDmode)
1175     return 0;
1176
1177   return (code == EQ || code == LE || code == LT || code == UNORDERED);
1178 }
1179
1180 /* Return 1 if this is a divide or modulus operator.  */
1181
1182 int
1183 divmod_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1184 {
1185   enum rtx_code code = GET_CODE (op);
1186
1187   return (code == DIV || code == MOD || code == UDIV || code == UMOD);
1188 }
1189
1190 /* Return 1 if this is a float->int conversion operator.  */
1191
1192 int
1193 fix_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1194 {
1195   enum rtx_code code = GET_CODE (op);
1196
1197   return (code == FIX || code == UNSIGNED_FIX);
1198 }
1199
1200 /* Return 1 if this memory address is a known aligned register plus
1201    a constant.  It must be a valid address.  This means that we can do
1202    this as an aligned reference plus some offset.
1203
1204    Take into account what reload will do.  */
1205
1206 int
1207 aligned_memory_operand (rtx op, enum machine_mode mode)
1208 {
1209   rtx base;
1210
1211   if (reload_in_progress)
1212     {
1213       rtx tmp = op;
1214       if (GET_CODE (tmp) == SUBREG)
1215         tmp = SUBREG_REG (tmp);
1216       if (GET_CODE (tmp) == REG
1217           && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1218         {
1219           op = reg_equiv_memory_loc[REGNO (tmp)];
1220           if (op == 0)
1221             return 0;
1222         }
1223     }
1224
1225   if (GET_CODE (op) != MEM)
1226     return 0;
1227   if (MEM_ALIGN (op) >= 32)
1228     return 1;
1229   op = XEXP (op, 0);
1230
1231   /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
1232      sorts of constructs.  Dig for the real base register.  */
1233   if (reload_in_progress
1234       && GET_CODE (op) == PLUS
1235       && GET_CODE (XEXP (op, 0)) == PLUS)
1236     base = XEXP (XEXP (op, 0), 0);
1237   else
1238     {
1239       if (! memory_address_p (mode, op))
1240         return 0;
1241       base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1242     }
1243
1244   return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) >= 32);
1245 }
1246
1247 /* Similar, but return 1 if OP is a MEM which is not alignable.  */
1248
1249 int
1250 unaligned_memory_operand (rtx op, enum machine_mode mode)
1251 {
1252   rtx base;
1253
1254   if (reload_in_progress)
1255     {
1256       rtx tmp = op;
1257       if (GET_CODE (tmp) == SUBREG)
1258         tmp = SUBREG_REG (tmp);
1259       if (GET_CODE (tmp) == REG
1260           && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1261         {
1262           op = reg_equiv_memory_loc[REGNO (tmp)];
1263           if (op == 0)
1264             return 0;
1265         }
1266     }
1267
1268   if (GET_CODE (op) != MEM)
1269     return 0;
1270   if (MEM_ALIGN (op) >= 32)
1271     return 0;
1272   op = XEXP (op, 0);
1273
1274   /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
1275      sorts of constructs.  Dig for the real base register.  */
1276   if (reload_in_progress
1277       && GET_CODE (op) == PLUS
1278       && GET_CODE (XEXP (op, 0)) == PLUS)
1279     base = XEXP (XEXP (op, 0), 0);
1280   else
1281     {
1282       if (! memory_address_p (mode, op))
1283         return 0;
1284       base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1285     }
1286
1287   return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) < 32);
1288 }
1289
1290 /* Return 1 if OP is either a register or an unaligned memory location.  */
1291
1292 int
1293 reg_or_unaligned_mem_operand (rtx op, enum machine_mode mode)
1294 {
1295   return register_operand (op, mode) || unaligned_memory_operand (op, mode);
1296 }
1297
1298 /* Return 1 if OP is any memory location.  During reload a pseudo matches.  */
1299
1300 int
1301 any_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1302 {
1303   return (GET_CODE (op) == MEM
1304           || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
1305           || (reload_in_progress && GET_CODE (op) == REG
1306               && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1307           || (reload_in_progress && GET_CODE (op) == SUBREG
1308               && GET_CODE (SUBREG_REG (op)) == REG
1309               && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER));
1310 }
1311
1312 /* Returns 1 if OP is not an eliminable register.
1313
1314    This exists to cure a pathological abort in the s8addq (et al) patterns,
1315
1316         long foo () { long t; bar(); return (long) &t * 26107; }
1317
1318    which run afoul of a hack in reload to cure a (presumably) similar
1319    problem with lea-type instructions on other targets.  But there is
1320    one of us and many of them, so work around the problem by selectively
1321    preventing combine from making the optimization.  */
1322
1323 int
1324 reg_not_elim_operand (rtx op, enum machine_mode mode)
1325 {
1326   rtx inner = op;
1327   if (GET_CODE (op) == SUBREG)
1328     inner = SUBREG_REG (op);
1329   if (inner == frame_pointer_rtx || inner == arg_pointer_rtx)
1330     return 0;
1331
1332   return register_operand (op, mode);
1333 }
1334
1335 /* Return 1 is OP is a memory location that is not a reference (using
1336    an AND) to an unaligned location.  Take into account what reload
1337    will do.  */
1338
1339 int
1340 normal_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1341 {
1342   if (reload_in_progress)
1343     {
1344       rtx tmp = op;
1345       if (GET_CODE (tmp) == SUBREG)
1346         tmp = SUBREG_REG (tmp);
1347       if (GET_CODE (tmp) == REG
1348           && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1349         {
1350           op = reg_equiv_memory_loc[REGNO (tmp)];
1351
1352           /* This may not have been assigned an equivalent address if it will
1353              be eliminated.  In that case, it doesn't matter what we do.  */
1354           if (op == 0)
1355             return 1;
1356         }
1357     }
1358
1359   return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) != AND;
1360 }
1361
1362 /* Accept a register, but not a subreg of any kind.  This allows us to
1363    avoid pathological cases in reload wrt data movement common in 
1364    int->fp conversion.  */
1365
1366 int
1367 reg_no_subreg_operand (rtx op, enum machine_mode mode)
1368 {
1369   if (GET_CODE (op) != REG)
1370     return 0;
1371   return register_operand (op, mode);
1372 }
1373
1374 /* Recognize an addition operation that includes a constant.  Used to
1375    convince reload to canonize (plus (plus reg c1) c2) during register
1376    elimination.  */
1377
1378 int
1379 addition_operation (rtx op, enum machine_mode mode)
1380 {
1381   if (GET_MODE (op) != mode && mode != VOIDmode)
1382     return 0;
1383   if (GET_CODE (op) == PLUS
1384       && register_operand (XEXP (op, 0), mode)
1385       && GET_CODE (XEXP (op, 1)) == CONST_INT
1386       && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (op, 1)), 'K'))
1387     return 1;
1388   return 0;
1389 }
1390
1391 /* Implements CONST_OK_FOR_LETTER_P.  Return true if the value matches
1392    the range defined for C in [I-P].  */
1393
1394 bool
1395 alpha_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
1396 {
1397   switch (c)
1398     {
1399     case 'I':
1400       /* An unsigned 8 bit constant.  */
1401       return (unsigned HOST_WIDE_INT) value < 0x100;
1402     case 'J':
1403       /* The constant zero.  */
1404       return value == 0;
1405     case 'K':
1406       /* A signed 16 bit constant.  */
1407       return (unsigned HOST_WIDE_INT) (value + 0x8000) < 0x10000;
1408     case 'L':
1409       /* A shifted signed 16 bit constant appropriate for LDAH.  */
1410       return ((value & 0xffff) == 0
1411               && ((value) >> 31 == -1 || value >> 31 == 0));
1412     case 'M':
1413       /* A constant that can be AND'ed with using a ZAP insn.  */
1414       return zap_mask (value);
1415     case 'N':
1416       /* A complemented unsigned 8 bit constant.  */
1417       return (unsigned HOST_WIDE_INT) (~ value) < 0x100;
1418     case 'O':
1419       /* A negated unsigned 8 bit constant.  */
1420       return (unsigned HOST_WIDE_INT) (- value) < 0x100;
1421     case 'P':
1422       /* The constant 1, 2 or 3.  */
1423       return value == 1 || value == 2 || value == 3;
1424
1425     default:
1426       return false;
1427     }
1428 }
1429
1430 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P.  Return true if VALUE
1431    matches for C in [GH].  */
1432
1433 bool
1434 alpha_const_double_ok_for_letter_p (rtx value, int c)
1435 {
1436   switch (c)
1437     {
1438     case 'G':
1439       /* The floating point zero constant.  */
1440       return (GET_MODE_CLASS (GET_MODE (value)) == MODE_FLOAT
1441               && value == CONST0_RTX (GET_MODE (value)));
1442
1443     case 'H':
1444       /* A valid operand of a ZAP insn.  */
1445       return (GET_MODE (value) == VOIDmode
1446               && zap_mask (CONST_DOUBLE_LOW (value))
1447               && zap_mask (CONST_DOUBLE_HIGH (value)));
1448
1449     default:
1450       return false;
1451     }
1452 }
1453
1454 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P.  Return true if VALUE
1455    matches for C.  */
1456
1457 bool
1458 alpha_extra_constraint (rtx value, int c)
1459 {
1460   switch (c)
1461     {
1462     case 'Q':
1463       return normal_memory_operand (value, VOIDmode);
1464     case 'R':
1465       return direct_call_operand (value, Pmode);
1466     case 'S':
1467       return (GET_CODE (value) == CONST_INT
1468               && (unsigned HOST_WIDE_INT) INTVAL (value) < 64);
1469     case 'T':
1470       return GET_CODE (value) == HIGH;
1471     case 'U':
1472       return TARGET_ABI_UNICOSMK && symbolic_operand (value, VOIDmode);
1473     case 'W':
1474       return (GET_CODE (value) == CONST_VECTOR
1475               && value == CONST0_RTX (GET_MODE (value)));
1476     default:
1477       return false;
1478     }
1479 }
1480
1481 /* Return 1 if this function can directly return via $26.  */
1482
1483 int
1484 direct_return (void)
1485 {
1486   return (! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK
1487           && reload_completed
1488           && alpha_sa_size () == 0
1489           && get_frame_size () == 0
1490           && current_function_outgoing_args_size == 0
1491           && current_function_pretend_args_size == 0);
1492 }
1493
1494 /* Return the ADDR_VEC associated with a tablejump insn.  */
1495
1496 rtx
1497 alpha_tablejump_addr_vec (rtx insn)
1498 {
1499   rtx tmp;
1500
1501   tmp = JUMP_LABEL (insn);
1502   if (!tmp)
1503     return NULL_RTX;
1504   tmp = NEXT_INSN (tmp);
1505   if (!tmp)
1506     return NULL_RTX;
1507   if (GET_CODE (tmp) == JUMP_INSN
1508       && GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC)
1509     return PATTERN (tmp);
1510   return NULL_RTX;
1511 }
1512
1513 /* Return the label of the predicted edge, or CONST0_RTX if we don't know.  */
1514
1515 rtx
1516 alpha_tablejump_best_label (rtx insn)
1517 {
1518   rtx jump_table = alpha_tablejump_addr_vec (insn);
1519   rtx best_label = NULL_RTX;
1520
1521   /* ??? Once the CFG doesn't keep getting completely rebuilt, look
1522      there for edge frequency counts from profile data.  */
1523
1524   if (jump_table)
1525     {
1526       int n_labels = XVECLEN (jump_table, 1);
1527       int best_count = -1;
1528       int i, j;
1529
1530       for (i = 0; i < n_labels; i++)
1531         {
1532           int count = 1;
1533
1534           for (j = i + 1; j < n_labels; j++)
1535             if (XEXP (XVECEXP (jump_table, 1, i), 0)
1536                 == XEXP (XVECEXP (jump_table, 1, j), 0))
1537               count++;
1538
1539           if (count > best_count)
1540             best_count = count, best_label = XVECEXP (jump_table, 1, i);
1541         }
1542     }
1543
1544   return best_label ? best_label : const0_rtx;
1545 }
1546
1547 /* Return the TLS model to use for SYMBOL.  */
1548
1549 static enum tls_model
1550 tls_symbolic_operand_type (rtx symbol)
1551 {
1552   enum tls_model model;
1553
1554   if (GET_CODE (symbol) != SYMBOL_REF)
1555     return 0;
1556   model = SYMBOL_REF_TLS_MODEL (symbol);
1557
1558   /* Local-exec with a 64-bit size is the same code as initial-exec.  */
1559   if (model == TLS_MODEL_LOCAL_EXEC && alpha_tls_size == 64)
1560     model = TLS_MODEL_INITIAL_EXEC;
1561
1562   return model;
1563 }
1564 \f
1565 /* Return true if the function DECL will share the same GP as any
1566    function in the current unit of translation.  */
1567
1568 static bool
1569 decl_has_samegp (tree decl)
1570 {
1571   /* Functions that are not local can be overridden, and thus may
1572      not share the same gp.  */
1573   if (!(*targetm.binds_local_p) (decl))
1574     return false;
1575
1576   /* If -msmall-data is in effect, assume that there is only one GP
1577      for the module, and so any local symbol has this property.  We
1578      need explicit relocations to be able to enforce this for symbols
1579      not defined in this unit of translation, however.  */
1580   if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
1581     return true;
1582
1583   /* Functions that are not external are defined in this UoT.  */
1584   /* ??? Irritatingly, static functions not yet emitted are still
1585      marked "external".  Apply this to non-static functions only.  */
1586   return !TREE_PUBLIC (decl) || !DECL_EXTERNAL (decl);
1587 }
1588
1589 /* Return true if EXP should be placed in the small data section.  */
1590
1591 static bool
1592 alpha_in_small_data_p (tree exp)
1593 {
1594   /* We want to merge strings, so we never consider them small data.  */
1595   if (TREE_CODE (exp) == STRING_CST)
1596     return false;
1597
1598   /* Functions are never in the small data area.  Duh.  */
1599   if (TREE_CODE (exp) == FUNCTION_DECL)
1600     return false;
1601
1602   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
1603     {
1604       const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
1605       if (strcmp (section, ".sdata") == 0
1606           || strcmp (section, ".sbss") == 0)
1607         return true;
1608     }
1609   else
1610     {
1611       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
1612
1613       /* If this is an incomplete type with size 0, then we can't put it
1614          in sdata because it might be too big when completed.  */
1615       if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value)
1616         return true;
1617     }
1618
1619   return false;
1620 }
1621
1622 #if TARGET_ABI_OPEN_VMS
1623 static bool
1624 alpha_linkage_symbol_p (const char *symname)
1625 {
1626   int symlen = strlen (symname);
1627
1628   if (symlen > 4)
1629     return strcmp (&symname [symlen - 4], "..lk") == 0;
1630
1631   return false;
1632 }
1633
1634 #define LINKAGE_SYMBOL_REF_P(X) \
1635   ((GET_CODE (X) == SYMBOL_REF   \
1636     && alpha_linkage_symbol_p (XSTR (X, 0))) \
1637    || (GET_CODE (X) == CONST                 \
1638        && GET_CODE (XEXP (X, 0)) == PLUS     \
1639        && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF \
1640        && alpha_linkage_symbol_p (XSTR (XEXP (XEXP (X, 0), 0), 0))))
1641 #endif
1642
1643 /* legitimate_address_p recognizes an RTL expression that is a valid
1644    memory address for an instruction.  The MODE argument is the
1645    machine mode for the MEM expression that wants to use this address.
1646
1647    For Alpha, we have either a constant address or the sum of a
1648    register and a constant address, or just a register.  For DImode,
1649    any of those forms can be surrounded with an AND that clear the
1650    low-order three bits; this is an "unaligned" access.  */
1651
1652 bool
1653 alpha_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1654 {
1655   /* If this is an ldq_u type address, discard the outer AND.  */
1656   if (mode == DImode
1657       && GET_CODE (x) == AND
1658       && GET_CODE (XEXP (x, 1)) == CONST_INT
1659       && INTVAL (XEXP (x, 1)) == -8)
1660     x = XEXP (x, 0);
1661
1662   /* Discard non-paradoxical subregs.  */
1663   if (GET_CODE (x) == SUBREG
1664       && (GET_MODE_SIZE (GET_MODE (x))
1665           < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1666     x = SUBREG_REG (x);
1667
1668   /* Unadorned general registers are valid.  */
1669   if (REG_P (x)
1670       && (strict
1671           ? STRICT_REG_OK_FOR_BASE_P (x)
1672           : NONSTRICT_REG_OK_FOR_BASE_P (x)))
1673     return true;
1674
1675   /* Constant addresses (i.e. +/- 32k) are valid.  */
1676   if (CONSTANT_ADDRESS_P (x))
1677     return true;
1678
1679 #if TARGET_ABI_OPEN_VMS
1680   if (LINKAGE_SYMBOL_REF_P (x))
1681     return true;
1682 #endif
1683
1684   /* Register plus a small constant offset is valid.  */
1685   if (GET_CODE (x) == PLUS)
1686     {
1687       rtx ofs = XEXP (x, 1);
1688       x = XEXP (x, 0);
1689
1690       /* Discard non-paradoxical subregs.  */
1691       if (GET_CODE (x) == SUBREG
1692           && (GET_MODE_SIZE (GET_MODE (x))
1693               < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1694         x = SUBREG_REG (x);
1695
1696       if (REG_P (x))
1697         {
1698           if (! strict
1699               && NONSTRICT_REG_OK_FP_BASE_P (x)
1700               && GET_CODE (ofs) == CONST_INT)
1701             return true;
1702           if ((strict
1703                ? STRICT_REG_OK_FOR_BASE_P (x)
1704                : NONSTRICT_REG_OK_FOR_BASE_P (x))
1705               && CONSTANT_ADDRESS_P (ofs))
1706             return true;
1707         }
1708       else if (GET_CODE (x) == ADDRESSOF
1709                && GET_CODE (ofs) == CONST_INT)
1710         return true;
1711     }
1712
1713   /* If we're managing explicit relocations, LO_SUM is valid, as
1714      are small data symbols.  */
1715   else if (TARGET_EXPLICIT_RELOCS)
1716     {
1717       if (small_symbolic_operand (x, Pmode))
1718         return true;
1719
1720       if (GET_CODE (x) == LO_SUM)
1721         {
1722           rtx ofs = XEXP (x, 1);
1723           x = XEXP (x, 0);
1724
1725           /* Discard non-paradoxical subregs.  */
1726           if (GET_CODE (x) == SUBREG
1727               && (GET_MODE_SIZE (GET_MODE (x))
1728                   < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1729             x = SUBREG_REG (x);
1730
1731           /* Must have a valid base register.  */
1732           if (! (REG_P (x)
1733                  && (strict
1734                      ? STRICT_REG_OK_FOR_BASE_P (x)
1735                      : NONSTRICT_REG_OK_FOR_BASE_P (x))))
1736             return false;
1737
1738           /* The symbol must be local.  */
1739           if (local_symbolic_operand (ofs, Pmode)
1740               || dtp32_symbolic_operand (ofs, Pmode)
1741               || tp32_symbolic_operand (ofs, Pmode))
1742             return true;
1743         }
1744     }
1745
1746   return false;
1747 }
1748
1749 /* Build the SYMBOL_REF for __tls_get_addr.  */
1750
1751 static GTY(()) rtx tls_get_addr_libfunc;
1752
1753 static rtx
1754 get_tls_get_addr (void)
1755 {
1756   if (!tls_get_addr_libfunc)
1757     tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr");
1758   return tls_get_addr_libfunc;
1759 }
1760
1761 /* Try machine-dependent ways of modifying an illegitimate address
1762    to be legitimate.  If we find one, return the new, valid address.  */
1763
1764 rtx
1765 alpha_legitimize_address (rtx x, rtx scratch,
1766                           enum machine_mode mode ATTRIBUTE_UNUSED)
1767 {
1768   HOST_WIDE_INT addend;
1769
1770   /* If the address is (plus reg const_int) and the CONST_INT is not a
1771      valid offset, compute the high part of the constant and add it to
1772      the register.  Then our address is (plus temp low-part-const).  */
1773   if (GET_CODE (x) == PLUS
1774       && GET_CODE (XEXP (x, 0)) == REG
1775       && GET_CODE (XEXP (x, 1)) == CONST_INT
1776       && ! CONSTANT_ADDRESS_P (XEXP (x, 1)))
1777     {
1778       addend = INTVAL (XEXP (x, 1));
1779       x = XEXP (x, 0);
1780       goto split_addend;
1781     }
1782
1783   /* If the address is (const (plus FOO const_int)), find the low-order
1784      part of the CONST_INT.  Then load FOO plus any high-order part of the
1785      CONST_INT into a register.  Our address is (plus reg low-part-const).
1786      This is done to reduce the number of GOT entries.  */
1787   if (!no_new_pseudos
1788       && GET_CODE (x) == CONST
1789       && GET_CODE (XEXP (x, 0)) == PLUS
1790       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1791     {
1792       addend = INTVAL (XEXP (XEXP (x, 0), 1));
1793       x = force_reg (Pmode, XEXP (XEXP (x, 0), 0));
1794       goto split_addend;
1795     }
1796
1797   /* If we have a (plus reg const), emit the load as in (2), then add
1798      the two registers, and finally generate (plus reg low-part-const) as
1799      our address.  */
1800   if (!no_new_pseudos
1801       && GET_CODE (x) == PLUS
1802       && GET_CODE (XEXP (x, 0)) == REG
1803       && GET_CODE (XEXP (x, 1)) == CONST
1804       && GET_CODE (XEXP (XEXP (x, 1), 0)) == PLUS
1805       && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == CONST_INT)
1806     {
1807       addend = INTVAL (XEXP (XEXP (XEXP (x, 1), 0), 1));
1808       x = expand_simple_binop (Pmode, PLUS, XEXP (x, 0),
1809                                XEXP (XEXP (XEXP (x, 1), 0), 0),
1810                                NULL_RTX, 1, OPTAB_LIB_WIDEN);
1811       goto split_addend;
1812     }
1813
1814   /* If this is a local symbol, split the address into HIGH/LO_SUM parts.  */
1815   if (TARGET_EXPLICIT_RELOCS && symbolic_operand (x, Pmode))
1816     {
1817       rtx r0, r16, eqv, tga, tp, insn, dest, seq;
1818
1819       switch (tls_symbolic_operand_type (x))
1820         {
1821         case TLS_MODEL_GLOBAL_DYNAMIC:
1822           start_sequence ();
1823
1824           r0 = gen_rtx_REG (Pmode, 0);
1825           r16 = gen_rtx_REG (Pmode, 16);
1826           tga = get_tls_get_addr ();
1827           dest = gen_reg_rtx (Pmode);
1828           seq = GEN_INT (alpha_next_sequence_number++);
1829           
1830           emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq));
1831           insn = gen_call_value_osf_tlsgd (r0, tga, seq);
1832           insn = emit_call_insn (insn);
1833           CONST_OR_PURE_CALL_P (insn) = 1;
1834           use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16);
1835
1836           insn = get_insns ();
1837           end_sequence ();
1838
1839           emit_libcall_block (insn, dest, r0, x);
1840           return dest;
1841
1842         case TLS_MODEL_LOCAL_DYNAMIC:
1843           start_sequence ();
1844
1845           r0 = gen_rtx_REG (Pmode, 0);
1846           r16 = gen_rtx_REG (Pmode, 16);
1847           tga = get_tls_get_addr ();
1848           scratch = gen_reg_rtx (Pmode);
1849           seq = GEN_INT (alpha_next_sequence_number++);
1850
1851           emit_insn (gen_movdi_er_tlsldm (r16, pic_offset_table_rtx, seq));
1852           insn = gen_call_value_osf_tlsldm (r0, tga, seq);
1853           insn = emit_call_insn (insn);
1854           CONST_OR_PURE_CALL_P (insn) = 1;
1855           use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16);
1856
1857           insn = get_insns ();
1858           end_sequence ();
1859
1860           eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
1861                                 UNSPEC_TLSLDM_CALL);
1862           emit_libcall_block (insn, scratch, r0, eqv);
1863
1864           eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPREL);
1865           eqv = gen_rtx_CONST (Pmode, eqv);
1866
1867           if (alpha_tls_size == 64)
1868             {
1869               dest = gen_reg_rtx (Pmode);
1870               emit_insn (gen_rtx_SET (VOIDmode, dest, eqv));
1871               emit_insn (gen_adddi3 (dest, dest, scratch));
1872               return dest;
1873             }
1874           if (alpha_tls_size == 32)
1875             {
1876               insn = gen_rtx_HIGH (Pmode, eqv);
1877               insn = gen_rtx_PLUS (Pmode, scratch, insn);
1878               scratch = gen_reg_rtx (Pmode);
1879               emit_insn (gen_rtx_SET (VOIDmode, scratch, insn));
1880             }
1881           return gen_rtx_LO_SUM (Pmode, scratch, eqv);
1882
1883         case TLS_MODEL_INITIAL_EXEC:
1884           eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_TPREL);
1885           eqv = gen_rtx_CONST (Pmode, eqv);
1886           tp = gen_reg_rtx (Pmode);
1887           scratch = gen_reg_rtx (Pmode);
1888           dest = gen_reg_rtx (Pmode);
1889
1890           emit_insn (gen_load_tp (tp));
1891           emit_insn (gen_rtx_SET (VOIDmode, scratch, eqv));
1892           emit_insn (gen_adddi3 (dest, tp, scratch));
1893           return dest;
1894
1895         case TLS_MODEL_LOCAL_EXEC:
1896           eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_TPREL);
1897           eqv = gen_rtx_CONST (Pmode, eqv);
1898           tp = gen_reg_rtx (Pmode);
1899
1900           emit_insn (gen_load_tp (tp));
1901           if (alpha_tls_size == 32)
1902             {
1903               insn = gen_rtx_HIGH (Pmode, eqv);
1904               insn = gen_rtx_PLUS (Pmode, tp, insn);
1905               tp = gen_reg_rtx (Pmode);
1906               emit_insn (gen_rtx_SET (VOIDmode, tp, insn));
1907             }
1908           return gen_rtx_LO_SUM (Pmode, tp, eqv);
1909         }
1910
1911       if (local_symbolic_operand (x, Pmode))
1912         {
1913           if (small_symbolic_operand (x, Pmode))
1914             return x;
1915           else
1916             {
1917               if (!no_new_pseudos)
1918                 scratch = gen_reg_rtx (Pmode);
1919               emit_insn (gen_rtx_SET (VOIDmode, scratch,
1920                                       gen_rtx_HIGH (Pmode, x)));
1921               return gen_rtx_LO_SUM (Pmode, scratch, x);
1922             }
1923         }
1924     }
1925
1926   return NULL;
1927
1928  split_addend:
1929   {
1930     HOST_WIDE_INT low, high;
1931
1932     low = ((addend & 0xffff) ^ 0x8000) - 0x8000;
1933     addend -= low;
1934     high = ((addend & 0xffffffff) ^ 0x80000000) - 0x80000000;
1935     addend -= high;
1936
1937     if (addend)
1938       x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (addend),
1939                                (no_new_pseudos ? scratch : NULL_RTX),
1940                                1, OPTAB_LIB_WIDEN);
1941     if (high)
1942       x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (high),
1943                                (no_new_pseudos ? scratch : NULL_RTX),
1944                                1, OPTAB_LIB_WIDEN);
1945
1946     return plus_constant (x, low);
1947   }
1948 }
1949
1950 /* Primarily this is required for TLS symbols, but given that our move
1951    patterns *ought* to be able to handle any symbol at any time, we
1952    should never be spilling symbolic operands to the constant pool, ever.  */
1953
1954 static bool
1955 alpha_cannot_force_const_mem (rtx x)
1956 {
1957   enum rtx_code code = GET_CODE (x);
1958   return code == SYMBOL_REF || code == LABEL_REF || code == CONST;
1959 }
1960
1961 /* We do not allow indirect calls to be optimized into sibling calls, nor
1962    can we allow a call to a function with a different GP to be optimized
1963    into a sibcall.  */
1964
1965 static bool
1966 alpha_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
1967 {
1968   /* Can't do indirect tail calls, since we don't know if the target
1969      uses the same GP.  */
1970   if (!decl)
1971     return false;
1972
1973   /* Otherwise, we can make a tail call if the target function shares
1974      the same GP.  */
1975   return decl_has_samegp (decl);
1976 }
1977
1978 /* For TARGET_EXPLICIT_RELOCS, we don't obfuscate a SYMBOL_REF to a
1979    small symbolic operand until after reload.  At which point we need
1980    to replace (mem (symbol_ref)) with (mem (lo_sum $29 symbol_ref))
1981    so that sched2 has the proper dependency information.  */
1982
1983 static int
1984 some_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
1985 {
1986   rtx x = *px;
1987
1988   /* Don't re-split.  */
1989   if (GET_CODE (x) == LO_SUM)
1990     return -1;
1991
1992   return small_symbolic_operand (x, Pmode) != 0;
1993 }
1994
1995 int
1996 some_small_symbolic_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1997 {
1998   return for_each_rtx (&x, some_small_symbolic_operand_1, NULL);
1999 }
2000
2001 static int
2002 split_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
2003 {
2004   rtx x = *px;
2005
2006   /* Don't re-split.  */
2007   if (GET_CODE (x) == LO_SUM)
2008     return -1;
2009
2010   if (small_symbolic_operand (x, Pmode))
2011     {
2012       x = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, x);
2013       *px = x;
2014       return -1;
2015     }
2016
2017   return 0;
2018 }
2019
2020 rtx
2021 split_small_symbolic_operand (rtx x)
2022 {
2023   x = copy_insn (x);
2024   for_each_rtx (&x, split_small_symbolic_operand_1, NULL);
2025   return x;
2026 }
2027
2028 /* Indicate that INSN cannot be duplicated.  This is true for any insn
2029    that we've marked with gpdisp relocs, since those have to stay in
2030    1-1 correspondence with one another.
2031
2032    Technically we could copy them if we could set up a mapping from one
2033    sequence number to another, across the set of insns to be duplicated.
2034    This seems overly complicated and error-prone since interblock motion
2035    from sched-ebb could move one of the pair of insns to a different block.
2036
2037    Also cannot allow jsr insns to be duplicated.  If they throw exceptions,
2038    then they'll be in a different block from their ldgp.  Which could lead
2039    the bb reorder code to think that it would be ok to copy just the block
2040    containing the call and branch to the block containing the ldgp.  */
2041
2042 static bool
2043 alpha_cannot_copy_insn_p (rtx insn)
2044 {
2045   if (!reload_completed || !TARGET_EXPLICIT_RELOCS)
2046     return false;
2047   if (recog_memoized (insn) >= 0)
2048     return get_attr_cannot_copy (insn);
2049   else
2050     return false;
2051 }
2052
2053   
2054 /* Try a machine-dependent way of reloading an illegitimate address
2055    operand.  If we find one, push the reload and return the new rtx.  */
2056    
2057 rtx
2058 alpha_legitimize_reload_address (rtx x,
2059                                  enum machine_mode mode ATTRIBUTE_UNUSED,
2060                                  int opnum, int type,
2061                                  int ind_levels ATTRIBUTE_UNUSED)
2062 {
2063   /* We must recognize output that we have already generated ourselves.  */
2064   if (GET_CODE (x) == PLUS
2065       && GET_CODE (XEXP (x, 0)) == PLUS
2066       && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2067       && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2068       && GET_CODE (XEXP (x, 1)) == CONST_INT)
2069     {
2070       push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2071                    BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2072                    opnum, type);
2073       return x;
2074     }
2075
2076   /* We wish to handle large displacements off a base register by
2077      splitting the addend across an ldah and the mem insn.  This
2078      cuts number of extra insns needed from 3 to 1.  */
2079   if (GET_CODE (x) == PLUS
2080       && GET_CODE (XEXP (x, 0)) == REG
2081       && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2082       && REGNO_OK_FOR_BASE_P (REGNO (XEXP (x, 0)))
2083       && GET_CODE (XEXP (x, 1)) == CONST_INT)
2084     {
2085       HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2086       HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2087       HOST_WIDE_INT high
2088         = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2089
2090       /* Check for 32-bit overflow.  */
2091       if (high + low != val)
2092         return NULL_RTX;
2093
2094       /* Reload the high part into a base reg; leave the low part
2095          in the mem directly.  */
2096       x = gen_rtx_PLUS (GET_MODE (x),
2097                         gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2098                                       GEN_INT (high)),
2099                         GEN_INT (low));
2100
2101       push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2102                    BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2103                    opnum, type);
2104       return x;
2105     }
2106
2107   return NULL_RTX;
2108 }
2109 \f
2110 /* Compute a (partial) cost for rtx X.  Return true if the complete
2111    cost has been computed, and false if subexpressions should be
2112    scanned.  In either case, *TOTAL contains the cost result.  */
2113
2114 static bool
2115 alpha_rtx_costs (rtx x, int code, int outer_code, int *total)
2116 {
2117   enum machine_mode mode = GET_MODE (x);
2118   bool float_mode_p = FLOAT_MODE_P (mode);
2119
2120   switch (code)
2121     {
2122       /* If this is an 8-bit constant, return zero since it can be used
2123          nearly anywhere with no cost.  If it is a valid operand for an
2124          ADD or AND, likewise return 0 if we know it will be used in that
2125          context.  Otherwise, return 2 since it might be used there later.
2126          All other constants take at least two insns.  */
2127     case CONST_INT:
2128       if (INTVAL (x) >= 0 && INTVAL (x) < 256)
2129         {
2130           *total = 0;
2131           return true;
2132         }
2133       /* FALLTHRU */
2134
2135     case CONST_DOUBLE:
2136       if (x == CONST0_RTX (mode))
2137         *total = 0;
2138       else if ((outer_code == PLUS && add_operand (x, VOIDmode))
2139                || (outer_code == AND && and_operand (x, VOIDmode)))
2140         *total = 0;
2141       else if (add_operand (x, VOIDmode) || and_operand (x, VOIDmode))
2142         *total = 2;
2143       else
2144         *total = COSTS_N_INSNS (2);
2145       return true;
2146       
2147     case CONST:
2148     case SYMBOL_REF:
2149     case LABEL_REF:
2150       if (TARGET_EXPLICIT_RELOCS && small_symbolic_operand (x, VOIDmode))
2151         *total = COSTS_N_INSNS (outer_code != MEM);
2152       else if (TARGET_EXPLICIT_RELOCS && local_symbolic_operand (x, VOIDmode))
2153         *total = COSTS_N_INSNS (1 + (outer_code != MEM));
2154       else if (tls_symbolic_operand_type (x))
2155         /* Estimate of cost for call_pal rduniq.  */
2156         *total = COSTS_N_INSNS (15);
2157       else
2158         /* Otherwise we do a load from the GOT.  */
2159         *total = COSTS_N_INSNS (alpha_memory_latency);
2160       return true;
2161     
2162     case PLUS:
2163     case MINUS:
2164       if (float_mode_p)
2165         *total = alpha_rtx_cost_data[alpha_cpu].fp_add;
2166       else if (GET_CODE (XEXP (x, 0)) == MULT
2167                && const48_operand (XEXP (XEXP (x, 0), 1), VOIDmode))
2168         {
2169           *total = (rtx_cost (XEXP (XEXP (x, 0), 0), outer_code)
2170                     + rtx_cost (XEXP (x, 1), outer_code) + 2);
2171           return true;
2172         }
2173       return false;
2174
2175     case MULT:
2176       if (float_mode_p)
2177         *total = alpha_rtx_cost_data[alpha_cpu].fp_mult;
2178       else if (mode == DImode)
2179         *total = alpha_rtx_cost_data[alpha_cpu].int_mult_di;
2180       else
2181         *total = alpha_rtx_cost_data[alpha_cpu].int_mult_si;
2182       return false;
2183
2184     case ASHIFT:
2185       if (GET_CODE (XEXP (x, 1)) == CONST_INT
2186           && INTVAL (XEXP (x, 1)) <= 3)
2187         {
2188           *total = COSTS_N_INSNS (1);
2189           return false;
2190         }
2191       /* FALLTHRU */
2192
2193     case ASHIFTRT:
2194     case LSHIFTRT:
2195       *total = alpha_rtx_cost_data[alpha_cpu].int_shift;
2196       return false;
2197
2198     case IF_THEN_ELSE:
2199       if (float_mode_p)
2200         *total = alpha_rtx_cost_data[alpha_cpu].fp_add;
2201       else
2202         *total = alpha_rtx_cost_data[alpha_cpu].int_cmov;
2203       return false;
2204
2205     case DIV:
2206     case UDIV:
2207     case MOD:
2208     case UMOD:
2209       if (!float_mode_p)
2210         *total = COSTS_N_INSNS (70);    /* ??? */
2211       else if (mode == SFmode)
2212         *total = alpha_rtx_cost_data[alpha_cpu].fp_div_sf;
2213       else
2214         *total = alpha_rtx_cost_data[alpha_cpu].fp_div_df;
2215       return false;
2216
2217     case MEM:
2218       *total = COSTS_N_INSNS (alpha_memory_latency);
2219       return true;
2220
2221     case NEG:
2222       if (! float_mode_p)
2223         {
2224           *total = COSTS_N_INSNS (1);
2225           return false;
2226         }
2227       /* FALLTHRU */
2228
2229     case ABS:
2230       if (! float_mode_p)
2231         {
2232           *total = COSTS_N_INSNS (1) + alpha_rtx_cost_data[alpha_cpu].int_cmov;
2233           return false;
2234         }
2235       /* FALLTHRU */
2236
2237     case FLOAT:
2238     case UNSIGNED_FLOAT:
2239     case FIX:
2240     case UNSIGNED_FIX:
2241     case FLOAT_EXTEND:
2242     case FLOAT_TRUNCATE:
2243       *total = alpha_rtx_cost_data[alpha_cpu].fp_add;
2244       return false;
2245
2246     default:
2247       return false;
2248     }
2249 }
2250 \f
2251 /* REF is an alignable memory location.  Place an aligned SImode
2252    reference into *PALIGNED_MEM and the number of bits to shift into
2253    *PBITNUM.  SCRATCH is a free register for use in reloading out
2254    of range stack slots.  */
2255
2256 void
2257 get_aligned_mem (rtx ref, rtx *paligned_mem, rtx *pbitnum)
2258 {
2259   rtx base;
2260   HOST_WIDE_INT offset = 0;
2261
2262   if (GET_CODE (ref) != MEM)
2263     abort ();
2264
2265   if (reload_in_progress
2266       && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2267     {
2268       base = find_replacement (&XEXP (ref, 0));
2269
2270       if (! memory_address_p (GET_MODE (ref), base))
2271         abort ();
2272     }
2273   else
2274     {
2275       base = XEXP (ref, 0);
2276     }
2277
2278   if (GET_CODE (base) == PLUS)
2279     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2280
2281   *paligned_mem
2282     = widen_memory_access (ref, SImode, (offset & ~3) - offset);
2283
2284   if (WORDS_BIG_ENDIAN)
2285     *pbitnum = GEN_INT (32 - (GET_MODE_BITSIZE (GET_MODE (ref))
2286                               + (offset & 3) * 8));
2287   else
2288     *pbitnum = GEN_INT ((offset & 3) * 8);
2289 }
2290
2291 /* Similar, but just get the address.  Handle the two reload cases.  
2292    Add EXTRA_OFFSET to the address we return.  */
2293
2294 rtx
2295 get_unaligned_address (rtx ref, int extra_offset)
2296 {
2297   rtx base;
2298   HOST_WIDE_INT offset = 0;
2299
2300   if (GET_CODE (ref) != MEM)
2301     abort ();
2302
2303   if (reload_in_progress
2304       && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2305     {
2306       base = find_replacement (&XEXP (ref, 0));
2307
2308       if (! memory_address_p (GET_MODE (ref), base))
2309         abort ();
2310     }
2311   else
2312     {
2313       base = XEXP (ref, 0);
2314     }
2315
2316   if (GET_CODE (base) == PLUS)
2317     offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2318
2319   return plus_constant (base, offset + extra_offset);
2320 }
2321
2322 /* On the Alpha, all (non-symbolic) constants except zero go into
2323    a floating-point register via memory.  Note that we cannot 
2324    return anything that is not a subset of CLASS, and that some
2325    symbolic constants cannot be dropped to memory.  */
2326
2327 enum reg_class
2328 alpha_preferred_reload_class(rtx x, enum reg_class class)
2329 {
2330   /* Zero is present in any register class.  */
2331   if (x == CONST0_RTX (GET_MODE (x)))
2332     return class;
2333
2334   /* These sorts of constants we can easily drop to memory.  */
2335   if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
2336     {
2337       if (class == FLOAT_REGS)
2338         return NO_REGS;
2339       if (class == ALL_REGS)
2340         return GENERAL_REGS;
2341       return class;
2342     }
2343
2344   /* All other kinds of constants should not (and in the case of HIGH
2345      cannot) be dropped to memory -- instead we use a GENERAL_REGS
2346      secondary reload.  */
2347   if (CONSTANT_P (x))
2348     return (class == ALL_REGS ? GENERAL_REGS : class);
2349
2350   return class;
2351 }
2352
2353 /* Loading and storing HImode or QImode values to and from memory
2354    usually requires a scratch register.  The exceptions are loading
2355    QImode and HImode from an aligned address to a general register
2356    unless byte instructions are permitted. 
2357
2358    We also cannot load an unaligned address or a paradoxical SUBREG
2359    into an FP register. 
2360
2361    We also cannot do integral arithmetic into FP regs, as might result
2362    from register elimination into a DImode fp register.  */
2363
2364 enum reg_class
2365 secondary_reload_class (enum reg_class class, enum machine_mode mode,
2366                         rtx x, int in)
2367 {
2368   if ((mode == QImode || mode == HImode) && ! TARGET_BWX)
2369     {
2370       if (GET_CODE (x) == MEM
2371           || (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2372           || (GET_CODE (x) == SUBREG
2373               && (GET_CODE (SUBREG_REG (x)) == MEM
2374                   || (GET_CODE (SUBREG_REG (x)) == REG
2375                       && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER))))
2376         {
2377           if (!in || !aligned_memory_operand(x, mode))
2378             return GENERAL_REGS;
2379         }
2380     }
2381
2382   if (class == FLOAT_REGS)
2383     {
2384       if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
2385         return GENERAL_REGS;
2386
2387       if (GET_CODE (x) == SUBREG
2388           && (GET_MODE_SIZE (GET_MODE (x))
2389               > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
2390         return GENERAL_REGS;
2391
2392       if (in && INTEGRAL_MODE_P (mode)
2393           && ! (memory_operand (x, mode) || x == const0_rtx))
2394         return GENERAL_REGS;
2395     }
2396
2397   return NO_REGS;
2398 }
2399 \f
2400 /* Subfunction of the following function.  Update the flags of any MEM
2401    found in part of X.  */
2402
2403 static void
2404 alpha_set_memflags_1 (rtx x, int in_struct_p, int volatile_p, int unchanging_p)
2405 {
2406   int i;
2407
2408   switch (GET_CODE (x))
2409     {
2410     case SEQUENCE:
2411       abort ();
2412
2413     case PARALLEL:
2414       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2415         alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
2416                               unchanging_p);
2417       break;
2418
2419     case INSN:
2420       alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
2421                             unchanging_p);
2422       break;
2423
2424     case SET:
2425       alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
2426                             unchanging_p);
2427       alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p,
2428                             unchanging_p);
2429       break;
2430
2431     case MEM:
2432       MEM_IN_STRUCT_P (x) = in_struct_p;
2433       MEM_VOLATILE_P (x) = volatile_p;
2434       RTX_UNCHANGING_P (x) = unchanging_p;
2435       /* Sadly, we cannot use alias sets because the extra aliasing
2436          produced by the AND interferes.  Given that two-byte quantities
2437          are the only thing we would be able to differentiate anyway,
2438          there does not seem to be any point in convoluting the early
2439          out of the alias check.  */
2440       break;
2441
2442     default:
2443       break;
2444     }
2445 }
2446
2447 /* Given INSN, which is an INSN list or the PATTERN of a single insn
2448    generated to perform a memory operation, look for any MEMs in either
2449    a SET_DEST or a SET_SRC and copy the in-struct, unchanging, and
2450    volatile flags from REF into each of the MEMs found.  If REF is not
2451    a MEM, don't do anything.  */
2452
2453 void
2454 alpha_set_memflags (rtx insn, rtx ref)
2455 {
2456   int in_struct_p, volatile_p, unchanging_p;
2457
2458   if (GET_CODE (ref) != MEM)
2459     return;
2460
2461   in_struct_p = MEM_IN_STRUCT_P (ref);
2462   volatile_p = MEM_VOLATILE_P (ref);
2463   unchanging_p = RTX_UNCHANGING_P (ref);
2464
2465   /* This is only called from alpha.md, after having had something 
2466      generated from one of the insn patterns.  So if everything is
2467      zero, the pattern is already up-to-date.  */
2468   if (! in_struct_p && ! volatile_p && ! unchanging_p)
2469     return;
2470
2471   alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
2472 }
2473 \f
2474 /* Internal routine for alpha_emit_set_const to check for N or below insns.  */
2475
2476 static rtx
2477 alpha_emit_set_const_1 (rtx target, enum machine_mode mode,
2478                         HOST_WIDE_INT c, int n)
2479 {
2480   HOST_WIDE_INT new;
2481   int i, bits;
2482   /* Use a pseudo if highly optimizing and still generating RTL.  */
2483   rtx subtarget
2484     = (flag_expensive_optimizations && !no_new_pseudos ? 0 : target);
2485   rtx temp, insn;
2486
2487   /* If this is a sign-extended 32-bit constant, we can do this in at most
2488      three insns, so do it if we have enough insns left.  We always have
2489      a sign-extended 32-bit constant when compiling on a narrow machine.  */
2490
2491   if (HOST_BITS_PER_WIDE_INT != 64
2492       || c >> 31 == -1 || c >> 31 == 0)
2493     {
2494       HOST_WIDE_INT low = ((c & 0xffff) ^ 0x8000) - 0x8000;
2495       HOST_WIDE_INT tmp1 = c - low;
2496       HOST_WIDE_INT high = (((tmp1 >> 16) & 0xffff) ^ 0x8000) - 0x8000;
2497       HOST_WIDE_INT extra = 0;
2498
2499       /* If HIGH will be interpreted as negative but the constant is
2500          positive, we must adjust it to do two ldha insns.  */
2501
2502       if ((high & 0x8000) != 0 && c >= 0)
2503         {
2504           extra = 0x4000;
2505           tmp1 -= 0x40000000;
2506           high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
2507         }
2508
2509       if (c == low || (low == 0 && extra == 0))
2510         {
2511           /* We used to use copy_to_suggested_reg (GEN_INT (c), target, mode)
2512              but that meant that we can't handle INT_MIN on 32-bit machines
2513              (like NT/Alpha), because we recurse indefinitely through 
2514              emit_move_insn to gen_movdi.  So instead, since we know exactly
2515              what we want, create it explicitly.  */
2516
2517           if (target == NULL)
2518             target = gen_reg_rtx (mode);
2519           emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (c)));
2520           return target;
2521         }
2522       else if (n >= 2 + (extra != 0))
2523         {
2524           if (no_new_pseudos)
2525             {
2526               emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (high << 16)));
2527               temp = target;
2528             }
2529           else
2530             temp = copy_to_suggested_reg (GEN_INT (high << 16),
2531                                           subtarget, mode);
2532
2533           /* As of 2002-02-23, addsi3 is only available when not optimizing.
2534              This means that if we go through expand_binop, we'll try to
2535              generate extensions, etc, which will require new pseudos, which
2536              will fail during some split phases.  The SImode add patterns
2537              still exist, but are not named.  So build the insns by hand.  */
2538
2539           if (extra != 0)
2540             {
2541               if (! subtarget)
2542                 subtarget = gen_reg_rtx (mode);
2543               insn = gen_rtx_PLUS (mode, temp, GEN_INT (extra << 16));
2544               insn = gen_rtx_SET (VOIDmode, subtarget, insn);
2545               emit_insn (insn);
2546               temp = subtarget;
2547             }
2548
2549           if (target == NULL)
2550             target = gen_reg_rtx (mode);
2551           insn = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2552           insn = gen_rtx_SET (VOIDmode, target, insn);
2553           emit_insn (insn);
2554           return target;
2555         }
2556     }
2557
2558   /* If we couldn't do it that way, try some other methods.  But if we have
2559      no instructions left, don't bother.  Likewise, if this is SImode and
2560      we can't make pseudos, we can't do anything since the expand_binop
2561      and expand_unop calls will widen and try to make pseudos.  */
2562
2563   if (n == 1 || (mode == SImode && no_new_pseudos))
2564     return 0;
2565
2566   /* Next, see if we can load a related constant and then shift and possibly
2567      negate it to get the constant we want.  Try this once each increasing
2568      numbers of insns.  */
2569
2570   for (i = 1; i < n; i++)
2571     {
2572       /* First, see if minus some low bits, we've an easy load of
2573          high bits.  */
2574
2575       new = ((c & 0xffff) ^ 0x8000) - 0x8000;
2576       if (new != 0
2577           && (temp = alpha_emit_set_const (subtarget, mode, c - new, i)) != 0)
2578         return expand_binop (mode, add_optab, temp, GEN_INT (new),
2579                              target, 0, OPTAB_WIDEN);
2580
2581       /* Next try complementing.  */
2582       if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0)
2583         return expand_unop (mode, one_cmpl_optab, temp, target, 0);
2584
2585       /* Next try to form a constant and do a left shift.  We can do this
2586          if some low-order bits are zero; the exact_log2 call below tells
2587          us that information.  The bits we are shifting out could be any
2588          value, but here we'll just try the 0- and sign-extended forms of
2589          the constant.  To try to increase the chance of having the same
2590          constant in more than one insn, start at the highest number of
2591          bits to shift, but try all possibilities in case a ZAPNOT will
2592          be useful.  */
2593
2594       if ((bits = exact_log2 (c & - c)) > 0)
2595         for (; bits > 0; bits--)
2596           if ((temp = (alpha_emit_set_const
2597                        (subtarget, mode, c >> bits, i))) != 0
2598               || ((temp = (alpha_emit_set_const
2599                           (subtarget, mode,
2600                            ((unsigned HOST_WIDE_INT) c) >> bits, i)))
2601                   != 0))
2602             return expand_binop (mode, ashl_optab, temp, GEN_INT (bits),
2603                                  target, 0, OPTAB_WIDEN);
2604
2605       /* Now try high-order zero bits.  Here we try the shifted-in bits as
2606          all zero and all ones.  Be careful to avoid shifting outside the
2607          mode and to avoid shifting outside the host wide int size.  */
2608       /* On narrow hosts, don't shift a 1 into the high bit, since we'll
2609          confuse the recursive call and set all of the high 32 bits.  */
2610
2611       if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
2612                    - floor_log2 (c) - 1 - (HOST_BITS_PER_WIDE_INT < 64))) > 0)
2613         for (; bits > 0; bits--)
2614           if ((temp = alpha_emit_set_const (subtarget, mode,
2615                                             c << bits, i)) != 0
2616               || ((temp = (alpha_emit_set_const
2617                            (subtarget, mode,
2618                             ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
2619                             i)))
2620                   != 0))
2621             return expand_binop (mode, lshr_optab, temp, GEN_INT (bits),
2622                                  target, 1, OPTAB_WIDEN);
2623
2624       /* Now try high-order 1 bits.  We get that with a sign-extension.
2625          But one bit isn't enough here.  Be careful to avoid shifting outside
2626          the mode and to avoid shifting outside the host wide int size.  */
2627
2628       if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
2629                    - floor_log2 (~ c) - 2)) > 0)
2630         for (; bits > 0; bits--)
2631           if ((temp = alpha_emit_set_const (subtarget, mode,
2632                                             c << bits, i)) != 0
2633               || ((temp = (alpha_emit_set_const
2634                            (subtarget, mode,
2635                             ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
2636                             i)))
2637                   != 0))
2638             return expand_binop (mode, ashr_optab, temp, GEN_INT (bits),
2639                                  target, 0, OPTAB_WIDEN);
2640     }
2641
2642 #if HOST_BITS_PER_WIDE_INT == 64
2643   /* Finally, see if can load a value into the target that is the same as the
2644      constant except that all bytes that are 0 are changed to be 0xff.  If we
2645      can, then we can do a ZAPNOT to obtain the desired constant.  */
2646
2647   new = c;
2648   for (i = 0; i < 64; i += 8)
2649     if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
2650       new |= (HOST_WIDE_INT) 0xff << i;
2651
2652   /* We are only called for SImode and DImode.  If this is SImode, ensure that
2653      we are sign extended to a full word.  */
2654
2655   if (mode == SImode)
2656     new = ((new & 0xffffffff) ^ 0x80000000) - 0x80000000;
2657
2658   if (new != c && new != -1
2659       && (temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0)
2660     return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new),
2661                          target, 0, OPTAB_WIDEN);
2662 #endif
2663
2664   return 0;
2665 }
2666
2667 /* Try to output insns to set TARGET equal to the constant C if it can be
2668    done in less than N insns.  Do all computations in MODE.  Returns the place
2669    where the output has been placed if it can be done and the insns have been
2670    emitted.  If it would take more than N insns, zero is returned and no
2671    insns and emitted.  */
2672
2673 rtx
2674 alpha_emit_set_const (rtx target, enum machine_mode mode,
2675                       HOST_WIDE_INT c, int n)
2676 {
2677   rtx result = 0;
2678   rtx orig_target = target;
2679   int i;
2680
2681   /* If we can't make any pseudos, TARGET is an SImode hard register, we
2682      can't load this constant in one insn, do this in DImode.  */
2683   if (no_new_pseudos && mode == SImode
2684       && GET_CODE (target) == REG && REGNO (target) < FIRST_PSEUDO_REGISTER
2685       && (result = alpha_emit_set_const_1 (target, mode, c, 1)) == 0)
2686     {
2687       target = gen_lowpart (DImode, target);
2688       mode = DImode;
2689     }
2690
2691   /* Try 1 insn, then 2, then up to N.  */
2692   for (i = 1; i <= n; i++)
2693     {
2694       result = alpha_emit_set_const_1 (target, mode, c, i);
2695       if (result)
2696         {
2697           rtx insn = get_last_insn ();
2698           rtx set = single_set (insn);
2699           if (! CONSTANT_P (SET_SRC (set)))
2700             set_unique_reg_note (get_last_insn (), REG_EQUAL, GEN_INT (c));
2701           break;
2702         }
2703     }
2704
2705   /* Allow for the case where we changed the mode of TARGET.  */
2706   if (result == target)
2707     result = orig_target;
2708
2709   return result;
2710 }
2711
2712 /* Having failed to find a 3 insn sequence in alpha_emit_set_const,
2713    fall back to a straight forward decomposition.  We do this to avoid
2714    exponential run times encountered when looking for longer sequences
2715    with alpha_emit_set_const.  */
2716
2717 rtx
2718 alpha_emit_set_long_const (rtx target, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2719 {
2720   HOST_WIDE_INT d1, d2, d3, d4;
2721
2722   /* Decompose the entire word */
2723 #if HOST_BITS_PER_WIDE_INT >= 64
2724   if (c2 != -(c1 < 0))
2725     abort ();
2726   d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2727   c1 -= d1;
2728   d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2729   c1 = (c1 - d2) >> 32;
2730   d3 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2731   c1 -= d3;
2732   d4 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2733   if (c1 != d4)
2734     abort ();
2735 #else
2736   d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2737   c1 -= d1;
2738   d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2739   if (c1 != d2)
2740     abort ();
2741   c2 += (d2 < 0);
2742   d3 = ((c2 & 0xffff) ^ 0x8000) - 0x8000;
2743   c2 -= d3;
2744   d4 = ((c2 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2745   if (c2 != d4)
2746     abort ();
2747 #endif
2748
2749   /* Construct the high word */
2750   if (d4)
2751     {
2752       emit_move_insn (target, GEN_INT (d4));
2753       if (d3)
2754         emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d3)));
2755     }
2756   else
2757     emit_move_insn (target, GEN_INT (d3));
2758
2759   /* Shift it into place */
2760   emit_move_insn (target, gen_rtx_ASHIFT (DImode, target, GEN_INT (32)));
2761
2762   /* Add in the low bits.  */
2763   if (d2)
2764     emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d2)));
2765   if (d1)
2766     emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d1)));
2767
2768   return target;
2769 }
2770
2771 /* Expand a move instruction; return true if all work is done.
2772    We don't handle non-bwx subword loads here.  */
2773
2774 bool
2775 alpha_expand_mov (enum machine_mode mode, rtx *operands)
2776 {
2777   /* If the output is not a register, the input must be.  */
2778   if (GET_CODE (operands[0]) == MEM
2779       && ! reg_or_0_operand (operands[1], mode))
2780     operands[1] = force_reg (mode, operands[1]);
2781
2782   /* Allow legitimize_address to perform some simplifications.  */
2783   if (mode == Pmode && symbolic_operand (operands[1], mode))
2784     {
2785       rtx tmp;
2786
2787       /* With RTL inlining, at -O3, rtl is generated, stored, then actually
2788          compiled at the end of compilation.  In the meantime, someone can
2789          re-encode-section-info on some symbol changing it e.g. from global
2790          to local-not-small.  If this happens, we'd have emitted a plain
2791          load rather than a high+losum load and not recognize the insn.
2792
2793          So if rtl inlining is in effect, we delay the global/not-global
2794          decision until rest_of_compilation by wrapping it in an
2795          UNSPEC_SYMBOL.  */
2796       if (TARGET_EXPLICIT_RELOCS && flag_inline_functions
2797           && rtx_equal_function_value_matters
2798           && global_symbolic_operand (operands[1], mode))
2799         {
2800           emit_insn (gen_movdi_er_maybe_g (operands[0], operands[1]));
2801           return true;
2802         }
2803
2804       tmp = alpha_legitimize_address (operands[1], operands[0], mode);
2805       if (tmp)
2806         {
2807           if (tmp == operands[0])
2808             return true;
2809           operands[1] = tmp;
2810           return false;
2811         }
2812     }
2813
2814   /* Early out for non-constants and valid constants.  */
2815   if (! CONSTANT_P (operands[1]) || input_operand (operands[1], mode))
2816     return false;
2817
2818   /* Split large integers.  */
2819   if (GET_CODE (operands[1]) == CONST_INT
2820       || GET_CODE (operands[1]) == CONST_DOUBLE)
2821     {
2822       HOST_WIDE_INT i0, i1;
2823       rtx temp = NULL_RTX;
2824
2825       if (GET_CODE (operands[1]) == CONST_INT)
2826         {
2827           i0 = INTVAL (operands[1]);
2828           i1 = -(i0 < 0);
2829         }
2830       else if (HOST_BITS_PER_WIDE_INT >= 64)
2831         {
2832           i0 = CONST_DOUBLE_LOW (operands[1]);
2833           i1 = -(i0 < 0);
2834         }
2835       else
2836         {
2837           i0 = CONST_DOUBLE_LOW (operands[1]);
2838           i1 = CONST_DOUBLE_HIGH (operands[1]);
2839         }
2840
2841       if (HOST_BITS_PER_WIDE_INT >= 64 || i1 == -(i0 < 0))
2842         temp = alpha_emit_set_const (operands[0], mode, i0, 3);
2843
2844       if (!temp && TARGET_BUILD_CONSTANTS)
2845         temp = alpha_emit_set_long_const (operands[0], i0, i1);
2846
2847       if (temp)
2848         {
2849           if (rtx_equal_p (operands[0], temp))
2850             return true;
2851           operands[1] = temp;
2852           return false;
2853         }
2854     }
2855
2856   /* Otherwise we've nothing left but to drop the thing to memory.  */
2857   operands[1] = force_const_mem (mode, operands[1]);
2858   if (reload_in_progress)
2859     {
2860       emit_move_insn (operands[0], XEXP (operands[1], 0));
2861       operands[1] = copy_rtx (operands[1]);
2862       XEXP (operands[1], 0) = operands[0];
2863     }
2864   else
2865     operands[1] = validize_mem (operands[1]);
2866   return false;
2867 }
2868
2869 /* Expand a non-bwx QImode or HImode move instruction;
2870    return true if all work is done.  */
2871
2872 bool
2873 alpha_expand_mov_nobwx (enum machine_mode mode, rtx *operands)
2874 {
2875   /* If the output is not a register, the input must be.  */
2876   if (GET_CODE (operands[0]) == MEM)
2877     operands[1] = force_reg (mode, operands[1]);
2878
2879   /* Handle four memory cases, unaligned and aligned for either the input
2880      or the output.  The only case where we can be called during reload is
2881      for aligned loads; all other cases require temporaries.  */
2882
2883   if (GET_CODE (operands[1]) == MEM
2884       || (GET_CODE (operands[1]) == SUBREG
2885           && GET_CODE (SUBREG_REG (operands[1])) == MEM)
2886       || (reload_in_progress && GET_CODE (operands[1]) == REG
2887           && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
2888       || (reload_in_progress && GET_CODE (operands[1]) == SUBREG
2889           && GET_CODE (SUBREG_REG (operands[1])) == REG
2890           && REGNO (SUBREG_REG (operands[1])) >= FIRST_PSEUDO_REGISTER))
2891     {
2892       if (aligned_memory_operand (operands[1], mode))
2893         {
2894           if (reload_in_progress)
2895             {
2896               emit_insn ((mode == QImode
2897                           ? gen_reload_inqi_help
2898                           : gen_reload_inhi_help)
2899                          (operands[0], operands[1],
2900                           gen_rtx_REG (SImode, REGNO (operands[0]))));
2901             }
2902           else
2903             {
2904               rtx aligned_mem, bitnum;
2905               rtx scratch = gen_reg_rtx (SImode);
2906               rtx subtarget;
2907               bool copyout;
2908
2909               get_aligned_mem (operands[1], &aligned_mem, &bitnum);
2910
2911               subtarget = operands[0];
2912               if (GET_CODE (subtarget) == REG)
2913                 subtarget = gen_lowpart (DImode, subtarget), copyout = false;
2914               else
2915                 subtarget = gen_reg_rtx (DImode), copyout = true;
2916
2917               emit_insn ((mode == QImode
2918                           ? gen_aligned_loadqi
2919                           : gen_aligned_loadhi)
2920                          (subtarget, aligned_mem, bitnum, scratch));
2921
2922               if (copyout)
2923                 emit_move_insn (operands[0], gen_lowpart (mode, subtarget));
2924             }
2925         }
2926       else
2927         {
2928           /* Don't pass these as parameters since that makes the generated
2929              code depend on parameter evaluation order which will cause
2930              bootstrap failures.  */
2931
2932           rtx temp1, temp2, seq, subtarget;
2933           bool copyout;
2934
2935           temp1 = gen_reg_rtx (DImode);
2936           temp2 = gen_reg_rtx (DImode);
2937
2938           subtarget = operands[0];
2939           if (GET_CODE (subtarget) == REG)
2940             subtarget = gen_lowpart (DImode, subtarget), copyout = false;
2941           else
2942             subtarget = gen_reg_rtx (DImode), copyout = true;
2943
2944           seq = ((mode == QImode
2945                   ? gen_unaligned_loadqi
2946                   : gen_unaligned_loadhi)
2947                  (subtarget, get_unaligned_address (operands[1], 0),
2948                   temp1, temp2));
2949           alpha_set_memflags (seq, operands[1]);
2950           emit_insn (seq);
2951
2952           if (copyout)
2953             emit_move_insn (operands[0], gen_lowpart (mode, subtarget));
2954         }
2955       return true;
2956     }
2957
2958   if (GET_CODE (operands[0]) == MEM
2959       || (GET_CODE (operands[0]) == SUBREG
2960           && GET_CODE (SUBREG_REG (operands[0])) == MEM)
2961       || (reload_in_progress && GET_CODE (operands[0]) == REG
2962           && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)
2963       || (reload_in_progress && GET_CODE (operands[0]) == SUBREG
2964           && GET_CODE (SUBREG_REG (operands[0])) == REG
2965           && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))
2966     {
2967       if (aligned_memory_operand (operands[0], mode))
2968         {
2969           rtx aligned_mem, bitnum;
2970           rtx temp1 = gen_reg_rtx (SImode);
2971           rtx temp2 = gen_reg_rtx (SImode);
2972
2973           get_aligned_mem (operands[0], &aligned_mem, &bitnum);
2974
2975           emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
2976                                         temp1, temp2));
2977         }
2978       else
2979         {
2980           rtx temp1 = gen_reg_rtx (DImode);
2981           rtx temp2 = gen_reg_rtx (DImode);
2982           rtx temp3 = gen_reg_rtx (DImode);
2983           rtx seq = ((mode == QImode
2984                       ? gen_unaligned_storeqi
2985                       : gen_unaligned_storehi)
2986                      (get_unaligned_address (operands[0], 0),
2987                       operands[1], temp1, temp2, temp3));
2988
2989           alpha_set_memflags (seq, operands[0]);
2990           emit_insn (seq);
2991         }
2992       return true;
2993     }
2994
2995   return false;
2996 }
2997
2998 /* Generate an unsigned DImode to FP conversion.  This is the same code
2999    optabs would emit if we didn't have TFmode patterns.
3000
3001    For SFmode, this is the only construction I've found that can pass
3002    gcc.c-torture/execute/ieee/rbug.c.  No scenario that uses DFmode
3003    intermediates will work, because you'll get intermediate rounding
3004    that ruins the end result.  Some of this could be fixed by turning
3005    on round-to-positive-infinity, but that requires diddling the fpsr,
3006    which kills performance.  I tried turning this around and converting
3007    to a negative number, so that I could turn on /m, but either I did
3008    it wrong or there's something else cause I wound up with the exact
3009    same single-bit error.  There is a branch-less form of this same code:
3010
3011         srl     $16,1,$1
3012         and     $16,1,$2
3013         cmplt   $16,0,$3
3014         or      $1,$2,$2
3015         cmovge  $16,$16,$2
3016         itoft   $3,$f10
3017         itoft   $2,$f11
3018         cvtqs   $f11,$f11
3019         adds    $f11,$f11,$f0
3020         fcmoveq $f10,$f11,$f0
3021
3022    I'm not using it because it's the same number of instructions as
3023    this branch-full form, and it has more serialized long latency
3024    instructions on the critical path.
3025
3026    For DFmode, we can avoid rounding errors by breaking up the word
3027    into two pieces, converting them separately, and adding them back:
3028
3029    LC0: .long 0,0x5f800000
3030
3031         itoft   $16,$f11
3032         lda     $2,LC0
3033         cmplt   $16,0,$1
3034         cpyse   $f11,$f31,$f10
3035         cpyse   $f31,$f11,$f11
3036         s4addq  $1,$2,$1
3037         lds     $f12,0($1)
3038         cvtqt   $f10,$f10
3039         cvtqt   $f11,$f11
3040         addt    $f12,$f10,$f0
3041         addt    $f0,$f11,$f0
3042
3043    This doesn't seem to be a clear-cut win over the optabs form.
3044    It probably all depends on the distribution of numbers being
3045    converted -- in the optabs form, all but high-bit-set has a
3046    much lower minimum execution time.  */
3047
3048 void
3049 alpha_emit_floatuns (rtx operands[2])
3050 {
3051   rtx neglab, donelab, i0, i1, f0, in, out;
3052   enum machine_mode mode;
3053
3054   out = operands[0];
3055   in = force_reg (DImode, operands[1]);
3056   mode = GET_MODE (out);
3057   neglab = gen_label_rtx ();
3058   donelab = gen_label_rtx ();
3059   i0 = gen_reg_rtx (DImode);
3060   i1 = gen_reg_rtx (DImode);
3061   f0 = gen_reg_rtx (mode);
3062
3063   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
3064
3065   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
3066   emit_jump_insn (gen_jump (donelab));
3067   emit_barrier ();
3068
3069   emit_label (neglab);
3070
3071   emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
3072   emit_insn (gen_anddi3 (i1, in, const1_rtx));
3073   emit_insn (gen_iordi3 (i0, i0, i1));
3074   emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
3075   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
3076
3077   emit_label (donelab);
3078 }
3079
3080 /* Generate the comparison for a conditional branch.  */
3081
3082 rtx
3083 alpha_emit_conditional_branch (enum rtx_code code)
3084 {
3085   enum rtx_code cmp_code, branch_code;
3086   enum machine_mode cmp_mode, branch_mode = VOIDmode;
3087   rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1;
3088   rtx tem;
3089
3090   if (alpha_compare.fp_p && GET_MODE (op0) == TFmode)
3091     {
3092       if (! TARGET_HAS_XFLOATING_LIBS)
3093         abort ();
3094
3095       /* X_floating library comparison functions return
3096            -1  unordered
3097             0  false
3098             1  true
3099          Convert the compare against the raw return value.  */
3100
3101       switch (code)
3102         {
3103         case UNORDERED:
3104           cmp_code = EQ;
3105           code = LT;
3106           break;
3107         case ORDERED:
3108           cmp_code = EQ;
3109           code = GE;
3110           break;
3111         case NE:
3112           cmp_code = NE;
3113           code = NE;
3114           break;
3115         default:
3116           cmp_code = code;
3117           code = GT;
3118           break;
3119         }
3120
3121       op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3122       op1 = const0_rtx;
3123       alpha_compare.fp_p = 0;
3124     }
3125
3126   /* The general case: fold the comparison code to the types of compares
3127      that we have, choosing the branch as necessary.  */
3128   switch (code)
3129     {
3130     case EQ:  case LE:  case LT:  case LEU:  case LTU:
3131     case UNORDERED:
3132       /* We have these compares: */
3133       cmp_code = code, branch_code = NE;
3134       break;
3135
3136     case NE:
3137     case ORDERED:
3138       /* These must be reversed.  */
3139       cmp_code = reverse_condition (code), branch_code = EQ;
3140       break;
3141
3142     case GE:  case GT: case GEU:  case GTU:
3143       /* For FP, we swap them, for INT, we reverse them.  */
3144       if (alpha_compare.fp_p)
3145         {
3146           cmp_code = swap_condition (code);
3147           branch_code = NE;
3148           tem = op0, op0 = op1, op1 = tem;
3149         }
3150       else
3151         {
3152           cmp_code = reverse_condition (code);
3153           branch_code = EQ;
3154         }
3155       break;
3156
3157     default:
3158       abort ();
3159     }
3160
3161   if (alpha_compare.fp_p)
3162     {
3163       cmp_mode = DFmode;
3164       if (flag_unsafe_math_optimizations)
3165         {
3166           /* When we are not as concerned about non-finite values, and we
3167              are comparing against zero, we can branch directly.  */
3168           if (op1 == CONST0_RTX (DFmode))
3169             cmp_code = NIL, branch_code = code;
3170           else if (op0 == CONST0_RTX (DFmode))
3171             {
3172               /* Undo the swap we probably did just above.  */
3173               tem = op0, op0 = op1, op1 = tem;
3174               branch_code = swap_condition (cmp_code);
3175               cmp_code = NIL;
3176             }
3177         }
3178       else
3179         {
3180           /* ??? We mark the branch mode to be CCmode to prevent the
3181              compare and branch from being combined, since the compare 
3182              insn follows IEEE rules that the branch does not.  */
3183           branch_mode = CCmode;
3184         }
3185     }
3186   else
3187     {
3188       cmp_mode = DImode;
3189
3190       /* The following optimizations are only for signed compares.  */
3191       if (code != LEU && code != LTU && code != GEU && code != GTU)
3192         {
3193           /* Whee.  Compare and branch against 0 directly.  */
3194           if (op1 == const0_rtx)
3195             cmp_code = NIL, branch_code = code;
3196
3197           /* If the constants doesn't fit into an immediate, but can
3198              be generated by lda/ldah, we adjust the argument and
3199              compare against zero, so we can use beq/bne directly.  */
3200           /* ??? Don't do this when comparing against symbols, otherwise
3201              we'll reduce (&x == 0x1234) to (&x-0x1234 == 0), which will
3202              be declared false out of hand (at least for non-weak).  */
3203           else if (GET_CODE (op1) == CONST_INT
3204                    && (code == EQ || code == NE)
3205                    && !(symbolic_operand (op0, VOIDmode)
3206                         || (GET_CODE (op0) == REG && REG_POINTER (op0))))
3207             {
3208               HOST_WIDE_INT v = INTVAL (op1), n = -v;
3209
3210               if (! CONST_OK_FOR_LETTER_P (v, 'I')
3211                   && (CONST_OK_FOR_LETTER_P (n, 'K')
3212                       || CONST_OK_FOR_LETTER_P (n, 'L')))
3213                 {
3214                   cmp_code = PLUS, branch_code = code;
3215                   op1 = GEN_INT (n);
3216                 }
3217             }
3218         }
3219
3220       if (!reg_or_0_operand (op0, DImode))
3221         op0 = force_reg (DImode, op0);
3222       if (cmp_code != PLUS && !reg_or_8bit_operand (op1, DImode))
3223         op1 = force_reg (DImode, op1);
3224     }
3225
3226   /* Emit an initial compare instruction, if necessary.  */
3227   tem = op0;
3228   if (cmp_code != NIL)
3229     {
3230       tem = gen_reg_rtx (cmp_mode);
3231       emit_move_insn (tem, gen_rtx_fmt_ee (cmp_code, cmp_mode, op0, op1));
3232     }
3233
3234   /* Zero the operands.  */
3235   memset (&alpha_compare, 0, sizeof (alpha_compare));
3236
3237   /* Return the branch comparison.  */
3238   return gen_rtx_fmt_ee (branch_code, branch_mode, tem, CONST0_RTX (cmp_mode));
3239 }
3240
3241 /* Certain simplifications can be done to make invalid setcc operations
3242    valid.  Return the final comparison, or NULL if we can't work.  */
3243
3244 rtx
3245 alpha_emit_setcc (enum rtx_code code)
3246 {
3247   enum rtx_code cmp_code;
3248   rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1;
3249   int fp_p = alpha_compare.fp_p;
3250   rtx tmp;
3251
3252   /* Zero the operands.  */
3253   memset (&alpha_compare, 0, sizeof (alpha_compare));
3254
3255   if (fp_p && GET_MODE (op0) == TFmode)
3256     {
3257       if (! TARGET_HAS_XFLOATING_LIBS)
3258         abort ();
3259
3260       /* X_floating library comparison functions return
3261            -1  unordered
3262             0  false
3263             1  true
3264          Convert the compare against the raw return value.  */
3265
3266       if (code == UNORDERED || code == ORDERED)
3267         cmp_code = EQ;
3268       else
3269         cmp_code = code;
3270
3271       op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3272       op1 = const0_rtx;
3273       fp_p = 0;
3274
3275       if (code == UNORDERED)
3276         code = LT;
3277       else if (code == ORDERED)
3278         code = GE;
3279       else
3280         code = GT;
3281     }
3282
3283   if (fp_p && !TARGET_FIX)
3284     return NULL_RTX;
3285
3286   /* The general case: fold the comparison code to the types of compares
3287      that we have, choosing the branch as necessary.  */
3288
3289   cmp_code = NIL;
3290   switch (code)
3291     {
3292     case EQ:  case LE:  case LT:  case LEU:  case LTU:
3293     case UNORDERED:
3294       /* We have these compares.  */
3295       if (fp_p)
3296         cmp_code = code, code = NE;
3297       break;
3298
3299     case NE:
3300       if (!fp_p && op1 == const0_rtx)
3301         break;
3302       /* FALLTHRU */
3303
3304     case ORDERED:
3305       cmp_code = reverse_condition (code);
3306       code = EQ;
3307       break;
3308
3309     case GE:  case GT: case GEU:  case GTU:
3310       /* These normally need swapping, but for integer zero we have
3311          special patterns that recognize swapped operands.  */
3312       if (!fp_p && op1 == const0_rtx)
3313         break;
3314       code = swap_condition (code);
3315       if (fp_p)
3316         cmp_code = code, code = NE;
3317       tmp = op0, op0 = op1, op1 = tmp;
3318       break;
3319
3320     default:
3321       abort ();
3322     }
3323
3324   if (!fp_p)
3325     {
3326       if (!register_operand (op0, DImode))
3327         op0 = force_reg (DImode, op0);
3328       if (!reg_or_8bit_operand (op1, DImode))
3329         op1 = force_reg (DImode, op1);
3330     }
3331
3332   /* Emit an initial compare instruction, if necessary.  */
3333   if (cmp_code != NIL)
3334     {
3335       enum machine_mode mode = fp_p ? DFmode : DImode;
3336
3337       tmp = gen_reg_rtx (mode);
3338       emit_insn (gen_rtx_SET (VOIDmode, tmp,
3339                               gen_rtx_fmt_ee (cmp_code, mode, op0, op1)));
3340
3341       op0 = fp_p ? gen_lowpart (DImode, tmp) : tmp;
3342       op1 = const0_rtx;
3343     }
3344
3345   /* Return the setcc comparison.  */
3346   return gen_rtx_fmt_ee (code, DImode, op0, op1);
3347 }
3348
3349
3350 /* Rewrite a comparison against zero CMP of the form
3351    (CODE (cc0) (const_int 0)) so it can be written validly in
3352    a conditional move (if_then_else CMP ...).
3353    If both of the operands that set cc0 are nonzero we must emit
3354    an insn to perform the compare (it can't be done within
3355    the conditional move).  */
3356
3357 rtx
3358 alpha_emit_conditional_move (rtx cmp, enum machine_mode mode)
3359 {
3360   enum rtx_code code = GET_CODE (cmp);
3361   enum rtx_code cmov_code = NE;
3362   rtx op0 = alpha_compare.op0;
3363   rtx op1 = alpha_compare.op1;
3364   int fp_p = alpha_compare.fp_p;
3365   enum machine_mode cmp_mode
3366     = (GET_MODE (op0) == VOIDmode ? DImode : GET_MODE (op0));
3367   enum machine_mode cmp_op_mode = fp_p ? DFmode : DImode;
3368   enum machine_mode cmov_mode = VOIDmode;
3369   int local_fast_math = flag_unsafe_math_optimizations;
3370   rtx tem;
3371
3372   /* Zero the operands.  */
3373   memset (&alpha_compare, 0, sizeof (alpha_compare));
3374
3375   if (fp_p != FLOAT_MODE_P (mode))
3376     {
3377       enum rtx_code cmp_code;
3378
3379       if (! TARGET_FIX)
3380         return 0;
3381
3382       /* If we have fp<->int register move instructions, do a cmov by
3383          performing the comparison in fp registers, and move the
3384          zero/nonzero value to integer registers, where we can then
3385          use a normal cmov, or vice-versa.  */
3386
3387       switch (code)
3388         {
3389         case EQ: case LE: case LT: case LEU: case LTU:
3390           /* We have these compares.  */
3391           cmp_code = code, code = NE;
3392           break;
3393
3394         case NE:
3395           /* This must be reversed.  */
3396           cmp_code = EQ, code = EQ;
3397           break;
3398
3399         case GE: case GT: case GEU: case GTU:
3400           /* These normally need swapping, but for integer zero we have
3401              special patterns that recognize swapped operands.  */
3402           if (!fp_p && op1 == const0_rtx)
3403             cmp_code = code, code = NE;
3404           else
3405             {
3406               cmp_code = swap_condition (code);
3407               code = NE;
3408               tem = op0, op0 = op1, op1 = tem;
3409             }
3410           break;
3411
3412         default:
3413           abort ();
3414         }
3415
3416       tem = gen_reg_rtx (cmp_op_mode);
3417       emit_insn (gen_rtx_SET (VOIDmode, tem,
3418                               gen_rtx_fmt_ee (cmp_code, cmp_op_mode,
3419                                               op0, op1)));
3420
3421       cmp_mode = cmp_op_mode = fp_p ? DImode : DFmode;
3422       op0 = gen_lowpart (cmp_op_mode, tem);
3423       op1 = CONST0_RTX (cmp_op_mode);
3424       fp_p = !fp_p;
3425       local_fast_math = 1;
3426     }
3427
3428   /* We may be able to use a conditional move directly.
3429      This avoids emitting spurious compares.  */
3430   if (signed_comparison_operator (cmp, VOIDmode)
3431       && (!fp_p || local_fast_math)
3432       && (op0 == CONST0_RTX (cmp_mode) || op1 == CONST0_RTX (cmp_mode)))
3433     return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
3434
3435   /* We can't put the comparison inside the conditional move;
3436      emit a compare instruction and put that inside the
3437      conditional move.  Make sure we emit only comparisons we have;
3438      swap or reverse as necessary.  */
3439
3440   if (no_new_pseudos)
3441     return NULL_RTX;
3442
3443   switch (code)
3444     {
3445     case EQ:  case LE:  case LT:  case LEU:  case LTU:
3446       /* We have these compares: */
3447       break;
3448
3449     case NE:
3450       /* This must be reversed.  */
3451       code = reverse_condition (code);
3452       cmov_code = EQ;
3453       break;
3454
3455     case GE:  case GT:  case GEU:  case GTU:
3456       /* These must be swapped.  */
3457       if (op1 != CONST0_RTX (cmp_mode))
3458         {
3459           code = swap_condition (code);
3460           tem = op0, op0 = op1, op1 = tem;
3461         }
3462       break;
3463
3464     default:
3465       abort ();
3466     }
3467
3468   if (!fp_p)
3469     {
3470       if (!reg_or_0_operand (op0, DImode))
3471         op0 = force_reg (DImode, op0);
3472       if (!reg_or_8bit_operand (op1, DImode))
3473         op1 = force_reg (DImode, op1);
3474     }
3475
3476   /* ??? We mark the branch mode to be CCmode to prevent the compare
3477      and cmov from being combined, since the compare insn follows IEEE
3478      rules that the cmov does not.  */
3479   if (fp_p && !local_fast_math)
3480     cmov_mode = CCmode;
3481
3482   tem = gen_reg_rtx (cmp_op_mode);
3483   emit_move_insn (tem, gen_rtx_fmt_ee (code, cmp_op_mode, op0, op1));
3484   return gen_rtx_fmt_ee (cmov_code, cmov_mode, tem, CONST0_RTX (cmp_op_mode));
3485 }
3486
3487 /* Simplify a conditional move of two constants into a setcc with
3488    arithmetic.  This is done with a splitter since combine would
3489    just undo the work if done during code generation.  It also catches
3490    cases we wouldn't have before cse.  */
3491
3492 int
3493 alpha_split_conditional_move (enum rtx_code code, rtx dest, rtx cond,
3494                               rtx t_rtx, rtx f_rtx)
3495 {
3496   HOST_WIDE_INT t, f, diff;
3497   enum machine_mode mode;
3498   rtx target, subtarget, tmp;
3499
3500   mode = GET_MODE (dest);
3501   t = INTVAL (t_rtx);
3502   f = INTVAL (f_rtx);
3503   diff = t - f;
3504
3505   if (((code == NE || code == EQ) && diff < 0)
3506       || (code == GE || code == GT))
3507     {
3508       code = reverse_condition (code);
3509       diff = t, t = f, f = diff;
3510       diff = t - f;
3511     }
3512
3513   subtarget = target = dest;
3514   if (mode != DImode)
3515     {
3516       target = gen_lowpart (DImode, dest);
3517       if (! no_new_pseudos)
3518         subtarget = gen_reg_rtx (DImode);
3519       else
3520         subtarget = target;
3521     }
3522   /* Below, we must be careful to use copy_rtx on target and subtarget
3523      in intermediate insns, as they may be a subreg rtx, which may not
3524      be shared.  */
3525
3526   if (f == 0 && exact_log2 (diff) > 0
3527       /* On EV6, we've got enough shifters to make non-arithmetic shifts
3528          viable over a longer latency cmove.  On EV5, the E0 slot is a
3529          scarce resource, and on EV4 shift has the same latency as a cmove.  */
3530       && (diff <= 8 || alpha_cpu == PROCESSOR_EV6))
3531     {
3532       tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3533       emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3534
3535       tmp = gen_rtx_ASHIFT (DImode, copy_rtx (subtarget),
3536                             GEN_INT (exact_log2 (t)));
3537       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3538     }
3539   else if (f == 0 && t == -1)
3540     {
3541       tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3542       emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3543
3544       emit_insn (gen_negdi2 (target, copy_rtx (subtarget)));
3545     }
3546   else if (diff == 1 || diff == 4 || diff == 8)
3547     {
3548       rtx add_op;
3549
3550       tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3551       emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3552
3553       if (diff == 1)
3554         emit_insn (gen_adddi3 (target, copy_rtx (subtarget), GEN_INT (f)));
3555       else
3556         {
3557           add_op = GEN_INT (f);
3558           if (sext_add_operand (add_op, mode))
3559             {
3560               tmp = gen_rtx_MULT (DImode, copy_rtx (subtarget),
3561                                   GEN_INT (diff));
3562               tmp = gen_rtx_PLUS (DImode, tmp, add_op);
3563               emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3564             }
3565           else
3566             return 0;
3567         }
3568     }
3569   else
3570     return 0;
3571
3572   return 1;
3573 }
3574 \f
3575 /* Look up the function X_floating library function name for the
3576    given operation.  */
3577
3578 static const char *
3579 alpha_lookup_xfloating_lib_func (enum rtx_code code)
3580 {
3581   struct xfloating_op
3582     {
3583       const enum rtx_code code;
3584       const char *const func;
3585     };
3586
3587   static const struct xfloating_op vms_xfloating_ops[] = 
3588     {
3589       { PLUS,           "OTS$ADD_X" },
3590       { MINUS,          "OTS$SUB_X" },
3591       { MULT,           "OTS$MUL_X" },
3592       { DIV,            "OTS$DIV_X" },
3593       { EQ,             "OTS$EQL_X" },
3594       { NE,             "OTS$NEQ_X" },
3595       { LT,             "OTS$LSS_X" },
3596       { LE,             "OTS$LEQ_X" },
3597       { GT,             "OTS$GTR_X" },
3598       { GE,             "OTS$GEQ_X" },
3599       { FIX,            "OTS$CVTXQ" },
3600       { FLOAT,          "OTS$CVTQX" },
3601       { UNSIGNED_FLOAT, "OTS$CVTQUX" },
3602       { FLOAT_EXTEND,   "OTS$CVT_FLOAT_T_X" },
3603       { FLOAT_TRUNCATE, "OTS$CVT_FLOAT_X_T" },
3604     };
3605
3606   static const struct xfloating_op osf_xfloating_ops[] = 
3607     {
3608       { PLUS,           "_OtsAddX" },
3609       { MINUS,          "_OtsSubX" },
3610       { MULT,           "_OtsMulX" },
3611       { DIV,            "_OtsDivX" },
3612       { EQ,             "_OtsEqlX" },
3613       { NE,             "_OtsNeqX" },
3614       { LT,             "_OtsLssX" },
3615       { LE,             "_OtsLeqX" },
3616       { GT,             "_OtsGtrX" },
3617       { GE,             "_OtsGeqX" },
3618       { FIX,            "_OtsCvtXQ" },
3619       { FLOAT,          "_OtsCvtQX" },
3620       { UNSIGNED_FLOAT, "_OtsCvtQUX" },
3621       { FLOAT_EXTEND,   "_OtsConvertFloatTX" },
3622       { FLOAT_TRUNCATE, "_OtsConvertFloatXT" },
3623     };
3624
3625   const struct xfloating_op *ops;
3626   const long n = ARRAY_SIZE (osf_xfloating_ops);
3627   long i;
3628
3629   /* How irritating.  Nothing to key off for the table.  Hardcode
3630      knowledge of the G_floating routines.  */
3631   if (TARGET_FLOAT_VAX)
3632     {
3633       if (TARGET_ABI_OPEN_VMS)
3634         {
3635           if (code == FLOAT_EXTEND)
3636             return "OTS$CVT_FLOAT_G_X";
3637           if (code == FLOAT_TRUNCATE)
3638             return "OTS$CVT_FLOAT_X_G";
3639         }
3640       else
3641         {
3642           if (code == FLOAT_EXTEND)
3643             return "_OtsConvertFloatGX";
3644           if (code == FLOAT_TRUNCATE)
3645             return "_OtsConvertFloatXG";
3646         }
3647     }
3648
3649   if (TARGET_ABI_OPEN_VMS)
3650     ops = vms_xfloating_ops;
3651   else
3652     ops = osf_xfloating_ops;
3653
3654   for (i = 0; i < n; ++i)
3655     if (ops[i].code == code)
3656       return ops[i].func;
3657
3658   abort();
3659 }
3660
3661 /* Most X_floating operations take the rounding mode as an argument.
3662    Compute that here.  */
3663
3664 static int
3665 alpha_compute_xfloating_mode_arg (enum rtx_code code,
3666                                   enum alpha_fp_rounding_mode round)
3667 {
3668   int mode;
3669
3670   switch (round)
3671     {
3672     case ALPHA_FPRM_NORM:
3673       mode = 2;
3674       break;
3675     case ALPHA_FPRM_MINF:
3676       mode = 1;
3677       break;
3678     case ALPHA_FPRM_CHOP:
3679       mode = 0;
3680       break;
3681     case ALPHA_FPRM_DYN:
3682       mode = 4;
3683       break;
3684     default:
3685       abort ();
3686
3687     /* XXX For reference, round to +inf is mode = 3.  */
3688     }
3689
3690   if (code == FLOAT_TRUNCATE && alpha_fptm == ALPHA_FPTM_N)
3691     mode |= 0x10000;
3692
3693   return mode;
3694 }
3695
3696 /* Emit an X_floating library function call.
3697
3698    Note that these functions do not follow normal calling conventions:
3699    TFmode arguments are passed in two integer registers (as opposed to
3700    indirect); TFmode return values appear in R16+R17. 
3701
3702    FUNC is the function name to call.
3703    TARGET is where the output belongs.
3704    OPERANDS are the inputs.
3705    NOPERANDS is the count of inputs.
3706    EQUIV is the expression equivalent for the function.
3707 */
3708
3709 static void
3710 alpha_emit_xfloating_libcall (const char *func, rtx target, rtx operands[],
3711                               int noperands, rtx equiv)
3712 {
3713   rtx usage = NULL_RTX, tmp, reg;
3714   int regno = 16, i;
3715
3716   start_sequence ();
3717
3718   for (i = 0; i < noperands; ++i)
3719     {
3720       switch (GET_MODE (operands[i]))
3721         {
3722         case TFmode:
3723           reg = gen_rtx_REG (TFmode, regno);
3724           regno += 2;
3725           break;
3726
3727         case DFmode:
3728           reg = gen_rtx_REG (DFmode, regno + 32);
3729           regno += 1;
3730           break;
3731
3732         case VOIDmode:
3733           if (GET_CODE (operands[i]) != CONST_INT)
3734             abort ();
3735           /* FALLTHRU */
3736         case DImode:
3737           reg = gen_rtx_REG (DImode, regno);
3738           regno += 1;
3739           break;
3740
3741         default:
3742           abort ();
3743         }
3744
3745       emit_move_insn (reg, operands[i]);
3746       usage = alloc_EXPR_LIST (0, gen_rtx_USE (VOIDmode, reg), usage);
3747     }
3748
3749   switch (GET_MODE (target))
3750     {
3751     case TFmode:
3752       reg = gen_rtx_REG (TFmode, 16);
3753       break;
3754     case DFmode:
3755       reg = gen_rtx_REG (DFmode, 32);
3756       break;
3757     case DImode:
3758       reg = gen_rtx_REG (DImode, 0);
3759       break;
3760     default:
3761       abort ();
3762     }
3763
3764   tmp = gen_rtx_MEM (QImode, init_one_libfunc (func));
3765   tmp = emit_call_insn (GEN_CALL_VALUE (reg, tmp, const0_rtx,
3766                                         const0_rtx, const0_rtx));
3767   CALL_INSN_FUNCTION_USAGE (tmp) = usage;
3768
3769   tmp = get_insns ();
3770   end_sequence ();
3771
3772   emit_libcall_block (tmp, target, reg, equiv);
3773 }
3774
3775 /* Emit an X_floating library function call for arithmetic (+,-,*,/).  */
3776
3777 void
3778 alpha_emit_xfloating_arith (enum rtx_code code, rtx operands[])
3779 {
3780   const char *func;
3781   int mode;
3782   rtx out_operands[3];
3783
3784   func = alpha_lookup_xfloating_lib_func (code);
3785   mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3786
3787   out_operands[0] = operands[1];
3788   out_operands[1] = operands[2];
3789   out_operands[2] = GEN_INT (mode);
3790   alpha_emit_xfloating_libcall (func, operands[0], out_operands, 3,  
3791                                 gen_rtx_fmt_ee (code, TFmode, operands[1],
3792                                                 operands[2]));
3793 }
3794
3795 /* Emit an X_floating library function call for a comparison.  */
3796
3797 static rtx
3798 alpha_emit_xfloating_compare (enum rtx_code code, rtx op0, rtx op1)
3799 {
3800   const char *func;
3801   rtx out, operands[2];
3802
3803   func = alpha_lookup_xfloating_lib_func (code);
3804
3805   operands[0] = op0;
3806   operands[1] = op1;
3807   out = gen_reg_rtx (DImode);
3808
3809   /* ??? Strange mode for equiv because what's actually returned
3810      is -1,0,1, not a proper boolean value.  */
3811   alpha_emit_xfloating_libcall (func, out, operands, 2,
3812                                 gen_rtx_fmt_ee (code, CCmode, op0, op1));
3813
3814   return out;
3815 }
3816
3817 /* Emit an X_floating library function call for a conversion.  */
3818
3819 void
3820 alpha_emit_xfloating_cvt (enum rtx_code orig_code, rtx operands[])
3821 {
3822   int noperands = 1, mode;
3823   rtx out_operands[2];
3824   const char *func;
3825   enum rtx_code code = orig_code;
3826
3827   if (code == UNSIGNED_FIX)
3828     code = FIX;
3829
3830   func = alpha_lookup_xfloating_lib_func (code);
3831
3832   out_operands[0] = operands[1];
3833
3834   switch (code)
3835     {
3836     case FIX:
3837       mode = alpha_compute_xfloating_mode_arg (code, ALPHA_FPRM_CHOP);
3838       out_operands[1] = GEN_INT (mode);
3839       noperands = 2;
3840       break;
3841     case FLOAT_TRUNCATE:
3842       mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3843       out_operands[1] = GEN_INT (mode);
3844       noperands = 2;
3845       break;
3846     default:
3847       break;
3848     }
3849
3850   alpha_emit_xfloating_libcall (func, operands[0], out_operands, noperands,
3851                                 gen_rtx_fmt_e (orig_code,
3852                                                GET_MODE (operands[0]),
3853                                                operands[1]));
3854 }
3855
3856 /* Split a TFmode OP[1] into DImode OP[2,3] and likewise for
3857    OP[0] into OP[0,1].  Naturally, output operand ordering is
3858    little-endian.  */
3859
3860 void
3861 alpha_split_tfmode_pair (rtx operands[4])
3862 {
3863   if (GET_CODE (operands[1]) == REG)
3864     {
3865       operands[3] = gen_rtx_REG (DImode, REGNO (operands[1]) + 1);
3866       operands[2] = gen_rtx_REG (DImode, REGNO (operands[1]));
3867     }
3868   else if (GET_CODE (operands[1]) == MEM)
3869     {
3870       operands[3] = adjust_address (operands[1], DImode, 8);
3871       operands[2] = adjust_address (operands[1], DImode, 0);
3872     }
3873   else if (operands[1] == CONST0_RTX (TFmode))
3874     operands[2] = operands[3] = const0_rtx;
3875   else
3876     abort ();
3877
3878   if (GET_CODE (operands[0]) == REG)
3879     {
3880       operands[1] = gen_rtx_REG (DImode, REGNO (operands[0]) + 1);
3881       operands[0] = gen_rtx_REG (DImode, REGNO (operands[0]));
3882     }
3883   else if (GET_CODE (operands[0]) == MEM)
3884     {
3885       operands[1] = adjust_address (operands[0], DImode, 8);
3886       operands[0] = adjust_address (operands[0], DImode, 0);
3887     }
3888   else
3889     abort ();
3890 }
3891
3892 /* Implement negtf2 or abstf2.  Op0 is destination, op1 is source, 
3893    op2 is a register containing the sign bit, operation is the 
3894    logical operation to be performed.  */
3895
3896 void
3897 alpha_split_tfmode_frobsign (rtx operands[3], rtx (*operation) (rtx, rtx, rtx))
3898 {
3899   rtx high_bit = operands[2];
3900   rtx scratch;
3901   int move;
3902
3903   alpha_split_tfmode_pair (operands);
3904
3905   /* Detect three flavors of operand overlap.  */
3906   move = 1;
3907   if (rtx_equal_p (operands[0], operands[2]))
3908     move = 0;
3909   else if (rtx_equal_p (operands[1], operands[2]))
3910     {
3911       if (rtx_equal_p (operands[0], high_bit))
3912         move = 2;
3913       else
3914         move = -1;
3915     }
3916
3917   if (move < 0)
3918     emit_move_insn (operands[0], operands[2]);
3919
3920   /* ??? If the destination overlaps both source tf and high_bit, then
3921      assume source tf is dead in its entirety and use the other half
3922      for a scratch register.  Otherwise "scratch" is just the proper
3923      destination register.  */
3924   scratch = operands[move < 2 ? 1 : 3];
3925
3926   emit_insn ((*operation) (scratch, high_bit, operands[3]));
3927
3928   if (move > 0)
3929     {
3930       emit_move_insn (operands[0], operands[2]);
3931       if (move > 1)
3932         emit_move_insn (operands[1], scratch);
3933     }
3934 }
3935 \f
3936 /* Use ext[wlq][lh] as the Architecture Handbook describes for extracting
3937    unaligned data:
3938
3939            unsigned:                       signed:
3940    word:   ldq_u  r1,X(r11)                ldq_u  r1,X(r11)
3941            ldq_u  r2,X+1(r11)              ldq_u  r2,X+1(r11)
3942            lda    r3,X(r11)                lda    r3,X+2(r11)
3943            extwl  r1,r3,r1                 extql  r1,r3,r1
3944            extwh  r2,r3,r2                 extqh  r2,r3,r2
3945            or     r1.r2.r1                 or     r1,r2,r1
3946                                            sra    r1,48,r1
3947
3948    long:   ldq_u  r1,X(r11)                ldq_u  r1,X(r11)
3949            ldq_u  r2,X+3(r11)              ldq_u  r2,X+3(r11)
3950            lda    r3,X(r11)                lda    r3,X(r11)
3951            extll  r1,r3,r1                 extll  r1,r3,r1
3952            extlh  r2,r3,r2                 extlh  r2,r3,r2
3953            or     r1.r2.r1                 addl   r1,r2,r1
3954
3955    quad:   ldq_u  r1,X(r11)
3956            ldq_u  r2,X+7(r11)
3957            lda    r3,X(r11)
3958            extql  r1,r3,r1
3959            extqh  r2,r3,r2
3960            or     r1.r2.r1
3961 */
3962
3963 void
3964 alpha_expand_unaligned_load (rtx tgt, rtx mem, HOST_WIDE_INT size,
3965                              HOST_WIDE_INT ofs, int sign)
3966 {
3967   rtx meml, memh, addr, extl, exth, tmp, mema;
3968   enum machine_mode mode;
3969
3970   meml = gen_reg_rtx (DImode);
3971   memh = gen_reg_rtx (DImode);
3972   addr = gen_reg_rtx (DImode);
3973   extl = gen_reg_rtx (DImode);
3974   exth = gen_reg_rtx (DImode);
3975
3976   mema = XEXP (mem, 0);
3977   if (GET_CODE (mema) == LO_SUM)
3978     mema = force_reg (Pmode, mema);
3979
3980   /* AND addresses cannot be in any alias set, since they may implicitly
3981      alias surrounding code.  Ideally we'd have some alias set that 
3982      covered all types except those with alignment 8 or higher.  */
3983
3984   tmp = change_address (mem, DImode,
3985                         gen_rtx_AND (DImode, 
3986                                      plus_constant (mema, ofs),
3987                                      GEN_INT (-8)));
3988   set_mem_alias_set (tmp, 0);
3989   emit_move_insn (meml, tmp);
3990
3991   tmp = change_address (mem, DImode,
3992                         gen_rtx_AND (DImode, 
3993                                      plus_constant (mema, ofs + size - 1),
3994                                      GEN_INT (-8)));
3995   set_mem_alias_set (tmp, 0);
3996   emit_move_insn (memh, tmp);
3997
3998   if (WORDS_BIG_ENDIAN && sign && (size == 2 || size == 4))
3999     {
4000       emit_move_insn (addr, plus_constant (mema, -1));
4001
4002       emit_insn (gen_extqh_be (extl, meml, addr));
4003       emit_insn (gen_extxl_be (exth, memh, GEN_INT (64), addr));
4004
4005       addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
4006       addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (64 - size*8),
4007                            addr, 1, OPTAB_WIDEN);
4008     }
4009   else if (sign && size == 2)
4010     {
4011       emit_move_insn (addr, plus_constant (mema, ofs+2));
4012
4013       emit_insn (gen_extxl_le (extl, meml, GEN_INT (64), addr));
4014       emit_insn (gen_extqh_le (exth, memh, addr));
4015
4016       /* We must use tgt here for the target.  Alpha-vms port fails if we use
4017          addr for the target, because addr is marked as a pointer and combine
4018          knows that pointers are always sign-extended 32 bit values.  */
4019       addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
4020       addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (48), 
4021                            addr, 1, OPTAB_WIDEN);
4022     }
4023   else
4024     {
4025       if (WORDS_BIG_ENDIAN)
4026         {
4027           emit_move_insn (addr, plus_constant (mema, ofs+size-1));
4028           switch ((int) size)
4029             {
4030             case 2:
4031               emit_insn (gen_extwh_be (extl, meml, addr));
4032               mode = HImode;
4033               break;
4034
4035             case 4:
4036               emit_insn (gen_extlh_be (extl, meml, addr));
4037               mode = SImode;
4038               break;
4039
4040             case 8:
4041               emit_insn (gen_extqh_be (extl, meml, addr));
4042               mode = DImode;
4043               break;
4044
4045             default:
4046               abort ();
4047             }
4048           emit_insn (gen_extxl_be (exth, memh, GEN_INT (size*8), addr));
4049         }
4050       else
4051         {
4052           emit_move_insn (addr, plus_constant (mema, ofs));
4053           emit_insn (gen_extxl_le (extl, meml, GEN_INT (size*8), addr));
4054           switch ((int) size)
4055             {
4056             case 2:
4057               emit_insn (gen_extwh_le (exth, memh, addr));
4058               mode = HImode;
4059               break;
4060
4061             case 4:
4062               emit_insn (gen_extlh_le (exth, memh, addr));
4063               mode = SImode;
4064               break;
4065
4066             case 8:
4067               emit_insn (gen_extqh_le (exth, memh, addr));
4068               mode = DImode;
4069               break;
4070
4071             default:
4072               abort();
4073             }
4074         }
4075
4076       addr = expand_binop (mode, ior_optab, gen_lowpart (mode, extl),
4077                            gen_lowpart (mode, exth), gen_lowpart (mode, tgt),
4078                            sign, OPTAB_WIDEN);
4079     }
4080
4081   if (addr != tgt)
4082     emit_move_insn (tgt, gen_lowpart(GET_MODE (tgt), addr));
4083 }
4084
4085 /* Similarly, use ins and msk instructions to perform unaligned stores.  */
4086
4087 void
4088 alpha_expand_unaligned_store (rtx dst, rtx src,
4089                               HOST_WIDE_INT size, HOST_WIDE_INT ofs)
4090 {
4091   rtx dstl, dsth, addr, insl, insh, meml, memh, dsta;
4092   
4093   dstl = gen_reg_rtx (DImode);
4094   dsth = gen_reg_rtx (DImode);
4095   insl = gen_reg_rtx (DImode);
4096   insh = gen_reg_rtx (DImode);
4097
4098   dsta = XEXP (dst, 0);
4099   if (GET_CODE (dsta) == LO_SUM)
4100     dsta = force_reg (Pmode, dsta);
4101
4102   /* AND addresses cannot be in any alias set, since they may implicitly
4103      alias surrounding code.  Ideally we'd have some alias set that 
4104      covered all types except those with alignment 8 or higher.  */
4105
4106   meml = change_address (dst, DImode,
4107                          gen_rtx_AND (DImode, 
4108                                       plus_constant (dsta, ofs),
4109                                       GEN_INT (-8)));
4110   set_mem_alias_set (meml, 0);
4111
4112   memh = change_address (dst, DImode,
4113                          gen_rtx_AND (DImode, 
4114                                       plus_constant (dsta, ofs + size - 1),
4115                                       GEN_INT (-8)));
4116   set_mem_alias_set (memh, 0);
4117
4118   emit_move_insn (dsth, memh);
4119   emit_move_insn (dstl, meml);
4120   if (WORDS_BIG_ENDIAN)
4121     {
4122       addr = copy_addr_to_reg (plus_constant (dsta, ofs+size-1));
4123
4124       if (src != const0_rtx)
4125         {
4126           switch ((int) size)
4127             {
4128             case 2:
4129               emit_insn (gen_inswl_be (insh, gen_lowpart (HImode,src), addr));
4130               break;
4131             case 4:
4132               emit_insn (gen_insll_be (insh, gen_lowpart (SImode,src), addr));
4133               break;
4134             case 8:
4135               emit_insn (gen_insql_be (insh, gen_lowpart (DImode,src), addr));
4136               break;
4137             }
4138           emit_insn (gen_insxh (insl, gen_lowpart (DImode, src),
4139                                 GEN_INT (size*8), addr));
4140         }
4141
4142       switch ((int) size)
4143         {
4144         case 2:
4145           emit_insn (gen_mskxl_be (dsth, dsth, GEN_INT (0xffff), addr));
4146           break;
4147         case 4:
4148           {
4149             rtx msk = immed_double_const (0xffffffff, 0, DImode);
4150             emit_insn (gen_mskxl_be (dsth, dsth, msk, addr));
4151             break;
4152           }
4153         case 8:
4154           emit_insn (gen_mskxl_be (dsth, dsth, constm1_rtx, addr));
4155           break;
4156         }
4157
4158       emit_insn (gen_mskxh (dstl, dstl, GEN_INT (size*8), addr));
4159     }
4160   else
4161     {
4162       addr = copy_addr_to_reg (plus_constant (dsta, ofs));
4163
4164       if (src != const0_rtx)
4165         {
4166           emit_insn (gen_insxh (insh, gen_lowpart (DImode, src),
4167                                 GEN_INT (size*8), addr));
4168
4169           switch ((int) size)
4170             {
4171             case 2:
4172               emit_insn (gen_inswl_le (insl, gen_lowpart (HImode, src), addr));
4173               break;
4174             case 4:
4175               emit_insn (gen_insll_le (insl, gen_lowpart (SImode, src), addr));
4176               break;
4177             case 8:
4178               emit_insn (gen_insql_le (insl, src, addr));
4179               break;
4180             }
4181         }
4182
4183       emit_insn (gen_mskxh (dsth, dsth, GEN_INT (size*8), addr));
4184
4185       switch ((int) size)
4186         {
4187         case 2:
4188           emit_insn (gen_mskxl_le (dstl, dstl, GEN_INT (0xffff), addr));
4189           break;
4190         case 4:
4191           {
4192             rtx msk = immed_double_const (0xffffffff, 0, DImode);
4193             emit_insn (gen_mskxl_le (dstl, dstl, msk, addr));
4194             break;
4195           }
4196         case 8:
4197           emit_insn (gen_mskxl_le (dstl, dstl, constm1_rtx, addr));
4198           break;
4199         }
4200     }
4201
4202   if (src != const0_rtx)
4203     {
4204       dsth = expand_binop (DImode, ior_optab, insh, dsth, dsth, 0, OPTAB_WIDEN);
4205       dstl = expand_binop (DImode, ior_optab, insl, dstl, dstl, 0, OPTAB_WIDEN);
4206     }
4207  
4208   if (WORDS_BIG_ENDIAN)
4209     {
4210       emit_move_insn (meml, dstl);
4211       emit_move_insn (memh, dsth);
4212     }
4213   else
4214     {
4215       /* Must store high before low for degenerate case of aligned.  */
4216       emit_move_insn (memh, dsth);
4217       emit_move_insn (meml, dstl);
4218     }
4219 }
4220
4221 /* The block move code tries to maximize speed by separating loads and
4222    stores at the expense of register pressure: we load all of the data
4223    before we store it back out.  There are two secondary effects worth
4224    mentioning, that this speeds copying to/from aligned and unaligned
4225    buffers, and that it makes the code significantly easier to write.  */
4226
4227 #define MAX_MOVE_WORDS  8
4228
4229 /* Load an integral number of consecutive unaligned quadwords.  */
4230
4231 static void
4232 alpha_expand_unaligned_load_words (rtx *out_regs, rtx smem,
4233                                    HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4234 {
4235   rtx const im8 = GEN_INT (-8);
4236   rtx const i64 = GEN_INT (64);
4237   rtx ext_tmps[MAX_MOVE_WORDS], data_regs[MAX_MOVE_WORDS+1];
4238   rtx sreg, areg, tmp, smema;
4239   HOST_WIDE_INT i;
4240
4241   smema = XEXP (smem, 0);
4242   if (GET_CODE (smema) == LO_SUM)
4243     smema = force_reg (Pmode, smema);
4244
4245   /* Generate all the tmp registers we need.  */
4246   for (i = 0; i < words; ++i)
4247     {
4248       data_regs[i] = out_regs[i];
4249       ext_tmps[i] = gen_reg_rtx (DImode);
4250     }
4251   data_regs[words] = gen_reg_rtx (DImode);
4252
4253   if (ofs != 0)
4254     smem = adjust_address (smem, GET_MODE (smem), ofs);
4255   
4256   /* Load up all of the source data.  */
4257   for (i = 0; i < words; ++i)
4258     {
4259       tmp = change_address (smem, DImode,
4260                             gen_rtx_AND (DImode,
4261                                          plus_constant (smema, 8*i),
4262                                          im8));
4263       set_mem_alias_set (tmp, 0);
4264       emit_move_insn (data_regs[i], tmp);
4265     }
4266
4267   tmp = change_address (smem, DImode,
4268                         gen_rtx_AND (DImode,
4269                                      plus_constant (smema, 8*words - 1),
4270                                      im8));
4271   set_mem_alias_set (tmp, 0);
4272   emit_move_insn (data_regs[words], tmp);
4273
4274   /* Extract the half-word fragments.  Unfortunately DEC decided to make
4275      extxh with offset zero a noop instead of zeroing the register, so 
4276      we must take care of that edge condition ourselves with cmov.  */
4277
4278   sreg = copy_addr_to_reg (smema);
4279   areg = expand_binop (DImode, and_optab, sreg, GEN_INT (7), NULL, 
4280                        1, OPTAB_WIDEN);
4281   if (WORDS_BIG_ENDIAN)
4282     emit_move_insn (sreg, plus_constant (sreg, 7));
4283   for (i = 0; i < words; ++i)
4284     {
4285       if (WORDS_BIG_ENDIAN)
4286         {
4287           emit_insn (gen_extqh_be (data_regs[i], data_regs[i], sreg));
4288           emit_insn (gen_extxl_be (ext_tmps[i], data_regs[i+1], i64, sreg));
4289         }
4290       else
4291         {
4292           emit_insn (gen_extxl_le (data_regs[i], data_regs[i], i64, sreg));
4293           emit_insn (gen_extqh_le (ext_tmps[i], data_regs[i+1], sreg));
4294         }
4295       emit_insn (gen_rtx_SET (VOIDmode, ext_tmps[i],
4296                               gen_rtx_IF_THEN_ELSE (DImode,
4297                                                     gen_rtx_EQ (DImode, areg,
4298                                                                 const0_rtx),
4299                                                     const0_rtx, ext_tmps[i])));
4300     }
4301
4302   /* Merge the half-words into whole words.  */
4303   for (i = 0; i < words; ++i)
4304     {
4305       out_regs[i] = expand_binop (DImode, ior_optab, data_regs[i],
4306                                   ext_tmps[i], data_regs[i], 1, OPTAB_WIDEN);
4307     }
4308 }
4309
4310 /* Store an integral number of consecutive unaligned quadwords.  DATA_REGS
4311    may be NULL to store zeros.  */
4312
4313 static void
4314 alpha_expand_unaligned_store_words (rtx *data_regs, rtx dmem,
4315                                     HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4316 {
4317   rtx const im8 = GEN_INT (-8);
4318   rtx const i64 = GEN_INT (64);
4319   rtx ins_tmps[MAX_MOVE_WORDS];
4320   rtx st_tmp_1, st_tmp_2, dreg;
4321   rtx st_addr_1, st_addr_2, dmema;
4322   HOST_WIDE_INT i;
4323
4324   dmema = XEXP (dmem, 0);
4325   if (GET_CODE (dmema) == LO_SUM)
4326     dmema = force_reg (Pmode, dmema);
4327
4328   /* Generate all the tmp registers we need.  */
4329   if (data_regs != NULL)
4330     for (i = 0; i < words; ++i)
4331       ins_tmps[i] = gen_reg_rtx(DImode);
4332   st_tmp_1 = gen_reg_rtx(DImode);
4333   st_tmp_2 = gen_reg_rtx(DImode);
4334   
4335   if (ofs != 0)
4336     dmem = adjust_address (dmem, GET_MODE (dmem), ofs);
4337
4338   st_addr_2 = change_address (dmem, DImode,
4339                               gen_rtx_AND (DImode,
4340                                            plus_constant (dmema, words*8 - 1),
4341                                        im8));
4342   set_mem_alias_set (st_addr_2, 0);
4343
4344   st_addr_1 = change_address (dmem, DImode,
4345                               gen_rtx_AND (DImode, dmema, im8));
4346   set_mem_alias_set (st_addr_1, 0);
4347
4348   /* Load up the destination end bits.  */
4349   emit_move_insn (st_tmp_2, st_addr_2);
4350   emit_move_insn (st_tmp_1, st_addr_1);
4351
4352   /* Shift the input data into place.  */
4353   dreg = copy_addr_to_reg (dmema);
4354   if (WORDS_BIG_ENDIAN)
4355     emit_move_insn (dreg, plus_constant (dreg, 7));
4356   if (data_regs != NULL)
4357     {
4358       for (i = words-1; i >= 0; --i)
4359         {
4360           if (WORDS_BIG_ENDIAN)
4361             {
4362               emit_insn (gen_insql_be (ins_tmps[i], data_regs[i], dreg));
4363               emit_insn (gen_insxh (data_regs[i], data_regs[i], i64, dreg));
4364             }
4365           else
4366             {
4367               emit_insn (gen_insxh (ins_tmps[i], data_regs[i], i64, dreg));
4368               emit_insn (gen_insql_le (data_regs[i], data_regs[i], dreg));
4369             }
4370         }
4371       for (i = words-1; i > 0; --i)
4372         {
4373           ins_tmps[i-1] = expand_binop (DImode, ior_optab, data_regs[i],
4374                                         ins_tmps[i-1], ins_tmps[i-1], 1,
4375                                         OPTAB_WIDEN);
4376         }
4377     }
4378
4379   /* Split and merge the ends with the destination data.  */
4380   if (WORDS_BIG_ENDIAN)
4381     {
4382       emit_insn (gen_mskxl_be (st_tmp_2, st_tmp_2, constm1_rtx, dreg));
4383       emit_insn (gen_mskxh (st_tmp_1, st_tmp_1, i64, dreg));
4384     }
4385   else
4386     {
4387       emit_insn (gen_mskxh (st_tmp_2, st_tmp_2, i64, dreg));
4388       emit_insn (gen_mskxl_le (st_tmp_1, st_tmp_1, constm1_rtx, dreg));
4389     }
4390
4391   if (data_regs != NULL)
4392     {
4393       st_tmp_2 = expand_binop (DImode, ior_optab, st_tmp_2, ins_tmps[words-1],
4394                                st_tmp_2, 1, OPTAB_WIDEN);
4395       st_tmp_1 = expand_binop (DImode, ior_optab, st_tmp_1, data_regs[0],
4396                                st_tmp_1, 1, OPTAB_WIDEN);
4397     }
4398
4399   /* Store it all.  */
4400   if (WORDS_BIG_ENDIAN)
4401     emit_move_insn (st_addr_1, st_tmp_1);
4402   else
4403     emit_move_insn (st_addr_2, st_tmp_2);
4404   for (i = words-1; i > 0; --i)
4405     {
4406       rtx tmp = change_address (dmem, DImode,
4407                                 gen_rtx_AND (DImode,
4408                                              plus_constant(dmema,
4409                                              WORDS_BIG_ENDIAN ? i*8-1 : i*8),
4410                                              im8));
4411       set_mem_alias_set (tmp, 0);
4412       emit_move_insn (tmp, data_regs ? ins_tmps[i-1] : const0_rtx);
4413     }
4414   if (WORDS_BIG_ENDIAN)
4415     emit_move_insn (st_addr_2, st_tmp_2);
4416   else
4417     emit_move_insn (st_addr_1, st_tmp_1);
4418 }
4419
4420
4421 /* Expand string/block move operations.
4422
4423    operands[0] is the pointer to the destination.
4424    operands[1] is the pointer to the source.
4425    operands[2] is the number of bytes to move.
4426    operands[3] is the alignment.  */
4427
4428 int
4429 alpha_expand_block_move (rtx operands[])
4430 {
4431   rtx bytes_rtx = operands[2];
4432   rtx align_rtx = operands[3];
4433   HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4434   HOST_WIDE_INT bytes = orig_bytes;
4435   HOST_WIDE_INT src_align = INTVAL (align_rtx) * BITS_PER_UNIT;
4436   HOST_WIDE_INT dst_align = src_align;
4437   rtx orig_src = operands[1];
4438   rtx orig_dst = operands[0];
4439   rtx data_regs[2 * MAX_MOVE_WORDS + 16];
4440   rtx tmp;
4441   unsigned int i, words, ofs, nregs = 0;
4442   
4443   if (orig_bytes <= 0)
4444     return 1;
4445   else if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4446     return 0;
4447
4448   /* Look for additional alignment information from recorded register info.  */
4449
4450   tmp = XEXP (orig_src, 0);
4451   if (GET_CODE (tmp) == REG)
4452     src_align = MAX (src_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4453   else if (GET_CODE (tmp) == PLUS
4454            && GET_CODE (XEXP (tmp, 0)) == REG
4455            && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4456     {
4457       unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4458       unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4459
4460       if (a > src_align)
4461         {
4462           if (a >= 64 && c % 8 == 0)
4463             src_align = 64;
4464           else if (a >= 32 && c % 4 == 0)
4465             src_align = 32;
4466           else if (a >= 16 && c % 2 == 0)
4467             src_align = 16;
4468         }
4469     }
4470         
4471   tmp = XEXP (orig_dst, 0);
4472   if (GET_CODE (tmp) == REG)
4473     dst_align = MAX (dst_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4474   else if (GET_CODE (tmp) == PLUS
4475            && GET_CODE (XEXP (tmp, 0)) == REG
4476            && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4477     {
4478       unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4479       unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4480
4481       if (a > dst_align)
4482         {
4483           if (a >= 64 && c % 8 == 0)
4484             dst_align = 64;
4485           else if (a >= 32 && c % 4 == 0)
4486             dst_align = 32;
4487           else if (a >= 16 && c % 2 == 0)
4488             dst_align = 16;
4489         }
4490     }
4491
4492   /* Load the entire block into registers.  */
4493   if (GET_CODE (XEXP (orig_src, 0)) == ADDRESSOF)
4494     {
4495       enum machine_mode mode;
4496
4497       tmp = XEXP (XEXP (orig_src, 0), 0);
4498
4499       /* Don't use the existing register if we're reading more than
4500          is held in the register.  Nor if there is not a mode that
4501          handles the exact size.  */
4502       mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1);
4503       if (GET_CODE (tmp) == REG
4504           && mode != BLKmode
4505           && GET_MODE_SIZE (GET_MODE (tmp)) >= bytes)
4506         {
4507           if (mode == TImode)
4508             {
4509               data_regs[nregs] = gen_lowpart (DImode, tmp);
4510               data_regs[nregs + 1] = gen_highpart (DImode, tmp);
4511               nregs += 2;
4512             }
4513           else
4514             data_regs[nregs++] = gen_lowpart (mode, tmp);
4515
4516           goto src_done;
4517         }
4518
4519       /* No appropriate mode; fall back on memory.  */
4520       orig_src = replace_equiv_address (orig_src,
4521                                         copy_addr_to_reg (XEXP (orig_src, 0)));
4522       src_align = GET_MODE_BITSIZE (GET_MODE (tmp));
4523     }
4524
4525   ofs = 0;
4526   if (src_align >= 64 && bytes >= 8)
4527     {
4528       words = bytes / 8;
4529
4530       for (i = 0; i < words; ++i)
4531         data_regs[nregs + i] = gen_reg_rtx (DImode);
4532
4533       for (i = 0; i < words; ++i)
4534         emit_move_insn (data_regs[nregs + i],
4535                         adjust_address (orig_src, DImode, ofs + i * 8));
4536
4537       nregs += words;
4538       bytes -= words * 8;
4539       ofs += words * 8;
4540     }
4541
4542   if (src_align >= 32 && bytes >= 4)
4543     {
4544       words = bytes / 4;
4545
4546       for (i = 0; i < words; ++i)
4547         data_regs[nregs + i] = gen_reg_rtx (SImode);
4548
4549       for (i = 0; i < words; ++i)
4550         emit_move_insn (data_regs[nregs + i],
4551                         adjust_address (orig_src, SImode, ofs + i * 4));
4552
4553       nregs += words;
4554       bytes -= words * 4;
4555       ofs += words * 4;
4556     }
4557
4558   if (bytes >= 8)
4559     {
4560       words = bytes / 8;
4561
4562       for (i = 0; i < words+1; ++i)
4563         data_regs[nregs + i] = gen_reg_rtx (DImode);
4564
4565       alpha_expand_unaligned_load_words (data_regs + nregs, orig_src,
4566                                          words, ofs);
4567
4568       nregs += words;
4569       bytes -= words * 8;
4570       ofs += words * 8;
4571     }
4572
4573   if (! TARGET_BWX && bytes >= 4)
4574     {
4575       data_regs[nregs++] = tmp = gen_reg_rtx (SImode);
4576       alpha_expand_unaligned_load (tmp, orig_src, 4, ofs, 0);
4577       bytes -= 4;
4578       ofs += 4;
4579     }
4580
4581   if (bytes >= 2)
4582     {
4583       if (src_align >= 16)
4584         {
4585           do {
4586             data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4587             emit_move_insn (tmp, adjust_address (orig_src, HImode, ofs));
4588             bytes -= 2;
4589             ofs += 2;
4590           } while (bytes >= 2);
4591         }
4592       else if (! TARGET_BWX)
4593         {
4594           data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4595           alpha_expand_unaligned_load (tmp, orig_src, 2, ofs, 0);
4596           bytes -= 2;
4597           ofs += 2;
4598         }
4599     }
4600
4601   while (bytes > 0)
4602     {
4603       data_regs[nregs++] = tmp = gen_reg_rtx (QImode);
4604       emit_move_insn (tmp, adjust_address (orig_src, QImode, ofs));
4605       bytes -= 1;
4606       ofs += 1;
4607     }
4608
4609  src_done:
4610
4611   if (nregs > ARRAY_SIZE (data_regs))
4612     abort ();
4613
4614   /* Now save it back out again.  */
4615
4616   i = 0, ofs = 0;
4617
4618   if (GET_CODE (XEXP (orig_dst, 0)) == ADDRESSOF)
4619     {
4620       enum machine_mode mode;
4621       tmp = XEXP (XEXP (orig_dst, 0), 0);
4622
4623       mode = mode_for_size (orig_bytes * BITS_PER_UNIT, MODE_INT, 1);
4624       if (GET_CODE (tmp) == REG && GET_MODE (tmp) == mode)
4625         {
4626           if (nregs == 1)
4627             {
4628               emit_move_insn (tmp, data_regs[0]);
4629               i = 1;
4630               goto dst_done;
4631             }
4632
4633           else if (nregs == 2 && mode == TImode)
4634             {
4635               /* Undo the subregging done above when copying between
4636                  two TImode registers.  */
4637               if (GET_CODE (data_regs[0]) == SUBREG
4638                   && GET_MODE (SUBREG_REG (data_regs[0])) == TImode)
4639                 emit_move_insn (tmp, SUBREG_REG (data_regs[0]));
4640               else
4641                 {
4642                   rtx seq;
4643
4644                   start_sequence ();
4645                   emit_move_insn (gen_lowpart (DImode, tmp), data_regs[0]);
4646                   emit_move_insn (gen_highpart (DImode, tmp), data_regs[1]);
4647                   seq = get_insns ();
4648                   end_sequence ();
4649
4650                   emit_no_conflict_block (seq, tmp, data_regs[0],
4651                                           data_regs[1], NULL_RTX);
4652                 }
4653
4654               i = 2;
4655               goto dst_done;
4656             }
4657         }
4658
4659       /* ??? If nregs > 1, consider reconstructing the word in regs.  */
4660       /* ??? Optimize mode < dst_mode with strict_low_part.  */
4661
4662       /* No appropriate mode; fall back on memory.  We can speed things
4663          up by recognizing extra alignment information.  */
4664       orig_dst = replace_equiv_address (orig_dst,
4665                                         copy_addr_to_reg (XEXP (orig_dst, 0)));
4666       dst_align = GET_MODE_BITSIZE (GET_MODE (tmp));
4667     }
4668
4669   /* Write out the data in whatever chunks reading the source allowed.  */
4670   if (dst_align >= 64)
4671     {
4672       while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4673         {
4674           emit_move_insn (adjust_address (orig_dst, DImode, ofs),
4675                           data_regs[i]);
4676           ofs += 8;
4677           i++;
4678         }
4679     }
4680
4681   if (dst_align >= 32)
4682     {
4683       /* If the source has remaining DImode regs, write them out in
4684          two pieces.  */
4685       while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4686         {
4687           tmp = expand_binop (DImode, lshr_optab, data_regs[i], GEN_INT (32),
4688                               NULL_RTX, 1, OPTAB_WIDEN);
4689
4690           emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4691                           gen_lowpart (SImode, data_regs[i]));
4692           emit_move_insn (adjust_address (orig_dst, SImode, ofs + 4),
4693                           gen_lowpart (SImode, tmp));
4694           ofs += 8;
4695           i++;
4696         }
4697
4698       while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4699         {
4700           emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4701                           data_regs[i]);
4702           ofs += 4;
4703           i++;
4704         }
4705     }
4706
4707   if (i < nregs && GET_MODE (data_regs[i]) == DImode)
4708     {
4709       /* Write out a remaining block of words using unaligned methods.  */
4710
4711       for (words = 1; i + words < nregs; words++)
4712         if (GET_MODE (data_regs[i + words]) != DImode)
4713           break;
4714
4715       if (words == 1)
4716         alpha_expand_unaligned_store (orig_dst, data_regs[i], 8, ofs);
4717       else
4718         alpha_expand_unaligned_store_words (data_regs + i, orig_dst,
4719                                             words, ofs);
4720      
4721       i += words;
4722       ofs += words * 8;
4723     }
4724
4725   /* Due to the above, this won't be aligned.  */
4726   /* ??? If we have more than one of these, consider constructing full
4727      words in registers and using alpha_expand_unaligned_store_words.  */
4728   while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4729     {
4730       alpha_expand_unaligned_store (orig_dst, data_regs[i], 4, ofs);
4731       ofs += 4;
4732       i++;
4733     }
4734
4735   if (dst_align >= 16)
4736     while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4737       {
4738         emit_move_insn (adjust_address (orig_dst, HImode, ofs), data_regs[i]);
4739         i++;
4740         ofs += 2;
4741       }
4742   else
4743     while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4744       {
4745         alpha_expand_unaligned_store (orig_dst, data_regs[i], 2, ofs);
4746         i++;
4747         ofs += 2;
4748       }
4749
4750   while (i < nregs && GET_MODE (data_regs[i]) == QImode)
4751     {
4752       emit_move_insn (adjust_address (orig_dst, QImode, ofs), data_regs[i]);
4753       i++;
4754       ofs += 1;
4755     }
4756
4757  dst_done:
4758
4759   if (i != nregs)
4760     abort ();
4761
4762   return 1;
4763 }
4764
4765 int
4766 alpha_expand_block_clear (rtx operands[])
4767 {
4768   rtx bytes_rtx = operands[1];
4769   rtx align_rtx = operands[2];
4770   HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4771   HOST_WIDE_INT bytes = orig_bytes;
4772   HOST_WIDE_INT align = INTVAL (align_rtx) * BITS_PER_UNIT;
4773   HOST_WIDE_INT alignofs = 0;
4774   rtx orig_dst = operands[0];
4775   rtx tmp;
4776   int i, words, ofs = 0;
4777   
4778   if (orig_bytes <= 0)
4779     return 1;
4780   if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4781     return 0;
4782
4783   /* Look for stricter alignment.  */
4784   tmp = XEXP (orig_dst, 0);
4785   if (GET_CODE (tmp) == REG)
4786     align = MAX (align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4787   else if (GET_CODE (tmp) == PLUS
4788            && GET_CODE (XEXP (tmp, 0)) == REG
4789            && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4790     {
4791       HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4792       int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4793
4794       if (a > align)
4795         {
4796           if (a >= 64)
4797             align = a, alignofs = 8 - c % 8;
4798           else if (a >= 32)
4799             align = a, alignofs = 4 - c % 4;
4800           else if (a >= 16)
4801             align = a, alignofs = 2 - c % 2;
4802         }
4803     }
4804   else if (GET_CODE (tmp) == ADDRESSOF)
4805     {
4806       enum machine_mode mode;
4807
4808       mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1);
4809       if (GET_MODE (XEXP (tmp, 0)) == mode)
4810         {
4811           emit_move_insn (XEXP (tmp, 0), const0_rtx);
4812           return 1;
4813         }
4814
4815       /* No appropriate mode; fall back on memory.  */
4816       orig_dst = replace_equiv_address (orig_dst, copy_addr_to_reg (tmp));
4817       align = GET_MODE_BITSIZE (GET_MODE (XEXP (tmp, 0)));
4818     }
4819
4820   /* Handle an unaligned prefix first.  */
4821
4822   if (alignofs > 0)
4823     {
4824 #if HOST_BITS_PER_WIDE_INT >= 64
4825       /* Given that alignofs is bounded by align, the only time BWX could
4826          generate three stores is for a 7 byte fill.  Prefer two individual
4827          stores over a load/mask/store sequence.  */
4828       if ((!TARGET_BWX || alignofs == 7)
4829                && align >= 32
4830                && !(alignofs == 4 && bytes >= 4))
4831         {
4832           enum machine_mode mode = (align >= 64 ? DImode : SImode);
4833           int inv_alignofs = (align >= 64 ? 8 : 4) - alignofs;
4834           rtx mem, tmp;
4835           HOST_WIDE_INT mask;
4836
4837           mem = adjust_address (orig_dst, mode, ofs - inv_alignofs);
4838           set_mem_alias_set (mem, 0);
4839
4840           mask = ~(~(HOST_WIDE_INT)0 << (inv_alignofs * 8));
4841           if (bytes < alignofs)
4842             {
4843               mask |= ~(HOST_WIDE_INT)0 << ((inv_alignofs + bytes) * 8);
4844               ofs += bytes;
4845               bytes = 0;
4846             }
4847           else
4848             {
4849               bytes -= alignofs;
4850               ofs += alignofs;
4851             }
4852           alignofs = 0;
4853
4854           tmp = expand_binop (mode, and_optab, mem, GEN_INT (mask),
4855                               NULL_RTX, 1, OPTAB_WIDEN);
4856
4857           emit_move_insn (mem, tmp);
4858         }
4859 #endif
4860
4861       if (TARGET_BWX && (alignofs & 1) && bytes >= 1)
4862         {
4863           emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
4864           bytes -= 1;
4865           ofs += 1;
4866           alignofs -= 1;
4867         }
4868       if (TARGET_BWX && align >= 16 && (alignofs & 3) == 2 && bytes >= 2)
4869         {
4870           emit_move_insn (adjust_address (orig_dst, HImode, ofs), const0_rtx);
4871           bytes -= 2;
4872           ofs += 2;
4873           alignofs -= 2;
4874         }
4875       if (alignofs == 4 && bytes >= 4)
4876         {
4877           emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4878           bytes -= 4;
4879           ofs += 4;
4880           alignofs = 0;
4881         }
4882
4883       /* If we've not used the extra lead alignment information by now,
4884          we won't be able to.  Downgrade align to match what's left over.  */
4885       if (alignofs > 0)
4886         {
4887           alignofs = alignofs & -alignofs;
4888           align = MIN (align, alignofs * BITS_PER_UNIT);
4889         }
4890     }
4891
4892   /* Handle a block of contiguous long-words.  */
4893
4894   if (align >= 64 && bytes >= 8)
4895     {
4896       words = bytes / 8;
4897
4898       for (i = 0; i < words; ++i)
4899         emit_move_insn (adjust_address (orig_dst, DImode, ofs + i * 8),
4900                         const0_rtx);
4901
4902       bytes -= words * 8;
4903       ofs += words * 8;
4904     }
4905
4906   /* If the block is large and appropriately aligned, emit a single
4907      store followed by a sequence of stq_u insns.  */
4908
4909   if (align >= 32 && bytes > 16)
4910     {
4911       rtx orig_dsta;
4912
4913       emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4914       bytes -= 4;
4915       ofs += 4;
4916
4917       orig_dsta = XEXP (orig_dst, 0);
4918       if (GET_CODE (orig_dsta) == LO_SUM)
4919         orig_dsta = force_reg (Pmode, orig_dsta);
4920
4921       words = bytes / 8;
4922       for (i = 0; i < words; ++i)
4923         {
4924           rtx mem
4925             = change_address (orig_dst, DImode,
4926                               gen_rtx_AND (DImode,
4927                                            plus_constant (orig_dsta, ofs + i*8),
4928                                            GEN_INT (-8)));
4929           set_mem_alias_set (mem, 0);
4930           emit_move_insn (mem, const0_rtx);
4931         }
4932
4933       /* Depending on the alignment, the first stq_u may have overlapped
4934          with the initial stl, which means that the last stq_u didn't
4935          write as much as it would appear.  Leave those questionable bytes
4936          unaccounted for.  */
4937       bytes -= words * 8 - 4;
4938       ofs += words * 8 - 4;
4939     }
4940
4941   /* Handle a smaller block of aligned words.  */
4942
4943   if ((align >= 64 && bytes == 4)
4944       || (align == 32 && bytes >= 4))
4945     {
4946       words = bytes / 4;
4947
4948       for (i = 0; i < words; ++i)
4949         emit_move_insn (adjust_address (orig_dst, SImode, ofs + i * 4),
4950                         const0_rtx);
4951
4952       bytes -= words * 4;
4953       ofs += words * 4;
4954     }
4955
4956   /* An unaligned block uses stq_u stores for as many as possible.  */
4957
4958   if (bytes >= 8)
4959     {
4960       words = bytes / 8;
4961
4962       alpha_expand_unaligned_store_words (NULL, orig_dst, words, ofs);
4963
4964       bytes -= words * 8;
4965       ofs += words * 8;
4966     }
4967
4968   /* Next clean up any trailing pieces.  */
4969
4970 #if HOST_BITS_PER_WIDE_INT >= 64
4971   /* Count the number of bits in BYTES for which aligned stores could
4972      be emitted.  */
4973   words = 0;
4974   for (i = (TARGET_BWX ? 1 : 4); i * BITS_PER_UNIT <= align ; i <<= 1)
4975     if (bytes & i)
4976       words += 1;
4977
4978   /* If we have appropriate alignment (and it wouldn't take too many
4979      instructions otherwise), mask out the bytes we need.  */
4980   if (TARGET_BWX ? words > 2 : bytes > 0)
4981     {
4982       if (align >= 64)
4983         {
4984           rtx mem, tmp;
4985           HOST_WIDE_INT mask;
4986
4987           mem = adjust_address (orig_dst, DImode, ofs);
4988           set_mem_alias_set (mem, 0);
4989
4990           mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
4991
4992           tmp = expand_binop (DImode, and_optab, mem, GEN_INT (mask),
4993                               NULL_RTX, 1, OPTAB_WIDEN);
4994
4995           emit_move_insn (mem, tmp);
4996           return 1;
4997         }
4998       else if (align >= 32 && bytes < 4)
4999         {
5000           rtx mem, tmp;
5001           HOST_WIDE_INT mask;
5002
5003           mem = adjust_address (orig_dst, SImode, ofs);
5004           set_mem_alias_set (mem, 0);
5005
5006           mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
5007
5008           tmp = expand_binop (SImode, and_optab, mem, GEN_INT (mask),
5009                               NULL_RTX, 1, OPTAB_WIDEN);
5010
5011           emit_move_insn (mem, tmp);
5012           return 1;
5013         }
5014     }
5015 #endif
5016
5017   if (!TARGET_BWX && bytes >= 4)
5018     {
5019       alpha_expand_unaligned_store (orig_dst, const0_rtx, 4, ofs);
5020       bytes -= 4;
5021       ofs += 4;
5022     }
5023
5024   if (bytes >= 2)
5025     {
5026       if (align >= 16)
5027         {
5028           do {
5029             emit_move_insn (adjust_address (orig_dst, HImode, ofs),
5030                             const0_rtx);
5031             bytes -= 2;
5032             ofs += 2;
5033           } while (bytes >= 2);
5034         }
5035       else if (! TARGET_BWX)
5036         {
5037           alpha_expand_unaligned_store (orig_dst, const0_rtx, 2, ofs);
5038           bytes -= 2;
5039           ofs += 2;
5040         }
5041     }
5042
5043   while (bytes > 0)
5044     {
5045       emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
5046       bytes -= 1;
5047       ofs += 1;
5048     }
5049
5050   return 1;
5051 }
5052
5053 /* Returns a mask so that zap(x, value) == x & mask.  */
5054
5055 rtx
5056 alpha_expand_zap_mask (HOST_WIDE_INT value)
5057 {
5058   rtx result;
5059   int i;
5060
5061   if (HOST_BITS_PER_WIDE_INT >= 64)
5062     {
5063       HOST_WIDE_INT mask = 0;
5064
5065       for (i = 7; i >= 0; --i)
5066         {
5067           mask <<= 8;
5068           if (!((value >> i) & 1))
5069             mask |= 0xff;
5070         }
5071
5072       result = gen_int_mode (mask, DImode);
5073     }
5074   else if (HOST_BITS_PER_WIDE_INT == 32)
5075     {
5076       HOST_WIDE_INT mask_lo = 0, mask_hi = 0;
5077
5078       for (i = 7; i >= 4; --i)
5079         {
5080           mask_hi <<= 8;
5081           if (!((value >> i) & 1))
5082             mask_hi |= 0xff;
5083         }
5084
5085       for (i = 3; i >= 0; --i)
5086         {
5087           mask_lo <<= 8;
5088           if (!((value >> i) & 1))
5089             mask_lo |= 0xff;
5090         }
5091
5092       result = immed_double_const (mask_lo, mask_hi, DImode);
5093     }
5094   else
5095     abort ();
5096
5097   return result;
5098 }
5099
5100 void
5101 alpha_expand_builtin_vector_binop (rtx (*gen) (rtx, rtx, rtx),
5102                                    enum machine_mode mode,
5103                                    rtx op0, rtx op1, rtx op2)
5104 {
5105   op0 = gen_lowpart (mode, op0);
5106
5107   if (op1 == const0_rtx)
5108     op1 = CONST0_RTX (mode);
5109   else
5110     op1 = gen_lowpart (mode, op1);
5111
5112   if (op2 == const0_rtx)
5113     op2 = CONST0_RTX (mode);
5114   else
5115     op2 = gen_lowpart (mode, op2);
5116
5117   emit_insn ((*gen) (op0, op1, op2));
5118 }
5119 \f
5120 /* Adjust the cost of a scheduling dependency.  Return the new cost of
5121    a dependency LINK or INSN on DEP_INSN.  COST is the current cost.  */
5122
5123 static int
5124 alpha_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
5125 {
5126   enum attr_type insn_type, dep_insn_type;
5127
5128   /* If the dependence is an anti-dependence, there is no cost.  For an
5129      output dependence, there is sometimes a cost, but it doesn't seem
5130      worth handling those few cases.  */
5131   if (REG_NOTE_KIND (link) != 0)
5132     return cost;
5133
5134   /* If we can't recognize the insns, we can't really do anything.  */
5135   if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
5136     return cost;
5137
5138   insn_type = get_attr_type (insn);
5139   dep_insn_type = get_attr_type (dep_insn);
5140
5141   /* Bring in the user-defined memory latency.  */
5142   if (dep_insn_type == TYPE_ILD
5143       || dep_insn_type == TYPE_FLD
5144       || dep_insn_type == TYPE_LDSYM)
5145     cost += alpha_memory_latency-1;
5146
5147   /* Everything else handled in DFA bypasses now.  */
5148
5149   return cost;
5150 }
5151
5152 /* The number of instructions that can be issued per cycle.  */
5153
5154 static int
5155 alpha_issue_rate (void)
5156 {
5157   return (alpha_cpu == PROCESSOR_EV4 ? 2 : 4);
5158 }
5159
5160 static int
5161 alpha_use_dfa_pipeline_interface (void)
5162 {
5163   return true;
5164 }
5165
5166 /* How many alternative schedules to try.  This should be as wide as the
5167    scheduling freedom in the DFA, but no wider.  Making this value too
5168    large results extra work for the scheduler.
5169
5170    For EV4, loads can be issued to either IB0 or IB1, thus we have 2
5171    alternative schedules.  For EV5, we can choose between E0/E1 and
5172    FA/FM.  For EV6, an arithmetic insn can be issued to U0/U1/L0/L1.  */
5173
5174 static int
5175 alpha_multipass_dfa_lookahead (void)
5176 {
5177   return (alpha_cpu == PROCESSOR_EV6 ? 4 : 2);
5178 }
5179 \f
5180 /* Machine-specific function data.  */
5181
5182 struct machine_function GTY(())
5183 {
5184   /* For unicosmk.  */
5185   /* List of call information words for calls from this function.  */
5186   struct rtx_def *first_ciw;
5187   struct rtx_def *last_ciw;
5188   int ciw_count;
5189
5190   /* List of deferred case vectors.  */
5191   struct rtx_def *addr_list;
5192
5193   /* For OSF.  */
5194   const char *some_ld_name;
5195 };
5196
5197 /* How to allocate a 'struct machine_function'.  */
5198
5199 static struct machine_function *
5200 alpha_init_machine_status (void)
5201 {
5202   return ((struct machine_function *) 
5203                 ggc_alloc_cleared (sizeof (struct machine_function)));
5204 }
5205
5206 /* Functions to save and restore alpha_return_addr_rtx.  */
5207
5208 /* Start the ball rolling with RETURN_ADDR_RTX.  */
5209
5210 rtx
5211 alpha_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
5212 {
5213   if (count != 0)
5214     return const0_rtx;
5215
5216   return get_hard_reg_initial_val (Pmode, REG_RA);
5217 }
5218
5219 /* Return or create a pseudo containing the gp value for the current
5220    function.  Needed only if TARGET_LD_BUGGY_LDGP.  */
5221
5222 rtx
5223 alpha_gp_save_rtx (void)
5224 {
5225   rtx r = get_hard_reg_initial_val (DImode, 29);
5226   if (GET_CODE (r) != MEM)
5227     r = gen_mem_addressof (r, NULL_TREE, /*rescan=*/true);
5228   return r;
5229 }
5230
5231 static int
5232 alpha_ra_ever_killed (void)
5233 {
5234   rtx top;
5235
5236   if (!has_hard_reg_initial_val (Pmode, REG_RA))
5237     return regs_ever_live[REG_RA];
5238
5239   push_topmost_sequence ();
5240   top = get_insns ();
5241   pop_topmost_sequence ();
5242
5243   return reg_set_between_p (gen_rtx_REG (Pmode, REG_RA), top, NULL_RTX);
5244 }
5245
5246 \f
5247 /* Return the trap mode suffix applicable to the current
5248    instruction, or NULL.  */
5249
5250 static const char *
5251 get_trap_mode_suffix (void)
5252 {
5253   enum attr_trap_suffix s = get_attr_trap_suffix (current_output_insn);
5254
5255   switch (s)
5256     {
5257     case TRAP_SUFFIX_NONE:
5258       return NULL;
5259
5260     case TRAP_SUFFIX_SU:
5261       if (alpha_fptm >= ALPHA_FPTM_SU)
5262         return "su";
5263       return NULL;
5264
5265     case TRAP_SUFFIX_SUI:
5266       if (alpha_fptm >= ALPHA_FPTM_SUI)
5267         return "sui";
5268       return NULL;
5269
5270     case TRAP_SUFFIX_V_SV:
5271       switch (alpha_fptm)
5272         {
5273         case ALPHA_FPTM_N:
5274           return NULL;
5275         case ALPHA_FPTM_U:
5276           return "v";
5277         case ALPHA_FPTM_SU:
5278         case ALPHA_FPTM_SUI:
5279           return "sv";
5280         }
5281       break;
5282
5283     case TRAP_SUFFIX_V_SV_SVI:
5284       switch (alpha_fptm)
5285         {
5286         case ALPHA_FPTM_N:
5287           return NULL;
5288         case ALPHA_FPTM_U:
5289           return "v";
5290         case ALPHA_FPTM_SU:
5291           return "sv";
5292         case ALPHA_FPTM_SUI:
5293           return "svi";
5294         }
5295       break;
5296
5297     case TRAP_SUFFIX_U_SU_SUI:
5298       switch (alpha_fptm)
5299         {
5300         case ALPHA_FPTM_N:
5301           return NULL;
5302         case ALPHA_FPTM_U:
5303           return "u";
5304         case ALPHA_FPTM_SU:
5305           return "su";
5306         case ALPHA_FPTM_SUI:
5307           return "sui";
5308         }
5309       break;
5310     }
5311   abort ();
5312 }
5313
5314 /* Return the rounding mode suffix applicable to the current
5315    instruction, or NULL.  */
5316
5317 static const char *
5318 get_round_mode_suffix (void)
5319 {
5320   enum attr_round_suffix s = get_attr_round_suffix (current_output_insn);
5321
5322   switch (s)
5323     {
5324     case ROUND_SUFFIX_NONE:
5325       return NULL;
5326     case ROUND_SUFFIX_NORMAL:
5327       switch (alpha_fprm)
5328         {
5329         case ALPHA_FPRM_NORM:
5330           return NULL;
5331         case ALPHA_FPRM_MINF: 
5332           return "m";
5333         case ALPHA_FPRM_CHOP:
5334           return "c";
5335         case ALPHA_FPRM_DYN:
5336           return "d";
5337         }
5338       break;
5339
5340     case ROUND_SUFFIX_C:
5341       return "c";
5342     }
5343   abort ();
5344 }
5345
5346 /* Locate some local-dynamic symbol still in use by this function
5347    so that we can print its name in some movdi_er_tlsldm pattern.  */
5348
5349 static int
5350 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
5351 {
5352   rtx x = *px;
5353
5354   if (GET_CODE (x) == SYMBOL_REF
5355       && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
5356     {
5357       cfun->machine->some_ld_name = XSTR (x, 0);
5358       return 1;
5359     }
5360
5361   return 0;
5362 }
5363
5364 static const char *
5365 get_some_local_dynamic_name (void)
5366 {
5367   rtx insn;
5368
5369   if (cfun->machine->some_ld_name)
5370     return cfun->machine->some_ld_name;
5371
5372   for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
5373     if (INSN_P (insn)
5374         && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
5375       return cfun->machine->some_ld_name;
5376
5377   abort ();
5378 }
5379
5380 /* Print an operand.  Recognize special options, documented below.  */
5381
5382 void
5383 print_operand (FILE *file, rtx x, int code)
5384 {
5385   int i;
5386
5387   switch (code)
5388     {
5389     case '~':
5390       /* Print the assembler name of the current function.  */
5391       assemble_name (file, alpha_fnname);
5392       break;
5393
5394     case '&':
5395       assemble_name (file, get_some_local_dynamic_name ());
5396       break;
5397
5398     case '/':
5399       {
5400         const char *trap = get_trap_mode_suffix ();
5401         const char *round = get_round_mode_suffix ();
5402
5403         if (trap || round)
5404           fprintf (file, (TARGET_AS_SLASH_BEFORE_SUFFIX ? "/%s%s" : "%s%s"),
5405                    (trap ? trap : ""), (round ? round : ""));
5406         break;
5407       }
5408
5409     case ',':
5410       /* Generates single precision instruction suffix.  */
5411       fputc ((TARGET_FLOAT_VAX ? 'f' : 's'), file);
5412       break;
5413
5414     case '-':
5415       /* Generates double precision instruction suffix.  */
5416       fputc ((TARGET_FLOAT_VAX ? 'g' : 't'), file);
5417       break;
5418
5419     case '+':
5420       /* Generates a nop after a noreturn call at the very end of the
5421          function.  */
5422       if (next_real_insn (current_output_insn) == 0)
5423         fprintf (file, "\n\tnop");
5424       break;
5425
5426     case '#':
5427       if (alpha_this_literal_sequence_number == 0)
5428         alpha_this_literal_sequence_number = alpha_next_sequence_number++;
5429       fprintf (file, "%d", alpha_this_literal_sequence_number);
5430       break;
5431
5432     case '*':
5433       if (alpha_this_gpdisp_sequence_number == 0)
5434         alpha_this_gpdisp_sequence_number = alpha_next_sequence_number++;
5435       fprintf (file, "%d", alpha_this_gpdisp_sequence_number);
5436       break;
5437
5438     case 'H':
5439       if (GET_CODE (x) == HIGH)
5440         output_addr_const (file, XEXP (x, 0));
5441       else
5442         output_operand_lossage ("invalid %%H value");
5443       break;
5444
5445     case 'J':
5446       {
5447         const char *lituse;
5448
5449         if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSGD_CALL)
5450           {
5451             x = XVECEXP (x, 0, 0);
5452             lituse = "lituse_tlsgd";
5453           }
5454         else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSLDM_CALL)
5455           {
5456             x = XVECEXP (x, 0, 0);
5457             lituse = "lituse_tlsldm";
5458           }
5459         else if (GET_CODE (x) == CONST_INT)
5460           lituse = "lituse_jsr";
5461         else
5462           {
5463             output_operand_lossage ("invalid %%J value");
5464             break;
5465           }
5466
5467         if (x != const0_rtx)
5468           fprintf (file, "\t\t!%s!%d", lituse, (int) INTVAL (x));
5469       }
5470       break;
5471
5472     case 'j':
5473       {
5474         const char *lituse;
5475
5476 #ifdef HAVE_AS_JSRDIRECT_RELOCS
5477         lituse = "lituse_jsrdirect";
5478 #else
5479         lituse = "lituse_jsr";
5480 #endif
5481
5482         if (INTVAL (x) == 0)
5483           abort ();
5484         fprintf (file, "\t\t!%s!%d", lituse, (int) INTVAL (x));
5485       }
5486       break;
5487     case 'r':
5488       /* If this operand is the constant zero, write it as "$31".  */
5489       if (GET_CODE (x) == REG)
5490         fprintf (file, "%s", reg_names[REGNO (x)]);
5491       else if (x == CONST0_RTX (GET_MODE (x)))
5492         fprintf (file, "$31");
5493       else
5494         output_operand_lossage ("invalid %%r value");
5495       break;
5496
5497     case 'R':
5498       /* Similar, but for floating-point.  */
5499       if (GET_CODE (x) == REG)
5500         fprintf (file, "%s", reg_names[REGNO (x)]);
5501       else if (x == CONST0_RTX (GET_MODE (x)))
5502         fprintf (file, "$f31");
5503       else
5504         output_operand_lossage ("invalid %%R value");
5505       break;
5506
5507     case 'N':
5508       /* Write the 1's complement of a constant.  */
5509       if (GET_CODE (x) != CONST_INT)
5510         output_operand_lossage ("invalid %%N value");
5511
5512       fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
5513       break;
5514
5515     case 'P':
5516       /* Write 1 << C, for a constant C.  */
5517       if (GET_CODE (x) != CONST_INT)
5518         output_operand_lossage ("invalid %%P value");
5519
5520       fprintf (file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) 1 << INTVAL (x));
5521       break;
5522
5523     case 'h':
5524       /* Write the high-order 16 bits of a constant, sign-extended.  */
5525       if (GET_CODE (x) != CONST_INT)
5526         output_operand_lossage ("invalid %%h value");
5527
5528       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) >> 16);
5529       break;
5530
5531     case 'L':
5532       /* Write the low-order 16 bits of a constant, sign-extended.  */
5533       if (GET_CODE (x) != CONST_INT)
5534         output_operand_lossage ("invalid %%L value");
5535
5536       fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5537                (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
5538       break;
5539
5540     case 'm':
5541       /* Write mask for ZAP insn.  */
5542       if (GET_CODE (x) == CONST_DOUBLE)
5543         {
5544           HOST_WIDE_INT mask = 0;
5545           HOST_WIDE_INT value;
5546
5547           value = CONST_DOUBLE_LOW (x);
5548           for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5549                i++, value >>= 8)
5550             if (value & 0xff)
5551               mask |= (1 << i);
5552
5553           value = CONST_DOUBLE_HIGH (x);
5554           for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5555                i++, value >>= 8)
5556             if (value & 0xff)
5557               mask |= (1 << (i + sizeof (int)));
5558
5559           fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask & 0xff);
5560         }
5561
5562       else if (GET_CODE (x) == CONST_INT)
5563         {
5564           HOST_WIDE_INT mask = 0, value = INTVAL (x);
5565
5566           for (i = 0; i < 8; i++, value >>= 8)
5567             if (value & 0xff)
5568               mask |= (1 << i);
5569
5570           fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask);
5571         }
5572       else
5573         output_operand_lossage ("invalid %%m value");
5574       break;
5575
5576     case 'M':
5577       /* 'b', 'w', 'l', or 'q' as the value of the constant.  */
5578       if (GET_CODE (x) != CONST_INT
5579           || (INTVAL (x) != 8 && INTVAL (x) != 16
5580               && INTVAL (x) != 32 && INTVAL (x) != 64))
5581         output_operand_lossage ("invalid %%M value");
5582
5583       fprintf (file, "%s",
5584                (INTVAL (x) == 8 ? "b"
5585                 : INTVAL (x) == 16 ? "w"
5586                 : INTVAL (x) == 32 ? "l"
5587                 : "q"));
5588       break;
5589
5590     case 'U':
5591       /* Similar, except do it from the mask.  */
5592       if (GET_CODE (x) == CONST_INT)
5593         {
5594           HOST_WIDE_INT value = INTVAL (x);
5595
5596           if (value == 0xff)
5597             {
5598               fputc ('b', file);
5599               break;
5600             }
5601           if (value == 0xffff)
5602             {
5603               fputc ('w', file);
5604               break;
5605             }
5606           if (value == 0xffffffff)
5607             {
5608               fputc ('l', file);
5609               break;
5610             }
5611           if (value == -1)
5612             {
5613               fputc ('q', file);
5614               break;
5615             }
5616         }
5617       else if (HOST_BITS_PER_WIDE_INT == 32
5618                && GET_CODE (x) == CONST_DOUBLE
5619                && CONST_DOUBLE_LOW (x) == 0xffffffff
5620                && CONST_DOUBLE_HIGH (x) == 0)
5621         {
5622           fputc ('l', file);
5623           break;
5624         }
5625       output_operand_lossage ("invalid %%U value");
5626       break;
5627
5628     case 's':
5629       /* Write the constant value divided by 8 for little-endian mode or
5630          (56 - value) / 8 for big-endian mode.  */
5631
5632       if (GET_CODE (x) != CONST_INT
5633           || (unsigned HOST_WIDE_INT) INTVAL (x) >= (WORDS_BIG_ENDIAN
5634                                                      ? 56
5635                                                      : 64)  
5636           || (INTVAL (x) & 7) != 0)
5637         output_operand_lossage ("invalid %%s value");
5638
5639       fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5640                WORDS_BIG_ENDIAN
5641                ? (56 - INTVAL (x)) / 8
5642                : INTVAL (x) / 8);
5643       break;
5644
5645     case 'S':
5646       /* Same, except compute (64 - c) / 8 */
5647
5648       if (GET_CODE (x) != CONST_INT
5649           && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
5650           && (INTVAL (x) & 7) != 8)
5651         output_operand_lossage ("invalid %%s value");
5652
5653       fprintf (file, HOST_WIDE_INT_PRINT_DEC, (64 - INTVAL (x)) / 8);
5654       break;
5655
5656     case 't':
5657       {
5658         /* On Unicos/Mk systems: use a DEX expression if the symbol
5659            clashes with a register name.  */
5660         int dex = unicosmk_need_dex (x);
5661         if (dex)
5662           fprintf (file, "DEX(%d)", dex);
5663         else
5664           output_addr_const (file, x);
5665       }
5666       break;
5667
5668     case 'C': case 'D': case 'c': case 'd':
5669       /* Write out comparison name.  */
5670       {
5671         enum rtx_code c = GET_CODE (x);
5672
5673         if (GET_RTX_CLASS (c) != '<')
5674           output_operand_lossage ("invalid %%C value");
5675
5676         else if (code == 'D')
5677           c = reverse_condition (c);
5678         else if (code == 'c')
5679           c = swap_condition (c);
5680         else if (code == 'd')
5681           c = swap_condition (reverse_condition (c));
5682
5683         if (c == LEU)
5684           fprintf (file, "ule");
5685         else if (c == LTU)
5686           fprintf (file, "ult");
5687         else if (c == UNORDERED)
5688           fprintf (file, "un");
5689         else
5690           fprintf (file, "%s", GET_RTX_NAME (c));
5691       }
5692       break;
5693
5694     case 'E':
5695       /* Write the divide or modulus operator.  */
5696       switch (GET_CODE (x))
5697         {
5698         case DIV:
5699           fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
5700           break;
5701         case UDIV:
5702           fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
5703           break;
5704         case MOD:
5705           fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
5706           break;
5707         case UMOD:
5708           fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
5709           break;
5710         default:
5711           output_operand_lossage ("invalid %%E value");
5712           break;
5713         }
5714       break;
5715
5716     case 'A':
5717       /* Write "_u" for unaligned access.  */
5718       if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
5719         fprintf (file, "_u");
5720       break;
5721
5722     case 0:
5723       if (GET_CODE (x) == REG)
5724         fprintf (file, "%s", reg_names[REGNO (x)]);
5725       else if (GET_CODE (x) == MEM)
5726         output_address (XEXP (x, 0));
5727       else if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == UNSPEC)
5728         {
5729           switch (XINT (XEXP (x, 0), 1))
5730             {
5731             case UNSPEC_DTPREL:
5732             case UNSPEC_TPREL:
5733               output_addr_const (file, XVECEXP (XEXP (x, 0), 0, 0));
5734               break;
5735             default:
5736               output_operand_lossage ("unknown relocation unspec");
5737               break;
5738             }
5739         }
5740       else
5741         output_addr_const (file, x);
5742       break;
5743
5744     default:
5745       output_operand_lossage ("invalid %%xn code");
5746     }
5747 }
5748
5749 void
5750 print_operand_address (FILE *file, rtx addr)
5751 {
5752   int basereg = 31;
5753   HOST_WIDE_INT offset = 0;
5754
5755   if (GET_CODE (addr) == AND)
5756     addr = XEXP (addr, 0);
5757
5758   if (GET_CODE (addr) == PLUS
5759       && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5760     {
5761       offset = INTVAL (XEXP (addr, 1));
5762       addr = XEXP (addr, 0);
5763     }
5764
5765   if (GET_CODE (addr) == LO_SUM)
5766     {
5767       const char *reloc16, *reloclo;
5768       rtx op1 = XEXP (addr, 1);
5769
5770       if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1, 0)) == UNSPEC)
5771         {
5772           op1 = XEXP (op1, 0);
5773           switch (XINT (op1, 1))
5774             {
5775             case UNSPEC_DTPREL:
5776               reloc16 = NULL;
5777               reloclo = (alpha_tls_size == 16 ? "dtprel" : "dtprello");
5778               break;
5779             case UNSPEC_TPREL:
5780               reloc16 = NULL;
5781               reloclo = (alpha_tls_size == 16 ? "tprel" : "tprello");
5782               break;
5783             default:
5784               output_operand_lossage ("unknown relocation unspec");
5785               return;
5786             }
5787
5788           output_addr_const (file, XVECEXP (op1, 0, 0));
5789         }
5790       else
5791         {
5792           reloc16 = "gprel";
5793           reloclo = "gprellow";
5794           output_addr_const (file, op1);
5795         }
5796
5797       if (offset)
5798         fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC, offset);
5799       
5800       addr = XEXP (addr, 0);
5801       if (GET_CODE (addr) == REG)
5802         basereg = REGNO (addr);
5803       else if (GET_CODE (addr) == SUBREG
5804                && GET_CODE (SUBREG_REG (addr)) == REG)
5805         basereg = subreg_regno (addr);
5806       else
5807         abort ();
5808
5809       fprintf (file, "($%d)\t\t!%s", basereg,
5810                (basereg == 29 ? reloc16 : reloclo));
5811       return;
5812     }
5813
5814   if (GET_CODE (addr) == REG)
5815     basereg = REGNO (addr);
5816   else if (GET_CODE (addr) == SUBREG
5817            && GET_CODE (SUBREG_REG (addr)) == REG)
5818     basereg = subreg_regno (addr);
5819   else if (GET_CODE (addr) == CONST_INT)
5820     offset = INTVAL (addr);
5821
5822 #if TARGET_ABI_OPEN_VMS
5823   else if (GET_CODE (addr) == SYMBOL_REF)
5824     {
5825       fprintf (file, "%s", XSTR (addr, 0));
5826       return;
5827     }
5828   else if (GET_CODE (addr) == CONST
5829            && GET_CODE (XEXP (addr, 0)) == PLUS
5830            && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF)
5831     {
5832       fprintf (file, "%s+" HOST_WIDE_INT_PRINT_DEC,
5833                XSTR (XEXP (XEXP (addr, 0), 0), 0),
5834                INTVAL (XEXP (XEXP (addr, 0), 1)));
5835       return;
5836     }
5837 #endif
5838
5839   else
5840     abort ();
5841
5842   fprintf (file, HOST_WIDE_INT_PRINT_DEC "($%d)", offset, basereg);
5843 }
5844 \f
5845 /* Emit RTL insns to initialize the variable parts of a trampoline at
5846    TRAMP. FNADDR is an RTX for the address of the function's pure
5847    code.  CXT is an RTX for the static chain value for the function.
5848
5849    The three offset parameters are for the individual template's
5850    layout.  A JMPOFS < 0 indicates that the trampoline does not 
5851    contain instructions at all.
5852
5853    We assume here that a function will be called many more times than
5854    its address is taken (e.g., it might be passed to qsort), so we
5855    take the trouble to initialize the "hint" field in the JMP insn.
5856    Note that the hint field is PC (new) + 4 * bits 13:0.  */
5857
5858 void
5859 alpha_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt,
5860                              int fnofs, int cxtofs, int jmpofs)
5861 {
5862   rtx temp, temp1, addr;
5863   /* VMS really uses DImode pointers in memory at this point.  */
5864   enum machine_mode mode = TARGET_ABI_OPEN_VMS ? Pmode : ptr_mode;
5865
5866 #ifdef POINTERS_EXTEND_UNSIGNED
5867   fnaddr = convert_memory_address (mode, fnaddr);
5868   cxt = convert_memory_address (mode, cxt);
5869 #endif
5870
5871   /* Store function address and CXT.  */
5872   addr = memory_address (mode, plus_constant (tramp, fnofs));
5873   emit_move_insn (gen_rtx_MEM (mode, addr), fnaddr);
5874   addr = memory_address (mode, plus_constant (tramp, cxtofs));
5875   emit_move_insn (gen_rtx_MEM (mode, addr), cxt);
5876
5877   /* This has been disabled since the hint only has a 32k range, and in
5878      no existing OS is the stack within 32k of the text segment.  */
5879   if (0 && jmpofs >= 0)
5880     {
5881       /* Compute hint value.  */
5882       temp = force_operand (plus_constant (tramp, jmpofs+4), NULL_RTX);
5883       temp = expand_binop (DImode, sub_optab, fnaddr, temp, temp, 1,
5884                            OPTAB_WIDEN);
5885       temp = expand_shift (RSHIFT_EXPR, Pmode, temp,
5886                            build_int_2 (2, 0), NULL_RTX, 1);
5887       temp = expand_and (SImode, gen_lowpart (SImode, temp),
5888                          GEN_INT (0x3fff), 0);
5889
5890       /* Merge in the hint.  */
5891       addr = memory_address (SImode, plus_constant (tramp, jmpofs));
5892       temp1 = force_reg (SImode, gen_rtx_MEM (SImode, addr));
5893       temp1 = expand_and (SImode, temp1, GEN_INT (0xffffc000), NULL_RTX);
5894       temp1 = expand_binop (SImode, ior_optab, temp1, temp, temp1, 1,
5895                             OPTAB_WIDEN);
5896       emit_move_insn (gen_rtx_MEM (SImode, addr), temp1);
5897     }
5898
5899 #ifdef ENABLE_EXECUTE_STACK
5900   emit_library_call (init_one_libfunc ("__enable_execute_stack"),
5901                      0, VOIDmode, 1, tramp, Pmode);
5902 #endif
5903
5904   if (jmpofs >= 0)
5905     emit_insn (gen_imb ());
5906 }
5907 \f
5908 /* Determine where to put an argument to a function.
5909    Value is zero to push the argument on the stack,
5910    or a hard register in which to store the argument.
5911
5912    MODE is the argument's machine mode.
5913    TYPE is the data type of the argument (as a tree).
5914     This is null for libcalls where that information may
5915     not be available.
5916    CUM is a variable of type CUMULATIVE_ARGS which gives info about
5917     the preceding args and about the function being called.
5918    NAMED is nonzero if this argument is a named parameter
5919     (otherwise it is an extra parameter matching an ellipsis).
5920
5921    On Alpha the first 6 words of args are normally in registers
5922    and the rest are pushed.  */
5923
5924 rtx
5925 function_arg (CUMULATIVE_ARGS cum, enum machine_mode mode, tree type,
5926               int named ATTRIBUTE_UNUSED)
5927 {
5928   int basereg;
5929   int num_args;
5930
5931   /* Don't get confused and pass small structures in FP registers.  */
5932   if (type && AGGREGATE_TYPE_P (type))
5933     basereg = 16;
5934   else
5935     {
5936 #ifdef ENABLE_CHECKING
5937       /* With alpha_split_complex_arg, we shouldn't see any raw complex
5938          values here.  */
5939       if (COMPLEX_MODE_P (mode))
5940         abort ();
5941 #endif
5942
5943       /* Set up defaults for FP operands passed in FP registers, and
5944          integral operands passed in integer registers.  */
5945       if (TARGET_FPREGS && GET_MODE_CLASS (mode) == MODE_FLOAT)
5946         basereg = 32 + 16;
5947       else
5948         basereg = 16;
5949     }
5950
5951   /* ??? Irritatingly, the definition of CUMULATIVE_ARGS is different for
5952      the three platforms, so we can't avoid conditional compilation.  */
5953 #if TARGET_ABI_OPEN_VMS
5954     {
5955       if (mode == VOIDmode)
5956         return alpha_arg_info_reg_val (cum);
5957
5958       num_args = cum.num_args;
5959       if (num_args >= 6 || MUST_PASS_IN_STACK (mode, type))
5960         return NULL_RTX;
5961     }
5962 #elif TARGET_ABI_UNICOSMK
5963     {
5964       int size;
5965
5966       /* If this is the last argument, generate the call info word (CIW).  */
5967       /* ??? We don't include the caller's line number in the CIW because
5968          I don't know how to determine it if debug infos are turned off.  */
5969       if (mode == VOIDmode)
5970         {
5971           int i;
5972           HOST_WIDE_INT lo;
5973           HOST_WIDE_INT hi;
5974           rtx ciw;
5975
5976           lo = 0;
5977
5978           for (i = 0; i < cum.num_reg_words && i < 5; i++)
5979             if (cum.reg_args_type[i])
5980               lo |= (1 << (7 - i));
5981
5982           if (cum.num_reg_words == 6 && cum.reg_args_type[5])
5983             lo |= 7;
5984           else
5985             lo |= cum.num_reg_words;
5986
5987 #if HOST_BITS_PER_WIDE_INT == 32
5988           hi = (cum.num_args << 20) | cum.num_arg_words;
5989 #else
5990           lo = lo | ((HOST_WIDE_INT) cum.num_args << 52)
5991             | ((HOST_WIDE_INT) cum.num_arg_words << 32);
5992           hi = 0;
5993 #endif
5994           ciw = immed_double_const (lo, hi, DImode);
5995
5996           return gen_rtx_UNSPEC (DImode, gen_rtvec (1, ciw),
5997                                  UNSPEC_UMK_LOAD_CIW);
5998         }
5999
6000       size = ALPHA_ARG_SIZE (mode, type, named);
6001       num_args = cum.num_reg_words;
6002       if (MUST_PASS_IN_STACK (mode, type)
6003           || cum.num_reg_words + size > 6 || cum.force_stack)
6004         return NULL_RTX;
6005       else if (type && TYPE_MODE (type) == BLKmode)
6006         {
6007           rtx reg1, reg2;
6008
6009           reg1 = gen_rtx_REG (DImode, num_args + 16);
6010           reg1 = gen_rtx_EXPR_LIST (DImode, reg1, const0_rtx);
6011
6012           /* The argument fits in two registers. Note that we still need to
6013              reserve a register for empty structures.  */
6014           if (size == 0)
6015             return NULL_RTX;
6016           else if (size == 1)
6017             return gen_rtx_PARALLEL (mode, gen_rtvec (1, reg1));
6018           else
6019             {
6020               reg2 = gen_rtx_REG (DImode, num_args + 17);
6021               reg2 = gen_rtx_EXPR_LIST (DImode, reg2, GEN_INT (8));
6022               return gen_rtx_PARALLEL (mode, gen_rtvec (2, reg1, reg2));
6023             }
6024         }
6025     }
6026 #elif TARGET_ABI_OSF
6027     {
6028       if (cum >= 6)
6029         return NULL_RTX;
6030       num_args = cum;
6031
6032       /* VOID is passed as a special flag for "last argument".  */
6033       if (type == void_type_node)
6034         basereg = 16;
6035       else if (MUST_PASS_IN_STACK (mode, type))
6036         return NULL_RTX;
6037       else if (FUNCTION_ARG_PASS_BY_REFERENCE (cum, mode, type, named))
6038         basereg = 16;
6039     }
6040 #else
6041 #error Unhandled ABI
6042 #endif
6043
6044   return gen_rtx_REG (mode, num_args + basereg);
6045 }
6046
6047 /* Return true if TYPE must be returned in memory, instead of in registers.  */
6048
6049 static bool
6050 alpha_return_in_memory (tree type, tree fndecl ATTRIBUTE_UNUSED)
6051 {
6052   enum machine_mode mode = VOIDmode;
6053   int size;
6054
6055   if (type)
6056     {
6057       mode = TYPE_MODE (type);
6058
6059       /* All aggregates are returned in memory.  */
6060       if (AGGREGATE_TYPE_P (type))
6061         return true;
6062     }
6063
6064   size = GET_MODE_SIZE (mode);
6065   switch (GET_MODE_CLASS (mode))
6066     {
6067     case MODE_VECTOR_FLOAT:
6068       /* Pass all float vectors in memory, like an aggregate.  */
6069       return true;
6070
6071     case MODE_COMPLEX_FLOAT:
6072       /* We judge complex floats on the size of their element,
6073          not the size of the whole type.  */
6074       size = GET_MODE_UNIT_SIZE (mode);
6075       break;
6076
6077     case MODE_INT:
6078     case MODE_FLOAT:
6079     case MODE_COMPLEX_INT:
6080     case MODE_VECTOR_INT:
6081       break;
6082
6083     default:
6084       /* ??? We get called on all sorts of random stuff from 
6085          aggregate_value_p.  We can't abort, but it's not clear
6086          what's safe to return.  Pretend it's a struct I guess.  */
6087       return true;
6088     }
6089
6090   /* Otherwise types must fit in one register.  */
6091   return size > UNITS_PER_WORD;
6092 }
6093
6094 /* Define how to find the value returned by a function.  VALTYPE is the
6095    data type of the value (as a tree).  If the precise function being
6096    called is known, FUNC is its FUNCTION_DECL; otherwise, FUNC is 0.
6097    MODE is set instead of VALTYPE for libcalls.
6098
6099    On Alpha the value is found in $0 for integer functions and
6100    $f0 for floating-point functions.  */
6101
6102 rtx
6103 function_value (tree valtype, tree func ATTRIBUTE_UNUSED,
6104                 enum machine_mode mode)
6105 {
6106   unsigned int regnum;
6107   enum mode_class class;
6108
6109 #ifdef ENABLE_CHECKING
6110   if (valtype && alpha_return_in_memory (valtype, func))
6111     abort ();
6112 #endif
6113
6114   if (valtype)
6115     mode = TYPE_MODE (valtype);
6116
6117   class = GET_MODE_CLASS (mode);
6118   switch (class)
6119     {
6120     case MODE_INT:
6121       /* Do the same thing as PROMOTE_MODE.  */
6122       mode = DImode;
6123       /* FALLTHRU */
6124
6125     case MODE_COMPLEX_INT:
6126     case MODE_VECTOR_INT:
6127       regnum = 0;
6128       break;
6129
6130     case MODE_FLOAT:
6131       regnum = 32;
6132       break;
6133
6134     case MODE_COMPLEX_FLOAT:
6135       {
6136         enum machine_mode cmode = GET_MODE_INNER (mode);
6137
6138         return gen_rtx_PARALLEL
6139           (VOIDmode,
6140            gen_rtvec (2,
6141                       gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 32),
6142                                          GEN_INT (0)),
6143                       gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 33),
6144                                          GEN_INT (GET_MODE_SIZE (cmode)))));
6145       }
6146
6147     default:
6148       abort ();
6149     }
6150
6151   return gen_rtx_REG (mode, regnum);
6152 }
6153
6154 /* TCmode complex values are passed by invisible reference.  We 
6155    should not split these values.  */
6156
6157 static bool
6158 alpha_split_complex_arg (tree type)
6159 {
6160   return TYPE_MODE (type) != TCmode;
6161 }
6162
6163 static tree
6164 alpha_build_builtin_va_list (void)
6165 {
6166   tree base, ofs, space, record, type_decl;
6167
6168   if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
6169     return ptr_type_node;
6170
6171   record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6172   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6173   TREE_CHAIN (record) = type_decl;
6174   TYPE_NAME (record) = type_decl;
6175
6176   /* C++? SET_IS_AGGR_TYPE (record, 1); */
6177
6178   /* Dummy field to prevent alignment warnings.  */
6179   space = build_decl (FIELD_DECL, NULL_TREE, integer_type_node);
6180   DECL_FIELD_CONTEXT (space) = record;
6181   DECL_ARTIFICIAL (space) = 1;
6182   DECL_IGNORED_P (space) = 1;
6183
6184   ofs = build_decl (FIELD_DECL, get_identifier ("__offset"),
6185                     integer_type_node);
6186   DECL_FIELD_CONTEXT (ofs) = record;
6187   TREE_CHAIN (ofs) = space;
6188
6189   base = build_decl (FIELD_DECL, get_identifier ("__base"),
6190                      ptr_type_node);
6191   DECL_FIELD_CONTEXT (base) = record;
6192   TREE_CHAIN (base) = ofs;
6193
6194   TYPE_FIELDS (record) = base;
6195   layout_type (record);
6196
6197   return record;
6198 }
6199
6200 /* Perform any needed actions needed for a function that is receiving a
6201    variable number of arguments.  */
6202
6203 static void
6204 alpha_setup_incoming_varargs (CUMULATIVE_ARGS *pcum,
6205                               enum machine_mode mode ATTRIBUTE_UNUSED,
6206                               tree type ATTRIBUTE_UNUSED,
6207                               int *pretend_size, int no_rtl)
6208 {
6209 #if TARGET_ABI_UNICOSMK
6210   /* On Unicos/Mk, the standard subroutine __T3E_MISMATCH stores all register
6211      arguments on the stack. Unfortunately, it doesn't always store the first
6212      one (i.e. the one that arrives in $16 or $f16). This is not a problem
6213      with stdargs as we always have at least one named argument there.  */
6214   int num_reg_words = pcum->num_reg_words;
6215   if (num_reg_words < 6)
6216     {
6217       if (!no_rtl)
6218         {
6219           emit_insn (gen_umk_mismatch_args (GEN_INT (num_reg_words + 1)));
6220           emit_insn (gen_arg_home_umk ());
6221         }
6222       *pretend_size = 0;
6223     }
6224 #elif TARGET_ABI_OPEN_VMS
6225   /* For VMS, we allocate space for all 6 arg registers plus a count.
6226
6227      However, if NO registers need to be saved, don't allocate any space.
6228      This is not only because we won't need the space, but because AP
6229      includes the current_pretend_args_size and we don't want to mess up
6230      any ap-relative addresses already made.  */
6231   if (pcum->num_args < 6)
6232     {
6233       if (!no_rtl)
6234         {
6235           emit_move_insn (gen_rtx_REG (DImode, 1), virtual_incoming_args_rtx);
6236           emit_insn (gen_arg_home ());
6237         }
6238       *pretend_size = 7 * UNITS_PER_WORD;
6239     }
6240 #else
6241   /* On OSF/1 and friends, we allocate space for all 12 arg registers, but
6242      only push those that are remaining.  However, if NO registers need to
6243      be saved, don't allocate any space.  This is not only because we won't
6244      need the space, but because AP includes the current_pretend_args_size
6245      and we don't want to mess up any ap-relative addresses already made.
6246
6247      If we are not to use the floating-point registers, save the integer
6248      registers where we would put the floating-point registers.  This is
6249      not the most efficient way to implement varargs with just one register
6250      class, but it isn't worth doing anything more efficient in this rare
6251      case.  */
6252   CUMULATIVE_ARGS cum = *pcum;
6253
6254   if (cum >= 6)
6255     return;
6256
6257   if (!no_rtl)
6258     {
6259       int set = get_varargs_alias_set ();
6260       rtx tmp;
6261
6262       tmp = gen_rtx_MEM (BLKmode,
6263                          plus_constant (virtual_incoming_args_rtx,
6264                                         (cum + 6) * UNITS_PER_WORD));
6265       set_mem_alias_set (tmp, set);
6266       move_block_from_reg (16 + cum, tmp, 6 - cum);
6267
6268       tmp = gen_rtx_MEM (BLKmode,
6269                          plus_constant (virtual_incoming_args_rtx,
6270                                         cum * UNITS_PER_WORD));
6271       set_mem_alias_set (tmp, set);
6272       move_block_from_reg (16 + (TARGET_FPREGS ? 32 : 0) + cum, tmp,
6273                            6 - cum);
6274      }
6275   *pretend_size = 12 * UNITS_PER_WORD;
6276 #endif
6277 }
6278
6279 void
6280 alpha_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
6281 {
6282   HOST_WIDE_INT offset;
6283   tree t, offset_field, base_field;
6284
6285   if (TREE_CODE (TREE_TYPE (valist)) == ERROR_MARK)
6286     return;
6287
6288   if (TARGET_ABI_UNICOSMK)
6289     std_expand_builtin_va_start (valist, nextarg);
6290
6291   /* For Unix, SETUP_INCOMING_VARARGS moves the starting address base
6292      up by 48, storing fp arg registers in the first 48 bytes, and the
6293      integer arg registers in the next 48 bytes.  This is only done,
6294      however, if any integer registers need to be stored.
6295
6296      If no integer registers need be stored, then we must subtract 48
6297      in order to account for the integer arg registers which are counted
6298      in argsize above, but which are not actually stored on the stack.
6299      Must further be careful here about structures straddling the last
6300      integer argument register; that futzes with pretend_args_size, 
6301      which changes the meaning of AP.  */
6302
6303   if (NUM_ARGS <= 6)
6304     offset = TARGET_ABI_OPEN_VMS ? UNITS_PER_WORD : 6 * UNITS_PER_WORD;
6305   else
6306     offset = -6 * UNITS_PER_WORD + current_function_pretend_args_size;
6307
6308   if (TARGET_ABI_OPEN_VMS)
6309     {
6310       nextarg = plus_constant (nextarg, offset);
6311       nextarg = plus_constant (nextarg, NUM_ARGS * UNITS_PER_WORD);
6312       t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
6313                  make_tree (ptr_type_node, nextarg));
6314       TREE_SIDE_EFFECTS (t) = 1;
6315
6316       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6317     }
6318   else
6319     {
6320       base_field = TYPE_FIELDS (TREE_TYPE (valist));
6321       offset_field = TREE_CHAIN (base_field);
6322
6323       base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6324                           valist, base_field);
6325       offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6326                             valist, offset_field);
6327
6328       t = make_tree (ptr_type_node, virtual_incoming_args_rtx);
6329       t = build (PLUS_EXPR, ptr_type_node, t, build_int_2 (offset, 0));
6330       t = build (MODIFY_EXPR, TREE_TYPE (base_field), base_field, t);
6331       TREE_SIDE_EFFECTS (t) = 1;
6332       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6333
6334       t = build_int_2 (NUM_ARGS * UNITS_PER_WORD, 0);
6335       t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field, t);
6336       TREE_SIDE_EFFECTS (t) = 1;
6337       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6338     }
6339 }
6340
6341 rtx
6342 alpha_va_arg (tree valist, tree type)
6343 {
6344   rtx addr;
6345   tree t, type_size, rounded_size;
6346   tree offset_field, base_field, addr_tree, addend;
6347   tree wide_type, wide_ofs;
6348   int indirect = 0;
6349
6350   if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
6351     return std_expand_builtin_va_arg (valist, type);
6352
6353   if (type == error_mark_node
6354       || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
6355       || TREE_OVERFLOW (type_size))
6356     rounded_size = size_zero_node;
6357   else
6358     rounded_size = fold (build (MULT_EXPR, sizetype,
6359                                 fold (build (TRUNC_DIV_EXPR, sizetype,
6360                                              fold (build (PLUS_EXPR, sizetype,
6361                                                           type_size,
6362                                                           size_int (7))),
6363                                              size_int (8))),
6364                                 size_int (8)));
6365
6366   base_field = TYPE_FIELDS (TREE_TYPE (valist));
6367   offset_field = TREE_CHAIN (base_field);
6368
6369   base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6370                       valist, base_field);
6371   offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6372                         valist, offset_field);
6373
6374   /* If the type could not be passed in registers, skip the block
6375      reserved for the registers.  */
6376   if (MUST_PASS_IN_STACK (TYPE_MODE (type), type))
6377     {
6378       t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field,
6379                  build (MAX_EXPR, TREE_TYPE (offset_field), 
6380                         offset_field, build_int_2 (6*8, 0)));
6381       TREE_SIDE_EFFECTS (t) = 1;
6382       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6383     }
6384
6385   wide_type = make_signed_type (64);
6386   wide_ofs = save_expr (build1 (CONVERT_EXPR, wide_type, offset_field));
6387
6388   addend = wide_ofs;
6389
6390   if (TYPE_MODE (type) == TFmode || TYPE_MODE (type) == TCmode)
6391     {
6392       indirect = 1;
6393       rounded_size = size_int (UNITS_PER_WORD);
6394     }
6395   else if (TREE_CODE (type) == COMPLEX_TYPE)
6396     {
6397       rtx real_part, imag_part, value, tmp;
6398
6399       real_part = alpha_va_arg (valist, TREE_TYPE (type));
6400       imag_part = alpha_va_arg (valist, TREE_TYPE (type));
6401
6402       /* ??? Most irritatingly, we're not returning the value here,
6403          but the address.  Since real_part and imag_part are not
6404          necessarily contiguous, we must copy to local storage.  */
6405
6406       real_part = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (type)), real_part);
6407       imag_part = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (type)), imag_part);
6408       value = gen_rtx_CONCAT (TYPE_MODE (type), real_part, imag_part);
6409
6410       tmp = assign_temp (type, 0, 1, 0);
6411       emit_move_insn (tmp, value);
6412
6413       return XEXP (tmp, 0);
6414     }
6415   else if (TREE_CODE (type) == REAL_TYPE)
6416     {
6417       tree fpaddend, cond;
6418
6419       fpaddend = fold (build (PLUS_EXPR, TREE_TYPE (addend),
6420                               addend, build_int_2 (-6*8, 0)));
6421
6422       cond = fold (build (LT_EXPR, integer_type_node,
6423                           wide_ofs, build_int_2 (6*8, 0)));
6424
6425       addend = fold (build (COND_EXPR, TREE_TYPE (addend), cond,
6426                             fpaddend, addend));
6427     }
6428
6429   addr_tree = build (PLUS_EXPR, TREE_TYPE (base_field),
6430                      base_field, addend);
6431
6432   addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
6433   addr = copy_to_reg (addr);
6434
6435   t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field,
6436              build (PLUS_EXPR, TREE_TYPE (offset_field), 
6437                     offset_field, rounded_size));
6438   TREE_SIDE_EFFECTS (t) = 1;
6439   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6440
6441   if (indirect)
6442     {
6443       addr = force_reg (Pmode, addr);
6444       addr = gen_rtx_MEM (Pmode, addr);
6445     }
6446
6447   return addr;
6448 }
6449 \f
6450 /* Builtins.  */
6451
6452 enum alpha_builtin
6453 {
6454   ALPHA_BUILTIN_CMPBGE,
6455   ALPHA_BUILTIN_EXTBL,
6456   ALPHA_BUILTIN_EXTWL,
6457   ALPHA_BUILTIN_EXTLL,
6458   ALPHA_BUILTIN_EXTQL,
6459   ALPHA_BUILTIN_EXTWH,
6460   ALPHA_BUILTIN_EXTLH,
6461   ALPHA_BUILTIN_EXTQH,
6462   ALPHA_BUILTIN_INSBL,
6463   ALPHA_BUILTIN_INSWL,
6464   ALPHA_BUILTIN_INSLL,
6465   ALPHA_BUILTIN_INSQL,
6466   ALPHA_BUILTIN_INSWH,
6467   ALPHA_BUILTIN_INSLH,
6468   ALPHA_BUILTIN_INSQH,
6469   ALPHA_BUILTIN_MSKBL,
6470   ALPHA_BUILTIN_MSKWL,
6471   ALPHA_BUILTIN_MSKLL,
6472   ALPHA_BUILTIN_MSKQL,
6473   ALPHA_BUILTIN_MSKWH,
6474   ALPHA_BUILTIN_MSKLH,
6475   ALPHA_BUILTIN_MSKQH,
6476   ALPHA_BUILTIN_UMULH,
6477   ALPHA_BUILTIN_ZAP,
6478   ALPHA_BUILTIN_ZAPNOT,
6479   ALPHA_BUILTIN_AMASK,
6480   ALPHA_BUILTIN_IMPLVER,
6481   ALPHA_BUILTIN_RPCC,
6482   ALPHA_BUILTIN_THREAD_POINTER,
6483   ALPHA_BUILTIN_SET_THREAD_POINTER,
6484
6485   /* TARGET_MAX */
6486   ALPHA_BUILTIN_MINUB8,
6487   ALPHA_BUILTIN_MINSB8,
6488   ALPHA_BUILTIN_MINUW4,
6489   ALPHA_BUILTIN_MINSW4,
6490   ALPHA_BUILTIN_MAXUB8,
6491   ALPHA_BUILTIN_MAXSB8,
6492   ALPHA_BUILTIN_MAXUW4,
6493   ALPHA_BUILTIN_MAXSW4,
6494   ALPHA_BUILTIN_PERR,
6495   ALPHA_BUILTIN_PKLB,
6496   ALPHA_BUILTIN_PKWB,
6497   ALPHA_BUILTIN_UNPKBL,
6498   ALPHA_BUILTIN_UNPKBW,
6499
6500   /* TARGET_CIX */
6501   ALPHA_BUILTIN_CTTZ,
6502   ALPHA_BUILTIN_CTLZ,
6503   ALPHA_BUILTIN_CTPOP,
6504
6505   ALPHA_BUILTIN_max
6506 };
6507
6508 static unsigned int const code_for_builtin[ALPHA_BUILTIN_max] = {
6509   CODE_FOR_builtin_cmpbge,
6510   CODE_FOR_builtin_extbl,
6511   CODE_FOR_builtin_extwl,
6512   CODE_FOR_builtin_extll,
6513   CODE_FOR_builtin_extql,
6514   CODE_FOR_builtin_extwh,
6515   CODE_FOR_builtin_extlh,
6516   CODE_FOR_builtin_extqh,
6517   CODE_FOR_builtin_insbl,
6518   CODE_FOR_builtin_inswl,
6519   CODE_FOR_builtin_insll,
6520   CODE_FOR_builtin_insql,
6521   CODE_FOR_builtin_inswh,
6522   CODE_FOR_builtin_inslh,
6523   CODE_FOR_builtin_insqh,
6524   CODE_FOR_builtin_mskbl,
6525   CODE_FOR_builtin_mskwl,
6526   CODE_FOR_builtin_mskll,
6527   CODE_FOR_builtin_mskql,
6528   CODE_FOR_builtin_mskwh,
6529   CODE_FOR_builtin_msklh,
6530   CODE_FOR_builtin_mskqh,
6531   CODE_FOR_umuldi3_highpart,
6532   CODE_FOR_builtin_zap,
6533   CODE_FOR_builtin_zapnot,
6534   CODE_FOR_builtin_amask,
6535   CODE_FOR_builtin_implver,
6536   CODE_FOR_builtin_rpcc,
6537   CODE_FOR_load_tp,
6538   CODE_FOR_set_tp,
6539
6540   /* TARGET_MAX */
6541   CODE_FOR_builtin_minub8,
6542   CODE_FOR_builtin_minsb8,
6543   CODE_FOR_builtin_minuw4,
6544   CODE_FOR_builtin_minsw4,
6545   CODE_FOR_builtin_maxub8,
6546   CODE_FOR_builtin_maxsb8,
6547   CODE_FOR_builtin_maxuw4,
6548   CODE_FOR_builtin_maxsw4,
6549   CODE_FOR_builtin_perr,
6550   CODE_FOR_builtin_pklb,
6551   CODE_FOR_builtin_pkwb,
6552   CODE_FOR_builtin_unpkbl,
6553   CODE_FOR_builtin_unpkbw,
6554
6555   /* TARGET_CIX */
6556   CODE_FOR_builtin_cttz,
6557   CODE_FOR_builtin_ctlz,
6558   CODE_FOR_builtin_ctpop
6559 };
6560
6561 struct alpha_builtin_def
6562 {
6563   const char *name;
6564   enum alpha_builtin code;
6565   unsigned int target_mask;
6566 };
6567
6568 static struct alpha_builtin_def const zero_arg_builtins[] = {
6569   { "__builtin_alpha_implver",  ALPHA_BUILTIN_IMPLVER,  0 },
6570   { "__builtin_alpha_rpcc",     ALPHA_BUILTIN_RPCC,     0 }
6571 };
6572
6573 static struct alpha_builtin_def const one_arg_builtins[] = {
6574   { "__builtin_alpha_amask",    ALPHA_BUILTIN_AMASK,    0 },
6575   { "__builtin_alpha_pklb",     ALPHA_BUILTIN_PKLB,     MASK_MAX },
6576   { "__builtin_alpha_pkwb",     ALPHA_BUILTIN_PKWB,     MASK_MAX },
6577   { "__builtin_alpha_unpkbl",   ALPHA_BUILTIN_UNPKBL,   MASK_MAX },
6578   { "__builtin_alpha_unpkbw",   ALPHA_BUILTIN_UNPKBW,   MASK_MAX },
6579   { "__builtin_alpha_cttz",     ALPHA_BUILTIN_CTTZ,     MASK_CIX },
6580   { "__builtin_alpha_ctlz",     ALPHA_BUILTIN_CTLZ,     MASK_CIX },
6581   { "__builtin_alpha_ctpop",    ALPHA_BUILTIN_CTPOP,    MASK_CIX }
6582 };
6583
6584 static struct alpha_builtin_def const two_arg_builtins[] = {
6585   { "__builtin_alpha_cmpbge",   ALPHA_BUILTIN_CMPBGE,   0 },
6586   { "__builtin_alpha_extbl",    ALPHA_BUILTIN_EXTBL,    0 },
6587   { "__builtin_alpha_extwl",    ALPHA_BUILTIN_EXTWL,    0 },
6588   { "__builtin_alpha_extll",    ALPHA_BUILTIN_EXTLL,    0 },
6589   { "__builtin_alpha_extql",    ALPHA_BUILTIN_EXTQL,    0 },
6590   { "__builtin_alpha_extwh",    ALPHA_BUILTIN_EXTWH,    0 },
6591   { "__builtin_alpha_extlh",    ALPHA_BUILTIN_EXTLH,    0 },
6592   { "__builtin_alpha_extqh",    ALPHA_BUILTIN_EXTQH,    0 },
6593   { "__builtin_alpha_insbl",    ALPHA_BUILTIN_INSBL,    0 },
6594   { "__builtin_alpha_inswl",    ALPHA_BUILTIN_INSWL,    0 },
6595   { "__builtin_alpha_insll",    ALPHA_BUILTIN_INSLL,    0 },
6596   { "__builtin_alpha_insql",    ALPHA_BUILTIN_INSQL,    0 },
6597   { "__builtin_alpha_inswh",    ALPHA_BUILTIN_INSWH,    0 },
6598   { "__builtin_alpha_inslh",    ALPHA_BUILTIN_INSLH,    0 },
6599   { "__builtin_alpha_insqh",    ALPHA_BUILTIN_INSQH,    0 },
6600   { "__builtin_alpha_mskbl",    ALPHA_BUILTIN_MSKBL,    0 },
6601   { "__builtin_alpha_mskwl",    ALPHA_BUILTIN_MSKWL,    0 },
6602   { "__builtin_alpha_mskll",    ALPHA_BUILTIN_MSKLL,    0 },
6603   { "__builtin_alpha_mskql",    ALPHA_BUILTIN_MSKQL,    0 },
6604   { "__builtin_alpha_mskwh",    ALPHA_BUILTIN_MSKWH,    0 },
6605   { "__builtin_alpha_msklh",    ALPHA_BUILTIN_MSKLH,    0 },
6606   { "__builtin_alpha_mskqh",    ALPHA_BUILTIN_MSKQH,    0 },
6607   { "__builtin_alpha_umulh",    ALPHA_BUILTIN_UMULH,    0 },
6608   { "__builtin_alpha_zap",      ALPHA_BUILTIN_ZAP,      0 },
6609   { "__builtin_alpha_zapnot",   ALPHA_BUILTIN_ZAPNOT,   0 },
6610   { "__builtin_alpha_minub8",   ALPHA_BUILTIN_MINUB8,   MASK_MAX },
6611   { "__builtin_alpha_minsb8",   ALPHA_BUILTIN_MINSB8,   MASK_MAX },
6612   { "__builtin_alpha_minuw4",   ALPHA_BUILTIN_MINUW4,   MASK_MAX },
6613   { "__builtin_alpha_minsw4",   ALPHA_BUILTIN_MINSW4,   MASK_MAX },
6614   { "__builtin_alpha_maxub8",   ALPHA_BUILTIN_MAXUB8,   MASK_MAX },
6615   { "__builtin_alpha_maxsb8",   ALPHA_BUILTIN_MAXSB8,   MASK_MAX },
6616   { "__builtin_alpha_maxuw4",   ALPHA_BUILTIN_MAXUW4,   MASK_MAX },
6617   { "__builtin_alpha_maxsw4",   ALPHA_BUILTIN_MAXSW4,   MASK_MAX },
6618   { "__builtin_alpha_perr",     ALPHA_BUILTIN_PERR,     MASK_MAX }
6619 };
6620
6621 static void
6622 alpha_init_builtins (void)
6623 {
6624   const struct alpha_builtin_def *p;
6625   tree ftype;
6626   size_t i;
6627
6628   ftype = build_function_type (long_integer_type_node, void_list_node);
6629
6630   p = zero_arg_builtins;
6631   for (i = 0; i < ARRAY_SIZE (zero_arg_builtins); ++i, ++p)
6632     if ((target_flags & p->target_mask) == p->target_mask)
6633       builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6634                         NULL, NULL_TREE);
6635
6636   ftype = build_function_type_list (long_integer_type_node,
6637                                     long_integer_type_node, NULL_TREE);
6638
6639   p = one_arg_builtins;
6640   for (i = 0; i < ARRAY_SIZE (one_arg_builtins); ++i, ++p)
6641     if ((target_flags & p->target_mask) == p->target_mask)
6642       builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6643                         NULL, NULL_TREE);
6644
6645   ftype = build_function_type_list (long_integer_type_node,
6646                                     long_integer_type_node,
6647                                     long_integer_type_node, NULL_TREE);
6648
6649   p = two_arg_builtins;
6650   for (i = 0; i < ARRAY_SIZE (two_arg_builtins); ++i, ++p)
6651     if ((target_flags & p->target_mask) == p->target_mask)
6652       builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6653                         NULL, NULL_TREE);
6654
6655   ftype = build_function_type (ptr_type_node, void_list_node);
6656   builtin_function ("__builtin_thread_pointer", ftype,
6657                     ALPHA_BUILTIN_THREAD_POINTER, BUILT_IN_MD,
6658                     NULL, NULL_TREE);
6659
6660   ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
6661   builtin_function ("__builtin_set_thread_pointer", ftype,
6662                     ALPHA_BUILTIN_SET_THREAD_POINTER, BUILT_IN_MD,
6663                     NULL, NULL_TREE);
6664 }
6665
6666 /* Expand an expression EXP that calls a built-in function,
6667    with result going to TARGET if that's convenient
6668    (and in mode MODE if that's convenient).
6669    SUBTARGET may be used as the target for computing one of EXP's operands.
6670    IGNORE is nonzero if the value is to be ignored.  */
6671
6672 static rtx
6673 alpha_expand_builtin (tree exp, rtx target,
6674                       rtx subtarget ATTRIBUTE_UNUSED,
6675                       enum machine_mode mode ATTRIBUTE_UNUSED,
6676                       int ignore ATTRIBUTE_UNUSED)
6677 {
6678 #define MAX_ARGS 2
6679
6680   tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6681   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6682   tree arglist = TREE_OPERAND (exp, 1);
6683   enum insn_code icode;
6684   rtx op[MAX_ARGS], pat;
6685   int arity;
6686   bool nonvoid;
6687
6688   if (fcode >= ALPHA_BUILTIN_max)
6689     internal_error ("bad builtin fcode");
6690   icode = code_for_builtin[fcode];
6691   if (icode == 0)
6692     internal_error ("bad builtin fcode");
6693
6694   nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
6695
6696   for (arglist = TREE_OPERAND (exp, 1), arity = 0;
6697        arglist;
6698        arglist = TREE_CHAIN (arglist), arity++)
6699     {
6700       const struct insn_operand_data *insn_op;
6701
6702       tree arg = TREE_VALUE (arglist);
6703       if (arg == error_mark_node)
6704         return NULL_RTX;
6705       if (arity > MAX_ARGS)
6706         return NULL_RTX;
6707
6708       insn_op = &insn_data[icode].operand[arity + nonvoid];
6709
6710       op[arity] = expand_expr (arg, NULL_RTX, insn_op->mode, 0);
6711
6712       if (!(*insn_op->predicate) (op[arity], insn_op->mode))
6713         op[arity] = copy_to_mode_reg (insn_op->mode, op[arity]);
6714     }
6715
6716   if (nonvoid)
6717     {
6718       enum machine_mode tmode = insn_data[icode].operand[0].mode;
6719       if (!target
6720           || GET_MODE (target) != tmode
6721           || !(*insn_data[icode].operand[0].predicate) (target, tmode))
6722         target = gen_reg_rtx (tmode);
6723     }
6724
6725   switch (arity)
6726     {
6727     case 0:
6728       pat = GEN_FCN (icode) (target);
6729       break;
6730     case 1:
6731       if (nonvoid)
6732         pat = GEN_FCN (icode) (target, op[0]);
6733       else
6734         pat = GEN_FCN (icode) (op[0]);
6735       break;
6736     case 2:
6737       pat = GEN_FCN (icode) (target, op[0], op[1]);
6738       break;
6739     default:
6740       abort ();
6741     }
6742   if (!pat)
6743     return NULL_RTX;
6744   emit_insn (pat);
6745
6746   if (nonvoid)
6747     return target;
6748   else
6749     return const0_rtx;
6750 }
6751 \f
6752 /* This page contains routines that are used to determine what the function
6753    prologue and epilogue code will do and write them out.  */
6754
6755 /* Compute the size of the save area in the stack.  */
6756
6757 /* These variables are used for communication between the following functions.
6758    They indicate various things about the current function being compiled
6759    that are used to tell what kind of prologue, epilogue and procedure
6760    descriptor to generate.  */
6761
6762 /* Nonzero if we need a stack procedure.  */
6763 enum alpha_procedure_types {PT_NULL = 0, PT_REGISTER = 1, PT_STACK = 2};
6764 static enum alpha_procedure_types alpha_procedure_type;
6765
6766 /* Register number (either FP or SP) that is used to unwind the frame.  */
6767 static int vms_unwind_regno;
6768
6769 /* Register number used to save FP.  We need not have one for RA since
6770    we don't modify it for register procedures.  This is only defined
6771    for register frame procedures.  */
6772 static int vms_save_fp_regno;
6773
6774 /* Register number used to reference objects off our PV.  */
6775 static int vms_base_regno;
6776
6777 /* Compute register masks for saved registers.  */
6778
6779 static void
6780 alpha_sa_mask (unsigned long *imaskP, unsigned long *fmaskP)
6781 {
6782   unsigned long imask = 0;
6783   unsigned long fmask = 0;
6784   unsigned int i;
6785
6786   /* When outputting a thunk, we don't have valid register life info,
6787      but assemble_start_function wants to output .frame and .mask
6788      directives.  */
6789   if (current_function_is_thunk)
6790     {
6791       *imaskP = 0;
6792       *fmaskP = 0;
6793       return;
6794     }
6795
6796   if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
6797     imask |= (1UL << HARD_FRAME_POINTER_REGNUM);
6798
6799   /* One for every register we have to save.  */
6800   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
6801     if (! fixed_regs[i] && ! call_used_regs[i]
6802         && regs_ever_live[i] && i != REG_RA
6803         && (!TARGET_ABI_UNICOSMK || i != HARD_FRAME_POINTER_REGNUM))
6804       {
6805         if (i < 32)
6806           imask |= (1UL << i);
6807         else
6808           fmask |= (1UL << (i - 32));
6809       }
6810
6811   /* We need to restore these for the handler.  */
6812   if (current_function_calls_eh_return)
6813     {
6814       for (i = 0; ; ++i)
6815         {
6816           unsigned regno = EH_RETURN_DATA_REGNO (i);
6817           if (regno == INVALID_REGNUM)
6818             break;
6819           imask |= 1UL << regno;
6820         }
6821     }
6822      
6823   /* If any register spilled, then spill the return address also.  */
6824   /* ??? This is required by the Digital stack unwind specification
6825      and isn't needed if we're doing Dwarf2 unwinding.  */
6826   if (imask || fmask || alpha_ra_ever_killed ())
6827     imask |= (1UL << REG_RA);
6828
6829   *imaskP = imask;
6830   *fmaskP = fmask;
6831 }
6832
6833 int
6834 alpha_sa_size (void)
6835 {
6836   unsigned long mask[2];
6837   int sa_size = 0;
6838   int i, j;
6839
6840   alpha_sa_mask (&mask[0], &mask[1]);
6841
6842   if (TARGET_ABI_UNICOSMK)
6843     {
6844       if (mask[0] || mask[1])
6845         sa_size = 14;
6846     }
6847   else
6848     {
6849       for (j = 0; j < 2; ++j)
6850         for (i = 0; i < 32; ++i)
6851           if ((mask[j] >> i) & 1)
6852             sa_size++;
6853     }
6854
6855   if (TARGET_ABI_UNICOSMK)
6856     {
6857       /* We might not need to generate a frame if we don't make any calls
6858          (including calls to __T3E_MISMATCH if this is a vararg function),
6859          don't have any local variables which require stack slots, don't
6860          use alloca and have not determined that we need a frame for other
6861          reasons.  */
6862
6863       alpha_procedure_type
6864         = (sa_size || get_frame_size() != 0
6865            || current_function_outgoing_args_size
6866            || current_function_stdarg || current_function_calls_alloca
6867            || frame_pointer_needed)
6868           ? PT_STACK : PT_REGISTER;
6869
6870       /* Always reserve space for saving callee-saved registers if we
6871          need a frame as required by the calling convention.  */
6872       if (alpha_procedure_type == PT_STACK)
6873         sa_size = 14;
6874     }
6875   else if (TARGET_ABI_OPEN_VMS)
6876     {
6877       /* Start by assuming we can use a register procedure if we don't
6878          make any calls (REG_RA not used) or need to save any
6879          registers and a stack procedure if we do.  */
6880       if ((mask[0] >> REG_RA) & 1)
6881         alpha_procedure_type = PT_STACK;
6882       else if (get_frame_size() != 0)
6883         alpha_procedure_type = PT_REGISTER;
6884       else
6885         alpha_procedure_type = PT_NULL;
6886
6887       /* Don't reserve space for saving FP & RA yet.  Do that later after we've
6888          made the final decision on stack procedure vs register procedure.  */
6889       if (alpha_procedure_type == PT_STACK)
6890         sa_size -= 2;
6891
6892       /* Decide whether to refer to objects off our PV via FP or PV.
6893          If we need FP for something else or if we receive a nonlocal
6894          goto (which expects PV to contain the value), we must use PV.
6895          Otherwise, start by assuming we can use FP.  */
6896
6897       vms_base_regno
6898         = (frame_pointer_needed
6899            || current_function_has_nonlocal_label
6900            || alpha_procedure_type == PT_STACK
6901            || current_function_outgoing_args_size)
6902           ? REG_PV : HARD_FRAME_POINTER_REGNUM;
6903
6904       /* If we want to copy PV into FP, we need to find some register
6905          in which to save FP.  */
6906
6907       vms_save_fp_regno = -1;
6908       if (vms_base_regno == HARD_FRAME_POINTER_REGNUM)
6909         for (i = 0; i < 32; i++)
6910           if (! fixed_regs[i] && call_used_regs[i] && ! regs_ever_live[i])
6911             vms_save_fp_regno = i;
6912
6913       if (vms_save_fp_regno == -1 && alpha_procedure_type == PT_REGISTER)
6914         vms_base_regno = REG_PV, alpha_procedure_type = PT_STACK;
6915       else if (alpha_procedure_type == PT_NULL)
6916         vms_base_regno = REG_PV;
6917
6918       /* Stack unwinding should be done via FP unless we use it for PV.  */
6919       vms_unwind_regno = (vms_base_regno == REG_PV
6920                           ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
6921
6922       /* If this is a stack procedure, allow space for saving FP and RA.  */
6923       if (alpha_procedure_type == PT_STACK)
6924         sa_size += 2;
6925     }
6926   else
6927     {
6928       /* Our size must be even (multiple of 16 bytes).  */
6929       if (sa_size & 1)
6930         sa_size++;
6931     }
6932
6933   return sa_size * 8;
6934 }
6935
6936 /* Define the offset between two registers, one to be eliminated,
6937    and the other its replacement, at the start of a routine.  */
6938
6939 HOST_WIDE_INT
6940 alpha_initial_elimination_offset (unsigned int from,
6941                                   unsigned int to ATTRIBUTE_UNUSED)
6942 {
6943   HOST_WIDE_INT ret;
6944
6945   ret = alpha_sa_size ();
6946   ret += ALPHA_ROUND (current_function_outgoing_args_size);
6947
6948   if (from == FRAME_POINTER_REGNUM)
6949     ;
6950   else if (from == ARG_POINTER_REGNUM)
6951     ret += (ALPHA_ROUND (get_frame_size ()
6952                          + current_function_pretend_args_size)
6953             - current_function_pretend_args_size);
6954   else
6955     abort ();
6956
6957   return ret;
6958 }
6959
6960 int
6961 alpha_pv_save_size (void)
6962 {
6963   alpha_sa_size ();
6964   return alpha_procedure_type == PT_STACK ? 8 : 0;
6965 }
6966
6967 int
6968 alpha_using_fp (void)
6969 {
6970   alpha_sa_size ();
6971   return vms_unwind_regno == HARD_FRAME_POINTER_REGNUM;
6972 }
6973
6974 #if TARGET_ABI_OPEN_VMS
6975
6976 const struct attribute_spec vms_attribute_table[] =
6977 {
6978   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
6979   { "overlaid",   0, 0, true,  false, false, NULL },
6980   { "global",     0, 0, true,  false, false, NULL },
6981   { "initialize", 0, 0, true,  false, false, NULL },
6982   { NULL,         0, 0, false, false, false, NULL }
6983 };
6984
6985 #endif
6986
6987 static int
6988 find_lo_sum_using_gp (rtx *px, void *data ATTRIBUTE_UNUSED)
6989 {
6990   return GET_CODE (*px) == LO_SUM && XEXP (*px, 0) == pic_offset_table_rtx;
6991 }
6992
6993 int
6994 alpha_find_lo_sum_using_gp (rtx insn)
6995 {
6996   return for_each_rtx (&PATTERN (insn), find_lo_sum_using_gp, NULL) > 0;
6997 }
6998
6999 static int
7000 alpha_does_function_need_gp (void)
7001 {
7002   rtx insn;
7003
7004   /* The GP being variable is an OSF abi thing.  */
7005   if (! TARGET_ABI_OSF)
7006     return 0;
7007
7008   /* We need the gp to load the address of __mcount.  */
7009   if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
7010     return 1;
7011
7012   /* The code emitted by alpha_output_mi_thunk_osf uses the gp.  */
7013   if (current_function_is_thunk)
7014     return 1;
7015
7016   /* The nonlocal receiver pattern assumes that the gp is valid for
7017      the nested function.  Reasonable because it's almost always set
7018      correctly already.  For the cases where that's wrong, make sure
7019      the nested function loads its gp on entry.  */
7020   if (current_function_has_nonlocal_goto)
7021     return 1;
7022
7023   /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first. 
7024      Even if we are a static function, we still need to do this in case
7025      our address is taken and passed to something like qsort.  */
7026
7027   push_topmost_sequence ();
7028   insn = get_insns ();
7029   pop_topmost_sequence ();
7030
7031   for (; insn; insn = NEXT_INSN (insn))
7032     if (INSN_P (insn)
7033         && GET_CODE (PATTERN (insn)) != USE
7034         && GET_CODE (PATTERN (insn)) != CLOBBER
7035         && get_attr_usegp (insn))
7036       return 1;
7037
7038   return 0;
7039 }
7040
7041 \f
7042 /* Helper function to set RTX_FRAME_RELATED_P on instructions, including
7043    sequences.  */
7044
7045 static rtx
7046 set_frame_related_p (void)
7047 {
7048   rtx seq = get_insns ();
7049   rtx insn;
7050
7051   end_sequence ();
7052
7053   if (!seq)
7054     return NULL_RTX;
7055
7056   if (INSN_P (seq))
7057     {
7058       insn = seq;
7059       while (insn != NULL_RTX)
7060         {
7061           RTX_FRAME_RELATED_P (insn) = 1;
7062           insn = NEXT_INSN (insn);
7063         }
7064       seq = emit_insn (seq);
7065     }
7066   else
7067     {
7068       seq = emit_insn (seq);
7069       RTX_FRAME_RELATED_P (seq) = 1;
7070     }
7071   return seq;
7072 }
7073
7074 #define FRP(exp)  (start_sequence (), exp, set_frame_related_p ())
7075
7076 /* Generates a store with the proper unwind info attached.  VALUE is
7077    stored at BASE_REG+BASE_OFS.  If FRAME_BIAS is non-zero, then BASE_REG
7078    contains SP+FRAME_BIAS, and that is the unwind info that should be
7079    generated.  If FRAME_REG != VALUE, then VALUE is being stored on
7080    behalf of FRAME_REG, and FRAME_REG should be present in the unwind.  */
7081
7082 static void
7083 emit_frame_store_1 (rtx value, rtx base_reg, HOST_WIDE_INT frame_bias,
7084                     HOST_WIDE_INT base_ofs, rtx frame_reg)
7085 {
7086   rtx addr, mem, insn;
7087
7088   addr = plus_constant (base_reg, base_ofs);
7089   mem = gen_rtx_MEM (DImode, addr);
7090   set_mem_alias_set (mem, alpha_sr_alias_set);
7091
7092   insn = emit_move_insn (mem, value);
7093   RTX_FRAME_RELATED_P (insn) = 1;
7094
7095   if (frame_bias || value != frame_reg)
7096     {
7097       if (frame_bias)
7098         {
7099           addr = plus_constant (stack_pointer_rtx, frame_bias + base_ofs);
7100           mem = gen_rtx_MEM (DImode, addr);
7101         }
7102
7103       REG_NOTES (insn)
7104         = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7105                              gen_rtx_SET (VOIDmode, mem, frame_reg),
7106                              REG_NOTES (insn));
7107     }
7108 }
7109
7110 static void
7111 emit_frame_store (unsigned int regno, rtx base_reg,
7112                   HOST_WIDE_INT frame_bias, HOST_WIDE_INT base_ofs)
7113 {
7114   rtx reg = gen_rtx_REG (DImode, regno);
7115   emit_frame_store_1 (reg, base_reg, frame_bias, base_ofs, reg);
7116 }
7117
7118 /* Write function prologue.  */
7119
7120 /* On vms we have two kinds of functions:
7121
7122    - stack frame (PROC_STACK)
7123         these are 'normal' functions with local vars and which are
7124         calling other functions
7125    - register frame (PROC_REGISTER)
7126         keeps all data in registers, needs no stack
7127
7128    We must pass this to the assembler so it can generate the
7129    proper pdsc (procedure descriptor)
7130    This is done with the '.pdesc' command.
7131
7132    On not-vms, we don't really differentiate between the two, as we can
7133    simply allocate stack without saving registers.  */
7134
7135 void
7136 alpha_expand_prologue (void)
7137 {
7138   /* Registers to save.  */
7139   unsigned long imask = 0;
7140   unsigned long fmask = 0;
7141   /* Stack space needed for pushing registers clobbered by us.  */
7142   HOST_WIDE_INT sa_size;
7143   /* Complete stack size needed.  */
7144   HOST_WIDE_INT frame_size;
7145   /* Offset from base reg to register save area.  */
7146   HOST_WIDE_INT reg_offset;
7147   rtx sa_reg;
7148   int i;
7149
7150   sa_size = alpha_sa_size ();
7151
7152   frame_size = get_frame_size ();
7153   if (TARGET_ABI_OPEN_VMS)
7154     frame_size = ALPHA_ROUND (sa_size 
7155                               + (alpha_procedure_type == PT_STACK ? 8 : 0)
7156                               + frame_size
7157                               + current_function_pretend_args_size);
7158   else if (TARGET_ABI_UNICOSMK)
7159     /* We have to allocate space for the DSIB if we generate a frame.  */
7160     frame_size = ALPHA_ROUND (sa_size
7161                               + (alpha_procedure_type == PT_STACK ? 48 : 0))
7162                  + ALPHA_ROUND (frame_size
7163                                 + current_function_outgoing_args_size);
7164   else
7165     frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7166                   + sa_size
7167                   + ALPHA_ROUND (frame_size
7168                                  + current_function_pretend_args_size));
7169
7170   if (TARGET_ABI_OPEN_VMS)
7171     reg_offset = 8;
7172   else
7173     reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7174
7175   alpha_sa_mask (&imask, &fmask);
7176
7177   /* Emit an insn to reload GP, if needed.  */
7178   if (TARGET_ABI_OSF)
7179     {
7180       alpha_function_needs_gp = alpha_does_function_need_gp ();
7181       if (alpha_function_needs_gp)
7182         emit_insn (gen_prologue_ldgp ());
7183     }
7184
7185   /* TARGET_PROFILING_NEEDS_GP actually implies that we need to insert
7186      the call to mcount ourselves, rather than having the linker do it
7187      magically in response to -pg.  Since _mcount has special linkage,
7188      don't represent the call as a call.  */
7189   if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
7190     emit_insn (gen_prologue_mcount ());
7191
7192   if (TARGET_ABI_UNICOSMK)
7193     unicosmk_gen_dsib (&imask);
7194
7195   /* Adjust the stack by the frame size.  If the frame size is > 4096
7196      bytes, we need to be sure we probe somewhere in the first and last
7197      4096 bytes (we can probably get away without the latter test) and
7198      every 8192 bytes in between.  If the frame size is > 32768, we
7199      do this in a loop.  Otherwise, we generate the explicit probe
7200      instructions. 
7201
7202      Note that we are only allowed to adjust sp once in the prologue.  */
7203
7204   if (frame_size <= 32768)
7205     {
7206       if (frame_size > 4096)
7207         {
7208           int probed = 4096;
7209
7210           do
7211             emit_insn (gen_probe_stack (GEN_INT (TARGET_ABI_UNICOSMK
7212                                                  ? -probed + 64
7213                                                  : -probed)));
7214           while ((probed += 8192) < frame_size);
7215
7216           /* We only have to do this probe if we aren't saving registers.  */
7217           if (sa_size == 0 && probed + 4096 < frame_size)
7218             emit_insn (gen_probe_stack (GEN_INT (-frame_size)));
7219         }
7220
7221       if (frame_size != 0)
7222         FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
7223                                     GEN_INT (TARGET_ABI_UNICOSMK
7224                                              ? -frame_size + 64
7225                                              : -frame_size))));
7226     }
7227   else
7228     {
7229       /* Here we generate code to set R22 to SP + 4096 and set R23 to the
7230          number of 8192 byte blocks to probe.  We then probe each block
7231          in the loop and then set SP to the proper location.  If the
7232          amount remaining is > 4096, we have to do one more probe if we
7233          are not saving any registers.  */
7234
7235       HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
7236       HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
7237       rtx ptr = gen_rtx_REG (DImode, 22);
7238       rtx count = gen_rtx_REG (DImode, 23);
7239       rtx seq;
7240
7241       emit_move_insn (count, GEN_INT (blocks));
7242       emit_insn (gen_adddi3 (ptr, stack_pointer_rtx,
7243                              GEN_INT (TARGET_ABI_UNICOSMK ? 4096 - 64 : 4096)));
7244
7245       /* Because of the difficulty in emitting a new basic block this
7246          late in the compilation, generate the loop as a single insn.  */
7247       emit_insn (gen_prologue_stack_probe_loop (count, ptr));
7248
7249       if (leftover > 4096 && sa_size == 0)
7250         {
7251           rtx last = gen_rtx_MEM (DImode, plus_constant (ptr, -leftover));
7252           MEM_VOLATILE_P (last) = 1;
7253           emit_move_insn (last, const0_rtx);
7254         }
7255
7256       if (TARGET_ABI_WINDOWS_NT)
7257         {
7258           /* For NT stack unwind (done by 'reverse execution'), it's
7259              not OK to take the result of a loop, even though the value
7260              is already in ptr, so we reload it via a single operation
7261              and subtract it to sp. 
7262
7263              Yes, that's correct -- we have to reload the whole constant
7264              into a temporary via ldah+lda then subtract from sp.  */
7265
7266           HOST_WIDE_INT lo, hi;
7267           lo = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
7268           hi = frame_size - lo;
7269
7270           emit_move_insn (ptr, GEN_INT (hi));
7271           emit_insn (gen_adddi3 (ptr, ptr, GEN_INT (lo)));
7272           seq = emit_insn (gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx,
7273                                        ptr));
7274         }
7275       else
7276         {
7277           seq = emit_insn (gen_adddi3 (stack_pointer_rtx, ptr,
7278                                        GEN_INT (-leftover)));
7279         }
7280
7281       /* This alternative is special, because the DWARF code cannot
7282          possibly intuit through the loop above.  So we invent this
7283          note it looks at instead.  */
7284       RTX_FRAME_RELATED_P (seq) = 1;
7285       REG_NOTES (seq)
7286         = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7287                              gen_rtx_SET (VOIDmode, stack_pointer_rtx,
7288                                gen_rtx_PLUS (Pmode, stack_pointer_rtx,
7289                                              GEN_INT (TARGET_ABI_UNICOSMK
7290                                                       ? -frame_size + 64
7291                                                       : -frame_size))),
7292                              REG_NOTES (seq));
7293     }
7294
7295   if (!TARGET_ABI_UNICOSMK)
7296     {
7297       HOST_WIDE_INT sa_bias = 0;
7298
7299       /* Cope with very large offsets to the register save area.  */
7300       sa_reg = stack_pointer_rtx;
7301       if (reg_offset + sa_size > 0x8000)
7302         {
7303           int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7304           rtx sa_bias_rtx;
7305
7306           if (low + sa_size <= 0x8000)
7307             sa_bias = reg_offset - low, reg_offset = low;
7308           else 
7309             sa_bias = reg_offset, reg_offset = 0;
7310
7311           sa_reg = gen_rtx_REG (DImode, 24);
7312           sa_bias_rtx = GEN_INT (sa_bias);
7313
7314           if (add_operand (sa_bias_rtx, DImode))
7315             emit_insn (gen_adddi3 (sa_reg, stack_pointer_rtx, sa_bias_rtx));
7316           else
7317             {
7318               emit_move_insn (sa_reg, sa_bias_rtx);
7319               emit_insn (gen_adddi3 (sa_reg, stack_pointer_rtx, sa_reg));
7320             }
7321         }
7322     
7323       /* Save regs in stack order.  Beginning with VMS PV.  */
7324       if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7325         emit_frame_store (REG_PV, stack_pointer_rtx, 0, 0);
7326
7327       /* Save register RA next.  */
7328       if (imask & (1UL << REG_RA))
7329         {
7330           emit_frame_store (REG_RA, sa_reg, sa_bias, reg_offset);
7331           imask &= ~(1UL << REG_RA);
7332           reg_offset += 8;
7333         }
7334
7335       /* Now save any other registers required to be saved.  */
7336       for (i = 0; i < 31; i++)
7337         if (imask & (1UL << i))
7338           {
7339             emit_frame_store (i, sa_reg, sa_bias, reg_offset);
7340             reg_offset += 8;
7341           }
7342
7343       for (i = 0; i < 31; i++)
7344         if (fmask & (1UL << i))
7345           {
7346             emit_frame_store (i+32, sa_reg, sa_bias, reg_offset);
7347             reg_offset += 8;
7348           }
7349     }
7350   else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7351     {
7352       /* The standard frame on the T3E includes space for saving registers.
7353          We just have to use it. We don't have to save the return address and
7354          the old frame pointer here - they are saved in the DSIB.  */
7355
7356       reg_offset = -56;
7357       for (i = 9; i < 15; i++)
7358         if (imask & (1UL << i))
7359           {
7360             emit_frame_store (i, hard_frame_pointer_rtx, 0, reg_offset);
7361             reg_offset -= 8;
7362           }
7363       for (i = 2; i < 10; i++)
7364         if (fmask & (1UL << i))
7365           {
7366             emit_frame_store (i+32, hard_frame_pointer_rtx, 0, reg_offset);
7367             reg_offset -= 8;
7368           }
7369     }
7370
7371   if (TARGET_ABI_OPEN_VMS)
7372     {
7373       if (alpha_procedure_type == PT_REGISTER)
7374         /* Register frame procedures save the fp.
7375            ?? Ought to have a dwarf2 save for this.  */
7376         emit_move_insn (gen_rtx_REG (DImode, vms_save_fp_regno),
7377                         hard_frame_pointer_rtx);
7378
7379       if (alpha_procedure_type != PT_NULL && vms_base_regno != REG_PV)
7380         emit_insn (gen_force_movdi (gen_rtx_REG (DImode, vms_base_regno),
7381                                     gen_rtx_REG (DImode, REG_PV)));
7382
7383       if (alpha_procedure_type != PT_NULL
7384           && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7385         FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7386
7387       /* If we have to allocate space for outgoing args, do it now.  */
7388       if (current_function_outgoing_args_size != 0)
7389         {
7390           rtx seq
7391             = emit_move_insn (stack_pointer_rtx, 
7392                               plus_constant
7393                               (hard_frame_pointer_rtx,
7394                                - (ALPHA_ROUND
7395                                   (current_function_outgoing_args_size))));
7396           
7397           /* Only set FRAME_RELATED_P on the stack adjustment we just emitted
7398              if ! frame_pointer_needed. Setting the bit will change the CFA
7399              computation rule to use sp again, which would be wrong if we had
7400              frame_pointer_needed, as this means sp might move unpredictably
7401              later on.
7402
7403              Also, note that
7404                frame_pointer_needed
7405                => vms_unwind_regno == HARD_FRAME_POINTER_REGNUM
7406              and
7407                current_function_outgoing_args_size != 0
7408                => alpha_procedure_type != PT_NULL,
7409
7410              so when we are not setting the bit here, we are guaranteed to
7411              have emitted an FRP frame pointer update just before.  */
7412           RTX_FRAME_RELATED_P (seq) = ! frame_pointer_needed;
7413         }
7414     }
7415   else if (!TARGET_ABI_UNICOSMK)
7416     {
7417       /* If we need a frame pointer, set it from the stack pointer.  */
7418       if (frame_pointer_needed)
7419         {
7420           if (TARGET_CAN_FAULT_IN_PROLOGUE)
7421             FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7422           else
7423             /* This must always be the last instruction in the
7424                prologue, thus we emit a special move + clobber.  */
7425               FRP (emit_insn (gen_init_fp (hard_frame_pointer_rtx,
7426                                            stack_pointer_rtx, sa_reg)));
7427         }
7428     }
7429
7430   /* The ABIs for VMS and OSF/1 say that while we can schedule insns into
7431      the prologue, for exception handling reasons, we cannot do this for
7432      any insn that might fault.  We could prevent this for mems with a
7433      (clobber:BLK (scratch)), but this doesn't work for fp insns.  So we
7434      have to prevent all such scheduling with a blockage.
7435
7436      Linux, on the other hand, never bothered to implement OSF/1's 
7437      exception handling, and so doesn't care about such things.  Anyone
7438      planning to use dwarf2 frame-unwind info can also omit the blockage.  */
7439
7440   if (! TARGET_CAN_FAULT_IN_PROLOGUE)
7441     emit_insn (gen_blockage ());
7442 }
7443
7444 /* Output the textual info surrounding the prologue.  */
7445
7446 void
7447 alpha_start_function (FILE *file, const char *fnname,
7448                       tree decl ATTRIBUTE_UNUSED)
7449 {
7450   unsigned long imask = 0;
7451   unsigned long fmask = 0;
7452   /* Stack space needed for pushing registers clobbered by us.  */
7453   HOST_WIDE_INT sa_size;
7454   /* Complete stack size needed.  */
7455   unsigned HOST_WIDE_INT frame_size;
7456   /* Offset from base reg to register save area.  */
7457   HOST_WIDE_INT reg_offset;
7458   char *entry_label = (char *) alloca (strlen (fnname) + 6);
7459   int i;
7460
7461   /* Don't emit an extern directive for functions defined in the same file.  */
7462   if (TARGET_ABI_UNICOSMK)
7463     {
7464       tree name_tree;
7465       name_tree = get_identifier (fnname);
7466       TREE_ASM_WRITTEN (name_tree) = 1;
7467     }
7468
7469   alpha_fnname = fnname;
7470   sa_size = alpha_sa_size ();
7471
7472   frame_size = get_frame_size ();
7473   if (TARGET_ABI_OPEN_VMS)
7474     frame_size = ALPHA_ROUND (sa_size 
7475                               + (alpha_procedure_type == PT_STACK ? 8 : 0)
7476                               + frame_size
7477                               + current_function_pretend_args_size);
7478   else if (TARGET_ABI_UNICOSMK)
7479     frame_size = ALPHA_ROUND (sa_size
7480                               + (alpha_procedure_type == PT_STACK ? 48 : 0))
7481                  + ALPHA_ROUND (frame_size
7482                               + current_function_outgoing_args_size);
7483   else
7484     frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7485                   + sa_size
7486                   + ALPHA_ROUND (frame_size
7487                                  + current_function_pretend_args_size));
7488
7489   if (TARGET_ABI_OPEN_VMS)
7490     reg_offset = 8;
7491   else
7492     reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7493
7494   alpha_sa_mask (&imask, &fmask);
7495
7496   /* Ecoff can handle multiple .file directives, so put out file and lineno.
7497      We have to do that before the .ent directive as we cannot switch
7498      files within procedures with native ecoff because line numbers are
7499      linked to procedure descriptors.
7500      Outputting the lineno helps debugging of one line functions as they
7501      would otherwise get no line number at all. Please note that we would
7502      like to put out last_linenum from final.c, but it is not accessible.  */
7503
7504   if (write_symbols == SDB_DEBUG)
7505     {
7506 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7507       ASM_OUTPUT_SOURCE_FILENAME (file,
7508                                   DECL_SOURCE_FILE (current_function_decl));
7509 #endif
7510 #ifdef ASM_OUTPUT_SOURCE_LINE
7511       if (debug_info_level != DINFO_LEVEL_TERSE)
7512         ASM_OUTPUT_SOURCE_LINE (file,
7513                                 DECL_SOURCE_LINE (current_function_decl), 0);
7514 #endif
7515     }
7516
7517   /* Issue function start and label.  */
7518   if (TARGET_ABI_OPEN_VMS
7519       || (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive))
7520     {
7521       fputs ("\t.ent ", file);
7522       assemble_name (file, fnname);
7523       putc ('\n', file);
7524
7525       /* If the function needs GP, we'll write the "..ng" label there.
7526          Otherwise, do it here.  */
7527       if (TARGET_ABI_OSF
7528           && ! alpha_function_needs_gp
7529           && ! current_function_is_thunk)
7530         {
7531           putc ('$', file);
7532           assemble_name (file, fnname);
7533           fputs ("..ng:\n", file);
7534         }
7535     }
7536
7537   strcpy (entry_label, fnname);
7538   if (TARGET_ABI_OPEN_VMS)
7539     strcat (entry_label, "..en");
7540
7541   /* For public functions, the label must be globalized by appending an
7542      additional colon.  */
7543   if (TARGET_ABI_UNICOSMK && TREE_PUBLIC (decl))
7544     strcat (entry_label, ":");
7545
7546   ASM_OUTPUT_LABEL (file, entry_label);
7547   inside_function = TRUE;
7548
7549   if (TARGET_ABI_OPEN_VMS)
7550     fprintf (file, "\t.base $%d\n", vms_base_regno);
7551
7552   if (!TARGET_ABI_OPEN_VMS && !TARGET_ABI_UNICOSMK && TARGET_IEEE_CONFORMANT
7553       && !flag_inhibit_size_directive)
7554     {
7555       /* Set flags in procedure descriptor to request IEEE-conformant
7556          math-library routines.  The value we set it to is PDSC_EXC_IEEE
7557          (/usr/include/pdsc.h).  */
7558       fputs ("\t.eflag 48\n", file);
7559     }
7560
7561   /* Set up offsets to alpha virtual arg/local debugging pointer.  */
7562   alpha_auto_offset = -frame_size + current_function_pretend_args_size;
7563   alpha_arg_offset = -frame_size + 48;
7564
7565   /* Describe our frame.  If the frame size is larger than an integer,
7566      print it as zero to avoid an assembler error.  We won't be
7567      properly describing such a frame, but that's the best we can do.  */
7568   if (TARGET_ABI_UNICOSMK)
7569     ;
7570   else if (TARGET_ABI_OPEN_VMS)
7571     fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,"
7572              HOST_WIDE_INT_PRINT_DEC "\n",
7573              vms_unwind_regno,
7574              frame_size >= (1UL << 31) ? 0 : frame_size,
7575              reg_offset);
7576   else if (!flag_inhibit_size_directive)
7577     fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,%d\n",
7578              (frame_pointer_needed
7579               ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
7580              frame_size >= (1UL << 31) ? 0 : frame_size,
7581              current_function_pretend_args_size);
7582
7583   /* Describe which registers were spilled.  */
7584   if (TARGET_ABI_UNICOSMK)
7585     ;
7586   else if (TARGET_ABI_OPEN_VMS)
7587     {
7588       if (imask)
7589         /* ??? Does VMS care if mask contains ra?  The old code didn't
7590            set it, so I don't here.  */
7591         fprintf (file, "\t.mask 0x%lx,0\n", imask & ~(1UL << REG_RA));
7592       if (fmask)
7593         fprintf (file, "\t.fmask 0x%lx,0\n", fmask);
7594       if (alpha_procedure_type == PT_REGISTER)
7595         fprintf (file, "\t.fp_save $%d\n", vms_save_fp_regno);
7596     }
7597   else if (!flag_inhibit_size_directive)
7598     {
7599       if (imask)
7600         {
7601           fprintf (file, "\t.mask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", imask,
7602                    frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7603
7604           for (i = 0; i < 32; ++i)
7605             if (imask & (1UL << i))
7606               reg_offset += 8;
7607         }
7608
7609       if (fmask)
7610         fprintf (file, "\t.fmask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", fmask,
7611                  frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7612     }
7613
7614 #if TARGET_ABI_OPEN_VMS
7615   /* Ifdef'ed cause link_section are only available then.  */
7616   readonly_data_section ();
7617   fprintf (file, "\t.align 3\n");
7618   assemble_name (file, fnname); fputs ("..na:\n", file);
7619   fputs ("\t.ascii \"", file);
7620   assemble_name (file, fnname);
7621   fputs ("\\0\"\n", file);
7622   alpha_need_linkage (fnname, 1);
7623   text_section ();
7624 #endif
7625 }
7626
7627 /* Emit the .prologue note at the scheduled end of the prologue.  */
7628
7629 static void
7630 alpha_output_function_end_prologue (FILE *file)
7631 {
7632   if (TARGET_ABI_UNICOSMK)
7633     ;
7634   else if (TARGET_ABI_OPEN_VMS)
7635     fputs ("\t.prologue\n", file);
7636   else if (TARGET_ABI_WINDOWS_NT)
7637     fputs ("\t.prologue 0\n", file);
7638   else if (!flag_inhibit_size_directive)
7639     fprintf (file, "\t.prologue %d\n",
7640              alpha_function_needs_gp || current_function_is_thunk);
7641 }
7642
7643 /* Write function epilogue.  */
7644
7645 /* ??? At some point we will want to support full unwind, and so will 
7646    need to mark the epilogue as well.  At the moment, we just confuse
7647    dwarf2out.  */
7648 #undef FRP
7649 #define FRP(exp) exp
7650
7651 void
7652 alpha_expand_epilogue (void)
7653 {
7654   /* Registers to save.  */
7655   unsigned long imask = 0;
7656   unsigned long fmask = 0;
7657   /* Stack space needed for pushing registers clobbered by us.  */
7658   HOST_WIDE_INT sa_size;
7659   /* Complete stack size needed.  */
7660   HOST_WIDE_INT frame_size;
7661   /* Offset from base reg to register save area.  */
7662   HOST_WIDE_INT reg_offset;
7663   int fp_is_frame_pointer, fp_offset;
7664   rtx sa_reg, sa_reg_exp = NULL;
7665   rtx sp_adj1, sp_adj2, mem;
7666   rtx eh_ofs;
7667   int i;
7668
7669   sa_size = alpha_sa_size ();
7670
7671   frame_size = get_frame_size ();
7672   if (TARGET_ABI_OPEN_VMS)
7673     frame_size = ALPHA_ROUND (sa_size 
7674                               + (alpha_procedure_type == PT_STACK ? 8 : 0)
7675                               + frame_size
7676                               + current_function_pretend_args_size);
7677   else if (TARGET_ABI_UNICOSMK)
7678     frame_size = ALPHA_ROUND (sa_size
7679                               + (alpha_procedure_type == PT_STACK ? 48 : 0))
7680                  + ALPHA_ROUND (frame_size
7681                               + current_function_outgoing_args_size);
7682   else
7683     frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7684                   + sa_size
7685                   + ALPHA_ROUND (frame_size
7686                                  + current_function_pretend_args_size));
7687
7688   if (TARGET_ABI_OPEN_VMS)
7689     {
7690        if (alpha_procedure_type == PT_STACK)
7691           reg_offset = 8;
7692        else
7693           reg_offset = 0;
7694     }
7695   else
7696     reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7697
7698   alpha_sa_mask (&imask, &fmask);
7699
7700   fp_is_frame_pointer
7701     = ((TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7702        || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed));
7703   fp_offset = 0;
7704   sa_reg = stack_pointer_rtx;
7705
7706   if (current_function_calls_eh_return)
7707     eh_ofs = EH_RETURN_STACKADJ_RTX;
7708   else
7709     eh_ofs = NULL_RTX;
7710
7711   if (!TARGET_ABI_UNICOSMK && sa_size)
7712     {
7713       /* If we have a frame pointer, restore SP from it.  */
7714       if ((TARGET_ABI_OPEN_VMS
7715            && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7716           || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed))
7717         FRP (emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx));
7718
7719       /* Cope with very large offsets to the register save area.  */
7720       if (reg_offset + sa_size > 0x8000)
7721         {
7722           int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7723           HOST_WIDE_INT bias;
7724
7725           if (low + sa_size <= 0x8000)
7726             bias = reg_offset - low, reg_offset = low;
7727           else 
7728             bias = reg_offset, reg_offset = 0;
7729
7730           sa_reg = gen_rtx_REG (DImode, 22);
7731           sa_reg_exp = plus_constant (stack_pointer_rtx, bias);
7732
7733           FRP (emit_move_insn (sa_reg, sa_reg_exp));
7734         }
7735           
7736       /* Restore registers in order, excepting a true frame pointer.  */
7737
7738       mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7739       if (! eh_ofs)
7740         set_mem_alias_set (mem, alpha_sr_alias_set);
7741       FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7742
7743       reg_offset += 8;
7744       imask &= ~(1UL << REG_RA);
7745
7746       for (i = 0; i < 31; ++i)
7747         if (imask & (1UL << i))
7748           {
7749             if (i == HARD_FRAME_POINTER_REGNUM && fp_is_frame_pointer)
7750               fp_offset = reg_offset;
7751             else
7752               {
7753                 mem = gen_rtx_MEM (DImode, plus_constant(sa_reg, reg_offset));
7754                 set_mem_alias_set (mem, alpha_sr_alias_set);
7755                 FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7756               }
7757             reg_offset += 8;
7758           }
7759
7760       for (i = 0; i < 31; ++i)
7761         if (fmask & (1UL << i))
7762           {
7763             mem = gen_rtx_MEM (DFmode, plus_constant(sa_reg, reg_offset));
7764             set_mem_alias_set (mem, alpha_sr_alias_set);
7765             FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7766             reg_offset += 8;
7767           }
7768     }
7769   else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7770     {
7771       /* Restore callee-saved general-purpose registers.  */
7772
7773       reg_offset = -56;
7774
7775       for (i = 9; i < 15; i++)
7776         if (imask & (1UL << i))
7777           {
7778             mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx,
7779                                                      reg_offset));
7780             set_mem_alias_set (mem, alpha_sr_alias_set);
7781             FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7782             reg_offset -= 8;
7783           }
7784
7785       for (i = 2; i < 10; i++)
7786         if (fmask & (1UL << i))
7787           {
7788             mem = gen_rtx_MEM (DFmode, plus_constant(hard_frame_pointer_rtx,
7789                                                      reg_offset));
7790             set_mem_alias_set (mem, alpha_sr_alias_set);
7791             FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7792             reg_offset -= 8;
7793           }
7794
7795       /* Restore the return address from the DSIB.  */
7796
7797       mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx, -8));
7798       set_mem_alias_set (mem, alpha_sr_alias_set);
7799       FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7800     }
7801
7802   if (frame_size || eh_ofs)
7803     {
7804       sp_adj1 = stack_pointer_rtx;
7805
7806       if (eh_ofs)
7807         {
7808           sp_adj1 = gen_rtx_REG (DImode, 23);
7809           emit_move_insn (sp_adj1,
7810                           gen_rtx_PLUS (Pmode, stack_pointer_rtx, eh_ofs));
7811         }
7812
7813       /* If the stack size is large, begin computation into a temporary
7814          register so as not to interfere with a potential fp restore,
7815          which must be consecutive with an SP restore.  */
7816       if (frame_size < 32768
7817           && ! (TARGET_ABI_UNICOSMK && current_function_calls_alloca))
7818         sp_adj2 = GEN_INT (frame_size);
7819       else if (TARGET_ABI_UNICOSMK)
7820         {
7821           sp_adj1 = gen_rtx_REG (DImode, 23);
7822           FRP (emit_move_insn (sp_adj1, hard_frame_pointer_rtx));
7823           sp_adj2 = const0_rtx;
7824         }
7825       else if (frame_size < 0x40007fffL)
7826         {
7827           int low = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
7828
7829           sp_adj2 = plus_constant (sp_adj1, frame_size - low);
7830           if (sa_reg_exp && rtx_equal_p (sa_reg_exp, sp_adj2))
7831             sp_adj1 = sa_reg;
7832           else
7833             {
7834               sp_adj1 = gen_rtx_REG (DImode, 23);
7835               FRP (emit_move_insn (sp_adj1, sp_adj2));
7836             }
7837           sp_adj2 = GEN_INT (low);
7838         }
7839       else
7840         {
7841           rtx tmp = gen_rtx_REG (DImode, 23);
7842           FRP (sp_adj2 = alpha_emit_set_const (tmp, DImode, frame_size, 3));
7843           if (!sp_adj2)
7844             {
7845               /* We can't drop new things to memory this late, afaik,
7846                  so build it up by pieces.  */
7847               FRP (sp_adj2 = alpha_emit_set_long_const (tmp, frame_size,
7848                                                         -(frame_size < 0)));
7849               if (!sp_adj2)
7850                 abort ();
7851             }
7852         }
7853
7854       /* From now on, things must be in order.  So emit blockages.  */
7855
7856       /* Restore the frame pointer.  */
7857       if (TARGET_ABI_UNICOSMK)
7858         {
7859           emit_insn (gen_blockage ());
7860           mem = gen_rtx_MEM (DImode,
7861                              plus_constant (hard_frame_pointer_rtx, -16));
7862           set_mem_alias_set (mem, alpha_sr_alias_set);
7863           FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7864         }
7865       else if (fp_is_frame_pointer)
7866         {
7867           emit_insn (gen_blockage ());
7868           mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, fp_offset));
7869           set_mem_alias_set (mem, alpha_sr_alias_set);
7870           FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7871         }
7872       else if (TARGET_ABI_OPEN_VMS)
7873         {
7874           emit_insn (gen_blockage ());
7875           FRP (emit_move_insn (hard_frame_pointer_rtx,
7876                                gen_rtx_REG (DImode, vms_save_fp_regno)));
7877         }
7878
7879       /* Restore the stack pointer.  */
7880       emit_insn (gen_blockage ());
7881       if (sp_adj2 == const0_rtx)
7882         FRP (emit_move_insn (stack_pointer_rtx, sp_adj1));
7883       else
7884         FRP (emit_move_insn (stack_pointer_rtx,
7885                              gen_rtx_PLUS (DImode, sp_adj1, sp_adj2)));
7886     }
7887   else 
7888     {
7889       if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_REGISTER)
7890         {
7891           emit_insn (gen_blockage ());
7892           FRP (emit_move_insn (hard_frame_pointer_rtx,
7893                                gen_rtx_REG (DImode, vms_save_fp_regno)));
7894         }
7895       else if (TARGET_ABI_UNICOSMK && alpha_procedure_type != PT_STACK)
7896         {
7897           /* Decrement the frame pointer if the function does not have a
7898              frame.  */
7899
7900           emit_insn (gen_blockage ());
7901           FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
7902                                       hard_frame_pointer_rtx, GEN_INT (-1))));
7903         }
7904     }
7905 }
7906 \f
7907 /* Output the rest of the textual info surrounding the epilogue.  */
7908
7909 void
7910 alpha_end_function (FILE *file, const char *fnname, tree decl ATTRIBUTE_UNUSED)
7911 {
7912   /* End the function.  */
7913   if (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive)
7914     {
7915       fputs ("\t.end ", file);
7916       assemble_name (file, fnname);
7917       putc ('\n', file);
7918     }
7919   inside_function = FALSE;
7920
7921 #if TARGET_ABI_OPEN_VMS
7922   alpha_write_linkage (file, fnname, decl);
7923 #endif
7924
7925   /* Output jump tables and the static subroutine information block.  */
7926   if (TARGET_ABI_UNICOSMK)
7927     {
7928       unicosmk_output_ssib (file, fnname);
7929       unicosmk_output_deferred_case_vectors (file);
7930     }
7931 }
7932
7933 #if TARGET_ABI_OSF
7934 /* Emit a tail call to FUNCTION after adjusting THIS by DELTA.
7935
7936    In order to avoid the hordes of differences between generated code
7937    with and without TARGET_EXPLICIT_RELOCS, and to avoid duplicating
7938    lots of code loading up large constants, generate rtl and emit it
7939    instead of going straight to text.
7940
7941    Not sure why this idea hasn't been explored before...  */
7942
7943 static void
7944 alpha_output_mi_thunk_osf (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
7945                            HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
7946                            tree function)
7947 {
7948   HOST_WIDE_INT hi, lo;
7949   rtx this, insn, funexp;
7950
7951   /* We always require a valid GP.  */
7952   emit_insn (gen_prologue_ldgp ());
7953   emit_note (NOTE_INSN_PROLOGUE_END);
7954
7955   /* Find the "this" pointer.  If the function returns a structure,
7956      the structure return pointer is in $16.  */
7957   if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
7958     this = gen_rtx_REG (Pmode, 17);
7959   else
7960     this = gen_rtx_REG (Pmode, 16);
7961
7962   /* Add DELTA.  When possible we use ldah+lda.  Otherwise load the
7963      entire constant for the add.  */
7964   lo = ((delta & 0xffff) ^ 0x8000) - 0x8000;
7965   hi = (((delta - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7966   if (hi + lo == delta)
7967     {
7968       if (hi)
7969         emit_insn (gen_adddi3 (this, this, GEN_INT (hi)));
7970       if (lo)
7971         emit_insn (gen_adddi3 (this, this, GEN_INT (lo)));
7972     }
7973   else
7974     {
7975       rtx tmp = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 0),
7976                                            delta, -(delta < 0));
7977       emit_insn (gen_adddi3 (this, this, tmp));
7978     }
7979
7980   /* Add a delta stored in the vtable at VCALL_OFFSET.  */
7981   if (vcall_offset)
7982     {
7983       rtx tmp, tmp2;
7984
7985       tmp = gen_rtx_REG (Pmode, 0);
7986       emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
7987
7988       lo = ((vcall_offset & 0xffff) ^ 0x8000) - 0x8000;
7989       hi = (((vcall_offset - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7990       if (hi + lo == vcall_offset)
7991         {
7992           if (hi)
7993             emit_insn (gen_adddi3 (tmp, tmp, GEN_INT (hi)));
7994         }
7995       else
7996         {
7997           tmp2 = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 1),
7998                                             vcall_offset, -(vcall_offset < 0));
7999           emit_insn (gen_adddi3 (tmp, tmp, tmp2));
8000           lo = 0;
8001         }
8002       if (lo)
8003         tmp2 = gen_rtx_PLUS (Pmode, tmp, GEN_INT (lo));
8004       else
8005         tmp2 = tmp;
8006       emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp2));
8007
8008       emit_insn (gen_adddi3 (this, this, tmp));
8009     }
8010
8011   /* Generate a tail call to the target function.  */
8012   if (! TREE_USED (function))
8013     {
8014       assemble_external (function);
8015       TREE_USED (function) = 1;
8016     }
8017   funexp = XEXP (DECL_RTL (function), 0);
8018   funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
8019   insn = emit_call_insn (gen_sibcall (funexp, const0_rtx));
8020   SIBLING_CALL_P (insn) = 1;
8021
8022   /* Run just enough of rest_of_compilation to get the insns emitted.
8023      There's not really enough bulk here to make other passes such as
8024      instruction scheduling worth while.  Note that use_thunk calls
8025      assemble_start_function and assemble_end_function.  */
8026   insn = get_insns ();
8027   insn_locators_initialize ();
8028   shorten_branches (insn);
8029   final_start_function (insn, file, 1);
8030   final (insn, file, 1, 0);
8031   final_end_function ();
8032 }
8033 #endif /* TARGET_ABI_OSF */
8034 \f
8035 /* Debugging support.  */
8036
8037 #include "gstab.h"
8038
8039 /* Count the number of sdb related labels are generated (to find block
8040    start and end boundaries).  */
8041
8042 int sdb_label_count = 0;
8043
8044 /* Next label # for each statement.  */
8045
8046 static int sym_lineno = 0;
8047
8048 /* Count the number of .file directives, so that .loc is up to date.  */
8049
8050 static int num_source_filenames = 0;
8051
8052 /* Name of the file containing the current function.  */
8053
8054 static const char *current_function_file = "";
8055
8056 /* Offsets to alpha virtual arg/local debugging pointers.  */
8057
8058 long alpha_arg_offset;
8059 long alpha_auto_offset;
8060 \f
8061 /* Emit a new filename to a stream.  */
8062
8063 void
8064 alpha_output_filename (FILE *stream, const char *name)
8065 {
8066   static int first_time = TRUE;
8067   char ltext_label_name[100];
8068
8069   if (first_time)
8070     {
8071       first_time = FALSE;
8072       ++num_source_filenames;
8073       current_function_file = name;
8074       fprintf (stream, "\t.file\t%d ", num_source_filenames);
8075       output_quoted_string (stream, name);
8076       fprintf (stream, "\n");
8077       if (!TARGET_GAS && write_symbols == DBX_DEBUG)
8078         fprintf (stream, "\t#@stabs\n");
8079     }
8080
8081   else if (write_symbols == DBX_DEBUG)
8082     {
8083       ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
8084       fprintf (stream, "%s", ASM_STABS_OP);
8085       output_quoted_string (stream, name);
8086       fprintf (stream, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
8087     }
8088
8089   else if (name != current_function_file
8090            && strcmp (name, current_function_file) != 0)
8091     {
8092       if (inside_function && ! TARGET_GAS)
8093         fprintf (stream, "\t#.file\t%d ", num_source_filenames);
8094       else
8095         {
8096           ++num_source_filenames;
8097           current_function_file = name;
8098           fprintf (stream, "\t.file\t%d ", num_source_filenames);
8099         }
8100
8101       output_quoted_string (stream, name);
8102       fprintf (stream, "\n");
8103     }
8104 }
8105
8106 /* Emit a linenumber to a stream.  */
8107
8108 void
8109 alpha_output_lineno (FILE *stream, int line)
8110 {
8111   if (write_symbols == DBX_DEBUG)
8112     {
8113       /* mips-tfile doesn't understand .stabd directives.  */
8114       ++sym_lineno;
8115       fprintf (stream, "$LM%d:\n%s%d,0,%d,$LM%d\n",
8116                sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
8117     }
8118   else
8119     fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
8120 }
8121 \f
8122 /* Structure to show the current status of registers and memory.  */
8123
8124 struct shadow_summary
8125 {
8126   struct {
8127     unsigned int i     : 31;    /* Mask of int regs */
8128     unsigned int fp    : 31;    /* Mask of fp regs */
8129     unsigned int mem   :  1;    /* mem == imem | fpmem */
8130   } used, defd;
8131 };
8132
8133 /* Summary the effects of expression X on the machine.  Update SUM, a pointer
8134    to the summary structure.  SET is nonzero if the insn is setting the
8135    object, otherwise zero.  */
8136
8137 static void
8138 summarize_insn (rtx x, struct shadow_summary *sum, int set)
8139 {
8140   const char *format_ptr;
8141   int i, j;
8142
8143   if (x == 0)
8144     return;
8145
8146   switch (GET_CODE (x))
8147     {
8148       /* ??? Note that this case would be incorrect if the Alpha had a
8149          ZERO_EXTRACT in SET_DEST.  */
8150     case SET:
8151       summarize_insn (SET_SRC (x), sum, 0);
8152       summarize_insn (SET_DEST (x), sum, 1);
8153       break;
8154
8155     case CLOBBER:
8156       summarize_insn (XEXP (x, 0), sum, 1);
8157       break;
8158
8159     case USE:
8160       summarize_insn (XEXP (x, 0), sum, 0);
8161       break;
8162
8163     case ASM_OPERANDS:
8164       for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
8165         summarize_insn (ASM_OPERANDS_INPUT (x, i), sum, 0);
8166       break;
8167
8168     case PARALLEL:
8169       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
8170         summarize_insn (XVECEXP (x, 0, i), sum, 0);
8171       break;
8172
8173     case SUBREG:
8174       summarize_insn (SUBREG_REG (x), sum, 0);
8175       break;
8176
8177     case REG:
8178       {
8179         int regno = REGNO (x);
8180         unsigned long mask = ((unsigned long) 1) << (regno % 32);
8181
8182         if (regno == 31 || regno == 63)
8183           break;
8184
8185         if (set)
8186           {
8187             if (regno < 32)
8188               sum->defd.i |= mask;
8189             else
8190               sum->defd.fp |= mask;
8191           }
8192         else
8193           {
8194             if (regno < 32)
8195               sum->used.i  |= mask;
8196             else
8197               sum->used.fp |= mask;
8198           }
8199         }
8200       break;
8201
8202     case MEM:
8203       if (set)
8204         sum->defd.mem = 1;
8205       else
8206         sum->used.mem = 1;
8207
8208       /* Find the regs used in memory address computation: */
8209       summarize_insn (XEXP (x, 0), sum, 0);
8210       break;
8211
8212     case CONST_INT:   case CONST_DOUBLE:
8213     case SYMBOL_REF:  case LABEL_REF:     case CONST:
8214     case SCRATCH:     case ASM_INPUT:
8215       break;
8216
8217       /* Handle common unary and binary ops for efficiency.  */
8218     case COMPARE:  case PLUS:    case MINUS:   case MULT:      case DIV:
8219     case MOD:      case UDIV:    case UMOD:    case AND:       case IOR:
8220     case XOR:      case ASHIFT:  case ROTATE:  case ASHIFTRT:  case LSHIFTRT:
8221     case ROTATERT: case SMIN:    case SMAX:    case UMIN:      case UMAX:
8222     case NE:       case EQ:      case GE:      case GT:        case LE:
8223     case LT:       case GEU:     case GTU:     case LEU:       case LTU:
8224       summarize_insn (XEXP (x, 0), sum, 0);
8225       summarize_insn (XEXP (x, 1), sum, 0);
8226       break;
8227
8228     case NEG:  case NOT:  case SIGN_EXTEND:  case ZERO_EXTEND:
8229     case TRUNCATE:  case FLOAT_EXTEND:  case FLOAT_TRUNCATE:  case FLOAT:
8230     case FIX:  case UNSIGNED_FLOAT:  case UNSIGNED_FIX:  case ABS:
8231     case SQRT:  case FFS: 
8232       summarize_insn (XEXP (x, 0), sum, 0);
8233       break;
8234
8235     default:
8236       format_ptr = GET_RTX_FORMAT (GET_CODE (x));
8237       for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
8238         switch (format_ptr[i])
8239           {
8240           case 'e':
8241             summarize_insn (XEXP (x, i), sum, 0);
8242             break;
8243
8244           case 'E':
8245             for (j = XVECLEN (x, i) - 1; j >= 0; j--)
8246               summarize_insn (XVECEXP (x, i, j), sum, 0);
8247             break;
8248
8249           case 'i':
8250             break;
8251
8252           default:
8253             abort ();
8254           }
8255     }
8256 }
8257
8258 /* Ensure a sufficient number of `trapb' insns are in the code when
8259    the user requests code with a trap precision of functions or
8260    instructions.
8261
8262    In naive mode, when the user requests a trap-precision of
8263    "instruction", a trapb is needed after every instruction that may
8264    generate a trap.  This ensures that the code is resumption safe but
8265    it is also slow.
8266
8267    When optimizations are turned on, we delay issuing a trapb as long
8268    as possible.  In this context, a trap shadow is the sequence of
8269    instructions that starts with a (potentially) trap generating
8270    instruction and extends to the next trapb or call_pal instruction
8271    (but GCC never generates call_pal by itself).  We can delay (and
8272    therefore sometimes omit) a trapb subject to the following
8273    conditions:
8274
8275    (a) On entry to the trap shadow, if any Alpha register or memory
8276    location contains a value that is used as an operand value by some
8277    instruction in the trap shadow (live on entry), then no instruction
8278    in the trap shadow may modify the register or memory location.
8279
8280    (b) Within the trap shadow, the computation of the base register
8281    for a memory load or store instruction may not involve using the
8282    result of an instruction that might generate an UNPREDICTABLE
8283    result.
8284
8285    (c) Within the trap shadow, no register may be used more than once
8286    as a destination register.  (This is to make life easier for the
8287    trap-handler.)
8288
8289    (d) The trap shadow may not include any branch instructions.  */
8290
8291 static void
8292 alpha_handle_trap_shadows (void)
8293 {
8294   struct shadow_summary shadow;
8295   int trap_pending, exception_nesting;
8296   rtx i, n;
8297
8298   trap_pending = 0;
8299   exception_nesting = 0;
8300   shadow.used.i = 0;
8301   shadow.used.fp = 0;
8302   shadow.used.mem = 0;
8303   shadow.defd = shadow.used;
8304   
8305   for (i = get_insns (); i ; i = NEXT_INSN (i))
8306     {
8307       if (GET_CODE (i) == NOTE)
8308         {
8309           switch (NOTE_LINE_NUMBER (i))
8310             {
8311             case NOTE_INSN_EH_REGION_BEG:
8312               exception_nesting++;
8313               if (trap_pending)
8314                 goto close_shadow;
8315               break;
8316
8317             case NOTE_INSN_EH_REGION_END:
8318               exception_nesting--;
8319               if (trap_pending)
8320                 goto close_shadow;
8321               break;
8322
8323             case NOTE_INSN_EPILOGUE_BEG:
8324               if (trap_pending && alpha_tp >= ALPHA_TP_FUNC)
8325                 goto close_shadow;
8326               break;
8327             }
8328         }
8329       else if (trap_pending)
8330         {
8331           if (alpha_tp == ALPHA_TP_FUNC)
8332             {
8333               if (GET_CODE (i) == JUMP_INSN
8334                   && GET_CODE (PATTERN (i)) == RETURN)
8335                 goto close_shadow;
8336             }
8337           else if (alpha_tp == ALPHA_TP_INSN)
8338             {
8339               if (optimize > 0)
8340                 {
8341                   struct shadow_summary sum;
8342
8343                   sum.used.i = 0;
8344                   sum.used.fp = 0;
8345                   sum.used.mem = 0;
8346                   sum.defd = sum.used;
8347
8348                   switch (GET_CODE (i))
8349                     {
8350                     case INSN:
8351                       /* Annoyingly, get_attr_trap will abort on these.  */
8352                       if (GET_CODE (PATTERN (i)) == USE
8353                           || GET_CODE (PATTERN (i)) == CLOBBER)
8354                         break;
8355
8356                       summarize_insn (PATTERN (i), &sum, 0);
8357
8358                       if ((sum.defd.i & shadow.defd.i)
8359                           || (sum.defd.fp & shadow.defd.fp))
8360                         {
8361                           /* (c) would be violated */
8362                           goto close_shadow;
8363                         }
8364
8365                       /* Combine shadow with summary of current insn: */
8366                       shadow.used.i   |= sum.used.i;
8367                       shadow.used.fp  |= sum.used.fp;
8368                       shadow.used.mem |= sum.used.mem;
8369                       shadow.defd.i   |= sum.defd.i;
8370                       shadow.defd.fp  |= sum.defd.fp;
8371                       shadow.defd.mem |= sum.defd.mem;
8372
8373                       if ((sum.defd.i & shadow.used.i)
8374                           || (sum.defd.fp & shadow.used.fp)
8375                           || (sum.defd.mem & shadow.used.mem))
8376                         {
8377                           /* (a) would be violated (also takes care of (b))  */
8378                           if (get_attr_trap (i) == TRAP_YES
8379                               && ((sum.defd.i & sum.used.i)
8380                                   || (sum.defd.fp & sum.used.fp)))
8381                             abort ();
8382
8383                           goto close_shadow;
8384                         }
8385                       break;
8386
8387                     case JUMP_INSN:
8388                     case CALL_INSN:
8389                     case CODE_LABEL:
8390                       goto close_shadow;
8391
8392                     default:
8393                       abort ();
8394                     }
8395                 }
8396               else
8397                 {
8398                 close_shadow:
8399                   n = emit_insn_before (gen_trapb (), i);
8400                   PUT_MODE (n, TImode);
8401                   PUT_MODE (i, TImode);
8402                   trap_pending = 0;
8403                   shadow.used.i = 0;
8404                   shadow.used.fp = 0;
8405                   shadow.used.mem = 0;
8406                   shadow.defd = shadow.used;
8407                 }
8408             }
8409         }
8410
8411       if ((exception_nesting > 0 || alpha_tp >= ALPHA_TP_FUNC)
8412           && GET_CODE (i) == INSN
8413           && GET_CODE (PATTERN (i)) != USE
8414           && GET_CODE (PATTERN (i)) != CLOBBER
8415           && get_attr_trap (i) == TRAP_YES)
8416         {
8417           if (optimize && !trap_pending)
8418             summarize_insn (PATTERN (i), &shadow, 0);
8419           trap_pending = 1;
8420         }
8421     }
8422 }
8423 \f
8424 /* Alpha can only issue instruction groups simultaneously if they are
8425    suitably aligned.  This is very processor-specific.  */
8426
8427 enum alphaev4_pipe {
8428   EV4_STOP = 0,
8429   EV4_IB0 = 1,
8430   EV4_IB1 = 2,
8431   EV4_IBX = 4
8432 };
8433
8434 enum alphaev5_pipe {
8435   EV5_STOP = 0,
8436   EV5_NONE = 1,
8437   EV5_E01 = 2,
8438   EV5_E0 = 4,
8439   EV5_E1 = 8,
8440   EV5_FAM = 16,
8441   EV5_FA = 32,
8442   EV5_FM = 64
8443 };
8444
8445 static enum alphaev4_pipe
8446 alphaev4_insn_pipe (rtx insn)
8447 {
8448   if (recog_memoized (insn) < 0)
8449     return EV4_STOP;
8450   if (get_attr_length (insn) != 4)
8451     return EV4_STOP;
8452
8453   switch (get_attr_type (insn))
8454     {
8455     case TYPE_ILD:
8456     case TYPE_FLD:
8457       return EV4_IBX;
8458
8459     case TYPE_LDSYM:
8460     case TYPE_IADD:
8461     case TYPE_ILOG:
8462     case TYPE_ICMOV:
8463     case TYPE_ICMP:
8464     case TYPE_IST:
8465     case TYPE_FST:
8466     case TYPE_SHIFT:
8467     case TYPE_IMUL:
8468     case TYPE_FBR:
8469       return EV4_IB0;
8470
8471     case TYPE_MISC:
8472     case TYPE_IBR:
8473     case TYPE_JSR:
8474     case TYPE_CALLPAL:
8475     case TYPE_FCPYS:
8476     case TYPE_FCMOV:
8477     case TYPE_FADD:
8478     case TYPE_FDIV:
8479     case TYPE_FMUL:
8480       return EV4_IB1;
8481
8482     default:
8483       abort ();
8484     }
8485 }
8486
8487 static enum alphaev5_pipe
8488 alphaev5_insn_pipe (rtx insn)
8489 {
8490   if (recog_memoized (insn) < 0)
8491     return EV5_STOP;
8492   if (get_attr_length (insn) != 4)
8493     return EV5_STOP;
8494
8495   switch (get_attr_type (insn))
8496     {
8497     case TYPE_ILD:
8498     case TYPE_FLD:
8499     case TYPE_LDSYM:
8500     case TYPE_IADD:
8501     case TYPE_ILOG:
8502     case TYPE_ICMOV:
8503     case TYPE_ICMP:
8504       return EV5_E01;
8505
8506     case TYPE_IST:
8507     case TYPE_FST:
8508     case TYPE_SHIFT:
8509     case TYPE_IMUL:
8510     case TYPE_MISC:
8511     case TYPE_MVI:
8512       return EV5_E0;
8513
8514     case TYPE_IBR:
8515     case TYPE_JSR:
8516     case TYPE_CALLPAL:
8517       return EV5_E1;
8518
8519     case TYPE_FCPYS:
8520       return EV5_FAM;
8521
8522     case TYPE_FBR:
8523     case TYPE_FCMOV:
8524     case TYPE_FADD:
8525     case TYPE_FDIV:
8526       return EV5_FA;
8527
8528     case TYPE_FMUL:
8529       return EV5_FM;
8530
8531     default:
8532       abort();
8533     }
8534 }
8535
8536 /* IN_USE is a mask of the slots currently filled within the insn group. 
8537    The mask bits come from alphaev4_pipe above.  If EV4_IBX is set, then
8538    the insn in EV4_IB0 can be swapped by the hardware into EV4_IB1. 
8539
8540    LEN is, of course, the length of the group in bytes.  */
8541
8542 static rtx
8543 alphaev4_next_group (rtx insn, int *pin_use, int *plen)
8544 {
8545   int len, in_use;
8546
8547   len = in_use = 0;
8548
8549   if (! INSN_P (insn)
8550       || GET_CODE (PATTERN (insn)) == CLOBBER
8551       || GET_CODE (PATTERN (insn)) == USE)
8552     goto next_and_done;
8553
8554   while (1)
8555     {
8556       enum alphaev4_pipe pipe;
8557
8558       pipe = alphaev4_insn_pipe (insn);
8559       switch (pipe)
8560         {
8561         case EV4_STOP:
8562           /* Force complex instructions to start new groups.  */
8563           if (in_use)
8564             goto done;
8565
8566           /* If this is a completely unrecognized insn, its an asm.
8567              We don't know how long it is, so record length as -1 to
8568              signal a needed realignment.  */
8569           if (recog_memoized (insn) < 0)
8570             len = -1;
8571           else
8572             len = get_attr_length (insn);
8573           goto next_and_done;
8574
8575         case EV4_IBX:
8576           if (in_use & EV4_IB0)
8577             {
8578               if (in_use & EV4_IB1)
8579                 goto done;
8580               in_use |= EV4_IB1;
8581             }
8582           else
8583             in_use |= EV4_IB0 | EV4_IBX;
8584           break;
8585
8586         case EV4_IB0:
8587           if (in_use & EV4_IB0)
8588             {
8589               if (!(in_use & EV4_IBX) || (in_use & EV4_IB1))
8590                 goto done;
8591               in_use |= EV4_IB1;
8592             }
8593           in_use |= EV4_IB0;
8594           break;
8595
8596         case EV4_IB1:
8597           if (in_use & EV4_IB1)
8598             goto done;
8599           in_use |= EV4_IB1;
8600           break;
8601
8602         default:
8603           abort();
8604         }
8605       len += 4;
8606       
8607       /* Haifa doesn't do well scheduling branches.  */
8608       if (GET_CODE (insn) == JUMP_INSN)
8609         goto next_and_done;
8610
8611     next:
8612       insn = next_nonnote_insn (insn);
8613
8614       if (!insn || ! INSN_P (insn))
8615         goto done;
8616
8617       /* Let Haifa tell us where it thinks insn group boundaries are.  */
8618       if (GET_MODE (insn) == TImode)
8619         goto done;
8620
8621       if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8622         goto next;
8623     }
8624
8625  next_and_done:
8626   insn = next_nonnote_insn (insn);
8627
8628  done:
8629   *plen = len;
8630   *pin_use = in_use;
8631   return insn;
8632 }
8633
8634 /* IN_USE is a mask of the slots currently filled within the insn group. 
8635    The mask bits come from alphaev5_pipe above.  If EV5_E01 is set, then
8636    the insn in EV5_E0 can be swapped by the hardware into EV5_E1. 
8637
8638    LEN is, of course, the length of the group in bytes.  */
8639
8640 static rtx
8641 alphaev5_next_group (rtx insn, int *pin_use, int *plen)
8642 {
8643   int len, in_use;
8644
8645   len = in_use = 0;
8646
8647   if (! INSN_P (insn)
8648       || GET_CODE (PATTERN (insn)) == CLOBBER
8649       || GET_CODE (PATTERN (insn)) == USE)
8650     goto next_and_done;
8651
8652   while (1)
8653     {
8654       enum alphaev5_pipe pipe;
8655
8656       pipe = alphaev5_insn_pipe (insn);
8657       switch (pipe)
8658         {
8659         case EV5_STOP:
8660           /* Force complex instructions to start new groups.  */
8661           if (in_use)
8662             goto done;
8663
8664           /* If this is a completely unrecognized insn, its an asm.
8665              We don't know how long it is, so record length as -1 to
8666              signal a needed realignment.  */
8667           if (recog_memoized (insn) < 0)
8668             len = -1;
8669           else
8670             len = get_attr_length (insn);
8671           goto next_and_done;
8672
8673         /* ??? Most of the places below, we would like to abort, as 
8674            it would indicate an error either in Haifa, or in the 
8675            scheduling description.  Unfortunately, Haifa never 
8676            schedules the last instruction of the BB, so we don't
8677            have an accurate TI bit to go off.  */
8678         case EV5_E01:
8679           if (in_use & EV5_E0)
8680             {
8681               if (in_use & EV5_E1)
8682                 goto done;
8683               in_use |= EV5_E1;
8684             }
8685           else
8686             in_use |= EV5_E0 | EV5_E01;
8687           break;
8688
8689         case EV5_E0:
8690           if (in_use & EV5_E0)
8691             {
8692               if (!(in_use & EV5_E01) || (in_use & EV5_E1))
8693                 goto done;
8694               in_use |= EV5_E1;
8695             }
8696           in_use |= EV5_E0;
8697           break;
8698
8699         case EV5_E1:
8700           if (in_use & EV5_E1)
8701             goto done;
8702           in_use |= EV5_E1;
8703           break;
8704
8705         case EV5_FAM:
8706           if (in_use & EV5_FA)
8707             {
8708               if (in_use & EV5_FM)
8709                 goto done;
8710               in_use |= EV5_FM;
8711             }
8712           else
8713             in_use |= EV5_FA | EV5_FAM;
8714           break;
8715
8716         case EV5_FA:
8717           if (in_use & EV5_FA)
8718             goto done;
8719           in_use |= EV5_FA;
8720           break;
8721
8722         case EV5_FM:
8723           if (in_use & EV5_FM)
8724             goto done;
8725           in_use |= EV5_FM;
8726           break;
8727
8728         case EV5_NONE:
8729           break;
8730
8731         default:
8732           abort();
8733         }
8734       len += 4;
8735       
8736       /* Haifa doesn't do well scheduling branches.  */
8737       /* ??? If this is predicted not-taken, slotting continues, except
8738          that no more IBR, FBR, or JSR insns may be slotted.  */
8739       if (GET_CODE (insn) == JUMP_INSN)
8740         goto next_and_done;
8741
8742     next:
8743       insn = next_nonnote_insn (insn);
8744
8745       if (!insn || ! INSN_P (insn))
8746         goto done;
8747
8748       /* Let Haifa tell us where it thinks insn group boundaries are.  */
8749       if (GET_MODE (insn) == TImode)
8750         goto done;
8751
8752       if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8753         goto next;
8754     }
8755
8756  next_and_done:
8757   insn = next_nonnote_insn (insn);
8758
8759  done:
8760   *plen = len;
8761   *pin_use = in_use;
8762   return insn;
8763 }
8764
8765 static rtx
8766 alphaev4_next_nop (int *pin_use)
8767 {
8768   int in_use = *pin_use;
8769   rtx nop;
8770
8771   if (!(in_use & EV4_IB0))
8772     {
8773       in_use |= EV4_IB0;
8774       nop = gen_nop ();
8775     }
8776   else if ((in_use & (EV4_IBX|EV4_IB1)) == EV4_IBX)
8777     {
8778       in_use |= EV4_IB1;
8779       nop = gen_nop ();
8780     }
8781   else if (TARGET_FP && !(in_use & EV4_IB1))
8782     {
8783       in_use |= EV4_IB1;
8784       nop = gen_fnop ();
8785     }
8786   else
8787     nop = gen_unop ();
8788
8789   *pin_use = in_use;
8790   return nop;
8791 }
8792
8793 static rtx
8794 alphaev5_next_nop (int *pin_use)
8795 {
8796   int in_use = *pin_use;
8797   rtx nop;
8798
8799   if (!(in_use & EV5_E1))
8800     {
8801       in_use |= EV5_E1;
8802       nop = gen_nop ();
8803     }
8804   else if (TARGET_FP && !(in_use & EV5_FA))
8805     {
8806       in_use |= EV5_FA;
8807       nop = gen_fnop ();
8808     }
8809   else if (TARGET_FP && !(in_use & EV5_FM))
8810     {
8811       in_use |= EV5_FM;
8812       nop = gen_fnop ();
8813     }
8814   else
8815     nop = gen_unop ();
8816
8817   *pin_use = in_use;
8818   return nop;
8819 }
8820
8821 /* The instruction group alignment main loop.  */
8822
8823 static void
8824 alpha_align_insns (unsigned int max_align,
8825                    rtx (*next_group) (rtx, int *, int *),
8826                    rtx (*next_nop) (int *))
8827 {
8828   /* ALIGN is the known alignment for the insn group.  */
8829   unsigned int align;
8830   /* OFS is the offset of the current insn in the insn group.  */
8831   int ofs;
8832   int prev_in_use, in_use, len, ldgp;
8833   rtx i, next;
8834
8835   /* Let shorten branches care for assigning alignments to code labels.  */
8836   shorten_branches (get_insns ());
8837
8838   if (align_functions < 4)
8839     align = 4;
8840   else if ((unsigned int) align_functions < max_align)
8841     align = align_functions;
8842   else
8843     align = max_align;
8844
8845   ofs = prev_in_use = 0;
8846   i = get_insns ();
8847   if (GET_CODE (i) == NOTE)
8848     i = next_nonnote_insn (i);
8849
8850   ldgp = alpha_function_needs_gp ? 8 : 0;
8851
8852   while (i)
8853     {
8854       next = (*next_group) (i, &in_use, &len);
8855
8856       /* When we see a label, resync alignment etc.  */
8857       if (GET_CODE (i) == CODE_LABEL)
8858         {
8859           unsigned int new_align = 1 << label_to_alignment (i);
8860
8861           if (new_align >= align)
8862             {
8863               align = new_align < max_align ? new_align : max_align;
8864               ofs = 0;
8865             }
8866
8867           else if (ofs & (new_align-1))
8868             ofs = (ofs | (new_align-1)) + 1;
8869           if (len != 0)
8870             abort();
8871         }
8872
8873       /* Handle complex instructions special.  */
8874       else if (in_use == 0)
8875         {
8876           /* Asms will have length < 0.  This is a signal that we have
8877              lost alignment knowledge.  Assume, however, that the asm
8878              will not mis-align instructions.  */
8879           if (len < 0)
8880             {
8881               ofs = 0;
8882               align = 4;
8883               len = 0;
8884             }
8885         }
8886
8887       /* If the known alignment is smaller than the recognized insn group,
8888          realign the output.  */
8889       else if ((int) align < len)
8890         {
8891           unsigned int new_log_align = len > 8 ? 4 : 3;
8892           rtx prev, where;
8893
8894           where = prev = prev_nonnote_insn (i);
8895           if (!where || GET_CODE (where) != CODE_LABEL)
8896             where = i;
8897
8898           /* Can't realign between a call and its gp reload.  */
8899           if (! (TARGET_EXPLICIT_RELOCS
8900                  && prev && GET_CODE (prev) == CALL_INSN))
8901             {
8902               emit_insn_before (gen_realign (GEN_INT (new_log_align)), where);
8903               align = 1 << new_log_align;
8904               ofs = 0;
8905             }
8906         }
8907
8908       /* We may not insert padding inside the initial ldgp sequence.  */
8909       else if (ldgp > 0)
8910         ldgp -= len;
8911
8912       /* If the group won't fit in the same INT16 as the previous,
8913          we need to add padding to keep the group together.  Rather
8914          than simply leaving the insn filling to the assembler, we
8915          can make use of the knowledge of what sorts of instructions
8916          were issued in the previous group to make sure that all of
8917          the added nops are really free.  */
8918       else if (ofs + len > (int) align)
8919         {
8920           int nop_count = (align - ofs) / 4;
8921           rtx where;
8922
8923           /* Insert nops before labels, branches, and calls to truly merge
8924              the execution of the nops with the previous instruction group.  */
8925           where = prev_nonnote_insn (i);
8926           if (where)
8927             {
8928               if (GET_CODE (where) == CODE_LABEL)
8929                 {
8930                   rtx where2 = prev_nonnote_insn (where);
8931                   if (where2 && GET_CODE (where2) == JUMP_INSN)
8932                     where = where2;
8933                 }
8934               else if (GET_CODE (where) == INSN)
8935                 where = i;
8936             }
8937           else
8938             where = i;
8939
8940           do 
8941             emit_insn_before ((*next_nop)(&prev_in_use), where);
8942           while (--nop_count);
8943           ofs = 0;
8944         }
8945
8946       ofs = (ofs + len) & (align - 1);
8947       prev_in_use = in_use;
8948       i = next;
8949     }
8950 }
8951 \f
8952 /* Machine dependent reorg pass.  */
8953
8954 static void
8955 alpha_reorg (void)
8956 {
8957   if (alpha_tp != ALPHA_TP_PROG || flag_exceptions)
8958     alpha_handle_trap_shadows ();
8959
8960   /* Due to the number of extra trapb insns, don't bother fixing up
8961      alignment when trap precision is instruction.  Moreover, we can
8962      only do our job when sched2 is run.  */
8963   if (optimize && !optimize_size
8964       && alpha_tp != ALPHA_TP_INSN
8965       && flag_schedule_insns_after_reload)
8966     {
8967       if (alpha_cpu == PROCESSOR_EV4)
8968         alpha_align_insns (8, alphaev4_next_group, alphaev4_next_nop);
8969       else if (alpha_cpu == PROCESSOR_EV5)
8970         alpha_align_insns (16, alphaev5_next_group, alphaev5_next_nop);
8971     }
8972 }
8973 \f
8974 #if !TARGET_ABI_UNICOSMK
8975
8976 #ifdef HAVE_STAMP_H
8977 #include <stamp.h>
8978 #endif
8979
8980 static void
8981 alpha_file_start (void)
8982 {
8983 #ifdef OBJECT_FORMAT_ELF
8984   /* If emitting dwarf2 debug information, we cannot generate a .file
8985      directive to start the file, as it will conflict with dwarf2out
8986      file numbers.  So it's only useful when emitting mdebug output.  */
8987   targetm.file_start_file_directive = (write_symbols == DBX_DEBUG);
8988 #endif
8989
8990   default_file_start ();
8991 #ifdef MS_STAMP
8992   fprintf (asm_out_file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP);
8993 #endif
8994
8995   fputs ("\t.set noreorder\n", asm_out_file);
8996   fputs ("\t.set volatile\n", asm_out_file);
8997   if (!TARGET_ABI_OPEN_VMS)
8998     fputs ("\t.set noat\n", asm_out_file);
8999   if (TARGET_EXPLICIT_RELOCS)
9000     fputs ("\t.set nomacro\n", asm_out_file);
9001   if (TARGET_SUPPORT_ARCH | TARGET_BWX | TARGET_MAX | TARGET_FIX | TARGET_CIX)
9002     fprintf (asm_out_file,
9003              "\t.arch %s\n",
9004              TARGET_CPU_EV6 ? "ev6"        
9005              : (TARGET_CPU_EV5
9006                 ? (TARGET_MAX ? "pca56" : TARGET_BWX ? "ev56" : "ev5")
9007                 : "ev4"));
9008 }
9009 #endif
9010
9011 #ifdef OBJECT_FORMAT_ELF
9012
9013 /* Switch to the section to which we should output X.  The only thing
9014    special we do here is to honor small data.  */
9015
9016 static void
9017 alpha_elf_select_rtx_section (enum machine_mode mode, rtx x,
9018                               unsigned HOST_WIDE_INT align)
9019 {
9020   if (TARGET_SMALL_DATA && GET_MODE_SIZE (mode) <= g_switch_value)
9021     /* ??? Consider using mergeable sdata sections.  */
9022     sdata_section ();
9023   else
9024     default_elf_select_rtx_section (mode, x, align);
9025 }
9026
9027 #endif /* OBJECT_FORMAT_ELF */
9028 \f
9029 /* Structure to collect function names for final output in link section.  */
9030 /* Note that items marked with GTY can't be ifdef'ed out.  */
9031
9032 enum links_kind {KIND_UNUSED, KIND_LOCAL, KIND_EXTERN};
9033 enum reloc_kind {KIND_LINKAGE, KIND_CODEADDR};
9034
9035 struct alpha_links GTY(())
9036 {
9037   int num;
9038   rtx linkage;
9039   enum links_kind lkind;
9040   enum reloc_kind rkind;
9041 };
9042
9043 struct alpha_funcs GTY(())
9044 {
9045   int num;
9046   splay_tree GTY ((param1_is (char *), param2_is (struct alpha_links *)))
9047     links;
9048 };
9049
9050 static GTY ((param1_is (char *), param2_is (struct alpha_links *)))
9051   splay_tree alpha_links_tree;
9052 static GTY ((param1_is (tree), param2_is (struct alpha_funcs *)))
9053   splay_tree alpha_funcs_tree;
9054
9055 static GTY(()) int alpha_funcs_num;
9056
9057 #if TARGET_ABI_OPEN_VMS
9058
9059 /* Return the VMS argument type corresponding to MODE.  */
9060
9061 enum avms_arg_type
9062 alpha_arg_type (enum machine_mode mode)
9063 {
9064   switch (mode)
9065     {
9066     case SFmode:
9067       return TARGET_FLOAT_VAX ? FF : FS;
9068     case DFmode:
9069       return TARGET_FLOAT_VAX ? FD : FT;
9070     default:
9071       return I64;
9072     }
9073 }
9074
9075 /* Return an rtx for an integer representing the VMS Argument Information
9076    register value.  */
9077
9078 rtx
9079 alpha_arg_info_reg_val (CUMULATIVE_ARGS cum)
9080 {
9081   unsigned HOST_WIDE_INT regval = cum.num_args;
9082   int i;
9083
9084   for (i = 0; i < 6; i++)
9085     regval |= ((int) cum.atypes[i]) << (i * 3 + 8);
9086
9087   return GEN_INT (regval);
9088 }
9089 \f
9090 /* Make (or fake) .linkage entry for function call.
9091
9092    IS_LOCAL is 0 if name is used in call, 1 if name is used in definition.
9093
9094    Return an SYMBOL_REF rtx for the linkage.  */
9095
9096 rtx
9097 alpha_need_linkage (const char *name, int is_local)
9098 {
9099   splay_tree_node node;
9100   struct alpha_links *al;
9101
9102   if (name[0] == '*')
9103     name++;
9104
9105   if (is_local)
9106     {
9107       struct alpha_funcs *cfaf;
9108
9109       if (!alpha_funcs_tree)
9110         alpha_funcs_tree = splay_tree_new_ggc ((splay_tree_compare_fn)
9111                                                splay_tree_compare_pointers);
9112     
9113       cfaf = (struct alpha_funcs *) ggc_alloc (sizeof (struct alpha_funcs));
9114
9115       cfaf->links = 0;
9116       cfaf->num = ++alpha_funcs_num;
9117
9118       splay_tree_insert (alpha_funcs_tree,
9119                          (splay_tree_key) current_function_decl,
9120                          (splay_tree_value) cfaf);
9121     }
9122
9123   if (alpha_links_tree)
9124     {
9125       /* Is this name already defined?  */
9126
9127       node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
9128       if (node)
9129         {
9130           al = (struct alpha_links *) node->value;
9131           if (is_local)
9132             {
9133               /* Defined here but external assumed.  */
9134               if (al->lkind == KIND_EXTERN)
9135                 al->lkind = KIND_LOCAL;
9136             }
9137           else
9138             {
9139               /* Used here but unused assumed.  */
9140               if (al->lkind == KIND_UNUSED)
9141                 al->lkind = KIND_LOCAL;
9142             }
9143           return al->linkage;
9144         }
9145     }
9146   else
9147     alpha_links_tree = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
9148
9149   al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
9150   name = ggc_strdup (name);
9151
9152   /* Assume external if no definition.  */
9153   al->lkind = (is_local ? KIND_UNUSED : KIND_EXTERN);
9154
9155   /* Ensure we have an IDENTIFIER so assemble_name can mark it used.  */
9156   get_identifier (name);
9157
9158   /* Construct a SYMBOL_REF for us to call.  */
9159   {
9160     size_t name_len = strlen (name);
9161     char *linksym = alloca (name_len + 6);
9162     linksym[0] = '$';
9163     memcpy (linksym + 1, name, name_len);
9164     memcpy (linksym + 1 + name_len, "..lk", 5);
9165     al->linkage = gen_rtx_SYMBOL_REF (Pmode,
9166                                       ggc_alloc_string (linksym, name_len + 5));
9167   }
9168
9169   splay_tree_insert (alpha_links_tree, (splay_tree_key) name,
9170                      (splay_tree_value) al);
9171
9172   return al->linkage;
9173 }
9174
9175 rtx
9176 alpha_use_linkage (rtx linkage, tree cfundecl, int lflag, int rflag)
9177 {
9178   splay_tree_node cfunnode;
9179   struct alpha_funcs *cfaf;
9180   struct alpha_links *al;
9181   const char *name = XSTR (linkage, 0);
9182
9183   cfaf = (struct alpha_funcs *) 0;
9184   al = (struct alpha_links *) 0;
9185
9186   cfunnode = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) cfundecl);
9187   cfaf = (struct alpha_funcs *) cfunnode->value;
9188
9189   if (cfaf->links)
9190     {
9191       splay_tree_node lnode;
9192
9193       /* Is this name already defined?  */
9194
9195       lnode = splay_tree_lookup (cfaf->links, (splay_tree_key) name);
9196       if (lnode)
9197         al = (struct alpha_links *) lnode->value;
9198     }
9199   else
9200     cfaf->links = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
9201
9202   if (!al)
9203     {
9204       size_t name_len;
9205       size_t buflen;
9206       char buf [512];
9207       char *linksym;
9208       splay_tree_node node = 0;
9209       struct alpha_links *anl;
9210
9211       if (name[0] == '*')
9212         name++;
9213
9214       name_len = strlen (name);
9215
9216       al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
9217       al->num = cfaf->num;
9218
9219       node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
9220       if (node)
9221         {
9222           anl = (struct alpha_links *) node->value;
9223           al->lkind = anl->lkind;
9224         }
9225
9226       sprintf (buf, "$%d..%s..lk", cfaf->num, name);
9227       buflen = strlen (buf);
9228       linksym = alloca (buflen + 1);
9229       memcpy (linksym, buf, buflen + 1);
9230
9231       al->linkage = gen_rtx_SYMBOL_REF
9232         (Pmode, ggc_alloc_string (linksym, buflen + 1));
9233
9234       splay_tree_insert (cfaf->links, (splay_tree_key) name,
9235                          (splay_tree_value) al);
9236     }
9237
9238   if (rflag)
9239     al->rkind = KIND_CODEADDR;
9240   else
9241     al->rkind = KIND_LINKAGE;
9242       
9243   if (lflag)
9244     return gen_rtx_MEM (Pmode, plus_constant (al->linkage, 8));
9245   else
9246     return al->linkage;
9247 }
9248
9249 static int
9250 alpha_write_one_linkage (splay_tree_node node, void *data)
9251 {
9252   const char *const name = (const char *) node->key;
9253   struct alpha_links *link = (struct alpha_links *) node->value;
9254   FILE *stream = (FILE *) data;
9255
9256   fprintf (stream, "$%d..%s..lk:\n", link->num, name);
9257   if (link->rkind == KIND_CODEADDR)
9258     {
9259       if (link->lkind == KIND_LOCAL)
9260         {
9261           /* Local and used */
9262           fprintf (stream, "\t.quad %s..en\n", name);
9263         }
9264       else
9265         {
9266           /* External and used, request code address.  */
9267           fprintf (stream, "\t.code_address %s\n", name);
9268         }
9269     }
9270   else
9271     {
9272       if (link->lkind == KIND_LOCAL)
9273         {
9274           /* Local and used, build linkage pair.  */
9275           fprintf (stream, "\t.quad %s..en\n", name);
9276           fprintf (stream, "\t.quad %s\n", name);
9277         }
9278       else
9279         {
9280           /* External and used, request linkage pair.  */
9281           fprintf (stream, "\t.linkage %s\n", name);
9282         }
9283     }
9284
9285   return 0;
9286 }
9287
9288 static void
9289 alpha_write_linkage (FILE *stream, const char *funname, tree fundecl)
9290 {
9291   splay_tree_node node;
9292   struct alpha_funcs *func;
9293
9294   link_section ();
9295   fprintf (stream, "\t.align 3\n");
9296   node = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) fundecl);
9297   func = (struct alpha_funcs *) node->value;
9298
9299   fputs ("\t.name ", stream);
9300   assemble_name (stream, funname);
9301   fputs ("..na\n", stream);
9302   ASM_OUTPUT_LABEL (stream, funname);
9303   fprintf (stream, "\t.pdesc ");
9304   assemble_name (stream, funname);
9305   fprintf (stream, "..en,%s\n",
9306            alpha_procedure_type == PT_STACK ? "stack"
9307            : alpha_procedure_type == PT_REGISTER ? "reg" : "null");
9308
9309   if (func->links)
9310     {
9311       splay_tree_foreach (func->links, alpha_write_one_linkage, stream);
9312       /* splay_tree_delete (func->links); */
9313     }
9314 }
9315
9316 /* Given a decl, a section name, and whether the decl initializer
9317    has relocs, choose attributes for the section.  */
9318
9319 #define SECTION_VMS_OVERLAY     SECTION_FORGET
9320 #define SECTION_VMS_GLOBAL SECTION_MACH_DEP
9321 #define SECTION_VMS_INITIALIZE (SECTION_VMS_GLOBAL << 1)
9322
9323 static unsigned int
9324 vms_section_type_flags (tree decl, const char *name, int reloc)
9325 {
9326   unsigned int flags = default_section_type_flags (decl, name, reloc);
9327
9328   if (decl && DECL_ATTRIBUTES (decl)
9329       && lookup_attribute ("overlaid", DECL_ATTRIBUTES (decl)))
9330     flags |= SECTION_VMS_OVERLAY;
9331   if (decl && DECL_ATTRIBUTES (decl)
9332       && lookup_attribute ("global", DECL_ATTRIBUTES (decl)))
9333     flags |= SECTION_VMS_GLOBAL;
9334   if (decl && DECL_ATTRIBUTES (decl)
9335       && lookup_attribute ("initialize", DECL_ATTRIBUTES (decl)))
9336     flags |= SECTION_VMS_INITIALIZE;
9337
9338   return flags;
9339 }
9340
9341 /* Switch to an arbitrary section NAME with attributes as specified
9342    by FLAGS.  ALIGN specifies any known alignment requirements for
9343    the section; 0 if the default should be used.  */
9344
9345 static void
9346 vms_asm_named_section (const char *name, unsigned int flags)
9347 {
9348   fputc ('\n', asm_out_file);
9349   fprintf (asm_out_file, ".section\t%s", name);
9350
9351   if (flags & SECTION_VMS_OVERLAY)
9352     fprintf (asm_out_file, ",OVR");
9353   if (flags & SECTION_VMS_GLOBAL)
9354     fprintf (asm_out_file, ",GBL");
9355   if (flags & SECTION_VMS_INITIALIZE)
9356     fprintf (asm_out_file, ",NOMOD");
9357   if (flags & SECTION_DEBUG)
9358     fprintf (asm_out_file, ",NOWRT");
9359
9360   fputc ('\n', asm_out_file);
9361 }
9362
9363 /* Record an element in the table of global constructors.  SYMBOL is
9364    a SYMBOL_REF of the function to be called; PRIORITY is a number
9365    between 0 and MAX_INIT_PRIORITY.  
9366
9367    Differs from default_ctors_section_asm_out_constructor in that the
9368    width of the .ctors entry is always 64 bits, rather than the 32 bits
9369    used by a normal pointer.  */
9370
9371 static void
9372 vms_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9373 {
9374   ctors_section ();
9375   assemble_align (BITS_PER_WORD);
9376   assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9377 }
9378
9379 static void
9380 vms_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9381 {
9382   dtors_section ();
9383   assemble_align (BITS_PER_WORD);
9384   assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9385 }
9386 #else
9387
9388 rtx
9389 alpha_need_linkage (const char *name ATTRIBUTE_UNUSED,
9390                     int is_local ATTRIBUTE_UNUSED)
9391 {
9392   return NULL_RTX;
9393 }
9394
9395 rtx
9396 alpha_use_linkage (rtx linkage ATTRIBUTE_UNUSED,
9397                    tree cfundecl ATTRIBUTE_UNUSED,
9398                    int lflag ATTRIBUTE_UNUSED,
9399                    int rflag ATTRIBUTE_UNUSED)
9400 {
9401   return NULL_RTX;
9402 }
9403
9404 #endif /* TARGET_ABI_OPEN_VMS */
9405 \f
9406 #if TARGET_ABI_UNICOSMK
9407
9408 /* Define the offset between two registers, one to be eliminated, and the
9409    other its replacement, at the start of a routine.  */
9410
9411 int
9412 unicosmk_initial_elimination_offset (int from, int to)
9413 {
9414   int fixed_size;
9415   
9416   fixed_size = alpha_sa_size();
9417   if (fixed_size != 0)
9418     fixed_size += 48;
9419
9420   if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9421     return -fixed_size; 
9422   else if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9423     return 0;
9424   else if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9425     return (ALPHA_ROUND (current_function_outgoing_args_size)
9426             + ALPHA_ROUND (get_frame_size()));
9427   else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9428     return (ALPHA_ROUND (fixed_size)
9429             + ALPHA_ROUND (get_frame_size() 
9430                            + current_function_outgoing_args_size));
9431   else
9432     abort ();
9433 }
9434
9435 /* Output the module name for .ident and .end directives. We have to strip
9436    directories and add make sure that the module name starts with a letter
9437    or '$'.  */
9438
9439 static void
9440 unicosmk_output_module_name (FILE *file)
9441 {
9442   const char *name = lbasename (main_input_filename);
9443   unsigned len = strlen (name);
9444   char *clean_name = alloca (len + 2);
9445   char *ptr = clean_name;
9446   
9447   /* CAM only accepts module names that start with a letter or '$'. We
9448      prefix the module name with a '$' if necessary.  */
9449
9450   if (!ISALPHA (*name))
9451     *ptr++ = '$';
9452   memcpy (ptr, name, len + 1);
9453   clean_symbol_name (clean_name);
9454   fputs (clean_name, file);
9455 }
9456
9457 /* Output the definition of a common variable.  */
9458
9459 void
9460 unicosmk_output_common (FILE *file, const char *name, int size, int align)
9461 {
9462   tree name_tree;
9463   printf ("T3E__: common %s\n", name);
9464
9465   common_section ();
9466   fputs("\t.endp\n\n\t.psect ", file);
9467   assemble_name(file, name);
9468   fprintf(file, ",%d,common\n", floor_log2 (align / BITS_PER_UNIT));
9469   fprintf(file, "\t.byte\t0:%d\n", size);
9470
9471   /* Mark the symbol as defined in this module.  */
9472   name_tree = get_identifier (name);
9473   TREE_ASM_WRITTEN (name_tree) = 1;
9474 }
9475
9476 #define SECTION_PUBLIC SECTION_MACH_DEP
9477 #define SECTION_MAIN (SECTION_PUBLIC << 1)
9478 static int current_section_align;
9479
9480 static unsigned int
9481 unicosmk_section_type_flags (tree decl, const char *name,
9482                              int reloc ATTRIBUTE_UNUSED)
9483 {
9484   unsigned int flags = default_section_type_flags (decl, name, reloc);
9485
9486   if (!decl)
9487     return flags;
9488
9489   if (TREE_CODE (decl) == FUNCTION_DECL)
9490     {
9491       current_section_align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
9492       if (align_functions_log > current_section_align)
9493         current_section_align = align_functions_log;
9494
9495       if (! strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "main"))
9496         flags |= SECTION_MAIN;
9497     }
9498   else
9499     current_section_align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
9500
9501   if (TREE_PUBLIC (decl))
9502     flags |= SECTION_PUBLIC;
9503
9504   return flags;
9505 }
9506
9507 /* Generate a section name for decl and associate it with the
9508    declaration.  */
9509
9510 static void
9511 unicosmk_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
9512 {
9513   const char *name;
9514   int len;
9515
9516   if (!decl) 
9517     abort ();
9518
9519   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9520   name = default_strip_name_encoding (name);
9521   len = strlen (name);
9522
9523   if (TREE_CODE (decl) == FUNCTION_DECL)
9524     {
9525       char *string;
9526
9527       /* It is essential that we prefix the section name here because 
9528          otherwise the section names generated for constructors and 
9529          destructors confuse collect2.  */
9530
9531       string = alloca (len + 6);
9532       sprintf (string, "code@%s", name);
9533       DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9534     }
9535   else if (TREE_PUBLIC (decl))
9536     DECL_SECTION_NAME (decl) = build_string (len, name);
9537   else
9538     {
9539       char *string;
9540
9541       string = alloca (len + 6);
9542       sprintf (string, "data@%s", name);
9543       DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9544     }
9545 }
9546
9547 /* Switch to an arbitrary section NAME with attributes as specified
9548    by FLAGS.  ALIGN specifies any known alignment requirements for
9549    the section; 0 if the default should be used.  */
9550
9551 static void
9552 unicosmk_asm_named_section (const char *name, unsigned int flags)
9553 {
9554   const char *kind;
9555
9556   /* Close the previous section.  */
9557
9558   fputs ("\t.endp\n\n", asm_out_file);
9559
9560   /* Find out what kind of section we are opening.  */
9561
9562   if (flags & SECTION_MAIN)
9563     fputs ("\t.start\tmain\n", asm_out_file);
9564
9565   if (flags & SECTION_CODE)
9566     kind = "code";
9567   else if (flags & SECTION_PUBLIC)
9568     kind = "common";
9569   else
9570     kind = "data";
9571
9572   if (current_section_align != 0)
9573     fprintf (asm_out_file, "\t.psect\t%s,%d,%s\n", name,
9574              current_section_align, kind);
9575   else
9576     fprintf (asm_out_file, "\t.psect\t%s,%s\n", name, kind);
9577 }
9578
9579 static void
9580 unicosmk_insert_attributes (tree decl, tree *attr_ptr ATTRIBUTE_UNUSED)
9581 {
9582   if (DECL_P (decl)
9583       && (TREE_PUBLIC (decl) || TREE_CODE (decl) == FUNCTION_DECL))
9584     unicosmk_unique_section (decl, 0);
9585 }
9586
9587 /* Output an alignment directive. We have to use the macro 'gcc@code@align'
9588    in code sections because .align fill unused space with zeroes.  */
9589       
9590 void
9591 unicosmk_output_align (FILE *file, int align)
9592 {
9593   if (inside_function)
9594     fprintf (file, "\tgcc@code@align\t%d\n", align);
9595   else
9596     fprintf (file, "\t.align\t%d\n", align);
9597 }
9598
9599 /* Add a case vector to the current function's list of deferred case
9600    vectors. Case vectors have to be put into a separate section because CAM
9601    does not allow data definitions in code sections.  */
9602
9603 void
9604 unicosmk_defer_case_vector (rtx lab, rtx vec)
9605 {
9606   struct machine_function *machine = cfun->machine;
9607   
9608   vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
9609   machine->addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec,
9610                                           machine->addr_list); 
9611 }
9612
9613 /* Output a case vector.  */
9614
9615 static void
9616 unicosmk_output_addr_vec (FILE *file, rtx vec)
9617 {
9618   rtx lab  = XEXP (vec, 0);
9619   rtx body = XEXP (vec, 1);
9620   int vlen = XVECLEN (body, 0);
9621   int idx;
9622
9623   (*targetm.asm_out.internal_label) (file, "L", CODE_LABEL_NUMBER (lab));
9624
9625   for (idx = 0; idx < vlen; idx++)
9626     {
9627       ASM_OUTPUT_ADDR_VEC_ELT
9628         (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
9629     }
9630 }
9631
9632 /* Output current function's deferred case vectors.  */
9633
9634 static void
9635 unicosmk_output_deferred_case_vectors (FILE *file)
9636 {
9637   struct machine_function *machine = cfun->machine;
9638   rtx t;
9639
9640   if (machine->addr_list == NULL_RTX)
9641     return;
9642
9643   data_section ();
9644   for (t = machine->addr_list; t; t = XEXP (t, 1))
9645     unicosmk_output_addr_vec (file, XEXP (t, 0));
9646 }
9647
9648 /* Generate the name of the SSIB section for the current function.  */
9649
9650 #define SSIB_PREFIX "__SSIB_"
9651 #define SSIB_PREFIX_LEN 7
9652
9653 static const char *
9654 unicosmk_ssib_name (void)
9655 {
9656   /* This is ok since CAM won't be able to deal with names longer than that 
9657      anyway.  */
9658
9659   static char name[256];
9660
9661   rtx x;
9662   const char *fnname;
9663   int len;
9664
9665   x = DECL_RTL (cfun->decl);
9666   if (GET_CODE (x) != MEM)
9667     abort ();
9668   x = XEXP (x, 0);
9669   if (GET_CODE (x) != SYMBOL_REF)
9670     abort ();
9671   fnname = XSTR (x, 0);
9672
9673   len = strlen (fnname);
9674   if (len + SSIB_PREFIX_LEN > 255)
9675     len = 255 - SSIB_PREFIX_LEN;
9676
9677   strcpy (name, SSIB_PREFIX);
9678   strncpy (name + SSIB_PREFIX_LEN, fnname, len);
9679   name[len + SSIB_PREFIX_LEN] = 0;
9680
9681   return name;
9682 }
9683
9684 /* Set up the dynamic subprogram information block (DSIB) and update the 
9685    frame pointer register ($15) for subroutines which have a frame. If the 
9686    subroutine doesn't have a frame, simply increment $15.  */
9687
9688 static void
9689 unicosmk_gen_dsib (unsigned long *imaskP)
9690 {
9691   if (alpha_procedure_type == PT_STACK)
9692     {
9693       const char *ssib_name;
9694       rtx mem;
9695
9696       /* Allocate 64 bytes for the DSIB.  */
9697
9698       FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
9699                                   GEN_INT (-64))));
9700       emit_insn (gen_blockage ());
9701
9702       /* Save the return address.  */
9703
9704       mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 56));
9705       set_mem_alias_set (mem, alpha_sr_alias_set);
9706       FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA)));
9707       (*imaskP) &= ~(1UL << REG_RA);
9708
9709       /* Save the old frame pointer.  */
9710
9711       mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 48));
9712       set_mem_alias_set (mem, alpha_sr_alias_set);
9713       FRP (emit_move_insn (mem, hard_frame_pointer_rtx));
9714       (*imaskP) &= ~(1UL << HARD_FRAME_POINTER_REGNUM);
9715
9716       emit_insn (gen_blockage ());
9717
9718       /* Store the SSIB pointer.  */
9719
9720       ssib_name = ggc_strdup (unicosmk_ssib_name ());
9721       mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 32));
9722       set_mem_alias_set (mem, alpha_sr_alias_set);
9723
9724       FRP (emit_move_insn (gen_rtx_REG (DImode, 5),
9725                            gen_rtx_SYMBOL_REF (Pmode, ssib_name)));
9726       FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 5)));
9727
9728       /* Save the CIW index.  */
9729
9730       mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 24));
9731       set_mem_alias_set (mem, alpha_sr_alias_set);
9732       FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 25)));
9733
9734       emit_insn (gen_blockage ());
9735
9736       /* Set the new frame pointer.  */
9737
9738       FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9739                                   stack_pointer_rtx, GEN_INT (64))));
9740
9741     }
9742   else
9743     {
9744       /* Increment the frame pointer register to indicate that we do not
9745          have a frame.  */
9746
9747       FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9748                                   hard_frame_pointer_rtx, GEN_INT (1))));
9749     }
9750 }
9751
9752 /* Output the static subroutine information block for the current
9753    function.  */
9754
9755 static void
9756 unicosmk_output_ssib (FILE *file, const char *fnname)
9757 {
9758   int len;
9759   int i;
9760   rtx x;
9761   rtx ciw;
9762   struct machine_function *machine = cfun->machine;
9763
9764   ssib_section ();
9765   fprintf (file, "\t.endp\n\n\t.psect\t%s%s,data\n", user_label_prefix,
9766            unicosmk_ssib_name ());
9767
9768   /* Some required stuff and the function name length.  */
9769
9770   len = strlen (fnname);
9771   fprintf (file, "\t.quad\t^X20008%2.2X28\n", len);
9772
9773   /* Saved registers
9774      ??? We don't do that yet.  */
9775
9776   fputs ("\t.quad\t0\n", file);
9777
9778   /* Function address.  */
9779
9780   fputs ("\t.quad\t", file);
9781   assemble_name (file, fnname);
9782   putc ('\n', file);
9783
9784   fputs ("\t.quad\t0\n", file);
9785   fputs ("\t.quad\t0\n", file);
9786
9787   /* Function name.
9788      ??? We do it the same way Cray CC does it but this could be
9789      simplified.  */
9790
9791   for( i = 0; i < len; i++ )
9792     fprintf (file, "\t.byte\t%d\n", (int)(fnname[i]));
9793   if( (len % 8) == 0 )
9794     fputs ("\t.quad\t0\n", file);
9795   else
9796     fprintf (file, "\t.bits\t%d : 0\n", (8 - (len % 8))*8);
9797
9798   /* All call information words used in the function.  */
9799
9800   for (x = machine->first_ciw; x; x = XEXP (x, 1))
9801     {
9802       ciw = XEXP (x, 0);
9803 #if HOST_BITS_PER_WIDE_INT == 32
9804       fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_DOUBLE_HEX "\n",
9805                CONST_DOUBLE_HIGH (ciw), CONST_DOUBLE_LOW (ciw));
9806 #else
9807       fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX "\n", INTVAL (ciw));
9808 #endif
9809     }
9810 }
9811
9812 /* Add a call information word (CIW) to the list of the current function's
9813    CIWs and return its index.
9814
9815    X is a CONST_INT or CONST_DOUBLE representing the CIW.  */
9816
9817 rtx
9818 unicosmk_add_call_info_word (rtx x)
9819 {
9820   rtx node;
9821   struct machine_function *machine = cfun->machine;
9822
9823   node = gen_rtx_EXPR_LIST (VOIDmode, x, NULL_RTX);
9824   if (machine->first_ciw == NULL_RTX)
9825     machine->first_ciw = node;
9826   else
9827     XEXP (machine->last_ciw, 1) = node;
9828
9829   machine->last_ciw = node;
9830   ++machine->ciw_count;
9831
9832   return GEN_INT (machine->ciw_count
9833                   + strlen (current_function_name ())/8 + 5);
9834 }
9835
9836 static char unicosmk_section_buf[100];
9837
9838 char *
9839 unicosmk_text_section (void)
9840 {
9841   static int count = 0;
9842   sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@text___%d,code", 
9843                                  count++);
9844   return unicosmk_section_buf;
9845 }
9846
9847 char *
9848 unicosmk_data_section (void)
9849 {
9850   static int count = 1;
9851   sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@data___%d,data", 
9852                                  count++);
9853   return unicosmk_section_buf;
9854 }
9855
9856 /* The Cray assembler doesn't accept extern declarations for symbols which
9857    are defined in the same file. We have to keep track of all global
9858    symbols which are referenced and/or defined in a source file and output
9859    extern declarations for those which are referenced but not defined at
9860    the end of file.  */
9861
9862 /* List of identifiers for which an extern declaration might have to be
9863    emitted.  */
9864 /* FIXME: needs to use GC, so it can be saved and restored for PCH.  */
9865
9866 struct unicosmk_extern_list
9867 {
9868   struct unicosmk_extern_list *next;
9869   const char *name;
9870 };
9871
9872 static struct unicosmk_extern_list *unicosmk_extern_head = 0;
9873
9874 /* Output extern declarations which are required for every asm file.  */
9875
9876 static void
9877 unicosmk_output_default_externs (FILE *file)
9878 {
9879   static const char *const externs[] =
9880     { "__T3E_MISMATCH" };
9881
9882   int i;
9883   int n;
9884
9885   n = ARRAY_SIZE (externs);
9886
9887   for (i = 0; i < n; i++)
9888     fprintf (file, "\t.extern\t%s\n", externs[i]);
9889 }
9890
9891 /* Output extern declarations for global symbols which are have been
9892    referenced but not defined.  */
9893
9894 static void
9895 unicosmk_output_externs (FILE *file)
9896 {
9897   struct unicosmk_extern_list *p;
9898   const char *real_name;
9899   int len;
9900   tree name_tree;
9901
9902   len = strlen (user_label_prefix);
9903   for (p = unicosmk_extern_head; p != 0; p = p->next)
9904     {
9905       /* We have to strip the encoding and possibly remove user_label_prefix 
9906          from the identifier in order to handle -fleading-underscore and
9907          explicit asm names correctly (cf. gcc.dg/asm-names-1.c).  */
9908       real_name = default_strip_name_encoding (p->name);
9909       if (len && p->name[0] == '*'
9910           && !memcmp (real_name, user_label_prefix, len))
9911         real_name += len;
9912         
9913       name_tree = get_identifier (real_name);
9914       if (! TREE_ASM_WRITTEN (name_tree))
9915         {
9916           TREE_ASM_WRITTEN (name_tree) = 1;
9917           fputs ("\t.extern\t", file);
9918           assemble_name (file, p->name);
9919           putc ('\n', file);
9920         }
9921     }
9922 }
9923       
9924 /* Record an extern.  */
9925
9926 void
9927 unicosmk_add_extern (const char *name)
9928 {
9929   struct unicosmk_extern_list *p;
9930
9931   p = (struct unicosmk_extern_list *)
9932        xmalloc (sizeof (struct unicosmk_extern_list));
9933   p->next = unicosmk_extern_head;
9934   p->name = name;
9935   unicosmk_extern_head = p;
9936 }
9937
9938 /* The Cray assembler generates incorrect code if identifiers which
9939    conflict with register names are used as instruction operands. We have
9940    to replace such identifiers with DEX expressions.  */
9941
9942 /* Structure to collect identifiers which have been replaced by DEX
9943    expressions.  */
9944 /* FIXME: needs to use GC, so it can be saved and restored for PCH.  */
9945
9946 struct unicosmk_dex {
9947   struct unicosmk_dex *next;
9948   const char *name;
9949 };
9950
9951 /* List of identifiers which have been replaced by DEX expressions. The DEX 
9952    number is determined by the position in the list.  */
9953
9954 static struct unicosmk_dex *unicosmk_dex_list = NULL; 
9955
9956 /* The number of elements in the DEX list.  */
9957
9958 static int unicosmk_dex_count = 0;
9959
9960 /* Check if NAME must be replaced by a DEX expression.  */
9961
9962 static int
9963 unicosmk_special_name (const char *name)
9964 {
9965   if (name[0] == '*')
9966     ++name;
9967
9968   if (name[0] == '$')
9969     ++name;
9970
9971   if (name[0] != 'r' && name[0] != 'f' && name[0] != 'R' && name[0] != 'F')
9972     return 0;
9973
9974   switch (name[1])
9975     {
9976     case '1':  case '2':
9977       return (name[2] == '\0' || (ISDIGIT (name[2]) && name[3] == '\0'));
9978
9979     case '3':
9980       return (name[2] == '\0'
9981                || ((name[2] == '0' || name[2] == '1') && name[3] == '\0'));
9982
9983     default:
9984       return (ISDIGIT (name[1]) && name[2] == '\0');
9985     }
9986 }
9987
9988 /* Return the DEX number if X must be replaced by a DEX expression and 0
9989    otherwise.  */
9990
9991 static int
9992 unicosmk_need_dex (rtx x)
9993 {
9994   struct unicosmk_dex *dex;
9995   const char *name;
9996   int i;
9997   
9998   if (GET_CODE (x) != SYMBOL_REF)
9999     return 0;
10000
10001   name = XSTR (x,0);
10002   if (! unicosmk_special_name (name))
10003     return 0;
10004
10005   i = unicosmk_dex_count;
10006   for (dex = unicosmk_dex_list; dex; dex = dex->next)
10007     {
10008       if (! strcmp (name, dex->name))
10009         return i;
10010       --i;
10011     }
10012       
10013   dex = (struct unicosmk_dex *) xmalloc (sizeof (struct unicosmk_dex));
10014   dex->name = name;
10015   dex->next = unicosmk_dex_list;
10016   unicosmk_dex_list = dex;
10017
10018   ++unicosmk_dex_count;
10019   return unicosmk_dex_count;
10020 }
10021
10022 /* Output the DEX definitions for this file.  */
10023
10024 static void
10025 unicosmk_output_dex (FILE *file)
10026 {
10027   struct unicosmk_dex *dex;
10028   int i;
10029
10030   if (unicosmk_dex_list == NULL)
10031     return;
10032
10033   fprintf (file, "\t.dexstart\n");
10034
10035   i = unicosmk_dex_count;
10036   for (dex = unicosmk_dex_list; dex; dex = dex->next)
10037     {
10038       fprintf (file, "\tDEX (%d) = ", i);
10039       assemble_name (file, dex->name);
10040       putc ('\n', file);
10041       --i;
10042     }
10043   
10044   fprintf (file, "\t.dexend\n");
10045 }
10046
10047 /* Output text that to appear at the beginning of an assembler file.  */
10048
10049 static void 
10050 unicosmk_file_start (void)
10051 {
10052   int i;
10053
10054   fputs ("\t.ident\t", asm_out_file);
10055   unicosmk_output_module_name (asm_out_file);
10056   fputs ("\n\n", asm_out_file);
10057
10058   /* The Unicos/Mk assembler uses different register names. Instead of trying
10059      to support them, we simply use micro definitions.  */
10060
10061   /* CAM has different register names: rN for the integer register N and fN
10062      for the floating-point register N. Instead of trying to use these in
10063      alpha.md, we define the symbols $N and $fN to refer to the appropriate
10064      register.  */
10065
10066   for (i = 0; i < 32; ++i)
10067     fprintf (asm_out_file, "$%d <- r%d\n", i, i);
10068
10069   for (i = 0; i < 32; ++i)
10070     fprintf (asm_out_file, "$f%d <- f%d\n", i, i);
10071
10072   putc ('\n', asm_out_file);
10073
10074   /* The .align directive fill unused space with zeroes which does not work
10075      in code sections. We define the macro 'gcc@code@align' which uses nops
10076      instead. Note that it assumes that code sections always have the
10077      biggest possible alignment since . refers to the current offset from
10078      the beginning of the section.  */
10079
10080   fputs ("\t.macro gcc@code@align n\n", asm_out_file);
10081   fputs ("gcc@n@bytes = 1 << n\n", asm_out_file);
10082   fputs ("gcc@here = . % gcc@n@bytes\n", asm_out_file);
10083   fputs ("\t.if ne, gcc@here, 0\n", asm_out_file);
10084   fputs ("\t.repeat (gcc@n@bytes - gcc@here) / 4\n", asm_out_file);
10085   fputs ("\tbis r31,r31,r31\n", asm_out_file);
10086   fputs ("\t.endr\n", asm_out_file);
10087   fputs ("\t.endif\n", asm_out_file);
10088   fputs ("\t.endm gcc@code@align\n\n", asm_out_file);
10089
10090   /* Output extern declarations which should always be visible.  */
10091   unicosmk_output_default_externs (asm_out_file);
10092
10093   /* Open a dummy section. We always need to be inside a section for the
10094      section-switching code to work correctly.
10095      ??? This should be a module id or something like that. I still have to
10096      figure out what the rules for those are.  */
10097   fputs ("\n\t.psect\t$SG00000,data\n", asm_out_file);
10098 }
10099
10100 /* Output text to appear at the end of an assembler file. This includes all
10101    pending extern declarations and DEX expressions.  */
10102
10103 static void
10104 unicosmk_file_end (void)
10105 {
10106   fputs ("\t.endp\n\n", asm_out_file);
10107
10108   /* Output all pending externs.  */
10109
10110   unicosmk_output_externs (asm_out_file);
10111
10112   /* Output dex definitions used for functions whose names conflict with 
10113      register names.  */
10114
10115   unicosmk_output_dex (asm_out_file);
10116
10117   fputs ("\t.end\t", asm_out_file);
10118   unicosmk_output_module_name (asm_out_file);
10119   putc ('\n', asm_out_file);
10120 }
10121
10122 #else
10123
10124 static void
10125 unicosmk_output_deferred_case_vectors (FILE *file ATTRIBUTE_UNUSED)
10126 {}
10127
10128 static void
10129 unicosmk_gen_dsib (unsigned long *imaskP ATTRIBUTE_UNUSED)
10130 {}
10131
10132 static void
10133 unicosmk_output_ssib (FILE * file ATTRIBUTE_UNUSED,
10134                       const char * fnname ATTRIBUTE_UNUSED)
10135 {}
10136
10137 rtx
10138 unicosmk_add_call_info_word (rtx x ATTRIBUTE_UNUSED)
10139 {
10140   return NULL_RTX;
10141 }
10142
10143 static int
10144 unicosmk_need_dex (rtx x ATTRIBUTE_UNUSED)
10145 {
10146   return 0;
10147 }
10148
10149 #endif /* TARGET_ABI_UNICOSMK */
10150
10151 static void
10152 alpha_init_libfuncs (void)
10153 {
10154   if (TARGET_ABI_UNICOSMK)
10155     {
10156       /* Prevent gcc from generating calls to __divsi3.  */
10157       set_optab_libfunc (sdiv_optab, SImode, 0);
10158       set_optab_libfunc (udiv_optab, SImode, 0);
10159
10160       /* Use the functions provided by the system library
10161          for DImode integer division.  */
10162       set_optab_libfunc (sdiv_optab, DImode, "$sldiv");
10163       set_optab_libfunc (udiv_optab, DImode, "$uldiv");
10164     }
10165   else if (TARGET_ABI_OPEN_VMS)
10166     {
10167       /* Use the VMS runtime library functions for division and
10168          remainder.  */
10169       set_optab_libfunc (sdiv_optab, SImode, "OTS$DIV_I");
10170       set_optab_libfunc (sdiv_optab, DImode, "OTS$DIV_L");
10171       set_optab_libfunc (udiv_optab, SImode, "OTS$DIV_UI");
10172       set_optab_libfunc (udiv_optab, DImode, "OTS$DIV_UL");
10173       set_optab_libfunc (smod_optab, SImode, "OTS$REM_I");
10174       set_optab_libfunc (smod_optab, DImode, "OTS$REM_L");
10175       set_optab_libfunc (umod_optab, SImode, "OTS$REM_UI");
10176       set_optab_libfunc (umod_optab, DImode, "OTS$REM_UL");
10177     }
10178 }
10179
10180 \f
10181 /* Initialize the GCC target structure.  */
10182 #if TARGET_ABI_OPEN_VMS
10183 # undef TARGET_ATTRIBUTE_TABLE
10184 # define TARGET_ATTRIBUTE_TABLE vms_attribute_table
10185 # undef TARGET_SECTION_TYPE_FLAGS
10186 # define TARGET_SECTION_TYPE_FLAGS vms_section_type_flags
10187 #endif
10188
10189 #undef TARGET_IN_SMALL_DATA_P
10190 #define TARGET_IN_SMALL_DATA_P alpha_in_small_data_p
10191
10192 #if TARGET_ABI_UNICOSMK
10193 # undef TARGET_INSERT_ATTRIBUTES
10194 # define TARGET_INSERT_ATTRIBUTES unicosmk_insert_attributes
10195 # undef TARGET_SECTION_TYPE_FLAGS
10196 # define TARGET_SECTION_TYPE_FLAGS unicosmk_section_type_flags
10197 # undef TARGET_ASM_UNIQUE_SECTION
10198 # define TARGET_ASM_UNIQUE_SECTION unicosmk_unique_section
10199 # undef TARGET_ASM_GLOBALIZE_LABEL
10200 # define TARGET_ASM_GLOBALIZE_LABEL hook_void_FILEptr_constcharptr
10201 #endif
10202
10203 #undef TARGET_ASM_ALIGNED_HI_OP
10204 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
10205 #undef TARGET_ASM_ALIGNED_DI_OP
10206 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
10207
10208 /* Default unaligned ops are provided for ELF systems.  To get unaligned
10209    data for non-ELF systems, we have to turn off auto alignment.  */
10210 #ifndef OBJECT_FORMAT_ELF
10211 #undef TARGET_ASM_UNALIGNED_HI_OP
10212 #define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.word\t"
10213 #undef TARGET_ASM_UNALIGNED_SI_OP
10214 #define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.long\t"
10215 #undef TARGET_ASM_UNALIGNED_DI_OP
10216 #define TARGET_ASM_UNALIGNED_DI_OP "\t.align 0\n\t.quad\t"
10217 #endif
10218
10219 #ifdef OBJECT_FORMAT_ELF
10220 #undef  TARGET_ASM_SELECT_RTX_SECTION
10221 #define TARGET_ASM_SELECT_RTX_SECTION  alpha_elf_select_rtx_section
10222 #endif
10223
10224 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
10225 #define TARGET_ASM_FUNCTION_END_PROLOGUE alpha_output_function_end_prologue
10226
10227 #undef TARGET_INIT_LIBFUNCS
10228 #define TARGET_INIT_LIBFUNCS alpha_init_libfuncs
10229
10230 #if TARGET_ABI_UNICOSMK
10231 #undef TARGET_ASM_FILE_START
10232 #define TARGET_ASM_FILE_START unicosmk_file_start
10233 #undef TARGET_ASM_FILE_END
10234 #define TARGET_ASM_FILE_END unicosmk_file_end
10235 #else
10236 #undef TARGET_ASM_FILE_START
10237 #define TARGET_ASM_FILE_START alpha_file_start
10238 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
10239 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
10240 #endif
10241
10242 #undef TARGET_SCHED_ADJUST_COST
10243 #define TARGET_SCHED_ADJUST_COST alpha_adjust_cost
10244 #undef TARGET_SCHED_ISSUE_RATE
10245 #define TARGET_SCHED_ISSUE_RATE alpha_issue_rate
10246 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
10247 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE \
10248   alpha_use_dfa_pipeline_interface
10249 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
10250 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
10251   alpha_multipass_dfa_lookahead
10252
10253 #undef TARGET_HAVE_TLS
10254 #define TARGET_HAVE_TLS HAVE_AS_TLS
10255
10256 #undef  TARGET_INIT_BUILTINS
10257 #define TARGET_INIT_BUILTINS alpha_init_builtins
10258 #undef  TARGET_EXPAND_BUILTIN
10259 #define TARGET_EXPAND_BUILTIN alpha_expand_builtin
10260
10261 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
10262 #define TARGET_FUNCTION_OK_FOR_SIBCALL alpha_function_ok_for_sibcall
10263 #undef TARGET_CANNOT_COPY_INSN_P
10264 #define TARGET_CANNOT_COPY_INSN_P alpha_cannot_copy_insn_p
10265 #undef TARGET_CANNOT_FORCE_CONST_MEM
10266 #define TARGET_CANNOT_FORCE_CONST_MEM alpha_cannot_force_const_mem
10267
10268 #if TARGET_ABI_OSF
10269 #undef TARGET_ASM_OUTPUT_MI_THUNK
10270 #define TARGET_ASM_OUTPUT_MI_THUNK alpha_output_mi_thunk_osf
10271 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
10272 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
10273 #endif
10274
10275 #undef TARGET_RTX_COSTS
10276 #define TARGET_RTX_COSTS alpha_rtx_costs
10277 #undef TARGET_ADDRESS_COST
10278 #define TARGET_ADDRESS_COST hook_int_rtx_0
10279
10280 #undef TARGET_MACHINE_DEPENDENT_REORG
10281 #define TARGET_MACHINE_DEPENDENT_REORG alpha_reorg
10282
10283 #undef TARGET_PROMOTE_FUNCTION_ARGS
10284 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
10285 #undef TARGET_PROMOTE_FUNCTION_RETURN
10286 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
10287 #undef TARGET_PROMOTE_PROTOTYPES
10288 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_false
10289 #undef TARGET_STRUCT_VALUE_RTX
10290 #define TARGET_STRUCT_VALUE_RTX hook_rtx_tree_int_null
10291 #undef TARGET_RETURN_IN_MEMORY
10292 #define TARGET_RETURN_IN_MEMORY alpha_return_in_memory
10293 #undef TARGET_SETUP_INCOMING_VARARGS
10294 #define TARGET_SETUP_INCOMING_VARARGS alpha_setup_incoming_varargs
10295 #undef TARGET_STRICT_ARGUMENT_NAMING
10296 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
10297 #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
10298 #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
10299 #undef TARGET_SPLIT_COMPLEX_ARG
10300 #define TARGET_SPLIT_COMPLEX_ARG alpha_split_complex_arg
10301
10302 #undef TARGET_BUILD_BUILTIN_VA_LIST
10303 #define TARGET_BUILD_BUILTIN_VA_LIST alpha_build_builtin_va_list
10304
10305 struct gcc_target targetm = TARGET_INITIALIZER;
10306
10307 \f
10308 #include "gt-alpha.h"