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