rs6000.c (struct rs6000_stack): Correct comments.
[official-gcc.git] / gcc / config / rs6000 / rs6000.c
blob92ebd82fadc0d9d2f9ae2569c33b0367d01335f1
1 /* Subroutines used for code generation on IBM RS/6000.
2 Copyright (C) 1991-2015 Free Software Foundation, Inc.
3 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-attr.h"
31 #include "flags.h"
32 #include "recog.h"
33 #include "obstack.h"
34 #include "hash-set.h"
35 #include "machmode.h"
36 #include "vec.h"
37 #include "double-int.h"
38 #include "input.h"
39 #include "alias.h"
40 #include "symtab.h"
41 #include "wide-int.h"
42 #include "inchash.h"
43 #include "tree.h"
44 #include "fold-const.h"
45 #include "stringpool.h"
46 #include "stor-layout.h"
47 #include "calls.h"
48 #include "print-tree.h"
49 #include "varasm.h"
50 #include "hashtab.h"
51 #include "function.h"
52 #include "statistics.h"
53 #include "real.h"
54 #include "fixed-value.h"
55 #include "expmed.h"
56 #include "dojump.h"
57 #include "explow.h"
58 #include "emit-rtl.h"
59 #include "stmt.h"
60 #include "expr.h"
61 #include "insn-codes.h"
62 #include "optabs.h"
63 #include "except.h"
64 #include "output.h"
65 #include "dbxout.h"
66 #include "predict.h"
67 #include "dominance.h"
68 #include "cfg.h"
69 #include "cfgrtl.h"
70 #include "cfganal.h"
71 #include "lcm.h"
72 #include "cfgbuild.h"
73 #include "cfgcleanup.h"
74 #include "basic-block.h"
75 #include "diagnostic-core.h"
76 #include "toplev.h"
77 #include "ggc.h"
78 #include "tm_p.h"
79 #include "target.h"
80 #include "target-def.h"
81 #include "common/common-target.h"
82 #include "langhooks.h"
83 #include "reload.h"
84 #include "cfgloop.h"
85 #include "sched-int.h"
86 #include "hash-table.h"
87 #include "tree-ssa-alias.h"
88 #include "internal-fn.h"
89 #include "gimple-fold.h"
90 #include "tree-eh.h"
91 #include "gimple-expr.h"
92 #include "is-a.h"
93 #include "gimple.h"
94 #include "gimplify.h"
95 #include "gimple-iterator.h"
96 #include "gimple-walk.h"
97 #include "intl.h"
98 #include "params.h"
99 #include "tm-constrs.h"
100 #include "ira.h"
101 #include "opts.h"
102 #include "tree-vectorizer.h"
103 #include "dumpfile.h"
104 #include "hash-map.h"
105 #include "plugin-api.h"
106 #include "ipa-ref.h"
107 #include "cgraph.h"
108 #include "target-globals.h"
109 #include "builtins.h"
110 #include "context.h"
111 #include "tree-pass.h"
112 #if TARGET_XCOFF
113 #include "xcoffout.h" /* get declarations of xcoff_*_section_name */
114 #endif
115 #if TARGET_MACHO
116 #include "gstab.h" /* for N_SLINE */
117 #endif
119 #ifndef TARGET_NO_PROTOTYPE
120 #define TARGET_NO_PROTOTYPE 0
121 #endif
123 #define min(A,B) ((A) < (B) ? (A) : (B))
124 #define max(A,B) ((A) > (B) ? (A) : (B))
126 /* Structure used to define the rs6000 stack */
127 typedef struct rs6000_stack {
128 int reload_completed; /* stack info won't change from here on */
129 int first_gp_reg_save; /* first callee saved GP register used */
130 int first_fp_reg_save; /* first callee saved FP register used */
131 int first_altivec_reg_save; /* first callee saved AltiVec register used */
132 int lr_save_p; /* true if the link reg needs to be saved */
133 int cr_save_p; /* true if the CR reg needs to be saved */
134 unsigned int vrsave_mask; /* mask of vec registers to save */
135 int push_p; /* true if we need to allocate stack space */
136 int calls_p; /* true if the function makes any calls */
137 int world_save_p; /* true if we're saving *everything*:
138 r13-r31, cr, f14-f31, vrsave, v20-v31 */
139 enum rs6000_abi abi; /* which ABI to use */
140 int gp_save_offset; /* offset to save GP regs from initial SP */
141 int fp_save_offset; /* offset to save FP regs from initial SP */
142 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
143 int lr_save_offset; /* offset to save LR from initial SP */
144 int cr_save_offset; /* offset to save CR from initial SP */
145 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
146 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
147 int varargs_save_offset; /* offset to save the varargs registers */
148 int ehrd_offset; /* offset to EH return data */
149 int ehcr_offset; /* offset to EH CR field data */
150 int reg_size; /* register size (4 or 8) */
151 HOST_WIDE_INT vars_size; /* variable save area size */
152 int parm_size; /* outgoing parameter size */
153 int save_size; /* save area size */
154 int fixed_size; /* fixed size of stack frame */
155 int gp_size; /* size of saved GP registers */
156 int fp_size; /* size of saved FP registers */
157 int altivec_size; /* size of saved AltiVec registers */
158 int cr_size; /* size to hold CR if not in fixed area */
159 int vrsave_size; /* size to hold VRSAVE */
160 int altivec_padding_size; /* size of altivec alignment padding */
161 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
162 int spe_padding_size;
163 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
164 int spe_64bit_regs_used;
165 int savres_strategy;
166 } rs6000_stack_t;
168 /* A C structure for machine-specific, per-function data.
169 This is added to the cfun structure. */
170 typedef struct GTY(()) machine_function
172 /* Whether the instruction chain has been scanned already. */
173 int insn_chain_scanned_p;
174 /* Flags if __builtin_return_address (n) with n >= 1 was used. */
175 int ra_needs_full_frame;
176 /* Flags if __builtin_return_address (0) was used. */
177 int ra_need_lr;
178 /* Cache lr_save_p after expansion of builtin_eh_return. */
179 int lr_save_state;
180 /* Whether we need to save the TOC to the reserved stack location in the
181 function prologue. */
182 bool save_toc_in_prologue;
183 /* Offset from virtual_stack_vars_rtx to the start of the ABI_V4
184 varargs save area. */
185 HOST_WIDE_INT varargs_save_offset;
186 /* Temporary stack slot to use for SDmode copies. This slot is
187 64-bits wide and is allocated early enough so that the offset
188 does not overflow the 16-bit load/store offset field. */
189 rtx sdmode_stack_slot;
190 /* Flag if r2 setup is needed with ELFv2 ABI. */
191 bool r2_setup_needed;
192 } machine_function;
194 /* Support targetm.vectorize.builtin_mask_for_load. */
195 static GTY(()) tree altivec_builtin_mask_for_load;
197 /* Set to nonzero once AIX common-mode calls have been defined. */
198 static GTY(()) int common_mode_defined;
200 /* Label number of label created for -mrelocatable, to call to so we can
201 get the address of the GOT section */
202 static int rs6000_pic_labelno;
204 #ifdef USING_ELFOS_H
205 /* Counter for labels which are to be placed in .fixup. */
206 int fixuplabelno = 0;
207 #endif
209 /* Whether to use variant of AIX ABI for PowerPC64 Linux. */
210 int dot_symbols;
212 /* Specify the machine mode that pointers have. After generation of rtl, the
213 compiler makes no further distinction between pointers and any other objects
214 of this machine mode. The type is unsigned since not all things that
215 include rs6000.h also include machmode.h. */
216 unsigned rs6000_pmode;
218 /* Width in bits of a pointer. */
219 unsigned rs6000_pointer_size;
221 #ifdef HAVE_AS_GNU_ATTRIBUTE
222 /* Flag whether floating point values have been passed/returned. */
223 static bool rs6000_passes_float;
224 /* Flag whether vector values have been passed/returned. */
225 static bool rs6000_passes_vector;
226 /* Flag whether small (<= 8 byte) structures have been returned. */
227 static bool rs6000_returns_struct;
228 #endif
230 /* Value is TRUE if register/mode pair is acceptable. */
231 bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
233 /* Maximum number of registers needed for a given register class and mode. */
234 unsigned char rs6000_class_max_nregs[NUM_MACHINE_MODES][LIM_REG_CLASSES];
236 /* How many registers are needed for a given register and mode. */
237 unsigned char rs6000_hard_regno_nregs[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
239 /* Map register number to register class. */
240 enum reg_class rs6000_regno_regclass[FIRST_PSEUDO_REGISTER];
242 static int dbg_cost_ctrl;
244 /* Built in types. */
245 tree rs6000_builtin_types[RS6000_BTI_MAX];
246 tree rs6000_builtin_decls[RS6000_BUILTIN_COUNT];
248 /* Flag to say the TOC is initialized */
249 int toc_initialized;
250 char toc_label_name[10];
252 /* Cached value of rs6000_variable_issue. This is cached in
253 rs6000_variable_issue hook and returned from rs6000_sched_reorder2. */
254 static short cached_can_issue_more;
256 static GTY(()) section *read_only_data_section;
257 static GTY(()) section *private_data_section;
258 static GTY(()) section *tls_data_section;
259 static GTY(()) section *tls_private_data_section;
260 static GTY(()) section *read_only_private_data_section;
261 static GTY(()) section *sdata2_section;
262 static GTY(()) section *toc_section;
264 struct builtin_description
266 const HOST_WIDE_INT mask;
267 const enum insn_code icode;
268 const char *const name;
269 const enum rs6000_builtins code;
272 /* Describe the vector unit used for modes. */
273 enum rs6000_vector rs6000_vector_unit[NUM_MACHINE_MODES];
274 enum rs6000_vector rs6000_vector_mem[NUM_MACHINE_MODES];
276 /* Register classes for various constraints that are based on the target
277 switches. */
278 enum reg_class rs6000_constraints[RS6000_CONSTRAINT_MAX];
280 /* Describe the alignment of a vector. */
281 int rs6000_vector_align[NUM_MACHINE_MODES];
283 /* Map selected modes to types for builtins. */
284 static GTY(()) tree builtin_mode_to_type[MAX_MACHINE_MODE][2];
286 /* What modes to automatically generate reciprocal divide estimate (fre) and
287 reciprocal sqrt (frsqrte) for. */
288 unsigned char rs6000_recip_bits[MAX_MACHINE_MODE];
290 /* Masks to determine which reciprocal esitmate instructions to generate
291 automatically. */
292 enum rs6000_recip_mask {
293 RECIP_SF_DIV = 0x001, /* Use divide estimate */
294 RECIP_DF_DIV = 0x002,
295 RECIP_V4SF_DIV = 0x004,
296 RECIP_V2DF_DIV = 0x008,
298 RECIP_SF_RSQRT = 0x010, /* Use reciprocal sqrt estimate. */
299 RECIP_DF_RSQRT = 0x020,
300 RECIP_V4SF_RSQRT = 0x040,
301 RECIP_V2DF_RSQRT = 0x080,
303 /* Various combination of flags for -mrecip=xxx. */
304 RECIP_NONE = 0,
305 RECIP_ALL = (RECIP_SF_DIV | RECIP_DF_DIV | RECIP_V4SF_DIV
306 | RECIP_V2DF_DIV | RECIP_SF_RSQRT | RECIP_DF_RSQRT
307 | RECIP_V4SF_RSQRT | RECIP_V2DF_RSQRT),
309 RECIP_HIGH_PRECISION = RECIP_ALL,
311 /* On low precision machines like the power5, don't enable double precision
312 reciprocal square root estimate, since it isn't accurate enough. */
313 RECIP_LOW_PRECISION = (RECIP_ALL & ~(RECIP_DF_RSQRT | RECIP_V2DF_RSQRT))
316 /* -mrecip options. */
317 static struct
319 const char *string; /* option name */
320 unsigned int mask; /* mask bits to set */
321 } recip_options[] = {
322 { "all", RECIP_ALL },
323 { "none", RECIP_NONE },
324 { "div", (RECIP_SF_DIV | RECIP_DF_DIV | RECIP_V4SF_DIV
325 | RECIP_V2DF_DIV) },
326 { "divf", (RECIP_SF_DIV | RECIP_V4SF_DIV) },
327 { "divd", (RECIP_DF_DIV | RECIP_V2DF_DIV) },
328 { "rsqrt", (RECIP_SF_RSQRT | RECIP_DF_RSQRT | RECIP_V4SF_RSQRT
329 | RECIP_V2DF_RSQRT) },
330 { "rsqrtf", (RECIP_SF_RSQRT | RECIP_V4SF_RSQRT) },
331 { "rsqrtd", (RECIP_DF_RSQRT | RECIP_V2DF_RSQRT) },
334 /* Pointer to function (in rs6000-c.c) that can define or undefine target
335 macros that have changed. Languages that don't support the preprocessor
336 don't link in rs6000-c.c, so we can't call it directly. */
337 void (*rs6000_target_modify_macros_ptr) (bool, HOST_WIDE_INT, HOST_WIDE_INT);
339 /* Simplfy register classes into simpler classifications. We assume
340 GPR_REG_TYPE - FPR_REG_TYPE are ordered so that we can use a simple range
341 check for standard register classes (gpr/floating/altivec/vsx) and
342 floating/vector classes (float/altivec/vsx). */
344 enum rs6000_reg_type {
345 NO_REG_TYPE,
346 PSEUDO_REG_TYPE,
347 GPR_REG_TYPE,
348 VSX_REG_TYPE,
349 ALTIVEC_REG_TYPE,
350 FPR_REG_TYPE,
351 SPR_REG_TYPE,
352 CR_REG_TYPE,
353 SPE_ACC_TYPE,
354 SPEFSCR_REG_TYPE
357 /* Map register class to register type. */
358 static enum rs6000_reg_type reg_class_to_reg_type[N_REG_CLASSES];
360 /* First/last register type for the 'normal' register types (i.e. general
361 purpose, floating point, altivec, and VSX registers). */
362 #define IS_STD_REG_TYPE(RTYPE) IN_RANGE(RTYPE, GPR_REG_TYPE, FPR_REG_TYPE)
364 #define IS_FP_VECT_REG_TYPE(RTYPE) IN_RANGE(RTYPE, VSX_REG_TYPE, FPR_REG_TYPE)
367 /* Register classes we care about in secondary reload or go if legitimate
368 address. We only need to worry about GPR, FPR, and Altivec registers here,
369 along an ANY field that is the OR of the 3 register classes. */
371 enum rs6000_reload_reg_type {
372 RELOAD_REG_GPR, /* General purpose registers. */
373 RELOAD_REG_FPR, /* Traditional floating point regs. */
374 RELOAD_REG_VMX, /* Altivec (VMX) registers. */
375 RELOAD_REG_ANY, /* OR of GPR, FPR, Altivec masks. */
376 N_RELOAD_REG
379 /* For setting up register classes, loop through the 3 register classes mapping
380 into real registers, and skip the ANY class, which is just an OR of the
381 bits. */
382 #define FIRST_RELOAD_REG_CLASS RELOAD_REG_GPR
383 #define LAST_RELOAD_REG_CLASS RELOAD_REG_VMX
385 /* Map reload register type to a register in the register class. */
386 struct reload_reg_map_type {
387 const char *name; /* Register class name. */
388 int reg; /* Register in the register class. */
391 static const struct reload_reg_map_type reload_reg_map[N_RELOAD_REG] = {
392 { "Gpr", FIRST_GPR_REGNO }, /* RELOAD_REG_GPR. */
393 { "Fpr", FIRST_FPR_REGNO }, /* RELOAD_REG_FPR. */
394 { "VMX", FIRST_ALTIVEC_REGNO }, /* RELOAD_REG_VMX. */
395 { "Any", -1 }, /* RELOAD_REG_ANY. */
398 /* Mask bits for each register class, indexed per mode. Historically the
399 compiler has been more restrictive which types can do PRE_MODIFY instead of
400 PRE_INC and PRE_DEC, so keep track of sepaate bits for these two. */
401 typedef unsigned char addr_mask_type;
403 #define RELOAD_REG_VALID 0x01 /* Mode valid in register.. */
404 #define RELOAD_REG_MULTIPLE 0x02 /* Mode takes multiple registers. */
405 #define RELOAD_REG_INDEXED 0x04 /* Reg+reg addressing. */
406 #define RELOAD_REG_OFFSET 0x08 /* Reg+offset addressing. */
407 #define RELOAD_REG_PRE_INCDEC 0x10 /* PRE_INC/PRE_DEC valid. */
408 #define RELOAD_REG_PRE_MODIFY 0x20 /* PRE_MODIFY valid. */
409 #define RELOAD_REG_AND_M16 0x40 /* AND -16 addressing. */
411 /* Register type masks based on the type, of valid addressing modes. */
412 struct rs6000_reg_addr {
413 enum insn_code reload_load; /* INSN to reload for loading. */
414 enum insn_code reload_store; /* INSN to reload for storing. */
415 enum insn_code reload_fpr_gpr; /* INSN to move from FPR to GPR. */
416 enum insn_code reload_gpr_vsx; /* INSN to move from GPR to VSX. */
417 enum insn_code reload_vsx_gpr; /* INSN to move from VSX to GPR. */
418 addr_mask_type addr_mask[(int)N_RELOAD_REG]; /* Valid address masks. */
419 bool scalar_in_vmx_p; /* Scalar value can go in VMX. */
422 static struct rs6000_reg_addr reg_addr[NUM_MACHINE_MODES];
424 /* Helper function to say whether a mode supports PRE_INC or PRE_DEC. */
425 static inline bool
426 mode_supports_pre_incdec_p (machine_mode mode)
428 return ((reg_addr[mode].addr_mask[RELOAD_REG_ANY] & RELOAD_REG_PRE_INCDEC)
429 != 0);
432 /* Helper function to say whether a mode supports PRE_MODIFY. */
433 static inline bool
434 mode_supports_pre_modify_p (machine_mode mode)
436 return ((reg_addr[mode].addr_mask[RELOAD_REG_ANY] & RELOAD_REG_PRE_MODIFY)
437 != 0);
441 /* Target cpu costs. */
443 struct processor_costs {
444 const int mulsi; /* cost of SImode multiplication. */
445 const int mulsi_const; /* cost of SImode multiplication by constant. */
446 const int mulsi_const9; /* cost of SImode mult by short constant. */
447 const int muldi; /* cost of DImode multiplication. */
448 const int divsi; /* cost of SImode division. */
449 const int divdi; /* cost of DImode division. */
450 const int fp; /* cost of simple SFmode and DFmode insns. */
451 const int dmul; /* cost of DFmode multiplication (and fmadd). */
452 const int sdiv; /* cost of SFmode division (fdivs). */
453 const int ddiv; /* cost of DFmode division (fdiv). */
454 const int cache_line_size; /* cache line size in bytes. */
455 const int l1_cache_size; /* size of l1 cache, in kilobytes. */
456 const int l2_cache_size; /* size of l2 cache, in kilobytes. */
457 const int simultaneous_prefetches; /* number of parallel prefetch
458 operations. */
459 const int sfdf_convert; /* cost of SF->DF conversion. */
462 const struct processor_costs *rs6000_cost;
464 /* Processor costs (relative to an add) */
466 /* Instruction size costs on 32bit processors. */
467 static const
468 struct processor_costs size32_cost = {
469 COSTS_N_INSNS (1), /* mulsi */
470 COSTS_N_INSNS (1), /* mulsi_const */
471 COSTS_N_INSNS (1), /* mulsi_const9 */
472 COSTS_N_INSNS (1), /* muldi */
473 COSTS_N_INSNS (1), /* divsi */
474 COSTS_N_INSNS (1), /* divdi */
475 COSTS_N_INSNS (1), /* fp */
476 COSTS_N_INSNS (1), /* dmul */
477 COSTS_N_INSNS (1), /* sdiv */
478 COSTS_N_INSNS (1), /* ddiv */
479 32, /* cache line size */
480 0, /* l1 cache */
481 0, /* l2 cache */
482 0, /* streams */
483 0, /* SF->DF convert */
486 /* Instruction size costs on 64bit processors. */
487 static const
488 struct processor_costs size64_cost = {
489 COSTS_N_INSNS (1), /* mulsi */
490 COSTS_N_INSNS (1), /* mulsi_const */
491 COSTS_N_INSNS (1), /* mulsi_const9 */
492 COSTS_N_INSNS (1), /* muldi */
493 COSTS_N_INSNS (1), /* divsi */
494 COSTS_N_INSNS (1), /* divdi */
495 COSTS_N_INSNS (1), /* fp */
496 COSTS_N_INSNS (1), /* dmul */
497 COSTS_N_INSNS (1), /* sdiv */
498 COSTS_N_INSNS (1), /* ddiv */
499 128, /* cache line size */
500 0, /* l1 cache */
501 0, /* l2 cache */
502 0, /* streams */
503 0, /* SF->DF convert */
506 /* Instruction costs on RS64A processors. */
507 static const
508 struct processor_costs rs64a_cost = {
509 COSTS_N_INSNS (20), /* mulsi */
510 COSTS_N_INSNS (12), /* mulsi_const */
511 COSTS_N_INSNS (8), /* mulsi_const9 */
512 COSTS_N_INSNS (34), /* muldi */
513 COSTS_N_INSNS (65), /* divsi */
514 COSTS_N_INSNS (67), /* divdi */
515 COSTS_N_INSNS (4), /* fp */
516 COSTS_N_INSNS (4), /* dmul */
517 COSTS_N_INSNS (31), /* sdiv */
518 COSTS_N_INSNS (31), /* ddiv */
519 128, /* cache line size */
520 128, /* l1 cache */
521 2048, /* l2 cache */
522 1, /* streams */
523 0, /* SF->DF convert */
526 /* Instruction costs on MPCCORE processors. */
527 static const
528 struct processor_costs mpccore_cost = {
529 COSTS_N_INSNS (2), /* mulsi */
530 COSTS_N_INSNS (2), /* mulsi_const */
531 COSTS_N_INSNS (2), /* mulsi_const9 */
532 COSTS_N_INSNS (2), /* muldi */
533 COSTS_N_INSNS (6), /* divsi */
534 COSTS_N_INSNS (6), /* divdi */
535 COSTS_N_INSNS (4), /* fp */
536 COSTS_N_INSNS (5), /* dmul */
537 COSTS_N_INSNS (10), /* sdiv */
538 COSTS_N_INSNS (17), /* ddiv */
539 32, /* cache line size */
540 4, /* l1 cache */
541 16, /* l2 cache */
542 1, /* streams */
543 0, /* SF->DF convert */
546 /* Instruction costs on PPC403 processors. */
547 static const
548 struct processor_costs ppc403_cost = {
549 COSTS_N_INSNS (4), /* mulsi */
550 COSTS_N_INSNS (4), /* mulsi_const */
551 COSTS_N_INSNS (4), /* mulsi_const9 */
552 COSTS_N_INSNS (4), /* muldi */
553 COSTS_N_INSNS (33), /* divsi */
554 COSTS_N_INSNS (33), /* divdi */
555 COSTS_N_INSNS (11), /* fp */
556 COSTS_N_INSNS (11), /* dmul */
557 COSTS_N_INSNS (11), /* sdiv */
558 COSTS_N_INSNS (11), /* ddiv */
559 32, /* cache line size */
560 4, /* l1 cache */
561 16, /* l2 cache */
562 1, /* streams */
563 0, /* SF->DF convert */
566 /* Instruction costs on PPC405 processors. */
567 static const
568 struct processor_costs ppc405_cost = {
569 COSTS_N_INSNS (5), /* mulsi */
570 COSTS_N_INSNS (4), /* mulsi_const */
571 COSTS_N_INSNS (3), /* mulsi_const9 */
572 COSTS_N_INSNS (5), /* muldi */
573 COSTS_N_INSNS (35), /* divsi */
574 COSTS_N_INSNS (35), /* divdi */
575 COSTS_N_INSNS (11), /* fp */
576 COSTS_N_INSNS (11), /* dmul */
577 COSTS_N_INSNS (11), /* sdiv */
578 COSTS_N_INSNS (11), /* ddiv */
579 32, /* cache line size */
580 16, /* l1 cache */
581 128, /* l2 cache */
582 1, /* streams */
583 0, /* SF->DF convert */
586 /* Instruction costs on PPC440 processors. */
587 static const
588 struct processor_costs ppc440_cost = {
589 COSTS_N_INSNS (3), /* mulsi */
590 COSTS_N_INSNS (2), /* mulsi_const */
591 COSTS_N_INSNS (2), /* mulsi_const9 */
592 COSTS_N_INSNS (3), /* muldi */
593 COSTS_N_INSNS (34), /* divsi */
594 COSTS_N_INSNS (34), /* divdi */
595 COSTS_N_INSNS (5), /* fp */
596 COSTS_N_INSNS (5), /* dmul */
597 COSTS_N_INSNS (19), /* sdiv */
598 COSTS_N_INSNS (33), /* ddiv */
599 32, /* cache line size */
600 32, /* l1 cache */
601 256, /* l2 cache */
602 1, /* streams */
603 0, /* SF->DF convert */
606 /* Instruction costs on PPC476 processors. */
607 static const
608 struct processor_costs ppc476_cost = {
609 COSTS_N_INSNS (4), /* mulsi */
610 COSTS_N_INSNS (4), /* mulsi_const */
611 COSTS_N_INSNS (4), /* mulsi_const9 */
612 COSTS_N_INSNS (4), /* muldi */
613 COSTS_N_INSNS (11), /* divsi */
614 COSTS_N_INSNS (11), /* divdi */
615 COSTS_N_INSNS (6), /* fp */
616 COSTS_N_INSNS (6), /* dmul */
617 COSTS_N_INSNS (19), /* sdiv */
618 COSTS_N_INSNS (33), /* ddiv */
619 32, /* l1 cache line size */
620 32, /* l1 cache */
621 512, /* l2 cache */
622 1, /* streams */
623 0, /* SF->DF convert */
626 /* Instruction costs on PPC601 processors. */
627 static const
628 struct processor_costs ppc601_cost = {
629 COSTS_N_INSNS (5), /* mulsi */
630 COSTS_N_INSNS (5), /* mulsi_const */
631 COSTS_N_INSNS (5), /* mulsi_const9 */
632 COSTS_N_INSNS (5), /* muldi */
633 COSTS_N_INSNS (36), /* divsi */
634 COSTS_N_INSNS (36), /* divdi */
635 COSTS_N_INSNS (4), /* fp */
636 COSTS_N_INSNS (5), /* dmul */
637 COSTS_N_INSNS (17), /* sdiv */
638 COSTS_N_INSNS (31), /* ddiv */
639 32, /* cache line size */
640 32, /* l1 cache */
641 256, /* l2 cache */
642 1, /* streams */
643 0, /* SF->DF convert */
646 /* Instruction costs on PPC603 processors. */
647 static const
648 struct processor_costs ppc603_cost = {
649 COSTS_N_INSNS (5), /* mulsi */
650 COSTS_N_INSNS (3), /* mulsi_const */
651 COSTS_N_INSNS (2), /* mulsi_const9 */
652 COSTS_N_INSNS (5), /* muldi */
653 COSTS_N_INSNS (37), /* divsi */
654 COSTS_N_INSNS (37), /* divdi */
655 COSTS_N_INSNS (3), /* fp */
656 COSTS_N_INSNS (4), /* dmul */
657 COSTS_N_INSNS (18), /* sdiv */
658 COSTS_N_INSNS (33), /* ddiv */
659 32, /* cache line size */
660 8, /* l1 cache */
661 64, /* l2 cache */
662 1, /* streams */
663 0, /* SF->DF convert */
666 /* Instruction costs on PPC604 processors. */
667 static const
668 struct processor_costs ppc604_cost = {
669 COSTS_N_INSNS (4), /* mulsi */
670 COSTS_N_INSNS (4), /* mulsi_const */
671 COSTS_N_INSNS (4), /* mulsi_const9 */
672 COSTS_N_INSNS (4), /* muldi */
673 COSTS_N_INSNS (20), /* divsi */
674 COSTS_N_INSNS (20), /* divdi */
675 COSTS_N_INSNS (3), /* fp */
676 COSTS_N_INSNS (3), /* dmul */
677 COSTS_N_INSNS (18), /* sdiv */
678 COSTS_N_INSNS (32), /* ddiv */
679 32, /* cache line size */
680 16, /* l1 cache */
681 512, /* l2 cache */
682 1, /* streams */
683 0, /* SF->DF convert */
686 /* Instruction costs on PPC604e processors. */
687 static const
688 struct processor_costs ppc604e_cost = {
689 COSTS_N_INSNS (2), /* mulsi */
690 COSTS_N_INSNS (2), /* mulsi_const */
691 COSTS_N_INSNS (2), /* mulsi_const9 */
692 COSTS_N_INSNS (2), /* muldi */
693 COSTS_N_INSNS (20), /* divsi */
694 COSTS_N_INSNS (20), /* divdi */
695 COSTS_N_INSNS (3), /* fp */
696 COSTS_N_INSNS (3), /* dmul */
697 COSTS_N_INSNS (18), /* sdiv */
698 COSTS_N_INSNS (32), /* ddiv */
699 32, /* cache line size */
700 32, /* l1 cache */
701 1024, /* l2 cache */
702 1, /* streams */
703 0, /* SF->DF convert */
706 /* Instruction costs on PPC620 processors. */
707 static const
708 struct processor_costs ppc620_cost = {
709 COSTS_N_INSNS (5), /* mulsi */
710 COSTS_N_INSNS (4), /* mulsi_const */
711 COSTS_N_INSNS (3), /* mulsi_const9 */
712 COSTS_N_INSNS (7), /* muldi */
713 COSTS_N_INSNS (21), /* divsi */
714 COSTS_N_INSNS (37), /* divdi */
715 COSTS_N_INSNS (3), /* fp */
716 COSTS_N_INSNS (3), /* dmul */
717 COSTS_N_INSNS (18), /* sdiv */
718 COSTS_N_INSNS (32), /* ddiv */
719 128, /* cache line size */
720 32, /* l1 cache */
721 1024, /* l2 cache */
722 1, /* streams */
723 0, /* SF->DF convert */
726 /* Instruction costs on PPC630 processors. */
727 static const
728 struct processor_costs ppc630_cost = {
729 COSTS_N_INSNS (5), /* mulsi */
730 COSTS_N_INSNS (4), /* mulsi_const */
731 COSTS_N_INSNS (3), /* mulsi_const9 */
732 COSTS_N_INSNS (7), /* muldi */
733 COSTS_N_INSNS (21), /* divsi */
734 COSTS_N_INSNS (37), /* divdi */
735 COSTS_N_INSNS (3), /* fp */
736 COSTS_N_INSNS (3), /* dmul */
737 COSTS_N_INSNS (17), /* sdiv */
738 COSTS_N_INSNS (21), /* ddiv */
739 128, /* cache line size */
740 64, /* l1 cache */
741 1024, /* l2 cache */
742 1, /* streams */
743 0, /* SF->DF convert */
746 /* Instruction costs on Cell processor. */
747 /* COSTS_N_INSNS (1) ~ one add. */
748 static const
749 struct processor_costs ppccell_cost = {
750 COSTS_N_INSNS (9/2)+2, /* mulsi */
751 COSTS_N_INSNS (6/2), /* mulsi_const */
752 COSTS_N_INSNS (6/2), /* mulsi_const9 */
753 COSTS_N_INSNS (15/2)+2, /* muldi */
754 COSTS_N_INSNS (38/2), /* divsi */
755 COSTS_N_INSNS (70/2), /* divdi */
756 COSTS_N_INSNS (10/2), /* fp */
757 COSTS_N_INSNS (10/2), /* dmul */
758 COSTS_N_INSNS (74/2), /* sdiv */
759 COSTS_N_INSNS (74/2), /* ddiv */
760 128, /* cache line size */
761 32, /* l1 cache */
762 512, /* l2 cache */
763 6, /* streams */
764 0, /* SF->DF convert */
767 /* Instruction costs on PPC750 and PPC7400 processors. */
768 static const
769 struct processor_costs ppc750_cost = {
770 COSTS_N_INSNS (5), /* mulsi */
771 COSTS_N_INSNS (3), /* mulsi_const */
772 COSTS_N_INSNS (2), /* mulsi_const9 */
773 COSTS_N_INSNS (5), /* muldi */
774 COSTS_N_INSNS (17), /* divsi */
775 COSTS_N_INSNS (17), /* divdi */
776 COSTS_N_INSNS (3), /* fp */
777 COSTS_N_INSNS (3), /* dmul */
778 COSTS_N_INSNS (17), /* sdiv */
779 COSTS_N_INSNS (31), /* ddiv */
780 32, /* cache line size */
781 32, /* l1 cache */
782 512, /* l2 cache */
783 1, /* streams */
784 0, /* SF->DF convert */
787 /* Instruction costs on PPC7450 processors. */
788 static const
789 struct processor_costs ppc7450_cost = {
790 COSTS_N_INSNS (4), /* mulsi */
791 COSTS_N_INSNS (3), /* mulsi_const */
792 COSTS_N_INSNS (3), /* mulsi_const9 */
793 COSTS_N_INSNS (4), /* muldi */
794 COSTS_N_INSNS (23), /* divsi */
795 COSTS_N_INSNS (23), /* divdi */
796 COSTS_N_INSNS (5), /* fp */
797 COSTS_N_INSNS (5), /* dmul */
798 COSTS_N_INSNS (21), /* sdiv */
799 COSTS_N_INSNS (35), /* ddiv */
800 32, /* cache line size */
801 32, /* l1 cache */
802 1024, /* l2 cache */
803 1, /* streams */
804 0, /* SF->DF convert */
807 /* Instruction costs on PPC8540 processors. */
808 static const
809 struct processor_costs ppc8540_cost = {
810 COSTS_N_INSNS (4), /* mulsi */
811 COSTS_N_INSNS (4), /* mulsi_const */
812 COSTS_N_INSNS (4), /* mulsi_const9 */
813 COSTS_N_INSNS (4), /* muldi */
814 COSTS_N_INSNS (19), /* divsi */
815 COSTS_N_INSNS (19), /* divdi */
816 COSTS_N_INSNS (4), /* fp */
817 COSTS_N_INSNS (4), /* dmul */
818 COSTS_N_INSNS (29), /* sdiv */
819 COSTS_N_INSNS (29), /* ddiv */
820 32, /* cache line size */
821 32, /* l1 cache */
822 256, /* l2 cache */
823 1, /* prefetch streams /*/
824 0, /* SF->DF convert */
827 /* Instruction costs on E300C2 and E300C3 cores. */
828 static const
829 struct processor_costs ppce300c2c3_cost = {
830 COSTS_N_INSNS (4), /* mulsi */
831 COSTS_N_INSNS (4), /* mulsi_const */
832 COSTS_N_INSNS (4), /* mulsi_const9 */
833 COSTS_N_INSNS (4), /* muldi */
834 COSTS_N_INSNS (19), /* divsi */
835 COSTS_N_INSNS (19), /* divdi */
836 COSTS_N_INSNS (3), /* fp */
837 COSTS_N_INSNS (4), /* dmul */
838 COSTS_N_INSNS (18), /* sdiv */
839 COSTS_N_INSNS (33), /* ddiv */
841 16, /* l1 cache */
842 16, /* l2 cache */
843 1, /* prefetch streams /*/
844 0, /* SF->DF convert */
847 /* Instruction costs on PPCE500MC processors. */
848 static const
849 struct processor_costs ppce500mc_cost = {
850 COSTS_N_INSNS (4), /* mulsi */
851 COSTS_N_INSNS (4), /* mulsi_const */
852 COSTS_N_INSNS (4), /* mulsi_const9 */
853 COSTS_N_INSNS (4), /* muldi */
854 COSTS_N_INSNS (14), /* divsi */
855 COSTS_N_INSNS (14), /* divdi */
856 COSTS_N_INSNS (8), /* fp */
857 COSTS_N_INSNS (10), /* dmul */
858 COSTS_N_INSNS (36), /* sdiv */
859 COSTS_N_INSNS (66), /* ddiv */
860 64, /* cache line size */
861 32, /* l1 cache */
862 128, /* l2 cache */
863 1, /* prefetch streams /*/
864 0, /* SF->DF convert */
867 /* Instruction costs on PPCE500MC64 processors. */
868 static const
869 struct processor_costs ppce500mc64_cost = {
870 COSTS_N_INSNS (4), /* mulsi */
871 COSTS_N_INSNS (4), /* mulsi_const */
872 COSTS_N_INSNS (4), /* mulsi_const9 */
873 COSTS_N_INSNS (4), /* muldi */
874 COSTS_N_INSNS (14), /* divsi */
875 COSTS_N_INSNS (14), /* divdi */
876 COSTS_N_INSNS (4), /* fp */
877 COSTS_N_INSNS (10), /* dmul */
878 COSTS_N_INSNS (36), /* sdiv */
879 COSTS_N_INSNS (66), /* ddiv */
880 64, /* cache line size */
881 32, /* l1 cache */
882 128, /* l2 cache */
883 1, /* prefetch streams /*/
884 0, /* SF->DF convert */
887 /* Instruction costs on PPCE5500 processors. */
888 static const
889 struct processor_costs ppce5500_cost = {
890 COSTS_N_INSNS (5), /* mulsi */
891 COSTS_N_INSNS (5), /* mulsi_const */
892 COSTS_N_INSNS (4), /* mulsi_const9 */
893 COSTS_N_INSNS (5), /* muldi */
894 COSTS_N_INSNS (14), /* divsi */
895 COSTS_N_INSNS (14), /* divdi */
896 COSTS_N_INSNS (7), /* fp */
897 COSTS_N_INSNS (10), /* dmul */
898 COSTS_N_INSNS (36), /* sdiv */
899 COSTS_N_INSNS (66), /* ddiv */
900 64, /* cache line size */
901 32, /* l1 cache */
902 128, /* l2 cache */
903 1, /* prefetch streams /*/
904 0, /* SF->DF convert */
907 /* Instruction costs on PPCE6500 processors. */
908 static const
909 struct processor_costs ppce6500_cost = {
910 COSTS_N_INSNS (5), /* mulsi */
911 COSTS_N_INSNS (5), /* mulsi_const */
912 COSTS_N_INSNS (4), /* mulsi_const9 */
913 COSTS_N_INSNS (5), /* muldi */
914 COSTS_N_INSNS (14), /* divsi */
915 COSTS_N_INSNS (14), /* divdi */
916 COSTS_N_INSNS (7), /* fp */
917 COSTS_N_INSNS (10), /* dmul */
918 COSTS_N_INSNS (36), /* sdiv */
919 COSTS_N_INSNS (66), /* ddiv */
920 64, /* cache line size */
921 32, /* l1 cache */
922 128, /* l2 cache */
923 1, /* prefetch streams /*/
924 0, /* SF->DF convert */
927 /* Instruction costs on AppliedMicro Titan processors. */
928 static const
929 struct processor_costs titan_cost = {
930 COSTS_N_INSNS (5), /* mulsi */
931 COSTS_N_INSNS (5), /* mulsi_const */
932 COSTS_N_INSNS (5), /* mulsi_const9 */
933 COSTS_N_INSNS (5), /* muldi */
934 COSTS_N_INSNS (18), /* divsi */
935 COSTS_N_INSNS (18), /* divdi */
936 COSTS_N_INSNS (10), /* fp */
937 COSTS_N_INSNS (10), /* dmul */
938 COSTS_N_INSNS (46), /* sdiv */
939 COSTS_N_INSNS (72), /* ddiv */
940 32, /* cache line size */
941 32, /* l1 cache */
942 512, /* l2 cache */
943 1, /* prefetch streams /*/
944 0, /* SF->DF convert */
947 /* Instruction costs on POWER4 and POWER5 processors. */
948 static const
949 struct processor_costs power4_cost = {
950 COSTS_N_INSNS (3), /* mulsi */
951 COSTS_N_INSNS (2), /* mulsi_const */
952 COSTS_N_INSNS (2), /* mulsi_const9 */
953 COSTS_N_INSNS (4), /* muldi */
954 COSTS_N_INSNS (18), /* divsi */
955 COSTS_N_INSNS (34), /* divdi */
956 COSTS_N_INSNS (3), /* fp */
957 COSTS_N_INSNS (3), /* dmul */
958 COSTS_N_INSNS (17), /* sdiv */
959 COSTS_N_INSNS (17), /* ddiv */
960 128, /* cache line size */
961 32, /* l1 cache */
962 1024, /* l2 cache */
963 8, /* prefetch streams /*/
964 0, /* SF->DF convert */
967 /* Instruction costs on POWER6 processors. */
968 static const
969 struct processor_costs power6_cost = {
970 COSTS_N_INSNS (8), /* mulsi */
971 COSTS_N_INSNS (8), /* mulsi_const */
972 COSTS_N_INSNS (8), /* mulsi_const9 */
973 COSTS_N_INSNS (8), /* muldi */
974 COSTS_N_INSNS (22), /* divsi */
975 COSTS_N_INSNS (28), /* divdi */
976 COSTS_N_INSNS (3), /* fp */
977 COSTS_N_INSNS (3), /* dmul */
978 COSTS_N_INSNS (13), /* sdiv */
979 COSTS_N_INSNS (16), /* ddiv */
980 128, /* cache line size */
981 64, /* l1 cache */
982 2048, /* l2 cache */
983 16, /* prefetch streams */
984 0, /* SF->DF convert */
987 /* Instruction costs on POWER7 processors. */
988 static const
989 struct processor_costs power7_cost = {
990 COSTS_N_INSNS (2), /* mulsi */
991 COSTS_N_INSNS (2), /* mulsi_const */
992 COSTS_N_INSNS (2), /* mulsi_const9 */
993 COSTS_N_INSNS (2), /* muldi */
994 COSTS_N_INSNS (18), /* divsi */
995 COSTS_N_INSNS (34), /* divdi */
996 COSTS_N_INSNS (3), /* fp */
997 COSTS_N_INSNS (3), /* dmul */
998 COSTS_N_INSNS (13), /* sdiv */
999 COSTS_N_INSNS (16), /* ddiv */
1000 128, /* cache line size */
1001 32, /* l1 cache */
1002 256, /* l2 cache */
1003 12, /* prefetch streams */
1004 COSTS_N_INSNS (3), /* SF->DF convert */
1007 /* Instruction costs on POWER8 processors. */
1008 static const
1009 struct processor_costs power8_cost = {
1010 COSTS_N_INSNS (3), /* mulsi */
1011 COSTS_N_INSNS (3), /* mulsi_const */
1012 COSTS_N_INSNS (3), /* mulsi_const9 */
1013 COSTS_N_INSNS (3), /* muldi */
1014 COSTS_N_INSNS (19), /* divsi */
1015 COSTS_N_INSNS (35), /* divdi */
1016 COSTS_N_INSNS (3), /* fp */
1017 COSTS_N_INSNS (3), /* dmul */
1018 COSTS_N_INSNS (14), /* sdiv */
1019 COSTS_N_INSNS (17), /* ddiv */
1020 128, /* cache line size */
1021 32, /* l1 cache */
1022 256, /* l2 cache */
1023 12, /* prefetch streams */
1024 COSTS_N_INSNS (3), /* SF->DF convert */
1027 /* Instruction costs on POWER A2 processors. */
1028 static const
1029 struct processor_costs ppca2_cost = {
1030 COSTS_N_INSNS (16), /* mulsi */
1031 COSTS_N_INSNS (16), /* mulsi_const */
1032 COSTS_N_INSNS (16), /* mulsi_const9 */
1033 COSTS_N_INSNS (16), /* muldi */
1034 COSTS_N_INSNS (22), /* divsi */
1035 COSTS_N_INSNS (28), /* divdi */
1036 COSTS_N_INSNS (3), /* fp */
1037 COSTS_N_INSNS (3), /* dmul */
1038 COSTS_N_INSNS (59), /* sdiv */
1039 COSTS_N_INSNS (72), /* ddiv */
1041 16, /* l1 cache */
1042 2048, /* l2 cache */
1043 16, /* prefetch streams */
1044 0, /* SF->DF convert */
1048 /* Table that classifies rs6000 builtin functions (pure, const, etc.). */
1049 #undef RS6000_BUILTIN_1
1050 #undef RS6000_BUILTIN_2
1051 #undef RS6000_BUILTIN_3
1052 #undef RS6000_BUILTIN_A
1053 #undef RS6000_BUILTIN_D
1054 #undef RS6000_BUILTIN_E
1055 #undef RS6000_BUILTIN_H
1056 #undef RS6000_BUILTIN_P
1057 #undef RS6000_BUILTIN_Q
1058 #undef RS6000_BUILTIN_S
1059 #undef RS6000_BUILTIN_X
1061 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE) \
1062 { NAME, ICODE, MASK, ATTR },
1064 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE) \
1065 { NAME, ICODE, MASK, ATTR },
1067 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE) \
1068 { NAME, ICODE, MASK, ATTR },
1070 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE) \
1071 { NAME, ICODE, MASK, ATTR },
1073 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE) \
1074 { NAME, ICODE, MASK, ATTR },
1076 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE) \
1077 { NAME, ICODE, MASK, ATTR },
1079 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE) \
1080 { NAME, ICODE, MASK, ATTR },
1082 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE) \
1083 { NAME, ICODE, MASK, ATTR },
1085 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE) \
1086 { NAME, ICODE, MASK, ATTR },
1088 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE) \
1089 { NAME, ICODE, MASK, ATTR },
1091 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE) \
1092 { NAME, ICODE, MASK, ATTR },
1094 struct rs6000_builtin_info_type {
1095 const char *name;
1096 const enum insn_code icode;
1097 const HOST_WIDE_INT mask;
1098 const unsigned attr;
1101 static const struct rs6000_builtin_info_type rs6000_builtin_info[] =
1103 #include "rs6000-builtin.def"
1106 #undef RS6000_BUILTIN_1
1107 #undef RS6000_BUILTIN_2
1108 #undef RS6000_BUILTIN_3
1109 #undef RS6000_BUILTIN_A
1110 #undef RS6000_BUILTIN_D
1111 #undef RS6000_BUILTIN_E
1112 #undef RS6000_BUILTIN_H
1113 #undef RS6000_BUILTIN_P
1114 #undef RS6000_BUILTIN_Q
1115 #undef RS6000_BUILTIN_S
1116 #undef RS6000_BUILTIN_X
1118 /* Support for -mveclibabi=<xxx> to control which vector library to use. */
1119 static tree (*rs6000_veclib_handler) (tree, tree, tree);
1122 static bool rs6000_debug_legitimate_address_p (machine_mode, rtx, bool);
1123 static bool spe_func_has_64bit_regs_p (void);
1124 static struct machine_function * rs6000_init_machine_status (void);
1125 static int rs6000_ra_ever_killed (void);
1126 static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
1127 static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
1128 static tree rs6000_handle_struct_attribute (tree *, tree, tree, int, bool *);
1129 static tree rs6000_builtin_vectorized_libmass (tree, tree, tree);
1130 static void rs6000_emit_set_long_const (rtx, HOST_WIDE_INT);
1131 static int rs6000_memory_move_cost (machine_mode, reg_class_t, bool);
1132 static bool rs6000_debug_rtx_costs (rtx, int, int, int, int *, bool);
1133 static int rs6000_debug_address_cost (rtx, machine_mode, addr_space_t,
1134 bool);
1135 static int rs6000_debug_adjust_cost (rtx_insn *, rtx, rtx_insn *, int);
1136 static bool is_microcoded_insn (rtx_insn *);
1137 static bool is_nonpipeline_insn (rtx_insn *);
1138 static bool is_cracked_insn (rtx_insn *);
1139 static bool is_load_insn (rtx, rtx *);
1140 static bool is_store_insn (rtx, rtx *);
1141 static bool set_to_load_agen (rtx_insn *,rtx_insn *);
1142 static bool insn_terminates_group_p (rtx_insn *, enum group_termination);
1143 static bool insn_must_be_first_in_group (rtx_insn *);
1144 static bool insn_must_be_last_in_group (rtx_insn *);
1145 static void altivec_init_builtins (void);
1146 static tree builtin_function_type (machine_mode, machine_mode,
1147 machine_mode, machine_mode,
1148 enum rs6000_builtins, const char *name);
1149 static void rs6000_common_init_builtins (void);
1150 static void paired_init_builtins (void);
1151 static rtx paired_expand_predicate_builtin (enum insn_code, tree, rtx);
1152 static void spe_init_builtins (void);
1153 static void htm_init_builtins (void);
1154 static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
1155 static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
1156 static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
1157 static rs6000_stack_t *rs6000_stack_info (void);
1158 static void is_altivec_return_reg (rtx, void *);
1159 int easy_vector_constant (rtx, machine_mode);
1160 static rtx rs6000_debug_legitimize_address (rtx, rtx, machine_mode);
1161 static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
1162 static rtx rs6000_darwin64_record_arg (CUMULATIVE_ARGS *, const_tree,
1163 bool, bool);
1164 #if TARGET_MACHO
1165 static void macho_branch_islands (void);
1166 #endif
1167 static rtx rs6000_legitimize_reload_address (rtx, machine_mode, int, int,
1168 int, int *);
1169 static rtx rs6000_debug_legitimize_reload_address (rtx, machine_mode, int,
1170 int, int, int *);
1171 static bool rs6000_mode_dependent_address (const_rtx);
1172 static bool rs6000_debug_mode_dependent_address (const_rtx);
1173 static enum reg_class rs6000_secondary_reload_class (enum reg_class,
1174 machine_mode, rtx);
1175 static enum reg_class rs6000_debug_secondary_reload_class (enum reg_class,
1176 machine_mode,
1177 rtx);
1178 static enum reg_class rs6000_preferred_reload_class (rtx, enum reg_class);
1179 static enum reg_class rs6000_debug_preferred_reload_class (rtx,
1180 enum reg_class);
1181 static bool rs6000_secondary_memory_needed (enum reg_class, enum reg_class,
1182 machine_mode);
1183 static bool rs6000_debug_secondary_memory_needed (enum reg_class,
1184 enum reg_class,
1185 machine_mode);
1186 static bool rs6000_cannot_change_mode_class (machine_mode,
1187 machine_mode,
1188 enum reg_class);
1189 static bool rs6000_debug_cannot_change_mode_class (machine_mode,
1190 machine_mode,
1191 enum reg_class);
1192 static bool rs6000_save_toc_in_prologue_p (void);
1194 rtx (*rs6000_legitimize_reload_address_ptr) (rtx, machine_mode, int, int,
1195 int, int *)
1196 = rs6000_legitimize_reload_address;
1198 static bool (*rs6000_mode_dependent_address_ptr) (const_rtx)
1199 = rs6000_mode_dependent_address;
1201 enum reg_class (*rs6000_secondary_reload_class_ptr) (enum reg_class,
1202 machine_mode, rtx)
1203 = rs6000_secondary_reload_class;
1205 enum reg_class (*rs6000_preferred_reload_class_ptr) (rtx, enum reg_class)
1206 = rs6000_preferred_reload_class;
1208 bool (*rs6000_secondary_memory_needed_ptr) (enum reg_class, enum reg_class,
1209 machine_mode)
1210 = rs6000_secondary_memory_needed;
1212 bool (*rs6000_cannot_change_mode_class_ptr) (machine_mode,
1213 machine_mode,
1214 enum reg_class)
1215 = rs6000_cannot_change_mode_class;
1217 const int INSN_NOT_AVAILABLE = -1;
1219 static void rs6000_print_isa_options (FILE *, int, const char *,
1220 HOST_WIDE_INT);
1221 static void rs6000_print_builtin_options (FILE *, int, const char *,
1222 HOST_WIDE_INT);
1224 static enum rs6000_reg_type register_to_reg_type (rtx, bool *);
1225 static bool rs6000_secondary_reload_move (enum rs6000_reg_type,
1226 enum rs6000_reg_type,
1227 machine_mode,
1228 secondary_reload_info *,
1229 bool);
1230 rtl_opt_pass *make_pass_analyze_swaps (gcc::context*);
1232 /* Hash table stuff for keeping track of TOC entries. */
1234 struct GTY((for_user)) toc_hash_struct
1236 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
1237 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
1238 rtx key;
1239 machine_mode key_mode;
1240 int labelno;
1243 struct toc_hasher : ggc_hasher<toc_hash_struct *>
1245 static hashval_t hash (toc_hash_struct *);
1246 static bool equal (toc_hash_struct *, toc_hash_struct *);
1249 static GTY (()) hash_table<toc_hasher> *toc_hash_table;
1251 /* Hash table to keep track of the argument types for builtin functions. */
1253 struct GTY((for_user)) builtin_hash_struct
1255 tree type;
1256 machine_mode mode[4]; /* return value + 3 arguments. */
1257 unsigned char uns_p[4]; /* and whether the types are unsigned. */
1260 struct builtin_hasher : ggc_hasher<builtin_hash_struct *>
1262 static hashval_t hash (builtin_hash_struct *);
1263 static bool equal (builtin_hash_struct *, builtin_hash_struct *);
1266 static GTY (()) hash_table<builtin_hasher> *builtin_hash_table;
1269 /* Default register names. */
1270 char rs6000_reg_names[][8] =
1272 "0", "1", "2", "3", "4", "5", "6", "7",
1273 "8", "9", "10", "11", "12", "13", "14", "15",
1274 "16", "17", "18", "19", "20", "21", "22", "23",
1275 "24", "25", "26", "27", "28", "29", "30", "31",
1276 "0", "1", "2", "3", "4", "5", "6", "7",
1277 "8", "9", "10", "11", "12", "13", "14", "15",
1278 "16", "17", "18", "19", "20", "21", "22", "23",
1279 "24", "25", "26", "27", "28", "29", "30", "31",
1280 "mq", "lr", "ctr","ap",
1281 "0", "1", "2", "3", "4", "5", "6", "7",
1282 "ca",
1283 /* AltiVec registers. */
1284 "0", "1", "2", "3", "4", "5", "6", "7",
1285 "8", "9", "10", "11", "12", "13", "14", "15",
1286 "16", "17", "18", "19", "20", "21", "22", "23",
1287 "24", "25", "26", "27", "28", "29", "30", "31",
1288 "vrsave", "vscr",
1289 /* SPE registers. */
1290 "spe_acc", "spefscr",
1291 /* Soft frame pointer. */
1292 "sfp",
1293 /* HTM SPR registers. */
1294 "tfhar", "tfiar", "texasr",
1295 /* SPE High registers. */
1296 "0", "1", "2", "3", "4", "5", "6", "7",
1297 "8", "9", "10", "11", "12", "13", "14", "15",
1298 "16", "17", "18", "19", "20", "21", "22", "23",
1299 "24", "25", "26", "27", "28", "29", "30", "31"
1302 #ifdef TARGET_REGNAMES
1303 static const char alt_reg_names[][8] =
1305 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
1306 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
1307 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
1308 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
1309 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
1310 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
1311 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
1312 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
1313 "mq", "lr", "ctr", "ap",
1314 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
1315 "ca",
1316 /* AltiVec registers. */
1317 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
1318 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
1319 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
1320 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
1321 "vrsave", "vscr",
1322 /* SPE registers. */
1323 "spe_acc", "spefscr",
1324 /* Soft frame pointer. */
1325 "sfp",
1326 /* HTM SPR registers. */
1327 "tfhar", "tfiar", "texasr",
1328 /* SPE High registers. */
1329 "%rh0", "%rh1", "%rh2", "%rh3", "%rh4", "%rh5", "%rh6", "%rh7",
1330 "%rh8", "%rh9", "%rh10", "%r11", "%rh12", "%rh13", "%rh14", "%rh15",
1331 "%rh16", "%rh17", "%rh18", "%rh19", "%rh20", "%rh21", "%rh22", "%rh23",
1332 "%rh24", "%rh25", "%rh26", "%rh27", "%rh28", "%rh29", "%rh30", "%rh31"
1334 #endif
1336 /* Table of valid machine attributes. */
1338 static const struct attribute_spec rs6000_attribute_table[] =
1340 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
1341 affects_type_identity } */
1342 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute,
1343 false },
1344 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute,
1345 false },
1346 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute,
1347 false },
1348 { "ms_struct", 0, 0, false, false, false, rs6000_handle_struct_attribute,
1349 false },
1350 { "gcc_struct", 0, 0, false, false, false, rs6000_handle_struct_attribute,
1351 false },
1352 #ifdef SUBTARGET_ATTRIBUTE_TABLE
1353 SUBTARGET_ATTRIBUTE_TABLE,
1354 #endif
1355 { NULL, 0, 0, false, false, false, NULL, false }
1358 #ifndef TARGET_PROFILE_KERNEL
1359 #define TARGET_PROFILE_KERNEL 0
1360 #endif
1362 /* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
1363 #define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
1365 /* Initialize the GCC target structure. */
1366 #undef TARGET_ATTRIBUTE_TABLE
1367 #define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
1368 #undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
1369 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
1370 #undef TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P
1371 #define TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P rs6000_attribute_takes_identifier_p
1373 #undef TARGET_ASM_ALIGNED_DI_OP
1374 #define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
1376 /* Default unaligned ops are only provided for ELF. Find the ops needed
1377 for non-ELF systems. */
1378 #ifndef OBJECT_FORMAT_ELF
1379 #if TARGET_XCOFF
1380 /* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
1381 64-bit targets. */
1382 #undef TARGET_ASM_UNALIGNED_HI_OP
1383 #define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
1384 #undef TARGET_ASM_UNALIGNED_SI_OP
1385 #define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
1386 #undef TARGET_ASM_UNALIGNED_DI_OP
1387 #define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
1388 #else
1389 /* For Darwin. */
1390 #undef TARGET_ASM_UNALIGNED_HI_OP
1391 #define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
1392 #undef TARGET_ASM_UNALIGNED_SI_OP
1393 #define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
1394 #undef TARGET_ASM_UNALIGNED_DI_OP
1395 #define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
1396 #undef TARGET_ASM_ALIGNED_DI_OP
1397 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
1398 #endif
1399 #endif
1401 /* This hook deals with fixups for relocatable code and DI-mode objects
1402 in 64-bit code. */
1403 #undef TARGET_ASM_INTEGER
1404 #define TARGET_ASM_INTEGER rs6000_assemble_integer
1406 #if defined (HAVE_GAS_HIDDEN) && !TARGET_MACHO
1407 #undef TARGET_ASM_ASSEMBLE_VISIBILITY
1408 #define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
1409 #endif
1411 #undef TARGET_SET_UP_BY_PROLOGUE
1412 #define TARGET_SET_UP_BY_PROLOGUE rs6000_set_up_by_prologue
1414 #undef TARGET_HAVE_TLS
1415 #define TARGET_HAVE_TLS HAVE_AS_TLS
1417 #undef TARGET_CANNOT_FORCE_CONST_MEM
1418 #define TARGET_CANNOT_FORCE_CONST_MEM rs6000_cannot_force_const_mem
1420 #undef TARGET_DELEGITIMIZE_ADDRESS
1421 #define TARGET_DELEGITIMIZE_ADDRESS rs6000_delegitimize_address
1423 #undef TARGET_CONST_NOT_OK_FOR_DEBUG_P
1424 #define TARGET_CONST_NOT_OK_FOR_DEBUG_P rs6000_const_not_ok_for_debug_p
1426 #undef TARGET_ASM_FUNCTION_PROLOGUE
1427 #define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
1428 #undef TARGET_ASM_FUNCTION_EPILOGUE
1429 #define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
1431 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
1432 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rs6000_output_addr_const_extra
1434 #undef TARGET_LEGITIMIZE_ADDRESS
1435 #define TARGET_LEGITIMIZE_ADDRESS rs6000_legitimize_address
1437 #undef TARGET_SCHED_VARIABLE_ISSUE
1438 #define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
1440 #undef TARGET_SCHED_ISSUE_RATE
1441 #define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
1442 #undef TARGET_SCHED_ADJUST_COST
1443 #define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
1444 #undef TARGET_SCHED_ADJUST_PRIORITY
1445 #define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
1446 #undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
1447 #define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
1448 #undef TARGET_SCHED_INIT
1449 #define TARGET_SCHED_INIT rs6000_sched_init
1450 #undef TARGET_SCHED_FINISH
1451 #define TARGET_SCHED_FINISH rs6000_sched_finish
1452 #undef TARGET_SCHED_REORDER
1453 #define TARGET_SCHED_REORDER rs6000_sched_reorder
1454 #undef TARGET_SCHED_REORDER2
1455 #define TARGET_SCHED_REORDER2 rs6000_sched_reorder2
1457 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
1458 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
1460 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD
1461 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD_GUARD rs6000_use_sched_lookahead_guard
1463 #undef TARGET_SCHED_ALLOC_SCHED_CONTEXT
1464 #define TARGET_SCHED_ALLOC_SCHED_CONTEXT rs6000_alloc_sched_context
1465 #undef TARGET_SCHED_INIT_SCHED_CONTEXT
1466 #define TARGET_SCHED_INIT_SCHED_CONTEXT rs6000_init_sched_context
1467 #undef TARGET_SCHED_SET_SCHED_CONTEXT
1468 #define TARGET_SCHED_SET_SCHED_CONTEXT rs6000_set_sched_context
1469 #undef TARGET_SCHED_FREE_SCHED_CONTEXT
1470 #define TARGET_SCHED_FREE_SCHED_CONTEXT rs6000_free_sched_context
1472 #undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
1473 #define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load
1474 #undef TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT
1475 #define TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT \
1476 rs6000_builtin_support_vector_misalignment
1477 #undef TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE
1478 #define TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE rs6000_vector_alignment_reachable
1479 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
1480 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
1481 rs6000_builtin_vectorization_cost
1482 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
1483 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
1484 rs6000_preferred_simd_mode
1485 #undef TARGET_VECTORIZE_INIT_COST
1486 #define TARGET_VECTORIZE_INIT_COST rs6000_init_cost
1487 #undef TARGET_VECTORIZE_ADD_STMT_COST
1488 #define TARGET_VECTORIZE_ADD_STMT_COST rs6000_add_stmt_cost
1489 #undef TARGET_VECTORIZE_FINISH_COST
1490 #define TARGET_VECTORIZE_FINISH_COST rs6000_finish_cost
1491 #undef TARGET_VECTORIZE_DESTROY_COST_DATA
1492 #define TARGET_VECTORIZE_DESTROY_COST_DATA rs6000_destroy_cost_data
1494 #undef TARGET_INIT_BUILTINS
1495 #define TARGET_INIT_BUILTINS rs6000_init_builtins
1496 #undef TARGET_BUILTIN_DECL
1497 #define TARGET_BUILTIN_DECL rs6000_builtin_decl
1499 #undef TARGET_EXPAND_BUILTIN
1500 #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
1502 #undef TARGET_MANGLE_TYPE
1503 #define TARGET_MANGLE_TYPE rs6000_mangle_type
1505 #undef TARGET_INIT_LIBFUNCS
1506 #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
1508 #if TARGET_MACHO
1509 #undef TARGET_BINDS_LOCAL_P
1510 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
1511 #endif
1513 #undef TARGET_MS_BITFIELD_LAYOUT_P
1514 #define TARGET_MS_BITFIELD_LAYOUT_P rs6000_ms_bitfield_layout_p
1516 #undef TARGET_ASM_OUTPUT_MI_THUNK
1517 #define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
1519 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
1520 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_const_tree_hwi_hwi_const_tree_true
1522 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
1523 #define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
1525 #undef TARGET_REGISTER_MOVE_COST
1526 #define TARGET_REGISTER_MOVE_COST rs6000_register_move_cost
1527 #undef TARGET_MEMORY_MOVE_COST
1528 #define TARGET_MEMORY_MOVE_COST rs6000_memory_move_cost
1529 #undef TARGET_RTX_COSTS
1530 #define TARGET_RTX_COSTS rs6000_rtx_costs
1531 #undef TARGET_ADDRESS_COST
1532 #define TARGET_ADDRESS_COST hook_int_rtx_mode_as_bool_0
1534 #undef TARGET_DWARF_REGISTER_SPAN
1535 #define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
1537 #undef TARGET_INIT_DWARF_REG_SIZES_EXTRA
1538 #define TARGET_INIT_DWARF_REG_SIZES_EXTRA rs6000_init_dwarf_reg_sizes_extra
1540 #undef TARGET_MEMBER_TYPE_FORCES_BLK
1541 #define TARGET_MEMBER_TYPE_FORCES_BLK rs6000_member_type_forces_blk
1543 #undef TARGET_PROMOTE_FUNCTION_MODE
1544 #define TARGET_PROMOTE_FUNCTION_MODE rs6000_promote_function_mode
1546 #undef TARGET_RETURN_IN_MEMORY
1547 #define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
1549 #undef TARGET_RETURN_IN_MSB
1550 #define TARGET_RETURN_IN_MSB rs6000_return_in_msb
1552 #undef TARGET_SETUP_INCOMING_VARARGS
1553 #define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
1555 /* Always strict argument naming on rs6000. */
1556 #undef TARGET_STRICT_ARGUMENT_NAMING
1557 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
1558 #undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
1559 #define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
1560 #undef TARGET_SPLIT_COMPLEX_ARG
1561 #define TARGET_SPLIT_COMPLEX_ARG hook_bool_const_tree_true
1562 #undef TARGET_MUST_PASS_IN_STACK
1563 #define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
1564 #undef TARGET_PASS_BY_REFERENCE
1565 #define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
1566 #undef TARGET_ARG_PARTIAL_BYTES
1567 #define TARGET_ARG_PARTIAL_BYTES rs6000_arg_partial_bytes
1568 #undef TARGET_FUNCTION_ARG_ADVANCE
1569 #define TARGET_FUNCTION_ARG_ADVANCE rs6000_function_arg_advance
1570 #undef TARGET_FUNCTION_ARG
1571 #define TARGET_FUNCTION_ARG rs6000_function_arg
1572 #undef TARGET_FUNCTION_ARG_BOUNDARY
1573 #define TARGET_FUNCTION_ARG_BOUNDARY rs6000_function_arg_boundary
1575 #undef TARGET_BUILD_BUILTIN_VA_LIST
1576 #define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
1578 #undef TARGET_EXPAND_BUILTIN_VA_START
1579 #define TARGET_EXPAND_BUILTIN_VA_START rs6000_va_start
1581 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
1582 #define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
1584 #undef TARGET_EH_RETURN_FILTER_MODE
1585 #define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
1587 #undef TARGET_SCALAR_MODE_SUPPORTED_P
1588 #define TARGET_SCALAR_MODE_SUPPORTED_P rs6000_scalar_mode_supported_p
1590 #undef TARGET_VECTOR_MODE_SUPPORTED_P
1591 #define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
1593 #undef TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN
1594 #define TARGET_INVALID_ARG_FOR_UNPROTOTYPED_FN invalid_arg_for_unprototyped_fn
1596 #undef TARGET_ASM_LOOP_ALIGN_MAX_SKIP
1597 #define TARGET_ASM_LOOP_ALIGN_MAX_SKIP rs6000_loop_align_max_skip
1599 #undef TARGET_MD_ASM_ADJUST
1600 #define TARGET_MD_ASM_ADJUST rs6000_md_asm_adjust
1602 #undef TARGET_OPTION_OVERRIDE
1603 #define TARGET_OPTION_OVERRIDE rs6000_option_override
1605 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
1606 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
1607 rs6000_builtin_vectorized_function
1609 #if !TARGET_MACHO
1610 #undef TARGET_STACK_PROTECT_FAIL
1611 #define TARGET_STACK_PROTECT_FAIL rs6000_stack_protect_fail
1612 #endif
1614 /* MPC604EUM 3.5.2 Weak Consistency between Multiple Processors
1615 The PowerPC architecture requires only weak consistency among
1616 processors--that is, memory accesses between processors need not be
1617 sequentially consistent and memory accesses among processors can occur
1618 in any order. The ability to order memory accesses weakly provides
1619 opportunities for more efficient use of the system bus. Unless a
1620 dependency exists, the 604e allows read operations to precede store
1621 operations. */
1622 #undef TARGET_RELAXED_ORDERING
1623 #define TARGET_RELAXED_ORDERING true
1625 #ifdef HAVE_AS_TLS
1626 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
1627 #define TARGET_ASM_OUTPUT_DWARF_DTPREL rs6000_output_dwarf_dtprel
1628 #endif
1630 /* Use a 32-bit anchor range. This leads to sequences like:
1632 addis tmp,anchor,high
1633 add dest,tmp,low
1635 where tmp itself acts as an anchor, and can be shared between
1636 accesses to the same 64k page. */
1637 #undef TARGET_MIN_ANCHOR_OFFSET
1638 #define TARGET_MIN_ANCHOR_OFFSET -0x7fffffff - 1
1639 #undef TARGET_MAX_ANCHOR_OFFSET
1640 #define TARGET_MAX_ANCHOR_OFFSET 0x7fffffff
1641 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
1642 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P rs6000_use_blocks_for_constant_p
1643 #undef TARGET_USE_BLOCKS_FOR_DECL_P
1644 #define TARGET_USE_BLOCKS_FOR_DECL_P rs6000_use_blocks_for_decl_p
1646 #undef TARGET_BUILTIN_RECIPROCAL
1647 #define TARGET_BUILTIN_RECIPROCAL rs6000_builtin_reciprocal
1649 #undef TARGET_EXPAND_TO_RTL_HOOK
1650 #define TARGET_EXPAND_TO_RTL_HOOK rs6000_alloc_sdmode_stack_slot
1652 #undef TARGET_INSTANTIATE_DECLS
1653 #define TARGET_INSTANTIATE_DECLS rs6000_instantiate_decls
1655 #undef TARGET_SECONDARY_RELOAD
1656 #define TARGET_SECONDARY_RELOAD rs6000_secondary_reload
1658 #undef TARGET_LEGITIMATE_ADDRESS_P
1659 #define TARGET_LEGITIMATE_ADDRESS_P rs6000_legitimate_address_p
1661 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
1662 #define TARGET_MODE_DEPENDENT_ADDRESS_P rs6000_mode_dependent_address_p
1664 #undef TARGET_LRA_P
1665 #define TARGET_LRA_P rs6000_lra_p
1667 #undef TARGET_CAN_ELIMINATE
1668 #define TARGET_CAN_ELIMINATE rs6000_can_eliminate
1670 #undef TARGET_CONDITIONAL_REGISTER_USAGE
1671 #define TARGET_CONDITIONAL_REGISTER_USAGE rs6000_conditional_register_usage
1673 #undef TARGET_TRAMPOLINE_INIT
1674 #define TARGET_TRAMPOLINE_INIT rs6000_trampoline_init
1676 #undef TARGET_FUNCTION_VALUE
1677 #define TARGET_FUNCTION_VALUE rs6000_function_value
1679 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
1680 #define TARGET_OPTION_VALID_ATTRIBUTE_P rs6000_valid_attribute_p
1682 #undef TARGET_OPTION_SAVE
1683 #define TARGET_OPTION_SAVE rs6000_function_specific_save
1685 #undef TARGET_OPTION_RESTORE
1686 #define TARGET_OPTION_RESTORE rs6000_function_specific_restore
1688 #undef TARGET_OPTION_PRINT
1689 #define TARGET_OPTION_PRINT rs6000_function_specific_print
1691 #undef TARGET_CAN_INLINE_P
1692 #define TARGET_CAN_INLINE_P rs6000_can_inline_p
1694 #undef TARGET_SET_CURRENT_FUNCTION
1695 #define TARGET_SET_CURRENT_FUNCTION rs6000_set_current_function
1697 #undef TARGET_LEGITIMATE_CONSTANT_P
1698 #define TARGET_LEGITIMATE_CONSTANT_P rs6000_legitimate_constant_p
1700 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
1701 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK rs6000_vectorize_vec_perm_const_ok
1703 #undef TARGET_CAN_USE_DOLOOP_P
1704 #define TARGET_CAN_USE_DOLOOP_P can_use_doloop_if_innermost
1706 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
1707 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV rs6000_atomic_assign_expand_fenv
1709 #undef TARGET_LIBGCC_CMP_RETURN_MODE
1710 #define TARGET_LIBGCC_CMP_RETURN_MODE rs6000_abi_word_mode
1711 #undef TARGET_LIBGCC_SHIFT_COUNT_MODE
1712 #define TARGET_LIBGCC_SHIFT_COUNT_MODE rs6000_abi_word_mode
1713 #undef TARGET_UNWIND_WORD_MODE
1714 #define TARGET_UNWIND_WORD_MODE rs6000_abi_word_mode
1717 /* Processor table. */
1718 struct rs6000_ptt
1720 const char *const name; /* Canonical processor name. */
1721 const enum processor_type processor; /* Processor type enum value. */
1722 const HOST_WIDE_INT target_enable; /* Target flags to enable. */
1725 static struct rs6000_ptt const processor_target_table[] =
1727 #define RS6000_CPU(NAME, CPU, FLAGS) { NAME, CPU, FLAGS },
1728 #include "rs6000-cpus.def"
1729 #undef RS6000_CPU
1732 /* Look up a processor name for -mcpu=xxx and -mtune=xxx. Return -1 if the
1733 name is invalid. */
1735 static int
1736 rs6000_cpu_name_lookup (const char *name)
1738 size_t i;
1740 if (name != NULL)
1742 for (i = 0; i < ARRAY_SIZE (processor_target_table); i++)
1743 if (! strcmp (name, processor_target_table[i].name))
1744 return (int)i;
1747 return -1;
1751 /* Return number of consecutive hard regs needed starting at reg REGNO
1752 to hold something of mode MODE.
1753 This is ordinarily the length in words of a value of mode MODE
1754 but can be less for certain modes in special long registers.
1756 For the SPE, GPRs are 64 bits but only 32 bits are visible in
1757 scalar instructions. The upper 32 bits are only available to the
1758 SIMD instructions.
1760 POWER and PowerPC GPRs hold 32 bits worth;
1761 PowerPC64 GPRs and FPRs point register holds 64 bits worth. */
1763 static int
1764 rs6000_hard_regno_nregs_internal (int regno, machine_mode mode)
1766 unsigned HOST_WIDE_INT reg_size;
1768 /* TF/TD modes are special in that they always take 2 registers. */
1769 if (FP_REGNO_P (regno))
1770 reg_size = ((VECTOR_MEM_VSX_P (mode) && mode != TDmode && mode != TFmode)
1771 ? UNITS_PER_VSX_WORD
1772 : UNITS_PER_FP_WORD);
1774 else if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1775 reg_size = UNITS_PER_SPE_WORD;
1777 else if (ALTIVEC_REGNO_P (regno))
1778 reg_size = UNITS_PER_ALTIVEC_WORD;
1780 /* The value returned for SCmode in the E500 double case is 2 for
1781 ABI compatibility; storing an SCmode value in a single register
1782 would require function_arg and rs6000_spe_function_arg to handle
1783 SCmode so as to pass the value correctly in a pair of
1784 registers. */
1785 else if (TARGET_E500_DOUBLE && FLOAT_MODE_P (mode) && mode != SCmode
1786 && !DECIMAL_FLOAT_MODE_P (mode) && SPE_SIMD_REGNO_P (regno))
1787 reg_size = UNITS_PER_FP_WORD;
1789 else
1790 reg_size = UNITS_PER_WORD;
1792 return (GET_MODE_SIZE (mode) + reg_size - 1) / reg_size;
1795 /* Value is 1 if hard register REGNO can hold a value of machine-mode
1796 MODE. */
1797 static int
1798 rs6000_hard_regno_mode_ok (int regno, machine_mode mode)
1800 int last_regno = regno + rs6000_hard_regno_nregs[mode][regno] - 1;
1802 /* PTImode can only go in GPRs. Quad word memory operations require even/odd
1803 register combinations, and use PTImode where we need to deal with quad
1804 word memory operations. Don't allow quad words in the argument or frame
1805 pointer registers, just registers 0..31. */
1806 if (mode == PTImode)
1807 return (IN_RANGE (regno, FIRST_GPR_REGNO, LAST_GPR_REGNO)
1808 && IN_RANGE (last_regno, FIRST_GPR_REGNO, LAST_GPR_REGNO)
1809 && ((regno & 1) == 0));
1811 /* VSX registers that overlap the FPR registers are larger than for non-VSX
1812 implementations. Don't allow an item to be split between a FP register
1813 and an Altivec register. Allow TImode in all VSX registers if the user
1814 asked for it. */
1815 if (TARGET_VSX && VSX_REGNO_P (regno)
1816 && (VECTOR_MEM_VSX_P (mode)
1817 || reg_addr[mode].scalar_in_vmx_p
1818 || (TARGET_VSX_TIMODE && mode == TImode)
1819 || (TARGET_VADDUQM && mode == V1TImode)))
1821 if (FP_REGNO_P (regno))
1822 return FP_REGNO_P (last_regno);
1824 if (ALTIVEC_REGNO_P (regno))
1826 if (GET_MODE_SIZE (mode) != 16 && !reg_addr[mode].scalar_in_vmx_p)
1827 return 0;
1829 return ALTIVEC_REGNO_P (last_regno);
1833 /* The GPRs can hold any mode, but values bigger than one register
1834 cannot go past R31. */
1835 if (INT_REGNO_P (regno))
1836 return INT_REGNO_P (last_regno);
1838 /* The float registers (except for VSX vector modes) can only hold floating
1839 modes and DImode. */
1840 if (FP_REGNO_P (regno))
1842 if (SCALAR_FLOAT_MODE_P (mode)
1843 && (mode != TDmode || (regno % 2) == 0)
1844 && FP_REGNO_P (last_regno))
1845 return 1;
1847 if (GET_MODE_CLASS (mode) == MODE_INT
1848 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD)
1849 return 1;
1851 if (PAIRED_SIMD_REGNO_P (regno) && TARGET_PAIRED_FLOAT
1852 && PAIRED_VECTOR_MODE (mode))
1853 return 1;
1855 return 0;
1858 /* The CR register can only hold CC modes. */
1859 if (CR_REGNO_P (regno))
1860 return GET_MODE_CLASS (mode) == MODE_CC;
1862 if (CA_REGNO_P (regno))
1863 return mode == Pmode || mode == SImode;
1865 /* AltiVec only in AldyVec registers. */
1866 if (ALTIVEC_REGNO_P (regno))
1867 return (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)
1868 || mode == V1TImode);
1870 /* ...but GPRs can hold SIMD data on the SPE in one register. */
1871 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1872 return 1;
1874 /* We cannot put non-VSX TImode or PTImode anywhere except general register
1875 and it must be able to fit within the register set. */
1877 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1880 /* Print interesting facts about registers. */
1881 static void
1882 rs6000_debug_reg_print (int first_regno, int last_regno, const char *reg_name)
1884 int r, m;
1886 for (r = first_regno; r <= last_regno; ++r)
1888 const char *comma = "";
1889 int len;
1891 if (first_regno == last_regno)
1892 fprintf (stderr, "%s:\t", reg_name);
1893 else
1894 fprintf (stderr, "%s%d:\t", reg_name, r - first_regno);
1896 len = 8;
1897 for (m = 0; m < NUM_MACHINE_MODES; ++m)
1898 if (rs6000_hard_regno_mode_ok_p[m][r] && rs6000_hard_regno_nregs[m][r])
1900 if (len > 70)
1902 fprintf (stderr, ",\n\t");
1903 len = 8;
1904 comma = "";
1907 if (rs6000_hard_regno_nregs[m][r] > 1)
1908 len += fprintf (stderr, "%s%s/%d", comma, GET_MODE_NAME (m),
1909 rs6000_hard_regno_nregs[m][r]);
1910 else
1911 len += fprintf (stderr, "%s%s", comma, GET_MODE_NAME (m));
1913 comma = ", ";
1916 if (call_used_regs[r])
1918 if (len > 70)
1920 fprintf (stderr, ",\n\t");
1921 len = 8;
1922 comma = "";
1925 len += fprintf (stderr, "%s%s", comma, "call-used");
1926 comma = ", ";
1929 if (fixed_regs[r])
1931 if (len > 70)
1933 fprintf (stderr, ",\n\t");
1934 len = 8;
1935 comma = "";
1938 len += fprintf (stderr, "%s%s", comma, "fixed");
1939 comma = ", ";
1942 if (len > 70)
1944 fprintf (stderr, ",\n\t");
1945 comma = "";
1948 len += fprintf (stderr, "%sreg-class = %s", comma,
1949 reg_class_names[(int)rs6000_regno_regclass[r]]);
1950 comma = ", ";
1952 if (len > 70)
1954 fprintf (stderr, ",\n\t");
1955 comma = "";
1958 fprintf (stderr, "%sregno = %d\n", comma, r);
1962 static const char *
1963 rs6000_debug_vector_unit (enum rs6000_vector v)
1965 const char *ret;
1967 switch (v)
1969 case VECTOR_NONE: ret = "none"; break;
1970 case VECTOR_ALTIVEC: ret = "altivec"; break;
1971 case VECTOR_VSX: ret = "vsx"; break;
1972 case VECTOR_P8_VECTOR: ret = "p8_vector"; break;
1973 case VECTOR_PAIRED: ret = "paired"; break;
1974 case VECTOR_SPE: ret = "spe"; break;
1975 case VECTOR_OTHER: ret = "other"; break;
1976 default: ret = "unknown"; break;
1979 return ret;
1982 /* Inner function printing just the address mask for a particular reload
1983 register class. */
1984 DEBUG_FUNCTION char *
1985 rs6000_debug_addr_mask (addr_mask_type mask, bool keep_spaces)
1987 static char ret[8];
1988 char *p = ret;
1990 if ((mask & RELOAD_REG_VALID) != 0)
1991 *p++ = 'v';
1992 else if (keep_spaces)
1993 *p++ = ' ';
1995 if ((mask & RELOAD_REG_MULTIPLE) != 0)
1996 *p++ = 'm';
1997 else if (keep_spaces)
1998 *p++ = ' ';
2000 if ((mask & RELOAD_REG_INDEXED) != 0)
2001 *p++ = 'i';
2002 else if (keep_spaces)
2003 *p++ = ' ';
2005 if ((mask & RELOAD_REG_OFFSET) != 0)
2006 *p++ = 'o';
2007 else if (keep_spaces)
2008 *p++ = ' ';
2010 if ((mask & RELOAD_REG_PRE_INCDEC) != 0)
2011 *p++ = '+';
2012 else if (keep_spaces)
2013 *p++ = ' ';
2015 if ((mask & RELOAD_REG_PRE_MODIFY) != 0)
2016 *p++ = '+';
2017 else if (keep_spaces)
2018 *p++ = ' ';
2020 if ((mask & RELOAD_REG_AND_M16) != 0)
2021 *p++ = '&';
2022 else if (keep_spaces)
2023 *p++ = ' ';
2025 *p = '\0';
2027 return ret;
2030 /* Print the address masks in a human readble fashion. */
2031 DEBUG_FUNCTION void
2032 rs6000_debug_print_mode (ssize_t m)
2034 ssize_t rc;
2036 fprintf (stderr, "Mode: %-5s", GET_MODE_NAME (m));
2037 for (rc = 0; rc < N_RELOAD_REG; rc++)
2038 fprintf (stderr, " %s: %s", reload_reg_map[rc].name,
2039 rs6000_debug_addr_mask (reg_addr[m].addr_mask[rc], true));
2041 if (rs6000_vector_unit[m] != VECTOR_NONE
2042 || rs6000_vector_mem[m] != VECTOR_NONE
2043 || (reg_addr[m].reload_store != CODE_FOR_nothing)
2044 || (reg_addr[m].reload_load != CODE_FOR_nothing)
2045 || reg_addr[m].scalar_in_vmx_p)
2047 fprintf (stderr,
2048 " Vector-arith=%-10s Vector-mem=%-10s Reload=%c%c Upper=%c",
2049 rs6000_debug_vector_unit (rs6000_vector_unit[m]),
2050 rs6000_debug_vector_unit (rs6000_vector_mem[m]),
2051 (reg_addr[m].reload_store != CODE_FOR_nothing) ? 's' : '*',
2052 (reg_addr[m].reload_load != CODE_FOR_nothing) ? 'l' : '*',
2053 (reg_addr[m].scalar_in_vmx_p) ? 'y' : 'n');
2056 fputs ("\n", stderr);
2059 #define DEBUG_FMT_ID "%-32s= "
2060 #define DEBUG_FMT_D DEBUG_FMT_ID "%d\n"
2061 #define DEBUG_FMT_WX DEBUG_FMT_ID "%#.12" HOST_WIDE_INT_PRINT "x: "
2062 #define DEBUG_FMT_S DEBUG_FMT_ID "%s\n"
2064 /* Print various interesting information with -mdebug=reg. */
2065 static void
2066 rs6000_debug_reg_global (void)
2068 static const char *const tf[2] = { "false", "true" };
2069 const char *nl = (const char *)0;
2070 int m;
2071 size_t m1, m2, v;
2072 char costly_num[20];
2073 char nop_num[20];
2074 char flags_buffer[40];
2075 const char *costly_str;
2076 const char *nop_str;
2077 const char *trace_str;
2078 const char *abi_str;
2079 const char *cmodel_str;
2080 struct cl_target_option cl_opts;
2082 /* Modes we want tieable information on. */
2083 static const machine_mode print_tieable_modes[] = {
2084 QImode,
2085 HImode,
2086 SImode,
2087 DImode,
2088 TImode,
2089 PTImode,
2090 SFmode,
2091 DFmode,
2092 TFmode,
2093 SDmode,
2094 DDmode,
2095 TDmode,
2096 V8QImode,
2097 V4HImode,
2098 V2SImode,
2099 V16QImode,
2100 V8HImode,
2101 V4SImode,
2102 V2DImode,
2103 V1TImode,
2104 V32QImode,
2105 V16HImode,
2106 V8SImode,
2107 V4DImode,
2108 V2TImode,
2109 V2SFmode,
2110 V4SFmode,
2111 V2DFmode,
2112 V8SFmode,
2113 V4DFmode,
2114 CCmode,
2115 CCUNSmode,
2116 CCEQmode,
2119 /* Virtual regs we are interested in. */
2120 const static struct {
2121 int regno; /* register number. */
2122 const char *name; /* register name. */
2123 } virtual_regs[] = {
2124 { STACK_POINTER_REGNUM, "stack pointer:" },
2125 { TOC_REGNUM, "toc: " },
2126 { STATIC_CHAIN_REGNUM, "static chain: " },
2127 { RS6000_PIC_OFFSET_TABLE_REGNUM, "pic offset: " },
2128 { HARD_FRAME_POINTER_REGNUM, "hard frame: " },
2129 { ARG_POINTER_REGNUM, "arg pointer: " },
2130 { FRAME_POINTER_REGNUM, "frame pointer:" },
2131 { FIRST_PSEUDO_REGISTER, "first pseudo: " },
2132 { FIRST_VIRTUAL_REGISTER, "first virtual:" },
2133 { VIRTUAL_INCOMING_ARGS_REGNUM, "incoming_args:" },
2134 { VIRTUAL_STACK_VARS_REGNUM, "stack_vars: " },
2135 { VIRTUAL_STACK_DYNAMIC_REGNUM, "stack_dynamic:" },
2136 { VIRTUAL_OUTGOING_ARGS_REGNUM, "outgoing_args:" },
2137 { VIRTUAL_CFA_REGNUM, "cfa (frame): " },
2138 { VIRTUAL_PREFERRED_STACK_BOUNDARY_REGNUM, "stack boundry:" },
2139 { LAST_VIRTUAL_REGISTER, "last virtual: " },
2142 fputs ("\nHard register information:\n", stderr);
2143 rs6000_debug_reg_print (FIRST_GPR_REGNO, LAST_GPR_REGNO, "gr");
2144 rs6000_debug_reg_print (FIRST_FPR_REGNO, LAST_FPR_REGNO, "fp");
2145 rs6000_debug_reg_print (FIRST_ALTIVEC_REGNO,
2146 LAST_ALTIVEC_REGNO,
2147 "vs");
2148 rs6000_debug_reg_print (LR_REGNO, LR_REGNO, "lr");
2149 rs6000_debug_reg_print (CTR_REGNO, CTR_REGNO, "ctr");
2150 rs6000_debug_reg_print (CR0_REGNO, CR7_REGNO, "cr");
2151 rs6000_debug_reg_print (CA_REGNO, CA_REGNO, "ca");
2152 rs6000_debug_reg_print (VRSAVE_REGNO, VRSAVE_REGNO, "vrsave");
2153 rs6000_debug_reg_print (VSCR_REGNO, VSCR_REGNO, "vscr");
2154 rs6000_debug_reg_print (SPE_ACC_REGNO, SPE_ACC_REGNO, "spe_a");
2155 rs6000_debug_reg_print (SPEFSCR_REGNO, SPEFSCR_REGNO, "spe_f");
2157 fputs ("\nVirtual/stack/frame registers:\n", stderr);
2158 for (v = 0; v < ARRAY_SIZE (virtual_regs); v++)
2159 fprintf (stderr, "%s regno = %3d\n", virtual_regs[v].name, virtual_regs[v].regno);
2161 fprintf (stderr,
2162 "\n"
2163 "d reg_class = %s\n"
2164 "f reg_class = %s\n"
2165 "v reg_class = %s\n"
2166 "wa reg_class = %s\n"
2167 "wd reg_class = %s\n"
2168 "wf reg_class = %s\n"
2169 "wg reg_class = %s\n"
2170 "wh reg_class = %s\n"
2171 "wi reg_class = %s\n"
2172 "wj reg_class = %s\n"
2173 "wk reg_class = %s\n"
2174 "wl reg_class = %s\n"
2175 "wm reg_class = %s\n"
2176 "wr reg_class = %s\n"
2177 "ws reg_class = %s\n"
2178 "wt reg_class = %s\n"
2179 "wu reg_class = %s\n"
2180 "wv reg_class = %s\n"
2181 "ww reg_class = %s\n"
2182 "wx reg_class = %s\n"
2183 "wy reg_class = %s\n"
2184 "wz reg_class = %s\n"
2185 "\n",
2186 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_d]],
2187 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_f]],
2188 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_v]],
2189 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wa]],
2190 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wd]],
2191 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wf]],
2192 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wg]],
2193 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wh]],
2194 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wi]],
2195 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wj]],
2196 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wk]],
2197 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wl]],
2198 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wm]],
2199 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wr]],
2200 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_ws]],
2201 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wt]],
2202 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wu]],
2203 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wv]],
2204 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_ww]],
2205 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wx]],
2206 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wy]],
2207 reg_class_names[rs6000_constraints[RS6000_CONSTRAINT_wz]]);
2209 nl = "\n";
2210 for (m = 0; m < NUM_MACHINE_MODES; ++m)
2211 rs6000_debug_print_mode (m);
2213 fputs ("\n", stderr);
2215 for (m1 = 0; m1 < ARRAY_SIZE (print_tieable_modes); m1++)
2217 machine_mode mode1 = print_tieable_modes[m1];
2218 bool first_time = true;
2220 nl = (const char *)0;
2221 for (m2 = 0; m2 < ARRAY_SIZE (print_tieable_modes); m2++)
2223 machine_mode mode2 = print_tieable_modes[m2];
2224 if (mode1 != mode2 && MODES_TIEABLE_P (mode1, mode2))
2226 if (first_time)
2228 fprintf (stderr, "Tieable modes %s:", GET_MODE_NAME (mode1));
2229 nl = "\n";
2230 first_time = false;
2233 fprintf (stderr, " %s", GET_MODE_NAME (mode2));
2237 if (!first_time)
2238 fputs ("\n", stderr);
2241 if (nl)
2242 fputs (nl, stderr);
2244 if (rs6000_recip_control)
2246 fprintf (stderr, "\nReciprocal mask = 0x%x\n", rs6000_recip_control);
2248 for (m = 0; m < NUM_MACHINE_MODES; ++m)
2249 if (rs6000_recip_bits[m])
2251 fprintf (stderr,
2252 "Reciprocal estimate mode: %-5s divide: %s rsqrt: %s\n",
2253 GET_MODE_NAME (m),
2254 (RS6000_RECIP_AUTO_RE_P (m)
2255 ? "auto"
2256 : (RS6000_RECIP_HAVE_RE_P (m) ? "have" : "none")),
2257 (RS6000_RECIP_AUTO_RSQRTE_P (m)
2258 ? "auto"
2259 : (RS6000_RECIP_HAVE_RSQRTE_P (m) ? "have" : "none")));
2262 fputs ("\n", stderr);
2265 if (rs6000_cpu_index >= 0)
2267 const char *name = processor_target_table[rs6000_cpu_index].name;
2268 HOST_WIDE_INT flags
2269 = processor_target_table[rs6000_cpu_index].target_enable;
2271 sprintf (flags_buffer, "-mcpu=%s flags", name);
2272 rs6000_print_isa_options (stderr, 0, flags_buffer, flags);
2274 else
2275 fprintf (stderr, DEBUG_FMT_S, "cpu", "<none>");
2277 if (rs6000_tune_index >= 0)
2279 const char *name = processor_target_table[rs6000_tune_index].name;
2280 HOST_WIDE_INT flags
2281 = processor_target_table[rs6000_tune_index].target_enable;
2283 sprintf (flags_buffer, "-mtune=%s flags", name);
2284 rs6000_print_isa_options (stderr, 0, flags_buffer, flags);
2286 else
2287 fprintf (stderr, DEBUG_FMT_S, "tune", "<none>");
2289 cl_target_option_save (&cl_opts, &global_options);
2290 rs6000_print_isa_options (stderr, 0, "rs6000_isa_flags",
2291 rs6000_isa_flags);
2293 rs6000_print_isa_options (stderr, 0, "rs6000_isa_flags_explicit",
2294 rs6000_isa_flags_explicit);
2296 rs6000_print_builtin_options (stderr, 0, "rs6000_builtin_mask",
2297 rs6000_builtin_mask);
2299 rs6000_print_isa_options (stderr, 0, "TARGET_DEFAULT", TARGET_DEFAULT);
2301 fprintf (stderr, DEBUG_FMT_S, "--with-cpu default",
2302 OPTION_TARGET_CPU_DEFAULT ? OPTION_TARGET_CPU_DEFAULT : "<none>");
2304 switch (rs6000_sched_costly_dep)
2306 case max_dep_latency:
2307 costly_str = "max_dep_latency";
2308 break;
2310 case no_dep_costly:
2311 costly_str = "no_dep_costly";
2312 break;
2314 case all_deps_costly:
2315 costly_str = "all_deps_costly";
2316 break;
2318 case true_store_to_load_dep_costly:
2319 costly_str = "true_store_to_load_dep_costly";
2320 break;
2322 case store_to_load_dep_costly:
2323 costly_str = "store_to_load_dep_costly";
2324 break;
2326 default:
2327 costly_str = costly_num;
2328 sprintf (costly_num, "%d", (int)rs6000_sched_costly_dep);
2329 break;
2332 fprintf (stderr, DEBUG_FMT_S, "sched_costly_dep", costly_str);
2334 switch (rs6000_sched_insert_nops)
2336 case sched_finish_regroup_exact:
2337 nop_str = "sched_finish_regroup_exact";
2338 break;
2340 case sched_finish_pad_groups:
2341 nop_str = "sched_finish_pad_groups";
2342 break;
2344 case sched_finish_none:
2345 nop_str = "sched_finish_none";
2346 break;
2348 default:
2349 nop_str = nop_num;
2350 sprintf (nop_num, "%d", (int)rs6000_sched_insert_nops);
2351 break;
2354 fprintf (stderr, DEBUG_FMT_S, "sched_insert_nops", nop_str);
2356 switch (rs6000_sdata)
2358 default:
2359 case SDATA_NONE:
2360 break;
2362 case SDATA_DATA:
2363 fprintf (stderr, DEBUG_FMT_S, "sdata", "data");
2364 break;
2366 case SDATA_SYSV:
2367 fprintf (stderr, DEBUG_FMT_S, "sdata", "sysv");
2368 break;
2370 case SDATA_EABI:
2371 fprintf (stderr, DEBUG_FMT_S, "sdata", "eabi");
2372 break;
2376 switch (rs6000_traceback)
2378 case traceback_default: trace_str = "default"; break;
2379 case traceback_none: trace_str = "none"; break;
2380 case traceback_part: trace_str = "part"; break;
2381 case traceback_full: trace_str = "full"; break;
2382 default: trace_str = "unknown"; break;
2385 fprintf (stderr, DEBUG_FMT_S, "traceback", trace_str);
2387 switch (rs6000_current_cmodel)
2389 case CMODEL_SMALL: cmodel_str = "small"; break;
2390 case CMODEL_MEDIUM: cmodel_str = "medium"; break;
2391 case CMODEL_LARGE: cmodel_str = "large"; break;
2392 default: cmodel_str = "unknown"; break;
2395 fprintf (stderr, DEBUG_FMT_S, "cmodel", cmodel_str);
2397 switch (rs6000_current_abi)
2399 case ABI_NONE: abi_str = "none"; break;
2400 case ABI_AIX: abi_str = "aix"; break;
2401 case ABI_ELFv2: abi_str = "ELFv2"; break;
2402 case ABI_V4: abi_str = "V4"; break;
2403 case ABI_DARWIN: abi_str = "darwin"; break;
2404 default: abi_str = "unknown"; break;
2407 fprintf (stderr, DEBUG_FMT_S, "abi", abi_str);
2409 if (rs6000_altivec_abi)
2410 fprintf (stderr, DEBUG_FMT_S, "altivec_abi", "true");
2412 if (rs6000_spe_abi)
2413 fprintf (stderr, DEBUG_FMT_S, "spe_abi", "true");
2415 if (rs6000_darwin64_abi)
2416 fprintf (stderr, DEBUG_FMT_S, "darwin64_abi", "true");
2418 if (rs6000_float_gprs)
2419 fprintf (stderr, DEBUG_FMT_S, "float_gprs", "true");
2421 fprintf (stderr, DEBUG_FMT_S, "fprs",
2422 (TARGET_FPRS ? "true" : "false"));
2424 fprintf (stderr, DEBUG_FMT_S, "single_float",
2425 (TARGET_SINGLE_FLOAT ? "true" : "false"));
2427 fprintf (stderr, DEBUG_FMT_S, "double_float",
2428 (TARGET_DOUBLE_FLOAT ? "true" : "false"));
2430 fprintf (stderr, DEBUG_FMT_S, "soft_float",
2431 (TARGET_SOFT_FLOAT ? "true" : "false"));
2433 fprintf (stderr, DEBUG_FMT_S, "e500_single",
2434 (TARGET_E500_SINGLE ? "true" : "false"));
2436 fprintf (stderr, DEBUG_FMT_S, "e500_double",
2437 (TARGET_E500_DOUBLE ? "true" : "false"));
2439 if (TARGET_LINK_STACK)
2440 fprintf (stderr, DEBUG_FMT_S, "link_stack", "true");
2442 if (targetm.lra_p ())
2443 fprintf (stderr, DEBUG_FMT_S, "lra", "true");
2445 if (TARGET_P8_FUSION)
2446 fprintf (stderr, DEBUG_FMT_S, "p8 fusion",
2447 (TARGET_P8_FUSION_SIGN) ? "zero+sign" : "zero");
2449 fprintf (stderr, DEBUG_FMT_S, "plt-format",
2450 TARGET_SECURE_PLT ? "secure" : "bss");
2451 fprintf (stderr, DEBUG_FMT_S, "struct-return",
2452 aix_struct_return ? "aix" : "sysv");
2453 fprintf (stderr, DEBUG_FMT_S, "always_hint", tf[!!rs6000_always_hint]);
2454 fprintf (stderr, DEBUG_FMT_S, "sched_groups", tf[!!rs6000_sched_groups]);
2455 fprintf (stderr, DEBUG_FMT_S, "align_branch",
2456 tf[!!rs6000_align_branch_targets]);
2457 fprintf (stderr, DEBUG_FMT_D, "tls_size", rs6000_tls_size);
2458 fprintf (stderr, DEBUG_FMT_D, "long_double_size",
2459 rs6000_long_double_type_size);
2460 fprintf (stderr, DEBUG_FMT_D, "sched_restricted_insns_priority",
2461 (int)rs6000_sched_restricted_insns_priority);
2462 fprintf (stderr, DEBUG_FMT_D, "Number of standard builtins",
2463 (int)END_BUILTINS);
2464 fprintf (stderr, DEBUG_FMT_D, "Number of rs6000 builtins",
2465 (int)RS6000_BUILTIN_COUNT);
2467 if (TARGET_VSX)
2468 fprintf (stderr, DEBUG_FMT_D, "VSX easy 64-bit scalar element",
2469 (int)VECTOR_ELEMENT_SCALAR_64BIT);
2473 /* Update the addr mask bits in reg_addr to help secondary reload and go if
2474 legitimate address support to figure out the appropriate addressing to
2475 use. */
2477 static void
2478 rs6000_setup_reg_addr_masks (void)
2480 ssize_t rc, reg, m, nregs;
2481 addr_mask_type any_addr_mask, addr_mask;
2483 for (m = 0; m < NUM_MACHINE_MODES; ++m)
2485 machine_mode m2 = (machine_mode)m;
2487 /* SDmode is special in that we want to access it only via REG+REG
2488 addressing on power7 and above, since we want to use the LFIWZX and
2489 STFIWZX instructions to load it. */
2490 bool indexed_only_p = (m == SDmode && TARGET_NO_SDMODE_STACK);
2492 any_addr_mask = 0;
2493 for (rc = FIRST_RELOAD_REG_CLASS; rc <= LAST_RELOAD_REG_CLASS; rc++)
2495 addr_mask = 0;
2496 reg = reload_reg_map[rc].reg;
2498 /* Can mode values go in the GPR/FPR/Altivec registers? */
2499 if (reg >= 0 && rs6000_hard_regno_mode_ok_p[m][reg])
2501 nregs = rs6000_hard_regno_nregs[m][reg];
2502 addr_mask |= RELOAD_REG_VALID;
2504 /* Indicate if the mode takes more than 1 physical register. If
2505 it takes a single register, indicate it can do REG+REG
2506 addressing. */
2507 if (nregs > 1 || m == BLKmode)
2508 addr_mask |= RELOAD_REG_MULTIPLE;
2509 else
2510 addr_mask |= RELOAD_REG_INDEXED;
2512 /* Figure out if we can do PRE_INC, PRE_DEC, or PRE_MODIFY
2513 addressing. Restrict addressing on SPE for 64-bit types
2514 because of the SUBREG hackery used to address 64-bit floats in
2515 '32-bit' GPRs. */
2517 if (TARGET_UPDATE
2518 && (rc == RELOAD_REG_GPR || rc == RELOAD_REG_FPR)
2519 && GET_MODE_SIZE (m2) <= 8
2520 && !VECTOR_MODE_P (m2)
2521 && !COMPLEX_MODE_P (m2)
2522 && !indexed_only_p
2523 && !(TARGET_E500_DOUBLE && GET_MODE_SIZE (m2) == 8))
2525 addr_mask |= RELOAD_REG_PRE_INCDEC;
2527 /* PRE_MODIFY is more restricted than PRE_INC/PRE_DEC in that
2528 we don't allow PRE_MODIFY for some multi-register
2529 operations. */
2530 switch (m)
2532 default:
2533 addr_mask |= RELOAD_REG_PRE_MODIFY;
2534 break;
2536 case DImode:
2537 if (TARGET_POWERPC64)
2538 addr_mask |= RELOAD_REG_PRE_MODIFY;
2539 break;
2541 case DFmode:
2542 case DDmode:
2543 if (TARGET_DF_INSN)
2544 addr_mask |= RELOAD_REG_PRE_MODIFY;
2545 break;
2550 /* GPR and FPR registers can do REG+OFFSET addressing, except
2551 possibly for SDmode. */
2552 if ((addr_mask != 0) && !indexed_only_p
2553 && (rc == RELOAD_REG_GPR || rc == RELOAD_REG_FPR))
2554 addr_mask |= RELOAD_REG_OFFSET;
2556 /* VMX registers can do (REG & -16) and ((REG+REG) & -16)
2557 addressing on 128-bit types. */
2558 if (rc == RELOAD_REG_VMX && GET_MODE_SIZE (m2) == 16
2559 && (addr_mask & RELOAD_REG_VALID) != 0)
2560 addr_mask |= RELOAD_REG_AND_M16;
2562 reg_addr[m].addr_mask[rc] = addr_mask;
2563 any_addr_mask |= addr_mask;
2566 reg_addr[m].addr_mask[RELOAD_REG_ANY] = any_addr_mask;
2571 /* Initialize the various global tables that are based on register size. */
2572 static void
2573 rs6000_init_hard_regno_mode_ok (bool global_init_p)
2575 ssize_t r, m, c;
2576 int align64;
2577 int align32;
2579 /* Precalculate REGNO_REG_CLASS. */
2580 rs6000_regno_regclass[0] = GENERAL_REGS;
2581 for (r = 1; r < 32; ++r)
2582 rs6000_regno_regclass[r] = BASE_REGS;
2584 for (r = 32; r < 64; ++r)
2585 rs6000_regno_regclass[r] = FLOAT_REGS;
2587 for (r = 64; r < FIRST_PSEUDO_REGISTER; ++r)
2588 rs6000_regno_regclass[r] = NO_REGS;
2590 for (r = FIRST_ALTIVEC_REGNO; r <= LAST_ALTIVEC_REGNO; ++r)
2591 rs6000_regno_regclass[r] = ALTIVEC_REGS;
2593 rs6000_regno_regclass[CR0_REGNO] = CR0_REGS;
2594 for (r = CR1_REGNO; r <= CR7_REGNO; ++r)
2595 rs6000_regno_regclass[r] = CR_REGS;
2597 rs6000_regno_regclass[LR_REGNO] = LINK_REGS;
2598 rs6000_regno_regclass[CTR_REGNO] = CTR_REGS;
2599 rs6000_regno_regclass[CA_REGNO] = NO_REGS;
2600 rs6000_regno_regclass[VRSAVE_REGNO] = VRSAVE_REGS;
2601 rs6000_regno_regclass[VSCR_REGNO] = VRSAVE_REGS;
2602 rs6000_regno_regclass[SPE_ACC_REGNO] = SPE_ACC_REGS;
2603 rs6000_regno_regclass[SPEFSCR_REGNO] = SPEFSCR_REGS;
2604 rs6000_regno_regclass[TFHAR_REGNO] = SPR_REGS;
2605 rs6000_regno_regclass[TFIAR_REGNO] = SPR_REGS;
2606 rs6000_regno_regclass[TEXASR_REGNO] = SPR_REGS;
2607 rs6000_regno_regclass[ARG_POINTER_REGNUM] = BASE_REGS;
2608 rs6000_regno_regclass[FRAME_POINTER_REGNUM] = BASE_REGS;
2610 /* Precalculate register class to simpler reload register class. We don't
2611 need all of the register classes that are combinations of different
2612 classes, just the simple ones that have constraint letters. */
2613 for (c = 0; c < N_REG_CLASSES; c++)
2614 reg_class_to_reg_type[c] = NO_REG_TYPE;
2616 reg_class_to_reg_type[(int)GENERAL_REGS] = GPR_REG_TYPE;
2617 reg_class_to_reg_type[(int)BASE_REGS] = GPR_REG_TYPE;
2618 reg_class_to_reg_type[(int)VSX_REGS] = VSX_REG_TYPE;
2619 reg_class_to_reg_type[(int)VRSAVE_REGS] = SPR_REG_TYPE;
2620 reg_class_to_reg_type[(int)VSCR_REGS] = SPR_REG_TYPE;
2621 reg_class_to_reg_type[(int)LINK_REGS] = SPR_REG_TYPE;
2622 reg_class_to_reg_type[(int)CTR_REGS] = SPR_REG_TYPE;
2623 reg_class_to_reg_type[(int)LINK_OR_CTR_REGS] = SPR_REG_TYPE;
2624 reg_class_to_reg_type[(int)CR_REGS] = CR_REG_TYPE;
2625 reg_class_to_reg_type[(int)CR0_REGS] = CR_REG_TYPE;
2626 reg_class_to_reg_type[(int)SPE_ACC_REGS] = SPE_ACC_TYPE;
2627 reg_class_to_reg_type[(int)SPEFSCR_REGS] = SPEFSCR_REG_TYPE;
2629 if (TARGET_VSX)
2631 reg_class_to_reg_type[(int)FLOAT_REGS] = VSX_REG_TYPE;
2632 reg_class_to_reg_type[(int)ALTIVEC_REGS] = VSX_REG_TYPE;
2634 else
2636 reg_class_to_reg_type[(int)FLOAT_REGS] = FPR_REG_TYPE;
2637 reg_class_to_reg_type[(int)ALTIVEC_REGS] = ALTIVEC_REG_TYPE;
2640 /* Precalculate the valid memory formats as well as the vector information,
2641 this must be set up before the rs6000_hard_regno_nregs_internal calls
2642 below. */
2643 gcc_assert ((int)VECTOR_NONE == 0);
2644 memset ((void *) &rs6000_vector_unit[0], '\0', sizeof (rs6000_vector_unit));
2645 memset ((void *) &rs6000_vector_mem[0], '\0', sizeof (rs6000_vector_unit));
2647 gcc_assert ((int)CODE_FOR_nothing == 0);
2648 memset ((void *) &reg_addr[0], '\0', sizeof (reg_addr));
2650 gcc_assert ((int)NO_REGS == 0);
2651 memset ((void *) &rs6000_constraints[0], '\0', sizeof (rs6000_constraints));
2653 /* The VSX hardware allows native alignment for vectors, but control whether the compiler
2654 believes it can use native alignment or still uses 128-bit alignment. */
2655 if (TARGET_VSX && !TARGET_VSX_ALIGN_128)
2657 align64 = 64;
2658 align32 = 32;
2660 else
2662 align64 = 128;
2663 align32 = 128;
2666 /* V2DF mode, VSX only. */
2667 if (TARGET_VSX)
2669 rs6000_vector_unit[V2DFmode] = VECTOR_VSX;
2670 rs6000_vector_mem[V2DFmode] = VECTOR_VSX;
2671 rs6000_vector_align[V2DFmode] = align64;
2674 /* V4SF mode, either VSX or Altivec. */
2675 if (TARGET_VSX)
2677 rs6000_vector_unit[V4SFmode] = VECTOR_VSX;
2678 rs6000_vector_mem[V4SFmode] = VECTOR_VSX;
2679 rs6000_vector_align[V4SFmode] = align32;
2681 else if (TARGET_ALTIVEC)
2683 rs6000_vector_unit[V4SFmode] = VECTOR_ALTIVEC;
2684 rs6000_vector_mem[V4SFmode] = VECTOR_ALTIVEC;
2685 rs6000_vector_align[V4SFmode] = align32;
2688 /* V16QImode, V8HImode, V4SImode are Altivec only, but possibly do VSX loads
2689 and stores. */
2690 if (TARGET_ALTIVEC)
2692 rs6000_vector_unit[V4SImode] = VECTOR_ALTIVEC;
2693 rs6000_vector_unit[V8HImode] = VECTOR_ALTIVEC;
2694 rs6000_vector_unit[V16QImode] = VECTOR_ALTIVEC;
2695 rs6000_vector_align[V4SImode] = align32;
2696 rs6000_vector_align[V8HImode] = align32;
2697 rs6000_vector_align[V16QImode] = align32;
2699 if (TARGET_VSX)
2701 rs6000_vector_mem[V4SImode] = VECTOR_VSX;
2702 rs6000_vector_mem[V8HImode] = VECTOR_VSX;
2703 rs6000_vector_mem[V16QImode] = VECTOR_VSX;
2705 else
2707 rs6000_vector_mem[V4SImode] = VECTOR_ALTIVEC;
2708 rs6000_vector_mem[V8HImode] = VECTOR_ALTIVEC;
2709 rs6000_vector_mem[V16QImode] = VECTOR_ALTIVEC;
2713 /* V2DImode, full mode depends on ISA 2.07 vector mode. Allow under VSX to
2714 do insert/splat/extract. Altivec doesn't have 64-bit integer support. */
2715 if (TARGET_VSX)
2717 rs6000_vector_mem[V2DImode] = VECTOR_VSX;
2718 rs6000_vector_unit[V2DImode]
2719 = (TARGET_P8_VECTOR) ? VECTOR_P8_VECTOR : VECTOR_NONE;
2720 rs6000_vector_align[V2DImode] = align64;
2722 rs6000_vector_mem[V1TImode] = VECTOR_VSX;
2723 rs6000_vector_unit[V1TImode]
2724 = (TARGET_P8_VECTOR) ? VECTOR_P8_VECTOR : VECTOR_NONE;
2725 rs6000_vector_align[V1TImode] = 128;
2728 /* DFmode, see if we want to use the VSX unit. Memory is handled
2729 differently, so don't set rs6000_vector_mem. */
2730 if (TARGET_VSX && TARGET_VSX_SCALAR_DOUBLE)
2732 rs6000_vector_unit[DFmode] = VECTOR_VSX;
2733 rs6000_vector_align[DFmode] = 64;
2736 /* SFmode, see if we want to use the VSX unit. */
2737 if (TARGET_P8_VECTOR && TARGET_VSX_SCALAR_FLOAT)
2739 rs6000_vector_unit[SFmode] = VECTOR_VSX;
2740 rs6000_vector_align[SFmode] = 32;
2743 /* Allow TImode in VSX register and set the VSX memory macros. */
2744 if (TARGET_VSX && TARGET_VSX_TIMODE)
2746 rs6000_vector_mem[TImode] = VECTOR_VSX;
2747 rs6000_vector_align[TImode] = align64;
2750 /* TODO add SPE and paired floating point vector support. */
2752 /* Register class constraints for the constraints that depend on compile
2753 switches. When the VSX code was added, different constraints were added
2754 based on the type (DFmode, V2DFmode, V4SFmode). For the vector types, all
2755 of the VSX registers are used. The register classes for scalar floating
2756 point types is set, based on whether we allow that type into the upper
2757 (Altivec) registers. GCC has register classes to target the Altivec
2758 registers for load/store operations, to select using a VSX memory
2759 operation instead of the traditional floating point operation. The
2760 constraints are:
2762 d - Register class to use with traditional DFmode instructions.
2763 f - Register class to use with traditional SFmode instructions.
2764 v - Altivec register.
2765 wa - Any VSX register.
2766 wc - Reserved to represent individual CR bits (used in LLVM).
2767 wd - Preferred register class for V2DFmode.
2768 wf - Preferred register class for V4SFmode.
2769 wg - Float register for power6x move insns.
2770 wh - FP register for direct move instructions.
2771 wi - FP or VSX register to hold 64-bit integers for VSX insns.
2772 wj - FP or VSX register to hold 64-bit integers for direct moves.
2773 wk - FP or VSX register to hold 64-bit doubles for direct moves.
2774 wl - Float register if we can do 32-bit signed int loads.
2775 wm - VSX register for ISA 2.07 direct move operations.
2776 wn - always NO_REGS.
2777 wr - GPR if 64-bit mode is permitted.
2778 ws - Register class to do ISA 2.06 DF operations.
2779 wt - VSX register for TImode in VSX registers.
2780 wu - Altivec register for ISA 2.07 VSX SF/SI load/stores.
2781 wv - Altivec register for ISA 2.06 VSX DF/DI load/stores.
2782 ww - Register class to do SF conversions in with VSX operations.
2783 wx - Float register if we can do 32-bit int stores.
2784 wy - Register class to do ISA 2.07 SF operations.
2785 wz - Float register if we can do 32-bit unsigned int loads. */
2787 if (TARGET_HARD_FLOAT && TARGET_FPRS)
2788 rs6000_constraints[RS6000_CONSTRAINT_f] = FLOAT_REGS; /* SFmode */
2790 if (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
2791 rs6000_constraints[RS6000_CONSTRAINT_d] = FLOAT_REGS; /* DFmode */
2793 if (TARGET_VSX)
2795 rs6000_constraints[RS6000_CONSTRAINT_wa] = VSX_REGS;
2796 rs6000_constraints[RS6000_CONSTRAINT_wd] = VSX_REGS; /* V2DFmode */
2797 rs6000_constraints[RS6000_CONSTRAINT_wf] = VSX_REGS; /* V4SFmode */
2798 rs6000_constraints[RS6000_CONSTRAINT_wi] = FLOAT_REGS; /* DImode */
2800 if (TARGET_VSX_TIMODE)
2801 rs6000_constraints[RS6000_CONSTRAINT_wt] = VSX_REGS; /* TImode */
2803 if (TARGET_UPPER_REGS_DF) /* DFmode */
2805 rs6000_constraints[RS6000_CONSTRAINT_ws] = VSX_REGS;
2806 rs6000_constraints[RS6000_CONSTRAINT_wv] = ALTIVEC_REGS;
2808 else
2809 rs6000_constraints[RS6000_CONSTRAINT_ws] = FLOAT_REGS;
2812 /* Add conditional constraints based on various options, to allow us to
2813 collapse multiple insn patterns. */
2814 if (TARGET_ALTIVEC)
2815 rs6000_constraints[RS6000_CONSTRAINT_v] = ALTIVEC_REGS;
2817 if (TARGET_MFPGPR) /* DFmode */
2818 rs6000_constraints[RS6000_CONSTRAINT_wg] = FLOAT_REGS;
2820 if (TARGET_LFIWAX)
2821 rs6000_constraints[RS6000_CONSTRAINT_wl] = FLOAT_REGS; /* DImode */
2823 if (TARGET_DIRECT_MOVE)
2825 rs6000_constraints[RS6000_CONSTRAINT_wh] = FLOAT_REGS;
2826 rs6000_constraints[RS6000_CONSTRAINT_wj] /* DImode */
2827 = rs6000_constraints[RS6000_CONSTRAINT_wi];
2828 rs6000_constraints[RS6000_CONSTRAINT_wk] /* DFmode */
2829 = rs6000_constraints[RS6000_CONSTRAINT_ws];
2830 rs6000_constraints[RS6000_CONSTRAINT_wm] = VSX_REGS;
2833 if (TARGET_POWERPC64)
2834 rs6000_constraints[RS6000_CONSTRAINT_wr] = GENERAL_REGS;
2836 if (TARGET_P8_VECTOR && TARGET_UPPER_REGS_SF) /* SFmode */
2838 rs6000_constraints[RS6000_CONSTRAINT_wu] = ALTIVEC_REGS;
2839 rs6000_constraints[RS6000_CONSTRAINT_wy] = VSX_REGS;
2840 rs6000_constraints[RS6000_CONSTRAINT_ww] = VSX_REGS;
2842 else if (TARGET_P8_VECTOR)
2844 rs6000_constraints[RS6000_CONSTRAINT_wy] = FLOAT_REGS;
2845 rs6000_constraints[RS6000_CONSTRAINT_ww] = FLOAT_REGS;
2847 else if (TARGET_VSX)
2848 rs6000_constraints[RS6000_CONSTRAINT_ww] = FLOAT_REGS;
2850 if (TARGET_STFIWX)
2851 rs6000_constraints[RS6000_CONSTRAINT_wx] = FLOAT_REGS; /* DImode */
2853 if (TARGET_LFIWZX)
2854 rs6000_constraints[RS6000_CONSTRAINT_wz] = FLOAT_REGS; /* DImode */
2856 /* Set up the reload helper and direct move functions. */
2857 if (TARGET_VSX || TARGET_ALTIVEC)
2859 if (TARGET_64BIT)
2861 reg_addr[V16QImode].reload_store = CODE_FOR_reload_v16qi_di_store;
2862 reg_addr[V16QImode].reload_load = CODE_FOR_reload_v16qi_di_load;
2863 reg_addr[V8HImode].reload_store = CODE_FOR_reload_v8hi_di_store;
2864 reg_addr[V8HImode].reload_load = CODE_FOR_reload_v8hi_di_load;
2865 reg_addr[V4SImode].reload_store = CODE_FOR_reload_v4si_di_store;
2866 reg_addr[V4SImode].reload_load = CODE_FOR_reload_v4si_di_load;
2867 reg_addr[V2DImode].reload_store = CODE_FOR_reload_v2di_di_store;
2868 reg_addr[V2DImode].reload_load = CODE_FOR_reload_v2di_di_load;
2869 reg_addr[V1TImode].reload_store = CODE_FOR_reload_v1ti_di_store;
2870 reg_addr[V1TImode].reload_load = CODE_FOR_reload_v1ti_di_load;
2871 reg_addr[V4SFmode].reload_store = CODE_FOR_reload_v4sf_di_store;
2872 reg_addr[V4SFmode].reload_load = CODE_FOR_reload_v4sf_di_load;
2873 reg_addr[V2DFmode].reload_store = CODE_FOR_reload_v2df_di_store;
2874 reg_addr[V2DFmode].reload_load = CODE_FOR_reload_v2df_di_load;
2875 reg_addr[DFmode].reload_store = CODE_FOR_reload_df_di_store;
2876 reg_addr[DFmode].reload_load = CODE_FOR_reload_df_di_load;
2877 reg_addr[DDmode].reload_store = CODE_FOR_reload_dd_di_store;
2878 reg_addr[DDmode].reload_load = CODE_FOR_reload_dd_di_load;
2879 reg_addr[SFmode].reload_store = CODE_FOR_reload_sf_di_store;
2880 reg_addr[SFmode].reload_load = CODE_FOR_reload_sf_di_load;
2882 /* Only provide a reload handler for SDmode if lfiwzx/stfiwx are
2883 available. */
2884 if (TARGET_NO_SDMODE_STACK)
2886 reg_addr[SDmode].reload_store = CODE_FOR_reload_sd_di_store;
2887 reg_addr[SDmode].reload_load = CODE_FOR_reload_sd_di_load;
2890 if (TARGET_VSX_TIMODE)
2892 reg_addr[TImode].reload_store = CODE_FOR_reload_ti_di_store;
2893 reg_addr[TImode].reload_load = CODE_FOR_reload_ti_di_load;
2896 if (TARGET_DIRECT_MOVE)
2898 reg_addr[TImode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxti;
2899 reg_addr[V1TImode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxv1ti;
2900 reg_addr[V2DFmode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxv2df;
2901 reg_addr[V2DImode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxv2di;
2902 reg_addr[V4SFmode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxv4sf;
2903 reg_addr[V4SImode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxv4si;
2904 reg_addr[V8HImode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxv8hi;
2905 reg_addr[V16QImode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxv16qi;
2906 reg_addr[SFmode].reload_gpr_vsx = CODE_FOR_reload_gpr_from_vsxsf;
2908 reg_addr[TImode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprti;
2909 reg_addr[V1TImode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprv1ti;
2910 reg_addr[V2DFmode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprv2df;
2911 reg_addr[V2DImode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprv2di;
2912 reg_addr[V4SFmode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprv4sf;
2913 reg_addr[V4SImode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprv4si;
2914 reg_addr[V8HImode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprv8hi;
2915 reg_addr[V16QImode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprv16qi;
2916 reg_addr[SFmode].reload_vsx_gpr = CODE_FOR_reload_vsx_from_gprsf;
2919 else
2921 reg_addr[V16QImode].reload_store = CODE_FOR_reload_v16qi_si_store;
2922 reg_addr[V16QImode].reload_load = CODE_FOR_reload_v16qi_si_load;
2923 reg_addr[V8HImode].reload_store = CODE_FOR_reload_v8hi_si_store;
2924 reg_addr[V8HImode].reload_load = CODE_FOR_reload_v8hi_si_load;
2925 reg_addr[V4SImode].reload_store = CODE_FOR_reload_v4si_si_store;
2926 reg_addr[V4SImode].reload_load = CODE_FOR_reload_v4si_si_load;
2927 reg_addr[V2DImode].reload_store = CODE_FOR_reload_v2di_si_store;
2928 reg_addr[V2DImode].reload_load = CODE_FOR_reload_v2di_si_load;
2929 reg_addr[V1TImode].reload_store = CODE_FOR_reload_v1ti_si_store;
2930 reg_addr[V1TImode].reload_load = CODE_FOR_reload_v1ti_si_load;
2931 reg_addr[V4SFmode].reload_store = CODE_FOR_reload_v4sf_si_store;
2932 reg_addr[V4SFmode].reload_load = CODE_FOR_reload_v4sf_si_load;
2933 reg_addr[V2DFmode].reload_store = CODE_FOR_reload_v2df_si_store;
2934 reg_addr[V2DFmode].reload_load = CODE_FOR_reload_v2df_si_load;
2935 reg_addr[DFmode].reload_store = CODE_FOR_reload_df_si_store;
2936 reg_addr[DFmode].reload_load = CODE_FOR_reload_df_si_load;
2937 reg_addr[DDmode].reload_store = CODE_FOR_reload_dd_si_store;
2938 reg_addr[DDmode].reload_load = CODE_FOR_reload_dd_si_load;
2939 reg_addr[SFmode].reload_store = CODE_FOR_reload_sf_si_store;
2940 reg_addr[SFmode].reload_load = CODE_FOR_reload_sf_si_load;
2942 /* Only provide a reload handler for SDmode if lfiwzx/stfiwx are
2943 available. */
2944 if (TARGET_NO_SDMODE_STACK)
2946 reg_addr[SDmode].reload_store = CODE_FOR_reload_sd_si_store;
2947 reg_addr[SDmode].reload_load = CODE_FOR_reload_sd_si_load;
2950 if (TARGET_VSX_TIMODE)
2952 reg_addr[TImode].reload_store = CODE_FOR_reload_ti_si_store;
2953 reg_addr[TImode].reload_load = CODE_FOR_reload_ti_si_load;
2956 if (TARGET_DIRECT_MOVE)
2958 reg_addr[DImode].reload_fpr_gpr = CODE_FOR_reload_fpr_from_gprdi;
2959 reg_addr[DDmode].reload_fpr_gpr = CODE_FOR_reload_fpr_from_gprdd;
2960 reg_addr[DFmode].reload_fpr_gpr = CODE_FOR_reload_fpr_from_gprdf;
2964 if (TARGET_UPPER_REGS_DF)
2965 reg_addr[DFmode].scalar_in_vmx_p = true;
2967 if (TARGET_UPPER_REGS_SF)
2968 reg_addr[SFmode].scalar_in_vmx_p = true;
2971 /* Precalculate HARD_REGNO_NREGS. */
2972 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
2973 for (m = 0; m < NUM_MACHINE_MODES; ++m)
2974 rs6000_hard_regno_nregs[m][r]
2975 = rs6000_hard_regno_nregs_internal (r, (machine_mode)m);
2977 /* Precalculate HARD_REGNO_MODE_OK. */
2978 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
2979 for (m = 0; m < NUM_MACHINE_MODES; ++m)
2980 if (rs6000_hard_regno_mode_ok (r, (machine_mode)m))
2981 rs6000_hard_regno_mode_ok_p[m][r] = true;
2983 /* Precalculate CLASS_MAX_NREGS sizes. */
2984 for (c = 0; c < LIM_REG_CLASSES; ++c)
2986 int reg_size;
2988 if (TARGET_VSX && VSX_REG_CLASS_P (c))
2989 reg_size = UNITS_PER_VSX_WORD;
2991 else if (c == ALTIVEC_REGS)
2992 reg_size = UNITS_PER_ALTIVEC_WORD;
2994 else if (c == FLOAT_REGS)
2995 reg_size = UNITS_PER_FP_WORD;
2997 else
2998 reg_size = UNITS_PER_WORD;
3000 for (m = 0; m < NUM_MACHINE_MODES; ++m)
3002 machine_mode m2 = (machine_mode)m;
3003 int reg_size2 = reg_size;
3005 /* TFmode/TDmode always takes 2 registers, even in VSX. */
3006 if (TARGET_VSX && VSX_REG_CLASS_P (c)
3007 && (m == TDmode || m == TFmode))
3008 reg_size2 = UNITS_PER_FP_WORD;
3010 rs6000_class_max_nregs[m][c]
3011 = (GET_MODE_SIZE (m2) + reg_size2 - 1) / reg_size2;
3015 if (TARGET_E500_DOUBLE)
3016 rs6000_class_max_nregs[DFmode][GENERAL_REGS] = 1;
3018 /* Calculate which modes to automatically generate code to use a the
3019 reciprocal divide and square root instructions. In the future, possibly
3020 automatically generate the instructions even if the user did not specify
3021 -mrecip. The older machines double precision reciprocal sqrt estimate is
3022 not accurate enough. */
3023 memset (rs6000_recip_bits, 0, sizeof (rs6000_recip_bits));
3024 if (TARGET_FRES)
3025 rs6000_recip_bits[SFmode] = RS6000_RECIP_MASK_HAVE_RE;
3026 if (TARGET_FRE)
3027 rs6000_recip_bits[DFmode] = RS6000_RECIP_MASK_HAVE_RE;
3028 if (VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode))
3029 rs6000_recip_bits[V4SFmode] = RS6000_RECIP_MASK_HAVE_RE;
3030 if (VECTOR_UNIT_VSX_P (V2DFmode))
3031 rs6000_recip_bits[V2DFmode] = RS6000_RECIP_MASK_HAVE_RE;
3033 if (TARGET_FRSQRTES)
3034 rs6000_recip_bits[SFmode] |= RS6000_RECIP_MASK_HAVE_RSQRTE;
3035 if (TARGET_FRSQRTE)
3036 rs6000_recip_bits[DFmode] |= RS6000_RECIP_MASK_HAVE_RSQRTE;
3037 if (VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode))
3038 rs6000_recip_bits[V4SFmode] |= RS6000_RECIP_MASK_HAVE_RSQRTE;
3039 if (VECTOR_UNIT_VSX_P (V2DFmode))
3040 rs6000_recip_bits[V2DFmode] |= RS6000_RECIP_MASK_HAVE_RSQRTE;
3042 if (rs6000_recip_control)
3044 if (!flag_finite_math_only)
3045 warning (0, "-mrecip requires -ffinite-math or -ffast-math");
3046 if (flag_trapping_math)
3047 warning (0, "-mrecip requires -fno-trapping-math or -ffast-math");
3048 if (!flag_reciprocal_math)
3049 warning (0, "-mrecip requires -freciprocal-math or -ffast-math");
3050 if (flag_finite_math_only && !flag_trapping_math && flag_reciprocal_math)
3052 if (RS6000_RECIP_HAVE_RE_P (SFmode)
3053 && (rs6000_recip_control & RECIP_SF_DIV) != 0)
3054 rs6000_recip_bits[SFmode] |= RS6000_RECIP_MASK_AUTO_RE;
3056 if (RS6000_RECIP_HAVE_RE_P (DFmode)
3057 && (rs6000_recip_control & RECIP_DF_DIV) != 0)
3058 rs6000_recip_bits[DFmode] |= RS6000_RECIP_MASK_AUTO_RE;
3060 if (RS6000_RECIP_HAVE_RE_P (V4SFmode)
3061 && (rs6000_recip_control & RECIP_V4SF_DIV) != 0)
3062 rs6000_recip_bits[V4SFmode] |= RS6000_RECIP_MASK_AUTO_RE;
3064 if (RS6000_RECIP_HAVE_RE_P (V2DFmode)
3065 && (rs6000_recip_control & RECIP_V2DF_DIV) != 0)
3066 rs6000_recip_bits[V2DFmode] |= RS6000_RECIP_MASK_AUTO_RE;
3068 if (RS6000_RECIP_HAVE_RSQRTE_P (SFmode)
3069 && (rs6000_recip_control & RECIP_SF_RSQRT) != 0)
3070 rs6000_recip_bits[SFmode] |= RS6000_RECIP_MASK_AUTO_RSQRTE;
3072 if (RS6000_RECIP_HAVE_RSQRTE_P (DFmode)
3073 && (rs6000_recip_control & RECIP_DF_RSQRT) != 0)
3074 rs6000_recip_bits[DFmode] |= RS6000_RECIP_MASK_AUTO_RSQRTE;
3076 if (RS6000_RECIP_HAVE_RSQRTE_P (V4SFmode)
3077 && (rs6000_recip_control & RECIP_V4SF_RSQRT) != 0)
3078 rs6000_recip_bits[V4SFmode] |= RS6000_RECIP_MASK_AUTO_RSQRTE;
3080 if (RS6000_RECIP_HAVE_RSQRTE_P (V2DFmode)
3081 && (rs6000_recip_control & RECIP_V2DF_RSQRT) != 0)
3082 rs6000_recip_bits[V2DFmode] |= RS6000_RECIP_MASK_AUTO_RSQRTE;
3086 /* Update the addr mask bits in reg_addr to help secondary reload and go if
3087 legitimate address support to figure out the appropriate addressing to
3088 use. */
3089 rs6000_setup_reg_addr_masks ();
3091 if (global_init_p || TARGET_DEBUG_TARGET)
3093 if (TARGET_DEBUG_REG)
3094 rs6000_debug_reg_global ();
3096 if (TARGET_DEBUG_COST || TARGET_DEBUG_REG)
3097 fprintf (stderr,
3098 "SImode variable mult cost = %d\n"
3099 "SImode constant mult cost = %d\n"
3100 "SImode short constant mult cost = %d\n"
3101 "DImode multipliciation cost = %d\n"
3102 "SImode division cost = %d\n"
3103 "DImode division cost = %d\n"
3104 "Simple fp operation cost = %d\n"
3105 "DFmode multiplication cost = %d\n"
3106 "SFmode division cost = %d\n"
3107 "DFmode division cost = %d\n"
3108 "cache line size = %d\n"
3109 "l1 cache size = %d\n"
3110 "l2 cache size = %d\n"
3111 "simultaneous prefetches = %d\n"
3112 "\n",
3113 rs6000_cost->mulsi,
3114 rs6000_cost->mulsi_const,
3115 rs6000_cost->mulsi_const9,
3116 rs6000_cost->muldi,
3117 rs6000_cost->divsi,
3118 rs6000_cost->divdi,
3119 rs6000_cost->fp,
3120 rs6000_cost->dmul,
3121 rs6000_cost->sdiv,
3122 rs6000_cost->ddiv,
3123 rs6000_cost->cache_line_size,
3124 rs6000_cost->l1_cache_size,
3125 rs6000_cost->l2_cache_size,
3126 rs6000_cost->simultaneous_prefetches);
3130 #if TARGET_MACHO
3131 /* The Darwin version of SUBTARGET_OVERRIDE_OPTIONS. */
3133 static void
3134 darwin_rs6000_override_options (void)
3136 /* The Darwin ABI always includes AltiVec, can't be (validly) turned
3137 off. */
3138 rs6000_altivec_abi = 1;
3139 TARGET_ALTIVEC_VRSAVE = 1;
3140 rs6000_current_abi = ABI_DARWIN;
3142 if (DEFAULT_ABI == ABI_DARWIN
3143 && TARGET_64BIT)
3144 darwin_one_byte_bool = 1;
3146 if (TARGET_64BIT && ! TARGET_POWERPC64)
3148 rs6000_isa_flags |= OPTION_MASK_POWERPC64;
3149 warning (0, "-m64 requires PowerPC64 architecture, enabling");
3151 if (flag_mkernel)
3153 rs6000_default_long_calls = 1;
3154 rs6000_isa_flags |= OPTION_MASK_SOFT_FLOAT;
3157 /* Make -m64 imply -maltivec. Darwin's 64-bit ABI includes
3158 Altivec. */
3159 if (!flag_mkernel && !flag_apple_kext
3160 && TARGET_64BIT
3161 && ! (rs6000_isa_flags_explicit & OPTION_MASK_ALTIVEC))
3162 rs6000_isa_flags |= OPTION_MASK_ALTIVEC;
3164 /* Unless the user (not the configurer) has explicitly overridden
3165 it with -mcpu=G3 or -mno-altivec, then 10.5+ targets default to
3166 G4 unless targeting the kernel. */
3167 if (!flag_mkernel
3168 && !flag_apple_kext
3169 && strverscmp (darwin_macosx_version_min, "10.5") >= 0
3170 && ! (rs6000_isa_flags_explicit & OPTION_MASK_ALTIVEC)
3171 && ! global_options_set.x_rs6000_cpu_index)
3173 rs6000_isa_flags |= OPTION_MASK_ALTIVEC;
3176 #endif
3178 /* If not otherwise specified by a target, make 'long double' equivalent to
3179 'double'. */
3181 #ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
3182 #define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
3183 #endif
3185 /* Return the builtin mask of the various options used that could affect which
3186 builtins were used. In the past we used target_flags, but we've run out of
3187 bits, and some options like SPE and PAIRED are no longer in
3188 target_flags. */
3190 HOST_WIDE_INT
3191 rs6000_builtin_mask_calculate (void)
3193 return (((TARGET_ALTIVEC) ? RS6000_BTM_ALTIVEC : 0)
3194 | ((TARGET_VSX) ? RS6000_BTM_VSX : 0)
3195 | ((TARGET_SPE) ? RS6000_BTM_SPE : 0)
3196 | ((TARGET_PAIRED_FLOAT) ? RS6000_BTM_PAIRED : 0)
3197 | ((TARGET_FRE) ? RS6000_BTM_FRE : 0)
3198 | ((TARGET_FRES) ? RS6000_BTM_FRES : 0)
3199 | ((TARGET_FRSQRTE) ? RS6000_BTM_FRSQRTE : 0)
3200 | ((TARGET_FRSQRTES) ? RS6000_BTM_FRSQRTES : 0)
3201 | ((TARGET_POPCNTD) ? RS6000_BTM_POPCNTD : 0)
3202 | ((rs6000_cpu == PROCESSOR_CELL) ? RS6000_BTM_CELL : 0)
3203 | ((TARGET_P8_VECTOR) ? RS6000_BTM_P8_VECTOR : 0)
3204 | ((TARGET_CRYPTO) ? RS6000_BTM_CRYPTO : 0)
3205 | ((TARGET_HTM) ? RS6000_BTM_HTM : 0)
3206 | ((TARGET_DFP) ? RS6000_BTM_DFP : 0)
3207 | ((TARGET_HARD_FLOAT) ? RS6000_BTM_HARD_FLOAT : 0)
3208 | ((TARGET_LONG_DOUBLE_128) ? RS6000_BTM_LDBL128 : 0));
3211 /* Implement TARGET_MD_ASM_ADJUST. All asm statements are considered
3212 to clobber the XER[CA] bit because clobbering that bit without telling
3213 the compiler worked just fine with versions of GCC before GCC 5, and
3214 breaking a lot of older code in ways that are hard to track down is
3215 not such a great idea. */
3217 static rtx_insn *
3218 rs6000_md_asm_adjust (vec<rtx> &/*outputs*/, vec<rtx> &/*inputs*/,
3219 vec<const char *> &/*constraints*/,
3220 vec<rtx> &clobbers, HARD_REG_SET &clobbered_regs)
3222 clobbers.safe_push (gen_rtx_REG (SImode, CA_REGNO));
3223 SET_HARD_REG_BIT (clobbered_regs, CA_REGNO);
3224 return NULL;
3227 /* Override command line options. Mostly we process the processor type and
3228 sometimes adjust other TARGET_ options. */
3230 static bool
3231 rs6000_option_override_internal (bool global_init_p)
3233 bool ret = true;
3234 bool have_cpu = false;
3236 /* The default cpu requested at configure time, if any. */
3237 const char *implicit_cpu = OPTION_TARGET_CPU_DEFAULT;
3239 HOST_WIDE_INT set_masks;
3240 int cpu_index;
3241 int tune_index;
3242 struct cl_target_option *main_target_opt
3243 = ((global_init_p || target_option_default_node == NULL)
3244 ? NULL : TREE_TARGET_OPTION (target_option_default_node));
3246 /* Print defaults. */
3247 if ((TARGET_DEBUG_REG || TARGET_DEBUG_TARGET) && global_init_p)
3248 rs6000_print_isa_options (stderr, 0, "TARGET_DEFAULT", TARGET_DEFAULT);
3250 /* Remember the explicit arguments. */
3251 if (global_init_p)
3252 rs6000_isa_flags_explicit = global_options_set.x_rs6000_isa_flags;
3254 /* On 64-bit Darwin, power alignment is ABI-incompatible with some C
3255 library functions, so warn about it. The flag may be useful for
3256 performance studies from time to time though, so don't disable it
3257 entirely. */
3258 if (global_options_set.x_rs6000_alignment_flags
3259 && rs6000_alignment_flags == MASK_ALIGN_POWER
3260 && DEFAULT_ABI == ABI_DARWIN
3261 && TARGET_64BIT)
3262 warning (0, "-malign-power is not supported for 64-bit Darwin;"
3263 " it is incompatible with the installed C and C++ libraries");
3265 /* Numerous experiment shows that IRA based loop pressure
3266 calculation works better for RTL loop invariant motion on targets
3267 with enough (>= 32) registers. It is an expensive optimization.
3268 So it is on only for peak performance. */
3269 if (optimize >= 3 && global_init_p
3270 && !global_options_set.x_flag_ira_loop_pressure)
3271 flag_ira_loop_pressure = 1;
3273 /* Set the pointer size. */
3274 if (TARGET_64BIT)
3276 rs6000_pmode = (int)DImode;
3277 rs6000_pointer_size = 64;
3279 else
3281 rs6000_pmode = (int)SImode;
3282 rs6000_pointer_size = 32;
3285 /* Some OSs don't support saving the high part of 64-bit registers on context
3286 switch. Other OSs don't support saving Altivec registers. On those OSs,
3287 we don't touch the OPTION_MASK_POWERPC64 or OPTION_MASK_ALTIVEC settings;
3288 if the user wants either, the user must explicitly specify them and we
3289 won't interfere with the user's specification. */
3291 set_masks = POWERPC_MASKS;
3292 #ifdef OS_MISSING_POWERPC64
3293 if (OS_MISSING_POWERPC64)
3294 set_masks &= ~OPTION_MASK_POWERPC64;
3295 #endif
3296 #ifdef OS_MISSING_ALTIVEC
3297 if (OS_MISSING_ALTIVEC)
3298 set_masks &= ~(OPTION_MASK_ALTIVEC | OPTION_MASK_VSX);
3299 #endif
3301 /* Don't override by the processor default if given explicitly. */
3302 set_masks &= ~rs6000_isa_flags_explicit;
3304 /* Process the -mcpu=<xxx> and -mtune=<xxx> argument. If the user changed
3305 the cpu in a target attribute or pragma, but did not specify a tuning
3306 option, use the cpu for the tuning option rather than the option specified
3307 with -mtune on the command line. Process a '--with-cpu' configuration
3308 request as an implicit --cpu. */
3309 if (rs6000_cpu_index >= 0)
3311 cpu_index = rs6000_cpu_index;
3312 have_cpu = true;
3314 else if (main_target_opt != NULL && main_target_opt->x_rs6000_cpu_index >= 0)
3316 rs6000_cpu_index = cpu_index = main_target_opt->x_rs6000_cpu_index;
3317 have_cpu = true;
3319 else if (implicit_cpu)
3321 rs6000_cpu_index = cpu_index = rs6000_cpu_name_lookup (implicit_cpu);
3322 have_cpu = true;
3324 else
3326 /* PowerPC 64-bit LE requires at least ISA 2.07. */
3327 const char *default_cpu = ((!TARGET_POWERPC64)
3328 ? "powerpc"
3329 : ((BYTES_BIG_ENDIAN)
3330 ? "powerpc64"
3331 : "powerpc64le"));
3333 rs6000_cpu_index = cpu_index = rs6000_cpu_name_lookup (default_cpu);
3334 have_cpu = false;
3337 gcc_assert (cpu_index >= 0);
3339 /* If we have a cpu, either through an explicit -mcpu=<xxx> or if the
3340 compiler was configured with --with-cpu=<xxx>, replace all of the ISA bits
3341 with those from the cpu, except for options that were explicitly set. If
3342 we don't have a cpu, do not override the target bits set in
3343 TARGET_DEFAULT. */
3344 if (have_cpu)
3346 rs6000_isa_flags &= ~set_masks;
3347 rs6000_isa_flags |= (processor_target_table[cpu_index].target_enable
3348 & set_masks);
3350 else
3352 /* If no -mcpu=<xxx>, inherit any default options that were cleared via
3353 POWERPC_MASKS. Originally, TARGET_DEFAULT was used to initialize
3354 target_flags via the TARGET_DEFAULT_TARGET_FLAGS hook. When we switched
3355 to using rs6000_isa_flags, we need to do the initialization here.
3357 If there is a TARGET_DEFAULT, use that. Otherwise fall back to using
3358 -mcpu=powerpc, -mcpu=powerpc64, or -mcpu=powerpc64le defaults. */
3359 HOST_WIDE_INT flags = ((TARGET_DEFAULT) ? TARGET_DEFAULT
3360 : processor_target_table[cpu_index].target_enable);
3361 rs6000_isa_flags |= (flags & ~rs6000_isa_flags_explicit);
3364 if (rs6000_tune_index >= 0)
3365 tune_index = rs6000_tune_index;
3366 else if (have_cpu)
3367 rs6000_tune_index = tune_index = cpu_index;
3368 else
3370 size_t i;
3371 enum processor_type tune_proc
3372 = (TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT);
3374 tune_index = -1;
3375 for (i = 0; i < ARRAY_SIZE (processor_target_table); i++)
3376 if (processor_target_table[i].processor == tune_proc)
3378 rs6000_tune_index = tune_index = i;
3379 break;
3383 gcc_assert (tune_index >= 0);
3384 rs6000_cpu = processor_target_table[tune_index].processor;
3386 /* Pick defaults for SPE related control flags. Do this early to make sure
3387 that the TARGET_ macros are representative ASAP. */
3389 int spe_capable_cpu =
3390 (rs6000_cpu == PROCESSOR_PPC8540
3391 || rs6000_cpu == PROCESSOR_PPC8548);
3393 if (!global_options_set.x_rs6000_spe_abi)
3394 rs6000_spe_abi = spe_capable_cpu;
3396 if (!global_options_set.x_rs6000_spe)
3397 rs6000_spe = spe_capable_cpu;
3399 if (!global_options_set.x_rs6000_float_gprs)
3400 rs6000_float_gprs =
3401 (rs6000_cpu == PROCESSOR_PPC8540 ? 1
3402 : rs6000_cpu == PROCESSOR_PPC8548 ? 2
3403 : 0);
3406 if (global_options_set.x_rs6000_spe_abi
3407 && rs6000_spe_abi
3408 && !TARGET_SPE_ABI)
3409 error ("not configured for SPE ABI");
3411 if (global_options_set.x_rs6000_spe
3412 && rs6000_spe
3413 && !TARGET_SPE)
3414 error ("not configured for SPE instruction set");
3416 if (main_target_opt != NULL
3417 && ((main_target_opt->x_rs6000_spe_abi != rs6000_spe_abi)
3418 || (main_target_opt->x_rs6000_spe != rs6000_spe)
3419 || (main_target_opt->x_rs6000_float_gprs != rs6000_float_gprs)))
3420 error ("target attribute or pragma changes SPE ABI");
3422 if (rs6000_cpu == PROCESSOR_PPCE300C2 || rs6000_cpu == PROCESSOR_PPCE300C3
3423 || rs6000_cpu == PROCESSOR_PPCE500MC || rs6000_cpu == PROCESSOR_PPCE500MC64
3424 || rs6000_cpu == PROCESSOR_PPCE5500)
3426 if (TARGET_ALTIVEC)
3427 error ("AltiVec not supported in this target");
3428 if (TARGET_SPE)
3429 error ("SPE not supported in this target");
3431 if (rs6000_cpu == PROCESSOR_PPCE6500)
3433 if (TARGET_SPE)
3434 error ("SPE not supported in this target");
3437 /* Disable Cell microcode if we are optimizing for the Cell
3438 and not optimizing for size. */
3439 if (rs6000_gen_cell_microcode == -1)
3440 rs6000_gen_cell_microcode = !(rs6000_cpu == PROCESSOR_CELL
3441 && !optimize_size);
3443 /* If we are optimizing big endian systems for space and it's OK to
3444 use instructions that would be microcoded on the Cell, use the
3445 load/store multiple and string instructions. */
3446 if (BYTES_BIG_ENDIAN && optimize_size && rs6000_gen_cell_microcode)
3447 rs6000_isa_flags |= ~rs6000_isa_flags_explicit & (OPTION_MASK_MULTIPLE
3448 | OPTION_MASK_STRING);
3450 /* Don't allow -mmultiple or -mstring on little endian systems
3451 unless the cpu is a 750, because the hardware doesn't support the
3452 instructions used in little endian mode, and causes an alignment
3453 trap. The 750 does not cause an alignment trap (except when the
3454 target is unaligned). */
3456 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
3458 if (TARGET_MULTIPLE)
3460 rs6000_isa_flags &= ~OPTION_MASK_MULTIPLE;
3461 if ((rs6000_isa_flags_explicit & OPTION_MASK_MULTIPLE) != 0)
3462 warning (0, "-mmultiple is not supported on little endian systems");
3465 if (TARGET_STRING)
3467 rs6000_isa_flags &= ~OPTION_MASK_STRING;
3468 if ((rs6000_isa_flags_explicit & OPTION_MASK_STRING) != 0)
3469 warning (0, "-mstring is not supported on little endian systems");
3473 /* If little-endian, default to -mstrict-align on older processors.
3474 Testing for htm matches power8 and later. */
3475 if (!BYTES_BIG_ENDIAN
3476 && !(processor_target_table[tune_index].target_enable & OPTION_MASK_HTM))
3477 rs6000_isa_flags |= ~rs6000_isa_flags_explicit & OPTION_MASK_STRICT_ALIGN;
3479 /* -maltivec={le,be} implies -maltivec. */
3480 if (rs6000_altivec_element_order != 0)
3481 rs6000_isa_flags |= OPTION_MASK_ALTIVEC;
3483 /* Disallow -maltivec=le in big endian mode for now. This is not
3484 known to be useful for anyone. */
3485 if (BYTES_BIG_ENDIAN && rs6000_altivec_element_order == 1)
3487 warning (0, N_("-maltivec=le not allowed for big-endian targets"));
3488 rs6000_altivec_element_order = 0;
3491 /* Add some warnings for VSX. */
3492 if (TARGET_VSX)
3494 const char *msg = NULL;
3495 if (!TARGET_HARD_FLOAT || !TARGET_FPRS
3496 || !TARGET_SINGLE_FLOAT || !TARGET_DOUBLE_FLOAT)
3498 if (rs6000_isa_flags_explicit & OPTION_MASK_VSX)
3499 msg = N_("-mvsx requires hardware floating point");
3500 else
3502 rs6000_isa_flags &= ~ OPTION_MASK_VSX;
3503 rs6000_isa_flags_explicit |= OPTION_MASK_VSX;
3506 else if (TARGET_PAIRED_FLOAT)
3507 msg = N_("-mvsx and -mpaired are incompatible");
3508 else if (TARGET_AVOID_XFORM > 0)
3509 msg = N_("-mvsx needs indexed addressing");
3510 else if (!TARGET_ALTIVEC && (rs6000_isa_flags_explicit
3511 & OPTION_MASK_ALTIVEC))
3513 if (rs6000_isa_flags_explicit & OPTION_MASK_VSX)
3514 msg = N_("-mvsx and -mno-altivec are incompatible");
3515 else
3516 msg = N_("-mno-altivec disables vsx");
3519 if (msg)
3521 warning (0, msg);
3522 rs6000_isa_flags &= ~ OPTION_MASK_VSX;
3523 rs6000_isa_flags_explicit |= OPTION_MASK_VSX;
3527 /* If hard-float/altivec/vsx were explicitly turned off then don't allow
3528 the -mcpu setting to enable options that conflict. */
3529 if ((!TARGET_HARD_FLOAT || !TARGET_ALTIVEC || !TARGET_VSX)
3530 && (rs6000_isa_flags_explicit & (OPTION_MASK_SOFT_FLOAT
3531 | OPTION_MASK_ALTIVEC
3532 | OPTION_MASK_VSX)) != 0)
3533 rs6000_isa_flags &= ~((OPTION_MASK_P8_VECTOR | OPTION_MASK_CRYPTO
3534 | OPTION_MASK_DIRECT_MOVE)
3535 & ~rs6000_isa_flags_explicit);
3537 if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET)
3538 rs6000_print_isa_options (stderr, 0, "before defaults", rs6000_isa_flags);
3540 /* For the newer switches (vsx, dfp, etc.) set some of the older options,
3541 unless the user explicitly used the -mno-<option> to disable the code. */
3542 if (TARGET_P8_VECTOR || TARGET_DIRECT_MOVE || TARGET_CRYPTO)
3543 rs6000_isa_flags |= (ISA_2_7_MASKS_SERVER & ~rs6000_isa_flags_explicit);
3544 else if (TARGET_VSX)
3545 rs6000_isa_flags |= (ISA_2_6_MASKS_SERVER & ~rs6000_isa_flags_explicit);
3546 else if (TARGET_POPCNTD)
3547 rs6000_isa_flags |= (ISA_2_6_MASKS_EMBEDDED & ~rs6000_isa_flags_explicit);
3548 else if (TARGET_DFP)
3549 rs6000_isa_flags |= (ISA_2_5_MASKS_SERVER & ~rs6000_isa_flags_explicit);
3550 else if (TARGET_CMPB)
3551 rs6000_isa_flags |= (ISA_2_5_MASKS_EMBEDDED & ~rs6000_isa_flags_explicit);
3552 else if (TARGET_FPRND)
3553 rs6000_isa_flags |= (ISA_2_4_MASKS & ~rs6000_isa_flags_explicit);
3554 else if (TARGET_POPCNTB)
3555 rs6000_isa_flags |= (ISA_2_2_MASKS & ~rs6000_isa_flags_explicit);
3556 else if (TARGET_ALTIVEC)
3557 rs6000_isa_flags |= (OPTION_MASK_PPC_GFXOPT & ~rs6000_isa_flags_explicit);
3559 if (TARGET_CRYPTO && !TARGET_ALTIVEC)
3561 if (rs6000_isa_flags_explicit & OPTION_MASK_CRYPTO)
3562 error ("-mcrypto requires -maltivec");
3563 rs6000_isa_flags &= ~OPTION_MASK_CRYPTO;
3566 if (TARGET_DIRECT_MOVE && !TARGET_VSX)
3568 if (rs6000_isa_flags_explicit & OPTION_MASK_DIRECT_MOVE)
3569 error ("-mdirect-move requires -mvsx");
3570 rs6000_isa_flags &= ~OPTION_MASK_DIRECT_MOVE;
3573 if (TARGET_P8_VECTOR && !TARGET_ALTIVEC)
3575 if (rs6000_isa_flags_explicit & OPTION_MASK_P8_VECTOR)
3576 error ("-mpower8-vector requires -maltivec");
3577 rs6000_isa_flags &= ~OPTION_MASK_P8_VECTOR;
3580 if (TARGET_P8_VECTOR && !TARGET_VSX)
3582 if (rs6000_isa_flags_explicit & OPTION_MASK_P8_VECTOR)
3583 error ("-mpower8-vector requires -mvsx");
3584 rs6000_isa_flags &= ~OPTION_MASK_P8_VECTOR;
3587 if (TARGET_VSX_TIMODE && !TARGET_VSX)
3589 if (rs6000_isa_flags_explicit & OPTION_MASK_VSX_TIMODE)
3590 error ("-mvsx-timode requires -mvsx");
3591 rs6000_isa_flags &= ~OPTION_MASK_VSX_TIMODE;
3594 if (TARGET_DFP && !TARGET_HARD_FLOAT)
3596 if (rs6000_isa_flags_explicit & OPTION_MASK_DFP)
3597 error ("-mhard-dfp requires -mhard-float");
3598 rs6000_isa_flags &= ~OPTION_MASK_DFP;
3601 /* Allow an explicit -mupper-regs to set both -mupper-regs-df and
3602 -mupper-regs-sf, depending on the cpu, unless the user explicitly also set
3603 the individual option. */
3604 if (TARGET_UPPER_REGS > 0)
3606 if (TARGET_VSX
3607 && !(rs6000_isa_flags_explicit & OPTION_MASK_UPPER_REGS_DF))
3609 rs6000_isa_flags |= OPTION_MASK_UPPER_REGS_DF;
3610 rs6000_isa_flags_explicit |= OPTION_MASK_UPPER_REGS_DF;
3612 if (TARGET_P8_VECTOR
3613 && !(rs6000_isa_flags_explicit & OPTION_MASK_UPPER_REGS_SF))
3615 rs6000_isa_flags |= OPTION_MASK_UPPER_REGS_SF;
3616 rs6000_isa_flags_explicit |= OPTION_MASK_UPPER_REGS_SF;
3619 else if (TARGET_UPPER_REGS == 0)
3621 if (TARGET_VSX
3622 && !(rs6000_isa_flags_explicit & OPTION_MASK_UPPER_REGS_DF))
3624 rs6000_isa_flags &= ~OPTION_MASK_UPPER_REGS_DF;
3625 rs6000_isa_flags_explicit |= OPTION_MASK_UPPER_REGS_DF;
3627 if (TARGET_P8_VECTOR
3628 && !(rs6000_isa_flags_explicit & OPTION_MASK_UPPER_REGS_SF))
3630 rs6000_isa_flags &= ~OPTION_MASK_UPPER_REGS_SF;
3631 rs6000_isa_flags_explicit |= OPTION_MASK_UPPER_REGS_SF;
3635 if (TARGET_UPPER_REGS_DF && !TARGET_VSX)
3637 if (rs6000_isa_flags_explicit & OPTION_MASK_UPPER_REGS_DF)
3638 error ("-mupper-regs-df requires -mvsx");
3639 rs6000_isa_flags &= ~OPTION_MASK_UPPER_REGS_DF;
3642 if (TARGET_UPPER_REGS_SF && !TARGET_P8_VECTOR)
3644 if (rs6000_isa_flags_explicit & OPTION_MASK_UPPER_REGS_SF)
3645 error ("-mupper-regs-sf requires -mpower8-vector");
3646 rs6000_isa_flags &= ~OPTION_MASK_UPPER_REGS_SF;
3649 /* The quad memory instructions only works in 64-bit mode. In 32-bit mode,
3650 silently turn off quad memory mode. */
3651 if ((TARGET_QUAD_MEMORY || TARGET_QUAD_MEMORY_ATOMIC) && !TARGET_POWERPC64)
3653 if ((rs6000_isa_flags_explicit & OPTION_MASK_QUAD_MEMORY) != 0)
3654 warning (0, N_("-mquad-memory requires 64-bit mode"));
3656 if ((rs6000_isa_flags_explicit & OPTION_MASK_QUAD_MEMORY_ATOMIC) != 0)
3657 warning (0, N_("-mquad-memory-atomic requires 64-bit mode"));
3659 rs6000_isa_flags &= ~(OPTION_MASK_QUAD_MEMORY
3660 | OPTION_MASK_QUAD_MEMORY_ATOMIC);
3663 /* Non-atomic quad memory load/store are disabled for little endian, since
3664 the words are reversed, but atomic operations can still be done by
3665 swapping the words. */
3666 if (TARGET_QUAD_MEMORY && !WORDS_BIG_ENDIAN)
3668 if ((rs6000_isa_flags_explicit & OPTION_MASK_QUAD_MEMORY) != 0)
3669 warning (0, N_("-mquad-memory is not available in little endian mode"));
3671 rs6000_isa_flags &= ~OPTION_MASK_QUAD_MEMORY;
3674 /* Assume if the user asked for normal quad memory instructions, they want
3675 the atomic versions as well, unless they explicity told us not to use quad
3676 word atomic instructions. */
3677 if (TARGET_QUAD_MEMORY
3678 && !TARGET_QUAD_MEMORY_ATOMIC
3679 && ((rs6000_isa_flags_explicit & OPTION_MASK_QUAD_MEMORY_ATOMIC) == 0))
3680 rs6000_isa_flags |= OPTION_MASK_QUAD_MEMORY_ATOMIC;
3682 /* Enable power8 fusion if we are tuning for power8, even if we aren't
3683 generating power8 instructions. */
3684 if (!(rs6000_isa_flags_explicit & OPTION_MASK_P8_FUSION))
3685 rs6000_isa_flags |= (processor_target_table[tune_index].target_enable
3686 & OPTION_MASK_P8_FUSION);
3688 /* Power8 does not fuse sign extended loads with the addis. If we are
3689 optimizing at high levels for speed, convert a sign extended load into a
3690 zero extending load, and an explicit sign extension. */
3691 if (TARGET_P8_FUSION
3692 && !(rs6000_isa_flags_explicit & OPTION_MASK_P8_FUSION_SIGN)
3693 && optimize_function_for_speed_p (cfun)
3694 && optimize >= 3)
3695 rs6000_isa_flags |= OPTION_MASK_P8_FUSION_SIGN;
3697 if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET)
3698 rs6000_print_isa_options (stderr, 0, "after defaults", rs6000_isa_flags);
3700 /* E500mc does "better" if we inline more aggressively. Respect the
3701 user's opinion, though. */
3702 if (rs6000_block_move_inline_limit == 0
3703 && (rs6000_cpu == PROCESSOR_PPCE500MC
3704 || rs6000_cpu == PROCESSOR_PPCE500MC64
3705 || rs6000_cpu == PROCESSOR_PPCE5500
3706 || rs6000_cpu == PROCESSOR_PPCE6500))
3707 rs6000_block_move_inline_limit = 128;
3709 /* store_one_arg depends on expand_block_move to handle at least the
3710 size of reg_parm_stack_space. */
3711 if (rs6000_block_move_inline_limit < (TARGET_POWERPC64 ? 64 : 32))
3712 rs6000_block_move_inline_limit = (TARGET_POWERPC64 ? 64 : 32);
3714 if (global_init_p)
3716 /* If the appropriate debug option is enabled, replace the target hooks
3717 with debug versions that call the real version and then prints
3718 debugging information. */
3719 if (TARGET_DEBUG_COST)
3721 targetm.rtx_costs = rs6000_debug_rtx_costs;
3722 targetm.address_cost = rs6000_debug_address_cost;
3723 targetm.sched.adjust_cost = rs6000_debug_adjust_cost;
3726 if (TARGET_DEBUG_ADDR)
3728 targetm.legitimate_address_p = rs6000_debug_legitimate_address_p;
3729 targetm.legitimize_address = rs6000_debug_legitimize_address;
3730 rs6000_secondary_reload_class_ptr
3731 = rs6000_debug_secondary_reload_class;
3732 rs6000_secondary_memory_needed_ptr
3733 = rs6000_debug_secondary_memory_needed;
3734 rs6000_cannot_change_mode_class_ptr
3735 = rs6000_debug_cannot_change_mode_class;
3736 rs6000_preferred_reload_class_ptr
3737 = rs6000_debug_preferred_reload_class;
3738 rs6000_legitimize_reload_address_ptr
3739 = rs6000_debug_legitimize_reload_address;
3740 rs6000_mode_dependent_address_ptr
3741 = rs6000_debug_mode_dependent_address;
3744 if (rs6000_veclibabi_name)
3746 if (strcmp (rs6000_veclibabi_name, "mass") == 0)
3747 rs6000_veclib_handler = rs6000_builtin_vectorized_libmass;
3748 else
3750 error ("unknown vectorization library ABI type (%s) for "
3751 "-mveclibabi= switch", rs6000_veclibabi_name);
3752 ret = false;
3757 if (!global_options_set.x_rs6000_long_double_type_size)
3759 if (main_target_opt != NULL
3760 && (main_target_opt->x_rs6000_long_double_type_size
3761 != RS6000_DEFAULT_LONG_DOUBLE_SIZE))
3762 error ("target attribute or pragma changes long double size");
3763 else
3764 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
3767 #if !defined (POWERPC_LINUX) && !defined (POWERPC_FREEBSD)
3768 if (!global_options_set.x_rs6000_ieeequad)
3769 rs6000_ieeequad = 1;
3770 #endif
3772 /* Disable VSX and Altivec silently if the user switched cpus to power7 in a
3773 target attribute or pragma which automatically enables both options,
3774 unless the altivec ABI was set. This is set by default for 64-bit, but
3775 not for 32-bit. */
3776 if (main_target_opt != NULL && !main_target_opt->x_rs6000_altivec_abi)
3777 rs6000_isa_flags &= ~((OPTION_MASK_VSX | OPTION_MASK_ALTIVEC)
3778 & ~rs6000_isa_flags_explicit);
3780 /* Enable Altivec ABI for AIX -maltivec. */
3781 if (TARGET_XCOFF && (TARGET_ALTIVEC || TARGET_VSX))
3783 if (main_target_opt != NULL && !main_target_opt->x_rs6000_altivec_abi)
3784 error ("target attribute or pragma changes AltiVec ABI");
3785 else
3786 rs6000_altivec_abi = 1;
3789 /* The AltiVec ABI is the default for PowerPC-64 GNU/Linux. For
3790 PowerPC-32 GNU/Linux, -maltivec implies the AltiVec ABI. It can
3791 be explicitly overridden in either case. */
3792 if (TARGET_ELF)
3794 if (!global_options_set.x_rs6000_altivec_abi
3795 && (TARGET_64BIT || TARGET_ALTIVEC || TARGET_VSX))
3797 if (main_target_opt != NULL &&
3798 !main_target_opt->x_rs6000_altivec_abi)
3799 error ("target attribute or pragma changes AltiVec ABI");
3800 else
3801 rs6000_altivec_abi = 1;
3805 /* Set the Darwin64 ABI as default for 64-bit Darwin.
3806 So far, the only darwin64 targets are also MACH-O. */
3807 if (TARGET_MACHO
3808 && DEFAULT_ABI == ABI_DARWIN
3809 && TARGET_64BIT)
3811 if (main_target_opt != NULL && !main_target_opt->x_rs6000_darwin64_abi)
3812 error ("target attribute or pragma changes darwin64 ABI");
3813 else
3815 rs6000_darwin64_abi = 1;
3816 /* Default to natural alignment, for better performance. */
3817 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
3821 /* Place FP constants in the constant pool instead of TOC
3822 if section anchors enabled. */
3823 if (flag_section_anchors
3824 && !global_options_set.x_TARGET_NO_FP_IN_TOC)
3825 TARGET_NO_FP_IN_TOC = 1;
3827 if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET)
3828 rs6000_print_isa_options (stderr, 0, "before subtarget", rs6000_isa_flags);
3830 #ifdef SUBTARGET_OVERRIDE_OPTIONS
3831 SUBTARGET_OVERRIDE_OPTIONS;
3832 #endif
3833 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
3834 SUBSUBTARGET_OVERRIDE_OPTIONS;
3835 #endif
3836 #ifdef SUB3TARGET_OVERRIDE_OPTIONS
3837 SUB3TARGET_OVERRIDE_OPTIONS;
3838 #endif
3840 if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET)
3841 rs6000_print_isa_options (stderr, 0, "after subtarget", rs6000_isa_flags);
3843 /* For the E500 family of cores, reset the single/double FP flags to let us
3844 check that they remain constant across attributes or pragmas. Also,
3845 clear a possible request for string instructions, not supported and which
3846 we might have silently queried above for -Os.
3848 For other families, clear ISEL in case it was set implicitly.
3851 switch (rs6000_cpu)
3853 case PROCESSOR_PPC8540:
3854 case PROCESSOR_PPC8548:
3855 case PROCESSOR_PPCE500MC:
3856 case PROCESSOR_PPCE500MC64:
3857 case PROCESSOR_PPCE5500:
3858 case PROCESSOR_PPCE6500:
3860 rs6000_single_float = TARGET_E500_SINGLE || TARGET_E500_DOUBLE;
3861 rs6000_double_float = TARGET_E500_DOUBLE;
3863 rs6000_isa_flags &= ~OPTION_MASK_STRING;
3865 break;
3867 default:
3869 if (have_cpu && !(rs6000_isa_flags_explicit & OPTION_MASK_ISEL))
3870 rs6000_isa_flags &= ~OPTION_MASK_ISEL;
3872 break;
3875 if (main_target_opt)
3877 if (main_target_opt->x_rs6000_single_float != rs6000_single_float)
3878 error ("target attribute or pragma changes single precision floating "
3879 "point");
3880 if (main_target_opt->x_rs6000_double_float != rs6000_double_float)
3881 error ("target attribute or pragma changes double precision floating "
3882 "point");
3885 /* Detect invalid option combinations with E500. */
3886 CHECK_E500_OPTIONS;
3888 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
3889 && rs6000_cpu != PROCESSOR_POWER5
3890 && rs6000_cpu != PROCESSOR_POWER6
3891 && rs6000_cpu != PROCESSOR_POWER7
3892 && rs6000_cpu != PROCESSOR_POWER8
3893 && rs6000_cpu != PROCESSOR_PPCA2
3894 && rs6000_cpu != PROCESSOR_CELL
3895 && rs6000_cpu != PROCESSOR_PPC476);
3896 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
3897 || rs6000_cpu == PROCESSOR_POWER5
3898 || rs6000_cpu == PROCESSOR_POWER7
3899 || rs6000_cpu == PROCESSOR_POWER8);
3900 rs6000_align_branch_targets = (rs6000_cpu == PROCESSOR_POWER4
3901 || rs6000_cpu == PROCESSOR_POWER5
3902 || rs6000_cpu == PROCESSOR_POWER6
3903 || rs6000_cpu == PROCESSOR_POWER7
3904 || rs6000_cpu == PROCESSOR_POWER8
3905 || rs6000_cpu == PROCESSOR_PPCE500MC
3906 || rs6000_cpu == PROCESSOR_PPCE500MC64
3907 || rs6000_cpu == PROCESSOR_PPCE5500
3908 || rs6000_cpu == PROCESSOR_PPCE6500);
3910 /* Allow debug switches to override the above settings. These are set to -1
3911 in rs6000.opt to indicate the user hasn't directly set the switch. */
3912 if (TARGET_ALWAYS_HINT >= 0)
3913 rs6000_always_hint = TARGET_ALWAYS_HINT;
3915 if (TARGET_SCHED_GROUPS >= 0)
3916 rs6000_sched_groups = TARGET_SCHED_GROUPS;
3918 if (TARGET_ALIGN_BRANCH_TARGETS >= 0)
3919 rs6000_align_branch_targets = TARGET_ALIGN_BRANCH_TARGETS;
3921 rs6000_sched_restricted_insns_priority
3922 = (rs6000_sched_groups ? 1 : 0);
3924 /* Handle -msched-costly-dep option. */
3925 rs6000_sched_costly_dep
3926 = (rs6000_sched_groups ? true_store_to_load_dep_costly : no_dep_costly);
3928 if (rs6000_sched_costly_dep_str)
3930 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
3931 rs6000_sched_costly_dep = no_dep_costly;
3932 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
3933 rs6000_sched_costly_dep = all_deps_costly;
3934 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
3935 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
3936 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
3937 rs6000_sched_costly_dep = store_to_load_dep_costly;
3938 else
3939 rs6000_sched_costly_dep = ((enum rs6000_dependence_cost)
3940 atoi (rs6000_sched_costly_dep_str));
3943 /* Handle -minsert-sched-nops option. */
3944 rs6000_sched_insert_nops
3945 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
3947 if (rs6000_sched_insert_nops_str)
3949 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
3950 rs6000_sched_insert_nops = sched_finish_none;
3951 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
3952 rs6000_sched_insert_nops = sched_finish_pad_groups;
3953 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
3954 rs6000_sched_insert_nops = sched_finish_regroup_exact;
3955 else
3956 rs6000_sched_insert_nops = ((enum rs6000_nop_insertion)
3957 atoi (rs6000_sched_insert_nops_str));
3960 if (global_init_p)
3962 #ifdef TARGET_REGNAMES
3963 /* If the user desires alternate register names, copy in the
3964 alternate names now. */
3965 if (TARGET_REGNAMES)
3966 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
3967 #endif
3969 /* Set aix_struct_return last, after the ABI is determined.
3970 If -maix-struct-return or -msvr4-struct-return was explicitly
3971 used, don't override with the ABI default. */
3972 if (!global_options_set.x_aix_struct_return)
3973 aix_struct_return = (DEFAULT_ABI != ABI_V4 || DRAFT_V4_STRUCT_RET);
3975 #if 0
3976 /* IBM XL compiler defaults to unsigned bitfields. */
3977 if (TARGET_XL_COMPAT)
3978 flag_signed_bitfields = 0;
3979 #endif
3981 if (TARGET_LONG_DOUBLE_128 && !TARGET_IEEEQUAD)
3982 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
3984 if (TARGET_TOC)
3985 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
3987 /* We can only guarantee the availability of DI pseudo-ops when
3988 assembling for 64-bit targets. */
3989 if (!TARGET_64BIT)
3991 targetm.asm_out.aligned_op.di = NULL;
3992 targetm.asm_out.unaligned_op.di = NULL;
3996 /* Set branch target alignment, if not optimizing for size. */
3997 if (!optimize_size)
3999 /* Cell wants to be aligned 8byte for dual issue. Titan wants to be
4000 aligned 8byte to avoid misprediction by the branch predictor. */
4001 if (rs6000_cpu == PROCESSOR_TITAN
4002 || rs6000_cpu == PROCESSOR_CELL)
4004 if (align_functions <= 0)
4005 align_functions = 8;
4006 if (align_jumps <= 0)
4007 align_jumps = 8;
4008 if (align_loops <= 0)
4009 align_loops = 8;
4011 if (rs6000_align_branch_targets)
4013 if (align_functions <= 0)
4014 align_functions = 16;
4015 if (align_jumps <= 0)
4016 align_jumps = 16;
4017 if (align_loops <= 0)
4019 can_override_loop_align = 1;
4020 align_loops = 16;
4023 if (align_jumps_max_skip <= 0)
4024 align_jumps_max_skip = 15;
4025 if (align_loops_max_skip <= 0)
4026 align_loops_max_skip = 15;
4029 /* Arrange to save and restore machine status around nested functions. */
4030 init_machine_status = rs6000_init_machine_status;
4032 /* We should always be splitting complex arguments, but we can't break
4033 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
4034 if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN)
4035 targetm.calls.split_complex_arg = NULL;
4038 /* Initialize rs6000_cost with the appropriate target costs. */
4039 if (optimize_size)
4040 rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
4041 else
4042 switch (rs6000_cpu)
4044 case PROCESSOR_RS64A:
4045 rs6000_cost = &rs64a_cost;
4046 break;
4048 case PROCESSOR_MPCCORE:
4049 rs6000_cost = &mpccore_cost;
4050 break;
4052 case PROCESSOR_PPC403:
4053 rs6000_cost = &ppc403_cost;
4054 break;
4056 case PROCESSOR_PPC405:
4057 rs6000_cost = &ppc405_cost;
4058 break;
4060 case PROCESSOR_PPC440:
4061 rs6000_cost = &ppc440_cost;
4062 break;
4064 case PROCESSOR_PPC476:
4065 rs6000_cost = &ppc476_cost;
4066 break;
4068 case PROCESSOR_PPC601:
4069 rs6000_cost = &ppc601_cost;
4070 break;
4072 case PROCESSOR_PPC603:
4073 rs6000_cost = &ppc603_cost;
4074 break;
4076 case PROCESSOR_PPC604:
4077 rs6000_cost = &ppc604_cost;
4078 break;
4080 case PROCESSOR_PPC604e:
4081 rs6000_cost = &ppc604e_cost;
4082 break;
4084 case PROCESSOR_PPC620:
4085 rs6000_cost = &ppc620_cost;
4086 break;
4088 case PROCESSOR_PPC630:
4089 rs6000_cost = &ppc630_cost;
4090 break;
4092 case PROCESSOR_CELL:
4093 rs6000_cost = &ppccell_cost;
4094 break;
4096 case PROCESSOR_PPC750:
4097 case PROCESSOR_PPC7400:
4098 rs6000_cost = &ppc750_cost;
4099 break;
4101 case PROCESSOR_PPC7450:
4102 rs6000_cost = &ppc7450_cost;
4103 break;
4105 case PROCESSOR_PPC8540:
4106 case PROCESSOR_PPC8548:
4107 rs6000_cost = &ppc8540_cost;
4108 break;
4110 case PROCESSOR_PPCE300C2:
4111 case PROCESSOR_PPCE300C3:
4112 rs6000_cost = &ppce300c2c3_cost;
4113 break;
4115 case PROCESSOR_PPCE500MC:
4116 rs6000_cost = &ppce500mc_cost;
4117 break;
4119 case PROCESSOR_PPCE500MC64:
4120 rs6000_cost = &ppce500mc64_cost;
4121 break;
4123 case PROCESSOR_PPCE5500:
4124 rs6000_cost = &ppce5500_cost;
4125 break;
4127 case PROCESSOR_PPCE6500:
4128 rs6000_cost = &ppce6500_cost;
4129 break;
4131 case PROCESSOR_TITAN:
4132 rs6000_cost = &titan_cost;
4133 break;
4135 case PROCESSOR_POWER4:
4136 case PROCESSOR_POWER5:
4137 rs6000_cost = &power4_cost;
4138 break;
4140 case PROCESSOR_POWER6:
4141 rs6000_cost = &power6_cost;
4142 break;
4144 case PROCESSOR_POWER7:
4145 rs6000_cost = &power7_cost;
4146 break;
4148 case PROCESSOR_POWER8:
4149 rs6000_cost = &power8_cost;
4150 break;
4152 case PROCESSOR_PPCA2:
4153 rs6000_cost = &ppca2_cost;
4154 break;
4156 default:
4157 gcc_unreachable ();
4160 if (global_init_p)
4162 maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
4163 rs6000_cost->simultaneous_prefetches,
4164 global_options.x_param_values,
4165 global_options_set.x_param_values);
4166 maybe_set_param_value (PARAM_L1_CACHE_SIZE, rs6000_cost->l1_cache_size,
4167 global_options.x_param_values,
4168 global_options_set.x_param_values);
4169 maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
4170 rs6000_cost->cache_line_size,
4171 global_options.x_param_values,
4172 global_options_set.x_param_values);
4173 maybe_set_param_value (PARAM_L2_CACHE_SIZE, rs6000_cost->l2_cache_size,
4174 global_options.x_param_values,
4175 global_options_set.x_param_values);
4177 /* Increase loop peeling limits based on performance analysis. */
4178 maybe_set_param_value (PARAM_MAX_PEELED_INSNS, 400,
4179 global_options.x_param_values,
4180 global_options_set.x_param_values);
4181 maybe_set_param_value (PARAM_MAX_COMPLETELY_PEELED_INSNS, 400,
4182 global_options.x_param_values,
4183 global_options_set.x_param_values);
4185 /* If using typedef char *va_list, signal that
4186 __builtin_va_start (&ap, 0) can be optimized to
4187 ap = __builtin_next_arg (0). */
4188 if (DEFAULT_ABI != ABI_V4)
4189 targetm.expand_builtin_va_start = NULL;
4192 /* Set up single/double float flags.
4193 If TARGET_HARD_FLOAT is set, but neither single or double is set,
4194 then set both flags. */
4195 if (TARGET_HARD_FLOAT && TARGET_FPRS
4196 && rs6000_single_float == 0 && rs6000_double_float == 0)
4197 rs6000_single_float = rs6000_double_float = 1;
4199 /* If not explicitly specified via option, decide whether to generate indexed
4200 load/store instructions. */
4201 if (TARGET_AVOID_XFORM == -1)
4202 /* Avoid indexed addressing when targeting Power6 in order to avoid the
4203 DERAT mispredict penalty. However the LVE and STVE altivec instructions
4204 need indexed accesses and the type used is the scalar type of the element
4205 being loaded or stored. */
4206 TARGET_AVOID_XFORM = (rs6000_cpu == PROCESSOR_POWER6 && TARGET_CMPB
4207 && !TARGET_ALTIVEC);
4209 /* Set the -mrecip options. */
4210 if (rs6000_recip_name)
4212 char *p = ASTRDUP (rs6000_recip_name);
4213 char *q;
4214 unsigned int mask, i;
4215 bool invert;
4217 while ((q = strtok (p, ",")) != NULL)
4219 p = NULL;
4220 if (*q == '!')
4222 invert = true;
4223 q++;
4225 else
4226 invert = false;
4228 if (!strcmp (q, "default"))
4229 mask = ((TARGET_RECIP_PRECISION)
4230 ? RECIP_HIGH_PRECISION : RECIP_LOW_PRECISION);
4231 else
4233 for (i = 0; i < ARRAY_SIZE (recip_options); i++)
4234 if (!strcmp (q, recip_options[i].string))
4236 mask = recip_options[i].mask;
4237 break;
4240 if (i == ARRAY_SIZE (recip_options))
4242 error ("unknown option for -mrecip=%s", q);
4243 invert = false;
4244 mask = 0;
4245 ret = false;
4249 if (invert)
4250 rs6000_recip_control &= ~mask;
4251 else
4252 rs6000_recip_control |= mask;
4256 /* Determine when unaligned vector accesses are permitted, and when
4257 they are preferred over masked Altivec loads. Note that if
4258 TARGET_ALLOW_MOVMISALIGN has been disabled by the user, then
4259 TARGET_EFFICIENT_UNALIGNED_VSX must be as well. The converse is
4260 not true. */
4261 if (TARGET_EFFICIENT_UNALIGNED_VSX == -1) {
4262 if (TARGET_VSX && rs6000_cpu == PROCESSOR_POWER8
4263 && TARGET_ALLOW_MOVMISALIGN != 0)
4264 TARGET_EFFICIENT_UNALIGNED_VSX = 1;
4265 else
4266 TARGET_EFFICIENT_UNALIGNED_VSX = 0;
4269 if (TARGET_ALLOW_MOVMISALIGN == -1 && rs6000_cpu == PROCESSOR_POWER8)
4270 TARGET_ALLOW_MOVMISALIGN = 1;
4272 /* Set the builtin mask of the various options used that could affect which
4273 builtins were used. In the past we used target_flags, but we've run out
4274 of bits, and some options like SPE and PAIRED are no longer in
4275 target_flags. */
4276 rs6000_builtin_mask = rs6000_builtin_mask_calculate ();
4277 if (TARGET_DEBUG_BUILTIN || TARGET_DEBUG_TARGET)
4278 rs6000_print_builtin_options (stderr, 0, "builtin mask",
4279 rs6000_builtin_mask);
4281 /* Initialize all of the registers. */
4282 rs6000_init_hard_regno_mode_ok (global_init_p);
4284 /* Save the initial options in case the user does function specific options */
4285 if (global_init_p)
4286 target_option_default_node = target_option_current_node
4287 = build_target_option_node (&global_options);
4289 /* If not explicitly specified via option, decide whether to generate the
4290 extra blr's required to preserve the link stack on some cpus (eg, 476). */
4291 if (TARGET_LINK_STACK == -1)
4292 SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 && flag_pic);
4294 return ret;
4297 /* Implement TARGET_OPTION_OVERRIDE. On the RS/6000 this is used to
4298 define the target cpu type. */
4300 static void
4301 rs6000_option_override (void)
4303 (void) rs6000_option_override_internal (true);
4305 /* Register machine-specific passes. This needs to be done at start-up.
4306 It's convenient to do it here (like i386 does). */
4307 opt_pass *pass_analyze_swaps = make_pass_analyze_swaps (g);
4309 struct register_pass_info analyze_swaps_info
4310 = { pass_analyze_swaps, "cse1", 1, PASS_POS_INSERT_BEFORE };
4312 register_pass (&analyze_swaps_info);
4316 /* Implement targetm.vectorize.builtin_mask_for_load. */
4317 static tree
4318 rs6000_builtin_mask_for_load (void)
4320 /* Don't use lvsl/vperm for P8 and similarly efficient machines. */
4321 if ((TARGET_ALTIVEC && !TARGET_VSX)
4322 || (TARGET_VSX && !TARGET_EFFICIENT_UNALIGNED_VSX))
4323 return altivec_builtin_mask_for_load;
4324 else
4325 return 0;
4328 /* Implement LOOP_ALIGN. */
4330 rs6000_loop_align (rtx label)
4332 basic_block bb;
4333 int ninsns;
4335 /* Don't override loop alignment if -falign-loops was specified. */
4336 if (!can_override_loop_align)
4337 return align_loops_log;
4339 bb = BLOCK_FOR_INSN (label);
4340 ninsns = num_loop_insns(bb->loop_father);
4342 /* Align small loops to 32 bytes to fit in an icache sector, otherwise return default. */
4343 if (ninsns > 4 && ninsns <= 8
4344 && (rs6000_cpu == PROCESSOR_POWER4
4345 || rs6000_cpu == PROCESSOR_POWER5
4346 || rs6000_cpu == PROCESSOR_POWER6
4347 || rs6000_cpu == PROCESSOR_POWER7
4348 || rs6000_cpu == PROCESSOR_POWER8))
4349 return 5;
4350 else
4351 return align_loops_log;
4354 /* Implement TARGET_LOOP_ALIGN_MAX_SKIP. */
4355 static int
4356 rs6000_loop_align_max_skip (rtx_insn *label)
4358 return (1 << rs6000_loop_align (label)) - 1;
4361 /* Return true iff, data reference of TYPE can reach vector alignment (16)
4362 after applying N number of iterations. This routine does not determine
4363 how may iterations are required to reach desired alignment. */
4365 static bool
4366 rs6000_vector_alignment_reachable (const_tree type ATTRIBUTE_UNUSED, bool is_packed)
4368 if (is_packed)
4369 return false;
4371 if (TARGET_32BIT)
4373 if (rs6000_alignment_flags == MASK_ALIGN_NATURAL)
4374 return true;
4376 if (rs6000_alignment_flags == MASK_ALIGN_POWER)
4377 return true;
4379 return false;
4381 else
4383 if (TARGET_MACHO)
4384 return false;
4386 /* Assuming that all other types are naturally aligned. CHECKME! */
4387 return true;
4391 /* Return true if the vector misalignment factor is supported by the
4392 target. */
4393 static bool
4394 rs6000_builtin_support_vector_misalignment (machine_mode mode,
4395 const_tree type,
4396 int misalignment,
4397 bool is_packed)
4399 if (TARGET_VSX)
4401 if (TARGET_EFFICIENT_UNALIGNED_VSX)
4402 return true;
4404 /* Return if movmisalign pattern is not supported for this mode. */
4405 if (optab_handler (movmisalign_optab, mode) == CODE_FOR_nothing)
4406 return false;
4408 if (misalignment == -1)
4410 /* Misalignment factor is unknown at compile time but we know
4411 it's word aligned. */
4412 if (rs6000_vector_alignment_reachable (type, is_packed))
4414 int element_size = TREE_INT_CST_LOW (TYPE_SIZE (type));
4416 if (element_size == 64 || element_size == 32)
4417 return true;
4420 return false;
4423 /* VSX supports word-aligned vector. */
4424 if (misalignment % 4 == 0)
4425 return true;
4427 return false;
4430 /* Implement targetm.vectorize.builtin_vectorization_cost. */
4431 static int
4432 rs6000_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
4433 tree vectype, int misalign)
4435 unsigned elements;
4436 tree elem_type;
4438 switch (type_of_cost)
4440 case scalar_stmt:
4441 case scalar_load:
4442 case scalar_store:
4443 case vector_stmt:
4444 case vector_load:
4445 case vector_store:
4446 case vec_to_scalar:
4447 case scalar_to_vec:
4448 case cond_branch_not_taken:
4449 return 1;
4451 case vec_perm:
4452 if (TARGET_VSX)
4453 return 3;
4454 else
4455 return 1;
4457 case vec_promote_demote:
4458 if (TARGET_VSX)
4459 return 4;
4460 else
4461 return 1;
4463 case cond_branch_taken:
4464 return 3;
4466 case unaligned_load:
4467 if (TARGET_EFFICIENT_UNALIGNED_VSX)
4468 return 1;
4470 if (TARGET_VSX && TARGET_ALLOW_MOVMISALIGN)
4472 elements = TYPE_VECTOR_SUBPARTS (vectype);
4473 if (elements == 2)
4474 /* Double word aligned. */
4475 return 2;
4477 if (elements == 4)
4479 switch (misalign)
4481 case 8:
4482 /* Double word aligned. */
4483 return 2;
4485 case -1:
4486 /* Unknown misalignment. */
4487 case 4:
4488 case 12:
4489 /* Word aligned. */
4490 return 22;
4492 default:
4493 gcc_unreachable ();
4498 if (TARGET_ALTIVEC)
4499 /* Misaligned loads are not supported. */
4500 gcc_unreachable ();
4502 return 2;
4504 case unaligned_store:
4505 if (TARGET_EFFICIENT_UNALIGNED_VSX)
4506 return 1;
4508 if (TARGET_VSX && TARGET_ALLOW_MOVMISALIGN)
4510 elements = TYPE_VECTOR_SUBPARTS (vectype);
4511 if (elements == 2)
4512 /* Double word aligned. */
4513 return 2;
4515 if (elements == 4)
4517 switch (misalign)
4519 case 8:
4520 /* Double word aligned. */
4521 return 2;
4523 case -1:
4524 /* Unknown misalignment. */
4525 case 4:
4526 case 12:
4527 /* Word aligned. */
4528 return 23;
4530 default:
4531 gcc_unreachable ();
4536 if (TARGET_ALTIVEC)
4537 /* Misaligned stores are not supported. */
4538 gcc_unreachable ();
4540 return 2;
4542 case vec_construct:
4543 elements = TYPE_VECTOR_SUBPARTS (vectype);
4544 elem_type = TREE_TYPE (vectype);
4545 /* 32-bit vectors loaded into registers are stored as double
4546 precision, so we need n/2 converts in addition to the usual
4547 n/2 merges to construct a vector of short floats from them. */
4548 if (SCALAR_FLOAT_TYPE_P (elem_type)
4549 && TYPE_PRECISION (elem_type) == 32)
4550 return elements + 1;
4551 else
4552 return elements / 2 + 1;
4554 default:
4555 gcc_unreachable ();
4559 /* Implement targetm.vectorize.preferred_simd_mode. */
4561 static machine_mode
4562 rs6000_preferred_simd_mode (machine_mode mode)
4564 if (TARGET_VSX)
4565 switch (mode)
4567 case DFmode:
4568 return V2DFmode;
4569 default:;
4571 if (TARGET_ALTIVEC || TARGET_VSX)
4572 switch (mode)
4574 case SFmode:
4575 return V4SFmode;
4576 case TImode:
4577 return V1TImode;
4578 case DImode:
4579 return V2DImode;
4580 case SImode:
4581 return V4SImode;
4582 case HImode:
4583 return V8HImode;
4584 case QImode:
4585 return V16QImode;
4586 default:;
4588 if (TARGET_SPE)
4589 switch (mode)
4591 case SFmode:
4592 return V2SFmode;
4593 case SImode:
4594 return V2SImode;
4595 default:;
4597 if (TARGET_PAIRED_FLOAT
4598 && mode == SFmode)
4599 return V2SFmode;
4600 return word_mode;
4603 typedef struct _rs6000_cost_data
4605 struct loop *loop_info;
4606 unsigned cost[3];
4607 } rs6000_cost_data;
4609 /* Test for likely overcommitment of vector hardware resources. If a
4610 loop iteration is relatively large, and too large a percentage of
4611 instructions in the loop are vectorized, the cost model may not
4612 adequately reflect delays from unavailable vector resources.
4613 Penalize the loop body cost for this case. */
4615 static void
4616 rs6000_density_test (rs6000_cost_data *data)
4618 const int DENSITY_PCT_THRESHOLD = 85;
4619 const int DENSITY_SIZE_THRESHOLD = 70;
4620 const int DENSITY_PENALTY = 10;
4621 struct loop *loop = data->loop_info;
4622 basic_block *bbs = get_loop_body (loop);
4623 int nbbs = loop->num_nodes;
4624 int vec_cost = data->cost[vect_body], not_vec_cost = 0;
4625 int i, density_pct;
4627 for (i = 0; i < nbbs; i++)
4629 basic_block bb = bbs[i];
4630 gimple_stmt_iterator gsi;
4632 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
4634 gimple stmt = gsi_stmt (gsi);
4635 stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
4637 if (!STMT_VINFO_RELEVANT_P (stmt_info)
4638 && !STMT_VINFO_IN_PATTERN_P (stmt_info))
4639 not_vec_cost++;
4643 free (bbs);
4644 density_pct = (vec_cost * 100) / (vec_cost + not_vec_cost);
4646 if (density_pct > DENSITY_PCT_THRESHOLD
4647 && vec_cost + not_vec_cost > DENSITY_SIZE_THRESHOLD)
4649 data->cost[vect_body] = vec_cost * (100 + DENSITY_PENALTY) / 100;
4650 if (dump_enabled_p ())
4651 dump_printf_loc (MSG_NOTE, vect_location,
4652 "density %d%%, cost %d exceeds threshold, penalizing "
4653 "loop body cost by %d%%", density_pct,
4654 vec_cost + not_vec_cost, DENSITY_PENALTY);
4658 /* Implement targetm.vectorize.init_cost. */
4660 static void *
4661 rs6000_init_cost (struct loop *loop_info)
4663 rs6000_cost_data *data = XNEW (struct _rs6000_cost_data);
4664 data->loop_info = loop_info;
4665 data->cost[vect_prologue] = 0;
4666 data->cost[vect_body] = 0;
4667 data->cost[vect_epilogue] = 0;
4668 return data;
4671 /* Implement targetm.vectorize.add_stmt_cost. */
4673 static unsigned
4674 rs6000_add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
4675 struct _stmt_vec_info *stmt_info, int misalign,
4676 enum vect_cost_model_location where)
4678 rs6000_cost_data *cost_data = (rs6000_cost_data*) data;
4679 unsigned retval = 0;
4681 if (flag_vect_cost_model)
4683 tree vectype = stmt_info ? stmt_vectype (stmt_info) : NULL_TREE;
4684 int stmt_cost = rs6000_builtin_vectorization_cost (kind, vectype,
4685 misalign);
4686 /* Statements in an inner loop relative to the loop being
4687 vectorized are weighted more heavily. The value here is
4688 arbitrary and could potentially be improved with analysis. */
4689 if (where == vect_body && stmt_info && stmt_in_inner_loop_p (stmt_info))
4690 count *= 50; /* FIXME. */
4692 retval = (unsigned) (count * stmt_cost);
4693 cost_data->cost[where] += retval;
4696 return retval;
4699 /* Implement targetm.vectorize.finish_cost. */
4701 static void
4702 rs6000_finish_cost (void *data, unsigned *prologue_cost,
4703 unsigned *body_cost, unsigned *epilogue_cost)
4705 rs6000_cost_data *cost_data = (rs6000_cost_data*) data;
4707 if (cost_data->loop_info)
4708 rs6000_density_test (cost_data);
4710 *prologue_cost = cost_data->cost[vect_prologue];
4711 *body_cost = cost_data->cost[vect_body];
4712 *epilogue_cost = cost_data->cost[vect_epilogue];
4715 /* Implement targetm.vectorize.destroy_cost_data. */
4717 static void
4718 rs6000_destroy_cost_data (void *data)
4720 free (data);
4723 /* Handler for the Mathematical Acceleration Subsystem (mass) interface to a
4724 library with vectorized intrinsics. */
4726 static tree
4727 rs6000_builtin_vectorized_libmass (tree fndecl, tree type_out, tree type_in)
4729 char name[32];
4730 const char *suffix = NULL;
4731 tree fntype, new_fndecl, bdecl = NULL_TREE;
4732 int n_args = 1;
4733 const char *bname;
4734 machine_mode el_mode, in_mode;
4735 int n, in_n;
4737 /* Libmass is suitable for unsafe math only as it does not correctly support
4738 parts of IEEE with the required precision such as denormals. Only support
4739 it if we have VSX to use the simd d2 or f4 functions.
4740 XXX: Add variable length support. */
4741 if (!flag_unsafe_math_optimizations || !TARGET_VSX)
4742 return NULL_TREE;
4744 el_mode = TYPE_MODE (TREE_TYPE (type_out));
4745 n = TYPE_VECTOR_SUBPARTS (type_out);
4746 in_mode = TYPE_MODE (TREE_TYPE (type_in));
4747 in_n = TYPE_VECTOR_SUBPARTS (type_in);
4748 if (el_mode != in_mode
4749 || n != in_n)
4750 return NULL_TREE;
4752 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
4754 enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
4755 switch (fn)
4757 case BUILT_IN_ATAN2:
4758 case BUILT_IN_HYPOT:
4759 case BUILT_IN_POW:
4760 n_args = 2;
4761 /* fall through */
4763 case BUILT_IN_ACOS:
4764 case BUILT_IN_ACOSH:
4765 case BUILT_IN_ASIN:
4766 case BUILT_IN_ASINH:
4767 case BUILT_IN_ATAN:
4768 case BUILT_IN_ATANH:
4769 case BUILT_IN_CBRT:
4770 case BUILT_IN_COS:
4771 case BUILT_IN_COSH:
4772 case BUILT_IN_ERF:
4773 case BUILT_IN_ERFC:
4774 case BUILT_IN_EXP2:
4775 case BUILT_IN_EXP:
4776 case BUILT_IN_EXPM1:
4777 case BUILT_IN_LGAMMA:
4778 case BUILT_IN_LOG10:
4779 case BUILT_IN_LOG1P:
4780 case BUILT_IN_LOG2:
4781 case BUILT_IN_LOG:
4782 case BUILT_IN_SIN:
4783 case BUILT_IN_SINH:
4784 case BUILT_IN_SQRT:
4785 case BUILT_IN_TAN:
4786 case BUILT_IN_TANH:
4787 bdecl = builtin_decl_implicit (fn);
4788 suffix = "d2"; /* pow -> powd2 */
4789 if (el_mode != DFmode
4790 || n != 2
4791 || !bdecl)
4792 return NULL_TREE;
4793 break;
4795 case BUILT_IN_ATAN2F:
4796 case BUILT_IN_HYPOTF:
4797 case BUILT_IN_POWF:
4798 n_args = 2;
4799 /* fall through */
4801 case BUILT_IN_ACOSF:
4802 case BUILT_IN_ACOSHF:
4803 case BUILT_IN_ASINF:
4804 case BUILT_IN_ASINHF:
4805 case BUILT_IN_ATANF:
4806 case BUILT_IN_ATANHF:
4807 case BUILT_IN_CBRTF:
4808 case BUILT_IN_COSF:
4809 case BUILT_IN_COSHF:
4810 case BUILT_IN_ERFF:
4811 case BUILT_IN_ERFCF:
4812 case BUILT_IN_EXP2F:
4813 case BUILT_IN_EXPF:
4814 case BUILT_IN_EXPM1F:
4815 case BUILT_IN_LGAMMAF:
4816 case BUILT_IN_LOG10F:
4817 case BUILT_IN_LOG1PF:
4818 case BUILT_IN_LOG2F:
4819 case BUILT_IN_LOGF:
4820 case BUILT_IN_SINF:
4821 case BUILT_IN_SINHF:
4822 case BUILT_IN_SQRTF:
4823 case BUILT_IN_TANF:
4824 case BUILT_IN_TANHF:
4825 bdecl = builtin_decl_implicit (fn);
4826 suffix = "4"; /* powf -> powf4 */
4827 if (el_mode != SFmode
4828 || n != 4
4829 || !bdecl)
4830 return NULL_TREE;
4831 break;
4833 default:
4834 return NULL_TREE;
4837 else
4838 return NULL_TREE;
4840 gcc_assert (suffix != NULL);
4841 bname = IDENTIFIER_POINTER (DECL_NAME (bdecl));
4842 if (!bname)
4843 return NULL_TREE;
4845 strcpy (name, bname + sizeof ("__builtin_") - 1);
4846 strcat (name, suffix);
4848 if (n_args == 1)
4849 fntype = build_function_type_list (type_out, type_in, NULL);
4850 else if (n_args == 2)
4851 fntype = build_function_type_list (type_out, type_in, type_in, NULL);
4852 else
4853 gcc_unreachable ();
4855 /* Build a function declaration for the vectorized function. */
4856 new_fndecl = build_decl (BUILTINS_LOCATION,
4857 FUNCTION_DECL, get_identifier (name), fntype);
4858 TREE_PUBLIC (new_fndecl) = 1;
4859 DECL_EXTERNAL (new_fndecl) = 1;
4860 DECL_IS_NOVOPS (new_fndecl) = 1;
4861 TREE_READONLY (new_fndecl) = 1;
4863 return new_fndecl;
4866 /* Returns a function decl for a vectorized version of the builtin function
4867 with builtin function code FN and the result vector type TYPE, or NULL_TREE
4868 if it is not available. */
4870 static tree
4871 rs6000_builtin_vectorized_function (tree fndecl, tree type_out,
4872 tree type_in)
4874 machine_mode in_mode, out_mode;
4875 int in_n, out_n;
4877 if (TARGET_DEBUG_BUILTIN)
4878 fprintf (stderr, "rs6000_builtin_vectorized_function (%s, %s, %s)\n",
4879 IDENTIFIER_POINTER (DECL_NAME (fndecl)),
4880 GET_MODE_NAME (TYPE_MODE (type_out)),
4881 GET_MODE_NAME (TYPE_MODE (type_in)));
4883 if (TREE_CODE (type_out) != VECTOR_TYPE
4884 || TREE_CODE (type_in) != VECTOR_TYPE
4885 || !TARGET_VECTORIZE_BUILTINS)
4886 return NULL_TREE;
4888 out_mode = TYPE_MODE (TREE_TYPE (type_out));
4889 out_n = TYPE_VECTOR_SUBPARTS (type_out);
4890 in_mode = TYPE_MODE (TREE_TYPE (type_in));
4891 in_n = TYPE_VECTOR_SUBPARTS (type_in);
4893 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
4895 enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
4896 switch (fn)
4898 case BUILT_IN_CLZIMAX:
4899 case BUILT_IN_CLZLL:
4900 case BUILT_IN_CLZL:
4901 case BUILT_IN_CLZ:
4902 if (TARGET_P8_VECTOR && in_mode == out_mode && out_n == in_n)
4904 if (out_mode == QImode && out_n == 16)
4905 return rs6000_builtin_decls[P8V_BUILTIN_VCLZB];
4906 else if (out_mode == HImode && out_n == 8)
4907 return rs6000_builtin_decls[P8V_BUILTIN_VCLZH];
4908 else if (out_mode == SImode && out_n == 4)
4909 return rs6000_builtin_decls[P8V_BUILTIN_VCLZW];
4910 else if (out_mode == DImode && out_n == 2)
4911 return rs6000_builtin_decls[P8V_BUILTIN_VCLZD];
4913 break;
4914 case BUILT_IN_COPYSIGN:
4915 if (VECTOR_UNIT_VSX_P (V2DFmode)
4916 && out_mode == DFmode && out_n == 2
4917 && in_mode == DFmode && in_n == 2)
4918 return rs6000_builtin_decls[VSX_BUILTIN_CPSGNDP];
4919 break;
4920 case BUILT_IN_COPYSIGNF:
4921 if (out_mode != SFmode || out_n != 4
4922 || in_mode != SFmode || in_n != 4)
4923 break;
4924 if (VECTOR_UNIT_VSX_P (V4SFmode))
4925 return rs6000_builtin_decls[VSX_BUILTIN_CPSGNSP];
4926 if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
4927 return rs6000_builtin_decls[ALTIVEC_BUILTIN_COPYSIGN_V4SF];
4928 break;
4929 case BUILT_IN_POPCOUNTIMAX:
4930 case BUILT_IN_POPCOUNTLL:
4931 case BUILT_IN_POPCOUNTL:
4932 case BUILT_IN_POPCOUNT:
4933 if (TARGET_P8_VECTOR && in_mode == out_mode && out_n == in_n)
4935 if (out_mode == QImode && out_n == 16)
4936 return rs6000_builtin_decls[P8V_BUILTIN_VPOPCNTB];
4937 else if (out_mode == HImode && out_n == 8)
4938 return rs6000_builtin_decls[P8V_BUILTIN_VPOPCNTH];
4939 else if (out_mode == SImode && out_n == 4)
4940 return rs6000_builtin_decls[P8V_BUILTIN_VPOPCNTW];
4941 else if (out_mode == DImode && out_n == 2)
4942 return rs6000_builtin_decls[P8V_BUILTIN_VPOPCNTD];
4944 break;
4945 case BUILT_IN_SQRT:
4946 if (VECTOR_UNIT_VSX_P (V2DFmode)
4947 && out_mode == DFmode && out_n == 2
4948 && in_mode == DFmode && in_n == 2)
4949 return rs6000_builtin_decls[VSX_BUILTIN_XVSQRTDP];
4950 break;
4951 case BUILT_IN_SQRTF:
4952 if (VECTOR_UNIT_VSX_P (V4SFmode)
4953 && out_mode == SFmode && out_n == 4
4954 && in_mode == SFmode && in_n == 4)
4955 return rs6000_builtin_decls[VSX_BUILTIN_XVSQRTSP];
4956 break;
4957 case BUILT_IN_CEIL:
4958 if (VECTOR_UNIT_VSX_P (V2DFmode)
4959 && out_mode == DFmode && out_n == 2
4960 && in_mode == DFmode && in_n == 2)
4961 return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIP];
4962 break;
4963 case BUILT_IN_CEILF:
4964 if (out_mode != SFmode || out_n != 4
4965 || in_mode != SFmode || in_n != 4)
4966 break;
4967 if (VECTOR_UNIT_VSX_P (V4SFmode))
4968 return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIP];
4969 if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
4970 return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRFIP];
4971 break;
4972 case BUILT_IN_FLOOR:
4973 if (VECTOR_UNIT_VSX_P (V2DFmode)
4974 && out_mode == DFmode && out_n == 2
4975 && in_mode == DFmode && in_n == 2)
4976 return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIM];
4977 break;
4978 case BUILT_IN_FLOORF:
4979 if (out_mode != SFmode || out_n != 4
4980 || in_mode != SFmode || in_n != 4)
4981 break;
4982 if (VECTOR_UNIT_VSX_P (V4SFmode))
4983 return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIM];
4984 if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
4985 return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRFIM];
4986 break;
4987 case BUILT_IN_FMA:
4988 if (VECTOR_UNIT_VSX_P (V2DFmode)
4989 && out_mode == DFmode && out_n == 2
4990 && in_mode == DFmode && in_n == 2)
4991 return rs6000_builtin_decls[VSX_BUILTIN_XVMADDDP];
4992 break;
4993 case BUILT_IN_FMAF:
4994 if (VECTOR_UNIT_VSX_P (V4SFmode)
4995 && out_mode == SFmode && out_n == 4
4996 && in_mode == SFmode && in_n == 4)
4997 return rs6000_builtin_decls[VSX_BUILTIN_XVMADDSP];
4998 else if (VECTOR_UNIT_ALTIVEC_P (V4SFmode)
4999 && out_mode == SFmode && out_n == 4
5000 && in_mode == SFmode && in_n == 4)
5001 return rs6000_builtin_decls[ALTIVEC_BUILTIN_VMADDFP];
5002 break;
5003 case BUILT_IN_TRUNC:
5004 if (VECTOR_UNIT_VSX_P (V2DFmode)
5005 && out_mode == DFmode && out_n == 2
5006 && in_mode == DFmode && in_n == 2)
5007 return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIZ];
5008 break;
5009 case BUILT_IN_TRUNCF:
5010 if (out_mode != SFmode || out_n != 4
5011 || in_mode != SFmode || in_n != 4)
5012 break;
5013 if (VECTOR_UNIT_VSX_P (V4SFmode))
5014 return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIZ];
5015 if (VECTOR_UNIT_ALTIVEC_P (V4SFmode))
5016 return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRFIZ];
5017 break;
5018 case BUILT_IN_NEARBYINT:
5019 if (VECTOR_UNIT_VSX_P (V2DFmode)
5020 && flag_unsafe_math_optimizations
5021 && out_mode == DFmode && out_n == 2
5022 && in_mode == DFmode && in_n == 2)
5023 return rs6000_builtin_decls[VSX_BUILTIN_XVRDPI];
5024 break;
5025 case BUILT_IN_NEARBYINTF:
5026 if (VECTOR_UNIT_VSX_P (V4SFmode)
5027 && flag_unsafe_math_optimizations
5028 && out_mode == SFmode && out_n == 4
5029 && in_mode == SFmode && in_n == 4)
5030 return rs6000_builtin_decls[VSX_BUILTIN_XVRSPI];
5031 break;
5032 case BUILT_IN_RINT:
5033 if (VECTOR_UNIT_VSX_P (V2DFmode)
5034 && !flag_trapping_math
5035 && out_mode == DFmode && out_n == 2
5036 && in_mode == DFmode && in_n == 2)
5037 return rs6000_builtin_decls[VSX_BUILTIN_XVRDPIC];
5038 break;
5039 case BUILT_IN_RINTF:
5040 if (VECTOR_UNIT_VSX_P (V4SFmode)
5041 && !flag_trapping_math
5042 && out_mode == SFmode && out_n == 4
5043 && in_mode == SFmode && in_n == 4)
5044 return rs6000_builtin_decls[VSX_BUILTIN_XVRSPIC];
5045 break;
5046 default:
5047 break;
5051 else if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
5053 enum rs6000_builtins fn
5054 = (enum rs6000_builtins)DECL_FUNCTION_CODE (fndecl);
5055 switch (fn)
5057 case RS6000_BUILTIN_RSQRTF:
5058 if (VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
5059 && out_mode == SFmode && out_n == 4
5060 && in_mode == SFmode && in_n == 4)
5061 return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRSQRTFP];
5062 break;
5063 case RS6000_BUILTIN_RSQRT:
5064 if (VECTOR_UNIT_VSX_P (V2DFmode)
5065 && out_mode == DFmode && out_n == 2
5066 && in_mode == DFmode && in_n == 2)
5067 return rs6000_builtin_decls[VSX_BUILTIN_RSQRT_2DF];
5068 break;
5069 case RS6000_BUILTIN_RECIPF:
5070 if (VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)
5071 && out_mode == SFmode && out_n == 4
5072 && in_mode == SFmode && in_n == 4)
5073 return rs6000_builtin_decls[ALTIVEC_BUILTIN_VRECIPFP];
5074 break;
5075 case RS6000_BUILTIN_RECIP:
5076 if (VECTOR_UNIT_VSX_P (V2DFmode)
5077 && out_mode == DFmode && out_n == 2
5078 && in_mode == DFmode && in_n == 2)
5079 return rs6000_builtin_decls[VSX_BUILTIN_RECIP_V2DF];
5080 break;
5081 default:
5082 break;
5086 /* Generate calls to libmass if appropriate. */
5087 if (rs6000_veclib_handler)
5088 return rs6000_veclib_handler (fndecl, type_out, type_in);
5090 return NULL_TREE;
5093 /* Default CPU string for rs6000*_file_start functions. */
5094 static const char *rs6000_default_cpu;
5096 /* Do anything needed at the start of the asm file. */
5098 static void
5099 rs6000_file_start (void)
5101 char buffer[80];
5102 const char *start = buffer;
5103 FILE *file = asm_out_file;
5105 rs6000_default_cpu = TARGET_CPU_DEFAULT;
5107 default_file_start ();
5109 if (flag_verbose_asm)
5111 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
5113 if (rs6000_default_cpu != 0 && rs6000_default_cpu[0] != '\0')
5115 fprintf (file, "%s --with-cpu=%s", start, rs6000_default_cpu);
5116 start = "";
5119 if (global_options_set.x_rs6000_cpu_index)
5121 fprintf (file, "%s -mcpu=%s", start,
5122 processor_target_table[rs6000_cpu_index].name);
5123 start = "";
5126 if (global_options_set.x_rs6000_tune_index)
5128 fprintf (file, "%s -mtune=%s", start,
5129 processor_target_table[rs6000_tune_index].name);
5130 start = "";
5133 if (PPC405_ERRATUM77)
5135 fprintf (file, "%s PPC405CR_ERRATUM77", start);
5136 start = "";
5139 #ifdef USING_ELFOS_H
5140 switch (rs6000_sdata)
5142 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
5143 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
5144 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
5145 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
5148 if (rs6000_sdata && g_switch_value)
5150 fprintf (file, "%s -G %d", start,
5151 g_switch_value);
5152 start = "";
5154 #endif
5156 if (*start == '\0')
5157 putc ('\n', file);
5160 #ifdef USING_ELFOS_H
5161 if (rs6000_default_cpu == 0 || rs6000_default_cpu[0] == '\0'
5162 || !global_options_set.x_rs6000_cpu_index)
5164 fputs ("\t.machine ", asm_out_file);
5165 if ((rs6000_isa_flags & OPTION_MASK_DIRECT_MOVE) != 0)
5166 fputs ("power8\n", asm_out_file);
5167 else if ((rs6000_isa_flags & OPTION_MASK_POPCNTD) != 0)
5168 fputs ("power7\n", asm_out_file);
5169 else if ((rs6000_isa_flags & OPTION_MASK_CMPB) != 0)
5170 fputs ("power6\n", asm_out_file);
5171 else if ((rs6000_isa_flags & OPTION_MASK_POPCNTB) != 0)
5172 fputs ("power5\n", asm_out_file);
5173 else if ((rs6000_isa_flags & OPTION_MASK_MFCRF) != 0)
5174 fputs ("power4\n", asm_out_file);
5175 else if ((rs6000_isa_flags & OPTION_MASK_POWERPC64) != 0)
5176 fputs ("ppc64\n", asm_out_file);
5177 else
5178 fputs ("ppc\n", asm_out_file);
5180 #endif
5182 if (DEFAULT_ABI == ABI_ELFv2)
5183 fprintf (file, "\t.abiversion 2\n");
5185 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2
5186 || (TARGET_ELF && flag_pic == 2))
5188 switch_to_section (toc_section);
5189 switch_to_section (text_section);
5194 /* Return nonzero if this function is known to have a null epilogue. */
5197 direct_return (void)
5199 if (reload_completed)
5201 rs6000_stack_t *info = rs6000_stack_info ();
5203 if (info->first_gp_reg_save == 32
5204 && info->first_fp_reg_save == 64
5205 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
5206 && ! info->lr_save_p
5207 && ! info->cr_save_p
5208 && info->vrsave_size == 0
5209 && ! info->push_p)
5210 return 1;
5213 return 0;
5216 /* Return the number of instructions it takes to form a constant in an
5217 integer register. */
5220 num_insns_constant_wide (HOST_WIDE_INT value)
5222 /* signed constant loadable with addi */
5223 if (((unsigned HOST_WIDE_INT) value + 0x8000) < 0x10000)
5224 return 1;
5226 /* constant loadable with addis */
5227 else if ((value & 0xffff) == 0
5228 && (value >> 31 == -1 || value >> 31 == 0))
5229 return 1;
5231 else if (TARGET_POWERPC64)
5233 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
5234 HOST_WIDE_INT high = value >> 31;
5236 if (high == 0 || high == -1)
5237 return 2;
5239 high >>= 1;
5241 if (low == 0)
5242 return num_insns_constant_wide (high) + 1;
5243 else if (high == 0)
5244 return num_insns_constant_wide (low) + 1;
5245 else
5246 return (num_insns_constant_wide (high)
5247 + num_insns_constant_wide (low) + 1);
5250 else
5251 return 2;
5255 num_insns_constant (rtx op, machine_mode mode)
5257 HOST_WIDE_INT low, high;
5259 switch (GET_CODE (op))
5261 case CONST_INT:
5262 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
5263 && mask64_operand (op, mode))
5264 return 2;
5265 else
5266 return num_insns_constant_wide (INTVAL (op));
5268 case CONST_WIDE_INT:
5270 int i;
5271 int ins = CONST_WIDE_INT_NUNITS (op) - 1;
5272 for (i = 0; i < CONST_WIDE_INT_NUNITS (op); i++)
5273 ins += num_insns_constant_wide (CONST_WIDE_INT_ELT (op, i));
5274 return ins;
5277 case CONST_DOUBLE:
5278 if (mode == SFmode || mode == SDmode)
5280 long l;
5281 REAL_VALUE_TYPE rv;
5283 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
5284 if (DECIMAL_FLOAT_MODE_P (mode))
5285 REAL_VALUE_TO_TARGET_DECIMAL32 (rv, l);
5286 else
5287 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
5288 return num_insns_constant_wide ((HOST_WIDE_INT) l);
5291 long l[2];
5292 REAL_VALUE_TYPE rv;
5294 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
5295 if (DECIMAL_FLOAT_MODE_P (mode))
5296 REAL_VALUE_TO_TARGET_DECIMAL64 (rv, l);
5297 else
5298 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
5299 high = l[WORDS_BIG_ENDIAN == 0];
5300 low = l[WORDS_BIG_ENDIAN != 0];
5302 if (TARGET_32BIT)
5303 return (num_insns_constant_wide (low)
5304 + num_insns_constant_wide (high));
5305 else
5307 if ((high == 0 && low >= 0)
5308 || (high == -1 && low < 0))
5309 return num_insns_constant_wide (low);
5311 else if (mask64_operand (op, mode))
5312 return 2;
5314 else if (low == 0)
5315 return num_insns_constant_wide (high) + 1;
5317 else
5318 return (num_insns_constant_wide (high)
5319 + num_insns_constant_wide (low) + 1);
5322 default:
5323 gcc_unreachable ();
5327 /* Interpret element ELT of the CONST_VECTOR OP as an integer value.
5328 If the mode of OP is MODE_VECTOR_INT, this simply returns the
5329 corresponding element of the vector, but for V4SFmode and V2SFmode,
5330 the corresponding "float" is interpreted as an SImode integer. */
5332 HOST_WIDE_INT
5333 const_vector_elt_as_int (rtx op, unsigned int elt)
5335 rtx tmp;
5337 /* We can't handle V2DImode and V2DFmode vector constants here yet. */
5338 gcc_assert (GET_MODE (op) != V2DImode
5339 && GET_MODE (op) != V2DFmode);
5341 tmp = CONST_VECTOR_ELT (op, elt);
5342 if (GET_MODE (op) == V4SFmode
5343 || GET_MODE (op) == V2SFmode)
5344 tmp = gen_lowpart (SImode, tmp);
5345 return INTVAL (tmp);
5348 /* Return true if OP can be synthesized with a particular vspltisb, vspltish
5349 or vspltisw instruction. OP is a CONST_VECTOR. Which instruction is used
5350 depends on STEP and COPIES, one of which will be 1. If COPIES > 1,
5351 all items are set to the same value and contain COPIES replicas of the
5352 vsplt's operand; if STEP > 1, one in STEP elements is set to the vsplt's
5353 operand and the others are set to the value of the operand's msb. */
5355 static bool
5356 vspltis_constant (rtx op, unsigned step, unsigned copies)
5358 machine_mode mode = GET_MODE (op);
5359 machine_mode inner = GET_MODE_INNER (mode);
5361 unsigned i;
5362 unsigned nunits;
5363 unsigned bitsize;
5364 unsigned mask;
5366 HOST_WIDE_INT val;
5367 HOST_WIDE_INT splat_val;
5368 HOST_WIDE_INT msb_val;
5370 if (mode == V2DImode || mode == V2DFmode || mode == V1TImode)
5371 return false;
5373 nunits = GET_MODE_NUNITS (mode);
5374 bitsize = GET_MODE_BITSIZE (inner);
5375 mask = GET_MODE_MASK (inner);
5377 val = const_vector_elt_as_int (op, BYTES_BIG_ENDIAN ? nunits - 1 : 0);
5378 splat_val = val;
5379 msb_val = val >= 0 ? 0 : -1;
5381 /* Construct the value to be splatted, if possible. If not, return 0. */
5382 for (i = 2; i <= copies; i *= 2)
5384 HOST_WIDE_INT small_val;
5385 bitsize /= 2;
5386 small_val = splat_val >> bitsize;
5387 mask >>= bitsize;
5388 if (splat_val != ((small_val << bitsize) | (small_val & mask)))
5389 return false;
5390 splat_val = small_val;
5393 /* Check if SPLAT_VAL can really be the operand of a vspltis[bhw]. */
5394 if (EASY_VECTOR_15 (splat_val))
5397 /* Also check if we can splat, and then add the result to itself. Do so if
5398 the value is positive, of if the splat instruction is using OP's mode;
5399 for splat_val < 0, the splat and the add should use the same mode. */
5400 else if (EASY_VECTOR_15_ADD_SELF (splat_val)
5401 && (splat_val >= 0 || (step == 1 && copies == 1)))
5404 /* Also check if are loading up the most significant bit which can be done by
5405 loading up -1 and shifting the value left by -1. */
5406 else if (EASY_VECTOR_MSB (splat_val, inner))
5409 else
5410 return false;
5412 /* Check if VAL is present in every STEP-th element, and the
5413 other elements are filled with its most significant bit. */
5414 for (i = 1; i < nunits; ++i)
5416 HOST_WIDE_INT desired_val;
5417 unsigned elt = BYTES_BIG_ENDIAN ? nunits - 1 - i : i;
5418 if ((i & (step - 1)) == 0)
5419 desired_val = val;
5420 else
5421 desired_val = msb_val;
5423 if (desired_val != const_vector_elt_as_int (op, elt))
5424 return false;
5427 return true;
5431 /* Return true if OP is of the given MODE and can be synthesized
5432 with a vspltisb, vspltish or vspltisw. */
5434 bool
5435 easy_altivec_constant (rtx op, machine_mode mode)
5437 unsigned step, copies;
5439 if (mode == VOIDmode)
5440 mode = GET_MODE (op);
5441 else if (mode != GET_MODE (op))
5442 return false;
5444 /* V2DI/V2DF was added with VSX. Only allow 0 and all 1's as easy
5445 constants. */
5446 if (mode == V2DFmode)
5447 return zero_constant (op, mode);
5449 else if (mode == V2DImode)
5451 if (GET_CODE (CONST_VECTOR_ELT (op, 0)) != CONST_INT
5452 || GET_CODE (CONST_VECTOR_ELT (op, 1)) != CONST_INT)
5453 return false;
5455 if (zero_constant (op, mode))
5456 return true;
5458 if (INTVAL (CONST_VECTOR_ELT (op, 0)) == -1
5459 && INTVAL (CONST_VECTOR_ELT (op, 1)) == -1)
5460 return true;
5462 return false;
5465 /* V1TImode is a special container for TImode. Ignore for now. */
5466 else if (mode == V1TImode)
5467 return false;
5469 /* Start with a vspltisw. */
5470 step = GET_MODE_NUNITS (mode) / 4;
5471 copies = 1;
5473 if (vspltis_constant (op, step, copies))
5474 return true;
5476 /* Then try with a vspltish. */
5477 if (step == 1)
5478 copies <<= 1;
5479 else
5480 step >>= 1;
5482 if (vspltis_constant (op, step, copies))
5483 return true;
5485 /* And finally a vspltisb. */
5486 if (step == 1)
5487 copies <<= 1;
5488 else
5489 step >>= 1;
5491 if (vspltis_constant (op, step, copies))
5492 return true;
5494 return false;
5497 /* Generate a VEC_DUPLICATE representing a vspltis[bhw] instruction whose
5498 result is OP. Abort if it is not possible. */
5501 gen_easy_altivec_constant (rtx op)
5503 machine_mode mode = GET_MODE (op);
5504 int nunits = GET_MODE_NUNITS (mode);
5505 rtx val = CONST_VECTOR_ELT (op, BYTES_BIG_ENDIAN ? nunits - 1 : 0);
5506 unsigned step = nunits / 4;
5507 unsigned copies = 1;
5509 /* Start with a vspltisw. */
5510 if (vspltis_constant (op, step, copies))
5511 return gen_rtx_VEC_DUPLICATE (V4SImode, gen_lowpart (SImode, val));
5513 /* Then try with a vspltish. */
5514 if (step == 1)
5515 copies <<= 1;
5516 else
5517 step >>= 1;
5519 if (vspltis_constant (op, step, copies))
5520 return gen_rtx_VEC_DUPLICATE (V8HImode, gen_lowpart (HImode, val));
5522 /* And finally a vspltisb. */
5523 if (step == 1)
5524 copies <<= 1;
5525 else
5526 step >>= 1;
5528 if (vspltis_constant (op, step, copies))
5529 return gen_rtx_VEC_DUPLICATE (V16QImode, gen_lowpart (QImode, val));
5531 gcc_unreachable ();
5534 const char *
5535 output_vec_const_move (rtx *operands)
5537 int cst, cst2;
5538 machine_mode mode;
5539 rtx dest, vec;
5541 dest = operands[0];
5542 vec = operands[1];
5543 mode = GET_MODE (dest);
5545 if (TARGET_VSX)
5547 if (zero_constant (vec, mode))
5548 return "xxlxor %x0,%x0,%x0";
5550 if ((mode == V2DImode || mode == V1TImode)
5551 && INTVAL (CONST_VECTOR_ELT (vec, 0)) == -1
5552 && INTVAL (CONST_VECTOR_ELT (vec, 1)) == -1)
5553 return "vspltisw %0,-1";
5556 if (TARGET_ALTIVEC)
5558 rtx splat_vec;
5559 if (zero_constant (vec, mode))
5560 return "vxor %0,%0,%0";
5562 splat_vec = gen_easy_altivec_constant (vec);
5563 gcc_assert (GET_CODE (splat_vec) == VEC_DUPLICATE);
5564 operands[1] = XEXP (splat_vec, 0);
5565 if (!EASY_VECTOR_15 (INTVAL (operands[1])))
5566 return "#";
5568 switch (GET_MODE (splat_vec))
5570 case V4SImode:
5571 return "vspltisw %0,%1";
5573 case V8HImode:
5574 return "vspltish %0,%1";
5576 case V16QImode:
5577 return "vspltisb %0,%1";
5579 default:
5580 gcc_unreachable ();
5584 gcc_assert (TARGET_SPE);
5586 /* Vector constant 0 is handled as a splitter of V2SI, and in the
5587 pattern of V1DI, V4HI, and V2SF.
5589 FIXME: We should probably return # and add post reload
5590 splitters for these, but this way is so easy ;-). */
5591 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
5592 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
5593 operands[1] = CONST_VECTOR_ELT (vec, 0);
5594 operands[2] = CONST_VECTOR_ELT (vec, 1);
5595 if (cst == cst2)
5596 return "li %0,%1\n\tevmergelo %0,%0,%0";
5597 else if (WORDS_BIG_ENDIAN)
5598 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
5599 else
5600 return "li %0,%2\n\tevmergelo %0,%0,%0\n\tli %0,%1";
5603 /* Initialize TARGET of vector PAIRED to VALS. */
5605 void
5606 paired_expand_vector_init (rtx target, rtx vals)
5608 machine_mode mode = GET_MODE (target);
5609 int n_elts = GET_MODE_NUNITS (mode);
5610 int n_var = 0;
5611 rtx x, new_rtx, tmp, constant_op, op1, op2;
5612 int i;
5614 for (i = 0; i < n_elts; ++i)
5616 x = XVECEXP (vals, 0, i);
5617 if (!(CONST_SCALAR_INT_P (x) || CONST_DOUBLE_P (x) || CONST_FIXED_P (x)))
5618 ++n_var;
5620 if (n_var == 0)
5622 /* Load from constant pool. */
5623 emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
5624 return;
5627 if (n_var == 2)
5629 /* The vector is initialized only with non-constants. */
5630 new_rtx = gen_rtx_VEC_CONCAT (V2SFmode, XVECEXP (vals, 0, 0),
5631 XVECEXP (vals, 0, 1));
5633 emit_move_insn (target, new_rtx);
5634 return;
5637 /* One field is non-constant and the other one is a constant. Load the
5638 constant from the constant pool and use ps_merge instruction to
5639 construct the whole vector. */
5640 op1 = XVECEXP (vals, 0, 0);
5641 op2 = XVECEXP (vals, 0, 1);
5643 constant_op = (CONSTANT_P (op1)) ? op1 : op2;
5645 tmp = gen_reg_rtx (GET_MODE (constant_op));
5646 emit_move_insn (tmp, constant_op);
5648 if (CONSTANT_P (op1))
5649 new_rtx = gen_rtx_VEC_CONCAT (V2SFmode, tmp, op2);
5650 else
5651 new_rtx = gen_rtx_VEC_CONCAT (V2SFmode, op1, tmp);
5653 emit_move_insn (target, new_rtx);
5656 void
5657 paired_expand_vector_move (rtx operands[])
5659 rtx op0 = operands[0], op1 = operands[1];
5661 emit_move_insn (op0, op1);
5664 /* Emit vector compare for code RCODE. DEST is destination, OP1 and
5665 OP2 are two VEC_COND_EXPR operands, CC_OP0 and CC_OP1 are the two
5666 operands for the relation operation COND. This is a recursive
5667 function. */
5669 static void
5670 paired_emit_vector_compare (enum rtx_code rcode,
5671 rtx dest, rtx op0, rtx op1,
5672 rtx cc_op0, rtx cc_op1)
5674 rtx tmp = gen_reg_rtx (V2SFmode);
5675 rtx tmp1, max, min;
5677 gcc_assert (TARGET_PAIRED_FLOAT);
5678 gcc_assert (GET_MODE (op0) == GET_MODE (op1));
5680 switch (rcode)
5682 case LT:
5683 case LTU:
5684 paired_emit_vector_compare (GE, dest, op1, op0, cc_op0, cc_op1);
5685 return;
5686 case GE:
5687 case GEU:
5688 emit_insn (gen_subv2sf3 (tmp, cc_op0, cc_op1));
5689 emit_insn (gen_selv2sf4 (dest, tmp, op0, op1, CONST0_RTX (SFmode)));
5690 return;
5691 case LE:
5692 case LEU:
5693 paired_emit_vector_compare (GE, dest, op0, op1, cc_op1, cc_op0);
5694 return;
5695 case GT:
5696 paired_emit_vector_compare (LE, dest, op1, op0, cc_op0, cc_op1);
5697 return;
5698 case EQ:
5699 tmp1 = gen_reg_rtx (V2SFmode);
5700 max = gen_reg_rtx (V2SFmode);
5701 min = gen_reg_rtx (V2SFmode);
5702 gen_reg_rtx (V2SFmode);
5704 emit_insn (gen_subv2sf3 (tmp, cc_op0, cc_op1));
5705 emit_insn (gen_selv2sf4
5706 (max, tmp, cc_op0, cc_op1, CONST0_RTX (SFmode)));
5707 emit_insn (gen_subv2sf3 (tmp, cc_op1, cc_op0));
5708 emit_insn (gen_selv2sf4
5709 (min, tmp, cc_op0, cc_op1, CONST0_RTX (SFmode)));
5710 emit_insn (gen_subv2sf3 (tmp1, min, max));
5711 emit_insn (gen_selv2sf4 (dest, tmp1, op0, op1, CONST0_RTX (SFmode)));
5712 return;
5713 case NE:
5714 paired_emit_vector_compare (EQ, dest, op1, op0, cc_op0, cc_op1);
5715 return;
5716 case UNLE:
5717 paired_emit_vector_compare (LE, dest, op1, op0, cc_op0, cc_op1);
5718 return;
5719 case UNLT:
5720 paired_emit_vector_compare (LT, dest, op1, op0, cc_op0, cc_op1);
5721 return;
5722 case UNGE:
5723 paired_emit_vector_compare (GE, dest, op1, op0, cc_op0, cc_op1);
5724 return;
5725 case UNGT:
5726 paired_emit_vector_compare (GT, dest, op1, op0, cc_op0, cc_op1);
5727 return;
5728 default:
5729 gcc_unreachable ();
5732 return;
5735 /* Emit vector conditional expression.
5736 DEST is destination. OP1 and OP2 are two VEC_COND_EXPR operands.
5737 CC_OP0 and CC_OP1 are the two operands for the relation operation COND. */
5740 paired_emit_vector_cond_expr (rtx dest, rtx op1, rtx op2,
5741 rtx cond, rtx cc_op0, rtx cc_op1)
5743 enum rtx_code rcode = GET_CODE (cond);
5745 if (!TARGET_PAIRED_FLOAT)
5746 return 0;
5748 paired_emit_vector_compare (rcode, dest, op1, op2, cc_op0, cc_op1);
5750 return 1;
5753 /* Initialize vector TARGET to VALS. */
5755 void
5756 rs6000_expand_vector_init (rtx target, rtx vals)
5758 machine_mode mode = GET_MODE (target);
5759 machine_mode inner_mode = GET_MODE_INNER (mode);
5760 int n_elts = GET_MODE_NUNITS (mode);
5761 int n_var = 0, one_var = -1;
5762 bool all_same = true, all_const_zero = true;
5763 rtx x, mem;
5764 int i;
5766 for (i = 0; i < n_elts; ++i)
5768 x = XVECEXP (vals, 0, i);
5769 if (!(CONST_SCALAR_INT_P (x) || CONST_DOUBLE_P (x) || CONST_FIXED_P (x)))
5770 ++n_var, one_var = i;
5771 else if (x != CONST0_RTX (inner_mode))
5772 all_const_zero = false;
5774 if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
5775 all_same = false;
5778 if (n_var == 0)
5780 rtx const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0));
5781 bool int_vector_p = (GET_MODE_CLASS (mode) == MODE_VECTOR_INT);
5782 if ((int_vector_p || TARGET_VSX) && all_const_zero)
5784 /* Zero register. */
5785 emit_insn (gen_rtx_SET (target, gen_rtx_XOR (mode, target, target)));
5786 return;
5788 else if (int_vector_p && easy_vector_constant (const_vec, mode))
5790 /* Splat immediate. */
5791 emit_insn (gen_rtx_SET (target, const_vec));
5792 return;
5794 else
5796 /* Load from constant pool. */
5797 emit_move_insn (target, const_vec);
5798 return;
5802 /* Double word values on VSX can use xxpermdi or lxvdsx. */
5803 if (VECTOR_MEM_VSX_P (mode) && (mode == V2DFmode || mode == V2DImode))
5805 rtx op0 = XVECEXP (vals, 0, 0);
5806 rtx op1 = XVECEXP (vals, 0, 1);
5807 if (all_same)
5809 if (!MEM_P (op0) && !REG_P (op0))
5810 op0 = force_reg (inner_mode, op0);
5811 if (mode == V2DFmode)
5812 emit_insn (gen_vsx_splat_v2df (target, op0));
5813 else
5814 emit_insn (gen_vsx_splat_v2di (target, op0));
5816 else
5818 op0 = force_reg (inner_mode, op0);
5819 op1 = force_reg (inner_mode, op1);
5820 if (mode == V2DFmode)
5821 emit_insn (gen_vsx_concat_v2df (target, op0, op1));
5822 else
5823 emit_insn (gen_vsx_concat_v2di (target, op0, op1));
5825 return;
5828 /* With single precision floating point on VSX, know that internally single
5829 precision is actually represented as a double, and either make 2 V2DF
5830 vectors, and convert these vectors to single precision, or do one
5831 conversion, and splat the result to the other elements. */
5832 if (mode == V4SFmode && VECTOR_MEM_VSX_P (mode))
5834 if (all_same)
5836 rtx freg = gen_reg_rtx (V4SFmode);
5837 rtx sreg = force_reg (SFmode, XVECEXP (vals, 0, 0));
5838 rtx cvt = ((TARGET_XSCVDPSPN)
5839 ? gen_vsx_xscvdpspn_scalar (freg, sreg)
5840 : gen_vsx_xscvdpsp_scalar (freg, sreg));
5842 emit_insn (cvt);
5843 emit_insn (gen_vsx_xxspltw_v4sf_direct (target, freg, const0_rtx));
5845 else
5847 rtx dbl_even = gen_reg_rtx (V2DFmode);
5848 rtx dbl_odd = gen_reg_rtx (V2DFmode);
5849 rtx flt_even = gen_reg_rtx (V4SFmode);
5850 rtx flt_odd = gen_reg_rtx (V4SFmode);
5851 rtx op0 = force_reg (SFmode, XVECEXP (vals, 0, 0));
5852 rtx op1 = force_reg (SFmode, XVECEXP (vals, 0, 1));
5853 rtx op2 = force_reg (SFmode, XVECEXP (vals, 0, 2));
5854 rtx op3 = force_reg (SFmode, XVECEXP (vals, 0, 3));
5856 emit_insn (gen_vsx_concat_v2sf (dbl_even, op0, op1));
5857 emit_insn (gen_vsx_concat_v2sf (dbl_odd, op2, op3));
5858 emit_insn (gen_vsx_xvcvdpsp (flt_even, dbl_even));
5859 emit_insn (gen_vsx_xvcvdpsp (flt_odd, dbl_odd));
5860 rs6000_expand_extract_even (target, flt_even, flt_odd);
5862 return;
5865 /* Store value to stack temp. Load vector element. Splat. However, splat
5866 of 64-bit items is not supported on Altivec. */
5867 if (all_same && GET_MODE_SIZE (inner_mode) <= 4)
5869 mem = assign_stack_temp (mode, GET_MODE_SIZE (inner_mode));
5870 emit_move_insn (adjust_address_nv (mem, inner_mode, 0),
5871 XVECEXP (vals, 0, 0));
5872 x = gen_rtx_UNSPEC (VOIDmode,
5873 gen_rtvec (1, const0_rtx), UNSPEC_LVE);
5874 emit_insn (gen_rtx_PARALLEL (VOIDmode,
5875 gen_rtvec (2,
5876 gen_rtx_SET (target, mem),
5877 x)));
5878 x = gen_rtx_VEC_SELECT (inner_mode, target,
5879 gen_rtx_PARALLEL (VOIDmode,
5880 gen_rtvec (1, const0_rtx)));
5881 emit_insn (gen_rtx_SET (target, gen_rtx_VEC_DUPLICATE (mode, x)));
5882 return;
5885 /* One field is non-constant. Load constant then overwrite
5886 varying field. */
5887 if (n_var == 1)
5889 rtx copy = copy_rtx (vals);
5891 /* Load constant part of vector, substitute neighboring value for
5892 varying element. */
5893 XVECEXP (copy, 0, one_var) = XVECEXP (vals, 0, (one_var + 1) % n_elts);
5894 rs6000_expand_vector_init (target, copy);
5896 /* Insert variable. */
5897 rs6000_expand_vector_set (target, XVECEXP (vals, 0, one_var), one_var);
5898 return;
5901 /* Construct the vector in memory one field at a time
5902 and load the whole vector. */
5903 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
5904 for (i = 0; i < n_elts; i++)
5905 emit_move_insn (adjust_address_nv (mem, inner_mode,
5906 i * GET_MODE_SIZE (inner_mode)),
5907 XVECEXP (vals, 0, i));
5908 emit_move_insn (target, mem);
5911 /* Set field ELT of TARGET to VAL. */
5913 void
5914 rs6000_expand_vector_set (rtx target, rtx val, int elt)
5916 machine_mode mode = GET_MODE (target);
5917 machine_mode inner_mode = GET_MODE_INNER (mode);
5918 rtx reg = gen_reg_rtx (mode);
5919 rtx mask, mem, x;
5920 int width = GET_MODE_SIZE (inner_mode);
5921 int i;
5923 if (VECTOR_MEM_VSX_P (mode) && (mode == V2DFmode || mode == V2DImode))
5925 rtx (*set_func) (rtx, rtx, rtx, rtx)
5926 = ((mode == V2DFmode) ? gen_vsx_set_v2df : gen_vsx_set_v2di);
5927 emit_insn (set_func (target, target, val, GEN_INT (elt)));
5928 return;
5931 /* Simplify setting single element vectors like V1TImode. */
5932 if (GET_MODE_SIZE (mode) == GET_MODE_SIZE (inner_mode) && elt == 0)
5934 emit_move_insn (target, gen_lowpart (mode, val));
5935 return;
5938 /* Load single variable value. */
5939 mem = assign_stack_temp (mode, GET_MODE_SIZE (inner_mode));
5940 emit_move_insn (adjust_address_nv (mem, inner_mode, 0), val);
5941 x = gen_rtx_UNSPEC (VOIDmode,
5942 gen_rtvec (1, const0_rtx), UNSPEC_LVE);
5943 emit_insn (gen_rtx_PARALLEL (VOIDmode,
5944 gen_rtvec (2,
5945 gen_rtx_SET (reg, mem),
5946 x)));
5948 /* Linear sequence. */
5949 mask = gen_rtx_PARALLEL (V16QImode, rtvec_alloc (16));
5950 for (i = 0; i < 16; ++i)
5951 XVECEXP (mask, 0, i) = GEN_INT (i);
5953 /* Set permute mask to insert element into target. */
5954 for (i = 0; i < width; ++i)
5955 XVECEXP (mask, 0, elt*width + i)
5956 = GEN_INT (i + 0x10);
5957 x = gen_rtx_CONST_VECTOR (V16QImode, XVEC (mask, 0));
5959 if (BYTES_BIG_ENDIAN)
5960 x = gen_rtx_UNSPEC (mode,
5961 gen_rtvec (3, target, reg,
5962 force_reg (V16QImode, x)),
5963 UNSPEC_VPERM);
5964 else
5966 /* Invert selector. We prefer to generate VNAND on P8 so
5967 that future fusion opportunities can kick in, but must
5968 generate VNOR elsewhere. */
5969 rtx notx = gen_rtx_NOT (V16QImode, force_reg (V16QImode, x));
5970 rtx iorx = (TARGET_P8_VECTOR
5971 ? gen_rtx_IOR (V16QImode, notx, notx)
5972 : gen_rtx_AND (V16QImode, notx, notx));
5973 rtx tmp = gen_reg_rtx (V16QImode);
5974 emit_insn (gen_rtx_SET (tmp, iorx));
5976 /* Permute with operands reversed and adjusted selector. */
5977 x = gen_rtx_UNSPEC (mode, gen_rtvec (3, reg, target, tmp),
5978 UNSPEC_VPERM);
5981 emit_insn (gen_rtx_SET (target, x));
5984 /* Extract field ELT from VEC into TARGET. */
5986 void
5987 rs6000_expand_vector_extract (rtx target, rtx vec, int elt)
5989 machine_mode mode = GET_MODE (vec);
5990 machine_mode inner_mode = GET_MODE_INNER (mode);
5991 rtx mem;
5993 if (VECTOR_MEM_VSX_P (mode))
5995 switch (mode)
5997 default:
5998 break;
5999 case V1TImode:
6000 gcc_assert (elt == 0 && inner_mode == TImode);
6001 emit_move_insn (target, gen_lowpart (TImode, vec));
6002 break;
6003 case V2DFmode:
6004 emit_insn (gen_vsx_extract_v2df (target, vec, GEN_INT (elt)));
6005 return;
6006 case V2DImode:
6007 emit_insn (gen_vsx_extract_v2di (target, vec, GEN_INT (elt)));
6008 return;
6009 case V4SFmode:
6010 emit_insn (gen_vsx_extract_v4sf (target, vec, GEN_INT (elt)));
6011 return;
6015 /* Allocate mode-sized buffer. */
6016 mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
6018 emit_move_insn (mem, vec);
6020 /* Add offset to field within buffer matching vector element. */
6021 mem = adjust_address_nv (mem, inner_mode, elt * GET_MODE_SIZE (inner_mode));
6023 emit_move_insn (target, adjust_address_nv (mem, inner_mode, 0));
6026 /* Generates shifts and masks for a pair of rldicl or rldicr insns to
6027 implement ANDing by the mask IN. */
6028 void
6029 build_mask64_2_operands (rtx in, rtx *out)
6031 unsigned HOST_WIDE_INT c, lsb, m1, m2;
6032 int shift;
6034 gcc_assert (GET_CODE (in) == CONST_INT);
6036 c = INTVAL (in);
6037 if (c & 1)
6039 /* Assume c initially something like 0x00fff000000fffff. The idea
6040 is to rotate the word so that the middle ^^^^^^ group of zeros
6041 is at the MS end and can be cleared with an rldicl mask. We then
6042 rotate back and clear off the MS ^^ group of zeros with a
6043 second rldicl. */
6044 c = ~c; /* c == 0xff000ffffff00000 */
6045 lsb = c & -c; /* lsb == 0x0000000000100000 */
6046 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
6047 c = ~c; /* c == 0x00fff000000fffff */
6048 c &= -lsb; /* c == 0x00fff00000000000 */
6049 lsb = c & -c; /* lsb == 0x0000100000000000 */
6050 c = ~c; /* c == 0xff000fffffffffff */
6051 c &= -lsb; /* c == 0xff00000000000000 */
6052 shift = 0;
6053 while ((lsb >>= 1) != 0)
6054 shift++; /* shift == 44 on exit from loop */
6055 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
6056 m1 = ~m1; /* m1 == 0x000000ffffffffff */
6057 m2 = ~c; /* m2 == 0x00ffffffffffffff */
6059 else
6061 /* Assume c initially something like 0xff000f0000000000. The idea
6062 is to rotate the word so that the ^^^ middle group of zeros
6063 is at the LS end and can be cleared with an rldicr mask. We then
6064 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
6065 a second rldicr. */
6066 lsb = c & -c; /* lsb == 0x0000010000000000 */
6067 m2 = -lsb; /* m2 == 0xffffff0000000000 */
6068 c = ~c; /* c == 0x00fff0ffffffffff */
6069 c &= -lsb; /* c == 0x00fff00000000000 */
6070 lsb = c & -c; /* lsb == 0x0000100000000000 */
6071 c = ~c; /* c == 0xff000fffffffffff */
6072 c &= -lsb; /* c == 0xff00000000000000 */
6073 shift = 0;
6074 while ((lsb >>= 1) != 0)
6075 shift++; /* shift == 44 on exit from loop */
6076 m1 = ~c; /* m1 == 0x00ffffffffffffff */
6077 m1 >>= shift; /* m1 == 0x0000000000000fff */
6078 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
6081 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
6082 masks will be all 1's. We are guaranteed more than one transition. */
6083 out[0] = GEN_INT (64 - shift);
6084 out[1] = GEN_INT (m1);
6085 out[2] = GEN_INT (shift);
6086 out[3] = GEN_INT (m2);
6089 /* Return TRUE if OP is an invalid SUBREG operation on the e500. */
6091 bool
6092 invalid_e500_subreg (rtx op, machine_mode mode)
6094 if (TARGET_E500_DOUBLE)
6096 /* Reject (subreg:SI (reg:DF)); likewise with subreg:DI or
6097 subreg:TI and reg:TF. Decimal float modes are like integer
6098 modes (only low part of each register used) for this
6099 purpose. */
6100 if (GET_CODE (op) == SUBREG
6101 && (mode == SImode || mode == DImode || mode == TImode
6102 || mode == DDmode || mode == TDmode || mode == PTImode)
6103 && REG_P (SUBREG_REG (op))
6104 && (GET_MODE (SUBREG_REG (op)) == DFmode
6105 || GET_MODE (SUBREG_REG (op)) == TFmode))
6106 return true;
6108 /* Reject (subreg:DF (reg:DI)); likewise with subreg:TF and
6109 reg:TI. */
6110 if (GET_CODE (op) == SUBREG
6111 && (mode == DFmode || mode == TFmode)
6112 && REG_P (SUBREG_REG (op))
6113 && (GET_MODE (SUBREG_REG (op)) == DImode
6114 || GET_MODE (SUBREG_REG (op)) == TImode
6115 || GET_MODE (SUBREG_REG (op)) == PTImode
6116 || GET_MODE (SUBREG_REG (op)) == DDmode
6117 || GET_MODE (SUBREG_REG (op)) == TDmode))
6118 return true;
6121 if (TARGET_SPE
6122 && GET_CODE (op) == SUBREG
6123 && mode == SImode
6124 && REG_P (SUBREG_REG (op))
6125 && SPE_VECTOR_MODE (GET_MODE (SUBREG_REG (op))))
6126 return true;
6128 return false;
6131 /* Return alignment of TYPE. Existing alignment is ALIGN. HOW
6132 selects whether the alignment is abi mandated, optional, or
6133 both abi and optional alignment. */
6135 unsigned int
6136 rs6000_data_alignment (tree type, unsigned int align, enum data_align how)
6138 if (how != align_opt)
6140 if (TREE_CODE (type) == VECTOR_TYPE)
6142 if ((TARGET_SPE && SPE_VECTOR_MODE (TYPE_MODE (type)))
6143 || (TARGET_PAIRED_FLOAT && PAIRED_VECTOR_MODE (TYPE_MODE (type))))
6145 if (align < 64)
6146 align = 64;
6148 else if (align < 128)
6149 align = 128;
6151 else if (TARGET_E500_DOUBLE
6152 && TREE_CODE (type) == REAL_TYPE
6153 && TYPE_MODE (type) == DFmode)
6155 if (align < 64)
6156 align = 64;
6160 if (how != align_abi)
6162 if (TREE_CODE (type) == ARRAY_TYPE
6163 && TYPE_MODE (TREE_TYPE (type)) == QImode)
6165 if (align < BITS_PER_WORD)
6166 align = BITS_PER_WORD;
6170 return align;
6173 /* Previous GCC releases forced all vector types to have 16-byte alignment. */
6175 bool
6176 rs6000_special_adjust_field_align_p (tree field, unsigned int computed)
6178 if (TARGET_ALTIVEC && TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
6180 if (computed != 128)
6182 static bool warned;
6183 if (!warned && warn_psabi)
6185 warned = true;
6186 inform (input_location,
6187 "the layout of aggregates containing vectors with"
6188 " %d-byte alignment has changed in GCC 5",
6189 computed / BITS_PER_UNIT);
6192 /* In current GCC there is no special case. */
6193 return false;
6196 return false;
6199 /* AIX increases natural record alignment to doubleword if the first
6200 field is an FP double while the FP fields remain word aligned. */
6202 unsigned int
6203 rs6000_special_round_type_align (tree type, unsigned int computed,
6204 unsigned int specified)
6206 unsigned int align = MAX (computed, specified);
6207 tree field = TYPE_FIELDS (type);
6209 /* Skip all non field decls */
6210 while (field != NULL && TREE_CODE (field) != FIELD_DECL)
6211 field = DECL_CHAIN (field);
6213 if (field != NULL && field != type)
6215 type = TREE_TYPE (field);
6216 while (TREE_CODE (type) == ARRAY_TYPE)
6217 type = TREE_TYPE (type);
6219 if (type != error_mark_node && TYPE_MODE (type) == DFmode)
6220 align = MAX (align, 64);
6223 return align;
6226 /* Darwin increases record alignment to the natural alignment of
6227 the first field. */
6229 unsigned int
6230 darwin_rs6000_special_round_type_align (tree type, unsigned int computed,
6231 unsigned int specified)
6233 unsigned int align = MAX (computed, specified);
6235 if (TYPE_PACKED (type))
6236 return align;
6238 /* Find the first field, looking down into aggregates. */
6239 do {
6240 tree field = TYPE_FIELDS (type);
6241 /* Skip all non field decls */
6242 while (field != NULL && TREE_CODE (field) != FIELD_DECL)
6243 field = DECL_CHAIN (field);
6244 if (! field)
6245 break;
6246 /* A packed field does not contribute any extra alignment. */
6247 if (DECL_PACKED (field))
6248 return align;
6249 type = TREE_TYPE (field);
6250 while (TREE_CODE (type) == ARRAY_TYPE)
6251 type = TREE_TYPE (type);
6252 } while (AGGREGATE_TYPE_P (type));
6254 if (! AGGREGATE_TYPE_P (type) && type != error_mark_node)
6255 align = MAX (align, TYPE_ALIGN (type));
6257 return align;
6260 /* Return 1 for an operand in small memory on V.4/eabi. */
6263 small_data_operand (rtx op ATTRIBUTE_UNUSED,
6264 machine_mode mode ATTRIBUTE_UNUSED)
6266 #if TARGET_ELF
6267 rtx sym_ref;
6269 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
6270 return 0;
6272 if (DEFAULT_ABI != ABI_V4)
6273 return 0;
6275 /* Vector and float memory instructions have a limited offset on the
6276 SPE, so using a vector or float variable directly as an operand is
6277 not useful. */
6278 if (TARGET_SPE
6279 && (SPE_VECTOR_MODE (mode) || FLOAT_MODE_P (mode)))
6280 return 0;
6282 if (GET_CODE (op) == SYMBOL_REF)
6283 sym_ref = op;
6285 else if (GET_CODE (op) != CONST
6286 || GET_CODE (XEXP (op, 0)) != PLUS
6287 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
6288 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
6289 return 0;
6291 else
6293 rtx sum = XEXP (op, 0);
6294 HOST_WIDE_INT summand;
6296 /* We have to be careful here, because it is the referenced address
6297 that must be 32k from _SDA_BASE_, not just the symbol. */
6298 summand = INTVAL (XEXP (sum, 1));
6299 if (summand < 0 || summand > g_switch_value)
6300 return 0;
6302 sym_ref = XEXP (sum, 0);
6305 return SYMBOL_REF_SMALL_P (sym_ref);
6306 #else
6307 return 0;
6308 #endif
6311 /* Return true if either operand is a general purpose register. */
6313 bool
6314 gpr_or_gpr_p (rtx op0, rtx op1)
6316 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
6317 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
6320 /* Return true if this is a move direct operation between GPR registers and
6321 floating point/VSX registers. */
6323 bool
6324 direct_move_p (rtx op0, rtx op1)
6326 int regno0, regno1;
6328 if (!REG_P (op0) || !REG_P (op1))
6329 return false;
6331 if (!TARGET_DIRECT_MOVE && !TARGET_MFPGPR)
6332 return false;
6334 regno0 = REGNO (op0);
6335 regno1 = REGNO (op1);
6336 if (regno0 >= FIRST_PSEUDO_REGISTER || regno1 >= FIRST_PSEUDO_REGISTER)
6337 return false;
6339 if (INT_REGNO_P (regno0))
6340 return (TARGET_DIRECT_MOVE) ? VSX_REGNO_P (regno1) : FP_REGNO_P (regno1);
6342 else if (INT_REGNO_P (regno1))
6344 if (TARGET_MFPGPR && FP_REGNO_P (regno0))
6345 return true;
6347 else if (TARGET_DIRECT_MOVE && VSX_REGNO_P (regno0))
6348 return true;
6351 return false;
6354 /* Return true if this is a load or store quad operation. This function does
6355 not handle the atomic quad memory instructions. */
6357 bool
6358 quad_load_store_p (rtx op0, rtx op1)
6360 bool ret;
6362 if (!TARGET_QUAD_MEMORY)
6363 ret = false;
6365 else if (REG_P (op0) && MEM_P (op1))
6366 ret = (quad_int_reg_operand (op0, GET_MODE (op0))
6367 && quad_memory_operand (op1, GET_MODE (op1))
6368 && !reg_overlap_mentioned_p (op0, op1));
6370 else if (MEM_P (op0) && REG_P (op1))
6371 ret = (quad_memory_operand (op0, GET_MODE (op0))
6372 && quad_int_reg_operand (op1, GET_MODE (op1)));
6374 else
6375 ret = false;
6377 if (TARGET_DEBUG_ADDR)
6379 fprintf (stderr, "\n========== quad_load_store, return %s\n",
6380 ret ? "true" : "false");
6381 debug_rtx (gen_rtx_SET (op0, op1));
6384 return ret;
6387 /* Given an address, return a constant offset term if one exists. */
6389 static rtx
6390 address_offset (rtx op)
6392 if (GET_CODE (op) == PRE_INC
6393 || GET_CODE (op) == PRE_DEC)
6394 op = XEXP (op, 0);
6395 else if (GET_CODE (op) == PRE_MODIFY
6396 || GET_CODE (op) == LO_SUM)
6397 op = XEXP (op, 1);
6399 if (GET_CODE (op) == CONST)
6400 op = XEXP (op, 0);
6402 if (GET_CODE (op) == PLUS)
6403 op = XEXP (op, 1);
6405 if (CONST_INT_P (op))
6406 return op;
6408 return NULL_RTX;
6411 /* Return true if the MEM operand is a memory operand suitable for use
6412 with a (full width, possibly multiple) gpr load/store. On
6413 powerpc64 this means the offset must be divisible by 4.
6414 Implements 'Y' constraint.
6416 Accept direct, indexed, offset, lo_sum and tocref. Since this is
6417 a constraint function we know the operand has satisfied a suitable
6418 memory predicate. Also accept some odd rtl generated by reload
6419 (see rs6000_legitimize_reload_address for various forms). It is
6420 important that reload rtl be accepted by appropriate constraints
6421 but not by the operand predicate.
6423 Offsetting a lo_sum should not be allowed, except where we know by
6424 alignment that a 32k boundary is not crossed, but see the ???
6425 comment in rs6000_legitimize_reload_address. Note that by
6426 "offsetting" here we mean a further offset to access parts of the
6427 MEM. It's fine to have a lo_sum where the inner address is offset
6428 from a sym, since the same sym+offset will appear in the high part
6429 of the address calculation. */
6431 bool
6432 mem_operand_gpr (rtx op, machine_mode mode)
6434 unsigned HOST_WIDE_INT offset;
6435 int extra;
6436 rtx addr = XEXP (op, 0);
6438 op = address_offset (addr);
6439 if (op == NULL_RTX)
6440 return true;
6442 offset = INTVAL (op);
6443 if (TARGET_POWERPC64 && (offset & 3) != 0)
6444 return false;
6446 extra = GET_MODE_SIZE (mode) - UNITS_PER_WORD;
6447 if (extra < 0)
6448 extra = 0;
6450 if (GET_CODE (addr) == LO_SUM)
6451 /* For lo_sum addresses, we must allow any offset except one that
6452 causes a wrap, so test only the low 16 bits. */
6453 offset = ((offset & 0xffff) ^ 0x8000) - 0x8000;
6455 return offset + 0x8000 < 0x10000u - extra;
6458 /* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address_p. */
6460 static bool
6461 reg_offset_addressing_ok_p (machine_mode mode)
6463 switch (mode)
6465 case V16QImode:
6466 case V8HImode:
6467 case V4SFmode:
6468 case V4SImode:
6469 case V2DFmode:
6470 case V2DImode:
6471 case V1TImode:
6472 case TImode:
6473 /* AltiVec/VSX vector modes. Only reg+reg addressing is valid. While
6474 TImode is not a vector mode, if we want to use the VSX registers to
6475 move it around, we need to restrict ourselves to reg+reg
6476 addressing. */
6477 if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
6478 return false;
6479 break;
6481 case V4HImode:
6482 case V2SImode:
6483 case V1DImode:
6484 case V2SFmode:
6485 /* Paired vector modes. Only reg+reg addressing is valid. */
6486 if (TARGET_PAIRED_FLOAT)
6487 return false;
6488 break;
6490 case SDmode:
6491 /* If we can do direct load/stores of SDmode, restrict it to reg+reg
6492 addressing for the LFIWZX and STFIWX instructions. */
6493 if (TARGET_NO_SDMODE_STACK)
6494 return false;
6495 break;
6497 default:
6498 break;
6501 return true;
6504 static bool
6505 virtual_stack_registers_memory_p (rtx op)
6507 int regnum;
6509 if (GET_CODE (op) == REG)
6510 regnum = REGNO (op);
6512 else if (GET_CODE (op) == PLUS
6513 && GET_CODE (XEXP (op, 0)) == REG
6514 && GET_CODE (XEXP (op, 1)) == CONST_INT)
6515 regnum = REGNO (XEXP (op, 0));
6517 else
6518 return false;
6520 return (regnum >= FIRST_VIRTUAL_REGISTER
6521 && regnum <= LAST_VIRTUAL_POINTER_REGISTER);
6524 /* Return true if a MODE sized memory accesses to OP plus OFFSET
6525 is known to not straddle a 32k boundary. This function is used
6526 to determine whether -mcmodel=medium code can use TOC pointer
6527 relative addressing for OP. This means the alignment of the TOC
6528 pointer must also be taken into account, and unfortunately that is
6529 only 8 bytes. */
6531 #ifndef POWERPC64_TOC_POINTER_ALIGNMENT
6532 #define POWERPC64_TOC_POINTER_ALIGNMENT 8
6533 #endif
6535 static bool
6536 offsettable_ok_by_alignment (rtx op, HOST_WIDE_INT offset,
6537 machine_mode mode)
6539 tree decl;
6540 unsigned HOST_WIDE_INT dsize, dalign, lsb, mask;
6542 if (GET_CODE (op) != SYMBOL_REF)
6543 return false;
6545 dsize = GET_MODE_SIZE (mode);
6546 decl = SYMBOL_REF_DECL (op);
6547 if (!decl)
6549 if (dsize == 0)
6550 return false;
6552 /* -fsection-anchors loses the original SYMBOL_REF_DECL when
6553 replacing memory addresses with an anchor plus offset. We
6554 could find the decl by rummaging around in the block->objects
6555 VEC for the given offset but that seems like too much work. */
6556 dalign = BITS_PER_UNIT;
6557 if (SYMBOL_REF_HAS_BLOCK_INFO_P (op)
6558 && SYMBOL_REF_ANCHOR_P (op)
6559 && SYMBOL_REF_BLOCK (op) != NULL)
6561 struct object_block *block = SYMBOL_REF_BLOCK (op);
6563 dalign = block->alignment;
6564 offset += SYMBOL_REF_BLOCK_OFFSET (op);
6566 else if (CONSTANT_POOL_ADDRESS_P (op))
6568 /* It would be nice to have get_pool_align().. */
6569 machine_mode cmode = get_pool_mode (op);
6571 dalign = GET_MODE_ALIGNMENT (cmode);
6574 else if (DECL_P (decl))
6576 dalign = DECL_ALIGN (decl);
6578 if (dsize == 0)
6580 /* Allow BLKmode when the entire object is known to not
6581 cross a 32k boundary. */
6582 if (!DECL_SIZE_UNIT (decl))
6583 return false;
6585 if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl)))
6586 return false;
6588 dsize = tree_to_uhwi (DECL_SIZE_UNIT (decl));
6589 if (dsize > 32768)
6590 return false;
6592 dalign /= BITS_PER_UNIT;
6593 if (dalign > POWERPC64_TOC_POINTER_ALIGNMENT)
6594 dalign = POWERPC64_TOC_POINTER_ALIGNMENT;
6595 return dalign >= dsize;
6598 else
6599 gcc_unreachable ();
6601 /* Find how many bits of the alignment we know for this access. */
6602 dalign /= BITS_PER_UNIT;
6603 if (dalign > POWERPC64_TOC_POINTER_ALIGNMENT)
6604 dalign = POWERPC64_TOC_POINTER_ALIGNMENT;
6605 mask = dalign - 1;
6606 lsb = offset & -offset;
6607 mask &= lsb - 1;
6608 dalign = mask + 1;
6610 return dalign >= dsize;
6613 static bool
6614 constant_pool_expr_p (rtx op)
6616 rtx base, offset;
6618 split_const (op, &base, &offset);
6619 return (GET_CODE (base) == SYMBOL_REF
6620 && CONSTANT_POOL_ADDRESS_P (base)
6621 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (base), Pmode));
6624 static const_rtx tocrel_base, tocrel_offset;
6626 /* Return true if OP is a toc pointer relative address (the output
6627 of create_TOC_reference). If STRICT, do not match high part or
6628 non-split -mcmodel=large/medium toc pointer relative addresses. */
6630 bool
6631 toc_relative_expr_p (const_rtx op, bool strict)
6633 if (!TARGET_TOC)
6634 return false;
6636 if (TARGET_CMODEL != CMODEL_SMALL)
6638 /* Only match the low part. */
6639 if (GET_CODE (op) == LO_SUM
6640 && REG_P (XEXP (op, 0))
6641 && INT_REG_OK_FOR_BASE_P (XEXP (op, 0), strict))
6642 op = XEXP (op, 1);
6643 else if (strict)
6644 return false;
6647 tocrel_base = op;
6648 tocrel_offset = const0_rtx;
6649 if (GET_CODE (op) == PLUS && add_cint_operand (XEXP (op, 1), GET_MODE (op)))
6651 tocrel_base = XEXP (op, 0);
6652 tocrel_offset = XEXP (op, 1);
6655 return (GET_CODE (tocrel_base) == UNSPEC
6656 && XINT (tocrel_base, 1) == UNSPEC_TOCREL);
6659 /* Return true if X is a constant pool address, and also for cmodel=medium
6660 if X is a toc-relative address known to be offsettable within MODE. */
6662 bool
6663 legitimate_constant_pool_address_p (const_rtx x, machine_mode mode,
6664 bool strict)
6666 return (toc_relative_expr_p (x, strict)
6667 && (TARGET_CMODEL != CMODEL_MEDIUM
6668 || constant_pool_expr_p (XVECEXP (tocrel_base, 0, 0))
6669 || mode == QImode
6670 || offsettable_ok_by_alignment (XVECEXP (tocrel_base, 0, 0),
6671 INTVAL (tocrel_offset), mode)));
6674 static bool
6675 legitimate_small_data_p (machine_mode mode, rtx x)
6677 return (DEFAULT_ABI == ABI_V4
6678 && !flag_pic && !TARGET_TOC
6679 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
6680 && small_data_operand (x, mode));
6683 /* SPE offset addressing is limited to 5-bits worth of double words. */
6684 #define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
6686 bool
6687 rs6000_legitimate_offset_address_p (machine_mode mode, rtx x,
6688 bool strict, bool worst_case)
6690 unsigned HOST_WIDE_INT offset;
6691 unsigned int extra;
6693 if (GET_CODE (x) != PLUS)
6694 return false;
6695 if (!REG_P (XEXP (x, 0)))
6696 return false;
6697 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
6698 return false;
6699 if (!reg_offset_addressing_ok_p (mode))
6700 return virtual_stack_registers_memory_p (x);
6701 if (legitimate_constant_pool_address_p (x, mode, strict || lra_in_progress))
6702 return true;
6703 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
6704 return false;
6706 offset = INTVAL (XEXP (x, 1));
6707 extra = 0;
6708 switch (mode)
6710 case V4HImode:
6711 case V2SImode:
6712 case V1DImode:
6713 case V2SFmode:
6714 /* SPE vector modes. */
6715 return SPE_CONST_OFFSET_OK (offset);
6717 case DFmode:
6718 case DDmode:
6719 case DImode:
6720 /* On e500v2, we may have:
6722 (subreg:DF (mem:DI (plus (reg) (const_int))) 0).
6724 Which gets addressed with evldd instructions. */
6725 if (TARGET_E500_DOUBLE)
6726 return SPE_CONST_OFFSET_OK (offset);
6728 /* If we are using VSX scalar loads, restrict ourselves to reg+reg
6729 addressing. */
6730 if (VECTOR_MEM_VSX_P (mode))
6731 return false;
6733 if (!worst_case)
6734 break;
6735 if (!TARGET_POWERPC64)
6736 extra = 4;
6737 else if (offset & 3)
6738 return false;
6739 break;
6741 case TFmode:
6742 if (TARGET_E500_DOUBLE)
6743 return (SPE_CONST_OFFSET_OK (offset)
6744 && SPE_CONST_OFFSET_OK (offset + 8));
6745 /* fall through */
6747 case TDmode:
6748 case TImode:
6749 case PTImode:
6750 extra = 8;
6751 if (!worst_case)
6752 break;
6753 if (!TARGET_POWERPC64)
6754 extra = 12;
6755 else if (offset & 3)
6756 return false;
6757 break;
6759 default:
6760 break;
6763 offset += 0x8000;
6764 return offset < 0x10000 - extra;
6767 bool
6768 legitimate_indexed_address_p (rtx x, int strict)
6770 rtx op0, op1;
6772 if (GET_CODE (x) != PLUS)
6773 return false;
6775 op0 = XEXP (x, 0);
6776 op1 = XEXP (x, 1);
6778 /* Recognize the rtl generated by reload which we know will later be
6779 replaced with proper base and index regs. */
6780 if (!strict
6781 && reload_in_progress
6782 && (REG_P (op0) || GET_CODE (op0) == PLUS)
6783 && REG_P (op1))
6784 return true;
6786 return (REG_P (op0) && REG_P (op1)
6787 && ((INT_REG_OK_FOR_BASE_P (op0, strict)
6788 && INT_REG_OK_FOR_INDEX_P (op1, strict))
6789 || (INT_REG_OK_FOR_BASE_P (op1, strict)
6790 && INT_REG_OK_FOR_INDEX_P (op0, strict))));
6793 bool
6794 avoiding_indexed_address_p (machine_mode mode)
6796 /* Avoid indexed addressing for modes that have non-indexed
6797 load/store instruction forms. */
6798 return (TARGET_AVOID_XFORM && VECTOR_MEM_NONE_P (mode));
6801 bool
6802 legitimate_indirect_address_p (rtx x, int strict)
6804 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
6807 bool
6808 macho_lo_sum_memory_operand (rtx x, machine_mode mode)
6810 if (!TARGET_MACHO || !flag_pic
6811 || mode != SImode || GET_CODE (x) != MEM)
6812 return false;
6813 x = XEXP (x, 0);
6815 if (GET_CODE (x) != LO_SUM)
6816 return false;
6817 if (GET_CODE (XEXP (x, 0)) != REG)
6818 return false;
6819 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
6820 return false;
6821 x = XEXP (x, 1);
6823 return CONSTANT_P (x);
6826 static bool
6827 legitimate_lo_sum_address_p (machine_mode mode, rtx x, int strict)
6829 if (GET_CODE (x) != LO_SUM)
6830 return false;
6831 if (GET_CODE (XEXP (x, 0)) != REG)
6832 return false;
6833 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
6834 return false;
6835 /* Restrict addressing for DI because of our SUBREG hackery. */
6836 if (TARGET_E500_DOUBLE && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
6837 return false;
6838 x = XEXP (x, 1);
6840 if (TARGET_ELF || TARGET_MACHO)
6842 bool large_toc_ok;
6844 if (DEFAULT_ABI == ABI_V4 && flag_pic)
6845 return false;
6846 /* LRA don't use LEGITIMIZE_RELOAD_ADDRESS as it usually calls
6847 push_reload from reload pass code. LEGITIMIZE_RELOAD_ADDRESS
6848 recognizes some LO_SUM addresses as valid although this
6849 function says opposite. In most cases, LRA through different
6850 transformations can generate correct code for address reloads.
6851 It can not manage only some LO_SUM cases. So we need to add
6852 code analogous to one in rs6000_legitimize_reload_address for
6853 LOW_SUM here saying that some addresses are still valid. */
6854 large_toc_ok = (lra_in_progress && TARGET_CMODEL != CMODEL_SMALL
6855 && small_toc_ref (x, VOIDmode));
6856 if (TARGET_TOC && ! large_toc_ok)
6857 return false;
6858 if (GET_MODE_NUNITS (mode) != 1)
6859 return false;
6860 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
6861 && !(/* ??? Assume floating point reg based on mode? */
6862 TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT
6863 && (mode == DFmode || mode == DDmode)))
6864 return false;
6866 return CONSTANT_P (x) || large_toc_ok;
6869 return false;
6873 /* Try machine-dependent ways of modifying an illegitimate address
6874 to be legitimate. If we find one, return the new, valid address.
6875 This is used from only one place: `memory_address' in explow.c.
6877 OLDX is the address as it was before break_out_memory_refs was
6878 called. In some cases it is useful to look at this to decide what
6879 needs to be done.
6881 It is always safe for this function to do nothing. It exists to
6882 recognize opportunities to optimize the output.
6884 On RS/6000, first check for the sum of a register with a constant
6885 integer that is out of range. If so, generate code to add the
6886 constant with the low-order 16 bits masked to the register and force
6887 this result into another register (this can be done with `cau').
6888 Then generate an address of REG+(CONST&0xffff), allowing for the
6889 possibility of bit 16 being a one.
6891 Then check for the sum of a register and something not constant, try to
6892 load the other things into a register and return the sum. */
6894 static rtx
6895 rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
6896 machine_mode mode)
6898 unsigned int extra;
6900 if (!reg_offset_addressing_ok_p (mode))
6902 if (virtual_stack_registers_memory_p (x))
6903 return x;
6905 /* In theory we should not be seeing addresses of the form reg+0,
6906 but just in case it is generated, optimize it away. */
6907 if (GET_CODE (x) == PLUS && XEXP (x, 1) == const0_rtx)
6908 return force_reg (Pmode, XEXP (x, 0));
6910 /* For TImode with load/store quad, restrict addresses to just a single
6911 pointer, so it works with both GPRs and VSX registers. */
6912 /* Make sure both operands are registers. */
6913 else if (GET_CODE (x) == PLUS
6914 && (mode != TImode || !TARGET_QUAD_MEMORY))
6915 return gen_rtx_PLUS (Pmode,
6916 force_reg (Pmode, XEXP (x, 0)),
6917 force_reg (Pmode, XEXP (x, 1)));
6918 else
6919 return force_reg (Pmode, x);
6921 if (GET_CODE (x) == SYMBOL_REF)
6923 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
6924 if (model != 0)
6925 return rs6000_legitimize_tls_address (x, model);
6928 extra = 0;
6929 switch (mode)
6931 case TFmode:
6932 case TDmode:
6933 case TImode:
6934 case PTImode:
6935 /* As in legitimate_offset_address_p we do not assume
6936 worst-case. The mode here is just a hint as to the registers
6937 used. A TImode is usually in gprs, but may actually be in
6938 fprs. Leave worst-case scenario for reload to handle via
6939 insn constraints. PTImode is only GPRs. */
6940 extra = 8;
6941 break;
6942 default:
6943 break;
6946 if (GET_CODE (x) == PLUS
6947 && GET_CODE (XEXP (x, 0)) == REG
6948 && GET_CODE (XEXP (x, 1)) == CONST_INT
6949 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000)
6950 >= 0x10000 - extra)
6951 && !(SPE_VECTOR_MODE (mode)
6952 || (TARGET_E500_DOUBLE && GET_MODE_SIZE (mode) > UNITS_PER_WORD)))
6954 HOST_WIDE_INT high_int, low_int;
6955 rtx sum;
6956 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
6957 if (low_int >= 0x8000 - extra)
6958 low_int = 0;
6959 high_int = INTVAL (XEXP (x, 1)) - low_int;
6960 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
6961 GEN_INT (high_int)), 0);
6962 return plus_constant (Pmode, sum, low_int);
6964 else if (GET_CODE (x) == PLUS
6965 && GET_CODE (XEXP (x, 0)) == REG
6966 && GET_CODE (XEXP (x, 1)) != CONST_INT
6967 && GET_MODE_NUNITS (mode) == 1
6968 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
6969 || (/* ??? Assume floating point reg based on mode? */
6970 (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
6971 && (mode == DFmode || mode == DDmode)))
6972 && !avoiding_indexed_address_p (mode))
6974 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
6975 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
6977 else if (SPE_VECTOR_MODE (mode)
6978 || (TARGET_E500_DOUBLE && GET_MODE_SIZE (mode) > UNITS_PER_WORD))
6980 if (mode == DImode)
6981 return x;
6982 /* We accept [reg + reg] and [reg + OFFSET]. */
6984 if (GET_CODE (x) == PLUS)
6986 rtx op1 = XEXP (x, 0);
6987 rtx op2 = XEXP (x, 1);
6988 rtx y;
6990 op1 = force_reg (Pmode, op1);
6992 if (GET_CODE (op2) != REG
6993 && (GET_CODE (op2) != CONST_INT
6994 || !SPE_CONST_OFFSET_OK (INTVAL (op2))
6995 || (GET_MODE_SIZE (mode) > 8
6996 && !SPE_CONST_OFFSET_OK (INTVAL (op2) + 8))))
6997 op2 = force_reg (Pmode, op2);
6999 /* We can't always do [reg + reg] for these, because [reg +
7000 reg + offset] is not a legitimate addressing mode. */
7001 y = gen_rtx_PLUS (Pmode, op1, op2);
7003 if ((GET_MODE_SIZE (mode) > 8 || mode == DDmode) && REG_P (op2))
7004 return force_reg (Pmode, y);
7005 else
7006 return y;
7009 return force_reg (Pmode, x);
7011 else if ((TARGET_ELF
7012 #if TARGET_MACHO
7013 || !MACHO_DYNAMIC_NO_PIC_P
7014 #endif
7016 && TARGET_32BIT
7017 && TARGET_NO_TOC
7018 && ! flag_pic
7019 && GET_CODE (x) != CONST_INT
7020 && GET_CODE (x) != CONST_WIDE_INT
7021 && GET_CODE (x) != CONST_DOUBLE
7022 && CONSTANT_P (x)
7023 && GET_MODE_NUNITS (mode) == 1
7024 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
7025 || (/* ??? Assume floating point reg based on mode? */
7026 (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
7027 && (mode == DFmode || mode == DDmode))))
7029 rtx reg = gen_reg_rtx (Pmode);
7030 if (TARGET_ELF)
7031 emit_insn (gen_elf_high (reg, x));
7032 else
7033 emit_insn (gen_macho_high (reg, x));
7034 return gen_rtx_LO_SUM (Pmode, reg, x);
7036 else if (TARGET_TOC
7037 && GET_CODE (x) == SYMBOL_REF
7038 && constant_pool_expr_p (x)
7039 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
7040 return create_TOC_reference (x, NULL_RTX);
7041 else
7042 return x;
7045 /* Debug version of rs6000_legitimize_address. */
7046 static rtx
7047 rs6000_debug_legitimize_address (rtx x, rtx oldx, machine_mode mode)
7049 rtx ret;
7050 rtx_insn *insns;
7052 start_sequence ();
7053 ret = rs6000_legitimize_address (x, oldx, mode);
7054 insns = get_insns ();
7055 end_sequence ();
7057 if (ret != x)
7059 fprintf (stderr,
7060 "\nrs6000_legitimize_address: mode %s, old code %s, "
7061 "new code %s, modified\n",
7062 GET_MODE_NAME (mode), GET_RTX_NAME (GET_CODE (x)),
7063 GET_RTX_NAME (GET_CODE (ret)));
7065 fprintf (stderr, "Original address:\n");
7066 debug_rtx (x);
7068 fprintf (stderr, "oldx:\n");
7069 debug_rtx (oldx);
7071 fprintf (stderr, "New address:\n");
7072 debug_rtx (ret);
7074 if (insns)
7076 fprintf (stderr, "Insns added:\n");
7077 debug_rtx_list (insns, 20);
7080 else
7082 fprintf (stderr,
7083 "\nrs6000_legitimize_address: mode %s, code %s, no change:\n",
7084 GET_MODE_NAME (mode), GET_RTX_NAME (GET_CODE (x)));
7086 debug_rtx (x);
7089 if (insns)
7090 emit_insn (insns);
7092 return ret;
7095 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
7096 We need to emit DTP-relative relocations. */
7098 static void rs6000_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED;
7099 static void
7100 rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
7102 switch (size)
7104 case 4:
7105 fputs ("\t.long\t", file);
7106 break;
7107 case 8:
7108 fputs (DOUBLE_INT_ASM_OP, file);
7109 break;
7110 default:
7111 gcc_unreachable ();
7113 output_addr_const (file, x);
7114 fputs ("@dtprel+0x8000", file);
7117 /* Return true if X is a symbol that refers to real (rather than emulated)
7118 TLS. */
7120 static bool
7121 rs6000_real_tls_symbol_ref_p (rtx x)
7123 return (GET_CODE (x) == SYMBOL_REF
7124 && SYMBOL_REF_TLS_MODEL (x) >= TLS_MODEL_REAL);
7127 /* In the name of slightly smaller debug output, and to cater to
7128 general assembler lossage, recognize various UNSPEC sequences
7129 and turn them back into a direct symbol reference. */
7131 static rtx
7132 rs6000_delegitimize_address (rtx orig_x)
7134 rtx x, y, offset;
7136 orig_x = delegitimize_mem_from_attrs (orig_x);
7137 x = orig_x;
7138 if (MEM_P (x))
7139 x = XEXP (x, 0);
7141 y = x;
7142 if (TARGET_CMODEL != CMODEL_SMALL
7143 && GET_CODE (y) == LO_SUM)
7144 y = XEXP (y, 1);
7146 offset = NULL_RTX;
7147 if (GET_CODE (y) == PLUS
7148 && GET_MODE (y) == Pmode
7149 && CONST_INT_P (XEXP (y, 1)))
7151 offset = XEXP (y, 1);
7152 y = XEXP (y, 0);
7155 if (GET_CODE (y) == UNSPEC
7156 && XINT (y, 1) == UNSPEC_TOCREL)
7158 y = XVECEXP (y, 0, 0);
7160 #ifdef HAVE_AS_TLS
7161 /* Do not associate thread-local symbols with the original
7162 constant pool symbol. */
7163 if (TARGET_XCOFF
7164 && GET_CODE (y) == SYMBOL_REF
7165 && CONSTANT_POOL_ADDRESS_P (y)
7166 && rs6000_real_tls_symbol_ref_p (get_pool_constant (y)))
7167 return orig_x;
7168 #endif
7170 if (offset != NULL_RTX)
7171 y = gen_rtx_PLUS (Pmode, y, offset);
7172 if (!MEM_P (orig_x))
7173 return y;
7174 else
7175 return replace_equiv_address_nv (orig_x, y);
7178 if (TARGET_MACHO
7179 && GET_CODE (orig_x) == LO_SUM
7180 && GET_CODE (XEXP (orig_x, 1)) == CONST)
7182 y = XEXP (XEXP (orig_x, 1), 0);
7183 if (GET_CODE (y) == UNSPEC
7184 && XINT (y, 1) == UNSPEC_MACHOPIC_OFFSET)
7185 return XVECEXP (y, 0, 0);
7188 return orig_x;
7191 /* Return true if X shouldn't be emitted into the debug info.
7192 The linker doesn't like .toc section references from
7193 .debug_* sections, so reject .toc section symbols. */
7195 static bool
7196 rs6000_const_not_ok_for_debug_p (rtx x)
7198 if (GET_CODE (x) == SYMBOL_REF
7199 && CONSTANT_POOL_ADDRESS_P (x))
7201 rtx c = get_pool_constant (x);
7202 machine_mode cmode = get_pool_mode (x);
7203 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (c, cmode))
7204 return true;
7207 return false;
7210 /* Construct the SYMBOL_REF for the tls_get_addr function. */
7212 static GTY(()) rtx rs6000_tls_symbol;
7213 static rtx
7214 rs6000_tls_get_addr (void)
7216 if (!rs6000_tls_symbol)
7217 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
7219 return rs6000_tls_symbol;
7222 /* Construct the SYMBOL_REF for TLS GOT references. */
7224 static GTY(()) rtx rs6000_got_symbol;
7225 static rtx
7226 rs6000_got_sym (void)
7228 if (!rs6000_got_symbol)
7230 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
7231 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
7232 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
7235 return rs6000_got_symbol;
7238 /* AIX Thread-Local Address support. */
7240 static rtx
7241 rs6000_legitimize_tls_address_aix (rtx addr, enum tls_model model)
7243 rtx sym, mem, tocref, tlsreg, tmpreg, dest, tlsaddr;
7244 const char *name;
7245 char *tlsname;
7247 name = XSTR (addr, 0);
7248 /* Append TLS CSECT qualifier, unless the symbol already is qualified
7249 or the symbol will be in TLS private data section. */
7250 if (name[strlen (name) - 1] != ']'
7251 && (TREE_PUBLIC (SYMBOL_REF_DECL (addr))
7252 || bss_initializer_p (SYMBOL_REF_DECL (addr))))
7254 tlsname = XALLOCAVEC (char, strlen (name) + 4);
7255 strcpy (tlsname, name);
7256 strcat (tlsname,
7257 bss_initializer_p (SYMBOL_REF_DECL (addr)) ? "[UL]" : "[TL]");
7258 tlsaddr = copy_rtx (addr);
7259 XSTR (tlsaddr, 0) = ggc_strdup (tlsname);
7261 else
7262 tlsaddr = addr;
7264 /* Place addr into TOC constant pool. */
7265 sym = force_const_mem (GET_MODE (tlsaddr), tlsaddr);
7267 /* Output the TOC entry and create the MEM referencing the value. */
7268 if (constant_pool_expr_p (XEXP (sym, 0))
7269 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (XEXP (sym, 0)), Pmode))
7271 tocref = create_TOC_reference (XEXP (sym, 0), NULL_RTX);
7272 mem = gen_const_mem (Pmode, tocref);
7273 set_mem_alias_set (mem, get_TOC_alias_set ());
7275 else
7276 return sym;
7278 /* Use global-dynamic for local-dynamic. */
7279 if (model == TLS_MODEL_GLOBAL_DYNAMIC
7280 || model == TLS_MODEL_LOCAL_DYNAMIC)
7282 /* Create new TOC reference for @m symbol. */
7283 name = XSTR (XVECEXP (XEXP (mem, 0), 0, 0), 0);
7284 tlsname = XALLOCAVEC (char, strlen (name) + 1);
7285 strcpy (tlsname, "*LCM");
7286 strcat (tlsname, name + 3);
7287 rtx modaddr = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tlsname));
7288 SYMBOL_REF_FLAGS (modaddr) |= SYMBOL_FLAG_LOCAL;
7289 tocref = create_TOC_reference (modaddr, NULL_RTX);
7290 rtx modmem = gen_const_mem (Pmode, tocref);
7291 set_mem_alias_set (modmem, get_TOC_alias_set ());
7293 rtx modreg = gen_reg_rtx (Pmode);
7294 emit_insn (gen_rtx_SET (modreg, modmem));
7296 tmpreg = gen_reg_rtx (Pmode);
7297 emit_insn (gen_rtx_SET (tmpreg, mem));
7299 dest = gen_reg_rtx (Pmode);
7300 if (TARGET_32BIT)
7301 emit_insn (gen_tls_get_addrsi (dest, modreg, tmpreg));
7302 else
7303 emit_insn (gen_tls_get_addrdi (dest, modreg, tmpreg));
7304 return dest;
7306 /* Obtain TLS pointer: 32 bit call or 64 bit GPR 13. */
7307 else if (TARGET_32BIT)
7309 tlsreg = gen_reg_rtx (SImode);
7310 emit_insn (gen_tls_get_tpointer (tlsreg));
7312 else
7313 tlsreg = gen_rtx_REG (DImode, 13);
7315 /* Load the TOC value into temporary register. */
7316 tmpreg = gen_reg_rtx (Pmode);
7317 emit_insn (gen_rtx_SET (tmpreg, mem));
7318 set_unique_reg_note (get_last_insn (), REG_EQUAL,
7319 gen_rtx_MINUS (Pmode, addr, tlsreg));
7321 /* Add TOC symbol value to TLS pointer. */
7322 dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tmpreg, tlsreg));
7324 return dest;
7327 /* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
7328 this (thread-local) address. */
7330 static rtx
7331 rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
7333 rtx dest, insn;
7335 if (TARGET_XCOFF)
7336 return rs6000_legitimize_tls_address_aix (addr, model);
7338 dest = gen_reg_rtx (Pmode);
7339 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
7341 rtx tlsreg;
7343 if (TARGET_64BIT)
7345 tlsreg = gen_rtx_REG (Pmode, 13);
7346 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
7348 else
7350 tlsreg = gen_rtx_REG (Pmode, 2);
7351 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
7353 emit_insn (insn);
7355 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
7357 rtx tlsreg, tmp;
7359 tmp = gen_reg_rtx (Pmode);
7360 if (TARGET_64BIT)
7362 tlsreg = gen_rtx_REG (Pmode, 13);
7363 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
7365 else
7367 tlsreg = gen_rtx_REG (Pmode, 2);
7368 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
7370 emit_insn (insn);
7371 if (TARGET_64BIT)
7372 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
7373 else
7374 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
7375 emit_insn (insn);
7377 else
7379 rtx r3, got, tga, tmp1, tmp2, call_insn;
7381 /* We currently use relocations like @got@tlsgd for tls, which
7382 means the linker will handle allocation of tls entries, placing
7383 them in the .got section. So use a pointer to the .got section,
7384 not one to secondary TOC sections used by 64-bit -mminimal-toc,
7385 or to secondary GOT sections used by 32-bit -fPIC. */
7386 if (TARGET_64BIT)
7387 got = gen_rtx_REG (Pmode, 2);
7388 else
7390 if (flag_pic == 1)
7391 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
7392 else
7394 rtx gsym = rs6000_got_sym ();
7395 got = gen_reg_rtx (Pmode);
7396 if (flag_pic == 0)
7397 rs6000_emit_move (got, gsym, Pmode);
7398 else
7400 rtx mem, lab, last;
7402 tmp1 = gen_reg_rtx (Pmode);
7403 tmp2 = gen_reg_rtx (Pmode);
7404 mem = gen_const_mem (Pmode, tmp1);
7405 lab = gen_label_rtx ();
7406 emit_insn (gen_load_toc_v4_PIC_1b (gsym, lab));
7407 emit_move_insn (tmp1, gen_rtx_REG (Pmode, LR_REGNO));
7408 if (TARGET_LINK_STACK)
7409 emit_insn (gen_addsi3 (tmp1, tmp1, GEN_INT (4)));
7410 emit_move_insn (tmp2, mem);
7411 last = emit_insn (gen_addsi3 (got, tmp1, tmp2));
7412 set_unique_reg_note (last, REG_EQUAL, gsym);
7417 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
7419 tga = rs6000_tls_get_addr ();
7420 emit_library_call_value (tga, dest, LCT_CONST, Pmode,
7421 1, const0_rtx, Pmode);
7423 r3 = gen_rtx_REG (Pmode, 3);
7424 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
7426 if (TARGET_64BIT)
7427 insn = gen_tls_gd_aix64 (r3, got, addr, tga, const0_rtx);
7428 else
7429 insn = gen_tls_gd_aix32 (r3, got, addr, tga, const0_rtx);
7431 else if (DEFAULT_ABI == ABI_V4)
7432 insn = gen_tls_gd_sysvsi (r3, got, addr, tga, const0_rtx);
7433 else
7434 gcc_unreachable ();
7435 call_insn = last_call_insn ();
7436 PATTERN (call_insn) = insn;
7437 if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT && flag_pic)
7438 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn),
7439 pic_offset_table_rtx);
7441 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
7443 tga = rs6000_tls_get_addr ();
7444 tmp1 = gen_reg_rtx (Pmode);
7445 emit_library_call_value (tga, tmp1, LCT_CONST, Pmode,
7446 1, const0_rtx, Pmode);
7448 r3 = gen_rtx_REG (Pmode, 3);
7449 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
7451 if (TARGET_64BIT)
7452 insn = gen_tls_ld_aix64 (r3, got, tga, const0_rtx);
7453 else
7454 insn = gen_tls_ld_aix32 (r3, got, tga, const0_rtx);
7456 else if (DEFAULT_ABI == ABI_V4)
7457 insn = gen_tls_ld_sysvsi (r3, got, tga, const0_rtx);
7458 else
7459 gcc_unreachable ();
7460 call_insn = last_call_insn ();
7461 PATTERN (call_insn) = insn;
7462 if (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT && flag_pic)
7463 use_reg (&CALL_INSN_FUNCTION_USAGE (call_insn),
7464 pic_offset_table_rtx);
7466 if (rs6000_tls_size == 16)
7468 if (TARGET_64BIT)
7469 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
7470 else
7471 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
7473 else if (rs6000_tls_size == 32)
7475 tmp2 = gen_reg_rtx (Pmode);
7476 if (TARGET_64BIT)
7477 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
7478 else
7479 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
7480 emit_insn (insn);
7481 if (TARGET_64BIT)
7482 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
7483 else
7484 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
7486 else
7488 tmp2 = gen_reg_rtx (Pmode);
7489 if (TARGET_64BIT)
7490 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
7491 else
7492 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
7493 emit_insn (insn);
7494 insn = gen_rtx_SET (dest, gen_rtx_PLUS (Pmode, tmp2, tmp1));
7496 emit_insn (insn);
7498 else
7500 /* IE, or 64-bit offset LE. */
7501 tmp2 = gen_reg_rtx (Pmode);
7502 if (TARGET_64BIT)
7503 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
7504 else
7505 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
7506 emit_insn (insn);
7507 if (TARGET_64BIT)
7508 insn = gen_tls_tls_64 (dest, tmp2, addr);
7509 else
7510 insn = gen_tls_tls_32 (dest, tmp2, addr);
7511 emit_insn (insn);
7515 return dest;
7518 /* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
7520 static bool
7521 rs6000_cannot_force_const_mem (machine_mode mode ATTRIBUTE_UNUSED, rtx x)
7523 if (GET_CODE (x) == HIGH
7524 && GET_CODE (XEXP (x, 0)) == UNSPEC)
7525 return true;
7527 /* A TLS symbol in the TOC cannot contain a sum. */
7528 if (GET_CODE (x) == CONST
7529 && GET_CODE (XEXP (x, 0)) == PLUS
7530 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
7531 && SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0)) != 0)
7532 return true;
7534 /* Do not place an ELF TLS symbol in the constant pool. */
7535 return TARGET_ELF && tls_referenced_p (x);
7538 /* Return true iff the given SYMBOL_REF refers to a constant pool entry
7539 that we have put in the TOC, or for cmodel=medium, if the SYMBOL_REF
7540 can be addressed relative to the toc pointer. */
7542 static bool
7543 use_toc_relative_ref (rtx sym, machine_mode mode)
7545 return ((constant_pool_expr_p (sym)
7546 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (sym),
7547 get_pool_mode (sym)))
7548 || (TARGET_CMODEL == CMODEL_MEDIUM
7549 && SYMBOL_REF_LOCAL_P (sym)
7550 && GET_MODE_SIZE (mode) <= POWERPC64_TOC_POINTER_ALIGNMENT));
7553 /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
7554 replace the input X, or the original X if no replacement is called for.
7555 The output parameter *WIN is 1 if the calling macro should goto WIN,
7556 0 if it should not.
7558 For RS/6000, we wish to handle large displacements off a base
7559 register by splitting the addend across an addiu/addis and the mem insn.
7560 This cuts number of extra insns needed from 3 to 1.
7562 On Darwin, we use this to generate code for floating point constants.
7563 A movsf_low is generated so we wind up with 2 instructions rather than 3.
7564 The Darwin code is inside #if TARGET_MACHO because only then are the
7565 machopic_* functions defined. */
7566 static rtx
7567 rs6000_legitimize_reload_address (rtx x, machine_mode mode,
7568 int opnum, int type,
7569 int ind_levels ATTRIBUTE_UNUSED, int *win)
7571 bool reg_offset_p = reg_offset_addressing_ok_p (mode);
7573 /* Nasty hack for vsx_splat_V2DF/V2DI load from mem, which takes a
7574 DFmode/DImode MEM. */
7575 if (reg_offset_p
7576 && opnum == 1
7577 && ((mode == DFmode && recog_data.operand_mode[0] == V2DFmode)
7578 || (mode == DImode && recog_data.operand_mode[0] == V2DImode)))
7579 reg_offset_p = false;
7581 /* We must recognize output that we have already generated ourselves. */
7582 if (GET_CODE (x) == PLUS
7583 && GET_CODE (XEXP (x, 0)) == PLUS
7584 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
7585 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
7586 && GET_CODE (XEXP (x, 1)) == CONST_INT)
7588 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
7589 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
7590 opnum, (enum reload_type) type);
7591 *win = 1;
7592 return x;
7595 /* Likewise for (lo_sum (high ...) ...) output we have generated. */
7596 if (GET_CODE (x) == LO_SUM
7597 && GET_CODE (XEXP (x, 0)) == HIGH)
7599 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
7600 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
7601 opnum, (enum reload_type) type);
7602 *win = 1;
7603 return x;
7606 #if TARGET_MACHO
7607 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
7608 && GET_CODE (x) == LO_SUM
7609 && GET_CODE (XEXP (x, 0)) == PLUS
7610 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
7611 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
7612 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
7613 && machopic_operand_p (XEXP (x, 1)))
7615 /* Result of previous invocation of this function on Darwin
7616 floating point constant. */
7617 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
7618 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
7619 opnum, (enum reload_type) type);
7620 *win = 1;
7621 return x;
7623 #endif
7625 if (TARGET_CMODEL != CMODEL_SMALL
7626 && reg_offset_p
7627 && small_toc_ref (x, VOIDmode))
7629 rtx hi = gen_rtx_HIGH (Pmode, copy_rtx (x));
7630 x = gen_rtx_LO_SUM (Pmode, hi, x);
7631 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
7632 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
7633 opnum, (enum reload_type) type);
7634 *win = 1;
7635 return x;
7638 if (GET_CODE (x) == PLUS
7639 && GET_CODE (XEXP (x, 0)) == REG
7640 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
7641 && INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 1)
7642 && GET_CODE (XEXP (x, 1)) == CONST_INT
7643 && reg_offset_p
7644 && !SPE_VECTOR_MODE (mode)
7645 && !(TARGET_E500_DOUBLE && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
7646 && (!VECTOR_MODE_P (mode) || VECTOR_MEM_NONE_P (mode)))
7648 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
7649 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
7650 HOST_WIDE_INT high
7651 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
7653 /* Check for 32-bit overflow. */
7654 if (high + low != val)
7656 *win = 0;
7657 return x;
7660 /* Reload the high part into a base reg; leave the low part
7661 in the mem directly. */
7663 x = gen_rtx_PLUS (GET_MODE (x),
7664 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
7665 GEN_INT (high)),
7666 GEN_INT (low));
7668 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
7669 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
7670 opnum, (enum reload_type) type);
7671 *win = 1;
7672 return x;
7675 if (GET_CODE (x) == SYMBOL_REF
7676 && reg_offset_p
7677 && (!VECTOR_MODE_P (mode) || VECTOR_MEM_NONE_P (mode))
7678 && !SPE_VECTOR_MODE (mode)
7679 #if TARGET_MACHO
7680 && DEFAULT_ABI == ABI_DARWIN
7681 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
7682 && machopic_symbol_defined_p (x)
7683 #else
7684 && DEFAULT_ABI == ABI_V4
7685 && !flag_pic
7686 #endif
7687 /* Don't do this for TFmode or TDmode, since the result isn't offsettable.
7688 The same goes for DImode without 64-bit gprs and DFmode and DDmode
7689 without fprs.
7690 ??? Assume floating point reg based on mode? This assumption is
7691 violated by eg. powerpc-linux -m32 compile of gcc.dg/pr28796-2.c
7692 where reload ends up doing a DFmode load of a constant from
7693 mem using two gprs. Unfortunately, at this point reload
7694 hasn't yet selected regs so poking around in reload data
7695 won't help and even if we could figure out the regs reliably,
7696 we'd still want to allow this transformation when the mem is
7697 naturally aligned. Since we say the address is good here, we
7698 can't disable offsets from LO_SUMs in mem_operand_gpr.
7699 FIXME: Allow offset from lo_sum for other modes too, when
7700 mem is sufficiently aligned.
7702 Also disallow this if the type can go in VMX/Altivec registers, since
7703 those registers do not have d-form (reg+offset) address modes. */
7704 && !reg_addr[mode].scalar_in_vmx_p
7705 && mode != TFmode
7706 && mode != TDmode
7707 && (mode != TImode || !TARGET_VSX_TIMODE)
7708 && mode != PTImode
7709 && (mode != DImode || TARGET_POWERPC64)
7710 && ((mode != DFmode && mode != DDmode) || TARGET_POWERPC64
7711 || (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)))
7713 #if TARGET_MACHO
7714 if (flag_pic)
7716 rtx offset = machopic_gen_offset (x);
7717 x = gen_rtx_LO_SUM (GET_MODE (x),
7718 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
7719 gen_rtx_HIGH (Pmode, offset)), offset);
7721 else
7722 #endif
7723 x = gen_rtx_LO_SUM (GET_MODE (x),
7724 gen_rtx_HIGH (Pmode, x), x);
7726 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
7727 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
7728 opnum, (enum reload_type) type);
7729 *win = 1;
7730 return x;
7733 /* Reload an offset address wrapped by an AND that represents the
7734 masking of the lower bits. Strip the outer AND and let reload
7735 convert the offset address into an indirect address. For VSX,
7736 force reload to create the address with an AND in a separate
7737 register, because we can't guarantee an altivec register will
7738 be used. */
7739 if (VECTOR_MEM_ALTIVEC_P (mode)
7740 && GET_CODE (x) == AND
7741 && GET_CODE (XEXP (x, 0)) == PLUS
7742 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
7743 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
7744 && GET_CODE (XEXP (x, 1)) == CONST_INT
7745 && INTVAL (XEXP (x, 1)) == -16)
7747 x = XEXP (x, 0);
7748 *win = 1;
7749 return x;
7752 if (TARGET_TOC
7753 && reg_offset_p
7754 && GET_CODE (x) == SYMBOL_REF
7755 && use_toc_relative_ref (x, mode))
7757 x = create_TOC_reference (x, NULL_RTX);
7758 if (TARGET_CMODEL != CMODEL_SMALL)
7759 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
7760 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
7761 opnum, (enum reload_type) type);
7762 *win = 1;
7763 return x;
7765 *win = 0;
7766 return x;
7769 /* Debug version of rs6000_legitimize_reload_address. */
7770 static rtx
7771 rs6000_debug_legitimize_reload_address (rtx x, machine_mode mode,
7772 int opnum, int type,
7773 int ind_levels, int *win)
7775 rtx ret = rs6000_legitimize_reload_address (x, mode, opnum, type,
7776 ind_levels, win);
7777 fprintf (stderr,
7778 "\nrs6000_legitimize_reload_address: mode = %s, opnum = %d, "
7779 "type = %d, ind_levels = %d, win = %d, original addr:\n",
7780 GET_MODE_NAME (mode), opnum, type, ind_levels, *win);
7781 debug_rtx (x);
7783 if (x == ret)
7784 fprintf (stderr, "Same address returned\n");
7785 else if (!ret)
7786 fprintf (stderr, "NULL returned\n");
7787 else
7789 fprintf (stderr, "New address:\n");
7790 debug_rtx (ret);
7793 return ret;
7796 /* TARGET_LEGITIMATE_ADDRESS_P recognizes an RTL expression
7797 that is a valid memory address for an instruction.
7798 The MODE argument is the machine mode for the MEM expression
7799 that wants to use this address.
7801 On the RS/6000, there are four valid address: a SYMBOL_REF that
7802 refers to a constant pool entry of an address (or the sum of it
7803 plus a constant), a short (16-bit signed) constant plus a register,
7804 the sum of two registers, or a register indirect, possibly with an
7805 auto-increment. For DFmode, DDmode and DImode with a constant plus
7806 register, we must ensure that both words are addressable or PowerPC64
7807 with offset word aligned.
7809 For modes spanning multiple registers (DFmode and DDmode in 32-bit GPRs,
7810 32-bit DImode, TImode, TFmode, TDmode), indexed addressing cannot be used
7811 because adjacent memory cells are accessed by adding word-sized offsets
7812 during assembly output. */
7813 static bool
7814 rs6000_legitimate_address_p (machine_mode mode, rtx x, bool reg_ok_strict)
7816 bool reg_offset_p = reg_offset_addressing_ok_p (mode);
7818 /* If this is an unaligned stvx/ldvx type address, discard the outer AND. */
7819 if (VECTOR_MEM_ALTIVEC_P (mode)
7820 && GET_CODE (x) == AND
7821 && GET_CODE (XEXP (x, 1)) == CONST_INT
7822 && INTVAL (XEXP (x, 1)) == -16)
7823 x = XEXP (x, 0);
7825 if (TARGET_ELF && RS6000_SYMBOL_REF_TLS_P (x))
7826 return 0;
7827 if (legitimate_indirect_address_p (x, reg_ok_strict))
7828 return 1;
7829 if (TARGET_UPDATE
7830 && (GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
7831 && mode_supports_pre_incdec_p (mode)
7832 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
7833 return 1;
7834 if (virtual_stack_registers_memory_p (x))
7835 return 1;
7836 if (reg_offset_p && legitimate_small_data_p (mode, x))
7837 return 1;
7838 if (reg_offset_p
7839 && legitimate_constant_pool_address_p (x, mode,
7840 reg_ok_strict || lra_in_progress))
7841 return 1;
7842 /* For TImode, if we have load/store quad and TImode in VSX registers, only
7843 allow register indirect addresses. This will allow the values to go in
7844 either GPRs or VSX registers without reloading. The vector types would
7845 tend to go into VSX registers, so we allow REG+REG, while TImode seems
7846 somewhat split, in that some uses are GPR based, and some VSX based. */
7847 if (mode == TImode && TARGET_QUAD_MEMORY && TARGET_VSX_TIMODE)
7848 return 0;
7849 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
7850 if (! reg_ok_strict
7851 && reg_offset_p
7852 && GET_CODE (x) == PLUS
7853 && GET_CODE (XEXP (x, 0)) == REG
7854 && (XEXP (x, 0) == virtual_stack_vars_rtx
7855 || XEXP (x, 0) == arg_pointer_rtx)
7856 && GET_CODE (XEXP (x, 1)) == CONST_INT)
7857 return 1;
7858 if (rs6000_legitimate_offset_address_p (mode, x, reg_ok_strict, false))
7859 return 1;
7860 if (mode != TFmode
7861 && mode != TDmode
7862 && ((TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT)
7863 || TARGET_POWERPC64
7864 || (mode != DFmode && mode != DDmode)
7865 || (TARGET_E500_DOUBLE && mode != DDmode))
7866 && (TARGET_POWERPC64 || mode != DImode)
7867 && (mode != TImode || VECTOR_MEM_VSX_P (TImode))
7868 && mode != PTImode
7869 && !avoiding_indexed_address_p (mode)
7870 && legitimate_indexed_address_p (x, reg_ok_strict))
7871 return 1;
7872 if (TARGET_UPDATE && GET_CODE (x) == PRE_MODIFY
7873 && mode_supports_pre_modify_p (mode)
7874 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict)
7875 && (rs6000_legitimate_offset_address_p (mode, XEXP (x, 1),
7876 reg_ok_strict, false)
7877 || (!avoiding_indexed_address_p (mode)
7878 && legitimate_indexed_address_p (XEXP (x, 1), reg_ok_strict)))
7879 && rtx_equal_p (XEXP (XEXP (x, 1), 0), XEXP (x, 0)))
7880 return 1;
7881 if (reg_offset_p && legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
7882 return 1;
7883 return 0;
7886 /* Debug version of rs6000_legitimate_address_p. */
7887 static bool
7888 rs6000_debug_legitimate_address_p (machine_mode mode, rtx x,
7889 bool reg_ok_strict)
7891 bool ret = rs6000_legitimate_address_p (mode, x, reg_ok_strict);
7892 fprintf (stderr,
7893 "\nrs6000_legitimate_address_p: return = %s, mode = %s, "
7894 "strict = %d, reload = %s, code = %s\n",
7895 ret ? "true" : "false",
7896 GET_MODE_NAME (mode),
7897 reg_ok_strict,
7898 (reload_completed
7899 ? "after"
7900 : (reload_in_progress ? "progress" : "before")),
7901 GET_RTX_NAME (GET_CODE (x)));
7902 debug_rtx (x);
7904 return ret;
7907 /* Implement TARGET_MODE_DEPENDENT_ADDRESS_P. */
7909 static bool
7910 rs6000_mode_dependent_address_p (const_rtx addr,
7911 addr_space_t as ATTRIBUTE_UNUSED)
7913 return rs6000_mode_dependent_address_ptr (addr);
7916 /* Go to LABEL if ADDR (a legitimate address expression)
7917 has an effect that depends on the machine mode it is used for.
7919 On the RS/6000 this is true of all integral offsets (since AltiVec
7920 and VSX modes don't allow them) or is a pre-increment or decrement.
7922 ??? Except that due to conceptual problems in offsettable_address_p
7923 we can't really report the problems of integral offsets. So leave
7924 this assuming that the adjustable offset must be valid for the
7925 sub-words of a TFmode operand, which is what we had before. */
7927 static bool
7928 rs6000_mode_dependent_address (const_rtx addr)
7930 switch (GET_CODE (addr))
7932 case PLUS:
7933 /* Any offset from virtual_stack_vars_rtx and arg_pointer_rtx
7934 is considered a legitimate address before reload, so there
7935 are no offset restrictions in that case. Note that this
7936 condition is safe in strict mode because any address involving
7937 virtual_stack_vars_rtx or arg_pointer_rtx would already have
7938 been rejected as illegitimate. */
7939 if (XEXP (addr, 0) != virtual_stack_vars_rtx
7940 && XEXP (addr, 0) != arg_pointer_rtx
7941 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
7943 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
7944 return val + 0x8000 >= 0x10000 - (TARGET_POWERPC64 ? 8 : 12);
7946 break;
7948 case LO_SUM:
7949 /* Anything in the constant pool is sufficiently aligned that
7950 all bytes have the same high part address. */
7951 return !legitimate_constant_pool_address_p (addr, QImode, false);
7953 /* Auto-increment cases are now treated generically in recog.c. */
7954 case PRE_MODIFY:
7955 return TARGET_UPDATE;
7957 /* AND is only allowed in Altivec loads. */
7958 case AND:
7959 return true;
7961 default:
7962 break;
7965 return false;
7968 /* Debug version of rs6000_mode_dependent_address. */
7969 static bool
7970 rs6000_debug_mode_dependent_address (const_rtx addr)
7972 bool ret = rs6000_mode_dependent_address (addr);
7974 fprintf (stderr, "\nrs6000_mode_dependent_address: ret = %s\n",
7975 ret ? "true" : "false");
7976 debug_rtx (addr);
7978 return ret;
7981 /* Implement FIND_BASE_TERM. */
7984 rs6000_find_base_term (rtx op)
7986 rtx base;
7988 base = op;
7989 if (GET_CODE (base) == CONST)
7990 base = XEXP (base, 0);
7991 if (GET_CODE (base) == PLUS)
7992 base = XEXP (base, 0);
7993 if (GET_CODE (base) == UNSPEC)
7994 switch (XINT (base, 1))
7996 case UNSPEC_TOCREL:
7997 case UNSPEC_MACHOPIC_OFFSET:
7998 /* OP represents SYM [+ OFFSET] - ANCHOR. SYM is the base term
7999 for aliasing purposes. */
8000 return XVECEXP (base, 0, 0);
8003 return op;
8006 /* More elaborate version of recog's offsettable_memref_p predicate
8007 that works around the ??? note of rs6000_mode_dependent_address.
8008 In particular it accepts
8010 (mem:DI (plus:SI (reg/f:SI 31 31) (const_int 32760 [0x7ff8])))
8012 in 32-bit mode, that the recog predicate rejects. */
8014 static bool
8015 rs6000_offsettable_memref_p (rtx op, machine_mode reg_mode)
8017 bool worst_case;
8019 if (!MEM_P (op))
8020 return false;
8022 /* First mimic offsettable_memref_p. */
8023 if (offsettable_address_p (true, GET_MODE (op), XEXP (op, 0)))
8024 return true;
8026 /* offsettable_address_p invokes rs6000_mode_dependent_address, but
8027 the latter predicate knows nothing about the mode of the memory
8028 reference and, therefore, assumes that it is the largest supported
8029 mode (TFmode). As a consequence, legitimate offsettable memory
8030 references are rejected. rs6000_legitimate_offset_address_p contains
8031 the correct logic for the PLUS case of rs6000_mode_dependent_address,
8032 at least with a little bit of help here given that we know the
8033 actual registers used. */
8034 worst_case = ((TARGET_POWERPC64 && GET_MODE_CLASS (reg_mode) == MODE_INT)
8035 || GET_MODE_SIZE (reg_mode) == 4);
8036 return rs6000_legitimate_offset_address_p (GET_MODE (op), XEXP (op, 0),
8037 true, worst_case);
8040 /* Change register usage conditional on target flags. */
8041 static void
8042 rs6000_conditional_register_usage (void)
8044 int i;
8046 if (TARGET_DEBUG_TARGET)
8047 fprintf (stderr, "rs6000_conditional_register_usage called\n");
8049 /* Set MQ register fixed (already call_used) so that it will not be
8050 allocated. */
8051 fixed_regs[64] = 1;
8053 /* 64-bit AIX and Linux reserve GPR13 for thread-private data. */
8054 if (TARGET_64BIT)
8055 fixed_regs[13] = call_used_regs[13]
8056 = call_really_used_regs[13] = 1;
8058 /* Conditionally disable FPRs. */
8059 if (TARGET_SOFT_FLOAT || !TARGET_FPRS)
8060 for (i = 32; i < 64; i++)
8061 fixed_regs[i] = call_used_regs[i]
8062 = call_really_used_regs[i] = 1;
8064 /* The TOC register is not killed across calls in a way that is
8065 visible to the compiler. */
8066 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
8067 call_really_used_regs[2] = 0;
8069 if (DEFAULT_ABI == ABI_V4
8070 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
8071 && flag_pic == 2)
8072 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
8074 if (DEFAULT_ABI == ABI_V4
8075 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
8076 && flag_pic == 1)
8077 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
8078 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
8079 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
8081 if (DEFAULT_ABI == ABI_DARWIN
8082 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
8083 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
8084 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
8085 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
8087 if (TARGET_TOC && TARGET_MINIMAL_TOC)
8088 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
8089 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
8091 if (TARGET_SPE)
8093 global_regs[SPEFSCR_REGNO] = 1;
8094 /* We used to use r14 as FIXED_SCRATCH to address SPE 64-bit
8095 registers in prologues and epilogues. We no longer use r14
8096 for FIXED_SCRATCH, but we're keeping r14 out of the allocation
8097 pool for link-compatibility with older versions of GCC. Once
8098 "old" code has died out, we can return r14 to the allocation
8099 pool. */
8100 fixed_regs[14]
8101 = call_used_regs[14]
8102 = call_really_used_regs[14] = 1;
8105 if (!TARGET_ALTIVEC && !TARGET_VSX)
8107 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
8108 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
8109 call_really_used_regs[VRSAVE_REGNO] = 1;
8112 if (TARGET_ALTIVEC || TARGET_VSX)
8113 global_regs[VSCR_REGNO] = 1;
8115 if (TARGET_ALTIVEC_ABI)
8117 for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i)
8118 call_used_regs[i] = call_really_used_regs[i] = 1;
8120 /* AIX reserves VR20:31 in non-extended ABI mode. */
8121 if (TARGET_XCOFF)
8122 for (i = FIRST_ALTIVEC_REGNO + 20; i < FIRST_ALTIVEC_REGNO + 32; ++i)
8123 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
8128 /* Output insns to set DEST equal to the constant SOURCE as a series of
8129 lis, ori and shl instructions and return TRUE. */
8131 bool
8132 rs6000_emit_set_const (rtx dest, rtx source)
8134 machine_mode mode = GET_MODE (dest);
8135 rtx temp, set;
8136 rtx_insn *insn;
8137 HOST_WIDE_INT c;
8139 gcc_checking_assert (CONST_INT_P (source));
8140 c = INTVAL (source);
8141 switch (mode)
8143 case QImode:
8144 case HImode:
8145 emit_insn (gen_rtx_SET (dest, source));
8146 return true;
8148 case SImode:
8149 temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (SImode);
8151 emit_insn (gen_rtx_SET (copy_rtx (temp),
8152 GEN_INT (c & ~(HOST_WIDE_INT) 0xffff)));
8153 emit_insn (gen_rtx_SET (dest,
8154 gen_rtx_IOR (SImode, copy_rtx (temp),
8155 GEN_INT (c & 0xffff))));
8156 break;
8158 case DImode:
8159 if (!TARGET_POWERPC64)
8161 rtx hi, lo;
8163 hi = operand_subword_force (copy_rtx (dest), WORDS_BIG_ENDIAN == 0,
8164 DImode);
8165 lo = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
8166 DImode);
8167 emit_move_insn (hi, GEN_INT (c >> 32));
8168 c = ((c & 0xffffffff) ^ 0x80000000) - 0x80000000;
8169 emit_move_insn (lo, GEN_INT (c));
8171 else
8172 rs6000_emit_set_long_const (dest, c);
8173 break;
8175 default:
8176 gcc_unreachable ();
8179 insn = get_last_insn ();
8180 set = single_set (insn);
8181 if (! CONSTANT_P (SET_SRC (set)))
8182 set_unique_reg_note (insn, REG_EQUAL, GEN_INT (c));
8184 return true;
8187 /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode.
8188 Output insns to set DEST equal to the constant C as a series of
8189 lis, ori and shl instructions. */
8191 static void
8192 rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c)
8194 rtx temp;
8195 HOST_WIDE_INT ud1, ud2, ud3, ud4;
8197 ud1 = c & 0xffff;
8198 c = c >> 16;
8199 ud2 = c & 0xffff;
8200 c = c >> 16;
8201 ud3 = c & 0xffff;
8202 c = c >> 16;
8203 ud4 = c & 0xffff;
8205 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
8206 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
8207 emit_move_insn (dest, GEN_INT ((ud1 ^ 0x8000) - 0x8000));
8209 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
8210 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
8212 temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
8214 emit_move_insn (ud1 != 0 ? copy_rtx (temp) : dest,
8215 GEN_INT (((ud2 << 16) ^ 0x80000000) - 0x80000000));
8216 if (ud1 != 0)
8217 emit_move_insn (dest,
8218 gen_rtx_IOR (DImode, copy_rtx (temp),
8219 GEN_INT (ud1)));
8221 else if (ud3 == 0 && ud4 == 0)
8223 temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
8225 gcc_assert (ud2 & 0x8000);
8226 emit_move_insn (copy_rtx (temp),
8227 GEN_INT (((ud2 << 16) ^ 0x80000000) - 0x80000000));
8228 if (ud1 != 0)
8229 emit_move_insn (copy_rtx (temp),
8230 gen_rtx_IOR (DImode, copy_rtx (temp),
8231 GEN_INT (ud1)));
8232 emit_move_insn (dest,
8233 gen_rtx_ZERO_EXTEND (DImode,
8234 gen_lowpart (SImode,
8235 copy_rtx (temp))));
8237 else if ((ud4 == 0xffff && (ud3 & 0x8000))
8238 || (ud4 == 0 && ! (ud3 & 0x8000)))
8240 temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
8242 emit_move_insn (copy_rtx (temp),
8243 GEN_INT (((ud3 << 16) ^ 0x80000000) - 0x80000000));
8244 if (ud2 != 0)
8245 emit_move_insn (copy_rtx (temp),
8246 gen_rtx_IOR (DImode, copy_rtx (temp),
8247 GEN_INT (ud2)));
8248 emit_move_insn (ud1 != 0 ? copy_rtx (temp) : dest,
8249 gen_rtx_ASHIFT (DImode, copy_rtx (temp),
8250 GEN_INT (16)));
8251 if (ud1 != 0)
8252 emit_move_insn (dest,
8253 gen_rtx_IOR (DImode, copy_rtx (temp),
8254 GEN_INT (ud1)));
8256 else
8258 temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode);
8260 emit_move_insn (copy_rtx (temp),
8261 GEN_INT (((ud4 << 16) ^ 0x80000000) - 0x80000000));
8262 if (ud3 != 0)
8263 emit_move_insn (copy_rtx (temp),
8264 gen_rtx_IOR (DImode, copy_rtx (temp),
8265 GEN_INT (ud3)));
8267 emit_move_insn (ud2 != 0 || ud1 != 0 ? copy_rtx (temp) : dest,
8268 gen_rtx_ASHIFT (DImode, copy_rtx (temp),
8269 GEN_INT (32)));
8270 if (ud2 != 0)
8271 emit_move_insn (ud1 != 0 ? copy_rtx (temp) : dest,
8272 gen_rtx_IOR (DImode, copy_rtx (temp),
8273 GEN_INT (ud2 << 16)));
8274 if (ud1 != 0)
8275 emit_move_insn (dest,
8276 gen_rtx_IOR (DImode, copy_rtx (temp),
8277 GEN_INT (ud1)));
8281 /* Helper for the following. Get rid of [r+r] memory refs
8282 in cases where it won't work (TImode, TFmode, TDmode, PTImode). */
8284 static void
8285 rs6000_eliminate_indexed_memrefs (rtx operands[2])
8287 if (reload_in_progress)
8288 return;
8290 if (GET_CODE (operands[0]) == MEM
8291 && GET_CODE (XEXP (operands[0], 0)) != REG
8292 && ! legitimate_constant_pool_address_p (XEXP (operands[0], 0),
8293 GET_MODE (operands[0]), false))
8294 operands[0]
8295 = replace_equiv_address (operands[0],
8296 copy_addr_to_reg (XEXP (operands[0], 0)));
8298 if (GET_CODE (operands[1]) == MEM
8299 && GET_CODE (XEXP (operands[1], 0)) != REG
8300 && ! legitimate_constant_pool_address_p (XEXP (operands[1], 0),
8301 GET_MODE (operands[1]), false))
8302 operands[1]
8303 = replace_equiv_address (operands[1],
8304 copy_addr_to_reg (XEXP (operands[1], 0)));
8307 /* Generate a vector of constants to permute MODE for a little-endian
8308 storage operation by swapping the two halves of a vector. */
8309 static rtvec
8310 rs6000_const_vec (machine_mode mode)
8312 int i, subparts;
8313 rtvec v;
8315 switch (mode)
8317 case V1TImode:
8318 subparts = 1;
8319 break;
8320 case V2DFmode:
8321 case V2DImode:
8322 subparts = 2;
8323 break;
8324 case V4SFmode:
8325 case V4SImode:
8326 subparts = 4;
8327 break;
8328 case V8HImode:
8329 subparts = 8;
8330 break;
8331 case V16QImode:
8332 subparts = 16;
8333 break;
8334 default:
8335 gcc_unreachable();
8338 v = rtvec_alloc (subparts);
8340 for (i = 0; i < subparts / 2; ++i)
8341 RTVEC_ELT (v, i) = gen_rtx_CONST_INT (DImode, i + subparts / 2);
8342 for (i = subparts / 2; i < subparts; ++i)
8343 RTVEC_ELT (v, i) = gen_rtx_CONST_INT (DImode, i - subparts / 2);
8345 return v;
8348 /* Generate a permute rtx that represents an lxvd2x, stxvd2x, or xxpermdi
8349 for a VSX load or store operation. */
8351 rs6000_gen_le_vsx_permute (rtx source, machine_mode mode)
8353 rtx par = gen_rtx_PARALLEL (VOIDmode, rs6000_const_vec (mode));
8354 return gen_rtx_VEC_SELECT (mode, source, par);
8357 /* Emit a little-endian load from vector memory location SOURCE to VSX
8358 register DEST in mode MODE. The load is done with two permuting
8359 insn's that represent an lxvd2x and xxpermdi. */
8360 void
8361 rs6000_emit_le_vsx_load (rtx dest, rtx source, machine_mode mode)
8363 rtx tmp, permute_mem, permute_reg;
8365 /* Use V2DImode to do swaps of types with 128-bit scalare parts (TImode,
8366 V1TImode). */
8367 if (mode == TImode || mode == V1TImode)
8369 mode = V2DImode;
8370 dest = gen_lowpart (V2DImode, dest);
8371 source = adjust_address (source, V2DImode, 0);
8374 tmp = can_create_pseudo_p () ? gen_reg_rtx_and_attrs (dest) : dest;
8375 permute_mem = rs6000_gen_le_vsx_permute (source, mode);
8376 permute_reg = rs6000_gen_le_vsx_permute (tmp, mode);
8377 emit_insn (gen_rtx_SET (tmp, permute_mem));
8378 emit_insn (gen_rtx_SET (dest, permute_reg));
8381 /* Emit a little-endian store to vector memory location DEST from VSX
8382 register SOURCE in mode MODE. The store is done with two permuting
8383 insn's that represent an xxpermdi and an stxvd2x. */
8384 void
8385 rs6000_emit_le_vsx_store (rtx dest, rtx source, machine_mode mode)
8387 rtx tmp, permute_src, permute_tmp;
8389 /* This should never be called during or after reload, because it does
8390 not re-permute the source register. It is intended only for use
8391 during expand. */
8392 gcc_assert (!reload_in_progress && !lra_in_progress && !reload_completed);
8394 /* Use V2DImode to do swaps of types with 128-bit scalare parts (TImode,
8395 V1TImode). */
8396 if (mode == TImode || mode == V1TImode)
8398 mode = V2DImode;
8399 dest = adjust_address (dest, V2DImode, 0);
8400 source = gen_lowpart (V2DImode, source);
8403 tmp = can_create_pseudo_p () ? gen_reg_rtx_and_attrs (source) : source;
8404 permute_src = rs6000_gen_le_vsx_permute (source, mode);
8405 permute_tmp = rs6000_gen_le_vsx_permute (tmp, mode);
8406 emit_insn (gen_rtx_SET (tmp, permute_src));
8407 emit_insn (gen_rtx_SET (dest, permute_tmp));
8410 /* Emit a sequence representing a little-endian VSX load or store,
8411 moving data from SOURCE to DEST in mode MODE. This is done
8412 separately from rs6000_emit_move to ensure it is called only
8413 during expand. LE VSX loads and stores introduced later are
8414 handled with a split. The expand-time RTL generation allows
8415 us to optimize away redundant pairs of register-permutes. */
8416 void
8417 rs6000_emit_le_vsx_move (rtx dest, rtx source, machine_mode mode)
8419 gcc_assert (!BYTES_BIG_ENDIAN
8420 && VECTOR_MEM_VSX_P (mode)
8421 && !gpr_or_gpr_p (dest, source)
8422 && (MEM_P (source) ^ MEM_P (dest)));
8424 if (MEM_P (source))
8426 gcc_assert (REG_P (dest) || GET_CODE (dest) == SUBREG);
8427 rs6000_emit_le_vsx_load (dest, source, mode);
8429 else
8431 if (!REG_P (source))
8432 source = force_reg (mode, source);
8433 rs6000_emit_le_vsx_store (dest, source, mode);
8437 /* Emit a move from SOURCE to DEST in mode MODE. */
8438 void
8439 rs6000_emit_move (rtx dest, rtx source, machine_mode mode)
8441 rtx operands[2];
8442 operands[0] = dest;
8443 operands[1] = source;
8445 if (TARGET_DEBUG_ADDR)
8447 fprintf (stderr,
8448 "\nrs6000_emit_move: mode = %s, reload_in_progress = %d, "
8449 "reload_completed = %d, can_create_pseudos = %d.\ndest:\n",
8450 GET_MODE_NAME (mode),
8451 reload_in_progress,
8452 reload_completed,
8453 can_create_pseudo_p ());
8454 debug_rtx (dest);
8455 fprintf (stderr, "source:\n");
8456 debug_rtx (source);
8459 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
8460 if (CONST_WIDE_INT_P (operands[1])
8461 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
8463 /* This should be fixed with the introduction of CONST_WIDE_INT. */
8464 gcc_unreachable ();
8467 /* Check if GCC is setting up a block move that will end up using FP
8468 registers as temporaries. We must make sure this is acceptable. */
8469 if (GET_CODE (operands[0]) == MEM
8470 && GET_CODE (operands[1]) == MEM
8471 && mode == DImode
8472 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
8473 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
8474 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
8475 ? 32 : MEM_ALIGN (operands[0])))
8476 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
8477 ? 32
8478 : MEM_ALIGN (operands[1]))))
8479 && ! MEM_VOLATILE_P (operands [0])
8480 && ! MEM_VOLATILE_P (operands [1]))
8482 emit_move_insn (adjust_address (operands[0], SImode, 0),
8483 adjust_address (operands[1], SImode, 0));
8484 emit_move_insn (adjust_address (copy_rtx (operands[0]), SImode, 4),
8485 adjust_address (copy_rtx (operands[1]), SImode, 4));
8486 return;
8489 if (can_create_pseudo_p () && GET_CODE (operands[0]) == MEM
8490 && !gpc_reg_operand (operands[1], mode))
8491 operands[1] = force_reg (mode, operands[1]);
8493 /* Recognize the case where operand[1] is a reference to thread-local
8494 data and load its address to a register. */
8495 if (tls_referenced_p (operands[1]))
8497 enum tls_model model;
8498 rtx tmp = operands[1];
8499 rtx addend = NULL;
8501 if (GET_CODE (tmp) == CONST && GET_CODE (XEXP (tmp, 0)) == PLUS)
8503 addend = XEXP (XEXP (tmp, 0), 1);
8504 tmp = XEXP (XEXP (tmp, 0), 0);
8507 gcc_assert (GET_CODE (tmp) == SYMBOL_REF);
8508 model = SYMBOL_REF_TLS_MODEL (tmp);
8509 gcc_assert (model != 0);
8511 tmp = rs6000_legitimize_tls_address (tmp, model);
8512 if (addend)
8514 tmp = gen_rtx_PLUS (mode, tmp, addend);
8515 tmp = force_operand (tmp, operands[0]);
8517 operands[1] = tmp;
8520 /* Handle the case where reload calls us with an invalid address. */
8521 if (reload_in_progress && mode == Pmode
8522 && (! general_operand (operands[1], mode)
8523 || ! nonimmediate_operand (operands[0], mode)))
8524 goto emit_set;
8526 /* 128-bit constant floating-point values on Darwin should really be loaded
8527 as two parts. However, this premature splitting is a problem when DFmode
8528 values can go into Altivec registers. */
8529 if (!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128
8530 && !reg_addr[DFmode].scalar_in_vmx_p
8531 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
8533 rs6000_emit_move (simplify_gen_subreg (DFmode, operands[0], mode, 0),
8534 simplify_gen_subreg (DFmode, operands[1], mode, 0),
8535 DFmode);
8536 rs6000_emit_move (simplify_gen_subreg (DFmode, operands[0], mode,
8537 GET_MODE_SIZE (DFmode)),
8538 simplify_gen_subreg (DFmode, operands[1], mode,
8539 GET_MODE_SIZE (DFmode)),
8540 DFmode);
8541 return;
8544 if (reload_in_progress && cfun->machine->sdmode_stack_slot != NULL_RTX)
8545 cfun->machine->sdmode_stack_slot =
8546 eliminate_regs (cfun->machine->sdmode_stack_slot, VOIDmode, NULL_RTX);
8549 /* Transform (p0:DD, (SUBREG:DD p1:SD)) to ((SUBREG:SD p0:DD),
8550 p1:SD) if p1 is not of floating point class and p0 is spilled as
8551 we can have no analogous movsd_store for this. */
8552 if (lra_in_progress && mode == DDmode
8553 && REG_P (operands[0]) && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER
8554 && reg_preferred_class (REGNO (operands[0])) == NO_REGS
8555 && GET_CODE (operands[1]) == SUBREG && REG_P (SUBREG_REG (operands[1]))
8556 && GET_MODE (SUBREG_REG (operands[1])) == SDmode)
8558 enum reg_class cl;
8559 int regno = REGNO (SUBREG_REG (operands[1]));
8561 if (regno >= FIRST_PSEUDO_REGISTER)
8563 cl = reg_preferred_class (regno);
8564 regno = cl == NO_REGS ? -1 : ira_class_hard_regs[cl][1];
8566 if (regno >= 0 && ! FP_REGNO_P (regno))
8568 mode = SDmode;
8569 operands[0] = gen_lowpart_SUBREG (SDmode, operands[0]);
8570 operands[1] = SUBREG_REG (operands[1]);
8573 if (lra_in_progress
8574 && mode == SDmode
8575 && REG_P (operands[0]) && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER
8576 && reg_preferred_class (REGNO (operands[0])) == NO_REGS
8577 && (REG_P (operands[1])
8578 || (GET_CODE (operands[1]) == SUBREG
8579 && REG_P (SUBREG_REG (operands[1])))))
8581 int regno = REGNO (GET_CODE (operands[1]) == SUBREG
8582 ? SUBREG_REG (operands[1]) : operands[1]);
8583 enum reg_class cl;
8585 if (regno >= FIRST_PSEUDO_REGISTER)
8587 cl = reg_preferred_class (regno);
8588 gcc_assert (cl != NO_REGS);
8589 regno = ira_class_hard_regs[cl][0];
8591 if (FP_REGNO_P (regno))
8593 if (GET_MODE (operands[0]) != DDmode)
8594 operands[0] = gen_rtx_SUBREG (DDmode, operands[0], 0);
8595 emit_insn (gen_movsd_store (operands[0], operands[1]));
8597 else if (INT_REGNO_P (regno))
8598 emit_insn (gen_movsd_hardfloat (operands[0], operands[1]));
8599 else
8600 gcc_unreachable();
8601 return;
8603 /* Transform ((SUBREG:DD p0:SD), p1:DD) to (p0:SD, (SUBREG:SD
8604 p:DD)) if p0 is not of floating point class and p1 is spilled as
8605 we can have no analogous movsd_load for this. */
8606 if (lra_in_progress && mode == DDmode
8607 && GET_CODE (operands[0]) == SUBREG && REG_P (SUBREG_REG (operands[0]))
8608 && GET_MODE (SUBREG_REG (operands[0])) == SDmode
8609 && REG_P (operands[1]) && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER
8610 && reg_preferred_class (REGNO (operands[1])) == NO_REGS)
8612 enum reg_class cl;
8613 int regno = REGNO (SUBREG_REG (operands[0]));
8615 if (regno >= FIRST_PSEUDO_REGISTER)
8617 cl = reg_preferred_class (regno);
8618 regno = cl == NO_REGS ? -1 : ira_class_hard_regs[cl][0];
8620 if (regno >= 0 && ! FP_REGNO_P (regno))
8622 mode = SDmode;
8623 operands[0] = SUBREG_REG (operands[0]);
8624 operands[1] = gen_lowpart_SUBREG (SDmode, operands[1]);
8627 if (lra_in_progress
8628 && mode == SDmode
8629 && (REG_P (operands[0])
8630 || (GET_CODE (operands[0]) == SUBREG
8631 && REG_P (SUBREG_REG (operands[0]))))
8632 && REG_P (operands[1]) && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER
8633 && reg_preferred_class (REGNO (operands[1])) == NO_REGS)
8635 int regno = REGNO (GET_CODE (operands[0]) == SUBREG
8636 ? SUBREG_REG (operands[0]) : operands[0]);
8637 enum reg_class cl;
8639 if (regno >= FIRST_PSEUDO_REGISTER)
8641 cl = reg_preferred_class (regno);
8642 gcc_assert (cl != NO_REGS);
8643 regno = ira_class_hard_regs[cl][0];
8645 if (FP_REGNO_P (regno))
8647 if (GET_MODE (operands[1]) != DDmode)
8648 operands[1] = gen_rtx_SUBREG (DDmode, operands[1], 0);
8649 emit_insn (gen_movsd_load (operands[0], operands[1]));
8651 else if (INT_REGNO_P (regno))
8652 emit_insn (gen_movsd_hardfloat (operands[0], operands[1]));
8653 else
8654 gcc_unreachable();
8655 return;
8658 if (reload_in_progress
8659 && mode == SDmode
8660 && cfun->machine->sdmode_stack_slot != NULL_RTX
8661 && MEM_P (operands[0])
8662 && rtx_equal_p (operands[0], cfun->machine->sdmode_stack_slot)
8663 && REG_P (operands[1]))
8665 if (FP_REGNO_P (REGNO (operands[1])))
8667 rtx mem = adjust_address_nv (operands[0], DDmode, 0);
8668 mem = eliminate_regs (mem, VOIDmode, NULL_RTX);
8669 emit_insn (gen_movsd_store (mem, operands[1]));
8671 else if (INT_REGNO_P (REGNO (operands[1])))
8673 rtx mem = operands[0];
8674 if (BYTES_BIG_ENDIAN)
8675 mem = adjust_address_nv (mem, mode, 4);
8676 mem = eliminate_regs (mem, VOIDmode, NULL_RTX);
8677 emit_insn (gen_movsd_hardfloat (mem, operands[1]));
8679 else
8680 gcc_unreachable();
8681 return;
8683 if (reload_in_progress
8684 && mode == SDmode
8685 && REG_P (operands[0])
8686 && MEM_P (operands[1])
8687 && cfun->machine->sdmode_stack_slot != NULL_RTX
8688 && rtx_equal_p (operands[1], cfun->machine->sdmode_stack_slot))
8690 if (FP_REGNO_P (REGNO (operands[0])))
8692 rtx mem = adjust_address_nv (operands[1], DDmode, 0);
8693 mem = eliminate_regs (mem, VOIDmode, NULL_RTX);
8694 emit_insn (gen_movsd_load (operands[0], mem));
8696 else if (INT_REGNO_P (REGNO (operands[0])))
8698 rtx mem = operands[1];
8699 if (BYTES_BIG_ENDIAN)
8700 mem = adjust_address_nv (mem, mode, 4);
8701 mem = eliminate_regs (mem, VOIDmode, NULL_RTX);
8702 emit_insn (gen_movsd_hardfloat (operands[0], mem));
8704 else
8705 gcc_unreachable();
8706 return;
8709 /* FIXME: In the long term, this switch statement should go away
8710 and be replaced by a sequence of tests based on things like
8711 mode == Pmode. */
8712 switch (mode)
8714 case HImode:
8715 case QImode:
8716 if (CONSTANT_P (operands[1])
8717 && GET_CODE (operands[1]) != CONST_INT)
8718 operands[1] = force_const_mem (mode, operands[1]);
8719 break;
8721 case TFmode:
8722 case TDmode:
8723 rs6000_eliminate_indexed_memrefs (operands);
8724 /* fall through */
8726 case DFmode:
8727 case DDmode:
8728 case SFmode:
8729 case SDmode:
8730 if (CONSTANT_P (operands[1])
8731 && ! easy_fp_constant (operands[1], mode))
8732 operands[1] = force_const_mem (mode, operands[1]);
8733 break;
8735 case V16QImode:
8736 case V8HImode:
8737 case V4SFmode:
8738 case V4SImode:
8739 case V4HImode:
8740 case V2SFmode:
8741 case V2SImode:
8742 case V1DImode:
8743 case V2DFmode:
8744 case V2DImode:
8745 case V1TImode:
8746 if (CONSTANT_P (operands[1])
8747 && !easy_vector_constant (operands[1], mode))
8748 operands[1] = force_const_mem (mode, operands[1]);
8749 break;
8751 case SImode:
8752 case DImode:
8753 /* Use default pattern for address of ELF small data */
8754 if (TARGET_ELF
8755 && mode == Pmode
8756 && DEFAULT_ABI == ABI_V4
8757 && (GET_CODE (operands[1]) == SYMBOL_REF
8758 || GET_CODE (operands[1]) == CONST)
8759 && small_data_operand (operands[1], mode))
8761 emit_insn (gen_rtx_SET (operands[0], operands[1]));
8762 return;
8765 if (DEFAULT_ABI == ABI_V4
8766 && mode == Pmode && mode == SImode
8767 && flag_pic == 1 && got_operand (operands[1], mode))
8769 emit_insn (gen_movsi_got (operands[0], operands[1]));
8770 return;
8773 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
8774 && TARGET_NO_TOC
8775 && ! flag_pic
8776 && mode == Pmode
8777 && CONSTANT_P (operands[1])
8778 && GET_CODE (operands[1]) != HIGH
8779 && GET_CODE (operands[1]) != CONST_INT)
8781 rtx target = (!can_create_pseudo_p ()
8782 ? operands[0]
8783 : gen_reg_rtx (mode));
8785 /* If this is a function address on -mcall-aixdesc,
8786 convert it to the address of the descriptor. */
8787 if (DEFAULT_ABI == ABI_AIX
8788 && GET_CODE (operands[1]) == SYMBOL_REF
8789 && XSTR (operands[1], 0)[0] == '.')
8791 const char *name = XSTR (operands[1], 0);
8792 rtx new_ref;
8793 while (*name == '.')
8794 name++;
8795 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
8796 CONSTANT_POOL_ADDRESS_P (new_ref)
8797 = CONSTANT_POOL_ADDRESS_P (operands[1]);
8798 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
8799 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
8800 SYMBOL_REF_DATA (new_ref) = SYMBOL_REF_DATA (operands[1]);
8801 operands[1] = new_ref;
8804 if (DEFAULT_ABI == ABI_DARWIN)
8806 #if TARGET_MACHO
8807 if (MACHO_DYNAMIC_NO_PIC_P)
8809 /* Take care of any required data indirection. */
8810 operands[1] = rs6000_machopic_legitimize_pic_address (
8811 operands[1], mode, operands[0]);
8812 if (operands[0] != operands[1])
8813 emit_insn (gen_rtx_SET (operands[0], operands[1]));
8814 return;
8816 #endif
8817 emit_insn (gen_macho_high (target, operands[1]));
8818 emit_insn (gen_macho_low (operands[0], target, operands[1]));
8819 return;
8822 emit_insn (gen_elf_high (target, operands[1]));
8823 emit_insn (gen_elf_low (operands[0], target, operands[1]));
8824 return;
8827 /* If this is a SYMBOL_REF that refers to a constant pool entry,
8828 and we have put it in the TOC, we just need to make a TOC-relative
8829 reference to it. */
8830 if (TARGET_TOC
8831 && GET_CODE (operands[1]) == SYMBOL_REF
8832 && use_toc_relative_ref (operands[1], mode))
8833 operands[1] = create_TOC_reference (operands[1], operands[0]);
8834 else if (mode == Pmode
8835 && CONSTANT_P (operands[1])
8836 && GET_CODE (operands[1]) != HIGH
8837 && ((GET_CODE (operands[1]) != CONST_INT
8838 && ! easy_fp_constant (operands[1], mode))
8839 || (GET_CODE (operands[1]) == CONST_INT
8840 && (num_insns_constant (operands[1], mode)
8841 > (TARGET_CMODEL != CMODEL_SMALL ? 3 : 2)))
8842 || (GET_CODE (operands[0]) == REG
8843 && FP_REGNO_P (REGNO (operands[0]))))
8844 && !toc_relative_expr_p (operands[1], false)
8845 && (TARGET_CMODEL == CMODEL_SMALL
8846 || can_create_pseudo_p ()
8847 || (REG_P (operands[0])
8848 && INT_REG_OK_FOR_BASE_P (operands[0], true))))
8851 #if TARGET_MACHO
8852 /* Darwin uses a special PIC legitimizer. */
8853 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
8855 operands[1] =
8856 rs6000_machopic_legitimize_pic_address (operands[1], mode,
8857 operands[0]);
8858 if (operands[0] != operands[1])
8859 emit_insn (gen_rtx_SET (operands[0], operands[1]));
8860 return;
8862 #endif
8864 /* If we are to limit the number of things we put in the TOC and
8865 this is a symbol plus a constant we can add in one insn,
8866 just put the symbol in the TOC and add the constant. Don't do
8867 this if reload is in progress. */
8868 if (GET_CODE (operands[1]) == CONST
8869 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
8870 && GET_CODE (XEXP (operands[1], 0)) == PLUS
8871 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
8872 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
8873 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
8874 && ! side_effects_p (operands[0]))
8876 rtx sym =
8877 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
8878 rtx other = XEXP (XEXP (operands[1], 0), 1);
8880 sym = force_reg (mode, sym);
8881 emit_insn (gen_add3_insn (operands[0], sym, other));
8882 return;
8885 operands[1] = force_const_mem (mode, operands[1]);
8887 if (TARGET_TOC
8888 && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
8889 && constant_pool_expr_p (XEXP (operands[1], 0))
8890 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
8891 get_pool_constant (XEXP (operands[1], 0)),
8892 get_pool_mode (XEXP (operands[1], 0))))
8894 rtx tocref = create_TOC_reference (XEXP (operands[1], 0),
8895 operands[0]);
8896 operands[1] = gen_const_mem (mode, tocref);
8897 set_mem_alias_set (operands[1], get_TOC_alias_set ());
8900 break;
8902 case TImode:
8903 if (!VECTOR_MEM_VSX_P (TImode))
8904 rs6000_eliminate_indexed_memrefs (operands);
8905 break;
8907 case PTImode:
8908 rs6000_eliminate_indexed_memrefs (operands);
8909 break;
8911 default:
8912 fatal_insn ("bad move", gen_rtx_SET (dest, source));
8915 /* Above, we may have called force_const_mem which may have returned
8916 an invalid address. If we can, fix this up; otherwise, reload will
8917 have to deal with it. */
8918 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
8919 operands[1] = validize_mem (operands[1]);
8921 emit_set:
8922 emit_insn (gen_rtx_SET (operands[0], operands[1]));
8925 /* Return true if a structure, union or array containing FIELD should be
8926 accessed using `BLKMODE'.
8928 For the SPE, simd types are V2SI, and gcc can be tempted to put the
8929 entire thing in a DI and use subregs to access the internals.
8930 store_bit_field() will force (subreg:DI (reg:V2SI x))'s to the
8931 back-end. Because a single GPR can hold a V2SI, but not a DI, the
8932 best thing to do is set structs to BLKmode and avoid Severe Tire
8933 Damage.
8935 On e500 v2, DF and DI modes suffer from the same anomaly. DF can
8936 fit into 1, whereas DI still needs two. */
8938 static bool
8939 rs6000_member_type_forces_blk (const_tree field, machine_mode mode)
8941 return ((TARGET_SPE && TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE)
8942 || (TARGET_E500_DOUBLE && mode == DFmode));
8945 /* Nonzero if we can use a floating-point register to pass this arg. */
8946 #define USE_FP_FOR_ARG_P(CUM,MODE) \
8947 (SCALAR_FLOAT_MODE_P (MODE) \
8948 && (CUM)->fregno <= FP_ARG_MAX_REG \
8949 && TARGET_HARD_FLOAT && TARGET_FPRS)
8951 /* Nonzero if we can use an AltiVec register to pass this arg. */
8952 #define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,NAMED) \
8953 (ALTIVEC_OR_VSX_VECTOR_MODE (MODE) \
8954 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
8955 && TARGET_ALTIVEC_ABI \
8956 && (NAMED))
8958 /* Walk down the type tree of TYPE counting consecutive base elements.
8959 If *MODEP is VOIDmode, then set it to the first valid floating point
8960 or vector type. If a non-floating point or vector type is found, or
8961 if a floating point or vector type that doesn't match a non-VOIDmode
8962 *MODEP is found, then return -1, otherwise return the count in the
8963 sub-tree. */
8965 static int
8966 rs6000_aggregate_candidate (const_tree type, machine_mode *modep)
8968 machine_mode mode;
8969 HOST_WIDE_INT size;
8971 switch (TREE_CODE (type))
8973 case REAL_TYPE:
8974 mode = TYPE_MODE (type);
8975 if (!SCALAR_FLOAT_MODE_P (mode))
8976 return -1;
8978 if (*modep == VOIDmode)
8979 *modep = mode;
8981 if (*modep == mode)
8982 return 1;
8984 break;
8986 case COMPLEX_TYPE:
8987 mode = TYPE_MODE (TREE_TYPE (type));
8988 if (!SCALAR_FLOAT_MODE_P (mode))
8989 return -1;
8991 if (*modep == VOIDmode)
8992 *modep = mode;
8994 if (*modep == mode)
8995 return 2;
8997 break;
8999 case VECTOR_TYPE:
9000 if (!TARGET_ALTIVEC_ABI || !TARGET_ALTIVEC)
9001 return -1;
9003 /* Use V4SImode as representative of all 128-bit vector types. */
9004 size = int_size_in_bytes (type);
9005 switch (size)
9007 case 16:
9008 mode = V4SImode;
9009 break;
9010 default:
9011 return -1;
9014 if (*modep == VOIDmode)
9015 *modep = mode;
9017 /* Vector modes are considered to be opaque: two vectors are
9018 equivalent for the purposes of being homogeneous aggregates
9019 if they are the same size. */
9020 if (*modep == mode)
9021 return 1;
9023 break;
9025 case ARRAY_TYPE:
9027 int count;
9028 tree index = TYPE_DOMAIN (type);
9030 /* Can't handle incomplete types nor sizes that are not
9031 fixed. */
9032 if (!COMPLETE_TYPE_P (type)
9033 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
9034 return -1;
9036 count = rs6000_aggregate_candidate (TREE_TYPE (type), modep);
9037 if (count == -1
9038 || !index
9039 || !TYPE_MAX_VALUE (index)
9040 || !tree_fits_uhwi_p (TYPE_MAX_VALUE (index))
9041 || !TYPE_MIN_VALUE (index)
9042 || !tree_fits_uhwi_p (TYPE_MIN_VALUE (index))
9043 || count < 0)
9044 return -1;
9046 count *= (1 + tree_to_uhwi (TYPE_MAX_VALUE (index))
9047 - tree_to_uhwi (TYPE_MIN_VALUE (index)));
9049 /* There must be no padding. */
9050 if (wi::ne_p (TYPE_SIZE (type), count * GET_MODE_BITSIZE (*modep)))
9051 return -1;
9053 return count;
9056 case RECORD_TYPE:
9058 int count = 0;
9059 int sub_count;
9060 tree field;
9062 /* Can't handle incomplete types nor sizes that are not
9063 fixed. */
9064 if (!COMPLETE_TYPE_P (type)
9065 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
9066 return -1;
9068 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
9070 if (TREE_CODE (field) != FIELD_DECL)
9071 continue;
9073 sub_count = rs6000_aggregate_candidate (TREE_TYPE (field), modep);
9074 if (sub_count < 0)
9075 return -1;
9076 count += sub_count;
9079 /* There must be no padding. */
9080 if (wi::ne_p (TYPE_SIZE (type), count * GET_MODE_BITSIZE (*modep)))
9081 return -1;
9083 return count;
9086 case UNION_TYPE:
9087 case QUAL_UNION_TYPE:
9089 /* These aren't very interesting except in a degenerate case. */
9090 int count = 0;
9091 int sub_count;
9092 tree field;
9094 /* Can't handle incomplete types nor sizes that are not
9095 fixed. */
9096 if (!COMPLETE_TYPE_P (type)
9097 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
9098 return -1;
9100 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
9102 if (TREE_CODE (field) != FIELD_DECL)
9103 continue;
9105 sub_count = rs6000_aggregate_candidate (TREE_TYPE (field), modep);
9106 if (sub_count < 0)
9107 return -1;
9108 count = count > sub_count ? count : sub_count;
9111 /* There must be no padding. */
9112 if (wi::ne_p (TYPE_SIZE (type), count * GET_MODE_BITSIZE (*modep)))
9113 return -1;
9115 return count;
9118 default:
9119 break;
9122 return -1;
9125 /* If an argument, whose type is described by TYPE and MODE, is a homogeneous
9126 float or vector aggregate that shall be passed in FP/vector registers
9127 according to the ELFv2 ABI, return the homogeneous element mode in
9128 *ELT_MODE and the number of elements in *N_ELTS, and return TRUE.
9130 Otherwise, set *ELT_MODE to MODE and *N_ELTS to 1, and return FALSE. */
9132 static bool
9133 rs6000_discover_homogeneous_aggregate (machine_mode mode, const_tree type,
9134 machine_mode *elt_mode,
9135 int *n_elts)
9137 /* Note that we do not accept complex types at the top level as
9138 homogeneous aggregates; these types are handled via the
9139 targetm.calls.split_complex_arg mechanism. Complex types
9140 can be elements of homogeneous aggregates, however. */
9141 if (DEFAULT_ABI == ABI_ELFv2 && type && AGGREGATE_TYPE_P (type))
9143 machine_mode field_mode = VOIDmode;
9144 int field_count = rs6000_aggregate_candidate (type, &field_mode);
9146 if (field_count > 0)
9148 int n_regs = (SCALAR_FLOAT_MODE_P (field_mode)?
9149 (GET_MODE_SIZE (field_mode) + 7) >> 3 : 1);
9151 /* The ELFv2 ABI allows homogeneous aggregates to occupy
9152 up to AGGR_ARG_NUM_REG registers. */
9153 if (field_count * n_regs <= AGGR_ARG_NUM_REG)
9155 if (elt_mode)
9156 *elt_mode = field_mode;
9157 if (n_elts)
9158 *n_elts = field_count;
9159 return true;
9164 if (elt_mode)
9165 *elt_mode = mode;
9166 if (n_elts)
9167 *n_elts = 1;
9168 return false;
9171 /* Return a nonzero value to say to return the function value in
9172 memory, just as large structures are always returned. TYPE will be
9173 the data type of the value, and FNTYPE will be the type of the
9174 function doing the returning, or @code{NULL} for libcalls.
9176 The AIX ABI for the RS/6000 specifies that all structures are
9177 returned in memory. The Darwin ABI does the same.
9179 For the Darwin 64 Bit ABI, a function result can be returned in
9180 registers or in memory, depending on the size of the return data
9181 type. If it is returned in registers, the value occupies the same
9182 registers as it would if it were the first and only function
9183 argument. Otherwise, the function places its result in memory at
9184 the location pointed to by GPR3.
9186 The SVR4 ABI specifies that structures <= 8 bytes are returned in r3/r4,
9187 but a draft put them in memory, and GCC used to implement the draft
9188 instead of the final standard. Therefore, aix_struct_return
9189 controls this instead of DEFAULT_ABI; V.4 targets needing backward
9190 compatibility can change DRAFT_V4_STRUCT_RET to override the
9191 default, and -m switches get the final word. See
9192 rs6000_option_override_internal for more details.
9194 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
9195 long double support is enabled. These values are returned in memory.
9197 int_size_in_bytes returns -1 for variable size objects, which go in
9198 memory always. The cast to unsigned makes -1 > 8. */
9200 static bool
9201 rs6000_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
9203 /* For the Darwin64 ABI, test if we can fit the return value in regs. */
9204 if (TARGET_MACHO
9205 && rs6000_darwin64_abi
9206 && TREE_CODE (type) == RECORD_TYPE
9207 && int_size_in_bytes (type) > 0)
9209 CUMULATIVE_ARGS valcum;
9210 rtx valret;
9212 valcum.words = 0;
9213 valcum.fregno = FP_ARG_MIN_REG;
9214 valcum.vregno = ALTIVEC_ARG_MIN_REG;
9215 /* Do a trial code generation as if this were going to be passed
9216 as an argument; if any part goes in memory, we return NULL. */
9217 valret = rs6000_darwin64_record_arg (&valcum, type, true, true);
9218 if (valret)
9219 return false;
9220 /* Otherwise fall through to more conventional ABI rules. */
9223 /* The ELFv2 ABI returns homogeneous VFP aggregates in registers */
9224 if (rs6000_discover_homogeneous_aggregate (TYPE_MODE (type), type,
9225 NULL, NULL))
9226 return false;
9228 /* The ELFv2 ABI returns aggregates up to 16B in registers */
9229 if (DEFAULT_ABI == ABI_ELFv2 && AGGREGATE_TYPE_P (type)
9230 && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) <= 16)
9231 return false;
9233 if (AGGREGATE_TYPE_P (type)
9234 && (aix_struct_return
9235 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
9236 return true;
9238 /* Allow -maltivec -mabi=no-altivec without warning. Altivec vector
9239 modes only exist for GCC vector types if -maltivec. */
9240 if (TARGET_32BIT && !TARGET_ALTIVEC_ABI
9241 && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
9242 return false;
9244 /* Return synthetic vectors in memory. */
9245 if (TREE_CODE (type) == VECTOR_TYPE
9246 && int_size_in_bytes (type) > (TARGET_ALTIVEC_ABI ? 16 : 8))
9248 static bool warned_for_return_big_vectors = false;
9249 if (!warned_for_return_big_vectors)
9251 warning (0, "GCC vector returned by reference: "
9252 "non-standard ABI extension with no compatibility guarantee");
9253 warned_for_return_big_vectors = true;
9255 return true;
9258 if (DEFAULT_ABI == ABI_V4 && TARGET_IEEEQUAD && TYPE_MODE (type) == TFmode)
9259 return true;
9261 return false;
9264 /* Specify whether values returned in registers should be at the most
9265 significant end of a register. We want aggregates returned by
9266 value to match the way aggregates are passed to functions. */
9268 static bool
9269 rs6000_return_in_msb (const_tree valtype)
9271 return (DEFAULT_ABI == ABI_ELFv2
9272 && BYTES_BIG_ENDIAN
9273 && AGGREGATE_TYPE_P (valtype)
9274 && FUNCTION_ARG_PADDING (TYPE_MODE (valtype), valtype) == upward);
9277 #ifdef HAVE_AS_GNU_ATTRIBUTE
9278 /* Return TRUE if a call to function FNDECL may be one that
9279 potentially affects the function calling ABI of the object file. */
9281 static bool
9282 call_ABI_of_interest (tree fndecl)
9284 if (symtab->state == EXPANSION)
9286 struct cgraph_node *c_node;
9288 /* Libcalls are always interesting. */
9289 if (fndecl == NULL_TREE)
9290 return true;
9292 /* Any call to an external function is interesting. */
9293 if (DECL_EXTERNAL (fndecl))
9294 return true;
9296 /* Interesting functions that we are emitting in this object file. */
9297 c_node = cgraph_node::get (fndecl);
9298 c_node = c_node->ultimate_alias_target ();
9299 return !c_node->only_called_directly_p ();
9301 return false;
9303 #endif
9305 /* Initialize a variable CUM of type CUMULATIVE_ARGS
9306 for a call to a function whose data type is FNTYPE.
9307 For a library call, FNTYPE is 0 and RETURN_MODE the return value mode.
9309 For incoming args we set the number of arguments in the prototype large
9310 so we never return a PARALLEL. */
9312 void
9313 init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
9314 rtx libname ATTRIBUTE_UNUSED, int incoming,
9315 int libcall, int n_named_args,
9316 tree fndecl ATTRIBUTE_UNUSED,
9317 machine_mode return_mode ATTRIBUTE_UNUSED)
9319 static CUMULATIVE_ARGS zero_cumulative;
9321 *cum = zero_cumulative;
9322 cum->words = 0;
9323 cum->fregno = FP_ARG_MIN_REG;
9324 cum->vregno = ALTIVEC_ARG_MIN_REG;
9325 cum->prototype = (fntype && prototype_p (fntype));
9326 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
9327 ? CALL_LIBCALL : CALL_NORMAL);
9328 cum->sysv_gregno = GP_ARG_MIN_REG;
9329 cum->stdarg = stdarg_p (fntype);
9331 cum->nargs_prototype = 0;
9332 if (incoming || cum->prototype)
9333 cum->nargs_prototype = n_named_args;
9335 /* Check for a longcall attribute. */
9336 if ((!fntype && rs6000_default_long_calls)
9337 || (fntype
9338 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
9339 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype))))
9340 cum->call_cookie |= CALL_LONG;
9342 if (TARGET_DEBUG_ARG)
9344 fprintf (stderr, "\ninit_cumulative_args:");
9345 if (fntype)
9347 tree ret_type = TREE_TYPE (fntype);
9348 fprintf (stderr, " ret code = %s,",
9349 get_tree_code_name (TREE_CODE (ret_type)));
9352 if (cum->call_cookie & CALL_LONG)
9353 fprintf (stderr, " longcall,");
9355 fprintf (stderr, " proto = %d, nargs = %d\n",
9356 cum->prototype, cum->nargs_prototype);
9359 #ifdef HAVE_AS_GNU_ATTRIBUTE
9360 if (DEFAULT_ABI == ABI_V4)
9362 cum->escapes = call_ABI_of_interest (fndecl);
9363 if (cum->escapes)
9365 tree return_type;
9367 if (fntype)
9369 return_type = TREE_TYPE (fntype);
9370 return_mode = TYPE_MODE (return_type);
9372 else
9373 return_type = lang_hooks.types.type_for_mode (return_mode, 0);
9375 if (return_type != NULL)
9377 if (TREE_CODE (return_type) == RECORD_TYPE
9378 && TYPE_TRANSPARENT_AGGR (return_type))
9380 return_type = TREE_TYPE (first_field (return_type));
9381 return_mode = TYPE_MODE (return_type);
9383 if (AGGREGATE_TYPE_P (return_type)
9384 && ((unsigned HOST_WIDE_INT) int_size_in_bytes (return_type)
9385 <= 8))
9386 rs6000_returns_struct = true;
9388 if (SCALAR_FLOAT_MODE_P (return_mode))
9389 rs6000_passes_float = true;
9390 else if (ALTIVEC_OR_VSX_VECTOR_MODE (return_mode)
9391 || SPE_VECTOR_MODE (return_mode))
9392 rs6000_passes_vector = true;
9395 #endif
9397 if (fntype
9398 && !TARGET_ALTIVEC
9399 && TARGET_ALTIVEC_ABI
9400 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
9402 error ("cannot return value in vector register because"
9403 " altivec instructions are disabled, use -maltivec"
9404 " to enable them");
9408 /* The mode the ABI uses for a word. This is not the same as word_mode
9409 for -m32 -mpowerpc64. This is used to implement various target hooks. */
9411 static machine_mode
9412 rs6000_abi_word_mode (void)
9414 return TARGET_32BIT ? SImode : DImode;
9417 /* On rs6000, function arguments are promoted, as are function return
9418 values. */
9420 static machine_mode
9421 rs6000_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
9422 machine_mode mode,
9423 int *punsignedp ATTRIBUTE_UNUSED,
9424 const_tree, int)
9426 PROMOTE_MODE (mode, *punsignedp, type);
9428 return mode;
9431 /* Return true if TYPE must be passed on the stack and not in registers. */
9433 static bool
9434 rs6000_must_pass_in_stack (machine_mode mode, const_tree type)
9436 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2 || TARGET_64BIT)
9437 return must_pass_in_stack_var_size (mode, type);
9438 else
9439 return must_pass_in_stack_var_size_or_pad (mode, type);
9442 /* If defined, a C expression which determines whether, and in which
9443 direction, to pad out an argument with extra space. The value
9444 should be of type `enum direction': either `upward' to pad above
9445 the argument, `downward' to pad below, or `none' to inhibit
9446 padding.
9448 For the AIX ABI structs are always stored left shifted in their
9449 argument slot. */
9451 enum direction
9452 function_arg_padding (machine_mode mode, const_tree type)
9454 #ifndef AGGREGATE_PADDING_FIXED
9455 #define AGGREGATE_PADDING_FIXED 0
9456 #endif
9457 #ifndef AGGREGATES_PAD_UPWARD_ALWAYS
9458 #define AGGREGATES_PAD_UPWARD_ALWAYS 0
9459 #endif
9461 if (!AGGREGATE_PADDING_FIXED)
9463 /* GCC used to pass structures of the same size as integer types as
9464 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
9465 i.e. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
9466 passed padded downward, except that -mstrict-align further
9467 muddied the water in that multi-component structures of 2 and 4
9468 bytes in size were passed padded upward.
9470 The following arranges for best compatibility with previous
9471 versions of gcc, but removes the -mstrict-align dependency. */
9472 if (BYTES_BIG_ENDIAN)
9474 HOST_WIDE_INT size = 0;
9476 if (mode == BLKmode)
9478 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
9479 size = int_size_in_bytes (type);
9481 else
9482 size = GET_MODE_SIZE (mode);
9484 if (size == 1 || size == 2 || size == 4)
9485 return downward;
9487 return upward;
9490 if (AGGREGATES_PAD_UPWARD_ALWAYS)
9492 if (type != 0 && AGGREGATE_TYPE_P (type))
9493 return upward;
9496 /* Fall back to the default. */
9497 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
9500 /* If defined, a C expression that gives the alignment boundary, in bits,
9501 of an argument with the specified mode and type. If it is not defined,
9502 PARM_BOUNDARY is used for all arguments.
9504 V.4 wants long longs and doubles to be double word aligned. Just
9505 testing the mode size is a boneheaded way to do this as it means
9506 that other types such as complex int are also double word aligned.
9507 However, we're stuck with this because changing the ABI might break
9508 existing library interfaces.
9510 Doubleword align SPE vectors.
9511 Quadword align Altivec/VSX vectors.
9512 Quadword align large synthetic vector types. */
9514 static unsigned int
9515 rs6000_function_arg_boundary (machine_mode mode, const_tree type)
9517 machine_mode elt_mode;
9518 int n_elts;
9520 rs6000_discover_homogeneous_aggregate (mode, type, &elt_mode, &n_elts);
9522 if (DEFAULT_ABI == ABI_V4
9523 && (GET_MODE_SIZE (mode) == 8
9524 || (TARGET_HARD_FLOAT
9525 && TARGET_FPRS
9526 && (mode == TFmode || mode == TDmode))))
9527 return 64;
9528 else if (SPE_VECTOR_MODE (mode)
9529 || (type && TREE_CODE (type) == VECTOR_TYPE
9530 && int_size_in_bytes (type) >= 8
9531 && int_size_in_bytes (type) < 16))
9532 return 64;
9533 else if (ALTIVEC_OR_VSX_VECTOR_MODE (elt_mode)
9534 || (type && TREE_CODE (type) == VECTOR_TYPE
9535 && int_size_in_bytes (type) >= 16))
9536 return 128;
9538 /* Aggregate types that need > 8 byte alignment are quadword-aligned
9539 in the parameter area in the ELFv2 ABI, and in the AIX ABI unless
9540 -mcompat-align-parm is used. */
9541 if (((DEFAULT_ABI == ABI_AIX && !rs6000_compat_align_parm)
9542 || DEFAULT_ABI == ABI_ELFv2)
9543 && type && TYPE_ALIGN (type) > 64)
9545 /* "Aggregate" means any AGGREGATE_TYPE except for single-element
9546 or homogeneous float/vector aggregates here. We already handled
9547 vector aggregates above, but still need to check for float here. */
9548 bool aggregate_p = (AGGREGATE_TYPE_P (type)
9549 && !SCALAR_FLOAT_MODE_P (elt_mode));
9551 /* We used to check for BLKmode instead of the above aggregate type
9552 check. Warn when this results in any difference to the ABI. */
9553 if (aggregate_p != (mode == BLKmode))
9555 static bool warned;
9556 if (!warned && warn_psabi)
9558 warned = true;
9559 inform (input_location,
9560 "the ABI of passing aggregates with %d-byte alignment"
9561 " has changed in GCC 5",
9562 (int) TYPE_ALIGN (type) / BITS_PER_UNIT);
9566 if (aggregate_p)
9567 return 128;
9570 /* Similar for the Darwin64 ABI. Note that for historical reasons we
9571 implement the "aggregate type" check as a BLKmode check here; this
9572 means certain aggregate types are in fact not aligned. */
9573 if (TARGET_MACHO && rs6000_darwin64_abi
9574 && mode == BLKmode
9575 && type && TYPE_ALIGN (type) > 64)
9576 return 128;
9578 return PARM_BOUNDARY;
9581 /* The offset in words to the start of the parameter save area. */
9583 static unsigned int
9584 rs6000_parm_offset (void)
9586 return (DEFAULT_ABI == ABI_V4 ? 2
9587 : DEFAULT_ABI == ABI_ELFv2 ? 4
9588 : 6);
9591 /* For a function parm of MODE and TYPE, return the starting word in
9592 the parameter area. NWORDS of the parameter area are already used. */
9594 static unsigned int
9595 rs6000_parm_start (machine_mode mode, const_tree type,
9596 unsigned int nwords)
9598 unsigned int align;
9600 align = rs6000_function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
9601 return nwords + (-(rs6000_parm_offset () + nwords) & align);
9604 /* Compute the size (in words) of a function argument. */
9606 static unsigned long
9607 rs6000_arg_size (machine_mode mode, const_tree type)
9609 unsigned long size;
9611 if (mode != BLKmode)
9612 size = GET_MODE_SIZE (mode);
9613 else
9614 size = int_size_in_bytes (type);
9616 if (TARGET_32BIT)
9617 return (size + 3) >> 2;
9618 else
9619 return (size + 7) >> 3;
9622 /* Use this to flush pending int fields. */
9624 static void
9625 rs6000_darwin64_record_arg_advance_flush (CUMULATIVE_ARGS *cum,
9626 HOST_WIDE_INT bitpos, int final)
9628 unsigned int startbit, endbit;
9629 int intregs, intoffset;
9630 machine_mode mode;
9632 /* Handle the situations where a float is taking up the first half
9633 of the GPR, and the other half is empty (typically due to
9634 alignment restrictions). We can detect this by a 8-byte-aligned
9635 int field, or by seeing that this is the final flush for this
9636 argument. Count the word and continue on. */
9637 if (cum->floats_in_gpr == 1
9638 && (cum->intoffset % 64 == 0
9639 || (cum->intoffset == -1 && final)))
9641 cum->words++;
9642 cum->floats_in_gpr = 0;
9645 if (cum->intoffset == -1)
9646 return;
9648 intoffset = cum->intoffset;
9649 cum->intoffset = -1;
9650 cum->floats_in_gpr = 0;
9652 if (intoffset % BITS_PER_WORD != 0)
9654 mode = mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
9655 MODE_INT, 0);
9656 if (mode == BLKmode)
9658 /* We couldn't find an appropriate mode, which happens,
9659 e.g., in packed structs when there are 3 bytes to load.
9660 Back intoffset back to the beginning of the word in this
9661 case. */
9662 intoffset = intoffset & -BITS_PER_WORD;
9666 startbit = intoffset & -BITS_PER_WORD;
9667 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
9668 intregs = (endbit - startbit) / BITS_PER_WORD;
9669 cum->words += intregs;
9670 /* words should be unsigned. */
9671 if ((unsigned)cum->words < (endbit/BITS_PER_WORD))
9673 int pad = (endbit/BITS_PER_WORD) - cum->words;
9674 cum->words += pad;
9678 /* The darwin64 ABI calls for us to recurse down through structs,
9679 looking for elements passed in registers. Unfortunately, we have
9680 to track int register count here also because of misalignments
9681 in powerpc alignment mode. */
9683 static void
9684 rs6000_darwin64_record_arg_advance_recurse (CUMULATIVE_ARGS *cum,
9685 const_tree type,
9686 HOST_WIDE_INT startbitpos)
9688 tree f;
9690 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
9691 if (TREE_CODE (f) == FIELD_DECL)
9693 HOST_WIDE_INT bitpos = startbitpos;
9694 tree ftype = TREE_TYPE (f);
9695 machine_mode mode;
9696 if (ftype == error_mark_node)
9697 continue;
9698 mode = TYPE_MODE (ftype);
9700 if (DECL_SIZE (f) != 0
9701 && tree_fits_uhwi_p (bit_position (f)))
9702 bitpos += int_bit_position (f);
9704 /* ??? FIXME: else assume zero offset. */
9706 if (TREE_CODE (ftype) == RECORD_TYPE)
9707 rs6000_darwin64_record_arg_advance_recurse (cum, ftype, bitpos);
9708 else if (USE_FP_FOR_ARG_P (cum, mode))
9710 unsigned n_fpregs = (GET_MODE_SIZE (mode) + 7) >> 3;
9711 rs6000_darwin64_record_arg_advance_flush (cum, bitpos, 0);
9712 cum->fregno += n_fpregs;
9713 /* Single-precision floats present a special problem for
9714 us, because they are smaller than an 8-byte GPR, and so
9715 the structure-packing rules combined with the standard
9716 varargs behavior mean that we want to pack float/float
9717 and float/int combinations into a single register's
9718 space. This is complicated by the arg advance flushing,
9719 which works on arbitrarily large groups of int-type
9720 fields. */
9721 if (mode == SFmode)
9723 if (cum->floats_in_gpr == 1)
9725 /* Two floats in a word; count the word and reset
9726 the float count. */
9727 cum->words++;
9728 cum->floats_in_gpr = 0;
9730 else if (bitpos % 64 == 0)
9732 /* A float at the beginning of an 8-byte word;
9733 count it and put off adjusting cum->words until
9734 we see if a arg advance flush is going to do it
9735 for us. */
9736 cum->floats_in_gpr++;
9738 else
9740 /* The float is at the end of a word, preceded
9741 by integer fields, so the arg advance flush
9742 just above has already set cum->words and
9743 everything is taken care of. */
9746 else
9747 cum->words += n_fpregs;
9749 else if (USE_ALTIVEC_FOR_ARG_P (cum, mode, 1))
9751 rs6000_darwin64_record_arg_advance_flush (cum, bitpos, 0);
9752 cum->vregno++;
9753 cum->words += 2;
9755 else if (cum->intoffset == -1)
9756 cum->intoffset = bitpos;
9760 /* Check for an item that needs to be considered specially under the darwin 64
9761 bit ABI. These are record types where the mode is BLK or the structure is
9762 8 bytes in size. */
9763 static int
9764 rs6000_darwin64_struct_check_p (machine_mode mode, const_tree type)
9766 return rs6000_darwin64_abi
9767 && ((mode == BLKmode
9768 && TREE_CODE (type) == RECORD_TYPE
9769 && int_size_in_bytes (type) > 0)
9770 || (type && TREE_CODE (type) == RECORD_TYPE
9771 && int_size_in_bytes (type) == 8)) ? 1 : 0;
9774 /* Update the data in CUM to advance over an argument
9775 of mode MODE and data type TYPE.
9776 (TYPE is null for libcalls where that information may not be available.)
9778 Note that for args passed by reference, function_arg will be called
9779 with MODE and TYPE set to that of the pointer to the arg, not the arg
9780 itself. */
9782 static void
9783 rs6000_function_arg_advance_1 (CUMULATIVE_ARGS *cum, machine_mode mode,
9784 const_tree type, bool named, int depth)
9786 machine_mode elt_mode;
9787 int n_elts;
9789 rs6000_discover_homogeneous_aggregate (mode, type, &elt_mode, &n_elts);
9791 /* Only tick off an argument if we're not recursing. */
9792 if (depth == 0)
9793 cum->nargs_prototype--;
9795 #ifdef HAVE_AS_GNU_ATTRIBUTE
9796 if (DEFAULT_ABI == ABI_V4
9797 && cum->escapes)
9799 if (SCALAR_FLOAT_MODE_P (mode))
9800 rs6000_passes_float = true;
9801 else if (named && ALTIVEC_OR_VSX_VECTOR_MODE (mode))
9802 rs6000_passes_vector = true;
9803 else if (SPE_VECTOR_MODE (mode)
9804 && !cum->stdarg
9805 && cum->sysv_gregno <= GP_ARG_MAX_REG)
9806 rs6000_passes_vector = true;
9808 #endif
9810 if (TARGET_ALTIVEC_ABI
9811 && (ALTIVEC_OR_VSX_VECTOR_MODE (elt_mode)
9812 || (type && TREE_CODE (type) == VECTOR_TYPE
9813 && int_size_in_bytes (type) == 16)))
9815 bool stack = false;
9817 if (USE_ALTIVEC_FOR_ARG_P (cum, elt_mode, named))
9819 cum->vregno += n_elts;
9821 if (!TARGET_ALTIVEC)
9822 error ("cannot pass argument in vector register because"
9823 " altivec instructions are disabled, use -maltivec"
9824 " to enable them");
9826 /* PowerPC64 Linux and AIX allocate GPRs for a vector argument
9827 even if it is going to be passed in a vector register.
9828 Darwin does the same for variable-argument functions. */
9829 if (((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
9830 && TARGET_64BIT)
9831 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
9832 stack = true;
9834 else
9835 stack = true;
9837 if (stack)
9839 int align;
9841 /* Vector parameters must be 16-byte aligned. In 32-bit
9842 mode this means we need to take into account the offset
9843 to the parameter save area. In 64-bit mode, they just
9844 have to start on an even word, since the parameter save
9845 area is 16-byte aligned. */
9846 if (TARGET_32BIT)
9847 align = -(rs6000_parm_offset () + cum->words) & 3;
9848 else
9849 align = cum->words & 1;
9850 cum->words += align + rs6000_arg_size (mode, type);
9852 if (TARGET_DEBUG_ARG)
9854 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
9855 cum->words, align);
9856 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
9857 cum->nargs_prototype, cum->prototype,
9858 GET_MODE_NAME (mode));
9862 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
9863 && !cum->stdarg
9864 && cum->sysv_gregno <= GP_ARG_MAX_REG)
9865 cum->sysv_gregno++;
9867 else if (TARGET_MACHO && rs6000_darwin64_struct_check_p (mode, type))
9869 int size = int_size_in_bytes (type);
9870 /* Variable sized types have size == -1 and are
9871 treated as if consisting entirely of ints.
9872 Pad to 16 byte boundary if needed. */
9873 if (TYPE_ALIGN (type) >= 2 * BITS_PER_WORD
9874 && (cum->words % 2) != 0)
9875 cum->words++;
9876 /* For varargs, we can just go up by the size of the struct. */
9877 if (!named)
9878 cum->words += (size + 7) / 8;
9879 else
9881 /* It is tempting to say int register count just goes up by
9882 sizeof(type)/8, but this is wrong in a case such as
9883 { int; double; int; } [powerpc alignment]. We have to
9884 grovel through the fields for these too. */
9885 cum->intoffset = 0;
9886 cum->floats_in_gpr = 0;
9887 rs6000_darwin64_record_arg_advance_recurse (cum, type, 0);
9888 rs6000_darwin64_record_arg_advance_flush (cum,
9889 size * BITS_PER_UNIT, 1);
9891 if (TARGET_DEBUG_ARG)
9893 fprintf (stderr, "function_adv: words = %2d, align=%d, size=%d",
9894 cum->words, TYPE_ALIGN (type), size);
9895 fprintf (stderr,
9896 "nargs = %4d, proto = %d, mode = %4s (darwin64 abi)\n",
9897 cum->nargs_prototype, cum->prototype,
9898 GET_MODE_NAME (mode));
9901 else if (DEFAULT_ABI == ABI_V4)
9903 if (TARGET_HARD_FLOAT && TARGET_FPRS
9904 && ((TARGET_SINGLE_FLOAT && mode == SFmode)
9905 || (TARGET_DOUBLE_FLOAT && mode == DFmode)
9906 || (mode == TFmode && !TARGET_IEEEQUAD)
9907 || mode == SDmode || mode == DDmode || mode == TDmode))
9909 /* _Decimal128 must use an even/odd register pair. This assumes
9910 that the register number is odd when fregno is odd. */
9911 if (mode == TDmode && (cum->fregno % 2) == 1)
9912 cum->fregno++;
9914 if (cum->fregno + (mode == TFmode || mode == TDmode ? 1 : 0)
9915 <= FP_ARG_V4_MAX_REG)
9916 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
9917 else
9919 cum->fregno = FP_ARG_V4_MAX_REG + 1;
9920 if (mode == DFmode || mode == TFmode
9921 || mode == DDmode || mode == TDmode)
9922 cum->words += cum->words & 1;
9923 cum->words += rs6000_arg_size (mode, type);
9926 else
9928 int n_words = rs6000_arg_size (mode, type);
9929 int gregno = cum->sysv_gregno;
9931 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
9932 (r7,r8) or (r9,r10). As does any other 2 word item such
9933 as complex int due to a historical mistake. */
9934 if (n_words == 2)
9935 gregno += (1 - gregno) & 1;
9937 /* Multi-reg args are not split between registers and stack. */
9938 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
9940 /* Long long and SPE vectors are aligned on the stack.
9941 So are other 2 word items such as complex int due to
9942 a historical mistake. */
9943 if (n_words == 2)
9944 cum->words += cum->words & 1;
9945 cum->words += n_words;
9948 /* Note: continuing to accumulate gregno past when we've started
9949 spilling to the stack indicates the fact that we've started
9950 spilling to the stack to expand_builtin_saveregs. */
9951 cum->sysv_gregno = gregno + n_words;
9954 if (TARGET_DEBUG_ARG)
9956 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
9957 cum->words, cum->fregno);
9958 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
9959 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
9960 fprintf (stderr, "mode = %4s, named = %d\n",
9961 GET_MODE_NAME (mode), named);
9964 else
9966 int n_words = rs6000_arg_size (mode, type);
9967 int start_words = cum->words;
9968 int align_words = rs6000_parm_start (mode, type, start_words);
9970 cum->words = align_words + n_words;
9972 if (SCALAR_FLOAT_MODE_P (elt_mode)
9973 && TARGET_HARD_FLOAT && TARGET_FPRS)
9975 /* _Decimal128 must be passed in an even/odd float register pair.
9976 This assumes that the register number is odd when fregno is
9977 odd. */
9978 if (elt_mode == TDmode && (cum->fregno % 2) == 1)
9979 cum->fregno++;
9980 cum->fregno += n_elts * ((GET_MODE_SIZE (elt_mode) + 7) >> 3);
9983 if (TARGET_DEBUG_ARG)
9985 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
9986 cum->words, cum->fregno);
9987 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
9988 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
9989 fprintf (stderr, "named = %d, align = %d, depth = %d\n",
9990 named, align_words - start_words, depth);
9995 static void
9996 rs6000_function_arg_advance (cumulative_args_t cum, machine_mode mode,
9997 const_tree type, bool named)
9999 rs6000_function_arg_advance_1 (get_cumulative_args (cum), mode, type, named,
10003 static rtx
10004 spe_build_register_parallel (machine_mode mode, int gregno)
10006 rtx r1, r3, r5, r7;
10008 switch (mode)
10010 case DFmode:
10011 r1 = gen_rtx_REG (DImode, gregno);
10012 r1 = gen_rtx_EXPR_LIST (VOIDmode, r1, const0_rtx);
10013 return gen_rtx_PARALLEL (mode, gen_rtvec (1, r1));
10015 case DCmode:
10016 case TFmode:
10017 r1 = gen_rtx_REG (DImode, gregno);
10018 r1 = gen_rtx_EXPR_LIST (VOIDmode, r1, const0_rtx);
10019 r3 = gen_rtx_REG (DImode, gregno + 2);
10020 r3 = gen_rtx_EXPR_LIST (VOIDmode, r3, GEN_INT (8));
10021 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r3));
10023 case TCmode:
10024 r1 = gen_rtx_REG (DImode, gregno);
10025 r1 = gen_rtx_EXPR_LIST (VOIDmode, r1, const0_rtx);
10026 r3 = gen_rtx_REG (DImode, gregno + 2);
10027 r3 = gen_rtx_EXPR_LIST (VOIDmode, r3, GEN_INT (8));
10028 r5 = gen_rtx_REG (DImode, gregno + 4);
10029 r5 = gen_rtx_EXPR_LIST (VOIDmode, r5, GEN_INT (16));
10030 r7 = gen_rtx_REG (DImode, gregno + 6);
10031 r7 = gen_rtx_EXPR_LIST (VOIDmode, r7, GEN_INT (24));
10032 return gen_rtx_PARALLEL (mode, gen_rtvec (4, r1, r3, r5, r7));
10034 default:
10035 gcc_unreachable ();
10039 /* Determine where to put a SIMD argument on the SPE. */
10040 static rtx
10041 rs6000_spe_function_arg (const CUMULATIVE_ARGS *cum, machine_mode mode,
10042 const_tree type)
10044 int gregno = cum->sysv_gregno;
10046 /* On E500 v2, double arithmetic is done on the full 64-bit GPR, but
10047 are passed and returned in a pair of GPRs for ABI compatibility. */
10048 if (TARGET_E500_DOUBLE && (mode == DFmode || mode == TFmode
10049 || mode == DCmode || mode == TCmode))
10051 int n_words = rs6000_arg_size (mode, type);
10053 /* Doubles go in an odd/even register pair (r5/r6, etc). */
10054 if (mode == DFmode)
10055 gregno += (1 - gregno) & 1;
10057 /* Multi-reg args are not split between registers and stack. */
10058 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
10059 return NULL_RTX;
10061 return spe_build_register_parallel (mode, gregno);
10063 if (cum->stdarg)
10065 int n_words = rs6000_arg_size (mode, type);
10067 /* SPE vectors are put in odd registers. */
10068 if (n_words == 2 && (gregno & 1) == 0)
10069 gregno += 1;
10071 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
10073 rtx r1, r2;
10074 machine_mode m = SImode;
10076 r1 = gen_rtx_REG (m, gregno);
10077 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
10078 r2 = gen_rtx_REG (m, gregno + 1);
10079 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
10080 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
10082 else
10083 return NULL_RTX;
10085 else
10087 if (gregno <= GP_ARG_MAX_REG)
10088 return gen_rtx_REG (mode, gregno);
10089 else
10090 return NULL_RTX;
10094 /* A subroutine of rs6000_darwin64_record_arg. Assign the bits of the
10095 structure between cum->intoffset and bitpos to integer registers. */
10097 static void
10098 rs6000_darwin64_record_arg_flush (CUMULATIVE_ARGS *cum,
10099 HOST_WIDE_INT bitpos, rtx rvec[], int *k)
10101 machine_mode mode;
10102 unsigned int regno;
10103 unsigned int startbit, endbit;
10104 int this_regno, intregs, intoffset;
10105 rtx reg;
10107 if (cum->intoffset == -1)
10108 return;
10110 intoffset = cum->intoffset;
10111 cum->intoffset = -1;
10113 /* If this is the trailing part of a word, try to only load that
10114 much into the register. Otherwise load the whole register. Note
10115 that in the latter case we may pick up unwanted bits. It's not a
10116 problem at the moment but may wish to revisit. */
10118 if (intoffset % BITS_PER_WORD != 0)
10120 mode = mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD,
10121 MODE_INT, 0);
10122 if (mode == BLKmode)
10124 /* We couldn't find an appropriate mode, which happens,
10125 e.g., in packed structs when there are 3 bytes to load.
10126 Back intoffset back to the beginning of the word in this
10127 case. */
10128 intoffset = intoffset & -BITS_PER_WORD;
10129 mode = word_mode;
10132 else
10133 mode = word_mode;
10135 startbit = intoffset & -BITS_PER_WORD;
10136 endbit = (bitpos + BITS_PER_WORD - 1) & -BITS_PER_WORD;
10137 intregs = (endbit - startbit) / BITS_PER_WORD;
10138 this_regno = cum->words + intoffset / BITS_PER_WORD;
10140 if (intregs > 0 && intregs > GP_ARG_NUM_REG - this_regno)
10141 cum->use_stack = 1;
10143 intregs = MIN (intregs, GP_ARG_NUM_REG - this_regno);
10144 if (intregs <= 0)
10145 return;
10147 intoffset /= BITS_PER_UNIT;
10150 regno = GP_ARG_MIN_REG + this_regno;
10151 reg = gen_rtx_REG (mode, regno);
10152 rvec[(*k)++] =
10153 gen_rtx_EXPR_LIST (VOIDmode, reg, GEN_INT (intoffset));
10155 this_regno += 1;
10156 intoffset = (intoffset | (UNITS_PER_WORD-1)) + 1;
10157 mode = word_mode;
10158 intregs -= 1;
10160 while (intregs > 0);
10163 /* Recursive workhorse for the following. */
10165 static void
10166 rs6000_darwin64_record_arg_recurse (CUMULATIVE_ARGS *cum, const_tree type,
10167 HOST_WIDE_INT startbitpos, rtx rvec[],
10168 int *k)
10170 tree f;
10172 for (f = TYPE_FIELDS (type); f ; f = DECL_CHAIN (f))
10173 if (TREE_CODE (f) == FIELD_DECL)
10175 HOST_WIDE_INT bitpos = startbitpos;
10176 tree ftype = TREE_TYPE (f);
10177 machine_mode mode;
10178 if (ftype == error_mark_node)
10179 continue;
10180 mode = TYPE_MODE (ftype);
10182 if (DECL_SIZE (f) != 0
10183 && tree_fits_uhwi_p (bit_position (f)))
10184 bitpos += int_bit_position (f);
10186 /* ??? FIXME: else assume zero offset. */
10188 if (TREE_CODE (ftype) == RECORD_TYPE)
10189 rs6000_darwin64_record_arg_recurse (cum, ftype, bitpos, rvec, k);
10190 else if (cum->named && USE_FP_FOR_ARG_P (cum, mode))
10192 unsigned n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
10193 #if 0
10194 switch (mode)
10196 case SCmode: mode = SFmode; break;
10197 case DCmode: mode = DFmode; break;
10198 case TCmode: mode = TFmode; break;
10199 default: break;
10201 #endif
10202 rs6000_darwin64_record_arg_flush (cum, bitpos, rvec, k);
10203 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
10205 gcc_assert (cum->fregno == FP_ARG_MAX_REG
10206 && (mode == TFmode || mode == TDmode));
10207 /* Long double or _Decimal128 split over regs and memory. */
10208 mode = DECIMAL_FLOAT_MODE_P (mode) ? DDmode : DFmode;
10209 cum->use_stack=1;
10211 rvec[(*k)++]
10212 = gen_rtx_EXPR_LIST (VOIDmode,
10213 gen_rtx_REG (mode, cum->fregno++),
10214 GEN_INT (bitpos / BITS_PER_UNIT));
10215 if (mode == TFmode || mode == TDmode)
10216 cum->fregno++;
10218 else if (cum->named && USE_ALTIVEC_FOR_ARG_P (cum, mode, 1))
10220 rs6000_darwin64_record_arg_flush (cum, bitpos, rvec, k);
10221 rvec[(*k)++]
10222 = gen_rtx_EXPR_LIST (VOIDmode,
10223 gen_rtx_REG (mode, cum->vregno++),
10224 GEN_INT (bitpos / BITS_PER_UNIT));
10226 else if (cum->intoffset == -1)
10227 cum->intoffset = bitpos;
10231 /* For the darwin64 ABI, we want to construct a PARALLEL consisting of
10232 the register(s) to be used for each field and subfield of a struct
10233 being passed by value, along with the offset of where the
10234 register's value may be found in the block. FP fields go in FP
10235 register, vector fields go in vector registers, and everything
10236 else goes in int registers, packed as in memory.
10238 This code is also used for function return values. RETVAL indicates
10239 whether this is the case.
10241 Much of this is taken from the SPARC V9 port, which has a similar
10242 calling convention. */
10244 static rtx
10245 rs6000_darwin64_record_arg (CUMULATIVE_ARGS *orig_cum, const_tree type,
10246 bool named, bool retval)
10248 rtx rvec[FIRST_PSEUDO_REGISTER];
10249 int k = 1, kbase = 1;
10250 HOST_WIDE_INT typesize = int_size_in_bytes (type);
10251 /* This is a copy; modifications are not visible to our caller. */
10252 CUMULATIVE_ARGS copy_cum = *orig_cum;
10253 CUMULATIVE_ARGS *cum = &copy_cum;
10255 /* Pad to 16 byte boundary if needed. */
10256 if (!retval && TYPE_ALIGN (type) >= 2 * BITS_PER_WORD
10257 && (cum->words % 2) != 0)
10258 cum->words++;
10260 cum->intoffset = 0;
10261 cum->use_stack = 0;
10262 cum->named = named;
10264 /* Put entries into rvec[] for individual FP and vector fields, and
10265 for the chunks of memory that go in int regs. Note we start at
10266 element 1; 0 is reserved for an indication of using memory, and
10267 may or may not be filled in below. */
10268 rs6000_darwin64_record_arg_recurse (cum, type, /* startbit pos= */ 0, rvec, &k);
10269 rs6000_darwin64_record_arg_flush (cum, typesize * BITS_PER_UNIT, rvec, &k);
10271 /* If any part of the struct went on the stack put all of it there.
10272 This hack is because the generic code for
10273 FUNCTION_ARG_PARTIAL_NREGS cannot handle cases where the register
10274 parts of the struct are not at the beginning. */
10275 if (cum->use_stack)
10277 if (retval)
10278 return NULL_RTX; /* doesn't go in registers at all */
10279 kbase = 0;
10280 rvec[0] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
10282 if (k > 1 || cum->use_stack)
10283 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (k - kbase, &rvec[kbase]));
10284 else
10285 return NULL_RTX;
10288 /* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
10290 static rtx
10291 rs6000_mixed_function_arg (machine_mode mode, const_tree type,
10292 int align_words)
10294 int n_units;
10295 int i, k;
10296 rtx rvec[GP_ARG_NUM_REG + 1];
10298 if (align_words >= GP_ARG_NUM_REG)
10299 return NULL_RTX;
10301 n_units = rs6000_arg_size (mode, type);
10303 /* Optimize the simple case where the arg fits in one gpr, except in
10304 the case of BLKmode due to assign_parms assuming that registers are
10305 BITS_PER_WORD wide. */
10306 if (n_units == 0
10307 || (n_units == 1 && mode != BLKmode))
10308 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
10310 k = 0;
10311 if (align_words + n_units > GP_ARG_NUM_REG)
10312 /* Not all of the arg fits in gprs. Say that it goes in memory too,
10313 using a magic NULL_RTX component.
10314 This is not strictly correct. Only some of the arg belongs in
10315 memory, not all of it. However, the normal scheme using
10316 function_arg_partial_nregs can result in unusual subregs, eg.
10317 (subreg:SI (reg:DF) 4), which are not handled well. The code to
10318 store the whole arg to memory is often more efficient than code
10319 to store pieces, and we know that space is available in the right
10320 place for the whole arg. */
10321 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
10323 i = 0;
10326 rtx r = gen_rtx_REG (SImode, GP_ARG_MIN_REG + align_words);
10327 rtx off = GEN_INT (i++ * 4);
10328 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
10330 while (++align_words < GP_ARG_NUM_REG && --n_units != 0);
10332 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
10335 /* We have an argument of MODE and TYPE that goes into FPRs or VRs,
10336 but must also be copied into the parameter save area starting at
10337 offset ALIGN_WORDS. Fill in RVEC with the elements corresponding
10338 to the GPRs and/or memory. Return the number of elements used. */
10340 static int
10341 rs6000_psave_function_arg (machine_mode mode, const_tree type,
10342 int align_words, rtx *rvec)
10344 int k = 0;
10346 if (align_words < GP_ARG_NUM_REG)
10348 int n_words = rs6000_arg_size (mode, type);
10350 if (align_words + n_words > GP_ARG_NUM_REG
10351 || mode == BLKmode
10352 || (TARGET_32BIT && TARGET_POWERPC64))
10354 /* If this is partially on the stack, then we only
10355 include the portion actually in registers here. */
10356 machine_mode rmode = TARGET_32BIT ? SImode : DImode;
10357 int i = 0;
10359 if (align_words + n_words > GP_ARG_NUM_REG)
10361 /* Not all of the arg fits in gprs. Say that it goes in memory
10362 too, using a magic NULL_RTX component. Also see comment in
10363 rs6000_mixed_function_arg for why the normal
10364 function_arg_partial_nregs scheme doesn't work in this case. */
10365 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
10370 rtx r = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words);
10371 rtx off = GEN_INT (i++ * GET_MODE_SIZE (rmode));
10372 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
10374 while (++align_words < GP_ARG_NUM_REG && --n_words != 0);
10376 else
10378 /* The whole arg fits in gprs. */
10379 rtx r = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
10380 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
10383 else
10385 /* It's entirely in memory. */
10386 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
10389 return k;
10392 /* RVEC is a vector of K components of an argument of mode MODE.
10393 Construct the final function_arg return value from it. */
10395 static rtx
10396 rs6000_finish_function_arg (machine_mode mode, rtx *rvec, int k)
10398 gcc_assert (k >= 1);
10400 /* Avoid returning a PARALLEL in the trivial cases. */
10401 if (k == 1)
10403 if (XEXP (rvec[0], 0) == NULL_RTX)
10404 return NULL_RTX;
10406 if (GET_MODE (XEXP (rvec[0], 0)) == mode)
10407 return XEXP (rvec[0], 0);
10410 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
10413 /* Determine where to put an argument to a function.
10414 Value is zero to push the argument on the stack,
10415 or a hard register in which to store the argument.
10417 MODE is the argument's machine mode.
10418 TYPE is the data type of the argument (as a tree).
10419 This is null for libcalls where that information may
10420 not be available.
10421 CUM is a variable of type CUMULATIVE_ARGS which gives info about
10422 the preceding args and about the function being called. It is
10423 not modified in this routine.
10424 NAMED is nonzero if this argument is a named parameter
10425 (otherwise it is an extra parameter matching an ellipsis).
10427 On RS/6000 the first eight words of non-FP are normally in registers
10428 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
10429 Under V.4, the first 8 FP args are in registers.
10431 If this is floating-point and no prototype is specified, we use
10432 both an FP and integer register (or possibly FP reg and stack). Library
10433 functions (when CALL_LIBCALL is set) always have the proper types for args,
10434 so we can pass the FP value just in one register. emit_library_function
10435 doesn't support PARALLEL anyway.
10437 Note that for args passed by reference, function_arg will be called
10438 with MODE and TYPE set to that of the pointer to the arg, not the arg
10439 itself. */
10441 static rtx
10442 rs6000_function_arg (cumulative_args_t cum_v, machine_mode mode,
10443 const_tree type, bool named)
10445 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
10446 enum rs6000_abi abi = DEFAULT_ABI;
10447 machine_mode elt_mode;
10448 int n_elts;
10450 /* Return a marker to indicate whether CR1 needs to set or clear the
10451 bit that V.4 uses to say fp args were passed in registers.
10452 Assume that we don't need the marker for software floating point,
10453 or compiler generated library calls. */
10454 if (mode == VOIDmode)
10456 if (abi == ABI_V4
10457 && (cum->call_cookie & CALL_LIBCALL) == 0
10458 && (cum->stdarg
10459 || (cum->nargs_prototype < 0
10460 && (cum->prototype || TARGET_NO_PROTOTYPE))))
10462 /* For the SPE, we need to crxor CR6 always. */
10463 if (TARGET_SPE_ABI)
10464 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
10465 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
10466 return GEN_INT (cum->call_cookie
10467 | ((cum->fregno == FP_ARG_MIN_REG)
10468 ? CALL_V4_SET_FP_ARGS
10469 : CALL_V4_CLEAR_FP_ARGS));
10472 return GEN_INT (cum->call_cookie & ~CALL_LIBCALL);
10475 rs6000_discover_homogeneous_aggregate (mode, type, &elt_mode, &n_elts);
10477 if (TARGET_MACHO && rs6000_darwin64_struct_check_p (mode, type))
10479 rtx rslt = rs6000_darwin64_record_arg (cum, type, named, /*retval= */false);
10480 if (rslt != NULL_RTX)
10481 return rslt;
10482 /* Else fall through to usual handling. */
10485 if (USE_ALTIVEC_FOR_ARG_P (cum, elt_mode, named))
10487 rtx rvec[GP_ARG_NUM_REG + AGGR_ARG_NUM_REG + 1];
10488 rtx r, off;
10489 int i, k = 0;
10491 /* Do we also need to pass this argument in the parameter
10492 save area? */
10493 if (TARGET_64BIT && ! cum->prototype)
10495 int align_words = (cum->words + 1) & ~1;
10496 k = rs6000_psave_function_arg (mode, type, align_words, rvec);
10499 /* Describe where this argument goes in the vector registers. */
10500 for (i = 0; i < n_elts && cum->vregno + i <= ALTIVEC_ARG_MAX_REG; i++)
10502 r = gen_rtx_REG (elt_mode, cum->vregno + i);
10503 off = GEN_INT (i * GET_MODE_SIZE (elt_mode));
10504 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
10507 return rs6000_finish_function_arg (mode, rvec, k);
10509 else if (TARGET_ALTIVEC_ABI
10510 && (ALTIVEC_OR_VSX_VECTOR_MODE (mode)
10511 || (type && TREE_CODE (type) == VECTOR_TYPE
10512 && int_size_in_bytes (type) == 16)))
10514 if (named || abi == ABI_V4)
10515 return NULL_RTX;
10516 else
10518 /* Vector parameters to varargs functions under AIX or Darwin
10519 get passed in memory and possibly also in GPRs. */
10520 int align, align_words, n_words;
10521 machine_mode part_mode;
10523 /* Vector parameters must be 16-byte aligned. In 32-bit
10524 mode this means we need to take into account the offset
10525 to the parameter save area. In 64-bit mode, they just
10526 have to start on an even word, since the parameter save
10527 area is 16-byte aligned. */
10528 if (TARGET_32BIT)
10529 align = -(rs6000_parm_offset () + cum->words) & 3;
10530 else
10531 align = cum->words & 1;
10532 align_words = cum->words + align;
10534 /* Out of registers? Memory, then. */
10535 if (align_words >= GP_ARG_NUM_REG)
10536 return NULL_RTX;
10538 if (TARGET_32BIT && TARGET_POWERPC64)
10539 return rs6000_mixed_function_arg (mode, type, align_words);
10541 /* The vector value goes in GPRs. Only the part of the
10542 value in GPRs is reported here. */
10543 part_mode = mode;
10544 n_words = rs6000_arg_size (mode, type);
10545 if (align_words + n_words > GP_ARG_NUM_REG)
10546 /* Fortunately, there are only two possibilities, the value
10547 is either wholly in GPRs or half in GPRs and half not. */
10548 part_mode = DImode;
10550 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
10553 else if (TARGET_SPE_ABI && TARGET_SPE
10554 && (SPE_VECTOR_MODE (mode)
10555 || (TARGET_E500_DOUBLE && (mode == DFmode
10556 || mode == DCmode
10557 || mode == TFmode
10558 || mode == TCmode))))
10559 return rs6000_spe_function_arg (cum, mode, type);
10561 else if (abi == ABI_V4)
10563 if (TARGET_HARD_FLOAT && TARGET_FPRS
10564 && ((TARGET_SINGLE_FLOAT && mode == SFmode)
10565 || (TARGET_DOUBLE_FLOAT && mode == DFmode)
10566 || (mode == TFmode && !TARGET_IEEEQUAD)
10567 || mode == SDmode || mode == DDmode || mode == TDmode))
10569 /* _Decimal128 must use an even/odd register pair. This assumes
10570 that the register number is odd when fregno is odd. */
10571 if (mode == TDmode && (cum->fregno % 2) == 1)
10572 cum->fregno++;
10574 if (cum->fregno + (mode == TFmode || mode == TDmode ? 1 : 0)
10575 <= FP_ARG_V4_MAX_REG)
10576 return gen_rtx_REG (mode, cum->fregno);
10577 else
10578 return NULL_RTX;
10580 else
10582 int n_words = rs6000_arg_size (mode, type);
10583 int gregno = cum->sysv_gregno;
10585 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
10586 (r7,r8) or (r9,r10). As does any other 2 word item such
10587 as complex int due to a historical mistake. */
10588 if (n_words == 2)
10589 gregno += (1 - gregno) & 1;
10591 /* Multi-reg args are not split between registers and stack. */
10592 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
10593 return NULL_RTX;
10595 if (TARGET_32BIT && TARGET_POWERPC64)
10596 return rs6000_mixed_function_arg (mode, type,
10597 gregno - GP_ARG_MIN_REG);
10598 return gen_rtx_REG (mode, gregno);
10601 else
10603 int align_words = rs6000_parm_start (mode, type, cum->words);
10605 /* _Decimal128 must be passed in an even/odd float register pair.
10606 This assumes that the register number is odd when fregno is odd. */
10607 if (elt_mode == TDmode && (cum->fregno % 2) == 1)
10608 cum->fregno++;
10610 if (USE_FP_FOR_ARG_P (cum, elt_mode))
10612 rtx rvec[GP_ARG_NUM_REG + AGGR_ARG_NUM_REG + 1];
10613 rtx r, off;
10614 int i, k = 0;
10615 unsigned long n_fpreg = (GET_MODE_SIZE (elt_mode) + 7) >> 3;
10616 int fpr_words;
10618 /* Do we also need to pass this argument in the parameter
10619 save area? */
10620 if (type && (cum->nargs_prototype <= 0
10621 || ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
10622 && TARGET_XL_COMPAT
10623 && align_words >= GP_ARG_NUM_REG)))
10624 k = rs6000_psave_function_arg (mode, type, align_words, rvec);
10626 /* Describe where this argument goes in the fprs. */
10627 for (i = 0; i < n_elts
10628 && cum->fregno + i * n_fpreg <= FP_ARG_MAX_REG; i++)
10630 /* Check if the argument is split over registers and memory.
10631 This can only ever happen for long double or _Decimal128;
10632 complex types are handled via split_complex_arg. */
10633 machine_mode fmode = elt_mode;
10634 if (cum->fregno + (i + 1) * n_fpreg > FP_ARG_MAX_REG + 1)
10636 gcc_assert (fmode == TFmode || fmode == TDmode);
10637 fmode = DECIMAL_FLOAT_MODE_P (fmode) ? DDmode : DFmode;
10640 r = gen_rtx_REG (fmode, cum->fregno + i * n_fpreg);
10641 off = GEN_INT (i * GET_MODE_SIZE (elt_mode));
10642 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
10645 /* If there were not enough FPRs to hold the argument, the rest
10646 usually goes into memory. However, if the current position
10647 is still within the register parameter area, a portion may
10648 actually have to go into GPRs.
10650 Note that it may happen that the portion of the argument
10651 passed in the first "half" of the first GPR was already
10652 passed in the last FPR as well.
10654 For unnamed arguments, we already set up GPRs to cover the
10655 whole argument in rs6000_psave_function_arg, so there is
10656 nothing further to do at this point. */
10657 fpr_words = (i * GET_MODE_SIZE (elt_mode)) / (TARGET_32BIT ? 4 : 8);
10658 if (i < n_elts && align_words + fpr_words < GP_ARG_NUM_REG
10659 && cum->nargs_prototype > 0)
10661 static bool warned;
10663 machine_mode rmode = TARGET_32BIT ? SImode : DImode;
10664 int n_words = rs6000_arg_size (mode, type);
10666 align_words += fpr_words;
10667 n_words -= fpr_words;
10671 r = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words);
10672 off = GEN_INT (fpr_words++ * GET_MODE_SIZE (rmode));
10673 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
10675 while (++align_words < GP_ARG_NUM_REG && --n_words != 0);
10677 if (!warned && warn_psabi)
10679 warned = true;
10680 inform (input_location,
10681 "the ABI of passing homogeneous float aggregates"
10682 " has changed in GCC 5");
10686 return rs6000_finish_function_arg (mode, rvec, k);
10688 else if (align_words < GP_ARG_NUM_REG)
10690 if (TARGET_32BIT && TARGET_POWERPC64)
10691 return rs6000_mixed_function_arg (mode, type, align_words);
10693 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
10695 else
10696 return NULL_RTX;
10700 /* For an arg passed partly in registers and partly in memory, this is
10701 the number of bytes passed in registers. For args passed entirely in
10702 registers or entirely in memory, zero. When an arg is described by a
10703 PARALLEL, perhaps using more than one register type, this function
10704 returns the number of bytes used by the first element of the PARALLEL. */
10706 static int
10707 rs6000_arg_partial_bytes (cumulative_args_t cum_v, machine_mode mode,
10708 tree type, bool named)
10710 CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
10711 bool passed_in_gprs = true;
10712 int ret = 0;
10713 int align_words;
10714 machine_mode elt_mode;
10715 int n_elts;
10717 rs6000_discover_homogeneous_aggregate (mode, type, &elt_mode, &n_elts);
10719 if (DEFAULT_ABI == ABI_V4)
10720 return 0;
10722 if (USE_ALTIVEC_FOR_ARG_P (cum, elt_mode, named))
10724 /* If we are passing this arg in the fixed parameter save area
10725 (gprs or memory) as well as VRs, we do not use the partial
10726 bytes mechanism; instead, rs6000_function_arg will return a
10727 PARALLEL including a memory element as necessary. */
10728 if (TARGET_64BIT && ! cum->prototype)
10729 return 0;
10731 /* Otherwise, we pass in VRs only. Check for partial copies. */
10732 passed_in_gprs = false;
10733 if (cum->vregno + n_elts > ALTIVEC_ARG_MAX_REG + 1)
10734 ret = (ALTIVEC_ARG_MAX_REG + 1 - cum->vregno) * 16;
10737 /* In this complicated case we just disable the partial_nregs code. */
10738 if (TARGET_MACHO && rs6000_darwin64_struct_check_p (mode, type))
10739 return 0;
10741 align_words = rs6000_parm_start (mode, type, cum->words);
10743 if (USE_FP_FOR_ARG_P (cum, elt_mode))
10745 unsigned long n_fpreg = (GET_MODE_SIZE (elt_mode) + 7) >> 3;
10747 /* If we are passing this arg in the fixed parameter save area
10748 (gprs or memory) as well as FPRs, we do not use the partial
10749 bytes mechanism; instead, rs6000_function_arg will return a
10750 PARALLEL including a memory element as necessary. */
10751 if (type
10752 && (cum->nargs_prototype <= 0
10753 || ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
10754 && TARGET_XL_COMPAT
10755 && align_words >= GP_ARG_NUM_REG)))
10756 return 0;
10758 /* Otherwise, we pass in FPRs only. Check for partial copies. */
10759 passed_in_gprs = false;
10760 if (cum->fregno + n_elts * n_fpreg > FP_ARG_MAX_REG + 1)
10762 /* Compute number of bytes / words passed in FPRs. If there
10763 is still space available in the register parameter area
10764 *after* that amount, a part of the argument will be passed
10765 in GPRs. In that case, the total amount passed in any
10766 registers is equal to the amount that would have been passed
10767 in GPRs if everything were passed there, so we fall back to
10768 the GPR code below to compute the appropriate value. */
10769 int fpr = ((FP_ARG_MAX_REG + 1 - cum->fregno)
10770 * MIN (8, GET_MODE_SIZE (elt_mode)));
10771 int fpr_words = fpr / (TARGET_32BIT ? 4 : 8);
10773 if (align_words + fpr_words < GP_ARG_NUM_REG)
10774 passed_in_gprs = true;
10775 else
10776 ret = fpr;
10780 if (passed_in_gprs
10781 && align_words < GP_ARG_NUM_REG
10782 && GP_ARG_NUM_REG < align_words + rs6000_arg_size (mode, type))
10783 ret = (GP_ARG_NUM_REG - align_words) * (TARGET_32BIT ? 4 : 8);
10785 if (ret != 0 && TARGET_DEBUG_ARG)
10786 fprintf (stderr, "rs6000_arg_partial_bytes: %d\n", ret);
10788 return ret;
10791 /* A C expression that indicates when an argument must be passed by
10792 reference. If nonzero for an argument, a copy of that argument is
10793 made in memory and a pointer to the argument is passed instead of
10794 the argument itself. The pointer is passed in whatever way is
10795 appropriate for passing a pointer to that type.
10797 Under V.4, aggregates and long double are passed by reference.
10799 As an extension to all 32-bit ABIs, AltiVec vectors are passed by
10800 reference unless the AltiVec vector extension ABI is in force.
10802 As an extension to all ABIs, variable sized types are passed by
10803 reference. */
10805 static bool
10806 rs6000_pass_by_reference (cumulative_args_t cum ATTRIBUTE_UNUSED,
10807 machine_mode mode, const_tree type,
10808 bool named ATTRIBUTE_UNUSED)
10810 if (DEFAULT_ABI == ABI_V4 && TARGET_IEEEQUAD && mode == TFmode)
10812 if (TARGET_DEBUG_ARG)
10813 fprintf (stderr, "function_arg_pass_by_reference: V4 long double\n");
10814 return 1;
10817 if (!type)
10818 return 0;
10820 if (DEFAULT_ABI == ABI_V4 && AGGREGATE_TYPE_P (type))
10822 if (TARGET_DEBUG_ARG)
10823 fprintf (stderr, "function_arg_pass_by_reference: V4 aggregate\n");
10824 return 1;
10827 if (int_size_in_bytes (type) < 0)
10829 if (TARGET_DEBUG_ARG)
10830 fprintf (stderr, "function_arg_pass_by_reference: variable size\n");
10831 return 1;
10834 /* Allow -maltivec -mabi=no-altivec without warning. Altivec vector
10835 modes only exist for GCC vector types if -maltivec. */
10836 if (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
10838 if (TARGET_DEBUG_ARG)
10839 fprintf (stderr, "function_arg_pass_by_reference: AltiVec\n");
10840 return 1;
10843 /* Pass synthetic vectors in memory. */
10844 if (TREE_CODE (type) == VECTOR_TYPE
10845 && int_size_in_bytes (type) > (TARGET_ALTIVEC_ABI ? 16 : 8))
10847 static bool warned_for_pass_big_vectors = false;
10848 if (TARGET_DEBUG_ARG)
10849 fprintf (stderr, "function_arg_pass_by_reference: synthetic vector\n");
10850 if (!warned_for_pass_big_vectors)
10852 warning (0, "GCC vector passed by reference: "
10853 "non-standard ABI extension with no compatibility guarantee");
10854 warned_for_pass_big_vectors = true;
10856 return 1;
10859 return 0;
10862 /* Process parameter of type TYPE after ARGS_SO_FAR parameters were
10863 already processes. Return true if the parameter must be passed
10864 (fully or partially) on the stack. */
10866 static bool
10867 rs6000_parm_needs_stack (cumulative_args_t args_so_far, tree type)
10869 machine_mode mode;
10870 int unsignedp;
10871 rtx entry_parm;
10873 /* Catch errors. */
10874 if (type == NULL || type == error_mark_node)
10875 return true;
10877 /* Handle types with no storage requirement. */
10878 if (TYPE_MODE (type) == VOIDmode)
10879 return false;
10881 /* Handle complex types. */
10882 if (TREE_CODE (type) == COMPLEX_TYPE)
10883 return (rs6000_parm_needs_stack (args_so_far, TREE_TYPE (type))
10884 || rs6000_parm_needs_stack (args_so_far, TREE_TYPE (type)));
10886 /* Handle transparent aggregates. */
10887 if ((TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == RECORD_TYPE)
10888 && TYPE_TRANSPARENT_AGGR (type))
10889 type = TREE_TYPE (first_field (type));
10891 /* See if this arg was passed by invisible reference. */
10892 if (pass_by_reference (get_cumulative_args (args_so_far),
10893 TYPE_MODE (type), type, true))
10894 type = build_pointer_type (type);
10896 /* Find mode as it is passed by the ABI. */
10897 unsignedp = TYPE_UNSIGNED (type);
10898 mode = promote_mode (type, TYPE_MODE (type), &unsignedp);
10900 /* If we must pass in stack, we need a stack. */
10901 if (rs6000_must_pass_in_stack (mode, type))
10902 return true;
10904 /* If there is no incoming register, we need a stack. */
10905 entry_parm = rs6000_function_arg (args_so_far, mode, type, true);
10906 if (entry_parm == NULL)
10907 return true;
10909 /* Likewise if we need to pass both in registers and on the stack. */
10910 if (GET_CODE (entry_parm) == PARALLEL
10911 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX)
10912 return true;
10914 /* Also true if we're partially in registers and partially not. */
10915 if (rs6000_arg_partial_bytes (args_so_far, mode, type, true) != 0)
10916 return true;
10918 /* Update info on where next arg arrives in registers. */
10919 rs6000_function_arg_advance (args_so_far, mode, type, true);
10920 return false;
10923 /* Return true if FUN has no prototype, has a variable argument
10924 list, or passes any parameter in memory. */
10926 static bool
10927 rs6000_function_parms_need_stack (tree fun, bool incoming)
10929 tree fntype, result;
10930 CUMULATIVE_ARGS args_so_far_v;
10931 cumulative_args_t args_so_far;
10933 if (!fun)
10934 /* Must be a libcall, all of which only use reg parms. */
10935 return false;
10937 fntype = fun;
10938 if (!TYPE_P (fun))
10939 fntype = TREE_TYPE (fun);
10941 /* Varargs functions need the parameter save area. */
10942 if ((!incoming && !prototype_p (fntype)) || stdarg_p (fntype))
10943 return true;
10945 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far_v, fntype, NULL_RTX);
10946 args_so_far = pack_cumulative_args (&args_so_far_v);
10948 /* When incoming, we will have been passed the function decl.
10949 It is necessary to use the decl to handle K&R style functions,
10950 where TYPE_ARG_TYPES may not be available. */
10951 if (incoming)
10953 gcc_assert (DECL_P (fun));
10954 result = DECL_RESULT (fun);
10956 else
10957 result = TREE_TYPE (fntype);
10959 if (result && aggregate_value_p (result, fntype))
10961 if (!TYPE_P (result))
10962 result = TREE_TYPE (result);
10963 result = build_pointer_type (result);
10964 rs6000_parm_needs_stack (args_so_far, result);
10967 if (incoming)
10969 tree parm;
10971 for (parm = DECL_ARGUMENTS (fun);
10972 parm && parm != void_list_node;
10973 parm = TREE_CHAIN (parm))
10974 if (rs6000_parm_needs_stack (args_so_far, TREE_TYPE (parm)))
10975 return true;
10977 else
10979 function_args_iterator args_iter;
10980 tree arg_type;
10982 FOREACH_FUNCTION_ARGS (fntype, arg_type, args_iter)
10983 if (rs6000_parm_needs_stack (args_so_far, arg_type))
10984 return true;
10987 return false;
10990 /* Return the size of the REG_PARM_STACK_SPACE are for FUN. This is
10991 usually a constant depending on the ABI. However, in the ELFv2 ABI
10992 the register parameter area is optional when calling a function that
10993 has a prototype is scope, has no variable argument list, and passes
10994 all parameters in registers. */
10997 rs6000_reg_parm_stack_space (tree fun, bool incoming)
10999 int reg_parm_stack_space;
11001 switch (DEFAULT_ABI)
11003 default:
11004 reg_parm_stack_space = 0;
11005 break;
11007 case ABI_AIX:
11008 case ABI_DARWIN:
11009 reg_parm_stack_space = TARGET_64BIT ? 64 : 32;
11010 break;
11012 case ABI_ELFv2:
11013 /* ??? Recomputing this every time is a bit expensive. Is there
11014 a place to cache this information? */
11015 if (rs6000_function_parms_need_stack (fun, incoming))
11016 reg_parm_stack_space = TARGET_64BIT ? 64 : 32;
11017 else
11018 reg_parm_stack_space = 0;
11019 break;
11022 return reg_parm_stack_space;
11025 static void
11026 rs6000_move_block_from_reg (int regno, rtx x, int nregs)
11028 int i;
11029 machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
11031 if (nregs == 0)
11032 return;
11034 for (i = 0; i < nregs; i++)
11036 rtx tem = adjust_address_nv (x, reg_mode, i * GET_MODE_SIZE (reg_mode));
11037 if (reload_completed)
11039 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
11040 tem = NULL_RTX;
11041 else
11042 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
11043 i * GET_MODE_SIZE (reg_mode));
11045 else
11046 tem = replace_equiv_address (tem, XEXP (tem, 0));
11048 gcc_assert (tem);
11050 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
11054 /* Perform any needed actions needed for a function that is receiving a
11055 variable number of arguments.
11057 CUM is as above.
11059 MODE and TYPE are the mode and type of the current parameter.
11061 PRETEND_SIZE is a variable that should be set to the amount of stack
11062 that must be pushed by the prolog to pretend that our caller pushed
11065 Normally, this macro will push all remaining incoming registers on the
11066 stack and set PRETEND_SIZE to the length of the registers pushed. */
11068 static void
11069 setup_incoming_varargs (cumulative_args_t cum, machine_mode mode,
11070 tree type, int *pretend_size ATTRIBUTE_UNUSED,
11071 int no_rtl)
11073 CUMULATIVE_ARGS next_cum;
11074 int reg_size = TARGET_32BIT ? 4 : 8;
11075 rtx save_area = NULL_RTX, mem;
11076 int first_reg_offset;
11077 alias_set_type set;
11079 /* Skip the last named argument. */
11080 next_cum = *get_cumulative_args (cum);
11081 rs6000_function_arg_advance_1 (&next_cum, mode, type, true, 0);
11083 if (DEFAULT_ABI == ABI_V4)
11085 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
11087 if (! no_rtl)
11089 int gpr_reg_num = 0, gpr_size = 0, fpr_size = 0;
11090 HOST_WIDE_INT offset = 0;
11092 /* Try to optimize the size of the varargs save area.
11093 The ABI requires that ap.reg_save_area is doubleword
11094 aligned, but we don't need to allocate space for all
11095 the bytes, only those to which we actually will save
11096 anything. */
11097 if (cfun->va_list_gpr_size && first_reg_offset < GP_ARG_NUM_REG)
11098 gpr_reg_num = GP_ARG_NUM_REG - first_reg_offset;
11099 if (TARGET_HARD_FLOAT && TARGET_FPRS
11100 && next_cum.fregno <= FP_ARG_V4_MAX_REG
11101 && cfun->va_list_fpr_size)
11103 if (gpr_reg_num)
11104 fpr_size = (next_cum.fregno - FP_ARG_MIN_REG)
11105 * UNITS_PER_FP_WORD;
11106 if (cfun->va_list_fpr_size
11107 < FP_ARG_V4_MAX_REG + 1 - next_cum.fregno)
11108 fpr_size += cfun->va_list_fpr_size * UNITS_PER_FP_WORD;
11109 else
11110 fpr_size += (FP_ARG_V4_MAX_REG + 1 - next_cum.fregno)
11111 * UNITS_PER_FP_WORD;
11113 if (gpr_reg_num)
11115 offset = -((first_reg_offset * reg_size) & ~7);
11116 if (!fpr_size && gpr_reg_num > cfun->va_list_gpr_size)
11118 gpr_reg_num = cfun->va_list_gpr_size;
11119 if (reg_size == 4 && (first_reg_offset & 1))
11120 gpr_reg_num++;
11122 gpr_size = (gpr_reg_num * reg_size + 7) & ~7;
11124 else if (fpr_size)
11125 offset = - (int) (next_cum.fregno - FP_ARG_MIN_REG)
11126 * UNITS_PER_FP_WORD
11127 - (int) (GP_ARG_NUM_REG * reg_size);
11129 if (gpr_size + fpr_size)
11131 rtx reg_save_area
11132 = assign_stack_local (BLKmode, gpr_size + fpr_size, 64);
11133 gcc_assert (GET_CODE (reg_save_area) == MEM);
11134 reg_save_area = XEXP (reg_save_area, 0);
11135 if (GET_CODE (reg_save_area) == PLUS)
11137 gcc_assert (XEXP (reg_save_area, 0)
11138 == virtual_stack_vars_rtx);
11139 gcc_assert (GET_CODE (XEXP (reg_save_area, 1)) == CONST_INT);
11140 offset += INTVAL (XEXP (reg_save_area, 1));
11142 else
11143 gcc_assert (reg_save_area == virtual_stack_vars_rtx);
11146 cfun->machine->varargs_save_offset = offset;
11147 save_area = plus_constant (Pmode, virtual_stack_vars_rtx, offset);
11150 else
11152 first_reg_offset = next_cum.words;
11153 save_area = virtual_incoming_args_rtx;
11155 if (targetm.calls.must_pass_in_stack (mode, type))
11156 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
11159 set = get_varargs_alias_set ();
11160 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG
11161 && cfun->va_list_gpr_size)
11163 int n_gpr, nregs = GP_ARG_NUM_REG - first_reg_offset;
11165 if (va_list_gpr_counter_field)
11166 /* V4 va_list_gpr_size counts number of registers needed. */
11167 n_gpr = cfun->va_list_gpr_size;
11168 else
11169 /* char * va_list instead counts number of bytes needed. */
11170 n_gpr = (cfun->va_list_gpr_size + reg_size - 1) / reg_size;
11172 if (nregs > n_gpr)
11173 nregs = n_gpr;
11175 mem = gen_rtx_MEM (BLKmode,
11176 plus_constant (Pmode, save_area,
11177 first_reg_offset * reg_size));
11178 MEM_NOTRAP_P (mem) = 1;
11179 set_mem_alias_set (mem, set);
11180 set_mem_align (mem, BITS_PER_WORD);
11182 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
11183 nregs);
11186 /* Save FP registers if needed. */
11187 if (DEFAULT_ABI == ABI_V4
11188 && TARGET_HARD_FLOAT && TARGET_FPRS
11189 && ! no_rtl
11190 && next_cum.fregno <= FP_ARG_V4_MAX_REG
11191 && cfun->va_list_fpr_size)
11193 int fregno = next_cum.fregno, nregs;
11194 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
11195 rtx lab = gen_label_rtx ();
11196 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG)
11197 * UNITS_PER_FP_WORD);
11199 emit_jump_insn
11200 (gen_rtx_SET (pc_rtx,
11201 gen_rtx_IF_THEN_ELSE (VOIDmode,
11202 gen_rtx_NE (VOIDmode, cr1,
11203 const0_rtx),
11204 gen_rtx_LABEL_REF (VOIDmode, lab),
11205 pc_rtx)));
11207 for (nregs = 0;
11208 fregno <= FP_ARG_V4_MAX_REG && nregs < cfun->va_list_fpr_size;
11209 fregno++, off += UNITS_PER_FP_WORD, nregs++)
11211 mem = gen_rtx_MEM ((TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT)
11212 ? DFmode : SFmode,
11213 plus_constant (Pmode, save_area, off));
11214 MEM_NOTRAP_P (mem) = 1;
11215 set_mem_alias_set (mem, set);
11216 set_mem_align (mem, GET_MODE_ALIGNMENT (
11217 (TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT)
11218 ? DFmode : SFmode));
11219 emit_move_insn (mem, gen_rtx_REG (
11220 (TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT)
11221 ? DFmode : SFmode, fregno));
11224 emit_label (lab);
11228 /* Create the va_list data type. */
11230 static tree
11231 rs6000_build_builtin_va_list (void)
11233 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
11235 /* For AIX, prefer 'char *' because that's what the system
11236 header files like. */
11237 if (DEFAULT_ABI != ABI_V4)
11238 return build_pointer_type (char_type_node);
11240 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
11241 type_decl = build_decl (BUILTINS_LOCATION, TYPE_DECL,
11242 get_identifier ("__va_list_tag"), record);
11244 f_gpr = build_decl (BUILTINS_LOCATION, FIELD_DECL, get_identifier ("gpr"),
11245 unsigned_char_type_node);
11246 f_fpr = build_decl (BUILTINS_LOCATION, FIELD_DECL, get_identifier ("fpr"),
11247 unsigned_char_type_node);
11248 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
11249 every user file. */
11250 f_res = build_decl (BUILTINS_LOCATION, FIELD_DECL,
11251 get_identifier ("reserved"), short_unsigned_type_node);
11252 f_ovf = build_decl (BUILTINS_LOCATION, FIELD_DECL,
11253 get_identifier ("overflow_arg_area"),
11254 ptr_type_node);
11255 f_sav = build_decl (BUILTINS_LOCATION, FIELD_DECL,
11256 get_identifier ("reg_save_area"),
11257 ptr_type_node);
11259 va_list_gpr_counter_field = f_gpr;
11260 va_list_fpr_counter_field = f_fpr;
11262 DECL_FIELD_CONTEXT (f_gpr) = record;
11263 DECL_FIELD_CONTEXT (f_fpr) = record;
11264 DECL_FIELD_CONTEXT (f_res) = record;
11265 DECL_FIELD_CONTEXT (f_ovf) = record;
11266 DECL_FIELD_CONTEXT (f_sav) = record;
11268 TYPE_STUB_DECL (record) = type_decl;
11269 TYPE_NAME (record) = type_decl;
11270 TYPE_FIELDS (record) = f_gpr;
11271 DECL_CHAIN (f_gpr) = f_fpr;
11272 DECL_CHAIN (f_fpr) = f_res;
11273 DECL_CHAIN (f_res) = f_ovf;
11274 DECL_CHAIN (f_ovf) = f_sav;
11276 layout_type (record);
11278 /* The correct type is an array type of one element. */
11279 return build_array_type (record, build_index_type (size_zero_node));
11282 /* Implement va_start. */
11284 static void
11285 rs6000_va_start (tree valist, rtx nextarg)
11287 HOST_WIDE_INT words, n_gpr, n_fpr;
11288 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
11289 tree gpr, fpr, ovf, sav, t;
11291 /* Only SVR4 needs something special. */
11292 if (DEFAULT_ABI != ABI_V4)
11294 std_expand_builtin_va_start (valist, nextarg);
11295 return;
11298 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
11299 f_fpr = DECL_CHAIN (f_gpr);
11300 f_res = DECL_CHAIN (f_fpr);
11301 f_ovf = DECL_CHAIN (f_res);
11302 f_sav = DECL_CHAIN (f_ovf);
11304 valist = build_simple_mem_ref (valist);
11305 gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
11306 fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
11307 f_fpr, NULL_TREE);
11308 ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
11309 f_ovf, NULL_TREE);
11310 sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
11311 f_sav, NULL_TREE);
11313 /* Count number of gp and fp argument registers used. */
11314 words = crtl->args.info.words;
11315 n_gpr = MIN (crtl->args.info.sysv_gregno - GP_ARG_MIN_REG,
11316 GP_ARG_NUM_REG);
11317 n_fpr = MIN (crtl->args.info.fregno - FP_ARG_MIN_REG,
11318 FP_ARG_NUM_REG);
11320 if (TARGET_DEBUG_ARG)
11321 fprintf (stderr, "va_start: words = " HOST_WIDE_INT_PRINT_DEC", n_gpr = "
11322 HOST_WIDE_INT_PRINT_DEC", n_fpr = " HOST_WIDE_INT_PRINT_DEC"\n",
11323 words, n_gpr, n_fpr);
11325 if (cfun->va_list_gpr_size)
11327 t = build2 (MODIFY_EXPR, TREE_TYPE (gpr), gpr,
11328 build_int_cst (NULL_TREE, n_gpr));
11329 TREE_SIDE_EFFECTS (t) = 1;
11330 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
11333 if (cfun->va_list_fpr_size)
11335 t = build2 (MODIFY_EXPR, TREE_TYPE (fpr), fpr,
11336 build_int_cst (NULL_TREE, n_fpr));
11337 TREE_SIDE_EFFECTS (t) = 1;
11338 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
11340 #ifdef HAVE_AS_GNU_ATTRIBUTE
11341 if (call_ABI_of_interest (cfun->decl))
11342 rs6000_passes_float = true;
11343 #endif
11346 /* Find the overflow area. */
11347 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
11348 if (words != 0)
11349 t = fold_build_pointer_plus_hwi (t, words * MIN_UNITS_PER_WORD);
11350 t = build2 (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
11351 TREE_SIDE_EFFECTS (t) = 1;
11352 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
11354 /* If there were no va_arg invocations, don't set up the register
11355 save area. */
11356 if (!cfun->va_list_gpr_size
11357 && !cfun->va_list_fpr_size
11358 && n_gpr < GP_ARG_NUM_REG
11359 && n_fpr < FP_ARG_V4_MAX_REG)
11360 return;
11362 /* Find the register save area. */
11363 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
11364 if (cfun->machine->varargs_save_offset)
11365 t = fold_build_pointer_plus_hwi (t, cfun->machine->varargs_save_offset);
11366 t = build2 (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
11367 TREE_SIDE_EFFECTS (t) = 1;
11368 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
11371 /* Implement va_arg. */
11373 static tree
11374 rs6000_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
11375 gimple_seq *post_p)
11377 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
11378 tree gpr, fpr, ovf, sav, reg, t, u;
11379 int size, rsize, n_reg, sav_ofs, sav_scale;
11380 tree lab_false, lab_over, addr;
11381 int align;
11382 tree ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
11383 int regalign = 0;
11384 gimple stmt;
11386 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
11388 t = rs6000_gimplify_va_arg (valist, ptrtype, pre_p, post_p);
11389 return build_va_arg_indirect_ref (t);
11392 /* We need to deal with the fact that the darwin ppc64 ABI is defined by an
11393 earlier version of gcc, with the property that it always applied alignment
11394 adjustments to the va-args (even for zero-sized types). The cheapest way
11395 to deal with this is to replicate the effect of the part of
11396 std_gimplify_va_arg_expr that carries out the align adjust, for the case
11397 of relevance.
11398 We don't need to check for pass-by-reference because of the test above.
11399 We can return a simplifed answer, since we know there's no offset to add. */
11401 if (((TARGET_MACHO
11402 && rs6000_darwin64_abi)
11403 || DEFAULT_ABI == ABI_ELFv2
11404 || (DEFAULT_ABI == ABI_AIX && !rs6000_compat_align_parm))
11405 && integer_zerop (TYPE_SIZE (type)))
11407 unsigned HOST_WIDE_INT align, boundary;
11408 tree valist_tmp = get_initialized_tmp_var (valist, pre_p, NULL);
11409 align = PARM_BOUNDARY / BITS_PER_UNIT;
11410 boundary = rs6000_function_arg_boundary (TYPE_MODE (type), type);
11411 if (boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
11412 boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
11413 boundary /= BITS_PER_UNIT;
11414 if (boundary > align)
11416 tree t ;
11417 /* This updates arg ptr by the amount that would be necessary
11418 to align the zero-sized (but not zero-alignment) item. */
11419 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
11420 fold_build_pointer_plus_hwi (valist_tmp, boundary - 1));
11421 gimplify_and_add (t, pre_p);
11423 t = fold_convert (sizetype, valist_tmp);
11424 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist_tmp,
11425 fold_convert (TREE_TYPE (valist),
11426 fold_build2 (BIT_AND_EXPR, sizetype, t,
11427 size_int (-boundary))));
11428 t = build2 (MODIFY_EXPR, TREE_TYPE (valist), valist, t);
11429 gimplify_and_add (t, pre_p);
11431 /* Since it is zero-sized there's no increment for the item itself. */
11432 valist_tmp = fold_convert (build_pointer_type (type), valist_tmp);
11433 return build_va_arg_indirect_ref (valist_tmp);
11436 if (DEFAULT_ABI != ABI_V4)
11438 if (targetm.calls.split_complex_arg && TREE_CODE (type) == COMPLEX_TYPE)
11440 tree elem_type = TREE_TYPE (type);
11441 machine_mode elem_mode = TYPE_MODE (elem_type);
11442 int elem_size = GET_MODE_SIZE (elem_mode);
11444 if (elem_size < UNITS_PER_WORD)
11446 tree real_part, imag_part;
11447 gimple_seq post = NULL;
11449 real_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
11450 &post);
11451 /* Copy the value into a temporary, lest the formal temporary
11452 be reused out from under us. */
11453 real_part = get_initialized_tmp_var (real_part, pre_p, &post);
11454 gimple_seq_add_seq (pre_p, post);
11456 imag_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
11457 post_p);
11459 return build2 (COMPLEX_EXPR, type, real_part, imag_part);
11463 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
11466 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
11467 f_fpr = DECL_CHAIN (f_gpr);
11468 f_res = DECL_CHAIN (f_fpr);
11469 f_ovf = DECL_CHAIN (f_res);
11470 f_sav = DECL_CHAIN (f_ovf);
11472 gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
11473 fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
11474 f_fpr, NULL_TREE);
11475 ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
11476 f_ovf, NULL_TREE);
11477 sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
11478 f_sav, NULL_TREE);
11480 size = int_size_in_bytes (type);
11481 rsize = (size + 3) / 4;
11482 align = 1;
11484 if (TARGET_HARD_FLOAT && TARGET_FPRS
11485 && ((TARGET_SINGLE_FLOAT && TYPE_MODE (type) == SFmode)
11486 || (TARGET_DOUBLE_FLOAT
11487 && (TYPE_MODE (type) == DFmode
11488 || TYPE_MODE (type) == TFmode
11489 || TYPE_MODE (type) == SDmode
11490 || TYPE_MODE (type) == DDmode
11491 || TYPE_MODE (type) == TDmode))))
11493 /* FP args go in FP registers, if present. */
11494 reg = fpr;
11495 n_reg = (size + 7) / 8;
11496 sav_ofs = ((TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT) ? 8 : 4) * 4;
11497 sav_scale = ((TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT) ? 8 : 4);
11498 if (TYPE_MODE (type) != SFmode && TYPE_MODE (type) != SDmode)
11499 align = 8;
11501 else
11503 /* Otherwise into GP registers. */
11504 reg = gpr;
11505 n_reg = rsize;
11506 sav_ofs = 0;
11507 sav_scale = 4;
11508 if (n_reg == 2)
11509 align = 8;
11512 /* Pull the value out of the saved registers.... */
11514 lab_over = NULL;
11515 addr = create_tmp_var (ptr_type_node, "addr");
11517 /* AltiVec vectors never go in registers when -mabi=altivec. */
11518 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
11519 align = 16;
11520 else
11522 lab_false = create_artificial_label (input_location);
11523 lab_over = create_artificial_label (input_location);
11525 /* Long long and SPE vectors are aligned in the registers.
11526 As are any other 2 gpr item such as complex int due to a
11527 historical mistake. */
11528 u = reg;
11529 if (n_reg == 2 && reg == gpr)
11531 regalign = 1;
11532 u = build2 (BIT_AND_EXPR, TREE_TYPE (reg), unshare_expr (reg),
11533 build_int_cst (TREE_TYPE (reg), n_reg - 1));
11534 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg),
11535 unshare_expr (reg), u);
11537 /* _Decimal128 is passed in even/odd fpr pairs; the stored
11538 reg number is 0 for f1, so we want to make it odd. */
11539 else if (reg == fpr && TYPE_MODE (type) == TDmode)
11541 t = build2 (BIT_IOR_EXPR, TREE_TYPE (reg), unshare_expr (reg),
11542 build_int_cst (TREE_TYPE (reg), 1));
11543 u = build2 (MODIFY_EXPR, void_type_node, unshare_expr (reg), t);
11546 t = fold_convert (TREE_TYPE (reg), size_int (8 - n_reg + 1));
11547 t = build2 (GE_EXPR, boolean_type_node, u, t);
11548 u = build1 (GOTO_EXPR, void_type_node, lab_false);
11549 t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE);
11550 gimplify_and_add (t, pre_p);
11552 t = sav;
11553 if (sav_ofs)
11554 t = fold_build_pointer_plus_hwi (sav, sav_ofs);
11556 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), unshare_expr (reg),
11557 build_int_cst (TREE_TYPE (reg), n_reg));
11558 u = fold_convert (sizetype, u);
11559 u = build2 (MULT_EXPR, sizetype, u, size_int (sav_scale));
11560 t = fold_build_pointer_plus (t, u);
11562 /* _Decimal32 varargs are located in the second word of the 64-bit
11563 FP register for 32-bit binaries. */
11564 if (TARGET_32BIT
11565 && TARGET_HARD_FLOAT && TARGET_FPRS
11566 && TYPE_MODE (type) == SDmode)
11567 t = fold_build_pointer_plus_hwi (t, size);
11569 gimplify_assign (addr, t, pre_p);
11571 gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
11573 stmt = gimple_build_label (lab_false);
11574 gimple_seq_add_stmt (pre_p, stmt);
11576 if ((n_reg == 2 && !regalign) || n_reg > 2)
11578 /* Ensure that we don't find any more args in regs.
11579 Alignment has taken care of for special cases. */
11580 gimplify_assign (reg, build_int_cst (TREE_TYPE (reg), 8), pre_p);
11584 /* ... otherwise out of the overflow area. */
11586 /* Care for on-stack alignment if needed. */
11587 t = ovf;
11588 if (align != 1)
11590 t = fold_build_pointer_plus_hwi (t, align - 1);
11591 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
11592 build_int_cst (TREE_TYPE (t), -align));
11594 gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
11596 gimplify_assign (unshare_expr (addr), t, pre_p);
11598 t = fold_build_pointer_plus_hwi (t, size);
11599 gimplify_assign (unshare_expr (ovf), t, pre_p);
11601 if (lab_over)
11603 stmt = gimple_build_label (lab_over);
11604 gimple_seq_add_stmt (pre_p, stmt);
11607 if (STRICT_ALIGNMENT
11608 && (TYPE_ALIGN (type)
11609 > (unsigned) BITS_PER_UNIT * (align < 4 ? 4 : align)))
11611 /* The value (of type complex double, for example) may not be
11612 aligned in memory in the saved registers, so copy via a
11613 temporary. (This is the same code as used for SPARC.) */
11614 tree tmp = create_tmp_var (type, "va_arg_tmp");
11615 tree dest_addr = build_fold_addr_expr (tmp);
11617 tree copy = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
11618 3, dest_addr, addr, size_int (rsize * 4));
11620 gimplify_and_add (copy, pre_p);
11621 addr = dest_addr;
11624 addr = fold_convert (ptrtype, addr);
11625 return build_va_arg_indirect_ref (addr);
11628 /* Builtins. */
11630 static void
11631 def_builtin (const char *name, tree type, enum rs6000_builtins code)
11633 tree t;
11634 unsigned classify = rs6000_builtin_info[(int)code].attr;
11635 const char *attr_string = "";
11637 gcc_assert (name != NULL);
11638 gcc_assert (IN_RANGE ((int)code, 0, (int)RS6000_BUILTIN_COUNT));
11640 if (rs6000_builtin_decls[(int)code])
11641 fatal_error (input_location,
11642 "internal error: builtin function %s already processed", name);
11644 rs6000_builtin_decls[(int)code] = t =
11645 add_builtin_function (name, type, (int)code, BUILT_IN_MD, NULL, NULL_TREE);
11647 /* Set any special attributes. */
11648 if ((classify & RS6000_BTC_CONST) != 0)
11650 /* const function, function only depends on the inputs. */
11651 TREE_READONLY (t) = 1;
11652 TREE_NOTHROW (t) = 1;
11653 attr_string = ", pure";
11655 else if ((classify & RS6000_BTC_PURE) != 0)
11657 /* pure function, function can read global memory, but does not set any
11658 external state. */
11659 DECL_PURE_P (t) = 1;
11660 TREE_NOTHROW (t) = 1;
11661 attr_string = ", const";
11663 else if ((classify & RS6000_BTC_FP) != 0)
11665 /* Function is a math function. If rounding mode is on, then treat the
11666 function as not reading global memory, but it can have arbitrary side
11667 effects. If it is off, then assume the function is a const function.
11668 This mimics the ATTR_MATHFN_FPROUNDING attribute in
11669 builtin-attribute.def that is used for the math functions. */
11670 TREE_NOTHROW (t) = 1;
11671 if (flag_rounding_math)
11673 DECL_PURE_P (t) = 1;
11674 DECL_IS_NOVOPS (t) = 1;
11675 attr_string = ", fp, pure";
11677 else
11679 TREE_READONLY (t) = 1;
11680 attr_string = ", fp, const";
11683 else if ((classify & RS6000_BTC_ATTR_MASK) != 0)
11684 gcc_unreachable ();
11686 if (TARGET_DEBUG_BUILTIN)
11687 fprintf (stderr, "rs6000_builtin, code = %4d, %s%s\n",
11688 (int)code, name, attr_string);
11691 /* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
11693 #undef RS6000_BUILTIN_1
11694 #undef RS6000_BUILTIN_2
11695 #undef RS6000_BUILTIN_3
11696 #undef RS6000_BUILTIN_A
11697 #undef RS6000_BUILTIN_D
11698 #undef RS6000_BUILTIN_E
11699 #undef RS6000_BUILTIN_H
11700 #undef RS6000_BUILTIN_P
11701 #undef RS6000_BUILTIN_Q
11702 #undef RS6000_BUILTIN_S
11703 #undef RS6000_BUILTIN_X
11705 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11706 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11707 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE) \
11708 { MASK, ICODE, NAME, ENUM },
11710 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11711 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11712 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11713 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11714 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11715 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11716 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11717 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11719 static const struct builtin_description bdesc_3arg[] =
11721 #include "rs6000-builtin.def"
11724 /* DST operations: void foo (void *, const int, const char). */
11726 #undef RS6000_BUILTIN_1
11727 #undef RS6000_BUILTIN_2
11728 #undef RS6000_BUILTIN_3
11729 #undef RS6000_BUILTIN_A
11730 #undef RS6000_BUILTIN_D
11731 #undef RS6000_BUILTIN_E
11732 #undef RS6000_BUILTIN_H
11733 #undef RS6000_BUILTIN_P
11734 #undef RS6000_BUILTIN_Q
11735 #undef RS6000_BUILTIN_S
11736 #undef RS6000_BUILTIN_X
11738 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11739 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11740 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11741 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11742 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE) \
11743 { MASK, ICODE, NAME, ENUM },
11745 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11746 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11747 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11748 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11749 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11750 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11752 static const struct builtin_description bdesc_dst[] =
11754 #include "rs6000-builtin.def"
11757 /* Simple binary operations: VECc = foo (VECa, VECb). */
11759 #undef RS6000_BUILTIN_1
11760 #undef RS6000_BUILTIN_2
11761 #undef RS6000_BUILTIN_3
11762 #undef RS6000_BUILTIN_A
11763 #undef RS6000_BUILTIN_D
11764 #undef RS6000_BUILTIN_E
11765 #undef RS6000_BUILTIN_H
11766 #undef RS6000_BUILTIN_P
11767 #undef RS6000_BUILTIN_Q
11768 #undef RS6000_BUILTIN_S
11769 #undef RS6000_BUILTIN_X
11771 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11772 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE) \
11773 { MASK, ICODE, NAME, ENUM },
11775 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11776 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11777 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11778 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11779 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11780 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11781 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11782 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11783 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11785 static const struct builtin_description bdesc_2arg[] =
11787 #include "rs6000-builtin.def"
11790 #undef RS6000_BUILTIN_1
11791 #undef RS6000_BUILTIN_2
11792 #undef RS6000_BUILTIN_3
11793 #undef RS6000_BUILTIN_A
11794 #undef RS6000_BUILTIN_D
11795 #undef RS6000_BUILTIN_E
11796 #undef RS6000_BUILTIN_H
11797 #undef RS6000_BUILTIN_P
11798 #undef RS6000_BUILTIN_Q
11799 #undef RS6000_BUILTIN_S
11800 #undef RS6000_BUILTIN_X
11802 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11803 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11804 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11805 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11806 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11807 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11808 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11809 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE) \
11810 { MASK, ICODE, NAME, ENUM },
11812 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11813 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11814 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11816 /* AltiVec predicates. */
11818 static const struct builtin_description bdesc_altivec_preds[] =
11820 #include "rs6000-builtin.def"
11823 /* SPE predicates. */
11824 #undef RS6000_BUILTIN_1
11825 #undef RS6000_BUILTIN_2
11826 #undef RS6000_BUILTIN_3
11827 #undef RS6000_BUILTIN_A
11828 #undef RS6000_BUILTIN_D
11829 #undef RS6000_BUILTIN_E
11830 #undef RS6000_BUILTIN_H
11831 #undef RS6000_BUILTIN_P
11832 #undef RS6000_BUILTIN_Q
11833 #undef RS6000_BUILTIN_S
11834 #undef RS6000_BUILTIN_X
11836 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11837 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11838 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11839 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11840 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11841 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11842 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11843 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11844 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11845 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE) \
11846 { MASK, ICODE, NAME, ENUM },
11848 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11850 static const struct builtin_description bdesc_spe_predicates[] =
11852 #include "rs6000-builtin.def"
11855 /* SPE evsel predicates. */
11856 #undef RS6000_BUILTIN_1
11857 #undef RS6000_BUILTIN_2
11858 #undef RS6000_BUILTIN_3
11859 #undef RS6000_BUILTIN_A
11860 #undef RS6000_BUILTIN_D
11861 #undef RS6000_BUILTIN_E
11862 #undef RS6000_BUILTIN_H
11863 #undef RS6000_BUILTIN_P
11864 #undef RS6000_BUILTIN_Q
11865 #undef RS6000_BUILTIN_S
11866 #undef RS6000_BUILTIN_X
11868 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11869 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11870 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11871 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11872 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11873 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE) \
11874 { MASK, ICODE, NAME, ENUM },
11876 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11877 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11878 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11879 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11880 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11882 static const struct builtin_description bdesc_spe_evsel[] =
11884 #include "rs6000-builtin.def"
11887 /* PAIRED predicates. */
11888 #undef RS6000_BUILTIN_1
11889 #undef RS6000_BUILTIN_2
11890 #undef RS6000_BUILTIN_3
11891 #undef RS6000_BUILTIN_A
11892 #undef RS6000_BUILTIN_D
11893 #undef RS6000_BUILTIN_E
11894 #undef RS6000_BUILTIN_H
11895 #undef RS6000_BUILTIN_P
11896 #undef RS6000_BUILTIN_Q
11897 #undef RS6000_BUILTIN_S
11898 #undef RS6000_BUILTIN_X
11900 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11901 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11902 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11903 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11904 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11905 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11906 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11907 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11908 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE) \
11909 { MASK, ICODE, NAME, ENUM },
11911 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11912 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11914 static const struct builtin_description bdesc_paired_preds[] =
11916 #include "rs6000-builtin.def"
11919 /* ABS* operations. */
11921 #undef RS6000_BUILTIN_1
11922 #undef RS6000_BUILTIN_2
11923 #undef RS6000_BUILTIN_3
11924 #undef RS6000_BUILTIN_A
11925 #undef RS6000_BUILTIN_D
11926 #undef RS6000_BUILTIN_E
11927 #undef RS6000_BUILTIN_H
11928 #undef RS6000_BUILTIN_P
11929 #undef RS6000_BUILTIN_Q
11930 #undef RS6000_BUILTIN_S
11931 #undef RS6000_BUILTIN_X
11933 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
11934 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11935 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11936 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE) \
11937 { MASK, ICODE, NAME, ENUM },
11939 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11940 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11941 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11942 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11943 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11944 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11945 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11947 static const struct builtin_description bdesc_abs[] =
11949 #include "rs6000-builtin.def"
11952 /* Simple unary operations: VECb = foo (unsigned literal) or VECb =
11953 foo (VECa). */
11955 #undef RS6000_BUILTIN_1
11956 #undef RS6000_BUILTIN_2
11957 #undef RS6000_BUILTIN_3
11958 #undef RS6000_BUILTIN_A
11959 #undef RS6000_BUILTIN_D
11960 #undef RS6000_BUILTIN_E
11961 #undef RS6000_BUILTIN_H
11962 #undef RS6000_BUILTIN_P
11963 #undef RS6000_BUILTIN_Q
11964 #undef RS6000_BUILTIN_S
11965 #undef RS6000_BUILTIN_X
11967 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE) \
11968 { MASK, ICODE, NAME, ENUM },
11970 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
11971 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
11972 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
11973 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
11974 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
11975 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE)
11976 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
11977 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
11978 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
11979 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
11981 static const struct builtin_description bdesc_1arg[] =
11983 #include "rs6000-builtin.def"
11986 /* HTM builtins. */
11987 #undef RS6000_BUILTIN_1
11988 #undef RS6000_BUILTIN_2
11989 #undef RS6000_BUILTIN_3
11990 #undef RS6000_BUILTIN_A
11991 #undef RS6000_BUILTIN_D
11992 #undef RS6000_BUILTIN_E
11993 #undef RS6000_BUILTIN_H
11994 #undef RS6000_BUILTIN_P
11995 #undef RS6000_BUILTIN_Q
11996 #undef RS6000_BUILTIN_S
11997 #undef RS6000_BUILTIN_X
11999 #define RS6000_BUILTIN_1(ENUM, NAME, MASK, ATTR, ICODE)
12000 #define RS6000_BUILTIN_2(ENUM, NAME, MASK, ATTR, ICODE)
12001 #define RS6000_BUILTIN_3(ENUM, NAME, MASK, ATTR, ICODE)
12002 #define RS6000_BUILTIN_A(ENUM, NAME, MASK, ATTR, ICODE)
12003 #define RS6000_BUILTIN_D(ENUM, NAME, MASK, ATTR, ICODE)
12004 #define RS6000_BUILTIN_E(ENUM, NAME, MASK, ATTR, ICODE)
12005 #define RS6000_BUILTIN_H(ENUM, NAME, MASK, ATTR, ICODE) \
12006 { MASK, ICODE, NAME, ENUM },
12008 #define RS6000_BUILTIN_P(ENUM, NAME, MASK, ATTR, ICODE)
12009 #define RS6000_BUILTIN_Q(ENUM, NAME, MASK, ATTR, ICODE)
12010 #define RS6000_BUILTIN_S(ENUM, NAME, MASK, ATTR, ICODE)
12011 #define RS6000_BUILTIN_X(ENUM, NAME, MASK, ATTR, ICODE)
12013 static const struct builtin_description bdesc_htm[] =
12015 #include "rs6000-builtin.def"
12018 #undef RS6000_BUILTIN_1
12019 #undef RS6000_BUILTIN_2
12020 #undef RS6000_BUILTIN_3
12021 #undef RS6000_BUILTIN_A
12022 #undef RS6000_BUILTIN_D
12023 #undef RS6000_BUILTIN_E
12024 #undef RS6000_BUILTIN_H
12025 #undef RS6000_BUILTIN_P
12026 #undef RS6000_BUILTIN_Q
12027 #undef RS6000_BUILTIN_S
12029 /* Return true if a builtin function is overloaded. */
12030 bool
12031 rs6000_overloaded_builtin_p (enum rs6000_builtins fncode)
12033 return (rs6000_builtin_info[(int)fncode].attr & RS6000_BTC_OVERLOADED) != 0;
12036 /* Expand an expression EXP that calls a builtin without arguments. */
12037 static rtx
12038 rs6000_expand_zeroop_builtin (enum insn_code icode, rtx target)
12040 rtx pat;
12041 machine_mode tmode = insn_data[icode].operand[0].mode;
12043 if (icode == CODE_FOR_nothing)
12044 /* Builtin not supported on this processor. */
12045 return 0;
12047 if (target == 0
12048 || GET_MODE (target) != tmode
12049 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12050 target = gen_reg_rtx (tmode);
12052 pat = GEN_FCN (icode) (target);
12053 if (! pat)
12054 return 0;
12055 emit_insn (pat);
12057 return target;
12061 static rtx
12062 rs6000_expand_mtfsf_builtin (enum insn_code icode, tree exp)
12064 rtx pat;
12065 tree arg0 = CALL_EXPR_ARG (exp, 0);
12066 tree arg1 = CALL_EXPR_ARG (exp, 1);
12067 rtx op0 = expand_normal (arg0);
12068 rtx op1 = expand_normal (arg1);
12069 machine_mode mode0 = insn_data[icode].operand[0].mode;
12070 machine_mode mode1 = insn_data[icode].operand[1].mode;
12072 if (icode == CODE_FOR_nothing)
12073 /* Builtin not supported on this processor. */
12074 return 0;
12076 /* If we got invalid arguments bail out before generating bad rtl. */
12077 if (arg0 == error_mark_node || arg1 == error_mark_node)
12078 return const0_rtx;
12080 if (GET_CODE (op0) != CONST_INT
12081 || INTVAL (op0) > 255
12082 || INTVAL (op0) < 0)
12084 error ("argument 1 must be an 8-bit field value");
12085 return const0_rtx;
12088 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
12089 op0 = copy_to_mode_reg (mode0, op0);
12091 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
12092 op1 = copy_to_mode_reg (mode1, op1);
12094 pat = GEN_FCN (icode) (op0, op1);
12095 if (! pat)
12096 return const0_rtx;
12097 emit_insn (pat);
12099 return NULL_RTX;
12103 static rtx
12104 rs6000_expand_unop_builtin (enum insn_code icode, tree exp, rtx target)
12106 rtx pat;
12107 tree arg0 = CALL_EXPR_ARG (exp, 0);
12108 rtx op0 = expand_normal (arg0);
12109 machine_mode tmode = insn_data[icode].operand[0].mode;
12110 machine_mode mode0 = insn_data[icode].operand[1].mode;
12112 if (icode == CODE_FOR_nothing)
12113 /* Builtin not supported on this processor. */
12114 return 0;
12116 /* If we got invalid arguments bail out before generating bad rtl. */
12117 if (arg0 == error_mark_node)
12118 return const0_rtx;
12120 if (icode == CODE_FOR_altivec_vspltisb
12121 || icode == CODE_FOR_altivec_vspltish
12122 || icode == CODE_FOR_altivec_vspltisw
12123 || icode == CODE_FOR_spe_evsplatfi
12124 || icode == CODE_FOR_spe_evsplati)
12126 /* Only allow 5-bit *signed* literals. */
12127 if (GET_CODE (op0) != CONST_INT
12128 || INTVAL (op0) > 15
12129 || INTVAL (op0) < -16)
12131 error ("argument 1 must be a 5-bit signed literal");
12132 return const0_rtx;
12136 if (target == 0
12137 || GET_MODE (target) != tmode
12138 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12139 target = gen_reg_rtx (tmode);
12141 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12142 op0 = copy_to_mode_reg (mode0, op0);
12144 pat = GEN_FCN (icode) (target, op0);
12145 if (! pat)
12146 return 0;
12147 emit_insn (pat);
12149 return target;
12152 static rtx
12153 altivec_expand_abs_builtin (enum insn_code icode, tree exp, rtx target)
12155 rtx pat, scratch1, scratch2;
12156 tree arg0 = CALL_EXPR_ARG (exp, 0);
12157 rtx op0 = expand_normal (arg0);
12158 machine_mode tmode = insn_data[icode].operand[0].mode;
12159 machine_mode mode0 = insn_data[icode].operand[1].mode;
12161 /* If we have invalid arguments, bail out before generating bad rtl. */
12162 if (arg0 == error_mark_node)
12163 return const0_rtx;
12165 if (target == 0
12166 || GET_MODE (target) != tmode
12167 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12168 target = gen_reg_rtx (tmode);
12170 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12171 op0 = copy_to_mode_reg (mode0, op0);
12173 scratch1 = gen_reg_rtx (mode0);
12174 scratch2 = gen_reg_rtx (mode0);
12176 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
12177 if (! pat)
12178 return 0;
12179 emit_insn (pat);
12181 return target;
12184 static rtx
12185 rs6000_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
12187 rtx pat;
12188 tree arg0 = CALL_EXPR_ARG (exp, 0);
12189 tree arg1 = CALL_EXPR_ARG (exp, 1);
12190 rtx op0 = expand_normal (arg0);
12191 rtx op1 = expand_normal (arg1);
12192 machine_mode tmode = insn_data[icode].operand[0].mode;
12193 machine_mode mode0 = insn_data[icode].operand[1].mode;
12194 machine_mode mode1 = insn_data[icode].operand[2].mode;
12196 if (icode == CODE_FOR_nothing)
12197 /* Builtin not supported on this processor. */
12198 return 0;
12200 /* If we got invalid arguments bail out before generating bad rtl. */
12201 if (arg0 == error_mark_node || arg1 == error_mark_node)
12202 return const0_rtx;
12204 if (icode == CODE_FOR_altivec_vcfux
12205 || icode == CODE_FOR_altivec_vcfsx
12206 || icode == CODE_FOR_altivec_vctsxs
12207 || icode == CODE_FOR_altivec_vctuxs
12208 || icode == CODE_FOR_altivec_vspltb
12209 || icode == CODE_FOR_altivec_vsplth
12210 || icode == CODE_FOR_altivec_vspltw
12211 || icode == CODE_FOR_spe_evaddiw
12212 || icode == CODE_FOR_spe_evldd
12213 || icode == CODE_FOR_spe_evldh
12214 || icode == CODE_FOR_spe_evldw
12215 || icode == CODE_FOR_spe_evlhhesplat
12216 || icode == CODE_FOR_spe_evlhhossplat
12217 || icode == CODE_FOR_spe_evlhhousplat
12218 || icode == CODE_FOR_spe_evlwhe
12219 || icode == CODE_FOR_spe_evlwhos
12220 || icode == CODE_FOR_spe_evlwhou
12221 || icode == CODE_FOR_spe_evlwhsplat
12222 || icode == CODE_FOR_spe_evlwwsplat
12223 || icode == CODE_FOR_spe_evrlwi
12224 || icode == CODE_FOR_spe_evslwi
12225 || icode == CODE_FOR_spe_evsrwis
12226 || icode == CODE_FOR_spe_evsubifw
12227 || icode == CODE_FOR_spe_evsrwiu)
12229 /* Only allow 5-bit unsigned literals. */
12230 STRIP_NOPS (arg1);
12231 if (TREE_CODE (arg1) != INTEGER_CST
12232 || TREE_INT_CST_LOW (arg1) & ~0x1f)
12234 error ("argument 2 must be a 5-bit unsigned literal");
12235 return const0_rtx;
12239 if (target == 0
12240 || GET_MODE (target) != tmode
12241 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12242 target = gen_reg_rtx (tmode);
12244 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12245 op0 = copy_to_mode_reg (mode0, op0);
12246 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
12247 op1 = copy_to_mode_reg (mode1, op1);
12249 pat = GEN_FCN (icode) (target, op0, op1);
12250 if (! pat)
12251 return 0;
12252 emit_insn (pat);
12254 return target;
12257 static rtx
12258 altivec_expand_predicate_builtin (enum insn_code icode, tree exp, rtx target)
12260 rtx pat, scratch;
12261 tree cr6_form = CALL_EXPR_ARG (exp, 0);
12262 tree arg0 = CALL_EXPR_ARG (exp, 1);
12263 tree arg1 = CALL_EXPR_ARG (exp, 2);
12264 rtx op0 = expand_normal (arg0);
12265 rtx op1 = expand_normal (arg1);
12266 machine_mode tmode = SImode;
12267 machine_mode mode0 = insn_data[icode].operand[1].mode;
12268 machine_mode mode1 = insn_data[icode].operand[2].mode;
12269 int cr6_form_int;
12271 if (TREE_CODE (cr6_form) != INTEGER_CST)
12273 error ("argument 1 of __builtin_altivec_predicate must be a constant");
12274 return const0_rtx;
12276 else
12277 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
12279 gcc_assert (mode0 == mode1);
12281 /* If we have invalid arguments, bail out before generating bad rtl. */
12282 if (arg0 == error_mark_node || arg1 == error_mark_node)
12283 return const0_rtx;
12285 if (target == 0
12286 || GET_MODE (target) != tmode
12287 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12288 target = gen_reg_rtx (tmode);
12290 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
12291 op0 = copy_to_mode_reg (mode0, op0);
12292 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
12293 op1 = copy_to_mode_reg (mode1, op1);
12295 scratch = gen_reg_rtx (mode0);
12297 pat = GEN_FCN (icode) (scratch, op0, op1);
12298 if (! pat)
12299 return 0;
12300 emit_insn (pat);
12302 /* The vec_any* and vec_all* predicates use the same opcodes for two
12303 different operations, but the bits in CR6 will be different
12304 depending on what information we want. So we have to play tricks
12305 with CR6 to get the right bits out.
12307 If you think this is disgusting, look at the specs for the
12308 AltiVec predicates. */
12310 switch (cr6_form_int)
12312 case 0:
12313 emit_insn (gen_cr6_test_for_zero (target));
12314 break;
12315 case 1:
12316 emit_insn (gen_cr6_test_for_zero_reverse (target));
12317 break;
12318 case 2:
12319 emit_insn (gen_cr6_test_for_lt (target));
12320 break;
12321 case 3:
12322 emit_insn (gen_cr6_test_for_lt_reverse (target));
12323 break;
12324 default:
12325 error ("argument 1 of __builtin_altivec_predicate is out of range");
12326 break;
12329 return target;
12332 static rtx
12333 paired_expand_lv_builtin (enum insn_code icode, tree exp, rtx target)
12335 rtx pat, addr;
12336 tree arg0 = CALL_EXPR_ARG (exp, 0);
12337 tree arg1 = CALL_EXPR_ARG (exp, 1);
12338 machine_mode tmode = insn_data[icode].operand[0].mode;
12339 machine_mode mode0 = Pmode;
12340 machine_mode mode1 = Pmode;
12341 rtx op0 = expand_normal (arg0);
12342 rtx op1 = expand_normal (arg1);
12344 if (icode == CODE_FOR_nothing)
12345 /* Builtin not supported on this processor. */
12346 return 0;
12348 /* If we got invalid arguments bail out before generating bad rtl. */
12349 if (arg0 == error_mark_node || arg1 == error_mark_node)
12350 return const0_rtx;
12352 if (target == 0
12353 || GET_MODE (target) != tmode
12354 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12355 target = gen_reg_rtx (tmode);
12357 op1 = copy_to_mode_reg (mode1, op1);
12359 if (op0 == const0_rtx)
12361 addr = gen_rtx_MEM (tmode, op1);
12363 else
12365 op0 = copy_to_mode_reg (mode0, op0);
12366 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
12369 pat = GEN_FCN (icode) (target, addr);
12371 if (! pat)
12372 return 0;
12373 emit_insn (pat);
12375 return target;
12378 /* Return a constant vector for use as a little-endian permute control vector
12379 to reverse the order of elements of the given vector mode. */
12380 static rtx
12381 swap_selector_for_mode (machine_mode mode)
12383 /* These are little endian vectors, so their elements are reversed
12384 from what you would normally expect for a permute control vector. */
12385 unsigned int swap2[16] = {7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
12386 unsigned int swap4[16] = {3,2,1,0,7,6,5,4,11,10,9,8,15,14,13,12};
12387 unsigned int swap8[16] = {1,0,3,2,5,4,7,6,9,8,11,10,13,12,15,14};
12388 unsigned int swap16[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
12389 unsigned int *swaparray, i;
12390 rtx perm[16];
12392 switch (mode)
12394 case V2DFmode:
12395 case V2DImode:
12396 swaparray = swap2;
12397 break;
12398 case V4SFmode:
12399 case V4SImode:
12400 swaparray = swap4;
12401 break;
12402 case V8HImode:
12403 swaparray = swap8;
12404 break;
12405 case V16QImode:
12406 swaparray = swap16;
12407 break;
12408 default:
12409 gcc_unreachable ();
12412 for (i = 0; i < 16; ++i)
12413 perm[i] = GEN_INT (swaparray[i]);
12415 return force_reg (V16QImode, gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, perm)));
12418 /* Generate code for an "lvx", "lvxl", or "lve*x" built-in for a little endian target
12419 with -maltivec=be specified. Issue the load followed by an element-reversing
12420 permute. */
12421 void
12422 altivec_expand_lvx_be (rtx op0, rtx op1, machine_mode mode, unsigned unspec)
12424 rtx tmp = gen_reg_rtx (mode);
12425 rtx load = gen_rtx_SET (tmp, op1);
12426 rtx lvx = gen_rtx_UNSPEC (mode, gen_rtvec (1, const0_rtx), unspec);
12427 rtx par = gen_rtx_PARALLEL (mode, gen_rtvec (2, load, lvx));
12428 rtx sel = swap_selector_for_mode (mode);
12429 rtx vperm = gen_rtx_UNSPEC (mode, gen_rtvec (3, tmp, tmp, sel), UNSPEC_VPERM);
12431 gcc_assert (REG_P (op0));
12432 emit_insn (par);
12433 emit_insn (gen_rtx_SET (op0, vperm));
12436 /* Generate code for a "stvx" or "stvxl" built-in for a little endian target
12437 with -maltivec=be specified. Issue the store preceded by an element-reversing
12438 permute. */
12439 void
12440 altivec_expand_stvx_be (rtx op0, rtx op1, machine_mode mode, unsigned unspec)
12442 rtx tmp = gen_reg_rtx (mode);
12443 rtx store = gen_rtx_SET (op0, tmp);
12444 rtx stvx = gen_rtx_UNSPEC (mode, gen_rtvec (1, const0_rtx), unspec);
12445 rtx par = gen_rtx_PARALLEL (mode, gen_rtvec (2, store, stvx));
12446 rtx sel = swap_selector_for_mode (mode);
12447 rtx vperm;
12449 gcc_assert (REG_P (op1));
12450 vperm = gen_rtx_UNSPEC (mode, gen_rtvec (3, op1, op1, sel), UNSPEC_VPERM);
12451 emit_insn (gen_rtx_SET (tmp, vperm));
12452 emit_insn (par);
12455 /* Generate code for a "stve*x" built-in for a little endian target with -maltivec=be
12456 specified. Issue the store preceded by an element-reversing permute. */
12457 void
12458 altivec_expand_stvex_be (rtx op0, rtx op1, machine_mode mode, unsigned unspec)
12460 machine_mode inner_mode = GET_MODE_INNER (mode);
12461 rtx tmp = gen_reg_rtx (mode);
12462 rtx stvx = gen_rtx_UNSPEC (inner_mode, gen_rtvec (1, tmp), unspec);
12463 rtx sel = swap_selector_for_mode (mode);
12464 rtx vperm;
12466 gcc_assert (REG_P (op1));
12467 vperm = gen_rtx_UNSPEC (mode, gen_rtvec (3, op1, op1, sel), UNSPEC_VPERM);
12468 emit_insn (gen_rtx_SET (tmp, vperm));
12469 emit_insn (gen_rtx_SET (op0, stvx));
12472 static rtx
12473 altivec_expand_lv_builtin (enum insn_code icode, tree exp, rtx target, bool blk)
12475 rtx pat, addr;
12476 tree arg0 = CALL_EXPR_ARG (exp, 0);
12477 tree arg1 = CALL_EXPR_ARG (exp, 1);
12478 machine_mode tmode = insn_data[icode].operand[0].mode;
12479 machine_mode mode0 = Pmode;
12480 machine_mode mode1 = Pmode;
12481 rtx op0 = expand_normal (arg0);
12482 rtx op1 = expand_normal (arg1);
12484 if (icode == CODE_FOR_nothing)
12485 /* Builtin not supported on this processor. */
12486 return 0;
12488 /* If we got invalid arguments bail out before generating bad rtl. */
12489 if (arg0 == error_mark_node || arg1 == error_mark_node)
12490 return const0_rtx;
12492 if (target == 0
12493 || GET_MODE (target) != tmode
12494 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
12495 target = gen_reg_rtx (tmode);
12497 op1 = copy_to_mode_reg (mode1, op1);
12499 if (op0 == const0_rtx)
12501 addr = gen_rtx_MEM (blk ? BLKmode : tmode, op1);
12503 else
12505 op0 = copy_to_mode_reg (mode0, op0);
12506 addr = gen_rtx_MEM (blk ? BLKmode : tmode, gen_rtx_PLUS (Pmode, op0, op1));
12509 pat = GEN_FCN (icode) (target, addr);
12511 if (! pat)
12512 return 0;
12513 emit_insn (pat);
12515 return target;
12518 static rtx
12519 spe_expand_stv_builtin (enum insn_code icode, tree exp)
12521 tree arg0 = CALL_EXPR_ARG (exp, 0);
12522 tree arg1 = CALL_EXPR_ARG (exp, 1);
12523 tree arg2 = CALL_EXPR_ARG (exp, 2);
12524 rtx op0 = expand_normal (arg0);
12525 rtx op1 = expand_normal (arg1);
12526 rtx op2 = expand_normal (arg2);
12527 rtx pat;
12528 machine_mode mode0 = insn_data[icode].operand[0].mode;
12529 machine_mode mode1 = insn_data[icode].operand[1].mode;
12530 machine_mode mode2 = insn_data[icode].operand[2].mode;
12532 /* Invalid arguments. Bail before doing anything stoopid! */
12533 if (arg0 == error_mark_node
12534 || arg1 == error_mark_node
12535 || arg2 == error_mark_node)
12536 return const0_rtx;
12538 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
12539 op0 = copy_to_mode_reg (mode2, op0);
12540 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
12541 op1 = copy_to_mode_reg (mode0, op1);
12542 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
12543 op2 = copy_to_mode_reg (mode1, op2);
12545 pat = GEN_FCN (icode) (op1, op2, op0);
12546 if (pat)
12547 emit_insn (pat);
12548 return NULL_RTX;
12551 static rtx
12552 paired_expand_stv_builtin (enum insn_code icode, tree exp)
12554 tree arg0 = CALL_EXPR_ARG (exp, 0);
12555 tree arg1 = CALL_EXPR_ARG (exp, 1);
12556 tree arg2 = CALL_EXPR_ARG (exp, 2);
12557 rtx op0 = expand_normal (arg0);
12558 rtx op1 = expand_normal (arg1);
12559 rtx op2 = expand_normal (arg2);
12560 rtx pat, addr;
12561 machine_mode tmode = insn_data[icode].operand[0].mode;
12562 machine_mode mode1 = Pmode;
12563 machine_mode mode2 = Pmode;
12565 /* Invalid arguments. Bail before doing anything stoopid! */
12566 if (arg0 == error_mark_node
12567 || arg1 == error_mark_node
12568 || arg2 == error_mark_node)
12569 return const0_rtx;
12571 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
12572 op0 = copy_to_mode_reg (tmode, op0);
12574 op2 = copy_to_mode_reg (mode2, op2);
12576 if (op1 == const0_rtx)
12578 addr = gen_rtx_MEM (tmode, op2);
12580 else
12582 op1 = copy_to_mode_reg (mode1, op1);
12583 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
12586 pat = GEN_FCN (icode) (addr, op0);
12587 if (pat)
12588 emit_insn (pat);
12589 return NULL_RTX;
12592 static rtx
12593 altivec_expand_stv_builtin (enum insn_code icode, tree exp)
12595 tree arg0 = CALL_EXPR_ARG (exp, 0);
12596 tree arg1 = CALL_EXPR_ARG (exp, 1);
12597 tree arg2 = CALL_EXPR_ARG (exp, 2);
12598 rtx op0 = expand_normal (arg0);
12599 rtx op1 = expand_normal (arg1);
12600 rtx op2 = expand_normal (arg2);
12601 rtx pat, addr;
12602 machine_mode tmode = insn_data[icode].operand[0].mode;
12603 machine_mode smode = insn_data[icode].operand[1].mode;
12604 machine_mode mode1 = Pmode;
12605 machine_mode mode2 = Pmode;
12607 /* Invalid arguments. Bail before doing anything stoopid! */
12608 if (arg0 == error_mark_node
12609 || arg1 == error_mark_node
12610 || arg2 == error_mark_node)
12611 return const0_rtx;
12613 if (! (*insn_data[icode].operand[1].predicate) (op0, smode))
12614 op0 = copy_to_mode_reg (smode, op0);
12616 op2 = copy_to_mode_reg (mode2, op2);
12618 if (op1 == const0_rtx)
12620 addr = gen_rtx_MEM (tmode, op2);
12622 else
12624 op1 = copy_to_mode_reg (mode1, op1);
12625 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
12628 pat = GEN_FCN (icode) (addr, op0);
12629 if (pat)
12630 emit_insn (pat);
12631 return NULL_RTX;
12634 /* Return the appropriate SPR number associated with the given builtin. */
12635 static inline HOST_WIDE_INT
12636 htm_spr_num (enum rs6000_builtins code)
12638 if (code == HTM_BUILTIN_GET_TFHAR
12639 || code == HTM_BUILTIN_SET_TFHAR)
12640 return TFHAR_SPR;
12641 else if (code == HTM_BUILTIN_GET_TFIAR
12642 || code == HTM_BUILTIN_SET_TFIAR)
12643 return TFIAR_SPR;
12644 else if (code == HTM_BUILTIN_GET_TEXASR
12645 || code == HTM_BUILTIN_SET_TEXASR)
12646 return TEXASR_SPR;
12647 gcc_assert (code == HTM_BUILTIN_GET_TEXASRU
12648 || code == HTM_BUILTIN_SET_TEXASRU);
12649 return TEXASRU_SPR;
12652 /* Return the appropriate SPR regno associated with the given builtin. */
12653 static inline HOST_WIDE_INT
12654 htm_spr_regno (enum rs6000_builtins code)
12656 if (code == HTM_BUILTIN_GET_TFHAR
12657 || code == HTM_BUILTIN_SET_TFHAR)
12658 return TFHAR_REGNO;
12659 else if (code == HTM_BUILTIN_GET_TFIAR
12660 || code == HTM_BUILTIN_SET_TFIAR)
12661 return TFIAR_REGNO;
12662 gcc_assert (code == HTM_BUILTIN_GET_TEXASR
12663 || code == HTM_BUILTIN_SET_TEXASR
12664 || code == HTM_BUILTIN_GET_TEXASRU
12665 || code == HTM_BUILTIN_SET_TEXASRU);
12666 return TEXASR_REGNO;
12669 /* Return the correct ICODE value depending on whether we are
12670 setting or reading the HTM SPRs. */
12671 static inline enum insn_code
12672 rs6000_htm_spr_icode (bool nonvoid)
12674 if (nonvoid)
12675 return (TARGET_POWERPC64) ? CODE_FOR_htm_mfspr_di : CODE_FOR_htm_mfspr_si;
12676 else
12677 return (TARGET_POWERPC64) ? CODE_FOR_htm_mtspr_di : CODE_FOR_htm_mtspr_si;
12680 /* Expand the HTM builtin in EXP and store the result in TARGET.
12681 Store true in *EXPANDEDP if we found a builtin to expand. */
12682 static rtx
12683 htm_expand_builtin (tree exp, rtx target, bool * expandedp)
12685 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
12686 bool nonvoid = TREE_TYPE (TREE_TYPE (fndecl)) != void_type_node;
12687 enum rs6000_builtins fcode = (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl);
12688 const struct builtin_description *d;
12689 size_t i;
12691 *expandedp = true;
12693 if (!TARGET_POWERPC64
12694 && (fcode == HTM_BUILTIN_TABORTDC
12695 || fcode == HTM_BUILTIN_TABORTDCI))
12697 size_t uns_fcode = (size_t)fcode;
12698 const char *name = rs6000_builtin_info[uns_fcode].name;
12699 error ("builtin %s is only valid in 64-bit mode", name);
12700 return const0_rtx;
12703 /* Expand the HTM builtins. */
12704 d = bdesc_htm;
12705 for (i = 0; i < ARRAY_SIZE (bdesc_htm); i++, d++)
12706 if (d->code == fcode)
12708 rtx op[MAX_HTM_OPERANDS], pat;
12709 int nopnds = 0;
12710 tree arg;
12711 call_expr_arg_iterator iter;
12712 unsigned attr = rs6000_builtin_info[fcode].attr;
12713 enum insn_code icode = d->icode;
12714 const struct insn_operand_data *insn_op;
12715 bool uses_spr = (attr & RS6000_BTC_SPR);
12716 rtx cr = NULL_RTX;
12718 if (uses_spr)
12719 icode = rs6000_htm_spr_icode (nonvoid);
12720 insn_op = &insn_data[icode].operand[0];
12722 if (nonvoid)
12724 machine_mode tmode = (uses_spr) ? insn_op->mode : SImode;
12725 if (!target
12726 || GET_MODE (target) != tmode
12727 || (uses_spr && !(*insn_op->predicate) (target, tmode)))
12728 target = gen_reg_rtx (tmode);
12729 if (uses_spr)
12730 op[nopnds++] = target;
12733 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp)
12735 if (arg == error_mark_node || nopnds >= MAX_HTM_OPERANDS)
12736 return const0_rtx;
12738 insn_op = &insn_data[icode].operand[nopnds];
12740 op[nopnds] = expand_normal (arg);
12742 if (!(*insn_op->predicate) (op[nopnds], insn_op->mode))
12744 if (!strcmp (insn_op->constraint, "n"))
12746 int arg_num = (nonvoid) ? nopnds : nopnds + 1;
12747 if (!CONST_INT_P (op[nopnds]))
12748 error ("argument %d must be an unsigned literal", arg_num);
12749 else
12750 error ("argument %d is an unsigned literal that is "
12751 "out of range", arg_num);
12752 return const0_rtx;
12754 op[nopnds] = copy_to_mode_reg (insn_op->mode, op[nopnds]);
12757 nopnds++;
12760 /* Handle the builtins for extended mnemonics. These accept
12761 no arguments, but map to builtins that take arguments. */
12762 switch (fcode)
12764 case HTM_BUILTIN_TENDALL: /* Alias for: tend. 1 */
12765 case HTM_BUILTIN_TRESUME: /* Alias for: tsr. 1 */
12766 op[nopnds++] = GEN_INT (1);
12767 #ifdef ENABLE_CHECKING
12768 attr |= RS6000_BTC_UNARY;
12769 #endif
12770 break;
12771 case HTM_BUILTIN_TSUSPEND: /* Alias for: tsr. 0 */
12772 op[nopnds++] = GEN_INT (0);
12773 #ifdef ENABLE_CHECKING
12774 attr |= RS6000_BTC_UNARY;
12775 #endif
12776 break;
12777 default:
12778 break;
12781 /* If this builtin accesses SPRs, then pass in the appropriate
12782 SPR number and SPR regno as the last two operands. */
12783 if (uses_spr)
12785 machine_mode mode = (TARGET_POWERPC64) ? DImode : SImode;
12786 op[nopnds++] = gen_rtx_CONST_INT (mode, htm_spr_num (fcode));
12787 op[nopnds++] = gen_rtx_REG (mode, htm_spr_regno (fcode));
12789 /* If this builtin accesses a CR, then pass in a scratch
12790 CR as the last operand. */
12791 else if (attr & RS6000_BTC_CR)
12792 { cr = gen_reg_rtx (CCmode);
12793 op[nopnds++] = cr;
12796 #ifdef ENABLE_CHECKING
12797 int expected_nopnds = 0;
12798 if ((attr & RS6000_BTC_TYPE_MASK) == RS6000_BTC_UNARY)
12799 expected_nopnds = 1;
12800 else if ((attr & RS6000_BTC_TYPE_MASK) == RS6000_BTC_BINARY)
12801 expected_nopnds = 2;
12802 else if ((attr & RS6000_BTC_TYPE_MASK) == RS6000_BTC_TERNARY)
12803 expected_nopnds = 3;
12804 if (!(attr & RS6000_BTC_VOID))
12805 expected_nopnds += 1;
12806 if (uses_spr)
12807 expected_nopnds += 2;
12809 gcc_assert (nopnds == expected_nopnds && nopnds <= MAX_HTM_OPERANDS);
12810 #endif
12812 switch (nopnds)
12814 case 1:
12815 pat = GEN_FCN (icode) (op[0]);
12816 break;
12817 case 2:
12818 pat = GEN_FCN (icode) (op[0], op[1]);
12819 break;
12820 case 3:
12821 pat = GEN_FCN (icode) (op[0], op[1], op[2]);
12822 break;
12823 case 4:
12824 pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]);
12825 break;
12826 default:
12827 gcc_unreachable ();
12829 if (!pat)
12830 return NULL_RTX;
12831 emit_insn (pat);
12833 if (attr & RS6000_BTC_CR)
12835 if (fcode == HTM_BUILTIN_TBEGIN)
12837 /* Emit code to set TARGET to true or false depending on
12838 whether the tbegin. instruction successfully or failed
12839 to start a transaction. We do this by placing the 1's
12840 complement of CR's EQ bit into TARGET. */
12841 rtx scratch = gen_reg_rtx (SImode);
12842 emit_insn (gen_rtx_SET (scratch,
12843 gen_rtx_EQ (SImode, cr,
12844 const0_rtx)));
12845 emit_insn (gen_rtx_SET (target,
12846 gen_rtx_XOR (SImode, scratch,
12847 GEN_INT (1))));
12849 else
12851 /* Emit code to copy the 4-bit condition register field
12852 CR into the least significant end of register TARGET. */
12853 rtx scratch1 = gen_reg_rtx (SImode);
12854 rtx scratch2 = gen_reg_rtx (SImode);
12855 rtx subreg = simplify_gen_subreg (CCmode, scratch1, SImode, 0);
12856 emit_insn (gen_movcc (subreg, cr));
12857 emit_insn (gen_lshrsi3 (scratch2, scratch1, GEN_INT (28)));
12858 emit_insn (gen_andsi3 (target, scratch2, GEN_INT (0xf)));
12862 if (nonvoid)
12863 return target;
12864 return const0_rtx;
12867 *expandedp = false;
12868 return NULL_RTX;
12871 static rtx
12872 rs6000_expand_ternop_builtin (enum insn_code icode, tree exp, rtx target)
12874 rtx pat;
12875 tree arg0 = CALL_EXPR_ARG (exp, 0);
12876 tree arg1 = CALL_EXPR_ARG (exp, 1);
12877 tree arg2 = CALL_EXPR_ARG (exp, 2);
12878 rtx op0 = expand_normal (arg0);
12879 rtx op1 = expand_normal (arg1);
12880 rtx op2 = expand_normal (arg2);
12881 machine_mode tmode = insn_data[icode].operand[0].mode;
12882 machine_mode mode0 = insn_data[icode].operand[1].mode;
12883 machine_mode mode1 = insn_data[icode].operand[2].mode;
12884 machine_mode mode2 = insn_data[icode].operand[3].mode;
12886 if (icode == CODE_FOR_nothing)
12887 /* Builtin not supported on this processor. */
12888 return 0;
12890 /* If we got invalid arguments bail out before generating bad rtl. */
12891 if (arg0 == error_mark_node
12892 || arg1 == error_mark_node
12893 || arg2 == error_mark_node)
12894 return const0_rtx;
12896 /* Check and prepare argument depending on the instruction code.
12898 Note that a switch statement instead of the sequence of tests
12899 would be incorrect as many of the CODE_FOR values could be
12900 CODE_FOR_nothing and that would yield multiple alternatives
12901 with identical values. We'd never reach here at runtime in
12902 this case. */
12903 if (icode == CODE_FOR_altivec_vsldoi_v4sf
12904 || icode == CODE_FOR_altivec_vsldoi_v4si
12905 || icode == CODE_FOR_altivec_vsldoi_v8hi
12906 || icode == CODE_FOR_altivec_vsldoi_v16qi)
12908 /* Only allow 4-bit unsigned literals. */
12909 STRIP_NOPS (arg2);
12910 if (TREE_CODE (arg2) != INTEGER_CST
12911 || TREE_INT_CST_LOW (arg2) & ~0xf)
12913 error ("argument 3 must be a 4-bit unsigned literal");
12914 return const0_rtx;
12917 else if (icode == CODE_FOR_vsx_xxpermdi_v2df
12918 || icode == CODE_FOR_vsx_xxpermdi_v2di
12919 || icode == CODE_FOR_vsx_xxsldwi_v16qi
12920 || icode == CODE_FOR_vsx_xxsldwi_v8hi
12921 || icode == CODE_FOR_vsx_xxsldwi_v4si
12922 || icode == CODE_FOR_vsx_xxsldwi_v4sf
12923 || icode == CODE_FOR_vsx_xxsldwi_v2di
12924 || icode == CODE_FOR_vsx_xxsldwi_v2df)
12926 /* Only allow 2-bit unsigned literals. */
12927 STRIP_NOPS (arg2);
12928 if (TREE_CODE (arg2) != INTEGER_CST
12929 || TREE_INT_CST_LOW (arg2) & ~0x3)
12931 error ("argument 3 must be a 2-bit unsigned literal");
12932 return const0_rtx;
12935 else if (icode == CODE_FOR_vsx_set_v2df
12936 || icode == CODE_FOR_vsx_set_v2di
12937 || icode == CODE_FOR_bcdadd
12938 || icode == CODE_FOR_bcdadd_lt
12939 || icode == CODE_FOR_bcdadd_eq
12940 || icode == CODE_FOR_bcdadd_gt
12941 || icode == CODE_FOR_bcdsub
12942 || icode == CODE_FOR_bcdsub_lt
12943 || icode == CODE_FOR_bcdsub_eq
12944 || icode == CODE_FOR_bcdsub_gt)
12946 /* Only allow 1-bit unsigned literals. */
12947 STRIP_NOPS (arg2);
12948 if (TREE_CODE (arg2) != INTEGER_CST
12949 || TREE_INT_CST_LOW (arg2) & ~0x1)
12951 error ("argument 3 must be a 1-bit unsigned literal");
12952 return const0_rtx;
12955 else if (icode == CODE_FOR_dfp_ddedpd_dd
12956 || icode == CODE_FOR_dfp_ddedpd_td)
12958 /* Only allow 2-bit unsigned literals where the value is 0 or 2. */
12959 STRIP_NOPS (arg0);
12960 if (TREE_CODE (arg0) != INTEGER_CST
12961 || TREE_INT_CST_LOW (arg2) & ~0x3)
12963 error ("argument 1 must be 0 or 2");
12964 return const0_rtx;
12967 else if (icode == CODE_FOR_dfp_denbcd_dd
12968 || icode == CODE_FOR_dfp_denbcd_td)
12970 /* Only allow 1-bit unsigned literals. */
12971 STRIP_NOPS (arg0);
12972 if (TREE_CODE (arg0) != INTEGER_CST
12973 || TREE_INT_CST_LOW (arg0) & ~0x1)
12975 error ("argument 1 must be a 1-bit unsigned literal");
12976 return const0_rtx;
12979 else if (icode == CODE_FOR_dfp_dscli_dd
12980 || icode == CODE_FOR_dfp_dscli_td
12981 || icode == CODE_FOR_dfp_dscri_dd
12982 || icode == CODE_FOR_dfp_dscri_td)
12984 /* Only allow 6-bit unsigned literals. */
12985 STRIP_NOPS (arg1);
12986 if (TREE_CODE (arg1) != INTEGER_CST
12987 || TREE_INT_CST_LOW (arg1) & ~0x3f)
12989 error ("argument 2 must be a 6-bit unsigned literal");
12990 return const0_rtx;
12993 else if (icode == CODE_FOR_crypto_vshasigmaw
12994 || icode == CODE_FOR_crypto_vshasigmad)
12996 /* Check whether the 2nd and 3rd arguments are integer constants and in
12997 range and prepare arguments. */
12998 STRIP_NOPS (arg1);
12999 if (TREE_CODE (arg1) != INTEGER_CST || wi::geu_p (arg1, 2))
13001 error ("argument 2 must be 0 or 1");
13002 return const0_rtx;
13005 STRIP_NOPS (arg2);
13006 if (TREE_CODE (arg2) != INTEGER_CST || wi::geu_p (arg1, 16))
13008 error ("argument 3 must be in the range 0..15");
13009 return const0_rtx;
13013 if (target == 0
13014 || GET_MODE (target) != tmode
13015 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
13016 target = gen_reg_rtx (tmode);
13018 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
13019 op0 = copy_to_mode_reg (mode0, op0);
13020 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
13021 op1 = copy_to_mode_reg (mode1, op1);
13022 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
13023 op2 = copy_to_mode_reg (mode2, op2);
13025 if (TARGET_PAIRED_FLOAT && icode == CODE_FOR_selv2sf4)
13026 pat = GEN_FCN (icode) (target, op0, op1, op2, CONST0_RTX (SFmode));
13027 else
13028 pat = GEN_FCN (icode) (target, op0, op1, op2);
13029 if (! pat)
13030 return 0;
13031 emit_insn (pat);
13033 return target;
13036 /* Expand the lvx builtins. */
13037 static rtx
13038 altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
13040 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
13041 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
13042 tree arg0;
13043 machine_mode tmode, mode0;
13044 rtx pat, op0;
13045 enum insn_code icode;
13047 switch (fcode)
13049 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
13050 icode = CODE_FOR_vector_altivec_load_v16qi;
13051 break;
13052 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
13053 icode = CODE_FOR_vector_altivec_load_v8hi;
13054 break;
13055 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
13056 icode = CODE_FOR_vector_altivec_load_v4si;
13057 break;
13058 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
13059 icode = CODE_FOR_vector_altivec_load_v4sf;
13060 break;
13061 case ALTIVEC_BUILTIN_LD_INTERNAL_2df:
13062 icode = CODE_FOR_vector_altivec_load_v2df;
13063 break;
13064 case ALTIVEC_BUILTIN_LD_INTERNAL_2di:
13065 icode = CODE_FOR_vector_altivec_load_v2di;
13066 case ALTIVEC_BUILTIN_LD_INTERNAL_1ti:
13067 icode = CODE_FOR_vector_altivec_load_v1ti;
13068 break;
13069 default:
13070 *expandedp = false;
13071 return NULL_RTX;
13074 *expandedp = true;
13076 arg0 = CALL_EXPR_ARG (exp, 0);
13077 op0 = expand_normal (arg0);
13078 tmode = insn_data[icode].operand[0].mode;
13079 mode0 = insn_data[icode].operand[1].mode;
13081 if (target == 0
13082 || GET_MODE (target) != tmode
13083 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
13084 target = gen_reg_rtx (tmode);
13086 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
13087 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
13089 pat = GEN_FCN (icode) (target, op0);
13090 if (! pat)
13091 return 0;
13092 emit_insn (pat);
13093 return target;
13096 /* Expand the stvx builtins. */
13097 static rtx
13098 altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
13099 bool *expandedp)
13101 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
13102 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
13103 tree arg0, arg1;
13104 machine_mode mode0, mode1;
13105 rtx pat, op0, op1;
13106 enum insn_code icode;
13108 switch (fcode)
13110 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
13111 icode = CODE_FOR_vector_altivec_store_v16qi;
13112 break;
13113 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
13114 icode = CODE_FOR_vector_altivec_store_v8hi;
13115 break;
13116 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
13117 icode = CODE_FOR_vector_altivec_store_v4si;
13118 break;
13119 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
13120 icode = CODE_FOR_vector_altivec_store_v4sf;
13121 break;
13122 case ALTIVEC_BUILTIN_ST_INTERNAL_2df:
13123 icode = CODE_FOR_vector_altivec_store_v2df;
13124 break;
13125 case ALTIVEC_BUILTIN_ST_INTERNAL_2di:
13126 icode = CODE_FOR_vector_altivec_store_v2di;
13127 case ALTIVEC_BUILTIN_ST_INTERNAL_1ti:
13128 icode = CODE_FOR_vector_altivec_store_v1ti;
13129 break;
13130 default:
13131 *expandedp = false;
13132 return NULL_RTX;
13135 arg0 = CALL_EXPR_ARG (exp, 0);
13136 arg1 = CALL_EXPR_ARG (exp, 1);
13137 op0 = expand_normal (arg0);
13138 op1 = expand_normal (arg1);
13139 mode0 = insn_data[icode].operand[0].mode;
13140 mode1 = insn_data[icode].operand[1].mode;
13142 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
13143 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
13144 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
13145 op1 = copy_to_mode_reg (mode1, op1);
13147 pat = GEN_FCN (icode) (op0, op1);
13148 if (pat)
13149 emit_insn (pat);
13151 *expandedp = true;
13152 return NULL_RTX;
13155 /* Expand the dst builtins. */
13156 static rtx
13157 altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
13158 bool *expandedp)
13160 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
13161 enum rs6000_builtins fcode = (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl);
13162 tree arg0, arg1, arg2;
13163 machine_mode mode0, mode1;
13164 rtx pat, op0, op1, op2;
13165 const struct builtin_description *d;
13166 size_t i;
13168 *expandedp = false;
13170 /* Handle DST variants. */
13171 d = bdesc_dst;
13172 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
13173 if (d->code == fcode)
13175 arg0 = CALL_EXPR_ARG (exp, 0);
13176 arg1 = CALL_EXPR_ARG (exp, 1);
13177 arg2 = CALL_EXPR_ARG (exp, 2);
13178 op0 = expand_normal (arg0);
13179 op1 = expand_normal (arg1);
13180 op2 = expand_normal (arg2);
13181 mode0 = insn_data[d->icode].operand[0].mode;
13182 mode1 = insn_data[d->icode].operand[1].mode;
13184 /* Invalid arguments, bail out before generating bad rtl. */
13185 if (arg0 == error_mark_node
13186 || arg1 == error_mark_node
13187 || arg2 == error_mark_node)
13188 return const0_rtx;
13190 *expandedp = true;
13191 STRIP_NOPS (arg2);
13192 if (TREE_CODE (arg2) != INTEGER_CST
13193 || TREE_INT_CST_LOW (arg2) & ~0x3)
13195 error ("argument to %qs must be a 2-bit unsigned literal", d->name);
13196 return const0_rtx;
13199 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
13200 op0 = copy_to_mode_reg (Pmode, op0);
13201 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
13202 op1 = copy_to_mode_reg (mode1, op1);
13204 pat = GEN_FCN (d->icode) (op0, op1, op2);
13205 if (pat != 0)
13206 emit_insn (pat);
13208 return NULL_RTX;
13211 return NULL_RTX;
13214 /* Expand vec_init builtin. */
13215 static rtx
13216 altivec_expand_vec_init_builtin (tree type, tree exp, rtx target)
13218 machine_mode tmode = TYPE_MODE (type);
13219 machine_mode inner_mode = GET_MODE_INNER (tmode);
13220 int i, n_elt = GET_MODE_NUNITS (tmode);
13222 gcc_assert (VECTOR_MODE_P (tmode));
13223 gcc_assert (n_elt == call_expr_nargs (exp));
13225 if (!target || !register_operand (target, tmode))
13226 target = gen_reg_rtx (tmode);
13228 /* If we have a vector compromised of a single element, such as V1TImode, do
13229 the initialization directly. */
13230 if (n_elt == 1 && GET_MODE_SIZE (tmode) == GET_MODE_SIZE (inner_mode))
13232 rtx x = expand_normal (CALL_EXPR_ARG (exp, 0));
13233 emit_move_insn (target, gen_lowpart (tmode, x));
13235 else
13237 rtvec v = rtvec_alloc (n_elt);
13239 for (i = 0; i < n_elt; ++i)
13241 rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
13242 RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
13245 rs6000_expand_vector_init (target, gen_rtx_PARALLEL (tmode, v));
13248 return target;
13251 /* Return the integer constant in ARG. Constrain it to be in the range
13252 of the subparts of VEC_TYPE; issue an error if not. */
13254 static int
13255 get_element_number (tree vec_type, tree arg)
13257 unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
13259 if (!tree_fits_uhwi_p (arg)
13260 || (elt = tree_to_uhwi (arg), elt > max))
13262 error ("selector must be an integer constant in the range 0..%wi", max);
13263 return 0;
13266 return elt;
13269 /* Expand vec_set builtin. */
13270 static rtx
13271 altivec_expand_vec_set_builtin (tree exp)
13273 machine_mode tmode, mode1;
13274 tree arg0, arg1, arg2;
13275 int elt;
13276 rtx op0, op1;
13278 arg0 = CALL_EXPR_ARG (exp, 0);
13279 arg1 = CALL_EXPR_ARG (exp, 1);
13280 arg2 = CALL_EXPR_ARG (exp, 2);
13282 tmode = TYPE_MODE (TREE_TYPE (arg0));
13283 mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
13284 gcc_assert (VECTOR_MODE_P (tmode));
13286 op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
13287 op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
13288 elt = get_element_number (TREE_TYPE (arg0), arg2);
13290 if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
13291 op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
13293 op0 = force_reg (tmode, op0);
13294 op1 = force_reg (mode1, op1);
13296 rs6000_expand_vector_set (op0, op1, elt);
13298 return op0;
13301 /* Expand vec_ext builtin. */
13302 static rtx
13303 altivec_expand_vec_ext_builtin (tree exp, rtx target)
13305 machine_mode tmode, mode0;
13306 tree arg0, arg1;
13307 int elt;
13308 rtx op0;
13310 arg0 = CALL_EXPR_ARG (exp, 0);
13311 arg1 = CALL_EXPR_ARG (exp, 1);
13313 op0 = expand_normal (arg0);
13314 elt = get_element_number (TREE_TYPE (arg0), arg1);
13316 tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
13317 mode0 = TYPE_MODE (TREE_TYPE (arg0));
13318 gcc_assert (VECTOR_MODE_P (mode0));
13320 op0 = force_reg (mode0, op0);
13322 if (optimize || !target || !register_operand (target, tmode))
13323 target = gen_reg_rtx (tmode);
13325 rs6000_expand_vector_extract (target, op0, elt);
13327 return target;
13330 /* Expand the builtin in EXP and store the result in TARGET. Store
13331 true in *EXPANDEDP if we found a builtin to expand. */
13332 static rtx
13333 altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
13335 const struct builtin_description *d;
13336 size_t i;
13337 enum insn_code icode;
13338 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
13339 tree arg0;
13340 rtx op0, pat;
13341 machine_mode tmode, mode0;
13342 enum rs6000_builtins fcode
13343 = (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl);
13345 if (rs6000_overloaded_builtin_p (fcode))
13347 *expandedp = true;
13348 error ("unresolved overload for Altivec builtin %qF", fndecl);
13350 /* Given it is invalid, just generate a normal call. */
13351 return expand_call (exp, target, false);
13354 target = altivec_expand_ld_builtin (exp, target, expandedp);
13355 if (*expandedp)
13356 return target;
13358 target = altivec_expand_st_builtin (exp, target, expandedp);
13359 if (*expandedp)
13360 return target;
13362 target = altivec_expand_dst_builtin (exp, target, expandedp);
13363 if (*expandedp)
13364 return target;
13366 *expandedp = true;
13368 switch (fcode)
13370 case ALTIVEC_BUILTIN_STVX_V2DF:
13371 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx_v2df, exp);
13372 case ALTIVEC_BUILTIN_STVX_V2DI:
13373 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx_v2di, exp);
13374 case ALTIVEC_BUILTIN_STVX_V4SF:
13375 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx_v4sf, exp);
13376 case ALTIVEC_BUILTIN_STVX:
13377 case ALTIVEC_BUILTIN_STVX_V4SI:
13378 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx_v4si, exp);
13379 case ALTIVEC_BUILTIN_STVX_V8HI:
13380 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx_v8hi, exp);
13381 case ALTIVEC_BUILTIN_STVX_V16QI:
13382 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx_v16qi, exp);
13383 case ALTIVEC_BUILTIN_STVEBX:
13384 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, exp);
13385 case ALTIVEC_BUILTIN_STVEHX:
13386 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, exp);
13387 case ALTIVEC_BUILTIN_STVEWX:
13388 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, exp);
13389 case ALTIVEC_BUILTIN_STVXL_V2DF:
13390 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl_v2df, exp);
13391 case ALTIVEC_BUILTIN_STVXL_V2DI:
13392 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl_v2di, exp);
13393 case ALTIVEC_BUILTIN_STVXL_V4SF:
13394 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl_v4sf, exp);
13395 case ALTIVEC_BUILTIN_STVXL:
13396 case ALTIVEC_BUILTIN_STVXL_V4SI:
13397 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl_v4si, exp);
13398 case ALTIVEC_BUILTIN_STVXL_V8HI:
13399 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl_v8hi, exp);
13400 case ALTIVEC_BUILTIN_STVXL_V16QI:
13401 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl_v16qi, exp);
13403 case ALTIVEC_BUILTIN_STVLX:
13404 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvlx, exp);
13405 case ALTIVEC_BUILTIN_STVLXL:
13406 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvlxl, exp);
13407 case ALTIVEC_BUILTIN_STVRX:
13408 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvrx, exp);
13409 case ALTIVEC_BUILTIN_STVRXL:
13410 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvrxl, exp);
13412 case VSX_BUILTIN_STXVD2X_V1TI:
13413 return altivec_expand_stv_builtin (CODE_FOR_vsx_store_v1ti, exp);
13414 case VSX_BUILTIN_STXVD2X_V2DF:
13415 return altivec_expand_stv_builtin (CODE_FOR_vsx_store_v2df, exp);
13416 case VSX_BUILTIN_STXVD2X_V2DI:
13417 return altivec_expand_stv_builtin (CODE_FOR_vsx_store_v2di, exp);
13418 case VSX_BUILTIN_STXVW4X_V4SF:
13419 return altivec_expand_stv_builtin (CODE_FOR_vsx_store_v4sf, exp);
13420 case VSX_BUILTIN_STXVW4X_V4SI:
13421 return altivec_expand_stv_builtin (CODE_FOR_vsx_store_v4si, exp);
13422 case VSX_BUILTIN_STXVW4X_V8HI:
13423 return altivec_expand_stv_builtin (CODE_FOR_vsx_store_v8hi, exp);
13424 case VSX_BUILTIN_STXVW4X_V16QI:
13425 return altivec_expand_stv_builtin (CODE_FOR_vsx_store_v16qi, exp);
13427 case ALTIVEC_BUILTIN_MFVSCR:
13428 icode = CODE_FOR_altivec_mfvscr;
13429 tmode = insn_data[icode].operand[0].mode;
13431 if (target == 0
13432 || GET_MODE (target) != tmode
13433 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
13434 target = gen_reg_rtx (tmode);
13436 pat = GEN_FCN (icode) (target);
13437 if (! pat)
13438 return 0;
13439 emit_insn (pat);
13440 return target;
13442 case ALTIVEC_BUILTIN_MTVSCR:
13443 icode = CODE_FOR_altivec_mtvscr;
13444 arg0 = CALL_EXPR_ARG (exp, 0);
13445 op0 = expand_normal (arg0);
13446 mode0 = insn_data[icode].operand[0].mode;
13448 /* If we got invalid arguments bail out before generating bad rtl. */
13449 if (arg0 == error_mark_node)
13450 return const0_rtx;
13452 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
13453 op0 = copy_to_mode_reg (mode0, op0);
13455 pat = GEN_FCN (icode) (op0);
13456 if (pat)
13457 emit_insn (pat);
13458 return NULL_RTX;
13460 case ALTIVEC_BUILTIN_DSSALL:
13461 emit_insn (gen_altivec_dssall ());
13462 return NULL_RTX;
13464 case ALTIVEC_BUILTIN_DSS:
13465 icode = CODE_FOR_altivec_dss;
13466 arg0 = CALL_EXPR_ARG (exp, 0);
13467 STRIP_NOPS (arg0);
13468 op0 = expand_normal (arg0);
13469 mode0 = insn_data[icode].operand[0].mode;
13471 /* If we got invalid arguments bail out before generating bad rtl. */
13472 if (arg0 == error_mark_node)
13473 return const0_rtx;
13475 if (TREE_CODE (arg0) != INTEGER_CST
13476 || TREE_INT_CST_LOW (arg0) & ~0x3)
13478 error ("argument to dss must be a 2-bit unsigned literal");
13479 return const0_rtx;
13482 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
13483 op0 = copy_to_mode_reg (mode0, op0);
13485 emit_insn (gen_altivec_dss (op0));
13486 return NULL_RTX;
13488 case ALTIVEC_BUILTIN_VEC_INIT_V4SI:
13489 case ALTIVEC_BUILTIN_VEC_INIT_V8HI:
13490 case ALTIVEC_BUILTIN_VEC_INIT_V16QI:
13491 case ALTIVEC_BUILTIN_VEC_INIT_V4SF:
13492 case VSX_BUILTIN_VEC_INIT_V2DF:
13493 case VSX_BUILTIN_VEC_INIT_V2DI:
13494 case VSX_BUILTIN_VEC_INIT_V1TI:
13495 return altivec_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
13497 case ALTIVEC_BUILTIN_VEC_SET_V4SI:
13498 case ALTIVEC_BUILTIN_VEC_SET_V8HI:
13499 case ALTIVEC_BUILTIN_VEC_SET_V16QI:
13500 case ALTIVEC_BUILTIN_VEC_SET_V4SF:
13501 case VSX_BUILTIN_VEC_SET_V2DF:
13502 case VSX_BUILTIN_VEC_SET_V2DI:
13503 case VSX_BUILTIN_VEC_SET_V1TI:
13504 return altivec_expand_vec_set_builtin (exp);
13506 case ALTIVEC_BUILTIN_VEC_EXT_V4SI:
13507 case ALTIVEC_BUILTIN_VEC_EXT_V8HI:
13508 case ALTIVEC_BUILTIN_VEC_EXT_V16QI:
13509 case ALTIVEC_BUILTIN_VEC_EXT_V4SF:
13510 case VSX_BUILTIN_VEC_EXT_V2DF:
13511 case VSX_BUILTIN_VEC_EXT_V2DI:
13512 case VSX_BUILTIN_VEC_EXT_V1TI:
13513 return altivec_expand_vec_ext_builtin (exp, target);
13515 default:
13516 break;
13517 /* Fall through. */
13520 /* Expand abs* operations. */
13521 d = bdesc_abs;
13522 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
13523 if (d->code == fcode)
13524 return altivec_expand_abs_builtin (d->icode, exp, target);
13526 /* Expand the AltiVec predicates. */
13527 d = bdesc_altivec_preds;
13528 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, d++)
13529 if (d->code == fcode)
13530 return altivec_expand_predicate_builtin (d->icode, exp, target);
13532 /* LV* are funky. We initialized them differently. */
13533 switch (fcode)
13535 case ALTIVEC_BUILTIN_LVSL:
13536 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
13537 exp, target, false);
13538 case ALTIVEC_BUILTIN_LVSR:
13539 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
13540 exp, target, false);
13541 case ALTIVEC_BUILTIN_LVEBX:
13542 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
13543 exp, target, false);
13544 case ALTIVEC_BUILTIN_LVEHX:
13545 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
13546 exp, target, false);
13547 case ALTIVEC_BUILTIN_LVEWX:
13548 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
13549 exp, target, false);
13550 case ALTIVEC_BUILTIN_LVXL_V2DF:
13551 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl_v2df,
13552 exp, target, false);
13553 case ALTIVEC_BUILTIN_LVXL_V2DI:
13554 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl_v2di,
13555 exp, target, false);
13556 case ALTIVEC_BUILTIN_LVXL_V4SF:
13557 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl_v4sf,
13558 exp, target, false);
13559 case ALTIVEC_BUILTIN_LVXL:
13560 case ALTIVEC_BUILTIN_LVXL_V4SI:
13561 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl_v4si,
13562 exp, target, false);
13563 case ALTIVEC_BUILTIN_LVXL_V8HI:
13564 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl_v8hi,
13565 exp, target, false);
13566 case ALTIVEC_BUILTIN_LVXL_V16QI:
13567 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl_v16qi,
13568 exp, target, false);
13569 case ALTIVEC_BUILTIN_LVX_V2DF:
13570 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx_v2df,
13571 exp, target, false);
13572 case ALTIVEC_BUILTIN_LVX_V2DI:
13573 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx_v2di,
13574 exp, target, false);
13575 case ALTIVEC_BUILTIN_LVX_V4SF:
13576 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx_v4sf,
13577 exp, target, false);
13578 case ALTIVEC_BUILTIN_LVX:
13579 case ALTIVEC_BUILTIN_LVX_V4SI:
13580 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx_v4si,
13581 exp, target, false);
13582 case ALTIVEC_BUILTIN_LVX_V8HI:
13583 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx_v8hi,
13584 exp, target, false);
13585 case ALTIVEC_BUILTIN_LVX_V16QI:
13586 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx_v16qi,
13587 exp, target, false);
13588 case ALTIVEC_BUILTIN_LVLX:
13589 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvlx,
13590 exp, target, true);
13591 case ALTIVEC_BUILTIN_LVLXL:
13592 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvlxl,
13593 exp, target, true);
13594 case ALTIVEC_BUILTIN_LVRX:
13595 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvrx,
13596 exp, target, true);
13597 case ALTIVEC_BUILTIN_LVRXL:
13598 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvrxl,
13599 exp, target, true);
13600 case VSX_BUILTIN_LXVD2X_V1TI:
13601 return altivec_expand_lv_builtin (CODE_FOR_vsx_load_v1ti,
13602 exp, target, false);
13603 case VSX_BUILTIN_LXVD2X_V2DF:
13604 return altivec_expand_lv_builtin (CODE_FOR_vsx_load_v2df,
13605 exp, target, false);
13606 case VSX_BUILTIN_LXVD2X_V2DI:
13607 return altivec_expand_lv_builtin (CODE_FOR_vsx_load_v2di,
13608 exp, target, false);
13609 case VSX_BUILTIN_LXVW4X_V4SF:
13610 return altivec_expand_lv_builtin (CODE_FOR_vsx_load_v4sf,
13611 exp, target, false);
13612 case VSX_BUILTIN_LXVW4X_V4SI:
13613 return altivec_expand_lv_builtin (CODE_FOR_vsx_load_v4si,
13614 exp, target, false);
13615 case VSX_BUILTIN_LXVW4X_V8HI:
13616 return altivec_expand_lv_builtin (CODE_FOR_vsx_load_v8hi,
13617 exp, target, false);
13618 case VSX_BUILTIN_LXVW4X_V16QI:
13619 return altivec_expand_lv_builtin (CODE_FOR_vsx_load_v16qi,
13620 exp, target, false);
13621 break;
13622 default:
13623 break;
13624 /* Fall through. */
13627 *expandedp = false;
13628 return NULL_RTX;
13631 /* Expand the builtin in EXP and store the result in TARGET. Store
13632 true in *EXPANDEDP if we found a builtin to expand. */
13633 static rtx
13634 paired_expand_builtin (tree exp, rtx target, bool * expandedp)
13636 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
13637 enum rs6000_builtins fcode = (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl);
13638 const struct builtin_description *d;
13639 size_t i;
13641 *expandedp = true;
13643 switch (fcode)
13645 case PAIRED_BUILTIN_STX:
13646 return paired_expand_stv_builtin (CODE_FOR_paired_stx, exp);
13647 case PAIRED_BUILTIN_LX:
13648 return paired_expand_lv_builtin (CODE_FOR_paired_lx, exp, target);
13649 default:
13650 break;
13651 /* Fall through. */
13654 /* Expand the paired predicates. */
13655 d = bdesc_paired_preds;
13656 for (i = 0; i < ARRAY_SIZE (bdesc_paired_preds); i++, d++)
13657 if (d->code == fcode)
13658 return paired_expand_predicate_builtin (d->icode, exp, target);
13660 *expandedp = false;
13661 return NULL_RTX;
13664 /* Binops that need to be initialized manually, but can be expanded
13665 automagically by rs6000_expand_binop_builtin. */
13666 static const struct builtin_description bdesc_2arg_spe[] =
13668 { RS6000_BTM_SPE, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
13669 { RS6000_BTM_SPE, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
13670 { RS6000_BTM_SPE, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
13671 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
13672 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
13673 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
13674 { RS6000_BTM_SPE, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
13675 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
13676 { RS6000_BTM_SPE, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
13677 { RS6000_BTM_SPE, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
13678 { RS6000_BTM_SPE, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
13679 { RS6000_BTM_SPE, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
13680 { RS6000_BTM_SPE, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
13681 { RS6000_BTM_SPE, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
13682 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
13683 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
13684 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
13685 { RS6000_BTM_SPE, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
13686 { RS6000_BTM_SPE, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
13687 { RS6000_BTM_SPE, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
13688 { RS6000_BTM_SPE, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
13689 { RS6000_BTM_SPE, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
13692 /* Expand the builtin in EXP and store the result in TARGET. Store
13693 true in *EXPANDEDP if we found a builtin to expand.
13695 This expands the SPE builtins that are not simple unary and binary
13696 operations. */
13697 static rtx
13698 spe_expand_builtin (tree exp, rtx target, bool *expandedp)
13700 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
13701 tree arg1, arg0;
13702 enum rs6000_builtins fcode = (enum rs6000_builtins) DECL_FUNCTION_CODE (fndecl);
13703 enum insn_code icode;
13704 machine_mode tmode, mode0;
13705 rtx pat, op0;
13706 const struct builtin_description *d;
13707 size_t i;
13709 *expandedp = true;
13711 /* Syntax check for a 5-bit unsigned immediate. */
13712 switch (fcode)
13714 case SPE_BUILTIN_EVSTDD:
13715 case SPE_BUILTIN_EVSTDH:
13716 case SPE_BUILTIN_EVSTDW:
13717 case SPE_BUILTIN_EVSTWHE:
13718 case SPE_BUILTIN_EVSTWHO:
13719 case SPE_BUILTIN_EVSTWWE:
13720 case SPE_BUILTIN_EVSTWWO:
13721 arg1 = CALL_EXPR_ARG (exp, 2);
13722 if (TREE_CODE (arg1) != INTEGER_CST
13723 || TREE_INT_CST_LOW (arg1) & ~0x1f)
13725 error ("argument 2 must be a 5-bit unsigned literal");
13726 return const0_rtx;
13728 break;
13729 default:
13730 break;
13733 /* The evsplat*i instructions are not quite generic. */
13734 switch (fcode)
13736 case SPE_BUILTIN_EVSPLATFI:
13737 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
13738 exp, target);
13739 case SPE_BUILTIN_EVSPLATI:
13740 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
13741 exp, target);
13742 default:
13743 break;
13746 d = bdesc_2arg_spe;
13747 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
13748 if (d->code == fcode)
13749 return rs6000_expand_binop_builtin (d->icode, exp, target);
13751 d = bdesc_spe_predicates;
13752 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
13753 if (d->code == fcode)
13754 return spe_expand_predicate_builtin (d->icode, exp, target);
13756 d = bdesc_spe_evsel;
13757 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
13758 if (d->code == fcode)
13759 return spe_expand_evsel_builtin (d->icode, exp, target);
13761 switch (fcode)
13763 case SPE_BUILTIN_EVSTDDX:
13764 return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, exp);
13765 case SPE_BUILTIN_EVSTDHX:
13766 return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, exp);
13767 case SPE_BUILTIN_EVSTDWX:
13768 return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, exp);
13769 case SPE_BUILTIN_EVSTWHEX:
13770 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, exp);
13771 case SPE_BUILTIN_EVSTWHOX:
13772 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, exp);
13773 case SPE_BUILTIN_EVSTWWEX:
13774 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, exp);
13775 case SPE_BUILTIN_EVSTWWOX:
13776 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, exp);
13777 case SPE_BUILTIN_EVSTDD:
13778 return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, exp);
13779 case SPE_BUILTIN_EVSTDH:
13780 return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, exp);
13781 case SPE_BUILTIN_EVSTDW:
13782 return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, exp);
13783 case SPE_BUILTIN_EVSTWHE:
13784 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, exp);
13785 case SPE_BUILTIN_EVSTWHO:
13786 return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, exp);
13787 case SPE_BUILTIN_EVSTWWE:
13788 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, exp);
13789 case SPE_BUILTIN_EVSTWWO:
13790 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, exp);
13791 case SPE_BUILTIN_MFSPEFSCR:
13792 icode = CODE_FOR_spe_mfspefscr;
13793 tmode = insn_data[icode].operand[0].mode;
13795 if (target == 0
13796 || GET_MODE (target) != tmode
13797 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
13798 target = gen_reg_rtx (tmode);
13800 pat = GEN_FCN (icode) (target);
13801 if (! pat)
13802 return 0;
13803 emit_insn (pat);
13804 return target;
13805 case SPE_BUILTIN_MTSPEFSCR:
13806 icode = CODE_FOR_spe_mtspefscr;
13807 arg0 = CALL_EXPR_ARG (exp, 0);
13808 op0 = expand_normal (arg0);
13809 mode0 = insn_data[icode].operand[0].mode;
13811 if (arg0 == error_mark_node)
13812 return const0_rtx;
13814 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
13815 op0 = copy_to_mode_reg (mode0, op0);
13817 pat = GEN_FCN (icode) (op0);
13818 if (pat)
13819 emit_insn (pat);
13820 return NULL_RTX;
13821 default:
13822 break;
13825 *expandedp = false;
13826 return NULL_RTX;
13829 static rtx
13830 paired_expand_predicate_builtin (enum insn_code icode, tree exp, rtx target)
13832 rtx pat, scratch, tmp;
13833 tree form = CALL_EXPR_ARG (exp, 0);
13834 tree arg0 = CALL_EXPR_ARG (exp, 1);
13835 tree arg1 = CALL_EXPR_ARG (exp, 2);
13836 rtx op0 = expand_normal (arg0);
13837 rtx op1 = expand_normal (arg1);
13838 machine_mode mode0 = insn_data[icode].operand[1].mode;
13839 machine_mode mode1 = insn_data[icode].operand[2].mode;
13840 int form_int;
13841 enum rtx_code code;
13843 if (TREE_CODE (form) != INTEGER_CST)
13845 error ("argument 1 of __builtin_paired_predicate must be a constant");
13846 return const0_rtx;
13848 else
13849 form_int = TREE_INT_CST_LOW (form);
13851 gcc_assert (mode0 == mode1);
13853 if (arg0 == error_mark_node || arg1 == error_mark_node)
13854 return const0_rtx;
13856 if (target == 0
13857 || GET_MODE (target) != SImode
13858 || !(*insn_data[icode].operand[0].predicate) (target, SImode))
13859 target = gen_reg_rtx (SImode);
13860 if (!(*insn_data[icode].operand[1].predicate) (op0, mode0))
13861 op0 = copy_to_mode_reg (mode0, op0);
13862 if (!(*insn_data[icode].operand[2].predicate) (op1, mode1))
13863 op1 = copy_to_mode_reg (mode1, op1);
13865 scratch = gen_reg_rtx (CCFPmode);
13867 pat = GEN_FCN (icode) (scratch, op0, op1);
13868 if (!pat)
13869 return const0_rtx;
13871 emit_insn (pat);
13873 switch (form_int)
13875 /* LT bit. */
13876 case 0:
13877 code = LT;
13878 break;
13879 /* GT bit. */
13880 case 1:
13881 code = GT;
13882 break;
13883 /* EQ bit. */
13884 case 2:
13885 code = EQ;
13886 break;
13887 /* UN bit. */
13888 case 3:
13889 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
13890 return target;
13891 default:
13892 error ("argument 1 of __builtin_paired_predicate is out of range");
13893 return const0_rtx;
13896 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
13897 emit_move_insn (target, tmp);
13898 return target;
13901 static rtx
13902 spe_expand_predicate_builtin (enum insn_code icode, tree exp, rtx target)
13904 rtx pat, scratch, tmp;
13905 tree form = CALL_EXPR_ARG (exp, 0);
13906 tree arg0 = CALL_EXPR_ARG (exp, 1);
13907 tree arg1 = CALL_EXPR_ARG (exp, 2);
13908 rtx op0 = expand_normal (arg0);
13909 rtx op1 = expand_normal (arg1);
13910 machine_mode mode0 = insn_data[icode].operand[1].mode;
13911 machine_mode mode1 = insn_data[icode].operand[2].mode;
13912 int form_int;
13913 enum rtx_code code;
13915 if (TREE_CODE (form) != INTEGER_CST)
13917 error ("argument 1 of __builtin_spe_predicate must be a constant");
13918 return const0_rtx;
13920 else
13921 form_int = TREE_INT_CST_LOW (form);
13923 gcc_assert (mode0 == mode1);
13925 if (arg0 == error_mark_node || arg1 == error_mark_node)
13926 return const0_rtx;
13928 if (target == 0
13929 || GET_MODE (target) != SImode
13930 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
13931 target = gen_reg_rtx (SImode);
13933 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
13934 op0 = copy_to_mode_reg (mode0, op0);
13935 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
13936 op1 = copy_to_mode_reg (mode1, op1);
13938 scratch = gen_reg_rtx (CCmode);
13940 pat = GEN_FCN (icode) (scratch, op0, op1);
13941 if (! pat)
13942 return const0_rtx;
13943 emit_insn (pat);
13945 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
13946 _lower_. We use one compare, but look in different bits of the
13947 CR for each variant.
13949 There are 2 elements in each SPE simd type (upper/lower). The CR
13950 bits are set as follows:
13952 BIT0 | BIT 1 | BIT 2 | BIT 3
13953 U | L | (U | L) | (U & L)
13955 So, for an "all" relationship, BIT 3 would be set.
13956 For an "any" relationship, BIT 2 would be set. Etc.
13958 Following traditional nomenclature, these bits map to:
13960 BIT0 | BIT 1 | BIT 2 | BIT 3
13961 LT | GT | EQ | OV
13963 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
13966 switch (form_int)
13968 /* All variant. OV bit. */
13969 case 0:
13970 /* We need to get to the OV bit, which is the ORDERED bit. We
13971 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
13972 that's ugly and will make validate_condition_mode die.
13973 So let's just use another pattern. */
13974 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
13975 return target;
13976 /* Any variant. EQ bit. */
13977 case 1:
13978 code = EQ;
13979 break;
13980 /* Upper variant. LT bit. */
13981 case 2:
13982 code = LT;
13983 break;
13984 /* Lower variant. GT bit. */
13985 case 3:
13986 code = GT;
13987 break;
13988 default:
13989 error ("argument 1 of __builtin_spe_predicate is out of range");
13990 return const0_rtx;
13993 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
13994 emit_move_insn (target, tmp);
13996 return target;
13999 /* The evsel builtins look like this:
14001 e = __builtin_spe_evsel_OP (a, b, c, d);
14003 and work like this:
14005 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
14006 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
14009 static rtx
14010 spe_expand_evsel_builtin (enum insn_code icode, tree exp, rtx target)
14012 rtx pat, scratch;
14013 tree arg0 = CALL_EXPR_ARG (exp, 0);
14014 tree arg1 = CALL_EXPR_ARG (exp, 1);
14015 tree arg2 = CALL_EXPR_ARG (exp, 2);
14016 tree arg3 = CALL_EXPR_ARG (exp, 3);
14017 rtx op0 = expand_normal (arg0);
14018 rtx op1 = expand_normal (arg1);
14019 rtx op2 = expand_normal (arg2);
14020 rtx op3 = expand_normal (arg3);
14021 machine_mode mode0 = insn_data[icode].operand[1].mode;
14022 machine_mode mode1 = insn_data[icode].operand[2].mode;
14024 gcc_assert (mode0 == mode1);
14026 if (arg0 == error_mark_node || arg1 == error_mark_node
14027 || arg2 == error_mark_node || arg3 == error_mark_node)
14028 return const0_rtx;
14030 if (target == 0
14031 || GET_MODE (target) != mode0
14032 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
14033 target = gen_reg_rtx (mode0);
14035 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
14036 op0 = copy_to_mode_reg (mode0, op0);
14037 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
14038 op1 = copy_to_mode_reg (mode0, op1);
14039 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
14040 op2 = copy_to_mode_reg (mode0, op2);
14041 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
14042 op3 = copy_to_mode_reg (mode0, op3);
14044 /* Generate the compare. */
14045 scratch = gen_reg_rtx (CCmode);
14046 pat = GEN_FCN (icode) (scratch, op0, op1);
14047 if (! pat)
14048 return const0_rtx;
14049 emit_insn (pat);
14051 if (mode0 == V2SImode)
14052 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
14053 else
14054 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
14056 return target;
14059 /* Raise an error message for a builtin function that is called without the
14060 appropriate target options being set. */
14062 static void
14063 rs6000_invalid_builtin (enum rs6000_builtins fncode)
14065 size_t uns_fncode = (size_t)fncode;
14066 const char *name = rs6000_builtin_info[uns_fncode].name;
14067 HOST_WIDE_INT fnmask = rs6000_builtin_info[uns_fncode].mask;
14069 gcc_assert (name != NULL);
14070 if ((fnmask & RS6000_BTM_CELL) != 0)
14071 error ("Builtin function %s is only valid for the cell processor", name);
14072 else if ((fnmask & RS6000_BTM_VSX) != 0)
14073 error ("Builtin function %s requires the -mvsx option", name);
14074 else if ((fnmask & RS6000_BTM_HTM) != 0)
14075 error ("Builtin function %s requires the -mhtm option", name);
14076 else if ((fnmask & RS6000_BTM_ALTIVEC) != 0)
14077 error ("Builtin function %s requires the -maltivec option", name);
14078 else if ((fnmask & RS6000_BTM_PAIRED) != 0)
14079 error ("Builtin function %s requires the -mpaired option", name);
14080 else if ((fnmask & RS6000_BTM_SPE) != 0)
14081 error ("Builtin function %s requires the -mspe option", name);
14082 else if ((fnmask & (RS6000_BTM_DFP | RS6000_BTM_P8_VECTOR))
14083 == (RS6000_BTM_DFP | RS6000_BTM_P8_VECTOR))
14084 error ("Builtin function %s requires the -mhard-dfp and"
14085 " -mpower8-vector options", name);
14086 else if ((fnmask & RS6000_BTM_DFP) != 0)
14087 error ("Builtin function %s requires the -mhard-dfp option", name);
14088 else if ((fnmask & RS6000_BTM_P8_VECTOR) != 0)
14089 error ("Builtin function %s requires the -mpower8-vector option", name);
14090 else if ((fnmask & (RS6000_BTM_HARD_FLOAT | RS6000_BTM_LDBL128))
14091 == (RS6000_BTM_HARD_FLOAT | RS6000_BTM_LDBL128))
14092 error ("Builtin function %s requires the -mhard-float and"
14093 " -mlong-double-128 options", name);
14094 else if ((fnmask & RS6000_BTM_HARD_FLOAT) != 0)
14095 error ("Builtin function %s requires the -mhard-float option", name);
14096 else
14097 error ("Builtin function %s is not supported with the current options",
14098 name);
14101 /* Expand an expression EXP that calls a built-in function,
14102 with result going to TARGET if that's convenient
14103 (and in mode MODE if that's convenient).
14104 SUBTARGET may be used as the target for computing one of EXP's operands.
14105 IGNORE is nonzero if the value is to be ignored. */
14107 static rtx
14108 rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
14109 machine_mode mode ATTRIBUTE_UNUSED,
14110 int ignore ATTRIBUTE_UNUSED)
14112 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
14113 enum rs6000_builtins fcode
14114 = (enum rs6000_builtins)DECL_FUNCTION_CODE (fndecl);
14115 size_t uns_fcode = (size_t)fcode;
14116 const struct builtin_description *d;
14117 size_t i;
14118 rtx ret;
14119 bool success;
14120 HOST_WIDE_INT mask = rs6000_builtin_info[uns_fcode].mask;
14121 bool func_valid_p = ((rs6000_builtin_mask & mask) == mask);
14123 if (TARGET_DEBUG_BUILTIN)
14125 enum insn_code icode = rs6000_builtin_info[uns_fcode].icode;
14126 const char *name1 = rs6000_builtin_info[uns_fcode].name;
14127 const char *name2 = ((icode != CODE_FOR_nothing)
14128 ? get_insn_name ((int)icode)
14129 : "nothing");
14130 const char *name3;
14132 switch (rs6000_builtin_info[uns_fcode].attr & RS6000_BTC_TYPE_MASK)
14134 default: name3 = "unknown"; break;
14135 case RS6000_BTC_SPECIAL: name3 = "special"; break;
14136 case RS6000_BTC_UNARY: name3 = "unary"; break;
14137 case RS6000_BTC_BINARY: name3 = "binary"; break;
14138 case RS6000_BTC_TERNARY: name3 = "ternary"; break;
14139 case RS6000_BTC_PREDICATE: name3 = "predicate"; break;
14140 case RS6000_BTC_ABS: name3 = "abs"; break;
14141 case RS6000_BTC_EVSEL: name3 = "evsel"; break;
14142 case RS6000_BTC_DST: name3 = "dst"; break;
14146 fprintf (stderr,
14147 "rs6000_expand_builtin, %s (%d), insn = %s (%d), type=%s%s\n",
14148 (name1) ? name1 : "---", fcode,
14149 (name2) ? name2 : "---", (int)icode,
14150 name3,
14151 func_valid_p ? "" : ", not valid");
14154 if (!func_valid_p)
14156 rs6000_invalid_builtin (fcode);
14158 /* Given it is invalid, just generate a normal call. */
14159 return expand_call (exp, target, ignore);
14162 switch (fcode)
14164 case RS6000_BUILTIN_RECIP:
14165 return rs6000_expand_binop_builtin (CODE_FOR_recipdf3, exp, target);
14167 case RS6000_BUILTIN_RECIPF:
14168 return rs6000_expand_binop_builtin (CODE_FOR_recipsf3, exp, target);
14170 case RS6000_BUILTIN_RSQRTF:
14171 return rs6000_expand_unop_builtin (CODE_FOR_rsqrtsf2, exp, target);
14173 case RS6000_BUILTIN_RSQRT:
14174 return rs6000_expand_unop_builtin (CODE_FOR_rsqrtdf2, exp, target);
14176 case POWER7_BUILTIN_BPERMD:
14177 return rs6000_expand_binop_builtin (((TARGET_64BIT)
14178 ? CODE_FOR_bpermd_di
14179 : CODE_FOR_bpermd_si), exp, target);
14181 case RS6000_BUILTIN_GET_TB:
14182 return rs6000_expand_zeroop_builtin (CODE_FOR_rs6000_get_timebase,
14183 target);
14185 case RS6000_BUILTIN_MFTB:
14186 return rs6000_expand_zeroop_builtin (((TARGET_64BIT)
14187 ? CODE_FOR_rs6000_mftb_di
14188 : CODE_FOR_rs6000_mftb_si),
14189 target);
14191 case RS6000_BUILTIN_MFFS:
14192 return rs6000_expand_zeroop_builtin (CODE_FOR_rs6000_mffs, target);
14194 case RS6000_BUILTIN_MTFSF:
14195 return rs6000_expand_mtfsf_builtin (CODE_FOR_rs6000_mtfsf, exp);
14197 case ALTIVEC_BUILTIN_MASK_FOR_LOAD:
14198 case ALTIVEC_BUILTIN_MASK_FOR_STORE:
14200 int icode = (BYTES_BIG_ENDIAN ? (int) CODE_FOR_altivec_lvsr_direct
14201 : (int) CODE_FOR_altivec_lvsl_direct);
14202 machine_mode tmode = insn_data[icode].operand[0].mode;
14203 machine_mode mode = insn_data[icode].operand[1].mode;
14204 tree arg;
14205 rtx op, addr, pat;
14207 gcc_assert (TARGET_ALTIVEC);
14209 arg = CALL_EXPR_ARG (exp, 0);
14210 gcc_assert (POINTER_TYPE_P (TREE_TYPE (arg)));
14211 op = expand_expr (arg, NULL_RTX, Pmode, EXPAND_NORMAL);
14212 addr = memory_address (mode, op);
14213 if (fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE)
14214 op = addr;
14215 else
14217 /* For the load case need to negate the address. */
14218 op = gen_reg_rtx (GET_MODE (addr));
14219 emit_insn (gen_rtx_SET (op, gen_rtx_NEG (GET_MODE (addr), addr)));
14221 op = gen_rtx_MEM (mode, op);
14223 if (target == 0
14224 || GET_MODE (target) != tmode
14225 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
14226 target = gen_reg_rtx (tmode);
14228 pat = GEN_FCN (icode) (target, op);
14229 if (!pat)
14230 return 0;
14231 emit_insn (pat);
14233 return target;
14236 case ALTIVEC_BUILTIN_VCFUX:
14237 case ALTIVEC_BUILTIN_VCFSX:
14238 case ALTIVEC_BUILTIN_VCTUXS:
14239 case ALTIVEC_BUILTIN_VCTSXS:
14240 /* FIXME: There's got to be a nicer way to handle this case than
14241 constructing a new CALL_EXPR. */
14242 if (call_expr_nargs (exp) == 1)
14244 exp = build_call_nary (TREE_TYPE (exp), CALL_EXPR_FN (exp),
14245 2, CALL_EXPR_ARG (exp, 0), integer_zero_node);
14247 break;
14249 default:
14250 break;
14253 if (TARGET_ALTIVEC)
14255 ret = altivec_expand_builtin (exp, target, &success);
14257 if (success)
14258 return ret;
14260 if (TARGET_SPE)
14262 ret = spe_expand_builtin (exp, target, &success);
14264 if (success)
14265 return ret;
14267 if (TARGET_PAIRED_FLOAT)
14269 ret = paired_expand_builtin (exp, target, &success);
14271 if (success)
14272 return ret;
14274 if (TARGET_HTM)
14276 ret = htm_expand_builtin (exp, target, &success);
14278 if (success)
14279 return ret;
14282 unsigned attr = rs6000_builtin_info[uns_fcode].attr & RS6000_BTC_TYPE_MASK;
14283 gcc_assert (attr == RS6000_BTC_UNARY
14284 || attr == RS6000_BTC_BINARY
14285 || attr == RS6000_BTC_TERNARY);
14287 /* Handle simple unary operations. */
14288 d = bdesc_1arg;
14289 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
14290 if (d->code == fcode)
14291 return rs6000_expand_unop_builtin (d->icode, exp, target);
14293 /* Handle simple binary operations. */
14294 d = bdesc_2arg;
14295 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
14296 if (d->code == fcode)
14297 return rs6000_expand_binop_builtin (d->icode, exp, target);
14299 /* Handle simple ternary operations. */
14300 d = bdesc_3arg;
14301 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
14302 if (d->code == fcode)
14303 return rs6000_expand_ternop_builtin (d->icode, exp, target);
14305 gcc_unreachable ();
14308 static void
14309 rs6000_init_builtins (void)
14311 tree tdecl;
14312 tree ftype;
14313 machine_mode mode;
14315 if (TARGET_DEBUG_BUILTIN)
14316 fprintf (stderr, "rs6000_init_builtins%s%s%s%s\n",
14317 (TARGET_PAIRED_FLOAT) ? ", paired" : "",
14318 (TARGET_SPE) ? ", spe" : "",
14319 (TARGET_ALTIVEC) ? ", altivec" : "",
14320 (TARGET_VSX) ? ", vsx" : "");
14322 V2SI_type_node = build_vector_type (intSI_type_node, 2);
14323 V2SF_type_node = build_vector_type (float_type_node, 2);
14324 V2DI_type_node = build_vector_type (intDI_type_node, 2);
14325 V2DF_type_node = build_vector_type (double_type_node, 2);
14326 V4HI_type_node = build_vector_type (intHI_type_node, 4);
14327 V4SI_type_node = build_vector_type (intSI_type_node, 4);
14328 V4SF_type_node = build_vector_type (float_type_node, 4);
14329 V8HI_type_node = build_vector_type (intHI_type_node, 8);
14330 V16QI_type_node = build_vector_type (intQI_type_node, 16);
14332 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
14333 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
14334 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
14335 unsigned_V2DI_type_node = build_vector_type (unsigned_intDI_type_node, 2);
14337 opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2);
14338 opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2);
14339 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
14340 opaque_V4SI_type_node = build_opaque_vector_type (intSI_type_node, 4);
14342 /* We use V1TI mode as a special container to hold __int128_t items that
14343 must live in VSX registers. */
14344 if (intTI_type_node)
14346 V1TI_type_node = build_vector_type (intTI_type_node, 1);
14347 unsigned_V1TI_type_node = build_vector_type (unsigned_intTI_type_node, 1);
14350 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
14351 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
14352 'vector unsigned short'. */
14354 bool_char_type_node = build_distinct_type_copy (unsigned_intQI_type_node);
14355 bool_short_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
14356 bool_int_type_node = build_distinct_type_copy (unsigned_intSI_type_node);
14357 bool_long_type_node = build_distinct_type_copy (unsigned_intDI_type_node);
14358 pixel_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
14360 long_integer_type_internal_node = long_integer_type_node;
14361 long_unsigned_type_internal_node = long_unsigned_type_node;
14362 long_long_integer_type_internal_node = long_long_integer_type_node;
14363 long_long_unsigned_type_internal_node = long_long_unsigned_type_node;
14364 intQI_type_internal_node = intQI_type_node;
14365 uintQI_type_internal_node = unsigned_intQI_type_node;
14366 intHI_type_internal_node = intHI_type_node;
14367 uintHI_type_internal_node = unsigned_intHI_type_node;
14368 intSI_type_internal_node = intSI_type_node;
14369 uintSI_type_internal_node = unsigned_intSI_type_node;
14370 intDI_type_internal_node = intDI_type_node;
14371 uintDI_type_internal_node = unsigned_intDI_type_node;
14372 intTI_type_internal_node = intTI_type_node;
14373 uintTI_type_internal_node = unsigned_intTI_type_node;
14374 float_type_internal_node = float_type_node;
14375 double_type_internal_node = double_type_node;
14376 long_double_type_internal_node = long_double_type_node;
14377 dfloat64_type_internal_node = dfloat64_type_node;
14378 dfloat128_type_internal_node = dfloat128_type_node;
14379 void_type_internal_node = void_type_node;
14381 /* Initialize the modes for builtin_function_type, mapping a machine mode to
14382 tree type node. */
14383 builtin_mode_to_type[QImode][0] = integer_type_node;
14384 builtin_mode_to_type[HImode][0] = integer_type_node;
14385 builtin_mode_to_type[SImode][0] = intSI_type_node;
14386 builtin_mode_to_type[SImode][1] = unsigned_intSI_type_node;
14387 builtin_mode_to_type[DImode][0] = intDI_type_node;
14388 builtin_mode_to_type[DImode][1] = unsigned_intDI_type_node;
14389 builtin_mode_to_type[TImode][0] = intTI_type_node;
14390 builtin_mode_to_type[TImode][1] = unsigned_intTI_type_node;
14391 builtin_mode_to_type[SFmode][0] = float_type_node;
14392 builtin_mode_to_type[DFmode][0] = double_type_node;
14393 builtin_mode_to_type[TFmode][0] = long_double_type_node;
14394 builtin_mode_to_type[DDmode][0] = dfloat64_type_node;
14395 builtin_mode_to_type[TDmode][0] = dfloat128_type_node;
14396 builtin_mode_to_type[V1TImode][0] = V1TI_type_node;
14397 builtin_mode_to_type[V1TImode][1] = unsigned_V1TI_type_node;
14398 builtin_mode_to_type[V2SImode][0] = V2SI_type_node;
14399 builtin_mode_to_type[V2SFmode][0] = V2SF_type_node;
14400 builtin_mode_to_type[V2DImode][0] = V2DI_type_node;
14401 builtin_mode_to_type[V2DImode][1] = unsigned_V2DI_type_node;
14402 builtin_mode_to_type[V2DFmode][0] = V2DF_type_node;
14403 builtin_mode_to_type[V4HImode][0] = V4HI_type_node;
14404 builtin_mode_to_type[V4SImode][0] = V4SI_type_node;
14405 builtin_mode_to_type[V4SImode][1] = unsigned_V4SI_type_node;
14406 builtin_mode_to_type[V4SFmode][0] = V4SF_type_node;
14407 builtin_mode_to_type[V8HImode][0] = V8HI_type_node;
14408 builtin_mode_to_type[V8HImode][1] = unsigned_V8HI_type_node;
14409 builtin_mode_to_type[V16QImode][0] = V16QI_type_node;
14410 builtin_mode_to_type[V16QImode][1] = unsigned_V16QI_type_node;
14412 tdecl = add_builtin_type ("__bool char", bool_char_type_node);
14413 TYPE_NAME (bool_char_type_node) = tdecl;
14415 tdecl = add_builtin_type ("__bool short", bool_short_type_node);
14416 TYPE_NAME (bool_short_type_node) = tdecl;
14418 tdecl = add_builtin_type ("__bool int", bool_int_type_node);
14419 TYPE_NAME (bool_int_type_node) = tdecl;
14421 tdecl = add_builtin_type ("__pixel", pixel_type_node);
14422 TYPE_NAME (pixel_type_node) = tdecl;
14424 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
14425 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
14426 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
14427 bool_V2DI_type_node = build_vector_type (bool_long_type_node, 2);
14428 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
14430 tdecl = add_builtin_type ("__vector unsigned char", unsigned_V16QI_type_node);
14431 TYPE_NAME (unsigned_V16QI_type_node) = tdecl;
14433 tdecl = add_builtin_type ("__vector signed char", V16QI_type_node);
14434 TYPE_NAME (V16QI_type_node) = tdecl;
14436 tdecl = add_builtin_type ("__vector __bool char", bool_V16QI_type_node);
14437 TYPE_NAME ( bool_V16QI_type_node) = tdecl;
14439 tdecl = add_builtin_type ("__vector unsigned short", unsigned_V8HI_type_node);
14440 TYPE_NAME (unsigned_V8HI_type_node) = tdecl;
14442 tdecl = add_builtin_type ("__vector signed short", V8HI_type_node);
14443 TYPE_NAME (V8HI_type_node) = tdecl;
14445 tdecl = add_builtin_type ("__vector __bool short", bool_V8HI_type_node);
14446 TYPE_NAME (bool_V8HI_type_node) = tdecl;
14448 tdecl = add_builtin_type ("__vector unsigned int", unsigned_V4SI_type_node);
14449 TYPE_NAME (unsigned_V4SI_type_node) = tdecl;
14451 tdecl = add_builtin_type ("__vector signed int", V4SI_type_node);
14452 TYPE_NAME (V4SI_type_node) = tdecl;
14454 tdecl = add_builtin_type ("__vector __bool int", bool_V4SI_type_node);
14455 TYPE_NAME (bool_V4SI_type_node) = tdecl;
14457 tdecl = add_builtin_type ("__vector float", V4SF_type_node);
14458 TYPE_NAME (V4SF_type_node) = tdecl;
14460 tdecl = add_builtin_type ("__vector __pixel", pixel_V8HI_type_node);
14461 TYPE_NAME (pixel_V8HI_type_node) = tdecl;
14463 tdecl = add_builtin_type ("__vector double", V2DF_type_node);
14464 TYPE_NAME (V2DF_type_node) = tdecl;
14466 if (TARGET_POWERPC64)
14468 tdecl = add_builtin_type ("__vector long", V2DI_type_node);
14469 TYPE_NAME (V2DI_type_node) = tdecl;
14471 tdecl = add_builtin_type ("__vector unsigned long",
14472 unsigned_V2DI_type_node);
14473 TYPE_NAME (unsigned_V2DI_type_node) = tdecl;
14475 tdecl = add_builtin_type ("__vector __bool long", bool_V2DI_type_node);
14476 TYPE_NAME (bool_V2DI_type_node) = tdecl;
14478 else
14480 tdecl = add_builtin_type ("__vector long long", V2DI_type_node);
14481 TYPE_NAME (V2DI_type_node) = tdecl;
14483 tdecl = add_builtin_type ("__vector unsigned long long",
14484 unsigned_V2DI_type_node);
14485 TYPE_NAME (unsigned_V2DI_type_node) = tdecl;
14487 tdecl = add_builtin_type ("__vector __bool long long",
14488 bool_V2DI_type_node);
14489 TYPE_NAME (bool_V2DI_type_node) = tdecl;
14492 if (V1TI_type_node)
14494 tdecl = add_builtin_type ("__vector __int128", V1TI_type_node);
14495 TYPE_NAME (V1TI_type_node) = tdecl;
14497 tdecl = add_builtin_type ("__vector unsigned __int128",
14498 unsigned_V1TI_type_node);
14499 TYPE_NAME (unsigned_V1TI_type_node) = tdecl;
14502 /* Paired and SPE builtins are only available if you build a compiler with
14503 the appropriate options, so only create those builtins with the
14504 appropriate compiler option. Create Altivec and VSX builtins on machines
14505 with at least the general purpose extensions (970 and newer) to allow the
14506 use of the target attribute. */
14507 if (TARGET_PAIRED_FLOAT)
14508 paired_init_builtins ();
14509 if (TARGET_SPE)
14510 spe_init_builtins ();
14511 if (TARGET_EXTRA_BUILTINS)
14512 altivec_init_builtins ();
14513 if (TARGET_HTM)
14514 htm_init_builtins ();
14516 if (TARGET_EXTRA_BUILTINS || TARGET_SPE || TARGET_PAIRED_FLOAT)
14517 rs6000_common_init_builtins ();
14519 ftype = builtin_function_type (DFmode, DFmode, DFmode, VOIDmode,
14520 RS6000_BUILTIN_RECIP, "__builtin_recipdiv");
14521 def_builtin ("__builtin_recipdiv", ftype, RS6000_BUILTIN_RECIP);
14523 ftype = builtin_function_type (SFmode, SFmode, SFmode, VOIDmode,
14524 RS6000_BUILTIN_RECIPF, "__builtin_recipdivf");
14525 def_builtin ("__builtin_recipdivf", ftype, RS6000_BUILTIN_RECIPF);
14527 ftype = builtin_function_type (DFmode, DFmode, VOIDmode, VOIDmode,
14528 RS6000_BUILTIN_RSQRT, "__builtin_rsqrt");
14529 def_builtin ("__builtin_rsqrt", ftype, RS6000_BUILTIN_RSQRT);
14531 ftype = builtin_function_type (SFmode, SFmode, VOIDmode, VOIDmode,
14532 RS6000_BUILTIN_RSQRTF, "__builtin_rsqrtf");
14533 def_builtin ("__builtin_rsqrtf", ftype, RS6000_BUILTIN_RSQRTF);
14535 mode = (TARGET_64BIT) ? DImode : SImode;
14536 ftype = builtin_function_type (mode, mode, mode, VOIDmode,
14537 POWER7_BUILTIN_BPERMD, "__builtin_bpermd");
14538 def_builtin ("__builtin_bpermd", ftype, POWER7_BUILTIN_BPERMD);
14540 ftype = build_function_type_list (unsigned_intDI_type_node,
14541 NULL_TREE);
14542 def_builtin ("__builtin_ppc_get_timebase", ftype, RS6000_BUILTIN_GET_TB);
14544 if (TARGET_64BIT)
14545 ftype = build_function_type_list (unsigned_intDI_type_node,
14546 NULL_TREE);
14547 else
14548 ftype = build_function_type_list (unsigned_intSI_type_node,
14549 NULL_TREE);
14550 def_builtin ("__builtin_ppc_mftb", ftype, RS6000_BUILTIN_MFTB);
14552 ftype = build_function_type_list (double_type_node, NULL_TREE);
14553 def_builtin ("__builtin_mffs", ftype, RS6000_BUILTIN_MFFS);
14555 ftype = build_function_type_list (void_type_node,
14556 intSI_type_node, double_type_node,
14557 NULL_TREE);
14558 def_builtin ("__builtin_mtfsf", ftype, RS6000_BUILTIN_MTFSF);
14560 #if TARGET_XCOFF
14561 /* AIX libm provides clog as __clog. */
14562 if ((tdecl = builtin_decl_explicit (BUILT_IN_CLOG)) != NULL_TREE)
14563 set_user_assembler_name (tdecl, "__clog");
14564 #endif
14566 #ifdef SUBTARGET_INIT_BUILTINS
14567 SUBTARGET_INIT_BUILTINS;
14568 #endif
14571 /* Returns the rs6000 builtin decl for CODE. */
14573 static tree
14574 rs6000_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED)
14576 HOST_WIDE_INT fnmask;
14578 if (code >= RS6000_BUILTIN_COUNT)
14579 return error_mark_node;
14581 fnmask = rs6000_builtin_info[code].mask;
14582 if ((fnmask & rs6000_builtin_mask) != fnmask)
14584 rs6000_invalid_builtin ((enum rs6000_builtins)code);
14585 return error_mark_node;
14588 return rs6000_builtin_decls[code];
14591 static void
14592 spe_init_builtins (void)
14594 tree puint_type_node = build_pointer_type (unsigned_type_node);
14595 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
14596 const struct builtin_description *d;
14597 size_t i;
14599 tree v2si_ftype_4_v2si
14600 = build_function_type_list (opaque_V2SI_type_node,
14601 opaque_V2SI_type_node,
14602 opaque_V2SI_type_node,
14603 opaque_V2SI_type_node,
14604 opaque_V2SI_type_node,
14605 NULL_TREE);
14607 tree v2sf_ftype_4_v2sf
14608 = build_function_type_list (opaque_V2SF_type_node,
14609 opaque_V2SF_type_node,
14610 opaque_V2SF_type_node,
14611 opaque_V2SF_type_node,
14612 opaque_V2SF_type_node,
14613 NULL_TREE);
14615 tree int_ftype_int_v2si_v2si
14616 = build_function_type_list (integer_type_node,
14617 integer_type_node,
14618 opaque_V2SI_type_node,
14619 opaque_V2SI_type_node,
14620 NULL_TREE);
14622 tree int_ftype_int_v2sf_v2sf
14623 = build_function_type_list (integer_type_node,
14624 integer_type_node,
14625 opaque_V2SF_type_node,
14626 opaque_V2SF_type_node,
14627 NULL_TREE);
14629 tree void_ftype_v2si_puint_int
14630 = build_function_type_list (void_type_node,
14631 opaque_V2SI_type_node,
14632 puint_type_node,
14633 integer_type_node,
14634 NULL_TREE);
14636 tree void_ftype_v2si_puint_char
14637 = build_function_type_list (void_type_node,
14638 opaque_V2SI_type_node,
14639 puint_type_node,
14640 char_type_node,
14641 NULL_TREE);
14643 tree void_ftype_v2si_pv2si_int
14644 = build_function_type_list (void_type_node,
14645 opaque_V2SI_type_node,
14646 opaque_p_V2SI_type_node,
14647 integer_type_node,
14648 NULL_TREE);
14650 tree void_ftype_v2si_pv2si_char
14651 = build_function_type_list (void_type_node,
14652 opaque_V2SI_type_node,
14653 opaque_p_V2SI_type_node,
14654 char_type_node,
14655 NULL_TREE);
14657 tree void_ftype_int
14658 = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
14660 tree int_ftype_void
14661 = build_function_type_list (integer_type_node, NULL_TREE);
14663 tree v2si_ftype_pv2si_int
14664 = build_function_type_list (opaque_V2SI_type_node,
14665 opaque_p_V2SI_type_node,
14666 integer_type_node,
14667 NULL_TREE);
14669 tree v2si_ftype_puint_int
14670 = build_function_type_list (opaque_V2SI_type_node,
14671 puint_type_node,
14672 integer_type_node,
14673 NULL_TREE);
14675 tree v2si_ftype_pushort_int
14676 = build_function_type_list (opaque_V2SI_type_node,
14677 pushort_type_node,
14678 integer_type_node,
14679 NULL_TREE);
14681 tree v2si_ftype_signed_char
14682 = build_function_type_list (opaque_V2SI_type_node,
14683 signed_char_type_node,
14684 NULL_TREE);
14686 add_builtin_type ("__ev64_opaque__", opaque_V2SI_type_node);
14688 /* Initialize irregular SPE builtins. */
14690 def_builtin ("__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
14691 def_builtin ("__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
14692 def_builtin ("__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
14693 def_builtin ("__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
14694 def_builtin ("__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
14695 def_builtin ("__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
14696 def_builtin ("__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
14697 def_builtin ("__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
14698 def_builtin ("__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
14699 def_builtin ("__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
14700 def_builtin ("__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
14701 def_builtin ("__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
14702 def_builtin ("__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
14703 def_builtin ("__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
14704 def_builtin ("__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
14705 def_builtin ("__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
14706 def_builtin ("__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
14707 def_builtin ("__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
14709 /* Loads. */
14710 def_builtin ("__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
14711 def_builtin ("__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
14712 def_builtin ("__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
14713 def_builtin ("__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
14714 def_builtin ("__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
14715 def_builtin ("__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
14716 def_builtin ("__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
14717 def_builtin ("__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
14718 def_builtin ("__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
14719 def_builtin ("__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
14720 def_builtin ("__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
14721 def_builtin ("__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
14722 def_builtin ("__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
14723 def_builtin ("__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
14724 def_builtin ("__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
14725 def_builtin ("__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
14726 def_builtin ("__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
14727 def_builtin ("__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
14728 def_builtin ("__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
14729 def_builtin ("__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
14730 def_builtin ("__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
14731 def_builtin ("__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
14733 /* Predicates. */
14734 d = bdesc_spe_predicates;
14735 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
14737 tree type;
14739 switch (insn_data[d->icode].operand[1].mode)
14741 case V2SImode:
14742 type = int_ftype_int_v2si_v2si;
14743 break;
14744 case V2SFmode:
14745 type = int_ftype_int_v2sf_v2sf;
14746 break;
14747 default:
14748 gcc_unreachable ();
14751 def_builtin (d->name, type, d->code);
14754 /* Evsel predicates. */
14755 d = bdesc_spe_evsel;
14756 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
14758 tree type;
14760 switch (insn_data[d->icode].operand[1].mode)
14762 case V2SImode:
14763 type = v2si_ftype_4_v2si;
14764 break;
14765 case V2SFmode:
14766 type = v2sf_ftype_4_v2sf;
14767 break;
14768 default:
14769 gcc_unreachable ();
14772 def_builtin (d->name, type, d->code);
14776 static void
14777 paired_init_builtins (void)
14779 const struct builtin_description *d;
14780 size_t i;
14782 tree int_ftype_int_v2sf_v2sf
14783 = build_function_type_list (integer_type_node,
14784 integer_type_node,
14785 V2SF_type_node,
14786 V2SF_type_node,
14787 NULL_TREE);
14788 tree pcfloat_type_node =
14789 build_pointer_type (build_qualified_type
14790 (float_type_node, TYPE_QUAL_CONST));
14792 tree v2sf_ftype_long_pcfloat = build_function_type_list (V2SF_type_node,
14793 long_integer_type_node,
14794 pcfloat_type_node,
14795 NULL_TREE);
14796 tree void_ftype_v2sf_long_pcfloat =
14797 build_function_type_list (void_type_node,
14798 V2SF_type_node,
14799 long_integer_type_node,
14800 pcfloat_type_node,
14801 NULL_TREE);
14804 def_builtin ("__builtin_paired_lx", v2sf_ftype_long_pcfloat,
14805 PAIRED_BUILTIN_LX);
14808 def_builtin ("__builtin_paired_stx", void_ftype_v2sf_long_pcfloat,
14809 PAIRED_BUILTIN_STX);
14811 /* Predicates. */
14812 d = bdesc_paired_preds;
14813 for (i = 0; i < ARRAY_SIZE (bdesc_paired_preds); ++i, d++)
14815 tree type;
14817 if (TARGET_DEBUG_BUILTIN)
14818 fprintf (stderr, "paired pred #%d, insn = %s [%d], mode = %s\n",
14819 (int)i, get_insn_name (d->icode), (int)d->icode,
14820 GET_MODE_NAME (insn_data[d->icode].operand[1].mode));
14822 switch (insn_data[d->icode].operand[1].mode)
14824 case V2SFmode:
14825 type = int_ftype_int_v2sf_v2sf;
14826 break;
14827 default:
14828 gcc_unreachable ();
14831 def_builtin (d->name, type, d->code);
14835 static void
14836 altivec_init_builtins (void)
14838 const struct builtin_description *d;
14839 size_t i;
14840 tree ftype;
14841 tree decl;
14843 tree pvoid_type_node = build_pointer_type (void_type_node);
14845 tree pcvoid_type_node
14846 = build_pointer_type (build_qualified_type (void_type_node,
14847 TYPE_QUAL_CONST));
14849 tree int_ftype_opaque
14850 = build_function_type_list (integer_type_node,
14851 opaque_V4SI_type_node, NULL_TREE);
14852 tree opaque_ftype_opaque
14853 = build_function_type_list (integer_type_node, NULL_TREE);
14854 tree opaque_ftype_opaque_int
14855 = build_function_type_list (opaque_V4SI_type_node,
14856 opaque_V4SI_type_node, integer_type_node, NULL_TREE);
14857 tree opaque_ftype_opaque_opaque_int
14858 = build_function_type_list (opaque_V4SI_type_node,
14859 opaque_V4SI_type_node, opaque_V4SI_type_node,
14860 integer_type_node, NULL_TREE);
14861 tree int_ftype_int_opaque_opaque
14862 = build_function_type_list (integer_type_node,
14863 integer_type_node, opaque_V4SI_type_node,
14864 opaque_V4SI_type_node, NULL_TREE);
14865 tree int_ftype_int_v4si_v4si
14866 = build_function_type_list (integer_type_node,
14867 integer_type_node, V4SI_type_node,
14868 V4SI_type_node, NULL_TREE);
14869 tree int_ftype_int_v2di_v2di
14870 = build_function_type_list (integer_type_node,
14871 integer_type_node, V2DI_type_node,
14872 V2DI_type_node, NULL_TREE);
14873 tree void_ftype_v4si
14874 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
14875 tree v8hi_ftype_void
14876 = build_function_type_list (V8HI_type_node, NULL_TREE);
14877 tree void_ftype_void
14878 = build_function_type_list (void_type_node, NULL_TREE);
14879 tree void_ftype_int
14880 = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
14882 tree opaque_ftype_long_pcvoid
14883 = build_function_type_list (opaque_V4SI_type_node,
14884 long_integer_type_node, pcvoid_type_node,
14885 NULL_TREE);
14886 tree v16qi_ftype_long_pcvoid
14887 = build_function_type_list (V16QI_type_node,
14888 long_integer_type_node, pcvoid_type_node,
14889 NULL_TREE);
14890 tree v8hi_ftype_long_pcvoid
14891 = build_function_type_list (V8HI_type_node,
14892 long_integer_type_node, pcvoid_type_node,
14893 NULL_TREE);
14894 tree v4si_ftype_long_pcvoid
14895 = build_function_type_list (V4SI_type_node,
14896 long_integer_type_node, pcvoid_type_node,
14897 NULL_TREE);
14898 tree v4sf_ftype_long_pcvoid
14899 = build_function_type_list (V4SF_type_node,
14900 long_integer_type_node, pcvoid_type_node,
14901 NULL_TREE);
14902 tree v2df_ftype_long_pcvoid
14903 = build_function_type_list (V2DF_type_node,
14904 long_integer_type_node, pcvoid_type_node,
14905 NULL_TREE);
14906 tree v2di_ftype_long_pcvoid
14907 = build_function_type_list (V2DI_type_node,
14908 long_integer_type_node, pcvoid_type_node,
14909 NULL_TREE);
14911 tree void_ftype_opaque_long_pvoid
14912 = build_function_type_list (void_type_node,
14913 opaque_V4SI_type_node, long_integer_type_node,
14914 pvoid_type_node, NULL_TREE);
14915 tree void_ftype_v4si_long_pvoid
14916 = build_function_type_list (void_type_node,
14917 V4SI_type_node, long_integer_type_node,
14918 pvoid_type_node, NULL_TREE);
14919 tree void_ftype_v16qi_long_pvoid
14920 = build_function_type_list (void_type_node,
14921 V16QI_type_node, long_integer_type_node,
14922 pvoid_type_node, NULL_TREE);
14923 tree void_ftype_v8hi_long_pvoid
14924 = build_function_type_list (void_type_node,
14925 V8HI_type_node, long_integer_type_node,
14926 pvoid_type_node, NULL_TREE);
14927 tree void_ftype_v4sf_long_pvoid
14928 = build_function_type_list (void_type_node,
14929 V4SF_type_node, long_integer_type_node,
14930 pvoid_type_node, NULL_TREE);
14931 tree void_ftype_v2df_long_pvoid
14932 = build_function_type_list (void_type_node,
14933 V2DF_type_node, long_integer_type_node,
14934 pvoid_type_node, NULL_TREE);
14935 tree void_ftype_v2di_long_pvoid
14936 = build_function_type_list (void_type_node,
14937 V2DI_type_node, long_integer_type_node,
14938 pvoid_type_node, NULL_TREE);
14939 tree int_ftype_int_v8hi_v8hi
14940 = build_function_type_list (integer_type_node,
14941 integer_type_node, V8HI_type_node,
14942 V8HI_type_node, NULL_TREE);
14943 tree int_ftype_int_v16qi_v16qi
14944 = build_function_type_list (integer_type_node,
14945 integer_type_node, V16QI_type_node,
14946 V16QI_type_node, NULL_TREE);
14947 tree int_ftype_int_v4sf_v4sf
14948 = build_function_type_list (integer_type_node,
14949 integer_type_node, V4SF_type_node,
14950 V4SF_type_node, NULL_TREE);
14951 tree int_ftype_int_v2df_v2df
14952 = build_function_type_list (integer_type_node,
14953 integer_type_node, V2DF_type_node,
14954 V2DF_type_node, NULL_TREE);
14955 tree v2di_ftype_v2di
14956 = build_function_type_list (V2DI_type_node, V2DI_type_node, NULL_TREE);
14957 tree v4si_ftype_v4si
14958 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
14959 tree v8hi_ftype_v8hi
14960 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
14961 tree v16qi_ftype_v16qi
14962 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
14963 tree v4sf_ftype_v4sf
14964 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
14965 tree v2df_ftype_v2df
14966 = build_function_type_list (V2DF_type_node, V2DF_type_node, NULL_TREE);
14967 tree void_ftype_pcvoid_int_int
14968 = build_function_type_list (void_type_node,
14969 pcvoid_type_node, integer_type_node,
14970 integer_type_node, NULL_TREE);
14972 def_builtin ("__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
14973 def_builtin ("__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
14974 def_builtin ("__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
14975 def_builtin ("__builtin_altivec_dss", void_ftype_int, ALTIVEC_BUILTIN_DSS);
14976 def_builtin ("__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
14977 def_builtin ("__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
14978 def_builtin ("__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
14979 def_builtin ("__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
14980 def_builtin ("__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
14981 def_builtin ("__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
14982 def_builtin ("__builtin_altivec_lvxl_v2df", v2df_ftype_long_pcvoid,
14983 ALTIVEC_BUILTIN_LVXL_V2DF);
14984 def_builtin ("__builtin_altivec_lvxl_v2di", v2di_ftype_long_pcvoid,
14985 ALTIVEC_BUILTIN_LVXL_V2DI);
14986 def_builtin ("__builtin_altivec_lvxl_v4sf", v4sf_ftype_long_pcvoid,
14987 ALTIVEC_BUILTIN_LVXL_V4SF);
14988 def_builtin ("__builtin_altivec_lvxl_v4si", v4si_ftype_long_pcvoid,
14989 ALTIVEC_BUILTIN_LVXL_V4SI);
14990 def_builtin ("__builtin_altivec_lvxl_v8hi", v8hi_ftype_long_pcvoid,
14991 ALTIVEC_BUILTIN_LVXL_V8HI);
14992 def_builtin ("__builtin_altivec_lvxl_v16qi", v16qi_ftype_long_pcvoid,
14993 ALTIVEC_BUILTIN_LVXL_V16QI);
14994 def_builtin ("__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
14995 def_builtin ("__builtin_altivec_lvx_v2df", v2df_ftype_long_pcvoid,
14996 ALTIVEC_BUILTIN_LVX_V2DF);
14997 def_builtin ("__builtin_altivec_lvx_v2di", v2di_ftype_long_pcvoid,
14998 ALTIVEC_BUILTIN_LVX_V2DI);
14999 def_builtin ("__builtin_altivec_lvx_v4sf", v4sf_ftype_long_pcvoid,
15000 ALTIVEC_BUILTIN_LVX_V4SF);
15001 def_builtin ("__builtin_altivec_lvx_v4si", v4si_ftype_long_pcvoid,
15002 ALTIVEC_BUILTIN_LVX_V4SI);
15003 def_builtin ("__builtin_altivec_lvx_v8hi", v8hi_ftype_long_pcvoid,
15004 ALTIVEC_BUILTIN_LVX_V8HI);
15005 def_builtin ("__builtin_altivec_lvx_v16qi", v16qi_ftype_long_pcvoid,
15006 ALTIVEC_BUILTIN_LVX_V16QI);
15007 def_builtin ("__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
15008 def_builtin ("__builtin_altivec_stvx_v2df", void_ftype_v2df_long_pvoid,
15009 ALTIVEC_BUILTIN_STVX_V2DF);
15010 def_builtin ("__builtin_altivec_stvx_v2di", void_ftype_v2di_long_pvoid,
15011 ALTIVEC_BUILTIN_STVX_V2DI);
15012 def_builtin ("__builtin_altivec_stvx_v4sf", void_ftype_v4sf_long_pvoid,
15013 ALTIVEC_BUILTIN_STVX_V4SF);
15014 def_builtin ("__builtin_altivec_stvx_v4si", void_ftype_v4si_long_pvoid,
15015 ALTIVEC_BUILTIN_STVX_V4SI);
15016 def_builtin ("__builtin_altivec_stvx_v8hi", void_ftype_v8hi_long_pvoid,
15017 ALTIVEC_BUILTIN_STVX_V8HI);
15018 def_builtin ("__builtin_altivec_stvx_v16qi", void_ftype_v16qi_long_pvoid,
15019 ALTIVEC_BUILTIN_STVX_V16QI);
15020 def_builtin ("__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
15021 def_builtin ("__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
15022 def_builtin ("__builtin_altivec_stvxl_v2df", void_ftype_v2df_long_pvoid,
15023 ALTIVEC_BUILTIN_STVXL_V2DF);
15024 def_builtin ("__builtin_altivec_stvxl_v2di", void_ftype_v2di_long_pvoid,
15025 ALTIVEC_BUILTIN_STVXL_V2DI);
15026 def_builtin ("__builtin_altivec_stvxl_v4sf", void_ftype_v4sf_long_pvoid,
15027 ALTIVEC_BUILTIN_STVXL_V4SF);
15028 def_builtin ("__builtin_altivec_stvxl_v4si", void_ftype_v4si_long_pvoid,
15029 ALTIVEC_BUILTIN_STVXL_V4SI);
15030 def_builtin ("__builtin_altivec_stvxl_v8hi", void_ftype_v8hi_long_pvoid,
15031 ALTIVEC_BUILTIN_STVXL_V8HI);
15032 def_builtin ("__builtin_altivec_stvxl_v16qi", void_ftype_v16qi_long_pvoid,
15033 ALTIVEC_BUILTIN_STVXL_V16QI);
15034 def_builtin ("__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
15035 def_builtin ("__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
15036 def_builtin ("__builtin_vec_ld", opaque_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LD);
15037 def_builtin ("__builtin_vec_lde", opaque_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LDE);
15038 def_builtin ("__builtin_vec_ldl", opaque_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LDL);
15039 def_builtin ("__builtin_vec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVSL);
15040 def_builtin ("__builtin_vec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVSR);
15041 def_builtin ("__builtin_vec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVEBX);
15042 def_builtin ("__builtin_vec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVEHX);
15043 def_builtin ("__builtin_vec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVEWX);
15044 def_builtin ("__builtin_vec_st", void_ftype_opaque_long_pvoid, ALTIVEC_BUILTIN_VEC_ST);
15045 def_builtin ("__builtin_vec_ste", void_ftype_opaque_long_pvoid, ALTIVEC_BUILTIN_VEC_STE);
15046 def_builtin ("__builtin_vec_stl", void_ftype_opaque_long_pvoid, ALTIVEC_BUILTIN_VEC_STL);
15047 def_builtin ("__builtin_vec_stvewx", void_ftype_opaque_long_pvoid, ALTIVEC_BUILTIN_VEC_STVEWX);
15048 def_builtin ("__builtin_vec_stvebx", void_ftype_opaque_long_pvoid, ALTIVEC_BUILTIN_VEC_STVEBX);
15049 def_builtin ("__builtin_vec_stvehx", void_ftype_opaque_long_pvoid, ALTIVEC_BUILTIN_VEC_STVEHX);
15051 def_builtin ("__builtin_vsx_lxvd2x_v2df", v2df_ftype_long_pcvoid,
15052 VSX_BUILTIN_LXVD2X_V2DF);
15053 def_builtin ("__builtin_vsx_lxvd2x_v2di", v2di_ftype_long_pcvoid,
15054 VSX_BUILTIN_LXVD2X_V2DI);
15055 def_builtin ("__builtin_vsx_lxvw4x_v4sf", v4sf_ftype_long_pcvoid,
15056 VSX_BUILTIN_LXVW4X_V4SF);
15057 def_builtin ("__builtin_vsx_lxvw4x_v4si", v4si_ftype_long_pcvoid,
15058 VSX_BUILTIN_LXVW4X_V4SI);
15059 def_builtin ("__builtin_vsx_lxvw4x_v8hi", v8hi_ftype_long_pcvoid,
15060 VSX_BUILTIN_LXVW4X_V8HI);
15061 def_builtin ("__builtin_vsx_lxvw4x_v16qi", v16qi_ftype_long_pcvoid,
15062 VSX_BUILTIN_LXVW4X_V16QI);
15063 def_builtin ("__builtin_vsx_stxvd2x_v2df", void_ftype_v2df_long_pvoid,
15064 VSX_BUILTIN_STXVD2X_V2DF);
15065 def_builtin ("__builtin_vsx_stxvd2x_v2di", void_ftype_v2di_long_pvoid,
15066 VSX_BUILTIN_STXVD2X_V2DI);
15067 def_builtin ("__builtin_vsx_stxvw4x_v4sf", void_ftype_v4sf_long_pvoid,
15068 VSX_BUILTIN_STXVW4X_V4SF);
15069 def_builtin ("__builtin_vsx_stxvw4x_v4si", void_ftype_v4si_long_pvoid,
15070 VSX_BUILTIN_STXVW4X_V4SI);
15071 def_builtin ("__builtin_vsx_stxvw4x_v8hi", void_ftype_v8hi_long_pvoid,
15072 VSX_BUILTIN_STXVW4X_V8HI);
15073 def_builtin ("__builtin_vsx_stxvw4x_v16qi", void_ftype_v16qi_long_pvoid,
15074 VSX_BUILTIN_STXVW4X_V16QI);
15075 def_builtin ("__builtin_vec_vsx_ld", opaque_ftype_long_pcvoid,
15076 VSX_BUILTIN_VEC_LD);
15077 def_builtin ("__builtin_vec_vsx_st", void_ftype_opaque_long_pvoid,
15078 VSX_BUILTIN_VEC_ST);
15080 def_builtin ("__builtin_vec_step", int_ftype_opaque, ALTIVEC_BUILTIN_VEC_STEP);
15081 def_builtin ("__builtin_vec_splats", opaque_ftype_opaque, ALTIVEC_BUILTIN_VEC_SPLATS);
15082 def_builtin ("__builtin_vec_promote", opaque_ftype_opaque, ALTIVEC_BUILTIN_VEC_PROMOTE);
15084 def_builtin ("__builtin_vec_sld", opaque_ftype_opaque_opaque_int, ALTIVEC_BUILTIN_VEC_SLD);
15085 def_builtin ("__builtin_vec_splat", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_SPLAT);
15086 def_builtin ("__builtin_vec_extract", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_EXTRACT);
15087 def_builtin ("__builtin_vec_insert", opaque_ftype_opaque_opaque_int, ALTIVEC_BUILTIN_VEC_INSERT);
15088 def_builtin ("__builtin_vec_vspltw", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VSPLTW);
15089 def_builtin ("__builtin_vec_vsplth", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VSPLTH);
15090 def_builtin ("__builtin_vec_vspltb", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VSPLTB);
15091 def_builtin ("__builtin_vec_ctf", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_CTF);
15092 def_builtin ("__builtin_vec_vcfsx", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VCFSX);
15093 def_builtin ("__builtin_vec_vcfux", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_VCFUX);
15094 def_builtin ("__builtin_vec_cts", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_CTS);
15095 def_builtin ("__builtin_vec_ctu", opaque_ftype_opaque_int, ALTIVEC_BUILTIN_VEC_CTU);
15097 /* Cell builtins. */
15098 def_builtin ("__builtin_altivec_lvlx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVLX);
15099 def_builtin ("__builtin_altivec_lvlxl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVLXL);
15100 def_builtin ("__builtin_altivec_lvrx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVRX);
15101 def_builtin ("__builtin_altivec_lvrxl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVRXL);
15103 def_builtin ("__builtin_vec_lvlx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVLX);
15104 def_builtin ("__builtin_vec_lvlxl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVLXL);
15105 def_builtin ("__builtin_vec_lvrx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVRX);
15106 def_builtin ("__builtin_vec_lvrxl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_VEC_LVRXL);
15108 def_builtin ("__builtin_altivec_stvlx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVLX);
15109 def_builtin ("__builtin_altivec_stvlxl", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVLXL);
15110 def_builtin ("__builtin_altivec_stvrx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVRX);
15111 def_builtin ("__builtin_altivec_stvrxl", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVRXL);
15113 def_builtin ("__builtin_vec_stvlx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_VEC_STVLX);
15114 def_builtin ("__builtin_vec_stvlxl", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_VEC_STVLXL);
15115 def_builtin ("__builtin_vec_stvrx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_VEC_STVRX);
15116 def_builtin ("__builtin_vec_stvrxl", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_VEC_STVRXL);
15118 /* Add the DST variants. */
15119 d = bdesc_dst;
15120 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
15121 def_builtin (d->name, void_ftype_pcvoid_int_int, d->code);
15123 /* Initialize the predicates. */
15124 d = bdesc_altivec_preds;
15125 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, d++)
15127 machine_mode mode1;
15128 tree type;
15130 if (rs6000_overloaded_builtin_p (d->code))
15131 mode1 = VOIDmode;
15132 else
15133 mode1 = insn_data[d->icode].operand[1].mode;
15135 switch (mode1)
15137 case VOIDmode:
15138 type = int_ftype_int_opaque_opaque;
15139 break;
15140 case V2DImode:
15141 type = int_ftype_int_v2di_v2di;
15142 break;
15143 case V4SImode:
15144 type = int_ftype_int_v4si_v4si;
15145 break;
15146 case V8HImode:
15147 type = int_ftype_int_v8hi_v8hi;
15148 break;
15149 case V16QImode:
15150 type = int_ftype_int_v16qi_v16qi;
15151 break;
15152 case V4SFmode:
15153 type = int_ftype_int_v4sf_v4sf;
15154 break;
15155 case V2DFmode:
15156 type = int_ftype_int_v2df_v2df;
15157 break;
15158 default:
15159 gcc_unreachable ();
15162 def_builtin (d->name, type, d->code);
15165 /* Initialize the abs* operators. */
15166 d = bdesc_abs;
15167 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
15169 machine_mode mode0;
15170 tree type;
15172 mode0 = insn_data[d->icode].operand[0].mode;
15174 switch (mode0)
15176 case V2DImode:
15177 type = v2di_ftype_v2di;
15178 break;
15179 case V4SImode:
15180 type = v4si_ftype_v4si;
15181 break;
15182 case V8HImode:
15183 type = v8hi_ftype_v8hi;
15184 break;
15185 case V16QImode:
15186 type = v16qi_ftype_v16qi;
15187 break;
15188 case V4SFmode:
15189 type = v4sf_ftype_v4sf;
15190 break;
15191 case V2DFmode:
15192 type = v2df_ftype_v2df;
15193 break;
15194 default:
15195 gcc_unreachable ();
15198 def_builtin (d->name, type, d->code);
15201 /* Initialize target builtin that implements
15202 targetm.vectorize.builtin_mask_for_load. */
15204 decl = add_builtin_function ("__builtin_altivec_mask_for_load",
15205 v16qi_ftype_long_pcvoid,
15206 ALTIVEC_BUILTIN_MASK_FOR_LOAD,
15207 BUILT_IN_MD, NULL, NULL_TREE);
15208 TREE_READONLY (decl) = 1;
15209 /* Record the decl. Will be used by rs6000_builtin_mask_for_load. */
15210 altivec_builtin_mask_for_load = decl;
15212 /* Access to the vec_init patterns. */
15213 ftype = build_function_type_list (V4SI_type_node, integer_type_node,
15214 integer_type_node, integer_type_node,
15215 integer_type_node, NULL_TREE);
15216 def_builtin ("__builtin_vec_init_v4si", ftype, ALTIVEC_BUILTIN_VEC_INIT_V4SI);
15218 ftype = build_function_type_list (V8HI_type_node, short_integer_type_node,
15219 short_integer_type_node,
15220 short_integer_type_node,
15221 short_integer_type_node,
15222 short_integer_type_node,
15223 short_integer_type_node,
15224 short_integer_type_node,
15225 short_integer_type_node, NULL_TREE);
15226 def_builtin ("__builtin_vec_init_v8hi", ftype, ALTIVEC_BUILTIN_VEC_INIT_V8HI);
15228 ftype = build_function_type_list (V16QI_type_node, char_type_node,
15229 char_type_node, char_type_node,
15230 char_type_node, char_type_node,
15231 char_type_node, char_type_node,
15232 char_type_node, char_type_node,
15233 char_type_node, char_type_node,
15234 char_type_node, char_type_node,
15235 char_type_node, char_type_node,
15236 char_type_node, NULL_TREE);
15237 def_builtin ("__builtin_vec_init_v16qi", ftype,
15238 ALTIVEC_BUILTIN_VEC_INIT_V16QI);
15240 ftype = build_function_type_list (V4SF_type_node, float_type_node,
15241 float_type_node, float_type_node,
15242 float_type_node, NULL_TREE);
15243 def_builtin ("__builtin_vec_init_v4sf", ftype, ALTIVEC_BUILTIN_VEC_INIT_V4SF);
15245 /* VSX builtins. */
15246 ftype = build_function_type_list (V2DF_type_node, double_type_node,
15247 double_type_node, NULL_TREE);
15248 def_builtin ("__builtin_vec_init_v2df", ftype, VSX_BUILTIN_VEC_INIT_V2DF);
15250 ftype = build_function_type_list (V2DI_type_node, intDI_type_node,
15251 intDI_type_node, NULL_TREE);
15252 def_builtin ("__builtin_vec_init_v2di", ftype, VSX_BUILTIN_VEC_INIT_V2DI);
15254 /* Access to the vec_set patterns. */
15255 ftype = build_function_type_list (V4SI_type_node, V4SI_type_node,
15256 intSI_type_node,
15257 integer_type_node, NULL_TREE);
15258 def_builtin ("__builtin_vec_set_v4si", ftype, ALTIVEC_BUILTIN_VEC_SET_V4SI);
15260 ftype = build_function_type_list (V8HI_type_node, V8HI_type_node,
15261 intHI_type_node,
15262 integer_type_node, NULL_TREE);
15263 def_builtin ("__builtin_vec_set_v8hi", ftype, ALTIVEC_BUILTIN_VEC_SET_V8HI);
15265 ftype = build_function_type_list (V16QI_type_node, V16QI_type_node,
15266 intQI_type_node,
15267 integer_type_node, NULL_TREE);
15268 def_builtin ("__builtin_vec_set_v16qi", ftype, ALTIVEC_BUILTIN_VEC_SET_V16QI);
15270 ftype = build_function_type_list (V4SF_type_node, V4SF_type_node,
15271 float_type_node,
15272 integer_type_node, NULL_TREE);
15273 def_builtin ("__builtin_vec_set_v4sf", ftype, ALTIVEC_BUILTIN_VEC_SET_V4SF);
15275 ftype = build_function_type_list (V2DF_type_node, V2DF_type_node,
15276 double_type_node,
15277 integer_type_node, NULL_TREE);
15278 def_builtin ("__builtin_vec_set_v2df", ftype, VSX_BUILTIN_VEC_SET_V2DF);
15280 ftype = build_function_type_list (V2DI_type_node, V2DI_type_node,
15281 intDI_type_node,
15282 integer_type_node, NULL_TREE);
15283 def_builtin ("__builtin_vec_set_v2di", ftype, VSX_BUILTIN_VEC_SET_V2DI);
15285 /* Access to the vec_extract patterns. */
15286 ftype = build_function_type_list (intSI_type_node, V4SI_type_node,
15287 integer_type_node, NULL_TREE);
15288 def_builtin ("__builtin_vec_ext_v4si", ftype, ALTIVEC_BUILTIN_VEC_EXT_V4SI);
15290 ftype = build_function_type_list (intHI_type_node, V8HI_type_node,
15291 integer_type_node, NULL_TREE);
15292 def_builtin ("__builtin_vec_ext_v8hi", ftype, ALTIVEC_BUILTIN_VEC_EXT_V8HI);
15294 ftype = build_function_type_list (intQI_type_node, V16QI_type_node,
15295 integer_type_node, NULL_TREE);
15296 def_builtin ("__builtin_vec_ext_v16qi", ftype, ALTIVEC_BUILTIN_VEC_EXT_V16QI);
15298 ftype = build_function_type_list (float_type_node, V4SF_type_node,
15299 integer_type_node, NULL_TREE);
15300 def_builtin ("__builtin_vec_ext_v4sf", ftype, ALTIVEC_BUILTIN_VEC_EXT_V4SF);
15302 ftype = build_function_type_list (double_type_node, V2DF_type_node,
15303 integer_type_node, NULL_TREE);
15304 def_builtin ("__builtin_vec_ext_v2df", ftype, VSX_BUILTIN_VEC_EXT_V2DF);
15306 ftype = build_function_type_list (intDI_type_node, V2DI_type_node,
15307 integer_type_node, NULL_TREE);
15308 def_builtin ("__builtin_vec_ext_v2di", ftype, VSX_BUILTIN_VEC_EXT_V2DI);
15311 if (V1TI_type_node)
15313 tree v1ti_ftype_long_pcvoid
15314 = build_function_type_list (V1TI_type_node,
15315 long_integer_type_node, pcvoid_type_node,
15316 NULL_TREE);
15317 tree void_ftype_v1ti_long_pvoid
15318 = build_function_type_list (void_type_node,
15319 V1TI_type_node, long_integer_type_node,
15320 pvoid_type_node, NULL_TREE);
15321 def_builtin ("__builtin_vsx_lxvd2x_v1ti", v1ti_ftype_long_pcvoid,
15322 VSX_BUILTIN_LXVD2X_V1TI);
15323 def_builtin ("__builtin_vsx_stxvd2x_v1ti", void_ftype_v1ti_long_pvoid,
15324 VSX_BUILTIN_STXVD2X_V1TI);
15325 ftype = build_function_type_list (V1TI_type_node, intTI_type_node,
15326 NULL_TREE, NULL_TREE);
15327 def_builtin ("__builtin_vec_init_v1ti", ftype, VSX_BUILTIN_VEC_INIT_V1TI);
15328 ftype = build_function_type_list (V1TI_type_node, V1TI_type_node,
15329 intTI_type_node,
15330 integer_type_node, NULL_TREE);
15331 def_builtin ("__builtin_vec_set_v1ti", ftype, VSX_BUILTIN_VEC_SET_V1TI);
15332 ftype = build_function_type_list (intTI_type_node, V1TI_type_node,
15333 integer_type_node, NULL_TREE);
15334 def_builtin ("__builtin_vec_ext_v1ti", ftype, VSX_BUILTIN_VEC_EXT_V1TI);
15339 static void
15340 htm_init_builtins (void)
15342 HOST_WIDE_INT builtin_mask = rs6000_builtin_mask;
15343 const struct builtin_description *d;
15344 size_t i;
15346 d = bdesc_htm;
15347 for (i = 0; i < ARRAY_SIZE (bdesc_htm); i++, d++)
15349 tree op[MAX_HTM_OPERANDS], type;
15350 HOST_WIDE_INT mask = d->mask;
15351 unsigned attr = rs6000_builtin_info[d->code].attr;
15352 bool void_func = (attr & RS6000_BTC_VOID);
15353 int attr_args = (attr & RS6000_BTC_TYPE_MASK);
15354 int nopnds = 0;
15355 tree gpr_type_node;
15356 tree rettype;
15357 tree argtype;
15359 if (TARGET_32BIT && TARGET_POWERPC64)
15360 gpr_type_node = long_long_unsigned_type_node;
15361 else
15362 gpr_type_node = long_unsigned_type_node;
15364 if (attr & RS6000_BTC_SPR)
15366 rettype = gpr_type_node;
15367 argtype = gpr_type_node;
15369 else if (d->code == HTM_BUILTIN_TABORTDC
15370 || d->code == HTM_BUILTIN_TABORTDCI)
15372 rettype = unsigned_type_node;
15373 argtype = gpr_type_node;
15375 else
15377 rettype = unsigned_type_node;
15378 argtype = unsigned_type_node;
15381 if ((mask & builtin_mask) != mask)
15383 if (TARGET_DEBUG_BUILTIN)
15384 fprintf (stderr, "htm_builtin, skip binary %s\n", d->name);
15385 continue;
15388 if (d->name == 0)
15390 if (TARGET_DEBUG_BUILTIN)
15391 fprintf (stderr, "htm_builtin, bdesc_htm[%ld] no name\n",
15392 (long unsigned) i);
15393 continue;
15396 op[nopnds++] = (void_func) ? void_type_node : rettype;
15398 if (attr_args == RS6000_BTC_UNARY)
15399 op[nopnds++] = argtype;
15400 else if (attr_args == RS6000_BTC_BINARY)
15402 op[nopnds++] = argtype;
15403 op[nopnds++] = argtype;
15405 else if (attr_args == RS6000_BTC_TERNARY)
15407 op[nopnds++] = argtype;
15408 op[nopnds++] = argtype;
15409 op[nopnds++] = argtype;
15412 switch (nopnds)
15414 case 1:
15415 type = build_function_type_list (op[0], NULL_TREE);
15416 break;
15417 case 2:
15418 type = build_function_type_list (op[0], op[1], NULL_TREE);
15419 break;
15420 case 3:
15421 type = build_function_type_list (op[0], op[1], op[2], NULL_TREE);
15422 break;
15423 case 4:
15424 type = build_function_type_list (op[0], op[1], op[2], op[3],
15425 NULL_TREE);
15426 break;
15427 default:
15428 gcc_unreachable ();
15431 def_builtin (d->name, type, d->code);
15435 /* Hash function for builtin functions with up to 3 arguments and a return
15436 type. */
15437 hashval_t
15438 builtin_hasher::hash (builtin_hash_struct *bh)
15440 unsigned ret = 0;
15441 int i;
15443 for (i = 0; i < 4; i++)
15445 ret = (ret * (unsigned)MAX_MACHINE_MODE) + ((unsigned)bh->mode[i]);
15446 ret = (ret * 2) + bh->uns_p[i];
15449 return ret;
15452 /* Compare builtin hash entries H1 and H2 for equivalence. */
15453 bool
15454 builtin_hasher::equal (builtin_hash_struct *p1, builtin_hash_struct *p2)
15456 return ((p1->mode[0] == p2->mode[0])
15457 && (p1->mode[1] == p2->mode[1])
15458 && (p1->mode[2] == p2->mode[2])
15459 && (p1->mode[3] == p2->mode[3])
15460 && (p1->uns_p[0] == p2->uns_p[0])
15461 && (p1->uns_p[1] == p2->uns_p[1])
15462 && (p1->uns_p[2] == p2->uns_p[2])
15463 && (p1->uns_p[3] == p2->uns_p[3]));
15466 /* Map types for builtin functions with an explicit return type and up to 3
15467 arguments. Functions with fewer than 3 arguments use VOIDmode as the type
15468 of the argument. */
15469 static tree
15470 builtin_function_type (machine_mode mode_ret, machine_mode mode_arg0,
15471 machine_mode mode_arg1, machine_mode mode_arg2,
15472 enum rs6000_builtins builtin, const char *name)
15474 struct builtin_hash_struct h;
15475 struct builtin_hash_struct *h2;
15476 int num_args = 3;
15477 int i;
15478 tree ret_type = NULL_TREE;
15479 tree arg_type[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
15481 /* Create builtin_hash_table. */
15482 if (builtin_hash_table == NULL)
15483 builtin_hash_table = hash_table<builtin_hasher>::create_ggc (1500);
15485 h.type = NULL_TREE;
15486 h.mode[0] = mode_ret;
15487 h.mode[1] = mode_arg0;
15488 h.mode[2] = mode_arg1;
15489 h.mode[3] = mode_arg2;
15490 h.uns_p[0] = 0;
15491 h.uns_p[1] = 0;
15492 h.uns_p[2] = 0;
15493 h.uns_p[3] = 0;
15495 /* If the builtin is a type that produces unsigned results or takes unsigned
15496 arguments, and it is returned as a decl for the vectorizer (such as
15497 widening multiplies, permute), make sure the arguments and return value
15498 are type correct. */
15499 switch (builtin)
15501 /* unsigned 1 argument functions. */
15502 case CRYPTO_BUILTIN_VSBOX:
15503 case P8V_BUILTIN_VGBBD:
15504 case MISC_BUILTIN_CDTBCD:
15505 case MISC_BUILTIN_CBCDTD:
15506 h.uns_p[0] = 1;
15507 h.uns_p[1] = 1;
15508 break;
15510 /* unsigned 2 argument functions. */
15511 case ALTIVEC_BUILTIN_VMULEUB_UNS:
15512 case ALTIVEC_BUILTIN_VMULEUH_UNS:
15513 case ALTIVEC_BUILTIN_VMULOUB_UNS:
15514 case ALTIVEC_BUILTIN_VMULOUH_UNS:
15515 case CRYPTO_BUILTIN_VCIPHER:
15516 case CRYPTO_BUILTIN_VCIPHERLAST:
15517 case CRYPTO_BUILTIN_VNCIPHER:
15518 case CRYPTO_BUILTIN_VNCIPHERLAST:
15519 case CRYPTO_BUILTIN_VPMSUMB:
15520 case CRYPTO_BUILTIN_VPMSUMH:
15521 case CRYPTO_BUILTIN_VPMSUMW:
15522 case CRYPTO_BUILTIN_VPMSUMD:
15523 case CRYPTO_BUILTIN_VPMSUM:
15524 case MISC_BUILTIN_ADDG6S:
15525 case MISC_BUILTIN_DIVWEU:
15526 case MISC_BUILTIN_DIVWEUO:
15527 case MISC_BUILTIN_DIVDEU:
15528 case MISC_BUILTIN_DIVDEUO:
15529 h.uns_p[0] = 1;
15530 h.uns_p[1] = 1;
15531 h.uns_p[2] = 1;
15532 break;
15534 /* unsigned 3 argument functions. */
15535 case ALTIVEC_BUILTIN_VPERM_16QI_UNS:
15536 case ALTIVEC_BUILTIN_VPERM_8HI_UNS:
15537 case ALTIVEC_BUILTIN_VPERM_4SI_UNS:
15538 case ALTIVEC_BUILTIN_VPERM_2DI_UNS:
15539 case ALTIVEC_BUILTIN_VSEL_16QI_UNS:
15540 case ALTIVEC_BUILTIN_VSEL_8HI_UNS:
15541 case ALTIVEC_BUILTIN_VSEL_4SI_UNS:
15542 case ALTIVEC_BUILTIN_VSEL_2DI_UNS:
15543 case VSX_BUILTIN_VPERM_16QI_UNS:
15544 case VSX_BUILTIN_VPERM_8HI_UNS:
15545 case VSX_BUILTIN_VPERM_4SI_UNS:
15546 case VSX_BUILTIN_VPERM_2DI_UNS:
15547 case VSX_BUILTIN_XXSEL_16QI_UNS:
15548 case VSX_BUILTIN_XXSEL_8HI_UNS:
15549 case VSX_BUILTIN_XXSEL_4SI_UNS:
15550 case VSX_BUILTIN_XXSEL_2DI_UNS:
15551 case CRYPTO_BUILTIN_VPERMXOR:
15552 case CRYPTO_BUILTIN_VPERMXOR_V2DI:
15553 case CRYPTO_BUILTIN_VPERMXOR_V4SI:
15554 case CRYPTO_BUILTIN_VPERMXOR_V8HI:
15555 case CRYPTO_BUILTIN_VPERMXOR_V16QI:
15556 case CRYPTO_BUILTIN_VSHASIGMAW:
15557 case CRYPTO_BUILTIN_VSHASIGMAD:
15558 case CRYPTO_BUILTIN_VSHASIGMA:
15559 h.uns_p[0] = 1;
15560 h.uns_p[1] = 1;
15561 h.uns_p[2] = 1;
15562 h.uns_p[3] = 1;
15563 break;
15565 /* signed permute functions with unsigned char mask. */
15566 case ALTIVEC_BUILTIN_VPERM_16QI:
15567 case ALTIVEC_BUILTIN_VPERM_8HI:
15568 case ALTIVEC_BUILTIN_VPERM_4SI:
15569 case ALTIVEC_BUILTIN_VPERM_4SF:
15570 case ALTIVEC_BUILTIN_VPERM_2DI:
15571 case ALTIVEC_BUILTIN_VPERM_2DF:
15572 case VSX_BUILTIN_VPERM_16QI:
15573 case VSX_BUILTIN_VPERM_8HI:
15574 case VSX_BUILTIN_VPERM_4SI:
15575 case VSX_BUILTIN_VPERM_4SF:
15576 case VSX_BUILTIN_VPERM_2DI:
15577 case VSX_BUILTIN_VPERM_2DF:
15578 h.uns_p[3] = 1;
15579 break;
15581 /* unsigned args, signed return. */
15582 case VSX_BUILTIN_XVCVUXDDP_UNS:
15583 case ALTIVEC_BUILTIN_UNSFLOAT_V4SI_V4SF:
15584 h.uns_p[1] = 1;
15585 break;
15587 /* signed args, unsigned return. */
15588 case VSX_BUILTIN_XVCVDPUXDS_UNS:
15589 case ALTIVEC_BUILTIN_FIXUNS_V4SF_V4SI:
15590 case MISC_BUILTIN_UNPACK_TD:
15591 case MISC_BUILTIN_UNPACK_V1TI:
15592 h.uns_p[0] = 1;
15593 break;
15595 /* unsigned arguments for 128-bit pack instructions. */
15596 case MISC_BUILTIN_PACK_TD:
15597 case MISC_BUILTIN_PACK_V1TI:
15598 h.uns_p[1] = 1;
15599 h.uns_p[2] = 1;
15600 break;
15602 default:
15603 break;
15606 /* Figure out how many args are present. */
15607 while (num_args > 0 && h.mode[num_args] == VOIDmode)
15608 num_args--;
15610 if (num_args == 0)
15611 fatal_error (input_location,
15612 "internal error: builtin function %s had no type", name);
15614 ret_type = builtin_mode_to_type[h.mode[0]][h.uns_p[0]];
15615 if (!ret_type && h.uns_p[0])
15616 ret_type = builtin_mode_to_type[h.mode[0]][0];
15618 if (!ret_type)
15619 fatal_error (input_location,
15620 "internal error: builtin function %s had an unexpected "
15621 "return type %s", name, GET_MODE_NAME (h.mode[0]));
15623 for (i = 0; i < (int) ARRAY_SIZE (arg_type); i++)
15624 arg_type[i] = NULL_TREE;
15626 for (i = 0; i < num_args; i++)
15628 int m = (int) h.mode[i+1];
15629 int uns_p = h.uns_p[i+1];
15631 arg_type[i] = builtin_mode_to_type[m][uns_p];
15632 if (!arg_type[i] && uns_p)
15633 arg_type[i] = builtin_mode_to_type[m][0];
15635 if (!arg_type[i])
15636 fatal_error (input_location,
15637 "internal error: builtin function %s, argument %d "
15638 "had unexpected argument type %s", name, i,
15639 GET_MODE_NAME (m));
15642 builtin_hash_struct **found = builtin_hash_table->find_slot (&h, INSERT);
15643 if (*found == NULL)
15645 h2 = ggc_alloc<builtin_hash_struct> ();
15646 *h2 = h;
15647 *found = h2;
15649 h2->type = build_function_type_list (ret_type, arg_type[0], arg_type[1],
15650 arg_type[2], NULL_TREE);
15653 return (*found)->type;
15656 static void
15657 rs6000_common_init_builtins (void)
15659 const struct builtin_description *d;
15660 size_t i;
15662 tree opaque_ftype_opaque = NULL_TREE;
15663 tree opaque_ftype_opaque_opaque = NULL_TREE;
15664 tree opaque_ftype_opaque_opaque_opaque = NULL_TREE;
15665 tree v2si_ftype_qi = NULL_TREE;
15666 tree v2si_ftype_v2si_qi = NULL_TREE;
15667 tree v2si_ftype_int_qi = NULL_TREE;
15668 HOST_WIDE_INT builtin_mask = rs6000_builtin_mask;
15670 if (!TARGET_PAIRED_FLOAT)
15672 builtin_mode_to_type[V2SImode][0] = opaque_V2SI_type_node;
15673 builtin_mode_to_type[V2SFmode][0] = opaque_V2SF_type_node;
15676 /* Paired and SPE builtins are only available if you build a compiler with
15677 the appropriate options, so only create those builtins with the
15678 appropriate compiler option. Create Altivec and VSX builtins on machines
15679 with at least the general purpose extensions (970 and newer) to allow the
15680 use of the target attribute.. */
15682 if (TARGET_EXTRA_BUILTINS)
15683 builtin_mask |= RS6000_BTM_COMMON;
15685 /* Add the ternary operators. */
15686 d = bdesc_3arg;
15687 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
15689 tree type;
15690 HOST_WIDE_INT mask = d->mask;
15692 if ((mask & builtin_mask) != mask)
15694 if (TARGET_DEBUG_BUILTIN)
15695 fprintf (stderr, "rs6000_builtin, skip ternary %s\n", d->name);
15696 continue;
15699 if (rs6000_overloaded_builtin_p (d->code))
15701 if (! (type = opaque_ftype_opaque_opaque_opaque))
15702 type = opaque_ftype_opaque_opaque_opaque
15703 = build_function_type_list (opaque_V4SI_type_node,
15704 opaque_V4SI_type_node,
15705 opaque_V4SI_type_node,
15706 opaque_V4SI_type_node,
15707 NULL_TREE);
15709 else
15711 enum insn_code icode = d->icode;
15712 if (d->name == 0)
15714 if (TARGET_DEBUG_BUILTIN)
15715 fprintf (stderr, "rs6000_builtin, bdesc_3arg[%ld] no name\n",
15716 (long unsigned)i);
15718 continue;
15721 if (icode == CODE_FOR_nothing)
15723 if (TARGET_DEBUG_BUILTIN)
15724 fprintf (stderr, "rs6000_builtin, skip ternary %s (no code)\n",
15725 d->name);
15727 continue;
15730 type = builtin_function_type (insn_data[icode].operand[0].mode,
15731 insn_data[icode].operand[1].mode,
15732 insn_data[icode].operand[2].mode,
15733 insn_data[icode].operand[3].mode,
15734 d->code, d->name);
15737 def_builtin (d->name, type, d->code);
15740 /* Add the binary operators. */
15741 d = bdesc_2arg;
15742 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
15744 machine_mode mode0, mode1, mode2;
15745 tree type;
15746 HOST_WIDE_INT mask = d->mask;
15748 if ((mask & builtin_mask) != mask)
15750 if (TARGET_DEBUG_BUILTIN)
15751 fprintf (stderr, "rs6000_builtin, skip binary %s\n", d->name);
15752 continue;
15755 if (rs6000_overloaded_builtin_p (d->code))
15757 if (! (type = opaque_ftype_opaque_opaque))
15758 type = opaque_ftype_opaque_opaque
15759 = build_function_type_list (opaque_V4SI_type_node,
15760 opaque_V4SI_type_node,
15761 opaque_V4SI_type_node,
15762 NULL_TREE);
15764 else
15766 enum insn_code icode = d->icode;
15767 if (d->name == 0)
15769 if (TARGET_DEBUG_BUILTIN)
15770 fprintf (stderr, "rs6000_builtin, bdesc_2arg[%ld] no name\n",
15771 (long unsigned)i);
15773 continue;
15776 if (icode == CODE_FOR_nothing)
15778 if (TARGET_DEBUG_BUILTIN)
15779 fprintf (stderr, "rs6000_builtin, skip binary %s (no code)\n",
15780 d->name);
15782 continue;
15785 mode0 = insn_data[icode].operand[0].mode;
15786 mode1 = insn_data[icode].operand[1].mode;
15787 mode2 = insn_data[icode].operand[2].mode;
15789 if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
15791 if (! (type = v2si_ftype_v2si_qi))
15792 type = v2si_ftype_v2si_qi
15793 = build_function_type_list (opaque_V2SI_type_node,
15794 opaque_V2SI_type_node,
15795 char_type_node,
15796 NULL_TREE);
15799 else if (mode0 == V2SImode && GET_MODE_CLASS (mode1) == MODE_INT
15800 && mode2 == QImode)
15802 if (! (type = v2si_ftype_int_qi))
15803 type = v2si_ftype_int_qi
15804 = build_function_type_list (opaque_V2SI_type_node,
15805 integer_type_node,
15806 char_type_node,
15807 NULL_TREE);
15810 else
15811 type = builtin_function_type (mode0, mode1, mode2, VOIDmode,
15812 d->code, d->name);
15815 def_builtin (d->name, type, d->code);
15818 /* Add the simple unary operators. */
15819 d = bdesc_1arg;
15820 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
15822 machine_mode mode0, mode1;
15823 tree type;
15824 HOST_WIDE_INT mask = d->mask;
15826 if ((mask & builtin_mask) != mask)
15828 if (TARGET_DEBUG_BUILTIN)
15829 fprintf (stderr, "rs6000_builtin, skip unary %s\n", d->name);
15830 continue;
15833 if (rs6000_overloaded_builtin_p (d->code))
15835 if (! (type = opaque_ftype_opaque))
15836 type = opaque_ftype_opaque
15837 = build_function_type_list (opaque_V4SI_type_node,
15838 opaque_V4SI_type_node,
15839 NULL_TREE);
15841 else
15843 enum insn_code icode = d->icode;
15844 if (d->name == 0)
15846 if (TARGET_DEBUG_BUILTIN)
15847 fprintf (stderr, "rs6000_builtin, bdesc_1arg[%ld] no name\n",
15848 (long unsigned)i);
15850 continue;
15853 if (icode == CODE_FOR_nothing)
15855 if (TARGET_DEBUG_BUILTIN)
15856 fprintf (stderr, "rs6000_builtin, skip unary %s (no code)\n",
15857 d->name);
15859 continue;
15862 mode0 = insn_data[icode].operand[0].mode;
15863 mode1 = insn_data[icode].operand[1].mode;
15865 if (mode0 == V2SImode && mode1 == QImode)
15867 if (! (type = v2si_ftype_qi))
15868 type = v2si_ftype_qi
15869 = build_function_type_list (opaque_V2SI_type_node,
15870 char_type_node,
15871 NULL_TREE);
15874 else
15875 type = builtin_function_type (mode0, mode1, VOIDmode, VOIDmode,
15876 d->code, d->name);
15879 def_builtin (d->name, type, d->code);
15883 static void
15884 rs6000_init_libfuncs (void)
15886 if (!TARGET_IEEEQUAD)
15887 /* AIX/Darwin/64-bit Linux quad floating point routines. */
15888 if (!TARGET_XL_COMPAT)
15890 set_optab_libfunc (add_optab, TFmode, "__gcc_qadd");
15891 set_optab_libfunc (sub_optab, TFmode, "__gcc_qsub");
15892 set_optab_libfunc (smul_optab, TFmode, "__gcc_qmul");
15893 set_optab_libfunc (sdiv_optab, TFmode, "__gcc_qdiv");
15895 if (!(TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)))
15897 set_optab_libfunc (neg_optab, TFmode, "__gcc_qneg");
15898 set_optab_libfunc (eq_optab, TFmode, "__gcc_qeq");
15899 set_optab_libfunc (ne_optab, TFmode, "__gcc_qne");
15900 set_optab_libfunc (gt_optab, TFmode, "__gcc_qgt");
15901 set_optab_libfunc (ge_optab, TFmode, "__gcc_qge");
15902 set_optab_libfunc (lt_optab, TFmode, "__gcc_qlt");
15903 set_optab_libfunc (le_optab, TFmode, "__gcc_qle");
15905 set_conv_libfunc (sext_optab, TFmode, SFmode, "__gcc_stoq");
15906 set_conv_libfunc (sext_optab, TFmode, DFmode, "__gcc_dtoq");
15907 set_conv_libfunc (trunc_optab, SFmode, TFmode, "__gcc_qtos");
15908 set_conv_libfunc (trunc_optab, DFmode, TFmode, "__gcc_qtod");
15909 set_conv_libfunc (sfix_optab, SImode, TFmode, "__gcc_qtoi");
15910 set_conv_libfunc (ufix_optab, SImode, TFmode, "__gcc_qtou");
15911 set_conv_libfunc (sfloat_optab, TFmode, SImode, "__gcc_itoq");
15912 set_conv_libfunc (ufloat_optab, TFmode, SImode, "__gcc_utoq");
15915 if (!(TARGET_HARD_FLOAT && TARGET_FPRS))
15916 set_optab_libfunc (unord_optab, TFmode, "__gcc_qunord");
15918 else
15920 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
15921 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
15922 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
15923 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
15925 else
15927 /* 32-bit SVR4 quad floating point routines. */
15929 set_optab_libfunc (add_optab, TFmode, "_q_add");
15930 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
15931 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
15932 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
15933 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
15934 if (TARGET_PPC_GPOPT)
15935 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
15937 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
15938 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
15939 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
15940 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
15941 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
15942 set_optab_libfunc (le_optab, TFmode, "_q_fle");
15944 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
15945 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
15946 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
15947 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
15948 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
15949 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
15950 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
15951 set_conv_libfunc (ufloat_optab, TFmode, SImode, "_q_utoq");
15956 /* Expand a block clear operation, and return 1 if successful. Return 0
15957 if we should let the compiler generate normal code.
15959 operands[0] is the destination
15960 operands[1] is the length
15961 operands[3] is the alignment */
15964 expand_block_clear (rtx operands[])
15966 rtx orig_dest = operands[0];
15967 rtx bytes_rtx = operands[1];
15968 rtx align_rtx = operands[3];
15969 bool constp = (GET_CODE (bytes_rtx) == CONST_INT);
15970 HOST_WIDE_INT align;
15971 HOST_WIDE_INT bytes;
15972 int offset;
15973 int clear_bytes;
15974 int clear_step;
15976 /* If this is not a fixed size move, just call memcpy */
15977 if (! constp)
15978 return 0;
15980 /* This must be a fixed size alignment */
15981 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
15982 align = INTVAL (align_rtx) * BITS_PER_UNIT;
15984 /* Anything to clear? */
15985 bytes = INTVAL (bytes_rtx);
15986 if (bytes <= 0)
15987 return 1;
15989 /* Use the builtin memset after a point, to avoid huge code bloat.
15990 When optimize_size, avoid any significant code bloat; calling
15991 memset is about 4 instructions, so allow for one instruction to
15992 load zero and three to do clearing. */
15993 if (TARGET_ALTIVEC && align >= 128)
15994 clear_step = 16;
15995 else if (TARGET_POWERPC64 && (align >= 64 || !STRICT_ALIGNMENT))
15996 clear_step = 8;
15997 else if (TARGET_SPE && align >= 64)
15998 clear_step = 8;
15999 else
16000 clear_step = 4;
16002 if (optimize_size && bytes > 3 * clear_step)
16003 return 0;
16004 if (! optimize_size && bytes > 8 * clear_step)
16005 return 0;
16007 for (offset = 0; bytes > 0; offset += clear_bytes, bytes -= clear_bytes)
16009 machine_mode mode = BLKmode;
16010 rtx dest;
16012 if (bytes >= 16 && TARGET_ALTIVEC && align >= 128)
16014 clear_bytes = 16;
16015 mode = V4SImode;
16017 else if (bytes >= 8 && TARGET_SPE && align >= 64)
16019 clear_bytes = 8;
16020 mode = V2SImode;
16022 else if (bytes >= 8 && TARGET_POWERPC64
16023 && (align >= 64 || !STRICT_ALIGNMENT))
16025 clear_bytes = 8;
16026 mode = DImode;
16027 if (offset == 0 && align < 64)
16029 rtx addr;
16031 /* If the address form is reg+offset with offset not a
16032 multiple of four, reload into reg indirect form here
16033 rather than waiting for reload. This way we get one
16034 reload, not one per store. */
16035 addr = XEXP (orig_dest, 0);
16036 if ((GET_CODE (addr) == PLUS || GET_CODE (addr) == LO_SUM)
16037 && GET_CODE (XEXP (addr, 1)) == CONST_INT
16038 && (INTVAL (XEXP (addr, 1)) & 3) != 0)
16040 addr = copy_addr_to_reg (addr);
16041 orig_dest = replace_equiv_address (orig_dest, addr);
16045 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
16046 { /* move 4 bytes */
16047 clear_bytes = 4;
16048 mode = SImode;
16050 else if (bytes >= 2 && (align >= 16 || !STRICT_ALIGNMENT))
16051 { /* move 2 bytes */
16052 clear_bytes = 2;
16053 mode = HImode;
16055 else /* move 1 byte at a time */
16057 clear_bytes = 1;
16058 mode = QImode;
16061 dest = adjust_address (orig_dest, mode, offset);
16063 emit_move_insn (dest, CONST0_RTX (mode));
16066 return 1;
16070 /* Expand a block move operation, and return 1 if successful. Return 0
16071 if we should let the compiler generate normal code.
16073 operands[0] is the destination
16074 operands[1] is the source
16075 operands[2] is the length
16076 operands[3] is the alignment */
16078 #define MAX_MOVE_REG 4
16081 expand_block_move (rtx operands[])
16083 rtx orig_dest = operands[0];
16084 rtx orig_src = operands[1];
16085 rtx bytes_rtx = operands[2];
16086 rtx align_rtx = operands[3];
16087 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
16088 int align;
16089 int bytes;
16090 int offset;
16091 int move_bytes;
16092 rtx stores[MAX_MOVE_REG];
16093 int num_reg = 0;
16095 /* If this is not a fixed size move, just call memcpy */
16096 if (! constp)
16097 return 0;
16099 /* This must be a fixed size alignment */
16100 gcc_assert (GET_CODE (align_rtx) == CONST_INT);
16101 align = INTVAL (align_rtx) * BITS_PER_UNIT;
16103 /* Anything to move? */
16104 bytes = INTVAL (bytes_rtx);
16105 if (bytes <= 0)
16106 return 1;
16108 if (bytes > rs6000_block_move_inline_limit)
16109 return 0;
16111 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
16113 union {
16114 rtx (*movmemsi) (rtx, rtx, rtx, rtx);
16115 rtx (*mov) (rtx, rtx);
16116 } gen_func;
16117 machine_mode mode = BLKmode;
16118 rtx src, dest;
16120 /* Altivec first, since it will be faster than a string move
16121 when it applies, and usually not significantly larger. */
16122 if (TARGET_ALTIVEC && bytes >= 16 && align >= 128)
16124 move_bytes = 16;
16125 mode = V4SImode;
16126 gen_func.mov = gen_movv4si;
16128 else if (TARGET_SPE && bytes >= 8 && align >= 64)
16130 move_bytes = 8;
16131 mode = V2SImode;
16132 gen_func.mov = gen_movv2si;
16134 else if (TARGET_STRING
16135 && bytes > 24 /* move up to 32 bytes at a time */
16136 && ! fixed_regs[5]
16137 && ! fixed_regs[6]
16138 && ! fixed_regs[7]
16139 && ! fixed_regs[8]
16140 && ! fixed_regs[9]
16141 && ! fixed_regs[10]
16142 && ! fixed_regs[11]
16143 && ! fixed_regs[12])
16145 move_bytes = (bytes > 32) ? 32 : bytes;
16146 gen_func.movmemsi = gen_movmemsi_8reg;
16148 else if (TARGET_STRING
16149 && bytes > 16 /* move up to 24 bytes at a time */
16150 && ! fixed_regs[5]
16151 && ! fixed_regs[6]
16152 && ! fixed_regs[7]
16153 && ! fixed_regs[8]
16154 && ! fixed_regs[9]
16155 && ! fixed_regs[10])
16157 move_bytes = (bytes > 24) ? 24 : bytes;
16158 gen_func.movmemsi = gen_movmemsi_6reg;
16160 else if (TARGET_STRING
16161 && bytes > 8 /* move up to 16 bytes at a time */
16162 && ! fixed_regs[5]
16163 && ! fixed_regs[6]
16164 && ! fixed_regs[7]
16165 && ! fixed_regs[8])
16167 move_bytes = (bytes > 16) ? 16 : bytes;
16168 gen_func.movmemsi = gen_movmemsi_4reg;
16170 else if (bytes >= 8 && TARGET_POWERPC64
16171 && (align >= 64 || !STRICT_ALIGNMENT))
16173 move_bytes = 8;
16174 mode = DImode;
16175 gen_func.mov = gen_movdi;
16176 if (offset == 0 && align < 64)
16178 rtx addr;
16180 /* If the address form is reg+offset with offset not a
16181 multiple of four, reload into reg indirect form here
16182 rather than waiting for reload. This way we get one
16183 reload, not one per load and/or store. */
16184 addr = XEXP (orig_dest, 0);
16185 if ((GET_CODE (addr) == PLUS || GET_CODE (addr) == LO_SUM)
16186 && GET_CODE (XEXP (addr, 1)) == CONST_INT
16187 && (INTVAL (XEXP (addr, 1)) & 3) != 0)
16189 addr = copy_addr_to_reg (addr);
16190 orig_dest = replace_equiv_address (orig_dest, addr);
16192 addr = XEXP (orig_src, 0);
16193 if ((GET_CODE (addr) == PLUS || GET_CODE (addr) == LO_SUM)
16194 && GET_CODE (XEXP (addr, 1)) == CONST_INT
16195 && (INTVAL (XEXP (addr, 1)) & 3) != 0)
16197 addr = copy_addr_to_reg (addr);
16198 orig_src = replace_equiv_address (orig_src, addr);
16202 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
16203 { /* move up to 8 bytes at a time */
16204 move_bytes = (bytes > 8) ? 8 : bytes;
16205 gen_func.movmemsi = gen_movmemsi_2reg;
16207 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
16208 { /* move 4 bytes */
16209 move_bytes = 4;
16210 mode = SImode;
16211 gen_func.mov = gen_movsi;
16213 else if (bytes >= 2 && (align >= 16 || !STRICT_ALIGNMENT))
16214 { /* move 2 bytes */
16215 move_bytes = 2;
16216 mode = HImode;
16217 gen_func.mov = gen_movhi;
16219 else if (TARGET_STRING && bytes > 1)
16220 { /* move up to 4 bytes at a time */
16221 move_bytes = (bytes > 4) ? 4 : bytes;
16222 gen_func.movmemsi = gen_movmemsi_1reg;
16224 else /* move 1 byte at a time */
16226 move_bytes = 1;
16227 mode = QImode;
16228 gen_func.mov = gen_movqi;
16231 src = adjust_address (orig_src, mode, offset);
16232 dest = adjust_address (orig_dest, mode, offset);
16234 if (mode != BLKmode)
16236 rtx tmp_reg = gen_reg_rtx (mode);
16238 emit_insn ((*gen_func.mov) (tmp_reg, src));
16239 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
16242 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
16244 int i;
16245 for (i = 0; i < num_reg; i++)
16246 emit_insn (stores[i]);
16247 num_reg = 0;
16250 if (mode == BLKmode)
16252 /* Move the address into scratch registers. The movmemsi
16253 patterns require zero offset. */
16254 if (!REG_P (XEXP (src, 0)))
16256 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
16257 src = replace_equiv_address (src, src_reg);
16259 set_mem_size (src, move_bytes);
16261 if (!REG_P (XEXP (dest, 0)))
16263 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
16264 dest = replace_equiv_address (dest, dest_reg);
16266 set_mem_size (dest, move_bytes);
16268 emit_insn ((*gen_func.movmemsi) (dest, src,
16269 GEN_INT (move_bytes & 31),
16270 align_rtx));
16274 return 1;
16278 /* Return a string to perform a load_multiple operation.
16279 operands[0] is the vector.
16280 operands[1] is the source address.
16281 operands[2] is the first destination register. */
16283 const char *
16284 rs6000_output_load_multiple (rtx operands[3])
16286 /* We have to handle the case where the pseudo used to contain the address
16287 is assigned to one of the output registers. */
16288 int i, j;
16289 int words = XVECLEN (operands[0], 0);
16290 rtx xop[10];
16292 if (XVECLEN (operands[0], 0) == 1)
16293 return "lwz %2,0(%1)";
16295 for (i = 0; i < words; i++)
16296 if (refers_to_regno_p (REGNO (operands[2]) + i, operands[1]))
16298 if (i == words-1)
16300 xop[0] = GEN_INT (4 * (words-1));
16301 xop[1] = operands[1];
16302 xop[2] = operands[2];
16303 output_asm_insn ("lswi %2,%1,%0\n\tlwz %1,%0(%1)", xop);
16304 return "";
16306 else if (i == 0)
16308 xop[0] = GEN_INT (4 * (words-1));
16309 xop[1] = operands[1];
16310 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
16311 output_asm_insn ("addi %1,%1,4\n\tlswi %2,%1,%0\n\tlwz %1,-4(%1)", xop);
16312 return "";
16314 else
16316 for (j = 0; j < words; j++)
16317 if (j != i)
16319 xop[0] = GEN_INT (j * 4);
16320 xop[1] = operands[1];
16321 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
16322 output_asm_insn ("lwz %2,%0(%1)", xop);
16324 xop[0] = GEN_INT (i * 4);
16325 xop[1] = operands[1];
16326 output_asm_insn ("lwz %1,%0(%1)", xop);
16327 return "";
16331 return "lswi %2,%1,%N0";
16335 /* A validation routine: say whether CODE, a condition code, and MODE
16336 match. The other alternatives either don't make sense or should
16337 never be generated. */
16339 void
16340 validate_condition_mode (enum rtx_code code, machine_mode mode)
16342 gcc_assert ((GET_RTX_CLASS (code) == RTX_COMPARE
16343 || GET_RTX_CLASS (code) == RTX_COMM_COMPARE)
16344 && GET_MODE_CLASS (mode) == MODE_CC);
16346 /* These don't make sense. */
16347 gcc_assert ((code != GT && code != LT && code != GE && code != LE)
16348 || mode != CCUNSmode);
16350 gcc_assert ((code != GTU && code != LTU && code != GEU && code != LEU)
16351 || mode == CCUNSmode);
16353 gcc_assert (mode == CCFPmode
16354 || (code != ORDERED && code != UNORDERED
16355 && code != UNEQ && code != LTGT
16356 && code != UNGT && code != UNLT
16357 && code != UNGE && code != UNLE));
16359 /* These should never be generated except for
16360 flag_finite_math_only. */
16361 gcc_assert (mode != CCFPmode
16362 || flag_finite_math_only
16363 || (code != LE && code != GE
16364 && code != UNEQ && code != LTGT
16365 && code != UNGT && code != UNLT));
16367 /* These are invalid; the information is not there. */
16368 gcc_assert (mode != CCEQmode || code == EQ || code == NE);
16372 /* Return 1 if ANDOP is a mask that has no bits on that are not in the
16373 mask required to convert the result of a rotate insn into a shift
16374 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
16377 includes_lshift_p (rtx shiftop, rtx andop)
16379 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
16381 shift_mask <<= INTVAL (shiftop);
16383 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
16386 /* Similar, but for right shift. */
16389 includes_rshift_p (rtx shiftop, rtx andop)
16391 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
16393 shift_mask >>= INTVAL (shiftop);
16395 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
16398 /* Return 1 if ANDOP is a mask suitable for use with an rldic insn
16399 to perform a left shift. It must have exactly SHIFTOP least
16400 significant 0's, then one or more 1's, then zero or more 0's. */
16403 includes_rldic_lshift_p (rtx shiftop, rtx andop)
16405 if (GET_CODE (andop) == CONST_INT)
16407 unsigned HOST_WIDE_INT c, lsb, shift_mask;
16409 c = INTVAL (andop);
16410 if (c == 0 || c == HOST_WIDE_INT_M1U)
16411 return 0;
16413 shift_mask = HOST_WIDE_INT_M1U;
16414 shift_mask <<= INTVAL (shiftop);
16416 /* Find the least significant one bit. */
16417 lsb = c & -c;
16419 /* It must coincide with the LSB of the shift mask. */
16420 if (-lsb != shift_mask)
16421 return 0;
16423 /* Invert to look for the next transition (if any). */
16424 c = ~c;
16426 /* Remove the low group of ones (originally low group of zeros). */
16427 c &= -lsb;
16429 /* Again find the lsb, and check we have all 1's above. */
16430 lsb = c & -c;
16431 return c == -lsb;
16433 else
16434 return 0;
16437 /* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
16438 to perform a left shift. It must have SHIFTOP or more least
16439 significant 0's, with the remainder of the word 1's. */
16442 includes_rldicr_lshift_p (rtx shiftop, rtx andop)
16444 if (GET_CODE (andop) == CONST_INT)
16446 unsigned HOST_WIDE_INT c, lsb, shift_mask;
16448 shift_mask = HOST_WIDE_INT_M1U;
16449 shift_mask <<= INTVAL (shiftop);
16450 c = INTVAL (andop);
16452 /* Find the least significant one bit. */
16453 lsb = c & -c;
16455 /* It must be covered by the shift mask.
16456 This test also rejects c == 0. */
16457 if ((lsb & shift_mask) == 0)
16458 return 0;
16460 /* Check we have all 1's above the transition, and reject all 1's. */
16461 return c == -lsb && lsb != 1;
16463 else
16464 return 0;
16467 /* Return 1 if operands will generate a valid arguments to rlwimi
16468 instruction for insert with right shift in 64-bit mode. The mask may
16469 not start on the first bit or stop on the last bit because wrap-around
16470 effects of instruction do not correspond to semantics of RTL insn. */
16473 insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop)
16475 if (INTVAL (startop) > 32
16476 && INTVAL (startop) < 64
16477 && INTVAL (sizeop) > 1
16478 && INTVAL (sizeop) + INTVAL (startop) < 64
16479 && INTVAL (shiftop) > 0
16480 && INTVAL (sizeop) + INTVAL (shiftop) < 32
16481 && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop))
16482 return 1;
16484 return 0;
16487 /* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
16488 for lfq and stfq insns iff the registers are hard registers. */
16491 registers_ok_for_quad_peep (rtx reg1, rtx reg2)
16493 /* We might have been passed a SUBREG. */
16494 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
16495 return 0;
16497 /* We might have been passed non floating point registers. */
16498 if (!FP_REGNO_P (REGNO (reg1))
16499 || !FP_REGNO_P (REGNO (reg2)))
16500 return 0;
16502 return (REGNO (reg1) == REGNO (reg2) - 1);
16505 /* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
16506 addr1 and addr2 must be in consecutive memory locations
16507 (addr2 == addr1 + 8). */
16510 mems_ok_for_quad_peep (rtx mem1, rtx mem2)
16512 rtx addr1, addr2;
16513 unsigned int reg1, reg2;
16514 int offset1, offset2;
16516 /* The mems cannot be volatile. */
16517 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
16518 return 0;
16520 addr1 = XEXP (mem1, 0);
16521 addr2 = XEXP (mem2, 0);
16523 /* Extract an offset (if used) from the first addr. */
16524 if (GET_CODE (addr1) == PLUS)
16526 /* If not a REG, return zero. */
16527 if (GET_CODE (XEXP (addr1, 0)) != REG)
16528 return 0;
16529 else
16531 reg1 = REGNO (XEXP (addr1, 0));
16532 /* The offset must be constant! */
16533 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
16534 return 0;
16535 offset1 = INTVAL (XEXP (addr1, 1));
16538 else if (GET_CODE (addr1) != REG)
16539 return 0;
16540 else
16542 reg1 = REGNO (addr1);
16543 /* This was a simple (mem (reg)) expression. Offset is 0. */
16544 offset1 = 0;
16547 /* And now for the second addr. */
16548 if (GET_CODE (addr2) == PLUS)
16550 /* If not a REG, return zero. */
16551 if (GET_CODE (XEXP (addr2, 0)) != REG)
16552 return 0;
16553 else
16555 reg2 = REGNO (XEXP (addr2, 0));
16556 /* The offset must be constant. */
16557 if (GET_CODE (XEXP (addr2, 1)) != CONST_INT)
16558 return 0;
16559 offset2 = INTVAL (XEXP (addr2, 1));
16562 else if (GET_CODE (addr2) != REG)
16563 return 0;
16564 else
16566 reg2 = REGNO (addr2);
16567 /* This was a simple (mem (reg)) expression. Offset is 0. */
16568 offset2 = 0;
16571 /* Both of these must have the same base register. */
16572 if (reg1 != reg2)
16573 return 0;
16575 /* The offset for the second addr must be 8 more than the first addr. */
16576 if (offset2 != offset1 + 8)
16577 return 0;
16579 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
16580 instructions. */
16581 return 1;
16586 rs6000_secondary_memory_needed_rtx (machine_mode mode)
16588 static bool eliminated = false;
16589 rtx ret;
16591 if (mode != SDmode || TARGET_NO_SDMODE_STACK)
16592 ret = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
16593 else
16595 rtx mem = cfun->machine->sdmode_stack_slot;
16596 gcc_assert (mem != NULL_RTX);
16598 if (!eliminated)
16600 mem = eliminate_regs (mem, VOIDmode, NULL_RTX);
16601 cfun->machine->sdmode_stack_slot = mem;
16602 eliminated = true;
16604 ret = mem;
16607 if (TARGET_DEBUG_ADDR)
16609 fprintf (stderr, "\nrs6000_secondary_memory_needed_rtx, mode %s, rtx:\n",
16610 GET_MODE_NAME (mode));
16611 if (!ret)
16612 fprintf (stderr, "\tNULL_RTX\n");
16613 else
16614 debug_rtx (ret);
16617 return ret;
16620 /* Return the mode to be used for memory when a secondary memory
16621 location is needed. For SDmode values we need to use DDmode, in
16622 all other cases we can use the same mode. */
16623 machine_mode
16624 rs6000_secondary_memory_needed_mode (machine_mode mode)
16626 if (lra_in_progress && mode == SDmode)
16627 return DDmode;
16628 return mode;
16631 static tree
16632 rs6000_check_sdmode (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
16634 /* Don't walk into types. */
16635 if (*tp == NULL_TREE || *tp == error_mark_node || TYPE_P (*tp))
16637 *walk_subtrees = 0;
16638 return NULL_TREE;
16641 switch (TREE_CODE (*tp))
16643 case VAR_DECL:
16644 case PARM_DECL:
16645 case FIELD_DECL:
16646 case RESULT_DECL:
16647 case SSA_NAME:
16648 case REAL_CST:
16649 case MEM_REF:
16650 case VIEW_CONVERT_EXPR:
16651 if (TYPE_MODE (TREE_TYPE (*tp)) == SDmode)
16652 return *tp;
16653 break;
16654 default:
16655 break;
16658 return NULL_TREE;
16661 /* Classify a register type. Because the FMRGOW/FMRGEW instructions only work
16662 on traditional floating point registers, and the VMRGOW/VMRGEW instructions
16663 only work on the traditional altivec registers, note if an altivec register
16664 was chosen. */
16666 static enum rs6000_reg_type
16667 register_to_reg_type (rtx reg, bool *is_altivec)
16669 HOST_WIDE_INT regno;
16670 enum reg_class rclass;
16672 if (GET_CODE (reg) == SUBREG)
16673 reg = SUBREG_REG (reg);
16675 if (!REG_P (reg))
16676 return NO_REG_TYPE;
16678 regno = REGNO (reg);
16679 if (regno >= FIRST_PSEUDO_REGISTER)
16681 if (!lra_in_progress && !reload_in_progress && !reload_completed)
16682 return PSEUDO_REG_TYPE;
16684 regno = true_regnum (reg);
16685 if (regno < 0 || regno >= FIRST_PSEUDO_REGISTER)
16686 return PSEUDO_REG_TYPE;
16689 gcc_assert (regno >= 0);
16691 if (is_altivec && ALTIVEC_REGNO_P (regno))
16692 *is_altivec = true;
16694 rclass = rs6000_regno_regclass[regno];
16695 return reg_class_to_reg_type[(int)rclass];
16698 /* Helper function to return the cost of adding a TOC entry address. */
16700 static inline int
16701 rs6000_secondary_reload_toc_costs (addr_mask_type addr_mask)
16703 int ret;
16705 if (TARGET_CMODEL != CMODEL_SMALL)
16706 ret = ((addr_mask & RELOAD_REG_OFFSET) == 0) ? 1 : 2;
16708 else
16709 ret = (TARGET_MINIMAL_TOC) ? 6 : 3;
16711 return ret;
16714 /* Helper function for rs6000_secondary_reload to determine whether the memory
16715 address (ADDR) with a given register class (RCLASS) and machine mode (MODE)
16716 needs reloading. Return negative if the memory is not handled by the memory
16717 helper functions and to try a different reload method, 0 if no additional
16718 instructions are need, and positive to give the extra cost for the
16719 memory. */
16721 static int
16722 rs6000_secondary_reload_memory (rtx addr,
16723 enum reg_class rclass,
16724 enum machine_mode mode)
16726 int extra_cost = 0;
16727 rtx reg, and_arg, plus_arg0, plus_arg1;
16728 addr_mask_type addr_mask;
16729 const char *type = NULL;
16730 const char *fail_msg = NULL;
16732 if (GPR_REG_CLASS_P (rclass))
16733 addr_mask = reg_addr[mode].addr_mask[RELOAD_REG_GPR];
16735 else if (rclass == FLOAT_REGS)
16736 addr_mask = reg_addr[mode].addr_mask[RELOAD_REG_FPR];
16738 else if (rclass == ALTIVEC_REGS)
16739 addr_mask = reg_addr[mode].addr_mask[RELOAD_REG_VMX];
16741 /* For the combined VSX_REGS, turn off Altivec AND -16. */
16742 else if (rclass == VSX_REGS)
16743 addr_mask = (reg_addr[mode].addr_mask[RELOAD_REG_VMX]
16744 & ~RELOAD_REG_AND_M16);
16746 else
16748 if (TARGET_DEBUG_ADDR)
16749 fprintf (stderr,
16750 "rs6000_secondary_reload_memory: mode = %s, class = %s, "
16751 "class is not GPR, FPR, VMX\n",
16752 GET_MODE_NAME (mode), reg_class_names[rclass]);
16754 return -1;
16757 /* If the register isn't valid in this register class, just return now. */
16758 if ((addr_mask & RELOAD_REG_VALID) == 0)
16760 if (TARGET_DEBUG_ADDR)
16761 fprintf (stderr,
16762 "rs6000_secondary_reload_memory: mode = %s, class = %s, "
16763 "not valid in class\n",
16764 GET_MODE_NAME (mode), reg_class_names[rclass]);
16766 return -1;
16769 switch (GET_CODE (addr))
16771 /* Does the register class supports auto update forms for this mode? We
16772 don't need a scratch register, since the powerpc only supports
16773 PRE_INC, PRE_DEC, and PRE_MODIFY. */
16774 case PRE_INC:
16775 case PRE_DEC:
16776 reg = XEXP (addr, 0);
16777 if (!base_reg_operand (addr, GET_MODE (reg)))
16779 fail_msg = "no base register #1";
16780 extra_cost = -1;
16783 else if ((addr_mask & RELOAD_REG_PRE_INCDEC) == 0)
16785 extra_cost = 1;
16786 type = "update";
16788 break;
16790 case PRE_MODIFY:
16791 reg = XEXP (addr, 0);
16792 plus_arg1 = XEXP (addr, 1);
16793 if (!base_reg_operand (reg, GET_MODE (reg))
16794 || GET_CODE (plus_arg1) != PLUS
16795 || !rtx_equal_p (reg, XEXP (plus_arg1, 0)))
16797 fail_msg = "bad PRE_MODIFY";
16798 extra_cost = -1;
16801 else if ((addr_mask & RELOAD_REG_PRE_MODIFY) == 0)
16803 extra_cost = 1;
16804 type = "update";
16806 break;
16808 /* Do we need to simulate AND -16 to clear the bottom address bits used
16809 in VMX load/stores? Only allow the AND for vector sizes. */
16810 case AND:
16811 and_arg = XEXP (addr, 0);
16812 if (GET_MODE_SIZE (mode) != 16
16813 || GET_CODE (XEXP (addr, 1)) != CONST_INT
16814 || INTVAL (XEXP (addr, 1)) != -16)
16816 fail_msg = "bad Altivec AND #1";
16817 extra_cost = -1;
16820 if (rclass != ALTIVEC_REGS)
16822 if (legitimate_indirect_address_p (and_arg, false))
16823 extra_cost = 1;
16825 else if (legitimate_indexed_address_p (and_arg, false))
16826 extra_cost = 2;
16828 else
16830 fail_msg = "bad Altivec AND #2";
16831 extra_cost = -1;
16834 type = "and";
16836 break;
16838 /* If this is an indirect address, make sure it is a base register. */
16839 case REG:
16840 case SUBREG:
16841 if (!legitimate_indirect_address_p (addr, false))
16843 extra_cost = 1;
16844 type = "move";
16846 break;
16848 /* If this is an indexed address, make sure the register class can handle
16849 indexed addresses for this mode. */
16850 case PLUS:
16851 plus_arg0 = XEXP (addr, 0);
16852 plus_arg1 = XEXP (addr, 1);
16854 /* (plus (plus (reg) (constant)) (constant)) is generated during
16855 push_reload processing, so handle it now. */
16856 if (GET_CODE (plus_arg0) == PLUS && CONST_INT_P (plus_arg1))
16858 if ((addr_mask & RELOAD_REG_OFFSET) == 0)
16860 extra_cost = 1;
16861 type = "offset";
16865 /* (plus (plus (reg) (constant)) (reg)) is also generated during
16866 push_reload processing, so handle it now. */
16867 else if (GET_CODE (plus_arg0) == PLUS && REG_P (plus_arg1))
16869 if ((addr_mask & RELOAD_REG_INDEXED) == 0)
16871 extra_cost = 1;
16872 type = "indexed #2";
16876 else if (!base_reg_operand (plus_arg0, GET_MODE (plus_arg0)))
16878 fail_msg = "no base register #2";
16879 extra_cost = -1;
16882 else if (int_reg_operand (plus_arg1, GET_MODE (plus_arg1)))
16884 if ((addr_mask & RELOAD_REG_INDEXED) == 0
16885 || !legitimate_indexed_address_p (addr, false))
16887 extra_cost = 1;
16888 type = "indexed";
16892 /* Make sure the register class can handle offset addresses. */
16893 else if (rs6000_legitimate_offset_address_p (mode, addr, false, true))
16895 if ((addr_mask & RELOAD_REG_OFFSET) == 0)
16897 extra_cost = 1;
16898 type = "offset";
16902 else
16904 fail_msg = "bad PLUS";
16905 extra_cost = -1;
16908 break;
16910 case LO_SUM:
16911 if (!legitimate_lo_sum_address_p (mode, addr, false))
16913 fail_msg = "bad LO_SUM";
16914 extra_cost = -1;
16917 if ((addr_mask & RELOAD_REG_OFFSET) == 0)
16919 extra_cost = 1;
16920 type = "lo_sum";
16922 break;
16924 /* Static addresses need to create a TOC entry. */
16925 case CONST:
16926 case SYMBOL_REF:
16927 case LABEL_REF:
16928 type = "address";
16929 extra_cost = rs6000_secondary_reload_toc_costs (addr_mask);
16930 break;
16932 /* TOC references look like offsetable memory. */
16933 case UNSPEC:
16934 if (TARGET_CMODEL == CMODEL_SMALL || XINT (addr, 1) != UNSPEC_TOCREL)
16936 fail_msg = "bad UNSPEC";
16937 extra_cost = -1;
16940 else if ((addr_mask & RELOAD_REG_OFFSET) == 0)
16942 extra_cost = 1;
16943 type = "toc reference";
16945 break;
16947 default:
16949 fail_msg = "bad address";
16950 extra_cost = -1;
16954 if (TARGET_DEBUG_ADDR /* && extra_cost != 0 */)
16956 if (extra_cost < 0)
16957 fprintf (stderr,
16958 "rs6000_secondary_reload_memory error: mode = %s, "
16959 "class = %s, addr_mask = '%s', %s\n",
16960 GET_MODE_NAME (mode),
16961 reg_class_names[rclass],
16962 rs6000_debug_addr_mask (addr_mask, false),
16963 (fail_msg != NULL) ? fail_msg : "<bad address>");
16965 else
16966 fprintf (stderr,
16967 "rs6000_secondary_reload_memory: mode = %s, class = %s, "
16968 "addr_mask = '%s', extra cost = %d, %s\n",
16969 GET_MODE_NAME (mode),
16970 reg_class_names[rclass],
16971 rs6000_debug_addr_mask (addr_mask, false),
16972 extra_cost,
16973 (type) ? type : "<none>");
16975 debug_rtx (addr);
16978 return extra_cost;
16981 /* Helper function for rs6000_secondary_reload to return true if a move to a
16982 different register classe is really a simple move. */
16984 static bool
16985 rs6000_secondary_reload_simple_move (enum rs6000_reg_type to_type,
16986 enum rs6000_reg_type from_type,
16987 machine_mode mode)
16989 int size;
16991 /* Add support for various direct moves available. In this function, we only
16992 look at cases where we don't need any extra registers, and one or more
16993 simple move insns are issued. At present, 32-bit integers are not allowed
16994 in FPR/VSX registers. Single precision binary floating is not a simple
16995 move because we need to convert to the single precision memory layout.
16996 The 4-byte SDmode can be moved. */
16997 size = GET_MODE_SIZE (mode);
16998 if (TARGET_DIRECT_MOVE
16999 && ((mode == SDmode) || (TARGET_POWERPC64 && size == 8))
17000 && ((to_type == GPR_REG_TYPE && from_type == VSX_REG_TYPE)
17001 || (to_type == VSX_REG_TYPE && from_type == GPR_REG_TYPE)))
17002 return true;
17004 else if (TARGET_MFPGPR && TARGET_POWERPC64 && size == 8
17005 && ((to_type == GPR_REG_TYPE && from_type == FPR_REG_TYPE)
17006 || (to_type == FPR_REG_TYPE && from_type == GPR_REG_TYPE)))
17007 return true;
17009 else if ((size == 4 || (TARGET_POWERPC64 && size == 8))
17010 && ((to_type == GPR_REG_TYPE && from_type == SPR_REG_TYPE)
17011 || (to_type == SPR_REG_TYPE && from_type == GPR_REG_TYPE)))
17012 return true;
17014 return false;
17017 /* Power8 helper function for rs6000_secondary_reload, handle all of the
17018 special direct moves that involve allocating an extra register, return the
17019 insn code of the helper function if there is such a function or
17020 CODE_FOR_nothing if not. */
17022 static bool
17023 rs6000_secondary_reload_direct_move (enum rs6000_reg_type to_type,
17024 enum rs6000_reg_type from_type,
17025 machine_mode mode,
17026 secondary_reload_info *sri,
17027 bool altivec_p)
17029 bool ret = false;
17030 enum insn_code icode = CODE_FOR_nothing;
17031 int cost = 0;
17032 int size = GET_MODE_SIZE (mode);
17034 if (TARGET_POWERPC64)
17036 if (size == 16)
17038 /* Handle moving 128-bit values from GPRs to VSX point registers on
17039 power8 when running in 64-bit mode using XXPERMDI to glue the two
17040 64-bit values back together. */
17041 if (to_type == VSX_REG_TYPE && from_type == GPR_REG_TYPE)
17043 cost = 3; /* 2 mtvsrd's, 1 xxpermdi. */
17044 icode = reg_addr[mode].reload_vsx_gpr;
17047 /* Handle moving 128-bit values from VSX point registers to GPRs on
17048 power8 when running in 64-bit mode using XXPERMDI to get access to the
17049 bottom 64-bit value. */
17050 else if (to_type == GPR_REG_TYPE && from_type == VSX_REG_TYPE)
17052 cost = 3; /* 2 mfvsrd's, 1 xxpermdi. */
17053 icode = reg_addr[mode].reload_gpr_vsx;
17057 else if (mode == SFmode)
17059 if (to_type == GPR_REG_TYPE && from_type == VSX_REG_TYPE)
17061 cost = 3; /* xscvdpspn, mfvsrd, and. */
17062 icode = reg_addr[mode].reload_gpr_vsx;
17065 else if (to_type == VSX_REG_TYPE && from_type == GPR_REG_TYPE)
17067 cost = 2; /* mtvsrz, xscvspdpn. */
17068 icode = reg_addr[mode].reload_vsx_gpr;
17073 if (TARGET_POWERPC64 && size == 16)
17075 /* Handle moving 128-bit values from GPRs to VSX point registers on
17076 power8 when running in 64-bit mode using XXPERMDI to glue the two
17077 64-bit values back together. */
17078 if (to_type == VSX_REG_TYPE && from_type == GPR_REG_TYPE)
17080 cost = 3; /* 2 mtvsrd's, 1 xxpermdi. */
17081 icode = reg_addr[mode].reload_vsx_gpr;
17084 /* Handle moving 128-bit values from VSX point registers to GPRs on
17085 power8 when running in 64-bit mode using XXPERMDI to get access to the
17086 bottom 64-bit value. */
17087 else if (to_type == GPR_REG_TYPE && from_type == VSX_REG_TYPE)
17089 cost = 3; /* 2 mfvsrd's, 1 xxpermdi. */
17090 icode = reg_addr[mode].reload_gpr_vsx;
17094 else if (!TARGET_POWERPC64 && size == 8)
17096 /* Handle moving 64-bit values from GPRs to floating point registers on
17097 power8 when running in 32-bit mode using FMRGOW to glue the two 32-bit
17098 values back together. Altivec register classes must be handled
17099 specially since a different instruction is used, and the secondary
17100 reload support requires a single instruction class in the scratch
17101 register constraint. However, right now TFmode is not allowed in
17102 Altivec registers, so the pattern will never match. */
17103 if (to_type == VSX_REG_TYPE && from_type == GPR_REG_TYPE && !altivec_p)
17105 cost = 3; /* 2 mtvsrwz's, 1 fmrgow. */
17106 icode = reg_addr[mode].reload_fpr_gpr;
17110 if (icode != CODE_FOR_nothing)
17112 ret = true;
17113 if (sri)
17115 sri->icode = icode;
17116 sri->extra_cost = cost;
17120 return ret;
17123 /* Return whether a move between two register classes can be done either
17124 directly (simple move) or via a pattern that uses a single extra temporary
17125 (using power8's direct move in this case. */
17127 static bool
17128 rs6000_secondary_reload_move (enum rs6000_reg_type to_type,
17129 enum rs6000_reg_type from_type,
17130 machine_mode mode,
17131 secondary_reload_info *sri,
17132 bool altivec_p)
17134 /* Fall back to load/store reloads if either type is not a register. */
17135 if (to_type == NO_REG_TYPE || from_type == NO_REG_TYPE)
17136 return false;
17138 /* If we haven't allocated registers yet, assume the move can be done for the
17139 standard register types. */
17140 if ((to_type == PSEUDO_REG_TYPE && from_type == PSEUDO_REG_TYPE)
17141 || (to_type == PSEUDO_REG_TYPE && IS_STD_REG_TYPE (from_type))
17142 || (from_type == PSEUDO_REG_TYPE && IS_STD_REG_TYPE (to_type)))
17143 return true;
17145 /* Moves to the same set of registers is a simple move for non-specialized
17146 registers. */
17147 if (to_type == from_type && IS_STD_REG_TYPE (to_type))
17148 return true;
17150 /* Check whether a simple move can be done directly. */
17151 if (rs6000_secondary_reload_simple_move (to_type, from_type, mode))
17153 if (sri)
17155 sri->icode = CODE_FOR_nothing;
17156 sri->extra_cost = 0;
17158 return true;
17161 /* Now check if we can do it in a few steps. */
17162 return rs6000_secondary_reload_direct_move (to_type, from_type, mode, sri,
17163 altivec_p);
17166 /* Inform reload about cases where moving X with a mode MODE to a register in
17167 RCLASS requires an extra scratch or immediate register. Return the class
17168 needed for the immediate register.
17170 For VSX and Altivec, we may need a register to convert sp+offset into
17171 reg+sp.
17173 For misaligned 64-bit gpr loads and stores we need a register to
17174 convert an offset address to indirect. */
17176 static reg_class_t
17177 rs6000_secondary_reload (bool in_p,
17178 rtx x,
17179 reg_class_t rclass_i,
17180 machine_mode mode,
17181 secondary_reload_info *sri)
17183 enum reg_class rclass = (enum reg_class) rclass_i;
17184 reg_class_t ret = ALL_REGS;
17185 enum insn_code icode;
17186 bool default_p = false;
17187 bool done_p = false;
17189 /* Allow subreg of memory before/during reload. */
17190 bool memory_p = (MEM_P (x)
17191 || (!reload_completed && GET_CODE (x) == SUBREG
17192 && MEM_P (SUBREG_REG (x))));
17194 sri->icode = CODE_FOR_nothing;
17195 sri->extra_cost = 0;
17196 icode = ((in_p)
17197 ? reg_addr[mode].reload_load
17198 : reg_addr[mode].reload_store);
17200 if (REG_P (x) || register_operand (x, mode))
17202 enum rs6000_reg_type to_type = reg_class_to_reg_type[(int)rclass];
17203 bool altivec_p = (rclass == ALTIVEC_REGS);
17204 enum rs6000_reg_type from_type = register_to_reg_type (x, &altivec_p);
17206 if (!in_p)
17208 enum rs6000_reg_type exchange = to_type;
17209 to_type = from_type;
17210 from_type = exchange;
17213 /* Can we do a direct move of some sort? */
17214 if (rs6000_secondary_reload_move (to_type, from_type, mode, sri,
17215 altivec_p))
17217 icode = (enum insn_code)sri->icode;
17218 default_p = false;
17219 done_p = true;
17220 ret = NO_REGS;
17224 /* Make sure 0.0 is not reloaded or forced into memory. */
17225 if (x == CONST0_RTX (mode) && VSX_REG_CLASS_P (rclass))
17227 ret = NO_REGS;
17228 default_p = false;
17229 done_p = true;
17232 /* If this is a scalar floating point value and we want to load it into the
17233 traditional Altivec registers, do it via a move via a traditional floating
17234 point register. Also make sure that non-zero constants use a FPR. */
17235 if (!done_p && reg_addr[mode].scalar_in_vmx_p
17236 && (rclass == VSX_REGS || rclass == ALTIVEC_REGS)
17237 && (memory_p || (GET_CODE (x) == CONST_DOUBLE)))
17239 ret = FLOAT_REGS;
17240 default_p = false;
17241 done_p = true;
17244 /* Handle reload of load/stores if we have reload helper functions. */
17245 if (!done_p && icode != CODE_FOR_nothing && memory_p)
17247 int extra_cost = rs6000_secondary_reload_memory (XEXP (x, 0), rclass,
17248 mode);
17250 if (extra_cost >= 0)
17252 done_p = true;
17253 ret = NO_REGS;
17254 if (extra_cost > 0)
17256 sri->extra_cost = extra_cost;
17257 sri->icode = icode;
17262 /* Handle unaligned loads and stores of integer registers. */
17263 if (!done_p && TARGET_POWERPC64
17264 && reg_class_to_reg_type[(int)rclass] == GPR_REG_TYPE
17265 && memory_p
17266 && GET_MODE_SIZE (GET_MODE (x)) >= UNITS_PER_WORD)
17268 rtx addr = XEXP (x, 0);
17269 rtx off = address_offset (addr);
17271 if (off != NULL_RTX)
17273 unsigned int extra = GET_MODE_SIZE (GET_MODE (x)) - UNITS_PER_WORD;
17274 unsigned HOST_WIDE_INT offset = INTVAL (off);
17276 /* We need a secondary reload when our legitimate_address_p
17277 says the address is good (as otherwise the entire address
17278 will be reloaded), and the offset is not a multiple of
17279 four or we have an address wrap. Address wrap will only
17280 occur for LO_SUMs since legitimate_offset_address_p
17281 rejects addresses for 16-byte mems that will wrap. */
17282 if (GET_CODE (addr) == LO_SUM
17283 ? (1 /* legitimate_address_p allows any offset for lo_sum */
17284 && ((offset & 3) != 0
17285 || ((offset & 0xffff) ^ 0x8000) >= 0x10000 - extra))
17286 : (offset + 0x8000 < 0x10000 - extra /* legitimate_address_p */
17287 && (offset & 3) != 0))
17289 /* -m32 -mpowerpc64 needs to use a 32-bit scratch register. */
17290 if (in_p)
17291 sri->icode = ((TARGET_32BIT) ? CODE_FOR_reload_si_load
17292 : CODE_FOR_reload_di_load);
17293 else
17294 sri->icode = ((TARGET_32BIT) ? CODE_FOR_reload_si_store
17295 : CODE_FOR_reload_di_store);
17296 sri->extra_cost = 2;
17297 ret = NO_REGS;
17298 done_p = true;
17300 else
17301 default_p = true;
17303 else
17304 default_p = true;
17307 if (!done_p && !TARGET_POWERPC64
17308 && reg_class_to_reg_type[(int)rclass] == GPR_REG_TYPE
17309 && memory_p
17310 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
17312 rtx addr = XEXP (x, 0);
17313 rtx off = address_offset (addr);
17315 if (off != NULL_RTX)
17317 unsigned int extra = GET_MODE_SIZE (GET_MODE (x)) - UNITS_PER_WORD;
17318 unsigned HOST_WIDE_INT offset = INTVAL (off);
17320 /* We need a secondary reload when our legitimate_address_p
17321 says the address is good (as otherwise the entire address
17322 will be reloaded), and we have a wrap.
17324 legitimate_lo_sum_address_p allows LO_SUM addresses to
17325 have any offset so test for wrap in the low 16 bits.
17327 legitimate_offset_address_p checks for the range
17328 [-0x8000,0x7fff] for mode size of 8 and [-0x8000,0x7ff7]
17329 for mode size of 16. We wrap at [0x7ffc,0x7fff] and
17330 [0x7ff4,0x7fff] respectively, so test for the
17331 intersection of these ranges, [0x7ffc,0x7fff] and
17332 [0x7ff4,0x7ff7] respectively.
17334 Note that the address we see here may have been
17335 manipulated by legitimize_reload_address. */
17336 if (GET_CODE (addr) == LO_SUM
17337 ? ((offset & 0xffff) ^ 0x8000) >= 0x10000 - extra
17338 : offset - (0x8000 - extra) < UNITS_PER_WORD)
17340 if (in_p)
17341 sri->icode = CODE_FOR_reload_si_load;
17342 else
17343 sri->icode = CODE_FOR_reload_si_store;
17344 sri->extra_cost = 2;
17345 ret = NO_REGS;
17346 done_p = true;
17348 else
17349 default_p = true;
17351 else
17352 default_p = true;
17355 if (!done_p)
17356 default_p = true;
17358 if (default_p)
17359 ret = default_secondary_reload (in_p, x, rclass, mode, sri);
17361 gcc_assert (ret != ALL_REGS);
17363 if (TARGET_DEBUG_ADDR)
17365 fprintf (stderr,
17366 "\nrs6000_secondary_reload, return %s, in_p = %s, rclass = %s, "
17367 "mode = %s",
17368 reg_class_names[ret],
17369 in_p ? "true" : "false",
17370 reg_class_names[rclass],
17371 GET_MODE_NAME (mode));
17373 if (reload_completed)
17374 fputs (", after reload", stderr);
17376 if (!done_p)
17377 fputs (", done_p not set", stderr);
17379 if (default_p)
17380 fputs (", default secondary reload", stderr);
17382 if (sri->icode != CODE_FOR_nothing)
17383 fprintf (stderr, ", reload func = %s, extra cost = %d",
17384 insn_data[sri->icode].name, sri->extra_cost);
17386 fputs ("\n", stderr);
17387 debug_rtx (x);
17390 return ret;
17393 /* Better tracing for rs6000_secondary_reload_inner. */
17395 static void
17396 rs6000_secondary_reload_trace (int line, rtx reg, rtx mem, rtx scratch,
17397 bool store_p)
17399 rtx set, clobber;
17401 gcc_assert (reg != NULL_RTX && mem != NULL_RTX && scratch != NULL_RTX);
17403 fprintf (stderr, "rs6000_secondary_reload_inner:%d, type = %s\n", line,
17404 store_p ? "store" : "load");
17406 if (store_p)
17407 set = gen_rtx_SET (mem, reg);
17408 else
17409 set = gen_rtx_SET (reg, mem);
17411 clobber = gen_rtx_CLOBBER (VOIDmode, scratch);
17412 debug_rtx (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber)));
17415 static void rs6000_secondary_reload_fail (int, rtx, rtx, rtx, bool)
17416 ATTRIBUTE_NORETURN;
17418 static void
17419 rs6000_secondary_reload_fail (int line, rtx reg, rtx mem, rtx scratch,
17420 bool store_p)
17422 rs6000_secondary_reload_trace (line, reg, mem, scratch, store_p);
17423 gcc_unreachable ();
17426 /* Fixup reload addresses for values in GPR, FPR, and VMX registers that have
17427 reload helper functions. These were identified in
17428 rs6000_secondary_reload_memory, and if reload decided to use the secondary
17429 reload, it calls the insns:
17430 reload_<RELOAD:mode>_<P:mptrsize>_store
17431 reload_<RELOAD:mode>_<P:mptrsize>_load
17433 which in turn calls this function, to do whatever is necessary to create
17434 valid addresses. */
17436 void
17437 rs6000_secondary_reload_inner (rtx reg, rtx mem, rtx scratch, bool store_p)
17439 int regno = true_regnum (reg);
17440 machine_mode mode = GET_MODE (reg);
17441 addr_mask_type addr_mask;
17442 rtx addr;
17443 rtx new_addr;
17444 rtx op_reg, op0, op1;
17445 rtx and_op;
17446 rtx cc_clobber;
17447 rtvec rv;
17449 if (regno < 0 || regno >= FIRST_PSEUDO_REGISTER || !MEM_P (mem)
17450 || !base_reg_operand (scratch, GET_MODE (scratch)))
17451 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17453 if (IN_RANGE (regno, FIRST_GPR_REGNO, LAST_GPR_REGNO))
17454 addr_mask = reg_addr[mode].addr_mask[RELOAD_REG_GPR];
17456 else if (IN_RANGE (regno, FIRST_FPR_REGNO, LAST_FPR_REGNO))
17457 addr_mask = reg_addr[mode].addr_mask[RELOAD_REG_FPR];
17459 else if (IN_RANGE (regno, FIRST_ALTIVEC_REGNO, LAST_ALTIVEC_REGNO))
17460 addr_mask = reg_addr[mode].addr_mask[RELOAD_REG_VMX];
17462 else
17463 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17465 /* Make sure the mode is valid in this register class. */
17466 if ((addr_mask & RELOAD_REG_VALID) == 0)
17467 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17469 if (TARGET_DEBUG_ADDR)
17470 rs6000_secondary_reload_trace (__LINE__, reg, mem, scratch, store_p);
17472 new_addr = addr = XEXP (mem, 0);
17473 switch (GET_CODE (addr))
17475 /* Does the register class support auto update forms for this mode? If
17476 not, do the update now. We don't need a scratch register, since the
17477 powerpc only supports PRE_INC, PRE_DEC, and PRE_MODIFY. */
17478 case PRE_INC:
17479 case PRE_DEC:
17480 op_reg = XEXP (addr, 0);
17481 if (!base_reg_operand (op_reg, Pmode))
17482 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17484 if ((addr_mask & RELOAD_REG_PRE_INCDEC) == 0)
17486 emit_insn (gen_add2_insn (op_reg, GEN_INT (GET_MODE_SIZE (mode))));
17487 new_addr = op_reg;
17489 break;
17491 case PRE_MODIFY:
17492 op0 = XEXP (addr, 0);
17493 op1 = XEXP (addr, 1);
17494 if (!base_reg_operand (op0, Pmode)
17495 || GET_CODE (op1) != PLUS
17496 || !rtx_equal_p (op0, XEXP (op1, 0)))
17497 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17499 if ((addr_mask & RELOAD_REG_PRE_MODIFY) == 0)
17501 emit_insn (gen_rtx_SET (op0, op1));
17502 new_addr = reg;
17504 break;
17506 /* Do we need to simulate AND -16 to clear the bottom address bits used
17507 in VMX load/stores? */
17508 case AND:
17509 op0 = XEXP (addr, 0);
17510 op1 = XEXP (addr, 1);
17511 if ((addr_mask & RELOAD_REG_AND_M16) == 0)
17513 if (REG_P (op0) || GET_CODE (op0) == SUBREG)
17514 op_reg = op0;
17516 else if (GET_CODE (op1) == PLUS)
17518 emit_insn (gen_rtx_SET (scratch, op1));
17519 op_reg = scratch;
17522 else
17523 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17525 and_op = gen_rtx_AND (GET_MODE (scratch), op_reg, op1);
17526 cc_clobber = gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (CCmode));
17527 rv = gen_rtvec (2, gen_rtx_SET (scratch, and_op), cc_clobber);
17528 emit_insn (gen_rtx_PARALLEL (VOIDmode, rv));
17529 new_addr = scratch;
17531 break;
17533 /* If this is an indirect address, make sure it is a base register. */
17534 case REG:
17535 case SUBREG:
17536 if (!base_reg_operand (addr, GET_MODE (addr)))
17538 emit_insn (gen_rtx_SET (scratch, addr));
17539 new_addr = scratch;
17541 break;
17543 /* If this is an indexed address, make sure the register class can handle
17544 indexed addresses for this mode. */
17545 case PLUS:
17546 op0 = XEXP (addr, 0);
17547 op1 = XEXP (addr, 1);
17548 if (!base_reg_operand (op0, Pmode))
17549 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17551 else if (int_reg_operand (op1, Pmode))
17553 if ((addr_mask & RELOAD_REG_INDEXED) == 0)
17555 emit_insn (gen_rtx_SET (scratch, addr));
17556 new_addr = scratch;
17560 /* Make sure the register class can handle offset addresses. */
17561 else if (rs6000_legitimate_offset_address_p (mode, addr, false, true))
17563 if ((addr_mask & RELOAD_REG_OFFSET) == 0)
17565 emit_insn (gen_rtx_SET (scratch, addr));
17566 new_addr = scratch;
17570 else
17571 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17573 break;
17575 case LO_SUM:
17576 op0 = XEXP (addr, 0);
17577 op1 = XEXP (addr, 1);
17578 if (!base_reg_operand (op0, Pmode))
17579 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17581 else if (int_reg_operand (op1, Pmode))
17583 if ((addr_mask & RELOAD_REG_INDEXED) == 0)
17585 emit_insn (gen_rtx_SET (scratch, addr));
17586 new_addr = scratch;
17590 /* Make sure the register class can handle offset addresses. */
17591 else if (legitimate_lo_sum_address_p (mode, addr, false))
17593 if ((addr_mask & RELOAD_REG_OFFSET) == 0)
17595 emit_insn (gen_rtx_SET (scratch, addr));
17596 new_addr = scratch;
17600 else
17601 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17603 break;
17605 case SYMBOL_REF:
17606 case CONST:
17607 case LABEL_REF:
17608 rs6000_emit_move (scratch, addr, Pmode);
17609 new_addr = scratch;
17610 break;
17612 default:
17613 rs6000_secondary_reload_fail (__LINE__, reg, mem, scratch, store_p);
17616 /* Adjust the address if it changed. */
17617 if (addr != new_addr)
17619 mem = replace_equiv_address_nv (mem, new_addr);
17620 if (TARGET_DEBUG_ADDR)
17621 fprintf (stderr, "\nrs6000_secondary_reload_inner, mem adjusted.\n");
17624 /* Now create the move. */
17625 if (store_p)
17626 emit_insn (gen_rtx_SET (mem, reg));
17627 else
17628 emit_insn (gen_rtx_SET (reg, mem));
17630 return;
17633 /* Convert reloads involving 64-bit gprs and misaligned offset
17634 addressing, or multiple 32-bit gprs and offsets that are too large,
17635 to use indirect addressing. */
17637 void
17638 rs6000_secondary_reload_gpr (rtx reg, rtx mem, rtx scratch, bool store_p)
17640 int regno = true_regnum (reg);
17641 enum reg_class rclass;
17642 rtx addr;
17643 rtx scratch_or_premodify = scratch;
17645 if (TARGET_DEBUG_ADDR)
17647 fprintf (stderr, "\nrs6000_secondary_reload_gpr, type = %s\n",
17648 store_p ? "store" : "load");
17649 fprintf (stderr, "reg:\n");
17650 debug_rtx (reg);
17651 fprintf (stderr, "mem:\n");
17652 debug_rtx (mem);
17653 fprintf (stderr, "scratch:\n");
17654 debug_rtx (scratch);
17657 gcc_assert (regno >= 0 && regno < FIRST_PSEUDO_REGISTER);
17658 gcc_assert (GET_CODE (mem) == MEM);
17659 rclass = REGNO_REG_CLASS (regno);
17660 gcc_assert (rclass == GENERAL_REGS || rclass == BASE_REGS);
17661 addr = XEXP (mem, 0);
17663 if (GET_CODE (addr) == PRE_MODIFY)
17665 scratch_or_premodify = XEXP (addr, 0);
17666 gcc_assert (REG_P (scratch_or_premodify));
17667 addr = XEXP (addr, 1);
17669 gcc_assert (GET_CODE (addr) == PLUS || GET_CODE (addr) == LO_SUM);
17671 rs6000_emit_move (scratch_or_premodify, addr, Pmode);
17673 mem = replace_equiv_address_nv (mem, scratch_or_premodify);
17675 /* Now create the move. */
17676 if (store_p)
17677 emit_insn (gen_rtx_SET (mem, reg));
17678 else
17679 emit_insn (gen_rtx_SET (reg, mem));
17681 return;
17684 /* Allocate a 64-bit stack slot to be used for copying SDmode values through if
17685 this function has any SDmode references. If we are on a power7 or later, we
17686 don't need the 64-bit stack slot since the LFIWZX and STIFWX instructions
17687 can load/store the value. */
17689 static void
17690 rs6000_alloc_sdmode_stack_slot (void)
17692 tree t;
17693 basic_block bb;
17694 gimple_stmt_iterator gsi;
17696 gcc_assert (cfun->machine->sdmode_stack_slot == NULL_RTX);
17697 /* We use a different approach for dealing with the secondary
17698 memory in LRA. */
17699 if (ira_use_lra_p)
17700 return;
17702 if (TARGET_NO_SDMODE_STACK)
17703 return;
17705 FOR_EACH_BB_FN (bb, cfun)
17706 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
17708 tree ret = walk_gimple_op (gsi_stmt (gsi), rs6000_check_sdmode, NULL);
17709 if (ret)
17711 rtx stack = assign_stack_local (DDmode, GET_MODE_SIZE (DDmode), 0);
17712 cfun->machine->sdmode_stack_slot = adjust_address_nv (stack,
17713 SDmode, 0);
17714 return;
17718 /* Check for any SDmode parameters of the function. */
17719 for (t = DECL_ARGUMENTS (cfun->decl); t; t = DECL_CHAIN (t))
17721 if (TREE_TYPE (t) == error_mark_node)
17722 continue;
17724 if (TYPE_MODE (TREE_TYPE (t)) == SDmode
17725 || TYPE_MODE (DECL_ARG_TYPE (t)) == SDmode)
17727 rtx stack = assign_stack_local (DDmode, GET_MODE_SIZE (DDmode), 0);
17728 cfun->machine->sdmode_stack_slot = adjust_address_nv (stack,
17729 SDmode, 0);
17730 return;
17735 static void
17736 rs6000_instantiate_decls (void)
17738 if (cfun->machine->sdmode_stack_slot != NULL_RTX)
17739 instantiate_decl_rtl (cfun->machine->sdmode_stack_slot);
17742 /* Given an rtx X being reloaded into a reg required to be
17743 in class CLASS, return the class of reg to actually use.
17744 In general this is just CLASS; but on some machines
17745 in some cases it is preferable to use a more restrictive class.
17747 On the RS/6000, we have to return NO_REGS when we want to reload a
17748 floating-point CONST_DOUBLE to force it to be copied to memory.
17750 We also don't want to reload integer values into floating-point
17751 registers if we can at all help it. In fact, this can
17752 cause reload to die, if it tries to generate a reload of CTR
17753 into a FP register and discovers it doesn't have the memory location
17754 required.
17756 ??? Would it be a good idea to have reload do the converse, that is
17757 try to reload floating modes into FP registers if possible?
17760 static enum reg_class
17761 rs6000_preferred_reload_class (rtx x, enum reg_class rclass)
17763 machine_mode mode = GET_MODE (x);
17764 bool is_constant = CONSTANT_P (x);
17766 /* For VSX, see if we should prefer FLOAT_REGS or ALTIVEC_REGS. Do not allow
17767 the reloading of address expressions using PLUS into floating point
17768 registers. */
17769 if (TARGET_VSX && VSX_REG_CLASS_P (rclass) && GET_CODE (x) != PLUS)
17771 if (is_constant)
17773 /* Zero is always allowed in all VSX registers. */
17774 if (x == CONST0_RTX (mode))
17775 return rclass;
17777 /* If this is a vector constant that can be formed with a few Altivec
17778 instructions, we want altivec registers. */
17779 if (GET_CODE (x) == CONST_VECTOR && easy_vector_constant (x, mode))
17780 return ALTIVEC_REGS;
17782 /* Force constant to memory. */
17783 return NO_REGS;
17786 /* If this is a scalar floating point value, prefer the traditional
17787 floating point registers so that we can use D-form (register+offset)
17788 addressing. */
17789 if (GET_MODE_SIZE (mode) < 16)
17790 return FLOAT_REGS;
17792 /* Prefer the Altivec registers if Altivec is handling the vector
17793 operations (i.e. V16QI, V8HI, and V4SI), or if we prefer Altivec
17794 loads. */
17795 if (VECTOR_UNIT_ALTIVEC_P (mode) || VECTOR_MEM_ALTIVEC_P (mode)
17796 || mode == V1TImode)
17797 return ALTIVEC_REGS;
17799 return rclass;
17802 if (is_constant || GET_CODE (x) == PLUS)
17804 if (reg_class_subset_p (GENERAL_REGS, rclass))
17805 return GENERAL_REGS;
17806 if (reg_class_subset_p (BASE_REGS, rclass))
17807 return BASE_REGS;
17808 return NO_REGS;
17811 if (GET_MODE_CLASS (mode) == MODE_INT && rclass == NON_SPECIAL_REGS)
17812 return GENERAL_REGS;
17814 return rclass;
17817 /* Debug version of rs6000_preferred_reload_class. */
17818 static enum reg_class
17819 rs6000_debug_preferred_reload_class (rtx x, enum reg_class rclass)
17821 enum reg_class ret = rs6000_preferred_reload_class (x, rclass);
17823 fprintf (stderr,
17824 "\nrs6000_preferred_reload_class, return %s, rclass = %s, "
17825 "mode = %s, x:\n",
17826 reg_class_names[ret], reg_class_names[rclass],
17827 GET_MODE_NAME (GET_MODE (x)));
17828 debug_rtx (x);
17830 return ret;
17833 /* If we are copying between FP or AltiVec registers and anything else, we need
17834 a memory location. The exception is when we are targeting ppc64 and the
17835 move to/from fpr to gpr instructions are available. Also, under VSX, you
17836 can copy vector registers from the FP register set to the Altivec register
17837 set and vice versa. */
17839 static bool
17840 rs6000_secondary_memory_needed (enum reg_class from_class,
17841 enum reg_class to_class,
17842 machine_mode mode)
17844 enum rs6000_reg_type from_type, to_type;
17845 bool altivec_p = ((from_class == ALTIVEC_REGS)
17846 || (to_class == ALTIVEC_REGS));
17848 /* If a simple/direct move is available, we don't need secondary memory */
17849 from_type = reg_class_to_reg_type[(int)from_class];
17850 to_type = reg_class_to_reg_type[(int)to_class];
17852 if (rs6000_secondary_reload_move (to_type, from_type, mode,
17853 (secondary_reload_info *)0, altivec_p))
17854 return false;
17856 /* If we have a floating point or vector register class, we need to use
17857 memory to transfer the data. */
17858 if (IS_FP_VECT_REG_TYPE (from_type) || IS_FP_VECT_REG_TYPE (to_type))
17859 return true;
17861 return false;
17864 /* Debug version of rs6000_secondary_memory_needed. */
17865 static bool
17866 rs6000_debug_secondary_memory_needed (enum reg_class from_class,
17867 enum reg_class to_class,
17868 machine_mode mode)
17870 bool ret = rs6000_secondary_memory_needed (from_class, to_class, mode);
17872 fprintf (stderr,
17873 "rs6000_secondary_memory_needed, return: %s, from_class = %s, "
17874 "to_class = %s, mode = %s\n",
17875 ret ? "true" : "false",
17876 reg_class_names[from_class],
17877 reg_class_names[to_class],
17878 GET_MODE_NAME (mode));
17880 return ret;
17883 /* Return the register class of a scratch register needed to copy IN into
17884 or out of a register in RCLASS in MODE. If it can be done directly,
17885 NO_REGS is returned. */
17887 static enum reg_class
17888 rs6000_secondary_reload_class (enum reg_class rclass, machine_mode mode,
17889 rtx in)
17891 int regno;
17893 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
17894 #if TARGET_MACHO
17895 && MACHOPIC_INDIRECT
17896 #endif
17899 /* We cannot copy a symbolic operand directly into anything
17900 other than BASE_REGS for TARGET_ELF. So indicate that a
17901 register from BASE_REGS is needed as an intermediate
17902 register.
17904 On Darwin, pic addresses require a load from memory, which
17905 needs a base register. */
17906 if (rclass != BASE_REGS
17907 && (GET_CODE (in) == SYMBOL_REF
17908 || GET_CODE (in) == HIGH
17909 || GET_CODE (in) == LABEL_REF
17910 || GET_CODE (in) == CONST))
17911 return BASE_REGS;
17914 if (GET_CODE (in) == REG)
17916 regno = REGNO (in);
17917 if (regno >= FIRST_PSEUDO_REGISTER)
17919 regno = true_regnum (in);
17920 if (regno >= FIRST_PSEUDO_REGISTER)
17921 regno = -1;
17924 else if (GET_CODE (in) == SUBREG)
17926 regno = true_regnum (in);
17927 if (regno >= FIRST_PSEUDO_REGISTER)
17928 regno = -1;
17930 else
17931 regno = -1;
17933 /* If we have VSX register moves, prefer moving scalar values between
17934 Altivec registers and GPR by going via an FPR (and then via memory)
17935 instead of reloading the secondary memory address for Altivec moves. */
17936 if (TARGET_VSX
17937 && GET_MODE_SIZE (mode) < 16
17938 && (((rclass == GENERAL_REGS || rclass == BASE_REGS)
17939 && (regno >= 0 && ALTIVEC_REGNO_P (regno)))
17940 || ((rclass == VSX_REGS || rclass == ALTIVEC_REGS)
17941 && (regno >= 0 && INT_REGNO_P (regno)))))
17942 return FLOAT_REGS;
17944 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
17945 into anything. */
17946 if (rclass == GENERAL_REGS || rclass == BASE_REGS
17947 || (regno >= 0 && INT_REGNO_P (regno)))
17948 return NO_REGS;
17950 /* Constants, memory, and VSX registers can go into VSX registers (both the
17951 traditional floating point and the altivec registers). */
17952 if (rclass == VSX_REGS
17953 && (regno == -1 || VSX_REGNO_P (regno)))
17954 return NO_REGS;
17956 /* Constants, memory, and FP registers can go into FP registers. */
17957 if ((regno == -1 || FP_REGNO_P (regno))
17958 && (rclass == FLOAT_REGS || rclass == NON_SPECIAL_REGS))
17959 return (mode != SDmode || lra_in_progress) ? NO_REGS : GENERAL_REGS;
17961 /* Memory, and AltiVec registers can go into AltiVec registers. */
17962 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
17963 && rclass == ALTIVEC_REGS)
17964 return NO_REGS;
17966 /* We can copy among the CR registers. */
17967 if ((rclass == CR_REGS || rclass == CR0_REGS)
17968 && regno >= 0 && CR_REGNO_P (regno))
17969 return NO_REGS;
17971 /* Otherwise, we need GENERAL_REGS. */
17972 return GENERAL_REGS;
17975 /* Debug version of rs6000_secondary_reload_class. */
17976 static enum reg_class
17977 rs6000_debug_secondary_reload_class (enum reg_class rclass,
17978 machine_mode mode, rtx in)
17980 enum reg_class ret = rs6000_secondary_reload_class (rclass, mode, in);
17981 fprintf (stderr,
17982 "\nrs6000_secondary_reload_class, return %s, rclass = %s, "
17983 "mode = %s, input rtx:\n",
17984 reg_class_names[ret], reg_class_names[rclass],
17985 GET_MODE_NAME (mode));
17986 debug_rtx (in);
17988 return ret;
17991 /* Return nonzero if for CLASS a mode change from FROM to TO is invalid. */
17993 static bool
17994 rs6000_cannot_change_mode_class (machine_mode from,
17995 machine_mode to,
17996 enum reg_class rclass)
17998 unsigned from_size = GET_MODE_SIZE (from);
17999 unsigned to_size = GET_MODE_SIZE (to);
18001 if (from_size != to_size)
18003 enum reg_class xclass = (TARGET_VSX) ? VSX_REGS : FLOAT_REGS;
18005 if (reg_classes_intersect_p (xclass, rclass))
18007 unsigned to_nregs = hard_regno_nregs[FIRST_FPR_REGNO][to];
18008 unsigned from_nregs = hard_regno_nregs[FIRST_FPR_REGNO][from];
18010 /* Don't allow 64-bit types to overlap with 128-bit types that take a
18011 single register under VSX because the scalar part of the register
18012 is in the upper 64-bits, and not the lower 64-bits. Types like
18013 TFmode/TDmode that take 2 scalar register can overlap. 128-bit
18014 IEEE floating point can't overlap, and neither can small
18015 values. */
18017 if (TARGET_IEEEQUAD && (to == TFmode || from == TFmode))
18018 return true;
18020 /* TDmode in floating-mode registers must always go into a register
18021 pair with the most significant word in the even-numbered register
18022 to match ISA requirements. In little-endian mode, this does not
18023 match subreg numbering, so we cannot allow subregs. */
18024 if (!BYTES_BIG_ENDIAN && (to == TDmode || from == TDmode))
18025 return true;
18027 if (from_size < 8 || to_size < 8)
18028 return true;
18030 if (from_size == 8 && (8 * to_nregs) != to_size)
18031 return true;
18033 if (to_size == 8 && (8 * from_nregs) != from_size)
18034 return true;
18036 return false;
18038 else
18039 return false;
18042 if (TARGET_E500_DOUBLE
18043 && ((((to) == DFmode) + ((from) == DFmode)) == 1
18044 || (((to) == TFmode) + ((from) == TFmode)) == 1
18045 || (((to) == DDmode) + ((from) == DDmode)) == 1
18046 || (((to) == TDmode) + ((from) == TDmode)) == 1
18047 || (((to) == DImode) + ((from) == DImode)) == 1))
18048 return true;
18050 /* Since the VSX register set includes traditional floating point registers
18051 and altivec registers, just check for the size being different instead of
18052 trying to check whether the modes are vector modes. Otherwise it won't
18053 allow say DF and DI to change classes. For types like TFmode and TDmode
18054 that take 2 64-bit registers, rather than a single 128-bit register, don't
18055 allow subregs of those types to other 128 bit types. */
18056 if (TARGET_VSX && VSX_REG_CLASS_P (rclass))
18058 unsigned num_regs = (from_size + 15) / 16;
18059 if (hard_regno_nregs[FIRST_FPR_REGNO][to] > num_regs
18060 || hard_regno_nregs[FIRST_FPR_REGNO][from] > num_regs)
18061 return true;
18063 return (from_size != 8 && from_size != 16);
18066 if (TARGET_ALTIVEC && rclass == ALTIVEC_REGS
18067 && (ALTIVEC_VECTOR_MODE (from) + ALTIVEC_VECTOR_MODE (to)) == 1)
18068 return true;
18070 if (TARGET_SPE && (SPE_VECTOR_MODE (from) + SPE_VECTOR_MODE (to)) == 1
18071 && reg_classes_intersect_p (GENERAL_REGS, rclass))
18072 return true;
18074 return false;
18077 /* Debug version of rs6000_cannot_change_mode_class. */
18078 static bool
18079 rs6000_debug_cannot_change_mode_class (machine_mode from,
18080 machine_mode to,
18081 enum reg_class rclass)
18083 bool ret = rs6000_cannot_change_mode_class (from, to, rclass);
18085 fprintf (stderr,
18086 "rs6000_cannot_change_mode_class, return %s, from = %s, "
18087 "to = %s, rclass = %s\n",
18088 ret ? "true" : "false",
18089 GET_MODE_NAME (from), GET_MODE_NAME (to),
18090 reg_class_names[rclass]);
18092 return ret;
18095 /* Return a string to do a move operation of 128 bits of data. */
18097 const char *
18098 rs6000_output_move_128bit (rtx operands[])
18100 rtx dest = operands[0];
18101 rtx src = operands[1];
18102 machine_mode mode = GET_MODE (dest);
18103 int dest_regno;
18104 int src_regno;
18105 bool dest_gpr_p, dest_fp_p, dest_vmx_p, dest_vsx_p;
18106 bool src_gpr_p, src_fp_p, src_vmx_p, src_vsx_p;
18108 if (REG_P (dest))
18110 dest_regno = REGNO (dest);
18111 dest_gpr_p = INT_REGNO_P (dest_regno);
18112 dest_fp_p = FP_REGNO_P (dest_regno);
18113 dest_vmx_p = ALTIVEC_REGNO_P (dest_regno);
18114 dest_vsx_p = dest_fp_p | dest_vmx_p;
18116 else
18118 dest_regno = -1;
18119 dest_gpr_p = dest_fp_p = dest_vmx_p = dest_vsx_p = false;
18122 if (REG_P (src))
18124 src_regno = REGNO (src);
18125 src_gpr_p = INT_REGNO_P (src_regno);
18126 src_fp_p = FP_REGNO_P (src_regno);
18127 src_vmx_p = ALTIVEC_REGNO_P (src_regno);
18128 src_vsx_p = src_fp_p | src_vmx_p;
18130 else
18132 src_regno = -1;
18133 src_gpr_p = src_fp_p = src_vmx_p = src_vsx_p = false;
18136 /* Register moves. */
18137 if (dest_regno >= 0 && src_regno >= 0)
18139 if (dest_gpr_p)
18141 if (src_gpr_p)
18142 return "#";
18144 else if (TARGET_VSX && TARGET_DIRECT_MOVE && src_vsx_p)
18145 return "#";
18148 else if (TARGET_VSX && dest_vsx_p)
18150 if (src_vsx_p)
18151 return "xxlor %x0,%x1,%x1";
18153 else if (TARGET_DIRECT_MOVE && src_gpr_p)
18154 return "#";
18157 else if (TARGET_ALTIVEC && dest_vmx_p && src_vmx_p)
18158 return "vor %0,%1,%1";
18160 else if (dest_fp_p && src_fp_p)
18161 return "#";
18164 /* Loads. */
18165 else if (dest_regno >= 0 && MEM_P (src))
18167 if (dest_gpr_p)
18169 if (TARGET_QUAD_MEMORY && quad_load_store_p (dest, src))
18170 return "lq %0,%1";
18171 else
18172 return "#";
18175 else if (TARGET_ALTIVEC && dest_vmx_p
18176 && altivec_indexed_or_indirect_operand (src, mode))
18177 return "lvx %0,%y1";
18179 else if (TARGET_VSX && dest_vsx_p)
18181 if (mode == V16QImode || mode == V8HImode || mode == V4SImode)
18182 return "lxvw4x %x0,%y1";
18183 else
18184 return "lxvd2x %x0,%y1";
18187 else if (TARGET_ALTIVEC && dest_vmx_p)
18188 return "lvx %0,%y1";
18190 else if (dest_fp_p)
18191 return "#";
18194 /* Stores. */
18195 else if (src_regno >= 0 && MEM_P (dest))
18197 if (src_gpr_p)
18199 if (TARGET_QUAD_MEMORY && quad_load_store_p (dest, src))
18200 return "stq %1,%0";
18201 else
18202 return "#";
18205 else if (TARGET_ALTIVEC && src_vmx_p
18206 && altivec_indexed_or_indirect_operand (src, mode))
18207 return "stvx %1,%y0";
18209 else if (TARGET_VSX && src_vsx_p)
18211 if (mode == V16QImode || mode == V8HImode || mode == V4SImode)
18212 return "stxvw4x %x1,%y0";
18213 else
18214 return "stxvd2x %x1,%y0";
18217 else if (TARGET_ALTIVEC && src_vmx_p)
18218 return "stvx %1,%y0";
18220 else if (src_fp_p)
18221 return "#";
18224 /* Constants. */
18225 else if (dest_regno >= 0
18226 && (GET_CODE (src) == CONST_INT
18227 || GET_CODE (src) == CONST_WIDE_INT
18228 || GET_CODE (src) == CONST_DOUBLE
18229 || GET_CODE (src) == CONST_VECTOR))
18231 if (dest_gpr_p)
18232 return "#";
18234 else if (TARGET_VSX && dest_vsx_p && zero_constant (src, mode))
18235 return "xxlxor %x0,%x0,%x0";
18237 else if (TARGET_ALTIVEC && dest_vmx_p)
18238 return output_vec_const_move (operands);
18241 if (TARGET_DEBUG_ADDR)
18243 fprintf (stderr, "\n===== Bad 128 bit move:\n");
18244 debug_rtx (gen_rtx_SET (dest, src));
18247 gcc_unreachable ();
18250 /* Validate a 128-bit move. */
18251 bool
18252 rs6000_move_128bit_ok_p (rtx operands[])
18254 machine_mode mode = GET_MODE (operands[0]);
18255 return (gpc_reg_operand (operands[0], mode)
18256 || gpc_reg_operand (operands[1], mode));
18259 /* Return true if a 128-bit move needs to be split. */
18260 bool
18261 rs6000_split_128bit_ok_p (rtx operands[])
18263 if (!reload_completed)
18264 return false;
18266 if (!gpr_or_gpr_p (operands[0], operands[1]))
18267 return false;
18269 if (quad_load_store_p (operands[0], operands[1]))
18270 return false;
18272 return true;
18276 /* Given a comparison operation, return the bit number in CCR to test. We
18277 know this is a valid comparison.
18279 SCC_P is 1 if this is for an scc. That means that %D will have been
18280 used instead of %C, so the bits will be in different places.
18282 Return -1 if OP isn't a valid comparison for some reason. */
18285 ccr_bit (rtx op, int scc_p)
18287 enum rtx_code code = GET_CODE (op);
18288 machine_mode cc_mode;
18289 int cc_regnum;
18290 int base_bit;
18291 rtx reg;
18293 if (!COMPARISON_P (op))
18294 return -1;
18296 reg = XEXP (op, 0);
18298 gcc_assert (GET_CODE (reg) == REG && CR_REGNO_P (REGNO (reg)));
18300 cc_mode = GET_MODE (reg);
18301 cc_regnum = REGNO (reg);
18302 base_bit = 4 * (cc_regnum - CR0_REGNO);
18304 validate_condition_mode (code, cc_mode);
18306 /* When generating a sCOND operation, only positive conditions are
18307 allowed. */
18308 gcc_assert (!scc_p
18309 || code == EQ || code == GT || code == LT || code == UNORDERED
18310 || code == GTU || code == LTU);
18312 switch (code)
18314 case NE:
18315 return scc_p ? base_bit + 3 : base_bit + 2;
18316 case EQ:
18317 return base_bit + 2;
18318 case GT: case GTU: case UNLE:
18319 return base_bit + 1;
18320 case LT: case LTU: case UNGE:
18321 return base_bit;
18322 case ORDERED: case UNORDERED:
18323 return base_bit + 3;
18325 case GE: case GEU:
18326 /* If scc, we will have done a cror to put the bit in the
18327 unordered position. So test that bit. For integer, this is ! LT
18328 unless this is an scc insn. */
18329 return scc_p ? base_bit + 3 : base_bit;
18331 case LE: case LEU:
18332 return scc_p ? base_bit + 3 : base_bit + 1;
18334 default:
18335 gcc_unreachable ();
18339 /* Return the GOT register. */
18342 rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
18344 /* The second flow pass currently (June 1999) can't update
18345 regs_ever_live without disturbing other parts of the compiler, so
18346 update it here to make the prolog/epilogue code happy. */
18347 if (!can_create_pseudo_p ()
18348 && !df_regs_ever_live_p (RS6000_PIC_OFFSET_TABLE_REGNUM))
18349 df_set_regs_ever_live (RS6000_PIC_OFFSET_TABLE_REGNUM, true);
18351 crtl->uses_pic_offset_table = 1;
18353 return pic_offset_table_rtx;
18356 static rs6000_stack_t stack_info;
18358 /* Function to init struct machine_function.
18359 This will be called, via a pointer variable,
18360 from push_function_context. */
18362 static struct machine_function *
18363 rs6000_init_machine_status (void)
18365 stack_info.reload_completed = 0;
18366 return ggc_cleared_alloc<machine_function> ();
18369 #define INT_P(X) (GET_CODE (X) == CONST_INT && GET_MODE (X) == VOIDmode)
18372 extract_MB (rtx op)
18374 int i;
18375 unsigned long val = INTVAL (op);
18377 /* If the high bit is zero, the value is the first 1 bit we find
18378 from the left. */
18379 if ((val & 0x80000000) == 0)
18381 gcc_assert (val & 0xffffffff);
18383 i = 1;
18384 while (((val <<= 1) & 0x80000000) == 0)
18385 ++i;
18386 return i;
18389 /* If the high bit is set and the low bit is not, or the mask is all
18390 1's, the value is zero. */
18391 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
18392 return 0;
18394 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
18395 from the right. */
18396 i = 31;
18397 while (((val >>= 1) & 1) != 0)
18398 --i;
18400 return i;
18404 extract_ME (rtx op)
18406 int i;
18407 unsigned long val = INTVAL (op);
18409 /* If the low bit is zero, the value is the first 1 bit we find from
18410 the right. */
18411 if ((val & 1) == 0)
18413 gcc_assert (val & 0xffffffff);
18415 i = 30;
18416 while (((val >>= 1) & 1) == 0)
18417 --i;
18419 return i;
18422 /* If the low bit is set and the high bit is not, or the mask is all
18423 1's, the value is 31. */
18424 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
18425 return 31;
18427 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
18428 from the left. */
18429 i = 0;
18430 while (((val <<= 1) & 0x80000000) != 0)
18431 ++i;
18433 return i;
18436 /* Write out a function code label. */
18438 void
18439 rs6000_output_function_entry (FILE *file, const char *fname)
18441 if (fname[0] != '.')
18443 switch (DEFAULT_ABI)
18445 default:
18446 gcc_unreachable ();
18448 case ABI_AIX:
18449 if (DOT_SYMBOLS)
18450 putc ('.', file);
18451 else
18452 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "L.");
18453 break;
18455 case ABI_ELFv2:
18456 case ABI_V4:
18457 case ABI_DARWIN:
18458 break;
18462 RS6000_OUTPUT_BASENAME (file, fname);
18465 /* Print an operand. Recognize special options, documented below. */
18467 #if TARGET_ELF
18468 #define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
18469 #define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
18470 #else
18471 #define SMALL_DATA_RELOC "sda21"
18472 #define SMALL_DATA_REG 0
18473 #endif
18475 void
18476 print_operand (FILE *file, rtx x, int code)
18478 int i;
18479 unsigned HOST_WIDE_INT uval;
18481 switch (code)
18483 /* %a is output_address. */
18485 case 'b':
18486 /* If constant, low-order 16 bits of constant, unsigned.
18487 Otherwise, write normally. */
18488 if (INT_P (x))
18489 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0xffff);
18490 else
18491 print_operand (file, x, 0);
18492 return;
18494 case 'B':
18495 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
18496 for 64-bit mask direction. */
18497 putc (((INTVAL (x) & 1) == 0 ? 'r' : 'l'), file);
18498 return;
18500 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
18501 output_operand. */
18503 case 'D':
18504 /* Like 'J' but get to the GT bit only. */
18505 gcc_assert (REG_P (x));
18507 /* Bit 1 is GT bit. */
18508 i = 4 * (REGNO (x) - CR0_REGNO) + 1;
18510 /* Add one for shift count in rlinm for scc. */
18511 fprintf (file, "%d", i + 1);
18512 return;
18514 case 'e':
18515 /* If the low 16 bits are 0, but some other bit is set, write 's'. */
18516 if (! INT_P (x))
18518 output_operand_lossage ("invalid %%e value");
18519 return;
18522 uval = INTVAL (x);
18523 if ((uval & 0xffff) == 0 && uval != 0)
18524 putc ('s', file);
18525 return;
18527 case 'E':
18528 /* X is a CR register. Print the number of the EQ bit of the CR */
18529 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
18530 output_operand_lossage ("invalid %%E value");
18531 else
18532 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
18533 return;
18535 case 'f':
18536 /* X is a CR register. Print the shift count needed to move it
18537 to the high-order four bits. */
18538 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
18539 output_operand_lossage ("invalid %%f value");
18540 else
18541 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
18542 return;
18544 case 'F':
18545 /* Similar, but print the count for the rotate in the opposite
18546 direction. */
18547 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
18548 output_operand_lossage ("invalid %%F value");
18549 else
18550 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
18551 return;
18553 case 'G':
18554 /* X is a constant integer. If it is negative, print "m",
18555 otherwise print "z". This is to make an aze or ame insn. */
18556 if (GET_CODE (x) != CONST_INT)
18557 output_operand_lossage ("invalid %%G value");
18558 else if (INTVAL (x) >= 0)
18559 putc ('z', file);
18560 else
18561 putc ('m', file);
18562 return;
18564 case 'h':
18565 /* If constant, output low-order five bits. Otherwise, write
18566 normally. */
18567 if (INT_P (x))
18568 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 31);
18569 else
18570 print_operand (file, x, 0);
18571 return;
18573 case 'H':
18574 /* If constant, output low-order six bits. Otherwise, write
18575 normally. */
18576 if (INT_P (x))
18577 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 63);
18578 else
18579 print_operand (file, x, 0);
18580 return;
18582 case 'I':
18583 /* Print `i' if this is a constant, else nothing. */
18584 if (INT_P (x))
18585 putc ('i', file);
18586 return;
18588 case 'j':
18589 /* Write the bit number in CCR for jump. */
18590 i = ccr_bit (x, 0);
18591 if (i == -1)
18592 output_operand_lossage ("invalid %%j code");
18593 else
18594 fprintf (file, "%d", i);
18595 return;
18597 case 'J':
18598 /* Similar, but add one for shift count in rlinm for scc and pass
18599 scc flag to `ccr_bit'. */
18600 i = ccr_bit (x, 1);
18601 if (i == -1)
18602 output_operand_lossage ("invalid %%J code");
18603 else
18604 /* If we want bit 31, write a shift count of zero, not 32. */
18605 fprintf (file, "%d", i == 31 ? 0 : i + 1);
18606 return;
18608 case 'k':
18609 /* X must be a constant. Write the 1's complement of the
18610 constant. */
18611 if (! INT_P (x))
18612 output_operand_lossage ("invalid %%k value");
18613 else
18614 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INTVAL (x));
18615 return;
18617 case 'K':
18618 /* X must be a symbolic constant on ELF. Write an
18619 expression suitable for an 'addi' that adds in the low 16
18620 bits of the MEM. */
18621 if (GET_CODE (x) == CONST)
18623 if (GET_CODE (XEXP (x, 0)) != PLUS
18624 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
18625 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
18626 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
18627 output_operand_lossage ("invalid %%K value");
18629 print_operand_address (file, x);
18630 fputs ("@l", file);
18631 return;
18633 /* %l is output_asm_label. */
18635 case 'L':
18636 /* Write second word of DImode or DFmode reference. Works on register
18637 or non-indexed memory only. */
18638 if (REG_P (x))
18639 fputs (reg_names[REGNO (x) + 1], file);
18640 else if (MEM_P (x))
18642 /* Handle possible auto-increment. Since it is pre-increment and
18643 we have already done it, we can just use an offset of word. */
18644 if (GET_CODE (XEXP (x, 0)) == PRE_INC
18645 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
18646 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0),
18647 UNITS_PER_WORD));
18648 else if (GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
18649 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0),
18650 UNITS_PER_WORD));
18651 else
18652 output_address (XEXP (adjust_address_nv (x, SImode,
18653 UNITS_PER_WORD),
18654 0));
18656 if (small_data_operand (x, GET_MODE (x)))
18657 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
18658 reg_names[SMALL_DATA_REG]);
18660 return;
18662 case 'm':
18663 /* MB value for a mask operand. */
18664 if (! mask_operand (x, SImode))
18665 output_operand_lossage ("invalid %%m value");
18667 fprintf (file, "%d", extract_MB (x));
18668 return;
18670 case 'M':
18671 /* ME value for a mask operand. */
18672 if (! mask_operand (x, SImode))
18673 output_operand_lossage ("invalid %%M value");
18675 fprintf (file, "%d", extract_ME (x));
18676 return;
18678 /* %n outputs the negative of its operand. */
18680 case 'N':
18681 /* Write the number of elements in the vector times 4. */
18682 if (GET_CODE (x) != PARALLEL)
18683 output_operand_lossage ("invalid %%N value");
18684 else
18685 fprintf (file, "%d", XVECLEN (x, 0) * 4);
18686 return;
18688 case 'O':
18689 /* Similar, but subtract 1 first. */
18690 if (GET_CODE (x) != PARALLEL)
18691 output_operand_lossage ("invalid %%O value");
18692 else
18693 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
18694 return;
18696 case 'p':
18697 /* X is a CONST_INT that is a power of two. Output the logarithm. */
18698 if (! INT_P (x)
18699 || INTVAL (x) < 0
18700 || (i = exact_log2 (INTVAL (x))) < 0)
18701 output_operand_lossage ("invalid %%p value");
18702 else
18703 fprintf (file, "%d", i);
18704 return;
18706 case 'P':
18707 /* The operand must be an indirect memory reference. The result
18708 is the register name. */
18709 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
18710 || REGNO (XEXP (x, 0)) >= 32)
18711 output_operand_lossage ("invalid %%P value");
18712 else
18713 fputs (reg_names[REGNO (XEXP (x, 0))], file);
18714 return;
18716 case 'q':
18717 /* This outputs the logical code corresponding to a boolean
18718 expression. The expression may have one or both operands
18719 negated (if one, only the first one). For condition register
18720 logical operations, it will also treat the negated
18721 CR codes as NOTs, but not handle NOTs of them. */
18723 const char *const *t = 0;
18724 const char *s;
18725 enum rtx_code code = GET_CODE (x);
18726 static const char * const tbl[3][3] = {
18727 { "and", "andc", "nor" },
18728 { "or", "orc", "nand" },
18729 { "xor", "eqv", "xor" } };
18731 if (code == AND)
18732 t = tbl[0];
18733 else if (code == IOR)
18734 t = tbl[1];
18735 else if (code == XOR)
18736 t = tbl[2];
18737 else
18738 output_operand_lossage ("invalid %%q value");
18740 if (GET_CODE (XEXP (x, 0)) != NOT)
18741 s = t[0];
18742 else
18744 if (GET_CODE (XEXP (x, 1)) == NOT)
18745 s = t[2];
18746 else
18747 s = t[1];
18750 fputs (s, file);
18752 return;
18754 case 'Q':
18755 if (! TARGET_MFCRF)
18756 return;
18757 fputc (',', file);
18758 /* FALLTHRU */
18760 case 'R':
18761 /* X is a CR register. Print the mask for `mtcrf'. */
18762 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
18763 output_operand_lossage ("invalid %%R value");
18764 else
18765 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
18766 return;
18768 case 's':
18769 /* Low 5 bits of 32 - value */
18770 if (! INT_P (x))
18771 output_operand_lossage ("invalid %%s value");
18772 else
18773 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 31);
18774 return;
18776 case 'S':
18777 /* PowerPC64 mask position. All 0's is excluded.
18778 CONST_INT 32-bit mask is considered sign-extended so any
18779 transition must occur within the CONST_INT, not on the boundary. */
18780 if (! mask64_operand (x, DImode))
18781 output_operand_lossage ("invalid %%S value");
18783 uval = INTVAL (x);
18785 if (uval & 1) /* Clear Left */
18787 #if HOST_BITS_PER_WIDE_INT > 64
18788 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
18789 #endif
18790 i = 64;
18792 else /* Clear Right */
18794 uval = ~uval;
18795 #if HOST_BITS_PER_WIDE_INT > 64
18796 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
18797 #endif
18798 i = 63;
18800 while (uval != 0)
18801 --i, uval >>= 1;
18802 gcc_assert (i >= 0);
18803 fprintf (file, "%d", i);
18804 return;
18806 case 't':
18807 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
18808 gcc_assert (REG_P (x) && GET_MODE (x) == CCmode);
18810 /* Bit 3 is OV bit. */
18811 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
18813 /* If we want bit 31, write a shift count of zero, not 32. */
18814 fprintf (file, "%d", i == 31 ? 0 : i + 1);
18815 return;
18817 case 'T':
18818 /* Print the symbolic name of a branch target register. */
18819 if (GET_CODE (x) != REG || (REGNO (x) != LR_REGNO
18820 && REGNO (x) != CTR_REGNO))
18821 output_operand_lossage ("invalid %%T value");
18822 else if (REGNO (x) == LR_REGNO)
18823 fputs ("lr", file);
18824 else
18825 fputs ("ctr", file);
18826 return;
18828 case 'u':
18829 /* High-order or low-order 16 bits of constant, whichever is non-zero,
18830 for use in unsigned operand. */
18831 if (! INT_P (x))
18833 output_operand_lossage ("invalid %%u value");
18834 return;
18837 uval = INTVAL (x);
18838 if ((uval & 0xffff) == 0)
18839 uval >>= 16;
18841 fprintf (file, HOST_WIDE_INT_PRINT_HEX, uval & 0xffff);
18842 return;
18844 case 'v':
18845 /* High-order 16 bits of constant for use in signed operand. */
18846 if (! INT_P (x))
18847 output_operand_lossage ("invalid %%v value");
18848 else
18849 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
18850 (INTVAL (x) >> 16) & 0xffff);
18851 return;
18853 case 'U':
18854 /* Print `u' if this has an auto-increment or auto-decrement. */
18855 if (MEM_P (x)
18856 && (GET_CODE (XEXP (x, 0)) == PRE_INC
18857 || GET_CODE (XEXP (x, 0)) == PRE_DEC
18858 || GET_CODE (XEXP (x, 0)) == PRE_MODIFY))
18859 putc ('u', file);
18860 return;
18862 case 'V':
18863 /* Print the trap code for this operand. */
18864 switch (GET_CODE (x))
18866 case EQ:
18867 fputs ("eq", file); /* 4 */
18868 break;
18869 case NE:
18870 fputs ("ne", file); /* 24 */
18871 break;
18872 case LT:
18873 fputs ("lt", file); /* 16 */
18874 break;
18875 case LE:
18876 fputs ("le", file); /* 20 */
18877 break;
18878 case GT:
18879 fputs ("gt", file); /* 8 */
18880 break;
18881 case GE:
18882 fputs ("ge", file); /* 12 */
18883 break;
18884 case LTU:
18885 fputs ("llt", file); /* 2 */
18886 break;
18887 case LEU:
18888 fputs ("lle", file); /* 6 */
18889 break;
18890 case GTU:
18891 fputs ("lgt", file); /* 1 */
18892 break;
18893 case GEU:
18894 fputs ("lge", file); /* 5 */
18895 break;
18896 default:
18897 gcc_unreachable ();
18899 break;
18901 case 'w':
18902 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
18903 normally. */
18904 if (INT_P (x))
18905 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
18906 ((INTVAL (x) & 0xffff) ^ 0x8000) - 0x8000);
18907 else
18908 print_operand (file, x, 0);
18909 return;
18911 case 'W':
18912 /* MB value for a PowerPC64 rldic operand. */
18913 i = clz_hwi (INTVAL (x));
18915 fprintf (file, "%d", i);
18916 return;
18918 case 'x':
18919 /* X is a FPR or Altivec register used in a VSX context. */
18920 if (GET_CODE (x) != REG || !VSX_REGNO_P (REGNO (x)))
18921 output_operand_lossage ("invalid %%x value");
18922 else
18924 int reg = REGNO (x);
18925 int vsx_reg = (FP_REGNO_P (reg)
18926 ? reg - 32
18927 : reg - FIRST_ALTIVEC_REGNO + 32);
18929 #ifdef TARGET_REGNAMES
18930 if (TARGET_REGNAMES)
18931 fprintf (file, "%%vs%d", vsx_reg);
18932 else
18933 #endif
18934 fprintf (file, "%d", vsx_reg);
18936 return;
18938 case 'X':
18939 if (MEM_P (x)
18940 && (legitimate_indexed_address_p (XEXP (x, 0), 0)
18941 || (GET_CODE (XEXP (x, 0)) == PRE_MODIFY
18942 && legitimate_indexed_address_p (XEXP (XEXP (x, 0), 1), 0))))
18943 putc ('x', file);
18944 return;
18946 case 'Y':
18947 /* Like 'L', for third word of TImode/PTImode */
18948 if (REG_P (x))
18949 fputs (reg_names[REGNO (x) + 2], file);
18950 else if (MEM_P (x))
18952 if (GET_CODE (XEXP (x, 0)) == PRE_INC
18953 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
18954 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0), 8));
18955 else if (GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
18956 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0), 8));
18957 else
18958 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
18959 if (small_data_operand (x, GET_MODE (x)))
18960 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
18961 reg_names[SMALL_DATA_REG]);
18963 return;
18965 case 'z':
18966 /* X is a SYMBOL_REF. Write out the name preceded by a
18967 period and without any trailing data in brackets. Used for function
18968 names. If we are configured for System V (or the embedded ABI) on
18969 the PowerPC, do not emit the period, since those systems do not use
18970 TOCs and the like. */
18971 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18973 /* For macho, check to see if we need a stub. */
18974 if (TARGET_MACHO)
18976 const char *name = XSTR (x, 0);
18977 #if TARGET_MACHO
18978 if (darwin_emit_branch_islands
18979 && MACHOPIC_INDIRECT
18980 && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
18981 name = machopic_indirection_name (x, /*stub_p=*/true);
18982 #endif
18983 assemble_name (file, name);
18985 else if (!DOT_SYMBOLS)
18986 assemble_name (file, XSTR (x, 0));
18987 else
18988 rs6000_output_function_entry (file, XSTR (x, 0));
18989 return;
18991 case 'Z':
18992 /* Like 'L', for last word of TImode/PTImode. */
18993 if (REG_P (x))
18994 fputs (reg_names[REGNO (x) + 3], file);
18995 else if (MEM_P (x))
18997 if (GET_CODE (XEXP (x, 0)) == PRE_INC
18998 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
18999 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0), 12));
19000 else if (GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
19001 output_address (plus_constant (Pmode, XEXP (XEXP (x, 0), 0), 12));
19002 else
19003 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
19004 if (small_data_operand (x, GET_MODE (x)))
19005 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
19006 reg_names[SMALL_DATA_REG]);
19008 return;
19010 /* Print AltiVec or SPE memory operand. */
19011 case 'y':
19013 rtx tmp;
19015 gcc_assert (MEM_P (x));
19017 tmp = XEXP (x, 0);
19019 /* Ugly hack because %y is overloaded. */
19020 if ((TARGET_SPE || TARGET_E500_DOUBLE)
19021 && (GET_MODE_SIZE (GET_MODE (x)) == 8
19022 || GET_MODE (x) == TFmode
19023 || GET_MODE (x) == TImode
19024 || GET_MODE (x) == PTImode))
19026 /* Handle [reg]. */
19027 if (REG_P (tmp))
19029 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
19030 break;
19032 /* Handle [reg+UIMM]. */
19033 else if (GET_CODE (tmp) == PLUS &&
19034 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
19036 int x;
19038 gcc_assert (REG_P (XEXP (tmp, 0)));
19040 x = INTVAL (XEXP (tmp, 1));
19041 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
19042 break;
19045 /* Fall through. Must be [reg+reg]. */
19047 if (VECTOR_MEM_ALTIVEC_P (GET_MODE (x))
19048 && GET_CODE (tmp) == AND
19049 && GET_CODE (XEXP (tmp, 1)) == CONST_INT
19050 && INTVAL (XEXP (tmp, 1)) == -16)
19051 tmp = XEXP (tmp, 0);
19052 else if (VECTOR_MEM_VSX_P (GET_MODE (x))
19053 && GET_CODE (tmp) == PRE_MODIFY)
19054 tmp = XEXP (tmp, 1);
19055 if (REG_P (tmp))
19056 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
19057 else
19059 if (GET_CODE (tmp) != PLUS
19060 || !REG_P (XEXP (tmp, 0))
19061 || !REG_P (XEXP (tmp, 1)))
19063 output_operand_lossage ("invalid %%y value, try using the 'Z' constraint");
19064 break;
19067 if (REGNO (XEXP (tmp, 0)) == 0)
19068 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
19069 reg_names[ REGNO (XEXP (tmp, 0)) ]);
19070 else
19071 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
19072 reg_names[ REGNO (XEXP (tmp, 1)) ]);
19074 break;
19077 case 0:
19078 if (REG_P (x))
19079 fprintf (file, "%s", reg_names[REGNO (x)]);
19080 else if (MEM_P (x))
19082 /* We need to handle PRE_INC and PRE_DEC here, since we need to
19083 know the width from the mode. */
19084 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
19085 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
19086 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
19087 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
19088 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
19089 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
19090 else if (GET_CODE (XEXP (x, 0)) == PRE_MODIFY)
19091 output_address (XEXP (XEXP (x, 0), 1));
19092 else
19093 output_address (XEXP (x, 0));
19095 else
19097 if (toc_relative_expr_p (x, false))
19098 /* This hack along with a corresponding hack in
19099 rs6000_output_addr_const_extra arranges to output addends
19100 where the assembler expects to find them. eg.
19101 (plus (unspec [(symbol_ref ("x")) (reg 2)] tocrel) 4)
19102 without this hack would be output as "x@toc+4". We
19103 want "x+4@toc". */
19104 output_addr_const (file, CONST_CAST_RTX (tocrel_base));
19105 else
19106 output_addr_const (file, x);
19108 return;
19110 case '&':
19111 if (const char *name = get_some_local_dynamic_name ())
19112 assemble_name (file, name);
19113 else
19114 output_operand_lossage ("'%%&' used without any "
19115 "local dynamic TLS references");
19116 return;
19118 default:
19119 output_operand_lossage ("invalid %%xn code");
19123 /* Print the address of an operand. */
19125 void
19126 print_operand_address (FILE *file, rtx x)
19128 if (REG_P (x))
19129 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
19130 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
19131 || GET_CODE (x) == LABEL_REF)
19133 output_addr_const (file, x);
19134 if (small_data_operand (x, GET_MODE (x)))
19135 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
19136 reg_names[SMALL_DATA_REG]);
19137 else
19138 gcc_assert (!TARGET_TOC);
19140 else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
19141 && REG_P (XEXP (x, 1)))
19143 if (REGNO (XEXP (x, 0)) == 0)
19144 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
19145 reg_names[ REGNO (XEXP (x, 0)) ]);
19146 else
19147 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
19148 reg_names[ REGNO (XEXP (x, 1)) ]);
19150 else if (GET_CODE (x) == PLUS && REG_P (XEXP (x, 0))
19151 && GET_CODE (XEXP (x, 1)) == CONST_INT)
19152 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
19153 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
19154 #if TARGET_MACHO
19155 else if (GET_CODE (x) == LO_SUM && REG_P (XEXP (x, 0))
19156 && CONSTANT_P (XEXP (x, 1)))
19158 fprintf (file, "lo16(");
19159 output_addr_const (file, XEXP (x, 1));
19160 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
19162 #endif
19163 #if TARGET_ELF
19164 else if (GET_CODE (x) == LO_SUM && REG_P (XEXP (x, 0))
19165 && CONSTANT_P (XEXP (x, 1)))
19167 output_addr_const (file, XEXP (x, 1));
19168 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
19170 #endif
19171 else if (toc_relative_expr_p (x, false))
19173 /* This hack along with a corresponding hack in
19174 rs6000_output_addr_const_extra arranges to output addends
19175 where the assembler expects to find them. eg.
19176 (lo_sum (reg 9)
19177 . (plus (unspec [(symbol_ref ("x")) (reg 2)] tocrel) 8))
19178 without this hack would be output as "x@toc+8@l(9)". We
19179 want "x+8@toc@l(9)". */
19180 output_addr_const (file, CONST_CAST_RTX (tocrel_base));
19181 if (GET_CODE (x) == LO_SUM)
19182 fprintf (file, "@l(%s)", reg_names[REGNO (XEXP (x, 0))]);
19183 else
19184 fprintf (file, "(%s)", reg_names[REGNO (XVECEXP (tocrel_base, 0, 1))]);
19186 else
19187 gcc_unreachable ();
19190 /* Implement TARGET_OUTPUT_ADDR_CONST_EXTRA. */
19192 static bool
19193 rs6000_output_addr_const_extra (FILE *file, rtx x)
19195 if (GET_CODE (x) == UNSPEC)
19196 switch (XINT (x, 1))
19198 case UNSPEC_TOCREL:
19199 gcc_checking_assert (GET_CODE (XVECEXP (x, 0, 0)) == SYMBOL_REF
19200 && REG_P (XVECEXP (x, 0, 1))
19201 && REGNO (XVECEXP (x, 0, 1)) == TOC_REGISTER);
19202 output_addr_const (file, XVECEXP (x, 0, 0));
19203 if (x == tocrel_base && tocrel_offset != const0_rtx)
19205 if (INTVAL (tocrel_offset) >= 0)
19206 fprintf (file, "+");
19207 output_addr_const (file, CONST_CAST_RTX (tocrel_offset));
19209 if (!TARGET_AIX || (TARGET_ELF && TARGET_MINIMAL_TOC))
19211 putc ('-', file);
19212 assemble_name (file, toc_label_name);
19214 else if (TARGET_ELF)
19215 fputs ("@toc", file);
19216 return true;
19218 #if TARGET_MACHO
19219 case UNSPEC_MACHOPIC_OFFSET:
19220 output_addr_const (file, XVECEXP (x, 0, 0));
19221 putc ('-', file);
19222 machopic_output_function_base_name (file);
19223 return true;
19224 #endif
19226 return false;
19229 /* Target hook for assembling integer objects. The PowerPC version has
19230 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
19231 is defined. It also needs to handle DI-mode objects on 64-bit
19232 targets. */
19234 static bool
19235 rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
19237 #ifdef RELOCATABLE_NEEDS_FIXUP
19238 /* Special handling for SI values. */
19239 if (RELOCATABLE_NEEDS_FIXUP && size == 4 && aligned_p)
19241 static int recurse = 0;
19243 /* For -mrelocatable, we mark all addresses that need to be fixed up in
19244 the .fixup section. Since the TOC section is already relocated, we
19245 don't need to mark it here. We used to skip the text section, but it
19246 should never be valid for relocated addresses to be placed in the text
19247 section. */
19248 if (TARGET_RELOCATABLE
19249 && in_section != toc_section
19250 && !recurse
19251 && !CONST_SCALAR_INT_P (x)
19252 && CONSTANT_P (x))
19254 char buf[256];
19256 recurse = 1;
19257 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
19258 fixuplabelno++;
19259 ASM_OUTPUT_LABEL (asm_out_file, buf);
19260 fprintf (asm_out_file, "\t.long\t(");
19261 output_addr_const (asm_out_file, x);
19262 fprintf (asm_out_file, ")@fixup\n");
19263 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
19264 ASM_OUTPUT_ALIGN (asm_out_file, 2);
19265 fprintf (asm_out_file, "\t.long\t");
19266 assemble_name (asm_out_file, buf);
19267 fprintf (asm_out_file, "\n\t.previous\n");
19268 recurse = 0;
19269 return true;
19271 /* Remove initial .'s to turn a -mcall-aixdesc function
19272 address into the address of the descriptor, not the function
19273 itself. */
19274 else if (GET_CODE (x) == SYMBOL_REF
19275 && XSTR (x, 0)[0] == '.'
19276 && DEFAULT_ABI == ABI_AIX)
19278 const char *name = XSTR (x, 0);
19279 while (*name == '.')
19280 name++;
19282 fprintf (asm_out_file, "\t.long\t%s\n", name);
19283 return true;
19286 #endif /* RELOCATABLE_NEEDS_FIXUP */
19287 return default_assemble_integer (x, size, aligned_p);
19290 #if defined (HAVE_GAS_HIDDEN) && !TARGET_MACHO
19291 /* Emit an assembler directive to set symbol visibility for DECL to
19292 VISIBILITY_TYPE. */
19294 static void
19295 rs6000_assemble_visibility (tree decl, int vis)
19297 if (TARGET_XCOFF)
19298 return;
19300 /* Functions need to have their entry point symbol visibility set as
19301 well as their descriptor symbol visibility. */
19302 if (DEFAULT_ABI == ABI_AIX
19303 && DOT_SYMBOLS
19304 && TREE_CODE (decl) == FUNCTION_DECL)
19306 static const char * const visibility_types[] = {
19307 NULL, "internal", "hidden", "protected"
19310 const char *name, *type;
19312 name = ((* targetm.strip_name_encoding)
19313 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
19314 type = visibility_types[vis];
19316 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
19317 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
19319 else
19320 default_assemble_visibility (decl, vis);
19322 #endif
19324 enum rtx_code
19325 rs6000_reverse_condition (machine_mode mode, enum rtx_code code)
19327 /* Reversal of FP compares takes care -- an ordered compare
19328 becomes an unordered compare and vice versa. */
19329 if (mode == CCFPmode
19330 && (!flag_finite_math_only
19331 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
19332 || code == UNEQ || code == LTGT))
19333 return reverse_condition_maybe_unordered (code);
19334 else
19335 return reverse_condition (code);
19338 /* Generate a compare for CODE. Return a brand-new rtx that
19339 represents the result of the compare. */
19341 static rtx
19342 rs6000_generate_compare (rtx cmp, machine_mode mode)
19344 machine_mode comp_mode;
19345 rtx compare_result;
19346 enum rtx_code code = GET_CODE (cmp);
19347 rtx op0 = XEXP (cmp, 0);
19348 rtx op1 = XEXP (cmp, 1);
19350 if (FLOAT_MODE_P (mode))
19351 comp_mode = CCFPmode;
19352 else if (code == GTU || code == LTU
19353 || code == GEU || code == LEU)
19354 comp_mode = CCUNSmode;
19355 else if ((code == EQ || code == NE)
19356 && unsigned_reg_p (op0)
19357 && (unsigned_reg_p (op1)
19358 || (CONST_INT_P (op1) && INTVAL (op1) != 0)))
19359 /* These are unsigned values, perhaps there will be a later
19360 ordering compare that can be shared with this one. */
19361 comp_mode = CCUNSmode;
19362 else
19363 comp_mode = CCmode;
19365 /* If we have an unsigned compare, make sure we don't have a signed value as
19366 an immediate. */
19367 if (comp_mode == CCUNSmode && GET_CODE (op1) == CONST_INT
19368 && INTVAL (op1) < 0)
19370 op0 = copy_rtx_if_shared (op0);
19371 op1 = force_reg (GET_MODE (op0), op1);
19372 cmp = gen_rtx_fmt_ee (code, GET_MODE (cmp), op0, op1);
19375 /* First, the compare. */
19376 compare_result = gen_reg_rtx (comp_mode);
19378 /* E500 FP compare instructions on the GPRs. Yuck! */
19379 if ((!TARGET_FPRS && TARGET_HARD_FLOAT)
19380 && FLOAT_MODE_P (mode))
19382 rtx cmp, or_result, compare_result2;
19383 machine_mode op_mode = GET_MODE (op0);
19384 bool reverse_p;
19386 if (op_mode == VOIDmode)
19387 op_mode = GET_MODE (op1);
19389 /* First reverse the condition codes that aren't directly supported. */
19390 switch (code)
19392 case NE:
19393 case UNLT:
19394 case UNLE:
19395 case UNGT:
19396 case UNGE:
19397 code = reverse_condition_maybe_unordered (code);
19398 reverse_p = true;
19399 break;
19401 case EQ:
19402 case LT:
19403 case LE:
19404 case GT:
19405 case GE:
19406 reverse_p = false;
19407 break;
19409 default:
19410 gcc_unreachable ();
19413 /* The E500 FP compare instructions toggle the GT bit (CR bit 1) only.
19414 This explains the following mess. */
19416 switch (code)
19418 case EQ:
19419 switch (op_mode)
19421 case SFmode:
19422 cmp = (flag_finite_math_only && !flag_trapping_math)
19423 ? gen_tstsfeq_gpr (compare_result, op0, op1)
19424 : gen_cmpsfeq_gpr (compare_result, op0, op1);
19425 break;
19427 case DFmode:
19428 cmp = (flag_finite_math_only && !flag_trapping_math)
19429 ? gen_tstdfeq_gpr (compare_result, op0, op1)
19430 : gen_cmpdfeq_gpr (compare_result, op0, op1);
19431 break;
19433 case TFmode:
19434 cmp = (flag_finite_math_only && !flag_trapping_math)
19435 ? gen_tsttfeq_gpr (compare_result, op0, op1)
19436 : gen_cmptfeq_gpr (compare_result, op0, op1);
19437 break;
19439 default:
19440 gcc_unreachable ();
19442 break;
19444 case GT:
19445 case GE:
19446 switch (op_mode)
19448 case SFmode:
19449 cmp = (flag_finite_math_only && !flag_trapping_math)
19450 ? gen_tstsfgt_gpr (compare_result, op0, op1)
19451 : gen_cmpsfgt_gpr (compare_result, op0, op1);
19452 break;
19454 case DFmode:
19455 cmp = (flag_finite_math_only && !flag_trapping_math)
19456 ? gen_tstdfgt_gpr (compare_result, op0, op1)
19457 : gen_cmpdfgt_gpr (compare_result, op0, op1);
19458 break;
19460 case TFmode:
19461 cmp = (flag_finite_math_only && !flag_trapping_math)
19462 ? gen_tsttfgt_gpr (compare_result, op0, op1)
19463 : gen_cmptfgt_gpr (compare_result, op0, op1);
19464 break;
19466 default:
19467 gcc_unreachable ();
19469 break;
19471 case LT:
19472 case LE:
19473 switch (op_mode)
19475 case SFmode:
19476 cmp = (flag_finite_math_only && !flag_trapping_math)
19477 ? gen_tstsflt_gpr (compare_result, op0, op1)
19478 : gen_cmpsflt_gpr (compare_result, op0, op1);
19479 break;
19481 case DFmode:
19482 cmp = (flag_finite_math_only && !flag_trapping_math)
19483 ? gen_tstdflt_gpr (compare_result, op0, op1)
19484 : gen_cmpdflt_gpr (compare_result, op0, op1);
19485 break;
19487 case TFmode:
19488 cmp = (flag_finite_math_only && !flag_trapping_math)
19489 ? gen_tsttflt_gpr (compare_result, op0, op1)
19490 : gen_cmptflt_gpr (compare_result, op0, op1);
19491 break;
19493 default:
19494 gcc_unreachable ();
19496 break;
19498 default:
19499 gcc_unreachable ();
19502 /* Synthesize LE and GE from LT/GT || EQ. */
19503 if (code == LE || code == GE)
19505 emit_insn (cmp);
19507 compare_result2 = gen_reg_rtx (CCFPmode);
19509 /* Do the EQ. */
19510 switch (op_mode)
19512 case SFmode:
19513 cmp = (flag_finite_math_only && !flag_trapping_math)
19514 ? gen_tstsfeq_gpr (compare_result2, op0, op1)
19515 : gen_cmpsfeq_gpr (compare_result2, op0, op1);
19516 break;
19518 case DFmode:
19519 cmp = (flag_finite_math_only && !flag_trapping_math)
19520 ? gen_tstdfeq_gpr (compare_result2, op0, op1)
19521 : gen_cmpdfeq_gpr (compare_result2, op0, op1);
19522 break;
19524 case TFmode:
19525 cmp = (flag_finite_math_only && !flag_trapping_math)
19526 ? gen_tsttfeq_gpr (compare_result2, op0, op1)
19527 : gen_cmptfeq_gpr (compare_result2, op0, op1);
19528 break;
19530 default:
19531 gcc_unreachable ();
19534 emit_insn (cmp);
19536 /* OR them together. */
19537 or_result = gen_reg_rtx (CCFPmode);
19538 cmp = gen_e500_cr_ior_compare (or_result, compare_result,
19539 compare_result2);
19540 compare_result = or_result;
19543 code = reverse_p ? NE : EQ;
19545 emit_insn (cmp);
19547 else
19549 /* Generate XLC-compatible TFmode compare as PARALLEL with extra
19550 CLOBBERs to match cmptf_internal2 pattern. */
19551 if (comp_mode == CCFPmode && TARGET_XL_COMPAT
19552 && GET_MODE (op0) == TFmode
19553 && !TARGET_IEEEQUAD
19554 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128)
19555 emit_insn (gen_rtx_PARALLEL (VOIDmode,
19556 gen_rtvec (10,
19557 gen_rtx_SET (compare_result,
19558 gen_rtx_COMPARE (comp_mode, op0, op1)),
19559 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19560 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19561 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19562 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19563 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19564 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19565 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19566 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (DFmode)),
19567 gen_rtx_CLOBBER (VOIDmode, gen_rtx_SCRATCH (Pmode)))));
19568 else if (GET_CODE (op1) == UNSPEC
19569 && XINT (op1, 1) == UNSPEC_SP_TEST)
19571 rtx op1b = XVECEXP (op1, 0, 0);
19572 comp_mode = CCEQmode;
19573 compare_result = gen_reg_rtx (CCEQmode);
19574 if (TARGET_64BIT)
19575 emit_insn (gen_stack_protect_testdi (compare_result, op0, op1b));
19576 else
19577 emit_insn (gen_stack_protect_testsi (compare_result, op0, op1b));
19579 else
19580 emit_insn (gen_rtx_SET (compare_result,
19581 gen_rtx_COMPARE (comp_mode, op0, op1)));
19584 /* Some kinds of FP comparisons need an OR operation;
19585 under flag_finite_math_only we don't bother. */
19586 if (FLOAT_MODE_P (mode)
19587 && !flag_finite_math_only
19588 && !(TARGET_HARD_FLOAT && !TARGET_FPRS)
19589 && (code == LE || code == GE
19590 || code == UNEQ || code == LTGT
19591 || code == UNGT || code == UNLT))
19593 enum rtx_code or1, or2;
19594 rtx or1_rtx, or2_rtx, compare2_rtx;
19595 rtx or_result = gen_reg_rtx (CCEQmode);
19597 switch (code)
19599 case LE: or1 = LT; or2 = EQ; break;
19600 case GE: or1 = GT; or2 = EQ; break;
19601 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
19602 case LTGT: or1 = LT; or2 = GT; break;
19603 case UNGT: or1 = UNORDERED; or2 = GT; break;
19604 case UNLT: or1 = UNORDERED; or2 = LT; break;
19605 default: gcc_unreachable ();
19607 validate_condition_mode (or1, comp_mode);
19608 validate_condition_mode (or2, comp_mode);
19609 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
19610 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
19611 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
19612 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
19613 const_true_rtx);
19614 emit_insn (gen_rtx_SET (or_result, compare2_rtx));
19616 compare_result = or_result;
19617 code = EQ;
19620 validate_condition_mode (code, GET_MODE (compare_result));
19622 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
19626 /* Emit the RTL for an sISEL pattern. */
19628 void
19629 rs6000_emit_sISEL (machine_mode mode ATTRIBUTE_UNUSED, rtx operands[])
19631 rs6000_emit_int_cmove (operands[0], operands[1], const1_rtx, const0_rtx);
19634 /* Emit RTL that sets a register to zero if OP1 and OP2 are equal. SCRATCH
19635 can be used as that dest register. Return the dest register. */
19638 rs6000_emit_eqne (machine_mode mode, rtx op1, rtx op2, rtx scratch)
19640 if (op2 == const0_rtx)
19641 return op1;
19643 if (GET_CODE (scratch) == SCRATCH)
19644 scratch = gen_reg_rtx (mode);
19646 if (logical_operand (op2, mode))
19647 emit_insn (gen_rtx_SET (scratch, gen_rtx_XOR (mode, op1, op2)));
19648 else
19649 emit_insn (gen_rtx_SET (scratch,
19650 gen_rtx_PLUS (mode, op1, negate_rtx (mode, op2))));
19652 return scratch;
19655 void
19656 rs6000_emit_sCOND (machine_mode mode, rtx operands[])
19658 rtx condition_rtx;
19659 machine_mode op_mode;
19660 enum rtx_code cond_code;
19661 rtx result = operands[0];
19663 condition_rtx = rs6000_generate_compare (operands[1], mode);
19664 cond_code = GET_CODE (condition_rtx);
19666 if (FLOAT_MODE_P (mode)
19667 && !TARGET_FPRS && TARGET_HARD_FLOAT)
19669 rtx t;
19671 PUT_MODE (condition_rtx, SImode);
19672 t = XEXP (condition_rtx, 0);
19674 gcc_assert (cond_code == NE || cond_code == EQ);
19676 if (cond_code == NE)
19677 emit_insn (gen_e500_flip_gt_bit (t, t));
19679 emit_insn (gen_move_from_CR_gt_bit (result, t));
19680 return;
19683 if (cond_code == NE
19684 || cond_code == GE || cond_code == LE
19685 || cond_code == GEU || cond_code == LEU
19686 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
19688 rtx not_result = gen_reg_rtx (CCEQmode);
19689 rtx not_op, rev_cond_rtx;
19690 machine_mode cc_mode;
19692 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
19694 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
19695 SImode, XEXP (condition_rtx, 0), const0_rtx);
19696 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
19697 emit_insn (gen_rtx_SET (not_result, not_op));
19698 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
19701 op_mode = GET_MODE (XEXP (operands[1], 0));
19702 if (op_mode == VOIDmode)
19703 op_mode = GET_MODE (XEXP (operands[1], 1));
19705 if (TARGET_POWERPC64 && (op_mode == DImode || FLOAT_MODE_P (mode)))
19707 PUT_MODE (condition_rtx, DImode);
19708 convert_move (result, condition_rtx, 0);
19710 else
19712 PUT_MODE (condition_rtx, SImode);
19713 emit_insn (gen_rtx_SET (result, condition_rtx));
19717 /* Emit a branch of kind CODE to location LOC. */
19719 void
19720 rs6000_emit_cbranch (machine_mode mode, rtx operands[])
19722 rtx condition_rtx, loc_ref;
19724 condition_rtx = rs6000_generate_compare (operands[0], mode);
19725 loc_ref = gen_rtx_LABEL_REF (VOIDmode, operands[3]);
19726 emit_jump_insn (gen_rtx_SET (pc_rtx,
19727 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
19728 loc_ref, pc_rtx)));
19731 /* Return the string to output a conditional branch to LABEL, which is
19732 the operand template of the label, or NULL if the branch is really a
19733 conditional return.
19735 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
19736 condition code register and its mode specifies what kind of
19737 comparison we made.
19739 REVERSED is nonzero if we should reverse the sense of the comparison.
19741 INSN is the insn. */
19743 char *
19744 output_cbranch (rtx op, const char *label, int reversed, rtx_insn *insn)
19746 static char string[64];
19747 enum rtx_code code = GET_CODE (op);
19748 rtx cc_reg = XEXP (op, 0);
19749 machine_mode mode = GET_MODE (cc_reg);
19750 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
19751 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
19752 int really_reversed = reversed ^ need_longbranch;
19753 char *s = string;
19754 const char *ccode;
19755 const char *pred;
19756 rtx note;
19758 validate_condition_mode (code, mode);
19760 /* Work out which way this really branches. We could use
19761 reverse_condition_maybe_unordered here always but this
19762 makes the resulting assembler clearer. */
19763 if (really_reversed)
19765 /* Reversal of FP compares takes care -- an ordered compare
19766 becomes an unordered compare and vice versa. */
19767 if (mode == CCFPmode)
19768 code = reverse_condition_maybe_unordered (code);
19769 else
19770 code = reverse_condition (code);
19773 if ((!TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
19775 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
19776 to the GT bit. */
19777 switch (code)
19779 case EQ:
19780 /* Opposite of GT. */
19781 code = GT;
19782 break;
19784 case NE:
19785 code = UNLE;
19786 break;
19788 default:
19789 gcc_unreachable ();
19793 switch (code)
19795 /* Not all of these are actually distinct opcodes, but
19796 we distinguish them for clarity of the resulting assembler. */
19797 case NE: case LTGT:
19798 ccode = "ne"; break;
19799 case EQ: case UNEQ:
19800 ccode = "eq"; break;
19801 case GE: case GEU:
19802 ccode = "ge"; break;
19803 case GT: case GTU: case UNGT:
19804 ccode = "gt"; break;
19805 case LE: case LEU:
19806 ccode = "le"; break;
19807 case LT: case LTU: case UNLT:
19808 ccode = "lt"; break;
19809 case UNORDERED: ccode = "un"; break;
19810 case ORDERED: ccode = "nu"; break;
19811 case UNGE: ccode = "nl"; break;
19812 case UNLE: ccode = "ng"; break;
19813 default:
19814 gcc_unreachable ();
19817 /* Maybe we have a guess as to how likely the branch is. */
19818 pred = "";
19819 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
19820 if (note != NULL_RTX)
19822 /* PROB is the difference from 50%. */
19823 int prob = XINT (note, 0) - REG_BR_PROB_BASE / 2;
19825 /* Only hint for highly probable/improbable branches on newer
19826 cpus as static prediction overrides processor dynamic
19827 prediction. For older cpus we may as well always hint, but
19828 assume not taken for branches that are very close to 50% as a
19829 mispredicted taken branch is more expensive than a
19830 mispredicted not-taken branch. */
19831 if (rs6000_always_hint
19832 || (abs (prob) > REG_BR_PROB_BASE / 100 * 48
19833 && br_prob_note_reliable_p (note)))
19835 if (abs (prob) > REG_BR_PROB_BASE / 20
19836 && ((prob > 0) ^ need_longbranch))
19837 pred = "+";
19838 else
19839 pred = "-";
19843 if (label == NULL)
19844 s += sprintf (s, "b%slr%s ", ccode, pred);
19845 else
19846 s += sprintf (s, "b%s%s ", ccode, pred);
19848 /* We need to escape any '%' characters in the reg_names string.
19849 Assume they'd only be the first character.... */
19850 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
19851 *s++ = '%';
19852 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
19854 if (label != NULL)
19856 /* If the branch distance was too far, we may have to use an
19857 unconditional branch to go the distance. */
19858 if (need_longbranch)
19859 s += sprintf (s, ",$+8\n\tb %s", label);
19860 else
19861 s += sprintf (s, ",%s", label);
19864 return string;
19867 /* Return the string to flip the GT bit on a CR. */
19868 char *
19869 output_e500_flip_gt_bit (rtx dst, rtx src)
19871 static char string[64];
19872 int a, b;
19874 gcc_assert (GET_CODE (dst) == REG && CR_REGNO_P (REGNO (dst))
19875 && GET_CODE (src) == REG && CR_REGNO_P (REGNO (src)));
19877 /* GT bit. */
19878 a = 4 * (REGNO (dst) - CR0_REGNO) + 1;
19879 b = 4 * (REGNO (src) - CR0_REGNO) + 1;
19881 sprintf (string, "crnot %d,%d", a, b);
19882 return string;
19885 /* Return insn for VSX or Altivec comparisons. */
19887 static rtx
19888 rs6000_emit_vector_compare_inner (enum rtx_code code, rtx op0, rtx op1)
19890 rtx mask;
19891 machine_mode mode = GET_MODE (op0);
19893 switch (code)
19895 default:
19896 break;
19898 case GE:
19899 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
19900 return NULL_RTX;
19902 case EQ:
19903 case GT:
19904 case GTU:
19905 case ORDERED:
19906 case UNORDERED:
19907 case UNEQ:
19908 case LTGT:
19909 mask = gen_reg_rtx (mode);
19910 emit_insn (gen_rtx_SET (mask, gen_rtx_fmt_ee (code, mode, op0, op1)));
19911 return mask;
19914 return NULL_RTX;
19917 /* Emit vector compare for operands OP0 and OP1 using code RCODE.
19918 DMODE is expected destination mode. This is a recursive function. */
19920 static rtx
19921 rs6000_emit_vector_compare (enum rtx_code rcode,
19922 rtx op0, rtx op1,
19923 machine_mode dmode)
19925 rtx mask;
19926 bool swap_operands = false;
19927 bool try_again = false;
19929 gcc_assert (VECTOR_UNIT_ALTIVEC_OR_VSX_P (dmode));
19930 gcc_assert (GET_MODE (op0) == GET_MODE (op1));
19932 /* See if the comparison works as is. */
19933 mask = rs6000_emit_vector_compare_inner (rcode, op0, op1);
19934 if (mask)
19935 return mask;
19937 switch (rcode)
19939 case LT:
19940 rcode = GT;
19941 swap_operands = true;
19942 try_again = true;
19943 break;
19944 case LTU:
19945 rcode = GTU;
19946 swap_operands = true;
19947 try_again = true;
19948 break;
19949 case NE:
19950 case UNLE:
19951 case UNLT:
19952 case UNGE:
19953 case UNGT:
19954 /* Invert condition and try again.
19955 e.g., A != B becomes ~(A==B). */
19957 enum rtx_code rev_code;
19958 enum insn_code nor_code;
19959 rtx mask2;
19961 rev_code = reverse_condition_maybe_unordered (rcode);
19962 if (rev_code == UNKNOWN)
19963 return NULL_RTX;
19965 nor_code = optab_handler (one_cmpl_optab, dmode);
19966 if (nor_code == CODE_FOR_nothing)
19967 return NULL_RTX;
19969 mask2 = rs6000_emit_vector_compare (rev_code, op0, op1, dmode);
19970 if (!mask2)
19971 return NULL_RTX;
19973 mask = gen_reg_rtx (dmode);
19974 emit_insn (GEN_FCN (nor_code) (mask, mask2));
19975 return mask;
19977 break;
19978 case GE:
19979 case GEU:
19980 case LE:
19981 case LEU:
19982 /* Try GT/GTU/LT/LTU OR EQ */
19984 rtx c_rtx, eq_rtx;
19985 enum insn_code ior_code;
19986 enum rtx_code new_code;
19988 switch (rcode)
19990 case GE:
19991 new_code = GT;
19992 break;
19994 case GEU:
19995 new_code = GTU;
19996 break;
19998 case LE:
19999 new_code = LT;
20000 break;
20002 case LEU:
20003 new_code = LTU;
20004 break;
20006 default:
20007 gcc_unreachable ();
20010 ior_code = optab_handler (ior_optab, dmode);
20011 if (ior_code == CODE_FOR_nothing)
20012 return NULL_RTX;
20014 c_rtx = rs6000_emit_vector_compare (new_code, op0, op1, dmode);
20015 if (!c_rtx)
20016 return NULL_RTX;
20018 eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1, dmode);
20019 if (!eq_rtx)
20020 return NULL_RTX;
20022 mask = gen_reg_rtx (dmode);
20023 emit_insn (GEN_FCN (ior_code) (mask, c_rtx, eq_rtx));
20024 return mask;
20026 break;
20027 default:
20028 return NULL_RTX;
20031 if (try_again)
20033 if (swap_operands)
20034 std::swap (op0, op1);
20036 mask = rs6000_emit_vector_compare_inner (rcode, op0, op1);
20037 if (mask)
20038 return mask;
20041 /* You only get two chances. */
20042 return NULL_RTX;
20045 /* Emit vector conditional expression. DEST is destination. OP_TRUE and
20046 OP_FALSE are two VEC_COND_EXPR operands. CC_OP0 and CC_OP1 are the two
20047 operands for the relation operation COND. */
20050 rs6000_emit_vector_cond_expr (rtx dest, rtx op_true, rtx op_false,
20051 rtx cond, rtx cc_op0, rtx cc_op1)
20053 machine_mode dest_mode = GET_MODE (dest);
20054 machine_mode mask_mode = GET_MODE (cc_op0);
20055 enum rtx_code rcode = GET_CODE (cond);
20056 machine_mode cc_mode = CCmode;
20057 rtx mask;
20058 rtx cond2;
20059 rtx tmp;
20060 bool invert_move = false;
20062 if (VECTOR_UNIT_NONE_P (dest_mode))
20063 return 0;
20065 gcc_assert (GET_MODE_SIZE (dest_mode) == GET_MODE_SIZE (mask_mode)
20066 && GET_MODE_NUNITS (dest_mode) == GET_MODE_NUNITS (mask_mode));
20068 switch (rcode)
20070 /* Swap operands if we can, and fall back to doing the operation as
20071 specified, and doing a NOR to invert the test. */
20072 case NE:
20073 case UNLE:
20074 case UNLT:
20075 case UNGE:
20076 case UNGT:
20077 /* Invert condition and try again.
20078 e.g., A = (B != C) ? D : E becomes A = (B == C) ? E : D. */
20079 invert_move = true;
20080 rcode = reverse_condition_maybe_unordered (rcode);
20081 if (rcode == UNKNOWN)
20082 return 0;
20083 break;
20085 /* Mark unsigned tests with CCUNSmode. */
20086 case GTU:
20087 case GEU:
20088 case LTU:
20089 case LEU:
20090 cc_mode = CCUNSmode;
20091 break;
20093 default:
20094 break;
20097 /* Get the vector mask for the given relational operations. */
20098 mask = rs6000_emit_vector_compare (rcode, cc_op0, cc_op1, mask_mode);
20100 if (!mask)
20101 return 0;
20103 if (invert_move)
20105 tmp = op_true;
20106 op_true = op_false;
20107 op_false = tmp;
20110 cond2 = gen_rtx_fmt_ee (NE, cc_mode, gen_lowpart (dest_mode, mask),
20111 CONST0_RTX (dest_mode));
20112 emit_insn (gen_rtx_SET (dest,
20113 gen_rtx_IF_THEN_ELSE (dest_mode,
20114 cond2,
20115 op_true,
20116 op_false)));
20117 return 1;
20120 /* Emit a conditional move: move TRUE_COND to DEST if OP of the
20121 operands of the last comparison is nonzero/true, FALSE_COND if it
20122 is zero/false. Return 0 if the hardware has no such operation. */
20125 rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
20127 enum rtx_code code = GET_CODE (op);
20128 rtx op0 = XEXP (op, 0);
20129 rtx op1 = XEXP (op, 1);
20130 REAL_VALUE_TYPE c1;
20131 machine_mode compare_mode = GET_MODE (op0);
20132 machine_mode result_mode = GET_MODE (dest);
20133 rtx temp;
20134 bool is_against_zero;
20136 /* These modes should always match. */
20137 if (GET_MODE (op1) != compare_mode
20138 /* In the isel case however, we can use a compare immediate, so
20139 op1 may be a small constant. */
20140 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
20141 return 0;
20142 if (GET_MODE (true_cond) != result_mode)
20143 return 0;
20144 if (GET_MODE (false_cond) != result_mode)
20145 return 0;
20147 /* Don't allow using floating point comparisons for integer results for
20148 now. */
20149 if (FLOAT_MODE_P (compare_mode) && !FLOAT_MODE_P (result_mode))
20150 return 0;
20152 /* First, work out if the hardware can do this at all, or
20153 if it's too slow.... */
20154 if (!FLOAT_MODE_P (compare_mode))
20156 if (TARGET_ISEL)
20157 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
20158 return 0;
20160 else if (TARGET_HARD_FLOAT && !TARGET_FPRS
20161 && SCALAR_FLOAT_MODE_P (compare_mode))
20162 return 0;
20164 is_against_zero = op1 == CONST0_RTX (compare_mode);
20166 /* A floating-point subtract might overflow, underflow, or produce
20167 an inexact result, thus changing the floating-point flags, so it
20168 can't be generated if we care about that. It's safe if one side
20169 of the construct is zero, since then no subtract will be
20170 generated. */
20171 if (SCALAR_FLOAT_MODE_P (compare_mode)
20172 && flag_trapping_math && ! is_against_zero)
20173 return 0;
20175 /* Eliminate half of the comparisons by switching operands, this
20176 makes the remaining code simpler. */
20177 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
20178 || code == LTGT || code == LT || code == UNLE)
20180 code = reverse_condition_maybe_unordered (code);
20181 temp = true_cond;
20182 true_cond = false_cond;
20183 false_cond = temp;
20186 /* UNEQ and LTGT take four instructions for a comparison with zero,
20187 it'll probably be faster to use a branch here too. */
20188 if (code == UNEQ && HONOR_NANS (compare_mode))
20189 return 0;
20191 if (GET_CODE (op1) == CONST_DOUBLE)
20192 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
20194 /* We're going to try to implement comparisons by performing
20195 a subtract, then comparing against zero. Unfortunately,
20196 Inf - Inf is NaN which is not zero, and so if we don't
20197 know that the operand is finite and the comparison
20198 would treat EQ different to UNORDERED, we can't do it. */
20199 if (HONOR_INFINITIES (compare_mode)
20200 && code != GT && code != UNGE
20201 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
20202 /* Constructs of the form (a OP b ? a : b) are safe. */
20203 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
20204 || (! rtx_equal_p (op0, true_cond)
20205 && ! rtx_equal_p (op1, true_cond))))
20206 return 0;
20208 /* At this point we know we can use fsel. */
20210 /* Reduce the comparison to a comparison against zero. */
20211 if (! is_against_zero)
20213 temp = gen_reg_rtx (compare_mode);
20214 emit_insn (gen_rtx_SET (temp, gen_rtx_MINUS (compare_mode, op0, op1)));
20215 op0 = temp;
20216 op1 = CONST0_RTX (compare_mode);
20219 /* If we don't care about NaNs we can reduce some of the comparisons
20220 down to faster ones. */
20221 if (! HONOR_NANS (compare_mode))
20222 switch (code)
20224 case GT:
20225 code = LE;
20226 temp = true_cond;
20227 true_cond = false_cond;
20228 false_cond = temp;
20229 break;
20230 case UNGE:
20231 code = GE;
20232 break;
20233 case UNEQ:
20234 code = EQ;
20235 break;
20236 default:
20237 break;
20240 /* Now, reduce everything down to a GE. */
20241 switch (code)
20243 case GE:
20244 break;
20246 case LE:
20247 temp = gen_reg_rtx (compare_mode);
20248 emit_insn (gen_rtx_SET (temp, gen_rtx_NEG (compare_mode, op0)));
20249 op0 = temp;
20250 break;
20252 case ORDERED:
20253 temp = gen_reg_rtx (compare_mode);
20254 emit_insn (gen_rtx_SET (temp, gen_rtx_ABS (compare_mode, op0)));
20255 op0 = temp;
20256 break;
20258 case EQ:
20259 temp = gen_reg_rtx (compare_mode);
20260 emit_insn (gen_rtx_SET (temp,
20261 gen_rtx_NEG (compare_mode,
20262 gen_rtx_ABS (compare_mode, op0))));
20263 op0 = temp;
20264 break;
20266 case UNGE:
20267 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
20268 temp = gen_reg_rtx (result_mode);
20269 emit_insn (gen_rtx_SET (temp,
20270 gen_rtx_IF_THEN_ELSE (result_mode,
20271 gen_rtx_GE (VOIDmode,
20272 op0, op1),
20273 true_cond, false_cond)));
20274 false_cond = true_cond;
20275 true_cond = temp;
20277 temp = gen_reg_rtx (compare_mode);
20278 emit_insn (gen_rtx_SET (temp, gen_rtx_NEG (compare_mode, op0)));
20279 op0 = temp;
20280 break;
20282 case GT:
20283 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
20284 temp = gen_reg_rtx (result_mode);
20285 emit_insn (gen_rtx_SET (temp,
20286 gen_rtx_IF_THEN_ELSE (result_mode,
20287 gen_rtx_GE (VOIDmode,
20288 op0, op1),
20289 true_cond, false_cond)));
20290 true_cond = false_cond;
20291 false_cond = temp;
20293 temp = gen_reg_rtx (compare_mode);
20294 emit_insn (gen_rtx_SET (temp, gen_rtx_NEG (compare_mode, op0)));
20295 op0 = temp;
20296 break;
20298 default:
20299 gcc_unreachable ();
20302 emit_insn (gen_rtx_SET (dest,
20303 gen_rtx_IF_THEN_ELSE (result_mode,
20304 gen_rtx_GE (VOIDmode,
20305 op0, op1),
20306 true_cond, false_cond)));
20307 return 1;
20310 /* Same as above, but for ints (isel). */
20312 static int
20313 rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
20315 rtx condition_rtx, cr;
20316 machine_mode mode = GET_MODE (dest);
20317 enum rtx_code cond_code;
20318 rtx (*isel_func) (rtx, rtx, rtx, rtx, rtx);
20319 bool signedp;
20321 if (mode != SImode && (!TARGET_POWERPC64 || mode != DImode))
20322 return 0;
20324 /* We still have to do the compare, because isel doesn't do a
20325 compare, it just looks at the CRx bits set by a previous compare
20326 instruction. */
20327 condition_rtx = rs6000_generate_compare (op, mode);
20328 cond_code = GET_CODE (condition_rtx);
20329 cr = XEXP (condition_rtx, 0);
20330 signedp = GET_MODE (cr) == CCmode;
20332 isel_func = (mode == SImode
20333 ? (signedp ? gen_isel_signed_si : gen_isel_unsigned_si)
20334 : (signedp ? gen_isel_signed_di : gen_isel_unsigned_di));
20336 switch (cond_code)
20338 case LT: case GT: case LTU: case GTU: case EQ:
20339 /* isel handles these directly. */
20340 break;
20342 default:
20343 /* We need to swap the sense of the comparison. */
20345 std::swap (false_cond, true_cond);
20346 PUT_CODE (condition_rtx, reverse_condition (cond_code));
20348 break;
20351 false_cond = force_reg (mode, false_cond);
20352 if (true_cond != const0_rtx)
20353 true_cond = force_reg (mode, true_cond);
20355 emit_insn (isel_func (dest, condition_rtx, true_cond, false_cond, cr));
20357 return 1;
20360 const char *
20361 output_isel (rtx *operands)
20363 enum rtx_code code;
20365 code = GET_CODE (operands[1]);
20367 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
20369 gcc_assert (GET_CODE (operands[2]) == REG
20370 && GET_CODE (operands[3]) == REG);
20371 PUT_CODE (operands[1], reverse_condition (code));
20372 return "isel %0,%3,%2,%j1";
20375 return "isel %0,%2,%3,%j1";
20378 void
20379 rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
20381 machine_mode mode = GET_MODE (op0);
20382 enum rtx_code c;
20383 rtx target;
20385 /* VSX/altivec have direct min/max insns. */
20386 if ((code == SMAX || code == SMIN)
20387 && (VECTOR_UNIT_ALTIVEC_OR_VSX_P (mode)
20388 || (mode == SFmode && VECTOR_UNIT_VSX_P (DFmode))))
20390 emit_insn (gen_rtx_SET (dest, gen_rtx_fmt_ee (code, mode, op0, op1)));
20391 return;
20394 if (code == SMAX || code == SMIN)
20395 c = GE;
20396 else
20397 c = GEU;
20399 if (code == SMAX || code == UMAX)
20400 target = emit_conditional_move (dest, c, op0, op1, mode,
20401 op0, op1, mode, 0);
20402 else
20403 target = emit_conditional_move (dest, c, op0, op1, mode,
20404 op1, op0, mode, 0);
20405 gcc_assert (target);
20406 if (target != dest)
20407 emit_move_insn (dest, target);
20410 /* A subroutine of the atomic operation splitters. Jump to LABEL if
20411 COND is true. Mark the jump as unlikely to be taken. */
20413 static void
20414 emit_unlikely_jump (rtx cond, rtx label)
20416 int very_unlikely = REG_BR_PROB_BASE / 100 - 1;
20417 rtx x;
20419 x = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, label, pc_rtx);
20420 x = emit_jump_insn (gen_rtx_SET (pc_rtx, x));
20421 add_int_reg_note (x, REG_BR_PROB, very_unlikely);
20424 /* A subroutine of the atomic operation splitters. Emit a load-locked
20425 instruction in MODE. For QI/HImode, possibly use a pattern than includes
20426 the zero_extend operation. */
20428 static void
20429 emit_load_locked (machine_mode mode, rtx reg, rtx mem)
20431 rtx (*fn) (rtx, rtx) = NULL;
20433 switch (mode)
20435 case QImode:
20436 fn = gen_load_lockedqi;
20437 break;
20438 case HImode:
20439 fn = gen_load_lockedhi;
20440 break;
20441 case SImode:
20442 if (GET_MODE (mem) == QImode)
20443 fn = gen_load_lockedqi_si;
20444 else if (GET_MODE (mem) == HImode)
20445 fn = gen_load_lockedhi_si;
20446 else
20447 fn = gen_load_lockedsi;
20448 break;
20449 case DImode:
20450 fn = gen_load_lockeddi;
20451 break;
20452 case TImode:
20453 fn = gen_load_lockedti;
20454 break;
20455 default:
20456 gcc_unreachable ();
20458 emit_insn (fn (reg, mem));
20461 /* A subroutine of the atomic operation splitters. Emit a store-conditional
20462 instruction in MODE. */
20464 static void
20465 emit_store_conditional (machine_mode mode, rtx res, rtx mem, rtx val)
20467 rtx (*fn) (rtx, rtx, rtx) = NULL;
20469 switch (mode)
20471 case QImode:
20472 fn = gen_store_conditionalqi;
20473 break;
20474 case HImode:
20475 fn = gen_store_conditionalhi;
20476 break;
20477 case SImode:
20478 fn = gen_store_conditionalsi;
20479 break;
20480 case DImode:
20481 fn = gen_store_conditionaldi;
20482 break;
20483 case TImode:
20484 fn = gen_store_conditionalti;
20485 break;
20486 default:
20487 gcc_unreachable ();
20490 /* Emit sync before stwcx. to address PPC405 Erratum. */
20491 if (PPC405_ERRATUM77)
20492 emit_insn (gen_hwsync ());
20494 emit_insn (fn (res, mem, val));
20497 /* Expand barriers before and after a load_locked/store_cond sequence. */
20499 static rtx
20500 rs6000_pre_atomic_barrier (rtx mem, enum memmodel model)
20502 rtx addr = XEXP (mem, 0);
20503 int strict_p = (reload_in_progress || reload_completed);
20505 if (!legitimate_indirect_address_p (addr, strict_p)
20506 && !legitimate_indexed_address_p (addr, strict_p))
20508 addr = force_reg (Pmode, addr);
20509 mem = replace_equiv_address_nv (mem, addr);
20512 switch (model)
20514 case MEMMODEL_RELAXED:
20515 case MEMMODEL_CONSUME:
20516 case MEMMODEL_ACQUIRE:
20517 case MEMMODEL_SYNC_ACQUIRE:
20518 break;
20519 case MEMMODEL_RELEASE:
20520 case MEMMODEL_SYNC_RELEASE:
20521 case MEMMODEL_ACQ_REL:
20522 emit_insn (gen_lwsync ());
20523 break;
20524 case MEMMODEL_SEQ_CST:
20525 case MEMMODEL_SYNC_SEQ_CST:
20526 emit_insn (gen_hwsync ());
20527 break;
20528 default:
20529 gcc_unreachable ();
20531 return mem;
20534 static void
20535 rs6000_post_atomic_barrier (enum memmodel model)
20537 switch (model)
20539 case MEMMODEL_RELAXED:
20540 case MEMMODEL_CONSUME:
20541 case MEMMODEL_RELEASE:
20542 case MEMMODEL_SYNC_RELEASE:
20543 break;
20544 case MEMMODEL_ACQUIRE:
20545 case MEMMODEL_SYNC_ACQUIRE:
20546 case MEMMODEL_ACQ_REL:
20547 case MEMMODEL_SEQ_CST:
20548 case MEMMODEL_SYNC_SEQ_CST:
20549 emit_insn (gen_isync ());
20550 break;
20551 default:
20552 gcc_unreachable ();
20556 /* A subroutine of the various atomic expanders. For sub-word operations,
20557 we must adjust things to operate on SImode. Given the original MEM,
20558 return a new aligned memory. Also build and return the quantities by
20559 which to shift and mask. */
20561 static rtx
20562 rs6000_adjust_atomic_subword (rtx orig_mem, rtx *pshift, rtx *pmask)
20564 rtx addr, align, shift, mask, mem;
20565 HOST_WIDE_INT shift_mask;
20566 machine_mode mode = GET_MODE (orig_mem);
20568 /* For smaller modes, we have to implement this via SImode. */
20569 shift_mask = (mode == QImode ? 0x18 : 0x10);
20571 addr = XEXP (orig_mem, 0);
20572 addr = force_reg (GET_MODE (addr), addr);
20574 /* Aligned memory containing subword. Generate a new memory. We
20575 do not want any of the existing MEM_ATTR data, as we're now
20576 accessing memory outside the original object. */
20577 align = expand_simple_binop (Pmode, AND, addr, GEN_INT (-4),
20578 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20579 mem = gen_rtx_MEM (SImode, align);
20580 MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (orig_mem);
20581 if (MEM_ALIAS_SET (orig_mem) == ALIAS_SET_MEMORY_BARRIER)
20582 set_mem_alias_set (mem, ALIAS_SET_MEMORY_BARRIER);
20584 /* Shift amount for subword relative to aligned word. */
20585 shift = gen_reg_rtx (SImode);
20586 addr = gen_lowpart (SImode, addr);
20587 rtx tmp = gen_reg_rtx (SImode);
20588 emit_insn (gen_ashlsi3 (tmp, addr, GEN_INT (3)));
20589 emit_insn (gen_andsi3 (shift, tmp, GEN_INT (shift_mask)));
20590 if (BYTES_BIG_ENDIAN)
20591 shift = expand_simple_binop (SImode, XOR, shift, GEN_INT (shift_mask),
20592 shift, 1, OPTAB_LIB_WIDEN);
20593 *pshift = shift;
20595 /* Mask for insertion. */
20596 mask = expand_simple_binop (SImode, ASHIFT, GEN_INT (GET_MODE_MASK (mode)),
20597 shift, NULL_RTX, 1, OPTAB_LIB_WIDEN);
20598 *pmask = mask;
20600 return mem;
20603 /* A subroutine of the various atomic expanders. For sub-word operands,
20604 combine OLDVAL and NEWVAL via MASK. Returns a new pseduo. */
20606 static rtx
20607 rs6000_mask_atomic_subword (rtx oldval, rtx newval, rtx mask)
20609 rtx x;
20611 x = gen_reg_rtx (SImode);
20612 emit_insn (gen_rtx_SET (x, gen_rtx_AND (SImode,
20613 gen_rtx_NOT (SImode, mask),
20614 oldval)));
20616 x = expand_simple_binop (SImode, IOR, newval, x, x, 1, OPTAB_LIB_WIDEN);
20618 return x;
20621 /* A subroutine of the various atomic expanders. For sub-word operands,
20622 extract WIDE to NARROW via SHIFT. */
20624 static void
20625 rs6000_finish_atomic_subword (rtx narrow, rtx wide, rtx shift)
20627 wide = expand_simple_binop (SImode, LSHIFTRT, wide, shift,
20628 wide, 1, OPTAB_LIB_WIDEN);
20629 emit_move_insn (narrow, gen_lowpart (GET_MODE (narrow), wide));
20632 /* Expand an atomic compare and swap operation. */
20634 void
20635 rs6000_expand_atomic_compare_and_swap (rtx operands[])
20637 rtx boolval, retval, mem, oldval, newval, cond;
20638 rtx label1, label2, x, mask, shift;
20639 machine_mode mode, orig_mode;
20640 enum memmodel mod_s, mod_f;
20641 bool is_weak;
20643 boolval = operands[0];
20644 retval = operands[1];
20645 mem = operands[2];
20646 oldval = operands[3];
20647 newval = operands[4];
20648 is_weak = (INTVAL (operands[5]) != 0);
20649 mod_s = memmodel_from_int (INTVAL (operands[6]));
20650 mod_f = memmodel_from_int (INTVAL (operands[7]));
20651 orig_mode = mode = GET_MODE (mem);
20653 mask = shift = NULL_RTX;
20654 if (mode == QImode || mode == HImode)
20656 /* Before power8, we didn't have access to lbarx/lharx, so generate a
20657 lwarx and shift/mask operations. With power8, we need to do the
20658 comparison in SImode, but the store is still done in QI/HImode. */
20659 oldval = convert_modes (SImode, mode, oldval, 1);
20661 if (!TARGET_SYNC_HI_QI)
20663 mem = rs6000_adjust_atomic_subword (mem, &shift, &mask);
20665 /* Shift and mask OLDVAL into position with the word. */
20666 oldval = expand_simple_binop (SImode, ASHIFT, oldval, shift,
20667 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20669 /* Shift and mask NEWVAL into position within the word. */
20670 newval = convert_modes (SImode, mode, newval, 1);
20671 newval = expand_simple_binop (SImode, ASHIFT, newval, shift,
20672 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20675 /* Prepare to adjust the return value. */
20676 retval = gen_reg_rtx (SImode);
20677 mode = SImode;
20679 else if (reg_overlap_mentioned_p (retval, oldval))
20680 oldval = copy_to_reg (oldval);
20682 mem = rs6000_pre_atomic_barrier (mem, mod_s);
20684 label1 = NULL_RTX;
20685 if (!is_weak)
20687 label1 = gen_rtx_LABEL_REF (VOIDmode, gen_label_rtx ());
20688 emit_label (XEXP (label1, 0));
20690 label2 = gen_rtx_LABEL_REF (VOIDmode, gen_label_rtx ());
20692 emit_load_locked (mode, retval, mem);
20694 x = retval;
20695 if (mask)
20697 x = expand_simple_binop (SImode, AND, retval, mask,
20698 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20701 cond = gen_reg_rtx (CCmode);
20702 /* If we have TImode, synthesize a comparison. */
20703 if (mode != TImode)
20704 x = gen_rtx_COMPARE (CCmode, x, oldval);
20705 else
20707 rtx xor1_result = gen_reg_rtx (DImode);
20708 rtx xor2_result = gen_reg_rtx (DImode);
20709 rtx or_result = gen_reg_rtx (DImode);
20710 rtx new_word0 = simplify_gen_subreg (DImode, x, TImode, 0);
20711 rtx new_word1 = simplify_gen_subreg (DImode, x, TImode, 8);
20712 rtx old_word0 = simplify_gen_subreg (DImode, oldval, TImode, 0);
20713 rtx old_word1 = simplify_gen_subreg (DImode, oldval, TImode, 8);
20715 emit_insn (gen_xordi3 (xor1_result, new_word0, old_word0));
20716 emit_insn (gen_xordi3 (xor2_result, new_word1, old_word1));
20717 emit_insn (gen_iordi3 (or_result, xor1_result, xor2_result));
20718 x = gen_rtx_COMPARE (CCmode, or_result, const0_rtx);
20721 emit_insn (gen_rtx_SET (cond, x));
20723 x = gen_rtx_NE (VOIDmode, cond, const0_rtx);
20724 emit_unlikely_jump (x, label2);
20726 x = newval;
20727 if (mask)
20728 x = rs6000_mask_atomic_subword (retval, newval, mask);
20730 emit_store_conditional (orig_mode, cond, mem, x);
20732 if (!is_weak)
20734 x = gen_rtx_NE (VOIDmode, cond, const0_rtx);
20735 emit_unlikely_jump (x, label1);
20738 if (!is_mm_relaxed (mod_f))
20739 emit_label (XEXP (label2, 0));
20741 rs6000_post_atomic_barrier (mod_s);
20743 if (is_mm_relaxed (mod_f))
20744 emit_label (XEXP (label2, 0));
20746 if (shift)
20747 rs6000_finish_atomic_subword (operands[1], retval, shift);
20748 else if (mode != GET_MODE (operands[1]))
20749 convert_move (operands[1], retval, 1);
20751 /* In all cases, CR0 contains EQ on success, and NE on failure. */
20752 x = gen_rtx_EQ (SImode, cond, const0_rtx);
20753 emit_insn (gen_rtx_SET (boolval, x));
20756 /* Expand an atomic exchange operation. */
20758 void
20759 rs6000_expand_atomic_exchange (rtx operands[])
20761 rtx retval, mem, val, cond;
20762 machine_mode mode;
20763 enum memmodel model;
20764 rtx label, x, mask, shift;
20766 retval = operands[0];
20767 mem = operands[1];
20768 val = operands[2];
20769 model = (enum memmodel) INTVAL (operands[3]);
20770 mode = GET_MODE (mem);
20772 mask = shift = NULL_RTX;
20773 if (!TARGET_SYNC_HI_QI && (mode == QImode || mode == HImode))
20775 mem = rs6000_adjust_atomic_subword (mem, &shift, &mask);
20777 /* Shift and mask VAL into position with the word. */
20778 val = convert_modes (SImode, mode, val, 1);
20779 val = expand_simple_binop (SImode, ASHIFT, val, shift,
20780 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20782 /* Prepare to adjust the return value. */
20783 retval = gen_reg_rtx (SImode);
20784 mode = SImode;
20787 mem = rs6000_pre_atomic_barrier (mem, model);
20789 label = gen_rtx_LABEL_REF (VOIDmode, gen_label_rtx ());
20790 emit_label (XEXP (label, 0));
20792 emit_load_locked (mode, retval, mem);
20794 x = val;
20795 if (mask)
20796 x = rs6000_mask_atomic_subword (retval, val, mask);
20798 cond = gen_reg_rtx (CCmode);
20799 emit_store_conditional (mode, cond, mem, x);
20801 x = gen_rtx_NE (VOIDmode, cond, const0_rtx);
20802 emit_unlikely_jump (x, label);
20804 rs6000_post_atomic_barrier (model);
20806 if (shift)
20807 rs6000_finish_atomic_subword (operands[0], retval, shift);
20810 /* Expand an atomic fetch-and-operate pattern. CODE is the binary operation
20811 to perform. MEM is the memory on which to operate. VAL is the second
20812 operand of the binary operator. BEFORE and AFTER are optional locations to
20813 return the value of MEM either before of after the operation. MODEL_RTX
20814 is a CONST_INT containing the memory model to use. */
20816 void
20817 rs6000_expand_atomic_op (enum rtx_code code, rtx mem, rtx val,
20818 rtx orig_before, rtx orig_after, rtx model_rtx)
20820 enum memmodel model = (enum memmodel) INTVAL (model_rtx);
20821 machine_mode mode = GET_MODE (mem);
20822 machine_mode store_mode = mode;
20823 rtx label, x, cond, mask, shift;
20824 rtx before = orig_before, after = orig_after;
20826 mask = shift = NULL_RTX;
20827 /* On power8, we want to use SImode for the operation. On previous systems,
20828 use the operation in a subword and shift/mask to get the proper byte or
20829 halfword. */
20830 if (mode == QImode || mode == HImode)
20832 if (TARGET_SYNC_HI_QI)
20834 val = convert_modes (SImode, mode, val, 1);
20836 /* Prepare to adjust the return value. */
20837 before = gen_reg_rtx (SImode);
20838 if (after)
20839 after = gen_reg_rtx (SImode);
20840 mode = SImode;
20842 else
20844 mem = rs6000_adjust_atomic_subword (mem, &shift, &mask);
20846 /* Shift and mask VAL into position with the word. */
20847 val = convert_modes (SImode, mode, val, 1);
20848 val = expand_simple_binop (SImode, ASHIFT, val, shift,
20849 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20851 switch (code)
20853 case IOR:
20854 case XOR:
20855 /* We've already zero-extended VAL. That is sufficient to
20856 make certain that it does not affect other bits. */
20857 mask = NULL;
20858 break;
20860 case AND:
20861 /* If we make certain that all of the other bits in VAL are
20862 set, that will be sufficient to not affect other bits. */
20863 x = gen_rtx_NOT (SImode, mask);
20864 x = gen_rtx_IOR (SImode, x, val);
20865 emit_insn (gen_rtx_SET (val, x));
20866 mask = NULL;
20867 break;
20869 case NOT:
20870 case PLUS:
20871 case MINUS:
20872 /* These will all affect bits outside the field and need
20873 adjustment via MASK within the loop. */
20874 break;
20876 default:
20877 gcc_unreachable ();
20880 /* Prepare to adjust the return value. */
20881 before = gen_reg_rtx (SImode);
20882 if (after)
20883 after = gen_reg_rtx (SImode);
20884 store_mode = mode = SImode;
20888 mem = rs6000_pre_atomic_barrier (mem, model);
20890 label = gen_label_rtx ();
20891 emit_label (label);
20892 label = gen_rtx_LABEL_REF (VOIDmode, label);
20894 if (before == NULL_RTX)
20895 before = gen_reg_rtx (mode);
20897 emit_load_locked (mode, before, mem);
20899 if (code == NOT)
20901 x = expand_simple_binop (mode, AND, before, val,
20902 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20903 after = expand_simple_unop (mode, NOT, x, after, 1);
20905 else
20907 after = expand_simple_binop (mode, code, before, val,
20908 after, 1, OPTAB_LIB_WIDEN);
20911 x = after;
20912 if (mask)
20914 x = expand_simple_binop (SImode, AND, after, mask,
20915 NULL_RTX, 1, OPTAB_LIB_WIDEN);
20916 x = rs6000_mask_atomic_subword (before, x, mask);
20918 else if (store_mode != mode)
20919 x = convert_modes (store_mode, mode, x, 1);
20921 cond = gen_reg_rtx (CCmode);
20922 emit_store_conditional (store_mode, cond, mem, x);
20924 x = gen_rtx_NE (VOIDmode, cond, const0_rtx);
20925 emit_unlikely_jump (x, label);
20927 rs6000_post_atomic_barrier (model);
20929 if (shift)
20931 /* QImode/HImode on machines without lbarx/lharx where we do a lwarx and
20932 then do the calcuations in a SImode register. */
20933 if (orig_before)
20934 rs6000_finish_atomic_subword (orig_before, before, shift);
20935 if (orig_after)
20936 rs6000_finish_atomic_subword (orig_after, after, shift);
20938 else if (store_mode != mode)
20940 /* QImode/HImode on machines with lbarx/lharx where we do the native
20941 operation and then do the calcuations in a SImode register. */
20942 if (orig_before)
20943 convert_move (orig_before, before, 1);
20944 if (orig_after)
20945 convert_move (orig_after, after, 1);
20947 else if (orig_after && after != orig_after)
20948 emit_move_insn (orig_after, after);
20951 /* Emit instructions to move SRC to DST. Called by splitters for
20952 multi-register moves. It will emit at most one instruction for
20953 each register that is accessed; that is, it won't emit li/lis pairs
20954 (or equivalent for 64-bit code). One of SRC or DST must be a hard
20955 register. */
20957 void
20958 rs6000_split_multireg_move (rtx dst, rtx src)
20960 /* The register number of the first register being moved. */
20961 int reg;
20962 /* The mode that is to be moved. */
20963 machine_mode mode;
20964 /* The mode that the move is being done in, and its size. */
20965 machine_mode reg_mode;
20966 int reg_mode_size;
20967 /* The number of registers that will be moved. */
20968 int nregs;
20970 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
20971 mode = GET_MODE (dst);
20972 nregs = hard_regno_nregs[reg][mode];
20973 if (FP_REGNO_P (reg))
20974 reg_mode = DECIMAL_FLOAT_MODE_P (mode) ? DDmode :
20975 ((TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT) ? DFmode : SFmode);
20976 else if (ALTIVEC_REGNO_P (reg))
20977 reg_mode = V16QImode;
20978 else if (TARGET_E500_DOUBLE && mode == TFmode)
20979 reg_mode = DFmode;
20980 else
20981 reg_mode = word_mode;
20982 reg_mode_size = GET_MODE_SIZE (reg_mode);
20984 gcc_assert (reg_mode_size * nregs == GET_MODE_SIZE (mode));
20986 /* TDmode residing in FP registers is special, since the ISA requires that
20987 the lower-numbered word of a register pair is always the most significant
20988 word, even in little-endian mode. This does not match the usual subreg
20989 semantics, so we cannnot use simplify_gen_subreg in those cases. Access
20990 the appropriate constituent registers "by hand" in little-endian mode.
20992 Note we do not need to check for destructive overlap here since TDmode
20993 can only reside in even/odd register pairs. */
20994 if (FP_REGNO_P (reg) && DECIMAL_FLOAT_MODE_P (mode) && !BYTES_BIG_ENDIAN)
20996 rtx p_src, p_dst;
20997 int i;
20999 for (i = 0; i < nregs; i++)
21001 if (REG_P (src) && FP_REGNO_P (REGNO (src)))
21002 p_src = gen_rtx_REG (reg_mode, REGNO (src) + nregs - 1 - i);
21003 else
21004 p_src = simplify_gen_subreg (reg_mode, src, mode,
21005 i * reg_mode_size);
21007 if (REG_P (dst) && FP_REGNO_P (REGNO (dst)))
21008 p_dst = gen_rtx_REG (reg_mode, REGNO (dst) + nregs - 1 - i);
21009 else
21010 p_dst = simplify_gen_subreg (reg_mode, dst, mode,
21011 i * reg_mode_size);
21013 emit_insn (gen_rtx_SET (p_dst, p_src));
21016 return;
21019 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
21021 /* Move register range backwards, if we might have destructive
21022 overlap. */
21023 int i;
21024 for (i = nregs - 1; i >= 0; i--)
21025 emit_insn (gen_rtx_SET (simplify_gen_subreg (reg_mode, dst, mode,
21026 i * reg_mode_size),
21027 simplify_gen_subreg (reg_mode, src, mode,
21028 i * reg_mode_size)));
21030 else
21032 int i;
21033 int j = -1;
21034 bool used_update = false;
21035 rtx restore_basereg = NULL_RTX;
21037 if (MEM_P (src) && INT_REGNO_P (reg))
21039 rtx breg;
21041 if (GET_CODE (XEXP (src, 0)) == PRE_INC
21042 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
21044 rtx delta_rtx;
21045 breg = XEXP (XEXP (src, 0), 0);
21046 delta_rtx = (GET_CODE (XEXP (src, 0)) == PRE_INC
21047 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
21048 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src))));
21049 emit_insn (gen_add3_insn (breg, breg, delta_rtx));
21050 src = replace_equiv_address (src, breg);
21052 else if (! rs6000_offsettable_memref_p (src, reg_mode))
21054 if (GET_CODE (XEXP (src, 0)) == PRE_MODIFY)
21056 rtx basereg = XEXP (XEXP (src, 0), 0);
21057 if (TARGET_UPDATE)
21059 rtx ndst = simplify_gen_subreg (reg_mode, dst, mode, 0);
21060 emit_insn (gen_rtx_SET (ndst,
21061 gen_rtx_MEM (reg_mode,
21062 XEXP (src, 0))));
21063 used_update = true;
21065 else
21066 emit_insn (gen_rtx_SET (basereg,
21067 XEXP (XEXP (src, 0), 1)));
21068 src = replace_equiv_address (src, basereg);
21070 else
21072 rtx basereg = gen_rtx_REG (Pmode, reg);
21073 emit_insn (gen_rtx_SET (basereg, XEXP (src, 0)));
21074 src = replace_equiv_address (src, basereg);
21078 breg = XEXP (src, 0);
21079 if (GET_CODE (breg) == PLUS || GET_CODE (breg) == LO_SUM)
21080 breg = XEXP (breg, 0);
21082 /* If the base register we are using to address memory is
21083 also a destination reg, then change that register last. */
21084 if (REG_P (breg)
21085 && REGNO (breg) >= REGNO (dst)
21086 && REGNO (breg) < REGNO (dst) + nregs)
21087 j = REGNO (breg) - REGNO (dst);
21089 else if (MEM_P (dst) && INT_REGNO_P (reg))
21091 rtx breg;
21093 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
21094 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
21096 rtx delta_rtx;
21097 breg = XEXP (XEXP (dst, 0), 0);
21098 delta_rtx = (GET_CODE (XEXP (dst, 0)) == PRE_INC
21099 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
21100 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst))));
21102 /* We have to update the breg before doing the store.
21103 Use store with update, if available. */
21105 if (TARGET_UPDATE)
21107 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
21108 emit_insn (TARGET_32BIT
21109 ? (TARGET_POWERPC64
21110 ? gen_movdi_si_update (breg, breg, delta_rtx, nsrc)
21111 : gen_movsi_update (breg, breg, delta_rtx, nsrc))
21112 : gen_movdi_di_update (breg, breg, delta_rtx, nsrc));
21113 used_update = true;
21115 else
21116 emit_insn (gen_add3_insn (breg, breg, delta_rtx));
21117 dst = replace_equiv_address (dst, breg);
21119 else if (!rs6000_offsettable_memref_p (dst, reg_mode)
21120 && GET_CODE (XEXP (dst, 0)) != LO_SUM)
21122 if (GET_CODE (XEXP (dst, 0)) == PRE_MODIFY)
21124 rtx basereg = XEXP (XEXP (dst, 0), 0);
21125 if (TARGET_UPDATE)
21127 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
21128 emit_insn (gen_rtx_SET (gen_rtx_MEM (reg_mode,
21129 XEXP (dst, 0)),
21130 nsrc));
21131 used_update = true;
21133 else
21134 emit_insn (gen_rtx_SET (basereg,
21135 XEXP (XEXP (dst, 0), 1)));
21136 dst = replace_equiv_address (dst, basereg);
21138 else
21140 rtx basereg = XEXP (XEXP (dst, 0), 0);
21141 rtx offsetreg = XEXP (XEXP (dst, 0), 1);
21142 gcc_assert (GET_CODE (XEXP (dst, 0)) == PLUS
21143 && REG_P (basereg)
21144 && REG_P (offsetreg)
21145 && REGNO (basereg) != REGNO (offsetreg));
21146 if (REGNO (basereg) == 0)
21148 rtx tmp = offsetreg;
21149 offsetreg = basereg;
21150 basereg = tmp;
21152 emit_insn (gen_add3_insn (basereg, basereg, offsetreg));
21153 restore_basereg = gen_sub3_insn (basereg, basereg, offsetreg);
21154 dst = replace_equiv_address (dst, basereg);
21157 else if (GET_CODE (XEXP (dst, 0)) != LO_SUM)
21158 gcc_assert (rs6000_offsettable_memref_p (dst, reg_mode));
21161 for (i = 0; i < nregs; i++)
21163 /* Calculate index to next subword. */
21164 ++j;
21165 if (j == nregs)
21166 j = 0;
21168 /* If compiler already emitted move of first word by
21169 store with update, no need to do anything. */
21170 if (j == 0 && used_update)
21171 continue;
21173 emit_insn (gen_rtx_SET (simplify_gen_subreg (reg_mode, dst, mode,
21174 j * reg_mode_size),
21175 simplify_gen_subreg (reg_mode, src, mode,
21176 j * reg_mode_size)));
21178 if (restore_basereg != NULL_RTX)
21179 emit_insn (restore_basereg);
21184 /* This page contains routines that are used to determine what the
21185 function prologue and epilogue code will do and write them out. */
21187 static inline bool
21188 save_reg_p (int r)
21190 return !call_used_regs[r] && df_regs_ever_live_p (r);
21193 /* Return the first fixed-point register that is required to be
21194 saved. 32 if none. */
21197 first_reg_to_save (void)
21199 int first_reg;
21201 /* Find lowest numbered live register. */
21202 for (first_reg = 13; first_reg <= 31; first_reg++)
21203 if (save_reg_p (first_reg))
21204 break;
21206 if (first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM
21207 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
21208 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)
21209 || (TARGET_TOC && TARGET_MINIMAL_TOC))
21210 && df_regs_ever_live_p (RS6000_PIC_OFFSET_TABLE_REGNUM))
21211 first_reg = RS6000_PIC_OFFSET_TABLE_REGNUM;
21213 #if TARGET_MACHO
21214 if (flag_pic
21215 && crtl->uses_pic_offset_table
21216 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
21217 return RS6000_PIC_OFFSET_TABLE_REGNUM;
21218 #endif
21220 return first_reg;
21223 /* Similar, for FP regs. */
21226 first_fp_reg_to_save (void)
21228 int first_reg;
21230 /* Find lowest numbered live register. */
21231 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
21232 if (save_reg_p (first_reg))
21233 break;
21235 return first_reg;
21238 /* Similar, for AltiVec regs. */
21240 static int
21241 first_altivec_reg_to_save (void)
21243 int i;
21245 /* Stack frame remains as is unless we are in AltiVec ABI. */
21246 if (! TARGET_ALTIVEC_ABI)
21247 return LAST_ALTIVEC_REGNO + 1;
21249 /* On Darwin, the unwind routines are compiled without
21250 TARGET_ALTIVEC, and use save_world to save/restore the
21251 altivec registers when necessary. */
21252 if (DEFAULT_ABI == ABI_DARWIN && crtl->calls_eh_return
21253 && ! TARGET_ALTIVEC)
21254 return FIRST_ALTIVEC_REGNO + 20;
21256 /* Find lowest numbered live register. */
21257 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
21258 if (save_reg_p (i))
21259 break;
21261 return i;
21264 /* Return a 32-bit mask of the AltiVec registers we need to set in
21265 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
21266 the 32-bit word is 0. */
21268 static unsigned int
21269 compute_vrsave_mask (void)
21271 unsigned int i, mask = 0;
21273 /* On Darwin, the unwind routines are compiled without
21274 TARGET_ALTIVEC, and use save_world to save/restore the
21275 call-saved altivec registers when necessary. */
21276 if (DEFAULT_ABI == ABI_DARWIN && crtl->calls_eh_return
21277 && ! TARGET_ALTIVEC)
21278 mask |= 0xFFF;
21280 /* First, find out if we use _any_ altivec registers. */
21281 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
21282 if (df_regs_ever_live_p (i))
21283 mask |= ALTIVEC_REG_BIT (i);
21285 if (mask == 0)
21286 return mask;
21288 /* Next, remove the argument registers from the set. These must
21289 be in the VRSAVE mask set by the caller, so we don't need to add
21290 them in again. More importantly, the mask we compute here is
21291 used to generate CLOBBERs in the set_vrsave insn, and we do not
21292 wish the argument registers to die. */
21293 for (i = ALTIVEC_ARG_MIN_REG; i < (unsigned) crtl->args.info.vregno; i++)
21294 mask &= ~ALTIVEC_REG_BIT (i);
21296 /* Similarly, remove the return value from the set. */
21298 bool yes = false;
21299 diddle_return_value (is_altivec_return_reg, &yes);
21300 if (yes)
21301 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
21304 return mask;
21307 /* For a very restricted set of circumstances, we can cut down the
21308 size of prologues/epilogues by calling our own save/restore-the-world
21309 routines. */
21311 static void
21312 compute_save_world_info (rs6000_stack_t *info_ptr)
21314 info_ptr->world_save_p = 1;
21315 info_ptr->world_save_p
21316 = (WORLD_SAVE_P (info_ptr)
21317 && DEFAULT_ABI == ABI_DARWIN
21318 && !cfun->has_nonlocal_label
21319 && info_ptr->first_fp_reg_save == FIRST_SAVED_FP_REGNO
21320 && info_ptr->first_gp_reg_save == FIRST_SAVED_GP_REGNO
21321 && info_ptr->first_altivec_reg_save == FIRST_SAVED_ALTIVEC_REGNO
21322 && info_ptr->cr_save_p);
21324 /* This will not work in conjunction with sibcalls. Make sure there
21325 are none. (This check is expensive, but seldom executed.) */
21326 if (WORLD_SAVE_P (info_ptr))
21328 rtx_insn *insn;
21329 for (insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn))
21330 if (CALL_P (insn) && SIBLING_CALL_P (insn))
21332 info_ptr->world_save_p = 0;
21333 break;
21337 if (WORLD_SAVE_P (info_ptr))
21339 /* Even if we're not touching VRsave, make sure there's room on the
21340 stack for it, if it looks like we're calling SAVE_WORLD, which
21341 will attempt to save it. */
21342 info_ptr->vrsave_size = 4;
21344 /* If we are going to save the world, we need to save the link register too. */
21345 info_ptr->lr_save_p = 1;
21347 /* "Save" the VRsave register too if we're saving the world. */
21348 if (info_ptr->vrsave_mask == 0)
21349 info_ptr->vrsave_mask = compute_vrsave_mask ();
21351 /* Because the Darwin register save/restore routines only handle
21352 F14 .. F31 and V20 .. V31 as per the ABI, perform a consistency
21353 check. */
21354 gcc_assert (info_ptr->first_fp_reg_save >= FIRST_SAVED_FP_REGNO
21355 && (info_ptr->first_altivec_reg_save
21356 >= FIRST_SAVED_ALTIVEC_REGNO));
21358 return;
21362 static void
21363 is_altivec_return_reg (rtx reg, void *xyes)
21365 bool *yes = (bool *) xyes;
21366 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
21367 *yes = true;
21371 /* Look for user-defined global regs in the range FIRST to LAST-1.
21372 We should not restore these, and so cannot use lmw or out-of-line
21373 restore functions if there are any. We also can't save them
21374 (well, emit frame notes for them), because frame unwinding during
21375 exception handling will restore saved registers. */
21377 static bool
21378 global_regs_p (unsigned first, unsigned last)
21380 while (first < last)
21381 if (global_regs[first++])
21382 return true;
21383 return false;
21386 /* Determine the strategy for savings/restoring registers. */
21388 enum {
21389 SAVRES_MULTIPLE = 0x1,
21390 SAVE_INLINE_FPRS = 0x2,
21391 SAVE_INLINE_GPRS = 0x4,
21392 REST_INLINE_FPRS = 0x8,
21393 REST_INLINE_GPRS = 0x10,
21394 SAVE_NOINLINE_GPRS_SAVES_LR = 0x20,
21395 SAVE_NOINLINE_FPRS_SAVES_LR = 0x40,
21396 REST_NOINLINE_FPRS_DOESNT_RESTORE_LR = 0x80,
21397 SAVE_INLINE_VRS = 0x100,
21398 REST_INLINE_VRS = 0x200
21401 static int
21402 rs6000_savres_strategy (rs6000_stack_t *info,
21403 bool using_static_chain_p)
21405 int strategy = 0;
21406 bool lr_save_p;
21408 if (TARGET_MULTIPLE
21409 && !TARGET_POWERPC64
21410 && !(TARGET_SPE_ABI && info->spe_64bit_regs_used)
21411 && info->first_gp_reg_save < 31
21412 && !global_regs_p (info->first_gp_reg_save, 32))
21413 strategy |= SAVRES_MULTIPLE;
21415 if (crtl->calls_eh_return
21416 || cfun->machine->ra_need_lr)
21417 strategy |= (SAVE_INLINE_FPRS | REST_INLINE_FPRS
21418 | SAVE_INLINE_GPRS | REST_INLINE_GPRS
21419 | SAVE_INLINE_VRS | REST_INLINE_VRS);
21421 if (info->first_fp_reg_save == 64
21422 /* The out-of-line FP routines use double-precision stores;
21423 we can't use those routines if we don't have such stores. */
21424 || (TARGET_HARD_FLOAT && !TARGET_DOUBLE_FLOAT)
21425 || global_regs_p (info->first_fp_reg_save, 64))
21426 strategy |= SAVE_INLINE_FPRS | REST_INLINE_FPRS;
21428 if (info->first_gp_reg_save == 32
21429 || (!(strategy & SAVRES_MULTIPLE)
21430 && global_regs_p (info->first_gp_reg_save, 32)))
21431 strategy |= SAVE_INLINE_GPRS | REST_INLINE_GPRS;
21433 if (info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
21434 || global_regs_p (info->first_altivec_reg_save, LAST_ALTIVEC_REGNO + 1))
21435 strategy |= SAVE_INLINE_VRS | REST_INLINE_VRS;
21437 /* Define cutoff for using out-of-line functions to save registers. */
21438 if (DEFAULT_ABI == ABI_V4 || TARGET_ELF)
21440 if (!optimize_size)
21442 strategy |= SAVE_INLINE_FPRS | REST_INLINE_FPRS;
21443 strategy |= SAVE_INLINE_GPRS | REST_INLINE_GPRS;
21444 strategy |= SAVE_INLINE_VRS | REST_INLINE_VRS;
21446 else
21448 /* Prefer out-of-line restore if it will exit. */
21449 if (info->first_fp_reg_save > 61)
21450 strategy |= SAVE_INLINE_FPRS;
21451 if (info->first_gp_reg_save > 29)
21453 if (info->first_fp_reg_save == 64)
21454 strategy |= SAVE_INLINE_GPRS;
21455 else
21456 strategy |= SAVE_INLINE_GPRS | REST_INLINE_GPRS;
21458 if (info->first_altivec_reg_save == LAST_ALTIVEC_REGNO)
21459 strategy |= SAVE_INLINE_VRS | REST_INLINE_VRS;
21462 else if (DEFAULT_ABI == ABI_DARWIN)
21464 if (info->first_fp_reg_save > 60)
21465 strategy |= SAVE_INLINE_FPRS | REST_INLINE_FPRS;
21466 if (info->first_gp_reg_save > 29)
21467 strategy |= SAVE_INLINE_GPRS | REST_INLINE_GPRS;
21468 strategy |= SAVE_INLINE_VRS | REST_INLINE_VRS;
21470 else
21472 gcc_checking_assert (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2);
21473 if (info->first_fp_reg_save > 61)
21474 strategy |= SAVE_INLINE_FPRS | REST_INLINE_FPRS;
21475 strategy |= SAVE_INLINE_GPRS | REST_INLINE_GPRS;
21476 strategy |= SAVE_INLINE_VRS | REST_INLINE_VRS;
21479 /* Don't bother to try to save things out-of-line if r11 is occupied
21480 by the static chain. It would require too much fiddling and the
21481 static chain is rarely used anyway. FPRs are saved w.r.t the stack
21482 pointer on Darwin, and AIX uses r1 or r12. */
21483 if (using_static_chain_p
21484 && (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN))
21485 strategy |= ((DEFAULT_ABI == ABI_DARWIN ? 0 : SAVE_INLINE_FPRS)
21486 | SAVE_INLINE_GPRS
21487 | SAVE_INLINE_VRS | REST_INLINE_VRS);
21489 /* We can only use the out-of-line routines to restore if we've
21490 saved all the registers from first_fp_reg_save in the prologue.
21491 Otherwise, we risk loading garbage. */
21492 if ((strategy & (SAVE_INLINE_FPRS | REST_INLINE_FPRS)) == SAVE_INLINE_FPRS)
21494 int i;
21496 for (i = info->first_fp_reg_save; i < 64; i++)
21497 if (!save_reg_p (i))
21499 strategy |= REST_INLINE_FPRS;
21500 break;
21504 /* If we are going to use store multiple, then don't even bother
21505 with the out-of-line routines, since the store-multiple
21506 instruction will always be smaller. */
21507 if ((strategy & SAVRES_MULTIPLE))
21508 strategy |= SAVE_INLINE_GPRS;
21510 /* info->lr_save_p isn't yet set if the only reason lr needs to be
21511 saved is an out-of-line save or restore. Set up the value for
21512 the next test (excluding out-of-line gpr restore). */
21513 lr_save_p = (info->lr_save_p
21514 || !(strategy & SAVE_INLINE_GPRS)
21515 || !(strategy & SAVE_INLINE_FPRS)
21516 || !(strategy & SAVE_INLINE_VRS)
21517 || !(strategy & REST_INLINE_FPRS)
21518 || !(strategy & REST_INLINE_VRS));
21520 /* The situation is more complicated with load multiple. We'd
21521 prefer to use the out-of-line routines for restores, since the
21522 "exit" out-of-line routines can handle the restore of LR and the
21523 frame teardown. However if doesn't make sense to use the
21524 out-of-line routine if that is the only reason we'd need to save
21525 LR, and we can't use the "exit" out-of-line gpr restore if we
21526 have saved some fprs; In those cases it is advantageous to use
21527 load multiple when available. */
21528 if ((strategy & SAVRES_MULTIPLE)
21529 && (!lr_save_p
21530 || info->first_fp_reg_save != 64))
21531 strategy |= REST_INLINE_GPRS;
21533 /* Saving CR interferes with the exit routines used on the SPE, so
21534 just punt here. */
21535 if (TARGET_SPE_ABI
21536 && info->spe_64bit_regs_used
21537 && info->cr_save_p)
21538 strategy |= REST_INLINE_GPRS;
21540 /* We can only use load multiple or the out-of-line routines to
21541 restore if we've used store multiple or out-of-line routines
21542 in the prologue, i.e. if we've saved all the registers from
21543 first_gp_reg_save. Otherwise, we risk loading garbage. */
21544 if ((strategy & (SAVE_INLINE_GPRS | REST_INLINE_GPRS | SAVRES_MULTIPLE))
21545 == SAVE_INLINE_GPRS)
21547 int i;
21549 for (i = info->first_gp_reg_save; i < 32; i++)
21550 if (!save_reg_p (i))
21552 strategy |= REST_INLINE_GPRS;
21553 break;
21557 if (TARGET_ELF && TARGET_64BIT)
21559 if (!(strategy & SAVE_INLINE_FPRS))
21560 strategy |= SAVE_NOINLINE_FPRS_SAVES_LR;
21561 else if (!(strategy & SAVE_INLINE_GPRS)
21562 && info->first_fp_reg_save == 64)
21563 strategy |= SAVE_NOINLINE_GPRS_SAVES_LR;
21565 else if (TARGET_AIX && !(strategy & REST_INLINE_FPRS))
21566 strategy |= REST_NOINLINE_FPRS_DOESNT_RESTORE_LR;
21568 if (TARGET_MACHO && !(strategy & SAVE_INLINE_FPRS))
21569 strategy |= SAVE_NOINLINE_FPRS_SAVES_LR;
21571 return strategy;
21574 /* Calculate the stack information for the current function. This is
21575 complicated by having two separate calling sequences, the AIX calling
21576 sequence and the V.4 calling sequence.
21578 AIX (and Darwin/Mac OS X) stack frames look like:
21579 32-bit 64-bit
21580 SP----> +---------------------------------------+
21581 | back chain to caller | 0 0
21582 +---------------------------------------+
21583 | saved CR | 4 8 (8-11)
21584 +---------------------------------------+
21585 | saved LR | 8 16
21586 +---------------------------------------+
21587 | reserved for compilers | 12 24
21588 +---------------------------------------+
21589 | reserved for binders | 16 32
21590 +---------------------------------------+
21591 | saved TOC pointer | 20 40
21592 +---------------------------------------+
21593 | Parameter save area (P) | 24 48
21594 +---------------------------------------+
21595 | Alloca space (A) | 24+P etc.
21596 +---------------------------------------+
21597 | Local variable space (L) | 24+P+A
21598 +---------------------------------------+
21599 | Float/int conversion temporary (X) | 24+P+A+L
21600 +---------------------------------------+
21601 | Save area for AltiVec registers (W) | 24+P+A+L+X
21602 +---------------------------------------+
21603 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
21604 +---------------------------------------+
21605 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
21606 +---------------------------------------+
21607 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
21608 +---------------------------------------+
21609 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
21610 +---------------------------------------+
21611 old SP->| back chain to caller's caller |
21612 +---------------------------------------+
21614 The required alignment for AIX configurations is two words (i.e., 8
21615 or 16 bytes).
21617 The ELFv2 ABI is a variant of the AIX ABI. Stack frames look like:
21619 SP----> +---------------------------------------+
21620 | Back chain to caller | 0
21621 +---------------------------------------+
21622 | Save area for CR | 8
21623 +---------------------------------------+
21624 | Saved LR | 16
21625 +---------------------------------------+
21626 | Saved TOC pointer | 24
21627 +---------------------------------------+
21628 | Parameter save area (P) | 32
21629 +---------------------------------------+
21630 | Alloca space (A) | 32+P
21631 +---------------------------------------+
21632 | Local variable space (L) | 32+P+A
21633 +---------------------------------------+
21634 | Save area for AltiVec registers (W) | 32+P+A+L
21635 +---------------------------------------+
21636 | AltiVec alignment padding (Y) | 32+P+A+L+W
21637 +---------------------------------------+
21638 | Save area for GP registers (G) | 32+P+A+L+W+Y
21639 +---------------------------------------+
21640 | Save area for FP registers (F) | 32+P+A+L+W+Y+G
21641 +---------------------------------------+
21642 old SP->| back chain to caller's caller | 32+P+A+L+W+Y+G+F
21643 +---------------------------------------+
21646 V.4 stack frames look like:
21648 SP----> +---------------------------------------+
21649 | back chain to caller | 0
21650 +---------------------------------------+
21651 | caller's saved LR | 4
21652 +---------------------------------------+
21653 | Parameter save area (P) | 8
21654 +---------------------------------------+
21655 | Alloca space (A) | 8+P
21656 +---------------------------------------+
21657 | Varargs save area (V) | 8+P+A
21658 +---------------------------------------+
21659 | Local variable space (L) | 8+P+A+V
21660 +---------------------------------------+
21661 | Float/int conversion temporary (X) | 8+P+A+V+L
21662 +---------------------------------------+
21663 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
21664 +---------------------------------------+
21665 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
21666 +---------------------------------------+
21667 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
21668 +---------------------------------------+
21669 | SPE: area for 64-bit GP registers |
21670 +---------------------------------------+
21671 | SPE alignment padding |
21672 +---------------------------------------+
21673 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
21674 +---------------------------------------+
21675 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
21676 +---------------------------------------+
21677 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
21678 +---------------------------------------+
21679 old SP->| back chain to caller's caller |
21680 +---------------------------------------+
21682 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
21683 given. (But note below and in sysv4.h that we require only 8 and
21684 may round up the size of our stack frame anyways. The historical
21685 reason is early versions of powerpc-linux which didn't properly
21686 align the stack at program startup. A happy side-effect is that
21687 -mno-eabi libraries can be used with -meabi programs.)
21689 The EABI configuration defaults to the V.4 layout. However,
21690 the stack alignment requirements may differ. If -mno-eabi is not
21691 given, the required stack alignment is 8 bytes; if -mno-eabi is
21692 given, the required alignment is 16 bytes. (But see V.4 comment
21693 above.) */
21695 #ifndef ABI_STACK_BOUNDARY
21696 #define ABI_STACK_BOUNDARY STACK_BOUNDARY
21697 #endif
21699 static rs6000_stack_t *
21700 rs6000_stack_info (void)
21702 /* We should never be called for thunks, we are not set up for that. */
21703 gcc_assert (!cfun->is_thunk);
21705 rs6000_stack_t *info_ptr = &stack_info;
21706 int reg_size = TARGET_32BIT ? 4 : 8;
21707 int ehrd_size;
21708 int ehcr_size;
21709 int save_align;
21710 int first_gp;
21711 HOST_WIDE_INT non_fixed_size;
21712 bool using_static_chain_p;
21714 if (reload_completed && info_ptr->reload_completed)
21715 return info_ptr;
21717 memset (info_ptr, 0, sizeof (*info_ptr));
21718 info_ptr->reload_completed = reload_completed;
21720 if (TARGET_SPE)
21722 /* Cache value so we don't rescan instruction chain over and over. */
21723 if (cfun->machine->insn_chain_scanned_p == 0)
21724 cfun->machine->insn_chain_scanned_p
21725 = spe_func_has_64bit_regs_p () + 1;
21726 info_ptr->spe_64bit_regs_used = cfun->machine->insn_chain_scanned_p - 1;
21729 /* Select which calling sequence. */
21730 info_ptr->abi = DEFAULT_ABI;
21732 /* Calculate which registers need to be saved & save area size. */
21733 info_ptr->first_gp_reg_save = first_reg_to_save ();
21734 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
21735 even if it currently looks like we won't. Reload may need it to
21736 get at a constant; if so, it will have already created a constant
21737 pool entry for it. */
21738 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
21739 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
21740 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
21741 && crtl->uses_const_pool
21742 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
21743 first_gp = RS6000_PIC_OFFSET_TABLE_REGNUM;
21744 else
21745 first_gp = info_ptr->first_gp_reg_save;
21747 info_ptr->gp_size = reg_size * (32 - first_gp);
21749 /* For the SPE, we have an additional upper 32-bits on each GPR.
21750 Ideally we should save the entire 64-bits only when the upper
21751 half is used in SIMD instructions. Since we only record
21752 registers live (not the size they are used in), this proves
21753 difficult because we'd have to traverse the instruction chain at
21754 the right time, taking reload into account. This is a real pain,
21755 so we opt to save the GPRs in 64-bits always if but one register
21756 gets used in 64-bits. Otherwise, all the registers in the frame
21757 get saved in 32-bits.
21759 So... since when we save all GPRs (except the SP) in 64-bits, the
21760 traditional GP save area will be empty. */
21761 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
21762 info_ptr->gp_size = 0;
21764 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
21765 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
21767 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
21768 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
21769 - info_ptr->first_altivec_reg_save);
21771 /* Does this function call anything? */
21772 info_ptr->calls_p = (! crtl->is_leaf
21773 || cfun->machine->ra_needs_full_frame);
21775 /* Determine if we need to save the condition code registers. */
21776 if (df_regs_ever_live_p (CR2_REGNO)
21777 || df_regs_ever_live_p (CR3_REGNO)
21778 || df_regs_ever_live_p (CR4_REGNO))
21780 info_ptr->cr_save_p = 1;
21781 if (DEFAULT_ABI == ABI_V4)
21782 info_ptr->cr_size = reg_size;
21785 /* If the current function calls __builtin_eh_return, then we need
21786 to allocate stack space for registers that will hold data for
21787 the exception handler. */
21788 if (crtl->calls_eh_return)
21790 unsigned int i;
21791 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
21792 continue;
21794 /* SPE saves EH registers in 64-bits. */
21795 ehrd_size = i * (TARGET_SPE_ABI
21796 && info_ptr->spe_64bit_regs_used != 0
21797 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
21799 else
21800 ehrd_size = 0;
21802 /* In the ELFv2 ABI, we also need to allocate space for separate
21803 CR field save areas if the function calls __builtin_eh_return. */
21804 if (DEFAULT_ABI == ABI_ELFv2 && crtl->calls_eh_return)
21806 /* This hard-codes that we have three call-saved CR fields. */
21807 ehcr_size = 3 * reg_size;
21808 /* We do *not* use the regular CR save mechanism. */
21809 info_ptr->cr_save_p = 0;
21811 else
21812 ehcr_size = 0;
21814 /* Determine various sizes. */
21815 info_ptr->reg_size = reg_size;
21816 info_ptr->fixed_size = RS6000_SAVE_AREA;
21817 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
21818 info_ptr->parm_size = RS6000_ALIGN (crtl->outgoing_args_size,
21819 TARGET_ALTIVEC ? 16 : 8);
21820 if (FRAME_GROWS_DOWNWARD)
21821 info_ptr->vars_size
21822 += RS6000_ALIGN (info_ptr->fixed_size + info_ptr->vars_size
21823 + info_ptr->parm_size,
21824 ABI_STACK_BOUNDARY / BITS_PER_UNIT)
21825 - (info_ptr->fixed_size + info_ptr->vars_size
21826 + info_ptr->parm_size);
21828 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
21829 info_ptr->spe_gp_size = 8 * (32 - first_gp);
21830 else
21831 info_ptr->spe_gp_size = 0;
21833 if (TARGET_ALTIVEC_ABI)
21834 info_ptr->vrsave_mask = compute_vrsave_mask ();
21835 else
21836 info_ptr->vrsave_mask = 0;
21838 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
21839 info_ptr->vrsave_size = 4;
21840 else
21841 info_ptr->vrsave_size = 0;
21843 compute_save_world_info (info_ptr);
21845 /* Calculate the offsets. */
21846 switch (DEFAULT_ABI)
21848 case ABI_NONE:
21849 default:
21850 gcc_unreachable ();
21852 case ABI_AIX:
21853 case ABI_ELFv2:
21854 case ABI_DARWIN:
21855 info_ptr->fp_save_offset = - info_ptr->fp_size;
21856 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
21858 if (TARGET_ALTIVEC_ABI)
21860 info_ptr->vrsave_save_offset
21861 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
21863 /* Align stack so vector save area is on a quadword boundary.
21864 The padding goes above the vectors. */
21865 if (info_ptr->altivec_size != 0)
21866 info_ptr->altivec_padding_size
21867 = info_ptr->vrsave_save_offset & 0xF;
21868 else
21869 info_ptr->altivec_padding_size = 0;
21871 info_ptr->altivec_save_offset
21872 = info_ptr->vrsave_save_offset
21873 - info_ptr->altivec_padding_size
21874 - info_ptr->altivec_size;
21875 gcc_assert (info_ptr->altivec_size == 0
21876 || info_ptr->altivec_save_offset % 16 == 0);
21878 /* Adjust for AltiVec case. */
21879 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
21881 else
21882 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
21884 info_ptr->ehcr_offset = info_ptr->ehrd_offset - ehcr_size;
21885 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
21886 info_ptr->lr_save_offset = 2*reg_size;
21887 break;
21889 case ABI_V4:
21890 info_ptr->fp_save_offset = - info_ptr->fp_size;
21891 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
21892 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
21894 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
21896 /* Align stack so SPE GPR save area is aligned on a
21897 double-word boundary. */
21898 if (info_ptr->spe_gp_size != 0 && info_ptr->cr_save_offset != 0)
21899 info_ptr->spe_padding_size
21900 = 8 - (-info_ptr->cr_save_offset % 8);
21901 else
21902 info_ptr->spe_padding_size = 0;
21904 info_ptr->spe_gp_save_offset
21905 = info_ptr->cr_save_offset
21906 - info_ptr->spe_padding_size
21907 - info_ptr->spe_gp_size;
21909 /* Adjust for SPE case. */
21910 info_ptr->ehrd_offset = info_ptr->spe_gp_save_offset;
21912 else if (TARGET_ALTIVEC_ABI)
21914 info_ptr->vrsave_save_offset
21915 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
21917 /* Align stack so vector save area is on a quadword boundary. */
21918 if (info_ptr->altivec_size != 0)
21919 info_ptr->altivec_padding_size
21920 = 16 - (-info_ptr->vrsave_save_offset % 16);
21921 else
21922 info_ptr->altivec_padding_size = 0;
21924 info_ptr->altivec_save_offset
21925 = info_ptr->vrsave_save_offset
21926 - info_ptr->altivec_padding_size
21927 - info_ptr->altivec_size;
21929 /* Adjust for AltiVec case. */
21930 info_ptr->ehrd_offset = info_ptr->altivec_save_offset;
21932 else
21933 info_ptr->ehrd_offset = info_ptr->cr_save_offset;
21934 info_ptr->ehrd_offset -= ehrd_size;
21935 info_ptr->lr_save_offset = reg_size;
21936 break;
21939 save_align = (TARGET_ALTIVEC_ABI || DEFAULT_ABI == ABI_DARWIN) ? 16 : 8;
21940 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
21941 + info_ptr->gp_size
21942 + info_ptr->altivec_size
21943 + info_ptr->altivec_padding_size
21944 + info_ptr->spe_gp_size
21945 + info_ptr->spe_padding_size
21946 + ehrd_size
21947 + ehcr_size
21948 + info_ptr->cr_size
21949 + info_ptr->vrsave_size,
21950 save_align);
21952 non_fixed_size = (info_ptr->vars_size
21953 + info_ptr->parm_size
21954 + info_ptr->save_size);
21956 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
21957 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
21959 /* Determine if we need to save the link register. */
21960 if (info_ptr->calls_p
21961 || ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
21962 && crtl->profile
21963 && !TARGET_PROFILE_KERNEL)
21964 || (DEFAULT_ABI == ABI_V4 && cfun->calls_alloca)
21965 #ifdef TARGET_RELOCATABLE
21966 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
21967 #endif
21968 || rs6000_ra_ever_killed ())
21969 info_ptr->lr_save_p = 1;
21971 using_static_chain_p = (cfun->static_chain_decl != NULL_TREE
21972 && df_regs_ever_live_p (STATIC_CHAIN_REGNUM)
21973 && call_used_regs[STATIC_CHAIN_REGNUM]);
21974 info_ptr->savres_strategy = rs6000_savres_strategy (info_ptr,
21975 using_static_chain_p);
21977 if (!(info_ptr->savres_strategy & SAVE_INLINE_GPRS)
21978 || !(info_ptr->savres_strategy & SAVE_INLINE_FPRS)
21979 || !(info_ptr->savres_strategy & SAVE_INLINE_VRS)
21980 || !(info_ptr->savres_strategy & REST_INLINE_GPRS)
21981 || !(info_ptr->savres_strategy & REST_INLINE_FPRS)
21982 || !(info_ptr->savres_strategy & REST_INLINE_VRS))
21983 info_ptr->lr_save_p = 1;
21985 if (info_ptr->lr_save_p)
21986 df_set_regs_ever_live (LR_REGNO, true);
21988 /* Determine if we need to allocate any stack frame:
21990 For AIX we need to push the stack if a frame pointer is needed
21991 (because the stack might be dynamically adjusted), if we are
21992 debugging, if we make calls, or if the sum of fp_save, gp_save,
21993 and local variables are more than the space needed to save all
21994 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
21995 + 18*8 = 288 (GPR13 reserved).
21997 For V.4 we don't have the stack cushion that AIX uses, but assume
21998 that the debugger can handle stackless frames. */
22000 if (info_ptr->calls_p)
22001 info_ptr->push_p = 1;
22003 else if (DEFAULT_ABI == ABI_V4)
22004 info_ptr->push_p = non_fixed_size != 0;
22006 else if (frame_pointer_needed)
22007 info_ptr->push_p = 1;
22009 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
22010 info_ptr->push_p = 1;
22012 else
22013 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
22015 return info_ptr;
22018 /* Return true if the current function uses any GPRs in 64-bit SIMD
22019 mode. */
22021 static bool
22022 spe_func_has_64bit_regs_p (void)
22024 rtx_insn *insns, *insn;
22026 /* Functions that save and restore all the call-saved registers will
22027 need to save/restore the registers in 64-bits. */
22028 if (crtl->calls_eh_return
22029 || cfun->calls_setjmp
22030 || crtl->has_nonlocal_goto)
22031 return true;
22033 insns = get_insns ();
22035 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
22037 if (INSN_P (insn))
22039 rtx i;
22041 /* FIXME: This should be implemented with attributes...
22043 (set_attr "spe64" "true")....then,
22044 if (get_spe64(insn)) return true;
22046 It's the only reliable way to do the stuff below. */
22048 i = PATTERN (insn);
22049 if (GET_CODE (i) == SET)
22051 machine_mode mode = GET_MODE (SET_SRC (i));
22053 if (SPE_VECTOR_MODE (mode))
22054 return true;
22055 if (TARGET_E500_DOUBLE && (mode == DFmode || mode == TFmode))
22056 return true;
22061 return false;
22064 static void
22065 debug_stack_info (rs6000_stack_t *info)
22067 const char *abi_string;
22069 if (! info)
22070 info = rs6000_stack_info ();
22072 fprintf (stderr, "\nStack information for function %s:\n",
22073 ((current_function_decl && DECL_NAME (current_function_decl))
22074 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
22075 : "<unknown>"));
22077 switch (info->abi)
22079 default: abi_string = "Unknown"; break;
22080 case ABI_NONE: abi_string = "NONE"; break;
22081 case ABI_AIX: abi_string = "AIX"; break;
22082 case ABI_ELFv2: abi_string = "ELFv2"; break;
22083 case ABI_DARWIN: abi_string = "Darwin"; break;
22084 case ABI_V4: abi_string = "V.4"; break;
22087 fprintf (stderr, "\tABI = %5s\n", abi_string);
22089 if (TARGET_ALTIVEC_ABI)
22090 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
22092 if (TARGET_SPE_ABI)
22093 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
22095 if (info->first_gp_reg_save != 32)
22096 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
22098 if (info->first_fp_reg_save != 64)
22099 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
22101 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
22102 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
22103 info->first_altivec_reg_save);
22105 if (info->lr_save_p)
22106 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
22108 if (info->cr_save_p)
22109 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
22111 if (info->vrsave_mask)
22112 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
22114 if (info->push_p)
22115 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
22117 if (info->calls_p)
22118 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
22120 if (info->gp_size)
22121 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
22123 if (info->fp_size)
22124 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
22126 if (info->altivec_size)
22127 fprintf (stderr, "\taltivec_save_offset = %5d\n",
22128 info->altivec_save_offset);
22130 if (info->spe_gp_size == 0)
22131 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
22132 info->spe_gp_save_offset);
22134 if (info->vrsave_size)
22135 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
22136 info->vrsave_save_offset);
22138 if (info->lr_save_p)
22139 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
22141 if (info->cr_save_p)
22142 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
22144 if (info->varargs_save_offset)
22145 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
22147 if (info->total_size)
22148 fprintf (stderr, "\ttotal_size = " HOST_WIDE_INT_PRINT_DEC"\n",
22149 info->total_size);
22151 if (info->vars_size)
22152 fprintf (stderr, "\tvars_size = " HOST_WIDE_INT_PRINT_DEC"\n",
22153 info->vars_size);
22155 if (info->parm_size)
22156 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
22158 if (info->fixed_size)
22159 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
22161 if (info->gp_size)
22162 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
22164 if (info->spe_gp_size)
22165 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
22167 if (info->fp_size)
22168 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
22170 if (info->altivec_size)
22171 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
22173 if (info->vrsave_size)
22174 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
22176 if (info->altivec_padding_size)
22177 fprintf (stderr, "\taltivec_padding_size= %5d\n",
22178 info->altivec_padding_size);
22180 if (info->spe_padding_size)
22181 fprintf (stderr, "\tspe_padding_size = %5d\n",
22182 info->spe_padding_size);
22184 if (info->cr_size)
22185 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
22187 if (info->save_size)
22188 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
22190 if (info->reg_size != 4)
22191 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
22193 fprintf (stderr, "\tsave-strategy = %04x\n", info->savres_strategy);
22195 fprintf (stderr, "\n");
22199 rs6000_return_addr (int count, rtx frame)
22201 /* Currently we don't optimize very well between prolog and body
22202 code and for PIC code the code can be actually quite bad, so
22203 don't try to be too clever here. */
22204 if (count != 0
22205 || ((DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_DARWIN) && flag_pic))
22207 cfun->machine->ra_needs_full_frame = 1;
22209 return
22210 gen_rtx_MEM
22211 (Pmode,
22212 memory_address
22213 (Pmode,
22214 plus_constant (Pmode,
22215 copy_to_reg
22216 (gen_rtx_MEM (Pmode,
22217 memory_address (Pmode, frame))),
22218 RETURN_ADDRESS_OFFSET)));
22221 cfun->machine->ra_need_lr = 1;
22222 return get_hard_reg_initial_val (Pmode, LR_REGNO);
22225 /* Say whether a function is a candidate for sibcall handling or not. */
22227 static bool
22228 rs6000_function_ok_for_sibcall (tree decl, tree exp)
22230 tree fntype;
22232 if (decl)
22233 fntype = TREE_TYPE (decl);
22234 else
22235 fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp)));
22237 /* We can't do it if the called function has more vector parameters
22238 than the current function; there's nowhere to put the VRsave code. */
22239 if (TARGET_ALTIVEC_ABI
22240 && TARGET_ALTIVEC_VRSAVE
22241 && !(decl && decl == current_function_decl))
22243 function_args_iterator args_iter;
22244 tree type;
22245 int nvreg = 0;
22247 /* Functions with vector parameters are required to have a
22248 prototype, so the argument type info must be available
22249 here. */
22250 FOREACH_FUNCTION_ARGS(fntype, type, args_iter)
22251 if (TREE_CODE (type) == VECTOR_TYPE
22252 && ALTIVEC_OR_VSX_VECTOR_MODE (TYPE_MODE (type)))
22253 nvreg++;
22255 FOREACH_FUNCTION_ARGS(TREE_TYPE (current_function_decl), type, args_iter)
22256 if (TREE_CODE (type) == VECTOR_TYPE
22257 && ALTIVEC_OR_VSX_VECTOR_MODE (TYPE_MODE (type)))
22258 nvreg--;
22260 if (nvreg > 0)
22261 return false;
22264 /* Under the AIX or ELFv2 ABIs we can't allow calls to non-local
22265 functions, because the callee may have a different TOC pointer to
22266 the caller and there's no way to ensure we restore the TOC when
22267 we return. With the secure-plt SYSV ABI we can't make non-local
22268 calls when -fpic/PIC because the plt call stubs use r30. */
22269 if (DEFAULT_ABI == ABI_DARWIN
22270 || ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
22271 && decl
22272 && !DECL_EXTERNAL (decl)
22273 && (*targetm.binds_local_p) (decl))
22274 || (DEFAULT_ABI == ABI_V4
22275 && (!TARGET_SECURE_PLT
22276 || !flag_pic
22277 || (decl
22278 && (*targetm.binds_local_p) (decl)))))
22280 tree attr_list = TYPE_ATTRIBUTES (fntype);
22282 if (!lookup_attribute ("longcall", attr_list)
22283 || lookup_attribute ("shortcall", attr_list))
22284 return true;
22287 return false;
22290 static int
22291 rs6000_ra_ever_killed (void)
22293 rtx_insn *top;
22294 rtx reg;
22295 rtx_insn *insn;
22297 if (cfun->is_thunk)
22298 return 0;
22300 if (cfun->machine->lr_save_state)
22301 return cfun->machine->lr_save_state - 1;
22303 /* regs_ever_live has LR marked as used if any sibcalls are present,
22304 but this should not force saving and restoring in the
22305 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
22306 clobbers LR, so that is inappropriate. */
22308 /* Also, the prologue can generate a store into LR that
22309 doesn't really count, like this:
22311 move LR->R0
22312 bcl to set PIC register
22313 move LR->R31
22314 move R0->LR
22316 When we're called from the epilogue, we need to avoid counting
22317 this as a store. */
22319 push_topmost_sequence ();
22320 top = get_insns ();
22321 pop_topmost_sequence ();
22322 reg = gen_rtx_REG (Pmode, LR_REGNO);
22324 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
22326 if (INSN_P (insn))
22328 if (CALL_P (insn))
22330 if (!SIBLING_CALL_P (insn))
22331 return 1;
22333 else if (find_regno_note (insn, REG_INC, LR_REGNO))
22334 return 1;
22335 else if (set_of (reg, insn) != NULL_RTX
22336 && !prologue_epilogue_contains (insn))
22337 return 1;
22340 return 0;
22343 /* Emit instructions needed to load the TOC register.
22344 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
22345 a constant pool; or for SVR4 -fpic. */
22347 void
22348 rs6000_emit_load_toc_table (int fromprolog)
22350 rtx dest;
22351 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
22353 if (TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic)
22355 char buf[30];
22356 rtx lab, tmp1, tmp2, got;
22358 lab = gen_label_rtx ();
22359 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (lab));
22360 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
22361 if (flag_pic == 2)
22362 got = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
22363 else
22364 got = rs6000_got_sym ();
22365 tmp1 = tmp2 = dest;
22366 if (!fromprolog)
22368 tmp1 = gen_reg_rtx (Pmode);
22369 tmp2 = gen_reg_rtx (Pmode);
22371 emit_insn (gen_load_toc_v4_PIC_1 (lab));
22372 emit_move_insn (tmp1, gen_rtx_REG (Pmode, LR_REGNO));
22373 emit_insn (gen_load_toc_v4_PIC_3b (tmp2, tmp1, got, lab));
22374 emit_insn (gen_load_toc_v4_PIC_3c (dest, tmp2, got, lab));
22376 else if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
22378 emit_insn (gen_load_toc_v4_pic_si ());
22379 emit_move_insn (dest, gen_rtx_REG (Pmode, LR_REGNO));
22381 else if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2)
22383 char buf[30];
22384 rtx temp0 = (fromprolog
22385 ? gen_rtx_REG (Pmode, 0)
22386 : gen_reg_rtx (Pmode));
22388 if (fromprolog)
22390 rtx symF, symL;
22392 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
22393 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
22395 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
22396 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
22398 emit_insn (gen_load_toc_v4_PIC_1 (symF));
22399 emit_move_insn (dest, gen_rtx_REG (Pmode, LR_REGNO));
22400 emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest, symL, symF));
22402 else
22404 rtx tocsym, lab;
22406 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
22407 lab = gen_label_rtx ();
22408 emit_insn (gen_load_toc_v4_PIC_1b (tocsym, lab));
22409 emit_move_insn (dest, gen_rtx_REG (Pmode, LR_REGNO));
22410 if (TARGET_LINK_STACK)
22411 emit_insn (gen_addsi3 (dest, dest, GEN_INT (4)));
22412 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
22414 emit_insn (gen_addsi3 (dest, temp0, dest));
22416 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
22418 /* This is for AIX code running in non-PIC ELF32. */
22419 char buf[30];
22420 rtx realsym;
22421 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
22422 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
22424 emit_insn (gen_elf_high (dest, realsym));
22425 emit_insn (gen_elf_low (dest, dest, realsym));
22427 else
22429 gcc_assert (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2);
22431 if (TARGET_32BIT)
22432 emit_insn (gen_load_toc_aix_si (dest));
22433 else
22434 emit_insn (gen_load_toc_aix_di (dest));
22438 /* Emit instructions to restore the link register after determining where
22439 its value has been stored. */
22441 void
22442 rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
22444 rs6000_stack_t *info = rs6000_stack_info ();
22445 rtx operands[2];
22447 operands[0] = source;
22448 operands[1] = scratch;
22450 if (info->lr_save_p)
22452 rtx frame_rtx = stack_pointer_rtx;
22453 HOST_WIDE_INT sp_offset = 0;
22454 rtx tmp;
22456 if (frame_pointer_needed
22457 || cfun->calls_alloca
22458 || info->total_size > 32767)
22460 tmp = gen_frame_mem (Pmode, frame_rtx);
22461 emit_move_insn (operands[1], tmp);
22462 frame_rtx = operands[1];
22464 else if (info->push_p)
22465 sp_offset = info->total_size;
22467 tmp = plus_constant (Pmode, frame_rtx,
22468 info->lr_save_offset + sp_offset);
22469 tmp = gen_frame_mem (Pmode, tmp);
22470 emit_move_insn (tmp, operands[0]);
22472 else
22473 emit_move_insn (gen_rtx_REG (Pmode, LR_REGNO), operands[0]);
22475 /* Freeze lr_save_p. We've just emitted rtl that depends on the
22476 state of lr_save_p so any change from here on would be a bug. In
22477 particular, stop rs6000_ra_ever_killed from considering the SET
22478 of lr we may have added just above. */
22479 cfun->machine->lr_save_state = info->lr_save_p + 1;
22482 static GTY(()) alias_set_type set = -1;
22484 alias_set_type
22485 get_TOC_alias_set (void)
22487 if (set == -1)
22488 set = new_alias_set ();
22489 return set;
22492 /* This returns nonzero if the current function uses the TOC. This is
22493 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
22494 is generated by the ABI_V4 load_toc_* patterns. */
22495 #if TARGET_ELF
22496 static int
22497 uses_TOC (void)
22499 rtx_insn *insn;
22501 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
22502 if (INSN_P (insn))
22504 rtx pat = PATTERN (insn);
22505 int i;
22507 if (GET_CODE (pat) == PARALLEL)
22508 for (i = 0; i < XVECLEN (pat, 0); i++)
22510 rtx sub = XVECEXP (pat, 0, i);
22511 if (GET_CODE (sub) == USE)
22513 sub = XEXP (sub, 0);
22514 if (GET_CODE (sub) == UNSPEC
22515 && XINT (sub, 1) == UNSPEC_TOC)
22516 return 1;
22520 return 0;
22522 #endif
22525 create_TOC_reference (rtx symbol, rtx largetoc_reg)
22527 rtx tocrel, tocreg, hi;
22529 if (TARGET_DEBUG_ADDR)
22531 if (GET_CODE (symbol) == SYMBOL_REF)
22532 fprintf (stderr, "\ncreate_TOC_reference, (symbol_ref %s)\n",
22533 XSTR (symbol, 0));
22534 else
22536 fprintf (stderr, "\ncreate_TOC_reference, code %s:\n",
22537 GET_RTX_NAME (GET_CODE (symbol)));
22538 debug_rtx (symbol);
22542 if (!can_create_pseudo_p ())
22543 df_set_regs_ever_live (TOC_REGISTER, true);
22545 tocreg = gen_rtx_REG (Pmode, TOC_REGISTER);
22546 tocrel = gen_rtx_UNSPEC (Pmode, gen_rtvec (2, symbol, tocreg), UNSPEC_TOCREL);
22547 if (TARGET_CMODEL == CMODEL_SMALL || can_create_pseudo_p ())
22548 return tocrel;
22550 hi = gen_rtx_HIGH (Pmode, copy_rtx (tocrel));
22551 if (largetoc_reg != NULL)
22553 emit_move_insn (largetoc_reg, hi);
22554 hi = largetoc_reg;
22556 return gen_rtx_LO_SUM (Pmode, hi, tocrel);
22559 /* Issue assembly directives that create a reference to the given DWARF
22560 FRAME_TABLE_LABEL from the current function section. */
22561 void
22562 rs6000_aix_asm_output_dwarf_table_ref (char * frame_table_label)
22564 fprintf (asm_out_file, "\t.ref %s\n",
22565 (* targetm.strip_name_encoding) (frame_table_label));
22568 /* This ties together stack memory (MEM with an alias set of frame_alias_set)
22569 and the change to the stack pointer. */
22571 static void
22572 rs6000_emit_stack_tie (rtx fp, bool hard_frame_needed)
22574 rtvec p;
22575 int i;
22576 rtx regs[3];
22578 i = 0;
22579 regs[i++] = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
22580 if (hard_frame_needed)
22581 regs[i++] = gen_rtx_REG (Pmode, HARD_FRAME_POINTER_REGNUM);
22582 if (!(REGNO (fp) == STACK_POINTER_REGNUM
22583 || (hard_frame_needed
22584 && REGNO (fp) == HARD_FRAME_POINTER_REGNUM)))
22585 regs[i++] = fp;
22587 p = rtvec_alloc (i);
22588 while (--i >= 0)
22590 rtx mem = gen_frame_mem (BLKmode, regs[i]);
22591 RTVEC_ELT (p, i) = gen_rtx_SET (mem, const0_rtx);
22594 emit_insn (gen_stack_tie (gen_rtx_PARALLEL (VOIDmode, p)));
22597 /* Emit the correct code for allocating stack space, as insns.
22598 If COPY_REG, make sure a copy of the old frame is left there.
22599 The generated code may use hard register 0 as a temporary. */
22601 static void
22602 rs6000_emit_allocate_stack (HOST_WIDE_INT size, rtx copy_reg, int copy_off)
22604 rtx_insn *insn;
22605 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
22606 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
22607 rtx todec = gen_int_mode (-size, Pmode);
22608 rtx par, set, mem;
22610 if (INTVAL (todec) != -size)
22612 warning (0, "stack frame too large");
22613 emit_insn (gen_trap ());
22614 return;
22617 if (crtl->limit_stack)
22619 if (REG_P (stack_limit_rtx)
22620 && REGNO (stack_limit_rtx) > 1
22621 && REGNO (stack_limit_rtx) <= 31)
22623 emit_insn (gen_add3_insn (tmp_reg, stack_limit_rtx, GEN_INT (size)));
22624 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
22625 const0_rtx));
22627 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
22628 && TARGET_32BIT
22629 && DEFAULT_ABI == ABI_V4)
22631 rtx toload = gen_rtx_CONST (VOIDmode,
22632 gen_rtx_PLUS (Pmode,
22633 stack_limit_rtx,
22634 GEN_INT (size)));
22636 emit_insn (gen_elf_high (tmp_reg, toload));
22637 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
22638 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
22639 const0_rtx));
22641 else
22642 warning (0, "stack limit expression is not supported");
22645 if (copy_reg)
22647 if (copy_off != 0)
22648 emit_insn (gen_add3_insn (copy_reg, stack_reg, GEN_INT (copy_off)));
22649 else
22650 emit_move_insn (copy_reg, stack_reg);
22653 if (size > 32767)
22655 /* Need a note here so that try_split doesn't get confused. */
22656 if (get_last_insn () == NULL_RTX)
22657 emit_note (NOTE_INSN_DELETED);
22658 insn = emit_move_insn (tmp_reg, todec);
22659 try_split (PATTERN (insn), insn, 0);
22660 todec = tmp_reg;
22663 insn = emit_insn (TARGET_32BIT
22664 ? gen_movsi_update_stack (stack_reg, stack_reg,
22665 todec, stack_reg)
22666 : gen_movdi_di_update_stack (stack_reg, stack_reg,
22667 todec, stack_reg));
22668 /* Since we didn't use gen_frame_mem to generate the MEM, grab
22669 it now and set the alias set/attributes. The above gen_*_update
22670 calls will generate a PARALLEL with the MEM set being the first
22671 operation. */
22672 par = PATTERN (insn);
22673 gcc_assert (GET_CODE (par) == PARALLEL);
22674 set = XVECEXP (par, 0, 0);
22675 gcc_assert (GET_CODE (set) == SET);
22676 mem = SET_DEST (set);
22677 gcc_assert (MEM_P (mem));
22678 MEM_NOTRAP_P (mem) = 1;
22679 set_mem_alias_set (mem, get_frame_alias_set ());
22681 RTX_FRAME_RELATED_P (insn) = 1;
22682 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
22683 gen_rtx_SET (stack_reg, gen_rtx_PLUS (Pmode, stack_reg,
22684 GEN_INT (-size))));
22687 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
22689 #if PROBE_INTERVAL > 32768
22690 #error Cannot use indexed addressing mode for stack probing
22691 #endif
22693 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
22694 inclusive. These are offsets from the current stack pointer. */
22696 static void
22697 rs6000_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
22699 /* See if we have a constant small number of probes to generate. If so,
22700 that's the easy case. */
22701 if (first + size <= 32768)
22703 HOST_WIDE_INT i;
22705 /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
22706 it exceeds SIZE. If only one probe is needed, this will not
22707 generate any code. Then probe at FIRST + SIZE. */
22708 for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
22709 emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
22710 -(first + i)));
22712 emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
22713 -(first + size)));
22716 /* Otherwise, do the same as above, but in a loop. Note that we must be
22717 extra careful with variables wrapping around because we might be at
22718 the very top (or the very bottom) of the address space and we have
22719 to be able to handle this case properly; in particular, we use an
22720 equality test for the loop condition. */
22721 else
22723 HOST_WIDE_INT rounded_size;
22724 rtx r12 = gen_rtx_REG (Pmode, 12);
22725 rtx r0 = gen_rtx_REG (Pmode, 0);
22727 /* Sanity check for the addressing mode we're going to use. */
22728 gcc_assert (first <= 32768);
22730 /* Step 1: round SIZE to the previous multiple of the interval. */
22732 rounded_size = size & -PROBE_INTERVAL;
22735 /* Step 2: compute initial and final value of the loop counter. */
22737 /* TEST_ADDR = SP + FIRST. */
22738 emit_insn (gen_rtx_SET (r12, plus_constant (Pmode, stack_pointer_rtx,
22739 -first)));
22741 /* LAST_ADDR = SP + FIRST + ROUNDED_SIZE. */
22742 if (rounded_size > 32768)
22744 emit_move_insn (r0, GEN_INT (-rounded_size));
22745 emit_insn (gen_rtx_SET (r0, gen_rtx_PLUS (Pmode, r12, r0)));
22747 else
22748 emit_insn (gen_rtx_SET (r0, plus_constant (Pmode, r12,
22749 -rounded_size)));
22752 /* Step 3: the loop
22754 while (TEST_ADDR != LAST_ADDR)
22756 TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
22757 probe at TEST_ADDR
22760 probes at FIRST + N * PROBE_INTERVAL for values of N from 1
22761 until it is equal to ROUNDED_SIZE. */
22763 if (TARGET_64BIT)
22764 emit_insn (gen_probe_stack_rangedi (r12, r12, r0));
22765 else
22766 emit_insn (gen_probe_stack_rangesi (r12, r12, r0));
22769 /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
22770 that SIZE is equal to ROUNDED_SIZE. */
22772 if (size != rounded_size)
22773 emit_stack_probe (plus_constant (Pmode, r12, rounded_size - size));
22777 /* Probe a range of stack addresses from REG1 to REG2 inclusive. These are
22778 absolute addresses. */
22780 const char *
22781 output_probe_stack_range (rtx reg1, rtx reg2)
22783 static int labelno = 0;
22784 char loop_lab[32], end_lab[32];
22785 rtx xops[2];
22787 ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
22788 ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
22790 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
22792 /* Jump to END_LAB if TEST_ADDR == LAST_ADDR. */
22793 xops[0] = reg1;
22794 xops[1] = reg2;
22795 if (TARGET_64BIT)
22796 output_asm_insn ("cmpd 0,%0,%1", xops);
22797 else
22798 output_asm_insn ("cmpw 0,%0,%1", xops);
22800 fputs ("\tbeq 0,", asm_out_file);
22801 assemble_name_raw (asm_out_file, end_lab);
22802 fputc ('\n', asm_out_file);
22804 /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL. */
22805 xops[1] = GEN_INT (-PROBE_INTERVAL);
22806 output_asm_insn ("addi %0,%0,%1", xops);
22808 /* Probe at TEST_ADDR and branch. */
22809 xops[1] = gen_rtx_REG (Pmode, 0);
22810 output_asm_insn ("stw %1,0(%0)", xops);
22811 fprintf (asm_out_file, "\tb ");
22812 assemble_name_raw (asm_out_file, loop_lab);
22813 fputc ('\n', asm_out_file);
22815 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
22817 return "";
22820 /* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
22821 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
22822 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
22823 deduce these equivalences by itself so it wasn't necessary to hold
22824 its hand so much. Don't be tempted to always supply d2_f_d_e with
22825 the actual cfa register, ie. r31 when we are using a hard frame
22826 pointer. That fails when saving regs off r1, and sched moves the
22827 r31 setup past the reg saves. */
22829 static rtx
22830 rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
22831 rtx reg2, rtx rreg)
22833 rtx real, temp;
22835 if (REGNO (reg) == STACK_POINTER_REGNUM && reg2 == NULL_RTX)
22837 /* No need for any replacement. Just set RTX_FRAME_RELATED_P. */
22838 int i;
22840 gcc_checking_assert (val == 0);
22841 real = PATTERN (insn);
22842 if (GET_CODE (real) == PARALLEL)
22843 for (i = 0; i < XVECLEN (real, 0); i++)
22844 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
22846 rtx set = XVECEXP (real, 0, i);
22848 RTX_FRAME_RELATED_P (set) = 1;
22850 RTX_FRAME_RELATED_P (insn) = 1;
22851 return insn;
22854 /* copy_rtx will not make unique copies of registers, so we need to
22855 ensure we don't have unwanted sharing here. */
22856 if (reg == reg2)
22857 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
22859 if (reg == rreg)
22860 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
22862 real = copy_rtx (PATTERN (insn));
22864 if (reg2 != NULL_RTX)
22865 real = replace_rtx (real, reg2, rreg);
22867 if (REGNO (reg) == STACK_POINTER_REGNUM)
22868 gcc_checking_assert (val == 0);
22869 else
22870 real = replace_rtx (real, reg,
22871 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
22872 STACK_POINTER_REGNUM),
22873 GEN_INT (val)));
22875 /* We expect that 'real' is either a SET or a PARALLEL containing
22876 SETs (and possibly other stuff). In a PARALLEL, all the SETs
22877 are important so they all have to be marked RTX_FRAME_RELATED_P. */
22879 if (GET_CODE (real) == SET)
22881 rtx set = real;
22883 temp = simplify_rtx (SET_SRC (set));
22884 if (temp)
22885 SET_SRC (set) = temp;
22886 temp = simplify_rtx (SET_DEST (set));
22887 if (temp)
22888 SET_DEST (set) = temp;
22889 if (GET_CODE (SET_DEST (set)) == MEM)
22891 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
22892 if (temp)
22893 XEXP (SET_DEST (set), 0) = temp;
22896 else
22898 int i;
22900 gcc_assert (GET_CODE (real) == PARALLEL);
22901 for (i = 0; i < XVECLEN (real, 0); i++)
22902 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
22904 rtx set = XVECEXP (real, 0, i);
22906 temp = simplify_rtx (SET_SRC (set));
22907 if (temp)
22908 SET_SRC (set) = temp;
22909 temp = simplify_rtx (SET_DEST (set));
22910 if (temp)
22911 SET_DEST (set) = temp;
22912 if (GET_CODE (SET_DEST (set)) == MEM)
22914 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
22915 if (temp)
22916 XEXP (SET_DEST (set), 0) = temp;
22918 RTX_FRAME_RELATED_P (set) = 1;
22922 RTX_FRAME_RELATED_P (insn) = 1;
22923 add_reg_note (insn, REG_FRAME_RELATED_EXPR, real);
22925 return insn;
22928 /* Returns an insn that has a vrsave set operation with the
22929 appropriate CLOBBERs. */
22931 static rtx
22932 generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
22934 int nclobs, i;
22935 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
22936 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
22938 clobs[0]
22939 = gen_rtx_SET (vrsave,
22940 gen_rtx_UNSPEC_VOLATILE (SImode,
22941 gen_rtvec (2, reg, vrsave),
22942 UNSPECV_SET_VRSAVE));
22944 nclobs = 1;
22946 /* We need to clobber the registers in the mask so the scheduler
22947 does not move sets to VRSAVE before sets of AltiVec registers.
22949 However, if the function receives nonlocal gotos, reload will set
22950 all call saved registers live. We will end up with:
22952 (set (reg 999) (mem))
22953 (parallel [ (set (reg vrsave) (unspec blah))
22954 (clobber (reg 999))])
22956 The clobber will cause the store into reg 999 to be dead, and
22957 flow will attempt to delete an epilogue insn. In this case, we
22958 need an unspec use/set of the register. */
22960 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
22961 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
22963 if (!epiloguep || call_used_regs [i])
22964 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
22965 gen_rtx_REG (V4SImode, i));
22966 else
22968 rtx reg = gen_rtx_REG (V4SImode, i);
22970 clobs[nclobs++]
22971 = gen_rtx_SET (reg,
22972 gen_rtx_UNSPEC (V4SImode,
22973 gen_rtvec (1, reg), 27));
22977 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
22979 for (i = 0; i < nclobs; ++i)
22980 XVECEXP (insn, 0, i) = clobs[i];
22982 return insn;
22985 static rtx
22986 gen_frame_set (rtx reg, rtx frame_reg, int offset, bool store)
22988 rtx addr, mem;
22990 addr = gen_rtx_PLUS (Pmode, frame_reg, GEN_INT (offset));
22991 mem = gen_frame_mem (GET_MODE (reg), addr);
22992 return gen_rtx_SET (store ? mem : reg, store ? reg : mem);
22995 static rtx
22996 gen_frame_load (rtx reg, rtx frame_reg, int offset)
22998 return gen_frame_set (reg, frame_reg, offset, false);
23001 static rtx
23002 gen_frame_store (rtx reg, rtx frame_reg, int offset)
23004 return gen_frame_set (reg, frame_reg, offset, true);
23007 /* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
23008 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
23010 static rtx
23011 emit_frame_save (rtx frame_reg, machine_mode mode,
23012 unsigned int regno, int offset, HOST_WIDE_INT frame_reg_to_sp)
23014 rtx reg, insn;
23016 /* Some cases that need register indexed addressing. */
23017 gcc_checking_assert (!((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
23018 || (TARGET_VSX && ALTIVEC_OR_VSX_VECTOR_MODE (mode))
23019 || (TARGET_E500_DOUBLE && mode == DFmode)
23020 || (TARGET_SPE_ABI
23021 && SPE_VECTOR_MODE (mode)
23022 && !SPE_CONST_OFFSET_OK (offset))));
23024 reg = gen_rtx_REG (mode, regno);
23025 insn = emit_insn (gen_frame_store (reg, frame_reg, offset));
23026 return rs6000_frame_related (insn, frame_reg, frame_reg_to_sp,
23027 NULL_RTX, NULL_RTX);
23030 /* Emit an offset memory reference suitable for a frame store, while
23031 converting to a valid addressing mode. */
23033 static rtx
23034 gen_frame_mem_offset (machine_mode mode, rtx reg, int offset)
23036 rtx int_rtx, offset_rtx;
23038 int_rtx = GEN_INT (offset);
23040 if ((TARGET_SPE_ABI && SPE_VECTOR_MODE (mode) && !SPE_CONST_OFFSET_OK (offset))
23041 || (TARGET_E500_DOUBLE && mode == DFmode))
23043 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
23044 emit_move_insn (offset_rtx, int_rtx);
23046 else
23047 offset_rtx = int_rtx;
23049 return gen_frame_mem (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
23052 #ifndef TARGET_FIX_AND_CONTINUE
23053 #define TARGET_FIX_AND_CONTINUE 0
23054 #endif
23056 /* It's really GPR 13 or 14, FPR 14 and VR 20. We need the smallest. */
23057 #define FIRST_SAVRES_REGISTER FIRST_SAVED_GP_REGNO
23058 #define LAST_SAVRES_REGISTER 31
23059 #define N_SAVRES_REGISTERS (LAST_SAVRES_REGISTER - FIRST_SAVRES_REGISTER + 1)
23061 enum {
23062 SAVRES_LR = 0x1,
23063 SAVRES_SAVE = 0x2,
23064 SAVRES_REG = 0x0c,
23065 SAVRES_GPR = 0,
23066 SAVRES_FPR = 4,
23067 SAVRES_VR = 8
23070 static GTY(()) rtx savres_routine_syms[N_SAVRES_REGISTERS][12];
23072 /* Temporary holding space for an out-of-line register save/restore
23073 routine name. */
23074 static char savres_routine_name[30];
23076 /* Return the name for an out-of-line register save/restore routine.
23077 We are saving/restoring GPRs if GPR is true. */
23079 static char *
23080 rs6000_savres_routine_name (rs6000_stack_t *info, int regno, int sel)
23082 const char *prefix = "";
23083 const char *suffix = "";
23085 /* Different targets are supposed to define
23086 {SAVE,RESTORE}_FP_{PREFIX,SUFFIX} with the idea that the needed
23087 routine name could be defined with:
23089 sprintf (name, "%s%d%s", SAVE_FP_PREFIX, regno, SAVE_FP_SUFFIX)
23091 This is a nice idea in practice, but in reality, things are
23092 complicated in several ways:
23094 - ELF targets have save/restore routines for GPRs.
23096 - SPE targets use different prefixes for 32/64-bit registers, and
23097 neither of them fit neatly in the FOO_{PREFIX,SUFFIX} regimen.
23099 - PPC64 ELF targets have routines for save/restore of GPRs that
23100 differ in what they do with the link register, so having a set
23101 prefix doesn't work. (We only use one of the save routines at
23102 the moment, though.)
23104 - PPC32 elf targets have "exit" versions of the restore routines
23105 that restore the link register and can save some extra space.
23106 These require an extra suffix. (There are also "tail" versions
23107 of the restore routines and "GOT" versions of the save routines,
23108 but we don't generate those at present. Same problems apply,
23109 though.)
23111 We deal with all this by synthesizing our own prefix/suffix and
23112 using that for the simple sprintf call shown above. */
23113 if (TARGET_SPE)
23115 /* No floating point saves on the SPE. */
23116 gcc_assert ((sel & SAVRES_REG) == SAVRES_GPR);
23118 if ((sel & SAVRES_SAVE))
23119 prefix = info->spe_64bit_regs_used ? "_save64gpr_" : "_save32gpr_";
23120 else
23121 prefix = info->spe_64bit_regs_used ? "_rest64gpr_" : "_rest32gpr_";
23123 if ((sel & SAVRES_LR))
23124 suffix = "_x";
23126 else if (DEFAULT_ABI == ABI_V4)
23128 if (TARGET_64BIT)
23129 goto aix_names;
23131 if ((sel & SAVRES_REG) == SAVRES_GPR)
23132 prefix = (sel & SAVRES_SAVE) ? "_savegpr_" : "_restgpr_";
23133 else if ((sel & SAVRES_REG) == SAVRES_FPR)
23134 prefix = (sel & SAVRES_SAVE) ? "_savefpr_" : "_restfpr_";
23135 else if ((sel & SAVRES_REG) == SAVRES_VR)
23136 prefix = (sel & SAVRES_SAVE) ? "_savevr_" : "_restvr_";
23137 else
23138 abort ();
23140 if ((sel & SAVRES_LR))
23141 suffix = "_x";
23143 else if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
23145 #if !defined (POWERPC_LINUX) && !defined (POWERPC_FREEBSD)
23146 /* No out-of-line save/restore routines for GPRs on AIX. */
23147 gcc_assert (!TARGET_AIX || (sel & SAVRES_REG) != SAVRES_GPR);
23148 #endif
23150 aix_names:
23151 if ((sel & SAVRES_REG) == SAVRES_GPR)
23152 prefix = ((sel & SAVRES_SAVE)
23153 ? ((sel & SAVRES_LR) ? "_savegpr0_" : "_savegpr1_")
23154 : ((sel & SAVRES_LR) ? "_restgpr0_" : "_restgpr1_"));
23155 else if ((sel & SAVRES_REG) == SAVRES_FPR)
23157 #if defined (POWERPC_LINUX) || defined (POWERPC_FREEBSD)
23158 if ((sel & SAVRES_LR))
23159 prefix = ((sel & SAVRES_SAVE) ? "_savefpr_" : "_restfpr_");
23160 else
23161 #endif
23163 prefix = (sel & SAVRES_SAVE) ? SAVE_FP_PREFIX : RESTORE_FP_PREFIX;
23164 suffix = (sel & SAVRES_SAVE) ? SAVE_FP_SUFFIX : RESTORE_FP_SUFFIX;
23167 else if ((sel & SAVRES_REG) == SAVRES_VR)
23168 prefix = (sel & SAVRES_SAVE) ? "_savevr_" : "_restvr_";
23169 else
23170 abort ();
23173 if (DEFAULT_ABI == ABI_DARWIN)
23175 /* The Darwin approach is (slightly) different, in order to be
23176 compatible with code generated by the system toolchain. There is a
23177 single symbol for the start of save sequence, and the code here
23178 embeds an offset into that code on the basis of the first register
23179 to be saved. */
23180 prefix = (sel & SAVRES_SAVE) ? "save" : "rest" ;
23181 if ((sel & SAVRES_REG) == SAVRES_GPR)
23182 sprintf (savres_routine_name, "*%sGPR%s%s%.0d ; %s r%d-r31", prefix,
23183 ((sel & SAVRES_LR) ? "x" : ""), (regno == 13 ? "" : "+"),
23184 (regno - 13) * 4, prefix, regno);
23185 else if ((sel & SAVRES_REG) == SAVRES_FPR)
23186 sprintf (savres_routine_name, "*%sFP%s%.0d ; %s f%d-f31", prefix,
23187 (regno == 14 ? "" : "+"), (regno - 14) * 4, prefix, regno);
23188 else if ((sel & SAVRES_REG) == SAVRES_VR)
23189 sprintf (savres_routine_name, "*%sVEC%s%.0d ; %s v%d-v31", prefix,
23190 (regno == 20 ? "" : "+"), (regno - 20) * 8, prefix, regno);
23191 else
23192 abort ();
23194 else
23195 sprintf (savres_routine_name, "%s%d%s", prefix, regno, suffix);
23197 return savres_routine_name;
23200 /* Return an RTL SYMBOL_REF for an out-of-line register save/restore routine.
23201 We are saving/restoring GPRs if GPR is true. */
23203 static rtx
23204 rs6000_savres_routine_sym (rs6000_stack_t *info, int sel)
23206 int regno = ((sel & SAVRES_REG) == SAVRES_GPR
23207 ? info->first_gp_reg_save
23208 : (sel & SAVRES_REG) == SAVRES_FPR
23209 ? info->first_fp_reg_save - 32
23210 : (sel & SAVRES_REG) == SAVRES_VR
23211 ? info->first_altivec_reg_save - FIRST_ALTIVEC_REGNO
23212 : -1);
23213 rtx sym;
23214 int select = sel;
23216 /* On the SPE, we never have any FPRs, but we do have 32/64-bit
23217 versions of the gpr routines. */
23218 if (TARGET_SPE_ABI && (sel & SAVRES_REG) == SAVRES_GPR
23219 && info->spe_64bit_regs_used)
23220 select ^= SAVRES_FPR ^ SAVRES_GPR;
23222 /* Don't generate bogus routine names. */
23223 gcc_assert (FIRST_SAVRES_REGISTER <= regno
23224 && regno <= LAST_SAVRES_REGISTER
23225 && select >= 0 && select <= 12);
23227 sym = savres_routine_syms[regno-FIRST_SAVRES_REGISTER][select];
23229 if (sym == NULL)
23231 char *name;
23233 name = rs6000_savres_routine_name (info, regno, sel);
23235 sym = savres_routine_syms[regno-FIRST_SAVRES_REGISTER][select]
23236 = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
23237 SYMBOL_REF_FLAGS (sym) |= SYMBOL_FLAG_FUNCTION;
23240 return sym;
23243 /* Emit a sequence of insns, including a stack tie if needed, for
23244 resetting the stack pointer. If UPDT_REGNO is not 1, then don't
23245 reset the stack pointer, but move the base of the frame into
23246 reg UPDT_REGNO for use by out-of-line register restore routines. */
23248 static rtx
23249 rs6000_emit_stack_reset (rs6000_stack_t *info,
23250 rtx frame_reg_rtx, HOST_WIDE_INT frame_off,
23251 unsigned updt_regno)
23253 rtx updt_reg_rtx;
23255 /* This blockage is needed so that sched doesn't decide to move
23256 the sp change before the register restores. */
23257 if (DEFAULT_ABI == ABI_V4
23258 || (TARGET_SPE_ABI
23259 && info->spe_64bit_regs_used != 0
23260 && info->first_gp_reg_save != 32))
23261 rs6000_emit_stack_tie (frame_reg_rtx, frame_pointer_needed);
23263 /* If we are restoring registers out-of-line, we will be using the
23264 "exit" variants of the restore routines, which will reset the
23265 stack for us. But we do need to point updt_reg into the
23266 right place for those routines. */
23267 updt_reg_rtx = gen_rtx_REG (Pmode, updt_regno);
23269 if (frame_off != 0)
23270 return emit_insn (gen_add3_insn (updt_reg_rtx,
23271 frame_reg_rtx, GEN_INT (frame_off)));
23272 else if (REGNO (frame_reg_rtx) != updt_regno)
23273 return emit_move_insn (updt_reg_rtx, frame_reg_rtx);
23275 return NULL_RTX;
23278 /* Return the register number used as a pointer by out-of-line
23279 save/restore functions. */
23281 static inline unsigned
23282 ptr_regno_for_savres (int sel)
23284 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
23285 return (sel & SAVRES_REG) == SAVRES_FPR || (sel & SAVRES_LR) ? 1 : 12;
23286 return DEFAULT_ABI == ABI_DARWIN && (sel & SAVRES_REG) == SAVRES_FPR ? 1 : 11;
23289 /* Construct a parallel rtx describing the effect of a call to an
23290 out-of-line register save/restore routine, and emit the insn
23291 or jump_insn as appropriate. */
23293 static rtx
23294 rs6000_emit_savres_rtx (rs6000_stack_t *info,
23295 rtx frame_reg_rtx, int save_area_offset, int lr_offset,
23296 machine_mode reg_mode, int sel)
23298 int i;
23299 int offset, start_reg, end_reg, n_regs, use_reg;
23300 int reg_size = GET_MODE_SIZE (reg_mode);
23301 rtx sym;
23302 rtvec p;
23303 rtx par, insn;
23305 offset = 0;
23306 start_reg = ((sel & SAVRES_REG) == SAVRES_GPR
23307 ? info->first_gp_reg_save
23308 : (sel & SAVRES_REG) == SAVRES_FPR
23309 ? info->first_fp_reg_save
23310 : (sel & SAVRES_REG) == SAVRES_VR
23311 ? info->first_altivec_reg_save
23312 : -1);
23313 end_reg = ((sel & SAVRES_REG) == SAVRES_GPR
23314 ? 32
23315 : (sel & SAVRES_REG) == SAVRES_FPR
23316 ? 64
23317 : (sel & SAVRES_REG) == SAVRES_VR
23318 ? LAST_ALTIVEC_REGNO + 1
23319 : -1);
23320 n_regs = end_reg - start_reg;
23321 p = rtvec_alloc (3 + ((sel & SAVRES_LR) ? 1 : 0)
23322 + ((sel & SAVRES_REG) == SAVRES_VR ? 1 : 0)
23323 + n_regs);
23325 if (!(sel & SAVRES_SAVE) && (sel & SAVRES_LR))
23326 RTVEC_ELT (p, offset++) = ret_rtx;
23328 RTVEC_ELT (p, offset++)
23329 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, LR_REGNO));
23331 sym = rs6000_savres_routine_sym (info, sel);
23332 RTVEC_ELT (p, offset++) = gen_rtx_USE (VOIDmode, sym);
23334 use_reg = ptr_regno_for_savres (sel);
23335 if ((sel & SAVRES_REG) == SAVRES_VR)
23337 /* Vector regs are saved/restored using [reg+reg] addressing. */
23338 RTVEC_ELT (p, offset++)
23339 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, use_reg));
23340 RTVEC_ELT (p, offset++)
23341 = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, 0));
23343 else
23344 RTVEC_ELT (p, offset++)
23345 = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, use_reg));
23347 for (i = 0; i < end_reg - start_reg; i++)
23348 RTVEC_ELT (p, i + offset)
23349 = gen_frame_set (gen_rtx_REG (reg_mode, start_reg + i),
23350 frame_reg_rtx, save_area_offset + reg_size * i,
23351 (sel & SAVRES_SAVE) != 0);
23353 if ((sel & SAVRES_SAVE) && (sel & SAVRES_LR))
23354 RTVEC_ELT (p, i + offset)
23355 = gen_frame_store (gen_rtx_REG (Pmode, 0), frame_reg_rtx, lr_offset);
23357 par = gen_rtx_PARALLEL (VOIDmode, p);
23359 if (!(sel & SAVRES_SAVE) && (sel & SAVRES_LR))
23361 insn = emit_jump_insn (par);
23362 JUMP_LABEL (insn) = ret_rtx;
23364 else
23365 insn = emit_insn (par);
23366 return insn;
23369 /* Emit code to store CR fields that need to be saved into REG. */
23371 static void
23372 rs6000_emit_move_from_cr (rtx reg)
23374 /* Only the ELFv2 ABI allows storing only selected fields. */
23375 if (DEFAULT_ABI == ABI_ELFv2 && TARGET_MFCRF)
23377 int i, cr_reg[8], count = 0;
23379 /* Collect CR fields that must be saved. */
23380 for (i = 0; i < 8; i++)
23381 if (save_reg_p (CR0_REGNO + i))
23382 cr_reg[count++] = i;
23384 /* If it's just a single one, use mfcrf. */
23385 if (count == 1)
23387 rtvec p = rtvec_alloc (1);
23388 rtvec r = rtvec_alloc (2);
23389 RTVEC_ELT (r, 0) = gen_rtx_REG (CCmode, CR0_REGNO + cr_reg[0]);
23390 RTVEC_ELT (r, 1) = GEN_INT (1 << (7 - cr_reg[0]));
23391 RTVEC_ELT (p, 0)
23392 = gen_rtx_SET (reg,
23393 gen_rtx_UNSPEC (SImode, r, UNSPEC_MOVESI_FROM_CR));
23395 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
23396 return;
23399 /* ??? It might be better to handle count == 2 / 3 cases here
23400 as well, using logical operations to combine the values. */
23403 emit_insn (gen_movesi_from_cr (reg));
23406 /* Determine whether the gp REG is really used. */
23408 static bool
23409 rs6000_reg_live_or_pic_offset_p (int reg)
23411 /* If the function calls eh_return, claim used all the registers that would
23412 be checked for liveness otherwise. This is required for the PIC offset
23413 register with -mminimal-toc on AIX, as it is advertised as "fixed" for
23414 register allocation purposes in this case. */
23416 return (((crtl->calls_eh_return || df_regs_ever_live_p (reg))
23417 && (!call_used_regs[reg]
23418 || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM
23419 && !TARGET_SINGLE_PIC_BASE
23420 && TARGET_TOC && TARGET_MINIMAL_TOC)))
23421 || (reg == RS6000_PIC_OFFSET_TABLE_REGNUM
23422 && !TARGET_SINGLE_PIC_BASE
23423 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
23424 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))));
23427 /* Emit function prologue as insns. */
23429 void
23430 rs6000_emit_prologue (void)
23432 rs6000_stack_t *info = rs6000_stack_info ();
23433 machine_mode reg_mode = Pmode;
23434 int reg_size = TARGET_32BIT ? 4 : 8;
23435 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
23436 rtx frame_reg_rtx = sp_reg_rtx;
23437 unsigned int cr_save_regno;
23438 rtx cr_save_rtx = NULL_RTX;
23439 rtx insn;
23440 int strategy;
23441 int using_static_chain_p = (cfun->static_chain_decl != NULL_TREE
23442 && df_regs_ever_live_p (STATIC_CHAIN_REGNUM)
23443 && call_used_regs[STATIC_CHAIN_REGNUM]);
23444 /* Offset to top of frame for frame_reg and sp respectively. */
23445 HOST_WIDE_INT frame_off = 0;
23446 HOST_WIDE_INT sp_off = 0;
23448 #ifdef ENABLE_CHECKING
23449 /* Track and check usage of r0, r11, r12. */
23450 int reg_inuse = using_static_chain_p ? 1 << 11 : 0;
23451 #define START_USE(R) do \
23453 gcc_assert ((reg_inuse & (1 << (R))) == 0); \
23454 reg_inuse |= 1 << (R); \
23455 } while (0)
23456 #define END_USE(R) do \
23458 gcc_assert ((reg_inuse & (1 << (R))) != 0); \
23459 reg_inuse &= ~(1 << (R)); \
23460 } while (0)
23461 #define NOT_INUSE(R) do \
23463 gcc_assert ((reg_inuse & (1 << (R))) == 0); \
23464 } while (0)
23465 #else
23466 #define START_USE(R) do {} while (0)
23467 #define END_USE(R) do {} while (0)
23468 #define NOT_INUSE(R) do {} while (0)
23469 #endif
23471 if (DEFAULT_ABI == ABI_ELFv2)
23473 cfun->machine->r2_setup_needed = df_regs_ever_live_p (TOC_REGNUM);
23475 /* With -mminimal-toc we may generate an extra use of r2 below. */
23476 if (!TARGET_SINGLE_PIC_BASE
23477 && TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
23478 cfun->machine->r2_setup_needed = true;
23482 if (flag_stack_usage_info)
23483 current_function_static_stack_size = info->total_size;
23485 if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
23487 HOST_WIDE_INT size = info->total_size;
23489 if (crtl->is_leaf && !cfun->calls_alloca)
23491 if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
23492 rs6000_emit_probe_stack_range (STACK_CHECK_PROTECT,
23493 size - STACK_CHECK_PROTECT);
23495 else if (size > 0)
23496 rs6000_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
23499 if (TARGET_FIX_AND_CONTINUE)
23501 /* gdb on darwin arranges to forward a function from the old
23502 address by modifying the first 5 instructions of the function
23503 to branch to the overriding function. This is necessary to
23504 permit function pointers that point to the old function to
23505 actually forward to the new function. */
23506 emit_insn (gen_nop ());
23507 emit_insn (gen_nop ());
23508 emit_insn (gen_nop ());
23509 emit_insn (gen_nop ());
23510 emit_insn (gen_nop ());
23513 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
23515 reg_mode = V2SImode;
23516 reg_size = 8;
23519 /* Handle world saves specially here. */
23520 if (WORLD_SAVE_P (info))
23522 int i, j, sz;
23523 rtx treg;
23524 rtvec p;
23525 rtx reg0;
23527 /* save_world expects lr in r0. */
23528 reg0 = gen_rtx_REG (Pmode, 0);
23529 if (info->lr_save_p)
23531 insn = emit_move_insn (reg0,
23532 gen_rtx_REG (Pmode, LR_REGNO));
23533 RTX_FRAME_RELATED_P (insn) = 1;
23536 /* The SAVE_WORLD and RESTORE_WORLD routines make a number of
23537 assumptions about the offsets of various bits of the stack
23538 frame. */
23539 gcc_assert (info->gp_save_offset == -220
23540 && info->fp_save_offset == -144
23541 && info->lr_save_offset == 8
23542 && info->cr_save_offset == 4
23543 && info->push_p
23544 && info->lr_save_p
23545 && (!crtl->calls_eh_return
23546 || info->ehrd_offset == -432)
23547 && info->vrsave_save_offset == -224
23548 && info->altivec_save_offset == -416);
23550 treg = gen_rtx_REG (SImode, 11);
23551 emit_move_insn (treg, GEN_INT (-info->total_size));
23553 /* SAVE_WORLD takes the caller's LR in R0 and the frame size
23554 in R11. It also clobbers R12, so beware! */
23556 /* Preserve CR2 for save_world prologues */
23557 sz = 5;
23558 sz += 32 - info->first_gp_reg_save;
23559 sz += 64 - info->first_fp_reg_save;
23560 sz += LAST_ALTIVEC_REGNO - info->first_altivec_reg_save + 1;
23561 p = rtvec_alloc (sz);
23562 j = 0;
23563 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode,
23564 gen_rtx_REG (SImode,
23565 LR_REGNO));
23566 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
23567 gen_rtx_SYMBOL_REF (Pmode,
23568 "*save_world"));
23569 /* We do floats first so that the instruction pattern matches
23570 properly. */
23571 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
23572 RTVEC_ELT (p, j++)
23573 = gen_frame_store (gen_rtx_REG (TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
23574 ? DFmode : SFmode,
23575 info->first_fp_reg_save + i),
23576 frame_reg_rtx,
23577 info->fp_save_offset + frame_off + 8 * i);
23578 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
23579 RTVEC_ELT (p, j++)
23580 = gen_frame_store (gen_rtx_REG (V4SImode,
23581 info->first_altivec_reg_save + i),
23582 frame_reg_rtx,
23583 info->altivec_save_offset + frame_off + 16 * i);
23584 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
23585 RTVEC_ELT (p, j++)
23586 = gen_frame_store (gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
23587 frame_reg_rtx,
23588 info->gp_save_offset + frame_off + reg_size * i);
23590 /* CR register traditionally saved as CR2. */
23591 RTVEC_ELT (p, j++)
23592 = gen_frame_store (gen_rtx_REG (SImode, CR2_REGNO),
23593 frame_reg_rtx, info->cr_save_offset + frame_off);
23594 /* Explain about use of R0. */
23595 if (info->lr_save_p)
23596 RTVEC_ELT (p, j++)
23597 = gen_frame_store (reg0,
23598 frame_reg_rtx, info->lr_save_offset + frame_off);
23599 /* Explain what happens to the stack pointer. */
23601 rtx newval = gen_rtx_PLUS (Pmode, sp_reg_rtx, treg);
23602 RTVEC_ELT (p, j++) = gen_rtx_SET (sp_reg_rtx, newval);
23605 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
23606 rs6000_frame_related (insn, frame_reg_rtx, sp_off - frame_off,
23607 treg, GEN_INT (-info->total_size));
23608 sp_off = frame_off = info->total_size;
23611 strategy = info->savres_strategy;
23613 /* For V.4, update stack before we do any saving and set back pointer. */
23614 if (! WORLD_SAVE_P (info)
23615 && info->push_p
23616 && (DEFAULT_ABI == ABI_V4
23617 || crtl->calls_eh_return))
23619 bool need_r11 = (TARGET_SPE
23620 ? (!(strategy & SAVE_INLINE_GPRS)
23621 && info->spe_64bit_regs_used == 0)
23622 : (!(strategy & SAVE_INLINE_FPRS)
23623 || !(strategy & SAVE_INLINE_GPRS)
23624 || !(strategy & SAVE_INLINE_VRS)));
23625 int ptr_regno = -1;
23626 rtx ptr_reg = NULL_RTX;
23627 int ptr_off = 0;
23629 if (info->total_size < 32767)
23630 frame_off = info->total_size;
23631 else if (need_r11)
23632 ptr_regno = 11;
23633 else if (info->cr_save_p
23634 || info->lr_save_p
23635 || info->first_fp_reg_save < 64
23636 || info->first_gp_reg_save < 32
23637 || info->altivec_size != 0
23638 || info->vrsave_size != 0
23639 || crtl->calls_eh_return)
23640 ptr_regno = 12;
23641 else
23643 /* The prologue won't be saving any regs so there is no need
23644 to set up a frame register to access any frame save area.
23645 We also won't be using frame_off anywhere below, but set
23646 the correct value anyway to protect against future
23647 changes to this function. */
23648 frame_off = info->total_size;
23650 if (ptr_regno != -1)
23652 /* Set up the frame offset to that needed by the first
23653 out-of-line save function. */
23654 START_USE (ptr_regno);
23655 ptr_reg = gen_rtx_REG (Pmode, ptr_regno);
23656 frame_reg_rtx = ptr_reg;
23657 if (!(strategy & SAVE_INLINE_FPRS) && info->fp_size != 0)
23658 gcc_checking_assert (info->fp_save_offset + info->fp_size == 0);
23659 else if (!(strategy & SAVE_INLINE_GPRS) && info->first_gp_reg_save < 32)
23660 ptr_off = info->gp_save_offset + info->gp_size;
23661 else if (!(strategy & SAVE_INLINE_VRS) && info->altivec_size != 0)
23662 ptr_off = info->altivec_save_offset + info->altivec_size;
23663 frame_off = -ptr_off;
23665 rs6000_emit_allocate_stack (info->total_size, ptr_reg, ptr_off);
23666 sp_off = info->total_size;
23667 if (frame_reg_rtx != sp_reg_rtx)
23668 rs6000_emit_stack_tie (frame_reg_rtx, false);
23671 /* If we use the link register, get it into r0. */
23672 if (!WORLD_SAVE_P (info) && info->lr_save_p)
23674 rtx addr, reg, mem;
23676 reg = gen_rtx_REG (Pmode, 0);
23677 START_USE (0);
23678 insn = emit_move_insn (reg, gen_rtx_REG (Pmode, LR_REGNO));
23679 RTX_FRAME_RELATED_P (insn) = 1;
23681 if (!(strategy & (SAVE_NOINLINE_GPRS_SAVES_LR
23682 | SAVE_NOINLINE_FPRS_SAVES_LR)))
23684 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
23685 GEN_INT (info->lr_save_offset + frame_off));
23686 mem = gen_rtx_MEM (Pmode, addr);
23687 /* This should not be of rs6000_sr_alias_set, because of
23688 __builtin_return_address. */
23690 insn = emit_move_insn (mem, reg);
23691 rs6000_frame_related (insn, frame_reg_rtx, sp_off - frame_off,
23692 NULL_RTX, NULL_RTX);
23693 END_USE (0);
23697 /* If we need to save CR, put it into r12 or r11. Choose r12 except when
23698 r12 will be needed by out-of-line gpr restore. */
23699 cr_save_regno = ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
23700 && !(strategy & (SAVE_INLINE_GPRS
23701 | SAVE_NOINLINE_GPRS_SAVES_LR))
23702 ? 11 : 12);
23703 if (!WORLD_SAVE_P (info)
23704 && info->cr_save_p
23705 && REGNO (frame_reg_rtx) != cr_save_regno
23706 && !(using_static_chain_p && cr_save_regno == 11))
23708 cr_save_rtx = gen_rtx_REG (SImode, cr_save_regno);
23709 START_USE (cr_save_regno);
23710 rs6000_emit_move_from_cr (cr_save_rtx);
23713 /* Do any required saving of fpr's. If only one or two to save, do
23714 it ourselves. Otherwise, call function. */
23715 if (!WORLD_SAVE_P (info) && (strategy & SAVE_INLINE_FPRS))
23717 int i;
23718 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
23719 if (save_reg_p (info->first_fp_reg_save + i))
23720 emit_frame_save (frame_reg_rtx,
23721 (TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
23722 ? DFmode : SFmode),
23723 info->first_fp_reg_save + i,
23724 info->fp_save_offset + frame_off + 8 * i,
23725 sp_off - frame_off);
23727 else if (!WORLD_SAVE_P (info) && info->first_fp_reg_save != 64)
23729 bool lr = (strategy & SAVE_NOINLINE_FPRS_SAVES_LR) != 0;
23730 int sel = SAVRES_SAVE | SAVRES_FPR | (lr ? SAVRES_LR : 0);
23731 unsigned ptr_regno = ptr_regno_for_savres (sel);
23732 rtx ptr_reg = frame_reg_rtx;
23734 if (REGNO (frame_reg_rtx) == ptr_regno)
23735 gcc_checking_assert (frame_off == 0);
23736 else
23738 ptr_reg = gen_rtx_REG (Pmode, ptr_regno);
23739 NOT_INUSE (ptr_regno);
23740 emit_insn (gen_add3_insn (ptr_reg,
23741 frame_reg_rtx, GEN_INT (frame_off)));
23743 insn = rs6000_emit_savres_rtx (info, ptr_reg,
23744 info->fp_save_offset,
23745 info->lr_save_offset,
23746 DFmode, sel);
23747 rs6000_frame_related (insn, ptr_reg, sp_off,
23748 NULL_RTX, NULL_RTX);
23749 if (lr)
23750 END_USE (0);
23753 /* Save GPRs. This is done as a PARALLEL if we are using
23754 the store-multiple instructions. */
23755 if (!WORLD_SAVE_P (info)
23756 && TARGET_SPE_ABI
23757 && info->spe_64bit_regs_used != 0
23758 && info->first_gp_reg_save != 32)
23760 int i;
23761 rtx spe_save_area_ptr;
23762 HOST_WIDE_INT save_off;
23763 int ool_adjust = 0;
23765 /* Determine whether we can address all of the registers that need
23766 to be saved with an offset from frame_reg_rtx that fits in
23767 the small const field for SPE memory instructions. */
23768 int spe_regs_addressable
23769 = (SPE_CONST_OFFSET_OK (info->spe_gp_save_offset + frame_off
23770 + reg_size * (32 - info->first_gp_reg_save - 1))
23771 && (strategy & SAVE_INLINE_GPRS));
23773 if (spe_regs_addressable)
23775 spe_save_area_ptr = frame_reg_rtx;
23776 save_off = frame_off;
23778 else
23780 /* Make r11 point to the start of the SPE save area. We need
23781 to be careful here if r11 is holding the static chain. If
23782 it is, then temporarily save it in r0. */
23783 HOST_WIDE_INT offset;
23785 if (!(strategy & SAVE_INLINE_GPRS))
23786 ool_adjust = 8 * (info->first_gp_reg_save - FIRST_SAVED_GP_REGNO);
23787 offset = info->spe_gp_save_offset + frame_off - ool_adjust;
23788 spe_save_area_ptr = gen_rtx_REG (Pmode, 11);
23789 save_off = frame_off - offset;
23791 if (using_static_chain_p)
23793 rtx r0 = gen_rtx_REG (Pmode, 0);
23795 START_USE (0);
23796 gcc_assert (info->first_gp_reg_save > 11);
23798 emit_move_insn (r0, spe_save_area_ptr);
23800 else if (REGNO (frame_reg_rtx) != 11)
23801 START_USE (11);
23803 emit_insn (gen_addsi3 (spe_save_area_ptr,
23804 frame_reg_rtx, GEN_INT (offset)));
23805 if (!using_static_chain_p && REGNO (frame_reg_rtx) == 11)
23806 frame_off = -info->spe_gp_save_offset + ool_adjust;
23809 if ((strategy & SAVE_INLINE_GPRS))
23811 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
23812 if (rs6000_reg_live_or_pic_offset_p (info->first_gp_reg_save + i))
23813 emit_frame_save (spe_save_area_ptr, reg_mode,
23814 info->first_gp_reg_save + i,
23815 (info->spe_gp_save_offset + save_off
23816 + reg_size * i),
23817 sp_off - save_off);
23819 else
23821 insn = rs6000_emit_savres_rtx (info, spe_save_area_ptr,
23822 info->spe_gp_save_offset + save_off,
23823 0, reg_mode,
23824 SAVRES_SAVE | SAVRES_GPR);
23826 rs6000_frame_related (insn, spe_save_area_ptr, sp_off - save_off,
23827 NULL_RTX, NULL_RTX);
23830 /* Move the static chain pointer back. */
23831 if (!spe_regs_addressable)
23833 if (using_static_chain_p)
23835 emit_move_insn (spe_save_area_ptr, gen_rtx_REG (Pmode, 0));
23836 END_USE (0);
23838 else if (REGNO (frame_reg_rtx) != 11)
23839 END_USE (11);
23842 else if (!WORLD_SAVE_P (info) && !(strategy & SAVE_INLINE_GPRS))
23844 bool lr = (strategy & SAVE_NOINLINE_GPRS_SAVES_LR) != 0;
23845 int sel = SAVRES_SAVE | SAVRES_GPR | (lr ? SAVRES_LR : 0);
23846 unsigned ptr_regno = ptr_regno_for_savres (sel);
23847 rtx ptr_reg = frame_reg_rtx;
23848 bool ptr_set_up = REGNO (ptr_reg) == ptr_regno;
23849 int end_save = info->gp_save_offset + info->gp_size;
23850 int ptr_off;
23852 if (!ptr_set_up)
23853 ptr_reg = gen_rtx_REG (Pmode, ptr_regno);
23855 /* Need to adjust r11 (r12) if we saved any FPRs. */
23856 if (end_save + frame_off != 0)
23858 rtx offset = GEN_INT (end_save + frame_off);
23860 if (ptr_set_up)
23861 frame_off = -end_save;
23862 else
23863 NOT_INUSE (ptr_regno);
23864 emit_insn (gen_add3_insn (ptr_reg, frame_reg_rtx, offset));
23866 else if (!ptr_set_up)
23868 NOT_INUSE (ptr_regno);
23869 emit_move_insn (ptr_reg, frame_reg_rtx);
23871 ptr_off = -end_save;
23872 insn = rs6000_emit_savres_rtx (info, ptr_reg,
23873 info->gp_save_offset + ptr_off,
23874 info->lr_save_offset + ptr_off,
23875 reg_mode, sel);
23876 rs6000_frame_related (insn, ptr_reg, sp_off - ptr_off,
23877 NULL_RTX, NULL_RTX);
23878 if (lr)
23879 END_USE (0);
23881 else if (!WORLD_SAVE_P (info) && (strategy & SAVRES_MULTIPLE))
23883 rtvec p;
23884 int i;
23885 p = rtvec_alloc (32 - info->first_gp_reg_save);
23886 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
23887 RTVEC_ELT (p, i)
23888 = gen_frame_store (gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
23889 frame_reg_rtx,
23890 info->gp_save_offset + frame_off + reg_size * i);
23891 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
23892 rs6000_frame_related (insn, frame_reg_rtx, sp_off - frame_off,
23893 NULL_RTX, NULL_RTX);
23895 else if (!WORLD_SAVE_P (info))
23897 int i;
23898 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
23899 if (rs6000_reg_live_or_pic_offset_p (info->first_gp_reg_save + i))
23900 emit_frame_save (frame_reg_rtx, reg_mode,
23901 info->first_gp_reg_save + i,
23902 info->gp_save_offset + frame_off + reg_size * i,
23903 sp_off - frame_off);
23906 if (crtl->calls_eh_return)
23908 unsigned int i;
23909 rtvec p;
23911 for (i = 0; ; ++i)
23913 unsigned int regno = EH_RETURN_DATA_REGNO (i);
23914 if (regno == INVALID_REGNUM)
23915 break;
23918 p = rtvec_alloc (i);
23920 for (i = 0; ; ++i)
23922 unsigned int regno = EH_RETURN_DATA_REGNO (i);
23923 if (regno == INVALID_REGNUM)
23924 break;
23926 insn
23927 = gen_frame_store (gen_rtx_REG (reg_mode, regno),
23928 sp_reg_rtx,
23929 info->ehrd_offset + sp_off + reg_size * (int) i);
23930 RTVEC_ELT (p, i) = insn;
23931 RTX_FRAME_RELATED_P (insn) = 1;
23934 insn = emit_insn (gen_blockage ());
23935 RTX_FRAME_RELATED_P (insn) = 1;
23936 add_reg_note (insn, REG_FRAME_RELATED_EXPR, gen_rtx_PARALLEL (VOIDmode, p));
23939 /* In AIX ABI we need to make sure r2 is really saved. */
23940 if (TARGET_AIX && crtl->calls_eh_return)
23942 rtx tmp_reg, tmp_reg_si, hi, lo, compare_result, toc_save_done, jump;
23943 rtx save_insn, join_insn, note;
23944 long toc_restore_insn;
23946 tmp_reg = gen_rtx_REG (Pmode, 11);
23947 tmp_reg_si = gen_rtx_REG (SImode, 11);
23948 if (using_static_chain_p)
23950 START_USE (0);
23951 emit_move_insn (gen_rtx_REG (Pmode, 0), tmp_reg);
23953 else
23954 START_USE (11);
23955 emit_move_insn (tmp_reg, gen_rtx_REG (Pmode, LR_REGNO));
23956 /* Peek at instruction to which this function returns. If it's
23957 restoring r2, then we know we've already saved r2. We can't
23958 unconditionally save r2 because the value we have will already
23959 be updated if we arrived at this function via a plt call or
23960 toc adjusting stub. */
23961 emit_move_insn (tmp_reg_si, gen_rtx_MEM (SImode, tmp_reg));
23962 toc_restore_insn = ((TARGET_32BIT ? 0x80410000 : 0xE8410000)
23963 + RS6000_TOC_SAVE_SLOT);
23964 hi = gen_int_mode (toc_restore_insn & ~0xffff, SImode);
23965 emit_insn (gen_xorsi3 (tmp_reg_si, tmp_reg_si, hi));
23966 compare_result = gen_rtx_REG (CCUNSmode, CR0_REGNO);
23967 validate_condition_mode (EQ, CCUNSmode);
23968 lo = gen_int_mode (toc_restore_insn & 0xffff, SImode);
23969 emit_insn (gen_rtx_SET (compare_result,
23970 gen_rtx_COMPARE (CCUNSmode, tmp_reg_si, lo)));
23971 toc_save_done = gen_label_rtx ();
23972 jump = gen_rtx_IF_THEN_ELSE (VOIDmode,
23973 gen_rtx_EQ (VOIDmode, compare_result,
23974 const0_rtx),
23975 gen_rtx_LABEL_REF (VOIDmode, toc_save_done),
23976 pc_rtx);
23977 jump = emit_jump_insn (gen_rtx_SET (pc_rtx, jump));
23978 JUMP_LABEL (jump) = toc_save_done;
23979 LABEL_NUSES (toc_save_done) += 1;
23981 save_insn = emit_frame_save (frame_reg_rtx, reg_mode,
23982 TOC_REGNUM, frame_off + RS6000_TOC_SAVE_SLOT,
23983 sp_off - frame_off);
23985 emit_label (toc_save_done);
23987 /* ??? If we leave SAVE_INSN as marked as saving R2, then we'll
23988 have a CFG that has different saves along different paths.
23989 Move the note to a dummy blockage insn, which describes that
23990 R2 is unconditionally saved after the label. */
23991 /* ??? An alternate representation might be a special insn pattern
23992 containing both the branch and the store. That might let the
23993 code that minimizes the number of DW_CFA_advance opcodes better
23994 freedom in placing the annotations. */
23995 note = find_reg_note (save_insn, REG_FRAME_RELATED_EXPR, NULL);
23996 if (note)
23997 remove_note (save_insn, note);
23998 else
23999 note = alloc_reg_note (REG_FRAME_RELATED_EXPR,
24000 copy_rtx (PATTERN (save_insn)), NULL_RTX);
24001 RTX_FRAME_RELATED_P (save_insn) = 0;
24003 join_insn = emit_insn (gen_blockage ());
24004 REG_NOTES (join_insn) = note;
24005 RTX_FRAME_RELATED_P (join_insn) = 1;
24007 if (using_static_chain_p)
24009 emit_move_insn (tmp_reg, gen_rtx_REG (Pmode, 0));
24010 END_USE (0);
24012 else
24013 END_USE (11);
24016 /* Save CR if we use any that must be preserved. */
24017 if (!WORLD_SAVE_P (info) && info->cr_save_p)
24019 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
24020 GEN_INT (info->cr_save_offset + frame_off));
24021 rtx mem = gen_frame_mem (SImode, addr);
24023 /* If we didn't copy cr before, do so now using r0. */
24024 if (cr_save_rtx == NULL_RTX)
24026 START_USE (0);
24027 cr_save_rtx = gen_rtx_REG (SImode, 0);
24028 rs6000_emit_move_from_cr (cr_save_rtx);
24031 /* Saving CR requires a two-instruction sequence: one instruction
24032 to move the CR to a general-purpose register, and a second
24033 instruction that stores the GPR to memory.
24035 We do not emit any DWARF CFI records for the first of these,
24036 because we cannot properly represent the fact that CR is saved in
24037 a register. One reason is that we cannot express that multiple
24038 CR fields are saved; another reason is that on 64-bit, the size
24039 of the CR register in DWARF (4 bytes) differs from the size of
24040 a general-purpose register.
24042 This means if any intervening instruction were to clobber one of
24043 the call-saved CR fields, we'd have incorrect CFI. To prevent
24044 this from happening, we mark the store to memory as a use of
24045 those CR fields, which prevents any such instruction from being
24046 scheduled in between the two instructions. */
24047 rtx crsave_v[9];
24048 int n_crsave = 0;
24049 int i;
24051 crsave_v[n_crsave++] = gen_rtx_SET (mem, cr_save_rtx);
24052 for (i = 0; i < 8; i++)
24053 if (save_reg_p (CR0_REGNO + i))
24054 crsave_v[n_crsave++]
24055 = gen_rtx_USE (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO + i));
24057 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode,
24058 gen_rtvec_v (n_crsave, crsave_v)));
24059 END_USE (REGNO (cr_save_rtx));
24061 /* Now, there's no way that dwarf2out_frame_debug_expr is going to
24062 understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)',
24063 so we need to construct a frame expression manually. */
24064 RTX_FRAME_RELATED_P (insn) = 1;
24066 /* Update address to be stack-pointer relative, like
24067 rs6000_frame_related would do. */
24068 addr = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM),
24069 GEN_INT (info->cr_save_offset + sp_off));
24070 mem = gen_frame_mem (SImode, addr);
24072 if (DEFAULT_ABI == ABI_ELFv2)
24074 /* In the ELFv2 ABI we generate separate CFI records for each
24075 CR field that was actually saved. They all point to the
24076 same 32-bit stack slot. */
24077 rtx crframe[8];
24078 int n_crframe = 0;
24080 for (i = 0; i < 8; i++)
24081 if (save_reg_p (CR0_REGNO + i))
24083 crframe[n_crframe]
24084 = gen_rtx_SET (mem, gen_rtx_REG (SImode, CR0_REGNO + i));
24086 RTX_FRAME_RELATED_P (crframe[n_crframe]) = 1;
24087 n_crframe++;
24090 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
24091 gen_rtx_PARALLEL (VOIDmode,
24092 gen_rtvec_v (n_crframe, crframe)));
24094 else
24096 /* In other ABIs, by convention, we use a single CR regnum to
24097 represent the fact that all call-saved CR fields are saved.
24098 We use CR2_REGNO to be compatible with gcc-2.95 on Linux. */
24099 rtx set = gen_rtx_SET (mem, gen_rtx_REG (SImode, CR2_REGNO));
24100 add_reg_note (insn, REG_FRAME_RELATED_EXPR, set);
24104 /* In the ELFv2 ABI we need to save all call-saved CR fields into
24105 *separate* slots if the routine calls __builtin_eh_return, so
24106 that they can be independently restored by the unwinder. */
24107 if (DEFAULT_ABI == ABI_ELFv2 && crtl->calls_eh_return)
24109 int i, cr_off = info->ehcr_offset;
24110 rtx crsave;
24112 /* ??? We might get better performance by using multiple mfocrf
24113 instructions. */
24114 crsave = gen_rtx_REG (SImode, 0);
24115 emit_insn (gen_movesi_from_cr (crsave));
24117 for (i = 0; i < 8; i++)
24118 if (!call_used_regs[CR0_REGNO + i])
24120 rtvec p = rtvec_alloc (2);
24121 RTVEC_ELT (p, 0)
24122 = gen_frame_store (crsave, frame_reg_rtx, cr_off + frame_off);
24123 RTVEC_ELT (p, 1)
24124 = gen_rtx_USE (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO + i));
24126 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
24128 RTX_FRAME_RELATED_P (insn) = 1;
24129 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
24130 gen_frame_store (gen_rtx_REG (SImode, CR0_REGNO + i),
24131 sp_reg_rtx, cr_off + sp_off));
24133 cr_off += reg_size;
24137 /* Update stack and set back pointer unless this is V.4,
24138 for which it was done previously. */
24139 if (!WORLD_SAVE_P (info) && info->push_p
24140 && !(DEFAULT_ABI == ABI_V4 || crtl->calls_eh_return))
24142 rtx ptr_reg = NULL;
24143 int ptr_off = 0;
24145 /* If saving altivec regs we need to be able to address all save
24146 locations using a 16-bit offset. */
24147 if ((strategy & SAVE_INLINE_VRS) == 0
24148 || (info->altivec_size != 0
24149 && (info->altivec_save_offset + info->altivec_size - 16
24150 + info->total_size - frame_off) > 32767)
24151 || (info->vrsave_size != 0
24152 && (info->vrsave_save_offset
24153 + info->total_size - frame_off) > 32767))
24155 int sel = SAVRES_SAVE | SAVRES_VR;
24156 unsigned ptr_regno = ptr_regno_for_savres (sel);
24158 if (using_static_chain_p
24159 && ptr_regno == STATIC_CHAIN_REGNUM)
24160 ptr_regno = 12;
24161 if (REGNO (frame_reg_rtx) != ptr_regno)
24162 START_USE (ptr_regno);
24163 ptr_reg = gen_rtx_REG (Pmode, ptr_regno);
24164 frame_reg_rtx = ptr_reg;
24165 ptr_off = info->altivec_save_offset + info->altivec_size;
24166 frame_off = -ptr_off;
24168 else if (REGNO (frame_reg_rtx) == 1)
24169 frame_off = info->total_size;
24170 rs6000_emit_allocate_stack (info->total_size, ptr_reg, ptr_off);
24171 sp_off = info->total_size;
24172 if (frame_reg_rtx != sp_reg_rtx)
24173 rs6000_emit_stack_tie (frame_reg_rtx, false);
24176 /* Set frame pointer, if needed. */
24177 if (frame_pointer_needed)
24179 insn = emit_move_insn (gen_rtx_REG (Pmode, HARD_FRAME_POINTER_REGNUM),
24180 sp_reg_rtx);
24181 RTX_FRAME_RELATED_P (insn) = 1;
24184 /* Save AltiVec registers if needed. Save here because the red zone does
24185 not always include AltiVec registers. */
24186 if (!WORLD_SAVE_P (info)
24187 && info->altivec_size != 0 && (strategy & SAVE_INLINE_VRS) == 0)
24189 int end_save = info->altivec_save_offset + info->altivec_size;
24190 int ptr_off;
24191 /* Oddly, the vector save/restore functions point r0 at the end
24192 of the save area, then use r11 or r12 to load offsets for
24193 [reg+reg] addressing. */
24194 rtx ptr_reg = gen_rtx_REG (Pmode, 0);
24195 int scratch_regno = ptr_regno_for_savres (SAVRES_SAVE | SAVRES_VR);
24196 rtx scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
24198 gcc_checking_assert (scratch_regno == 11 || scratch_regno == 12);
24199 NOT_INUSE (0);
24200 if (end_save + frame_off != 0)
24202 rtx offset = GEN_INT (end_save + frame_off);
24204 emit_insn (gen_add3_insn (ptr_reg, frame_reg_rtx, offset));
24206 else
24207 emit_move_insn (ptr_reg, frame_reg_rtx);
24209 ptr_off = -end_save;
24210 insn = rs6000_emit_savres_rtx (info, scratch_reg,
24211 info->altivec_save_offset + ptr_off,
24212 0, V4SImode, SAVRES_SAVE | SAVRES_VR);
24213 rs6000_frame_related (insn, scratch_reg, sp_off - ptr_off,
24214 NULL_RTX, NULL_RTX);
24215 if (REGNO (frame_reg_rtx) == REGNO (scratch_reg))
24217 /* The oddity mentioned above clobbered our frame reg. */
24218 emit_move_insn (frame_reg_rtx, ptr_reg);
24219 frame_off = ptr_off;
24222 else if (!WORLD_SAVE_P (info)
24223 && info->altivec_size != 0)
24225 int i;
24227 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
24228 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
24230 rtx areg, savereg, mem;
24231 int offset;
24233 offset = (info->altivec_save_offset + frame_off
24234 + 16 * (i - info->first_altivec_reg_save));
24236 savereg = gen_rtx_REG (V4SImode, i);
24238 NOT_INUSE (0);
24239 areg = gen_rtx_REG (Pmode, 0);
24240 emit_move_insn (areg, GEN_INT (offset));
24242 /* AltiVec addressing mode is [reg+reg]. */
24243 mem = gen_frame_mem (V4SImode,
24244 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
24246 /* Rather than emitting a generic move, force use of the stvx
24247 instruction, which we always want. In particular we don't
24248 want xxpermdi/stxvd2x for little endian. */
24249 insn = emit_insn (gen_altivec_stvx_v4si_internal (mem, savereg));
24251 rs6000_frame_related (insn, frame_reg_rtx, sp_off - frame_off,
24252 areg, GEN_INT (offset));
24256 /* VRSAVE is a bit vector representing which AltiVec registers
24257 are used. The OS uses this to determine which vector
24258 registers to save on a context switch. We need to save
24259 VRSAVE on the stack frame, add whatever AltiVec registers we
24260 used in this function, and do the corresponding magic in the
24261 epilogue. */
24263 if (!WORLD_SAVE_P (info)
24264 && info->vrsave_size != 0)
24266 rtx reg, vrsave;
24267 int offset;
24268 int save_regno;
24270 /* Get VRSAVE onto a GPR. Note that ABI_V4 and ABI_DARWIN might
24271 be using r12 as frame_reg_rtx and r11 as the static chain
24272 pointer for nested functions. */
24273 save_regno = 12;
24274 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
24275 && !using_static_chain_p)
24276 save_regno = 11;
24277 else if (REGNO (frame_reg_rtx) == 12)
24279 save_regno = 11;
24280 if (using_static_chain_p)
24281 save_regno = 0;
24284 NOT_INUSE (save_regno);
24285 reg = gen_rtx_REG (SImode, save_regno);
24286 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
24287 if (TARGET_MACHO)
24288 emit_insn (gen_get_vrsave_internal (reg));
24289 else
24290 emit_insn (gen_rtx_SET (reg, vrsave));
24292 /* Save VRSAVE. */
24293 offset = info->vrsave_save_offset + frame_off;
24294 insn = emit_insn (gen_frame_store (reg, frame_reg_rtx, offset));
24296 /* Include the registers in the mask. */
24297 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
24299 insn = emit_insn (generate_set_vrsave (reg, info, 0));
24302 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
24303 if (!TARGET_SINGLE_PIC_BASE
24304 && ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
24305 || (DEFAULT_ABI == ABI_V4
24306 && (flag_pic == 1 || (flag_pic && TARGET_SECURE_PLT))
24307 && df_regs_ever_live_p (RS6000_PIC_OFFSET_TABLE_REGNUM))))
24309 /* If emit_load_toc_table will use the link register, we need to save
24310 it. We use R12 for this purpose because emit_load_toc_table
24311 can use register 0. This allows us to use a plain 'blr' to return
24312 from the procedure more often. */
24313 int save_LR_around_toc_setup = (TARGET_ELF
24314 && DEFAULT_ABI == ABI_V4
24315 && flag_pic
24316 && ! info->lr_save_p
24317 && EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) > 0);
24318 if (save_LR_around_toc_setup)
24320 rtx lr = gen_rtx_REG (Pmode, LR_REGNO);
24321 rtx tmp = gen_rtx_REG (Pmode, 12);
24323 insn = emit_move_insn (tmp, lr);
24324 RTX_FRAME_RELATED_P (insn) = 1;
24326 rs6000_emit_load_toc_table (TRUE);
24328 insn = emit_move_insn (lr, tmp);
24329 add_reg_note (insn, REG_CFA_RESTORE, lr);
24330 RTX_FRAME_RELATED_P (insn) = 1;
24332 else
24333 rs6000_emit_load_toc_table (TRUE);
24336 #if TARGET_MACHO
24337 if (!TARGET_SINGLE_PIC_BASE
24338 && DEFAULT_ABI == ABI_DARWIN
24339 && flag_pic && crtl->uses_pic_offset_table)
24341 rtx lr = gen_rtx_REG (Pmode, LR_REGNO);
24342 rtx src = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
24344 /* Save and restore LR locally around this call (in R0). */
24345 if (!info->lr_save_p)
24346 emit_move_insn (gen_rtx_REG (Pmode, 0), lr);
24348 emit_insn (gen_load_macho_picbase (src));
24350 emit_move_insn (gen_rtx_REG (Pmode,
24351 RS6000_PIC_OFFSET_TABLE_REGNUM),
24352 lr);
24354 if (!info->lr_save_p)
24355 emit_move_insn (lr, gen_rtx_REG (Pmode, 0));
24357 #endif
24359 /* If we need to, save the TOC register after doing the stack setup.
24360 Do not emit eh frame info for this save. The unwinder wants info,
24361 conceptually attached to instructions in this function, about
24362 register values in the caller of this function. This R2 may have
24363 already been changed from the value in the caller.
24364 We don't attempt to write accurate DWARF EH frame info for R2
24365 because code emitted by gcc for a (non-pointer) function call
24366 doesn't save and restore R2. Instead, R2 is managed out-of-line
24367 by a linker generated plt call stub when the function resides in
24368 a shared library. This behaviour is costly to describe in DWARF,
24369 both in terms of the size of DWARF info and the time taken in the
24370 unwinder to interpret it. R2 changes, apart from the
24371 calls_eh_return case earlier in this function, are handled by
24372 linux-unwind.h frob_update_context. */
24373 if (rs6000_save_toc_in_prologue_p ())
24375 rtx reg = gen_rtx_REG (reg_mode, TOC_REGNUM);
24376 emit_insn (gen_frame_store (reg, sp_reg_rtx, RS6000_TOC_SAVE_SLOT));
24380 /* Output .extern statements for the save/restore routines we use. */
24382 static void
24383 rs6000_output_savres_externs (FILE *file)
24385 rs6000_stack_t *info = rs6000_stack_info ();
24387 if (TARGET_DEBUG_STACK)
24388 debug_stack_info (info);
24390 /* Write .extern for any function we will call to save and restore
24391 fp values. */
24392 if (info->first_fp_reg_save < 64
24393 && !TARGET_MACHO
24394 && !TARGET_ELF)
24396 char *name;
24397 int regno = info->first_fp_reg_save - 32;
24399 if ((info->savres_strategy & SAVE_INLINE_FPRS) == 0)
24401 bool lr = (info->savres_strategy & SAVE_NOINLINE_FPRS_SAVES_LR) != 0;
24402 int sel = SAVRES_SAVE | SAVRES_FPR | (lr ? SAVRES_LR : 0);
24403 name = rs6000_savres_routine_name (info, regno, sel);
24404 fprintf (file, "\t.extern %s\n", name);
24406 if ((info->savres_strategy & REST_INLINE_FPRS) == 0)
24408 bool lr = (info->savres_strategy
24409 & REST_NOINLINE_FPRS_DOESNT_RESTORE_LR) == 0;
24410 int sel = SAVRES_FPR | (lr ? SAVRES_LR : 0);
24411 name = rs6000_savres_routine_name (info, regno, sel);
24412 fprintf (file, "\t.extern %s\n", name);
24417 /* Write function prologue. */
24419 static void
24420 rs6000_output_function_prologue (FILE *file,
24421 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
24423 if (!cfun->is_thunk)
24424 rs6000_output_savres_externs (file);
24426 /* ELFv2 ABI r2 setup code and local entry point. This must follow
24427 immediately after the global entry point label. */
24428 if (DEFAULT_ABI == ABI_ELFv2 && cfun->machine->r2_setup_needed)
24430 const char *name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
24432 fprintf (file, "0:\taddis 2,12,.TOC.-0b@ha\n");
24433 fprintf (file, "\taddi 2,2,.TOC.-0b@l\n");
24435 fputs ("\t.localentry\t", file);
24436 assemble_name (file, name);
24437 fputs (",.-", file);
24438 assemble_name (file, name);
24439 fputs ("\n", file);
24442 /* Output -mprofile-kernel code. This needs to be done here instead of
24443 in output_function_profile since it must go after the ELFv2 ABI
24444 local entry point. */
24445 if (TARGET_PROFILE_KERNEL && crtl->profile)
24447 gcc_assert (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2);
24448 gcc_assert (!TARGET_32BIT);
24450 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
24452 /* In the ELFv2 ABI we have no compiler stack word. It must be
24453 the resposibility of _mcount to preserve the static chain
24454 register if required. */
24455 if (DEFAULT_ABI != ABI_ELFv2
24456 && cfun->static_chain_decl != NULL)
24458 asm_fprintf (file, "\tstd %s,24(%s)\n",
24459 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
24460 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
24461 asm_fprintf (file, "\tld %s,24(%s)\n",
24462 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
24464 else
24465 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
24468 rs6000_pic_labelno++;
24471 /* Non-zero if vmx regs are restored before the frame pop, zero if
24472 we restore after the pop when possible. */
24473 #define ALWAYS_RESTORE_ALTIVEC_BEFORE_POP 0
24475 /* Restoring cr is a two step process: loading a reg from the frame
24476 save, then moving the reg to cr. For ABI_V4 we must let the
24477 unwinder know that the stack location is no longer valid at or
24478 before the stack deallocation, but we can't emit a cfa_restore for
24479 cr at the stack deallocation like we do for other registers.
24480 The trouble is that it is possible for the move to cr to be
24481 scheduled after the stack deallocation. So say exactly where cr
24482 is located on each of the two insns. */
24484 static rtx
24485 load_cr_save (int regno, rtx frame_reg_rtx, int offset, bool exit_func)
24487 rtx mem = gen_frame_mem_offset (SImode, frame_reg_rtx, offset);
24488 rtx reg = gen_rtx_REG (SImode, regno);
24489 rtx_insn *insn = emit_move_insn (reg, mem);
24491 if (!exit_func && DEFAULT_ABI == ABI_V4)
24493 rtx cr = gen_rtx_REG (SImode, CR2_REGNO);
24494 rtx set = gen_rtx_SET (reg, cr);
24496 add_reg_note (insn, REG_CFA_REGISTER, set);
24497 RTX_FRAME_RELATED_P (insn) = 1;
24499 return reg;
24502 /* Reload CR from REG. */
24504 static void
24505 restore_saved_cr (rtx reg, int using_mfcr_multiple, bool exit_func)
24507 int count = 0;
24508 int i;
24510 if (using_mfcr_multiple)
24512 for (i = 0; i < 8; i++)
24513 if (save_reg_p (CR0_REGNO + i))
24514 count++;
24515 gcc_assert (count);
24518 if (using_mfcr_multiple && count > 1)
24520 rtx_insn *insn;
24521 rtvec p;
24522 int ndx;
24524 p = rtvec_alloc (count);
24526 ndx = 0;
24527 for (i = 0; i < 8; i++)
24528 if (save_reg_p (CR0_REGNO + i))
24530 rtvec r = rtvec_alloc (2);
24531 RTVEC_ELT (r, 0) = reg;
24532 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
24533 RTVEC_ELT (p, ndx) =
24534 gen_rtx_SET (gen_rtx_REG (CCmode, CR0_REGNO + i),
24535 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
24536 ndx++;
24538 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
24539 gcc_assert (ndx == count);
24541 /* For the ELFv2 ABI we generate a CFA_RESTORE for each
24542 CR field separately. */
24543 if (!exit_func && DEFAULT_ABI == ABI_ELFv2 && flag_shrink_wrap)
24545 for (i = 0; i < 8; i++)
24546 if (save_reg_p (CR0_REGNO + i))
24547 add_reg_note (insn, REG_CFA_RESTORE,
24548 gen_rtx_REG (SImode, CR0_REGNO + i));
24550 RTX_FRAME_RELATED_P (insn) = 1;
24553 else
24554 for (i = 0; i < 8; i++)
24555 if (save_reg_p (CR0_REGNO + i))
24557 rtx insn = emit_insn (gen_movsi_to_cr_one
24558 (gen_rtx_REG (CCmode, CR0_REGNO + i), reg));
24560 /* For the ELFv2 ABI we generate a CFA_RESTORE for each
24561 CR field separately, attached to the insn that in fact
24562 restores this particular CR field. */
24563 if (!exit_func && DEFAULT_ABI == ABI_ELFv2 && flag_shrink_wrap)
24565 add_reg_note (insn, REG_CFA_RESTORE,
24566 gen_rtx_REG (SImode, CR0_REGNO + i));
24568 RTX_FRAME_RELATED_P (insn) = 1;
24572 /* For other ABIs, we just generate a single CFA_RESTORE for CR2. */
24573 if (!exit_func && DEFAULT_ABI != ABI_ELFv2
24574 && (DEFAULT_ABI == ABI_V4 || flag_shrink_wrap))
24576 rtx_insn *insn = get_last_insn ();
24577 rtx cr = gen_rtx_REG (SImode, CR2_REGNO);
24579 add_reg_note (insn, REG_CFA_RESTORE, cr);
24580 RTX_FRAME_RELATED_P (insn) = 1;
24584 /* Like cr, the move to lr instruction can be scheduled after the
24585 stack deallocation, but unlike cr, its stack frame save is still
24586 valid. So we only need to emit the cfa_restore on the correct
24587 instruction. */
24589 static void
24590 load_lr_save (int regno, rtx frame_reg_rtx, int offset)
24592 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx, offset);
24593 rtx reg = gen_rtx_REG (Pmode, regno);
24595 emit_move_insn (reg, mem);
24598 static void
24599 restore_saved_lr (int regno, bool exit_func)
24601 rtx reg = gen_rtx_REG (Pmode, regno);
24602 rtx lr = gen_rtx_REG (Pmode, LR_REGNO);
24603 rtx_insn *insn = emit_move_insn (lr, reg);
24605 if (!exit_func && flag_shrink_wrap)
24607 add_reg_note (insn, REG_CFA_RESTORE, lr);
24608 RTX_FRAME_RELATED_P (insn) = 1;
24612 static rtx
24613 add_crlr_cfa_restore (const rs6000_stack_t *info, rtx cfa_restores)
24615 if (DEFAULT_ABI == ABI_ELFv2)
24617 int i;
24618 for (i = 0; i < 8; i++)
24619 if (save_reg_p (CR0_REGNO + i))
24621 rtx cr = gen_rtx_REG (SImode, CR0_REGNO + i);
24622 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, cr,
24623 cfa_restores);
24626 else if (info->cr_save_p)
24627 cfa_restores = alloc_reg_note (REG_CFA_RESTORE,
24628 gen_rtx_REG (SImode, CR2_REGNO),
24629 cfa_restores);
24631 if (info->lr_save_p)
24632 cfa_restores = alloc_reg_note (REG_CFA_RESTORE,
24633 gen_rtx_REG (Pmode, LR_REGNO),
24634 cfa_restores);
24635 return cfa_restores;
24638 /* Return true if OFFSET from stack pointer can be clobbered by signals.
24639 V.4 doesn't have any stack cushion, AIX ABIs have 220 or 288 bytes
24640 below stack pointer not cloberred by signals. */
24642 static inline bool
24643 offset_below_red_zone_p (HOST_WIDE_INT offset)
24645 return offset < (DEFAULT_ABI == ABI_V4
24647 : TARGET_32BIT ? -220 : -288);
24650 /* Append CFA_RESTORES to any existing REG_NOTES on the last insn. */
24652 static void
24653 emit_cfa_restores (rtx cfa_restores)
24655 rtx_insn *insn = get_last_insn ();
24656 rtx *loc = &REG_NOTES (insn);
24658 while (*loc)
24659 loc = &XEXP (*loc, 1);
24660 *loc = cfa_restores;
24661 RTX_FRAME_RELATED_P (insn) = 1;
24664 /* Emit function epilogue as insns. */
24666 void
24667 rs6000_emit_epilogue (int sibcall)
24669 rs6000_stack_t *info;
24670 int restoring_GPRs_inline;
24671 int restoring_FPRs_inline;
24672 int using_load_multiple;
24673 int using_mtcr_multiple;
24674 int use_backchain_to_restore_sp;
24675 int restore_lr;
24676 int strategy;
24677 HOST_WIDE_INT frame_off = 0;
24678 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
24679 rtx frame_reg_rtx = sp_reg_rtx;
24680 rtx cfa_restores = NULL_RTX;
24681 rtx insn;
24682 rtx cr_save_reg = NULL_RTX;
24683 machine_mode reg_mode = Pmode;
24684 int reg_size = TARGET_32BIT ? 4 : 8;
24685 int i;
24686 bool exit_func;
24687 unsigned ptr_regno;
24689 info = rs6000_stack_info ();
24691 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
24693 reg_mode = V2SImode;
24694 reg_size = 8;
24697 strategy = info->savres_strategy;
24698 using_load_multiple = strategy & SAVRES_MULTIPLE;
24699 restoring_FPRs_inline = sibcall || (strategy & REST_INLINE_FPRS);
24700 restoring_GPRs_inline = sibcall || (strategy & REST_INLINE_GPRS);
24701 using_mtcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
24702 || rs6000_cpu == PROCESSOR_PPC603
24703 || rs6000_cpu == PROCESSOR_PPC750
24704 || optimize_size);
24705 /* Restore via the backchain when we have a large frame, since this
24706 is more efficient than an addis, addi pair. The second condition
24707 here will not trigger at the moment; We don't actually need a
24708 frame pointer for alloca, but the generic parts of the compiler
24709 give us one anyway. */
24710 use_backchain_to_restore_sp = (info->total_size + (info->lr_save_p
24711 ? info->lr_save_offset
24712 : 0) > 32767
24713 || (cfun->calls_alloca
24714 && !frame_pointer_needed));
24715 restore_lr = (info->lr_save_p
24716 && (restoring_FPRs_inline
24717 || (strategy & REST_NOINLINE_FPRS_DOESNT_RESTORE_LR))
24718 && (restoring_GPRs_inline
24719 || info->first_fp_reg_save < 64));
24721 if (WORLD_SAVE_P (info))
24723 int i, j;
24724 char rname[30];
24725 const char *alloc_rname;
24726 rtvec p;
24728 /* eh_rest_world_r10 will return to the location saved in the LR
24729 stack slot (which is not likely to be our caller.)
24730 Input: R10 -- stack adjustment. Clobbers R0, R11, R12, R7, R8.
24731 rest_world is similar, except any R10 parameter is ignored.
24732 The exception-handling stuff that was here in 2.95 is no
24733 longer necessary. */
24735 p = rtvec_alloc (9
24737 + 32 - info->first_gp_reg_save
24738 + LAST_ALTIVEC_REGNO + 1 - info->first_altivec_reg_save
24739 + 63 + 1 - info->first_fp_reg_save);
24741 strcpy (rname, ((crtl->calls_eh_return) ?
24742 "*eh_rest_world_r10" : "*rest_world"));
24743 alloc_rname = ggc_strdup (rname);
24745 j = 0;
24746 RTVEC_ELT (p, j++) = ret_rtx;
24747 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
24748 gen_rtx_REG (Pmode,
24749 LR_REGNO));
24750 RTVEC_ELT (p, j++)
24751 = gen_rtx_USE (VOIDmode, gen_rtx_SYMBOL_REF (Pmode, alloc_rname));
24752 /* The instruction pattern requires a clobber here;
24753 it is shared with the restVEC helper. */
24754 RTVEC_ELT (p, j++)
24755 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
24758 /* CR register traditionally saved as CR2. */
24759 rtx reg = gen_rtx_REG (SImode, CR2_REGNO);
24760 RTVEC_ELT (p, j++)
24761 = gen_frame_load (reg, frame_reg_rtx, info->cr_save_offset);
24762 if (flag_shrink_wrap)
24764 cfa_restores = alloc_reg_note (REG_CFA_RESTORE,
24765 gen_rtx_REG (Pmode, LR_REGNO),
24766 cfa_restores);
24767 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
24771 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
24773 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
24774 RTVEC_ELT (p, j++)
24775 = gen_frame_load (reg,
24776 frame_reg_rtx, info->gp_save_offset + reg_size * i);
24777 if (flag_shrink_wrap)
24778 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
24780 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
24782 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
24783 RTVEC_ELT (p, j++)
24784 = gen_frame_load (reg,
24785 frame_reg_rtx, info->altivec_save_offset + 16 * i);
24786 if (flag_shrink_wrap)
24787 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
24789 for (i = 0; info->first_fp_reg_save + i <= 63; i++)
24791 rtx reg = gen_rtx_REG ((TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
24792 ? DFmode : SFmode),
24793 info->first_fp_reg_save + i);
24794 RTVEC_ELT (p, j++)
24795 = gen_frame_load (reg, frame_reg_rtx, info->fp_save_offset + 8 * i);
24796 if (flag_shrink_wrap)
24797 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
24799 RTVEC_ELT (p, j++)
24800 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 0));
24801 RTVEC_ELT (p, j++)
24802 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 12));
24803 RTVEC_ELT (p, j++)
24804 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 7));
24805 RTVEC_ELT (p, j++)
24806 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 8));
24807 RTVEC_ELT (p, j++)
24808 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 10));
24809 insn = emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
24811 if (flag_shrink_wrap)
24813 REG_NOTES (insn) = cfa_restores;
24814 add_reg_note (insn, REG_CFA_DEF_CFA, sp_reg_rtx);
24815 RTX_FRAME_RELATED_P (insn) = 1;
24817 return;
24820 /* frame_reg_rtx + frame_off points to the top of this stack frame. */
24821 if (info->push_p)
24822 frame_off = info->total_size;
24824 /* Restore AltiVec registers if we must do so before adjusting the
24825 stack. */
24826 if (info->altivec_size != 0
24827 && (ALWAYS_RESTORE_ALTIVEC_BEFORE_POP
24828 || (DEFAULT_ABI != ABI_V4
24829 && offset_below_red_zone_p (info->altivec_save_offset))))
24831 int i;
24832 int scratch_regno = ptr_regno_for_savres (SAVRES_VR);
24834 gcc_checking_assert (scratch_regno == 11 || scratch_regno == 12);
24835 if (use_backchain_to_restore_sp)
24837 int frame_regno = 11;
24839 if ((strategy & REST_INLINE_VRS) == 0)
24841 /* Of r11 and r12, select the one not clobbered by an
24842 out-of-line restore function for the frame register. */
24843 frame_regno = 11 + 12 - scratch_regno;
24845 frame_reg_rtx = gen_rtx_REG (Pmode, frame_regno);
24846 emit_move_insn (frame_reg_rtx,
24847 gen_rtx_MEM (Pmode, sp_reg_rtx));
24848 frame_off = 0;
24850 else if (frame_pointer_needed)
24851 frame_reg_rtx = hard_frame_pointer_rtx;
24853 if ((strategy & REST_INLINE_VRS) == 0)
24855 int end_save = info->altivec_save_offset + info->altivec_size;
24856 int ptr_off;
24857 rtx ptr_reg = gen_rtx_REG (Pmode, 0);
24858 rtx scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
24860 if (end_save + frame_off != 0)
24862 rtx offset = GEN_INT (end_save + frame_off);
24864 emit_insn (gen_add3_insn (ptr_reg, frame_reg_rtx, offset));
24866 else
24867 emit_move_insn (ptr_reg, frame_reg_rtx);
24869 ptr_off = -end_save;
24870 insn = rs6000_emit_savres_rtx (info, scratch_reg,
24871 info->altivec_save_offset + ptr_off,
24872 0, V4SImode, SAVRES_VR);
24874 else
24876 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
24877 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
24879 rtx addr, areg, mem, reg;
24881 areg = gen_rtx_REG (Pmode, 0);
24882 emit_move_insn
24883 (areg, GEN_INT (info->altivec_save_offset
24884 + frame_off
24885 + 16 * (i - info->first_altivec_reg_save)));
24887 /* AltiVec addressing mode is [reg+reg]. */
24888 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
24889 mem = gen_frame_mem (V4SImode, addr);
24891 reg = gen_rtx_REG (V4SImode, i);
24892 /* Rather than emitting a generic move, force use of the
24893 lvx instruction, which we always want. In particular
24894 we don't want lxvd2x/xxpermdi for little endian. */
24895 (void) emit_insn (gen_altivec_lvx_v4si_internal (reg, mem));
24899 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
24900 if (((strategy & REST_INLINE_VRS) == 0
24901 || (info->vrsave_mask & ALTIVEC_REG_BIT (i)) != 0)
24902 && (flag_shrink_wrap
24903 || (offset_below_red_zone_p
24904 (info->altivec_save_offset
24905 + 16 * (i - info->first_altivec_reg_save)))))
24907 rtx reg = gen_rtx_REG (V4SImode, i);
24908 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
24912 /* Restore VRSAVE if we must do so before adjusting the stack. */
24913 if (info->vrsave_size != 0
24914 && (ALWAYS_RESTORE_ALTIVEC_BEFORE_POP
24915 || (DEFAULT_ABI != ABI_V4
24916 && offset_below_red_zone_p (info->vrsave_save_offset))))
24918 rtx reg;
24920 if (frame_reg_rtx == sp_reg_rtx)
24922 if (use_backchain_to_restore_sp)
24924 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
24925 emit_move_insn (frame_reg_rtx,
24926 gen_rtx_MEM (Pmode, sp_reg_rtx));
24927 frame_off = 0;
24929 else if (frame_pointer_needed)
24930 frame_reg_rtx = hard_frame_pointer_rtx;
24933 reg = gen_rtx_REG (SImode, 12);
24934 emit_insn (gen_frame_load (reg, frame_reg_rtx,
24935 info->vrsave_save_offset + frame_off));
24937 emit_insn (generate_set_vrsave (reg, info, 1));
24940 insn = NULL_RTX;
24941 /* If we have a large stack frame, restore the old stack pointer
24942 using the backchain. */
24943 if (use_backchain_to_restore_sp)
24945 if (frame_reg_rtx == sp_reg_rtx)
24947 /* Under V.4, don't reset the stack pointer until after we're done
24948 loading the saved registers. */
24949 if (DEFAULT_ABI == ABI_V4)
24950 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
24952 insn = emit_move_insn (frame_reg_rtx,
24953 gen_rtx_MEM (Pmode, sp_reg_rtx));
24954 frame_off = 0;
24956 else if (ALWAYS_RESTORE_ALTIVEC_BEFORE_POP
24957 && DEFAULT_ABI == ABI_V4)
24958 /* frame_reg_rtx has been set up by the altivec restore. */
24960 else
24962 insn = emit_move_insn (sp_reg_rtx, frame_reg_rtx);
24963 frame_reg_rtx = sp_reg_rtx;
24966 /* If we have a frame pointer, we can restore the old stack pointer
24967 from it. */
24968 else if (frame_pointer_needed)
24970 frame_reg_rtx = sp_reg_rtx;
24971 if (DEFAULT_ABI == ABI_V4)
24972 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
24973 /* Prevent reordering memory accesses against stack pointer restore. */
24974 else if (cfun->calls_alloca
24975 || offset_below_red_zone_p (-info->total_size))
24976 rs6000_emit_stack_tie (frame_reg_rtx, true);
24978 insn = emit_insn (gen_add3_insn (frame_reg_rtx, hard_frame_pointer_rtx,
24979 GEN_INT (info->total_size)));
24980 frame_off = 0;
24982 else if (info->push_p
24983 && DEFAULT_ABI != ABI_V4
24984 && !crtl->calls_eh_return)
24986 /* Prevent reordering memory accesses against stack pointer restore. */
24987 if (cfun->calls_alloca
24988 || offset_below_red_zone_p (-info->total_size))
24989 rs6000_emit_stack_tie (frame_reg_rtx, false);
24990 insn = emit_insn (gen_add3_insn (sp_reg_rtx, sp_reg_rtx,
24991 GEN_INT (info->total_size)));
24992 frame_off = 0;
24994 if (insn && frame_reg_rtx == sp_reg_rtx)
24996 if (cfa_restores)
24998 REG_NOTES (insn) = cfa_restores;
24999 cfa_restores = NULL_RTX;
25001 add_reg_note (insn, REG_CFA_DEF_CFA, sp_reg_rtx);
25002 RTX_FRAME_RELATED_P (insn) = 1;
25005 /* Restore AltiVec registers if we have not done so already. */
25006 if (!ALWAYS_RESTORE_ALTIVEC_BEFORE_POP
25007 && info->altivec_size != 0
25008 && (DEFAULT_ABI == ABI_V4
25009 || !offset_below_red_zone_p (info->altivec_save_offset)))
25011 int i;
25013 if ((strategy & REST_INLINE_VRS) == 0)
25015 int end_save = info->altivec_save_offset + info->altivec_size;
25016 int ptr_off;
25017 rtx ptr_reg = gen_rtx_REG (Pmode, 0);
25018 int scratch_regno = ptr_regno_for_savres (SAVRES_VR);
25019 rtx scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
25021 if (end_save + frame_off != 0)
25023 rtx offset = GEN_INT (end_save + frame_off);
25025 emit_insn (gen_add3_insn (ptr_reg, frame_reg_rtx, offset));
25027 else
25028 emit_move_insn (ptr_reg, frame_reg_rtx);
25030 ptr_off = -end_save;
25031 insn = rs6000_emit_savres_rtx (info, scratch_reg,
25032 info->altivec_save_offset + ptr_off,
25033 0, V4SImode, SAVRES_VR);
25034 if (REGNO (frame_reg_rtx) == REGNO (scratch_reg))
25036 /* Frame reg was clobbered by out-of-line save. Restore it
25037 from ptr_reg, and if we are calling out-of-line gpr or
25038 fpr restore set up the correct pointer and offset. */
25039 unsigned newptr_regno = 1;
25040 if (!restoring_GPRs_inline)
25042 bool lr = info->gp_save_offset + info->gp_size == 0;
25043 int sel = SAVRES_GPR | (lr ? SAVRES_LR : 0);
25044 newptr_regno = ptr_regno_for_savres (sel);
25045 end_save = info->gp_save_offset + info->gp_size;
25047 else if (!restoring_FPRs_inline)
25049 bool lr = !(strategy & REST_NOINLINE_FPRS_DOESNT_RESTORE_LR);
25050 int sel = SAVRES_FPR | (lr ? SAVRES_LR : 0);
25051 newptr_regno = ptr_regno_for_savres (sel);
25052 end_save = info->fp_save_offset + info->fp_size;
25055 if (newptr_regno != 1 && REGNO (frame_reg_rtx) != newptr_regno)
25056 frame_reg_rtx = gen_rtx_REG (Pmode, newptr_regno);
25058 if (end_save + ptr_off != 0)
25060 rtx offset = GEN_INT (end_save + ptr_off);
25062 frame_off = -end_save;
25063 if (TARGET_32BIT)
25064 emit_insn (gen_addsi3_carry (frame_reg_rtx,
25065 ptr_reg, offset));
25066 else
25067 emit_insn (gen_adddi3_carry (frame_reg_rtx,
25068 ptr_reg, offset));
25070 else
25072 frame_off = ptr_off;
25073 emit_move_insn (frame_reg_rtx, ptr_reg);
25077 else
25079 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
25080 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
25082 rtx addr, areg, mem, reg;
25084 areg = gen_rtx_REG (Pmode, 0);
25085 emit_move_insn
25086 (areg, GEN_INT (info->altivec_save_offset
25087 + frame_off
25088 + 16 * (i - info->first_altivec_reg_save)));
25090 /* AltiVec addressing mode is [reg+reg]. */
25091 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
25092 mem = gen_frame_mem (V4SImode, addr);
25094 reg = gen_rtx_REG (V4SImode, i);
25095 /* Rather than emitting a generic move, force use of the
25096 lvx instruction, which we always want. In particular
25097 we don't want lxvd2x/xxpermdi for little endian. */
25098 (void) emit_insn (gen_altivec_lvx_v4si_internal (reg, mem));
25102 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
25103 if (((strategy & REST_INLINE_VRS) == 0
25104 || (info->vrsave_mask & ALTIVEC_REG_BIT (i)) != 0)
25105 && (DEFAULT_ABI == ABI_V4 || flag_shrink_wrap))
25107 rtx reg = gen_rtx_REG (V4SImode, i);
25108 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
25112 /* Restore VRSAVE if we have not done so already. */
25113 if (!ALWAYS_RESTORE_ALTIVEC_BEFORE_POP
25114 && info->vrsave_size != 0
25115 && (DEFAULT_ABI == ABI_V4
25116 || !offset_below_red_zone_p (info->vrsave_save_offset)))
25118 rtx reg;
25120 reg = gen_rtx_REG (SImode, 12);
25121 emit_insn (gen_frame_load (reg, frame_reg_rtx,
25122 info->vrsave_save_offset + frame_off));
25124 emit_insn (generate_set_vrsave (reg, info, 1));
25127 /* If we exit by an out-of-line restore function on ABI_V4 then that
25128 function will deallocate the stack, so we don't need to worry
25129 about the unwinder restoring cr from an invalid stack frame
25130 location. */
25131 exit_func = (!restoring_FPRs_inline
25132 || (!restoring_GPRs_inline
25133 && info->first_fp_reg_save == 64));
25135 /* In the ELFv2 ABI we need to restore all call-saved CR fields from
25136 *separate* slots if the routine calls __builtin_eh_return, so
25137 that they can be independently restored by the unwinder. */
25138 if (DEFAULT_ABI == ABI_ELFv2 && crtl->calls_eh_return)
25140 int i, cr_off = info->ehcr_offset;
25142 for (i = 0; i < 8; i++)
25143 if (!call_used_regs[CR0_REGNO + i])
25145 rtx reg = gen_rtx_REG (SImode, 0);
25146 emit_insn (gen_frame_load (reg, frame_reg_rtx,
25147 cr_off + frame_off));
25149 insn = emit_insn (gen_movsi_to_cr_one
25150 (gen_rtx_REG (CCmode, CR0_REGNO + i), reg));
25152 if (!exit_func && flag_shrink_wrap)
25154 add_reg_note (insn, REG_CFA_RESTORE,
25155 gen_rtx_REG (SImode, CR0_REGNO + i));
25157 RTX_FRAME_RELATED_P (insn) = 1;
25160 cr_off += reg_size;
25164 /* Get the old lr if we saved it. If we are restoring registers
25165 out-of-line, then the out-of-line routines can do this for us. */
25166 if (restore_lr && restoring_GPRs_inline)
25167 load_lr_save (0, frame_reg_rtx, info->lr_save_offset + frame_off);
25169 /* Get the old cr if we saved it. */
25170 if (info->cr_save_p)
25172 unsigned cr_save_regno = 12;
25174 if (!restoring_GPRs_inline)
25176 /* Ensure we don't use the register used by the out-of-line
25177 gpr register restore below. */
25178 bool lr = info->gp_save_offset + info->gp_size == 0;
25179 int sel = SAVRES_GPR | (lr ? SAVRES_LR : 0);
25180 int gpr_ptr_regno = ptr_regno_for_savres (sel);
25182 if (gpr_ptr_regno == 12)
25183 cr_save_regno = 11;
25184 gcc_checking_assert (REGNO (frame_reg_rtx) != cr_save_regno);
25186 else if (REGNO (frame_reg_rtx) == 12)
25187 cr_save_regno = 11;
25189 cr_save_reg = load_cr_save (cr_save_regno, frame_reg_rtx,
25190 info->cr_save_offset + frame_off,
25191 exit_func);
25194 /* Set LR here to try to overlap restores below. */
25195 if (restore_lr && restoring_GPRs_inline)
25196 restore_saved_lr (0, exit_func);
25198 /* Load exception handler data registers, if needed. */
25199 if (crtl->calls_eh_return)
25201 unsigned int i, regno;
25203 if (TARGET_AIX)
25205 rtx reg = gen_rtx_REG (reg_mode, 2);
25206 emit_insn (gen_frame_load (reg, frame_reg_rtx,
25207 frame_off + RS6000_TOC_SAVE_SLOT));
25210 for (i = 0; ; ++i)
25212 rtx mem;
25214 regno = EH_RETURN_DATA_REGNO (i);
25215 if (regno == INVALID_REGNUM)
25216 break;
25218 /* Note: possible use of r0 here to address SPE regs. */
25219 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
25220 info->ehrd_offset + frame_off
25221 + reg_size * (int) i);
25223 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
25227 /* Restore GPRs. This is done as a PARALLEL if we are using
25228 the load-multiple instructions. */
25229 if (TARGET_SPE_ABI
25230 && info->spe_64bit_regs_used
25231 && info->first_gp_reg_save != 32)
25233 /* Determine whether we can address all of the registers that need
25234 to be saved with an offset from frame_reg_rtx that fits in
25235 the small const field for SPE memory instructions. */
25236 int spe_regs_addressable
25237 = (SPE_CONST_OFFSET_OK (info->spe_gp_save_offset + frame_off
25238 + reg_size * (32 - info->first_gp_reg_save - 1))
25239 && restoring_GPRs_inline);
25241 if (!spe_regs_addressable)
25243 int ool_adjust = 0;
25244 rtx old_frame_reg_rtx = frame_reg_rtx;
25245 /* Make r11 point to the start of the SPE save area. We worried about
25246 not clobbering it when we were saving registers in the prologue.
25247 There's no need to worry here because the static chain is passed
25248 anew to every function. */
25250 if (!restoring_GPRs_inline)
25251 ool_adjust = 8 * (info->first_gp_reg_save - FIRST_SAVED_GP_REGNO);
25252 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
25253 emit_insn (gen_addsi3 (frame_reg_rtx, old_frame_reg_rtx,
25254 GEN_INT (info->spe_gp_save_offset
25255 + frame_off
25256 - ool_adjust)));
25257 /* Keep the invariant that frame_reg_rtx + frame_off points
25258 at the top of the stack frame. */
25259 frame_off = -info->spe_gp_save_offset + ool_adjust;
25262 if (restoring_GPRs_inline)
25264 HOST_WIDE_INT spe_offset = info->spe_gp_save_offset + frame_off;
25266 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
25267 if (rs6000_reg_live_or_pic_offset_p (info->first_gp_reg_save + i))
25269 rtx offset, addr, mem, reg;
25271 /* We're doing all this to ensure that the immediate offset
25272 fits into the immediate field of 'evldd'. */
25273 gcc_assert (SPE_CONST_OFFSET_OK (spe_offset + reg_size * i));
25275 offset = GEN_INT (spe_offset + reg_size * i);
25276 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, offset);
25277 mem = gen_rtx_MEM (V2SImode, addr);
25278 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
25280 emit_move_insn (reg, mem);
25283 else
25284 rs6000_emit_savres_rtx (info, frame_reg_rtx,
25285 info->spe_gp_save_offset + frame_off,
25286 info->lr_save_offset + frame_off,
25287 reg_mode,
25288 SAVRES_GPR | SAVRES_LR);
25290 else if (!restoring_GPRs_inline)
25292 /* We are jumping to an out-of-line function. */
25293 rtx ptr_reg;
25294 int end_save = info->gp_save_offset + info->gp_size;
25295 bool can_use_exit = end_save == 0;
25296 int sel = SAVRES_GPR | (can_use_exit ? SAVRES_LR : 0);
25297 int ptr_off;
25299 /* Emit stack reset code if we need it. */
25300 ptr_regno = ptr_regno_for_savres (sel);
25301 ptr_reg = gen_rtx_REG (Pmode, ptr_regno);
25302 if (can_use_exit)
25303 rs6000_emit_stack_reset (info, frame_reg_rtx, frame_off, ptr_regno);
25304 else if (end_save + frame_off != 0)
25305 emit_insn (gen_add3_insn (ptr_reg, frame_reg_rtx,
25306 GEN_INT (end_save + frame_off)));
25307 else if (REGNO (frame_reg_rtx) != ptr_regno)
25308 emit_move_insn (ptr_reg, frame_reg_rtx);
25309 if (REGNO (frame_reg_rtx) == ptr_regno)
25310 frame_off = -end_save;
25312 if (can_use_exit && info->cr_save_p)
25313 restore_saved_cr (cr_save_reg, using_mtcr_multiple, true);
25315 ptr_off = -end_save;
25316 rs6000_emit_savres_rtx (info, ptr_reg,
25317 info->gp_save_offset + ptr_off,
25318 info->lr_save_offset + ptr_off,
25319 reg_mode, sel);
25321 else if (using_load_multiple)
25323 rtvec p;
25324 p = rtvec_alloc (32 - info->first_gp_reg_save);
25325 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
25326 RTVEC_ELT (p, i)
25327 = gen_frame_load (gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
25328 frame_reg_rtx,
25329 info->gp_save_offset + frame_off + reg_size * i);
25330 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
25332 else
25334 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
25335 if (rs6000_reg_live_or_pic_offset_p (info->first_gp_reg_save + i))
25336 emit_insn (gen_frame_load
25337 (gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
25338 frame_reg_rtx,
25339 info->gp_save_offset + frame_off + reg_size * i));
25342 if (DEFAULT_ABI == ABI_V4 || flag_shrink_wrap)
25344 /* If the frame pointer was used then we can't delay emitting
25345 a REG_CFA_DEF_CFA note. This must happen on the insn that
25346 restores the frame pointer, r31. We may have already emitted
25347 a REG_CFA_DEF_CFA note, but that's OK; A duplicate is
25348 discarded by dwarf2cfi.c/dwarf2out.c, and in any case would
25349 be harmless if emitted. */
25350 if (frame_pointer_needed)
25352 insn = get_last_insn ();
25353 add_reg_note (insn, REG_CFA_DEF_CFA,
25354 plus_constant (Pmode, frame_reg_rtx, frame_off));
25355 RTX_FRAME_RELATED_P (insn) = 1;
25358 /* Set up cfa_restores. We always need these when
25359 shrink-wrapping. If not shrink-wrapping then we only need
25360 the cfa_restore when the stack location is no longer valid.
25361 The cfa_restores must be emitted on or before the insn that
25362 invalidates the stack, and of course must not be emitted
25363 before the insn that actually does the restore. The latter
25364 is why it is a bad idea to emit the cfa_restores as a group
25365 on the last instruction here that actually does a restore:
25366 That insn may be reordered with respect to others doing
25367 restores. */
25368 if (flag_shrink_wrap
25369 && !restoring_GPRs_inline
25370 && info->first_fp_reg_save == 64)
25371 cfa_restores = add_crlr_cfa_restore (info, cfa_restores);
25373 for (i = info->first_gp_reg_save; i < 32; i++)
25374 if (!restoring_GPRs_inline
25375 || using_load_multiple
25376 || rs6000_reg_live_or_pic_offset_p (i))
25378 rtx reg = gen_rtx_REG (reg_mode, i);
25380 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
25384 if (!restoring_GPRs_inline
25385 && info->first_fp_reg_save == 64)
25387 /* We are jumping to an out-of-line function. */
25388 if (cfa_restores)
25389 emit_cfa_restores (cfa_restores);
25390 return;
25393 if (restore_lr && !restoring_GPRs_inline)
25395 load_lr_save (0, frame_reg_rtx, info->lr_save_offset + frame_off);
25396 restore_saved_lr (0, exit_func);
25399 /* Restore fpr's if we need to do it without calling a function. */
25400 if (restoring_FPRs_inline)
25401 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
25402 if (save_reg_p (info->first_fp_reg_save + i))
25404 rtx reg = gen_rtx_REG ((TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
25405 ? DFmode : SFmode),
25406 info->first_fp_reg_save + i);
25407 emit_insn (gen_frame_load (reg, frame_reg_rtx,
25408 info->fp_save_offset + frame_off + 8 * i));
25409 if (DEFAULT_ABI == ABI_V4 || flag_shrink_wrap)
25410 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg, cfa_restores);
25413 /* If we saved cr, restore it here. Just those that were used. */
25414 if (info->cr_save_p)
25415 restore_saved_cr (cr_save_reg, using_mtcr_multiple, exit_func);
25417 /* If this is V.4, unwind the stack pointer after all of the loads
25418 have been done, or set up r11 if we are restoring fp out of line. */
25419 ptr_regno = 1;
25420 if (!restoring_FPRs_inline)
25422 bool lr = (strategy & REST_NOINLINE_FPRS_DOESNT_RESTORE_LR) == 0;
25423 int sel = SAVRES_FPR | (lr ? SAVRES_LR : 0);
25424 ptr_regno = ptr_regno_for_savres (sel);
25427 insn = rs6000_emit_stack_reset (info, frame_reg_rtx, frame_off, ptr_regno);
25428 if (REGNO (frame_reg_rtx) == ptr_regno)
25429 frame_off = 0;
25431 if (insn && restoring_FPRs_inline)
25433 if (cfa_restores)
25435 REG_NOTES (insn) = cfa_restores;
25436 cfa_restores = NULL_RTX;
25438 add_reg_note (insn, REG_CFA_DEF_CFA, sp_reg_rtx);
25439 RTX_FRAME_RELATED_P (insn) = 1;
25442 if (crtl->calls_eh_return)
25444 rtx sa = EH_RETURN_STACKADJ_RTX;
25445 emit_insn (gen_add3_insn (sp_reg_rtx, sp_reg_rtx, sa));
25448 if (!sibcall)
25450 rtvec p;
25451 bool lr = (strategy & REST_NOINLINE_FPRS_DOESNT_RESTORE_LR) == 0;
25452 if (! restoring_FPRs_inline)
25454 p = rtvec_alloc (4 + 64 - info->first_fp_reg_save);
25455 RTVEC_ELT (p, 0) = ret_rtx;
25457 else
25459 if (cfa_restores)
25461 /* We can't hang the cfa_restores off a simple return,
25462 since the shrink-wrap code sometimes uses an existing
25463 return. This means there might be a path from
25464 pre-prologue code to this return, and dwarf2cfi code
25465 wants the eh_frame unwinder state to be the same on
25466 all paths to any point. So we need to emit the
25467 cfa_restores before the return. For -m64 we really
25468 don't need epilogue cfa_restores at all, except for
25469 this irritating dwarf2cfi with shrink-wrap
25470 requirement; The stack red-zone means eh_frame info
25471 from the prologue telling the unwinder to restore
25472 from the stack is perfectly good right to the end of
25473 the function. */
25474 emit_insn (gen_blockage ());
25475 emit_cfa_restores (cfa_restores);
25476 cfa_restores = NULL_RTX;
25478 p = rtvec_alloc (2);
25479 RTVEC_ELT (p, 0) = simple_return_rtx;
25482 RTVEC_ELT (p, 1) = ((restoring_FPRs_inline || !lr)
25483 ? gen_rtx_USE (VOIDmode,
25484 gen_rtx_REG (Pmode, LR_REGNO))
25485 : gen_rtx_CLOBBER (VOIDmode,
25486 gen_rtx_REG (Pmode, LR_REGNO)));
25488 /* If we have to restore more than two FP registers, branch to the
25489 restore function. It will return to our caller. */
25490 if (! restoring_FPRs_inline)
25492 int i;
25493 int reg;
25494 rtx sym;
25496 if (flag_shrink_wrap)
25497 cfa_restores = add_crlr_cfa_restore (info, cfa_restores);
25499 sym = rs6000_savres_routine_sym (info,
25500 SAVRES_FPR | (lr ? SAVRES_LR : 0));
25501 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode, sym);
25502 reg = (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)? 1 : 11;
25503 RTVEC_ELT (p, 3) = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, reg));
25505 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
25507 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
25509 RTVEC_ELT (p, i + 4)
25510 = gen_frame_load (reg, sp_reg_rtx, info->fp_save_offset + 8 * i);
25511 if (flag_shrink_wrap)
25512 cfa_restores = alloc_reg_note (REG_CFA_RESTORE, reg,
25513 cfa_restores);
25517 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
25520 if (cfa_restores)
25522 if (sibcall)
25523 /* Ensure the cfa_restores are hung off an insn that won't
25524 be reordered above other restores. */
25525 emit_insn (gen_blockage ());
25527 emit_cfa_restores (cfa_restores);
25531 /* Write function epilogue. */
25533 static void
25534 rs6000_output_function_epilogue (FILE *file,
25535 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
25537 #if TARGET_MACHO
25538 macho_branch_islands ();
25539 /* Mach-O doesn't support labels at the end of objects, so if
25540 it looks like we might want one, insert a NOP. */
25542 rtx_insn *insn = get_last_insn ();
25543 rtx_insn *deleted_debug_label = NULL;
25544 while (insn
25545 && NOTE_P (insn)
25546 && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
25548 /* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL
25549 notes only, instead set their CODE_LABEL_NUMBER to -1,
25550 otherwise there would be code generation differences
25551 in between -g and -g0. */
25552 if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
25553 deleted_debug_label = insn;
25554 insn = PREV_INSN (insn);
25556 if (insn
25557 && (LABEL_P (insn)
25558 || (NOTE_P (insn)
25559 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
25560 fputs ("\tnop\n", file);
25561 else if (deleted_debug_label)
25562 for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn))
25563 if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
25564 CODE_LABEL_NUMBER (insn) = -1;
25566 #endif
25568 /* Output a traceback table here. See /usr/include/sys/debug.h for info
25569 on its format.
25571 We don't output a traceback table if -finhibit-size-directive was
25572 used. The documentation for -finhibit-size-directive reads
25573 ``don't output a @code{.size} assembler directive, or anything
25574 else that would cause trouble if the function is split in the
25575 middle, and the two halves are placed at locations far apart in
25576 memory.'' The traceback table has this property, since it
25577 includes the offset from the start of the function to the
25578 traceback table itself.
25580 System V.4 Powerpc's (and the embedded ABI derived from it) use a
25581 different traceback table. */
25582 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
25583 && ! flag_inhibit_size_directive
25584 && rs6000_traceback != traceback_none && !cfun->is_thunk)
25586 const char *fname = NULL;
25587 const char *language_string = lang_hooks.name;
25588 int fixed_parms = 0, float_parms = 0, parm_info = 0;
25589 int i;
25590 int optional_tbtab;
25591 rs6000_stack_t *info = rs6000_stack_info ();
25593 if (rs6000_traceback == traceback_full)
25594 optional_tbtab = 1;
25595 else if (rs6000_traceback == traceback_part)
25596 optional_tbtab = 0;
25597 else
25598 optional_tbtab = !optimize_size && !TARGET_ELF;
25600 if (optional_tbtab)
25602 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
25603 while (*fname == '.') /* V.4 encodes . in the name */
25604 fname++;
25606 /* Need label immediately before tbtab, so we can compute
25607 its offset from the function start. */
25608 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
25609 ASM_OUTPUT_LABEL (file, fname);
25612 /* The .tbtab pseudo-op can only be used for the first eight
25613 expressions, since it can't handle the possibly variable
25614 length fields that follow. However, if you omit the optional
25615 fields, the assembler outputs zeros for all optional fields
25616 anyways, giving each variable length field is minimum length
25617 (as defined in sys/debug.h). Thus we can not use the .tbtab
25618 pseudo-op at all. */
25620 /* An all-zero word flags the start of the tbtab, for debuggers
25621 that have to find it by searching forward from the entry
25622 point or from the current pc. */
25623 fputs ("\t.long 0\n", file);
25625 /* Tbtab format type. Use format type 0. */
25626 fputs ("\t.byte 0,", file);
25628 /* Language type. Unfortunately, there does not seem to be any
25629 official way to discover the language being compiled, so we
25630 use language_string.
25631 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
25632 Java is 13. Objective-C is 14. Objective-C++ isn't assigned
25633 a number, so for now use 9. LTO, Go and JIT aren't assigned numbers
25634 either, so for now use 0. */
25635 if (lang_GNU_C ()
25636 || ! strcmp (language_string, "GNU GIMPLE")
25637 || ! strcmp (language_string, "GNU Go")
25638 || ! strcmp (language_string, "libgccjit"))
25639 i = 0;
25640 else if (! strcmp (language_string, "GNU F77")
25641 || lang_GNU_Fortran ())
25642 i = 1;
25643 else if (! strcmp (language_string, "GNU Pascal"))
25644 i = 2;
25645 else if (! strcmp (language_string, "GNU Ada"))
25646 i = 3;
25647 else if (lang_GNU_CXX ()
25648 || ! strcmp (language_string, "GNU Objective-C++"))
25649 i = 9;
25650 else if (! strcmp (language_string, "GNU Java"))
25651 i = 13;
25652 else if (! strcmp (language_string, "GNU Objective-C"))
25653 i = 14;
25654 else
25655 gcc_unreachable ();
25656 fprintf (file, "%d,", i);
25658 /* 8 single bit fields: global linkage (not set for C extern linkage,
25659 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
25660 from start of procedure stored in tbtab, internal function, function
25661 has controlled storage, function has no toc, function uses fp,
25662 function logs/aborts fp operations. */
25663 /* Assume that fp operations are used if any fp reg must be saved. */
25664 fprintf (file, "%d,",
25665 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
25667 /* 6 bitfields: function is interrupt handler, name present in
25668 proc table, function calls alloca, on condition directives
25669 (controls stack walks, 3 bits), saves condition reg, saves
25670 link reg. */
25671 /* The `function calls alloca' bit seems to be set whenever reg 31 is
25672 set up as a frame pointer, even when there is no alloca call. */
25673 fprintf (file, "%d,",
25674 ((optional_tbtab << 6)
25675 | ((optional_tbtab & frame_pointer_needed) << 5)
25676 | (info->cr_save_p << 1)
25677 | (info->lr_save_p)));
25679 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
25680 (6 bits). */
25681 fprintf (file, "%d,",
25682 (info->push_p << 7) | (64 - info->first_fp_reg_save));
25684 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
25685 fprintf (file, "%d,", (32 - first_reg_to_save ()));
25687 if (optional_tbtab)
25689 /* Compute the parameter info from the function decl argument
25690 list. */
25691 tree decl;
25692 int next_parm_info_bit = 31;
25694 for (decl = DECL_ARGUMENTS (current_function_decl);
25695 decl; decl = DECL_CHAIN (decl))
25697 rtx parameter = DECL_INCOMING_RTL (decl);
25698 machine_mode mode = GET_MODE (parameter);
25700 if (GET_CODE (parameter) == REG)
25702 if (SCALAR_FLOAT_MODE_P (mode))
25704 int bits;
25706 float_parms++;
25708 switch (mode)
25710 case SFmode:
25711 case SDmode:
25712 bits = 0x2;
25713 break;
25715 case DFmode:
25716 case DDmode:
25717 case TFmode:
25718 case TDmode:
25719 bits = 0x3;
25720 break;
25722 default:
25723 gcc_unreachable ();
25726 /* If only one bit will fit, don't or in this entry. */
25727 if (next_parm_info_bit > 0)
25728 parm_info |= (bits << (next_parm_info_bit - 1));
25729 next_parm_info_bit -= 2;
25731 else
25733 fixed_parms += ((GET_MODE_SIZE (mode)
25734 + (UNITS_PER_WORD - 1))
25735 / UNITS_PER_WORD);
25736 next_parm_info_bit -= 1;
25742 /* Number of fixed point parameters. */
25743 /* This is actually the number of words of fixed point parameters; thus
25744 an 8 byte struct counts as 2; and thus the maximum value is 8. */
25745 fprintf (file, "%d,", fixed_parms);
25747 /* 2 bitfields: number of floating point parameters (7 bits), parameters
25748 all on stack. */
25749 /* This is actually the number of fp registers that hold parameters;
25750 and thus the maximum value is 13. */
25751 /* Set parameters on stack bit if parameters are not in their original
25752 registers, regardless of whether they are on the stack? Xlc
25753 seems to set the bit when not optimizing. */
25754 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
25756 if (! optional_tbtab)
25757 return;
25759 /* Optional fields follow. Some are variable length. */
25761 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
25762 11 double float. */
25763 /* There is an entry for each parameter in a register, in the order that
25764 they occur in the parameter list. Any intervening arguments on the
25765 stack are ignored. If the list overflows a long (max possible length
25766 34 bits) then completely leave off all elements that don't fit. */
25767 /* Only emit this long if there was at least one parameter. */
25768 if (fixed_parms || float_parms)
25769 fprintf (file, "\t.long %d\n", parm_info);
25771 /* Offset from start of code to tb table. */
25772 fputs ("\t.long ", file);
25773 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
25774 RS6000_OUTPUT_BASENAME (file, fname);
25775 putc ('-', file);
25776 rs6000_output_function_entry (file, fname);
25777 putc ('\n', file);
25779 /* Interrupt handler mask. */
25780 /* Omit this long, since we never set the interrupt handler bit
25781 above. */
25783 /* Number of CTL (controlled storage) anchors. */
25784 /* Omit this long, since the has_ctl bit is never set above. */
25786 /* Displacement into stack of each CTL anchor. */
25787 /* Omit this list of longs, because there are no CTL anchors. */
25789 /* Length of function name. */
25790 if (*fname == '*')
25791 ++fname;
25792 fprintf (file, "\t.short %d\n", (int) strlen (fname));
25794 /* Function name. */
25795 assemble_string (fname, strlen (fname));
25797 /* Register for alloca automatic storage; this is always reg 31.
25798 Only emit this if the alloca bit was set above. */
25799 if (frame_pointer_needed)
25800 fputs ("\t.byte 31\n", file);
25802 fputs ("\t.align 2\n", file);
25806 /* A C compound statement that outputs the assembler code for a thunk
25807 function, used to implement C++ virtual function calls with
25808 multiple inheritance. The thunk acts as a wrapper around a virtual
25809 function, adjusting the implicit object parameter before handing
25810 control off to the real function.
25812 First, emit code to add the integer DELTA to the location that
25813 contains the incoming first argument. Assume that this argument
25814 contains a pointer, and is the one used to pass the `this' pointer
25815 in C++. This is the incoming argument *before* the function
25816 prologue, e.g. `%o0' on a sparc. The addition must preserve the
25817 values of all other incoming arguments.
25819 After the addition, emit code to jump to FUNCTION, which is a
25820 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
25821 not touch the return address. Hence returning from FUNCTION will
25822 return to whoever called the current `thunk'.
25824 The effect must be as if FUNCTION had been called directly with the
25825 adjusted first argument. This macro is responsible for emitting
25826 all of the code for a thunk function; output_function_prologue()
25827 and output_function_epilogue() are not invoked.
25829 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
25830 been extracted from it.) It might possibly be useful on some
25831 targets, but probably not.
25833 If you do not define this macro, the target-independent code in the
25834 C++ frontend will generate a less efficient heavyweight thunk that
25835 calls FUNCTION instead of jumping to it. The generic approach does
25836 not support varargs. */
25838 static void
25839 rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
25840 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
25841 tree function)
25843 rtx this_rtx, funexp;
25844 rtx_insn *insn;
25846 reload_completed = 1;
25847 epilogue_completed = 1;
25849 /* Mark the end of the (empty) prologue. */
25850 emit_note (NOTE_INSN_PROLOGUE_END);
25852 /* Find the "this" pointer. If the function returns a structure,
25853 the structure return pointer is in r3. */
25854 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
25855 this_rtx = gen_rtx_REG (Pmode, 4);
25856 else
25857 this_rtx = gen_rtx_REG (Pmode, 3);
25859 /* Apply the constant offset, if required. */
25860 if (delta)
25861 emit_insn (gen_add3_insn (this_rtx, this_rtx, GEN_INT (delta)));
25863 /* Apply the offset from the vtable, if required. */
25864 if (vcall_offset)
25866 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
25867 rtx tmp = gen_rtx_REG (Pmode, 12);
25869 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this_rtx));
25870 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
25872 emit_insn (gen_add3_insn (tmp, tmp, vcall_offset_rtx));
25873 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
25875 else
25877 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
25879 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
25881 emit_insn (gen_add3_insn (this_rtx, this_rtx, tmp));
25884 /* Generate a tail call to the target function. */
25885 if (!TREE_USED (function))
25887 assemble_external (function);
25888 TREE_USED (function) = 1;
25890 funexp = XEXP (DECL_RTL (function), 0);
25891 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
25893 #if TARGET_MACHO
25894 if (MACHOPIC_INDIRECT)
25895 funexp = machopic_indirect_call_target (funexp);
25896 #endif
25898 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
25899 generate sibcall RTL explicitly. */
25900 insn = emit_call_insn (
25901 gen_rtx_PARALLEL (VOIDmode,
25902 gen_rtvec (4,
25903 gen_rtx_CALL (VOIDmode,
25904 funexp, const0_rtx),
25905 gen_rtx_USE (VOIDmode, const0_rtx),
25906 gen_rtx_USE (VOIDmode,
25907 gen_rtx_REG (SImode,
25908 LR_REGNO)),
25909 simple_return_rtx)));
25910 SIBLING_CALL_P (insn) = 1;
25911 emit_barrier ();
25913 /* Ensure we have a global entry point for the thunk. ??? We could
25914 avoid that if the target routine doesn't need a global entry point,
25915 but we do not know whether this is the case at this point. */
25916 if (DEFAULT_ABI == ABI_ELFv2)
25917 cfun->machine->r2_setup_needed = true;
25919 /* Run just enough of rest_of_compilation to get the insns emitted.
25920 There's not really enough bulk here to make other passes such as
25921 instruction scheduling worth while. Note that use_thunk calls
25922 assemble_start_function and assemble_end_function. */
25923 insn = get_insns ();
25924 shorten_branches (insn);
25925 final_start_function (insn, file, 1);
25926 final (insn, file, 1);
25927 final_end_function ();
25929 reload_completed = 0;
25930 epilogue_completed = 0;
25933 /* A quick summary of the various types of 'constant-pool tables'
25934 under PowerPC:
25936 Target Flags Name One table per
25937 AIX (none) AIX TOC object file
25938 AIX -mfull-toc AIX TOC object file
25939 AIX -mminimal-toc AIX minimal TOC translation unit
25940 SVR4/EABI (none) SVR4 SDATA object file
25941 SVR4/EABI -fpic SVR4 pic object file
25942 SVR4/EABI -fPIC SVR4 PIC translation unit
25943 SVR4/EABI -mrelocatable EABI TOC function
25944 SVR4/EABI -maix AIX TOC object file
25945 SVR4/EABI -maix -mminimal-toc
25946 AIX minimal TOC translation unit
25948 Name Reg. Set by entries contains:
25949 made by addrs? fp? sum?
25951 AIX TOC 2 crt0 as Y option option
25952 AIX minimal TOC 30 prolog gcc Y Y option
25953 SVR4 SDATA 13 crt0 gcc N Y N
25954 SVR4 pic 30 prolog ld Y not yet N
25955 SVR4 PIC 30 prolog gcc Y option option
25956 EABI TOC 30 prolog gcc Y option option
25960 /* Hash functions for the hash table. */
25962 static unsigned
25963 rs6000_hash_constant (rtx k)
25965 enum rtx_code code = GET_CODE (k);
25966 machine_mode mode = GET_MODE (k);
25967 unsigned result = (code << 3) ^ mode;
25968 const char *format;
25969 int flen, fidx;
25971 format = GET_RTX_FORMAT (code);
25972 flen = strlen (format);
25973 fidx = 0;
25975 switch (code)
25977 case LABEL_REF:
25978 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
25980 case CONST_WIDE_INT:
25982 int i;
25983 flen = CONST_WIDE_INT_NUNITS (k);
25984 for (i = 0; i < flen; i++)
25985 result = result * 613 + CONST_WIDE_INT_ELT (k, i);
25986 return result;
25989 case CONST_DOUBLE:
25990 if (mode != VOIDmode)
25991 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
25992 flen = 2;
25993 break;
25995 case CODE_LABEL:
25996 fidx = 3;
25997 break;
25999 default:
26000 break;
26003 for (; fidx < flen; fidx++)
26004 switch (format[fidx])
26006 case 's':
26008 unsigned i, len;
26009 const char *str = XSTR (k, fidx);
26010 len = strlen (str);
26011 result = result * 613 + len;
26012 for (i = 0; i < len; i++)
26013 result = result * 613 + (unsigned) str[i];
26014 break;
26016 case 'u':
26017 case 'e':
26018 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
26019 break;
26020 case 'i':
26021 case 'n':
26022 result = result * 613 + (unsigned) XINT (k, fidx);
26023 break;
26024 case 'w':
26025 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
26026 result = result * 613 + (unsigned) XWINT (k, fidx);
26027 else
26029 size_t i;
26030 for (i = 0; i < sizeof (HOST_WIDE_INT) / sizeof (unsigned); i++)
26031 result = result * 613 + (unsigned) (XWINT (k, fidx)
26032 >> CHAR_BIT * i);
26034 break;
26035 case '0':
26036 break;
26037 default:
26038 gcc_unreachable ();
26041 return result;
26044 hashval_t
26045 toc_hasher::hash (toc_hash_struct *thc)
26047 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
26050 /* Compare H1 and H2 for equivalence. */
26052 bool
26053 toc_hasher::equal (toc_hash_struct *h1, toc_hash_struct *h2)
26055 rtx r1 = h1->key;
26056 rtx r2 = h2->key;
26058 if (h1->key_mode != h2->key_mode)
26059 return 0;
26061 return rtx_equal_p (r1, r2);
26064 /* These are the names given by the C++ front-end to vtables, and
26065 vtable-like objects. Ideally, this logic should not be here;
26066 instead, there should be some programmatic way of inquiring as
26067 to whether or not an object is a vtable. */
26069 #define VTABLE_NAME_P(NAME) \
26070 (strncmp ("_vt.", name, strlen ("_vt.")) == 0 \
26071 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
26072 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26073 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
26074 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
26076 #ifdef NO_DOLLAR_IN_LABEL
26077 /* Return a GGC-allocated character string translating dollar signs in
26078 input NAME to underscores. Used by XCOFF ASM_OUTPUT_LABELREF. */
26080 const char *
26081 rs6000_xcoff_strip_dollar (const char *name)
26083 char *strip, *p;
26084 const char *q;
26085 size_t len;
26087 q = (const char *) strchr (name, '$');
26089 if (q == 0 || q == name)
26090 return name;
26092 len = strlen (name);
26093 strip = XALLOCAVEC (char, len + 1);
26094 strcpy (strip, name);
26095 p = strip + (q - name);
26096 while (p)
26098 *p = '_';
26099 p = strchr (p + 1, '$');
26102 return ggc_alloc_string (strip, len);
26104 #endif
26106 void
26107 rs6000_output_symbol_ref (FILE *file, rtx x)
26109 /* Currently C++ toc references to vtables can be emitted before it
26110 is decided whether the vtable is public or private. If this is
26111 the case, then the linker will eventually complain that there is
26112 a reference to an unknown section. Thus, for vtables only,
26113 we emit the TOC reference to reference the symbol and not the
26114 section. */
26115 const char *name = XSTR (x, 0);
26117 tree decl = SYMBOL_REF_DECL (x);
26118 if (decl /* sync condition with assemble_external () */
26119 && DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)
26120 && (TREE_CODE (decl) == VAR_DECL
26121 || TREE_CODE (decl) == FUNCTION_DECL)
26122 && name[strlen (name) - 1] != ']')
26124 name = concat (name,
26125 (TREE_CODE (decl) == FUNCTION_DECL
26126 ? "[DS]" : "[UA]"),
26127 NULL);
26128 XSTR (x, 0) = name;
26131 if (VTABLE_NAME_P (name))
26133 RS6000_OUTPUT_BASENAME (file, name);
26135 else
26136 assemble_name (file, name);
26139 /* Output a TOC entry. We derive the entry name from what is being
26140 written. */
26142 void
26143 output_toc (FILE *file, rtx x, int labelno, machine_mode mode)
26145 char buf[256];
26146 const char *name = buf;
26147 rtx base = x;
26148 HOST_WIDE_INT offset = 0;
26150 gcc_assert (!TARGET_NO_TOC);
26152 /* When the linker won't eliminate them, don't output duplicate
26153 TOC entries (this happens on AIX if there is any kind of TOC,
26154 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
26155 CODE_LABELs. */
26156 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
26158 struct toc_hash_struct *h;
26160 /* Create toc_hash_table. This can't be done at TARGET_OPTION_OVERRIDE
26161 time because GGC is not initialized at that point. */
26162 if (toc_hash_table == NULL)
26163 toc_hash_table = hash_table<toc_hasher>::create_ggc (1021);
26165 h = ggc_alloc<toc_hash_struct> ();
26166 h->key = x;
26167 h->key_mode = mode;
26168 h->labelno = labelno;
26170 toc_hash_struct **found = toc_hash_table->find_slot (h, INSERT);
26171 if (*found == NULL)
26172 *found = h;
26173 else /* This is indeed a duplicate.
26174 Set this label equal to that label. */
26176 fputs ("\t.set ", file);
26177 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
26178 fprintf (file, "%d,", labelno);
26179 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
26180 fprintf (file, "%d\n", ((*found)->labelno));
26182 #ifdef HAVE_AS_TLS
26183 if (TARGET_XCOFF && GET_CODE (x) == SYMBOL_REF
26184 && (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_GLOBAL_DYNAMIC
26185 || SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC))
26187 fputs ("\t.set ", file);
26188 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCM");
26189 fprintf (file, "%d,", labelno);
26190 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LCM");
26191 fprintf (file, "%d\n", ((*found)->labelno));
26193 #endif
26194 return;
26198 /* If we're going to put a double constant in the TOC, make sure it's
26199 aligned properly when strict alignment is on. */
26200 if ((CONST_DOUBLE_P (x) || CONST_WIDE_INT_P (x))
26201 && STRICT_ALIGNMENT
26202 && GET_MODE_BITSIZE (mode) >= 64
26203 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
26204 ASM_OUTPUT_ALIGN (file, 3);
26207 (*targetm.asm_out.internal_label) (file, "LC", labelno);
26209 /* Handle FP constants specially. Note that if we have a minimal
26210 TOC, things we put here aren't actually in the TOC, so we can allow
26211 FP constants. */
26212 if (GET_CODE (x) == CONST_DOUBLE &&
26213 (GET_MODE (x) == TFmode || GET_MODE (x) == TDmode))
26215 REAL_VALUE_TYPE rv;
26216 long k[4];
26218 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
26219 if (DECIMAL_FLOAT_MODE_P (GET_MODE (x)))
26220 REAL_VALUE_TO_TARGET_DECIMAL128 (rv, k);
26221 else
26222 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
26224 if (TARGET_64BIT)
26226 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26227 fputs (DOUBLE_INT_ASM_OP, file);
26228 else
26229 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
26230 k[0] & 0xffffffff, k[1] & 0xffffffff,
26231 k[2] & 0xffffffff, k[3] & 0xffffffff);
26232 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
26233 k[WORDS_BIG_ENDIAN ? 0 : 1] & 0xffffffff,
26234 k[WORDS_BIG_ENDIAN ? 1 : 0] & 0xffffffff,
26235 k[WORDS_BIG_ENDIAN ? 2 : 3] & 0xffffffff,
26236 k[WORDS_BIG_ENDIAN ? 3 : 2] & 0xffffffff);
26237 return;
26239 else
26241 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26242 fputs ("\t.long ", file);
26243 else
26244 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
26245 k[0] & 0xffffffff, k[1] & 0xffffffff,
26246 k[2] & 0xffffffff, k[3] & 0xffffffff);
26247 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
26248 k[0] & 0xffffffff, k[1] & 0xffffffff,
26249 k[2] & 0xffffffff, k[3] & 0xffffffff);
26250 return;
26253 else if (GET_CODE (x) == CONST_DOUBLE &&
26254 (GET_MODE (x) == DFmode || GET_MODE (x) == DDmode))
26256 REAL_VALUE_TYPE rv;
26257 long k[2];
26259 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
26261 if (DECIMAL_FLOAT_MODE_P (GET_MODE (x)))
26262 REAL_VALUE_TO_TARGET_DECIMAL64 (rv, k);
26263 else
26264 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
26266 if (TARGET_64BIT)
26268 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26269 fputs (DOUBLE_INT_ASM_OP, file);
26270 else
26271 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
26272 k[0] & 0xffffffff, k[1] & 0xffffffff);
26273 fprintf (file, "0x%lx%08lx\n",
26274 k[WORDS_BIG_ENDIAN ? 0 : 1] & 0xffffffff,
26275 k[WORDS_BIG_ENDIAN ? 1 : 0] & 0xffffffff);
26276 return;
26278 else
26280 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26281 fputs ("\t.long ", file);
26282 else
26283 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
26284 k[0] & 0xffffffff, k[1] & 0xffffffff);
26285 fprintf (file, "0x%lx,0x%lx\n",
26286 k[0] & 0xffffffff, k[1] & 0xffffffff);
26287 return;
26290 else if (GET_CODE (x) == CONST_DOUBLE &&
26291 (GET_MODE (x) == SFmode || GET_MODE (x) == SDmode))
26293 REAL_VALUE_TYPE rv;
26294 long l;
26296 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
26297 if (DECIMAL_FLOAT_MODE_P (GET_MODE (x)))
26298 REAL_VALUE_TO_TARGET_DECIMAL32 (rv, l);
26299 else
26300 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
26302 if (TARGET_64BIT)
26304 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26305 fputs (DOUBLE_INT_ASM_OP, file);
26306 else
26307 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
26308 if (WORDS_BIG_ENDIAN)
26309 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
26310 else
26311 fprintf (file, "0x%lx\n", l & 0xffffffff);
26312 return;
26314 else
26316 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26317 fputs ("\t.long ", file);
26318 else
26319 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
26320 fprintf (file, "0x%lx\n", l & 0xffffffff);
26321 return;
26324 else if (GET_MODE (x) == VOIDmode && GET_CODE (x) == CONST_INT)
26326 unsigned HOST_WIDE_INT low;
26327 HOST_WIDE_INT high;
26329 low = INTVAL (x) & 0xffffffff;
26330 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
26332 /* TOC entries are always Pmode-sized, so when big-endian
26333 smaller integer constants in the TOC need to be padded.
26334 (This is still a win over putting the constants in
26335 a separate constant pool, because then we'd have
26336 to have both a TOC entry _and_ the actual constant.)
26338 For a 32-bit target, CONST_INT values are loaded and shifted
26339 entirely within `low' and can be stored in one TOC entry. */
26341 /* It would be easy to make this work, but it doesn't now. */
26342 gcc_assert (!TARGET_64BIT || POINTER_SIZE >= GET_MODE_BITSIZE (mode));
26344 if (WORDS_BIG_ENDIAN && POINTER_SIZE > GET_MODE_BITSIZE (mode))
26346 low |= high << 32;
26347 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
26348 high = (HOST_WIDE_INT) low >> 32;
26349 low &= 0xffffffff;
26352 if (TARGET_64BIT)
26354 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26355 fputs (DOUBLE_INT_ASM_OP, file);
26356 else
26357 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
26358 (long) high & 0xffffffff, (long) low & 0xffffffff);
26359 fprintf (file, "0x%lx%08lx\n",
26360 (long) high & 0xffffffff, (long) low & 0xffffffff);
26361 return;
26363 else
26365 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
26367 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26368 fputs ("\t.long ", file);
26369 else
26370 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
26371 (long) high & 0xffffffff, (long) low & 0xffffffff);
26372 fprintf (file, "0x%lx,0x%lx\n",
26373 (long) high & 0xffffffff, (long) low & 0xffffffff);
26375 else
26377 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26378 fputs ("\t.long ", file);
26379 else
26380 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
26381 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
26383 return;
26387 if (GET_CODE (x) == CONST)
26389 gcc_assert (GET_CODE (XEXP (x, 0)) == PLUS
26390 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT);
26392 base = XEXP (XEXP (x, 0), 0);
26393 offset = INTVAL (XEXP (XEXP (x, 0), 1));
26396 switch (GET_CODE (base))
26398 case SYMBOL_REF:
26399 name = XSTR (base, 0);
26400 break;
26402 case LABEL_REF:
26403 ASM_GENERATE_INTERNAL_LABEL (buf, "L",
26404 CODE_LABEL_NUMBER (XEXP (base, 0)));
26405 break;
26407 case CODE_LABEL:
26408 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
26409 break;
26411 default:
26412 gcc_unreachable ();
26415 if (TARGET_ELF || TARGET_MINIMAL_TOC)
26416 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
26417 else
26419 fputs ("\t.tc ", file);
26420 RS6000_OUTPUT_BASENAME (file, name);
26422 if (offset < 0)
26423 fprintf (file, ".N" HOST_WIDE_INT_PRINT_UNSIGNED, - offset);
26424 else if (offset)
26425 fprintf (file, ".P" HOST_WIDE_INT_PRINT_UNSIGNED, offset);
26427 /* Mark large TOC symbols on AIX with [TE] so they are mapped
26428 after other TOC symbols, reducing overflow of small TOC access
26429 to [TC] symbols. */
26430 fputs (TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL
26431 ? "[TE]," : "[TC],", file);
26434 /* Currently C++ toc references to vtables can be emitted before it
26435 is decided whether the vtable is public or private. If this is
26436 the case, then the linker will eventually complain that there is
26437 a TOC reference to an unknown section. Thus, for vtables only,
26438 we emit the TOC reference to reference the symbol and not the
26439 section. */
26440 if (VTABLE_NAME_P (name))
26442 RS6000_OUTPUT_BASENAME (file, name);
26443 if (offset < 0)
26444 fprintf (file, HOST_WIDE_INT_PRINT_DEC, offset);
26445 else if (offset > 0)
26446 fprintf (file, "+" HOST_WIDE_INT_PRINT_DEC, offset);
26448 else
26449 output_addr_const (file, x);
26451 #if HAVE_AS_TLS
26452 if (TARGET_XCOFF && GET_CODE (base) == SYMBOL_REF
26453 && SYMBOL_REF_TLS_MODEL (base) != 0)
26455 if (SYMBOL_REF_TLS_MODEL (base) == TLS_MODEL_LOCAL_EXEC)
26456 fputs ("@le", file);
26457 else if (SYMBOL_REF_TLS_MODEL (base) == TLS_MODEL_INITIAL_EXEC)
26458 fputs ("@ie", file);
26459 /* Use global-dynamic for local-dynamic. */
26460 else if (SYMBOL_REF_TLS_MODEL (base) == TLS_MODEL_GLOBAL_DYNAMIC
26461 || SYMBOL_REF_TLS_MODEL (base) == TLS_MODEL_LOCAL_DYNAMIC)
26463 putc ('\n', file);
26464 (*targetm.asm_out.internal_label) (file, "LCM", labelno);
26465 fputs ("\t.tc .", file);
26466 RS6000_OUTPUT_BASENAME (file, name);
26467 fputs ("[TC],", file);
26468 output_addr_const (file, x);
26469 fputs ("@m", file);
26472 #endif
26474 putc ('\n', file);
26477 /* Output an assembler pseudo-op to write an ASCII string of N characters
26478 starting at P to FILE.
26480 On the RS/6000, we have to do this using the .byte operation and
26481 write out special characters outside the quoted string.
26482 Also, the assembler is broken; very long strings are truncated,
26483 so we must artificially break them up early. */
26485 void
26486 output_ascii (FILE *file, const char *p, int n)
26488 char c;
26489 int i, count_string;
26490 const char *for_string = "\t.byte \"";
26491 const char *for_decimal = "\t.byte ";
26492 const char *to_close = NULL;
26494 count_string = 0;
26495 for (i = 0; i < n; i++)
26497 c = *p++;
26498 if (c >= ' ' && c < 0177)
26500 if (for_string)
26501 fputs (for_string, file);
26502 putc (c, file);
26504 /* Write two quotes to get one. */
26505 if (c == '"')
26507 putc (c, file);
26508 ++count_string;
26511 for_string = NULL;
26512 for_decimal = "\"\n\t.byte ";
26513 to_close = "\"\n";
26514 ++count_string;
26516 if (count_string >= 512)
26518 fputs (to_close, file);
26520 for_string = "\t.byte \"";
26521 for_decimal = "\t.byte ";
26522 to_close = NULL;
26523 count_string = 0;
26526 else
26528 if (for_decimal)
26529 fputs (for_decimal, file);
26530 fprintf (file, "%d", c);
26532 for_string = "\n\t.byte \"";
26533 for_decimal = ", ";
26534 to_close = "\n";
26535 count_string = 0;
26539 /* Now close the string if we have written one. Then end the line. */
26540 if (to_close)
26541 fputs (to_close, file);
26544 /* Generate a unique section name for FILENAME for a section type
26545 represented by SECTION_DESC. Output goes into BUF.
26547 SECTION_DESC can be any string, as long as it is different for each
26548 possible section type.
26550 We name the section in the same manner as xlc. The name begins with an
26551 underscore followed by the filename (after stripping any leading directory
26552 names) with the last period replaced by the string SECTION_DESC. If
26553 FILENAME does not contain a period, SECTION_DESC is appended to the end of
26554 the name. */
26556 void
26557 rs6000_gen_section_name (char **buf, const char *filename,
26558 const char *section_desc)
26560 const char *q, *after_last_slash, *last_period = 0;
26561 char *p;
26562 int len;
26564 after_last_slash = filename;
26565 for (q = filename; *q; q++)
26567 if (*q == '/')
26568 after_last_slash = q + 1;
26569 else if (*q == '.')
26570 last_period = q;
26573 len = strlen (after_last_slash) + strlen (section_desc) + 2;
26574 *buf = (char *) xmalloc (len);
26576 p = *buf;
26577 *p++ = '_';
26579 for (q = after_last_slash; *q; q++)
26581 if (q == last_period)
26583 strcpy (p, section_desc);
26584 p += strlen (section_desc);
26585 break;
26588 else if (ISALNUM (*q))
26589 *p++ = *q;
26592 if (last_period == 0)
26593 strcpy (p, section_desc);
26594 else
26595 *p = '\0';
26598 /* Emit profile function. */
26600 void
26601 output_profile_hook (int labelno ATTRIBUTE_UNUSED)
26603 /* Non-standard profiling for kernels, which just saves LR then calls
26604 _mcount without worrying about arg saves. The idea is to change
26605 the function prologue as little as possible as it isn't easy to
26606 account for arg save/restore code added just for _mcount. */
26607 if (TARGET_PROFILE_KERNEL)
26608 return;
26610 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
26612 #ifndef NO_PROFILE_COUNTERS
26613 # define NO_PROFILE_COUNTERS 0
26614 #endif
26615 if (NO_PROFILE_COUNTERS)
26616 emit_library_call (init_one_libfunc (RS6000_MCOUNT),
26617 LCT_NORMAL, VOIDmode, 0);
26618 else
26620 char buf[30];
26621 const char *label_name;
26622 rtx fun;
26624 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
26625 label_name = ggc_strdup ((*targetm.strip_name_encoding) (buf));
26626 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
26628 emit_library_call (init_one_libfunc (RS6000_MCOUNT),
26629 LCT_NORMAL, VOIDmode, 1, fun, Pmode);
26632 else if (DEFAULT_ABI == ABI_DARWIN)
26634 const char *mcount_name = RS6000_MCOUNT;
26635 int caller_addr_regno = LR_REGNO;
26637 /* Be conservative and always set this, at least for now. */
26638 crtl->uses_pic_offset_table = 1;
26640 #if TARGET_MACHO
26641 /* For PIC code, set up a stub and collect the caller's address
26642 from r0, which is where the prologue puts it. */
26643 if (MACHOPIC_INDIRECT
26644 && crtl->uses_pic_offset_table)
26645 caller_addr_regno = 0;
26646 #endif
26647 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
26648 LCT_NORMAL, VOIDmode, 1,
26649 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
26653 /* Write function profiler code. */
26655 void
26656 output_function_profiler (FILE *file, int labelno)
26658 char buf[100];
26660 switch (DEFAULT_ABI)
26662 default:
26663 gcc_unreachable ();
26665 case ABI_V4:
26666 if (!TARGET_32BIT)
26668 warning (0, "no profiling of 64-bit code for this ABI");
26669 return;
26671 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
26672 fprintf (file, "\tmflr %s\n", reg_names[0]);
26673 if (NO_PROFILE_COUNTERS)
26675 asm_fprintf (file, "\tstw %s,4(%s)\n",
26676 reg_names[0], reg_names[1]);
26678 else if (TARGET_SECURE_PLT && flag_pic)
26680 if (TARGET_LINK_STACK)
26682 char name[32];
26683 get_ppc476_thunk_name (name);
26684 asm_fprintf (file, "\tbl %s\n", name);
26686 else
26687 asm_fprintf (file, "\tbcl 20,31,1f\n1:\n");
26688 asm_fprintf (file, "\tstw %s,4(%s)\n",
26689 reg_names[0], reg_names[1]);
26690 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
26691 asm_fprintf (file, "\taddis %s,%s,",
26692 reg_names[12], reg_names[12]);
26693 assemble_name (file, buf);
26694 asm_fprintf (file, "-1b@ha\n\tla %s,", reg_names[0]);
26695 assemble_name (file, buf);
26696 asm_fprintf (file, "-1b@l(%s)\n", reg_names[12]);
26698 else if (flag_pic == 1)
26700 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
26701 asm_fprintf (file, "\tstw %s,4(%s)\n",
26702 reg_names[0], reg_names[1]);
26703 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
26704 asm_fprintf (file, "\tlwz %s,", reg_names[0]);
26705 assemble_name (file, buf);
26706 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
26708 else if (flag_pic > 1)
26710 asm_fprintf (file, "\tstw %s,4(%s)\n",
26711 reg_names[0], reg_names[1]);
26712 /* Now, we need to get the address of the label. */
26713 if (TARGET_LINK_STACK)
26715 char name[32];
26716 get_ppc476_thunk_name (name);
26717 asm_fprintf (file, "\tbl %s\n\tb 1f\n\t.long ", name);
26718 assemble_name (file, buf);
26719 fputs ("-.\n1:", file);
26720 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
26721 asm_fprintf (file, "\taddi %s,%s,4\n",
26722 reg_names[11], reg_names[11]);
26724 else
26726 fputs ("\tbcl 20,31,1f\n\t.long ", file);
26727 assemble_name (file, buf);
26728 fputs ("-.\n1:", file);
26729 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
26731 asm_fprintf (file, "\tlwz %s,0(%s)\n",
26732 reg_names[0], reg_names[11]);
26733 asm_fprintf (file, "\tadd %s,%s,%s\n",
26734 reg_names[0], reg_names[0], reg_names[11]);
26736 else
26738 asm_fprintf (file, "\tlis %s,", reg_names[12]);
26739 assemble_name (file, buf);
26740 fputs ("@ha\n", file);
26741 asm_fprintf (file, "\tstw %s,4(%s)\n",
26742 reg_names[0], reg_names[1]);
26743 asm_fprintf (file, "\tla %s,", reg_names[0]);
26744 assemble_name (file, buf);
26745 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
26748 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
26749 fprintf (file, "\tbl %s%s\n",
26750 RS6000_MCOUNT, flag_pic ? "@plt" : "");
26751 break;
26753 case ABI_AIX:
26754 case ABI_ELFv2:
26755 case ABI_DARWIN:
26756 /* Don't do anything, done in output_profile_hook (). */
26757 break;
26763 /* The following variable value is the last issued insn. */
26765 static rtx last_scheduled_insn;
26767 /* The following variable helps to balance issuing of load and
26768 store instructions */
26770 static int load_store_pendulum;
26772 /* Power4 load update and store update instructions are cracked into a
26773 load or store and an integer insn which are executed in the same cycle.
26774 Branches have their own dispatch slot which does not count against the
26775 GCC issue rate, but it changes the program flow so there are no other
26776 instructions to issue in this cycle. */
26778 static int
26779 rs6000_variable_issue_1 (rtx_insn *insn, int more)
26781 last_scheduled_insn = insn;
26782 if (GET_CODE (PATTERN (insn)) == USE
26783 || GET_CODE (PATTERN (insn)) == CLOBBER)
26785 cached_can_issue_more = more;
26786 return cached_can_issue_more;
26789 if (insn_terminates_group_p (insn, current_group))
26791 cached_can_issue_more = 0;
26792 return cached_can_issue_more;
26795 /* If no reservation, but reach here */
26796 if (recog_memoized (insn) < 0)
26797 return more;
26799 if (rs6000_sched_groups)
26801 if (is_microcoded_insn (insn))
26802 cached_can_issue_more = 0;
26803 else if (is_cracked_insn (insn))
26804 cached_can_issue_more = more > 2 ? more - 2 : 0;
26805 else
26806 cached_can_issue_more = more - 1;
26808 return cached_can_issue_more;
26811 if (rs6000_cpu_attr == CPU_CELL && is_nonpipeline_insn (insn))
26812 return 0;
26814 cached_can_issue_more = more - 1;
26815 return cached_can_issue_more;
26818 static int
26819 rs6000_variable_issue (FILE *stream, int verbose, rtx_insn *insn, int more)
26821 int r = rs6000_variable_issue_1 (insn, more);
26822 if (verbose)
26823 fprintf (stream, "// rs6000_variable_issue (more = %d) = %d\n", more, r);
26824 return r;
26827 /* Adjust the cost of a scheduling dependency. Return the new cost of
26828 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
26830 static int
26831 rs6000_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
26833 enum attr_type attr_type;
26835 if (! recog_memoized (insn))
26836 return 0;
26838 switch (REG_NOTE_KIND (link))
26840 case REG_DEP_TRUE:
26842 /* Data dependency; DEP_INSN writes a register that INSN reads
26843 some cycles later. */
26845 /* Separate a load from a narrower, dependent store. */
26846 if (rs6000_sched_groups
26847 && GET_CODE (PATTERN (insn)) == SET
26848 && GET_CODE (PATTERN (dep_insn)) == SET
26849 && GET_CODE (XEXP (PATTERN (insn), 1)) == MEM
26850 && GET_CODE (XEXP (PATTERN (dep_insn), 0)) == MEM
26851 && (GET_MODE_SIZE (GET_MODE (XEXP (PATTERN (insn), 1)))
26852 > GET_MODE_SIZE (GET_MODE (XEXP (PATTERN (dep_insn), 0)))))
26853 return cost + 14;
26855 attr_type = get_attr_type (insn);
26857 switch (attr_type)
26859 case TYPE_JMPREG:
26860 /* Tell the first scheduling pass about the latency between
26861 a mtctr and bctr (and mtlr and br/blr). The first
26862 scheduling pass will not know about this latency since
26863 the mtctr instruction, which has the latency associated
26864 to it, will be generated by reload. */
26865 return 4;
26866 case TYPE_BRANCH:
26867 /* Leave some extra cycles between a compare and its
26868 dependent branch, to inhibit expensive mispredicts. */
26869 if ((rs6000_cpu_attr == CPU_PPC603
26870 || rs6000_cpu_attr == CPU_PPC604
26871 || rs6000_cpu_attr == CPU_PPC604E
26872 || rs6000_cpu_attr == CPU_PPC620
26873 || rs6000_cpu_attr == CPU_PPC630
26874 || rs6000_cpu_attr == CPU_PPC750
26875 || rs6000_cpu_attr == CPU_PPC7400
26876 || rs6000_cpu_attr == CPU_PPC7450
26877 || rs6000_cpu_attr == CPU_PPCE5500
26878 || rs6000_cpu_attr == CPU_PPCE6500
26879 || rs6000_cpu_attr == CPU_POWER4
26880 || rs6000_cpu_attr == CPU_POWER5
26881 || rs6000_cpu_attr == CPU_POWER7
26882 || rs6000_cpu_attr == CPU_POWER8
26883 || rs6000_cpu_attr == CPU_CELL)
26884 && recog_memoized (dep_insn)
26885 && (INSN_CODE (dep_insn) >= 0))
26887 switch (get_attr_type (dep_insn))
26889 case TYPE_CMP:
26890 case TYPE_FPCOMPARE:
26891 case TYPE_CR_LOGICAL:
26892 case TYPE_DELAYED_CR:
26893 return cost + 2;
26894 case TYPE_EXTS:
26895 case TYPE_MUL:
26896 if (get_attr_dot (dep_insn) == DOT_YES)
26897 return cost + 2;
26898 else
26899 break;
26900 case TYPE_SHIFT:
26901 if (get_attr_dot (dep_insn) == DOT_YES
26902 && get_attr_var_shift (dep_insn) == VAR_SHIFT_NO)
26903 return cost + 2;
26904 else
26905 break;
26906 default:
26907 break;
26909 break;
26911 case TYPE_STORE:
26912 case TYPE_FPSTORE:
26913 if ((rs6000_cpu == PROCESSOR_POWER6)
26914 && recog_memoized (dep_insn)
26915 && (INSN_CODE (dep_insn) >= 0))
26918 if (GET_CODE (PATTERN (insn)) != SET)
26919 /* If this happens, we have to extend this to schedule
26920 optimally. Return default for now. */
26921 return cost;
26923 /* Adjust the cost for the case where the value written
26924 by a fixed point operation is used as the address
26925 gen value on a store. */
26926 switch (get_attr_type (dep_insn))
26928 case TYPE_LOAD:
26929 case TYPE_CNTLZ:
26931 if (! store_data_bypass_p (dep_insn, insn))
26932 return get_attr_sign_extend (dep_insn)
26933 == SIGN_EXTEND_YES ? 6 : 4;
26934 break;
26936 case TYPE_SHIFT:
26938 if (! store_data_bypass_p (dep_insn, insn))
26939 return get_attr_var_shift (dep_insn) == VAR_SHIFT_YES ?
26940 6 : 3;
26941 break;
26943 case TYPE_INTEGER:
26944 case TYPE_ADD:
26945 case TYPE_LOGICAL:
26946 case TYPE_EXTS:
26947 case TYPE_INSERT:
26949 if (! store_data_bypass_p (dep_insn, insn))
26950 return 3;
26951 break;
26953 case TYPE_STORE:
26954 case TYPE_FPLOAD:
26955 case TYPE_FPSTORE:
26957 if (get_attr_update (dep_insn) == UPDATE_YES
26958 && ! store_data_bypass_p (dep_insn, insn))
26959 return 3;
26960 break;
26962 case TYPE_MUL:
26964 if (! store_data_bypass_p (dep_insn, insn))
26965 return 17;
26966 break;
26968 case TYPE_DIV:
26970 if (! store_data_bypass_p (dep_insn, insn))
26971 return get_attr_size (dep_insn) == SIZE_32 ? 45 : 57;
26972 break;
26974 default:
26975 break;
26978 break;
26980 case TYPE_LOAD:
26981 if ((rs6000_cpu == PROCESSOR_POWER6)
26982 && recog_memoized (dep_insn)
26983 && (INSN_CODE (dep_insn) >= 0))
26986 /* Adjust the cost for the case where the value written
26987 by a fixed point instruction is used within the address
26988 gen portion of a subsequent load(u)(x) */
26989 switch (get_attr_type (dep_insn))
26991 case TYPE_LOAD:
26992 case TYPE_CNTLZ:
26994 if (set_to_load_agen (dep_insn, insn))
26995 return get_attr_sign_extend (dep_insn)
26996 == SIGN_EXTEND_YES ? 6 : 4;
26997 break;
26999 case TYPE_SHIFT:
27001 if (set_to_load_agen (dep_insn, insn))
27002 return get_attr_var_shift (dep_insn) == VAR_SHIFT_YES ?
27003 6 : 3;
27004 break;
27006 case TYPE_INTEGER:
27007 case TYPE_ADD:
27008 case TYPE_LOGICAL:
27009 case TYPE_EXTS:
27010 case TYPE_INSERT:
27012 if (set_to_load_agen (dep_insn, insn))
27013 return 3;
27014 break;
27016 case TYPE_STORE:
27017 case TYPE_FPLOAD:
27018 case TYPE_FPSTORE:
27020 if (get_attr_update (dep_insn) == UPDATE_YES
27021 && set_to_load_agen (dep_insn, insn))
27022 return 3;
27023 break;
27025 case TYPE_MUL:
27027 if (set_to_load_agen (dep_insn, insn))
27028 return 17;
27029 break;
27031 case TYPE_DIV:
27033 if (set_to_load_agen (dep_insn, insn))
27034 return get_attr_size (dep_insn) == SIZE_32 ? 45 : 57;
27035 break;
27037 default:
27038 break;
27041 break;
27043 case TYPE_FPLOAD:
27044 if ((rs6000_cpu == PROCESSOR_POWER6)
27045 && get_attr_update (insn) == UPDATE_NO
27046 && recog_memoized (dep_insn)
27047 && (INSN_CODE (dep_insn) >= 0)
27048 && (get_attr_type (dep_insn) == TYPE_MFFGPR))
27049 return 2;
27051 default:
27052 break;
27055 /* Fall out to return default cost. */
27057 break;
27059 case REG_DEP_OUTPUT:
27060 /* Output dependency; DEP_INSN writes a register that INSN writes some
27061 cycles later. */
27062 if ((rs6000_cpu == PROCESSOR_POWER6)
27063 && recog_memoized (dep_insn)
27064 && (INSN_CODE (dep_insn) >= 0))
27066 attr_type = get_attr_type (insn);
27068 switch (attr_type)
27070 case TYPE_FP:
27071 if (get_attr_type (dep_insn) == TYPE_FP)
27072 return 1;
27073 break;
27074 case TYPE_FPLOAD:
27075 if (get_attr_update (insn) == UPDATE_NO
27076 && get_attr_type (dep_insn) == TYPE_MFFGPR)
27077 return 2;
27078 break;
27079 default:
27080 break;
27083 case REG_DEP_ANTI:
27084 /* Anti dependency; DEP_INSN reads a register that INSN writes some
27085 cycles later. */
27086 return 0;
27088 default:
27089 gcc_unreachable ();
27092 return cost;
27095 /* Debug version of rs6000_adjust_cost. */
27097 static int
27098 rs6000_debug_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn,
27099 int cost)
27101 int ret = rs6000_adjust_cost (insn, link, dep_insn, cost);
27103 if (ret != cost)
27105 const char *dep;
27107 switch (REG_NOTE_KIND (link))
27109 default: dep = "unknown depencency"; break;
27110 case REG_DEP_TRUE: dep = "data dependency"; break;
27111 case REG_DEP_OUTPUT: dep = "output dependency"; break;
27112 case REG_DEP_ANTI: dep = "anti depencency"; break;
27115 fprintf (stderr,
27116 "\nrs6000_adjust_cost, final cost = %d, orig cost = %d, "
27117 "%s, insn:\n", ret, cost, dep);
27119 debug_rtx (insn);
27122 return ret;
27125 /* The function returns a true if INSN is microcoded.
27126 Return false otherwise. */
27128 static bool
27129 is_microcoded_insn (rtx_insn *insn)
27131 if (!insn || !NONDEBUG_INSN_P (insn)
27132 || GET_CODE (PATTERN (insn)) == USE
27133 || GET_CODE (PATTERN (insn)) == CLOBBER)
27134 return false;
27136 if (rs6000_cpu_attr == CPU_CELL)
27137 return get_attr_cell_micro (insn) == CELL_MICRO_ALWAYS;
27139 if (rs6000_sched_groups
27140 && (rs6000_cpu == PROCESSOR_POWER4 || rs6000_cpu == PROCESSOR_POWER5))
27142 enum attr_type type = get_attr_type (insn);
27143 if ((type == TYPE_LOAD
27144 && get_attr_update (insn) == UPDATE_YES
27145 && get_attr_sign_extend (insn) == SIGN_EXTEND_YES)
27146 || ((type == TYPE_LOAD || type == TYPE_STORE)
27147 && get_attr_update (insn) == UPDATE_YES
27148 && get_attr_indexed (insn) == INDEXED_YES)
27149 || type == TYPE_MFCR)
27150 return true;
27153 return false;
27156 /* The function returns true if INSN is cracked into 2 instructions
27157 by the processor (and therefore occupies 2 issue slots). */
27159 static bool
27160 is_cracked_insn (rtx_insn *insn)
27162 if (!insn || !NONDEBUG_INSN_P (insn)
27163 || GET_CODE (PATTERN (insn)) == USE
27164 || GET_CODE (PATTERN (insn)) == CLOBBER)
27165 return false;
27167 if (rs6000_sched_groups
27168 && (rs6000_cpu == PROCESSOR_POWER4 || rs6000_cpu == PROCESSOR_POWER5))
27170 enum attr_type type = get_attr_type (insn);
27171 if ((type == TYPE_LOAD
27172 && get_attr_sign_extend (insn) == SIGN_EXTEND_YES
27173 && get_attr_update (insn) == UPDATE_NO)
27174 || (type == TYPE_LOAD
27175 && get_attr_sign_extend (insn) == SIGN_EXTEND_NO
27176 && get_attr_update (insn) == UPDATE_YES
27177 && get_attr_indexed (insn) == INDEXED_NO)
27178 || (type == TYPE_STORE
27179 && get_attr_update (insn) == UPDATE_YES
27180 && get_attr_indexed (insn) == INDEXED_NO)
27181 || ((type == TYPE_FPLOAD || type == TYPE_FPSTORE)
27182 && get_attr_update (insn) == UPDATE_YES)
27183 || type == TYPE_DELAYED_CR
27184 || (type == TYPE_EXTS
27185 && get_attr_dot (insn) == DOT_YES)
27186 || (type == TYPE_SHIFT
27187 && get_attr_dot (insn) == DOT_YES
27188 && get_attr_var_shift (insn) == VAR_SHIFT_NO)
27189 || (type == TYPE_MUL
27190 && get_attr_dot (insn) == DOT_YES)
27191 || type == TYPE_DIV
27192 || (type == TYPE_INSERT
27193 && get_attr_size (insn) == SIZE_32))
27194 return true;
27197 return false;
27200 /* The function returns true if INSN can be issued only from
27201 the branch slot. */
27203 static bool
27204 is_branch_slot_insn (rtx_insn *insn)
27206 if (!insn || !NONDEBUG_INSN_P (insn)
27207 || GET_CODE (PATTERN (insn)) == USE
27208 || GET_CODE (PATTERN (insn)) == CLOBBER)
27209 return false;
27211 if (rs6000_sched_groups)
27213 enum attr_type type = get_attr_type (insn);
27214 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
27215 return true;
27216 return false;
27219 return false;
27222 /* The function returns true if out_inst sets a value that is
27223 used in the address generation computation of in_insn */
27224 static bool
27225 set_to_load_agen (rtx_insn *out_insn, rtx_insn *in_insn)
27227 rtx out_set, in_set;
27229 /* For performance reasons, only handle the simple case where
27230 both loads are a single_set. */
27231 out_set = single_set (out_insn);
27232 if (out_set)
27234 in_set = single_set (in_insn);
27235 if (in_set)
27236 return reg_mentioned_p (SET_DEST (out_set), SET_SRC (in_set));
27239 return false;
27242 /* Try to determine base/offset/size parts of the given MEM.
27243 Return true if successful, false if all the values couldn't
27244 be determined.
27246 This function only looks for REG or REG+CONST address forms.
27247 REG+REG address form will return false. */
27249 static bool
27250 get_memref_parts (rtx mem, rtx *base, HOST_WIDE_INT *offset,
27251 HOST_WIDE_INT *size)
27253 rtx addr_rtx;
27254 if MEM_SIZE_KNOWN_P (mem)
27255 *size = MEM_SIZE (mem);
27256 else
27257 return false;
27259 addr_rtx = (XEXP (mem, 0));
27260 if (GET_CODE (addr_rtx) == PRE_MODIFY)
27261 addr_rtx = XEXP (addr_rtx, 1);
27263 *offset = 0;
27264 while (GET_CODE (addr_rtx) == PLUS
27265 && CONST_INT_P (XEXP (addr_rtx, 1)))
27267 *offset += INTVAL (XEXP (addr_rtx, 1));
27268 addr_rtx = XEXP (addr_rtx, 0);
27270 if (!REG_P (addr_rtx))
27271 return false;
27273 *base = addr_rtx;
27274 return true;
27277 /* The function returns true if the target storage location of
27278 mem1 is adjacent to the target storage location of mem2 */
27279 /* Return 1 if memory locations are adjacent. */
27281 static bool
27282 adjacent_mem_locations (rtx mem1, rtx mem2)
27284 rtx reg1, reg2;
27285 HOST_WIDE_INT off1, size1, off2, size2;
27287 if (get_memref_parts (mem1, &reg1, &off1, &size1)
27288 && get_memref_parts (mem2, &reg2, &off2, &size2))
27289 return ((REGNO (reg1) == REGNO (reg2))
27290 && ((off1 + size1 == off2)
27291 || (off2 + size2 == off1)));
27293 return false;
27296 /* This function returns true if it can be determined that the two MEM
27297 locations overlap by at least 1 byte based on base reg/offset/size. */
27299 static bool
27300 mem_locations_overlap (rtx mem1, rtx mem2)
27302 rtx reg1, reg2;
27303 HOST_WIDE_INT off1, size1, off2, size2;
27305 if (get_memref_parts (mem1, &reg1, &off1, &size1)
27306 && get_memref_parts (mem2, &reg2, &off2, &size2))
27307 return ((REGNO (reg1) == REGNO (reg2))
27308 && (((off1 <= off2) && (off1 + size1 > off2))
27309 || ((off2 <= off1) && (off2 + size2 > off1))));
27311 return false;
27314 /* A C statement (sans semicolon) to update the integer scheduling
27315 priority INSN_PRIORITY (INSN). Increase the priority to execute the
27316 INSN earlier, reduce the priority to execute INSN later. Do not
27317 define this macro if you do not need to adjust the scheduling
27318 priorities of insns. */
27320 static int
27321 rs6000_adjust_priority (rtx_insn *insn ATTRIBUTE_UNUSED, int priority)
27323 rtx load_mem, str_mem;
27324 /* On machines (like the 750) which have asymmetric integer units,
27325 where one integer unit can do multiply and divides and the other
27326 can't, reduce the priority of multiply/divide so it is scheduled
27327 before other integer operations. */
27329 #if 0
27330 if (! INSN_P (insn))
27331 return priority;
27333 if (GET_CODE (PATTERN (insn)) == USE)
27334 return priority;
27336 switch (rs6000_cpu_attr) {
27337 case CPU_PPC750:
27338 switch (get_attr_type (insn))
27340 default:
27341 break;
27343 case TYPE_MUL:
27344 case TYPE_DIV:
27345 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
27346 priority, priority);
27347 if (priority >= 0 && priority < 0x01000000)
27348 priority >>= 3;
27349 break;
27352 #endif
27354 if (insn_must_be_first_in_group (insn)
27355 && reload_completed
27356 && current_sched_info->sched_max_insns_priority
27357 && rs6000_sched_restricted_insns_priority)
27360 /* Prioritize insns that can be dispatched only in the first
27361 dispatch slot. */
27362 if (rs6000_sched_restricted_insns_priority == 1)
27363 /* Attach highest priority to insn. This means that in
27364 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
27365 precede 'priority' (critical path) considerations. */
27366 return current_sched_info->sched_max_insns_priority;
27367 else if (rs6000_sched_restricted_insns_priority == 2)
27368 /* Increase priority of insn by a minimal amount. This means that in
27369 haifa-sched.c:ready_sort(), only 'priority' (critical path)
27370 considerations precede dispatch-slot restriction considerations. */
27371 return (priority + 1);
27374 if (rs6000_cpu == PROCESSOR_POWER6
27375 && ((load_store_pendulum == -2 && is_load_insn (insn, &load_mem))
27376 || (load_store_pendulum == 2 && is_store_insn (insn, &str_mem))))
27377 /* Attach highest priority to insn if the scheduler has just issued two
27378 stores and this instruction is a load, or two loads and this instruction
27379 is a store. Power6 wants loads and stores scheduled alternately
27380 when possible */
27381 return current_sched_info->sched_max_insns_priority;
27383 return priority;
27386 /* Return true if the instruction is nonpipelined on the Cell. */
27387 static bool
27388 is_nonpipeline_insn (rtx_insn *insn)
27390 enum attr_type type;
27391 if (!insn || !NONDEBUG_INSN_P (insn)
27392 || GET_CODE (PATTERN (insn)) == USE
27393 || GET_CODE (PATTERN (insn)) == CLOBBER)
27394 return false;
27396 type = get_attr_type (insn);
27397 if (type == TYPE_MUL
27398 || type == TYPE_DIV
27399 || type == TYPE_SDIV
27400 || type == TYPE_DDIV
27401 || type == TYPE_SSQRT
27402 || type == TYPE_DSQRT
27403 || type == TYPE_MFCR
27404 || type == TYPE_MFCRF
27405 || type == TYPE_MFJMPR)
27407 return true;
27409 return false;
27413 /* Return how many instructions the machine can issue per cycle. */
27415 static int
27416 rs6000_issue_rate (void)
27418 /* Unless scheduling for register pressure, use issue rate of 1 for
27419 first scheduling pass to decrease degradation. */
27420 if (!reload_completed && !flag_sched_pressure)
27421 return 1;
27423 switch (rs6000_cpu_attr) {
27424 case CPU_RS64A:
27425 case CPU_PPC601: /* ? */
27426 case CPU_PPC7450:
27427 return 3;
27428 case CPU_PPC440:
27429 case CPU_PPC603:
27430 case CPU_PPC750:
27431 case CPU_PPC7400:
27432 case CPU_PPC8540:
27433 case CPU_PPC8548:
27434 case CPU_CELL:
27435 case CPU_PPCE300C2:
27436 case CPU_PPCE300C3:
27437 case CPU_PPCE500MC:
27438 case CPU_PPCE500MC64:
27439 case CPU_PPCE5500:
27440 case CPU_PPCE6500:
27441 case CPU_TITAN:
27442 return 2;
27443 case CPU_PPC476:
27444 case CPU_PPC604:
27445 case CPU_PPC604E:
27446 case CPU_PPC620:
27447 case CPU_PPC630:
27448 return 4;
27449 case CPU_POWER4:
27450 case CPU_POWER5:
27451 case CPU_POWER6:
27452 case CPU_POWER7:
27453 return 5;
27454 case CPU_POWER8:
27455 return 7;
27456 default:
27457 return 1;
27461 /* Return how many instructions to look ahead for better insn
27462 scheduling. */
27464 static int
27465 rs6000_use_sched_lookahead (void)
27467 switch (rs6000_cpu_attr)
27469 case CPU_PPC8540:
27470 case CPU_PPC8548:
27471 return 4;
27473 case CPU_CELL:
27474 return (reload_completed ? 8 : 0);
27476 default:
27477 return 0;
27481 /* We are choosing insn from the ready queue. Return zero if INSN can be
27482 chosen. */
27483 static int
27484 rs6000_use_sched_lookahead_guard (rtx_insn *insn, int ready_index)
27486 if (ready_index == 0)
27487 return 0;
27489 if (rs6000_cpu_attr != CPU_CELL)
27490 return 0;
27492 gcc_assert (insn != NULL_RTX && INSN_P (insn));
27494 if (!reload_completed
27495 || is_nonpipeline_insn (insn)
27496 || is_microcoded_insn (insn))
27497 return 1;
27499 return 0;
27502 /* Determine if PAT refers to memory. If so, set MEM_REF to the MEM rtx
27503 and return true. */
27505 static bool
27506 find_mem_ref (rtx pat, rtx *mem_ref)
27508 const char * fmt;
27509 int i, j;
27511 /* stack_tie does not produce any real memory traffic. */
27512 if (tie_operand (pat, VOIDmode))
27513 return false;
27515 if (GET_CODE (pat) == MEM)
27517 *mem_ref = pat;
27518 return true;
27521 /* Recursively process the pattern. */
27522 fmt = GET_RTX_FORMAT (GET_CODE (pat));
27524 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0; i--)
27526 if (fmt[i] == 'e')
27528 if (find_mem_ref (XEXP (pat, i), mem_ref))
27529 return true;
27531 else if (fmt[i] == 'E')
27532 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
27534 if (find_mem_ref (XVECEXP (pat, i, j), mem_ref))
27535 return true;
27539 return false;
27542 /* Determine if PAT is a PATTERN of a load insn. */
27544 static bool
27545 is_load_insn1 (rtx pat, rtx *load_mem)
27547 if (!pat || pat == NULL_RTX)
27548 return false;
27550 if (GET_CODE (pat) == SET)
27551 return find_mem_ref (SET_SRC (pat), load_mem);
27553 if (GET_CODE (pat) == PARALLEL)
27555 int i;
27557 for (i = 0; i < XVECLEN (pat, 0); i++)
27558 if (is_load_insn1 (XVECEXP (pat, 0, i), load_mem))
27559 return true;
27562 return false;
27565 /* Determine if INSN loads from memory. */
27567 static bool
27568 is_load_insn (rtx insn, rtx *load_mem)
27570 if (!insn || !INSN_P (insn))
27571 return false;
27573 if (CALL_P (insn))
27574 return false;
27576 return is_load_insn1 (PATTERN (insn), load_mem);
27579 /* Determine if PAT is a PATTERN of a store insn. */
27581 static bool
27582 is_store_insn1 (rtx pat, rtx *str_mem)
27584 if (!pat || pat == NULL_RTX)
27585 return false;
27587 if (GET_CODE (pat) == SET)
27588 return find_mem_ref (SET_DEST (pat), str_mem);
27590 if (GET_CODE (pat) == PARALLEL)
27592 int i;
27594 for (i = 0; i < XVECLEN (pat, 0); i++)
27595 if (is_store_insn1 (XVECEXP (pat, 0, i), str_mem))
27596 return true;
27599 return false;
27602 /* Determine if INSN stores to memory. */
27604 static bool
27605 is_store_insn (rtx insn, rtx *str_mem)
27607 if (!insn || !INSN_P (insn))
27608 return false;
27610 return is_store_insn1 (PATTERN (insn), str_mem);
27613 /* Returns whether the dependence between INSN and NEXT is considered
27614 costly by the given target. */
27616 static bool
27617 rs6000_is_costly_dependence (dep_t dep, int cost, int distance)
27619 rtx insn;
27620 rtx next;
27621 rtx load_mem, str_mem;
27623 /* If the flag is not enabled - no dependence is considered costly;
27624 allow all dependent insns in the same group.
27625 This is the most aggressive option. */
27626 if (rs6000_sched_costly_dep == no_dep_costly)
27627 return false;
27629 /* If the flag is set to 1 - a dependence is always considered costly;
27630 do not allow dependent instructions in the same group.
27631 This is the most conservative option. */
27632 if (rs6000_sched_costly_dep == all_deps_costly)
27633 return true;
27635 insn = DEP_PRO (dep);
27636 next = DEP_CON (dep);
27638 if (rs6000_sched_costly_dep == store_to_load_dep_costly
27639 && is_load_insn (next, &load_mem)
27640 && is_store_insn (insn, &str_mem))
27641 /* Prevent load after store in the same group. */
27642 return true;
27644 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
27645 && is_load_insn (next, &load_mem)
27646 && is_store_insn (insn, &str_mem)
27647 && DEP_TYPE (dep) == REG_DEP_TRUE
27648 && mem_locations_overlap(str_mem, load_mem))
27649 /* Prevent load after store in the same group if it is a true
27650 dependence. */
27651 return true;
27653 /* The flag is set to X; dependences with latency >= X are considered costly,
27654 and will not be scheduled in the same group. */
27655 if (rs6000_sched_costly_dep <= max_dep_latency
27656 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
27657 return true;
27659 return false;
27662 /* Return the next insn after INSN that is found before TAIL is reached,
27663 skipping any "non-active" insns - insns that will not actually occupy
27664 an issue slot. Return NULL_RTX if such an insn is not found. */
27666 static rtx_insn *
27667 get_next_active_insn (rtx_insn *insn, rtx_insn *tail)
27669 if (insn == NULL_RTX || insn == tail)
27670 return NULL;
27672 while (1)
27674 insn = NEXT_INSN (insn);
27675 if (insn == NULL_RTX || insn == tail)
27676 return NULL;
27678 if (CALL_P (insn)
27679 || JUMP_P (insn) || JUMP_TABLE_DATA_P (insn)
27680 || (NONJUMP_INSN_P (insn)
27681 && GET_CODE (PATTERN (insn)) != USE
27682 && GET_CODE (PATTERN (insn)) != CLOBBER
27683 && INSN_CODE (insn) != CODE_FOR_stack_tie))
27684 break;
27686 return insn;
27689 /* We are about to begin issuing insns for this clock cycle. */
27691 static int
27692 rs6000_sched_reorder (FILE *dump ATTRIBUTE_UNUSED, int sched_verbose,
27693 rtx_insn **ready ATTRIBUTE_UNUSED,
27694 int *pn_ready ATTRIBUTE_UNUSED,
27695 int clock_var ATTRIBUTE_UNUSED)
27697 int n_ready = *pn_ready;
27699 if (sched_verbose)
27700 fprintf (dump, "// rs6000_sched_reorder :\n");
27702 /* Reorder the ready list, if the second to last ready insn
27703 is a nonepipeline insn. */
27704 if (rs6000_cpu_attr == CPU_CELL && n_ready > 1)
27706 if (is_nonpipeline_insn (ready[n_ready - 1])
27707 && (recog_memoized (ready[n_ready - 2]) > 0))
27708 /* Simply swap first two insns. */
27709 std::swap (ready[n_ready - 1], ready[n_ready - 2]);
27712 if (rs6000_cpu == PROCESSOR_POWER6)
27713 load_store_pendulum = 0;
27715 return rs6000_issue_rate ();
27718 /* Like rs6000_sched_reorder, but called after issuing each insn. */
27720 static int
27721 rs6000_sched_reorder2 (FILE *dump, int sched_verbose, rtx_insn **ready,
27722 int *pn_ready, int clock_var ATTRIBUTE_UNUSED)
27724 if (sched_verbose)
27725 fprintf (dump, "// rs6000_sched_reorder2 :\n");
27727 /* For Power6, we need to handle some special cases to try and keep the
27728 store queue from overflowing and triggering expensive flushes.
27730 This code monitors how load and store instructions are being issued
27731 and skews the ready list one way or the other to increase the likelihood
27732 that a desired instruction is issued at the proper time.
27734 A couple of things are done. First, we maintain a "load_store_pendulum"
27735 to track the current state of load/store issue.
27737 - If the pendulum is at zero, then no loads or stores have been
27738 issued in the current cycle so we do nothing.
27740 - If the pendulum is 1, then a single load has been issued in this
27741 cycle and we attempt to locate another load in the ready list to
27742 issue with it.
27744 - If the pendulum is -2, then two stores have already been
27745 issued in this cycle, so we increase the priority of the first load
27746 in the ready list to increase it's likelihood of being chosen first
27747 in the next cycle.
27749 - If the pendulum is -1, then a single store has been issued in this
27750 cycle and we attempt to locate another store in the ready list to
27751 issue with it, preferring a store to an adjacent memory location to
27752 facilitate store pairing in the store queue.
27754 - If the pendulum is 2, then two loads have already been
27755 issued in this cycle, so we increase the priority of the first store
27756 in the ready list to increase it's likelihood of being chosen first
27757 in the next cycle.
27759 - If the pendulum < -2 or > 2, then do nothing.
27761 Note: This code covers the most common scenarios. There exist non
27762 load/store instructions which make use of the LSU and which
27763 would need to be accounted for to strictly model the behavior
27764 of the machine. Those instructions are currently unaccounted
27765 for to help minimize compile time overhead of this code.
27767 if (rs6000_cpu == PROCESSOR_POWER6 && last_scheduled_insn)
27769 int pos;
27770 int i;
27771 rtx_insn *tmp;
27772 rtx load_mem, str_mem;
27774 if (is_store_insn (last_scheduled_insn, &str_mem))
27775 /* Issuing a store, swing the load_store_pendulum to the left */
27776 load_store_pendulum--;
27777 else if (is_load_insn (last_scheduled_insn, &load_mem))
27778 /* Issuing a load, swing the load_store_pendulum to the right */
27779 load_store_pendulum++;
27780 else
27781 return cached_can_issue_more;
27783 /* If the pendulum is balanced, or there is only one instruction on
27784 the ready list, then all is well, so return. */
27785 if ((load_store_pendulum == 0) || (*pn_ready <= 1))
27786 return cached_can_issue_more;
27788 if (load_store_pendulum == 1)
27790 /* A load has been issued in this cycle. Scan the ready list
27791 for another load to issue with it */
27792 pos = *pn_ready-1;
27794 while (pos >= 0)
27796 if (is_load_insn (ready[pos], &load_mem))
27798 /* Found a load. Move it to the head of the ready list,
27799 and adjust it's priority so that it is more likely to
27800 stay there */
27801 tmp = ready[pos];
27802 for (i=pos; i<*pn_ready-1; i++)
27803 ready[i] = ready[i + 1];
27804 ready[*pn_ready-1] = tmp;
27806 if (!sel_sched_p () && INSN_PRIORITY_KNOWN (tmp))
27807 INSN_PRIORITY (tmp)++;
27808 break;
27810 pos--;
27813 else if (load_store_pendulum == -2)
27815 /* Two stores have been issued in this cycle. Increase the
27816 priority of the first load in the ready list to favor it for
27817 issuing in the next cycle. */
27818 pos = *pn_ready-1;
27820 while (pos >= 0)
27822 if (is_load_insn (ready[pos], &load_mem)
27823 && !sel_sched_p ()
27824 && INSN_PRIORITY_KNOWN (ready[pos]))
27826 INSN_PRIORITY (ready[pos])++;
27828 /* Adjust the pendulum to account for the fact that a load
27829 was found and increased in priority. This is to prevent
27830 increasing the priority of multiple loads */
27831 load_store_pendulum--;
27833 break;
27835 pos--;
27838 else if (load_store_pendulum == -1)
27840 /* A store has been issued in this cycle. Scan the ready list for
27841 another store to issue with it, preferring a store to an adjacent
27842 memory location */
27843 int first_store_pos = -1;
27845 pos = *pn_ready-1;
27847 while (pos >= 0)
27849 if (is_store_insn (ready[pos], &str_mem))
27851 rtx str_mem2;
27852 /* Maintain the index of the first store found on the
27853 list */
27854 if (first_store_pos == -1)
27855 first_store_pos = pos;
27857 if (is_store_insn (last_scheduled_insn, &str_mem2)
27858 && adjacent_mem_locations (str_mem, str_mem2))
27860 /* Found an adjacent store. Move it to the head of the
27861 ready list, and adjust it's priority so that it is
27862 more likely to stay there */
27863 tmp = ready[pos];
27864 for (i=pos; i<*pn_ready-1; i++)
27865 ready[i] = ready[i + 1];
27866 ready[*pn_ready-1] = tmp;
27868 if (!sel_sched_p () && INSN_PRIORITY_KNOWN (tmp))
27869 INSN_PRIORITY (tmp)++;
27871 first_store_pos = -1;
27873 break;
27876 pos--;
27879 if (first_store_pos >= 0)
27881 /* An adjacent store wasn't found, but a non-adjacent store was,
27882 so move the non-adjacent store to the front of the ready
27883 list, and adjust its priority so that it is more likely to
27884 stay there. */
27885 tmp = ready[first_store_pos];
27886 for (i=first_store_pos; i<*pn_ready-1; i++)
27887 ready[i] = ready[i + 1];
27888 ready[*pn_ready-1] = tmp;
27889 if (!sel_sched_p () && INSN_PRIORITY_KNOWN (tmp))
27890 INSN_PRIORITY (tmp)++;
27893 else if (load_store_pendulum == 2)
27895 /* Two loads have been issued in this cycle. Increase the priority
27896 of the first store in the ready list to favor it for issuing in
27897 the next cycle. */
27898 pos = *pn_ready-1;
27900 while (pos >= 0)
27902 if (is_store_insn (ready[pos], &str_mem)
27903 && !sel_sched_p ()
27904 && INSN_PRIORITY_KNOWN (ready[pos]))
27906 INSN_PRIORITY (ready[pos])++;
27908 /* Adjust the pendulum to account for the fact that a store
27909 was found and increased in priority. This is to prevent
27910 increasing the priority of multiple stores */
27911 load_store_pendulum++;
27913 break;
27915 pos--;
27920 return cached_can_issue_more;
27923 /* Return whether the presence of INSN causes a dispatch group termination
27924 of group WHICH_GROUP.
27926 If WHICH_GROUP == current_group, this function will return true if INSN
27927 causes the termination of the current group (i.e, the dispatch group to
27928 which INSN belongs). This means that INSN will be the last insn in the
27929 group it belongs to.
27931 If WHICH_GROUP == previous_group, this function will return true if INSN
27932 causes the termination of the previous group (i.e, the dispatch group that
27933 precedes the group to which INSN belongs). This means that INSN will be
27934 the first insn in the group it belongs to). */
27936 static bool
27937 insn_terminates_group_p (rtx_insn *insn, enum group_termination which_group)
27939 bool first, last;
27941 if (! insn)
27942 return false;
27944 first = insn_must_be_first_in_group (insn);
27945 last = insn_must_be_last_in_group (insn);
27947 if (first && last)
27948 return true;
27950 if (which_group == current_group)
27951 return last;
27952 else if (which_group == previous_group)
27953 return first;
27955 return false;
27959 static bool
27960 insn_must_be_first_in_group (rtx_insn *insn)
27962 enum attr_type type;
27964 if (!insn
27965 || NOTE_P (insn)
27966 || DEBUG_INSN_P (insn)
27967 || GET_CODE (PATTERN (insn)) == USE
27968 || GET_CODE (PATTERN (insn)) == CLOBBER)
27969 return false;
27971 switch (rs6000_cpu)
27973 case PROCESSOR_POWER5:
27974 if (is_cracked_insn (insn))
27975 return true;
27976 case PROCESSOR_POWER4:
27977 if (is_microcoded_insn (insn))
27978 return true;
27980 if (!rs6000_sched_groups)
27981 return false;
27983 type = get_attr_type (insn);
27985 switch (type)
27987 case TYPE_MFCR:
27988 case TYPE_MFCRF:
27989 case TYPE_MTCR:
27990 case TYPE_DELAYED_CR:
27991 case TYPE_CR_LOGICAL:
27992 case TYPE_MTJMPR:
27993 case TYPE_MFJMPR:
27994 case TYPE_DIV:
27995 case TYPE_LOAD_L:
27996 case TYPE_STORE_C:
27997 case TYPE_ISYNC:
27998 case TYPE_SYNC:
27999 return true;
28000 default:
28001 break;
28003 break;
28004 case PROCESSOR_POWER6:
28005 type = get_attr_type (insn);
28007 switch (type)
28009 case TYPE_EXTS:
28010 case TYPE_CNTLZ:
28011 case TYPE_TRAP:
28012 case TYPE_MUL:
28013 case TYPE_INSERT:
28014 case TYPE_FPCOMPARE:
28015 case TYPE_MFCR:
28016 case TYPE_MTCR:
28017 case TYPE_MFJMPR:
28018 case TYPE_MTJMPR:
28019 case TYPE_ISYNC:
28020 case TYPE_SYNC:
28021 case TYPE_LOAD_L:
28022 case TYPE_STORE_C:
28023 return true;
28024 case TYPE_SHIFT:
28025 if (get_attr_dot (insn) == DOT_NO
28026 || get_attr_var_shift (insn) == VAR_SHIFT_NO)
28027 return true;
28028 else
28029 break;
28030 case TYPE_DIV:
28031 if (get_attr_size (insn) == SIZE_32)
28032 return true;
28033 else
28034 break;
28035 case TYPE_LOAD:
28036 case TYPE_STORE:
28037 case TYPE_FPLOAD:
28038 case TYPE_FPSTORE:
28039 if (get_attr_update (insn) == UPDATE_YES)
28040 return true;
28041 else
28042 break;
28043 default:
28044 break;
28046 break;
28047 case PROCESSOR_POWER7:
28048 type = get_attr_type (insn);
28050 switch (type)
28052 case TYPE_CR_LOGICAL:
28053 case TYPE_MFCR:
28054 case TYPE_MFCRF:
28055 case TYPE_MTCR:
28056 case TYPE_DIV:
28057 case TYPE_ISYNC:
28058 case TYPE_LOAD_L:
28059 case TYPE_STORE_C:
28060 case TYPE_MFJMPR:
28061 case TYPE_MTJMPR:
28062 return true;
28063 case TYPE_MUL:
28064 case TYPE_SHIFT:
28065 case TYPE_EXTS:
28066 if (get_attr_dot (insn) == DOT_YES)
28067 return true;
28068 else
28069 break;
28070 case TYPE_LOAD:
28071 if (get_attr_sign_extend (insn) == SIGN_EXTEND_YES
28072 || get_attr_update (insn) == UPDATE_YES)
28073 return true;
28074 else
28075 break;
28076 case TYPE_STORE:
28077 case TYPE_FPLOAD:
28078 case TYPE_FPSTORE:
28079 if (get_attr_update (insn) == UPDATE_YES)
28080 return true;
28081 else
28082 break;
28083 default:
28084 break;
28086 break;
28087 case PROCESSOR_POWER8:
28088 type = get_attr_type (insn);
28090 switch (type)
28092 case TYPE_CR_LOGICAL:
28093 case TYPE_DELAYED_CR:
28094 case TYPE_MFCR:
28095 case TYPE_MFCRF:
28096 case TYPE_MTCR:
28097 case TYPE_SYNC:
28098 case TYPE_ISYNC:
28099 case TYPE_LOAD_L:
28100 case TYPE_STORE_C:
28101 case TYPE_VECSTORE:
28102 case TYPE_MFJMPR:
28103 case TYPE_MTJMPR:
28104 return true;
28105 case TYPE_SHIFT:
28106 case TYPE_EXTS:
28107 case TYPE_MUL:
28108 if (get_attr_dot (insn) == DOT_YES)
28109 return true;
28110 else
28111 break;
28112 case TYPE_LOAD:
28113 if (get_attr_sign_extend (insn) == SIGN_EXTEND_YES
28114 || get_attr_update (insn) == UPDATE_YES)
28115 return true;
28116 else
28117 break;
28118 case TYPE_STORE:
28119 if (get_attr_update (insn) == UPDATE_YES
28120 && get_attr_indexed (insn) == INDEXED_YES)
28121 return true;
28122 else
28123 break;
28124 default:
28125 break;
28127 break;
28128 default:
28129 break;
28132 return false;
28135 static bool
28136 insn_must_be_last_in_group (rtx_insn *insn)
28138 enum attr_type type;
28140 if (!insn
28141 || NOTE_P (insn)
28142 || DEBUG_INSN_P (insn)
28143 || GET_CODE (PATTERN (insn)) == USE
28144 || GET_CODE (PATTERN (insn)) == CLOBBER)
28145 return false;
28147 switch (rs6000_cpu) {
28148 case PROCESSOR_POWER4:
28149 case PROCESSOR_POWER5:
28150 if (is_microcoded_insn (insn))
28151 return true;
28153 if (is_branch_slot_insn (insn))
28154 return true;
28156 break;
28157 case PROCESSOR_POWER6:
28158 type = get_attr_type (insn);
28160 switch (type)
28162 case TYPE_EXTS:
28163 case TYPE_CNTLZ:
28164 case TYPE_TRAP:
28165 case TYPE_MUL:
28166 case TYPE_FPCOMPARE:
28167 case TYPE_MFCR:
28168 case TYPE_MTCR:
28169 case TYPE_MFJMPR:
28170 case TYPE_MTJMPR:
28171 case TYPE_ISYNC:
28172 case TYPE_SYNC:
28173 case TYPE_LOAD_L:
28174 case TYPE_STORE_C:
28175 return true;
28176 case TYPE_SHIFT:
28177 if (get_attr_dot (insn) == DOT_NO
28178 || get_attr_var_shift (insn) == VAR_SHIFT_NO)
28179 return true;
28180 else
28181 break;
28182 case TYPE_DIV:
28183 if (get_attr_size (insn) == SIZE_32)
28184 return true;
28185 else
28186 break;
28187 default:
28188 break;
28190 break;
28191 case PROCESSOR_POWER7:
28192 type = get_attr_type (insn);
28194 switch (type)
28196 case TYPE_ISYNC:
28197 case TYPE_SYNC:
28198 case TYPE_LOAD_L:
28199 case TYPE_STORE_C:
28200 return true;
28201 case TYPE_LOAD:
28202 if (get_attr_sign_extend (insn) == SIGN_EXTEND_YES
28203 && get_attr_update (insn) == UPDATE_YES)
28204 return true;
28205 else
28206 break;
28207 case TYPE_STORE:
28208 if (get_attr_update (insn) == UPDATE_YES
28209 && get_attr_indexed (insn) == INDEXED_YES)
28210 return true;
28211 else
28212 break;
28213 default:
28214 break;
28216 break;
28217 case PROCESSOR_POWER8:
28218 type = get_attr_type (insn);
28220 switch (type)
28222 case TYPE_MFCR:
28223 case TYPE_MTCR:
28224 case TYPE_ISYNC:
28225 case TYPE_SYNC:
28226 case TYPE_LOAD_L:
28227 case TYPE_STORE_C:
28228 return true;
28229 case TYPE_LOAD:
28230 if (get_attr_sign_extend (insn) == SIGN_EXTEND_YES
28231 && get_attr_update (insn) == UPDATE_YES)
28232 return true;
28233 else
28234 break;
28235 case TYPE_STORE:
28236 if (get_attr_update (insn) == UPDATE_YES
28237 && get_attr_indexed (insn) == INDEXED_YES)
28238 return true;
28239 else
28240 break;
28241 default:
28242 break;
28244 break;
28245 default:
28246 break;
28249 return false;
28252 /* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
28253 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
28255 static bool
28256 is_costly_group (rtx *group_insns, rtx next_insn)
28258 int i;
28259 int issue_rate = rs6000_issue_rate ();
28261 for (i = 0; i < issue_rate; i++)
28263 sd_iterator_def sd_it;
28264 dep_t dep;
28265 rtx insn = group_insns[i];
28267 if (!insn)
28268 continue;
28270 FOR_EACH_DEP (insn, SD_LIST_RES_FORW, sd_it, dep)
28272 rtx next = DEP_CON (dep);
28274 if (next == next_insn
28275 && rs6000_is_costly_dependence (dep, dep_cost (dep), 0))
28276 return true;
28280 return false;
28283 /* Utility of the function redefine_groups.
28284 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
28285 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
28286 to keep it "far" (in a separate group) from GROUP_INSNS, following
28287 one of the following schemes, depending on the value of the flag
28288 -minsert_sched_nops = X:
28289 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
28290 in order to force NEXT_INSN into a separate group.
28291 (2) X < sched_finish_regroup_exact: insert exactly X nops.
28292 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
28293 insertion (has a group just ended, how many vacant issue slots remain in the
28294 last group, and how many dispatch groups were encountered so far). */
28296 static int
28297 force_new_group (int sched_verbose, FILE *dump, rtx *group_insns,
28298 rtx_insn *next_insn, bool *group_end, int can_issue_more,
28299 int *group_count)
28301 rtx nop;
28302 bool force;
28303 int issue_rate = rs6000_issue_rate ();
28304 bool end = *group_end;
28305 int i;
28307 if (next_insn == NULL_RTX || DEBUG_INSN_P (next_insn))
28308 return can_issue_more;
28310 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
28311 return can_issue_more;
28313 force = is_costly_group (group_insns, next_insn);
28314 if (!force)
28315 return can_issue_more;
28317 if (sched_verbose > 6)
28318 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
28319 *group_count ,can_issue_more);
28321 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
28323 if (*group_end)
28324 can_issue_more = 0;
28326 /* Since only a branch can be issued in the last issue_slot, it is
28327 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
28328 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
28329 in this case the last nop will start a new group and the branch
28330 will be forced to the new group. */
28331 if (can_issue_more && !is_branch_slot_insn (next_insn))
28332 can_issue_more--;
28334 /* Do we have a special group ending nop? */
28335 if (rs6000_cpu_attr == CPU_POWER6 || rs6000_cpu_attr == CPU_POWER7
28336 || rs6000_cpu_attr == CPU_POWER8)
28338 nop = gen_group_ending_nop ();
28339 emit_insn_before (nop, next_insn);
28340 can_issue_more = 0;
28342 else
28343 while (can_issue_more > 0)
28345 nop = gen_nop ();
28346 emit_insn_before (nop, next_insn);
28347 can_issue_more--;
28350 *group_end = true;
28351 return 0;
28354 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
28356 int n_nops = rs6000_sched_insert_nops;
28358 /* Nops can't be issued from the branch slot, so the effective
28359 issue_rate for nops is 'issue_rate - 1'. */
28360 if (can_issue_more == 0)
28361 can_issue_more = issue_rate;
28362 can_issue_more--;
28363 if (can_issue_more == 0)
28365 can_issue_more = issue_rate - 1;
28366 (*group_count)++;
28367 end = true;
28368 for (i = 0; i < issue_rate; i++)
28370 group_insns[i] = 0;
28374 while (n_nops > 0)
28376 nop = gen_nop ();
28377 emit_insn_before (nop, next_insn);
28378 if (can_issue_more == issue_rate - 1) /* new group begins */
28379 end = false;
28380 can_issue_more--;
28381 if (can_issue_more == 0)
28383 can_issue_more = issue_rate - 1;
28384 (*group_count)++;
28385 end = true;
28386 for (i = 0; i < issue_rate; i++)
28388 group_insns[i] = 0;
28391 n_nops--;
28394 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
28395 can_issue_more++;
28397 /* Is next_insn going to start a new group? */
28398 *group_end
28399 = (end
28400 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
28401 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
28402 || (can_issue_more < issue_rate &&
28403 insn_terminates_group_p (next_insn, previous_group)));
28404 if (*group_end && end)
28405 (*group_count)--;
28407 if (sched_verbose > 6)
28408 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
28409 *group_count, can_issue_more);
28410 return can_issue_more;
28413 return can_issue_more;
28416 /* This function tries to synch the dispatch groups that the compiler "sees"
28417 with the dispatch groups that the processor dispatcher is expected to
28418 form in practice. It tries to achieve this synchronization by forcing the
28419 estimated processor grouping on the compiler (as opposed to the function
28420 'pad_goups' which tries to force the scheduler's grouping on the processor).
28422 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
28423 examines the (estimated) dispatch groups that will be formed by the processor
28424 dispatcher. It marks these group boundaries to reflect the estimated
28425 processor grouping, overriding the grouping that the scheduler had marked.
28426 Depending on the value of the flag '-minsert-sched-nops' this function can
28427 force certain insns into separate groups or force a certain distance between
28428 them by inserting nops, for example, if there exists a "costly dependence"
28429 between the insns.
28431 The function estimates the group boundaries that the processor will form as
28432 follows: It keeps track of how many vacant issue slots are available after
28433 each insn. A subsequent insn will start a new group if one of the following
28434 4 cases applies:
28435 - no more vacant issue slots remain in the current dispatch group.
28436 - only the last issue slot, which is the branch slot, is vacant, but the next
28437 insn is not a branch.
28438 - only the last 2 or less issue slots, including the branch slot, are vacant,
28439 which means that a cracked insn (which occupies two issue slots) can't be
28440 issued in this group.
28441 - less than 'issue_rate' slots are vacant, and the next insn always needs to
28442 start a new group. */
28444 static int
28445 redefine_groups (FILE *dump, int sched_verbose, rtx_insn *prev_head_insn,
28446 rtx_insn *tail)
28448 rtx_insn *insn, *next_insn;
28449 int issue_rate;
28450 int can_issue_more;
28451 int slot, i;
28452 bool group_end;
28453 int group_count = 0;
28454 rtx *group_insns;
28456 /* Initialize. */
28457 issue_rate = rs6000_issue_rate ();
28458 group_insns = XALLOCAVEC (rtx, issue_rate);
28459 for (i = 0; i < issue_rate; i++)
28461 group_insns[i] = 0;
28463 can_issue_more = issue_rate;
28464 slot = 0;
28465 insn = get_next_active_insn (prev_head_insn, tail);
28466 group_end = false;
28468 while (insn != NULL_RTX)
28470 slot = (issue_rate - can_issue_more);
28471 group_insns[slot] = insn;
28472 can_issue_more =
28473 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
28474 if (insn_terminates_group_p (insn, current_group))
28475 can_issue_more = 0;
28477 next_insn = get_next_active_insn (insn, tail);
28478 if (next_insn == NULL_RTX)
28479 return group_count + 1;
28481 /* Is next_insn going to start a new group? */
28482 group_end
28483 = (can_issue_more == 0
28484 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
28485 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
28486 || (can_issue_more < issue_rate &&
28487 insn_terminates_group_p (next_insn, previous_group)));
28489 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
28490 next_insn, &group_end, can_issue_more,
28491 &group_count);
28493 if (group_end)
28495 group_count++;
28496 can_issue_more = 0;
28497 for (i = 0; i < issue_rate; i++)
28499 group_insns[i] = 0;
28503 if (GET_MODE (next_insn) == TImode && can_issue_more)
28504 PUT_MODE (next_insn, VOIDmode);
28505 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
28506 PUT_MODE (next_insn, TImode);
28508 insn = next_insn;
28509 if (can_issue_more == 0)
28510 can_issue_more = issue_rate;
28511 } /* while */
28513 return group_count;
28516 /* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
28517 dispatch group boundaries that the scheduler had marked. Pad with nops
28518 any dispatch groups which have vacant issue slots, in order to force the
28519 scheduler's grouping on the processor dispatcher. The function
28520 returns the number of dispatch groups found. */
28522 static int
28523 pad_groups (FILE *dump, int sched_verbose, rtx_insn *prev_head_insn,
28524 rtx_insn *tail)
28526 rtx_insn *insn, *next_insn;
28527 rtx nop;
28528 int issue_rate;
28529 int can_issue_more;
28530 int group_end;
28531 int group_count = 0;
28533 /* Initialize issue_rate. */
28534 issue_rate = rs6000_issue_rate ();
28535 can_issue_more = issue_rate;
28537 insn = get_next_active_insn (prev_head_insn, tail);
28538 next_insn = get_next_active_insn (insn, tail);
28540 while (insn != NULL_RTX)
28542 can_issue_more =
28543 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
28545 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
28547 if (next_insn == NULL_RTX)
28548 break;
28550 if (group_end)
28552 /* If the scheduler had marked group termination at this location
28553 (between insn and next_insn), and neither insn nor next_insn will
28554 force group termination, pad the group with nops to force group
28555 termination. */
28556 if (can_issue_more
28557 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
28558 && !insn_terminates_group_p (insn, current_group)
28559 && !insn_terminates_group_p (next_insn, previous_group))
28561 if (!is_branch_slot_insn (next_insn))
28562 can_issue_more--;
28564 while (can_issue_more)
28566 nop = gen_nop ();
28567 emit_insn_before (nop, next_insn);
28568 can_issue_more--;
28572 can_issue_more = issue_rate;
28573 group_count++;
28576 insn = next_insn;
28577 next_insn = get_next_active_insn (insn, tail);
28580 return group_count;
28583 /* We're beginning a new block. Initialize data structures as necessary. */
28585 static void
28586 rs6000_sched_init (FILE *dump ATTRIBUTE_UNUSED,
28587 int sched_verbose ATTRIBUTE_UNUSED,
28588 int max_ready ATTRIBUTE_UNUSED)
28590 last_scheduled_insn = NULL_RTX;
28591 load_store_pendulum = 0;
28594 /* The following function is called at the end of scheduling BB.
28595 After reload, it inserts nops at insn group bundling. */
28597 static void
28598 rs6000_sched_finish (FILE *dump, int sched_verbose)
28600 int n_groups;
28602 if (sched_verbose)
28603 fprintf (dump, "=== Finishing schedule.\n");
28605 if (reload_completed && rs6000_sched_groups)
28607 /* Do not run sched_finish hook when selective scheduling enabled. */
28608 if (sel_sched_p ())
28609 return;
28611 if (rs6000_sched_insert_nops == sched_finish_none)
28612 return;
28614 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
28615 n_groups = pad_groups (dump, sched_verbose,
28616 current_sched_info->prev_head,
28617 current_sched_info->next_tail);
28618 else
28619 n_groups = redefine_groups (dump, sched_verbose,
28620 current_sched_info->prev_head,
28621 current_sched_info->next_tail);
28623 if (sched_verbose >= 6)
28625 fprintf (dump, "ngroups = %d\n", n_groups);
28626 print_rtl (dump, current_sched_info->prev_head);
28627 fprintf (dump, "Done finish_sched\n");
28632 struct _rs6000_sched_context
28634 short cached_can_issue_more;
28635 rtx last_scheduled_insn;
28636 int load_store_pendulum;
28639 typedef struct _rs6000_sched_context rs6000_sched_context_def;
28640 typedef rs6000_sched_context_def *rs6000_sched_context_t;
28642 /* Allocate store for new scheduling context. */
28643 static void *
28644 rs6000_alloc_sched_context (void)
28646 return xmalloc (sizeof (rs6000_sched_context_def));
28649 /* If CLEAN_P is true then initializes _SC with clean data,
28650 and from the global context otherwise. */
28651 static void
28652 rs6000_init_sched_context (void *_sc, bool clean_p)
28654 rs6000_sched_context_t sc = (rs6000_sched_context_t) _sc;
28656 if (clean_p)
28658 sc->cached_can_issue_more = 0;
28659 sc->last_scheduled_insn = NULL_RTX;
28660 sc->load_store_pendulum = 0;
28662 else
28664 sc->cached_can_issue_more = cached_can_issue_more;
28665 sc->last_scheduled_insn = last_scheduled_insn;
28666 sc->load_store_pendulum = load_store_pendulum;
28670 /* Sets the global scheduling context to the one pointed to by _SC. */
28671 static void
28672 rs6000_set_sched_context (void *_sc)
28674 rs6000_sched_context_t sc = (rs6000_sched_context_t) _sc;
28676 gcc_assert (sc != NULL);
28678 cached_can_issue_more = sc->cached_can_issue_more;
28679 last_scheduled_insn = sc->last_scheduled_insn;
28680 load_store_pendulum = sc->load_store_pendulum;
28683 /* Free _SC. */
28684 static void
28685 rs6000_free_sched_context (void *_sc)
28687 gcc_assert (_sc != NULL);
28689 free (_sc);
28693 /* Length in units of the trampoline for entering a nested function. */
28696 rs6000_trampoline_size (void)
28698 int ret = 0;
28700 switch (DEFAULT_ABI)
28702 default:
28703 gcc_unreachable ();
28705 case ABI_AIX:
28706 ret = (TARGET_32BIT) ? 12 : 24;
28707 break;
28709 case ABI_ELFv2:
28710 gcc_assert (!TARGET_32BIT);
28711 ret = 32;
28712 break;
28714 case ABI_DARWIN:
28715 case ABI_V4:
28716 ret = (TARGET_32BIT) ? 40 : 48;
28717 break;
28720 return ret;
28723 /* Emit RTL insns to initialize the variable parts of a trampoline.
28724 FNADDR is an RTX for the address of the function's pure code.
28725 CXT is an RTX for the static chain value for the function. */
28727 static void
28728 rs6000_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt)
28730 int regsize = (TARGET_32BIT) ? 4 : 8;
28731 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
28732 rtx ctx_reg = force_reg (Pmode, cxt);
28733 rtx addr = force_reg (Pmode, XEXP (m_tramp, 0));
28735 switch (DEFAULT_ABI)
28737 default:
28738 gcc_unreachable ();
28740 /* Under AIX, just build the 3 word function descriptor */
28741 case ABI_AIX:
28743 rtx fnmem, fn_reg, toc_reg;
28745 if (!TARGET_POINTERS_TO_NESTED_FUNCTIONS)
28746 error ("You cannot take the address of a nested function if you use "
28747 "the -mno-pointers-to-nested-functions option.");
28749 fnmem = gen_const_mem (Pmode, force_reg (Pmode, fnaddr));
28750 fn_reg = gen_reg_rtx (Pmode);
28751 toc_reg = gen_reg_rtx (Pmode);
28753 /* Macro to shorten the code expansions below. */
28754 # define MEM_PLUS(MEM, OFFSET) adjust_address (MEM, Pmode, OFFSET)
28756 m_tramp = replace_equiv_address (m_tramp, addr);
28758 emit_move_insn (fn_reg, MEM_PLUS (fnmem, 0));
28759 emit_move_insn (toc_reg, MEM_PLUS (fnmem, regsize));
28760 emit_move_insn (MEM_PLUS (m_tramp, 0), fn_reg);
28761 emit_move_insn (MEM_PLUS (m_tramp, regsize), toc_reg);
28762 emit_move_insn (MEM_PLUS (m_tramp, 2*regsize), ctx_reg);
28764 # undef MEM_PLUS
28766 break;
28768 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
28769 case ABI_ELFv2:
28770 case ABI_DARWIN:
28771 case ABI_V4:
28772 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__trampoline_setup"),
28773 LCT_NORMAL, VOIDmode, 4,
28774 addr, Pmode,
28775 GEN_INT (rs6000_trampoline_size ()), SImode,
28776 fnaddr, Pmode,
28777 ctx_reg, Pmode);
28778 break;
28783 /* Returns TRUE iff the target attribute indicated by ATTR_ID takes a plain
28784 identifier as an argument, so the front end shouldn't look it up. */
28786 static bool
28787 rs6000_attribute_takes_identifier_p (const_tree attr_id)
28789 return is_attribute_p ("altivec", attr_id);
28792 /* Handle the "altivec" attribute. The attribute may have
28793 arguments as follows:
28795 __attribute__((altivec(vector__)))
28796 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
28797 __attribute__((altivec(bool__))) (always followed by 'unsigned')
28799 and may appear more than once (e.g., 'vector bool char') in a
28800 given declaration. */
28802 static tree
28803 rs6000_handle_altivec_attribute (tree *node,
28804 tree name ATTRIBUTE_UNUSED,
28805 tree args,
28806 int flags ATTRIBUTE_UNUSED,
28807 bool *no_add_attrs)
28809 tree type = *node, result = NULL_TREE;
28810 machine_mode mode;
28811 int unsigned_p;
28812 char altivec_type
28813 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
28814 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
28815 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
28816 : '?');
28818 while (POINTER_TYPE_P (type)
28819 || TREE_CODE (type) == FUNCTION_TYPE
28820 || TREE_CODE (type) == METHOD_TYPE
28821 || TREE_CODE (type) == ARRAY_TYPE)
28822 type = TREE_TYPE (type);
28824 mode = TYPE_MODE (type);
28826 /* Check for invalid AltiVec type qualifiers. */
28827 if (type == long_double_type_node)
28828 error ("use of %<long double%> in AltiVec types is invalid");
28829 else if (type == boolean_type_node)
28830 error ("use of boolean types in AltiVec types is invalid");
28831 else if (TREE_CODE (type) == COMPLEX_TYPE)
28832 error ("use of %<complex%> in AltiVec types is invalid");
28833 else if (DECIMAL_FLOAT_MODE_P (mode))
28834 error ("use of decimal floating point types in AltiVec types is invalid");
28835 else if (!TARGET_VSX)
28837 if (type == long_unsigned_type_node || type == long_integer_type_node)
28839 if (TARGET_64BIT)
28840 error ("use of %<long%> in AltiVec types is invalid for "
28841 "64-bit code without -mvsx");
28842 else if (rs6000_warn_altivec_long)
28843 warning (0, "use of %<long%> in AltiVec types is deprecated; "
28844 "use %<int%>");
28846 else if (type == long_long_unsigned_type_node
28847 || type == long_long_integer_type_node)
28848 error ("use of %<long long%> in AltiVec types is invalid without "
28849 "-mvsx");
28850 else if (type == double_type_node)
28851 error ("use of %<double%> in AltiVec types is invalid without -mvsx");
28854 switch (altivec_type)
28856 case 'v':
28857 unsigned_p = TYPE_UNSIGNED (type);
28858 switch (mode)
28860 case TImode:
28861 result = (unsigned_p ? unsigned_V1TI_type_node : V1TI_type_node);
28862 break;
28863 case DImode:
28864 result = (unsigned_p ? unsigned_V2DI_type_node : V2DI_type_node);
28865 break;
28866 case SImode:
28867 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
28868 break;
28869 case HImode:
28870 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
28871 break;
28872 case QImode:
28873 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
28874 break;
28875 case SFmode: result = V4SF_type_node; break;
28876 case DFmode: result = V2DF_type_node; break;
28877 /* If the user says 'vector int bool', we may be handed the 'bool'
28878 attribute _before_ the 'vector' attribute, and so select the
28879 proper type in the 'b' case below. */
28880 case V4SImode: case V8HImode: case V16QImode: case V4SFmode:
28881 case V2DImode: case V2DFmode:
28882 result = type;
28883 default: break;
28885 break;
28886 case 'b':
28887 switch (mode)
28889 case DImode: case V2DImode: result = bool_V2DI_type_node; break;
28890 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
28891 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
28892 case QImode: case V16QImode: result = bool_V16QI_type_node;
28893 default: break;
28895 break;
28896 case 'p':
28897 switch (mode)
28899 case V8HImode: result = pixel_V8HI_type_node;
28900 default: break;
28902 default: break;
28905 /* Propagate qualifiers attached to the element type
28906 onto the vector type. */
28907 if (result && result != type && TYPE_QUALS (type))
28908 result = build_qualified_type (result, TYPE_QUALS (type));
28910 *no_add_attrs = true; /* No need to hang on to the attribute. */
28912 if (result)
28913 *node = lang_hooks.types.reconstruct_complex_type (*node, result);
28915 return NULL_TREE;
28918 /* AltiVec defines four built-in scalar types that serve as vector
28919 elements; we must teach the compiler how to mangle them. */
28921 static const char *
28922 rs6000_mangle_type (const_tree type)
28924 type = TYPE_MAIN_VARIANT (type);
28926 if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
28927 && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
28928 return NULL;
28930 if (type == bool_char_type_node) return "U6__boolc";
28931 if (type == bool_short_type_node) return "U6__bools";
28932 if (type == pixel_type_node) return "u7__pixel";
28933 if (type == bool_int_type_node) return "U6__booli";
28934 if (type == bool_long_type_node) return "U6__booll";
28936 /* Mangle IBM extended float long double as `g' (__float128) on
28937 powerpc*-linux where long-double-64 previously was the default. */
28938 if (TYPE_MAIN_VARIANT (type) == long_double_type_node
28939 && TARGET_ELF
28940 && TARGET_LONG_DOUBLE_128
28941 && !TARGET_IEEEQUAD)
28942 return "g";
28944 /* For all other types, use normal C++ mangling. */
28945 return NULL;
28948 /* Handle a "longcall" or "shortcall" attribute; arguments as in
28949 struct attribute_spec.handler. */
28951 static tree
28952 rs6000_handle_longcall_attribute (tree *node, tree name,
28953 tree args ATTRIBUTE_UNUSED,
28954 int flags ATTRIBUTE_UNUSED,
28955 bool *no_add_attrs)
28957 if (TREE_CODE (*node) != FUNCTION_TYPE
28958 && TREE_CODE (*node) != FIELD_DECL
28959 && TREE_CODE (*node) != TYPE_DECL)
28961 warning (OPT_Wattributes, "%qE attribute only applies to functions",
28962 name);
28963 *no_add_attrs = true;
28966 return NULL_TREE;
28969 /* Set longcall attributes on all functions declared when
28970 rs6000_default_long_calls is true. */
28971 static void
28972 rs6000_set_default_type_attributes (tree type)
28974 if (rs6000_default_long_calls
28975 && (TREE_CODE (type) == FUNCTION_TYPE
28976 || TREE_CODE (type) == METHOD_TYPE))
28977 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
28978 NULL_TREE,
28979 TYPE_ATTRIBUTES (type));
28981 #if TARGET_MACHO
28982 darwin_set_default_type_attributes (type);
28983 #endif
28986 /* Return a reference suitable for calling a function with the
28987 longcall attribute. */
28990 rs6000_longcall_ref (rtx call_ref)
28992 const char *call_name;
28993 tree node;
28995 if (GET_CODE (call_ref) != SYMBOL_REF)
28996 return call_ref;
28998 /* System V adds '.' to the internal name, so skip them. */
28999 call_name = XSTR (call_ref, 0);
29000 if (*call_name == '.')
29002 while (*call_name == '.')
29003 call_name++;
29005 node = get_identifier (call_name);
29006 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
29009 return force_reg (Pmode, call_ref);
29012 #ifndef TARGET_USE_MS_BITFIELD_LAYOUT
29013 #define TARGET_USE_MS_BITFIELD_LAYOUT 0
29014 #endif
29016 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
29017 struct attribute_spec.handler. */
29018 static tree
29019 rs6000_handle_struct_attribute (tree *node, tree name,
29020 tree args ATTRIBUTE_UNUSED,
29021 int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
29023 tree *type = NULL;
29024 if (DECL_P (*node))
29026 if (TREE_CODE (*node) == TYPE_DECL)
29027 type = &TREE_TYPE (*node);
29029 else
29030 type = node;
29032 if (!(type && (TREE_CODE (*type) == RECORD_TYPE
29033 || TREE_CODE (*type) == UNION_TYPE)))
29035 warning (OPT_Wattributes, "%qE attribute ignored", name);
29036 *no_add_attrs = true;
29039 else if ((is_attribute_p ("ms_struct", name)
29040 && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
29041 || ((is_attribute_p ("gcc_struct", name)
29042 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
29044 warning (OPT_Wattributes, "%qE incompatible attribute ignored",
29045 name);
29046 *no_add_attrs = true;
29049 return NULL_TREE;
29052 static bool
29053 rs6000_ms_bitfield_layout_p (const_tree record_type)
29055 return (TARGET_USE_MS_BITFIELD_LAYOUT &&
29056 !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
29057 || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type));
29060 #ifdef USING_ELFOS_H
29062 /* A get_unnamed_section callback, used for switching to toc_section. */
29064 static void
29065 rs6000_elf_output_toc_section_asm_op (const void *data ATTRIBUTE_UNUSED)
29067 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
29068 && TARGET_MINIMAL_TOC
29069 && !TARGET_RELOCATABLE)
29071 if (!toc_initialized)
29073 toc_initialized = 1;
29074 fprintf (asm_out_file, "%s\n", TOC_SECTION_ASM_OP);
29075 (*targetm.asm_out.internal_label) (asm_out_file, "LCTOC", 0);
29076 fprintf (asm_out_file, "\t.tc ");
29077 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (asm_out_file, "LCTOC1[TC],");
29078 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (asm_out_file, "LCTOC1");
29079 fprintf (asm_out_file, "\n");
29081 fprintf (asm_out_file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
29082 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (asm_out_file, "LCTOC1");
29083 fprintf (asm_out_file, " = .+32768\n");
29085 else
29086 fprintf (asm_out_file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
29088 else if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
29089 && !TARGET_RELOCATABLE)
29090 fprintf (asm_out_file, "%s\n", TOC_SECTION_ASM_OP);
29091 else
29093 fprintf (asm_out_file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
29094 if (!toc_initialized)
29096 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (asm_out_file, "LCTOC1");
29097 fprintf (asm_out_file, " = .+32768\n");
29098 toc_initialized = 1;
29103 /* Implement TARGET_ASM_INIT_SECTIONS. */
29105 static void
29106 rs6000_elf_asm_init_sections (void)
29108 toc_section
29109 = get_unnamed_section (0, rs6000_elf_output_toc_section_asm_op, NULL);
29111 sdata2_section
29112 = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
29113 SDATA2_SECTION_ASM_OP);
29116 /* Implement TARGET_SELECT_RTX_SECTION. */
29118 static section *
29119 rs6000_elf_select_rtx_section (machine_mode mode, rtx x,
29120 unsigned HOST_WIDE_INT align)
29122 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
29123 return toc_section;
29124 else
29125 return default_elf_select_rtx_section (mode, x, align);
29128 /* For a SYMBOL_REF, set generic flags and then perform some
29129 target-specific processing.
29131 When the AIX ABI is requested on a non-AIX system, replace the
29132 function name with the real name (with a leading .) rather than the
29133 function descriptor name. This saves a lot of overriding code to
29134 read the prefixes. */
29136 static void rs6000_elf_encode_section_info (tree, rtx, int) ATTRIBUTE_UNUSED;
29137 static void
29138 rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
29140 default_encode_section_info (decl, rtl, first);
29142 if (first
29143 && TREE_CODE (decl) == FUNCTION_DECL
29144 && !TARGET_AIX
29145 && DEFAULT_ABI == ABI_AIX)
29147 rtx sym_ref = XEXP (rtl, 0);
29148 size_t len = strlen (XSTR (sym_ref, 0));
29149 char *str = XALLOCAVEC (char, len + 2);
29150 str[0] = '.';
29151 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
29152 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
29156 static inline bool
29157 compare_section_name (const char *section, const char *templ)
29159 int len;
29161 len = strlen (templ);
29162 return (strncmp (section, templ, len) == 0
29163 && (section[len] == 0 || section[len] == '.'));
29166 bool
29167 rs6000_elf_in_small_data_p (const_tree decl)
29169 if (rs6000_sdata == SDATA_NONE)
29170 return false;
29172 /* We want to merge strings, so we never consider them small data. */
29173 if (TREE_CODE (decl) == STRING_CST)
29174 return false;
29176 /* Functions are never in the small data area. */
29177 if (TREE_CODE (decl) == FUNCTION_DECL)
29178 return false;
29180 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
29182 const char *section = DECL_SECTION_NAME (decl);
29183 if (compare_section_name (section, ".sdata")
29184 || compare_section_name (section, ".sdata2")
29185 || compare_section_name (section, ".gnu.linkonce.s")
29186 || compare_section_name (section, ".sbss")
29187 || compare_section_name (section, ".sbss2")
29188 || compare_section_name (section, ".gnu.linkonce.sb")
29189 || strcmp (section, ".PPC.EMB.sdata0") == 0
29190 || strcmp (section, ".PPC.EMB.sbss0") == 0)
29191 return true;
29193 else
29195 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
29197 if (size > 0
29198 && size <= g_switch_value
29199 /* If it's not public, and we're not going to reference it there,
29200 there's no need to put it in the small data section. */
29201 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
29202 return true;
29205 return false;
29208 #endif /* USING_ELFOS_H */
29210 /* Implement TARGET_USE_BLOCKS_FOR_CONSTANT_P. */
29212 static bool
29213 rs6000_use_blocks_for_constant_p (machine_mode mode, const_rtx x)
29215 return !ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode);
29218 /* Do not place thread-local symbols refs in the object blocks. */
29220 static bool
29221 rs6000_use_blocks_for_decl_p (const_tree decl)
29223 return !DECL_THREAD_LOCAL_P (decl);
29226 /* Return a REG that occurs in ADDR with coefficient 1.
29227 ADDR can be effectively incremented by incrementing REG.
29229 r0 is special and we must not select it as an address
29230 register by this routine since our caller will try to
29231 increment the returned register via an "la" instruction. */
29234 find_addr_reg (rtx addr)
29236 while (GET_CODE (addr) == PLUS)
29238 if (GET_CODE (XEXP (addr, 0)) == REG
29239 && REGNO (XEXP (addr, 0)) != 0)
29240 addr = XEXP (addr, 0);
29241 else if (GET_CODE (XEXP (addr, 1)) == REG
29242 && REGNO (XEXP (addr, 1)) != 0)
29243 addr = XEXP (addr, 1);
29244 else if (CONSTANT_P (XEXP (addr, 0)))
29245 addr = XEXP (addr, 1);
29246 else if (CONSTANT_P (XEXP (addr, 1)))
29247 addr = XEXP (addr, 0);
29248 else
29249 gcc_unreachable ();
29251 gcc_assert (GET_CODE (addr) == REG && REGNO (addr) != 0);
29252 return addr;
29255 void
29256 rs6000_fatal_bad_address (rtx op)
29258 fatal_insn ("bad address", op);
29261 #if TARGET_MACHO
29263 typedef struct branch_island_d {
29264 tree function_name;
29265 tree label_name;
29266 int line_number;
29267 } branch_island;
29270 static vec<branch_island, va_gc> *branch_islands;
29272 /* Remember to generate a branch island for far calls to the given
29273 function. */
29275 static void
29276 add_compiler_branch_island (tree label_name, tree function_name,
29277 int line_number)
29279 branch_island bi = {function_name, label_name, line_number};
29280 vec_safe_push (branch_islands, bi);
29283 /* Generate far-jump branch islands for everything recorded in
29284 branch_islands. Invoked immediately after the last instruction of
29285 the epilogue has been emitted; the branch islands must be appended
29286 to, and contiguous with, the function body. Mach-O stubs are
29287 generated in machopic_output_stub(). */
29289 static void
29290 macho_branch_islands (void)
29292 char tmp_buf[512];
29294 while (!vec_safe_is_empty (branch_islands))
29296 branch_island *bi = &branch_islands->last ();
29297 const char *label = IDENTIFIER_POINTER (bi->label_name);
29298 const char *name = IDENTIFIER_POINTER (bi->function_name);
29299 char name_buf[512];
29300 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
29301 if (name[0] == '*' || name[0] == '&')
29302 strcpy (name_buf, name+1);
29303 else
29305 name_buf[0] = '_';
29306 strcpy (name_buf+1, name);
29308 strcpy (tmp_buf, "\n");
29309 strcat (tmp_buf, label);
29310 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
29311 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
29312 dbxout_stabd (N_SLINE, bi->line_number);
29313 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
29314 if (flag_pic)
29316 if (TARGET_LINK_STACK)
29318 char name[32];
29319 get_ppc476_thunk_name (name);
29320 strcat (tmp_buf, ":\n\tmflr r0\n\tbl ");
29321 strcat (tmp_buf, name);
29322 strcat (tmp_buf, "\n");
29323 strcat (tmp_buf, label);
29324 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
29326 else
29328 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
29329 strcat (tmp_buf, label);
29330 strcat (tmp_buf, "_pic\n");
29331 strcat (tmp_buf, label);
29332 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
29335 strcat (tmp_buf, "\taddis r11,r11,ha16(");
29336 strcat (tmp_buf, name_buf);
29337 strcat (tmp_buf, " - ");
29338 strcat (tmp_buf, label);
29339 strcat (tmp_buf, "_pic)\n");
29341 strcat (tmp_buf, "\tmtlr r0\n");
29343 strcat (tmp_buf, "\taddi r12,r11,lo16(");
29344 strcat (tmp_buf, name_buf);
29345 strcat (tmp_buf, " - ");
29346 strcat (tmp_buf, label);
29347 strcat (tmp_buf, "_pic)\n");
29349 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
29351 else
29353 strcat (tmp_buf, ":\nlis r12,hi16(");
29354 strcat (tmp_buf, name_buf);
29355 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
29356 strcat (tmp_buf, name_buf);
29357 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
29359 output_asm_insn (tmp_buf, 0);
29360 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
29361 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
29362 dbxout_stabd (N_SLINE, bi->line_number);
29363 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
29364 branch_islands->pop ();
29368 /* NO_PREVIOUS_DEF checks in the link list whether the function name is
29369 already there or not. */
29371 static int
29372 no_previous_def (tree function_name)
29374 branch_island *bi;
29375 unsigned ix;
29377 FOR_EACH_VEC_SAFE_ELT (branch_islands, ix, bi)
29378 if (function_name == bi->function_name)
29379 return 0;
29380 return 1;
29383 /* GET_PREV_LABEL gets the label name from the previous definition of
29384 the function. */
29386 static tree
29387 get_prev_label (tree function_name)
29389 branch_island *bi;
29390 unsigned ix;
29392 FOR_EACH_VEC_SAFE_ELT (branch_islands, ix, bi)
29393 if (function_name == bi->function_name)
29394 return bi->label_name;
29395 return NULL_TREE;
29398 /* INSN is either a function call or a millicode call. It may have an
29399 unconditional jump in its delay slot.
29401 CALL_DEST is the routine we are calling. */
29403 char *
29404 output_call (rtx_insn *insn, rtx *operands, int dest_operand_number,
29405 int cookie_operand_number)
29407 static char buf[256];
29408 if (darwin_emit_branch_islands
29409 && GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
29410 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
29412 tree labelname;
29413 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
29415 if (no_previous_def (funname))
29417 rtx label_rtx = gen_label_rtx ();
29418 char *label_buf, temp_buf[256];
29419 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
29420 CODE_LABEL_NUMBER (label_rtx));
29421 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
29422 labelname = get_identifier (label_buf);
29423 add_compiler_branch_island (labelname, funname, insn_line (insn));
29425 else
29426 labelname = get_prev_label (funname);
29428 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
29429 instruction will reach 'foo', otherwise link as 'bl L42'".
29430 "L42" should be a 'branch island', that will do a far jump to
29431 'foo'. Branch islands are generated in
29432 macho_branch_islands(). */
29433 sprintf (buf, "jbsr %%z%d,%.246s",
29434 dest_operand_number, IDENTIFIER_POINTER (labelname));
29436 else
29437 sprintf (buf, "bl %%z%d", dest_operand_number);
29438 return buf;
29441 /* Generate PIC and indirect symbol stubs. */
29443 void
29444 machopic_output_stub (FILE *file, const char *symb, const char *stub)
29446 unsigned int length;
29447 char *symbol_name, *lazy_ptr_name;
29448 char *local_label_0;
29449 static int label = 0;
29451 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
29452 symb = (*targetm.strip_name_encoding) (symb);
29455 length = strlen (symb);
29456 symbol_name = XALLOCAVEC (char, length + 32);
29457 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
29459 lazy_ptr_name = XALLOCAVEC (char, length + 32);
29460 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
29462 if (flag_pic == 2)
29463 switch_to_section (darwin_sections[machopic_picsymbol_stub1_section]);
29464 else
29465 switch_to_section (darwin_sections[machopic_symbol_stub1_section]);
29467 if (flag_pic == 2)
29469 fprintf (file, "\t.align 5\n");
29471 fprintf (file, "%s:\n", stub);
29472 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
29474 label++;
29475 local_label_0 = XALLOCAVEC (char, sizeof ("\"L00000000000$spb\""));
29476 sprintf (local_label_0, "\"L%011d$spb\"", label);
29478 fprintf (file, "\tmflr r0\n");
29479 if (TARGET_LINK_STACK)
29481 char name[32];
29482 get_ppc476_thunk_name (name);
29483 fprintf (file, "\tbl %s\n", name);
29484 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
29486 else
29488 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
29489 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
29491 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
29492 lazy_ptr_name, local_label_0);
29493 fprintf (file, "\tmtlr r0\n");
29494 fprintf (file, "\t%s r12,lo16(%s-%s)(r11)\n",
29495 (TARGET_64BIT ? "ldu" : "lwzu"),
29496 lazy_ptr_name, local_label_0);
29497 fprintf (file, "\tmtctr r12\n");
29498 fprintf (file, "\tbctr\n");
29500 else
29502 fprintf (file, "\t.align 4\n");
29504 fprintf (file, "%s:\n", stub);
29505 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
29507 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
29508 fprintf (file, "\t%s r12,lo16(%s)(r11)\n",
29509 (TARGET_64BIT ? "ldu" : "lwzu"),
29510 lazy_ptr_name);
29511 fprintf (file, "\tmtctr r12\n");
29512 fprintf (file, "\tbctr\n");
29515 switch_to_section (darwin_sections[machopic_lazy_symbol_ptr_section]);
29516 fprintf (file, "%s:\n", lazy_ptr_name);
29517 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
29518 fprintf (file, "%sdyld_stub_binding_helper\n",
29519 (TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t"));
29522 /* Legitimize PIC addresses. If the address is already
29523 position-independent, we return ORIG. Newly generated
29524 position-independent addresses go into a reg. This is REG if non
29525 zero, otherwise we allocate register(s) as necessary. */
29527 #define SMALL_INT(X) ((UINTVAL (X) + 0x8000) < 0x10000)
29530 rs6000_machopic_legitimize_pic_address (rtx orig, machine_mode mode,
29531 rtx reg)
29533 rtx base, offset;
29535 if (reg == NULL && ! reload_in_progress && ! reload_completed)
29536 reg = gen_reg_rtx (Pmode);
29538 if (GET_CODE (orig) == CONST)
29540 rtx reg_temp;
29542 if (GET_CODE (XEXP (orig, 0)) == PLUS
29543 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
29544 return orig;
29546 gcc_assert (GET_CODE (XEXP (orig, 0)) == PLUS);
29548 /* Use a different reg for the intermediate value, as
29549 it will be marked UNCHANGING. */
29550 reg_temp = !can_create_pseudo_p () ? reg : gen_reg_rtx (Pmode);
29551 base = rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
29552 Pmode, reg_temp);
29553 offset =
29554 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
29555 Pmode, reg);
29557 if (GET_CODE (offset) == CONST_INT)
29559 if (SMALL_INT (offset))
29560 return plus_constant (Pmode, base, INTVAL (offset));
29561 else if (! reload_in_progress && ! reload_completed)
29562 offset = force_reg (Pmode, offset);
29563 else
29565 rtx mem = force_const_mem (Pmode, orig);
29566 return machopic_legitimize_pic_address (mem, Pmode, reg);
29569 return gen_rtx_PLUS (Pmode, base, offset);
29572 /* Fall back on generic machopic code. */
29573 return machopic_legitimize_pic_address (orig, mode, reg);
29576 /* Output a .machine directive for the Darwin assembler, and call
29577 the generic start_file routine. */
29579 static void
29580 rs6000_darwin_file_start (void)
29582 static const struct
29584 const char *arg;
29585 const char *name;
29586 HOST_WIDE_INT if_set;
29587 } mapping[] = {
29588 { "ppc64", "ppc64", MASK_64BIT },
29589 { "970", "ppc970", MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64 },
29590 { "power4", "ppc970", 0 },
29591 { "G5", "ppc970", 0 },
29592 { "7450", "ppc7450", 0 },
29593 { "7400", "ppc7400", MASK_ALTIVEC },
29594 { "G4", "ppc7400", 0 },
29595 { "750", "ppc750", 0 },
29596 { "740", "ppc750", 0 },
29597 { "G3", "ppc750", 0 },
29598 { "604e", "ppc604e", 0 },
29599 { "604", "ppc604", 0 },
29600 { "603e", "ppc603", 0 },
29601 { "603", "ppc603", 0 },
29602 { "601", "ppc601", 0 },
29603 { NULL, "ppc", 0 } };
29604 const char *cpu_id = "";
29605 size_t i;
29607 rs6000_file_start ();
29608 darwin_file_start ();
29610 /* Determine the argument to -mcpu=. Default to G3 if not specified. */
29612 if (rs6000_default_cpu != 0 && rs6000_default_cpu[0] != '\0')
29613 cpu_id = rs6000_default_cpu;
29615 if (global_options_set.x_rs6000_cpu_index)
29616 cpu_id = processor_target_table[rs6000_cpu_index].name;
29618 /* Look through the mapping array. Pick the first name that either
29619 matches the argument, has a bit set in IF_SET that is also set
29620 in the target flags, or has a NULL name. */
29622 i = 0;
29623 while (mapping[i].arg != NULL
29624 && strcmp (mapping[i].arg, cpu_id) != 0
29625 && (mapping[i].if_set & rs6000_isa_flags) == 0)
29626 i++;
29628 fprintf (asm_out_file, "\t.machine %s\n", mapping[i].name);
29631 #endif /* TARGET_MACHO */
29633 #if TARGET_ELF
29634 static int
29635 rs6000_elf_reloc_rw_mask (void)
29637 if (flag_pic)
29638 return 3;
29639 else if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
29640 return 2;
29641 else
29642 return 0;
29645 /* Record an element in the table of global constructors. SYMBOL is
29646 a SYMBOL_REF of the function to be called; PRIORITY is a number
29647 between 0 and MAX_INIT_PRIORITY.
29649 This differs from default_named_section_asm_out_constructor in
29650 that we have special handling for -mrelocatable. */
29652 static void rs6000_elf_asm_out_constructor (rtx, int) ATTRIBUTE_UNUSED;
29653 static void
29654 rs6000_elf_asm_out_constructor (rtx symbol, int priority)
29656 const char *section = ".ctors";
29657 char buf[16];
29659 if (priority != DEFAULT_INIT_PRIORITY)
29661 sprintf (buf, ".ctors.%.5u",
29662 /* Invert the numbering so the linker puts us in the proper
29663 order; constructors are run from right to left, and the
29664 linker sorts in increasing order. */
29665 MAX_INIT_PRIORITY - priority);
29666 section = buf;
29669 switch_to_section (get_section (section, SECTION_WRITE, NULL));
29670 assemble_align (POINTER_SIZE);
29672 if (TARGET_RELOCATABLE)
29674 fputs ("\t.long (", asm_out_file);
29675 output_addr_const (asm_out_file, symbol);
29676 fputs (")@fixup\n", asm_out_file);
29678 else
29679 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
29682 static void rs6000_elf_asm_out_destructor (rtx, int) ATTRIBUTE_UNUSED;
29683 static void
29684 rs6000_elf_asm_out_destructor (rtx symbol, int priority)
29686 const char *section = ".dtors";
29687 char buf[16];
29689 if (priority != DEFAULT_INIT_PRIORITY)
29691 sprintf (buf, ".dtors.%.5u",
29692 /* Invert the numbering so the linker puts us in the proper
29693 order; constructors are run from right to left, and the
29694 linker sorts in increasing order. */
29695 MAX_INIT_PRIORITY - priority);
29696 section = buf;
29699 switch_to_section (get_section (section, SECTION_WRITE, NULL));
29700 assemble_align (POINTER_SIZE);
29702 if (TARGET_RELOCATABLE)
29704 fputs ("\t.long (", asm_out_file);
29705 output_addr_const (asm_out_file, symbol);
29706 fputs (")@fixup\n", asm_out_file);
29708 else
29709 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
29712 void
29713 rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
29715 if (TARGET_64BIT && DEFAULT_ABI != ABI_ELFv2)
29717 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
29718 ASM_OUTPUT_LABEL (file, name);
29719 fputs (DOUBLE_INT_ASM_OP, file);
29720 rs6000_output_function_entry (file, name);
29721 fputs (",.TOC.@tocbase,0\n\t.previous\n", file);
29722 if (DOT_SYMBOLS)
29724 fputs ("\t.size\t", file);
29725 assemble_name (file, name);
29726 fputs (",24\n\t.type\t.", file);
29727 assemble_name (file, name);
29728 fputs (",@function\n", file);
29729 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
29731 fputs ("\t.globl\t.", file);
29732 assemble_name (file, name);
29733 putc ('\n', file);
29736 else
29737 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
29738 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
29739 rs6000_output_function_entry (file, name);
29740 fputs (":\n", file);
29741 return;
29744 if (TARGET_RELOCATABLE
29745 && !TARGET_SECURE_PLT
29746 && (get_pool_size () != 0 || crtl->profile)
29747 && uses_TOC ())
29749 char buf[256];
29751 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
29753 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
29754 fprintf (file, "\t.long ");
29755 assemble_name (file, buf);
29756 putc ('-', file);
29757 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
29758 assemble_name (file, buf);
29759 putc ('\n', file);
29762 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
29763 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
29765 if (DEFAULT_ABI == ABI_AIX)
29767 const char *desc_name, *orig_name;
29769 orig_name = (*targetm.strip_name_encoding) (name);
29770 desc_name = orig_name;
29771 while (*desc_name == '.')
29772 desc_name++;
29774 if (TREE_PUBLIC (decl))
29775 fprintf (file, "\t.globl %s\n", desc_name);
29777 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
29778 fprintf (file, "%s:\n", desc_name);
29779 fprintf (file, "\t.long %s\n", orig_name);
29780 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
29781 fputs ("\t.long 0\n", file);
29782 fprintf (file, "\t.previous\n");
29784 ASM_OUTPUT_LABEL (file, name);
29787 static void rs6000_elf_file_end (void) ATTRIBUTE_UNUSED;
29788 static void
29789 rs6000_elf_file_end (void)
29791 #ifdef HAVE_AS_GNU_ATTRIBUTE
29792 if (TARGET_32BIT && DEFAULT_ABI == ABI_V4)
29794 if (rs6000_passes_float)
29795 fprintf (asm_out_file, "\t.gnu_attribute 4, %d\n",
29796 ((TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_DOUBLE_FLOAT) ? 1
29797 : (TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_SINGLE_FLOAT) ? 3
29798 : 2));
29799 if (rs6000_passes_vector)
29800 fprintf (asm_out_file, "\t.gnu_attribute 8, %d\n",
29801 (TARGET_ALTIVEC_ABI ? 2
29802 : TARGET_SPE_ABI ? 3
29803 : 1));
29804 if (rs6000_returns_struct)
29805 fprintf (asm_out_file, "\t.gnu_attribute 12, %d\n",
29806 aix_struct_return ? 2 : 1);
29808 #endif
29809 #if defined (POWERPC_LINUX) || defined (POWERPC_FREEBSD)
29810 if (TARGET_32BIT || DEFAULT_ABI == ABI_ELFv2)
29811 file_end_indicate_exec_stack ();
29812 #endif
29814 #endif
29816 #if TARGET_XCOFF
29817 static void
29818 rs6000_xcoff_asm_output_anchor (rtx symbol)
29820 char buffer[100];
29822 sprintf (buffer, "$ + " HOST_WIDE_INT_PRINT_DEC,
29823 SYMBOL_REF_BLOCK_OFFSET (symbol));
29824 fprintf (asm_out_file, "%s", SET_ASM_OP);
29825 RS6000_OUTPUT_BASENAME (asm_out_file, XSTR (symbol, 0));
29826 fprintf (asm_out_file, ",");
29827 RS6000_OUTPUT_BASENAME (asm_out_file, buffer);
29828 fprintf (asm_out_file, "\n");
29831 static void
29832 rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
29834 fputs (GLOBAL_ASM_OP, stream);
29835 RS6000_OUTPUT_BASENAME (stream, name);
29836 putc ('\n', stream);
29839 /* A get_unnamed_decl callback, used for read-only sections. PTR
29840 points to the section string variable. */
29842 static void
29843 rs6000_xcoff_output_readonly_section_asm_op (const void *directive)
29845 fprintf (asm_out_file, "\t.csect %s[RO],%s\n",
29846 *(const char *const *) directive,
29847 XCOFF_CSECT_DEFAULT_ALIGNMENT_STR);
29850 /* Likewise for read-write sections. */
29852 static void
29853 rs6000_xcoff_output_readwrite_section_asm_op (const void *directive)
29855 fprintf (asm_out_file, "\t.csect %s[RW],%s\n",
29856 *(const char *const *) directive,
29857 XCOFF_CSECT_DEFAULT_ALIGNMENT_STR);
29860 static void
29861 rs6000_xcoff_output_tls_section_asm_op (const void *directive)
29863 fprintf (asm_out_file, "\t.csect %s[TL],%s\n",
29864 *(const char *const *) directive,
29865 XCOFF_CSECT_DEFAULT_ALIGNMENT_STR);
29868 /* A get_unnamed_section callback, used for switching to toc_section. */
29870 static void
29871 rs6000_xcoff_output_toc_section_asm_op (const void *data ATTRIBUTE_UNUSED)
29873 if (TARGET_MINIMAL_TOC)
29875 /* toc_section is always selected at least once from
29876 rs6000_xcoff_file_start, so this is guaranteed to
29877 always be defined once and only once in each file. */
29878 if (!toc_initialized)
29880 fputs ("\t.toc\nLCTOC..1:\n", asm_out_file);
29881 fputs ("\t.tc toc_table[TC],toc_table[RW]\n", asm_out_file);
29882 toc_initialized = 1;
29884 fprintf (asm_out_file, "\t.csect toc_table[RW]%s\n",
29885 (TARGET_32BIT ? "" : ",3"));
29887 else
29888 fputs ("\t.toc\n", asm_out_file);
29891 /* Implement TARGET_ASM_INIT_SECTIONS. */
29893 static void
29894 rs6000_xcoff_asm_init_sections (void)
29896 read_only_data_section
29897 = get_unnamed_section (0, rs6000_xcoff_output_readonly_section_asm_op,
29898 &xcoff_read_only_section_name);
29900 private_data_section
29901 = get_unnamed_section (SECTION_WRITE,
29902 rs6000_xcoff_output_readwrite_section_asm_op,
29903 &xcoff_private_data_section_name);
29905 tls_data_section
29906 = get_unnamed_section (SECTION_TLS,
29907 rs6000_xcoff_output_tls_section_asm_op,
29908 &xcoff_tls_data_section_name);
29910 tls_private_data_section
29911 = get_unnamed_section (SECTION_TLS,
29912 rs6000_xcoff_output_tls_section_asm_op,
29913 &xcoff_private_data_section_name);
29915 read_only_private_data_section
29916 = get_unnamed_section (0, rs6000_xcoff_output_readonly_section_asm_op,
29917 &xcoff_private_data_section_name);
29919 toc_section
29920 = get_unnamed_section (0, rs6000_xcoff_output_toc_section_asm_op, NULL);
29922 readonly_data_section = read_only_data_section;
29923 exception_section = data_section;
29926 static int
29927 rs6000_xcoff_reloc_rw_mask (void)
29929 return 3;
29932 static void
29933 rs6000_xcoff_asm_named_section (const char *name, unsigned int flags,
29934 tree decl ATTRIBUTE_UNUSED)
29936 int smclass;
29937 static const char * const suffix[4] = { "PR", "RO", "RW", "TL" };
29939 if (flags & SECTION_CODE)
29940 smclass = 0;
29941 else if (flags & SECTION_TLS)
29942 smclass = 3;
29943 else if (flags & SECTION_WRITE)
29944 smclass = 2;
29945 else
29946 smclass = 1;
29948 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
29949 (flags & SECTION_CODE) ? "." : "",
29950 name, suffix[smclass], flags & SECTION_ENTSIZE);
29953 #define IN_NAMED_SECTION(DECL) \
29954 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
29955 && DECL_SECTION_NAME (DECL) != NULL)
29957 static section *
29958 rs6000_xcoff_select_section (tree decl, int reloc,
29959 unsigned HOST_WIDE_INT align)
29961 /* Place variables with alignment stricter than BIGGEST_ALIGNMENT into
29962 named section. */
29963 if (align > BIGGEST_ALIGNMENT)
29965 resolve_unique_section (decl, reloc, true);
29966 if (IN_NAMED_SECTION (decl))
29967 return get_named_section (decl, NULL, reloc);
29970 if (decl_readonly_section (decl, reloc))
29972 if (TREE_PUBLIC (decl))
29973 return read_only_data_section;
29974 else
29975 return read_only_private_data_section;
29977 else
29979 #if HAVE_AS_TLS
29980 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
29982 if (TREE_PUBLIC (decl))
29983 return tls_data_section;
29984 else if (bss_initializer_p (decl))
29986 /* Convert to COMMON to emit in BSS. */
29987 DECL_COMMON (decl) = 1;
29988 return tls_comm_section;
29990 else
29991 return tls_private_data_section;
29993 else
29994 #endif
29995 if (TREE_PUBLIC (decl))
29996 return data_section;
29997 else
29998 return private_data_section;
30002 static void
30003 rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
30005 const char *name;
30007 /* Use select_section for private data and uninitialized data with
30008 alignment <= BIGGEST_ALIGNMENT. */
30009 if (!TREE_PUBLIC (decl)
30010 || DECL_COMMON (decl)
30011 || (DECL_INITIAL (decl) == NULL_TREE
30012 && DECL_ALIGN (decl) <= BIGGEST_ALIGNMENT)
30013 || DECL_INITIAL (decl) == error_mark_node
30014 || (flag_zero_initialized_in_bss
30015 && initializer_zerop (DECL_INITIAL (decl))))
30016 return;
30018 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
30019 name = (*targetm.strip_name_encoding) (name);
30020 set_decl_section_name (decl, name);
30023 /* Select section for constant in constant pool.
30025 On RS/6000, all constants are in the private read-only data area.
30026 However, if this is being placed in the TOC it must be output as a
30027 toc entry. */
30029 static section *
30030 rs6000_xcoff_select_rtx_section (machine_mode mode, rtx x,
30031 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
30033 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
30034 return toc_section;
30035 else
30036 return read_only_private_data_section;
30039 /* Remove any trailing [DS] or the like from the symbol name. */
30041 static const char *
30042 rs6000_xcoff_strip_name_encoding (const char *name)
30044 size_t len;
30045 if (*name == '*')
30046 name++;
30047 len = strlen (name);
30048 if (name[len - 1] == ']')
30049 return ggc_alloc_string (name, len - 4);
30050 else
30051 return name;
30054 /* Section attributes. AIX is always PIC. */
30056 static unsigned int
30057 rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
30059 unsigned int align;
30060 unsigned int flags = default_section_type_flags (decl, name, reloc);
30062 /* Align to at least UNIT size. */
30063 if ((flags & SECTION_CODE) != 0 || !decl || !DECL_P (decl))
30064 align = MIN_UNITS_PER_WORD;
30065 else
30066 /* Increase alignment of large objects if not already stricter. */
30067 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
30068 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
30069 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
30071 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
30074 /* Output at beginning of assembler file.
30076 Initialize the section names for the RS/6000 at this point.
30078 Specify filename, including full path, to assembler.
30080 We want to go into the TOC section so at least one .toc will be emitted.
30081 Also, in order to output proper .bs/.es pairs, we need at least one static
30082 [RW] section emitted.
30084 Finally, declare mcount when profiling to make the assembler happy. */
30086 static void
30087 rs6000_xcoff_file_start (void)
30089 rs6000_gen_section_name (&xcoff_bss_section_name,
30090 main_input_filename, ".bss_");
30091 rs6000_gen_section_name (&xcoff_private_data_section_name,
30092 main_input_filename, ".rw_");
30093 rs6000_gen_section_name (&xcoff_read_only_section_name,
30094 main_input_filename, ".ro_");
30095 rs6000_gen_section_name (&xcoff_tls_data_section_name,
30096 main_input_filename, ".tls_");
30097 rs6000_gen_section_name (&xcoff_tbss_section_name,
30098 main_input_filename, ".tbss_[UL]");
30100 fputs ("\t.file\t", asm_out_file);
30101 output_quoted_string (asm_out_file, main_input_filename);
30102 fputc ('\n', asm_out_file);
30103 if (write_symbols != NO_DEBUG)
30104 switch_to_section (private_data_section);
30105 switch_to_section (text_section);
30106 if (profile_flag)
30107 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
30108 rs6000_file_start ();
30111 /* Output at end of assembler file.
30112 On the RS/6000, referencing data should automatically pull in text. */
30114 static void
30115 rs6000_xcoff_file_end (void)
30117 switch_to_section (text_section);
30118 fputs ("_section_.text:\n", asm_out_file);
30119 switch_to_section (data_section);
30120 fputs (TARGET_32BIT
30121 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
30122 asm_out_file);
30125 struct declare_alias_data
30127 FILE *file;
30128 bool function_descriptor;
30131 /* Declare alias N. A helper function for for_node_and_aliases. */
30133 static bool
30134 rs6000_declare_alias (struct symtab_node *n, void *d)
30136 struct declare_alias_data *data = (struct declare_alias_data *)d;
30137 /* Main symbol is output specially, because varasm machinery does part of
30138 the job for us - we do not need to declare .globl/lglobs and such. */
30139 if (!n->alias || n->weakref)
30140 return false;
30142 if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (n->decl)))
30143 return false;
30145 /* Prevent assemble_alias from trying to use .set pseudo operation
30146 that does not behave as expected by the middle-end. */
30147 TREE_ASM_WRITTEN (n->decl) = true;
30149 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (n->decl));
30150 char *buffer = (char *) alloca (strlen (name) + 2);
30151 char *p;
30152 int dollar_inside = 0;
30154 strcpy (buffer, name);
30155 p = strchr (buffer, '$');
30156 while (p) {
30157 *p = '_';
30158 dollar_inside++;
30159 p = strchr (p + 1, '$');
30161 if (TREE_PUBLIC (n->decl))
30163 if (!RS6000_WEAK || !DECL_WEAK (n->decl))
30165 if (dollar_inside) {
30166 if (data->function_descriptor)
30167 fprintf(data->file, "\t.rename .%s,\".%s\"\n", buffer, name);
30168 else
30169 fprintf(data->file, "\t.rename %s,\"%s\"\n", buffer, name);
30171 if (data->function_descriptor)
30172 fputs ("\t.globl .", data->file);
30173 else
30174 fputs ("\t.globl ", data->file);
30175 RS6000_OUTPUT_BASENAME (data->file, buffer);
30176 putc ('\n', data->file);
30178 #ifdef ASM_WEAKEN_DECL
30179 else if (DECL_WEAK (n->decl) && !data->function_descriptor)
30180 ASM_WEAKEN_DECL (data->file, n->decl, name, NULL);
30181 #endif
30183 else
30185 if (dollar_inside)
30187 if (data->function_descriptor)
30188 fprintf(data->file, "\t.rename %s,\"%s\"\n", buffer, name);
30189 else
30190 fprintf(data->file, "\t.rename .%s,\".%s\"\n", buffer, name);
30192 if (data->function_descriptor)
30193 fputs ("\t.lglobl .", data->file);
30194 else
30195 fputs ("\t.lglobl ", data->file);
30196 RS6000_OUTPUT_BASENAME (data->file, buffer);
30197 putc ('\n', data->file);
30199 if (data->function_descriptor)
30200 fputs (".", data->file);
30201 RS6000_OUTPUT_BASENAME (data->file, buffer);
30202 fputs (":\n", data->file);
30203 return false;
30206 /* This macro produces the initial definition of a function name.
30207 On the RS/6000, we need to place an extra '.' in the function name and
30208 output the function descriptor.
30209 Dollar signs are converted to underscores.
30211 The csect for the function will have already been created when
30212 text_section was selected. We do have to go back to that csect, however.
30214 The third and fourth parameters to the .function pseudo-op (16 and 044)
30215 are placeholders which no longer have any use.
30217 Because AIX assembler's .set command has unexpected semantics, we output
30218 all aliases as alternative labels in front of the definition. */
30220 void
30221 rs6000_xcoff_declare_function_name (FILE *file, const char *name, tree decl)
30223 char *buffer = (char *) alloca (strlen (name) + 1);
30224 char *p;
30225 int dollar_inside = 0;
30226 struct declare_alias_data data = {file, false};
30228 strcpy (buffer, name);
30229 p = strchr (buffer, '$');
30230 while (p) {
30231 *p = '_';
30232 dollar_inside++;
30233 p = strchr (p + 1, '$');
30235 if (TREE_PUBLIC (decl))
30237 if (!RS6000_WEAK || !DECL_WEAK (decl))
30239 if (dollar_inside) {
30240 fprintf(file, "\t.rename .%s,\".%s\"\n", buffer, name);
30241 fprintf(file, "\t.rename %s,\"%s\"\n", buffer, name);
30243 fputs ("\t.globl .", file);
30244 RS6000_OUTPUT_BASENAME (file, buffer);
30245 putc ('\n', file);
30248 else
30250 if (dollar_inside) {
30251 fprintf(file, "\t.rename .%s,\".%s\"\n", buffer, name);
30252 fprintf(file, "\t.rename %s,\"%s\"\n", buffer, name);
30254 fputs ("\t.lglobl .", file);
30255 RS6000_OUTPUT_BASENAME (file, buffer);
30256 putc ('\n', file);
30258 fputs ("\t.csect ", file);
30259 RS6000_OUTPUT_BASENAME (file, buffer);
30260 fputs (TARGET_32BIT ? "[DS]\n" : "[DS],3\n", file);
30261 RS6000_OUTPUT_BASENAME (file, buffer);
30262 fputs (":\n", file);
30263 symtab_node::get (decl)->call_for_symbol_and_aliases (rs6000_declare_alias, &data, true);
30264 fputs (TARGET_32BIT ? "\t.long ." : "\t.llong .", file);
30265 RS6000_OUTPUT_BASENAME (file, buffer);
30266 fputs (", TOC[tc0], 0\n", file);
30267 in_section = NULL;
30268 switch_to_section (function_section (decl));
30269 putc ('.', file);
30270 RS6000_OUTPUT_BASENAME (file, buffer);
30271 fputs (":\n", file);
30272 data.function_descriptor = true;
30273 symtab_node::get (decl)->call_for_symbol_and_aliases (rs6000_declare_alias, &data, true);
30274 if (write_symbols != NO_DEBUG && !DECL_IGNORED_P (decl))
30275 xcoffout_declare_function (file, decl, buffer);
30276 return;
30279 /* This macro produces the initial definition of a object (variable) name.
30280 Because AIX assembler's .set command has unexpected semantics, we output
30281 all aliases as alternative labels in front of the definition. */
30283 void
30284 rs6000_xcoff_declare_object_name (FILE *file, const char *name, tree decl)
30286 struct declare_alias_data data = {file, false};
30287 RS6000_OUTPUT_BASENAME (file, name);
30288 fputs (":\n", file);
30289 symtab_node::get (decl)->call_for_symbol_and_aliases (rs6000_declare_alias, &data, true);
30292 #ifdef HAVE_AS_TLS
30293 static void
30294 rs6000_xcoff_encode_section_info (tree decl, rtx rtl, int first)
30296 rtx symbol;
30297 int flags;
30299 default_encode_section_info (decl, rtl, first);
30301 /* Careful not to prod global register variables. */
30302 if (!MEM_P (rtl))
30303 return;
30304 symbol = XEXP (rtl, 0);
30305 if (GET_CODE (symbol) != SYMBOL_REF)
30306 return;
30308 flags = SYMBOL_REF_FLAGS (symbol);
30310 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl))
30311 flags &= ~SYMBOL_FLAG_HAS_BLOCK_INFO;
30313 SYMBOL_REF_FLAGS (symbol) = flags;
30315 #endif /* HAVE_AS_TLS */
30316 #endif /* TARGET_XCOFF */
30318 /* Compute a (partial) cost for rtx X. Return true if the complete
30319 cost has been computed, and false if subexpressions should be
30320 scanned. In either case, *TOTAL contains the cost result. */
30322 static bool
30323 rs6000_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED,
30324 int *total, bool speed)
30326 machine_mode mode = GET_MODE (x);
30328 switch (code)
30330 /* On the RS/6000, if it is valid in the insn, it is free. */
30331 case CONST_INT:
30332 if (((outer_code == SET
30333 || outer_code == PLUS
30334 || outer_code == MINUS)
30335 && (satisfies_constraint_I (x)
30336 || satisfies_constraint_L (x)))
30337 || (outer_code == AND
30338 && (satisfies_constraint_K (x)
30339 || (mode == SImode
30340 ? satisfies_constraint_L (x)
30341 : satisfies_constraint_J (x))
30342 || mask_operand (x, mode)
30343 || (mode == DImode
30344 && mask64_operand (x, DImode))))
30345 || ((outer_code == IOR || outer_code == XOR)
30346 && (satisfies_constraint_K (x)
30347 || (mode == SImode
30348 ? satisfies_constraint_L (x)
30349 : satisfies_constraint_J (x))))
30350 || outer_code == ASHIFT
30351 || outer_code == ASHIFTRT
30352 || outer_code == LSHIFTRT
30353 || outer_code == ROTATE
30354 || outer_code == ROTATERT
30355 || outer_code == ZERO_EXTRACT
30356 || (outer_code == MULT
30357 && satisfies_constraint_I (x))
30358 || ((outer_code == DIV || outer_code == UDIV
30359 || outer_code == MOD || outer_code == UMOD)
30360 && exact_log2 (INTVAL (x)) >= 0)
30361 || (outer_code == COMPARE
30362 && (satisfies_constraint_I (x)
30363 || satisfies_constraint_K (x)))
30364 || ((outer_code == EQ || outer_code == NE)
30365 && (satisfies_constraint_I (x)
30366 || satisfies_constraint_K (x)
30367 || (mode == SImode
30368 ? satisfies_constraint_L (x)
30369 : satisfies_constraint_J (x))))
30370 || (outer_code == GTU
30371 && satisfies_constraint_I (x))
30372 || (outer_code == LTU
30373 && satisfies_constraint_P (x)))
30375 *total = 0;
30376 return true;
30378 else if ((outer_code == PLUS
30379 && reg_or_add_cint_operand (x, VOIDmode))
30380 || (outer_code == MINUS
30381 && reg_or_sub_cint_operand (x, VOIDmode))
30382 || ((outer_code == SET
30383 || outer_code == IOR
30384 || outer_code == XOR)
30385 && (INTVAL (x)
30386 & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0))
30388 *total = COSTS_N_INSNS (1);
30389 return true;
30391 /* FALLTHRU */
30393 case CONST_DOUBLE:
30394 case CONST_WIDE_INT:
30395 case CONST:
30396 case HIGH:
30397 case SYMBOL_REF:
30398 case MEM:
30399 /* When optimizing for size, MEM should be slightly more expensive
30400 than generating address, e.g., (plus (reg) (const)).
30401 L1 cache latency is about two instructions. */
30402 *total = !speed ? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (2);
30403 return true;
30405 case LABEL_REF:
30406 *total = 0;
30407 return true;
30409 case PLUS:
30410 case MINUS:
30411 if (FLOAT_MODE_P (mode))
30412 *total = rs6000_cost->fp;
30413 else
30414 *total = COSTS_N_INSNS (1);
30415 return false;
30417 case MULT:
30418 if (GET_CODE (XEXP (x, 1)) == CONST_INT
30419 && satisfies_constraint_I (XEXP (x, 1)))
30421 if (INTVAL (XEXP (x, 1)) >= -256
30422 && INTVAL (XEXP (x, 1)) <= 255)
30423 *total = rs6000_cost->mulsi_const9;
30424 else
30425 *total = rs6000_cost->mulsi_const;
30427 else if (mode == SFmode)
30428 *total = rs6000_cost->fp;
30429 else if (FLOAT_MODE_P (mode))
30430 *total = rs6000_cost->dmul;
30431 else if (mode == DImode)
30432 *total = rs6000_cost->muldi;
30433 else
30434 *total = rs6000_cost->mulsi;
30435 return false;
30437 case FMA:
30438 if (mode == SFmode)
30439 *total = rs6000_cost->fp;
30440 else
30441 *total = rs6000_cost->dmul;
30442 break;
30444 case DIV:
30445 case MOD:
30446 if (FLOAT_MODE_P (mode))
30448 *total = mode == DFmode ? rs6000_cost->ddiv
30449 : rs6000_cost->sdiv;
30450 return false;
30452 /* FALLTHRU */
30454 case UDIV:
30455 case UMOD:
30456 if (GET_CODE (XEXP (x, 1)) == CONST_INT
30457 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
30459 if (code == DIV || code == MOD)
30460 /* Shift, addze */
30461 *total = COSTS_N_INSNS (2);
30462 else
30463 /* Shift */
30464 *total = COSTS_N_INSNS (1);
30466 else
30468 if (GET_MODE (XEXP (x, 1)) == DImode)
30469 *total = rs6000_cost->divdi;
30470 else
30471 *total = rs6000_cost->divsi;
30473 /* Add in shift and subtract for MOD. */
30474 if (code == MOD || code == UMOD)
30475 *total += COSTS_N_INSNS (2);
30476 return false;
30478 case CTZ:
30479 case FFS:
30480 *total = COSTS_N_INSNS (4);
30481 return false;
30483 case POPCOUNT:
30484 *total = COSTS_N_INSNS (TARGET_POPCNTD ? 1 : 6);
30485 return false;
30487 case PARITY:
30488 *total = COSTS_N_INSNS (TARGET_CMPB ? 2 : 6);
30489 return false;
30491 case NOT:
30492 if (outer_code == AND || outer_code == IOR || outer_code == XOR)
30494 *total = 0;
30495 return false;
30497 /* FALLTHRU */
30499 case AND:
30500 case CLZ:
30501 case IOR:
30502 case XOR:
30503 case ZERO_EXTRACT:
30504 *total = COSTS_N_INSNS (1);
30505 return false;
30507 case ASHIFT:
30508 case ASHIFTRT:
30509 case LSHIFTRT:
30510 case ROTATE:
30511 case ROTATERT:
30512 /* Handle mul_highpart. */
30513 if (outer_code == TRUNCATE
30514 && GET_CODE (XEXP (x, 0)) == MULT)
30516 if (mode == DImode)
30517 *total = rs6000_cost->muldi;
30518 else
30519 *total = rs6000_cost->mulsi;
30520 return true;
30522 else if (outer_code == AND)
30523 *total = 0;
30524 else
30525 *total = COSTS_N_INSNS (1);
30526 return false;
30528 case SIGN_EXTEND:
30529 case ZERO_EXTEND:
30530 if (GET_CODE (XEXP (x, 0)) == MEM)
30531 *total = 0;
30532 else
30533 *total = COSTS_N_INSNS (1);
30534 return false;
30536 case COMPARE:
30537 case NEG:
30538 case ABS:
30539 if (!FLOAT_MODE_P (mode))
30541 *total = COSTS_N_INSNS (1);
30542 return false;
30544 /* FALLTHRU */
30546 case FLOAT:
30547 case UNSIGNED_FLOAT:
30548 case FIX:
30549 case UNSIGNED_FIX:
30550 case FLOAT_TRUNCATE:
30551 *total = rs6000_cost->fp;
30552 return false;
30554 case FLOAT_EXTEND:
30555 if (mode == DFmode)
30556 *total = rs6000_cost->sfdf_convert;
30557 else
30558 *total = rs6000_cost->fp;
30559 return false;
30561 case UNSPEC:
30562 switch (XINT (x, 1))
30564 case UNSPEC_FRSP:
30565 *total = rs6000_cost->fp;
30566 return true;
30568 default:
30569 break;
30571 break;
30573 case CALL:
30574 case IF_THEN_ELSE:
30575 if (!speed)
30577 *total = COSTS_N_INSNS (1);
30578 return true;
30580 else if (FLOAT_MODE_P (mode)
30581 && TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS)
30583 *total = rs6000_cost->fp;
30584 return false;
30586 break;
30588 case NE:
30589 case EQ:
30590 case GTU:
30591 case LTU:
30592 /* Carry bit requires mode == Pmode.
30593 NEG or PLUS already counted so only add one. */
30594 if (mode == Pmode
30595 && (outer_code == NEG || outer_code == PLUS))
30597 *total = COSTS_N_INSNS (1);
30598 return true;
30600 if (outer_code == SET)
30602 if (XEXP (x, 1) == const0_rtx)
30604 if (TARGET_ISEL && !TARGET_MFCRF)
30605 *total = COSTS_N_INSNS (8);
30606 else
30607 *total = COSTS_N_INSNS (2);
30608 return true;
30610 else
30612 *total = COSTS_N_INSNS (3);
30613 return false;
30616 /* FALLTHRU */
30618 case GT:
30619 case LT:
30620 case UNORDERED:
30621 if (outer_code == SET && (XEXP (x, 1) == const0_rtx))
30623 if (TARGET_ISEL && !TARGET_MFCRF)
30624 *total = COSTS_N_INSNS (8);
30625 else
30626 *total = COSTS_N_INSNS (2);
30627 return true;
30629 /* CC COMPARE. */
30630 if (outer_code == COMPARE)
30632 *total = 0;
30633 return true;
30635 break;
30637 default:
30638 break;
30641 return false;
30644 /* Debug form of r6000_rtx_costs that is selected if -mdebug=cost. */
30646 static bool
30647 rs6000_debug_rtx_costs (rtx x, int code, int outer_code, int opno, int *total,
30648 bool speed)
30650 bool ret = rs6000_rtx_costs (x, code, outer_code, opno, total, speed);
30652 fprintf (stderr,
30653 "\nrs6000_rtx_costs, return = %s, code = %s, outer_code = %s, "
30654 "opno = %d, total = %d, speed = %s, x:\n",
30655 ret ? "complete" : "scan inner",
30656 GET_RTX_NAME (code),
30657 GET_RTX_NAME (outer_code),
30658 opno,
30659 *total,
30660 speed ? "true" : "false");
30662 debug_rtx (x);
30664 return ret;
30667 /* Debug form of ADDRESS_COST that is selected if -mdebug=cost. */
30669 static int
30670 rs6000_debug_address_cost (rtx x, machine_mode mode,
30671 addr_space_t as, bool speed)
30673 int ret = TARGET_ADDRESS_COST (x, mode, as, speed);
30675 fprintf (stderr, "\nrs6000_address_cost, return = %d, speed = %s, x:\n",
30676 ret, speed ? "true" : "false");
30677 debug_rtx (x);
30679 return ret;
30683 /* A C expression returning the cost of moving data from a register of class
30684 CLASS1 to one of CLASS2. */
30686 static int
30687 rs6000_register_move_cost (machine_mode mode,
30688 reg_class_t from, reg_class_t to)
30690 int ret;
30692 if (TARGET_DEBUG_COST)
30693 dbg_cost_ctrl++;
30695 /* Moves from/to GENERAL_REGS. */
30696 if (reg_classes_intersect_p (to, GENERAL_REGS)
30697 || reg_classes_intersect_p (from, GENERAL_REGS))
30699 reg_class_t rclass = from;
30701 if (! reg_classes_intersect_p (to, GENERAL_REGS))
30702 rclass = to;
30704 if (rclass == FLOAT_REGS || rclass == ALTIVEC_REGS || rclass == VSX_REGS)
30705 ret = (rs6000_memory_move_cost (mode, rclass, false)
30706 + rs6000_memory_move_cost (mode, GENERAL_REGS, false));
30708 /* It's more expensive to move CR_REGS than CR0_REGS because of the
30709 shift. */
30710 else if (rclass == CR_REGS)
30711 ret = 4;
30713 /* For those processors that have slow LR/CTR moves, make them more
30714 expensive than memory in order to bias spills to memory .*/
30715 else if ((rs6000_cpu == PROCESSOR_POWER6
30716 || rs6000_cpu == PROCESSOR_POWER7
30717 || rs6000_cpu == PROCESSOR_POWER8)
30718 && reg_classes_intersect_p (rclass, LINK_OR_CTR_REGS))
30719 ret = 6 * hard_regno_nregs[0][mode];
30721 else
30722 /* A move will cost one instruction per GPR moved. */
30723 ret = 2 * hard_regno_nregs[0][mode];
30726 /* If we have VSX, we can easily move between FPR or Altivec registers. */
30727 else if (VECTOR_MEM_VSX_P (mode)
30728 && reg_classes_intersect_p (to, VSX_REGS)
30729 && reg_classes_intersect_p (from, VSX_REGS))
30730 ret = 2 * hard_regno_nregs[32][mode];
30732 /* Moving between two similar registers is just one instruction. */
30733 else if (reg_classes_intersect_p (to, from))
30734 ret = (mode == TFmode || mode == TDmode) ? 4 : 2;
30736 /* Everything else has to go through GENERAL_REGS. */
30737 else
30738 ret = (rs6000_register_move_cost (mode, GENERAL_REGS, to)
30739 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
30741 if (TARGET_DEBUG_COST)
30743 if (dbg_cost_ctrl == 1)
30744 fprintf (stderr,
30745 "rs6000_register_move_cost:, ret=%d, mode=%s, from=%s, to=%s\n",
30746 ret, GET_MODE_NAME (mode), reg_class_names[from],
30747 reg_class_names[to]);
30748 dbg_cost_ctrl--;
30751 return ret;
30754 /* A C expressions returning the cost of moving data of MODE from a register to
30755 or from memory. */
30757 static int
30758 rs6000_memory_move_cost (machine_mode mode, reg_class_t rclass,
30759 bool in ATTRIBUTE_UNUSED)
30761 int ret;
30763 if (TARGET_DEBUG_COST)
30764 dbg_cost_ctrl++;
30766 if (reg_classes_intersect_p (rclass, GENERAL_REGS))
30767 ret = 4 * hard_regno_nregs[0][mode];
30768 else if ((reg_classes_intersect_p (rclass, FLOAT_REGS)
30769 || reg_classes_intersect_p (rclass, VSX_REGS)))
30770 ret = 4 * hard_regno_nregs[32][mode];
30771 else if (reg_classes_intersect_p (rclass, ALTIVEC_REGS))
30772 ret = 4 * hard_regno_nregs[FIRST_ALTIVEC_REGNO][mode];
30773 else
30774 ret = 4 + rs6000_register_move_cost (mode, rclass, GENERAL_REGS);
30776 if (TARGET_DEBUG_COST)
30778 if (dbg_cost_ctrl == 1)
30779 fprintf (stderr,
30780 "rs6000_memory_move_cost: ret=%d, mode=%s, rclass=%s, in=%d\n",
30781 ret, GET_MODE_NAME (mode), reg_class_names[rclass], in);
30782 dbg_cost_ctrl--;
30785 return ret;
30788 /* Returns a code for a target-specific builtin that implements
30789 reciprocal of the function, or NULL_TREE if not available. */
30791 static tree
30792 rs6000_builtin_reciprocal (unsigned int fn, bool md_fn,
30793 bool sqrt ATTRIBUTE_UNUSED)
30795 if (optimize_insn_for_size_p ())
30796 return NULL_TREE;
30798 if (md_fn)
30799 switch (fn)
30801 case VSX_BUILTIN_XVSQRTDP:
30802 if (!RS6000_RECIP_AUTO_RSQRTE_P (V2DFmode))
30803 return NULL_TREE;
30805 return rs6000_builtin_decls[VSX_BUILTIN_RSQRT_2DF];
30807 case VSX_BUILTIN_XVSQRTSP:
30808 if (!RS6000_RECIP_AUTO_RSQRTE_P (V4SFmode))
30809 return NULL_TREE;
30811 return rs6000_builtin_decls[VSX_BUILTIN_RSQRT_4SF];
30813 default:
30814 return NULL_TREE;
30817 else
30818 switch (fn)
30820 case BUILT_IN_SQRT:
30821 if (!RS6000_RECIP_AUTO_RSQRTE_P (DFmode))
30822 return NULL_TREE;
30824 return rs6000_builtin_decls[RS6000_BUILTIN_RSQRT];
30826 case BUILT_IN_SQRTF:
30827 if (!RS6000_RECIP_AUTO_RSQRTE_P (SFmode))
30828 return NULL_TREE;
30830 return rs6000_builtin_decls[RS6000_BUILTIN_RSQRTF];
30832 default:
30833 return NULL_TREE;
30837 /* Load up a constant. If the mode is a vector mode, splat the value across
30838 all of the vector elements. */
30840 static rtx
30841 rs6000_load_constant_and_splat (machine_mode mode, REAL_VALUE_TYPE dconst)
30843 rtx reg;
30845 if (mode == SFmode || mode == DFmode)
30847 rtx d = CONST_DOUBLE_FROM_REAL_VALUE (dconst, mode);
30848 reg = force_reg (mode, d);
30850 else if (mode == V4SFmode)
30852 rtx d = CONST_DOUBLE_FROM_REAL_VALUE (dconst, SFmode);
30853 rtvec v = gen_rtvec (4, d, d, d, d);
30854 reg = gen_reg_rtx (mode);
30855 rs6000_expand_vector_init (reg, gen_rtx_PARALLEL (mode, v));
30857 else if (mode == V2DFmode)
30859 rtx d = CONST_DOUBLE_FROM_REAL_VALUE (dconst, DFmode);
30860 rtvec v = gen_rtvec (2, d, d);
30861 reg = gen_reg_rtx (mode);
30862 rs6000_expand_vector_init (reg, gen_rtx_PARALLEL (mode, v));
30864 else
30865 gcc_unreachable ();
30867 return reg;
30870 /* Generate an FMA instruction. */
30872 static void
30873 rs6000_emit_madd (rtx target, rtx m1, rtx m2, rtx a)
30875 machine_mode mode = GET_MODE (target);
30876 rtx dst;
30878 dst = expand_ternary_op (mode, fma_optab, m1, m2, a, target, 0);
30879 gcc_assert (dst != NULL);
30881 if (dst != target)
30882 emit_move_insn (target, dst);
30885 /* Generate a FMSUB instruction: dst = fma(m1, m2, -a). */
30887 static void
30888 rs6000_emit_msub (rtx target, rtx m1, rtx m2, rtx a)
30890 machine_mode mode = GET_MODE (target);
30891 rtx dst;
30893 /* Altivec does not support fms directly;
30894 generate in terms of fma in that case. */
30895 if (optab_handler (fms_optab, mode) != CODE_FOR_nothing)
30896 dst = expand_ternary_op (mode, fms_optab, m1, m2, a, target, 0);
30897 else
30899 a = expand_unop (mode, neg_optab, a, NULL_RTX, 0);
30900 dst = expand_ternary_op (mode, fma_optab, m1, m2, a, target, 0);
30902 gcc_assert (dst != NULL);
30904 if (dst != target)
30905 emit_move_insn (target, dst);
30908 /* Generate a FNMSUB instruction: dst = -fma(m1, m2, -a). */
30910 static void
30911 rs6000_emit_nmsub (rtx dst, rtx m1, rtx m2, rtx a)
30913 machine_mode mode = GET_MODE (dst);
30914 rtx r;
30916 /* This is a tad more complicated, since the fnma_optab is for
30917 a different expression: fma(-m1, m2, a), which is the same
30918 thing except in the case of signed zeros.
30920 Fortunately we know that if FMA is supported that FNMSUB is
30921 also supported in the ISA. Just expand it directly. */
30923 gcc_assert (optab_handler (fma_optab, mode) != CODE_FOR_nothing);
30925 r = gen_rtx_NEG (mode, a);
30926 r = gen_rtx_FMA (mode, m1, m2, r);
30927 r = gen_rtx_NEG (mode, r);
30928 emit_insn (gen_rtx_SET (dst, r));
30931 /* Newton-Raphson approximation of floating point divide DST = N/D. If NOTE_P,
30932 add a reg_note saying that this was a division. Support both scalar and
30933 vector divide. Assumes no trapping math and finite arguments. */
30935 void
30936 rs6000_emit_swdiv (rtx dst, rtx n, rtx d, bool note_p)
30938 machine_mode mode = GET_MODE (dst);
30939 rtx one, x0, e0, x1, xprev, eprev, xnext, enext, u, v;
30940 int i;
30942 /* Low precision estimates guarantee 5 bits of accuracy. High
30943 precision estimates guarantee 14 bits of accuracy. SFmode
30944 requires 23 bits of accuracy. DFmode requires 52 bits of
30945 accuracy. Each pass at least doubles the accuracy, leading
30946 to the following. */
30947 int passes = (TARGET_RECIP_PRECISION) ? 1 : 3;
30948 if (mode == DFmode || mode == V2DFmode)
30949 passes++;
30951 enum insn_code code = optab_handler (smul_optab, mode);
30952 insn_gen_fn gen_mul = GEN_FCN (code);
30954 gcc_assert (code != CODE_FOR_nothing);
30956 one = rs6000_load_constant_and_splat (mode, dconst1);
30958 /* x0 = 1./d estimate */
30959 x0 = gen_reg_rtx (mode);
30960 emit_insn (gen_rtx_SET (x0, gen_rtx_UNSPEC (mode, gen_rtvec (1, d),
30961 UNSPEC_FRES)));
30963 /* Each iteration but the last calculates x_(i+1) = x_i * (2 - d * x_i). */
30964 if (passes > 1) {
30966 /* e0 = 1. - d * x0 */
30967 e0 = gen_reg_rtx (mode);
30968 rs6000_emit_nmsub (e0, d, x0, one);
30970 /* x1 = x0 + e0 * x0 */
30971 x1 = gen_reg_rtx (mode);
30972 rs6000_emit_madd (x1, e0, x0, x0);
30974 for (i = 0, xprev = x1, eprev = e0; i < passes - 2;
30975 ++i, xprev = xnext, eprev = enext) {
30977 /* enext = eprev * eprev */
30978 enext = gen_reg_rtx (mode);
30979 emit_insn (gen_mul (enext, eprev, eprev));
30981 /* xnext = xprev + enext * xprev */
30982 xnext = gen_reg_rtx (mode);
30983 rs6000_emit_madd (xnext, enext, xprev, xprev);
30986 } else
30987 xprev = x0;
30989 /* The last iteration calculates x_(i+1) = n * x_i * (2 - d * x_i). */
30991 /* u = n * xprev */
30992 u = gen_reg_rtx (mode);
30993 emit_insn (gen_mul (u, n, xprev));
30995 /* v = n - (d * u) */
30996 v = gen_reg_rtx (mode);
30997 rs6000_emit_nmsub (v, d, u, n);
30999 /* dst = (v * xprev) + u */
31000 rs6000_emit_madd (dst, v, xprev, u);
31002 if (note_p)
31003 add_reg_note (get_last_insn (), REG_EQUAL, gen_rtx_DIV (mode, n, d));
31006 /* Newton-Raphson approximation of single/double-precision floating point
31007 rsqrt. Assumes no trapping math and finite arguments. */
31009 void
31010 rs6000_emit_swrsqrt (rtx dst, rtx src)
31012 machine_mode mode = GET_MODE (src);
31013 rtx x0 = gen_reg_rtx (mode);
31014 rtx y = gen_reg_rtx (mode);
31016 /* Low precision estimates guarantee 5 bits of accuracy. High
31017 precision estimates guarantee 14 bits of accuracy. SFmode
31018 requires 23 bits of accuracy. DFmode requires 52 bits of
31019 accuracy. Each pass at least doubles the accuracy, leading
31020 to the following. */
31021 int passes = (TARGET_RECIP_PRECISION) ? 1 : 3;
31022 if (mode == DFmode || mode == V2DFmode)
31023 passes++;
31025 REAL_VALUE_TYPE dconst3_2;
31026 int i;
31027 rtx halfthree;
31028 enum insn_code code = optab_handler (smul_optab, mode);
31029 insn_gen_fn gen_mul = GEN_FCN (code);
31031 gcc_assert (code != CODE_FOR_nothing);
31033 /* Load up the constant 1.5 either as a scalar, or as a vector. */
31034 real_from_integer (&dconst3_2, VOIDmode, 3, SIGNED);
31035 SET_REAL_EXP (&dconst3_2, REAL_EXP (&dconst3_2) - 1);
31037 halfthree = rs6000_load_constant_and_splat (mode, dconst3_2);
31039 /* x0 = rsqrt estimate */
31040 emit_insn (gen_rtx_SET (x0, gen_rtx_UNSPEC (mode, gen_rtvec (1, src),
31041 UNSPEC_RSQRT)));
31043 /* y = 0.5 * src = 1.5 * src - src -> fewer constants */
31044 rs6000_emit_msub (y, src, halfthree, src);
31046 for (i = 0; i < passes; i++)
31048 rtx x1 = gen_reg_rtx (mode);
31049 rtx u = gen_reg_rtx (mode);
31050 rtx v = gen_reg_rtx (mode);
31052 /* x1 = x0 * (1.5 - y * (x0 * x0)) */
31053 emit_insn (gen_mul (u, x0, x0));
31054 rs6000_emit_nmsub (v, y, u, halfthree);
31055 emit_insn (gen_mul (x1, x0, v));
31056 x0 = x1;
31059 emit_move_insn (dst, x0);
31060 return;
31063 /* Emit popcount intrinsic on TARGET_POPCNTB (Power5) and TARGET_POPCNTD
31064 (Power7) targets. DST is the target, and SRC is the argument operand. */
31066 void
31067 rs6000_emit_popcount (rtx dst, rtx src)
31069 machine_mode mode = GET_MODE (dst);
31070 rtx tmp1, tmp2;
31072 /* Use the PPC ISA 2.06 popcnt{w,d} instruction if we can. */
31073 if (TARGET_POPCNTD)
31075 if (mode == SImode)
31076 emit_insn (gen_popcntdsi2 (dst, src));
31077 else
31078 emit_insn (gen_popcntddi2 (dst, src));
31079 return;
31082 tmp1 = gen_reg_rtx (mode);
31084 if (mode == SImode)
31086 emit_insn (gen_popcntbsi2 (tmp1, src));
31087 tmp2 = expand_mult (SImode, tmp1, GEN_INT (0x01010101),
31088 NULL_RTX, 0);
31089 tmp2 = force_reg (SImode, tmp2);
31090 emit_insn (gen_lshrsi3 (dst, tmp2, GEN_INT (24)));
31092 else
31094 emit_insn (gen_popcntbdi2 (tmp1, src));
31095 tmp2 = expand_mult (DImode, tmp1,
31096 GEN_INT ((HOST_WIDE_INT)
31097 0x01010101 << 32 | 0x01010101),
31098 NULL_RTX, 0);
31099 tmp2 = force_reg (DImode, tmp2);
31100 emit_insn (gen_lshrdi3 (dst, tmp2, GEN_INT (56)));
31105 /* Emit parity intrinsic on TARGET_POPCNTB targets. DST is the
31106 target, and SRC is the argument operand. */
31108 void
31109 rs6000_emit_parity (rtx dst, rtx src)
31111 machine_mode mode = GET_MODE (dst);
31112 rtx tmp;
31114 tmp = gen_reg_rtx (mode);
31116 /* Use the PPC ISA 2.05 prtyw/prtyd instruction if we can. */
31117 if (TARGET_CMPB)
31119 if (mode == SImode)
31121 emit_insn (gen_popcntbsi2 (tmp, src));
31122 emit_insn (gen_paritysi2_cmpb (dst, tmp));
31124 else
31126 emit_insn (gen_popcntbdi2 (tmp, src));
31127 emit_insn (gen_paritydi2_cmpb (dst, tmp));
31129 return;
31132 if (mode == SImode)
31134 /* Is mult+shift >= shift+xor+shift+xor? */
31135 if (rs6000_cost->mulsi_const >= COSTS_N_INSNS (3))
31137 rtx tmp1, tmp2, tmp3, tmp4;
31139 tmp1 = gen_reg_rtx (SImode);
31140 emit_insn (gen_popcntbsi2 (tmp1, src));
31142 tmp2 = gen_reg_rtx (SImode);
31143 emit_insn (gen_lshrsi3 (tmp2, tmp1, GEN_INT (16)));
31144 tmp3 = gen_reg_rtx (SImode);
31145 emit_insn (gen_xorsi3 (tmp3, tmp1, tmp2));
31147 tmp4 = gen_reg_rtx (SImode);
31148 emit_insn (gen_lshrsi3 (tmp4, tmp3, GEN_INT (8)));
31149 emit_insn (gen_xorsi3 (tmp, tmp3, tmp4));
31151 else
31152 rs6000_emit_popcount (tmp, src);
31153 emit_insn (gen_andsi3 (dst, tmp, const1_rtx));
31155 else
31157 /* Is mult+shift >= shift+xor+shift+xor+shift+xor? */
31158 if (rs6000_cost->muldi >= COSTS_N_INSNS (5))
31160 rtx tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
31162 tmp1 = gen_reg_rtx (DImode);
31163 emit_insn (gen_popcntbdi2 (tmp1, src));
31165 tmp2 = gen_reg_rtx (DImode);
31166 emit_insn (gen_lshrdi3 (tmp2, tmp1, GEN_INT (32)));
31167 tmp3 = gen_reg_rtx (DImode);
31168 emit_insn (gen_xordi3 (tmp3, tmp1, tmp2));
31170 tmp4 = gen_reg_rtx (DImode);
31171 emit_insn (gen_lshrdi3 (tmp4, tmp3, GEN_INT (16)));
31172 tmp5 = gen_reg_rtx (DImode);
31173 emit_insn (gen_xordi3 (tmp5, tmp3, tmp4));
31175 tmp6 = gen_reg_rtx (DImode);
31176 emit_insn (gen_lshrdi3 (tmp6, tmp5, GEN_INT (8)));
31177 emit_insn (gen_xordi3 (tmp, tmp5, tmp6));
31179 else
31180 rs6000_emit_popcount (tmp, src);
31181 emit_insn (gen_anddi3 (dst, tmp, const1_rtx));
31185 /* Expand an Altivec constant permutation for little endian mode.
31186 There are two issues: First, the two input operands must be
31187 swapped so that together they form a double-wide array in LE
31188 order. Second, the vperm instruction has surprising behavior
31189 in LE mode: it interprets the elements of the source vectors
31190 in BE mode ("left to right") and interprets the elements of
31191 the destination vector in LE mode ("right to left"). To
31192 correct for this, we must subtract each element of the permute
31193 control vector from 31.
31195 For example, suppose we want to concatenate vr10 = {0, 1, 2, 3}
31196 with vr11 = {4, 5, 6, 7} and extract {0, 2, 4, 6} using a vperm.
31197 We place {0,1,2,3,8,9,10,11,16,17,18,19,24,25,26,27} in vr12 to
31198 serve as the permute control vector. Then, in BE mode,
31200 vperm 9,10,11,12
31202 places the desired result in vr9. However, in LE mode the
31203 vector contents will be
31205 vr10 = 00000003 00000002 00000001 00000000
31206 vr11 = 00000007 00000006 00000005 00000004
31208 The result of the vperm using the same permute control vector is
31210 vr9 = 05000000 07000000 01000000 03000000
31212 That is, the leftmost 4 bytes of vr10 are interpreted as the
31213 source for the rightmost 4 bytes of vr9, and so on.
31215 If we change the permute control vector to
31217 vr12 = {31,20,29,28,23,22,21,20,15,14,13,12,7,6,5,4}
31219 and issue
31221 vperm 9,11,10,12
31223 we get the desired
31225 vr9 = 00000006 00000004 00000002 00000000. */
31227 void
31228 altivec_expand_vec_perm_const_le (rtx operands[4])
31230 unsigned int i;
31231 rtx perm[16];
31232 rtx constv, unspec;
31233 rtx target = operands[0];
31234 rtx op0 = operands[1];
31235 rtx op1 = operands[2];
31236 rtx sel = operands[3];
31238 /* Unpack and adjust the constant selector. */
31239 for (i = 0; i < 16; ++i)
31241 rtx e = XVECEXP (sel, 0, i);
31242 unsigned int elt = 31 - (INTVAL (e) & 31);
31243 perm[i] = GEN_INT (elt);
31246 /* Expand to a permute, swapping the inputs and using the
31247 adjusted selector. */
31248 if (!REG_P (op0))
31249 op0 = force_reg (V16QImode, op0);
31250 if (!REG_P (op1))
31251 op1 = force_reg (V16QImode, op1);
31253 constv = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, perm));
31254 constv = force_reg (V16QImode, constv);
31255 unspec = gen_rtx_UNSPEC (V16QImode, gen_rtvec (3, op1, op0, constv),
31256 UNSPEC_VPERM);
31257 if (!REG_P (target))
31259 rtx tmp = gen_reg_rtx (V16QImode);
31260 emit_move_insn (tmp, unspec);
31261 unspec = tmp;
31264 emit_move_insn (target, unspec);
31267 /* Similarly to altivec_expand_vec_perm_const_le, we must adjust the
31268 permute control vector. But here it's not a constant, so we must
31269 generate a vector NAND or NOR to do the adjustment. */
31271 void
31272 altivec_expand_vec_perm_le (rtx operands[4])
31274 rtx notx, iorx, unspec;
31275 rtx target = operands[0];
31276 rtx op0 = operands[1];
31277 rtx op1 = operands[2];
31278 rtx sel = operands[3];
31279 rtx tmp = target;
31280 rtx norreg = gen_reg_rtx (V16QImode);
31281 machine_mode mode = GET_MODE (target);
31283 /* Get everything in regs so the pattern matches. */
31284 if (!REG_P (op0))
31285 op0 = force_reg (mode, op0);
31286 if (!REG_P (op1))
31287 op1 = force_reg (mode, op1);
31288 if (!REG_P (sel))
31289 sel = force_reg (V16QImode, sel);
31290 if (!REG_P (target))
31291 tmp = gen_reg_rtx (mode);
31293 /* Invert the selector with a VNAND if available, else a VNOR.
31294 The VNAND is preferred for future fusion opportunities. */
31295 notx = gen_rtx_NOT (V16QImode, sel);
31296 iorx = (TARGET_P8_VECTOR
31297 ? gen_rtx_IOR (V16QImode, notx, notx)
31298 : gen_rtx_AND (V16QImode, notx, notx));
31299 emit_insn (gen_rtx_SET (norreg, iorx));
31301 /* Permute with operands reversed and adjusted selector. */
31302 unspec = gen_rtx_UNSPEC (mode, gen_rtvec (3, op1, op0, norreg),
31303 UNSPEC_VPERM);
31305 /* Copy into target, possibly by way of a register. */
31306 if (!REG_P (target))
31308 emit_move_insn (tmp, unspec);
31309 unspec = tmp;
31312 emit_move_insn (target, unspec);
31315 /* Expand an Altivec constant permutation. Return true if we match
31316 an efficient implementation; false to fall back to VPERM. */
31318 bool
31319 altivec_expand_vec_perm_const (rtx operands[4])
31321 struct altivec_perm_insn {
31322 HOST_WIDE_INT mask;
31323 enum insn_code impl;
31324 unsigned char perm[16];
31326 static const struct altivec_perm_insn patterns[] = {
31327 { OPTION_MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum_direct,
31328 { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31 } },
31329 { OPTION_MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum_direct,
31330 { 2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31 } },
31331 { OPTION_MASK_ALTIVEC,
31332 (BYTES_BIG_ENDIAN ? CODE_FOR_altivec_vmrghb_direct
31333 : CODE_FOR_altivec_vmrglb_direct),
31334 { 0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23 } },
31335 { OPTION_MASK_ALTIVEC,
31336 (BYTES_BIG_ENDIAN ? CODE_FOR_altivec_vmrghh_direct
31337 : CODE_FOR_altivec_vmrglh_direct),
31338 { 0, 1, 16, 17, 2, 3, 18, 19, 4, 5, 20, 21, 6, 7, 22, 23 } },
31339 { OPTION_MASK_ALTIVEC,
31340 (BYTES_BIG_ENDIAN ? CODE_FOR_altivec_vmrghw_direct
31341 : CODE_FOR_altivec_vmrglw_direct),
31342 { 0, 1, 2, 3, 16, 17, 18, 19, 4, 5, 6, 7, 20, 21, 22, 23 } },
31343 { OPTION_MASK_ALTIVEC,
31344 (BYTES_BIG_ENDIAN ? CODE_FOR_altivec_vmrglb_direct
31345 : CODE_FOR_altivec_vmrghb_direct),
31346 { 8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31 } },
31347 { OPTION_MASK_ALTIVEC,
31348 (BYTES_BIG_ENDIAN ? CODE_FOR_altivec_vmrglh_direct
31349 : CODE_FOR_altivec_vmrghh_direct),
31350 { 8, 9, 24, 25, 10, 11, 26, 27, 12, 13, 28, 29, 14, 15, 30, 31 } },
31351 { OPTION_MASK_ALTIVEC,
31352 (BYTES_BIG_ENDIAN ? CODE_FOR_altivec_vmrglw_direct
31353 : CODE_FOR_altivec_vmrghw_direct),
31354 { 8, 9, 10, 11, 24, 25, 26, 27, 12, 13, 14, 15, 28, 29, 30, 31 } },
31355 { OPTION_MASK_P8_VECTOR, CODE_FOR_p8_vmrgew,
31356 { 0, 1, 2, 3, 16, 17, 18, 19, 8, 9, 10, 11, 24, 25, 26, 27 } },
31357 { OPTION_MASK_P8_VECTOR, CODE_FOR_p8_vmrgow,
31358 { 4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 28, 29, 30, 31 } }
31361 unsigned int i, j, elt, which;
31362 unsigned char perm[16];
31363 rtx target, op0, op1, sel, x;
31364 bool one_vec;
31366 target = operands[0];
31367 op0 = operands[1];
31368 op1 = operands[2];
31369 sel = operands[3];
31371 /* Unpack the constant selector. */
31372 for (i = which = 0; i < 16; ++i)
31374 rtx e = XVECEXP (sel, 0, i);
31375 elt = INTVAL (e) & 31;
31376 which |= (elt < 16 ? 1 : 2);
31377 perm[i] = elt;
31380 /* Simplify the constant selector based on operands. */
31381 switch (which)
31383 default:
31384 gcc_unreachable ();
31386 case 3:
31387 one_vec = false;
31388 if (!rtx_equal_p (op0, op1))
31389 break;
31390 /* FALLTHRU */
31392 case 2:
31393 for (i = 0; i < 16; ++i)
31394 perm[i] &= 15;
31395 op0 = op1;
31396 one_vec = true;
31397 break;
31399 case 1:
31400 op1 = op0;
31401 one_vec = true;
31402 break;
31405 /* Look for splat patterns. */
31406 if (one_vec)
31408 elt = perm[0];
31410 for (i = 0; i < 16; ++i)
31411 if (perm[i] != elt)
31412 break;
31413 if (i == 16)
31415 if (!BYTES_BIG_ENDIAN)
31416 elt = 15 - elt;
31417 emit_insn (gen_altivec_vspltb_direct (target, op0, GEN_INT (elt)));
31418 return true;
31421 if (elt % 2 == 0)
31423 for (i = 0; i < 16; i += 2)
31424 if (perm[i] != elt || perm[i + 1] != elt + 1)
31425 break;
31426 if (i == 16)
31428 int field = BYTES_BIG_ENDIAN ? elt / 2 : 7 - elt / 2;
31429 x = gen_reg_rtx (V8HImode);
31430 emit_insn (gen_altivec_vsplth_direct (x, gen_lowpart (V8HImode, op0),
31431 GEN_INT (field)));
31432 emit_move_insn (target, gen_lowpart (V16QImode, x));
31433 return true;
31437 if (elt % 4 == 0)
31439 for (i = 0; i < 16; i += 4)
31440 if (perm[i] != elt
31441 || perm[i + 1] != elt + 1
31442 || perm[i + 2] != elt + 2
31443 || perm[i + 3] != elt + 3)
31444 break;
31445 if (i == 16)
31447 int field = BYTES_BIG_ENDIAN ? elt / 4 : 3 - elt / 4;
31448 x = gen_reg_rtx (V4SImode);
31449 emit_insn (gen_altivec_vspltw_direct (x, gen_lowpart (V4SImode, op0),
31450 GEN_INT (field)));
31451 emit_move_insn (target, gen_lowpart (V16QImode, x));
31452 return true;
31457 /* Look for merge and pack patterns. */
31458 for (j = 0; j < ARRAY_SIZE (patterns); ++j)
31460 bool swapped;
31462 if ((patterns[j].mask & rs6000_isa_flags) == 0)
31463 continue;
31465 elt = patterns[j].perm[0];
31466 if (perm[0] == elt)
31467 swapped = false;
31468 else if (perm[0] == elt + 16)
31469 swapped = true;
31470 else
31471 continue;
31472 for (i = 1; i < 16; ++i)
31474 elt = patterns[j].perm[i];
31475 if (swapped)
31476 elt = (elt >= 16 ? elt - 16 : elt + 16);
31477 else if (one_vec && elt >= 16)
31478 elt -= 16;
31479 if (perm[i] != elt)
31480 break;
31482 if (i == 16)
31484 enum insn_code icode = patterns[j].impl;
31485 machine_mode omode = insn_data[icode].operand[0].mode;
31486 machine_mode imode = insn_data[icode].operand[1].mode;
31488 /* For little-endian, don't use vpkuwum and vpkuhum if the
31489 underlying vector type is not V4SI and V8HI, respectively.
31490 For example, using vpkuwum with a V8HI picks up the even
31491 halfwords (BE numbering) when the even halfwords (LE
31492 numbering) are what we need. */
31493 if (!BYTES_BIG_ENDIAN
31494 && icode == CODE_FOR_altivec_vpkuwum_direct
31495 && ((GET_CODE (op0) == REG
31496 && GET_MODE (op0) != V4SImode)
31497 || (GET_CODE (op0) == SUBREG
31498 && GET_MODE (XEXP (op0, 0)) != V4SImode)))
31499 continue;
31500 if (!BYTES_BIG_ENDIAN
31501 && icode == CODE_FOR_altivec_vpkuhum_direct
31502 && ((GET_CODE (op0) == REG
31503 && GET_MODE (op0) != V8HImode)
31504 || (GET_CODE (op0) == SUBREG
31505 && GET_MODE (XEXP (op0, 0)) != V8HImode)))
31506 continue;
31508 /* For little-endian, the two input operands must be swapped
31509 (or swapped back) to ensure proper right-to-left numbering
31510 from 0 to 2N-1. */
31511 if (swapped ^ !BYTES_BIG_ENDIAN)
31512 std::swap (op0, op1);
31513 if (imode != V16QImode)
31515 op0 = gen_lowpart (imode, op0);
31516 op1 = gen_lowpart (imode, op1);
31518 if (omode == V16QImode)
31519 x = target;
31520 else
31521 x = gen_reg_rtx (omode);
31522 emit_insn (GEN_FCN (icode) (x, op0, op1));
31523 if (omode != V16QImode)
31524 emit_move_insn (target, gen_lowpart (V16QImode, x));
31525 return true;
31529 if (!BYTES_BIG_ENDIAN)
31531 altivec_expand_vec_perm_const_le (operands);
31532 return true;
31535 return false;
31538 /* Expand a Paired Single, VSX Permute Doubleword, or SPE constant permutation.
31539 Return true if we match an efficient implementation. */
31541 static bool
31542 rs6000_expand_vec_perm_const_1 (rtx target, rtx op0, rtx op1,
31543 unsigned char perm0, unsigned char perm1)
31545 rtx x;
31547 /* If both selectors come from the same operand, fold to single op. */
31548 if ((perm0 & 2) == (perm1 & 2))
31550 if (perm0 & 2)
31551 op0 = op1;
31552 else
31553 op1 = op0;
31555 /* If both operands are equal, fold to simpler permutation. */
31556 if (rtx_equal_p (op0, op1))
31558 perm0 = perm0 & 1;
31559 perm1 = (perm1 & 1) + 2;
31561 /* If the first selector comes from the second operand, swap. */
31562 else if (perm0 & 2)
31564 if (perm1 & 2)
31565 return false;
31566 perm0 -= 2;
31567 perm1 += 2;
31568 std::swap (op0, op1);
31570 /* If the second selector does not come from the second operand, fail. */
31571 else if ((perm1 & 2) == 0)
31572 return false;
31574 /* Success! */
31575 if (target != NULL)
31577 machine_mode vmode, dmode;
31578 rtvec v;
31580 vmode = GET_MODE (target);
31581 gcc_assert (GET_MODE_NUNITS (vmode) == 2);
31582 dmode = mode_for_vector (GET_MODE_INNER (vmode), 4);
31583 x = gen_rtx_VEC_CONCAT (dmode, op0, op1);
31584 v = gen_rtvec (2, GEN_INT (perm0), GEN_INT (perm1));
31585 x = gen_rtx_VEC_SELECT (vmode, x, gen_rtx_PARALLEL (VOIDmode, v));
31586 emit_insn (gen_rtx_SET (target, x));
31588 return true;
31591 bool
31592 rs6000_expand_vec_perm_const (rtx operands[4])
31594 rtx target, op0, op1, sel;
31595 unsigned char perm0, perm1;
31597 target = operands[0];
31598 op0 = operands[1];
31599 op1 = operands[2];
31600 sel = operands[3];
31602 /* Unpack the constant selector. */
31603 perm0 = INTVAL (XVECEXP (sel, 0, 0)) & 3;
31604 perm1 = INTVAL (XVECEXP (sel, 0, 1)) & 3;
31606 return rs6000_expand_vec_perm_const_1 (target, op0, op1, perm0, perm1);
31609 /* Test whether a constant permutation is supported. */
31611 static bool
31612 rs6000_vectorize_vec_perm_const_ok (machine_mode vmode,
31613 const unsigned char *sel)
31615 /* AltiVec (and thus VSX) can handle arbitrary permutations. */
31616 if (TARGET_ALTIVEC)
31617 return true;
31619 /* Check for ps_merge* or evmerge* insns. */
31620 if ((TARGET_PAIRED_FLOAT && vmode == V2SFmode)
31621 || (TARGET_SPE && vmode == V2SImode))
31623 rtx op0 = gen_raw_REG (vmode, LAST_VIRTUAL_REGISTER + 1);
31624 rtx op1 = gen_raw_REG (vmode, LAST_VIRTUAL_REGISTER + 2);
31625 return rs6000_expand_vec_perm_const_1 (NULL, op0, op1, sel[0], sel[1]);
31628 return false;
31631 /* A subroutine for rs6000_expand_extract_even & rs6000_expand_interleave. */
31633 static void
31634 rs6000_do_expand_vec_perm (rtx target, rtx op0, rtx op1,
31635 machine_mode vmode, unsigned nelt, rtx perm[])
31637 machine_mode imode;
31638 rtx x;
31640 imode = vmode;
31641 if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT)
31643 imode = GET_MODE_INNER (vmode);
31644 imode = mode_for_size (GET_MODE_BITSIZE (imode), MODE_INT, 0);
31645 imode = mode_for_vector (imode, nelt);
31648 x = gen_rtx_CONST_VECTOR (imode, gen_rtvec_v (nelt, perm));
31649 x = expand_vec_perm (vmode, op0, op1, x, target);
31650 if (x != target)
31651 emit_move_insn (target, x);
31654 /* Expand an extract even operation. */
31656 void
31657 rs6000_expand_extract_even (rtx target, rtx op0, rtx op1)
31659 machine_mode vmode = GET_MODE (target);
31660 unsigned i, nelt = GET_MODE_NUNITS (vmode);
31661 rtx perm[16];
31663 for (i = 0; i < nelt; i++)
31664 perm[i] = GEN_INT (i * 2);
31666 rs6000_do_expand_vec_perm (target, op0, op1, vmode, nelt, perm);
31669 /* Expand a vector interleave operation. */
31671 void
31672 rs6000_expand_interleave (rtx target, rtx op0, rtx op1, bool highp)
31674 machine_mode vmode = GET_MODE (target);
31675 unsigned i, high, nelt = GET_MODE_NUNITS (vmode);
31676 rtx perm[16];
31678 high = (highp ? 0 : nelt / 2);
31679 for (i = 0; i < nelt / 2; i++)
31681 perm[i * 2] = GEN_INT (i + high);
31682 perm[i * 2 + 1] = GEN_INT (i + nelt + high);
31685 rs6000_do_expand_vec_perm (target, op0, op1, vmode, nelt, perm);
31688 /* Scale a V2DF vector SRC by two to the SCALE and place in TGT. */
31689 void
31690 rs6000_scale_v2df (rtx tgt, rtx src, int scale)
31692 HOST_WIDE_INT hwi_scale (scale);
31693 REAL_VALUE_TYPE r_pow;
31694 rtvec v = rtvec_alloc (2);
31695 rtx elt;
31696 rtx scale_vec = gen_reg_rtx (V2DFmode);
31697 (void)real_powi (&r_pow, DFmode, &dconst2, hwi_scale);
31698 elt = CONST_DOUBLE_FROM_REAL_VALUE (r_pow, DFmode);
31699 RTVEC_ELT (v, 0) = elt;
31700 RTVEC_ELT (v, 1) = elt;
31701 rs6000_expand_vector_init (scale_vec, gen_rtx_PARALLEL (V2DFmode, v));
31702 emit_insn (gen_mulv2df3 (tgt, src, scale_vec));
31705 /* Return an RTX representing where to find the function value of a
31706 function returning MODE. */
31707 static rtx
31708 rs6000_complex_function_value (machine_mode mode)
31710 unsigned int regno;
31711 rtx r1, r2;
31712 machine_mode inner = GET_MODE_INNER (mode);
31713 unsigned int inner_bytes = GET_MODE_SIZE (inner);
31715 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
31716 regno = FP_ARG_RETURN;
31717 else
31719 regno = GP_ARG_RETURN;
31721 /* 32-bit is OK since it'll go in r3/r4. */
31722 if (TARGET_32BIT && inner_bytes >= 4)
31723 return gen_rtx_REG (mode, regno);
31726 if (inner_bytes >= 8)
31727 return gen_rtx_REG (mode, regno);
31729 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
31730 const0_rtx);
31731 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
31732 GEN_INT (inner_bytes));
31733 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
31736 /* Return an rtx describing a return value of MODE as a PARALLEL
31737 in N_ELTS registers, each of mode ELT_MODE, starting at REGNO,
31738 stride REG_STRIDE. */
31740 static rtx
31741 rs6000_parallel_return (machine_mode mode,
31742 int n_elts, machine_mode elt_mode,
31743 unsigned int regno, unsigned int reg_stride)
31745 rtx par = gen_rtx_PARALLEL (mode, rtvec_alloc (n_elts));
31747 int i;
31748 for (i = 0; i < n_elts; i++)
31750 rtx r = gen_rtx_REG (elt_mode, regno);
31751 rtx off = GEN_INT (i * GET_MODE_SIZE (elt_mode));
31752 XVECEXP (par, 0, i) = gen_rtx_EXPR_LIST (VOIDmode, r, off);
31753 regno += reg_stride;
31756 return par;
31759 /* Target hook for TARGET_FUNCTION_VALUE.
31761 On the SPE, both FPs and vectors are returned in r3.
31763 On RS/6000 an integer value is in r3 and a floating-point value is in
31764 fp1, unless -msoft-float. */
31766 static rtx
31767 rs6000_function_value (const_tree valtype,
31768 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
31769 bool outgoing ATTRIBUTE_UNUSED)
31771 machine_mode mode;
31772 unsigned int regno;
31773 machine_mode elt_mode;
31774 int n_elts;
31776 /* Special handling for structs in darwin64. */
31777 if (TARGET_MACHO
31778 && rs6000_darwin64_struct_check_p (TYPE_MODE (valtype), valtype))
31780 CUMULATIVE_ARGS valcum;
31781 rtx valret;
31783 valcum.words = 0;
31784 valcum.fregno = FP_ARG_MIN_REG;
31785 valcum.vregno = ALTIVEC_ARG_MIN_REG;
31786 /* Do a trial code generation as if this were going to be passed as
31787 an argument; if any part goes in memory, we return NULL. */
31788 valret = rs6000_darwin64_record_arg (&valcum, valtype, true, /* retval= */ true);
31789 if (valret)
31790 return valret;
31791 /* Otherwise fall through to standard ABI rules. */
31794 mode = TYPE_MODE (valtype);
31796 /* The ELFv2 ABI returns homogeneous VFP aggregates in registers. */
31797 if (rs6000_discover_homogeneous_aggregate (mode, valtype, &elt_mode, &n_elts))
31799 int first_reg, n_regs;
31801 if (SCALAR_FLOAT_MODE_P (elt_mode))
31803 /* _Decimal128 must use even/odd register pairs. */
31804 first_reg = (elt_mode == TDmode) ? FP_ARG_RETURN + 1 : FP_ARG_RETURN;
31805 n_regs = (GET_MODE_SIZE (elt_mode) + 7) >> 3;
31807 else
31809 first_reg = ALTIVEC_ARG_RETURN;
31810 n_regs = 1;
31813 return rs6000_parallel_return (mode, n_elts, elt_mode, first_reg, n_regs);
31816 /* Some return value types need be split in -mpowerpc64, 32bit ABI. */
31817 if (TARGET_32BIT && TARGET_POWERPC64)
31818 switch (mode)
31820 default:
31821 break;
31822 case DImode:
31823 case SCmode:
31824 case DCmode:
31825 case TCmode:
31826 int count = GET_MODE_SIZE (mode) / 4;
31827 return rs6000_parallel_return (mode, count, SImode, GP_ARG_RETURN, 1);
31830 if ((INTEGRAL_TYPE_P (valtype)
31831 && GET_MODE_BITSIZE (mode) < (TARGET_32BIT ? 32 : 64))
31832 || POINTER_TYPE_P (valtype))
31833 mode = TARGET_32BIT ? SImode : DImode;
31835 if (DECIMAL_FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
31836 /* _Decimal128 must use an even/odd register pair. */
31837 regno = (mode == TDmode) ? FP_ARG_RETURN + 1 : FP_ARG_RETURN;
31838 else if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS
31839 && ((TARGET_SINGLE_FLOAT && (mode == SFmode)) || TARGET_DOUBLE_FLOAT))
31840 regno = FP_ARG_RETURN;
31841 else if (TREE_CODE (valtype) == COMPLEX_TYPE
31842 && targetm.calls.split_complex_arg)
31843 return rs6000_complex_function_value (mode);
31844 /* VSX is a superset of Altivec and adds V2DImode/V2DFmode. Since the same
31845 return register is used in both cases, and we won't see V2DImode/V2DFmode
31846 for pure altivec, combine the two cases. */
31847 else if (TREE_CODE (valtype) == VECTOR_TYPE
31848 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI
31849 && ALTIVEC_OR_VSX_VECTOR_MODE (mode))
31850 regno = ALTIVEC_ARG_RETURN;
31851 else if (TARGET_E500_DOUBLE && TARGET_HARD_FLOAT
31852 && (mode == DFmode || mode == DCmode
31853 || mode == TFmode || mode == TCmode))
31854 return spe_build_register_parallel (mode, GP_ARG_RETURN);
31855 else
31856 regno = GP_ARG_RETURN;
31858 return gen_rtx_REG (mode, regno);
31861 /* Define how to find the value returned by a library function
31862 assuming the value has mode MODE. */
31864 rs6000_libcall_value (machine_mode mode)
31866 unsigned int regno;
31868 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
31869 if (TARGET_32BIT && TARGET_POWERPC64 && mode == DImode)
31870 return rs6000_parallel_return (mode, 2, SImode, GP_ARG_RETURN, 1);
31872 if (DECIMAL_FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
31873 /* _Decimal128 must use an even/odd register pair. */
31874 regno = (mode == TDmode) ? FP_ARG_RETURN + 1 : FP_ARG_RETURN;
31875 else if (SCALAR_FLOAT_MODE_P (mode)
31876 && TARGET_HARD_FLOAT && TARGET_FPRS
31877 && ((TARGET_SINGLE_FLOAT && mode == SFmode) || TARGET_DOUBLE_FLOAT))
31878 regno = FP_ARG_RETURN;
31879 /* VSX is a superset of Altivec and adds V2DImode/V2DFmode. Since the same
31880 return register is used in both cases, and we won't see V2DImode/V2DFmode
31881 for pure altivec, combine the two cases. */
31882 else if (ALTIVEC_OR_VSX_VECTOR_MODE (mode)
31883 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
31884 regno = ALTIVEC_ARG_RETURN;
31885 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
31886 return rs6000_complex_function_value (mode);
31887 else if (TARGET_E500_DOUBLE && TARGET_HARD_FLOAT
31888 && (mode == DFmode || mode == DCmode
31889 || mode == TFmode || mode == TCmode))
31890 return spe_build_register_parallel (mode, GP_ARG_RETURN);
31891 else
31892 regno = GP_ARG_RETURN;
31894 return gen_rtx_REG (mode, regno);
31898 /* Return true if we use LRA instead of reload pass. */
31899 static bool
31900 rs6000_lra_p (void)
31902 return rs6000_lra_flag;
31905 /* Given FROM and TO register numbers, say whether this elimination is allowed.
31906 Frame pointer elimination is automatically handled.
31908 For the RS/6000, if frame pointer elimination is being done, we would like
31909 to convert ap into fp, not sp.
31911 We need r30 if -mminimal-toc was specified, and there are constant pool
31912 references. */
31914 static bool
31915 rs6000_can_eliminate (const int from, const int to)
31917 return (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM
31918 ? ! frame_pointer_needed
31919 : from == RS6000_PIC_OFFSET_TABLE_REGNUM
31920 ? ! TARGET_MINIMAL_TOC || TARGET_NO_TOC || get_pool_size () == 0
31921 : true);
31924 /* Define the offset between two registers, FROM to be eliminated and its
31925 replacement TO, at the start of a routine. */
31926 HOST_WIDE_INT
31927 rs6000_initial_elimination_offset (int from, int to)
31929 rs6000_stack_t *info = rs6000_stack_info ();
31930 HOST_WIDE_INT offset;
31932 if (from == HARD_FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
31933 offset = info->push_p ? 0 : -info->total_size;
31934 else if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
31936 offset = info->push_p ? 0 : -info->total_size;
31937 if (FRAME_GROWS_DOWNWARD)
31938 offset += info->fixed_size + info->vars_size + info->parm_size;
31940 else if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
31941 offset = FRAME_GROWS_DOWNWARD
31942 ? info->fixed_size + info->vars_size + info->parm_size
31943 : 0;
31944 else if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
31945 offset = info->total_size;
31946 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
31947 offset = info->push_p ? info->total_size : 0;
31948 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
31949 offset = 0;
31950 else
31951 gcc_unreachable ();
31953 return offset;
31956 static rtx
31957 rs6000_dwarf_register_span (rtx reg)
31959 rtx parts[8];
31960 int i, words;
31961 unsigned regno = REGNO (reg);
31962 machine_mode mode = GET_MODE (reg);
31964 if (TARGET_SPE
31965 && regno < 32
31966 && (SPE_VECTOR_MODE (GET_MODE (reg))
31967 || (TARGET_E500_DOUBLE && FLOAT_MODE_P (mode)
31968 && mode != SFmode && mode != SDmode && mode != SCmode)))
31970 else
31971 return NULL_RTX;
31973 regno = REGNO (reg);
31975 /* The duality of the SPE register size wreaks all kinds of havoc.
31976 This is a way of distinguishing r0 in 32-bits from r0 in
31977 64-bits. */
31978 words = (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD;
31979 gcc_assert (words <= 4);
31980 for (i = 0; i < words; i++, regno++)
31982 if (BYTES_BIG_ENDIAN)
31984 parts[2 * i] = gen_rtx_REG (SImode, regno + FIRST_SPE_HIGH_REGNO);
31985 parts[2 * i + 1] = gen_rtx_REG (SImode, regno);
31987 else
31989 parts[2 * i] = gen_rtx_REG (SImode, regno);
31990 parts[2 * i + 1] = gen_rtx_REG (SImode, regno + FIRST_SPE_HIGH_REGNO);
31994 return gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (words * 2, parts));
31997 /* Fill in sizes for SPE register high parts in table used by unwinder. */
31999 static void
32000 rs6000_init_dwarf_reg_sizes_extra (tree address)
32002 if (TARGET_SPE)
32004 int i;
32005 machine_mode mode = TYPE_MODE (char_type_node);
32006 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, EXPAND_NORMAL);
32007 rtx mem = gen_rtx_MEM (BLKmode, addr);
32008 rtx value = gen_int_mode (4, mode);
32010 for (i = FIRST_SPE_HIGH_REGNO; i < LAST_SPE_HIGH_REGNO+1; i++)
32012 int column = DWARF_REG_TO_UNWIND_COLUMN
32013 (DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), true));
32014 HOST_WIDE_INT offset = column * GET_MODE_SIZE (mode);
32016 emit_move_insn (adjust_address (mem, mode, offset), value);
32020 if (TARGET_MACHO && ! TARGET_ALTIVEC)
32022 int i;
32023 machine_mode mode = TYPE_MODE (char_type_node);
32024 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, EXPAND_NORMAL);
32025 rtx mem = gen_rtx_MEM (BLKmode, addr);
32026 rtx value = gen_int_mode (16, mode);
32028 /* On Darwin, libgcc may be built to run on both G3 and G4/5.
32029 The unwinder still needs to know the size of Altivec registers. */
32031 for (i = FIRST_ALTIVEC_REGNO; i < LAST_ALTIVEC_REGNO+1; i++)
32033 int column = DWARF_REG_TO_UNWIND_COLUMN
32034 (DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), true));
32035 HOST_WIDE_INT offset = column * GET_MODE_SIZE (mode);
32037 emit_move_insn (adjust_address (mem, mode, offset), value);
32042 /* Map internal gcc register numbers to debug format register numbers.
32043 FORMAT specifies the type of debug register number to use:
32044 0 -- debug information, except for frame-related sections
32045 1 -- DWARF .debug_frame section
32046 2 -- DWARF .eh_frame section */
32048 unsigned int
32049 rs6000_dbx_register_number (unsigned int regno, unsigned int format)
32051 /* We never use the GCC internal number for SPE high registers.
32052 Those are mapped to the 1200..1231 range for all debug formats. */
32053 if (SPE_HIGH_REGNO_P (regno))
32054 return regno - FIRST_SPE_HIGH_REGNO + 1200;
32056 /* Except for the above, we use the internal number for non-DWARF
32057 debug information, and also for .eh_frame. */
32058 if ((format == 0 && write_symbols != DWARF2_DEBUG) || format == 2)
32059 return regno;
32061 /* On some platforms, we use the standard DWARF register
32062 numbering for .debug_info and .debug_frame. */
32063 #ifdef RS6000_USE_DWARF_NUMBERING
32064 if (regno <= 63)
32065 return regno;
32066 if (regno == LR_REGNO)
32067 return 108;
32068 if (regno == CTR_REGNO)
32069 return 109;
32070 /* Special handling for CR for .debug_frame: rs6000_emit_prologue has
32071 translated any combination of CR2, CR3, CR4 saves to a save of CR2.
32072 The actual code emitted saves the whole of CR, so we map CR2_REGNO
32073 to the DWARF reg for CR. */
32074 if (format == 1 && regno == CR2_REGNO)
32075 return 64;
32076 if (CR_REGNO_P (regno))
32077 return regno - CR0_REGNO + 86;
32078 if (regno == CA_REGNO)
32079 return 101; /* XER */
32080 if (ALTIVEC_REGNO_P (regno))
32081 return regno - FIRST_ALTIVEC_REGNO + 1124;
32082 if (regno == VRSAVE_REGNO)
32083 return 356;
32084 if (regno == VSCR_REGNO)
32085 return 67;
32086 if (regno == SPE_ACC_REGNO)
32087 return 99;
32088 if (regno == SPEFSCR_REGNO)
32089 return 612;
32090 #endif
32091 return regno;
32094 /* target hook eh_return_filter_mode */
32095 static machine_mode
32096 rs6000_eh_return_filter_mode (void)
32098 return TARGET_32BIT ? SImode : word_mode;
32101 /* Target hook for scalar_mode_supported_p. */
32102 static bool
32103 rs6000_scalar_mode_supported_p (machine_mode mode)
32105 /* -m32 does not support TImode. This is the default, from
32106 default_scalar_mode_supported_p. For -m32 -mpowerpc64 we want the
32107 same ABI as for -m32. But default_scalar_mode_supported_p allows
32108 integer modes of precision 2 * BITS_PER_WORD, which matches TImode
32109 for -mpowerpc64. */
32110 if (TARGET_32BIT && mode == TImode)
32111 return false;
32113 if (DECIMAL_FLOAT_MODE_P (mode))
32114 return default_decimal_float_supported_p ();
32115 else
32116 return default_scalar_mode_supported_p (mode);
32119 /* Target hook for vector_mode_supported_p. */
32120 static bool
32121 rs6000_vector_mode_supported_p (machine_mode mode)
32124 if (TARGET_PAIRED_FLOAT && PAIRED_VECTOR_MODE (mode))
32125 return true;
32127 if (TARGET_SPE && SPE_VECTOR_MODE (mode))
32128 return true;
32130 else if (VECTOR_MEM_ALTIVEC_OR_VSX_P (mode))
32131 return true;
32133 else
32134 return false;
32137 /* Target hook for invalid_arg_for_unprototyped_fn. */
32138 static const char *
32139 invalid_arg_for_unprototyped_fn (const_tree typelist, const_tree funcdecl, const_tree val)
32141 return (!rs6000_darwin64_abi
32142 && typelist == 0
32143 && TREE_CODE (TREE_TYPE (val)) == VECTOR_TYPE
32144 && (funcdecl == NULL_TREE
32145 || (TREE_CODE (funcdecl) == FUNCTION_DECL
32146 && DECL_BUILT_IN_CLASS (funcdecl) != BUILT_IN_MD)))
32147 ? N_("AltiVec argument passed to unprototyped function")
32148 : NULL;
32151 /* For TARGET_SECURE_PLT 32-bit PIC code we can save PIC register
32152 setup by using __stack_chk_fail_local hidden function instead of
32153 calling __stack_chk_fail directly. Otherwise it is better to call
32154 __stack_chk_fail directly. */
32156 static tree ATTRIBUTE_UNUSED
32157 rs6000_stack_protect_fail (void)
32159 return (DEFAULT_ABI == ABI_V4 && TARGET_SECURE_PLT && flag_pic)
32160 ? default_hidden_stack_protect_fail ()
32161 : default_external_stack_protect_fail ();
32164 void
32165 rs6000_final_prescan_insn (rtx_insn *insn, rtx *operand ATTRIBUTE_UNUSED,
32166 int num_operands ATTRIBUTE_UNUSED)
32168 if (rs6000_warn_cell_microcode)
32170 const char *temp;
32171 int insn_code_number = recog_memoized (insn);
32172 location_t location = INSN_LOCATION (insn);
32174 /* Punt on insns we cannot recognize. */
32175 if (insn_code_number < 0)
32176 return;
32178 temp = get_insn_template (insn_code_number, insn);
32180 if (get_attr_cell_micro (insn) == CELL_MICRO_ALWAYS)
32181 warning_at (location, OPT_mwarn_cell_microcode,
32182 "emitting microcode insn %s\t[%s] #%d",
32183 temp, insn_data[INSN_CODE (insn)].name, INSN_UID (insn));
32184 else if (get_attr_cell_micro (insn) == CELL_MICRO_CONDITIONAL)
32185 warning_at (location, OPT_mwarn_cell_microcode,
32186 "emitting conditional microcode insn %s\t[%s] #%d",
32187 temp, insn_data[INSN_CODE (insn)].name, INSN_UID (insn));
32191 /* Implement the TARGET_ASAN_SHADOW_OFFSET hook. */
32193 #if TARGET_ELF
32194 static unsigned HOST_WIDE_INT
32195 rs6000_asan_shadow_offset (void)
32197 return (unsigned HOST_WIDE_INT) 1 << (TARGET_64BIT ? 41 : 29);
32199 #endif
32201 /* Mask options that we want to support inside of attribute((target)) and
32202 #pragma GCC target operations. Note, we do not include things like
32203 64/32-bit, endianess, hard/soft floating point, etc. that would have
32204 different calling sequences. */
32206 struct rs6000_opt_mask {
32207 const char *name; /* option name */
32208 HOST_WIDE_INT mask; /* mask to set */
32209 bool invert; /* invert sense of mask */
32210 bool valid_target; /* option is a target option */
32213 static struct rs6000_opt_mask const rs6000_opt_masks[] =
32215 { "altivec", OPTION_MASK_ALTIVEC, false, true },
32216 { "cmpb", OPTION_MASK_CMPB, false, true },
32217 { "crypto", OPTION_MASK_CRYPTO, false, true },
32218 { "direct-move", OPTION_MASK_DIRECT_MOVE, false, true },
32219 { "dlmzb", OPTION_MASK_DLMZB, false, true },
32220 { "fprnd", OPTION_MASK_FPRND, false, true },
32221 { "hard-dfp", OPTION_MASK_DFP, false, true },
32222 { "htm", OPTION_MASK_HTM, false, true },
32223 { "isel", OPTION_MASK_ISEL, false, true },
32224 { "mfcrf", OPTION_MASK_MFCRF, false, true },
32225 { "mfpgpr", OPTION_MASK_MFPGPR, false, true },
32226 { "mulhw", OPTION_MASK_MULHW, false, true },
32227 { "multiple", OPTION_MASK_MULTIPLE, false, true },
32228 { "popcntb", OPTION_MASK_POPCNTB, false, true },
32229 { "popcntd", OPTION_MASK_POPCNTD, false, true },
32230 { "power8-fusion", OPTION_MASK_P8_FUSION, false, true },
32231 { "power8-fusion-sign", OPTION_MASK_P8_FUSION_SIGN, false, true },
32232 { "power8-vector", OPTION_MASK_P8_VECTOR, false, true },
32233 { "powerpc-gfxopt", OPTION_MASK_PPC_GFXOPT, false, true },
32234 { "powerpc-gpopt", OPTION_MASK_PPC_GPOPT, false, true },
32235 { "quad-memory", OPTION_MASK_QUAD_MEMORY, false, true },
32236 { "quad-memory-atomic", OPTION_MASK_QUAD_MEMORY_ATOMIC, false, true },
32237 { "recip-precision", OPTION_MASK_RECIP_PRECISION, false, true },
32238 { "save-toc-indirect", OPTION_MASK_SAVE_TOC_INDIRECT, false, true },
32239 { "string", OPTION_MASK_STRING, false, true },
32240 { "update", OPTION_MASK_NO_UPDATE, true , true },
32241 { "upper-regs-df", OPTION_MASK_UPPER_REGS_DF, false, true },
32242 { "upper-regs-sf", OPTION_MASK_UPPER_REGS_SF, false, true },
32243 { "vsx", OPTION_MASK_VSX, false, true },
32244 { "vsx-timode", OPTION_MASK_VSX_TIMODE, false, true },
32245 #ifdef OPTION_MASK_64BIT
32246 #if TARGET_AIX_OS
32247 { "aix64", OPTION_MASK_64BIT, false, false },
32248 { "aix32", OPTION_MASK_64BIT, true, false },
32249 #else
32250 { "64", OPTION_MASK_64BIT, false, false },
32251 { "32", OPTION_MASK_64BIT, true, false },
32252 #endif
32253 #endif
32254 #ifdef OPTION_MASK_EABI
32255 { "eabi", OPTION_MASK_EABI, false, false },
32256 #endif
32257 #ifdef OPTION_MASK_LITTLE_ENDIAN
32258 { "little", OPTION_MASK_LITTLE_ENDIAN, false, false },
32259 { "big", OPTION_MASK_LITTLE_ENDIAN, true, false },
32260 #endif
32261 #ifdef OPTION_MASK_RELOCATABLE
32262 { "relocatable", OPTION_MASK_RELOCATABLE, false, false },
32263 #endif
32264 #ifdef OPTION_MASK_STRICT_ALIGN
32265 { "strict-align", OPTION_MASK_STRICT_ALIGN, false, false },
32266 #endif
32267 { "soft-float", OPTION_MASK_SOFT_FLOAT, false, false },
32268 { "string", OPTION_MASK_STRING, false, false },
32271 /* Builtin mask mapping for printing the flags. */
32272 static struct rs6000_opt_mask const rs6000_builtin_mask_names[] =
32274 { "altivec", RS6000_BTM_ALTIVEC, false, false },
32275 { "vsx", RS6000_BTM_VSX, false, false },
32276 { "spe", RS6000_BTM_SPE, false, false },
32277 { "paired", RS6000_BTM_PAIRED, false, false },
32278 { "fre", RS6000_BTM_FRE, false, false },
32279 { "fres", RS6000_BTM_FRES, false, false },
32280 { "frsqrte", RS6000_BTM_FRSQRTE, false, false },
32281 { "frsqrtes", RS6000_BTM_FRSQRTES, false, false },
32282 { "popcntd", RS6000_BTM_POPCNTD, false, false },
32283 { "cell", RS6000_BTM_CELL, false, false },
32284 { "power8-vector", RS6000_BTM_P8_VECTOR, false, false },
32285 { "crypto", RS6000_BTM_CRYPTO, false, false },
32286 { "htm", RS6000_BTM_HTM, false, false },
32287 { "hard-dfp", RS6000_BTM_DFP, false, false },
32288 { "hard-float", RS6000_BTM_HARD_FLOAT, false, false },
32289 { "long-double-128", RS6000_BTM_LDBL128, false, false },
32292 /* Option variables that we want to support inside attribute((target)) and
32293 #pragma GCC target operations. */
32295 struct rs6000_opt_var {
32296 const char *name; /* option name */
32297 size_t global_offset; /* offset of the option in global_options. */
32298 size_t target_offset; /* offset of the option in target optiosn. */
32301 static struct rs6000_opt_var const rs6000_opt_vars[] =
32303 { "friz",
32304 offsetof (struct gcc_options, x_TARGET_FRIZ),
32305 offsetof (struct cl_target_option, x_TARGET_FRIZ), },
32306 { "avoid-indexed-addresses",
32307 offsetof (struct gcc_options, x_TARGET_AVOID_XFORM),
32308 offsetof (struct cl_target_option, x_TARGET_AVOID_XFORM) },
32309 { "paired",
32310 offsetof (struct gcc_options, x_rs6000_paired_float),
32311 offsetof (struct cl_target_option, x_rs6000_paired_float), },
32312 { "longcall",
32313 offsetof (struct gcc_options, x_rs6000_default_long_calls),
32314 offsetof (struct cl_target_option, x_rs6000_default_long_calls), },
32315 { "optimize-swaps",
32316 offsetof (struct gcc_options, x_rs6000_optimize_swaps),
32317 offsetof (struct cl_target_option, x_rs6000_optimize_swaps), },
32318 { "allow-movmisalign",
32319 offsetof (struct gcc_options, x_TARGET_ALLOW_MOVMISALIGN),
32320 offsetof (struct cl_target_option, x_TARGET_ALLOW_MOVMISALIGN), },
32321 { "allow-df-permute",
32322 offsetof (struct gcc_options, x_TARGET_ALLOW_DF_PERMUTE),
32323 offsetof (struct cl_target_option, x_TARGET_ALLOW_DF_PERMUTE), },
32324 { "sched-groups",
32325 offsetof (struct gcc_options, x_TARGET_SCHED_GROUPS),
32326 offsetof (struct cl_target_option, x_TARGET_SCHED_GROUPS), },
32327 { "always-hint",
32328 offsetof (struct gcc_options, x_TARGET_ALWAYS_HINT),
32329 offsetof (struct cl_target_option, x_TARGET_ALWAYS_HINT), },
32330 { "align-branch-targets",
32331 offsetof (struct gcc_options, x_TARGET_ALIGN_BRANCH_TARGETS),
32332 offsetof (struct cl_target_option, x_TARGET_ALIGN_BRANCH_TARGETS), },
32333 { "vectorize-builtins",
32334 offsetof (struct gcc_options, x_TARGET_VECTORIZE_BUILTINS),
32335 offsetof (struct cl_target_option, x_TARGET_VECTORIZE_BUILTINS), },
32336 { "tls-markers",
32337 offsetof (struct gcc_options, x_tls_markers),
32338 offsetof (struct cl_target_option, x_tls_markers), },
32339 { "sched-prolog",
32340 offsetof (struct gcc_options, x_TARGET_SCHED_PROLOG),
32341 offsetof (struct cl_target_option, x_TARGET_SCHED_PROLOG), },
32342 { "sched-epilog",
32343 offsetof (struct gcc_options, x_TARGET_SCHED_PROLOG),
32344 offsetof (struct cl_target_option, x_TARGET_SCHED_PROLOG), },
32345 { "gen-cell-microcode",
32346 offsetof (struct gcc_options, x_rs6000_gen_cell_microcode),
32347 offsetof (struct cl_target_option, x_rs6000_gen_cell_microcode), },
32348 { "warn-cell-microcode",
32349 offsetof (struct gcc_options, x_rs6000_warn_cell_microcode),
32350 offsetof (struct cl_target_option, x_rs6000_warn_cell_microcode), },
32353 /* Inner function to handle attribute((target("..."))) and #pragma GCC target
32354 parsing. Return true if there were no errors. */
32356 static bool
32357 rs6000_inner_target_options (tree args, bool attr_p)
32359 bool ret = true;
32361 if (args == NULL_TREE)
32364 else if (TREE_CODE (args) == STRING_CST)
32366 char *p = ASTRDUP (TREE_STRING_POINTER (args));
32367 char *q;
32369 while ((q = strtok (p, ",")) != NULL)
32371 bool error_p = false;
32372 bool not_valid_p = false;
32373 const char *cpu_opt = NULL;
32375 p = NULL;
32376 if (strncmp (q, "cpu=", 4) == 0)
32378 int cpu_index = rs6000_cpu_name_lookup (q+4);
32379 if (cpu_index >= 0)
32380 rs6000_cpu_index = cpu_index;
32381 else
32383 error_p = true;
32384 cpu_opt = q+4;
32387 else if (strncmp (q, "tune=", 5) == 0)
32389 int tune_index = rs6000_cpu_name_lookup (q+5);
32390 if (tune_index >= 0)
32391 rs6000_tune_index = tune_index;
32392 else
32394 error_p = true;
32395 cpu_opt = q+5;
32398 else
32400 size_t i;
32401 bool invert = false;
32402 char *r = q;
32404 error_p = true;
32405 if (strncmp (r, "no-", 3) == 0)
32407 invert = true;
32408 r += 3;
32411 for (i = 0; i < ARRAY_SIZE (rs6000_opt_masks); i++)
32412 if (strcmp (r, rs6000_opt_masks[i].name) == 0)
32414 HOST_WIDE_INT mask = rs6000_opt_masks[i].mask;
32416 if (!rs6000_opt_masks[i].valid_target)
32417 not_valid_p = true;
32418 else
32420 error_p = false;
32421 rs6000_isa_flags_explicit |= mask;
32423 /* VSX needs altivec, so -mvsx automagically sets
32424 altivec and disables -mavoid-indexed-addresses. */
32425 if (!invert)
32427 if (mask == OPTION_MASK_VSX)
32429 mask |= OPTION_MASK_ALTIVEC;
32430 TARGET_AVOID_XFORM = 0;
32434 if (rs6000_opt_masks[i].invert)
32435 invert = !invert;
32437 if (invert)
32438 rs6000_isa_flags &= ~mask;
32439 else
32440 rs6000_isa_flags |= mask;
32442 break;
32445 if (error_p && !not_valid_p)
32447 for (i = 0; i < ARRAY_SIZE (rs6000_opt_vars); i++)
32448 if (strcmp (r, rs6000_opt_vars[i].name) == 0)
32450 size_t j = rs6000_opt_vars[i].global_offset;
32451 *((int *) ((char *)&global_options + j)) = !invert;
32452 error_p = false;
32453 not_valid_p = false;
32454 break;
32459 if (error_p)
32461 const char *eprefix, *esuffix;
32463 ret = false;
32464 if (attr_p)
32466 eprefix = "__attribute__((__target__(";
32467 esuffix = ")))";
32469 else
32471 eprefix = "#pragma GCC target ";
32472 esuffix = "";
32475 if (cpu_opt)
32476 error ("invalid cpu \"%s\" for %s\"%s\"%s", cpu_opt, eprefix,
32477 q, esuffix);
32478 else if (not_valid_p)
32479 error ("%s\"%s\"%s is not allowed", eprefix, q, esuffix);
32480 else
32481 error ("%s\"%s\"%s is invalid", eprefix, q, esuffix);
32486 else if (TREE_CODE (args) == TREE_LIST)
32490 tree value = TREE_VALUE (args);
32491 if (value)
32493 bool ret2 = rs6000_inner_target_options (value, attr_p);
32494 if (!ret2)
32495 ret = false;
32497 args = TREE_CHAIN (args);
32499 while (args != NULL_TREE);
32502 else
32503 gcc_unreachable ();
32505 return ret;
32508 /* Print out the target options as a list for -mdebug=target. */
32510 static void
32511 rs6000_debug_target_options (tree args, const char *prefix)
32513 if (args == NULL_TREE)
32514 fprintf (stderr, "%s<NULL>", prefix);
32516 else if (TREE_CODE (args) == STRING_CST)
32518 char *p = ASTRDUP (TREE_STRING_POINTER (args));
32519 char *q;
32521 while ((q = strtok (p, ",")) != NULL)
32523 p = NULL;
32524 fprintf (stderr, "%s\"%s\"", prefix, q);
32525 prefix = ", ";
32529 else if (TREE_CODE (args) == TREE_LIST)
32533 tree value = TREE_VALUE (args);
32534 if (value)
32536 rs6000_debug_target_options (value, prefix);
32537 prefix = ", ";
32539 args = TREE_CHAIN (args);
32541 while (args != NULL_TREE);
32544 else
32545 gcc_unreachable ();
32547 return;
32551 /* Hook to validate attribute((target("..."))). */
32553 static bool
32554 rs6000_valid_attribute_p (tree fndecl,
32555 tree ARG_UNUSED (name),
32556 tree args,
32557 int flags)
32559 struct cl_target_option cur_target;
32560 bool ret;
32561 tree old_optimize = build_optimization_node (&global_options);
32562 tree new_target, new_optimize;
32563 tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
32565 gcc_assert ((fndecl != NULL_TREE) && (args != NULL_TREE));
32567 if (TARGET_DEBUG_TARGET)
32569 tree tname = DECL_NAME (fndecl);
32570 fprintf (stderr, "\n==================== rs6000_valid_attribute_p:\n");
32571 if (tname)
32572 fprintf (stderr, "function: %.*s\n",
32573 (int) IDENTIFIER_LENGTH (tname),
32574 IDENTIFIER_POINTER (tname));
32575 else
32576 fprintf (stderr, "function: unknown\n");
32578 fprintf (stderr, "args:");
32579 rs6000_debug_target_options (args, " ");
32580 fprintf (stderr, "\n");
32582 if (flags)
32583 fprintf (stderr, "flags: 0x%x\n", flags);
32585 fprintf (stderr, "--------------------\n");
32588 old_optimize = build_optimization_node (&global_options);
32589 func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
32591 /* If the function changed the optimization levels as well as setting target
32592 options, start with the optimizations specified. */
32593 if (func_optimize && func_optimize != old_optimize)
32594 cl_optimization_restore (&global_options,
32595 TREE_OPTIMIZATION (func_optimize));
32597 /* The target attributes may also change some optimization flags, so update
32598 the optimization options if necessary. */
32599 cl_target_option_save (&cur_target, &global_options);
32600 rs6000_cpu_index = rs6000_tune_index = -1;
32601 ret = rs6000_inner_target_options (args, true);
32603 /* Set up any additional state. */
32604 if (ret)
32606 ret = rs6000_option_override_internal (false);
32607 new_target = build_target_option_node (&global_options);
32609 else
32610 new_target = NULL;
32612 new_optimize = build_optimization_node (&global_options);
32614 if (!new_target)
32615 ret = false;
32617 else if (fndecl)
32619 DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
32621 if (old_optimize != new_optimize)
32622 DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
32625 cl_target_option_restore (&global_options, &cur_target);
32627 if (old_optimize != new_optimize)
32628 cl_optimization_restore (&global_options,
32629 TREE_OPTIMIZATION (old_optimize));
32631 return ret;
32635 /* Hook to validate the current #pragma GCC target and set the state, and
32636 update the macros based on what was changed. If ARGS is NULL, then
32637 POP_TARGET is used to reset the options. */
32639 bool
32640 rs6000_pragma_target_parse (tree args, tree pop_target)
32642 tree prev_tree = build_target_option_node (&global_options);
32643 tree cur_tree;
32644 struct cl_target_option *prev_opt, *cur_opt;
32645 HOST_WIDE_INT prev_flags, cur_flags, diff_flags;
32646 HOST_WIDE_INT prev_bumask, cur_bumask, diff_bumask;
32648 if (TARGET_DEBUG_TARGET)
32650 fprintf (stderr, "\n==================== rs6000_pragma_target_parse\n");
32651 fprintf (stderr, "args:");
32652 rs6000_debug_target_options (args, " ");
32653 fprintf (stderr, "\n");
32655 if (pop_target)
32657 fprintf (stderr, "pop_target:\n");
32658 debug_tree (pop_target);
32660 else
32661 fprintf (stderr, "pop_target: <NULL>\n");
32663 fprintf (stderr, "--------------------\n");
32666 if (! args)
32668 cur_tree = ((pop_target)
32669 ? pop_target
32670 : target_option_default_node);
32671 cl_target_option_restore (&global_options,
32672 TREE_TARGET_OPTION (cur_tree));
32674 else
32676 rs6000_cpu_index = rs6000_tune_index = -1;
32677 if (!rs6000_inner_target_options (args, false)
32678 || !rs6000_option_override_internal (false)
32679 || (cur_tree = build_target_option_node (&global_options))
32680 == NULL_TREE)
32682 if (TARGET_DEBUG_BUILTIN || TARGET_DEBUG_TARGET)
32683 fprintf (stderr, "invalid pragma\n");
32685 return false;
32689 target_option_current_node = cur_tree;
32691 /* If we have the preprocessor linked in (i.e. C or C++ languages), possibly
32692 change the macros that are defined. */
32693 if (rs6000_target_modify_macros_ptr)
32695 prev_opt = TREE_TARGET_OPTION (prev_tree);
32696 prev_bumask = prev_opt->x_rs6000_builtin_mask;
32697 prev_flags = prev_opt->x_rs6000_isa_flags;
32699 cur_opt = TREE_TARGET_OPTION (cur_tree);
32700 cur_flags = cur_opt->x_rs6000_isa_flags;
32701 cur_bumask = cur_opt->x_rs6000_builtin_mask;
32703 diff_bumask = (prev_bumask ^ cur_bumask);
32704 diff_flags = (prev_flags ^ cur_flags);
32706 if ((diff_flags != 0) || (diff_bumask != 0))
32708 /* Delete old macros. */
32709 rs6000_target_modify_macros_ptr (false,
32710 prev_flags & diff_flags,
32711 prev_bumask & diff_bumask);
32713 /* Define new macros. */
32714 rs6000_target_modify_macros_ptr (true,
32715 cur_flags & diff_flags,
32716 cur_bumask & diff_bumask);
32720 return true;
32724 /* Remember the last target of rs6000_set_current_function. */
32725 static GTY(()) tree rs6000_previous_fndecl;
32727 /* Establish appropriate back-end context for processing the function
32728 FNDECL. The argument might be NULL to indicate processing at top
32729 level, outside of any function scope. */
32730 static void
32731 rs6000_set_current_function (tree fndecl)
32733 tree old_tree = (rs6000_previous_fndecl
32734 ? DECL_FUNCTION_SPECIFIC_TARGET (rs6000_previous_fndecl)
32735 : NULL_TREE);
32737 tree new_tree = (fndecl
32738 ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
32739 : NULL_TREE);
32741 if (TARGET_DEBUG_TARGET)
32743 bool print_final = false;
32744 fprintf (stderr, "\n==================== rs6000_set_current_function");
32746 if (fndecl)
32747 fprintf (stderr, ", fndecl %s (%p)",
32748 (DECL_NAME (fndecl)
32749 ? IDENTIFIER_POINTER (DECL_NAME (fndecl))
32750 : "<unknown>"), (void *)fndecl);
32752 if (rs6000_previous_fndecl)
32753 fprintf (stderr, ", prev_fndecl (%p)", (void *)rs6000_previous_fndecl);
32755 fprintf (stderr, "\n");
32756 if (new_tree)
32758 fprintf (stderr, "\nnew fndecl target specific options:\n");
32759 debug_tree (new_tree);
32760 print_final = true;
32763 if (old_tree)
32765 fprintf (stderr, "\nold fndecl target specific options:\n");
32766 debug_tree (old_tree);
32767 print_final = true;
32770 if (print_final)
32771 fprintf (stderr, "--------------------\n");
32774 /* Only change the context if the function changes. This hook is called
32775 several times in the course of compiling a function, and we don't want to
32776 slow things down too much or call target_reinit when it isn't safe. */
32777 if (fndecl && fndecl != rs6000_previous_fndecl)
32779 rs6000_previous_fndecl = fndecl;
32780 if (old_tree == new_tree)
32783 else if (new_tree && new_tree != target_option_default_node)
32785 cl_target_option_restore (&global_options,
32786 TREE_TARGET_OPTION (new_tree));
32787 if (TREE_TARGET_GLOBALS (new_tree))
32788 restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
32789 else
32790 TREE_TARGET_GLOBALS (new_tree)
32791 = save_target_globals_default_opts ();
32794 else if (old_tree && old_tree != target_option_default_node)
32796 new_tree = target_option_current_node;
32797 cl_target_option_restore (&global_options,
32798 TREE_TARGET_OPTION (new_tree));
32799 if (TREE_TARGET_GLOBALS (new_tree))
32800 restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
32801 else if (new_tree == target_option_default_node)
32802 restore_target_globals (&default_target_globals);
32803 else
32804 TREE_TARGET_GLOBALS (new_tree)
32805 = save_target_globals_default_opts ();
32811 /* Save the current options */
32813 static void
32814 rs6000_function_specific_save (struct cl_target_option *ptr,
32815 struct gcc_options *opts)
32817 ptr->x_rs6000_isa_flags = opts->x_rs6000_isa_flags;
32818 ptr->x_rs6000_isa_flags_explicit = opts->x_rs6000_isa_flags_explicit;
32821 /* Restore the current options */
32823 static void
32824 rs6000_function_specific_restore (struct gcc_options *opts,
32825 struct cl_target_option *ptr)
32828 opts->x_rs6000_isa_flags = ptr->x_rs6000_isa_flags;
32829 opts->x_rs6000_isa_flags_explicit = ptr->x_rs6000_isa_flags_explicit;
32830 (void) rs6000_option_override_internal (false);
32833 /* Print the current options */
32835 static void
32836 rs6000_function_specific_print (FILE *file, int indent,
32837 struct cl_target_option *ptr)
32839 rs6000_print_isa_options (file, indent, "Isa options set",
32840 ptr->x_rs6000_isa_flags);
32842 rs6000_print_isa_options (file, indent, "Isa options explicit",
32843 ptr->x_rs6000_isa_flags_explicit);
32846 /* Helper function to print the current isa or misc options on a line. */
32848 static void
32849 rs6000_print_options_internal (FILE *file,
32850 int indent,
32851 const char *string,
32852 HOST_WIDE_INT flags,
32853 const char *prefix,
32854 const struct rs6000_opt_mask *opts,
32855 size_t num_elements)
32857 size_t i;
32858 size_t start_column = 0;
32859 size_t cur_column;
32860 size_t max_column = 76;
32861 const char *comma = "";
32863 if (indent)
32864 start_column += fprintf (file, "%*s", indent, "");
32866 if (!flags)
32868 fprintf (stderr, DEBUG_FMT_S, string, "<none>");
32869 return;
32872 start_column += fprintf (stderr, DEBUG_FMT_WX, string, flags);
32874 /* Print the various mask options. */
32875 cur_column = start_column;
32876 for (i = 0; i < num_elements; i++)
32878 if ((flags & opts[i].mask) != 0)
32880 const char *no_str = rs6000_opt_masks[i].invert ? "no-" : "";
32881 size_t len = (strlen (comma)
32882 + strlen (prefix)
32883 + strlen (no_str)
32884 + strlen (rs6000_opt_masks[i].name));
32886 cur_column += len;
32887 if (cur_column > max_column)
32889 fprintf (stderr, ", \\\n%*s", (int)start_column, "");
32890 cur_column = start_column + len;
32891 comma = "";
32894 fprintf (file, "%s%s%s%s", comma, prefix, no_str,
32895 rs6000_opt_masks[i].name);
32896 flags &= ~ opts[i].mask;
32897 comma = ", ";
32901 fputs ("\n", file);
32904 /* Helper function to print the current isa options on a line. */
32906 static void
32907 rs6000_print_isa_options (FILE *file, int indent, const char *string,
32908 HOST_WIDE_INT flags)
32910 rs6000_print_options_internal (file, indent, string, flags, "-m",
32911 &rs6000_opt_masks[0],
32912 ARRAY_SIZE (rs6000_opt_masks));
32915 static void
32916 rs6000_print_builtin_options (FILE *file, int indent, const char *string,
32917 HOST_WIDE_INT flags)
32919 rs6000_print_options_internal (file, indent, string, flags, "",
32920 &rs6000_builtin_mask_names[0],
32921 ARRAY_SIZE (rs6000_builtin_mask_names));
32925 /* Hook to determine if one function can safely inline another. */
32927 static bool
32928 rs6000_can_inline_p (tree caller, tree callee)
32930 bool ret = false;
32931 tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
32932 tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
32934 /* If callee has no option attributes, then it is ok to inline. */
32935 if (!callee_tree)
32936 ret = true;
32938 /* If caller has no option attributes, but callee does then it is not ok to
32939 inline. */
32940 else if (!caller_tree)
32941 ret = false;
32943 else
32945 struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
32946 struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
32948 /* Callee's options should a subset of the caller's, i.e. a vsx function
32949 can inline an altivec function but a non-vsx function can't inline a
32950 vsx function. */
32951 if ((caller_opts->x_rs6000_isa_flags & callee_opts->x_rs6000_isa_flags)
32952 == callee_opts->x_rs6000_isa_flags)
32953 ret = true;
32956 if (TARGET_DEBUG_TARGET)
32957 fprintf (stderr, "rs6000_can_inline_p:, caller %s, callee %s, %s inline\n",
32958 (DECL_NAME (caller)
32959 ? IDENTIFIER_POINTER (DECL_NAME (caller))
32960 : "<unknown>"),
32961 (DECL_NAME (callee)
32962 ? IDENTIFIER_POINTER (DECL_NAME (callee))
32963 : "<unknown>"),
32964 (ret ? "can" : "cannot"));
32966 return ret;
32969 /* Allocate a stack temp and fixup the address so it meets the particular
32970 memory requirements (either offetable or REG+REG addressing). */
32973 rs6000_allocate_stack_temp (machine_mode mode,
32974 bool offsettable_p,
32975 bool reg_reg_p)
32977 rtx stack = assign_stack_temp (mode, GET_MODE_SIZE (mode));
32978 rtx addr = XEXP (stack, 0);
32979 int strict_p = (reload_in_progress || reload_completed);
32981 if (!legitimate_indirect_address_p (addr, strict_p))
32983 if (offsettable_p
32984 && !rs6000_legitimate_offset_address_p (mode, addr, strict_p, true))
32985 stack = replace_equiv_address (stack, copy_addr_to_reg (addr));
32987 else if (reg_reg_p && !legitimate_indexed_address_p (addr, strict_p))
32988 stack = replace_equiv_address (stack, copy_addr_to_reg (addr));
32991 return stack;
32994 /* Given a memory reference, if it is not a reg or reg+reg addressing, convert
32995 to such a form to deal with memory reference instructions like STFIWX that
32996 only take reg+reg addressing. */
32999 rs6000_address_for_fpconvert (rtx x)
33001 int strict_p = (reload_in_progress || reload_completed);
33002 rtx addr;
33004 gcc_assert (MEM_P (x));
33005 addr = XEXP (x, 0);
33006 if (! legitimate_indirect_address_p (addr, strict_p)
33007 && ! legitimate_indexed_address_p (addr, strict_p))
33009 if (GET_CODE (addr) == PRE_INC || GET_CODE (addr) == PRE_DEC)
33011 rtx reg = XEXP (addr, 0);
33012 HOST_WIDE_INT size = GET_MODE_SIZE (GET_MODE (x));
33013 rtx size_rtx = GEN_INT ((GET_CODE (addr) == PRE_DEC) ? -size : size);
33014 gcc_assert (REG_P (reg));
33015 emit_insn (gen_add3_insn (reg, reg, size_rtx));
33016 addr = reg;
33018 else if (GET_CODE (addr) == PRE_MODIFY)
33020 rtx reg = XEXP (addr, 0);
33021 rtx expr = XEXP (addr, 1);
33022 gcc_assert (REG_P (reg));
33023 gcc_assert (GET_CODE (expr) == PLUS);
33024 emit_insn (gen_add3_insn (reg, XEXP (expr, 0), XEXP (expr, 1)));
33025 addr = reg;
33028 x = replace_equiv_address (x, copy_addr_to_reg (addr));
33031 return x;
33034 /* Given a memory reference, if it is not in the form for altivec memory
33035 reference instructions (i.e. reg or reg+reg addressing with AND of -16),
33036 convert to the altivec format. */
33039 rs6000_address_for_altivec (rtx x)
33041 gcc_assert (MEM_P (x));
33042 if (!altivec_indexed_or_indirect_operand (x, GET_MODE (x)))
33044 rtx addr = XEXP (x, 0);
33045 int strict_p = (reload_in_progress || reload_completed);
33047 if (!legitimate_indexed_address_p (addr, strict_p)
33048 && !legitimate_indirect_address_p (addr, strict_p))
33049 addr = copy_to_mode_reg (Pmode, addr);
33051 addr = gen_rtx_AND (Pmode, addr, GEN_INT (-16));
33052 x = change_address (x, GET_MODE (x), addr);
33055 return x;
33058 /* Implement TARGET_LEGITIMATE_CONSTANT_P.
33060 On the RS/6000, all integer constants are acceptable, most won't be valid
33061 for particular insns, though. Only easy FP constants are acceptable. */
33063 static bool
33064 rs6000_legitimate_constant_p (machine_mode mode, rtx x)
33066 if (TARGET_ELF && tls_referenced_p (x))
33067 return false;
33069 return ((GET_CODE (x) != CONST_DOUBLE && GET_CODE (x) != CONST_VECTOR)
33070 || GET_MODE (x) == VOIDmode
33071 || (TARGET_POWERPC64 && mode == DImode)
33072 || easy_fp_constant (x, mode)
33073 || easy_vector_constant (x, mode));
33077 /* Return TRUE iff the sequence ending in LAST sets the static chain. */
33079 static bool
33080 chain_already_loaded (rtx_insn *last)
33082 for (; last != NULL; last = PREV_INSN (last))
33084 if (NONJUMP_INSN_P (last))
33086 rtx patt = PATTERN (last);
33088 if (GET_CODE (patt) == SET)
33090 rtx lhs = XEXP (patt, 0);
33092 if (REG_P (lhs) && REGNO (lhs) == STATIC_CHAIN_REGNUM)
33093 return true;
33097 return false;
33100 /* Expand code to perform a call under the AIX or ELFv2 ABI. */
33102 void
33103 rs6000_call_aix (rtx value, rtx func_desc, rtx flag, rtx cookie)
33105 const bool direct_call_p
33106 = GET_CODE (func_desc) == SYMBOL_REF && SYMBOL_REF_FUNCTION_P (func_desc);
33107 rtx toc_reg = gen_rtx_REG (Pmode, TOC_REGNUM);
33108 rtx toc_load = NULL_RTX;
33109 rtx toc_restore = NULL_RTX;
33110 rtx func_addr;
33111 rtx abi_reg = NULL_RTX;
33112 rtx call[4];
33113 int n_call;
33114 rtx insn;
33116 /* Handle longcall attributes. */
33117 if (INTVAL (cookie) & CALL_LONG)
33118 func_desc = rs6000_longcall_ref (func_desc);
33120 /* Handle indirect calls. */
33121 if (GET_CODE (func_desc) != SYMBOL_REF
33122 || (DEFAULT_ABI == ABI_AIX && !SYMBOL_REF_FUNCTION_P (func_desc)))
33124 /* Save the TOC into its reserved slot before the call,
33125 and prepare to restore it after the call. */
33126 rtx stack_ptr = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
33127 rtx stack_toc_offset = GEN_INT (RS6000_TOC_SAVE_SLOT);
33128 rtx stack_toc_mem = gen_frame_mem (Pmode,
33129 gen_rtx_PLUS (Pmode, stack_ptr,
33130 stack_toc_offset));
33131 rtx stack_toc_unspec = gen_rtx_UNSPEC (Pmode,
33132 gen_rtvec (1, stack_toc_offset),
33133 UNSPEC_TOCSLOT);
33134 toc_restore = gen_rtx_SET (toc_reg, stack_toc_unspec);
33136 /* Can we optimize saving the TOC in the prologue or
33137 do we need to do it at every call? */
33138 if (TARGET_SAVE_TOC_INDIRECT && !cfun->calls_alloca)
33139 cfun->machine->save_toc_in_prologue = true;
33140 else
33142 MEM_VOLATILE_P (stack_toc_mem) = 1;
33143 emit_move_insn (stack_toc_mem, toc_reg);
33146 if (DEFAULT_ABI == ABI_ELFv2)
33148 /* A function pointer in the ELFv2 ABI is just a plain address, but
33149 the ABI requires it to be loaded into r12 before the call. */
33150 func_addr = gen_rtx_REG (Pmode, 12);
33151 emit_move_insn (func_addr, func_desc);
33152 abi_reg = func_addr;
33154 else
33156 /* A function pointer under AIX is a pointer to a data area whose
33157 first word contains the actual address of the function, whose
33158 second word contains a pointer to its TOC, and whose third word
33159 contains a value to place in the static chain register (r11).
33160 Note that if we load the static chain, our "trampoline" need
33161 not have any executable code. */
33163 /* Load up address of the actual function. */
33164 func_desc = force_reg (Pmode, func_desc);
33165 func_addr = gen_reg_rtx (Pmode);
33166 emit_move_insn (func_addr, gen_rtx_MEM (Pmode, func_desc));
33168 /* Prepare to load the TOC of the called function. Note that the
33169 TOC load must happen immediately before the actual call so
33170 that unwinding the TOC registers works correctly. See the
33171 comment in frob_update_context. */
33172 rtx func_toc_offset = GEN_INT (GET_MODE_SIZE (Pmode));
33173 rtx func_toc_mem = gen_rtx_MEM (Pmode,
33174 gen_rtx_PLUS (Pmode, func_desc,
33175 func_toc_offset));
33176 toc_load = gen_rtx_USE (VOIDmode, func_toc_mem);
33178 /* If we have a static chain, load it up. But, if the call was
33179 originally direct, the 3rd word has not been written since no
33180 trampoline has been built, so we ought not to load it, lest we
33181 override a static chain value. */
33182 if (!direct_call_p
33183 && TARGET_POINTERS_TO_NESTED_FUNCTIONS
33184 && !chain_already_loaded (get_current_sequence ()->next->last))
33186 rtx sc_reg = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
33187 rtx func_sc_offset = GEN_INT (2 * GET_MODE_SIZE (Pmode));
33188 rtx func_sc_mem = gen_rtx_MEM (Pmode,
33189 gen_rtx_PLUS (Pmode, func_desc,
33190 func_sc_offset));
33191 emit_move_insn (sc_reg, func_sc_mem);
33192 abi_reg = sc_reg;
33196 else
33198 /* Direct calls use the TOC: for local calls, the callee will
33199 assume the TOC register is set; for non-local calls, the
33200 PLT stub needs the TOC register. */
33201 abi_reg = toc_reg;
33202 func_addr = func_desc;
33205 /* Create the call. */
33206 call[0] = gen_rtx_CALL (VOIDmode, gen_rtx_MEM (SImode, func_addr), flag);
33207 if (value != NULL_RTX)
33208 call[0] = gen_rtx_SET (value, call[0]);
33209 n_call = 1;
33211 if (toc_load)
33212 call[n_call++] = toc_load;
33213 if (toc_restore)
33214 call[n_call++] = toc_restore;
33216 call[n_call++] = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, LR_REGNO));
33218 insn = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (n_call, call));
33219 insn = emit_call_insn (insn);
33221 /* Mention all registers defined by the ABI to hold information
33222 as uses in CALL_INSN_FUNCTION_USAGE. */
33223 if (abi_reg)
33224 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), abi_reg);
33227 /* Expand code to perform a sibling call under the AIX or ELFv2 ABI. */
33229 void
33230 rs6000_sibcall_aix (rtx value, rtx func_desc, rtx flag, rtx cookie)
33232 rtx call[2];
33233 rtx insn;
33235 gcc_assert (INTVAL (cookie) == 0);
33237 /* Create the call. */
33238 call[0] = gen_rtx_CALL (VOIDmode, gen_rtx_MEM (SImode, func_desc), flag);
33239 if (value != NULL_RTX)
33240 call[0] = gen_rtx_SET (value, call[0]);
33242 call[1] = simple_return_rtx;
33244 insn = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (2, call));
33245 insn = emit_call_insn (insn);
33247 /* Note use of the TOC register. */
33248 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), gen_rtx_REG (Pmode, TOC_REGNUM));
33249 /* We need to also mark a use of the link register since the function we
33250 sibling-call to will use it to return to our caller. */
33251 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), gen_rtx_REG (Pmode, LR_REGNO));
33254 /* Return whether we need to always update the saved TOC pointer when we update
33255 the stack pointer. */
33257 static bool
33258 rs6000_save_toc_in_prologue_p (void)
33260 return (cfun && cfun->machine && cfun->machine->save_toc_in_prologue);
33263 #ifdef HAVE_GAS_HIDDEN
33264 # define USE_HIDDEN_LINKONCE 1
33265 #else
33266 # define USE_HIDDEN_LINKONCE 0
33267 #endif
33269 /* Fills in the label name that should be used for a 476 link stack thunk. */
33271 void
33272 get_ppc476_thunk_name (char name[32])
33274 gcc_assert (TARGET_LINK_STACK);
33276 if (USE_HIDDEN_LINKONCE)
33277 sprintf (name, "__ppc476.get_thunk");
33278 else
33279 ASM_GENERATE_INTERNAL_LABEL (name, "LPPC476_", 0);
33282 /* This function emits the simple thunk routine that is used to preserve
33283 the link stack on the 476 cpu. */
33285 static void rs6000_code_end (void) ATTRIBUTE_UNUSED;
33286 static void
33287 rs6000_code_end (void)
33289 char name[32];
33290 tree decl;
33292 if (!TARGET_LINK_STACK)
33293 return;
33295 get_ppc476_thunk_name (name);
33297 decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, get_identifier (name),
33298 build_function_type_list (void_type_node, NULL_TREE));
33299 DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
33300 NULL_TREE, void_type_node);
33301 TREE_PUBLIC (decl) = 1;
33302 TREE_STATIC (decl) = 1;
33304 #if RS6000_WEAK
33305 if (USE_HIDDEN_LINKONCE)
33307 cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
33308 targetm.asm_out.unique_section (decl, 0);
33309 switch_to_section (get_named_section (decl, NULL, 0));
33310 DECL_WEAK (decl) = 1;
33311 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
33312 targetm.asm_out.globalize_label (asm_out_file, name);
33313 targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN);
33314 ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
33316 else
33317 #endif
33319 switch_to_section (text_section);
33320 ASM_OUTPUT_LABEL (asm_out_file, name);
33323 DECL_INITIAL (decl) = make_node (BLOCK);
33324 current_function_decl = decl;
33325 init_function_start (decl);
33326 first_function_block_is_cold = false;
33327 /* Make sure unwind info is emitted for the thunk if needed. */
33328 final_start_function (emit_barrier (), asm_out_file, 1);
33330 fputs ("\tblr\n", asm_out_file);
33332 final_end_function ();
33333 init_insn_lengths ();
33334 free_after_compilation (cfun);
33335 set_cfun (NULL);
33336 current_function_decl = NULL;
33339 /* Add r30 to hard reg set if the prologue sets it up and it is not
33340 pic_offset_table_rtx. */
33342 static void
33343 rs6000_set_up_by_prologue (struct hard_reg_set_container *set)
33345 if (!TARGET_SINGLE_PIC_BASE
33346 && TARGET_TOC
33347 && TARGET_MINIMAL_TOC
33348 && get_pool_size () != 0)
33349 add_to_hard_reg_set (&set->set, Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
33353 /* Helper function for rs6000_split_logical to emit a logical instruction after
33354 spliting the operation to single GPR registers.
33356 DEST is the destination register.
33357 OP1 and OP2 are the input source registers.
33358 CODE is the base operation (AND, IOR, XOR, NOT).
33359 MODE is the machine mode.
33360 If COMPLEMENT_FINAL_P is true, wrap the whole operation with NOT.
33361 If COMPLEMENT_OP1_P is true, wrap operand1 with NOT.
33362 If COMPLEMENT_OP2_P is true, wrap operand2 with NOT. */
33364 static void
33365 rs6000_split_logical_inner (rtx dest,
33366 rtx op1,
33367 rtx op2,
33368 enum rtx_code code,
33369 machine_mode mode,
33370 bool complement_final_p,
33371 bool complement_op1_p,
33372 bool complement_op2_p)
33374 rtx bool_rtx;
33376 /* Optimize AND of 0/0xffffffff and IOR/XOR of 0. */
33377 if (op2 && GET_CODE (op2) == CONST_INT
33378 && (mode == SImode || (mode == DImode && TARGET_POWERPC64))
33379 && !complement_final_p && !complement_op1_p && !complement_op2_p)
33381 HOST_WIDE_INT mask = GET_MODE_MASK (mode);
33382 HOST_WIDE_INT value = INTVAL (op2) & mask;
33384 /* Optimize AND of 0 to just set 0. Optimize AND of -1 to be a move. */
33385 if (code == AND)
33387 if (value == 0)
33389 emit_insn (gen_rtx_SET (dest, const0_rtx));
33390 return;
33393 else if (value == mask)
33395 if (!rtx_equal_p (dest, op1))
33396 emit_insn (gen_rtx_SET (dest, op1));
33397 return;
33401 /* Optimize IOR/XOR of 0 to be a simple move. Split large operations
33402 into separate ORI/ORIS or XORI/XORIS instrucitons. */
33403 else if (code == IOR || code == XOR)
33405 if (value == 0)
33407 if (!rtx_equal_p (dest, op1))
33408 emit_insn (gen_rtx_SET (dest, op1));
33409 return;
33414 if (code == AND && mode == SImode
33415 && !complement_final_p && !complement_op1_p && !complement_op2_p)
33417 emit_insn (gen_andsi3 (dest, op1, op2));
33418 return;
33421 if (complement_op1_p)
33422 op1 = gen_rtx_NOT (mode, op1);
33424 if (complement_op2_p)
33425 op2 = gen_rtx_NOT (mode, op2);
33427 /* For canonical RTL, if only one arm is inverted it is the first. */
33428 if (!complement_op1_p && complement_op2_p)
33429 std::swap (op1, op2);
33431 bool_rtx = ((code == NOT)
33432 ? gen_rtx_NOT (mode, op1)
33433 : gen_rtx_fmt_ee (code, mode, op1, op2));
33435 if (complement_final_p)
33436 bool_rtx = gen_rtx_NOT (mode, bool_rtx);
33438 emit_insn (gen_rtx_SET (dest, bool_rtx));
33441 /* Split a DImode AND/IOR/XOR with a constant on a 32-bit system. These
33442 operations are split immediately during RTL generation to allow for more
33443 optimizations of the AND/IOR/XOR.
33445 OPERANDS is an array containing the destination and two input operands.
33446 CODE is the base operation (AND, IOR, XOR, NOT).
33447 MODE is the machine mode.
33448 If COMPLEMENT_FINAL_P is true, wrap the whole operation with NOT.
33449 If COMPLEMENT_OP1_P is true, wrap operand1 with NOT.
33450 If COMPLEMENT_OP2_P is true, wrap operand2 with NOT.
33451 CLOBBER_REG is either NULL or a scratch register of type CC to allow
33452 formation of the AND instructions. */
33454 static void
33455 rs6000_split_logical_di (rtx operands[3],
33456 enum rtx_code code,
33457 bool complement_final_p,
33458 bool complement_op1_p,
33459 bool complement_op2_p)
33461 const HOST_WIDE_INT lower_32bits = HOST_WIDE_INT_C(0xffffffff);
33462 const HOST_WIDE_INT upper_32bits = ~ lower_32bits;
33463 const HOST_WIDE_INT sign_bit = HOST_WIDE_INT_C(0x80000000);
33464 enum hi_lo { hi = 0, lo = 1 };
33465 rtx op0_hi_lo[2], op1_hi_lo[2], op2_hi_lo[2];
33466 size_t i;
33468 op0_hi_lo[hi] = gen_highpart (SImode, operands[0]);
33469 op1_hi_lo[hi] = gen_highpart (SImode, operands[1]);
33470 op0_hi_lo[lo] = gen_lowpart (SImode, operands[0]);
33471 op1_hi_lo[lo] = gen_lowpart (SImode, operands[1]);
33473 if (code == NOT)
33474 op2_hi_lo[hi] = op2_hi_lo[lo] = NULL_RTX;
33475 else
33477 if (GET_CODE (operands[2]) != CONST_INT)
33479 op2_hi_lo[hi] = gen_highpart_mode (SImode, DImode, operands[2]);
33480 op2_hi_lo[lo] = gen_lowpart (SImode, operands[2]);
33482 else
33484 HOST_WIDE_INT value = INTVAL (operands[2]);
33485 HOST_WIDE_INT value_hi_lo[2];
33487 gcc_assert (!complement_final_p);
33488 gcc_assert (!complement_op1_p);
33489 gcc_assert (!complement_op2_p);
33491 value_hi_lo[hi] = value >> 32;
33492 value_hi_lo[lo] = value & lower_32bits;
33494 for (i = 0; i < 2; i++)
33496 HOST_WIDE_INT sub_value = value_hi_lo[i];
33498 if (sub_value & sign_bit)
33499 sub_value |= upper_32bits;
33501 op2_hi_lo[i] = GEN_INT (sub_value);
33503 /* If this is an AND instruction, check to see if we need to load
33504 the value in a register. */
33505 if (code == AND && sub_value != -1 && sub_value != 0
33506 && !and_operand (op2_hi_lo[i], SImode))
33507 op2_hi_lo[i] = force_reg (SImode, op2_hi_lo[i]);
33512 for (i = 0; i < 2; i++)
33514 /* Split large IOR/XOR operations. */
33515 if ((code == IOR || code == XOR)
33516 && GET_CODE (op2_hi_lo[i]) == CONST_INT
33517 && !complement_final_p
33518 && !complement_op1_p
33519 && !complement_op2_p
33520 && !logical_const_operand (op2_hi_lo[i], SImode))
33522 HOST_WIDE_INT value = INTVAL (op2_hi_lo[i]);
33523 HOST_WIDE_INT hi_16bits = value & HOST_WIDE_INT_C(0xffff0000);
33524 HOST_WIDE_INT lo_16bits = value & HOST_WIDE_INT_C(0x0000ffff);
33525 rtx tmp = gen_reg_rtx (SImode);
33527 /* Make sure the constant is sign extended. */
33528 if ((hi_16bits & sign_bit) != 0)
33529 hi_16bits |= upper_32bits;
33531 rs6000_split_logical_inner (tmp, op1_hi_lo[i], GEN_INT (hi_16bits),
33532 code, SImode, false, false, false);
33534 rs6000_split_logical_inner (op0_hi_lo[i], tmp, GEN_INT (lo_16bits),
33535 code, SImode, false, false, false);
33537 else
33538 rs6000_split_logical_inner (op0_hi_lo[i], op1_hi_lo[i], op2_hi_lo[i],
33539 code, SImode, complement_final_p,
33540 complement_op1_p, complement_op2_p);
33543 return;
33546 /* Split the insns that make up boolean operations operating on multiple GPR
33547 registers. The boolean MD patterns ensure that the inputs either are
33548 exactly the same as the output registers, or there is no overlap.
33550 OPERANDS is an array containing the destination and two input operands.
33551 CODE is the base operation (AND, IOR, XOR, NOT).
33552 If COMPLEMENT_FINAL_P is true, wrap the whole operation with NOT.
33553 If COMPLEMENT_OP1_P is true, wrap operand1 with NOT.
33554 If COMPLEMENT_OP2_P is true, wrap operand2 with NOT. */
33556 void
33557 rs6000_split_logical (rtx operands[3],
33558 enum rtx_code code,
33559 bool complement_final_p,
33560 bool complement_op1_p,
33561 bool complement_op2_p)
33563 machine_mode mode = GET_MODE (operands[0]);
33564 machine_mode sub_mode;
33565 rtx op0, op1, op2;
33566 int sub_size, regno0, regno1, nregs, i;
33568 /* If this is DImode, use the specialized version that can run before
33569 register allocation. */
33570 if (mode == DImode && !TARGET_POWERPC64)
33572 rs6000_split_logical_di (operands, code, complement_final_p,
33573 complement_op1_p, complement_op2_p);
33574 return;
33577 op0 = operands[0];
33578 op1 = operands[1];
33579 op2 = (code == NOT) ? NULL_RTX : operands[2];
33580 sub_mode = (TARGET_POWERPC64) ? DImode : SImode;
33581 sub_size = GET_MODE_SIZE (sub_mode);
33582 regno0 = REGNO (op0);
33583 regno1 = REGNO (op1);
33585 gcc_assert (reload_completed);
33586 gcc_assert (IN_RANGE (regno0, FIRST_GPR_REGNO, LAST_GPR_REGNO));
33587 gcc_assert (IN_RANGE (regno1, FIRST_GPR_REGNO, LAST_GPR_REGNO));
33589 nregs = rs6000_hard_regno_nregs[(int)mode][regno0];
33590 gcc_assert (nregs > 1);
33592 if (op2 && REG_P (op2))
33593 gcc_assert (IN_RANGE (REGNO (op2), FIRST_GPR_REGNO, LAST_GPR_REGNO));
33595 for (i = 0; i < nregs; i++)
33597 int offset = i * sub_size;
33598 rtx sub_op0 = simplify_subreg (sub_mode, op0, mode, offset);
33599 rtx sub_op1 = simplify_subreg (sub_mode, op1, mode, offset);
33600 rtx sub_op2 = ((code == NOT)
33601 ? NULL_RTX
33602 : simplify_subreg (sub_mode, op2, mode, offset));
33604 rs6000_split_logical_inner (sub_op0, sub_op1, sub_op2, code, sub_mode,
33605 complement_final_p, complement_op1_p,
33606 complement_op2_p);
33609 return;
33613 /* Return true if the peephole2 can combine a load involving a combination of
33614 an addis instruction and a load with an offset that can be fused together on
33615 a power8. */
33617 bool
33618 fusion_gpr_load_p (rtx addis_reg, /* register set via addis. */
33619 rtx addis_value, /* addis value. */
33620 rtx target, /* target register that is loaded. */
33621 rtx mem) /* bottom part of the memory addr. */
33623 rtx addr;
33624 rtx base_reg;
33626 /* Validate arguments. */
33627 if (!base_reg_operand (addis_reg, GET_MODE (addis_reg)))
33628 return false;
33630 if (!base_reg_operand (target, GET_MODE (target)))
33631 return false;
33633 if (!fusion_gpr_addis (addis_value, GET_MODE (addis_value)))
33634 return false;
33636 /* Allow sign/zero extension. */
33637 if (GET_CODE (mem) == ZERO_EXTEND
33638 || (GET_CODE (mem) == SIGN_EXTEND && TARGET_P8_FUSION_SIGN))
33639 mem = XEXP (mem, 0);
33641 if (!MEM_P (mem))
33642 return false;
33644 if (!fusion_gpr_mem_load (mem, GET_MODE (mem)))
33645 return false;
33647 addr = XEXP (mem, 0); /* either PLUS or LO_SUM. */
33648 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
33649 return false;
33651 /* Validate that the register used to load the high value is either the
33652 register being loaded, or we can safely replace its use.
33654 This function is only called from the peephole2 pass and we assume that
33655 there are 2 instructions in the peephole (addis and load), so we want to
33656 check if the target register was not used in the memory address and the
33657 register to hold the addis result is dead after the peephole. */
33658 if (REGNO (addis_reg) != REGNO (target))
33660 if (reg_mentioned_p (target, mem))
33661 return false;
33663 if (!peep2_reg_dead_p (2, addis_reg))
33664 return false;
33666 /* If the target register being loaded is the stack pointer, we must
33667 avoid loading any other value into it, even temporarily. */
33668 if (REG_P (target) && REGNO (target) == STACK_POINTER_REGNUM)
33669 return false;
33672 base_reg = XEXP (addr, 0);
33673 return REGNO (addis_reg) == REGNO (base_reg);
33676 /* During the peephole2 pass, adjust and expand the insns for a load fusion
33677 sequence. We adjust the addis register to use the target register. If the
33678 load sign extends, we adjust the code to do the zero extending load, and an
33679 explicit sign extension later since the fusion only covers zero extending
33680 loads.
33682 The operands are:
33683 operands[0] register set with addis (to be replaced with target)
33684 operands[1] value set via addis
33685 operands[2] target register being loaded
33686 operands[3] D-form memory reference using operands[0]. */
33688 void
33689 expand_fusion_gpr_load (rtx *operands)
33691 rtx addis_value = operands[1];
33692 rtx target = operands[2];
33693 rtx orig_mem = operands[3];
33694 rtx new_addr, new_mem, orig_addr, offset;
33695 enum rtx_code plus_or_lo_sum;
33696 machine_mode target_mode = GET_MODE (target);
33697 machine_mode extend_mode = target_mode;
33698 machine_mode ptr_mode = Pmode;
33699 enum rtx_code extend = UNKNOWN;
33701 if (GET_CODE (orig_mem) == ZERO_EXTEND
33702 || (TARGET_P8_FUSION_SIGN && GET_CODE (orig_mem) == SIGN_EXTEND))
33704 extend = GET_CODE (orig_mem);
33705 orig_mem = XEXP (orig_mem, 0);
33706 target_mode = GET_MODE (orig_mem);
33709 gcc_assert (MEM_P (orig_mem));
33711 orig_addr = XEXP (orig_mem, 0);
33712 plus_or_lo_sum = GET_CODE (orig_addr);
33713 gcc_assert (plus_or_lo_sum == PLUS || plus_or_lo_sum == LO_SUM);
33715 offset = XEXP (orig_addr, 1);
33716 new_addr = gen_rtx_fmt_ee (plus_or_lo_sum, ptr_mode, addis_value, offset);
33717 new_mem = replace_equiv_address_nv (orig_mem, new_addr, false);
33719 if (extend != UNKNOWN)
33720 new_mem = gen_rtx_fmt_e (ZERO_EXTEND, extend_mode, new_mem);
33722 new_mem = gen_rtx_UNSPEC (extend_mode, gen_rtvec (1, new_mem),
33723 UNSPEC_FUSION_GPR);
33724 emit_insn (gen_rtx_SET (target, new_mem));
33726 if (extend == SIGN_EXTEND)
33728 int sub_off = ((BYTES_BIG_ENDIAN)
33729 ? GET_MODE_SIZE (extend_mode) - GET_MODE_SIZE (target_mode)
33730 : 0);
33731 rtx sign_reg
33732 = simplify_subreg (target_mode, target, extend_mode, sub_off);
33734 emit_insn (gen_rtx_SET (target,
33735 gen_rtx_SIGN_EXTEND (extend_mode, sign_reg)));
33738 return;
33741 /* Return a string to fuse an addis instruction with a gpr load to the same
33742 register that we loaded up the addis instruction. The address that is used
33743 is the logical address that was formed during peephole2:
33744 (lo_sum (high) (low-part))
33746 The code is complicated, so we call output_asm_insn directly, and just
33747 return "". */
33749 const char *
33750 emit_fusion_gpr_load (rtx target, rtx mem)
33752 rtx addis_value;
33753 rtx fuse_ops[10];
33754 rtx addr;
33755 rtx load_offset;
33756 const char *addis_str = NULL;
33757 const char *load_str = NULL;
33758 const char *mode_name = NULL;
33759 char insn_template[80];
33760 machine_mode mode;
33761 const char *comment_str = ASM_COMMENT_START;
33763 if (GET_CODE (mem) == ZERO_EXTEND)
33764 mem = XEXP (mem, 0);
33766 gcc_assert (REG_P (target) && MEM_P (mem));
33768 if (*comment_str == ' ')
33769 comment_str++;
33771 addr = XEXP (mem, 0);
33772 if (GET_CODE (addr) != PLUS && GET_CODE (addr) != LO_SUM)
33773 gcc_unreachable ();
33775 addis_value = XEXP (addr, 0);
33776 load_offset = XEXP (addr, 1);
33778 /* Now emit the load instruction to the same register. */
33779 mode = GET_MODE (mem);
33780 switch (mode)
33782 case QImode:
33783 mode_name = "char";
33784 load_str = "lbz";
33785 break;
33787 case HImode:
33788 mode_name = "short";
33789 load_str = "lhz";
33790 break;
33792 case SImode:
33793 mode_name = "int";
33794 load_str = "lwz";
33795 break;
33797 case DImode:
33798 gcc_assert (TARGET_POWERPC64);
33799 mode_name = "long";
33800 load_str = "ld";
33801 break;
33803 default:
33804 gcc_unreachable ();
33807 /* Emit the addis instruction. */
33808 fuse_ops[0] = target;
33809 if (satisfies_constraint_L (addis_value))
33811 fuse_ops[1] = addis_value;
33812 addis_str = "lis %0,%v1";
33815 else if (GET_CODE (addis_value) == PLUS)
33817 rtx op0 = XEXP (addis_value, 0);
33818 rtx op1 = XEXP (addis_value, 1);
33820 if (REG_P (op0) && CONST_INT_P (op1)
33821 && satisfies_constraint_L (op1))
33823 fuse_ops[1] = op0;
33824 fuse_ops[2] = op1;
33825 addis_str = "addis %0,%1,%v2";
33829 else if (GET_CODE (addis_value) == HIGH)
33831 rtx value = XEXP (addis_value, 0);
33832 if (GET_CODE (value) == UNSPEC && XINT (value, 1) == UNSPEC_TOCREL)
33834 fuse_ops[1] = XVECEXP (value, 0, 0); /* symbol ref. */
33835 fuse_ops[2] = XVECEXP (value, 0, 1); /* TOC register. */
33836 if (TARGET_ELF)
33837 addis_str = "addis %0,%2,%1@toc@ha";
33839 else if (TARGET_XCOFF)
33840 addis_str = "addis %0,%1@u(%2)";
33842 else
33843 gcc_unreachable ();
33846 else if (GET_CODE (value) == PLUS)
33848 rtx op0 = XEXP (value, 0);
33849 rtx op1 = XEXP (value, 1);
33851 if (GET_CODE (op0) == UNSPEC
33852 && XINT (op0, 1) == UNSPEC_TOCREL
33853 && CONST_INT_P (op1))
33855 fuse_ops[1] = XVECEXP (op0, 0, 0); /* symbol ref. */
33856 fuse_ops[2] = XVECEXP (op0, 0, 1); /* TOC register. */
33857 fuse_ops[3] = op1;
33858 if (TARGET_ELF)
33859 addis_str = "addis %0,%2,%1+%3@toc@ha";
33861 else if (TARGET_XCOFF)
33862 addis_str = "addis %0,%1+%3@u(%2)";
33864 else
33865 gcc_unreachable ();
33869 else if (satisfies_constraint_L (value))
33871 fuse_ops[1] = value;
33872 addis_str = "lis %0,%v1";
33875 else if (TARGET_ELF && !TARGET_POWERPC64 && CONSTANT_P (value))
33877 fuse_ops[1] = value;
33878 addis_str = "lis %0,%1@ha";
33882 if (!addis_str)
33883 fatal_insn ("Could not generate addis value for fusion", addis_value);
33885 sprintf (insn_template, "%s\t\t%s gpr load fusion, type %s", addis_str,
33886 comment_str, mode_name);
33887 output_asm_insn (insn_template, fuse_ops);
33889 /* Emit the D-form load instruction. */
33890 if (CONST_INT_P (load_offset) && satisfies_constraint_I (load_offset))
33892 sprintf (insn_template, "%s %%0,%%1(%%0)", load_str);
33893 fuse_ops[1] = load_offset;
33894 output_asm_insn (insn_template, fuse_ops);
33897 else if (GET_CODE (load_offset) == UNSPEC
33898 && XINT (load_offset, 1) == UNSPEC_TOCREL)
33900 if (TARGET_ELF)
33901 sprintf (insn_template, "%s %%0,%%1@toc@l(%%0)", load_str);
33903 else if (TARGET_XCOFF)
33904 sprintf (insn_template, "%s %%0,%%1@l(%%0)", load_str);
33906 else
33907 gcc_unreachable ();
33909 fuse_ops[1] = XVECEXP (load_offset, 0, 0);
33910 output_asm_insn (insn_template, fuse_ops);
33913 else if (GET_CODE (load_offset) == PLUS
33914 && GET_CODE (XEXP (load_offset, 0)) == UNSPEC
33915 && XINT (XEXP (load_offset, 0), 1) == UNSPEC_TOCREL
33916 && CONST_INT_P (XEXP (load_offset, 1)))
33918 rtx tocrel_unspec = XEXP (load_offset, 0);
33919 if (TARGET_ELF)
33920 sprintf (insn_template, "%s %%0,%%1+%%2@toc@l(%%0)", load_str);
33922 else if (TARGET_XCOFF)
33923 sprintf (insn_template, "%s %%0,%%1+%%2@l(%%0)", load_str);
33925 else
33926 gcc_unreachable ();
33928 fuse_ops[1] = XVECEXP (tocrel_unspec, 0, 0);
33929 fuse_ops[2] = XEXP (load_offset, 1);
33930 output_asm_insn (insn_template, fuse_ops);
33933 else if (TARGET_ELF && !TARGET_POWERPC64 && CONSTANT_P (load_offset))
33935 sprintf (insn_template, "%s %%0,%%1@l(%%0)", load_str);
33937 fuse_ops[1] = load_offset;
33938 output_asm_insn (insn_template, fuse_ops);
33941 else
33942 fatal_insn ("Unable to generate load offset for fusion", load_offset);
33944 return "";
33947 /* Analyze vector computations and remove unnecessary doubleword
33948 swaps (xxswapdi instructions). This pass is performed only
33949 for little-endian VSX code generation.
33951 For this specific case, loads and stores of 4x32 and 2x64 vectors
33952 are inefficient. These are implemented using the lvx2dx and
33953 stvx2dx instructions, which invert the order of doublewords in
33954 a vector register. Thus the code generation inserts an xxswapdi
33955 after each such load, and prior to each such store. (For spill
33956 code after register assignment, an additional xxswapdi is inserted
33957 following each store in order to return a hard register to its
33958 unpermuted value.)
33960 The extra xxswapdi instructions reduce performance. This can be
33961 particularly bad for vectorized code. The purpose of this pass
33962 is to reduce the number of xxswapdi instructions required for
33963 correctness.
33965 The primary insight is that much code that operates on vectors
33966 does not care about the relative order of elements in a register,
33967 so long as the correct memory order is preserved. If we have
33968 a computation where all input values are provided by lvxd2x/xxswapdi
33969 sequences, all outputs are stored using xxswapdi/stvxd2x sequences,
33970 and all intermediate computations are pure SIMD (independent of
33971 element order), then all the xxswapdi's associated with the loads
33972 and stores may be removed.
33974 This pass uses some of the infrastructure and logical ideas from
33975 the "web" pass in web.c. We create maximal webs of computations
33976 fitting the description above using union-find. Each such web is
33977 then optimized by removing its unnecessary xxswapdi instructions.
33979 The pass is placed prior to global optimization so that we can
33980 perform the optimization in the safest and simplest way possible;
33981 that is, by replacing each xxswapdi insn with a register copy insn.
33982 Subsequent forward propagation will remove copies where possible.
33984 There are some operations sensitive to element order for which we
33985 can still allow the operation, provided we modify those operations.
33986 These include CONST_VECTORs, for which we must swap the first and
33987 second halves of the constant vector; and SUBREGs, for which we
33988 must adjust the byte offset to account for the swapped doublewords.
33989 A remaining opportunity would be non-immediate-form splats, for
33990 which we should adjust the selected lane of the input. We should
33991 also make code generation adjustments for sum-across operations,
33992 since this is a common vectorizer reduction.
33994 Because we run prior to the first split, we can see loads and stores
33995 here that match *vsx_le_perm_{load,store}_<mode>. These are vanilla
33996 vector loads and stores that have not yet been split into a permuting
33997 load/store and a swap. (One way this can happen is with a builtin
33998 call to vec_vsx_{ld,st}.) We can handle these as well, but rather
33999 than deleting a swap, we convert the load/store into a permuting
34000 load/store (which effectively removes the swap). */
34002 /* Notes on Permutes
34004 We do not currently handle computations that contain permutes. There
34005 is a general transformation that can be performed correctly, but it
34006 may introduce more expensive code than it replaces. To handle these
34007 would require a cost model to determine when to perform the optimization.
34008 This commentary records how this could be done if desired.
34010 The most general permute is something like this (example for V16QI):
34012 (vec_select:V16QI (vec_concat:V32QI (op1:V16QI) (op2:V16QI))
34013 (parallel [(const_int a0) (const_int a1)
34015 (const_int a14) (const_int a15)]))
34017 where a0,...,a15 are in [0,31] and select elements from op1 and op2
34018 to produce in the result.
34020 Regardless of mode, we can convert the PARALLEL to a mask of 16
34021 byte-element selectors. Let's call this M, with M[i] representing
34022 the ith byte-element selector value. Then if we swap doublewords
34023 throughout the computation, we can get correct behavior by replacing
34024 M with M' as follows:
34026 { M[i+8]+8 : i < 8, M[i+8] in [0,7] U [16,23]
34027 M'[i] = { M[i+8]-8 : i < 8, M[i+8] in [8,15] U [24,31]
34028 { M[i-8]+8 : i >= 8, M[i-8] in [0,7] U [16,23]
34029 { M[i-8]-8 : i >= 8, M[i-8] in [8,15] U [24,31]
34031 This seems promising at first, since we are just replacing one mask
34032 with another. But certain masks are preferable to others. If M
34033 is a mask that matches a vmrghh pattern, for example, M' certainly
34034 will not. Instead of a single vmrghh, we would generate a load of
34035 M' and a vperm. So we would need to know how many xxswapd's we can
34036 remove as a result of this transformation to determine if it's
34037 profitable; and preferably the logic would need to be aware of all
34038 the special preferable masks.
34040 Another form of permute is an UNSPEC_VPERM, in which the mask is
34041 already in a register. In some cases, this mask may be a constant
34042 that we can discover with ud-chains, in which case the above
34043 transformation is ok. However, the common usage here is for the
34044 mask to be produced by an UNSPEC_LVSL, in which case the mask
34045 cannot be known at compile time. In such a case we would have to
34046 generate several instructions to compute M' as above at run time,
34047 and a cost model is needed again. */
34049 /* This is based on the union-find logic in web.c. web_entry_base is
34050 defined in df.h. */
34051 class swap_web_entry : public web_entry_base
34053 public:
34054 /* Pointer to the insn. */
34055 rtx_insn *insn;
34056 /* Set if insn contains a mention of a vector register. All other
34057 fields are undefined if this field is unset. */
34058 unsigned int is_relevant : 1;
34059 /* Set if insn is a load. */
34060 unsigned int is_load : 1;
34061 /* Set if insn is a store. */
34062 unsigned int is_store : 1;
34063 /* Set if insn is a doubleword swap. This can either be a register swap
34064 or a permuting load or store (test is_load and is_store for this). */
34065 unsigned int is_swap : 1;
34066 /* Set if the insn has a live-in use of a parameter register. */
34067 unsigned int is_live_in : 1;
34068 /* Set if the insn has a live-out def of a return register. */
34069 unsigned int is_live_out : 1;
34070 /* Set if the insn contains a subreg reference of a vector register. */
34071 unsigned int contains_subreg : 1;
34072 /* Set if the insn contains a 128-bit integer operand. */
34073 unsigned int is_128_int : 1;
34074 /* Set if this is a call-insn. */
34075 unsigned int is_call : 1;
34076 /* Set if this insn does not perform a vector operation for which
34077 element order matters, or if we know how to fix it up if it does.
34078 Undefined if is_swap is set. */
34079 unsigned int is_swappable : 1;
34080 /* A nonzero value indicates what kind of special handling for this
34081 insn is required if doublewords are swapped. Undefined if
34082 is_swappable is not set. */
34083 unsigned int special_handling : 3;
34084 /* Set if the web represented by this entry cannot be optimized. */
34085 unsigned int web_not_optimizable : 1;
34086 /* Set if this insn should be deleted. */
34087 unsigned int will_delete : 1;
34090 enum special_handling_values {
34091 SH_NONE = 0,
34092 SH_CONST_VECTOR,
34093 SH_SUBREG,
34094 SH_NOSWAP_LD,
34095 SH_NOSWAP_ST,
34096 SH_EXTRACT,
34097 SH_SPLAT
34100 /* Union INSN with all insns containing definitions that reach USE.
34101 Detect whether USE is live-in to the current function. */
34102 static void
34103 union_defs (swap_web_entry *insn_entry, rtx insn, df_ref use)
34105 struct df_link *link = DF_REF_CHAIN (use);
34107 if (!link)
34108 insn_entry[INSN_UID (insn)].is_live_in = 1;
34110 while (link)
34112 if (DF_REF_IS_ARTIFICIAL (link->ref))
34113 insn_entry[INSN_UID (insn)].is_live_in = 1;
34115 if (DF_REF_INSN_INFO (link->ref))
34117 rtx def_insn = DF_REF_INSN (link->ref);
34118 (void)unionfind_union (insn_entry + INSN_UID (insn),
34119 insn_entry + INSN_UID (def_insn));
34122 link = link->next;
34126 /* Union INSN with all insns containing uses reached from DEF.
34127 Detect whether DEF is live-out from the current function. */
34128 static void
34129 union_uses (swap_web_entry *insn_entry, rtx insn, df_ref def)
34131 struct df_link *link = DF_REF_CHAIN (def);
34133 if (!link)
34134 insn_entry[INSN_UID (insn)].is_live_out = 1;
34136 while (link)
34138 /* This could be an eh use or some other artificial use;
34139 we treat these all the same (killing the optimization). */
34140 if (DF_REF_IS_ARTIFICIAL (link->ref))
34141 insn_entry[INSN_UID (insn)].is_live_out = 1;
34143 if (DF_REF_INSN_INFO (link->ref))
34145 rtx use_insn = DF_REF_INSN (link->ref);
34146 (void)unionfind_union (insn_entry + INSN_UID (insn),
34147 insn_entry + INSN_UID (use_insn));
34150 link = link->next;
34154 /* Return 1 iff INSN is a load insn, including permuting loads that
34155 represent an lvxd2x instruction; else return 0. */
34156 static unsigned int
34157 insn_is_load_p (rtx insn)
34159 rtx body = PATTERN (insn);
34161 if (GET_CODE (body) == SET)
34163 if (GET_CODE (SET_SRC (body)) == MEM)
34164 return 1;
34166 if (GET_CODE (SET_SRC (body)) == VEC_SELECT
34167 && GET_CODE (XEXP (SET_SRC (body), 0)) == MEM)
34168 return 1;
34170 return 0;
34173 if (GET_CODE (body) != PARALLEL)
34174 return 0;
34176 rtx set = XVECEXP (body, 0, 0);
34178 if (GET_CODE (set) == SET && GET_CODE (SET_SRC (set)) == MEM)
34179 return 1;
34181 return 0;
34184 /* Return 1 iff INSN is a store insn, including permuting stores that
34185 represent an stvxd2x instruction; else return 0. */
34186 static unsigned int
34187 insn_is_store_p (rtx insn)
34189 rtx body = PATTERN (insn);
34190 if (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == MEM)
34191 return 1;
34192 if (GET_CODE (body) != PARALLEL)
34193 return 0;
34194 rtx set = XVECEXP (body, 0, 0);
34195 if (GET_CODE (set) == SET && GET_CODE (SET_DEST (set)) == MEM)
34196 return 1;
34197 return 0;
34200 /* Return 1 iff INSN swaps doublewords. This may be a reg-reg swap,
34201 a permuting load, or a permuting store. */
34202 static unsigned int
34203 insn_is_swap_p (rtx insn)
34205 rtx body = PATTERN (insn);
34206 if (GET_CODE (body) != SET)
34207 return 0;
34208 rtx rhs = SET_SRC (body);
34209 if (GET_CODE (rhs) != VEC_SELECT)
34210 return 0;
34211 rtx parallel = XEXP (rhs, 1);
34212 if (GET_CODE (parallel) != PARALLEL)
34213 return 0;
34214 unsigned int len = XVECLEN (parallel, 0);
34215 if (len != 2 && len != 4 && len != 8 && len != 16)
34216 return 0;
34217 for (unsigned int i = 0; i < len / 2; ++i)
34219 rtx op = XVECEXP (parallel, 0, i);
34220 if (GET_CODE (op) != CONST_INT || INTVAL (op) != len / 2 + i)
34221 return 0;
34223 for (unsigned int i = len / 2; i < len; ++i)
34225 rtx op = XVECEXP (parallel, 0, i);
34226 if (GET_CODE (op) != CONST_INT || INTVAL (op) != i - len / 2)
34227 return 0;
34229 return 1;
34232 /* Return 1 iff OP is an operand that will not be affected by having
34233 vector doublewords swapped in memory. */
34234 static unsigned int
34235 rtx_is_swappable_p (rtx op, unsigned int *special)
34237 enum rtx_code code = GET_CODE (op);
34238 int i, j;
34239 rtx parallel;
34241 switch (code)
34243 case LABEL_REF:
34244 case SYMBOL_REF:
34245 case CLOBBER:
34246 case REG:
34247 return 1;
34249 case VEC_CONCAT:
34250 case ASM_INPUT:
34251 case ASM_OPERANDS:
34252 return 0;
34254 case CONST_VECTOR:
34256 *special = SH_CONST_VECTOR;
34257 return 1;
34260 case VEC_DUPLICATE:
34261 /* Opportunity: If XEXP (op, 0) has the same mode as the result,
34262 and XEXP (op, 1) is a PARALLEL with a single QImode const int,
34263 it represents a vector splat for which we can do special
34264 handling. */
34265 if (GET_CODE (XEXP (op, 0)) == CONST_INT)
34266 return 1;
34267 else if (GET_CODE (XEXP (op, 0)) == REG
34268 && GET_MODE_INNER (GET_MODE (op)) == GET_MODE (XEXP (op, 0)))
34269 /* This catches V2DF and V2DI splat, at a minimum. */
34270 return 1;
34271 else if (GET_CODE (XEXP (op, 0)) == VEC_SELECT)
34272 /* If the duplicated item is from a select, defer to the select
34273 processing to see if we can change the lane for the splat. */
34274 return rtx_is_swappable_p (XEXP (op, 0), special);
34275 else
34276 return 0;
34278 case VEC_SELECT:
34279 /* A vec_extract operation is ok if we change the lane. */
34280 if (GET_CODE (XEXP (op, 0)) == REG
34281 && GET_MODE_INNER (GET_MODE (XEXP (op, 0))) == GET_MODE (op)
34282 && GET_CODE ((parallel = XEXP (op, 1))) == PARALLEL
34283 && XVECLEN (parallel, 0) == 1
34284 && GET_CODE (XVECEXP (parallel, 0, 0)) == CONST_INT)
34286 *special = SH_EXTRACT;
34287 return 1;
34289 else
34290 return 0;
34292 case UNSPEC:
34294 /* Various operations are unsafe for this optimization, at least
34295 without significant additional work. Permutes are obviously
34296 problematic, as both the permute control vector and the ordering
34297 of the target values are invalidated by doubleword swapping.
34298 Vector pack and unpack modify the number of vector lanes.
34299 Merge-high/low will not operate correctly on swapped operands.
34300 Vector shifts across element boundaries are clearly uncool,
34301 as are vector select and concatenate operations. Vector
34302 sum-across instructions define one operand with a specific
34303 order-dependent element, so additional fixup code would be
34304 needed to make those work. Vector set and non-immediate-form
34305 vector splat are element-order sensitive. A few of these
34306 cases might be workable with special handling if required.
34307 Adding cost modeling would be appropriate in some cases. */
34308 int val = XINT (op, 1);
34309 switch (val)
34311 default:
34312 break;
34313 case UNSPEC_VMRGH_DIRECT:
34314 case UNSPEC_VMRGL_DIRECT:
34315 case UNSPEC_VPACK_SIGN_SIGN_SAT:
34316 case UNSPEC_VPACK_SIGN_UNS_SAT:
34317 case UNSPEC_VPACK_UNS_UNS_MOD:
34318 case UNSPEC_VPACK_UNS_UNS_MOD_DIRECT:
34319 case UNSPEC_VPACK_UNS_UNS_SAT:
34320 case UNSPEC_VPERM:
34321 case UNSPEC_VPERM_UNS:
34322 case UNSPEC_VPERMHI:
34323 case UNSPEC_VPERMSI:
34324 case UNSPEC_VPKPX:
34325 case UNSPEC_VSLDOI:
34326 case UNSPEC_VSLO:
34327 case UNSPEC_VSRO:
34328 case UNSPEC_VSUM2SWS:
34329 case UNSPEC_VSUM4S:
34330 case UNSPEC_VSUM4UBS:
34331 case UNSPEC_VSUMSWS:
34332 case UNSPEC_VSUMSWS_DIRECT:
34333 case UNSPEC_VSX_CONCAT:
34334 case UNSPEC_VSX_SET:
34335 case UNSPEC_VSX_SLDWI:
34336 case UNSPEC_VUNPACK_HI_SIGN:
34337 case UNSPEC_VUNPACK_HI_SIGN_DIRECT:
34338 case UNSPEC_VUNPACK_LO_SIGN:
34339 case UNSPEC_VUNPACK_LO_SIGN_DIRECT:
34340 case UNSPEC_VUPKHPX:
34341 case UNSPEC_VUPKHS_V4SF:
34342 case UNSPEC_VUPKHU_V4SF:
34343 case UNSPEC_VUPKLPX:
34344 case UNSPEC_VUPKLS_V4SF:
34345 case UNSPEC_VUPKLU_V4SF:
34346 case UNSPEC_VSX_CVDPSPN:
34347 case UNSPEC_VSX_CVSPDP:
34348 case UNSPEC_VSX_CVSPDPN:
34349 return 0;
34350 case UNSPEC_VSPLT_DIRECT:
34351 *special = SH_SPLAT;
34352 return 1;
34356 default:
34357 break;
34360 const char *fmt = GET_RTX_FORMAT (code);
34361 int ok = 1;
34363 for (i = 0; i < GET_RTX_LENGTH (code); ++i)
34364 if (fmt[i] == 'e' || fmt[i] == 'u')
34366 unsigned int special_op = SH_NONE;
34367 ok &= rtx_is_swappable_p (XEXP (op, i), &special_op);
34368 if (special_op == SH_NONE)
34369 continue;
34370 /* Ensure we never have two kinds of special handling
34371 for the same insn. */
34372 if (*special != SH_NONE && *special != special_op)
34373 return 0;
34374 *special = special_op;
34376 else if (fmt[i] == 'E')
34377 for (j = 0; j < XVECLEN (op, i); ++j)
34379 unsigned int special_op = SH_NONE;
34380 ok &= rtx_is_swappable_p (XVECEXP (op, i, j), &special_op);
34381 if (special_op == SH_NONE)
34382 continue;
34383 /* Ensure we never have two kinds of special handling
34384 for the same insn. */
34385 if (*special != SH_NONE && *special != special_op)
34386 return 0;
34387 *special = special_op;
34390 return ok;
34393 /* Return 1 iff INSN is an operand that will not be affected by
34394 having vector doublewords swapped in memory (in which case
34395 *SPECIAL is unchanged), or that can be modified to be correct
34396 if vector doublewords are swapped in memory (in which case
34397 *SPECIAL is changed to a value indicating how). */
34398 static unsigned int
34399 insn_is_swappable_p (swap_web_entry *insn_entry, rtx insn,
34400 unsigned int *special)
34402 /* Calls are always bad. */
34403 if (GET_CODE (insn) == CALL_INSN)
34404 return 0;
34406 /* Loads and stores seen here are not permuting, but we can still
34407 fix them up by converting them to permuting ones. Exceptions:
34408 UNSPEC_LVE, UNSPEC_LVX, and UNSPEC_STVX, which have a PARALLEL
34409 body instead of a SET; and UNSPEC_STVE, which has an UNSPEC
34410 for the SET source. */
34411 rtx body = PATTERN (insn);
34412 int i = INSN_UID (insn);
34414 if (insn_entry[i].is_load)
34416 if (GET_CODE (body) == SET)
34418 *special = SH_NOSWAP_LD;
34419 return 1;
34421 else
34422 return 0;
34425 if (insn_entry[i].is_store)
34427 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) != UNSPEC)
34429 *special = SH_NOSWAP_ST;
34430 return 1;
34432 else
34433 return 0;
34436 /* A convert to single precision can be left as is provided that
34437 all of its uses are in xxspltw instructions that splat BE element
34438 zero. */
34439 if (GET_CODE (body) == SET
34440 && GET_CODE (SET_SRC (body)) == UNSPEC
34441 && XINT (SET_SRC (body), 1) == UNSPEC_VSX_CVDPSPN)
34443 df_ref def;
34444 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
34446 FOR_EACH_INSN_INFO_DEF (def, insn_info)
34448 struct df_link *link = DF_REF_CHAIN (def);
34449 if (!link)
34450 return 0;
34452 for (; link; link = link->next) {
34453 rtx use_insn = DF_REF_INSN (link->ref);
34454 rtx use_body = PATTERN (use_insn);
34455 if (GET_CODE (use_body) != SET
34456 || GET_CODE (SET_SRC (use_body)) != UNSPEC
34457 || XINT (SET_SRC (use_body), 1) != UNSPEC_VSX_XXSPLTW
34458 || XEXP (XEXP (SET_SRC (use_body), 0), 1) != const0_rtx)
34459 return 0;
34463 return 1;
34466 /* Otherwise check the operands for vector lane violations. */
34467 return rtx_is_swappable_p (body, special);
34470 enum chain_purpose { FOR_LOADS, FOR_STORES };
34472 /* Return true if the UD or DU chain headed by LINK is non-empty,
34473 and every entry on the chain references an insn that is a
34474 register swap. Furthermore, if PURPOSE is FOR_LOADS, each such
34475 register swap must have only permuting loads as reaching defs.
34476 If PURPOSE is FOR_STORES, each such register swap must have only
34477 register swaps or permuting stores as reached uses. */
34478 static bool
34479 chain_contains_only_swaps (swap_web_entry *insn_entry, struct df_link *link,
34480 enum chain_purpose purpose)
34482 if (!link)
34483 return false;
34485 for (; link; link = link->next)
34487 if (!VECTOR_MODE_P (GET_MODE (DF_REF_REG (link->ref))))
34488 continue;
34490 if (DF_REF_IS_ARTIFICIAL (link->ref))
34491 return false;
34493 rtx reached_insn = DF_REF_INSN (link->ref);
34494 unsigned uid = INSN_UID (reached_insn);
34495 struct df_insn_info *insn_info = DF_INSN_INFO_GET (reached_insn);
34497 if (!insn_entry[uid].is_swap || insn_entry[uid].is_load
34498 || insn_entry[uid].is_store)
34499 return false;
34501 if (purpose == FOR_LOADS)
34503 df_ref use;
34504 FOR_EACH_INSN_INFO_USE (use, insn_info)
34506 struct df_link *swap_link = DF_REF_CHAIN (use);
34508 while (swap_link)
34510 if (DF_REF_IS_ARTIFICIAL (link->ref))
34511 return false;
34513 rtx swap_def_insn = DF_REF_INSN (swap_link->ref);
34514 unsigned uid2 = INSN_UID (swap_def_insn);
34516 /* Only permuting loads are allowed. */
34517 if (!insn_entry[uid2].is_swap || !insn_entry[uid2].is_load)
34518 return false;
34520 swap_link = swap_link->next;
34524 else if (purpose == FOR_STORES)
34526 df_ref def;
34527 FOR_EACH_INSN_INFO_DEF (def, insn_info)
34529 struct df_link *swap_link = DF_REF_CHAIN (def);
34531 while (swap_link)
34533 if (DF_REF_IS_ARTIFICIAL (link->ref))
34534 return false;
34536 rtx swap_use_insn = DF_REF_INSN (swap_link->ref);
34537 unsigned uid2 = INSN_UID (swap_use_insn);
34539 /* Permuting stores or register swaps are allowed. */
34540 if (!insn_entry[uid2].is_swap || insn_entry[uid2].is_load)
34541 return false;
34543 swap_link = swap_link->next;
34549 return true;
34552 /* Mark the xxswapdi instructions associated with permuting loads and
34553 stores for removal. Note that we only flag them for deletion here,
34554 as there is a possibility of a swap being reached from multiple
34555 loads, etc. */
34556 static void
34557 mark_swaps_for_removal (swap_web_entry *insn_entry, unsigned int i)
34559 rtx insn = insn_entry[i].insn;
34560 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
34562 if (insn_entry[i].is_load)
34564 df_ref def;
34565 FOR_EACH_INSN_INFO_DEF (def, insn_info)
34567 struct df_link *link = DF_REF_CHAIN (def);
34569 /* We know by now that these are swaps, so we can delete
34570 them confidently. */
34571 while (link)
34573 rtx use_insn = DF_REF_INSN (link->ref);
34574 insn_entry[INSN_UID (use_insn)].will_delete = 1;
34575 link = link->next;
34579 else if (insn_entry[i].is_store)
34581 df_ref use;
34582 FOR_EACH_INSN_INFO_USE (use, insn_info)
34584 /* Ignore uses for addressability. */
34585 machine_mode mode = GET_MODE (DF_REF_REG (use));
34586 if (!VECTOR_MODE_P (mode))
34587 continue;
34589 struct df_link *link = DF_REF_CHAIN (use);
34591 /* We know by now that these are swaps, so we can delete
34592 them confidently. */
34593 while (link)
34595 rtx def_insn = DF_REF_INSN (link->ref);
34596 insn_entry[INSN_UID (def_insn)].will_delete = 1;
34597 link = link->next;
34603 /* OP is either a CONST_VECTOR or an expression containing one.
34604 Swap the first half of the vector with the second in the first
34605 case. Recurse to find it in the second. */
34606 static void
34607 swap_const_vector_halves (rtx op)
34609 int i;
34610 enum rtx_code code = GET_CODE (op);
34611 if (GET_CODE (op) == CONST_VECTOR)
34613 int half_units = GET_MODE_NUNITS (GET_MODE (op)) / 2;
34614 for (i = 0; i < half_units; ++i)
34616 rtx temp = CONST_VECTOR_ELT (op, i);
34617 CONST_VECTOR_ELT (op, i) = CONST_VECTOR_ELT (op, i + half_units);
34618 CONST_VECTOR_ELT (op, i + half_units) = temp;
34621 else
34623 int j;
34624 const char *fmt = GET_RTX_FORMAT (code);
34625 for (i = 0; i < GET_RTX_LENGTH (code); ++i)
34626 if (fmt[i] == 'e' || fmt[i] == 'u')
34627 swap_const_vector_halves (XEXP (op, i));
34628 else if (fmt[i] == 'E')
34629 for (j = 0; j < XVECLEN (op, i); ++j)
34630 swap_const_vector_halves (XVECEXP (op, i, j));
34634 /* Find all subregs of a vector expression that perform a narrowing,
34635 and adjust the subreg index to account for doubleword swapping. */
34636 static void
34637 adjust_subreg_index (rtx op)
34639 enum rtx_code code = GET_CODE (op);
34640 if (code == SUBREG
34641 && (GET_MODE_SIZE (GET_MODE (op))
34642 < GET_MODE_SIZE (GET_MODE (XEXP (op, 0)))))
34644 unsigned int index = SUBREG_BYTE (op);
34645 if (index < 8)
34646 index += 8;
34647 else
34648 index -= 8;
34649 SUBREG_BYTE (op) = index;
34652 const char *fmt = GET_RTX_FORMAT (code);
34653 int i,j;
34654 for (i = 0; i < GET_RTX_LENGTH (code); ++i)
34655 if (fmt[i] == 'e' || fmt[i] == 'u')
34656 adjust_subreg_index (XEXP (op, i));
34657 else if (fmt[i] == 'E')
34658 for (j = 0; j < XVECLEN (op, i); ++j)
34659 adjust_subreg_index (XVECEXP (op, i, j));
34662 /* Convert the non-permuting load INSN to a permuting one. */
34663 static void
34664 permute_load (rtx_insn *insn)
34666 rtx body = PATTERN (insn);
34667 rtx mem_op = SET_SRC (body);
34668 rtx tgt_reg = SET_DEST (body);
34669 machine_mode mode = GET_MODE (tgt_reg);
34670 int n_elts = GET_MODE_NUNITS (mode);
34671 int half_elts = n_elts / 2;
34672 rtx par = gen_rtx_PARALLEL (mode, rtvec_alloc (n_elts));
34673 int i, j;
34674 for (i = 0, j = half_elts; i < half_elts; ++i, ++j)
34675 XVECEXP (par, 0, i) = GEN_INT (j);
34676 for (i = half_elts, j = 0; j < half_elts; ++i, ++j)
34677 XVECEXP (par, 0, i) = GEN_INT (j);
34678 rtx sel = gen_rtx_VEC_SELECT (mode, mem_op, par);
34679 SET_SRC (body) = sel;
34680 INSN_CODE (insn) = -1; /* Force re-recognition. */
34681 df_insn_rescan (insn);
34683 if (dump_file)
34684 fprintf (dump_file, "Replacing load %d with permuted load\n",
34685 INSN_UID (insn));
34688 /* Convert the non-permuting store INSN to a permuting one. */
34689 static void
34690 permute_store (rtx_insn *insn)
34692 rtx body = PATTERN (insn);
34693 rtx src_reg = SET_SRC (body);
34694 machine_mode mode = GET_MODE (src_reg);
34695 int n_elts = GET_MODE_NUNITS (mode);
34696 int half_elts = n_elts / 2;
34697 rtx par = gen_rtx_PARALLEL (mode, rtvec_alloc (n_elts));
34698 int i, j;
34699 for (i = 0, j = half_elts; i < half_elts; ++i, ++j)
34700 XVECEXP (par, 0, i) = GEN_INT (j);
34701 for (i = half_elts, j = 0; j < half_elts; ++i, ++j)
34702 XVECEXP (par, 0, i) = GEN_INT (j);
34703 rtx sel = gen_rtx_VEC_SELECT (mode, src_reg, par);
34704 SET_SRC (body) = sel;
34705 INSN_CODE (insn) = -1; /* Force re-recognition. */
34706 df_insn_rescan (insn);
34708 if (dump_file)
34709 fprintf (dump_file, "Replacing store %d with permuted store\n",
34710 INSN_UID (insn));
34713 /* Given OP that contains a vector extract operation, adjust the index
34714 of the extracted lane to account for the doubleword swap. */
34715 static void
34716 adjust_extract (rtx_insn *insn)
34718 rtx pattern = PATTERN (insn);
34719 if (GET_CODE (pattern) == PARALLEL)
34720 pattern = XVECEXP (pattern, 0, 0);
34721 rtx src = SET_SRC (pattern);
34722 /* The vec_select may be wrapped in a vec_duplicate for a splat, so
34723 account for that. */
34724 rtx sel = GET_CODE (src) == VEC_DUPLICATE ? XEXP (src, 0) : src;
34725 rtx par = XEXP (sel, 1);
34726 int half_elts = GET_MODE_NUNITS (GET_MODE (XEXP (sel, 0))) >> 1;
34727 int lane = INTVAL (XVECEXP (par, 0, 0));
34728 lane = lane >= half_elts ? lane - half_elts : lane + half_elts;
34729 XVECEXP (par, 0, 0) = GEN_INT (lane);
34730 INSN_CODE (insn) = -1; /* Force re-recognition. */
34731 df_insn_rescan (insn);
34733 if (dump_file)
34734 fprintf (dump_file, "Changing lane for extract %d\n", INSN_UID (insn));
34737 /* Given OP that contains a vector direct-splat operation, adjust the index
34738 of the source lane to account for the doubleword swap. */
34739 static void
34740 adjust_splat (rtx_insn *insn)
34742 rtx body = PATTERN (insn);
34743 rtx unspec = XEXP (body, 1);
34744 int half_elts = GET_MODE_NUNITS (GET_MODE (unspec)) >> 1;
34745 int lane = INTVAL (XVECEXP (unspec, 0, 1));
34746 lane = lane >= half_elts ? lane - half_elts : lane + half_elts;
34747 XVECEXP (unspec, 0, 1) = GEN_INT (lane);
34748 INSN_CODE (insn) = -1; /* Force re-recognition. */
34749 df_insn_rescan (insn);
34751 if (dump_file)
34752 fprintf (dump_file, "Changing lane for splat %d\n", INSN_UID (insn));
34755 /* The insn described by INSN_ENTRY[I] can be swapped, but only
34756 with special handling. Take care of that here. */
34757 static void
34758 handle_special_swappables (swap_web_entry *insn_entry, unsigned i)
34760 rtx_insn *insn = insn_entry[i].insn;
34761 rtx body = PATTERN (insn);
34763 switch (insn_entry[i].special_handling)
34765 default:
34766 gcc_unreachable ();
34767 case SH_CONST_VECTOR:
34769 /* A CONST_VECTOR will only show up somewhere in the RHS of a SET. */
34770 gcc_assert (GET_CODE (body) == SET);
34771 rtx rhs = SET_SRC (body);
34772 swap_const_vector_halves (rhs);
34773 if (dump_file)
34774 fprintf (dump_file, "Swapping constant halves in insn %d\n", i);
34775 break;
34777 case SH_SUBREG:
34778 /* A subreg of the same size is already safe. For subregs that
34779 select a smaller portion of a reg, adjust the index for
34780 swapped doublewords. */
34781 adjust_subreg_index (body);
34782 if (dump_file)
34783 fprintf (dump_file, "Adjusting subreg in insn %d\n", i);
34784 break;
34785 case SH_NOSWAP_LD:
34786 /* Convert a non-permuting load to a permuting one. */
34787 permute_load (insn);
34788 break;
34789 case SH_NOSWAP_ST:
34790 /* Convert a non-permuting store to a permuting one. */
34791 permute_store (insn);
34792 break;
34793 case SH_EXTRACT:
34794 /* Change the lane on an extract operation. */
34795 adjust_extract (insn);
34796 break;
34797 case SH_SPLAT:
34798 /* Change the lane on a direct-splat operation. */
34799 adjust_splat (insn);
34800 break;
34804 /* Find the insn from the Ith table entry, which is known to be a
34805 register swap Y = SWAP(X). Replace it with a copy Y = X. */
34806 static void
34807 replace_swap_with_copy (swap_web_entry *insn_entry, unsigned i)
34809 rtx_insn *insn = insn_entry[i].insn;
34810 rtx body = PATTERN (insn);
34811 rtx src_reg = XEXP (SET_SRC (body), 0);
34812 rtx copy = gen_rtx_SET (SET_DEST (body), src_reg);
34813 rtx_insn *new_insn = emit_insn_before (copy, insn);
34814 set_block_for_insn (new_insn, BLOCK_FOR_INSN (insn));
34815 df_insn_rescan (new_insn);
34817 if (dump_file)
34819 unsigned int new_uid = INSN_UID (new_insn);
34820 fprintf (dump_file, "Replacing swap %d with copy %d\n", i, new_uid);
34823 df_insn_delete (insn);
34824 remove_insn (insn);
34825 insn->set_deleted ();
34828 /* Dump the swap table to DUMP_FILE. */
34829 static void
34830 dump_swap_insn_table (swap_web_entry *insn_entry)
34832 int e = get_max_uid ();
34833 fprintf (dump_file, "\nRelevant insns with their flag settings\n\n");
34835 for (int i = 0; i < e; ++i)
34836 if (insn_entry[i].is_relevant)
34838 swap_web_entry *pred_entry = (swap_web_entry *)insn_entry[i].pred ();
34839 fprintf (dump_file, "%6d %6d ", i,
34840 pred_entry && pred_entry->insn
34841 ? INSN_UID (pred_entry->insn) : 0);
34842 if (insn_entry[i].is_load)
34843 fputs ("load ", dump_file);
34844 if (insn_entry[i].is_store)
34845 fputs ("store ", dump_file);
34846 if (insn_entry[i].is_swap)
34847 fputs ("swap ", dump_file);
34848 if (insn_entry[i].is_live_in)
34849 fputs ("live-in ", dump_file);
34850 if (insn_entry[i].is_live_out)
34851 fputs ("live-out ", dump_file);
34852 if (insn_entry[i].contains_subreg)
34853 fputs ("subreg ", dump_file);
34854 if (insn_entry[i].is_128_int)
34855 fputs ("int128 ", dump_file);
34856 if (insn_entry[i].is_call)
34857 fputs ("call ", dump_file);
34858 if (insn_entry[i].is_swappable)
34860 fputs ("swappable ", dump_file);
34861 if (insn_entry[i].special_handling == SH_CONST_VECTOR)
34862 fputs ("special:constvec ", dump_file);
34863 else if (insn_entry[i].special_handling == SH_SUBREG)
34864 fputs ("special:subreg ", dump_file);
34865 else if (insn_entry[i].special_handling == SH_NOSWAP_LD)
34866 fputs ("special:load ", dump_file);
34867 else if (insn_entry[i].special_handling == SH_NOSWAP_ST)
34868 fputs ("special:store ", dump_file);
34869 else if (insn_entry[i].special_handling == SH_EXTRACT)
34870 fputs ("special:extract ", dump_file);
34871 else if (insn_entry[i].special_handling == SH_SPLAT)
34872 fputs ("special:splat ", dump_file);
34874 if (insn_entry[i].web_not_optimizable)
34875 fputs ("unoptimizable ", dump_file);
34876 if (insn_entry[i].will_delete)
34877 fputs ("delete ", dump_file);
34878 fputs ("\n", dump_file);
34880 fputs ("\n", dump_file);
34883 /* Main entry point for this pass. */
34884 unsigned int
34885 rs6000_analyze_swaps (function *fun)
34887 swap_web_entry *insn_entry;
34888 basic_block bb;
34889 rtx_insn *insn;
34891 /* Dataflow analysis for use-def chains. */
34892 df_set_flags (DF_RD_PRUNE_DEAD_DEFS);
34893 df_chain_add_problem (DF_DU_CHAIN | DF_UD_CHAIN);
34894 df_analyze ();
34895 df_set_flags (DF_DEFER_INSN_RESCAN);
34897 /* Allocate structure to represent webs of insns. */
34898 insn_entry = XCNEWVEC (swap_web_entry, get_max_uid ());
34900 /* Walk the insns to gather basic data. */
34901 FOR_ALL_BB_FN (bb, fun)
34902 FOR_BB_INSNS (bb, insn)
34904 unsigned int uid = INSN_UID (insn);
34905 if (NONDEBUG_INSN_P (insn))
34907 insn_entry[uid].insn = insn;
34909 if (GET_CODE (insn) == CALL_INSN)
34910 insn_entry[uid].is_call = 1;
34912 /* Walk the uses and defs to see if we mention vector regs.
34913 Record any constraints on optimization of such mentions. */
34914 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
34915 df_ref mention;
34916 FOR_EACH_INSN_INFO_USE (mention, insn_info)
34918 /* We use DF_REF_REAL_REG here to get inside any subregs. */
34919 machine_mode mode = GET_MODE (DF_REF_REAL_REG (mention));
34921 /* If a use gets its value from a call insn, it will be
34922 a hard register and will look like (reg:V4SI 3 3).
34923 The df analysis creates two mentions for GPR3 and GPR4,
34924 both DImode. We must recognize this and treat it as a
34925 vector mention to ensure the call is unioned with this
34926 use. */
34927 if (mode == DImode && DF_REF_INSN_INFO (mention))
34929 rtx feeder = DF_REF_INSN (mention);
34930 /* FIXME: It is pretty hard to get from the df mention
34931 to the mode of the use in the insn. We arbitrarily
34932 pick a vector mode here, even though the use might
34933 be a real DImode. We can be too conservative
34934 (create a web larger than necessary) because of
34935 this, so consider eventually fixing this. */
34936 if (GET_CODE (feeder) == CALL_INSN)
34937 mode = V4SImode;
34940 if (VECTOR_MODE_P (mode) || mode == TImode)
34942 insn_entry[uid].is_relevant = 1;
34943 if (mode == TImode || mode == V1TImode)
34944 insn_entry[uid].is_128_int = 1;
34945 if (DF_REF_INSN_INFO (mention))
34946 insn_entry[uid].contains_subreg
34947 = !rtx_equal_p (DF_REF_REG (mention),
34948 DF_REF_REAL_REG (mention));
34949 union_defs (insn_entry, insn, mention);
34952 FOR_EACH_INSN_INFO_DEF (mention, insn_info)
34954 /* We use DF_REF_REAL_REG here to get inside any subregs. */
34955 machine_mode mode = GET_MODE (DF_REF_REAL_REG (mention));
34957 /* If we're loading up a hard vector register for a call,
34958 it looks like (set (reg:V4SI 9 9) (...)). The df
34959 analysis creates two mentions for GPR9 and GPR10, both
34960 DImode. So relying on the mode from the mentions
34961 isn't sufficient to ensure we union the call into the
34962 web with the parameter setup code. */
34963 if (mode == DImode && GET_CODE (insn) == SET
34964 && VECTOR_MODE_P (GET_MODE (SET_DEST (insn))))
34965 mode = GET_MODE (SET_DEST (insn));
34967 if (VECTOR_MODE_P (mode) || mode == TImode)
34969 insn_entry[uid].is_relevant = 1;
34970 if (mode == TImode || mode == V1TImode)
34971 insn_entry[uid].is_128_int = 1;
34972 if (DF_REF_INSN_INFO (mention))
34973 insn_entry[uid].contains_subreg
34974 = !rtx_equal_p (DF_REF_REG (mention),
34975 DF_REF_REAL_REG (mention));
34976 /* REG_FUNCTION_VALUE_P is not valid for subregs. */
34977 else if (REG_FUNCTION_VALUE_P (DF_REF_REG (mention)))
34978 insn_entry[uid].is_live_out = 1;
34979 union_uses (insn_entry, insn, mention);
34983 if (insn_entry[uid].is_relevant)
34985 /* Determine if this is a load or store. */
34986 insn_entry[uid].is_load = insn_is_load_p (insn);
34987 insn_entry[uid].is_store = insn_is_store_p (insn);
34989 /* Determine if this is a doubleword swap. If not,
34990 determine whether it can legally be swapped. */
34991 if (insn_is_swap_p (insn))
34992 insn_entry[uid].is_swap = 1;
34993 else
34995 unsigned int special = SH_NONE;
34996 insn_entry[uid].is_swappable
34997 = insn_is_swappable_p (insn_entry, insn, &special);
34998 if (special != SH_NONE && insn_entry[uid].contains_subreg)
34999 insn_entry[uid].is_swappable = 0;
35000 else if (special != SH_NONE)
35001 insn_entry[uid].special_handling = special;
35002 else if (insn_entry[uid].contains_subreg)
35003 insn_entry[uid].special_handling = SH_SUBREG;
35009 if (dump_file)
35011 fprintf (dump_file, "\nSwap insn entry table when first built\n");
35012 dump_swap_insn_table (insn_entry);
35015 /* Record unoptimizable webs. */
35016 unsigned e = get_max_uid (), i;
35017 for (i = 0; i < e; ++i)
35019 if (!insn_entry[i].is_relevant)
35020 continue;
35022 swap_web_entry *root
35023 = (swap_web_entry*)(&insn_entry[i])->unionfind_root ();
35025 if (insn_entry[i].is_live_in || insn_entry[i].is_live_out
35026 || (insn_entry[i].contains_subreg
35027 && insn_entry[i].special_handling != SH_SUBREG)
35028 || insn_entry[i].is_128_int || insn_entry[i].is_call
35029 || !(insn_entry[i].is_swappable || insn_entry[i].is_swap))
35030 root->web_not_optimizable = 1;
35032 /* If we have loads or stores that aren't permuting then the
35033 optimization isn't appropriate. */
35034 else if ((insn_entry[i].is_load || insn_entry[i].is_store)
35035 && !insn_entry[i].is_swap && !insn_entry[i].is_swappable)
35036 root->web_not_optimizable = 1;
35038 /* If we have permuting loads or stores that are not accompanied
35039 by a register swap, the optimization isn't appropriate. */
35040 else if (insn_entry[i].is_load && insn_entry[i].is_swap)
35042 rtx insn = insn_entry[i].insn;
35043 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
35044 df_ref def;
35046 FOR_EACH_INSN_INFO_DEF (def, insn_info)
35048 struct df_link *link = DF_REF_CHAIN (def);
35050 if (!chain_contains_only_swaps (insn_entry, link, FOR_LOADS))
35052 root->web_not_optimizable = 1;
35053 break;
35057 else if (insn_entry[i].is_store && insn_entry[i].is_swap)
35059 rtx insn = insn_entry[i].insn;
35060 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
35061 df_ref use;
35063 FOR_EACH_INSN_INFO_USE (use, insn_info)
35065 struct df_link *link = DF_REF_CHAIN (use);
35067 if (!chain_contains_only_swaps (insn_entry, link, FOR_STORES))
35069 root->web_not_optimizable = 1;
35070 break;
35076 if (dump_file)
35078 fprintf (dump_file, "\nSwap insn entry table after web analysis\n");
35079 dump_swap_insn_table (insn_entry);
35082 /* For each load and store in an optimizable web (which implies
35083 the loads and stores are permuting), find the associated
35084 register swaps and mark them for removal. Due to various
35085 optimizations we may mark the same swap more than once. Also
35086 perform special handling for swappable insns that require it. */
35087 for (i = 0; i < e; ++i)
35088 if ((insn_entry[i].is_load || insn_entry[i].is_store)
35089 && insn_entry[i].is_swap)
35091 swap_web_entry* root_entry
35092 = (swap_web_entry*)((&insn_entry[i])->unionfind_root ());
35093 if (!root_entry->web_not_optimizable)
35094 mark_swaps_for_removal (insn_entry, i);
35096 else if (insn_entry[i].is_swappable && insn_entry[i].special_handling)
35098 swap_web_entry* root_entry
35099 = (swap_web_entry*)((&insn_entry[i])->unionfind_root ());
35100 if (!root_entry->web_not_optimizable)
35101 handle_special_swappables (insn_entry, i);
35104 /* Now delete the swaps marked for removal. */
35105 for (i = 0; i < e; ++i)
35106 if (insn_entry[i].will_delete)
35107 replace_swap_with_copy (insn_entry, i);
35109 /* Clean up. */
35110 free (insn_entry);
35111 return 0;
35114 const pass_data pass_data_analyze_swaps =
35116 RTL_PASS, /* type */
35117 "swaps", /* name */
35118 OPTGROUP_NONE, /* optinfo_flags */
35119 TV_NONE, /* tv_id */
35120 0, /* properties_required */
35121 0, /* properties_provided */
35122 0, /* properties_destroyed */
35123 0, /* todo_flags_start */
35124 TODO_df_finish, /* todo_flags_finish */
35127 class pass_analyze_swaps : public rtl_opt_pass
35129 public:
35130 pass_analyze_swaps(gcc::context *ctxt)
35131 : rtl_opt_pass(pass_data_analyze_swaps, ctxt)
35134 /* opt_pass methods: */
35135 virtual bool gate (function *)
35137 return (optimize > 0 && !BYTES_BIG_ENDIAN && TARGET_VSX
35138 && rs6000_optimize_swaps);
35141 virtual unsigned int execute (function *fun)
35143 return rs6000_analyze_swaps (fun);
35146 }; // class pass_analyze_swaps
35148 rtl_opt_pass *
35149 make_pass_analyze_swaps (gcc::context *ctxt)
35151 return new pass_analyze_swaps (ctxt);
35154 #ifdef RS6000_GLIBC_ATOMIC_FENV
35155 /* Function declarations for rs6000_atomic_assign_expand_fenv. */
35156 static tree atomic_hold_decl, atomic_clear_decl, atomic_update_decl;
35157 #endif
35159 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV hook. */
35161 static void
35162 rs6000_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
35164 if (!TARGET_HARD_FLOAT || !TARGET_FPRS)
35166 #ifdef RS6000_GLIBC_ATOMIC_FENV
35167 if (atomic_hold_decl == NULL_TREE)
35169 atomic_hold_decl
35170 = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
35171 get_identifier ("__atomic_feholdexcept"),
35172 build_function_type_list (void_type_node,
35173 double_ptr_type_node,
35174 NULL_TREE));
35175 TREE_PUBLIC (atomic_hold_decl) = 1;
35176 DECL_EXTERNAL (atomic_hold_decl) = 1;
35179 if (atomic_clear_decl == NULL_TREE)
35181 atomic_clear_decl
35182 = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
35183 get_identifier ("__atomic_feclearexcept"),
35184 build_function_type_list (void_type_node,
35185 NULL_TREE));
35186 TREE_PUBLIC (atomic_clear_decl) = 1;
35187 DECL_EXTERNAL (atomic_clear_decl) = 1;
35190 tree const_double = build_qualified_type (double_type_node,
35191 TYPE_QUAL_CONST);
35192 tree const_double_ptr = build_pointer_type (const_double);
35193 if (atomic_update_decl == NULL_TREE)
35195 atomic_update_decl
35196 = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
35197 get_identifier ("__atomic_feupdateenv"),
35198 build_function_type_list (void_type_node,
35199 const_double_ptr,
35200 NULL_TREE));
35201 TREE_PUBLIC (atomic_update_decl) = 1;
35202 DECL_EXTERNAL (atomic_update_decl) = 1;
35205 tree fenv_var = create_tmp_var (double_type_node);
35206 mark_addressable (fenv_var);
35207 tree fenv_addr = build1 (ADDR_EXPR, double_ptr_type_node, fenv_var);
35209 *hold = build_call_expr (atomic_hold_decl, 1, fenv_addr);
35210 *clear = build_call_expr (atomic_clear_decl, 0);
35211 *update = build_call_expr (atomic_update_decl, 1,
35212 fold_convert (const_double_ptr, fenv_addr));
35213 #endif
35214 return;
35217 tree mffs = rs6000_builtin_decls[RS6000_BUILTIN_MFFS];
35218 tree mtfsf = rs6000_builtin_decls[RS6000_BUILTIN_MTFSF];
35219 tree call_mffs = build_call_expr (mffs, 0);
35221 /* Generates the equivalent of feholdexcept (&fenv_var)
35223 *fenv_var = __builtin_mffs ();
35224 double fenv_hold;
35225 *(uint64_t*)&fenv_hold = *(uint64_t*)fenv_var & 0xffffffff00000007LL;
35226 __builtin_mtfsf (0xff, fenv_hold); */
35228 /* Mask to clear everything except for the rounding modes and non-IEEE
35229 arithmetic flag. */
35230 const unsigned HOST_WIDE_INT hold_exception_mask =
35231 HOST_WIDE_INT_C (0xffffffff00000007);
35233 tree fenv_var = create_tmp_var (double_type_node);
35235 tree hold_mffs = build2 (MODIFY_EXPR, void_type_node, fenv_var, call_mffs);
35237 tree fenv_llu = build1 (VIEW_CONVERT_EXPR, uint64_type_node, fenv_var);
35238 tree fenv_llu_and = build2 (BIT_AND_EXPR, uint64_type_node, fenv_llu,
35239 build_int_cst (uint64_type_node,
35240 hold_exception_mask));
35242 tree fenv_hold_mtfsf = build1 (VIEW_CONVERT_EXPR, double_type_node,
35243 fenv_llu_and);
35245 tree hold_mtfsf = build_call_expr (mtfsf, 2,
35246 build_int_cst (unsigned_type_node, 0xff),
35247 fenv_hold_mtfsf);
35249 *hold = build2 (COMPOUND_EXPR, void_type_node, hold_mffs, hold_mtfsf);
35251 /* Generates the equivalent of feclearexcept (FE_ALL_EXCEPT):
35253 double fenv_clear = __builtin_mffs ();
35254 *(uint64_t)&fenv_clear &= 0xffffffff00000000LL;
35255 __builtin_mtfsf (0xff, fenv_clear); */
35257 /* Mask to clear everything except for the rounding modes and non-IEEE
35258 arithmetic flag. */
35259 const unsigned HOST_WIDE_INT clear_exception_mask =
35260 HOST_WIDE_INT_C (0xffffffff00000000);
35262 tree fenv_clear = create_tmp_var (double_type_node);
35264 tree clear_mffs = build2 (MODIFY_EXPR, void_type_node, fenv_clear, call_mffs);
35266 tree fenv_clean_llu = build1 (VIEW_CONVERT_EXPR, uint64_type_node, fenv_clear);
35267 tree fenv_clear_llu_and = build2 (BIT_AND_EXPR, uint64_type_node,
35268 fenv_clean_llu,
35269 build_int_cst (uint64_type_node,
35270 clear_exception_mask));
35272 tree fenv_clear_mtfsf = build1 (VIEW_CONVERT_EXPR, double_type_node,
35273 fenv_clear_llu_and);
35275 tree clear_mtfsf = build_call_expr (mtfsf, 2,
35276 build_int_cst (unsigned_type_node, 0xff),
35277 fenv_clear_mtfsf);
35279 *clear = build2 (COMPOUND_EXPR, void_type_node, clear_mffs, clear_mtfsf);
35281 /* Generates the equivalent of feupdateenv (&fenv_var)
35283 double old_fenv = __builtin_mffs ();
35284 double fenv_update;
35285 *(uint64_t*)&fenv_update = (*(uint64_t*)&old & 0xffffffff1fffff00LL) |
35286 (*(uint64_t*)fenv_var 0x1ff80fff);
35287 __builtin_mtfsf (0xff, fenv_update); */
35289 const unsigned HOST_WIDE_INT update_exception_mask =
35290 HOST_WIDE_INT_C (0xffffffff1fffff00);
35291 const unsigned HOST_WIDE_INT new_exception_mask =
35292 HOST_WIDE_INT_C (0x1ff80fff);
35294 tree old_fenv = create_tmp_var (double_type_node);
35295 tree update_mffs = build2 (MODIFY_EXPR, void_type_node, old_fenv, call_mffs);
35297 tree old_llu = build1 (VIEW_CONVERT_EXPR, uint64_type_node, old_fenv);
35298 tree old_llu_and = build2 (BIT_AND_EXPR, uint64_type_node, old_llu,
35299 build_int_cst (uint64_type_node,
35300 update_exception_mask));
35302 tree new_llu_and = build2 (BIT_AND_EXPR, uint64_type_node, fenv_llu,
35303 build_int_cst (uint64_type_node,
35304 new_exception_mask));
35306 tree new_llu_mask = build2 (BIT_IOR_EXPR, uint64_type_node,
35307 old_llu_and, new_llu_and);
35309 tree fenv_update_mtfsf = build1 (VIEW_CONVERT_EXPR, double_type_node,
35310 new_llu_mask);
35312 tree update_mtfsf = build_call_expr (mtfsf, 2,
35313 build_int_cst (unsigned_type_node, 0xff),
35314 fenv_update_mtfsf);
35316 *update = build2 (COMPOUND_EXPR, void_type_node, update_mffs, update_mtfsf);
35320 struct gcc_target targetm = TARGET_INITIALIZER;
35322 #include "gt-rs6000.h"