This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / gcc / config / alpha / alpha.c
blobbf39eec28a96685093bf306f793faec8a5ea3e74
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)
6 This file is part of GCC.
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.
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.
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. */
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"
56 /* Specify which cpu to schedule for. */
58 enum processor_type alpha_cpu;
59 static const char * const alpha_cpu_name[] =
61 "ev4", "ev5", "ev6"
64 /* Specify how accurate floating-point traps need to be. */
66 enum alpha_trap_precision alpha_tp;
68 /* Specify the floating-point rounding mode. */
70 enum alpha_fp_rounding_mode alpha_fprm;
72 /* Specify which things cause traps. */
74 enum alpha_fp_trap_mode alpha_fptm;
76 /* Specify bit size of immediate TLS offsets. */
78 int alpha_tls_size = 32;
80 /* Strings decoded into the above options. */
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] */
90 /* Save information from a "cmpxx" operation until the branch or scc is
91 emitted. */
93 struct alpha_compare alpha_compare;
95 /* Nonzero if inside of a function, because the Alpha asm can't
96 handle .files inside of functions. */
98 static int inside_function = FALSE;
100 /* The number of cycles of latency we should assume on memory reads. */
102 int alpha_memory_latency = 3;
104 /* Whether the function needs the GP. */
106 static int alpha_function_needs_gp;
108 /* The alias set for prologue/epilogue register save/restore. */
110 static GTY(()) int alpha_sr_alias_set;
112 /* The assembler name of the current function. */
114 static const char *alpha_fnname;
116 /* The next explicit relocation sequence number. */
117 extern GTY(()) int alpha_next_sequence_number;
118 int alpha_next_sequence_number = 1;
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;
127 /* Costs of various operations on the different architectures. */
129 struct alpha_rtx_cost_data
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;
141 static struct alpha_rtx_cost_data const alpha_rtx_cost_data[PROCESSOR_MAX] =
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 */
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 */
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 */
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
182 #define REG_PV 27
183 #define REG_RA 26
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);
189 #if TARGET_ABI_OPEN_VMS
190 static void alpha_write_linkage (FILE *, const char *, tree);
191 #endif
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);
198 /* Parse target option strings. */
200 void
201 override_options (void)
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 }
228 /* Unicos/Mk doesn't have shared libraries. */
229 if (TARGET_ABI_UNICOSMK && flag_pic)
231 warning ("-f%s ignored for Unicos/Mk (not supported)",
232 (flag_pic > 1) ? "PIC" : "pic");
233 flag_pic = 0;
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;
243 alpha_tp = ALPHA_TP_PROG;
244 alpha_fptm = ALPHA_FPTM_N;
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. */
252 if (TARGET_IEEE)
254 if (TARGET_ABI_UNICOSMK)
255 warning ("-mieee not supported on Unicos/Mk");
256 else
258 alpha_tp = ALPHA_TP_INSN;
259 alpha_fptm = ALPHA_FPTM_SU;
263 if (TARGET_IEEE_WITH_INEXACT)
265 if (TARGET_ABI_UNICOSMK)
266 warning ("-mieee-with-inexact not supported on Unicos/Mk");
267 else
269 alpha_tp = ALPHA_TP_INSN;
270 alpha_fptm = ALPHA_FPTM_SUI;
274 if (alpha_tp_string)
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);
286 if (alpha_fprm_string)
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);
301 if (alpha_fptm_string)
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);
315 if (alpha_tls_size_string)
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);
327 alpha_cpu
328 = TARGET_CPU_DEFAULT & MASK_CPU_EV6 ? PROCESSOR_EV6
329 : (TARGET_CPU_DEFAULT & MASK_CPU_EV5 ? PROCESSOR_EV5 : PROCESSOR_EV4);
331 if (alpha_cpu_string)
333 for (i = 0; cpu_table [i].name; i++)
334 if (! strcmp (alpha_cpu_string, cpu_table [i].name))
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;
342 if (! cpu_table [i].name)
343 error ("bad value `%s' for -mcpu switch", alpha_cpu_string);
346 if (alpha_tune_string)
348 for (i = 0; cpu_table [i].name; i++)
349 if (! strcmp (alpha_tune_string, cpu_table [i].name))
351 alpha_cpu = cpu_table [i].processor;
352 break;
354 if (! cpu_table [i].name)
355 error ("bad value `%s' for -mcpu switch", alpha_tune_string);
358 /* Do some sanity checks on the above options. */
360 if (TARGET_ABI_UNICOSMK && alpha_fptm != ALPHA_FPTM_N)
362 warning ("trap mode not supported on Unicos/Mk");
363 alpha_fptm = ALPHA_FPTM_N;
366 if ((alpha_fptm == ALPHA_FPTM_SU || alpha_fptm == ALPHA_FPTM_SUI)
367 && alpha_tp != ALPHA_TP_INSN && ! TARGET_CPU_EV6)
369 warning ("fp software completion requires -mtrap-precision=i");
370 alpha_tp = ALPHA_TP_INSN;
373 if (TARGET_CPU_EV6)
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;
381 if (TARGET_FLOAT_VAX)
383 if (alpha_fprm == ALPHA_FPRM_MINF || alpha_fprm == ALPHA_FPRM_DYN)
385 warning ("rounding mode not supported for VAX floats");
386 alpha_fprm = ALPHA_FPRM_NORM;
388 if (alpha_fptm == ALPHA_FPTM_SUI)
390 warning ("trap mode not supported for VAX floats");
391 alpha_fptm = ALPHA_FPTM_SU;
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;
399 char *end;
400 int lat;
402 if (!alpha_mlat_string)
403 alpha_mlat_string = "L1";
405 if (ISDIGIT ((unsigned char)alpha_mlat_string[0])
406 && (lat = strtol (alpha_mlat_string, &end, 10), *end == '\0'))
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')
412 static int const cache_latency[][4] =
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. */
419 lat = alpha_mlat_string[1] - '0';
420 if (lat <= 0 || lat > 3 || cache_latency[alpha_cpu][lat-1] == -1)
422 warning ("L%d cache latency unknown for %s",
423 lat, alpha_cpu_name[alpha_cpu]);
424 lat = 3;
426 else
427 lat = cache_latency[alpha_cpu][lat-1];
429 else if (! strcmp (alpha_mlat_string, "main"))
431 /* Most current memories have about 370ns latency. This is
432 a reasonable guess for a fast cpu. */
433 lat = 150;
435 else
437 warning ("bad value `%s' for -mmemory-latency", alpha_mlat_string);
438 lat = 3;
441 alpha_memory_latency = lat;
444 /* Default the definition of "small data" to 8 bytes. */
445 if (!g_switch_set)
446 g_switch_value = 8;
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;
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)
459 if (align_loops <= 0)
460 align_loops = 16;
461 if (align_jumps <= 0)
462 align_jumps = 16;
464 if (align_functions <= 0)
465 align_functions = 16;
467 /* Acquire a unique set number for our register saves and restores. */
468 alpha_sr_alias_set = new_alias_set ();
470 /* Register variables and functions with the garbage collector. */
472 /* Set up function hooks. */
473 init_machine_status = alpha_init_machine_status;
475 /* Tell the compiler when we're using VAX floating point. */
476 if (TARGET_FLOAT_VAX)
478 REAL_MODE_FORMAT (SFmode) = &vax_f_format;
479 REAL_MODE_FORMAT (DFmode) = &vax_g_format;
480 REAL_MODE_FORMAT (TFmode) = NULL;
484 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones. */
487 zap_mask (HOST_WIDE_INT value)
489 int i;
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;
496 return 1;
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. */
503 reg_or_0_operand (rtx op, enum machine_mode mode)
505 return op == CONST0_RTX (mode) || register_operand (op, mode);
508 /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
509 any register. */
512 reg_or_6bit_operand (rtx op, enum machine_mode mode)
514 return ((GET_CODE (op) == CONST_INT
515 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
516 || register_operand (op, mode));
520 /* Return 1 if OP is an 8-bit constant or any register. */
523 reg_or_8bit_operand (rtx op, enum machine_mode mode)
525 return ((GET_CODE (op) == CONST_INT
526 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
527 || register_operand (op, mode));
530 /* Return 1 if OP is a constant or any register. */
533 reg_or_const_int_operand (rtx op, enum machine_mode mode)
535 return GET_CODE (op) == CONST_INT || register_operand (op, mode);
538 /* Return 1 if OP is an 8-bit constant. */
541 cint8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
543 return ((GET_CODE (op) == CONST_INT
544 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100));
547 /* Return 1 if the operand is a valid second operand to an add insn. */
550 add_operand (rtx op, enum machine_mode mode)
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'));
557 return register_operand (op, mode);
560 /* Return 1 if the operand is a valid second operand to a sign-extending
561 add insn. */
564 sext_add_operand (rtx op, enum machine_mode mode)
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'));
570 return reg_not_elim_operand (op, mode);
573 /* Return 1 if OP is the constant 4 or 8. */
576 const48_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
578 return (GET_CODE (op) == CONST_INT
579 && (INTVAL (op) == 4 || INTVAL (op) == 8));
582 /* Return 1 if OP is a valid first operand to an AND insn. */
585 and_operand (rtx op, enum machine_mode mode)
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)));
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)));
596 return register_operand (op, mode);
599 /* Return 1 if OP is a valid first operand to an IOR or XOR insn. */
602 or_operand (rtx op, enum machine_mode mode)
604 if (GET_CODE (op) == CONST_INT)
605 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
606 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
608 return register_operand (op, mode);
611 /* Return 1 if OP is a constant that is the width, in bits, of an integral
612 mode smaller than DImode. */
615 mode_width_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
617 return (GET_CODE (op) == CONST_INT
618 && (INTVAL (op) == 8 || INTVAL (op) == 16
619 || INTVAL (op) == 32 || INTVAL (op) == 64));
622 /* Return 1 if OP is a constant that is the width of an integral machine mode
623 smaller than an integer. */
626 mode_mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
628 if (GET_CODE (op) == CONST_INT)
630 HOST_WIDE_INT value = INTVAL (op);
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;
641 else if (HOST_BITS_PER_WIDE_INT == 32 && GET_CODE (op) == CONST_DOUBLE)
643 if (CONST_DOUBLE_LOW (op) == 0xffffffff && CONST_DOUBLE_HIGH (op) == 0)
644 return 1;
647 return 0;
650 /* Return 1 if OP is a multiple of 8 less than 64. */
653 mul8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
655 return (GET_CODE (op) == CONST_INT
656 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
657 && (INTVAL (op) & 7) == 0);
660 /* Return 1 if OP is the zero constant for MODE. */
663 const0_operand (rtx op, enum machine_mode mode)
665 return op == CONST0_RTX (mode);
668 /* Return 1 if OP is a hard floating-point register. */
671 hard_fp_register_operand (rtx op, enum machine_mode mode)
673 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
674 return 0;
676 if (GET_CODE (op) == SUBREG)
677 op = SUBREG_REG (op);
678 return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == FLOAT_REGS;
681 /* Return 1 if OP is a hard general register. */
684 hard_int_register_operand (rtx op, enum machine_mode mode)
686 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
687 return 0;
689 if (GET_CODE (op) == SUBREG)
690 op = SUBREG_REG (op);
691 return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS;
694 /* Return 1 if OP is a register or a constant integer. */
698 reg_or_cint_operand (rtx op, enum machine_mode mode)
700 return (GET_CODE (op) == CONST_INT
701 || register_operand (op, mode));
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. */
708 some_operand (rtx op, enum machine_mode mode)
710 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
711 return 0;
713 switch (GET_CODE (op))
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;
726 case SUBREG:
727 return some_operand (SUBREG_REG (op), VOIDmode);
729 default:
730 break;
733 return 0;
736 /* Likewise, but don't accept constants. */
739 some_ni_operand (rtx op, enum machine_mode mode)
741 if (GET_MODE (op) != mode && mode != VOIDmode)
742 return 0;
744 if (GET_CODE (op) == SUBREG)
745 op = SUBREG_REG (op);
747 return (GET_CODE (op) == REG || GET_CODE (op) == MEM);
750 /* Return 1 if OP is a valid operand for the source of a move insn. */
753 input_operand (rtx op, enum machine_mode mode)
755 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
756 return 0;
758 if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
759 return 0;
761 switch (GET_CODE (op))
763 case LABEL_REF:
764 case SYMBOL_REF:
765 case CONST:
766 if (TARGET_EXPLICIT_RELOCS)
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));
778 /* This handles both the Windows/NT and OSF cases. */
779 return mode == ptr_mode || mode == DImode;
781 case HIGH:
782 return (TARGET_EXPLICIT_RELOCS
783 && local_symbolic_operand (XEXP (op, 0), mode));
785 case REG:
786 case ADDRESSOF:
787 return 1;
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));
797 case CONST_DOUBLE:
798 case CONST_VECTOR:
799 return op == CONST0_RTX (mode);
801 case CONST_INT:
802 return mode == QImode || mode == HImode || add_operand (op, mode);
804 case CONSTANT_P_RTX:
805 return 1;
807 default:
808 break;
811 return 0;
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. */
818 samegp_function_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
820 if (GET_CODE (op) != SYMBOL_REF)
821 return false;
823 /* Easy test for recursion. */
824 if (op == XEXP (DECL_RTL (current_function_decl), 0))
825 return true;
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;
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;
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);
844 /* Return 1 if OP is a SYMBOL_REF for which we can make a call via bsr. */
847 direct_call_operand (rtx op, enum machine_mode mode)
849 tree op_decl, cfun_sec, op_sec;
851 /* Must share the same GP. */
852 if (!samegp_function_operand (op, mode))
853 return false;
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;
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;
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;
878 /* Otherwise, a decl is "near" if it is defined in the same section. */
879 if (flag_function_sections)
880 return false;
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;
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));
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. */
899 local_symbolic_operand (rtx op, enum machine_mode mode)
901 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
902 return 0;
904 if (GET_CODE (op) == LABEL_REF)
905 return 1;
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);
912 if (GET_CODE (op) != SYMBOL_REF)
913 return 0;
915 return SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
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. */
922 small_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
924 if (! TARGET_SMALL_DATA)
925 return 0;
927 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
928 return 0;
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);
935 if (GET_CODE (op) != SYMBOL_REF)
936 return 0;
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;
943 return (SYMBOL_REF_LOCAL_P (op)
944 && SYMBOL_REF_SMALL_P (op)
945 && SYMBOL_REF_TLS_MODEL (op) == 0);
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. */
952 global_symbolic_operand (rtx op, enum machine_mode mode)
954 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
955 return 0;
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);
962 if (GET_CODE (op) != SYMBOL_REF)
963 return 0;
965 return !SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
968 /* Return 1 if OP is a valid operand for the MEM of a CALL insn. */
971 call_operand (rtx op, enum machine_mode mode)
973 if (mode != Pmode)
974 return 0;
976 if (GET_CODE (op) == REG)
978 if (TARGET_ABI_OSF)
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);
985 else
986 return 1;
988 if (TARGET_ABI_UNICOSMK)
989 return 0;
990 if (GET_CODE (op) == SYMBOL_REF)
991 return 1;
993 return 0;
996 /* Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
997 possibly with an offset. */
1000 symbolic_operand (rtx op, enum machine_mode mode)
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;
1014 /* Return true if OP is valid for a particular TLS relocation. */
1016 static int
1017 tls_symbolic_operand_1 (rtx op, enum machine_mode mode, int size, int unspec)
1019 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1020 return 0;
1022 if (GET_CODE (op) != CONST)
1023 return 0;
1024 op = XEXP (op, 0);
1026 if (GET_CODE (op) != UNSPEC || XINT (op, 1) != unspec)
1027 return 0;
1028 op = XVECEXP (op, 0, 0);
1030 if (GET_CODE (op) != SYMBOL_REF)
1031 return 0;
1033 if (SYMBOL_REF_LOCAL_P (op))
1035 if (alpha_tls_size > size)
1036 return 0;
1038 else
1040 if (size != 64)
1041 return 0;
1044 switch (SYMBOL_REF_TLS_MODEL (op))
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 ();
1057 /* Return true if OP is valid for 16-bit DTP relative relocations. */
1060 dtp16_symbolic_operand (rtx op, enum machine_mode mode)
1062 return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_DTPREL);
1065 /* Return true if OP is valid for 32-bit DTP relative relocations. */
1068 dtp32_symbolic_operand (rtx op, enum machine_mode mode)
1070 return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_DTPREL);
1073 /* Return true if OP is valid for 64-bit DTP relative relocations. */
1076 gotdtp_symbolic_operand (rtx op, enum machine_mode mode)
1078 return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_DTPREL);
1081 /* Return true if OP is valid for 16-bit TP relative relocations. */
1084 tp16_symbolic_operand (rtx op, enum machine_mode mode)
1086 return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_TPREL);
1089 /* Return true if OP is valid for 32-bit TP relative relocations. */
1092 tp32_symbolic_operand (rtx op, enum machine_mode mode)
1094 return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_TPREL);
1097 /* Return true if OP is valid for 64-bit TP relative relocations. */
1100 gottp_symbolic_operand (rtx op, enum machine_mode mode)
1102 return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_TPREL);
1105 /* Return 1 if OP is a valid Alpha comparison operator. Here we know which
1106 comparisons are valid in which insn. */
1109 alpha_comparison_operator (rtx op, enum machine_mode mode)
1111 enum rtx_code code = GET_CODE (op);
1113 if (mode != GET_MODE (op) && mode != VOIDmode)
1114 return 0;
1116 return (code == EQ || code == LE || code == LT
1117 || code == LEU || code == LTU);
1120 /* Return 1 if OP is a valid Alpha comparison operator against zero.
1121 Here we know which comparisons are valid in which insn. */
1124 alpha_zero_comparison_operator (rtx op, enum machine_mode mode)
1126 enum rtx_code code = GET_CODE (op);
1128 if (mode != GET_MODE (op) && mode != VOIDmode)
1129 return 0;
1131 return (code == EQ || code == NE || code == LE || code == LT
1132 || code == LEU || code == LTU);
1135 /* Return 1 if OP is a valid Alpha swapped comparison operator. */
1138 alpha_swapped_comparison_operator (rtx op, enum machine_mode mode)
1140 enum rtx_code code = GET_CODE (op);
1142 if ((mode != GET_MODE (op) && mode != VOIDmode)
1143 || GET_RTX_CLASS (code) != '<')
1144 return 0;
1146 code = swap_condition (code);
1147 return (code == EQ || code == LE || code == LT
1148 || code == LEU || code == LTU);
1151 /* Return 1 if OP is a signed comparison operation. */
1154 signed_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1156 enum rtx_code code = GET_CODE (op);
1158 if (mode != GET_MODE (op) && mode != VOIDmode)
1159 return 0;
1161 return (code == EQ || code == NE
1162 || code == LE || code == LT
1163 || code == GE || code == GT);
1166 /* Return 1 if OP is a valid Alpha floating point comparison operator.
1167 Here we know which comparisons are valid in which insn. */
1170 alpha_fp_comparison_operator (rtx op, enum machine_mode mode)
1172 enum rtx_code code = GET_CODE (op);
1174 if (mode != GET_MODE (op) && mode != VOIDmode)
1175 return 0;
1177 return (code == EQ || code == LE || code == LT || code == UNORDERED);
1180 /* Return 1 if this is a divide or modulus operator. */
1183 divmod_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1185 enum rtx_code code = GET_CODE (op);
1187 return (code == DIV || code == MOD || code == UDIV || code == UMOD);
1190 /* Return 1 if this is a float->int conversion operator. */
1193 fix_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1195 enum rtx_code code = GET_CODE (op);
1197 return (code == FIX || code == UNSIGNED_FIX);
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.
1204 Take into account what reload will do. */
1207 aligned_memory_operand (rtx op, enum machine_mode mode)
1209 rtx base;
1211 if (reload_in_progress)
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)
1219 op = reg_equiv_memory_loc[REGNO (tmp)];
1220 if (op == 0)
1221 return 0;
1225 if (GET_CODE (op) != MEM)
1226 return 0;
1227 if (MEM_ALIGN (op) >= 32)
1228 return 1;
1229 op = XEXP (op, 0);
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
1239 if (! memory_address_p (mode, op))
1240 return 0;
1241 base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1244 return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) >= 32);
1247 /* Similar, but return 1 if OP is a MEM which is not alignable. */
1250 unaligned_memory_operand (rtx op, enum machine_mode mode)
1252 rtx base;
1254 if (reload_in_progress)
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)
1262 op = reg_equiv_memory_loc[REGNO (tmp)];
1263 if (op == 0)
1264 return 0;
1268 if (GET_CODE (op) != MEM)
1269 return 0;
1270 if (MEM_ALIGN (op) >= 32)
1271 return 0;
1272 op = XEXP (op, 0);
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
1282 if (! memory_address_p (mode, op))
1283 return 0;
1284 base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1287 return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) < 32);
1290 /* Return 1 if OP is either a register or an unaligned memory location. */
1293 reg_or_unaligned_mem_operand (rtx op, enum machine_mode mode)
1295 return register_operand (op, mode) || unaligned_memory_operand (op, mode);
1298 /* Return 1 if OP is any memory location. During reload a pseudo matches. */
1301 any_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
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));
1312 /* Returns 1 if OP is not an eliminable register.
1314 This exists to cure a pathological abort in the s8addq (et al) patterns,
1316 long foo () { long t; bar(); return (long) &t * 26107; }
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. */
1324 reg_not_elim_operand (rtx op, enum machine_mode mode)
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;
1332 return register_operand (op, mode);
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. */
1340 normal_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1342 if (reload_in_progress)
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)
1350 op = reg_equiv_memory_loc[REGNO (tmp)];
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;
1359 return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) != AND;
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. */
1367 reg_no_subreg_operand (rtx op, enum machine_mode mode)
1369 if (GET_CODE (op) != REG)
1370 return 0;
1371 return register_operand (op, mode);
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. */
1379 addition_operation (rtx op, enum machine_mode mode)
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;
1391 /* Implements CONST_OK_FOR_LETTER_P. Return true if the value matches
1392 the range defined for C in [I-P]. */
1394 bool
1395 alpha_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
1397 switch (c)
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;
1425 default:
1426 return false;
1430 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE
1431 matches for C in [GH]. */
1433 bool
1434 alpha_const_double_ok_for_letter_p (rtx value, int c)
1436 switch (c)
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)));
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)));
1449 default:
1450 return false;
1454 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE
1455 matches for C. */
1457 bool
1458 alpha_extra_constraint (rtx value, int c)
1460 switch (c)
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;
1481 /* Return 1 if this function can directly return via $26. */
1484 direct_return (void)
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);
1494 /* Return the ADDR_VEC associated with a tablejump insn. */
1497 alpha_tablejump_addr_vec (rtx insn)
1499 rtx tmp;
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;
1513 /* Return the label of the predicted edge, or CONST0_RTX if we don't know. */
1516 alpha_tablejump_best_label (rtx insn)
1518 rtx jump_table = alpha_tablejump_addr_vec (insn);
1519 rtx best_label = NULL_RTX;
1521 /* ??? Once the CFG doesn't keep getting completely rebuilt, look
1522 there for edge frequency counts from profile data. */
1524 if (jump_table)
1526 int n_labels = XVECLEN (jump_table, 1);
1527 int best_count = -1;
1528 int i, j;
1530 for (i = 0; i < n_labels; i++)
1532 int count = 1;
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++;
1539 if (count > best_count)
1540 best_count = count, best_label = XVECEXP (jump_table, 1, i);
1544 return best_label ? best_label : const0_rtx;
1547 /* Return the TLS model to use for SYMBOL. */
1549 static enum tls_model
1550 tls_symbolic_operand_type (rtx symbol)
1552 enum tls_model model;
1554 if (GET_CODE (symbol) != SYMBOL_REF)
1555 return 0;
1556 model = SYMBOL_REF_TLS_MODEL (symbol);
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;
1562 return model;
1565 /* Return true if the function DECL will share the same GP as any
1566 function in the current unit of translation. */
1568 static bool
1569 decl_has_samegp (tree decl)
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;
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;
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);
1589 /* Return true if EXP should be placed in the small data section. */
1591 static bool
1592 alpha_in_small_data_p (tree exp)
1594 /* We want to merge strings, so we never consider them small data. */
1595 if (TREE_CODE (exp) == STRING_CST)
1596 return false;
1598 /* Functions are never in the small data area. Duh. */
1599 if (TREE_CODE (exp) == FUNCTION_DECL)
1600 return false;
1602 if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
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;
1609 else
1611 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
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;
1619 return false;
1622 #if TARGET_ABI_OPEN_VMS
1623 static bool
1624 alpha_linkage_symbol_p (const char *symname)
1626 int symlen = strlen (symname);
1628 if (symlen > 4)
1629 return strcmp (&symname [symlen - 4], "..lk") == 0;
1631 return false;
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
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.
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. */
1652 bool
1653 alpha_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
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);
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);
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;
1675 /* Constant addresses (i.e. +/- 32k) are valid. */
1676 if (CONSTANT_ADDRESS_P (x))
1677 return true;
1679 #if TARGET_ABI_OPEN_VMS
1680 if (LINKAGE_SYMBOL_REF_P (x))
1681 return true;
1682 #endif
1684 /* Register plus a small constant offset is valid. */
1685 if (GET_CODE (x) == PLUS)
1687 rtx ofs = XEXP (x, 1);
1688 x = XEXP (x, 0);
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);
1696 if (REG_P (x))
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;
1708 else if (GET_CODE (x) == ADDRESSOF
1709 && GET_CODE (ofs) == CONST_INT)
1710 return true;
1713 /* If we're managing explicit relocations, LO_SUM is valid, as
1714 are small data symbols. */
1715 else if (TARGET_EXPLICIT_RELOCS)
1717 if (small_symbolic_operand (x, Pmode))
1718 return true;
1720 if (GET_CODE (x) == LO_SUM)
1722 rtx ofs = XEXP (x, 1);
1723 x = XEXP (x, 0);
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);
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;
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;
1746 return false;
1749 /* Build the SYMBOL_REF for __tls_get_addr. */
1751 static GTY(()) rtx tls_get_addr_libfunc;
1753 static rtx
1754 get_tls_get_addr (void)
1756 if (!tls_get_addr_libfunc)
1757 tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr");
1758 return tls_get_addr_libfunc;
1761 /* Try machine-dependent ways of modifying an illegitimate address
1762 to be legitimate. If we find one, return the new, valid address. */
1765 alpha_legitimize_address (rtx x, rtx scratch,
1766 enum machine_mode mode ATTRIBUTE_UNUSED)
1768 HOST_WIDE_INT addend;
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)))
1778 addend = INTVAL (XEXP (x, 1));
1779 x = XEXP (x, 0);
1780 goto split_addend;
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)
1792 addend = INTVAL (XEXP (XEXP (x, 0), 1));
1793 x = force_reg (Pmode, XEXP (XEXP (x, 0), 0));
1794 goto split_addend;
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)
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;
1814 /* If this is a local symbol, split the address into HIGH/LO_SUM parts. */
1815 if (TARGET_EXPLICIT_RELOCS && symbolic_operand (x, Pmode))
1817 rtx r0, r16, eqv, tga, tp, insn, dest, seq;
1819 switch (tls_symbolic_operand_type (x))
1821 case TLS_MODEL_GLOBAL_DYNAMIC:
1822 start_sequence ();
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++);
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);
1836 insn = get_insns ();
1837 end_sequence ();
1839 emit_libcall_block (insn, dest, r0, x);
1840 return dest;
1842 case TLS_MODEL_LOCAL_DYNAMIC:
1843 start_sequence ();
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++);
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);
1857 insn = get_insns ();
1858 end_sequence ();
1860 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
1861 UNSPEC_TLSLDM_CALL);
1862 emit_libcall_block (insn, scratch, r0, eqv);
1864 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPREL);
1865 eqv = gen_rtx_CONST (Pmode, eqv);
1867 if (alpha_tls_size == 64)
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;
1874 if (alpha_tls_size == 32)
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));
1881 return gen_rtx_LO_SUM (Pmode, scratch, eqv);
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);
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;
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);
1900 emit_insn (gen_load_tp (tp));
1901 if (alpha_tls_size == 32)
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));
1908 return gen_rtx_LO_SUM (Pmode, tp, eqv);
1911 if (local_symbolic_operand (x, Pmode))
1913 if (small_symbolic_operand (x, Pmode))
1914 return x;
1915 else
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);
1926 return NULL;
1928 split_addend:
1930 HOST_WIDE_INT low, high;
1932 low = ((addend & 0xffff) ^ 0x8000) - 0x8000;
1933 addend -= low;
1934 high = ((addend & 0xffffffff) ^ 0x80000000) - 0x80000000;
1935 addend -= high;
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);
1946 return plus_constant (x, low);
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. */
1954 static bool
1955 alpha_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
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;
1962 /* Otherwise, we can make a tail call if the target function shares
1963 the same GP. */
1964 return decl_has_samegp (decl);
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. */
1972 static int
1973 some_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
1975 rtx x = *px;
1977 /* Don't re-split. */
1978 if (GET_CODE (x) == LO_SUM)
1979 return -1;
1981 return small_symbolic_operand (x, Pmode) != 0;
1985 some_small_symbolic_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1987 return for_each_rtx (&x, some_small_symbolic_operand_1, NULL);
1990 static int
1991 split_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
1993 rtx x = *px;
1995 /* Don't re-split. */
1996 if (GET_CODE (x) == LO_SUM)
1997 return -1;
1999 if (small_symbolic_operand (x, Pmode))
2001 x = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, x);
2002 *px = x;
2003 return -1;
2006 return 0;
2010 split_small_symbolic_operand (rtx x)
2012 x = copy_insn (x);
2013 for_each_rtx (&x, split_small_symbolic_operand_1, NULL);
2014 return x;
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.
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.
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. */
2031 static bool
2032 alpha_cannot_copy_insn_p (rtx insn)
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;
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. */
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)
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)
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;
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)
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;
2079 /* Check for 32-bit overflow. */
2080 if (high + low != val)
2081 return NULL_RTX;
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));
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;
2096 return NULL_RTX;
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. */
2103 static bool
2104 alpha_rtx_costs (rtx x, int code, int outer_code, int *total)
2106 enum machine_mode mode = GET_MODE (x);
2107 bool float_mode_p = FLOAT_MODE_P (mode);
2109 switch (code)
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)
2119 *total = 0;
2120 return true;
2122 /* FALLTHRU */
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;
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;
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))
2158 *total = (rtx_cost (XEXP (XEXP (x, 0), 0), outer_code)
2159 + rtx_cost (XEXP (x, 1), outer_code) + 2);
2160 return true;
2162 return false;
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;
2173 case ASHIFT:
2174 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2175 && INTVAL (XEXP (x, 1)) <= 3)
2177 *total = COSTS_N_INSNS (1);
2178 return false;
2180 /* FALLTHRU */
2182 case ASHIFTRT:
2183 case LSHIFTRT:
2184 *total = alpha_rtx_cost_data[alpha_cpu].int_shift;
2185 return false;
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;
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;
2206 case MEM:
2207 *total = COSTS_N_INSNS (alpha_memory_latency);
2208 return true;
2210 case NEG:
2211 if (! float_mode_p)
2213 *total = COSTS_N_INSNS (1);
2214 return false;
2216 /* FALLTHRU */
2218 case ABS:
2219 if (! float_mode_p)
2221 *total = COSTS_N_INSNS (1) + alpha_rtx_cost_data[alpha_cpu].int_cmov;
2222 return false;
2224 /* FALLTHRU */
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;
2235 default:
2236 return false;
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. */
2245 void
2246 get_aligned_mem (rtx ref, rtx *paligned_mem, rtx *pbitnum)
2248 rtx base;
2249 HOST_WIDE_INT offset = 0;
2251 if (GET_CODE (ref) != MEM)
2252 abort ();
2254 if (reload_in_progress
2255 && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2257 base = find_replacement (&XEXP (ref, 0));
2259 if (! memory_address_p (GET_MODE (ref), base))
2260 abort ();
2262 else
2264 base = XEXP (ref, 0);
2267 if (GET_CODE (base) == PLUS)
2268 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2270 *paligned_mem
2271 = widen_memory_access (ref, SImode, (offset & ~3) - offset);
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);
2280 /* Similar, but just get the address. Handle the two reload cases.
2281 Add EXTRA_OFFSET to the address we return. */
2284 get_unaligned_address (rtx ref, int extra_offset)
2286 rtx base;
2287 HOST_WIDE_INT offset = 0;
2289 if (GET_CODE (ref) != MEM)
2290 abort ();
2292 if (reload_in_progress
2293 && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2295 base = find_replacement (&XEXP (ref, 0));
2297 if (! memory_address_p (GET_MODE (ref), base))
2298 abort ();
2300 else
2302 base = XEXP (ref, 0);
2305 if (GET_CODE (base) == PLUS)
2306 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2308 return plus_constant (base, offset + extra_offset);
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. */
2316 enum reg_class
2317 alpha_preferred_reload_class(rtx x, enum reg_class class)
2319 /* Zero is present in any register class. */
2320 if (x == CONST0_RTX (GET_MODE (x)))
2321 return class;
2323 /* These sorts of constants we can easily drop to memory. */
2324 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
2326 if (class == FLOAT_REGS)
2327 return NO_REGS;
2328 if (class == ALL_REGS)
2329 return GENERAL_REGS;
2330 return class;
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);
2339 return class;
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.
2347 We also cannot load an unaligned address or a paradoxical SUBREG
2348 into an FP register.
2350 We also cannot do integral arithmetic into FP regs, as might result
2351 from register elimination into a DImode fp register. */
2353 enum reg_class
2354 secondary_reload_class (enum reg_class class, enum machine_mode mode,
2355 rtx x, int in)
2357 if ((mode == QImode || mode == HImode) && ! TARGET_BWX)
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))))
2366 if (!in || !aligned_memory_operand(x, mode))
2367 return GENERAL_REGS;
2371 if (class == FLOAT_REGS)
2373 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
2374 return GENERAL_REGS;
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;
2381 if (in && INTEGRAL_MODE_P (mode)
2382 && ! (memory_operand (x, mode) || x == const0_rtx))
2383 return GENERAL_REGS;
2386 return NO_REGS;
2389 /* Subfunction of the following function. Update the flags of any MEM
2390 found in part of X. */
2392 static void
2393 alpha_set_memflags_1 (rtx x, int in_struct_p, int volatile_p, int unchanging_p)
2395 int i;
2397 switch (GET_CODE (x))
2399 case SEQUENCE:
2400 abort ();
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;
2408 case INSN:
2409 alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
2410 unchanging_p);
2411 break;
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;
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;
2431 default:
2432 break;
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. */
2442 void
2443 alpha_set_memflags (rtx insn, rtx ref)
2445 int in_struct_p, volatile_p, unchanging_p;
2447 if (GET_CODE (ref) != MEM)
2448 return;
2450 in_struct_p = MEM_IN_STRUCT_P (ref);
2451 volatile_p = MEM_VOLATILE_P (ref);
2452 unchanging_p = RTX_UNCHANGING_P (ref);
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;
2460 alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
2463 /* Internal routine for alpha_emit_set_const to check for N or below insns. */
2465 static rtx
2466 alpha_emit_set_const_1 (rtx target, enum machine_mode mode,
2467 HOST_WIDE_INT c, int n)
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;
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. */
2480 if (HOST_BITS_PER_WIDE_INT != 64
2481 || c >> 31 == -1 || c >> 31 == 0)
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;
2488 /* If HIGH will be interpreted as negative but the constant is
2489 positive, we must adjust it to do two ldha insns. */
2491 if ((high & 0x8000) != 0 && c >= 0)
2493 extra = 0x4000;
2494 tmp1 -= 0x40000000;
2495 high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
2498 if (c == low || (low == 0 && extra == 0))
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. */
2506 if (target == NULL)
2507 target = gen_reg_rtx (mode);
2508 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (c)));
2509 return target;
2511 else if (n >= 2 + (extra != 0))
2513 if (no_new_pseudos)
2515 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (high << 16)));
2516 temp = target;
2518 else
2519 temp = copy_to_suggested_reg (GEN_INT (high << 16),
2520 subtarget, mode);
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. */
2528 if (extra != 0)
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;
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;
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. */
2552 if (n == 1 || (mode == SImode && no_new_pseudos))
2553 return 0;
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. */
2559 for (i = 1; i < n; i++)
2561 /* First, see if minus some low bits, we've an easy load of
2562 high bits. */
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);
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);
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. */
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);
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. */
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);
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. */
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);
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. */
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;
2641 /* We are only called for SImode and DImode. If this is SImode, ensure that
2642 we are sign extended to a full word. */
2644 if (mode == SImode)
2645 new = ((new & 0xffffffff) ^ 0x80000000) - 0x80000000;
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
2653 return 0;
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. */
2663 alpha_emit_set_const (rtx target, enum machine_mode mode,
2664 HOST_WIDE_INT c, int n)
2666 rtx result = 0;
2667 rtx orig_target = target;
2668 int i;
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)
2676 target = gen_lowpart (DImode, target);
2677 mode = DImode;
2680 /* Try 1 insn, then 2, then up to N. */
2681 for (i = 1; i <= n; i++)
2683 result = alpha_emit_set_const_1 (target, mode, c, i);
2684 if (result)
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;
2694 /* Allow for the case where we changed the mode of TARGET. */
2695 if (result == target)
2696 result = orig_target;
2698 return result;
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. */
2707 alpha_emit_set_long_const (rtx target, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2709 HOST_WIDE_INT d1, d2, d3, d4;
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
2738 /* Construct the high word */
2739 if (d4)
2741 emit_move_insn (target, GEN_INT (d4));
2742 if (d3)
2743 emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d3)));
2745 else
2746 emit_move_insn (target, GEN_INT (d3));
2748 /* Shift it into place */
2749 emit_move_insn (target, gen_rtx_ASHIFT (DImode, target, GEN_INT (32)));
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)));
2757 return target;
2760 /* Expand a move instruction; return true if all work is done.
2761 We don't handle non-bwx subword loads here. */
2763 bool
2764 alpha_expand_mov (enum machine_mode mode, rtx *operands)
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]);
2771 /* Allow legitimize_address to perform some simplifications. */
2772 if (mode == Pmode && symbolic_operand (operands[1], mode))
2774 rtx tmp;
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.
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))
2789 emit_insn (gen_movdi_er_maybe_g (operands[0], operands[1]));
2790 return true;
2793 tmp = alpha_legitimize_address (operands[1], operands[0], mode);
2794 if (tmp)
2796 if (tmp == operands[0])
2797 return true;
2798 operands[1] = tmp;
2799 return false;
2803 /* Early out for non-constants and valid constants. */
2804 if (! CONSTANT_P (operands[1]) || input_operand (operands[1], mode))
2805 return false;
2807 /* Split large integers. */
2808 if (GET_CODE (operands[1]) == CONST_INT
2809 || GET_CODE (operands[1]) == CONST_DOUBLE)
2811 HOST_WIDE_INT i0, i1;
2812 rtx temp = NULL_RTX;
2814 if (GET_CODE (operands[1]) == CONST_INT)
2816 i0 = INTVAL (operands[1]);
2817 i1 = -(i0 < 0);
2819 else if (HOST_BITS_PER_WIDE_INT >= 64)
2821 i0 = CONST_DOUBLE_LOW (operands[1]);
2822 i1 = -(i0 < 0);
2824 else
2826 i0 = CONST_DOUBLE_LOW (operands[1]);
2827 i1 = CONST_DOUBLE_HIGH (operands[1]);
2830 if (HOST_BITS_PER_WIDE_INT >= 64 || i1 == -(i0 < 0))
2831 temp = alpha_emit_set_const (operands[0], mode, i0, 3);
2833 if (!temp && TARGET_BUILD_CONSTANTS)
2834 temp = alpha_emit_set_long_const (operands[0], i0, i1);
2836 if (temp)
2838 if (rtx_equal_p (operands[0], temp))
2839 return true;
2840 operands[1] = temp;
2841 return false;
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)
2849 emit_move_insn (operands[0], XEXP (operands[1], 0));
2850 operands[1] = copy_rtx (operands[1]);
2851 XEXP (operands[1], 0) = operands[0];
2853 else
2854 operands[1] = validize_mem (operands[1]);
2855 return false;
2858 /* Expand a non-bwx QImode or HImode move instruction;
2859 return true if all work is done. */
2861 bool
2862 alpha_expand_mov_nobwx (enum machine_mode mode, rtx *operands)
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]);
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. */
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))
2881 if (aligned_memory_operand (operands[1], mode))
2883 if (reload_in_progress)
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]))));
2891 else
2893 rtx aligned_mem, bitnum;
2894 rtx scratch = gen_reg_rtx (SImode);
2895 rtx subtarget;
2896 bool copyout;
2898 get_aligned_mem (operands[1], &aligned_mem, &bitnum);
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;
2906 emit_insn ((mode == QImode
2907 ? gen_aligned_loadqi
2908 : gen_aligned_loadhi)
2909 (subtarget, aligned_mem, bitnum, scratch));
2911 if (copyout)
2912 emit_move_insn (operands[0], gen_lowpart (mode, subtarget));
2915 else
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. */
2921 rtx temp1, temp2, seq, subtarget;
2922 bool copyout;
2924 temp1 = gen_reg_rtx (DImode);
2925 temp2 = gen_reg_rtx (DImode);
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;
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);
2941 if (copyout)
2942 emit_move_insn (operands[0], gen_lowpart (mode, subtarget));
2944 return true;
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))
2956 if (aligned_memory_operand (operands[0], mode))
2958 rtx aligned_mem, bitnum;
2959 rtx temp1 = gen_reg_rtx (SImode);
2960 rtx temp2 = gen_reg_rtx (SImode);
2962 get_aligned_mem (operands[0], &aligned_mem, &bitnum);
2964 emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
2965 temp1, temp2));
2967 else
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));
2978 alpha_set_memflags (seq, operands[0]);
2979 emit_insn (seq);
2981 return true;
2984 return false;
2987 /* Generate an unsigned DImode to FP conversion. This is the same code
2988 optabs would emit if we didn't have TFmode patterns.
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:
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
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.
3015 For DFmode, we can avoid rounding errors by breaking up the word
3016 into two pieces, converting them separately, and adding them back:
3018 LC0: .long 0,0x5f800000
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
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. */
3037 void
3038 alpha_emit_floatuns (rtx operands[2])
3040 rtx neglab, donelab, i0, i1, f0, in, out;
3041 enum machine_mode mode;
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);
3052 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
3054 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
3055 emit_jump_insn (gen_jump (donelab));
3056 emit_barrier ();
3058 emit_label (neglab);
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)));
3066 emit_label (donelab);
3069 /* Generate the comparison for a conditional branch. */
3072 alpha_emit_conditional_branch (enum rtx_code code)
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;
3079 if (alpha_compare.fp_p && GET_MODE (op0) == TFmode)
3081 if (! TARGET_HAS_XFLOATING_LIBS)
3082 abort ();
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. */
3090 switch (code)
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;
3110 op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3111 op1 = const0_rtx;
3112 alpha_compare.fp_p = 0;
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)
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;
3125 case NE:
3126 case ORDERED:
3127 /* These must be reversed. */
3128 cmp_code = reverse_condition (code), branch_code = EQ;
3129 break;
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)
3135 cmp_code = swap_condition (code);
3136 branch_code = NE;
3137 tem = op0, op0 = op1, op1 = tem;
3139 else
3141 cmp_code = reverse_condition (code);
3142 branch_code = EQ;
3144 break;
3146 default:
3147 abort ();
3150 if (alpha_compare.fp_p)
3152 cmp_mode = DFmode;
3153 if (flag_unsafe_math_optimizations)
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))
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;
3167 else
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;
3175 else
3177 cmp_mode = DImode;
3179 /* The following optimizations are only for signed compares. */
3180 if (code != LEU && code != LTU && code != GEU && code != GTU)
3182 /* Whee. Compare and branch against 0 directly. */
3183 if (op1 == const0_rtx)
3184 cmp_code = NIL, branch_code = code;
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 else if (GET_CODE (op1) == CONST_INT && (code == EQ || code == NE))
3191 HOST_WIDE_INT v = INTVAL (op1), n = -v;
3193 if (! CONST_OK_FOR_LETTER_P (v, 'I')
3194 && (CONST_OK_FOR_LETTER_P (n, 'K')
3195 || CONST_OK_FOR_LETTER_P (n, 'L')))
3197 cmp_code = PLUS, branch_code = code;
3198 op1 = GEN_INT (n);
3203 if (!reg_or_0_operand (op0, DImode))
3204 op0 = force_reg (DImode, op0);
3205 if (cmp_code != PLUS && !reg_or_8bit_operand (op1, DImode))
3206 op1 = force_reg (DImode, op1);
3209 /* Emit an initial compare instruction, if necessary. */
3210 tem = op0;
3211 if (cmp_code != NIL)
3213 tem = gen_reg_rtx (cmp_mode);
3214 emit_move_insn (tem, gen_rtx_fmt_ee (cmp_code, cmp_mode, op0, op1));
3217 /* Zero the operands. */
3218 memset (&alpha_compare, 0, sizeof (alpha_compare));
3220 /* Return the branch comparison. */
3221 return gen_rtx_fmt_ee (branch_code, branch_mode, tem, CONST0_RTX (cmp_mode));
3224 /* Certain simplifications can be done to make invalid setcc operations
3225 valid. Return the final comparison, or NULL if we can't work. */
3228 alpha_emit_setcc (enum rtx_code code)
3230 enum rtx_code cmp_code;
3231 rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1;
3232 int fp_p = alpha_compare.fp_p;
3233 rtx tmp;
3235 /* Zero the operands. */
3236 memset (&alpha_compare, 0, sizeof (alpha_compare));
3238 if (fp_p && GET_MODE (op0) == TFmode)
3240 if (! TARGET_HAS_XFLOATING_LIBS)
3241 abort ();
3243 /* X_floating library comparison functions return
3244 -1 unordered
3245 0 false
3246 1 true
3247 Convert the compare against the raw return value. */
3249 if (code == UNORDERED || code == ORDERED)
3250 cmp_code = EQ;
3251 else
3252 cmp_code = code;
3254 op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3255 op1 = const0_rtx;
3256 fp_p = 0;
3258 if (code == UNORDERED)
3259 code = LT;
3260 else if (code == ORDERED)
3261 code = GE;
3262 else
3263 code = GT;
3266 if (fp_p && !TARGET_FIX)
3267 return NULL_RTX;
3269 /* The general case: fold the comparison code to the types of compares
3270 that we have, choosing the branch as necessary. */
3272 cmp_code = NIL;
3273 switch (code)
3275 case EQ: case LE: case LT: case LEU: case LTU:
3276 case UNORDERED:
3277 /* We have these compares. */
3278 if (fp_p)
3279 cmp_code = code, code = NE;
3280 break;
3282 case NE:
3283 if (!fp_p && op1 == const0_rtx)
3284 break;
3285 /* FALLTHRU */
3287 case ORDERED:
3288 cmp_code = reverse_condition (code);
3289 code = EQ;
3290 break;
3292 case GE: case GT: case GEU: case GTU:
3293 /* These normally need swapping, but for integer zero we have
3294 special patterns that recognize swapped operands. */
3295 if (!fp_p && op1 == const0_rtx)
3296 break;
3297 code = swap_condition (code);
3298 if (fp_p)
3299 cmp_code = code, code = NE;
3300 tmp = op0, op0 = op1, op1 = tmp;
3301 break;
3303 default:
3304 abort ();
3307 if (!fp_p)
3309 if (!register_operand (op0, DImode))
3310 op0 = force_reg (DImode, op0);
3311 if (!reg_or_8bit_operand (op1, DImode))
3312 op1 = force_reg (DImode, op1);
3315 /* Emit an initial compare instruction, if necessary. */
3316 if (cmp_code != NIL)
3318 enum machine_mode mode = fp_p ? DFmode : DImode;
3320 tmp = gen_reg_rtx (mode);
3321 emit_insn (gen_rtx_SET (VOIDmode, tmp,
3322 gen_rtx_fmt_ee (cmp_code, mode, op0, op1)));
3324 op0 = fp_p ? gen_lowpart (DImode, tmp) : tmp;
3325 op1 = const0_rtx;
3328 /* Return the setcc comparison. */
3329 return gen_rtx_fmt_ee (code, DImode, op0, op1);
3333 /* Rewrite a comparison against zero CMP of the form
3334 (CODE (cc0) (const_int 0)) so it can be written validly in
3335 a conditional move (if_then_else CMP ...).
3336 If both of the operands that set cc0 are nonzero we must emit
3337 an insn to perform the compare (it can't be done within
3338 the conditional move). */
3341 alpha_emit_conditional_move (rtx cmp, enum machine_mode mode)
3343 enum rtx_code code = GET_CODE (cmp);
3344 enum rtx_code cmov_code = NE;
3345 rtx op0 = alpha_compare.op0;
3346 rtx op1 = alpha_compare.op1;
3347 int fp_p = alpha_compare.fp_p;
3348 enum machine_mode cmp_mode
3349 = (GET_MODE (op0) == VOIDmode ? DImode : GET_MODE (op0));
3350 enum machine_mode cmp_op_mode = fp_p ? DFmode : DImode;
3351 enum machine_mode cmov_mode = VOIDmode;
3352 int local_fast_math = flag_unsafe_math_optimizations;
3353 rtx tem;
3355 /* Zero the operands. */
3356 memset (&alpha_compare, 0, sizeof (alpha_compare));
3358 if (fp_p != FLOAT_MODE_P (mode))
3360 enum rtx_code cmp_code;
3362 if (! TARGET_FIX)
3363 return 0;
3365 /* If we have fp<->int register move instructions, do a cmov by
3366 performing the comparison in fp registers, and move the
3367 zero/nonzero value to integer registers, where we can then
3368 use a normal cmov, or vice-versa. */
3370 switch (code)
3372 case EQ: case LE: case LT: case LEU: case LTU:
3373 /* We have these compares. */
3374 cmp_code = code, code = NE;
3375 break;
3377 case NE:
3378 /* This must be reversed. */
3379 cmp_code = EQ, code = EQ;
3380 break;
3382 case GE: case GT: case GEU: case GTU:
3383 /* These normally need swapping, but for integer zero we have
3384 special patterns that recognize swapped operands. */
3385 if (!fp_p && op1 == const0_rtx)
3386 cmp_code = code, code = NE;
3387 else
3389 cmp_code = swap_condition (code);
3390 code = NE;
3391 tem = op0, op0 = op1, op1 = tem;
3393 break;
3395 default:
3396 abort ();
3399 tem = gen_reg_rtx (cmp_op_mode);
3400 emit_insn (gen_rtx_SET (VOIDmode, tem,
3401 gen_rtx_fmt_ee (cmp_code, cmp_op_mode,
3402 op0, op1)));
3404 cmp_mode = cmp_op_mode = fp_p ? DImode : DFmode;
3405 op0 = gen_lowpart (cmp_op_mode, tem);
3406 op1 = CONST0_RTX (cmp_op_mode);
3407 fp_p = !fp_p;
3408 local_fast_math = 1;
3411 /* We may be able to use a conditional move directly.
3412 This avoids emitting spurious compares. */
3413 if (signed_comparison_operator (cmp, VOIDmode)
3414 && (!fp_p || local_fast_math)
3415 && (op0 == CONST0_RTX (cmp_mode) || op1 == CONST0_RTX (cmp_mode)))
3416 return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
3418 /* We can't put the comparison inside the conditional move;
3419 emit a compare instruction and put that inside the
3420 conditional move. Make sure we emit only comparisons we have;
3421 swap or reverse as necessary. */
3423 if (no_new_pseudos)
3424 return NULL_RTX;
3426 switch (code)
3428 case EQ: case LE: case LT: case LEU: case LTU:
3429 /* We have these compares: */
3430 break;
3432 case NE:
3433 /* This must be reversed. */
3434 code = reverse_condition (code);
3435 cmov_code = EQ;
3436 break;
3438 case GE: case GT: case GEU: case GTU:
3439 /* These must be swapped. */
3440 if (op1 != CONST0_RTX (cmp_mode))
3442 code = swap_condition (code);
3443 tem = op0, op0 = op1, op1 = tem;
3445 break;
3447 default:
3448 abort ();
3451 if (!fp_p)
3453 if (!reg_or_0_operand (op0, DImode))
3454 op0 = force_reg (DImode, op0);
3455 if (!reg_or_8bit_operand (op1, DImode))
3456 op1 = force_reg (DImode, op1);
3459 /* ??? We mark the branch mode to be CCmode to prevent the compare
3460 and cmov from being combined, since the compare insn follows IEEE
3461 rules that the cmov does not. */
3462 if (fp_p && !local_fast_math)
3463 cmov_mode = CCmode;
3465 tem = gen_reg_rtx (cmp_op_mode);
3466 emit_move_insn (tem, gen_rtx_fmt_ee (code, cmp_op_mode, op0, op1));
3467 return gen_rtx_fmt_ee (cmov_code, cmov_mode, tem, CONST0_RTX (cmp_op_mode));
3470 /* Simplify a conditional move of two constants into a setcc with
3471 arithmetic. This is done with a splitter since combine would
3472 just undo the work if done during code generation. It also catches
3473 cases we wouldn't have before cse. */
3476 alpha_split_conditional_move (enum rtx_code code, rtx dest, rtx cond,
3477 rtx t_rtx, rtx f_rtx)
3479 HOST_WIDE_INT t, f, diff;
3480 enum machine_mode mode;
3481 rtx target, subtarget, tmp;
3483 mode = GET_MODE (dest);
3484 t = INTVAL (t_rtx);
3485 f = INTVAL (f_rtx);
3486 diff = t - f;
3488 if (((code == NE || code == EQ) && diff < 0)
3489 || (code == GE || code == GT))
3491 code = reverse_condition (code);
3492 diff = t, t = f, f = diff;
3493 diff = t - f;
3496 subtarget = target = dest;
3497 if (mode != DImode)
3499 target = gen_lowpart (DImode, dest);
3500 if (! no_new_pseudos)
3501 subtarget = gen_reg_rtx (DImode);
3502 else
3503 subtarget = target;
3505 /* Below, we must be careful to use copy_rtx on target and subtarget
3506 in intermediate insns, as they may be a subreg rtx, which may not
3507 be shared. */
3509 if (f == 0 && exact_log2 (diff) > 0
3510 /* On EV6, we've got enough shifters to make non-arithmetic shifts
3511 viable over a longer latency cmove. On EV5, the E0 slot is a
3512 scarce resource, and on EV4 shift has the same latency as a cmove. */
3513 && (diff <= 8 || alpha_cpu == PROCESSOR_EV6))
3515 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3516 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3518 tmp = gen_rtx_ASHIFT (DImode, copy_rtx (subtarget),
3519 GEN_INT (exact_log2 (t)));
3520 emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3522 else if (f == 0 && t == -1)
3524 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3525 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3527 emit_insn (gen_negdi2 (target, copy_rtx (subtarget)));
3529 else if (diff == 1 || diff == 4 || diff == 8)
3531 rtx add_op;
3533 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3534 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3536 if (diff == 1)
3537 emit_insn (gen_adddi3 (target, copy_rtx (subtarget), GEN_INT (f)));
3538 else
3540 add_op = GEN_INT (f);
3541 if (sext_add_operand (add_op, mode))
3543 tmp = gen_rtx_MULT (DImode, copy_rtx (subtarget),
3544 GEN_INT (diff));
3545 tmp = gen_rtx_PLUS (DImode, tmp, add_op);
3546 emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3548 else
3549 return 0;
3552 else
3553 return 0;
3555 return 1;
3558 /* Look up the function X_floating library function name for the
3559 given operation. */
3561 static const char *
3562 alpha_lookup_xfloating_lib_func (enum rtx_code code)
3564 struct xfloating_op
3566 const enum rtx_code code;
3567 const char *const func;
3570 static const struct xfloating_op vms_xfloating_ops[] =
3572 { PLUS, "OTS$ADD_X" },
3573 { MINUS, "OTS$SUB_X" },
3574 { MULT, "OTS$MUL_X" },
3575 { DIV, "OTS$DIV_X" },
3576 { EQ, "OTS$EQL_X" },
3577 { NE, "OTS$NEQ_X" },
3578 { LT, "OTS$LSS_X" },
3579 { LE, "OTS$LEQ_X" },
3580 { GT, "OTS$GTR_X" },
3581 { GE, "OTS$GEQ_X" },
3582 { FIX, "OTS$CVTXQ" },
3583 { FLOAT, "OTS$CVTQX" },
3584 { UNSIGNED_FLOAT, "OTS$CVTQUX" },
3585 { FLOAT_EXTEND, "OTS$CVT_FLOAT_T_X" },
3586 { FLOAT_TRUNCATE, "OTS$CVT_FLOAT_X_T" },
3589 static const struct xfloating_op osf_xfloating_ops[] =
3591 { PLUS, "_OtsAddX" },
3592 { MINUS, "_OtsSubX" },
3593 { MULT, "_OtsMulX" },
3594 { DIV, "_OtsDivX" },
3595 { EQ, "_OtsEqlX" },
3596 { NE, "_OtsNeqX" },
3597 { LT, "_OtsLssX" },
3598 { LE, "_OtsLeqX" },
3599 { GT, "_OtsGtrX" },
3600 { GE, "_OtsGeqX" },
3601 { FIX, "_OtsCvtXQ" },
3602 { FLOAT, "_OtsCvtQX" },
3603 { UNSIGNED_FLOAT, "_OtsCvtQUX" },
3604 { FLOAT_EXTEND, "_OtsConvertFloatTX" },
3605 { FLOAT_TRUNCATE, "_OtsConvertFloatXT" },
3608 const struct xfloating_op *ops;
3609 const long n = ARRAY_SIZE (osf_xfloating_ops);
3610 long i;
3612 /* How irritating. Nothing to key off for the table. Hardcode
3613 knowledge of the G_floating routines. */
3614 if (TARGET_FLOAT_VAX)
3616 if (TARGET_ABI_OPEN_VMS)
3618 if (code == FLOAT_EXTEND)
3619 return "OTS$CVT_FLOAT_G_X";
3620 if (code == FLOAT_TRUNCATE)
3621 return "OTS$CVT_FLOAT_X_G";
3623 else
3625 if (code == FLOAT_EXTEND)
3626 return "_OtsConvertFloatGX";
3627 if (code == FLOAT_TRUNCATE)
3628 return "_OtsConvertFloatXG";
3632 if (TARGET_ABI_OPEN_VMS)
3633 ops = vms_xfloating_ops;
3634 else
3635 ops = osf_xfloating_ops;
3637 for (i = 0; i < n; ++i)
3638 if (ops[i].code == code)
3639 return ops[i].func;
3641 abort();
3644 /* Most X_floating operations take the rounding mode as an argument.
3645 Compute that here. */
3647 static int
3648 alpha_compute_xfloating_mode_arg (enum rtx_code code,
3649 enum alpha_fp_rounding_mode round)
3651 int mode;
3653 switch (round)
3655 case ALPHA_FPRM_NORM:
3656 mode = 2;
3657 break;
3658 case ALPHA_FPRM_MINF:
3659 mode = 1;
3660 break;
3661 case ALPHA_FPRM_CHOP:
3662 mode = 0;
3663 break;
3664 case ALPHA_FPRM_DYN:
3665 mode = 4;
3666 break;
3667 default:
3668 abort ();
3670 /* XXX For reference, round to +inf is mode = 3. */
3673 if (code == FLOAT_TRUNCATE && alpha_fptm == ALPHA_FPTM_N)
3674 mode |= 0x10000;
3676 return mode;
3679 /* Emit an X_floating library function call.
3681 Note that these functions do not follow normal calling conventions:
3682 TFmode arguments are passed in two integer registers (as opposed to
3683 indirect); TFmode return values appear in R16+R17.
3685 FUNC is the function name to call.
3686 TARGET is where the output belongs.
3687 OPERANDS are the inputs.
3688 NOPERANDS is the count of inputs.
3689 EQUIV is the expression equivalent for the function.
3692 static void
3693 alpha_emit_xfloating_libcall (const char *func, rtx target, rtx operands[],
3694 int noperands, rtx equiv)
3696 rtx usage = NULL_RTX, tmp, reg;
3697 int regno = 16, i;
3699 start_sequence ();
3701 for (i = 0; i < noperands; ++i)
3703 switch (GET_MODE (operands[i]))
3705 case TFmode:
3706 reg = gen_rtx_REG (TFmode, regno);
3707 regno += 2;
3708 break;
3710 case DFmode:
3711 reg = gen_rtx_REG (DFmode, regno + 32);
3712 regno += 1;
3713 break;
3715 case VOIDmode:
3716 if (GET_CODE (operands[i]) != CONST_INT)
3717 abort ();
3718 /* FALLTHRU */
3719 case DImode:
3720 reg = gen_rtx_REG (DImode, regno);
3721 regno += 1;
3722 break;
3724 default:
3725 abort ();
3728 emit_move_insn (reg, operands[i]);
3729 usage = alloc_EXPR_LIST (0, gen_rtx_USE (VOIDmode, reg), usage);
3732 switch (GET_MODE (target))
3734 case TFmode:
3735 reg = gen_rtx_REG (TFmode, 16);
3736 break;
3737 case DFmode:
3738 reg = gen_rtx_REG (DFmode, 32);
3739 break;
3740 case DImode:
3741 reg = gen_rtx_REG (DImode, 0);
3742 break;
3743 default:
3744 abort ();
3747 tmp = gen_rtx_MEM (QImode, init_one_libfunc (func));
3748 tmp = emit_call_insn (GEN_CALL_VALUE (reg, tmp, const0_rtx,
3749 const0_rtx, const0_rtx));
3750 CALL_INSN_FUNCTION_USAGE (tmp) = usage;
3752 tmp = get_insns ();
3753 end_sequence ();
3755 emit_libcall_block (tmp, target, reg, equiv);
3758 /* Emit an X_floating library function call for arithmetic (+,-,*,/). */
3760 void
3761 alpha_emit_xfloating_arith (enum rtx_code code, rtx operands[])
3763 const char *func;
3764 int mode;
3765 rtx out_operands[3];
3767 func = alpha_lookup_xfloating_lib_func (code);
3768 mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3770 out_operands[0] = operands[1];
3771 out_operands[1] = operands[2];
3772 out_operands[2] = GEN_INT (mode);
3773 alpha_emit_xfloating_libcall (func, operands[0], out_operands, 3,
3774 gen_rtx_fmt_ee (code, TFmode, operands[1],
3775 operands[2]));
3778 /* Emit an X_floating library function call for a comparison. */
3780 static rtx
3781 alpha_emit_xfloating_compare (enum rtx_code code, rtx op0, rtx op1)
3783 const char *func;
3784 rtx out, operands[2];
3786 func = alpha_lookup_xfloating_lib_func (code);
3788 operands[0] = op0;
3789 operands[1] = op1;
3790 out = gen_reg_rtx (DImode);
3792 /* ??? Strange mode for equiv because what's actually returned
3793 is -1,0,1, not a proper boolean value. */
3794 alpha_emit_xfloating_libcall (func, out, operands, 2,
3795 gen_rtx_fmt_ee (code, CCmode, op0, op1));
3797 return out;
3800 /* Emit an X_floating library function call for a conversion. */
3802 void
3803 alpha_emit_xfloating_cvt (enum rtx_code orig_code, rtx operands[])
3805 int noperands = 1, mode;
3806 rtx out_operands[2];
3807 const char *func;
3808 enum rtx_code code = orig_code;
3810 if (code == UNSIGNED_FIX)
3811 code = FIX;
3813 func = alpha_lookup_xfloating_lib_func (code);
3815 out_operands[0] = operands[1];
3817 switch (code)
3819 case FIX:
3820 mode = alpha_compute_xfloating_mode_arg (code, ALPHA_FPRM_CHOP);
3821 out_operands[1] = GEN_INT (mode);
3822 noperands = 2;
3823 break;
3824 case FLOAT_TRUNCATE:
3825 mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3826 out_operands[1] = GEN_INT (mode);
3827 noperands = 2;
3828 break;
3829 default:
3830 break;
3833 alpha_emit_xfloating_libcall (func, operands[0], out_operands, noperands,
3834 gen_rtx_fmt_e (orig_code,
3835 GET_MODE (operands[0]),
3836 operands[1]));
3839 /* Split a TFmode OP[1] into DImode OP[2,3] and likewise for
3840 OP[0] into OP[0,1]. Naturally, output operand ordering is
3841 little-endian. */
3843 void
3844 alpha_split_tfmode_pair (rtx operands[4])
3846 if (GET_CODE (operands[1]) == REG)
3848 operands[3] = gen_rtx_REG (DImode, REGNO (operands[1]) + 1);
3849 operands[2] = gen_rtx_REG (DImode, REGNO (operands[1]));
3851 else if (GET_CODE (operands[1]) == MEM)
3853 operands[3] = adjust_address (operands[1], DImode, 8);
3854 operands[2] = adjust_address (operands[1], DImode, 0);
3856 else if (operands[1] == CONST0_RTX (TFmode))
3857 operands[2] = operands[3] = const0_rtx;
3858 else
3859 abort ();
3861 if (GET_CODE (operands[0]) == REG)
3863 operands[1] = gen_rtx_REG (DImode, REGNO (operands[0]) + 1);
3864 operands[0] = gen_rtx_REG (DImode, REGNO (operands[0]));
3866 else if (GET_CODE (operands[0]) == MEM)
3868 operands[1] = adjust_address (operands[0], DImode, 8);
3869 operands[0] = adjust_address (operands[0], DImode, 0);
3871 else
3872 abort ();
3875 /* Implement negtf2 or abstf2. Op0 is destination, op1 is source,
3876 op2 is a register containing the sign bit, operation is the
3877 logical operation to be performed. */
3879 void
3880 alpha_split_tfmode_frobsign (rtx operands[3], rtx (*operation) (rtx, rtx, rtx))
3882 rtx high_bit = operands[2];
3883 rtx scratch;
3884 int move;
3886 alpha_split_tfmode_pair (operands);
3888 /* Detect three flavors of operand overlap. */
3889 move = 1;
3890 if (rtx_equal_p (operands[0], operands[2]))
3891 move = 0;
3892 else if (rtx_equal_p (operands[1], operands[2]))
3894 if (rtx_equal_p (operands[0], high_bit))
3895 move = 2;
3896 else
3897 move = -1;
3900 if (move < 0)
3901 emit_move_insn (operands[0], operands[2]);
3903 /* ??? If the destination overlaps both source tf and high_bit, then
3904 assume source tf is dead in its entirety and use the other half
3905 for a scratch register. Otherwise "scratch" is just the proper
3906 destination register. */
3907 scratch = operands[move < 2 ? 1 : 3];
3909 emit_insn ((*operation) (scratch, high_bit, operands[3]));
3911 if (move > 0)
3913 emit_move_insn (operands[0], operands[2]);
3914 if (move > 1)
3915 emit_move_insn (operands[1], scratch);
3919 /* Use ext[wlq][lh] as the Architecture Handbook describes for extracting
3920 unaligned data:
3922 unsigned: signed:
3923 word: ldq_u r1,X(r11) ldq_u r1,X(r11)
3924 ldq_u r2,X+1(r11) ldq_u r2,X+1(r11)
3925 lda r3,X(r11) lda r3,X+2(r11)
3926 extwl r1,r3,r1 extql r1,r3,r1
3927 extwh r2,r3,r2 extqh r2,r3,r2
3928 or r1.r2.r1 or r1,r2,r1
3929 sra r1,48,r1
3931 long: ldq_u r1,X(r11) ldq_u r1,X(r11)
3932 ldq_u r2,X+3(r11) ldq_u r2,X+3(r11)
3933 lda r3,X(r11) lda r3,X(r11)
3934 extll r1,r3,r1 extll r1,r3,r1
3935 extlh r2,r3,r2 extlh r2,r3,r2
3936 or r1.r2.r1 addl r1,r2,r1
3938 quad: ldq_u r1,X(r11)
3939 ldq_u r2,X+7(r11)
3940 lda r3,X(r11)
3941 extql r1,r3,r1
3942 extqh r2,r3,r2
3943 or r1.r2.r1
3946 void
3947 alpha_expand_unaligned_load (rtx tgt, rtx mem, HOST_WIDE_INT size,
3948 HOST_WIDE_INT ofs, int sign)
3950 rtx meml, memh, addr, extl, exth, tmp, mema;
3951 enum machine_mode mode;
3953 meml = gen_reg_rtx (DImode);
3954 memh = gen_reg_rtx (DImode);
3955 addr = gen_reg_rtx (DImode);
3956 extl = gen_reg_rtx (DImode);
3957 exth = gen_reg_rtx (DImode);
3959 mema = XEXP (mem, 0);
3960 if (GET_CODE (mema) == LO_SUM)
3961 mema = force_reg (Pmode, mema);
3963 /* AND addresses cannot be in any alias set, since they may implicitly
3964 alias surrounding code. Ideally we'd have some alias set that
3965 covered all types except those with alignment 8 or higher. */
3967 tmp = change_address (mem, DImode,
3968 gen_rtx_AND (DImode,
3969 plus_constant (mema, ofs),
3970 GEN_INT (-8)));
3971 set_mem_alias_set (tmp, 0);
3972 emit_move_insn (meml, tmp);
3974 tmp = change_address (mem, DImode,
3975 gen_rtx_AND (DImode,
3976 plus_constant (mema, ofs + size - 1),
3977 GEN_INT (-8)));
3978 set_mem_alias_set (tmp, 0);
3979 emit_move_insn (memh, tmp);
3981 if (WORDS_BIG_ENDIAN && sign && (size == 2 || size == 4))
3983 emit_move_insn (addr, plus_constant (mema, -1));
3985 emit_insn (gen_extqh_be (extl, meml, addr));
3986 emit_insn (gen_extxl_be (exth, memh, GEN_INT (64), addr));
3988 addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
3989 addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (64 - size*8),
3990 addr, 1, OPTAB_WIDEN);
3992 else if (sign && size == 2)
3994 emit_move_insn (addr, plus_constant (mema, ofs+2));
3996 emit_insn (gen_extxl_le (extl, meml, GEN_INT (64), addr));
3997 emit_insn (gen_extqh_le (exth, memh, addr));
3999 /* We must use tgt here for the target. Alpha-vms port fails if we use
4000 addr for the target, because addr is marked as a pointer and combine
4001 knows that pointers are always sign-extended 32 bit values. */
4002 addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
4003 addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (48),
4004 addr, 1, OPTAB_WIDEN);
4006 else
4008 if (WORDS_BIG_ENDIAN)
4010 emit_move_insn (addr, plus_constant (mema, ofs+size-1));
4011 switch ((int) size)
4013 case 2:
4014 emit_insn (gen_extwh_be (extl, meml, addr));
4015 mode = HImode;
4016 break;
4018 case 4:
4019 emit_insn (gen_extlh_be (extl, meml, addr));
4020 mode = SImode;
4021 break;
4023 case 8:
4024 emit_insn (gen_extqh_be (extl, meml, addr));
4025 mode = DImode;
4026 break;
4028 default:
4029 abort ();
4031 emit_insn (gen_extxl_be (exth, memh, GEN_INT (size*8), addr));
4033 else
4035 emit_move_insn (addr, plus_constant (mema, ofs));
4036 emit_insn (gen_extxl_le (extl, meml, GEN_INT (size*8), addr));
4037 switch ((int) size)
4039 case 2:
4040 emit_insn (gen_extwh_le (exth, memh, addr));
4041 mode = HImode;
4042 break;
4044 case 4:
4045 emit_insn (gen_extlh_le (exth, memh, addr));
4046 mode = SImode;
4047 break;
4049 case 8:
4050 emit_insn (gen_extqh_le (exth, memh, addr));
4051 mode = DImode;
4052 break;
4054 default:
4055 abort();
4059 addr = expand_binop (mode, ior_optab, gen_lowpart (mode, extl),
4060 gen_lowpart (mode, exth), gen_lowpart (mode, tgt),
4061 sign, OPTAB_WIDEN);
4064 if (addr != tgt)
4065 emit_move_insn (tgt, gen_lowpart(GET_MODE (tgt), addr));
4068 /* Similarly, use ins and msk instructions to perform unaligned stores. */
4070 void
4071 alpha_expand_unaligned_store (rtx dst, rtx src,
4072 HOST_WIDE_INT size, HOST_WIDE_INT ofs)
4074 rtx dstl, dsth, addr, insl, insh, meml, memh, dsta;
4076 dstl = gen_reg_rtx (DImode);
4077 dsth = gen_reg_rtx (DImode);
4078 insl = gen_reg_rtx (DImode);
4079 insh = gen_reg_rtx (DImode);
4081 dsta = XEXP (dst, 0);
4082 if (GET_CODE (dsta) == LO_SUM)
4083 dsta = force_reg (Pmode, dsta);
4085 /* AND addresses cannot be in any alias set, since they may implicitly
4086 alias surrounding code. Ideally we'd have some alias set that
4087 covered all types except those with alignment 8 or higher. */
4089 meml = change_address (dst, DImode,
4090 gen_rtx_AND (DImode,
4091 plus_constant (dsta, ofs),
4092 GEN_INT (-8)));
4093 set_mem_alias_set (meml, 0);
4095 memh = change_address (dst, DImode,
4096 gen_rtx_AND (DImode,
4097 plus_constant (dsta, ofs + size - 1),
4098 GEN_INT (-8)));
4099 set_mem_alias_set (memh, 0);
4101 emit_move_insn (dsth, memh);
4102 emit_move_insn (dstl, meml);
4103 if (WORDS_BIG_ENDIAN)
4105 addr = copy_addr_to_reg (plus_constant (dsta, ofs+size-1));
4107 if (src != const0_rtx)
4109 switch ((int) size)
4111 case 2:
4112 emit_insn (gen_inswl_be (insh, gen_lowpart (HImode,src), addr));
4113 break;
4114 case 4:
4115 emit_insn (gen_insll_be (insh, gen_lowpart (SImode,src), addr));
4116 break;
4117 case 8:
4118 emit_insn (gen_insql_be (insh, gen_lowpart (DImode,src), addr));
4119 break;
4121 emit_insn (gen_insxh (insl, gen_lowpart (DImode, src),
4122 GEN_INT (size*8), addr));
4125 switch ((int) size)
4127 case 2:
4128 emit_insn (gen_mskxl_be (dsth, dsth, GEN_INT (0xffff), addr));
4129 break;
4130 case 4:
4132 rtx msk = immed_double_const (0xffffffff, 0, DImode);
4133 emit_insn (gen_mskxl_be (dsth, dsth, msk, addr));
4134 break;
4136 case 8:
4137 emit_insn (gen_mskxl_be (dsth, dsth, constm1_rtx, addr));
4138 break;
4141 emit_insn (gen_mskxh (dstl, dstl, GEN_INT (size*8), addr));
4143 else
4145 addr = copy_addr_to_reg (plus_constant (dsta, ofs));
4147 if (src != const0_rtx)
4149 emit_insn (gen_insxh (insh, gen_lowpart (DImode, src),
4150 GEN_INT (size*8), addr));
4152 switch ((int) size)
4154 case 2:
4155 emit_insn (gen_inswl_le (insl, gen_lowpart (HImode, src), addr));
4156 break;
4157 case 4:
4158 emit_insn (gen_insll_le (insl, gen_lowpart (SImode, src), addr));
4159 break;
4160 case 8:
4161 emit_insn (gen_insql_le (insl, src, addr));
4162 break;
4166 emit_insn (gen_mskxh (dsth, dsth, GEN_INT (size*8), addr));
4168 switch ((int) size)
4170 case 2:
4171 emit_insn (gen_mskxl_le (dstl, dstl, GEN_INT (0xffff), addr));
4172 break;
4173 case 4:
4175 rtx msk = immed_double_const (0xffffffff, 0, DImode);
4176 emit_insn (gen_mskxl_le (dstl, dstl, msk, addr));
4177 break;
4179 case 8:
4180 emit_insn (gen_mskxl_le (dstl, dstl, constm1_rtx, addr));
4181 break;
4185 if (src != const0_rtx)
4187 dsth = expand_binop (DImode, ior_optab, insh, dsth, dsth, 0, OPTAB_WIDEN);
4188 dstl = expand_binop (DImode, ior_optab, insl, dstl, dstl, 0, OPTAB_WIDEN);
4191 if (WORDS_BIG_ENDIAN)
4193 emit_move_insn (meml, dstl);
4194 emit_move_insn (memh, dsth);
4196 else
4198 /* Must store high before low for degenerate case of aligned. */
4199 emit_move_insn (memh, dsth);
4200 emit_move_insn (meml, dstl);
4204 /* The block move code tries to maximize speed by separating loads and
4205 stores at the expense of register pressure: we load all of the data
4206 before we store it back out. There are two secondary effects worth
4207 mentioning, that this speeds copying to/from aligned and unaligned
4208 buffers, and that it makes the code significantly easier to write. */
4210 #define MAX_MOVE_WORDS 8
4212 /* Load an integral number of consecutive unaligned quadwords. */
4214 static void
4215 alpha_expand_unaligned_load_words (rtx *out_regs, rtx smem,
4216 HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4218 rtx const im8 = GEN_INT (-8);
4219 rtx const i64 = GEN_INT (64);
4220 rtx ext_tmps[MAX_MOVE_WORDS], data_regs[MAX_MOVE_WORDS+1];
4221 rtx sreg, areg, tmp, smema;
4222 HOST_WIDE_INT i;
4224 smema = XEXP (smem, 0);
4225 if (GET_CODE (smema) == LO_SUM)
4226 smema = force_reg (Pmode, smema);
4228 /* Generate all the tmp registers we need. */
4229 for (i = 0; i < words; ++i)
4231 data_regs[i] = out_regs[i];
4232 ext_tmps[i] = gen_reg_rtx (DImode);
4234 data_regs[words] = gen_reg_rtx (DImode);
4236 if (ofs != 0)
4237 smem = adjust_address (smem, GET_MODE (smem), ofs);
4239 /* Load up all of the source data. */
4240 for (i = 0; i < words; ++i)
4242 tmp = change_address (smem, DImode,
4243 gen_rtx_AND (DImode,
4244 plus_constant (smema, 8*i),
4245 im8));
4246 set_mem_alias_set (tmp, 0);
4247 emit_move_insn (data_regs[i], tmp);
4250 tmp = change_address (smem, DImode,
4251 gen_rtx_AND (DImode,
4252 plus_constant (smema, 8*words - 1),
4253 im8));
4254 set_mem_alias_set (tmp, 0);
4255 emit_move_insn (data_regs[words], tmp);
4257 /* Extract the half-word fragments. Unfortunately DEC decided to make
4258 extxh with offset zero a noop instead of zeroing the register, so
4259 we must take care of that edge condition ourselves with cmov. */
4261 sreg = copy_addr_to_reg (smema);
4262 areg = expand_binop (DImode, and_optab, sreg, GEN_INT (7), NULL,
4263 1, OPTAB_WIDEN);
4264 if (WORDS_BIG_ENDIAN)
4265 emit_move_insn (sreg, plus_constant (sreg, 7));
4266 for (i = 0; i < words; ++i)
4268 if (WORDS_BIG_ENDIAN)
4270 emit_insn (gen_extqh_be (data_regs[i], data_regs[i], sreg));
4271 emit_insn (gen_extxl_be (ext_tmps[i], data_regs[i+1], i64, sreg));
4273 else
4275 emit_insn (gen_extxl_le (data_regs[i], data_regs[i], i64, sreg));
4276 emit_insn (gen_extqh_le (ext_tmps[i], data_regs[i+1], sreg));
4278 emit_insn (gen_rtx_SET (VOIDmode, ext_tmps[i],
4279 gen_rtx_IF_THEN_ELSE (DImode,
4280 gen_rtx_EQ (DImode, areg,
4281 const0_rtx),
4282 const0_rtx, ext_tmps[i])));
4285 /* Merge the half-words into whole words. */
4286 for (i = 0; i < words; ++i)
4288 out_regs[i] = expand_binop (DImode, ior_optab, data_regs[i],
4289 ext_tmps[i], data_regs[i], 1, OPTAB_WIDEN);
4293 /* Store an integral number of consecutive unaligned quadwords. DATA_REGS
4294 may be NULL to store zeros. */
4296 static void
4297 alpha_expand_unaligned_store_words (rtx *data_regs, rtx dmem,
4298 HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4300 rtx const im8 = GEN_INT (-8);
4301 rtx const i64 = GEN_INT (64);
4302 rtx ins_tmps[MAX_MOVE_WORDS];
4303 rtx st_tmp_1, st_tmp_2, dreg;
4304 rtx st_addr_1, st_addr_2, dmema;
4305 HOST_WIDE_INT i;
4307 dmema = XEXP (dmem, 0);
4308 if (GET_CODE (dmema) == LO_SUM)
4309 dmema = force_reg (Pmode, dmema);
4311 /* Generate all the tmp registers we need. */
4312 if (data_regs != NULL)
4313 for (i = 0; i < words; ++i)
4314 ins_tmps[i] = gen_reg_rtx(DImode);
4315 st_tmp_1 = gen_reg_rtx(DImode);
4316 st_tmp_2 = gen_reg_rtx(DImode);
4318 if (ofs != 0)
4319 dmem = adjust_address (dmem, GET_MODE (dmem), ofs);
4321 st_addr_2 = change_address (dmem, DImode,
4322 gen_rtx_AND (DImode,
4323 plus_constant (dmema, words*8 - 1),
4324 im8));
4325 set_mem_alias_set (st_addr_2, 0);
4327 st_addr_1 = change_address (dmem, DImode,
4328 gen_rtx_AND (DImode, dmema, im8));
4329 set_mem_alias_set (st_addr_1, 0);
4331 /* Load up the destination end bits. */
4332 emit_move_insn (st_tmp_2, st_addr_2);
4333 emit_move_insn (st_tmp_1, st_addr_1);
4335 /* Shift the input data into place. */
4336 dreg = copy_addr_to_reg (dmema);
4337 if (WORDS_BIG_ENDIAN)
4338 emit_move_insn (dreg, plus_constant (dreg, 7));
4339 if (data_regs != NULL)
4341 for (i = words-1; i >= 0; --i)
4343 if (WORDS_BIG_ENDIAN)
4345 emit_insn (gen_insql_be (ins_tmps[i], data_regs[i], dreg));
4346 emit_insn (gen_insxh (data_regs[i], data_regs[i], i64, dreg));
4348 else
4350 emit_insn (gen_insxh (ins_tmps[i], data_regs[i], i64, dreg));
4351 emit_insn (gen_insql_le (data_regs[i], data_regs[i], dreg));
4354 for (i = words-1; i > 0; --i)
4356 ins_tmps[i-1] = expand_binop (DImode, ior_optab, data_regs[i],
4357 ins_tmps[i-1], ins_tmps[i-1], 1,
4358 OPTAB_WIDEN);
4362 /* Split and merge the ends with the destination data. */
4363 if (WORDS_BIG_ENDIAN)
4365 emit_insn (gen_mskxl_be (st_tmp_2, st_tmp_2, constm1_rtx, dreg));
4366 emit_insn (gen_mskxh (st_tmp_1, st_tmp_1, i64, dreg));
4368 else
4370 emit_insn (gen_mskxh (st_tmp_2, st_tmp_2, i64, dreg));
4371 emit_insn (gen_mskxl_le (st_tmp_1, st_tmp_1, constm1_rtx, dreg));
4374 if (data_regs != NULL)
4376 st_tmp_2 = expand_binop (DImode, ior_optab, st_tmp_2, ins_tmps[words-1],
4377 st_tmp_2, 1, OPTAB_WIDEN);
4378 st_tmp_1 = expand_binop (DImode, ior_optab, st_tmp_1, data_regs[0],
4379 st_tmp_1, 1, OPTAB_WIDEN);
4382 /* Store it all. */
4383 if (WORDS_BIG_ENDIAN)
4384 emit_move_insn (st_addr_1, st_tmp_1);
4385 else
4386 emit_move_insn (st_addr_2, st_tmp_2);
4387 for (i = words-1; i > 0; --i)
4389 rtx tmp = change_address (dmem, DImode,
4390 gen_rtx_AND (DImode,
4391 plus_constant(dmema,
4392 WORDS_BIG_ENDIAN ? i*8-1 : i*8),
4393 im8));
4394 set_mem_alias_set (tmp, 0);
4395 emit_move_insn (tmp, data_regs ? ins_tmps[i-1] : const0_rtx);
4397 if (WORDS_BIG_ENDIAN)
4398 emit_move_insn (st_addr_2, st_tmp_2);
4399 else
4400 emit_move_insn (st_addr_1, st_tmp_1);
4404 /* Expand string/block move operations.
4406 operands[0] is the pointer to the destination.
4407 operands[1] is the pointer to the source.
4408 operands[2] is the number of bytes to move.
4409 operands[3] is the alignment. */
4412 alpha_expand_block_move (rtx operands[])
4414 rtx bytes_rtx = operands[2];
4415 rtx align_rtx = operands[3];
4416 HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4417 HOST_WIDE_INT bytes = orig_bytes;
4418 HOST_WIDE_INT src_align = INTVAL (align_rtx) * BITS_PER_UNIT;
4419 HOST_WIDE_INT dst_align = src_align;
4420 rtx orig_src = operands[1];
4421 rtx orig_dst = operands[0];
4422 rtx data_regs[2 * MAX_MOVE_WORDS + 16];
4423 rtx tmp;
4424 unsigned int i, words, ofs, nregs = 0;
4426 if (orig_bytes <= 0)
4427 return 1;
4428 else if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4429 return 0;
4431 /* Look for additional alignment information from recorded register info. */
4433 tmp = XEXP (orig_src, 0);
4434 if (GET_CODE (tmp) == REG)
4435 src_align = MAX (src_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4436 else if (GET_CODE (tmp) == PLUS
4437 && GET_CODE (XEXP (tmp, 0)) == REG
4438 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4440 unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4441 unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4443 if (a > src_align)
4445 if (a >= 64 && c % 8 == 0)
4446 src_align = 64;
4447 else if (a >= 32 && c % 4 == 0)
4448 src_align = 32;
4449 else if (a >= 16 && c % 2 == 0)
4450 src_align = 16;
4454 tmp = XEXP (orig_dst, 0);
4455 if (GET_CODE (tmp) == REG)
4456 dst_align = MAX (dst_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4457 else if (GET_CODE (tmp) == PLUS
4458 && GET_CODE (XEXP (tmp, 0)) == REG
4459 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4461 unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4462 unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4464 if (a > dst_align)
4466 if (a >= 64 && c % 8 == 0)
4467 dst_align = 64;
4468 else if (a >= 32 && c % 4 == 0)
4469 dst_align = 32;
4470 else if (a >= 16 && c % 2 == 0)
4471 dst_align = 16;
4475 /* Load the entire block into registers. */
4476 if (GET_CODE (XEXP (orig_src, 0)) == ADDRESSOF)
4478 enum machine_mode mode;
4480 tmp = XEXP (XEXP (orig_src, 0), 0);
4482 /* Don't use the existing register if we're reading more than
4483 is held in the register. Nor if there is not a mode that
4484 handles the exact size. */
4485 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1);
4486 if (GET_CODE (tmp) == REG
4487 && mode != BLKmode
4488 && GET_MODE_SIZE (GET_MODE (tmp)) >= bytes)
4490 if (mode == TImode)
4492 data_regs[nregs] = gen_lowpart (DImode, tmp);
4493 data_regs[nregs + 1] = gen_highpart (DImode, tmp);
4494 nregs += 2;
4496 else
4497 data_regs[nregs++] = gen_lowpart (mode, tmp);
4499 goto src_done;
4502 /* No appropriate mode; fall back on memory. */
4503 orig_src = replace_equiv_address (orig_src,
4504 copy_addr_to_reg (XEXP (orig_src, 0)));
4505 src_align = GET_MODE_BITSIZE (GET_MODE (tmp));
4508 ofs = 0;
4509 if (src_align >= 64 && bytes >= 8)
4511 words = bytes / 8;
4513 for (i = 0; i < words; ++i)
4514 data_regs[nregs + i] = gen_reg_rtx (DImode);
4516 for (i = 0; i < words; ++i)
4517 emit_move_insn (data_regs[nregs + i],
4518 adjust_address (orig_src, DImode, ofs + i * 8));
4520 nregs += words;
4521 bytes -= words * 8;
4522 ofs += words * 8;
4525 if (src_align >= 32 && bytes >= 4)
4527 words = bytes / 4;
4529 for (i = 0; i < words; ++i)
4530 data_regs[nregs + i] = gen_reg_rtx (SImode);
4532 for (i = 0; i < words; ++i)
4533 emit_move_insn (data_regs[nregs + i],
4534 adjust_address (orig_src, SImode, ofs + i * 4));
4536 nregs += words;
4537 bytes -= words * 4;
4538 ofs += words * 4;
4541 if (bytes >= 8)
4543 words = bytes / 8;
4545 for (i = 0; i < words+1; ++i)
4546 data_regs[nregs + i] = gen_reg_rtx (DImode);
4548 alpha_expand_unaligned_load_words (data_regs + nregs, orig_src,
4549 words, ofs);
4551 nregs += words;
4552 bytes -= words * 8;
4553 ofs += words * 8;
4556 if (! TARGET_BWX && bytes >= 4)
4558 data_regs[nregs++] = tmp = gen_reg_rtx (SImode);
4559 alpha_expand_unaligned_load (tmp, orig_src, 4, ofs, 0);
4560 bytes -= 4;
4561 ofs += 4;
4564 if (bytes >= 2)
4566 if (src_align >= 16)
4568 do {
4569 data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4570 emit_move_insn (tmp, adjust_address (orig_src, HImode, ofs));
4571 bytes -= 2;
4572 ofs += 2;
4573 } while (bytes >= 2);
4575 else if (! TARGET_BWX)
4577 data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4578 alpha_expand_unaligned_load (tmp, orig_src, 2, ofs, 0);
4579 bytes -= 2;
4580 ofs += 2;
4584 while (bytes > 0)
4586 data_regs[nregs++] = tmp = gen_reg_rtx (QImode);
4587 emit_move_insn (tmp, adjust_address (orig_src, QImode, ofs));
4588 bytes -= 1;
4589 ofs += 1;
4592 src_done:
4594 if (nregs > ARRAY_SIZE (data_regs))
4595 abort ();
4597 /* Now save it back out again. */
4599 i = 0, ofs = 0;
4601 if (GET_CODE (XEXP (orig_dst, 0)) == ADDRESSOF)
4603 enum machine_mode mode;
4604 tmp = XEXP (XEXP (orig_dst, 0), 0);
4606 mode = mode_for_size (orig_bytes * BITS_PER_UNIT, MODE_INT, 1);
4607 if (GET_CODE (tmp) == REG && GET_MODE (tmp) == mode)
4609 if (nregs == 1)
4611 emit_move_insn (tmp, data_regs[0]);
4612 i = 1;
4613 goto dst_done;
4616 else if (nregs == 2 && mode == TImode)
4618 /* Undo the subregging done above when copying between
4619 two TImode registers. */
4620 if (GET_CODE (data_regs[0]) == SUBREG
4621 && GET_MODE (SUBREG_REG (data_regs[0])) == TImode)
4622 emit_move_insn (tmp, SUBREG_REG (data_regs[0]));
4623 else
4625 rtx seq;
4627 start_sequence ();
4628 emit_move_insn (gen_lowpart (DImode, tmp), data_regs[0]);
4629 emit_move_insn (gen_highpart (DImode, tmp), data_regs[1]);
4630 seq = get_insns ();
4631 end_sequence ();
4633 emit_no_conflict_block (seq, tmp, data_regs[0],
4634 data_regs[1], NULL_RTX);
4637 i = 2;
4638 goto dst_done;
4642 /* ??? If nregs > 1, consider reconstructing the word in regs. */
4643 /* ??? Optimize mode < dst_mode with strict_low_part. */
4645 /* No appropriate mode; fall back on memory. We can speed things
4646 up by recognizing extra alignment information. */
4647 orig_dst = replace_equiv_address (orig_dst,
4648 copy_addr_to_reg (XEXP (orig_dst, 0)));
4649 dst_align = GET_MODE_BITSIZE (GET_MODE (tmp));
4652 /* Write out the data in whatever chunks reading the source allowed. */
4653 if (dst_align >= 64)
4655 while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4657 emit_move_insn (adjust_address (orig_dst, DImode, ofs),
4658 data_regs[i]);
4659 ofs += 8;
4660 i++;
4664 if (dst_align >= 32)
4666 /* If the source has remaining DImode regs, write them out in
4667 two pieces. */
4668 while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4670 tmp = expand_binop (DImode, lshr_optab, data_regs[i], GEN_INT (32),
4671 NULL_RTX, 1, OPTAB_WIDEN);
4673 emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4674 gen_lowpart (SImode, data_regs[i]));
4675 emit_move_insn (adjust_address (orig_dst, SImode, ofs + 4),
4676 gen_lowpart (SImode, tmp));
4677 ofs += 8;
4678 i++;
4681 while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4683 emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4684 data_regs[i]);
4685 ofs += 4;
4686 i++;
4690 if (i < nregs && GET_MODE (data_regs[i]) == DImode)
4692 /* Write out a remaining block of words using unaligned methods. */
4694 for (words = 1; i + words < nregs; words++)
4695 if (GET_MODE (data_regs[i + words]) != DImode)
4696 break;
4698 if (words == 1)
4699 alpha_expand_unaligned_store (orig_dst, data_regs[i], 8, ofs);
4700 else
4701 alpha_expand_unaligned_store_words (data_regs + i, orig_dst,
4702 words, ofs);
4704 i += words;
4705 ofs += words * 8;
4708 /* Due to the above, this won't be aligned. */
4709 /* ??? If we have more than one of these, consider constructing full
4710 words in registers and using alpha_expand_unaligned_store_words. */
4711 while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4713 alpha_expand_unaligned_store (orig_dst, data_regs[i], 4, ofs);
4714 ofs += 4;
4715 i++;
4718 if (dst_align >= 16)
4719 while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4721 emit_move_insn (adjust_address (orig_dst, HImode, ofs), data_regs[i]);
4722 i++;
4723 ofs += 2;
4725 else
4726 while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4728 alpha_expand_unaligned_store (orig_dst, data_regs[i], 2, ofs);
4729 i++;
4730 ofs += 2;
4733 while (i < nregs && GET_MODE (data_regs[i]) == QImode)
4735 emit_move_insn (adjust_address (orig_dst, QImode, ofs), data_regs[i]);
4736 i++;
4737 ofs += 1;
4740 dst_done:
4742 if (i != nregs)
4743 abort ();
4745 return 1;
4749 alpha_expand_block_clear (rtx operands[])
4751 rtx bytes_rtx = operands[1];
4752 rtx align_rtx = operands[2];
4753 HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4754 HOST_WIDE_INT bytes = orig_bytes;
4755 HOST_WIDE_INT align = INTVAL (align_rtx) * BITS_PER_UNIT;
4756 HOST_WIDE_INT alignofs = 0;
4757 rtx orig_dst = operands[0];
4758 rtx tmp;
4759 int i, words, ofs = 0;
4761 if (orig_bytes <= 0)
4762 return 1;
4763 if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4764 return 0;
4766 /* Look for stricter alignment. */
4767 tmp = XEXP (orig_dst, 0);
4768 if (GET_CODE (tmp) == REG)
4769 align = MAX (align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4770 else if (GET_CODE (tmp) == PLUS
4771 && GET_CODE (XEXP (tmp, 0)) == REG
4772 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4774 HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4775 int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4777 if (a > align)
4779 if (a >= 64)
4780 align = a, alignofs = 8 - c % 8;
4781 else if (a >= 32)
4782 align = a, alignofs = 4 - c % 4;
4783 else if (a >= 16)
4784 align = a, alignofs = 2 - c % 2;
4787 else if (GET_CODE (tmp) == ADDRESSOF)
4789 enum machine_mode mode;
4791 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1);
4792 if (GET_MODE (XEXP (tmp, 0)) == mode)
4794 emit_move_insn (XEXP (tmp, 0), const0_rtx);
4795 return 1;
4798 /* No appropriate mode; fall back on memory. */
4799 orig_dst = replace_equiv_address (orig_dst, copy_addr_to_reg (tmp));
4800 align = GET_MODE_BITSIZE (GET_MODE (XEXP (tmp, 0)));
4803 /* Handle an unaligned prefix first. */
4805 if (alignofs > 0)
4807 #if HOST_BITS_PER_WIDE_INT >= 64
4808 /* Given that alignofs is bounded by align, the only time BWX could
4809 generate three stores is for a 7 byte fill. Prefer two individual
4810 stores over a load/mask/store sequence. */
4811 if ((!TARGET_BWX || alignofs == 7)
4812 && align >= 32
4813 && !(alignofs == 4 && bytes >= 4))
4815 enum machine_mode mode = (align >= 64 ? DImode : SImode);
4816 int inv_alignofs = (align >= 64 ? 8 : 4) - alignofs;
4817 rtx mem, tmp;
4818 HOST_WIDE_INT mask;
4820 mem = adjust_address (orig_dst, mode, ofs - inv_alignofs);
4821 set_mem_alias_set (mem, 0);
4823 mask = ~(~(HOST_WIDE_INT)0 << (inv_alignofs * 8));
4824 if (bytes < alignofs)
4826 mask |= ~(HOST_WIDE_INT)0 << ((inv_alignofs + bytes) * 8);
4827 ofs += bytes;
4828 bytes = 0;
4830 else
4832 bytes -= alignofs;
4833 ofs += alignofs;
4835 alignofs = 0;
4837 tmp = expand_binop (mode, and_optab, mem, GEN_INT (mask),
4838 NULL_RTX, 1, OPTAB_WIDEN);
4840 emit_move_insn (mem, tmp);
4842 #endif
4844 if (TARGET_BWX && (alignofs & 1) && bytes >= 1)
4846 emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
4847 bytes -= 1;
4848 ofs += 1;
4849 alignofs -= 1;
4851 if (TARGET_BWX && align >= 16 && (alignofs & 3) == 2 && bytes >= 2)
4853 emit_move_insn (adjust_address (orig_dst, HImode, ofs), const0_rtx);
4854 bytes -= 2;
4855 ofs += 2;
4856 alignofs -= 2;
4858 if (alignofs == 4 && bytes >= 4)
4860 emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4861 bytes -= 4;
4862 ofs += 4;
4863 alignofs = 0;
4866 /* If we've not used the extra lead alignment information by now,
4867 we won't be able to. Downgrade align to match what's left over. */
4868 if (alignofs > 0)
4870 alignofs = alignofs & -alignofs;
4871 align = MIN (align, alignofs * BITS_PER_UNIT);
4875 /* Handle a block of contiguous long-words. */
4877 if (align >= 64 && bytes >= 8)
4879 words = bytes / 8;
4881 for (i = 0; i < words; ++i)
4882 emit_move_insn (adjust_address (orig_dst, DImode, ofs + i * 8),
4883 const0_rtx);
4885 bytes -= words * 8;
4886 ofs += words * 8;
4889 /* If the block is large and appropriately aligned, emit a single
4890 store followed by a sequence of stq_u insns. */
4892 if (align >= 32 && bytes > 16)
4894 rtx orig_dsta;
4896 emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4897 bytes -= 4;
4898 ofs += 4;
4900 orig_dsta = XEXP (orig_dst, 0);
4901 if (GET_CODE (orig_dsta) == LO_SUM)
4902 orig_dsta = force_reg (Pmode, orig_dsta);
4904 words = bytes / 8;
4905 for (i = 0; i < words; ++i)
4907 rtx mem
4908 = change_address (orig_dst, DImode,
4909 gen_rtx_AND (DImode,
4910 plus_constant (orig_dsta, ofs + i*8),
4911 GEN_INT (-8)));
4912 set_mem_alias_set (mem, 0);
4913 emit_move_insn (mem, const0_rtx);
4916 /* Depending on the alignment, the first stq_u may have overlapped
4917 with the initial stl, which means that the last stq_u didn't
4918 write as much as it would appear. Leave those questionable bytes
4919 unaccounted for. */
4920 bytes -= words * 8 - 4;
4921 ofs += words * 8 - 4;
4924 /* Handle a smaller block of aligned words. */
4926 if ((align >= 64 && bytes == 4)
4927 || (align == 32 && bytes >= 4))
4929 words = bytes / 4;
4931 for (i = 0; i < words; ++i)
4932 emit_move_insn (adjust_address (orig_dst, SImode, ofs + i * 4),
4933 const0_rtx);
4935 bytes -= words * 4;
4936 ofs += words * 4;
4939 /* An unaligned block uses stq_u stores for as many as possible. */
4941 if (bytes >= 8)
4943 words = bytes / 8;
4945 alpha_expand_unaligned_store_words (NULL, orig_dst, words, ofs);
4947 bytes -= words * 8;
4948 ofs += words * 8;
4951 /* Next clean up any trailing pieces. */
4953 #if HOST_BITS_PER_WIDE_INT >= 64
4954 /* Count the number of bits in BYTES for which aligned stores could
4955 be emitted. */
4956 words = 0;
4957 for (i = (TARGET_BWX ? 1 : 4); i * BITS_PER_UNIT <= align ; i <<= 1)
4958 if (bytes & i)
4959 words += 1;
4961 /* If we have appropriate alignment (and it wouldn't take too many
4962 instructions otherwise), mask out the bytes we need. */
4963 if (TARGET_BWX ? words > 2 : bytes > 0)
4965 if (align >= 64)
4967 rtx mem, tmp;
4968 HOST_WIDE_INT mask;
4970 mem = adjust_address (orig_dst, DImode, ofs);
4971 set_mem_alias_set (mem, 0);
4973 mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
4975 tmp = expand_binop (DImode, and_optab, mem, GEN_INT (mask),
4976 NULL_RTX, 1, OPTAB_WIDEN);
4978 emit_move_insn (mem, tmp);
4979 return 1;
4981 else if (align >= 32 && bytes < 4)
4983 rtx mem, tmp;
4984 HOST_WIDE_INT mask;
4986 mem = adjust_address (orig_dst, SImode, ofs);
4987 set_mem_alias_set (mem, 0);
4989 mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
4991 tmp = expand_binop (SImode, and_optab, mem, GEN_INT (mask),
4992 NULL_RTX, 1, OPTAB_WIDEN);
4994 emit_move_insn (mem, tmp);
4995 return 1;
4998 #endif
5000 if (!TARGET_BWX && bytes >= 4)
5002 alpha_expand_unaligned_store (orig_dst, const0_rtx, 4, ofs);
5003 bytes -= 4;
5004 ofs += 4;
5007 if (bytes >= 2)
5009 if (align >= 16)
5011 do {
5012 emit_move_insn (adjust_address (orig_dst, HImode, ofs),
5013 const0_rtx);
5014 bytes -= 2;
5015 ofs += 2;
5016 } while (bytes >= 2);
5018 else if (! TARGET_BWX)
5020 alpha_expand_unaligned_store (orig_dst, const0_rtx, 2, ofs);
5021 bytes -= 2;
5022 ofs += 2;
5026 while (bytes > 0)
5028 emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
5029 bytes -= 1;
5030 ofs += 1;
5033 return 1;
5036 /* Returns a mask so that zap(x, value) == x & mask. */
5039 alpha_expand_zap_mask (HOST_WIDE_INT value)
5041 rtx result;
5042 int i;
5044 if (HOST_BITS_PER_WIDE_INT >= 64)
5046 HOST_WIDE_INT mask = 0;
5048 for (i = 7; i >= 0; --i)
5050 mask <<= 8;
5051 if (!((value >> i) & 1))
5052 mask |= 0xff;
5055 result = gen_int_mode (mask, DImode);
5057 else if (HOST_BITS_PER_WIDE_INT == 32)
5059 HOST_WIDE_INT mask_lo = 0, mask_hi = 0;
5061 for (i = 7; i >= 4; --i)
5063 mask_hi <<= 8;
5064 if (!((value >> i) & 1))
5065 mask_hi |= 0xff;
5068 for (i = 3; i >= 0; --i)
5070 mask_lo <<= 8;
5071 if (!((value >> i) & 1))
5072 mask_lo |= 0xff;
5075 result = immed_double_const (mask_lo, mask_hi, DImode);
5077 else
5078 abort ();
5080 return result;
5083 void
5084 alpha_expand_builtin_vector_binop (rtx (*gen) (rtx, rtx, rtx),
5085 enum machine_mode mode,
5086 rtx op0, rtx op1, rtx op2)
5088 op0 = gen_lowpart (mode, op0);
5090 if (op1 == const0_rtx)
5091 op1 = CONST0_RTX (mode);
5092 else
5093 op1 = gen_lowpart (mode, op1);
5095 if (op2 == const0_rtx)
5096 op2 = CONST0_RTX (mode);
5097 else
5098 op2 = gen_lowpart (mode, op2);
5100 emit_insn ((*gen) (op0, op1, op2));
5103 /* Adjust the cost of a scheduling dependency. Return the new cost of
5104 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
5106 static int
5107 alpha_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
5109 enum attr_type insn_type, dep_insn_type;
5111 /* If the dependence is an anti-dependence, there is no cost. For an
5112 output dependence, there is sometimes a cost, but it doesn't seem
5113 worth handling those few cases. */
5114 if (REG_NOTE_KIND (link) != 0)
5115 return cost;
5117 /* If we can't recognize the insns, we can't really do anything. */
5118 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
5119 return cost;
5121 insn_type = get_attr_type (insn);
5122 dep_insn_type = get_attr_type (dep_insn);
5124 /* Bring in the user-defined memory latency. */
5125 if (dep_insn_type == TYPE_ILD
5126 || dep_insn_type == TYPE_FLD
5127 || dep_insn_type == TYPE_LDSYM)
5128 cost += alpha_memory_latency-1;
5130 /* Everything else handled in DFA bypasses now. */
5132 return cost;
5135 /* The number of instructions that can be issued per cycle. */
5137 static int
5138 alpha_issue_rate (void)
5140 return (alpha_cpu == PROCESSOR_EV4 ? 2 : 4);
5143 static int
5144 alpha_use_dfa_pipeline_interface (void)
5146 return true;
5149 /* How many alternative schedules to try. This should be as wide as the
5150 scheduling freedom in the DFA, but no wider. Making this value too
5151 large results extra work for the scheduler.
5153 For EV4, loads can be issued to either IB0 or IB1, thus we have 2
5154 alternative schedules. For EV5, we can choose between E0/E1 and
5155 FA/FM. For EV6, an arithmetic insn can be issued to U0/U1/L0/L1. */
5157 static int
5158 alpha_multipass_dfa_lookahead (void)
5160 return (alpha_cpu == PROCESSOR_EV6 ? 4 : 2);
5163 /* Machine-specific function data. */
5165 struct machine_function GTY(())
5167 /* For unicosmk. */
5168 /* List of call information words for calls from this function. */
5169 struct rtx_def *first_ciw;
5170 struct rtx_def *last_ciw;
5171 int ciw_count;
5173 /* List of deferred case vectors. */
5174 struct rtx_def *addr_list;
5176 /* For OSF. */
5177 const char *some_ld_name;
5180 /* How to allocate a 'struct machine_function'. */
5182 static struct machine_function *
5183 alpha_init_machine_status (void)
5185 return ((struct machine_function *)
5186 ggc_alloc_cleared (sizeof (struct machine_function)));
5189 /* Functions to save and restore alpha_return_addr_rtx. */
5191 /* Start the ball rolling with RETURN_ADDR_RTX. */
5194 alpha_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
5196 if (count != 0)
5197 return const0_rtx;
5199 return get_hard_reg_initial_val (Pmode, REG_RA);
5202 /* Return or create a pseudo containing the gp value for the current
5203 function. Needed only if TARGET_LD_BUGGY_LDGP. */
5206 alpha_gp_save_rtx (void)
5208 rtx r = get_hard_reg_initial_val (DImode, 29);
5209 if (GET_CODE (r) != MEM)
5210 r = gen_mem_addressof (r, NULL_TREE, /*rescan=*/true);
5211 return r;
5214 static int
5215 alpha_ra_ever_killed (void)
5217 rtx top;
5219 if (!has_hard_reg_initial_val (Pmode, REG_RA))
5220 return regs_ever_live[REG_RA];
5222 push_topmost_sequence ();
5223 top = get_insns ();
5224 pop_topmost_sequence ();
5226 return reg_set_between_p (gen_rtx_REG (Pmode, REG_RA), top, NULL_RTX);
5230 /* Return the trap mode suffix applicable to the current
5231 instruction, or NULL. */
5233 static const char *
5234 get_trap_mode_suffix (void)
5236 enum attr_trap_suffix s = get_attr_trap_suffix (current_output_insn);
5238 switch (s)
5240 case TRAP_SUFFIX_NONE:
5241 return NULL;
5243 case TRAP_SUFFIX_SU:
5244 if (alpha_fptm >= ALPHA_FPTM_SU)
5245 return "su";
5246 return NULL;
5248 case TRAP_SUFFIX_SUI:
5249 if (alpha_fptm >= ALPHA_FPTM_SUI)
5250 return "sui";
5251 return NULL;
5253 case TRAP_SUFFIX_V_SV:
5254 switch (alpha_fptm)
5256 case ALPHA_FPTM_N:
5257 return NULL;
5258 case ALPHA_FPTM_U:
5259 return "v";
5260 case ALPHA_FPTM_SU:
5261 case ALPHA_FPTM_SUI:
5262 return "sv";
5264 break;
5266 case TRAP_SUFFIX_V_SV_SVI:
5267 switch (alpha_fptm)
5269 case ALPHA_FPTM_N:
5270 return NULL;
5271 case ALPHA_FPTM_U:
5272 return "v";
5273 case ALPHA_FPTM_SU:
5274 return "sv";
5275 case ALPHA_FPTM_SUI:
5276 return "svi";
5278 break;
5280 case TRAP_SUFFIX_U_SU_SUI:
5281 switch (alpha_fptm)
5283 case ALPHA_FPTM_N:
5284 return NULL;
5285 case ALPHA_FPTM_U:
5286 return "u";
5287 case ALPHA_FPTM_SU:
5288 return "su";
5289 case ALPHA_FPTM_SUI:
5290 return "sui";
5292 break;
5294 abort ();
5297 /* Return the rounding mode suffix applicable to the current
5298 instruction, or NULL. */
5300 static const char *
5301 get_round_mode_suffix (void)
5303 enum attr_round_suffix s = get_attr_round_suffix (current_output_insn);
5305 switch (s)
5307 case ROUND_SUFFIX_NONE:
5308 return NULL;
5309 case ROUND_SUFFIX_NORMAL:
5310 switch (alpha_fprm)
5312 case ALPHA_FPRM_NORM:
5313 return NULL;
5314 case ALPHA_FPRM_MINF:
5315 return "m";
5316 case ALPHA_FPRM_CHOP:
5317 return "c";
5318 case ALPHA_FPRM_DYN:
5319 return "d";
5321 break;
5323 case ROUND_SUFFIX_C:
5324 return "c";
5326 abort ();
5329 /* Locate some local-dynamic symbol still in use by this function
5330 so that we can print its name in some movdi_er_tlsldm pattern. */
5332 static int
5333 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
5335 rtx x = *px;
5337 if (GET_CODE (x) == SYMBOL_REF
5338 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
5340 cfun->machine->some_ld_name = XSTR (x, 0);
5341 return 1;
5344 return 0;
5347 static const char *
5348 get_some_local_dynamic_name (void)
5350 rtx insn;
5352 if (cfun->machine->some_ld_name)
5353 return cfun->machine->some_ld_name;
5355 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
5356 if (INSN_P (insn)
5357 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
5358 return cfun->machine->some_ld_name;
5360 abort ();
5363 /* Print an operand. Recognize special options, documented below. */
5365 void
5366 print_operand (FILE *file, rtx x, int code)
5368 int i;
5370 switch (code)
5372 case '~':
5373 /* Print the assembler name of the current function. */
5374 assemble_name (file, alpha_fnname);
5375 break;
5377 case '&':
5378 assemble_name (file, get_some_local_dynamic_name ());
5379 break;
5381 case '/':
5383 const char *trap = get_trap_mode_suffix ();
5384 const char *round = get_round_mode_suffix ();
5386 if (trap || round)
5387 fprintf (file, (TARGET_AS_SLASH_BEFORE_SUFFIX ? "/%s%s" : "%s%s"),
5388 (trap ? trap : ""), (round ? round : ""));
5389 break;
5392 case ',':
5393 /* Generates single precision instruction suffix. */
5394 fputc ((TARGET_FLOAT_VAX ? 'f' : 's'), file);
5395 break;
5397 case '-':
5398 /* Generates double precision instruction suffix. */
5399 fputc ((TARGET_FLOAT_VAX ? 'g' : 't'), file);
5400 break;
5402 case '+':
5403 /* Generates a nop after a noreturn call at the very end of the
5404 function. */
5405 if (next_real_insn (current_output_insn) == 0)
5406 fprintf (file, "\n\tnop");
5407 break;
5409 case '#':
5410 if (alpha_this_literal_sequence_number == 0)
5411 alpha_this_literal_sequence_number = alpha_next_sequence_number++;
5412 fprintf (file, "%d", alpha_this_literal_sequence_number);
5413 break;
5415 case '*':
5416 if (alpha_this_gpdisp_sequence_number == 0)
5417 alpha_this_gpdisp_sequence_number = alpha_next_sequence_number++;
5418 fprintf (file, "%d", alpha_this_gpdisp_sequence_number);
5419 break;
5421 case 'H':
5422 if (GET_CODE (x) == HIGH)
5423 output_addr_const (file, XEXP (x, 0));
5424 else
5425 output_operand_lossage ("invalid %%H value");
5426 break;
5428 case 'J':
5430 const char *lituse;
5432 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSGD_CALL)
5434 x = XVECEXP (x, 0, 0);
5435 lituse = "lituse_tlsgd";
5437 else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSLDM_CALL)
5439 x = XVECEXP (x, 0, 0);
5440 lituse = "lituse_tlsldm";
5442 else if (GET_CODE (x) == CONST_INT)
5443 lituse = "lituse_jsr";
5444 else
5446 output_operand_lossage ("invalid %%J value");
5447 break;
5450 if (x != const0_rtx)
5451 fprintf (file, "\t\t!%s!%d", lituse, (int) INTVAL (x));
5453 break;
5455 case 'r':
5456 /* If this operand is the constant zero, write it as "$31". */
5457 if (GET_CODE (x) == REG)
5458 fprintf (file, "%s", reg_names[REGNO (x)]);
5459 else if (x == CONST0_RTX (GET_MODE (x)))
5460 fprintf (file, "$31");
5461 else
5462 output_operand_lossage ("invalid %%r value");
5463 break;
5465 case 'R':
5466 /* Similar, but for floating-point. */
5467 if (GET_CODE (x) == REG)
5468 fprintf (file, "%s", reg_names[REGNO (x)]);
5469 else if (x == CONST0_RTX (GET_MODE (x)))
5470 fprintf (file, "$f31");
5471 else
5472 output_operand_lossage ("invalid %%R value");
5473 break;
5475 case 'N':
5476 /* Write the 1's complement of a constant. */
5477 if (GET_CODE (x) != CONST_INT)
5478 output_operand_lossage ("invalid %%N value");
5480 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
5481 break;
5483 case 'P':
5484 /* Write 1 << C, for a constant C. */
5485 if (GET_CODE (x) != CONST_INT)
5486 output_operand_lossage ("invalid %%P value");
5488 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) 1 << INTVAL (x));
5489 break;
5491 case 'h':
5492 /* Write the high-order 16 bits of a constant, sign-extended. */
5493 if (GET_CODE (x) != CONST_INT)
5494 output_operand_lossage ("invalid %%h value");
5496 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) >> 16);
5497 break;
5499 case 'L':
5500 /* Write the low-order 16 bits of a constant, sign-extended. */
5501 if (GET_CODE (x) != CONST_INT)
5502 output_operand_lossage ("invalid %%L value");
5504 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5505 (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
5506 break;
5508 case 'm':
5509 /* Write mask for ZAP insn. */
5510 if (GET_CODE (x) == CONST_DOUBLE)
5512 HOST_WIDE_INT mask = 0;
5513 HOST_WIDE_INT value;
5515 value = CONST_DOUBLE_LOW (x);
5516 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5517 i++, value >>= 8)
5518 if (value & 0xff)
5519 mask |= (1 << i);
5521 value = CONST_DOUBLE_HIGH (x);
5522 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5523 i++, value >>= 8)
5524 if (value & 0xff)
5525 mask |= (1 << (i + sizeof (int)));
5527 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask & 0xff);
5530 else if (GET_CODE (x) == CONST_INT)
5532 HOST_WIDE_INT mask = 0, value = INTVAL (x);
5534 for (i = 0; i < 8; i++, value >>= 8)
5535 if (value & 0xff)
5536 mask |= (1 << i);
5538 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask);
5540 else
5541 output_operand_lossage ("invalid %%m value");
5542 break;
5544 case 'M':
5545 /* 'b', 'w', 'l', or 'q' as the value of the constant. */
5546 if (GET_CODE (x) != CONST_INT
5547 || (INTVAL (x) != 8 && INTVAL (x) != 16
5548 && INTVAL (x) != 32 && INTVAL (x) != 64))
5549 output_operand_lossage ("invalid %%M value");
5551 fprintf (file, "%s",
5552 (INTVAL (x) == 8 ? "b"
5553 : INTVAL (x) == 16 ? "w"
5554 : INTVAL (x) == 32 ? "l"
5555 : "q"));
5556 break;
5558 case 'U':
5559 /* Similar, except do it from the mask. */
5560 if (GET_CODE (x) == CONST_INT)
5562 HOST_WIDE_INT value = INTVAL (x);
5564 if (value == 0xff)
5566 fputc ('b', file);
5567 break;
5569 if (value == 0xffff)
5571 fputc ('w', file);
5572 break;
5574 if (value == 0xffffffff)
5576 fputc ('l', file);
5577 break;
5579 if (value == -1)
5581 fputc ('q', file);
5582 break;
5585 else if (HOST_BITS_PER_WIDE_INT == 32
5586 && GET_CODE (x) == CONST_DOUBLE
5587 && CONST_DOUBLE_LOW (x) == 0xffffffff
5588 && CONST_DOUBLE_HIGH (x) == 0)
5590 fputc ('l', file);
5591 break;
5593 output_operand_lossage ("invalid %%U value");
5594 break;
5596 case 's':
5597 /* Write the constant value divided by 8 for little-endian mode or
5598 (56 - value) / 8 for big-endian mode. */
5600 if (GET_CODE (x) != CONST_INT
5601 || (unsigned HOST_WIDE_INT) INTVAL (x) >= (WORDS_BIG_ENDIAN
5602 ? 56
5603 : 64)
5604 || (INTVAL (x) & 7) != 0)
5605 output_operand_lossage ("invalid %%s value");
5607 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5608 WORDS_BIG_ENDIAN
5609 ? (56 - INTVAL (x)) / 8
5610 : INTVAL (x) / 8);
5611 break;
5613 case 'S':
5614 /* Same, except compute (64 - c) / 8 */
5616 if (GET_CODE (x) != CONST_INT
5617 && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
5618 && (INTVAL (x) & 7) != 8)
5619 output_operand_lossage ("invalid %%s value");
5621 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (64 - INTVAL (x)) / 8);
5622 break;
5624 case 't':
5626 /* On Unicos/Mk systems: use a DEX expression if the symbol
5627 clashes with a register name. */
5628 int dex = unicosmk_need_dex (x);
5629 if (dex)
5630 fprintf (file, "DEX(%d)", dex);
5631 else
5632 output_addr_const (file, x);
5634 break;
5636 case 'C': case 'D': case 'c': case 'd':
5637 /* Write out comparison name. */
5639 enum rtx_code c = GET_CODE (x);
5641 if (GET_RTX_CLASS (c) != '<')
5642 output_operand_lossage ("invalid %%C value");
5644 else if (code == 'D')
5645 c = reverse_condition (c);
5646 else if (code == 'c')
5647 c = swap_condition (c);
5648 else if (code == 'd')
5649 c = swap_condition (reverse_condition (c));
5651 if (c == LEU)
5652 fprintf (file, "ule");
5653 else if (c == LTU)
5654 fprintf (file, "ult");
5655 else if (c == UNORDERED)
5656 fprintf (file, "un");
5657 else
5658 fprintf (file, "%s", GET_RTX_NAME (c));
5660 break;
5662 case 'E':
5663 /* Write the divide or modulus operator. */
5664 switch (GET_CODE (x))
5666 case DIV:
5667 fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
5668 break;
5669 case UDIV:
5670 fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
5671 break;
5672 case MOD:
5673 fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
5674 break;
5675 case UMOD:
5676 fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
5677 break;
5678 default:
5679 output_operand_lossage ("invalid %%E value");
5680 break;
5682 break;
5684 case 'A':
5685 /* Write "_u" for unaligned access. */
5686 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
5687 fprintf (file, "_u");
5688 break;
5690 case 0:
5691 if (GET_CODE (x) == REG)
5692 fprintf (file, "%s", reg_names[REGNO (x)]);
5693 else if (GET_CODE (x) == MEM)
5694 output_address (XEXP (x, 0));
5695 else if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == UNSPEC)
5697 switch (XINT (XEXP (x, 0), 1))
5699 case UNSPEC_DTPREL:
5700 case UNSPEC_TPREL:
5701 output_addr_const (file, XVECEXP (XEXP (x, 0), 0, 0));
5702 break;
5703 default:
5704 output_operand_lossage ("unknown relocation unspec");
5705 break;
5708 else
5709 output_addr_const (file, x);
5710 break;
5712 default:
5713 output_operand_lossage ("invalid %%xn code");
5717 void
5718 print_operand_address (FILE *file, rtx addr)
5720 int basereg = 31;
5721 HOST_WIDE_INT offset = 0;
5723 if (GET_CODE (addr) == AND)
5724 addr = XEXP (addr, 0);
5726 if (GET_CODE (addr) == PLUS
5727 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5729 offset = INTVAL (XEXP (addr, 1));
5730 addr = XEXP (addr, 0);
5733 if (GET_CODE (addr) == LO_SUM)
5735 const char *reloc16, *reloclo;
5736 rtx op1 = XEXP (addr, 1);
5738 if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1, 0)) == UNSPEC)
5740 op1 = XEXP (op1, 0);
5741 switch (XINT (op1, 1))
5743 case UNSPEC_DTPREL:
5744 reloc16 = NULL;
5745 reloclo = (alpha_tls_size == 16 ? "dtprel" : "dtprello");
5746 break;
5747 case UNSPEC_TPREL:
5748 reloc16 = NULL;
5749 reloclo = (alpha_tls_size == 16 ? "tprel" : "tprello");
5750 break;
5751 default:
5752 output_operand_lossage ("unknown relocation unspec");
5753 return;
5756 output_addr_const (file, XVECEXP (op1, 0, 0));
5758 else
5760 reloc16 = "gprel";
5761 reloclo = "gprellow";
5762 output_addr_const (file, op1);
5765 if (offset)
5766 fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC, offset);
5768 addr = XEXP (addr, 0);
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
5775 abort ();
5777 fprintf (file, "($%d)\t\t!%s", basereg,
5778 (basereg == 29 ? reloc16 : reloclo));
5779 return;
5782 if (GET_CODE (addr) == REG)
5783 basereg = REGNO (addr);
5784 else if (GET_CODE (addr) == SUBREG
5785 && GET_CODE (SUBREG_REG (addr)) == REG)
5786 basereg = subreg_regno (addr);
5787 else if (GET_CODE (addr) == CONST_INT)
5788 offset = INTVAL (addr);
5790 #if TARGET_ABI_OPEN_VMS
5791 else if (GET_CODE (addr) == SYMBOL_REF)
5793 fprintf (file, "%s", XSTR (addr, 0));
5794 return;
5796 else if (GET_CODE (addr) == CONST
5797 && GET_CODE (XEXP (addr, 0)) == PLUS
5798 && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF)
5800 fprintf (file, "%s+" HOST_WIDE_INT_PRINT_DEC,
5801 XSTR (XEXP (XEXP (addr, 0), 0), 0),
5802 INTVAL (XEXP (XEXP (addr, 0), 1)));
5803 return;
5805 #endif
5807 else
5808 abort ();
5810 fprintf (file, HOST_WIDE_INT_PRINT_DEC "($%d)", offset, basereg);
5813 /* Emit RTL insns to initialize the variable parts of a trampoline at
5814 TRAMP. FNADDR is an RTX for the address of the function's pure
5815 code. CXT is an RTX for the static chain value for the function.
5817 The three offset parameters are for the individual template's
5818 layout. A JMPOFS < 0 indicates that the trampoline does not
5819 contain instructions at all.
5821 We assume here that a function will be called many more times than
5822 its address is taken (e.g., it might be passed to qsort), so we
5823 take the trouble to initialize the "hint" field in the JMP insn.
5824 Note that the hint field is PC (new) + 4 * bits 13:0. */
5826 void
5827 alpha_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt,
5828 int fnofs, int cxtofs, int jmpofs)
5830 rtx temp, temp1, addr;
5831 /* VMS really uses DImode pointers in memory at this point. */
5832 enum machine_mode mode = TARGET_ABI_OPEN_VMS ? Pmode : ptr_mode;
5834 #ifdef POINTERS_EXTEND_UNSIGNED
5835 fnaddr = convert_memory_address (mode, fnaddr);
5836 cxt = convert_memory_address (mode, cxt);
5837 #endif
5839 /* Store function address and CXT. */
5840 addr = memory_address (mode, plus_constant (tramp, fnofs));
5841 emit_move_insn (gen_rtx_MEM (mode, addr), fnaddr);
5842 addr = memory_address (mode, plus_constant (tramp, cxtofs));
5843 emit_move_insn (gen_rtx_MEM (mode, addr), cxt);
5845 /* This has been disabled since the hint only has a 32k range, and in
5846 no existing OS is the stack within 32k of the text segment. */
5847 if (0 && jmpofs >= 0)
5849 /* Compute hint value. */
5850 temp = force_operand (plus_constant (tramp, jmpofs+4), NULL_RTX);
5851 temp = expand_binop (DImode, sub_optab, fnaddr, temp, temp, 1,
5852 OPTAB_WIDEN);
5853 temp = expand_shift (RSHIFT_EXPR, Pmode, temp,
5854 build_int_2 (2, 0), NULL_RTX, 1);
5855 temp = expand_and (SImode, gen_lowpart (SImode, temp),
5856 GEN_INT (0x3fff), 0);
5858 /* Merge in the hint. */
5859 addr = memory_address (SImode, plus_constant (tramp, jmpofs));
5860 temp1 = force_reg (SImode, gen_rtx_MEM (SImode, addr));
5861 temp1 = expand_and (SImode, temp1, GEN_INT (0xffffc000), NULL_RTX);
5862 temp1 = expand_binop (SImode, ior_optab, temp1, temp, temp1, 1,
5863 OPTAB_WIDEN);
5864 emit_move_insn (gen_rtx_MEM (SImode, addr), temp1);
5867 #ifdef TRANSFER_FROM_TRAMPOLINE
5868 emit_library_call (init_one_libfunc ("__enable_execute_stack"),
5869 0, VOIDmode, 1, tramp, Pmode);
5870 #endif
5872 if (jmpofs >= 0)
5873 emit_insn (gen_imb ());
5876 /* Determine where to put an argument to a function.
5877 Value is zero to push the argument on the stack,
5878 or a hard register in which to store the argument.
5880 MODE is the argument's machine mode.
5881 TYPE is the data type of the argument (as a tree).
5882 This is null for libcalls where that information may
5883 not be available.
5884 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5885 the preceding args and about the function being called.
5886 NAMED is nonzero if this argument is a named parameter
5887 (otherwise it is an extra parameter matching an ellipsis).
5889 On Alpha the first 6 words of args are normally in registers
5890 and the rest are pushed. */
5893 function_arg (CUMULATIVE_ARGS cum, enum machine_mode mode, tree type,
5894 int named ATTRIBUTE_UNUSED)
5896 int basereg;
5897 int num_args;
5899 /* Don't get confused and pass small structures in FP registers. */
5900 if (type && AGGREGATE_TYPE_P (type))
5901 basereg = 16;
5902 else
5904 #ifdef ENABLE_CHECKING
5905 /* With alpha_split_complex_arg, we shouldn't see any raw complex
5906 values here. */
5907 if (COMPLEX_MODE_P (mode))
5908 abort ();
5909 #endif
5911 /* Set up defaults for FP operands passed in FP registers, and
5912 integral operands passed in integer registers. */
5913 if (TARGET_FPREGS && GET_MODE_CLASS (mode) == MODE_FLOAT)
5914 basereg = 32 + 16;
5915 else
5916 basereg = 16;
5919 /* ??? Irritatingly, the definition of CUMULATIVE_ARGS is different for
5920 the three platforms, so we can't avoid conditional compilation. */
5921 #if TARGET_ABI_OPEN_VMS
5923 if (mode == VOIDmode)
5924 return alpha_arg_info_reg_val (cum);
5926 num_args = cum.num_args;
5927 if (num_args >= 6 || MUST_PASS_IN_STACK (mode, type))
5928 return NULL_RTX;
5930 #elif TARGET_ABI_UNICOSMK
5932 int size;
5934 /* If this is the last argument, generate the call info word (CIW). */
5935 /* ??? We don't include the caller's line number in the CIW because
5936 I don't know how to determine it if debug infos are turned off. */
5937 if (mode == VOIDmode)
5939 int i;
5940 HOST_WIDE_INT lo;
5941 HOST_WIDE_INT hi;
5942 rtx ciw;
5944 lo = 0;
5946 for (i = 0; i < cum.num_reg_words && i < 5; i++)
5947 if (cum.reg_args_type[i])
5948 lo |= (1 << (7 - i));
5950 if (cum.num_reg_words == 6 && cum.reg_args_type[5])
5951 lo |= 7;
5952 else
5953 lo |= cum.num_reg_words;
5955 #if HOST_BITS_PER_WIDE_INT == 32
5956 hi = (cum.num_args << 20) | cum.num_arg_words;
5957 #else
5958 lo = lo | ((HOST_WIDE_INT) cum.num_args << 52)
5959 | ((HOST_WIDE_INT) cum.num_arg_words << 32);
5960 hi = 0;
5961 #endif
5962 ciw = immed_double_const (lo, hi, DImode);
5964 return gen_rtx_UNSPEC (DImode, gen_rtvec (1, ciw),
5965 UNSPEC_UMK_LOAD_CIW);
5968 size = ALPHA_ARG_SIZE (mode, type, named);
5969 num_args = cum.num_reg_words;
5970 if (MUST_PASS_IN_STACK (mode, type)
5971 || cum.num_reg_words + size > 6 || cum.force_stack)
5972 return NULL_RTX;
5973 else if (type && TYPE_MODE (type) == BLKmode)
5975 rtx reg1, reg2;
5977 reg1 = gen_rtx_REG (DImode, num_args + 16);
5978 reg1 = gen_rtx_EXPR_LIST (DImode, reg1, const0_rtx);
5980 /* The argument fits in two registers. Note that we still need to
5981 reserve a register for empty structures. */
5982 if (size == 0)
5983 return NULL_RTX;
5984 else if (size == 1)
5985 return gen_rtx_PARALLEL (mode, gen_rtvec (1, reg1));
5986 else
5988 reg2 = gen_rtx_REG (DImode, num_args + 17);
5989 reg2 = gen_rtx_EXPR_LIST (DImode, reg2, GEN_INT (8));
5990 return gen_rtx_PARALLEL (mode, gen_rtvec (2, reg1, reg2));
5994 #elif TARGET_ABI_OSF
5996 if (cum >= 6)
5997 return NULL_RTX;
5998 num_args = cum;
6000 /* VOID is passed as a special flag for "last argument". */
6001 if (type == void_type_node)
6002 basereg = 16;
6003 else if (MUST_PASS_IN_STACK (mode, type))
6004 return NULL_RTX;
6005 else if (FUNCTION_ARG_PASS_BY_REFERENCE (cum, mode, type, named))
6006 basereg = 16;
6008 #else
6009 #error Unhandled ABI
6010 #endif
6012 return gen_rtx_REG (mode, num_args + basereg);
6015 /* Return true if TYPE must be returned in memory, instead of in registers. */
6017 static bool
6018 alpha_return_in_memory (tree type, tree fndecl ATTRIBUTE_UNUSED)
6020 enum machine_mode mode = VOIDmode;
6021 int size;
6023 if (type)
6025 mode = TYPE_MODE (type);
6027 /* All aggregates are returned in memory. */
6028 if (AGGREGATE_TYPE_P (type))
6029 return true;
6032 size = GET_MODE_SIZE (mode);
6033 switch (GET_MODE_CLASS (mode))
6035 case MODE_VECTOR_FLOAT:
6036 /* Pass all float vectors in memory, like an aggregate. */
6037 return true;
6039 case MODE_COMPLEX_FLOAT:
6040 /* We judge complex floats on the size of their element,
6041 not the size of the whole type. */
6042 size = GET_MODE_UNIT_SIZE (mode);
6043 break;
6045 case MODE_INT:
6046 case MODE_FLOAT:
6047 case MODE_COMPLEX_INT:
6048 case MODE_VECTOR_INT:
6049 break;
6051 default:
6052 /* ??? We get called on all sorts of random stuff from
6053 aggregate_value_p. We can't abort, but it's not clear
6054 what's safe to return. Pretend it's a struct I guess. */
6055 return true;
6058 /* Otherwise types must fit in one register. */
6059 return size > UNITS_PER_WORD;
6062 /* Define how to find the value returned by a function. VALTYPE is the
6063 data type of the value (as a tree). If the precise function being
6064 called is known, FUNC is its FUNCTION_DECL; otherwise, FUNC is 0.
6065 MODE is set instead of VALTYPE for libcalls.
6067 On Alpha the value is found in $0 for integer functions and
6068 $f0 for floating-point functions. */
6071 function_value (tree valtype, tree func ATTRIBUTE_UNUSED,
6072 enum machine_mode mode)
6074 unsigned int regnum;
6075 enum mode_class class;
6077 #ifdef ENABLE_CHECKING
6078 if (valtype && alpha_return_in_memory (valtype, func))
6079 abort ();
6080 #endif
6082 if (valtype)
6083 mode = TYPE_MODE (valtype);
6085 class = GET_MODE_CLASS (mode);
6086 switch (class)
6088 case MODE_INT:
6089 /* Do the same thing as PROMOTE_MODE. */
6090 mode = DImode;
6091 /* FALLTHRU */
6093 case MODE_COMPLEX_INT:
6094 case MODE_VECTOR_INT:
6095 regnum = 0;
6096 break;
6098 case MODE_FLOAT:
6099 regnum = 32;
6100 break;
6102 case MODE_COMPLEX_FLOAT:
6104 enum machine_mode cmode = GET_MODE_INNER (mode);
6106 return gen_rtx_PARALLEL
6107 (VOIDmode,
6108 gen_rtvec (2,
6109 gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 32),
6110 GEN_INT (0)),
6111 gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 33),
6112 GEN_INT (GET_MODE_SIZE (cmode)))));
6115 default:
6116 abort ();
6119 return gen_rtx_REG (mode, regnum);
6122 /* TCmode complex values are passed by invisible reference. We
6123 should not split these values. */
6125 static bool
6126 alpha_split_complex_arg (tree type)
6128 return TYPE_MODE (type) != TCmode;
6131 static tree
6132 alpha_build_builtin_va_list (void)
6134 tree base, ofs, space, record, type_decl;
6136 if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
6137 return ptr_type_node;
6139 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6140 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6141 TREE_CHAIN (record) = type_decl;
6142 TYPE_NAME (record) = type_decl;
6144 /* C++? SET_IS_AGGR_TYPE (record, 1); */
6146 /* Dummy field to prevent alignment warnings. */
6147 space = build_decl (FIELD_DECL, NULL_TREE, integer_type_node);
6148 DECL_FIELD_CONTEXT (space) = record;
6149 DECL_ARTIFICIAL (space) = 1;
6150 DECL_IGNORED_P (space) = 1;
6152 ofs = build_decl (FIELD_DECL, get_identifier ("__offset"),
6153 integer_type_node);
6154 DECL_FIELD_CONTEXT (ofs) = record;
6155 TREE_CHAIN (ofs) = space;
6157 base = build_decl (FIELD_DECL, get_identifier ("__base"),
6158 ptr_type_node);
6159 DECL_FIELD_CONTEXT (base) = record;
6160 TREE_CHAIN (base) = ofs;
6162 TYPE_FIELDS (record) = base;
6163 layout_type (record);
6165 return record;
6168 /* Perform any needed actions needed for a function that is receiving a
6169 variable number of arguments. */
6171 static void
6172 alpha_setup_incoming_varargs (CUMULATIVE_ARGS *pcum,
6173 enum machine_mode mode ATTRIBUTE_UNUSED,
6174 tree type ATTRIBUTE_UNUSED,
6175 int *pretend_size, int no_rtl)
6177 #if TARGET_ABI_UNICOSMK
6178 /* On Unicos/Mk, the standard subroutine __T3E_MISMATCH stores all register
6179 arguments on the stack. Unfortunately, it doesn't always store the first
6180 one (i.e. the one that arrives in $16 or $f16). This is not a problem
6181 with stdargs as we always have at least one named argument there. */
6182 int num_reg_words = pcum->num_reg_words;
6183 if (num_reg_words < 6)
6185 if (!no_rtl)
6187 emit_insn (gen_umk_mismatch_args (GEN_INT (num_reg_words + 1)));
6188 emit_insn (gen_arg_home_umk ());
6190 *pretend_size = 0;
6192 #elif TARGET_ABI_OPEN_VMS
6193 /* For VMS, we allocate space for all 6 arg registers plus a count.
6195 However, if NO registers need to be saved, don't allocate any space.
6196 This is not only because we won't need the space, but because AP
6197 includes the current_pretend_args_size and we don't want to mess up
6198 any ap-relative addresses already made. */
6199 if (pcum->num_args < 6)
6201 if (!no_rtl)
6203 emit_move_insn (gen_rtx_REG (DImode, 1), virtual_incoming_args_rtx);
6204 emit_insn (gen_arg_home ());
6206 *pretend_size = 7 * UNITS_PER_WORD;
6208 #else
6209 /* On OSF/1 and friends, we allocate space for all 12 arg registers, but
6210 only push those that are remaining. However, if NO registers need to
6211 be saved, don't allocate any space. This is not only because we won't
6212 need the space, but because AP includes the current_pretend_args_size
6213 and we don't want to mess up any ap-relative addresses already made.
6215 If we are not to use the floating-point registers, save the integer
6216 registers where we would put the floating-point registers. This is
6217 not the most efficient way to implement varargs with just one register
6218 class, but it isn't worth doing anything more efficient in this rare
6219 case. */
6220 CUMULATIVE_ARGS cum = *pcum;
6222 if (cum >= 6)
6223 return;
6225 if (!no_rtl)
6227 int set = get_varargs_alias_set ();
6228 rtx tmp;
6230 tmp = gen_rtx_MEM (BLKmode,
6231 plus_constant (virtual_incoming_args_rtx,
6232 (cum + 6) * UNITS_PER_WORD));
6233 set_mem_alias_set (tmp, set);
6234 move_block_from_reg (16 + cum, tmp, 6 - cum);
6236 tmp = gen_rtx_MEM (BLKmode,
6237 plus_constant (virtual_incoming_args_rtx,
6238 cum * UNITS_PER_WORD));
6239 set_mem_alias_set (tmp, set);
6240 move_block_from_reg (16 + (TARGET_FPREGS ? 32 : 0) + cum, tmp,
6241 6 - cum);
6243 *pretend_size = 12 * UNITS_PER_WORD;
6244 #endif
6247 void
6248 alpha_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
6250 HOST_WIDE_INT offset;
6251 tree t, offset_field, base_field;
6253 if (TREE_CODE (TREE_TYPE (valist)) == ERROR_MARK)
6254 return;
6256 if (TARGET_ABI_UNICOSMK)
6257 std_expand_builtin_va_start (valist, nextarg);
6259 /* For Unix, SETUP_INCOMING_VARARGS moves the starting address base
6260 up by 48, storing fp arg registers in the first 48 bytes, and the
6261 integer arg registers in the next 48 bytes. This is only done,
6262 however, if any integer registers need to be stored.
6264 If no integer registers need be stored, then we must subtract 48
6265 in order to account for the integer arg registers which are counted
6266 in argsize above, but which are not actually stored on the stack.
6267 Must further be careful here about structures straddling the last
6268 integer argument register; that futzes with pretend_args_size,
6269 which changes the meaning of AP. */
6271 if (NUM_ARGS <= 6)
6272 offset = TARGET_ABI_OPEN_VMS ? UNITS_PER_WORD : 6 * UNITS_PER_WORD;
6273 else
6274 offset = -6 * UNITS_PER_WORD + current_function_pretend_args_size;
6276 if (TARGET_ABI_OPEN_VMS)
6278 nextarg = plus_constant (nextarg, offset);
6279 nextarg = plus_constant (nextarg, NUM_ARGS * UNITS_PER_WORD);
6280 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
6281 make_tree (ptr_type_node, nextarg));
6282 TREE_SIDE_EFFECTS (t) = 1;
6284 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6286 else
6288 base_field = TYPE_FIELDS (TREE_TYPE (valist));
6289 offset_field = TREE_CHAIN (base_field);
6291 base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6292 valist, base_field);
6293 offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6294 valist, offset_field);
6296 t = make_tree (ptr_type_node, virtual_incoming_args_rtx);
6297 t = build (PLUS_EXPR, ptr_type_node, t, build_int_2 (offset, 0));
6298 t = build (MODIFY_EXPR, TREE_TYPE (base_field), base_field, t);
6299 TREE_SIDE_EFFECTS (t) = 1;
6300 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6302 t = build_int_2 (NUM_ARGS * UNITS_PER_WORD, 0);
6303 t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field, t);
6304 TREE_SIDE_EFFECTS (t) = 1;
6305 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6310 alpha_va_arg (tree valist, tree type)
6312 rtx addr;
6313 tree t, type_size, rounded_size;
6314 tree offset_field, base_field, addr_tree, addend;
6315 tree wide_type, wide_ofs;
6316 int indirect = 0;
6318 if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
6319 return std_expand_builtin_va_arg (valist, type);
6321 if (type == error_mark_node
6322 || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
6323 || TREE_OVERFLOW (type_size))
6324 rounded_size = size_zero_node;
6325 else
6326 rounded_size = fold (build (MULT_EXPR, sizetype,
6327 fold (build (TRUNC_DIV_EXPR, sizetype,
6328 fold (build (PLUS_EXPR, sizetype,
6329 type_size,
6330 size_int (7))),
6331 size_int (8))),
6332 size_int (8)));
6334 base_field = TYPE_FIELDS (TREE_TYPE (valist));
6335 offset_field = TREE_CHAIN (base_field);
6337 base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6338 valist, base_field);
6339 offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6340 valist, offset_field);
6342 /* If the type could not be passed in registers, skip the block
6343 reserved for the registers. */
6344 if (MUST_PASS_IN_STACK (TYPE_MODE (type), type))
6346 t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field,
6347 build (MAX_EXPR, TREE_TYPE (offset_field),
6348 offset_field, build_int_2 (6*8, 0)));
6349 TREE_SIDE_EFFECTS (t) = 1;
6350 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6353 wide_type = make_signed_type (64);
6354 wide_ofs = save_expr (build1 (CONVERT_EXPR, wide_type, offset_field));
6356 addend = wide_ofs;
6358 if (TYPE_MODE (type) == TFmode || TYPE_MODE (type) == TCmode)
6360 indirect = 1;
6361 rounded_size = size_int (UNITS_PER_WORD);
6363 else if (TREE_CODE (type) == COMPLEX_TYPE)
6365 rtx real_part, imag_part, value, tmp;
6367 real_part = alpha_va_arg (valist, TREE_TYPE (type));
6368 imag_part = alpha_va_arg (valist, TREE_TYPE (type));
6370 /* ??? Most irritatingly, we're not returning the value here,
6371 but the address. Since real_part and imag_part are not
6372 necessarily contiguous, we must copy to local storage. */
6374 real_part = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (type)), real_part);
6375 imag_part = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (type)), imag_part);
6376 value = gen_rtx_CONCAT (TYPE_MODE (type), real_part, imag_part);
6378 tmp = assign_temp (type, 0, 1, 0);
6379 emit_move_insn (tmp, value);
6381 return XEXP (tmp, 0);
6383 else if (TREE_CODE (type) == REAL_TYPE)
6385 tree fpaddend, cond;
6387 fpaddend = fold (build (PLUS_EXPR, TREE_TYPE (addend),
6388 addend, build_int_2 (-6*8, 0)));
6390 cond = fold (build (LT_EXPR, integer_type_node,
6391 wide_ofs, build_int_2 (6*8, 0)));
6393 addend = fold (build (COND_EXPR, TREE_TYPE (addend), cond,
6394 fpaddend, addend));
6397 addr_tree = build (PLUS_EXPR, TREE_TYPE (base_field),
6398 base_field, addend);
6400 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
6401 addr = copy_to_reg (addr);
6403 t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field,
6404 build (PLUS_EXPR, TREE_TYPE (offset_field),
6405 offset_field, rounded_size));
6406 TREE_SIDE_EFFECTS (t) = 1;
6407 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6409 if (indirect)
6411 addr = force_reg (Pmode, addr);
6412 addr = gen_rtx_MEM (Pmode, addr);
6415 return addr;
6418 /* Builtins. */
6420 enum alpha_builtin
6422 ALPHA_BUILTIN_CMPBGE,
6423 ALPHA_BUILTIN_EXTBL,
6424 ALPHA_BUILTIN_EXTWL,
6425 ALPHA_BUILTIN_EXTLL,
6426 ALPHA_BUILTIN_EXTQL,
6427 ALPHA_BUILTIN_EXTWH,
6428 ALPHA_BUILTIN_EXTLH,
6429 ALPHA_BUILTIN_EXTQH,
6430 ALPHA_BUILTIN_INSBL,
6431 ALPHA_BUILTIN_INSWL,
6432 ALPHA_BUILTIN_INSLL,
6433 ALPHA_BUILTIN_INSQL,
6434 ALPHA_BUILTIN_INSWH,
6435 ALPHA_BUILTIN_INSLH,
6436 ALPHA_BUILTIN_INSQH,
6437 ALPHA_BUILTIN_MSKBL,
6438 ALPHA_BUILTIN_MSKWL,
6439 ALPHA_BUILTIN_MSKLL,
6440 ALPHA_BUILTIN_MSKQL,
6441 ALPHA_BUILTIN_MSKWH,
6442 ALPHA_BUILTIN_MSKLH,
6443 ALPHA_BUILTIN_MSKQH,
6444 ALPHA_BUILTIN_UMULH,
6445 ALPHA_BUILTIN_ZAP,
6446 ALPHA_BUILTIN_ZAPNOT,
6447 ALPHA_BUILTIN_AMASK,
6448 ALPHA_BUILTIN_IMPLVER,
6449 ALPHA_BUILTIN_RPCC,
6450 ALPHA_BUILTIN_THREAD_POINTER,
6451 ALPHA_BUILTIN_SET_THREAD_POINTER,
6453 /* TARGET_MAX */
6454 ALPHA_BUILTIN_MINUB8,
6455 ALPHA_BUILTIN_MINSB8,
6456 ALPHA_BUILTIN_MINUW4,
6457 ALPHA_BUILTIN_MINSW4,
6458 ALPHA_BUILTIN_MAXUB8,
6459 ALPHA_BUILTIN_MAXSB8,
6460 ALPHA_BUILTIN_MAXUW4,
6461 ALPHA_BUILTIN_MAXSW4,
6462 ALPHA_BUILTIN_PERR,
6463 ALPHA_BUILTIN_PKLB,
6464 ALPHA_BUILTIN_PKWB,
6465 ALPHA_BUILTIN_UNPKBL,
6466 ALPHA_BUILTIN_UNPKBW,
6468 /* TARGET_CIX */
6469 ALPHA_BUILTIN_CTTZ,
6470 ALPHA_BUILTIN_CTLZ,
6471 ALPHA_BUILTIN_CTPOP,
6473 ALPHA_BUILTIN_max
6476 static unsigned int const code_for_builtin[ALPHA_BUILTIN_max] = {
6477 CODE_FOR_builtin_cmpbge,
6478 CODE_FOR_builtin_extbl,
6479 CODE_FOR_builtin_extwl,
6480 CODE_FOR_builtin_extll,
6481 CODE_FOR_builtin_extql,
6482 CODE_FOR_builtin_extwh,
6483 CODE_FOR_builtin_extlh,
6484 CODE_FOR_builtin_extqh,
6485 CODE_FOR_builtin_insbl,
6486 CODE_FOR_builtin_inswl,
6487 CODE_FOR_builtin_insll,
6488 CODE_FOR_builtin_insql,
6489 CODE_FOR_builtin_inswh,
6490 CODE_FOR_builtin_inslh,
6491 CODE_FOR_builtin_insqh,
6492 CODE_FOR_builtin_mskbl,
6493 CODE_FOR_builtin_mskwl,
6494 CODE_FOR_builtin_mskll,
6495 CODE_FOR_builtin_mskql,
6496 CODE_FOR_builtin_mskwh,
6497 CODE_FOR_builtin_msklh,
6498 CODE_FOR_builtin_mskqh,
6499 CODE_FOR_umuldi3_highpart,
6500 CODE_FOR_builtin_zap,
6501 CODE_FOR_builtin_zapnot,
6502 CODE_FOR_builtin_amask,
6503 CODE_FOR_builtin_implver,
6504 CODE_FOR_builtin_rpcc,
6505 CODE_FOR_load_tp,
6506 CODE_FOR_set_tp,
6508 /* TARGET_MAX */
6509 CODE_FOR_builtin_minub8,
6510 CODE_FOR_builtin_minsb8,
6511 CODE_FOR_builtin_minuw4,
6512 CODE_FOR_builtin_minsw4,
6513 CODE_FOR_builtin_maxub8,
6514 CODE_FOR_builtin_maxsb8,
6515 CODE_FOR_builtin_maxuw4,
6516 CODE_FOR_builtin_maxsw4,
6517 CODE_FOR_builtin_perr,
6518 CODE_FOR_builtin_pklb,
6519 CODE_FOR_builtin_pkwb,
6520 CODE_FOR_builtin_unpkbl,
6521 CODE_FOR_builtin_unpkbw,
6523 /* TARGET_CIX */
6524 CODE_FOR_builtin_cttz,
6525 CODE_FOR_builtin_ctlz,
6526 CODE_FOR_builtin_ctpop
6529 struct alpha_builtin_def
6531 const char *name;
6532 enum alpha_builtin code;
6533 unsigned int target_mask;
6536 static struct alpha_builtin_def const zero_arg_builtins[] = {
6537 { "__builtin_alpha_implver", ALPHA_BUILTIN_IMPLVER, 0 },
6538 { "__builtin_alpha_rpcc", ALPHA_BUILTIN_RPCC, 0 }
6541 static struct alpha_builtin_def const one_arg_builtins[] = {
6542 { "__builtin_alpha_amask", ALPHA_BUILTIN_AMASK, 0 },
6543 { "__builtin_alpha_pklb", ALPHA_BUILTIN_PKLB, MASK_MAX },
6544 { "__builtin_alpha_pkwb", ALPHA_BUILTIN_PKWB, MASK_MAX },
6545 { "__builtin_alpha_unpkbl", ALPHA_BUILTIN_UNPKBL, MASK_MAX },
6546 { "__builtin_alpha_unpkbw", ALPHA_BUILTIN_UNPKBW, MASK_MAX },
6547 { "__builtin_alpha_cttz", ALPHA_BUILTIN_CTTZ, MASK_CIX },
6548 { "__builtin_alpha_ctlz", ALPHA_BUILTIN_CTLZ, MASK_CIX },
6549 { "__builtin_alpha_ctpop", ALPHA_BUILTIN_CTPOP, MASK_CIX }
6552 static struct alpha_builtin_def const two_arg_builtins[] = {
6553 { "__builtin_alpha_cmpbge", ALPHA_BUILTIN_CMPBGE, 0 },
6554 { "__builtin_alpha_extbl", ALPHA_BUILTIN_EXTBL, 0 },
6555 { "__builtin_alpha_extwl", ALPHA_BUILTIN_EXTWL, 0 },
6556 { "__builtin_alpha_extll", ALPHA_BUILTIN_EXTLL, 0 },
6557 { "__builtin_alpha_extql", ALPHA_BUILTIN_EXTQL, 0 },
6558 { "__builtin_alpha_extwh", ALPHA_BUILTIN_EXTWH, 0 },
6559 { "__builtin_alpha_extlh", ALPHA_BUILTIN_EXTLH, 0 },
6560 { "__builtin_alpha_extqh", ALPHA_BUILTIN_EXTQH, 0 },
6561 { "__builtin_alpha_insbl", ALPHA_BUILTIN_INSBL, 0 },
6562 { "__builtin_alpha_inswl", ALPHA_BUILTIN_INSWL, 0 },
6563 { "__builtin_alpha_insll", ALPHA_BUILTIN_INSLL, 0 },
6564 { "__builtin_alpha_insql", ALPHA_BUILTIN_INSQL, 0 },
6565 { "__builtin_alpha_inswh", ALPHA_BUILTIN_INSWH, 0 },
6566 { "__builtin_alpha_inslh", ALPHA_BUILTIN_INSLH, 0 },
6567 { "__builtin_alpha_insqh", ALPHA_BUILTIN_INSQH, 0 },
6568 { "__builtin_alpha_mskbl", ALPHA_BUILTIN_MSKBL, 0 },
6569 { "__builtin_alpha_mskwl", ALPHA_BUILTIN_MSKWL, 0 },
6570 { "__builtin_alpha_mskll", ALPHA_BUILTIN_MSKLL, 0 },
6571 { "__builtin_alpha_mskql", ALPHA_BUILTIN_MSKQL, 0 },
6572 { "__builtin_alpha_mskwh", ALPHA_BUILTIN_MSKWH, 0 },
6573 { "__builtin_alpha_msklh", ALPHA_BUILTIN_MSKLH, 0 },
6574 { "__builtin_alpha_mskqh", ALPHA_BUILTIN_MSKQH, 0 },
6575 { "__builtin_alpha_umulh", ALPHA_BUILTIN_UMULH, 0 },
6576 { "__builtin_alpha_zap", ALPHA_BUILTIN_ZAP, 0 },
6577 { "__builtin_alpha_zapnot", ALPHA_BUILTIN_ZAPNOT, 0 },
6578 { "__builtin_alpha_minub8", ALPHA_BUILTIN_MINUB8, MASK_MAX },
6579 { "__builtin_alpha_minsb8", ALPHA_BUILTIN_MINSB8, MASK_MAX },
6580 { "__builtin_alpha_minuw4", ALPHA_BUILTIN_MINUW4, MASK_MAX },
6581 { "__builtin_alpha_minsw4", ALPHA_BUILTIN_MINSW4, MASK_MAX },
6582 { "__builtin_alpha_maxub8", ALPHA_BUILTIN_MAXUB8, MASK_MAX },
6583 { "__builtin_alpha_maxsb8", ALPHA_BUILTIN_MAXSB8, MASK_MAX },
6584 { "__builtin_alpha_maxuw4", ALPHA_BUILTIN_MAXUW4, MASK_MAX },
6585 { "__builtin_alpha_maxsw4", ALPHA_BUILTIN_MAXSW4, MASK_MAX },
6586 { "__builtin_alpha_perr", ALPHA_BUILTIN_PERR, MASK_MAX }
6589 static void
6590 alpha_init_builtins (void)
6592 const struct alpha_builtin_def *p;
6593 tree ftype;
6594 size_t i;
6596 ftype = build_function_type (long_integer_type_node, void_list_node);
6598 p = zero_arg_builtins;
6599 for (i = 0; i < ARRAY_SIZE (zero_arg_builtins); ++i, ++p)
6600 if ((target_flags & p->target_mask) == p->target_mask)
6601 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6602 NULL, NULL_TREE);
6604 ftype = build_function_type_list (long_integer_type_node,
6605 long_integer_type_node, NULL_TREE);
6607 p = one_arg_builtins;
6608 for (i = 0; i < ARRAY_SIZE (one_arg_builtins); ++i, ++p)
6609 if ((target_flags & p->target_mask) == p->target_mask)
6610 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6611 NULL, NULL_TREE);
6613 ftype = build_function_type_list (long_integer_type_node,
6614 long_integer_type_node,
6615 long_integer_type_node, NULL_TREE);
6617 p = two_arg_builtins;
6618 for (i = 0; i < ARRAY_SIZE (two_arg_builtins); ++i, ++p)
6619 if ((target_flags & p->target_mask) == p->target_mask)
6620 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6621 NULL, NULL_TREE);
6623 ftype = build_function_type (ptr_type_node, void_list_node);
6624 builtin_function ("__builtin_thread_pointer", ftype,
6625 ALPHA_BUILTIN_THREAD_POINTER, BUILT_IN_MD,
6626 NULL, NULL_TREE);
6628 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
6629 builtin_function ("__builtin_set_thread_pointer", ftype,
6630 ALPHA_BUILTIN_SET_THREAD_POINTER, BUILT_IN_MD,
6631 NULL, NULL_TREE);
6634 /* Expand an expression EXP that calls a built-in function,
6635 with result going to TARGET if that's convenient
6636 (and in mode MODE if that's convenient).
6637 SUBTARGET may be used as the target for computing one of EXP's operands.
6638 IGNORE is nonzero if the value is to be ignored. */
6640 static rtx
6641 alpha_expand_builtin (tree exp, rtx target,
6642 rtx subtarget ATTRIBUTE_UNUSED,
6643 enum machine_mode mode ATTRIBUTE_UNUSED,
6644 int ignore ATTRIBUTE_UNUSED)
6646 #define MAX_ARGS 2
6648 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6649 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6650 tree arglist = TREE_OPERAND (exp, 1);
6651 enum insn_code icode;
6652 rtx op[MAX_ARGS], pat;
6653 int arity;
6654 bool nonvoid;
6656 if (fcode >= ALPHA_BUILTIN_max)
6657 internal_error ("bad builtin fcode");
6658 icode = code_for_builtin[fcode];
6659 if (icode == 0)
6660 internal_error ("bad builtin fcode");
6662 nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
6664 for (arglist = TREE_OPERAND (exp, 1), arity = 0;
6665 arglist;
6666 arglist = TREE_CHAIN (arglist), arity++)
6668 const struct insn_operand_data *insn_op;
6670 tree arg = TREE_VALUE (arglist);
6671 if (arg == error_mark_node)
6672 return NULL_RTX;
6673 if (arity > MAX_ARGS)
6674 return NULL_RTX;
6676 insn_op = &insn_data[icode].operand[arity + nonvoid];
6678 op[arity] = expand_expr (arg, NULL_RTX, insn_op->mode, 0);
6680 if (!(*insn_op->predicate) (op[arity], insn_op->mode))
6681 op[arity] = copy_to_mode_reg (insn_op->mode, op[arity]);
6684 if (nonvoid)
6686 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6687 if (!target
6688 || GET_MODE (target) != tmode
6689 || !(*insn_data[icode].operand[0].predicate) (target, tmode))
6690 target = gen_reg_rtx (tmode);
6693 switch (arity)
6695 case 0:
6696 pat = GEN_FCN (icode) (target);
6697 break;
6698 case 1:
6699 if (nonvoid)
6700 pat = GEN_FCN (icode) (target, op[0]);
6701 else
6702 pat = GEN_FCN (icode) (op[0]);
6703 break;
6704 case 2:
6705 pat = GEN_FCN (icode) (target, op[0], op[1]);
6706 break;
6707 default:
6708 abort ();
6710 if (!pat)
6711 return NULL_RTX;
6712 emit_insn (pat);
6714 if (nonvoid)
6715 return target;
6716 else
6717 return const0_rtx;
6720 /* This page contains routines that are used to determine what the function
6721 prologue and epilogue code will do and write them out. */
6723 /* Compute the size of the save area in the stack. */
6725 /* These variables are used for communication between the following functions.
6726 They indicate various things about the current function being compiled
6727 that are used to tell what kind of prologue, epilogue and procedure
6728 descriptor to generate. */
6730 /* Nonzero if we need a stack procedure. */
6731 enum alpha_procedure_types {PT_NULL = 0, PT_REGISTER = 1, PT_STACK = 2};
6732 static enum alpha_procedure_types alpha_procedure_type;
6734 /* Register number (either FP or SP) that is used to unwind the frame. */
6735 static int vms_unwind_regno;
6737 /* Register number used to save FP. We need not have one for RA since
6738 we don't modify it for register procedures. This is only defined
6739 for register frame procedures. */
6740 static int vms_save_fp_regno;
6742 /* Register number used to reference objects off our PV. */
6743 static int vms_base_regno;
6745 /* Compute register masks for saved registers. */
6747 static void
6748 alpha_sa_mask (unsigned long *imaskP, unsigned long *fmaskP)
6750 unsigned long imask = 0;
6751 unsigned long fmask = 0;
6752 unsigned int i;
6754 /* When outputting a thunk, we don't have valid register life info,
6755 but assemble_start_function wants to output .frame and .mask
6756 directives. */
6757 if (current_function_is_thunk)
6759 *imaskP = 0;
6760 *fmaskP = 0;
6761 return;
6764 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
6765 imask |= (1UL << HARD_FRAME_POINTER_REGNUM);
6767 /* One for every register we have to save. */
6768 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
6769 if (! fixed_regs[i] && ! call_used_regs[i]
6770 && regs_ever_live[i] && i != REG_RA
6771 && (!TARGET_ABI_UNICOSMK || i != HARD_FRAME_POINTER_REGNUM))
6773 if (i < 32)
6774 imask |= (1UL << i);
6775 else
6776 fmask |= (1UL << (i - 32));
6779 /* We need to restore these for the handler. */
6780 if (current_function_calls_eh_return)
6782 for (i = 0; ; ++i)
6784 unsigned regno = EH_RETURN_DATA_REGNO (i);
6785 if (regno == INVALID_REGNUM)
6786 break;
6787 imask |= 1UL << regno;
6790 /* Glibc likes to use $31 as an unwind stopper for crt0. To
6791 avoid hackery in unwind-dw2.c, we need to actively store a
6792 zero in the prologue of _Unwind_RaiseException et al. */
6793 imask |= 1UL << 31;
6796 /* If any register spilled, then spill the return address also. */
6797 /* ??? This is required by the Digital stack unwind specification
6798 and isn't needed if we're doing Dwarf2 unwinding. */
6799 if (imask || fmask || alpha_ra_ever_killed ())
6800 imask |= (1UL << REG_RA);
6802 *imaskP = imask;
6803 *fmaskP = fmask;
6807 alpha_sa_size (void)
6809 unsigned long mask[2];
6810 int sa_size = 0;
6811 int i, j;
6813 alpha_sa_mask (&mask[0], &mask[1]);
6815 if (TARGET_ABI_UNICOSMK)
6817 if (mask[0] || mask[1])
6818 sa_size = 14;
6820 else
6822 for (j = 0; j < 2; ++j)
6823 for (i = 0; i < 32; ++i)
6824 if ((mask[j] >> i) & 1)
6825 sa_size++;
6828 if (TARGET_ABI_UNICOSMK)
6830 /* We might not need to generate a frame if we don't make any calls
6831 (including calls to __T3E_MISMATCH if this is a vararg function),
6832 don't have any local variables which require stack slots, don't
6833 use alloca and have not determined that we need a frame for other
6834 reasons. */
6836 alpha_procedure_type
6837 = (sa_size || get_frame_size() != 0
6838 || current_function_outgoing_args_size
6839 || current_function_stdarg || current_function_calls_alloca
6840 || frame_pointer_needed)
6841 ? PT_STACK : PT_REGISTER;
6843 /* Always reserve space for saving callee-saved registers if we
6844 need a frame as required by the calling convention. */
6845 if (alpha_procedure_type == PT_STACK)
6846 sa_size = 14;
6848 else if (TARGET_ABI_OPEN_VMS)
6850 /* Start by assuming we can use a register procedure if we don't
6851 make any calls (REG_RA not used) or need to save any
6852 registers and a stack procedure if we do. */
6853 if ((mask[0] >> REG_RA) & 1)
6854 alpha_procedure_type = PT_STACK;
6855 else if (get_frame_size() != 0)
6856 alpha_procedure_type = PT_REGISTER;
6857 else
6858 alpha_procedure_type = PT_NULL;
6860 /* Don't reserve space for saving FP & RA yet. Do that later after we've
6861 made the final decision on stack procedure vs register procedure. */
6862 if (alpha_procedure_type == PT_STACK)
6863 sa_size -= 2;
6865 /* Decide whether to refer to objects off our PV via FP or PV.
6866 If we need FP for something else or if we receive a nonlocal
6867 goto (which expects PV to contain the value), we must use PV.
6868 Otherwise, start by assuming we can use FP. */
6870 vms_base_regno
6871 = (frame_pointer_needed
6872 || current_function_has_nonlocal_label
6873 || alpha_procedure_type == PT_STACK
6874 || current_function_outgoing_args_size)
6875 ? REG_PV : HARD_FRAME_POINTER_REGNUM;
6877 /* If we want to copy PV into FP, we need to find some register
6878 in which to save FP. */
6880 vms_save_fp_regno = -1;
6881 if (vms_base_regno == HARD_FRAME_POINTER_REGNUM)
6882 for (i = 0; i < 32; i++)
6883 if (! fixed_regs[i] && call_used_regs[i] && ! regs_ever_live[i])
6884 vms_save_fp_regno = i;
6886 if (vms_save_fp_regno == -1 && alpha_procedure_type == PT_REGISTER)
6887 vms_base_regno = REG_PV, alpha_procedure_type = PT_STACK;
6888 else if (alpha_procedure_type == PT_NULL)
6889 vms_base_regno = REG_PV;
6891 /* Stack unwinding should be done via FP unless we use it for PV. */
6892 vms_unwind_regno = (vms_base_regno == REG_PV
6893 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
6895 /* If this is a stack procedure, allow space for saving FP and RA. */
6896 if (alpha_procedure_type == PT_STACK)
6897 sa_size += 2;
6899 else
6901 /* Our size must be even (multiple of 16 bytes). */
6902 if (sa_size & 1)
6903 sa_size++;
6906 return sa_size * 8;
6909 /* Define the offset between two registers, one to be eliminated,
6910 and the other its replacement, at the start of a routine. */
6912 HOST_WIDE_INT
6913 alpha_initial_elimination_offset (unsigned int from,
6914 unsigned int to ATTRIBUTE_UNUSED)
6916 HOST_WIDE_INT ret;
6918 ret = alpha_sa_size ();
6919 ret += ALPHA_ROUND (current_function_outgoing_args_size);
6921 if (from == FRAME_POINTER_REGNUM)
6923 else if (from == ARG_POINTER_REGNUM)
6924 ret += (ALPHA_ROUND (get_frame_size ()
6925 + current_function_pretend_args_size)
6926 - current_function_pretend_args_size);
6927 else
6928 abort ();
6930 return ret;
6934 alpha_pv_save_size (void)
6936 alpha_sa_size ();
6937 return alpha_procedure_type == PT_STACK ? 8 : 0;
6941 alpha_using_fp (void)
6943 alpha_sa_size ();
6944 return vms_unwind_regno == HARD_FRAME_POINTER_REGNUM;
6947 #if TARGET_ABI_OPEN_VMS
6949 const struct attribute_spec vms_attribute_table[] =
6951 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
6952 { "overlaid", 0, 0, true, false, false, NULL },
6953 { "global", 0, 0, true, false, false, NULL },
6954 { "initialize", 0, 0, true, false, false, NULL },
6955 { NULL, 0, 0, false, false, false, NULL }
6958 #endif
6960 static int
6961 find_lo_sum_using_gp (rtx *px, void *data ATTRIBUTE_UNUSED)
6963 return GET_CODE (*px) == LO_SUM && XEXP (*px, 0) == pic_offset_table_rtx;
6967 alpha_find_lo_sum_using_gp (rtx insn)
6969 return for_each_rtx (&PATTERN (insn), find_lo_sum_using_gp, NULL) > 0;
6972 static int
6973 alpha_does_function_need_gp (void)
6975 rtx insn;
6977 /* The GP being variable is an OSF abi thing. */
6978 if (! TARGET_ABI_OSF)
6979 return 0;
6981 /* We need the gp to load the address of __mcount. */
6982 if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
6983 return 1;
6985 /* The code emitted by alpha_output_mi_thunk_osf uses the gp. */
6986 if (current_function_is_thunk)
6987 return 1;
6989 /* The nonlocal receiver pattern assumes that the gp is valid for
6990 the nested function. Reasonable because it's almost always set
6991 correctly already. For the cases where that's wrong, make sure
6992 the nested function loads its gp on entry. */
6993 if (current_function_has_nonlocal_goto)
6994 return 1;
6996 /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first.
6997 Even if we are a static function, we still need to do this in case
6998 our address is taken and passed to something like qsort. */
7000 push_topmost_sequence ();
7001 insn = get_insns ();
7002 pop_topmost_sequence ();
7004 for (; insn; insn = NEXT_INSN (insn))
7005 if (INSN_P (insn)
7006 && GET_CODE (PATTERN (insn)) != USE
7007 && GET_CODE (PATTERN (insn)) != CLOBBER
7008 && get_attr_usegp (insn))
7009 return 1;
7011 return 0;
7015 /* Helper function to set RTX_FRAME_RELATED_P on instructions, including
7016 sequences. */
7018 static rtx
7019 set_frame_related_p (void)
7021 rtx seq = get_insns ();
7022 rtx insn;
7024 end_sequence ();
7026 if (!seq)
7027 return NULL_RTX;
7029 if (INSN_P (seq))
7031 insn = seq;
7032 while (insn != NULL_RTX)
7034 RTX_FRAME_RELATED_P (insn) = 1;
7035 insn = NEXT_INSN (insn);
7037 seq = emit_insn (seq);
7039 else
7041 seq = emit_insn (seq);
7042 RTX_FRAME_RELATED_P (seq) = 1;
7044 return seq;
7047 #define FRP(exp) (start_sequence (), exp, set_frame_related_p ())
7049 /* Write function prologue. */
7051 /* On vms we have two kinds of functions:
7053 - stack frame (PROC_STACK)
7054 these are 'normal' functions with local vars and which are
7055 calling other functions
7056 - register frame (PROC_REGISTER)
7057 keeps all data in registers, needs no stack
7059 We must pass this to the assembler so it can generate the
7060 proper pdsc (procedure descriptor)
7061 This is done with the '.pdesc' command.
7063 On not-vms, we don't really differentiate between the two, as we can
7064 simply allocate stack without saving registers. */
7066 void
7067 alpha_expand_prologue (void)
7069 /* Registers to save. */
7070 unsigned long imask = 0;
7071 unsigned long fmask = 0;
7072 /* Stack space needed for pushing registers clobbered by us. */
7073 HOST_WIDE_INT sa_size;
7074 /* Complete stack size needed. */
7075 HOST_WIDE_INT frame_size;
7076 /* Offset from base reg to register save area. */
7077 HOST_WIDE_INT reg_offset;
7078 rtx sa_reg, mem;
7079 int i;
7081 sa_size = alpha_sa_size ();
7083 frame_size = get_frame_size ();
7084 if (TARGET_ABI_OPEN_VMS)
7085 frame_size = ALPHA_ROUND (sa_size
7086 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7087 + frame_size
7088 + current_function_pretend_args_size);
7089 else if (TARGET_ABI_UNICOSMK)
7090 /* We have to allocate space for the DSIB if we generate a frame. */
7091 frame_size = ALPHA_ROUND (sa_size
7092 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7093 + ALPHA_ROUND (frame_size
7094 + current_function_outgoing_args_size);
7095 else
7096 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7097 + sa_size
7098 + ALPHA_ROUND (frame_size
7099 + current_function_pretend_args_size));
7101 if (TARGET_ABI_OPEN_VMS)
7102 reg_offset = 8;
7103 else
7104 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7106 alpha_sa_mask (&imask, &fmask);
7108 /* Emit an insn to reload GP, if needed. */
7109 if (TARGET_ABI_OSF)
7111 alpha_function_needs_gp = alpha_does_function_need_gp ();
7112 if (alpha_function_needs_gp)
7113 emit_insn (gen_prologue_ldgp ());
7116 /* TARGET_PROFILING_NEEDS_GP actually implies that we need to insert
7117 the call to mcount ourselves, rather than having the linker do it
7118 magically in response to -pg. Since _mcount has special linkage,
7119 don't represent the call as a call. */
7120 if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
7121 emit_insn (gen_prologue_mcount ());
7123 if (TARGET_ABI_UNICOSMK)
7124 unicosmk_gen_dsib (&imask);
7126 /* Adjust the stack by the frame size. If the frame size is > 4096
7127 bytes, we need to be sure we probe somewhere in the first and last
7128 4096 bytes (we can probably get away without the latter test) and
7129 every 8192 bytes in between. If the frame size is > 32768, we
7130 do this in a loop. Otherwise, we generate the explicit probe
7131 instructions.
7133 Note that we are only allowed to adjust sp once in the prologue. */
7135 if (frame_size <= 32768)
7137 if (frame_size > 4096)
7139 int probed = 4096;
7142 emit_insn (gen_probe_stack (GEN_INT (TARGET_ABI_UNICOSMK
7143 ? -probed + 64
7144 : -probed)));
7145 while ((probed += 8192) < frame_size);
7147 /* We only have to do this probe if we aren't saving registers. */
7148 if (sa_size == 0 && probed + 4096 < frame_size)
7149 emit_insn (gen_probe_stack (GEN_INT (-frame_size)));
7152 if (frame_size != 0)
7153 FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
7154 GEN_INT (TARGET_ABI_UNICOSMK
7155 ? -frame_size + 64
7156 : -frame_size))));
7158 else
7160 /* Here we generate code to set R22 to SP + 4096 and set R23 to the
7161 number of 8192 byte blocks to probe. We then probe each block
7162 in the loop and then set SP to the proper location. If the
7163 amount remaining is > 4096, we have to do one more probe if we
7164 are not saving any registers. */
7166 HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
7167 HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
7168 rtx ptr = gen_rtx_REG (DImode, 22);
7169 rtx count = gen_rtx_REG (DImode, 23);
7170 rtx seq;
7172 emit_move_insn (count, GEN_INT (blocks));
7173 emit_insn (gen_adddi3 (ptr, stack_pointer_rtx,
7174 GEN_INT (TARGET_ABI_UNICOSMK ? 4096 - 64 : 4096)));
7176 /* Because of the difficulty in emitting a new basic block this
7177 late in the compilation, generate the loop as a single insn. */
7178 emit_insn (gen_prologue_stack_probe_loop (count, ptr));
7180 if (leftover > 4096 && sa_size == 0)
7182 rtx last = gen_rtx_MEM (DImode, plus_constant (ptr, -leftover));
7183 MEM_VOLATILE_P (last) = 1;
7184 emit_move_insn (last, const0_rtx);
7187 if (TARGET_ABI_WINDOWS_NT)
7189 /* For NT stack unwind (done by 'reverse execution'), it's
7190 not OK to take the result of a loop, even though the value
7191 is already in ptr, so we reload it via a single operation
7192 and subtract it to sp.
7194 Yes, that's correct -- we have to reload the whole constant
7195 into a temporary via ldah+lda then subtract from sp. */
7197 HOST_WIDE_INT lo, hi;
7198 lo = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
7199 hi = frame_size - lo;
7201 emit_move_insn (ptr, GEN_INT (hi));
7202 emit_insn (gen_adddi3 (ptr, ptr, GEN_INT (lo)));
7203 seq = emit_insn (gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx,
7204 ptr));
7206 else
7208 seq = emit_insn (gen_adddi3 (stack_pointer_rtx, ptr,
7209 GEN_INT (-leftover)));
7212 /* This alternative is special, because the DWARF code cannot
7213 possibly intuit through the loop above. So we invent this
7214 note it looks at instead. */
7215 RTX_FRAME_RELATED_P (seq) = 1;
7216 REG_NOTES (seq)
7217 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7218 gen_rtx_SET (VOIDmode, stack_pointer_rtx,
7219 gen_rtx_PLUS (Pmode, stack_pointer_rtx,
7220 GEN_INT (TARGET_ABI_UNICOSMK
7221 ? -frame_size + 64
7222 : -frame_size))),
7223 REG_NOTES (seq));
7226 if (!TARGET_ABI_UNICOSMK)
7228 /* Cope with very large offsets to the register save area. */
7229 sa_reg = stack_pointer_rtx;
7230 if (reg_offset + sa_size > 0x8000)
7232 int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7233 HOST_WIDE_INT bias;
7235 if (low + sa_size <= 0x8000)
7236 bias = reg_offset - low, reg_offset = low;
7237 else
7238 bias = reg_offset, reg_offset = 0;
7240 sa_reg = gen_rtx_REG (DImode, 24);
7241 FRP (emit_insn (gen_adddi3 (sa_reg, stack_pointer_rtx,
7242 GEN_INT (bias))));
7245 /* Save regs in stack order. Beginning with VMS PV. */
7246 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7248 mem = gen_rtx_MEM (DImode, stack_pointer_rtx);
7249 set_mem_alias_set (mem, alpha_sr_alias_set);
7250 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_PV)));
7253 /* Save register RA next. */
7254 if (imask & (1UL << REG_RA))
7256 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7257 set_mem_alias_set (mem, alpha_sr_alias_set);
7258 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA)));
7259 imask &= ~(1UL << REG_RA);
7260 reg_offset += 8;
7263 /* Now save any other registers required to be saved. */
7264 for (i = 0; i < 31; i++)
7265 if (imask & (1UL << i))
7267 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7268 set_mem_alias_set (mem, alpha_sr_alias_set);
7269 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, i)));
7270 reg_offset += 8;
7273 /* Store a zero if requested for unwinding. */
7274 if (imask & (1UL << 31))
7276 rtx insn, t;
7278 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7279 set_mem_alias_set (mem, alpha_sr_alias_set);
7280 insn = emit_move_insn (mem, const0_rtx);
7282 RTX_FRAME_RELATED_P (insn) = 1;
7283 t = gen_rtx_REG (Pmode, 31);
7284 t = gen_rtx_SET (VOIDmode, mem, t);
7285 t = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, t, REG_NOTES (insn));
7286 REG_NOTES (insn) = t;
7288 reg_offset += 8;
7291 for (i = 0; i < 31; i++)
7292 if (fmask & (1UL << i))
7294 mem = gen_rtx_MEM (DFmode, plus_constant (sa_reg, reg_offset));
7295 set_mem_alias_set (mem, alpha_sr_alias_set);
7296 FRP (emit_move_insn (mem, gen_rtx_REG (DFmode, i+32)));
7297 reg_offset += 8;
7300 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7302 /* The standard frame on the T3E includes space for saving registers.
7303 We just have to use it. We don't have to save the return address and
7304 the old frame pointer here - they are saved in the DSIB. */
7306 reg_offset = -56;
7307 for (i = 9; i < 15; i++)
7308 if (imask & (1UL << i))
7310 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx,
7311 reg_offset));
7312 set_mem_alias_set (mem, alpha_sr_alias_set);
7313 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, i)));
7314 reg_offset -= 8;
7316 for (i = 2; i < 10; i++)
7317 if (fmask & (1UL << i))
7319 mem = gen_rtx_MEM (DFmode, plus_constant (hard_frame_pointer_rtx,
7320 reg_offset));
7321 set_mem_alias_set (mem, alpha_sr_alias_set);
7322 FRP (emit_move_insn (mem, gen_rtx_REG (DFmode, i+32)));
7323 reg_offset -= 8;
7327 if (TARGET_ABI_OPEN_VMS)
7329 if (alpha_procedure_type == PT_REGISTER)
7330 /* Register frame procedures save the fp.
7331 ?? Ought to have a dwarf2 save for this. */
7332 emit_move_insn (gen_rtx_REG (DImode, vms_save_fp_regno),
7333 hard_frame_pointer_rtx);
7335 if (alpha_procedure_type != PT_NULL && vms_base_regno != REG_PV)
7336 emit_insn (gen_force_movdi (gen_rtx_REG (DImode, vms_base_regno),
7337 gen_rtx_REG (DImode, REG_PV)));
7339 if (alpha_procedure_type != PT_NULL
7340 && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7341 FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7343 /* If we have to allocate space for outgoing args, do it now. */
7344 if (current_function_outgoing_args_size != 0)
7346 rtx seq
7347 = emit_move_insn (stack_pointer_rtx,
7348 plus_constant
7349 (hard_frame_pointer_rtx,
7350 - (ALPHA_ROUND
7351 (current_function_outgoing_args_size))));
7353 /* Only set FRAME_RELATED_P on the stack adjustment we just emitted
7354 if ! frame_pointer_needed. Setting the bit will change the CFA
7355 computation rule to use sp again, which would be wrong if we had
7356 frame_pointer_needed, as this means sp might move unpredictably
7357 later on.
7359 Also, note that
7360 frame_pointer_needed
7361 => vms_unwind_regno == HARD_FRAME_POINTER_REGNUM
7363 current_function_outgoing_args_size != 0
7364 => alpha_procedure_type != PT_NULL,
7366 so when we are not setting the bit here, we are guaranteed to
7367 have emitted an FRP frame pointer update just before. */
7368 RTX_FRAME_RELATED_P (seq) = ! frame_pointer_needed;
7371 else if (!TARGET_ABI_UNICOSMK)
7373 /* If we need a frame pointer, set it from the stack pointer. */
7374 if (frame_pointer_needed)
7376 if (TARGET_CAN_FAULT_IN_PROLOGUE)
7377 FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7378 else
7379 /* This must always be the last instruction in the
7380 prologue, thus we emit a special move + clobber. */
7381 FRP (emit_insn (gen_init_fp (hard_frame_pointer_rtx,
7382 stack_pointer_rtx, sa_reg)));
7386 /* The ABIs for VMS and OSF/1 say that while we can schedule insns into
7387 the prologue, for exception handling reasons, we cannot do this for
7388 any insn that might fault. We could prevent this for mems with a
7389 (clobber:BLK (scratch)), but this doesn't work for fp insns. So we
7390 have to prevent all such scheduling with a blockage.
7392 Linux, on the other hand, never bothered to implement OSF/1's
7393 exception handling, and so doesn't care about such things. Anyone
7394 planning to use dwarf2 frame-unwind info can also omit the blockage. */
7396 if (! TARGET_CAN_FAULT_IN_PROLOGUE)
7397 emit_insn (gen_blockage ());
7400 /* Output the textual info surrounding the prologue. */
7402 void
7403 alpha_start_function (FILE *file, const char *fnname,
7404 tree decl ATTRIBUTE_UNUSED)
7406 unsigned long imask = 0;
7407 unsigned long fmask = 0;
7408 /* Stack space needed for pushing registers clobbered by us. */
7409 HOST_WIDE_INT sa_size;
7410 /* Complete stack size needed. */
7411 unsigned HOST_WIDE_INT frame_size;
7412 /* Offset from base reg to register save area. */
7413 HOST_WIDE_INT reg_offset;
7414 char *entry_label = (char *) alloca (strlen (fnname) + 6);
7415 int i;
7417 /* Don't emit an extern directive for functions defined in the same file. */
7418 if (TARGET_ABI_UNICOSMK)
7420 tree name_tree;
7421 name_tree = get_identifier (fnname);
7422 TREE_ASM_WRITTEN (name_tree) = 1;
7425 alpha_fnname = fnname;
7426 sa_size = alpha_sa_size ();
7428 frame_size = get_frame_size ();
7429 if (TARGET_ABI_OPEN_VMS)
7430 frame_size = ALPHA_ROUND (sa_size
7431 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7432 + frame_size
7433 + current_function_pretend_args_size);
7434 else if (TARGET_ABI_UNICOSMK)
7435 frame_size = ALPHA_ROUND (sa_size
7436 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7437 + ALPHA_ROUND (frame_size
7438 + current_function_outgoing_args_size);
7439 else
7440 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7441 + sa_size
7442 + ALPHA_ROUND (frame_size
7443 + current_function_pretend_args_size));
7445 if (TARGET_ABI_OPEN_VMS)
7446 reg_offset = 8;
7447 else
7448 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7450 alpha_sa_mask (&imask, &fmask);
7452 /* Ecoff can handle multiple .file directives, so put out file and lineno.
7453 We have to do that before the .ent directive as we cannot switch
7454 files within procedures with native ecoff because line numbers are
7455 linked to procedure descriptors.
7456 Outputting the lineno helps debugging of one line functions as they
7457 would otherwise get no line number at all. Please note that we would
7458 like to put out last_linenum from final.c, but it is not accessible. */
7460 if (write_symbols == SDB_DEBUG)
7462 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7463 ASM_OUTPUT_SOURCE_FILENAME (file,
7464 DECL_SOURCE_FILE (current_function_decl));
7465 #endif
7466 #ifdef ASM_OUTPUT_SOURCE_LINE
7467 if (debug_info_level != DINFO_LEVEL_TERSE)
7468 ASM_OUTPUT_SOURCE_LINE (file,
7469 DECL_SOURCE_LINE (current_function_decl), 0);
7470 #endif
7473 /* Issue function start and label. */
7474 if (TARGET_ABI_OPEN_VMS
7475 || (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive))
7477 fputs ("\t.ent ", file);
7478 assemble_name (file, fnname);
7479 putc ('\n', file);
7481 /* If the function needs GP, we'll write the "..ng" label there.
7482 Otherwise, do it here. */
7483 if (TARGET_ABI_OSF
7484 && ! alpha_function_needs_gp
7485 && ! current_function_is_thunk)
7487 putc ('$', file);
7488 assemble_name (file, fnname);
7489 fputs ("..ng:\n", file);
7493 strcpy (entry_label, fnname);
7494 if (TARGET_ABI_OPEN_VMS)
7495 strcat (entry_label, "..en");
7497 /* For public functions, the label must be globalized by appending an
7498 additional colon. */
7499 if (TARGET_ABI_UNICOSMK && TREE_PUBLIC (decl))
7500 strcat (entry_label, ":");
7502 ASM_OUTPUT_LABEL (file, entry_label);
7503 inside_function = TRUE;
7505 if (TARGET_ABI_OPEN_VMS)
7506 fprintf (file, "\t.base $%d\n", vms_base_regno);
7508 if (!TARGET_ABI_OPEN_VMS && !TARGET_ABI_UNICOSMK && TARGET_IEEE_CONFORMANT
7509 && !flag_inhibit_size_directive)
7511 /* Set flags in procedure descriptor to request IEEE-conformant
7512 math-library routines. The value we set it to is PDSC_EXC_IEEE
7513 (/usr/include/pdsc.h). */
7514 fputs ("\t.eflag 48\n", file);
7517 /* Set up offsets to alpha virtual arg/local debugging pointer. */
7518 alpha_auto_offset = -frame_size + current_function_pretend_args_size;
7519 alpha_arg_offset = -frame_size + 48;
7521 /* Describe our frame. If the frame size is larger than an integer,
7522 print it as zero to avoid an assembler error. We won't be
7523 properly describing such a frame, but that's the best we can do. */
7524 if (TARGET_ABI_UNICOSMK)
7526 else if (TARGET_ABI_OPEN_VMS)
7527 fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,"
7528 HOST_WIDE_INT_PRINT_DEC "\n",
7529 vms_unwind_regno,
7530 frame_size >= (1UL << 31) ? 0 : frame_size,
7531 reg_offset);
7532 else if (!flag_inhibit_size_directive)
7533 fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,%d\n",
7534 (frame_pointer_needed
7535 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
7536 frame_size >= (1UL << 31) ? 0 : frame_size,
7537 current_function_pretend_args_size);
7539 /* Describe which registers were spilled. */
7540 if (TARGET_ABI_UNICOSMK)
7542 else if (TARGET_ABI_OPEN_VMS)
7544 if (imask)
7545 /* ??? Does VMS care if mask contains ra? The old code didn't
7546 set it, so I don't here. */
7547 fprintf (file, "\t.mask 0x%lx,0\n", imask & ~(1UL << REG_RA));
7548 if (fmask)
7549 fprintf (file, "\t.fmask 0x%lx,0\n", fmask);
7550 if (alpha_procedure_type == PT_REGISTER)
7551 fprintf (file, "\t.fp_save $%d\n", vms_save_fp_regno);
7553 else if (!flag_inhibit_size_directive)
7555 if (imask)
7557 fprintf (file, "\t.mask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", imask,
7558 frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7560 for (i = 0; i < 32; ++i)
7561 if (imask & (1UL << i))
7562 reg_offset += 8;
7565 if (fmask)
7566 fprintf (file, "\t.fmask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", fmask,
7567 frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7570 #if TARGET_ABI_OPEN_VMS
7571 /* Ifdef'ed cause link_section are only available then. */
7572 readonly_data_section ();
7573 fprintf (file, "\t.align 3\n");
7574 assemble_name (file, fnname); fputs ("..na:\n", file);
7575 fputs ("\t.ascii \"", file);
7576 assemble_name (file, fnname);
7577 fputs ("\\0\"\n", file);
7578 alpha_need_linkage (fnname, 1);
7579 text_section ();
7580 #endif
7583 /* Emit the .prologue note at the scheduled end of the prologue. */
7585 static void
7586 alpha_output_function_end_prologue (FILE *file)
7588 if (TARGET_ABI_UNICOSMK)
7590 else if (TARGET_ABI_OPEN_VMS)
7591 fputs ("\t.prologue\n", file);
7592 else if (TARGET_ABI_WINDOWS_NT)
7593 fputs ("\t.prologue 0\n", file);
7594 else if (!flag_inhibit_size_directive)
7595 fprintf (file, "\t.prologue %d\n",
7596 alpha_function_needs_gp || current_function_is_thunk);
7599 /* Write function epilogue. */
7601 /* ??? At some point we will want to support full unwind, and so will
7602 need to mark the epilogue as well. At the moment, we just confuse
7603 dwarf2out. */
7604 #undef FRP
7605 #define FRP(exp) exp
7607 void
7608 alpha_expand_epilogue (void)
7610 /* Registers to save. */
7611 unsigned long imask = 0;
7612 unsigned long fmask = 0;
7613 /* Stack space needed for pushing registers clobbered by us. */
7614 HOST_WIDE_INT sa_size;
7615 /* Complete stack size needed. */
7616 HOST_WIDE_INT frame_size;
7617 /* Offset from base reg to register save area. */
7618 HOST_WIDE_INT reg_offset;
7619 int fp_is_frame_pointer, fp_offset;
7620 rtx sa_reg, sa_reg_exp = NULL;
7621 rtx sp_adj1, sp_adj2, mem;
7622 rtx eh_ofs;
7623 int i;
7625 sa_size = alpha_sa_size ();
7627 frame_size = get_frame_size ();
7628 if (TARGET_ABI_OPEN_VMS)
7629 frame_size = ALPHA_ROUND (sa_size
7630 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7631 + frame_size
7632 + current_function_pretend_args_size);
7633 else if (TARGET_ABI_UNICOSMK)
7634 frame_size = ALPHA_ROUND (sa_size
7635 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7636 + ALPHA_ROUND (frame_size
7637 + current_function_outgoing_args_size);
7638 else
7639 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7640 + sa_size
7641 + ALPHA_ROUND (frame_size
7642 + current_function_pretend_args_size));
7644 if (TARGET_ABI_OPEN_VMS)
7646 if (alpha_procedure_type == PT_STACK)
7647 reg_offset = 8;
7648 else
7649 reg_offset = 0;
7651 else
7652 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7654 alpha_sa_mask (&imask, &fmask);
7656 fp_is_frame_pointer
7657 = ((TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7658 || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed));
7659 fp_offset = 0;
7660 sa_reg = stack_pointer_rtx;
7662 if (current_function_calls_eh_return)
7663 eh_ofs = EH_RETURN_STACKADJ_RTX;
7664 else
7665 eh_ofs = NULL_RTX;
7667 if (!TARGET_ABI_UNICOSMK && sa_size)
7669 /* If we have a frame pointer, restore SP from it. */
7670 if ((TARGET_ABI_OPEN_VMS
7671 && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7672 || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed))
7673 FRP (emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx));
7675 /* Cope with very large offsets to the register save area. */
7676 if (reg_offset + sa_size > 0x8000)
7678 int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7679 HOST_WIDE_INT bias;
7681 if (low + sa_size <= 0x8000)
7682 bias = reg_offset - low, reg_offset = low;
7683 else
7684 bias = reg_offset, reg_offset = 0;
7686 sa_reg = gen_rtx_REG (DImode, 22);
7687 sa_reg_exp = plus_constant (stack_pointer_rtx, bias);
7689 FRP (emit_move_insn (sa_reg, sa_reg_exp));
7692 /* Restore registers in order, excepting a true frame pointer. */
7694 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7695 if (! eh_ofs)
7696 set_mem_alias_set (mem, alpha_sr_alias_set);
7697 FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7699 reg_offset += 8;
7700 imask &= ~(1UL << REG_RA);
7702 for (i = 0; i < 31; ++i)
7703 if (imask & (1UL << i))
7705 if (i == HARD_FRAME_POINTER_REGNUM && fp_is_frame_pointer)
7706 fp_offset = reg_offset;
7707 else
7709 mem = gen_rtx_MEM (DImode, plus_constant(sa_reg, reg_offset));
7710 set_mem_alias_set (mem, alpha_sr_alias_set);
7711 FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7713 reg_offset += 8;
7716 if (imask & (1UL << 31))
7717 reg_offset += 8;
7719 for (i = 0; i < 31; ++i)
7720 if (fmask & (1UL << i))
7722 mem = gen_rtx_MEM (DFmode, plus_constant(sa_reg, reg_offset));
7723 set_mem_alias_set (mem, alpha_sr_alias_set);
7724 FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7725 reg_offset += 8;
7728 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7730 /* Restore callee-saved general-purpose registers. */
7732 reg_offset = -56;
7734 for (i = 9; i < 15; i++)
7735 if (imask & (1UL << i))
7737 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx,
7738 reg_offset));
7739 set_mem_alias_set (mem, alpha_sr_alias_set);
7740 FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7741 reg_offset -= 8;
7744 for (i = 2; i < 10; i++)
7745 if (fmask & (1UL << i))
7747 mem = gen_rtx_MEM (DFmode, plus_constant(hard_frame_pointer_rtx,
7748 reg_offset));
7749 set_mem_alias_set (mem, alpha_sr_alias_set);
7750 FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7751 reg_offset -= 8;
7754 /* Restore the return address from the DSIB. */
7756 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx, -8));
7757 set_mem_alias_set (mem, alpha_sr_alias_set);
7758 FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7761 if (frame_size || eh_ofs)
7763 sp_adj1 = stack_pointer_rtx;
7765 if (eh_ofs)
7767 sp_adj1 = gen_rtx_REG (DImode, 23);
7768 emit_move_insn (sp_adj1,
7769 gen_rtx_PLUS (Pmode, stack_pointer_rtx, eh_ofs));
7772 /* If the stack size is large, begin computation into a temporary
7773 register so as not to interfere with a potential fp restore,
7774 which must be consecutive with an SP restore. */
7775 if (frame_size < 32768
7776 && ! (TARGET_ABI_UNICOSMK && current_function_calls_alloca))
7777 sp_adj2 = GEN_INT (frame_size);
7778 else if (TARGET_ABI_UNICOSMK)
7780 sp_adj1 = gen_rtx_REG (DImode, 23);
7781 FRP (emit_move_insn (sp_adj1, hard_frame_pointer_rtx));
7782 sp_adj2 = const0_rtx;
7784 else if (frame_size < 0x40007fffL)
7786 int low = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
7788 sp_adj2 = plus_constant (sp_adj1, frame_size - low);
7789 if (sa_reg_exp && rtx_equal_p (sa_reg_exp, sp_adj2))
7790 sp_adj1 = sa_reg;
7791 else
7793 sp_adj1 = gen_rtx_REG (DImode, 23);
7794 FRP (emit_move_insn (sp_adj1, sp_adj2));
7796 sp_adj2 = GEN_INT (low);
7798 else
7800 rtx tmp = gen_rtx_REG (DImode, 23);
7801 FRP (sp_adj2 = alpha_emit_set_const (tmp, DImode, frame_size, 3));
7802 if (!sp_adj2)
7804 /* We can't drop new things to memory this late, afaik,
7805 so build it up by pieces. */
7806 FRP (sp_adj2 = alpha_emit_set_long_const (tmp, frame_size,
7807 -(frame_size < 0)));
7808 if (!sp_adj2)
7809 abort ();
7813 /* From now on, things must be in order. So emit blockages. */
7815 /* Restore the frame pointer. */
7816 if (TARGET_ABI_UNICOSMK)
7818 emit_insn (gen_blockage ());
7819 mem = gen_rtx_MEM (DImode,
7820 plus_constant (hard_frame_pointer_rtx, -16));
7821 set_mem_alias_set (mem, alpha_sr_alias_set);
7822 FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7824 else if (fp_is_frame_pointer)
7826 emit_insn (gen_blockage ());
7827 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, fp_offset));
7828 set_mem_alias_set (mem, alpha_sr_alias_set);
7829 FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7831 else if (TARGET_ABI_OPEN_VMS)
7833 emit_insn (gen_blockage ());
7834 FRP (emit_move_insn (hard_frame_pointer_rtx,
7835 gen_rtx_REG (DImode, vms_save_fp_regno)));
7838 /* Restore the stack pointer. */
7839 emit_insn (gen_blockage ());
7840 if (sp_adj2 == const0_rtx)
7841 FRP (emit_move_insn (stack_pointer_rtx, sp_adj1));
7842 else
7843 FRP (emit_move_insn (stack_pointer_rtx,
7844 gen_rtx_PLUS (DImode, sp_adj1, sp_adj2)));
7846 else
7848 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_REGISTER)
7850 emit_insn (gen_blockage ());
7851 FRP (emit_move_insn (hard_frame_pointer_rtx,
7852 gen_rtx_REG (DImode, vms_save_fp_regno)));
7854 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type != PT_STACK)
7856 /* Decrement the frame pointer if the function does not have a
7857 frame. */
7859 emit_insn (gen_blockage ());
7860 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
7861 hard_frame_pointer_rtx, GEN_INT (-1))));
7866 /* Output the rest of the textual info surrounding the epilogue. */
7868 void
7869 alpha_end_function (FILE *file, const char *fnname, tree decl ATTRIBUTE_UNUSED)
7871 /* End the function. */
7872 if (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive)
7874 fputs ("\t.end ", file);
7875 assemble_name (file, fnname);
7876 putc ('\n', file);
7878 inside_function = FALSE;
7880 #if TARGET_ABI_OPEN_VMS
7881 alpha_write_linkage (file, fnname, decl);
7882 #endif
7884 /* Output jump tables and the static subroutine information block. */
7885 if (TARGET_ABI_UNICOSMK)
7887 unicosmk_output_ssib (file, fnname);
7888 unicosmk_output_deferred_case_vectors (file);
7892 #if TARGET_ABI_OSF
7893 /* Emit a tail call to FUNCTION after adjusting THIS by DELTA.
7895 In order to avoid the hordes of differences between generated code
7896 with and without TARGET_EXPLICIT_RELOCS, and to avoid duplicating
7897 lots of code loading up large constants, generate rtl and emit it
7898 instead of going straight to text.
7900 Not sure why this idea hasn't been explored before... */
7902 static void
7903 alpha_output_mi_thunk_osf (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
7904 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
7905 tree function)
7907 HOST_WIDE_INT hi, lo;
7908 rtx this, insn, funexp;
7910 /* We always require a valid GP. */
7911 emit_insn (gen_prologue_ldgp ());
7912 emit_note (NOTE_INSN_PROLOGUE_END);
7914 /* Find the "this" pointer. If the function returns a structure,
7915 the structure return pointer is in $16. */
7916 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
7917 this = gen_rtx_REG (Pmode, 17);
7918 else
7919 this = gen_rtx_REG (Pmode, 16);
7921 /* Add DELTA. When possible we use ldah+lda. Otherwise load the
7922 entire constant for the add. */
7923 lo = ((delta & 0xffff) ^ 0x8000) - 0x8000;
7924 hi = (((delta - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7925 if (hi + lo == delta)
7927 if (hi)
7928 emit_insn (gen_adddi3 (this, this, GEN_INT (hi)));
7929 if (lo)
7930 emit_insn (gen_adddi3 (this, this, GEN_INT (lo)));
7932 else
7934 rtx tmp = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 0),
7935 delta, -(delta < 0));
7936 emit_insn (gen_adddi3 (this, this, tmp));
7939 /* Add a delta stored in the vtable at VCALL_OFFSET. */
7940 if (vcall_offset)
7942 rtx tmp, tmp2;
7944 tmp = gen_rtx_REG (Pmode, 0);
7945 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
7947 lo = ((vcall_offset & 0xffff) ^ 0x8000) - 0x8000;
7948 hi = (((vcall_offset - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7949 if (hi + lo == vcall_offset)
7951 if (hi)
7952 emit_insn (gen_adddi3 (tmp, tmp, GEN_INT (hi)));
7954 else
7956 tmp2 = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 1),
7957 vcall_offset, -(vcall_offset < 0));
7958 emit_insn (gen_adddi3 (tmp, tmp, tmp2));
7959 lo = 0;
7961 if (lo)
7962 tmp2 = gen_rtx_PLUS (Pmode, tmp, GEN_INT (lo));
7963 else
7964 tmp2 = tmp;
7965 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp2));
7967 emit_insn (gen_adddi3 (this, this, tmp));
7970 /* Generate a tail call to the target function. */
7971 if (! TREE_USED (function))
7973 assemble_external (function);
7974 TREE_USED (function) = 1;
7976 funexp = XEXP (DECL_RTL (function), 0);
7977 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
7978 insn = emit_call_insn (gen_sibcall (funexp, const0_rtx));
7979 SIBLING_CALL_P (insn) = 1;
7981 /* Run just enough of rest_of_compilation to get the insns emitted.
7982 There's not really enough bulk here to make other passes such as
7983 instruction scheduling worth while. Note that use_thunk calls
7984 assemble_start_function and assemble_end_function. */
7985 insn = get_insns ();
7986 insn_locators_initialize ();
7987 shorten_branches (insn);
7988 final_start_function (insn, file, 1);
7989 final (insn, file, 1, 0);
7990 final_end_function ();
7992 #endif /* TARGET_ABI_OSF */
7994 /* Debugging support. */
7996 #include "gstab.h"
7998 /* Count the number of sdb related labels are generated (to find block
7999 start and end boundaries). */
8001 int sdb_label_count = 0;
8003 /* Next label # for each statement. */
8005 static int sym_lineno = 0;
8007 /* Count the number of .file directives, so that .loc is up to date. */
8009 static int num_source_filenames = 0;
8011 /* Name of the file containing the current function. */
8013 static const char *current_function_file = "";
8015 /* Offsets to alpha virtual arg/local debugging pointers. */
8017 long alpha_arg_offset;
8018 long alpha_auto_offset;
8020 /* Emit a new filename to a stream. */
8022 void
8023 alpha_output_filename (FILE *stream, const char *name)
8025 static int first_time = TRUE;
8026 char ltext_label_name[100];
8028 if (first_time)
8030 first_time = FALSE;
8031 ++num_source_filenames;
8032 current_function_file = name;
8033 fprintf (stream, "\t.file\t%d ", num_source_filenames);
8034 output_quoted_string (stream, name);
8035 fprintf (stream, "\n");
8036 if (!TARGET_GAS && write_symbols == DBX_DEBUG)
8037 fprintf (stream, "\t#@stabs\n");
8040 else if (write_symbols == DBX_DEBUG)
8042 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
8043 fprintf (stream, "%s", ASM_STABS_OP);
8044 output_quoted_string (stream, name);
8045 fprintf (stream, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
8048 else if (name != current_function_file
8049 && strcmp (name, current_function_file) != 0)
8051 if (inside_function && ! TARGET_GAS)
8052 fprintf (stream, "\t#.file\t%d ", num_source_filenames);
8053 else
8055 ++num_source_filenames;
8056 current_function_file = name;
8057 fprintf (stream, "\t.file\t%d ", num_source_filenames);
8060 output_quoted_string (stream, name);
8061 fprintf (stream, "\n");
8065 /* Emit a linenumber to a stream. */
8067 void
8068 alpha_output_lineno (FILE *stream, int line)
8070 if (write_symbols == DBX_DEBUG)
8072 /* mips-tfile doesn't understand .stabd directives. */
8073 ++sym_lineno;
8074 fprintf (stream, "$LM%d:\n%s%d,0,%d,$LM%d\n",
8075 sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
8077 else
8078 fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
8081 /* Structure to show the current status of registers and memory. */
8083 struct shadow_summary
8085 struct {
8086 unsigned int i : 31; /* Mask of int regs */
8087 unsigned int fp : 31; /* Mask of fp regs */
8088 unsigned int mem : 1; /* mem == imem | fpmem */
8089 } used, defd;
8092 /* Summary the effects of expression X on the machine. Update SUM, a pointer
8093 to the summary structure. SET is nonzero if the insn is setting the
8094 object, otherwise zero. */
8096 static void
8097 summarize_insn (rtx x, struct shadow_summary *sum, int set)
8099 const char *format_ptr;
8100 int i, j;
8102 if (x == 0)
8103 return;
8105 switch (GET_CODE (x))
8107 /* ??? Note that this case would be incorrect if the Alpha had a
8108 ZERO_EXTRACT in SET_DEST. */
8109 case SET:
8110 summarize_insn (SET_SRC (x), sum, 0);
8111 summarize_insn (SET_DEST (x), sum, 1);
8112 break;
8114 case CLOBBER:
8115 summarize_insn (XEXP (x, 0), sum, 1);
8116 break;
8118 case USE:
8119 summarize_insn (XEXP (x, 0), sum, 0);
8120 break;
8122 case ASM_OPERANDS:
8123 for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
8124 summarize_insn (ASM_OPERANDS_INPUT (x, i), sum, 0);
8125 break;
8127 case PARALLEL:
8128 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
8129 summarize_insn (XVECEXP (x, 0, i), sum, 0);
8130 break;
8132 case SUBREG:
8133 summarize_insn (SUBREG_REG (x), sum, 0);
8134 break;
8136 case REG:
8138 int regno = REGNO (x);
8139 unsigned long mask = ((unsigned long) 1) << (regno % 32);
8141 if (regno == 31 || regno == 63)
8142 break;
8144 if (set)
8146 if (regno < 32)
8147 sum->defd.i |= mask;
8148 else
8149 sum->defd.fp |= mask;
8151 else
8153 if (regno < 32)
8154 sum->used.i |= mask;
8155 else
8156 sum->used.fp |= mask;
8159 break;
8161 case MEM:
8162 if (set)
8163 sum->defd.mem = 1;
8164 else
8165 sum->used.mem = 1;
8167 /* Find the regs used in memory address computation: */
8168 summarize_insn (XEXP (x, 0), sum, 0);
8169 break;
8171 case CONST_INT: case CONST_DOUBLE:
8172 case SYMBOL_REF: case LABEL_REF: case CONST:
8173 case SCRATCH: case ASM_INPUT:
8174 break;
8176 /* Handle common unary and binary ops for efficiency. */
8177 case COMPARE: case PLUS: case MINUS: case MULT: case DIV:
8178 case MOD: case UDIV: case UMOD: case AND: case IOR:
8179 case XOR: case ASHIFT: case ROTATE: case ASHIFTRT: case LSHIFTRT:
8180 case ROTATERT: case SMIN: case SMAX: case UMIN: case UMAX:
8181 case NE: case EQ: case GE: case GT: case LE:
8182 case LT: case GEU: case GTU: case LEU: case LTU:
8183 summarize_insn (XEXP (x, 0), sum, 0);
8184 summarize_insn (XEXP (x, 1), sum, 0);
8185 break;
8187 case NEG: case NOT: case SIGN_EXTEND: case ZERO_EXTEND:
8188 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: case FLOAT:
8189 case FIX: case UNSIGNED_FLOAT: case UNSIGNED_FIX: case ABS:
8190 case SQRT: case FFS:
8191 summarize_insn (XEXP (x, 0), sum, 0);
8192 break;
8194 default:
8195 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
8196 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
8197 switch (format_ptr[i])
8199 case 'e':
8200 summarize_insn (XEXP (x, i), sum, 0);
8201 break;
8203 case 'E':
8204 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
8205 summarize_insn (XVECEXP (x, i, j), sum, 0);
8206 break;
8208 case 'i':
8209 break;
8211 default:
8212 abort ();
8217 /* Ensure a sufficient number of `trapb' insns are in the code when
8218 the user requests code with a trap precision of functions or
8219 instructions.
8221 In naive mode, when the user requests a trap-precision of
8222 "instruction", a trapb is needed after every instruction that may
8223 generate a trap. This ensures that the code is resumption safe but
8224 it is also slow.
8226 When optimizations are turned on, we delay issuing a trapb as long
8227 as possible. In this context, a trap shadow is the sequence of
8228 instructions that starts with a (potentially) trap generating
8229 instruction and extends to the next trapb or call_pal instruction
8230 (but GCC never generates call_pal by itself). We can delay (and
8231 therefore sometimes omit) a trapb subject to the following
8232 conditions:
8234 (a) On entry to the trap shadow, if any Alpha register or memory
8235 location contains a value that is used as an operand value by some
8236 instruction in the trap shadow (live on entry), then no instruction
8237 in the trap shadow may modify the register or memory location.
8239 (b) Within the trap shadow, the computation of the base register
8240 for a memory load or store instruction may not involve using the
8241 result of an instruction that might generate an UNPREDICTABLE
8242 result.
8244 (c) Within the trap shadow, no register may be used more than once
8245 as a destination register. (This is to make life easier for the
8246 trap-handler.)
8248 (d) The trap shadow may not include any branch instructions. */
8250 static void
8251 alpha_handle_trap_shadows (void)
8253 struct shadow_summary shadow;
8254 int trap_pending, exception_nesting;
8255 rtx i, n;
8257 trap_pending = 0;
8258 exception_nesting = 0;
8259 shadow.used.i = 0;
8260 shadow.used.fp = 0;
8261 shadow.used.mem = 0;
8262 shadow.defd = shadow.used;
8264 for (i = get_insns (); i ; i = NEXT_INSN (i))
8266 if (GET_CODE (i) == NOTE)
8268 switch (NOTE_LINE_NUMBER (i))
8270 case NOTE_INSN_EH_REGION_BEG:
8271 exception_nesting++;
8272 if (trap_pending)
8273 goto close_shadow;
8274 break;
8276 case NOTE_INSN_EH_REGION_END:
8277 exception_nesting--;
8278 if (trap_pending)
8279 goto close_shadow;
8280 break;
8282 case NOTE_INSN_EPILOGUE_BEG:
8283 if (trap_pending && alpha_tp >= ALPHA_TP_FUNC)
8284 goto close_shadow;
8285 break;
8288 else if (trap_pending)
8290 if (alpha_tp == ALPHA_TP_FUNC)
8292 if (GET_CODE (i) == JUMP_INSN
8293 && GET_CODE (PATTERN (i)) == RETURN)
8294 goto close_shadow;
8296 else if (alpha_tp == ALPHA_TP_INSN)
8298 if (optimize > 0)
8300 struct shadow_summary sum;
8302 sum.used.i = 0;
8303 sum.used.fp = 0;
8304 sum.used.mem = 0;
8305 sum.defd = sum.used;
8307 switch (GET_CODE (i))
8309 case INSN:
8310 /* Annoyingly, get_attr_trap will abort on these. */
8311 if (GET_CODE (PATTERN (i)) == USE
8312 || GET_CODE (PATTERN (i)) == CLOBBER)
8313 break;
8315 summarize_insn (PATTERN (i), &sum, 0);
8317 if ((sum.defd.i & shadow.defd.i)
8318 || (sum.defd.fp & shadow.defd.fp))
8320 /* (c) would be violated */
8321 goto close_shadow;
8324 /* Combine shadow with summary of current insn: */
8325 shadow.used.i |= sum.used.i;
8326 shadow.used.fp |= sum.used.fp;
8327 shadow.used.mem |= sum.used.mem;
8328 shadow.defd.i |= sum.defd.i;
8329 shadow.defd.fp |= sum.defd.fp;
8330 shadow.defd.mem |= sum.defd.mem;
8332 if ((sum.defd.i & shadow.used.i)
8333 || (sum.defd.fp & shadow.used.fp)
8334 || (sum.defd.mem & shadow.used.mem))
8336 /* (a) would be violated (also takes care of (b)) */
8337 if (get_attr_trap (i) == TRAP_YES
8338 && ((sum.defd.i & sum.used.i)
8339 || (sum.defd.fp & sum.used.fp)))
8340 abort ();
8342 goto close_shadow;
8344 break;
8346 case JUMP_INSN:
8347 case CALL_INSN:
8348 case CODE_LABEL:
8349 goto close_shadow;
8351 default:
8352 abort ();
8355 else
8357 close_shadow:
8358 n = emit_insn_before (gen_trapb (), i);
8359 PUT_MODE (n, TImode);
8360 PUT_MODE (i, TImode);
8361 trap_pending = 0;
8362 shadow.used.i = 0;
8363 shadow.used.fp = 0;
8364 shadow.used.mem = 0;
8365 shadow.defd = shadow.used;
8370 if ((exception_nesting > 0 || alpha_tp >= ALPHA_TP_FUNC)
8371 && GET_CODE (i) == INSN
8372 && GET_CODE (PATTERN (i)) != USE
8373 && GET_CODE (PATTERN (i)) != CLOBBER
8374 && get_attr_trap (i) == TRAP_YES)
8376 if (optimize && !trap_pending)
8377 summarize_insn (PATTERN (i), &shadow, 0);
8378 trap_pending = 1;
8383 /* Alpha can only issue instruction groups simultaneously if they are
8384 suitably aligned. This is very processor-specific. */
8386 enum alphaev4_pipe {
8387 EV4_STOP = 0,
8388 EV4_IB0 = 1,
8389 EV4_IB1 = 2,
8390 EV4_IBX = 4
8393 enum alphaev5_pipe {
8394 EV5_STOP = 0,
8395 EV5_NONE = 1,
8396 EV5_E01 = 2,
8397 EV5_E0 = 4,
8398 EV5_E1 = 8,
8399 EV5_FAM = 16,
8400 EV5_FA = 32,
8401 EV5_FM = 64
8404 static enum alphaev4_pipe
8405 alphaev4_insn_pipe (rtx insn)
8407 if (recog_memoized (insn) < 0)
8408 return EV4_STOP;
8409 if (get_attr_length (insn) != 4)
8410 return EV4_STOP;
8412 switch (get_attr_type (insn))
8414 case TYPE_ILD:
8415 case TYPE_FLD:
8416 return EV4_IBX;
8418 case TYPE_LDSYM:
8419 case TYPE_IADD:
8420 case TYPE_ILOG:
8421 case TYPE_ICMOV:
8422 case TYPE_ICMP:
8423 case TYPE_IST:
8424 case TYPE_FST:
8425 case TYPE_SHIFT:
8426 case TYPE_IMUL:
8427 case TYPE_FBR:
8428 return EV4_IB0;
8430 case TYPE_MISC:
8431 case TYPE_IBR:
8432 case TYPE_JSR:
8433 case TYPE_CALLPAL:
8434 case TYPE_FCPYS:
8435 case TYPE_FCMOV:
8436 case TYPE_FADD:
8437 case TYPE_FDIV:
8438 case TYPE_FMUL:
8439 return EV4_IB1;
8441 default:
8442 abort ();
8446 static enum alphaev5_pipe
8447 alphaev5_insn_pipe (rtx insn)
8449 if (recog_memoized (insn) < 0)
8450 return EV5_STOP;
8451 if (get_attr_length (insn) != 4)
8452 return EV5_STOP;
8454 switch (get_attr_type (insn))
8456 case TYPE_ILD:
8457 case TYPE_FLD:
8458 case TYPE_LDSYM:
8459 case TYPE_IADD:
8460 case TYPE_ILOG:
8461 case TYPE_ICMOV:
8462 case TYPE_ICMP:
8463 return EV5_E01;
8465 case TYPE_IST:
8466 case TYPE_FST:
8467 case TYPE_SHIFT:
8468 case TYPE_IMUL:
8469 case TYPE_MISC:
8470 case TYPE_MVI:
8471 return EV5_E0;
8473 case TYPE_IBR:
8474 case TYPE_JSR:
8475 case TYPE_CALLPAL:
8476 return EV5_E1;
8478 case TYPE_FCPYS:
8479 return EV5_FAM;
8481 case TYPE_FBR:
8482 case TYPE_FCMOV:
8483 case TYPE_FADD:
8484 case TYPE_FDIV:
8485 return EV5_FA;
8487 case TYPE_FMUL:
8488 return EV5_FM;
8490 default:
8491 abort();
8495 /* IN_USE is a mask of the slots currently filled within the insn group.
8496 The mask bits come from alphaev4_pipe above. If EV4_IBX is set, then
8497 the insn in EV4_IB0 can be swapped by the hardware into EV4_IB1.
8499 LEN is, of course, the length of the group in bytes. */
8501 static rtx
8502 alphaev4_next_group (rtx insn, int *pin_use, int *plen)
8504 int len, in_use;
8506 len = in_use = 0;
8508 if (! INSN_P (insn)
8509 || GET_CODE (PATTERN (insn)) == CLOBBER
8510 || GET_CODE (PATTERN (insn)) == USE)
8511 goto next_and_done;
8513 while (1)
8515 enum alphaev4_pipe pipe;
8517 pipe = alphaev4_insn_pipe (insn);
8518 switch (pipe)
8520 case EV4_STOP:
8521 /* Force complex instructions to start new groups. */
8522 if (in_use)
8523 goto done;
8525 /* If this is a completely unrecognized insn, its an asm.
8526 We don't know how long it is, so record length as -1 to
8527 signal a needed realignment. */
8528 if (recog_memoized (insn) < 0)
8529 len = -1;
8530 else
8531 len = get_attr_length (insn);
8532 goto next_and_done;
8534 case EV4_IBX:
8535 if (in_use & EV4_IB0)
8537 if (in_use & EV4_IB1)
8538 goto done;
8539 in_use |= EV4_IB1;
8541 else
8542 in_use |= EV4_IB0 | EV4_IBX;
8543 break;
8545 case EV4_IB0:
8546 if (in_use & EV4_IB0)
8548 if (!(in_use & EV4_IBX) || (in_use & EV4_IB1))
8549 goto done;
8550 in_use |= EV4_IB1;
8552 in_use |= EV4_IB0;
8553 break;
8555 case EV4_IB1:
8556 if (in_use & EV4_IB1)
8557 goto done;
8558 in_use |= EV4_IB1;
8559 break;
8561 default:
8562 abort();
8564 len += 4;
8566 /* Haifa doesn't do well scheduling branches. */
8567 if (GET_CODE (insn) == JUMP_INSN)
8568 goto next_and_done;
8570 next:
8571 insn = next_nonnote_insn (insn);
8573 if (!insn || ! INSN_P (insn))
8574 goto done;
8576 /* Let Haifa tell us where it thinks insn group boundaries are. */
8577 if (GET_MODE (insn) == TImode)
8578 goto done;
8580 if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8581 goto next;
8584 next_and_done:
8585 insn = next_nonnote_insn (insn);
8587 done:
8588 *plen = len;
8589 *pin_use = in_use;
8590 return insn;
8593 /* IN_USE is a mask of the slots currently filled within the insn group.
8594 The mask bits come from alphaev5_pipe above. If EV5_E01 is set, then
8595 the insn in EV5_E0 can be swapped by the hardware into EV5_E1.
8597 LEN is, of course, the length of the group in bytes. */
8599 static rtx
8600 alphaev5_next_group (rtx insn, int *pin_use, int *plen)
8602 int len, in_use;
8604 len = in_use = 0;
8606 if (! INSN_P (insn)
8607 || GET_CODE (PATTERN (insn)) == CLOBBER
8608 || GET_CODE (PATTERN (insn)) == USE)
8609 goto next_and_done;
8611 while (1)
8613 enum alphaev5_pipe pipe;
8615 pipe = alphaev5_insn_pipe (insn);
8616 switch (pipe)
8618 case EV5_STOP:
8619 /* Force complex instructions to start new groups. */
8620 if (in_use)
8621 goto done;
8623 /* If this is a completely unrecognized insn, its an asm.
8624 We don't know how long it is, so record length as -1 to
8625 signal a needed realignment. */
8626 if (recog_memoized (insn) < 0)
8627 len = -1;
8628 else
8629 len = get_attr_length (insn);
8630 goto next_and_done;
8632 /* ??? Most of the places below, we would like to abort, as
8633 it would indicate an error either in Haifa, or in the
8634 scheduling description. Unfortunately, Haifa never
8635 schedules the last instruction of the BB, so we don't
8636 have an accurate TI bit to go off. */
8637 case EV5_E01:
8638 if (in_use & EV5_E0)
8640 if (in_use & EV5_E1)
8641 goto done;
8642 in_use |= EV5_E1;
8644 else
8645 in_use |= EV5_E0 | EV5_E01;
8646 break;
8648 case EV5_E0:
8649 if (in_use & EV5_E0)
8651 if (!(in_use & EV5_E01) || (in_use & EV5_E1))
8652 goto done;
8653 in_use |= EV5_E1;
8655 in_use |= EV5_E0;
8656 break;
8658 case EV5_E1:
8659 if (in_use & EV5_E1)
8660 goto done;
8661 in_use |= EV5_E1;
8662 break;
8664 case EV5_FAM:
8665 if (in_use & EV5_FA)
8667 if (in_use & EV5_FM)
8668 goto done;
8669 in_use |= EV5_FM;
8671 else
8672 in_use |= EV5_FA | EV5_FAM;
8673 break;
8675 case EV5_FA:
8676 if (in_use & EV5_FA)
8677 goto done;
8678 in_use |= EV5_FA;
8679 break;
8681 case EV5_FM:
8682 if (in_use & EV5_FM)
8683 goto done;
8684 in_use |= EV5_FM;
8685 break;
8687 case EV5_NONE:
8688 break;
8690 default:
8691 abort();
8693 len += 4;
8695 /* Haifa doesn't do well scheduling branches. */
8696 /* ??? If this is predicted not-taken, slotting continues, except
8697 that no more IBR, FBR, or JSR insns may be slotted. */
8698 if (GET_CODE (insn) == JUMP_INSN)
8699 goto next_and_done;
8701 next:
8702 insn = next_nonnote_insn (insn);
8704 if (!insn || ! INSN_P (insn))
8705 goto done;
8707 /* Let Haifa tell us where it thinks insn group boundaries are. */
8708 if (GET_MODE (insn) == TImode)
8709 goto done;
8711 if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8712 goto next;
8715 next_and_done:
8716 insn = next_nonnote_insn (insn);
8718 done:
8719 *plen = len;
8720 *pin_use = in_use;
8721 return insn;
8724 static rtx
8725 alphaev4_next_nop (int *pin_use)
8727 int in_use = *pin_use;
8728 rtx nop;
8730 if (!(in_use & EV4_IB0))
8732 in_use |= EV4_IB0;
8733 nop = gen_nop ();
8735 else if ((in_use & (EV4_IBX|EV4_IB1)) == EV4_IBX)
8737 in_use |= EV4_IB1;
8738 nop = gen_nop ();
8740 else if (TARGET_FP && !(in_use & EV4_IB1))
8742 in_use |= EV4_IB1;
8743 nop = gen_fnop ();
8745 else
8746 nop = gen_unop ();
8748 *pin_use = in_use;
8749 return nop;
8752 static rtx
8753 alphaev5_next_nop (int *pin_use)
8755 int in_use = *pin_use;
8756 rtx nop;
8758 if (!(in_use & EV5_E1))
8760 in_use |= EV5_E1;
8761 nop = gen_nop ();
8763 else if (TARGET_FP && !(in_use & EV5_FA))
8765 in_use |= EV5_FA;
8766 nop = gen_fnop ();
8768 else if (TARGET_FP && !(in_use & EV5_FM))
8770 in_use |= EV5_FM;
8771 nop = gen_fnop ();
8773 else
8774 nop = gen_unop ();
8776 *pin_use = in_use;
8777 return nop;
8780 /* The instruction group alignment main loop. */
8782 static void
8783 alpha_align_insns (unsigned int max_align,
8784 rtx (*next_group) (rtx, int *, int *),
8785 rtx (*next_nop) (int *))
8787 /* ALIGN is the known alignment for the insn group. */
8788 unsigned int align;
8789 /* OFS is the offset of the current insn in the insn group. */
8790 int ofs;
8791 int prev_in_use, in_use, len;
8792 rtx i, next;
8794 /* Let shorten branches care for assigning alignments to code labels. */
8795 shorten_branches (get_insns ());
8797 if (align_functions < 4)
8798 align = 4;
8799 else if ((unsigned int) align_functions < max_align)
8800 align = align_functions;
8801 else
8802 align = max_align;
8804 ofs = prev_in_use = 0;
8805 i = get_insns ();
8806 if (GET_CODE (i) == NOTE)
8807 i = next_nonnote_insn (i);
8809 while (i)
8811 next = (*next_group) (i, &in_use, &len);
8813 /* When we see a label, resync alignment etc. */
8814 if (GET_CODE (i) == CODE_LABEL)
8816 unsigned int new_align = 1 << label_to_alignment (i);
8818 if (new_align >= align)
8820 align = new_align < max_align ? new_align : max_align;
8821 ofs = 0;
8824 else if (ofs & (new_align-1))
8825 ofs = (ofs | (new_align-1)) + 1;
8826 if (len != 0)
8827 abort();
8830 /* Handle complex instructions special. */
8831 else if (in_use == 0)
8833 /* Asms will have length < 0. This is a signal that we have
8834 lost alignment knowledge. Assume, however, that the asm
8835 will not mis-align instructions. */
8836 if (len < 0)
8838 ofs = 0;
8839 align = 4;
8840 len = 0;
8844 /* If the known alignment is smaller than the recognized insn group,
8845 realign the output. */
8846 else if ((int) align < len)
8848 unsigned int new_log_align = len > 8 ? 4 : 3;
8849 rtx prev, where;
8851 where = prev = prev_nonnote_insn (i);
8852 if (!where || GET_CODE (where) != CODE_LABEL)
8853 where = i;
8855 /* Can't realign between a call and its gp reload. */
8856 if (! (TARGET_EXPLICIT_RELOCS
8857 && prev && GET_CODE (prev) == CALL_INSN))
8859 emit_insn_before (gen_realign (GEN_INT (new_log_align)), where);
8860 align = 1 << new_log_align;
8861 ofs = 0;
8865 /* If the group won't fit in the same INT16 as the previous,
8866 we need to add padding to keep the group together. Rather
8867 than simply leaving the insn filling to the assembler, we
8868 can make use of the knowledge of what sorts of instructions
8869 were issued in the previous group to make sure that all of
8870 the added nops are really free. */
8871 else if (ofs + len > (int) align)
8873 int nop_count = (align - ofs) / 4;
8874 rtx where;
8876 /* Insert nops before labels, branches, and calls to truly merge
8877 the execution of the nops with the previous instruction group. */
8878 where = prev_nonnote_insn (i);
8879 if (where)
8881 if (GET_CODE (where) == CODE_LABEL)
8883 rtx where2 = prev_nonnote_insn (where);
8884 if (where2 && GET_CODE (where2) == JUMP_INSN)
8885 where = where2;
8887 else if (GET_CODE (where) == INSN)
8888 where = i;
8890 else
8891 where = i;
8894 emit_insn_before ((*next_nop)(&prev_in_use), where);
8895 while (--nop_count);
8896 ofs = 0;
8899 ofs = (ofs + len) & (align - 1);
8900 prev_in_use = in_use;
8901 i = next;
8905 /* Machine dependent reorg pass. */
8907 static void
8908 alpha_reorg (void)
8910 if (alpha_tp != ALPHA_TP_PROG || flag_exceptions)
8911 alpha_handle_trap_shadows ();
8913 /* Due to the number of extra trapb insns, don't bother fixing up
8914 alignment when trap precision is instruction. Moreover, we can
8915 only do our job when sched2 is run. */
8916 if (optimize && !optimize_size
8917 && alpha_tp != ALPHA_TP_INSN
8918 && flag_schedule_insns_after_reload)
8920 if (alpha_cpu == PROCESSOR_EV4)
8921 alpha_align_insns (8, alphaev4_next_group, alphaev4_next_nop);
8922 else if (alpha_cpu == PROCESSOR_EV5)
8923 alpha_align_insns (16, alphaev5_next_group, alphaev5_next_nop);
8927 #if !TARGET_ABI_UNICOSMK
8929 #ifdef HAVE_STAMP_H
8930 #include <stamp.h>
8931 #endif
8933 static void
8934 alpha_file_start (void)
8936 #ifdef OBJECT_FORMAT_ELF
8937 /* If emitting dwarf2 debug information, we cannot generate a .file
8938 directive to start the file, as it will conflict with dwarf2out
8939 file numbers. So it's only useful when emitting mdebug output. */
8940 targetm.file_start_file_directive = (write_symbols == DBX_DEBUG);
8941 #endif
8943 default_file_start ();
8944 #ifdef MS_STAMP
8945 fprintf (asm_out_file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP);
8946 #endif
8948 fputs ("\t.set noreorder\n", asm_out_file);
8949 fputs ("\t.set volatile\n", asm_out_file);
8950 if (!TARGET_ABI_OPEN_VMS)
8951 fputs ("\t.set noat\n", asm_out_file);
8952 if (TARGET_EXPLICIT_RELOCS)
8953 fputs ("\t.set nomacro\n", asm_out_file);
8954 if (TARGET_SUPPORT_ARCH | TARGET_BWX | TARGET_MAX | TARGET_FIX | TARGET_CIX)
8955 fprintf (asm_out_file,
8956 "\t.arch %s\n",
8957 TARGET_CPU_EV6 ? "ev6"
8958 : (TARGET_CPU_EV5
8959 ? (TARGET_MAX ? "pca56" : TARGET_BWX ? "ev56" : "ev5")
8960 : "ev4"));
8962 #endif
8964 #ifdef OBJECT_FORMAT_ELF
8966 /* Switch to the section to which we should output X. The only thing
8967 special we do here is to honor small data. */
8969 static void
8970 alpha_elf_select_rtx_section (enum machine_mode mode, rtx x,
8971 unsigned HOST_WIDE_INT align)
8973 if (TARGET_SMALL_DATA && GET_MODE_SIZE (mode) <= g_switch_value)
8974 /* ??? Consider using mergeable sdata sections. */
8975 sdata_section ();
8976 else
8977 default_elf_select_rtx_section (mode, x, align);
8980 #endif /* OBJECT_FORMAT_ELF */
8982 /* Structure to collect function names for final output in link section. */
8983 /* Note that items marked with GTY can't be ifdef'ed out. */
8985 enum links_kind {KIND_UNUSED, KIND_LOCAL, KIND_EXTERN};
8986 enum reloc_kind {KIND_LINKAGE, KIND_CODEADDR};
8988 struct alpha_links GTY(())
8990 int num;
8991 rtx linkage;
8992 enum links_kind lkind;
8993 enum reloc_kind rkind;
8996 struct alpha_funcs GTY(())
8998 int num;
8999 splay_tree GTY ((param1_is (char *), param2_is (struct alpha_links *)))
9000 links;
9003 static GTY ((param1_is (char *), param2_is (struct alpha_links *)))
9004 splay_tree alpha_links_tree;
9005 static GTY ((param1_is (tree), param2_is (struct alpha_funcs *)))
9006 splay_tree alpha_funcs_tree;
9008 static GTY(()) int alpha_funcs_num;
9010 #if TARGET_ABI_OPEN_VMS
9012 /* Return the VMS argument type corresponding to MODE. */
9014 enum avms_arg_type
9015 alpha_arg_type (enum machine_mode mode)
9017 switch (mode)
9019 case SFmode:
9020 return TARGET_FLOAT_VAX ? FF : FS;
9021 case DFmode:
9022 return TARGET_FLOAT_VAX ? FD : FT;
9023 default:
9024 return I64;
9028 /* Return an rtx for an integer representing the VMS Argument Information
9029 register value. */
9032 alpha_arg_info_reg_val (CUMULATIVE_ARGS cum)
9034 unsigned HOST_WIDE_INT regval = cum.num_args;
9035 int i;
9037 for (i = 0; i < 6; i++)
9038 regval |= ((int) cum.atypes[i]) << (i * 3 + 8);
9040 return GEN_INT (regval);
9043 /* Make (or fake) .linkage entry for function call.
9045 IS_LOCAL is 0 if name is used in call, 1 if name is used in definition.
9047 Return an SYMBOL_REF rtx for the linkage. */
9050 alpha_need_linkage (const char *name, int is_local)
9052 splay_tree_node node;
9053 struct alpha_links *al;
9055 if (name[0] == '*')
9056 name++;
9058 if (is_local)
9060 struct alpha_funcs *cfaf;
9062 if (!alpha_funcs_tree)
9063 alpha_funcs_tree = splay_tree_new_ggc ((splay_tree_compare_fn)
9064 splay_tree_compare_pointers);
9066 cfaf = (struct alpha_funcs *) ggc_alloc (sizeof (struct alpha_funcs));
9068 cfaf->links = 0;
9069 cfaf->num = ++alpha_funcs_num;
9071 splay_tree_insert (alpha_funcs_tree,
9072 (splay_tree_key) current_function_decl,
9073 (splay_tree_value) cfaf);
9076 if (alpha_links_tree)
9078 /* Is this name already defined? */
9080 node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
9081 if (node)
9083 al = (struct alpha_links *) node->value;
9084 if (is_local)
9086 /* Defined here but external assumed. */
9087 if (al->lkind == KIND_EXTERN)
9088 al->lkind = KIND_LOCAL;
9090 else
9092 /* Used here but unused assumed. */
9093 if (al->lkind == KIND_UNUSED)
9094 al->lkind = KIND_LOCAL;
9096 return al->linkage;
9099 else
9100 alpha_links_tree = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
9102 al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
9103 name = ggc_strdup (name);
9105 /* Assume external if no definition. */
9106 al->lkind = (is_local ? KIND_UNUSED : KIND_EXTERN);
9108 /* Ensure we have an IDENTIFIER so assemble_name can mark it used. */
9109 get_identifier (name);
9111 /* Construct a SYMBOL_REF for us to call. */
9113 size_t name_len = strlen (name);
9114 char *linksym = alloca (name_len + 6);
9115 linksym[0] = '$';
9116 memcpy (linksym + 1, name, name_len);
9117 memcpy (linksym + 1 + name_len, "..lk", 5);
9118 al->linkage = gen_rtx_SYMBOL_REF (Pmode,
9119 ggc_alloc_string (linksym, name_len + 5));
9122 splay_tree_insert (alpha_links_tree, (splay_tree_key) name,
9123 (splay_tree_value) al);
9125 return al->linkage;
9129 alpha_use_linkage (rtx linkage, tree cfundecl, int lflag, int rflag)
9131 splay_tree_node cfunnode;
9132 struct alpha_funcs *cfaf;
9133 struct alpha_links *al;
9134 const char *name = XSTR (linkage, 0);
9136 cfaf = (struct alpha_funcs *) 0;
9137 al = (struct alpha_links *) 0;
9139 cfunnode = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) cfundecl);
9140 cfaf = (struct alpha_funcs *) cfunnode->value;
9142 if (cfaf->links)
9144 splay_tree_node lnode;
9146 /* Is this name already defined? */
9148 lnode = splay_tree_lookup (cfaf->links, (splay_tree_key) name);
9149 if (lnode)
9150 al = (struct alpha_links *) lnode->value;
9152 else
9153 cfaf->links = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
9155 if (!al)
9157 size_t name_len;
9158 size_t buflen;
9159 char buf [512];
9160 char *linksym;
9161 splay_tree_node node = 0;
9162 struct alpha_links *anl;
9164 if (name[0] == '*')
9165 name++;
9167 name_len = strlen (name);
9169 al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
9170 al->num = cfaf->num;
9172 node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
9173 if (node)
9175 anl = (struct alpha_links *) node->value;
9176 al->lkind = anl->lkind;
9179 sprintf (buf, "$%d..%s..lk", cfaf->num, name);
9180 buflen = strlen (buf);
9181 linksym = alloca (buflen + 1);
9182 memcpy (linksym, buf, buflen + 1);
9184 al->linkage = gen_rtx_SYMBOL_REF
9185 (Pmode, ggc_alloc_string (linksym, buflen + 1));
9187 splay_tree_insert (cfaf->links, (splay_tree_key) name,
9188 (splay_tree_value) al);
9191 if (rflag)
9192 al->rkind = KIND_CODEADDR;
9193 else
9194 al->rkind = KIND_LINKAGE;
9196 if (lflag)
9197 return gen_rtx_MEM (Pmode, plus_constant (al->linkage, 8));
9198 else
9199 return al->linkage;
9202 static int
9203 alpha_write_one_linkage (splay_tree_node node, void *data)
9205 const char *const name = (const char *) node->key;
9206 struct alpha_links *link = (struct alpha_links *) node->value;
9207 FILE *stream = (FILE *) data;
9209 fprintf (stream, "$%d..%s..lk:\n", link->num, name);
9210 if (link->rkind == KIND_CODEADDR)
9212 if (link->lkind == KIND_LOCAL)
9214 /* Local and used */
9215 fprintf (stream, "\t.quad %s..en\n", name);
9217 else
9219 /* External and used, request code address. */
9220 fprintf (stream, "\t.code_address %s\n", name);
9223 else
9225 if (link->lkind == KIND_LOCAL)
9227 /* Local and used, build linkage pair. */
9228 fprintf (stream, "\t.quad %s..en\n", name);
9229 fprintf (stream, "\t.quad %s\n", name);
9231 else
9233 /* External and used, request linkage pair. */
9234 fprintf (stream, "\t.linkage %s\n", name);
9238 return 0;
9241 static void
9242 alpha_write_linkage (FILE *stream, const char *funname, tree fundecl)
9244 splay_tree_node node;
9245 struct alpha_funcs *func;
9247 link_section ();
9248 fprintf (stream, "\t.align 3\n");
9249 node = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) fundecl);
9250 func = (struct alpha_funcs *) node->value;
9252 fputs ("\t.name ", stream);
9253 assemble_name (stream, funname);
9254 fputs ("..na\n", stream);
9255 ASM_OUTPUT_LABEL (stream, funname);
9256 fprintf (stream, "\t.pdesc ");
9257 assemble_name (stream, funname);
9258 fprintf (stream, "..en,%s\n",
9259 alpha_procedure_type == PT_STACK ? "stack"
9260 : alpha_procedure_type == PT_REGISTER ? "reg" : "null");
9262 if (func->links)
9264 splay_tree_foreach (func->links, alpha_write_one_linkage, stream);
9265 /* splay_tree_delete (func->links); */
9269 /* Given a decl, a section name, and whether the decl initializer
9270 has relocs, choose attributes for the section. */
9272 #define SECTION_VMS_OVERLAY SECTION_FORGET
9273 #define SECTION_VMS_GLOBAL SECTION_MACH_DEP
9274 #define SECTION_VMS_INITIALIZE (SECTION_VMS_GLOBAL << 1)
9276 static unsigned int
9277 vms_section_type_flags (tree decl, const char *name, int reloc)
9279 unsigned int flags = default_section_type_flags (decl, name, reloc);
9281 if (decl && DECL_ATTRIBUTES (decl)
9282 && lookup_attribute ("overlaid", DECL_ATTRIBUTES (decl)))
9283 flags |= SECTION_VMS_OVERLAY;
9284 if (decl && DECL_ATTRIBUTES (decl)
9285 && lookup_attribute ("global", DECL_ATTRIBUTES (decl)))
9286 flags |= SECTION_VMS_GLOBAL;
9287 if (decl && DECL_ATTRIBUTES (decl)
9288 && lookup_attribute ("initialize", DECL_ATTRIBUTES (decl)))
9289 flags |= SECTION_VMS_INITIALIZE;
9291 return flags;
9294 /* Switch to an arbitrary section NAME with attributes as specified
9295 by FLAGS. ALIGN specifies any known alignment requirements for
9296 the section; 0 if the default should be used. */
9298 static void
9299 vms_asm_named_section (const char *name, unsigned int flags)
9301 fputc ('\n', asm_out_file);
9302 fprintf (asm_out_file, ".section\t%s", name);
9304 if (flags & SECTION_VMS_OVERLAY)
9305 fprintf (asm_out_file, ",OVR");
9306 if (flags & SECTION_VMS_GLOBAL)
9307 fprintf (asm_out_file, ",GBL");
9308 if (flags & SECTION_VMS_INITIALIZE)
9309 fprintf (asm_out_file, ",NOMOD");
9310 if (flags & SECTION_DEBUG)
9311 fprintf (asm_out_file, ",NOWRT");
9313 fputc ('\n', asm_out_file);
9316 /* Record an element in the table of global constructors. SYMBOL is
9317 a SYMBOL_REF of the function to be called; PRIORITY is a number
9318 between 0 and MAX_INIT_PRIORITY.
9320 Differs from default_ctors_section_asm_out_constructor in that the
9321 width of the .ctors entry is always 64 bits, rather than the 32 bits
9322 used by a normal pointer. */
9324 static void
9325 vms_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9327 ctors_section ();
9328 assemble_align (BITS_PER_WORD);
9329 assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9332 static void
9333 vms_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9335 dtors_section ();
9336 assemble_align (BITS_PER_WORD);
9337 assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9339 #else
9342 alpha_need_linkage (const char *name ATTRIBUTE_UNUSED,
9343 int is_local ATTRIBUTE_UNUSED)
9345 return NULL_RTX;
9349 alpha_use_linkage (rtx linkage ATTRIBUTE_UNUSED,
9350 tree cfundecl ATTRIBUTE_UNUSED,
9351 int lflag ATTRIBUTE_UNUSED,
9352 int rflag ATTRIBUTE_UNUSED)
9354 return NULL_RTX;
9357 #endif /* TARGET_ABI_OPEN_VMS */
9359 #if TARGET_ABI_UNICOSMK
9361 /* Define the offset between two registers, one to be eliminated, and the
9362 other its replacement, at the start of a routine. */
9365 unicosmk_initial_elimination_offset (int from, int to)
9367 int fixed_size;
9369 fixed_size = alpha_sa_size();
9370 if (fixed_size != 0)
9371 fixed_size += 48;
9373 if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9374 return -fixed_size;
9375 else if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9376 return 0;
9377 else if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9378 return (ALPHA_ROUND (current_function_outgoing_args_size)
9379 + ALPHA_ROUND (get_frame_size()));
9380 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9381 return (ALPHA_ROUND (fixed_size)
9382 + ALPHA_ROUND (get_frame_size()
9383 + current_function_outgoing_args_size));
9384 else
9385 abort ();
9388 /* Output the module name for .ident and .end directives. We have to strip
9389 directories and add make sure that the module name starts with a letter
9390 or '$'. */
9392 static void
9393 unicosmk_output_module_name (FILE *file)
9395 const char *name = lbasename (main_input_filename);
9396 unsigned len = strlen (name);
9397 char *clean_name = alloca (len + 2);
9398 char *ptr = clean_name;
9400 /* CAM only accepts module names that start with a letter or '$'. We
9401 prefix the module name with a '$' if necessary. */
9403 if (!ISALPHA (*name))
9404 *ptr++ = '$';
9405 memcpy (ptr, name, len + 1);
9406 clean_symbol_name (clean_name);
9407 fputs (clean_name, file);
9410 /* Output the definition of a common variable. */
9412 void
9413 unicosmk_output_common (FILE *file, const char *name, int size, int align)
9415 tree name_tree;
9416 printf ("T3E__: common %s\n", name);
9418 common_section ();
9419 fputs("\t.endp\n\n\t.psect ", file);
9420 assemble_name(file, name);
9421 fprintf(file, ",%d,common\n", floor_log2 (align / BITS_PER_UNIT));
9422 fprintf(file, "\t.byte\t0:%d\n", size);
9424 /* Mark the symbol as defined in this module. */
9425 name_tree = get_identifier (name);
9426 TREE_ASM_WRITTEN (name_tree) = 1;
9429 #define SECTION_PUBLIC SECTION_MACH_DEP
9430 #define SECTION_MAIN (SECTION_PUBLIC << 1)
9431 static int current_section_align;
9433 static unsigned int
9434 unicosmk_section_type_flags (tree decl, const char *name,
9435 int reloc ATTRIBUTE_UNUSED)
9437 unsigned int flags = default_section_type_flags (decl, name, reloc);
9439 if (!decl)
9440 return flags;
9442 if (TREE_CODE (decl) == FUNCTION_DECL)
9444 current_section_align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
9445 if (align_functions_log > current_section_align)
9446 current_section_align = align_functions_log;
9448 if (! strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "main"))
9449 flags |= SECTION_MAIN;
9451 else
9452 current_section_align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
9454 if (TREE_PUBLIC (decl))
9455 flags |= SECTION_PUBLIC;
9457 return flags;
9460 /* Generate a section name for decl and associate it with the
9461 declaration. */
9463 static void
9464 unicosmk_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
9466 const char *name;
9467 int len;
9469 if (!decl)
9470 abort ();
9472 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9473 name = default_strip_name_encoding (name);
9474 len = strlen (name);
9476 if (TREE_CODE (decl) == FUNCTION_DECL)
9478 char *string;
9480 /* It is essential that we prefix the section name here because
9481 otherwise the section names generated for constructors and
9482 destructors confuse collect2. */
9484 string = alloca (len + 6);
9485 sprintf (string, "code@%s", name);
9486 DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9488 else if (TREE_PUBLIC (decl))
9489 DECL_SECTION_NAME (decl) = build_string (len, name);
9490 else
9492 char *string;
9494 string = alloca (len + 6);
9495 sprintf (string, "data@%s", name);
9496 DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9500 /* Switch to an arbitrary section NAME with attributes as specified
9501 by FLAGS. ALIGN specifies any known alignment requirements for
9502 the section; 0 if the default should be used. */
9504 static void
9505 unicosmk_asm_named_section (const char *name, unsigned int flags)
9507 const char *kind;
9509 /* Close the previous section. */
9511 fputs ("\t.endp\n\n", asm_out_file);
9513 /* Find out what kind of section we are opening. */
9515 if (flags & SECTION_MAIN)
9516 fputs ("\t.start\tmain\n", asm_out_file);
9518 if (flags & SECTION_CODE)
9519 kind = "code";
9520 else if (flags & SECTION_PUBLIC)
9521 kind = "common";
9522 else
9523 kind = "data";
9525 if (current_section_align != 0)
9526 fprintf (asm_out_file, "\t.psect\t%s,%d,%s\n", name,
9527 current_section_align, kind);
9528 else
9529 fprintf (asm_out_file, "\t.psect\t%s,%s\n", name, kind);
9532 static void
9533 unicosmk_insert_attributes (tree decl, tree *attr_ptr ATTRIBUTE_UNUSED)
9535 if (DECL_P (decl)
9536 && (TREE_PUBLIC (decl) || TREE_CODE (decl) == FUNCTION_DECL))
9537 unicosmk_unique_section (decl, 0);
9540 /* Output an alignment directive. We have to use the macro 'gcc@code@align'
9541 in code sections because .align fill unused space with zeroes. */
9543 void
9544 unicosmk_output_align (FILE *file, int align)
9546 if (inside_function)
9547 fprintf (file, "\tgcc@code@align\t%d\n", align);
9548 else
9549 fprintf (file, "\t.align\t%d\n", align);
9552 /* Add a case vector to the current function's list of deferred case
9553 vectors. Case vectors have to be put into a separate section because CAM
9554 does not allow data definitions in code sections. */
9556 void
9557 unicosmk_defer_case_vector (rtx lab, rtx vec)
9559 struct machine_function *machine = cfun->machine;
9561 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
9562 machine->addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec,
9563 machine->addr_list);
9566 /* Output a case vector. */
9568 static void
9569 unicosmk_output_addr_vec (FILE *file, rtx vec)
9571 rtx lab = XEXP (vec, 0);
9572 rtx body = XEXP (vec, 1);
9573 int vlen = XVECLEN (body, 0);
9574 int idx;
9576 (*targetm.asm_out.internal_label) (file, "L", CODE_LABEL_NUMBER (lab));
9578 for (idx = 0; idx < vlen; idx++)
9580 ASM_OUTPUT_ADDR_VEC_ELT
9581 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
9585 /* Output current function's deferred case vectors. */
9587 static void
9588 unicosmk_output_deferred_case_vectors (FILE *file)
9590 struct machine_function *machine = cfun->machine;
9591 rtx t;
9593 if (machine->addr_list == NULL_RTX)
9594 return;
9596 data_section ();
9597 for (t = machine->addr_list; t; t = XEXP (t, 1))
9598 unicosmk_output_addr_vec (file, XEXP (t, 0));
9601 /* Generate the name of the SSIB section for the current function. */
9603 #define SSIB_PREFIX "__SSIB_"
9604 #define SSIB_PREFIX_LEN 7
9606 static const char *
9607 unicosmk_ssib_name (void)
9609 /* This is ok since CAM won't be able to deal with names longer than that
9610 anyway. */
9612 static char name[256];
9614 rtx x;
9615 const char *fnname;
9616 int len;
9618 x = DECL_RTL (cfun->decl);
9619 if (GET_CODE (x) != MEM)
9620 abort ();
9621 x = XEXP (x, 0);
9622 if (GET_CODE (x) != SYMBOL_REF)
9623 abort ();
9624 fnname = XSTR (x, 0);
9626 len = strlen (fnname);
9627 if (len + SSIB_PREFIX_LEN > 255)
9628 len = 255 - SSIB_PREFIX_LEN;
9630 strcpy (name, SSIB_PREFIX);
9631 strncpy (name + SSIB_PREFIX_LEN, fnname, len);
9632 name[len + SSIB_PREFIX_LEN] = 0;
9634 return name;
9637 /* Set up the dynamic subprogram information block (DSIB) and update the
9638 frame pointer register ($15) for subroutines which have a frame. If the
9639 subroutine doesn't have a frame, simply increment $15. */
9641 static void
9642 unicosmk_gen_dsib (unsigned long *imaskP)
9644 if (alpha_procedure_type == PT_STACK)
9646 const char *ssib_name;
9647 rtx mem;
9649 /* Allocate 64 bytes for the DSIB. */
9651 FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
9652 GEN_INT (-64))));
9653 emit_insn (gen_blockage ());
9655 /* Save the return address. */
9657 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 56));
9658 set_mem_alias_set (mem, alpha_sr_alias_set);
9659 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA)));
9660 (*imaskP) &= ~(1UL << REG_RA);
9662 /* Save the old frame pointer. */
9664 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 48));
9665 set_mem_alias_set (mem, alpha_sr_alias_set);
9666 FRP (emit_move_insn (mem, hard_frame_pointer_rtx));
9667 (*imaskP) &= ~(1UL << HARD_FRAME_POINTER_REGNUM);
9669 emit_insn (gen_blockage ());
9671 /* Store the SSIB pointer. */
9673 ssib_name = ggc_strdup (unicosmk_ssib_name ());
9674 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 32));
9675 set_mem_alias_set (mem, alpha_sr_alias_set);
9677 FRP (emit_move_insn (gen_rtx_REG (DImode, 5),
9678 gen_rtx_SYMBOL_REF (Pmode, ssib_name)));
9679 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 5)));
9681 /* Save the CIW index. */
9683 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 24));
9684 set_mem_alias_set (mem, alpha_sr_alias_set);
9685 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 25)));
9687 emit_insn (gen_blockage ());
9689 /* Set the new frame pointer. */
9691 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9692 stack_pointer_rtx, GEN_INT (64))));
9695 else
9697 /* Increment the frame pointer register to indicate that we do not
9698 have a frame. */
9700 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9701 hard_frame_pointer_rtx, GEN_INT (1))));
9705 /* Output the static subroutine information block for the current
9706 function. */
9708 static void
9709 unicosmk_output_ssib (FILE *file, const char *fnname)
9711 int len;
9712 int i;
9713 rtx x;
9714 rtx ciw;
9715 struct machine_function *machine = cfun->machine;
9717 ssib_section ();
9718 fprintf (file, "\t.endp\n\n\t.psect\t%s%s,data\n", user_label_prefix,
9719 unicosmk_ssib_name ());
9721 /* Some required stuff and the function name length. */
9723 len = strlen (fnname);
9724 fprintf (file, "\t.quad\t^X20008%2.2X28\n", len);
9726 /* Saved registers
9727 ??? We don't do that yet. */
9729 fputs ("\t.quad\t0\n", file);
9731 /* Function address. */
9733 fputs ("\t.quad\t", file);
9734 assemble_name (file, fnname);
9735 putc ('\n', file);
9737 fputs ("\t.quad\t0\n", file);
9738 fputs ("\t.quad\t0\n", file);
9740 /* Function name.
9741 ??? We do it the same way Cray CC does it but this could be
9742 simplified. */
9744 for( i = 0; i < len; i++ )
9745 fprintf (file, "\t.byte\t%d\n", (int)(fnname[i]));
9746 if( (len % 8) == 0 )
9747 fputs ("\t.quad\t0\n", file);
9748 else
9749 fprintf (file, "\t.bits\t%d : 0\n", (8 - (len % 8))*8);
9751 /* All call information words used in the function. */
9753 for (x = machine->first_ciw; x; x = XEXP (x, 1))
9755 ciw = XEXP (x, 0);
9756 #if HOST_BITS_PER_WIDE_INT == 32
9757 fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_DOUBLE_HEX "\n",
9758 CONST_DOUBLE_HIGH (ciw), CONST_DOUBLE_LOW (ciw));
9759 #else
9760 fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX "\n", INTVAL (ciw));
9761 #endif
9765 /* Add a call information word (CIW) to the list of the current function's
9766 CIWs and return its index.
9768 X is a CONST_INT or CONST_DOUBLE representing the CIW. */
9771 unicosmk_add_call_info_word (rtx x)
9773 rtx node;
9774 struct machine_function *machine = cfun->machine;
9776 node = gen_rtx_EXPR_LIST (VOIDmode, x, NULL_RTX);
9777 if (machine->first_ciw == NULL_RTX)
9778 machine->first_ciw = node;
9779 else
9780 XEXP (machine->last_ciw, 1) = node;
9782 machine->last_ciw = node;
9783 ++machine->ciw_count;
9785 return GEN_INT (machine->ciw_count
9786 + strlen (current_function_name ())/8 + 5);
9789 static char unicosmk_section_buf[100];
9791 char *
9792 unicosmk_text_section (void)
9794 static int count = 0;
9795 sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@text___%d,code",
9796 count++);
9797 return unicosmk_section_buf;
9800 char *
9801 unicosmk_data_section (void)
9803 static int count = 1;
9804 sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@data___%d,data",
9805 count++);
9806 return unicosmk_section_buf;
9809 /* The Cray assembler doesn't accept extern declarations for symbols which
9810 are defined in the same file. We have to keep track of all global
9811 symbols which are referenced and/or defined in a source file and output
9812 extern declarations for those which are referenced but not defined at
9813 the end of file. */
9815 /* List of identifiers for which an extern declaration might have to be
9816 emitted. */
9817 /* FIXME: needs to use GC, so it can be saved and restored for PCH. */
9819 struct unicosmk_extern_list
9821 struct unicosmk_extern_list *next;
9822 const char *name;
9825 static struct unicosmk_extern_list *unicosmk_extern_head = 0;
9827 /* Output extern declarations which are required for every asm file. */
9829 static void
9830 unicosmk_output_default_externs (FILE *file)
9832 static const char *const externs[] =
9833 { "__T3E_MISMATCH" };
9835 int i;
9836 int n;
9838 n = ARRAY_SIZE (externs);
9840 for (i = 0; i < n; i++)
9841 fprintf (file, "\t.extern\t%s\n", externs[i]);
9844 /* Output extern declarations for global symbols which are have been
9845 referenced but not defined. */
9847 static void
9848 unicosmk_output_externs (FILE *file)
9850 struct unicosmk_extern_list *p;
9851 const char *real_name;
9852 int len;
9853 tree name_tree;
9855 len = strlen (user_label_prefix);
9856 for (p = unicosmk_extern_head; p != 0; p = p->next)
9858 /* We have to strip the encoding and possibly remove user_label_prefix
9859 from the identifier in order to handle -fleading-underscore and
9860 explicit asm names correctly (cf. gcc.dg/asm-names-1.c). */
9861 real_name = default_strip_name_encoding (p->name);
9862 if (len && p->name[0] == '*'
9863 && !memcmp (real_name, user_label_prefix, len))
9864 real_name += len;
9866 name_tree = get_identifier (real_name);
9867 if (! TREE_ASM_WRITTEN (name_tree))
9869 TREE_ASM_WRITTEN (name_tree) = 1;
9870 fputs ("\t.extern\t", file);
9871 assemble_name (file, p->name);
9872 putc ('\n', file);
9877 /* Record an extern. */
9879 void
9880 unicosmk_add_extern (const char *name)
9882 struct unicosmk_extern_list *p;
9884 p = (struct unicosmk_extern_list *)
9885 xmalloc (sizeof (struct unicosmk_extern_list));
9886 p->next = unicosmk_extern_head;
9887 p->name = name;
9888 unicosmk_extern_head = p;
9891 /* The Cray assembler generates incorrect code if identifiers which
9892 conflict with register names are used as instruction operands. We have
9893 to replace such identifiers with DEX expressions. */
9895 /* Structure to collect identifiers which have been replaced by DEX
9896 expressions. */
9897 /* FIXME: needs to use GC, so it can be saved and restored for PCH. */
9899 struct unicosmk_dex {
9900 struct unicosmk_dex *next;
9901 const char *name;
9904 /* List of identifiers which have been replaced by DEX expressions. The DEX
9905 number is determined by the position in the list. */
9907 static struct unicosmk_dex *unicosmk_dex_list = NULL;
9909 /* The number of elements in the DEX list. */
9911 static int unicosmk_dex_count = 0;
9913 /* Check if NAME must be replaced by a DEX expression. */
9915 static int
9916 unicosmk_special_name (const char *name)
9918 if (name[0] == '*')
9919 ++name;
9921 if (name[0] == '$')
9922 ++name;
9924 if (name[0] != 'r' && name[0] != 'f' && name[0] != 'R' && name[0] != 'F')
9925 return 0;
9927 switch (name[1])
9929 case '1': case '2':
9930 return (name[2] == '\0' || (ISDIGIT (name[2]) && name[3] == '\0'));
9932 case '3':
9933 return (name[2] == '\0'
9934 || ((name[2] == '0' || name[2] == '1') && name[3] == '\0'));
9936 default:
9937 return (ISDIGIT (name[1]) && name[2] == '\0');
9941 /* Return the DEX number if X must be replaced by a DEX expression and 0
9942 otherwise. */
9944 static int
9945 unicosmk_need_dex (rtx x)
9947 struct unicosmk_dex *dex;
9948 const char *name;
9949 int i;
9951 if (GET_CODE (x) != SYMBOL_REF)
9952 return 0;
9954 name = XSTR (x,0);
9955 if (! unicosmk_special_name (name))
9956 return 0;
9958 i = unicosmk_dex_count;
9959 for (dex = unicosmk_dex_list; dex; dex = dex->next)
9961 if (! strcmp (name, dex->name))
9962 return i;
9963 --i;
9966 dex = (struct unicosmk_dex *) xmalloc (sizeof (struct unicosmk_dex));
9967 dex->name = name;
9968 dex->next = unicosmk_dex_list;
9969 unicosmk_dex_list = dex;
9971 ++unicosmk_dex_count;
9972 return unicosmk_dex_count;
9975 /* Output the DEX definitions for this file. */
9977 static void
9978 unicosmk_output_dex (FILE *file)
9980 struct unicosmk_dex *dex;
9981 int i;
9983 if (unicosmk_dex_list == NULL)
9984 return;
9986 fprintf (file, "\t.dexstart\n");
9988 i = unicosmk_dex_count;
9989 for (dex = unicosmk_dex_list; dex; dex = dex->next)
9991 fprintf (file, "\tDEX (%d) = ", i);
9992 assemble_name (file, dex->name);
9993 putc ('\n', file);
9994 --i;
9997 fprintf (file, "\t.dexend\n");
10000 /* Output text that to appear at the beginning of an assembler file. */
10002 static void
10003 unicosmk_file_start (void)
10005 int i;
10007 fputs ("\t.ident\t", asm_out_file);
10008 unicosmk_output_module_name (asm_out_file);
10009 fputs ("\n\n", asm_out_file);
10011 /* The Unicos/Mk assembler uses different register names. Instead of trying
10012 to support them, we simply use micro definitions. */
10014 /* CAM has different register names: rN for the integer register N and fN
10015 for the floating-point register N. Instead of trying to use these in
10016 alpha.md, we define the symbols $N and $fN to refer to the appropriate
10017 register. */
10019 for (i = 0; i < 32; ++i)
10020 fprintf (asm_out_file, "$%d <- r%d\n", i, i);
10022 for (i = 0; i < 32; ++i)
10023 fprintf (asm_out_file, "$f%d <- f%d\n", i, i);
10025 putc ('\n', asm_out_file);
10027 /* The .align directive fill unused space with zeroes which does not work
10028 in code sections. We define the macro 'gcc@code@align' which uses nops
10029 instead. Note that it assumes that code sections always have the
10030 biggest possible alignment since . refers to the current offset from
10031 the beginning of the section. */
10033 fputs ("\t.macro gcc@code@align n\n", asm_out_file);
10034 fputs ("gcc@n@bytes = 1 << n\n", asm_out_file);
10035 fputs ("gcc@here = . % gcc@n@bytes\n", asm_out_file);
10036 fputs ("\t.if ne, gcc@here, 0\n", asm_out_file);
10037 fputs ("\t.repeat (gcc@n@bytes - gcc@here) / 4\n", asm_out_file);
10038 fputs ("\tbis r31,r31,r31\n", asm_out_file);
10039 fputs ("\t.endr\n", asm_out_file);
10040 fputs ("\t.endif\n", asm_out_file);
10041 fputs ("\t.endm gcc@code@align\n\n", asm_out_file);
10043 /* Output extern declarations which should always be visible. */
10044 unicosmk_output_default_externs (asm_out_file);
10046 /* Open a dummy section. We always need to be inside a section for the
10047 section-switching code to work correctly.
10048 ??? This should be a module id or something like that. I still have to
10049 figure out what the rules for those are. */
10050 fputs ("\n\t.psect\t$SG00000,data\n", asm_out_file);
10053 /* Output text to appear at the end of an assembler file. This includes all
10054 pending extern declarations and DEX expressions. */
10056 static void
10057 unicosmk_file_end (void)
10059 fputs ("\t.endp\n\n", asm_out_file);
10061 /* Output all pending externs. */
10063 unicosmk_output_externs (asm_out_file);
10065 /* Output dex definitions used for functions whose names conflict with
10066 register names. */
10068 unicosmk_output_dex (asm_out_file);
10070 fputs ("\t.end\t", asm_out_file);
10071 unicosmk_output_module_name (asm_out_file);
10072 putc ('\n', asm_out_file);
10075 #else
10077 static void
10078 unicosmk_output_deferred_case_vectors (FILE *file ATTRIBUTE_UNUSED)
10081 static void
10082 unicosmk_gen_dsib (unsigned long *imaskP ATTRIBUTE_UNUSED)
10085 static void
10086 unicosmk_output_ssib (FILE * file ATTRIBUTE_UNUSED,
10087 const char * fnname ATTRIBUTE_UNUSED)
10091 unicosmk_add_call_info_word (rtx x ATTRIBUTE_UNUSED)
10093 return NULL_RTX;
10096 static int
10097 unicosmk_need_dex (rtx x ATTRIBUTE_UNUSED)
10099 return 0;
10102 #endif /* TARGET_ABI_UNICOSMK */
10104 static void
10105 alpha_init_libfuncs (void)
10107 if (TARGET_ABI_UNICOSMK)
10109 /* Prevent gcc from generating calls to __divsi3. */
10110 set_optab_libfunc (sdiv_optab, SImode, 0);
10111 set_optab_libfunc (udiv_optab, SImode, 0);
10113 /* Use the functions provided by the system library
10114 for DImode integer division. */
10115 set_optab_libfunc (sdiv_optab, DImode, "$sldiv");
10116 set_optab_libfunc (udiv_optab, DImode, "$uldiv");
10118 else if (TARGET_ABI_OPEN_VMS)
10120 /* Use the VMS runtime library functions for division and
10121 remainder. */
10122 set_optab_libfunc (sdiv_optab, SImode, "OTS$DIV_I");
10123 set_optab_libfunc (sdiv_optab, DImode, "OTS$DIV_L");
10124 set_optab_libfunc (udiv_optab, SImode, "OTS$DIV_UI");
10125 set_optab_libfunc (udiv_optab, DImode, "OTS$DIV_UL");
10126 set_optab_libfunc (smod_optab, SImode, "OTS$REM_I");
10127 set_optab_libfunc (smod_optab, DImode, "OTS$REM_L");
10128 set_optab_libfunc (umod_optab, SImode, "OTS$REM_UI");
10129 set_optab_libfunc (umod_optab, DImode, "OTS$REM_UL");
10134 /* Initialize the GCC target structure. */
10135 #if TARGET_ABI_OPEN_VMS
10136 # undef TARGET_ATTRIBUTE_TABLE
10137 # define TARGET_ATTRIBUTE_TABLE vms_attribute_table
10138 # undef TARGET_SECTION_TYPE_FLAGS
10139 # define TARGET_SECTION_TYPE_FLAGS vms_section_type_flags
10140 #endif
10142 #undef TARGET_IN_SMALL_DATA_P
10143 #define TARGET_IN_SMALL_DATA_P alpha_in_small_data_p
10145 #if TARGET_ABI_UNICOSMK
10146 # undef TARGET_INSERT_ATTRIBUTES
10147 # define TARGET_INSERT_ATTRIBUTES unicosmk_insert_attributes
10148 # undef TARGET_SECTION_TYPE_FLAGS
10149 # define TARGET_SECTION_TYPE_FLAGS unicosmk_section_type_flags
10150 # undef TARGET_ASM_UNIQUE_SECTION
10151 # define TARGET_ASM_UNIQUE_SECTION unicosmk_unique_section
10152 # undef TARGET_ASM_GLOBALIZE_LABEL
10153 # define TARGET_ASM_GLOBALIZE_LABEL hook_void_FILEptr_constcharptr
10154 #endif
10156 #undef TARGET_ASM_ALIGNED_HI_OP
10157 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
10158 #undef TARGET_ASM_ALIGNED_DI_OP
10159 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
10161 /* Default unaligned ops are provided for ELF systems. To get unaligned
10162 data for non-ELF systems, we have to turn off auto alignment. */
10163 #ifndef OBJECT_FORMAT_ELF
10164 #undef TARGET_ASM_UNALIGNED_HI_OP
10165 #define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.word\t"
10166 #undef TARGET_ASM_UNALIGNED_SI_OP
10167 #define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.long\t"
10168 #undef TARGET_ASM_UNALIGNED_DI_OP
10169 #define TARGET_ASM_UNALIGNED_DI_OP "\t.align 0\n\t.quad\t"
10170 #endif
10172 #ifdef OBJECT_FORMAT_ELF
10173 #undef TARGET_ASM_SELECT_RTX_SECTION
10174 #define TARGET_ASM_SELECT_RTX_SECTION alpha_elf_select_rtx_section
10175 #endif
10177 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
10178 #define TARGET_ASM_FUNCTION_END_PROLOGUE alpha_output_function_end_prologue
10180 #undef TARGET_INIT_LIBFUNCS
10181 #define TARGET_INIT_LIBFUNCS alpha_init_libfuncs
10183 #if TARGET_ABI_UNICOSMK
10184 #undef TARGET_ASM_FILE_START
10185 #define TARGET_ASM_FILE_START unicosmk_file_start
10186 #undef TARGET_ASM_FILE_END
10187 #define TARGET_ASM_FILE_END unicosmk_file_end
10188 #else
10189 #undef TARGET_ASM_FILE_START
10190 #define TARGET_ASM_FILE_START alpha_file_start
10191 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
10192 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
10193 #endif
10195 #undef TARGET_SCHED_ADJUST_COST
10196 #define TARGET_SCHED_ADJUST_COST alpha_adjust_cost
10197 #undef TARGET_SCHED_ISSUE_RATE
10198 #define TARGET_SCHED_ISSUE_RATE alpha_issue_rate
10199 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
10200 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE \
10201 alpha_use_dfa_pipeline_interface
10202 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
10203 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
10204 alpha_multipass_dfa_lookahead
10206 #undef TARGET_HAVE_TLS
10207 #define TARGET_HAVE_TLS HAVE_AS_TLS
10209 #undef TARGET_INIT_BUILTINS
10210 #define TARGET_INIT_BUILTINS alpha_init_builtins
10211 #undef TARGET_EXPAND_BUILTIN
10212 #define TARGET_EXPAND_BUILTIN alpha_expand_builtin
10214 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
10215 #define TARGET_FUNCTION_OK_FOR_SIBCALL alpha_function_ok_for_sibcall
10216 #undef TARGET_CANNOT_COPY_INSN_P
10217 #define TARGET_CANNOT_COPY_INSN_P alpha_cannot_copy_insn_p
10219 #if TARGET_ABI_OSF
10220 #undef TARGET_ASM_OUTPUT_MI_THUNK
10221 #define TARGET_ASM_OUTPUT_MI_THUNK alpha_output_mi_thunk_osf
10222 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
10223 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
10224 #endif
10226 #undef TARGET_RTX_COSTS
10227 #define TARGET_RTX_COSTS alpha_rtx_costs
10228 #undef TARGET_ADDRESS_COST
10229 #define TARGET_ADDRESS_COST hook_int_rtx_0
10231 #undef TARGET_MACHINE_DEPENDENT_REORG
10232 #define TARGET_MACHINE_DEPENDENT_REORG alpha_reorg
10234 #undef TARGET_PROMOTE_FUNCTION_ARGS
10235 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
10236 #undef TARGET_PROMOTE_FUNCTION_RETURN
10237 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
10238 #undef TARGET_PROMOTE_PROTOTYPES
10239 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_false
10240 #undef TARGET_STRUCT_VALUE_RTX
10241 #define TARGET_STRUCT_VALUE_RTX hook_rtx_tree_int_null
10242 #undef TARGET_RETURN_IN_MEMORY
10243 #define TARGET_RETURN_IN_MEMORY alpha_return_in_memory
10244 #undef TARGET_SETUP_INCOMING_VARARGS
10245 #define TARGET_SETUP_INCOMING_VARARGS alpha_setup_incoming_varargs
10246 #undef TARGET_STRICT_ARGUMENT_NAMING
10247 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
10248 #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
10249 #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
10250 #undef TARGET_SPLIT_COMPLEX_ARG
10251 #define TARGET_SPLIT_COMPLEX_ARG alpha_split_complex_arg
10253 #undef TARGET_BUILD_BUILTIN_VA_LIST
10254 #define TARGET_BUILD_BUILTIN_VA_LIST alpha_build_builtin_va_list
10256 struct gcc_target targetm = TARGET_INITIALIZER;
10259 #include "gt-alpha.h"