Debian Codegraph @

gcc/config/alpha/alpha.cc

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