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