OSDN Git Service

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