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