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, 2006, 2007
4 Free Software Foundation, Inc.
5 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published
11 by the Free Software Foundation; either version 2, or (at your
12 option) any later version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the
21 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
22 MA 02110-1301, USA. */
26 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
34 #include "insn-attr.h"
44 #include "basic-block.h"
45 #include "integrate.h"
51 #include "target-def.h"
52 #include "langhooks.h"
54 #include "cfglayout.h"
55 #include "sched-int.h"
56 #include "tree-gimple.h"
59 #include "tm-constrs.h"
61 #include "xcoffout.h" /* get declarations of xcoff_*_section_name */
64 #include "gstab.h" /* for N_SLINE */
67 #ifndef TARGET_NO_PROTOTYPE
68 #define TARGET_NO_PROTOTYPE 0
71 #define min(A,B) ((A) < (B) ? (A) : (B))
72 #define max(A,B) ((A) > (B) ? (A) : (B))
74 /* Structure used to define the rs6000 stack */
75 typedef struct rs6000_stack {
76 int first_gp_reg_save; /* first callee saved GP register used */
77 int first_fp_reg_save; /* first callee saved FP register used */
78 int first_altivec_reg_save; /* first callee saved AltiVec register used */
79 int lr_save_p; /* true if the link reg needs to be saved */
80 int cr_save_p; /* true if the CR reg needs to be saved */
81 unsigned int vrsave_mask; /* mask of vec registers to save */
82 int push_p; /* true if we need to allocate stack space */
83 int calls_p; /* true if the function makes any calls */
84 int world_save_p; /* true if we're saving *everything*:
85 r13-r31, cr, f14-f31, vrsave, v20-v31 */
86 enum rs6000_abi abi; /* which ABI to use */
87 int gp_save_offset; /* offset to save GP regs from initial SP */
88 int fp_save_offset; /* offset to save FP regs from initial SP */
89 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
90 int lr_save_offset; /* offset to save LR from initial SP */
91 int cr_save_offset; /* offset to save CR from initial SP */
92 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
93 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
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 vrsave_size; /* size to hold VRSAVE if not in save_size */
106 int altivec_padding_size; /* size of altivec alignment padding if
108 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
109 int spe_padding_size;
110 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
111 int spe_64bit_regs_used;
114 /* A C structure for machine-specific, per-function data.
115 This is added to the cfun structure. */
116 typedef struct machine_function GTY(())
118 /* Flags if __builtin_return_address (n) with n >= 1 was used. */
119 int ra_needs_full_frame;
120 /* Some local-dynamic symbol. */
121 const char *some_ld_name;
122 /* Whether the instruction chain has been scanned already. */
123 int insn_chain_scanned_p;
124 /* Flags if __builtin_return_address (0) was used. */
126 /* Offset from virtual_stack_vars_rtx to the start of the ABI_V4
127 varargs save area. */
128 HOST_WIDE_INT varargs_save_offset;
131 /* Target cpu type */
133 enum processor_type rs6000_cpu;
134 struct rs6000_cpu_select rs6000_select[3] =
136 /* switch name, tune arch */
137 { (const char *)0, "--with-cpu=", 1, 1 },
138 { (const char *)0, "-mcpu=", 1, 1 },
139 { (const char *)0, "-mtune=", 1, 0 },
142 static GTY(()) bool rs6000_cell_dont_microcode;
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 /* Align branch targets. */
151 static GTY(()) bool rs6000_align_branch_targets;
153 /* Support for -msched-costly-dep option. */
154 const char *rs6000_sched_costly_dep_str;
155 enum rs6000_dependence_cost rs6000_sched_costly_dep;
157 /* Support for -minsert-sched-nops option. */
158 const char *rs6000_sched_insert_nops_str;
159 enum rs6000_nop_insertion rs6000_sched_insert_nops;
161 /* Support targetm.vectorize.builtin_mask_for_load. */
162 static GTY(()) tree altivec_builtin_mask_for_load;
164 /* Size of long double. */
165 int rs6000_long_double_type_size;
167 /* IEEE quad extended precision long double. */
170 /* Whether -mabi=altivec has appeared. */
171 int rs6000_altivec_abi;
173 /* Nonzero if we want SPE ABI extensions. */
176 /* Nonzero if floating point operations are done in the GPRs. */
177 int rs6000_float_gprs = 0;
179 /* Nonzero if we want Darwin's struct-by-value-in-regs ABI. */
180 int rs6000_darwin64_abi;
182 /* Set to nonzero once AIX common-mode calls have been defined. */
183 static GTY(()) int common_mode_defined;
185 /* Save information from a "cmpxx" operation until the branch or scc is
187 rtx rs6000_compare_op0, rs6000_compare_op1;
188 int rs6000_compare_fp_p;
190 /* Label number of label created for -mrelocatable, to call to so we can
191 get the address of the GOT section */
192 int rs6000_pic_labelno;
195 /* Which abi to adhere to */
196 const char *rs6000_abi_name;
198 /* Semantics of the small data area */
199 enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
201 /* Which small data model to use */
202 const char *rs6000_sdata_name = (char *)0;
204 /* Counter for labels which are to be placed in .fixup. */
205 int fixuplabelno = 0;
208 /* Bit size of immediate TLS offsets and string from which it is decoded. */
209 int rs6000_tls_size = 32;
210 const char *rs6000_tls_size_string;
212 /* ABI enumeration available for subtarget to use. */
213 enum rs6000_abi rs6000_current_abi;
215 /* Whether to use variant of AIX ABI for PowerPC64 Linux. */
219 const char *rs6000_debug_name;
220 int rs6000_debug_stack; /* debug stack applications */
221 int rs6000_debug_arg; /* debug argument handling */
223 /* Value is TRUE if register/mode pair is acceptable. */
224 bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
226 /* Built in types. */
228 tree rs6000_builtin_types[RS6000_BTI_MAX];
229 tree rs6000_builtin_decls[RS6000_BUILTIN_COUNT];
231 const char *rs6000_traceback_name;
233 traceback_default = 0,
239 /* Flag to say the TOC is initialized */
241 char toc_label_name[10];
243 /* Cached value of rs6000_variable_issue. This is cached in
244 rs6000_variable_issue hook and returned from rs6000_sched_reorder2. */
245 static short cached_can_issue_more;
247 static GTY(()) section *read_only_data_section;
248 static GTY(()) section *private_data_section;
249 static GTY(()) section *read_only_private_data_section;
250 static GTY(()) section *sdata2_section;
251 static GTY(()) section *toc_section;
253 /* Control alignment for fields within structures. */
254 /* String from -malign-XXXXX. */
255 int rs6000_alignment_flags;
257 /* True for any options that were explicitly set. */
259 bool aix_struct_ret; /* True if -maix-struct-ret was used. */
260 bool alignment; /* True if -malign- was used. */
261 bool abi; /* True if -mabi=spe/nospe was used. */
262 bool spe; /* True if -mspe= was used. */
263 bool float_gprs; /* True if -mfloat-gprs= was used. */
264 bool isel; /* True if -misel was used. */
265 bool long_double; /* True if -mlong-double- was used. */
266 bool ieee; /* True if -mabi=ieee/ibmlongdouble used. */
267 } rs6000_explicit_options;
269 struct builtin_description
271 /* mask is not const because we're going to alter it below. This
272 nonsense will go away when we rewrite the -march infrastructure
273 to give us more target flag bits. */
275 const enum insn_code icode;
276 const char *const name;
277 const enum rs6000_builtins code;
280 /* Target cpu costs. */
282 struct processor_costs {
283 const int mulsi; /* cost of SImode multiplication. */
284 const int mulsi_const; /* cost of SImode multiplication by constant. */
285 const int mulsi_const9; /* cost of SImode mult by short constant. */
286 const int muldi; /* cost of DImode multiplication. */
287 const int divsi; /* cost of SImode division. */
288 const int divdi; /* cost of DImode division. */
289 const int fp; /* cost of simple SFmode and DFmode insns. */
290 const int dmul; /* cost of DFmode multiplication (and fmadd). */
291 const int sdiv; /* cost of SFmode division (fdivs). */
292 const int ddiv; /* cost of DFmode division (fdiv). */
295 const struct processor_costs *rs6000_cost;
297 /* Processor costs (relative to an add) */
299 /* Instruction size costs on 32bit processors. */
301 struct processor_costs size32_cost = {
302 COSTS_N_INSNS (1), /* mulsi */
303 COSTS_N_INSNS (1), /* mulsi_const */
304 COSTS_N_INSNS (1), /* mulsi_const9 */
305 COSTS_N_INSNS (1), /* muldi */
306 COSTS_N_INSNS (1), /* divsi */
307 COSTS_N_INSNS (1), /* divdi */
308 COSTS_N_INSNS (1), /* fp */
309 COSTS_N_INSNS (1), /* dmul */
310 COSTS_N_INSNS (1), /* sdiv */
311 COSTS_N_INSNS (1), /* ddiv */
314 /* Instruction size costs on 64bit processors. */
316 struct processor_costs size64_cost = {
317 COSTS_N_INSNS (1), /* mulsi */
318 COSTS_N_INSNS (1), /* mulsi_const */
319 COSTS_N_INSNS (1), /* mulsi_const9 */
320 COSTS_N_INSNS (1), /* muldi */
321 COSTS_N_INSNS (1), /* divsi */
322 COSTS_N_INSNS (1), /* divdi */
323 COSTS_N_INSNS (1), /* fp */
324 COSTS_N_INSNS (1), /* dmul */
325 COSTS_N_INSNS (1), /* sdiv */
326 COSTS_N_INSNS (1), /* ddiv */
329 /* Instruction costs on RIOS1 processors. */
331 struct processor_costs rios1_cost = {
332 COSTS_N_INSNS (5), /* mulsi */
333 COSTS_N_INSNS (4), /* mulsi_const */
334 COSTS_N_INSNS (3), /* mulsi_const9 */
335 COSTS_N_INSNS (5), /* muldi */
336 COSTS_N_INSNS (19), /* divsi */
337 COSTS_N_INSNS (19), /* divdi */
338 COSTS_N_INSNS (2), /* fp */
339 COSTS_N_INSNS (2), /* dmul */
340 COSTS_N_INSNS (19), /* sdiv */
341 COSTS_N_INSNS (19), /* ddiv */
344 /* Instruction costs on RIOS2 processors. */
346 struct processor_costs rios2_cost = {
347 COSTS_N_INSNS (2), /* mulsi */
348 COSTS_N_INSNS (2), /* mulsi_const */
349 COSTS_N_INSNS (2), /* mulsi_const9 */
350 COSTS_N_INSNS (2), /* muldi */
351 COSTS_N_INSNS (13), /* divsi */
352 COSTS_N_INSNS (13), /* divdi */
353 COSTS_N_INSNS (2), /* fp */
354 COSTS_N_INSNS (2), /* dmul */
355 COSTS_N_INSNS (17), /* sdiv */
356 COSTS_N_INSNS (17), /* ddiv */
359 /* Instruction costs on RS64A processors. */
361 struct processor_costs rs64a_cost = {
362 COSTS_N_INSNS (20), /* mulsi */
363 COSTS_N_INSNS (12), /* mulsi_const */
364 COSTS_N_INSNS (8), /* mulsi_const9 */
365 COSTS_N_INSNS (34), /* muldi */
366 COSTS_N_INSNS (65), /* divsi */
367 COSTS_N_INSNS (67), /* divdi */
368 COSTS_N_INSNS (4), /* fp */
369 COSTS_N_INSNS (4), /* dmul */
370 COSTS_N_INSNS (31), /* sdiv */
371 COSTS_N_INSNS (31), /* ddiv */
374 /* Instruction costs on MPCCORE processors. */
376 struct processor_costs mpccore_cost = {
377 COSTS_N_INSNS (2), /* mulsi */
378 COSTS_N_INSNS (2), /* mulsi_const */
379 COSTS_N_INSNS (2), /* mulsi_const9 */
380 COSTS_N_INSNS (2), /* muldi */
381 COSTS_N_INSNS (6), /* divsi */
382 COSTS_N_INSNS (6), /* divdi */
383 COSTS_N_INSNS (4), /* fp */
384 COSTS_N_INSNS (5), /* dmul */
385 COSTS_N_INSNS (10), /* sdiv */
386 COSTS_N_INSNS (17), /* ddiv */
389 /* Instruction costs on PPC403 processors. */
391 struct processor_costs ppc403_cost = {
392 COSTS_N_INSNS (4), /* mulsi */
393 COSTS_N_INSNS (4), /* mulsi_const */
394 COSTS_N_INSNS (4), /* mulsi_const9 */
395 COSTS_N_INSNS (4), /* muldi */
396 COSTS_N_INSNS (33), /* divsi */
397 COSTS_N_INSNS (33), /* divdi */
398 COSTS_N_INSNS (11), /* fp */
399 COSTS_N_INSNS (11), /* dmul */
400 COSTS_N_INSNS (11), /* sdiv */
401 COSTS_N_INSNS (11), /* ddiv */
404 /* Instruction costs on PPC405 processors. */
406 struct processor_costs ppc405_cost = {
407 COSTS_N_INSNS (5), /* mulsi */
408 COSTS_N_INSNS (4), /* mulsi_const */
409 COSTS_N_INSNS (3), /* mulsi_const9 */
410 COSTS_N_INSNS (5), /* muldi */
411 COSTS_N_INSNS (35), /* divsi */
412 COSTS_N_INSNS (35), /* divdi */
413 COSTS_N_INSNS (11), /* fp */
414 COSTS_N_INSNS (11), /* dmul */
415 COSTS_N_INSNS (11), /* sdiv */
416 COSTS_N_INSNS (11), /* ddiv */
419 /* Instruction costs on PPC440 processors. */
421 struct processor_costs ppc440_cost = {
422 COSTS_N_INSNS (3), /* mulsi */
423 COSTS_N_INSNS (2), /* mulsi_const */
424 COSTS_N_INSNS (2), /* mulsi_const9 */
425 COSTS_N_INSNS (3), /* muldi */
426 COSTS_N_INSNS (34), /* divsi */
427 COSTS_N_INSNS (34), /* divdi */
428 COSTS_N_INSNS (5), /* fp */
429 COSTS_N_INSNS (5), /* dmul */
430 COSTS_N_INSNS (19), /* sdiv */
431 COSTS_N_INSNS (33), /* ddiv */
434 /* Instruction costs on PPC601 processors. */
436 struct processor_costs ppc601_cost = {
437 COSTS_N_INSNS (5), /* mulsi */
438 COSTS_N_INSNS (5), /* mulsi_const */
439 COSTS_N_INSNS (5), /* mulsi_const9 */
440 COSTS_N_INSNS (5), /* muldi */
441 COSTS_N_INSNS (36), /* divsi */
442 COSTS_N_INSNS (36), /* divdi */
443 COSTS_N_INSNS (4), /* fp */
444 COSTS_N_INSNS (5), /* dmul */
445 COSTS_N_INSNS (17), /* sdiv */
446 COSTS_N_INSNS (31), /* ddiv */
449 /* Instruction costs on PPC603 processors. */
451 struct processor_costs ppc603_cost = {
452 COSTS_N_INSNS (5), /* mulsi */
453 COSTS_N_INSNS (3), /* mulsi_const */
454 COSTS_N_INSNS (2), /* mulsi_const9 */
455 COSTS_N_INSNS (5), /* muldi */
456 COSTS_N_INSNS (37), /* divsi */
457 COSTS_N_INSNS (37), /* divdi */
458 COSTS_N_INSNS (3), /* fp */
459 COSTS_N_INSNS (4), /* dmul */
460 COSTS_N_INSNS (18), /* sdiv */
461 COSTS_N_INSNS (33), /* ddiv */
464 /* Instruction costs on PPC604 processors. */
466 struct processor_costs ppc604_cost = {
467 COSTS_N_INSNS (4), /* mulsi */
468 COSTS_N_INSNS (4), /* mulsi_const */
469 COSTS_N_INSNS (4), /* mulsi_const9 */
470 COSTS_N_INSNS (4), /* muldi */
471 COSTS_N_INSNS (20), /* divsi */
472 COSTS_N_INSNS (20), /* divdi */
473 COSTS_N_INSNS (3), /* fp */
474 COSTS_N_INSNS (3), /* dmul */
475 COSTS_N_INSNS (18), /* sdiv */
476 COSTS_N_INSNS (32), /* ddiv */
479 /* Instruction costs on PPC604e processors. */
481 struct processor_costs ppc604e_cost = {
482 COSTS_N_INSNS (2), /* mulsi */
483 COSTS_N_INSNS (2), /* mulsi_const */
484 COSTS_N_INSNS (2), /* mulsi_const9 */
485 COSTS_N_INSNS (2), /* muldi */
486 COSTS_N_INSNS (20), /* divsi */
487 COSTS_N_INSNS (20), /* divdi */
488 COSTS_N_INSNS (3), /* fp */
489 COSTS_N_INSNS (3), /* dmul */
490 COSTS_N_INSNS (18), /* sdiv */
491 COSTS_N_INSNS (32), /* ddiv */
494 /* Instruction costs on PPC620 processors. */
496 struct processor_costs ppc620_cost = {
497 COSTS_N_INSNS (5), /* mulsi */
498 COSTS_N_INSNS (4), /* mulsi_const */
499 COSTS_N_INSNS (3), /* mulsi_const9 */
500 COSTS_N_INSNS (7), /* muldi */
501 COSTS_N_INSNS (21), /* divsi */
502 COSTS_N_INSNS (37), /* divdi */
503 COSTS_N_INSNS (3), /* fp */
504 COSTS_N_INSNS (3), /* dmul */
505 COSTS_N_INSNS (18), /* sdiv */
506 COSTS_N_INSNS (32), /* ddiv */
509 /* Instruction costs on PPC630 processors. */
511 struct processor_costs ppc630_cost = {
512 COSTS_N_INSNS (5), /* mulsi */
513 COSTS_N_INSNS (4), /* mulsi_const */
514 COSTS_N_INSNS (3), /* mulsi_const9 */
515 COSTS_N_INSNS (7), /* muldi */
516 COSTS_N_INSNS (21), /* divsi */
517 COSTS_N_INSNS (37), /* divdi */
518 COSTS_N_INSNS (3), /* fp */
519 COSTS_N_INSNS (3), /* dmul */
520 COSTS_N_INSNS (17), /* sdiv */
521 COSTS_N_INSNS (21), /* ddiv */
524 /* Instruction costs on Cell processor. */
525 /* COSTS_N_INSNS (1) ~ one add. */
527 struct processor_costs ppccell_cost = {
528 COSTS_N_INSNS (9/2)+2, /* mulsi */
529 COSTS_N_INSNS (6/2), /* mulsi_const */
530 COSTS_N_INSNS (6/2), /* mulsi_const9 */
531 COSTS_N_INSNS (15/2)+2, /* muldi */
532 COSTS_N_INSNS (38/2), /* divsi */
533 COSTS_N_INSNS (70/2), /* divdi */
534 COSTS_N_INSNS (10/2), /* fp */
535 COSTS_N_INSNS (10/2), /* dmul */
536 COSTS_N_INSNS (74/2), /* sdiv */
537 COSTS_N_INSNS (74/2), /* ddiv */
540 /* Instruction costs on PPC750 and PPC7400 processors. */
542 struct processor_costs ppc750_cost = {
543 COSTS_N_INSNS (5), /* mulsi */
544 COSTS_N_INSNS (3), /* mulsi_const */
545 COSTS_N_INSNS (2), /* mulsi_const9 */
546 COSTS_N_INSNS (5), /* muldi */
547 COSTS_N_INSNS (17), /* divsi */
548 COSTS_N_INSNS (17), /* divdi */
549 COSTS_N_INSNS (3), /* fp */
550 COSTS_N_INSNS (3), /* dmul */
551 COSTS_N_INSNS (17), /* sdiv */
552 COSTS_N_INSNS (31), /* ddiv */
555 /* Instruction costs on PPC7450 processors. */
557 struct processor_costs ppc7450_cost = {
558 COSTS_N_INSNS (4), /* mulsi */
559 COSTS_N_INSNS (3), /* mulsi_const */
560 COSTS_N_INSNS (3), /* mulsi_const9 */
561 COSTS_N_INSNS (4), /* muldi */
562 COSTS_N_INSNS (23), /* divsi */
563 COSTS_N_INSNS (23), /* divdi */
564 COSTS_N_INSNS (5), /* fp */
565 COSTS_N_INSNS (5), /* dmul */
566 COSTS_N_INSNS (21), /* sdiv */
567 COSTS_N_INSNS (35), /* ddiv */
570 /* Instruction costs on PPC8540 processors. */
572 struct processor_costs ppc8540_cost = {
573 COSTS_N_INSNS (4), /* mulsi */
574 COSTS_N_INSNS (4), /* mulsi_const */
575 COSTS_N_INSNS (4), /* mulsi_const9 */
576 COSTS_N_INSNS (4), /* muldi */
577 COSTS_N_INSNS (19), /* divsi */
578 COSTS_N_INSNS (19), /* divdi */
579 COSTS_N_INSNS (4), /* fp */
580 COSTS_N_INSNS (4), /* dmul */
581 COSTS_N_INSNS (29), /* sdiv */
582 COSTS_N_INSNS (29), /* ddiv */
585 /* Instruction costs on POWER4 and POWER5 processors. */
587 struct processor_costs power4_cost = {
588 COSTS_N_INSNS (3), /* mulsi */
589 COSTS_N_INSNS (2), /* mulsi_const */
590 COSTS_N_INSNS (2), /* mulsi_const9 */
591 COSTS_N_INSNS (4), /* muldi */
592 COSTS_N_INSNS (18), /* divsi */
593 COSTS_N_INSNS (34), /* divdi */
594 COSTS_N_INSNS (3), /* fp */
595 COSTS_N_INSNS (3), /* dmul */
596 COSTS_N_INSNS (17), /* sdiv */
597 COSTS_N_INSNS (17), /* ddiv */
600 /* Instruction costs on POWER6 processors. */
602 struct processor_costs power6_cost = {
603 COSTS_N_INSNS (8), /* mulsi */
604 COSTS_N_INSNS (8), /* mulsi_const */
605 COSTS_N_INSNS (8), /* mulsi_const9 */
606 COSTS_N_INSNS (8), /* muldi */
607 COSTS_N_INSNS (22), /* divsi */
608 COSTS_N_INSNS (28), /* divdi */
609 COSTS_N_INSNS (3), /* fp */
610 COSTS_N_INSNS (3), /* dmul */
611 COSTS_N_INSNS (13), /* sdiv */
612 COSTS_N_INSNS (16), /* ddiv */
616 static bool rs6000_function_ok_for_sibcall (tree, tree);
617 static const char *rs6000_invalid_within_doloop (rtx);
618 static rtx rs6000_generate_compare (enum rtx_code);
619 static void rs6000_maybe_dead (rtx);
620 static void rs6000_emit_stack_tie (void);
621 static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
622 static rtx spe_synthesize_frame_save (rtx);
623 static bool spe_func_has_64bit_regs_p (void);
624 static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
626 static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
627 static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
628 static unsigned rs6000_hash_constant (rtx);
629 static unsigned toc_hash_function (const void *);
630 static int toc_hash_eq (const void *, const void *);
631 static int constant_pool_expr_1 (rtx, int *, int *);
632 static bool constant_pool_expr_p (rtx);
633 static bool legitimate_small_data_p (enum machine_mode, rtx);
634 static bool legitimate_indexed_address_p (rtx, int);
635 static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
636 static struct machine_function * rs6000_init_machine_status (void);
637 static bool rs6000_assemble_integer (rtx, unsigned int, int);
638 static bool no_global_regs_above (int);
639 #ifdef HAVE_GAS_HIDDEN
640 static void rs6000_assemble_visibility (tree, int);
642 static int rs6000_ra_ever_killed (void);
643 static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
644 static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
645 static bool rs6000_ms_bitfield_layout_p (tree);
646 static tree rs6000_handle_struct_attribute (tree *, tree, tree, int, bool *);
647 static void rs6000_eliminate_indexed_memrefs (rtx operands[2]);
648 static const char *rs6000_mangle_fundamental_type (tree);
649 extern const struct attribute_spec rs6000_attribute_table[];
650 static void rs6000_set_default_type_attributes (tree);
651 static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
652 static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
653 static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
655 static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
656 static bool rs6000_return_in_memory (tree, tree);
657 static void rs6000_file_start (void);
659 static int rs6000_elf_reloc_rw_mask (void);
660 static void rs6000_elf_asm_out_constructor (rtx, int);
661 static void rs6000_elf_asm_out_destructor (rtx, int);
662 static void rs6000_elf_end_indicate_exec_stack (void) ATTRIBUTE_UNUSED;
663 static void rs6000_elf_asm_init_sections (void);
664 static section *rs6000_elf_select_rtx_section (enum machine_mode, rtx,
665 unsigned HOST_WIDE_INT);
666 static void rs6000_elf_encode_section_info (tree, rtx, int)
669 static bool rs6000_use_blocks_for_constant_p (enum machine_mode, rtx);
671 static void rs6000_xcoff_asm_output_anchor (rtx);
672 static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
673 static void rs6000_xcoff_asm_init_sections (void);
674 static int rs6000_xcoff_reloc_rw_mask (void);
675 static void rs6000_xcoff_asm_named_section (const char *, unsigned int, tree);
676 static section *rs6000_xcoff_select_section (tree, int,
677 unsigned HOST_WIDE_INT);
678 static void rs6000_xcoff_unique_section (tree, int);
679 static section *rs6000_xcoff_select_rtx_section
680 (enum machine_mode, rtx, unsigned HOST_WIDE_INT);
681 static const char * rs6000_xcoff_strip_name_encoding (const char *);
682 static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
683 static void rs6000_xcoff_file_start (void);
684 static void rs6000_xcoff_file_end (void);
686 static int rs6000_variable_issue (FILE *, int, rtx, int);
687 static bool rs6000_rtx_costs (rtx, int, int, int *);
688 static int rs6000_adjust_cost (rtx, rtx, rtx, int);
689 static void rs6000_sched_init (FILE *, int, int);
690 static bool is_microcoded_insn (rtx);
691 static bool is_nonpipeline_insn (rtx);
692 static bool is_cracked_insn (rtx);
693 static bool is_branch_slot_insn (rtx);
694 static bool is_load_insn (rtx);
695 static rtx get_store_dest (rtx pat);
696 static bool is_store_insn (rtx);
697 static bool set_to_load_agen (rtx,rtx);
698 static bool adjacent_mem_locations (rtx,rtx);
699 static int rs6000_adjust_priority (rtx, int);
700 static int rs6000_issue_rate (void);
701 static bool rs6000_is_costly_dependence (dep_t, int, int);
702 static rtx get_next_active_insn (rtx, rtx);
703 static bool insn_terminates_group_p (rtx , enum group_termination);
704 static bool insn_must_be_first_in_group (rtx);
705 static bool insn_must_be_last_in_group (rtx);
706 static bool is_costly_group (rtx *, rtx);
707 static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
708 static int redefine_groups (FILE *, int, rtx, rtx);
709 static int pad_groups (FILE *, int, rtx, rtx);
710 static void rs6000_sched_finish (FILE *, int);
711 static int rs6000_sched_reorder (FILE *, int, rtx *, int *, int);
712 static int rs6000_sched_reorder2 (FILE *, int, rtx *, int *, int);
713 static int rs6000_use_sched_lookahead (void);
714 static int rs6000_use_sched_lookahead_guard (rtx);
715 static tree rs6000_builtin_mask_for_load (void);
716 static tree rs6000_builtin_mul_widen_even (tree);
717 static tree rs6000_builtin_mul_widen_odd (tree);
718 static tree rs6000_builtin_conversion (enum tree_code, tree);
720 static void def_builtin (int, const char *, tree, int);
721 static void rs6000_init_builtins (void);
722 static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
723 static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
724 static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
725 static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
726 static void altivec_init_builtins (void);
727 static void rs6000_common_init_builtins (void);
728 static void rs6000_init_libfuncs (void);
730 static void enable_mask_for_builtins (struct builtin_description *, int,
731 enum rs6000_builtins,
732 enum rs6000_builtins);
733 static tree build_opaque_vector_type (tree, int);
734 static void spe_init_builtins (void);
735 static rtx spe_expand_builtin (tree, rtx, bool *);
736 static rtx spe_expand_stv_builtin (enum insn_code, tree);
737 static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
738 static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
739 static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
740 static rs6000_stack_t *rs6000_stack_info (void);
741 static void debug_stack_info (rs6000_stack_t *);
743 static rtx altivec_expand_builtin (tree, rtx, bool *);
744 static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
745 static rtx altivec_expand_st_builtin (tree, rtx, bool *);
746 static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
747 static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
748 static rtx altivec_expand_predicate_builtin (enum insn_code,
749 const char *, tree, rtx);
750 static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
751 static rtx altivec_expand_stv_builtin (enum insn_code, tree);
752 static rtx altivec_expand_vec_init_builtin (tree, tree, rtx);
753 static rtx altivec_expand_vec_set_builtin (tree);
754 static rtx altivec_expand_vec_ext_builtin (tree, rtx);
755 static int get_element_number (tree, tree);
756 static bool rs6000_handle_option (size_t, const char *, int);
757 static void rs6000_parse_tls_size_option (void);
758 static void rs6000_parse_yes_no_option (const char *, const char *, int *);
759 static int first_altivec_reg_to_save (void);
760 static unsigned int compute_vrsave_mask (void);
761 static void compute_save_world_info (rs6000_stack_t *info_ptr);
762 static void is_altivec_return_reg (rtx, void *);
763 static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
764 int easy_vector_constant (rtx, enum machine_mode);
765 static bool rs6000_is_opaque_type (tree);
766 static rtx rs6000_dwarf_register_span (rtx);
767 static void rs6000_init_dwarf_reg_sizes_extra (tree);
768 static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
769 static void rs6000_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
770 static rtx rs6000_tls_get_addr (void);
771 static rtx rs6000_got_sym (void);
772 static int rs6000_tls_symbol_ref_1 (rtx *, void *);
773 static const char *rs6000_get_some_local_dynamic_name (void);
774 static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
775 static rtx rs6000_complex_function_value (enum machine_mode);
776 static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
777 enum machine_mode, tree);
778 static void rs6000_darwin64_record_arg_advance_flush (CUMULATIVE_ARGS *,
780 static void rs6000_darwin64_record_arg_advance_recurse (CUMULATIVE_ARGS *,
781 tree, HOST_WIDE_INT);
782 static void rs6000_darwin64_record_arg_flush (CUMULATIVE_ARGS *,
785 static void rs6000_darwin64_record_arg_recurse (CUMULATIVE_ARGS *,
788 static rtx rs6000_darwin64_record_arg (CUMULATIVE_ARGS *, tree, int, bool);
789 static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int);
790 static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
791 static void setup_incoming_varargs (CUMULATIVE_ARGS *,
792 enum machine_mode, tree,
794 static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
796 static int rs6000_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
798 static const char *invalid_arg_for_unprototyped_fn (tree, tree, tree);
800 static void macho_branch_islands (void);
801 static int no_previous_def (tree function_name);
802 static tree get_prev_label (tree function_name);
803 static void rs6000_darwin_file_start (void);
806 static tree rs6000_build_builtin_va_list (void);
807 static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *);
808 static bool rs6000_must_pass_in_stack (enum machine_mode, tree);
809 static bool rs6000_scalar_mode_supported_p (enum machine_mode);
810 static bool rs6000_vector_mode_supported_p (enum machine_mode);
811 static int get_vec_cmp_insn (enum rtx_code, enum machine_mode,
813 static rtx rs6000_emit_vector_compare (enum rtx_code, rtx, rtx,
815 static int get_vsel_insn (enum machine_mode);
816 static void rs6000_emit_vector_select (rtx, rtx, rtx, rtx);
817 static tree rs6000_stack_protect_fail (void);
819 const int INSN_NOT_AVAILABLE = -1;
820 static enum machine_mode rs6000_eh_return_filter_mode (void);
822 /* Hash table stuff for keeping track of TOC entries. */
824 struct toc_hash_struct GTY(())
826 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
827 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
829 enum machine_mode key_mode;
833 static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
835 /* Default register names. */
836 char rs6000_reg_names[][8] =
838 "0", "1", "2", "3", "4", "5", "6", "7",
839 "8", "9", "10", "11", "12", "13", "14", "15",
840 "16", "17", "18", "19", "20", "21", "22", "23",
841 "24", "25", "26", "27", "28", "29", "30", "31",
842 "0", "1", "2", "3", "4", "5", "6", "7",
843 "8", "9", "10", "11", "12", "13", "14", "15",
844 "16", "17", "18", "19", "20", "21", "22", "23",
845 "24", "25", "26", "27", "28", "29", "30", "31",
846 "mq", "lr", "ctr","ap",
847 "0", "1", "2", "3", "4", "5", "6", "7",
849 /* AltiVec registers. */
850 "0", "1", "2", "3", "4", "5", "6", "7",
851 "8", "9", "10", "11", "12", "13", "14", "15",
852 "16", "17", "18", "19", "20", "21", "22", "23",
853 "24", "25", "26", "27", "28", "29", "30", "31",
856 "spe_acc", "spefscr",
857 /* Soft frame pointer. */
861 #ifdef TARGET_REGNAMES
862 static const char alt_reg_names[][8] =
864 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
865 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
866 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
867 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
868 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
869 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
870 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
871 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
872 "mq", "lr", "ctr", "ap",
873 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
875 /* AltiVec registers. */
876 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
877 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
878 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
879 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
882 "spe_acc", "spefscr",
883 /* Soft frame pointer. */
888 #ifndef MASK_STRICT_ALIGN
889 #define MASK_STRICT_ALIGN 0
891 #ifndef TARGET_PROFILE_KERNEL
892 #define TARGET_PROFILE_KERNEL 0
895 /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
896 #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
898 /* Initialize the GCC target structure. */
899 #undef TARGET_ATTRIBUTE_TABLE
900 #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
901 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
902 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
904 #undef TARGET_ASM_ALIGNED_DI_OP
905 #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
907 /* Default unaligned ops are only provided for ELF. Find the ops needed
908 for non-ELF systems. */
909 #ifndef OBJECT_FORMAT_ELF
911 /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
913 #undef TARGET_ASM_UNALIGNED_HI_OP
914 #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
915 #undef TARGET_ASM_UNALIGNED_SI_OP
916 #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
917 #undef TARGET_ASM_UNALIGNED_DI_OP
918 #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
921 #undef TARGET_ASM_UNALIGNED_HI_OP
922 #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
923 #undef TARGET_ASM_UNALIGNED_SI_OP
924 #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
925 #undef TARGET_ASM_UNALIGNED_DI_OP
926 #define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
927 #undef TARGET_ASM_ALIGNED_DI_OP
928 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
932 /* This hook deals with fixups for relocatable code and DI-mode objects
934 #undef TARGET_ASM_INTEGER
935 #define TARGET_ASM_INTEGER rs6000_assemble_integer
937 #ifdef HAVE_GAS_HIDDEN
938 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
939 #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
942 #undef TARGET_HAVE_TLS
943 #define TARGET_HAVE_TLS HAVE_AS_TLS
945 #undef TARGET_CANNOT_FORCE_CONST_MEM
946 #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
948 #undef TARGET_ASM_FUNCTION_PROLOGUE
949 #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
950 #undef TARGET_ASM_FUNCTION_EPILOGUE
951 #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
953 #undef TARGET_SCHED_VARIABLE_ISSUE
954 #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
956 #undef TARGET_SCHED_ISSUE_RATE
957 #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
958 #undef TARGET_SCHED_ADJUST_COST
959 #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
960 #undef TARGET_SCHED_ADJUST_PRIORITY
961 #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
962 #undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
963 #define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
964 #undef TARGET_SCHED_INIT
965 #define TARGET_SCHED_INIT rs6000_sched_init
966 #undef TARGET_SCHED_FINISH
967 #define TARGET_SCHED_FINISH rs6000_sched_finish
968 #undef TARGET_SCHED_REORDER
969 #define TARGET_SCHED_REORDER rs6000_sched_reorder
970 #undef TARGET_SCHED_REORDER2
971 #define TARGET_SCHED_REORDER2 rs6000_sched_reorder2
973 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
974 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
976 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD
977 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD rs6000_use_sched_lookahead_guard
979 #undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
980 #define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load
981 #undef TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_EVEN
982 #define TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_EVEN rs6000_builtin_mul_widen_even
983 #undef TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_ODD
984 #define TARGET_VECTORIZE_BUILTIN_MUL_WIDEN_ODD rs6000_builtin_mul_widen_odd
985 #undef TARGET_VECTORIZE_BUILTIN_CONVERSION
986 #define TARGET_VECTORIZE_BUILTIN_CONVERSION rs6000_builtin_conversion
988 #undef TARGET_INIT_BUILTINS
989 #define TARGET_INIT_BUILTINS rs6000_init_builtins
991 #undef TARGET_EXPAND_BUILTIN
992 #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
994 #undef TARGET_MANGLE_FUNDAMENTAL_TYPE
995 #define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
997 #undef TARGET_INIT_LIBFUNCS
998 #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
1001 #undef TARGET_BINDS_LOCAL_P
1002 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
1005 #undef TARGET_MS_BITFIELD_LAYOUT_P
1006 #define TARGET_MS_BITFIELD_LAYOUT_P rs6000_ms_bitfield_layout_p
1008 #undef TARGET_ASM_OUTPUT_MI_THUNK
1009 #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
1011 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
1012 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
1014 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
1015 #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
1017 #undef TARGET_INVALID_WITHIN_DOLOOP
1018 #define TARGET_INVALID_WITHIN_DOLOOP rs6000_invalid_within_doloop
1020 #undef TARGET_RTX_COSTS
1021 #define TARGET_RTX_COSTS rs6000_rtx_costs
1022 #undef TARGET_ADDRESS_COST
1023 #define TARGET_ADDRESS_COST hook_int_rtx_0
1025 #undef TARGET_VECTOR_OPAQUE_P
1026 #define TARGET_VECTOR_OPAQUE_P rs6000_is_opaque_type
1028 #undef TARGET_DWARF_REGISTER_SPAN
1029 #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
1031 #undef TARGET_INIT_DWARF_REG_SIZES_EXTRA
1032 #define TARGET_INIT_DWARF_REG_SIZES_EXTRA rs6000_init_dwarf_reg_sizes_extra
1034 /* On rs6000, function arguments are promoted, as are function return
1036 #undef TARGET_PROMOTE_FUNCTION_ARGS
1037 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
1038 #undef TARGET_PROMOTE_FUNCTION_RETURN
1039 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
1041 #undef TARGET_RETURN_IN_MEMORY
1042 #define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
1044 #undef TARGET_SETUP_INCOMING_VARARGS
1045 #define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
1047 /* Always strict argument naming on rs6000. */
1048 #undef TARGET_STRICT_ARGUMENT_NAMING
1049 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
1050 #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
1051 #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
1052 #undef TARGET_SPLIT_COMPLEX_ARG
1053 #define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
1054 #undef TARGET_MUST_PASS_IN_STACK
1055 #define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
1056 #undef TARGET_PASS_BY_REFERENCE
1057 #define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
1058 #undef TARGET_ARG_PARTIAL_BYTES
1059 #define TARGET_ARG_PARTIAL_BYTES rs6000_arg_partial_bytes
1061 #undef TARGET_BUILD_BUILTIN_VA_LIST
1062 #define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
1064 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
1065 #define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
1067 #undef TARGET_EH_RETURN_FILTER_MODE
1068 #define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
1070 #undef TARGET_SCALAR_MODE_SUPPORTED_P
1071 #define TARGET_SCALAR_MODE_SUPPORTED_P rs6000_scalar_mode_supported_p
1073 #undef TARGET_VECTOR_MODE_SUPPORTED_P
1074 #define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
1076 #undef TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN
1077 #define TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN invalid_arg_for_unprototyped_fn
1079 #undef TARGET_HANDLE_OPTION
1080 #define TARGET_HANDLE_OPTION rs6000_handle_option
1082 #undef TARGET_DEFAULT_TARGET_FLAGS
1083 #define TARGET_DEFAULT_TARGET_FLAGS \
1086 #undef TARGET_STACK_PROTECT_FAIL
1087 #define TARGET_STACK_PROTECT_FAIL rs6000_stack_protect_fail
1089 /* MPC604EUM 3.5.2 Weak Consistency between Multiple Processors
1090 The PowerPC architecture requires only weak consistency among
1091 processors--that is, memory accesses between processors need not be
1092 sequentially consistent and memory accesses among processors can occur
1093 in any order. The ability to order memory accesses weakly provides
1094 opportunities for more efficient use of the system bus. Unless a
1095 dependency exists, the 604e allows read operations to precede store
1097 #undef TARGET_RELAXED_ORDERING
1098 #define TARGET_RELAXED_ORDERING true
1101 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
1102 #define TARGET_ASM_OUTPUT_DWARF_DTPREL rs6000_output_dwarf_dtprel
1105 /* Use a 32-bit anchor range. This leads to sequences like:
1107 addis tmp,anchor,high
1110 where tmp itself acts as an anchor, and can be shared between
1111 accesses to the same 64k page. */
1112 #undef TARGET_MIN_ANCHOR_OFFSET
1113 #define TARGET_MIN_ANCHOR_OFFSET -0x7fffffff - 1
1114 #undef TARGET_MAX_ANCHOR_OFFSET
1115 #define TARGET_MAX_ANCHOR_OFFSET 0x7fffffff
1116 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
1117 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P rs6000_use_blocks_for_constant_p
1119 struct gcc_target targetm = TARGET_INITIALIZER;
1122 /* Value is 1 if hard register REGNO can hold a value of machine-mode
1125 rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
1127 /* The GPRs can hold any mode, but values bigger than one register
1128 cannot go past R31. */
1129 if (INT_REGNO_P (regno))
1130 return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1);
1132 /* The float registers can only hold floating modes and DImode.
1133 This excludes the 32-bit decimal float mode for now. */
1134 if (FP_REGNO_P (regno))
1136 (SCALAR_FLOAT_MODE_P (mode)
1138 && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1))
1139 || (GET_MODE_CLASS (mode) == MODE_INT
1140 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD);
1142 /* The CR register can only hold CC modes. */
1143 if (CR_REGNO_P (regno))
1144 return GET_MODE_CLASS (mode) == MODE_CC;
1146 if (XER_REGNO_P (regno))
1147 return mode == PSImode;
1149 /* AltiVec only in AldyVec registers. */
1150 if (ALTIVEC_REGNO_P (regno))
1151 return ALTIVEC_VECTOR_MODE (mode);
1153 /* ...but GPRs can hold SIMD data on the SPE in one register. */
1154 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1157 /* We cannot put TImode anywhere except general register and it must be
1158 able to fit within the register set. */
1160 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1163 /* Initialize rs6000_hard_regno_mode_ok_p table. */
1165 rs6000_init_hard_regno_mode_ok (void)
1169 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
1170 for (m = 0; m < NUM_MACHINE_MODES; ++m)
1171 if (rs6000_hard_regno_mode_ok (r, m))
1172 rs6000_hard_regno_mode_ok_p[m][r] = true;
1176 /* The Darwin version of SUBTARGET_OVERRIDE_OPTIONS. */
1179 darwin_rs6000_override_options (void)
1181 /* The Darwin ABI always includes AltiVec, can't be (validly) turned
1183 rs6000_altivec_abi = 1;
1184 TARGET_ALTIVEC_VRSAVE = 1;
1185 if (DEFAULT_ABI == ABI_DARWIN)
1187 if (MACHO_DYNAMIC_NO_PIC_P)
1190 warning (0, "-mdynamic-no-pic overrides -fpic or -fPIC");
1193 else if (flag_pic == 1)
1198 if (TARGET_64BIT && ! TARGET_POWERPC64)
1200 target_flags |= MASK_POWERPC64;
1201 warning (0, "-m64 requires PowerPC64 architecture, enabling");
1205 rs6000_default_long_calls = 1;
1206 target_flags |= MASK_SOFT_FLOAT;
1209 /* Make -m64 imply -maltivec. Darwin's 64-bit ABI includes
1211 if (!flag_mkernel && !flag_apple_kext
1213 && ! (target_flags_explicit & MASK_ALTIVEC))
1214 target_flags |= MASK_ALTIVEC;
1216 /* Unless the user (not the configurer) has explicitly overridden
1217 it with -mcpu=G3 or -mno-altivec, then 10.5+ targets default to
1218 G4 unless targetting the kernel. */
1221 && strverscmp (darwin_macosx_version_min, "10.5") >= 0
1222 && ! (target_flags_explicit & MASK_ALTIVEC)
1223 && ! rs6000_select[1].string)
1225 target_flags |= MASK_ALTIVEC;
1230 /* If not otherwise specified by a target, make 'long double' equivalent to
1233 #ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
1234 #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
1237 /* Override command line options. Mostly we process the processor
1238 type and sometimes adjust other TARGET_ options. */
1241 rs6000_override_options (const char *default_cpu)
1244 struct rs6000_cpu_select *ptr;
1247 /* Simplifications for entries below. */
1250 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
1251 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
1254 /* This table occasionally claims that a processor does not support
1255 a particular feature even though it does, but the feature is slower
1256 than the alternative. Thus, it shouldn't be relied on as a
1257 complete description of the processor's support.
1259 Please keep this list in order, and don't forget to update the
1260 documentation in invoke.texi when adding a new processor or
1264 const char *const name; /* Canonical processor name. */
1265 const enum processor_type processor; /* Processor type enum value. */
1266 const int target_enable; /* Target flags to enable. */
1267 } const processor_target_table[]
1268 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1269 {"403", PROCESSOR_PPC403,
1270 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
1271 {"405", PROCESSOR_PPC405,
1272 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_MULHW | MASK_DLMZB},
1273 {"405fp", PROCESSOR_PPC405,
1274 POWERPC_BASE_MASK | MASK_MULHW | MASK_DLMZB},
1275 {"440", PROCESSOR_PPC440,
1276 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_MULHW | MASK_DLMZB},
1277 {"440fp", PROCESSOR_PPC440,
1278 POWERPC_BASE_MASK | MASK_MULHW | MASK_DLMZB},
1279 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
1280 {"601", PROCESSOR_PPC601,
1281 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
1282 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1283 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1284 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1285 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1286 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1287 {"620", PROCESSOR_PPC620,
1288 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1289 {"630", PROCESSOR_PPC630,
1290 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1291 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1292 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
1293 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1294 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1295 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1296 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1297 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1298 {"8540", PROCESSOR_PPC8540,
1299 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_STRICT_ALIGN},
1300 /* 8548 has a dummy entry for now. */
1301 {"8548", PROCESSOR_PPC8540,
1302 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_STRICT_ALIGN},
1303 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1304 {"970", PROCESSOR_POWER4,
1305 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1306 {"cell", PROCESSOR_CELL,
1307 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1308 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
1309 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1310 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1311 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1312 {"G5", PROCESSOR_POWER4,
1313 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1314 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1315 {"power2", PROCESSOR_POWER,
1316 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1317 {"power3", PROCESSOR_PPC630,
1318 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1319 {"power4", PROCESSOR_POWER4,
1320 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
1321 {"power5", PROCESSOR_POWER5,
1322 POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GFXOPT
1323 | MASK_MFCRF | MASK_POPCNTB},
1324 {"power5+", PROCESSOR_POWER5,
1325 POWERPC_BASE_MASK | MASK_POWERPC64 | MASK_PPC_GFXOPT
1326 | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND},
1327 {"power6", PROCESSOR_POWER6,
1328 POWERPC_7400_MASK | MASK_POWERPC64 | MASK_MFCRF | MASK_POPCNTB
1329 | MASK_FPRND | MASK_CMPB | MASK_DFP },
1330 {"power6x", PROCESSOR_POWER6,
1331 POWERPC_7400_MASK | MASK_POWERPC64 | MASK_MFCRF | MASK_POPCNTB
1332 | MASK_FPRND | MASK_CMPB | MASK_MFPGPR | MASK_DFP },
1333 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
1334 {"powerpc64", PROCESSOR_POWERPC64,
1335 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1336 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1337 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1338 {"rios2", PROCESSOR_RIOS2,
1339 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1340 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1341 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1342 {"rs64", PROCESSOR_RS64A,
1343 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64}
1346 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
1348 /* Some OSs don't support saving the high part of 64-bit registers on
1349 context switch. Other OSs don't support saving Altivec registers.
1350 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
1351 settings; if the user wants either, the user must explicitly specify
1352 them and we won't interfere with the user's specification. */
1355 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
1356 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT | MASK_STRICT_ALIGN
1357 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
1358 | MASK_MFCRF | MASK_POPCNTB | MASK_FPRND | MASK_MULHW
1359 | MASK_DLMZB | MASK_CMPB | MASK_MFPGPR | MASK_DFP)
1362 rs6000_init_hard_regno_mode_ok ();
1364 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
1365 #ifdef OS_MISSING_POWERPC64
1366 if (OS_MISSING_POWERPC64)
1367 set_masks &= ~MASK_POWERPC64;
1369 #ifdef OS_MISSING_ALTIVEC
1370 if (OS_MISSING_ALTIVEC)
1371 set_masks &= ~MASK_ALTIVEC;
1374 /* Don't override by the processor default if given explicitly. */
1375 set_masks &= ~target_flags_explicit;
1377 /* Identify the processor type. */
1378 rs6000_select[0].string = default_cpu;
1379 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
1381 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
1383 ptr = &rs6000_select[i];
1384 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1386 for (j = 0; j < ptt_size; j++)
1387 if (! strcmp (ptr->string, processor_target_table[j].name))
1389 if (ptr->set_tune_p)
1390 rs6000_cpu = processor_target_table[j].processor;
1392 if (ptr->set_arch_p)
1394 target_flags &= ~set_masks;
1395 target_flags |= (processor_target_table[j].target_enable
1402 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
1409 /* If we are optimizing big endian systems for space, use the load/store
1410 multiple and string instructions. */
1411 if (BYTES_BIG_ENDIAN && optimize_size)
1412 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
1414 /* Don't allow -mmultiple or -mstring on little endian systems
1415 unless the cpu is a 750, because the hardware doesn't support the
1416 instructions used in little endian mode, and causes an alignment
1417 trap. The 750 does not cause an alignment trap (except when the
1418 target is unaligned). */
1420 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
1422 if (TARGET_MULTIPLE)
1424 target_flags &= ~MASK_MULTIPLE;
1425 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
1426 warning (0, "-mmultiple is not supported on little endian systems");
1431 target_flags &= ~MASK_STRING;
1432 if ((target_flags_explicit & MASK_STRING) != 0)
1433 warning (0, "-mstring is not supported on little endian systems");
1437 /* Set debug flags */
1438 if (rs6000_debug_name)
1440 if (! strcmp (rs6000_debug_name, "all"))
1441 rs6000_debug_stack = rs6000_debug_arg = 1;
1442 else if (! strcmp (rs6000_debug_name, "stack"))
1443 rs6000_debug_stack = 1;
1444 else if (! strcmp (rs6000_debug_name, "arg"))
1445 rs6000_debug_arg = 1;
1447 error ("unknown -mdebug-%s switch", rs6000_debug_name);
1450 if (rs6000_traceback_name)
1452 if (! strncmp (rs6000_traceback_name, "full", 4))
1453 rs6000_traceback = traceback_full;
1454 else if (! strncmp (rs6000_traceback_name, "part", 4))
1455 rs6000_traceback = traceback_part;
1456 else if (! strncmp (rs6000_traceback_name, "no", 2))
1457 rs6000_traceback = traceback_none;
1459 error ("unknown -mtraceback arg %qs; expecting %<full%>, %<partial%> or %<none%>",
1460 rs6000_traceback_name);
1463 if (!rs6000_explicit_options.long_double)
1464 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
1466 #ifndef POWERPC_LINUX
1467 if (!rs6000_explicit_options.ieee)
1468 rs6000_ieeequad = 1;
1471 /* Set Altivec ABI as default for powerpc64 linux. */
1472 if (TARGET_ELF && TARGET_64BIT)
1474 rs6000_altivec_abi = 1;
1475 TARGET_ALTIVEC_VRSAVE = 1;
1478 /* Set the Darwin64 ABI as default for 64-bit Darwin. */
1479 if (DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT)
1481 rs6000_darwin64_abi = 1;
1483 darwin_one_byte_bool = 1;
1485 /* Default to natural alignment, for better performance. */
1486 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1489 /* Place FP constants in the constant pool instead of TOC
1490 if section anchors enabled. */
1491 if (flag_section_anchors)
1492 TARGET_NO_FP_IN_TOC = 1;
1494 /* Handle -mtls-size option. */
1495 rs6000_parse_tls_size_option ();
1497 #ifdef SUBTARGET_OVERRIDE_OPTIONS
1498 SUBTARGET_OVERRIDE_OPTIONS;
1500 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
1501 SUBSUBTARGET_OVERRIDE_OPTIONS;
1503 #ifdef SUB3TARGET_OVERRIDE_OPTIONS
1504 SUB3TARGET_OVERRIDE_OPTIONS;
1509 /* The e500 does not have string instructions, and we set
1510 MASK_STRING above when optimizing for size. */
1511 if ((target_flags & MASK_STRING) != 0)
1512 target_flags = target_flags & ~MASK_STRING;
1514 else if (rs6000_select[1].string != NULL)
1516 /* For the powerpc-eabispe configuration, we set all these by
1517 default, so let's unset them if we manually set another
1518 CPU that is not the E500. */
1519 if (!rs6000_explicit_options.abi)
1521 if (!rs6000_explicit_options.spe)
1523 if (!rs6000_explicit_options.float_gprs)
1524 rs6000_float_gprs = 0;
1525 if (!rs6000_explicit_options.isel)
1529 /* Detect invalid option combinations with E500. */
1532 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
1533 && rs6000_cpu != PROCESSOR_POWER5
1534 && rs6000_cpu != PROCESSOR_POWER6
1535 && rs6000_cpu != PROCESSOR_CELL);
1536 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
1537 || rs6000_cpu == PROCESSOR_POWER5);
1538 rs6000_align_branch_targets = (rs6000_cpu == PROCESSOR_POWER4
1539 || rs6000_cpu == PROCESSOR_POWER5
1540 || rs6000_cpu == PROCESSOR_POWER6);
1542 rs6000_sched_restricted_insns_priority
1543 = (rs6000_sched_groups ? 1 : 0);
1545 /* Handle -msched-costly-dep option. */
1546 rs6000_sched_costly_dep
1547 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
1549 if (rs6000_sched_costly_dep_str)
1551 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
1552 rs6000_sched_costly_dep = no_dep_costly;
1553 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
1554 rs6000_sched_costly_dep = all_deps_costly;
1555 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
1556 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
1557 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
1558 rs6000_sched_costly_dep = store_to_load_dep_costly;
1560 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
1563 /* Handle -minsert-sched-nops option. */
1564 rs6000_sched_insert_nops
1565 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
1567 if (rs6000_sched_insert_nops_str)
1569 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
1570 rs6000_sched_insert_nops = sched_finish_none;
1571 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
1572 rs6000_sched_insert_nops = sched_finish_pad_groups;
1573 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
1574 rs6000_sched_insert_nops = sched_finish_regroup_exact;
1576 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
1579 #ifdef TARGET_REGNAMES
1580 /* If the user desires alternate register names, copy in the
1581 alternate names now. */
1582 if (TARGET_REGNAMES)
1583 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
1586 /* Set aix_struct_return last, after the ABI is determined.
1587 If -maix-struct-return or -msvr4-struct-return was explicitly
1588 used, don't override with the ABI default. */
1589 if (!rs6000_explicit_options.aix_struct_ret)
1590 aix_struct_return = (DEFAULT_ABI != ABI_V4 || DRAFT_V4_STRUCT_RET);
1592 if (TARGET_LONG_DOUBLE_128 && !TARGET_IEEEQUAD)
1593 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
1596 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
1598 /* We can only guarantee the availability of DI pseudo-ops when
1599 assembling for 64-bit targets. */
1602 targetm.asm_out.aligned_op.di = NULL;
1603 targetm.asm_out.unaligned_op.di = NULL;
1606 /* Set branch target alignment, if not optimizing for size. */
1609 /* Cell wants to be aligned 8byte for dual issue. */
1610 if (rs6000_cpu == PROCESSOR_CELL)
1612 if (align_functions <= 0)
1613 align_functions = 8;
1614 if (align_jumps <= 0)
1616 if (align_loops <= 0)
1619 if (rs6000_align_branch_targets)
1621 if (align_functions <= 0)
1622 align_functions = 16;
1623 if (align_jumps <= 0)
1625 if (align_loops <= 0)
1628 if (align_jumps_max_skip <= 0)
1629 align_jumps_max_skip = 15;
1630 if (align_loops_max_skip <= 0)
1631 align_loops_max_skip = 15;
1634 /* Arrange to save and restore machine status around nested functions. */
1635 init_machine_status = rs6000_init_machine_status;
1637 /* We should always be splitting complex arguments, but we can't break
1638 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1639 if (DEFAULT_ABI != ABI_AIX)
1640 targetm.calls.split_complex_arg = NULL;
1642 /* Initialize rs6000_cost with the appropriate target costs. */
1644 rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
1648 case PROCESSOR_RIOS1:
1649 rs6000_cost = &rios1_cost;
1652 case PROCESSOR_RIOS2:
1653 rs6000_cost = &rios2_cost;
1656 case PROCESSOR_RS64A:
1657 rs6000_cost = &rs64a_cost;
1660 case PROCESSOR_MPCCORE:
1661 rs6000_cost = &mpccore_cost;
1664 case PROCESSOR_PPC403:
1665 rs6000_cost = &ppc403_cost;
1668 case PROCESSOR_PPC405:
1669 rs6000_cost = &ppc405_cost;
1672 case PROCESSOR_PPC440:
1673 rs6000_cost = &ppc440_cost;
1676 case PROCESSOR_PPC601:
1677 rs6000_cost = &ppc601_cost;
1680 case PROCESSOR_PPC603:
1681 rs6000_cost = &ppc603_cost;
1684 case PROCESSOR_PPC604:
1685 rs6000_cost = &ppc604_cost;
1688 case PROCESSOR_PPC604e:
1689 rs6000_cost = &ppc604e_cost;
1692 case PROCESSOR_PPC620:
1693 rs6000_cost = &ppc620_cost;
1696 case PROCESSOR_PPC630:
1697 rs6000_cost = &ppc630_cost;
1700 case PROCESSOR_CELL:
1701 rs6000_cost = &ppccell_cost;
1704 case PROCESSOR_PPC750:
1705 case PROCESSOR_PPC7400:
1706 rs6000_cost = &ppc750_cost;
1709 case PROCESSOR_PPC7450:
1710 rs6000_cost = &ppc7450_cost;
1713 case PROCESSOR_PPC8540:
1714 rs6000_cost = &ppc8540_cost;
1717 case PROCESSOR_POWER4:
1718 case PROCESSOR_POWER5:
1719 rs6000_cost = &power4_cost;
1722 case PROCESSOR_POWER6:
1723 rs6000_cost = &power6_cost;
1731 /* Implement targetm.vectorize.builtin_mask_for_load. */
1733 rs6000_builtin_mask_for_load (void)
1736 return altivec_builtin_mask_for_load;
1741 /* Implement targetm.vectorize.builtin_conversion. */
1743 rs6000_builtin_conversion (enum tree_code code, tree type)
1745 if (!TARGET_ALTIVEC)
1751 switch (TYPE_MODE (type))
1754 return TYPE_UNSIGNED (type) ?
1755 rs6000_builtin_decls[ALTIVEC_BUILTIN_VCFUX] :
1756 rs6000_builtin_decls[ALTIVEC_BUILTIN_VCFSX];
1765 /* Implement targetm.vectorize.builtin_mul_widen_even. */
1767 rs6000_builtin_mul_widen_even (tree type)
1769 if (!TARGET_ALTIVEC)
1772 switch (TYPE_MODE (type))
1775 return TYPE_UNSIGNED (type) ?
1776 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULEUH] :
1777 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULESH];
1780 return TYPE_UNSIGNED (type) ?
1781 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULEUB] :
1782 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULESB];
1788 /* Implement targetm.vectorize.builtin_mul_widen_odd. */
1790 rs6000_builtin_mul_widen_odd (tree type)
1792 if (!TARGET_ALTIVEC)
1795 switch (TYPE_MODE (type))
1798 return TYPE_UNSIGNED (type) ?
1799 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOUH] :
1800 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOSH];
1803 return TYPE_UNSIGNED (type) ?
1804 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOUB] :
1805 rs6000_builtin_decls[ALTIVEC_BUILTIN_VMULOSB];
1811 /* Handle generic options of the form -mfoo=yes/no.
1812 NAME is the option name.
1813 VALUE is the option value.
1814 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1815 whether the option value is 'yes' or 'no' respectively. */
1817 rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
1821 else if (!strcmp (value, "yes"))
1823 else if (!strcmp (value, "no"))
1826 error ("unknown -m%s= option specified: '%s'", name, value);
1829 /* Validate and record the size specified with the -mtls-size option. */
1832 rs6000_parse_tls_size_option (void)
1834 if (rs6000_tls_size_string == 0)
1836 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1837 rs6000_tls_size = 16;
1838 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1839 rs6000_tls_size = 32;
1840 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1841 rs6000_tls_size = 64;
1843 error ("bad value %qs for -mtls-size switch", rs6000_tls_size_string);
1847 optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
1849 if (DEFAULT_ABI == ABI_DARWIN)
1850 /* The Darwin libraries never set errno, so we might as well
1851 avoid calling them when that's the only reason we would. */
1852 flag_errno_math = 0;
1854 /* Double growth factor to counter reduced min jump length. */
1855 set_param_value ("max-grow-copy-bb-insns", 16);
1857 /* Enable section anchors by default.
1858 Skip section anchors for Objective C and Objective C++
1859 until front-ends fixed. */
1860 if (!TARGET_MACHO && lang_hooks.name[4] != 'O')
1861 flag_section_anchors = 1;
1864 /* Implement TARGET_HANDLE_OPTION. */
1867 rs6000_handle_option (size_t code, const char *arg, int value)
1872 target_flags &= ~(MASK_POWER | MASK_POWER2
1873 | MASK_MULTIPLE | MASK_STRING);
1874 target_flags_explicit |= (MASK_POWER | MASK_POWER2
1875 | MASK_MULTIPLE | MASK_STRING);
1877 case OPT_mno_powerpc:
1878 target_flags &= ~(MASK_POWERPC | MASK_PPC_GPOPT
1879 | MASK_PPC_GFXOPT | MASK_POWERPC64);
1880 target_flags_explicit |= (MASK_POWERPC | MASK_PPC_GPOPT
1881 | MASK_PPC_GFXOPT | MASK_POWERPC64);
1884 target_flags &= ~MASK_MINIMAL_TOC;
1885 TARGET_NO_FP_IN_TOC = 0;
1886 TARGET_NO_SUM_IN_TOC = 0;
1887 target_flags_explicit |= MASK_MINIMAL_TOC;
1888 #ifdef TARGET_USES_SYSV4_OPT
1889 /* Note, V.4 no longer uses a normal TOC, so make -mfull-toc, be
1890 just the same as -mminimal-toc. */
1891 target_flags |= MASK_MINIMAL_TOC;
1892 target_flags_explicit |= MASK_MINIMAL_TOC;
1896 #ifdef TARGET_USES_SYSV4_OPT
1898 /* Make -mtoc behave like -mminimal-toc. */
1899 target_flags |= MASK_MINIMAL_TOC;
1900 target_flags_explicit |= MASK_MINIMAL_TOC;
1904 #ifdef TARGET_USES_AIX64_OPT
1909 target_flags |= MASK_POWERPC64 | MASK_POWERPC;
1910 target_flags |= ~target_flags_explicit & MASK_PPC_GFXOPT;
1911 target_flags_explicit |= MASK_POWERPC64 | MASK_POWERPC;
1914 #ifdef TARGET_USES_AIX64_OPT
1919 target_flags &= ~MASK_POWERPC64;
1920 target_flags_explicit |= MASK_POWERPC64;
1923 case OPT_minsert_sched_nops_:
1924 rs6000_sched_insert_nops_str = arg;
1927 case OPT_mminimal_toc:
1930 TARGET_NO_FP_IN_TOC = 0;
1931 TARGET_NO_SUM_IN_TOC = 0;
1938 target_flags |= (MASK_MULTIPLE | MASK_STRING);
1939 target_flags_explicit |= (MASK_MULTIPLE | MASK_STRING);
1946 target_flags |= (MASK_POWER | MASK_MULTIPLE | MASK_STRING);
1947 target_flags_explicit |= (MASK_POWER | MASK_MULTIPLE | MASK_STRING);
1951 case OPT_mpowerpc_gpopt:
1952 case OPT_mpowerpc_gfxopt:
1955 target_flags |= MASK_POWERPC;
1956 target_flags_explicit |= MASK_POWERPC;
1960 case OPT_maix_struct_return:
1961 case OPT_msvr4_struct_return:
1962 rs6000_explicit_options.aix_struct_ret = true;
1966 rs6000_parse_yes_no_option ("vrsave", arg, &(TARGET_ALTIVEC_VRSAVE));
1970 rs6000_explicit_options.isel = true;
1971 rs6000_parse_yes_no_option ("isel", arg, &(rs6000_isel));
1975 rs6000_explicit_options.spe = true;
1976 rs6000_parse_yes_no_option ("spe", arg, &(rs6000_spe));
1980 rs6000_debug_name = arg;
1983 #ifdef TARGET_USES_SYSV4_OPT
1985 rs6000_abi_name = arg;
1989 rs6000_sdata_name = arg;
1992 case OPT_mtls_size_:
1993 rs6000_tls_size_string = arg;
1996 case OPT_mrelocatable:
1999 target_flags |= MASK_MINIMAL_TOC;
2000 target_flags_explicit |= MASK_MINIMAL_TOC;
2001 TARGET_NO_FP_IN_TOC = 1;
2005 case OPT_mrelocatable_lib:
2008 target_flags |= MASK_RELOCATABLE | MASK_MINIMAL_TOC;
2009 target_flags_explicit |= MASK_RELOCATABLE | MASK_MINIMAL_TOC;
2010 TARGET_NO_FP_IN_TOC = 1;
2014 target_flags &= ~MASK_RELOCATABLE;
2015 target_flags_explicit |= MASK_RELOCATABLE;
2021 if (!strcmp (arg, "altivec"))
2023 rs6000_explicit_options.abi = true;
2024 rs6000_altivec_abi = 1;
2027 else if (! strcmp (arg, "no-altivec"))
2029 /* ??? Don't set rs6000_explicit_options.abi here, to allow
2030 the default for rs6000_spe_abi to be chosen later. */
2031 rs6000_altivec_abi = 0;
2033 else if (! strcmp (arg, "spe"))
2035 rs6000_explicit_options.abi = true;
2037 rs6000_altivec_abi = 0;
2038 if (!TARGET_SPE_ABI)
2039 error ("not configured for ABI: '%s'", arg);
2041 else if (! strcmp (arg, "no-spe"))
2043 rs6000_explicit_options.abi = true;
2047 /* These are here for testing during development only, do not
2048 document in the manual please. */
2049 else if (! strcmp (arg, "d64"))
2051 rs6000_darwin64_abi = 1;
2052 warning (0, "Using darwin64 ABI");
2054 else if (! strcmp (arg, "d32"))
2056 rs6000_darwin64_abi = 0;
2057 warning (0, "Using old darwin ABI");
2060 else if (! strcmp (arg, "ibmlongdouble"))
2062 rs6000_explicit_options.ieee = true;
2063 rs6000_ieeequad = 0;
2064 warning (0, "Using IBM extended precision long double");
2066 else if (! strcmp (arg, "ieeelongdouble"))
2068 rs6000_explicit_options.ieee = true;
2069 rs6000_ieeequad = 1;
2070 warning (0, "Using IEEE extended precision long double");
2075 error ("unknown ABI specified: '%s'", arg);
2081 rs6000_select[1].string = arg;
2085 rs6000_select[2].string = arg;
2088 case OPT_mtraceback_:
2089 rs6000_traceback_name = arg;
2092 case OPT_mfloat_gprs_:
2093 rs6000_explicit_options.float_gprs = true;
2094 if (! strcmp (arg, "yes") || ! strcmp (arg, "single"))
2095 rs6000_float_gprs = 1;
2096 else if (! strcmp (arg, "double"))
2097 rs6000_float_gprs = 2;
2098 else if (! strcmp (arg, "no"))
2099 rs6000_float_gprs = 0;
2102 error ("invalid option for -mfloat-gprs: '%s'", arg);
2107 case OPT_mlong_double_:
2108 rs6000_explicit_options.long_double = true;
2109 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
2110 if (value != 64 && value != 128)
2112 error ("Unknown switch -mlong-double-%s", arg);
2113 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
2117 rs6000_long_double_type_size = value;
2120 case OPT_msched_costly_dep_:
2121 rs6000_sched_costly_dep_str = arg;
2125 rs6000_explicit_options.alignment = true;
2126 if (! strcmp (arg, "power"))
2128 /* On 64-bit Darwin, power alignment is ABI-incompatible with
2129 some C library functions, so warn about it. The flag may be
2130 useful for performance studies from time to time though, so
2131 don't disable it entirely. */
2132 if (DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT)
2133 warning (0, "-malign-power is not supported for 64-bit Darwin;"
2134 " it is incompatible with the installed C and C++ libraries");
2135 rs6000_alignment_flags = MASK_ALIGN_POWER;
2137 else if (! strcmp (arg, "natural"))
2138 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
2141 error ("unknown -malign-XXXXX option specified: '%s'", arg);
2149 /* Do anything needed at the start of the asm file. */
2152 rs6000_file_start (void)
2156 const char *start = buffer;
2157 struct rs6000_cpu_select *ptr;
2158 const char *default_cpu = TARGET_CPU_DEFAULT;
2159 FILE *file = asm_out_file;
2161 default_file_start ();
2163 #ifdef TARGET_BI_ARCH
2164 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
2168 if (flag_verbose_asm)
2170 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
2171 rs6000_select[0].string = default_cpu;
2173 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
2175 ptr = &rs6000_select[i];
2176 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
2178 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
2183 if (PPC405_ERRATUM77)
2185 fprintf (file, "%s PPC405CR_ERRATUM77", start);
2189 #ifdef USING_ELFOS_H
2190 switch (rs6000_sdata)
2192 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
2193 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
2194 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
2195 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
2198 if (rs6000_sdata && g_switch_value)
2200 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
2210 if (DEFAULT_ABI == ABI_AIX || (TARGET_ELF && flag_pic == 2))
2212 switch_to_section (toc_section);
2213 switch_to_section (text_section);
2218 /* Return nonzero if this function is known to have a null epilogue. */
2221 direct_return (void)
2223 if (reload_completed)
2225 rs6000_stack_t *info = rs6000_stack_info ();
2227 if (info->first_gp_reg_save == 32
2228 && info->first_fp_reg_save == 64
2229 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
2230 && ! info->lr_save_p
2231 && ! info->cr_save_p
2232 && info->vrsave_mask == 0
2240 /* Return the number of instructions it takes to form a constant in an
2241 integer register. */
2244 num_insns_constant_wide (HOST_WIDE_INT value)
2246 /* signed constant loadable with {cal|addi} */
2247 if ((unsigned HOST_WIDE_INT) (value + 0x8000) < 0x10000)
2250 /* constant loadable with {cau|addis} */
2251 else if ((value & 0xffff) == 0
2252 && (value >> 31 == -1 || value >> 31 == 0))
2255 #if HOST_BITS_PER_WIDE_INT == 64
2256 else if (TARGET_POWERPC64)
2258 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
2259 HOST_WIDE_INT high = value >> 31;
2261 if (high == 0 || high == -1)
2267 return num_insns_constant_wide (high) + 1;
2269 return (num_insns_constant_wide (high)
2270 + num_insns_constant_wide (low) + 1);
2279 num_insns_constant (rtx op, enum machine_mode mode)
2281 HOST_WIDE_INT low, high;
2283 switch (GET_CODE (op))
2286 #if HOST_BITS_PER_WIDE_INT == 64
2287 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
2288 && mask64_operand (op, mode))
2292 return num_insns_constant_wide (INTVAL (op));
2300 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2301 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
2302 return num_insns_constant_wide ((HOST_WIDE_INT) l);
2305 if (mode == VOIDmode || mode == DImode)
2307 high = CONST_DOUBLE_HIGH (op);
2308 low = CONST_DOUBLE_LOW (op);
2315 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2316 if (DECIMAL_FLOAT_MODE_P (mode))
2317 REAL_VALUE_TO_TARGET_DECIMAL64 (rv, l);
2319 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
2320 high = l[WORDS_BIG_ENDIAN == 0];
2321 low = l[WORDS_BIG_ENDIAN != 0];
2325 return (num_insns_constant_wide (low)
2326 + num_insns_constant_wide (high));
2329 if ((high == 0 && low >= 0)
2330 || (high == -1 && low < 0))
2331 return num_insns_constant_wide (low);
2333 else if (mask64_operand (op, mode))
2337 return num_insns_constant_wide (high) + 1;
2340 return (num_insns_constant_wide (high)
2341 + num_insns_constant_wide (low) + 1);
2349 /* Interpret element ELT of the CONST_VECTOR OP as an integer value.
2350 If the mode of OP is MODE_VECTOR_INT, this simply returns the
2351 corresponding element of the vector, but for V4SFmode and V2SFmode,
2352 the corresponding "float" is interpreted as an SImode integer. */
2354 static HOST_WIDE_INT
2355 const_vector_elt_as_int (rtx op, unsigned int elt)
2357 rtx tmp = CONST_VECTOR_ELT (op, elt);
2358 if (GET_MODE (op) == V4SFmode
2359 || GET_MODE (op) == V2SFmode)
2360 tmp = gen_lowpart (SImode, tmp);
2361 return INTVAL (tmp);
2364 /* Return true if OP can be synthesized with a particular vspltisb, vspltish
2365 or vspltisw instruction. OP is a CONST_VECTOR. Which instruction is used
2366 depends on STEP and COPIES, one of which will be 1. If COPIES > 1,
2367 all items are set to the same value and contain COPIES replicas of the
2368 vsplt's operand; if STEP > 1, one in STEP elements is set to the vsplt's
2369 operand and the others are set to the value of the operand's msb. */
2372 vspltis_constant (rtx op, unsigned step, unsigned copies)
2374 enum machine_mode mode = GET_MODE (op);
2375 enum machine_mode inner = GET_MODE_INNER (mode);
2378 unsigned nunits = GET_MODE_NUNITS (mode);
2379 unsigned bitsize = GET_MODE_BITSIZE (inner);
2380 unsigned mask = GET_MODE_MASK (inner);
2382 HOST_WIDE_INT val = const_vector_elt_as_int (op, nunits - 1);
2383 HOST_WIDE_INT splat_val = val;
2384 HOST_WIDE_INT msb_val = val > 0 ? 0 : -1;
2386 /* Construct the value to be splatted, if possible. If not, return 0. */
2387 for (i = 2; i <= copies; i *= 2)
2389 HOST_WIDE_INT small_val;
2391 small_val = splat_val >> bitsize;
2393 if (splat_val != ((small_val << bitsize) | (small_val & mask)))
2395 splat_val = small_val;
2398 /* Check if SPLAT_VAL can really be the operand of a vspltis[bhw]. */
2399 if (EASY_VECTOR_15 (splat_val))
2402 /* Also check if we can splat, and then add the result to itself. Do so if
2403 the value is positive, of if the splat instruction is using OP's mode;
2404 for splat_val < 0, the splat and the add should use the same mode. */
2405 else if (EASY_VECTOR_15_ADD_SELF (splat_val)
2406 && (splat_val >= 0 || (step == 1 && copies == 1)))
2412 /* Check if VAL is present in every STEP-th element, and the
2413 other elements are filled with its most significant bit. */
2414 for (i = 0; i < nunits - 1; ++i)
2416 HOST_WIDE_INT desired_val;
2417 if (((i + 1) & (step - 1)) == 0)
2420 desired_val = msb_val;
2422 if (desired_val != const_vector_elt_as_int (op, i))
2430 /* Return true if OP is of the given MODE and can be synthesized
2431 with a vspltisb, vspltish or vspltisw. */
2434 easy_altivec_constant (rtx op, enum machine_mode mode)
2436 unsigned step, copies;
2438 if (mode == VOIDmode)
2439 mode = GET_MODE (op);
2440 else if (mode != GET_MODE (op))
2443 /* Start with a vspltisw. */
2444 step = GET_MODE_NUNITS (mode) / 4;
2447 if (vspltis_constant (op, step, copies))
2450 /* Then try with a vspltish. */
2456 if (vspltis_constant (op, step, copies))
2459 /* And finally a vspltisb. */
2465 if (vspltis_constant (op, step, copies))
2471 /* Generate a VEC_DUPLICATE representing a vspltis[bhw] instruction whose
2472 result is OP. Abort if it is not possible. */
2475 gen_easy_altivec_constant (rtx op)
2477 enum machine_mode mode = GET_MODE (op);
2478 int nunits = GET_MODE_NUNITS (mode);
2479 rtx last = CONST_VECTOR_ELT (op, nunits - 1);
2480 unsigned step = nunits / 4;
2481 unsigned copies = 1;
2483 /* Start with a vspltisw. */
2484 if (vspltis_constant (op, step, copies))
2485 return gen_rtx_VEC_DUPLICATE (V4SImode, gen_lowpart (SImode, last));
2487 /* Then try with a vspltish. */
2493 if (vspltis_constant (op, step, copies))
2494 return gen_rtx_VEC_DUPLICATE (V8HImode, gen_lowpart (HImode, last));
2496 /* And finally a vspltisb. */
2502 if (vspltis_constant (op, step, copies))
2503 return gen_rtx_VEC_DUPLICATE (V16QImode, gen_lowpart (QImode, last));
2509 output_vec_const_move (rtx *operands)
2512 enum machine_mode mode;
2517 mode = GET_MODE (dest);
2522 if (zero_constant (vec, mode))
2523 return "vxor %0,%0,%0";
2525 splat_vec = gen_easy_altivec_constant (vec);
2526 gcc_assert (GET_CODE (splat_vec) == VEC_DUPLICATE);
2527 operands[1] = XEXP (splat_vec, 0);
2528 if (!EASY_VECTOR_15 (INTVAL (operands[1])))
2531 switch (GET_MODE (splat_vec))
2534 return "vspltisw %0,%1";
2537 return "vspltish %0,%1";
2540 return "vspltisb %0,%1";
2547 gcc_assert (TARGET_SPE);
2549 /* Vector constant 0 is handled as a splitter of V2SI, and in the
2550 pattern of V1DI, V4HI, and V2SF.
2552 FIXME: We should probably return # and add post reload
2553 splitters for these, but this way is so easy ;-). */
2554 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
2555 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
2556 operands[1] = CONST_VECTOR_ELT (vec, 0);
2557 operands[2] = CONST_VECTOR_ELT (vec, 1);
2559 return "li %0,%1\n\tevmergelo %0,%0,%0";
2561 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
2564 /* Initialize vector TARGET to VALS. */
2567 rs6000_expand_vector_init (rtx target, rtx vals)
2569 enum machine_mode mode = GET_MODE (target);
2570 enum machine_mode inner_mode = GET_MODE_INNER (mode);
2571 int n_elts = GET_MODE_NUNITS (mode);
2572 int n_var = 0, one_var = -1;
2573 bool all_same = true, all_const_zero = true;
2577 for (i = 0; i < n_elts; ++i)
2579 x = XVECEXP (vals, 0, i);
2580 if (!CONSTANT_P (x))
2581 ++n_var, one_var = i;
2582 else if (x != CONST0_RTX (inner_mode))
2583 all_const_zero = false;
2585 if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
2591 if (mode != V4SFmode && all_const_zero)
2593 /* Zero register. */
2594 emit_insn (gen_rtx_SET (VOIDmode, target,
2595 gen_rtx_XOR (mode, target, target)));
2598 else if (mode != V4SFmode && easy_vector_constant (vals, mode))
2600 /* Splat immediate. */
2601 emit_insn (gen_rtx_SET (VOIDmode, target, vals));
2605 ; /* Splat vector element. */
2608 /* Load from constant pool. */
2609 emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
2614 /* Store value to stack temp. Load vector element. Splat. */
2617 mem = assign_stack_temp (mode, GET_MODE_SIZE (inner_mode), 0);
2618 emit_move_insn (adjust_address_nv (mem, inner_mode, 0),
2619 XVECEXP (vals, 0, 0));
2620 x = gen_rtx_UNSPEC (VOIDmode,
2621 gen_rtvec (1, const0_rtx), UNSPEC_LVE);
2622 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2624 gen_rtx_SET (VOIDmode,
2627 x = gen_rtx_VEC_SELECT (inner_mode, target,
2628 gen_rtx_PARALLEL (VOIDmode,
2629 gen_rtvec (1, const0_rtx)));
2630 emit_insn (gen_rtx_SET (VOIDmode, target,
2631 gen_rtx_VEC_DUPLICATE (mode, x)));
2635 /* One field is non-constant. Load constant then overwrite
2639 rtx copy = copy_rtx (vals);
2641 /* Load constant part of vector, substitute neighboring value for
2643 XVECEXP (copy, 0, one_var) = XVECEXP (vals, 0, (one_var + 1) % n_elts);
2644 rs6000_expand_vector_init (target, copy);
2646 /* Insert variable. */
2647 rs6000_expand_vector_set (target, XVECEXP (vals, 0, one_var), one_var);
2651 /* Construct the vector in memory one field at a time
2652 and load the whole vector. */
2653 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2654 for (i = 0; i < n_elts; i++)
2655 emit_move_insn (adjust_address_nv (mem, inner_mode,
2656 i * GET_MODE_SIZE (inner_mode)),
2657 XVECEXP (vals, 0, i));
2658 emit_move_insn (target, mem);
2661 /* Set field ELT of TARGET to VAL. */
2664 rs6000_expand_vector_set (rtx target, rtx val, int elt)
2666 enum machine_mode mode = GET_MODE (target);
2667 enum machine_mode inner_mode = GET_MODE_INNER (mode);
2668 rtx reg = gen_reg_rtx (mode);
2670 int width = GET_MODE_SIZE (inner_mode);
2673 /* Load single variable value. */
2674 mem = assign_stack_temp (mode, GET_MODE_SIZE (inner_mode), 0);
2675 emit_move_insn (adjust_address_nv (mem, inner_mode, 0), val);
2676 x = gen_rtx_UNSPEC (VOIDmode,
2677 gen_rtvec (1, const0_rtx), UNSPEC_LVE);
2678 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2680 gen_rtx_SET (VOIDmode,
2684 /* Linear sequence. */
2685 mask = gen_rtx_PARALLEL (V16QImode, rtvec_alloc (16));
2686 for (i = 0; i < 16; ++i)
2687 XVECEXP (mask, 0, i) = GEN_INT (i);
2689 /* Set permute mask to insert element into target. */
2690 for (i = 0; i < width; ++i)
2691 XVECEXP (mask, 0, elt*width + i)
2692 = GEN_INT (i + 0x10);
2693 x = gen_rtx_CONST_VECTOR (V16QImode, XVEC (mask, 0));
2694 x = gen_rtx_UNSPEC (mode,
2695 gen_rtvec (3, target, reg,
2696 force_reg (V16QImode, x)),
2698 emit_insn (gen_rtx_SET (VOIDmode, target, x));
2701 /* Extract field ELT from VEC into TARGET. */
2704 rs6000_expand_vector_extract (rtx target, rtx vec, int elt)
2706 enum machine_mode mode = GET_MODE (vec);
2707 enum machine_mode inner_mode = GET_MODE_INNER (mode);
2710 /* Allocate mode-sized buffer. */
2711 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode), 0);
2713 /* Add offset to field within buffer matching vector element. */
2714 mem = adjust_address_nv (mem, mode, elt * GET_MODE_SIZE (inner_mode));
2716 /* Store single field into mode-sized buffer. */
2717 x = gen_rtx_UNSPEC (VOIDmode,
2718 gen_rtvec (1, const0_rtx), UNSPEC_STVE);
2719 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2721 gen_rtx_SET (VOIDmode,
2724 emit_move_insn (target, adjust_address_nv (mem, inner_mode, 0));
2727 /* Generates shifts and masks for a pair of rldicl or rldicr insns to
2728 implement ANDing by the mask IN. */
2730 build_mask64_2_operands (rtx in, rtx *out)
2732 #if HOST_BITS_PER_WIDE_INT >= 64
2733 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2736 gcc_assert (GET_CODE (in) == CONST_INT);
2741 /* Assume c initially something like 0x00fff000000fffff. The idea
2742 is to rotate the word so that the middle ^^^^^^ group of zeros
2743 is at the MS end and can be cleared with an rldicl mask. We then
2744 rotate back and clear off the MS ^^ group of zeros with a
2746 c = ~c; /* c == 0xff000ffffff00000 */
2747 lsb = c & -c; /* lsb == 0x0000000000100000 */
2748 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2749 c = ~c; /* c == 0x00fff000000fffff */
2750 c &= -lsb; /* c == 0x00fff00000000000 */
2751 lsb = c & -c; /* lsb == 0x0000100000000000 */
2752 c = ~c; /* c == 0xff000fffffffffff */
2753 c &= -lsb; /* c == 0xff00000000000000 */
2755 while ((lsb >>= 1) != 0)
2756 shift++; /* shift == 44 on exit from loop */
2757 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2758 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2759 m2 = ~c; /* m2 == 0x00ffffffffffffff */
2763 /* Assume c initially something like 0xff000f0000000000. The idea
2764 is to rotate the word so that the ^^^ middle group of zeros
2765 is at the LS end and can be cleared with an rldicr mask. We then
2766 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2768 lsb = c & -c; /* lsb == 0x0000010000000000 */
2769 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2770 c = ~c; /* c == 0x00fff0ffffffffff */
2771 c &= -lsb; /* c == 0x00fff00000000000 */
2772 lsb = c & -c; /* lsb == 0x0000100000000000 */
2773 c = ~c; /* c == 0xff000fffffffffff */
2774 c &= -lsb; /* c == 0xff00000000000000 */
2776 while ((lsb >>= 1) != 0)
2777 shift++; /* shift == 44 on exit from loop */
2778 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2779 m1 >>= shift; /* m1 == 0x0000000000000fff */
2780 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2783 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2784 masks will be all 1's. We are guaranteed more than one transition. */
2785 out[0] = GEN_INT (64 - shift);
2786 out[1] = GEN_INT (m1);
2787 out[2] = GEN_INT (shift);
2788 out[3] = GEN_INT (m2);
2796 /* Return TRUE if OP is an invalid SUBREG operation on the e500. */
2799 invalid_e500_subreg (rtx op, enum machine_mode mode)
2801 if (TARGET_E500_DOUBLE)
2803 /* Reject (subreg:SI (reg:DF)); likewise with subreg:DI or
2804 subreg:TI and reg:TF. */
2805 if (GET_CODE (op) == SUBREG
2806 && (mode == SImode || mode == DImode || mode == TImode)
2807 && REG_P (SUBREG_REG (op))
2808 && (GET_MODE (SUBREG_REG (op)) == DFmode
2809 || GET_MODE (SUBREG_REG (op)) == TFmode))
2812 /* Reject (subreg:DF (reg:DI)); likewise with subreg:TF and
2814 if (GET_CODE (op) == SUBREG
2815 && (mode == DFmode || mode == TFmode)
2816 && REG_P (SUBREG_REG (op))
2817 && (GET_MODE (SUBREG_REG (op)) == DImode
2818 || GET_MODE (SUBREG_REG (op)) == TImode))
2823 && GET_CODE (op) == SUBREG
2825 && REG_P (SUBREG_REG (op))
2826 && SPE_VECTOR_MODE (GET_MODE (SUBREG_REG (op))))
2832 /* AIX increases natural record alignment to doubleword if the first
2833 field is an FP double while the FP fields remain word aligned. */
2836 rs6000_special_round_type_align (tree type, unsigned int computed,
2837 unsigned int specified)
2839 unsigned int align = MAX (computed, specified);
2840 tree field = TYPE_FIELDS (type);
2842 /* Skip all non field decls */
2843 while (field != NULL && TREE_CODE (field) != FIELD_DECL)
2844 field = TREE_CHAIN (field);
2846 if (field != NULL && field != type)
2848 type = TREE_TYPE (field);
2849 while (TREE_CODE (type) == ARRAY_TYPE)
2850 type = TREE_TYPE (type);
2852 if (type != error_mark_node && TYPE_MODE (type) == DFmode)
2853 align = MAX (align, 64);
2859 /* Darwin increases record alignment to the natural alignment of
2863 darwin_rs6000_special_round_type_align (tree type, unsigned int computed,
2864 unsigned int specified)
2866 unsigned int align = MAX (computed, specified);
2868 if (TYPE_PACKED (type))
2871 /* Find the first field, looking down into aggregates. */
2873 tree field = TYPE_FIELDS (type);
2874 /* Skip all non field decls */
2875 while (field != NULL && TREE_CODE (field) != FIELD_DECL)
2876 field = TREE_CHAIN (field);
2879 type = TREE_TYPE (field);
2880 while (TREE_CODE (type) == ARRAY_TYPE)
2881 type = TREE_TYPE (type);
2882 } while (AGGREGATE_TYPE_P (type));
2884 if (! AGGREGATE_TYPE_P (type) && type != error_mark_node)
2885 align = MAX (align, TYPE_ALIGN (type));
2890 /* Return 1 for an operand in small memory on V.4/eabi. */
2893 small_data_operand (rtx op ATTRIBUTE_UNUSED,
2894 enum machine_mode mode ATTRIBUTE_UNUSED)
2899 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
2902 if (DEFAULT_ABI != ABI_V4)
2905 if (GET_CODE (op) == SYMBOL_REF)
2908 else if (GET_CODE (op) != CONST
2909 || GET_CODE (XEXP (op, 0)) != PLUS
2910 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2911 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
2916 rtx sum = XEXP (op, 0);
2917 HOST_WIDE_INT summand;
2919 /* We have to be careful here, because it is the referenced address
2920 that must be 32k from _SDA_BASE_, not just the symbol. */
2921 summand = INTVAL (XEXP (sum, 1));
2922 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
2925 sym_ref = XEXP (sum, 0);
2928 return SYMBOL_REF_SMALL_P (sym_ref);
2934 /* Return true if either operand is a general purpose register. */
2937 gpr_or_gpr_p (rtx op0, rtx op1)
2939 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2940 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
2944 /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2947 constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
2949 switch (GET_CODE (op))
2952 if (RS6000_SYMBOL_REF_TLS_P (op))
2954 else if (CONSTANT_POOL_ADDRESS_P (op))
2956 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2964 else if (! strcmp (XSTR (op, 0), toc_label_name))
2973 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2974 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
2976 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
2985 constant_pool_expr_p (rtx op)
2989 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2993 toc_relative_expr_p (rtx op)
2997 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
3001 legitimate_constant_pool_address_p (rtx x)
3004 && GET_CODE (x) == PLUS
3005 && GET_CODE (XEXP (x, 0)) == REG
3006 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
3007 && constant_pool_expr_p (XEXP (x, 1)));
3011 legitimate_small_data_p (enum machine_mode mode, rtx x)
3013 return (DEFAULT_ABI == ABI_V4
3014 && !flag_pic && !TARGET_TOC
3015 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
3016 && small_data_operand (x, mode));
3019 /* SPE offset addressing is limited to 5-bits worth of double words. */
3020 #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
3023 rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
3025 unsigned HOST_WIDE_INT offset, extra;
3027 if (GET_CODE (x) != PLUS)
3029 if (GET_CODE (XEXP (x, 0)) != REG)
3031 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3033 if (legitimate_constant_pool_address_p (x))
3035 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3038 offset = INTVAL (XEXP (x, 1));
3046 /* AltiVec vector modes. Only reg+reg addressing is valid and
3047 constant offset zero should not occur due to canonicalization.
3048 Allow any offset when not strict before reload. */
3055 /* SPE vector modes. */
3056 return SPE_CONST_OFFSET_OK (offset);
3060 if (TARGET_E500_DOUBLE)
3061 return SPE_CONST_OFFSET_OK (offset);
3064 /* On e500v2, we may have:
3066 (subreg:DF (mem:DI (plus (reg) (const_int))) 0).
3068 Which gets addressed with evldd instructions. */
3069 if (TARGET_E500_DOUBLE)
3070 return SPE_CONST_OFFSET_OK (offset);
3072 if (mode == DFmode || mode == DDmode || !TARGET_POWERPC64)
3074 else if (offset & 3)
3079 if (TARGET_E500_DOUBLE)
3080 return (SPE_CONST_OFFSET_OK (offset)
3081 && SPE_CONST_OFFSET_OK (offset + 8));
3085 if (mode == TFmode || mode == TDmode || !TARGET_POWERPC64)
3087 else if (offset & 3)
3098 return (offset < 0x10000) && (offset + extra < 0x10000);
3102 legitimate_indexed_address_p (rtx x, int strict)
3106 if (GET_CODE (x) != PLUS)
3112 /* Recognize the rtl generated by reload which we know will later be
3113 replaced with proper base and index regs. */
3115 && reload_in_progress
3116 && (REG_P (op0) || GET_CODE (op0) == PLUS)
3120 return (REG_P (op0) && REG_P (op1)
3121 && ((INT_REG_OK_FOR_BASE_P (op0, strict)
3122 && INT_REG_OK_FOR_INDEX_P (op1, strict))
3123 || (INT_REG_OK_FOR_BASE_P (op1, strict)
3124 && INT_REG_OK_FOR_INDEX_P (op0, strict))));
3128 legitimate_indirect_address_p (rtx x, int strict)
3130 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
3134 macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
3136 if (!TARGET_MACHO || !flag_pic
3137 || mode != SImode || GET_CODE (x) != MEM)
3141 if (GET_CODE (x) != LO_SUM)
3143 if (GET_CODE (XEXP (x, 0)) != REG)
3145 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
3149 return CONSTANT_P (x);
3153 legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
3155 if (GET_CODE (x) != LO_SUM)
3157 if (GET_CODE (XEXP (x, 0)) != REG)
3159 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3161 /* Restrict addressing for DI because of our SUBREG hackery. */
3162 if (TARGET_E500_DOUBLE && (mode == DFmode || mode == TFmode
3167 if (TARGET_ELF || TARGET_MACHO)
3169 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
3173 if (GET_MODE_NUNITS (mode) != 1)
3175 if (GET_MODE_BITSIZE (mode) > 64
3176 || (GET_MODE_BITSIZE (mode) > 32 && !TARGET_POWERPC64
3177 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode)))
3180 return CONSTANT_P (x);
3187 /* Try machine-dependent ways of modifying an illegitimate address
3188 to be legitimate. If we find one, return the new, valid address.
3189 This is used from only one place: `memory_address' in explow.c.
3191 OLDX is the address as it was before break_out_memory_refs was
3192 called. In some cases it is useful to look at this to decide what
3195 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
3197 It is always safe for this function to do nothing. It exists to
3198 recognize opportunities to optimize the output.
3200 On RS/6000, first check for the sum of a register with a constant
3201 integer that is out of range. If so, generate code to add the
3202 constant with the low-order 16 bits masked to the register and force
3203 this result into another register (this can be done with `cau').
3204 Then generate an address of REG+(CONST&0xffff), allowing for the
3205 possibility of bit 16 being a one.
3207 Then check for the sum of a register and something not constant, try to
3208 load the other things into a register and return the sum. */
3211 rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3212 enum machine_mode mode)
3214 if (GET_CODE (x) == SYMBOL_REF)
3216 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
3218 return rs6000_legitimize_tls_address (x, model);
3221 if (GET_CODE (x) == PLUS
3222 && GET_CODE (XEXP (x, 0)) == REG
3223 && GET_CODE (XEXP (x, 1)) == CONST_INT
3224 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
3226 HOST_WIDE_INT high_int, low_int;
3228 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
3229 high_int = INTVAL (XEXP (x, 1)) - low_int;
3230 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
3231 GEN_INT (high_int)), 0);
3232 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
3234 else if (GET_CODE (x) == PLUS
3235 && GET_CODE (XEXP (x, 0)) == REG
3236 && GET_CODE (XEXP (x, 1)) != CONST_INT
3237 && GET_MODE_NUNITS (mode) == 1
3238 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3240 || (((mode != DImode && mode != DFmode && mode != DDmode)
3241 || TARGET_E500_DOUBLE)
3242 && mode != TFmode && mode != TDmode))
3243 && (TARGET_POWERPC64 || mode != DImode)
3246 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
3247 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
3249 else if (ALTIVEC_VECTOR_MODE (mode))
3253 /* Make sure both operands are registers. */
3254 if (GET_CODE (x) == PLUS)
3255 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
3256 force_reg (Pmode, XEXP (x, 1)));
3258 reg = force_reg (Pmode, x);
3261 else if (SPE_VECTOR_MODE (mode)
3262 || (TARGET_E500_DOUBLE && (mode == DFmode || mode == TFmode
3263 || mode == DDmode || mode == TDmode
3264 || mode == DImode)))
3268 /* We accept [reg + reg] and [reg + OFFSET]. */
3270 if (GET_CODE (x) == PLUS)
3272 rtx op1 = XEXP (x, 0);
3273 rtx op2 = XEXP (x, 1);
3275 op1 = force_reg (Pmode, op1);
3277 if (GET_CODE (op2) != REG
3278 && (GET_CODE (op2) != CONST_INT
3279 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
3280 op2 = force_reg (Pmode, op2);
3282 return gen_rtx_PLUS (Pmode, op1, op2);
3285 return force_reg (Pmode, x);
3291 && GET_CODE (x) != CONST_INT
3292 && GET_CODE (x) != CONST_DOUBLE
3294 && GET_MODE_NUNITS (mode) == 1
3295 && (GET_MODE_BITSIZE (mode) <= 32
3296 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
3298 rtx reg = gen_reg_rtx (Pmode);
3299 emit_insn (gen_elf_high (reg, x));
3300 return gen_rtx_LO_SUM (Pmode, reg, x);
3302 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
3305 && ! MACHO_DYNAMIC_NO_PIC_P
3307 && GET_CODE (x) != CONST_INT
3308 && GET_CODE (x) != CONST_DOUBLE
3310 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
3314 rtx reg = gen_reg_rtx (Pmode);
3315 emit_insn (gen_macho_high (reg, x));
3316 return gen_rtx_LO_SUM (Pmode, reg, x);
3319 && constant_pool_expr_p (x)
3320 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
3322 return create_TOC_reference (x);
3328 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
3329 We need to emit DTP-relative relocations. */
3332 rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
3337 fputs ("\t.long\t", file);
3340 fputs (DOUBLE_INT_ASM_OP, file);
3345 output_addr_const (file, x);
3346 fputs ("@dtprel+0x8000", file);
3349 /* Construct the SYMBOL_REF for the tls_get_addr function. */
3351 static GTY(()) rtx rs6000_tls_symbol;
3353 rs6000_tls_get_addr (void)
3355 if (!rs6000_tls_symbol)
3356 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
3358 return rs6000_tls_symbol;
3361 /* Construct the SYMBOL_REF for TLS GOT references. */
3363 static GTY(()) rtx rs6000_got_symbol;
3365 rs6000_got_sym (void)
3367 if (!rs6000_got_symbol)
3369 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3370 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
3371 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
3374 return rs6000_got_symbol;
3377 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3378 this (thread-local) address. */
3381 rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
3385 dest = gen_reg_rtx (Pmode);
3386 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
3392 tlsreg = gen_rtx_REG (Pmode, 13);
3393 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
3397 tlsreg = gen_rtx_REG (Pmode, 2);
3398 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
3402 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
3406 tmp = gen_reg_rtx (Pmode);
3409 tlsreg = gen_rtx_REG (Pmode, 13);
3410 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
3414 tlsreg = gen_rtx_REG (Pmode, 2);
3415 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
3419 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3421 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3426 rtx r3, got, tga, tmp1, tmp2, eqv;
3428 /* We currently use relocations like @got@tlsgd for tls, which
3429 means the linker will handle allocation of tls entries, placing
3430 them in the .got section. So use a pointer to the .got section,
3431 not one to secondary TOC sections used by 64-bit -mminimal-toc,
3432 or to secondary GOT sections used by 32-bit -fPIC. */
3434 got = gen_rtx_REG (Pmode, 2);
3438 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3441 rtx gsym = rs6000_got_sym ();
3442 got = gen_reg_rtx (Pmode);
3444 rs6000_emit_move (got, gsym, Pmode);
3450 tmp1 = gen_reg_rtx (Pmode);
3451 tmp2 = gen_reg_rtx (Pmode);
3452 tmp3 = gen_reg_rtx (Pmode);
3453 mem = gen_const_mem (Pmode, tmp1);
3455 first = emit_insn (gen_load_toc_v4_PIC_1b (gsym));
3456 emit_move_insn (tmp1,
3457 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
3458 emit_move_insn (tmp2, mem);