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