* target.h (struct gcc_target): Add calls.pass_by_reference.
[official-gcc.git] / gcc / config / alpha / alpha.c
blob8ed7b78d72cd8586fb7a29b9045bbd3d5ee8a4e5
1 /* Subroutines used for code generation on the DEC Alpha.
2 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "rtl.h"
29 #include "tree.h"
30 #include "regs.h"
31 #include "hard-reg-set.h"
32 #include "real.h"
33 #include "insn-config.h"
34 #include "conditions.h"
35 #include "output.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "recog.h"
39 #include "expr.h"
40 #include "optabs.h"
41 #include "reload.h"
42 #include "obstack.h"
43 #include "except.h"
44 #include "function.h"
45 #include "toplev.h"
46 #include "ggc.h"
47 #include "integrate.h"
48 #include "tm_p.h"
49 #include "target.h"
50 #include "target-def.h"
51 #include "debug.h"
52 #include "langhooks.h"
53 #include <splay-tree.h>
54 #include "cfglayout.h"
55 #include "tree-gimple.h"
57 /* Specify which cpu to schedule for. */
59 enum processor_type alpha_cpu;
60 static const char * const alpha_cpu_name[] =
62 "ev4", "ev5", "ev6"
65 /* Specify how accurate floating-point traps need to be. */
67 enum alpha_trap_precision alpha_tp;
69 /* Specify the floating-point rounding mode. */
71 enum alpha_fp_rounding_mode alpha_fprm;
73 /* Specify which things cause traps. */
75 enum alpha_fp_trap_mode alpha_fptm;
77 /* Specify bit size of immediate TLS offsets. */
79 int alpha_tls_size = 32;
81 /* Strings decoded into the above options. */
83 const char *alpha_cpu_string; /* -mcpu= */
84 const char *alpha_tune_string; /* -mtune= */
85 const char *alpha_tp_string; /* -mtrap-precision=[p|s|i] */
86 const char *alpha_fprm_string; /* -mfp-rounding-mode=[n|m|c|d] */
87 const char *alpha_fptm_string; /* -mfp-trap-mode=[n|u|su|sui] */
88 const char *alpha_mlat_string; /* -mmemory-latency= */
89 const char *alpha_tls_size_string; /* -mtls-size=[16|32|64] */
91 /* Save information from a "cmpxx" operation until the branch or scc is
92 emitted. */
94 struct alpha_compare alpha_compare;
96 /* Nonzero if inside of a function, because the Alpha asm can't
97 handle .files inside of functions. */
99 static int inside_function = FALSE;
101 /* The number of cycles of latency we should assume on memory reads. */
103 int alpha_memory_latency = 3;
105 /* Whether the function needs the GP. */
107 static int alpha_function_needs_gp;
109 /* The alias set for prologue/epilogue register save/restore. */
111 static GTY(()) int alpha_sr_alias_set;
113 /* The assembler name of the current function. */
115 static const char *alpha_fnname;
117 /* The next explicit relocation sequence number. */
118 extern GTY(()) int alpha_next_sequence_number;
119 int alpha_next_sequence_number = 1;
121 /* The literal and gpdisp sequence numbers for this insn, as printed
122 by %# and %* respectively. */
123 extern GTY(()) int alpha_this_literal_sequence_number;
124 extern GTY(()) int alpha_this_gpdisp_sequence_number;
125 int alpha_this_literal_sequence_number;
126 int alpha_this_gpdisp_sequence_number;
128 /* Costs of various operations on the different architectures. */
130 struct alpha_rtx_cost_data
132 unsigned char fp_add;
133 unsigned char fp_mult;
134 unsigned char fp_div_sf;
135 unsigned char fp_div_df;
136 unsigned char int_mult_si;
137 unsigned char int_mult_di;
138 unsigned char int_shift;
139 unsigned char int_cmov;
140 unsigned short int_div;
143 static struct alpha_rtx_cost_data const alpha_rtx_cost_data[PROCESSOR_MAX] =
145 { /* EV4 */
146 COSTS_N_INSNS (6), /* fp_add */
147 COSTS_N_INSNS (6), /* fp_mult */
148 COSTS_N_INSNS (34), /* fp_div_sf */
149 COSTS_N_INSNS (63), /* fp_div_df */
150 COSTS_N_INSNS (23), /* int_mult_si */
151 COSTS_N_INSNS (23), /* int_mult_di */
152 COSTS_N_INSNS (2), /* int_shift */
153 COSTS_N_INSNS (2), /* int_cmov */
154 COSTS_N_INSNS (70), /* int_div */
156 { /* EV5 */
157 COSTS_N_INSNS (4), /* fp_add */
158 COSTS_N_INSNS (4), /* fp_mult */
159 COSTS_N_INSNS (15), /* fp_div_sf */
160 COSTS_N_INSNS (22), /* fp_div_df */
161 COSTS_N_INSNS (8), /* int_mult_si */
162 COSTS_N_INSNS (12), /* int_mult_di */
163 COSTS_N_INSNS (1) + 1, /* int_shift */
164 COSTS_N_INSNS (1), /* int_cmov */
165 COSTS_N_INSNS (45), /* int_div */
167 { /* EV6 */
168 COSTS_N_INSNS (4), /* fp_add */
169 COSTS_N_INSNS (4), /* fp_mult */
170 COSTS_N_INSNS (12), /* fp_div_sf */
171 COSTS_N_INSNS (15), /* fp_div_df */
172 COSTS_N_INSNS (7), /* int_mult_si */
173 COSTS_N_INSNS (7), /* int_mult_di */
174 COSTS_N_INSNS (1), /* int_shift */
175 COSTS_N_INSNS (2), /* int_cmov */
176 COSTS_N_INSNS (25), /* int_div */
180 /* Similar but tuned for code size instead of execution latency. The
181 extra +N is fractional cost tuning based on latency. It's used to
182 encourage use of cheaper insns like shift, but only if there's just
183 one of them. */
185 static struct alpha_rtx_cost_data const alpha_rtx_cost_size =
187 COSTS_N_INSNS (1), /* fp_add */
188 COSTS_N_INSNS (1), /* fp_mult */
189 COSTS_N_INSNS (1), /* fp_div_sf */
190 COSTS_N_INSNS (1) + 1, /* fp_div_df */
191 COSTS_N_INSNS (1) + 1, /* int_mult_si */
192 COSTS_N_INSNS (1) + 2, /* int_mult_di */
193 COSTS_N_INSNS (1), /* int_shift */
194 COSTS_N_INSNS (1), /* int_cmov */
195 COSTS_N_INSNS (6), /* int_div */
198 /* Get the number of args of a function in one of two ways. */
199 #if TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK
200 #define NUM_ARGS current_function_args_info.num_args
201 #else
202 #define NUM_ARGS current_function_args_info
203 #endif
205 #define REG_PV 27
206 #define REG_RA 26
208 /* Declarations of static functions. */
209 static struct machine_function *alpha_init_machine_status (void);
210 static rtx alpha_emit_xfloating_compare (enum rtx_code, rtx, rtx);
212 #if TARGET_ABI_OPEN_VMS
213 static void alpha_write_linkage (FILE *, const char *, tree);
214 #endif
216 static void unicosmk_output_deferred_case_vectors (FILE *);
217 static void unicosmk_gen_dsib (unsigned long *);
218 static void unicosmk_output_ssib (FILE *, const char *);
219 static int unicosmk_need_dex (rtx);
221 /* Parse target option strings. */
223 void
224 override_options (void)
226 int i;
227 static const struct cpu_table {
228 const char *const name;
229 const enum processor_type processor;
230 const int flags;
231 } cpu_table[] = {
232 #define EV5_MASK (MASK_CPU_EV5)
233 #define EV6_MASK (MASK_CPU_EV6|MASK_BWX|MASK_MAX|MASK_FIX)
234 { "ev4", PROCESSOR_EV4, 0 },
235 { "ev45", PROCESSOR_EV4, 0 },
236 { "21064", PROCESSOR_EV4, 0 },
237 { "ev5", PROCESSOR_EV5, EV5_MASK },
238 { "21164", PROCESSOR_EV5, EV5_MASK },
239 { "ev56", PROCESSOR_EV5, EV5_MASK|MASK_BWX },
240 { "21164a", PROCESSOR_EV5, EV5_MASK|MASK_BWX },
241 { "pca56", PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX },
242 { "21164PC",PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX },
243 { "21164pc",PROCESSOR_EV5, EV5_MASK|MASK_BWX|MASK_MAX },
244 { "ev6", PROCESSOR_EV6, EV6_MASK },
245 { "21264", PROCESSOR_EV6, EV6_MASK },
246 { "ev67", PROCESSOR_EV6, EV6_MASK|MASK_CIX },
247 { "21264a", PROCESSOR_EV6, EV6_MASK|MASK_CIX },
248 { 0, 0, 0 }
251 /* Unicos/Mk doesn't have shared libraries. */
252 if (TARGET_ABI_UNICOSMK && flag_pic)
254 warning ("-f%s ignored for Unicos/Mk (not supported)",
255 (flag_pic > 1) ? "PIC" : "pic");
256 flag_pic = 0;
259 /* On Unicos/Mk, the native compiler consistently generates /d suffices for
260 floating-point instructions. Make that the default for this target. */
261 if (TARGET_ABI_UNICOSMK)
262 alpha_fprm = ALPHA_FPRM_DYN;
263 else
264 alpha_fprm = ALPHA_FPRM_NORM;
266 alpha_tp = ALPHA_TP_PROG;
267 alpha_fptm = ALPHA_FPTM_N;
269 /* We cannot use su and sui qualifiers for conversion instructions on
270 Unicos/Mk. I'm not sure if this is due to assembler or hardware
271 limitations. Right now, we issue a warning if -mieee is specified
272 and then ignore it; eventually, we should either get it right or
273 disable the option altogether. */
275 if (TARGET_IEEE)
277 if (TARGET_ABI_UNICOSMK)
278 warning ("-mieee not supported on Unicos/Mk");
279 else
281 alpha_tp = ALPHA_TP_INSN;
282 alpha_fptm = ALPHA_FPTM_SU;
286 if (TARGET_IEEE_WITH_INEXACT)
288 if (TARGET_ABI_UNICOSMK)
289 warning ("-mieee-with-inexact not supported on Unicos/Mk");
290 else
292 alpha_tp = ALPHA_TP_INSN;
293 alpha_fptm = ALPHA_FPTM_SUI;
297 if (alpha_tp_string)
299 if (! strcmp (alpha_tp_string, "p"))
300 alpha_tp = ALPHA_TP_PROG;
301 else if (! strcmp (alpha_tp_string, "f"))
302 alpha_tp = ALPHA_TP_FUNC;
303 else if (! strcmp (alpha_tp_string, "i"))
304 alpha_tp = ALPHA_TP_INSN;
305 else
306 error ("bad value `%s' for -mtrap-precision switch", alpha_tp_string);
309 if (alpha_fprm_string)
311 if (! strcmp (alpha_fprm_string, "n"))
312 alpha_fprm = ALPHA_FPRM_NORM;
313 else if (! strcmp (alpha_fprm_string, "m"))
314 alpha_fprm = ALPHA_FPRM_MINF;
315 else if (! strcmp (alpha_fprm_string, "c"))
316 alpha_fprm = ALPHA_FPRM_CHOP;
317 else if (! strcmp (alpha_fprm_string,"d"))
318 alpha_fprm = ALPHA_FPRM_DYN;
319 else
320 error ("bad value `%s' for -mfp-rounding-mode switch",
321 alpha_fprm_string);
324 if (alpha_fptm_string)
326 if (strcmp (alpha_fptm_string, "n") == 0)
327 alpha_fptm = ALPHA_FPTM_N;
328 else if (strcmp (alpha_fptm_string, "u") == 0)
329 alpha_fptm = ALPHA_FPTM_U;
330 else if (strcmp (alpha_fptm_string, "su") == 0)
331 alpha_fptm = ALPHA_FPTM_SU;
332 else if (strcmp (alpha_fptm_string, "sui") == 0)
333 alpha_fptm = ALPHA_FPTM_SUI;
334 else
335 error ("bad value `%s' for -mfp-trap-mode switch", alpha_fptm_string);
338 if (alpha_tls_size_string)
340 if (strcmp (alpha_tls_size_string, "16") == 0)
341 alpha_tls_size = 16;
342 else if (strcmp (alpha_tls_size_string, "32") == 0)
343 alpha_tls_size = 32;
344 else if (strcmp (alpha_tls_size_string, "64") == 0)
345 alpha_tls_size = 64;
346 else
347 error ("bad value `%s' for -mtls-size switch", alpha_tls_size_string);
350 alpha_cpu
351 = TARGET_CPU_DEFAULT & MASK_CPU_EV6 ? PROCESSOR_EV6
352 : (TARGET_CPU_DEFAULT & MASK_CPU_EV5 ? PROCESSOR_EV5 : PROCESSOR_EV4);
354 if (alpha_cpu_string)
356 for (i = 0; cpu_table [i].name; i++)
357 if (! strcmp (alpha_cpu_string, cpu_table [i].name))
359 alpha_cpu = cpu_table [i].processor;
360 target_flags &= ~ (MASK_BWX | MASK_MAX | MASK_FIX | MASK_CIX
361 | MASK_CPU_EV5 | MASK_CPU_EV6);
362 target_flags |= cpu_table [i].flags;
363 break;
365 if (! cpu_table [i].name)
366 error ("bad value `%s' for -mcpu switch", alpha_cpu_string);
369 if (alpha_tune_string)
371 for (i = 0; cpu_table [i].name; i++)
372 if (! strcmp (alpha_tune_string, cpu_table [i].name))
374 alpha_cpu = cpu_table [i].processor;
375 break;
377 if (! cpu_table [i].name)
378 error ("bad value `%s' for -mcpu switch", alpha_tune_string);
381 /* Do some sanity checks on the above options. */
383 if (TARGET_ABI_UNICOSMK && alpha_fptm != ALPHA_FPTM_N)
385 warning ("trap mode not supported on Unicos/Mk");
386 alpha_fptm = ALPHA_FPTM_N;
389 if ((alpha_fptm == ALPHA_FPTM_SU || alpha_fptm == ALPHA_FPTM_SUI)
390 && alpha_tp != ALPHA_TP_INSN && ! TARGET_CPU_EV6)
392 warning ("fp software completion requires -mtrap-precision=i");
393 alpha_tp = ALPHA_TP_INSN;
396 if (TARGET_CPU_EV6)
398 /* Except for EV6 pass 1 (not released), we always have precise
399 arithmetic traps. Which means we can do software completion
400 without minding trap shadows. */
401 alpha_tp = ALPHA_TP_PROG;
404 if (TARGET_FLOAT_VAX)
406 if (alpha_fprm == ALPHA_FPRM_MINF || alpha_fprm == ALPHA_FPRM_DYN)
408 warning ("rounding mode not supported for VAX floats");
409 alpha_fprm = ALPHA_FPRM_NORM;
411 if (alpha_fptm == ALPHA_FPTM_SUI)
413 warning ("trap mode not supported for VAX floats");
414 alpha_fptm = ALPHA_FPTM_SU;
416 if (target_flags_explicit & MASK_LONG_DOUBLE_128)
417 warning ("128-bit long double not supported for VAX floats");
418 target_flags &= ~MASK_LONG_DOUBLE_128;
422 char *end;
423 int lat;
425 if (!alpha_mlat_string)
426 alpha_mlat_string = "L1";
428 if (ISDIGIT ((unsigned char)alpha_mlat_string[0])
429 && (lat = strtol (alpha_mlat_string, &end, 10), *end == '\0'))
431 else if ((alpha_mlat_string[0] == 'L' || alpha_mlat_string[0] == 'l')
432 && ISDIGIT ((unsigned char)alpha_mlat_string[1])
433 && alpha_mlat_string[2] == '\0')
435 static int const cache_latency[][4] =
437 { 3, 30, -1 }, /* ev4 -- Bcache is a guess */
438 { 2, 12, 38 }, /* ev5 -- Bcache from PC164 LMbench numbers */
439 { 3, 12, 30 }, /* ev6 -- Bcache from DS20 LMbench. */
442 lat = alpha_mlat_string[1] - '0';
443 if (lat <= 0 || lat > 3 || cache_latency[alpha_cpu][lat-1] == -1)
445 warning ("L%d cache latency unknown for %s",
446 lat, alpha_cpu_name[alpha_cpu]);
447 lat = 3;
449 else
450 lat = cache_latency[alpha_cpu][lat-1];
452 else if (! strcmp (alpha_mlat_string, "main"))
454 /* Most current memories have about 370ns latency. This is
455 a reasonable guess for a fast cpu. */
456 lat = 150;
458 else
460 warning ("bad value `%s' for -mmemory-latency", alpha_mlat_string);
461 lat = 3;
464 alpha_memory_latency = lat;
467 /* Default the definition of "small data" to 8 bytes. */
468 if (!g_switch_set)
469 g_switch_value = 8;
471 /* Infer TARGET_SMALL_DATA from -fpic/-fPIC. */
472 if (flag_pic == 1)
473 target_flags |= MASK_SMALL_DATA;
474 else if (flag_pic == 2)
475 target_flags &= ~MASK_SMALL_DATA;
477 /* Align labels and loops for optimal branching. */
478 /* ??? Kludge these by not doing anything if we don't optimize and also if
479 we are writing ECOFF symbols to work around a bug in DEC's assembler. */
480 if (optimize > 0 && write_symbols != SDB_DEBUG)
482 if (align_loops <= 0)
483 align_loops = 16;
484 if (align_jumps <= 0)
485 align_jumps = 16;
487 if (align_functions <= 0)
488 align_functions = 16;
490 /* Acquire a unique set number for our register saves and restores. */
491 alpha_sr_alias_set = new_alias_set ();
493 /* Register variables and functions with the garbage collector. */
495 /* Set up function hooks. */
496 init_machine_status = alpha_init_machine_status;
498 /* Tell the compiler when we're using VAX floating point. */
499 if (TARGET_FLOAT_VAX)
501 REAL_MODE_FORMAT (SFmode) = &vax_f_format;
502 REAL_MODE_FORMAT (DFmode) = &vax_g_format;
503 REAL_MODE_FORMAT (TFmode) = NULL;
507 /* Returns 1 if VALUE is a mask that contains full bytes of zero or ones. */
510 zap_mask (HOST_WIDE_INT value)
512 int i;
514 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
515 i++, value >>= 8)
516 if ((value & 0xff) != 0 && (value & 0xff) != 0xff)
517 return 0;
519 return 1;
522 /* Returns 1 if OP is either the constant zero or a register. If a
523 register, it must be in the proper mode unless MODE is VOIDmode. */
526 reg_or_0_operand (rtx op, enum machine_mode mode)
528 return op == CONST0_RTX (mode) || register_operand (op, mode);
531 /* Return 1 if OP is a constant in the range of 0-63 (for a shift) or
532 any register. */
535 reg_or_6bit_operand (rtx op, enum machine_mode mode)
537 return ((GET_CODE (op) == CONST_INT
538 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64)
539 || register_operand (op, mode));
543 /* Return 1 if OP is an 8-bit constant or any register. */
546 reg_or_8bit_operand (rtx op, enum machine_mode mode)
548 return ((GET_CODE (op) == CONST_INT
549 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100)
550 || register_operand (op, mode));
553 /* Return 1 if OP is a constant or any register. */
556 reg_or_const_int_operand (rtx op, enum machine_mode mode)
558 return GET_CODE (op) == CONST_INT || register_operand (op, mode);
561 /* Return 1 if OP is an 8-bit constant. */
564 cint8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
566 return ((GET_CODE (op) == CONST_INT
567 && (unsigned HOST_WIDE_INT) INTVAL (op) < 0x100));
570 /* Return 1 if the operand is a valid second operand to an add insn. */
573 add_operand (rtx op, enum machine_mode mode)
575 if (GET_CODE (op) == CONST_INT)
576 /* Constraints I, J, O and P are covered by K. */
577 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'K')
578 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
580 return register_operand (op, mode);
583 /* Return 1 if the operand is a valid second operand to a sign-extending
584 add insn. */
587 sext_add_operand (rtx op, enum machine_mode mode)
589 if (GET_CODE (op) == CONST_INT)
590 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
591 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'O'));
593 return reg_not_elim_operand (op, mode);
596 /* Return 1 if OP is the constant 4 or 8. */
599 const48_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
601 return (GET_CODE (op) == CONST_INT
602 && (INTVAL (op) == 4 || INTVAL (op) == 8));
605 /* Return 1 if OP is a valid first operand to an AND insn. */
608 and_operand (rtx op, enum machine_mode mode)
610 if (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
611 return (zap_mask (CONST_DOUBLE_LOW (op))
612 && zap_mask (CONST_DOUBLE_HIGH (op)));
614 if (GET_CODE (op) == CONST_INT)
615 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
616 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100
617 || zap_mask (INTVAL (op)));
619 return register_operand (op, mode);
622 /* Return 1 if OP is a valid first operand to an IOR or XOR insn. */
625 or_operand (rtx op, enum machine_mode mode)
627 if (GET_CODE (op) == CONST_INT)
628 return ((unsigned HOST_WIDE_INT) INTVAL (op) < 0x100
629 || (unsigned HOST_WIDE_INT) ~ INTVAL (op) < 0x100);
631 return register_operand (op, mode);
634 /* Return 1 if OP is a constant that is the width, in bits, of an integral
635 mode smaller than DImode. */
638 mode_width_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
640 return (GET_CODE (op) == CONST_INT
641 && (INTVAL (op) == 8 || INTVAL (op) == 16
642 || INTVAL (op) == 32 || INTVAL (op) == 64));
645 /* Return 1 if OP is a constant that is the width of an integral machine mode
646 smaller than an integer. */
649 mode_mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
651 if (GET_CODE (op) == CONST_INT)
653 HOST_WIDE_INT value = INTVAL (op);
655 if (value == 0xff)
656 return 1;
657 if (value == 0xffff)
658 return 1;
659 if (value == 0xffffffff)
660 return 1;
661 if (value == -1)
662 return 1;
664 else if (HOST_BITS_PER_WIDE_INT == 32 && GET_CODE (op) == CONST_DOUBLE)
666 if (CONST_DOUBLE_LOW (op) == 0xffffffff && CONST_DOUBLE_HIGH (op) == 0)
667 return 1;
670 return 0;
673 /* Return 1 if OP is a multiple of 8 less than 64. */
676 mul8_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
678 return (GET_CODE (op) == CONST_INT
679 && (unsigned HOST_WIDE_INT) INTVAL (op) < 64
680 && (INTVAL (op) & 7) == 0);
683 /* Return 1 if OP is the zero constant for MODE. */
686 const0_operand (rtx op, enum machine_mode mode)
688 return op == CONST0_RTX (mode);
691 /* Return 1 if OP is a hard floating-point register. */
694 hard_fp_register_operand (rtx op, enum machine_mode mode)
696 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
697 return 0;
699 if (GET_CODE (op) == SUBREG)
700 op = SUBREG_REG (op);
701 return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == FLOAT_REGS;
704 /* Return 1 if OP is a hard general register. */
707 hard_int_register_operand (rtx op, enum machine_mode mode)
709 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
710 return 0;
712 if (GET_CODE (op) == SUBREG)
713 op = SUBREG_REG (op);
714 return GET_CODE (op) == REG && REGNO_REG_CLASS (REGNO (op)) == GENERAL_REGS;
717 /* Return 1 if OP is a register or a constant integer. */
721 reg_or_cint_operand (rtx op, enum machine_mode mode)
723 return (GET_CODE (op) == CONST_INT
724 || register_operand (op, mode));
727 /* Return 1 if OP is something that can be reloaded into a register;
728 if it is a MEM, it need not be valid. */
731 some_operand (rtx op, enum machine_mode mode)
733 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
734 return 0;
736 switch (GET_CODE (op))
738 case REG:
739 case MEM:
740 case CONST_INT:
741 case CONST_DOUBLE:
742 case CONST_VECTOR:
743 case LABEL_REF:
744 case SYMBOL_REF:
745 case CONST:
746 case HIGH:
747 return 1;
749 case SUBREG:
750 return some_operand (SUBREG_REG (op), VOIDmode);
752 default:
753 break;
756 return 0;
759 /* Likewise, but don't accept constants. */
762 some_ni_operand (rtx op, enum machine_mode mode)
764 if (GET_MODE (op) != mode && mode != VOIDmode)
765 return 0;
767 if (GET_CODE (op) == SUBREG)
768 op = SUBREG_REG (op);
770 return (GET_CODE (op) == REG || GET_CODE (op) == MEM);
773 /* Return 1 if OP is a valid operand for the source of a move insn. */
776 input_operand (rtx op, enum machine_mode mode)
778 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
779 return 0;
781 if (GET_MODE_CLASS (mode) == MODE_FLOAT && GET_MODE (op) != mode)
782 return 0;
784 switch (GET_CODE (op))
786 case LABEL_REF:
787 case SYMBOL_REF:
788 case CONST:
789 if (TARGET_EXPLICIT_RELOCS)
791 /* We don't split symbolic operands into something unintelligable
792 until after reload, but we do not wish non-small, non-global
793 symbolic operands to be reconstructed from their high/lo_sum
794 form. */
795 return (small_symbolic_operand (op, mode)
796 || global_symbolic_operand (op, mode)
797 || gotdtp_symbolic_operand (op, mode)
798 || gottp_symbolic_operand (op, mode));
801 /* This handles both the Windows/NT and OSF cases. */
802 return mode == ptr_mode || mode == DImode;
804 case HIGH:
805 return (TARGET_EXPLICIT_RELOCS
806 && local_symbolic_operand (XEXP (op, 0), mode));
808 case REG:
809 return 1;
811 case SUBREG:
812 if (register_operand (op, mode))
813 return 1;
814 /* ... fall through ... */
815 case MEM:
816 return ((TARGET_BWX || (mode != HImode && mode != QImode))
817 && general_operand (op, mode));
819 case CONST_DOUBLE:
820 case CONST_VECTOR:
821 return op == CONST0_RTX (mode);
823 case CONST_INT:
824 return mode == QImode || mode == HImode || add_operand (op, mode);
826 default:
827 break;
830 return 0;
833 /* Return 1 if OP is a SYMBOL_REF for a function known to be in this
834 file, and in the same section as the current function. */
837 samegp_function_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
839 if (GET_CODE (op) != SYMBOL_REF)
840 return false;
842 /* Easy test for recursion. */
843 if (op == XEXP (DECL_RTL (current_function_decl), 0))
844 return true;
846 /* Functions that are not local can be overridden, and thus may
847 not share the same gp. */
848 if (! SYMBOL_REF_LOCAL_P (op))
849 return false;
851 /* If -msmall-data is in effect, assume that there is only one GP
852 for the module, and so any local symbol has this property. We
853 need explicit relocations to be able to enforce this for symbols
854 not defined in this unit of translation, however. */
855 if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
856 return true;
858 /* Functions that are not external are defined in this UoT,
859 and thus must share the same gp. */
860 return ! SYMBOL_REF_EXTERNAL_P (op);
863 /* Return 1 if OP is a SYMBOL_REF for which we can make a call via bsr. */
866 direct_call_operand (rtx op, enum machine_mode mode)
868 tree op_decl, cfun_sec, op_sec;
870 /* Must share the same GP. */
871 if (!samegp_function_operand (op, mode))
872 return false;
874 /* If profiling is implemented via linker tricks, we can't jump
875 to the nogp alternate entry point. Note that current_function_profile
876 would not be correct, since that doesn't indicate if the target
877 function uses profiling. */
878 /* ??? TARGET_PROFILING_NEEDS_GP isn't really the right test,
879 but is approximately correct for the OSF ABIs. Don't know
880 what to do for VMS, NT, or UMK. */
881 if (!TARGET_PROFILING_NEEDS_GP && profile_flag)
882 return false;
884 /* Must be a function. In some cases folks create thunks in static
885 data structures and then make calls to them. If we allow the
886 direct call, we'll get an error from the linker about !samegp reloc
887 against a symbol without a .prologue directive. */
888 if (!SYMBOL_REF_FUNCTION_P (op))
889 return false;
891 /* Must be "near" so that the branch is assumed to reach. With
892 -msmall-text, this is assumed true of all local symbols. Since
893 we've already checked samegp, locality is already assured. */
894 if (TARGET_SMALL_TEXT)
895 return true;
897 /* Otherwise, a decl is "near" if it is defined in the same section. */
898 if (flag_function_sections)
899 return false;
901 op_decl = SYMBOL_REF_DECL (op);
902 if (DECL_ONE_ONLY (current_function_decl)
903 || (op_decl && DECL_ONE_ONLY (op_decl)))
904 return false;
906 cfun_sec = DECL_SECTION_NAME (current_function_decl);
907 op_sec = op_decl ? DECL_SECTION_NAME (op_decl) : NULL;
908 return ((!cfun_sec && !op_sec)
909 || (cfun_sec && op_sec
910 && strcmp (TREE_STRING_POINTER (cfun_sec),
911 TREE_STRING_POINTER (op_sec)) == 0));
914 /* Return true if OP is a LABEL_REF, or SYMBOL_REF or CONST referencing
915 a (non-tls) variable known to be defined in this file. */
918 local_symbolic_operand (rtx op, enum machine_mode mode)
920 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
921 return 0;
923 if (GET_CODE (op) == LABEL_REF)
924 return 1;
926 if (GET_CODE (op) == CONST
927 && GET_CODE (XEXP (op, 0)) == PLUS
928 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
929 op = XEXP (XEXP (op, 0), 0);
931 if (GET_CODE (op) != SYMBOL_REF)
932 return 0;
934 return SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
937 /* Return true if OP is a SYMBOL_REF or CONST referencing a variable
938 known to be defined in this file in the small data area. */
941 small_symbolic_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
943 if (! TARGET_SMALL_DATA)
944 return 0;
946 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
947 return 0;
949 if (GET_CODE (op) == CONST
950 && GET_CODE (XEXP (op, 0)) == PLUS
951 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
952 op = XEXP (XEXP (op, 0), 0);
954 if (GET_CODE (op) != SYMBOL_REF)
955 return 0;
957 /* ??? There's no encode_section_info equivalent for the rtl
958 constant pool, so SYMBOL_FLAG_SMALL never gets set. */
959 if (CONSTANT_POOL_ADDRESS_P (op))
960 return GET_MODE_SIZE (get_pool_mode (op)) <= g_switch_value;
962 return (SYMBOL_REF_LOCAL_P (op)
963 && SYMBOL_REF_SMALL_P (op)
964 && SYMBOL_REF_TLS_MODEL (op) == 0);
967 /* Return true if OP is a SYMBOL_REF or CONST referencing a variable
968 not known (or known not) to be defined in this file. */
971 global_symbolic_operand (rtx op, enum machine_mode mode)
973 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
974 return 0;
976 if (GET_CODE (op) == CONST
977 && GET_CODE (XEXP (op, 0)) == PLUS
978 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
979 op = XEXP (XEXP (op, 0), 0);
981 if (GET_CODE (op) != SYMBOL_REF)
982 return 0;
984 return !SYMBOL_REF_LOCAL_P (op) && !SYMBOL_REF_TLS_MODEL (op);
987 /* Return 1 if OP is a valid operand for the MEM of a CALL insn. */
990 call_operand (rtx op, enum machine_mode mode)
992 if (mode != Pmode)
993 return 0;
995 if (GET_CODE (op) == REG)
997 if (TARGET_ABI_OSF)
999 /* Disallow virtual registers to cope with pathological test cases
1000 such as compile/930117-1.c in which the virtual reg decomposes
1001 to the frame pointer. Which is a hard reg that is not $27. */
1002 return (REGNO (op) == 27 || REGNO (op) > LAST_VIRTUAL_REGISTER);
1004 else
1005 return 1;
1007 if (TARGET_ABI_UNICOSMK)
1008 return 0;
1009 if (GET_CODE (op) == SYMBOL_REF)
1010 return 1;
1012 return 0;
1015 /* Returns 1 if OP is a symbolic operand, i.e. a symbol_ref or a label_ref,
1016 possibly with an offset. */
1019 symbolic_operand (rtx op, enum machine_mode mode)
1021 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1022 return 0;
1023 if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
1024 return 1;
1025 if (GET_CODE (op) == CONST
1026 && GET_CODE (XEXP (op,0)) == PLUS
1027 && GET_CODE (XEXP (XEXP (op,0), 0)) == SYMBOL_REF
1028 && GET_CODE (XEXP (XEXP (op,0), 1)) == CONST_INT)
1029 return 1;
1030 return 0;
1033 /* Return true if OP is valid for a particular TLS relocation. */
1035 static int
1036 tls_symbolic_operand_1 (rtx op, enum machine_mode mode, int size, int unspec)
1038 if (mode != VOIDmode && GET_MODE (op) != VOIDmode && mode != GET_MODE (op))
1039 return 0;
1041 if (GET_CODE (op) != CONST)
1042 return 0;
1043 op = XEXP (op, 0);
1045 if (GET_CODE (op) != UNSPEC || XINT (op, 1) != unspec)
1046 return 0;
1047 op = XVECEXP (op, 0, 0);
1049 if (GET_CODE (op) != SYMBOL_REF)
1050 return 0;
1052 if (SYMBOL_REF_LOCAL_P (op))
1054 if (alpha_tls_size > size)
1055 return 0;
1057 else
1059 if (size != 64)
1060 return 0;
1063 switch (SYMBOL_REF_TLS_MODEL (op))
1065 case TLS_MODEL_LOCAL_DYNAMIC:
1066 return unspec == UNSPEC_DTPREL;
1067 case TLS_MODEL_INITIAL_EXEC:
1068 return unspec == UNSPEC_TPREL && size == 64;
1069 case TLS_MODEL_LOCAL_EXEC:
1070 return unspec == UNSPEC_TPREL;
1071 default:
1072 abort ();
1076 /* Return true if OP is valid for 16-bit DTP relative relocations. */
1079 dtp16_symbolic_operand (rtx op, enum machine_mode mode)
1081 return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_DTPREL);
1084 /* Return true if OP is valid for 32-bit DTP relative relocations. */
1087 dtp32_symbolic_operand (rtx op, enum machine_mode mode)
1089 return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_DTPREL);
1092 /* Return true if OP is valid for 64-bit DTP relative relocations. */
1095 gotdtp_symbolic_operand (rtx op, enum machine_mode mode)
1097 return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_DTPREL);
1100 /* Return true if OP is valid for 16-bit TP relative relocations. */
1103 tp16_symbolic_operand (rtx op, enum machine_mode mode)
1105 return tls_symbolic_operand_1 (op, mode, 16, UNSPEC_TPREL);
1108 /* Return true if OP is valid for 32-bit TP relative relocations. */
1111 tp32_symbolic_operand (rtx op, enum machine_mode mode)
1113 return tls_symbolic_operand_1 (op, mode, 32, UNSPEC_TPREL);
1116 /* Return true if OP is valid for 64-bit TP relative relocations. */
1119 gottp_symbolic_operand (rtx op, enum machine_mode mode)
1121 return tls_symbolic_operand_1 (op, mode, 64, UNSPEC_TPREL);
1124 /* Return 1 if OP is a valid Alpha comparison operator. Here we know which
1125 comparisons are valid in which insn. */
1128 alpha_comparison_operator (rtx op, enum machine_mode mode)
1130 enum rtx_code code = GET_CODE (op);
1132 if (mode != GET_MODE (op) && mode != VOIDmode)
1133 return 0;
1135 return (code == EQ || code == LE || code == LT
1136 || code == LEU || code == LTU);
1139 /* Return 1 if OP is a valid Alpha comparison operator against zero.
1140 Here we know which comparisons are valid in which insn. */
1143 alpha_zero_comparison_operator (rtx op, enum machine_mode mode)
1145 enum rtx_code code = GET_CODE (op);
1147 if (mode != GET_MODE (op) && mode != VOIDmode)
1148 return 0;
1150 return (code == EQ || code == NE || code == LE || code == LT
1151 || code == LEU || code == LTU);
1154 /* Return 1 if OP is a valid Alpha swapped comparison operator. */
1157 alpha_swapped_comparison_operator (rtx op, enum machine_mode mode)
1159 enum rtx_code code;
1161 if ((mode != GET_MODE (op) && mode != VOIDmode)
1162 || !COMPARISON_P (op))
1163 return 0;
1165 code = swap_condition (GET_CODE (op));
1166 return (code == EQ || code == LE || code == LT
1167 || code == LEU || code == LTU);
1170 /* Return 1 if OP is a signed comparison operation. */
1173 signed_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1175 enum rtx_code code = GET_CODE (op);
1177 if (mode != GET_MODE (op) && mode != VOIDmode)
1178 return 0;
1180 return (code == EQ || code == NE
1181 || code == LE || code == LT
1182 || code == GE || code == GT);
1185 /* Return 1 if OP is a valid Alpha floating point comparison operator.
1186 Here we know which comparisons are valid in which insn. */
1189 alpha_fp_comparison_operator (rtx op, enum machine_mode mode)
1191 enum rtx_code code = GET_CODE (op);
1193 if (mode != GET_MODE (op) && mode != VOIDmode)
1194 return 0;
1196 return (code == EQ || code == LE || code == LT || code == UNORDERED);
1199 /* Return 1 if this is a divide or modulus operator. */
1202 divmod_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1204 enum rtx_code code = GET_CODE (op);
1206 return (code == DIV || code == MOD || code == UDIV || code == UMOD);
1209 /* Return 1 if this is a float->int conversion operator. */
1212 fix_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1214 enum rtx_code code = GET_CODE (op);
1216 return (code == FIX || code == UNSIGNED_FIX);
1219 /* Return 1 if this memory address is a known aligned register plus
1220 a constant. It must be a valid address. This means that we can do
1221 this as an aligned reference plus some offset.
1223 Take into account what reload will do. */
1226 aligned_memory_operand (rtx op, enum machine_mode mode)
1228 rtx base;
1230 if (reload_in_progress)
1232 rtx tmp = op;
1233 if (GET_CODE (tmp) == SUBREG)
1234 tmp = SUBREG_REG (tmp);
1235 if (GET_CODE (tmp) == REG
1236 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1238 op = reg_equiv_memory_loc[REGNO (tmp)];
1239 if (op == 0)
1240 return 0;
1244 if (GET_CODE (op) != MEM)
1245 return 0;
1246 if (MEM_ALIGN (op) >= 32)
1247 return 1;
1248 op = XEXP (op, 0);
1250 /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
1251 sorts of constructs. Dig for the real base register. */
1252 if (reload_in_progress
1253 && GET_CODE (op) == PLUS
1254 && GET_CODE (XEXP (op, 0)) == PLUS)
1255 base = XEXP (XEXP (op, 0), 0);
1256 else
1258 if (! memory_address_p (mode, op))
1259 return 0;
1260 base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1263 return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) >= 32);
1266 /* Similar, but return 1 if OP is a MEM which is not alignable. */
1269 unaligned_memory_operand (rtx op, enum machine_mode mode)
1271 rtx base;
1273 if (reload_in_progress)
1275 rtx tmp = op;
1276 if (GET_CODE (tmp) == SUBREG)
1277 tmp = SUBREG_REG (tmp);
1278 if (GET_CODE (tmp) == REG
1279 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1281 op = reg_equiv_memory_loc[REGNO (tmp)];
1282 if (op == 0)
1283 return 0;
1287 if (GET_CODE (op) != MEM)
1288 return 0;
1289 if (MEM_ALIGN (op) >= 32)
1290 return 0;
1291 op = XEXP (op, 0);
1293 /* LEGITIMIZE_RELOAD_ADDRESS creates (plus (plus reg const_hi) const_lo)
1294 sorts of constructs. Dig for the real base register. */
1295 if (reload_in_progress
1296 && GET_CODE (op) == PLUS
1297 && GET_CODE (XEXP (op, 0)) == PLUS)
1298 base = XEXP (XEXP (op, 0), 0);
1299 else
1301 if (! memory_address_p (mode, op))
1302 return 0;
1303 base = (GET_CODE (op) == PLUS ? XEXP (op, 0) : op);
1306 return (GET_CODE (base) == REG && REGNO_POINTER_ALIGN (REGNO (base)) < 32);
1309 /* Return 1 if OP is either a register or an unaligned memory location. */
1312 reg_or_unaligned_mem_operand (rtx op, enum machine_mode mode)
1314 return register_operand (op, mode) || unaligned_memory_operand (op, mode);
1317 /* Return 1 if OP is any memory location. During reload a pseudo matches. */
1320 any_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1322 return (GET_CODE (op) == MEM
1323 || (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
1324 || (reload_in_progress && GET_CODE (op) == REG
1325 && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1326 || (reload_in_progress && GET_CODE (op) == SUBREG
1327 && GET_CODE (SUBREG_REG (op)) == REG
1328 && REGNO (SUBREG_REG (op)) >= FIRST_PSEUDO_REGISTER));
1331 /* Returns 1 if OP is not an eliminable register.
1333 This exists to cure a pathological abort in the s8addq (et al) patterns,
1335 long foo () { long t; bar(); return (long) &t * 26107; }
1337 which run afoul of a hack in reload to cure a (presumably) similar
1338 problem with lea-type instructions on other targets. But there is
1339 one of us and many of them, so work around the problem by selectively
1340 preventing combine from making the optimization. */
1343 reg_not_elim_operand (rtx op, enum machine_mode mode)
1345 rtx inner = op;
1346 if (GET_CODE (op) == SUBREG)
1347 inner = SUBREG_REG (op);
1348 if (inner == frame_pointer_rtx || inner == arg_pointer_rtx)
1349 return 0;
1351 return register_operand (op, mode);
1354 /* Return 1 is OP is a memory location that is not a reference (using
1355 an AND) to an unaligned location. Take into account what reload
1356 will do. */
1359 normal_memory_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1361 if (reload_in_progress)
1363 rtx tmp = op;
1364 if (GET_CODE (tmp) == SUBREG)
1365 tmp = SUBREG_REG (tmp);
1366 if (GET_CODE (tmp) == REG
1367 && REGNO (tmp) >= FIRST_PSEUDO_REGISTER)
1369 op = reg_equiv_memory_loc[REGNO (tmp)];
1371 /* This may not have been assigned an equivalent address if it will
1372 be eliminated. In that case, it doesn't matter what we do. */
1373 if (op == 0)
1374 return 1;
1378 return GET_CODE (op) == MEM && GET_CODE (XEXP (op, 0)) != AND;
1381 /* Accept a register, but not a subreg of any kind. This allows us to
1382 avoid pathological cases in reload wrt data movement common in
1383 int->fp conversion. */
1386 reg_no_subreg_operand (rtx op, enum machine_mode mode)
1388 if (GET_CODE (op) != REG)
1389 return 0;
1390 return register_operand (op, mode);
1393 /* Recognize an addition operation that includes a constant. Used to
1394 convince reload to canonize (plus (plus reg c1) c2) during register
1395 elimination. */
1398 addition_operation (rtx op, enum machine_mode mode)
1400 if (GET_MODE (op) != mode && mode != VOIDmode)
1401 return 0;
1402 if (GET_CODE (op) == PLUS
1403 && register_operand (XEXP (op, 0), mode)
1404 && GET_CODE (XEXP (op, 1)) == CONST_INT
1405 && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (op, 1)), 'K'))
1406 return 1;
1407 return 0;
1410 /* Implements CONST_OK_FOR_LETTER_P. Return true if the value matches
1411 the range defined for C in [I-P]. */
1413 bool
1414 alpha_const_ok_for_letter_p (HOST_WIDE_INT value, int c)
1416 switch (c)
1418 case 'I':
1419 /* An unsigned 8 bit constant. */
1420 return (unsigned HOST_WIDE_INT) value < 0x100;
1421 case 'J':
1422 /* The constant zero. */
1423 return value == 0;
1424 case 'K':
1425 /* A signed 16 bit constant. */
1426 return (unsigned HOST_WIDE_INT) (value + 0x8000) < 0x10000;
1427 case 'L':
1428 /* A shifted signed 16 bit constant appropriate for LDAH. */
1429 return ((value & 0xffff) == 0
1430 && ((value) >> 31 == -1 || value >> 31 == 0));
1431 case 'M':
1432 /* A constant that can be AND'ed with using a ZAP insn. */
1433 return zap_mask (value);
1434 case 'N':
1435 /* A complemented unsigned 8 bit constant. */
1436 return (unsigned HOST_WIDE_INT) (~ value) < 0x100;
1437 case 'O':
1438 /* A negated unsigned 8 bit constant. */
1439 return (unsigned HOST_WIDE_INT) (- value) < 0x100;
1440 case 'P':
1441 /* The constant 1, 2 or 3. */
1442 return value == 1 || value == 2 || value == 3;
1444 default:
1445 return false;
1449 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE
1450 matches for C in [GH]. */
1452 bool
1453 alpha_const_double_ok_for_letter_p (rtx value, int c)
1455 switch (c)
1457 case 'G':
1458 /* The floating point zero constant. */
1459 return (GET_MODE_CLASS (GET_MODE (value)) == MODE_FLOAT
1460 && value == CONST0_RTX (GET_MODE (value)));
1462 case 'H':
1463 /* A valid operand of a ZAP insn. */
1464 return (GET_MODE (value) == VOIDmode
1465 && zap_mask (CONST_DOUBLE_LOW (value))
1466 && zap_mask (CONST_DOUBLE_HIGH (value)));
1468 default:
1469 return false;
1473 /* Implements CONST_DOUBLE_OK_FOR_LETTER_P. Return true if VALUE
1474 matches for C. */
1476 bool
1477 alpha_extra_constraint (rtx value, int c)
1479 switch (c)
1481 case 'Q':
1482 return normal_memory_operand (value, VOIDmode);
1483 case 'R':
1484 return direct_call_operand (value, Pmode);
1485 case 'S':
1486 return (GET_CODE (value) == CONST_INT
1487 && (unsigned HOST_WIDE_INT) INTVAL (value) < 64);
1488 case 'T':
1489 return GET_CODE (value) == HIGH;
1490 case 'U':
1491 return TARGET_ABI_UNICOSMK && symbolic_operand (value, VOIDmode);
1492 case 'W':
1493 return (GET_CODE (value) == CONST_VECTOR
1494 && value == CONST0_RTX (GET_MODE (value)));
1495 default:
1496 return false;
1500 /* Return 1 if this function can directly return via $26. */
1503 direct_return (void)
1505 return (! TARGET_ABI_OPEN_VMS && ! TARGET_ABI_UNICOSMK
1506 && reload_completed
1507 && alpha_sa_size () == 0
1508 && get_frame_size () == 0
1509 && current_function_outgoing_args_size == 0
1510 && current_function_pretend_args_size == 0);
1513 /* Return the ADDR_VEC associated with a tablejump insn. */
1516 alpha_tablejump_addr_vec (rtx insn)
1518 rtx tmp;
1520 tmp = JUMP_LABEL (insn);
1521 if (!tmp)
1522 return NULL_RTX;
1523 tmp = NEXT_INSN (tmp);
1524 if (!tmp)
1525 return NULL_RTX;
1526 if (GET_CODE (tmp) == JUMP_INSN
1527 && GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC)
1528 return PATTERN (tmp);
1529 return NULL_RTX;
1532 /* Return the label of the predicted edge, or CONST0_RTX if we don't know. */
1535 alpha_tablejump_best_label (rtx insn)
1537 rtx jump_table = alpha_tablejump_addr_vec (insn);
1538 rtx best_label = NULL_RTX;
1540 /* ??? Once the CFG doesn't keep getting completely rebuilt, look
1541 there for edge frequency counts from profile data. */
1543 if (jump_table)
1545 int n_labels = XVECLEN (jump_table, 1);
1546 int best_count = -1;
1547 int i, j;
1549 for (i = 0; i < n_labels; i++)
1551 int count = 1;
1553 for (j = i + 1; j < n_labels; j++)
1554 if (XEXP (XVECEXP (jump_table, 1, i), 0)
1555 == XEXP (XVECEXP (jump_table, 1, j), 0))
1556 count++;
1558 if (count > best_count)
1559 best_count = count, best_label = XVECEXP (jump_table, 1, i);
1563 return best_label ? best_label : const0_rtx;
1566 /* Return the TLS model to use for SYMBOL. */
1568 static enum tls_model
1569 tls_symbolic_operand_type (rtx symbol)
1571 enum tls_model model;
1573 if (GET_CODE (symbol) != SYMBOL_REF)
1574 return 0;
1575 model = SYMBOL_REF_TLS_MODEL (symbol);
1577 /* Local-exec with a 64-bit size is the same code as initial-exec. */
1578 if (model == TLS_MODEL_LOCAL_EXEC && alpha_tls_size == 64)
1579 model = TLS_MODEL_INITIAL_EXEC;
1581 return model;
1584 /* Return true if the function DECL will share the same GP as any
1585 function in the current unit of translation. */
1587 static bool
1588 decl_has_samegp (tree decl)
1590 /* Functions that are not local can be overridden, and thus may
1591 not share the same gp. */
1592 if (!(*targetm.binds_local_p) (decl))
1593 return false;
1595 /* If -msmall-data is in effect, assume that there is only one GP
1596 for the module, and so any local symbol has this property. We
1597 need explicit relocations to be able to enforce this for symbols
1598 not defined in this unit of translation, however. */
1599 if (TARGET_EXPLICIT_RELOCS && TARGET_SMALL_DATA)
1600 return true;
1602 /* Functions that are not external are defined in this UoT. */
1603 /* ??? Irritatingly, static functions not yet emitted are still
1604 marked "external". Apply this to non-static functions only. */
1605 return !TREE_PUBLIC (decl) || !DECL_EXTERNAL (decl);
1608 /* Return true if EXP should be placed in the small data section. */
1610 static bool
1611 alpha_in_small_data_p (tree exp)
1613 /* We want to merge strings, so we never consider them small data. */
1614 if (TREE_CODE (exp) == STRING_CST)
1615 return false;
1617 /* Functions are never in the small data area. Duh. */
1618 if (TREE_CODE (exp) == FUNCTION_DECL)
1619 return false;
1621 if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
1623 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (exp));
1624 if (strcmp (section, ".sdata") == 0
1625 || strcmp (section, ".sbss") == 0)
1626 return true;
1628 else
1630 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
1632 /* If this is an incomplete type with size 0, then we can't put it
1633 in sdata because it might be too big when completed. */
1634 if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value)
1635 return true;
1638 return false;
1641 #if TARGET_ABI_OPEN_VMS
1642 static bool
1643 alpha_linkage_symbol_p (const char *symname)
1645 int symlen = strlen (symname);
1647 if (symlen > 4)
1648 return strcmp (&symname [symlen - 4], "..lk") == 0;
1650 return false;
1653 #define LINKAGE_SYMBOL_REF_P(X) \
1654 ((GET_CODE (X) == SYMBOL_REF \
1655 && alpha_linkage_symbol_p (XSTR (X, 0))) \
1656 || (GET_CODE (X) == CONST \
1657 && GET_CODE (XEXP (X, 0)) == PLUS \
1658 && GET_CODE (XEXP (XEXP (X, 0), 0)) == SYMBOL_REF \
1659 && alpha_linkage_symbol_p (XSTR (XEXP (XEXP (X, 0), 0), 0))))
1660 #endif
1662 /* legitimate_address_p recognizes an RTL expression that is a valid
1663 memory address for an instruction. The MODE argument is the
1664 machine mode for the MEM expression that wants to use this address.
1666 For Alpha, we have either a constant address or the sum of a
1667 register and a constant address, or just a register. For DImode,
1668 any of those forms can be surrounded with an AND that clear the
1669 low-order three bits; this is an "unaligned" access. */
1671 bool
1672 alpha_legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1674 /* If this is an ldq_u type address, discard the outer AND. */
1675 if (mode == DImode
1676 && GET_CODE (x) == AND
1677 && GET_CODE (XEXP (x, 1)) == CONST_INT
1678 && INTVAL (XEXP (x, 1)) == -8)
1679 x = XEXP (x, 0);
1681 /* Discard non-paradoxical subregs. */
1682 if (GET_CODE (x) == SUBREG
1683 && (GET_MODE_SIZE (GET_MODE (x))
1684 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1685 x = SUBREG_REG (x);
1687 /* Unadorned general registers are valid. */
1688 if (REG_P (x)
1689 && (strict
1690 ? STRICT_REG_OK_FOR_BASE_P (x)
1691 : NONSTRICT_REG_OK_FOR_BASE_P (x)))
1692 return true;
1694 /* Constant addresses (i.e. +/- 32k) are valid. */
1695 if (CONSTANT_ADDRESS_P (x))
1696 return true;
1698 #if TARGET_ABI_OPEN_VMS
1699 if (LINKAGE_SYMBOL_REF_P (x))
1700 return true;
1701 #endif
1703 /* Register plus a small constant offset is valid. */
1704 if (GET_CODE (x) == PLUS)
1706 rtx ofs = XEXP (x, 1);
1707 x = XEXP (x, 0);
1709 /* Discard non-paradoxical subregs. */
1710 if (GET_CODE (x) == SUBREG
1711 && (GET_MODE_SIZE (GET_MODE (x))
1712 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1713 x = SUBREG_REG (x);
1715 if (REG_P (x))
1717 if (! strict
1718 && NONSTRICT_REG_OK_FP_BASE_P (x)
1719 && GET_CODE (ofs) == CONST_INT)
1720 return true;
1721 if ((strict
1722 ? STRICT_REG_OK_FOR_BASE_P (x)
1723 : NONSTRICT_REG_OK_FOR_BASE_P (x))
1724 && CONSTANT_ADDRESS_P (ofs))
1725 return true;
1729 /* If we're managing explicit relocations, LO_SUM is valid, as
1730 are small data symbols. */
1731 else if (TARGET_EXPLICIT_RELOCS)
1733 if (small_symbolic_operand (x, Pmode))
1734 return true;
1736 if (GET_CODE (x) == LO_SUM)
1738 rtx ofs = XEXP (x, 1);
1739 x = XEXP (x, 0);
1741 /* Discard non-paradoxical subregs. */
1742 if (GET_CODE (x) == SUBREG
1743 && (GET_MODE_SIZE (GET_MODE (x))
1744 < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
1745 x = SUBREG_REG (x);
1747 /* Must have a valid base register. */
1748 if (! (REG_P (x)
1749 && (strict
1750 ? STRICT_REG_OK_FOR_BASE_P (x)
1751 : NONSTRICT_REG_OK_FOR_BASE_P (x))))
1752 return false;
1754 /* The symbol must be local. */
1755 if (local_symbolic_operand (ofs, Pmode)
1756 || dtp32_symbolic_operand (ofs, Pmode)
1757 || tp32_symbolic_operand (ofs, Pmode))
1758 return true;
1762 return false;
1765 /* Build the SYMBOL_REF for __tls_get_addr. */
1767 static GTY(()) rtx tls_get_addr_libfunc;
1769 static rtx
1770 get_tls_get_addr (void)
1772 if (!tls_get_addr_libfunc)
1773 tls_get_addr_libfunc = init_one_libfunc ("__tls_get_addr");
1774 return tls_get_addr_libfunc;
1777 /* Try machine-dependent ways of modifying an illegitimate address
1778 to be legitimate. If we find one, return the new, valid address. */
1781 alpha_legitimize_address (rtx x, rtx scratch,
1782 enum machine_mode mode ATTRIBUTE_UNUSED)
1784 HOST_WIDE_INT addend;
1786 /* If the address is (plus reg const_int) and the CONST_INT is not a
1787 valid offset, compute the high part of the constant and add it to
1788 the register. Then our address is (plus temp low-part-const). */
1789 if (GET_CODE (x) == PLUS
1790 && GET_CODE (XEXP (x, 0)) == REG
1791 && GET_CODE (XEXP (x, 1)) == CONST_INT
1792 && ! CONSTANT_ADDRESS_P (XEXP (x, 1)))
1794 addend = INTVAL (XEXP (x, 1));
1795 x = XEXP (x, 0);
1796 goto split_addend;
1799 /* If the address is (const (plus FOO const_int)), find the low-order
1800 part of the CONST_INT. Then load FOO plus any high-order part of the
1801 CONST_INT into a register. Our address is (plus reg low-part-const).
1802 This is done to reduce the number of GOT entries. */
1803 if (!no_new_pseudos
1804 && GET_CODE (x) == CONST
1805 && GET_CODE (XEXP (x, 0)) == PLUS
1806 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1808 addend = INTVAL (XEXP (XEXP (x, 0), 1));
1809 x = force_reg (Pmode, XEXP (XEXP (x, 0), 0));
1810 goto split_addend;
1813 /* If we have a (plus reg const), emit the load as in (2), then add
1814 the two registers, and finally generate (plus reg low-part-const) as
1815 our address. */
1816 if (!no_new_pseudos
1817 && GET_CODE (x) == PLUS
1818 && GET_CODE (XEXP (x, 0)) == REG
1819 && GET_CODE (XEXP (x, 1)) == CONST
1820 && GET_CODE (XEXP (XEXP (x, 1), 0)) == PLUS
1821 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == CONST_INT)
1823 addend = INTVAL (XEXP (XEXP (XEXP (x, 1), 0), 1));
1824 x = expand_simple_binop (Pmode, PLUS, XEXP (x, 0),
1825 XEXP (XEXP (XEXP (x, 1), 0), 0),
1826 NULL_RTX, 1, OPTAB_LIB_WIDEN);
1827 goto split_addend;
1830 /* If this is a local symbol, split the address into HIGH/LO_SUM parts. */
1831 if (TARGET_EXPLICIT_RELOCS && symbolic_operand (x, Pmode))
1833 rtx r0, r16, eqv, tga, tp, insn, dest, seq;
1835 switch (tls_symbolic_operand_type (x))
1837 case TLS_MODEL_GLOBAL_DYNAMIC:
1838 start_sequence ();
1840 r0 = gen_rtx_REG (Pmode, 0);
1841 r16 = gen_rtx_REG (Pmode, 16);
1842 tga = get_tls_get_addr ();
1843 dest = gen_reg_rtx (Pmode);
1844 seq = GEN_INT (alpha_next_sequence_number++);
1846 emit_insn (gen_movdi_er_tlsgd (r16, pic_offset_table_rtx, x, seq));
1847 insn = gen_call_value_osf_tlsgd (r0, tga, seq);
1848 insn = emit_call_insn (insn);
1849 CONST_OR_PURE_CALL_P (insn) = 1;
1850 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16);
1852 insn = get_insns ();
1853 end_sequence ();
1855 emit_libcall_block (insn, dest, r0, x);
1856 return dest;
1858 case TLS_MODEL_LOCAL_DYNAMIC:
1859 start_sequence ();
1861 r0 = gen_rtx_REG (Pmode, 0);
1862 r16 = gen_rtx_REG (Pmode, 16);
1863 tga = get_tls_get_addr ();
1864 scratch = gen_reg_rtx (Pmode);
1865 seq = GEN_INT (alpha_next_sequence_number++);
1867 emit_insn (gen_movdi_er_tlsldm (r16, pic_offset_table_rtx, seq));
1868 insn = gen_call_value_osf_tlsldm (r0, tga, seq);
1869 insn = emit_call_insn (insn);
1870 CONST_OR_PURE_CALL_P (insn) = 1;
1871 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r16);
1873 insn = get_insns ();
1874 end_sequence ();
1876 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
1877 UNSPEC_TLSLDM_CALL);
1878 emit_libcall_block (insn, scratch, r0, eqv);
1880 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPREL);
1881 eqv = gen_rtx_CONST (Pmode, eqv);
1883 if (alpha_tls_size == 64)
1885 dest = gen_reg_rtx (Pmode);
1886 emit_insn (gen_rtx_SET (VOIDmode, dest, eqv));
1887 emit_insn (gen_adddi3 (dest, dest, scratch));
1888 return dest;
1890 if (alpha_tls_size == 32)
1892 insn = gen_rtx_HIGH (Pmode, eqv);
1893 insn = gen_rtx_PLUS (Pmode, scratch, insn);
1894 scratch = gen_reg_rtx (Pmode);
1895 emit_insn (gen_rtx_SET (VOIDmode, scratch, insn));
1897 return gen_rtx_LO_SUM (Pmode, scratch, eqv);
1899 case TLS_MODEL_INITIAL_EXEC:
1900 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_TPREL);
1901 eqv = gen_rtx_CONST (Pmode, eqv);
1902 tp = gen_reg_rtx (Pmode);
1903 scratch = gen_reg_rtx (Pmode);
1904 dest = gen_reg_rtx (Pmode);
1906 emit_insn (gen_load_tp (tp));
1907 emit_insn (gen_rtx_SET (VOIDmode, scratch, eqv));
1908 emit_insn (gen_adddi3 (dest, tp, scratch));
1909 return dest;
1911 case TLS_MODEL_LOCAL_EXEC:
1912 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_TPREL);
1913 eqv = gen_rtx_CONST (Pmode, eqv);
1914 tp = gen_reg_rtx (Pmode);
1916 emit_insn (gen_load_tp (tp));
1917 if (alpha_tls_size == 32)
1919 insn = gen_rtx_HIGH (Pmode, eqv);
1920 insn = gen_rtx_PLUS (Pmode, tp, insn);
1921 tp = gen_reg_rtx (Pmode);
1922 emit_insn (gen_rtx_SET (VOIDmode, tp, insn));
1924 return gen_rtx_LO_SUM (Pmode, tp, eqv);
1927 if (local_symbolic_operand (x, Pmode))
1929 if (small_symbolic_operand (x, Pmode))
1930 return x;
1931 else
1933 if (!no_new_pseudos)
1934 scratch = gen_reg_rtx (Pmode);
1935 emit_insn (gen_rtx_SET (VOIDmode, scratch,
1936 gen_rtx_HIGH (Pmode, x)));
1937 return gen_rtx_LO_SUM (Pmode, scratch, x);
1942 return NULL;
1944 split_addend:
1946 HOST_WIDE_INT low, high;
1948 low = ((addend & 0xffff) ^ 0x8000) - 0x8000;
1949 addend -= low;
1950 high = ((addend & 0xffffffff) ^ 0x80000000) - 0x80000000;
1951 addend -= high;
1953 if (addend)
1954 x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (addend),
1955 (no_new_pseudos ? scratch : NULL_RTX),
1956 1, OPTAB_LIB_WIDEN);
1957 if (high)
1958 x = expand_simple_binop (Pmode, PLUS, x, GEN_INT (high),
1959 (no_new_pseudos ? scratch : NULL_RTX),
1960 1, OPTAB_LIB_WIDEN);
1962 return plus_constant (x, low);
1966 /* We do not allow indirect calls to be optimized into sibling calls, nor
1967 can we allow a call to a function with a different GP to be optimized
1968 into a sibcall. */
1970 static bool
1971 alpha_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
1973 /* Can't do indirect tail calls, since we don't know if the target
1974 uses the same GP. */
1975 if (!decl)
1976 return false;
1978 /* Otherwise, we can make a tail call if the target function shares
1979 the same GP. */
1980 return decl_has_samegp (decl);
1983 /* For TARGET_EXPLICIT_RELOCS, we don't obfuscate a SYMBOL_REF to a
1984 small symbolic operand until after reload. At which point we need
1985 to replace (mem (symbol_ref)) with (mem (lo_sum $29 symbol_ref))
1986 so that sched2 has the proper dependency information. */
1988 static int
1989 some_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
1991 rtx x = *px;
1993 /* Don't re-split. */
1994 if (GET_CODE (x) == LO_SUM)
1995 return -1;
1997 return small_symbolic_operand (x, Pmode) != 0;
2001 some_small_symbolic_operand (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
2003 return for_each_rtx (&x, some_small_symbolic_operand_1, NULL);
2006 static int
2007 split_small_symbolic_operand_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
2009 rtx x = *px;
2011 /* Don't re-split. */
2012 if (GET_CODE (x) == LO_SUM)
2013 return -1;
2015 if (small_symbolic_operand (x, Pmode))
2017 x = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, x);
2018 *px = x;
2019 return -1;
2022 return 0;
2026 split_small_symbolic_operand (rtx x)
2028 x = copy_insn (x);
2029 for_each_rtx (&x, split_small_symbolic_operand_1, NULL);
2030 return x;
2033 /* Indicate that INSN cannot be duplicated. This is true for any insn
2034 that we've marked with gpdisp relocs, since those have to stay in
2035 1-1 correspondence with one another.
2037 Technically we could copy them if we could set up a mapping from one
2038 sequence number to another, across the set of insns to be duplicated.
2039 This seems overly complicated and error-prone since interblock motion
2040 from sched-ebb could move one of the pair of insns to a different block.
2042 Also cannot allow jsr insns to be duplicated. If they throw exceptions,
2043 then they'll be in a different block from their ldgp. Which could lead
2044 the bb reorder code to think that it would be ok to copy just the block
2045 containing the call and branch to the block containing the ldgp. */
2047 static bool
2048 alpha_cannot_copy_insn_p (rtx insn)
2050 if (!reload_completed || !TARGET_EXPLICIT_RELOCS)
2051 return false;
2052 if (recog_memoized (insn) >= 0)
2053 return get_attr_cannot_copy (insn);
2054 else
2055 return false;
2059 /* Try a machine-dependent way of reloading an illegitimate address
2060 operand. If we find one, push the reload and return the new rtx. */
2063 alpha_legitimize_reload_address (rtx x,
2064 enum machine_mode mode ATTRIBUTE_UNUSED,
2065 int opnum, int type,
2066 int ind_levels ATTRIBUTE_UNUSED)
2068 /* We must recognize output that we have already generated ourselves. */
2069 if (GET_CODE (x) == PLUS
2070 && GET_CODE (XEXP (x, 0)) == PLUS
2071 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2072 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2073 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2075 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2076 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2077 opnum, type);
2078 return x;
2081 /* We wish to handle large displacements off a base register by
2082 splitting the addend across an ldah and the mem insn. This
2083 cuts number of extra insns needed from 3 to 1. */
2084 if (GET_CODE (x) == PLUS
2085 && GET_CODE (XEXP (x, 0)) == REG
2086 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2087 && REGNO_OK_FOR_BASE_P (REGNO (XEXP (x, 0)))
2088 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2090 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2091 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2092 HOST_WIDE_INT high
2093 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2095 /* Check for 32-bit overflow. */
2096 if (high + low != val)
2097 return NULL_RTX;
2099 /* Reload the high part into a base reg; leave the low part
2100 in the mem directly. */
2101 x = gen_rtx_PLUS (GET_MODE (x),
2102 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2103 GEN_INT (high)),
2104 GEN_INT (low));
2106 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2107 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2108 opnum, type);
2109 return x;
2112 return NULL_RTX;
2115 /* Compute a (partial) cost for rtx X. Return true if the complete
2116 cost has been computed, and false if subexpressions should be
2117 scanned. In either case, *TOTAL contains the cost result. */
2119 static bool
2120 alpha_rtx_costs (rtx x, int code, int outer_code, int *total)
2122 enum machine_mode mode = GET_MODE (x);
2123 bool float_mode_p = FLOAT_MODE_P (mode);
2124 const struct alpha_rtx_cost_data *cost_data;
2126 if (optimize_size)
2127 cost_data = &alpha_rtx_cost_size;
2128 else
2129 cost_data = &alpha_rtx_cost_data[alpha_cpu];
2131 switch (code)
2133 case CONST_INT:
2134 /* If this is an 8-bit constant, return zero since it can be used
2135 nearly anywhere with no cost. If it is a valid operand for an
2136 ADD or AND, likewise return 0 if we know it will be used in that
2137 context. Otherwise, return 2 since it might be used there later.
2138 All other constants take at least two insns. */
2139 if (INTVAL (x) >= 0 && INTVAL (x) < 256)
2141 *total = 0;
2142 return true;
2144 /* FALLTHRU */
2146 case CONST_DOUBLE:
2147 if (x == CONST0_RTX (mode))
2148 *total = 0;
2149 else if ((outer_code == PLUS && add_operand (x, VOIDmode))
2150 || (outer_code == AND && and_operand (x, VOIDmode)))
2151 *total = 0;
2152 else if (add_operand (x, VOIDmode) || and_operand (x, VOIDmode))
2153 *total = 2;
2154 else
2155 *total = COSTS_N_INSNS (2);
2156 return true;
2158 case CONST:
2159 case SYMBOL_REF:
2160 case LABEL_REF:
2161 if (TARGET_EXPLICIT_RELOCS && small_symbolic_operand (x, VOIDmode))
2162 *total = COSTS_N_INSNS (outer_code != MEM);
2163 else if (TARGET_EXPLICIT_RELOCS && local_symbolic_operand (x, VOIDmode))
2164 *total = COSTS_N_INSNS (1 + (outer_code != MEM));
2165 else if (tls_symbolic_operand_type (x))
2166 /* Estimate of cost for call_pal rduniq. */
2167 /* ??? How many insns do we emit here? More than one... */
2168 *total = COSTS_N_INSNS (15);
2169 else
2170 /* Otherwise we do a load from the GOT. */
2171 *total = COSTS_N_INSNS (optimize_size ? 1 : alpha_memory_latency);
2172 return true;
2174 case PLUS:
2175 case MINUS:
2176 if (float_mode_p)
2177 *total = cost_data->fp_add;
2178 else if (GET_CODE (XEXP (x, 0)) == MULT
2179 && const48_operand (XEXP (XEXP (x, 0), 1), VOIDmode))
2181 *total = (rtx_cost (XEXP (XEXP (x, 0), 0), outer_code)
2182 + rtx_cost (XEXP (x, 1), outer_code) + COSTS_N_INSNS (1));
2183 return true;
2185 return false;
2187 case MULT:
2188 if (float_mode_p)
2189 *total = cost_data->fp_mult;
2190 else if (mode == DImode)
2191 *total = cost_data->int_mult_di;
2192 else
2193 *total = cost_data->int_mult_si;
2194 return false;
2196 case ASHIFT:
2197 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2198 && INTVAL (XEXP (x, 1)) <= 3)
2200 *total = COSTS_N_INSNS (1);
2201 return false;
2203 /* FALLTHRU */
2205 case ASHIFTRT:
2206 case LSHIFTRT:
2207 *total = cost_data->int_shift;
2208 return false;
2210 case IF_THEN_ELSE:
2211 if (float_mode_p)
2212 *total = cost_data->fp_add;
2213 else
2214 *total = cost_data->int_cmov;
2215 return false;
2217 case DIV:
2218 case UDIV:
2219 case MOD:
2220 case UMOD:
2221 if (!float_mode_p)
2222 *total = cost_data->int_div;
2223 else if (mode == SFmode)
2224 *total = cost_data->fp_div_sf;
2225 else
2226 *total = cost_data->fp_div_df;
2227 return false;
2229 case MEM:
2230 *total = COSTS_N_INSNS (optimize_size ? 1 : alpha_memory_latency);
2231 return true;
2233 case NEG:
2234 if (! float_mode_p)
2236 *total = COSTS_N_INSNS (1);
2237 return false;
2239 /* FALLTHRU */
2241 case ABS:
2242 if (! float_mode_p)
2244 *total = COSTS_N_INSNS (1) + cost_data->int_cmov;
2245 return false;
2247 /* FALLTHRU */
2249 case FLOAT:
2250 case UNSIGNED_FLOAT:
2251 case FIX:
2252 case UNSIGNED_FIX:
2253 case FLOAT_EXTEND:
2254 case FLOAT_TRUNCATE:
2255 *total = cost_data->fp_add;
2256 return false;
2258 default:
2259 return false;
2263 /* REF is an alignable memory location. Place an aligned SImode
2264 reference into *PALIGNED_MEM and the number of bits to shift into
2265 *PBITNUM. SCRATCH is a free register for use in reloading out
2266 of range stack slots. */
2268 void
2269 get_aligned_mem (rtx ref, rtx *paligned_mem, rtx *pbitnum)
2271 rtx base;
2272 HOST_WIDE_INT offset = 0;
2274 if (GET_CODE (ref) != MEM)
2275 abort ();
2277 if (reload_in_progress
2278 && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2280 base = find_replacement (&XEXP (ref, 0));
2282 if (! memory_address_p (GET_MODE (ref), base))
2283 abort ();
2285 else
2287 base = XEXP (ref, 0);
2290 if (GET_CODE (base) == PLUS)
2291 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2293 *paligned_mem
2294 = widen_memory_access (ref, SImode, (offset & ~3) - offset);
2296 if (WORDS_BIG_ENDIAN)
2297 *pbitnum = GEN_INT (32 - (GET_MODE_BITSIZE (GET_MODE (ref))
2298 + (offset & 3) * 8));
2299 else
2300 *pbitnum = GEN_INT ((offset & 3) * 8);
2303 /* Similar, but just get the address. Handle the two reload cases.
2304 Add EXTRA_OFFSET to the address we return. */
2307 get_unaligned_address (rtx ref, int extra_offset)
2309 rtx base;
2310 HOST_WIDE_INT offset = 0;
2312 if (GET_CODE (ref) != MEM)
2313 abort ();
2315 if (reload_in_progress
2316 && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
2318 base = find_replacement (&XEXP (ref, 0));
2320 if (! memory_address_p (GET_MODE (ref), base))
2321 abort ();
2323 else
2325 base = XEXP (ref, 0);
2328 if (GET_CODE (base) == PLUS)
2329 offset += INTVAL (XEXP (base, 1)), base = XEXP (base, 0);
2331 return plus_constant (base, offset + extra_offset);
2334 /* On the Alpha, all (non-symbolic) constants except zero go into
2335 a floating-point register via memory. Note that we cannot
2336 return anything that is not a subset of CLASS, and that some
2337 symbolic constants cannot be dropped to memory. */
2339 enum reg_class
2340 alpha_preferred_reload_class(rtx x, enum reg_class class)
2342 /* Zero is present in any register class. */
2343 if (x == CONST0_RTX (GET_MODE (x)))
2344 return class;
2346 /* These sorts of constants we can easily drop to memory. */
2347 if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
2349 if (class == FLOAT_REGS)
2350 return NO_REGS;
2351 if (class == ALL_REGS)
2352 return GENERAL_REGS;
2353 return class;
2356 /* All other kinds of constants should not (and in the case of HIGH
2357 cannot) be dropped to memory -- instead we use a GENERAL_REGS
2358 secondary reload. */
2359 if (CONSTANT_P (x))
2360 return (class == ALL_REGS ? GENERAL_REGS : class);
2362 return class;
2365 /* Loading and storing HImode or QImode values to and from memory
2366 usually requires a scratch register. The exceptions are loading
2367 QImode and HImode from an aligned address to a general register
2368 unless byte instructions are permitted.
2370 We also cannot load an unaligned address or a paradoxical SUBREG
2371 into an FP register.
2373 We also cannot do integral arithmetic into FP regs, as might result
2374 from register elimination into a DImode fp register. */
2376 enum reg_class
2377 secondary_reload_class (enum reg_class class, enum machine_mode mode,
2378 rtx x, int in)
2380 if ((mode == QImode || mode == HImode) && ! TARGET_BWX)
2382 if (GET_CODE (x) == MEM
2383 || (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER)
2384 || (GET_CODE (x) == SUBREG
2385 && (GET_CODE (SUBREG_REG (x)) == MEM
2386 || (GET_CODE (SUBREG_REG (x)) == REG
2387 && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER))))
2389 if (!in || !aligned_memory_operand(x, mode))
2390 return GENERAL_REGS;
2394 if (class == FLOAT_REGS)
2396 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
2397 return GENERAL_REGS;
2399 if (GET_CODE (x) == SUBREG
2400 && (GET_MODE_SIZE (GET_MODE (x))
2401 > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))))
2402 return GENERAL_REGS;
2404 if (in && INTEGRAL_MODE_P (mode)
2405 && ! (memory_operand (x, mode) || x == const0_rtx))
2406 return GENERAL_REGS;
2409 return NO_REGS;
2412 /* Subfunction of the following function. Update the flags of any MEM
2413 found in part of X. */
2415 static void
2416 alpha_set_memflags_1 (rtx x, int in_struct_p, int volatile_p, int unchanging_p)
2418 int i;
2420 switch (GET_CODE (x))
2422 case SEQUENCE:
2423 abort ();
2425 case PARALLEL:
2426 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
2427 alpha_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
2428 unchanging_p);
2429 break;
2431 case INSN:
2432 alpha_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
2433 unchanging_p);
2434 break;
2436 case SET:
2437 alpha_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
2438 unchanging_p);
2439 alpha_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p,
2440 unchanging_p);
2441 break;
2443 case MEM:
2444 MEM_IN_STRUCT_P (x) = in_struct_p;
2445 MEM_VOLATILE_P (x) = volatile_p;
2446 RTX_UNCHANGING_P (x) = unchanging_p;
2447 /* Sadly, we cannot use alias sets because the extra aliasing
2448 produced by the AND interferes. Given that two-byte quantities
2449 are the only thing we would be able to differentiate anyway,
2450 there does not seem to be any point in convoluting the early
2451 out of the alias check. */
2452 break;
2454 default:
2455 break;
2459 /* Given INSN, which is an INSN list or the PATTERN of a single insn
2460 generated to perform a memory operation, look for any MEMs in either
2461 a SET_DEST or a SET_SRC and copy the in-struct, unchanging, and
2462 volatile flags from REF into each of the MEMs found. If REF is not
2463 a MEM, don't do anything. */
2465 void
2466 alpha_set_memflags (rtx insn, rtx ref)
2468 int in_struct_p, volatile_p, unchanging_p;
2470 if (GET_CODE (ref) != MEM)
2471 return;
2473 in_struct_p = MEM_IN_STRUCT_P (ref);
2474 volatile_p = MEM_VOLATILE_P (ref);
2475 unchanging_p = RTX_UNCHANGING_P (ref);
2477 /* This is only called from alpha.md, after having had something
2478 generated from one of the insn patterns. So if everything is
2479 zero, the pattern is already up-to-date. */
2480 if (! in_struct_p && ! volatile_p && ! unchanging_p)
2481 return;
2483 alpha_set_memflags_1 (insn, in_struct_p, volatile_p, unchanging_p);
2486 /* Internal routine for alpha_emit_set_const to check for N or below insns. */
2488 static rtx
2489 alpha_emit_set_const_1 (rtx target, enum machine_mode mode,
2490 HOST_WIDE_INT c, int n)
2492 HOST_WIDE_INT new;
2493 int i, bits;
2494 /* Use a pseudo if highly optimizing and still generating RTL. */
2495 rtx subtarget
2496 = (flag_expensive_optimizations && !no_new_pseudos ? 0 : target);
2497 rtx temp, insn;
2499 /* If this is a sign-extended 32-bit constant, we can do this in at most
2500 three insns, so do it if we have enough insns left. We always have
2501 a sign-extended 32-bit constant when compiling on a narrow machine. */
2503 if (HOST_BITS_PER_WIDE_INT != 64
2504 || c >> 31 == -1 || c >> 31 == 0)
2506 HOST_WIDE_INT low = ((c & 0xffff) ^ 0x8000) - 0x8000;
2507 HOST_WIDE_INT tmp1 = c - low;
2508 HOST_WIDE_INT high = (((tmp1 >> 16) & 0xffff) ^ 0x8000) - 0x8000;
2509 HOST_WIDE_INT extra = 0;
2511 /* If HIGH will be interpreted as negative but the constant is
2512 positive, we must adjust it to do two ldha insns. */
2514 if ((high & 0x8000) != 0 && c >= 0)
2516 extra = 0x4000;
2517 tmp1 -= 0x40000000;
2518 high = ((tmp1 >> 16) & 0xffff) - 2 * ((tmp1 >> 16) & 0x8000);
2521 if (c == low || (low == 0 && extra == 0))
2523 /* We used to use copy_to_suggested_reg (GEN_INT (c), target, mode)
2524 but that meant that we can't handle INT_MIN on 32-bit machines
2525 (like NT/Alpha), because we recurse indefinitely through
2526 emit_move_insn to gen_movdi. So instead, since we know exactly
2527 what we want, create it explicitly. */
2529 if (target == NULL)
2530 target = gen_reg_rtx (mode);
2531 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (c)));
2532 return target;
2534 else if (n >= 2 + (extra != 0))
2536 if (no_new_pseudos)
2538 emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (high << 16)));
2539 temp = target;
2541 else
2542 temp = copy_to_suggested_reg (GEN_INT (high << 16),
2543 subtarget, mode);
2545 /* As of 2002-02-23, addsi3 is only available when not optimizing.
2546 This means that if we go through expand_binop, we'll try to
2547 generate extensions, etc, which will require new pseudos, which
2548 will fail during some split phases. The SImode add patterns
2549 still exist, but are not named. So build the insns by hand. */
2551 if (extra != 0)
2553 if (! subtarget)
2554 subtarget = gen_reg_rtx (mode);
2555 insn = gen_rtx_PLUS (mode, temp, GEN_INT (extra << 16));
2556 insn = gen_rtx_SET (VOIDmode, subtarget, insn);
2557 emit_insn (insn);
2558 temp = subtarget;
2561 if (target == NULL)
2562 target = gen_reg_rtx (mode);
2563 insn = gen_rtx_PLUS (mode, temp, GEN_INT (low));
2564 insn = gen_rtx_SET (VOIDmode, target, insn);
2565 emit_insn (insn);
2566 return target;
2570 /* If we couldn't do it that way, try some other methods. But if we have
2571 no instructions left, don't bother. Likewise, if this is SImode and
2572 we can't make pseudos, we can't do anything since the expand_binop
2573 and expand_unop calls will widen and try to make pseudos. */
2575 if (n == 1 || (mode == SImode && no_new_pseudos))
2576 return 0;
2578 /* Next, see if we can load a related constant and then shift and possibly
2579 negate it to get the constant we want. Try this once each increasing
2580 numbers of insns. */
2582 for (i = 1; i < n; i++)
2584 /* First, see if minus some low bits, we've an easy load of
2585 high bits. */
2587 new = ((c & 0xffff) ^ 0x8000) - 0x8000;
2588 if (new != 0
2589 && (temp = alpha_emit_set_const (subtarget, mode, c - new, i)) != 0)
2590 return expand_binop (mode, add_optab, temp, GEN_INT (new),
2591 target, 0, OPTAB_WIDEN);
2593 /* Next try complementing. */
2594 if ((temp = alpha_emit_set_const (subtarget, mode, ~ c, i)) != 0)
2595 return expand_unop (mode, one_cmpl_optab, temp, target, 0);
2597 /* Next try to form a constant and do a left shift. We can do this
2598 if some low-order bits are zero; the exact_log2 call below tells
2599 us that information. The bits we are shifting out could be any
2600 value, but here we'll just try the 0- and sign-extended forms of
2601 the constant. To try to increase the chance of having the same
2602 constant in more than one insn, start at the highest number of
2603 bits to shift, but try all possibilities in case a ZAPNOT will
2604 be useful. */
2606 if ((bits = exact_log2 (c & - c)) > 0)
2607 for (; bits > 0; bits--)
2608 if ((temp = (alpha_emit_set_const
2609 (subtarget, mode, c >> bits, i))) != 0
2610 || ((temp = (alpha_emit_set_const
2611 (subtarget, mode,
2612 ((unsigned HOST_WIDE_INT) c) >> bits, i)))
2613 != 0))
2614 return expand_binop (mode, ashl_optab, temp, GEN_INT (bits),
2615 target, 0, OPTAB_WIDEN);
2617 /* Now try high-order zero bits. Here we try the shifted-in bits as
2618 all zero and all ones. Be careful to avoid shifting outside the
2619 mode and to avoid shifting outside the host wide int size. */
2620 /* On narrow hosts, don't shift a 1 into the high bit, since we'll
2621 confuse the recursive call and set all of the high 32 bits. */
2623 if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
2624 - floor_log2 (c) - 1 - (HOST_BITS_PER_WIDE_INT < 64))) > 0)
2625 for (; bits > 0; bits--)
2626 if ((temp = alpha_emit_set_const (subtarget, mode,
2627 c << bits, i)) != 0
2628 || ((temp = (alpha_emit_set_const
2629 (subtarget, mode,
2630 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
2631 i)))
2632 != 0))
2633 return expand_binop (mode, lshr_optab, temp, GEN_INT (bits),
2634 target, 1, OPTAB_WIDEN);
2636 /* Now try high-order 1 bits. We get that with a sign-extension.
2637 But one bit isn't enough here. Be careful to avoid shifting outside
2638 the mode and to avoid shifting outside the host wide int size. */
2640 if ((bits = (MIN (HOST_BITS_PER_WIDE_INT, GET_MODE_SIZE (mode) * 8)
2641 - floor_log2 (~ c) - 2)) > 0)
2642 for (; bits > 0; bits--)
2643 if ((temp = alpha_emit_set_const (subtarget, mode,
2644 c << bits, i)) != 0
2645 || ((temp = (alpha_emit_set_const
2646 (subtarget, mode,
2647 ((c << bits) | (((HOST_WIDE_INT) 1 << bits) - 1)),
2648 i)))
2649 != 0))
2650 return expand_binop (mode, ashr_optab, temp, GEN_INT (bits),
2651 target, 0, OPTAB_WIDEN);
2654 #if HOST_BITS_PER_WIDE_INT == 64
2655 /* Finally, see if can load a value into the target that is the same as the
2656 constant except that all bytes that are 0 are changed to be 0xff. If we
2657 can, then we can do a ZAPNOT to obtain the desired constant. */
2659 new = c;
2660 for (i = 0; i < 64; i += 8)
2661 if ((new & ((HOST_WIDE_INT) 0xff << i)) == 0)
2662 new |= (HOST_WIDE_INT) 0xff << i;
2664 /* We are only called for SImode and DImode. If this is SImode, ensure that
2665 we are sign extended to a full word. */
2667 if (mode == SImode)
2668 new = ((new & 0xffffffff) ^ 0x80000000) - 0x80000000;
2670 if (new != c && new != -1
2671 && (temp = alpha_emit_set_const (subtarget, mode, new, n - 1)) != 0)
2672 return expand_binop (mode, and_optab, temp, GEN_INT (c | ~ new),
2673 target, 0, OPTAB_WIDEN);
2674 #endif
2676 return 0;
2679 /* Try to output insns to set TARGET equal to the constant C if it can be
2680 done in less than N insns. Do all computations in MODE. Returns the place
2681 where the output has been placed if it can be done and the insns have been
2682 emitted. If it would take more than N insns, zero is returned and no
2683 insns and emitted. */
2686 alpha_emit_set_const (rtx target, enum machine_mode mode,
2687 HOST_WIDE_INT c, int n)
2689 rtx result = 0;
2690 rtx orig_target = target;
2691 int i;
2693 /* If we can't make any pseudos, TARGET is an SImode hard register, we
2694 can't load this constant in one insn, do this in DImode. */
2695 if (no_new_pseudos && mode == SImode
2696 && GET_CODE (target) == REG && REGNO (target) < FIRST_PSEUDO_REGISTER
2697 && (result = alpha_emit_set_const_1 (target, mode, c, 1)) == 0)
2699 target = gen_lowpart (DImode, target);
2700 mode = DImode;
2703 /* Try 1 insn, then 2, then up to N. */
2704 for (i = 1; i <= n; i++)
2706 result = alpha_emit_set_const_1 (target, mode, c, i);
2707 if (result)
2709 rtx insn = get_last_insn ();
2710 rtx set = single_set (insn);
2711 if (! CONSTANT_P (SET_SRC (set)))
2712 set_unique_reg_note (get_last_insn (), REG_EQUAL, GEN_INT (c));
2713 break;
2717 /* Allow for the case where we changed the mode of TARGET. */
2718 if (result == target)
2719 result = orig_target;
2721 return result;
2724 /* Having failed to find a 3 insn sequence in alpha_emit_set_const,
2725 fall back to a straight forward decomposition. We do this to avoid
2726 exponential run times encountered when looking for longer sequences
2727 with alpha_emit_set_const. */
2730 alpha_emit_set_long_const (rtx target, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2732 HOST_WIDE_INT d1, d2, d3, d4;
2734 /* Decompose the entire word */
2735 #if HOST_BITS_PER_WIDE_INT >= 64
2736 if (c2 != -(c1 < 0))
2737 abort ();
2738 d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2739 c1 -= d1;
2740 d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2741 c1 = (c1 - d2) >> 32;
2742 d3 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2743 c1 -= d3;
2744 d4 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2745 if (c1 != d4)
2746 abort ();
2747 #else
2748 d1 = ((c1 & 0xffff) ^ 0x8000) - 0x8000;
2749 c1 -= d1;
2750 d2 = ((c1 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2751 if (c1 != d2)
2752 abort ();
2753 c2 += (d2 < 0);
2754 d3 = ((c2 & 0xffff) ^ 0x8000) - 0x8000;
2755 c2 -= d3;
2756 d4 = ((c2 & 0xffffffff) ^ 0x80000000) - 0x80000000;
2757 if (c2 != d4)
2758 abort ();
2759 #endif
2761 /* Construct the high word */
2762 if (d4)
2764 emit_move_insn (target, GEN_INT (d4));
2765 if (d3)
2766 emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d3)));
2768 else
2769 emit_move_insn (target, GEN_INT (d3));
2771 /* Shift it into place */
2772 emit_move_insn (target, gen_rtx_ASHIFT (DImode, target, GEN_INT (32)));
2774 /* Add in the low bits. */
2775 if (d2)
2776 emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d2)));
2777 if (d1)
2778 emit_move_insn (target, gen_rtx_PLUS (DImode, target, GEN_INT (d1)));
2780 return target;
2783 /* Expand a move instruction; return true if all work is done.
2784 We don't handle non-bwx subword loads here. */
2786 bool
2787 alpha_expand_mov (enum machine_mode mode, rtx *operands)
2789 /* If the output is not a register, the input must be. */
2790 if (GET_CODE (operands[0]) == MEM
2791 && ! reg_or_0_operand (operands[1], mode))
2792 operands[1] = force_reg (mode, operands[1]);
2794 /* Allow legitimize_address to perform some simplifications. */
2795 if (mode == Pmode && symbolic_operand (operands[1], mode))
2797 rtx tmp;
2799 /* With RTL inlining, at -O3, rtl is generated, stored, then actually
2800 compiled at the end of compilation. In the meantime, someone can
2801 re-encode-section-info on some symbol changing it e.g. from global
2802 to local-not-small. If this happens, we'd have emitted a plain
2803 load rather than a high+losum load and not recognize the insn.
2805 So if rtl inlining is in effect, we delay the global/not-global
2806 decision until rest_of_compilation by wrapping it in an
2807 UNSPEC_SYMBOL. */
2808 if (TARGET_EXPLICIT_RELOCS && flag_inline_functions
2809 && rtx_equal_function_value_matters
2810 && global_symbolic_operand (operands[1], mode))
2812 emit_insn (gen_movdi_er_maybe_g (operands[0], operands[1]));
2813 return true;
2816 tmp = alpha_legitimize_address (operands[1], operands[0], mode);
2817 if (tmp)
2819 if (tmp == operands[0])
2820 return true;
2821 operands[1] = tmp;
2822 return false;
2826 /* Early out for non-constants and valid constants. */
2827 if (! CONSTANT_P (operands[1]) || input_operand (operands[1], mode))
2828 return false;
2830 /* Split large integers. */
2831 if (GET_CODE (operands[1]) == CONST_INT
2832 || GET_CODE (operands[1]) == CONST_DOUBLE)
2834 HOST_WIDE_INT i0, i1;
2835 rtx temp = NULL_RTX;
2837 if (GET_CODE (operands[1]) == CONST_INT)
2839 i0 = INTVAL (operands[1]);
2840 i1 = -(i0 < 0);
2842 else if (HOST_BITS_PER_WIDE_INT >= 64)
2844 i0 = CONST_DOUBLE_LOW (operands[1]);
2845 i1 = -(i0 < 0);
2847 else
2849 i0 = CONST_DOUBLE_LOW (operands[1]);
2850 i1 = CONST_DOUBLE_HIGH (operands[1]);
2853 if (HOST_BITS_PER_WIDE_INT >= 64 || i1 == -(i0 < 0))
2854 temp = alpha_emit_set_const (operands[0], mode, i0, 3);
2856 if (!temp && TARGET_BUILD_CONSTANTS)
2857 temp = alpha_emit_set_long_const (operands[0], i0, i1);
2859 if (temp)
2861 if (rtx_equal_p (operands[0], temp))
2862 return true;
2863 operands[1] = temp;
2864 return false;
2868 /* Otherwise we've nothing left but to drop the thing to memory. */
2869 operands[1] = force_const_mem (mode, operands[1]);
2870 if (reload_in_progress)
2872 emit_move_insn (operands[0], XEXP (operands[1], 0));
2873 operands[1] = copy_rtx (operands[1]);
2874 XEXP (operands[1], 0) = operands[0];
2876 else
2877 operands[1] = validize_mem (operands[1]);
2878 return false;
2881 /* Expand a non-bwx QImode or HImode move instruction;
2882 return true if all work is done. */
2884 bool
2885 alpha_expand_mov_nobwx (enum machine_mode mode, rtx *operands)
2887 /* If the output is not a register, the input must be. */
2888 if (GET_CODE (operands[0]) == MEM)
2889 operands[1] = force_reg (mode, operands[1]);
2891 /* Handle four memory cases, unaligned and aligned for either the input
2892 or the output. The only case where we can be called during reload is
2893 for aligned loads; all other cases require temporaries. */
2895 if (GET_CODE (operands[1]) == MEM
2896 || (GET_CODE (operands[1]) == SUBREG
2897 && GET_CODE (SUBREG_REG (operands[1])) == MEM)
2898 || (reload_in_progress && GET_CODE (operands[1]) == REG
2899 && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER)
2900 || (reload_in_progress && GET_CODE (operands[1]) == SUBREG
2901 && GET_CODE (SUBREG_REG (operands[1])) == REG
2902 && REGNO (SUBREG_REG (operands[1])) >= FIRST_PSEUDO_REGISTER))
2904 if (aligned_memory_operand (operands[1], mode))
2906 if (reload_in_progress)
2908 emit_insn ((mode == QImode
2909 ? gen_reload_inqi_help
2910 : gen_reload_inhi_help)
2911 (operands[0], operands[1],
2912 gen_rtx_REG (SImode, REGNO (operands[0]))));
2914 else
2916 rtx aligned_mem, bitnum;
2917 rtx scratch = gen_reg_rtx (SImode);
2918 rtx subtarget;
2919 bool copyout;
2921 get_aligned_mem (operands[1], &aligned_mem, &bitnum);
2923 subtarget = operands[0];
2924 if (GET_CODE (subtarget) == REG)
2925 subtarget = gen_lowpart (DImode, subtarget), copyout = false;
2926 else
2927 subtarget = gen_reg_rtx (DImode), copyout = true;
2929 emit_insn ((mode == QImode
2930 ? gen_aligned_loadqi
2931 : gen_aligned_loadhi)
2932 (subtarget, aligned_mem, bitnum, scratch));
2934 if (copyout)
2935 emit_move_insn (operands[0], gen_lowpart (mode, subtarget));
2938 else
2940 /* Don't pass these as parameters since that makes the generated
2941 code depend on parameter evaluation order which will cause
2942 bootstrap failures. */
2944 rtx temp1, temp2, seq, subtarget;
2945 bool copyout;
2947 temp1 = gen_reg_rtx (DImode);
2948 temp2 = gen_reg_rtx (DImode);
2950 subtarget = operands[0];
2951 if (GET_CODE (subtarget) == REG)
2952 subtarget = gen_lowpart (DImode, subtarget), copyout = false;
2953 else
2954 subtarget = gen_reg_rtx (DImode), copyout = true;
2956 seq = ((mode == QImode
2957 ? gen_unaligned_loadqi
2958 : gen_unaligned_loadhi)
2959 (subtarget, get_unaligned_address (operands[1], 0),
2960 temp1, temp2));
2961 alpha_set_memflags (seq, operands[1]);
2962 emit_insn (seq);
2964 if (copyout)
2965 emit_move_insn (operands[0], gen_lowpart (mode, subtarget));
2967 return true;
2970 if (GET_CODE (operands[0]) == MEM
2971 || (GET_CODE (operands[0]) == SUBREG
2972 && GET_CODE (SUBREG_REG (operands[0])) == MEM)
2973 || (reload_in_progress && GET_CODE (operands[0]) == REG
2974 && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER)
2975 || (reload_in_progress && GET_CODE (operands[0]) == SUBREG
2976 && GET_CODE (SUBREG_REG (operands[0])) == REG
2977 && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))
2979 if (aligned_memory_operand (operands[0], mode))
2981 rtx aligned_mem, bitnum;
2982 rtx temp1 = gen_reg_rtx (SImode);
2983 rtx temp2 = gen_reg_rtx (SImode);
2985 get_aligned_mem (operands[0], &aligned_mem, &bitnum);
2987 emit_insn (gen_aligned_store (aligned_mem, operands[1], bitnum,
2988 temp1, temp2));
2990 else
2992 rtx temp1 = gen_reg_rtx (DImode);
2993 rtx temp2 = gen_reg_rtx (DImode);
2994 rtx temp3 = gen_reg_rtx (DImode);
2995 rtx seq = ((mode == QImode
2996 ? gen_unaligned_storeqi
2997 : gen_unaligned_storehi)
2998 (get_unaligned_address (operands[0], 0),
2999 operands[1], temp1, temp2, temp3));
3001 alpha_set_memflags (seq, operands[0]);
3002 emit_insn (seq);
3004 return true;
3007 return false;
3010 /* Generate an unsigned DImode to FP conversion. This is the same code
3011 optabs would emit if we didn't have TFmode patterns.
3013 For SFmode, this is the only construction I've found that can pass
3014 gcc.c-torture/execute/ieee/rbug.c. No scenario that uses DFmode
3015 intermediates will work, because you'll get intermediate rounding
3016 that ruins the end result. Some of this could be fixed by turning
3017 on round-to-positive-infinity, but that requires diddling the fpsr,
3018 which kills performance. I tried turning this around and converting
3019 to a negative number, so that I could turn on /m, but either I did
3020 it wrong or there's something else cause I wound up with the exact
3021 same single-bit error. There is a branch-less form of this same code:
3023 srl $16,1,$1
3024 and $16,1,$2
3025 cmplt $16,0,$3
3026 or $1,$2,$2
3027 cmovge $16,$16,$2
3028 itoft $3,$f10
3029 itoft $2,$f11
3030 cvtqs $f11,$f11
3031 adds $f11,$f11,$f0
3032 fcmoveq $f10,$f11,$f0
3034 I'm not using it because it's the same number of instructions as
3035 this branch-full form, and it has more serialized long latency
3036 instructions on the critical path.
3038 For DFmode, we can avoid rounding errors by breaking up the word
3039 into two pieces, converting them separately, and adding them back:
3041 LC0: .long 0,0x5f800000
3043 itoft $16,$f11
3044 lda $2,LC0
3045 cmplt $16,0,$1
3046 cpyse $f11,$f31,$f10
3047 cpyse $f31,$f11,$f11
3048 s4addq $1,$2,$1
3049 lds $f12,0($1)
3050 cvtqt $f10,$f10
3051 cvtqt $f11,$f11
3052 addt $f12,$f10,$f0
3053 addt $f0,$f11,$f0
3055 This doesn't seem to be a clear-cut win over the optabs form.
3056 It probably all depends on the distribution of numbers being
3057 converted -- in the optabs form, all but high-bit-set has a
3058 much lower minimum execution time. */
3060 void
3061 alpha_emit_floatuns (rtx operands[2])
3063 rtx neglab, donelab, i0, i1, f0, in, out;
3064 enum machine_mode mode;
3066 out = operands[0];
3067 in = force_reg (DImode, operands[1]);
3068 mode = GET_MODE (out);
3069 neglab = gen_label_rtx ();
3070 donelab = gen_label_rtx ();
3071 i0 = gen_reg_rtx (DImode);
3072 i1 = gen_reg_rtx (DImode);
3073 f0 = gen_reg_rtx (mode);
3075 emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, DImode, 0, neglab);
3077 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_FLOAT (mode, in)));
3078 emit_jump_insn (gen_jump (donelab));
3079 emit_barrier ();
3081 emit_label (neglab);
3083 emit_insn (gen_lshrdi3 (i0, in, const1_rtx));
3084 emit_insn (gen_anddi3 (i1, in, const1_rtx));
3085 emit_insn (gen_iordi3 (i0, i0, i1));
3086 emit_insn (gen_rtx_SET (VOIDmode, f0, gen_rtx_FLOAT (mode, i0)));
3087 emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
3089 emit_label (donelab);
3092 /* Generate the comparison for a conditional branch. */
3095 alpha_emit_conditional_branch (enum rtx_code code)
3097 enum rtx_code cmp_code, branch_code;
3098 enum machine_mode cmp_mode, branch_mode = VOIDmode;
3099 rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1;
3100 rtx tem;
3102 if (alpha_compare.fp_p && GET_MODE (op0) == TFmode)
3104 if (! TARGET_HAS_XFLOATING_LIBS)
3105 abort ();
3107 /* X_floating library comparison functions return
3108 -1 unordered
3109 0 false
3110 1 true
3111 Convert the compare against the raw return value. */
3113 switch (code)
3115 case UNORDERED:
3116 cmp_code = EQ;
3117 code = LT;
3118 break;
3119 case ORDERED:
3120 cmp_code = EQ;
3121 code = GE;
3122 break;
3123 case NE:
3124 cmp_code = NE;
3125 code = NE;
3126 break;
3127 default:
3128 cmp_code = code;
3129 code = GT;
3130 break;
3133 op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3134 op1 = const0_rtx;
3135 alpha_compare.fp_p = 0;
3138 /* The general case: fold the comparison code to the types of compares
3139 that we have, choosing the branch as necessary. */
3140 switch (code)
3142 case EQ: case LE: case LT: case LEU: case LTU:
3143 case UNORDERED:
3144 /* We have these compares: */
3145 cmp_code = code, branch_code = NE;
3146 break;
3148 case NE:
3149 case ORDERED:
3150 /* These must be reversed. */
3151 cmp_code = reverse_condition (code), branch_code = EQ;
3152 break;
3154 case GE: case GT: case GEU: case GTU:
3155 /* For FP, we swap them, for INT, we reverse them. */
3156 if (alpha_compare.fp_p)
3158 cmp_code = swap_condition (code);
3159 branch_code = NE;
3160 tem = op0, op0 = op1, op1 = tem;
3162 else
3164 cmp_code = reverse_condition (code);
3165 branch_code = EQ;
3167 break;
3169 default:
3170 abort ();
3173 if (alpha_compare.fp_p)
3175 cmp_mode = DFmode;
3176 if (flag_unsafe_math_optimizations)
3178 /* When we are not as concerned about non-finite values, and we
3179 are comparing against zero, we can branch directly. */
3180 if (op1 == CONST0_RTX (DFmode))
3181 cmp_code = NIL, branch_code = code;
3182 else if (op0 == CONST0_RTX (DFmode))
3184 /* Undo the swap we probably did just above. */
3185 tem = op0, op0 = op1, op1 = tem;
3186 branch_code = swap_condition (cmp_code);
3187 cmp_code = NIL;
3190 else
3192 /* ??? We mark the branch mode to be CCmode to prevent the
3193 compare and branch from being combined, since the compare
3194 insn follows IEEE rules that the branch does not. */
3195 branch_mode = CCmode;
3198 else
3200 cmp_mode = DImode;
3202 /* The following optimizations are only for signed compares. */
3203 if (code != LEU && code != LTU && code != GEU && code != GTU)
3205 /* Whee. Compare and branch against 0 directly. */
3206 if (op1 == const0_rtx)
3207 cmp_code = NIL, branch_code = code;
3209 /* If the constants doesn't fit into an immediate, but can
3210 be generated by lda/ldah, we adjust the argument and
3211 compare against zero, so we can use beq/bne directly. */
3212 /* ??? Don't do this when comparing against symbols, otherwise
3213 we'll reduce (&x == 0x1234) to (&x-0x1234 == 0), which will
3214 be declared false out of hand (at least for non-weak). */
3215 else if (GET_CODE (op1) == CONST_INT
3216 && (code == EQ || code == NE)
3217 && !(symbolic_operand (op0, VOIDmode)
3218 || (GET_CODE (op0) == REG && REG_POINTER (op0))))
3220 HOST_WIDE_INT v = INTVAL (op1), n = -v;
3222 if (! CONST_OK_FOR_LETTER_P (v, 'I')
3223 && (CONST_OK_FOR_LETTER_P (n, 'K')
3224 || CONST_OK_FOR_LETTER_P (n, 'L')))
3226 cmp_code = PLUS, branch_code = code;
3227 op1 = GEN_INT (n);
3232 if (!reg_or_0_operand (op0, DImode))
3233 op0 = force_reg (DImode, op0);
3234 if (cmp_code != PLUS && !reg_or_8bit_operand (op1, DImode))
3235 op1 = force_reg (DImode, op1);
3238 /* Emit an initial compare instruction, if necessary. */
3239 tem = op0;
3240 if (cmp_code != NIL)
3242 tem = gen_reg_rtx (cmp_mode);
3243 emit_move_insn (tem, gen_rtx_fmt_ee (cmp_code, cmp_mode, op0, op1));
3246 /* Zero the operands. */
3247 memset (&alpha_compare, 0, sizeof (alpha_compare));
3249 /* Return the branch comparison. */
3250 return gen_rtx_fmt_ee (branch_code, branch_mode, tem, CONST0_RTX (cmp_mode));
3253 /* Certain simplifications can be done to make invalid setcc operations
3254 valid. Return the final comparison, or NULL if we can't work. */
3257 alpha_emit_setcc (enum rtx_code code)
3259 enum rtx_code cmp_code;
3260 rtx op0 = alpha_compare.op0, op1 = alpha_compare.op1;
3261 int fp_p = alpha_compare.fp_p;
3262 rtx tmp;
3264 /* Zero the operands. */
3265 memset (&alpha_compare, 0, sizeof (alpha_compare));
3267 if (fp_p && GET_MODE (op0) == TFmode)
3269 if (! TARGET_HAS_XFLOATING_LIBS)
3270 abort ();
3272 /* X_floating library comparison functions return
3273 -1 unordered
3274 0 false
3275 1 true
3276 Convert the compare against the raw return value. */
3278 if (code == UNORDERED || code == ORDERED)
3279 cmp_code = EQ;
3280 else
3281 cmp_code = code;
3283 op0 = alpha_emit_xfloating_compare (cmp_code, op0, op1);
3284 op1 = const0_rtx;
3285 fp_p = 0;
3287 if (code == UNORDERED)
3288 code = LT;
3289 else if (code == ORDERED)
3290 code = GE;
3291 else
3292 code = GT;
3295 if (fp_p && !TARGET_FIX)
3296 return NULL_RTX;
3298 /* The general case: fold the comparison code to the types of compares
3299 that we have, choosing the branch as necessary. */
3301 cmp_code = NIL;
3302 switch (code)
3304 case EQ: case LE: case LT: case LEU: case LTU:
3305 case UNORDERED:
3306 /* We have these compares. */
3307 if (fp_p)
3308 cmp_code = code, code = NE;
3309 break;
3311 case NE:
3312 if (!fp_p && op1 == const0_rtx)
3313 break;
3314 /* FALLTHRU */
3316 case ORDERED:
3317 cmp_code = reverse_condition (code);
3318 code = EQ;
3319 break;
3321 case GE: case GT: case GEU: case GTU:
3322 /* These normally need swapping, but for integer zero we have
3323 special patterns that recognize swapped operands. */
3324 if (!fp_p && op1 == const0_rtx)
3325 break;
3326 code = swap_condition (code);
3327 if (fp_p)
3328 cmp_code = code, code = NE;
3329 tmp = op0, op0 = op1, op1 = tmp;
3330 break;
3332 default:
3333 abort ();
3336 if (!fp_p)
3338 if (!register_operand (op0, DImode))
3339 op0 = force_reg (DImode, op0);
3340 if (!reg_or_8bit_operand (op1, DImode))
3341 op1 = force_reg (DImode, op1);
3344 /* Emit an initial compare instruction, if necessary. */
3345 if (cmp_code != NIL)
3347 enum machine_mode mode = fp_p ? DFmode : DImode;
3349 tmp = gen_reg_rtx (mode);
3350 emit_insn (gen_rtx_SET (VOIDmode, tmp,
3351 gen_rtx_fmt_ee (cmp_code, mode, op0, op1)));
3353 op0 = fp_p ? gen_lowpart (DImode, tmp) : tmp;
3354 op1 = const0_rtx;
3357 /* Return the setcc comparison. */
3358 return gen_rtx_fmt_ee (code, DImode, op0, op1);
3362 /* Rewrite a comparison against zero CMP of the form
3363 (CODE (cc0) (const_int 0)) so it can be written validly in
3364 a conditional move (if_then_else CMP ...).
3365 If both of the operands that set cc0 are nonzero we must emit
3366 an insn to perform the compare (it can't be done within
3367 the conditional move). */
3370 alpha_emit_conditional_move (rtx cmp, enum machine_mode mode)
3372 enum rtx_code code = GET_CODE (cmp);
3373 enum rtx_code cmov_code = NE;
3374 rtx op0 = alpha_compare.op0;
3375 rtx op1 = alpha_compare.op1;
3376 int fp_p = alpha_compare.fp_p;
3377 enum machine_mode cmp_mode
3378 = (GET_MODE (op0) == VOIDmode ? DImode : GET_MODE (op0));
3379 enum machine_mode cmp_op_mode = fp_p ? DFmode : DImode;
3380 enum machine_mode cmov_mode = VOIDmode;
3381 int local_fast_math = flag_unsafe_math_optimizations;
3382 rtx tem;
3384 /* Zero the operands. */
3385 memset (&alpha_compare, 0, sizeof (alpha_compare));
3387 if (fp_p != FLOAT_MODE_P (mode))
3389 enum rtx_code cmp_code;
3391 if (! TARGET_FIX)
3392 return 0;
3394 /* If we have fp<->int register move instructions, do a cmov by
3395 performing the comparison in fp registers, and move the
3396 zero/nonzero value to integer registers, where we can then
3397 use a normal cmov, or vice-versa. */
3399 switch (code)
3401 case EQ: case LE: case LT: case LEU: case LTU:
3402 /* We have these compares. */
3403 cmp_code = code, code = NE;
3404 break;
3406 case NE:
3407 /* This must be reversed. */
3408 cmp_code = EQ, code = EQ;
3409 break;
3411 case GE: case GT: case GEU: case GTU:
3412 /* These normally need swapping, but for integer zero we have
3413 special patterns that recognize swapped operands. */
3414 if (!fp_p && op1 == const0_rtx)
3415 cmp_code = code, code = NE;
3416 else
3418 cmp_code = swap_condition (code);
3419 code = NE;
3420 tem = op0, op0 = op1, op1 = tem;
3422 break;
3424 default:
3425 abort ();
3428 tem = gen_reg_rtx (cmp_op_mode);
3429 emit_insn (gen_rtx_SET (VOIDmode, tem,
3430 gen_rtx_fmt_ee (cmp_code, cmp_op_mode,
3431 op0, op1)));
3433 cmp_mode = cmp_op_mode = fp_p ? DImode : DFmode;
3434 op0 = gen_lowpart (cmp_op_mode, tem);
3435 op1 = CONST0_RTX (cmp_op_mode);
3436 fp_p = !fp_p;
3437 local_fast_math = 1;
3440 /* We may be able to use a conditional move directly.
3441 This avoids emitting spurious compares. */
3442 if (signed_comparison_operator (cmp, VOIDmode)
3443 && (!fp_p || local_fast_math)
3444 && (op0 == CONST0_RTX (cmp_mode) || op1 == CONST0_RTX (cmp_mode)))
3445 return gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
3447 /* We can't put the comparison inside the conditional move;
3448 emit a compare instruction and put that inside the
3449 conditional move. Make sure we emit only comparisons we have;
3450 swap or reverse as necessary. */
3452 if (no_new_pseudos)
3453 return NULL_RTX;
3455 switch (code)
3457 case EQ: case LE: case LT: case LEU: case LTU:
3458 /* We have these compares: */
3459 break;
3461 case NE:
3462 /* This must be reversed. */
3463 code = reverse_condition (code);
3464 cmov_code = EQ;
3465 break;
3467 case GE: case GT: case GEU: case GTU:
3468 /* These must be swapped. */
3469 if (op1 != CONST0_RTX (cmp_mode))
3471 code = swap_condition (code);
3472 tem = op0, op0 = op1, op1 = tem;
3474 break;
3476 default:
3477 abort ();
3480 if (!fp_p)
3482 if (!reg_or_0_operand (op0, DImode))
3483 op0 = force_reg (DImode, op0);
3484 if (!reg_or_8bit_operand (op1, DImode))
3485 op1 = force_reg (DImode, op1);
3488 /* ??? We mark the branch mode to be CCmode to prevent the compare
3489 and cmov from being combined, since the compare insn follows IEEE
3490 rules that the cmov does not. */
3491 if (fp_p && !local_fast_math)
3492 cmov_mode = CCmode;
3494 tem = gen_reg_rtx (cmp_op_mode);
3495 emit_move_insn (tem, gen_rtx_fmt_ee (code, cmp_op_mode, op0, op1));
3496 return gen_rtx_fmt_ee (cmov_code, cmov_mode, tem, CONST0_RTX (cmp_op_mode));
3499 /* Simplify a conditional move of two constants into a setcc with
3500 arithmetic. This is done with a splitter since combine would
3501 just undo the work if done during code generation. It also catches
3502 cases we wouldn't have before cse. */
3505 alpha_split_conditional_move (enum rtx_code code, rtx dest, rtx cond,
3506 rtx t_rtx, rtx f_rtx)
3508 HOST_WIDE_INT t, f, diff;
3509 enum machine_mode mode;
3510 rtx target, subtarget, tmp;
3512 mode = GET_MODE (dest);
3513 t = INTVAL (t_rtx);
3514 f = INTVAL (f_rtx);
3515 diff = t - f;
3517 if (((code == NE || code == EQ) && diff < 0)
3518 || (code == GE || code == GT))
3520 code = reverse_condition (code);
3521 diff = t, t = f, f = diff;
3522 diff = t - f;
3525 subtarget = target = dest;
3526 if (mode != DImode)
3528 target = gen_lowpart (DImode, dest);
3529 if (! no_new_pseudos)
3530 subtarget = gen_reg_rtx (DImode);
3531 else
3532 subtarget = target;
3534 /* Below, we must be careful to use copy_rtx on target and subtarget
3535 in intermediate insns, as they may be a subreg rtx, which may not
3536 be shared. */
3538 if (f == 0 && exact_log2 (diff) > 0
3539 /* On EV6, we've got enough shifters to make non-arithmetic shifts
3540 viable over a longer latency cmove. On EV5, the E0 slot is a
3541 scarce resource, and on EV4 shift has the same latency as a cmove. */
3542 && (diff <= 8 || alpha_cpu == PROCESSOR_EV6))
3544 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3545 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3547 tmp = gen_rtx_ASHIFT (DImode, copy_rtx (subtarget),
3548 GEN_INT (exact_log2 (t)));
3549 emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3551 else if (f == 0 && t == -1)
3553 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3554 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3556 emit_insn (gen_negdi2 (target, copy_rtx (subtarget)));
3558 else if (diff == 1 || diff == 4 || diff == 8)
3560 rtx add_op;
3562 tmp = gen_rtx_fmt_ee (code, DImode, cond, const0_rtx);
3563 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (subtarget), tmp));
3565 if (diff == 1)
3566 emit_insn (gen_adddi3 (target, copy_rtx (subtarget), GEN_INT (f)));
3567 else
3569 add_op = GEN_INT (f);
3570 if (sext_add_operand (add_op, mode))
3572 tmp = gen_rtx_MULT (DImode, copy_rtx (subtarget),
3573 GEN_INT (diff));
3574 tmp = gen_rtx_PLUS (DImode, tmp, add_op);
3575 emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
3577 else
3578 return 0;
3581 else
3582 return 0;
3584 return 1;
3587 /* Look up the function X_floating library function name for the
3588 given operation. */
3590 struct xfloating_op GTY(())
3592 const enum rtx_code code;
3593 const char *const GTY((skip)) osf_func;
3594 const char *const GTY((skip)) vms_func;
3595 rtx libcall;
3598 static GTY(()) struct xfloating_op xfloating_ops[] =
3600 { PLUS, "_OtsAddX", "OTS$ADD_X", 0 },
3601 { MINUS, "_OtsSubX", "OTS$SUB_X", 0 },
3602 { MULT, "_OtsMulX", "OTS$MUL_X", 0 },
3603 { DIV, "_OtsDivX", "OTS$DIV_X", 0 },
3604 { EQ, "_OtsEqlX", "OTS$EQL_X", 0 },
3605 { NE, "_OtsNeqX", "OTS$NEQ_X", 0 },
3606 { LT, "_OtsLssX", "OTS$LSS_X", 0 },
3607 { LE, "_OtsLeqX", "OTS$LEQ_X", 0 },
3608 { GT, "_OtsGtrX", "OTS$GTR_X", 0 },
3609 { GE, "_OtsGeqX", "OTS$GEQ_X", 0 },
3610 { FIX, "_OtsCvtXQ", "OTS$CVTXQ", 0 },
3611 { FLOAT, "_OtsCvtQX", "OTS$CVTQX", 0 },
3612 { UNSIGNED_FLOAT, "_OtsCvtQUX", "OTS$CVTQUX", 0 },
3613 { FLOAT_EXTEND, "_OtsConvertFloatTX", "OTS$CVT_FLOAT_T_X", 0 },
3614 { FLOAT_TRUNCATE, "_OtsConvertFloatXT", "OTS$CVT_FLOAT_X_T", 0 }
3617 static GTY(()) struct xfloating_op vax_cvt_ops[] =
3619 { FLOAT_EXTEND, "_OtsConvertFloatGX", "OTS$CVT_FLOAT_G_X", 0 },
3620 { FLOAT_TRUNCATE, "_OtsConvertFloatXG", "OTS$CVT_FLOAT_X_G", 0 }
3623 static rtx
3624 alpha_lookup_xfloating_lib_func (enum rtx_code code)
3626 struct xfloating_op *ops = xfloating_ops;
3627 long n = ARRAY_SIZE (xfloating_ops);
3628 long i;
3630 /* How irritating. Nothing to key off for the main table. */
3631 if (TARGET_FLOAT_VAX && (code == FLOAT_EXTEND || code == FLOAT_TRUNCATE))
3633 ops = vax_cvt_ops;
3634 n = ARRAY_SIZE (vax_cvt_ops);
3637 for (i = 0; i < n; ++i, ++ops)
3638 if (ops->code == code)
3640 rtx func = ops->libcall;
3641 if (!func)
3643 func = init_one_libfunc (TARGET_ABI_OPEN_VMS
3644 ? ops->vms_func : ops->osf_func);
3645 ops->libcall = func;
3647 return func;
3650 abort();
3653 /* Most X_floating operations take the rounding mode as an argument.
3654 Compute that here. */
3656 static int
3657 alpha_compute_xfloating_mode_arg (enum rtx_code code,
3658 enum alpha_fp_rounding_mode round)
3660 int mode;
3662 switch (round)
3664 case ALPHA_FPRM_NORM:
3665 mode = 2;
3666 break;
3667 case ALPHA_FPRM_MINF:
3668 mode = 1;
3669 break;
3670 case ALPHA_FPRM_CHOP:
3671 mode = 0;
3672 break;
3673 case ALPHA_FPRM_DYN:
3674 mode = 4;
3675 break;
3676 default:
3677 abort ();
3679 /* XXX For reference, round to +inf is mode = 3. */
3682 if (code == FLOAT_TRUNCATE && alpha_fptm == ALPHA_FPTM_N)
3683 mode |= 0x10000;
3685 return mode;
3688 /* Emit an X_floating library function call.
3690 Note that these functions do not follow normal calling conventions:
3691 TFmode arguments are passed in two integer registers (as opposed to
3692 indirect); TFmode return values appear in R16+R17.
3694 FUNC is the function to call.
3695 TARGET is where the output belongs.
3696 OPERANDS are the inputs.
3697 NOPERANDS is the count of inputs.
3698 EQUIV is the expression equivalent for the function.
3701 static void
3702 alpha_emit_xfloating_libcall (rtx func, rtx target, rtx operands[],
3703 int noperands, rtx equiv)
3705 rtx usage = NULL_RTX, tmp, reg;
3706 int regno = 16, i;
3708 start_sequence ();
3710 for (i = 0; i < noperands; ++i)
3712 switch (GET_MODE (operands[i]))
3714 case TFmode:
3715 reg = gen_rtx_REG (TFmode, regno);
3716 regno += 2;
3717 break;
3719 case DFmode:
3720 reg = gen_rtx_REG (DFmode, regno + 32);
3721 regno += 1;
3722 break;
3724 case VOIDmode:
3725 if (GET_CODE (operands[i]) != CONST_INT)
3726 abort ();
3727 /* FALLTHRU */
3728 case DImode:
3729 reg = gen_rtx_REG (DImode, regno);
3730 regno += 1;
3731 break;
3733 default:
3734 abort ();
3737 emit_move_insn (reg, operands[i]);
3738 usage = alloc_EXPR_LIST (0, gen_rtx_USE (VOIDmode, reg), usage);
3741 switch (GET_MODE (target))
3743 case TFmode:
3744 reg = gen_rtx_REG (TFmode, 16);
3745 break;
3746 case DFmode:
3747 reg = gen_rtx_REG (DFmode, 32);
3748 break;
3749 case DImode:
3750 reg = gen_rtx_REG (DImode, 0);
3751 break;
3752 default:
3753 abort ();
3756 tmp = gen_rtx_MEM (QImode, func);
3757 tmp = emit_call_insn (GEN_CALL_VALUE (reg, tmp, const0_rtx,
3758 const0_rtx, const0_rtx));
3759 CALL_INSN_FUNCTION_USAGE (tmp) = usage;
3760 CONST_OR_PURE_CALL_P (tmp) = 1;
3762 tmp = get_insns ();
3763 end_sequence ();
3765 emit_libcall_block (tmp, target, reg, equiv);
3768 /* Emit an X_floating library function call for arithmetic (+,-,*,/). */
3770 void
3771 alpha_emit_xfloating_arith (enum rtx_code code, rtx operands[])
3773 rtx func;
3774 int mode;
3775 rtx out_operands[3];
3777 func = alpha_lookup_xfloating_lib_func (code);
3778 mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3780 out_operands[0] = operands[1];
3781 out_operands[1] = operands[2];
3782 out_operands[2] = GEN_INT (mode);
3783 alpha_emit_xfloating_libcall (func, operands[0], out_operands, 3,
3784 gen_rtx_fmt_ee (code, TFmode, operands[1],
3785 operands[2]));
3788 /* Emit an X_floating library function call for a comparison. */
3790 static rtx
3791 alpha_emit_xfloating_compare (enum rtx_code code, rtx op0, rtx op1)
3793 rtx func;
3794 rtx out, operands[2];
3796 func = alpha_lookup_xfloating_lib_func (code);
3798 operands[0] = op0;
3799 operands[1] = op1;
3800 out = gen_reg_rtx (DImode);
3802 /* ??? Strange mode for equiv because what's actually returned
3803 is -1,0,1, not a proper boolean value. */
3804 alpha_emit_xfloating_libcall (func, out, operands, 2,
3805 gen_rtx_fmt_ee (code, CCmode, op0, op1));
3807 return out;
3810 /* Emit an X_floating library function call for a conversion. */
3812 void
3813 alpha_emit_xfloating_cvt (enum rtx_code orig_code, rtx operands[])
3815 int noperands = 1, mode;
3816 rtx out_operands[2];
3817 rtx func;
3818 enum rtx_code code = orig_code;
3820 if (code == UNSIGNED_FIX)
3821 code = FIX;
3823 func = alpha_lookup_xfloating_lib_func (code);
3825 out_operands[0] = operands[1];
3827 switch (code)
3829 case FIX:
3830 mode = alpha_compute_xfloating_mode_arg (code, ALPHA_FPRM_CHOP);
3831 out_operands[1] = GEN_INT (mode);
3832 noperands = 2;
3833 break;
3834 case FLOAT_TRUNCATE:
3835 mode = alpha_compute_xfloating_mode_arg (code, alpha_fprm);
3836 out_operands[1] = GEN_INT (mode);
3837 noperands = 2;
3838 break;
3839 default:
3840 break;
3843 alpha_emit_xfloating_libcall (func, operands[0], out_operands, noperands,
3844 gen_rtx_fmt_e (orig_code,
3845 GET_MODE (operands[0]),
3846 operands[1]));
3849 /* Split a TFmode OP[1] into DImode OP[2,3] and likewise for
3850 OP[0] into OP[0,1]. Naturally, output operand ordering is
3851 little-endian. */
3853 void
3854 alpha_split_tfmode_pair (rtx operands[4])
3856 if (GET_CODE (operands[1]) == REG)
3858 operands[3] = gen_rtx_REG (DImode, REGNO (operands[1]) + 1);
3859 operands[2] = gen_rtx_REG (DImode, REGNO (operands[1]));
3861 else if (GET_CODE (operands[1]) == MEM)
3863 operands[3] = adjust_address (operands[1], DImode, 8);
3864 operands[2] = adjust_address (operands[1], DImode, 0);
3866 else if (operands[1] == CONST0_RTX (TFmode))
3867 operands[2] = operands[3] = const0_rtx;
3868 else
3869 abort ();
3871 if (GET_CODE (operands[0]) == REG)
3873 operands[1] = gen_rtx_REG (DImode, REGNO (operands[0]) + 1);
3874 operands[0] = gen_rtx_REG (DImode, REGNO (operands[0]));
3876 else if (GET_CODE (operands[0]) == MEM)
3878 operands[1] = adjust_address (operands[0], DImode, 8);
3879 operands[0] = adjust_address (operands[0], DImode, 0);
3881 else
3882 abort ();
3885 /* Implement negtf2 or abstf2. Op0 is destination, op1 is source,
3886 op2 is a register containing the sign bit, operation is the
3887 logical operation to be performed. */
3889 void
3890 alpha_split_tfmode_frobsign (rtx operands[3], rtx (*operation) (rtx, rtx, rtx))
3892 rtx high_bit = operands[2];
3893 rtx scratch;
3894 int move;
3896 alpha_split_tfmode_pair (operands);
3898 /* Detect three flavors of operand overlap. */
3899 move = 1;
3900 if (rtx_equal_p (operands[0], operands[2]))
3901 move = 0;
3902 else if (rtx_equal_p (operands[1], operands[2]))
3904 if (rtx_equal_p (operands[0], high_bit))
3905 move = 2;
3906 else
3907 move = -1;
3910 if (move < 0)
3911 emit_move_insn (operands[0], operands[2]);
3913 /* ??? If the destination overlaps both source tf and high_bit, then
3914 assume source tf is dead in its entirety and use the other half
3915 for a scratch register. Otherwise "scratch" is just the proper
3916 destination register. */
3917 scratch = operands[move < 2 ? 1 : 3];
3919 emit_insn ((*operation) (scratch, high_bit, operands[3]));
3921 if (move > 0)
3923 emit_move_insn (operands[0], operands[2]);
3924 if (move > 1)
3925 emit_move_insn (operands[1], scratch);
3929 /* Use ext[wlq][lh] as the Architecture Handbook describes for extracting
3930 unaligned data:
3932 unsigned: signed:
3933 word: ldq_u r1,X(r11) ldq_u r1,X(r11)
3934 ldq_u r2,X+1(r11) ldq_u r2,X+1(r11)
3935 lda r3,X(r11) lda r3,X+2(r11)
3936 extwl r1,r3,r1 extql r1,r3,r1
3937 extwh r2,r3,r2 extqh r2,r3,r2
3938 or r1.r2.r1 or r1,r2,r1
3939 sra r1,48,r1
3941 long: ldq_u r1,X(r11) ldq_u r1,X(r11)
3942 ldq_u r2,X+3(r11) ldq_u r2,X+3(r11)
3943 lda r3,X(r11) lda r3,X(r11)
3944 extll r1,r3,r1 extll r1,r3,r1
3945 extlh r2,r3,r2 extlh r2,r3,r2
3946 or r1.r2.r1 addl r1,r2,r1
3948 quad: ldq_u r1,X(r11)
3949 ldq_u r2,X+7(r11)
3950 lda r3,X(r11)
3951 extql r1,r3,r1
3952 extqh r2,r3,r2
3953 or r1.r2.r1
3956 void
3957 alpha_expand_unaligned_load (rtx tgt, rtx mem, HOST_WIDE_INT size,
3958 HOST_WIDE_INT ofs, int sign)
3960 rtx meml, memh, addr, extl, exth, tmp, mema;
3961 enum machine_mode mode;
3963 meml = gen_reg_rtx (DImode);
3964 memh = gen_reg_rtx (DImode);
3965 addr = gen_reg_rtx (DImode);
3966 extl = gen_reg_rtx (DImode);
3967 exth = gen_reg_rtx (DImode);
3969 mema = XEXP (mem, 0);
3970 if (GET_CODE (mema) == LO_SUM)
3971 mema = force_reg (Pmode, mema);
3973 /* AND addresses cannot be in any alias set, since they may implicitly
3974 alias surrounding code. Ideally we'd have some alias set that
3975 covered all types except those with alignment 8 or higher. */
3977 tmp = change_address (mem, DImode,
3978 gen_rtx_AND (DImode,
3979 plus_constant (mema, ofs),
3980 GEN_INT (-8)));
3981 set_mem_alias_set (tmp, 0);
3982 emit_move_insn (meml, tmp);
3984 tmp = change_address (mem, DImode,
3985 gen_rtx_AND (DImode,
3986 plus_constant (mema, ofs + size - 1),
3987 GEN_INT (-8)));
3988 set_mem_alias_set (tmp, 0);
3989 emit_move_insn (memh, tmp);
3991 if (WORDS_BIG_ENDIAN && sign && (size == 2 || size == 4))
3993 emit_move_insn (addr, plus_constant (mema, -1));
3995 emit_insn (gen_extqh_be (extl, meml, addr));
3996 emit_insn (gen_extxl_be (exth, memh, GEN_INT (64), addr));
3998 addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
3999 addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (64 - size*8),
4000 addr, 1, OPTAB_WIDEN);
4002 else if (sign && size == 2)
4004 emit_move_insn (addr, plus_constant (mema, ofs+2));
4006 emit_insn (gen_extxl_le (extl, meml, GEN_INT (64), addr));
4007 emit_insn (gen_extqh_le (exth, memh, addr));
4009 /* We must use tgt here for the target. Alpha-vms port fails if we use
4010 addr for the target, because addr is marked as a pointer and combine
4011 knows that pointers are always sign-extended 32 bit values. */
4012 addr = expand_binop (DImode, ior_optab, extl, exth, tgt, 1, OPTAB_WIDEN);
4013 addr = expand_binop (DImode, ashr_optab, addr, GEN_INT (48),
4014 addr, 1, OPTAB_WIDEN);
4016 else
4018 if (WORDS_BIG_ENDIAN)
4020 emit_move_insn (addr, plus_constant (mema, ofs+size-1));
4021 switch ((int) size)
4023 case 2:
4024 emit_insn (gen_extwh_be (extl, meml, addr));
4025 mode = HImode;
4026 break;
4028 case 4:
4029 emit_insn (gen_extlh_be (extl, meml, addr));
4030 mode = SImode;
4031 break;
4033 case 8:
4034 emit_insn (gen_extqh_be (extl, meml, addr));
4035 mode = DImode;
4036 break;
4038 default:
4039 abort ();
4041 emit_insn (gen_extxl_be (exth, memh, GEN_INT (size*8), addr));
4043 else
4045 emit_move_insn (addr, plus_constant (mema, ofs));
4046 emit_insn (gen_extxl_le (extl, meml, GEN_INT (size*8), addr));
4047 switch ((int) size)
4049 case 2:
4050 emit_insn (gen_extwh_le (exth, memh, addr));
4051 mode = HImode;
4052 break;
4054 case 4:
4055 emit_insn (gen_extlh_le (exth, memh, addr));
4056 mode = SImode;
4057 break;
4059 case 8:
4060 emit_insn (gen_extqh_le (exth, memh, addr));
4061 mode = DImode;
4062 break;
4064 default:
4065 abort();
4069 addr = expand_binop (mode, ior_optab, gen_lowpart (mode, extl),
4070 gen_lowpart (mode, exth), gen_lowpart (mode, tgt),
4071 sign, OPTAB_WIDEN);
4074 if (addr != tgt)
4075 emit_move_insn (tgt, gen_lowpart(GET_MODE (tgt), addr));
4078 /* Similarly, use ins and msk instructions to perform unaligned stores. */
4080 void
4081 alpha_expand_unaligned_store (rtx dst, rtx src,
4082 HOST_WIDE_INT size, HOST_WIDE_INT ofs)
4084 rtx dstl, dsth, addr, insl, insh, meml, memh, dsta;
4086 dstl = gen_reg_rtx (DImode);
4087 dsth = gen_reg_rtx (DImode);
4088 insl = gen_reg_rtx (DImode);
4089 insh = gen_reg_rtx (DImode);
4091 dsta = XEXP (dst, 0);
4092 if (GET_CODE (dsta) == LO_SUM)
4093 dsta = force_reg (Pmode, dsta);
4095 /* AND addresses cannot be in any alias set, since they may implicitly
4096 alias surrounding code. Ideally we'd have some alias set that
4097 covered all types except those with alignment 8 or higher. */
4099 meml = change_address (dst, DImode,
4100 gen_rtx_AND (DImode,
4101 plus_constant (dsta, ofs),
4102 GEN_INT (-8)));
4103 set_mem_alias_set (meml, 0);
4105 memh = change_address (dst, DImode,
4106 gen_rtx_AND (DImode,
4107 plus_constant (dsta, ofs + size - 1),
4108 GEN_INT (-8)));
4109 set_mem_alias_set (memh, 0);
4111 emit_move_insn (dsth, memh);
4112 emit_move_insn (dstl, meml);
4113 if (WORDS_BIG_ENDIAN)
4115 addr = copy_addr_to_reg (plus_constant (dsta, ofs+size-1));
4117 if (src != const0_rtx)
4119 switch ((int) size)
4121 case 2:
4122 emit_insn (gen_inswl_be (insh, gen_lowpart (HImode,src), addr));
4123 break;
4124 case 4:
4125 emit_insn (gen_insll_be (insh, gen_lowpart (SImode,src), addr));
4126 break;
4127 case 8:
4128 emit_insn (gen_insql_be (insh, gen_lowpart (DImode,src), addr));
4129 break;
4131 emit_insn (gen_insxh (insl, gen_lowpart (DImode, src),
4132 GEN_INT (size*8), addr));
4135 switch ((int) size)
4137 case 2:
4138 emit_insn (gen_mskxl_be (dsth, dsth, GEN_INT (0xffff), addr));
4139 break;
4140 case 4:
4142 rtx msk = immed_double_const (0xffffffff, 0, DImode);
4143 emit_insn (gen_mskxl_be (dsth, dsth, msk, addr));
4144 break;
4146 case 8:
4147 emit_insn (gen_mskxl_be (dsth, dsth, constm1_rtx, addr));
4148 break;
4151 emit_insn (gen_mskxh (dstl, dstl, GEN_INT (size*8), addr));
4153 else
4155 addr = copy_addr_to_reg (plus_constant (dsta, ofs));
4157 if (src != const0_rtx)
4159 emit_insn (gen_insxh (insh, gen_lowpart (DImode, src),
4160 GEN_INT (size*8), addr));
4162 switch ((int) size)
4164 case 2:
4165 emit_insn (gen_inswl_le (insl, gen_lowpart (HImode, src), addr));
4166 break;
4167 case 4:
4168 emit_insn (gen_insll_le (insl, gen_lowpart (SImode, src), addr));
4169 break;
4170 case 8:
4171 emit_insn (gen_insql_le (insl, src, addr));
4172 break;
4176 emit_insn (gen_mskxh (dsth, dsth, GEN_INT (size*8), addr));
4178 switch ((int) size)
4180 case 2:
4181 emit_insn (gen_mskxl_le (dstl, dstl, GEN_INT (0xffff), addr));
4182 break;
4183 case 4:
4185 rtx msk = immed_double_const (0xffffffff, 0, DImode);
4186 emit_insn (gen_mskxl_le (dstl, dstl, msk, addr));
4187 break;
4189 case 8:
4190 emit_insn (gen_mskxl_le (dstl, dstl, constm1_rtx, addr));
4191 break;
4195 if (src != const0_rtx)
4197 dsth = expand_binop (DImode, ior_optab, insh, dsth, dsth, 0, OPTAB_WIDEN);
4198 dstl = expand_binop (DImode, ior_optab, insl, dstl, dstl, 0, OPTAB_WIDEN);
4201 if (WORDS_BIG_ENDIAN)
4203 emit_move_insn (meml, dstl);
4204 emit_move_insn (memh, dsth);
4206 else
4208 /* Must store high before low for degenerate case of aligned. */
4209 emit_move_insn (memh, dsth);
4210 emit_move_insn (meml, dstl);
4214 /* The block move code tries to maximize speed by separating loads and
4215 stores at the expense of register pressure: we load all of the data
4216 before we store it back out. There are two secondary effects worth
4217 mentioning, that this speeds copying to/from aligned and unaligned
4218 buffers, and that it makes the code significantly easier to write. */
4220 #define MAX_MOVE_WORDS 8
4222 /* Load an integral number of consecutive unaligned quadwords. */
4224 static void
4225 alpha_expand_unaligned_load_words (rtx *out_regs, rtx smem,
4226 HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4228 rtx const im8 = GEN_INT (-8);
4229 rtx const i64 = GEN_INT (64);
4230 rtx ext_tmps[MAX_MOVE_WORDS], data_regs[MAX_MOVE_WORDS+1];
4231 rtx sreg, areg, tmp, smema;
4232 HOST_WIDE_INT i;
4234 smema = XEXP (smem, 0);
4235 if (GET_CODE (smema) == LO_SUM)
4236 smema = force_reg (Pmode, smema);
4238 /* Generate all the tmp registers we need. */
4239 for (i = 0; i < words; ++i)
4241 data_regs[i] = out_regs[i];
4242 ext_tmps[i] = gen_reg_rtx (DImode);
4244 data_regs[words] = gen_reg_rtx (DImode);
4246 if (ofs != 0)
4247 smem = adjust_address (smem, GET_MODE (smem), ofs);
4249 /* Load up all of the source data. */
4250 for (i = 0; i < words; ++i)
4252 tmp = change_address (smem, DImode,
4253 gen_rtx_AND (DImode,
4254 plus_constant (smema, 8*i),
4255 im8));
4256 set_mem_alias_set (tmp, 0);
4257 emit_move_insn (data_regs[i], tmp);
4260 tmp = change_address (smem, DImode,
4261 gen_rtx_AND (DImode,
4262 plus_constant (smema, 8*words - 1),
4263 im8));
4264 set_mem_alias_set (tmp, 0);
4265 emit_move_insn (data_regs[words], tmp);
4267 /* Extract the half-word fragments. Unfortunately DEC decided to make
4268 extxh with offset zero a noop instead of zeroing the register, so
4269 we must take care of that edge condition ourselves with cmov. */
4271 sreg = copy_addr_to_reg (smema);
4272 areg = expand_binop (DImode, and_optab, sreg, GEN_INT (7), NULL,
4273 1, OPTAB_WIDEN);
4274 if (WORDS_BIG_ENDIAN)
4275 emit_move_insn (sreg, plus_constant (sreg, 7));
4276 for (i = 0; i < words; ++i)
4278 if (WORDS_BIG_ENDIAN)
4280 emit_insn (gen_extqh_be (data_regs[i], data_regs[i], sreg));
4281 emit_insn (gen_extxl_be (ext_tmps[i], data_regs[i+1], i64, sreg));
4283 else
4285 emit_insn (gen_extxl_le (data_regs[i], data_regs[i], i64, sreg));
4286 emit_insn (gen_extqh_le (ext_tmps[i], data_regs[i+1], sreg));
4288 emit_insn (gen_rtx_SET (VOIDmode, ext_tmps[i],
4289 gen_rtx_IF_THEN_ELSE (DImode,
4290 gen_rtx_EQ (DImode, areg,
4291 const0_rtx),
4292 const0_rtx, ext_tmps[i])));
4295 /* Merge the half-words into whole words. */
4296 for (i = 0; i < words; ++i)
4298 out_regs[i] = expand_binop (DImode, ior_optab, data_regs[i],
4299 ext_tmps[i], data_regs[i], 1, OPTAB_WIDEN);
4303 /* Store an integral number of consecutive unaligned quadwords. DATA_REGS
4304 may be NULL to store zeros. */
4306 static void
4307 alpha_expand_unaligned_store_words (rtx *data_regs, rtx dmem,
4308 HOST_WIDE_INT words, HOST_WIDE_INT ofs)
4310 rtx const im8 = GEN_INT (-8);
4311 rtx const i64 = GEN_INT (64);
4312 rtx ins_tmps[MAX_MOVE_WORDS];
4313 rtx st_tmp_1, st_tmp_2, dreg;
4314 rtx st_addr_1, st_addr_2, dmema;
4315 HOST_WIDE_INT i;
4317 dmema = XEXP (dmem, 0);
4318 if (GET_CODE (dmema) == LO_SUM)
4319 dmema = force_reg (Pmode, dmema);
4321 /* Generate all the tmp registers we need. */
4322 if (data_regs != NULL)
4323 for (i = 0; i < words; ++i)
4324 ins_tmps[i] = gen_reg_rtx(DImode);
4325 st_tmp_1 = gen_reg_rtx(DImode);
4326 st_tmp_2 = gen_reg_rtx(DImode);
4328 if (ofs != 0)
4329 dmem = adjust_address (dmem, GET_MODE (dmem), ofs);
4331 st_addr_2 = change_address (dmem, DImode,
4332 gen_rtx_AND (DImode,
4333 plus_constant (dmema, words*8 - 1),
4334 im8));
4335 set_mem_alias_set (st_addr_2, 0);
4337 st_addr_1 = change_address (dmem, DImode,
4338 gen_rtx_AND (DImode, dmema, im8));
4339 set_mem_alias_set (st_addr_1, 0);
4341 /* Load up the destination end bits. */
4342 emit_move_insn (st_tmp_2, st_addr_2);
4343 emit_move_insn (st_tmp_1, st_addr_1);
4345 /* Shift the input data into place. */
4346 dreg = copy_addr_to_reg (dmema);
4347 if (WORDS_BIG_ENDIAN)
4348 emit_move_insn (dreg, plus_constant (dreg, 7));
4349 if (data_regs != NULL)
4351 for (i = words-1; i >= 0; --i)
4353 if (WORDS_BIG_ENDIAN)
4355 emit_insn (gen_insql_be (ins_tmps[i], data_regs[i], dreg));
4356 emit_insn (gen_insxh (data_regs[i], data_regs[i], i64, dreg));
4358 else
4360 emit_insn (gen_insxh (ins_tmps[i], data_regs[i], i64, dreg));
4361 emit_insn (gen_insql_le (data_regs[i], data_regs[i], dreg));
4364 for (i = words-1; i > 0; --i)
4366 ins_tmps[i-1] = expand_binop (DImode, ior_optab, data_regs[i],
4367 ins_tmps[i-1], ins_tmps[i-1], 1,
4368 OPTAB_WIDEN);
4372 /* Split and merge the ends with the destination data. */
4373 if (WORDS_BIG_ENDIAN)
4375 emit_insn (gen_mskxl_be (st_tmp_2, st_tmp_2, constm1_rtx, dreg));
4376 emit_insn (gen_mskxh (st_tmp_1, st_tmp_1, i64, dreg));
4378 else
4380 emit_insn (gen_mskxh (st_tmp_2, st_tmp_2, i64, dreg));
4381 emit_insn (gen_mskxl_le (st_tmp_1, st_tmp_1, constm1_rtx, dreg));
4384 if (data_regs != NULL)
4386 st_tmp_2 = expand_binop (DImode, ior_optab, st_tmp_2, ins_tmps[words-1],
4387 st_tmp_2, 1, OPTAB_WIDEN);
4388 st_tmp_1 = expand_binop (DImode, ior_optab, st_tmp_1, data_regs[0],
4389 st_tmp_1, 1, OPTAB_WIDEN);
4392 /* Store it all. */
4393 if (WORDS_BIG_ENDIAN)
4394 emit_move_insn (st_addr_1, st_tmp_1);
4395 else
4396 emit_move_insn (st_addr_2, st_tmp_2);
4397 for (i = words-1; i > 0; --i)
4399 rtx tmp = change_address (dmem, DImode,
4400 gen_rtx_AND (DImode,
4401 plus_constant(dmema,
4402 WORDS_BIG_ENDIAN ? i*8-1 : i*8),
4403 im8));
4404 set_mem_alias_set (tmp, 0);
4405 emit_move_insn (tmp, data_regs ? ins_tmps[i-1] : const0_rtx);
4407 if (WORDS_BIG_ENDIAN)
4408 emit_move_insn (st_addr_2, st_tmp_2);
4409 else
4410 emit_move_insn (st_addr_1, st_tmp_1);
4414 /* Expand string/block move operations.
4416 operands[0] is the pointer to the destination.
4417 operands[1] is the pointer to the source.
4418 operands[2] is the number of bytes to move.
4419 operands[3] is the alignment. */
4422 alpha_expand_block_move (rtx operands[])
4424 rtx bytes_rtx = operands[2];
4425 rtx align_rtx = operands[3];
4426 HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4427 HOST_WIDE_INT bytes = orig_bytes;
4428 HOST_WIDE_INT src_align = INTVAL (align_rtx) * BITS_PER_UNIT;
4429 HOST_WIDE_INT dst_align = src_align;
4430 rtx orig_src = operands[1];
4431 rtx orig_dst = operands[0];
4432 rtx data_regs[2 * MAX_MOVE_WORDS + 16];
4433 rtx tmp;
4434 unsigned int i, words, ofs, nregs = 0;
4436 if (orig_bytes <= 0)
4437 return 1;
4438 else if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4439 return 0;
4441 /* Look for additional alignment information from recorded register info. */
4443 tmp = XEXP (orig_src, 0);
4444 if (GET_CODE (tmp) == REG)
4445 src_align = MAX (src_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4446 else if (GET_CODE (tmp) == PLUS
4447 && GET_CODE (XEXP (tmp, 0)) == REG
4448 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4450 unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4451 unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4453 if (a > src_align)
4455 if (a >= 64 && c % 8 == 0)
4456 src_align = 64;
4457 else if (a >= 32 && c % 4 == 0)
4458 src_align = 32;
4459 else if (a >= 16 && c % 2 == 0)
4460 src_align = 16;
4464 tmp = XEXP (orig_dst, 0);
4465 if (GET_CODE (tmp) == REG)
4466 dst_align = MAX (dst_align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4467 else if (GET_CODE (tmp) == PLUS
4468 && GET_CODE (XEXP (tmp, 0)) == REG
4469 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4471 unsigned HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4472 unsigned int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4474 if (a > dst_align)
4476 if (a >= 64 && c % 8 == 0)
4477 dst_align = 64;
4478 else if (a >= 32 && c % 4 == 0)
4479 dst_align = 32;
4480 else if (a >= 16 && c % 2 == 0)
4481 dst_align = 16;
4485 ofs = 0;
4486 if (src_align >= 64 && bytes >= 8)
4488 words = bytes / 8;
4490 for (i = 0; i < words; ++i)
4491 data_regs[nregs + i] = gen_reg_rtx (DImode);
4493 for (i = 0; i < words; ++i)
4494 emit_move_insn (data_regs[nregs + i],
4495 adjust_address (orig_src, DImode, ofs + i * 8));
4497 nregs += words;
4498 bytes -= words * 8;
4499 ofs += words * 8;
4502 if (src_align >= 32 && bytes >= 4)
4504 words = bytes / 4;
4506 for (i = 0; i < words; ++i)
4507 data_regs[nregs + i] = gen_reg_rtx (SImode);
4509 for (i = 0; i < words; ++i)
4510 emit_move_insn (data_regs[nregs + i],
4511 adjust_address (orig_src, SImode, ofs + i * 4));
4513 nregs += words;
4514 bytes -= words * 4;
4515 ofs += words * 4;
4518 if (bytes >= 8)
4520 words = bytes / 8;
4522 for (i = 0; i < words+1; ++i)
4523 data_regs[nregs + i] = gen_reg_rtx (DImode);
4525 alpha_expand_unaligned_load_words (data_regs + nregs, orig_src,
4526 words, ofs);
4528 nregs += words;
4529 bytes -= words * 8;
4530 ofs += words * 8;
4533 if (! TARGET_BWX && bytes >= 4)
4535 data_regs[nregs++] = tmp = gen_reg_rtx (SImode);
4536 alpha_expand_unaligned_load (tmp, orig_src, 4, ofs, 0);
4537 bytes -= 4;
4538 ofs += 4;
4541 if (bytes >= 2)
4543 if (src_align >= 16)
4545 do {
4546 data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4547 emit_move_insn (tmp, adjust_address (orig_src, HImode, ofs));
4548 bytes -= 2;
4549 ofs += 2;
4550 } while (bytes >= 2);
4552 else if (! TARGET_BWX)
4554 data_regs[nregs++] = tmp = gen_reg_rtx (HImode);
4555 alpha_expand_unaligned_load (tmp, orig_src, 2, ofs, 0);
4556 bytes -= 2;
4557 ofs += 2;
4561 while (bytes > 0)
4563 data_regs[nregs++] = tmp = gen_reg_rtx (QImode);
4564 emit_move_insn (tmp, adjust_address (orig_src, QImode, ofs));
4565 bytes -= 1;
4566 ofs += 1;
4569 if (nregs > ARRAY_SIZE (data_regs))
4570 abort ();
4572 /* Now save it back out again. */
4574 i = 0, ofs = 0;
4576 /* Write out the data in whatever chunks reading the source allowed. */
4577 if (dst_align >= 64)
4579 while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4581 emit_move_insn (adjust_address (orig_dst, DImode, ofs),
4582 data_regs[i]);
4583 ofs += 8;
4584 i++;
4588 if (dst_align >= 32)
4590 /* If the source has remaining DImode regs, write them out in
4591 two pieces. */
4592 while (i < nregs && GET_MODE (data_regs[i]) == DImode)
4594 tmp = expand_binop (DImode, lshr_optab, data_regs[i], GEN_INT (32),
4595 NULL_RTX, 1, OPTAB_WIDEN);
4597 emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4598 gen_lowpart (SImode, data_regs[i]));
4599 emit_move_insn (adjust_address (orig_dst, SImode, ofs + 4),
4600 gen_lowpart (SImode, tmp));
4601 ofs += 8;
4602 i++;
4605 while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4607 emit_move_insn (adjust_address (orig_dst, SImode, ofs),
4608 data_regs[i]);
4609 ofs += 4;
4610 i++;
4614 if (i < nregs && GET_MODE (data_regs[i]) == DImode)
4616 /* Write out a remaining block of words using unaligned methods. */
4618 for (words = 1; i + words < nregs; words++)
4619 if (GET_MODE (data_regs[i + words]) != DImode)
4620 break;
4622 if (words == 1)
4623 alpha_expand_unaligned_store (orig_dst, data_regs[i], 8, ofs);
4624 else
4625 alpha_expand_unaligned_store_words (data_regs + i, orig_dst,
4626 words, ofs);
4628 i += words;
4629 ofs += words * 8;
4632 /* Due to the above, this won't be aligned. */
4633 /* ??? If we have more than one of these, consider constructing full
4634 words in registers and using alpha_expand_unaligned_store_words. */
4635 while (i < nregs && GET_MODE (data_regs[i]) == SImode)
4637 alpha_expand_unaligned_store (orig_dst, data_regs[i], 4, ofs);
4638 ofs += 4;
4639 i++;
4642 if (dst_align >= 16)
4643 while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4645 emit_move_insn (adjust_address (orig_dst, HImode, ofs), data_regs[i]);
4646 i++;
4647 ofs += 2;
4649 else
4650 while (i < nregs && GET_MODE (data_regs[i]) == HImode)
4652 alpha_expand_unaligned_store (orig_dst, data_regs[i], 2, ofs);
4653 i++;
4654 ofs += 2;
4657 while (i < nregs && GET_MODE (data_regs[i]) == QImode)
4659 emit_move_insn (adjust_address (orig_dst, QImode, ofs), data_regs[i]);
4660 i++;
4661 ofs += 1;
4664 if (i != nregs)
4665 abort ();
4667 return 1;
4671 alpha_expand_block_clear (rtx operands[])
4673 rtx bytes_rtx = operands[1];
4674 rtx align_rtx = operands[2];
4675 HOST_WIDE_INT orig_bytes = INTVAL (bytes_rtx);
4676 HOST_WIDE_INT bytes = orig_bytes;
4677 HOST_WIDE_INT align = INTVAL (align_rtx) * BITS_PER_UNIT;
4678 HOST_WIDE_INT alignofs = 0;
4679 rtx orig_dst = operands[0];
4680 rtx tmp;
4681 int i, words, ofs = 0;
4683 if (orig_bytes <= 0)
4684 return 1;
4685 if (orig_bytes > MAX_MOVE_WORDS * UNITS_PER_WORD)
4686 return 0;
4688 /* Look for stricter alignment. */
4689 tmp = XEXP (orig_dst, 0);
4690 if (GET_CODE (tmp) == REG)
4691 align = MAX (align, REGNO_POINTER_ALIGN (REGNO (tmp)));
4692 else if (GET_CODE (tmp) == PLUS
4693 && GET_CODE (XEXP (tmp, 0)) == REG
4694 && GET_CODE (XEXP (tmp, 1)) == CONST_INT)
4696 HOST_WIDE_INT c = INTVAL (XEXP (tmp, 1));
4697 int a = REGNO_POINTER_ALIGN (REGNO (XEXP (tmp, 0)));
4699 if (a > align)
4701 if (a >= 64)
4702 align = a, alignofs = 8 - c % 8;
4703 else if (a >= 32)
4704 align = a, alignofs = 4 - c % 4;
4705 else if (a >= 16)
4706 align = a, alignofs = 2 - c % 2;
4710 /* Handle an unaligned prefix first. */
4712 if (alignofs > 0)
4714 #if HOST_BITS_PER_WIDE_INT >= 64
4715 /* Given that alignofs is bounded by align, the only time BWX could
4716 generate three stores is for a 7 byte fill. Prefer two individual
4717 stores over a load/mask/store sequence. */
4718 if ((!TARGET_BWX || alignofs == 7)
4719 && align >= 32
4720 && !(alignofs == 4 && bytes >= 4))
4722 enum machine_mode mode = (align >= 64 ? DImode : SImode);
4723 int inv_alignofs = (align >= 64 ? 8 : 4) - alignofs;
4724 rtx mem, tmp;
4725 HOST_WIDE_INT mask;
4727 mem = adjust_address (orig_dst, mode, ofs - inv_alignofs);
4728 set_mem_alias_set (mem, 0);
4730 mask = ~(~(HOST_WIDE_INT)0 << (inv_alignofs * 8));
4731 if (bytes < alignofs)
4733 mask |= ~(HOST_WIDE_INT)0 << ((inv_alignofs + bytes) * 8);
4734 ofs += bytes;
4735 bytes = 0;
4737 else
4739 bytes -= alignofs;
4740 ofs += alignofs;
4742 alignofs = 0;
4744 tmp = expand_binop (mode, and_optab, mem, GEN_INT (mask),
4745 NULL_RTX, 1, OPTAB_WIDEN);
4747 emit_move_insn (mem, tmp);
4749 #endif
4751 if (TARGET_BWX && (alignofs & 1) && bytes >= 1)
4753 emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
4754 bytes -= 1;
4755 ofs += 1;
4756 alignofs -= 1;
4758 if (TARGET_BWX && align >= 16 && (alignofs & 3) == 2 && bytes >= 2)
4760 emit_move_insn (adjust_address (orig_dst, HImode, ofs), const0_rtx);
4761 bytes -= 2;
4762 ofs += 2;
4763 alignofs -= 2;
4765 if (alignofs == 4 && bytes >= 4)
4767 emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4768 bytes -= 4;
4769 ofs += 4;
4770 alignofs = 0;
4773 /* If we've not used the extra lead alignment information by now,
4774 we won't be able to. Downgrade align to match what's left over. */
4775 if (alignofs > 0)
4777 alignofs = alignofs & -alignofs;
4778 align = MIN (align, alignofs * BITS_PER_UNIT);
4782 /* Handle a block of contiguous long-words. */
4784 if (align >= 64 && bytes >= 8)
4786 words = bytes / 8;
4788 for (i = 0; i < words; ++i)
4789 emit_move_insn (adjust_address (orig_dst, DImode, ofs + i * 8),
4790 const0_rtx);
4792 bytes -= words * 8;
4793 ofs += words * 8;
4796 /* If the block is large and appropriately aligned, emit a single
4797 store followed by a sequence of stq_u insns. */
4799 if (align >= 32 && bytes > 16)
4801 rtx orig_dsta;
4803 emit_move_insn (adjust_address (orig_dst, SImode, ofs), const0_rtx);
4804 bytes -= 4;
4805 ofs += 4;
4807 orig_dsta = XEXP (orig_dst, 0);
4808 if (GET_CODE (orig_dsta) == LO_SUM)
4809 orig_dsta = force_reg (Pmode, orig_dsta);
4811 words = bytes / 8;
4812 for (i = 0; i < words; ++i)
4814 rtx mem
4815 = change_address (orig_dst, DImode,
4816 gen_rtx_AND (DImode,
4817 plus_constant (orig_dsta, ofs + i*8),
4818 GEN_INT (-8)));
4819 set_mem_alias_set (mem, 0);
4820 emit_move_insn (mem, const0_rtx);
4823 /* Depending on the alignment, the first stq_u may have overlapped
4824 with the initial stl, which means that the last stq_u didn't
4825 write as much as it would appear. Leave those questionable bytes
4826 unaccounted for. */
4827 bytes -= words * 8 - 4;
4828 ofs += words * 8 - 4;
4831 /* Handle a smaller block of aligned words. */
4833 if ((align >= 64 && bytes == 4)
4834 || (align == 32 && bytes >= 4))
4836 words = bytes / 4;
4838 for (i = 0; i < words; ++i)
4839 emit_move_insn (adjust_address (orig_dst, SImode, ofs + i * 4),
4840 const0_rtx);
4842 bytes -= words * 4;
4843 ofs += words * 4;
4846 /* An unaligned block uses stq_u stores for as many as possible. */
4848 if (bytes >= 8)
4850 words = bytes / 8;
4852 alpha_expand_unaligned_store_words (NULL, orig_dst, words, ofs);
4854 bytes -= words * 8;
4855 ofs += words * 8;
4858 /* Next clean up any trailing pieces. */
4860 #if HOST_BITS_PER_WIDE_INT >= 64
4861 /* Count the number of bits in BYTES for which aligned stores could
4862 be emitted. */
4863 words = 0;
4864 for (i = (TARGET_BWX ? 1 : 4); i * BITS_PER_UNIT <= align ; i <<= 1)
4865 if (bytes & i)
4866 words += 1;
4868 /* If we have appropriate alignment (and it wouldn't take too many
4869 instructions otherwise), mask out the bytes we need. */
4870 if (TARGET_BWX ? words > 2 : bytes > 0)
4872 if (align >= 64)
4874 rtx mem, tmp;
4875 HOST_WIDE_INT mask;
4877 mem = adjust_address (orig_dst, DImode, ofs);
4878 set_mem_alias_set (mem, 0);
4880 mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
4882 tmp = expand_binop (DImode, and_optab, mem, GEN_INT (mask),
4883 NULL_RTX, 1, OPTAB_WIDEN);
4885 emit_move_insn (mem, tmp);
4886 return 1;
4888 else if (align >= 32 && bytes < 4)
4890 rtx mem, tmp;
4891 HOST_WIDE_INT mask;
4893 mem = adjust_address (orig_dst, SImode, ofs);
4894 set_mem_alias_set (mem, 0);
4896 mask = ~(HOST_WIDE_INT)0 << (bytes * 8);
4898 tmp = expand_binop (SImode, and_optab, mem, GEN_INT (mask),
4899 NULL_RTX, 1, OPTAB_WIDEN);
4901 emit_move_insn (mem, tmp);
4902 return 1;
4905 #endif
4907 if (!TARGET_BWX && bytes >= 4)
4909 alpha_expand_unaligned_store (orig_dst, const0_rtx, 4, ofs);
4910 bytes -= 4;
4911 ofs += 4;
4914 if (bytes >= 2)
4916 if (align >= 16)
4918 do {
4919 emit_move_insn (adjust_address (orig_dst, HImode, ofs),
4920 const0_rtx);
4921 bytes -= 2;
4922 ofs += 2;
4923 } while (bytes >= 2);
4925 else if (! TARGET_BWX)
4927 alpha_expand_unaligned_store (orig_dst, const0_rtx, 2, ofs);
4928 bytes -= 2;
4929 ofs += 2;
4933 while (bytes > 0)
4935 emit_move_insn (adjust_address (orig_dst, QImode, ofs), const0_rtx);
4936 bytes -= 1;
4937 ofs += 1;
4940 return 1;
4943 /* Returns a mask so that zap(x, value) == x & mask. */
4946 alpha_expand_zap_mask (HOST_WIDE_INT value)
4948 rtx result;
4949 int i;
4951 if (HOST_BITS_PER_WIDE_INT >= 64)
4953 HOST_WIDE_INT mask = 0;
4955 for (i = 7; i >= 0; --i)
4957 mask <<= 8;
4958 if (!((value >> i) & 1))
4959 mask |= 0xff;
4962 result = gen_int_mode (mask, DImode);
4964 else if (HOST_BITS_PER_WIDE_INT == 32)
4966 HOST_WIDE_INT mask_lo = 0, mask_hi = 0;
4968 for (i = 7; i >= 4; --i)
4970 mask_hi <<= 8;
4971 if (!((value >> i) & 1))
4972 mask_hi |= 0xff;
4975 for (i = 3; i >= 0; --i)
4977 mask_lo <<= 8;
4978 if (!((value >> i) & 1))
4979 mask_lo |= 0xff;
4982 result = immed_double_const (mask_lo, mask_hi, DImode);
4984 else
4985 abort ();
4987 return result;
4990 void
4991 alpha_expand_builtin_vector_binop (rtx (*gen) (rtx, rtx, rtx),
4992 enum machine_mode mode,
4993 rtx op0, rtx op1, rtx op2)
4995 op0 = gen_lowpart (mode, op0);
4997 if (op1 == const0_rtx)
4998 op1 = CONST0_RTX (mode);
4999 else
5000 op1 = gen_lowpart (mode, op1);
5002 if (op2 == const0_rtx)
5003 op2 = CONST0_RTX (mode);
5004 else
5005 op2 = gen_lowpart (mode, op2);
5007 emit_insn ((*gen) (op0, op1, op2));
5010 /* Adjust the cost of a scheduling dependency. Return the new cost of
5011 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
5013 static int
5014 alpha_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
5016 enum attr_type insn_type, dep_insn_type;
5018 /* If the dependence is an anti-dependence, there is no cost. For an
5019 output dependence, there is sometimes a cost, but it doesn't seem
5020 worth handling those few cases. */
5021 if (REG_NOTE_KIND (link) != 0)
5022 return cost;
5024 /* If we can't recognize the insns, we can't really do anything. */
5025 if (recog_memoized (insn) < 0 || recog_memoized (dep_insn) < 0)
5026 return cost;
5028 insn_type = get_attr_type (insn);
5029 dep_insn_type = get_attr_type (dep_insn);
5031 /* Bring in the user-defined memory latency. */
5032 if (dep_insn_type == TYPE_ILD
5033 || dep_insn_type == TYPE_FLD
5034 || dep_insn_type == TYPE_LDSYM)
5035 cost += alpha_memory_latency-1;
5037 /* Everything else handled in DFA bypasses now. */
5039 return cost;
5042 /* The number of instructions that can be issued per cycle. */
5044 static int
5045 alpha_issue_rate (void)
5047 return (alpha_cpu == PROCESSOR_EV4 ? 2 : 4);
5050 /* How many alternative schedules to try. This should be as wide as the
5051 scheduling freedom in the DFA, but no wider. Making this value too
5052 large results extra work for the scheduler.
5054 For EV4, loads can be issued to either IB0 or IB1, thus we have 2
5055 alternative schedules. For EV5, we can choose between E0/E1 and
5056 FA/FM. For EV6, an arithmetic insn can be issued to U0/U1/L0/L1. */
5058 static int
5059 alpha_multipass_dfa_lookahead (void)
5061 return (alpha_cpu == PROCESSOR_EV6 ? 4 : 2);
5064 /* Machine-specific function data. */
5066 struct machine_function GTY(())
5068 /* For unicosmk. */
5069 /* List of call information words for calls from this function. */
5070 struct rtx_def *first_ciw;
5071 struct rtx_def *last_ciw;
5072 int ciw_count;
5074 /* List of deferred case vectors. */
5075 struct rtx_def *addr_list;
5077 /* For OSF. */
5078 const char *some_ld_name;
5080 /* For TARGET_LD_BUGGY_LDGP. */
5081 struct rtx_def *gp_save_rtx;
5084 /* How to allocate a 'struct machine_function'. */
5086 static struct machine_function *
5087 alpha_init_machine_status (void)
5089 return ((struct machine_function *)
5090 ggc_alloc_cleared (sizeof (struct machine_function)));
5093 /* Functions to save and restore alpha_return_addr_rtx. */
5095 /* Start the ball rolling with RETURN_ADDR_RTX. */
5098 alpha_return_addr (int count, rtx frame ATTRIBUTE_UNUSED)
5100 if (count != 0)
5101 return const0_rtx;
5103 return get_hard_reg_initial_val (Pmode, REG_RA);
5106 /* Return or create a memory slot containing the gp value for the current
5107 function. Needed only if TARGET_LD_BUGGY_LDGP. */
5110 alpha_gp_save_rtx (void)
5112 rtx seq, m = cfun->machine->gp_save_rtx;
5114 if (m == NULL)
5116 start_sequence ();
5118 m = assign_stack_local (DImode, UNITS_PER_WORD, BITS_PER_WORD);
5119 m = validize_mem (m);
5120 emit_move_insn (m, pic_offset_table_rtx);
5122 seq = get_insns ();
5123 end_sequence ();
5124 emit_insn_after (seq, entry_of_function ());
5126 cfun->machine->gp_save_rtx = m;
5129 return m;
5132 static int
5133 alpha_ra_ever_killed (void)
5135 rtx top;
5137 if (!has_hard_reg_initial_val (Pmode, REG_RA))
5138 return regs_ever_live[REG_RA];
5140 push_topmost_sequence ();
5141 top = get_insns ();
5142 pop_topmost_sequence ();
5144 return reg_set_between_p (gen_rtx_REG (Pmode, REG_RA), top, NULL_RTX);
5148 /* Return the trap mode suffix applicable to the current
5149 instruction, or NULL. */
5151 static const char *
5152 get_trap_mode_suffix (void)
5154 enum attr_trap_suffix s = get_attr_trap_suffix (current_output_insn);
5156 switch (s)
5158 case TRAP_SUFFIX_NONE:
5159 return NULL;
5161 case TRAP_SUFFIX_SU:
5162 if (alpha_fptm >= ALPHA_FPTM_SU)
5163 return "su";
5164 return NULL;
5166 case TRAP_SUFFIX_SUI:
5167 if (alpha_fptm >= ALPHA_FPTM_SUI)
5168 return "sui";
5169 return NULL;
5171 case TRAP_SUFFIX_V_SV:
5172 switch (alpha_fptm)
5174 case ALPHA_FPTM_N:
5175 return NULL;
5176 case ALPHA_FPTM_U:
5177 return "v";
5178 case ALPHA_FPTM_SU:
5179 case ALPHA_FPTM_SUI:
5180 return "sv";
5182 break;
5184 case TRAP_SUFFIX_V_SV_SVI:
5185 switch (alpha_fptm)
5187 case ALPHA_FPTM_N:
5188 return NULL;
5189 case ALPHA_FPTM_U:
5190 return "v";
5191 case ALPHA_FPTM_SU:
5192 return "sv";
5193 case ALPHA_FPTM_SUI:
5194 return "svi";
5196 break;
5198 case TRAP_SUFFIX_U_SU_SUI:
5199 switch (alpha_fptm)
5201 case ALPHA_FPTM_N:
5202 return NULL;
5203 case ALPHA_FPTM_U:
5204 return "u";
5205 case ALPHA_FPTM_SU:
5206 return "su";
5207 case ALPHA_FPTM_SUI:
5208 return "sui";
5210 break;
5212 abort ();
5215 /* Return the rounding mode suffix applicable to the current
5216 instruction, or NULL. */
5218 static const char *
5219 get_round_mode_suffix (void)
5221 enum attr_round_suffix s = get_attr_round_suffix (current_output_insn);
5223 switch (s)
5225 case ROUND_SUFFIX_NONE:
5226 return NULL;
5227 case ROUND_SUFFIX_NORMAL:
5228 switch (alpha_fprm)
5230 case ALPHA_FPRM_NORM:
5231 return NULL;
5232 case ALPHA_FPRM_MINF:
5233 return "m";
5234 case ALPHA_FPRM_CHOP:
5235 return "c";
5236 case ALPHA_FPRM_DYN:
5237 return "d";
5239 break;
5241 case ROUND_SUFFIX_C:
5242 return "c";
5244 abort ();
5247 /* Locate some local-dynamic symbol still in use by this function
5248 so that we can print its name in some movdi_er_tlsldm pattern. */
5250 static int
5251 get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
5253 rtx x = *px;
5255 if (GET_CODE (x) == SYMBOL_REF
5256 && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
5258 cfun->machine->some_ld_name = XSTR (x, 0);
5259 return 1;
5262 return 0;
5265 static const char *
5266 get_some_local_dynamic_name (void)
5268 rtx insn;
5270 if (cfun->machine->some_ld_name)
5271 return cfun->machine->some_ld_name;
5273 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
5274 if (INSN_P (insn)
5275 && for_each_rtx (&PATTERN (insn), get_some_local_dynamic_name_1, 0))
5276 return cfun->machine->some_ld_name;
5278 abort ();
5281 /* Print an operand. Recognize special options, documented below. */
5283 void
5284 print_operand (FILE *file, rtx x, int code)
5286 int i;
5288 switch (code)
5290 case '~':
5291 /* Print the assembler name of the current function. */
5292 assemble_name (file, alpha_fnname);
5293 break;
5295 case '&':
5296 assemble_name (file, get_some_local_dynamic_name ());
5297 break;
5299 case '/':
5301 const char *trap = get_trap_mode_suffix ();
5302 const char *round = get_round_mode_suffix ();
5304 if (trap || round)
5305 fprintf (file, (TARGET_AS_SLASH_BEFORE_SUFFIX ? "/%s%s" : "%s%s"),
5306 (trap ? trap : ""), (round ? round : ""));
5307 break;
5310 case ',':
5311 /* Generates single precision instruction suffix. */
5312 fputc ((TARGET_FLOAT_VAX ? 'f' : 's'), file);
5313 break;
5315 case '-':
5316 /* Generates double precision instruction suffix. */
5317 fputc ((TARGET_FLOAT_VAX ? 'g' : 't'), file);
5318 break;
5320 case '+':
5321 /* Generates a nop after a noreturn call at the very end of the
5322 function. */
5323 if (next_real_insn (current_output_insn) == 0)
5324 fprintf (file, "\n\tnop");
5325 break;
5327 case '#':
5328 if (alpha_this_literal_sequence_number == 0)
5329 alpha_this_literal_sequence_number = alpha_next_sequence_number++;
5330 fprintf (file, "%d", alpha_this_literal_sequence_number);
5331 break;
5333 case '*':
5334 if (alpha_this_gpdisp_sequence_number == 0)
5335 alpha_this_gpdisp_sequence_number = alpha_next_sequence_number++;
5336 fprintf (file, "%d", alpha_this_gpdisp_sequence_number);
5337 break;
5339 case 'H':
5340 if (GET_CODE (x) == HIGH)
5341 output_addr_const (file, XEXP (x, 0));
5342 else
5343 output_operand_lossage ("invalid %%H value");
5344 break;
5346 case 'J':
5348 const char *lituse;
5350 if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSGD_CALL)
5352 x = XVECEXP (x, 0, 0);
5353 lituse = "lituse_tlsgd";
5355 else if (GET_CODE (x) == UNSPEC && XINT (x, 1) == UNSPEC_TLSLDM_CALL)
5357 x = XVECEXP (x, 0, 0);
5358 lituse = "lituse_tlsldm";
5360 else if (GET_CODE (x) == CONST_INT)
5361 lituse = "lituse_jsr";
5362 else
5364 output_operand_lossage ("invalid %%J value");
5365 break;
5368 if (x != const0_rtx)
5369 fprintf (file, "\t\t!%s!%d", lituse, (int) INTVAL (x));
5371 break;
5373 case 'r':
5374 /* If this operand is the constant zero, write it as "$31". */
5375 if (GET_CODE (x) == REG)
5376 fprintf (file, "%s", reg_names[REGNO (x)]);
5377 else if (x == CONST0_RTX (GET_MODE (x)))
5378 fprintf (file, "$31");
5379 else
5380 output_operand_lossage ("invalid %%r value");
5381 break;
5383 case 'R':
5384 /* Similar, but for floating-point. */
5385 if (GET_CODE (x) == REG)
5386 fprintf (file, "%s", reg_names[REGNO (x)]);
5387 else if (x == CONST0_RTX (GET_MODE (x)))
5388 fprintf (file, "$f31");
5389 else
5390 output_operand_lossage ("invalid %%R value");
5391 break;
5393 case 'N':
5394 /* Write the 1's complement of a constant. */
5395 if (GET_CODE (x) != CONST_INT)
5396 output_operand_lossage ("invalid %%N value");
5398 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
5399 break;
5401 case 'P':
5402 /* Write 1 << C, for a constant C. */
5403 if (GET_CODE (x) != CONST_INT)
5404 output_operand_lossage ("invalid %%P value");
5406 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) 1 << INTVAL (x));
5407 break;
5409 case 'h':
5410 /* Write the high-order 16 bits of a constant, sign-extended. */
5411 if (GET_CODE (x) != CONST_INT)
5412 output_operand_lossage ("invalid %%h value");
5414 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) >> 16);
5415 break;
5417 case 'L':
5418 /* Write the low-order 16 bits of a constant, sign-extended. */
5419 if (GET_CODE (x) != CONST_INT)
5420 output_operand_lossage ("invalid %%L value");
5422 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5423 (INTVAL (x) & 0xffff) - 2 * (INTVAL (x) & 0x8000));
5424 break;
5426 case 'm':
5427 /* Write mask for ZAP insn. */
5428 if (GET_CODE (x) == CONST_DOUBLE)
5430 HOST_WIDE_INT mask = 0;
5431 HOST_WIDE_INT value;
5433 value = CONST_DOUBLE_LOW (x);
5434 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5435 i++, value >>= 8)
5436 if (value & 0xff)
5437 mask |= (1 << i);
5439 value = CONST_DOUBLE_HIGH (x);
5440 for (i = 0; i < HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
5441 i++, value >>= 8)
5442 if (value & 0xff)
5443 mask |= (1 << (i + sizeof (int)));
5445 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask & 0xff);
5448 else if (GET_CODE (x) == CONST_INT)
5450 HOST_WIDE_INT mask = 0, value = INTVAL (x);
5452 for (i = 0; i < 8; i++, value >>= 8)
5453 if (value & 0xff)
5454 mask |= (1 << i);
5456 fprintf (file, HOST_WIDE_INT_PRINT_DEC, mask);
5458 else
5459 output_operand_lossage ("invalid %%m value");
5460 break;
5462 case 'M':
5463 /* 'b', 'w', 'l', or 'q' as the value of the constant. */
5464 if (GET_CODE (x) != CONST_INT
5465 || (INTVAL (x) != 8 && INTVAL (x) != 16
5466 && INTVAL (x) != 32 && INTVAL (x) != 64))
5467 output_operand_lossage ("invalid %%M value");
5469 fprintf (file, "%s",
5470 (INTVAL (x) == 8 ? "b"
5471 : INTVAL (x) == 16 ? "w"
5472 : INTVAL (x) == 32 ? "l"
5473 : "q"));
5474 break;
5476 case 'U':
5477 /* Similar, except do it from the mask. */
5478 if (GET_CODE (x) == CONST_INT)
5480 HOST_WIDE_INT value = INTVAL (x);
5482 if (value == 0xff)
5484 fputc ('b', file);
5485 break;
5487 if (value == 0xffff)
5489 fputc ('w', file);
5490 break;
5492 if (value == 0xffffffff)
5494 fputc ('l', file);
5495 break;
5497 if (value == -1)
5499 fputc ('q', file);
5500 break;
5503 else if (HOST_BITS_PER_WIDE_INT == 32
5504 && GET_CODE (x) == CONST_DOUBLE
5505 && CONST_DOUBLE_LOW (x) == 0xffffffff
5506 && CONST_DOUBLE_HIGH (x) == 0)
5508 fputc ('l', file);
5509 break;
5511 output_operand_lossage ("invalid %%U value");
5512 break;
5514 case 's':
5515 /* Write the constant value divided by 8 for little-endian mode or
5516 (56 - value) / 8 for big-endian mode. */
5518 if (GET_CODE (x) != CONST_INT
5519 || (unsigned HOST_WIDE_INT) INTVAL (x) >= (WORDS_BIG_ENDIAN
5520 ? 56
5521 : 64)
5522 || (INTVAL (x) & 7) != 0)
5523 output_operand_lossage ("invalid %%s value");
5525 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5526 WORDS_BIG_ENDIAN
5527 ? (56 - INTVAL (x)) / 8
5528 : INTVAL (x) / 8);
5529 break;
5531 case 'S':
5532 /* Same, except compute (64 - c) / 8 */
5534 if (GET_CODE (x) != CONST_INT
5535 && (unsigned HOST_WIDE_INT) INTVAL (x) >= 64
5536 && (INTVAL (x) & 7) != 8)
5537 output_operand_lossage ("invalid %%s value");
5539 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (64 - INTVAL (x)) / 8);
5540 break;
5542 case 't':
5544 /* On Unicos/Mk systems: use a DEX expression if the symbol
5545 clashes with a register name. */
5546 int dex = unicosmk_need_dex (x);
5547 if (dex)
5548 fprintf (file, "DEX(%d)", dex);
5549 else
5550 output_addr_const (file, x);
5552 break;
5554 case 'C': case 'D': case 'c': case 'd':
5555 /* Write out comparison name. */
5557 enum rtx_code c = GET_CODE (x);
5559 if (!COMPARISON_P (x))
5560 output_operand_lossage ("invalid %%C value");
5562 else if (code == 'D')
5563 c = reverse_condition (c);
5564 else if (code == 'c')
5565 c = swap_condition (c);
5566 else if (code == 'd')
5567 c = swap_condition (reverse_condition (c));
5569 if (c == LEU)
5570 fprintf (file, "ule");
5571 else if (c == LTU)
5572 fprintf (file, "ult");
5573 else if (c == UNORDERED)
5574 fprintf (file, "un");
5575 else
5576 fprintf (file, "%s", GET_RTX_NAME (c));
5578 break;
5580 case 'E':
5581 /* Write the divide or modulus operator. */
5582 switch (GET_CODE (x))
5584 case DIV:
5585 fprintf (file, "div%s", GET_MODE (x) == SImode ? "l" : "q");
5586 break;
5587 case UDIV:
5588 fprintf (file, "div%su", GET_MODE (x) == SImode ? "l" : "q");
5589 break;
5590 case MOD:
5591 fprintf (file, "rem%s", GET_MODE (x) == SImode ? "l" : "q");
5592 break;
5593 case UMOD:
5594 fprintf (file, "rem%su", GET_MODE (x) == SImode ? "l" : "q");
5595 break;
5596 default:
5597 output_operand_lossage ("invalid %%E value");
5598 break;
5600 break;
5602 case 'A':
5603 /* Write "_u" for unaligned access. */
5604 if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == AND)
5605 fprintf (file, "_u");
5606 break;
5608 case 0:
5609 if (GET_CODE (x) == REG)
5610 fprintf (file, "%s", reg_names[REGNO (x)]);
5611 else if (GET_CODE (x) == MEM)
5612 output_address (XEXP (x, 0));
5613 else if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == UNSPEC)
5615 switch (XINT (XEXP (x, 0), 1))
5617 case UNSPEC_DTPREL:
5618 case UNSPEC_TPREL:
5619 output_addr_const (file, XVECEXP (XEXP (x, 0), 0, 0));
5620 break;
5621 default:
5622 output_operand_lossage ("unknown relocation unspec");
5623 break;
5626 else
5627 output_addr_const (file, x);
5628 break;
5630 default:
5631 output_operand_lossage ("invalid %%xn code");
5635 void
5636 print_operand_address (FILE *file, rtx addr)
5638 int basereg = 31;
5639 HOST_WIDE_INT offset = 0;
5641 if (GET_CODE (addr) == AND)
5642 addr = XEXP (addr, 0);
5644 if (GET_CODE (addr) == PLUS
5645 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
5647 offset = INTVAL (XEXP (addr, 1));
5648 addr = XEXP (addr, 0);
5651 if (GET_CODE (addr) == LO_SUM)
5653 const char *reloc16, *reloclo;
5654 rtx op1 = XEXP (addr, 1);
5656 if (GET_CODE (op1) == CONST && GET_CODE (XEXP (op1, 0)) == UNSPEC)
5658 op1 = XEXP (op1, 0);
5659 switch (XINT (op1, 1))
5661 case UNSPEC_DTPREL:
5662 reloc16 = NULL;
5663 reloclo = (alpha_tls_size == 16 ? "dtprel" : "dtprello");
5664 break;
5665 case UNSPEC_TPREL:
5666 reloc16 = NULL;
5667 reloclo = (alpha_tls_size == 16 ? "tprel" : "tprello");
5668 break;
5669 default:
5670 output_operand_lossage ("unknown relocation unspec");
5671 return;
5674 output_addr_const (file, XVECEXP (op1, 0, 0));
5676 else
5678 reloc16 = "gprel";
5679 reloclo = "gprellow";
5680 output_addr_const (file, op1);
5683 if (offset)
5684 fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC, offset);
5686 addr = XEXP (addr, 0);
5687 if (GET_CODE (addr) == REG)
5688 basereg = REGNO (addr);
5689 else if (GET_CODE (addr) == SUBREG
5690 && GET_CODE (SUBREG_REG (addr)) == REG)
5691 basereg = subreg_regno (addr);
5692 else
5693 abort ();
5695 fprintf (file, "($%d)\t\t!%s", basereg,
5696 (basereg == 29 ? reloc16 : reloclo));
5697 return;
5700 if (GET_CODE (addr) == REG)
5701 basereg = REGNO (addr);
5702 else if (GET_CODE (addr) == SUBREG
5703 && GET_CODE (SUBREG_REG (addr)) == REG)
5704 basereg = subreg_regno (addr);
5705 else if (GET_CODE (addr) == CONST_INT)
5706 offset = INTVAL (addr);
5708 #if TARGET_ABI_OPEN_VMS
5709 else if (GET_CODE (addr) == SYMBOL_REF)
5711 fprintf (file, "%s", XSTR (addr, 0));
5712 return;
5714 else if (GET_CODE (addr) == CONST
5715 && GET_CODE (XEXP (addr, 0)) == PLUS
5716 && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF)
5718 fprintf (file, "%s+" HOST_WIDE_INT_PRINT_DEC,
5719 XSTR (XEXP (XEXP (addr, 0), 0), 0),
5720 INTVAL (XEXP (XEXP (addr, 0), 1)));
5721 return;
5723 #endif
5725 else
5726 abort ();
5728 fprintf (file, HOST_WIDE_INT_PRINT_DEC "($%d)", offset, basereg);
5731 /* Emit RTL insns to initialize the variable parts of a trampoline at
5732 TRAMP. FNADDR is an RTX for the address of the function's pure
5733 code. CXT is an RTX for the static chain value for the function.
5735 The three offset parameters are for the individual template's
5736 layout. A JMPOFS < 0 indicates that the trampoline does not
5737 contain instructions at all.
5739 We assume here that a function will be called many more times than
5740 its address is taken (e.g., it might be passed to qsort), so we
5741 take the trouble to initialize the "hint" field in the JMP insn.
5742 Note that the hint field is PC (new) + 4 * bits 13:0. */
5744 void
5745 alpha_initialize_trampoline (rtx tramp, rtx fnaddr, rtx cxt,
5746 int fnofs, int cxtofs, int jmpofs)
5748 rtx temp, temp1, addr;
5749 /* VMS really uses DImode pointers in memory at this point. */
5750 enum machine_mode mode = TARGET_ABI_OPEN_VMS ? Pmode : ptr_mode;
5752 #ifdef POINTERS_EXTEND_UNSIGNED
5753 fnaddr = convert_memory_address (mode, fnaddr);
5754 cxt = convert_memory_address (mode, cxt);
5755 #endif
5757 /* Store function address and CXT. */
5758 addr = memory_address (mode, plus_constant (tramp, fnofs));
5759 emit_move_insn (gen_rtx_MEM (mode, addr), fnaddr);
5760 addr = memory_address (mode, plus_constant (tramp, cxtofs));
5761 emit_move_insn (gen_rtx_MEM (mode, addr), cxt);
5763 /* This has been disabled since the hint only has a 32k range, and in
5764 no existing OS is the stack within 32k of the text segment. */
5765 if (0 && jmpofs >= 0)
5767 /* Compute hint value. */
5768 temp = force_operand (plus_constant (tramp, jmpofs+4), NULL_RTX);
5769 temp = expand_binop (DImode, sub_optab, fnaddr, temp, temp, 1,
5770 OPTAB_WIDEN);
5771 temp = expand_shift (RSHIFT_EXPR, Pmode, temp,
5772 build_int_2 (2, 0), NULL_RTX, 1);
5773 temp = expand_and (SImode, gen_lowpart (SImode, temp),
5774 GEN_INT (0x3fff), 0);
5776 /* Merge in the hint. */
5777 addr = memory_address (SImode, plus_constant (tramp, jmpofs));
5778 temp1 = force_reg (SImode, gen_rtx_MEM (SImode, addr));
5779 temp1 = expand_and (SImode, temp1, GEN_INT (0xffffc000), NULL_RTX);
5780 temp1 = expand_binop (SImode, ior_optab, temp1, temp, temp1, 1,
5781 OPTAB_WIDEN);
5782 emit_move_insn (gen_rtx_MEM (SImode, addr), temp1);
5785 #ifdef TRANSFER_FROM_TRAMPOLINE
5786 emit_library_call (init_one_libfunc ("__enable_execute_stack"),
5787 0, VOIDmode, 1, tramp, Pmode);
5788 #endif
5790 if (jmpofs >= 0)
5791 emit_insn (gen_imb ());
5794 /* Determine where to put an argument to a function.
5795 Value is zero to push the argument on the stack,
5796 or a hard register in which to store the argument.
5798 MODE is the argument's machine mode.
5799 TYPE is the data type of the argument (as a tree).
5800 This is null for libcalls where that information may
5801 not be available.
5802 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5803 the preceding args and about the function being called.
5804 NAMED is nonzero if this argument is a named parameter
5805 (otherwise it is an extra parameter matching an ellipsis).
5807 On Alpha the first 6 words of args are normally in registers
5808 and the rest are pushed. */
5811 function_arg (CUMULATIVE_ARGS cum, enum machine_mode mode, tree type,
5812 int named ATTRIBUTE_UNUSED)
5814 int basereg;
5815 int num_args;
5817 /* Don't get confused and pass small structures in FP registers. */
5818 if (type && AGGREGATE_TYPE_P (type))
5819 basereg = 16;
5820 else
5822 #ifdef ENABLE_CHECKING
5823 /* With alpha_split_complex_arg, we shouldn't see any raw complex
5824 values here. */
5825 if (COMPLEX_MODE_P (mode))
5826 abort ();
5827 #endif
5829 /* Set up defaults for FP operands passed in FP registers, and
5830 integral operands passed in integer registers. */
5831 if (TARGET_FPREGS && GET_MODE_CLASS (mode) == MODE_FLOAT)
5832 basereg = 32 + 16;
5833 else
5834 basereg = 16;
5837 /* ??? Irritatingly, the definition of CUMULATIVE_ARGS is different for
5838 the three platforms, so we can't avoid conditional compilation. */
5839 #if TARGET_ABI_OPEN_VMS
5841 if (mode == VOIDmode)
5842 return alpha_arg_info_reg_val (cum);
5844 num_args = cum.num_args;
5845 if (num_args >= 6
5846 || targetm.calls.must_pass_in_stack (mode, type))
5847 return NULL_RTX;
5849 #elif TARGET_ABI_UNICOSMK
5851 int size;
5853 /* If this is the last argument, generate the call info word (CIW). */
5854 /* ??? We don't include the caller's line number in the CIW because
5855 I don't know how to determine it if debug infos are turned off. */
5856 if (mode == VOIDmode)
5858 int i;
5859 HOST_WIDE_INT lo;
5860 HOST_WIDE_INT hi;
5861 rtx ciw;
5863 lo = 0;
5865 for (i = 0; i < cum.num_reg_words && i < 5; i++)
5866 if (cum.reg_args_type[i])
5867 lo |= (1 << (7 - i));
5869 if (cum.num_reg_words == 6 && cum.reg_args_type[5])
5870 lo |= 7;
5871 else
5872 lo |= cum.num_reg_words;
5874 #if HOST_BITS_PER_WIDE_INT == 32
5875 hi = (cum.num_args << 20) | cum.num_arg_words;
5876 #else
5877 lo = lo | ((HOST_WIDE_INT) cum.num_args << 52)
5878 | ((HOST_WIDE_INT) cum.num_arg_words << 32);
5879 hi = 0;
5880 #endif
5881 ciw = immed_double_const (lo, hi, DImode);
5883 return gen_rtx_UNSPEC (DImode, gen_rtvec (1, ciw),
5884 UNSPEC_UMK_LOAD_CIW);
5887 size = ALPHA_ARG_SIZE (mode, type, named);
5888 num_args = cum.num_reg_words;
5889 if (cum.force_stack
5890 || cum.num_reg_words + size > 6
5891 || targetm.calls.must_pass_in_stack (mode, type))
5892 return NULL_RTX;
5893 else if (type && TYPE_MODE (type) == BLKmode)
5895 rtx reg1, reg2;
5897 reg1 = gen_rtx_REG (DImode, num_args + 16);
5898 reg1 = gen_rtx_EXPR_LIST (DImode, reg1, const0_rtx);
5900 /* The argument fits in two registers. Note that we still need to
5901 reserve a register for empty structures. */
5902 if (size == 0)
5903 return NULL_RTX;
5904 else if (size == 1)
5905 return gen_rtx_PARALLEL (mode, gen_rtvec (1, reg1));
5906 else
5908 reg2 = gen_rtx_REG (DImode, num_args + 17);
5909 reg2 = gen_rtx_EXPR_LIST (DImode, reg2, GEN_INT (8));
5910 return gen_rtx_PARALLEL (mode, gen_rtvec (2, reg1, reg2));
5914 #elif TARGET_ABI_OSF
5916 if (cum >= 6)
5917 return NULL_RTX;
5918 num_args = cum;
5920 /* VOID is passed as a special flag for "last argument". */
5921 if (type == void_type_node)
5922 basereg = 16;
5923 else if (targetm.calls.must_pass_in_stack (mode, type))
5924 return NULL_RTX;
5926 #else
5927 #error Unhandled ABI
5928 #endif
5930 return gen_rtx_REG (mode, num_args + basereg);
5933 /* Return true if TYPE must be returned in memory, instead of in registers. */
5935 static bool
5936 alpha_return_in_memory (tree type, tree fndecl ATTRIBUTE_UNUSED)
5938 enum machine_mode mode = VOIDmode;
5939 int size;
5941 if (type)
5943 mode = TYPE_MODE (type);
5945 /* All aggregates are returned in memory. */
5946 if (AGGREGATE_TYPE_P (type))
5947 return true;
5950 size = GET_MODE_SIZE (mode);
5951 switch (GET_MODE_CLASS (mode))
5953 case MODE_VECTOR_FLOAT:
5954 /* Pass all float vectors in memory, like an aggregate. */
5955 return true;
5957 case MODE_COMPLEX_FLOAT:
5958 /* We judge complex floats on the size of their element,
5959 not the size of the whole type. */
5960 size = GET_MODE_UNIT_SIZE (mode);
5961 break;
5963 case MODE_INT:
5964 case MODE_FLOAT:
5965 case MODE_COMPLEX_INT:
5966 case MODE_VECTOR_INT:
5967 break;
5969 default:
5970 /* ??? We get called on all sorts of random stuff from
5971 aggregate_value_p. We can't abort, but it's not clear
5972 what's safe to return. Pretend it's a struct I guess. */
5973 return true;
5976 /* Otherwise types must fit in one register. */
5977 return size > UNITS_PER_WORD;
5980 /* Return true if TYPE should be passed by invisible reference. */
5982 static bool
5983 alpha_pass_by_reference (CUMULATIVE_ARGS *ca ATTRIBUTE_UNUSED,
5984 enum machine_mode mode,
5985 tree type ATTRIBUTE_UNUSED,
5986 bool named ATTRIBUTE_UNUSED)
5988 return mode == TFmode || mode == TCmode;
5991 /* Define how to find the value returned by a function. VALTYPE is the
5992 data type of the value (as a tree). If the precise function being
5993 called is known, FUNC is its FUNCTION_DECL; otherwise, FUNC is 0.
5994 MODE is set instead of VALTYPE for libcalls.
5996 On Alpha the value is found in $0 for integer functions and
5997 $f0 for floating-point functions. */
6000 function_value (tree valtype, tree func ATTRIBUTE_UNUSED,
6001 enum machine_mode mode)
6003 unsigned int regnum;
6004 enum mode_class class;
6006 #ifdef ENABLE_CHECKING
6007 if (valtype && alpha_return_in_memory (valtype, func))
6008 abort ();
6009 #endif
6011 if (valtype)
6012 mode = TYPE_MODE (valtype);
6014 class = GET_MODE_CLASS (mode);
6015 switch (class)
6017 case MODE_INT:
6018 /* Do the same thing as PROMOTE_MODE. */
6019 mode = DImode;
6020 /* FALLTHRU */
6022 case MODE_COMPLEX_INT:
6023 case MODE_VECTOR_INT:
6024 regnum = 0;
6025 break;
6027 case MODE_FLOAT:
6028 regnum = 32;
6029 break;
6031 case MODE_COMPLEX_FLOAT:
6033 enum machine_mode cmode = GET_MODE_INNER (mode);
6035 return gen_rtx_PARALLEL
6036 (VOIDmode,
6037 gen_rtvec (2,
6038 gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 32),
6039 const0_rtx),
6040 gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (cmode, 33),
6041 GEN_INT (GET_MODE_SIZE (cmode)))));
6044 default:
6045 abort ();
6048 return gen_rtx_REG (mode, regnum);
6051 /* TCmode complex values are passed by invisible reference. We
6052 should not split these values. */
6054 static bool
6055 alpha_split_complex_arg (tree type)
6057 return TYPE_MODE (type) != TCmode;
6060 static tree
6061 alpha_build_builtin_va_list (void)
6063 tree base, ofs, space, record, type_decl;
6065 if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
6066 return ptr_type_node;
6068 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
6069 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
6070 TREE_CHAIN (record) = type_decl;
6071 TYPE_NAME (record) = type_decl;
6073 /* C++? SET_IS_AGGR_TYPE (record, 1); */
6075 /* Dummy field to prevent alignment warnings. */
6076 space = build_decl (FIELD_DECL, NULL_TREE, integer_type_node);
6077 DECL_FIELD_CONTEXT (space) = record;
6078 DECL_ARTIFICIAL (space) = 1;
6079 DECL_IGNORED_P (space) = 1;
6081 ofs = build_decl (FIELD_DECL, get_identifier ("__offset"),
6082 integer_type_node);
6083 DECL_FIELD_CONTEXT (ofs) = record;
6084 TREE_CHAIN (ofs) = space;
6086 base = build_decl (FIELD_DECL, get_identifier ("__base"),
6087 ptr_type_node);
6088 DECL_FIELD_CONTEXT (base) = record;
6089 TREE_CHAIN (base) = ofs;
6091 TYPE_FIELDS (record) = base;
6092 layout_type (record);
6094 return record;
6097 /* Perform any needed actions needed for a function that is receiving a
6098 variable number of arguments. */
6100 static void
6101 alpha_setup_incoming_varargs (CUMULATIVE_ARGS *pcum,
6102 enum machine_mode mode ATTRIBUTE_UNUSED,
6103 tree type ATTRIBUTE_UNUSED,
6104 int *pretend_size, int no_rtl)
6106 #if TARGET_ABI_UNICOSMK
6107 /* On Unicos/Mk, the standard subroutine __T3E_MISMATCH stores all register
6108 arguments on the stack. Unfortunately, it doesn't always store the first
6109 one (i.e. the one that arrives in $16 or $f16). This is not a problem
6110 with stdargs as we always have at least one named argument there. */
6111 int num_reg_words = pcum->num_reg_words;
6112 if (num_reg_words < 6)
6114 if (!no_rtl)
6116 emit_insn (gen_umk_mismatch_args (GEN_INT (num_reg_words + 1)));
6117 emit_insn (gen_arg_home_umk ());
6119 *pretend_size = 0;
6121 #elif TARGET_ABI_OPEN_VMS
6122 /* For VMS, we allocate space for all 6 arg registers plus a count.
6124 However, if NO registers need to be saved, don't allocate any space.
6125 This is not only because we won't need the space, but because AP
6126 includes the current_pretend_args_size and we don't want to mess up
6127 any ap-relative addresses already made. */
6128 if (pcum->num_args < 6)
6130 if (!no_rtl)
6132 emit_move_insn (gen_rtx_REG (DImode, 1), virtual_incoming_args_rtx);
6133 emit_insn (gen_arg_home ());
6135 *pretend_size = 7 * UNITS_PER_WORD;
6137 #else
6138 /* On OSF/1 and friends, we allocate space for all 12 arg registers, but
6139 only push those that are remaining. However, if NO registers need to
6140 be saved, don't allocate any space. This is not only because we won't
6141 need the space, but because AP includes the current_pretend_args_size
6142 and we don't want to mess up any ap-relative addresses already made.
6144 If we are not to use the floating-point registers, save the integer
6145 registers where we would put the floating-point registers. This is
6146 not the most efficient way to implement varargs with just one register
6147 class, but it isn't worth doing anything more efficient in this rare
6148 case. */
6149 CUMULATIVE_ARGS cum = *pcum;
6151 if (cum >= 6)
6152 return;
6154 if (!no_rtl)
6156 int set = get_varargs_alias_set ();
6157 rtx tmp;
6159 tmp = gen_rtx_MEM (BLKmode,
6160 plus_constant (virtual_incoming_args_rtx,
6161 (cum + 6) * UNITS_PER_WORD));
6162 set_mem_alias_set (tmp, set);
6163 move_block_from_reg (16 + cum, tmp, 6 - cum);
6165 tmp = gen_rtx_MEM (BLKmode,
6166 plus_constant (virtual_incoming_args_rtx,
6167 cum * UNITS_PER_WORD));
6168 set_mem_alias_set (tmp, set);
6169 move_block_from_reg (16 + (TARGET_FPREGS ? 32 : 0) + cum, tmp,
6170 6 - cum);
6172 *pretend_size = 12 * UNITS_PER_WORD;
6173 #endif
6176 void
6177 alpha_va_start (tree valist, rtx nextarg ATTRIBUTE_UNUSED)
6179 HOST_WIDE_INT offset;
6180 tree t, offset_field, base_field;
6182 if (TREE_CODE (TREE_TYPE (valist)) == ERROR_MARK)
6183 return;
6185 if (TARGET_ABI_UNICOSMK)
6186 std_expand_builtin_va_start (valist, nextarg);
6188 /* For Unix, TARGET_SETUP_INCOMING_VARARGS moves the starting address base
6189 up by 48, storing fp arg registers in the first 48 bytes, and the
6190 integer arg registers in the next 48 bytes. This is only done,
6191 however, if any integer registers need to be stored.
6193 If no integer registers need be stored, then we must subtract 48
6194 in order to account for the integer arg registers which are counted
6195 in argsize above, but which are not actually stored on the stack.
6196 Must further be careful here about structures straddling the last
6197 integer argument register; that futzes with pretend_args_size,
6198 which changes the meaning of AP. */
6200 if (NUM_ARGS <= 6)
6201 offset = TARGET_ABI_OPEN_VMS ? UNITS_PER_WORD : 6 * UNITS_PER_WORD;
6202 else
6203 offset = -6 * UNITS_PER_WORD + current_function_pretend_args_size;
6205 if (TARGET_ABI_OPEN_VMS)
6207 nextarg = plus_constant (nextarg, offset);
6208 nextarg = plus_constant (nextarg, NUM_ARGS * UNITS_PER_WORD);
6209 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
6210 make_tree (ptr_type_node, nextarg));
6211 TREE_SIDE_EFFECTS (t) = 1;
6213 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6215 else
6217 base_field = TYPE_FIELDS (TREE_TYPE (valist));
6218 offset_field = TREE_CHAIN (base_field);
6220 base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6221 valist, base_field, NULL_TREE);
6222 offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6223 valist, offset_field, NULL_TREE);
6225 t = make_tree (ptr_type_node, virtual_incoming_args_rtx);
6226 t = build (PLUS_EXPR, ptr_type_node, t, build_int_2 (offset, 0));
6227 t = build (MODIFY_EXPR, TREE_TYPE (base_field), base_field, t);
6228 TREE_SIDE_EFFECTS (t) = 1;
6229 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6231 t = build_int_2 (NUM_ARGS * UNITS_PER_WORD, 0);
6232 t = build (MODIFY_EXPR, TREE_TYPE (offset_field), offset_field, t);
6233 TREE_SIDE_EFFECTS (t) = 1;
6234 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
6238 static tree
6239 alpha_gimplify_va_arg_1 (tree type, tree base, tree offset, tree *pre_p)
6241 tree type_size, ptr_type, addend, t, addr, internal_post;
6242 bool indirect;
6244 /* If the type could not be passed in registers, skip the block
6245 reserved for the registers. */
6246 if (targetm.calls.must_pass_in_stack (TYPE_MODE (type), type))
6248 t = fold_convert (TREE_TYPE (offset), build_int_2 (6*8, 0));
6249 t = build (MODIFY_EXPR, TREE_TYPE (offset), offset,
6250 build (MAX_EXPR, TREE_TYPE (offset), offset, t));
6251 gimplify_and_add (t, pre_p);
6254 addend = offset;
6255 ptr_type = build_pointer_type (type);
6256 indirect = false;
6258 if (TYPE_MODE (type) == TFmode || TYPE_MODE (type) == TCmode)
6260 type = ptr_type;
6261 ptr_type = build_pointer_type (type);
6262 indirect = true;
6264 else if (TREE_CODE (type) == COMPLEX_TYPE)
6266 tree real_part, imag_part, real_temp;
6268 real_part = alpha_gimplify_va_arg_1 (TREE_TYPE (type), base,
6269 offset, pre_p);
6271 /* Copy the value into a new temporary, lest the formal temporary
6272 be reused out from under us. */
6273 real_temp = get_initialized_tmp_var (real_part, pre_p, NULL);
6275 imag_part = alpha_gimplify_va_arg_1 (TREE_TYPE (type), base,
6276 offset, pre_p);
6278 return build (COMPLEX_EXPR, type, real_temp, imag_part);
6280 else if (TREE_CODE (type) == REAL_TYPE)
6282 tree fpaddend, cond, fourtyeight;
6284 fourtyeight = fold_convert (TREE_TYPE (addend), build_int_2 (6*8, 0));
6285 fpaddend = fold (build (MINUS_EXPR, TREE_TYPE (addend),
6286 addend, fourtyeight));
6287 cond = fold (build (LT_EXPR, boolean_type_node, addend, fourtyeight));
6288 addend = fold (build (COND_EXPR, TREE_TYPE (addend), cond,
6289 fpaddend, addend));
6292 /* Build the final address and force that value into a temporary. */
6293 addr = build (PLUS_EXPR, ptr_type, fold_convert (ptr_type, base),
6294 fold_convert (ptr_type, addend));
6295 if (indirect)
6296 addr = build (INDIRECT_REF, type, addr);
6297 internal_post = NULL;
6298 gimplify_expr (&addr, pre_p, &internal_post, is_gimple_val, fb_rvalue);
6299 append_to_statement_list (internal_post, pre_p);
6301 /* Update the offset field. */
6302 type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type));
6303 if (type_size == NULL || TREE_OVERFLOW (type_size))
6304 t = size_zero_node;
6305 else
6307 t = size_binop (PLUS_EXPR, type_size, size_int (7));
6308 t = size_binop (TRUNC_DIV_EXPR, t, size_int (8));
6309 t = size_binop (MULT_EXPR, t, size_int (8));
6311 t = fold_convert (TREE_TYPE (offset), t);
6312 t = build (MODIFY_EXPR, void_type_node, offset,
6313 build (PLUS_EXPR, TREE_TYPE (offset), offset, t));
6314 gimplify_and_add (t, pre_p);
6316 return build_fold_indirect_ref (addr);
6319 static tree
6320 alpha_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
6322 tree offset_field, base_field, offset, base, t, r;
6324 if (TARGET_ABI_OPEN_VMS || TARGET_ABI_UNICOSMK)
6325 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
6327 base_field = TYPE_FIELDS (va_list_type_node);
6328 offset_field = TREE_CHAIN (base_field);
6329 base_field = build (COMPONENT_REF, TREE_TYPE (base_field),
6330 valist, base_field, NULL_TREE);
6331 offset_field = build (COMPONENT_REF, TREE_TYPE (offset_field),
6332 valist, offset_field, NULL_TREE);
6334 /* Pull the fields of the structure out into temporaries. Since we never
6335 modify the base field, we can use a formal temporary. Sign-extend the
6336 offset field so that it's the proper width for pointer arithmetic. */
6337 base = get_formal_tmp_var (base_field, pre_p);
6339 t = fold_convert (lang_hooks.types.type_for_size (64, 0), offset_field);
6340 offset = get_initialized_tmp_var (t, pre_p, NULL);
6342 /* Find the value. Note that this will be a stable indirection, or
6343 a composite of stable indirections in the case of complex. */
6344 r = alpha_gimplify_va_arg_1 (type, base, offset, pre_p);
6346 /* Stuff the offset temporary back into its field. */
6347 t = build (MODIFY_EXPR, void_type_node, offset_field,
6348 fold_convert (TREE_TYPE (offset_field), offset));
6349 gimplify_and_add (t, pre_p);
6351 return r;
6354 /* Builtins. */
6356 enum alpha_builtin
6358 ALPHA_BUILTIN_CMPBGE,
6359 ALPHA_BUILTIN_EXTBL,
6360 ALPHA_BUILTIN_EXTWL,
6361 ALPHA_BUILTIN_EXTLL,
6362 ALPHA_BUILTIN_EXTQL,
6363 ALPHA_BUILTIN_EXTWH,
6364 ALPHA_BUILTIN_EXTLH,
6365 ALPHA_BUILTIN_EXTQH,
6366 ALPHA_BUILTIN_INSBL,
6367 ALPHA_BUILTIN_INSWL,
6368 ALPHA_BUILTIN_INSLL,
6369 ALPHA_BUILTIN_INSQL,
6370 ALPHA_BUILTIN_INSWH,
6371 ALPHA_BUILTIN_INSLH,
6372 ALPHA_BUILTIN_INSQH,
6373 ALPHA_BUILTIN_MSKBL,
6374 ALPHA_BUILTIN_MSKWL,
6375 ALPHA_BUILTIN_MSKLL,
6376 ALPHA_BUILTIN_MSKQL,
6377 ALPHA_BUILTIN_MSKWH,
6378 ALPHA_BUILTIN_MSKLH,
6379 ALPHA_BUILTIN_MSKQH,
6380 ALPHA_BUILTIN_UMULH,
6381 ALPHA_BUILTIN_ZAP,
6382 ALPHA_BUILTIN_ZAPNOT,
6383 ALPHA_BUILTIN_AMASK,
6384 ALPHA_BUILTIN_IMPLVER,
6385 ALPHA_BUILTIN_RPCC,
6386 ALPHA_BUILTIN_THREAD_POINTER,
6387 ALPHA_BUILTIN_SET_THREAD_POINTER,
6389 /* TARGET_MAX */
6390 ALPHA_BUILTIN_MINUB8,
6391 ALPHA_BUILTIN_MINSB8,
6392 ALPHA_BUILTIN_MINUW4,
6393 ALPHA_BUILTIN_MINSW4,
6394 ALPHA_BUILTIN_MAXUB8,
6395 ALPHA_BUILTIN_MAXSB8,
6396 ALPHA_BUILTIN_MAXUW4,
6397 ALPHA_BUILTIN_MAXSW4,
6398 ALPHA_BUILTIN_PERR,
6399 ALPHA_BUILTIN_PKLB,
6400 ALPHA_BUILTIN_PKWB,
6401 ALPHA_BUILTIN_UNPKBL,
6402 ALPHA_BUILTIN_UNPKBW,
6404 /* TARGET_CIX */
6405 ALPHA_BUILTIN_CTTZ,
6406 ALPHA_BUILTIN_CTLZ,
6407 ALPHA_BUILTIN_CTPOP,
6409 ALPHA_BUILTIN_max
6412 static unsigned int const code_for_builtin[ALPHA_BUILTIN_max] = {
6413 CODE_FOR_builtin_cmpbge,
6414 CODE_FOR_builtin_extbl,
6415 CODE_FOR_builtin_extwl,
6416 CODE_FOR_builtin_extll,
6417 CODE_FOR_builtin_extql,
6418 CODE_FOR_builtin_extwh,
6419 CODE_FOR_builtin_extlh,
6420 CODE_FOR_builtin_extqh,
6421 CODE_FOR_builtin_insbl,
6422 CODE_FOR_builtin_inswl,
6423 CODE_FOR_builtin_insll,
6424 CODE_FOR_builtin_insql,
6425 CODE_FOR_builtin_inswh,
6426 CODE_FOR_builtin_inslh,
6427 CODE_FOR_builtin_insqh,
6428 CODE_FOR_builtin_mskbl,
6429 CODE_FOR_builtin_mskwl,
6430 CODE_FOR_builtin_mskll,
6431 CODE_FOR_builtin_mskql,
6432 CODE_FOR_builtin_mskwh,
6433 CODE_FOR_builtin_msklh,
6434 CODE_FOR_builtin_mskqh,
6435 CODE_FOR_umuldi3_highpart,
6436 CODE_FOR_builtin_zap,
6437 CODE_FOR_builtin_zapnot,
6438 CODE_FOR_builtin_amask,
6439 CODE_FOR_builtin_implver,
6440 CODE_FOR_builtin_rpcc,
6441 CODE_FOR_load_tp,
6442 CODE_FOR_set_tp,
6444 /* TARGET_MAX */
6445 CODE_FOR_builtin_minub8,
6446 CODE_FOR_builtin_minsb8,
6447 CODE_FOR_builtin_minuw4,
6448 CODE_FOR_builtin_minsw4,
6449 CODE_FOR_builtin_maxub8,
6450 CODE_FOR_builtin_maxsb8,
6451 CODE_FOR_builtin_maxuw4,
6452 CODE_FOR_builtin_maxsw4,
6453 CODE_FOR_builtin_perr,
6454 CODE_FOR_builtin_pklb,
6455 CODE_FOR_builtin_pkwb,
6456 CODE_FOR_builtin_unpkbl,
6457 CODE_FOR_builtin_unpkbw,
6459 /* TARGET_CIX */
6460 CODE_FOR_builtin_cttz,
6461 CODE_FOR_builtin_ctlz,
6462 CODE_FOR_builtin_ctpop
6465 struct alpha_builtin_def
6467 const char *name;
6468 enum alpha_builtin code;
6469 unsigned int target_mask;
6472 static struct alpha_builtin_def const zero_arg_builtins[] = {
6473 { "__builtin_alpha_implver", ALPHA_BUILTIN_IMPLVER, 0 },
6474 { "__builtin_alpha_rpcc", ALPHA_BUILTIN_RPCC, 0 }
6477 static struct alpha_builtin_def const one_arg_builtins[] = {
6478 { "__builtin_alpha_amask", ALPHA_BUILTIN_AMASK, 0 },
6479 { "__builtin_alpha_pklb", ALPHA_BUILTIN_PKLB, MASK_MAX },
6480 { "__builtin_alpha_pkwb", ALPHA_BUILTIN_PKWB, MASK_MAX },
6481 { "__builtin_alpha_unpkbl", ALPHA_BUILTIN_UNPKBL, MASK_MAX },
6482 { "__builtin_alpha_unpkbw", ALPHA_BUILTIN_UNPKBW, MASK_MAX },
6483 { "__builtin_alpha_cttz", ALPHA_BUILTIN_CTTZ, MASK_CIX },
6484 { "__builtin_alpha_ctlz", ALPHA_BUILTIN_CTLZ, MASK_CIX },
6485 { "__builtin_alpha_ctpop", ALPHA_BUILTIN_CTPOP, MASK_CIX }
6488 static struct alpha_builtin_def const two_arg_builtins[] = {
6489 { "__builtin_alpha_cmpbge", ALPHA_BUILTIN_CMPBGE, 0 },
6490 { "__builtin_alpha_extbl", ALPHA_BUILTIN_EXTBL, 0 },
6491 { "__builtin_alpha_extwl", ALPHA_BUILTIN_EXTWL, 0 },
6492 { "__builtin_alpha_extll", ALPHA_BUILTIN_EXTLL, 0 },
6493 { "__builtin_alpha_extql", ALPHA_BUILTIN_EXTQL, 0 },
6494 { "__builtin_alpha_extwh", ALPHA_BUILTIN_EXTWH, 0 },
6495 { "__builtin_alpha_extlh", ALPHA_BUILTIN_EXTLH, 0 },
6496 { "__builtin_alpha_extqh", ALPHA_BUILTIN_EXTQH, 0 },
6497 { "__builtin_alpha_insbl", ALPHA_BUILTIN_INSBL, 0 },
6498 { "__builtin_alpha_inswl", ALPHA_BUILTIN_INSWL, 0 },
6499 { "__builtin_alpha_insll", ALPHA_BUILTIN_INSLL, 0 },
6500 { "__builtin_alpha_insql", ALPHA_BUILTIN_INSQL, 0 },
6501 { "__builtin_alpha_inswh", ALPHA_BUILTIN_INSWH, 0 },
6502 { "__builtin_alpha_inslh", ALPHA_BUILTIN_INSLH, 0 },
6503 { "__builtin_alpha_insqh", ALPHA_BUILTIN_INSQH, 0 },
6504 { "__builtin_alpha_mskbl", ALPHA_BUILTIN_MSKBL, 0 },
6505 { "__builtin_alpha_mskwl", ALPHA_BUILTIN_MSKWL, 0 },
6506 { "__builtin_alpha_mskll", ALPHA_BUILTIN_MSKLL, 0 },
6507 { "__builtin_alpha_mskql", ALPHA_BUILTIN_MSKQL, 0 },
6508 { "__builtin_alpha_mskwh", ALPHA_BUILTIN_MSKWH, 0 },
6509 { "__builtin_alpha_msklh", ALPHA_BUILTIN_MSKLH, 0 },
6510 { "__builtin_alpha_mskqh", ALPHA_BUILTIN_MSKQH, 0 },
6511 { "__builtin_alpha_umulh", ALPHA_BUILTIN_UMULH, 0 },
6512 { "__builtin_alpha_zap", ALPHA_BUILTIN_ZAP, 0 },
6513 { "__builtin_alpha_zapnot", ALPHA_BUILTIN_ZAPNOT, 0 },
6514 { "__builtin_alpha_minub8", ALPHA_BUILTIN_MINUB8, MASK_MAX },
6515 { "__builtin_alpha_minsb8", ALPHA_BUILTIN_MINSB8, MASK_MAX },
6516 { "__builtin_alpha_minuw4", ALPHA_BUILTIN_MINUW4, MASK_MAX },
6517 { "__builtin_alpha_minsw4", ALPHA_BUILTIN_MINSW4, MASK_MAX },
6518 { "__builtin_alpha_maxub8", ALPHA_BUILTIN_MAXUB8, MASK_MAX },
6519 { "__builtin_alpha_maxsb8", ALPHA_BUILTIN_MAXSB8, MASK_MAX },
6520 { "__builtin_alpha_maxuw4", ALPHA_BUILTIN_MAXUW4, MASK_MAX },
6521 { "__builtin_alpha_maxsw4", ALPHA_BUILTIN_MAXSW4, MASK_MAX },
6522 { "__builtin_alpha_perr", ALPHA_BUILTIN_PERR, MASK_MAX }
6525 static void
6526 alpha_init_builtins (void)
6528 const struct alpha_builtin_def *p;
6529 tree ftype;
6530 size_t i;
6532 ftype = build_function_type (long_integer_type_node, void_list_node);
6534 p = zero_arg_builtins;
6535 for (i = 0; i < ARRAY_SIZE (zero_arg_builtins); ++i, ++p)
6536 if ((target_flags & p->target_mask) == p->target_mask)
6537 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6538 NULL, NULL_TREE);
6540 ftype = build_function_type_list (long_integer_type_node,
6541 long_integer_type_node, NULL_TREE);
6543 p = one_arg_builtins;
6544 for (i = 0; i < ARRAY_SIZE (one_arg_builtins); ++i, ++p)
6545 if ((target_flags & p->target_mask) == p->target_mask)
6546 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6547 NULL, NULL_TREE);
6549 ftype = build_function_type_list (long_integer_type_node,
6550 long_integer_type_node,
6551 long_integer_type_node, NULL_TREE);
6553 p = two_arg_builtins;
6554 for (i = 0; i < ARRAY_SIZE (two_arg_builtins); ++i, ++p)
6555 if ((target_flags & p->target_mask) == p->target_mask)
6556 builtin_function (p->name, ftype, p->code, BUILT_IN_MD,
6557 NULL, NULL_TREE);
6559 ftype = build_function_type (ptr_type_node, void_list_node);
6560 builtin_function ("__builtin_thread_pointer", ftype,
6561 ALPHA_BUILTIN_THREAD_POINTER, BUILT_IN_MD,
6562 NULL, NULL_TREE);
6564 ftype = build_function_type_list (void_type_node, ptr_type_node, NULL_TREE);
6565 builtin_function ("__builtin_set_thread_pointer", ftype,
6566 ALPHA_BUILTIN_SET_THREAD_POINTER, BUILT_IN_MD,
6567 NULL, NULL_TREE);
6570 /* Expand an expression EXP that calls a built-in function,
6571 with result going to TARGET if that's convenient
6572 (and in mode MODE if that's convenient).
6573 SUBTARGET may be used as the target for computing one of EXP's operands.
6574 IGNORE is nonzero if the value is to be ignored. */
6576 static rtx
6577 alpha_expand_builtin (tree exp, rtx target,
6578 rtx subtarget ATTRIBUTE_UNUSED,
6579 enum machine_mode mode ATTRIBUTE_UNUSED,
6580 int ignore ATTRIBUTE_UNUSED)
6582 #define MAX_ARGS 2
6584 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6585 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6586 tree arglist = TREE_OPERAND (exp, 1);
6587 enum insn_code icode;
6588 rtx op[MAX_ARGS], pat;
6589 int arity;
6590 bool nonvoid;
6592 if (fcode >= ALPHA_BUILTIN_max)
6593 internal_error ("bad builtin fcode");
6594 icode = code_for_builtin[fcode];
6595 if (icode == 0)
6596 internal_error ("bad builtin fcode");
6598 nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
6600 for (arglist = TREE_OPERAND (exp, 1), arity = 0;
6601 arglist;
6602 arglist = TREE_CHAIN (arglist), arity++)
6604 const struct insn_operand_data *insn_op;
6606 tree arg = TREE_VALUE (arglist);
6607 if (arg == error_mark_node)
6608 return NULL_RTX;
6609 if (arity > MAX_ARGS)
6610 return NULL_RTX;
6612 insn_op = &insn_data[icode].operand[arity + nonvoid];
6614 op[arity] = expand_expr (arg, NULL_RTX, insn_op->mode, 0);
6616 if (!(*insn_op->predicate) (op[arity], insn_op->mode))
6617 op[arity] = copy_to_mode_reg (insn_op->mode, op[arity]);
6620 if (nonvoid)
6622 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6623 if (!target
6624 || GET_MODE (target) != tmode
6625 || !(*insn_data[icode].operand[0].predicate) (target, tmode))
6626 target = gen_reg_rtx (tmode);
6629 switch (arity)
6631 case 0:
6632 pat = GEN_FCN (icode) (target);
6633 break;
6634 case 1:
6635 if (nonvoid)
6636 pat = GEN_FCN (icode) (target, op[0]);
6637 else
6638 pat = GEN_FCN (icode) (op[0]);
6639 break;
6640 case 2:
6641 pat = GEN_FCN (icode) (target, op[0], op[1]);
6642 break;
6643 default:
6644 abort ();
6646 if (!pat)
6647 return NULL_RTX;
6648 emit_insn (pat);
6650 if (nonvoid)
6651 return target;
6652 else
6653 return const0_rtx;
6656 /* This page contains routines that are used to determine what the function
6657 prologue and epilogue code will do and write them out. */
6659 /* Compute the size of the save area in the stack. */
6661 /* These variables are used for communication between the following functions.
6662 They indicate various things about the current function being compiled
6663 that are used to tell what kind of prologue, epilogue and procedure
6664 descriptor to generate. */
6666 /* Nonzero if we need a stack procedure. */
6667 enum alpha_procedure_types {PT_NULL = 0, PT_REGISTER = 1, PT_STACK = 2};
6668 static enum alpha_procedure_types alpha_procedure_type;
6670 /* Register number (either FP or SP) that is used to unwind the frame. */
6671 static int vms_unwind_regno;
6673 /* Register number used to save FP. We need not have one for RA since
6674 we don't modify it for register procedures. This is only defined
6675 for register frame procedures. */
6676 static int vms_save_fp_regno;
6678 /* Register number used to reference objects off our PV. */
6679 static int vms_base_regno;
6681 /* Compute register masks for saved registers. */
6683 static void
6684 alpha_sa_mask (unsigned long *imaskP, unsigned long *fmaskP)
6686 unsigned long imask = 0;
6687 unsigned long fmask = 0;
6688 unsigned int i;
6690 /* When outputting a thunk, we don't have valid register life info,
6691 but assemble_start_function wants to output .frame and .mask
6692 directives. */
6693 if (current_function_is_thunk)
6695 *imaskP = 0;
6696 *fmaskP = 0;
6697 return;
6700 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
6701 imask |= (1UL << HARD_FRAME_POINTER_REGNUM);
6703 /* One for every register we have to save. */
6704 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
6705 if (! fixed_regs[i] && ! call_used_regs[i]
6706 && regs_ever_live[i] && i != REG_RA
6707 && (!TARGET_ABI_UNICOSMK || i != HARD_FRAME_POINTER_REGNUM))
6709 if (i < 32)
6710 imask |= (1UL << i);
6711 else
6712 fmask |= (1UL << (i - 32));
6715 /* We need to restore these for the handler. */
6716 if (current_function_calls_eh_return)
6718 for (i = 0; ; ++i)
6720 unsigned regno = EH_RETURN_DATA_REGNO (i);
6721 if (regno == INVALID_REGNUM)
6722 break;
6723 imask |= 1UL << regno;
6726 /* Glibc likes to use $31 as an unwind stopper for crt0. To
6727 avoid hackery in unwind-dw2.c, we need to actively store a
6728 zero in the prologue of _Unwind_RaiseException et al. */
6729 imask |= 1UL << 31;
6732 /* If any register spilled, then spill the return address also. */
6733 /* ??? This is required by the Digital stack unwind specification
6734 and isn't needed if we're doing Dwarf2 unwinding. */
6735 if (imask || fmask || alpha_ra_ever_killed ())
6736 imask |= (1UL << REG_RA);
6738 *imaskP = imask;
6739 *fmaskP = fmask;
6743 alpha_sa_size (void)
6745 unsigned long mask[2];
6746 int sa_size = 0;
6747 int i, j;
6749 alpha_sa_mask (&mask[0], &mask[1]);
6751 if (TARGET_ABI_UNICOSMK)
6753 if (mask[0] || mask[1])
6754 sa_size = 14;
6756 else
6758 for (j = 0; j < 2; ++j)
6759 for (i = 0; i < 32; ++i)
6760 if ((mask[j] >> i) & 1)
6761 sa_size++;
6764 if (TARGET_ABI_UNICOSMK)
6766 /* We might not need to generate a frame if we don't make any calls
6767 (including calls to __T3E_MISMATCH if this is a vararg function),
6768 don't have any local variables which require stack slots, don't
6769 use alloca and have not determined that we need a frame for other
6770 reasons. */
6772 alpha_procedure_type
6773 = (sa_size || get_frame_size() != 0
6774 || current_function_outgoing_args_size
6775 || current_function_stdarg || current_function_calls_alloca
6776 || frame_pointer_needed)
6777 ? PT_STACK : PT_REGISTER;
6779 /* Always reserve space for saving callee-saved registers if we
6780 need a frame as required by the calling convention. */
6781 if (alpha_procedure_type == PT_STACK)
6782 sa_size = 14;
6784 else if (TARGET_ABI_OPEN_VMS)
6786 /* Start by assuming we can use a register procedure if we don't
6787 make any calls (REG_RA not used) or need to save any
6788 registers and a stack procedure if we do. */
6789 if ((mask[0] >> REG_RA) & 1)
6790 alpha_procedure_type = PT_STACK;
6791 else if (get_frame_size() != 0)
6792 alpha_procedure_type = PT_REGISTER;
6793 else
6794 alpha_procedure_type = PT_NULL;
6796 /* Don't reserve space for saving FP & RA yet. Do that later after we've
6797 made the final decision on stack procedure vs register procedure. */
6798 if (alpha_procedure_type == PT_STACK)
6799 sa_size -= 2;
6801 /* Decide whether to refer to objects off our PV via FP or PV.
6802 If we need FP for something else or if we receive a nonlocal
6803 goto (which expects PV to contain the value), we must use PV.
6804 Otherwise, start by assuming we can use FP. */
6806 vms_base_regno
6807 = (frame_pointer_needed
6808 || current_function_has_nonlocal_label
6809 || alpha_procedure_type == PT_STACK
6810 || current_function_outgoing_args_size)
6811 ? REG_PV : HARD_FRAME_POINTER_REGNUM;
6813 /* If we want to copy PV into FP, we need to find some register
6814 in which to save FP. */
6816 vms_save_fp_regno = -1;
6817 if (vms_base_regno == HARD_FRAME_POINTER_REGNUM)
6818 for (i = 0; i < 32; i++)
6819 if (! fixed_regs[i] && call_used_regs[i] && ! regs_ever_live[i])
6820 vms_save_fp_regno = i;
6822 if (vms_save_fp_regno == -1 && alpha_procedure_type == PT_REGISTER)
6823 vms_base_regno = REG_PV, alpha_procedure_type = PT_STACK;
6824 else if (alpha_procedure_type == PT_NULL)
6825 vms_base_regno = REG_PV;
6827 /* Stack unwinding should be done via FP unless we use it for PV. */
6828 vms_unwind_regno = (vms_base_regno == REG_PV
6829 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM);
6831 /* If this is a stack procedure, allow space for saving FP and RA. */
6832 if (alpha_procedure_type == PT_STACK)
6833 sa_size += 2;
6835 else
6837 /* Our size must be even (multiple of 16 bytes). */
6838 if (sa_size & 1)
6839 sa_size++;
6842 return sa_size * 8;
6845 /* Define the offset between two registers, one to be eliminated,
6846 and the other its replacement, at the start of a routine. */
6848 HOST_WIDE_INT
6849 alpha_initial_elimination_offset (unsigned int from,
6850 unsigned int to ATTRIBUTE_UNUSED)
6852 HOST_WIDE_INT ret;
6854 ret = alpha_sa_size ();
6855 ret += ALPHA_ROUND (current_function_outgoing_args_size);
6857 if (from == FRAME_POINTER_REGNUM)
6859 else if (from == ARG_POINTER_REGNUM)
6860 ret += (ALPHA_ROUND (get_frame_size ()
6861 + current_function_pretend_args_size)
6862 - current_function_pretend_args_size);
6863 else
6864 abort ();
6866 return ret;
6870 alpha_pv_save_size (void)
6872 alpha_sa_size ();
6873 return alpha_procedure_type == PT_STACK ? 8 : 0;
6877 alpha_using_fp (void)
6879 alpha_sa_size ();
6880 return vms_unwind_regno == HARD_FRAME_POINTER_REGNUM;
6883 #if TARGET_ABI_OPEN_VMS
6885 const struct attribute_spec vms_attribute_table[] =
6887 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
6888 { "overlaid", 0, 0, true, false, false, NULL },
6889 { "global", 0, 0, true, false, false, NULL },
6890 { "initialize", 0, 0, true, false, false, NULL },
6891 { NULL, 0, 0, false, false, false, NULL }
6894 #endif
6896 static int
6897 find_lo_sum_using_gp (rtx *px, void *data ATTRIBUTE_UNUSED)
6899 return GET_CODE (*px) == LO_SUM && XEXP (*px, 0) == pic_offset_table_rtx;
6903 alpha_find_lo_sum_using_gp (rtx insn)
6905 return for_each_rtx (&PATTERN (insn), find_lo_sum_using_gp, NULL) > 0;
6908 static int
6909 alpha_does_function_need_gp (void)
6911 rtx insn;
6913 /* The GP being variable is an OSF abi thing. */
6914 if (! TARGET_ABI_OSF)
6915 return 0;
6917 /* We need the gp to load the address of __mcount. */
6918 if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
6919 return 1;
6921 /* The code emitted by alpha_output_mi_thunk_osf uses the gp. */
6922 if (current_function_is_thunk)
6923 return 1;
6925 /* The nonlocal receiver pattern assumes that the gp is valid for
6926 the nested function. Reasonable because it's almost always set
6927 correctly already. For the cases where that's wrong, make sure
6928 the nested function loads its gp on entry. */
6929 if (current_function_has_nonlocal_goto)
6930 return 1;
6932 /* If we need a GP (we have a LDSYM insn or a CALL_INSN), load it first.
6933 Even if we are a static function, we still need to do this in case
6934 our address is taken and passed to something like qsort. */
6936 push_topmost_sequence ();
6937 insn = get_insns ();
6938 pop_topmost_sequence ();
6940 for (; insn; insn = NEXT_INSN (insn))
6941 if (INSN_P (insn)
6942 && GET_CODE (PATTERN (insn)) != USE
6943 && GET_CODE (PATTERN (insn)) != CLOBBER
6944 && get_attr_usegp (insn))
6945 return 1;
6947 return 0;
6951 /* Helper function to set RTX_FRAME_RELATED_P on instructions, including
6952 sequences. */
6954 static rtx
6955 set_frame_related_p (void)
6957 rtx seq = get_insns ();
6958 rtx insn;
6960 end_sequence ();
6962 if (!seq)
6963 return NULL_RTX;
6965 if (INSN_P (seq))
6967 insn = seq;
6968 while (insn != NULL_RTX)
6970 RTX_FRAME_RELATED_P (insn) = 1;
6971 insn = NEXT_INSN (insn);
6973 seq = emit_insn (seq);
6975 else
6977 seq = emit_insn (seq);
6978 RTX_FRAME_RELATED_P (seq) = 1;
6980 return seq;
6983 #define FRP(exp) (start_sequence (), exp, set_frame_related_p ())
6985 /* Write function prologue. */
6987 /* On vms we have two kinds of functions:
6989 - stack frame (PROC_STACK)
6990 these are 'normal' functions with local vars and which are
6991 calling other functions
6992 - register frame (PROC_REGISTER)
6993 keeps all data in registers, needs no stack
6995 We must pass this to the assembler so it can generate the
6996 proper pdsc (procedure descriptor)
6997 This is done with the '.pdesc' command.
6999 On not-vms, we don't really differentiate between the two, as we can
7000 simply allocate stack without saving registers. */
7002 void
7003 alpha_expand_prologue (void)
7005 /* Registers to save. */
7006 unsigned long imask = 0;
7007 unsigned long fmask = 0;
7008 /* Stack space needed for pushing registers clobbered by us. */
7009 HOST_WIDE_INT sa_size;
7010 /* Complete stack size needed. */
7011 HOST_WIDE_INT frame_size;
7012 /* Offset from base reg to register save area. */
7013 HOST_WIDE_INT reg_offset;
7014 rtx sa_reg, mem;
7015 int i;
7017 sa_size = alpha_sa_size ();
7019 frame_size = get_frame_size ();
7020 if (TARGET_ABI_OPEN_VMS)
7021 frame_size = ALPHA_ROUND (sa_size
7022 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7023 + frame_size
7024 + current_function_pretend_args_size);
7025 else if (TARGET_ABI_UNICOSMK)
7026 /* We have to allocate space for the DSIB if we generate a frame. */
7027 frame_size = ALPHA_ROUND (sa_size
7028 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7029 + ALPHA_ROUND (frame_size
7030 + current_function_outgoing_args_size);
7031 else
7032 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7033 + sa_size
7034 + ALPHA_ROUND (frame_size
7035 + current_function_pretend_args_size));
7037 if (TARGET_ABI_OPEN_VMS)
7038 reg_offset = 8;
7039 else
7040 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7042 alpha_sa_mask (&imask, &fmask);
7044 /* Emit an insn to reload GP, if needed. */
7045 if (TARGET_ABI_OSF)
7047 alpha_function_needs_gp = alpha_does_function_need_gp ();
7048 if (alpha_function_needs_gp)
7049 emit_insn (gen_prologue_ldgp ());
7052 /* TARGET_PROFILING_NEEDS_GP actually implies that we need to insert
7053 the call to mcount ourselves, rather than having the linker do it
7054 magically in response to -pg. Since _mcount has special linkage,
7055 don't represent the call as a call. */
7056 if (TARGET_PROFILING_NEEDS_GP && current_function_profile)
7057 emit_insn (gen_prologue_mcount ());
7059 if (TARGET_ABI_UNICOSMK)
7060 unicosmk_gen_dsib (&imask);
7062 /* Adjust the stack by the frame size. If the frame size is > 4096
7063 bytes, we need to be sure we probe somewhere in the first and last
7064 4096 bytes (we can probably get away without the latter test) and
7065 every 8192 bytes in between. If the frame size is > 32768, we
7066 do this in a loop. Otherwise, we generate the explicit probe
7067 instructions.
7069 Note that we are only allowed to adjust sp once in the prologue. */
7071 if (frame_size <= 32768)
7073 if (frame_size > 4096)
7075 int probed = 4096;
7078 emit_insn (gen_probe_stack (GEN_INT (TARGET_ABI_UNICOSMK
7079 ? -probed + 64
7080 : -probed)));
7081 while ((probed += 8192) < frame_size);
7083 /* We only have to do this probe if we aren't saving registers. */
7084 if (sa_size == 0 && probed + 4096 < frame_size)
7085 emit_insn (gen_probe_stack (GEN_INT (-frame_size)));
7088 if (frame_size != 0)
7089 FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
7090 GEN_INT (TARGET_ABI_UNICOSMK
7091 ? -frame_size + 64
7092 : -frame_size))));
7094 else
7096 /* Here we generate code to set R22 to SP + 4096 and set R23 to the
7097 number of 8192 byte blocks to probe. We then probe each block
7098 in the loop and then set SP to the proper location. If the
7099 amount remaining is > 4096, we have to do one more probe if we
7100 are not saving any registers. */
7102 HOST_WIDE_INT blocks = (frame_size + 4096) / 8192;
7103 HOST_WIDE_INT leftover = frame_size + 4096 - blocks * 8192;
7104 rtx ptr = gen_rtx_REG (DImode, 22);
7105 rtx count = gen_rtx_REG (DImode, 23);
7106 rtx seq;
7108 emit_move_insn (count, GEN_INT (blocks));
7109 emit_insn (gen_adddi3 (ptr, stack_pointer_rtx,
7110 GEN_INT (TARGET_ABI_UNICOSMK ? 4096 - 64 : 4096)));
7112 /* Because of the difficulty in emitting a new basic block this
7113 late in the compilation, generate the loop as a single insn. */
7114 emit_insn (gen_prologue_stack_probe_loop (count, ptr));
7116 if (leftover > 4096 && sa_size == 0)
7118 rtx last = gen_rtx_MEM (DImode, plus_constant (ptr, -leftover));
7119 MEM_VOLATILE_P (last) = 1;
7120 emit_move_insn (last, const0_rtx);
7123 if (TARGET_ABI_WINDOWS_NT)
7125 /* For NT stack unwind (done by 'reverse execution'), it's
7126 not OK to take the result of a loop, even though the value
7127 is already in ptr, so we reload it via a single operation
7128 and subtract it to sp.
7130 Yes, that's correct -- we have to reload the whole constant
7131 into a temporary via ldah+lda then subtract from sp. */
7133 HOST_WIDE_INT lo, hi;
7134 lo = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
7135 hi = frame_size - lo;
7137 emit_move_insn (ptr, GEN_INT (hi));
7138 emit_insn (gen_adddi3 (ptr, ptr, GEN_INT (lo)));
7139 seq = emit_insn (gen_subdi3 (stack_pointer_rtx, stack_pointer_rtx,
7140 ptr));
7142 else
7144 seq = emit_insn (gen_adddi3 (stack_pointer_rtx, ptr,
7145 GEN_INT (-leftover)));
7148 /* This alternative is special, because the DWARF code cannot
7149 possibly intuit through the loop above. So we invent this
7150 note it looks at instead. */
7151 RTX_FRAME_RELATED_P (seq) = 1;
7152 REG_NOTES (seq)
7153 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
7154 gen_rtx_SET (VOIDmode, stack_pointer_rtx,
7155 gen_rtx_PLUS (Pmode, stack_pointer_rtx,
7156 GEN_INT (TARGET_ABI_UNICOSMK
7157 ? -frame_size + 64
7158 : -frame_size))),
7159 REG_NOTES (seq));
7162 if (!TARGET_ABI_UNICOSMK)
7164 /* Cope with very large offsets to the register save area. */
7165 sa_reg = stack_pointer_rtx;
7166 if (reg_offset + sa_size > 0x8000)
7168 int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7169 HOST_WIDE_INT bias;
7171 if (low + sa_size <= 0x8000)
7172 bias = reg_offset - low, reg_offset = low;
7173 else
7174 bias = reg_offset, reg_offset = 0;
7176 sa_reg = gen_rtx_REG (DImode, 24);
7177 FRP (emit_insn (gen_adddi3 (sa_reg, stack_pointer_rtx,
7178 GEN_INT (bias))));
7181 /* Save regs in stack order. Beginning with VMS PV. */
7182 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7184 mem = gen_rtx_MEM (DImode, stack_pointer_rtx);
7185 set_mem_alias_set (mem, alpha_sr_alias_set);
7186 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_PV)));
7189 /* Save register RA next. */
7190 if (imask & (1UL << REG_RA))
7192 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7193 set_mem_alias_set (mem, alpha_sr_alias_set);
7194 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA)));
7195 imask &= ~(1UL << REG_RA);
7196 reg_offset += 8;
7199 /* Now save any other registers required to be saved. */
7200 for (i = 0; i < 31; i++)
7201 if (imask & (1UL << i))
7203 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7204 set_mem_alias_set (mem, alpha_sr_alias_set);
7205 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, i)));
7206 reg_offset += 8;
7209 /* Store a zero if requested for unwinding. */
7210 if (imask & (1UL << 31))
7212 rtx insn, t;
7214 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7215 set_mem_alias_set (mem, alpha_sr_alias_set);
7216 insn = emit_move_insn (mem, const0_rtx);
7218 RTX_FRAME_RELATED_P (insn) = 1;
7219 t = gen_rtx_REG (Pmode, 31);
7220 t = gen_rtx_SET (VOIDmode, mem, t);
7221 t = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, t, REG_NOTES (insn));
7222 REG_NOTES (insn) = t;
7224 reg_offset += 8;
7227 for (i = 0; i < 31; i++)
7228 if (fmask & (1UL << i))
7230 mem = gen_rtx_MEM (DFmode, plus_constant (sa_reg, reg_offset));
7231 set_mem_alias_set (mem, alpha_sr_alias_set);
7232 FRP (emit_move_insn (mem, gen_rtx_REG (DFmode, i+32)));
7233 reg_offset += 8;
7236 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7238 /* The standard frame on the T3E includes space for saving registers.
7239 We just have to use it. We don't have to save the return address and
7240 the old frame pointer here - they are saved in the DSIB. */
7242 reg_offset = -56;
7243 for (i = 9; i < 15; i++)
7244 if (imask & (1UL << i))
7246 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx,
7247 reg_offset));
7248 set_mem_alias_set (mem, alpha_sr_alias_set);
7249 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, i)));
7250 reg_offset -= 8;
7252 for (i = 2; i < 10; i++)
7253 if (fmask & (1UL << i))
7255 mem = gen_rtx_MEM (DFmode, plus_constant (hard_frame_pointer_rtx,
7256 reg_offset));
7257 set_mem_alias_set (mem, alpha_sr_alias_set);
7258 FRP (emit_move_insn (mem, gen_rtx_REG (DFmode, i+32)));
7259 reg_offset -= 8;
7263 if (TARGET_ABI_OPEN_VMS)
7265 if (alpha_procedure_type == PT_REGISTER)
7266 /* Register frame procedures save the fp.
7267 ?? Ought to have a dwarf2 save for this. */
7268 emit_move_insn (gen_rtx_REG (DImode, vms_save_fp_regno),
7269 hard_frame_pointer_rtx);
7271 if (alpha_procedure_type != PT_NULL && vms_base_regno != REG_PV)
7272 emit_insn (gen_force_movdi (gen_rtx_REG (DImode, vms_base_regno),
7273 gen_rtx_REG (DImode, REG_PV)));
7275 if (alpha_procedure_type != PT_NULL
7276 && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7277 FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7279 /* If we have to allocate space for outgoing args, do it now. */
7280 if (current_function_outgoing_args_size != 0)
7282 rtx seq
7283 = emit_move_insn (stack_pointer_rtx,
7284 plus_constant
7285 (hard_frame_pointer_rtx,
7286 - (ALPHA_ROUND
7287 (current_function_outgoing_args_size))));
7289 /* Only set FRAME_RELATED_P on the stack adjustment we just emitted
7290 if ! frame_pointer_needed. Setting the bit will change the CFA
7291 computation rule to use sp again, which would be wrong if we had
7292 frame_pointer_needed, as this means sp might move unpredictably
7293 later on.
7295 Also, note that
7296 frame_pointer_needed
7297 => vms_unwind_regno == HARD_FRAME_POINTER_REGNUM
7299 current_function_outgoing_args_size != 0
7300 => alpha_procedure_type != PT_NULL,
7302 so when we are not setting the bit here, we are guaranteed to
7303 have emitted an FRP frame pointer update just before. */
7304 RTX_FRAME_RELATED_P (seq) = ! frame_pointer_needed;
7307 else if (!TARGET_ABI_UNICOSMK)
7309 /* If we need a frame pointer, set it from the stack pointer. */
7310 if (frame_pointer_needed)
7312 if (TARGET_CAN_FAULT_IN_PROLOGUE)
7313 FRP (emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx));
7314 else
7315 /* This must always be the last instruction in the
7316 prologue, thus we emit a special move + clobber. */
7317 FRP (emit_insn (gen_init_fp (hard_frame_pointer_rtx,
7318 stack_pointer_rtx, sa_reg)));
7322 /* The ABIs for VMS and OSF/1 say that while we can schedule insns into
7323 the prologue, for exception handling reasons, we cannot do this for
7324 any insn that might fault. We could prevent this for mems with a
7325 (clobber:BLK (scratch)), but this doesn't work for fp insns. So we
7326 have to prevent all such scheduling with a blockage.
7328 Linux, on the other hand, never bothered to implement OSF/1's
7329 exception handling, and so doesn't care about such things. Anyone
7330 planning to use dwarf2 frame-unwind info can also omit the blockage. */
7332 if (! TARGET_CAN_FAULT_IN_PROLOGUE)
7333 emit_insn (gen_blockage ());
7336 /* Output the textual info surrounding the prologue. */
7338 void
7339 alpha_start_function (FILE *file, const char *fnname,
7340 tree decl ATTRIBUTE_UNUSED)
7342 unsigned long imask = 0;
7343 unsigned long fmask = 0;
7344 /* Stack space needed for pushing registers clobbered by us. */
7345 HOST_WIDE_INT sa_size;
7346 /* Complete stack size needed. */
7347 unsigned HOST_WIDE_INT frame_size;
7348 /* Offset from base reg to register save area. */
7349 HOST_WIDE_INT reg_offset;
7350 char *entry_label = (char *) alloca (strlen (fnname) + 6);
7351 int i;
7353 /* Don't emit an extern directive for functions defined in the same file. */
7354 if (TARGET_ABI_UNICOSMK)
7356 tree name_tree;
7357 name_tree = get_identifier (fnname);
7358 TREE_ASM_WRITTEN (name_tree) = 1;
7361 alpha_fnname = fnname;
7362 sa_size = alpha_sa_size ();
7364 frame_size = get_frame_size ();
7365 if (TARGET_ABI_OPEN_VMS)
7366 frame_size = ALPHA_ROUND (sa_size
7367 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7368 + frame_size
7369 + current_function_pretend_args_size);
7370 else if (TARGET_ABI_UNICOSMK)
7371 frame_size = ALPHA_ROUND (sa_size
7372 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7373 + ALPHA_ROUND (frame_size
7374 + current_function_outgoing_args_size);
7375 else
7376 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7377 + sa_size
7378 + ALPHA_ROUND (frame_size
7379 + current_function_pretend_args_size));
7381 if (TARGET_ABI_OPEN_VMS)
7382 reg_offset = 8;
7383 else
7384 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7386 alpha_sa_mask (&imask, &fmask);
7388 /* Ecoff can handle multiple .file directives, so put out file and lineno.
7389 We have to do that before the .ent directive as we cannot switch
7390 files within procedures with native ecoff because line numbers are
7391 linked to procedure descriptors.
7392 Outputting the lineno helps debugging of one line functions as they
7393 would otherwise get no line number at all. Please note that we would
7394 like to put out last_linenum from final.c, but it is not accessible. */
7396 if (write_symbols == SDB_DEBUG)
7398 #ifdef ASM_OUTPUT_SOURCE_FILENAME
7399 ASM_OUTPUT_SOURCE_FILENAME (file,
7400 DECL_SOURCE_FILE (current_function_decl));
7401 #endif
7402 #ifdef ASM_OUTPUT_SOURCE_LINE
7403 if (debug_info_level != DINFO_LEVEL_TERSE)
7404 ASM_OUTPUT_SOURCE_LINE (file,
7405 DECL_SOURCE_LINE (current_function_decl), 0);
7406 #endif
7409 /* Issue function start and label. */
7410 if (TARGET_ABI_OPEN_VMS
7411 || (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive))
7413 fputs ("\t.ent ", file);
7414 assemble_name (file, fnname);
7415 putc ('\n', file);
7417 /* If the function needs GP, we'll write the "..ng" label there.
7418 Otherwise, do it here. */
7419 if (TARGET_ABI_OSF
7420 && ! alpha_function_needs_gp
7421 && ! current_function_is_thunk)
7423 putc ('$', file);
7424 assemble_name (file, fnname);
7425 fputs ("..ng:\n", file);
7429 strcpy (entry_label, fnname);
7430 if (TARGET_ABI_OPEN_VMS)
7431 strcat (entry_label, "..en");
7433 /* For public functions, the label must be globalized by appending an
7434 additional colon. */
7435 if (TARGET_ABI_UNICOSMK && TREE_PUBLIC (decl))
7436 strcat (entry_label, ":");
7438 ASM_OUTPUT_LABEL (file, entry_label);
7439 inside_function = TRUE;
7441 if (TARGET_ABI_OPEN_VMS)
7442 fprintf (file, "\t.base $%d\n", vms_base_regno);
7444 if (!TARGET_ABI_OPEN_VMS && !TARGET_ABI_UNICOSMK && TARGET_IEEE_CONFORMANT
7445 && !flag_inhibit_size_directive)
7447 /* Set flags in procedure descriptor to request IEEE-conformant
7448 math-library routines. The value we set it to is PDSC_EXC_IEEE
7449 (/usr/include/pdsc.h). */
7450 fputs ("\t.eflag 48\n", file);
7453 /* Set up offsets to alpha virtual arg/local debugging pointer. */
7454 alpha_auto_offset = -frame_size + current_function_pretend_args_size;
7455 alpha_arg_offset = -frame_size + 48;
7457 /* Describe our frame. If the frame size is larger than an integer,
7458 print it as zero to avoid an assembler error. We won't be
7459 properly describing such a frame, but that's the best we can do. */
7460 if (TARGET_ABI_UNICOSMK)
7462 else if (TARGET_ABI_OPEN_VMS)
7463 fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,"
7464 HOST_WIDE_INT_PRINT_DEC "\n",
7465 vms_unwind_regno,
7466 frame_size >= (1UL << 31) ? 0 : frame_size,
7467 reg_offset);
7468 else if (!flag_inhibit_size_directive)
7469 fprintf (file, "\t.frame $%d," HOST_WIDE_INT_PRINT_DEC ",$26,%d\n",
7470 (frame_pointer_needed
7471 ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM),
7472 frame_size >= (1UL << 31) ? 0 : frame_size,
7473 current_function_pretend_args_size);
7475 /* Describe which registers were spilled. */
7476 if (TARGET_ABI_UNICOSMK)
7478 else if (TARGET_ABI_OPEN_VMS)
7480 if (imask)
7481 /* ??? Does VMS care if mask contains ra? The old code didn't
7482 set it, so I don't here. */
7483 fprintf (file, "\t.mask 0x%lx,0\n", imask & ~(1UL << REG_RA));
7484 if (fmask)
7485 fprintf (file, "\t.fmask 0x%lx,0\n", fmask);
7486 if (alpha_procedure_type == PT_REGISTER)
7487 fprintf (file, "\t.fp_save $%d\n", vms_save_fp_regno);
7489 else if (!flag_inhibit_size_directive)
7491 if (imask)
7493 fprintf (file, "\t.mask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", imask,
7494 frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7496 for (i = 0; i < 32; ++i)
7497 if (imask & (1UL << i))
7498 reg_offset += 8;
7501 if (fmask)
7502 fprintf (file, "\t.fmask 0x%lx," HOST_WIDE_INT_PRINT_DEC "\n", fmask,
7503 frame_size >= (1UL << 31) ? 0 : reg_offset - frame_size);
7506 #if TARGET_ABI_OPEN_VMS
7507 /* Ifdef'ed cause link_section are only available then. */
7508 readonly_data_section ();
7509 fprintf (file, "\t.align 3\n");
7510 assemble_name (file, fnname); fputs ("..na:\n", file);
7511 fputs ("\t.ascii \"", file);
7512 assemble_name (file, fnname);
7513 fputs ("\\0\"\n", file);
7514 alpha_need_linkage (fnname, 1);
7515 text_section ();
7516 #endif
7519 /* Emit the .prologue note at the scheduled end of the prologue. */
7521 static void
7522 alpha_output_function_end_prologue (FILE *file)
7524 if (TARGET_ABI_UNICOSMK)
7526 else if (TARGET_ABI_OPEN_VMS)
7527 fputs ("\t.prologue\n", file);
7528 else if (TARGET_ABI_WINDOWS_NT)
7529 fputs ("\t.prologue 0\n", file);
7530 else if (!flag_inhibit_size_directive)
7531 fprintf (file, "\t.prologue %d\n",
7532 alpha_function_needs_gp || current_function_is_thunk);
7535 /* Write function epilogue. */
7537 /* ??? At some point we will want to support full unwind, and so will
7538 need to mark the epilogue as well. At the moment, we just confuse
7539 dwarf2out. */
7540 #undef FRP
7541 #define FRP(exp) exp
7543 void
7544 alpha_expand_epilogue (void)
7546 /* Registers to save. */
7547 unsigned long imask = 0;
7548 unsigned long fmask = 0;
7549 /* Stack space needed for pushing registers clobbered by us. */
7550 HOST_WIDE_INT sa_size;
7551 /* Complete stack size needed. */
7552 HOST_WIDE_INT frame_size;
7553 /* Offset from base reg to register save area. */
7554 HOST_WIDE_INT reg_offset;
7555 int fp_is_frame_pointer, fp_offset;
7556 rtx sa_reg, sa_reg_exp = NULL;
7557 rtx sp_adj1, sp_adj2, mem;
7558 rtx eh_ofs;
7559 int i;
7561 sa_size = alpha_sa_size ();
7563 frame_size = get_frame_size ();
7564 if (TARGET_ABI_OPEN_VMS)
7565 frame_size = ALPHA_ROUND (sa_size
7566 + (alpha_procedure_type == PT_STACK ? 8 : 0)
7567 + frame_size
7568 + current_function_pretend_args_size);
7569 else if (TARGET_ABI_UNICOSMK)
7570 frame_size = ALPHA_ROUND (sa_size
7571 + (alpha_procedure_type == PT_STACK ? 48 : 0))
7572 + ALPHA_ROUND (frame_size
7573 + current_function_outgoing_args_size);
7574 else
7575 frame_size = (ALPHA_ROUND (current_function_outgoing_args_size)
7576 + sa_size
7577 + ALPHA_ROUND (frame_size
7578 + current_function_pretend_args_size));
7580 if (TARGET_ABI_OPEN_VMS)
7582 if (alpha_procedure_type == PT_STACK)
7583 reg_offset = 8;
7584 else
7585 reg_offset = 0;
7587 else
7588 reg_offset = ALPHA_ROUND (current_function_outgoing_args_size);
7590 alpha_sa_mask (&imask, &fmask);
7592 fp_is_frame_pointer
7593 = ((TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_STACK)
7594 || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed));
7595 fp_offset = 0;
7596 sa_reg = stack_pointer_rtx;
7598 if (current_function_calls_eh_return)
7599 eh_ofs = EH_RETURN_STACKADJ_RTX;
7600 else
7601 eh_ofs = NULL_RTX;
7603 if (!TARGET_ABI_UNICOSMK && sa_size)
7605 /* If we have a frame pointer, restore SP from it. */
7606 if ((TARGET_ABI_OPEN_VMS
7607 && vms_unwind_regno == HARD_FRAME_POINTER_REGNUM)
7608 || (!TARGET_ABI_OPEN_VMS && frame_pointer_needed))
7609 FRP (emit_move_insn (stack_pointer_rtx, hard_frame_pointer_rtx));
7611 /* Cope with very large offsets to the register save area. */
7612 if (reg_offset + sa_size > 0x8000)
7614 int low = ((reg_offset & 0xffff) ^ 0x8000) - 0x8000;
7615 HOST_WIDE_INT bias;
7617 if (low + sa_size <= 0x8000)
7618 bias = reg_offset - low, reg_offset = low;
7619 else
7620 bias = reg_offset, reg_offset = 0;
7622 sa_reg = gen_rtx_REG (DImode, 22);
7623 sa_reg_exp = plus_constant (stack_pointer_rtx, bias);
7625 FRP (emit_move_insn (sa_reg, sa_reg_exp));
7628 /* Restore registers in order, excepting a true frame pointer. */
7630 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, reg_offset));
7631 if (! eh_ofs)
7632 set_mem_alias_set (mem, alpha_sr_alias_set);
7633 FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7635 reg_offset += 8;
7636 imask &= ~(1UL << REG_RA);
7638 for (i = 0; i < 31; ++i)
7639 if (imask & (1UL << i))
7641 if (i == HARD_FRAME_POINTER_REGNUM && fp_is_frame_pointer)
7642 fp_offset = reg_offset;
7643 else
7645 mem = gen_rtx_MEM (DImode, plus_constant(sa_reg, reg_offset));
7646 set_mem_alias_set (mem, alpha_sr_alias_set);
7647 FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7649 reg_offset += 8;
7652 if (imask & (1UL << 31))
7653 reg_offset += 8;
7655 for (i = 0; i < 31; ++i)
7656 if (fmask & (1UL << i))
7658 mem = gen_rtx_MEM (DFmode, plus_constant(sa_reg, reg_offset));
7659 set_mem_alias_set (mem, alpha_sr_alias_set);
7660 FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7661 reg_offset += 8;
7664 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type == PT_STACK)
7666 /* Restore callee-saved general-purpose registers. */
7668 reg_offset = -56;
7670 for (i = 9; i < 15; i++)
7671 if (imask & (1UL << i))
7673 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx,
7674 reg_offset));
7675 set_mem_alias_set (mem, alpha_sr_alias_set);
7676 FRP (emit_move_insn (gen_rtx_REG (DImode, i), mem));
7677 reg_offset -= 8;
7680 for (i = 2; i < 10; i++)
7681 if (fmask & (1UL << i))
7683 mem = gen_rtx_MEM (DFmode, plus_constant(hard_frame_pointer_rtx,
7684 reg_offset));
7685 set_mem_alias_set (mem, alpha_sr_alias_set);
7686 FRP (emit_move_insn (gen_rtx_REG (DFmode, i+32), mem));
7687 reg_offset -= 8;
7690 /* Restore the return address from the DSIB. */
7692 mem = gen_rtx_MEM (DImode, plus_constant(hard_frame_pointer_rtx, -8));
7693 set_mem_alias_set (mem, alpha_sr_alias_set);
7694 FRP (emit_move_insn (gen_rtx_REG (DImode, REG_RA), mem));
7697 if (frame_size || eh_ofs)
7699 sp_adj1 = stack_pointer_rtx;
7701 if (eh_ofs)
7703 sp_adj1 = gen_rtx_REG (DImode, 23);
7704 emit_move_insn (sp_adj1,
7705 gen_rtx_PLUS (Pmode, stack_pointer_rtx, eh_ofs));
7708 /* If the stack size is large, begin computation into a temporary
7709 register so as not to interfere with a potential fp restore,
7710 which must be consecutive with an SP restore. */
7711 if (frame_size < 32768
7712 && ! (TARGET_ABI_UNICOSMK && current_function_calls_alloca))
7713 sp_adj2 = GEN_INT (frame_size);
7714 else if (TARGET_ABI_UNICOSMK)
7716 sp_adj1 = gen_rtx_REG (DImode, 23);
7717 FRP (emit_move_insn (sp_adj1, hard_frame_pointer_rtx));
7718 sp_adj2 = const0_rtx;
7720 else if (frame_size < 0x40007fffL)
7722 int low = ((frame_size & 0xffff) ^ 0x8000) - 0x8000;
7724 sp_adj2 = plus_constant (sp_adj1, frame_size - low);
7725 if (sa_reg_exp && rtx_equal_p (sa_reg_exp, sp_adj2))
7726 sp_adj1 = sa_reg;
7727 else
7729 sp_adj1 = gen_rtx_REG (DImode, 23);
7730 FRP (emit_move_insn (sp_adj1, sp_adj2));
7732 sp_adj2 = GEN_INT (low);
7734 else
7736 rtx tmp = gen_rtx_REG (DImode, 23);
7737 FRP (sp_adj2 = alpha_emit_set_const (tmp, DImode, frame_size, 3));
7738 if (!sp_adj2)
7740 /* We can't drop new things to memory this late, afaik,
7741 so build it up by pieces. */
7742 FRP (sp_adj2 = alpha_emit_set_long_const (tmp, frame_size,
7743 -(frame_size < 0)));
7744 if (!sp_adj2)
7745 abort ();
7749 /* From now on, things must be in order. So emit blockages. */
7751 /* Restore the frame pointer. */
7752 if (TARGET_ABI_UNICOSMK)
7754 emit_insn (gen_blockage ());
7755 mem = gen_rtx_MEM (DImode,
7756 plus_constant (hard_frame_pointer_rtx, -16));
7757 set_mem_alias_set (mem, alpha_sr_alias_set);
7758 FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7760 else if (fp_is_frame_pointer)
7762 emit_insn (gen_blockage ());
7763 mem = gen_rtx_MEM (DImode, plus_constant (sa_reg, fp_offset));
7764 set_mem_alias_set (mem, alpha_sr_alias_set);
7765 FRP (emit_move_insn (hard_frame_pointer_rtx, mem));
7767 else if (TARGET_ABI_OPEN_VMS)
7769 emit_insn (gen_blockage ());
7770 FRP (emit_move_insn (hard_frame_pointer_rtx,
7771 gen_rtx_REG (DImode, vms_save_fp_regno)));
7774 /* Restore the stack pointer. */
7775 emit_insn (gen_blockage ());
7776 if (sp_adj2 == const0_rtx)
7777 FRP (emit_move_insn (stack_pointer_rtx, sp_adj1));
7778 else
7779 FRP (emit_move_insn (stack_pointer_rtx,
7780 gen_rtx_PLUS (DImode, sp_adj1, sp_adj2)));
7782 else
7784 if (TARGET_ABI_OPEN_VMS && alpha_procedure_type == PT_REGISTER)
7786 emit_insn (gen_blockage ());
7787 FRP (emit_move_insn (hard_frame_pointer_rtx,
7788 gen_rtx_REG (DImode, vms_save_fp_regno)));
7790 else if (TARGET_ABI_UNICOSMK && alpha_procedure_type != PT_STACK)
7792 /* Decrement the frame pointer if the function does not have a
7793 frame. */
7795 emit_insn (gen_blockage ());
7796 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
7797 hard_frame_pointer_rtx, constm1_rtx)));
7802 /* Output the rest of the textual info surrounding the epilogue. */
7804 void
7805 alpha_end_function (FILE *file, const char *fnname, tree decl ATTRIBUTE_UNUSED)
7807 #if TARGET_ABI_OPEN_VMS
7808 alpha_write_linkage (file, fnname, decl);
7809 #endif
7811 /* End the function. */
7812 if (!TARGET_ABI_UNICOSMK && !flag_inhibit_size_directive)
7814 fputs ("\t.end ", file);
7815 assemble_name (file, fnname);
7816 putc ('\n', file);
7818 inside_function = FALSE;
7820 /* Output jump tables and the static subroutine information block. */
7821 if (TARGET_ABI_UNICOSMK)
7823 unicosmk_output_ssib (file, fnname);
7824 unicosmk_output_deferred_case_vectors (file);
7828 #if TARGET_ABI_OSF
7829 /* Emit a tail call to FUNCTION after adjusting THIS by DELTA.
7831 In order to avoid the hordes of differences between generated code
7832 with and without TARGET_EXPLICIT_RELOCS, and to avoid duplicating
7833 lots of code loading up large constants, generate rtl and emit it
7834 instead of going straight to text.
7836 Not sure why this idea hasn't been explored before... */
7838 static void
7839 alpha_output_mi_thunk_osf (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
7840 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
7841 tree function)
7843 HOST_WIDE_INT hi, lo;
7844 rtx this, insn, funexp;
7846 reset_block_changes ();
7848 /* We always require a valid GP. */
7849 emit_insn (gen_prologue_ldgp ());
7850 emit_note (NOTE_INSN_PROLOGUE_END);
7852 /* Find the "this" pointer. If the function returns a structure,
7853 the structure return pointer is in $16. */
7854 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
7855 this = gen_rtx_REG (Pmode, 17);
7856 else
7857 this = gen_rtx_REG (Pmode, 16);
7859 /* Add DELTA. When possible we use ldah+lda. Otherwise load the
7860 entire constant for the add. */
7861 lo = ((delta & 0xffff) ^ 0x8000) - 0x8000;
7862 hi = (((delta - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7863 if (hi + lo == delta)
7865 if (hi)
7866 emit_insn (gen_adddi3 (this, this, GEN_INT (hi)));
7867 if (lo)
7868 emit_insn (gen_adddi3 (this, this, GEN_INT (lo)));
7870 else
7872 rtx tmp = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 0),
7873 delta, -(delta < 0));
7874 emit_insn (gen_adddi3 (this, this, tmp));
7877 /* Add a delta stored in the vtable at VCALL_OFFSET. */
7878 if (vcall_offset)
7880 rtx tmp, tmp2;
7882 tmp = gen_rtx_REG (Pmode, 0);
7883 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
7885 lo = ((vcall_offset & 0xffff) ^ 0x8000) - 0x8000;
7886 hi = (((vcall_offset - lo) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7887 if (hi + lo == vcall_offset)
7889 if (hi)
7890 emit_insn (gen_adddi3 (tmp, tmp, GEN_INT (hi)));
7892 else
7894 tmp2 = alpha_emit_set_long_const (gen_rtx_REG (Pmode, 1),
7895 vcall_offset, -(vcall_offset < 0));
7896 emit_insn (gen_adddi3 (tmp, tmp, tmp2));
7897 lo = 0;
7899 if (lo)
7900 tmp2 = gen_rtx_PLUS (Pmode, tmp, GEN_INT (lo));
7901 else
7902 tmp2 = tmp;
7903 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp2));
7905 emit_insn (gen_adddi3 (this, this, tmp));
7908 /* Generate a tail call to the target function. */
7909 if (! TREE_USED (function))
7911 assemble_external (function);
7912 TREE_USED (function) = 1;
7914 funexp = XEXP (DECL_RTL (function), 0);
7915 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
7916 insn = emit_call_insn (gen_sibcall (funexp, const0_rtx));
7917 SIBLING_CALL_P (insn) = 1;
7919 /* Run just enough of rest_of_compilation to get the insns emitted.
7920 There's not really enough bulk here to make other passes such as
7921 instruction scheduling worth while. Note that use_thunk calls
7922 assemble_start_function and assemble_end_function. */
7923 insn = get_insns ();
7924 insn_locators_initialize ();
7925 shorten_branches (insn);
7926 final_start_function (insn, file, 1);
7927 final (insn, file, 1, 0);
7928 final_end_function ();
7930 #endif /* TARGET_ABI_OSF */
7932 /* Debugging support. */
7934 #include "gstab.h"
7936 /* Count the number of sdb related labels are generated (to find block
7937 start and end boundaries). */
7939 int sdb_label_count = 0;
7941 /* Next label # for each statement. */
7943 static int sym_lineno = 0;
7945 /* Count the number of .file directives, so that .loc is up to date. */
7947 static int num_source_filenames = 0;
7949 /* Name of the file containing the current function. */
7951 static const char *current_function_file = "";
7953 /* Offsets to alpha virtual arg/local debugging pointers. */
7955 long alpha_arg_offset;
7956 long alpha_auto_offset;
7958 /* Emit a new filename to a stream. */
7960 void
7961 alpha_output_filename (FILE *stream, const char *name)
7963 static int first_time = TRUE;
7964 char ltext_label_name[100];
7966 if (first_time)
7968 first_time = FALSE;
7969 ++num_source_filenames;
7970 current_function_file = name;
7971 fprintf (stream, "\t.file\t%d ", num_source_filenames);
7972 output_quoted_string (stream, name);
7973 fprintf (stream, "\n");
7974 if (!TARGET_GAS && write_symbols == DBX_DEBUG)
7975 fprintf (stream, "\t#@stabs\n");
7978 else if (write_symbols == DBX_DEBUG)
7980 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
7981 fprintf (stream, "%s", ASM_STABS_OP);
7982 output_quoted_string (stream, name);
7983 fprintf (stream, ",%d,0,0,%s\n", N_SOL, &ltext_label_name[1]);
7986 else if (name != current_function_file
7987 && strcmp (name, current_function_file) != 0)
7989 if (inside_function && ! TARGET_GAS)
7990 fprintf (stream, "\t#.file\t%d ", num_source_filenames);
7991 else
7993 ++num_source_filenames;
7994 current_function_file = name;
7995 fprintf (stream, "\t.file\t%d ", num_source_filenames);
7998 output_quoted_string (stream, name);
7999 fprintf (stream, "\n");
8003 /* Emit a linenumber to a stream. */
8005 void
8006 alpha_output_lineno (FILE *stream, int line)
8008 if (write_symbols == DBX_DEBUG)
8010 /* mips-tfile doesn't understand .stabd directives. */
8011 ++sym_lineno;
8012 fprintf (stream, "$LM%d:\n%s%d,0,%d,$LM%d\n",
8013 sym_lineno, ASM_STABN_OP, N_SLINE, line, sym_lineno);
8015 else
8016 fprintf (stream, "\n\t.loc\t%d %d\n", num_source_filenames, line);
8019 /* Structure to show the current status of registers and memory. */
8021 struct shadow_summary
8023 struct {
8024 unsigned int i : 31; /* Mask of int regs */
8025 unsigned int fp : 31; /* Mask of fp regs */
8026 unsigned int mem : 1; /* mem == imem | fpmem */
8027 } used, defd;
8030 /* Summary the effects of expression X on the machine. Update SUM, a pointer
8031 to the summary structure. SET is nonzero if the insn is setting the
8032 object, otherwise zero. */
8034 static void
8035 summarize_insn (rtx x, struct shadow_summary *sum, int set)
8037 const char *format_ptr;
8038 int i, j;
8040 if (x == 0)
8041 return;
8043 switch (GET_CODE (x))
8045 /* ??? Note that this case would be incorrect if the Alpha had a
8046 ZERO_EXTRACT in SET_DEST. */
8047 case SET:
8048 summarize_insn (SET_SRC (x), sum, 0);
8049 summarize_insn (SET_DEST (x), sum, 1);
8050 break;
8052 case CLOBBER:
8053 summarize_insn (XEXP (x, 0), sum, 1);
8054 break;
8056 case USE:
8057 summarize_insn (XEXP (x, 0), sum, 0);
8058 break;
8060 case ASM_OPERANDS:
8061 for (i = ASM_OPERANDS_INPUT_LENGTH (x) - 1; i >= 0; i--)
8062 summarize_insn (ASM_OPERANDS_INPUT (x, i), sum, 0);
8063 break;
8065 case PARALLEL:
8066 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
8067 summarize_insn (XVECEXP (x, 0, i), sum, 0);
8068 break;
8070 case SUBREG:
8071 summarize_insn (SUBREG_REG (x), sum, 0);
8072 break;
8074 case REG:
8076 int regno = REGNO (x);
8077 unsigned long mask = ((unsigned long) 1) << (regno % 32);
8079 if (regno == 31 || regno == 63)
8080 break;
8082 if (set)
8084 if (regno < 32)
8085 sum->defd.i |= mask;
8086 else
8087 sum->defd.fp |= mask;
8089 else
8091 if (regno < 32)
8092 sum->used.i |= mask;
8093 else
8094 sum->used.fp |= mask;
8097 break;
8099 case MEM:
8100 if (set)
8101 sum->defd.mem = 1;
8102 else
8103 sum->used.mem = 1;
8105 /* Find the regs used in memory address computation: */
8106 summarize_insn (XEXP (x, 0), sum, 0);
8107 break;
8109 case CONST_INT: case CONST_DOUBLE:
8110 case SYMBOL_REF: case LABEL_REF: case CONST:
8111 case SCRATCH: case ASM_INPUT:
8112 break;
8114 /* Handle common unary and binary ops for efficiency. */
8115 case COMPARE: case PLUS: case MINUS: case MULT: case DIV:
8116 case MOD: case UDIV: case UMOD: case AND: case IOR:
8117 case XOR: case ASHIFT: case ROTATE: case ASHIFTRT: case LSHIFTRT:
8118 case ROTATERT: case SMIN: case SMAX: case UMIN: case UMAX:
8119 case NE: case EQ: case GE: case GT: case LE:
8120 case LT: case GEU: case GTU: case LEU: case LTU:
8121 summarize_insn (XEXP (x, 0), sum, 0);
8122 summarize_insn (XEXP (x, 1), sum, 0);
8123 break;
8125 case NEG: case NOT: case SIGN_EXTEND: case ZERO_EXTEND:
8126 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: case FLOAT:
8127 case FIX: case UNSIGNED_FLOAT: case UNSIGNED_FIX: case ABS:
8128 case SQRT: case FFS:
8129 summarize_insn (XEXP (x, 0), sum, 0);
8130 break;
8132 default:
8133 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
8134 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
8135 switch (format_ptr[i])
8137 case 'e':
8138 summarize_insn (XEXP (x, i), sum, 0);
8139 break;
8141 case 'E':
8142 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
8143 summarize_insn (XVECEXP (x, i, j), sum, 0);
8144 break;
8146 case 'i':
8147 break;
8149 default:
8150 abort ();
8155 /* Ensure a sufficient number of `trapb' insns are in the code when
8156 the user requests code with a trap precision of functions or
8157 instructions.
8159 In naive mode, when the user requests a trap-precision of
8160 "instruction", a trapb is needed after every instruction that may
8161 generate a trap. This ensures that the code is resumption safe but
8162 it is also slow.
8164 When optimizations are turned on, we delay issuing a trapb as long
8165 as possible. In this context, a trap shadow is the sequence of
8166 instructions that starts with a (potentially) trap generating
8167 instruction and extends to the next trapb or call_pal instruction
8168 (but GCC never generates call_pal by itself). We can delay (and
8169 therefore sometimes omit) a trapb subject to the following
8170 conditions:
8172 (a) On entry to the trap shadow, if any Alpha register or memory
8173 location contains a value that is used as an operand value by some
8174 instruction in the trap shadow (live on entry), then no instruction
8175 in the trap shadow may modify the register or memory location.
8177 (b) Within the trap shadow, the computation of the base register
8178 for a memory load or store instruction may not involve using the
8179 result of an instruction that might generate an UNPREDICTABLE
8180 result.
8182 (c) Within the trap shadow, no register may be used more than once
8183 as a destination register. (This is to make life easier for the
8184 trap-handler.)
8186 (d) The trap shadow may not include any branch instructions. */
8188 static void
8189 alpha_handle_trap_shadows (void)
8191 struct shadow_summary shadow;
8192 int trap_pending, exception_nesting;
8193 rtx i, n;
8195 trap_pending = 0;
8196 exception_nesting = 0;
8197 shadow.used.i = 0;
8198 shadow.used.fp = 0;
8199 shadow.used.mem = 0;
8200 shadow.defd = shadow.used;
8202 for (i = get_insns (); i ; i = NEXT_INSN (i))
8204 if (GET_CODE (i) == NOTE)
8206 switch (NOTE_LINE_NUMBER (i))
8208 case NOTE_INSN_EH_REGION_BEG:
8209 exception_nesting++;
8210 if (trap_pending)
8211 goto close_shadow;
8212 break;
8214 case NOTE_INSN_EH_REGION_END:
8215 exception_nesting--;
8216 if (trap_pending)
8217 goto close_shadow;
8218 break;
8220 case NOTE_INSN_EPILOGUE_BEG:
8221 if (trap_pending && alpha_tp >= ALPHA_TP_FUNC)
8222 goto close_shadow;
8223 break;
8226 else if (trap_pending)
8228 if (alpha_tp == ALPHA_TP_FUNC)
8230 if (GET_CODE (i) == JUMP_INSN
8231 && GET_CODE (PATTERN (i)) == RETURN)
8232 goto close_shadow;
8234 else if (alpha_tp == ALPHA_TP_INSN)
8236 if (optimize > 0)
8238 struct shadow_summary sum;
8240 sum.used.i = 0;
8241 sum.used.fp = 0;
8242 sum.used.mem = 0;
8243 sum.defd = sum.used;
8245 switch (GET_CODE (i))
8247 case INSN:
8248 /* Annoyingly, get_attr_trap will abort on these. */
8249 if (GET_CODE (PATTERN (i)) == USE
8250 || GET_CODE (PATTERN (i)) == CLOBBER)
8251 break;
8253 summarize_insn (PATTERN (i), &sum, 0);
8255 if ((sum.defd.i & shadow.defd.i)
8256 || (sum.defd.fp & shadow.defd.fp))
8258 /* (c) would be violated */
8259 goto close_shadow;
8262 /* Combine shadow with summary of current insn: */
8263 shadow.used.i |= sum.used.i;
8264 shadow.used.fp |= sum.used.fp;
8265 shadow.used.mem |= sum.used.mem;
8266 shadow.defd.i |= sum.defd.i;
8267 shadow.defd.fp |= sum.defd.fp;
8268 shadow.defd.mem |= sum.defd.mem;
8270 if ((sum.defd.i & shadow.used.i)
8271 || (sum.defd.fp & shadow.used.fp)
8272 || (sum.defd.mem & shadow.used.mem))
8274 /* (a) would be violated (also takes care of (b)) */
8275 if (get_attr_trap (i) == TRAP_YES
8276 && ((sum.defd.i & sum.used.i)
8277 || (sum.defd.fp & sum.used.fp)))
8278 abort ();
8280 goto close_shadow;
8282 break;
8284 case JUMP_INSN:
8285 case CALL_INSN:
8286 case CODE_LABEL:
8287 goto close_shadow;
8289 default:
8290 abort ();
8293 else
8295 close_shadow:
8296 n = emit_insn_before (gen_trapb (), i);
8297 PUT_MODE (n, TImode);
8298 PUT_MODE (i, TImode);
8299 trap_pending = 0;
8300 shadow.used.i = 0;
8301 shadow.used.fp = 0;
8302 shadow.used.mem = 0;
8303 shadow.defd = shadow.used;
8308 if ((exception_nesting > 0 || alpha_tp >= ALPHA_TP_FUNC)
8309 && GET_CODE (i) == INSN
8310 && GET_CODE (PATTERN (i)) != USE
8311 && GET_CODE (PATTERN (i)) != CLOBBER
8312 && get_attr_trap (i) == TRAP_YES)
8314 if (optimize && !trap_pending)
8315 summarize_insn (PATTERN (i), &shadow, 0);
8316 trap_pending = 1;
8321 /* Alpha can only issue instruction groups simultaneously if they are
8322 suitably aligned. This is very processor-specific. */
8324 enum alphaev4_pipe {
8325 EV4_STOP = 0,
8326 EV4_IB0 = 1,
8327 EV4_IB1 = 2,
8328 EV4_IBX = 4
8331 enum alphaev5_pipe {
8332 EV5_STOP = 0,
8333 EV5_NONE = 1,
8334 EV5_E01 = 2,
8335 EV5_E0 = 4,
8336 EV5_E1 = 8,
8337 EV5_FAM = 16,
8338 EV5_FA = 32,
8339 EV5_FM = 64
8342 static enum alphaev4_pipe
8343 alphaev4_insn_pipe (rtx insn)
8345 if (recog_memoized (insn) < 0)
8346 return EV4_STOP;
8347 if (get_attr_length (insn) != 4)
8348 return EV4_STOP;
8350 switch (get_attr_type (insn))
8352 case TYPE_ILD:
8353 case TYPE_FLD:
8354 return EV4_IBX;
8356 case TYPE_LDSYM:
8357 case TYPE_IADD:
8358 case TYPE_ILOG:
8359 case TYPE_ICMOV:
8360 case TYPE_ICMP:
8361 case TYPE_IST:
8362 case TYPE_FST:
8363 case TYPE_SHIFT:
8364 case TYPE_IMUL:
8365 case TYPE_FBR:
8366 return EV4_IB0;
8368 case TYPE_MISC:
8369 case TYPE_IBR:
8370 case TYPE_JSR:
8371 case TYPE_CALLPAL:
8372 case TYPE_FCPYS:
8373 case TYPE_FCMOV:
8374 case TYPE_FADD:
8375 case TYPE_FDIV:
8376 case TYPE_FMUL:
8377 return EV4_IB1;
8379 default:
8380 abort ();
8384 static enum alphaev5_pipe
8385 alphaev5_insn_pipe (rtx insn)
8387 if (recog_memoized (insn) < 0)
8388 return EV5_STOP;
8389 if (get_attr_length (insn) != 4)
8390 return EV5_STOP;
8392 switch (get_attr_type (insn))
8394 case TYPE_ILD:
8395 case TYPE_FLD:
8396 case TYPE_LDSYM:
8397 case TYPE_IADD:
8398 case TYPE_ILOG:
8399 case TYPE_ICMOV:
8400 case TYPE_ICMP:
8401 return EV5_E01;
8403 case TYPE_IST:
8404 case TYPE_FST:
8405 case TYPE_SHIFT:
8406 case TYPE_IMUL:
8407 case TYPE_MISC:
8408 case TYPE_MVI:
8409 return EV5_E0;
8411 case TYPE_IBR:
8412 case TYPE_JSR:
8413 case TYPE_CALLPAL:
8414 return EV5_E1;
8416 case TYPE_FCPYS:
8417 return EV5_FAM;
8419 case TYPE_FBR:
8420 case TYPE_FCMOV:
8421 case TYPE_FADD:
8422 case TYPE_FDIV:
8423 return EV5_FA;
8425 case TYPE_FMUL:
8426 return EV5_FM;
8428 default:
8429 abort();
8433 /* IN_USE is a mask of the slots currently filled within the insn group.
8434 The mask bits come from alphaev4_pipe above. If EV4_IBX is set, then
8435 the insn in EV4_IB0 can be swapped by the hardware into EV4_IB1.
8437 LEN is, of course, the length of the group in bytes. */
8439 static rtx
8440 alphaev4_next_group (rtx insn, int *pin_use, int *plen)
8442 int len, in_use;
8444 len = in_use = 0;
8446 if (! INSN_P (insn)
8447 || GET_CODE (PATTERN (insn)) == CLOBBER
8448 || GET_CODE (PATTERN (insn)) == USE)
8449 goto next_and_done;
8451 while (1)
8453 enum alphaev4_pipe pipe;
8455 pipe = alphaev4_insn_pipe (insn);
8456 switch (pipe)
8458 case EV4_STOP:
8459 /* Force complex instructions to start new groups. */
8460 if (in_use)
8461 goto done;
8463 /* If this is a completely unrecognized insn, its an asm.
8464 We don't know how long it is, so record length as -1 to
8465 signal a needed realignment. */
8466 if (recog_memoized (insn) < 0)
8467 len = -1;
8468 else
8469 len = get_attr_length (insn);
8470 goto next_and_done;
8472 case EV4_IBX:
8473 if (in_use & EV4_IB0)
8475 if (in_use & EV4_IB1)
8476 goto done;
8477 in_use |= EV4_IB1;
8479 else
8480 in_use |= EV4_IB0 | EV4_IBX;
8481 break;
8483 case EV4_IB0:
8484 if (in_use & EV4_IB0)
8486 if (!(in_use & EV4_IBX) || (in_use & EV4_IB1))
8487 goto done;
8488 in_use |= EV4_IB1;
8490 in_use |= EV4_IB0;
8491 break;
8493 case EV4_IB1:
8494 if (in_use & EV4_IB1)
8495 goto done;
8496 in_use |= EV4_IB1;
8497 break;
8499 default:
8500 abort();
8502 len += 4;
8504 /* Haifa doesn't do well scheduling branches. */
8505 if (GET_CODE (insn) == JUMP_INSN)
8506 goto next_and_done;
8508 next:
8509 insn = next_nonnote_insn (insn);
8511 if (!insn || ! INSN_P (insn))
8512 goto done;
8514 /* Let Haifa tell us where it thinks insn group boundaries are. */
8515 if (GET_MODE (insn) == TImode)
8516 goto done;
8518 if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8519 goto next;
8522 next_and_done:
8523 insn = next_nonnote_insn (insn);
8525 done:
8526 *plen = len;
8527 *pin_use = in_use;
8528 return insn;
8531 /* IN_USE is a mask of the slots currently filled within the insn group.
8532 The mask bits come from alphaev5_pipe above. If EV5_E01 is set, then
8533 the insn in EV5_E0 can be swapped by the hardware into EV5_E1.
8535 LEN is, of course, the length of the group in bytes. */
8537 static rtx
8538 alphaev5_next_group (rtx insn, int *pin_use, int *plen)
8540 int len, in_use;
8542 len = in_use = 0;
8544 if (! INSN_P (insn)
8545 || GET_CODE (PATTERN (insn)) == CLOBBER
8546 || GET_CODE (PATTERN (insn)) == USE)
8547 goto next_and_done;
8549 while (1)
8551 enum alphaev5_pipe pipe;
8553 pipe = alphaev5_insn_pipe (insn);
8554 switch (pipe)
8556 case EV5_STOP:
8557 /* Force complex instructions to start new groups. */
8558 if (in_use)
8559 goto done;
8561 /* If this is a completely unrecognized insn, its an asm.
8562 We don't know how long it is, so record length as -1 to
8563 signal a needed realignment. */
8564 if (recog_memoized (insn) < 0)
8565 len = -1;
8566 else
8567 len = get_attr_length (insn);
8568 goto next_and_done;
8570 /* ??? Most of the places below, we would like to abort, as
8571 it would indicate an error either in Haifa, or in the
8572 scheduling description. Unfortunately, Haifa never
8573 schedules the last instruction of the BB, so we don't
8574 have an accurate TI bit to go off. */
8575 case EV5_E01:
8576 if (in_use & EV5_E0)
8578 if (in_use & EV5_E1)
8579 goto done;
8580 in_use |= EV5_E1;
8582 else
8583 in_use |= EV5_E0 | EV5_E01;
8584 break;
8586 case EV5_E0:
8587 if (in_use & EV5_E0)
8589 if (!(in_use & EV5_E01) || (in_use & EV5_E1))
8590 goto done;
8591 in_use |= EV5_E1;
8593 in_use |= EV5_E0;
8594 break;
8596 case EV5_E1:
8597 if (in_use & EV5_E1)
8598 goto done;
8599 in_use |= EV5_E1;
8600 break;
8602 case EV5_FAM:
8603 if (in_use & EV5_FA)
8605 if (in_use & EV5_FM)
8606 goto done;
8607 in_use |= EV5_FM;
8609 else
8610 in_use |= EV5_FA | EV5_FAM;
8611 break;
8613 case EV5_FA:
8614 if (in_use & EV5_FA)
8615 goto done;
8616 in_use |= EV5_FA;
8617 break;
8619 case EV5_FM:
8620 if (in_use & EV5_FM)
8621 goto done;
8622 in_use |= EV5_FM;
8623 break;
8625 case EV5_NONE:
8626 break;
8628 default:
8629 abort();
8631 len += 4;
8633 /* Haifa doesn't do well scheduling branches. */
8634 /* ??? If this is predicted not-taken, slotting continues, except
8635 that no more IBR, FBR, or JSR insns may be slotted. */
8636 if (GET_CODE (insn) == JUMP_INSN)
8637 goto next_and_done;
8639 next:
8640 insn = next_nonnote_insn (insn);
8642 if (!insn || ! INSN_P (insn))
8643 goto done;
8645 /* Let Haifa tell us where it thinks insn group boundaries are. */
8646 if (GET_MODE (insn) == TImode)
8647 goto done;
8649 if (GET_CODE (insn) == CLOBBER || GET_CODE (insn) == USE)
8650 goto next;
8653 next_and_done:
8654 insn = next_nonnote_insn (insn);
8656 done:
8657 *plen = len;
8658 *pin_use = in_use;
8659 return insn;
8662 static rtx
8663 alphaev4_next_nop (int *pin_use)
8665 int in_use = *pin_use;
8666 rtx nop;
8668 if (!(in_use & EV4_IB0))
8670 in_use |= EV4_IB0;
8671 nop = gen_nop ();
8673 else if ((in_use & (EV4_IBX|EV4_IB1)) == EV4_IBX)
8675 in_use |= EV4_IB1;
8676 nop = gen_nop ();
8678 else if (TARGET_FP && !(in_use & EV4_IB1))
8680 in_use |= EV4_IB1;
8681 nop = gen_fnop ();
8683 else
8684 nop = gen_unop ();
8686 *pin_use = in_use;
8687 return nop;
8690 static rtx
8691 alphaev5_next_nop (int *pin_use)
8693 int in_use = *pin_use;
8694 rtx nop;
8696 if (!(in_use & EV5_E1))
8698 in_use |= EV5_E1;
8699 nop = gen_nop ();
8701 else if (TARGET_FP && !(in_use & EV5_FA))
8703 in_use |= EV5_FA;
8704 nop = gen_fnop ();
8706 else if (TARGET_FP && !(in_use & EV5_FM))
8708 in_use |= EV5_FM;
8709 nop = gen_fnop ();
8711 else
8712 nop = gen_unop ();
8714 *pin_use = in_use;
8715 return nop;
8718 /* The instruction group alignment main loop. */
8720 static void
8721 alpha_align_insns (unsigned int max_align,
8722 rtx (*next_group) (rtx, int *, int *),
8723 rtx (*next_nop) (int *))
8725 /* ALIGN is the known alignment for the insn group. */
8726 unsigned int align;
8727 /* OFS is the offset of the current insn in the insn group. */
8728 int ofs;
8729 int prev_in_use, in_use, len;
8730 rtx i, next;
8732 /* Let shorten branches care for assigning alignments to code labels. */
8733 shorten_branches (get_insns ());
8735 if (align_functions < 4)
8736 align = 4;
8737 else if ((unsigned int) align_functions < max_align)
8738 align = align_functions;
8739 else
8740 align = max_align;
8742 ofs = prev_in_use = 0;
8743 i = get_insns ();
8744 if (GET_CODE (i) == NOTE)
8745 i = next_nonnote_insn (i);
8747 while (i)
8749 next = (*next_group) (i, &in_use, &len);
8751 /* When we see a label, resync alignment etc. */
8752 if (GET_CODE (i) == CODE_LABEL)
8754 unsigned int new_align = 1 << label_to_alignment (i);
8756 if (new_align >= align)
8758 align = new_align < max_align ? new_align : max_align;
8759 ofs = 0;
8762 else if (ofs & (new_align-1))
8763 ofs = (ofs | (new_align-1)) + 1;
8764 if (len != 0)
8765 abort();
8768 /* Handle complex instructions special. */
8769 else if (in_use == 0)
8771 /* Asms will have length < 0. This is a signal that we have
8772 lost alignment knowledge. Assume, however, that the asm
8773 will not mis-align instructions. */
8774 if (len < 0)
8776 ofs = 0;
8777 align = 4;
8778 len = 0;
8782 /* If the known alignment is smaller than the recognized insn group,
8783 realign the output. */
8784 else if ((int) align < len)
8786 unsigned int new_log_align = len > 8 ? 4 : 3;
8787 rtx prev, where;
8789 where = prev = prev_nonnote_insn (i);
8790 if (!where || GET_CODE (where) != CODE_LABEL)
8791 where = i;
8793 /* Can't realign between a call and its gp reload. */
8794 if (! (TARGET_EXPLICIT_RELOCS
8795 && prev && GET_CODE (prev) == CALL_INSN))
8797 emit_insn_before (gen_realign (GEN_INT (new_log_align)), where);
8798 align = 1 << new_log_align;
8799 ofs = 0;
8803 /* If the group won't fit in the same INT16 as the previous,
8804 we need to add padding to keep the group together. Rather
8805 than simply leaving the insn filling to the assembler, we
8806 can make use of the knowledge of what sorts of instructions
8807 were issued in the previous group to make sure that all of
8808 the added nops are really free. */
8809 else if (ofs + len > (int) align)
8811 int nop_count = (align - ofs) / 4;
8812 rtx where;
8814 /* Insert nops before labels, branches, and calls to truly merge
8815 the execution of the nops with the previous instruction group. */
8816 where = prev_nonnote_insn (i);
8817 if (where)
8819 if (GET_CODE (where) == CODE_LABEL)
8821 rtx where2 = prev_nonnote_insn (where);
8822 if (where2 && GET_CODE (where2) == JUMP_INSN)
8823 where = where2;
8825 else if (GET_CODE (where) == INSN)
8826 where = i;
8828 else
8829 where = i;
8832 emit_insn_before ((*next_nop)(&prev_in_use), where);
8833 while (--nop_count);
8834 ofs = 0;
8837 ofs = (ofs + len) & (align - 1);
8838 prev_in_use = in_use;
8839 i = next;
8843 /* Machine dependent reorg pass. */
8845 static void
8846 alpha_reorg (void)
8848 if (alpha_tp != ALPHA_TP_PROG || flag_exceptions)
8849 alpha_handle_trap_shadows ();
8851 /* Due to the number of extra trapb insns, don't bother fixing up
8852 alignment when trap precision is instruction. Moreover, we can
8853 only do our job when sched2 is run. */
8854 if (optimize && !optimize_size
8855 && alpha_tp != ALPHA_TP_INSN
8856 && flag_schedule_insns_after_reload)
8858 if (alpha_cpu == PROCESSOR_EV4)
8859 alpha_align_insns (8, alphaev4_next_group, alphaev4_next_nop);
8860 else if (alpha_cpu == PROCESSOR_EV5)
8861 alpha_align_insns (16, alphaev5_next_group, alphaev5_next_nop);
8865 #if !TARGET_ABI_UNICOSMK
8867 #ifdef HAVE_STAMP_H
8868 #include <stamp.h>
8869 #endif
8871 static void
8872 alpha_file_start (void)
8874 #ifdef OBJECT_FORMAT_ELF
8875 /* If emitting dwarf2 debug information, we cannot generate a .file
8876 directive to start the file, as it will conflict with dwarf2out
8877 file numbers. So it's only useful when emitting mdebug output. */
8878 targetm.file_start_file_directive = (write_symbols == DBX_DEBUG);
8879 #endif
8881 default_file_start ();
8882 #ifdef MS_STAMP
8883 fprintf (asm_out_file, "\t.verstamp %d %d\n", MS_STAMP, LS_STAMP);
8884 #endif
8886 fputs ("\t.set noreorder\n", asm_out_file);
8887 fputs ("\t.set volatile\n", asm_out_file);
8888 if (!TARGET_ABI_OPEN_VMS)
8889 fputs ("\t.set noat\n", asm_out_file);
8890 if (TARGET_EXPLICIT_RELOCS)
8891 fputs ("\t.set nomacro\n", asm_out_file);
8892 if (TARGET_SUPPORT_ARCH | TARGET_BWX | TARGET_MAX | TARGET_FIX | TARGET_CIX)
8893 fprintf (asm_out_file,
8894 "\t.arch %s\n",
8895 TARGET_CPU_EV6 ? "ev6"
8896 : (TARGET_CPU_EV5
8897 ? (TARGET_MAX ? "pca56" : TARGET_BWX ? "ev56" : "ev5")
8898 : "ev4"));
8900 #endif
8902 #ifdef OBJECT_FORMAT_ELF
8904 /* Switch to the section to which we should output X. The only thing
8905 special we do here is to honor small data. */
8907 static void
8908 alpha_elf_select_rtx_section (enum machine_mode mode, rtx x,
8909 unsigned HOST_WIDE_INT align)
8911 if (TARGET_SMALL_DATA && GET_MODE_SIZE (mode) <= g_switch_value)
8912 /* ??? Consider using mergeable sdata sections. */
8913 sdata_section ();
8914 else
8915 default_elf_select_rtx_section (mode, x, align);
8918 #endif /* OBJECT_FORMAT_ELF */
8920 /* Structure to collect function names for final output in link section. */
8921 /* Note that items marked with GTY can't be ifdef'ed out. */
8923 enum links_kind {KIND_UNUSED, KIND_LOCAL, KIND_EXTERN};
8924 enum reloc_kind {KIND_LINKAGE, KIND_CODEADDR};
8926 struct alpha_links GTY(())
8928 int num;
8929 rtx linkage;
8930 enum links_kind lkind;
8931 enum reloc_kind rkind;
8934 struct alpha_funcs GTY(())
8936 int num;
8937 splay_tree GTY ((param1_is (char *), param2_is (struct alpha_links *)))
8938 links;
8941 static GTY ((param1_is (char *), param2_is (struct alpha_links *)))
8942 splay_tree alpha_links_tree;
8943 static GTY ((param1_is (tree), param2_is (struct alpha_funcs *)))
8944 splay_tree alpha_funcs_tree;
8946 static GTY(()) int alpha_funcs_num;
8948 #if TARGET_ABI_OPEN_VMS
8950 /* Return the VMS argument type corresponding to MODE. */
8952 enum avms_arg_type
8953 alpha_arg_type (enum machine_mode mode)
8955 switch (mode)
8957 case SFmode:
8958 return TARGET_FLOAT_VAX ? FF : FS;
8959 case DFmode:
8960 return TARGET_FLOAT_VAX ? FD : FT;
8961 default:
8962 return I64;
8966 /* Return an rtx for an integer representing the VMS Argument Information
8967 register value. */
8970 alpha_arg_info_reg_val (CUMULATIVE_ARGS cum)
8972 unsigned HOST_WIDE_INT regval = cum.num_args;
8973 int i;
8975 for (i = 0; i < 6; i++)
8976 regval |= ((int) cum.atypes[i]) << (i * 3 + 8);
8978 return GEN_INT (regval);
8981 /* Make (or fake) .linkage entry for function call.
8983 IS_LOCAL is 0 if name is used in call, 1 if name is used in definition.
8985 Return an SYMBOL_REF rtx for the linkage. */
8988 alpha_need_linkage (const char *name, int is_local)
8990 splay_tree_node node;
8991 struct alpha_links *al;
8993 if (name[0] == '*')
8994 name++;
8996 if (is_local)
8998 struct alpha_funcs *cfaf;
9000 if (!alpha_funcs_tree)
9001 alpha_funcs_tree = splay_tree_new_ggc ((splay_tree_compare_fn)
9002 splay_tree_compare_pointers);
9004 cfaf = (struct alpha_funcs *) ggc_alloc (sizeof (struct alpha_funcs));
9006 cfaf->links = 0;
9007 cfaf->num = ++alpha_funcs_num;
9009 splay_tree_insert (alpha_funcs_tree,
9010 (splay_tree_key) current_function_decl,
9011 (splay_tree_value) cfaf);
9014 if (alpha_links_tree)
9016 /* Is this name already defined? */
9018 node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
9019 if (node)
9021 al = (struct alpha_links *) node->value;
9022 if (is_local)
9024 /* Defined here but external assumed. */
9025 if (al->lkind == KIND_EXTERN)
9026 al->lkind = KIND_LOCAL;
9028 else
9030 /* Used here but unused assumed. */
9031 if (al->lkind == KIND_UNUSED)
9032 al->lkind = KIND_LOCAL;
9034 return al->linkage;
9037 else
9038 alpha_links_tree = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
9040 al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
9041 name = ggc_strdup (name);
9043 /* Assume external if no definition. */
9044 al->lkind = (is_local ? KIND_UNUSED : KIND_EXTERN);
9046 /* Ensure we have an IDENTIFIER so assemble_name can mark it used. */
9047 get_identifier (name);
9049 /* Construct a SYMBOL_REF for us to call. */
9051 size_t name_len = strlen (name);
9052 char *linksym = alloca (name_len + 6);
9053 linksym[0] = '$';
9054 memcpy (linksym + 1, name, name_len);
9055 memcpy (linksym + 1 + name_len, "..lk", 5);
9056 al->linkage = gen_rtx_SYMBOL_REF (Pmode,
9057 ggc_alloc_string (linksym, name_len + 5));
9060 splay_tree_insert (alpha_links_tree, (splay_tree_key) name,
9061 (splay_tree_value) al);
9063 return al->linkage;
9067 alpha_use_linkage (rtx linkage, tree cfundecl, int lflag, int rflag)
9069 splay_tree_node cfunnode;
9070 struct alpha_funcs *cfaf;
9071 struct alpha_links *al;
9072 const char *name = XSTR (linkage, 0);
9074 cfaf = (struct alpha_funcs *) 0;
9075 al = (struct alpha_links *) 0;
9077 cfunnode = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) cfundecl);
9078 cfaf = (struct alpha_funcs *) cfunnode->value;
9080 if (cfaf->links)
9082 splay_tree_node lnode;
9084 /* Is this name already defined? */
9086 lnode = splay_tree_lookup (cfaf->links, (splay_tree_key) name);
9087 if (lnode)
9088 al = (struct alpha_links *) lnode->value;
9090 else
9091 cfaf->links = splay_tree_new_ggc ((splay_tree_compare_fn) strcmp);
9093 if (!al)
9095 size_t name_len;
9096 size_t buflen;
9097 char buf [512];
9098 char *linksym;
9099 splay_tree_node node = 0;
9100 struct alpha_links *anl;
9102 if (name[0] == '*')
9103 name++;
9105 name_len = strlen (name);
9107 al = (struct alpha_links *) ggc_alloc (sizeof (struct alpha_links));
9108 al->num = cfaf->num;
9110 node = splay_tree_lookup (alpha_links_tree, (splay_tree_key) name);
9111 if (node)
9113 anl = (struct alpha_links *) node->value;
9114 al->lkind = anl->lkind;
9117 sprintf (buf, "$%d..%s..lk", cfaf->num, name);
9118 buflen = strlen (buf);
9119 linksym = alloca (buflen + 1);
9120 memcpy (linksym, buf, buflen + 1);
9122 al->linkage = gen_rtx_SYMBOL_REF
9123 (Pmode, ggc_alloc_string (linksym, buflen + 1));
9125 splay_tree_insert (cfaf->links, (splay_tree_key) name,
9126 (splay_tree_value) al);
9129 if (rflag)
9130 al->rkind = KIND_CODEADDR;
9131 else
9132 al->rkind = KIND_LINKAGE;
9134 if (lflag)
9135 return gen_rtx_MEM (Pmode, plus_constant (al->linkage, 8));
9136 else
9137 return al->linkage;
9140 static int
9141 alpha_write_one_linkage (splay_tree_node node, void *data)
9143 const char *const name = (const char *) node->key;
9144 struct alpha_links *link = (struct alpha_links *) node->value;
9145 FILE *stream = (FILE *) data;
9147 fprintf (stream, "$%d..%s..lk:\n", link->num, name);
9148 if (link->rkind == KIND_CODEADDR)
9150 if (link->lkind == KIND_LOCAL)
9152 /* Local and used */
9153 fprintf (stream, "\t.quad %s..en\n", name);
9155 else
9157 /* External and used, request code address. */
9158 fprintf (stream, "\t.code_address %s\n", name);
9161 else
9163 if (link->lkind == KIND_LOCAL)
9165 /* Local and used, build linkage pair. */
9166 fprintf (stream, "\t.quad %s..en\n", name);
9167 fprintf (stream, "\t.quad %s\n", name);
9169 else
9171 /* External and used, request linkage pair. */
9172 fprintf (stream, "\t.linkage %s\n", name);
9176 return 0;
9179 static void
9180 alpha_write_linkage (FILE *stream, const char *funname, tree fundecl)
9182 splay_tree_node node;
9183 struct alpha_funcs *func;
9185 link_section ();
9186 fprintf (stream, "\t.align 3\n");
9187 node = splay_tree_lookup (alpha_funcs_tree, (splay_tree_key) fundecl);
9188 func = (struct alpha_funcs *) node->value;
9190 fputs ("\t.name ", stream);
9191 assemble_name (stream, funname);
9192 fputs ("..na\n", stream);
9193 ASM_OUTPUT_LABEL (stream, funname);
9194 fprintf (stream, "\t.pdesc ");
9195 assemble_name (stream, funname);
9196 fprintf (stream, "..en,%s\n",
9197 alpha_procedure_type == PT_STACK ? "stack"
9198 : alpha_procedure_type == PT_REGISTER ? "reg" : "null");
9200 if (func->links)
9202 splay_tree_foreach (func->links, alpha_write_one_linkage, stream);
9203 /* splay_tree_delete (func->links); */
9207 /* Given a decl, a section name, and whether the decl initializer
9208 has relocs, choose attributes for the section. */
9210 #define SECTION_VMS_OVERLAY SECTION_FORGET
9211 #define SECTION_VMS_GLOBAL SECTION_MACH_DEP
9212 #define SECTION_VMS_INITIALIZE (SECTION_VMS_GLOBAL << 1)
9214 static unsigned int
9215 vms_section_type_flags (tree decl, const char *name, int reloc)
9217 unsigned int flags = default_section_type_flags (decl, name, reloc);
9219 if (decl && DECL_ATTRIBUTES (decl)
9220 && lookup_attribute ("overlaid", DECL_ATTRIBUTES (decl)))
9221 flags |= SECTION_VMS_OVERLAY;
9222 if (decl && DECL_ATTRIBUTES (decl)
9223 && lookup_attribute ("global", DECL_ATTRIBUTES (decl)))
9224 flags |= SECTION_VMS_GLOBAL;
9225 if (decl && DECL_ATTRIBUTES (decl)
9226 && lookup_attribute ("initialize", DECL_ATTRIBUTES (decl)))
9227 flags |= SECTION_VMS_INITIALIZE;
9229 return flags;
9232 /* Switch to an arbitrary section NAME with attributes as specified
9233 by FLAGS. ALIGN specifies any known alignment requirements for
9234 the section; 0 if the default should be used. */
9236 static void
9237 vms_asm_named_section (const char *name, unsigned int flags)
9239 fputc ('\n', asm_out_file);
9240 fprintf (asm_out_file, ".section\t%s", name);
9242 if (flags & SECTION_VMS_OVERLAY)
9243 fprintf (asm_out_file, ",OVR");
9244 if (flags & SECTION_VMS_GLOBAL)
9245 fprintf (asm_out_file, ",GBL");
9246 if (flags & SECTION_VMS_INITIALIZE)
9247 fprintf (asm_out_file, ",NOMOD");
9248 if (flags & SECTION_DEBUG)
9249 fprintf (asm_out_file, ",NOWRT");
9251 fputc ('\n', asm_out_file);
9254 /* Record an element in the table of global constructors. SYMBOL is
9255 a SYMBOL_REF of the function to be called; PRIORITY is a number
9256 between 0 and MAX_INIT_PRIORITY.
9258 Differs from default_ctors_section_asm_out_constructor in that the
9259 width of the .ctors entry is always 64 bits, rather than the 32 bits
9260 used by a normal pointer. */
9262 static void
9263 vms_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9265 ctors_section ();
9266 assemble_align (BITS_PER_WORD);
9267 assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9270 static void
9271 vms_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
9273 dtors_section ();
9274 assemble_align (BITS_PER_WORD);
9275 assemble_integer (symbol, UNITS_PER_WORD, BITS_PER_WORD, 1);
9277 #else
9280 alpha_need_linkage (const char *name ATTRIBUTE_UNUSED,
9281 int is_local ATTRIBUTE_UNUSED)
9283 return NULL_RTX;
9287 alpha_use_linkage (rtx linkage ATTRIBUTE_UNUSED,
9288 tree cfundecl ATTRIBUTE_UNUSED,
9289 int lflag ATTRIBUTE_UNUSED,
9290 int rflag ATTRIBUTE_UNUSED)
9292 return NULL_RTX;
9295 #endif /* TARGET_ABI_OPEN_VMS */
9297 #if TARGET_ABI_UNICOSMK
9299 /* This evaluates to true if we do not know how to pass TYPE solely in
9300 registers. This is the case for all arguments that do not fit in two
9301 registers. */
9303 static bool
9304 unicosmk_must_pass_in_stack (enum machine_mode mode, tree type)
9306 if (type == NULL)
9307 return false;
9309 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
9310 return true;
9311 if (TREE_ADDRESSABLE (type))
9312 return true;
9314 return ALPHA_ARG_SIZE (mode, type, 0) > 2;
9317 /* Define the offset between two registers, one to be eliminated, and the
9318 other its replacement, at the start of a routine. */
9321 unicosmk_initial_elimination_offset (int from, int to)
9323 int fixed_size;
9325 fixed_size = alpha_sa_size();
9326 if (fixed_size != 0)
9327 fixed_size += 48;
9329 if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9330 return -fixed_size;
9331 else if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9332 return 0;
9333 else if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9334 return (ALPHA_ROUND (current_function_outgoing_args_size)
9335 + ALPHA_ROUND (get_frame_size()));
9336 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
9337 return (ALPHA_ROUND (fixed_size)
9338 + ALPHA_ROUND (get_frame_size()
9339 + current_function_outgoing_args_size));
9340 else
9341 abort ();
9344 /* Output the module name for .ident and .end directives. We have to strip
9345 directories and add make sure that the module name starts with a letter
9346 or '$'. */
9348 static void
9349 unicosmk_output_module_name (FILE *file)
9351 const char *name = lbasename (main_input_filename);
9352 unsigned len = strlen (name);
9353 char *clean_name = alloca (len + 2);
9354 char *ptr = clean_name;
9356 /* CAM only accepts module names that start with a letter or '$'. We
9357 prefix the module name with a '$' if necessary. */
9359 if (!ISALPHA (*name))
9360 *ptr++ = '$';
9361 memcpy (ptr, name, len + 1);
9362 clean_symbol_name (clean_name);
9363 fputs (clean_name, file);
9366 /* Output the definition of a common variable. */
9368 void
9369 unicosmk_output_common (FILE *file, const char *name, int size, int align)
9371 tree name_tree;
9372 printf ("T3E__: common %s\n", name);
9374 common_section ();
9375 fputs("\t.endp\n\n\t.psect ", file);
9376 assemble_name(file, name);
9377 fprintf(file, ",%d,common\n", floor_log2 (align / BITS_PER_UNIT));
9378 fprintf(file, "\t.byte\t0:%d\n", size);
9380 /* Mark the symbol as defined in this module. */
9381 name_tree = get_identifier (name);
9382 TREE_ASM_WRITTEN (name_tree) = 1;
9385 #define SECTION_PUBLIC SECTION_MACH_DEP
9386 #define SECTION_MAIN (SECTION_PUBLIC << 1)
9387 static int current_section_align;
9389 static unsigned int
9390 unicosmk_section_type_flags (tree decl, const char *name,
9391 int reloc ATTRIBUTE_UNUSED)
9393 unsigned int flags = default_section_type_flags (decl, name, reloc);
9395 if (!decl)
9396 return flags;
9398 if (TREE_CODE (decl) == FUNCTION_DECL)
9400 current_section_align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
9401 if (align_functions_log > current_section_align)
9402 current_section_align = align_functions_log;
9404 if (! strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "main"))
9405 flags |= SECTION_MAIN;
9407 else
9408 current_section_align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
9410 if (TREE_PUBLIC (decl))
9411 flags |= SECTION_PUBLIC;
9413 return flags;
9416 /* Generate a section name for decl and associate it with the
9417 declaration. */
9419 static void
9420 unicosmk_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
9422 const char *name;
9423 int len;
9425 if (!decl)
9426 abort ();
9428 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
9429 name = default_strip_name_encoding (name);
9430 len = strlen (name);
9432 if (TREE_CODE (decl) == FUNCTION_DECL)
9434 char *string;
9436 /* It is essential that we prefix the section name here because
9437 otherwise the section names generated for constructors and
9438 destructors confuse collect2. */
9440 string = alloca (len + 6);
9441 sprintf (string, "code@%s", name);
9442 DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9444 else if (TREE_PUBLIC (decl))
9445 DECL_SECTION_NAME (decl) = build_string (len, name);
9446 else
9448 char *string;
9450 string = alloca (len + 6);
9451 sprintf (string, "data@%s", name);
9452 DECL_SECTION_NAME (decl) = build_string (len + 5, string);
9456 /* Switch to an arbitrary section NAME with attributes as specified
9457 by FLAGS. ALIGN specifies any known alignment requirements for
9458 the section; 0 if the default should be used. */
9460 static void
9461 unicosmk_asm_named_section (const char *name, unsigned int flags)
9463 const char *kind;
9465 /* Close the previous section. */
9467 fputs ("\t.endp\n\n", asm_out_file);
9469 /* Find out what kind of section we are opening. */
9471 if (flags & SECTION_MAIN)
9472 fputs ("\t.start\tmain\n", asm_out_file);
9474 if (flags & SECTION_CODE)
9475 kind = "code";
9476 else if (flags & SECTION_PUBLIC)
9477 kind = "common";
9478 else
9479 kind = "data";
9481 if (current_section_align != 0)
9482 fprintf (asm_out_file, "\t.psect\t%s,%d,%s\n", name,
9483 current_section_align, kind);
9484 else
9485 fprintf (asm_out_file, "\t.psect\t%s,%s\n", name, kind);
9488 static void
9489 unicosmk_insert_attributes (tree decl, tree *attr_ptr ATTRIBUTE_UNUSED)
9491 if (DECL_P (decl)
9492 && (TREE_PUBLIC (decl) || TREE_CODE (decl) == FUNCTION_DECL))
9493 unicosmk_unique_section (decl, 0);
9496 /* Output an alignment directive. We have to use the macro 'gcc@code@align'
9497 in code sections because .align fill unused space with zeroes. */
9499 void
9500 unicosmk_output_align (FILE *file, int align)
9502 if (inside_function)
9503 fprintf (file, "\tgcc@code@align\t%d\n", align);
9504 else
9505 fprintf (file, "\t.align\t%d\n", align);
9508 /* Add a case vector to the current function's list of deferred case
9509 vectors. Case vectors have to be put into a separate section because CAM
9510 does not allow data definitions in code sections. */
9512 void
9513 unicosmk_defer_case_vector (rtx lab, rtx vec)
9515 struct machine_function *machine = cfun->machine;
9517 vec = gen_rtx_EXPR_LIST (VOIDmode, lab, vec);
9518 machine->addr_list = gen_rtx_EXPR_LIST (VOIDmode, vec,
9519 machine->addr_list);
9522 /* Output a case vector. */
9524 static void
9525 unicosmk_output_addr_vec (FILE *file, rtx vec)
9527 rtx lab = XEXP (vec, 0);
9528 rtx body = XEXP (vec, 1);
9529 int vlen = XVECLEN (body, 0);
9530 int idx;
9532 (*targetm.asm_out.internal_label) (file, "L", CODE_LABEL_NUMBER (lab));
9534 for (idx = 0; idx < vlen; idx++)
9536 ASM_OUTPUT_ADDR_VEC_ELT
9537 (file, CODE_LABEL_NUMBER (XEXP (XVECEXP (body, 0, idx), 0)));
9541 /* Output current function's deferred case vectors. */
9543 static void
9544 unicosmk_output_deferred_case_vectors (FILE *file)
9546 struct machine_function *machine = cfun->machine;
9547 rtx t;
9549 if (machine->addr_list == NULL_RTX)
9550 return;
9552 data_section ();
9553 for (t = machine->addr_list; t; t = XEXP (t, 1))
9554 unicosmk_output_addr_vec (file, XEXP (t, 0));
9557 /* Generate the name of the SSIB section for the current function. */
9559 #define SSIB_PREFIX "__SSIB_"
9560 #define SSIB_PREFIX_LEN 7
9562 static const char *
9563 unicosmk_ssib_name (void)
9565 /* This is ok since CAM won't be able to deal with names longer than that
9566 anyway. */
9568 static char name[256];
9570 rtx x;
9571 const char *fnname;
9572 int len;
9574 x = DECL_RTL (cfun->decl);
9575 if (GET_CODE (x) != MEM)
9576 abort ();
9577 x = XEXP (x, 0);
9578 if (GET_CODE (x) != SYMBOL_REF)
9579 abort ();
9580 fnname = XSTR (x, 0);
9582 len = strlen (fnname);
9583 if (len + SSIB_PREFIX_LEN > 255)
9584 len = 255 - SSIB_PREFIX_LEN;
9586 strcpy (name, SSIB_PREFIX);
9587 strncpy (name + SSIB_PREFIX_LEN, fnname, len);
9588 name[len + SSIB_PREFIX_LEN] = 0;
9590 return name;
9593 /* Set up the dynamic subprogram information block (DSIB) and update the
9594 frame pointer register ($15) for subroutines which have a frame. If the
9595 subroutine doesn't have a frame, simply increment $15. */
9597 static void
9598 unicosmk_gen_dsib (unsigned long *imaskP)
9600 if (alpha_procedure_type == PT_STACK)
9602 const char *ssib_name;
9603 rtx mem;
9605 /* Allocate 64 bytes for the DSIB. */
9607 FRP (emit_insn (gen_adddi3 (stack_pointer_rtx, stack_pointer_rtx,
9608 GEN_INT (-64))));
9609 emit_insn (gen_blockage ());
9611 /* Save the return address. */
9613 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 56));
9614 set_mem_alias_set (mem, alpha_sr_alias_set);
9615 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, REG_RA)));
9616 (*imaskP) &= ~(1UL << REG_RA);
9618 /* Save the old frame pointer. */
9620 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 48));
9621 set_mem_alias_set (mem, alpha_sr_alias_set);
9622 FRP (emit_move_insn (mem, hard_frame_pointer_rtx));
9623 (*imaskP) &= ~(1UL << HARD_FRAME_POINTER_REGNUM);
9625 emit_insn (gen_blockage ());
9627 /* Store the SSIB pointer. */
9629 ssib_name = ggc_strdup (unicosmk_ssib_name ());
9630 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 32));
9631 set_mem_alias_set (mem, alpha_sr_alias_set);
9633 FRP (emit_move_insn (gen_rtx_REG (DImode, 5),
9634 gen_rtx_SYMBOL_REF (Pmode, ssib_name)));
9635 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 5)));
9637 /* Save the CIW index. */
9639 mem = gen_rtx_MEM (DImode, plus_constant (stack_pointer_rtx, 24));
9640 set_mem_alias_set (mem, alpha_sr_alias_set);
9641 FRP (emit_move_insn (mem, gen_rtx_REG (DImode, 25)));
9643 emit_insn (gen_blockage ());
9645 /* Set the new frame pointer. */
9647 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9648 stack_pointer_rtx, GEN_INT (64))));
9651 else
9653 /* Increment the frame pointer register to indicate that we do not
9654 have a frame. */
9656 FRP (emit_insn (gen_adddi3 (hard_frame_pointer_rtx,
9657 hard_frame_pointer_rtx, const1_rtx)));
9661 /* Output the static subroutine information block for the current
9662 function. */
9664 static void
9665 unicosmk_output_ssib (FILE *file, const char *fnname)
9667 int len;
9668 int i;
9669 rtx x;
9670 rtx ciw;
9671 struct machine_function *machine = cfun->machine;
9673 ssib_section ();
9674 fprintf (file, "\t.endp\n\n\t.psect\t%s%s,data\n", user_label_prefix,
9675 unicosmk_ssib_name ());
9677 /* Some required stuff and the function name length. */
9679 len = strlen (fnname);
9680 fprintf (file, "\t.quad\t^X20008%2.2X28\n", len);
9682 /* Saved registers
9683 ??? We don't do that yet. */
9685 fputs ("\t.quad\t0\n", file);
9687 /* Function address. */
9689 fputs ("\t.quad\t", file);
9690 assemble_name (file, fnname);
9691 putc ('\n', file);
9693 fputs ("\t.quad\t0\n", file);
9694 fputs ("\t.quad\t0\n", file);
9696 /* Function name.
9697 ??? We do it the same way Cray CC does it but this could be
9698 simplified. */
9700 for( i = 0; i < len; i++ )
9701 fprintf (file, "\t.byte\t%d\n", (int)(fnname[i]));
9702 if( (len % 8) == 0 )
9703 fputs ("\t.quad\t0\n", file);
9704 else
9705 fprintf (file, "\t.bits\t%d : 0\n", (8 - (len % 8))*8);
9707 /* All call information words used in the function. */
9709 for (x = machine->first_ciw; x; x = XEXP (x, 1))
9711 ciw = XEXP (x, 0);
9712 #if HOST_BITS_PER_WIDE_INT == 32
9713 fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_DOUBLE_HEX "\n",
9714 CONST_DOUBLE_HIGH (ciw), CONST_DOUBLE_LOW (ciw));
9715 #else
9716 fprintf (file, "\t.quad\t" HOST_WIDE_INT_PRINT_HEX "\n", INTVAL (ciw));
9717 #endif
9721 /* Add a call information word (CIW) to the list of the current function's
9722 CIWs and return its index.
9724 X is a CONST_INT or CONST_DOUBLE representing the CIW. */
9727 unicosmk_add_call_info_word (rtx x)
9729 rtx node;
9730 struct machine_function *machine = cfun->machine;
9732 node = gen_rtx_EXPR_LIST (VOIDmode, x, NULL_RTX);
9733 if (machine->first_ciw == NULL_RTX)
9734 machine->first_ciw = node;
9735 else
9736 XEXP (machine->last_ciw, 1) = node;
9738 machine->last_ciw = node;
9739 ++machine->ciw_count;
9741 return GEN_INT (machine->ciw_count
9742 + strlen (current_function_name ())/8 + 5);
9745 static char unicosmk_section_buf[100];
9747 char *
9748 unicosmk_text_section (void)
9750 static int count = 0;
9751 sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@text___%d,code",
9752 count++);
9753 return unicosmk_section_buf;
9756 char *
9757 unicosmk_data_section (void)
9759 static int count = 1;
9760 sprintf (unicosmk_section_buf, "\t.endp\n\n\t.psect\tgcc@data___%d,data",
9761 count++);
9762 return unicosmk_section_buf;
9765 /* The Cray assembler doesn't accept extern declarations for symbols which
9766 are defined in the same file. We have to keep track of all global
9767 symbols which are referenced and/or defined in a source file and output
9768 extern declarations for those which are referenced but not defined at
9769 the end of file. */
9771 /* List of identifiers for which an extern declaration might have to be
9772 emitted. */
9773 /* FIXME: needs to use GC, so it can be saved and restored for PCH. */
9775 struct unicosmk_extern_list
9777 struct unicosmk_extern_list *next;
9778 const char *name;
9781 static struct unicosmk_extern_list *unicosmk_extern_head = 0;
9783 /* Output extern declarations which are required for every asm file. */
9785 static void
9786 unicosmk_output_default_externs (FILE *file)
9788 static const char *const externs[] =
9789 { "__T3E_MISMATCH" };
9791 int i;
9792 int n;
9794 n = ARRAY_SIZE (externs);
9796 for (i = 0; i < n; i++)
9797 fprintf (file, "\t.extern\t%s\n", externs[i]);
9800 /* Output extern declarations for global symbols which are have been
9801 referenced but not defined. */
9803 static void
9804 unicosmk_output_externs (FILE *file)
9806 struct unicosmk_extern_list *p;
9807 const char *real_name;
9808 int len;
9809 tree name_tree;
9811 len = strlen (user_label_prefix);
9812 for (p = unicosmk_extern_head; p != 0; p = p->next)
9814 /* We have to strip the encoding and possibly remove user_label_prefix
9815 from the identifier in order to handle -fleading-underscore and
9816 explicit asm names correctly (cf. gcc.dg/asm-names-1.c). */
9817 real_name = default_strip_name_encoding (p->name);
9818 if (len && p->name[0] == '*'
9819 && !memcmp (real_name, user_label_prefix, len))
9820 real_name += len;
9822 name_tree = get_identifier (real_name);
9823 if (! TREE_ASM_WRITTEN (name_tree))
9825 TREE_ASM_WRITTEN (name_tree) = 1;
9826 fputs ("\t.extern\t", file);
9827 assemble_name (file, p->name);
9828 putc ('\n', file);
9833 /* Record an extern. */
9835 void
9836 unicosmk_add_extern (const char *name)
9838 struct unicosmk_extern_list *p;
9840 p = (struct unicosmk_extern_list *)
9841 xmalloc (sizeof (struct unicosmk_extern_list));
9842 p->next = unicosmk_extern_head;
9843 p->name = name;
9844 unicosmk_extern_head = p;
9847 /* The Cray assembler generates incorrect code if identifiers which
9848 conflict with register names are used as instruction operands. We have
9849 to replace such identifiers with DEX expressions. */
9851 /* Structure to collect identifiers which have been replaced by DEX
9852 expressions. */
9853 /* FIXME: needs to use GC, so it can be saved and restored for PCH. */
9855 struct unicosmk_dex {
9856 struct unicosmk_dex *next;
9857 const char *name;
9860 /* List of identifiers which have been replaced by DEX expressions. The DEX
9861 number is determined by the position in the list. */
9863 static struct unicosmk_dex *unicosmk_dex_list = NULL;
9865 /* The number of elements in the DEX list. */
9867 static int unicosmk_dex_count = 0;
9869 /* Check if NAME must be replaced by a DEX expression. */
9871 static int
9872 unicosmk_special_name (const char *name)
9874 if (name[0] == '*')
9875 ++name;
9877 if (name[0] == '$')
9878 ++name;
9880 if (name[0] != 'r' && name[0] != 'f' && name[0] != 'R' && name[0] != 'F')
9881 return 0;
9883 switch (name[1])
9885 case '1': case '2':
9886 return (name[2] == '\0' || (ISDIGIT (name[2]) && name[3] == '\0'));
9888 case '3':
9889 return (name[2] == '\0'
9890 || ((name[2] == '0' || name[2] == '1') && name[3] == '\0'));
9892 default:
9893 return (ISDIGIT (name[1]) && name[2] == '\0');
9897 /* Return the DEX number if X must be replaced by a DEX expression and 0
9898 otherwise. */
9900 static int
9901 unicosmk_need_dex (rtx x)
9903 struct unicosmk_dex *dex;
9904 const char *name;
9905 int i;
9907 if (GET_CODE (x) != SYMBOL_REF)
9908 return 0;
9910 name = XSTR (x,0);
9911 if (! unicosmk_special_name (name))
9912 return 0;
9914 i = unicosmk_dex_count;
9915 for (dex = unicosmk_dex_list; dex; dex = dex->next)
9917 if (! strcmp (name, dex->name))
9918 return i;
9919 --i;
9922 dex = (struct unicosmk_dex *) xmalloc (sizeof (struct unicosmk_dex));
9923 dex->name = name;
9924 dex->next = unicosmk_dex_list;
9925 unicosmk_dex_list = dex;
9927 ++unicosmk_dex_count;
9928 return unicosmk_dex_count;
9931 /* Output the DEX definitions for this file. */
9933 static void
9934 unicosmk_output_dex (FILE *file)
9936 struct unicosmk_dex *dex;
9937 int i;
9939 if (unicosmk_dex_list == NULL)
9940 return;
9942 fprintf (file, "\t.dexstart\n");
9944 i = unicosmk_dex_count;
9945 for (dex = unicosmk_dex_list; dex; dex = dex->next)
9947 fprintf (file, "\tDEX (%d) = ", i);
9948 assemble_name (file, dex->name);
9949 putc ('\n', file);
9950 --i;
9953 fprintf (file, "\t.dexend\n");
9956 /* Output text that to appear at the beginning of an assembler file. */
9958 static void
9959 unicosmk_file_start (void)
9961 int i;
9963 fputs ("\t.ident\t", asm_out_file);
9964 unicosmk_output_module_name (asm_out_file);
9965 fputs ("\n\n", asm_out_file);
9967 /* The Unicos/Mk assembler uses different register names. Instead of trying
9968 to support them, we simply use micro definitions. */
9970 /* CAM has different register names: rN for the integer register N and fN
9971 for the floating-point register N. Instead of trying to use these in
9972 alpha.md, we define the symbols $N and $fN to refer to the appropriate
9973 register. */
9975 for (i = 0; i < 32; ++i)
9976 fprintf (asm_out_file, "$%d <- r%d\n", i, i);
9978 for (i = 0; i < 32; ++i)
9979 fprintf (asm_out_file, "$f%d <- f%d\n", i, i);
9981 putc ('\n', asm_out_file);
9983 /* The .align directive fill unused space with zeroes which does not work
9984 in code sections. We define the macro 'gcc@code@align' which uses nops
9985 instead. Note that it assumes that code sections always have the
9986 biggest possible alignment since . refers to the current offset from
9987 the beginning of the section. */
9989 fputs ("\t.macro gcc@code@align n\n", asm_out_file);
9990 fputs ("gcc@n@bytes = 1 << n\n", asm_out_file);
9991 fputs ("gcc@here = . % gcc@n@bytes\n", asm_out_file);
9992 fputs ("\t.if ne, gcc@here, 0\n", asm_out_file);
9993 fputs ("\t.repeat (gcc@n@bytes - gcc@here) / 4\n", asm_out_file);
9994 fputs ("\tbis r31,r31,r31\n", asm_out_file);
9995 fputs ("\t.endr\n", asm_out_file);
9996 fputs ("\t.endif\n", asm_out_file);
9997 fputs ("\t.endm gcc@code@align\n\n", asm_out_file);
9999 /* Output extern declarations which should always be visible. */
10000 unicosmk_output_default_externs (asm_out_file);
10002 /* Open a dummy section. We always need to be inside a section for the
10003 section-switching code to work correctly.
10004 ??? This should be a module id or something like that. I still have to
10005 figure out what the rules for those are. */
10006 fputs ("\n\t.psect\t$SG00000,data\n", asm_out_file);
10009 /* Output text to appear at the end of an assembler file. This includes all
10010 pending extern declarations and DEX expressions. */
10012 static void
10013 unicosmk_file_end (void)
10015 fputs ("\t.endp\n\n", asm_out_file);
10017 /* Output all pending externs. */
10019 unicosmk_output_externs (asm_out_file);
10021 /* Output dex definitions used for functions whose names conflict with
10022 register names. */
10024 unicosmk_output_dex (asm_out_file);
10026 fputs ("\t.end\t", asm_out_file);
10027 unicosmk_output_module_name (asm_out_file);
10028 putc ('\n', asm_out_file);
10031 #else
10033 static void
10034 unicosmk_output_deferred_case_vectors (FILE *file ATTRIBUTE_UNUSED)
10037 static void
10038 unicosmk_gen_dsib (unsigned long *imaskP ATTRIBUTE_UNUSED)
10041 static void
10042 unicosmk_output_ssib (FILE * file ATTRIBUTE_UNUSED,
10043 const char * fnname ATTRIBUTE_UNUSED)
10047 unicosmk_add_call_info_word (rtx x ATTRIBUTE_UNUSED)
10049 return NULL_RTX;
10052 static int
10053 unicosmk_need_dex (rtx x ATTRIBUTE_UNUSED)
10055 return 0;
10058 #endif /* TARGET_ABI_UNICOSMK */
10060 static void
10061 alpha_init_libfuncs (void)
10063 if (TARGET_ABI_UNICOSMK)
10065 /* Prevent gcc from generating calls to __divsi3. */
10066 set_optab_libfunc (sdiv_optab, SImode, 0);
10067 set_optab_libfunc (udiv_optab, SImode, 0);
10069 /* Use the functions provided by the system library
10070 for DImode integer division. */
10071 set_optab_libfunc (sdiv_optab, DImode, "$sldiv");
10072 set_optab_libfunc (udiv_optab, DImode, "$uldiv");
10074 else if (TARGET_ABI_OPEN_VMS)
10076 /* Use the VMS runtime library functions for division and
10077 remainder. */
10078 set_optab_libfunc (sdiv_optab, SImode, "OTS$DIV_I");
10079 set_optab_libfunc (sdiv_optab, DImode, "OTS$DIV_L");
10080 set_optab_libfunc (udiv_optab, SImode, "OTS$DIV_UI");
10081 set_optab_libfunc (udiv_optab, DImode, "OTS$DIV_UL");
10082 set_optab_libfunc (smod_optab, SImode, "OTS$REM_I");
10083 set_optab_libfunc (smod_optab, DImode, "OTS$REM_L");
10084 set_optab_libfunc (umod_optab, SImode, "OTS$REM_UI");
10085 set_optab_libfunc (umod_optab, DImode, "OTS$REM_UL");
10090 /* Initialize the GCC target structure. */
10091 #if TARGET_ABI_OPEN_VMS
10092 # undef TARGET_ATTRIBUTE_TABLE
10093 # define TARGET_ATTRIBUTE_TABLE vms_attribute_table
10094 # undef TARGET_SECTION_TYPE_FLAGS
10095 # define TARGET_SECTION_TYPE_FLAGS vms_section_type_flags
10096 #endif
10098 #undef TARGET_IN_SMALL_DATA_P
10099 #define TARGET_IN_SMALL_DATA_P alpha_in_small_data_p
10101 #if TARGET_ABI_UNICOSMK
10102 # undef TARGET_INSERT_ATTRIBUTES
10103 # define TARGET_INSERT_ATTRIBUTES unicosmk_insert_attributes
10104 # undef TARGET_SECTION_TYPE_FLAGS
10105 # define TARGET_SECTION_TYPE_FLAGS unicosmk_section_type_flags
10106 # undef TARGET_ASM_UNIQUE_SECTION
10107 # define TARGET_ASM_UNIQUE_SECTION unicosmk_unique_section
10108 # undef TARGET_ASM_GLOBALIZE_LABEL
10109 # define TARGET_ASM_GLOBALIZE_LABEL hook_void_FILEptr_constcharptr
10110 # undef TARGET_MUST_PASS_IN_STACK
10111 # define TARGET_MUST_PASS_IN_STACK unicosmk_must_pass_in_stack
10112 #endif
10114 #undef TARGET_ASM_ALIGNED_HI_OP
10115 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
10116 #undef TARGET_ASM_ALIGNED_DI_OP
10117 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
10119 /* Default unaligned ops are provided for ELF systems. To get unaligned
10120 data for non-ELF systems, we have to turn off auto alignment. */
10121 #ifndef OBJECT_FORMAT_ELF
10122 #undef TARGET_ASM_UNALIGNED_HI_OP
10123 #define TARGET_ASM_UNALIGNED_HI_OP "\t.align 0\n\t.word\t"
10124 #undef TARGET_ASM_UNALIGNED_SI_OP
10125 #define TARGET_ASM_UNALIGNED_SI_OP "\t.align 0\n\t.long\t"
10126 #undef TARGET_ASM_UNALIGNED_DI_OP
10127 #define TARGET_ASM_UNALIGNED_DI_OP "\t.align 0\n\t.quad\t"
10128 #endif
10130 #ifdef OBJECT_FORMAT_ELF
10131 #undef TARGET_ASM_SELECT_RTX_SECTION
10132 #define TARGET_ASM_SELECT_RTX_SECTION alpha_elf_select_rtx_section
10133 #endif
10135 #undef TARGET_ASM_FUNCTION_END_PROLOGUE
10136 #define TARGET_ASM_FUNCTION_END_PROLOGUE alpha_output_function_end_prologue
10138 #undef TARGET_INIT_LIBFUNCS
10139 #define TARGET_INIT_LIBFUNCS alpha_init_libfuncs
10141 #if TARGET_ABI_UNICOSMK
10142 #undef TARGET_ASM_FILE_START
10143 #define TARGET_ASM_FILE_START unicosmk_file_start
10144 #undef TARGET_ASM_FILE_END
10145 #define TARGET_ASM_FILE_END unicosmk_file_end
10146 #else
10147 #undef TARGET_ASM_FILE_START
10148 #define TARGET_ASM_FILE_START alpha_file_start
10149 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
10150 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
10151 #endif
10153 #undef TARGET_SCHED_ADJUST_COST
10154 #define TARGET_SCHED_ADJUST_COST alpha_adjust_cost
10155 #undef TARGET_SCHED_ISSUE_RATE
10156 #define TARGET_SCHED_ISSUE_RATE alpha_issue_rate
10157 #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
10158 #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE hook_int_void_1
10159 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
10160 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
10161 alpha_multipass_dfa_lookahead
10163 #undef TARGET_HAVE_TLS
10164 #define TARGET_HAVE_TLS HAVE_AS_TLS
10166 #undef TARGET_INIT_BUILTINS
10167 #define TARGET_INIT_BUILTINS alpha_init_builtins
10168 #undef TARGET_EXPAND_BUILTIN
10169 #define TARGET_EXPAND_BUILTIN alpha_expand_builtin
10171 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
10172 #define TARGET_FUNCTION_OK_FOR_SIBCALL alpha_function_ok_for_sibcall
10173 #undef TARGET_CANNOT_COPY_INSN_P
10174 #define TARGET_CANNOT_COPY_INSN_P alpha_cannot_copy_insn_p
10176 #if TARGET_ABI_OSF
10177 #undef TARGET_ASM_OUTPUT_MI_THUNK
10178 #define TARGET_ASM_OUTPUT_MI_THUNK alpha_output_mi_thunk_osf
10179 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
10180 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
10181 #endif
10183 #undef TARGET_RTX_COSTS
10184 #define TARGET_RTX_COSTS alpha_rtx_costs
10185 #undef TARGET_ADDRESS_COST
10186 #define TARGET_ADDRESS_COST hook_int_rtx_0
10188 #undef TARGET_MACHINE_DEPENDENT_REORG
10189 #define TARGET_MACHINE_DEPENDENT_REORG alpha_reorg
10191 #undef TARGET_PROMOTE_FUNCTION_ARGS
10192 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
10193 #undef TARGET_PROMOTE_FUNCTION_RETURN
10194 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
10195 #undef TARGET_PROMOTE_PROTOTYPES
10196 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_false
10197 #undef TARGET_RETURN_IN_MEMORY
10198 #define TARGET_RETURN_IN_MEMORY alpha_return_in_memory
10199 #undef TARGET_PASS_BY_REFERENCE
10200 #define TARGET_PASS_BY_REFERENCE alpha_pass_by_reference
10201 #undef TARGET_SETUP_INCOMING_VARARGS
10202 #define TARGET_SETUP_INCOMING_VARARGS alpha_setup_incoming_varargs
10203 #undef TARGET_STRICT_ARGUMENT_NAMING
10204 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
10205 #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
10206 #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
10207 #undef TARGET_SPLIT_COMPLEX_ARG
10208 #define TARGET_SPLIT_COMPLEX_ARG alpha_split_complex_arg
10209 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
10210 #define TARGET_GIMPLIFY_VA_ARG_EXPR alpha_gimplify_va_arg
10212 #undef TARGET_BUILD_BUILTIN_VA_LIST
10213 #define TARGET_BUILD_BUILTIN_VA_LIST alpha_build_builtin_va_list
10215 struct gcc_target targetm = TARGET_INITIALIZER;
10218 #include "gt-alpha.h"