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