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