* target.h (asm_out.file_start, file_start_app_off,
[official-gcc.git] / gcc / config / alpha / alpha.c
blob31f03fc98786b468855b7d386fee66c257b3a5cc
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 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GNU CC.
8 GNU CC 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 GNU CC 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 GNU CC; 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 consistenly 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;
396 char *end;
397 int lat;
399 if (!alpha_mlat_string)
400 alpha_mlat_string = "L1";
402 if (ISDIGIT ((unsigned char)alpha_mlat_string[0])
403 && (lat = strtol (alpha_mlat_string, &end, 10), *end == '\0'))
405 else if ((alpha_mlat_string[0] == 'L' || alpha_mlat_string[0] == 'l')
406 && ISDIGIT ((unsigned char)alpha_mlat_string[1])
407 && alpha_mlat_string[2] == '\0')
409 static int const cache_latency[][4] =
411 { 3, 30, -1 }, /* ev4 -- Bcache is a guess */
412 { 2, 12, 38 }, /* ev5 -- Bcache from PC164 LMbench numbers */
413 { 3, 12, 30 }, /* ev6 -- Bcache from DS20 LMbench. */
416 lat = alpha_mlat_string[1] - '0';
417 if (lat <= 0 || lat > 3 || cache_latency[alpha_cpu][lat-1] == -1)
419 warning ("L%d cache latency unknown for %s",
420 lat, alpha_cpu_name[alpha_cpu]);
421 lat = 3;
423 else
424 lat = cache_latency[alpha_cpu][lat-1];
426 else if (! strcmp (alpha_mlat_string, "main"))
428 /* Most current memories have about 370ns latency. This is
429 a reasonable guess for a fast cpu. */
430 lat = 150;
432 else
434 warning ("bad value `%s' for -mmemory-latency", alpha_mlat_string);
435 lat = 3;
438 alpha_memory_latency = lat;
441 /* Default the definition of "small data" to 8 bytes. */
442 if (!g_switch_set)
443 g_switch_value = 8;
445 /* Infer TARGET_SMALL_DATA from -fpic/-fPIC. */
446 if (flag_pic == 1)
447 target_flags |= MASK_SMALL_DATA;
448 else if (flag_pic == 2)
449 target_flags &= ~MASK_SMALL_DATA;
451 /* Align labels and loops for optimal branching. */
452 /* ??? Kludge these by not doing anything if we don't optimize and also if
453 we are writing ECOFF symbols to work around a bug in DEC's assembler. */
454 if (optimize > 0 && write_symbols != SDB_DEBUG)
456 if (align_loops <= 0)
457 align_loops = 16;
458 if (align_jumps <= 0)
459 align_jumps = 16;
461 if (align_functions <= 0)
462 align_functions = 16;
464 /* Acquire a unique set number for our register saves and restores. */
465 alpha_sr_alias_set = new_alias_set ();
467 /* Register variables and functions with the garbage collector. */
469 /* Set up function hooks. */
470 init_machine_status = alpha_init_machine_status;
472 /* Tell the compiler when we're using VAX floating point. */
473 if (TARGET_FLOAT_VAX)
475 real_format_for_mode[SFmode - QFmode] = &vax_f_format;
476 real_format_for_mode[DFmode - QFmode] = &vax_g_format;
477 real_format_for_mode[TFmode - QFmode] = NULL;
481 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones. */
484 zap_mask (HOST_WIDE_INT value)
486 int i;
488 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
489 i++, value >>= 8)
490 if ((value & 0xff) != 0 && (value & 0xff) != 0xff)
491 return 0;
493 return 1;
496 /* Returns 1 if OP is either the constant zero or a register. If a
497 register, it must be in the proper mode unless MODE is VOIDmode. */
500 reg_or_0_operand (rtx op, enum machine_mode mode)
502 return op == CONST0_RTX (mode) || register_operand (op, mode);
505 /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
506 any register. */
509 reg_or_6bit_operand (rtx op, enum machine_mode mode)
511 return ((GET_CODE (op) == CONST_INT
512 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
513 || register_operand (op, mode));
517 /* Return 1 if OP is an 8-bit constant or any register. */
520 reg_or_8bit_operand (rtx op, enum machine_mode mode)
522 return ((GET_CODE (op) == CONST_INT
523 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
524 || register_operand (op, mode));
527 /* Return 1 if OP is a constant or any register. */
530 reg_or_const_int_operand (rtx op, enum machine_mode mode)
532 return GET_CODE (op) == CONST_INT || register_operand (op, mode);
535 /* Return 1 if OP is an 8-bit constant. */
538 cint8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
540 return ((GET_CODE (op) == CONST_INT
541 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100));
544 /* Return 1 if the operand is a valid second operand to an add insn. */
547 add_operand (rtx op, enum machine_mode mode)
549 if (GET_CODE (op) == CONST_INT)
550 /* Constraints I, J, O and P are covered by K. */
551 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
552 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
554 return register_operand (op, mode);
557 /* Return 1 if the operand is a valid second operand to a sign-extending
558 add insn. */
561 sext_add_operand (rtx op, enum machine_mode mode)
563 if (GET_CODE (op) == CONST_INT)
564 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
565 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'));
567 return reg_not_elim_operand (op, mode);
570 /* Return 1 if OP is the constant 4 or 8. */
573 const48_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
575 return (GET_CODE (op) == CONST_INT
576 && (INTVAL (op) == 4 || INTVAL (op) == 8));
579 /* Return 1 if OP is a valid first operand to an AND insn. */
582 and_operand (rtx op, enum machine_mode mode)
584 if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
585 return (zap_mask (CONST_DOUBLE_LOW (op))
586 && zap_mask (CONST_DOUBLE_HIGH (op)));
588 if (GET_CODE (op) == CONST_INT)
589 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
590 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
591 || zap_mask (INTVAL (op)));
593 return register_operand (op, mode);
596 /* Return 1 if OP is a valid first operand to an IOR or XOR insn. */
599 or_operand (rtx op, enum machine_mode mode)
601 if (GET_CODE (op) == CONST_INT)
602 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
603 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
605 return register_operand (op, mode);
608 /* Return 1 if OP is a constant that is the width, in bits, of an integral
609 mode smaller than DImode. */
612 mode_width_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
614 return (GET_CODE (op) == CONST_INT
615 && (INTVAL (op) == 8 || INTVAL (op) == 16
616 || INTVAL (op) == 32 || INTVAL (op) == 64));
619 /* Return 1 if OP is a constant that is the width of an integral machine mode
620 smaller than an integer. */
623 mode_mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
625 if (GET_CODE (op) == CONST_INT)
627 HOST_WIDE_INT value = INTVAL (op);
629 if (value == 0xff)
630 return 1;
631 if (value == 0xffff)
632 return 1;
633 if (value == 0xffffffff)
634 return 1;
635 if (value == -1)
636 return 1;
638 else if (HOST_BITS_PER_WIDE_INT == 32 && GET_CODE (op) == CONST_DOUBLE)
640 if (CONST_DOUBLE_LOW (op) == 0xffffffff && CONST_DOUBLE_HIGH (op) == 0)
641 return 1;
644 return 0;
647 /* Return 1 if OP is a multiple of 8 less than 64. */
650 mul8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
652 return (GET_CODE (op) == CONST_INT
653 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
654 && (INTVAL (op) & 7) == 0);
657 /* Return 1 if OP is the zero constant for MODE. */
660 const0_operand (rtx op, enum machine_mode mode)
662 return op == CONST0_RTX (mode);
665 /* Return 1 if OP is a hard floating-point register. */
668 hard_fp_register_operand (rtx op, enum machine_mode mode)
670 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
671 return 0;
673 if (GET_CODE (op) == SUBREG)
674 op = SUBREG_REG (op);
675 return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == FLOAT_REGS;
678 /* Return 1 if OP is a hard general register. */
681 hard_int_register_operand (rtx op, enum machine_mode mode)
683 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
684 return 0;
686 if (GET_CODE (op) == SUBREG)
687 op = SUBREG_REG (op);
688 return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS;
691 /* Return 1 if OP is a register or a constant integer. */
695 reg_or_cint_operand (rtx op, enum machine_mode mode)
697 return (GET_CODE (op) == CONST_INT
698 || register_operand (op, mode));
701 /* Return 1 if OP is something that can be reloaded into a register;
702 if it is a MEM, it need not be valid. */
705 some_operand (rtx op, enum machine_mode mode)
707 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
708 return 0;
710 switch (GET_CODE (op))
712 case REG:
713 case MEM:
714 case CONST_INT:
715 case CONST_DOUBLE:
716 case CONST_VECTOR:
717 case LABEL_REF:
718 case SYMBOL_REF:
719 case CONST:
720 case HIGH:
721 return 1;
723 case SUBREG:
724 return some_operand (SUBREG_REG (op), VOIDmode);
726 default:
727 break;
730 return 0;
733 /* Likewise, but don't accept constants. */
736 some_ni_operand (rtx op, enum machine_mode mode)
738 if (GET_MODE (op) != mode && mode != VOIDmode)
739 return 0;
741 if (GET_CODE (op) == SUBREG)
742 op = SUBREG_REG (op);
744 return (GET_CODE (op) == REG || GET_CODE (op) == MEM);
747 /* Return 1 if OP is a valid operand for the source of a move insn. */
750 input_operand (rtx op, enum machine_mode mode)
752 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
753 return 0;
755 if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
756 return 0;
758 switch (GET_CODE (op))
760 case LABEL_REF:
761 case SYMBOL_REF:
762 case CONST:
763 if (TARGET_EXPLICIT_RELOCS)
765 /* We don't split symbolic operands into something unintelligable
766 until after reload, but we do not wish non-small, non-global
767 symbolic operands to be reconstructed from their high/lo_sum
768 form. */
769 return (small_symbolic_operand (op, mode)
770 || global_symbolic_operand (op, mode)
771 || gotdtp_symbolic_operand (op, mode)
772 || gottp_symbolic_operand (op, mode));
775 /* This handles both the Windows/NT and OSF cases. */
776 return mode == ptr_mode || mode == DImode;
778 case HIGH:
779 return (TARGET_EXPLICIT_RELOCS
780 && local_symbolic_operand (XEXP (op, 0), mode));
782 case REG:
783 case ADDRESSOF:
784 return 1;
786 case SUBREG:
787 if (register_operand (op, mode))
788 return 1;
789 /* ... fall through ... */
790 case MEM:
791 return ((TARGET_BWX || (mode != HImode && mode != QImode))
792 && general_operand (op, mode));
794 case CONST_DOUBLE:
795 case CONST_VECTOR:
796 return op == CONST0_RTX (mode);
798 case CONST_INT:
799 return mode == QImode || mode == HImode || add_operand (op, mode);
801 case CONSTANT_P_RTX:
802 return 1;
804 default:
805 break;
808 return 0;
811 /* Return 1 if OP is a SYMBOL_REF for a function known to be in this
812 file, and in the same section as the current function. */
815 samegp_function_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
817 if (GET_CODE (op) != SYMBOL_REF)
818 return false;
820 /* Easy test for recursion. */
821 if (op == XEXP (DECL_RTL (current_function_decl), 0))
822 return true;
824 /* Functions that are not local can be overridden, and thus may
825 not share the same gp. */
826 if (! SYMBOL_REF_LOCAL_P (op))
827 return false;
829 /* If -msmall-data is in effect, assume that there is only one GP
830 for the module, and so any local symbol has this property. We
831 need explicit relocations to be able to enforce this for symbols
832 not defined in this unit of translation, however. */
833 if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
834 return true;
836 /* Functions that are not external are defined in this UoT,
837 and thus must share the same gp. */
838 return ! SYMBOL_REF_EXTERNAL_P (op);
841 /* Return 1 if OP is a SYMBOL_REF for which we can make a call via bsr. */
844 direct_call_operand (rtx op, enum machine_mode mode)
846 tree op_decl, cfun_sec, op_sec;
848 /* Must share the same GP. */
849 if (!samegp_function_operand (op, mode))
850 return false;
852 /* If profiling is implemented via linker tricks, we can't jump
853 to the nogp alternate entry point. Note that current_function_profile
854 would not be correct, since that doesn't indicate if the target
855 function uses profiling. */
856 /* ??? TARGET_PROFILING_NEEDS_GP isn't really the right test,
857 but is approximately correct for the OSF ABIs. Don't know
858 what to do for VMS, NT, or UMK. */
859 if (!TARGET_PROFILING_NEEDS_GP && profile_flag)
860 return false;
862 /* Must be a function. In some cases folks create thunks in static
863 data structures and then make calls to them. If we allow the
864 direct call, we'll get an error from the linker about !samegp reloc
865 against a symbol without a .prologue directive. */
866 if (!SYMBOL_REF_FUNCTION_P (op))
867 return false;
869 /* Must be "near" so that the branch is assumed to reach. With
870 -msmall-text, this is assumed true of all local symbols. Since
871 we've already checked samegp, locality is already assured. */
872 if (TARGET_SMALL_TEXT)
873 return true;
875 /* Otherwise, a decl is "near" if it is defined in the same section. */
876 if (flag_function_sections)
877 return false;
879 op_decl = SYMBOL_REF_DECL (op);
880 if (DECL_ONE_ONLY (current_function_decl)
881 || (op_decl && DECL_ONE_ONLY (op_decl)))
882 return false;
884 cfun_sec = DECL_SECTION_NAME (current_function_decl);
885 op_sec = op_decl ? DECL_SECTION_NAME (op_decl) : NULL;
886 return ((!cfun_sec && !op_sec)
887 || (cfun_sec && op_sec
888 && strcmp (TREE_STRING_POINTER (cfun_sec),
889 TREE_STRING_POINTER (op_sec)) == 0));
892 /* Return true if OP is a LABEL_REF, or SYMBOL_REF or CONST referencing
893 a (non-tls) variable known to be defined in this file. */
896 local_symbolic_operand (rtx op, enum machine_mode mode)
898 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
899 return 0;
901 if (GET_CODE (op) == LABEL_REF)
902 return 1;
904 if (GET_CODE (op) == CONST
905 && GET_CODE (XEXP (op, 0)) == PLUS
906 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
907 op = XEXP (XEXP (op, 0), 0);
909 if (GET_CODE (op) != SYMBOL_REF)
910 return 0;
912 return SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
915 /* Return true if OP is a SYMBOL_REF or CONST referencing a variable
916 known to be defined in this file in the small data area. */
919 small_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
921 if (! TARGET_SMALL_DATA)
922 return 0;
924 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
925 return 0;
927 if (GET_CODE (op) == CONST
928 && GET_CODE (XEXP (op, 0)) == PLUS
929 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
930 op = XEXP (XEXP (op, 0), 0);
932 if (GET_CODE (op) != SYMBOL_REF)
933 return 0;
935 /* ??? There's no encode_section_info equivalent for the rtl
936 constant pool, so SYMBOL_FLAG_SMALL never gets set. */
937 if (CONSTANT_POOL_ADDRESS_P (op))
938 return GET_MODE_SIZE (get_pool_mode (op)) <= g_switch_value;
940 return (SYMBOL_REF_LOCAL_P (op)
941 && SYMBOL_REF_SMALL_P (op)
942 && SYMBOL_REF_TLS_MODEL (op) == 0);
945 /* Return true if OP is a SYMBOL_REF or CONST referencing a variable
946 not known (or known not) to be defined in this file. */
949 global_symbolic_operand (rtx op, enum machine_mode mode)
951 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
952 return 0;
954 if (GET_CODE (op) == CONST
955 && GET_CODE (XEXP (op, 0)) == PLUS
956 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
957 op = XEXP (XEXP (op, 0), 0);
959 if (GET_CODE (op) != SYMBOL_REF)
960 return 0;
962 return !SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
965 /* Return 1 if OP is a valid operand for the MEM of a CALL insn. */
968 call_operand (rtx op, enum machine_mode mode)
970 if (mode != Pmode)
971 return 0;
973 if (GET_CODE (op) == REG)
975 if (TARGET_ABI_OSF)
977 /* Disallow virtual registers to cope with pathalogical test cases
978 such as compile/930117-1.c in which the virtual reg decomposes
979 to the frame pointer. Which is a hard reg that is not $27. */
980 return (REGNO (op) == 27 || REGNO (op) > LAST_VIRTUAL_REGISTER);
982 else
983 return 1;
985 if (TARGET_ABI_UNICOSMK)
986 return 0;
987 if (GET_CODE (op) == SYMBOL_REF)
988 return 1;
990 return 0;
993 /* Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
994 possibly with an offset. */
997 symbolic_operand (rtx op, enum machine_mode mode)
999 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1000 return 0;
1001 if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
1002 return 1;
1003 if (GET_CODE (op) == CONST
1004 && GET_CODE (XEXP (op,0)) == PLUS
1005 && GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF
1006 && GET_CODE (XEXP (XEXP (op,0), 1)) == CONST_INT)
1007 return 1;
1008 return 0;
1011 /* Return true if OP is valid for a particular TLS relocation. */
1013 static int
1014 tls_symbolic_operand_1 (rtx op, enum machine_mode mode, int size, int unspec)
1016 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1017 return 0;
1019 if (GET_CODE (op) != CONST)
1020 return 0;
1021 op = XEXP (op, 0);
1023 if (GET_CODE (op) != UNSPEC || XINT (op, 1) != unspec)
1024 return 0;
1025 op = XVECEXP (op, 0, 0);
1027 if (GET_CODE (op) != SYMBOL_REF)
1028 return 0;
1030 if (SYMBOL_REF_LOCAL_P (op))
1032 if (alpha_tls_size > size)
1033 return 0;
1035 else
1037 if (size != 64)
1038 return 0;
1041 switch (SYMBOL_REF_TLS_MODEL (op))
1043 case TLS_MODEL_LOCAL_DYNAMIC:
1044 return unspec == UNSPEC_DTPREL;
1045 case TLS_MODEL_INITIAL_EXEC:
1046 return unspec == UNSPEC_TPREL && size == 64;
1047 case TLS_MODEL_LOCAL_EXEC:
1048 return unspec == UNSPEC_TPREL;
1049 default:
1050 abort ();
1054 /* Return true if OP is valid for 16-bit DTP relative relocations. */
1057 dtp16_symbolic_operand (rtx op, enum machine_mode mode)
1059 return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_DTPREL);
1062 /* Return true if OP is valid for 32-bit DTP relative relocations. */
1065 dtp32_symbolic_operand (rtx op, enum machine_mode mode)
1067 return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_DTPREL);
1070 /* Return true if OP is valid for 64-bit DTP relative relocations. */
1073 gotdtp_symbolic_operand (rtx op, enum machine_mode mode)
1075 return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_DTPREL);
1078 /* Return true if OP is valid for 16-bit TP relative relocations. */
1081 tp16_symbolic_operand (rtx op, enum machine_mode mode)
1083 return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_TPREL);
1086 /* Return true if OP is valid for 32-bit TP relative relocations. */
1089 tp32_symbolic_operand (rtx op, enum machine_mode mode)
1091 return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_TPREL);
1094 /* Return true if OP is valid for 64-bit TP relative relocations. */
1097 gottp_symbolic_operand (rtx op, enum machine_mode mode)
1099 return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_TPREL);
1102 /* Return 1 if OP is a valid Alpha comparison operator. Here we know which
1103 comparisons are valid in which insn. */
1106 alpha_comparison_operator (rtx op, enum machine_mode mode)
1108 enum rtx_code code = GET_CODE (op);
1110 if (mode != GET_MODE (op) && mode != VOIDmode)
1111 return 0;
1113 return (code == EQ || code == LE || code == LT
1114 || code == LEU || code == LTU);
1117 /* Return 1 if OP is a valid Alpha comparison operator against zero.
1118 Here we know which comparisons are valid in which insn. */
1121 alpha_zero_comparison_operator (rtx op, enum machine_mode mode)
1123 enum rtx_code code = GET_CODE (op);
1125 if (mode != GET_MODE (op) && mode != VOIDmode)
1126 return 0;
1128 return (code == EQ || code == NE || code == LE || code == LT
1129 || code == LEU || code == LTU);
1132 /* Return 1 if OP is a valid Alpha swapped comparison operator. */
1135 alpha_swapped_comparison_operator (rtx op, enum machine_mode mode)
1137 enum rtx_code code = GET_CODE (op);
1139 if ((mode != GET_MODE (op) && mode != VOIDmode)
1140 || GET_RTX_CLASS (code) != '<')
1141 return 0;
1143 code = swap_condition (code);
1144 return (code == EQ || code == LE || code == LT
1145 || code == LEU || code == LTU);
1148 /* Return 1 if OP is a signed comparison operation. */
1151 signed_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1153 enum rtx_code code = GET_CODE (op);
1155 if (mode != GET_MODE (op) && mode != VOIDmode)
1156 return 0;
1158 return (code == EQ || code == NE
1159 || code == LE || code == LT
1160 || code == GE || code == GT);
1163 /* Return 1 if OP is a valid Alpha floating point comparison operator.
1164 Here we know which comparisons are valid in which insn. */
1167 alpha_fp_comparison_operator (rtx op, enum machine_mode mode)
1169 enum rtx_code code = GET_CODE (op);
1171 if (mode != GET_MODE (op) && mode != VOIDmode)
1172 return 0;
1174 return (code == EQ || code == LE || code == LT || code == UNORDERED);
1177 /* Return 1 if this is a divide or modulus operator. */
1180 divmod_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1182 switch (GET_CODE (op))
1184 case DIV: case MOD: case UDIV: case UMOD:
1185 return 1;
1187 default:
1188 break;
1191 return 0;
1194 /* Return 1 if this memory address is a known aligned register plus
1195 a constant. It must be a valid address. This means that we can do
1196 this as an aligned reference plus some offset.
1198 Take into account what reload will do. */
1201 aligned_memory_operand (rtx op, enum machine_mode mode)
1203 rtx base;
1205 if (reload_in_progress)
1207 rtx tmp = op;
1208 if (GET_CODE (tmp) == SUBREG)
1209 tmp = SUBREG_REG (tmp);
1210 if (GET_CODE (tmp) == REG
1211 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1213 op = reg_equiv_memory_loc[REGNO (tmp)];
1214 if (op == 0)
1215 return 0;
1219 if (GET_CODE (op) != MEM
1220 || GET_MODE (op) != mode)
1221 return 0;
1222 op = XEXP (op, 0);
1224 /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
1225 sorts of constructs. Dig for the real base register. */
1226 if (reload_in_progress
1227 && GET_CODE (op) == PLUS
1228 && GET_CODE (XEXP (op, 0)) == PLUS)
1229 base = XEXP (XEXP (op, 0), 0);
1230 else
1232 if (! memory_address_p (mode, op))
1233 return 0;
1234 base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1237 return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) >= 32);
1240 /* Similar, but return 1 if OP is a MEM which is not alignable. */
1243 unaligned_memory_operand (rtx op, enum machine_mode mode)
1245 rtx base;
1247 if (reload_in_progress)
1249 rtx tmp = op;
1250 if (GET_CODE (tmp) == SUBREG)
1251 tmp = SUBREG_REG (tmp);
1252 if (GET_CODE (tmp) == REG
1253 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1255 op = reg_equiv_memory_loc[REGNO (tmp)];
1256 if (op == 0)
1257 return 0;
1261 if (GET_CODE (op) != MEM
1262 || GET_MODE (op) != mode)
1263 return 0;
1264 op = XEXP (op, 0);
1266 /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
1267 sorts of constructs. Dig for the real base register. */
1268 if (reload_in_progress
1269 && GET_CODE (op) == PLUS
1270 && GET_CODE (XEXP (op, 0)) == PLUS)
1271 base = XEXP (XEXP (op, 0), 0);
1272 else
1274 if (! memory_address_p (mode, op))
1275 return 0;
1276 base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1279 return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) < 32);
1282 /* Return 1 if OP is either a register or an unaligned memory location. */
1285 reg_or_unaligned_mem_operand (rtx op, enum machine_mode mode)
1287 return register_operand (op, mode) || unaligned_memory_operand (op, mode);
1290 /* Return 1 if OP is any memory location. During reload a pseudo matches. */
1293 any_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1295 return (GET_CODE (op) == MEM
1296 || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
1297 || (reload_in_progress && GET_CODE (op) == REG
1298 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1299 || (reload_in_progress && GET_CODE (op) == SUBREG
1300 && GET_CODE (SUBREG_REG (op)) == REG
1301 && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER));
1304 /* Returns 1 if OP is not an eliminable register.
1306 This exists to cure a pathological abort in the s8addq (et al) patterns,
1308 long foo () { long t; bar(); return (long) &t * 26107; }
1310 which run afoul of a hack in reload to cure a (presumably) similar
1311 problem with lea-type instructions on other targets. But there is
1312 one of us and many of them, so work around the problem by selectively
1313 preventing combine from making the optimization. */
1316 reg_not_elim_operand (rtx op, enum machine_mode mode)
1318 rtx inner = op;
1319 if (GET_CODE (op) == SUBREG)
1320 inner = SUBREG_REG (op);
1321 if (inner == frame_pointer_rtx || inner == arg_pointer_rtx)
1322 return 0;
1324 return register_operand (op, mode);
1327 /* Return 1 is OP is a memory location that is not a reference (using
1328 an AND) to an unaligned location. Take into account what reload
1329 will do. */
1332 normal_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1334 if (reload_in_progress)
1336 rtx tmp = op;
1337 if (GET_CODE (tmp) == SUBREG)
1338 tmp = SUBREG_REG (tmp);
1339 if (GET_CODE (tmp) == REG
1340 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1342 op = reg_equiv_memory_loc[REGNO (tmp)];
1344 /* This may not have been assigned an equivalent address if it will
1345 be eliminated. In that case, it doesn't matter what we do. */
1346 if (op == 0)
1347 return 1;
1351 return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) != AND;
1354 /* Accept a register, but not a subreg of any kind. This allows us to
1355 avoid pathological cases in reload wrt data movement common in
1356 int->fp conversion. */
1359 reg_no_subreg_operand (rtx op, enum machine_mode mode)
1361 if (GET_CODE (op) != REG)
1362 return 0;
1363 return register_operand (op, mode);
1366 /* Recognize an addition operation that includes a constant. Used to
1367 convince reload to canonize (plus (plus reg c1) c2) during register
1368 elimination. */
1371 addition_operation (rtx op, enum machine_mode mode)
1373 if (GET_MODE (op) != mode && mode != VOIDmode)
1374 return 0;
1375 if (GET_CODE (op) == PLUS
1376 && register_operand (XEXP (op, 0), mode)
1377 && GET_CODE (XEXP (op, 1)) == CONST_INT
1378 && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (op, 1)), 'K'))
1379 return 1;
1380 return 0;
1383 /* Implements CONST_OK_FOR_LETTER_P. Return true if the value matches
1384 the range defined for C in [I-P]. */
1386 bool
1387 alpha_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
1389 switch (c)
1391 case 'I':
1392 /* An unsigned 8 bit constant. */
1393 return (unsigned HOST_WIDE_INT) value < 0x100;
1394 case 'J':
1395 /* The constant zero. */
1396 return value == 0;
1397 case 'K':
1398 /* A signed 16 bit constant. */
1399 return (unsigned HOST_WIDE_INT) (value + 0x8000) < 0x10000;
1400 case 'L':
1401 /* A shifted signed 16 bit constant appropriate for LDAH. */
1402 return ((value & 0xffff) == 0
1403 && ((value) >> 31 == -1 || value >> 31 == 0));
1404 case 'M':
1405 /* A constant that can be AND'ed with using a ZAP insn. */
1406 return zap_mask (value);
1407 case 'N':
1408 /* A complemented unsigned 8 bit constant. */
1409 return (unsigned HOST_WIDE_INT) (~ value) < 0x100;
1410 case 'O':
1411 /* A negated unsigned 8 bit constant. */
1412 return (unsigned HOST_WIDE_INT) (- value) < 0x100;
1413 case 'P':
1414 /* The constant 1, 2 or 3. */
1415 return value == 1 || value == 2 || value == 3;
1417 default:
1418 return false;
1422 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE
1423 matches for C in [GH]. */
1425 bool
1426 alpha_const_double_ok_for_letter_p (rtx value, int c)
1428 switch (c)
1430 case 'G':
1431 /* The floating point zero constant. */
1432 return (GET_MODE_CLASS (GET_MODE (value)) == MODE_FLOAT
1433 && value == CONST0_RTX (GET_MODE (value)));
1435 case 'H':
1436 /* A valid operand of a ZAP insn. */
1437 return (GET_MODE (value) == VOIDmode
1438 && zap_mask (CONST_DOUBLE_LOW (value))
1439 && zap_mask (CONST_DOUBLE_HIGH (value)));
1441 default:
1442 return false;
1446 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE
1447 matches for C. */
1449 bool
1450 alpha_extra_constraint (rtx value, int c)
1452 switch (c)
1454 case 'Q':
1455 return normal_memory_operand (value, VOIDmode);
1456 case 'R':
1457 return direct_call_operand (value, Pmode);
1458 case 'S':
1459 return (GET_CODE (value) == CONST_INT
1460 && (unsigned HOST_WIDE_INT) INTVAL (value) < 64);
1461 case 'T':
1462 return GET_CODE (value) == HIGH;
1463 case 'U':
1464 return TARGET_ABI_UNICOSMK && symbolic_operand (value, VOIDmode);
1465 case 'W':
1466 return (GET_CODE (value) == CONST_VECTOR
1467 && value == CONST0_RTX (GET_MODE (value)));
1468 default:
1469 return false;
1473 /* Return 1 if this function can directly return via $26. */
1476 direct_return (void)
1478 return (! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK
1479 && reload_completed
1480 && alpha_sa_size () == 0
1481 && get_frame_size () == 0
1482 && current_function_outgoing_args_size == 0
1483 && current_function_pretend_args_size == 0);
1486 /* Return the ADDR_VEC associated with a tablejump insn. */
1489 alpha_tablejump_addr_vec (rtx insn)
1491 rtx tmp;
1493 tmp = JUMP_LABEL (insn);
1494 if (!tmp)
1495 return NULL_RTX;
1496 tmp = NEXT_INSN (tmp);
1497 if (!tmp)
1498 return NULL_RTX;
1499 if (GET_CODE (tmp) == JUMP_INSN
1500 && GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC)
1501 return PATTERN (tmp);
1502 return NULL_RTX;
1505 /* Return the label of the predicted edge, or CONST0_RTX if we don't know. */
1508 alpha_tablejump_best_label (rtx insn)
1510 rtx jump_table = alpha_tablejump_addr_vec (insn);
1511 rtx best_label = NULL_RTX;
1513 /* ??? Once the CFG doesn't keep getting completely rebuilt, look
1514 there for edge frequency counts from profile data. */
1516 if (jump_table)
1518 int n_labels = XVECLEN (jump_table, 1);
1519 int best_count = -1;
1520 int i, j;
1522 for (i = 0; i < n_labels; i++)
1524 int count = 1;
1526 for (j = i + 1; j < n_labels; j++)
1527 if (XEXP (XVECEXP (jump_table, 1, i), 0)
1528 == XEXP (XVECEXP (jump_table, 1, j), 0))
1529 count++;
1531 if (count > best_count)
1532 best_count = count, best_label = XVECEXP (jump_table, 1, i);
1536 return best_label ? best_label : const0_rtx;
1539 /* Return the TLS model to use for SYMBOL. */
1541 static enum tls_model
1542 tls_symbolic_operand_type (rtx symbol)
1544 enum tls_model model;
1546 if (GET_CODE (symbol) != SYMBOL_REF)
1547 return 0;
1548 model = SYMBOL_REF_TLS_MODEL (symbol);
1550 /* Local-exec with a 64-bit size is the same code as initial-exec. */
1551 if (model == TLS_MODEL_LOCAL_EXEC && alpha_tls_size == 64)
1552 model = TLS_MODEL_INITIAL_EXEC;
1554 return model;
1557 /* Return true if the function DECL will share the same GP as any
1558 function in the current unit of translation. */
1560 static bool
1561 decl_has_samegp (tree decl)
1563 /* Functions that are not local can be overridden, and thus may
1564 not share the same gp. */
1565 if (!(*targetm.binds_local_p) (decl))
1566 return false;
1568 /* If -msmall-data is in effect, assume that there is only one GP
1569 for the module, and so any local symbol has this property. We
1570 need explicit relocations to be able to enforce this for symbols
1571 not defined in this unit of translation, however. */
1572 if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
1573 return true;
1575 /* Functions that are not external are defined in this UoT. */
1576 /* ??? Irritatingly, static functions not yet emitted are still
1577 marked "external". Apply this to non-static functions only. */
1578 return !TREE_PUBLIC (decl) || !DECL_EXTERNAL (decl);
1581 /* Return true if EXP should be placed in the small data section. */
1583 static bool
1584 alpha_in_small_data_p (tree exp)
1586 /* We want to merge strings, so we never consider them small data. */
1587 if (TREE_CODE (exp) == STRING_CST)
1588 return false;
1590 if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
1592 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
1593 if (strcmp (section, ".sdata") == 0
1594 || strcmp (section, ".sbss") == 0)
1595 return true;
1597 else
1599 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
1601 /* If this is an incomplete type with size 0, then we can't put it
1602 in sdata because it might be too big when completed. */
1603 if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value)
1604 return true;
1607 return false;
1610 #if TARGET_ABI_OPEN_VMS
1611 static bool
1612 alpha_linkage_symbol_p (const char *symname)
1614 int symlen = strlen (symname);
1616 if (symlen > 4)
1617 return strcmp (&symname [symlen - 4], "..lk") == 0;
1619 return false;
1622 #define LINKAGE_SYMBOL_REF_P(X) \
1623 ((GET_CODE (X) == SYMBOL_REF \
1624 && alpha_linkage_symbol_p (XSTR (X, 0))) \
1625 || (GET_CODE (X) == CONST \
1626 && GET_CODE (XEXP (X, 0)) == PLUS \
1627 && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF \
1628 && alpha_linkage_symbol_p (XSTR (XEXP (XEXP (X, 0), 0), 0))))
1629 #endif
1631 /* legitimate_address_p recognizes an RTL expression that is a valid
1632 memory address for an instruction. The MODE argument is the
1633 machine mode for the MEM expression that wants to use this address.
1635 For Alpha, we have either a constant address or the sum of a
1636 register and a constant address, or just a register. For DImode,
1637 any of those forms can be surrounded with an AND that clear the
1638 low-order three bits; this is an "unaligned" access. */
1640 bool
1641 alpha_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1643 /* If this is an ldq_u type address, discard the outer AND. */
1644 if (mode == DImode
1645 && GET_CODE (x) == AND
1646 && GET_CODE (XEXP (x, 1)) == CONST_INT
1647 && INTVAL (XEXP (x, 1)) == -8)
1648 x = XEXP (x, 0);
1650 /* Discard non-paradoxical subregs. */
1651 if (GET_CODE (x) == SUBREG
1652 && (GET_MODE_SIZE (GET_MODE (x))
1653 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1654 x = SUBREG_REG (x);
1656 /* Unadorned general registers are valid. */
1657 if (REG_P (x)
1658 && (strict
1659 ? STRICT_REG_OK_FOR_BASE_P (x)
1660 : NONSTRICT_REG_OK_FOR_BASE_P (x)))
1661 return true;
1663 /* Constant addresses (i.e. +/- 32k) are valid. */
1664 if (CONSTANT_ADDRESS_P (x))
1665 return true;
1667 #if TARGET_ABI_OPEN_VMS
1668 if (LINKAGE_SYMBOL_REF_P (x))
1669 return true;
1670 #endif
1672 /* Register plus a small constant offset is valid. */
1673 if (GET_CODE (x) == PLUS)
1675 rtx ofs = XEXP (x, 1);
1676 x = XEXP (x, 0);
1678 /* Discard non-paradoxical subregs. */
1679 if (GET_CODE (x) == SUBREG
1680 && (GET_MODE_SIZE (GET_MODE (x))
1681 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1682 x = SUBREG_REG (x);
1684 if (REG_P (x))
1686 if (! strict
1687 && NONSTRICT_REG_OK_FP_BASE_P (x)
1688 && GET_CODE (ofs) == CONST_INT)
1689 return true;
1690 if ((strict
1691 ? STRICT_REG_OK_FOR_BASE_P (x)
1692 : NONSTRICT_REG_OK_FOR_BASE_P (x))
1693 && CONSTANT_ADDRESS_P (ofs))
1694 return true;
1696 else if (GET_CODE (x) == ADDRESSOF
1697 && GET_CODE (ofs) == CONST_INT)
1698 return true;
1701 /* If we're managing explicit relocations, LO_SUM is valid, as
1702 are small data symbols. */
1703 else if (TARGET_EXPLICIT_RELOCS)
1705 if (small_symbolic_operand (x, Pmode))
1706 return true;
1708 if (GET_CODE (x) == LO_SUM)
1710 rtx ofs = XEXP (x, 1);
1711 x = XEXP (x, 0);
1713 /* Discard non-paradoxical subregs. */
1714 if (GET_CODE (x) == SUBREG
1715 && (GET_MODE_SIZE (GET_MODE (x))
1716 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1717 x = SUBREG_REG (x);
1719 /* Must have a valid base register. */
1720 if (! (REG_P (x)
1721 && (strict
1722 ? STRICT_REG_OK_FOR_BASE_P (x)
1723 : NONSTRICT_REG_OK_FOR_BASE_P (x))))
1724 return false;
1726 /* The symbol must be local. */
1727 if (local_symbolic_operand (ofs, Pmode)
1728 || dtp32_symbolic_operand (ofs, Pmode)
1729 || tp32_symbolic_operand (ofs, Pmode))
1730 return true;
1734 return false;
1737 /* Build the SYMBOL_REF for __tls_get_addr. */
1739 static GTY(()) rtx tls_get_addr_libfunc;
1741 static rtx
1742 get_tls_get_addr (void)
1744 if (!tls_get_addr_libfunc)
1745 tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr");
1746 return tls_get_addr_libfunc;
1749 /* Try machine-dependent ways of modifying an illegitimate address
1750 to be legitimate. If we find one, return the new, valid address. */
1753 alpha_legitimize_address (rtx x, rtx scratch,
1754 enum machine_mode mode ATTRIBUTE_UNUSED)
1756 HOST_WIDE_INT addend;
1758 /* If the address is (plus reg const_int) and the CONST_INT is not a
1759 valid offset, compute the high part of the constant and add it to
1760 the register. Then our address is (plus temp low-part-const). */
1761 if (GET_CODE (x) == PLUS
1762 && GET_CODE (XEXP (x, 0)) == REG
1763 && GET_CODE (XEXP (x, 1)) == CONST_INT
1764 && ! CONSTANT_ADDRESS_P (XEXP (x, 1)))
1766 addend = INTVAL (XEXP (x, 1));
1767 x = XEXP (x, 0);
1768 goto split_addend;
1771 /* If the address is (const (plus FOO const_int)), find the low-order
1772 part of the CONST_INT. Then load FOO plus any high-order part of the
1773 CONST_INT into a register. Our address is (plus reg low-part-const).
1774 This is done to reduce the number of GOT entries. */
1775 if (!no_new_pseudos
1776 && GET_CODE (x) == CONST
1777 && GET_CODE (XEXP (x, 0)) == PLUS
1778 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1780 addend = INTVAL (XEXP (XEXP (x, 0), 1));
1781 x = force_reg (Pmode, XEXP (XEXP (x, 0), 0));
1782 goto split_addend;
1785 /* If we have a (plus reg const), emit the load as in (2), then add
1786 the two registers, and finally generate (plus reg low-part-const) as
1787 our address. */
1788 if (!no_new_pseudos
1789 && GET_CODE (x) == PLUS
1790 && GET_CODE (XEXP (x, 0)) == REG
1791 && GET_CODE (XEXP (x, 1)) == CONST
1792 && GET_CODE (XEXP (XEXP (x, 1), 0)) == PLUS
1793 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == CONST_INT)
1795 addend = INTVAL (XEXP (XEXP (XEXP (x, 1), 0), 1));
1796 x = expand_simple_binop (Pmode, PLUS, XEXP (x, 0),
1797 XEXP (XEXP (XEXP (x, 1), 0), 0),
1798 NULL_RTX, 1, OPTAB_LIB_WIDEN);
1799 goto split_addend;
1802 /* If this is a local symbol, split the address into HIGH/LO_SUM parts. */
1803 if (TARGET_EXPLICIT_RELOCS && symbolic_operand (x, Pmode))
1805 rtx r0, r16, eqv, tga, tp, insn, dest, seq;
1807 switch (tls_symbolic_operand_type (x))
1809 case TLS_MODEL_GLOBAL_DYNAMIC:
1810 start_sequence ();
1812 r0 = gen_rtx_REG (Pmode, 0);
1813 r16 = gen_rtx_REG (Pmode, 16);
1814 tga = get_tls_get_addr ();
1815 dest = gen_reg_rtx (Pmode);
1816 seq = GEN_INT (alpha_next_sequence_number++);
1818 emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq));
1819 insn = gen_call_value_osf_tlsgd (r0, tga, seq);
1820 insn = emit_call_insn (insn);
1821 CONST_OR_PURE_CALL_P (insn) = 1;
1822 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16);
1824 insn = get_insns ();
1825 end_sequence ();
1827 emit_libcall_block (insn, dest, r0, x);
1828 return dest;
1830 case TLS_MODEL_LOCAL_DYNAMIC:
1831 start_sequence ();
1833 r0 = gen_rtx_REG (Pmode, 0);
1834 r16 = gen_rtx_REG (Pmode, 16);
1835 tga = get_tls_get_addr ();
1836 scratch = gen_reg_rtx (Pmode);
1837 seq = GEN_INT (alpha_next_sequence_number++);
1839 emit_insn (gen_movdi_er_tlsldm (r16, pic_offset_table_rtx, seq));
1840 insn = gen_call_value_osf_tlsldm (r0, tga, seq);
1841 insn = emit_call_insn (insn);
1842 CONST_OR_PURE_CALL_P (insn) = 1;
1843 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16);
1845 insn = get_insns ();
1846 end_sequence ();
1848 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
1849 UNSPEC_TLSLDM_CALL);
1850 emit_libcall_block (insn, scratch, r0, eqv);
1852 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPREL);
1853 eqv = gen_rtx_CONST (Pmode, eqv);
1855 if (alpha_tls_size == 64)
1857 dest = gen_reg_rtx (Pmode);
1858 emit_insn (gen_rtx_SET (VOIDmode, dest, eqv));
1859 emit_insn (gen_adddi3 (dest, dest, scratch));
1860 return dest;
1862 if (alpha_tls_size == 32)
1864 insn = gen_rtx_HIGH (Pmode, eqv);
1865 insn = gen_rtx_PLUS (Pmode, scratch, insn);
1866 scratch = gen_reg_rtx (Pmode);
1867 emit_insn (gen_rtx_SET (VOIDmode, scratch, insn));
1869 return gen_rtx_LO_SUM (Pmode, scratch, eqv);
1871 case TLS_MODEL_INITIAL_EXEC:
1872 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_TPREL);
1873 eqv = gen_rtx_CONST (Pmode, eqv);
1874 tp = gen_reg_rtx (Pmode);
1875 scratch = gen_reg_rtx (Pmode);
1876 dest = gen_reg_rtx (Pmode);
1878 emit_insn (gen_load_tp (tp));
1879 emit_insn (gen_rtx_SET (VOIDmode, scratch, eqv));
1880 emit_insn (gen_adddi3 (dest, tp, scratch));
1881 return dest;
1883 case TLS_MODEL_LOCAL_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);
1888 emit_insn (gen_load_tp (tp));
1889 if (alpha_tls_size == 32)
1891 insn = gen_rtx_HIGH (Pmode, eqv);
1892 insn = gen_rtx_PLUS (Pmode, tp, insn);
1893 tp = gen_reg_rtx (Pmode);
1894 emit_insn (gen_rtx_SET (VOIDmode, tp, insn));
1896 return gen_rtx_LO_SUM (Pmode, tp, eqv);
1899 if (local_symbolic_operand (x, Pmode))
1901 if (small_symbolic_operand (x, Pmode))
1902 return x;
1903 else
1905 if (!no_new_pseudos)
1906 scratch = gen_reg_rtx (Pmode);
1907 emit_insn (gen_rtx_SET (VOIDmode, scratch,
1908 gen_rtx_HIGH (Pmode, x)));
1909 return gen_rtx_LO_SUM (Pmode, scratch, x);
1914 return NULL;
1916 split_addend:
1918 HOST_WIDE_INT low, high;
1920 low = ((addend & 0xffff) ^ 0x8000) - 0x8000;
1921 addend -= low;
1922 high = ((addend & 0xffffffff) ^ 0x80000000) - 0x80000000;
1923 addend -= high;
1925 if (addend)
1926 x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (addend),
1927 (no_new_pseudos ? scratch : NULL_RTX),
1928 1, OPTAB_LIB_WIDEN);
1929 if (high)
1930 x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (high),
1931 (no_new_pseudos ? scratch : NULL_RTX),
1932 1, OPTAB_LIB_WIDEN);
1934 return plus_constant (x, low);
1938 /* We do not allow indirect calls to be optimized into sibling calls, nor
1939 can we allow a call to a function with a different GP to be optimized
1940 into a sibcall. */
1942 static bool
1943 alpha_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
1945 /* Can't do indirect tail calls, since we don't know if the target
1946 uses the same GP. */
1947 if (!decl)
1948 return false;
1950 /* Otherwise, we can make a tail call if the target function shares
1951 the same GP. */
1952 return decl_has_samegp (decl);
1955 /* For TARGET_EXPLICIT_RELOCS, we don't obfuscate a SYMBOL_REF to a
1956 small symbolic operand until after reload. At which point we need
1957 to replace (mem (symbol_ref)) with (mem (lo_sum $29 symbol_ref))
1958 so that sched2 has the proper dependency information. */
1960 static int
1961 some_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
1963 rtx x = *px;
1965 /* Don't re-split. */
1966 if (GET_CODE (x) == LO_SUM)
1967 return -1;
1969 return small_symbolic_operand (x, Pmode) != 0;
1973 some_small_symbolic_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
1975 return for_each_rtx (&x, some_small_symbolic_operand_1, NULL);
1978 static int
1979 split_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
1981 rtx x = *px;
1983 /* Don't re-split. */
1984 if (GET_CODE (x) == LO_SUM)
1985 return -1;
1987 if (small_symbolic_operand (x, Pmode))
1989 x = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, x);
1990 *px = x;
1991 return -1;
1994 return 0;
1998 split_small_symbolic_operand (rtx x)
2000 x = copy_insn (x);
2001 for_each_rtx (&x, split_small_symbolic_operand_1, NULL);
2002 return x;
2005 /* Indicate that INSN cannot be duplicated. This is true for any insn
2006 that we've marked with gpdisp relocs, since those have to stay in
2007 1-1 correspondence with one another.
2009 Techinically we could copy them if we could set up a mapping from one
2010 sequence number to another, across the set of insns to be duplicated.
2011 This seems overly complicated and error-prone since interblock motion
2012 from sched-ebb could move one of the pair of insns to a different block. */
2014 static bool
2015 alpha_cannot_copy_insn_p (rtx insn)
2017 rtx pat;
2019 if (!reload_completed || !TARGET_EXPLICIT_RELOCS)
2020 return false;
2022 if (GET_CODE (insn) != INSN)
2023 return false;
2024 if (asm_noperands (insn) >= 0)
2025 return false;
2027 pat = PATTERN (insn);
2028 if (GET_CODE (pat) != SET)
2029 return false;
2030 pat = SET_SRC (pat);
2031 if (GET_CODE (pat) == UNSPEC_VOLATILE)
2033 if (XINT (pat, 1) == UNSPECV_LDGP1
2034 || XINT (pat, 1) == UNSPECV_PLDGP2)
2035 return true;
2037 else if (GET_CODE (pat) == UNSPEC)
2039 if (XINT (pat, 1) == UNSPEC_LDGP2)
2040 return true;
2043 return false;
2047 /* Try a machine-dependent way of reloading an illegitimate address
2048 operand. If we find one, push the reload and return the new rtx. */
2051 alpha_legitimize_reload_address (rtx x,
2052 enum machine_mode mode ATTRIBUTE_UNUSED,
2053 int opnum, int type,
2054 int ind_levels ATTRIBUTE_UNUSED)
2056 /* We must recognize output that we have already generated ourselves. */
2057 if (GET_CODE (x) == PLUS
2058 && GET_CODE (XEXP (x, 0)) == PLUS
2059 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2060 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2061 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2063 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2064 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2065 opnum, type);
2066 return x;
2069 /* We wish to handle large displacements off a base register by
2070 splitting the addend across an ldah and the mem insn. This
2071 cuts number of extra insns needed from 3 to 1. */
2072 if (GET_CODE (x) == PLUS
2073 && GET_CODE (XEXP (x, 0)) == REG
2074 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2075 && REGNO_OK_FOR_BASE_P (REGNO (XEXP (x, 0)))
2076 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2078 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2079 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2080 HOST_WIDE_INT high
2081 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2083 /* Check for 32-bit overflow. */
2084 if (high + low != val)
2085 return NULL_RTX;
2087 /* Reload the high part into a base reg; leave the low part
2088 in the mem directly. */
2089 x = gen_rtx_PLUS (GET_MODE (x),
2090 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2091 GEN_INT (high)),
2092 GEN_INT (low));
2094 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2095 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2096 opnum, type);
2097 return x;
2100 return NULL_RTX;
2103 /* Compute a (partial) cost for rtx X. Return true if the complete
2104 cost has been computed, and false if subexpressions should be
2105 scanned. In either case, *TOTAL contains the cost result. */
2107 static bool
2108 alpha_rtx_costs (rtx x, int code, int outer_code, int *total)
2110 enum machine_mode mode = GET_MODE (x);
2111 bool float_mode_p = FLOAT_MODE_P (mode);
2113 switch (code)
2115 /* If this is an 8-bit constant, return zero since it can be used
2116 nearly anywhere with no cost. If it is a valid operand for an
2117 ADD or AND, likewise return 0 if we know it will be used in that
2118 context. Otherwise, return 2 since it might be used there later.
2119 All other constants take at least two insns. */
2120 case CONST_INT:
2121 if (INTVAL (x) >= 0 && INTVAL (x) < 256)
2123 *total = 0;
2124 return true;
2126 /* FALLTHRU */
2128 case CONST_DOUBLE:
2129 if (x == CONST0_RTX (mode))
2130 *total = 0;
2131 else if ((outer_code == PLUS && add_operand (x, VOIDmode))
2132 || (outer_code == AND && and_operand (x, VOIDmode)))
2133 *total = 0;
2134 else if (add_operand (x, VOIDmode) || and_operand (x, VOIDmode))
2135 *total = 2;
2136 else
2137 *total = COSTS_N_INSNS (2);
2138 return true;
2140 case CONST:
2141 case SYMBOL_REF:
2142 case LABEL_REF:
2143 if (TARGET_EXPLICIT_RELOCS && small_symbolic_operand (x, VOIDmode))
2144 *total = COSTS_N_INSNS (outer_code != MEM);
2145 else if (TARGET_EXPLICIT_RELOCS && local_symbolic_operand (x, VOIDmode))
2146 *total = COSTS_N_INSNS (1 + (outer_code != MEM));
2147 else if (tls_symbolic_operand_type (x))
2148 /* Estimate of cost for call_pal rduniq. */
2149 *total = COSTS_N_INSNS (15);
2150 else
2151 /* Otherwise we do a load from the GOT. */
2152 *total = COSTS_N_INSNS (alpha_memory_latency);
2153 return true;
2155 case PLUS:
2156 case MINUS:
2157 if (float_mode_p)
2158 *total = alpha_rtx_cost_data[alpha_cpu].fp_add;
2159 else if (GET_CODE (XEXP (x, 0)) == MULT
2160 && const48_operand (XEXP (XEXP (x, 0), 1), VOIDmode))
2162 *total = (rtx_cost (XEXP (XEXP (x, 0), 0), outer_code)
2163 + rtx_cost (XEXP (x, 1), outer_code) + 2);
2164 return true;
2166 return false;
2168 case MULT:
2169 if (float_mode_p)
2170 *total = alpha_rtx_cost_data[alpha_cpu].fp_mult;
2171 else if (mode == DImode)
2172 *total = alpha_rtx_cost_data[alpha_cpu].int_mult_di;
2173 else
2174 *total = alpha_rtx_cost_data[alpha_cpu].int_mult_si;
2175 return false;
2177 case ASHIFT:
2178 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2179 && INTVAL (XEXP (x, 1)) <= 3)
2181 *total = COSTS_N_INSNS (1);
2182 return false;
2184 /* FALLTHRU */
2186 case ASHIFTRT:
2187 case LSHIFTRT:
2188 *total = alpha_rtx_cost_data[alpha_cpu].int_shift;
2189 return false;
2191 case IF_THEN_ELSE:
2192 if (float_mode_p)
2193 *total = alpha_rtx_cost_data[alpha_cpu].fp_add;
2194 else
2195 *total = alpha_rtx_cost_data[alpha_cpu].int_cmov;
2196 return false;
2198 case DIV:
2199 case UDIV:
2200 case MOD:
2201 case UMOD:
2202 if (!float_mode_p)
2203 *total = COSTS_N_INSNS (70); /* ??? */
2204 else if (mode == SFmode)
2205 *total = alpha_rtx_cost_data[alpha_cpu].fp_div_sf;
2206 else
2207 *total = alpha_rtx_cost_data[alpha_cpu].fp_div_df;
2208 return false;
2210 case MEM:
2211 *total = COSTS_N_INSNS (alpha_memory_latency);
2212 return true;
2214 case NEG:
2215 if (! float_mode_p)
2217 *total = COSTS_N_INSNS (1);
2218 return false;
2220 /* FALLTHRU */
2222 case ABS:
2223 if (! float_mode_p)
2225 *total = COSTS_N_INSNS (1) + alpha_rtx_cost_data[alpha_cpu].int_cmov;
2226 return false;
2228 /* FALLTHRU */
2230 case FLOAT:
2231 case UNSIGNED_FLOAT:
2232 case FIX:
2233 case UNSIGNED_FIX:
2234 case FLOAT_EXTEND:
2235 case FLOAT_TRUNCATE:
2236 *total = alpha_rtx_cost_data[alpha_cpu].fp_add;
2237 return false;
2239 default:
2240 return false;
2244 /* REF is an alignable memory location. Place an aligned SImode
2245 reference into *PALIGNED_MEM and the number of bits to shift into
2246 *PBITNUM. SCRATCH is a free register for use in reloading out
2247 of range stack slots. */
2249 void
2250 get_aligned_mem (rtx ref, rtx *paligned_mem, rtx *pbitnum)
2252 rtx base;
2253 HOST_WIDE_INT offset = 0;
2255 if (GET_CODE (ref) != MEM)
2256 abort ();
2258 if (reload_in_progress
2259 && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2261 base = find_replacement (&XEXP (ref, 0));
2263 if (! memory_address_p (GET_MODE (ref), base))
2264 abort ();
2266 else
2268 base = XEXP (ref, 0);
2271 if (GET_CODE (base) == PLUS)
2272 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2274 *paligned_mem
2275 = widen_memory_access (ref, SImode, (offset & ~3) - offset);
2277 if (WORDS_BIG_ENDIAN)
2278 *pbitnum = GEN_INT (32 - (GET_MODE_BITSIZE (GET_MODE (ref))
2279 + (offset & 3) * 8));
2280 else
2281 *pbitnum = GEN_INT ((offset & 3) * 8);
2284 /* Similar, but just get the address. Handle the two reload cases.
2285 Add EXTRA_OFFSET to the address we return. */
2288 get_unaligned_address (rtx ref, int extra_offset)
2290 rtx base;
2291 HOST_WIDE_INT offset = 0;
2293 if (GET_CODE (ref) != MEM)
2294 abort ();
2296 if (reload_in_progress
2297 && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2299 base = find_replacement (&XEXP (ref, 0));
2301 if (! memory_address_p (GET_MODE (ref), base))
2302 abort ();
2304 else
2306 base = XEXP (ref, 0);
2309 if (GET_CODE (base) == PLUS)
2310 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2312 return plus_constant (base, offset + extra_offset);
2315 /* On the Alpha, all (non-symbolic) constants except zero go into
2316 a floating-point register via memory. Note that we cannot
2317 return anything that is not a subset of CLASS, and that some
2318 symbolic constants cannot be dropped to memory. */
2320 enum reg_class
2321 alpha_preferred_reload_class(rtx x, enum reg_class class)
2323 /* Zero is present in any register class. */
2324 if (x == CONST0_RTX (GET_MODE (x)))
2325 return class;
2327 /* These sorts of constants we can easily drop to memory. */
2328 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
2330 if (class == FLOAT_REGS)
2331 return NO_REGS;
2332 if (class == ALL_REGS)
2333 return GENERAL_REGS;
2334 return class;
2337 /* All other kinds of constants should not (and in the case of HIGH
2338 cannot) be dropped to memory -- instead we use a GENERAL_REGS
2339 secondary reload. */
2340 if (CONSTANT_P (x))
2341 return (class == ALL_REGS ? GENERAL_REGS : class);
2343 return class;
2346 /* Loading and storing HImode or QImode values to and from memory
2347 usually requires a scratch register. The exceptions are loading
2348 QImode and HImode from an aligned address to a general register
2349 unless byte instructions are permitted.
2351 We also cannot load an unaligned address or a paradoxical SUBREG
2352 into an FP register.
2354 We also cannot do integral arithmetic into FP regs, as might result
2355 from register elimination into a DImode fp register. */
2357 enum reg_class
2358 secondary_reload_class (enum reg_class class, enum machine_mode mode,
2359 rtx x, int in)
2361 if ((mode == QImode || mode == HImode) && ! TARGET_BWX)
2363 if (GET_CODE (x) == MEM
2364 || (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2365 || (GET_CODE (x) == SUBREG
2366 && (GET_CODE (SUBREG_REG (x)) == MEM
2367 || (GET_CODE (SUBREG_REG (x)) == REG
2368 && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER))))
2370 if (!in || !aligned_memory_operand(x, mode))
2371 return GENERAL_REGS;
2375 if (class == FLOAT_REGS)
2377 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
2378 return GENERAL_REGS;
2380 if (GET_CODE (x) == SUBREG
2381 && (GET_MODE_SIZE (GET_MODE (x))
2382 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
2383 return GENERAL_REGS;
2385 if (in && INTEGRAL_MODE_P (mode)
2386 && ! (memory_operand (x, mode) || x == const0_rtx))
2387 return GENERAL_REGS;
2390 return NO_REGS;
2393 /* Subfunction of the following function. Update the flags of any MEM
2394 found in part of X. */
2396 static void
2397 alpha_set_memflags_1 (rtx x, int in_struct_p, int volatile_p, int unchanging_p)
2399 int i;
2401 switch (GET_CODE (x))
2403 case SEQUENCE:
2404 abort ();
2406 case PARALLEL:
2407 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2408 alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
2409 unchanging_p);
2410 break;
2412 case INSN:
2413 alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
2414 unchanging_p);
2415 break;
2417 case SET:
2418 alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
2419 unchanging_p);
2420 alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p,
2421 unchanging_p);
2422 break;
2424 case MEM:
2425 MEM_IN_STRUCT_P (x) = in_struct_p;
2426 MEM_VOLATILE_P (x) = volatile_p;
2427 RTX_UNCHANGING_P (x) = unchanging_p;
2428 /* Sadly, we cannot use alias sets because the extra aliasing
2429 produced by the AND interferes. Given that two-byte quantities
2430 are the only thing we would be able to differentiate anyway,
2431 there does not seem to be any point in convoluting the early
2432 out of the alias check. */
2433 break;
2435 default:
2436 break;
2440 /* Given INSN, which is an INSN list or the PATTERN of a single insn
2441 generated to perform a memory operation, look for any MEMs in either
2442 a SET_DEST or a SET_SRC and copy the in-struct, unchanging, and
2443 volatile flags from REF into each of the MEMs found. If REF is not
2444 a MEM, don't do anything. */
2446 void
2447 alpha_set_memflags (rtx insn, rtx ref)
2449 int in_struct_p, volatile_p, unchanging_p;
2451 if (GET_CODE (ref) != MEM)
2452 return;
2454 in_struct_p = MEM_IN_STRUCT_P (ref);
2455 volatile_p = MEM_VOLATILE_P (ref);
2456 unchanging_p = RTX_UNCHANGING_P (ref);
2458 /* This is only called from alpha.md, after having had something
2459 generated from one of the insn patterns. So if everything is
2460 zero, the pattern is already up-to-date. */
2461 if (! in_struct_p && ! volatile_p && ! unchanging_p)
2462 return;
2464 alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
2467 /* Internal routine for alpha_emit_set_const to check for N or below insns. */
2469 static rtx
2470 alpha_emit_set_const_1 (rtx target, enum machine_mode mode,
2471 HOST_WIDE_INT c, int n)
2473 HOST_WIDE_INT new;
2474 int i, bits;
2475 /* Use a pseudo if highly optimizing and still generating RTL. */
2476 rtx subtarget
2477 = (flag_expensive_optimizations && !no_new_pseudos ? 0 : target);
2478 rtx temp, insn;
2480 /* If this is a sign-extended 32-bit constant, we can do this in at most
2481 three insns, so do it if we have enough insns left. We always have
2482 a sign-extended 32-bit constant when compiling on a narrow machine. */
2484 if (HOST_BITS_PER_WIDE_INT != 64
2485 || c >> 31 == -1 || c >> 31 == 0)
2487 HOST_WIDE_INT low = ((c & 0xffff) ^ 0x8000) - 0x8000;
2488 HOST_WIDE_INT tmp1 = c - low;
2489 HOST_WIDE_INT high = (((tmp1 >> 16) & 0xffff) ^ 0x8000) - 0x8000;
2490 HOST_WIDE_INT extra = 0;
2492 /* If HIGH will be interpreted as negative but the constant is
2493 positive, we must adjust it to do two ldha insns. */
2495 if ((high & 0x8000) != 0 && c >= 0)
2497 extra = 0x4000;
2498 tmp1 -= 0x40000000;
2499 high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
2502 if (c == low || (low == 0 && extra == 0))
2504 /* We used to use copy_to_suggested_reg (GEN_INT (c), target, mode)
2505 but that meant that we can't handle INT_MIN on 32-bit machines
2506 (like NT/Alpha), because we recurse indefinitely through
2507 emit_move_insn to gen_movdi. So instead, since we know exactly
2508 what we want, create it explicitly. */
2510 if (target == NULL)
2511 target = gen_reg_rtx (mode);
2512 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (c)));
2513 return target;
2515 else if (n >= 2 + (extra != 0))
2517 temp = copy_to_suggested_reg (GEN_INT (high << 16), subtarget, mode);
2519 /* As of 2002-02-23, addsi3 is only available when not optimizing.
2520 This means that if we go through expand_binop, we'll try to
2521 generate extensions, etc, which will require new pseudos, which
2522 will fail during some split phases. The SImode add patterns
2523 still exist, but are not named. So build the insns by hand. */
2525 if (extra != 0)
2527 if (! subtarget)
2528 subtarget = gen_reg_rtx (mode);
2529 insn = gen_rtx_PLUS (mode, temp, GEN_INT (extra << 16));
2530 insn = gen_rtx_SET (VOIDmode, subtarget, insn);
2531 emit_insn (insn);
2532 temp = subtarget;
2535 if (target == NULL)
2536 target = gen_reg_rtx (mode);
2537 insn = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2538 insn = gen_rtx_SET (VOIDmode, target, insn);
2539 emit_insn (insn);
2540 return target;
2544 /* If we couldn't do it that way, try some other methods. But if we have
2545 no instructions left, don't bother. Likewise, if this is SImode and
2546 we can't make pseudos, we can't do anything since the expand_binop
2547 and expand_unop calls will widen and try to make pseudos. */
2549 if (n == 1 || (mode == SImode && no_new_pseudos))
2550 return 0;
2552 /* Next, see if we can load a related constant and then shift and possibly
2553 negate it to get the constant we want. Try this once each increasing
2554 numbers of insns. */
2556 for (i = 1; i < n; i++)
2558 /* First, see if minus some low bits, we've an easy load of
2559 high bits. */
2561 new = ((c & 0xffff) ^ 0x8000) - 0x8000;
2562 if (new != 0
2563 && (temp = alpha_emit_set_const (subtarget, mode, c - new, i)) != 0)
2564 return expand_binop (mode, add_optab, temp, GEN_INT (new),
2565 target, 0, OPTAB_WIDEN);
2567 /* Next try complementing. */
2568 if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0)
2569 return expand_unop (mode, one_cmpl_optab, temp, target, 0);
2571 /* Next try to form a constant and do a left shift. We can do this
2572 if some low-order bits are zero; the exact_log2 call below tells
2573 us that information. The bits we are shifting out could be any
2574 value, but here we'll just try the 0- and sign-extended forms of
2575 the constant. To try to increase the chance of having the same
2576 constant in more than one insn, start at the highest number of
2577 bits to shift, but try all possibilities in case a ZAPNOT will
2578 be useful. */
2580 if ((bits = exact_log2 (c & - c)) > 0)
2581 for (; bits > 0; bits--)
2582 if ((temp = (alpha_emit_set_const
2583 (subtarget, mode, c >> bits, i))) != 0
2584 || ((temp = (alpha_emit_set_const
2585 (subtarget, mode,
2586 ((unsigned HOST_WIDE_INT) c) >> bits, i)))
2587 != 0))
2588 return expand_binop (mode, ashl_optab, temp, GEN_INT (bits),
2589 target, 0, OPTAB_WIDEN);
2591 /* Now try high-order zero bits. Here we try the shifted-in bits as
2592 all zero and all ones. Be careful to avoid shifting outside the
2593 mode and to avoid shifting outside the host wide int size. */
2594 /* On narrow hosts, don't shift a 1 into the high bit, since we'll
2595 confuse the recursive call and set all of the high 32 bits. */
2597 if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
2598 - floor_log2 (c) - 1 - (HOST_BITS_PER_WIDE_INT < 64))) > 0)
2599 for (; bits > 0; bits--)
2600 if ((temp = alpha_emit_set_const (subtarget, mode,
2601 c << bits, i)) != 0
2602 || ((temp = (alpha_emit_set_const
2603 (subtarget, mode,
2604 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
2605 i)))
2606 != 0))
2607 return expand_binop (mode, lshr_optab, temp, GEN_INT (bits),
2608 target, 1, OPTAB_WIDEN);
2610 /* Now try high-order 1 bits. We get that with a sign-extension.
2611 But one bit isn't enough here. Be careful to avoid shifting outside
2612 the mode and to avoid shifting outside the host wide int size. */
2614 if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
2615 - floor_log2 (~ c) - 2)) > 0)
2616 for (; bits > 0; bits--)
2617 if ((temp = alpha_emit_set_const (subtarget, mode,
2618 c << bits, i)) != 0
2619 || ((temp = (alpha_emit_set_const
2620 (subtarget, mode,
2621 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
2622 i)))
2623 != 0))
2624 return expand_binop (mode, ashr_optab, temp, GEN_INT (bits),
2625 target, 0, OPTAB_WIDEN);
2628 #if HOST_BITS_PER_WIDE_INT == 64
2629 /* Finally, see if can load a value into the target that is the same as the
2630 constant except that all bytes that are 0 are changed to be 0xff. If we
2631 can, then we can do a ZAPNOT to obtain the desired constant. */
2633 new = c;
2634 for (i = 0; i < 64; i += 8)
2635 if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
2636 new |= (HOST_WIDE_INT) 0xff << i;
2638 /* We are only called for SImode and DImode. If this is SImode, ensure that
2639 we are sign extended to a full word. */
2641 if (mode == SImode)
2642 new = ((new & 0xffffffff) ^ 0x80000000) - 0x80000000;
2644 if (new != c && new != -1
2645 && (temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0)
2646 return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new),
2647 target, 0, OPTAB_WIDEN);
2648 #endif
2650 return 0;
2653 /* Try to output insns to set TARGET equal to the constant C if it can be
2654 done in less than N insns. Do all computations in MODE. Returns the place
2655 where the output has been placed if it can be done and the insns have been
2656 emitted. If it would take more than N insns, zero is returned and no
2657 insns and emitted. */
2660 alpha_emit_set_const (rtx target, enum machine_mode mode,
2661 HOST_WIDE_INT c, int n)
2663 rtx result = 0;
2664 rtx orig_target = target;
2665 int i;
2667 /* If we can't make any pseudos, TARGET is an SImode hard register, we
2668 can't load this constant in one insn, do this in DImode. */
2669 if (no_new_pseudos && mode == SImode
2670 && GET_CODE (target) == REG && REGNO (target) < FIRST_PSEUDO_REGISTER
2671 && (result = alpha_emit_set_const_1 (target, mode, c, 1)) == 0)
2673 target = gen_lowpart (DImode, target);
2674 mode = DImode;
2677 /* Try 1 insn, then 2, then up to N. */
2678 for (i = 1; i <= n; i++)
2680 result = alpha_emit_set_const_1 (target, mode, c, i);
2681 if (result)
2683 rtx insn = get_last_insn ();
2684 rtx set = single_set (insn);
2685 if (! CONSTANT_P (SET_SRC (set)))
2686 set_unique_reg_note (get_last_insn (), REG_EQUAL, GEN_INT (c));
2687 break;
2691 /* Allow for the case where we changed the mode of TARGET. */
2692 if (result == target)
2693 result = orig_target;
2695 return result;
2698 /* Having failed to find a 3 insn sequence in alpha_emit_set_const,
2699 fall back to a straight forward decomposition. We do this to avoid
2700 exponential run times encountered when looking for longer sequences
2701 with alpha_emit_set_const. */
2704 alpha_emit_set_long_const (rtx target, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2706 HOST_WIDE_INT d1, d2, d3, d4;
2708 /* Decompose the entire word */
2709 #if HOST_BITS_PER_WIDE_INT >= 64
2710 if (c2 != -(c1 < 0))
2711 abort ();
2712 d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2713 c1 -= d1;
2714 d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2715 c1 = (c1 - d2) >> 32;
2716 d3 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2717 c1 -= d3;
2718 d4 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2719 if (c1 != d4)
2720 abort ();
2721 #else
2722 d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2723 c1 -= d1;
2724 d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2725 if (c1 != d2)
2726 abort ();
2727 c2 += (d2 < 0);
2728 d3 = ((c2 & 0xffff) ^ 0x8000) - 0x8000;
2729 c2 -= d3;
2730 d4 = ((c2 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2731 if (c2 != d4)
2732 abort ();
2733 #endif
2735 /* Construct the high word */
2736 if (d4)
2738 emit_move_insn (target, GEN_INT (d4));
2739 if (d3)
2740 emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d3)));
2742 else
2743 emit_move_insn (target, GEN_INT (d3));
2745 /* Shift it into place */
2746 emit_move_insn (target, gen_rtx_ASHIFT (DImode, target, GEN_INT (32)));
2748 /* Add in the low bits. */
2749 if (d2)
2750 emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d2)));
2751 if (d1)
2752 emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d1)));
2754 return target;
2757 /* Expand a move instruction; return true if all work is done.
2758 We don't handle non-bwx subword loads here. */
2760 bool
2761 alpha_expand_mov (enum machine_mode mode, rtx *operands)
2763 /* If the output is not a register, the input must be. */
2764 if (GET_CODE (operands[0]) == MEM
2765 && ! reg_or_0_operand (operands[1], mode))
2766 operands[1] = force_reg (mode, operands[1]);
2768 /* Allow legitimize_address to perform some simplifications. */
2769 if (mode == Pmode && symbolic_operand (operands[1], mode))
2771 rtx tmp;
2773 /* With RTL inlining, at -O3, rtl is generated, stored, then actually
2774 compiled at the end of compilation. In the meantime, someone can
2775 re-encode-section-info on some symbol changing it e.g. from global
2776 to local-not-small. If this happens, we'd have emitted a plain
2777 load rather than a high+losum load and not recognize the insn.
2779 So if rtl inlining is in effect, we delay the global/not-global
2780 decision until rest_of_compilation by wrapping it in an
2781 UNSPEC_SYMBOL. */
2782 if (TARGET_EXPLICIT_RELOCS && flag_inline_functions
2783 && rtx_equal_function_value_matters
2784 && global_symbolic_operand (operands[1], mode))
2786 emit_insn (gen_movdi_er_maybe_g (operands[0], operands[1]));
2787 return true;
2790 tmp = alpha_legitimize_address (operands[1], operands[0], mode);
2791 if (tmp)
2793 if (tmp == operands[0])
2794 return true;
2795 operands[1] = tmp;
2796 return false;
2800 /* Early out for non-constants and valid constants. */
2801 if (! CONSTANT_P (operands[1]) || input_operand (operands[1], mode))
2802 return false;
2804 /* Split large integers. */
2805 if (GET_CODE (operands[1]) == CONST_INT
2806 || GET_CODE (operands[1]) == CONST_DOUBLE)
2808 HOST_WIDE_INT i0, i1;
2809 rtx temp = NULL_RTX;
2811 if (GET_CODE (operands[1]) == CONST_INT)
2813 i0 = INTVAL (operands[1]);
2814 i1 = -(i0 < 0);
2816 else if (HOST_BITS_PER_WIDE_INT >= 64)
2818 i0 = CONST_DOUBLE_LOW (operands[1]);
2819 i1 = -(i0 < 0);
2821 else
2823 i0 = CONST_DOUBLE_LOW (operands[1]);
2824 i1 = CONST_DOUBLE_HIGH (operands[1]);
2827 if (HOST_BITS_PER_WIDE_INT >= 64 || i1 == -(i0 < 0))
2828 temp = alpha_emit_set_const (operands[0], mode, i0, 3);
2830 if (!temp && TARGET_BUILD_CONSTANTS)
2831 temp = alpha_emit_set_long_const (operands[0], i0, i1);
2833 if (temp)
2835 if (rtx_equal_p (operands[0], temp))
2836 return true;
2837 operands[1] = temp;
2838 return false;
2842 /* Otherwise we've nothing left but to drop the thing to memory. */
2843 operands[1] = force_const_mem (mode, operands[1]);
2844 if (reload_in_progress)
2846 emit_move_insn (operands[0], XEXP (operands[1], 0));
2847 operands[1] = copy_rtx (operands[1]);
2848 XEXP (operands[1], 0) = operands[0];
2850 else
2851 operands[1] = validize_mem (operands[1]);
2852 return false;
2855 /* Expand a non-bwx QImode or HImode move instruction;
2856 return true if all work is done. */
2858 bool
2859 alpha_expand_mov_nobwx (enum machine_mode mode, rtx *operands)
2861 /* If the output is not a register, the input must be. */
2862 if (GET_CODE (operands[0]) == MEM)
2863 operands[1] = force_reg (mode, operands[1]);
2865 /* Handle four memory cases, unaligned and aligned for either the input
2866 or the output. The only case where we can be called during reload is
2867 for aligned loads; all other cases require temporaries. */
2869 if (GET_CODE (operands[1]) == MEM
2870 || (GET_CODE (operands[1]) == SUBREG
2871 && GET_CODE (SUBREG_REG (operands[1])) == MEM)
2872 || (reload_in_progress && GET_CODE (operands[1]) == REG
2873 && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
2874 || (reload_in_progress && GET_CODE (operands[1]) == SUBREG
2875 && GET_CODE (SUBREG_REG (operands[1])) == REG
2876 && REGNO (SUBREG_REG (operands[1])) >= FIRST_PSEUDO_REGISTER))
2878 if (aligned_memory_operand (operands[1], mode))
2880 if (reload_in_progress)
2882 emit_insn ((mode == QImode
2883 ? gen_reload_inqi_help
2884 : gen_reload_inhi_help)
2885 (operands[0], operands[1],
2886 gen_rtx_REG (SImode, REGNO (operands[0]))));
2888 else
2890 rtx aligned_mem, bitnum;
2891 rtx scratch = gen_reg_rtx (SImode);
2893 get_aligned_mem (operands[1], &aligned_mem, &bitnum);
2895 emit_insn ((mode == QImode
2896 ? gen_aligned_loadqi
2897 : gen_aligned_loadhi)
2898 (operands[0], aligned_mem, bitnum, scratch));
2901 else
2903 /* Don't pass these as parameters since that makes the generated
2904 code depend on parameter evaluation order which will cause
2905 bootstrap failures. */
2907 rtx temp1 = gen_reg_rtx (DImode);
2908 rtx temp2 = gen_reg_rtx (DImode);
2909 rtx seq = ((mode == QImode
2910 ? gen_unaligned_loadqi
2911 : gen_unaligned_loadhi)
2912 (operands[0], get_unaligned_address (operands[1], 0),
2913 temp1, temp2));
2915 alpha_set_memflags (seq, operands[1]);
2916 emit_insn (seq);
2918 return true;
2921 if (GET_CODE (operands[0]) == MEM
2922 || (GET_CODE (operands[0]) == SUBREG
2923 && GET_CODE (SUBREG_REG (operands[0])) == MEM)
2924 || (reload_in_progress && GET_CODE (operands[0]) == REG
2925 && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)
2926 || (reload_in_progress && GET_CODE (operands[0]) == SUBREG
2927 && GET_CODE (SUBREG_REG (operands[0])) == REG
2928 && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))
2930 if (aligned_memory_operand (operands[0], mode))
2932 rtx aligned_mem, bitnum;
2933 rtx temp1 = gen_reg_rtx (SImode);
2934 rtx temp2 = gen_reg_rtx (SImode);
2936 get_aligned_mem (operands[0], &aligned_mem, &bitnum);
2938 emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
2939 temp1, temp2));
2941 else
2943 rtx temp1 = gen_reg_rtx (DImode);
2944 rtx temp2 = gen_reg_rtx (DImode);
2945 rtx temp3 = gen_reg_rtx (DImode);
2946 rtx seq = ((mode == QImode
2947 ? gen_unaligned_storeqi
2948 : gen_unaligned_storehi)
2949 (get_unaligned_address (operands[0], 0),
2950 operands[1], temp1, temp2, temp3));
2952 alpha_set_memflags (seq, operands[0]);
2953 emit_insn (seq);
2955 return true;
2958 return false;
2961 /* Generate an unsigned DImode to FP conversion. This is the same code
2962 optabs would emit if we didn't have TFmode patterns.
2964 For SFmode, this is the only construction I've found that can pass
2965 gcc.c-torture/execute/ieee/rbug.c. No scenario that uses DFmode
2966 intermediates will work, because you'll get intermediate rounding
2967 that ruins the end result. Some of this could be fixed by turning
2968 on round-to-positive-infinity, but that requires diddling the fpsr,
2969 which kills performance. I tried turning this around and converting
2970 to a negative number, so that I could turn on /m, but either I did
2971 it wrong or there's something else cause I wound up with the exact
2972 same single-bit error. There is a branch-less form of this same code:
2974 srl $16,1,$1
2975 and $16,1,$2
2976 cmplt $16,0,$3
2977 or $1,$2,$2
2978 cmovge $16,$16,$2
2979 itoft $3,$f10
2980 itoft $2,$f11
2981 cvtqs $f11,$f11
2982 adds $f11,$f11,$f0
2983 fcmoveq $f10,$f11,$f0
2985 I'm not using it because it's the same number of instructions as
2986 this branch-full form, and it has more serialized long latency
2987 instructions on the critical path.
2989 For DFmode, we can avoid rounding errors by breaking up the word
2990 into two pieces, converting them separately, and adding them back:
2992 LC0: .long 0,0x5f800000
2994 itoft $16,$f11
2995 lda $2,LC0
2996 cmplt $16,0,$1
2997 cpyse $f11,$f31,$f10
2998 cpyse $f31,$f11,$f11
2999 s4addq $1,$2,$1
3000 lds $f12,0($1)
3001 cvtqt $f10,$f10
3002 cvtqt $f11,$f11
3003 addt $f12,$f10,$f0
3004 addt $f0,$f11,$f0
3006 This doesn't seem to be a clear-cut win over the optabs form.
3007 It probably all depends on the distribution of numbers being
3008 converted -- in the optabs form, all but high-bit-set has a
3009 much lower minimum execution time. */
3011 void
3012 alpha_emit_floatuns (rtx operands[2])
3014 rtx neglab, donelab, i0, i1, f0, in, out;
3015 enum machine_mode mode;
3017 out = operands[0];
3018 in = force_reg (DImode, operands[1]);
3019 mode = GET_MODE (out);
3020 neglab = gen_label_rtx ();
3021 donelab = gen_label_rtx ();
3022 i0 = gen_reg_rtx (DImode);
3023 i1 = gen_reg_rtx (DImode);
3024 f0 = gen_reg_rtx (mode);
3026 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
3028 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
3029 emit_jump_insn (gen_jump (donelab));
3030 emit_barrier ();
3032 emit_label (neglab);
3034 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
3035 emit_insn (gen_anddi3 (i1, in, const1_rtx));
3036 emit_insn (gen_iordi3 (i0, i0, i1));
3037 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
3038 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
3040 emit_label (donelab);
3043 /* Generate the comparison for a conditional branch. */
3046 alpha_emit_conditional_branch (enum rtx_code code)
3048 enum rtx_code cmp_code, branch_code;
3049 enum machine_mode cmp_mode, branch_mode = VOIDmode;
3050 rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1;
3051 rtx tem;
3053 if (alpha_compare.fp_p && GET_MODE (op0) == TFmode)
3055 if (! TARGET_HAS_XFLOATING_LIBS)
3056 abort ();
3058 /* X_floating library comparison functions return
3059 -1 unordered
3060 0 false
3061 1 true
3062 Convert the compare against the raw return value. */
3064 switch (code)
3066 case UNORDERED:
3067 cmp_code = EQ;
3068 code = LT;
3069 break;
3070 case ORDERED:
3071 cmp_code = EQ;
3072 code = GE;
3073 break;
3074 case NE:
3075 cmp_code = NE;
3076 code = NE;
3077 break;
3078 default:
3079 cmp_code = code;
3080 code = GT;
3081 break;
3084 op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3085 op1 = const0_rtx;
3086 alpha_compare.fp_p = 0;
3089 /* The general case: fold the comparison code to the types of compares
3090 that we have, choosing the branch as necessary. */
3091 switch (code)
3093 case EQ: case LE: case LT: case LEU: case LTU:
3094 case UNORDERED:
3095 /* We have these compares: */
3096 cmp_code = code, branch_code = NE;
3097 break;
3099 case NE:
3100 case ORDERED:
3101 /* These must be reversed. */
3102 cmp_code = reverse_condition (code), branch_code = EQ;
3103 break;
3105 case GE: case GT: case GEU: case GTU:
3106 /* For FP, we swap them, for INT, we reverse them. */
3107 if (alpha_compare.fp_p)
3109 cmp_code = swap_condition (code);
3110 branch_code = NE;
3111 tem = op0, op0 = op1, op1 = tem;
3113 else
3115 cmp_code = reverse_condition (code);
3116 branch_code = EQ;
3118 break;
3120 default:
3121 abort ();
3124 if (alpha_compare.fp_p)
3126 cmp_mode = DFmode;
3127 if (flag_unsafe_math_optimizations)
3129 /* When we are not as concerned about non-finite values, and we
3130 are comparing against zero, we can branch directly. */
3131 if (op1 == CONST0_RTX (DFmode))
3132 cmp_code = NIL, branch_code = code;
3133 else if (op0 == CONST0_RTX (DFmode))
3135 /* Undo the swap we probably did just above. */
3136 tem = op0, op0 = op1, op1 = tem;
3137 branch_code = swap_condition (cmp_code);
3138 cmp_code = NIL;
3141 else
3143 /* ??? We mark the branch mode to be CCmode to prevent the
3144 compare and branch from being combined, since the compare
3145 insn follows IEEE rules that the branch does not. */
3146 branch_mode = CCmode;
3149 else
3151 cmp_mode = DImode;
3153 /* The following optimizations are only for signed compares. */
3154 if (code != LEU && code != LTU && code != GEU && code != GTU)
3156 /* Whee. Compare and branch against 0 directly. */
3157 if (op1 == const0_rtx)
3158 cmp_code = NIL, branch_code = code;
3160 /* We want to use cmpcc/bcc when we can, since there is a zero delay
3161 bypass between logicals and br/cmov on EV5. But we don't want to
3162 force valid immediate constants into registers needlessly. */
3163 else if (GET_CODE (op1) == CONST_INT)
3165 HOST_WIDE_INT v = INTVAL (op1), n = -v;
3167 if (! CONST_OK_FOR_LETTER_P (v, 'I')
3168 && (CONST_OK_FOR_LETTER_P (n, 'K')
3169 || CONST_OK_FOR_LETTER_P (n, 'L')))
3171 cmp_code = PLUS, branch_code = code;
3172 op1 = GEN_INT (n);
3177 if (!reg_or_0_operand (op0, DImode))
3178 op0 = force_reg (DImode, op0);
3179 if (cmp_code != PLUS && !reg_or_8bit_operand (op1, DImode))
3180 op1 = force_reg (DImode, op1);
3183 /* Emit an initial compare instruction, if necessary. */
3184 tem = op0;
3185 if (cmp_code != NIL)
3187 tem = gen_reg_rtx (cmp_mode);
3188 emit_move_insn (tem, gen_rtx_fmt_ee (cmp_code, cmp_mode, op0, op1));
3191 /* Zero the operands. */
3192 memset (&alpha_compare, 0, sizeof (alpha_compare));
3194 /* Return the branch comparison. */
3195 return gen_rtx_fmt_ee (branch_code, branch_mode, tem, CONST0_RTX (cmp_mode));
3198 /* Certain simplifications can be done to make invalid setcc operations
3199 valid. Return the final comparison, or NULL if we can't work. */
3202 alpha_emit_setcc (enum rtx_code code)
3204 enum rtx_code cmp_code;
3205 rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1;
3206 int fp_p = alpha_compare.fp_p;
3207 rtx tmp;
3209 /* Zero the operands. */
3210 memset (&alpha_compare, 0, sizeof (alpha_compare));
3212 if (fp_p && GET_MODE (op0) == TFmode)
3214 if (! TARGET_HAS_XFLOATING_LIBS)
3215 abort ();
3217 /* X_floating library comparison functions return
3218 -1 unordered
3219 0 false
3220 1 true
3221 Convert the compare against the raw return value. */
3223 if (code == UNORDERED || code == ORDERED)
3224 cmp_code = EQ;
3225 else
3226 cmp_code = code;
3228 op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3229 op1 = const0_rtx;
3230 fp_p = 0;
3232 if (code == UNORDERED)
3233 code = LT;
3234 else if (code == ORDERED)
3235 code = GE;
3236 else
3237 code = GT;
3240 if (fp_p && !TARGET_FIX)
3241 return NULL_RTX;
3243 /* The general case: fold the comparison code to the types of compares
3244 that we have, choosing the branch as necessary. */
3246 cmp_code = NIL;
3247 switch (code)
3249 case EQ: case LE: case LT: case LEU: case LTU:
3250 case UNORDERED:
3251 /* We have these compares. */
3252 if (fp_p)
3253 cmp_code = code, code = NE;
3254 break;
3256 case NE:
3257 if (!fp_p && op1 == const0_rtx)
3258 break;
3259 /* FALLTHRU */
3261 case ORDERED:
3262 cmp_code = reverse_condition (code);
3263 code = EQ;
3264 break;
3266 case GE: case GT: case GEU: case GTU:
3267 /* These normally need swapping, but for integer zero we have
3268 special patterns that recognize swapped operands. */
3269 if (!fp_p && op1 == const0_rtx)
3270 break;
3271 code = swap_condition (code);
3272 if (fp_p)
3273 cmp_code = code, code = NE;
3274 tmp = op0, op0 = op1, op1 = tmp;
3275 break;
3277 default:
3278 abort ();
3281 if (!fp_p)
3283 if (!register_operand (op0, DImode))
3284 op0 = force_reg (DImode, op0);
3285 if (!reg_or_8bit_operand (op1, DImode))
3286 op1 = force_reg (DImode, op1);
3289 /* Emit an initial compare instruction, if necessary. */
3290 if (cmp_code != NIL)
3292 enum machine_mode mode = fp_p ? DFmode : DImode;
3294 tmp = gen_reg_rtx (mode);
3295 emit_insn (gen_rtx_SET (VOIDmode, tmp,
3296 gen_rtx_fmt_ee (cmp_code, mode, op0, op1)));
3298 op0 = fp_p ? gen_lowpart (DImode, tmp) : tmp;
3299 op1 = const0_rtx;
3302 /* Return the setcc comparison. */
3303 return gen_rtx_fmt_ee (code, DImode, op0, op1);
3307 /* Rewrite a comparison against zero CMP of the form
3308 (CODE (cc0) (const_int 0)) so it can be written validly in
3309 a conditional move (if_then_else CMP ...).
3310 If both of the operands that set cc0 are nonzero we must emit
3311 an insn to perform the compare (it can't be done within
3312 the conditional move). */
3315 alpha_emit_conditional_move (rtx cmp, enum machine_mode mode)
3317 enum rtx_code code = GET_CODE (cmp);
3318 enum rtx_code cmov_code = NE;
3319 rtx op0 = alpha_compare.op0;
3320 rtx op1 = alpha_compare.op1;
3321 int fp_p = alpha_compare.fp_p;
3322 enum machine_mode cmp_mode
3323 = (GET_MODE (op0) == VOIDmode ? DImode : GET_MODE (op0));
3324 enum machine_mode cmp_op_mode = fp_p ? DFmode : DImode;
3325 enum machine_mode cmov_mode = VOIDmode;
3326 int local_fast_math = flag_unsafe_math_optimizations;
3327 rtx tem;
3329 /* Zero the operands. */
3330 memset (&alpha_compare, 0, sizeof (alpha_compare));
3332 if (fp_p != FLOAT_MODE_P (mode))
3334 enum rtx_code cmp_code;
3336 if (! TARGET_FIX)
3337 return 0;
3339 /* If we have fp<->int register move instructions, do a cmov by
3340 performing the comparison in fp registers, and move the
3341 zero/nonzero value to integer registers, where we can then
3342 use a normal cmov, or vice-versa. */
3344 switch (code)
3346 case EQ: case LE: case LT: case LEU: case LTU:
3347 /* We have these compares. */
3348 cmp_code = code, code = NE;
3349 break;
3351 case NE:
3352 /* This must be reversed. */
3353 cmp_code = EQ, code = EQ;
3354 break;
3356 case GE: case GT: case GEU: case GTU:
3357 /* These normally need swapping, but for integer zero we have
3358 special patterns that recognize swapped operands. */
3359 if (!fp_p && op1 == const0_rtx)
3360 cmp_code = code, code = NE;
3361 else
3363 cmp_code = swap_condition (code);
3364 code = NE;
3365 tem = op0, op0 = op1, op1 = tem;
3367 break;
3369 default:
3370 abort ();
3373 tem = gen_reg_rtx (cmp_op_mode);
3374 emit_insn (gen_rtx_SET (VOIDmode, tem,
3375 gen_rtx_fmt_ee (cmp_code, cmp_op_mode,
3376 op0, op1)));
3378 cmp_mode = cmp_op_mode = fp_p ? DImode : DFmode;
3379 op0 = gen_lowpart (cmp_op_mode, tem);
3380 op1 = CONST0_RTX (cmp_op_mode);
3381 fp_p = !fp_p;
3382 local_fast_math = 1;
3385 /* We may be able to use a conditional move directly.
3386 This avoids emitting spurious compares. */
3387 if (signed_comparison_operator (cmp, VOIDmode)
3388 && (!fp_p || local_fast_math)
3389 && (op0 == CONST0_RTX (cmp_mode) || op1 == CONST0_RTX (cmp_mode)))
3390 return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
3392 /* We can't put the comparison inside the conditional move;
3393 emit a compare instruction and put that inside the
3394 conditional move. Make sure we emit only comparisons we have;
3395 swap or reverse as necessary. */
3397 if (no_new_pseudos)
3398 return NULL_RTX;
3400 switch (code)
3402 case EQ: case LE: case LT: case LEU: case LTU:
3403 /* We have these compares: */
3404 break;
3406 case NE:
3407 /* This must be reversed. */
3408 code = reverse_condition (code);
3409 cmov_code = EQ;
3410 break;
3412 case GE: case GT: case GEU: case GTU:
3413 /* These must be swapped. */
3414 if (op1 != CONST0_RTX (cmp_mode))
3416 code = swap_condition (code);
3417 tem = op0, op0 = op1, op1 = tem;
3419 break;
3421 default:
3422 abort ();
3425 if (!fp_p)
3427 if (!reg_or_0_operand (op0, DImode))
3428 op0 = force_reg (DImode, op0);
3429 if (!reg_or_8bit_operand (op1, DImode))
3430 op1 = force_reg (DImode, op1);
3433 /* ??? We mark the branch mode to be CCmode to prevent the compare
3434 and cmov from being combined, since the compare insn follows IEEE
3435 rules that the cmov does not. */
3436 if (fp_p && !local_fast_math)
3437 cmov_mode = CCmode;
3439 tem = gen_reg_rtx (cmp_op_mode);
3440 emit_move_insn (tem, gen_rtx_fmt_ee (code, cmp_op_mode, op0, op1));
3441 return gen_rtx_fmt_ee (cmov_code, cmov_mode, tem, CONST0_RTX (cmp_op_mode));
3444 /* Simplify a conditional move of two constants into a setcc with
3445 arithmetic. This is done with a splitter since combine would
3446 just undo the work if done during code generation. It also catches
3447 cases we wouldn't have before cse. */
3450 alpha_split_conditional_move (enum rtx_code code, rtx dest, rtx cond,
3451 rtx t_rtx, rtx f_rtx)
3453 HOST_WIDE_INT t, f, diff;
3454 enum machine_mode mode;
3455 rtx target, subtarget, tmp;
3457 mode = GET_MODE (dest);
3458 t = INTVAL (t_rtx);
3459 f = INTVAL (f_rtx);
3460 diff = t - f;
3462 if (((code == NE || code == EQ) && diff < 0)
3463 || (code == GE || code == GT))
3465 code = reverse_condition (code);
3466 diff = t, t = f, f = diff;
3467 diff = t - f;
3470 subtarget = target = dest;
3471 if (mode != DImode)
3473 target = gen_lowpart (DImode, dest);
3474 if (! no_new_pseudos)
3475 subtarget = gen_reg_rtx (DImode);
3476 else
3477 subtarget = target;
3479 /* Below, we must be careful to use copy_rtx on target and subtarget
3480 in intermediate insns, as they may be a subreg rtx, which may not
3481 be shared. */
3483 if (f == 0 && exact_log2 (diff) > 0
3484 /* On EV6, we've got enough shifters to make non-arithmatic shifts
3485 viable over a longer latency cmove. On EV5, the E0 slot is a
3486 scarce resource, and on EV4 shift has the same latency as a cmove. */
3487 && (diff <= 8 || alpha_cpu == PROCESSOR_EV6))
3489 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3490 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3492 tmp = gen_rtx_ASHIFT (DImode, copy_rtx (subtarget),
3493 GEN_INT (exact_log2 (t)));
3494 emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3496 else if (f == 0 && t == -1)
3498 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3499 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3501 emit_insn (gen_negdi2 (target, copy_rtx (subtarget)));
3503 else if (diff == 1 || diff == 4 || diff == 8)
3505 rtx add_op;
3507 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3508 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3510 if (diff == 1)
3511 emit_insn (gen_adddi3 (target, copy_rtx (subtarget), GEN_INT (f)));
3512 else
3514 add_op = GEN_INT (f);
3515 if (sext_add_operand (add_op, mode))
3517 tmp = gen_rtx_MULT (DImode, copy_rtx (subtarget),
3518 GEN_INT (diff));
3519 tmp = gen_rtx_PLUS (DImode, tmp, add_op);
3520 emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3522 else
3523 return 0;
3526 else
3527 return 0;
3529 return 1;
3532 /* Look up the function X_floating library function name for the
3533 given operation. */
3535 static const char *
3536 alpha_lookup_xfloating_lib_func (enum rtx_code code)
3538 struct xfloating_op
3540 const enum rtx_code code;
3541 const char *const func;
3544 static const struct xfloating_op vms_xfloating_ops[] =
3546 { PLUS, "OTS$ADD_X" },
3547 { MINUS, "OTS$SUB_X" },
3548 { MULT, "OTS$MUL_X" },
3549 { DIV, "OTS$DIV_X" },
3550 { EQ, "OTS$EQL_X" },
3551 { NE, "OTS$NEQ_X" },
3552 { LT, "OTS$LSS_X" },
3553 { LE, "OTS$LEQ_X" },
3554 { GT, "OTS$GTR_X" },
3555 { GE, "OTS$GEQ_X" },
3556 { FIX, "OTS$CVTXQ" },
3557 { FLOAT, "OTS$CVTQX" },
3558 { UNSIGNED_FLOAT, "OTS$CVTQUX" },
3559 { FLOAT_EXTEND, "OTS$CVT_FLOAT_T_X" },
3560 { FLOAT_TRUNCATE, "OTS$CVT_FLOAT_X_T" },
3563 static const struct xfloating_op osf_xfloating_ops[] =
3565 { PLUS, "_OtsAddX" },
3566 { MINUS, "_OtsSubX" },
3567 { MULT, "_OtsMulX" },
3568 { DIV, "_OtsDivX" },
3569 { EQ, "_OtsEqlX" },
3570 { NE, "_OtsNeqX" },
3571 { LT, "_OtsLssX" },
3572 { LE, "_OtsLeqX" },
3573 { GT, "_OtsGtrX" },
3574 { GE, "_OtsGeqX" },
3575 { FIX, "_OtsCvtXQ" },
3576 { FLOAT, "_OtsCvtQX" },
3577 { UNSIGNED_FLOAT, "_OtsCvtQUX" },
3578 { FLOAT_EXTEND, "_OtsConvertFloatTX" },
3579 { FLOAT_TRUNCATE, "_OtsConvertFloatXT" },
3582 const struct xfloating_op *ops;
3583 const long n = ARRAY_SIZE (osf_xfloating_ops);
3584 long i;
3586 /* How irritating. Nothing to key off for the table. Hardcode
3587 knowledge of the G_floating routines. */
3588 if (TARGET_FLOAT_VAX)
3590 if (TARGET_ABI_OPEN_VMS)
3592 if (code == FLOAT_EXTEND)
3593 return "OTS$CVT_FLOAT_G_X";
3594 if (code == FLOAT_TRUNCATE)
3595 return "OTS$CVT_FLOAT_X_G";
3597 else
3599 if (code == FLOAT_EXTEND)
3600 return "_OtsConvertFloatGX";
3601 if (code == FLOAT_TRUNCATE)
3602 return "_OtsConvertFloatXG";
3606 if (TARGET_ABI_OPEN_VMS)
3607 ops = vms_xfloating_ops;
3608 else
3609 ops = osf_xfloating_ops;
3611 for (i = 0; i < n; ++i)
3612 if (ops[i].code == code)
3613 return ops[i].func;
3615 abort();
3618 /* Most X_floating operations take the rounding mode as an argument.
3619 Compute that here. */
3621 static int
3622 alpha_compute_xfloating_mode_arg (enum rtx_code code,
3623 enum alpha_fp_rounding_mode round)
3625 int mode;
3627 switch (round)
3629 case ALPHA_FPRM_NORM:
3630 mode = 2;
3631 break;
3632 case ALPHA_FPRM_MINF:
3633 mode = 1;
3634 break;
3635 case ALPHA_FPRM_CHOP:
3636 mode = 0;
3637 break;
3638 case ALPHA_FPRM_DYN:
3639 mode = 4;
3640 break;
3641 default:
3642 abort ();
3644 /* XXX For reference, round to +inf is mode = 3. */
3647 if (code == FLOAT_TRUNCATE && alpha_fptm == ALPHA_FPTM_N)
3648 mode |= 0x10000;
3650 return mode;
3653 /* Emit an X_floating library function call.
3655 Note that these functions do not follow normal calling conventions:
3656 TFmode arguments are passed in two integer registers (as opposed to
3657 indirect); TFmode return values appear in R16+R17.
3659 FUNC is the function name to call.
3660 TARGET is where the output belongs.
3661 OPERANDS are the inputs.
3662 NOPERANDS is the count of inputs.
3663 EQUIV is the expression equivalent for the function.
3666 static void
3667 alpha_emit_xfloating_libcall (const char *func, rtx target, rtx operands[],
3668 int noperands, rtx equiv)
3670 rtx usage = NULL_RTX, tmp, reg;
3671 int regno = 16, i;
3673 start_sequence ();
3675 for (i = 0; i < noperands; ++i)
3677 switch (GET_MODE (operands[i]))
3679 case TFmode:
3680 reg = gen_rtx_REG (TFmode, regno);
3681 regno += 2;
3682 break;
3684 case DFmode:
3685 reg = gen_rtx_REG (DFmode, regno + 32);
3686 regno += 1;
3687 break;
3689 case VOIDmode:
3690 if (GET_CODE (operands[i]) != CONST_INT)
3691 abort ();
3692 /* FALLTHRU */
3693 case DImode:
3694 reg = gen_rtx_REG (DImode, regno);
3695 regno += 1;
3696 break;
3698 default:
3699 abort ();
3702 emit_move_insn (reg, operands[i]);
3703 usage = alloc_EXPR_LIST (0, gen_rtx_USE (VOIDmode, reg), usage);
3706 switch (GET_MODE (target))
3708 case TFmode:
3709 reg = gen_rtx_REG (TFmode, 16);
3710 break;
3711 case DFmode:
3712 reg = gen_rtx_REG (DFmode, 32);
3713 break;
3714 case DImode:
3715 reg = gen_rtx_REG (DImode, 0);
3716 break;
3717 default:
3718 abort ();
3721 tmp = gen_rtx_MEM (QImode, init_one_libfunc (func));
3722 tmp = emit_call_insn (GEN_CALL_VALUE (reg, tmp, const0_rtx,
3723 const0_rtx, const0_rtx));
3724 CALL_INSN_FUNCTION_USAGE (tmp) = usage;
3726 tmp = get_insns ();
3727 end_sequence ();
3729 emit_libcall_block (tmp, target, reg, equiv);
3732 /* Emit an X_floating library function call for arithmetic (+,-,*,/). */
3734 void
3735 alpha_emit_xfloating_arith (enum rtx_code code, rtx operands[])
3737 const char *func;
3738 int mode;
3739 rtx out_operands[3];
3741 func = alpha_lookup_xfloating_lib_func (code);
3742 mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3744 out_operands[0] = operands[1];
3745 out_operands[1] = operands[2];
3746 out_operands[2] = GEN_INT (mode);
3747 alpha_emit_xfloating_libcall (func, operands[0], out_operands, 3,
3748 gen_rtx_fmt_ee (code, TFmode, operands[1],
3749 operands[2]));
3752 /* Emit an X_floating library function call for a comparison. */
3754 static rtx
3755 alpha_emit_xfloating_compare (enum rtx_code code, rtx op0, rtx op1)
3757 const char *func;
3758 rtx out, operands[2];
3760 func = alpha_lookup_xfloating_lib_func (code);
3762 operands[0] = op0;
3763 operands[1] = op1;
3764 out = gen_reg_rtx (DImode);
3766 /* ??? Strange mode for equiv because what's actually returned
3767 is -1,0,1, not a proper boolean value. */
3768 alpha_emit_xfloating_libcall (func, out, operands, 2,
3769 gen_rtx_fmt_ee (code, CCmode, op0, op1));
3771 return out;
3774 /* Emit an X_floating library function call for a conversion. */
3776 void
3777 alpha_emit_xfloating_cvt (enum rtx_code code, rtx operands[])
3779 int noperands = 1, mode;
3780 rtx out_operands[2];
3781 const char *func;
3783 func = alpha_lookup_xfloating_lib_func (code);
3785 out_operands[0] = operands[1];
3787 switch (code)
3789 case FIX:
3790 mode = alpha_compute_xfloating_mode_arg (code, ALPHA_FPRM_CHOP);
3791 out_operands[1] = GEN_INT (mode);
3792 noperands = 2;
3793 break;
3794 case FLOAT_TRUNCATE:
3795 mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3796 out_operands[1] = GEN_INT (mode);
3797 noperands = 2;
3798 break;
3799 default:
3800 break;
3803 alpha_emit_xfloating_libcall (func, operands[0], out_operands, noperands,
3804 gen_rtx_fmt_e (code, GET_MODE (operands[0]),
3805 operands[1]));
3808 /* Split a TFmode OP[1] into DImode OP[2,3] and likewise for
3809 OP[0] into OP[0,1]. Naturally, output operand ordering is
3810 little-endian. */
3812 void
3813 alpha_split_tfmode_pair (rtx operands[4])
3815 if (GET_CODE (operands[1]) == REG)
3817 operands[3] = gen_rtx_REG (DImode, REGNO (operands[1]) + 1);
3818 operands[2] = gen_rtx_REG (DImode, REGNO (operands[1]));
3820 else if (GET_CODE (operands[1]) == MEM)
3822 operands[3] = adjust_address (operands[1], DImode, 8);
3823 operands[2] = adjust_address (operands[1], DImode, 0);
3825 else if (operands[1] == CONST0_RTX (TFmode))
3826 operands[2] = operands[3] = const0_rtx;
3827 else
3828 abort ();
3830 if (GET_CODE (operands[0]) == REG)
3832 operands[1] = gen_rtx_REG (DImode, REGNO (operands[0]) + 1);
3833 operands[0] = gen_rtx_REG (DImode, REGNO (operands[0]));
3835 else if (GET_CODE (operands[0]) == MEM)
3837 operands[1] = adjust_address (operands[0], DImode, 8);
3838 operands[0] = adjust_address (operands[0], DImode, 0);
3840 else
3841 abort ();
3844 /* Implement negtf2 or abstf2. Op0 is destination, op1 is source,
3845 op2 is a register containing the sign bit, operation is the
3846 logical operation to be performed. */
3848 void
3849 alpha_split_tfmode_frobsign (rtx operands[3], rtx (*operation) (rtx, rtx, rtx))
3851 rtx high_bit = operands[2];
3852 rtx scratch;
3853 int move;
3855 alpha_split_tfmode_pair (operands);
3857 /* Detect three flavors of operand overlap. */
3858 move = 1;
3859 if (rtx_equal_p (operands[0], operands[2]))
3860 move = 0;
3861 else if (rtx_equal_p (operands[1], operands[2]))
3863 if (rtx_equal_p (operands[0], high_bit))
3864 move = 2;
3865 else
3866 move = -1;
3869 if (move < 0)
3870 emit_move_insn (operands[0], operands[2]);
3872 /* ??? If the destination overlaps both source tf and high_bit, then
3873 assume source tf is dead in its entirety and use the other half
3874 for a scratch register. Otherwise "scratch" is just the proper
3875 destination register. */
3876 scratch = operands[move < 2 ? 1 : 3];
3878 emit_insn ((*operation) (scratch, high_bit, operands[3]));
3880 if (move > 0)
3882 emit_move_insn (operands[0], operands[2]);
3883 if (move > 1)
3884 emit_move_insn (operands[1], scratch);
3888 /* Use ext[wlq][lh] as the Architecture Handbook describes for extracting
3889 unaligned data:
3891 unsigned: signed:
3892 word: ldq_u r1,X(r11) ldq_u r1,X(r11)
3893 ldq_u r2,X+1(r11) ldq_u r2,X+1(r11)
3894 lda r3,X(r11) lda r3,X+2(r11)
3895 extwl r1,r3,r1 extql r1,r3,r1
3896 extwh r2,r3,r2 extqh r2,r3,r2
3897 or r1.r2.r1 or r1,r2,r1
3898 sra r1,48,r1
3900 long: ldq_u r1,X(r11) ldq_u r1,X(r11)
3901 ldq_u r2,X+3(r11) ldq_u r2,X+3(r11)
3902 lda r3,X(r11) lda r3,X(r11)
3903 extll r1,r3,r1 extll r1,r3,r1
3904 extlh r2,r3,r2 extlh r2,r3,r2
3905 or r1.r2.r1 addl r1,r2,r1
3907 quad: ldq_u r1,X(r11)
3908 ldq_u r2,X+7(r11)
3909 lda r3,X(r11)
3910 extql r1,r3,r1
3911 extqh r2,r3,r2
3912 or r1.r2.r1
3915 void
3916 alpha_expand_unaligned_load (rtx tgt, rtx mem, HOST_WIDE_INT size,
3917 HOST_WIDE_INT ofs, int sign)
3919 rtx meml, memh, addr, extl, exth, tmp, mema;
3920 enum machine_mode mode;
3922 meml = gen_reg_rtx (DImode);
3923 memh = gen_reg_rtx (DImode);
3924 addr = gen_reg_rtx (DImode);
3925 extl = gen_reg_rtx (DImode);
3926 exth = gen_reg_rtx (DImode);
3928 mema = XEXP (mem, 0);
3929 if (GET_CODE (mema) == LO_SUM)
3930 mema = force_reg (Pmode, mema);
3932 /* AND addresses cannot be in any alias set, since they may implicitly
3933 alias surrounding code. Ideally we'd have some alias set that
3934 covered all types except those with alignment 8 or higher. */
3936 tmp = change_address (mem, DImode,
3937 gen_rtx_AND (DImode,
3938 plus_constant (mema, ofs),
3939 GEN_INT (-8)));
3940 set_mem_alias_set (tmp, 0);
3941 emit_move_insn (meml, tmp);
3943 tmp = change_address (mem, DImode,
3944 gen_rtx_AND (DImode,
3945 plus_constant (mema, ofs + size - 1),
3946 GEN_INT (-8)));
3947 set_mem_alias_set (tmp, 0);
3948 emit_move_insn (memh, tmp);
3950 if (WORDS_BIG_ENDIAN && sign && (size == 2 || size == 4))
3952 emit_move_insn (addr, plus_constant (mema, -1));
3954 emit_insn (gen_extqh_be (extl, meml, addr));
3955 emit_insn (gen_extxl_be (exth, memh, GEN_INT (64), addr));
3957 addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
3958 addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (64 - size*8),
3959 addr, 1, OPTAB_WIDEN);
3961 else if (sign && size == 2)
3963 emit_move_insn (addr, plus_constant (mema, ofs+2));
3965 emit_insn (gen_extxl_le (extl, meml, GEN_INT (64), addr));
3966 emit_insn (gen_extqh_le (exth, memh, addr));
3968 /* We must use tgt here for the target. Alpha-vms port fails if we use
3969 addr for the target, because addr is marked as a pointer and combine
3970 knows that pointers are always sign-extended 32 bit values. */
3971 addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
3972 addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (48),
3973 addr, 1, OPTAB_WIDEN);
3975 else
3977 if (WORDS_BIG_ENDIAN)
3979 emit_move_insn (addr, plus_constant (mema, ofs+size-1));
3980 switch ((int) size)
3982 case 2:
3983 emit_insn (gen_extwh_be (extl, meml, addr));
3984 mode = HImode;
3985 break;
3987 case 4:
3988 emit_insn (gen_extlh_be (extl, meml, addr));
3989 mode = SImode;
3990 break;
3992 case 8:
3993 emit_insn (gen_extqh_be (extl, meml, addr));
3994 mode = DImode;
3995 break;
3997 default:
3998 abort ();
4000 emit_insn (gen_extxl_be (exth, memh, GEN_INT (size*8), addr));
4002 else
4004 emit_move_insn (addr, plus_constant (mema, ofs));
4005 emit_insn (gen_extxl_le (extl, meml, GEN_INT (size*8), addr));
4006 switch ((int) size)
4008 case 2:
4009 emit_insn (gen_extwh_le (exth, memh, addr));
4010 mode = HImode;
4011 break;
4013 case 4:
4014 emit_insn (gen_extlh_le (exth, memh, addr));
4015 mode = SImode;
4016 break;
4018 case 8:
4019 emit_insn (gen_extqh_le (exth, memh, addr));
4020 mode = DImode;
4021 break;
4023 default:
4024 abort();
4028 addr = expand_binop (mode, ior_optab, gen_lowpart (mode, extl),
4029 gen_lowpart (mode, exth), gen_lowpart (mode, tgt),
4030 sign, OPTAB_WIDEN);
4033 if (addr != tgt)
4034 emit_move_insn (tgt, gen_lowpart(GET_MODE (tgt), addr));
4037 /* Similarly, use ins and msk instructions to perform unaligned stores. */
4039 void
4040 alpha_expand_unaligned_store (rtx dst, rtx src,
4041 HOST_WIDE_INT size, HOST_WIDE_INT ofs)
4043 rtx dstl, dsth, addr, insl, insh, meml, memh, dsta;
4045 dstl = gen_reg_rtx (DImode);
4046 dsth = gen_reg_rtx (DImode);
4047 insl = gen_reg_rtx (DImode);
4048 insh = gen_reg_rtx (DImode);
4050 dsta = XEXP (dst, 0);
4051 if (GET_CODE (dsta) == LO_SUM)
4052 dsta = force_reg (Pmode, dsta);
4054 /* AND addresses cannot be in any alias set, since they may implicitly
4055 alias surrounding code. Ideally we'd have some alias set that
4056 covered all types except those with alignment 8 or higher. */
4058 meml = change_address (dst, DImode,
4059 gen_rtx_AND (DImode,
4060 plus_constant (dsta, ofs),
4061 GEN_INT (-8)));
4062 set_mem_alias_set (meml, 0);
4064 memh = change_address (dst, DImode,
4065 gen_rtx_AND (DImode,
4066 plus_constant (dsta, ofs + size - 1),
4067 GEN_INT (-8)));
4068 set_mem_alias_set (memh, 0);
4070 emit_move_insn (dsth, memh);
4071 emit_move_insn (dstl, meml);
4072 if (WORDS_BIG_ENDIAN)
4074 addr = copy_addr_to_reg (plus_constant (dsta, ofs+size-1));
4076 if (src != const0_rtx)
4078 switch ((int) size)
4080 case 2:
4081 emit_insn (gen_inswl_be (insh, gen_lowpart (HImode,src), addr));
4082 break;
4083 case 4:
4084 emit_insn (gen_insll_be (insh, gen_lowpart (SImode,src), addr));
4085 break;
4086 case 8:
4087 emit_insn (gen_insql_be (insh, gen_lowpart (DImode,src), addr));
4088 break;
4090 emit_insn (gen_insxh (insl, gen_lowpart (DImode, src),
4091 GEN_INT (size*8), addr));
4094 switch ((int) size)
4096 case 2:
4097 emit_insn (gen_mskxl_be (dsth, dsth, GEN_INT (0xffff), addr));
4098 break;
4099 case 4:
4101 rtx msk = immed_double_const (0xffffffff, 0, DImode);
4102 emit_insn (gen_mskxl_be (dsth, dsth, msk, addr));
4103 break;
4105 case 8:
4106 emit_insn (gen_mskxl_be (dsth, dsth, constm1_rtx, addr));
4107 break;
4110 emit_insn (gen_mskxh (dstl, dstl, GEN_INT (size*8), addr));
4112 else
4114 addr = copy_addr_to_reg (plus_constant (dsta, ofs));
4116 if (src != const0_rtx)
4118 emit_insn (gen_insxh (insh, gen_lowpart (DImode, src),
4119 GEN_INT (size*8), addr));
4121 switch ((int) size)
4123 case 2:
4124 emit_insn (gen_inswl_le (insl, gen_lowpart (HImode, src), addr));
4125 break;
4126 case 4:
4127 emit_insn (gen_insll_le (insl, gen_lowpart (SImode, src), addr));
4128 break;
4129 case 8:
4130 emit_insn (gen_insql_le (insl, src, addr));
4131 break;
4135 emit_insn (gen_mskxh (dsth, dsth, GEN_INT (size*8), addr));
4137 switch ((int) size)
4139 case 2:
4140 emit_insn (gen_mskxl_le (dstl, dstl, GEN_INT (0xffff), addr));
4141 break;
4142 case 4:
4144 rtx msk = immed_double_const (0xffffffff, 0, DImode);
4145 emit_insn (gen_mskxl_le (dstl, dstl, msk, addr));
4146 break;
4148 case 8:
4149 emit_insn (gen_mskxl_le (dstl, dstl, constm1_rtx, addr));
4150 break;
4154 if (src != const0_rtx)
4156 dsth = expand_binop (DImode, ior_optab, insh, dsth, dsth, 0, OPTAB_WIDEN);
4157 dstl = expand_binop (DImode, ior_optab, insl, dstl, dstl, 0, OPTAB_WIDEN);
4160 if (WORDS_BIG_ENDIAN)
4162 emit_move_insn (meml, dstl);
4163 emit_move_insn (memh, dsth);
4165 else
4167 /* Must store high before low for degenerate case of aligned. */
4168 emit_move_insn (memh, dsth);
4169 emit_move_insn (meml, dstl);
4173 /* The block move code tries to maximize speed by separating loads and
4174 stores at the expense of register pressure: we load all of the data
4175 before we store it back out. There are two secondary effects worth
4176 mentioning, that this speeds copying to/from aligned and unaligned
4177 buffers, and that it makes the code significantly easier to write. */
4179 #define MAX_MOVE_WORDS 8
4181 /* Load an integral number of consecutive unaligned quadwords. */
4183 static void
4184 alpha_expand_unaligned_load_words (rtx *out_regs, rtx smem,
4185 HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4187 rtx const im8 = GEN_INT (-8);
4188 rtx const i64 = GEN_INT (64);
4189 rtx ext_tmps[MAX_MOVE_WORDS], data_regs[MAX_MOVE_WORDS+1];
4190 rtx sreg, areg, tmp, smema;
4191 HOST_WIDE_INT i;
4193 smema = XEXP (smem, 0);
4194 if (GET_CODE (smema) == LO_SUM)
4195 smema = force_reg (Pmode, smema);
4197 /* Generate all the tmp registers we need. */
4198 for (i = 0; i < words; ++i)
4200 data_regs[i] = out_regs[i];
4201 ext_tmps[i] = gen_reg_rtx (DImode);
4203 data_regs[words] = gen_reg_rtx (DImode);
4205 if (ofs != 0)
4206 smem = adjust_address (smem, GET_MODE (smem), ofs);
4208 /* Load up all of the source data. */
4209 for (i = 0; i < words; ++i)
4211 tmp = change_address (smem, DImode,
4212 gen_rtx_AND (DImode,
4213 plus_constant (smema, 8*i),
4214 im8));
4215 set_mem_alias_set (tmp, 0);
4216 emit_move_insn (data_regs[i], tmp);
4219 tmp = change_address (smem, DImode,
4220 gen_rtx_AND (DImode,
4221 plus_constant (smema, 8*words - 1),
4222 im8));
4223 set_mem_alias_set (tmp, 0);
4224 emit_move_insn (data_regs[words], tmp);
4226 /* Extract the half-word fragments. Unfortunately DEC decided to make
4227 extxh with offset zero a noop instead of zeroing the register, so
4228 we must take care of that edge condition ourselves with cmov. */
4230 sreg = copy_addr_to_reg (smema);
4231 areg = expand_binop (DImode, and_optab, sreg, GEN_INT (7), NULL,
4232 1, OPTAB_WIDEN);
4233 if (WORDS_BIG_ENDIAN)
4234 emit_move_insn (sreg, plus_constant (sreg, 7));
4235 for (i = 0; i < words; ++i)
4237 if (WORDS_BIG_ENDIAN)
4239 emit_insn (gen_extqh_be (data_regs[i], data_regs[i], sreg));
4240 emit_insn (gen_extxl_be (ext_tmps[i], data_regs[i+1], i64, sreg));
4242 else
4244 emit_insn (gen_extxl_le (data_regs[i], data_regs[i], i64, sreg));
4245 emit_insn (gen_extqh_le (ext_tmps[i], data_regs[i+1], sreg));
4247 emit_insn (gen_rtx_SET (VOIDmode, ext_tmps[i],
4248 gen_rtx_IF_THEN_ELSE (DImode,
4249 gen_rtx_EQ (DImode, areg,
4250 const0_rtx),
4251 const0_rtx, ext_tmps[i])));
4254 /* Merge the half-words into whole words. */
4255 for (i = 0; i < words; ++i)
4257 out_regs[i] = expand_binop (DImode, ior_optab, data_regs[i],
4258 ext_tmps[i], data_regs[i], 1, OPTAB_WIDEN);
4262 /* Store an integral number of consecutive unaligned quadwords. DATA_REGS
4263 may be NULL to store zeros. */
4265 static void
4266 alpha_expand_unaligned_store_words (rtx *data_regs, rtx dmem,
4267 HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4269 rtx const im8 = GEN_INT (-8);
4270 rtx const i64 = GEN_INT (64);
4271 rtx ins_tmps[MAX_MOVE_WORDS];
4272 rtx st_tmp_1, st_tmp_2, dreg;
4273 rtx st_addr_1, st_addr_2, dmema;
4274 HOST_WIDE_INT i;
4276 dmema = XEXP (dmem, 0);
4277 if (GET_CODE (dmema) == LO_SUM)
4278 dmema = force_reg (Pmode, dmema);
4280 /* Generate all the tmp registers we need. */
4281 if (data_regs != NULL)
4282 for (i = 0; i < words; ++i)
4283 ins_tmps[i] = gen_reg_rtx(DImode);
4284 st_tmp_1 = gen_reg_rtx(DImode);
4285 st_tmp_2 = gen_reg_rtx(DImode);
4287 if (ofs != 0)
4288 dmem = adjust_address (dmem, GET_MODE (dmem), ofs);
4290 st_addr_2 = change_address (dmem, DImode,
4291 gen_rtx_AND (DImode,
4292 plus_constant (dmema, words*8 - 1),
4293 im8));
4294 set_mem_alias_set (st_addr_2, 0);
4296 st_addr_1 = change_address (dmem, DImode,
4297 gen_rtx_AND (DImode, dmema, im8));
4298 set_mem_alias_set (st_addr_1, 0);
4300 /* Load up the destination end bits. */
4301 emit_move_insn (st_tmp_2, st_addr_2);
4302 emit_move_insn (st_tmp_1, st_addr_1);
4304 /* Shift the input data into place. */
4305 dreg = copy_addr_to_reg (dmema);
4306 if (WORDS_BIG_ENDIAN)
4307 emit_move_insn (dreg, plus_constant (dreg, 7));
4308 if (data_regs != NULL)
4310 for (i = words-1; i >= 0; --i)
4312 if (WORDS_BIG_ENDIAN)
4314 emit_insn (gen_insql_be (ins_tmps[i], data_regs[i], dreg));
4315 emit_insn (gen_insxh (data_regs[i], data_regs[i], i64, dreg));
4317 else
4319 emit_insn (gen_insxh (ins_tmps[i], data_regs[i], i64, dreg));
4320 emit_insn (gen_insql_le (data_regs[i], data_regs[i], dreg));
4323 for (i = words-1; i > 0; --i)
4325 ins_tmps[i-1] = expand_binop (DImode, ior_optab, data_regs[i],
4326 ins_tmps[i-1], ins_tmps[i-1], 1,
4327 OPTAB_WIDEN);
4331 /* Split and merge the ends with the destination data. */
4332 if (WORDS_BIG_ENDIAN)
4334 emit_insn (gen_mskxl_be (st_tmp_2, st_tmp_2, constm1_rtx, dreg));
4335 emit_insn (gen_mskxh (st_tmp_1, st_tmp_1, i64, dreg));
4337 else
4339 emit_insn (gen_mskxh (st_tmp_2, st_tmp_2, i64, dreg));
4340 emit_insn (gen_mskxl_le (st_tmp_1, st_tmp_1, constm1_rtx, dreg));
4343 if (data_regs != NULL)
4345 st_tmp_2 = expand_binop (DImode, ior_optab, st_tmp_2, ins_tmps[words-1],
4346 st_tmp_2, 1, OPTAB_WIDEN);
4347 st_tmp_1 = expand_binop (DImode, ior_optab, st_tmp_1, data_regs[0],
4348 st_tmp_1, 1, OPTAB_WIDEN);
4351 /* Store it all. */
4352 if (WORDS_BIG_ENDIAN)
4353 emit_move_insn (st_addr_1, st_tmp_1);
4354 else
4355 emit_move_insn (st_addr_2, st_tmp_2);
4356 for (i = words-1; i > 0; --i)
4358 rtx tmp = change_address (dmem, DImode,
4359 gen_rtx_AND (DImode,
4360 plus_constant(dmema,
4361 WORDS_BIG_ENDIAN ? i*8-1 : i*8),
4362 im8));
4363 set_mem_alias_set (tmp, 0);
4364 emit_move_insn (tmp, data_regs ? ins_tmps[i-1] : const0_rtx);
4366 if (WORDS_BIG_ENDIAN)
4367 emit_move_insn (st_addr_2, st_tmp_2);
4368 else
4369 emit_move_insn (st_addr_1, st_tmp_1);
4373 /* Expand string/block move operations.
4375 operands[0] is the pointer to the destination.
4376 operands[1] is the pointer to the source.
4377 operands[2] is the number of bytes to move.
4378 operands[3] is the alignment. */
4381 alpha_expand_block_move (rtx operands[])
4383 rtx bytes_rtx = operands[2];
4384 rtx align_rtx = operands[3];
4385 HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4386 HOST_WIDE_INT bytes = orig_bytes;
4387 HOST_WIDE_INT src_align = INTVAL (align_rtx) * BITS_PER_UNIT;
4388 HOST_WIDE_INT dst_align = src_align;
4389 rtx orig_src = operands[1];
4390 rtx orig_dst = operands[0];
4391 rtx data_regs[2 * MAX_MOVE_WORDS + 16];
4392 rtx tmp;
4393 unsigned int i, words, ofs, nregs = 0;
4395 if (orig_bytes <= 0)
4396 return 1;
4397 else if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4398 return 0;
4400 /* Look for additional alignment information from recorded register info. */
4402 tmp = XEXP (orig_src, 0);
4403 if (GET_CODE (tmp) == REG)
4404 src_align = MAX (src_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4405 else if (GET_CODE (tmp) == PLUS
4406 && GET_CODE (XEXP (tmp, 0)) == REG
4407 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4409 unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4410 unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4412 if (a > src_align)
4414 if (a >= 64 && c % 8 == 0)
4415 src_align = 64;
4416 else if (a >= 32 && c % 4 == 0)
4417 src_align = 32;
4418 else if (a >= 16 && c % 2 == 0)
4419 src_align = 16;
4423 tmp = XEXP (orig_dst, 0);
4424 if (GET_CODE (tmp) == REG)
4425 dst_align = MAX (dst_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4426 else if (GET_CODE (tmp) == PLUS
4427 && GET_CODE (XEXP (tmp, 0)) == REG
4428 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4430 unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4431 unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4433 if (a > dst_align)
4435 if (a >= 64 && c % 8 == 0)
4436 dst_align = 64;
4437 else if (a >= 32 && c % 4 == 0)
4438 dst_align = 32;
4439 else if (a >= 16 && c % 2 == 0)
4440 dst_align = 16;
4444 /* Load the entire block into registers. */
4445 if (GET_CODE (XEXP (orig_src, 0)) == ADDRESSOF)
4447 enum machine_mode mode;
4449 tmp = XEXP (XEXP (orig_src, 0), 0);
4451 /* Don't use the existing register if we're reading more than
4452 is held in the register. Nor if there is not a mode that
4453 handles the exact size. */
4454 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1);
4455 if (mode != BLKmode
4456 && GET_MODE_SIZE (GET_MODE (tmp)) >= bytes)
4458 if (mode == TImode)
4460 data_regs[nregs] = gen_lowpart (DImode, tmp);
4461 data_regs[nregs + 1] = gen_highpart (DImode, tmp);
4462 nregs += 2;
4464 else
4465 data_regs[nregs++] = gen_lowpart (mode, tmp);
4467 goto src_done;
4470 /* No appropriate mode; fall back on memory. */
4471 orig_src = replace_equiv_address (orig_src,
4472 copy_addr_to_reg (XEXP (orig_src, 0)));
4473 src_align = GET_MODE_BITSIZE (GET_MODE (tmp));
4476 ofs = 0;
4477 if (src_align >= 64 && bytes >= 8)
4479 words = bytes / 8;
4481 for (i = 0; i < words; ++i)
4482 data_regs[nregs + i] = gen_reg_rtx (DImode);
4484 for (i = 0; i < words; ++i)
4485 emit_move_insn (data_regs[nregs + i],
4486 adjust_address (orig_src, DImode, ofs + i * 8));
4488 nregs += words;
4489 bytes -= words * 8;
4490 ofs += words * 8;
4493 if (src_align >= 32 && bytes >= 4)
4495 words = bytes / 4;
4497 for (i = 0; i < words; ++i)
4498 data_regs[nregs + i] = gen_reg_rtx (SImode);
4500 for (i = 0; i < words; ++i)
4501 emit_move_insn (data_regs[nregs + i],
4502 adjust_address (orig_src, SImode, ofs + i * 4));
4504 nregs += words;
4505 bytes -= words * 4;
4506 ofs += words * 4;
4509 if (bytes >= 8)
4511 words = bytes / 8;
4513 for (i = 0; i < words+1; ++i)
4514 data_regs[nregs + i] = gen_reg_rtx (DImode);
4516 alpha_expand_unaligned_load_words (data_regs + nregs, orig_src,
4517 words, ofs);
4519 nregs += words;
4520 bytes -= words * 8;
4521 ofs += words * 8;
4524 if (! TARGET_BWX && bytes >= 4)
4526 data_regs[nregs++] = tmp = gen_reg_rtx (SImode);
4527 alpha_expand_unaligned_load (tmp, orig_src, 4, ofs, 0);
4528 bytes -= 4;
4529 ofs += 4;
4532 if (bytes >= 2)
4534 if (src_align >= 16)
4536 do {
4537 data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4538 emit_move_insn (tmp, adjust_address (orig_src, HImode, ofs));
4539 bytes -= 2;
4540 ofs += 2;
4541 } while (bytes >= 2);
4543 else if (! TARGET_BWX)
4545 data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4546 alpha_expand_unaligned_load (tmp, orig_src, 2, ofs, 0);
4547 bytes -= 2;
4548 ofs += 2;
4552 while (bytes > 0)
4554 data_regs[nregs++] = tmp = gen_reg_rtx (QImode);
4555 emit_move_insn (tmp, adjust_address (orig_src, QImode, ofs));
4556 bytes -= 1;
4557 ofs += 1;
4560 src_done:
4562 if (nregs > ARRAY_SIZE (data_regs))
4563 abort ();
4565 /* Now save it back out again. */
4567 i = 0, ofs = 0;
4569 if (GET_CODE (XEXP (orig_dst, 0)) == ADDRESSOF)
4571 enum machine_mode mode;
4572 tmp = XEXP (XEXP (orig_dst, 0), 0);
4574 mode = mode_for_size (orig_bytes * BITS_PER_UNIT, MODE_INT, 1);
4575 if (GET_MODE (tmp) == mode)
4577 if (nregs == 1)
4579 emit_move_insn (tmp, data_regs[0]);
4580 i = 1;
4581 goto dst_done;
4584 else if (nregs == 2 && mode == TImode)
4586 /* Undo the subregging done above when copying between
4587 two TImode registers. */
4588 if (GET_CODE (data_regs[0]) == SUBREG
4589 && GET_MODE (SUBREG_REG (data_regs[0])) == TImode)
4590 emit_move_insn (tmp, SUBREG_REG (data_regs[0]));
4591 else
4593 rtx seq;
4595 start_sequence ();
4596 emit_move_insn (gen_lowpart (DImode, tmp), data_regs[0]);
4597 emit_move_insn (gen_highpart (DImode, tmp), data_regs[1]);
4598 seq = get_insns ();
4599 end_sequence ();
4601 emit_no_conflict_block (seq, tmp, data_regs[0],
4602 data_regs[1], NULL_RTX);
4605 i = 2;
4606 goto dst_done;
4610 /* ??? If nregs > 1, consider reconstructing the word in regs. */
4611 /* ??? Optimize mode < dst_mode with strict_low_part. */
4613 /* No appropriate mode; fall back on memory. We can speed things
4614 up by recognizing extra alignment information. */
4615 orig_dst = replace_equiv_address (orig_dst,
4616 copy_addr_to_reg (XEXP (orig_dst, 0)));
4617 dst_align = GET_MODE_BITSIZE (GET_MODE (tmp));
4620 /* Write out the data in whatever chunks reading the source allowed. */
4621 if (dst_align >= 64)
4623 while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4625 emit_move_insn (adjust_address (orig_dst, DImode, ofs),
4626 data_regs[i]);
4627 ofs += 8;
4628 i++;
4632 if (dst_align >= 32)
4634 /* If the source has remaining DImode regs, write them out in
4635 two pieces. */
4636 while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4638 tmp = expand_binop (DImode, lshr_optab, data_regs[i], GEN_INT (32),
4639 NULL_RTX, 1, OPTAB_WIDEN);
4641 emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4642 gen_lowpart (SImode, data_regs[i]));
4643 emit_move_insn (adjust_address (orig_dst, SImode, ofs + 4),
4644 gen_lowpart (SImode, tmp));
4645 ofs += 8;
4646 i++;
4649 while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4651 emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4652 data_regs[i]);
4653 ofs += 4;
4654 i++;
4658 if (i < nregs && GET_MODE (data_regs[i]) == DImode)
4660 /* Write out a remaining block of words using unaligned methods. */
4662 for (words = 1; i + words < nregs; words++)
4663 if (GET_MODE (data_regs[i + words]) != DImode)
4664 break;
4666 if (words == 1)
4667 alpha_expand_unaligned_store (orig_dst, data_regs[i], 8, ofs);
4668 else
4669 alpha_expand_unaligned_store_words (data_regs + i, orig_dst,
4670 words, ofs);
4672 i += words;
4673 ofs += words * 8;
4676 /* Due to the above, this won't be aligned. */
4677 /* ??? If we have more than one of these, consider constructing full
4678 words in registers and using alpha_expand_unaligned_store_words. */
4679 while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4681 alpha_expand_unaligned_store (orig_dst, data_regs[i], 4, ofs);
4682 ofs += 4;
4683 i++;
4686 if (dst_align >= 16)
4687 while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4689 emit_move_insn (adjust_address (orig_dst, HImode, ofs), data_regs[i]);
4690 i++;
4691 ofs += 2;
4693 else
4694 while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4696 alpha_expand_unaligned_store (orig_dst, data_regs[i], 2, ofs);
4697 i++;
4698 ofs += 2;
4701 while (i < nregs && GET_MODE (data_regs[i]) == QImode)
4703 emit_move_insn (adjust_address (orig_dst, QImode, ofs), data_regs[i]);
4704 i++;
4705 ofs += 1;
4708 dst_done:
4710 if (i != nregs)
4711 abort ();
4713 return 1;
4717 alpha_expand_block_clear (rtx operands[])
4719 rtx bytes_rtx = operands[1];
4720 rtx align_rtx = operands[2];
4721 HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4722 HOST_WIDE_INT bytes = orig_bytes;
4723 HOST_WIDE_INT align = INTVAL (align_rtx) * BITS_PER_UNIT;
4724 HOST_WIDE_INT alignofs = 0;
4725 rtx orig_dst = operands[0];
4726 rtx tmp;
4727 int i, words, ofs = 0;
4729 if (orig_bytes <= 0)
4730 return 1;
4731 if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4732 return 0;
4734 /* Look for stricter alignment. */
4735 tmp = XEXP (orig_dst, 0);
4736 if (GET_CODE (tmp) == REG)
4737 align = MAX (align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4738 else if (GET_CODE (tmp) == PLUS
4739 && GET_CODE (XEXP (tmp, 0)) == REG
4740 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4742 HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4743 int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4745 if (a > align)
4747 if (a >= 64)
4748 align = a, alignofs = 8 - c % 8;
4749 else if (a >= 32)
4750 align = a, alignofs = 4 - c % 4;
4751 else if (a >= 16)
4752 align = a, alignofs = 2 - c % 2;
4755 else if (GET_CODE (tmp) == ADDRESSOF)
4757 enum machine_mode mode;
4759 mode = mode_for_size (bytes * BITS_PER_UNIT, MODE_INT, 1);
4760 if (GET_MODE (XEXP (tmp, 0)) == mode)
4762 emit_move_insn (XEXP (tmp, 0), const0_rtx);
4763 return 1;
4766 /* No appropriate mode; fall back on memory. */
4767 orig_dst = replace_equiv_address (orig_dst, copy_addr_to_reg (tmp));
4768 align = GET_MODE_BITSIZE (GET_MODE (XEXP (tmp, 0)));
4771 /* Handle an unaligned prefix first. */
4773 if (alignofs > 0)
4775 #if HOST_BITS_PER_WIDE_INT >= 64
4776 /* Given that alignofs is bounded by align, the only time BWX could
4777 generate three stores is for a 7 byte fill. Prefer two individual
4778 stores over a load/mask/store sequence. */
4779 if ((!TARGET_BWX || alignofs == 7)
4780 && align >= 32
4781 && !(alignofs == 4 && bytes >= 4))
4783 enum machine_mode mode = (align >= 64 ? DImode : SImode);
4784 int inv_alignofs = (align >= 64 ? 8 : 4) - alignofs;
4785 rtx mem, tmp;
4786 HOST_WIDE_INT mask;
4788 mem = adjust_address (orig_dst, mode, ofs - inv_alignofs);
4789 set_mem_alias_set (mem, 0);
4791 mask = ~(~(HOST_WIDE_INT)0 << (inv_alignofs * 8));
4792 if (bytes < alignofs)
4794 mask |= ~(HOST_WIDE_INT)0 << ((inv_alignofs + bytes) * 8);
4795 ofs += bytes;
4796 bytes = 0;
4798 else
4800 bytes -= alignofs;
4801 ofs += alignofs;
4803 alignofs = 0;
4805 tmp = expand_binop (mode, and_optab, mem, GEN_INT (mask),
4806 NULL_RTX, 1, OPTAB_WIDEN);
4808 emit_move_insn (mem, tmp);
4810 #endif
4812 if (TARGET_BWX && (alignofs & 1) && bytes >= 1)
4814 emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
4815 bytes -= 1;
4816 ofs += 1;
4817 alignofs -= 1;
4819 if (TARGET_BWX && align >= 16 && (alignofs & 3) == 2 && bytes >= 2)
4821 emit_move_insn (adjust_address (orig_dst, HImode, ofs), const0_rtx);
4822 bytes -= 2;
4823 ofs += 2;
4824 alignofs -= 2;
4826 if (alignofs == 4 && bytes >= 4)
4828 emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4829 bytes -= 4;
4830 ofs += 4;
4831 alignofs = 0;
4834 /* If we've not used the extra lead alignment information by now,
4835 we won't be able to. Downgrade align to match what's left over. */
4836 if (alignofs > 0)
4838 alignofs = alignofs & -alignofs;
4839 align = MIN (align, alignofs * BITS_PER_UNIT);
4843 /* Handle a block of contiguous long-words. */
4845 if (align >= 64 && bytes >= 8)
4847 words = bytes / 8;
4849 for (i = 0; i < words; ++i)
4850 emit_move_insn (adjust_address (orig_dst, DImode, ofs + i * 8),
4851 const0_rtx);
4853 bytes -= words * 8;
4854 ofs += words * 8;
4857 /* If the block is large and appropriately aligned, emit a single
4858 store followed by a sequence of stq_u insns. */
4860 if (align >= 32 && bytes > 16)
4862 rtx orig_dsta;
4864 emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4865 bytes -= 4;
4866 ofs += 4;
4868 orig_dsta = XEXP (orig_dst, 0);
4869 if (GET_CODE (orig_dsta) == LO_SUM)
4870 orig_dsta = force_reg (Pmode, orig_dsta);
4872 words = bytes / 8;
4873 for (i = 0; i < words; ++i)
4875 rtx mem
4876 = change_address (orig_dst, DImode,
4877 gen_rtx_AND (DImode,
4878 plus_constant (orig_dsta, ofs + i*8),
4879 GEN_INT (-8)));
4880 set_mem_alias_set (mem, 0);
4881 emit_move_insn (mem, const0_rtx);
4884 /* Depending on the alignment, the first stq_u may have overlapped
4885 with the initial stl, which means that the last stq_u didn't
4886 write as much as it would appear. Leave those questionable bytes
4887 unaccounted for. */
4888 bytes -= words * 8 - 4;
4889 ofs += words * 8 - 4;
4892 /* Handle a smaller block of aligned words. */
4894 if ((align >= 64 && bytes == 4)
4895 || (align == 32 && bytes >= 4))
4897 words = bytes / 4;
4899 for (i = 0; i < words; ++i)
4900 emit_move_insn (adjust_address (orig_dst, SImode, ofs + i * 4),
4901 const0_rtx);
4903 bytes -= words * 4;
4904 ofs += words * 4;
4907 /* An unaligned block uses stq_u stores for as many as possible. */
4909 if (bytes >= 8)
4911 words = bytes / 8;
4913 alpha_expand_unaligned_store_words (NULL, orig_dst, words, ofs);
4915 bytes -= words * 8;
4916 ofs += words * 8;
4919 /* Next clean up any trailing pieces. */
4921 #if HOST_BITS_PER_WIDE_INT >= 64
4922 /* Count the number of bits in BYTES for which aligned stores could
4923 be emitted. */
4924 words = 0;
4925 for (i = (TARGET_BWX ? 1 : 4); i * BITS_PER_UNIT <= align ; i <<= 1)
4926 if (bytes & i)
4927 words += 1;
4929 /* If we have appropriate alignment (and it wouldn't take too many
4930 instructions otherwise), mask out the bytes we need. */
4931 if (TARGET_BWX ? words > 2 : bytes > 0)
4933 if (align >= 64)
4935 rtx mem, tmp;
4936 HOST_WIDE_INT mask;
4938 mem = adjust_address (orig_dst, DImode, ofs);
4939 set_mem_alias_set (mem, 0);
4941 mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
4943 tmp = expand_binop (DImode, and_optab, mem, GEN_INT (mask),
4944 NULL_RTX, 1, OPTAB_WIDEN);
4946 emit_move_insn (mem, tmp);
4947 return 1;
4949 else if (align >= 32 && bytes < 4)
4951 rtx mem, tmp;
4952 HOST_WIDE_INT mask;
4954 mem = adjust_address (orig_dst, SImode, ofs);
4955 set_mem_alias_set (mem, 0);
4957 mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
4959 tmp = expand_binop (SImode, and_optab, mem, GEN_INT (mask),
4960 NULL_RTX, 1, OPTAB_WIDEN);
4962 emit_move_insn (mem, tmp);
4963 return 1;
4966 #endif
4968 if (!TARGET_BWX && bytes >= 4)
4970 alpha_expand_unaligned_store (orig_dst, const0_rtx, 4, ofs);
4971 bytes -= 4;
4972 ofs += 4;
4975 if (bytes >= 2)
4977 if (align >= 16)
4979 do {
4980 emit_move_insn (adjust_address (orig_dst, HImode, ofs),
4981 const0_rtx);
4982 bytes -= 2;
4983 ofs += 2;
4984 } while (bytes >= 2);
4986 else if (! TARGET_BWX)
4988 alpha_expand_unaligned_store (orig_dst, const0_rtx, 2, ofs);
4989 bytes -= 2;
4990 ofs += 2;
4994 while (bytes > 0)
4996 emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
4997 bytes -= 1;
4998 ofs += 1;
5001 return 1;
5004 /* Returns a mask so that zap(x, value) == x & mask. */
5007 alpha_expand_zap_mask (HOST_WIDE_INT value)
5009 rtx result;
5010 int i;
5012 if (HOST_BITS_PER_WIDE_INT >= 64)
5014 HOST_WIDE_INT mask = 0;
5016 for (i = 7; i >= 0; --i)
5018 mask <<= 8;
5019 if (!((value >> i) & 1))
5020 mask |= 0xff;
5023 result = gen_int_mode (mask, DImode);
5025 else if (HOST_BITS_PER_WIDE_INT == 32)
5027 HOST_WIDE_INT mask_lo = 0, mask_hi = 0;
5029 for (i = 7; i >= 4; --i)
5031 mask_hi <<= 8;
5032 if (!((value >> i) & 1))
5033 mask_hi |= 0xff;
5036 for (i = 3; i >= 0; --i)
5038 mask_lo <<= 8;
5039 if (!((value >> i) & 1))
5040 mask_lo |= 0xff;
5043 result = immed_double_const (mask_lo, mask_hi, DImode);
5045 else
5046 abort ();
5048 return result;
5051 void
5052 alpha_expand_builtin_vector_binop (rtx (*gen) (rtx, rtx, rtx),
5053 enum machine_mode mode,
5054 rtx op0, rtx op1, rtx op2)
5056 op0 = gen_lowpart (mode, op0);
5058 if (op1 == const0_rtx)
5059 op1 = CONST0_RTX (mode);
5060 else
5061 op1 = gen_lowpart (mode, op1);
5063 if (op2 == const0_rtx)
5064 op2 = CONST0_RTX (mode);
5065 else
5066 op2 = gen_lowpart (mode, op2);
5068 emit_insn ((*gen) (op0, op1, op2));
5071 /* Adjust the cost of a scheduling dependency. Return the new cost of
5072 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
5074 static int
5075 alpha_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
5077 enum attr_type insn_type, dep_insn_type;
5079 /* If the dependence is an anti-dependence, there is no cost. For an
5080 output dependence, there is sometimes a cost, but it doesn't seem
5081 worth handling those few cases. */
5082 if (REG_NOTE_KIND (link) != 0)
5083 return cost;
5085 /* If we can't recognize the insns, we can't really do anything. */
5086 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
5087 return cost;
5089 insn_type = get_attr_type (insn);
5090 dep_insn_type = get_attr_type (dep_insn);
5092 /* Bring in the user-defined memory latency. */
5093 if (dep_insn_type == TYPE_ILD
5094 || dep_insn_type == TYPE_FLD
5095 || dep_insn_type == TYPE_LDSYM)
5096 cost += alpha_memory_latency-1;
5098 /* Everything else handled in DFA bypasses now. */
5100 return cost;
5103 /* The number of instructions that can be issued per cycle. */
5105 static int
5106 alpha_issue_rate (void)
5108 return (alpha_cpu == PROCESSOR_EV4 ? 2 : 4);
5111 static int
5112 alpha_use_dfa_pipeline_interface (void)
5114 return true;
5117 /* How many alternative schedules to try. This should be as wide as the
5118 scheduling freedom in the DFA, but no wider. Making this value too
5119 large results extra work for the scheduler.
5121 For EV4, loads can be issued to either IB0 or IB1, thus we have 2
5122 alternative schedules. For EV5, we can choose between E0/E1 and
5123 FA/FM. For EV6, an arithmatic insn can be issued to U0/U1/L0/L1. */
5125 static int
5126 alpha_multipass_dfa_lookahead (void)
5128 return (alpha_cpu == PROCESSOR_EV6 ? 4 : 2);
5131 /* Machine-specific function data. */
5133 struct machine_function GTY(())
5135 /* For unicosmk. */
5136 /* List of call information words for calls from this function. */
5137 struct rtx_def *first_ciw;
5138 struct rtx_def *last_ciw;
5139 int ciw_count;
5141 /* List of deferred case vectors. */
5142 struct rtx_def *addr_list;
5144 /* For OSF. */
5145 const char *some_ld_name;
5148 /* How to allocate a 'struct machine_function'. */
5150 static struct machine_function *
5151 alpha_init_machine_status (void)
5153 return ((struct machine_function *)
5154 ggc_alloc_cleared (sizeof (struct machine_function)));
5157 /* Functions to save and restore alpha_return_addr_rtx. */
5159 /* Start the ball rolling with RETURN_ADDR_RTX. */
5162 alpha_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
5164 if (count != 0)
5165 return const0_rtx;
5167 return get_hard_reg_initial_val (Pmode, REG_RA);
5170 /* Return or create a pseudo containing the gp value for the current
5171 function. Needed only if TARGET_LD_BUGGY_LDGP. */
5174 alpha_gp_save_rtx (void)
5176 rtx r = get_hard_reg_initial_val (DImode, 29);
5177 if (GET_CODE (r) != MEM)
5178 r = gen_mem_addressof (r, NULL_TREE, /*rescan=*/true);
5179 return r;
5182 static int
5183 alpha_ra_ever_killed (void)
5185 rtx top;
5187 if (!has_hard_reg_initial_val (Pmode, REG_RA))
5188 return regs_ever_live[REG_RA];
5190 push_topmost_sequence ();
5191 top = get_insns ();
5192 pop_topmost_sequence ();
5194 return reg_set_between_p (gen_rtx_REG (Pmode, REG_RA), top, NULL_RTX);
5198 /* Return the trap mode suffix applicable to the current
5199 instruction, or NULL. */
5201 static const char *
5202 get_trap_mode_suffix (void)
5204 enum attr_trap_suffix s = get_attr_trap_suffix (current_output_insn);
5206 switch (s)
5208 case TRAP_SUFFIX_NONE:
5209 return NULL;
5211 case TRAP_SUFFIX_SU:
5212 if (alpha_fptm >= ALPHA_FPTM_SU)
5213 return "su";
5214 return NULL;
5216 case TRAP_SUFFIX_SUI:
5217 if (alpha_fptm >= ALPHA_FPTM_SUI)
5218 return "sui";
5219 return NULL;
5221 case TRAP_SUFFIX_V_SV:
5222 switch (alpha_fptm)
5224 case ALPHA_FPTM_N:
5225 return NULL;
5226 case ALPHA_FPTM_U:
5227 return "v";
5228 case ALPHA_FPTM_SU:
5229 case ALPHA_FPTM_SUI:
5230 return "sv";
5232 break;
5234 case TRAP_SUFFIX_V_SV_SVI:
5235 switch (alpha_fptm)
5237 case ALPHA_FPTM_N:
5238 return NULL;
5239 case ALPHA_FPTM_U:
5240 return "v";
5241 case ALPHA_FPTM_SU:
5242 return "sv";
5243 case ALPHA_FPTM_SUI:
5244 return "svi";
5246 break;
5248 case TRAP_SUFFIX_U_SU_SUI:
5249 switch (alpha_fptm)
5251 case ALPHA_FPTM_N:
5252 return NULL;
5253 case ALPHA_FPTM_U:
5254 return "u";
5255 case ALPHA_FPTM_SU:
5256 return "su";
5257 case ALPHA_FPTM_SUI:
5258 return "sui";
5260 break;
5262 abort ();
5265 /* Return the rounding mode suffix applicable to the current
5266 instruction, or NULL. */
5268 static const char *
5269 get_round_mode_suffix (void)
5271 enum attr_round_suffix s = get_attr_round_suffix (current_output_insn);
5273 switch (s)
5275 case ROUND_SUFFIX_NONE:
5276 return NULL;
5277 case ROUND_SUFFIX_NORMAL:
5278 switch (alpha_fprm)
5280 case ALPHA_FPRM_NORM:
5281 return NULL;
5282 case ALPHA_FPRM_MINF:
5283 return "m";
5284 case ALPHA_FPRM_CHOP:
5285 return "c";
5286 case ALPHA_FPRM_DYN:
5287 return "d";
5289 break;
5291 case ROUND_SUFFIX_C:
5292 return "c";
5294 abort ();
5297 /* Locate some local-dynamic symbol still in use by this function
5298 so that we can print its name in some movdi_er_tlsldm pattern. */
5300 static int
5301 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
5303 rtx x = *px;
5305 if (GET_CODE (x) == SYMBOL_REF
5306 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
5308 cfun->machine->some_ld_name = XSTR (x, 0);
5309 return 1;
5312 return 0;
5315 static const char *
5316 get_some_local_dynamic_name (void)
5318 rtx insn;
5320 if (cfun->machine->some_ld_name)
5321 return cfun->machine->some_ld_name;
5323 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
5324 if (INSN_P (insn)
5325 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
5326 return cfun->machine->some_ld_name;
5328 abort ();
5331 /* Print an operand. Recognize special options, documented below. */
5333 void
5334 print_operand (FILE *file, rtx x, int code)
5336 int i;
5338 switch (code)
5340 case '~':
5341 /* Print the assembler name of the current function. */
5342 assemble_name (file, alpha_fnname);
5343 break;
5345 case '&':
5346 assemble_name (file, get_some_local_dynamic_name ());
5347 break;
5349 case '/':
5351 const char *trap = get_trap_mode_suffix ();
5352 const char *round = get_round_mode_suffix ();
5354 if (trap || round)
5355 fprintf (file, (TARGET_AS_SLASH_BEFORE_SUFFIX ? "/%s%s" : "%s%s"),
5356 (trap ? trap : ""), (round ? round : ""));
5357 break;
5360 case ',':
5361 /* Generates single precision instruction suffix. */
5362 fputc ((TARGET_FLOAT_VAX ? 'f' : 's'), file);
5363 break;
5365 case '-':
5366 /* Generates double precision instruction suffix. */
5367 fputc ((TARGET_FLOAT_VAX ? 'g' : 't'), file);
5368 break;
5370 case '+':
5371 /* Generates a nop after a noreturn call at the very end of the
5372 function. */
5373 if (next_real_insn (current_output_insn) == 0)
5374 fprintf (file, "\n\tnop");
5375 break;
5377 case '#':
5378 if (alpha_this_literal_sequence_number == 0)
5379 alpha_this_literal_sequence_number = alpha_next_sequence_number++;
5380 fprintf (file, "%d", alpha_this_literal_sequence_number);
5381 break;
5383 case '*':
5384 if (alpha_this_gpdisp_sequence_number == 0)
5385 alpha_this_gpdisp_sequence_number = alpha_next_sequence_number++;
5386 fprintf (file, "%d", alpha_this_gpdisp_sequence_number);
5387 break;
5389 case 'H':
5390 if (GET_CODE (x) == HIGH)
5391 output_addr_const (file, XEXP (x, 0));
5392 else
5393 output_operand_lossage ("invalid %%H value");
5394 break;
5396 case 'J':
5398 const char *lituse;
5400 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSGD_CALL)
5402 x = XVECEXP (x, 0, 0);
5403 lituse = "lituse_tlsgd";
5405 else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSLDM_CALL)
5407 x = XVECEXP (x, 0, 0);
5408 lituse = "lituse_tlsldm";
5410 else if (GET_CODE (x) == CONST_INT)
5411 lituse = "lituse_jsr";
5412 else
5414 output_operand_lossage ("invalid %%J value");
5415 break;
5418 if (x != const0_rtx)
5419 fprintf (file, "\t\t!%s!%d", lituse, (int) INTVAL (x));
5421 break;
5423 case 'r':
5424 /* If this operand is the constant zero, write it as "$31". */
5425 if (GET_CODE (x) == REG)
5426 fprintf (file, "%s", reg_names[REGNO (x)]);
5427 else if (x == CONST0_RTX (GET_MODE (x)))
5428 fprintf (file, "$31");
5429 else
5430 output_operand_lossage ("invalid %%r value");
5431 break;
5433 case 'R':
5434 /* Similar, but for floating-point. */
5435 if (GET_CODE (x) == REG)
5436 fprintf (file, "%s", reg_names[REGNO (x)]);
5437 else if (x == CONST0_RTX (GET_MODE (x)))
5438 fprintf (file, "$f31");
5439 else
5440 output_operand_lossage ("invalid %%R value");
5441 break;
5443 case 'N':
5444 /* Write the 1's complement of a constant. */
5445 if (GET_CODE (x) != CONST_INT)
5446 output_operand_lossage ("invalid %%N value");
5448 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
5449 break;
5451 case 'P':
5452 /* Write 1 << C, for a constant C. */
5453 if (GET_CODE (x) != CONST_INT)
5454 output_operand_lossage ("invalid %%P value");
5456 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) 1 << INTVAL (x));
5457 break;
5459 case 'h':
5460 /* Write the high-order 16 bits of a constant, sign-extended. */
5461 if (GET_CODE (x) != CONST_INT)
5462 output_operand_lossage ("invalid %%h value");
5464 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) >> 16);
5465 break;
5467 case 'L':
5468 /* Write the low-order 16 bits of a constant, sign-extended. */
5469 if (GET_CODE (x) != CONST_INT)
5470 output_operand_lossage ("invalid %%L value");
5472 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5473 (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
5474 break;
5476 case 'm':
5477 /* Write mask for ZAP insn. */
5478 if (GET_CODE (x) == CONST_DOUBLE)
5480 HOST_WIDE_INT mask = 0;
5481 HOST_WIDE_INT value;
5483 value = CONST_DOUBLE_LOW (x);
5484 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5485 i++, value >>= 8)
5486 if (value & 0xff)
5487 mask |= (1 << i);
5489 value = CONST_DOUBLE_HIGH (x);
5490 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5491 i++, value >>= 8)
5492 if (value & 0xff)
5493 mask |= (1 << (i + sizeof (int)));
5495 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask & 0xff);
5498 else if (GET_CODE (x) == CONST_INT)
5500 HOST_WIDE_INT mask = 0, value = INTVAL (x);
5502 for (i = 0; i < 8; i++, value >>= 8)
5503 if (value & 0xff)
5504 mask |= (1 << i);
5506 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask);
5508 else
5509 output_operand_lossage ("invalid %%m value");
5510 break;
5512 case 'M':
5513 /* 'b', 'w', 'l', or 'q' as the value of the constant. */
5514 if (GET_CODE (x) != CONST_INT
5515 || (INTVAL (x) != 8 && INTVAL (x) != 16
5516 && INTVAL (x) != 32 && INTVAL (x) != 64))
5517 output_operand_lossage ("invalid %%M value");
5519 fprintf (file, "%s",
5520 (INTVAL (x) == 8 ? "b"
5521 : INTVAL (x) == 16 ? "w"
5522 : INTVAL (x) == 32 ? "l"
5523 : "q"));
5524 break;
5526 case 'U':
5527 /* Similar, except do it from the mask. */
5528 if (GET_CODE (x) == CONST_INT)
5530 HOST_WIDE_INT value = INTVAL (x);
5532 if (value == 0xff)
5534 fputc ('b', file);
5535 break;
5537 if (value == 0xffff)
5539 fputc ('w', file);
5540 break;
5542 if (value == 0xffffffff)
5544 fputc ('l', file);
5545 break;
5547 if (value == -1)
5549 fputc ('q', file);
5550 break;
5553 else if (HOST_BITS_PER_WIDE_INT == 32
5554 && GET_CODE (x) == CONST_DOUBLE
5555 && CONST_DOUBLE_LOW (x) == 0xffffffff
5556 && CONST_DOUBLE_HIGH (x) == 0)
5558 fputc ('l', file);
5559 break;
5561 output_operand_lossage ("invalid %%U value");
5562 break;
5564 case 's':
5565 /* Write the constant value divided by 8 for little-endian mode or
5566 (56 - value) / 8 for big-endian mode. */
5568 if (GET_CODE (x) != CONST_INT
5569 || (unsigned HOST_WIDE_INT) INTVAL (x) >= (WORDS_BIG_ENDIAN
5570 ? 56
5571 : 64)
5572 || (INTVAL (x) & 7) != 0)
5573 output_operand_lossage ("invalid %%s value");
5575 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5576 WORDS_BIG_ENDIAN
5577 ? (56 - INTVAL (x)) / 8
5578 : INTVAL (x) / 8);
5579 break;
5581 case 'S':
5582 /* Same, except compute (64 - c) / 8 */
5584 if (GET_CODE (x) != CONST_INT
5585 && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
5586 && (INTVAL (x) & 7) != 8)
5587 output_operand_lossage ("invalid %%s value");
5589 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (64 - INTVAL (x)) / 8);
5590 break;
5592 case 't':
5594 /* On Unicos/Mk systems: use a DEX expression if the symbol
5595 clashes with a register name. */
5596 int dex = unicosmk_need_dex (x);
5597 if (dex)
5598 fprintf (file, "DEX(%d)", dex);
5599 else
5600 output_addr_const (file, x);
5602 break;
5604 case 'C': case 'D': case 'c': case 'd':
5605 /* Write out comparison name. */
5607 enum rtx_code c = GET_CODE (x);
5609 if (GET_RTX_CLASS (c) != '<')
5610 output_operand_lossage ("invalid %%C value");
5612 else if (code == 'D')
5613 c = reverse_condition (c);
5614 else if (code == 'c')
5615 c = swap_condition (c);
5616 else if (code == 'd')
5617 c = swap_condition (reverse_condition (c));
5619 if (c == LEU)
5620 fprintf (file, "ule");
5621 else if (c == LTU)
5622 fprintf (file, "ult");
5623 else if (c == UNORDERED)
5624 fprintf (file, "un");
5625 else
5626 fprintf (file, "%s", GET_RTX_NAME (c));
5628 break;
5630 case 'E':
5631 /* Write the divide or modulus operator. */
5632 switch (GET_CODE (x))
5634 case DIV:
5635 fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
5636 break;
5637 case UDIV:
5638 fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
5639 break;
5640 case MOD:
5641 fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
5642 break;
5643 case UMOD:
5644 fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
5645 break;
5646 default:
5647 output_operand_lossage ("invalid %%E value");
5648 break;
5650 break;
5652 case 'A':
5653 /* Write "_u" for unaligned access. */
5654 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
5655 fprintf (file, "_u");
5656 break;
5658 case 0:
5659 if (GET_CODE (x) == REG)
5660 fprintf (file, "%s", reg_names[REGNO (x)]);
5661 else if (GET_CODE (x) == MEM)
5662 output_address (XEXP (x, 0));
5663 else if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == UNSPEC)
5665 switch (XINT (XEXP (x, 0), 1))
5667 case UNSPEC_DTPREL:
5668 case UNSPEC_TPREL:
5669 output_addr_const (file, XVECEXP (XEXP (x, 0), 0, 0));
5670 break;
5671 default:
5672 output_operand_lossage ("unknown relocation unspec");
5673 break;
5676 else
5677 output_addr_const (file, x);
5678 break;
5680 default:
5681 output_operand_lossage ("invalid %%xn code");
5685 void
5686 print_operand_address (FILE *file, rtx addr)
5688 int basereg = 31;
5689 HOST_WIDE_INT offset = 0;
5691 if (GET_CODE (addr) == AND)
5692 addr = XEXP (addr, 0);
5694 if (GET_CODE (addr) == PLUS
5695 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5697 offset = INTVAL (XEXP (addr, 1));
5698 addr = XEXP (addr, 0);
5701 if (GET_CODE (addr) == LO_SUM)
5703 const char *reloc16, *reloclo;
5704 rtx op1 = XEXP (addr, 1);
5706 if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1, 0)) == UNSPEC)
5708 op1 = XEXP (op1, 0);
5709 switch (XINT (op1, 1))
5711 case UNSPEC_DTPREL:
5712 reloc16 = NULL;
5713 reloclo = (alpha_tls_size == 16 ? "dtprel" : "dtprello");
5714 break;
5715 case UNSPEC_TPREL:
5716 reloc16 = NULL;
5717 reloclo = (alpha_tls_size == 16 ? "tprel" : "tprello");
5718 break;
5719 default:
5720 output_operand_lossage ("unknown relocation unspec");
5721 return;
5724 output_addr_const (file, XVECEXP (op1, 0, 0));
5726 else
5728 reloc16 = "gprel";
5729 reloclo = "gprellow";
5730 output_addr_const (file, op1);
5733 if (offset)
5734 fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC, offset);
5736 addr = XEXP (addr, 0);
5737 if (GET_CODE (addr) == REG)
5738 basereg = REGNO (addr);
5739 else if (GET_CODE (addr) == SUBREG
5740 && GET_CODE (SUBREG_REG (addr)) == REG)
5741 basereg = subreg_regno (addr);
5742 else
5743 abort ();
5745 fprintf (file, "($%d)\t\t!%s", basereg,
5746 (basereg == 29 ? reloc16 : reloclo));
5747 return;
5750 if (GET_CODE (addr) == REG)
5751 basereg = REGNO (addr);
5752 else if (GET_CODE (addr) == SUBREG
5753 && GET_CODE (SUBREG_REG (addr)) == REG)
5754 basereg = subreg_regno (addr);
5755 else if (GET_CODE (addr) == CONST_INT)
5756 offset = INTVAL (addr);
5758 #if TARGET_ABI_OPEN_VMS
5759 else if (GET_CODE (addr) == SYMBOL_REF)
5761 fprintf (file, "%s", XSTR (addr, 0));
5762 return;
5764 else if (GET_CODE (addr) == CONST
5765 && GET_CODE (XEXP (addr, 0)) == PLUS
5766 && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF)
5768 fprintf (file, "%s+" HOST_WIDE_INT_PRINT_DEC,
5769 XSTR (XEXP (XEXP (addr, 0), 0), 0),
5770 INTVAL (XEXP (XEXP (addr, 0), 1)));
5771 return;
5773 #endif
5775 else
5776 abort ();
5778 fprintf (file, HOST_WIDE_INT_PRINT_DEC "($%d)", offset, basereg);
5781 /* Emit RTL insns to initialize the variable parts of a trampoline at
5782 TRAMP. FNADDR is an RTX for the address of the function's pure
5783 code. CXT is an RTX for the static chain value for the function.
5785 The three offset parameters are for the individual template's
5786 layout. A JMPOFS < 0 indicates that the trampoline does not
5787 contain instructions at all.
5789 We assume here that a function will be called many more times than
5790 its address is taken (e.g., it might be passed to qsort), so we
5791 take the trouble to initialize the "hint" field in the JMP insn.
5792 Note that the hint field is PC (new) + 4 * bits 13:0. */
5794 void
5795 alpha_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt,
5796 int fnofs, int cxtofs, int jmpofs)
5798 rtx temp, temp1, addr;
5799 /* VMS really uses DImode pointers in memory at this point. */
5800 enum machine_mode mode = TARGET_ABI_OPEN_VMS ? Pmode : ptr_mode;
5802 #ifdef POINTERS_EXTEND_UNSIGNED
5803 fnaddr = convert_memory_address (mode, fnaddr);
5804 cxt = convert_memory_address (mode, cxt);
5805 #endif
5807 /* Store function address and CXT. */
5808 addr = memory_address (mode, plus_constant (tramp, fnofs));
5809 emit_move_insn (gen_rtx_MEM (mode, addr), fnaddr);
5810 addr = memory_address (mode, plus_constant (tramp, cxtofs));
5811 emit_move_insn (gen_rtx_MEM (mode, addr), cxt);
5813 /* This has been disabled since the hint only has a 32k range, and in
5814 no existing OS is the stack within 32k of the text segment. */
5815 if (0 && jmpofs >= 0)
5817 /* Compute hint value. */
5818 temp = force_operand (plus_constant (tramp, jmpofs+4), NULL_RTX);
5819 temp = expand_binop (DImode, sub_optab, fnaddr, temp, temp, 1,
5820 OPTAB_WIDEN);
5821 temp = expand_shift (RSHIFT_EXPR, Pmode, temp,
5822 build_int_2 (2, 0), NULL_RTX, 1);
5823 temp = expand_and (SImode, gen_lowpart (SImode, temp),
5824 GEN_INT (0x3fff), 0);
5826 /* Merge in the hint. */
5827 addr = memory_address (SImode, plus_constant (tramp, jmpofs));
5828 temp1 = force_reg (SImode, gen_rtx_MEM (SImode, addr));
5829 temp1 = expand_and (SImode, temp1, GEN_INT (0xffffc000), NULL_RTX);
5830 temp1 = expand_binop (SImode, ior_optab, temp1, temp, temp1, 1,
5831 OPTAB_WIDEN);
5832 emit_move_insn (gen_rtx_MEM (SImode, addr), temp1);
5835 #ifdef TRANSFER_FROM_TRAMPOLINE
5836 emit_library_call (init_one_libfunc ("__enable_execute_stack"),
5837 0, VOIDmode, 1, tramp, Pmode);
5838 #endif
5840 if (jmpofs >= 0)
5841 emit_insn (gen_imb ());
5844 /* Determine where to put an argument to a function.
5845 Value is zero to push the argument on the stack,
5846 or a hard register in which to store the argument.
5848 MODE is the argument's machine mode.
5849 TYPE is the data type of the argument (as a tree).
5850 This is null for libcalls where that information may
5851 not be available.
5852 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5853 the preceding args and about the function being called.
5854 NAMED is nonzero if this argument is a named parameter
5855 (otherwise it is an extra parameter matching an ellipsis).
5857 On Alpha the first 6 words of args are normally in registers
5858 and the rest are pushed. */
5861 function_arg (CUMULATIVE_ARGS cum, enum machine_mode mode, tree type,
5862 int named ATTRIBUTE_UNUSED)
5864 int basereg;
5865 int num_args;
5867 /* Set up defaults for FP operands passed in FP registers, and
5868 integral operands passed in integer registers. */
5869 if (TARGET_FPREGS
5870 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
5871 || GET_MODE_CLASS (mode) == MODE_FLOAT))
5872 basereg = 32 + 16;
5873 else
5874 basereg = 16;
5876 /* ??? Irritatingly, the definition of CUMULATIVE_ARGS is different for
5877 the three platforms, so we can't avoid conditional compilation. */
5878 #if TARGET_ABI_OPEN_VMS
5880 if (mode == VOIDmode)
5881 return alpha_arg_info_reg_val (cum);
5883 num_args = cum.num_args;
5884 if (num_args >= 6 || MUST_PASS_IN_STACK (mode, type))
5885 return NULL_RTX;
5887 #else
5888 #if TARGET_ABI_UNICOSMK
5890 int size;
5892 /* If this is the last argument, generate the call info word (CIW). */
5893 /* ??? We don't include the caller's line number in the CIW because
5894 I don't know how to determine it if debug infos are turned off. */
5895 if (mode == VOIDmode)
5897 int i;
5898 HOST_WIDE_INT lo;
5899 HOST_WIDE_INT hi;
5900 rtx ciw;
5902 lo = 0;
5904 for (i = 0; i < cum.num_reg_words && i < 5; i++)
5905 if (cum.reg_args_type[i])
5906 lo |= (1 << (7 - i));
5908 if (cum.num_reg_words == 6 && cum.reg_args_type[5])
5909 lo |= 7;
5910 else
5911 lo |= cum.num_reg_words;
5913 #if HOST_BITS_PER_WIDE_INT == 32
5914 hi = (cum.num_args << 20) | cum.num_arg_words;
5915 #else
5916 lo = lo | ((HOST_WIDE_INT) cum.num_args << 52)
5917 | ((HOST_WIDE_INT) cum.num_arg_words << 32);
5918 hi = 0;
5919 #endif
5920 ciw = immed_double_const (lo, hi, DImode);
5922 return gen_rtx_UNSPEC (DImode, gen_rtvec (1, ciw),
5923 UNSPEC_UMK_LOAD_CIW);
5926 size = ALPHA_ARG_SIZE (mode, type, named);
5927 num_args = cum.num_reg_words;
5928 if (MUST_PASS_IN_STACK (mode, type)
5929 || cum.num_reg_words + size > 6 || cum.force_stack)
5930 return NULL_RTX;
5931 else if (type && TYPE_MODE (type) == BLKmode)
5933 rtx reg1, reg2;
5935 reg1 = gen_rtx_REG (DImode, num_args + 16);
5936 reg1 = gen_rtx_EXPR_LIST (DImode, reg1, const0_rtx);
5938 /* The argument fits in two registers. Note that we still need to
5939 reserve a register for empty structures. */
5940 if (size == 0)
5941 return NULL_RTX;
5942 else if (size == 1)
5943 return gen_rtx_PARALLEL (mode, gen_rtvec (1, reg1));
5944 else
5946 reg2 = gen_rtx_REG (DImode, num_args + 17);
5947 reg2 = gen_rtx_EXPR_LIST (DImode, reg2, GEN_INT (8));
5948 return gen_rtx_PARALLEL (mode, gen_rtvec (2, reg1, reg2));
5952 #else
5954 if (cum >= 6)
5955 return NULL_RTX;
5956 num_args = cum;
5958 /* VOID is passed as a special flag for "last argument". */
5959 if (type == void_type_node)
5960 basereg = 16;
5961 else if (MUST_PASS_IN_STACK (mode, type))
5962 return NULL_RTX;
5963 else if (FUNCTION_ARG_PASS_BY_REFERENCE (cum, mode, type, named))
5964 basereg = 16;
5966 #endif /* TARGET_ABI_UNICOSMK */
5967 #endif /* TARGET_ABI_OPEN_VMS */
5969 return gen_rtx_REG (mode, num_args + basereg);
5972 tree
5973 alpha_build_va_list (void)
5975 tree base, ofs, record, type_decl;
5977 if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
5978 return ptr_type_node;
5980 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
5981 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
5982 TREE_CHAIN (record) = type_decl;
5983 TYPE_NAME (record) = type_decl;
5985 /* C++? SET_IS_AGGR_TYPE (record, 1); */
5987 ofs = build_decl (FIELD_DECL, get_identifier ("__offset"),
5988 integer_type_node);
5989 DECL_FIELD_CONTEXT (ofs) = record;
5991 base = build_decl (FIELD_DECL, get_identifier ("__base"),
5992 ptr_type_node);
5993 DECL_FIELD_CONTEXT (base) = record;
5994 TREE_CHAIN (base) = ofs;
5996 TYPE_FIELDS (record) = base;
5997 layout_type (record);
5999 return record;
6002 /* Perform any needed actions needed for a function that is receiving a
6003 variable number of arguments.
6005 On the Alpha, we allocate space for all 12 arg registers, but only
6006 push those that are remaining. However, if NO registers need to be
6007 saved, don't allocate any space. This is not only because we won't
6008 need the space, but because AP includes the current_pretend_args_size
6009 and we don't want to mess up any ap-relative addresses already made.
6011 If we are not to use the floating-point registers, save the integer
6012 registers where we would put the floating-point registers. This is
6013 not the most efficient way to implement varargs with just one register
6014 class, but it isn't worth doing anything more efficient in this rare
6015 case. */
6017 #if TARGET_ABI_OSF
6018 void
6019 alpha_setup_incoming_varargs(CUMULATIVE_ARGS cum,
6020 enum machine_mode mode ATTRIBUTE_UNUSED,
6021 tree type ATTRIBUTE_UNUSED,
6022 int *pretend_size, int no_rtl)
6024 if (cum >= 6)
6025 return;
6027 if (!no_rtl)
6029 int set = get_varargs_alias_set ();
6030 rtx tmp;
6032 tmp = gen_rtx_MEM (BLKmode,
6033 plus_constant (virtual_incoming_args_rtx,
6034 (cum + 6) * UNITS_PER_WORD));
6035 set_mem_alias_set (tmp, set);
6036 move_block_from_reg (16 + cum, tmp, 6 - cum);
6038 tmp = gen_rtx_MEM (BLKmode,
6039 plus_constant (virtual_incoming_args_rtx,
6040 cum * UNITS_PER_WORD));
6041 set_mem_alias_set (tmp, set);
6042 move_block_from_reg (16 + (TARGET_FPREGS ? 32 : 0) + cum, tmp,
6043 6 - cum);
6045 *pretend_size = 12 * UNITS_PER_WORD;
6047 #endif
6049 void
6050 alpha_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
6052 HOST_WIDE_INT offset;
6053 tree t, offset_field, base_field;
6055 if (TREE_CODE (TREE_TYPE (valist)) == ERROR_MARK)
6056 return;
6058 if (TARGET_ABI_UNICOSMK)
6059 std_expand_builtin_va_start (valist, nextarg);
6061 /* For Unix, SETUP_INCOMING_VARARGS moves the starting address base
6062 up by 48, storing fp arg registers in the first 48 bytes, and the
6063 integer arg registers in the next 48 bytes. This is only done,
6064 however, if any integer registers need to be stored.
6066 If no integer registers need be stored, then we must subtract 48
6067 in order to account for the integer arg registers which are counted
6068 in argsize above, but which are not actually stored on the stack.
6069 Must further be careful here about structures straddling the last
6070 integer argument register; that futzes with pretend_args_size,
6071 which changes the meaning of AP. */
6073 if (NUM_ARGS <= 6)
6074 offset = TARGET_ABI_OPEN_VMS ? UNITS_PER_WORD : 6 * UNITS_PER_WORD;
6075 else
6076 offset = -6 * UNITS_PER_WORD + current_function_pretend_args_size;
6078 if (TARGET_ABI_OPEN_VMS)
6080 nextarg = plus_constant (nextarg, offset);
6081 nextarg = plus_constant (nextarg, NUM_ARGS * UNITS_PER_WORD);
6082 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
6083 make_tree (ptr_type_node, nextarg));
6084 TREE_SIDE_EFFECTS (t) = 1;
6086 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6088 else
6090 base_field = TYPE_FIELDS (TREE_TYPE (valist));
6091 offset_field = TREE_CHAIN (base_field);
6093 base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6094 valist, base_field);
6095 offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6096 valist, offset_field);
6098 t = make_tree (ptr_type_node, virtual_incoming_args_rtx);
6099 t = build (PLUS_EXPR, ptr_type_node, t, build_int_2 (offset, 0));
6100 t = build (MODIFY_EXPR, TREE_TYPE (base_field), base_field, t);
6101 TREE_SIDE_EFFECTS (t) = 1;
6102 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6104 t = build_int_2 (NUM_ARGS * UNITS_PER_WORD, 0);
6105 t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field, t);
6106 TREE_SIDE_EFFECTS (t) = 1;
6107 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6112 alpha_va_arg (tree valist, tree type)
6114 rtx addr;
6115 tree t, type_size, rounded_size;
6116 tree offset_field, base_field, addr_tree, addend;
6117 tree wide_type, wide_ofs;
6118 int indirect = 0;
6120 if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
6121 return std_expand_builtin_va_arg (valist, type);
6123 if (type == error_mark_node
6124 || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
6125 || TREE_OVERFLOW (type_size))
6126 rounded_size = size_zero_node;
6127 else
6128 rounded_size = fold (build (MULT_EXPR, sizetype,
6129 fold (build (TRUNC_DIV_EXPR, sizetype,
6130 fold (build (PLUS_EXPR, sizetype,
6131 type_size,
6132 size_int (7))),
6133 size_int (8))),
6134 size_int (8)));
6136 base_field = TYPE_FIELDS (TREE_TYPE (valist));
6137 offset_field = TREE_CHAIN (base_field);
6139 base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6140 valist, base_field);
6141 offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6142 valist, offset_field);
6144 /* If the type could not be passed in registers, skip the block
6145 reserved for the registers. */
6146 if (MUST_PASS_IN_STACK (TYPE_MODE (type), type))
6148 t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field,
6149 build (MAX_EXPR, TREE_TYPE (offset_field),
6150 offset_field, build_int_2 (6*8, 0)));
6151 TREE_SIDE_EFFECTS (t) = 1;
6152 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6155 wide_type = make_signed_type (64);
6156 wide_ofs = save_expr (build1 (CONVERT_EXPR, wide_type, offset_field));
6158 addend = wide_ofs;
6160 if (TYPE_MODE (type) == TFmode || TYPE_MODE (type) == TCmode)
6162 indirect = 1;
6163 rounded_size = size_int (UNITS_PER_WORD);
6165 else if (FLOAT_TYPE_P (type))
6167 tree fpaddend, cond;
6169 fpaddend = fold (build (PLUS_EXPR, TREE_TYPE (addend),
6170 addend, build_int_2 (-6*8, 0)));
6172 cond = fold (build (LT_EXPR, integer_type_node,
6173 wide_ofs, build_int_2 (6*8, 0)));
6175 addend = fold (build (COND_EXPR, TREE_TYPE (addend), cond,
6176 fpaddend, addend));
6179 addr_tree = build (PLUS_EXPR, TREE_TYPE (base_field),
6180 base_field, addend);
6182 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
6183 addr = copy_to_reg (addr);
6185 t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field,
6186 build (PLUS_EXPR, TREE_TYPE (offset_field),
6187 offset_field, rounded_size));
6188 TREE_SIDE_EFFECTS (t) = 1;
6189 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6191 if (indirect)
6193 addr = force_reg (Pmode, addr);
6194 addr = gen_rtx_MEM (Pmode, addr);
6197 return addr;
6200 /* Builtins. */
6202 enum alpha_builtin
6204 ALPHA_BUILTIN_CMPBGE,
6205 ALPHA_BUILTIN_EXTBL,
6206 ALPHA_BUILTIN_EXTWL,
6207 ALPHA_BUILTIN_EXTLL,
6208 ALPHA_BUILTIN_EXTQL,
6209 ALPHA_BUILTIN_EXTWH,
6210 ALPHA_BUILTIN_EXTLH,
6211 ALPHA_BUILTIN_EXTQH,
6212 ALPHA_BUILTIN_INSBL,
6213 ALPHA_BUILTIN_INSWL,
6214 ALPHA_BUILTIN_INSLL,
6215 ALPHA_BUILTIN_INSQL,
6216 ALPHA_BUILTIN_INSWH,
6217 ALPHA_BUILTIN_INSLH,
6218 ALPHA_BUILTIN_INSQH,
6219 ALPHA_BUILTIN_MSKBL,
6220 ALPHA_BUILTIN_MSKWL,
6221 ALPHA_BUILTIN_MSKLL,
6222 ALPHA_BUILTIN_MSKQL,
6223 ALPHA_BUILTIN_MSKWH,
6224 ALPHA_BUILTIN_MSKLH,
6225 ALPHA_BUILTIN_MSKQH,
6226 ALPHA_BUILTIN_UMULH,
6227 ALPHA_BUILTIN_ZAP,
6228 ALPHA_BUILTIN_ZAPNOT,
6229 ALPHA_BUILTIN_AMASK,
6230 ALPHA_BUILTIN_IMPLVER,
6231 ALPHA_BUILTIN_RPCC,
6232 ALPHA_BUILTIN_THREAD_POINTER,
6233 ALPHA_BUILTIN_SET_THREAD_POINTER,
6235 /* TARGET_MAX */
6236 ALPHA_BUILTIN_MINUB8,
6237 ALPHA_BUILTIN_MINSB8,
6238 ALPHA_BUILTIN_MINUW4,
6239 ALPHA_BUILTIN_MINSW4,
6240 ALPHA_BUILTIN_MAXUB8,
6241 ALPHA_BUILTIN_MAXSB8,
6242 ALPHA_BUILTIN_MAXUW4,
6243 ALPHA_BUILTIN_MAXSW4,
6244 ALPHA_BUILTIN_PERR,
6245 ALPHA_BUILTIN_PKLB,
6246 ALPHA_BUILTIN_PKWB,
6247 ALPHA_BUILTIN_UNPKBL,
6248 ALPHA_BUILTIN_UNPKBW,
6250 /* TARGET_CIX */
6251 ALPHA_BUILTIN_CTTZ,
6252 ALPHA_BUILTIN_CTLZ,
6253 ALPHA_BUILTIN_CTPOP,
6255 ALPHA_BUILTIN_max
6258 static unsigned int const code_for_builtin[ALPHA_BUILTIN_max] = {
6259 CODE_FOR_builtin_cmpbge,
6260 CODE_FOR_builtin_extbl,
6261 CODE_FOR_builtin_extwl,
6262 CODE_FOR_builtin_extll,
6263 CODE_FOR_builtin_extql,
6264 CODE_FOR_builtin_extwh,
6265 CODE_FOR_builtin_extlh,
6266 CODE_FOR_builtin_extqh,
6267 CODE_FOR_builtin_insbl,
6268 CODE_FOR_builtin_inswl,
6269 CODE_FOR_builtin_insll,
6270 CODE_FOR_builtin_insql,
6271 CODE_FOR_builtin_inswh,
6272 CODE_FOR_builtin_inslh,
6273 CODE_FOR_builtin_insqh,
6274 CODE_FOR_builtin_mskbl,
6275 CODE_FOR_builtin_mskwl,
6276 CODE_FOR_builtin_mskll,
6277 CODE_FOR_builtin_mskql,
6278 CODE_FOR_builtin_mskwh,
6279 CODE_FOR_builtin_msklh,
6280 CODE_FOR_builtin_mskqh,
6281 CODE_FOR_umuldi3_highpart,
6282 CODE_FOR_builtin_zap,
6283 CODE_FOR_builtin_zapnot,
6284 CODE_FOR_builtin_amask,
6285 CODE_FOR_builtin_implver,
6286 CODE_FOR_builtin_rpcc,
6287 CODE_FOR_load_tp,
6288 CODE_FOR_set_tp,
6290 /* TARGET_MAX */
6291 CODE_FOR_builtin_minub8,
6292 CODE_FOR_builtin_minsb8,
6293 CODE_FOR_builtin_minuw4,
6294 CODE_FOR_builtin_minsw4,
6295 CODE_FOR_builtin_maxub8,
6296 CODE_FOR_builtin_maxsb8,
6297 CODE_FOR_builtin_maxuw4,
6298 CODE_FOR_builtin_maxsw4,
6299 CODE_FOR_builtin_perr,
6300 CODE_FOR_builtin_pklb,
6301 CODE_FOR_builtin_pkwb,
6302 CODE_FOR_builtin_unpkbl,
6303 CODE_FOR_builtin_unpkbw,
6305 /* TARGET_CIX */
6306 CODE_FOR_builtin_cttz,
6307 CODE_FOR_builtin_ctlz,
6308 CODE_FOR_builtin_ctpop
6311 struct alpha_builtin_def
6313 const char *name;
6314 enum alpha_builtin code;
6315 unsigned int target_mask;
6318 static struct alpha_builtin_def const zero_arg_builtins[] = {
6319 { "__builtin_alpha_implver", ALPHA_BUILTIN_IMPLVER, 0 },
6320 { "__builtin_alpha_rpcc", ALPHA_BUILTIN_RPCC, 0 }
6323 static struct alpha_builtin_def const one_arg_builtins[] = {
6324 { "__builtin_alpha_amask", ALPHA_BUILTIN_AMASK, 0 },
6325 { "__builtin_alpha_pklb", ALPHA_BUILTIN_PKLB, MASK_MAX },
6326 { "__builtin_alpha_pkwb", ALPHA_BUILTIN_PKWB, MASK_MAX },
6327 { "__builtin_alpha_unpkbl", ALPHA_BUILTIN_UNPKBL, MASK_MAX },
6328 { "__builtin_alpha_unpkbw", ALPHA_BUILTIN_UNPKBW, MASK_MAX },
6329 { "__builtin_alpha_cttz", ALPHA_BUILTIN_CTTZ, MASK_CIX },
6330 { "__builtin_alpha_ctlz", ALPHA_BUILTIN_CTLZ, MASK_CIX },
6331 { "__builtin_alpha_ctpop", ALPHA_BUILTIN_CTPOP, MASK_CIX }
6334 static struct alpha_builtin_def const two_arg_builtins[] = {
6335 { "__builtin_alpha_cmpbge", ALPHA_BUILTIN_CMPBGE, 0 },
6336 { "__builtin_alpha_extbl", ALPHA_BUILTIN_EXTBL, 0 },
6337 { "__builtin_alpha_extwl", ALPHA_BUILTIN_EXTWL, 0 },
6338 { "__builtin_alpha_extll", ALPHA_BUILTIN_EXTLL, 0 },
6339 { "__builtin_alpha_extql", ALPHA_BUILTIN_EXTQL, 0 },
6340 { "__builtin_alpha_extwh", ALPHA_BUILTIN_EXTWH, 0 },
6341 { "__builtin_alpha_extlh", ALPHA_BUILTIN_EXTLH, 0 },
6342 { "__builtin_alpha_extqh", ALPHA_BUILTIN_EXTQH, 0 },
6343 { "__builtin_alpha_insbl", ALPHA_BUILTIN_INSBL, 0 },
6344 { "__builtin_alpha_inswl", ALPHA_BUILTIN_INSWL, 0 },
6345 { "__builtin_alpha_insll", ALPHA_BUILTIN_INSLL, 0 },
6346 { "__builtin_alpha_insql", ALPHA_BUILTIN_INSQL, 0 },
6347 { "__builtin_alpha_inswh", ALPHA_BUILTIN_INSWH, 0 },
6348 { "__builtin_alpha_inslh", ALPHA_BUILTIN_INSLH, 0 },
6349 { "__builtin_alpha_insqh", ALPHA_BUILTIN_INSQH, 0 },
6350 { "__builtin_alpha_mskbl", ALPHA_BUILTIN_MSKBL, 0 },
6351 { "__builtin_alpha_mskwl", ALPHA_BUILTIN_MSKWL, 0 },
6352 { "__builtin_alpha_mskll", ALPHA_BUILTIN_MSKLL, 0 },
6353 { "__builtin_alpha_mskql", ALPHA_BUILTIN_MSKQL, 0 },
6354 { "__builtin_alpha_mskwh", ALPHA_BUILTIN_MSKWH, 0 },
6355 { "__builtin_alpha_msklh", ALPHA_BUILTIN_MSKLH, 0 },
6356 { "__builtin_alpha_mskqh", ALPHA_BUILTIN_MSKQH, 0 },
6357 { "__builtin_alpha_umulh", ALPHA_BUILTIN_UMULH, 0 },
6358 { "__builtin_alpha_zap", ALPHA_BUILTIN_ZAP, 0 },
6359 { "__builtin_alpha_zapnot", ALPHA_BUILTIN_ZAPNOT, 0 },
6360 { "__builtin_alpha_minub8", ALPHA_BUILTIN_MINUB8, MASK_MAX },
6361 { "__builtin_alpha_minsb8", ALPHA_BUILTIN_MINSB8, MASK_MAX },
6362 { "__builtin_alpha_minuw4", ALPHA_BUILTIN_MINUW4, MASK_MAX },
6363 { "__builtin_alpha_minsw4", ALPHA_BUILTIN_MINSW4, MASK_MAX },
6364 { "__builtin_alpha_maxub8", ALPHA_BUILTIN_MAXUB8, MASK_MAX },
6365 { "__builtin_alpha_maxsb8", ALPHA_BUILTIN_MAXSB8, MASK_MAX },
6366 { "__builtin_alpha_maxuw4", ALPHA_BUILTIN_MAXUW4, MASK_MAX },
6367 { "__builtin_alpha_maxsw4", ALPHA_BUILTIN_MAXSW4, MASK_MAX },
6368 { "__builtin_alpha_perr", ALPHA_BUILTIN_PERR, MASK_MAX }
6371 static void
6372 alpha_init_builtins (void)
6374 const struct alpha_builtin_def *p;
6375 tree ftype;
6376 size_t i;
6378 ftype = build_function_type (long_integer_type_node, void_list_node);
6380 p = zero_arg_builtins;
6381 for (i = 0; i < ARRAY_SIZE (zero_arg_builtins); ++i, ++p)
6382 if ((target_flags & p->target_mask) == p->target_mask)
6383 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6384 NULL, NULL_TREE);
6386 ftype = build_function_type_list (long_integer_type_node,
6387 long_integer_type_node, NULL_TREE);
6389 p = one_arg_builtins;
6390 for (i = 0; i < ARRAY_SIZE (one_arg_builtins); ++i, ++p)
6391 if ((target_flags & p->target_mask) == p->target_mask)
6392 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6393 NULL, NULL_TREE);
6395 ftype = build_function_type_list (long_integer_type_node,
6396 long_integer_type_node,
6397 long_integer_type_node, NULL_TREE);
6399 p = two_arg_builtins;
6400 for (i = 0; i < ARRAY_SIZE (two_arg_builtins); ++i, ++p)
6401 if ((target_flags & p->target_mask) == p->target_mask)
6402 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6403 NULL, NULL_TREE);
6405 ftype = build_function_type (ptr_type_node, void_list_node);
6406 builtin_function ("__builtin_thread_pointer", ftype,
6407 ALPHA_BUILTIN_THREAD_POINTER, BUILT_IN_MD,
6408 NULL, NULL_TREE);
6410 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
6411 builtin_function ("__builtin_set_thread_pointer", ftype,
6412 ALPHA_BUILTIN_SET_THREAD_POINTER, BUILT_IN_MD,
6413 NULL, NULL_TREE);
6416 /* Expand an expression EXP that calls a built-in function,
6417 with result going to TARGET if that's convenient
6418 (and in mode MODE if that's convenient).
6419 SUBTARGET may be used as the target for computing one of EXP's operands.
6420 IGNORE is nonzero if the value is to be ignored. */
6422 static rtx
6423 alpha_expand_builtin (tree exp, rtx target,
6424 rtx subtarget ATTRIBUTE_UNUSED,
6425 enum machine_mode mode ATTRIBUTE_UNUSED,
6426 int ignore ATTRIBUTE_UNUSED)
6428 #define MAX_ARGS 2
6430 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6431 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6432 tree arglist = TREE_OPERAND (exp, 1);
6433 enum insn_code icode;
6434 rtx op[MAX_ARGS], pat;
6435 int arity;
6436 bool nonvoid;
6438 if (fcode >= ALPHA_BUILTIN_max)
6439 internal_error ("bad builtin fcode");
6440 icode = code_for_builtin[fcode];
6441 if (icode == 0)
6442 internal_error ("bad builtin fcode");
6444 nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
6446 for (arglist = TREE_OPERAND (exp, 1), arity = 0;
6447 arglist;
6448 arglist = TREE_CHAIN (arglist), arity++)
6450 const struct insn_operand_data *insn_op;
6452 tree arg = TREE_VALUE (arglist);
6453 if (arg == error_mark_node)
6454 return NULL_RTX;
6455 if (arity > MAX_ARGS)
6456 return NULL_RTX;
6458 insn_op = &insn_data[icode].operand[arity + nonvoid];
6460 op[arity] = expand_expr (arg, NULL_RTX, insn_op->mode, 0);
6462 if (!(*insn_op->predicate) (op[arity], insn_op->mode))
6463 op[arity] = copy_to_mode_reg (insn_op->mode, op[arity]);
6466 if (nonvoid)
6468 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6469 if (!target
6470 || GET_MODE (target) != tmode
6471 || !(*insn_data[icode].operand[0].predicate) (target, tmode))
6472 target = gen_reg_rtx (tmode);
6475 switch (arity)
6477 case 0:
6478 pat = GEN_FCN (icode) (target);
6479 break;
6480 case 1:
6481 if (nonvoid)
6482 pat = GEN_FCN (icode) (target, op[0]);
6483 else
6484 pat = GEN_FCN (icode) (op[0]);
6485 break;
6486 case 2:
6487 pat = GEN_FCN (icode) (target, op[0], op[1]);
6488 break;
6489 default:
6490 abort ();
6492 if (!pat)
6493 return NULL_RTX;
6494 emit_insn (pat);
6496 if (nonvoid)
6497 return target;
6498 else
6499 return const0_rtx;
6502 /* This page contains routines that are used to determine what the function
6503 prologue and epilogue code will do and write them out. */
6505 /* Compute the size of the save area in the stack. */
6507 /* These variables are used for communication between the following functions.
6508 They indicate various things about the current function being compiled
6509 that are used to tell what kind of prologue, epilogue and procedure
6510 descriptior to generate. */
6512 /* Nonzero if we need a stack procedure. */
6513 enum alpha_procedure_types {PT_NULL = 0, PT_REGISTER = 1, PT_STACK = 2};
6514 static enum alpha_procedure_types alpha_procedure_type;
6516 /* Register number (either FP or SP) that is used to unwind the frame. */
6517 static int vms_unwind_regno;
6519 /* Register number used to save FP. We need not have one for RA since
6520 we don't modify it for register procedures. This is only defined
6521 for register frame procedures. */
6522 static int vms_save_fp_regno;
6524 /* Register number used to reference objects off our PV. */
6525 static int vms_base_regno;
6527 /* Compute register masks for saved registers. */
6529 static void
6530 alpha_sa_mask (unsigned long *imaskP, unsigned long *fmaskP)
6532 unsigned long imask = 0;
6533 unsigned long fmask = 0;
6534 unsigned int i;
6536 /* Irritatingly, there are two kinds of thunks -- those created with
6537 TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go
6538 through the regular part of the compiler. In the
6539 TARGET_ASM_OUTPUT_MI_THUNK case we don't have valid register life
6540 info, but assemble_start_function wants to output .frame and
6541 .mask directives. */
6542 if (current_function_is_thunk && !no_new_pseudos)
6544 *imaskP = 0;
6545 *fmaskP = 0;
6546 return;
6549 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
6550 imask |= (1UL << HARD_FRAME_POINTER_REGNUM);
6552 /* One for every register we have to save. */
6553 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
6554 if (! fixed_regs[i] && ! call_used_regs[i]
6555 && regs_ever_live[i] && i != REG_RA
6556 && (!TARGET_ABI_UNICOSMK || i != HARD_FRAME_POINTER_REGNUM))
6558 if (i < 32)
6559 imask |= (1UL << i);
6560 else
6561 fmask |= (1UL << (i - 32));
6564 /* We need to restore these for the handler. */
6565 if (current_function_calls_eh_return)
6566 for (i = 0; ; ++i)
6568 unsigned regno = EH_RETURN_DATA_REGNO (i);
6569 if (regno == INVALID_REGNUM)
6570 break;
6571 imask |= 1UL << regno;
6574 /* If any register spilled, then spill the return address also. */
6575 /* ??? This is required by the Digital stack unwind specification
6576 and isn't needed if we're doing Dwarf2 unwinding. */
6577 if (imask || fmask || alpha_ra_ever_killed ())
6578 imask |= (1UL << REG_RA);
6580 *imaskP = imask;
6581 *fmaskP = fmask;
6585 alpha_sa_size (void)
6587 unsigned long mask[2];
6588 int sa_size = 0;
6589 int i, j;
6591 alpha_sa_mask (&mask[0], &mask[1]);
6593 if (TARGET_ABI_UNICOSMK)
6595 if (mask[0] || mask[1])
6596 sa_size = 14;
6598 else
6600 for (j = 0; j < 2; ++j)
6601 for (i = 0; i < 32; ++i)
6602 if ((mask[j] >> i) & 1)
6603 sa_size++;
6606 if (TARGET_ABI_UNICOSMK)
6608 /* We might not need to generate a frame if we don't make any calls
6609 (including calls to __T3E_MISMATCH if this is a vararg function),
6610 don't have any local variables which require stack slots, don't
6611 use alloca and have not determined that we need a frame for other
6612 reasons. */
6614 alpha_procedure_type
6615 = (sa_size || get_frame_size() != 0
6616 || current_function_outgoing_args_size
6617 || current_function_stdarg || current_function_calls_alloca
6618 || frame_pointer_needed)
6619 ? PT_STACK : PT_REGISTER;
6621 /* Always reserve space for saving callee-saved registers if we
6622 need a frame as required by the calling convention. */
6623 if (alpha_procedure_type == PT_STACK)
6624 sa_size = 14;
6626 else if (TARGET_ABI_OPEN_VMS)
6628 /* Start by assuming we can use a register procedure if we don't
6629 make any calls (REG_RA not used) or need to save any
6630 registers and a stack procedure if we do. */
6631 if ((mask[0] >> REG_RA) & 1)
6632 alpha_procedure_type = PT_STACK;
6633 else if (get_frame_size() != 0)
6634 alpha_procedure_type = PT_REGISTER;
6635 else
6636 alpha_procedure_type = PT_NULL;
6638 /* Don't reserve space for saving FP & RA yet. Do that later after we've
6639 made the final decision on stack procedure vs register procedure. */
6640 if (alpha_procedure_type == PT_STACK)
6641 sa_size -= 2;
6643 /* Decide whether to refer to objects off our PV via FP or PV.
6644 If we need FP for something else or if we receive a nonlocal
6645 goto (which expects PV to contain the value), we must use PV.
6646 Otherwise, start by assuming we can use FP. */
6648 vms_base_regno
6649 = (frame_pointer_needed
6650 || current_function_has_nonlocal_label
6651 || alpha_procedure_type == PT_STACK
6652 || current_function_outgoing_args_size)
6653 ? REG_PV : HARD_FRAME_POINTER_REGNUM;
6655 /* If we want to copy PV into FP, we need to find some register
6656 in which to save FP. */
6658 vms_save_fp_regno = -1;
6659 if (vms_base_regno == HARD_FRAME_POINTER_REGNUM)
6660 for (i = 0; i < 32; i++)
6661 if (! fixed_regs[i] && call_used_regs[i] && ! regs_ever_live[i])
6662 vms_save_fp_regno = i;
6664 if (vms_save_fp_regno == -1 && alpha_procedure_type == PT_REGISTER)
6665 vms_base_regno = REG_PV, alpha_procedure_type = PT_STACK;
6666 else if (alpha_procedure_type == PT_NULL)
6667 vms_base_regno = REG_PV;
6669 /* Stack unwinding should be done via FP unless we use it for PV. */
6670 vms_unwind_regno = (vms_base_regno == REG_PV
6671 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
6673 /* If this is a stack procedure, allow space for saving FP and RA. */
6674 if (alpha_procedure_type == PT_STACK)
6675 sa_size += 2;
6677 else
6679 /* Our size must be even (multiple of 16 bytes). */
6680 if (sa_size & 1)
6681 sa_size++;
6684 return sa_size * 8;
6687 /* Define the offset between two registers, one to be eliminated,
6688 and the other its replacement, at the start of a routine. */
6690 HOST_WIDE_INT
6691 alpha_initial_elimination_offset (unsigned int from,
6692 unsigned int to ATTRIBUTE_UNUSED)
6694 HOST_WIDE_INT ret;
6696 ret = alpha_sa_size ();
6697 ret += ALPHA_ROUND (current_function_outgoing_args_size);
6699 if (from == FRAME_POINTER_REGNUM)
6701 else if (from == ARG_POINTER_REGNUM)
6702 ret += (ALPHA_ROUND (get_frame_size ()
6703 + current_function_pretend_args_size)
6704 - current_function_pretend_args_size);
6705 else
6706 abort ();
6708 return ret;
6712 alpha_pv_save_size (void)
6714 alpha_sa_size ();
6715 return alpha_procedure_type == PT_STACK ? 8 : 0;
6719 alpha_using_fp (void)
6721 alpha_sa_size ();
6722 return vms_unwind_regno == HARD_FRAME_POINTER_REGNUM;
6725 #if TARGET_ABI_OPEN_VMS
6727 const struct attribute_spec vms_attribute_table[] =
6729 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
6730 { "overlaid", 0, 0, true, false, false, NULL },
6731 { "global", 0, 0, true, false, false, NULL },
6732 { "initialize", 0, 0, true, false, false, NULL },
6733 { NULL, 0, 0, false, false, false, NULL }
6736 #endif
6738 static int
6739 find_lo_sum_using_gp (rtx *px, void *data ATTRIBUTE_UNUSED)
6741 return GET_CODE (*px) == LO_SUM && XEXP (*px, 0) == pic_offset_table_rtx;
6745 alpha_find_lo_sum_using_gp (rtx insn)
6747 return for_each_rtx (&PATTERN (insn), find_lo_sum_using_gp, NULL) > 0;
6750 static int
6751 alpha_does_function_need_gp (void)
6753 rtx insn;
6755 /* The GP being variable is an OSF abi thing. */
6756 if (! TARGET_ABI_OSF)
6757 return 0;
6759 if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
6760 return 1;
6762 if (current_function_is_thunk)
6763 return 1;
6765 /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first.
6766 Even if we are a static function, we still need to do this in case
6767 our address is taken and passed to something like qsort. */
6769 push_topmost_sequence ();
6770 insn = get_insns ();
6771 pop_topmost_sequence ();
6773 for (; insn; insn = NEXT_INSN (insn))
6774 if (INSN_P (insn)
6775 && GET_CODE (PATTERN (insn)) != USE
6776 && GET_CODE (PATTERN (insn)) != CLOBBER
6777 && get_attr_usegp (insn))
6778 return 1;
6780 return 0;
6784 /* Helper function to set RTX_FRAME_RELATED_P on instructions, including
6785 sequences. */
6787 static rtx
6788 set_frame_related_p (void)
6790 rtx seq = get_insns ();
6791 rtx insn;
6793 end_sequence ();
6795 if (!seq)
6796 return NULL_RTX;
6798 if (INSN_P (seq))
6800 insn = seq;
6801 while (insn != NULL_RTX)
6803 RTX_FRAME_RELATED_P (insn) = 1;
6804 insn = NEXT_INSN (insn);
6806 seq = emit_insn (seq);
6808 else
6810 seq = emit_insn (seq);
6811 RTX_FRAME_RELATED_P (seq) = 1;
6813 return seq;
6816 #define FRP(exp) (start_sequence (), exp, set_frame_related_p ())
6818 /* Write function prologue. */
6820 /* On vms we have two kinds of functions:
6822 - stack frame (PROC_STACK)
6823 these are 'normal' functions with local vars and which are
6824 calling other functions
6825 - register frame (PROC_REGISTER)
6826 keeps all data in registers, needs no stack
6828 We must pass this to the assembler so it can generate the
6829 proper pdsc (procedure descriptor)
6830 This is done with the '.pdesc' command.
6832 On not-vms, we don't really differentiate between the two, as we can
6833 simply allocate stack without saving registers. */
6835 void
6836 alpha_expand_prologue (void)
6838 /* Registers to save. */
6839 unsigned long imask = 0;
6840 unsigned long fmask = 0;
6841 /* Stack space needed for pushing registers clobbered by us. */
6842 HOST_WIDE_INT sa_size;
6843 /* Complete stack size needed. */
6844 HOST_WIDE_INT frame_size;
6845 /* Offset from base reg to register save area. */
6846 HOST_WIDE_INT reg_offset;
6847 rtx sa_reg, mem;
6848 int i;
6850 sa_size = alpha_sa_size ();
6852 frame_size = get_frame_size ();
6853 if (TARGET_ABI_OPEN_VMS)
6854 frame_size = ALPHA_ROUND (sa_size
6855 + (alpha_procedure_type == PT_STACK ? 8 : 0)
6856 + frame_size
6857 + current_function_pretend_args_size);
6858 else if (TARGET_ABI_UNICOSMK)
6859 /* We have to allocate space for the DSIB if we generate a frame. */
6860 frame_size = ALPHA_ROUND (sa_size
6861 + (alpha_procedure_type == PT_STACK ? 48 : 0))
6862 + ALPHA_ROUND (frame_size
6863 + current_function_outgoing_args_size);
6864 else
6865 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
6866 + sa_size
6867 + ALPHA_ROUND (frame_size
6868 + current_function_pretend_args_size));
6870 if (TARGET_ABI_OPEN_VMS)
6871 reg_offset = 8;
6872 else
6873 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
6875 alpha_sa_mask (&imask, &fmask);
6877 /* Emit an insn to reload GP, if needed. */
6878 if (TARGET_ABI_OSF)
6880 alpha_function_needs_gp = alpha_does_function_need_gp ();
6881 if (alpha_function_needs_gp)
6882 emit_insn (gen_prologue_ldgp ());
6885 /* TARGET_PROFILING_NEEDS_GP actually implies that we need to insert
6886 the call to mcount ourselves, rather than having the linker do it
6887 magically in response to -pg. Since _mcount has special linkage,
6888 don't represent the call as a call. */
6889 if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
6890 emit_insn (gen_prologue_mcount ());
6892 if (TARGET_ABI_UNICOSMK)
6893 unicosmk_gen_dsib (&imask);
6895 /* Adjust the stack by the frame size. If the frame size is > 4096
6896 bytes, we need to be sure we probe somewhere in the first and last
6897 4096 bytes (we can probably get away without the latter test) and
6898 every 8192 bytes in between. If the frame size is > 32768, we
6899 do this in a loop. Otherwise, we generate the explicit probe
6900 instructions.
6902 Note that we are only allowed to adjust sp once in the prologue. */
6904 if (frame_size <= 32768)
6906 if (frame_size > 4096)
6908 int probed = 4096;
6911 emit_insn (gen_probe_stack (GEN_INT (TARGET_ABI_UNICOSMK
6912 ? -probed + 64
6913 : -probed)));
6914 while ((probed += 8192) < frame_size);
6916 /* We only have to do this probe if we aren't saving registers. */
6917 if (sa_size == 0 && probed + 4096 < frame_size)
6918 emit_insn (gen_probe_stack (GEN_INT (-frame_size)));
6921 if (frame_size != 0)
6922 FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
6923 GEN_INT (TARGET_ABI_UNICOSMK
6924 ? -frame_size + 64
6925 : -frame_size))));
6927 else
6929 /* Here we generate code to set R22 to SP + 4096 and set R23 to the
6930 number of 8192 byte blocks to probe. We then probe each block
6931 in the loop and then set SP to the proper location. If the
6932 amount remaining is > 4096, we have to do one more probe if we
6933 are not saving any registers. */
6935 HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
6936 HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
6937 rtx ptr = gen_rtx_REG (DImode, 22);
6938 rtx count = gen_rtx_REG (DImode, 23);
6939 rtx seq;
6941 emit_move_insn (count, GEN_INT (blocks));
6942 emit_insn (gen_adddi3 (ptr, stack_pointer_rtx,
6943 GEN_INT (TARGET_ABI_UNICOSMK ? 4096 - 64 : 4096)));
6945 /* Because of the difficulty in emitting a new basic block this
6946 late in the compilation, generate the loop as a single insn. */
6947 emit_insn (gen_prologue_stack_probe_loop (count, ptr));
6949 if (leftover > 4096 && sa_size == 0)
6951 rtx last = gen_rtx_MEM (DImode, plus_constant (ptr, -leftover));
6952 MEM_VOLATILE_P (last) = 1;
6953 emit_move_insn (last, const0_rtx);
6956 if (TARGET_ABI_WINDOWS_NT)
6958 /* For NT stack unwind (done by 'reverse execution'), it's
6959 not OK to take the result of a loop, even though the value
6960 is already in ptr, so we reload it via a single operation
6961 and subtract it to sp.
6963 Yes, that's correct -- we have to reload the whole constant
6964 into a temporary via ldah+lda then subtract from sp. To
6965 ensure we get ldah+lda, we use a special pattern. */
6967 HOST_WIDE_INT lo, hi;
6968 lo = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
6969 hi = frame_size - lo;
6971 emit_move_insn (ptr, GEN_INT (hi));
6972 emit_insn (gen_nt_lda (ptr, GEN_INT (lo)));
6973 seq = emit_insn (gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx,
6974 ptr));
6976 else
6978 seq = emit_insn (gen_adddi3 (stack_pointer_rtx, ptr,
6979 GEN_INT (-leftover)));
6982 /* This alternative is special, because the DWARF code cannot
6983 possibly intuit through the loop above. So we invent this
6984 note it looks at instead. */
6985 RTX_FRAME_RELATED_P (seq) = 1;
6986 REG_NOTES (seq)
6987 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
6988 gen_rtx_SET (VOIDmode, stack_pointer_rtx,
6989 gen_rtx_PLUS (Pmode, stack_pointer_rtx,
6990 GEN_INT (TARGET_ABI_UNICOSMK
6991 ? -frame_size + 64
6992 : -frame_size))),
6993 REG_NOTES (seq));
6996 if (!TARGET_ABI_UNICOSMK)
6998 /* Cope with very large offsets to the register save area. */
6999 sa_reg = stack_pointer_rtx;
7000 if (reg_offset + sa_size > 0x8000)
7002 int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7003 HOST_WIDE_INT bias;
7005 if (low + sa_size <= 0x8000)
7006 bias = reg_offset - low, reg_offset = low;
7007 else
7008 bias = reg_offset, reg_offset = 0;
7010 sa_reg = gen_rtx_REG (DImode, 24);
7011 FRP (emit_insn (gen_adddi3 (sa_reg, stack_pointer_rtx,
7012 GEN_INT (bias))));
7015 /* Save regs in stack order. Beginning with VMS PV. */
7016 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7018 mem = gen_rtx_MEM (DImode, stack_pointer_rtx);
7019 set_mem_alias_set (mem, alpha_sr_alias_set);
7020 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_PV)));
7023 /* Save register RA next. */
7024 if (imask & (1UL << REG_RA))
7026 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7027 set_mem_alias_set (mem, alpha_sr_alias_set);
7028 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA)));
7029 imask &= ~(1UL << REG_RA);
7030 reg_offset += 8;
7033 /* Now save any other registers required to be saved. */
7034 for (i = 0; i < 32; i++)
7035 if (imask & (1UL << i))
7037 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7038 set_mem_alias_set (mem, alpha_sr_alias_set);
7039 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, i)));
7040 reg_offset += 8;
7043 for (i = 0; i < 32; i++)
7044 if (fmask & (1UL << i))
7046 mem = gen_rtx_MEM (DFmode, plus_constant (sa_reg, reg_offset));
7047 set_mem_alias_set (mem, alpha_sr_alias_set);
7048 FRP (emit_move_insn (mem, gen_rtx_REG (DFmode, i+32)));
7049 reg_offset += 8;
7052 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7054 /* The standard frame on the T3E includes space for saving registers.
7055 We just have to use it. We don't have to save the return address and
7056 the old frame pointer here - they are saved in the DSIB. */
7058 reg_offset = -56;
7059 for (i = 9; i < 15; i++)
7060 if (imask & (1UL << i))
7062 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx,
7063 reg_offset));
7064 set_mem_alias_set (mem, alpha_sr_alias_set);
7065 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, i)));
7066 reg_offset -= 8;
7068 for (i = 2; i < 10; i++)
7069 if (fmask & (1UL << i))
7071 mem = gen_rtx_MEM (DFmode, plus_constant (hard_frame_pointer_rtx,
7072 reg_offset));
7073 set_mem_alias_set (mem, alpha_sr_alias_set);
7074 FRP (emit_move_insn (mem, gen_rtx_REG (DFmode, i+32)));
7075 reg_offset -= 8;
7079 if (TARGET_ABI_OPEN_VMS)
7081 if (alpha_procedure_type == PT_REGISTER)
7082 /* Register frame procedures save the fp.
7083 ?? Ought to have a dwarf2 save for this. */
7084 emit_move_insn (gen_rtx_REG (DImode, vms_save_fp_regno),
7085 hard_frame_pointer_rtx);
7087 if (alpha_procedure_type != PT_NULL && vms_base_regno != REG_PV)
7088 emit_insn (gen_force_movdi (gen_rtx_REG (DImode, vms_base_regno),
7089 gen_rtx_REG (DImode, REG_PV)));
7091 if (alpha_procedure_type != PT_NULL
7092 && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7093 FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7095 /* If we have to allocate space for outgoing args, do it now. */
7096 if (current_function_outgoing_args_size != 0)
7098 rtx seq
7099 = emit_move_insn (stack_pointer_rtx,
7100 plus_constant
7101 (hard_frame_pointer_rtx,
7102 - (ALPHA_ROUND
7103 (current_function_outgoing_args_size))));
7105 /* Only set FRAME_RELATED_P on the stack adjustment we just emitted
7106 if ! frame_pointer_needed. Setting the bit will change the CFA
7107 computation rule to use sp again, which would be wrong if we had
7108 frame_pointer_needed, as this means sp might move unpredictably
7109 later on.
7111 Also, note that
7112 frame_pointer_needed
7113 => vms_unwind_regno == HARD_FRAME_POINTER_REGNUM
7115 current_function_outgoing_args_size != 0
7116 => alpha_procedure_type != PT_NULL,
7118 so when we are not setting the bit here, we are guaranteed to
7119 have emited an FRP frame pointer update just before. */
7120 RTX_FRAME_RELATED_P (seq) = ! frame_pointer_needed;
7123 else if (!TARGET_ABI_UNICOSMK)
7125 /* If we need a frame pointer, set it from the stack pointer. */
7126 if (frame_pointer_needed)
7128 if (TARGET_CAN_FAULT_IN_PROLOGUE)
7129 FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7130 else
7131 /* This must always be the last instruction in the
7132 prologue, thus we emit a special move + clobber. */
7133 FRP (emit_insn (gen_init_fp (hard_frame_pointer_rtx,
7134 stack_pointer_rtx, sa_reg)));
7138 /* The ABIs for VMS and OSF/1 say that while we can schedule insns into
7139 the prologue, for exception handling reasons, we cannot do this for
7140 any insn that might fault. We could prevent this for mems with a
7141 (clobber:BLK (scratch)), but this doesn't work for fp insns. So we
7142 have to prevent all such scheduling with a blockage.
7144 Linux, on the other hand, never bothered to implement OSF/1's
7145 exception handling, and so doesn't care about such things. Anyone
7146 planning to use dwarf2 frame-unwind info can also omit the blockage. */
7148 if (! TARGET_CAN_FAULT_IN_PROLOGUE)
7149 emit_insn (gen_blockage ());
7152 /* Output the textual info surrounding the prologue. */
7154 void
7155 alpha_start_function (FILE *file, const char *fnname,
7156 tree decl ATTRIBUTE_UNUSED)
7158 unsigned long imask = 0;
7159 unsigned long fmask = 0;
7160 /* Stack space needed for pushing registers clobbered by us. */
7161 HOST_WIDE_INT sa_size;
7162 /* Complete stack size needed. */
7163 unsigned HOST_WIDE_INT frame_size;
7164 /* Offset from base reg to register save area. */
7165 HOST_WIDE_INT reg_offset;
7166 char *entry_label = (char *) alloca (strlen (fnname) + 6);
7167 int i;
7169 /* Don't emit an extern directive for functions defined in the same file. */
7170 if (TARGET_ABI_UNICOSMK)
7172 tree name_tree;
7173 name_tree = get_identifier (fnname);
7174 TREE_ASM_WRITTEN (name_tree) = 1;
7177 alpha_fnname = fnname;
7178 sa_size = alpha_sa_size ();
7180 frame_size = get_frame_size ();
7181 if (TARGET_ABI_OPEN_VMS)
7182 frame_size = ALPHA_ROUND (sa_size
7183 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7184 + frame_size
7185 + current_function_pretend_args_size);
7186 else if (TARGET_ABI_UNICOSMK)
7187 frame_size = ALPHA_ROUND (sa_size
7188 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7189 + ALPHA_ROUND (frame_size
7190 + current_function_outgoing_args_size);
7191 else
7192 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7193 + sa_size
7194 + ALPHA_ROUND (frame_size
7195 + current_function_pretend_args_size));
7197 if (TARGET_ABI_OPEN_VMS)
7198 reg_offset = 8;
7199 else
7200 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7202 alpha_sa_mask (&imask, &fmask);
7204 /* Ecoff can handle multiple .file directives, so put out file and lineno.
7205 We have to do that before the .ent directive as we cannot switch
7206 files within procedures with native ecoff because line numbers are
7207 linked to procedure descriptors.
7208 Outputting the lineno helps debugging of one line functions as they
7209 would otherwise get no line number at all. Please note that we would
7210 like to put out last_linenum from final.c, but it is not accessible. */
7212 if (write_symbols == SDB_DEBUG)
7214 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7215 ASM_OUTPUT_SOURCE_FILENAME (file,
7216 DECL_SOURCE_FILE (current_function_decl));
7217 #endif
7218 #ifdef ASM_OUTPUT_SOURCE_LINE
7219 if (debug_info_level != DINFO_LEVEL_TERSE)
7220 ASM_OUTPUT_SOURCE_LINE (file,
7221 DECL_SOURCE_LINE (current_function_decl), 0);
7222 #endif
7225 /* Issue function start and label. */
7226 if (TARGET_ABI_OPEN_VMS
7227 || (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive))
7229 fputs ("\t.ent ", file);
7230 assemble_name (file, fnname);
7231 putc ('\n', file);
7233 /* If the function needs GP, we'll write the "..ng" label there.
7234 Otherwise, do it here. */
7235 if (TARGET_ABI_OSF
7236 && ! alpha_function_needs_gp
7237 && ! current_function_is_thunk)
7239 putc ('$', file);
7240 assemble_name (file, fnname);
7241 fputs ("..ng:\n", file);
7245 strcpy (entry_label, fnname);
7246 if (TARGET_ABI_OPEN_VMS)
7247 strcat (entry_label, "..en");
7249 /* For public functions, the label must be globalized by appending an
7250 additional colon. */
7251 if (TARGET_ABI_UNICOSMK && TREE_PUBLIC (decl))
7252 strcat (entry_label, ":");
7254 ASM_OUTPUT_LABEL (file, entry_label);
7255 inside_function = TRUE;
7257 if (TARGET_ABI_OPEN_VMS)
7258 fprintf (file, "\t.base $%d\n", vms_base_regno);
7260 if (!TARGET_ABI_OPEN_VMS && !TARGET_ABI_UNICOSMK && TARGET_IEEE_CONFORMANT
7261 && !flag_inhibit_size_directive)
7263 /* Set flags in procedure descriptor to request IEEE-conformant
7264 math-library routines. The value we set it to is PDSC_EXC_IEEE
7265 (/usr/include/pdsc.h). */
7266 fputs ("\t.eflag 48\n", file);
7269 /* Set up offsets to alpha virtual arg/local debugging pointer. */
7270 alpha_auto_offset = -frame_size + current_function_pretend_args_size;
7271 alpha_arg_offset = -frame_size + 48;
7273 /* Describe our frame. If the frame size is larger than an integer,
7274 print it as zero to avoid an assembler error. We won't be
7275 properly describing such a frame, but that's the best we can do. */
7276 if (TARGET_ABI_UNICOSMK)
7278 else if (TARGET_ABI_OPEN_VMS)
7279 fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,"
7280 HOST_WIDE_INT_PRINT_DEC "\n",
7281 vms_unwind_regno,
7282 frame_size >= (1UL << 31) ? 0 : frame_size,
7283 reg_offset);
7284 else if (!flag_inhibit_size_directive)
7285 fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,%d\n",
7286 (frame_pointer_needed
7287 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
7288 frame_size >= (1UL << 31) ? 0 : frame_size,
7289 current_function_pretend_args_size);
7291 /* Describe which registers were spilled. */
7292 if (TARGET_ABI_UNICOSMK)
7294 else if (TARGET_ABI_OPEN_VMS)
7296 if (imask)
7297 /* ??? Does VMS care if mask contains ra? The old code didn't
7298 set it, so I don't here. */
7299 fprintf (file, "\t.mask 0x%lx,0\n", imask & ~(1UL << REG_RA));
7300 if (fmask)
7301 fprintf (file, "\t.fmask 0x%lx,0\n", fmask);
7302 if (alpha_procedure_type == PT_REGISTER)
7303 fprintf (file, "\t.fp_save $%d\n", vms_save_fp_regno);
7305 else if (!flag_inhibit_size_directive)
7307 if (imask)
7309 fprintf (file, "\t.mask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", imask,
7310 frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7312 for (i = 0; i < 32; ++i)
7313 if (imask & (1UL << i))
7314 reg_offset += 8;
7317 if (fmask)
7318 fprintf (file, "\t.fmask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", fmask,
7319 frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7322 #if TARGET_ABI_OPEN_VMS
7323 /* Ifdef'ed cause link_section are only available then. */
7324 readonly_data_section ();
7325 fprintf (file, "\t.align 3\n");
7326 assemble_name (file, fnname); fputs ("..na:\n", file);
7327 fputs ("\t.ascii \"", file);
7328 assemble_name (file, fnname);
7329 fputs ("\\0\"\n", file);
7330 alpha_need_linkage (fnname, 1);
7331 text_section ();
7332 #endif
7335 /* Emit the .prologue note at the scheduled end of the prologue. */
7337 static void
7338 alpha_output_function_end_prologue (FILE *file)
7340 if (TARGET_ABI_UNICOSMK)
7342 else if (TARGET_ABI_OPEN_VMS)
7343 fputs ("\t.prologue\n", file);
7344 else if (TARGET_ABI_WINDOWS_NT)
7345 fputs ("\t.prologue 0\n", file);
7346 else if (!flag_inhibit_size_directive)
7347 fprintf (file, "\t.prologue %d\n",
7348 alpha_function_needs_gp || current_function_is_thunk);
7351 /* Write function epilogue. */
7353 /* ??? At some point we will want to support full unwind, and so will
7354 need to mark the epilogue as well. At the moment, we just confuse
7355 dwarf2out. */
7356 #undef FRP
7357 #define FRP(exp) exp
7359 void
7360 alpha_expand_epilogue (void)
7362 /* Registers to save. */
7363 unsigned long imask = 0;
7364 unsigned long fmask = 0;
7365 /* Stack space needed for pushing registers clobbered by us. */
7366 HOST_WIDE_INT sa_size;
7367 /* Complete stack size needed. */
7368 HOST_WIDE_INT frame_size;
7369 /* Offset from base reg to register save area. */
7370 HOST_WIDE_INT reg_offset;
7371 int fp_is_frame_pointer, fp_offset;
7372 rtx sa_reg, sa_reg_exp = NULL;
7373 rtx sp_adj1, sp_adj2, mem;
7374 rtx eh_ofs;
7375 int i;
7377 sa_size = alpha_sa_size ();
7379 frame_size = get_frame_size ();
7380 if (TARGET_ABI_OPEN_VMS)
7381 frame_size = ALPHA_ROUND (sa_size
7382 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7383 + frame_size
7384 + current_function_pretend_args_size);
7385 else if (TARGET_ABI_UNICOSMK)
7386 frame_size = ALPHA_ROUND (sa_size
7387 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7388 + ALPHA_ROUND (frame_size
7389 + current_function_outgoing_args_size);
7390 else
7391 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7392 + sa_size
7393 + ALPHA_ROUND (frame_size
7394 + current_function_pretend_args_size));
7396 if (TARGET_ABI_OPEN_VMS)
7398 if (alpha_procedure_type == PT_STACK)
7399 reg_offset = 8;
7400 else
7401 reg_offset = 0;
7403 else
7404 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7406 alpha_sa_mask (&imask, &fmask);
7408 fp_is_frame_pointer
7409 = ((TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7410 || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed));
7411 fp_offset = 0;
7412 sa_reg = stack_pointer_rtx;
7414 if (current_function_calls_eh_return)
7415 eh_ofs = EH_RETURN_STACKADJ_RTX;
7416 else
7417 eh_ofs = NULL_RTX;
7419 if (!TARGET_ABI_UNICOSMK && sa_size)
7421 /* If we have a frame pointer, restore SP from it. */
7422 if ((TARGET_ABI_OPEN_VMS
7423 && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7424 || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed))
7425 FRP (emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx));
7427 /* Cope with very large offsets to the register save area. */
7428 if (reg_offset + sa_size > 0x8000)
7430 int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7431 HOST_WIDE_INT bias;
7433 if (low + sa_size <= 0x8000)
7434 bias = reg_offset - low, reg_offset = low;
7435 else
7436 bias = reg_offset, reg_offset = 0;
7438 sa_reg = gen_rtx_REG (DImode, 22);
7439 sa_reg_exp = plus_constant (stack_pointer_rtx, bias);
7441 FRP (emit_move_insn (sa_reg, sa_reg_exp));
7444 /* Restore registers in order, excepting a true frame pointer. */
7446 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7447 if (! eh_ofs)
7448 set_mem_alias_set (mem, alpha_sr_alias_set);
7449 FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7451 reg_offset += 8;
7452 imask &= ~(1UL << REG_RA);
7454 for (i = 0; i < 32; ++i)
7455 if (imask & (1UL << i))
7457 if (i == HARD_FRAME_POINTER_REGNUM && fp_is_frame_pointer)
7458 fp_offset = reg_offset;
7459 else
7461 mem = gen_rtx_MEM (DImode, plus_constant(sa_reg, reg_offset));
7462 set_mem_alias_set (mem, alpha_sr_alias_set);
7463 FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7465 reg_offset += 8;
7468 for (i = 0; i < 32; ++i)
7469 if (fmask & (1UL << i))
7471 mem = gen_rtx_MEM (DFmode, plus_constant(sa_reg, reg_offset));
7472 set_mem_alias_set (mem, alpha_sr_alias_set);
7473 FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7474 reg_offset += 8;
7477 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7479 /* Restore callee-saved general-purpose registers. */
7481 reg_offset = -56;
7483 for (i = 9; i < 15; i++)
7484 if (imask & (1UL << i))
7486 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx,
7487 reg_offset));
7488 set_mem_alias_set (mem, alpha_sr_alias_set);
7489 FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7490 reg_offset -= 8;
7493 for (i = 2; i < 10; i++)
7494 if (fmask & (1UL << i))
7496 mem = gen_rtx_MEM (DFmode, plus_constant(hard_frame_pointer_rtx,
7497 reg_offset));
7498 set_mem_alias_set (mem, alpha_sr_alias_set);
7499 FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7500 reg_offset -= 8;
7503 /* Restore the return address from the DSIB. */
7505 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx, -8));
7506 set_mem_alias_set (mem, alpha_sr_alias_set);
7507 FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7510 if (frame_size || eh_ofs)
7512 sp_adj1 = stack_pointer_rtx;
7514 if (eh_ofs)
7516 sp_adj1 = gen_rtx_REG (DImode, 23);
7517 emit_move_insn (sp_adj1,
7518 gen_rtx_PLUS (Pmode, stack_pointer_rtx, eh_ofs));
7521 /* If the stack size is large, begin computation into a temporary
7522 register so as not to interfere with a potential fp restore,
7523 which must be consecutive with an SP restore. */
7524 if (frame_size < 32768
7525 && ! (TARGET_ABI_UNICOSMK && current_function_calls_alloca))
7526 sp_adj2 = GEN_INT (frame_size);
7527 else if (TARGET_ABI_UNICOSMK)
7529 sp_adj1 = gen_rtx_REG (DImode, 23);
7530 FRP (emit_move_insn (sp_adj1, hard_frame_pointer_rtx));
7531 sp_adj2 = const0_rtx;
7533 else if (frame_size < 0x40007fffL)
7535 int low = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
7537 sp_adj2 = plus_constant (sp_adj1, frame_size - low);
7538 if (sa_reg_exp && rtx_equal_p (sa_reg_exp, sp_adj2))
7539 sp_adj1 = sa_reg;
7540 else
7542 sp_adj1 = gen_rtx_REG (DImode, 23);
7543 FRP (emit_move_insn (sp_adj1, sp_adj2));
7545 sp_adj2 = GEN_INT (low);
7547 else
7549 rtx tmp = gen_rtx_REG (DImode, 23);
7550 FRP (sp_adj2 = alpha_emit_set_const (tmp, DImode, frame_size, 3));
7551 if (!sp_adj2)
7553 /* We can't drop new things to memory this late, afaik,
7554 so build it up by pieces. */
7555 FRP (sp_adj2 = alpha_emit_set_long_const (tmp, frame_size,
7556 -(frame_size < 0)));
7557 if (!sp_adj2)
7558 abort ();
7562 /* From now on, things must be in order. So emit blockages. */
7564 /* Restore the frame pointer. */
7565 if (TARGET_ABI_UNICOSMK)
7567 emit_insn (gen_blockage ());
7568 mem = gen_rtx_MEM (DImode,
7569 plus_constant (hard_frame_pointer_rtx, -16));
7570 set_mem_alias_set (mem, alpha_sr_alias_set);
7571 FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7573 else if (fp_is_frame_pointer)
7575 emit_insn (gen_blockage ());
7576 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, fp_offset));
7577 set_mem_alias_set (mem, alpha_sr_alias_set);
7578 FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7580 else if (TARGET_ABI_OPEN_VMS)
7582 emit_insn (gen_blockage ());
7583 FRP (emit_move_insn (hard_frame_pointer_rtx,
7584 gen_rtx_REG (DImode, vms_save_fp_regno)));
7587 /* Restore the stack pointer. */
7588 emit_insn (gen_blockage ());
7589 if (sp_adj2 == const0_rtx)
7590 FRP (emit_move_insn (stack_pointer_rtx, sp_adj1));
7591 else
7592 FRP (emit_move_insn (stack_pointer_rtx,
7593 gen_rtx_PLUS (DImode, sp_adj1, sp_adj2)));
7595 else
7597 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_REGISTER)
7599 emit_insn (gen_blockage ());
7600 FRP (emit_move_insn (hard_frame_pointer_rtx,
7601 gen_rtx_REG (DImode, vms_save_fp_regno)));
7603 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type != PT_STACK)
7605 /* Decrement the frame pointer if the function does not have a
7606 frame. */
7608 emit_insn (gen_blockage ());
7609 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
7610 hard_frame_pointer_rtx, GEN_INT (-1))));
7615 /* Output the rest of the textual info surrounding the epilogue. */
7617 void
7618 alpha_end_function (FILE *file, const char *fnname, tree decl ATTRIBUTE_UNUSED)
7620 /* End the function. */
7621 if (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive)
7623 fputs ("\t.end ", file);
7624 assemble_name (file, fnname);
7625 putc ('\n', file);
7627 inside_function = FALSE;
7629 #if TARGET_ABI_OPEN_VMS
7630 alpha_write_linkage (file, fnname, decl);
7631 #endif
7633 /* Output jump tables and the static subroutine information block. */
7634 if (TARGET_ABI_UNICOSMK)
7636 unicosmk_output_ssib (file, fnname);
7637 unicosmk_output_deferred_case_vectors (file);
7641 #if TARGET_ABI_OSF
7642 /* Emit a tail call to FUNCTION after adjusting THIS by DELTA.
7644 In order to avoid the hordes of differences between generated code
7645 with and without TARGET_EXPLICIT_RELOCS, and to avoid duplicating
7646 lots of code loading up large constants, generate rtl and emit it
7647 instead of going straight to text.
7649 Not sure why this idea hasn't been explored before... */
7651 static void
7652 alpha_output_mi_thunk_osf (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
7653 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
7654 tree function)
7656 HOST_WIDE_INT hi, lo;
7657 rtx this, insn, funexp;
7659 /* We always require a valid GP. */
7660 emit_insn (gen_prologue_ldgp ());
7661 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
7663 /* Find the "this" pointer. If the function returns a structure,
7664 the structure return pointer is in $16. */
7665 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
7666 this = gen_rtx_REG (Pmode, 17);
7667 else
7668 this = gen_rtx_REG (Pmode, 16);
7670 /* Add DELTA. When possible we use ldah+lda. Otherwise load the
7671 entire constant for the add. */
7672 lo = ((delta & 0xffff) ^ 0x8000) - 0x8000;
7673 hi = (((delta - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7674 if (hi + lo == delta)
7676 if (hi)
7677 emit_insn (gen_adddi3 (this, this, GEN_INT (hi)));
7678 if (lo)
7679 emit_insn (gen_adddi3 (this, this, GEN_INT (lo)));
7681 else
7683 rtx tmp = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 0),
7684 delta, -(delta < 0));
7685 emit_insn (gen_adddi3 (this, this, tmp));
7688 /* Add a delta stored in the vtable at VCALL_OFFSET. */
7689 if (vcall_offset)
7691 rtx tmp, tmp2;
7693 tmp = gen_rtx_REG (Pmode, 0);
7694 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
7696 lo = ((vcall_offset & 0xffff) ^ 0x8000) - 0x8000;
7697 hi = (((vcall_offset - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7698 if (hi + lo == vcall_offset)
7700 if (hi)
7701 emit_insn (gen_adddi3 (tmp, tmp, GEN_INT (hi)));
7703 else
7705 tmp2 = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 1),
7706 vcall_offset, -(vcall_offset < 0));
7707 emit_insn (gen_adddi3 (tmp, tmp, tmp2));
7708 lo = 0;
7710 if (lo)
7711 tmp2 = gen_rtx_PLUS (Pmode, tmp, GEN_INT (lo));
7712 else
7713 tmp2 = tmp;
7714 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp2));
7716 emit_insn (gen_adddi3 (this, this, tmp));
7719 /* Generate a tail call to the target function. */
7720 if (! TREE_USED (function))
7722 assemble_external (function);
7723 TREE_USED (function) = 1;
7725 funexp = XEXP (DECL_RTL (function), 0);
7726 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
7727 insn = emit_call_insn (gen_sibcall (funexp, const0_rtx));
7728 SIBLING_CALL_P (insn) = 1;
7730 /* Run just enough of rest_of_compilation to get the insns emitted.
7731 There's not really enough bulk here to make other passes such as
7732 instruction scheduling worth while. Note that use_thunk calls
7733 assemble_start_function and assemble_end_function. */
7734 insn = get_insns ();
7735 insn_locators_initialize ();
7736 shorten_branches (insn);
7737 final_start_function (insn, file, 1);
7738 final (insn, file, 1, 0);
7739 final_end_function ();
7741 #endif /* TARGET_ABI_OSF */
7743 /* Debugging support. */
7745 #include "gstab.h"
7747 /* Count the number of sdb related labels are generated (to find block
7748 start and end boundaries). */
7750 int sdb_label_count = 0;
7752 /* Next label # for each statement. */
7754 static int sym_lineno = 0;
7756 /* Count the number of .file directives, so that .loc is up to date. */
7758 static int num_source_filenames = 0;
7760 /* Name of the file containing the current function. */
7762 static const char *current_function_file = "";
7764 /* Offsets to alpha virtual arg/local debugging pointers. */
7766 long alpha_arg_offset;
7767 long alpha_auto_offset;
7769 /* Emit a new filename to a stream. */
7771 void
7772 alpha_output_filename (FILE *stream, const char *name)
7774 static int first_time = TRUE;
7775 char ltext_label_name[100];
7777 if (first_time)
7779 first_time = FALSE;
7780 ++num_source_filenames;
7781 current_function_file = name;
7782 fprintf (stream, "\t.file\t%d ", num_source_filenames);
7783 output_quoted_string (stream, name);
7784 fprintf (stream, "\n");
7785 if (!TARGET_GAS && write_symbols == DBX_DEBUG)
7786 fprintf (stream, "\t#@stabs\n");
7789 else if (write_symbols == DBX_DEBUG)
7791 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
7792 fprintf (stream, "%s", ASM_STABS_OP);
7793 output_quoted_string (stream, name);
7794 fprintf (stream, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
7797 else if (name != current_function_file
7798 && strcmp (name, current_function_file) != 0)
7800 if (inside_function && ! TARGET_GAS)
7801 fprintf (stream, "\t#.file\t%d ", num_source_filenames);
7802 else
7804 ++num_source_filenames;
7805 current_function_file = name;
7806 fprintf (stream, "\t.file\t%d ", num_source_filenames);
7809 output_quoted_string (stream, name);
7810 fprintf (stream, "\n");
7814 /* Emit a linenumber to a stream. */
7816 void
7817 alpha_output_lineno (FILE *stream, int line)
7819 if (write_symbols == DBX_DEBUG)
7821 /* mips-tfile doesn't understand .stabd directives. */
7822 ++sym_lineno;
7823 fprintf (stream, "$LM%d:\n%s%d,0,%d,$LM%d\n",
7824 sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
7826 else
7827 fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
7830 /* Structure to show the current status of registers and memory. */
7832 struct shadow_summary
7834 struct {
7835 unsigned int i : 31; /* Mask of int regs */
7836 unsigned int fp : 31; /* Mask of fp regs */
7837 unsigned int mem : 1; /* mem == imem | fpmem */
7838 } used, defd;
7841 /* Summary the effects of expression X on the machine. Update SUM, a pointer
7842 to the summary structure. SET is nonzero if the insn is setting the
7843 object, otherwise zero. */
7845 static void
7846 summarize_insn (rtx x, struct shadow_summary *sum, int set)
7848 const char *format_ptr;
7849 int i, j;
7851 if (x == 0)
7852 return;
7854 switch (GET_CODE (x))
7856 /* ??? Note that this case would be incorrect if the Alpha had a
7857 ZERO_EXTRACT in SET_DEST. */
7858 case SET:
7859 summarize_insn (SET_SRC (x), sum, 0);
7860 summarize_insn (SET_DEST (x), sum, 1);
7861 break;
7863 case CLOBBER:
7864 summarize_insn (XEXP (x, 0), sum, 1);
7865 break;
7867 case USE:
7868 summarize_insn (XEXP (x, 0), sum, 0);
7869 break;
7871 case ASM_OPERANDS:
7872 for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
7873 summarize_insn (ASM_OPERANDS_INPUT (x, i), sum, 0);
7874 break;
7876 case PARALLEL:
7877 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
7878 summarize_insn (XVECEXP (x, 0, i), sum, 0);
7879 break;
7881 case SUBREG:
7882 summarize_insn (SUBREG_REG (x), sum, 0);
7883 break;
7885 case REG:
7887 int regno = REGNO (x);
7888 unsigned long mask = ((unsigned long) 1) << (regno % 32);
7890 if (regno == 31 || regno == 63)
7891 break;
7893 if (set)
7895 if (regno < 32)
7896 sum->defd.i |= mask;
7897 else
7898 sum->defd.fp |= mask;
7900 else
7902 if (regno < 32)
7903 sum->used.i |= mask;
7904 else
7905 sum->used.fp |= mask;
7908 break;
7910 case MEM:
7911 if (set)
7912 sum->defd.mem = 1;
7913 else
7914 sum->used.mem = 1;
7916 /* Find the regs used in memory address computation: */
7917 summarize_insn (XEXP (x, 0), sum, 0);
7918 break;
7920 case CONST_INT: case CONST_DOUBLE:
7921 case SYMBOL_REF: case LABEL_REF: case CONST:
7922 case SCRATCH: case ASM_INPUT:
7923 break;
7925 /* Handle common unary and binary ops for efficiency. */
7926 case COMPARE: case PLUS: case MINUS: case MULT: case DIV:
7927 case MOD: case UDIV: case UMOD: case AND: case IOR:
7928 case XOR: case ASHIFT: case ROTATE: case ASHIFTRT: case LSHIFTRT:
7929 case ROTATERT: case SMIN: case SMAX: case UMIN: case UMAX:
7930 case NE: case EQ: case GE: case GT: case LE:
7931 case LT: case GEU: case GTU: case LEU: case LTU:
7932 summarize_insn (XEXP (x, 0), sum, 0);
7933 summarize_insn (XEXP (x, 1), sum, 0);
7934 break;
7936 case NEG: case NOT: case SIGN_EXTEND: case ZERO_EXTEND:
7937 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: case FLOAT:
7938 case FIX: case UNSIGNED_FLOAT: case UNSIGNED_FIX: case ABS:
7939 case SQRT: case FFS:
7940 summarize_insn (XEXP (x, 0), sum, 0);
7941 break;
7943 default:
7944 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
7945 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
7946 switch (format_ptr[i])
7948 case 'e':
7949 summarize_insn (XEXP (x, i), sum, 0);
7950 break;
7952 case 'E':
7953 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
7954 summarize_insn (XVECEXP (x, i, j), sum, 0);
7955 break;
7957 case 'i':
7958 break;
7960 default:
7961 abort ();
7966 /* Ensure a sufficient number of `trapb' insns are in the code when
7967 the user requests code with a trap precision of functions or
7968 instructions.
7970 In naive mode, when the user requests a trap-precision of
7971 "instruction", a trapb is needed after every instruction that may
7972 generate a trap. This ensures that the code is resumption safe but
7973 it is also slow.
7975 When optimizations are turned on, we delay issuing a trapb as long
7976 as possible. In this context, a trap shadow is the sequence of
7977 instructions that starts with a (potentially) trap generating
7978 instruction and extends to the next trapb or call_pal instruction
7979 (but GCC never generates call_pal by itself). We can delay (and
7980 therefore sometimes omit) a trapb subject to the following
7981 conditions:
7983 (a) On entry to the trap shadow, if any Alpha register or memory
7984 location contains a value that is used as an operand value by some
7985 instruction in the trap shadow (live on entry), then no instruction
7986 in the trap shadow may modify the register or memory location.
7988 (b) Within the trap shadow, the computation of the base register
7989 for a memory load or store instruction may not involve using the
7990 result of an instruction that might generate an UNPREDICTABLE
7991 result.
7993 (c) Within the trap shadow, no register may be used more than once
7994 as a destination register. (This is to make life easier for the
7995 trap-handler.)
7997 (d) The trap shadow may not include any branch instructions. */
7999 static void
8000 alpha_handle_trap_shadows (void)
8002 struct shadow_summary shadow;
8003 int trap_pending, exception_nesting;
8004 rtx i, n;
8006 trap_pending = 0;
8007 exception_nesting = 0;
8008 shadow.used.i = 0;
8009 shadow.used.fp = 0;
8010 shadow.used.mem = 0;
8011 shadow.defd = shadow.used;
8013 for (i = get_insns (); i ; i = NEXT_INSN (i))
8015 if (GET_CODE (i) == NOTE)
8017 switch (NOTE_LINE_NUMBER (i))
8019 case NOTE_INSN_EH_REGION_BEG:
8020 exception_nesting++;
8021 if (trap_pending)
8022 goto close_shadow;
8023 break;
8025 case NOTE_INSN_EH_REGION_END:
8026 exception_nesting--;
8027 if (trap_pending)
8028 goto close_shadow;
8029 break;
8031 case NOTE_INSN_EPILOGUE_BEG:
8032 if (trap_pending && alpha_tp >= ALPHA_TP_FUNC)
8033 goto close_shadow;
8034 break;
8037 else if (trap_pending)
8039 if (alpha_tp == ALPHA_TP_FUNC)
8041 if (GET_CODE (i) == JUMP_INSN
8042 && GET_CODE (PATTERN (i)) == RETURN)
8043 goto close_shadow;
8045 else if (alpha_tp == ALPHA_TP_INSN)
8047 if (optimize > 0)
8049 struct shadow_summary sum;
8051 sum.used.i = 0;
8052 sum.used.fp = 0;
8053 sum.used.mem = 0;
8054 sum.defd = sum.used;
8056 switch (GET_CODE (i))
8058 case INSN:
8059 /* Annoyingly, get_attr_trap will abort on these. */
8060 if (GET_CODE (PATTERN (i)) == USE
8061 || GET_CODE (PATTERN (i)) == CLOBBER)
8062 break;
8064 summarize_insn (PATTERN (i), &sum, 0);
8066 if ((sum.defd.i & shadow.defd.i)
8067 || (sum.defd.fp & shadow.defd.fp))
8069 /* (c) would be violated */
8070 goto close_shadow;
8073 /* Combine shadow with summary of current insn: */
8074 shadow.used.i |= sum.used.i;
8075 shadow.used.fp |= sum.used.fp;
8076 shadow.used.mem |= sum.used.mem;
8077 shadow.defd.i |= sum.defd.i;
8078 shadow.defd.fp |= sum.defd.fp;
8079 shadow.defd.mem |= sum.defd.mem;
8081 if ((sum.defd.i & shadow.used.i)
8082 || (sum.defd.fp & shadow.used.fp)
8083 || (sum.defd.mem & shadow.used.mem))
8085 /* (a) would be violated (also takes care of (b)) */
8086 if (get_attr_trap (i) == TRAP_YES
8087 && ((sum.defd.i & sum.used.i)
8088 || (sum.defd.fp & sum.used.fp)))
8089 abort ();
8091 goto close_shadow;
8093 break;
8095 case JUMP_INSN:
8096 case CALL_INSN:
8097 case CODE_LABEL:
8098 goto close_shadow;
8100 default:
8101 abort ();
8104 else
8106 close_shadow:
8107 n = emit_insn_before (gen_trapb (), i);
8108 PUT_MODE (n, TImode);
8109 PUT_MODE (i, TImode);
8110 trap_pending = 0;
8111 shadow.used.i = 0;
8112 shadow.used.fp = 0;
8113 shadow.used.mem = 0;
8114 shadow.defd = shadow.used;
8119 if ((exception_nesting > 0 || alpha_tp >= ALPHA_TP_FUNC)
8120 && GET_CODE (i) == INSN
8121 && GET_CODE (PATTERN (i)) != USE
8122 && GET_CODE (PATTERN (i)) != CLOBBER
8123 && get_attr_trap (i) == TRAP_YES)
8125 if (optimize && !trap_pending)
8126 summarize_insn (PATTERN (i), &shadow, 0);
8127 trap_pending = 1;
8132 /* Alpha can only issue instruction groups simultaneously if they are
8133 suitibly aligned. This is very processor-specific. */
8135 enum alphaev4_pipe {
8136 EV4_STOP = 0,
8137 EV4_IB0 = 1,
8138 EV4_IB1 = 2,
8139 EV4_IBX = 4
8142 enum alphaev5_pipe {
8143 EV5_STOP = 0,
8144 EV5_NONE = 1,
8145 EV5_E01 = 2,
8146 EV5_E0 = 4,
8147 EV5_E1 = 8,
8148 EV5_FAM = 16,
8149 EV5_FA = 32,
8150 EV5_FM = 64
8153 static enum alphaev4_pipe
8154 alphaev4_insn_pipe (rtx insn)
8156 if (recog_memoized (insn) < 0)
8157 return EV4_STOP;
8158 if (get_attr_length (insn) != 4)
8159 return EV4_STOP;
8161 switch (get_attr_type (insn))
8163 case TYPE_ILD:
8164 case TYPE_FLD:
8165 return EV4_IBX;
8167 case TYPE_LDSYM:
8168 case TYPE_IADD:
8169 case TYPE_ILOG:
8170 case TYPE_ICMOV:
8171 case TYPE_ICMP:
8172 case TYPE_IST:
8173 case TYPE_FST:
8174 case TYPE_SHIFT:
8175 case TYPE_IMUL:
8176 case TYPE_FBR:
8177 return EV4_IB0;
8179 case TYPE_MISC:
8180 case TYPE_IBR:
8181 case TYPE_JSR:
8182 case TYPE_CALLPAL:
8183 case TYPE_FCPYS:
8184 case TYPE_FCMOV:
8185 case TYPE_FADD:
8186 case TYPE_FDIV:
8187 case TYPE_FMUL:
8188 return EV4_IB1;
8190 default:
8191 abort ();
8195 static enum alphaev5_pipe
8196 alphaev5_insn_pipe (rtx insn)
8198 if (recog_memoized (insn) < 0)
8199 return EV5_STOP;
8200 if (get_attr_length (insn) != 4)
8201 return EV5_STOP;
8203 switch (get_attr_type (insn))
8205 case TYPE_ILD:
8206 case TYPE_FLD:
8207 case TYPE_LDSYM:
8208 case TYPE_IADD:
8209 case TYPE_ILOG:
8210 case TYPE_ICMOV:
8211 case TYPE_ICMP:
8212 return EV5_E01;
8214 case TYPE_IST:
8215 case TYPE_FST:
8216 case TYPE_SHIFT:
8217 case TYPE_IMUL:
8218 case TYPE_MISC:
8219 case TYPE_MVI:
8220 return EV5_E0;
8222 case TYPE_IBR:
8223 case TYPE_JSR:
8224 case TYPE_CALLPAL:
8225 return EV5_E1;
8227 case TYPE_FCPYS:
8228 return EV5_FAM;
8230 case TYPE_FBR:
8231 case TYPE_FCMOV:
8232 case TYPE_FADD:
8233 case TYPE_FDIV:
8234 return EV5_FA;
8236 case TYPE_FMUL:
8237 return EV5_FM;
8239 default:
8240 abort();
8244 /* IN_USE is a mask of the slots currently filled within the insn group.
8245 The mask bits come from alphaev4_pipe above. If EV4_IBX is set, then
8246 the insn in EV4_IB0 can be swapped by the hardware into EV4_IB1.
8248 LEN is, of course, the length of the group in bytes. */
8250 static rtx
8251 alphaev4_next_group (rtx insn, int *pin_use, int *plen)
8253 int len, in_use;
8255 len = in_use = 0;
8257 if (! INSN_P (insn)
8258 || GET_CODE (PATTERN (insn)) == CLOBBER
8259 || GET_CODE (PATTERN (insn)) == USE)
8260 goto next_and_done;
8262 while (1)
8264 enum alphaev4_pipe pipe;
8266 pipe = alphaev4_insn_pipe (insn);
8267 switch (pipe)
8269 case EV4_STOP:
8270 /* Force complex instructions to start new groups. */
8271 if (in_use)
8272 goto done;
8274 /* If this is a completely unrecognized insn, its an asm.
8275 We don't know how long it is, so record length as -1 to
8276 signal a needed realignment. */
8277 if (recog_memoized (insn) < 0)
8278 len = -1;
8279 else
8280 len = get_attr_length (insn);
8281 goto next_and_done;
8283 case EV4_IBX:
8284 if (in_use & EV4_IB0)
8286 if (in_use & EV4_IB1)
8287 goto done;
8288 in_use |= EV4_IB1;
8290 else
8291 in_use |= EV4_IB0 | EV4_IBX;
8292 break;
8294 case EV4_IB0:
8295 if (in_use & EV4_IB0)
8297 if (!(in_use & EV4_IBX) || (in_use & EV4_IB1))
8298 goto done;
8299 in_use |= EV4_IB1;
8301 in_use |= EV4_IB0;
8302 break;
8304 case EV4_IB1:
8305 if (in_use & EV4_IB1)
8306 goto done;
8307 in_use |= EV4_IB1;
8308 break;
8310 default:
8311 abort();
8313 len += 4;
8315 /* Haifa doesn't do well scheduling branches. */
8316 if (GET_CODE (insn) == JUMP_INSN)
8317 goto next_and_done;
8319 next:
8320 insn = next_nonnote_insn (insn);
8322 if (!insn || ! INSN_P (insn))
8323 goto done;
8325 /* Let Haifa tell us where it thinks insn group boundaries are. */
8326 if (GET_MODE (insn) == TImode)
8327 goto done;
8329 if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8330 goto next;
8333 next_and_done:
8334 insn = next_nonnote_insn (insn);
8336 done:
8337 *plen = len;
8338 *pin_use = in_use;
8339 return insn;
8342 /* IN_USE is a mask of the slots currently filled within the insn group.
8343 The mask bits come from alphaev5_pipe above. If EV5_E01 is set, then
8344 the insn in EV5_E0 can be swapped by the hardware into EV5_E1.
8346 LEN is, of course, the length of the group in bytes. */
8348 static rtx
8349 alphaev5_next_group (rtx insn, int *pin_use, int *plen)
8351 int len, in_use;
8353 len = in_use = 0;
8355 if (! INSN_P (insn)
8356 || GET_CODE (PATTERN (insn)) == CLOBBER
8357 || GET_CODE (PATTERN (insn)) == USE)
8358 goto next_and_done;
8360 while (1)
8362 enum alphaev5_pipe pipe;
8364 pipe = alphaev5_insn_pipe (insn);
8365 switch (pipe)
8367 case EV5_STOP:
8368 /* Force complex instructions to start new groups. */
8369 if (in_use)
8370 goto done;
8372 /* If this is a completely unrecognized insn, its an asm.
8373 We don't know how long it is, so record length as -1 to
8374 signal a needed realignment. */
8375 if (recog_memoized (insn) < 0)
8376 len = -1;
8377 else
8378 len = get_attr_length (insn);
8379 goto next_and_done;
8381 /* ??? Most of the places below, we would like to abort, as
8382 it would indicate an error either in Haifa, or in the
8383 scheduling description. Unfortunately, Haifa never
8384 schedules the last instruction of the BB, so we don't
8385 have an accurate TI bit to go off. */
8386 case EV5_E01:
8387 if (in_use & EV5_E0)
8389 if (in_use & EV5_E1)
8390 goto done;
8391 in_use |= EV5_E1;
8393 else
8394 in_use |= EV5_E0 | EV5_E01;
8395 break;
8397 case EV5_E0:
8398 if (in_use & EV5_E0)
8400 if (!(in_use & EV5_E01) || (in_use & EV5_E1))
8401 goto done;
8402 in_use |= EV5_E1;
8404 in_use |= EV5_E0;
8405 break;
8407 case EV5_E1:
8408 if (in_use & EV5_E1)
8409 goto done;
8410 in_use |= EV5_E1;
8411 break;
8413 case EV5_FAM:
8414 if (in_use & EV5_FA)
8416 if (in_use & EV5_FM)
8417 goto done;
8418 in_use |= EV5_FM;
8420 else
8421 in_use |= EV5_FA | EV5_FAM;
8422 break;
8424 case EV5_FA:
8425 if (in_use & EV5_FA)
8426 goto done;
8427 in_use |= EV5_FA;
8428 break;
8430 case EV5_FM:
8431 if (in_use & EV5_FM)
8432 goto done;
8433 in_use |= EV5_FM;
8434 break;
8436 case EV5_NONE:
8437 break;
8439 default:
8440 abort();
8442 len += 4;
8444 /* Haifa doesn't do well scheduling branches. */
8445 /* ??? If this is predicted not-taken, slotting continues, except
8446 that no more IBR, FBR, or JSR insns may be slotted. */
8447 if (GET_CODE (insn) == JUMP_INSN)
8448 goto next_and_done;
8450 next:
8451 insn = next_nonnote_insn (insn);
8453 if (!insn || ! INSN_P (insn))
8454 goto done;
8456 /* Let Haifa tell us where it thinks insn group boundaries are. */
8457 if (GET_MODE (insn) == TImode)
8458 goto done;
8460 if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8461 goto next;
8464 next_and_done:
8465 insn = next_nonnote_insn (insn);
8467 done:
8468 *plen = len;
8469 *pin_use = in_use;
8470 return insn;
8473 static rtx
8474 alphaev4_next_nop (int *pin_use)
8476 int in_use = *pin_use;
8477 rtx nop;
8479 if (!(in_use & EV4_IB0))
8481 in_use |= EV4_IB0;
8482 nop = gen_nop ();
8484 else if ((in_use & (EV4_IBX|EV4_IB1)) == EV4_IBX)
8486 in_use |= EV4_IB1;
8487 nop = gen_nop ();
8489 else if (TARGET_FP && !(in_use & EV4_IB1))
8491 in_use |= EV4_IB1;
8492 nop = gen_fnop ();
8494 else
8495 nop = gen_unop ();
8497 *pin_use = in_use;
8498 return nop;
8501 static rtx
8502 alphaev5_next_nop (int *pin_use)
8504 int in_use = *pin_use;
8505 rtx nop;
8507 if (!(in_use & EV5_E1))
8509 in_use |= EV5_E1;
8510 nop = gen_nop ();
8512 else if (TARGET_FP && !(in_use & EV5_FA))
8514 in_use |= EV5_FA;
8515 nop = gen_fnop ();
8517 else if (TARGET_FP && !(in_use & EV5_FM))
8519 in_use |= EV5_FM;
8520 nop = gen_fnop ();
8522 else
8523 nop = gen_unop ();
8525 *pin_use = in_use;
8526 return nop;
8529 /* The instruction group alignment main loop. */
8531 static void
8532 alpha_align_insns (unsigned int max_align,
8533 rtx (*next_group) (rtx, int *, int *),
8534 rtx (*next_nop) (int *))
8536 /* ALIGN is the known alignment for the insn group. */
8537 unsigned int align;
8538 /* OFS is the offset of the current insn in the insn group. */
8539 int ofs;
8540 int prev_in_use, in_use, len;
8541 rtx i, next;
8543 /* Let shorten branches care for assigning alignments to code labels. */
8544 shorten_branches (get_insns ());
8546 if (align_functions < 4)
8547 align = 4;
8548 else if ((unsigned int) align_functions < max_align)
8549 align = align_functions;
8550 else
8551 align = max_align;
8553 ofs = prev_in_use = 0;
8554 i = get_insns ();
8555 if (GET_CODE (i) == NOTE)
8556 i = next_nonnote_insn (i);
8558 while (i)
8560 next = (*next_group) (i, &in_use, &len);
8562 /* When we see a label, resync alignment etc. */
8563 if (GET_CODE (i) == CODE_LABEL)
8565 unsigned int new_align = 1 << label_to_alignment (i);
8567 if (new_align >= align)
8569 align = new_align < max_align ? new_align : max_align;
8570 ofs = 0;
8573 else if (ofs & (new_align-1))
8574 ofs = (ofs | (new_align-1)) + 1;
8575 if (len != 0)
8576 abort();
8579 /* Handle complex instructions special. */
8580 else if (in_use == 0)
8582 /* Asms will have length < 0. This is a signal that we have
8583 lost alignment knowledge. Assume, however, that the asm
8584 will not mis-align instructions. */
8585 if (len < 0)
8587 ofs = 0;
8588 align = 4;
8589 len = 0;
8593 /* If the known alignment is smaller than the recognized insn group,
8594 realign the output. */
8595 else if ((int) align < len)
8597 unsigned int new_log_align = len > 8 ? 4 : 3;
8598 rtx prev, where;
8600 where = prev = prev_nonnote_insn (i);
8601 if (!where || GET_CODE (where) != CODE_LABEL)
8602 where = i;
8604 /* Can't realign between a call and its gp reload. */
8605 if (! (TARGET_EXPLICIT_RELOCS
8606 && prev && GET_CODE (prev) == CALL_INSN))
8608 emit_insn_before (gen_realign (GEN_INT (new_log_align)), where);
8609 align = 1 << new_log_align;
8610 ofs = 0;
8614 /* If the group won't fit in the same INT16 as the previous,
8615 we need to add padding to keep the group together. Rather
8616 than simply leaving the insn filling to the assembler, we
8617 can make use of the knowledge of what sorts of instructions
8618 were issued in the previous group to make sure that all of
8619 the added nops are really free. */
8620 else if (ofs + len > (int) align)
8622 int nop_count = (align - ofs) / 4;
8623 rtx where;
8625 /* Insert nops before labels, branches, and calls to truely merge
8626 the execution of the nops with the previous instruction group. */
8627 where = prev_nonnote_insn (i);
8628 if (where)
8630 if (GET_CODE (where) == CODE_LABEL)
8632 rtx where2 = prev_nonnote_insn (where);
8633 if (where2 && GET_CODE (where2) == JUMP_INSN)
8634 where = where2;
8636 else if (GET_CODE (where) == INSN)
8637 where = i;
8639 else
8640 where = i;
8643 emit_insn_before ((*next_nop)(&prev_in_use), where);
8644 while (--nop_count);
8645 ofs = 0;
8648 ofs = (ofs + len) & (align - 1);
8649 prev_in_use = in_use;
8650 i = next;
8654 /* Machine dependent reorg pass. */
8656 static void
8657 alpha_reorg (void)
8659 if (alpha_tp != ALPHA_TP_PROG || flag_exceptions)
8660 alpha_handle_trap_shadows ();
8662 /* Due to the number of extra trapb insns, don't bother fixing up
8663 alignment when trap precision is instruction. Moreover, we can
8664 only do our job when sched2 is run. */
8665 if (optimize && !optimize_size
8666 && alpha_tp != ALPHA_TP_INSN
8667 && flag_schedule_insns_after_reload)
8669 if (alpha_cpu == PROCESSOR_EV4)
8670 alpha_align_insns (8, alphaev4_next_group, alphaev4_next_nop);
8671 else if (alpha_cpu == PROCESSOR_EV5)
8672 alpha_align_insns (16, alphaev5_next_group, alphaev5_next_nop);
8676 #if !TARGET_ABI_UNICOSMK
8678 #ifdef HAVE_STAMP_H
8679 #include <stamp.h>
8680 #endif
8682 static void
8683 alpha_file_start (void)
8685 default_file_start ();
8686 #ifdef MS_STAMP
8687 fprintf (file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP);
8688 #endif
8690 fputs ("\t.set noreorder\n", asm_out_file);
8691 fputs ("\t.set volatile\n", asm_out_file);
8692 if (!TARGET_ABI_OPEN_VMS)
8693 fputs ("\t.set noat\n", asm_out_file);
8694 if (TARGET_EXPLICIT_RELOCS)
8695 fputs ("\t.set nomacro\n", asm_out_file);
8696 if (TARGET_SUPPORT_ARCH | TARGET_BWX | TARGET_MAX | TARGET_FIX | TARGET_CIX)
8697 fprintf (asm_out_file,
8698 "\t.arch %s\n",
8699 TARGET_CPU_EV6 ? "ev6"
8700 : (TARGET_CPU_EV5
8701 ? (TARGET_MAX ? "pca56" : TARGET_BWX ? "ev56" : "ev5")
8702 : "ev4"));
8704 #endif
8706 #ifdef OBJECT_FORMAT_ELF
8708 /* Switch to the section to which we should output X. The only thing
8709 special we do here is to honor small data. */
8711 static void
8712 alpha_elf_select_rtx_section (enum machine_mode mode, rtx x,
8713 unsigned HOST_WIDE_INT align)
8715 if (TARGET_SMALL_DATA && GET_MODE_SIZE (mode) <= g_switch_value)
8716 /* ??? Consider using mergable sdata sections. */
8717 sdata_section ();
8718 else
8719 default_elf_select_rtx_section (mode, x, align);
8722 #endif /* OBJECT_FORMAT_ELF */
8724 /* Structure to collect function names for final output in link section. */
8725 /* Note that items marked with GTY can't be ifdef'ed out. */
8727 enum links_kind {KIND_UNUSED, KIND_LOCAL, KIND_EXTERN};
8728 enum reloc_kind {KIND_LINKAGE, KIND_CODEADDR};
8730 struct alpha_links GTY(())
8732 int num;
8733 rtx linkage;
8734 enum links_kind lkind;
8735 enum reloc_kind rkind;
8738 struct alpha_funcs GTY(())
8740 int num;
8741 splay_tree GTY ((param1_is (char *), param2_is (struct alpha_links *)))
8742 links;
8745 static GTY ((param1_is (char *), param2_is (struct alpha_links *)))
8746 splay_tree alpha_links_tree;
8747 static GTY ((param1_is (tree), param2_is (struct alpha_funcs *)))
8748 splay_tree alpha_funcs_tree;
8750 static GTY(()) int alpha_funcs_num;
8752 #if TARGET_ABI_OPEN_VMS
8754 /* Return the VMS argument type corresponding to MODE. */
8756 enum avms_arg_type
8757 alpha_arg_type (enum machine_mode mode)
8759 switch (mode)
8761 case SFmode:
8762 return TARGET_FLOAT_VAX ? FF : FS;
8763 case DFmode:
8764 return TARGET_FLOAT_VAX ? FD : FT;
8765 default:
8766 return I64;
8770 /* Return an rtx for an integer representing the VMS Argument Information
8771 register value. */
8774 alpha_arg_info_reg_val (CUMULATIVE_ARGS cum)
8776 unsigned HOST_WIDE_INT regval = cum.num_args;
8777 int i;
8779 for (i = 0; i < 6; i++)
8780 regval |= ((int) cum.atypes[i]) << (i * 3 + 8);
8782 return GEN_INT (regval);
8785 /* Make (or fake) .linkage entry for function call.
8787 IS_LOCAL is 0 if name is used in call, 1 if name is used in definition.
8789 Return an SYMBOL_REF rtx for the linkage. */
8792 alpha_need_linkage (const char *name, int is_local)
8794 splay_tree_node node;
8795 struct alpha_links *al;
8797 if (name[0] == '*')
8798 name++;
8800 if (is_local)
8802 struct alpha_funcs *cfaf;
8804 if (!alpha_funcs_tree)
8805 alpha_funcs_tree = splay_tree_new_ggc ((splay_tree_compare_fn)
8806 splay_tree_compare_pointers);
8808 cfaf = (struct alpha_funcs *) ggc_alloc (sizeof (struct alpha_funcs));
8810 cfaf->links = 0;
8811 cfaf->num = ++alpha_funcs_num;
8813 splay_tree_insert (alpha_funcs_tree,
8814 (splay_tree_key) current_function_decl,
8815 (splay_tree_value) cfaf);
8818 if (alpha_links_tree)
8820 /* Is this name already defined? */
8822 node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
8823 if (node)
8825 al = (struct alpha_links *) node->value;
8826 if (is_local)
8828 /* Defined here but external assumed. */
8829 if (al->lkind == KIND_EXTERN)
8830 al->lkind = KIND_LOCAL;
8832 else
8834 /* Used here but unused assumed. */
8835 if (al->lkind == KIND_UNUSED)
8836 al->lkind = KIND_LOCAL;
8838 return al->linkage;
8841 else
8842 alpha_links_tree = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
8844 al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
8845 name = ggc_strdup (name);
8847 /* Assume external if no definition. */
8848 al->lkind = (is_local ? KIND_UNUSED : KIND_EXTERN);
8850 /* Ensure we have an IDENTIFIER so assemble_name can mark it used. */
8851 get_identifier (name);
8853 /* Construct a SYMBOL_REF for us to call. */
8855 size_t name_len = strlen (name);
8856 char *linksym = alloca (name_len + 6);
8857 linksym[0] = '$';
8858 memcpy (linksym + 1, name, name_len);
8859 memcpy (linksym + 1 + name_len, "..lk", 5);
8860 al->linkage = gen_rtx_SYMBOL_REF (Pmode,
8861 ggc_alloc_string (linksym, name_len + 5));
8864 splay_tree_insert (alpha_links_tree, (splay_tree_key) name,
8865 (splay_tree_value) al);
8867 return al->linkage;
8871 alpha_use_linkage (rtx linkage, tree cfundecl, int lflag, int rflag)
8873 splay_tree_node cfunnode;
8874 struct alpha_funcs *cfaf;
8875 struct alpha_links *al;
8876 const char *name = XSTR (linkage, 0);
8878 cfaf = (struct alpha_funcs *) 0;
8879 al = (struct alpha_links *) 0;
8881 cfunnode = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) cfundecl);
8882 cfaf = (struct alpha_funcs *) cfunnode->value;
8884 if (cfaf->links)
8886 splay_tree_node lnode;
8888 /* Is this name already defined? */
8890 lnode = splay_tree_lookup (cfaf->links, (splay_tree_key) name);
8891 if (lnode)
8892 al = (struct alpha_links *) lnode->value;
8894 else
8895 cfaf->links = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
8897 if (!al)
8899 size_t name_len;
8900 size_t buflen;
8901 char buf [512];
8902 char *linksym;
8903 splay_tree_node node = 0;
8904 struct alpha_links *anl;
8906 if (name[0] == '*')
8907 name++;
8909 name_len = strlen (name);
8911 al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
8912 al->num = cfaf->num;
8914 node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
8915 if (node)
8917 anl = (struct alpha_links *) node->value;
8918 al->lkind = anl->lkind;
8921 sprintf (buf, "$%d..%s..lk", cfaf->num, name);
8922 buflen = strlen (buf);
8923 linksym = alloca (buflen + 1);
8924 memcpy (linksym, buf, buflen + 1);
8926 al->linkage = gen_rtx_SYMBOL_REF
8927 (Pmode, ggc_alloc_string (linksym, buflen + 1));
8929 splay_tree_insert (cfaf->links, (splay_tree_key) name,
8930 (splay_tree_value) al);
8933 if (rflag)
8934 al->rkind = KIND_CODEADDR;
8935 else
8936 al->rkind = KIND_LINKAGE;
8938 if (lflag)
8939 return gen_rtx_MEM (Pmode, plus_constant (al->linkage, 8));
8940 else
8941 return al->linkage;
8944 static int
8945 alpha_write_one_linkage (splay_tree_node node, void *data)
8947 const char *const name = (const char *) node->key;
8948 struct alpha_links *link = (struct alpha_links *) node->value;
8949 FILE *stream = (FILE *) data;
8951 fprintf (stream, "$%d..%s..lk:\n", link->num, name);
8952 if (link->rkind == KIND_CODEADDR)
8954 if (link->lkind == KIND_LOCAL)
8956 /* Local and used */
8957 fprintf (stream, "\t.quad %s..en\n", name);
8959 else
8961 /* External and used, request code address. */
8962 fprintf (stream, "\t.code_address %s\n", name);
8965 else
8967 if (link->lkind == KIND_LOCAL)
8969 /* Local and used, build linkage pair. */
8970 fprintf (stream, "\t.quad %s..en\n", name);
8971 fprintf (stream, "\t.quad %s\n", name);
8973 else
8975 /* External and used, request linkage pair. */
8976 fprintf (stream, "\t.linkage %s\n", name);
8980 return 0;
8983 static void
8984 alpha_write_linkage (FILE *stream, const char *funname, tree fundecl)
8986 splay_tree_node node;
8987 struct alpha_funcs *func;
8989 link_section ();
8990 fprintf (stream, "\t.align 3\n");
8991 node = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) fundecl);
8992 func = (struct alpha_funcs *) node->value;
8994 fputs ("\t.name ", stream);
8995 assemble_name (stream, funname);
8996 fputs ("..na\n", stream);
8997 ASM_OUTPUT_LABEL (stream, funname);
8998 fprintf (stream, "\t.pdesc ");
8999 assemble_name (stream, funname);
9000 fprintf (stream, "..en,%s\n",
9001 alpha_procedure_type == PT_STACK ? "stack"
9002 : alpha_procedure_type == PT_REGISTER ? "reg" : "null");
9004 if (func->links)
9006 splay_tree_foreach (func->links, alpha_write_one_linkage, stream);
9007 /* splay_tree_delete (func->links); */
9011 /* Given a decl, a section name, and whether the decl initializer
9012 has relocs, choose attributes for the section. */
9014 #define SECTION_VMS_OVERLAY SECTION_FORGET
9015 #define SECTION_VMS_GLOBAL SECTION_MACH_DEP
9016 #define SECTION_VMS_INITIALIZE (SECTION_VMS_GLOBAL << 1)
9018 static unsigned int
9019 vms_section_type_flags (tree decl, const char *name, int reloc)
9021 unsigned int flags = default_section_type_flags (decl, name, reloc);
9023 if (decl && DECL_ATTRIBUTES (decl)
9024 && lookup_attribute ("overlaid", DECL_ATTRIBUTES (decl)))
9025 flags |= SECTION_VMS_OVERLAY;
9026 if (decl && DECL_ATTRIBUTES (decl)
9027 && lookup_attribute ("global", DECL_ATTRIBUTES (decl)))
9028 flags |= SECTION_VMS_GLOBAL;
9029 if (decl && DECL_ATTRIBUTES (decl)
9030 && lookup_attribute ("initialize", DECL_ATTRIBUTES (decl)))
9031 flags |= SECTION_VMS_INITIALIZE;
9033 return flags;
9036 /* Switch to an arbitrary section NAME with attributes as specified
9037 by FLAGS. ALIGN specifies any known alignment requirements for
9038 the section; 0 if the default should be used. */
9040 static void
9041 vms_asm_named_section (const char *name, unsigned int flags)
9043 fputc ('\n', asm_out_file);
9044 fprintf (asm_out_file, ".section\t%s", name);
9046 if (flags & SECTION_VMS_OVERLAY)
9047 fprintf (asm_out_file, ",OVR");
9048 if (flags & SECTION_VMS_GLOBAL)
9049 fprintf (asm_out_file, ",GBL");
9050 if (flags & SECTION_VMS_INITIALIZE)
9051 fprintf (asm_out_file, ",NOMOD");
9052 if (flags & SECTION_DEBUG)
9053 fprintf (asm_out_file, ",NOWRT");
9055 fputc ('\n', asm_out_file);
9058 /* Record an element in the table of global constructors. SYMBOL is
9059 a SYMBOL_REF of the function to be called; PRIORITY is a number
9060 between 0 and MAX_INIT_PRIORITY.
9062 Differs from default_ctors_section_asm_out_constructor in that the
9063 width of the .ctors entry is always 64 bits, rather than the 32 bits
9064 used by a normal pointer. */
9066 static void
9067 vms_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9069 ctors_section ();
9070 assemble_align (BITS_PER_WORD);
9071 assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9074 static void
9075 vms_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9077 dtors_section ();
9078 assemble_align (BITS_PER_WORD);
9079 assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9081 #else
9084 alpha_need_linkage (const char *name ATTRIBUTE_UNUSED,
9085 int is_local ATTRIBUTE_UNUSED)
9087 return NULL_RTX;
9091 alpha_use_linkage (rtx linkage ATTRIBUTE_UNUSED,
9092 tree cfundecl ATTRIBUTE_UNUSED,
9093 int lflag ATTRIBUTE_UNUSED,
9094 int rflag ATTRIBUTE_UNUSED)
9096 return NULL_RTX;
9099 #endif /* TARGET_ABI_OPEN_VMS */
9101 #if TARGET_ABI_UNICOSMK
9103 /* Define the offset between two registers, one to be eliminated, and the
9104 other its replacement, at the start of a routine. */
9107 unicosmk_initial_elimination_offset (int from, int to)
9109 int fixed_size;
9111 fixed_size = alpha_sa_size();
9112 if (fixed_size != 0)
9113 fixed_size += 48;
9115 if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9116 return -fixed_size;
9117 else if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9118 return 0;
9119 else if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9120 return (ALPHA_ROUND (current_function_outgoing_args_size)
9121 + ALPHA_ROUND (get_frame_size()));
9122 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9123 return (ALPHA_ROUND (fixed_size)
9124 + ALPHA_ROUND (get_frame_size()
9125 + current_function_outgoing_args_size));
9126 else
9127 abort ();
9130 /* Output the module name for .ident and .end directives. We have to strip
9131 directories and add make sure that the module name starts with a letter
9132 or '$'. */
9134 static void
9135 unicosmk_output_module_name (FILE *file)
9137 const char *name;
9139 /* Strip directories. */
9141 name = strrchr (main_input_filename, '/');
9142 if (name)
9143 ++name;
9144 else
9145 name = main_input_filename;
9147 /* CAM only accepts module names that start with a letter or '$'. We
9148 prefix the module name with a '$' if necessary. */
9150 if (!ISALPHA (*name))
9151 putc ('$', file);
9152 output_clean_symbol_name (file, name);
9155 /* Output the definition of a common variable. */
9157 void
9158 unicosmk_output_common (FILE *file, const char *name, int size, int align)
9160 tree name_tree;
9161 printf ("T3E__: common %s\n", name);
9163 common_section ();
9164 fputs("\t.endp\n\n\t.psect ", file);
9165 assemble_name(file, name);
9166 fprintf(file, ",%d,common\n", floor_log2 (align / BITS_PER_UNIT));
9167 fprintf(file, "\t.byte\t0:%d\n", size);
9169 /* Mark the symbol as defined in this module. */
9170 name_tree = get_identifier (name);
9171 TREE_ASM_WRITTEN (name_tree) = 1;
9174 #define SECTION_PUBLIC SECTION_MACH_DEP
9175 #define SECTION_MAIN (SECTION_PUBLIC << 1)
9176 static int current_section_align;
9178 static unsigned int
9179 unicosmk_section_type_flags (tree decl, const char *name,
9180 int reloc ATTRIBUTE_UNUSED)
9182 unsigned int flags = default_section_type_flags (decl, name, reloc);
9184 if (!decl)
9185 return flags;
9187 if (TREE_CODE (decl) == FUNCTION_DECL)
9189 current_section_align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
9190 if (align_functions_log > current_section_align)
9191 current_section_align = align_functions_log;
9193 if (! strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "main"))
9194 flags |= SECTION_MAIN;
9196 else
9197 current_section_align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
9199 if (TREE_PUBLIC (decl))
9200 flags |= SECTION_PUBLIC;
9202 return flags;
9205 /* Generate a section name for decl and associate it with the
9206 declaration. */
9208 static void
9209 unicosmk_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
9211 const char *name;
9212 int len;
9214 if (!decl)
9215 abort ();
9217 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9218 name = default_strip_name_encoding (name);
9219 len = strlen (name);
9221 if (TREE_CODE (decl) == FUNCTION_DECL)
9223 char *string;
9225 /* It is essential that we prefix the section name here because
9226 otherwise the section names generated for constructors and
9227 destructors confuse collect2. */
9229 string = alloca (len + 6);
9230 sprintf (string, "code@%s", name);
9231 DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9233 else if (TREE_PUBLIC (decl))
9234 DECL_SECTION_NAME (decl) = build_string (len, name);
9235 else
9237 char *string;
9239 string = alloca (len + 6);
9240 sprintf (string, "data@%s", name);
9241 DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9245 /* Switch to an arbitrary section NAME with attributes as specified
9246 by FLAGS. ALIGN specifies any known alignment requirements for
9247 the section; 0 if the default should be used. */
9249 static void
9250 unicosmk_asm_named_section (const char *name, unsigned int flags)
9252 const char *kind;
9254 /* Close the previous section. */
9256 fputs ("\t.endp\n\n", asm_out_file);
9258 /* Find out what kind of section we are opening. */
9260 if (flags & SECTION_MAIN)
9261 fputs ("\t.start\tmain\n", asm_out_file);
9263 if (flags & SECTION_CODE)
9264 kind = "code";
9265 else if (flags & SECTION_PUBLIC)
9266 kind = "common";
9267 else
9268 kind = "data";
9270 if (current_section_align != 0)
9271 fprintf (asm_out_file, "\t.psect\t%s,%d,%s\n", name,
9272 current_section_align, kind);
9273 else
9274 fprintf (asm_out_file, "\t.psect\t%s,%s\n", name, kind);
9277 static void
9278 unicosmk_insert_attributes (tree decl, tree *attr_ptr ATTRIBUTE_UNUSED)
9280 if (DECL_P (decl)
9281 && (TREE_PUBLIC (decl) || TREE_CODE (decl) == FUNCTION_DECL))
9282 unicosmk_unique_section (decl, 0);
9285 /* Output an alignment directive. We have to use the macro 'gcc@code@align'
9286 in code sections because .align fill unused space with zeroes. */
9288 void
9289 unicosmk_output_align (FILE *file, int align)
9291 if (inside_function)
9292 fprintf (file, "\tgcc@code@align\t%d\n", align);
9293 else
9294 fprintf (file, "\t.align\t%d\n", align);
9297 /* Add a case vector to the current function's list of deferred case
9298 vectors. Case vectors have to be put into a separate section because CAM
9299 does not allow data definitions in code sections. */
9301 void
9302 unicosmk_defer_case_vector (rtx lab, rtx vec)
9304 struct machine_function *machine = cfun->machine;
9306 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
9307 machine->addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec,
9308 machine->addr_list);
9311 /* Output a case vector. */
9313 static void
9314 unicosmk_output_addr_vec (FILE *file, rtx vec)
9316 rtx lab = XEXP (vec, 0);
9317 rtx body = XEXP (vec, 1);
9318 int vlen = XVECLEN (body, 0);
9319 int idx;
9321 (*targetm.asm_out.internal_label) (file, "L", CODE_LABEL_NUMBER (lab));
9323 for (idx = 0; idx < vlen; idx++)
9325 ASM_OUTPUT_ADDR_VEC_ELT
9326 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
9330 /* Output current function's deferred case vectors. */
9332 static void
9333 unicosmk_output_deferred_case_vectors (FILE *file)
9335 struct machine_function *machine = cfun->machine;
9336 rtx t;
9338 if (machine->addr_list == NULL_RTX)
9339 return;
9341 data_section ();
9342 for (t = machine->addr_list; t; t = XEXP (t, 1))
9343 unicosmk_output_addr_vec (file, XEXP (t, 0));
9346 /* Generate the name of the SSIB section for the current function. */
9348 #define SSIB_PREFIX "__SSIB_"
9349 #define SSIB_PREFIX_LEN 7
9351 static const char *
9352 unicosmk_ssib_name (void)
9354 /* This is ok since CAM won't be able to deal with names longer than that
9355 anyway. */
9357 static char name[256];
9359 rtx x;
9360 const char *fnname;
9361 int len;
9363 x = DECL_RTL (cfun->decl);
9364 if (GET_CODE (x) != MEM)
9365 abort ();
9366 x = XEXP (x, 0);
9367 if (GET_CODE (x) != SYMBOL_REF)
9368 abort ();
9369 fnname = XSTR (x, 0);
9371 len = strlen (fnname);
9372 if (len + SSIB_PREFIX_LEN > 255)
9373 len = 255 - SSIB_PREFIX_LEN;
9375 strcpy (name, SSIB_PREFIX);
9376 strncpy (name + SSIB_PREFIX_LEN, fnname, len);
9377 name[len + SSIB_PREFIX_LEN] = 0;
9379 return name;
9382 /* Set up the dynamic subprogram information block (DSIB) and update the
9383 frame pointer register ($15) for subroutines which have a frame. If the
9384 subroutine doesn't have a frame, simply increment $15. */
9386 static void
9387 unicosmk_gen_dsib (unsigned long *imaskP)
9389 if (alpha_procedure_type == PT_STACK)
9391 const char *ssib_name;
9392 rtx mem;
9394 /* Allocate 64 bytes for the DSIB. */
9396 FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
9397 GEN_INT (-64))));
9398 emit_insn (gen_blockage ());
9400 /* Save the return address. */
9402 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 56));
9403 set_mem_alias_set (mem, alpha_sr_alias_set);
9404 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA)));
9405 (*imaskP) &= ~(1UL << REG_RA);
9407 /* Save the old frame pointer. */
9409 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 48));
9410 set_mem_alias_set (mem, alpha_sr_alias_set);
9411 FRP (emit_move_insn (mem, hard_frame_pointer_rtx));
9412 (*imaskP) &= ~(1UL << HARD_FRAME_POINTER_REGNUM);
9414 emit_insn (gen_blockage ());
9416 /* Store the SSIB pointer. */
9418 ssib_name = ggc_strdup (unicosmk_ssib_name ());
9419 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 32));
9420 set_mem_alias_set (mem, alpha_sr_alias_set);
9422 FRP (emit_move_insn (gen_rtx_REG (DImode, 5),
9423 gen_rtx_SYMBOL_REF (Pmode, ssib_name)));
9424 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 5)));
9426 /* Save the CIW index. */
9428 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 24));
9429 set_mem_alias_set (mem, alpha_sr_alias_set);
9430 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 25)));
9432 emit_insn (gen_blockage ());
9434 /* Set the new frame pointer. */
9436 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9437 stack_pointer_rtx, GEN_INT (64))));
9440 else
9442 /* Increment the frame pointer register to indicate that we do not
9443 have a frame. */
9445 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9446 hard_frame_pointer_rtx, GEN_INT (1))));
9450 /* Output the static subroutine information block for the current
9451 function. */
9453 static void
9454 unicosmk_output_ssib (FILE *file, const char *fnname)
9456 int len;
9457 int i;
9458 rtx x;
9459 rtx ciw;
9460 struct machine_function *machine = cfun->machine;
9462 ssib_section ();
9463 fprintf (file, "\t.endp\n\n\t.psect\t%s%s,data\n", user_label_prefix,
9464 unicosmk_ssib_name ());
9466 /* Some required stuff and the function name length. */
9468 len = strlen (fnname);
9469 fprintf (file, "\t.quad\t^X20008%2.2X28\n", len);
9471 /* Saved registers
9472 ??? We don't do that yet. */
9474 fputs ("\t.quad\t0\n", file);
9476 /* Function address. */
9478 fputs ("\t.quad\t", file);
9479 assemble_name (file, fnname);
9480 putc ('\n', file);
9482 fputs ("\t.quad\t0\n", file);
9483 fputs ("\t.quad\t0\n", file);
9485 /* Function name.
9486 ??? We do it the same way Cray CC does it but this could be
9487 simplified. */
9489 for( i = 0; i < len; i++ )
9490 fprintf (file, "\t.byte\t%d\n", (int)(fnname[i]));
9491 if( (len % 8) == 0 )
9492 fputs ("\t.quad\t0\n", file);
9493 else
9494 fprintf (file, "\t.bits\t%d : 0\n", (8 - (len % 8))*8);
9496 /* All call information words used in the function. */
9498 for (x = machine->first_ciw; x; x = XEXP (x, 1))
9500 ciw = XEXP (x, 0);
9501 #if HOST_BITS_PER_WIDE_INT == 32
9502 fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_DOUBLE_HEX "\n",
9503 CONST_DOUBLE_HIGH (ciw), CONST_DOUBLE_LOW (ciw));
9504 #else
9505 fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX "\n", INTVAL (ciw));
9506 #endif
9510 /* Add a call information word (CIW) to the list of the current function's
9511 CIWs and return its index.
9513 X is a CONST_INT or CONST_DOUBLE representing the CIW. */
9516 unicosmk_add_call_info_word (rtx x)
9518 rtx node;
9519 struct machine_function *machine = cfun->machine;
9521 node = gen_rtx_EXPR_LIST (VOIDmode, x, NULL_RTX);
9522 if (machine->first_ciw == NULL_RTX)
9523 machine->first_ciw = node;
9524 else
9525 XEXP (machine->last_ciw, 1) = node;
9527 machine->last_ciw = node;
9528 ++machine->ciw_count;
9530 return GEN_INT (machine->ciw_count
9531 + strlen (current_function_name)/8 + 5);
9534 static char unicosmk_section_buf[100];
9536 char *
9537 unicosmk_text_section (void)
9539 static int count = 0;
9540 sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@text___%d,code",
9541 count++);
9542 return unicosmk_section_buf;
9545 char *
9546 unicosmk_data_section (void)
9548 static int count = 1;
9549 sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@data___%d,data",
9550 count++);
9551 return unicosmk_section_buf;
9554 /* The Cray assembler doesn't accept extern declarations for symbols which
9555 are defined in the same file. We have to keep track of all global
9556 symbols which are referenced and/or defined in a source file and output
9557 extern declarations for those which are referenced but not defined at
9558 the end of file. */
9560 /* List of identifiers for which an extern declaration might have to be
9561 emitted. */
9562 /* FIXME: needs to use GC, so it can be saved and restored for PCH. */
9564 struct unicosmk_extern_list
9566 struct unicosmk_extern_list *next;
9567 const char *name;
9570 static struct unicosmk_extern_list *unicosmk_extern_head = 0;
9572 /* Output extern declarations which are required for every asm file. */
9574 static void
9575 unicosmk_output_default_externs (FILE *file)
9577 static const char *const externs[] =
9578 { "__T3E_MISMATCH" };
9580 int i;
9581 int n;
9583 n = ARRAY_SIZE (externs);
9585 for (i = 0; i < n; i++)
9586 fprintf (file, "\t.extern\t%s\n", externs[i]);
9589 /* Output extern declarations for global symbols which are have been
9590 referenced but not defined. */
9592 static void
9593 unicosmk_output_externs (FILE *file)
9595 struct unicosmk_extern_list *p;
9596 const char *real_name;
9597 int len;
9598 tree name_tree;
9600 len = strlen (user_label_prefix);
9601 for (p = unicosmk_extern_head; p != 0; p = p->next)
9603 /* We have to strip the encoding and possibly remove user_label_prefix
9604 from the identifier in order to handle -fleading-underscore and
9605 explicit asm names correctly (cf. gcc.dg/asm-names-1.c). */
9606 real_name = default_strip_name_encoding (p->name);
9607 if (len && p->name[0] == '*'
9608 && !memcmp (real_name, user_label_prefix, len))
9609 real_name += len;
9611 name_tree = get_identifier (real_name);
9612 if (! TREE_ASM_WRITTEN (name_tree))
9614 TREE_ASM_WRITTEN (name_tree) = 1;
9615 fputs ("\t.extern\t", file);
9616 assemble_name (file, p->name);
9617 putc ('\n', file);
9622 /* Record an extern. */
9624 void
9625 unicosmk_add_extern (const char *name)
9627 struct unicosmk_extern_list *p;
9629 p = (struct unicosmk_extern_list *)
9630 xmalloc (sizeof (struct unicosmk_extern_list));
9631 p->next = unicosmk_extern_head;
9632 p->name = name;
9633 unicosmk_extern_head = p;
9636 /* The Cray assembler generates incorrect code if identifiers which
9637 conflict with register names are used as instruction operands. We have
9638 to replace such identifiers with DEX expressions. */
9640 /* Structure to collect identifiers which have been replaced by DEX
9641 expressions. */
9642 /* FIXME: needs to use GC, so it can be saved and restored for PCH. */
9644 struct unicosmk_dex {
9645 struct unicosmk_dex *next;
9646 const char *name;
9649 /* List of identifiers which have been replaced by DEX expressions. The DEX
9650 number is determined by the position in the list. */
9652 static struct unicosmk_dex *unicosmk_dex_list = NULL;
9654 /* The number of elements in the DEX list. */
9656 static int unicosmk_dex_count = 0;
9658 /* Check if NAME must be replaced by a DEX expression. */
9660 static int
9661 unicosmk_special_name (const char *name)
9663 if (name[0] == '*')
9664 ++name;
9666 if (name[0] == '$')
9667 ++name;
9669 if (name[0] != 'r' && name[0] != 'f' && name[0] != 'R' && name[0] != 'F')
9670 return 0;
9672 switch (name[1])
9674 case '1': case '2':
9675 return (name[2] == '\0' || (ISDIGIT (name[2]) && name[3] == '\0'));
9677 case '3':
9678 return (name[2] == '\0'
9679 || ((name[2] == '0' || name[2] == '1') && name[3] == '\0'));
9681 default:
9682 return (ISDIGIT (name[1]) && name[2] == '\0');
9686 /* Return the DEX number if X must be replaced by a DEX expression and 0
9687 otherwise. */
9689 static int
9690 unicosmk_need_dex (rtx x)
9692 struct unicosmk_dex *dex;
9693 const char *name;
9694 int i;
9696 if (GET_CODE (x) != SYMBOL_REF)
9697 return 0;
9699 name = XSTR (x,0);
9700 if (! unicosmk_special_name (name))
9701 return 0;
9703 i = unicosmk_dex_count;
9704 for (dex = unicosmk_dex_list; dex; dex = dex->next)
9706 if (! strcmp (name, dex->name))
9707 return i;
9708 --i;
9711 dex = (struct unicosmk_dex *) xmalloc (sizeof (struct unicosmk_dex));
9712 dex->name = name;
9713 dex->next = unicosmk_dex_list;
9714 unicosmk_dex_list = dex;
9716 ++unicosmk_dex_count;
9717 return unicosmk_dex_count;
9720 /* Output the DEX definitions for this file. */
9722 static void
9723 unicosmk_output_dex (FILE *file)
9725 struct unicosmk_dex *dex;
9726 int i;
9728 if (unicosmk_dex_list == NULL)
9729 return;
9731 fprintf (file, "\t.dexstart\n");
9733 i = unicosmk_dex_count;
9734 for (dex = unicosmk_dex_list; dex; dex = dex->next)
9736 fprintf (file, "\tDEX (%d) = ", i);
9737 assemble_name (file, dex->name);
9738 putc ('\n', file);
9739 --i;
9742 fprintf (file, "\t.dexend\n");
9745 /* Output text that to appear at the beginning of an assembler file. */
9747 static void
9748 unicosmk_file_start (void)
9750 int i;
9752 fputs ("\t.ident\t", asm_out_file);
9753 unicosmk_output_module_name (asm_out_file);
9754 fputs ("\n\n", asm_out_file);
9756 /* The Unicos/Mk assembler uses different register names. Instead of trying
9757 to support them, we simply use micro definitions. */
9759 /* CAM has different register names: rN for the integer register N and fN
9760 for the floating-point register N. Instead of trying to use these in
9761 alpha.md, we define the symbols $N and $fN to refer to the appropriate
9762 register. */
9764 for (i = 0; i < 32; ++i)
9765 fprintf (asm_out_file, "$%d <- r%d\n", i, i);
9767 for (i = 0; i < 32; ++i)
9768 fprintf (asm_out_file, "$f%d <- f%d\n", i, i);
9770 putc ('\n', asm_out_file);
9772 /* The .align directive fill unused space with zeroes which does not work
9773 in code sections. We define the macro 'gcc@code@align' which uses nops
9774 instead. Note that it assumes that code sections always have the
9775 biggest possible alignment since . refers to the current offset from
9776 the beginning of the section. */
9778 fputs ("\t.macro gcc@code@align n\n", asm_out_file);
9779 fputs ("gcc@n@bytes = 1 << n\n", asm_out_file);
9780 fputs ("gcc@here = . % gcc@n@bytes\n", asm_out_file);
9781 fputs ("\t.if ne, gcc@here, 0\n", asm_out_file);
9782 fputs ("\t.repeat (gcc@n@bytes - gcc@here) / 4\n", asm_out_file);
9783 fputs ("\tbis r31,r31,r31\n", asm_out_file);
9784 fputs ("\t.endr\n", asm_out_file);
9785 fputs ("\t.endif\n", asm_out_file);
9786 fputs ("\t.endm gcc@code@align\n\n", asm_out_file);
9788 /* Output extern declarations which should always be visible. */
9789 unicosmk_output_default_externs (asm_out_file);
9791 /* Open a dummy section. We always need to be inside a section for the
9792 section-switching code to work correctly.
9793 ??? This should be a module id or something like that. I still have to
9794 figure out what the rules for those are. */
9795 fputs ("\n\t.psect\t$SG00000,data\n", asm_out_file);
9798 /* Output text to appear at the end of an assembler file. This includes all
9799 pending extern declarations and DEX expressions. */
9801 static void
9802 unicosmk_file_end (void)
9804 fputs ("\t.endp\n\n", asm_out_file);
9806 /* Output all pending externs. */
9808 unicosmk_output_externs (asm_out_file);
9810 /* Output dex definitions used for functions whose names conflict with
9811 register names. */
9813 unicosmk_output_dex (asm_out_file);
9815 fputs ("\t.end\t", asm_out_file);
9816 unicosmk_output_module_name (asm_out_file);
9817 putc ('\n', asm_out_file);
9820 #else
9822 static void
9823 unicosmk_output_deferred_case_vectors (FILE *file ATTRIBUTE_UNUSED)
9826 static void
9827 unicosmk_gen_dsib (unsigned long *imaskP ATTRIBUTE_UNUSED)
9830 static void
9831 unicosmk_output_ssib (FILE * file ATTRIBUTE_UNUSED,
9832 const char * fnname ATTRIBUTE_UNUSED)
9836 unicosmk_add_call_info_word (rtx x ATTRIBUTE_UNUSED)
9838 return NULL_RTX;
9841 static int
9842 unicosmk_need_dex (rtx x ATTRIBUTE_UNUSED)
9844 return 0;
9847 #endif /* TARGET_ABI_UNICOSMK */
9850 /* Initialize the GCC target structure. */
9851 #if TARGET_ABI_OPEN_VMS
9852 # undef TARGET_ATTRIBUTE_TABLE
9853 # define TARGET_ATTRIBUTE_TABLE vms_attribute_table
9854 # undef TARGET_SECTION_TYPE_FLAGS
9855 # define TARGET_SECTION_TYPE_FLAGS vms_section_type_flags
9856 #endif
9858 #undef TARGET_IN_SMALL_DATA_P
9859 #define TARGET_IN_SMALL_DATA_P alpha_in_small_data_p
9861 #if TARGET_ABI_UNICOSMK
9862 # undef TARGET_INSERT_ATTRIBUTES
9863 # define TARGET_INSERT_ATTRIBUTES unicosmk_insert_attributes
9864 # undef TARGET_SECTION_TYPE_FLAGS
9865 # define TARGET_SECTION_TYPE_FLAGS unicosmk_section_type_flags
9866 # undef TARGET_ASM_UNIQUE_SECTION
9867 # define TARGET_ASM_UNIQUE_SECTION unicosmk_unique_section
9868 # undef TARGET_ASM_GLOBALIZE_LABEL
9869 # define TARGET_ASM_GLOBALIZE_LABEL hook_void_FILEptr_constcharptr
9870 #endif
9872 #undef TARGET_ASM_ALIGNED_HI_OP
9873 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
9874 #undef TARGET_ASM_ALIGNED_DI_OP
9875 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
9877 /* Default unaligned ops are provided for ELF systems. To get unaligned
9878 data for non-ELF systems, we have to turn off auto alignment. */
9879 #ifndef OBJECT_FORMAT_ELF
9880 #undef TARGET_ASM_UNALIGNED_HI_OP
9881 #define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.word\t"
9882 #undef TARGET_ASM_UNALIGNED_SI_OP
9883 #define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.long\t"
9884 #undef TARGET_ASM_UNALIGNED_DI_OP
9885 #define TARGET_ASM_UNALIGNED_DI_OP "\t.align 0\n\t.quad\t"
9886 #endif
9888 #ifdef OBJECT_FORMAT_ELF
9889 #undef TARGET_ASM_SELECT_RTX_SECTION
9890 #define TARGET_ASM_SELECT_RTX_SECTION alpha_elf_select_rtx_section
9891 #endif
9893 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
9894 #define TARGET_ASM_FUNCTION_END_PROLOGUE alpha_output_function_end_prologue
9896 #if TARGET_ABI_UNICOSMK
9897 #undef TARGET_ASM_FILE_START
9898 #define TARGET_ASM_FILE_START unicosmk_file_start
9899 #undef TARGET_ASM_FILE_END
9900 #define TARGET_ASM_FILE_END unicosmk_file_end
9901 #else
9902 #undef TARGET_ASM_FILE_START
9903 #define TARGET_ASM_FILE_START alpha_file_start
9904 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
9905 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
9906 #endif
9908 #undef TARGET_SCHED_ADJUST_COST
9909 #define TARGET_SCHED_ADJUST_COST alpha_adjust_cost
9910 #undef TARGET_SCHED_ISSUE_RATE
9911 #define TARGET_SCHED_ISSUE_RATE alpha_issue_rate
9912 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
9913 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE \
9914 alpha_use_dfa_pipeline_interface
9915 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
9916 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
9917 alpha_multipass_dfa_lookahead
9919 #undef TARGET_HAVE_TLS
9920 #define TARGET_HAVE_TLS HAVE_AS_TLS
9922 #undef TARGET_INIT_BUILTINS
9923 #define TARGET_INIT_BUILTINS alpha_init_builtins
9924 #undef TARGET_EXPAND_BUILTIN
9925 #define TARGET_EXPAND_BUILTIN alpha_expand_builtin
9927 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
9928 #define TARGET_FUNCTION_OK_FOR_SIBCALL alpha_function_ok_for_sibcall
9929 #undef TARGET_CANNOT_COPY_INSN_P
9930 #define TARGET_CANNOT_COPY_INSN_P alpha_cannot_copy_insn_p
9932 #if TARGET_ABI_OSF
9933 #undef TARGET_ASM_OUTPUT_MI_THUNK
9934 #define TARGET_ASM_OUTPUT_MI_THUNK alpha_output_mi_thunk_osf
9935 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
9936 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
9937 #endif
9939 #undef TARGET_RTX_COSTS
9940 #define TARGET_RTX_COSTS alpha_rtx_costs
9941 #undef TARGET_ADDRESS_COST
9942 #define TARGET_ADDRESS_COST hook_int_rtx_0
9944 #undef TARGET_MACHINE_DEPENDENT_REORG
9945 #define TARGET_MACHINE_DEPENDENT_REORG alpha_reorg
9947 struct gcc_target targetm = TARGET_INITIALIZER;
9950 #include "gt-alpha.h"