1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2, or (at your
11 option) any later version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the
20 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 MA 02110-1301, USA. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
43 #include "basic-block.h"
44 #include "integrate.h"
50 #include "target-def.h"
51 #include "langhooks.h"
53 #include "cfglayout.h"
54 #include "sched-int.h"
55 #include "tree-gimple.h"
59 #include "xcoffout.h" /* get declarations of xcoff_*_section_name */
62 #include "gstab.h" /* for N_SLINE */
65 #ifndef TARGET_NO_PROTOTYPE
66 #define TARGET_NO_PROTOTYPE 0
69 #define min(A,B) ((A) < (B) ? (A) : (B))
70 #define max(A,B) ((A) > (B) ? (A) : (B))
72 /* Structure used to define the rs6000 stack */
73 typedef struct rs6000_stack {
74 int first_gp_reg_save; /* first callee saved GP register used */
75 int first_fp_reg_save; /* first callee saved FP register used */
76 int first_altivec_reg_save; /* first callee saved AltiVec register used */
77 int lr_save_p; /* true if the link reg needs to be saved */
78 int cr_save_p; /* true if the CR reg needs to be saved */
79 unsigned int vrsave_mask; /* mask of vec registers to save */
80 int toc_save_p; /* true if the TOC needs to be saved */
81 int push_p; /* true if we need to allocate stack space */
82 int calls_p; /* true if the function makes any calls */
83 int world_save_p; /* true if we're saving *everything*:
84 r13-r31, cr, f14-f31, vrsave, v20-v31 */
85 enum rs6000_abi abi; /* which ABI to use */
86 int gp_save_offset; /* offset to save GP regs from initial SP */
87 int fp_save_offset; /* offset to save FP regs from initial SP */
88 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
89 int lr_save_offset; /* offset to save LR from initial SP */
90 int cr_save_offset; /* offset to save CR from initial SP */
91 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
92 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
93 int toc_save_offset; /* offset to save the TOC pointer */
94 int varargs_save_offset; /* offset to save the varargs registers */
95 int ehrd_offset; /* offset to EH return data */
96 int reg_size; /* register size (4 or 8) */
97 HOST_WIDE_INT vars_size; /* variable save area size */
98 int parm_size; /* outgoing parameter size */
99 int save_size; /* save area size */
100 int fixed_size; /* fixed size of stack frame */
101 int gp_size; /* size of saved GP registers */
102 int fp_size; /* size of saved FP registers */
103 int altivec_size; /* size of saved AltiVec registers */
104 int cr_size; /* size to hold CR if not in save_size */
105 int lr_size; /* size to hold LR if not in save_size */
106 int vrsave_size; /* size to hold VRSAVE if not in save_size */
107 int altivec_padding_size; /* size of altivec alignment padding if
109 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
110 int spe_padding_size;
111 int toc_size; /* size to hold TOC if not in save_size */
112 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
113 int spe_64bit_regs_used;
116 /* A C structure for machine-specific, per-function data.
117 This is added to the cfun structure. */
118 typedef struct machine_function GTY(())
120 /* Flags if __builtin_return_address (n) with n >= 1 was used. */
121 int ra_needs_full_frame;
122 /* Some local-dynamic symbol. */
123 const char *some_ld_name;
124 /* Whether the instruction chain has been scanned already. */
125 int insn_chain_scanned_p;
126 /* Flags if __builtin_return_address (0) was used. */
128 /* Offset from virtual_stack_vars_rtx to the start of the ABI_V4
129 varargs save area. */
130 HOST_WIDE_INT varargs_save_offset;
133 /* Target cpu type */
135 enum processor_type rs6000_cpu;
136 struct rs6000_cpu_select rs6000_select[3] =
138 /* switch name, tune arch */
139 { (const char *)0, "--with-cpu=", 1, 1 },
140 { (const char *)0, "-mcpu=", 1, 1 },
141 { (const char *)0, "-mtune=", 1, 0 },
144 /* Always emit branch hint bits. */
145 static GTY(()) bool rs6000_always_hint;
147 /* Schedule instructions for group formation. */
148 static GTY(()) bool rs6000_sched_groups;
150 /* Support for -msched-costly-dep option. */
151 const char *rs6000_sched_costly_dep_str;
152 enum rs6000_dependence_cost rs6000_sched_costly_dep;
154 /* Support for -minsert-sched-nops option. */
155 const char *rs6000_sched_insert_nops_str;
156 enum rs6000_nop_insertion rs6000_sched_insert_nops;
158 /* Support targetm.vectorize.builtin_mask_for_load. */
159 static GTY(()) tree altivec_builtin_mask_for_load;
161 /* Size of long double */
162 int rs6000_long_double_type_size;
164 /* Whether -mabi=altivec has appeared */
165 int rs6000_altivec_abi;
167 /* Nonzero if we want SPE ABI extensions. */
170 /* Nonzero if floating point operations are done in the GPRs. */
171 int rs6000_float_gprs = 0;
173 /* Nonzero if we want Darwin's struct-by-value-in-regs ABI. */
174 int rs6000_darwin64_abi;
176 /* Set to nonzero once AIX common-mode calls have been defined. */
177 static GTY(()) int common_mode_defined;
179 /* Save information from a "cmpxx" operation until the branch or scc is
181 rtx rs6000_compare_op0, rs6000_compare_op1;
182 int rs6000_compare_fp_p;
184 /* Label number of label created for -mrelocatable, to call to so we can
185 get the address of the GOT section */
186 int rs6000_pic_labelno;
189 /* Which abi to adhere to */
190 const char *rs6000_abi_name;
192 /* Semantics of the small data area */
193 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
195 /* Which small data model to use */
196 const char *rs6000_sdata_name = (char *)0;
198 /* Counter for labels which are to be placed in .fixup. */
199 int fixuplabelno = 0;
202 /* Bit size of immediate TLS offsets and string from which it is decoded. */
203 int rs6000_tls_size = 32;
204 const char *rs6000_tls_size_string;
206 /* ABI enumeration available for subtarget to use. */
207 enum rs6000_abi rs6000_current_abi;
209 /* Whether to use variant of AIX ABI for PowerPC64 Linux. */
213 const char *rs6000_debug_name;
214 int rs6000_debug_stack; /* debug stack applications */
215 int rs6000_debug_arg; /* debug argument handling */
217 /* Value is TRUE if register/mode pair is acceptable. */
218 bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
220 /* Built in types. */
222 tree rs6000_builtin_types[RS6000_BTI_MAX];
223 tree rs6000_builtin_decls[RS6000_BUILTIN_COUNT];
225 const char *rs6000_traceback_name;
227 traceback_default = 0,
233 /* Flag to say the TOC is initialized */
235 char toc_label_name[10];
237 /* Control alignment for fields within structures. */
238 /* String from -malign-XXXXX. */
239 int rs6000_alignment_flags;
241 /* True for any options that were explicitly set. */
243 bool aix_struct_ret; /* True if -maix-struct-ret was used. */
244 bool alignment; /* True if -malign- was used. */
245 bool abi; /* True if -mabi= was used. */
246 bool spe; /* True if -mspe= was used. */
247 bool float_gprs; /* True if -mfloat-gprs= was used. */
248 bool isel; /* True if -misel was used. */
249 bool long_double; /* True if -mlong-double- was used. */
250 } rs6000_explicit_options;
252 struct builtin_description
254 /* mask is not const because we're going to alter it below. This
255 nonsense will go away when we rewrite the -march infrastructure
256 to give us more target flag bits. */
258 const enum insn_code icode;
259 const char *const name;
260 const enum rs6000_builtins code;
263 /* Target cpu costs. */
265 struct processor_costs {
266 const int mulsi; /* cost of SImode multiplication. */
267 const int mulsi_const; /* cost of SImode multiplication by constant. */
268 const int mulsi_const9; /* cost of SImode mult by short constant. */
269 const int muldi; /* cost of DImode multiplication. */
270 const int divsi; /* cost of SImode division. */
271 const int divdi; /* cost of DImode division. */
272 const int fp; /* cost of simple SFmode and DFmode insns. */
273 const int dmul; /* cost of DFmode multiplication (and fmadd). */
274 const int sdiv; /* cost of SFmode division (fdivs). */
275 const int ddiv; /* cost of DFmode division (fdiv). */
278 const struct processor_costs *rs6000_cost;
280 /* Processor costs (relative to an add) */
282 /* Instruction size costs on 32bit processors. */
284 struct processor_costs size32_cost = {
285 COSTS_N_INSNS (1), /* mulsi */
286 COSTS_N_INSNS (1), /* mulsi_const */
287 COSTS_N_INSNS (1), /* mulsi_const9 */
288 COSTS_N_INSNS (1), /* muldi */
289 COSTS_N_INSNS (1), /* divsi */
290 COSTS_N_INSNS (1), /* divdi */
291 COSTS_N_INSNS (1), /* fp */
292 COSTS_N_INSNS (1), /* dmul */
293 COSTS_N_INSNS (1), /* sdiv */
294 COSTS_N_INSNS (1), /* ddiv */
297 /* Instruction size costs on 64bit processors. */
299 struct processor_costs size64_cost = {
300 COSTS_N_INSNS (1), /* mulsi */
301 COSTS_N_INSNS (1), /* mulsi_const */
302 COSTS_N_INSNS (1), /* mulsi_const9 */
303 COSTS_N_INSNS (1), /* muldi */
304 COSTS_N_INSNS (1), /* divsi */
305 COSTS_N_INSNS (1), /* divdi */
306 COSTS_N_INSNS (1), /* fp */
307 COSTS_N_INSNS (1), /* dmul */
308 COSTS_N_INSNS (1), /* sdiv */
309 COSTS_N_INSNS (1), /* ddiv */
312 /* Instruction costs on RIOS1 processors. */
314 struct processor_costs rios1_cost = {
315 COSTS_N_INSNS (5), /* mulsi */
316 COSTS_N_INSNS (4), /* mulsi_const */
317 COSTS_N_INSNS (3), /* mulsi_const9 */
318 COSTS_N_INSNS (5), /* muldi */
319 COSTS_N_INSNS (19), /* divsi */
320 COSTS_N_INSNS (19), /* divdi */
321 COSTS_N_INSNS (2), /* fp */
322 COSTS_N_INSNS (2), /* dmul */
323 COSTS_N_INSNS (19), /* sdiv */
324 COSTS_N_INSNS (19), /* ddiv */
327 /* Instruction costs on RIOS2 processors. */
329 struct processor_costs rios2_cost = {
330 COSTS_N_INSNS (2), /* mulsi */
331 COSTS_N_INSNS (2), /* mulsi_const */
332 COSTS_N_INSNS (2), /* mulsi_const9 */
333 COSTS_N_INSNS (2), /* muldi */
334 COSTS_N_INSNS (13), /* divsi */
335 COSTS_N_INSNS (13), /* divdi */
336 COSTS_N_INSNS (2), /* fp */
337 COSTS_N_INSNS (2), /* dmul */
338 COSTS_N_INSNS (17), /* sdiv */
339 COSTS_N_INSNS (17), /* ddiv */
342 /* Instruction costs on RS64A processors. */
344 struct processor_costs rs64a_cost = {
345 COSTS_N_INSNS (20), /* mulsi */
346 COSTS_N_INSNS (12), /* mulsi_const */
347 COSTS_N_INSNS (8), /* mulsi_const9 */
348 COSTS_N_INSNS (34), /* muldi */
349 COSTS_N_INSNS (65), /* divsi */
350 COSTS_N_INSNS (67), /* divdi */
351 COSTS_N_INSNS (4), /* fp */
352 COSTS_N_INSNS (4), /* dmul */
353 COSTS_N_INSNS (31), /* sdiv */
354 COSTS_N_INSNS (31), /* ddiv */
357 /* Instruction costs on MPCCORE processors. */
359 struct processor_costs mpccore_cost = {
360 COSTS_N_INSNS (2), /* mulsi */
361 COSTS_N_INSNS (2), /* mulsi_const */
362 COSTS_N_INSNS (2), /* mulsi_const9 */
363 COSTS_N_INSNS (2), /* muldi */
364 COSTS_N_INSNS (6), /* divsi */
365 COSTS_N_INSNS (6), /* divdi */
366 COSTS_N_INSNS (4), /* fp */
367 COSTS_N_INSNS (5), /* dmul */
368 COSTS_N_INSNS (10), /* sdiv */
369 COSTS_N_INSNS (17), /* ddiv */
372 /* Instruction costs on PPC403 processors. */
374 struct processor_costs ppc403_cost = {
375 COSTS_N_INSNS (4), /* mulsi */
376 COSTS_N_INSNS (4), /* mulsi_const */
377 COSTS_N_INSNS (4), /* mulsi_const9 */
378 COSTS_N_INSNS (4), /* muldi */
379 COSTS_N_INSNS (33), /* divsi */
380 COSTS_N_INSNS (33), /* divdi */
381 COSTS_N_INSNS (11), /* fp */
382 COSTS_N_INSNS (11), /* dmul */
383 COSTS_N_INSNS (11), /* sdiv */
384 COSTS_N_INSNS (11), /* ddiv */
387 /* Instruction costs on PPC405 processors. */
389 struct processor_costs ppc405_cost = {
390 COSTS_N_INSNS (5), /* mulsi */
391 COSTS_N_INSNS (4), /* mulsi_const */
392 COSTS_N_INSNS (3), /* mulsi_const9 */
393 COSTS_N_INSNS (5), /* muldi */
394 COSTS_N_INSNS (35), /* divsi */
395 COSTS_N_INSNS (35), /* divdi */
396 COSTS_N_INSNS (11), /* fp */
397 COSTS_N_INSNS (11), /* dmul */
398 COSTS_N_INSNS (11), /* sdiv */
399 COSTS_N_INSNS (11), /* ddiv */
402 /* Instruction costs on PPC440 processors. */
404 struct processor_costs ppc440_cost = {
405 COSTS_N_INSNS (3), /* mulsi */
406 COSTS_N_INSNS (2), /* mulsi_const */
407 COSTS_N_INSNS (2), /* mulsi_const9 */
408 COSTS_N_INSNS (3), /* muldi */
409 COSTS_N_INSNS (34), /* divsi */
410 COSTS_N_INSNS (34), /* divdi */
411 COSTS_N_INSNS (5), /* fp */
412 COSTS_N_INSNS (5), /* dmul */
413 COSTS_N_INSNS (19), /* sdiv */
414 COSTS_N_INSNS (33), /* ddiv */
417 /* Instruction costs on PPC601 processors. */
419 struct processor_costs ppc601_cost = {
420 COSTS_N_INSNS (5), /* mulsi */
421 COSTS_N_INSNS (5), /* mulsi_const */
422 COSTS_N_INSNS (5), /* mulsi_const9 */
423 COSTS_N_INSNS (5), /* muldi */
424 COSTS_N_INSNS (36), /* divsi */
425 COSTS_N_INSNS (36), /* divdi */
426 COSTS_N_INSNS (4), /* fp */
427 COSTS_N_INSNS (5), /* dmul */
428 COSTS_N_INSNS (17), /* sdiv */
429 COSTS_N_INSNS (31), /* ddiv */
432 /* Instruction costs on PPC603 processors. */
434 struct processor_costs ppc603_cost = {
435 COSTS_N_INSNS (5), /* mulsi */
436 COSTS_N_INSNS (3), /* mulsi_const */
437 COSTS_N_INSNS (2), /* mulsi_const9 */
438 COSTS_N_INSNS (5), /* muldi */
439 COSTS_N_INSNS (37), /* divsi */
440 COSTS_N_INSNS (37), /* divdi */
441 COSTS_N_INSNS (3), /* fp */
442 COSTS_N_INSNS (4), /* dmul */
443 COSTS_N_INSNS (18), /* sdiv */
444 COSTS_N_INSNS (33), /* ddiv */
447 /* Instruction costs on PPC604 processors. */
449 struct processor_costs ppc604_cost = {
450 COSTS_N_INSNS (4), /* mulsi */
451 COSTS_N_INSNS (4), /* mulsi_const */
452 COSTS_N_INSNS (4), /* mulsi_const9 */
453 COSTS_N_INSNS (4), /* muldi */
454 COSTS_N_INSNS (20), /* divsi */
455 COSTS_N_INSNS (20), /* divdi */
456 COSTS_N_INSNS (3), /* fp */
457 COSTS_N_INSNS (3), /* dmul */
458 COSTS_N_INSNS (18), /* sdiv */
459 COSTS_N_INSNS (32), /* ddiv */
462 /* Instruction costs on PPC604e processors. */
464 struct processor_costs ppc604e_cost = {
465 COSTS_N_INSNS (2), /* mulsi */
466 COSTS_N_INSNS (2), /* mulsi_const */
467 COSTS_N_INSNS (2), /* mulsi_const9 */
468 COSTS_N_INSNS (2), /* muldi */
469 COSTS_N_INSNS (20), /* divsi */
470 COSTS_N_INSNS (20), /* divdi */
471 COSTS_N_INSNS (3), /* fp */
472 COSTS_N_INSNS (3), /* dmul */
473 COSTS_N_INSNS (18), /* sdiv */
474 COSTS_N_INSNS (32), /* ddiv */
477 /* Instruction costs on PPC620 processors. */
479 struct processor_costs ppc620_cost = {
480 COSTS_N_INSNS (5), /* mulsi */
481 COSTS_N_INSNS (4), /* mulsi_const */
482 COSTS_N_INSNS (3), /* mulsi_const9 */
483 COSTS_N_INSNS (7), /* muldi */
484 COSTS_N_INSNS (21), /* divsi */
485 COSTS_N_INSNS (37), /* divdi */
486 COSTS_N_INSNS (3), /* fp */
487 COSTS_N_INSNS (3), /* dmul */
488 COSTS_N_INSNS (18), /* sdiv */
489 COSTS_N_INSNS (32), /* ddiv */
492 /* Instruction costs on PPC630 processors. */
494 struct processor_costs ppc630_cost = {
495 COSTS_N_INSNS (5), /* mulsi */
496 COSTS_N_INSNS (4), /* mulsi_const */
497 COSTS_N_INSNS (3), /* mulsi_const9 */
498 COSTS_N_INSNS (7), /* muldi */
499 COSTS_N_INSNS (21), /* divsi */
500 COSTS_N_INSNS (37), /* divdi */
501 COSTS_N_INSNS (3), /* fp */
502 COSTS_N_INSNS (3), /* dmul */
503 COSTS_N_INSNS (17), /* sdiv */
504 COSTS_N_INSNS (21), /* ddiv */
507 /* Instruction costs on PPC750 and PPC7400 processors. */
509 struct processor_costs ppc750_cost = {
510 COSTS_N_INSNS (5), /* mulsi */
511 COSTS_N_INSNS (3), /* mulsi_const */
512 COSTS_N_INSNS (2), /* mulsi_const9 */
513 COSTS_N_INSNS (5), /* muldi */
514 COSTS_N_INSNS (17), /* divsi */
515 COSTS_N_INSNS (17), /* divdi */
516 COSTS_N_INSNS (3), /* fp */
517 COSTS_N_INSNS (3), /* dmul */
518 COSTS_N_INSNS (17), /* sdiv */
519 COSTS_N_INSNS (31), /* ddiv */
522 /* Instruction costs on PPC7450 processors. */
524 struct processor_costs ppc7450_cost = {
525 COSTS_N_INSNS (4), /* mulsi */
526 COSTS_N_INSNS (3), /* mulsi_const */
527 COSTS_N_INSNS (3), /* mulsi_const9 */
528 COSTS_N_INSNS (4), /* muldi */
529 COSTS_N_INSNS (23), /* divsi */
530 COSTS_N_INSNS (23), /* divdi */
531 COSTS_N_INSNS (5), /* fp */
532 COSTS_N_INSNS (5), /* dmul */
533 COSTS_N_INSNS (21), /* sdiv */
534 COSTS_N_INSNS (35), /* ddiv */
537 /* Instruction costs on PPC8540 processors. */
539 struct processor_costs ppc8540_cost = {
540 COSTS_N_INSNS (4), /* mulsi */
541 COSTS_N_INSNS (4), /* mulsi_const */
542 COSTS_N_INSNS (4), /* mulsi_const9 */
543 COSTS_N_INSNS (4), /* muldi */
544 COSTS_N_INSNS (19), /* divsi */
545 COSTS_N_INSNS (19), /* divdi */
546 COSTS_N_INSNS (4), /* fp */
547 COSTS_N_INSNS (4), /* dmul */
548 COSTS_N_INSNS (29), /* sdiv */
549 COSTS_N_INSNS (29), /* ddiv */
552 /* Instruction costs on POWER4 and POWER5 processors. */
554 struct processor_costs power4_cost = {
555 COSTS_N_INSNS (3), /* mulsi */
556 COSTS_N_INSNS (2), /* mulsi_const */
557 COSTS_N_INSNS (2), /* mulsi_const9 */
558 COSTS_N_INSNS (4), /* muldi */
559 COSTS_N_INSNS (18), /* divsi */
560 COSTS_N_INSNS (34), /* divdi */
561 COSTS_N_INSNS (3), /* fp */
562 COSTS_N_INSNS (3), /* dmul */
563 COSTS_N_INSNS (17), /* sdiv */
564 COSTS_N_INSNS (17), /* ddiv */
568 static bool rs6000_function_ok_for_sibcall (tree, tree);
569 static const char *rs6000_invalid_within_doloop (rtx);
570 static rtx rs6000_generate_compare (enum rtx_code);
571 static void rs6000_maybe_dead (rtx);
572 static void rs6000_emit_stack_tie (void);
573 static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
574 static rtx spe_synthesize_frame_save (rtx);
575 static bool spe_func_has_64bit_regs_p (void);
576 static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
578 static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
579 static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
580 static unsigned rs6000_hash_constant (rtx);
581 static unsigned toc_hash_function (const void *);
582 static int toc_hash_eq (const void *, const void *);
583 static int constant_pool_expr_1 (rtx, int *, int *);
584 static bool constant_pool_expr_p (rtx);
585 static bool legitimate_indexed_address_p (rtx, int);
586 static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
587 static struct machine_function * rs6000_init_machine_status (void);
588 static bool rs6000_assemble_integer (rtx, unsigned int, int);
589 static bool no_global_regs_above (int);
590 #ifdef HAVE_GAS_HIDDEN
591 static void rs6000_assemble_visibility (tree, int);
593 static int rs6000_ra_ever_killed (void);
594 static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
595 static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
596 static void rs6000_eliminate_indexed_memrefs (rtx operands[2]);
597 static const char *rs6000_mangle_fundamental_type (tree);
598 extern const struct attribute_spec rs6000_attribute_table[];
599 static void rs6000_set_default_type_attributes (tree);
600 static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
601 static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
602 static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
604 static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
605 static bool rs6000_return_in_memory (tree, tree);
606 static void rs6000_file_start (void);
608 static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
609 static void rs6000_elf_asm_out_constructor (rtx, int);
610 static void rs6000_elf_asm_out_destructor (rtx, int);
611 static void rs6000_elf_end_indicate_exec_stack (void) ATTRIBUTE_UNUSED;
612 static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
613 static void rs6000_elf_unique_section (tree, int);
614 static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
615 unsigned HOST_WIDE_INT);
616 static void rs6000_elf_encode_section_info (tree, rtx, int)
620 static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
621 static void rs6000_xcoff_asm_named_section (const char *, unsigned int, tree);
622 static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
623 static void rs6000_xcoff_unique_section (tree, int);
624 static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
625 unsigned HOST_WIDE_INT);
626 static const char * rs6000_xcoff_strip_name_encoding (const char *);
627 static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
628 static void rs6000_xcoff_file_start (void);
629 static void rs6000_xcoff_file_end (void);
631 static int rs6000_variable_issue (FILE *, int, rtx, int);
632 static bool rs6000_rtx_costs (rtx, int, int, int *);
633 static int rs6000_adjust_cost (rtx, rtx, rtx, int);
634 static bool is_microcoded_insn (rtx);
635 static int is_dispatch_slot_restricted (rtx);
636 static bool is_cracked_insn (rtx);
637 static bool is_branch_slot_insn (rtx);
638 static int rs6000_adjust_priority (rtx, int);
639 static int rs6000_issue_rate (void);
640 static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
641 static rtx get_next_active_insn (rtx, rtx);
642 static bool insn_terminates_group_p (rtx , enum group_termination);
643 static bool is_costly_group (rtx *, rtx);
644 static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
645 static int redefine_groups (FILE *, int, rtx, rtx);
646 static int pad_groups (FILE *, int, rtx, rtx);
647 static void rs6000_sched_finish (FILE *, int);
648 static int rs6000_use_sched_lookahead (void);
649 static tree rs6000_builtin_mask_for_load (void);
651 static void def_builtin (int, const char *, tree, int);
652 static void rs6000_init_builtins (void);
653 static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
654 static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
655 static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
656 static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
657 static void altivec_init_builtins (void);
658 static void rs6000_common_init_builtins (void);
659 static void rs6000_init_libfuncs (void);
661 static void enable_mask_for_builtins (struct builtin_description *, int,
662 enum rs6000_builtins,
663 enum rs6000_builtins);
664 static tree build_opaque_vector_type (tree, int);
665 static void spe_init_builtins (void);
666 static rtx spe_expand_builtin (tree, rtx, bool *);
667 static rtx spe_expand_stv_builtin (enum insn_code, tree);
668 static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
669 static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
670 static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
671 static rs6000_stack_t *rs6000_stack_info (void);
672 static void debug_stack_info (rs6000_stack_t *);
674 static rtx altivec_expand_builtin (tree, rtx, bool *);
675 static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
676 static rtx altivec_expand_st_builtin (tree, rtx, bool *);
677 static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
678 static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
679 static rtx altivec_expand_predicate_builtin (enum insn_code,
680 const char *, tree, rtx);
681 static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
682 static rtx altivec_expand_stv_builtin (enum insn_code, tree);
683 static rtx altivec_expand_vec_init_builtin (tree, tree, rtx);
684 static rtx altivec_expand_vec_set_builtin (tree);
685 static rtx altivec_expand_vec_ext_builtin (tree, rtx);
686 static int get_element_number (tree, tree);
687 static bool rs6000_handle_option (size_t, const char *, int);
688 static void rs6000_parse_tls_size_option (void);
689 static void rs6000_parse_yes_no_option (const char *, const char *, int *);
690 static int first_altivec_reg_to_save (void);
691 static unsigned int compute_vrsave_mask (void);
692 static void compute_save_world_info (rs6000_stack_t *info_ptr);
693 static void is_altivec_return_reg (rtx, void *);
694 static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
695 int easy_vector_constant (rtx, enum machine_mode);
696 static bool rs6000_is_opaque_type (tree);
697 static rtx rs6000_dwarf_register_span (rtx);
698 static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
699 static void rs6000_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
700 static rtx rs6000_tls_get_addr (void);
701 static rtx rs6000_got_sym (void);
702 static int rs6000_tls_symbol_ref_1 (rtx *, void *);
703 static const char *rs6000_get_some_local_dynamic_name (void);
704 static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
705 static rtx rs6000_complex_function_value (enum machine_mode);
706 static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
707 enum machine_mode, tree);
708 static void rs6000_darwin64_record_arg_advance_flush (CUMULATIVE_ARGS *,
710 static void rs6000_darwin64_record_arg_advance_recurse (CUMULATIVE_ARGS *,
711 tree, HOST_WIDE_INT);
712 static void rs6000_darwin64_record_arg_flush (CUMULATIVE_ARGS *,
715 static void rs6000_darwin64_record_arg_recurse (CUMULATIVE_ARGS *,
718 static rtx rs6000_darwin64_record_arg (CUMULATIVE_ARGS *, tree, int, bool);
719 static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int);
720 static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
721 static void setup_incoming_varargs (CUMULATIVE_ARGS *,
722 enum machine_mode, tree,
724 static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
726 static int rs6000_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
728 static const char *invalid_arg_for_unprototyped_fn (tree, tree, tree);
730 static void macho_branch_islands (void);
731 static void add_compiler_branch_island (tree, tree, int);
732 static int no_previous_def (tree function_name);
733 static tree get_prev_label (tree function_name);
734 static void rs6000_darwin_file_start (void);
737 static tree rs6000_build_builtin_va_list (void);
738 static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *);
739 static bool rs6000_must_pass_in_stack (enum machine_mode, tree);
740 static bool rs6000_vector_mode_supported_p (enum machine_mode);
741 static int get_vec_cmp_insn (enum rtx_code, enum machine_mode,
743 static rtx rs6000_emit_vector_compare (enum rtx_code, rtx, rtx,
745 static int get_vsel_insn (enum machine_mode);
746 static void rs6000_emit_vector_select (rtx, rtx, rtx, rtx);
747 static tree rs6000_stack_protect_fail (void);
749 const int INSN_NOT_AVAILABLE = -1;
750 static enum machine_mode rs6000_eh_return_filter_mode (void);
752 /* Hash table stuff for keeping track of TOC entries. */
754 struct toc_hash_struct GTY(())
756 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
757 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
759 enum machine_mode key_mode;
763 static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
765 /* Default register names. */
766 char rs6000_reg_names[][8] =
768 "0", "1", "2", "3", "4", "5", "6", "7",
769 "8", "9", "10", "11", "12", "13", "14", "15",
770 "16", "17", "18", "19", "20", "21", "22", "23",
771 "24", "25", "26", "27", "28", "29", "30", "31",
772 "0", "1", "2", "3", "4", "5", "6", "7",
773 "8", "9", "10", "11", "12", "13", "14", "15",
774 "16", "17", "18", "19", "20", "21", "22", "23",
775 "24", "25", "26", "27", "28", "29", "30", "31",
776 "mq", "lr", "ctr","ap",
777 "0", "1", "2", "3", "4", "5", "6", "7",
779 /* AltiVec registers. */
780 "0", "1", "2", "3", "4", "5", "6", "7",
781 "8", "9", "10", "11", "12", "13", "14", "15",
782 "16", "17", "18", "19", "20", "21", "22", "23",
783 "24", "25", "26", "27", "28", "29", "30", "31",
786 "spe_acc", "spefscr",
787 /* Soft frame pointer. */
791 #ifdef TARGET_REGNAMES
792 static const char alt_reg_names[][8] =
794 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
795 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
796 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
797 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
798 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
799 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
800 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
801 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
802 "mq", "lr", "ctr", "ap",
803 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
805 /* AltiVec registers. */
806 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
807 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
808 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
809 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
812 "spe_acc", "spefscr",
813 /* Soft frame pointer. */
818 #ifndef MASK_STRICT_ALIGN
819 #define MASK_STRICT_ALIGN 0
821 #ifndef TARGET_PROFILE_KERNEL
822 #define TARGET_PROFILE_KERNEL 0
825 /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
826 #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
828 /* Initialize the GCC target structure. */
829 #undef TARGET_ATTRIBUTE_TABLE
830 #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
831 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
832 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
834 #undef TARGET_ASM_ALIGNED_DI_OP
835 #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
837 /* Default unaligned ops are only provided for ELF. Find the ops needed
838 for non-ELF systems. */
839 #ifndef OBJECT_FORMAT_ELF
841 /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
843 #undef TARGET_ASM_UNALIGNED_HI_OP
844 #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
845 #undef TARGET_ASM_UNALIGNED_SI_OP
846 #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
847 #undef TARGET_ASM_UNALIGNED_DI_OP
848 #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
851 #undef TARGET_ASM_UNALIGNED_HI_OP
852 #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
853 #undef TARGET_ASM_UNALIGNED_SI_OP
854 #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
855 #undef TARGET_ASM_UNALIGNED_DI_OP
856 #define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
857 #undef TARGET_ASM_ALIGNED_DI_OP
858 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
862 /* This hook deals with fixups for relocatable code and DI-mode objects
864 #undef TARGET_ASM_INTEGER
865 #define TARGET_ASM_INTEGER rs6000_assemble_integer
867 #ifdef HAVE_GAS_HIDDEN
868 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
869 #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
872 #undef TARGET_HAVE_TLS
873 #define TARGET_HAVE_TLS HAVE_AS_TLS
875 #undef TARGET_CANNOT_FORCE_CONST_MEM
876 #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
878 #undef TARGET_ASM_FUNCTION_PROLOGUE
879 #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
880 #undef TARGET_ASM_FUNCTION_EPILOGUE
881 #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
883 #undef TARGET_SCHED_VARIABLE_ISSUE
884 #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
886 #undef TARGET_SCHED_ISSUE_RATE
887 #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
888 #undef TARGET_SCHED_ADJUST_COST
889 #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
890 #undef TARGET_SCHED_ADJUST_PRIORITY
891 #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
892 #undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
893 #define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
894 #undef TARGET_SCHED_FINISH
895 #define TARGET_SCHED_FINISH rs6000_sched_finish
897 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
898 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
900 #undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
901 #define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load
903 #undef TARGET_INIT_BUILTINS
904 #define TARGET_INIT_BUILTINS rs6000_init_builtins
906 #undef TARGET_EXPAND_BUILTIN
907 #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
909 #undef TARGET_MANGLE_FUNDAMENTAL_TYPE
910 #define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
912 #undef TARGET_INIT_LIBFUNCS
913 #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
916 #undef TARGET_BINDS_LOCAL_P
917 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
920 #undef TARGET_ASM_OUTPUT_MI_THUNK
921 #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
923 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
924 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
926 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
927 #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
929 #undef TARGET_INVALID_WITHIN_DOLOOP
930 #define TARGET_INVALID_WITHIN_DOLOOP rs6000_invalid_within_doloop
932 #undef TARGET_RTX_COSTS
933 #define TARGET_RTX_COSTS rs6000_rtx_costs
934 #undef TARGET_ADDRESS_COST
935 #define TARGET_ADDRESS_COST hook_int_rtx_0
937 #undef TARGET_VECTOR_OPAQUE_P
938 #define TARGET_VECTOR_OPAQUE_P rs6000_is_opaque_type
940 #undef TARGET_DWARF_REGISTER_SPAN
941 #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
943 /* On rs6000, function arguments are promoted, as are function return
945 #undef TARGET_PROMOTE_FUNCTION_ARGS
946 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
947 #undef TARGET_PROMOTE_FUNCTION_RETURN
948 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
950 #undef TARGET_RETURN_IN_MEMORY
951 #define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
953 #undef TARGET_SETUP_INCOMING_VARARGS
954 #define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
956 /* Always strict argument naming on rs6000. */
957 #undef TARGET_STRICT_ARGUMENT_NAMING
958 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
959 #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
960 #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
961 #undef TARGET_SPLIT_COMPLEX_ARG
962 #define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
963 #undef TARGET_MUST_PASS_IN_STACK
964 #define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
965 #undef TARGET_PASS_BY_REFERENCE
966 #define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
967 #undef TARGET_ARG_PARTIAL_BYTES
968 #define TARGET_ARG_PARTIAL_BYTES rs6000_arg_partial_bytes
970 #undef TARGET_BUILD_BUILTIN_VA_LIST
971 #define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
973 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
974 #define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
976 #undef TARGET_EH_RETURN_FILTER_MODE
977 #define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
979 #undef TARGET_VECTOR_MODE_SUPPORTED_P
980 #define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
982 #undef TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN
983 #define TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN invalid_arg_for_unprototyped_fn
985 #undef TARGET_HANDLE_OPTION
986 #define TARGET_HANDLE_OPTION rs6000_handle_option
988 #undef TARGET_DEFAULT_TARGET_FLAGS
989 #define TARGET_DEFAULT_TARGET_FLAGS \
990 (TARGET_DEFAULT | MASK_SCHED_PROLOG)
992 #undef TARGET_STACK_PROTECT_FAIL
993 #define TARGET_STACK_PROTECT_FAIL rs6000_stack_protect_fail
995 /* MPC604EUM 3.5.2 Weak Consistency between Multiple Processors
996 The PowerPC architecture requires only weak consistency among
997 processors--that is, memory accesses between processors need not be
998 sequentially consistent and memory accesses among processors can occur
999 in any order. The ability to order memory accesses weakly provides
1000 opportunities for more efficient use of the system bus. Unless a
1001 dependency exists, the 604e allows read operations to precede store
1003 #undef TARGET_RELAXED_ORDERING
1004 #define TARGET_RELAXED_ORDERING true
1007 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
1008 #define TARGET_ASM_OUTPUT_DWARF_DTPREL rs6000_output_dwarf_dtprel
1011 struct gcc_target targetm = TARGET_INITIALIZER;
1014 /* Value is 1 if hard register REGNO can hold a value of machine-mode
1017 rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
1019 /* The GPRs can hold any mode, but values bigger than one register
1020 cannot go past R31. */
1021 if (INT_REGNO_P (regno))
1022 return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1);
1024 /* The float registers can only hold floating modes and DImode. */
1025 if (FP_REGNO_P (regno))
1027 (SCALAR_FLOAT_MODE_P (mode)
1028 && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1))
1029 || (GET_MODE_CLASS (mode) == MODE_INT
1030 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD);
1032 /* The CR register can only hold CC modes. */
1033 if (CR_REGNO_P (regno))
1034 return GET_MODE_CLASS (mode) == MODE_CC;
1036 if (XER_REGNO_P (regno))
1037 return mode == PSImode;
1039 /* AltiVec only in AldyVec registers. */
1040 if (ALTIVEC_REGNO_P (regno))
1041 return ALTIVEC_VECTOR_MODE (mode);
1043 /* ...but GPRs can hold SIMD data on the SPE in one register. */
1044 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1047 /* We cannot put TImode anywhere except general register and it must be
1048 able to fit within the register set. */
1050 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1053 /* Initialize rs6000_hard_regno_mode_ok_p table. */
1055 rs6000_init_hard_regno_mode_ok (void)
1059 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
1060 for (m = 0; m < NUM_MACHINE_MODES; ++m)
1061 if (rs6000_hard_regno_mode_ok (r, m))
1062 rs6000_hard_regno_mode_ok_p[m][r] = true;
1065 /* If not otherwise specified by a target, make 'long double' equivalent to
1068 #ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
1069 #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
1072 /* Override command line options. Mostly we process the processor
1073 type and sometimes adjust other TARGET_ options. */
1076 rs6000_override_options (const char *default_cpu)
1079 struct rs6000_cpu_select *ptr;
1082 /* Simplifications for entries below. */
1085 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
1086 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
1089 /* This table occasionally claims that a processor does not support
1090 a particular feature even though it does, but the feature is slower
1091 than the alternative. Thus, it shouldn't be relied on as a
1092 complete description of the processor's support.
1094 Please keep this list in order, and don't forget to update the
1095 documentation in invoke.texi when adding a new processor or
1099 const char *const name; /* Canonical processor name. */
1100 const enum processor_type processor; /* Processor type enum value. */
1101 const int target_enable; /* Target flags to enable. */
1102 } const processor_target_table[]
1103 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1104 {"403", PROCESSOR_PPC403,
1105 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
1106 {"405", PROCESSOR_PPC405,
1107 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_MULHW},
1108 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_MULHW},
1109 {"440", PROCESSOR_PPC440,
1110 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_MULHW},
1111 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_MULHW},
1112 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
1113 {"601", PROCESSOR_PPC601,
1114 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
1115 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1116 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1117 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1118 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1119 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1120 {"620", PROCESSOR_PPC620,
1121 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1122 {"630", PROCESSOR_PPC630,
1123 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1124 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1125 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
1126 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1127 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1128 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1129 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1130 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1131 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1132 /* 8548 has a dummy entry for now. */
1133 {"8548", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1134 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1135 {"970", PROCESSOR_POWER4,
1136 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1137 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
1138 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1139 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1140 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1141 {"G5", PROCESSOR_POWER4,
1142 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1143 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1144 {"power2", PROCESSOR_POWER,
1145 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1146 {"power3", PROCESSOR_PPC630,
1147 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1148 {"power4", PROCESSOR_POWER4,
1149 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
1150 {"power5", PROCESSOR_POWER5,
1151 POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GFXOPT
1152 | MASK_MFCRF | MASK_POPCNTB},
1153 {"power5+", PROCESSOR_POWER5,
1154 POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GFXOPT
1155 | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND},
1156 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
1157 {"powerpc64", PROCESSOR_POWERPC64,
1158 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1159 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1160 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1161 {"rios2", PROCESSOR_RIOS2,
1162 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1163 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1164 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1165 {"rs64", PROCESSOR_RS64A,
1166 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}
1169 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
1171 /* Some OSs don't support saving the high part of 64-bit registers on
1172 context switch. Other OSs don't support saving Altivec registers.
1173 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
1174 settings; if the user wants either, the user must explicitly specify
1175 them and we won't interfere with the user's specification. */
1178 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
1179 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
1180 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
1181 | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND | MASK_MULHW)
1184 rs6000_init_hard_regno_mode_ok ();
1186 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
1187 #ifdef OS_MISSING_POWERPC64
1188 if (OS_MISSING_POWERPC64)
1189 set_masks &= ~MASK_POWERPC64;
1191 #ifdef OS_MISSING_ALTIVEC
1192 if (OS_MISSING_ALTIVEC)
1193 set_masks &= ~MASK_ALTIVEC;
1196 /* Don't override by the processor default if given explicitly. */
1197 set_masks &= ~target_flags_explicit;
1199 /* Identify the processor type. */
1200 rs6000_select[0].string = default_cpu;
1201 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
1203 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
1205 ptr = &rs6000_select[i];
1206 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1208 for (j = 0; j < ptt_size; j++)
1209 if (! strcmp (ptr->string, processor_target_table[j].name))
1211 if (ptr->set_tune_p)
1212 rs6000_cpu = processor_target_table[j].processor;
1214 if (ptr->set_arch_p)
1216 target_flags &= ~set_masks;
1217 target_flags |= (processor_target_table[j].target_enable
1224 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
1231 /* If we are optimizing big endian systems for space, use the load/store
1232 multiple and string instructions. */
1233 if (BYTES_BIG_ENDIAN && optimize_size)
1234 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
1236 /* Don't allow -mmultiple or -mstring on little endian systems
1237 unless the cpu is a 750, because the hardware doesn't support the
1238 instructions used in little endian mode, and causes an alignment
1239 trap. The 750 does not cause an alignment trap (except when the
1240 target is unaligned). */
1242 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
1244 if (TARGET_MULTIPLE)
1246 target_flags &= ~MASK_MULTIPLE;
1247 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
1248 warning (0, "-mmultiple is not supported on little endian systems");
1253 target_flags &= ~MASK_STRING;
1254 if ((target_flags_explicit & MASK_STRING) != 0)
1255 warning (0, "-mstring is not supported on little endian systems");
1259 /* Set debug flags */
1260 if (rs6000_debug_name)
1262 if (! strcmp (rs6000_debug_name, "all"))
1263 rs6000_debug_stack = rs6000_debug_arg = 1;
1264 else if (! strcmp (rs6000_debug_name, "stack"))
1265 rs6000_debug_stack = 1;
1266 else if (! strcmp (rs6000_debug_name, "arg"))
1267 rs6000_debug_arg = 1;
1269 error ("unknown -mdebug-%s switch", rs6000_debug_name);
1272 if (rs6000_traceback_name)
1274 if (! strncmp (rs6000_traceback_name, "full", 4))
1275 rs6000_traceback = traceback_full;
1276 else if (! strncmp (rs6000_traceback_name, "part", 4))
1277 rs6000_traceback = traceback_part;
1278 else if (! strncmp (rs6000_traceback_name, "no", 2))
1279 rs6000_traceback = traceback_none;
1281 error ("unknown -mtraceback arg %qs; expecting %<full%>, %<partial%> or %<none%>",
1282 rs6000_traceback_name);
1285 if (!rs6000_explicit_options.long_double)
1286 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
1288 /* Set Altivec ABI as default for powerpc64 linux. */
1289 if (TARGET_ELF && TARGET_64BIT)
1291 rs6000_altivec_abi = 1;
1292 TARGET_ALTIVEC_VRSAVE = 1;
1295 /* Set the Darwin64 ABI as default for 64-bit Darwin. */
1296 if (DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT)
1298 rs6000_darwin64_abi = 1;
1300 darwin_one_byte_bool = 1;
1302 /* Default to natural alignment, for better performance. */
1303 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1306 /* Handle -mtls-size option. */
1307 rs6000_parse_tls_size_option ();
1309 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1310 SUBTARGET_OVERRIDE_OPTIONS;
1312 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
1313 SUBSUBTARGET_OVERRIDE_OPTIONS;
1315 #ifdef SUB3TARGET_OVERRIDE_OPTIONS
1316 SUB3TARGET_OVERRIDE_OPTIONS;
1322 error ("AltiVec and E500 instructions cannot coexist");
1324 /* The e500 does not have string instructions, and we set
1325 MASK_STRING above when optimizing for size. */
1326 if ((target_flags & MASK_STRING) != 0)
1327 target_flags = target_flags & ~MASK_STRING;
1329 else if (rs6000_select[1].string != NULL)
1331 /* For the powerpc-eabispe configuration, we set all these by
1332 default, so let's unset them if we manually set another
1333 CPU that is not the E500. */
1334 if (!rs6000_explicit_options.abi)
1336 if (!rs6000_explicit_options.spe)
1338 if (!rs6000_explicit_options.float_gprs)
1339 rs6000_float_gprs = 0;
1340 if (!rs6000_explicit_options.isel)
1342 if (!rs6000_explicit_options.long_double)
1343 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
1346 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
1347 && rs6000_cpu != PROCESSOR_POWER5);
1348 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
1349 || rs6000_cpu == PROCESSOR_POWER5);
1351 rs6000_sched_restricted_insns_priority
1352 = (rs6000_sched_groups ? 1 : 0);
1354 /* Handle -msched-costly-dep option. */
1355 rs6000_sched_costly_dep
1356 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
1358 if (rs6000_sched_costly_dep_str)
1360 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
1361 rs6000_sched_costly_dep = no_dep_costly;
1362 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
1363 rs6000_sched_costly_dep = all_deps_costly;
1364 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
1365 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
1366 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
1367 rs6000_sched_costly_dep = store_to_load_dep_costly;
1369 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
1372 /* Handle -minsert-sched-nops option. */
1373 rs6000_sched_insert_nops
1374 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
1376 if (rs6000_sched_insert_nops_str)
1378 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
1379 rs6000_sched_insert_nops = sched_finish_none;
1380 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
1381 rs6000_sched_insert_nops = sched_finish_pad_groups;
1382 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
1383 rs6000_sched_insert_nops = sched_finish_regroup_exact;
1385 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
1388 #ifdef TARGET_REGNAMES
1389 /* If the user desires alternate register names, copy in the
1390 alternate names now. */
1391 if (TARGET_REGNAMES)
1392 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
1395 /* Set aix_struct_return last, after the ABI is determined.
1396 If -maix-struct-return or -msvr4-struct-return was explicitly
1397 used, don't override with the ABI default. */
1398 if (!rs6000_explicit_options.aix_struct_ret)
1399 aix_struct_return = (DEFAULT_ABI != ABI_V4 || DRAFT_V4_STRUCT_RET);
1401 if (TARGET_LONG_DOUBLE_128
1402 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
1403 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
1406 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
1408 /* We can only guarantee the availability of DI pseudo-ops when
1409 assembling for 64-bit targets. */
1412 targetm.asm_out.aligned_op.di = NULL;
1413 targetm.asm_out.unaligned_op.di = NULL;
1416 /* Set branch target alignment, if not optimizing for size. */
1419 if (rs6000_sched_groups)
1421 if (align_functions <= 0)
1422 align_functions = 16;
1423 if (align_jumps <= 0)
1425 if (align_loops <= 0)
1428 if (align_jumps_max_skip <= 0)
1429 align_jumps_max_skip = 15;
1430 if (align_loops_max_skip <= 0)
1431 align_loops_max_skip = 15;
1434 /* Arrange to save and restore machine status around nested functions. */
1435 init_machine_status = rs6000_init_machine_status;
1437 /* We should always be splitting complex arguments, but we can't break
1438 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1439 if (DEFAULT_ABI != ABI_AIX)
1440 targetm.calls.split_complex_arg = NULL;
1442 /* Initialize rs6000_cost with the appropriate target costs. */
1444 rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
1448 case PROCESSOR_RIOS1:
1449 rs6000_cost = &rios1_cost;
1452 case PROCESSOR_RIOS2:
1453 rs6000_cost = &rios2_cost;
1456 case PROCESSOR_RS64A:
1457 rs6000_cost = &rs64a_cost;
1460 case PROCESSOR_MPCCORE:
1461 rs6000_cost = &mpccore_cost;
1464 case PROCESSOR_PPC403:
1465 rs6000_cost = &ppc403_cost;
1468 case PROCESSOR_PPC405:
1469 rs6000_cost = &ppc405_cost;
1472 case PROCESSOR_PPC440:
1473 rs6000_cost = &ppc440_cost;
1476 case PROCESSOR_PPC601:
1477 rs6000_cost = &ppc601_cost;
1480 case PROCESSOR_PPC603:
1481 rs6000_cost = &ppc603_cost;
1484 case PROCESSOR_PPC604:
1485 rs6000_cost = &ppc604_cost;
1488 case PROCESSOR_PPC604e:
1489 rs6000_cost = &ppc604e_cost;
1492 case PROCESSOR_PPC620:
1493 rs6000_cost = &ppc620_cost;
1496 case PROCESSOR_PPC630:
1497 rs6000_cost = &ppc630_cost;
1500 case PROCESSOR_PPC750:
1501 case PROCESSOR_PPC7400:
1502 rs6000_cost = &ppc750_cost;
1505 case PROCESSOR_PPC7450:
1506 rs6000_cost = &ppc7450_cost;
1509 case PROCESSOR_PPC8540:
1510 rs6000_cost = &ppc8540_cost;
1513 case PROCESSOR_POWER4:
1514 case PROCESSOR_POWER5:
1515 rs6000_cost = &power4_cost;
1523 /* Implement targetm.vectorize.builtin_mask_for_load. */
1525 rs6000_builtin_mask_for_load (void)
1528 return altivec_builtin_mask_for_load;
1533 /* Handle generic options of the form -mfoo=yes/no.
1534 NAME is the option name.
1535 VALUE is the option value.
1536 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1537 whether the option value is 'yes' or 'no' respectively. */
1539 rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
1543 else if (!strcmp (value, "yes"))
1545 else if (!strcmp (value, "no"))
1548 error ("unknown -m%s= option specified: '%s'", name, value);
1551 /* Validate and record the size specified with the -mtls-size option. */
1554 rs6000_parse_tls_size_option (void)
1556 if (rs6000_tls_size_string == 0)
1558 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1559 rs6000_tls_size = 16;
1560 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1561 rs6000_tls_size = 32;
1562 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1563 rs6000_tls_size = 64;
1565 error ("bad value %qs for -mtls-size switch", rs6000_tls_size_string);
1569 optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
1571 if (DEFAULT_ABI == ABI_DARWIN)
1572 /* The Darwin libraries never set errno, so we might as well
1573 avoid calling them when that's the only reason we would. */
1574 flag_errno_math = 0;
1576 /* Double growth factor to counter reduced min jump length. */
1577 set_param_value ("max-grow-copy-bb-insns", 16);
1580 /* Implement TARGET_HANDLE_OPTION. */
1583 rs6000_handle_option (size_t code, const char *arg, int value)
1588 target_flags &= ~(MASK_POWER | MASK_POWER2
1589 | MASK_MULTIPLE | MASK_STRING);
1590 target_flags_explicit |= (MASK_POWER | MASK_POWER2
1591 | MASK_MULTIPLE | MASK_STRING);
1593 case OPT_mno_powerpc:
1594 target_flags &= ~(MASK_POWERPC | MASK_PPC_GPOPT
1595 | MASK_PPC_GFXOPT | MASK_POWERPC64);
1596 target_flags_explicit |= (MASK_POWERPC | MASK_PPC_GPOPT
1597 | MASK_PPC_GFXOPT | MASK_POWERPC64);
1600 target_flags &= ~(MASK_MINIMAL_TOC | MASK_NO_FP_IN_TOC
1601 | MASK_NO_SUM_IN_TOC);
1602 target_flags_explicit |= (MASK_MINIMAL_TOC | MASK_NO_FP_IN_TOC
1603 | MASK_NO_SUM_IN_TOC);
1604 #ifdef TARGET_USES_SYSV4_OPT
1605 /* Note, V.4 no longer uses a normal TOC, so make -mfull-toc, be
1606 just the same as -mminimal-toc. */
1607 target_flags |= MASK_MINIMAL_TOC;
1608 target_flags_explicit |= MASK_MINIMAL_TOC;
1612 #ifdef TARGET_USES_SYSV4_OPT
1614 /* Make -mtoc behave like -mminimal-toc. */
1615 target_flags |= MASK_MINIMAL_TOC;
1616 target_flags_explicit |= MASK_MINIMAL_TOC;
1620 #ifdef TARGET_USES_AIX64_OPT
1625 target_flags |= MASK_POWERPC64 | MASK_POWERPC;
1626 target_flags |= ~target_flags_explicit & MASK_PPC_GFXOPT;
1627 target_flags_explicit |= MASK_POWERPC64 | MASK_POWERPC;
1630 #ifdef TARGET_USES_AIX64_OPT
1635 target_flags &= ~MASK_POWERPC64;
1636 target_flags_explicit |= MASK_POWERPC64;
1639 case OPT_minsert_sched_nops_:
1640 rs6000_sched_insert_nops_str = arg;
1643 case OPT_mminimal_toc:
1646 target_flags &= ~(MASK_NO_FP_IN_TOC | MASK_NO_SUM_IN_TOC);
1647 target_flags_explicit |= (MASK_NO_FP_IN_TOC | MASK_NO_SUM_IN_TOC);
1654 target_flags |= (MASK_MULTIPLE | MASK_STRING);
1655 target_flags_explicit |= (MASK_MULTIPLE | MASK_STRING);
1662 target_flags |= (MASK_POWER | MASK_MULTIPLE | MASK_STRING);
1663 target_flags_explicit |= (MASK_POWER | MASK_MULTIPLE | MASK_STRING);
1667 case OPT_mpowerpc_gpopt:
1668 case OPT_mpowerpc_gfxopt:
1671 target_flags |= MASK_POWERPC;
1672 target_flags_explicit |= MASK_POWERPC;
1676 case OPT_maix_struct_return:
1677 case OPT_msvr4_struct_return:
1678 rs6000_explicit_options.aix_struct_ret = true;
1682 rs6000_parse_yes_no_option ("vrsave", arg, &(TARGET_ALTIVEC_VRSAVE));
1686 rs6000_explicit_options.isel = true;
1687 rs6000_parse_yes_no_option ("isel", arg, &(rs6000_isel));
1691 rs6000_explicit_options.spe = true;
1692 rs6000_parse_yes_no_option ("spe", arg, &(rs6000_spe));
1693 /* No SPE means 64-bit long doubles, even if an E500. */
1695 rs6000_long_double_type_size = 64;
1699 rs6000_debug_name = arg;
1702 #ifdef TARGET_USES_SYSV4_OPT
1704 rs6000_abi_name = arg;
1708 rs6000_sdata_name = arg;
1711 case OPT_mtls_size_:
1712 rs6000_tls_size_string = arg;
1715 case OPT_mrelocatable:
1718 target_flags |= MASK_MINIMAL_TOC | MASK_NO_FP_IN_TOC;
1719 target_flags_explicit |= MASK_MINIMAL_TOC | MASK_NO_FP_IN_TOC;
1723 case OPT_mrelocatable_lib:
1726 target_flags |= MASK_RELOCATABLE | MASK_MINIMAL_TOC
1727 | MASK_NO_FP_IN_TOC;
1728 target_flags_explicit |= MASK_RELOCATABLE | MASK_MINIMAL_TOC
1729 | MASK_NO_FP_IN_TOC;
1733 target_flags &= ~MASK_RELOCATABLE;
1734 target_flags_explicit |= MASK_RELOCATABLE;
1740 rs6000_explicit_options.abi = true;
1741 if (!strcmp (arg, "altivec"))
1743 rs6000_altivec_abi = 1;
1746 else if (! strcmp (arg, "no-altivec"))
1747 rs6000_altivec_abi = 0;
1748 else if (! strcmp (arg, "spe"))
1751 rs6000_altivec_abi = 0;
1752 if (!TARGET_SPE_ABI)
1753 error ("not configured for ABI: '%s'", arg);
1755 else if (! strcmp (arg, "no-spe"))
1758 /* These are here for testing during development only, do not
1759 document in the manual please. */
1760 else if (! strcmp (arg, "d64"))
1762 rs6000_darwin64_abi = 1;
1763 warning (0, "Using darwin64 ABI");
1765 else if (! strcmp (arg, "d32"))
1767 rs6000_darwin64_abi = 0;
1768 warning (0, "Using old darwin ABI");
1773 error ("unknown ABI specified: '%s'", arg);
1779 rs6000_select[1].string = arg;
1783 rs6000_select[2].string = arg;
1786 case OPT_mtraceback_:
1787 rs6000_traceback_name = arg;
1790 case OPT_mfloat_gprs_:
1791 rs6000_explicit_options.float_gprs = true;
1792 if (! strcmp (arg, "yes") || ! strcmp (arg, "single"))
1793 rs6000_float_gprs = 1;
1794 else if (! strcmp (arg, "double"))
1795 rs6000_float_gprs = 2;
1796 else if (! strcmp (arg, "no"))
1797 rs6000_float_gprs = 0;
1800 error ("invalid option for -mfloat-gprs: '%s'", arg);
1805 case OPT_mlong_double_:
1806 rs6000_explicit_options.long_double = true;
1807 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
1808 if (value != 64 && value != 128)
1810 error ("Unknown switch -mlong-double-%s", arg);
1811 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
1815 rs6000_long_double_type_size = value;
1818 case OPT_msched_costly_dep_:
1819 rs6000_sched_costly_dep_str = arg;
1823 rs6000_explicit_options.alignment = true;
1824 if (! strcmp (arg, "power"))
1826 /* On 64-bit Darwin, power alignment is ABI-incompatible with
1827 some C library functions, so warn about it. The flag may be
1828 useful for performance studies from time to time though, so
1829 don't disable it entirely. */
1830 if (DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT)
1831 warning (0, "-malign-power is not supported for 64-bit Darwin;"
1832 " it is incompatible with the installed C and C++ libraries");
1833 rs6000_alignment_flags = MASK_ALIGN_POWER;
1835 else if (! strcmp (arg, "natural"))
1836 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1839 error ("unknown -malign-XXXXX option specified: '%s'", arg);
1847 /* Do anything needed at the start of the asm file. */
1850 rs6000_file_start (void)
1854 const char *start = buffer;
1855 struct rs6000_cpu_select *ptr;
1856 const char *default_cpu = TARGET_CPU_DEFAULT;
1857 FILE *file = asm_out_file;
1859 default_file_start ();
1861 #ifdef TARGET_BI_ARCH
1862 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1866 if (flag_verbose_asm)
1868 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1869 rs6000_select[0].string = default_cpu;
1871 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
1873 ptr = &rs6000_select[i];
1874 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1876 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1881 if (PPC405_ERRATUM77)
1883 fprintf (file, "%s PPC405CR_ERRATUM77", start);
1887 #ifdef USING_ELFOS_H
1888 switch (rs6000_sdata)
1890 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1891 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1892 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1893 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1896 if (rs6000_sdata && g_switch_value)
1898 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1908 if (DEFAULT_ABI == ABI_AIX || (TARGET_ELF && flag_pic == 2))
1916 /* Return nonzero if this function is known to have a null epilogue. */
1919 direct_return (void)
1921 if (reload_completed)
1923 rs6000_stack_t *info = rs6000_stack_info ();
1925 if (info->first_gp_reg_save == 32
1926 && info->first_fp_reg_save == 64
1927 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
1928 && ! info->lr_save_p
1929 && ! info->cr_save_p
1930 && info->vrsave_mask == 0
1938 /* Return the number of instructions it takes to form a constant in an
1939 integer register. */
1942 num_insns_constant_wide (HOST_WIDE_INT value)
1944 /* signed constant loadable with {cal|addi} */
1945 if (CONST_OK_FOR_LETTER_P (value, 'I'))
1948 /* constant loadable with {cau|addis} */
1949 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
1952 #if HOST_BITS_PER_WIDE_INT == 64
1953 else if (TARGET_POWERPC64)
1955 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1956 HOST_WIDE_INT high = value >> 31;
1958 if (high == 0 || high == -1)
1964 return num_insns_constant_wide (high) + 1;
1966 return (num_insns_constant_wide (high)
1967 + num_insns_constant_wide (low) + 1);
1976 num_insns_constant (rtx op, enum machine_mode mode)
1978 HOST_WIDE_INT low, high;
1980 switch (GET_CODE (op))
1983 #if HOST_BITS_PER_WIDE_INT == 64
1984 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1985 && mask64_operand (op, mode))
1989 return num_insns_constant_wide (INTVAL (op));
1997 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1998 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1999 return num_insns_constant_wide ((HOST_WIDE_INT) l);
2002 if (mode == VOIDmode || mode == DImode)
2004 high = CONST_DOUBLE_HIGH (op);
2005 low = CONST_DOUBLE_LOW (op);
2012 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2013 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
2014 high = l[WORDS_BIG_ENDIAN == 0];
2015 low = l[WORDS_BIG_ENDIAN != 0];
2019 return (num_insns_constant_wide (low)
2020 + num_insns_constant_wide (high));
2023 if ((high == 0 && low >= 0)
2024 || (high == -1 && low < 0))
2025 return num_insns_constant_wide (low);
2027 else if (mask64_operand (op, mode))
2031 return num_insns_constant_wide (high) + 1;
2034 return (num_insns_constant_wide (high)
2035 + num_insns_constant_wide (low) + 1);
2044 /* Return true if OP can be synthesized with a particular vspltisb, vspltish
2045 or vspltisw instruction. OP is a CONST_VECTOR. Which instruction is used
2046 depends on STEP and COPIES, one of which will be 1. If COPIES > 1,
2047 all items are set to the same value and contain COPIES replicas of the
2048 vsplt's operand; if STEP > 1, one in STEP elements is set to the vsplt's
2049 operand and the others are set to the value of the operand's msb. */
2052 vspltis_constant (rtx op, unsigned step, unsigned copies)
2054 enum machine_mode mode = GET_MODE (op);
2055 enum machine_mode inner = GET_MODE_INNER (mode);
2058 unsigned nunits = GET_MODE_NUNITS (mode);
2059 unsigned bitsize = GET_MODE_BITSIZE (inner);
2060 unsigned mask = GET_MODE_MASK (inner);
2062 rtx last = CONST_VECTOR_ELT (op, nunits - 1);
2063 HOST_WIDE_INT val = INTVAL (last);
2064 HOST_WIDE_INT splat_val = val;
2065 HOST_WIDE_INT msb_val = val > 0 ? 0 : -1;
2067 /* Construct the value to be splatted, if possible. If not, return 0. */
2068 for (i = 2; i <= copies; i *= 2)
2070 HOST_WIDE_INT small_val;
2072 small_val = splat_val >> bitsize;
2074 if (splat_val != ((small_val << bitsize) | (small_val & mask)))
2076 splat_val = small_val;
2079 /* Check if SPLAT_VAL can really be the operand of a vspltis[bhw]. */
2080 if (EASY_VECTOR_15 (splat_val))
2083 /* Also check if we can splat, and then add the result to itself. Do so if
2084 the value is positive, of if the splat instruction is using OP's mode;
2085 for splat_val < 0, the splat and the add should use the same mode. */
2086 else if (EASY_VECTOR_15_ADD_SELF (splat_val)
2087 && (splat_val >= 0 || (step == 1 && copies == 1)))
2093 /* Check if VAL is present in every STEP-th element, and the
2094 other elements are filled with its most significant bit. */
2095 for (i = 0; i < nunits - 1; ++i)
2097 HOST_WIDE_INT desired_val;
2098 if (((i + 1) & (step - 1)) == 0)
2101 desired_val = msb_val;
2103 if (desired_val != INTVAL (CONST_VECTOR_ELT (op, i)))
2111 /* Return true if OP is of the given MODE and can be synthesized
2112 with a vspltisb, vspltish or vspltisw. */
2115 easy_altivec_constant (rtx op, enum machine_mode mode)
2117 unsigned step, copies;
2119 if (mode == VOIDmode)
2120 mode = GET_MODE (op);
2121 else if (mode != GET_MODE (op))
2124 /* Start with a vspltisw. */
2125 step = GET_MODE_NUNITS (mode) / 4;
2128 if (vspltis_constant (op, step, copies))
2131 /* Then try with a vspltish. */
2137 if (vspltis_constant (op, step, copies))
2140 /* And finally a vspltisb. */
2146 if (vspltis_constant (op, step, copies))
2152 /* Generate a VEC_DUPLICATE representing a vspltis[bhw] instruction whose
2153 result is OP. Abort if it is not possible. */
2156 gen_easy_altivec_constant (rtx op)
2158 enum machine_mode mode = GET_MODE (op);
2159 int nunits = GET_MODE_NUNITS (mode);
2160 rtx last = CONST_VECTOR_ELT (op, nunits - 1);
2161 unsigned step = nunits / 4;
2162 unsigned copies = 1;
2164 /* Start with a vspltisw. */
2165 if (vspltis_constant (op, step, copies))
2166 return gen_rtx_VEC_DUPLICATE (V4SImode, gen_lowpart (SImode, last));
2168 /* Then try with a vspltish. */
2174 if (vspltis_constant (op, step, copies))
2175 return gen_rtx_VEC_DUPLICATE (V8HImode, gen_lowpart (HImode, last));
2177 /* And finally a vspltisb. */
2183 if (vspltis_constant (op, step, copies))
2184 return gen_rtx_VEC_DUPLICATE (V16QImode, gen_lowpart (QImode, last));
2190 output_vec_const_move (rtx *operands)
2193 enum machine_mode mode;
2198 mode = GET_MODE (dest);
2203 if (zero_constant (vec, mode))
2204 return "vxor %0,%0,%0";
2206 splat_vec = gen_easy_altivec_constant (vec);
2207 gcc_assert (GET_CODE (splat_vec) == VEC_DUPLICATE);
2208 operands[1] = XEXP (splat_vec, 0);
2209 if (!EASY_VECTOR_15 (INTVAL (operands[1])))
2212 switch (GET_MODE (splat_vec))
2215 return "vspltisw %0,%1";
2218 return "vspltish %0,%1";
2221 return "vspltisb %0,%1";
2228 gcc_assert (TARGET_SPE);
2230 /* Vector constant 0 is handled as a splitter of V2SI, and in the
2231 pattern of V1DI, V4HI, and V2SF.
2233 FIXME: We should probably return # and add post reload
2234 splitters for these, but this way is so easy ;-). */
2235 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
2236 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
2237 operands[1] = CONST_VECTOR_ELT (vec, 0);
2238 operands[2] = CONST_VECTOR_ELT (vec, 1);
2240 return "li %0,%1\n\tevmergelo %0,%0,%0";
2242 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
2245 /* Initialize vector TARGET to VALS. */
2248 rs6000_expand_vector_init (rtx target, rtx vals)
2250 enum machine_mode mode = GET_MODE (target);
2251 enum machine_mode inner_mode = GET_MODE_INNER (mode);
2252 int n_elts = GET_MODE_NUNITS (mode);
2253 int n_var = 0, one_var = -1;
2254 bool all_same = true, all_const_zero = true;
2258 for (i = 0; i < n_elts; ++i)
2260 x = XVECEXP (vals, 0, i);
2261 if (!CONSTANT_P (x))
2262 ++n_var, one_var = i;
2263 else if (x != CONST0_RTX (inner_mode))
2264 all_const_zero = false;
2266 if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
2272 if (mode != V4SFmode && all_const_zero)
2274 /* Zero register. */
2275 emit_insn (gen_rtx_SET (VOIDmode, target,
2276 gen_rtx_XOR (mode, target, target)));
2279 else if (mode != V4SFmode && easy_vector_constant (vals, mode))
2281 /* Splat immediate. */
2282 emit_insn (gen_rtx_SET (VOIDmode, target, vals));
2286 ; /* Splat vector element. */
2289 /* Load from constant pool. */
2290 emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
2295 /* Store value to stack temp. Load vector element. Splat. */
2298 mem = assign_stack_temp (mode, GET_MODE_SIZE (inner_mode), 0);
2299 emit_move_insn (adjust_address_nv (mem, inner_mode, 0),
2300 XVECEXP (vals, 0, 0));
2301 x = gen_rtx_UNSPEC (VOIDmode,
2302 gen_rtvec (1, const0_rtx), UNSPEC_LVE);
2303 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2305 gen_rtx_SET (VOIDmode,
2308 x = gen_rtx_VEC_SELECT (inner_mode, target,
2309 gen_rtx_PARALLEL (VOIDmode,
2310 gen_rtvec (1, const0_rtx)));
2311 emit_insn (gen_rtx_SET (VOIDmode, target,
2312 gen_rtx_VEC_DUPLICATE (mode, x)));
2316 /* One field is non-constant. Load constant then overwrite
2320 rtx copy = copy_rtx (vals);
2322 /* Load constant part of vector, substitute neighboring value for
2324 XVECEXP (copy, 0, one_var) = XVECEXP (vals, 0, (one_var + 1) % n_elts);
2325 rs6000_expand_vector_init (target, copy);
2327 /* Insert variable. */
2328 rs6000_expand_vector_set (target, XVECEXP (vals, 0, one_var), one_var);
2332 /* Construct the vector in memory one field at a time
2333 and load the whole vector. */
2334 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2335 for (i = 0; i < n_elts; i++)
2336 emit_move_insn (adjust_address_nv (mem, inner_mode,
2337 i * GET_MODE_SIZE (inner_mode)),
2338 XVECEXP (vals, 0, i));
2339 emit_move_insn (target, mem);
2342 /* Set field ELT of TARGET to VAL. */
2345 rs6000_expand_vector_set (rtx target, rtx val, int elt)
2347 enum machine_mode mode = GET_MODE (target);
2348 enum machine_mode inner_mode = GET_MODE_INNER (mode);
2349 rtx reg = gen_reg_rtx (mode);
2351 int width = GET_MODE_SIZE (inner_mode);
2354 /* Load single variable value. */
2355 mem = assign_stack_temp (mode, GET_MODE_SIZE (inner_mode), 0);
2356 emit_move_insn (adjust_address_nv (mem, inner_mode, 0), val);
2357 x = gen_rtx_UNSPEC (VOIDmode,
2358 gen_rtvec (1, const0_rtx), UNSPEC_LVE);
2359 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2361 gen_rtx_SET (VOIDmode,
2365 /* Linear sequence. */
2366 mask = gen_rtx_PARALLEL (V16QImode, rtvec_alloc (16));
2367 for (i = 0; i < 16; ++i)
2368 XVECEXP (mask, 0, i) = GEN_INT (i);
2370 /* Set permute mask to insert element into target. */
2371 for (i = 0; i < width; ++i)
2372 XVECEXP (mask, 0, elt*width + i)
2373 = GEN_INT (i + 0x10);
2374 x = gen_rtx_CONST_VECTOR (V16QImode, XVEC (mask, 0));
2375 x = gen_rtx_UNSPEC (mode,
2376 gen_rtvec (3, target, reg,
2377 force_reg (V16QImode, x)),
2379 emit_insn (gen_rtx_SET (VOIDmode, target, x));
2382 /* Extract field ELT from VEC into TARGET. */
2385 rs6000_expand_vector_extract (rtx target, rtx vec, int elt)
2387 enum machine_mode mode = GET_MODE (vec);
2388 enum machine_mode inner_mode = GET_MODE_INNER (mode);
2391 /* Allocate mode-sized buffer. */
2392 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2394 /* Add offset to field within buffer matching vector element. */
2395 mem = adjust_address_nv (mem, mode, elt * GET_MODE_SIZE (inner_mode));
2397 /* Store single field into mode-sized buffer. */
2398 x = gen_rtx_UNSPEC (VOIDmode,
2399 gen_rtvec (1, const0_rtx), UNSPEC_STVE);
2400 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2402 gen_rtx_SET (VOIDmode,
2405 emit_move_insn (target, adjust_address_nv (mem, inner_mode, 0));
2408 /* Generates shifts and masks for a pair of rldicl or rldicr insns to
2409 implement ANDing by the mask IN. */
2411 build_mask64_2_operands (rtx in, rtx *out)
2413 #if HOST_BITS_PER_WIDE_INT >= 64
2414 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2417 gcc_assert (GET_CODE (in) == CONST_INT);
2422 /* Assume c initially something like 0x00fff000000fffff. The idea
2423 is to rotate the word so that the middle ^^^^^^ group of zeros
2424 is at the MS end and can be cleared with an rldicl mask. We then
2425 rotate back and clear off the MS ^^ group of zeros with a
2427 c = ~c; /* c == 0xff000ffffff00000 */
2428 lsb = c & -c; /* lsb == 0x0000000000100000 */
2429 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2430 c = ~c; /* c == 0x00fff000000fffff */
2431 c &= -lsb; /* c == 0x00fff00000000000 */
2432 lsb = c & -c; /* lsb == 0x0000100000000000 */
2433 c = ~c; /* c == 0xff000fffffffffff */
2434 c &= -lsb; /* c == 0xff00000000000000 */
2436 while ((lsb >>= 1) != 0)
2437 shift++; /* shift == 44 on exit from loop */
2438 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2439 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2440 m2 = ~c; /* m2 == 0x00ffffffffffffff */
2444 /* Assume c initially something like 0xff000f0000000000. The idea
2445 is to rotate the word so that the ^^^ middle group of zeros
2446 is at the LS end and can be cleared with an rldicr mask. We then
2447 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2449 lsb = c & -c; /* lsb == 0x0000010000000000 */
2450 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2451 c = ~c; /* c == 0x00fff0ffffffffff */
2452 c &= -lsb; /* c == 0x00fff00000000000 */
2453 lsb = c & -c; /* lsb == 0x0000100000000000 */
2454 c = ~c; /* c == 0xff000fffffffffff */
2455 c &= -lsb; /* c == 0xff00000000000000 */
2457 while ((lsb >>= 1) != 0)
2458 shift++; /* shift == 44 on exit from loop */
2459 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2460 m1 >>= shift; /* m1 == 0x0000000000000fff */
2461 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2464 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2465 masks will be all 1's. We are guaranteed more than one transition. */
2466 out[0] = GEN_INT (64 - shift);
2467 out[1] = GEN_INT (m1);
2468 out[2] = GEN_INT (shift);
2469 out[3] = GEN_INT (m2);
2477 /* Return TRUE if OP is an invalid SUBREG operation on the e500. */
2480 invalid_e500_subreg (rtx op, enum machine_mode mode)
2482 /* Reject (subreg:SI (reg:DF)). */
2483 if (GET_CODE (op) == SUBREG
2485 && REG_P (SUBREG_REG (op))
2486 && GET_MODE (SUBREG_REG (op)) == DFmode)
2489 /* Reject (subreg:DF (reg:DI)). */
2490 if (GET_CODE (op) == SUBREG
2492 && REG_P (SUBREG_REG (op))
2493 && GET_MODE (SUBREG_REG (op)) == DImode)
2499 /* Darwin, AIX increases natural record alignment to doubleword if the first
2500 field is an FP double while the FP fields remain word aligned. */
2503 rs6000_special_round_type_align (tree type, int computed, int specified)
2505 tree field = TYPE_FIELDS (type);
2507 /* Skip all non field decls */
2508 while (field != NULL && TREE_CODE (field) != FIELD_DECL)
2509 field = TREE_CHAIN (field);
2511 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
2512 return MAX (computed, specified);
2514 return MAX (MAX (computed, specified), 64);
2517 /* Return 1 for an operand in small memory on V.4/eabi. */
2520 small_data_operand (rtx op ATTRIBUTE_UNUSED,
2521 enum machine_mode mode ATTRIBUTE_UNUSED)
2526 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
2529 if (DEFAULT_ABI != ABI_V4)
2532 if (GET_CODE (op) == SYMBOL_REF)
2535 else if (GET_CODE (op) != CONST
2536 || GET_CODE (XEXP (op, 0)) != PLUS
2537 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2538 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
2543 rtx sum = XEXP (op, 0);
2544 HOST_WIDE_INT summand;
2546 /* We have to be careful here, because it is the referenced address
2547 that must be 32k from _SDA_BASE_, not just the symbol. */
2548 summand = INTVAL (XEXP (sum, 1));
2549 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
2552 sym_ref = XEXP (sum, 0);
2555 return SYMBOL_REF_SMALL_P (sym_ref);
2561 /* Return true if either operand is a general purpose register. */
2564 gpr_or_gpr_p (rtx op0, rtx op1)
2566 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2567 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
2571 /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2574 constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
2576 switch (GET_CODE (op))
2579 if (RS6000_SYMBOL_REF_TLS_P (op))
2581 else if (CONSTANT_POOL_ADDRESS_P (op))
2583 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2591 else if (! strcmp (XSTR (op, 0), toc_label_name))
2600 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2601 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
2603 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
2612 constant_pool_expr_p (rtx op)
2616 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2620 toc_relative_expr_p (rtx op)
2624 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2628 legitimate_constant_pool_address_p (rtx x)
2631 && GET_CODE (x) == PLUS
2632 && GET_CODE (XEXP (x, 0)) == REG
2633 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2634 && constant_pool_expr_p (XEXP (x, 1)));
2638 rs6000_legitimate_small_data_p (enum machine_mode mode, rtx x)
2640 return (DEFAULT_ABI == ABI_V4
2641 && !flag_pic && !TARGET_TOC
2642 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2643 && small_data_operand (x, mode));
2646 /* SPE offset addressing is limited to 5-bits worth of double words. */
2647 #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2650 rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
2652 unsigned HOST_WIDE_INT offset, extra;
2654 if (GET_CODE (x) != PLUS)
2656 if (GET_CODE (XEXP (x, 0)) != REG)
2658 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2660 if (legitimate_constant_pool_address_p (x))
2662 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2665 offset = INTVAL (XEXP (x, 1));
2673 /* AltiVec vector modes. Only reg+reg addressing is valid and
2674 constant offset zero should not occur due to canonicalization.
2675 Allow any offset when not strict before reload. */
2682 /* SPE vector modes. */
2683 return SPE_CONST_OFFSET_OK (offset);
2686 if (TARGET_E500_DOUBLE)
2687 return SPE_CONST_OFFSET_OK (offset);
2690 /* On e500v2, we may have:
2692 (subreg:DF (mem:DI (plus (reg) (const_int))) 0).
2694 Which gets addressed with evldd instructions. */
2695 if (TARGET_E500_DOUBLE)
2696 return SPE_CONST_OFFSET_OK (offset);
2698 if (mode == DFmode || !TARGET_POWERPC64)
2700 else if (offset & 3)
2706 if (mode == TFmode || !TARGET_POWERPC64)
2708 else if (offset & 3)
2719 return (offset < 0x10000) && (offset + extra < 0x10000);
2723 legitimate_indexed_address_p (rtx x, int strict)
2727 if (GET_CODE (x) != PLUS)
2733 if (REG_P (op0) && REG_P (op1))
2734 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2735 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2736 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2737 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
2739 /* Recognize the rtl generated by reload which we know will later be
2740 replaced by a base reg. We rely on nothing but reload generating
2741 this particular pattern, a reasonable assumption because it is not
2743 else if (reload_in_progress
2744 && GET_CODE (op0) == PLUS
2745 && REG_P (XEXP (op0, 0))
2746 && GET_CODE (XEXP (op0, 1)) == CONST_INT
2748 return INT_REG_OK_FOR_INDEX_P (op1, strict);
2753 legitimate_indirect_address_p (rtx x, int strict)
2755 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2759 macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
2761 if (!TARGET_MACHO || !flag_pic
2762 || mode != SImode || GET_CODE (x) != MEM)
2766 if (GET_CODE (x) != LO_SUM)
2768 if (GET_CODE (XEXP (x, 0)) != REG)
2770 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
2774 return CONSTANT_P (x);
2778 legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
2780 if (GET_CODE (x) != LO_SUM)
2782 if (GET_CODE (XEXP (x, 0)) != REG)
2784 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2786 /* Restrict addressing for DI because of our SUBREG hackery. */
2787 if (TARGET_E500_DOUBLE && (mode == DFmode || mode == DImode))
2791 if (TARGET_ELF || TARGET_MACHO)
2793 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
2797 if (GET_MODE_NUNITS (mode) != 1)
2799 if (GET_MODE_BITSIZE (mode) > 64
2800 || (GET_MODE_BITSIZE (mode) > 32 && !TARGET_POWERPC64
2801 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode)))
2804 return CONSTANT_P (x);
2811 /* Try machine-dependent ways of modifying an illegitimate address
2812 to be legitimate. If we find one, return the new, valid address.
2813 This is used from only one place: `memory_address' in explow.c.
2815 OLDX is the address as it was before break_out_memory_refs was
2816 called. In some cases it is useful to look at this to decide what
2819 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
2821 It is always safe for this function to do nothing. It exists to
2822 recognize opportunities to optimize the output.
2824 On RS/6000, first check for the sum of a register with a constant
2825 integer that is out of range. If so, generate code to add the
2826 constant with the low-order 16 bits masked to the register and force
2827 this result into another register (this can be done with `cau').
2828 Then generate an address of REG+(CONST&0xffff), allowing for the
2829 possibility of bit 16 being a one.
2831 Then check for the sum of a register and something not constant, try to
2832 load the other things into a register and return the sum. */
2835 rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2836 enum machine_mode mode)
2838 if (GET_CODE (x) == SYMBOL_REF)
2840 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2842 return rs6000_legitimize_tls_address (x, model);
2845 if (GET_CODE (x) == PLUS
2846 && GET_CODE (XEXP (x, 0)) == REG
2847 && GET_CODE (XEXP (x, 1)) == CONST_INT
2848 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2850 HOST_WIDE_INT high_int, low_int;
2852 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2853 high_int = INTVAL (XEXP (x, 1)) - low_int;
2854 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2855 GEN_INT (high_int)), 0);
2856 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2858 else if (GET_CODE (x) == PLUS
2859 && GET_CODE (XEXP (x, 0)) == REG
2860 && GET_CODE (XEXP (x, 1)) != CONST_INT
2861 && GET_MODE_NUNITS (mode) == 1
2862 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2864 || (((mode != DImode && mode != DFmode) || TARGET_E500_DOUBLE)
2866 && (TARGET_POWERPC64 || mode != DImode)
2869 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2870 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2872 else if (ALTIVEC_VECTOR_MODE (mode))
2876 /* Make sure both operands are registers. */
2877 if (GET_CODE (x) == PLUS)
2878 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
2879 force_reg (Pmode, XEXP (x, 1)));
2881 reg = force_reg (Pmode, x);
2884 else if (SPE_VECTOR_MODE (mode)
2885 || (TARGET_E500_DOUBLE && (mode == DFmode
2886 || mode == DImode)))
2890 /* We accept [reg + reg] and [reg + OFFSET]. */
2892 if (GET_CODE (x) == PLUS)
2894 rtx op1 = XEXP (x, 0);
2895 rtx op2 = XEXP (x, 1);
2897 op1 = force_reg (Pmode, op1);
2899 if (GET_CODE (op2) != REG
2900 && (GET_CODE (op2) != CONST_INT
2901 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2902 op2 = force_reg (Pmode, op2);
2904 return gen_rtx_PLUS (Pmode, op1, op2);
2907 return force_reg (Pmode, x);
2913 && GET_CODE (x) != CONST_INT
2914 && GET_CODE (x) != CONST_DOUBLE
2916 && GET_MODE_NUNITS (mode) == 1
2917 && (GET_MODE_BITSIZE (mode) <= 32
2918 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
2920 rtx reg = gen_reg_rtx (Pmode);
2921 emit_insn (gen_elf_high (reg, x));
2922 return gen_rtx_LO_SUM (Pmode, reg, x);
2924 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2927 && ! MACHO_DYNAMIC_NO_PIC_P
2929 && GET_CODE (x) != CONST_INT
2930 && GET_CODE (x) != CONST_DOUBLE
2932 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
2936 rtx reg = gen_reg_rtx (Pmode);
2937 emit_insn (gen_macho_high (reg, x));
2938 return gen_rtx_LO_SUM (Pmode, reg, x);
2941 && constant_pool_expr_p (x)
2942 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
2944 return create_TOC_reference (x);
2950 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
2951 We need to emit DTP-relative relocations. */
2954 rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
2959 fputs ("\t.long\t", file);
2962 fputs (DOUBLE_INT_ASM_OP, file);
2967 output_addr_const (file, x);
2968 fputs ("@dtprel+0x8000", file);
2971 /* Construct the SYMBOL_REF for the tls_get_addr function. */
2973 static GTY(()) rtx rs6000_tls_symbol;
2975 rs6000_tls_get_addr (void)
2977 if (!rs6000_tls_symbol)
2978 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2980 return rs6000_tls_symbol;
2983 /* Construct the SYMBOL_REF for TLS GOT references. */
2985 static GTY(()) rtx rs6000_got_symbol;
2987 rs6000_got_sym (void)
2989 if (!rs6000_got_symbol)
2991 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2992 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2993 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2996 return rs6000_got_symbol;
2999 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3000 this (thread-local) address. */
3003 rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
3007 dest = gen_reg_rtx (Pmode);
3008 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
3014 tlsreg = gen_rtx_REG (Pmode, 13);
3015 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
3019 tlsreg = gen_rtx_REG (Pmode, 2);
3020 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
3024 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
3028 tmp = gen_reg_rtx (Pmode);
3031 tlsreg = gen_rtx_REG (Pmode, 13);
3032 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
3036 tlsreg = gen_rtx_REG (Pmode, 2);
3037 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
3041 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3043 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3048 rtx r3, got, tga, tmp1, tmp2, eqv;
3050 /* We currently use relocations like @got@tlsgd for tls, which
3051 means the linker will handle allocation of tls entries, placing
3052 them in the .got section. So use a pointer to the .got section,
3053 not one to secondary TOC sections used by 64-bit -mminimal-toc,
3054 or to secondary GOT sections used by 32-bit -fPIC. */
3056 got = gen_rtx_REG (Pmode, 2);
3060 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3063 rtx gsym = rs6000_got_sym ();
3064 got = gen_reg_rtx (Pmode);
3066 rs6000_emit_move (got, gsym, Pmode);
3069 rtx tempLR, tmp3, mem;
3072 tempLR = gen_reg_rtx (Pmode);
3073 tmp1 = gen_reg_rtx (Pmode);
3074 tmp2 = gen_reg_rtx (Pmode);
3075 tmp3 = gen_reg_rtx (Pmode);
3076 mem = gen_const_mem (Pmode, tmp1);
3078 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, gsym));
3079 emit_move_insn (tmp1, tempLR);
3080 emit_move_insn (tmp2, mem);
3081 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
3082 last = emit_move_insn (got, tmp3);
3083 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
3085 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3087 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3093 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3095 r3 = gen_rtx_REG (Pmode, 3);
3097 insn = gen_tls_gd_64 (r3, got, addr);
3099 insn = gen_tls_gd_32 (r3, got, addr);
3102 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3103 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3104 insn = emit_call_insn (insn);
3105 CONST_OR_PURE_CALL_P (insn) = 1;
3106 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3107 insn = get_insns ();
3109 emit_libcall_block (insn, dest, r3, addr);
3111 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3113 r3 = gen_rtx_REG (Pmode, 3);
3115 insn = gen_tls_ld_64 (r3, got);
3117 insn = gen_tls_ld_32 (r3, got);
3120 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3121 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3122 insn = emit_call_insn (insn);
3123 CONST_OR_PURE_CALL_P (insn) = 1;
3124 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3125 insn = get_insns ();
3127 tmp1 = gen_reg_rtx (Pmode);
3128 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3130 emit_libcall_block (insn, tmp1, r3, eqv);
3131 if (rs6000_tls_size == 16)
3134 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3136 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3138 else if (rs6000_tls_size == 32)
3140 tmp2 = gen_reg_rtx (Pmode);
3142 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3144 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3147 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3149 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3153 tmp2 = gen_reg_rtx (Pmode);
3155 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3157 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3159 insn = gen_rtx_SET (Pmode, dest,
3160 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3166 /* IE, or 64 bit offset LE. */
3167 tmp2 = gen_reg_rtx (Pmode);
3169 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3171 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3174 insn = gen_tls_tls_64 (dest, tmp2, addr);
3176 insn = gen_tls_tls_32 (dest, tmp2, addr);
3184 /* Return 1 if X contains a thread-local symbol. */
3187 rs6000_tls_referenced_p (rtx x)
3189 if (! TARGET_HAVE_TLS)
3192 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3195 /* Return 1 if *X is a thread-local symbol. This is the same as
3196 rs6000_tls_symbol_ref except for the type of the unused argument. */
3199 rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
3201 return RS6000_SYMBOL_REF_TLS_P (*x);
3204 /* The convention appears to be to define this wherever it is used.
3205 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3206 is now used here. */
3207 #ifndef REG_MODE_OK_FOR_BASE_P
3208 #define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3211 /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3212 replace the input X, or the original X if no replacement is called for.
3213 The output parameter *WIN is 1 if the calling macro should goto WIN,
3216 For RS/6000, we wish to handle large displacements off a base
3217 register by splitting the addend across an addiu/addis and the mem insn.
3218 This cuts number of extra insns needed from 3 to 1.
3220 On Darwin, we use this to generate code for floating point constants.
3221 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3222 The Darwin code is inside #if TARGET_MACHO because only then is
3223 machopic_function_base_name() defined. */
3225 rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
3226 int opnum, int type,
3227 int ind_levels ATTRIBUTE_UNUSED, int *win)
3229 /* We must recognize output that we have already generated ourselves. */
3230 if (GET_CODE (x) == PLUS
3231 && GET_CODE (XEXP (x, 0)) == PLUS
3232 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3233 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3234 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3236 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3237 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3238 opnum, (enum reload_type)type);
3244 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3245 && GET_CODE (x) == LO_SUM
3246 && GET_CODE (XEXP (x, 0)) == PLUS
3247 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3248 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3249 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3250 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3251 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3252 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3253 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3255 /* Result of previous invocation of this function on Darwin
3256 floating point constant. */
3257 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3258 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3259 opnum, (enum reload_type)type);
3265 /* Force ld/std non-word aligned offset into base register by wrapping
3267 if (GET_CODE (x) == PLUS
3268 && GET_CODE (XEXP (x, 0)) == REG
3269 && REGNO (XEXP (x, 0)) < 32
3270 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
3271 && GET_CODE (XEXP (x, 1)) == CONST_INT
3272 && (INTVAL (XEXP (x, 1)) & 3) != 0
3273 && !ALTIVEC_VECTOR_MODE (mode)
3274 && GET_MODE_SIZE (mode) >= UNITS_PER_WORD
3275 && TARGET_POWERPC64)
3277 x = gen_rtx_PLUS (GET_MODE (x), x, GEN_INT (0));
3278 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3279 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3280 opnum, (enum reload_type) type);
3285 if (GET_CODE (x) == PLUS
3286 && GET_CODE (XEXP (x, 0)) == REG
3287 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3288 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
3289 && GET_CODE (XEXP (x, 1)) == CONST_INT
3290 && !SPE_VECTOR_MODE (mode)
3291 && !(TARGET_E500_DOUBLE && (mode == DFmode
3293 && !ALTIVEC_VECTOR_MODE (mode))
3295 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3296 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3298 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3300 /* Check for 32-bit overflow. */
3301 if (high + low != val)
3307 /* Reload the high part into a base reg; leave the low part
3308 in the mem directly. */
3310 x = gen_rtx_PLUS (GET_MODE (x),
3311 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3315 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3316 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3317 opnum, (enum reload_type)type);
3322 if (GET_CODE (x) == SYMBOL_REF
3323 && !ALTIVEC_VECTOR_MODE (mode)
3325 && DEFAULT_ABI == ABI_DARWIN
3326 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3328 && DEFAULT_ABI == ABI_V4
3331 /* Don't do this for TFmode, since the result isn't offsettable.
3332 The same goes for DImode without 64-bit gprs. */
3334 && (mode != DImode || TARGET_POWERPC64))
3339 rtx offset = gen_rtx_CONST (Pmode,
3340 gen_rtx_MINUS (Pmode, x,
3341 machopic_function_base_sym ()));
3342 x = gen_rtx_LO_SUM (GET_MODE (x),
3343 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3344 gen_rtx_HIGH (Pmode, offset)), offset);
3348 x = gen_rtx_LO_SUM (GET_MODE (x),
3349 gen_rtx_HIGH (Pmode, x), x);
3351 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3352 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3353 opnum, (enum reload_type)type);
3358 /* Reload an offset address wrapped by an AND that represents the
3359 masking of the lower bits. Strip the outer AND and let reload
3360 convert the offset address into an indirect address. */
3362 && ALTIVEC_VECTOR_MODE (mode)
3363 && GET_CODE (x) == AND
3364 && GET_CODE (XEXP (x, 0)) == PLUS
3365 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3366 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3367 && GET_CODE (XEXP (x, 1)) == CONST_INT
3368 && INTVAL (XEXP (x, 1)) == -16)
3376 && constant_pool_expr_p (x)
3377 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
3379 (x) = create_TOC_reference (x);
3387 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3388 that is a valid memory address for an instruction.
3389 The MODE argument is the machine mode for the MEM expression
3390 that wants to use this address.
3392 On the RS/6000, there are four valid address: a SYMBOL_REF that
3393 refers to a constant pool entry of an address (or the sum of it
3394 plus a constant), a short (16-bit signed) constant plus a register,
3395 the sum of two registers, or a register indirect, possibly with an
3396 auto-increment. For DFmode and DImode with a constant plus register,
3397 we must ensure that both words are addressable or PowerPC64 with offset
3400 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3401 32-bit DImode, TImode, TFmode), indexed addressing cannot be used because
3402 adjacent memory cells are accessed by adding word-sized offsets
3403 during assembly output. */
3405 rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
3407 /* If this is an unaligned stvx/ldvx type address, discard the outer AND. */
3409 && ALTIVEC_VECTOR_MODE (mode)
3410 && GET_CODE (x) == AND
3411 && GET_CODE (XEXP (x, 1)) == CONST_INT
3412 && INTVAL (XEXP (x, 1)) == -16)
3415 if (RS6000_SYMBOL_REF_TLS_P (x))
3417 if (legitimate_indirect_address_p (x, reg_ok_strict))
3419 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
3420 && !ALTIVEC_VECTOR_MODE (mode)
3421 && !SPE_VECTOR_MODE (mode)
3422 /* Restrict addressing for DI because of our SUBREG hackery. */
3423 && !(TARGET_E500_DOUBLE && (mode == DFmode || mode == DImode))
3425 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))