]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
s390-protos.h (s390_narrow_logical_operator): Add.
[thirdparty/gcc.git] / gcc / config / rs6000 / rs6000.c
CommitLineData
9878760c 1/* Subroutines used for code generation on IBM RS/6000.
f676971a 2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
93c9d1ba 3 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
fab3bcc3 4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
9878760c 5
5de601cf 6 This file is part of GCC.
9878760c 7
5de601cf
NC
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2, or (at your
11 option) any later version.
9878760c 12
5de601cf
NC
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
9878760c 17
5de601cf
NC
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the
20 Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
9878760c 22
956d6950 23#include "config.h"
c4d38ccb 24#include "system.h"
4977bab6
ZW
25#include "coretypes.h"
26#include "tm.h"
9878760c
RK
27#include "rtl.h"
28#include "regs.h"
29#include "hard-reg-set.h"
30#include "real.h"
31#include "insn-config.h"
32#include "conditions.h"
9878760c
RK
33#include "insn-attr.h"
34#include "flags.h"
35#include "recog.h"
9878760c 36#include "obstack.h"
9b30bae2 37#include "tree.h"
dfafc897 38#include "expr.h"
2fc1c679 39#include "optabs.h"
2a430ec1 40#include "except.h"
a7df97e6 41#include "function.h"
296b8152 42#include "output.h"
d5fa86ba 43#include "basic-block.h"
d0101753 44#include "integrate.h"
296b8152 45#include "toplev.h"
c8023011 46#include "ggc.h"
9ebbca7d
GK
47#include "hashtab.h"
48#include "tm_p.h"
672a6f42
NB
49#include "target.h"
50#include "target-def.h"
3ac88239 51#include "langhooks.h"
24ea750e 52#include "reload.h"
117dca74 53#include "cfglayout.h"
79ae11c4 54#include "sched-int.h"
cd3ce9b4 55#include "tree-gimple.h"
1bc7c5b6
ZW
56#if TARGET_XCOFF
57#include "xcoffout.h" /* get declarations of xcoff_*_section_name */
58#endif
9b30bae2 59
7509c759
MM
60#ifndef TARGET_NO_PROTOTYPE
61#define TARGET_NO_PROTOTYPE 0
62#endif
63
452a7d36 64#define EASY_VECTOR_15(n) ((n) >= -16 && (n) <= 15)
c4ad648e 65#define EASY_VECTOR_15_ADD_SELF(n) ((n) >= 0x10 && (n) <= 0x1e && !((n) & 1))
d744e06e 66
9878760c
RK
67#define min(A,B) ((A) < (B) ? (A) : (B))
68#define max(A,B) ((A) > (B) ? (A) : (B))
69
d1d0c603
JJ
70/* Structure used to define the rs6000 stack */
71typedef struct rs6000_stack {
72 int first_gp_reg_save; /* first callee saved GP register used */
73 int first_fp_reg_save; /* first callee saved FP register used */
74 int first_altivec_reg_save; /* first callee saved AltiVec register used */
75 int lr_save_p; /* true if the link reg needs to be saved */
76 int cr_save_p; /* true if the CR reg needs to be saved */
77 unsigned int vrsave_mask; /* mask of vec registers to save */
78 int toc_save_p; /* true if the TOC needs to be saved */
79 int push_p; /* true if we need to allocate stack space */
80 int calls_p; /* true if the function makes any calls */
c4ad648e 81 int world_save_p; /* true if we're saving *everything*:
d62294f5 82 r13-r31, cr, f14-f31, vrsave, v20-v31 */
d1d0c603
JJ
83 enum rs6000_abi abi; /* which ABI to use */
84 int gp_save_offset; /* offset to save GP regs from initial SP */
85 int fp_save_offset; /* offset to save FP regs from initial SP */
86 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
87 int lr_save_offset; /* offset to save LR from initial SP */
88 int cr_save_offset; /* offset to save CR from initial SP */
89 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
90 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
91 int toc_save_offset; /* offset to save the TOC pointer */
92 int varargs_save_offset; /* offset to save the varargs registers */
93 int ehrd_offset; /* offset to EH return data */
94 int reg_size; /* register size (4 or 8) */
95 int varargs_size; /* size to hold V.4 args passed in regs */
96 HOST_WIDE_INT vars_size; /* variable save area size */
97 int parm_size; /* outgoing parameter size */
98 int save_size; /* save area size */
99 int fixed_size; /* fixed size of stack frame */
100 int gp_size; /* size of saved GP registers */
101 int fp_size; /* size of saved FP registers */
102 int altivec_size; /* size of saved AltiVec registers */
103 int cr_size; /* size to hold CR if not in save_size */
104 int lr_size; /* size to hold LR if not in save_size */
105 int vrsave_size; /* size to hold VRSAVE if not in save_size */
106 int altivec_padding_size; /* size of altivec alignment padding if
107 not in save_size */
108 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
109 int spe_padding_size;
110 int toc_size; /* size to hold TOC if not in save_size */
111 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
112 int spe_64bit_regs_used;
113} rs6000_stack_t;
114
5248c961
RK
115/* Target cpu type */
116
117enum processor_type rs6000_cpu;
8e3f41e7
MM
118struct rs6000_cpu_select rs6000_select[3] =
119{
815cdc52
MM
120 /* switch name, tune arch */
121 { (const char *)0, "--with-cpu=", 1, 1 },
122 { (const char *)0, "-mcpu=", 1, 1 },
123 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 124};
5248c961 125
ec507f2d
DE
126/* Always emit branch hint bits. */
127static GTY(()) bool rs6000_always_hint;
128
129/* Schedule instructions for group formation. */
130static GTY(()) bool rs6000_sched_groups;
131
f676971a 132/* Support adjust_priority scheduler hook
79ae11c4
DN
133 and -mprioritize-restricted-insns= option. */
134const char *rs6000_sched_restricted_insns_priority_str;
135int rs6000_sched_restricted_insns_priority;
136
569fa502
DN
137/* Support for -msched-costly-dep option. */
138const char *rs6000_sched_costly_dep_str;
139enum rs6000_dependence_cost rs6000_sched_costly_dep;
140
cbe26ab8
DN
141/* Support for -minsert-sched-nops option. */
142const char *rs6000_sched_insert_nops_str;
143enum rs6000_nop_insertion rs6000_sched_insert_nops;
144
7ccf35ed
DN
145/* Support targetm.vectorize.builtin_mask_for_load. */
146tree altivec_builtin_mask_for_load;
147/* Support targetm.vectorize.builtin_mask_for_store. */
148tree altivec_builtin_mask_for_store;
149
6fa3f289
ZW
150/* Size of long double */
151const char *rs6000_long_double_size_string;
152int rs6000_long_double_type_size;
153
154/* Whether -mabi=altivec has appeared */
155int rs6000_altivec_abi;
156
08b57fb3
AH
157/* Whether VRSAVE instructions should be generated. */
158int rs6000_altivec_vrsave;
159
160/* String from -mvrsave= option. */
161const char *rs6000_altivec_vrsave_string;
162
a3170dc6
AH
163/* Nonzero if we want SPE ABI extensions. */
164int rs6000_spe_abi;
165
166/* Whether isel instructions should be generated. */
167int rs6000_isel;
168
993f19a8
AH
169/* Whether SPE simd instructions should be generated. */
170int rs6000_spe;
171
5da702b1
AH
172/* Nonzero if floating point operations are done in the GPRs. */
173int rs6000_float_gprs = 0;
174
175/* String from -mfloat-gprs=. */
176const char *rs6000_float_gprs_string;
a3170dc6
AH
177
178/* String from -misel=. */
179const char *rs6000_isel_string;
180
993f19a8
AH
181/* String from -mspe=. */
182const char *rs6000_spe_string;
183
a0ab749a 184/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 185static GTY(()) int common_mode_defined;
c81bebd7 186
9878760c
RK
187/* Save information from a "cmpxx" operation until the branch or scc is
188 emitted. */
9878760c
RK
189rtx rs6000_compare_op0, rs6000_compare_op1;
190int rs6000_compare_fp_p;
874a0744 191
874a0744
MM
192/* Label number of label created for -mrelocatable, to call to so we can
193 get the address of the GOT section */
194int rs6000_pic_labelno;
c81bebd7 195
b91da81f 196#ifdef USING_ELFOS_H
c81bebd7 197/* Which abi to adhere to */
9739c90c 198const char *rs6000_abi_name;
d9407988
MM
199
200/* Semantics of the small data area */
201enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
202
203/* Which small data model to use */
815cdc52 204const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
205
206/* Counter for labels which are to be placed in .fixup. */
207int fixuplabelno = 0;
874a0744 208#endif
4697a36c 209
c4501e62
JJ
210/* Bit size of immediate TLS offsets and string from which it is decoded. */
211int rs6000_tls_size = 32;
212const char *rs6000_tls_size_string;
213
b6c9286a
MM
214/* ABI enumeration available for subtarget to use. */
215enum rs6000_abi rs6000_current_abi;
216
0ac081f6
AH
217/* ABI string from -mabi= option. */
218const char *rs6000_abi_string;
219
85b776df
AM
220/* Whether to use variant of AIX ABI for PowerPC64 Linux. */
221int dot_symbols;
222
38c1f2d7 223/* Debug flags */
815cdc52 224const char *rs6000_debug_name;
38c1f2d7
MM
225int rs6000_debug_stack; /* debug stack applications */
226int rs6000_debug_arg; /* debug argument handling */
227
0d1fbc8c
AH
228/* Value is TRUE if register/mode pair is accepatable. */
229bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
230
6035d635 231/* Opaque types. */
2abe3e28 232static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 233static GTY(()) tree opaque_V2SF_type_node;
6035d635 234static GTY(()) tree opaque_p_V2SI_type_node;
4a5eab38
PB
235static GTY(()) tree V16QI_type_node;
236static GTY(()) tree V2SI_type_node;
237static GTY(()) tree V2SF_type_node;
238static GTY(()) tree V4HI_type_node;
239static GTY(()) tree V4SI_type_node;
240static GTY(()) tree V4SF_type_node;
241static GTY(()) tree V8HI_type_node;
242static GTY(()) tree unsigned_V16QI_type_node;
243static GTY(()) tree unsigned_V8HI_type_node;
244static GTY(()) tree unsigned_V4SI_type_node;
8bb418a3
ZL
245static GTY(()) tree bool_char_type_node; /* __bool char */
246static GTY(()) tree bool_short_type_node; /* __bool short */
247static GTY(()) tree bool_int_type_node; /* __bool int */
248static GTY(()) tree pixel_type_node; /* __pixel */
249static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */
250static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */
251static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */
252static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */
253
254int rs6000_warn_altivec_long = 1; /* On by default. */
255const char *rs6000_warn_altivec_long_switch;
256
57ac7be9
AM
257const char *rs6000_traceback_name;
258static enum {
259 traceback_default = 0,
260 traceback_none,
261 traceback_part,
262 traceback_full
263} rs6000_traceback;
264
38c1f2d7
MM
265/* Flag to say the TOC is initialized */
266int toc_initialized;
9ebbca7d 267char toc_label_name[10];
38c1f2d7 268
9ebbca7d 269/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 270static GTY(()) int rs6000_sr_alias_set;
c8023011 271
a5c76ee6
ZW
272/* Call distance, overridden by -mlongcall and #pragma longcall(1).
273 The only place that looks at this is rs6000_set_default_type_attributes;
274 everywhere else should rely on the presence or absence of a longcall
275 attribute on the function declaration. */
276int rs6000_default_long_calls;
277const char *rs6000_longcall_switch;
278
a3c9585f
KH
279/* Control alignment for fields within structures. */
280/* String from -malign-XXXXX. */
025d9908
KH
281const char *rs6000_alignment_string;
282int rs6000_alignment_flags;
283
a3170dc6
AH
284struct builtin_description
285{
286 /* mask is not const because we're going to alter it below. This
287 nonsense will go away when we rewrite the -march infrastructure
288 to give us more target flag bits. */
289 unsigned int mask;
290 const enum insn_code icode;
291 const char *const name;
292 const enum rs6000_builtins code;
293};
8b897cfa
RS
294\f
295/* Target cpu costs. */
296
297struct processor_costs {
c4ad648e 298 const int mulsi; /* cost of SImode multiplication. */
8b897cfa
RS
299 const int mulsi_const; /* cost of SImode multiplication by constant. */
300 const int mulsi_const9; /* cost of SImode mult by short constant. */
c4ad648e
AM
301 const int muldi; /* cost of DImode multiplication. */
302 const int divsi; /* cost of SImode division. */
303 const int divdi; /* cost of DImode division. */
304 const int fp; /* cost of simple SFmode and DFmode insns. */
305 const int dmul; /* cost of DFmode multiplication (and fmadd). */
306 const int sdiv; /* cost of SFmode division (fdivs). */
307 const int ddiv; /* cost of DFmode division (fdiv). */
8b897cfa
RS
308};
309
310const struct processor_costs *rs6000_cost;
311
312/* Processor costs (relative to an add) */
313
314/* Instruction size costs on 32bit processors. */
315static const
316struct processor_costs size32_cost = {
06a67bdd
RS
317 COSTS_N_INSNS (1), /* mulsi */
318 COSTS_N_INSNS (1), /* mulsi_const */
319 COSTS_N_INSNS (1), /* mulsi_const9 */
320 COSTS_N_INSNS (1), /* muldi */
321 COSTS_N_INSNS (1), /* divsi */
322 COSTS_N_INSNS (1), /* divdi */
323 COSTS_N_INSNS (1), /* fp */
324 COSTS_N_INSNS (1), /* dmul */
325 COSTS_N_INSNS (1), /* sdiv */
326 COSTS_N_INSNS (1), /* ddiv */
8b897cfa
RS
327};
328
329/* Instruction size costs on 64bit processors. */
330static const
331struct processor_costs size64_cost = {
06a67bdd
RS
332 COSTS_N_INSNS (1), /* mulsi */
333 COSTS_N_INSNS (1), /* mulsi_const */
334 COSTS_N_INSNS (1), /* mulsi_const9 */
335 COSTS_N_INSNS (1), /* muldi */
336 COSTS_N_INSNS (1), /* divsi */
337 COSTS_N_INSNS (1), /* divdi */
338 COSTS_N_INSNS (1), /* fp */
339 COSTS_N_INSNS (1), /* dmul */
340 COSTS_N_INSNS (1), /* sdiv */
341 COSTS_N_INSNS (1), /* ddiv */
8b897cfa
RS
342};
343
344/* Instruction costs on RIOS1 processors. */
345static const
346struct processor_costs rios1_cost = {
06a67bdd
RS
347 COSTS_N_INSNS (5), /* mulsi */
348 COSTS_N_INSNS (4), /* mulsi_const */
349 COSTS_N_INSNS (3), /* mulsi_const9 */
350 COSTS_N_INSNS (5), /* muldi */
351 COSTS_N_INSNS (19), /* divsi */
352 COSTS_N_INSNS (19), /* divdi */
353 COSTS_N_INSNS (2), /* fp */
354 COSTS_N_INSNS (2), /* dmul */
355 COSTS_N_INSNS (19), /* sdiv */
356 COSTS_N_INSNS (19), /* ddiv */
8b897cfa
RS
357};
358
359/* Instruction costs on RIOS2 processors. */
360static const
361struct processor_costs rios2_cost = {
06a67bdd
RS
362 COSTS_N_INSNS (2), /* mulsi */
363 COSTS_N_INSNS (2), /* mulsi_const */
364 COSTS_N_INSNS (2), /* mulsi_const9 */
365 COSTS_N_INSNS (2), /* muldi */
366 COSTS_N_INSNS (13), /* divsi */
367 COSTS_N_INSNS (13), /* divdi */
368 COSTS_N_INSNS (2), /* fp */
369 COSTS_N_INSNS (2), /* dmul */
370 COSTS_N_INSNS (17), /* sdiv */
371 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
372};
373
374/* Instruction costs on RS64A processors. */
375static const
376struct processor_costs rs64a_cost = {
06a67bdd
RS
377 COSTS_N_INSNS (20), /* mulsi */
378 COSTS_N_INSNS (12), /* mulsi_const */
379 COSTS_N_INSNS (8), /* mulsi_const9 */
380 COSTS_N_INSNS (34), /* muldi */
381 COSTS_N_INSNS (65), /* divsi */
382 COSTS_N_INSNS (67), /* divdi */
383 COSTS_N_INSNS (4), /* fp */
384 COSTS_N_INSNS (4), /* dmul */
385 COSTS_N_INSNS (31), /* sdiv */
386 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
387};
388
389/* Instruction costs on MPCCORE processors. */
390static const
391struct processor_costs mpccore_cost = {
06a67bdd
RS
392 COSTS_N_INSNS (2), /* mulsi */
393 COSTS_N_INSNS (2), /* mulsi_const */
394 COSTS_N_INSNS (2), /* mulsi_const9 */
395 COSTS_N_INSNS (2), /* muldi */
396 COSTS_N_INSNS (6), /* divsi */
397 COSTS_N_INSNS (6), /* divdi */
398 COSTS_N_INSNS (4), /* fp */
399 COSTS_N_INSNS (5), /* dmul */
400 COSTS_N_INSNS (10), /* sdiv */
401 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
402};
403
404/* Instruction costs on PPC403 processors. */
405static const
406struct processor_costs ppc403_cost = {
06a67bdd
RS
407 COSTS_N_INSNS (4), /* mulsi */
408 COSTS_N_INSNS (4), /* mulsi_const */
409 COSTS_N_INSNS (4), /* mulsi_const9 */
410 COSTS_N_INSNS (4), /* muldi */
411 COSTS_N_INSNS (33), /* divsi */
412 COSTS_N_INSNS (33), /* divdi */
413 COSTS_N_INSNS (11), /* fp */
414 COSTS_N_INSNS (11), /* dmul */
415 COSTS_N_INSNS (11), /* sdiv */
416 COSTS_N_INSNS (11), /* ddiv */
8b897cfa
RS
417};
418
419/* Instruction costs on PPC405 processors. */
420static const
421struct processor_costs ppc405_cost = {
06a67bdd
RS
422 COSTS_N_INSNS (5), /* mulsi */
423 COSTS_N_INSNS (4), /* mulsi_const */
424 COSTS_N_INSNS (3), /* mulsi_const9 */
425 COSTS_N_INSNS (5), /* muldi */
426 COSTS_N_INSNS (35), /* divsi */
427 COSTS_N_INSNS (35), /* divdi */
428 COSTS_N_INSNS (11), /* fp */
429 COSTS_N_INSNS (11), /* dmul */
430 COSTS_N_INSNS (11), /* sdiv */
431 COSTS_N_INSNS (11), /* ddiv */
8b897cfa
RS
432};
433
434/* Instruction costs on PPC440 processors. */
435static const
436struct processor_costs ppc440_cost = {
06a67bdd
RS
437 COSTS_N_INSNS (3), /* mulsi */
438 COSTS_N_INSNS (2), /* mulsi_const */
439 COSTS_N_INSNS (2), /* mulsi_const9 */
440 COSTS_N_INSNS (3), /* muldi */
441 COSTS_N_INSNS (34), /* divsi */
442 COSTS_N_INSNS (34), /* divdi */
443 COSTS_N_INSNS (5), /* fp */
444 COSTS_N_INSNS (5), /* dmul */
445 COSTS_N_INSNS (19), /* sdiv */
446 COSTS_N_INSNS (33), /* ddiv */
8b897cfa
RS
447};
448
449/* Instruction costs on PPC601 processors. */
450static const
451struct processor_costs ppc601_cost = {
06a67bdd
RS
452 COSTS_N_INSNS (5), /* mulsi */
453 COSTS_N_INSNS (5), /* mulsi_const */
454 COSTS_N_INSNS (5), /* mulsi_const9 */
455 COSTS_N_INSNS (5), /* muldi */
456 COSTS_N_INSNS (36), /* divsi */
457 COSTS_N_INSNS (36), /* divdi */
458 COSTS_N_INSNS (4), /* fp */
459 COSTS_N_INSNS (5), /* dmul */
460 COSTS_N_INSNS (17), /* sdiv */
461 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
462};
463
464/* Instruction costs on PPC603 processors. */
465static const
466struct processor_costs ppc603_cost = {
06a67bdd
RS
467 COSTS_N_INSNS (5), /* mulsi */
468 COSTS_N_INSNS (3), /* mulsi_const */
469 COSTS_N_INSNS (2), /* mulsi_const9 */
470 COSTS_N_INSNS (5), /* muldi */
471 COSTS_N_INSNS (37), /* divsi */
472 COSTS_N_INSNS (37), /* divdi */
473 COSTS_N_INSNS (3), /* fp */
474 COSTS_N_INSNS (4), /* dmul */
475 COSTS_N_INSNS (18), /* sdiv */
476 COSTS_N_INSNS (33), /* ddiv */
8b897cfa
RS
477};
478
479/* Instruction costs on PPC604 processors. */
480static const
481struct processor_costs ppc604_cost = {
06a67bdd
RS
482 COSTS_N_INSNS (4), /* mulsi */
483 COSTS_N_INSNS (4), /* mulsi_const */
484 COSTS_N_INSNS (4), /* mulsi_const9 */
485 COSTS_N_INSNS (4), /* muldi */
486 COSTS_N_INSNS (20), /* divsi */
487 COSTS_N_INSNS (20), /* divdi */
488 COSTS_N_INSNS (3), /* fp */
489 COSTS_N_INSNS (3), /* dmul */
490 COSTS_N_INSNS (18), /* sdiv */
491 COSTS_N_INSNS (32), /* ddiv */
8b897cfa
RS
492};
493
494/* Instruction costs on PPC604e processors. */
495static const
496struct processor_costs ppc604e_cost = {
06a67bdd
RS
497 COSTS_N_INSNS (2), /* mulsi */
498 COSTS_N_INSNS (2), /* mulsi_const */
499 COSTS_N_INSNS (2), /* mulsi_const9 */
500 COSTS_N_INSNS (2), /* muldi */
501 COSTS_N_INSNS (20), /* divsi */
502 COSTS_N_INSNS (20), /* divdi */
503 COSTS_N_INSNS (3), /* fp */
504 COSTS_N_INSNS (3), /* dmul */
505 COSTS_N_INSNS (18), /* sdiv */
506 COSTS_N_INSNS (32), /* ddiv */
8b897cfa
RS
507};
508
f0517163 509/* Instruction costs on PPC620 processors. */
8b897cfa
RS
510static const
511struct processor_costs ppc620_cost = {
06a67bdd
RS
512 COSTS_N_INSNS (5), /* mulsi */
513 COSTS_N_INSNS (4), /* mulsi_const */
514 COSTS_N_INSNS (3), /* mulsi_const9 */
515 COSTS_N_INSNS (7), /* muldi */
516 COSTS_N_INSNS (21), /* divsi */
517 COSTS_N_INSNS (37), /* divdi */
518 COSTS_N_INSNS (3), /* fp */
519 COSTS_N_INSNS (3), /* dmul */
520 COSTS_N_INSNS (18), /* sdiv */
521 COSTS_N_INSNS (32), /* ddiv */
f0517163
RS
522};
523
524/* Instruction costs on PPC630 processors. */
525static const
526struct processor_costs ppc630_cost = {
06a67bdd
RS
527 COSTS_N_INSNS (5), /* mulsi */
528 COSTS_N_INSNS (4), /* mulsi_const */
529 COSTS_N_INSNS (3), /* mulsi_const9 */
530 COSTS_N_INSNS (7), /* muldi */
531 COSTS_N_INSNS (21), /* divsi */
532 COSTS_N_INSNS (37), /* divdi */
533 COSTS_N_INSNS (3), /* fp */
534 COSTS_N_INSNS (3), /* dmul */
535 COSTS_N_INSNS (17), /* sdiv */
536 COSTS_N_INSNS (21), /* ddiv */
8b897cfa
RS
537};
538
539/* Instruction costs on PPC750 and PPC7400 processors. */
540static const
541struct processor_costs ppc750_cost = {
06a67bdd
RS
542 COSTS_N_INSNS (5), /* mulsi */
543 COSTS_N_INSNS (3), /* mulsi_const */
544 COSTS_N_INSNS (2), /* mulsi_const9 */
545 COSTS_N_INSNS (5), /* muldi */
546 COSTS_N_INSNS (17), /* divsi */
547 COSTS_N_INSNS (17), /* divdi */
548 COSTS_N_INSNS (3), /* fp */
549 COSTS_N_INSNS (3), /* dmul */
550 COSTS_N_INSNS (17), /* sdiv */
551 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
552};
553
554/* Instruction costs on PPC7450 processors. */
555static const
556struct processor_costs ppc7450_cost = {
06a67bdd
RS
557 COSTS_N_INSNS (4), /* mulsi */
558 COSTS_N_INSNS (3), /* mulsi_const */
559 COSTS_N_INSNS (3), /* mulsi_const9 */
560 COSTS_N_INSNS (4), /* muldi */
561 COSTS_N_INSNS (23), /* divsi */
562 COSTS_N_INSNS (23), /* divdi */
563 COSTS_N_INSNS (5), /* fp */
564 COSTS_N_INSNS (5), /* dmul */
565 COSTS_N_INSNS (21), /* sdiv */
566 COSTS_N_INSNS (35), /* ddiv */
8b897cfa 567};
a3170dc6 568
8b897cfa
RS
569/* Instruction costs on PPC8540 processors. */
570static const
571struct processor_costs ppc8540_cost = {
06a67bdd
RS
572 COSTS_N_INSNS (4), /* mulsi */
573 COSTS_N_INSNS (4), /* mulsi_const */
574 COSTS_N_INSNS (4), /* mulsi_const9 */
575 COSTS_N_INSNS (4), /* muldi */
576 COSTS_N_INSNS (19), /* divsi */
577 COSTS_N_INSNS (19), /* divdi */
578 COSTS_N_INSNS (4), /* fp */
579 COSTS_N_INSNS (4), /* dmul */
580 COSTS_N_INSNS (29), /* sdiv */
581 COSTS_N_INSNS (29), /* ddiv */
8b897cfa
RS
582};
583
584/* Instruction costs on POWER4 and POWER5 processors. */
585static const
586struct processor_costs power4_cost = {
06a67bdd
RS
587 COSTS_N_INSNS (3), /* mulsi */
588 COSTS_N_INSNS (2), /* mulsi_const */
589 COSTS_N_INSNS (2), /* mulsi_const9 */
590 COSTS_N_INSNS (4), /* muldi */
591 COSTS_N_INSNS (18), /* divsi */
592 COSTS_N_INSNS (34), /* divdi */
593 COSTS_N_INSNS (3), /* fp */
594 COSTS_N_INSNS (3), /* dmul */
595 COSTS_N_INSNS (17), /* sdiv */
596 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
597};
598
599\f
a2369ed3
DJ
600static bool rs6000_function_ok_for_sibcall (tree, tree);
601static int num_insns_constant_wide (HOST_WIDE_INT);
602static void validate_condition_mode (enum rtx_code, enum machine_mode);
603static rtx rs6000_generate_compare (enum rtx_code);
604static void rs6000_maybe_dead (rtx);
605static void rs6000_emit_stack_tie (void);
606static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
607static rtx spe_synthesize_frame_save (rtx);
608static bool spe_func_has_64bit_regs_p (void);
b20a9cca 609static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 610 int, HOST_WIDE_INT);
a2369ed3
DJ
611static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
612static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
613static unsigned rs6000_hash_constant (rtx);
614static unsigned toc_hash_function (const void *);
615static int toc_hash_eq (const void *, const void *);
616static int constant_pool_expr_1 (rtx, int *, int *);
617static bool constant_pool_expr_p (rtx);
618static bool toc_relative_expr_p (rtx);
619static bool legitimate_small_data_p (enum machine_mode, rtx);
a2369ed3
DJ
620static bool legitimate_indexed_address_p (rtx, int);
621static bool legitimate_indirect_address_p (rtx, int);
4c81e946 622static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
623static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
624static struct machine_function * rs6000_init_machine_status (void);
625static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 626#ifdef HAVE_GAS_HIDDEN
a2369ed3 627static void rs6000_assemble_visibility (tree, int);
5add3202 628#endif
a2369ed3
DJ
629static int rs6000_ra_ever_killed (void);
630static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
8bb418a3 631static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
76d2b81d 632static void rs6000_eliminate_indexed_memrefs (rtx operands[2]);
f18eca82 633static const char *rs6000_mangle_fundamental_type (tree);
b86fe7b4 634extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
635static void rs6000_set_default_type_attributes (tree);
636static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
637static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
638static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
639 tree);
a2369ed3 640static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 641static bool rs6000_return_in_memory (tree, tree);
a2369ed3 642static void rs6000_file_start (void);
7c262518 643#if TARGET_ELF
a2369ed3
DJ
644static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
645static void rs6000_elf_asm_out_constructor (rtx, int);
646static void rs6000_elf_asm_out_destructor (rtx, int);
647static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
648static void rs6000_elf_unique_section (tree, int);
649static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 650 unsigned HOST_WIDE_INT);
a56d7372 651static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 652 ATTRIBUTE_UNUSED;
a2369ed3 653static bool rs6000_elf_in_small_data_p (tree);
7c262518 654#endif
cbaaba19 655#if TARGET_XCOFF
a2369ed3 656static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
8210e4c4 657static void rs6000_xcoff_asm_named_section (const char *, unsigned int, tree);
a2369ed3
DJ
658static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
659static void rs6000_xcoff_unique_section (tree, int);
660static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 661 unsigned HOST_WIDE_INT);
a2369ed3
DJ
662static const char * rs6000_xcoff_strip_name_encoding (const char *);
663static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
664static void rs6000_xcoff_file_start (void);
665static void rs6000_xcoff_file_end (void);
f1384257
AM
666#endif
667#if TARGET_MACHO
a2369ed3 668static bool rs6000_binds_local_p (tree);
f1384257 669#endif
a2369ed3
DJ
670static int rs6000_variable_issue (FILE *, int, rtx, int);
671static bool rs6000_rtx_costs (rtx, int, int, int *);
672static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 673static bool is_microcoded_insn (rtx);
79ae11c4 674static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
675static bool is_cracked_insn (rtx);
676static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
677static int rs6000_adjust_priority (rtx, int);
678static int rs6000_issue_rate (void);
569fa502 679static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
680static rtx get_next_active_insn (rtx, rtx);
681static bool insn_terminates_group_p (rtx , enum group_termination);
682static bool is_costly_group (rtx *, rtx);
683static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
684static int redefine_groups (FILE *, int, rtx, rtx);
685static int pad_groups (FILE *, int, rtx, rtx);
686static void rs6000_sched_finish (FILE *, int);
a2369ed3 687static int rs6000_use_sched_lookahead (void);
7ccf35ed
DN
688static tree rs6000_builtin_mask_for_load (void);
689static tree rs6000_builtin_mask_for_store (void);
a2369ed3
DJ
690
691static void rs6000_init_builtins (void);
692static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
693static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
694static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
695static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
696static void altivec_init_builtins (void);
697static void rs6000_common_init_builtins (void);
c15c90bb 698static void rs6000_init_libfuncs (void);
a2369ed3 699
b20a9cca
AM
700static void enable_mask_for_builtins (struct builtin_description *, int,
701 enum rs6000_builtins,
702 enum rs6000_builtins);
7c62e993 703static tree build_opaque_vector_type (tree, int);
a2369ed3
DJ
704static void spe_init_builtins (void);
705static rtx spe_expand_builtin (tree, rtx, bool *);
61bea3b0 706static rtx spe_expand_stv_builtin (enum insn_code, tree);
a2369ed3
DJ
707static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
708static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
709static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
710static rs6000_stack_t *rs6000_stack_info (void);
711static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
712
713static rtx altivec_expand_builtin (tree, rtx, bool *);
714static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
715static rtx altivec_expand_st_builtin (tree, rtx, bool *);
716static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
717static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
f676971a 718static rtx altivec_expand_predicate_builtin (enum insn_code,
c4ad648e 719 const char *, tree, rtx);
b4a62fa0 720static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
721static rtx altivec_expand_stv_builtin (enum insn_code, tree);
722static void rs6000_parse_abi_options (void);
723static void rs6000_parse_alignment_option (void);
724static void rs6000_parse_tls_size_option (void);
5da702b1 725static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
726static int first_altivec_reg_to_save (void);
727static unsigned int compute_vrsave_mask (void);
d62294f5 728static void compute_save_world_info(rs6000_stack_t *info_ptr);
a2369ed3
DJ
729static void is_altivec_return_reg (rtx, void *);
730static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
731int easy_vector_constant (rtx, enum machine_mode);
732static int easy_vector_same (rtx, enum machine_mode);
452a7d36 733static int easy_vector_splat_const (int, enum machine_mode);
a2369ed3
DJ
734static bool is_ev64_opaque_type (tree);
735static rtx rs6000_dwarf_register_span (rtx);
736static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
737static rtx rs6000_tls_get_addr (void);
738static rtx rs6000_got_sym (void);
739static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
740static const char *rs6000_get_some_local_dynamic_name (void);
741static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 742static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 743static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 744 enum machine_mode, tree);
ec6376ab 745static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int);
b1917422 746static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
c6e8c921
GK
747static void setup_incoming_varargs (CUMULATIVE_ARGS *,
748 enum machine_mode, tree,
749 int *, int);
8cd5a4e0
RH
750static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
751 tree, bool);
efdba735
SH
752#if TARGET_MACHO
753static void macho_branch_islands (void);
754static void add_compiler_branch_island (tree, tree, int);
755static int no_previous_def (tree function_name);
756static tree get_prev_label (tree function_name);
757#endif
758
c35d187f 759static tree rs6000_build_builtin_va_list (void);
23a60a04 760static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *);
fe984136 761static bool rs6000_must_pass_in_stack (enum machine_mode, tree);
f676971a 762static bool rs6000_vector_mode_supported_p (enum machine_mode);
21213b4c
DP
763static int get_vec_cmp_insn (enum rtx_code, enum machine_mode,
764 enum machine_mode);
765static rtx rs6000_emit_vector_compare (enum rtx_code, rtx, rtx,
766 enum machine_mode);
767static int get_vsel_insn (enum machine_mode);
768static void rs6000_emit_vector_select (rtx, rtx, rtx, rtx);
17211ab5 769
21213b4c
DP
770
771const int INSN_NOT_AVAILABLE = -1;
93f90be6
FJ
772static enum machine_mode rs6000_eh_return_filter_mode (void);
773
17211ab5
GK
774/* Hash table stuff for keeping track of TOC entries. */
775
776struct toc_hash_struct GTY(())
777{
778 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
779 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
780 rtx key;
781 enum machine_mode key_mode;
782 int labelno;
783};
784
785static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
786\f
787/* Default register names. */
788char rs6000_reg_names[][8] =
789{
802a0058
MM
790 "0", "1", "2", "3", "4", "5", "6", "7",
791 "8", "9", "10", "11", "12", "13", "14", "15",
792 "16", "17", "18", "19", "20", "21", "22", "23",
793 "24", "25", "26", "27", "28", "29", "30", "31",
794 "0", "1", "2", "3", "4", "5", "6", "7",
795 "8", "9", "10", "11", "12", "13", "14", "15",
796 "16", "17", "18", "19", "20", "21", "22", "23",
797 "24", "25", "26", "27", "28", "29", "30", "31",
798 "mq", "lr", "ctr","ap",
799 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
800 "xer",
801 /* AltiVec registers. */
0cd5e3a1
AH
802 "0", "1", "2", "3", "4", "5", "6", "7",
803 "8", "9", "10", "11", "12", "13", "14", "15",
804 "16", "17", "18", "19", "20", "21", "22", "23",
805 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
806 "vrsave", "vscr",
807 /* SPE registers. */
808 "spe_acc", "spefscr"
c81bebd7
MM
809};
810
811#ifdef TARGET_REGNAMES
8b60264b 812static const char alt_reg_names[][8] =
c81bebd7 813{
802a0058
MM
814 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
815 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
816 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
817 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
818 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
819 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
820 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
821 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
822 "mq", "lr", "ctr", "ap",
823 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 824 "xer",
59a4c851 825 /* AltiVec registers. */
0ac081f6 826 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
827 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
828 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
829 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
830 "vrsave", "vscr",
831 /* SPE registers. */
832 "spe_acc", "spefscr"
c81bebd7
MM
833};
834#endif
9878760c 835\f
daf11973
MM
836#ifndef MASK_STRICT_ALIGN
837#define MASK_STRICT_ALIGN 0
838#endif
ffcfcb5f
AM
839#ifndef TARGET_PROFILE_KERNEL
840#define TARGET_PROFILE_KERNEL 0
841#endif
3961e8fe
RH
842
843/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
844#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
845
846/* Return 1 for a symbol ref for a thread-local storage symbol. */
847#define RS6000_SYMBOL_REF_TLS_P(RTX) \
848 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
849\f
850/* Initialize the GCC target structure. */
91d231cb
JM
851#undef TARGET_ATTRIBUTE_TABLE
852#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
853#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
854#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 855
301d03af
RS
856#undef TARGET_ASM_ALIGNED_DI_OP
857#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
858
859/* Default unaligned ops are only provided for ELF. Find the ops needed
860 for non-ELF systems. */
861#ifndef OBJECT_FORMAT_ELF
cbaaba19 862#if TARGET_XCOFF
ae6c1efd 863/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
864 64-bit targets. */
865#undef TARGET_ASM_UNALIGNED_HI_OP
866#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
867#undef TARGET_ASM_UNALIGNED_SI_OP
868#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
869#undef TARGET_ASM_UNALIGNED_DI_OP
870#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
871#else
872/* For Darwin. */
873#undef TARGET_ASM_UNALIGNED_HI_OP
874#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
875#undef TARGET_ASM_UNALIGNED_SI_OP
876#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
49bd1d27
SS
877#undef TARGET_ASM_UNALIGNED_DI_OP
878#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
879#undef TARGET_ASM_ALIGNED_DI_OP
880#define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
301d03af
RS
881#endif
882#endif
883
884/* This hook deals with fixups for relocatable code and DI-mode objects
885 in 64-bit code. */
886#undef TARGET_ASM_INTEGER
887#define TARGET_ASM_INTEGER rs6000_assemble_integer
888
93638d7a
AM
889#ifdef HAVE_GAS_HIDDEN
890#undef TARGET_ASM_ASSEMBLE_VISIBILITY
891#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
892#endif
893
c4501e62
JJ
894#undef TARGET_HAVE_TLS
895#define TARGET_HAVE_TLS HAVE_AS_TLS
896
897#undef TARGET_CANNOT_FORCE_CONST_MEM
898#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
899
08c148a8
NB
900#undef TARGET_ASM_FUNCTION_PROLOGUE
901#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
902#undef TARGET_ASM_FUNCTION_EPILOGUE
903#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
904
b54cf83a
DE
905#undef TARGET_SCHED_VARIABLE_ISSUE
906#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
907
c237e94a
ZW
908#undef TARGET_SCHED_ISSUE_RATE
909#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
910#undef TARGET_SCHED_ADJUST_COST
911#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
912#undef TARGET_SCHED_ADJUST_PRIORITY
913#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
f676971a 914#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
569fa502 915#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
916#undef TARGET_SCHED_FINISH
917#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 918
be12c2b0
VM
919#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
920#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
921
7ccf35ed
DN
922#undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
923#define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load
924
925#undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE
926#define TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE rs6000_builtin_mask_for_store
927
0ac081f6
AH
928#undef TARGET_INIT_BUILTINS
929#define TARGET_INIT_BUILTINS rs6000_init_builtins
930
931#undef TARGET_EXPAND_BUILTIN
932#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
933
f18eca82
ZL
934#undef TARGET_MANGLE_FUNDAMENTAL_TYPE
935#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
936
c15c90bb
ZW
937#undef TARGET_INIT_LIBFUNCS
938#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
939
f1384257 940#if TARGET_MACHO
0e5dbd9b
DE
941#undef TARGET_BINDS_LOCAL_P
942#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 943#endif
0e5dbd9b 944
3961e8fe
RH
945#undef TARGET_ASM_OUTPUT_MI_THUNK
946#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
947
3961e8fe 948#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 949#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 950
4977bab6
ZW
951#undef TARGET_FUNCTION_OK_FOR_SIBCALL
952#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
953
3c50106f
RH
954#undef TARGET_RTX_COSTS
955#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
956#undef TARGET_ADDRESS_COST
957#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 958
c8e4f0e9
AH
959#undef TARGET_VECTOR_OPAQUE_P
960#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 961
96714395
AH
962#undef TARGET_DWARF_REGISTER_SPAN
963#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
964
c6e8c921
GK
965/* On rs6000, function arguments are promoted, as are function return
966 values. */
967#undef TARGET_PROMOTE_FUNCTION_ARGS
968#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
969#undef TARGET_PROMOTE_FUNCTION_RETURN
970#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
971
c6e8c921
GK
972#undef TARGET_RETURN_IN_MEMORY
973#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
974
975#undef TARGET_SETUP_INCOMING_VARARGS
976#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
977
978/* Always strict argument naming on rs6000. */
979#undef TARGET_STRICT_ARGUMENT_NAMING
980#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
981#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
982#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
983#undef TARGET_SPLIT_COMPLEX_ARG
984#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
fe984136
RH
985#undef TARGET_MUST_PASS_IN_STACK
986#define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
8cd5a4e0
RH
987#undef TARGET_PASS_BY_REFERENCE
988#define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
c6e8c921 989
c35d187f
RH
990#undef TARGET_BUILD_BUILTIN_VA_LIST
991#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
992
cd3ce9b4
JM
993#undef TARGET_GIMPLIFY_VA_ARG_EXPR
994#define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
995
93f90be6
FJ
996#undef TARGET_EH_RETURN_FILTER_MODE
997#define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
998
f676971a
EC
999#undef TARGET_VECTOR_MODE_SUPPORTED_P
1000#define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
1001
f6897b10 1002struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 1003\f
0d1fbc8c
AH
1004
1005/* Value is 1 if hard register REGNO can hold a value of machine-mode
1006 MODE. */
1007static int
1008rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
1009{
1010 /* The GPRs can hold any mode, but values bigger than one register
1011 cannot go past R31. */
1012 if (INT_REGNO_P (regno))
1013 return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1);
1014
1015 /* The float registers can only hold floating modes and DImode. */
1016 if (FP_REGNO_P (regno))
1017 return
1018 (GET_MODE_CLASS (mode) == MODE_FLOAT
1019 && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1))
1020 || (GET_MODE_CLASS (mode) == MODE_INT
1021 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD);
1022
1023 /* The CR register can only hold CC modes. */
1024 if (CR_REGNO_P (regno))
1025 return GET_MODE_CLASS (mode) == MODE_CC;
1026
1027 if (XER_REGNO_P (regno))
1028 return mode == PSImode;
1029
1030 /* AltiVec only in AldyVec registers. */
1031 if (ALTIVEC_REGNO_P (regno))
1032 return ALTIVEC_VECTOR_MODE (mode);
1033
1034 /* ...but GPRs can hold SIMD data on the SPE in one register. */
1035 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1036 return 1;
1037
1038 /* We cannot put TImode anywhere except general register and it must be
1039 able to fit within the register set. */
1040
1041 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1042}
1043
1044/* Initialize rs6000_hard_regno_mode_ok_p table. */
1045static void
1046rs6000_init_hard_regno_mode_ok (void)
1047{
1048 int r, m;
1049
1050 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
1051 for (m = 0; m < NUM_MACHINE_MODES; ++m)
1052 if (rs6000_hard_regno_mode_ok (r, m))
1053 rs6000_hard_regno_mode_ok_p[m][r] = true;
1054}
1055
c1e55850
GK
1056/* If not otherwise specified by a target, make 'long double' equivalent to
1057 'double'. */
1058
1059#ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
1060#define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
1061#endif
1062
5248c961
RK
1063/* Override command line options. Mostly we process the processor
1064 type and sometimes adjust other TARGET_ options. */
1065
1066void
d779d0dc 1067rs6000_override_options (const char *default_cpu)
5248c961 1068{
c4d38ccb 1069 size_t i, j;
8e3f41e7 1070 struct rs6000_cpu_select *ptr;
66188a7e 1071 int set_masks;
5248c961 1072
66188a7e 1073 /* Simplifications for entries below. */
85638c0d 1074
66188a7e
GK
1075 enum {
1076 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
1077 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
1078 };
85638c0d 1079
66188a7e
GK
1080 /* This table occasionally claims that a processor does not support
1081 a particular feature even though it does, but the feature is slower
1082 than the alternative. Thus, it shouldn't be relied on as a
f676971a 1083 complete description of the processor's support.
66188a7e
GK
1084
1085 Please keep this list in order, and don't forget to update the
1086 documentation in invoke.texi when adding a new processor or
1087 flag. */
5248c961
RK
1088 static struct ptt
1089 {
8b60264b
KG
1090 const char *const name; /* Canonical processor name. */
1091 const enum processor_type processor; /* Processor type enum value. */
1092 const int target_enable; /* Target flags to enable. */
8b60264b 1093 } const processor_target_table[]
66188a7e 1094 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 1095 {"403", PROCESSOR_PPC403,
66188a7e
GK
1096 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
1097 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1098 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
1099 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1100 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
1101 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 1102 {"601", PROCESSOR_PPC601,
66188a7e
GK
1103 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
1104 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1105 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1106 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1107 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1108 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
1109 {"620", PROCESSOR_PPC620,
1110 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1111 {"630", PROCESSOR_PPC630,
1112 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
1113 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1114 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
1115 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1116 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1117 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1118 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1119 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1120 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1121 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 1122 {"970", PROCESSOR_POWER4,
66188a7e
GK
1123 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1124 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
1125 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1126 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1127 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 1128 {"G5", PROCESSOR_POWER4,
66188a7e
GK
1129 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1130 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1131 {"power2", PROCESSOR_POWER,
1132 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
1133 {"power3", PROCESSOR_PPC630,
1134 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1135 {"power4", PROCESSOR_POWER4,
fc091c8e 1136 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
ec507f2d 1137 {"power5", PROCESSOR_POWER5,
fc091c8e 1138 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
66188a7e
GK
1139 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
1140 {"powerpc64", PROCESSOR_POWERPC64,
1141 POWERPC_BASE_MASK | MASK_POWERPC64},
1142 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1143 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1144 {"rios2", PROCESSOR_RIOS2,
1145 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1146 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1147 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 1148 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 1149 };
5248c961 1150
ca7558fc 1151 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 1152
66188a7e
GK
1153 /* Some OSs don't support saving the high part of 64-bit registers on
1154 context switch. Other OSs don't support saving Altivec registers.
1155 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
1156 settings; if the user wants either, the user must explicitly specify
1157 them and we won't interfere with the user's specification. */
1158
1159 enum {
1160 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
f676971a 1161 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
66188a7e
GK
1162 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
1163 | MASK_MFCRF)
1164 };
0d1fbc8c
AH
1165
1166 rs6000_init_hard_regno_mode_ok ();
1167
c4ad648e 1168 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
66188a7e
GK
1169#ifdef OS_MISSING_POWERPC64
1170 if (OS_MISSING_POWERPC64)
1171 set_masks &= ~MASK_POWERPC64;
1172#endif
1173#ifdef OS_MISSING_ALTIVEC
1174 if (OS_MISSING_ALTIVEC)
1175 set_masks &= ~MASK_ALTIVEC;
1176#endif
1177
957211c3
AM
1178 /* Don't override these by the processor default if given explicitly. */
1179 set_masks &= ~(target_flags_explicit
1180 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
1181
a4f6c312 1182 /* Identify the processor type. */
8e3f41e7 1183 rs6000_select[0].string = default_cpu;
3cb999d8 1184 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 1185
b6a1cbae 1186 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 1187 {
8e3f41e7
MM
1188 ptr = &rs6000_select[i];
1189 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 1190 {
8e3f41e7
MM
1191 for (j = 0; j < ptt_size; j++)
1192 if (! strcmp (ptr->string, processor_target_table[j].name))
1193 {
1194 if (ptr->set_tune_p)
1195 rs6000_cpu = processor_target_table[j].processor;
1196
1197 if (ptr->set_arch_p)
1198 {
66188a7e
GK
1199 target_flags &= ~set_masks;
1200 target_flags |= (processor_target_table[j].target_enable
1201 & set_masks);
8e3f41e7
MM
1202 }
1203 break;
1204 }
1205
4406229e 1206 if (j == ptt_size)
8e3f41e7 1207 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
1208 }
1209 }
8a61d227 1210
993f19a8 1211 if (TARGET_E500)
a3170dc6
AH
1212 rs6000_isel = 1;
1213
dff9f1b6
DE
1214 /* If we are optimizing big endian systems for space, use the load/store
1215 multiple and string instructions. */
ef792183 1216 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 1217 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 1218
a4f6c312
SS
1219 /* Don't allow -mmultiple or -mstring on little endian systems
1220 unless the cpu is a 750, because the hardware doesn't support the
1221 instructions used in little endian mode, and causes an alignment
1222 trap. The 750 does not cause an alignment trap (except when the
1223 target is unaligned). */
bef84347 1224
b21fb038 1225 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
1226 {
1227 if (TARGET_MULTIPLE)
1228 {
1229 target_flags &= ~MASK_MULTIPLE;
b21fb038 1230 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
1231 warning ("-mmultiple is not supported on little endian systems");
1232 }
1233
1234 if (TARGET_STRING)
1235 {
1236 target_flags &= ~MASK_STRING;
b21fb038 1237 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 1238 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
1239 }
1240 }
3933e0e1 1241
38c1f2d7
MM
1242 /* Set debug flags */
1243 if (rs6000_debug_name)
1244 {
bfc79d3b 1245 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 1246 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 1247 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 1248 rs6000_debug_stack = 1;
bfc79d3b 1249 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
1250 rs6000_debug_arg = 1;
1251 else
c725bd79 1252 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
1253 }
1254
57ac7be9
AM
1255 if (rs6000_traceback_name)
1256 {
1257 if (! strncmp (rs6000_traceback_name, "full", 4))
1258 rs6000_traceback = traceback_full;
1259 else if (! strncmp (rs6000_traceback_name, "part", 4))
1260 rs6000_traceback = traceback_part;
1261 else if (! strncmp (rs6000_traceback_name, "no", 2))
1262 rs6000_traceback = traceback_none;
1263 else
1264 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
1265 rs6000_traceback_name);
1266 }
1267
6fa3f289 1268 /* Set size of long double */
c1e55850 1269 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
6fa3f289
ZW
1270 if (rs6000_long_double_size_string)
1271 {
1272 char *tail;
1273 int size = strtol (rs6000_long_double_size_string, &tail, 10);
1274 if (*tail != '\0' || (size != 64 && size != 128))
1275 error ("Unknown switch -mlong-double-%s",
1276 rs6000_long_double_size_string);
1277 else
1278 rs6000_long_double_type_size = size;
1279 }
1280
6d0ef01e
HP
1281 /* Set Altivec ABI as default for powerpc64 linux. */
1282 if (TARGET_ELF && TARGET_64BIT)
1283 {
1284 rs6000_altivec_abi = 1;
1285 rs6000_altivec_vrsave = 1;
1286 }
1287
0ac081f6
AH
1288 /* Handle -mabi= options. */
1289 rs6000_parse_abi_options ();
1290
025d9908
KH
1291 /* Handle -malign-XXXXX option. */
1292 rs6000_parse_alignment_option ();
1293
5da702b1
AH
1294 /* Handle generic -mFOO=YES/NO options. */
1295 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
1296 &rs6000_altivec_vrsave);
1297 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
1298 &rs6000_isel);
1299 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
1300 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
1301 &rs6000_float_gprs);
993f19a8 1302
c4501e62
JJ
1303 /* Handle -mtls-size option. */
1304 rs6000_parse_tls_size_option ();
1305
a7ae18e2
AH
1306#ifdef SUBTARGET_OVERRIDE_OPTIONS
1307 SUBTARGET_OVERRIDE_OPTIONS;
1308#endif
1309#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
1310 SUBSUBTARGET_OVERRIDE_OPTIONS;
1311#endif
1312
5da702b1
AH
1313 if (TARGET_E500)
1314 {
e4463bf1
AH
1315 if (TARGET_ALTIVEC)
1316 error ("AltiVec and E500 instructions cannot coexist");
1317
5da702b1
AH
1318 /* The e500 does not have string instructions, and we set
1319 MASK_STRING above when optimizing for size. */
1320 if ((target_flags & MASK_STRING) != 0)
1321 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
1322
1323 /* No SPE means 64-bit long doubles, even if an E500. */
1324 if (rs6000_spe_string != 0
c4ad648e 1325 && !strcmp (rs6000_spe_string, "no"))
b6e59a3a 1326 rs6000_long_double_type_size = 64;
5da702b1
AH
1327 }
1328 else if (rs6000_select[1].string != NULL)
1329 {
1330 /* For the powerpc-eabispe configuration, we set all these by
1331 default, so let's unset them if we manually set another
1332 CPU that is not the E500. */
1333 if (rs6000_abi_string == 0)
1334 rs6000_spe_abi = 0;
1335 if (rs6000_spe_string == 0)
1336 rs6000_spe = 0;
1337 if (rs6000_float_gprs_string == 0)
1338 rs6000_float_gprs = 0;
1339 if (rs6000_isel_string == 0)
1340 rs6000_isel = 0;
b6e59a3a 1341 if (rs6000_long_double_size_string == 0)
c1e55850 1342 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
5da702b1 1343 }
b5044283 1344
ec507f2d
DE
1345 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
1346 && rs6000_cpu != PROCESSOR_POWER5);
1347 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
1348 || rs6000_cpu == PROCESSOR_POWER5);
1349
a5c76ee6
ZW
1350 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
1351 using TARGET_OPTIONS to handle a toggle switch, but we're out of
1352 bits in target_flags so TARGET_SWITCHES cannot be used.
1353 Assumption here is that rs6000_longcall_switch points into the
1354 text of the complete option, rather than being a copy, so we can
1355 scan back for the presence or absence of the no- modifier. */
1356 if (rs6000_longcall_switch)
1357 {
1358 const char *base = rs6000_longcall_switch;
1359 while (base[-1] != 'm') base--;
1360
1361 if (*rs6000_longcall_switch != '\0')
1362 error ("invalid option `%s'", base);
1363 rs6000_default_long_calls = (base[0] != 'n');
1364 }
1365
8bb418a3
ZL
1366 /* Handle -m(no-)warn-altivec-long similarly. */
1367 if (rs6000_warn_altivec_long_switch)
1368 {
1369 const char *base = rs6000_warn_altivec_long_switch;
1370 while (base[-1] != 'm') base--;
1371
1372 if (*rs6000_warn_altivec_long_switch != '\0')
1373 error ("invalid option `%s'", base);
1374 rs6000_warn_altivec_long = (base[0] != 'n');
1375 }
1376
cbe26ab8 1377 /* Handle -mprioritize-restricted-insns option. */
ec507f2d
DE
1378 rs6000_sched_restricted_insns_priority
1379 = (rs6000_sched_groups ? 1 : 0);
79ae11c4
DN
1380 if (rs6000_sched_restricted_insns_priority_str)
1381 rs6000_sched_restricted_insns_priority =
1382 atoi (rs6000_sched_restricted_insns_priority_str);
1383
569fa502 1384 /* Handle -msched-costly-dep option. */
ec507f2d
DE
1385 rs6000_sched_costly_dep
1386 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
569fa502
DN
1387 if (rs6000_sched_costly_dep_str)
1388 {
f676971a 1389 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
c4ad648e 1390 rs6000_sched_costly_dep = no_dep_costly;
569fa502 1391 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
c4ad648e 1392 rs6000_sched_costly_dep = all_deps_costly;
569fa502 1393 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
c4ad648e 1394 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
569fa502 1395 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
c4ad648e 1396 rs6000_sched_costly_dep = store_to_load_dep_costly;
f676971a 1397 else
c4ad648e 1398 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
cbe26ab8
DN
1399 }
1400
1401 /* Handle -minsert-sched-nops option. */
ec507f2d
DE
1402 rs6000_sched_insert_nops
1403 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
cbe26ab8
DN
1404 if (rs6000_sched_insert_nops_str)
1405 {
1406 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
c4ad648e 1407 rs6000_sched_insert_nops = sched_finish_none;
cbe26ab8 1408 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
c4ad648e 1409 rs6000_sched_insert_nops = sched_finish_pad_groups;
cbe26ab8 1410 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
c4ad648e 1411 rs6000_sched_insert_nops = sched_finish_regroup_exact;
cbe26ab8 1412 else
c4ad648e 1413 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
1414 }
1415
c81bebd7 1416#ifdef TARGET_REGNAMES
a4f6c312
SS
1417 /* If the user desires alternate register names, copy in the
1418 alternate names now. */
c81bebd7 1419 if (TARGET_REGNAMES)
4e135bdd 1420 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
1421#endif
1422
6fa3f289
ZW
1423 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
1424 If -maix-struct-return or -msvr4-struct-return was explicitly
1425 used, don't override with the ABI default. */
b21fb038 1426 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
1427 {
1428 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
1429 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
1430 else
1431 target_flags |= MASK_AIX_STRUCT_RET;
1432 }
1433
fcce224d
DE
1434 if (TARGET_LONG_DOUBLE_128
1435 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 1436 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 1437
9ebbca7d
GK
1438 /* Allocate an alias set for register saves & restores from stack. */
1439 rs6000_sr_alias_set = new_alias_set ();
1440
f676971a 1441 if (TARGET_TOC)
9ebbca7d 1442 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 1443
301d03af
RS
1444 /* We can only guarantee the availability of DI pseudo-ops when
1445 assembling for 64-bit targets. */
ae6c1efd 1446 if (!TARGET_64BIT)
301d03af
RS
1447 {
1448 targetm.asm_out.aligned_op.di = NULL;
1449 targetm.asm_out.unaligned_op.di = NULL;
1450 }
1451
1494c534
DE
1452 /* Set branch target alignment, if not optimizing for size. */
1453 if (!optimize_size)
1454 {
1455 if (rs6000_sched_groups)
1456 {
1457 if (align_functions <= 0)
1458 align_functions = 16;
1459 if (align_jumps <= 0)
1460 align_jumps = 16;
1461 if (align_loops <= 0)
1462 align_loops = 16;
1463 }
1464 if (align_jumps_max_skip <= 0)
1465 align_jumps_max_skip = 15;
1466 if (align_loops_max_skip <= 0)
1467 align_loops_max_skip = 15;
1468 }
2792d578 1469
71f123ca
FS
1470 /* Arrange to save and restore machine status around nested functions. */
1471 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1472
1473 /* We should always be splitting complex arguments, but we can't break
1474 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1475 if (DEFAULT_ABI != ABI_AIX)
1476 targetm.calls.split_complex_arg = NULL;
8b897cfa
RS
1477
1478 /* Initialize rs6000_cost with the appropriate target costs. */
1479 if (optimize_size)
1480 rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
1481 else
1482 switch (rs6000_cpu)
1483 {
1484 case PROCESSOR_RIOS1:
1485 rs6000_cost = &rios1_cost;
1486 break;
1487
1488 case PROCESSOR_RIOS2:
1489 rs6000_cost = &rios2_cost;
1490 break;
1491
1492 case PROCESSOR_RS64A:
1493 rs6000_cost = &rs64a_cost;
1494 break;
1495
1496 case PROCESSOR_MPCCORE:
1497 rs6000_cost = &mpccore_cost;
1498 break;
1499
1500 case PROCESSOR_PPC403:
1501 rs6000_cost = &ppc403_cost;
1502 break;
1503
1504 case PROCESSOR_PPC405:
1505 rs6000_cost = &ppc405_cost;
1506 break;
1507
1508 case PROCESSOR_PPC440:
1509 rs6000_cost = &ppc440_cost;
1510 break;
1511
1512 case PROCESSOR_PPC601:
1513 rs6000_cost = &ppc601_cost;
1514 break;
1515
1516 case PROCESSOR_PPC603:
1517 rs6000_cost = &ppc603_cost;
1518 break;
1519
1520 case PROCESSOR_PPC604:
1521 rs6000_cost = &ppc604_cost;
1522 break;
1523
1524 case PROCESSOR_PPC604e:
1525 rs6000_cost = &ppc604e_cost;
1526 break;
1527
1528 case PROCESSOR_PPC620:
8b897cfa
RS
1529 rs6000_cost = &ppc620_cost;
1530 break;
1531
f0517163
RS
1532 case PROCESSOR_PPC630:
1533 rs6000_cost = &ppc630_cost;
1534 break;
1535
8b897cfa
RS
1536 case PROCESSOR_PPC750:
1537 case PROCESSOR_PPC7400:
1538 rs6000_cost = &ppc750_cost;
1539 break;
1540
1541 case PROCESSOR_PPC7450:
1542 rs6000_cost = &ppc7450_cost;
1543 break;
1544
1545 case PROCESSOR_PPC8540:
1546 rs6000_cost = &ppc8540_cost;
1547 break;
1548
1549 case PROCESSOR_POWER4:
1550 case PROCESSOR_POWER5:
1551 rs6000_cost = &power4_cost;
1552 break;
1553
1554 default:
1555 abort ();
1556 }
5248c961 1557}
5accd822 1558
7ccf35ed
DN
1559/* Implement targetm.vectorize.builtin_mask_for_load. */
1560static tree
1561rs6000_builtin_mask_for_load (void)
1562{
1563 if (TARGET_ALTIVEC)
1564 return altivec_builtin_mask_for_load;
1565 else
1566 return 0;
1567}
1568
1569/* Implement targetm.vectorize.builtin_mask_for_store. */
1570static tree
1571rs6000_builtin_mask_for_store (void)
1572{
1573 if (TARGET_ALTIVEC)
1574 return altivec_builtin_mask_for_store;
1575 else
1576 return 0;
1577}
1578
5da702b1
AH
1579/* Handle generic options of the form -mfoo=yes/no.
1580 NAME is the option name.
1581 VALUE is the option value.
1582 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1583 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1584static void
5da702b1 1585rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1586{
5da702b1 1587 if (value == 0)
993f19a8 1588 return;
5da702b1
AH
1589 else if (!strcmp (value, "yes"))
1590 *flag = 1;
1591 else if (!strcmp (value, "no"))
1592 *flag = 0;
08b57fb3 1593 else
5da702b1 1594 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1595}
1596
0ac081f6 1597/* Handle -mabi= options. */
00b960c7 1598static void
863d938c 1599rs6000_parse_abi_options (void)
0ac081f6
AH
1600{
1601 if (rs6000_abi_string == 0)
1602 return;
1603 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1604 {
1605 rs6000_altivec_abi = 1;
1606 rs6000_spe_abi = 0;
1607 }
76a773f3
AH
1608 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1609 rs6000_altivec_abi = 0;
a3170dc6 1610 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1611 {
1612 rs6000_spe_abi = 1;
5cc73f91 1613 rs6000_altivec_abi = 0;
01f4962d
NS
1614 if (!TARGET_SPE_ABI)
1615 error ("not configured for ABI: '%s'", rs6000_abi_string);
1616 }
f676971a 1617
a3170dc6
AH
1618 else if (! strcmp (rs6000_abi_string, "no-spe"))
1619 rs6000_spe_abi = 0;
0ac081f6 1620 else
c725bd79 1621 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1622}
1623
025d9908
KH
1624/* Handle -malign-XXXXXX options. */
1625static void
863d938c 1626rs6000_parse_alignment_option (void)
025d9908 1627{
b20a9cca
AM
1628 if (rs6000_alignment_string == 0)
1629 return;
1630 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1631 rs6000_alignment_flags = MASK_ALIGN_POWER;
1632 else if (! strcmp (rs6000_alignment_string, "natural"))
1633 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1634 else
1635 error ("unknown -malign-XXXXX option specified: '%s'",
1636 rs6000_alignment_string);
1637}
1638
c4501e62
JJ
1639/* Validate and record the size specified with the -mtls-size option. */
1640
1641static void
863d938c 1642rs6000_parse_tls_size_option (void)
c4501e62
JJ
1643{
1644 if (rs6000_tls_size_string == 0)
1645 return;
1646 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1647 rs6000_tls_size = 16;
1648 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1649 rs6000_tls_size = 32;
1650 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1651 rs6000_tls_size = 64;
1652 else
1653 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1654}
1655
5accd822 1656void
a2369ed3 1657optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1658{
5accd822 1659}
3cfa4909
MM
1660\f
1661/* Do anything needed at the start of the asm file. */
1662
1bc7c5b6 1663static void
863d938c 1664rs6000_file_start (void)
3cfa4909 1665{
c4d38ccb 1666 size_t i;
3cfa4909 1667 char buffer[80];
d330fd93 1668 const char *start = buffer;
3cfa4909 1669 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1670 const char *default_cpu = TARGET_CPU_DEFAULT;
1671 FILE *file = asm_out_file;
1672
1673 default_file_start ();
1674
1675#ifdef TARGET_BI_ARCH
1676 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1677 default_cpu = 0;
1678#endif
3cfa4909
MM
1679
1680 if (flag_verbose_asm)
1681 {
1682 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1683 rs6000_select[0].string = default_cpu;
1684
b6a1cbae 1685 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1686 {
1687 ptr = &rs6000_select[i];
1688 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1689 {
1690 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1691 start = "";
1692 }
1693 }
1694
b91da81f 1695#ifdef USING_ELFOS_H
3cfa4909
MM
1696 switch (rs6000_sdata)
1697 {
1698 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1699 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1700 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1701 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1702 }
1703
1704 if (rs6000_sdata && g_switch_value)
1705 {
307b599c
MK
1706 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1707 g_switch_value);
3cfa4909
MM
1708 start = "";
1709 }
1710#endif
1711
1712 if (*start == '\0')
949ea356 1713 putc ('\n', file);
3cfa4909
MM
1714 }
1715}
5248c961 1716\f
a0ab749a 1717/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1718
1719int
863d938c 1720direct_return (void)
9878760c 1721{
4697a36c
MM
1722 if (reload_completed)
1723 {
1724 rs6000_stack_t *info = rs6000_stack_info ();
1725
1726 if (info->first_gp_reg_save == 32
1727 && info->first_fp_reg_save == 64
00b960c7 1728 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1729 && ! info->lr_save_p
1730 && ! info->cr_save_p
00b960c7 1731 && info->vrsave_mask == 0
c81fc13e 1732 && ! info->push_p)
4697a36c
MM
1733 return 1;
1734 }
1735
1736 return 0;
9878760c
RK
1737}
1738
1739/* Returns 1 always. */
1740
1741int
f676971a 1742any_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 1743 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1744{
1745 return 1;
1746}
1747
85d346f1
DE
1748/* Returns 1 always. */
1749
1750int
f676971a 1751any_parallel_operand (rtx op ATTRIBUTE_UNUSED,
85d346f1
DE
1752 enum machine_mode mode ATTRIBUTE_UNUSED)
1753{
1754 return 1;
1755}
1756
a4f6c312 1757/* Returns 1 if op is the count register. */
85d346f1 1758
38c1f2d7 1759int
a2369ed3 1760count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1761{
1762 if (GET_CODE (op) != REG)
1763 return 0;
1764
1765 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1766 return 1;
1767
1768 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1769 return 1;
1770
1771 return 0;
1772}
1773
0ec4e2a8 1774/* Returns 1 if op is an altivec register. */
85d346f1 1775
0ec4e2a8 1776int
a2369ed3 1777altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8 1778{
0ec4e2a8
AH
1779 return (register_operand (op, mode)
1780 && (GET_CODE (op) != REG
1781 || REGNO (op) > FIRST_PSEUDO_REGISTER
1782 || ALTIVEC_REGNO_P (REGNO (op))));
1783}
1784
38c1f2d7 1785int
a2369ed3 1786xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1787{
1788 if (GET_CODE (op) != REG)
1789 return 0;
1790
9ebbca7d 1791 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1792 return 1;
1793
802a0058
MM
1794 return 0;
1795}
1796
c859cda6 1797/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1798 by such constants completes more quickly. */
c859cda6
DJ
1799
1800int
a2369ed3 1801s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6 1802{
c4ad648e 1803 return (GET_CODE (op) == CONST_INT
c859cda6
DJ
1804 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1805}
1806
9878760c
RK
1807/* Return 1 if OP is a constant that can fit in a D field. */
1808
1809int
a2369ed3 1810short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1811{
5f59ecb7
DE
1812 return (GET_CODE (op) == CONST_INT
1813 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1814}
1815
5519a4f9 1816/* Similar for an unsigned D field. */
9878760c
RK
1817
1818int
a2369ed3 1819u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1820{
19684119 1821 return (GET_CODE (op) == CONST_INT
c1f11548 1822 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1823}
1824
dcfedcd0
RK
1825/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1826
1827int
a2369ed3 1828non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1829{
1830 return (GET_CODE (op) == CONST_INT
a7653a2c 1831 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1832}
1833
2bfcf297
DB
1834/* Returns 1 if OP is a CONST_INT that is a positive value
1835 and an exact power of 2. */
1836
1837int
a2369ed3 1838exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1839{
1840 return (GET_CODE (op) == CONST_INT
1841 && INTVAL (op) > 0
1842 && exact_log2 (INTVAL (op)) >= 0);
1843}
1844
9878760c
RK
1845/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1846 ctr, or lr). */
1847
1848int
a2369ed3 1849gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1850{
1851 return (register_operand (op, mode)
802a0058 1852 && (GET_CODE (op) != REG
f676971a 1853 || (REGNO (op) >= ARG_POINTER_REGNUM
9ebbca7d
GK
1854 && !XER_REGNO_P (REGNO (op)))
1855 || REGNO (op) < MQ_REGNO));
9878760c
RK
1856}
1857
1858/* Returns 1 if OP is either a pseudo-register or a register denoting a
1859 CR field. */
1860
1861int
a2369ed3 1862cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1863{
1864 return (register_operand (op, mode)
1865 && (GET_CODE (op) != REG
1866 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1867 || CR_REGNO_P (REGNO (op))));
1868}
1869
815cdc52
MM
1870/* Returns 1 if OP is either a pseudo-register or a register denoting a
1871 CR field that isn't CR0. */
1872
1873int
a2369ed3 1874cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1875{
1876 return (register_operand (op, mode)
1877 && (GET_CODE (op) != REG
1878 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1879 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1880}
1881
a4f6c312
SS
1882/* Returns 1 if OP is either a constant integer valid for a D-field or
1883 a non-special register. If a register, it must be in the proper
1884 mode unless MODE is VOIDmode. */
9878760c
RK
1885
1886int
a2369ed3 1887reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1888{
f5a28898 1889 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1890}
1891
a4f6c312 1892/* Similar, except check if the negation of the constant would be
42f806e5
AM
1893 valid for a D-field. Don't allow a constant zero, since all the
1894 patterns that call this predicate use "addic r1,r2,-constant" on
1895 a constant value to set a carry when r2 is greater or equal to
1896 "constant". That doesn't work for zero. */
9878760c
RK
1897
1898int
a2369ed3 1899reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1900{
1901 if (GET_CODE (op) == CONST_INT)
42f806e5 1902 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P') && INTVAL (op) != 0;
9878760c 1903
cd2b37d9 1904 return gpc_reg_operand (op, mode);
9878760c
RK
1905}
1906
768070a0
TR
1907/* Returns 1 if OP is either a constant integer valid for a DS-field or
1908 a non-special register. If a register, it must be in the proper
1909 mode unless MODE is VOIDmode. */
1910
1911int
a2369ed3 1912reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1913{
1914 if (gpc_reg_operand (op, mode))
1915 return 1;
1916 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1917 return 1;
1918
1919 return 0;
1920}
1921
1922
a4f6c312
SS
1923/* Return 1 if the operand is either a register or an integer whose
1924 high-order 16 bits are zero. */
9878760c
RK
1925
1926int
a2369ed3 1927reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1928{
e675f625 1929 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1930}
1931
1932/* Return 1 is the operand is either a non-special register or ANY
1933 constant integer. */
1934
1935int
a2369ed3 1936reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1937{
a4f6c312 1938 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1939}
1940
1941/* Return 1 is the operand is either a non-special register or ANY
1942 32-bit signed constant integer. */
1943
1944int
a2369ed3 1945reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1946{
a4f6c312
SS
1947 return (gpc_reg_operand (op, mode)
1948 || (GET_CODE (op) == CONST_INT
f6bf7de2 1949#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1950 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1951 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1952#endif
a4f6c312 1953 ));
9878760c
RK
1954}
1955
2bfcf297
DB
1956/* Return 1 is the operand is either a non-special register or a 32-bit
1957 signed constant integer valid for 64-bit addition. */
1958
1959int
a2369ed3 1960reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1961{
a4f6c312
SS
1962 return (gpc_reg_operand (op, mode)
1963 || (GET_CODE (op) == CONST_INT
a65c591c 1964#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1965 && INTVAL (op) < 0x7fff8000
a65c591c 1966#else
a4f6c312
SS
1967 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1968 < 0x100000000ll)
2bfcf297 1969#endif
a4f6c312 1970 ));
2bfcf297
DB
1971}
1972
1973/* Return 1 is the operand is either a non-special register or a 32-bit
1974 signed constant integer valid for 64-bit subtraction. */
1975
1976int
a2369ed3 1977reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1978{
a4f6c312
SS
1979 return (gpc_reg_operand (op, mode)
1980 || (GET_CODE (op) == CONST_INT
a65c591c 1981#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1982 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1983#else
a4f6c312
SS
1984 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1985 < 0x100000000ll)
2bfcf297 1986#endif
a4f6c312 1987 ));
2bfcf297
DB
1988}
1989
9ebbca7d
GK
1990/* Return 1 is the operand is either a non-special register or ANY
1991 32-bit unsigned constant integer. */
1992
1993int
a2369ed3 1994reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1995{
1d328b19
GK
1996 if (GET_CODE (op) == CONST_INT)
1997 {
1998 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1999 {
2000 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 2001 abort ();
1d328b19
GK
2002
2003 if (INTVAL (op) < 0)
2004 return 0;
2005 }
2006
2007 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 2008 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
2009 }
2010 else if (GET_CODE (op) == CONST_DOUBLE)
2011 {
2012 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2013 || mode != DImode)
a4f6c312 2014 abort ();
1d328b19
GK
2015
2016 return CONST_DOUBLE_HIGH (op) == 0;
2017 }
f676971a 2018 else
1d328b19 2019 return gpc_reg_operand (op, mode);
9ebbca7d
GK
2020}
2021
51d3e7d6 2022/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
2023
2024int
a2369ed3 2025got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
2026{
2027 return (GET_CODE (op) == SYMBOL_REF
2028 || GET_CODE (op) == CONST
2029 || GET_CODE (op) == LABEL_REF);
2030}
2031
38c1f2d7
MM
2032/* Return 1 if the operand is a simple references that can be loaded via
2033 the GOT (labels involving addition aren't allowed). */
2034
2035int
a2369ed3 2036got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
2037{
2038 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
2039}
2040
4e74d8ec
MM
2041/* Return the number of instructions it takes to form a constant in an
2042 integer register. */
2043
2044static int
a2369ed3 2045num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
2046{
2047 /* signed constant loadable with {cal|addi} */
5f59ecb7 2048 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
2049 return 1;
2050
4e74d8ec 2051 /* constant loadable with {cau|addis} */
5f59ecb7 2052 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
2053 return 1;
2054
5f59ecb7 2055#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 2056 else if (TARGET_POWERPC64)
4e74d8ec 2057 {
a65c591c
DE
2058 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
2059 HOST_WIDE_INT high = value >> 31;
4e74d8ec 2060
a65c591c 2061 if (high == 0 || high == -1)
4e74d8ec
MM
2062 return 2;
2063
a65c591c 2064 high >>= 1;
4e74d8ec 2065
a65c591c 2066 if (low == 0)
4e74d8ec 2067 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
2068 else
2069 return (num_insns_constant_wide (high)
e396202a 2070 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
2071 }
2072#endif
2073
2074 else
2075 return 2;
2076}
2077
2078int
a2369ed3 2079num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 2080{
4e74d8ec 2081 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
2082 {
2083#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
2084 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
2085 && mask64_operand (op, mode))
c4ad648e 2086 return 2;
0d30d435
DE
2087 else
2088#endif
2089 return num_insns_constant_wide (INTVAL (op));
2090 }
4e74d8ec 2091
6fc48950
MM
2092 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
2093 {
2094 long l;
2095 REAL_VALUE_TYPE rv;
2096
2097 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2098 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 2099 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
2100 }
2101
47ad8c61 2102 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 2103 {
47ad8c61
MM
2104 HOST_WIDE_INT low;
2105 HOST_WIDE_INT high;
2106 long l[2];
2107 REAL_VALUE_TYPE rv;
2108 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 2109
47ad8c61
MM
2110 if (mode == VOIDmode || mode == DImode)
2111 {
2112 high = CONST_DOUBLE_HIGH (op);
2113 low = CONST_DOUBLE_LOW (op);
2114 }
2115 else
2116 {
2117 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2118 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
2119 high = l[endian];
2120 low = l[1 - endian];
2121 }
4e74d8ec 2122
47ad8c61
MM
2123 if (TARGET_32BIT)
2124 return (num_insns_constant_wide (low)
2125 + num_insns_constant_wide (high));
4e74d8ec
MM
2126
2127 else
47ad8c61 2128 {
e72247f4 2129 if (high == 0 && low >= 0)
47ad8c61
MM
2130 return num_insns_constant_wide (low);
2131
e72247f4 2132 else if (high == -1 && low < 0)
47ad8c61
MM
2133 return num_insns_constant_wide (low);
2134
a260abc9
DE
2135 else if (mask64_operand (op, mode))
2136 return 2;
2137
47ad8c61
MM
2138 else if (low == 0)
2139 return num_insns_constant_wide (high) + 1;
2140
2141 else
2142 return (num_insns_constant_wide (high)
2143 + num_insns_constant_wide (low) + 1);
2144 }
4e74d8ec
MM
2145 }
2146
2147 else
2148 abort ();
2149}
2150
a4f6c312
SS
2151/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
2152 register with one instruction per word. We only do this if we can
2153 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
2154
2155int
a2369ed3 2156easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 2157{
9878760c
RK
2158 if (GET_CODE (op) != CONST_DOUBLE
2159 || GET_MODE (op) != mode
4e74d8ec 2160 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
2161 return 0;
2162
a4f6c312 2163 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
2164 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
2165 && mode != DImode)
b6c9286a
MM
2166 return 1;
2167
a4f6c312 2168 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 2169 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
2170 return 0;
2171
5ae4759c 2172#ifdef TARGET_RELOCATABLE
a4f6c312
SS
2173 /* Similarly if we are using -mrelocatable, consider all constants
2174 to be hard. */
5ae4759c
MM
2175 if (TARGET_RELOCATABLE)
2176 return 0;
2177#endif
2178
fcce224d
DE
2179 if (mode == TFmode)
2180 {
2181 long k[4];
2182 REAL_VALUE_TYPE rv;
2183
2184 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2185 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
2186
2187 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2188 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
2189 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
2190 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
2191 }
2192
2193 else if (mode == DFmode)
042259f2
DE
2194 {
2195 long k[2];
2196 REAL_VALUE_TYPE rv;
2197
2198 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2199 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 2200
a65c591c
DE
2201 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2202 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 2203 }
4e74d8ec
MM
2204
2205 else if (mode == SFmode)
042259f2
DE
2206 {
2207 long l;
2208 REAL_VALUE_TYPE rv;
2209
2210 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2211 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 2212
4e74d8ec 2213 return num_insns_constant_wide (l) == 1;
042259f2 2214 }
4e74d8ec 2215
a260abc9 2216 else if (mode == DImode)
c81fc13e 2217 return ((TARGET_POWERPC64
a260abc9
DE
2218 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
2219 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 2220
a9098fd0
GK
2221 else if (mode == SImode)
2222 return 1;
4e74d8ec
MM
2223 else
2224 abort ();
9878760c 2225}
8f75773e 2226
effa5d5d 2227/* Returns the constant for the splat instruction, if exists. */
452a7d36
HP
2228
2229static int
2230easy_vector_splat_const (int cst, enum machine_mode mode)
2231{
f676971a 2232 switch (mode)
452a7d36
HP
2233 {
2234 case V4SImode:
f676971a
EC
2235 if (EASY_VECTOR_15 (cst)
2236 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2237 return cst;
2238 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
2239 break;
2240 cst = cst >> 16;
c4ad648e
AM
2241 /* Fall thru */
2242
452a7d36 2243 case V8HImode:
f676971a
EC
2244 if (EASY_VECTOR_15 (cst)
2245 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2246 return cst;
2247 if ((cst & 0xff) != ((cst >> 8) & 0xff))
2248 break;
2249 cst = cst >> 8;
c4ad648e
AM
2250 /* Fall thru */
2251
452a7d36 2252 case V16QImode:
c4ad648e
AM
2253 if (EASY_VECTOR_15 (cst)
2254 || EASY_VECTOR_15_ADD_SELF (cst))
2255 return cst;
f676971a 2256 default:
452a7d36
HP
2257 break;
2258 }
2259 return 0;
2260}
2261
2262
72ac76be 2263/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
2264
2265static int
a2369ed3 2266easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
2267{
2268 int units, i, cst;
2269
2270 units = CONST_VECTOR_NUNITS (op);
2271
2272 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2273 for (i = 1; i < units; ++i)
2274 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
2275 break;
452a7d36 2276 if (i == units && easy_vector_splat_const (cst, mode))
d744e06e
AH
2277 return 1;
2278 return 0;
2279}
2280
2281/* Return 1 if the operand is a CONST_INT and can be put into a
2282 register without using memory. */
2283
2284int
a2369ed3 2285easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 2286{
d744e06e 2287 int cst, cst2;
69ef87e2 2288
d744e06e
AH
2289 if (GET_CODE (op) != CONST_VECTOR
2290 || (!TARGET_ALTIVEC
2291 && !TARGET_SPE))
69ef87e2
AH
2292 return 0;
2293
d744e06e
AH
2294 if (zero_constant (op, mode)
2295 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
2296 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
2297 return 1;
69ef87e2 2298
d744e06e
AH
2299 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
2300 return 0;
2301
f5119d10
AH
2302 if (TARGET_SPE && mode == V1DImode)
2303 return 0;
2304
d744e06e
AH
2305 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2306 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
2307
2308 /* Limit SPE vectors to 15 bits signed. These we can generate with:
2309 li r0, CONSTANT1
2310 evmergelo r0, r0, r0
2311 li r0, CONSTANT2
2312
2313 I don't know how efficient it would be to allow bigger constants,
2314 considering we'll have an extra 'ori' for every 'li'. I doubt 5
2315 instructions is better than a 64-bit memory load, but I don't
2316 have the e500 timing specs. */
2317 if (TARGET_SPE && mode == V2SImode
2318 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 2319 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
2320 return 1;
2321
f676971a 2322 if (TARGET_ALTIVEC
452a7d36
HP
2323 && easy_vector_same (op, mode))
2324 {
2325 cst = easy_vector_splat_const (cst, mode);
f676971a 2326 if (EASY_VECTOR_15_ADD_SELF (cst)
452a7d36
HP
2327 || EASY_VECTOR_15 (cst))
2328 return 1;
f676971a 2329 }
d744e06e
AH
2330 return 0;
2331}
2332
2333/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
2334
2335int
a2369ed3 2336easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
2337{
2338 int cst;
452a7d36
HP
2339 if (TARGET_ALTIVEC
2340 && GET_CODE (op) == CONST_VECTOR
2341 && easy_vector_same (op, mode))
2342 {
2343 cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode);
2344 if (EASY_VECTOR_15_ADD_SELF (cst))
f676971a 2345 return 1;
452a7d36
HP
2346 }
2347 return 0;
2348}
d744e06e 2349
452a7d36 2350/* Generate easy_vector_constant out of a easy_vector_constant_add_self. */
d744e06e 2351
f676971a 2352rtx
452a7d36
HP
2353gen_easy_vector_constant_add_self (rtx op)
2354{
2355 int i, units;
2356 rtvec v;
2357 units = GET_MODE_NUNITS (GET_MODE (op));
2358 v = rtvec_alloc (units);
2359
2360 for (i = 0; i < units; i++)
f676971a 2361 RTVEC_ELT (v, i) =
452a7d36
HP
2362 GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1);
2363 return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v);
d744e06e
AH
2364}
2365
2366const char *
a2369ed3 2367output_vec_const_move (rtx *operands)
d744e06e
AH
2368{
2369 int cst, cst2;
2370 enum machine_mode mode;
2371 rtx dest, vec;
2372
2373 dest = operands[0];
2374 vec = operands[1];
69ef87e2 2375
d744e06e
AH
2376 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
2377 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
2378 mode = GET_MODE (dest);
69ef87e2 2379
d744e06e
AH
2380 if (TARGET_ALTIVEC)
2381 {
2382 if (zero_constant (vec, mode))
2383 return "vxor %0,%0,%0";
ce1f50b2 2384 else if (easy_vector_constant (vec, mode))
98ef3137 2385 {
d744e06e
AH
2386 operands[1] = GEN_INT (cst);
2387 switch (mode)
2388 {
2389 case V4SImode:
452a7d36 2390 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2391 {
2392 operands[1] = GEN_INT (cst);
2393 return "vspltisw %0,%1";
2394 }
452a7d36
HP
2395 else if (EASY_VECTOR_15_ADD_SELF (cst))
2396 return "#";
ce1f50b2 2397 cst = cst >> 16;
c4ad648e
AM
2398 /* Fall thru */
2399
d744e06e 2400 case V8HImode:
452a7d36 2401 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2402 {
2403 operands[1] = GEN_INT (cst);
2404 return "vspltish %0,%1";
2405 }
452a7d36
HP
2406 else if (EASY_VECTOR_15_ADD_SELF (cst))
2407 return "#";
ce1f50b2 2408 cst = cst >> 8;
c4ad648e
AM
2409 /* Fall thru */
2410
d744e06e 2411 case V16QImode:
452a7d36 2412 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2413 {
2414 operands[1] = GEN_INT (cst);
2415 return "vspltisb %0,%1";
2416 }
452a7d36
HP
2417 else if (EASY_VECTOR_15_ADD_SELF (cst))
2418 return "#";
c4ad648e 2419
d744e06e
AH
2420 default:
2421 abort ();
2422 }
98ef3137 2423 }
d744e06e
AH
2424 else
2425 abort ();
69ef87e2
AH
2426 }
2427
d744e06e
AH
2428 if (TARGET_SPE)
2429 {
2430 /* Vector constant 0 is handled as a splitter of V2SI, and in the
2431 pattern of V1DI, V4HI, and V2SF.
2432
c1207243 2433 FIXME: We should probably return # and add post reload
c4ad648e 2434 splitters for these, but this way is so easy ;-). */
d744e06e
AH
2435 operands[1] = GEN_INT (cst);
2436 operands[2] = GEN_INT (cst2);
2437 if (cst == cst2)
2438 return "li %0,%1\n\tevmergelo %0,%0,%0";
2439 else
2440 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
2441 }
2442
2443 abort ();
69ef87e2
AH
2444}
2445
2446/* Return 1 if the operand is the constant 0. This works for scalars
2447 as well as vectors. */
2448int
a2369ed3 2449zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
2450{
2451 return op == CONST0_RTX (mode);
2452}
2453
50a0b056
GK
2454/* Return 1 if the operand is 0.0. */
2455int
a2369ed3 2456zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
2457{
2458 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
2459}
2460
a4f6c312
SS
2461/* Return 1 if the operand is in volatile memory. Note that during
2462 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
2463 volatile memory references. So this function allows us to
2464 recognize volatile references where its safe. */
2465
2466int
a2369ed3 2467volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
2468{
2469 if (GET_CODE (op) != MEM)
2470 return 0;
2471
2472 if (!MEM_VOLATILE_P (op))
2473 return 0;
2474
2475 if (mode != GET_MODE (op))
2476 return 0;
2477
2478 if (reload_completed)
2479 return memory_operand (op, mode);
2480
2481 if (reload_in_progress)
2482 return strict_memory_address_p (mode, XEXP (op, 0));
2483
2484 return memory_address_p (mode, XEXP (op, 0));
2485}
2486
97f6e72f 2487/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
2488
2489int
a2369ed3 2490offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 2491{
97f6e72f 2492 return ((GET_CODE (op) == MEM)
677a9668 2493 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 2494 mode, XEXP (op, 0)));
914c2e77
RK
2495}
2496
9878760c
RK
2497/* Return 1 if the operand is either an easy FP constant (see above) or
2498 memory. */
2499
2500int
a2369ed3 2501mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
2502{
2503 return memory_operand (op, mode) || easy_fp_constant (op, mode);
2504}
2505
2506/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 2507 that can be used as the operand of a `mode' add insn. */
9878760c
RK
2508
2509int
a2369ed3 2510add_operand (rtx op, enum machine_mode mode)
9878760c 2511{
2bfcf297 2512 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
2513 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2514 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
2515
2516 return gpc_reg_operand (op, mode);
9878760c
RK
2517}
2518
dcfedcd0
RK
2519/* Return 1 if OP is a constant but not a valid add_operand. */
2520
2521int
a2369ed3 2522non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
2523{
2524 return (GET_CODE (op) == CONST_INT
e72247f4
DE
2525 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2526 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
2527}
2528
9878760c
RK
2529/* Return 1 if the operand is a non-special register or a constant that
2530 can be used as the operand of an OR or XOR insn on the RS/6000. */
2531
2532int
a2369ed3 2533logical_operand (rtx op, enum machine_mode mode)
9878760c 2534{
40501e5f 2535 HOST_WIDE_INT opl, oph;
1d328b19 2536
dfbdccdb
GK
2537 if (gpc_reg_operand (op, mode))
2538 return 1;
1d328b19 2539
dfbdccdb 2540 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
2541 {
2542 opl = INTVAL (op) & GET_MODE_MASK (mode);
2543
2544#if HOST_BITS_PER_WIDE_INT <= 32
2545 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
2546 return 0;
2547#endif
2548 }
dfbdccdb
GK
2549 else if (GET_CODE (op) == CONST_DOUBLE)
2550 {
1d328b19 2551 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 2552 abort ();
1d328b19
GK
2553
2554 opl = CONST_DOUBLE_LOW (op);
2555 oph = CONST_DOUBLE_HIGH (op);
40501e5f 2556 if (oph != 0)
38886f37 2557 return 0;
dfbdccdb
GK
2558 }
2559 else
2560 return 0;
1d328b19 2561
40501e5f
AM
2562 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
2563 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
2564}
2565
dcfedcd0 2566/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 2567 above), but could be split into one. */
dcfedcd0
RK
2568
2569int
a2369ed3 2570non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 2571{
dfbdccdb 2572 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
2573 && ! logical_operand (op, mode)
2574 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
2575}
2576
19ba8161 2577/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
2578 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
2579 Reject all ones and all zeros, since these should have been optimized
2580 away and confuse the making of MB and ME. */
2581
2582int
a2369ed3 2583mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 2584{
02071907 2585 HOST_WIDE_INT c, lsb;
9878760c 2586
19ba8161
DE
2587 if (GET_CODE (op) != CONST_INT)
2588 return 0;
2589
2590 c = INTVAL (op);
2591
57deb3a1
AM
2592 /* Fail in 64-bit mode if the mask wraps around because the upper
2593 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
2594 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
2595 return 0;
2596
c5059423
AM
2597 /* We don't change the number of transitions by inverting,
2598 so make sure we start with the LS bit zero. */
2599 if (c & 1)
2600 c = ~c;
2601
2602 /* Reject all zeros or all ones. */
2603 if (c == 0)
9878760c
RK
2604 return 0;
2605
c5059423
AM
2606 /* Find the first transition. */
2607 lsb = c & -c;
2608
2609 /* Invert to look for a second transition. */
2610 c = ~c;
9878760c 2611
c5059423
AM
2612 /* Erase first transition. */
2613 c &= -lsb;
9878760c 2614
c5059423
AM
2615 /* Find the second transition (if any). */
2616 lsb = c & -c;
2617
2618 /* Match if all the bits above are 1's (or c is zero). */
2619 return c == -lsb;
9878760c
RK
2620}
2621
0ba1b2ff
AM
2622/* Return 1 for the PowerPC64 rlwinm corner case. */
2623
2624int
a2369ed3 2625mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2626{
2627 HOST_WIDE_INT c, lsb;
2628
2629 if (GET_CODE (op) != CONST_INT)
2630 return 0;
2631
2632 c = INTVAL (op);
2633
2634 if ((c & 0x80000001) != 0x80000001)
2635 return 0;
2636
2637 c = ~c;
2638 if (c == 0)
2639 return 0;
2640
2641 lsb = c & -c;
2642 c = ~c;
2643 c &= -lsb;
2644 lsb = c & -c;
2645 return c == -lsb;
2646}
2647
a260abc9
DE
2648/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2649 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2650 Reject all zeros, since zero should have been optimized away and
2651 confuses the making of MB and ME. */
9878760c
RK
2652
2653int
a2369ed3 2654mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2655{
2656 if (GET_CODE (op) == CONST_INT)
2657 {
02071907 2658 HOST_WIDE_INT c, lsb;
a260abc9 2659
c5059423 2660 c = INTVAL (op);
a260abc9 2661
0ba1b2ff 2662 /* Reject all zeros. */
c5059423 2663 if (c == 0)
e2c953b6
DE
2664 return 0;
2665
0ba1b2ff
AM
2666 /* We don't change the number of transitions by inverting,
2667 so make sure we start with the LS bit zero. */
2668 if (c & 1)
2669 c = ~c;
2670
c5059423
AM
2671 /* Find the transition, and check that all bits above are 1's. */
2672 lsb = c & -c;
e3981aab
DE
2673
2674 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2675 return c == -lsb;
e2c953b6 2676 }
0ba1b2ff
AM
2677 return 0;
2678}
2679
2680/* Like mask64_operand, but allow up to three transitions. This
2681 predicate is used by insn patterns that generate two rldicl or
2682 rldicr machine insns. */
2683
2684int
a2369ed3 2685mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2686{
2687 if (GET_CODE (op) == CONST_INT)
a260abc9 2688 {
0ba1b2ff 2689 HOST_WIDE_INT c, lsb;
a260abc9 2690
0ba1b2ff 2691 c = INTVAL (op);
a260abc9 2692
0ba1b2ff
AM
2693 /* Disallow all zeros. */
2694 if (c == 0)
2695 return 0;
a260abc9 2696
0ba1b2ff
AM
2697 /* We don't change the number of transitions by inverting,
2698 so make sure we start with the LS bit zero. */
2699 if (c & 1)
2700 c = ~c;
a260abc9 2701
0ba1b2ff
AM
2702 /* Find the first transition. */
2703 lsb = c & -c;
a260abc9 2704
0ba1b2ff
AM
2705 /* Invert to look for a second transition. */
2706 c = ~c;
2707
2708 /* Erase first transition. */
2709 c &= -lsb;
2710
2711 /* Find the second transition. */
2712 lsb = c & -c;
2713
2714 /* Invert to look for a third transition. */
2715 c = ~c;
2716
2717 /* Erase second transition. */
2718 c &= -lsb;
2719
2720 /* Find the third transition (if any). */
2721 lsb = c & -c;
2722
2723 /* Match if all the bits above are 1's (or c is zero). */
2724 return c == -lsb;
2725 }
2726 return 0;
2727}
2728
2729/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2730 implement ANDing by the mask IN. */
2731void
a2369ed3 2732build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2733{
2734#if HOST_BITS_PER_WIDE_INT >= 64
2735 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2736 int shift;
2737
2738 if (GET_CODE (in) != CONST_INT)
2739 abort ();
2740
2741 c = INTVAL (in);
2742 if (c & 1)
2743 {
2744 /* Assume c initially something like 0x00fff000000fffff. The idea
2745 is to rotate the word so that the middle ^^^^^^ group of zeros
2746 is at the MS end and can be cleared with an rldicl mask. We then
2747 rotate back and clear off the MS ^^ group of zeros with a
2748 second rldicl. */
2749 c = ~c; /* c == 0xff000ffffff00000 */
2750 lsb = c & -c; /* lsb == 0x0000000000100000 */
2751 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2752 c = ~c; /* c == 0x00fff000000fffff */
2753 c &= -lsb; /* c == 0x00fff00000000000 */
2754 lsb = c & -c; /* lsb == 0x0000100000000000 */
2755 c = ~c; /* c == 0xff000fffffffffff */
2756 c &= -lsb; /* c == 0xff00000000000000 */
2757 shift = 0;
2758 while ((lsb >>= 1) != 0)
2759 shift++; /* shift == 44 on exit from loop */
2760 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2761 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2762 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2763 }
2764 else
0ba1b2ff
AM
2765 {
2766 /* Assume c initially something like 0xff000f0000000000. The idea
2767 is to rotate the word so that the ^^^ middle group of zeros
2768 is at the LS end and can be cleared with an rldicr mask. We then
2769 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2770 a second rldicr. */
2771 lsb = c & -c; /* lsb == 0x0000010000000000 */
2772 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2773 c = ~c; /* c == 0x00fff0ffffffffff */
2774 c &= -lsb; /* c == 0x00fff00000000000 */
2775 lsb = c & -c; /* lsb == 0x0000100000000000 */
2776 c = ~c; /* c == 0xff000fffffffffff */
2777 c &= -lsb; /* c == 0xff00000000000000 */
2778 shift = 0;
2779 while ((lsb >>= 1) != 0)
2780 shift++; /* shift == 44 on exit from loop */
2781 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2782 m1 >>= shift; /* m1 == 0x0000000000000fff */
2783 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2784 }
2785
2786 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2787 masks will be all 1's. We are guaranteed more than one transition. */
2788 out[0] = GEN_INT (64 - shift);
2789 out[1] = GEN_INT (m1);
2790 out[2] = GEN_INT (shift);
2791 out[3] = GEN_INT (m2);
2792#else
045572c7
GK
2793 (void)in;
2794 (void)out;
0ba1b2ff
AM
2795 abort ();
2796#endif
a260abc9
DE
2797}
2798
2799/* Return 1 if the operand is either a non-special register or a constant
2800 that can be used as the operand of a PowerPC64 logical AND insn. */
2801
2802int
a2369ed3 2803and64_operand (rtx op, enum machine_mode mode)
9878760c 2804{
a4f6c312 2805 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2806 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2807
2808 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2809}
2810
0ba1b2ff
AM
2811/* Like the above, but also match constants that can be implemented
2812 with two rldicl or rldicr insns. */
2813
2814int
a2369ed3 2815and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2816{
a3c9585f 2817 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2818 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2819
2820 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2821}
2822
a260abc9
DE
2823/* Return 1 if the operand is either a non-special register or a
2824 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2825
2826int
a2369ed3 2827and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2828{
a4f6c312 2829 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2830 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2831
2832 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2833}
2834
9878760c
RK
2835/* Return 1 if the operand is a general register or memory operand. */
2836
2837int
a2369ed3 2838reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2839{
b6c9286a
MM
2840 return (gpc_reg_operand (op, mode)
2841 || memory_operand (op, mode)
4c81e946 2842 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2843 || volatile_mem_operand (op, mode));
9878760c
RK
2844}
2845
a7a813f7 2846/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2847 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2848 instruction. */
2849
2850int
a2369ed3 2851lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2852{
2853 rtx inner = op;
2854
2855 if (reload_completed && GET_CODE (inner) == SUBREG)
2856 inner = SUBREG_REG (inner);
f676971a 2857
a7a813f7
RK
2858 return gpc_reg_operand (inner, mode)
2859 || (memory_operand (inner, mode)
2860 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2861 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2862 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2863 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2864 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2865}
2866
cc4d5fec
JH
2867/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2868
2869int
a2369ed3 2870symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2871{
2872 if (mode != VOIDmode && GET_MODE (op) != mode)
2873 return 0;
2874
473f51b6
DE
2875 return (GET_CODE (op) == SYMBOL_REF
2876 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2877}
2878
9878760c 2879/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2880 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2881
2882int
a2369ed3 2883call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2884{
2885 if (mode != VOIDmode && GET_MODE (op) != mode)
2886 return 0;
2887
2888 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2889 || (GET_CODE (op) == REG
2890 && (REGNO (op) == LINK_REGISTER_REGNUM
2891 || REGNO (op) == COUNT_REGISTER_REGNUM
2892 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2893}
2894
2af3d377 2895/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2896 this file. */
2af3d377
RK
2897
2898int
f676971a 2899current_file_function_operand (rtx op,
c4ad648e 2900 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2901{
473f51b6
DE
2902 return (GET_CODE (op) == SYMBOL_REF
2903 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2904 && (SYMBOL_REF_LOCAL_P (op)
2905 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2906}
2907
9878760c
RK
2908/* Return 1 if this operand is a valid input for a move insn. */
2909
2910int
a2369ed3 2911input_operand (rtx op, enum machine_mode mode)
9878760c 2912{
eb4e8003 2913 /* Memory is always valid. */
9878760c
RK
2914 if (memory_operand (op, mode))
2915 return 1;
2916
eb4e8003
RK
2917 /* For floating-point, easy constants are valid. */
2918 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2919 && CONSTANT_P (op)
2920 && easy_fp_constant (op, mode))
2921 return 1;
2922
4e74d8ec
MM
2923 /* Allow any integer constant. */
2924 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2925 && (GET_CODE (op) == CONST_INT
e675f625 2926 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2927 return 1;
2928
d744e06e
AH
2929 /* Allow easy vector constants. */
2930 if (GET_CODE (op) == CONST_VECTOR
2931 && easy_vector_constant (op, mode))
2932 return 1;
2933
eb4e8003
RK
2934 /* For floating-point or multi-word mode, the only remaining valid type
2935 is a register. */
9878760c
RK
2936 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2937 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2938 return register_operand (op, mode);
9878760c 2939
88fe15a1
RK
2940 /* The only cases left are integral modes one word or smaller (we
2941 do not get called for MODE_CC values). These can be in any
2942 register. */
2943 if (register_operand (op, mode))
a8b3aeda 2944 return 1;
88fe15a1 2945
84cf9dda 2946 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2947 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2948 return 1;
2949
9ebbca7d 2950 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2951 if (toc_relative_expr_p (op))
b6c9286a
MM
2952 return 1;
2953
88228c4b
MM
2954 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2955 to be valid. */
f607bc57 2956 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2957 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2958 && small_data_operand (op, Pmode))
2959 return 1;
2960
042259f2 2961 return 0;
9878760c 2962}
7509c759 2963
95727fb8
AP
2964
2965/* Darwin, AIX increases natural record alignment to doubleword if the first
2966 field is an FP double while the FP fields remain word aligned. */
2967
19d66194 2968unsigned int
95727fb8
AP
2969rs6000_special_round_type_align (tree type, int computed, int specified)
2970{
2971 tree field = TYPE_FIELDS (type);
95727fb8
AP
2972
2973 /* Skip all the static variables only if ABI is greater than
71cc389b 2974 1 or equal to 0. */
3ce5437a 2975 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2976 field = TREE_CHAIN (field);
2977
3ce5437a 2978 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2979 return MAX (computed, specified);
2980
2981 return MAX (MAX (computed, specified), 64);
2982}
2983
a4f6c312 2984/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2985
2986int
f676971a 2987small_data_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 2988 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2989{
38c1f2d7 2990#if TARGET_ELF
5f59ecb7 2991 rtx sym_ref;
7509c759 2992
d9407988 2993 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2994 return 0;
a54d04b7 2995
f607bc57 2996 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2997 return 0;
2998
88228c4b
MM
2999 if (GET_CODE (op) == SYMBOL_REF)
3000 sym_ref = op;
3001
3002 else if (GET_CODE (op) != CONST
3003 || GET_CODE (XEXP (op, 0)) != PLUS
3004 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
3005 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
3006 return 0;
3007
88228c4b 3008 else
dbf55e53
MM
3009 {
3010 rtx sum = XEXP (op, 0);
3011 HOST_WIDE_INT summand;
3012
3013 /* We have to be careful here, because it is the referenced address
c4ad648e 3014 that must be 32k from _SDA_BASE_, not just the symbol. */
dbf55e53 3015 summand = INTVAL (XEXP (sum, 1));
307b599c 3016 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
3017 return 0;
3018
3019 sym_ref = XEXP (sum, 0);
3020 }
88228c4b 3021
20bfcd69 3022 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
3023#else
3024 return 0;
3025#endif
7509c759 3026}
46c07df8 3027
d2288d5d
HP
3028/* Return true, if operand is a memory operand and has a
3029 displacement divisible by 4. */
3030
3031int
3032word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3033{
3034 rtx addr;
3035 int off = 0;
3036
3037 if (!memory_operand (op, mode))
3038 return 0;
3039
3040 addr = XEXP (op, 0);
3041 if (GET_CODE (addr) == PLUS
3042 && GET_CODE (XEXP (addr, 0)) == REG
3043 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
3044 off = INTVAL (XEXP (addr, 1));
3045
3046 return (off % 4) == 0;
3047}
3048
3a1f863f 3049/* Return true if either operand is a general purpose register. */
46c07df8 3050
3a1f863f
DE
3051bool
3052gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 3053{
3a1f863f
DE
3054 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
3055 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
3056}
3057
9ebbca7d 3058\f
4d588c14
RH
3059/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
3060
f676971a
EC
3061static int
3062constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d 3063{
f676971a 3064 switch (GET_CODE(op))
9ebbca7d
GK
3065 {
3066 case SYMBOL_REF:
c4501e62
JJ
3067 if (RS6000_SYMBOL_REF_TLS_P (op))
3068 return 0;
3069 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
3070 {
3071 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
3072 {
3073 *have_sym = 1;
3074 return 1;
3075 }
3076 else
3077 return 0;
3078 }
3079 else if (! strcmp (XSTR (op, 0), toc_label_name))
3080 {
3081 *have_toc = 1;
3082 return 1;
3083 }
3084 else
3085 return 0;
9ebbca7d
GK
3086 case PLUS:
3087 case MINUS:
c1f11548
DE
3088 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
3089 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 3090 case CONST:
a4f6c312 3091 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 3092 case CONST_INT:
a4f6c312 3093 return 1;
9ebbca7d 3094 default:
a4f6c312 3095 return 0;
9ebbca7d
GK
3096 }
3097}
3098
4d588c14 3099static bool
a2369ed3 3100constant_pool_expr_p (rtx op)
9ebbca7d
GK
3101{
3102 int have_sym = 0;
3103 int have_toc = 0;
3104 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
3105}
3106
4d588c14 3107static bool
a2369ed3 3108toc_relative_expr_p (rtx op)
9ebbca7d 3109{
4d588c14
RH
3110 int have_sym = 0;
3111 int have_toc = 0;
3112 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
3113}
3114
4d588c14 3115bool
a2369ed3 3116legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
3117{
3118 return (TARGET_TOC
3119 && GET_CODE (x) == PLUS
3120 && GET_CODE (XEXP (x, 0)) == REG
3121 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
3122 && constant_pool_expr_p (XEXP (x, 1)));
3123}
3124
3125static bool
a2369ed3 3126legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
3127{
3128 return (DEFAULT_ABI == ABI_V4
3129 && !flag_pic && !TARGET_TOC
3130 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
3131 && small_data_operand (x, mode));
3132}
3133
60cdabab
DE
3134/* SPE offset addressing is limited to 5-bits worth of double words. */
3135#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
3136
76d2b81d
DJ
3137bool
3138rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3139{
3140 unsigned HOST_WIDE_INT offset, extra;
3141
3142 if (GET_CODE (x) != PLUS)
3143 return false;
3144 if (GET_CODE (XEXP (x, 0)) != REG)
3145 return false;
3146 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3147 return false;
60cdabab
DE
3148 if (legitimate_constant_pool_address_p (x))
3149 return true;
4d588c14
RH
3150 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3151 return false;
3152
3153 offset = INTVAL (XEXP (x, 1));
3154 extra = 0;
3155 switch (mode)
3156 {
3157 case V16QImode:
3158 case V8HImode:
3159 case V4SFmode:
3160 case V4SImode:
3161 /* AltiVec vector modes. Only reg+reg addressing is valid here,
3162 which leaves the only valid constant offset of zero, which by
3163 canonicalization rules is also invalid. */
3164 return false;
3165
3166 case V4HImode:
3167 case V2SImode:
3168 case V1DImode:
3169 case V2SFmode:
3170 /* SPE vector modes. */
3171 return SPE_CONST_OFFSET_OK (offset);
3172
3173 case DFmode:
3174 case DImode:
3364872d 3175 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
3176 extra = 4;
3177 else if (offset & 3)
3178 return false;
3179 break;
3180
3181 case TFmode:
3182 case TImode:
3364872d 3183 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
3184 extra = 12;
3185 else if (offset & 3)
3186 return false;
3187 else
3188 extra = 8;
3189 break;
3190
3191 default:
3192 break;
3193 }
3194
b1917422
AM
3195 offset += 0x8000;
3196 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
3197}
3198
3199static bool
a2369ed3 3200legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
3201{
3202 rtx op0, op1;
3203
3204 if (GET_CODE (x) != PLUS)
3205 return false;
850e8d3d 3206
4d588c14
RH
3207 op0 = XEXP (x, 0);
3208 op1 = XEXP (x, 1);
3209
3210 if (!REG_P (op0) || !REG_P (op1))
3211 return false;
3212
3213 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
3214 && INT_REG_OK_FOR_INDEX_P (op1, strict))
3215 || (INT_REG_OK_FOR_BASE_P (op1, strict)
3216 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
3217}
3218
4d588c14 3219static inline bool
a2369ed3 3220legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
3221{
3222 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
3223}
3224
4c81e946
FJ
3225static bool
3226macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
3227{
c4ad648e
AM
3228 if (!TARGET_MACHO || !flag_pic
3229 || mode != SImode || GET_CODE(x) != MEM)
3230 return false;
3231 x = XEXP (x, 0);
4c81e946
FJ
3232
3233 if (GET_CODE (x) != LO_SUM)
3234 return false;
3235 if (GET_CODE (XEXP (x, 0)) != REG)
3236 return false;
3237 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
3238 return false;
3239 x = XEXP (x, 1);
3240
3241 return CONSTANT_P (x);
3242}
3243
4d588c14 3244static bool
a2369ed3 3245legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3246{
3247 if (GET_CODE (x) != LO_SUM)
3248 return false;
3249 if (GET_CODE (XEXP (x, 0)) != REG)
3250 return false;
3251 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3252 return false;
3253 x = XEXP (x, 1);
3254
8622e235 3255 if (TARGET_ELF || TARGET_MACHO)
4d588c14 3256 {
a29077da 3257 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
3258 return false;
3259 if (TARGET_TOC)
3260 return false;
3261 if (GET_MODE_NUNITS (mode) != 1)
3262 return false;
c1e55850 3263 if (GET_MODE_BITSIZE (mode) > 64)
4d588c14
RH
3264 return false;
3265
3266 return CONSTANT_P (x);
3267 }
3268
3269 return false;
3270}
3271
3272
9ebbca7d
GK
3273/* Try machine-dependent ways of modifying an illegitimate address
3274 to be legitimate. If we find one, return the new, valid address.
3275 This is used from only one place: `memory_address' in explow.c.
3276
a4f6c312
SS
3277 OLDX is the address as it was before break_out_memory_refs was
3278 called. In some cases it is useful to look at this to decide what
3279 needs to be done.
9ebbca7d 3280
a4f6c312 3281 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 3282
a4f6c312
SS
3283 It is always safe for this function to do nothing. It exists to
3284 recognize opportunities to optimize the output.
9ebbca7d
GK
3285
3286 On RS/6000, first check for the sum of a register with a constant
3287 integer that is out of range. If so, generate code to add the
3288 constant with the low-order 16 bits masked to the register and force
3289 this result into another register (this can be done with `cau').
3290 Then generate an address of REG+(CONST&0xffff), allowing for the
3291 possibility of bit 16 being a one.
3292
3293 Then check for the sum of a register and something not constant, try to
3294 load the other things into a register and return the sum. */
4d588c14 3295
9ebbca7d 3296rtx
a2369ed3
DJ
3297rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3298 enum machine_mode mode)
0ac081f6 3299{
c4501e62
JJ
3300 if (GET_CODE (x) == SYMBOL_REF)
3301 {
3302 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
3303 if (model != 0)
3304 return rs6000_legitimize_tls_address (x, model);
3305 }
3306
f676971a 3307 if (GET_CODE (x) == PLUS
9ebbca7d
GK
3308 && GET_CODE (XEXP (x, 0)) == REG
3309 && GET_CODE (XEXP (x, 1)) == CONST_INT
3310 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
f676971a 3311 {
9ebbca7d
GK
3312 HOST_WIDE_INT high_int, low_int;
3313 rtx sum;
a65c591c
DE
3314 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
3315 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
3316 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
3317 GEN_INT (high_int)), 0);
3318 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
3319 }
f676971a 3320 else if (GET_CODE (x) == PLUS
9ebbca7d
GK
3321 && GET_CODE (XEXP (x, 0)) == REG
3322 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 3323 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
3324 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3325 || TARGET_POWERPC64
fcce224d 3326 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
3327 && (TARGET_POWERPC64 || mode != DImode)
3328 && mode != TImode)
3329 {
3330 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
3331 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
3332 }
0ac081f6
AH
3333 else if (ALTIVEC_VECTOR_MODE (mode))
3334 {
3335 rtx reg;
3336
3337 /* Make sure both operands are registers. */
3338 if (GET_CODE (x) == PLUS)
9f85ed45 3339 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
3340 force_reg (Pmode, XEXP (x, 1)));
3341
3342 reg = force_reg (Pmode, x);
3343 return reg;
3344 }
a3170dc6
AH
3345 else if (SPE_VECTOR_MODE (mode))
3346 {
3347 /* We accept [reg + reg] and [reg + OFFSET]. */
3348
3349 if (GET_CODE (x) == PLUS)
c4ad648e
AM
3350 {
3351 rtx op1 = XEXP (x, 0);
3352 rtx op2 = XEXP (x, 1);
a3170dc6 3353
c4ad648e 3354 op1 = force_reg (Pmode, op1);
a3170dc6 3355
c4ad648e
AM
3356 if (GET_CODE (op2) != REG
3357 && (GET_CODE (op2) != CONST_INT
3358 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
3359 op2 = force_reg (Pmode, op2);
a3170dc6 3360
c4ad648e
AM
3361 return gen_rtx_PLUS (Pmode, op1, op2);
3362 }
a3170dc6
AH
3363
3364 return force_reg (Pmode, x);
3365 }
f1384257
AM
3366 else if (TARGET_ELF
3367 && TARGET_32BIT
3368 && TARGET_NO_TOC
3369 && ! flag_pic
9ebbca7d 3370 && GET_CODE (x) != CONST_INT
f676971a 3371 && GET_CODE (x) != CONST_DOUBLE
9ebbca7d 3372 && CONSTANT_P (x)
6ac7bf2c
GK
3373 && GET_MODE_NUNITS (mode) == 1
3374 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 3375 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
3376 {
3377 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3378 emit_insn (gen_elf_high (reg, x));
3379 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 3380 }
ee890fe2
SS
3381 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
3382 && ! flag_pic
ab82a49f
AP
3383#if TARGET_MACHO
3384 && ! MACHO_DYNAMIC_NO_PIC_P
3385#endif
ee890fe2 3386 && GET_CODE (x) != CONST_INT
f676971a 3387 && GET_CODE (x) != CONST_DOUBLE
ee890fe2 3388 && CONSTANT_P (x)
a3170dc6 3389 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
f676971a 3390 && mode != DImode
ee890fe2
SS
3391 && mode != TImode)
3392 {
3393 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3394 emit_insn (gen_macho_high (reg, x));
3395 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 3396 }
f676971a 3397 else if (TARGET_TOC
4d588c14 3398 && constant_pool_expr_p (x)
a9098fd0 3399 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
3400 {
3401 return create_TOC_reference (x);
3402 }
3403 else
3404 return NULL_RTX;
3405}
258bfae2 3406
c973d557
JJ
3407/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
3408 We need to emit DTP-relative relocations. */
3409
3410void
3411rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
3412{
3413 switch (size)
3414 {
3415 case 4:
3416 fputs ("\t.long\t", file);
3417 break;
3418 case 8:
3419 fputs (DOUBLE_INT_ASM_OP, file);
3420 break;
3421 default:
3422 abort ();
3423 }
3424 output_addr_const (file, x);
3425 fputs ("@dtprel+0x8000", file);
3426}
3427
c4501e62
JJ
3428/* Construct the SYMBOL_REF for the tls_get_addr function. */
3429
3430static GTY(()) rtx rs6000_tls_symbol;
3431static rtx
863d938c 3432rs6000_tls_get_addr (void)
c4501e62
JJ
3433{
3434 if (!rs6000_tls_symbol)
3435 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
3436
3437 return rs6000_tls_symbol;
3438}
3439
3440/* Construct the SYMBOL_REF for TLS GOT references. */
3441
3442static GTY(()) rtx rs6000_got_symbol;
3443static rtx
863d938c 3444rs6000_got_sym (void)
c4501e62
JJ
3445{
3446 if (!rs6000_got_symbol)
3447 {
3448 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3449 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
3450 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
f676971a 3451 }
c4501e62
JJ
3452
3453 return rs6000_got_symbol;
3454}
3455
3456/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3457 this (thread-local) address. */
3458
3459static rtx
a2369ed3 3460rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
3461{
3462 rtx dest, insn;
3463
3464 dest = gen_reg_rtx (Pmode);
3465 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
3466 {
3467 rtx tlsreg;
3468
3469 if (TARGET_64BIT)
3470 {
3471 tlsreg = gen_rtx_REG (Pmode, 13);
3472 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
3473 }
3474 else
3475 {
3476 tlsreg = gen_rtx_REG (Pmode, 2);
3477 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
3478 }
3479 emit_insn (insn);
3480 }
3481 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
3482 {
3483 rtx tlsreg, tmp;
3484
3485 tmp = gen_reg_rtx (Pmode);
3486 if (TARGET_64BIT)
3487 {
3488 tlsreg = gen_rtx_REG (Pmode, 13);
3489 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
3490 }
3491 else
3492 {
3493 tlsreg = gen_rtx_REG (Pmode, 2);
3494 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
3495 }
3496 emit_insn (insn);
3497 if (TARGET_64BIT)
3498 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3499 else
3500 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3501 emit_insn (insn);
3502 }
3503 else
3504 {
3505 rtx r3, got, tga, tmp1, tmp2, eqv;
3506
3507 if (TARGET_64BIT)
3508 got = gen_rtx_REG (Pmode, TOC_REGISTER);
3509 else
3510 {
3511 if (flag_pic == 1)
3512 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3513 else
3514 {
3515 rtx gsym = rs6000_got_sym ();
3516 got = gen_reg_rtx (Pmode);
3517 if (flag_pic == 0)
3518 rs6000_emit_move (got, gsym, Pmode);
3519 else
3520 {
3521 char buf[30];
3522 static int tls_got_labelno = 0;
3523 rtx tempLR, lab, tmp3, mem;
3524 rtx first, last;
3525
3526 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
3527 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
3528 tempLR = gen_reg_rtx (Pmode);
3529 tmp1 = gen_reg_rtx (Pmode);
3530 tmp2 = gen_reg_rtx (Pmode);
3531 tmp3 = gen_reg_rtx (Pmode);
542a8afa 3532 mem = gen_const_mem (Pmode, tmp1);
c4501e62
JJ
3533
3534 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
3535 gsym));
3536 emit_move_insn (tmp1, tempLR);
3537 emit_move_insn (tmp2, mem);
3538 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
3539 last = emit_move_insn (got, tmp3);
3540 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
3541 REG_NOTES (last));
3542 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3543 REG_NOTES (first));
3544 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3545 REG_NOTES (last));
3546 }
3547 }
3548 }
3549
3550 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3551 {
3552 r3 = gen_rtx_REG (Pmode, 3);
3553 if (TARGET_64BIT)
3554 insn = gen_tls_gd_64 (r3, got, addr);
3555 else
3556 insn = gen_tls_gd_32 (r3, got, addr);
3557 start_sequence ();
3558 emit_insn (insn);
3559 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3560 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3561 insn = emit_call_insn (insn);
3562 CONST_OR_PURE_CALL_P (insn) = 1;
3563 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3564 insn = get_insns ();
3565 end_sequence ();
3566 emit_libcall_block (insn, dest, r3, addr);
3567 }
3568 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3569 {
3570 r3 = gen_rtx_REG (Pmode, 3);
3571 if (TARGET_64BIT)
3572 insn = gen_tls_ld_64 (r3, got);
3573 else
3574 insn = gen_tls_ld_32 (r3, got);
3575 start_sequence ();
3576 emit_insn (insn);
3577 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3578 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3579 insn = emit_call_insn (insn);
3580 CONST_OR_PURE_CALL_P (insn) = 1;
3581 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3582 insn = get_insns ();
3583 end_sequence ();
3584 tmp1 = gen_reg_rtx (Pmode);
3585 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3586 UNSPEC_TLSLD);
3587 emit_libcall_block (insn, tmp1, r3, eqv);
3588 if (rs6000_tls_size == 16)
3589 {
3590 if (TARGET_64BIT)
3591 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3592 else
3593 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3594 }
3595 else if (rs6000_tls_size == 32)
3596 {
3597 tmp2 = gen_reg_rtx (Pmode);
3598 if (TARGET_64BIT)
3599 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3600 else
3601 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3602 emit_insn (insn);
3603 if (TARGET_64BIT)
3604 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3605 else
3606 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3607 }
3608 else
3609 {
3610 tmp2 = gen_reg_rtx (Pmode);
3611 if (TARGET_64BIT)
3612 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3613 else
3614 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3615 emit_insn (insn);
3616 insn = gen_rtx_SET (Pmode, dest,
3617 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3618 }
3619 emit_insn (insn);
3620 }
3621 else
3622 {
3623 /* IE, or 64 bit offset LE. */
3624 tmp2 = gen_reg_rtx (Pmode);
3625 if (TARGET_64BIT)
3626 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3627 else
3628 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3629 emit_insn (insn);
3630 if (TARGET_64BIT)
3631 insn = gen_tls_tls_64 (dest, tmp2, addr);
3632 else
3633 insn = gen_tls_tls_32 (dest, tmp2, addr);
3634 emit_insn (insn);
3635 }
3636 }
3637
3638 return dest;
3639}
3640
3641/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3642 instruction definitions. */
3643
3644int
a2369ed3 3645rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3646{
3647 return RS6000_SYMBOL_REF_TLS_P (x);
3648}
3649
3650/* Return 1 if X contains a thread-local symbol. */
3651
3652bool
a2369ed3 3653rs6000_tls_referenced_p (rtx x)
c4501e62 3654{
cd413cab
AP
3655 if (! TARGET_HAVE_TLS)
3656 return false;
3657
c4501e62
JJ
3658 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3659}
3660
3661/* Return 1 if *X is a thread-local symbol. This is the same as
3662 rs6000_tls_symbol_ref except for the type of the unused argument. */
3663
3664static inline int
a2369ed3 3665rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3666{
3667 return RS6000_SYMBOL_REF_TLS_P (*x);
3668}
3669
24ea750e
DJ
3670/* The convention appears to be to define this wherever it is used.
3671 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3672 is now used here. */
3673#ifndef REG_MODE_OK_FOR_BASE_P
3674#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3675#endif
3676
3677/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3678 replace the input X, or the original X if no replacement is called for.
3679 The output parameter *WIN is 1 if the calling macro should goto WIN,
3680 0 if it should not.
3681
3682 For RS/6000, we wish to handle large displacements off a base
3683 register by splitting the addend across an addiu/addis and the mem insn.
3684 This cuts number of extra insns needed from 3 to 1.
3685
3686 On Darwin, we use this to generate code for floating point constants.
3687 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3688 The Darwin code is inside #if TARGET_MACHO because only then is
3689 machopic_function_base_name() defined. */
3690rtx
f676971a 3691rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
c4ad648e
AM
3692 int opnum, int type,
3693 int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e 3694{
f676971a 3695 /* We must recognize output that we have already generated ourselves. */
24ea750e
DJ
3696 if (GET_CODE (x) == PLUS
3697 && GET_CODE (XEXP (x, 0)) == PLUS
3698 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3699 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3700 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3701 {
3702 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3703 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3704 opnum, (enum reload_type)type);
24ea750e
DJ
3705 *win = 1;
3706 return x;
3707 }
3deb2758 3708
24ea750e
DJ
3709#if TARGET_MACHO
3710 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3711 && GET_CODE (x) == LO_SUM
3712 && GET_CODE (XEXP (x, 0)) == PLUS
3713 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3714 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3715 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3716 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3717 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3718 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3719 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3720 {
3721 /* Result of previous invocation of this function on Darwin
6f317ef3 3722 floating point constant. */
24ea750e 3723 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3724 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3725 opnum, (enum reload_type)type);
24ea750e
DJ
3726 *win = 1;
3727 return x;
3728 }
3729#endif
3730 if (GET_CODE (x) == PLUS
3731 && GET_CODE (XEXP (x, 0)) == REG
3732 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3733 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3734 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3735 && !SPE_VECTOR_MODE (mode)
78c875e8 3736 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3737 {
3738 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3739 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3740 HOST_WIDE_INT high
c4ad648e 3741 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
24ea750e
DJ
3742
3743 /* Check for 32-bit overflow. */
3744 if (high + low != val)
c4ad648e 3745 {
24ea750e
DJ
3746 *win = 0;
3747 return x;
3748 }
3749
3750 /* Reload the high part into a base reg; leave the low part
c4ad648e 3751 in the mem directly. */
24ea750e
DJ
3752
3753 x = gen_rtx_PLUS (GET_MODE (x),
c4ad648e
AM
3754 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3755 GEN_INT (high)),
3756 GEN_INT (low));
24ea750e
DJ
3757
3758 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3759 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3760 opnum, (enum reload_type)type);
24ea750e
DJ
3761 *win = 1;
3762 return x;
3763 }
3764#if TARGET_MACHO
3765 if (GET_CODE (x) == SYMBOL_REF
3766 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3767 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3768 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3769 /* Don't do this for TFmode, since the result isn't offsettable. */
3770 && mode != TFmode)
24ea750e 3771 {
a29077da
GK
3772 if (flag_pic)
3773 {
3774 rtx offset = gen_rtx_CONST (Pmode,
3775 gen_rtx_MINUS (Pmode, x,
11abc112 3776 machopic_function_base_sym ()));
a29077da
GK
3777 x = gen_rtx_LO_SUM (GET_MODE (x),
3778 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3779 gen_rtx_HIGH (Pmode, offset)), offset);
3780 }
3781 else
3782 x = gen_rtx_LO_SUM (GET_MODE (x),
c4ad648e 3783 gen_rtx_HIGH (Pmode, x), x);
a29077da 3784
24ea750e 3785 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3786 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3787 opnum, (enum reload_type)type);
24ea750e
DJ
3788 *win = 1;
3789 return x;
3790 }
3791#endif
3792 if (TARGET_TOC
4d588c14 3793 && constant_pool_expr_p (x)
c1f11548 3794 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3795 {
3796 (x) = create_TOC_reference (x);
3797 *win = 1;
3798 return x;
3799 }
3800 *win = 0;
3801 return x;
f676971a 3802}
24ea750e 3803
258bfae2
FS
3804/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3805 that is a valid memory address for an instruction.
3806 The MODE argument is the machine mode for the MEM expression
3807 that wants to use this address.
3808
3809 On the RS/6000, there are four valid address: a SYMBOL_REF that
3810 refers to a constant pool entry of an address (or the sum of it
3811 plus a constant), a short (16-bit signed) constant plus a register,
3812 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3813 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3814 we must ensure that both words are addressable or PowerPC64 with offset
3815 word aligned.
3816
3817 For modes spanning multiple registers (DFmode in 32-bit GPRs,
76d2b81d 3818 32-bit DImode, TImode, TFmode), indexed addressing cannot be used because
258bfae2
FS
3819 adjacent memory cells are accessed by adding word-sized offsets
3820 during assembly output. */
3821int
a2369ed3 3822rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3823{
850e8d3d
DN
3824 /* If this is an unaligned stvx/ldvx type address, discard the outer AND. */
3825 if (TARGET_ALTIVEC
3826 && ALTIVEC_VECTOR_MODE (mode)
3827 && GET_CODE (x) == AND
3828 && GET_CODE (XEXP (x, 1)) == CONST_INT
3829 && INTVAL (XEXP (x, 1)) == -16)
3830 x = XEXP (x, 0);
3831
c4501e62
JJ
3832 if (RS6000_SYMBOL_REF_TLS_P (x))
3833 return 0;
4d588c14 3834 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3835 return 1;
3836 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3837 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3838 && !SPE_VECTOR_MODE (mode)
258bfae2 3839 && TARGET_UPDATE
4d588c14 3840 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3841 return 1;
4d588c14 3842 if (legitimate_small_data_p (mode, x))
258bfae2 3843 return 1;
4d588c14 3844 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3845 return 1;
3846 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3847 if (! reg_ok_strict
3848 && GET_CODE (x) == PLUS
3849 && GET_CODE (XEXP (x, 0)) == REG
708d2456 3850 && (XEXP (x, 0) == virtual_stack_vars_rtx
c4ad648e 3851 || XEXP (x, 0) == arg_pointer_rtx)
258bfae2
FS
3852 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3853 return 1;
76d2b81d 3854 if (rs6000_legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3855 return 1;
3856 if (mode != TImode
76d2b81d 3857 && mode != TFmode
a3170dc6
AH
3858 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3859 || TARGET_POWERPC64
fcce224d 3860 || (mode != DFmode && mode != TFmode))
258bfae2 3861 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3862 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3863 return 1;
4d588c14 3864 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3865 return 1;
3866 return 0;
3867}
4d588c14
RH
3868
3869/* Go to LABEL if ADDR (a legitimate address expression)
3870 has an effect that depends on the machine mode it is used for.
3871
3872 On the RS/6000 this is true of all integral offsets (since AltiVec
3873 modes don't allow them) or is a pre-increment or decrement.
3874
3875 ??? Except that due to conceptual problems in offsettable_address_p
3876 we can't really report the problems of integral offsets. So leave
f676971a 3877 this assuming that the adjustable offset must be valid for the
4d588c14
RH
3878 sub-words of a TFmode operand, which is what we had before. */
3879
3880bool
a2369ed3 3881rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3882{
3883 switch (GET_CODE (addr))
3884 {
3885 case PLUS:
3886 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3887 {
3888 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3889 return val + 12 + 0x8000 >= 0x10000;
3890 }
3891 break;
3892
3893 case LO_SUM:
3894 return true;
3895
3896 case PRE_INC:
3897 case PRE_DEC:
3898 return TARGET_UPDATE;
3899
3900 default:
3901 break;
3902 }
3903
3904 return false;
3905}
d8ecbcdb
AH
3906
3907/* Return number of consecutive hard regs needed starting at reg REGNO
3908 to hold something of mode MODE.
3909 This is ordinarily the length in words of a value of mode MODE
3910 but can be less for certain modes in special long registers.
3911
3912 For the SPE, GPRs are 64 bits but only 32 bits are visible in
3913 scalar instructions. The upper 32 bits are only available to the
3914 SIMD instructions.
3915
3916 POWER and PowerPC GPRs hold 32 bits worth;
3917 PowerPC64 GPRs and FPRs point register holds 64 bits worth. */
3918
3919int
3920rs6000_hard_regno_nregs (int regno, enum machine_mode mode)
3921{
3922 if (FP_REGNO_P (regno))
3923 return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD;
3924
3925 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
3926 return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD;
3927
3928 if (ALTIVEC_REGNO_P (regno))
3929 return
3930 (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD;
3931
3932 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3933}
2aa4498c
AH
3934
3935/* Change register usage conditional on target flags. */
3936void
3937rs6000_conditional_register_usage (void)
3938{
3939 int i;
3940
3941 /* Set MQ register fixed (already call_used) if not POWER
3942 architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not
3943 be allocated. */
3944 if (! TARGET_POWER)
3945 fixed_regs[64] = 1;
3946
3947 /* 64-bit AIX reserves GPR13 for thread-private data. */
3948 if (TARGET_64BIT)
3949 fixed_regs[13] = call_used_regs[13]
3950 = call_really_used_regs[13] = 1;
3951
3952 /* Conditionally disable FPRs. */
3953 if (TARGET_SOFT_FLOAT || !TARGET_FPRS)
3954 for (i = 32; i < 64; i++)
3955 fixed_regs[i] = call_used_regs[i]
c4ad648e 3956 = call_really_used_regs[i] = 1;
2aa4498c
AH
3957
3958 if (DEFAULT_ABI == ABI_V4
3959 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3960 && flag_pic == 2)
3961 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3962
3963 if (DEFAULT_ABI == ABI_V4
3964 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3965 && flag_pic == 1)
3966 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3967 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3968 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3969
3970 if (DEFAULT_ABI == ABI_DARWIN
3971 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
3972 global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3973 = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3974 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3975 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3976
b4db40bf
JJ
3977 if (TARGET_TOC && TARGET_MINIMAL_TOC)
3978 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3979 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3980
2aa4498c
AH
3981 if (TARGET_ALTIVEC)
3982 global_regs[VSCR_REGNO] = 1;
3983
3984 if (TARGET_SPE)
3985 {
3986 global_regs[SPEFSCR_REGNO] = 1;
3987 fixed_regs[FIXED_SCRATCH]
c4ad648e 3988 = call_used_regs[FIXED_SCRATCH]
2aa4498c
AH
3989 = call_really_used_regs[FIXED_SCRATCH] = 1;
3990 }
3991
3992 if (! TARGET_ALTIVEC)
3993 {
3994 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
3995 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
3996 call_really_used_regs[VRSAVE_REGNO] = 1;
3997 }
3998
3999 if (TARGET_ALTIVEC_ABI)
4000 for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i)
4001 call_used_regs[i] = call_really_used_regs[i] = 1;
4002}
fb4d4348 4003\f
a4f6c312
SS
4004/* Try to output insns to set TARGET equal to the constant C if it can
4005 be done in less than N insns. Do all computations in MODE.
4006 Returns the place where the output has been placed if it can be
4007 done and the insns have been emitted. If it would take more than N
4008 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
4009
4010rtx
f676971a 4011rs6000_emit_set_const (rtx dest, enum machine_mode mode,
a2369ed3 4012 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 4013{
af8cb5c5 4014 rtx result, insn, set;
2bfcf297
DB
4015 HOST_WIDE_INT c0, c1;
4016
af8cb5c5 4017 if (mode == QImode || mode == HImode)
2bfcf297
DB
4018 {
4019 if (dest == NULL)
c4ad648e 4020 dest = gen_reg_rtx (mode);
2bfcf297
DB
4021 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
4022 return dest;
4023 }
af8cb5c5 4024 else if (mode == SImode)
2bfcf297 4025 {
af8cb5c5
DE
4026 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
4027
4028 emit_insn (gen_rtx_SET (VOIDmode, result,
4029 GEN_INT (INTVAL (source)
4030 & (~ (HOST_WIDE_INT) 0xffff))));
4031 emit_insn (gen_rtx_SET (VOIDmode, dest,
4032 gen_rtx_IOR (SImode, result,
4033 GEN_INT (INTVAL (source) & 0xffff))));
4034 result = dest;
2bfcf297 4035 }
af8cb5c5 4036 else if (mode == DImode)
2bfcf297 4037 {
af8cb5c5
DE
4038 if (GET_CODE (source) == CONST_INT)
4039 {
4040 c0 = INTVAL (source);
4041 c1 = -(c0 < 0);
4042 }
4043 else if (GET_CODE (source) == CONST_DOUBLE)
4044 {
2bfcf297 4045#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
4046 c0 = CONST_DOUBLE_LOW (source);
4047 c1 = -(c0 < 0);
2bfcf297 4048#else
af8cb5c5
DE
4049 c0 = CONST_DOUBLE_LOW (source);
4050 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 4051#endif
af8cb5c5
DE
4052 }
4053 else
4054 abort ();
4055
4056 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
4057 }
4058 else
a4f6c312 4059 abort ();
2bfcf297 4060
af8cb5c5
DE
4061 insn = get_last_insn ();
4062 set = single_set (insn);
4063 if (! CONSTANT_P (SET_SRC (set)))
4064 set_unique_reg_note (insn, REG_EQUAL, source);
4065
4066 return result;
2bfcf297
DB
4067}
4068
4069/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
4070 fall back to a straight forward decomposition. We do this to avoid
4071 exponential run times encountered when looking for longer sequences
4072 with rs6000_emit_set_const. */
4073static rtx
a2369ed3 4074rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
4075{
4076 if (!TARGET_POWERPC64)
4077 {
4078 rtx operand1, operand2;
4079
4080 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
4081 DImode);
4082 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
4083 DImode);
4084 emit_move_insn (operand1, GEN_INT (c1));
4085 emit_move_insn (operand2, GEN_INT (c2));
4086 }
4087 else
4088 {
bc06712d 4089 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 4090
bc06712d 4091 ud1 = c1 & 0xffff;
f921c9c9 4092 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 4093#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 4094 c2 = c1 >> 32;
2bfcf297 4095#endif
bc06712d 4096 ud3 = c2 & 0xffff;
f921c9c9 4097 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 4098
f676971a 4099 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
bc06712d 4100 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 4101 {
bc06712d 4102 if (ud1 & 0x8000)
b78d48dd 4103 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
4104 else
4105 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 4106 }
2bfcf297 4107
f676971a 4108 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
bc06712d 4109 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 4110 {
bc06712d 4111 if (ud2 & 0x8000)
f676971a 4112 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
bc06712d 4113 - 0x80000000));
252b88f7 4114 else
bc06712d
TR
4115 emit_move_insn (dest, GEN_INT (ud2 << 16));
4116 if (ud1 != 0)
4117 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 4118 }
f676971a 4119 else if ((ud4 == 0xffff && (ud3 & 0x8000))
bc06712d
TR
4120 || (ud4 == 0 && ! (ud3 & 0x8000)))
4121 {
4122 if (ud3 & 0x8000)
f676971a 4123 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
bc06712d
TR
4124 - 0x80000000));
4125 else
4126 emit_move_insn (dest, GEN_INT (ud3 << 16));
4127
4128 if (ud2 != 0)
4129 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
4130 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
4131 if (ud1 != 0)
4132 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4133 }
f676971a 4134 else
bc06712d
TR
4135 {
4136 if (ud4 & 0x8000)
f676971a 4137 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
bc06712d
TR
4138 - 0x80000000));
4139 else
4140 emit_move_insn (dest, GEN_INT (ud4 << 16));
4141
4142 if (ud3 != 0)
4143 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 4144
bc06712d
TR
4145 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
4146 if (ud2 != 0)
f676971a
EC
4147 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
4148 GEN_INT (ud2 << 16)));
bc06712d
TR
4149 if (ud1 != 0)
4150 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4151 }
4152 }
2bfcf297
DB
4153 return dest;
4154}
4155
76d2b81d
DJ
4156/* Helper for the following. Get rid of [r+r] memory refs
4157 in cases where it won't work (TImode, TFmode). */
4158
4159static void
4160rs6000_eliminate_indexed_memrefs (rtx operands[2])
4161{
4162 if (GET_CODE (operands[0]) == MEM
4163 && GET_CODE (XEXP (operands[0], 0)) != REG
4164 && ! reload_in_progress)
4165 operands[0]
4166 = replace_equiv_address (operands[0],
4167 copy_addr_to_reg (XEXP (operands[0], 0)));
4168
4169 if (GET_CODE (operands[1]) == MEM
4170 && GET_CODE (XEXP (operands[1], 0)) != REG
4171 && ! reload_in_progress)
4172 operands[1]
4173 = replace_equiv_address (operands[1],
4174 copy_addr_to_reg (XEXP (operands[1], 0)));
4175}
4176
fb4d4348
GK
4177/* Emit a move from SOURCE to DEST in mode MODE. */
4178void
a2369ed3 4179rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
4180{
4181 rtx operands[2];
4182 operands[0] = dest;
4183 operands[1] = source;
f676971a 4184
fb4d4348
GK
4185 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
4186 if (GET_CODE (operands[1]) == CONST_DOUBLE
4187 && ! FLOAT_MODE_P (mode)
4188 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
4189 {
4190 /* FIXME. This should never happen. */
4191 /* Since it seems that it does, do the safe thing and convert
4192 to a CONST_INT. */
2496c7bd 4193 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
4194 }
4195 if (GET_CODE (operands[1]) == CONST_DOUBLE
4196 && ! FLOAT_MODE_P (mode)
4197 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
4198 && CONST_DOUBLE_LOW (operands[1]) >= 0)
4199 || (CONST_DOUBLE_HIGH (operands[1]) == -1
4200 && CONST_DOUBLE_LOW (operands[1]) < 0)))
4201 abort ();
c9e8cb32
DD
4202
4203 /* Check if GCC is setting up a block move that will end up using FP
4204 registers as temporaries. We must make sure this is acceptable. */
4205 if (GET_CODE (operands[0]) == MEM
4206 && GET_CODE (operands[1]) == MEM
4207 && mode == DImode
41543739
GK
4208 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
4209 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
4210 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
4211 ? 32 : MEM_ALIGN (operands[0])))
4212 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
f676971a 4213 ? 32
41543739
GK
4214 : MEM_ALIGN (operands[1]))))
4215 && ! MEM_VOLATILE_P (operands [0])
4216 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 4217 {
41543739
GK
4218 emit_move_insn (adjust_address (operands[0], SImode, 0),
4219 adjust_address (operands[1], SImode, 0));
4220 emit_move_insn (adjust_address (operands[0], SImode, 4),
4221 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
4222 return;
4223 }
630d42a0 4224
67cef334
DE
4225 if (!no_new_pseudos)
4226 {
4227 if (GET_CODE (operands[1]) == MEM && optimize > 0
4228 && (mode == QImode || mode == HImode || mode == SImode)
4229 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
4230 {
4231 rtx reg = gen_reg_rtx (word_mode);
4232
4233 emit_insn (gen_rtx_SET (word_mode, reg,
4234 gen_rtx_ZERO_EXTEND (word_mode,
4235 operands[1])));
4236 operands[1] = gen_lowpart (mode, reg);
4237 }
4238 if (GET_CODE (operands[0]) != REG)
4239 operands[1] = force_reg (mode, operands[1]);
4240 }
a9098fd0 4241
a3170dc6
AH
4242 if (mode == SFmode && ! TARGET_POWERPC
4243 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 4244 && GET_CODE (operands[0]) == MEM)
fb4d4348 4245 {
ffc14f31
GK
4246 int regnum;
4247
4248 if (reload_in_progress || reload_completed)
4249 regnum = true_regnum (operands[1]);
4250 else if (GET_CODE (operands[1]) == REG)
4251 regnum = REGNO (operands[1]);
4252 else
4253 regnum = -1;
f676971a 4254
fb4d4348
GK
4255 /* If operands[1] is a register, on POWER it may have
4256 double-precision data in it, so truncate it to single
4257 precision. */
4258 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
4259 {
4260 rtx newreg;
4261 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
4262 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
4263 operands[1] = newreg;
4264 }
4265 }
4266
c4501e62
JJ
4267 /* Recognize the case where operand[1] is a reference to thread-local
4268 data and load its address to a register. */
4269 if (GET_CODE (operands[1]) == SYMBOL_REF)
4270 {
4271 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
4272 if (model != 0)
4273 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
4274 }
4275
8f4e6caf
RH
4276 /* Handle the case where reload calls us with an invalid address. */
4277 if (reload_in_progress && mode == Pmode
69ef87e2 4278 && (! general_operand (operands[1], mode)
8f4e6caf
RH
4279 || ! nonimmediate_operand (operands[0], mode)))
4280 goto emit_set;
4281
a9baceb1
GK
4282 /* 128-bit constant floating-point values on Darwin should really be
4283 loaded as two parts. */
4284 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
4285 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
4286 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
4287 {
4288 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
4289 know how to get a DFmode SUBREG of a TFmode. */
4290 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
4291 simplify_gen_subreg (DImode, operands[1], mode, 0),
4292 DImode);
4293 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
4294 GET_MODE_SIZE (DImode)),
4295 simplify_gen_subreg (DImode, operands[1], mode,
4296 GET_MODE_SIZE (DImode)),
4297 DImode);
4298 return;
4299 }
4300
fb4d4348
GK
4301 /* FIXME: In the long term, this switch statement should go away
4302 and be replaced by a sequence of tests based on things like
4303 mode == Pmode. */
4304 switch (mode)
4305 {
4306 case HImode:
4307 case QImode:
4308 if (CONSTANT_P (operands[1])
4309 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 4310 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
4311 break;
4312
06f4e019 4313 case TFmode:
76d2b81d
DJ
4314 rs6000_eliminate_indexed_memrefs (operands);
4315 /* fall through */
4316
fb4d4348
GK
4317 case DFmode:
4318 case SFmode:
f676971a 4319 if (CONSTANT_P (operands[1])
fb4d4348 4320 && ! easy_fp_constant (operands[1], mode))
a9098fd0 4321 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4322 break;
f676971a 4323
0ac081f6
AH
4324 case V16QImode:
4325 case V8HImode:
4326 case V4SFmode:
4327 case V4SImode:
a3170dc6
AH
4328 case V4HImode:
4329 case V2SFmode:
4330 case V2SImode:
00a892b8 4331 case V1DImode:
69ef87e2 4332 if (CONSTANT_P (operands[1])
d744e06e 4333 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
4334 operands[1] = force_const_mem (mode, operands[1]);
4335 break;
f676971a 4336
fb4d4348 4337 case SImode:
a9098fd0 4338 case DImode:
fb4d4348
GK
4339 /* Use default pattern for address of ELF small data */
4340 if (TARGET_ELF
a9098fd0 4341 && mode == Pmode
f607bc57 4342 && DEFAULT_ABI == ABI_V4
f676971a 4343 && (GET_CODE (operands[1]) == SYMBOL_REF
a9098fd0
GK
4344 || GET_CODE (operands[1]) == CONST)
4345 && small_data_operand (operands[1], mode))
fb4d4348
GK
4346 {
4347 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4348 return;
4349 }
4350
f607bc57 4351 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
4352 && mode == Pmode && mode == SImode
4353 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
4354 {
4355 emit_insn (gen_movsi_got (operands[0], operands[1]));
4356 return;
4357 }
4358
ee890fe2 4359 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
4360 && TARGET_NO_TOC
4361 && ! flag_pic
a9098fd0 4362 && mode == Pmode
fb4d4348
GK
4363 && CONSTANT_P (operands[1])
4364 && GET_CODE (operands[1]) != HIGH
4365 && GET_CODE (operands[1]) != CONST_INT)
4366 {
a9098fd0 4367 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
4368
4369 /* If this is a function address on -mcall-aixdesc,
4370 convert it to the address of the descriptor. */
4371 if (DEFAULT_ABI == ABI_AIX
4372 && GET_CODE (operands[1]) == SYMBOL_REF
4373 && XSTR (operands[1], 0)[0] == '.')
4374 {
4375 const char *name = XSTR (operands[1], 0);
4376 rtx new_ref;
4377 while (*name == '.')
4378 name++;
4379 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
4380 CONSTANT_POOL_ADDRESS_P (new_ref)
4381 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 4382 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 4383 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 4384 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
4385 operands[1] = new_ref;
4386 }
7509c759 4387
ee890fe2
SS
4388 if (DEFAULT_ABI == ABI_DARWIN)
4389 {
ab82a49f
AP
4390#if TARGET_MACHO
4391 if (MACHO_DYNAMIC_NO_PIC_P)
4392 {
4393 /* Take care of any required data indirection. */
4394 operands[1] = rs6000_machopic_legitimize_pic_address (
4395 operands[1], mode, operands[0]);
4396 if (operands[0] != operands[1])
4397 emit_insn (gen_rtx_SET (VOIDmode,
c4ad648e 4398 operands[0], operands[1]));
ab82a49f
AP
4399 return;
4400 }
4401#endif
ac9e2cff
AP
4402 if (mode == DImode)
4403 {
4404 emit_insn (gen_macho_high_di (target, operands[1]));
4405 emit_insn (gen_macho_low_di (operands[0], target, operands[1]));
4406 }
4407 else
4408 {
4409 emit_insn (gen_macho_high (target, operands[1]));
4410 emit_insn (gen_macho_low (operands[0], target, operands[1]));
4411 }
ee890fe2
SS
4412 return;
4413 }
4414
fb4d4348
GK
4415 emit_insn (gen_elf_high (target, operands[1]));
4416 emit_insn (gen_elf_low (operands[0], target, operands[1]));
4417 return;
4418 }
4419
a9098fd0
GK
4420 /* If this is a SYMBOL_REF that refers to a constant pool entry,
4421 and we have put it in the TOC, we just need to make a TOC-relative
4422 reference to it. */
4423 if (TARGET_TOC
4424 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 4425 && constant_pool_expr_p (operands[1])
a9098fd0
GK
4426 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
4427 get_pool_mode (operands[1])))
fb4d4348 4428 {
a9098fd0 4429 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 4430 }
a9098fd0
GK
4431 else if (mode == Pmode
4432 && CONSTANT_P (operands[1])
38886f37
AO
4433 && ((GET_CODE (operands[1]) != CONST_INT
4434 && ! easy_fp_constant (operands[1], mode))
4435 || (GET_CODE (operands[1]) == CONST_INT
4436 && num_insns_constant (operands[1], mode) > 2)
4437 || (GET_CODE (operands[0]) == REG
4438 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 4439 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
4440 && ! legitimate_constant_pool_address_p (operands[1])
4441 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
4442 {
4443 /* Emit a USE operation so that the constant isn't deleted if
4444 expensive optimizations are turned on because nobody
4445 references it. This should only be done for operands that
4446 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
4447 This should not be done for operands that contain LABEL_REFs.
4448 For now, we just handle the obvious case. */
4449 if (GET_CODE (operands[1]) != LABEL_REF)
4450 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
4451
c859cda6 4452#if TARGET_MACHO
ee890fe2 4453 /* Darwin uses a special PIC legitimizer. */
ab82a49f 4454 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 4455 {
ee890fe2
SS
4456 operands[1] =
4457 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
4458 operands[0]);
4459 if (operands[0] != operands[1])
4460 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
4461 return;
4462 }
c859cda6 4463#endif
ee890fe2 4464
fb4d4348
GK
4465 /* If we are to limit the number of things we put in the TOC and
4466 this is a symbol plus a constant we can add in one insn,
4467 just put the symbol in the TOC and add the constant. Don't do
4468 this if reload is in progress. */
4469 if (GET_CODE (operands[1]) == CONST
4470 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
4471 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 4472 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
4473 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
4474 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
4475 && ! side_effects_p (operands[0]))
4476 {
a4f6c312
SS
4477 rtx sym =
4478 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
4479 rtx other = XEXP (XEXP (operands[1], 0), 1);
4480
a9098fd0
GK
4481 sym = force_reg (mode, sym);
4482 if (mode == SImode)
4483 emit_insn (gen_addsi3 (operands[0], sym, other));
4484 else
4485 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
4486 return;
4487 }
4488
a9098fd0 4489 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4490
f676971a 4491 if (TARGET_TOC
4d588c14 4492 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
4493 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
4494 get_pool_constant (XEXP (operands[1], 0)),
4495 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 4496 {
ba4828e0 4497 operands[1]
542a8afa 4498 = gen_const_mem (mode,
c4ad648e 4499 create_TOC_reference (XEXP (operands[1], 0)));
ba4828e0 4500 set_mem_alias_set (operands[1], get_TOC_alias_set ());
a9098fd0 4501 }
fb4d4348
GK
4502 }
4503 break;
a9098fd0 4504
fb4d4348 4505 case TImode:
76d2b81d
DJ
4506 rs6000_eliminate_indexed_memrefs (operands);
4507
27dc0551
DE
4508 if (TARGET_POWER)
4509 {
4510 emit_insn (gen_rtx_PARALLEL (VOIDmode,
4511 gen_rtvec (2,
4512 gen_rtx_SET (VOIDmode,
4513 operands[0], operands[1]),
4514 gen_rtx_CLOBBER (VOIDmode,
4515 gen_rtx_SCRATCH (SImode)))));
4516 return;
4517 }
fb4d4348
GK
4518 break;
4519
4520 default:
4521 abort ();
4522 }
4523
a9098fd0
GK
4524 /* Above, we may have called force_const_mem which may have returned
4525 an invalid address. If we can, fix this up; otherwise, reload will
4526 have to deal with it. */
8f4e6caf
RH
4527 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
4528 operands[1] = validize_mem (operands[1]);
a9098fd0 4529
8f4e6caf 4530 emit_set:
fb4d4348
GK
4531 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4532}
4697a36c 4533\f
2858f73a
GK
4534/* Nonzero if we can use a floating-point register to pass this arg. */
4535#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
4536 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
4537 && (CUM)->fregno <= FP_ARG_MAX_REG \
4538 && TARGET_HARD_FLOAT && TARGET_FPRS)
4539
4540/* Nonzero if we can use an AltiVec register to pass this arg. */
4541#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
4542 (ALTIVEC_VECTOR_MODE (MODE) \
4543 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
4544 && TARGET_ALTIVEC_ABI \
83953138 4545 && (NAMED))
2858f73a 4546
c6e8c921
GK
4547/* Return a nonzero value to say to return the function value in
4548 memory, just as large structures are always returned. TYPE will be
4549 the data type of the value, and FNTYPE will be the type of the
4550 function doing the returning, or @code{NULL} for libcalls.
4551
4552 The AIX ABI for the RS/6000 specifies that all structures are
4553 returned in memory. The Darwin ABI does the same. The SVR4 ABI
4554 specifies that structures <= 8 bytes are returned in r3/r4, but a
4555 draft put them in memory, and GCC used to implement the draft
4556 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
4557 controls this instead of DEFAULT_ABI; V.4 targets needing backward
4558 compatibility can change DRAFT_V4_STRUCT_RET to override the
4559 default, and -m switches get the final word. See
4560 rs6000_override_options for more details.
4561
4562 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
4563 long double support is enabled. These values are returned in memory.
4564
4565 int_size_in_bytes returns -1 for variable size objects, which go in
4566 memory always. The cast to unsigned makes -1 > 8. */
4567
4568static bool
4569rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4570{
4571 if (AGGREGATE_TYPE_P (type)
4572 && (TARGET_AIX_STRUCT_RET
4573 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
4574 return true;
4575 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
4576 return true;
4577 return false;
4578}
4579
4697a36c
MM
4580/* Initialize a variable CUM of type CUMULATIVE_ARGS
4581 for a call to a function whose data type is FNTYPE.
4582 For a library call, FNTYPE is 0.
4583
4584 For incoming args we set the number of arguments in the prototype large
1c20ae99 4585 so we never return a PARALLEL. */
4697a36c
MM
4586
4587void
f676971a 4588init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
4589 rtx libname ATTRIBUTE_UNUSED, int incoming,
4590 int libcall, int n_named_args)
4697a36c
MM
4591{
4592 static CUMULATIVE_ARGS zero_cumulative;
4593
4594 *cum = zero_cumulative;
4595 cum->words = 0;
4596 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 4597 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 4598 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
4599 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
4600 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 4601 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
4602 cum->stdarg = fntype
4603 && (TYPE_ARG_TYPES (fntype) != 0
4604 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4605 != void_type_node));
4697a36c 4606
0f6937fe
AM
4607 cum->nargs_prototype = 0;
4608 if (incoming || cum->prototype)
4609 cum->nargs_prototype = n_named_args;
4697a36c 4610
a5c76ee6
ZW
4611 /* Check for a longcall attribute. */
4612 if (fntype
4613 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
4614 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
4615 cum->call_cookie = CALL_LONG;
4616
4697a36c
MM
4617 if (TARGET_DEBUG_ARG)
4618 {
4619 fprintf (stderr, "\ninit_cumulative_args:");
4620 if (fntype)
4621 {
4622 tree ret_type = TREE_TYPE (fntype);
4623 fprintf (stderr, " ret code = %s,",
4624 tree_code_name[ (int)TREE_CODE (ret_type) ]);
4625 }
4626
6a4cee5f
MM
4627 if (cum->call_cookie & CALL_LONG)
4628 fprintf (stderr, " longcall,");
4629
4697a36c
MM
4630 fprintf (stderr, " proto = %d, nargs = %d\n",
4631 cum->prototype, cum->nargs_prototype);
4632 }
f676971a 4633
c4ad648e
AM
4634 if (fntype
4635 && !TARGET_ALTIVEC
4636 && TARGET_ALTIVEC_ABI
4637 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
4638 {
4639 error ("Cannot return value in vector register because"
4640 " altivec instructions are disabled, use -maltivec"
4641 " to enable them.");
4642 }
4697a36c
MM
4643}
4644\f
fe984136
RH
4645/* Return true if TYPE must be passed on the stack and not in registers. */
4646
4647static bool
4648rs6000_must_pass_in_stack (enum machine_mode mode, tree type)
4649{
4650 if (DEFAULT_ABI == ABI_AIX || TARGET_64BIT)
4651 return must_pass_in_stack_var_size (mode, type);
4652 else
4653 return must_pass_in_stack_var_size_or_pad (mode, type);
4654}
4655
c229cba9
DE
4656/* If defined, a C expression which determines whether, and in which
4657 direction, to pad out an argument with extra space. The value
4658 should be of type `enum direction': either `upward' to pad above
4659 the argument, `downward' to pad below, or `none' to inhibit
4660 padding.
4661
4662 For the AIX ABI structs are always stored left shifted in their
4663 argument slot. */
4664
9ebbca7d 4665enum direction
a2369ed3 4666function_arg_padding (enum machine_mode mode, tree type)
c229cba9 4667{
6e985040
AM
4668#ifndef AGGREGATE_PADDING_FIXED
4669#define AGGREGATE_PADDING_FIXED 0
4670#endif
4671#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
4672#define AGGREGATES_PAD_UPWARD_ALWAYS 0
4673#endif
4674
4675 if (!AGGREGATE_PADDING_FIXED)
4676 {
4677 /* GCC used to pass structures of the same size as integer types as
4678 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
19525b57 4679 i.e. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
6e985040
AM
4680 passed padded downward, except that -mstrict-align further
4681 muddied the water in that multi-component structures of 2 and 4
4682 bytes in size were passed padded upward.
4683
4684 The following arranges for best compatibility with previous
4685 versions of gcc, but removes the -mstrict-align dependency. */
4686 if (BYTES_BIG_ENDIAN)
4687 {
4688 HOST_WIDE_INT size = 0;
4689
4690 if (mode == BLKmode)
4691 {
4692 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4693 size = int_size_in_bytes (type);
4694 }
4695 else
4696 size = GET_MODE_SIZE (mode);
4697
4698 if (size == 1 || size == 2 || size == 4)
4699 return downward;
4700 }
4701 return upward;
4702 }
4703
4704 if (AGGREGATES_PAD_UPWARD_ALWAYS)
4705 {
4706 if (type != 0 && AGGREGATE_TYPE_P (type))
4707 return upward;
4708 }
c229cba9 4709
d3704c46
KH
4710 /* Fall back to the default. */
4711 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
4712}
4713
b6c9286a 4714/* If defined, a C expression that gives the alignment boundary, in bits,
f676971a 4715 of an argument with the specified mode and type. If it is not defined,
b6c9286a 4716 PARM_BOUNDARY is used for all arguments.
f676971a 4717
2310f99a 4718 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
4719
4720int
a2369ed3 4721function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 4722{
4ed78545
AM
4723 if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8)
4724 return 64;
4725 else if (SPE_VECTOR_MODE (mode))
e1f83b4d 4726 return 64;
b2d04ecf 4727 else if (ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4728 return 128;
9ebbca7d 4729 else
b6c9286a 4730 return PARM_BOUNDARY;
b6c9286a 4731}
c53bdcf5
AM
4732
4733/* Compute the size (in words) of a function argument. */
4734
4735static unsigned long
4736rs6000_arg_size (enum machine_mode mode, tree type)
4737{
4738 unsigned long size;
4739
4740 if (mode != BLKmode)
4741 size = GET_MODE_SIZE (mode);
4742 else
4743 size = int_size_in_bytes (type);
4744
4745 if (TARGET_32BIT)
4746 return (size + 3) >> 2;
4747 else
4748 return (size + 7) >> 3;
4749}
b6c9286a 4750\f
4697a36c
MM
4751/* Update the data in CUM to advance over an argument
4752 of mode MODE and data type TYPE.
b2d04ecf
AM
4753 (TYPE is null for libcalls where that information may not be available.)
4754
4755 Note that for args passed by reference, function_arg will be called
4756 with MODE and TYPE set to that of the pointer to the arg, not the arg
4757 itself. */
4697a36c
MM
4758
4759void
f676971a 4760function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 4761 tree type, int named)
4697a36c
MM
4762{
4763 cum->nargs_prototype--;
4764
0ac081f6
AH
4765 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4766 {
4ed78545
AM
4767 bool stack = false;
4768
2858f73a 4769 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c4ad648e 4770 {
6d0ef01e
HP
4771 cum->vregno++;
4772 if (!TARGET_ALTIVEC)
4773 error ("Cannot pass argument in vector register because"
4774 " altivec instructions are disabled, use -maltivec"
4775 " to enable them.");
4ed78545
AM
4776
4777 /* PowerPC64 Linux and AIX allocate GPRs for a vector argument
f676971a 4778 even if it is going to be passed in a vector register.
4ed78545
AM
4779 Darwin does the same for variable-argument functions. */
4780 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4781 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4782 stack = true;
6d0ef01e 4783 }
4ed78545
AM
4784 else
4785 stack = true;
4786
4787 if (stack)
c4ad648e 4788 {
a594a19c 4789 int align;
f676971a 4790
2858f73a
GK
4791 /* Vector parameters must be 16-byte aligned. This places
4792 them at 2 mod 4 in terms of words in 32-bit mode, since
4793 the parameter save area starts at offset 24 from the
4794 stack. In 64-bit mode, they just have to start on an
4795 even word, since the parameter save area is 16-byte
4796 aligned. Space for GPRs is reserved even if the argument
4797 will be passed in memory. */
4798 if (TARGET_32BIT)
4ed78545 4799 align = (2 - cum->words) & 3;
2858f73a
GK
4800 else
4801 align = cum->words & 1;
c53bdcf5 4802 cum->words += align + rs6000_arg_size (mode, type);
f676971a 4803
a594a19c
GK
4804 if (TARGET_DEBUG_ARG)
4805 {
f676971a 4806 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
a594a19c
GK
4807 cum->words, align);
4808 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
f676971a 4809 cum->nargs_prototype, cum->prototype,
2858f73a 4810 GET_MODE_NAME (mode));
a594a19c
GK
4811 }
4812 }
0ac081f6 4813 }
a4b0320c 4814 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4815 && !cum->stdarg
4816 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4817 cum->sysv_gregno++;
f607bc57 4818 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4819 {
a3170dc6 4820 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4821 && (mode == SFmode || mode == DFmode))
4697a36c 4822 {
4cc833b7
RH
4823 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4824 cum->fregno++;
4825 else
4826 {
4827 if (mode == DFmode)
c4ad648e 4828 cum->words += cum->words & 1;
c53bdcf5 4829 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4830 }
4697a36c 4831 }
4cc833b7
RH
4832 else
4833 {
b2d04ecf 4834 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4835 int gregno = cum->sysv_gregno;
4836
4ed78545
AM
4837 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4838 (r7,r8) or (r9,r10). As does any other 2 word item such
4839 as complex int due to a historical mistake. */
4840 if (n_words == 2)
4841 gregno += (1 - gregno) & 1;
4cc833b7 4842
4ed78545 4843 /* Multi-reg args are not split between registers and stack. */
4cc833b7
RH
4844 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4845 {
4ed78545
AM
4846 /* Long long and SPE vectors are aligned on the stack.
4847 So are other 2 word items such as complex int due to
4848 a historical mistake. */
4cc833b7
RH
4849 if (n_words == 2)
4850 cum->words += cum->words & 1;
4851 cum->words += n_words;
4852 }
4697a36c 4853
4cc833b7
RH
4854 /* Note: continuing to accumulate gregno past when we've started
4855 spilling to the stack indicates the fact that we've started
4856 spilling to the stack to expand_builtin_saveregs. */
4857 cum->sysv_gregno = gregno + n_words;
4858 }
4697a36c 4859
4cc833b7
RH
4860 if (TARGET_DEBUG_ARG)
4861 {
4862 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4863 cum->words, cum->fregno);
4864 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4865 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4866 fprintf (stderr, "mode = %4s, named = %d\n",
4867 GET_MODE_NAME (mode), named);
4868 }
4697a36c
MM
4869 }
4870 else
4cc833b7 4871 {
b2d04ecf
AM
4872 int n_words = rs6000_arg_size (mode, type);
4873 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
a4f6c312 4874
b2d04ecf
AM
4875 /* The simple alignment calculation here works because
4876 function_arg_boundary / PARM_BOUNDARY will only be 1 or 2.
4877 If we ever want to handle alignments larger than 8 bytes for
4878 32-bit or 16 bytes for 64-bit, then we'll need to take into
4879 account the offset to the start of the parm save area. */
4880 align &= cum->words;
4881 cum->words += align + n_words;
4697a36c 4882
a3170dc6
AH
4883 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4884 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4885 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4886
4887 if (TARGET_DEBUG_ARG)
4888 {
4889 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4890 cum->words, cum->fregno);
4891 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4892 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4893 fprintf (stderr, "named = %d, align = %d\n", named, align);
4894 }
4895 }
4697a36c 4896}
a6c9bed4
AH
4897
4898/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4899
a6c9bed4 4900static rtx
f676971a 4901rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 4902 tree type)
a6c9bed4
AH
4903{
4904 if (cum->stdarg)
4905 {
4906 int gregno = cum->sysv_gregno;
c53bdcf5 4907 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4908
4909 /* SPE vectors are put in odd registers. */
4910 if (n_words == 2 && (gregno & 1) == 0)
4911 gregno += 1;
4912
4913 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4914 {
4915 rtx r1, r2;
4916 enum machine_mode m = SImode;
4917
4918 r1 = gen_rtx_REG (m, gregno);
4919 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4920 r2 = gen_rtx_REG (m, gregno + 1);
4921 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4922 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4923 }
4924 else
b78d48dd 4925 return NULL_RTX;
a6c9bed4
AH
4926 }
4927 else
4928 {
4929 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4930 return gen_rtx_REG (mode, cum->sysv_gregno);
4931 else
b78d48dd 4932 return NULL_RTX;
a6c9bed4
AH
4933 }
4934}
4935
b78d48dd
FJ
4936/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4937
4938static rtx
ec6376ab 4939rs6000_mixed_function_arg (enum machine_mode mode, tree type, int align_words)
b78d48dd 4940{
ec6376ab
AM
4941 int n_units;
4942 int i, k;
4943 rtx rvec[GP_ARG_NUM_REG + 1];
4944
4945 if (align_words >= GP_ARG_NUM_REG)
4946 return NULL_RTX;
4947
4948 n_units = rs6000_arg_size (mode, type);
4949
4950 /* Optimize the simple case where the arg fits in one gpr, except in
4951 the case of BLKmode due to assign_parms assuming that registers are
4952 BITS_PER_WORD wide. */
4953 if (n_units == 0
4954 || (n_units == 1 && mode != BLKmode))
4955 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4956
4957 k = 0;
4958 if (align_words + n_units > GP_ARG_NUM_REG)
4959 /* Not all of the arg fits in gprs. Say that it goes in memory too,
4960 using a magic NULL_RTX component.
4961 FIXME: This is not strictly correct. Only some of the arg
4962 belongs in memory, not all of it. However, there isn't any way
4963 to do this currently, apart from building rtx descriptions for
4964 the pieces of memory we want stored. Due to bugs in the generic
4965 code we can't use the normal function_arg_partial_nregs scheme
4966 with the PARALLEL arg description we emit here.
4967 In any case, the code to store the whole arg to memory is often
4968 more efficient than code to store pieces, and we know that space
4969 is available in the right place for the whole arg. */
4970 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4971
4972 i = 0;
4973 do
36a454e1 4974 {
ec6376ab
AM
4975 rtx r = gen_rtx_REG (SImode, GP_ARG_MIN_REG + align_words);
4976 rtx off = GEN_INT (i++ * 4);
4977 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
36a454e1 4978 }
ec6376ab
AM
4979 while (++align_words < GP_ARG_NUM_REG && --n_units != 0);
4980
4981 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
b78d48dd
FJ
4982}
4983
4697a36c
MM
4984/* Determine where to put an argument to a function.
4985 Value is zero to push the argument on the stack,
4986 or a hard register in which to store the argument.
4987
4988 MODE is the argument's machine mode.
4989 TYPE is the data type of the argument (as a tree).
4990 This is null for libcalls where that information may
4991 not be available.
4992 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4993 the preceding args and about the function being called.
4994 NAMED is nonzero if this argument is a named parameter
4995 (otherwise it is an extra parameter matching an ellipsis).
4996
4997 On RS/6000 the first eight words of non-FP are normally in registers
4998 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4999 Under V.4, the first 8 FP args are in registers.
5000
5001 If this is floating-point and no prototype is specified, we use
5002 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 5003 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 5004 so we can pass the FP value just in one register. emit_library_function
b2d04ecf
AM
5005 doesn't support PARALLEL anyway.
5006
5007 Note that for args passed by reference, function_arg will be called
5008 with MODE and TYPE set to that of the pointer to the arg, not the arg
5009 itself. */
4697a36c
MM
5010
5011struct rtx_def *
f676971a 5012function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 5013 tree type, int named)
4697a36c 5014{
4cc833b7 5015 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 5016
a4f6c312
SS
5017 /* Return a marker to indicate whether CR1 needs to set or clear the
5018 bit that V.4 uses to say fp args were passed in registers.
5019 Assume that we don't need the marker for software floating point,
5020 or compiler generated library calls. */
4697a36c
MM
5021 if (mode == VOIDmode)
5022 {
f607bc57 5023 if (abi == ABI_V4
7509c759 5024 && cum->nargs_prototype < 0
b9599e46
FS
5025 && (cum->call_cookie & CALL_LIBCALL) == 0
5026 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 5027 {
a3170dc6
AH
5028 /* For the SPE, we need to crxor CR6 always. */
5029 if (TARGET_SPE_ABI)
5030 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
5031 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
5032 return GEN_INT (cum->call_cookie
5033 | ((cum->fregno == FP_ARG_MIN_REG)
5034 ? CALL_V4_SET_FP_ARGS
5035 : CALL_V4_CLEAR_FP_ARGS));
7509c759 5036 }
4697a36c 5037
7509c759 5038 return GEN_INT (cum->call_cookie);
4697a36c
MM
5039 }
5040
2858f73a 5041 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
5042 if (TARGET_64BIT && ! cum->prototype)
5043 {
c4ad648e
AM
5044 /* Vector parameters get passed in vector register
5045 and also in GPRs or memory, in absence of prototype. */
5046 int align_words;
5047 rtx slot;
5048 align_words = (cum->words + 1) & ~1;
5049
5050 if (align_words >= GP_ARG_NUM_REG)
5051 {
5052 slot = NULL_RTX;
5053 }
5054 else
5055 {
5056 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5057 }
5058 return gen_rtx_PARALLEL (mode,
5059 gen_rtvec (2,
5060 gen_rtx_EXPR_LIST (VOIDmode,
5061 slot, const0_rtx),
5062 gen_rtx_EXPR_LIST (VOIDmode,
5063 gen_rtx_REG (mode, cum->vregno),
5064 const0_rtx)));
c72d6c26
HP
5065 }
5066 else
5067 return gen_rtx_REG (mode, cum->vregno);
2858f73a 5068 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 5069 {
2858f73a 5070 if (named || abi == ABI_V4)
a594a19c 5071 return NULL_RTX;
0ac081f6 5072 else
a594a19c
GK
5073 {
5074 /* Vector parameters to varargs functions under AIX or Darwin
5075 get passed in memory and possibly also in GPRs. */
ec6376ab
AM
5076 int align, align_words, n_words;
5077 enum machine_mode part_mode;
a594a19c
GK
5078
5079 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
5080 2 mod 4 in terms of words in 32-bit mode, since the parameter
5081 save area starts at offset 24 from the stack. In 64-bit mode,
5082 they just have to start on an even word, since the parameter
5083 save area is 16-byte aligned. */
5084 if (TARGET_32BIT)
4ed78545 5085 align = (2 - cum->words) & 3;
2858f73a
GK
5086 else
5087 align = cum->words & 1;
a594a19c
GK
5088 align_words = cum->words + align;
5089
5090 /* Out of registers? Memory, then. */
5091 if (align_words >= GP_ARG_NUM_REG)
5092 return NULL_RTX;
ec6376ab
AM
5093
5094 if (TARGET_32BIT && TARGET_POWERPC64)
5095 return rs6000_mixed_function_arg (mode, type, align_words);
5096
2858f73a
GK
5097 /* The vector value goes in GPRs. Only the part of the
5098 value in GPRs is reported here. */
ec6376ab
AM
5099 part_mode = mode;
5100 n_words = rs6000_arg_size (mode, type);
5101 if (align_words + n_words > GP_ARG_NUM_REG)
839a4992 5102 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
5103 is either wholly in GPRs or half in GPRs and half not. */
5104 part_mode = DImode;
ec6376ab
AM
5105
5106 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 5107 }
0ac081f6 5108 }
a6c9bed4
AH
5109 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
5110 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 5111 else if (abi == ABI_V4)
4697a36c 5112 {
a3170dc6 5113 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
5114 && (mode == SFmode || mode == DFmode))
5115 {
5116 if (cum->fregno <= FP_ARG_V4_MAX_REG)
5117 return gen_rtx_REG (mode, cum->fregno);
5118 else
b78d48dd 5119 return NULL_RTX;
4cc833b7
RH
5120 }
5121 else
5122 {
b2d04ecf 5123 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
5124 int gregno = cum->sysv_gregno;
5125
4ed78545
AM
5126 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
5127 (r7,r8) or (r9,r10). As does any other 2 word item such
5128 as complex int due to a historical mistake. */
5129 if (n_words == 2)
5130 gregno += (1 - gregno) & 1;
4cc833b7 5131
4ed78545 5132 /* Multi-reg args are not split between registers and stack. */
ec6376ab 5133 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
b78d48dd 5134 return NULL_RTX;
ec6376ab
AM
5135
5136 if (TARGET_32BIT && TARGET_POWERPC64)
5137 return rs6000_mixed_function_arg (mode, type,
5138 gregno - GP_ARG_MIN_REG);
5139 return gen_rtx_REG (mode, gregno);
4cc833b7 5140 }
4697a36c 5141 }
4cc833b7
RH
5142 else
5143 {
b2d04ecf
AM
5144 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5145 int align_words = cum->words + (cum->words & align);
b78d48dd 5146
2858f73a 5147 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 5148 {
ec6376ab
AM
5149 rtx rvec[GP_ARG_NUM_REG + 1];
5150 rtx r;
5151 int k;
c53bdcf5
AM
5152 bool needs_psave;
5153 enum machine_mode fmode = mode;
c53bdcf5
AM
5154 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
5155
5156 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
5157 {
c53bdcf5
AM
5158 /* Currently, we only ever need one reg here because complex
5159 doubles are split. */
ec6376ab 5160 if (cum->fregno != FP_ARG_MAX_REG || fmode != TFmode)
c53bdcf5 5161 abort ();
ec6376ab
AM
5162
5163 /* Long double split over regs and memory. */
5164 fmode = DFmode;
c53bdcf5 5165 }
c53bdcf5
AM
5166
5167 /* Do we also need to pass this arg in the parameter save
5168 area? */
5169 needs_psave = (type
5170 && (cum->nargs_prototype <= 0
5171 || (DEFAULT_ABI == ABI_AIX
5172 && TARGET_XL_CALL
5173 && align_words >= GP_ARG_NUM_REG)));
5174
5175 if (!needs_psave && mode == fmode)
ec6376ab 5176 return gen_rtx_REG (fmode, cum->fregno);
c53bdcf5 5177
ec6376ab 5178 k = 0;
c53bdcf5
AM
5179 if (needs_psave)
5180 {
ec6376ab 5181 /* Describe the part that goes in gprs or the stack.
c53bdcf5 5182 This piece must come first, before the fprs. */
c53bdcf5
AM
5183 if (align_words < GP_ARG_NUM_REG)
5184 {
5185 unsigned long n_words = rs6000_arg_size (mode, type);
ec6376ab
AM
5186
5187 if (align_words + n_words > GP_ARG_NUM_REG
5188 || (TARGET_32BIT && TARGET_POWERPC64))
5189 {
5190 /* If this is partially on the stack, then we only
5191 include the portion actually in registers here. */
5192 enum machine_mode rmode = TARGET_32BIT ? SImode : DImode;
5193 rtx off;
2e6c9641 5194 int i=0;
c4ad648e
AM
5195 if (align_words + n_words > GP_ARG_NUM_REG
5196 && (TARGET_32BIT && TARGET_POWERPC64))
5197 /* Not all of the arg fits in gprs. Say that it
5198 goes in memory too, using a magic NULL_RTX
5199 component. Also see comment in
5200 rs6000_mixed_function_arg for why the normal
5201 function_arg_partial_nregs scheme doesn't work
5202 in this case. */
5203 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX,
5204 const0_rtx);
ec6376ab
AM
5205 do
5206 {
5207 r = gen_rtx_REG (rmode,
5208 GP_ARG_MIN_REG + align_words);
2e6c9641 5209 off = GEN_INT (i++ * GET_MODE_SIZE (rmode));
ec6376ab
AM
5210 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
5211 }
5212 while (++align_words < GP_ARG_NUM_REG && --n_words != 0);
5213 }
5214 else
5215 {
5216 /* The whole arg fits in gprs. */
5217 r = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5218 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5219 }
c53bdcf5 5220 }
ec6376ab
AM
5221 else
5222 /* It's entirely in memory. */
5223 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
c53bdcf5
AM
5224 }
5225
ec6376ab
AM
5226 /* Describe where this piece goes in the fprs. */
5227 r = gen_rtx_REG (fmode, cum->fregno);
5228 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5229
5230 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
4cc833b7
RH
5231 }
5232 else if (align_words < GP_ARG_NUM_REG)
b2d04ecf 5233 {
ec6376ab
AM
5234 if (TARGET_32BIT && TARGET_POWERPC64)
5235 return rs6000_mixed_function_arg (mode, type, align_words);
b2d04ecf
AM
5236
5237 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5238 }
4cc833b7
RH
5239 else
5240 return NULL_RTX;
4697a36c 5241 }
4697a36c
MM
5242}
5243\f
ec6376ab
AM
5244/* For an arg passed partly in registers and partly in memory, this is
5245 the number of registers used. For args passed entirely in registers
5246 or entirely in memory, zero. When an arg is described by a PARALLEL,
5247 perhaps using more than one register type, this function returns the
5248 number of registers used by the first element of the PARALLEL. */
4697a36c
MM
5249
5250int
f676971a 5251function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 5252 tree type, int named)
4697a36c 5253{
c53bdcf5 5254 int ret = 0;
ec6376ab
AM
5255 int align;
5256 int parm_offset;
5257 int align_words;
c53bdcf5 5258
f607bc57 5259 if (DEFAULT_ABI == ABI_V4)
4697a36c 5260 return 0;
4697a36c 5261
c53bdcf5
AM
5262 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
5263 && cum->nargs_prototype >= 0)
5264 return 0;
5265
ec6376ab
AM
5266 align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5267 parm_offset = TARGET_32BIT ? 2 : 0;
5268 align_words = cum->words + ((parm_offset - cum->words) & align);
5269
5270 if (USE_FP_FOR_ARG_P (cum, mode, type)
5271 /* If we are passing this arg in gprs as well, then this function
5272 should return the number of gprs (or memory) partially passed,
5273 *not* the number of fprs. */
5274 && !(type
5275 && (cum->nargs_prototype <= 0
5276 || (DEFAULT_ABI == ABI_AIX
5277 && TARGET_XL_CALL
5278 && align_words >= GP_ARG_NUM_REG))))
4697a36c 5279 {
c53bdcf5 5280 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
ec6376ab 5281 ret = FP_ARG_MAX_REG + 1 - cum->fregno;
c53bdcf5 5282 else if (cum->nargs_prototype >= 0)
4697a36c
MM
5283 return 0;
5284 }
5285
ec6376ab
AM
5286 if (align_words < GP_ARG_NUM_REG
5287 && GP_ARG_NUM_REG < align_words + rs6000_arg_size (mode, type))
5288 ret = GP_ARG_NUM_REG - align_words;
4697a36c 5289
c53bdcf5
AM
5290 if (ret != 0 && TARGET_DEBUG_ARG)
5291 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 5292
c53bdcf5 5293 return ret;
4697a36c
MM
5294}
5295\f
5296/* A C expression that indicates when an argument must be passed by
5297 reference. If nonzero for an argument, a copy of that argument is
5298 made in memory and a pointer to the argument is passed instead of
5299 the argument itself. The pointer is passed in whatever way is
5300 appropriate for passing a pointer to that type.
5301
b2d04ecf
AM
5302 Under V.4, aggregates and long double are passed by reference.
5303
5304 As an extension to all 32-bit ABIs, AltiVec vectors are passed by
5305 reference unless the AltiVec vector extension ABI is in force.
c8c99a68
DE
5306
5307 As an extension to all ABIs, variable sized types are passed by
5308 reference. */
4697a36c 5309
8cd5a4e0 5310static bool
f676971a
EC
5311rs6000_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5312 enum machine_mode mode ATTRIBUTE_UNUSED,
8cd5a4e0 5313 tree type, bool named ATTRIBUTE_UNUSED)
4697a36c 5314{
b2d04ecf
AM
5315 if ((DEFAULT_ABI == ABI_V4
5316 && ((type && AGGREGATE_TYPE_P (type))
5317 || mode == TFmode))
5318 || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
5319 || (type && int_size_in_bytes (type) < 0))
4697a36c
MM
5320 {
5321 if (TARGET_DEBUG_ARG)
b2d04ecf 5322 fprintf (stderr, "function_arg_pass_by_reference\n");
4697a36c
MM
5323
5324 return 1;
5325 }
b2d04ecf 5326 return 0;
4697a36c 5327}
5985c7a6
FJ
5328
5329static void
2d9db8eb 5330rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
5331{
5332 int i;
5333 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
5334
5335 if (nregs == 0)
5336 return;
5337
c4ad648e 5338 for (i = 0; i < nregs; i++)
5985c7a6
FJ
5339 {
5340 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
5341 if (reload_completed)
c4ad648e
AM
5342 {
5343 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
5344 tem = NULL_RTX;
5345 else
5346 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
5347 i * GET_MODE_SIZE(reg_mode));
5348 }
5985c7a6
FJ
5349 else
5350 tem = replace_equiv_address (tem, XEXP (tem, 0));
5351
5352 if (tem == NULL_RTX)
c4ad648e 5353 abort ();
5985c7a6
FJ
5354
5355 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
5356 }
5357}
4697a36c
MM
5358\f
5359/* Perform any needed actions needed for a function that is receiving a
f676971a 5360 variable number of arguments.
4697a36c
MM
5361
5362 CUM is as above.
5363
5364 MODE and TYPE are the mode and type of the current parameter.
5365
5366 PRETEND_SIZE is a variable that should be set to the amount of stack
5367 that must be pushed by the prolog to pretend that our caller pushed
5368 it.
5369
5370 Normally, this macro will push all remaining incoming registers on the
5371 stack and set PRETEND_SIZE to the length of the registers pushed. */
5372
c6e8c921 5373static void
f676971a 5374setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
c4ad648e
AM
5375 tree type, int *pretend_size ATTRIBUTE_UNUSED,
5376 int no_rtl)
4697a36c 5377{
4cc833b7
RH
5378 CUMULATIVE_ARGS next_cum;
5379 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 5380 rtx save_area = NULL_RTX, mem;
dfafc897 5381 int first_reg_offset, set;
4697a36c 5382
f31bf321 5383 /* Skip the last named argument. */
d34c5b80 5384 next_cum = *cum;
f31bf321 5385 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 5386
f607bc57 5387 if (DEFAULT_ABI == ABI_V4)
d34c5b80 5388 {
60e2d0ca 5389 if (! no_rtl)
2c4974b7 5390 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 5391 - RS6000_VARARGS_SIZE);
4cc833b7
RH
5392
5393 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 5394 }
60e2d0ca 5395 else
4697a36c 5396 {
d34c5b80 5397 first_reg_offset = next_cum.words;
4cc833b7 5398 save_area = virtual_incoming_args_rtx;
4697a36c 5399
fe984136 5400 if (targetm.calls.must_pass_in_stack (mode, type))
c53bdcf5 5401 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 5402 }
4697a36c 5403
dfafc897 5404 set = get_varargs_alias_set ();
5496b36f 5405 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 5406 {
dfafc897 5407 mem = gen_rtx_MEM (BLKmode,
c4ad648e 5408 plus_constant (save_area,
dfafc897 5409 first_reg_offset * reg_size)),
ba4828e0 5410 set_mem_alias_set (mem, set);
8ac61af7 5411 set_mem_align (mem, BITS_PER_WORD);
dfafc897 5412
f676971a 5413 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
c4ad648e 5414 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
5415 }
5416
4697a36c 5417 /* Save FP registers if needed. */
f607bc57 5418 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
5419 && TARGET_HARD_FLOAT && TARGET_FPRS
5420 && ! no_rtl
5496b36f 5421 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 5422 {
5496b36f 5423 int fregno = next_cum.fregno;
9ebbca7d 5424 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
5425 rtx lab = gen_label_rtx ();
5426 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 5427
c4ad648e
AM
5428 emit_jump_insn
5429 (gen_rtx_SET (VOIDmode,
5430 pc_rtx,
5431 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7 5432 gen_rtx_NE (VOIDmode, cr1,
c4ad648e 5433 const0_rtx),
39403d82 5434 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
5435 pc_rtx)));
5436
5496b36f 5437 while (fregno <= FP_ARG_V4_MAX_REG)
4cc833b7 5438 {
5496b36f 5439 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
c4ad648e 5440 set_mem_alias_set (mem, set);
dfafc897 5441 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
5496b36f
JJ
5442 fregno++;
5443 off += 8;
4697a36c 5444 }
4cc833b7
RH
5445
5446 emit_label (lab);
4697a36c 5447 }
4697a36c 5448}
4697a36c 5449
dfafc897 5450/* Create the va_list data type. */
2c4974b7 5451
c35d187f
RH
5452static tree
5453rs6000_build_builtin_va_list (void)
dfafc897 5454{
64c2816f 5455 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 5456
9ebbca7d
GK
5457 /* For AIX, prefer 'char *' because that's what the system
5458 header files like. */
f607bc57 5459 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 5460 return build_pointer_type (char_type_node);
dfafc897 5461
f1e639b1 5462 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 5463 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 5464
f676971a 5465 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
9ebbca7d 5466 unsigned_char_type_node);
f676971a 5467 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
9ebbca7d 5468 unsigned_char_type_node);
64c2816f
DT
5469 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
5470 every user file. */
5471 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
5472 short_unsigned_type_node);
dfafc897
FS
5473 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
5474 ptr_type_node);
5475 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
5476 ptr_type_node);
5477
5478 DECL_FIELD_CONTEXT (f_gpr) = record;
5479 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 5480 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
5481 DECL_FIELD_CONTEXT (f_ovf) = record;
5482 DECL_FIELD_CONTEXT (f_sav) = record;
5483
bab45a51
FS
5484 TREE_CHAIN (record) = type_decl;
5485 TYPE_NAME (record) = type_decl;
dfafc897
FS
5486 TYPE_FIELDS (record) = f_gpr;
5487 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
5488 TREE_CHAIN (f_fpr) = f_res;
5489 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
5490 TREE_CHAIN (f_ovf) = f_sav;
5491
5492 layout_type (record);
5493
5494 /* The correct type is an array type of one element. */
5495 return build_array_type (record, build_index_type (size_zero_node));
5496}
5497
5498/* Implement va_start. */
5499
5500void
a2369ed3 5501rs6000_va_start (tree valist, rtx nextarg)
4697a36c 5502{
dfafc897 5503 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 5504 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 5505 tree gpr, fpr, ovf, sav, t;
2c4974b7 5506
dfafc897 5507 /* Only SVR4 needs something special. */
f607bc57 5508 if (DEFAULT_ABI != ABI_V4)
dfafc897 5509 {
e5faf155 5510 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
5511 return;
5512 }
5513
973a648b 5514 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5515 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5516 f_res = TREE_CHAIN (f_fpr);
5517 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5518 f_sav = TREE_CHAIN (f_ovf);
5519
8ebecc3b 5520 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
44de5aeb
RK
5521 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5522 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5523 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5524 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
dfafc897
FS
5525
5526 /* Count number of gp and fp argument registers used. */
4cc833b7 5527 words = current_function_args_info.words;
dfafc897
FS
5528 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
5529 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
5530
5531 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
5532 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
5533 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
5534 words, n_gpr, n_fpr);
dfafc897 5535
5496b36f
JJ
5536 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr,
5537 build_int_cst (NULL_TREE, n_gpr));
5538 TREE_SIDE_EFFECTS (t) = 1;
5539 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
58c8adc1 5540
5496b36f
JJ
5541 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr,
5542 build_int_cst (NULL_TREE, n_fpr));
5543 TREE_SIDE_EFFECTS (t) = 1;
5544 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
dfafc897
FS
5545
5546 /* Find the overflow area. */
5547 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
5548 if (words != 0)
5549 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
7d60be94 5550 build_int_cst (NULL_TREE, words * UNITS_PER_WORD));
dfafc897
FS
5551 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5552 TREE_SIDE_EFFECTS (t) = 1;
5553 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5554
5555 /* Find the register save area. */
5556 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
5557 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
7d60be94 5558 build_int_cst (NULL_TREE, -RS6000_VARARGS_SIZE));
dfafc897
FS
5559 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
5560 TREE_SIDE_EFFECTS (t) = 1;
5561 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5562}
5563
5564/* Implement va_arg. */
5565
23a60a04
JM
5566tree
5567rs6000_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
cd3ce9b4 5568{
cd3ce9b4
JM
5569 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
5570 tree gpr, fpr, ovf, sav, reg, t, u;
08b0dc1b 5571 int size, rsize, n_reg, sav_ofs, sav_scale;
cd3ce9b4
JM
5572 tree lab_false, lab_over, addr;
5573 int align;
5574 tree ptrtype = build_pointer_type (type);
5575
08b0dc1b
RH
5576 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
5577 {
5578 t = rs6000_gimplify_va_arg (valist, ptrtype, pre_p, post_p);
5579 return build_fold_indirect_ref (t);
5580 }
5581
cd3ce9b4
JM
5582 if (DEFAULT_ABI != ABI_V4)
5583 {
08b0dc1b 5584 if (targetm.calls.split_complex_arg && TREE_CODE (type) == COMPLEX_TYPE)
cd3ce9b4
JM
5585 {
5586 tree elem_type = TREE_TYPE (type);
5587 enum machine_mode elem_mode = TYPE_MODE (elem_type);
5588 int elem_size = GET_MODE_SIZE (elem_mode);
5589
5590 if (elem_size < UNITS_PER_WORD)
5591 {
23a60a04 5592 tree real_part, imag_part;
cd3ce9b4
JM
5593 tree post = NULL_TREE;
5594
23a60a04
JM
5595 real_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5596 &post);
5597 /* Copy the value into a temporary, lest the formal temporary
5598 be reused out from under us. */
5599 real_part = get_initialized_tmp_var (real_part, pre_p, &post);
cd3ce9b4
JM
5600 append_to_statement_list (post, pre_p);
5601
23a60a04
JM
5602 imag_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5603 post_p);
cd3ce9b4 5604
23a60a04 5605 return build (COMPLEX_EXPR, type, real_part, imag_part);
cd3ce9b4
JM
5606 }
5607 }
5608
23a60a04 5609 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
cd3ce9b4
JM
5610 }
5611
5612 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
5613 f_fpr = TREE_CHAIN (f_gpr);
5614 f_res = TREE_CHAIN (f_fpr);
5615 f_ovf = TREE_CHAIN (f_res);
5616 f_sav = TREE_CHAIN (f_ovf);
5617
5618 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
44de5aeb
RK
5619 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5620 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5621 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5622 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
cd3ce9b4
JM
5623
5624 size = int_size_in_bytes (type);
5625 rsize = (size + 3) / 4;
5626 align = 1;
5627
08b0dc1b
RH
5628 if (TARGET_HARD_FLOAT && TARGET_FPRS
5629 && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode))
cd3ce9b4
JM
5630 {
5631 /* FP args go in FP registers, if present. */
cd3ce9b4
JM
5632 reg = fpr;
5633 n_reg = 1;
5634 sav_ofs = 8*4;
5635 sav_scale = 8;
5636 if (TYPE_MODE (type) == DFmode)
5637 align = 8;
5638 }
5639 else
5640 {
5641 /* Otherwise into GP registers. */
cd3ce9b4
JM
5642 reg = gpr;
5643 n_reg = rsize;
5644 sav_ofs = 0;
5645 sav_scale = 4;
5646 if (n_reg == 2)
5647 align = 8;
5648 }
5649
5650 /* Pull the value out of the saved registers.... */
5651
5652 lab_over = NULL;
5653 addr = create_tmp_var (ptr_type_node, "addr");
5654 DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
5655
5656 /* AltiVec vectors never go in registers when -mabi=altivec. */
5657 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
5658 align = 16;
5659 else
5660 {
5661 lab_false = create_artificial_label ();
5662 lab_over = create_artificial_label ();
5663
5664 /* Long long and SPE vectors are aligned in the registers.
5665 As are any other 2 gpr item such as complex int due to a
5666 historical mistake. */
5667 u = reg;
5668 if (n_reg == 2)
5669 {
5670 u = build2 (BIT_AND_EXPR, TREE_TYPE (reg), reg,
95674810 5671 size_int (n_reg - 1));
cd3ce9b4
JM
5672 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u);
5673 }
5674
95674810 5675 t = fold_convert (TREE_TYPE (reg), size_int (8 - n_reg + 1));
cd3ce9b4
JM
5676 t = build2 (GE_EXPR, boolean_type_node, u, t);
5677 u = build1 (GOTO_EXPR, void_type_node, lab_false);
5678 t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE);
5679 gimplify_and_add (t, pre_p);
5680
5681 t = sav;
5682 if (sav_ofs)
95674810 5683 t = build2 (PLUS_EXPR, ptr_type_node, sav, size_int (sav_ofs));
cd3ce9b4 5684
95674810 5685 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, size_int (n_reg));
cd3ce9b4 5686 u = build1 (CONVERT_EXPR, integer_type_node, u);
95674810 5687 u = build2 (MULT_EXPR, integer_type_node, u, size_int (sav_scale));
cd3ce9b4
JM
5688 t = build2 (PLUS_EXPR, ptr_type_node, t, u);
5689
5690 t = build2 (MODIFY_EXPR, void_type_node, addr, t);
5691 gimplify_and_add (t, pre_p);
5692
5693 t = build1 (GOTO_EXPR, void_type_node, lab_over);
5694 gimplify_and_add (t, pre_p);
5695
5696 t = build1 (LABEL_EXPR, void_type_node, lab_false);
5697 append_to_statement_list (t, pre_p);
5698
5699 if (n_reg > 2)
5700 {
5701 /* Ensure that we don't find any more args in regs.
5702 Alignment has taken care of the n_reg == 2 case. */
95674810 5703 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, size_int (8));
cd3ce9b4
JM
5704 gimplify_and_add (t, pre_p);
5705 }
5706 }
5707
5708 /* ... otherwise out of the overflow area. */
5709
5710 /* Care for on-stack alignment if needed. */
5711 t = ovf;
5712 if (align != 1)
5713 {
95674810 5714 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (align - 1));
4a90aeeb 5715 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
7d60be94 5716 build_int_cst (NULL_TREE, -align));
cd3ce9b4
JM
5717 }
5718 gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
5719
5720 u = build2 (MODIFY_EXPR, void_type_node, addr, t);
5721 gimplify_and_add (u, pre_p);
5722
95674810 5723 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (size));
cd3ce9b4
JM
5724 t = build2 (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5725 gimplify_and_add (t, pre_p);
5726
5727 if (lab_over)
5728 {
5729 t = build1 (LABEL_EXPR, void_type_node, lab_over);
5730 append_to_statement_list (t, pre_p);
5731 }
5732
08b0dc1b 5733 addr = fold_convert (ptrtype, addr);
23a60a04 5734 return build_fold_indirect_ref (addr);
cd3ce9b4
JM
5735}
5736
0ac081f6
AH
5737/* Builtins. */
5738
6e34d3a3
JM
5739#define def_builtin(MASK, NAME, TYPE, CODE) \
5740do { \
5741 if ((MASK) & target_flags) \
5742 lang_hooks.builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
5743 NULL, NULL_TREE); \
0ac081f6
AH
5744} while (0)
5745
24408032
AH
5746/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
5747
2212663f 5748static const struct builtin_description bdesc_3arg[] =
24408032
AH
5749{
5750 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
5751 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
5752 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
5753 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
5754 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
5755 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
5756 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
5757 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
5758 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
5759 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
f676971a 5760 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
24408032
AH
5761 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
5762 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
5763 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
5764 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
5765 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
5766 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
5767 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
5768 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
5769 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
5770 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
5771 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
5772 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
5773};
2212663f 5774
95385cbb
AH
5775/* DST operations: void foo (void *, const int, const char). */
5776
5777static const struct builtin_description bdesc_dst[] =
5778{
5779 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
5780 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
5781 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
5782 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
5783};
5784
2212663f 5785/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 5786
a3170dc6 5787static struct builtin_description bdesc_2arg[] =
0ac081f6 5788{
f18c054f
DB
5789 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
5790 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
5791 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
5792 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
5793 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
5794 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
5795 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
5796 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
5797 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
5798 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
5799 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 5800 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
5801 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
5802 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
5803 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
5804 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
5805 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
5806 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
5807 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
5808 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
5809 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
5810 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
5811 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
5812 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5813 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5814 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5815 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5816 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5817 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5818 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5819 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5820 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5821 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5822 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5823 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5824 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5825 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5826 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5827 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5828 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5829 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5830 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5831 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5832 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5833 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5834 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5835 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5836 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5837 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5838 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5839 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5840 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5841 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5842 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5843 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5844 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5845 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5846 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5847 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5848 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5849 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5850 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5851 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5852 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5853 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5854 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5855 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5856 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5857 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5858 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5859 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5860 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5861 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5862 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5863 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5864 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5865 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5866 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5867 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5868 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5869 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5870 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5871 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5872 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5873 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5874 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5875 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5876 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5877 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5878 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5879 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5880 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5881 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5882 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5883 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5884 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5885 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5886 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5887 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5888 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5889 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5890 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5891 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5892 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5893 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5894 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5895 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5896 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5897 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5898 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5899 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5900 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5901 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5902
5903 /* Place holder, leave as first spe builtin. */
5904 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5905 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5906 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5907 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5908 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5909 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5910 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5911 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5912 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5913 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5914 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5915 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5916 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5917 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5918 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5919 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5920 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5921 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5922 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5923 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5924 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5925 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5926 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5927 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5928 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5929 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5930 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5931 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5932 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5933 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5934 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5935 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5936 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5937 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5938 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5939 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5940 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5941 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5942 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5943 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5944 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5945 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5946 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5947 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5948 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5949 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5950 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5951 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5952 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5953 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5954 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5955 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5956 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5957 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5958 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5959 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5960 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5961 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5962 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5963 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5964 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5965 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5966 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5967 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5968 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5969 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5970 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5971 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5972 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5973 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5974 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5975 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5976 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5977 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5978 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5979 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5980 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5981 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5982 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5983 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5984 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5985 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5986 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5987 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5988 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5989 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5990 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5991 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5992 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5993 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5994 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5995 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5996 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5997 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5998 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5999 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
6000 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
6001 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
6002 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
6003 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
6004 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
6005 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
6006 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
6007 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
6008 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
6009 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
6010 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
6011 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
6012 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
6013
6014 /* SPE binary operations expecting a 5-bit unsigned literal. */
6015 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
6016
6017 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
6018 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
6019 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
6020 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
6021 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
6022 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
6023 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
6024 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
6025 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
6026 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
6027 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
6028 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
6029 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
6030 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
6031 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
6032 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
6033 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
6034 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
6035 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
6036 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
6037 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
6038 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
6039 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
6040 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
6041 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
6042 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
6043
6044 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 6045 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
6046};
6047
6048/* AltiVec predicates. */
6049
6050struct builtin_description_predicates
6051{
6052 const unsigned int mask;
6053 const enum insn_code icode;
6054 const char *opcode;
6055 const char *const name;
6056 const enum rs6000_builtins code;
6057};
6058
6059static const struct builtin_description_predicates bdesc_altivec_preds[] =
6060{
6061 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
6062 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
6063 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
6064 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
6065 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
6066 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
6067 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
6068 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
6069 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
6070 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
6071 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
6072 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
6073 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 6074};
24408032 6075
a3170dc6
AH
6076/* SPE predicates. */
6077static struct builtin_description bdesc_spe_predicates[] =
6078{
6079 /* Place-holder. Leave as first. */
6080 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
6081 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
6082 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
6083 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
6084 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
6085 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
6086 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
6087 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
6088 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
6089 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
6090 /* Place-holder. Leave as last. */
6091 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
6092};
6093
6094/* SPE evsel predicates. */
6095static struct builtin_description bdesc_spe_evsel[] =
6096{
6097 /* Place-holder. Leave as first. */
6098 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
6099 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
6100 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
6101 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
6102 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
6103 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
6104 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
6105 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
6106 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
6107 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
6108 /* Place-holder. Leave as last. */
6109 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
6110};
6111
b6d08ca1 6112/* ABS* operations. */
100c4561
AH
6113
6114static const struct builtin_description bdesc_abs[] =
6115{
6116 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
6117 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
6118 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
6119 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
6120 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
6121 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
6122 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
6123};
6124
617e0e1d
DB
6125/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
6126 foo (VECa). */
24408032 6127
a3170dc6 6128static struct builtin_description bdesc_1arg[] =
2212663f 6129{
617e0e1d
DB
6130 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
6131 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
6132 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
6133 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
6134 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
6135 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
6136 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
6137 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
6138 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
6139 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
6140 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
6141 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
6142 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
6143 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
6144 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
6145 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
6146 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
6147
6148 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
6149 end with SPE_BUILTIN_EVSUBFUSIAAW. */
6150 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
6151 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
6152 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
6153 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
6154 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
6155 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
6156 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
6157 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
6158 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
6159 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
6160 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
6161 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
6162 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
6163 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
6164 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
6165 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
6166 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
6167 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
6168 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
6169 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
6170 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
6171 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
6172 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
6a599451 6173 { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
a3170dc6
AH
6174 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
6175 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
6176 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
6177 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
6178
6179 /* Place-holder. Leave as last unary SPE builtin. */
6180 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
6181};
6182
6183static rtx
a2369ed3 6184rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6185{
6186 rtx pat;
6187 tree arg0 = TREE_VALUE (arglist);
6188 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6189 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6190 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6191
0559cc77
DE
6192 if (icode == CODE_FOR_nothing)
6193 /* Builtin not supported on this processor. */
6194 return 0;
6195
20e26713
AH
6196 /* If we got invalid arguments bail out before generating bad rtl. */
6197 if (arg0 == error_mark_node)
9a171fcd 6198 return const0_rtx;
20e26713 6199
0559cc77
DE
6200 if (icode == CODE_FOR_altivec_vspltisb
6201 || icode == CODE_FOR_altivec_vspltish
6202 || icode == CODE_FOR_altivec_vspltisw
6203 || icode == CODE_FOR_spe_evsplatfi
6204 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
6205 {
6206 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
6207 if (GET_CODE (op0) != CONST_INT
6208 || INTVAL (op0) > 0x1f
6209 || INTVAL (op0) < -0x1f)
6210 {
6211 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 6212 return const0_rtx;
b44140e7 6213 }
b44140e7
AH
6214 }
6215
c62f2db5 6216 if (target == 0
2212663f
DB
6217 || GET_MODE (target) != tmode
6218 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6219 target = gen_reg_rtx (tmode);
6220
6221 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6222 op0 = copy_to_mode_reg (mode0, op0);
6223
6224 pat = GEN_FCN (icode) (target, op0);
6225 if (! pat)
6226 return 0;
6227 emit_insn (pat);
0ac081f6 6228
2212663f
DB
6229 return target;
6230}
ae4b4a02 6231
100c4561 6232static rtx
a2369ed3 6233altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
6234{
6235 rtx pat, scratch1, scratch2;
6236 tree arg0 = TREE_VALUE (arglist);
6237 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6238 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6239 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6240
6241 /* If we have invalid arguments, bail out before generating bad rtl. */
6242 if (arg0 == error_mark_node)
9a171fcd 6243 return const0_rtx;
100c4561
AH
6244
6245 if (target == 0
6246 || GET_MODE (target) != tmode
6247 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6248 target = gen_reg_rtx (tmode);
6249
6250 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6251 op0 = copy_to_mode_reg (mode0, op0);
6252
6253 scratch1 = gen_reg_rtx (mode0);
6254 scratch2 = gen_reg_rtx (mode0);
6255
6256 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
6257 if (! pat)
6258 return 0;
6259 emit_insn (pat);
6260
6261 return target;
6262}
6263
0ac081f6 6264static rtx
a2369ed3 6265rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
6266{
6267 rtx pat;
6268 tree arg0 = TREE_VALUE (arglist);
6269 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6270 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6271 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6272 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6273 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6274 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6275
0559cc77
DE
6276 if (icode == CODE_FOR_nothing)
6277 /* Builtin not supported on this processor. */
6278 return 0;
6279
20e26713
AH
6280 /* If we got invalid arguments bail out before generating bad rtl. */
6281 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6282 return const0_rtx;
20e26713 6283
0559cc77
DE
6284 if (icode == CODE_FOR_altivec_vcfux
6285 || icode == CODE_FOR_altivec_vcfsx
6286 || icode == CODE_FOR_altivec_vctsxs
6287 || icode == CODE_FOR_altivec_vctuxs
6288 || icode == CODE_FOR_altivec_vspltb
6289 || icode == CODE_FOR_altivec_vsplth
6290 || icode == CODE_FOR_altivec_vspltw
6291 || icode == CODE_FOR_spe_evaddiw
6292 || icode == CODE_FOR_spe_evldd
6293 || icode == CODE_FOR_spe_evldh
6294 || icode == CODE_FOR_spe_evldw
6295 || icode == CODE_FOR_spe_evlhhesplat
6296 || icode == CODE_FOR_spe_evlhhossplat
6297 || icode == CODE_FOR_spe_evlhhousplat
6298 || icode == CODE_FOR_spe_evlwhe
6299 || icode == CODE_FOR_spe_evlwhos
6300 || icode == CODE_FOR_spe_evlwhou
6301 || icode == CODE_FOR_spe_evlwhsplat
6302 || icode == CODE_FOR_spe_evlwwsplat
6303 || icode == CODE_FOR_spe_evrlwi
6304 || icode == CODE_FOR_spe_evslwi
6305 || icode == CODE_FOR_spe_evsrwis
f5119d10 6306 || icode == CODE_FOR_spe_evsubifw
0559cc77 6307 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
6308 {
6309 /* Only allow 5-bit unsigned literals. */
8bb418a3 6310 STRIP_NOPS (arg1);
b44140e7
AH
6311 if (TREE_CODE (arg1) != INTEGER_CST
6312 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6313 {
6314 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 6315 return const0_rtx;
b44140e7 6316 }
b44140e7
AH
6317 }
6318
c62f2db5 6319 if (target == 0
0ac081f6
AH
6320 || GET_MODE (target) != tmode
6321 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6322 target = gen_reg_rtx (tmode);
6323
6324 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6325 op0 = copy_to_mode_reg (mode0, op0);
6326 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6327 op1 = copy_to_mode_reg (mode1, op1);
6328
6329 pat = GEN_FCN (icode) (target, op0, op1);
6330 if (! pat)
6331 return 0;
6332 emit_insn (pat);
6333
6334 return target;
6335}
6525c0e7 6336
ae4b4a02 6337static rtx
f676971a 6338altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
a2369ed3 6339 tree arglist, rtx target)
ae4b4a02
AH
6340{
6341 rtx pat, scratch;
6342 tree cr6_form = TREE_VALUE (arglist);
6343 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6344 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6345 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6346 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6347 enum machine_mode tmode = SImode;
6348 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6349 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6350 int cr6_form_int;
6351
6352 if (TREE_CODE (cr6_form) != INTEGER_CST)
6353 {
6354 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 6355 return const0_rtx;
ae4b4a02
AH
6356 }
6357 else
6358 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
6359
6360 if (mode0 != mode1)
6361 abort ();
6362
6363 /* If we have invalid arguments, bail out before generating bad rtl. */
6364 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6365 return const0_rtx;
ae4b4a02
AH
6366
6367 if (target == 0
6368 || GET_MODE (target) != tmode
6369 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6370 target = gen_reg_rtx (tmode);
6371
6372 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6373 op0 = copy_to_mode_reg (mode0, op0);
6374 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6375 op1 = copy_to_mode_reg (mode1, op1);
6376
6377 scratch = gen_reg_rtx (mode0);
6378
6379 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 6380 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
6381 if (! pat)
6382 return 0;
6383 emit_insn (pat);
6384
6385 /* The vec_any* and vec_all* predicates use the same opcodes for two
6386 different operations, but the bits in CR6 will be different
6387 depending on what information we want. So we have to play tricks
6388 with CR6 to get the right bits out.
6389
6390 If you think this is disgusting, look at the specs for the
6391 AltiVec predicates. */
6392
c4ad648e
AM
6393 switch (cr6_form_int)
6394 {
6395 case 0:
6396 emit_insn (gen_cr6_test_for_zero (target));
6397 break;
6398 case 1:
6399 emit_insn (gen_cr6_test_for_zero_reverse (target));
6400 break;
6401 case 2:
6402 emit_insn (gen_cr6_test_for_lt (target));
6403 break;
6404 case 3:
6405 emit_insn (gen_cr6_test_for_lt_reverse (target));
6406 break;
6407 default:
6408 error ("argument 1 of __builtin_altivec_predicate is out of range");
6409 break;
6410 }
ae4b4a02
AH
6411
6412 return target;
6413}
6414
b4a62fa0 6415static rtx
38f391a5 6416altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
6417{
6418 rtx pat, addr;
6419 tree arg0 = TREE_VALUE (arglist);
6420 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6421 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6422 enum machine_mode mode0 = Pmode;
6423 enum machine_mode mode1 = Pmode;
6424 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6425 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6426
6427 if (icode == CODE_FOR_nothing)
6428 /* Builtin not supported on this processor. */
6429 return 0;
6430
6431 /* If we got invalid arguments bail out before generating bad rtl. */
6432 if (arg0 == error_mark_node || arg1 == error_mark_node)
6433 return const0_rtx;
6434
6435 if (target == 0
6436 || GET_MODE (target) != tmode
6437 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6438 target = gen_reg_rtx (tmode);
6439
f676971a 6440 op1 = copy_to_mode_reg (mode1, op1);
b4a62fa0
SB
6441
6442 if (op0 == const0_rtx)
6443 {
6444 addr = gen_rtx_MEM (tmode, op1);
6445 }
6446 else
6447 {
6448 op0 = copy_to_mode_reg (mode0, op0);
6449 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
6450 }
6451
6452 pat = GEN_FCN (icode) (target, addr);
6453
6454 if (! pat)
6455 return 0;
6456 emit_insn (pat);
6457
6458 return target;
6459}
6460
61bea3b0
AH
6461static rtx
6462spe_expand_stv_builtin (enum insn_code icode, tree arglist)
6463{
6464 tree arg0 = TREE_VALUE (arglist);
6465 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6466 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6467 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6468 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6469 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6470 rtx pat;
6471 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
6472 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
6473 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
6474
6475 /* Invalid arguments. Bail before doing anything stoopid! */
6476 if (arg0 == error_mark_node
6477 || arg1 == error_mark_node
6478 || arg2 == error_mark_node)
6479 return const0_rtx;
6480
6481 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
6482 op0 = copy_to_mode_reg (mode2, op0);
6483 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
6484 op1 = copy_to_mode_reg (mode0, op1);
6485 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6486 op2 = copy_to_mode_reg (mode1, op2);
6487
6488 pat = GEN_FCN (icode) (op1, op2, op0);
6489 if (pat)
6490 emit_insn (pat);
6491 return NULL_RTX;
6492}
6493
6525c0e7 6494static rtx
a2369ed3 6495altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
6496{
6497 tree arg0 = TREE_VALUE (arglist);
6498 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6499 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6500 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6501 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6502 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
6503 rtx pat, addr;
6504 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6505 enum machine_mode mode1 = Pmode;
6506 enum machine_mode mode2 = Pmode;
6525c0e7
AH
6507
6508 /* Invalid arguments. Bail before doing anything stoopid! */
6509 if (arg0 == error_mark_node
6510 || arg1 == error_mark_node
6511 || arg2 == error_mark_node)
9a171fcd 6512 return const0_rtx;
6525c0e7 6513
b4a62fa0
SB
6514 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
6515 op0 = copy_to_mode_reg (tmode, op0);
6516
f676971a 6517 op2 = copy_to_mode_reg (mode2, op2);
b4a62fa0
SB
6518
6519 if (op1 == const0_rtx)
6520 {
6521 addr = gen_rtx_MEM (tmode, op2);
6522 }
6523 else
6524 {
6525 op1 = copy_to_mode_reg (mode1, op1);
6526 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
6527 }
6525c0e7 6528
b4a62fa0 6529 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
6530 if (pat)
6531 emit_insn (pat);
6532 return NULL_RTX;
6533}
6534
2212663f 6535static rtx
a2369ed3 6536rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6537{
6538 rtx pat;
6539 tree arg0 = TREE_VALUE (arglist);
6540 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6541 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6542 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6543 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6544 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6545 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6546 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6547 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6548 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 6549
774b5662
DE
6550 if (icode == CODE_FOR_nothing)
6551 /* Builtin not supported on this processor. */
6552 return 0;
6553
20e26713
AH
6554 /* If we got invalid arguments bail out before generating bad rtl. */
6555 if (arg0 == error_mark_node
6556 || arg1 == error_mark_node
6557 || arg2 == error_mark_node)
9a171fcd 6558 return const0_rtx;
20e26713 6559
774b5662
DE
6560 if (icode == CODE_FOR_altivec_vsldoi_4sf
6561 || icode == CODE_FOR_altivec_vsldoi_4si
6562 || icode == CODE_FOR_altivec_vsldoi_8hi
6563 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
6564 {
6565 /* Only allow 4-bit unsigned literals. */
8bb418a3 6566 STRIP_NOPS (arg2);
b44140e7
AH
6567 if (TREE_CODE (arg2) != INTEGER_CST
6568 || TREE_INT_CST_LOW (arg2) & ~0xf)
6569 {
6570 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 6571 return const0_rtx;
b44140e7 6572 }
b44140e7
AH
6573 }
6574
c62f2db5 6575 if (target == 0
2212663f
DB
6576 || GET_MODE (target) != tmode
6577 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6578 target = gen_reg_rtx (tmode);
6579
6580 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6581 op0 = copy_to_mode_reg (mode0, op0);
6582 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6583 op1 = copy_to_mode_reg (mode1, op1);
6584 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
6585 op2 = copy_to_mode_reg (mode2, op2);
6586
6587 pat = GEN_FCN (icode) (target, op0, op1, op2);
6588 if (! pat)
6589 return 0;
6590 emit_insn (pat);
6591
6592 return target;
6593}
92898235 6594
3a9b8c7e 6595/* Expand the lvx builtins. */
0ac081f6 6596static rtx
a2369ed3 6597altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 6598{
0ac081f6
AH
6599 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6600 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 6601 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
6602 tree arg0;
6603 enum machine_mode tmode, mode0;
7c3abc73 6604 rtx pat, op0;
3a9b8c7e 6605 enum insn_code icode;
92898235 6606
0ac081f6
AH
6607 switch (fcode)
6608 {
f18c054f
DB
6609 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
6610 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 6611 break;
f18c054f
DB
6612 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
6613 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
6614 break;
6615 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
6616 icode = CODE_FOR_altivec_lvx_4si;
6617 break;
6618 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
6619 icode = CODE_FOR_altivec_lvx_4sf;
6620 break;
6621 default:
6622 *expandedp = false;
6623 return NULL_RTX;
6624 }
0ac081f6 6625
3a9b8c7e 6626 *expandedp = true;
f18c054f 6627
3a9b8c7e
AH
6628 arg0 = TREE_VALUE (arglist);
6629 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6630 tmode = insn_data[icode].operand[0].mode;
6631 mode0 = insn_data[icode].operand[1].mode;
f18c054f 6632
3a9b8c7e
AH
6633 if (target == 0
6634 || GET_MODE (target) != tmode
6635 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6636 target = gen_reg_rtx (tmode);
24408032 6637
3a9b8c7e
AH
6638 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6639 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 6640
3a9b8c7e
AH
6641 pat = GEN_FCN (icode) (target, op0);
6642 if (! pat)
6643 return 0;
6644 emit_insn (pat);
6645 return target;
6646}
f18c054f 6647
3a9b8c7e
AH
6648/* Expand the stvx builtins. */
6649static rtx
f676971a 6650altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 6651 bool *expandedp)
3a9b8c7e
AH
6652{
6653 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6654 tree arglist = TREE_OPERAND (exp, 1);
6655 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6656 tree arg0, arg1;
6657 enum machine_mode mode0, mode1;
7c3abc73 6658 rtx pat, op0, op1;
3a9b8c7e 6659 enum insn_code icode;
f18c054f 6660
3a9b8c7e
AH
6661 switch (fcode)
6662 {
6663 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
6664 icode = CODE_FOR_altivec_stvx_16qi;
6665 break;
6666 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
6667 icode = CODE_FOR_altivec_stvx_8hi;
6668 break;
6669 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
6670 icode = CODE_FOR_altivec_stvx_4si;
6671 break;
6672 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
6673 icode = CODE_FOR_altivec_stvx_4sf;
6674 break;
6675 default:
6676 *expandedp = false;
6677 return NULL_RTX;
6678 }
24408032 6679
3a9b8c7e
AH
6680 arg0 = TREE_VALUE (arglist);
6681 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6682 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6683 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6684 mode0 = insn_data[icode].operand[0].mode;
6685 mode1 = insn_data[icode].operand[1].mode;
f18c054f 6686
3a9b8c7e
AH
6687 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6688 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
6689 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6690 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 6691
3a9b8c7e
AH
6692 pat = GEN_FCN (icode) (op0, op1);
6693 if (pat)
6694 emit_insn (pat);
f18c054f 6695
3a9b8c7e
AH
6696 *expandedp = true;
6697 return NULL_RTX;
6698}
f18c054f 6699
3a9b8c7e
AH
6700/* Expand the dst builtins. */
6701static rtx
f676971a 6702altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 6703 bool *expandedp)
3a9b8c7e
AH
6704{
6705 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6706 tree arglist = TREE_OPERAND (exp, 1);
6707 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6708 tree arg0, arg1, arg2;
6709 enum machine_mode mode0, mode1, mode2;
7c3abc73 6710 rtx pat, op0, op1, op2;
3a9b8c7e 6711 struct builtin_description *d;
a3170dc6 6712 size_t i;
f18c054f 6713
3a9b8c7e 6714 *expandedp = false;
f18c054f 6715
3a9b8c7e
AH
6716 /* Handle DST variants. */
6717 d = (struct builtin_description *) bdesc_dst;
6718 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
6719 if (d->code == fcode)
6720 {
6721 arg0 = TREE_VALUE (arglist);
6722 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6723 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6724 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6725 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6726 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6727 mode0 = insn_data[d->icode].operand[0].mode;
6728 mode1 = insn_data[d->icode].operand[1].mode;
6729 mode2 = insn_data[d->icode].operand[2].mode;
24408032 6730
3a9b8c7e
AH
6731 /* Invalid arguments, bail out before generating bad rtl. */
6732 if (arg0 == error_mark_node
6733 || arg1 == error_mark_node
6734 || arg2 == error_mark_node)
6735 return const0_rtx;
f18c054f 6736
86e7df90 6737 *expandedp = true;
8bb418a3 6738 STRIP_NOPS (arg2);
3a9b8c7e
AH
6739 if (TREE_CODE (arg2) != INTEGER_CST
6740 || TREE_INT_CST_LOW (arg2) & ~0x3)
6741 {
6742 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
6743 return const0_rtx;
6744 }
f18c054f 6745
3a9b8c7e 6746 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 6747 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
6748 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
6749 op1 = copy_to_mode_reg (mode1, op1);
24408032 6750
3a9b8c7e
AH
6751 pat = GEN_FCN (d->icode) (op0, op1, op2);
6752 if (pat != 0)
6753 emit_insn (pat);
f18c054f 6754
3a9b8c7e
AH
6755 return NULL_RTX;
6756 }
f18c054f 6757
3a9b8c7e
AH
6758 return NULL_RTX;
6759}
24408032 6760
3a9b8c7e
AH
6761/* Expand the builtin in EXP and store the result in TARGET. Store
6762 true in *EXPANDEDP if we found a builtin to expand. */
6763static rtx
a2369ed3 6764altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
6765{
6766 struct builtin_description *d;
6767 struct builtin_description_predicates *dp;
6768 size_t i;
6769 enum insn_code icode;
6770 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6771 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
6772 tree arg0;
6773 rtx op0, pat;
6774 enum machine_mode tmode, mode0;
3a9b8c7e 6775 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 6776
3a9b8c7e
AH
6777 target = altivec_expand_ld_builtin (exp, target, expandedp);
6778 if (*expandedp)
6779 return target;
0ac081f6 6780
3a9b8c7e
AH
6781 target = altivec_expand_st_builtin (exp, target, expandedp);
6782 if (*expandedp)
6783 return target;
6784
6785 target = altivec_expand_dst_builtin (exp, target, expandedp);
6786 if (*expandedp)
6787 return target;
6788
6789 *expandedp = true;
95385cbb 6790
3a9b8c7e
AH
6791 switch (fcode)
6792 {
6525c0e7
AH
6793 case ALTIVEC_BUILTIN_STVX:
6794 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
6795 case ALTIVEC_BUILTIN_STVEBX:
6796 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
6797 case ALTIVEC_BUILTIN_STVEHX:
6798 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
6799 case ALTIVEC_BUILTIN_STVEWX:
6800 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
6801 case ALTIVEC_BUILTIN_STVXL:
6802 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 6803
95385cbb
AH
6804 case ALTIVEC_BUILTIN_MFVSCR:
6805 icode = CODE_FOR_altivec_mfvscr;
6806 tmode = insn_data[icode].operand[0].mode;
6807
6808 if (target == 0
6809 || GET_MODE (target) != tmode
6810 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6811 target = gen_reg_rtx (tmode);
f676971a 6812
95385cbb 6813 pat = GEN_FCN (icode) (target);
0ac081f6
AH
6814 if (! pat)
6815 return 0;
6816 emit_insn (pat);
95385cbb
AH
6817 return target;
6818
6819 case ALTIVEC_BUILTIN_MTVSCR:
6820 icode = CODE_FOR_altivec_mtvscr;
6821 arg0 = TREE_VALUE (arglist);
6822 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6823 mode0 = insn_data[icode].operand[0].mode;
6824
6825 /* If we got invalid arguments bail out before generating bad rtl. */
6826 if (arg0 == error_mark_node)
9a171fcd 6827 return const0_rtx;
95385cbb
AH
6828
6829 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6830 op0 = copy_to_mode_reg (mode0, op0);
6831
6832 pat = GEN_FCN (icode) (op0);
6833 if (pat)
6834 emit_insn (pat);
6835 return NULL_RTX;
3a9b8c7e 6836
95385cbb
AH
6837 case ALTIVEC_BUILTIN_DSSALL:
6838 emit_insn (gen_altivec_dssall ());
6839 return NULL_RTX;
6840
6841 case ALTIVEC_BUILTIN_DSS:
6842 icode = CODE_FOR_altivec_dss;
6843 arg0 = TREE_VALUE (arglist);
8bb418a3 6844 STRIP_NOPS (arg0);
95385cbb
AH
6845 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6846 mode0 = insn_data[icode].operand[0].mode;
6847
6848 /* If we got invalid arguments bail out before generating bad rtl. */
6849 if (arg0 == error_mark_node)
9a171fcd 6850 return const0_rtx;
95385cbb 6851
b44140e7
AH
6852 if (TREE_CODE (arg0) != INTEGER_CST
6853 || TREE_INT_CST_LOW (arg0) & ~0x3)
6854 {
6855 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6856 return const0_rtx;
b44140e7
AH
6857 }
6858
95385cbb
AH
6859 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6860 op0 = copy_to_mode_reg (mode0, op0);
6861
6862 emit_insn (gen_altivec_dss (op0));
0ac081f6 6863 return NULL_RTX;
f676971a 6864
8bb418a3
ZL
6865 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
6866 arg0 = TREE_VALUE (arglist);
97dc04b3 6867 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR
c4ad648e 6868 || TREE_CODE (arg0) == ARRAY_REF)
8bb418a3
ZL
6869 arg0 = TREE_OPERAND (arg0, 0);
6870 error ("invalid parameter combination for `%s' AltiVec intrinsic",
6871 TREE_STRING_POINTER (arg0));
6872
6873 return const0_rtx;
0ac081f6 6874 }
24408032 6875
100c4561
AH
6876 /* Expand abs* operations. */
6877 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6878 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6879 if (d->code == fcode)
6880 return altivec_expand_abs_builtin (d->icode, arglist, target);
6881
ae4b4a02
AH
6882 /* Expand the AltiVec predicates. */
6883 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6884 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02 6885 if (dp->code == fcode)
c4ad648e
AM
6886 return altivec_expand_predicate_builtin (dp->icode, dp->opcode,
6887 arglist, target);
ae4b4a02 6888
6525c0e7
AH
6889 /* LV* are funky. We initialized them differently. */
6890 switch (fcode)
6891 {
6892 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6893 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
c4ad648e 6894 arglist, target);
6525c0e7 6895 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6896 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
c4ad648e 6897 arglist, target);
6525c0e7 6898 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6899 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
c4ad648e 6900 arglist, target);
6525c0e7 6901 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6902 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
c4ad648e 6903 arglist, target);
6525c0e7 6904 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6905 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
c4ad648e 6906 arglist, target);
6525c0e7 6907 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6908 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
c4ad648e 6909 arglist, target);
6525c0e7 6910 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6911 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
c4ad648e 6912 arglist, target);
6525c0e7
AH
6913 default:
6914 break;
6915 /* Fall through. */
6916 }
95385cbb 6917
92898235 6918 *expandedp = false;
0ac081f6
AH
6919 return NULL_RTX;
6920}
6921
a3170dc6
AH
6922/* Binops that need to be initialized manually, but can be expanded
6923 automagically by rs6000_expand_binop_builtin. */
6924static struct builtin_description bdesc_2arg_spe[] =
6925{
6926 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6927 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6928 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6929 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6930 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6931 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6932 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6933 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6934 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6935 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6936 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6937 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6938 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6939 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6940 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6941 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6942 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6943 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6944 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6945 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6946 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6947 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6948};
6949
6950/* Expand the builtin in EXP and store the result in TARGET. Store
6951 true in *EXPANDEDP if we found a builtin to expand.
6952
6953 This expands the SPE builtins that are not simple unary and binary
6954 operations. */
6955static rtx
a2369ed3 6956spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6957{
6958 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6959 tree arglist = TREE_OPERAND (exp, 1);
6960 tree arg1, arg0;
6961 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6962 enum insn_code icode;
6963 enum machine_mode tmode, mode0;
6964 rtx pat, op0;
6965 struct builtin_description *d;
6966 size_t i;
6967
6968 *expandedp = true;
6969
6970 /* Syntax check for a 5-bit unsigned immediate. */
6971 switch (fcode)
6972 {
6973 case SPE_BUILTIN_EVSTDD:
6974 case SPE_BUILTIN_EVSTDH:
6975 case SPE_BUILTIN_EVSTDW:
6976 case SPE_BUILTIN_EVSTWHE:
6977 case SPE_BUILTIN_EVSTWHO:
6978 case SPE_BUILTIN_EVSTWWE:
6979 case SPE_BUILTIN_EVSTWWO:
6980 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6981 if (TREE_CODE (arg1) != INTEGER_CST
6982 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6983 {
6984 error ("argument 2 must be a 5-bit unsigned literal");
6985 return const0_rtx;
6986 }
6987 break;
6988 default:
6989 break;
6990 }
6991
00332c9f
AH
6992 /* The evsplat*i instructions are not quite generic. */
6993 switch (fcode)
6994 {
6995 case SPE_BUILTIN_EVSPLATFI:
6996 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6997 arglist, target);
6998 case SPE_BUILTIN_EVSPLATI:
6999 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
7000 arglist, target);
7001 default:
7002 break;
7003 }
7004
a3170dc6
AH
7005 d = (struct builtin_description *) bdesc_2arg_spe;
7006 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
7007 if (d->code == fcode)
7008 return rs6000_expand_binop_builtin (d->icode, arglist, target);
7009
7010 d = (struct builtin_description *) bdesc_spe_predicates;
7011 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
7012 if (d->code == fcode)
7013 return spe_expand_predicate_builtin (d->icode, arglist, target);
7014
7015 d = (struct builtin_description *) bdesc_spe_evsel;
7016 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
7017 if (d->code == fcode)
7018 return spe_expand_evsel_builtin (d->icode, arglist, target);
7019
7020 switch (fcode)
7021 {
7022 case SPE_BUILTIN_EVSTDDX:
61bea3b0 7023 return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
a3170dc6 7024 case SPE_BUILTIN_EVSTDHX:
61bea3b0 7025 return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
a3170dc6 7026 case SPE_BUILTIN_EVSTDWX:
61bea3b0 7027 return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
a3170dc6 7028 case SPE_BUILTIN_EVSTWHEX:
61bea3b0 7029 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
a3170dc6 7030 case SPE_BUILTIN_EVSTWHOX:
61bea3b0 7031 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
a3170dc6 7032 case SPE_BUILTIN_EVSTWWEX:
61bea3b0 7033 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
a3170dc6 7034 case SPE_BUILTIN_EVSTWWOX:
61bea3b0 7035 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
a3170dc6 7036 case SPE_BUILTIN_EVSTDD:
61bea3b0 7037 return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
a3170dc6 7038 case SPE_BUILTIN_EVSTDH:
61bea3b0 7039 return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
a3170dc6 7040 case SPE_BUILTIN_EVSTDW:
61bea3b0 7041 return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
a3170dc6 7042 case SPE_BUILTIN_EVSTWHE:
61bea3b0 7043 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
a3170dc6 7044 case SPE_BUILTIN_EVSTWHO:
61bea3b0 7045 return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
a3170dc6 7046 case SPE_BUILTIN_EVSTWWE:
61bea3b0 7047 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
a3170dc6 7048 case SPE_BUILTIN_EVSTWWO:
61bea3b0 7049 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
a3170dc6
AH
7050 case SPE_BUILTIN_MFSPEFSCR:
7051 icode = CODE_FOR_spe_mfspefscr;
7052 tmode = insn_data[icode].operand[0].mode;
7053
7054 if (target == 0
7055 || GET_MODE (target) != tmode
7056 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7057 target = gen_reg_rtx (tmode);
f676971a 7058
a3170dc6
AH
7059 pat = GEN_FCN (icode) (target);
7060 if (! pat)
7061 return 0;
7062 emit_insn (pat);
7063 return target;
7064 case SPE_BUILTIN_MTSPEFSCR:
7065 icode = CODE_FOR_spe_mtspefscr;
7066 arg0 = TREE_VALUE (arglist);
7067 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7068 mode0 = insn_data[icode].operand[0].mode;
7069
7070 if (arg0 == error_mark_node)
7071 return const0_rtx;
7072
7073 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
7074 op0 = copy_to_mode_reg (mode0, op0);
7075
7076 pat = GEN_FCN (icode) (op0);
7077 if (pat)
7078 emit_insn (pat);
7079 return NULL_RTX;
7080 default:
7081 break;
7082 }
7083
7084 *expandedp = false;
7085 return NULL_RTX;
7086}
7087
7088static rtx
a2369ed3 7089spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7090{
7091 rtx pat, scratch, tmp;
7092 tree form = TREE_VALUE (arglist);
7093 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
7094 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7095 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7096 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7097 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7098 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7099 int form_int;
7100 enum rtx_code code;
7101
7102 if (TREE_CODE (form) != INTEGER_CST)
7103 {
7104 error ("argument 1 of __builtin_spe_predicate must be a constant");
7105 return const0_rtx;
7106 }
7107 else
7108 form_int = TREE_INT_CST_LOW (form);
7109
7110 if (mode0 != mode1)
7111 abort ();
7112
7113 if (arg0 == error_mark_node || arg1 == error_mark_node)
7114 return const0_rtx;
7115
7116 if (target == 0
7117 || GET_MODE (target) != SImode
7118 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
7119 target = gen_reg_rtx (SImode);
7120
7121 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7122 op0 = copy_to_mode_reg (mode0, op0);
7123 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
7124 op1 = copy_to_mode_reg (mode1, op1);
7125
7126 scratch = gen_reg_rtx (CCmode);
7127
7128 pat = GEN_FCN (icode) (scratch, op0, op1);
7129 if (! pat)
7130 return const0_rtx;
7131 emit_insn (pat);
7132
7133 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
7134 _lower_. We use one compare, but look in different bits of the
7135 CR for each variant.
7136
7137 There are 2 elements in each SPE simd type (upper/lower). The CR
7138 bits are set as follows:
7139
7140 BIT0 | BIT 1 | BIT 2 | BIT 3
7141 U | L | (U | L) | (U & L)
7142
7143 So, for an "all" relationship, BIT 3 would be set.
7144 For an "any" relationship, BIT 2 would be set. Etc.
7145
7146 Following traditional nomenclature, these bits map to:
7147
7148 BIT0 | BIT 1 | BIT 2 | BIT 3
7149 LT | GT | EQ | OV
7150
7151 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
7152 */
7153
7154 switch (form_int)
7155 {
7156 /* All variant. OV bit. */
7157 case 0:
7158 /* We need to get to the OV bit, which is the ORDERED bit. We
7159 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
7160 that's ugly and will trigger a validate_condition_mode abort.
7161 So let's just use another pattern. */
7162 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
7163 return target;
7164 /* Any variant. EQ bit. */
7165 case 1:
7166 code = EQ;
7167 break;
7168 /* Upper variant. LT bit. */
7169 case 2:
7170 code = LT;
7171 break;
7172 /* Lower variant. GT bit. */
7173 case 3:
7174 code = GT;
7175 break;
7176 default:
7177 error ("argument 1 of __builtin_spe_predicate is out of range");
7178 return const0_rtx;
7179 }
7180
7181 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
7182 emit_move_insn (target, tmp);
7183
7184 return target;
7185}
7186
7187/* The evsel builtins look like this:
7188
7189 e = __builtin_spe_evsel_OP (a, b, c, d);
7190
7191 and work like this:
7192
7193 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
7194 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
7195*/
7196
7197static rtx
a2369ed3 7198spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7199{
7200 rtx pat, scratch;
7201 tree arg0 = TREE_VALUE (arglist);
7202 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
7203 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7204 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
7205 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7206 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7207 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
7208 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
7209 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7210 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7211
7212 if (mode0 != mode1)
7213 abort ();
7214
7215 if (arg0 == error_mark_node || arg1 == error_mark_node
7216 || arg2 == error_mark_node || arg3 == error_mark_node)
7217 return const0_rtx;
7218
7219 if (target == 0
7220 || GET_MODE (target) != mode0
7221 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
7222 target = gen_reg_rtx (mode0);
7223
7224 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7225 op0 = copy_to_mode_reg (mode0, op0);
7226 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
7227 op1 = copy_to_mode_reg (mode0, op1);
7228 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
7229 op2 = copy_to_mode_reg (mode0, op2);
7230 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
7231 op3 = copy_to_mode_reg (mode0, op3);
7232
7233 /* Generate the compare. */
7234 scratch = gen_reg_rtx (CCmode);
7235 pat = GEN_FCN (icode) (scratch, op0, op1);
7236 if (! pat)
7237 return const0_rtx;
7238 emit_insn (pat);
7239
7240 if (mode0 == V2SImode)
7241 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
7242 else
7243 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
7244
7245 return target;
7246}
7247
0ac081f6
AH
7248/* Expand an expression EXP that calls a built-in function,
7249 with result going to TARGET if that's convenient
7250 (and in mode MODE if that's convenient).
7251 SUBTARGET may be used as the target for computing one of EXP's operands.
7252 IGNORE is nonzero if the value is to be ignored. */
7253
7254static rtx
a2369ed3 7255rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
c4ad648e
AM
7256 enum machine_mode mode ATTRIBUTE_UNUSED,
7257 int ignore ATTRIBUTE_UNUSED)
0ac081f6 7258{
92898235
AH
7259 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7260 tree arglist = TREE_OPERAND (exp, 1);
7261 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
7262 struct builtin_description *d;
7263 size_t i;
7264 rtx ret;
7265 bool success;
f676971a 7266
7ccf35ed
DN
7267 if (fcode == ALTIVEC_BUILTIN_MASK_FOR_LOAD
7268 || fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE)
7269 {
7270 int icode = (int) CODE_FOR_altivec_lvsr;
7271 enum machine_mode tmode = insn_data[icode].operand[0].mode;
7272 enum machine_mode mode = insn_data[icode].operand[1].mode;
7273 tree arg;
7274 rtx op, addr, pat;
7275
7276 if (!TARGET_ALTIVEC)
7277 abort ();
7278
7279 arg = TREE_VALUE (arglist);
7280 if (TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE)
7281 abort ();
7282 op = expand_expr (arg, NULL_RTX, Pmode, EXPAND_NORMAL);
7283 addr = memory_address (mode, op);
7284 if (fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE)
7285 op = addr;
7286 else
7287 {
7288 /* For the load case need to negate the address. */
7289 op = gen_reg_rtx (GET_MODE (addr));
7290 emit_insn (gen_rtx_SET (VOIDmode, op,
7291 gen_rtx_NEG (GET_MODE (addr), addr)));
c4ad648e 7292 }
7ccf35ed
DN
7293 op = gen_rtx_MEM (mode, op);
7294
7295 if (target == 0
7296 || GET_MODE (target) != tmode
7297 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7298 target = gen_reg_rtx (tmode);
7299
7300 /*pat = gen_altivec_lvsr (target, op);*/
7301 pat = GEN_FCN (icode) (target, op);
7302 if (!pat)
7303 return 0;
7304 emit_insn (pat);
7305
7306 return target;
7307 }
7308
0ac081f6 7309 if (TARGET_ALTIVEC)
92898235
AH
7310 {
7311 ret = altivec_expand_builtin (exp, target, &success);
7312
a3170dc6
AH
7313 if (success)
7314 return ret;
7315 }
7316 if (TARGET_SPE)
7317 {
7318 ret = spe_expand_builtin (exp, target, &success);
7319
92898235
AH
7320 if (success)
7321 return ret;
7322 }
7323
0559cc77
DE
7324 if (TARGET_ALTIVEC || TARGET_SPE)
7325 {
7326 /* Handle simple unary operations. */
7327 d = (struct builtin_description *) bdesc_1arg;
7328 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
7329 if (d->code == fcode)
7330 return rs6000_expand_unop_builtin (d->icode, arglist, target);
7331
7332 /* Handle simple binary operations. */
7333 d = (struct builtin_description *) bdesc_2arg;
7334 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
7335 if (d->code == fcode)
7336 return rs6000_expand_binop_builtin (d->icode, arglist, target);
7337
7338 /* Handle simple ternary operations. */
7339 d = (struct builtin_description *) bdesc_3arg;
7340 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
7341 if (d->code == fcode)
7342 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
7343 }
0ac081f6
AH
7344
7345 abort ();
92898235 7346 return NULL_RTX;
0ac081f6
AH
7347}
7348
7c62e993
PB
7349static tree
7350build_opaque_vector_type (tree node, int nunits)
7351{
7352 node = copy_node (node);
7353 TYPE_MAIN_VARIANT (node) = node;
7354 return build_vector_type (node, nunits);
7355}
7356
0ac081f6 7357static void
863d938c 7358rs6000_init_builtins (void)
0ac081f6 7359{
4a5eab38
PB
7360 V2SI_type_node = build_vector_type (intSI_type_node, 2);
7361 V2SF_type_node = build_vector_type (float_type_node, 2);
7362 V4HI_type_node = build_vector_type (intHI_type_node, 4);
7363 V4SI_type_node = build_vector_type (intSI_type_node, 4);
7364 V4SF_type_node = build_vector_type (float_type_node, 4);
7e463bda 7365 V8HI_type_node = build_vector_type (intHI_type_node, 8);
4a5eab38
PB
7366 V16QI_type_node = build_vector_type (intQI_type_node, 16);
7367
7368 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
7369 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
7370 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
7371
7c62e993
PB
7372 opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2);
7373 opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2);
6035d635 7374 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 7375
8bb418a3
ZL
7376 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
7377 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
7378 'vector unsigned short'. */
7379
8dd16ecc
NS
7380 bool_char_type_node = build_distinct_type_copy (unsigned_intQI_type_node);
7381 bool_short_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
7382 bool_int_type_node = build_distinct_type_copy (unsigned_intSI_type_node);
7383 pixel_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
8bb418a3
ZL
7384
7385 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7386 get_identifier ("__bool char"),
7387 bool_char_type_node));
7388 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7389 get_identifier ("__bool short"),
7390 bool_short_type_node));
7391 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7392 get_identifier ("__bool int"),
7393 bool_int_type_node));
7394 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7395 get_identifier ("__pixel"),
7396 pixel_type_node));
7397
4a5eab38
PB
7398 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
7399 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
7400 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
7401 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
8bb418a3
ZL
7402
7403 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7404 get_identifier ("__vector unsigned char"),
7405 unsigned_V16QI_type_node));
7406 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7407 get_identifier ("__vector signed char"),
7408 V16QI_type_node));
7409 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7410 get_identifier ("__vector __bool char"),
7411 bool_V16QI_type_node));
7412
7413 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7414 get_identifier ("__vector unsigned short"),
7415 unsigned_V8HI_type_node));
7416 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7417 get_identifier ("__vector signed short"),
7418 V8HI_type_node));
7419 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7420 get_identifier ("__vector __bool short"),
7421 bool_V8HI_type_node));
7422
7423 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7424 get_identifier ("__vector unsigned int"),
7425 unsigned_V4SI_type_node));
7426 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7427 get_identifier ("__vector signed int"),
7428 V4SI_type_node));
7429 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7430 get_identifier ("__vector __bool int"),
7431 bool_V4SI_type_node));
7432
7433 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7434 get_identifier ("__vector float"),
7435 V4SF_type_node));
7436 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7437 get_identifier ("__vector __pixel"),
7438 pixel_V8HI_type_node));
7439
a3170dc6 7440 if (TARGET_SPE)
3fdaa45a 7441 spe_init_builtins ();
0ac081f6
AH
7442 if (TARGET_ALTIVEC)
7443 altivec_init_builtins ();
0559cc77
DE
7444 if (TARGET_ALTIVEC || TARGET_SPE)
7445 rs6000_common_init_builtins ();
0ac081f6
AH
7446}
7447
a3170dc6
AH
7448/* Search through a set of builtins and enable the mask bits.
7449 DESC is an array of builtins.
b6d08ca1 7450 SIZE is the total number of builtins.
a3170dc6
AH
7451 START is the builtin enum at which to start.
7452 END is the builtin enum at which to end. */
0ac081f6 7453static void
a2369ed3 7454enable_mask_for_builtins (struct builtin_description *desc, int size,
f676971a 7455 enum rs6000_builtins start,
a2369ed3 7456 enum rs6000_builtins end)
a3170dc6
AH
7457{
7458 int i;
7459
7460 for (i = 0; i < size; ++i)
7461 if (desc[i].code == start)
7462 break;
7463
7464 if (i == size)
7465 return;
7466
7467 for (; i < size; ++i)
7468 {
7469 /* Flip all the bits on. */
7470 desc[i].mask = target_flags;
7471 if (desc[i].code == end)
7472 break;
7473 }
7474}
7475
7476static void
863d938c 7477spe_init_builtins (void)
0ac081f6 7478{
a3170dc6
AH
7479 tree endlink = void_list_node;
7480 tree puint_type_node = build_pointer_type (unsigned_type_node);
7481 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 7482 struct builtin_description *d;
0ac081f6
AH
7483 size_t i;
7484
a3170dc6
AH
7485 tree v2si_ftype_4_v2si
7486 = build_function_type
3fdaa45a
AH
7487 (opaque_V2SI_type_node,
7488 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7489 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7490 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7491 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7492 endlink)))));
7493
7494 tree v2sf_ftype_4_v2sf
7495 = build_function_type
3fdaa45a
AH
7496 (opaque_V2SF_type_node,
7497 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7498 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7499 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7500 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7501 endlink)))));
7502
7503 tree int_ftype_int_v2si_v2si
7504 = build_function_type
7505 (integer_type_node,
7506 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7507 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7508 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7509 endlink))));
7510
7511 tree int_ftype_int_v2sf_v2sf
7512 = build_function_type
7513 (integer_type_node,
7514 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7515 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7516 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7517 endlink))));
7518
7519 tree void_ftype_v2si_puint_int
7520 = build_function_type (void_type_node,
3fdaa45a 7521 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7522 tree_cons (NULL_TREE, puint_type_node,
7523 tree_cons (NULL_TREE,
7524 integer_type_node,
7525 endlink))));
7526
7527 tree void_ftype_v2si_puint_char
7528 = build_function_type (void_type_node,
3fdaa45a 7529 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7530 tree_cons (NULL_TREE, puint_type_node,
7531 tree_cons (NULL_TREE,
7532 char_type_node,
7533 endlink))));
7534
7535 tree void_ftype_v2si_pv2si_int
7536 = build_function_type (void_type_node,
3fdaa45a 7537 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7538 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7539 tree_cons (NULL_TREE,
7540 integer_type_node,
7541 endlink))));
7542
7543 tree void_ftype_v2si_pv2si_char
7544 = build_function_type (void_type_node,
3fdaa45a 7545 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7546 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7547 tree_cons (NULL_TREE,
7548 char_type_node,
7549 endlink))));
7550
7551 tree void_ftype_int
7552 = build_function_type (void_type_node,
7553 tree_cons (NULL_TREE, integer_type_node, endlink));
7554
7555 tree int_ftype_void
36e8d515 7556 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
7557
7558 tree v2si_ftype_pv2si_int
3fdaa45a 7559 = build_function_type (opaque_V2SI_type_node,
6035d635 7560 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7561 tree_cons (NULL_TREE, integer_type_node,
7562 endlink)));
7563
7564 tree v2si_ftype_puint_int
3fdaa45a 7565 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7566 tree_cons (NULL_TREE, puint_type_node,
7567 tree_cons (NULL_TREE, integer_type_node,
7568 endlink)));
7569
7570 tree v2si_ftype_pushort_int
3fdaa45a 7571 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7572 tree_cons (NULL_TREE, pushort_type_node,
7573 tree_cons (NULL_TREE, integer_type_node,
7574 endlink)));
7575
00332c9f
AH
7576 tree v2si_ftype_signed_char
7577 = build_function_type (opaque_V2SI_type_node,
7578 tree_cons (NULL_TREE, signed_char_type_node,
7579 endlink));
7580
a3170dc6
AH
7581 /* The initialization of the simple binary and unary builtins is
7582 done in rs6000_common_init_builtins, but we have to enable the
7583 mask bits here manually because we have run out of `target_flags'
7584 bits. We really need to redesign this mask business. */
7585
7586 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
7587 ARRAY_SIZE (bdesc_2arg),
7588 SPE_BUILTIN_EVADDW,
7589 SPE_BUILTIN_EVXOR);
7590 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
7591 ARRAY_SIZE (bdesc_1arg),
7592 SPE_BUILTIN_EVABS,
7593 SPE_BUILTIN_EVSUBFUSIAAW);
7594 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
7595 ARRAY_SIZE (bdesc_spe_predicates),
7596 SPE_BUILTIN_EVCMPEQ,
7597 SPE_BUILTIN_EVFSTSTLT);
7598 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
7599 ARRAY_SIZE (bdesc_spe_evsel),
7600 SPE_BUILTIN_EVSEL_CMPGTS,
7601 SPE_BUILTIN_EVSEL_FSTSTEQ);
7602
36252949
AH
7603 (*lang_hooks.decls.pushdecl)
7604 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
7605 opaque_V2SI_type_node));
7606
a3170dc6 7607 /* Initialize irregular SPE builtins. */
f676971a 7608
a3170dc6
AH
7609 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
7610 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
7611 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
7612 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
7613 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
7614 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
7615 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
7616 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
7617 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
7618 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
7619 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
7620 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
7621 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
7622 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
7623 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
7624 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
7625 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
7626 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
7627
7628 /* Loads. */
7629 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
7630 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
7631 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
7632 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
7633 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
7634 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
7635 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
7636 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
7637 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
7638 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
7639 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
7640 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
7641 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
7642 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
7643 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
7644 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
7645 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
7646 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
7647 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
7648 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
7649 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
7650 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
7651
7652 /* Predicates. */
7653 d = (struct builtin_description *) bdesc_spe_predicates;
7654 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
7655 {
7656 tree type;
7657
7658 switch (insn_data[d->icode].operand[1].mode)
7659 {
7660 case V2SImode:
7661 type = int_ftype_int_v2si_v2si;
7662 break;
7663 case V2SFmode:
7664 type = int_ftype_int_v2sf_v2sf;
7665 break;
7666 default:
7667 abort ();
7668 }
7669
7670 def_builtin (d->mask, d->name, type, d->code);
7671 }
7672
7673 /* Evsel predicates. */
7674 d = (struct builtin_description *) bdesc_spe_evsel;
7675 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
7676 {
7677 tree type;
7678
7679 switch (insn_data[d->icode].operand[1].mode)
7680 {
7681 case V2SImode:
7682 type = v2si_ftype_4_v2si;
7683 break;
7684 case V2SFmode:
7685 type = v2sf_ftype_4_v2sf;
7686 break;
7687 default:
7688 abort ();
7689 }
7690
7691 def_builtin (d->mask, d->name, type, d->code);
7692 }
7693}
7694
7695static void
863d938c 7696altivec_init_builtins (void)
a3170dc6
AH
7697{
7698 struct builtin_description *d;
7699 struct builtin_description_predicates *dp;
7700 size_t i;
7701 tree pfloat_type_node = build_pointer_type (float_type_node);
7702 tree pint_type_node = build_pointer_type (integer_type_node);
7703 tree pshort_type_node = build_pointer_type (short_integer_type_node);
7704 tree pchar_type_node = build_pointer_type (char_type_node);
7705
7706 tree pvoid_type_node = build_pointer_type (void_type_node);
7707
0dbc3651
ZW
7708 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
7709 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
7710 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
7711 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
7712
7713 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
7714
a3170dc6
AH
7715 tree int_ftype_int_v4si_v4si
7716 = build_function_type_list (integer_type_node,
7717 integer_type_node, V4SI_type_node,
7718 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7719 tree v4sf_ftype_pcfloat
7720 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 7721 tree void_ftype_pfloat_v4sf
b4de2f7d 7722 = build_function_type_list (void_type_node,
a3170dc6 7723 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
7724 tree v4si_ftype_pcint
7725 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
7726 tree void_ftype_pint_v4si
b4de2f7d
AH
7727 = build_function_type_list (void_type_node,
7728 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7729 tree v8hi_ftype_pcshort
7730 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 7731 tree void_ftype_pshort_v8hi
b4de2f7d
AH
7732 = build_function_type_list (void_type_node,
7733 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
7734 tree v16qi_ftype_pcchar
7735 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 7736 tree void_ftype_pchar_v16qi
b4de2f7d
AH
7737 = build_function_type_list (void_type_node,
7738 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 7739 tree void_ftype_v4si
b4de2f7d 7740 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7741 tree v8hi_ftype_void
7742 = build_function_type (V8HI_type_node, void_list_node);
7743 tree void_ftype_void
7744 = build_function_type (void_type_node, void_list_node);
e34b6648
JJ
7745 tree void_ftype_int
7746 = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
0dbc3651 7747
b4a62fa0 7748 tree v16qi_ftype_long_pcvoid
a3170dc6 7749 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
7750 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7751 tree v8hi_ftype_long_pcvoid
a3170dc6 7752 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
7753 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7754 tree v4si_ftype_long_pcvoid
a3170dc6 7755 = build_function_type_list (V4SI_type_node,
b4a62fa0 7756 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 7757
b4a62fa0 7758 tree void_ftype_v4si_long_pvoid
b4de2f7d 7759 = build_function_type_list (void_type_node,
b4a62fa0 7760 V4SI_type_node, long_integer_type_node,
b4de2f7d 7761 pvoid_type_node, NULL_TREE);
b4a62fa0 7762 tree void_ftype_v16qi_long_pvoid
b4de2f7d 7763 = build_function_type_list (void_type_node,
b4a62fa0 7764 V16QI_type_node, long_integer_type_node,
b4de2f7d 7765 pvoid_type_node, NULL_TREE);
b4a62fa0 7766 tree void_ftype_v8hi_long_pvoid
b4de2f7d 7767 = build_function_type_list (void_type_node,
b4a62fa0 7768 V8HI_type_node, long_integer_type_node,
b4de2f7d 7769 pvoid_type_node, NULL_TREE);
a3170dc6
AH
7770 tree int_ftype_int_v8hi_v8hi
7771 = build_function_type_list (integer_type_node,
7772 integer_type_node, V8HI_type_node,
7773 V8HI_type_node, NULL_TREE);
7774 tree int_ftype_int_v16qi_v16qi
7775 = build_function_type_list (integer_type_node,
7776 integer_type_node, V16QI_type_node,
7777 V16QI_type_node, NULL_TREE);
7778 tree int_ftype_int_v4sf_v4sf
7779 = build_function_type_list (integer_type_node,
7780 integer_type_node, V4SF_type_node,
7781 V4SF_type_node, NULL_TREE);
7782 tree v4si_ftype_v4si
7783 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
7784 tree v8hi_ftype_v8hi
7785 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
7786 tree v16qi_ftype_v16qi
7787 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
7788 tree v4sf_ftype_v4sf
7789 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 7790 tree void_ftype_pcvoid_int_int
a3170dc6 7791 = build_function_type_list (void_type_node,
0dbc3651 7792 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
7793 integer_type_node, NULL_TREE);
7794 tree int_ftype_pcchar
7795 = build_function_type_list (integer_type_node,
7796 pcchar_type_node, NULL_TREE);
7797
7ccf35ed
DN
7798 tree id;
7799 tree decl;
7800
0dbc3651
ZW
7801 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
7802 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
7803 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
7804 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
7805 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
7806 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
7807 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
7808 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
7809 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
7810 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
7811 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
7812 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
7813 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
7814 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
7815 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
7816 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
7817 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
7818 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
7819 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
e34b6648 7820 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_int, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
7821 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
7822 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
7823 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
7824 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
7825 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
7826 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
7827 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
7828 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
7829 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
7830 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
7831 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
7832 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 7833
8bb418a3
ZL
7834 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
7835 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
7836 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
7837
a3170dc6
AH
7838 /* Add the DST variants. */
7839 d = (struct builtin_description *) bdesc_dst;
7840 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 7841 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
7842
7843 /* Initialize the predicates. */
7844 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
7845 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
7846 {
7847 enum machine_mode mode1;
7848 tree type;
7849
7850 mode1 = insn_data[dp->icode].operand[1].mode;
7851
7852 switch (mode1)
7853 {
7854 case V4SImode:
7855 type = int_ftype_int_v4si_v4si;
7856 break;
7857 case V8HImode:
7858 type = int_ftype_int_v8hi_v8hi;
7859 break;
7860 case V16QImode:
7861 type = int_ftype_int_v16qi_v16qi;
7862 break;
7863 case V4SFmode:
7864 type = int_ftype_int_v4sf_v4sf;
7865 break;
7866 default:
7867 abort ();
7868 }
f676971a 7869
a3170dc6
AH
7870 def_builtin (dp->mask, dp->name, type, dp->code);
7871 }
7872
7873 /* Initialize the abs* operators. */
7874 d = (struct builtin_description *) bdesc_abs;
7875 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
7876 {
7877 enum machine_mode mode0;
7878 tree type;
7879
7880 mode0 = insn_data[d->icode].operand[0].mode;
7881
7882 switch (mode0)
7883 {
7884 case V4SImode:
7885 type = v4si_ftype_v4si;
7886 break;
7887 case V8HImode:
7888 type = v8hi_ftype_v8hi;
7889 break;
7890 case V16QImode:
7891 type = v16qi_ftype_v16qi;
7892 break;
7893 case V4SFmode:
7894 type = v4sf_ftype_v4sf;
7895 break;
7896 default:
7897 abort ();
7898 }
f676971a 7899
a3170dc6
AH
7900 def_builtin (d->mask, d->name, type, d->code);
7901 }
7ccf35ed 7902
c4ad648e 7903 /* Initialize target builtin that implements
7ccf35ed
DN
7904 targetm.vectorize.builtin_mask_for_load. */
7905 id = get_identifier ("__builtin_altivec_mask_for_load");
7906 decl = build_decl (FUNCTION_DECL, id, v16qi_ftype_long_pcvoid);
7907 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_MD;
7908 DECL_FUNCTION_CODE (decl) = ALTIVEC_BUILTIN_MASK_FOR_LOAD;
7909 /* Record the decl. Will be used by rs6000_builtin_mask_for_load. */
7910 altivec_builtin_mask_for_load = decl;
7911
c4ad648e 7912 /* Initialize target builtin that implements
7ccf35ed
DN
7913 targetm.vectorize.builtin_mask_for_store. */
7914 id = get_identifier ("__builtin_altivec_mask_for_store");
7915 decl = build_decl (FUNCTION_DECL, id, v16qi_ftype_long_pcvoid);
7916 DECL_BUILT_IN_CLASS (decl) = BUILT_IN_MD;
7917 DECL_FUNCTION_CODE (decl) = ALTIVEC_BUILTIN_MASK_FOR_STORE;
7918 /* Record the decl. Will be used by rs6000_builtin_mask_for_store. */
7919 altivec_builtin_mask_for_store = decl;
a3170dc6
AH
7920}
7921
7922static void
863d938c 7923rs6000_common_init_builtins (void)
a3170dc6
AH
7924{
7925 struct builtin_description *d;
7926 size_t i;
7927
7928 tree v4sf_ftype_v4sf_v4sf_v16qi
7929 = build_function_type_list (V4SF_type_node,
7930 V4SF_type_node, V4SF_type_node,
7931 V16QI_type_node, NULL_TREE);
7932 tree v4si_ftype_v4si_v4si_v16qi
7933 = build_function_type_list (V4SI_type_node,
7934 V4SI_type_node, V4SI_type_node,
7935 V16QI_type_node, NULL_TREE);
7936 tree v8hi_ftype_v8hi_v8hi_v16qi
7937 = build_function_type_list (V8HI_type_node,
7938 V8HI_type_node, V8HI_type_node,
7939 V16QI_type_node, NULL_TREE);
7940 tree v16qi_ftype_v16qi_v16qi_v16qi
7941 = build_function_type_list (V16QI_type_node,
7942 V16QI_type_node, V16QI_type_node,
7943 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
7944 tree v4si_ftype_int
7945 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
7946 tree v8hi_ftype_int
7947 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
7948 tree v16qi_ftype_int
7949 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
7950 tree v8hi_ftype_v16qi
7951 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
7952 tree v4sf_ftype_v4sf
7953 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
7954
7955 tree v2si_ftype_v2si_v2si
2abe3e28
AH
7956 = build_function_type_list (opaque_V2SI_type_node,
7957 opaque_V2SI_type_node,
7958 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7959
7960 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
7961 = build_function_type_list (opaque_V2SF_type_node,
7962 opaque_V2SF_type_node,
7963 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7964
7965 tree v2si_ftype_int_int
2abe3e28 7966 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7967 integer_type_node, integer_type_node,
7968 NULL_TREE);
7969
7970 tree v2si_ftype_v2si
2abe3e28
AH
7971 = build_function_type_list (opaque_V2SI_type_node,
7972 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7973
7974 tree v2sf_ftype_v2sf
2abe3e28
AH
7975 = build_function_type_list (opaque_V2SF_type_node,
7976 opaque_V2SF_type_node, NULL_TREE);
f676971a 7977
a3170dc6 7978 tree v2sf_ftype_v2si
2abe3e28
AH
7979 = build_function_type_list (opaque_V2SF_type_node,
7980 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7981
7982 tree v2si_ftype_v2sf
2abe3e28
AH
7983 = build_function_type_list (opaque_V2SI_type_node,
7984 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7985
7986 tree v2si_ftype_v2si_char
2abe3e28
AH
7987 = build_function_type_list (opaque_V2SI_type_node,
7988 opaque_V2SI_type_node,
7989 char_type_node, NULL_TREE);
a3170dc6
AH
7990
7991 tree v2si_ftype_int_char
2abe3e28 7992 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7993 integer_type_node, char_type_node, NULL_TREE);
7994
7995 tree v2si_ftype_char
2abe3e28
AH
7996 = build_function_type_list (opaque_V2SI_type_node,
7997 char_type_node, NULL_TREE);
a3170dc6
AH
7998
7999 tree int_ftype_int_int
8000 = build_function_type_list (integer_type_node,
8001 integer_type_node, integer_type_node,
8002 NULL_TREE);
95385cbb 8003
0ac081f6 8004 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
8005 = build_function_type_list (V4SI_type_node,
8006 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 8007 tree v4sf_ftype_v4si_int
b4de2f7d 8008 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
8009 V4SI_type_node, integer_type_node, NULL_TREE);
8010 tree v4si_ftype_v4sf_int
b4de2f7d 8011 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
8012 V4SF_type_node, integer_type_node, NULL_TREE);
8013 tree v4si_ftype_v4si_int
b4de2f7d 8014 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
8015 V4SI_type_node, integer_type_node, NULL_TREE);
8016 tree v8hi_ftype_v8hi_int
b4de2f7d 8017 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
8018 V8HI_type_node, integer_type_node, NULL_TREE);
8019 tree v16qi_ftype_v16qi_int
b4de2f7d 8020 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
8021 V16QI_type_node, integer_type_node, NULL_TREE);
8022 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
8023 = build_function_type_list (V16QI_type_node,
8024 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
8025 integer_type_node, NULL_TREE);
8026 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
8027 = build_function_type_list (V8HI_type_node,
8028 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
8029 integer_type_node, NULL_TREE);
8030 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
8031 = build_function_type_list (V4SI_type_node,
8032 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
8033 integer_type_node, NULL_TREE);
8034 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
8035 = build_function_type_list (V4SF_type_node,
8036 V4SF_type_node, V4SF_type_node,
b9e4e5d1 8037 integer_type_node, NULL_TREE);
0ac081f6 8038 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
8039 = build_function_type_list (V4SF_type_node,
8040 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 8041 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
8042 = build_function_type_list (V4SF_type_node,
8043 V4SF_type_node, V4SF_type_node,
8044 V4SI_type_node, NULL_TREE);
2212663f 8045 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
8046 = build_function_type_list (V4SF_type_node,
8047 V4SF_type_node, V4SF_type_node,
8048 V4SF_type_node, NULL_TREE);
f676971a 8049 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
8050 = build_function_type_list (V4SI_type_node,
8051 V4SI_type_node, V4SI_type_node,
8052 V4SI_type_node, NULL_TREE);
0ac081f6 8053 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
8054 = build_function_type_list (V8HI_type_node,
8055 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 8056 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
8057 = build_function_type_list (V8HI_type_node,
8058 V8HI_type_node, V8HI_type_node,
8059 V8HI_type_node, NULL_TREE);
c4ad648e 8060 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
8061 = build_function_type_list (V4SI_type_node,
8062 V8HI_type_node, V8HI_type_node,
8063 V4SI_type_node, NULL_TREE);
c4ad648e 8064 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
8065 = build_function_type_list (V4SI_type_node,
8066 V16QI_type_node, V16QI_type_node,
8067 V4SI_type_node, NULL_TREE);
0ac081f6 8068 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
8069 = build_function_type_list (V16QI_type_node,
8070 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8071 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
8072 = build_function_type_list (V4SI_type_node,
8073 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 8074 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
8075 = build_function_type_list (V8HI_type_node,
8076 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8077 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
8078 = build_function_type_list (V4SI_type_node,
8079 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8080 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
8081 = build_function_type_list (V8HI_type_node,
8082 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 8083 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
8084 = build_function_type_list (V16QI_type_node,
8085 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8086 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
8087 = build_function_type_list (V4SI_type_node,
8088 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 8089 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
8090 = build_function_type_list (V4SI_type_node,
8091 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8092 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
8093 = build_function_type_list (V4SI_type_node,
8094 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
8095 tree v4si_ftype_v8hi
8096 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
8097 tree int_ftype_v4si_v4si
8098 = build_function_type_list (integer_type_node,
8099 V4SI_type_node, V4SI_type_node, NULL_TREE);
8100 tree int_ftype_v4sf_v4sf
8101 = build_function_type_list (integer_type_node,
8102 V4SF_type_node, V4SF_type_node, NULL_TREE);
8103 tree int_ftype_v16qi_v16qi
8104 = build_function_type_list (integer_type_node,
8105 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8106 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
8107 = build_function_type_list (integer_type_node,
8108 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8109
6f317ef3 8110 /* Add the simple ternary operators. */
2212663f 8111 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 8112 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f 8113 {
f676971a 8114
2212663f
DB
8115 enum machine_mode mode0, mode1, mode2, mode3;
8116 tree type;
8117
0559cc77 8118 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 8119 continue;
f676971a 8120
2212663f
DB
8121 mode0 = insn_data[d->icode].operand[0].mode;
8122 mode1 = insn_data[d->icode].operand[1].mode;
8123 mode2 = insn_data[d->icode].operand[2].mode;
8124 mode3 = insn_data[d->icode].operand[3].mode;
f676971a 8125
2212663f
DB
8126 /* When all four are of the same mode. */
8127 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
8128 {
8129 switch (mode0)
8130 {
617e0e1d
DB
8131 case V4SImode:
8132 type = v4si_ftype_v4si_v4si_v4si;
8133 break;
2212663f
DB
8134 case V4SFmode:
8135 type = v4sf_ftype_v4sf_v4sf_v4sf;
8136 break;
8137 case V8HImode:
8138 type = v8hi_ftype_v8hi_v8hi_v8hi;
f676971a 8139 break;
2212663f
DB
8140 case V16QImode:
8141 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8142 break;
2212663f 8143 default:
f676971a 8144 abort();
2212663f
DB
8145 }
8146 }
8147 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
c4ad648e 8148 {
2212663f
DB
8149 switch (mode0)
8150 {
8151 case V4SImode:
8152 type = v4si_ftype_v4si_v4si_v16qi;
8153 break;
8154 case V4SFmode:
8155 type = v4sf_ftype_v4sf_v4sf_v16qi;
8156 break;
8157 case V8HImode:
8158 type = v8hi_ftype_v8hi_v8hi_v16qi;
f676971a 8159 break;
2212663f
DB
8160 case V16QImode:
8161 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8162 break;
2212663f 8163 default:
f676971a 8164 abort();
2212663f
DB
8165 }
8166 }
f676971a 8167 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
2212663f 8168 && mode3 == V4SImode)
24408032 8169 type = v4si_ftype_v16qi_v16qi_v4si;
f676971a 8170 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
2212663f 8171 && mode3 == V4SImode)
24408032 8172 type = v4si_ftype_v8hi_v8hi_v4si;
f676971a 8173 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
617e0e1d 8174 && mode3 == V4SImode)
24408032
AH
8175 type = v4sf_ftype_v4sf_v4sf_v4si;
8176
8177 /* vchar, vchar, vchar, 4 bit literal. */
8178 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
8179 && mode3 == QImode)
b9e4e5d1 8180 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
8181
8182 /* vshort, vshort, vshort, 4 bit literal. */
8183 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
8184 && mode3 == QImode)
b9e4e5d1 8185 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
8186
8187 /* vint, vint, vint, 4 bit literal. */
8188 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
8189 && mode3 == QImode)
b9e4e5d1 8190 type = v4si_ftype_v4si_v4si_int;
24408032
AH
8191
8192 /* vfloat, vfloat, vfloat, 4 bit literal. */
8193 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
8194 && mode3 == QImode)
b9e4e5d1 8195 type = v4sf_ftype_v4sf_v4sf_int;
24408032 8196
2212663f
DB
8197 else
8198 abort ();
8199
8200 def_builtin (d->mask, d->name, type, d->code);
8201 }
8202
0ac081f6 8203 /* Add the simple binary operators. */
00b960c7 8204 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 8205 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
8206 {
8207 enum machine_mode mode0, mode1, mode2;
8208 tree type;
8209
0559cc77 8210 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6 8211 continue;
f676971a 8212
0ac081f6
AH
8213 mode0 = insn_data[d->icode].operand[0].mode;
8214 mode1 = insn_data[d->icode].operand[1].mode;
8215 mode2 = insn_data[d->icode].operand[2].mode;
8216
8217 /* When all three operands are of the same mode. */
8218 if (mode0 == mode1 && mode1 == mode2)
8219 {
8220 switch (mode0)
8221 {
8222 case V4SFmode:
8223 type = v4sf_ftype_v4sf_v4sf;
8224 break;
8225 case V4SImode:
8226 type = v4si_ftype_v4si_v4si;
8227 break;
8228 case V16QImode:
8229 type = v16qi_ftype_v16qi_v16qi;
8230 break;
8231 case V8HImode:
8232 type = v8hi_ftype_v8hi_v8hi;
8233 break;
a3170dc6
AH
8234 case V2SImode:
8235 type = v2si_ftype_v2si_v2si;
8236 break;
8237 case V2SFmode:
8238 type = v2sf_ftype_v2sf_v2sf;
8239 break;
8240 case SImode:
8241 type = int_ftype_int_int;
8242 break;
0ac081f6
AH
8243 default:
8244 abort ();
8245 }
8246 }
8247
8248 /* A few other combos we really don't want to do manually. */
8249
8250 /* vint, vfloat, vfloat. */
8251 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
8252 type = v4si_ftype_v4sf_v4sf;
8253
8254 /* vshort, vchar, vchar. */
8255 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
8256 type = v8hi_ftype_v16qi_v16qi;
8257
8258 /* vint, vshort, vshort. */
8259 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
8260 type = v4si_ftype_v8hi_v8hi;
8261
8262 /* vshort, vint, vint. */
8263 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
8264 type = v8hi_ftype_v4si_v4si;
8265
8266 /* vchar, vshort, vshort. */
8267 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
8268 type = v16qi_ftype_v8hi_v8hi;
8269
8270 /* vint, vchar, vint. */
8271 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
8272 type = v4si_ftype_v16qi_v4si;
8273
fa066a23
AH
8274 /* vint, vchar, vchar. */
8275 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
8276 type = v4si_ftype_v16qi_v16qi;
8277
0ac081f6
AH
8278 /* vint, vshort, vint. */
8279 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
8280 type = v4si_ftype_v8hi_v4si;
f676971a 8281
2212663f
DB
8282 /* vint, vint, 5 bit literal. */
8283 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8284 type = v4si_ftype_v4si_int;
f676971a 8285
2212663f
DB
8286 /* vshort, vshort, 5 bit literal. */
8287 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 8288 type = v8hi_ftype_v8hi_int;
f676971a 8289
2212663f
DB
8290 /* vchar, vchar, 5 bit literal. */
8291 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 8292 type = v16qi_ftype_v16qi_int;
0ac081f6 8293
617e0e1d
DB
8294 /* vfloat, vint, 5 bit literal. */
8295 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8296 type = v4sf_ftype_v4si_int;
f676971a 8297
617e0e1d
DB
8298 /* vint, vfloat, 5 bit literal. */
8299 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 8300 type = v4si_ftype_v4sf_int;
617e0e1d 8301
a3170dc6
AH
8302 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
8303 type = v2si_ftype_int_int;
8304
8305 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
8306 type = v2si_ftype_v2si_char;
8307
8308 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
8309 type = v2si_ftype_int_char;
8310
0ac081f6
AH
8311 /* int, x, x. */
8312 else if (mode0 == SImode)
8313 {
8314 switch (mode1)
8315 {
8316 case V4SImode:
8317 type = int_ftype_v4si_v4si;
8318 break;
8319 case V4SFmode:
8320 type = int_ftype_v4sf_v4sf;
8321 break;
8322 case V16QImode:
8323 type = int_ftype_v16qi_v16qi;
8324 break;
8325 case V8HImode:
8326 type = int_ftype_v8hi_v8hi;
8327 break;
8328 default:
8329 abort ();
8330 }
8331 }
8332
8333 else
8334 abort ();
8335
2212663f
DB
8336 def_builtin (d->mask, d->name, type, d->code);
8337 }
24408032 8338
2212663f
DB
8339 /* Add the simple unary operators. */
8340 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 8341 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
8342 {
8343 enum machine_mode mode0, mode1;
8344 tree type;
8345
0559cc77 8346 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 8347 continue;
f676971a 8348
2212663f
DB
8349 mode0 = insn_data[d->icode].operand[0].mode;
8350 mode1 = insn_data[d->icode].operand[1].mode;
8351
8352 if (mode0 == V4SImode && mode1 == QImode)
c4ad648e 8353 type = v4si_ftype_int;
2212663f 8354 else if (mode0 == V8HImode && mode1 == QImode)
c4ad648e 8355 type = v8hi_ftype_int;
2212663f 8356 else if (mode0 == V16QImode && mode1 == QImode)
c4ad648e 8357 type = v16qi_ftype_int;
617e0e1d
DB
8358 else if (mode0 == V4SFmode && mode1 == V4SFmode)
8359 type = v4sf_ftype_v4sf;
20e26713
AH
8360 else if (mode0 == V8HImode && mode1 == V16QImode)
8361 type = v8hi_ftype_v16qi;
8362 else if (mode0 == V4SImode && mode1 == V8HImode)
8363 type = v4si_ftype_v8hi;
a3170dc6
AH
8364 else if (mode0 == V2SImode && mode1 == V2SImode)
8365 type = v2si_ftype_v2si;
8366 else if (mode0 == V2SFmode && mode1 == V2SFmode)
8367 type = v2sf_ftype_v2sf;
8368 else if (mode0 == V2SFmode && mode1 == V2SImode)
8369 type = v2sf_ftype_v2si;
8370 else if (mode0 == V2SImode && mode1 == V2SFmode)
8371 type = v2si_ftype_v2sf;
8372 else if (mode0 == V2SImode && mode1 == QImode)
8373 type = v2si_ftype_char;
2212663f
DB
8374 else
8375 abort ();
8376
0ac081f6
AH
8377 def_builtin (d->mask, d->name, type, d->code);
8378 }
8379}
8380
c15c90bb
ZW
8381static void
8382rs6000_init_libfuncs (void)
8383{
8384 if (!TARGET_HARD_FLOAT)
8385 return;
8386
c9034561 8387 if (DEFAULT_ABI != ABI_V4)
c15c90bb 8388 {
c9034561 8389 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 8390 {
c9034561 8391 /* AIX library routines for float->int conversion. */
85363ca0
ZW
8392 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
8393 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
8394 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
8395 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
8396 }
8397
c9034561 8398 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8399 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
8400 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
8401 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
8402 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
8403 }
c9034561 8404 else
c15c90bb 8405 {
c9034561 8406 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8407
8408 set_optab_libfunc (add_optab, TFmode, "_q_add");
8409 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
8410 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
8411 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
8412 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
8413 if (TARGET_PPC_GPOPT || TARGET_POWER2)
8414 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
8415
c9034561
ZW
8416 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
8417 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
8418 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
8419 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
8420 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
8421 set_optab_libfunc (le_optab, TFmode, "_q_fle");
8422
85363ca0
ZW
8423 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
8424 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
8425 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
8426 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
8427 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
8428 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
8429 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
8430 }
8431}
fba73eb1
DE
8432
8433\f
8434/* Expand a block clear operation, and return 1 if successful. Return 0
8435 if we should let the compiler generate normal code.
8436
8437 operands[0] is the destination
8438 operands[1] is the length
8439 operands[2] is the alignment */
8440
8441int
8442expand_block_clear (rtx operands[])
8443{
8444 rtx orig_dest = operands[0];
8445 rtx bytes_rtx = operands[1];
8446 rtx align_rtx = operands[2];
5514620a
GK
8447 bool constp = (GET_CODE (bytes_rtx) == CONST_INT);
8448 HOST_WIDE_INT align;
8449 HOST_WIDE_INT bytes;
fba73eb1
DE
8450 int offset;
8451 int clear_bytes;
5514620a 8452 int clear_step;
fba73eb1
DE
8453
8454 /* If this is not a fixed size move, just call memcpy */
8455 if (! constp)
8456 return 0;
8457
8458 /* If this is not a fixed size alignment, abort */
8459 if (GET_CODE (align_rtx) != CONST_INT)
8460 abort ();
8461 align = INTVAL (align_rtx) * BITS_PER_UNIT;
8462
8463 /* Anything to clear? */
8464 bytes = INTVAL (bytes_rtx);
8465 if (bytes <= 0)
8466 return 1;
8467
5514620a
GK
8468 /* Use the builtin memset after a point, to avoid huge code bloat.
8469 When optimize_size, avoid any significant code bloat; calling
8470 memset is about 4 instructions, so allow for one instruction to
8471 load zero and three to do clearing. */
8472 if (TARGET_ALTIVEC && align >= 128)
8473 clear_step = 16;
8474 else if (TARGET_POWERPC64 && align >= 32)
8475 clear_step = 8;
8476 else
8477 clear_step = 4;
fba73eb1 8478
5514620a
GK
8479 if (optimize_size && bytes > 3 * clear_step)
8480 return 0;
8481 if (! optimize_size && bytes > 8 * clear_step)
fba73eb1
DE
8482 return 0;
8483
8484 for (offset = 0; bytes > 0; offset += clear_bytes, bytes -= clear_bytes)
8485 {
fba73eb1
DE
8486 enum machine_mode mode = BLKmode;
8487 rtx dest;
f676971a 8488
5514620a
GK
8489 if (bytes >= 16 && TARGET_ALTIVEC && align >= 128)
8490 {
8491 clear_bytes = 16;
8492 mode = V4SImode;
8493 }
8494 else if (bytes >= 8 && TARGET_POWERPC64
8495 /* 64-bit loads and stores require word-aligned
8496 displacements. */
8497 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
fba73eb1
DE
8498 {
8499 clear_bytes = 8;
8500 mode = DImode;
fba73eb1 8501 }
5514620a 8502 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
fba73eb1
DE
8503 { /* move 4 bytes */
8504 clear_bytes = 4;
8505 mode = SImode;
fba73eb1 8506 }
5514620a 8507 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
fba73eb1
DE
8508 { /* move 2 bytes */
8509 clear_bytes = 2;
8510 mode = HImode;
fba73eb1
DE
8511 }
8512 else /* move 1 byte at a time */
8513 {
8514 clear_bytes = 1;
8515 mode = QImode;
fba73eb1 8516 }
f676971a 8517
fba73eb1 8518 dest = adjust_address (orig_dest, mode, offset);
f676971a 8519
5514620a 8520 emit_move_insn (dest, CONST0_RTX (mode));
fba73eb1
DE
8521 }
8522
8523 return 1;
8524}
8525
35aff10b 8526\f
7e69e155
MM
8527/* Expand a block move operation, and return 1 if successful. Return 0
8528 if we should let the compiler generate normal code.
8529
8530 operands[0] is the destination
8531 operands[1] is the source
8532 operands[2] is the length
8533 operands[3] is the alignment */
8534
3933e0e1
MM
8535#define MAX_MOVE_REG 4
8536
7e69e155 8537int
a2369ed3 8538expand_block_move (rtx operands[])
7e69e155 8539{
b6c9286a
MM
8540 rtx orig_dest = operands[0];
8541 rtx orig_src = operands[1];
7e69e155 8542 rtx bytes_rtx = operands[2];
7e69e155 8543 rtx align_rtx = operands[3];
3933e0e1 8544 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 8545 int align;
3933e0e1
MM
8546 int bytes;
8547 int offset;
7e69e155 8548 int move_bytes;
cabfd258
GK
8549 rtx stores[MAX_MOVE_REG];
8550 int num_reg = 0;
7e69e155 8551
3933e0e1 8552 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 8553 if (! constp)
3933e0e1
MM
8554 return 0;
8555
5ee95df6
FS
8556 /* If this is not a fixed size alignment, abort */
8557 if (GET_CODE (align_rtx) != CONST_INT)
8558 abort ();
fba73eb1 8559 align = INTVAL (align_rtx) * BITS_PER_UNIT;
5ee95df6 8560
7e69e155 8561 /* Anything to move? */
3933e0e1
MM
8562 bytes = INTVAL (bytes_rtx);
8563 if (bytes <= 0)
7e69e155
MM
8564 return 1;
8565
ea9982a8 8566 /* store_one_arg depends on expand_block_move to handle at least the size of
f676971a 8567 reg_parm_stack_space. */
ea9982a8 8568 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
8569 return 0;
8570
cabfd258 8571 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 8572 {
cabfd258 8573 union {
70128ad9 8574 rtx (*movmemsi) (rtx, rtx, rtx, rtx);
a2369ed3 8575 rtx (*mov) (rtx, rtx);
cabfd258
GK
8576 } gen_func;
8577 enum machine_mode mode = BLKmode;
8578 rtx src, dest;
f676971a 8579
5514620a
GK
8580 /* Altivec first, since it will be faster than a string move
8581 when it applies, and usually not significantly larger. */
8582 if (TARGET_ALTIVEC && bytes >= 16 && align >= 128)
8583 {
8584 move_bytes = 16;
8585 mode = V4SImode;
8586 gen_func.mov = gen_movv4si;
8587 }
8588 else if (TARGET_STRING
cabfd258
GK
8589 && bytes > 24 /* move up to 32 bytes at a time */
8590 && ! fixed_regs[5]
8591 && ! fixed_regs[6]
8592 && ! fixed_regs[7]
8593 && ! fixed_regs[8]
8594 && ! fixed_regs[9]
8595 && ! fixed_regs[10]
8596 && ! fixed_regs[11]
8597 && ! fixed_regs[12])
7e69e155 8598 {
cabfd258 8599 move_bytes = (bytes > 32) ? 32 : bytes;
70128ad9 8600 gen_func.movmemsi = gen_movmemsi_8reg;
cabfd258
GK
8601 }
8602 else if (TARGET_STRING
8603 && bytes > 16 /* move up to 24 bytes at a time */
8604 && ! fixed_regs[5]
8605 && ! fixed_regs[6]
8606 && ! fixed_regs[7]
8607 && ! fixed_regs[8]
8608 && ! fixed_regs[9]
8609 && ! fixed_regs[10])
8610 {
8611 move_bytes = (bytes > 24) ? 24 : bytes;
70128ad9 8612 gen_func.movmemsi = gen_movmemsi_6reg;
cabfd258
GK
8613 }
8614 else if (TARGET_STRING
8615 && bytes > 8 /* move up to 16 bytes at a time */
8616 && ! fixed_regs[5]
8617 && ! fixed_regs[6]
8618 && ! fixed_regs[7]
8619 && ! fixed_regs[8])
8620 {
8621 move_bytes = (bytes > 16) ? 16 : bytes;
70128ad9 8622 gen_func.movmemsi = gen_movmemsi_4reg;
cabfd258
GK
8623 }
8624 else if (bytes >= 8 && TARGET_POWERPC64
8625 /* 64-bit loads and stores require word-aligned
8626 displacements. */
fba73eb1 8627 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
cabfd258
GK
8628 {
8629 move_bytes = 8;
8630 mode = DImode;
8631 gen_func.mov = gen_movdi;
8632 }
8633 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
8634 { /* move up to 8 bytes at a time */
8635 move_bytes = (bytes > 8) ? 8 : bytes;
70128ad9 8636 gen_func.movmemsi = gen_movmemsi_2reg;
cabfd258 8637 }
cd7d9ca4 8638 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
cabfd258
GK
8639 { /* move 4 bytes */
8640 move_bytes = 4;
8641 mode = SImode;
8642 gen_func.mov = gen_movsi;
8643 }
cd7d9ca4 8644 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
cabfd258
GK
8645 { /* move 2 bytes */
8646 move_bytes = 2;
8647 mode = HImode;
8648 gen_func.mov = gen_movhi;
8649 }
8650 else if (TARGET_STRING && bytes > 1)
8651 { /* move up to 4 bytes at a time */
8652 move_bytes = (bytes > 4) ? 4 : bytes;
70128ad9 8653 gen_func.movmemsi = gen_movmemsi_1reg;
cabfd258
GK
8654 }
8655 else /* move 1 byte at a time */
8656 {
8657 move_bytes = 1;
8658 mode = QImode;
8659 gen_func.mov = gen_movqi;
8660 }
f676971a 8661
cabfd258
GK
8662 src = adjust_address (orig_src, mode, offset);
8663 dest = adjust_address (orig_dest, mode, offset);
f676971a
EC
8664
8665 if (mode != BLKmode)
cabfd258
GK
8666 {
8667 rtx tmp_reg = gen_reg_rtx (mode);
f676971a 8668
cabfd258
GK
8669 emit_insn ((*gen_func.mov) (tmp_reg, src));
8670 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 8671 }
3933e0e1 8672
cabfd258
GK
8673 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
8674 {
8675 int i;
8676 for (i = 0; i < num_reg; i++)
8677 emit_insn (stores[i]);
8678 num_reg = 0;
8679 }
35aff10b 8680
cabfd258 8681 if (mode == BLKmode)
7e69e155 8682 {
70128ad9 8683 /* Move the address into scratch registers. The movmemsi
cabfd258
GK
8684 patterns require zero offset. */
8685 if (!REG_P (XEXP (src, 0)))
b6c9286a 8686 {
cabfd258
GK
8687 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
8688 src = replace_equiv_address (src, src_reg);
b6c9286a 8689 }
cabfd258 8690 set_mem_size (src, GEN_INT (move_bytes));
f676971a 8691
cabfd258 8692 if (!REG_P (XEXP (dest, 0)))
3933e0e1 8693 {
cabfd258
GK
8694 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
8695 dest = replace_equiv_address (dest, dest_reg);
7e69e155 8696 }
cabfd258 8697 set_mem_size (dest, GEN_INT (move_bytes));
f676971a 8698
70128ad9 8699 emit_insn ((*gen_func.movmemsi) (dest, src,
cabfd258
GK
8700 GEN_INT (move_bytes & 31),
8701 align_rtx));
7e69e155 8702 }
7e69e155
MM
8703 }
8704
8705 return 1;
8706}
8707
d62294f5
FJ
8708\f
8709/* Return 1 if OP is suitable for a save_world call in prologue. It is
8710 known to be a PARALLEL. */
8711int
8712save_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8713{
8714 int index;
8715 int i;
8716 rtx elt;
8717 int count = XVECLEN (op, 0);
8718
8719 if (count != 55)
8720 return 0;
8721
8722 index = 0;
8723 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8724 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8725 return 0;
8726
8727 for (i=1; i <= 18; i++)
8728 {
8729 elt = XVECEXP (op, 0, index++);
8730 if (GET_CODE (elt) != SET
8731 || GET_CODE (SET_DEST (elt)) != MEM
8732 || ! memory_operand (SET_DEST (elt), DFmode)
8733 || GET_CODE (SET_SRC (elt)) != REG
8734 || GET_MODE (SET_SRC (elt)) != DFmode)
8735 return 0;
8736 }
8737
8738 for (i=1; i <= 12; i++)
8739 {
8740 elt = XVECEXP (op, 0, index++);
8741 if (GET_CODE (elt) != SET
8742 || GET_CODE (SET_DEST (elt)) != MEM
8743 || GET_CODE (SET_SRC (elt)) != REG
8744 || GET_MODE (SET_SRC (elt)) != V4SImode)
8745 return 0;
8746 }
8747
8748 for (i=1; i <= 19; i++)
8749 {
8750 elt = XVECEXP (op, 0, index++);
8751 if (GET_CODE (elt) != SET
8752 || GET_CODE (SET_DEST (elt)) != MEM
8753 || ! memory_operand (SET_DEST (elt), Pmode)
8754 || GET_CODE (SET_SRC (elt)) != REG
8755 || GET_MODE (SET_SRC (elt)) != Pmode)
8756 return 0;
8757 }
8758
8759 elt = XVECEXP (op, 0, index++);
8760 if (GET_CODE (elt) != SET
8761 || GET_CODE (SET_DEST (elt)) != MEM
8762 || ! memory_operand (SET_DEST (elt), Pmode)
8763 || GET_CODE (SET_SRC (elt)) != REG
8764 || REGNO (SET_SRC (elt)) != CR2_REGNO
8765 || GET_MODE (SET_SRC (elt)) != Pmode)
8766 return 0;
8767
8768 if (GET_CODE (XVECEXP (op, 0, index++)) != USE
8769 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8770 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8771 return 0;
8772 return 1;
8773}
8774
8775/* Return 1 if OP is suitable for a save_world call in prologue. It is
8776 known to be a PARALLEL. */
8777int
8778restore_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8779{
8780 int index;
8781 int i;
8782 rtx elt;
8783 int count = XVECLEN (op, 0);
8784
8785 if (count != 59)
8786 return 0;
8787
8788 index = 0;
8789 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
8790 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8791 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8792 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8793 return 0;
8794
8795 elt = XVECEXP (op, 0, index++);
8796 if (GET_CODE (elt) != SET
8797 || GET_CODE (SET_SRC (elt)) != MEM
8798 || ! memory_operand (SET_SRC (elt), Pmode)
8799 || GET_CODE (SET_DEST (elt)) != REG
8800 || REGNO (SET_DEST (elt)) != CR2_REGNO
8801 || GET_MODE (SET_DEST (elt)) != Pmode)
8802 return 0;
8803
8804 for (i=1; i <= 19; i++)
8805 {
8806 elt = XVECEXP (op, 0, index++);
8807 if (GET_CODE (elt) != SET
8808 || GET_CODE (SET_SRC (elt)) != MEM
8809 || ! memory_operand (SET_SRC (elt), Pmode)
8810 || GET_CODE (SET_DEST (elt)) != REG
8811 || GET_MODE (SET_DEST (elt)) != Pmode)
8812 return 0;
8813 }
8814
8815 for (i=1; i <= 12; i++)
8816 {
8817 elt = XVECEXP (op, 0, index++);
8818 if (GET_CODE (elt) != SET
8819 || GET_CODE (SET_SRC (elt)) != MEM
8820 || GET_CODE (SET_DEST (elt)) != REG
8821 || GET_MODE (SET_DEST (elt)) != V4SImode)
8822 return 0;
8823 }
8824
8825 for (i=1; i <= 18; i++)
8826 {
8827 elt = XVECEXP (op, 0, index++);
8828 if (GET_CODE (elt) != SET
8829 || GET_CODE (SET_SRC (elt)) != MEM
8830 || ! memory_operand (SET_SRC (elt), DFmode)
8831 || GET_CODE (SET_DEST (elt)) != REG
8832 || GET_MODE (SET_DEST (elt)) != DFmode)
8833 return 0;
8834 }
8835
8836 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8837 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8838 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8839 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8840 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8841 return 0;
8842 return 1;
8843}
8844
9878760c
RK
8845\f
8846/* Return 1 if OP is a load multiple operation. It is known to be a
8847 PARALLEL and the first section will be tested. */
8848
8849int
a2369ed3 8850load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8851{
8852 int count = XVECLEN (op, 0);
e2c953b6 8853 unsigned int dest_regno;
9878760c
RK
8854 rtx src_addr;
8855 int i;
8856
8857 /* Perform a quick check so we don't blow up below. */
8858 if (count <= 1
8859 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8860 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8861 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8862 return 0;
8863
8864 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8865 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8866
8867 for (i = 1; i < count; i++)
8868 {
8869 rtx elt = XVECEXP (op, 0, i);
8870
8871 if (GET_CODE (elt) != SET
8872 || GET_CODE (SET_DEST (elt)) != REG
8873 || GET_MODE (SET_DEST (elt)) != SImode
8874 || REGNO (SET_DEST (elt)) != dest_regno + i
8875 || GET_CODE (SET_SRC (elt)) != MEM
8876 || GET_MODE (SET_SRC (elt)) != SImode
8877 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
8878 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
8879 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
8880 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
8881 return 0;
8882 }
8883
8884 return 1;
8885}
8886
8887/* Similar, but tests for store multiple. Here, the second vector element
8888 is a CLOBBER. It will be tested later. */
8889
8890int
a2369ed3 8891store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8892{
8893 int count = XVECLEN (op, 0) - 1;
e2c953b6 8894 unsigned int src_regno;
9878760c
RK
8895 rtx dest_addr;
8896 int i;
8897
8898 /* Perform a quick check so we don't blow up below. */
8899 if (count <= 1
8900 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8901 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8902 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8903 return 0;
8904
8905 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8906 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8907
8908 for (i = 1; i < count; i++)
8909 {
8910 rtx elt = XVECEXP (op, 0, i + 1);
8911
8912 if (GET_CODE (elt) != SET
8913 || GET_CODE (SET_SRC (elt)) != REG
8914 || GET_MODE (SET_SRC (elt)) != SImode
8915 || REGNO (SET_SRC (elt)) != src_regno + i
8916 || GET_CODE (SET_DEST (elt)) != MEM
8917 || GET_MODE (SET_DEST (elt)) != SImode
8918 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
8919 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
8920 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
8921 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
8922 return 0;
8923 }
8924
8925 return 1;
8926}
9ebbca7d 8927
9caa3eb2
DE
8928/* Return a string to perform a load_multiple operation.
8929 operands[0] is the vector.
8930 operands[1] is the source address.
8931 operands[2] is the first destination register. */
8932
8933const char *
a2369ed3 8934rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
8935{
8936 /* We have to handle the case where the pseudo used to contain the address
8937 is assigned to one of the output registers. */
8938 int i, j;
8939 int words = XVECLEN (operands[0], 0);
8940 rtx xop[10];
8941
8942 if (XVECLEN (operands[0], 0) == 1)
8943 return "{l|lwz} %2,0(%1)";
8944
8945 for (i = 0; i < words; i++)
8946 if (refers_to_regno_p (REGNO (operands[2]) + i,
8947 REGNO (operands[2]) + i + 1, operands[1], 0))
8948 {
8949 if (i == words-1)
8950 {
8951 xop[0] = GEN_INT (4 * (words-1));
8952 xop[1] = operands[1];
8953 xop[2] = operands[2];
8954 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
8955 return "";
8956 }
8957 else if (i == 0)
8958 {
8959 xop[0] = GEN_INT (4 * (words-1));
8960 xop[1] = operands[1];
8961 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
8962 output_asm_insn ("{cal %1,4(%1)|addi %1,%1,4}\n\t{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,-4(%1)", xop);
8963 return "";
8964 }
8965 else
8966 {
8967 for (j = 0; j < words; j++)
8968 if (j != i)
8969 {
8970 xop[0] = GEN_INT (j * 4);
8971 xop[1] = operands[1];
8972 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
8973 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
8974 }
8975 xop[0] = GEN_INT (i * 4);
8976 xop[1] = operands[1];
8977 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
8978 return "";
8979 }
8980 }
8981
8982 return "{lsi|lswi} %2,%1,%N0";
8983}
8984
00b960c7
AH
8985/* Return 1 for a parallel vrsave operation. */
8986
8987int
a2369ed3 8988vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
8989{
8990 int count = XVECLEN (op, 0);
8991 unsigned int dest_regno, src_regno;
8992 int i;
8993
8994 if (count <= 1
8995 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8996 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 8997 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
8998 return 0;
8999
9000 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9001 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9002
9003 if (dest_regno != VRSAVE_REGNO
9004 && src_regno != VRSAVE_REGNO)
9005 return 0;
9006
9007 for (i = 1; i < count; i++)
9008 {
9009 rtx elt = XVECEXP (op, 0, i);
9010
9aa86737
AH
9011 if (GET_CODE (elt) != CLOBBER
9012 && GET_CODE (elt) != SET)
00b960c7
AH
9013 return 0;
9014 }
9015
9016 return 1;
9017}
9018
2c4a9cff
DE
9019/* Return 1 for an PARALLEL suitable for mfcr. */
9020
9021int
a2369ed3 9022mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
9023{
9024 int count = XVECLEN (op, 0);
9025 int i;
9026
9027 /* Perform a quick check so we don't blow up below. */
9028 if (count < 1
9029 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9030 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
9031 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9032 return 0;
9033
9034 for (i = 0; i < count; i++)
9035 {
9036 rtx exp = XVECEXP (op, 0, i);
9037 rtx unspec;
9038 int maskval;
9039 rtx src_reg;
9040
9041 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
9042
9043 if (GET_CODE (src_reg) != REG
9044 || GET_MODE (src_reg) != CCmode
9045 || ! CR_REGNO_P (REGNO (src_reg)))
9046 return 0;
9047
9048 if (GET_CODE (exp) != SET
9049 || GET_CODE (SET_DEST (exp)) != REG
9050 || GET_MODE (SET_DEST (exp)) != SImode
9051 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
9052 return 0;
9053 unspec = SET_SRC (exp);
9054 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
9055
9056 if (GET_CODE (unspec) != UNSPEC
9057 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
9058 || XVECLEN (unspec, 0) != 2
9059 || XVECEXP (unspec, 0, 0) != src_reg
9060 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
9061 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
9062 return 0;
9063 }
9064 return 1;
9065}
9066
a4f6c312 9067/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
9068
9069int
a2369ed3 9070mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9071{
9072 int count = XVECLEN (op, 0);
9073 int i;
9ebbca7d
GK
9074 rtx src_reg;
9075
9076 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
9077 if (count < 1
9078 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9079 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
9080 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 9081 return 0;
e35b9579 9082 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
f676971a 9083
9ebbca7d
GK
9084 if (GET_CODE (src_reg) != REG
9085 || GET_MODE (src_reg) != SImode
9086 || ! INT_REGNO_P (REGNO (src_reg)))
9087 return 0;
9088
e35b9579 9089 for (i = 0; i < count; i++)
9ebbca7d
GK
9090 {
9091 rtx exp = XVECEXP (op, 0, i);
9092 rtx unspec;
9093 int maskval;
f676971a 9094
9ebbca7d
GK
9095 if (GET_CODE (exp) != SET
9096 || GET_CODE (SET_DEST (exp)) != REG
9097 || GET_MODE (SET_DEST (exp)) != CCmode
9098 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
9099 return 0;
9100 unspec = SET_SRC (exp);
9101 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
f676971a 9102
9ebbca7d 9103 if (GET_CODE (unspec) != UNSPEC
615158e2 9104 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
9105 || XVECLEN (unspec, 0) != 2
9106 || XVECEXP (unspec, 0, 0) != src_reg
9107 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
9108 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
9109 return 0;
9110 }
e35b9579 9111 return 1;
9ebbca7d
GK
9112}
9113
a4f6c312 9114/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
9115
9116int
a2369ed3 9117lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9118{
9119 int count = XVECLEN (op, 0);
e2c953b6 9120 unsigned int dest_regno;
9ebbca7d 9121 rtx src_addr;
e2c953b6 9122 unsigned int base_regno;
9ebbca7d
GK
9123 HOST_WIDE_INT offset;
9124 int i;
9125
9126 /* Perform a quick check so we don't blow up below. */
9127 if (count <= 1
9128 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9129 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
9130 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
9131 return 0;
9132
9133 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9134 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
9135
9136 if (dest_regno > 31
e2c953b6 9137 || count != 32 - (int) dest_regno)
9ebbca7d
GK
9138 return 0;
9139
4d588c14 9140 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
9141 {
9142 offset = 0;
9143 base_regno = REGNO (src_addr);
9144 if (base_regno == 0)
9145 return 0;
9146 }
76d2b81d 9147 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
9148 {
9149 offset = INTVAL (XEXP (src_addr, 1));
9150 base_regno = REGNO (XEXP (src_addr, 0));
9151 }
9152 else
9153 return 0;
9154
9155 for (i = 0; i < count; i++)
9156 {
9157 rtx elt = XVECEXP (op, 0, i);
9158 rtx newaddr;
9159 rtx addr_reg;
9160 HOST_WIDE_INT newoffset;
9161
9162 if (GET_CODE (elt) != SET
9163 || GET_CODE (SET_DEST (elt)) != REG
9164 || GET_MODE (SET_DEST (elt)) != SImode
9165 || REGNO (SET_DEST (elt)) != dest_regno + i
9166 || GET_CODE (SET_SRC (elt)) != MEM
9167 || GET_MODE (SET_SRC (elt)) != SImode)
9168 return 0;
9169 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 9170 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9171 {
9172 newoffset = 0;
9173 addr_reg = newaddr;
9174 }
76d2b81d 9175 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9176 {
9177 addr_reg = XEXP (newaddr, 0);
9178 newoffset = INTVAL (XEXP (newaddr, 1));
9179 }
9180 else
9181 return 0;
9182 if (REGNO (addr_reg) != base_regno
9183 || newoffset != offset + 4 * i)
9184 return 0;
9185 }
9186
9187 return 1;
9188}
9189
a4f6c312 9190/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
9191
9192int
a2369ed3 9193stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9194{
9195 int count = XVECLEN (op, 0);
e2c953b6 9196 unsigned int src_regno;
9ebbca7d 9197 rtx dest_addr;
e2c953b6 9198 unsigned int base_regno;
9ebbca7d
GK
9199 HOST_WIDE_INT offset;
9200 int i;
9201
9202 /* Perform a quick check so we don't blow up below. */
9203 if (count <= 1
9204 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9205 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
9206 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
9207 return 0;
9208
9209 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9210 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
9211
9212 if (src_regno > 31
e2c953b6 9213 || count != 32 - (int) src_regno)
9ebbca7d
GK
9214 return 0;
9215
4d588c14 9216 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
9217 {
9218 offset = 0;
9219 base_regno = REGNO (dest_addr);
9220 if (base_regno == 0)
9221 return 0;
9222 }
76d2b81d 9223 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
9224 {
9225 offset = INTVAL (XEXP (dest_addr, 1));
9226 base_regno = REGNO (XEXP (dest_addr, 0));
9227 }
9228 else
9229 return 0;
9230
9231 for (i = 0; i < count; i++)
9232 {
9233 rtx elt = XVECEXP (op, 0, i);
9234 rtx newaddr;
9235 rtx addr_reg;
9236 HOST_WIDE_INT newoffset;
9237
9238 if (GET_CODE (elt) != SET
9239 || GET_CODE (SET_SRC (elt)) != REG
9240 || GET_MODE (SET_SRC (elt)) != SImode
9241 || REGNO (SET_SRC (elt)) != src_regno + i
9242 || GET_CODE (SET_DEST (elt)) != MEM
9243 || GET_MODE (SET_DEST (elt)) != SImode)
9244 return 0;
9245 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 9246 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9247 {
9248 newoffset = 0;
9249 addr_reg = newaddr;
9250 }
76d2b81d 9251 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9252 {
9253 addr_reg = XEXP (newaddr, 0);
9254 newoffset = INTVAL (XEXP (newaddr, 1));
9255 }
9256 else
9257 return 0;
9258 if (REGNO (addr_reg) != base_regno
9259 || newoffset != offset + 4 * i)
9260 return 0;
9261 }
9262
9263 return 1;
9264}
9878760c 9265\f
a4f6c312
SS
9266/* A validation routine: say whether CODE, a condition code, and MODE
9267 match. The other alternatives either don't make sense or should
9268 never be generated. */
39a10a29 9269
39a10a29 9270static void
a2369ed3 9271validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 9272{
ec8e098d
PB
9273 if ((GET_RTX_CLASS (code) != RTX_COMPARE
9274 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
9275 || GET_MODE_CLASS (mode) != MODE_CC)
9276 abort ();
9277
9278 /* These don't make sense. */
9279 if ((code == GT || code == LT || code == GE || code == LE)
9280 && mode == CCUNSmode)
9281 abort ();
9282
9283 if ((code == GTU || code == LTU || code == GEU || code == LEU)
9284 && mode != CCUNSmode)
9285 abort ();
9286
9287 if (mode != CCFPmode
9288 && (code == ORDERED || code == UNORDERED
9289 || code == UNEQ || code == LTGT
9290 || code == UNGT || code == UNLT
9291 || code == UNGE || code == UNLE))
a4f6c312 9292 abort ();
f676971a
EC
9293
9294 /* These should never be generated except for
bc9ec0e0 9295 flag_finite_math_only. */
39a10a29 9296 if (mode == CCFPmode
ad72b533 9297 && ! flag_finite_math_only
39a10a29
GK
9298 && (code == LE || code == GE
9299 || code == UNEQ || code == LTGT
9300 || code == UNGT || code == UNLT))
9301 abort ();
9302
9303 /* These are invalid; the information is not there. */
f676971a 9304 if (mode == CCEQmode
39a10a29
GK
9305 && code != EQ && code != NE)
9306 abort ();
9307}
9308
9878760c
RK
9309/* Return 1 if OP is a comparison operation that is valid for a branch insn.
9310 We only check the opcode against the mode of the CC value here. */
9311
9312int
a2369ed3 9313branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
9314{
9315 enum rtx_code code = GET_CODE (op);
9316 enum machine_mode cc_mode;
9317
ec8e098d 9318 if (!COMPARISON_P (op))
9878760c
RK
9319 return 0;
9320
9321 cc_mode = GET_MODE (XEXP (op, 0));
9322 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
9323 return 0;
9324
39a10a29 9325 validate_condition_mode (code, cc_mode);
9878760c 9326
39a10a29
GK
9327 return 1;
9328}
9329
9330/* Return 1 if OP is a comparison operation that is valid for a branch
9331 insn and which is true if the corresponding bit in the CC register
9332 is set. */
9333
9334int
a2369ed3 9335branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
9336{
9337 enum rtx_code code;
9338
8daf2e65 9339 if (! branch_comparison_operator (op, mode))
9878760c
RK
9340 return 0;
9341
39a10a29
GK
9342 code = GET_CODE (op);
9343 return (code == EQ || code == LT || code == GT
9344 || code == LTU || code == GTU
9345 || code == UNORDERED);
9878760c
RK
9346}
9347
b7053a3f
GK
9348/* Return 1 if OP is a comparison operation that is valid for an scc
9349 insn: it must be a positive comparison. */
9878760c
RK
9350
9351int
a2369ed3 9352scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 9353{
b7053a3f 9354 return branch_positive_comparison_operator (op, mode);
9878760c 9355}
e0cd0770
JC
9356
9357int
a2369ed3 9358trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
9359{
9360 if (mode != VOIDmode && mode != GET_MODE (op))
9361 return 0;
ec8e098d 9362 return COMPARISON_P (op);
e0cd0770 9363}
dfbdccdb
GK
9364
9365int
a2369ed3 9366boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
9367{
9368 enum rtx_code code = GET_CODE (op);
9369 return (code == AND || code == IOR || code == XOR);
9370}
1d328b19
GK
9371
9372int
a2369ed3 9373boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
9374{
9375 enum rtx_code code = GET_CODE (op);
9376 return (code == IOR || code == XOR);
9377}
50a0b056
GK
9378
9379int
a2369ed3 9380min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
9381{
9382 enum rtx_code code = GET_CODE (op);
9383 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
9384}
9878760c
RK
9385\f
9386/* Return 1 if ANDOP is a mask that has no bits on that are not in the
9387 mask required to convert the result of a rotate insn into a shift
b1765bde 9388 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
9389
9390int
a2369ed3 9391includes_lshift_p (rtx shiftop, rtx andop)
9878760c 9392{
e2c953b6
DE
9393 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9394
9395 shift_mask <<= INTVAL (shiftop);
9878760c 9396
b1765bde 9397 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
9398}
9399
9400/* Similar, but for right shift. */
9401
9402int
a2369ed3 9403includes_rshift_p (rtx shiftop, rtx andop)
9878760c 9404{
a7653a2c 9405 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
9406
9407 shift_mask >>= INTVAL (shiftop);
9408
b1765bde 9409 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
9410}
9411
c5059423
AM
9412/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
9413 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 9414 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
9415
9416int
a2369ed3 9417includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 9418{
c5059423
AM
9419 if (GET_CODE (andop) == CONST_INT)
9420 {
02071907 9421 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 9422
c5059423 9423 c = INTVAL (andop);
02071907 9424 if (c == 0 || c == ~0)
c5059423 9425 return 0;
e2c953b6 9426
02071907 9427 shift_mask = ~0;
c5059423
AM
9428 shift_mask <<= INTVAL (shiftop);
9429
b6d08ca1 9430 /* Find the least significant one bit. */
c5059423
AM
9431 lsb = c & -c;
9432
9433 /* It must coincide with the LSB of the shift mask. */
9434 if (-lsb != shift_mask)
9435 return 0;
e2c953b6 9436
c5059423
AM
9437 /* Invert to look for the next transition (if any). */
9438 c = ~c;
9439
9440 /* Remove the low group of ones (originally low group of zeros). */
9441 c &= -lsb;
9442
9443 /* Again find the lsb, and check we have all 1's above. */
9444 lsb = c & -c;
9445 return c == -lsb;
9446 }
9447 else if (GET_CODE (andop) == CONST_DOUBLE
9448 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9449 {
02071907
AM
9450 HOST_WIDE_INT low, high, lsb;
9451 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
9452
9453 low = CONST_DOUBLE_LOW (andop);
9454 if (HOST_BITS_PER_WIDE_INT < 64)
9455 high = CONST_DOUBLE_HIGH (andop);
9456
9457 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 9458 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
9459 return 0;
9460
9461 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9462 {
02071907 9463 shift_mask_high = ~0;
c5059423
AM
9464 if (INTVAL (shiftop) > 32)
9465 shift_mask_high <<= INTVAL (shiftop) - 32;
9466
9467 lsb = high & -high;
9468
9469 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
9470 return 0;
9471
9472 high = ~high;
9473 high &= -lsb;
9474
9475 lsb = high & -high;
9476 return high == -lsb;
9477 }
9478
02071907 9479 shift_mask_low = ~0;
c5059423
AM
9480 shift_mask_low <<= INTVAL (shiftop);
9481
9482 lsb = low & -low;
9483
9484 if (-lsb != shift_mask_low)
9485 return 0;
9486
9487 if (HOST_BITS_PER_WIDE_INT < 64)
9488 high = ~high;
9489 low = ~low;
9490 low &= -lsb;
9491
9492 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9493 {
9494 lsb = high & -high;
9495 return high == -lsb;
9496 }
9497
9498 lsb = low & -low;
9499 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
9500 }
9501 else
9502 return 0;
9503}
e2c953b6 9504
c5059423
AM
9505/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
9506 to perform a left shift. It must have SHIFTOP or more least
c1207243 9507 significant 0's, with the remainder of the word 1's. */
e2c953b6 9508
c5059423 9509int
a2369ed3 9510includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 9511{
e2c953b6 9512 if (GET_CODE (andop) == CONST_INT)
c5059423 9513 {
02071907 9514 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 9515
02071907 9516 shift_mask = ~0;
c5059423
AM
9517 shift_mask <<= INTVAL (shiftop);
9518 c = INTVAL (andop);
9519
c1207243 9520 /* Find the least significant one bit. */
c5059423
AM
9521 lsb = c & -c;
9522
9523 /* It must be covered by the shift mask.
a4f6c312 9524 This test also rejects c == 0. */
c5059423
AM
9525 if ((lsb & shift_mask) == 0)
9526 return 0;
9527
9528 /* Check we have all 1's above the transition, and reject all 1's. */
9529 return c == -lsb && lsb != 1;
9530 }
9531 else if (GET_CODE (andop) == CONST_DOUBLE
9532 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9533 {
02071907 9534 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
9535
9536 low = CONST_DOUBLE_LOW (andop);
9537
9538 if (HOST_BITS_PER_WIDE_INT < 64)
9539 {
02071907 9540 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
9541
9542 high = CONST_DOUBLE_HIGH (andop);
9543
9544 if (low == 0)
9545 {
02071907 9546 shift_mask_high = ~0;
c5059423
AM
9547 if (INTVAL (shiftop) > 32)
9548 shift_mask_high <<= INTVAL (shiftop) - 32;
9549
9550 lsb = high & -high;
9551
9552 if ((lsb & shift_mask_high) == 0)
9553 return 0;
9554
9555 return high == -lsb;
9556 }
9557 if (high != ~0)
9558 return 0;
9559 }
9560
02071907 9561 shift_mask_low = ~0;
c5059423
AM
9562 shift_mask_low <<= INTVAL (shiftop);
9563
9564 lsb = low & -low;
9565
9566 if ((lsb & shift_mask_low) == 0)
9567 return 0;
9568
9569 return low == -lsb && lsb != 1;
9570 }
e2c953b6 9571 else
c5059423 9572 return 0;
9878760c 9573}
35068b43 9574
11ac38b2
DE
9575/* Return 1 if operands will generate a valid arguments to rlwimi
9576instruction for insert with right shift in 64-bit mode. The mask may
9577not start on the first bit or stop on the last bit because wrap-around
9578effects of instruction do not correspond to semantics of RTL insn. */
9579
9580int
9581insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop)
9582{
9583 if (INTVAL (startop) < 64
9584 && INTVAL (startop) > 32
9585 && (INTVAL (sizeop) + INTVAL (startop) < 64)
9586 && (INTVAL (sizeop) + INTVAL (startop) > 33)
9587 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) < 96)
9588 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) >= 64)
9589 && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop))
9590 return 1;
9591
9592 return 0;
9593}
9594
35068b43 9595/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
90f81f99 9596 for lfq and stfq insns iff the registers are hard registers. */
35068b43
RK
9597
9598int
a2369ed3 9599registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
9600{
9601 /* We might have been passed a SUBREG. */
f676971a 9602 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
35068b43 9603 return 0;
f676971a 9604
90f81f99
AP
9605 /* We might have been passed non floating point registers. */
9606 if (!FP_REGNO_P (REGNO (reg1))
9607 || !FP_REGNO_P (REGNO (reg2)))
9608 return 0;
35068b43
RK
9609
9610 return (REGNO (reg1) == REGNO (reg2) - 1);
9611}
9612
a4f6c312
SS
9613/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
9614 addr1 and addr2 must be in consecutive memory locations
9615 (addr2 == addr1 + 8). */
35068b43
RK
9616
9617int
90f81f99 9618mems_ok_for_quad_peep (rtx mem1, rtx mem2)
35068b43 9619{
90f81f99 9620 rtx addr1, addr2;
e2c953b6 9621 unsigned int reg1;
35068b43
RK
9622 int offset1;
9623
90f81f99
AP
9624 /* The mems cannot be volatile. */
9625 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
9626 return 0;
f676971a 9627
90f81f99
AP
9628 addr1 = XEXP (mem1, 0);
9629 addr2 = XEXP (mem2, 0);
9630
35068b43
RK
9631 /* Extract an offset (if used) from the first addr. */
9632 if (GET_CODE (addr1) == PLUS)
9633 {
9634 /* If not a REG, return zero. */
9635 if (GET_CODE (XEXP (addr1, 0)) != REG)
9636 return 0;
9637 else
9638 {
c4ad648e 9639 reg1 = REGNO (XEXP (addr1, 0));
35068b43
RK
9640 /* The offset must be constant! */
9641 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
c4ad648e
AM
9642 return 0;
9643 offset1 = INTVAL (XEXP (addr1, 1));
35068b43
RK
9644 }
9645 }
9646 else if (GET_CODE (addr1) != REG)
9647 return 0;
9648 else
9649 {
9650 reg1 = REGNO (addr1);
9651 /* This was a simple (mem (reg)) expression. Offset is 0. */
9652 offset1 = 0;
9653 }
9654
a2369ed3 9655 /* Make sure the second address is a (mem (plus (reg) (const_int)))
f676971a 9656 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
0f6937fe 9657 register as addr1. */
984e25ac 9658 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 9659 return 1;
35068b43
RK
9660 if (GET_CODE (addr2) != PLUS)
9661 return 0;
9662
9663 if (GET_CODE (XEXP (addr2, 0)) != REG
9664 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
9665 return 0;
9666
9667 if (reg1 != REGNO (XEXP (addr2, 0)))
9668 return 0;
9669
9670 /* The offset for the second addr must be 8 more than the first addr. */
9671 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
9672 return 0;
9673
9674 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
9675 instructions. */
9676 return 1;
9677}
9878760c
RK
9678\f
9679/* Return the register class of a scratch register needed to copy IN into
9680 or out of a register in CLASS in MODE. If it can be done directly,
9681 NO_REGS is returned. */
9682
9683enum reg_class
f676971a 9684secondary_reload_class (enum reg_class class,
a9baceb1
GK
9685 enum machine_mode mode ATTRIBUTE_UNUSED,
9686 rtx in)
9878760c 9687{
5accd822 9688 int regno;
9878760c 9689
ab82a49f
AP
9690 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
9691#if TARGET_MACHO
c4ad648e 9692 && MACHOPIC_INDIRECT
ab82a49f 9693#endif
c4ad648e 9694 ))
46fad5b7
DJ
9695 {
9696 /* We cannot copy a symbolic operand directly into anything
c4ad648e
AM
9697 other than BASE_REGS for TARGET_ELF. So indicate that a
9698 register from BASE_REGS is needed as an intermediate
9699 register.
f676971a 9700
46fad5b7
DJ
9701 On Darwin, pic addresses require a load from memory, which
9702 needs a base register. */
9703 if (class != BASE_REGS
c4ad648e
AM
9704 && (GET_CODE (in) == SYMBOL_REF
9705 || GET_CODE (in) == HIGH
9706 || GET_CODE (in) == LABEL_REF
9707 || GET_CODE (in) == CONST))
9708 return BASE_REGS;
46fad5b7 9709 }
e7b7998a 9710
5accd822
DE
9711 if (GET_CODE (in) == REG)
9712 {
9713 regno = REGNO (in);
9714 if (regno >= FIRST_PSEUDO_REGISTER)
9715 {
9716 regno = true_regnum (in);
9717 if (regno >= FIRST_PSEUDO_REGISTER)
9718 regno = -1;
9719 }
9720 }
9721 else if (GET_CODE (in) == SUBREG)
9722 {
9723 regno = true_regnum (in);
9724 if (regno >= FIRST_PSEUDO_REGISTER)
9725 regno = -1;
9726 }
9727 else
9728 regno = -1;
9729
9878760c
RK
9730 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
9731 into anything. */
9732 if (class == GENERAL_REGS || class == BASE_REGS
9733 || (regno >= 0 && INT_REGNO_P (regno)))
9734 return NO_REGS;
9735
9736 /* Constants, memory, and FP registers can go into FP registers. */
9737 if ((regno == -1 || FP_REGNO_P (regno))
9738 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
9739 return NO_REGS;
9740
0ac081f6
AH
9741 /* Memory, and AltiVec registers can go into AltiVec registers. */
9742 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
9743 && class == ALTIVEC_REGS)
9744 return NO_REGS;
9745
9878760c
RK
9746 /* We can copy among the CR registers. */
9747 if ((class == CR_REGS || class == CR0_REGS)
9748 && regno >= 0 && CR_REGNO_P (regno))
9749 return NO_REGS;
9750
9751 /* Otherwise, we need GENERAL_REGS. */
9752 return GENERAL_REGS;
9753}
9754\f
9755/* Given a comparison operation, return the bit number in CCR to test. We
f676971a 9756 know this is a valid comparison.
9878760c
RK
9757
9758 SCC_P is 1 if this is for an scc. That means that %D will have been
9759 used instead of %C, so the bits will be in different places.
9760
b4ac57ab 9761 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
9762
9763int
a2369ed3 9764ccr_bit (rtx op, int scc_p)
9878760c
RK
9765{
9766 enum rtx_code code = GET_CODE (op);
9767 enum machine_mode cc_mode;
9768 int cc_regnum;
9769 int base_bit;
9ebbca7d 9770 rtx reg;
9878760c 9771
ec8e098d 9772 if (!COMPARISON_P (op))
9878760c
RK
9773 return -1;
9774
9ebbca7d
GK
9775 reg = XEXP (op, 0);
9776
9777 if (GET_CODE (reg) != REG
9778 || ! CR_REGNO_P (REGNO (reg)))
9779 abort ();
9780
9781 cc_mode = GET_MODE (reg);
9782 cc_regnum = REGNO (reg);
9783 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 9784
39a10a29 9785 validate_condition_mode (code, cc_mode);
c5defebb 9786
b7053a3f
GK
9787 /* When generating a sCOND operation, only positive conditions are
9788 allowed. */
9789 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
9790 && code != GTU && code != LTU)
9791 abort ();
f676971a 9792
9878760c
RK
9793 switch (code)
9794 {
9795 case NE:
9796 return scc_p ? base_bit + 3 : base_bit + 2;
9797 case EQ:
9798 return base_bit + 2;
1c882ea4 9799 case GT: case GTU: case UNLE:
9878760c 9800 return base_bit + 1;
1c882ea4 9801 case LT: case LTU: case UNGE:
9878760c 9802 return base_bit;
1c882ea4
GK
9803 case ORDERED: case UNORDERED:
9804 return base_bit + 3;
9878760c
RK
9805
9806 case GE: case GEU:
39a10a29 9807 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
9808 unordered position. So test that bit. For integer, this is ! LT
9809 unless this is an scc insn. */
39a10a29 9810 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
9811
9812 case LE: case LEU:
39a10a29 9813 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 9814
9878760c
RK
9815 default:
9816 abort ();
9817 }
9818}
1ff7789b 9819\f
8d30c4ee 9820/* Return the GOT register. */
1ff7789b
MM
9821
9822struct rtx_def *
a2369ed3 9823rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 9824{
a4f6c312
SS
9825 /* The second flow pass currently (June 1999) can't update
9826 regs_ever_live without disturbing other parts of the compiler, so
9827 update it here to make the prolog/epilogue code happy. */
1db02437
FS
9828 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
9829 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 9830
8d30c4ee 9831 current_function_uses_pic_offset_table = 1;
3cb999d8 9832
1ff7789b
MM
9833 return pic_offset_table_rtx;
9834}
a7df97e6 9835\f
e2500fed
GK
9836/* Function to init struct machine_function.
9837 This will be called, via a pointer variable,
9838 from push_function_context. */
a7df97e6 9839
e2500fed 9840static struct machine_function *
863d938c 9841rs6000_init_machine_status (void)
a7df97e6 9842{
e2500fed 9843 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 9844}
9878760c 9845\f
0ba1b2ff
AM
9846/* These macros test for integers and extract the low-order bits. */
9847#define INT_P(X) \
9848((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
9849 && GET_MODE (X) == VOIDmode)
9850
9851#define INT_LOWPART(X) \
9852 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
9853
9854int
a2369ed3 9855extract_MB (rtx op)
0ba1b2ff
AM
9856{
9857 int i;
9858 unsigned long val = INT_LOWPART (op);
9859
9860 /* If the high bit is zero, the value is the first 1 bit we find
9861 from the left. */
9862 if ((val & 0x80000000) == 0)
9863 {
9864 if ((val & 0xffffffff) == 0)
9865 abort ();
9866
9867 i = 1;
9868 while (((val <<= 1) & 0x80000000) == 0)
9869 ++i;
9870 return i;
9871 }
9872
9873 /* If the high bit is set and the low bit is not, or the mask is all
9874 1's, the value is zero. */
9875 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
9876 return 0;
9877
9878 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9879 from the right. */
9880 i = 31;
9881 while (((val >>= 1) & 1) != 0)
9882 --i;
9883
9884 return i;
9885}
9886
9887int
a2369ed3 9888extract_ME (rtx op)
0ba1b2ff
AM
9889{
9890 int i;
9891 unsigned long val = INT_LOWPART (op);
9892
9893 /* If the low bit is zero, the value is the first 1 bit we find from
9894 the right. */
9895 if ((val & 1) == 0)
9896 {
9897 if ((val & 0xffffffff) == 0)
9898 abort ();
9899
9900 i = 30;
9901 while (((val >>= 1) & 1) == 0)
9902 --i;
9903
9904 return i;
9905 }
9906
9907 /* If the low bit is set and the high bit is not, or the mask is all
9908 1's, the value is 31. */
9909 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
9910 return 31;
9911
9912 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9913 from the left. */
9914 i = 0;
9915 while (((val <<= 1) & 0x80000000) != 0)
9916 ++i;
9917
9918 return i;
9919}
9920
c4501e62
JJ
9921/* Locate some local-dynamic symbol still in use by this function
9922 so that we can print its name in some tls_ld pattern. */
9923
9924static const char *
863d938c 9925rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
9926{
9927 rtx insn;
9928
9929 if (cfun->machine->some_ld_name)
9930 return cfun->machine->some_ld_name;
9931
9932 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
9933 if (INSN_P (insn)
9934 && for_each_rtx (&PATTERN (insn),
9935 rs6000_get_some_local_dynamic_name_1, 0))
9936 return cfun->machine->some_ld_name;
9937
9938 abort ();
9939}
9940
9941/* Helper function for rs6000_get_some_local_dynamic_name. */
9942
9943static int
a2369ed3 9944rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
9945{
9946 rtx x = *px;
9947
9948 if (GET_CODE (x) == SYMBOL_REF)
9949 {
9950 const char *str = XSTR (x, 0);
9951 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
9952 {
9953 cfun->machine->some_ld_name = str;
9954 return 1;
9955 }
9956 }
9957
9958 return 0;
9959}
9960
85b776df
AM
9961/* Write out a function code label. */
9962
9963void
9964rs6000_output_function_entry (FILE *file, const char *fname)
9965{
9966 if (fname[0] != '.')
9967 {
9968 switch (DEFAULT_ABI)
9969 {
9970 default:
9971 abort ();
9972
9973 case ABI_AIX:
9974 if (DOT_SYMBOLS)
9975 putc ('.', file);
9976 else
9977 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "L.");
9978 break;
9979
9980 case ABI_V4:
9981 case ABI_DARWIN:
9982 break;
9983 }
9984 }
9985 if (TARGET_AIX)
9986 RS6000_OUTPUT_BASENAME (file, fname);
9987 else
9988 assemble_name (file, fname);
9989}
9990
9878760c
RK
9991/* Print an operand. Recognize special options, documented below. */
9992
38c1f2d7 9993#if TARGET_ELF
d9407988 9994#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 9995#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
9996#else
9997#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 9998#define SMALL_DATA_REG 0
ba5e43aa
MM
9999#endif
10000
9878760c 10001void
a2369ed3 10002print_operand (FILE *file, rtx x, int code)
9878760c
RK
10003{
10004 int i;
a260abc9 10005 HOST_WIDE_INT val;
0ba1b2ff 10006 unsigned HOST_WIDE_INT uval;
9878760c
RK
10007
10008 switch (code)
10009 {
a8b3aeda 10010 case '.':
a85d226b
RK
10011 /* Write out an instruction after the call which may be replaced
10012 with glue code by the loader. This depends on the AIX version. */
10013 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
10014 return;
10015
81eace42
GK
10016 /* %a is output_address. */
10017
9854d9ed
RK
10018 case 'A':
10019 /* If X is a constant integer whose low-order 5 bits are zero,
10020 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 10021 in the AIX assembler where "sri" with a zero shift count
20e26713 10022 writes a trash instruction. */
9854d9ed 10023 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 10024 putc ('l', file);
9854d9ed 10025 else
76229ac8 10026 putc ('r', file);
9854d9ed
RK
10027 return;
10028
10029 case 'b':
e2c953b6
DE
10030 /* If constant, low-order 16 bits of constant, unsigned.
10031 Otherwise, write normally. */
10032 if (INT_P (x))
10033 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
10034 else
10035 print_operand (file, x, 0);
cad12a8d
RK
10036 return;
10037
a260abc9
DE
10038 case 'B':
10039 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
10040 for 64-bit mask direction. */
296b8152 10041 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 10042 return;
a260abc9 10043
81eace42
GK
10044 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
10045 output_operand. */
10046
423c1189
AH
10047 case 'c':
10048 /* X is a CR register. Print the number of the GT bit of the CR. */
10049 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10050 output_operand_lossage ("invalid %%E value");
10051 else
10052 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1);
10053 return;
10054
10055 case 'D':
6b1fedc3 10056 /* Like 'J' but get to the EQ bit. */
423c1189
AH
10057 if (GET_CODE (x) != REG)
10058 abort ();
10059
6b1fedc3
AH
10060 /* Bit 1 is EQ bit. */
10061 i = 4 * (REGNO (x) - CR0_REGNO) + 2;
423c1189
AH
10062
10063 /* If we want bit 31, write a shift count of zero, not 32. */
10064 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10065 return;
10066
9854d9ed 10067 case 'E':
39a10a29 10068 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
10069 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10070 output_operand_lossage ("invalid %%E value");
78fbdbf7 10071 else
39a10a29 10072 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 10073 return;
9854d9ed
RK
10074
10075 case 'f':
10076 /* X is a CR register. Print the shift count needed to move it
10077 to the high-order four bits. */
10078 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10079 output_operand_lossage ("invalid %%f value");
10080 else
9ebbca7d 10081 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
10082 return;
10083
10084 case 'F':
10085 /* Similar, but print the count for the rotate in the opposite
10086 direction. */
10087 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10088 output_operand_lossage ("invalid %%F value");
10089 else
9ebbca7d 10090 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
10091 return;
10092
10093 case 'G':
10094 /* X is a constant integer. If it is negative, print "m",
43aa4e05 10095 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
10096 if (GET_CODE (x) != CONST_INT)
10097 output_operand_lossage ("invalid %%G value");
10098 else if (INTVAL (x) >= 0)
76229ac8 10099 putc ('z', file);
9854d9ed 10100 else
76229ac8 10101 putc ('m', file);
9854d9ed 10102 return;
e2c953b6 10103
9878760c 10104 case 'h':
a4f6c312
SS
10105 /* If constant, output low-order five bits. Otherwise, write
10106 normally. */
9878760c 10107 if (INT_P (x))
5f59ecb7 10108 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
10109 else
10110 print_operand (file, x, 0);
10111 return;
10112
64305719 10113 case 'H':
a4f6c312
SS
10114 /* If constant, output low-order six bits. Otherwise, write
10115 normally. */
64305719 10116 if (INT_P (x))
5f59ecb7 10117 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
10118 else
10119 print_operand (file, x, 0);
10120 return;
10121
9854d9ed
RK
10122 case 'I':
10123 /* Print `i' if this is a constant, else nothing. */
9878760c 10124 if (INT_P (x))
76229ac8 10125 putc ('i', file);
9878760c
RK
10126 return;
10127
9854d9ed
RK
10128 case 'j':
10129 /* Write the bit number in CCR for jump. */
10130 i = ccr_bit (x, 0);
10131 if (i == -1)
10132 output_operand_lossage ("invalid %%j code");
9878760c 10133 else
9854d9ed 10134 fprintf (file, "%d", i);
9878760c
RK
10135 return;
10136
9854d9ed
RK
10137 case 'J':
10138 /* Similar, but add one for shift count in rlinm for scc and pass
10139 scc flag to `ccr_bit'. */
10140 i = ccr_bit (x, 1);
10141 if (i == -1)
10142 output_operand_lossage ("invalid %%J code");
10143 else
a0466a68
RK
10144 /* If we want bit 31, write a shift count of zero, not 32. */
10145 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
10146 return;
10147
9854d9ed
RK
10148 case 'k':
10149 /* X must be a constant. Write the 1's complement of the
10150 constant. */
9878760c 10151 if (! INT_P (x))
9854d9ed 10152 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
10153 else
10154 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
10155 return;
10156
81eace42 10157 case 'K':
9ebbca7d
GK
10158 /* X must be a symbolic constant on ELF. Write an
10159 expression suitable for an 'addi' that adds in the low 16
10160 bits of the MEM. */
10161 if (GET_CODE (x) != CONST)
10162 {
10163 print_operand_address (file, x);
10164 fputs ("@l", file);
10165 }
10166 else
10167 {
10168 if (GET_CODE (XEXP (x, 0)) != PLUS
10169 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
10170 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
10171 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 10172 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
10173 print_operand_address (file, XEXP (XEXP (x, 0), 0));
10174 fputs ("@l", file);
ed8d2920
MM
10175 /* For GNU as, there must be a non-alphanumeric character
10176 between 'l' and the number. The '-' is added by
10177 print_operand() already. */
10178 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
10179 fputs ("+", file);
9ebbca7d
GK
10180 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
10181 }
81eace42
GK
10182 return;
10183
10184 /* %l is output_asm_label. */
9ebbca7d 10185
9854d9ed
RK
10186 case 'L':
10187 /* Write second word of DImode or DFmode reference. Works on register
10188 or non-indexed memory only. */
10189 if (GET_CODE (x) == REG)
fb5c67a7 10190 fputs (reg_names[REGNO (x) + 1], file);
9854d9ed
RK
10191 else if (GET_CODE (x) == MEM)
10192 {
10193 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 10194 we have already done it, we can just use an offset of word. */
9854d9ed
RK
10195 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10196 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
10197 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
10198 UNITS_PER_WORD));
9854d9ed 10199 else
d7624dc0
RK
10200 output_address (XEXP (adjust_address_nv (x, SImode,
10201 UNITS_PER_WORD),
10202 0));
ed8908e7 10203
ba5e43aa 10204 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10205 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10206 reg_names[SMALL_DATA_REG]);
9854d9ed 10207 }
9878760c 10208 return;
f676971a 10209
9878760c
RK
10210 case 'm':
10211 /* MB value for a mask operand. */
b1765bde 10212 if (! mask_operand (x, SImode))
9878760c
RK
10213 output_operand_lossage ("invalid %%m value");
10214
0ba1b2ff 10215 fprintf (file, "%d", extract_MB (x));
9878760c
RK
10216 return;
10217
10218 case 'M':
10219 /* ME value for a mask operand. */
b1765bde 10220 if (! mask_operand (x, SImode))
a260abc9 10221 output_operand_lossage ("invalid %%M value");
9878760c 10222
0ba1b2ff 10223 fprintf (file, "%d", extract_ME (x));
9878760c
RK
10224 return;
10225
81eace42
GK
10226 /* %n outputs the negative of its operand. */
10227
9878760c
RK
10228 case 'N':
10229 /* Write the number of elements in the vector times 4. */
10230 if (GET_CODE (x) != PARALLEL)
10231 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
10232 else
10233 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
10234 return;
10235
10236 case 'O':
10237 /* Similar, but subtract 1 first. */
10238 if (GET_CODE (x) != PARALLEL)
1427100a 10239 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
10240 else
10241 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
10242 return;
10243
9854d9ed
RK
10244 case 'p':
10245 /* X is a CONST_INT that is a power of two. Output the logarithm. */
10246 if (! INT_P (x)
2bfcf297 10247 || INT_LOWPART (x) < 0
9854d9ed
RK
10248 || (i = exact_log2 (INT_LOWPART (x))) < 0)
10249 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
10250 else
10251 fprintf (file, "%d", i);
9854d9ed
RK
10252 return;
10253
9878760c
RK
10254 case 'P':
10255 /* The operand must be an indirect memory reference. The result
8bb418a3 10256 is the register name. */
9878760c
RK
10257 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
10258 || REGNO (XEXP (x, 0)) >= 32)
10259 output_operand_lossage ("invalid %%P value");
e2c953b6 10260 else
fb5c67a7 10261 fputs (reg_names[REGNO (XEXP (x, 0))], file);
9878760c
RK
10262 return;
10263
dfbdccdb
GK
10264 case 'q':
10265 /* This outputs the logical code corresponding to a boolean
10266 expression. The expression may have one or both operands
39a10a29 10267 negated (if one, only the first one). For condition register
c4ad648e
AM
10268 logical operations, it will also treat the negated
10269 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 10270 {
63bc1d05 10271 const char *const *t = 0;
dfbdccdb
GK
10272 const char *s;
10273 enum rtx_code code = GET_CODE (x);
10274 static const char * const tbl[3][3] = {
10275 { "and", "andc", "nor" },
10276 { "or", "orc", "nand" },
10277 { "xor", "eqv", "xor" } };
10278
10279 if (code == AND)
10280 t = tbl[0];
10281 else if (code == IOR)
10282 t = tbl[1];
10283 else if (code == XOR)
10284 t = tbl[2];
10285 else
10286 output_operand_lossage ("invalid %%q value");
10287
10288 if (GET_CODE (XEXP (x, 0)) != NOT)
10289 s = t[0];
10290 else
10291 {
10292 if (GET_CODE (XEXP (x, 1)) == NOT)
10293 s = t[2];
10294 else
10295 s = t[1];
10296 }
f676971a 10297
dfbdccdb
GK
10298 fputs (s, file);
10299 }
10300 return;
10301
2c4a9cff
DE
10302 case 'Q':
10303 if (TARGET_MFCRF)
3b6ce0af 10304 fputc (',', file);
5efb1046 10305 /* FALLTHRU */
2c4a9cff
DE
10306 else
10307 return;
10308
9854d9ed
RK
10309 case 'R':
10310 /* X is a CR register. Print the mask for `mtcrf'. */
10311 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10312 output_operand_lossage ("invalid %%R value");
10313 else
9ebbca7d 10314 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 10315 return;
9854d9ed
RK
10316
10317 case 's':
10318 /* Low 5 bits of 32 - value */
10319 if (! INT_P (x))
10320 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
10321 else
10322 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 10323 return;
9854d9ed 10324
a260abc9 10325 case 'S':
0ba1b2ff 10326 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
10327 CONST_INT 32-bit mask is considered sign-extended so any
10328 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 10329 if (! mask64_operand (x, DImode))
a260abc9
DE
10330 output_operand_lossage ("invalid %%S value");
10331
0ba1b2ff 10332 uval = INT_LOWPART (x);
a260abc9 10333
0ba1b2ff 10334 if (uval & 1) /* Clear Left */
a260abc9 10335 {
f099d360
GK
10336#if HOST_BITS_PER_WIDE_INT > 64
10337 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10338#endif
0ba1b2ff 10339 i = 64;
a260abc9 10340 }
0ba1b2ff 10341 else /* Clear Right */
a260abc9 10342 {
0ba1b2ff 10343 uval = ~uval;
f099d360
GK
10344#if HOST_BITS_PER_WIDE_INT > 64
10345 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10346#endif
0ba1b2ff 10347 i = 63;
a260abc9 10348 }
0ba1b2ff
AM
10349 while (uval != 0)
10350 --i, uval >>= 1;
10351 if (i < 0)
10352 abort ();
10353 fprintf (file, "%d", i);
10354 return;
a260abc9 10355
a3170dc6
AH
10356 case 't':
10357 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
10358 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
10359 abort ();
10360
10361 /* Bit 3 is OV bit. */
10362 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
10363
10364 /* If we want bit 31, write a shift count of zero, not 32. */
10365 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10366 return;
10367
cccf3bdc
DE
10368 case 'T':
10369 /* Print the symbolic name of a branch target register. */
10370 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
10371 && REGNO (x) != COUNT_REGISTER_REGNUM))
10372 output_operand_lossage ("invalid %%T value");
e2c953b6 10373 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
10374 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
10375 else
10376 fputs ("ctr", file);
10377 return;
10378
9854d9ed 10379 case 'u':
802a0058 10380 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
10381 if (! INT_P (x))
10382 output_operand_lossage ("invalid %%u value");
e2c953b6 10383 else
f676971a 10384 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
e2c953b6 10385 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
10386 return;
10387
802a0058
MM
10388 case 'v':
10389 /* High-order 16 bits of constant for use in signed operand. */
10390 if (! INT_P (x))
10391 output_operand_lossage ("invalid %%v value");
e2c953b6 10392 else
134c32f6
DE
10393 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
10394 (INT_LOWPART (x) >> 16) & 0xffff);
10395 return;
802a0058 10396
9854d9ed
RK
10397 case 'U':
10398 /* Print `u' if this has an auto-increment or auto-decrement. */
10399 if (GET_CODE (x) == MEM
10400 && (GET_CODE (XEXP (x, 0)) == PRE_INC
10401 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 10402 putc ('u', file);
9854d9ed 10403 return;
9878760c 10404
e0cd0770
JC
10405 case 'V':
10406 /* Print the trap code for this operand. */
10407 switch (GET_CODE (x))
10408 {
10409 case EQ:
10410 fputs ("eq", file); /* 4 */
10411 break;
10412 case NE:
10413 fputs ("ne", file); /* 24 */
10414 break;
10415 case LT:
10416 fputs ("lt", file); /* 16 */
10417 break;
10418 case LE:
10419 fputs ("le", file); /* 20 */
10420 break;
10421 case GT:
10422 fputs ("gt", file); /* 8 */
10423 break;
10424 case GE:
10425 fputs ("ge", file); /* 12 */
10426 break;
10427 case LTU:
10428 fputs ("llt", file); /* 2 */
10429 break;
10430 case LEU:
10431 fputs ("lle", file); /* 6 */
10432 break;
10433 case GTU:
10434 fputs ("lgt", file); /* 1 */
10435 break;
10436 case GEU:
10437 fputs ("lge", file); /* 5 */
10438 break;
10439 default:
10440 abort ();
10441 }
10442 break;
10443
9854d9ed
RK
10444 case 'w':
10445 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
10446 normally. */
10447 if (INT_P (x))
f676971a 10448 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5f59ecb7 10449 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
10450 else
10451 print_operand (file, x, 0);
9878760c
RK
10452 return;
10453
9854d9ed 10454 case 'W':
e2c953b6 10455 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
10456 val = (GET_CODE (x) == CONST_INT
10457 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
10458
10459 if (val < 0)
10460 i = -1;
9854d9ed 10461 else
e2c953b6
DE
10462 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
10463 if ((val <<= 1) < 0)
10464 break;
10465
10466#if HOST_BITS_PER_WIDE_INT == 32
10467 if (GET_CODE (x) == CONST_INT && i >= 0)
10468 i += 32; /* zero-extend high-part was all 0's */
10469 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
10470 {
10471 val = CONST_DOUBLE_LOW (x);
10472
10473 if (val == 0)
a4f6c312 10474 abort ();
e2c953b6
DE
10475 else if (val < 0)
10476 --i;
10477 else
10478 for ( ; i < 64; i++)
10479 if ((val <<= 1) < 0)
10480 break;
10481 }
10482#endif
10483
10484 fprintf (file, "%d", i + 1);
9854d9ed 10485 return;
9878760c 10486
9854d9ed
RK
10487 case 'X':
10488 if (GET_CODE (x) == MEM
4d588c14 10489 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 10490 putc ('x', file);
9854d9ed 10491 return;
9878760c 10492
9854d9ed
RK
10493 case 'Y':
10494 /* Like 'L', for third word of TImode */
10495 if (GET_CODE (x) == REG)
fb5c67a7 10496 fputs (reg_names[REGNO (x) + 2], file);
9854d9ed 10497 else if (GET_CODE (x) == MEM)
9878760c 10498 {
9854d9ed
RK
10499 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10500 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10501 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 10502 else
d7624dc0 10503 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 10504 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10505 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10506 reg_names[SMALL_DATA_REG]);
9878760c
RK
10507 }
10508 return;
f676971a 10509
9878760c 10510 case 'z':
b4ac57ab
RS
10511 /* X is a SYMBOL_REF. Write out the name preceded by a
10512 period and without any trailing data in brackets. Used for function
4d30c363
MM
10513 names. If we are configured for System V (or the embedded ABI) on
10514 the PowerPC, do not emit the period, since those systems do not use
10515 TOCs and the like. */
9878760c
RK
10516 if (GET_CODE (x) != SYMBOL_REF)
10517 abort ();
10518
c4ad648e
AM
10519 /* Mark the decl as referenced so that cgraph will output the
10520 function. */
9bf6462a 10521 if (SYMBOL_REF_DECL (x))
c4ad648e 10522 mark_decl_referenced (SYMBOL_REF_DECL (x));
9bf6462a 10523
85b776df 10524 /* For macho, check to see if we need a stub. */
f9da97f0
AP
10525 if (TARGET_MACHO)
10526 {
10527 const char *name = XSTR (x, 0);
a031e781 10528#if TARGET_MACHO
3b48085e 10529 if (MACHOPIC_INDIRECT
11abc112
MM
10530 && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10531 name = machopic_indirection_name (x, /*stub_p=*/true);
f9da97f0
AP
10532#endif
10533 assemble_name (file, name);
10534 }
85b776df 10535 else if (!DOT_SYMBOLS)
9739c90c 10536 assemble_name (file, XSTR (x, 0));
85b776df
AM
10537 else
10538 rs6000_output_function_entry (file, XSTR (x, 0));
9878760c
RK
10539 return;
10540
9854d9ed
RK
10541 case 'Z':
10542 /* Like 'L', for last word of TImode. */
10543 if (GET_CODE (x) == REG)
fb5c67a7 10544 fputs (reg_names[REGNO (x) + 3], file);
9854d9ed
RK
10545 else if (GET_CODE (x) == MEM)
10546 {
10547 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10548 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10549 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 10550 else
d7624dc0 10551 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 10552 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10553 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10554 reg_names[SMALL_DATA_REG]);
9854d9ed 10555 }
5c23c401 10556 return;
0ac081f6 10557
a3170dc6 10558 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
10559 case 'y':
10560 {
10561 rtx tmp;
10562
10563 if (GET_CODE (x) != MEM)
10564 abort ();
10565
10566 tmp = XEXP (x, 0);
10567
993f19a8 10568 if (TARGET_E500)
a3170dc6
AH
10569 {
10570 /* Handle [reg]. */
10571 if (GET_CODE (tmp) == REG)
10572 {
10573 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
10574 break;
10575 }
10576 /* Handle [reg+UIMM]. */
10577 else if (GET_CODE (tmp) == PLUS &&
10578 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
10579 {
10580 int x;
10581
10582 if (GET_CODE (XEXP (tmp, 0)) != REG)
10583 abort ();
10584
10585 x = INTVAL (XEXP (tmp, 1));
10586 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
10587 break;
10588 }
10589
10590 /* Fall through. Must be [reg+reg]. */
10591 }
850e8d3d
DN
10592 if (TARGET_ALTIVEC
10593 && GET_CODE (tmp) == AND
10594 && GET_CODE (XEXP (tmp, 1)) == CONST_INT
10595 && INTVAL (XEXP (tmp, 1)) == -16)
10596 tmp = XEXP (tmp, 0);
0ac081f6 10597 if (GET_CODE (tmp) == REG)
c62f2db5 10598 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
10599 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
10600 {
10601 if (REGNO (XEXP (tmp, 0)) == 0)
10602 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
10603 reg_names[ REGNO (XEXP (tmp, 0)) ]);
10604 else
10605 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
10606 reg_names[ REGNO (XEXP (tmp, 1)) ]);
10607 }
10608 else
10609 abort ();
10610 break;
10611 }
f676971a 10612
9878760c
RK
10613 case 0:
10614 if (GET_CODE (x) == REG)
10615 fprintf (file, "%s", reg_names[REGNO (x)]);
10616 else if (GET_CODE (x) == MEM)
10617 {
10618 /* We need to handle PRE_INC and PRE_DEC here, since we need to
10619 know the width from the mode. */
10620 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
10621 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
10622 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10623 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
10624 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
10625 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10626 else
a54d04b7 10627 output_address (XEXP (x, 0));
9878760c
RK
10628 }
10629 else
a54d04b7 10630 output_addr_const (file, x);
a85d226b 10631 return;
9878760c 10632
c4501e62
JJ
10633 case '&':
10634 assemble_name (file, rs6000_get_some_local_dynamic_name ());
10635 return;
10636
9878760c
RK
10637 default:
10638 output_operand_lossage ("invalid %%xn code");
10639 }
10640}
10641\f
10642/* Print the address of an operand. */
10643
10644void
a2369ed3 10645print_operand_address (FILE *file, rtx x)
9878760c
RK
10646{
10647 if (GET_CODE (x) == REG)
4697a36c 10648 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
10649 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
10650 || GET_CODE (x) == LABEL_REF)
9878760c
RK
10651 {
10652 output_addr_const (file, x);
ba5e43aa 10653 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10654 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10655 reg_names[SMALL_DATA_REG]);
9ebbca7d 10656 else if (TARGET_TOC)
a4f6c312 10657 abort ();
9878760c
RK
10658 }
10659 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
10660 {
10661 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
10662 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
10663 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 10664 else
4697a36c
MM
10665 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
10666 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
10667 }
10668 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
10669 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
10670 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
10671#if TARGET_ELF
10672 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
c4ad648e 10673 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
10674 {
10675 output_addr_const (file, XEXP (x, 1));
10676 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10677 }
c859cda6
DJ
10678#endif
10679#if TARGET_MACHO
10680 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
c4ad648e 10681 && CONSTANT_P (XEXP (x, 1)))
c859cda6
DJ
10682 {
10683 fprintf (file, "lo16(");
10684 output_addr_const (file, XEXP (x, 1));
10685 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10686 }
3cb999d8 10687#endif
4d588c14 10688 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 10689 {
2bfcf297 10690 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 10691 {
2bfcf297
DB
10692 rtx contains_minus = XEXP (x, 1);
10693 rtx minus, symref;
10694 const char *name;
f676971a 10695
9ebbca7d 10696 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 10697 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
10698 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
10699 contains_minus = XEXP (contains_minus, 0);
10700
2bfcf297
DB
10701 minus = XEXP (contains_minus, 0);
10702 symref = XEXP (minus, 0);
10703 XEXP (contains_minus, 0) = symref;
10704 if (TARGET_ELF)
10705 {
10706 char *newname;
10707
10708 name = XSTR (symref, 0);
10709 newname = alloca (strlen (name) + sizeof ("@toc"));
10710 strcpy (newname, name);
10711 strcat (newname, "@toc");
10712 XSTR (symref, 0) = newname;
10713 }
10714 output_addr_const (file, XEXP (x, 1));
10715 if (TARGET_ELF)
10716 XSTR (symref, 0) = name;
9ebbca7d
GK
10717 XEXP (contains_minus, 0) = minus;
10718 }
10719 else
10720 output_addr_const (file, XEXP (x, 1));
10721
10722 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
10723 }
9878760c
RK
10724 else
10725 abort ();
10726}
10727\f
88cad84b 10728/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
10729 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
10730 is defined. It also needs to handle DI-mode objects on 64-bit
10731 targets. */
10732
10733static bool
a2369ed3 10734rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
10735{
10736#ifdef RELOCATABLE_NEEDS_FIXUP
10737 /* Special handling for SI values. */
10738 if (size == 4 && aligned_p)
10739 {
a2369ed3 10740 extern int in_toc_section (void);
301d03af 10741 static int recurse = 0;
f676971a 10742
301d03af
RS
10743 /* For -mrelocatable, we mark all addresses that need to be fixed up
10744 in the .fixup section. */
10745 if (TARGET_RELOCATABLE
10746 && !in_toc_section ()
10747 && !in_text_section ()
642af3be 10748 && !in_unlikely_text_section ()
301d03af
RS
10749 && !recurse
10750 && GET_CODE (x) != CONST_INT
10751 && GET_CODE (x) != CONST_DOUBLE
10752 && CONSTANT_P (x))
10753 {
10754 char buf[256];
10755
10756 recurse = 1;
10757 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
10758 fixuplabelno++;
10759 ASM_OUTPUT_LABEL (asm_out_file, buf);
10760 fprintf (asm_out_file, "\t.long\t(");
10761 output_addr_const (asm_out_file, x);
10762 fprintf (asm_out_file, ")@fixup\n");
10763 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
10764 ASM_OUTPUT_ALIGN (asm_out_file, 2);
10765 fprintf (asm_out_file, "\t.long\t");
10766 assemble_name (asm_out_file, buf);
10767 fprintf (asm_out_file, "\n\t.previous\n");
10768 recurse = 0;
10769 return true;
10770 }
10771 /* Remove initial .'s to turn a -mcall-aixdesc function
10772 address into the address of the descriptor, not the function
10773 itself. */
10774 else if (GET_CODE (x) == SYMBOL_REF
10775 && XSTR (x, 0)[0] == '.'
10776 && DEFAULT_ABI == ABI_AIX)
10777 {
10778 const char *name = XSTR (x, 0);
10779 while (*name == '.')
10780 name++;
10781
10782 fprintf (asm_out_file, "\t.long\t%s\n", name);
10783 return true;
10784 }
10785 }
10786#endif /* RELOCATABLE_NEEDS_FIXUP */
10787 return default_assemble_integer (x, size, aligned_p);
10788}
93638d7a
AM
10789
10790#ifdef HAVE_GAS_HIDDEN
10791/* Emit an assembler directive to set symbol visibility for DECL to
10792 VISIBILITY_TYPE. */
10793
5add3202 10794static void
a2369ed3 10795rs6000_assemble_visibility (tree decl, int vis)
93638d7a 10796{
93638d7a
AM
10797 /* Functions need to have their entry point symbol visibility set as
10798 well as their descriptor symbol visibility. */
85b776df
AM
10799 if (DEFAULT_ABI == ABI_AIX
10800 && DOT_SYMBOLS
10801 && TREE_CODE (decl) == FUNCTION_DECL)
93638d7a 10802 {
25fdb4dc 10803 static const char * const visibility_types[] = {
c4ad648e 10804 NULL, "internal", "hidden", "protected"
25fdb4dc
RH
10805 };
10806
10807 const char *name, *type;
93638d7a
AM
10808
10809 name = ((* targetm.strip_name_encoding)
10810 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 10811 type = visibility_types[vis];
93638d7a 10812
25fdb4dc
RH
10813 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
10814 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 10815 }
25fdb4dc
RH
10816 else
10817 default_assemble_visibility (decl, vis);
93638d7a
AM
10818}
10819#endif
301d03af 10820\f
39a10a29 10821enum rtx_code
a2369ed3 10822rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
10823{
10824 /* Reversal of FP compares takes care -- an ordered compare
10825 becomes an unordered compare and vice versa. */
f676971a 10826 if (mode == CCFPmode
bc9ec0e0
GK
10827 && (!flag_finite_math_only
10828 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
10829 || code == UNEQ || code == LTGT))
bab6226b 10830 return reverse_condition_maybe_unordered (code);
39a10a29 10831 else
bab6226b 10832 return reverse_condition (code);
39a10a29
GK
10833}
10834
39a10a29
GK
10835/* Generate a compare for CODE. Return a brand-new rtx that
10836 represents the result of the compare. */
a4f6c312 10837
39a10a29 10838static rtx
a2369ed3 10839rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
10840{
10841 enum machine_mode comp_mode;
10842 rtx compare_result;
10843
10844 if (rs6000_compare_fp_p)
10845 comp_mode = CCFPmode;
10846 else if (code == GTU || code == LTU
c4ad648e 10847 || code == GEU || code == LEU)
39a10a29
GK
10848 comp_mode = CCUNSmode;
10849 else
10850 comp_mode = CCmode;
10851
10852 /* First, the compare. */
10853 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
10854
10855 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
10856 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10857 && rs6000_compare_fp_p)
a3170dc6
AH
10858 {
10859 rtx cmp, or1, or2, or_result, compare_result2;
10860
423c1189
AH
10861 /* Note: The E500 comparison instructions set the GT bit (x +
10862 1), on success. This explains the mess. */
10863
a3170dc6
AH
10864 switch (code)
10865 {
423c1189 10866 case EQ: case UNEQ: case NE: case LTGT:
bc9ec0e0 10867 cmp = flag_finite_math_only
a3170dc6
AH
10868 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
10869 rs6000_compare_op1)
10870 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
10871 rs6000_compare_op1);
10872 break;
423c1189 10873 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
bc9ec0e0 10874 cmp = flag_finite_math_only
a3170dc6
AH
10875 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
10876 rs6000_compare_op1)
10877 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
10878 rs6000_compare_op1);
10879 break;
423c1189 10880 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
bc9ec0e0 10881 cmp = flag_finite_math_only
a3170dc6
AH
10882 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
10883 rs6000_compare_op1)
10884 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
10885 rs6000_compare_op1);
10886 break;
10887 default:
10888 abort ();
10889 }
10890
10891 /* Synthesize LE and GE from LT/GT || EQ. */
10892 if (code == LE || code == GE || code == LEU || code == GEU)
10893 {
a3170dc6
AH
10894 emit_insn (cmp);
10895
10896 switch (code)
10897 {
10898 case LE: code = LT; break;
10899 case GE: code = GT; break;
10900 case LEU: code = LT; break;
10901 case GEU: code = GT; break;
10902 default: abort ();
10903 }
10904
10905 or1 = gen_reg_rtx (SImode);
10906 or2 = gen_reg_rtx (SImode);
10907 or_result = gen_reg_rtx (CCEQmode);
10908 compare_result2 = gen_reg_rtx (CCFPmode);
10909
10910 /* Do the EQ. */
bc9ec0e0 10911 cmp = flag_finite_math_only
a3170dc6
AH
10912 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
10913 rs6000_compare_op1)
10914 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
10915 rs6000_compare_op1);
10916 emit_insn (cmp);
10917
423c1189
AH
10918 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
10919 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
10920
10921 /* OR them together. */
10922 cmp = gen_rtx_SET (VOIDmode, or_result,
10923 gen_rtx_COMPARE (CCEQmode,
10924 gen_rtx_IOR (SImode, or1, or2),
10925 const_true_rtx));
10926 compare_result = or_result;
10927 code = EQ;
10928 }
10929 else
10930 {
a3170dc6 10931 if (code == NE || code == LTGT)
a3170dc6 10932 code = NE;
423c1189
AH
10933 else
10934 code = EQ;
a3170dc6
AH
10935 }
10936
10937 emit_insn (cmp);
10938 }
10939 else
10940 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
10941 gen_rtx_COMPARE (comp_mode,
f676971a 10942 rs6000_compare_op0,
a3170dc6 10943 rs6000_compare_op1)));
f676971a 10944
ca5adc63 10945 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 10946 under flag_finite_math_only we don't bother. */
39a10a29 10947 if (rs6000_compare_fp_p
bc9ec0e0 10948 && ! flag_finite_math_only
993f19a8 10949 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
10950 && (code == LE || code == GE
10951 || code == UNEQ || code == LTGT
10952 || code == UNGT || code == UNLT))
10953 {
10954 enum rtx_code or1, or2;
10955 rtx or1_rtx, or2_rtx, compare2_rtx;
10956 rtx or_result = gen_reg_rtx (CCEQmode);
f676971a 10957
39a10a29
GK
10958 switch (code)
10959 {
10960 case LE: or1 = LT; or2 = EQ; break;
10961 case GE: or1 = GT; or2 = EQ; break;
10962 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
10963 case LTGT: or1 = LT; or2 = GT; break;
10964 case UNGT: or1 = UNORDERED; or2 = GT; break;
10965 case UNLT: or1 = UNORDERED; or2 = LT; break;
10966 default: abort ();
10967 }
10968 validate_condition_mode (or1, comp_mode);
10969 validate_condition_mode (or2, comp_mode);
1c563bed
KH
10970 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
10971 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
10972 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
10973 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
10974 const_true_rtx);
10975 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
10976
10977 compare_result = or_result;
10978 code = EQ;
10979 }
10980
10981 validate_condition_mode (code, GET_MODE (compare_result));
f676971a 10982
1c563bed 10983 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
10984}
10985
10986
10987/* Emit the RTL for an sCOND pattern. */
10988
10989void
a2369ed3 10990rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
10991{
10992 rtx condition_rtx;
10993 enum machine_mode op_mode;
b7053a3f 10994 enum rtx_code cond_code;
39a10a29
GK
10995
10996 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
10997 cond_code = GET_CODE (condition_rtx);
10998
423c1189
AH
10999 if (TARGET_E500 && rs6000_compare_fp_p
11000 && !TARGET_FPRS && TARGET_HARD_FLOAT)
11001 {
11002 rtx t;
11003
11004 PUT_MODE (condition_rtx, SImode);
11005 t = XEXP (condition_rtx, 0);
11006
11007 if (cond_code != NE && cond_code != EQ)
11008 abort ();
11009
11010 if (cond_code == NE)
6b1fedc3 11011 emit_insn (gen_e500_flip_eq_bit (t, t));
423c1189 11012
6b1fedc3 11013 emit_insn (gen_move_from_CR_eq_bit (result, t));
423c1189
AH
11014 return;
11015 }
11016
b7053a3f
GK
11017 if (cond_code == NE
11018 || cond_code == GE || cond_code == LE
11019 || cond_code == GEU || cond_code == LEU
11020 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
11021 {
11022 rtx not_result = gen_reg_rtx (CCEQmode);
11023 rtx not_op, rev_cond_rtx;
11024 enum machine_mode cc_mode;
f676971a 11025
b7053a3f
GK
11026 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
11027
1c563bed 11028 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 11029 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
11030 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
11031 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
11032 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
11033 }
39a10a29
GK
11034
11035 op_mode = GET_MODE (rs6000_compare_op0);
11036 if (op_mode == VOIDmode)
11037 op_mode = GET_MODE (rs6000_compare_op1);
11038
11039 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
11040 {
11041 PUT_MODE (condition_rtx, DImode);
11042 convert_move (result, condition_rtx, 0);
11043 }
11044 else
11045 {
11046 PUT_MODE (condition_rtx, SImode);
11047 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
11048 }
11049}
11050
39a10a29
GK
11051/* Emit a branch of kind CODE to location LOC. */
11052
11053void
a2369ed3 11054rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
11055{
11056 rtx condition_rtx, loc_ref;
11057
11058 condition_rtx = rs6000_generate_compare (code);
11059 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
11060 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
11061 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
11062 loc_ref, pc_rtx)));
11063}
11064
12a4e8c5
GK
11065/* Return the string to output a conditional branch to LABEL, which is
11066 the operand number of the label, or -1 if the branch is really a
f676971a 11067 conditional return.
12a4e8c5
GK
11068
11069 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
11070 condition code register and its mode specifies what kind of
11071 comparison we made.
11072
a0ab749a 11073 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
11074
11075 INSN is the insn. */
11076
11077char *
a2369ed3 11078output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
11079{
11080 static char string[64];
11081 enum rtx_code code = GET_CODE (op);
11082 rtx cc_reg = XEXP (op, 0);
11083 enum machine_mode mode = GET_MODE (cc_reg);
11084 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 11085 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
11086 int really_reversed = reversed ^ need_longbranch;
11087 char *s = string;
11088 const char *ccode;
11089 const char *pred;
11090 rtx note;
11091
39a10a29
GK
11092 validate_condition_mode (code, mode);
11093
11094 /* Work out which way this really branches. We could use
11095 reverse_condition_maybe_unordered here always but this
11096 makes the resulting assembler clearer. */
12a4e8c5 11097 if (really_reversed)
de40e1df
DJ
11098 {
11099 /* Reversal of FP compares takes care -- an ordered compare
11100 becomes an unordered compare and vice versa. */
11101 if (mode == CCFPmode)
11102 code = reverse_condition_maybe_unordered (code);
11103 else
11104 code = reverse_condition (code);
11105 }
12a4e8c5 11106
993f19a8 11107 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
11108 {
11109 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
11110 to the GT bit. */
11111 if (code == EQ)
11112 /* Opposite of GT. */
a3170dc6 11113 code = GT;
423c1189
AH
11114 else if (code == NE)
11115 code = UNLE;
a3170dc6
AH
11116 else
11117 abort ();
11118 }
11119
39a10a29 11120 switch (code)
12a4e8c5
GK
11121 {
11122 /* Not all of these are actually distinct opcodes, but
11123 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
11124 case NE: case LTGT:
11125 ccode = "ne"; break;
11126 case EQ: case UNEQ:
11127 ccode = "eq"; break;
f676971a 11128 case GE: case GEU:
50a0b056 11129 ccode = "ge"; break;
f676971a 11130 case GT: case GTU: case UNGT:
50a0b056 11131 ccode = "gt"; break;
f676971a 11132 case LE: case LEU:
50a0b056 11133 ccode = "le"; break;
f676971a 11134 case LT: case LTU: case UNLT:
50a0b056 11135 ccode = "lt"; break;
12a4e8c5
GK
11136 case UNORDERED: ccode = "un"; break;
11137 case ORDERED: ccode = "nu"; break;
11138 case UNGE: ccode = "nl"; break;
11139 case UNLE: ccode = "ng"; break;
11140 default:
a4f6c312 11141 abort ();
12a4e8c5 11142 }
f676971a
EC
11143
11144 /* Maybe we have a guess as to how likely the branch is.
94a54f47 11145 The old mnemonics don't have a way to specify this information. */
f4857b9b 11146 pred = "";
12a4e8c5
GK
11147 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
11148 if (note != NULL_RTX)
11149 {
11150 /* PROB is the difference from 50%. */
11151 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
11152
11153 /* Only hint for highly probable/improbable branches on newer
11154 cpus as static prediction overrides processor dynamic
11155 prediction. For older cpus we may as well always hint, but
11156 assume not taken for branches that are very close to 50% as a
11157 mispredicted taken branch is more expensive than a
f676971a 11158 mispredicted not-taken branch. */
ec507f2d 11159 if (rs6000_always_hint
f4857b9b
AM
11160 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
11161 {
11162 if (abs (prob) > REG_BR_PROB_BASE / 20
11163 && ((prob > 0) ^ need_longbranch))
c4ad648e 11164 pred = "+";
f4857b9b
AM
11165 else
11166 pred = "-";
11167 }
12a4e8c5 11168 }
12a4e8c5
GK
11169
11170 if (label == NULL)
94a54f47 11171 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 11172 else
94a54f47 11173 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 11174
37c67319 11175 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 11176 Assume they'd only be the first character.... */
37c67319
GK
11177 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
11178 *s++ = '%';
94a54f47 11179 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
11180
11181 if (label != NULL)
11182 {
11183 /* If the branch distance was too far, we may have to use an
11184 unconditional branch to go the distance. */
11185 if (need_longbranch)
44518ddd 11186 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
11187 else
11188 s += sprintf (s, ",%s", label);
11189 }
11190
11191 return string;
11192}
50a0b056 11193
6b1fedc3 11194/* Return the string to flip the EQ bit on a CR. */
423c1189 11195char *
6b1fedc3 11196output_e500_flip_eq_bit (rtx dst, rtx src)
423c1189
AH
11197{
11198 static char string[64];
11199 int a, b;
11200
11201 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
11202 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
11203 abort ();
11204
6b1fedc3
AH
11205 /* EQ bit. */
11206 a = 4 * (REGNO (dst) - CR0_REGNO) + 2;
11207 b = 4 * (REGNO (src) - CR0_REGNO) + 2;
423c1189
AH
11208
11209 sprintf (string, "crnot %d,%d", a, b);
11210 return string;
11211}
11212
21213b4c
DP
11213/* Return insn index for the vector compare instruction for given CODE,
11214 and DEST_MODE, OP_MODE. Return INSN_NOT_AVAILABLE if valid insn is
11215 not available. */
11216
11217static int
11218get_vec_cmp_insn (enum rtx_code code,
11219 enum machine_mode dest_mode,
11220 enum machine_mode op_mode)
11221{
11222 if (!TARGET_ALTIVEC)
11223 return INSN_NOT_AVAILABLE;
11224
11225 switch (code)
11226 {
11227 case EQ:
11228 if (dest_mode == V16QImode && op_mode == V16QImode)
11229 return UNSPEC_VCMPEQUB;
11230 if (dest_mode == V8HImode && op_mode == V8HImode)
11231 return UNSPEC_VCMPEQUH;
11232 if (dest_mode == V4SImode && op_mode == V4SImode)
11233 return UNSPEC_VCMPEQUW;
11234 if (dest_mode == V4SImode && op_mode == V4SFmode)
11235 return UNSPEC_VCMPEQFP;
11236 break;
11237 case GE:
11238 if (dest_mode == V4SImode && op_mode == V4SFmode)
11239 return UNSPEC_VCMPGEFP;
11240 case GT:
11241 if (dest_mode == V16QImode && op_mode == V16QImode)
11242 return UNSPEC_VCMPGTSB;
11243 if (dest_mode == V8HImode && op_mode == V8HImode)
11244 return UNSPEC_VCMPGTSH;
11245 if (dest_mode == V4SImode && op_mode == V4SImode)
11246 return UNSPEC_VCMPGTSW;
11247 if (dest_mode == V4SImode && op_mode == V4SFmode)
11248 return UNSPEC_VCMPGTFP;
11249 break;
11250 case GTU:
11251 if (dest_mode == V16QImode && op_mode == V16QImode)
11252 return UNSPEC_VCMPGTUB;
11253 if (dest_mode == V8HImode && op_mode == V8HImode)
11254 return UNSPEC_VCMPGTUH;
11255 if (dest_mode == V4SImode && op_mode == V4SImode)
11256 return UNSPEC_VCMPGTUW;
11257 break;
11258 default:
11259 break;
11260 }
11261 return INSN_NOT_AVAILABLE;
11262}
11263
11264/* Emit vector compare for operands OP0 and OP1 using code RCODE.
11265 DMODE is expected destination mode. This is a recursive function. */
11266
11267static rtx
11268rs6000_emit_vector_compare (enum rtx_code rcode,
11269 rtx op0, rtx op1,
11270 enum machine_mode dmode)
11271{
11272 int vec_cmp_insn;
11273 rtx mask;
11274 enum machine_mode dest_mode;
11275 enum machine_mode op_mode = GET_MODE (op1);
11276
11277#ifdef ENABLE_CHECKING
11278 if (!TARGET_ALTIVEC)
11279 abort ();
11280
11281 if (GET_MODE (op0) != GET_MODE (op1))
11282 abort ();
11283#endif
11284
11285 /* Floating point vector compare instructions uses destination V4SImode.
11286 Move destination to appropriate mode later. */
11287 if (dmode == V4SFmode)
11288 dest_mode = V4SImode;
11289 else
11290 dest_mode = dmode;
11291
11292 mask = gen_reg_rtx (dest_mode);
11293 vec_cmp_insn = get_vec_cmp_insn (rcode, dest_mode, op_mode);
11294
11295 if (vec_cmp_insn == INSN_NOT_AVAILABLE)
11296 {
11297 bool swap_operands = false;
11298 bool try_again = false;
11299 switch (rcode)
11300 {
11301 case LT:
11302 rcode = GT;
11303 swap_operands = true;
11304 try_again = true;
11305 break;
11306 case LTU:
11307 rcode = GTU;
11308 swap_operands = true;
11309 try_again = true;
11310 break;
11311 case NE:
11312 /* Treat A != B as ~(A==B). */
11313 {
11314 enum insn_code nor_code;
11315 rtx eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1,
11316 dest_mode);
11317
11318 nor_code = one_cmpl_optab->handlers[(int)dest_mode].insn_code;
11319 if (nor_code == CODE_FOR_nothing)
11320 abort ();
11321 emit_insn (GEN_FCN (nor_code) (mask, eq_rtx));
11322
11323 if (dmode != dest_mode)
11324 {
11325 rtx temp = gen_reg_rtx (dest_mode);
11326 convert_move (temp, mask, 0);
11327 return temp;
11328 }
11329 return mask;
11330 }
11331 break;
11332 case GE:
11333 case GEU:
11334 case LE:
11335 case LEU:
11336 /* Try GT/GTU/LT/LTU OR EQ */
11337 {
11338 rtx c_rtx, eq_rtx;
11339 enum insn_code ior_code;
11340 enum rtx_code new_code;
11341
11342 if (rcode == GE)
11343 new_code = GT;
11344 else if (rcode == GEU)
11345 new_code = GTU;
11346 else if (rcode == LE)
11347 new_code = LT;
11348 else if (rcode == LEU)
11349 new_code = LTU;
11350 else
11351 abort ();
11352
11353 c_rtx = rs6000_emit_vector_compare (new_code,
11354 op0, op1, dest_mode);
11355 eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1,
11356 dest_mode);
11357
11358 ior_code = ior_optab->handlers[(int)dest_mode].insn_code;
11359 if (ior_code == CODE_FOR_nothing)
11360 abort ();
11361 emit_insn (GEN_FCN (ior_code) (mask, c_rtx, eq_rtx));
11362 if (dmode != dest_mode)
11363 {
11364 rtx temp = gen_reg_rtx (dest_mode);
11365 convert_move (temp, mask, 0);
11366 return temp;
11367 }
11368 return mask;
11369 }
11370 break;
11371 default:
11372 abort ();
11373 }
11374
11375 if (try_again)
11376 {
11377 vec_cmp_insn = get_vec_cmp_insn (rcode, dest_mode, op_mode);
11378 if (vec_cmp_insn == INSN_NOT_AVAILABLE)
11379 /* You only get two chances. */
11380 abort ();
11381 }
11382
11383 if (swap_operands)
11384 {
11385 rtx tmp;
11386 tmp = op0;
11387 op0 = op1;
11388 op1 = tmp;
11389 }
11390 }
11391
11392 emit_insn (gen_rtx_fmt_ee (SET,
11393 VOIDmode,
11394 mask,
11395 gen_rtx_fmt_Ei (UNSPEC, dest_mode,
11396 gen_rtvec (2, op0, op1),
11397 vec_cmp_insn)));
11398 if (dmode != dest_mode)
11399 {
11400 rtx temp = gen_reg_rtx (dest_mode);
11401 convert_move (temp, mask, 0);
11402 return temp;
11403 }
11404 return mask;
11405}
11406
11407/* Return vector select instruction for MODE. Return INSN_NOT_AVAILABLE, if
11408 valid insn doesn exist for given mode. */
11409
11410static int
11411get_vsel_insn (enum machine_mode mode)
11412{
11413 switch (mode)
11414 {
11415 case V4SImode:
11416 return UNSPEC_VSEL4SI;
11417 break;
11418 case V4SFmode:
11419 return UNSPEC_VSEL4SF;
11420 break;
11421 case V8HImode:
11422 return UNSPEC_VSEL8HI;
11423 break;
11424 case V16QImode:
11425 return UNSPEC_VSEL16QI;
11426 break;
11427 default:
11428 return INSN_NOT_AVAILABLE;
11429 break;
11430 }
11431 return INSN_NOT_AVAILABLE;
11432}
11433
11434/* Emit vector select insn where DEST is destination using
11435 operands OP1, OP2 and MASK. */
11436
11437static void
11438rs6000_emit_vector_select (rtx dest, rtx op1, rtx op2, rtx mask)
11439{
11440 rtx t, temp;
11441 enum machine_mode dest_mode = GET_MODE (dest);
11442 int vsel_insn_index = get_vsel_insn (GET_MODE (dest));
11443
11444 temp = gen_reg_rtx (dest_mode);
11445
11446 t = gen_rtx_fmt_ee (SET, VOIDmode, temp,
11447 gen_rtx_fmt_Ei (UNSPEC, dest_mode,
11448 gen_rtvec (3, op1, op2, mask),
11449 vsel_insn_index));
11450 emit_insn (t);
11451 emit_move_insn (dest, temp);
11452 return;
11453}
11454
11455/* Emit vector conditional expression.
11456 DEST is destination. OP1 and OP2 are two VEC_COND_EXPR operands.
11457 CC_OP0 and CC_OP1 are the two operands for the relation operation COND. */
11458
11459int
11460rs6000_emit_vector_cond_expr (rtx dest, rtx op1, rtx op2,
11461 rtx cond, rtx cc_op0, rtx cc_op1)
11462{
11463 enum machine_mode dest_mode = GET_MODE (dest);
11464 enum rtx_code rcode = GET_CODE (cond);
11465 rtx mask;
11466
11467 if (!TARGET_ALTIVEC)
11468 return 0;
11469
11470 /* Get the vector mask for the given relational operations. */
11471 mask = rs6000_emit_vector_compare (rcode, cc_op0, cc_op1, dest_mode);
11472
11473 rs6000_emit_vector_select (dest, op1, op2, mask);
11474
11475 return 1;
11476}
11477
50a0b056
GK
11478/* Emit a conditional move: move TRUE_COND to DEST if OP of the
11479 operands of the last comparison is nonzero/true, FALSE_COND if it
11480 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 11481
50a0b056 11482int
a2369ed3 11483rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
11484{
11485 enum rtx_code code = GET_CODE (op);
11486 rtx op0 = rs6000_compare_op0;
11487 rtx op1 = rs6000_compare_op1;
11488 REAL_VALUE_TYPE c1;
3148ad6d
DJ
11489 enum machine_mode compare_mode = GET_MODE (op0);
11490 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
11491 rtx temp;
11492
a3c9585f 11493 /* These modes should always match. */
a3170dc6
AH
11494 if (GET_MODE (op1) != compare_mode
11495 /* In the isel case however, we can use a compare immediate, so
11496 op1 may be a small constant. */
11497 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 11498 return 0;
178c3eff 11499 if (GET_MODE (true_cond) != result_mode)
3148ad6d 11500 return 0;
178c3eff 11501 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
11502 return 0;
11503
50a0b056 11504 /* First, work out if the hardware can do this at all, or
a3c9585f 11505 if it's too slow.... */
50a0b056 11506 if (! rs6000_compare_fp_p)
a3170dc6
AH
11507 {
11508 if (TARGET_ISEL)
11509 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
11510 return 0;
11511 }
fef98bf2
AH
11512 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
11513 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
11514 return 0;
50a0b056
GK
11515
11516 /* Eliminate half of the comparisons by switching operands, this
11517 makes the remaining code simpler. */
11518 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 11519 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
11520 {
11521 code = reverse_condition_maybe_unordered (code);
11522 temp = true_cond;
11523 true_cond = false_cond;
11524 false_cond = temp;
11525 }
11526
11527 /* UNEQ and LTGT take four instructions for a comparison with zero,
11528 it'll probably be faster to use a branch here too. */
bc9ec0e0 11529 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056 11530 return 0;
f676971a 11531
50a0b056
GK
11532 if (GET_CODE (op1) == CONST_DOUBLE)
11533 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
f676971a 11534
b6d08ca1 11535 /* We're going to try to implement comparisons by performing
50a0b056
GK
11536 a subtract, then comparing against zero. Unfortunately,
11537 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 11538 know that the operand is finite and the comparison
50a0b056 11539 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 11540 if (HONOR_INFINITIES (compare_mode)
50a0b056 11541 && code != GT && code != UNGE
045572c7 11542 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
11543 /* Constructs of the form (a OP b ? a : b) are safe. */
11544 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
f676971a 11545 || (! rtx_equal_p (op0, true_cond)
50a0b056
GK
11546 && ! rtx_equal_p (op1, true_cond))))
11547 return 0;
11548 /* At this point we know we can use fsel. */
11549
11550 /* Reduce the comparison to a comparison against zero. */
3148ad6d 11551 temp = gen_reg_rtx (compare_mode);
50a0b056 11552 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 11553 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 11554 op0 = temp;
3148ad6d 11555 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
11556
11557 /* If we don't care about NaNs we can reduce some of the comparisons
11558 down to faster ones. */
bc9ec0e0 11559 if (! HONOR_NANS (compare_mode))
50a0b056
GK
11560 switch (code)
11561 {
11562 case GT:
11563 code = LE;
11564 temp = true_cond;
11565 true_cond = false_cond;
11566 false_cond = temp;
11567 break;
11568 case UNGE:
11569 code = GE;
11570 break;
11571 case UNEQ:
11572 code = EQ;
11573 break;
11574 default:
11575 break;
11576 }
11577
11578 /* Now, reduce everything down to a GE. */
11579 switch (code)
11580 {
11581 case GE:
11582 break;
11583
11584 case LE:
3148ad6d
DJ
11585 temp = gen_reg_rtx (compare_mode);
11586 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11587 op0 = temp;
11588 break;
11589
11590 case ORDERED:
3148ad6d
DJ
11591 temp = gen_reg_rtx (compare_mode);
11592 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
11593 op0 = temp;
11594 break;
11595
11596 case EQ:
3148ad6d 11597 temp = gen_reg_rtx (compare_mode);
f676971a 11598 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
11599 gen_rtx_NEG (compare_mode,
11600 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
11601 op0 = temp;
11602 break;
11603
11604 case UNGE:
bc9ec0e0 11605 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 11606 temp = gen_reg_rtx (result_mode);
50a0b056 11607 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 11608 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11609 gen_rtx_GE (VOIDmode,
11610 op0, op1),
11611 true_cond, false_cond)));
bc9ec0e0
GK
11612 false_cond = true_cond;
11613 true_cond = temp;
50a0b056 11614
3148ad6d
DJ
11615 temp = gen_reg_rtx (compare_mode);
11616 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11617 op0 = temp;
11618 break;
11619
11620 case GT:
bc9ec0e0 11621 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 11622 temp = gen_reg_rtx (result_mode);
50a0b056 11623 emit_insn (gen_rtx_SET (VOIDmode, temp,
f676971a 11624 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11625 gen_rtx_GE (VOIDmode,
11626 op0, op1),
11627 true_cond, false_cond)));
bc9ec0e0
GK
11628 true_cond = false_cond;
11629 false_cond = temp;
50a0b056 11630
3148ad6d
DJ
11631 temp = gen_reg_rtx (compare_mode);
11632 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11633 op0 = temp;
11634 break;
11635
11636 default:
11637 abort ();
11638 }
11639
11640 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 11641 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11642 gen_rtx_GE (VOIDmode,
11643 op0, op1),
11644 true_cond, false_cond)));
11645 return 1;
11646}
11647
a3170dc6
AH
11648/* Same as above, but for ints (isel). */
11649
11650static int
a2369ed3 11651rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
11652{
11653 rtx condition_rtx, cr;
11654
11655 /* All isel implementations thus far are 32-bits. */
11656 if (GET_MODE (rs6000_compare_op0) != SImode)
11657 return 0;
11658
11659 /* We still have to do the compare, because isel doesn't do a
11660 compare, it just looks at the CRx bits set by a previous compare
11661 instruction. */
11662 condition_rtx = rs6000_generate_compare (GET_CODE (op));
11663 cr = XEXP (condition_rtx, 0);
11664
11665 if (GET_MODE (cr) == CCmode)
11666 emit_insn (gen_isel_signed (dest, condition_rtx,
11667 true_cond, false_cond, cr));
11668 else
11669 emit_insn (gen_isel_unsigned (dest, condition_rtx,
11670 true_cond, false_cond, cr));
11671
11672 return 1;
11673}
11674
11675const char *
a2369ed3 11676output_isel (rtx *operands)
a3170dc6
AH
11677{
11678 enum rtx_code code;
11679
11680 code = GET_CODE (operands[1]);
11681 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
11682 {
11683 PUT_CODE (operands[1], reverse_condition (code));
11684 return "isel %0,%3,%2,%j1";
11685 }
11686 else
11687 return "isel %0,%2,%3,%j1";
11688}
11689
50a0b056 11690void
a2369ed3 11691rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
11692{
11693 enum machine_mode mode = GET_MODE (op0);
5dc8d536 11694 enum rtx_code c;
50a0b056 11695 rtx target;
5dc8d536
AH
11696
11697 if (code == SMAX || code == SMIN)
11698 c = GE;
11699 else
11700 c = GEU;
11701
50a0b056 11702 if (code == SMAX || code == UMAX)
f676971a 11703 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11704 op0, op1, mode, 0);
11705 else
f676971a 11706 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11707 op1, op0, mode, 0);
11708 if (target == NULL_RTX)
11709 abort ();
11710 if (target != dest)
11711 emit_move_insn (dest, target);
11712}
46c07df8 11713
a9baceb1
GK
11714/* Emit instructions to move SRC to DST. Called by splitters for
11715 multi-register moves. It will emit at most one instruction for
11716 each register that is accessed; that is, it won't emit li/lis pairs
11717 (or equivalent for 64-bit code). One of SRC or DST must be a hard
11718 register. */
46c07df8 11719
46c07df8 11720void
a9baceb1 11721rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 11722{
a9baceb1
GK
11723 /* The register number of the first register being moved. */
11724 int reg;
11725 /* The mode that is to be moved. */
11726 enum machine_mode mode;
11727 /* The mode that the move is being done in, and its size. */
11728 enum machine_mode reg_mode;
11729 int reg_mode_size;
11730 /* The number of registers that will be moved. */
11731 int nregs;
11732
11733 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
11734 mode = GET_MODE (dst);
11735 nregs = HARD_REGNO_NREGS (reg, mode);
11736 if (FP_REGNO_P (reg))
11737 reg_mode = DFmode;
11738 else if (ALTIVEC_REGNO_P (reg))
11739 reg_mode = V16QImode;
11740 else
11741 reg_mode = word_mode;
11742 reg_mode_size = GET_MODE_SIZE (reg_mode);
f676971a 11743
a9baceb1
GK
11744 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
11745 abort ();
f676971a 11746
a9baceb1
GK
11747 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
11748 {
11749 /* Move register range backwards, if we might have destructive
11750 overlap. */
11751 int i;
11752 for (i = nregs - 1; i >= 0; i--)
f676971a 11753 emit_insn (gen_rtx_SET (VOIDmode,
a9baceb1
GK
11754 simplify_gen_subreg (reg_mode, dst, mode,
11755 i * reg_mode_size),
11756 simplify_gen_subreg (reg_mode, src, mode,
11757 i * reg_mode_size)));
11758 }
46c07df8
HP
11759 else
11760 {
a9baceb1
GK
11761 int i;
11762 int j = -1;
11763 bool used_update = false;
46c07df8 11764
c1e55850 11765 if (MEM_P (src) && INT_REGNO_P (reg))
c4ad648e
AM
11766 {
11767 rtx breg;
3a1f863f 11768
a9baceb1
GK
11769 if (GET_CODE (XEXP (src, 0)) == PRE_INC
11770 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
11771 {
11772 rtx delta_rtx;
a9baceb1 11773 breg = XEXP (XEXP (src, 0), 0);
c4ad648e
AM
11774 delta_rtx = (GET_CODE (XEXP (src, 0)) == PRE_INC
11775 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
11776 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src))));
a9baceb1
GK
11777 emit_insn (TARGET_32BIT
11778 ? gen_addsi3 (breg, breg, delta_rtx)
11779 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11780 src = gen_rtx_MEM (mode, breg);
11781 }
c1e55850
GK
11782 else if (! offsettable_memref_p (src))
11783 {
11784 rtx newsrc, basereg;
11785 basereg = gen_rtx_REG (Pmode, reg);
11786 emit_insn (gen_rtx_SET (VOIDmode, basereg, XEXP (src, 0)));
11787 newsrc = gen_rtx_MEM (GET_MODE (src), basereg);
11788 MEM_COPY_ATTRIBUTES (newsrc, src);
11789 src = newsrc;
11790 }
3a1f863f 11791
0423421f
AM
11792 breg = XEXP (src, 0);
11793 if (GET_CODE (breg) == PLUS || GET_CODE (breg) == LO_SUM)
11794 breg = XEXP (breg, 0);
11795
11796 /* If the base register we are using to address memory is
11797 also a destination reg, then change that register last. */
11798 if (REG_P (breg)
11799 && REGNO (breg) >= REGNO (dst)
3a1f863f
DE
11800 && REGNO (breg) < REGNO (dst) + nregs)
11801 j = REGNO (breg) - REGNO (dst);
c4ad648e 11802 }
46c07df8 11803
a9baceb1 11804 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
11805 {
11806 rtx breg;
11807
a9baceb1
GK
11808 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
11809 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
11810 {
11811 rtx delta_rtx;
a9baceb1 11812 breg = XEXP (XEXP (dst, 0), 0);
c4ad648e
AM
11813 delta_rtx = (GET_CODE (XEXP (dst, 0)) == PRE_INC
11814 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
11815 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst))));
3a1f863f
DE
11816
11817 /* We have to update the breg before doing the store.
11818 Use store with update, if available. */
11819
11820 if (TARGET_UPDATE)
11821 {
a9baceb1 11822 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
c4ad648e
AM
11823 emit_insn (TARGET_32BIT
11824 ? (TARGET_POWERPC64
11825 ? gen_movdi_si_update (breg, breg, delta_rtx, nsrc)
11826 : gen_movsi_update (breg, breg, delta_rtx, nsrc))
11827 : gen_movdi_di_update (breg, breg, delta_rtx, nsrc));
a9baceb1 11828 used_update = true;
3a1f863f
DE
11829 }
11830 else
a9baceb1
GK
11831 emit_insn (TARGET_32BIT
11832 ? gen_addsi3 (breg, breg, delta_rtx)
11833 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11834 dst = gen_rtx_MEM (mode, breg);
11835 }
c1e55850 11836 else if (! offsettable_memref_p (dst))
112ccb83 11837 abort ();
3a1f863f
DE
11838 }
11839
46c07df8 11840 for (i = 0; i < nregs; i++)
f676971a 11841 {
3a1f863f
DE
11842 /* Calculate index to next subword. */
11843 ++j;
f676971a 11844 if (j == nregs)
3a1f863f 11845 j = 0;
46c07df8 11846
112cdef5 11847 /* If compiler already emitted move of first word by
a9baceb1 11848 store with update, no need to do anything. */
3a1f863f 11849 if (j == 0 && used_update)
a9baceb1 11850 continue;
f676971a 11851
a9baceb1
GK
11852 emit_insn (gen_rtx_SET (VOIDmode,
11853 simplify_gen_subreg (reg_mode, dst, mode,
11854 j * reg_mode_size),
11855 simplify_gen_subreg (reg_mode, src, mode,
11856 j * reg_mode_size)));
3a1f863f 11857 }
46c07df8
HP
11858 }
11859}
11860
12a4e8c5 11861\f
a4f6c312
SS
11862/* This page contains routines that are used to determine what the
11863 function prologue and epilogue code will do and write them out. */
9878760c 11864
a4f6c312
SS
11865/* Return the first fixed-point register that is required to be
11866 saved. 32 if none. */
9878760c
RK
11867
11868int
863d938c 11869first_reg_to_save (void)
9878760c
RK
11870{
11871 int first_reg;
11872
11873 /* Find lowest numbered live register. */
11874 for (first_reg = 13; first_reg <= 31; first_reg++)
f676971a 11875 if (regs_ever_live[first_reg]
a38d360d 11876 && (! call_used_regs[first_reg]
1db02437 11877 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11878 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
b4db40bf
JJ
11879 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)
11880 || (TARGET_TOC && TARGET_MINIMAL_TOC)))))
9878760c
RK
11881 break;
11882
ee890fe2 11883#if TARGET_MACHO
93638d7a
AM
11884 if (flag_pic
11885 && current_function_uses_pic_offset_table
11886 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 11887 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
11888#endif
11889
9878760c
RK
11890 return first_reg;
11891}
11892
11893/* Similar, for FP regs. */
11894
11895int
863d938c 11896first_fp_reg_to_save (void)
9878760c
RK
11897{
11898 int first_reg;
11899
11900 /* Find lowest numbered live register. */
11901 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
11902 if (regs_ever_live[first_reg])
11903 break;
11904
11905 return first_reg;
11906}
00b960c7
AH
11907
11908/* Similar, for AltiVec regs. */
11909
11910static int
863d938c 11911first_altivec_reg_to_save (void)
00b960c7
AH
11912{
11913 int i;
11914
11915 /* Stack frame remains as is unless we are in AltiVec ABI. */
11916 if (! TARGET_ALTIVEC_ABI)
11917 return LAST_ALTIVEC_REGNO + 1;
11918
11919 /* Find lowest numbered live register. */
11920 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
11921 if (regs_ever_live[i])
11922 break;
11923
11924 return i;
11925}
11926
11927/* Return a 32-bit mask of the AltiVec registers we need to set in
11928 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
11929 the 32-bit word is 0. */
11930
11931static unsigned int
863d938c 11932compute_vrsave_mask (void)
00b960c7
AH
11933{
11934 unsigned int i, mask = 0;
11935
11936 /* First, find out if we use _any_ altivec registers. */
11937 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11938 if (regs_ever_live[i])
11939 mask |= ALTIVEC_REG_BIT (i);
11940
11941 if (mask == 0)
11942 return mask;
11943
00b960c7
AH
11944 /* Next, remove the argument registers from the set. These must
11945 be in the VRSAVE mask set by the caller, so we don't need to add
11946 them in again. More importantly, the mask we compute here is
11947 used to generate CLOBBERs in the set_vrsave insn, and we do not
11948 wish the argument registers to die. */
a6cf80f2 11949 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
11950 mask &= ~ALTIVEC_REG_BIT (i);
11951
11952 /* Similarly, remove the return value from the set. */
11953 {
11954 bool yes = false;
11955 diddle_return_value (is_altivec_return_reg, &yes);
11956 if (yes)
11957 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
11958 }
11959
11960 return mask;
11961}
11962
d62294f5
FJ
11963/* For a very restricted set of circumstances, we can cut down the
11964 size of prologs/epilogs by calling our own save/restore-the-world
11965 routines. */
11966
11967static void
11968compute_save_world_info(rs6000_stack_t *info_ptr)
11969{
11970 info_ptr->world_save_p =
11971 (DEFAULT_ABI == ABI_DARWIN)
11972 && ! (current_function_calls_setjmp && flag_exceptions)
11973 && info_ptr->first_fp_reg_save == FIRST_SAVED_FP_REGNO
11974 && info_ptr->first_gp_reg_save == FIRST_SAVED_GP_REGNO
11975 && info_ptr->first_altivec_reg_save == FIRST_SAVED_ALTIVEC_REGNO
11976 && info_ptr->cr_save_p;
f676971a 11977
d62294f5
FJ
11978 /* This will not work in conjunction with sibcalls. Make sure there
11979 are none. (This check is expensive, but seldom executed.) */
11980 if ( info_ptr->world_save_p )
f676971a 11981 {
d62294f5
FJ
11982 rtx insn;
11983 for ( insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn))
c4ad648e
AM
11984 if ( GET_CODE (insn) == CALL_INSN
11985 && SIBLING_CALL_P (insn))
11986 {
11987 info_ptr->world_save_p = 0;
11988 break;
11989 }
d62294f5 11990 }
f676971a 11991
d62294f5
FJ
11992 if (info_ptr->world_save_p)
11993 {
11994 /* Even if we're not touching VRsave, make sure there's room on the
11995 stack for it, if it looks like we're calling SAVE_WORLD, which
c4ad648e 11996 will attempt to save it. */
d62294f5
FJ
11997 info_ptr->vrsave_size = 4;
11998
11999 /* "Save" the VRsave register too if we're saving the world. */
12000 if (info_ptr->vrsave_mask == 0)
c4ad648e 12001 info_ptr->vrsave_mask = compute_vrsave_mask ();
d62294f5
FJ
12002
12003 /* Because the Darwin register save/restore routines only handle
c4ad648e
AM
12004 F14 .. F31 and V20 .. V31 as per the ABI, perform a consistency
12005 check and abort if there's something worng. */
f676971a 12006 if (info_ptr->first_fp_reg_save < FIRST_SAVED_FP_REGNO
c4ad648e
AM
12007 || info_ptr->first_altivec_reg_save < FIRST_SAVED_ALTIVEC_REGNO)
12008 abort ();
d62294f5 12009 }
f676971a 12010 return;
d62294f5
FJ
12011}
12012
12013
00b960c7 12014static void
a2369ed3 12015is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
12016{
12017 bool *yes = (bool *) xyes;
12018 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
12019 *yes = true;
12020}
12021
4697a36c
MM
12022\f
12023/* Calculate the stack information for the current function. This is
12024 complicated by having two separate calling sequences, the AIX calling
12025 sequence and the V.4 calling sequence.
12026
592696dd 12027 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 12028 32-bit 64-bit
4697a36c 12029 SP----> +---------------------------------------+
a260abc9 12030 | back chain to caller | 0 0
4697a36c 12031 +---------------------------------------+
a260abc9 12032 | saved CR | 4 8 (8-11)
4697a36c 12033 +---------------------------------------+
a260abc9 12034 | saved LR | 8 16
4697a36c 12035 +---------------------------------------+
a260abc9 12036 | reserved for compilers | 12 24
4697a36c 12037 +---------------------------------------+
a260abc9 12038 | reserved for binders | 16 32
4697a36c 12039 +---------------------------------------+
a260abc9 12040 | saved TOC pointer | 20 40
4697a36c 12041 +---------------------------------------+
a260abc9 12042 | Parameter save area (P) | 24 48
4697a36c 12043 +---------------------------------------+
a260abc9 12044 | Alloca space (A) | 24+P etc.
802a0058 12045 +---------------------------------------+
a7df97e6 12046 | Local variable space (L) | 24+P+A
4697a36c 12047 +---------------------------------------+
a7df97e6 12048 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 12049 +---------------------------------------+
00b960c7
AH
12050 | Save area for AltiVec registers (W) | 24+P+A+L+X
12051 +---------------------------------------+
12052 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
12053 +---------------------------------------+
12054 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 12055 +---------------------------------------+
00b960c7
AH
12056 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
12057 +---------------------------------------+
12058 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
12059 +---------------------------------------+
12060 old SP->| back chain to caller's caller |
12061 +---------------------------------------+
12062
5376a30c
KR
12063 The required alignment for AIX configurations is two words (i.e., 8
12064 or 16 bytes).
12065
12066
4697a36c
MM
12067 V.4 stack frames look like:
12068
12069 SP----> +---------------------------------------+
12070 | back chain to caller | 0
12071 +---------------------------------------+
5eb387b8 12072 | caller's saved LR | 4
4697a36c
MM
12073 +---------------------------------------+
12074 | Parameter save area (P) | 8
12075 +---------------------------------------+
a7df97e6 12076 | Alloca space (A) | 8+P
f676971a 12077 +---------------------------------------+
a7df97e6 12078 | Varargs save area (V) | 8+P+A
f676971a 12079 +---------------------------------------+
a7df97e6 12080 | Local variable space (L) | 8+P+A+V
f676971a 12081 +---------------------------------------+
a7df97e6 12082 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 12083 +---------------------------------------+
00b960c7
AH
12084 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
12085 +---------------------------------------+
12086 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
12087 +---------------------------------------+
12088 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
12089 +---------------------------------------+
c4ad648e
AM
12090 | SPE: area for 64-bit GP registers |
12091 +---------------------------------------+
12092 | SPE alignment padding |
12093 +---------------------------------------+
00b960c7 12094 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
f676971a 12095 +---------------------------------------+
00b960c7 12096 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
f676971a 12097 +---------------------------------------+
00b960c7 12098 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
12099 +---------------------------------------+
12100 old SP->| back chain to caller's caller |
12101 +---------------------------------------+
b6c9286a 12102
5376a30c
KR
12103 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
12104 given. (But note below and in sysv4.h that we require only 8 and
12105 may round up the size of our stack frame anyways. The historical
12106 reason is early versions of powerpc-linux which didn't properly
12107 align the stack at program startup. A happy side-effect is that
12108 -mno-eabi libraries can be used with -meabi programs.)
12109
50d440bc 12110 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
12111 the stack alignment requirements may differ. If -mno-eabi is not
12112 given, the required stack alignment is 8 bytes; if -mno-eabi is
12113 given, the required alignment is 16 bytes. (But see V.4 comment
12114 above.) */
4697a36c 12115
61b2fbe7
MM
12116#ifndef ABI_STACK_BOUNDARY
12117#define ABI_STACK_BOUNDARY STACK_BOUNDARY
12118#endif
12119
d1d0c603 12120static rs6000_stack_t *
863d938c 12121rs6000_stack_info (void)
4697a36c
MM
12122{
12123 static rs6000_stack_t info, zero_info;
12124 rs6000_stack_t *info_ptr = &info;
327e5343 12125 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 12126 int ehrd_size;
64045029 12127 int save_align;
44688022 12128 HOST_WIDE_INT non_fixed_size;
4697a36c 12129
a4f6c312 12130 /* Zero all fields portably. */
4697a36c
MM
12131 info = zero_info;
12132
c19de7aa
AH
12133 if (TARGET_SPE)
12134 {
12135 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
12136 if (cfun->machine->insn_chain_scanned_p == 0)
12137 {
12138 cfun->machine->insn_chain_scanned_p = 1;
12139 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
12140 }
c19de7aa
AH
12141 }
12142
a4f6c312 12143 /* Select which calling sequence. */
178274da 12144 info_ptr->abi = DEFAULT_ABI;
9878760c 12145
a4f6c312 12146 /* Calculate which registers need to be saved & save area size. */
4697a36c 12147 info_ptr->first_gp_reg_save = first_reg_to_save ();
f676971a 12148 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 12149 even if it currently looks like we won't. */
2bfcf297 12150 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
12151 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
12152 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
12153 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
12154 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
12155 else
12156 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 12157
a3170dc6
AH
12158 /* For the SPE, we have an additional upper 32-bits on each GPR.
12159 Ideally we should save the entire 64-bits only when the upper
12160 half is used in SIMD instructions. Since we only record
12161 registers live (not the size they are used in), this proves
12162 difficult because we'd have to traverse the instruction chain at
12163 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
12164 so we opt to save the GPRs in 64-bits always if but one register
12165 gets used in 64-bits. Otherwise, all the registers in the frame
12166 get saved in 32-bits.
a3170dc6 12167
c19de7aa 12168 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 12169 traditional GP save area will be empty. */
c19de7aa 12170 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
12171 info_ptr->gp_size = 0;
12172
4697a36c
MM
12173 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
12174 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
12175
00b960c7
AH
12176 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
12177 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
12178 - info_ptr->first_altivec_reg_save);
12179
592696dd 12180 /* Does this function call anything? */
71f123ca
FS
12181 info_ptr->calls_p = (! current_function_is_leaf
12182 || cfun->machine->ra_needs_full_frame);
b6c9286a 12183
a4f6c312 12184 /* Determine if we need to save the link register. */
71f123ca 12185 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
12186 || (DEFAULT_ABI == ABI_AIX
12187 && current_function_profile
12188 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
12189#ifdef TARGET_RELOCATABLE
12190 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
12191#endif
12192 || (info_ptr->first_fp_reg_save != 64
12193 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 12194 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 12195 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
12196 || (DEFAULT_ABI == ABI_DARWIN
12197 && flag_pic
12198 && current_function_uses_pic_offset_table)
4697a36c
MM
12199 || info_ptr->calls_p)
12200 {
12201 info_ptr->lr_save_p = 1;
9ebbca7d 12202 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
12203 }
12204
9ebbca7d 12205 /* Determine if we need to save the condition code registers. */
f676971a 12206 if (regs_ever_live[CR2_REGNO]
9ebbca7d
GK
12207 || regs_ever_live[CR3_REGNO]
12208 || regs_ever_live[CR4_REGNO])
4697a36c
MM
12209 {
12210 info_ptr->cr_save_p = 1;
178274da 12211 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
12212 info_ptr->cr_size = reg_size;
12213 }
12214
83720594
RH
12215 /* If the current function calls __builtin_eh_return, then we need
12216 to allocate stack space for registers that will hold data for
12217 the exception handler. */
12218 if (current_function_calls_eh_return)
12219 {
12220 unsigned int i;
12221 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
12222 continue;
a3170dc6
AH
12223
12224 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
12225 ehrd_size = i * (TARGET_SPE_ABI
12226 && info_ptr->spe_64bit_regs_used != 0
12227 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
12228 }
12229 else
12230 ehrd_size = 0;
12231
592696dd 12232 /* Determine various sizes. */
4697a36c
MM
12233 info_ptr->reg_size = reg_size;
12234 info_ptr->fixed_size = RS6000_SAVE_AREA;
12235 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 12236 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 12237 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 12238 TARGET_ALTIVEC ? 16 : 8);
00b960c7 12239
c19de7aa 12240 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
12241 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
12242 else
12243 info_ptr->spe_gp_size = 0;
12244
4d774ff8
HP
12245 if (TARGET_ALTIVEC_ABI)
12246 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 12247 else
4d774ff8
HP
12248 info_ptr->vrsave_mask = 0;
12249
12250 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
12251 info_ptr->vrsave_size = 4;
12252 else
12253 info_ptr->vrsave_size = 0;
b6c9286a 12254
d62294f5
FJ
12255 compute_save_world_info (info_ptr);
12256
592696dd 12257 /* Calculate the offsets. */
178274da 12258 switch (DEFAULT_ABI)
4697a36c 12259 {
b6c9286a 12260 case ABI_NONE:
24d304eb 12261 default:
b6c9286a
MM
12262 abort ();
12263
12264 case ABI_AIX:
ee890fe2 12265 case ABI_DARWIN:
b6c9286a
MM
12266 info_ptr->fp_save_offset = - info_ptr->fp_size;
12267 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
12268
12269 if (TARGET_ALTIVEC_ABI)
12270 {
12271 info_ptr->vrsave_save_offset
12272 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
12273
12274 /* Align stack so vector save area is on a quadword boundary. */
12275 if (info_ptr->altivec_size != 0)
12276 info_ptr->altivec_padding_size
12277 = 16 - (-info_ptr->vrsave_save_offset % 16);
12278 else
12279 info_ptr->altivec_padding_size = 0;
12280
12281 info_ptr->altivec_save_offset
12282 = info_ptr->vrsave_save_offset
12283 - info_ptr->altivec_padding_size
12284 - info_ptr->altivec_size;
12285
12286 /* Adjust for AltiVec case. */
12287 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
12288 }
12289 else
12290 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
12291 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
12292 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
12293 break;
12294
12295 case ABI_V4:
b6c9286a
MM
12296 info_ptr->fp_save_offset = - info_ptr->fp_size;
12297 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 12298 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 12299
c19de7aa 12300 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
c4ad648e
AM
12301 {
12302 /* Align stack so SPE GPR save area is aligned on a
12303 double-word boundary. */
12304 if (info_ptr->spe_gp_size != 0)
12305 info_ptr->spe_padding_size
12306 = 8 - (-info_ptr->cr_save_offset % 8);
12307 else
12308 info_ptr->spe_padding_size = 0;
12309
12310 info_ptr->spe_gp_save_offset
12311 = info_ptr->cr_save_offset
12312 - info_ptr->spe_padding_size
12313 - info_ptr->spe_gp_size;
12314
12315 /* Adjust for SPE case. */
12316 info_ptr->toc_save_offset
12317 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
12318 }
a3170dc6 12319 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
12320 {
12321 info_ptr->vrsave_save_offset
12322 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
12323
12324 /* Align stack so vector save area is on a quadword boundary. */
12325 if (info_ptr->altivec_size != 0)
12326 info_ptr->altivec_padding_size
12327 = 16 - (-info_ptr->vrsave_save_offset % 16);
12328 else
12329 info_ptr->altivec_padding_size = 0;
12330
12331 info_ptr->altivec_save_offset
12332 = info_ptr->vrsave_save_offset
12333 - info_ptr->altivec_padding_size
12334 - info_ptr->altivec_size;
12335
12336 /* Adjust for AltiVec case. */
12337 info_ptr->toc_save_offset
12338 = info_ptr->altivec_save_offset - info_ptr->toc_size;
12339 }
12340 else
12341 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 12342 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
12343 info_ptr->lr_save_offset = reg_size;
12344 break;
4697a36c
MM
12345 }
12346
64045029 12347 save_align = (TARGET_ALTIVEC_ABI || DEFAULT_ABI == ABI_DARWIN) ? 16 : 8;
00b960c7
AH
12348 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
12349 + info_ptr->gp_size
12350 + info_ptr->altivec_size
12351 + info_ptr->altivec_padding_size
a3170dc6
AH
12352 + info_ptr->spe_gp_size
12353 + info_ptr->spe_padding_size
00b960c7
AH
12354 + ehrd_size
12355 + info_ptr->cr_size
12356 + info_ptr->lr_size
12357 + info_ptr->vrsave_size
12358 + info_ptr->toc_size,
64045029 12359 save_align);
00b960c7 12360
44688022 12361 non_fixed_size = (info_ptr->vars_size
ff381587 12362 + info_ptr->parm_size
ff381587 12363 + info_ptr->save_size
44688022 12364 + info_ptr->varargs_size);
ff381587 12365
44688022
AM
12366 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
12367 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
12368
12369 /* Determine if we need to allocate any stack frame:
12370
a4f6c312
SS
12371 For AIX we need to push the stack if a frame pointer is needed
12372 (because the stack might be dynamically adjusted), if we are
12373 debugging, if we make calls, or if the sum of fp_save, gp_save,
12374 and local variables are more than the space needed to save all
12375 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
12376 + 18*8 = 288 (GPR13 reserved).
ff381587 12377
a4f6c312
SS
12378 For V.4 we don't have the stack cushion that AIX uses, but assume
12379 that the debugger can handle stackless frames. */
ff381587
MM
12380
12381 if (info_ptr->calls_p)
12382 info_ptr->push_p = 1;
12383
178274da 12384 else if (DEFAULT_ABI == ABI_V4)
44688022 12385 info_ptr->push_p = non_fixed_size != 0;
ff381587 12386
178274da
AM
12387 else if (frame_pointer_needed)
12388 info_ptr->push_p = 1;
12389
12390 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
12391 info_ptr->push_p = 1;
12392
ff381587 12393 else
44688022 12394 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 12395
a4f6c312 12396 /* Zero offsets if we're not saving those registers. */
8dda1a21 12397 if (info_ptr->fp_size == 0)
4697a36c
MM
12398 info_ptr->fp_save_offset = 0;
12399
8dda1a21 12400 if (info_ptr->gp_size == 0)
4697a36c
MM
12401 info_ptr->gp_save_offset = 0;
12402
00b960c7
AH
12403 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
12404 info_ptr->altivec_save_offset = 0;
12405
12406 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
12407 info_ptr->vrsave_save_offset = 0;
12408
c19de7aa
AH
12409 if (! TARGET_SPE_ABI
12410 || info_ptr->spe_64bit_regs_used == 0
12411 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
12412 info_ptr->spe_gp_save_offset = 0;
12413
c81fc13e 12414 if (! info_ptr->lr_save_p)
4697a36c
MM
12415 info_ptr->lr_save_offset = 0;
12416
c81fc13e 12417 if (! info_ptr->cr_save_p)
4697a36c
MM
12418 info_ptr->cr_save_offset = 0;
12419
c81fc13e 12420 if (! info_ptr->toc_save_p)
b6c9286a
MM
12421 info_ptr->toc_save_offset = 0;
12422
4697a36c
MM
12423 return info_ptr;
12424}
12425
c19de7aa
AH
12426/* Return true if the current function uses any GPRs in 64-bit SIMD
12427 mode. */
12428
12429static bool
863d938c 12430spe_func_has_64bit_regs_p (void)
c19de7aa
AH
12431{
12432 rtx insns, insn;
12433
12434 /* Functions that save and restore all the call-saved registers will
12435 need to save/restore the registers in 64-bits. */
12436 if (current_function_calls_eh_return
12437 || current_function_calls_setjmp
12438 || current_function_has_nonlocal_goto)
12439 return true;
12440
12441 insns = get_insns ();
12442
12443 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
12444 {
12445 if (INSN_P (insn))
12446 {
12447 rtx i;
12448
12449 i = PATTERN (insn);
12450 if (GET_CODE (i) == SET
12451 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
12452 return true;
12453 }
12454 }
12455
12456 return false;
12457}
12458
d1d0c603 12459static void
a2369ed3 12460debug_stack_info (rs6000_stack_t *info)
9878760c 12461{
d330fd93 12462 const char *abi_string;
24d304eb 12463
c81fc13e 12464 if (! info)
4697a36c
MM
12465 info = rs6000_stack_info ();
12466
12467 fprintf (stderr, "\nStack information for function %s:\n",
12468 ((current_function_decl && DECL_NAME (current_function_decl))
12469 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
12470 : "<unknown>"));
12471
24d304eb
RK
12472 switch (info->abi)
12473 {
b6c9286a
MM
12474 default: abi_string = "Unknown"; break;
12475 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 12476 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 12477 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 12478 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
12479 }
12480
12481 fprintf (stderr, "\tABI = %5s\n", abi_string);
12482
00b960c7
AH
12483 if (TARGET_ALTIVEC_ABI)
12484 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
12485
a3170dc6
AH
12486 if (TARGET_SPE_ABI)
12487 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
12488
4697a36c
MM
12489 if (info->first_gp_reg_save != 32)
12490 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
12491
12492 if (info->first_fp_reg_save != 64)
12493 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 12494
00b960c7
AH
12495 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
12496 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
12497 info->first_altivec_reg_save);
12498
4697a36c
MM
12499 if (info->lr_save_p)
12500 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 12501
4697a36c
MM
12502 if (info->cr_save_p)
12503 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
12504
b6c9286a
MM
12505 if (info->toc_save_p)
12506 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
12507
00b960c7
AH
12508 if (info->vrsave_mask)
12509 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
12510
4697a36c
MM
12511 if (info->push_p)
12512 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
12513
12514 if (info->calls_p)
12515 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
12516
4697a36c
MM
12517 if (info->gp_save_offset)
12518 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
12519
12520 if (info->fp_save_offset)
12521 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
12522
00b960c7
AH
12523 if (info->altivec_save_offset)
12524 fprintf (stderr, "\taltivec_save_offset = %5d\n",
12525 info->altivec_save_offset);
12526
a3170dc6
AH
12527 if (info->spe_gp_save_offset)
12528 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
12529 info->spe_gp_save_offset);
12530
00b960c7
AH
12531 if (info->vrsave_save_offset)
12532 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
12533 info->vrsave_save_offset);
12534
4697a36c
MM
12535 if (info->lr_save_offset)
12536 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
12537
12538 if (info->cr_save_offset)
12539 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
12540
b6c9286a
MM
12541 if (info->toc_save_offset)
12542 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
12543
4697a36c
MM
12544 if (info->varargs_save_offset)
12545 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
12546
12547 if (info->total_size)
d1d0c603
JJ
12548 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12549 info->total_size);
4697a36c
MM
12550
12551 if (info->varargs_size)
12552 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
12553
12554 if (info->vars_size)
d1d0c603
JJ
12555 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12556 info->vars_size);
4697a36c
MM
12557
12558 if (info->parm_size)
12559 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
12560
12561 if (info->fixed_size)
12562 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
12563
12564 if (info->gp_size)
12565 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
12566
a3170dc6
AH
12567 if (info->spe_gp_size)
12568 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
12569
4697a36c
MM
12570 if (info->fp_size)
12571 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
12572
00b960c7
AH
12573 if (info->altivec_size)
12574 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
12575
12576 if (info->vrsave_size)
12577 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
12578
12579 if (info->altivec_padding_size)
12580 fprintf (stderr, "\taltivec_padding_size= %5d\n",
12581 info->altivec_padding_size);
12582
a3170dc6
AH
12583 if (info->spe_padding_size)
12584 fprintf (stderr, "\tspe_padding_size = %5d\n",
12585 info->spe_padding_size);
12586
a4f6c312 12587 if (info->lr_size)
ed947a96 12588 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 12589
4697a36c
MM
12590 if (info->cr_size)
12591 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
12592
a4f6c312 12593 if (info->toc_size)
b6c9286a
MM
12594 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
12595
4697a36c
MM
12596 if (info->save_size)
12597 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
12598
12599 if (info->reg_size != 4)
12600 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
12601
12602 fprintf (stderr, "\n");
9878760c 12603}
71f123ca
FS
12604
12605rtx
a2369ed3 12606rs6000_return_addr (int count, rtx frame)
71f123ca 12607{
a4f6c312
SS
12608 /* Currently we don't optimize very well between prolog and body
12609 code and for PIC code the code can be actually quite bad, so
12610 don't try to be too clever here. */
f1384257 12611 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
12612 {
12613 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
12614
12615 return
12616 gen_rtx_MEM
12617 (Pmode,
12618 memory_address
12619 (Pmode,
12620 plus_constant (copy_to_reg
12621 (gen_rtx_MEM (Pmode,
12622 memory_address (Pmode, frame))),
12623 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
12624 }
12625
8c29550d 12626 cfun->machine->ra_need_lr = 1;
9e2f7ec7 12627 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
12628}
12629
5e1bf043
DJ
12630/* Say whether a function is a candidate for sibcall handling or not.
12631 We do not allow indirect calls to be optimized into sibling calls.
12632 Also, we can't do it if there are any vector parameters; there's
12633 nowhere to put the VRsave code so it works; note that functions with
12634 vector parameters are required to have a prototype, so the argument
12635 type info must be available here. (The tail recursion case can work
12636 with vector parameters, but there's no way to distinguish here.) */
4977bab6 12637static bool
a2369ed3 12638rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
12639{
12640 tree type;
4977bab6 12641 if (decl)
5e1bf043
DJ
12642 {
12643 if (TARGET_ALTIVEC_VRSAVE)
c4ad648e 12644 {
4977bab6 12645 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
12646 type; type = TREE_CHAIN (type))
12647 {
c15b529f 12648 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 12649 return false;
5e1bf043 12650 }
c4ad648e 12651 }
5e1bf043 12652 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 12653 || (*targetm.binds_local_p) (decl))
2bcc50d0 12654 {
4977bab6 12655 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
12656
12657 if (!lookup_attribute ("longcall", attr_list)
12658 || lookup_attribute ("shortcall", attr_list))
4977bab6 12659 return true;
2bcc50d0 12660 }
5e1bf043 12661 }
4977bab6 12662 return false;
5e1bf043
DJ
12663}
12664
71f123ca 12665static int
863d938c 12666rs6000_ra_ever_killed (void)
71f123ca
FS
12667{
12668 rtx top;
5e1bf043
DJ
12669 rtx reg;
12670 rtx insn;
71f123ca 12671
dd292d0a 12672 if (current_function_is_thunk)
71f123ca 12673 return 0;
eb0424da 12674
36f7e964
AH
12675 /* regs_ever_live has LR marked as used if any sibcalls are present,
12676 but this should not force saving and restoring in the
12677 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 12678 clobbers LR, so that is inappropriate. */
36f7e964 12679
5e1bf043
DJ
12680 /* Also, the prologue can generate a store into LR that
12681 doesn't really count, like this:
36f7e964 12682
5e1bf043
DJ
12683 move LR->R0
12684 bcl to set PIC register
12685 move LR->R31
12686 move R0->LR
36f7e964
AH
12687
12688 When we're called from the epilogue, we need to avoid counting
12689 this as a store. */
f676971a 12690
71f123ca
FS
12691 push_topmost_sequence ();
12692 top = get_insns ();
12693 pop_topmost_sequence ();
5e1bf043 12694 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 12695
5e1bf043
DJ
12696 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
12697 {
12698 if (INSN_P (insn))
12699 {
12700 if (FIND_REG_INC_NOTE (insn, reg))
12701 return 1;
f676971a 12702 else if (GET_CODE (insn) == CALL_INSN
c15b529f 12703 && !SIBLING_CALL_P (insn))
5e1bf043 12704 return 1;
36f7e964
AH
12705 else if (set_of (reg, insn) != NULL_RTX
12706 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
12707 return 1;
12708 }
12709 }
12710 return 0;
71f123ca 12711}
4697a36c 12712\f
8cd8f856
GK
12713/* Add a REG_MAYBE_DEAD note to the insn. */
12714static void
a2369ed3 12715rs6000_maybe_dead (rtx insn)
8cd8f856
GK
12716{
12717 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
12718 const0_rtx,
12719 REG_NOTES (insn));
12720}
12721
9ebbca7d 12722/* Emit instructions needed to load the TOC register.
c7ca610e 12723 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 12724 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
12725
12726void
a2369ed3 12727rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 12728{
027fbf43 12729 rtx dest, insn;
1db02437 12730 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 12731
20b71b17
AM
12732 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
12733 {
12734 rtx temp = (fromprolog
12735 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12736 : gen_reg_rtx (Pmode));
027fbf43
JJ
12737 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
12738 if (fromprolog)
12739 rs6000_maybe_dead (insn);
12740 insn = emit_move_insn (dest, temp);
12741 if (fromprolog)
12742 rs6000_maybe_dead (insn);
20b71b17
AM
12743 }
12744 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
12745 {
12746 char buf[30];
12747 rtx tempLR = (fromprolog
12748 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12749 : gen_reg_rtx (Pmode));
12750 rtx temp0 = (fromprolog
12751 ? gen_rtx_REG (Pmode, 0)
12752 : gen_reg_rtx (Pmode));
12753 rtx symF;
12754
12755 /* possibly create the toc section */
12756 if (! toc_initialized)
38c1f2d7 12757 {
20b71b17
AM
12758 toc_section ();
12759 function_section (current_function_decl);
38c1f2d7 12760 }
9ebbca7d 12761
20b71b17
AM
12762 if (fromprolog)
12763 {
12764 rtx symL;
38c1f2d7 12765
20b71b17
AM
12766 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
12767 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 12768
20b71b17
AM
12769 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
12770 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12771
12772 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
12773 symF)));
12774 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
12775 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
12776 symL,
12777 symF)));
9ebbca7d
GK
12778 }
12779 else
20b71b17
AM
12780 {
12781 rtx tocsym;
12782 static int reload_toc_labelno = 0;
12783
12784 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
12785
12786 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
12787 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12788
027fbf43
JJ
12789 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
12790 emit_move_insn (dest, tempLR);
12791 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 12792 }
027fbf43
JJ
12793 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
12794 if (fromprolog)
12795 rs6000_maybe_dead (insn);
9ebbca7d 12796 }
20b71b17
AM
12797 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
12798 {
12799 /* This is for AIX code running in non-PIC ELF32. */
12800 char buf[30];
12801 rtx realsym;
12802 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
12803 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12804
027fbf43
JJ
12805 insn = emit_insn (gen_elf_high (dest, realsym));
12806 if (fromprolog)
12807 rs6000_maybe_dead (insn);
12808 insn = emit_insn (gen_elf_low (dest, dest, realsym));
12809 if (fromprolog)
12810 rs6000_maybe_dead (insn);
20b71b17
AM
12811 }
12812 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
12813 {
12814 if (TARGET_32BIT)
027fbf43 12815 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 12816 else
027fbf43
JJ
12817 insn = emit_insn (gen_load_toc_aix_di (dest));
12818 if (fromprolog)
12819 rs6000_maybe_dead (insn);
9ebbca7d 12820 }
20b71b17
AM
12821 else
12822 abort ();
9ebbca7d
GK
12823}
12824
d1d0c603
JJ
12825/* Emit instructions to restore the link register after determining where
12826 its value has been stored. */
12827
12828void
12829rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
12830{
12831 rs6000_stack_t *info = rs6000_stack_info ();
12832 rtx operands[2];
12833
12834 operands[0] = source;
12835 operands[1] = scratch;
12836
12837 if (info->lr_save_p)
12838 {
12839 rtx frame_rtx = stack_pointer_rtx;
12840 HOST_WIDE_INT sp_offset = 0;
12841 rtx tmp;
12842
12843 if (frame_pointer_needed
12844 || current_function_calls_alloca
12845 || info->total_size > 32767)
12846 {
12847 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
12848 frame_rtx = operands[1];
12849 }
12850 else if (info->push_p)
12851 sp_offset = info->total_size;
12852
12853 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
12854 tmp = gen_rtx_MEM (Pmode, tmp);
12855 emit_move_insn (tmp, operands[0]);
12856 }
12857 else
12858 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
12859}
12860
f103e34d
GK
12861static GTY(()) int set = -1;
12862
f676971a 12863int
863d938c 12864get_TOC_alias_set (void)
9ebbca7d 12865{
f103e34d
GK
12866 if (set == -1)
12867 set = new_alias_set ();
12868 return set;
f676971a 12869}
9ebbca7d 12870
c1207243 12871/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
12872 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
12873 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 12874#if TARGET_ELF
3c9eb5f4 12875static int
f676971a 12876uses_TOC (void)
9ebbca7d 12877{
c4501e62 12878 rtx insn;
38c1f2d7 12879
c4501e62
JJ
12880 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
12881 if (INSN_P (insn))
12882 {
12883 rtx pat = PATTERN (insn);
12884 int i;
9ebbca7d 12885
f676971a 12886 if (GET_CODE (pat) == PARALLEL)
c4501e62
JJ
12887 for (i = 0; i < XVECLEN (pat, 0); i++)
12888 {
12889 rtx sub = XVECEXP (pat, 0, i);
12890 if (GET_CODE (sub) == USE)
12891 {
12892 sub = XEXP (sub, 0);
12893 if (GET_CODE (sub) == UNSPEC
12894 && XINT (sub, 1) == UNSPEC_TOC)
12895 return 1;
12896 }
12897 }
12898 }
12899 return 0;
9ebbca7d 12900}
c954844a 12901#endif
38c1f2d7 12902
9ebbca7d 12903rtx
f676971a 12904create_TOC_reference (rtx symbol)
9ebbca7d 12905{
f676971a 12906 return gen_rtx_PLUS (Pmode,
a8a05998 12907 gen_rtx_REG (Pmode, TOC_REGISTER),
f676971a
EC
12908 gen_rtx_CONST (Pmode,
12909 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 12910 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 12911}
38c1f2d7 12912
fc4767bb
JJ
12913/* If _Unwind_* has been called from within the same module,
12914 toc register is not guaranteed to be saved to 40(1) on function
12915 entry. Save it there in that case. */
c7ca610e 12916
9ebbca7d 12917void
863d938c 12918rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
12919{
12920 rtx mem;
12921 rtx stack_top = gen_reg_rtx (Pmode);
12922 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
12923 rtx opcode = gen_reg_rtx (SImode);
12924 rtx tocompare = gen_reg_rtx (SImode);
12925 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
12926
12927 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
12928 emit_move_insn (stack_top, mem);
12929
fc4767bb
JJ
12930 mem = gen_rtx_MEM (Pmode,
12931 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
12932 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
12933 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
12934 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
12935 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 12936 : 0xE8410028, SImode));
9ebbca7d 12937
fc4767bb 12938 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 12939 SImode, NULL_RTX, NULL_RTX,
fc4767bb 12940 no_toc_save_needed);
9ebbca7d 12941
fc4767bb
JJ
12942 mem = gen_rtx_MEM (Pmode,
12943 gen_rtx_PLUS (Pmode, stack_top,
12944 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
12945 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
12946 emit_label (no_toc_save_needed);
9ebbca7d 12947}
38c1f2d7 12948\f
ba4828e0
RK
12949/* This ties together stack memory (MEM with an alias set of
12950 rs6000_sr_alias_set) and the change to the stack pointer. */
12951
9ebbca7d 12952static void
863d938c 12953rs6000_emit_stack_tie (void)
9ebbca7d 12954{
ba4828e0
RK
12955 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
12956
12957 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12958 emit_insn (gen_stack_tie (mem));
12959}
38c1f2d7 12960
9ebbca7d
GK
12961/* Emit the correct code for allocating stack space, as insns.
12962 If COPY_R12, make sure a copy of the old frame is left in r12.
12963 The generated code may use hard register 0 as a temporary. */
12964
12965static void
a2369ed3 12966rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 12967{
9ebbca7d
GK
12968 rtx insn;
12969 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12970 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
12971 rtx todec = GEN_INT (-size);
a157febd
GK
12972
12973 if (current_function_limit_stack)
12974 {
12975 if (REG_P (stack_limit_rtx)
f676971a 12976 && REGNO (stack_limit_rtx) > 1
a157febd
GK
12977 && REGNO (stack_limit_rtx) <= 31)
12978 {
5b71a4e7 12979 emit_insn (TARGET_32BIT
9ebbca7d
GK
12980 ? gen_addsi3 (tmp_reg,
12981 stack_limit_rtx,
12982 GEN_INT (size))
12983 : gen_adddi3 (tmp_reg,
12984 stack_limit_rtx,
12985 GEN_INT (size)));
5b71a4e7 12986
9ebbca7d
GK
12987 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
12988 const0_rtx));
a157febd
GK
12989 }
12990 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 12991 && TARGET_32BIT
f607bc57 12992 && DEFAULT_ABI == ABI_V4)
a157febd 12993 {
9ebbca7d 12994 rtx toload = gen_rtx_CONST (VOIDmode,
f676971a
EC
12995 gen_rtx_PLUS (Pmode,
12996 stack_limit_rtx,
9ebbca7d 12997 GEN_INT (size)));
5b71a4e7 12998
9ebbca7d
GK
12999 emit_insn (gen_elf_high (tmp_reg, toload));
13000 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
13001 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
13002 const0_rtx));
a157febd
GK
13003 }
13004 else
13005 warning ("stack limit expression is not supported");
13006 }
13007
9ebbca7d
GK
13008 if (copy_r12 || ! TARGET_UPDATE)
13009 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
13010
38c1f2d7
MM
13011 if (TARGET_UPDATE)
13012 {
9ebbca7d 13013 if (size > 32767)
38c1f2d7 13014 {
9ebbca7d
GK
13015 /* Need a note here so that try_split doesn't get confused. */
13016 if (get_last_insn() == NULL_RTX)
2e040219 13017 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
13018 insn = emit_move_insn (tmp_reg, todec);
13019 try_split (PATTERN (insn), insn, 0);
13020 todec = tmp_reg;
38c1f2d7 13021 }
5b71a4e7
DE
13022
13023 insn = emit_insn (TARGET_32BIT
13024 ? gen_movsi_update (stack_reg, stack_reg,
13025 todec, stack_reg)
c4ad648e 13026 : gen_movdi_di_update (stack_reg, stack_reg,
9ebbca7d 13027 todec, stack_reg));
38c1f2d7
MM
13028 }
13029 else
13030 {
5b71a4e7
DE
13031 insn = emit_insn (TARGET_32BIT
13032 ? gen_addsi3 (stack_reg, stack_reg, todec)
13033 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
13034 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
13035 gen_rtx_REG (Pmode, 12));
13036 }
f676971a 13037
9ebbca7d 13038 RTX_FRAME_RELATED_P (insn) = 1;
f676971a 13039 REG_NOTES (insn) =
9ebbca7d 13040 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
f676971a 13041 gen_rtx_SET (VOIDmode, stack_reg,
9ebbca7d
GK
13042 gen_rtx_PLUS (Pmode, stack_reg,
13043 GEN_INT (-size))),
13044 REG_NOTES (insn));
13045}
13046
a4f6c312
SS
13047/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
13048 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
13049 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
13050 deduce these equivalences by itself so it wasn't necessary to hold
13051 its hand so much. */
9ebbca7d
GK
13052
13053static void
f676971a 13054rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
a2369ed3 13055 rtx reg2, rtx rreg)
9ebbca7d
GK
13056{
13057 rtx real, temp;
13058
e56c4463
JL
13059 /* copy_rtx will not make unique copies of registers, so we need to
13060 ensure we don't have unwanted sharing here. */
13061 if (reg == reg2)
13062 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
13063
13064 if (reg == rreg)
13065 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
13066
9ebbca7d
GK
13067 real = copy_rtx (PATTERN (insn));
13068
89e7058f
AH
13069 if (reg2 != NULL_RTX)
13070 real = replace_rtx (real, reg2, rreg);
f676971a
EC
13071
13072 real = replace_rtx (real, reg,
9ebbca7d
GK
13073 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
13074 STACK_POINTER_REGNUM),
13075 GEN_INT (val)));
f676971a 13076
9ebbca7d
GK
13077 /* We expect that 'real' is either a SET or a PARALLEL containing
13078 SETs (and possibly other stuff). In a PARALLEL, all the SETs
13079 are important so they all have to be marked RTX_FRAME_RELATED_P. */
13080
13081 if (GET_CODE (real) == SET)
13082 {
13083 rtx set = real;
f676971a 13084
9ebbca7d
GK
13085 temp = simplify_rtx (SET_SRC (set));
13086 if (temp)
13087 SET_SRC (set) = temp;
13088 temp = simplify_rtx (SET_DEST (set));
13089 if (temp)
13090 SET_DEST (set) = temp;
13091 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 13092 {
9ebbca7d
GK
13093 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
13094 if (temp)
13095 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 13096 }
38c1f2d7 13097 }
9ebbca7d
GK
13098 else if (GET_CODE (real) == PARALLEL)
13099 {
13100 int i;
13101 for (i = 0; i < XVECLEN (real, 0); i++)
13102 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
13103 {
13104 rtx set = XVECEXP (real, 0, i);
f676971a 13105
9ebbca7d
GK
13106 temp = simplify_rtx (SET_SRC (set));
13107 if (temp)
13108 SET_SRC (set) = temp;
13109 temp = simplify_rtx (SET_DEST (set));
13110 if (temp)
13111 SET_DEST (set) = temp;
13112 if (GET_CODE (SET_DEST (set)) == MEM)
13113 {
13114 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
13115 if (temp)
13116 XEXP (SET_DEST (set), 0) = temp;
13117 }
13118 RTX_FRAME_RELATED_P (set) = 1;
13119 }
13120 }
13121 else
a4f6c312 13122 abort ();
c19de7aa
AH
13123
13124 if (TARGET_SPE)
13125 real = spe_synthesize_frame_save (real);
13126
9ebbca7d
GK
13127 RTX_FRAME_RELATED_P (insn) = 1;
13128 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13129 real,
13130 REG_NOTES (insn));
38c1f2d7
MM
13131}
13132
c19de7aa
AH
13133/* Given an SPE frame note, return a PARALLEL of SETs with the
13134 original note, plus a synthetic register save. */
13135
13136static rtx
a2369ed3 13137spe_synthesize_frame_save (rtx real)
c19de7aa
AH
13138{
13139 rtx synth, offset, reg, real2;
13140
13141 if (GET_CODE (real) != SET
13142 || GET_MODE (SET_SRC (real)) != V2SImode)
13143 return real;
13144
13145 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
13146 frame related note. The parallel contains a set of the register
41f3a930 13147 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
13148 This is so we can differentiate between 64-bit and 32-bit saves.
13149 Words cannot describe this nastiness. */
13150
13151 if (GET_CODE (SET_DEST (real)) != MEM
13152 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
13153 || GET_CODE (SET_SRC (real)) != REG)
13154 abort ();
13155
13156 /* Transform:
13157 (set (mem (plus (reg x) (const y)))
13158 (reg z))
13159 into:
13160 (set (mem (plus (reg x) (const y+4)))
41f3a930 13161 (reg z+1200))
c19de7aa
AH
13162 */
13163
13164 real2 = copy_rtx (real);
13165 PUT_MODE (SET_DEST (real2), SImode);
13166 reg = SET_SRC (real2);
13167 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
13168 synth = copy_rtx (real2);
13169
13170 if (BYTES_BIG_ENDIAN)
13171 {
13172 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
13173 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
13174 }
13175
13176 reg = SET_SRC (synth);
41f3a930 13177
c19de7aa 13178 synth = replace_rtx (synth, reg,
41f3a930 13179 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
13180
13181 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
13182 synth = replace_rtx (synth, offset,
13183 GEN_INT (INTVAL (offset)
13184 + (BYTES_BIG_ENDIAN ? 0 : 4)));
13185
13186 RTX_FRAME_RELATED_P (synth) = 1;
13187 RTX_FRAME_RELATED_P (real2) = 1;
13188 if (BYTES_BIG_ENDIAN)
13189 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
13190 else
13191 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
13192
13193 return real;
13194}
13195
00b960c7
AH
13196/* Returns an insn that has a vrsave set operation with the
13197 appropriate CLOBBERs. */
13198
13199static rtx
a2369ed3 13200generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
13201{
13202 int nclobs, i;
13203 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 13204 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 13205
a004eb82
AH
13206 clobs[0]
13207 = gen_rtx_SET (VOIDmode,
13208 vrsave,
13209 gen_rtx_UNSPEC_VOLATILE (SImode,
13210 gen_rtvec (2, reg, vrsave),
13211 30));
00b960c7
AH
13212
13213 nclobs = 1;
13214
9aa86737
AH
13215 /* We need to clobber the registers in the mask so the scheduler
13216 does not move sets to VRSAVE before sets of AltiVec registers.
13217
13218 However, if the function receives nonlocal gotos, reload will set
13219 all call saved registers live. We will end up with:
13220
13221 (set (reg 999) (mem))
13222 (parallel [ (set (reg vrsave) (unspec blah))
13223 (clobber (reg 999))])
13224
13225 The clobber will cause the store into reg 999 to be dead, and
13226 flow will attempt to delete an epilogue insn. In this case, we
13227 need an unspec use/set of the register. */
00b960c7
AH
13228
13229 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
44688022 13230 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
9aa86737
AH
13231 {
13232 if (!epiloguep || call_used_regs [i])
13233 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
13234 gen_rtx_REG (V4SImode, i));
13235 else
13236 {
13237 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
13238
13239 clobs[nclobs++]
a004eb82
AH
13240 = gen_rtx_SET (VOIDmode,
13241 reg,
13242 gen_rtx_UNSPEC (V4SImode,
13243 gen_rtvec (1, reg), 27));
9aa86737
AH
13244 }
13245 }
00b960c7
AH
13246
13247 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
13248
13249 for (i = 0; i < nclobs; ++i)
13250 XVECEXP (insn, 0, i) = clobs[i];
13251
13252 return insn;
13253}
13254
89e7058f
AH
13255/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
13256 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
13257
13258static void
f676971a 13259emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 13260 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
13261{
13262 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
13263 rtx replacea, replaceb;
13264
13265 int_rtx = GEN_INT (offset);
13266
13267 /* Some cases that need register indexed addressing. */
13268 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
13269 || (TARGET_SPE_ABI
13270 && SPE_VECTOR_MODE (mode)
13271 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
13272 {
13273 /* Whomever calls us must make sure r11 is available in the
c4ad648e 13274 flow path of instructions in the prologue. */
89e7058f
AH
13275 offset_rtx = gen_rtx_REG (Pmode, 11);
13276 emit_move_insn (offset_rtx, int_rtx);
13277
13278 replacea = offset_rtx;
13279 replaceb = int_rtx;
13280 }
13281 else
13282 {
13283 offset_rtx = int_rtx;
13284 replacea = NULL_RTX;
13285 replaceb = NULL_RTX;
13286 }
13287
13288 reg = gen_rtx_REG (mode, regno);
13289 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
13290 mem = gen_rtx_MEM (mode, addr);
13291 set_mem_alias_set (mem, rs6000_sr_alias_set);
13292
13293 insn = emit_move_insn (mem, reg);
13294
13295 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
13296}
13297
a3170dc6
AH
13298/* Emit an offset memory reference suitable for a frame store, while
13299 converting to a valid addressing mode. */
13300
13301static rtx
a2369ed3 13302gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
13303{
13304 rtx int_rtx, offset_rtx;
13305
13306 int_rtx = GEN_INT (offset);
13307
13308 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
13309 {
13310 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13311 emit_move_insn (offset_rtx, int_rtx);
13312 }
13313 else
13314 offset_rtx = int_rtx;
13315
13316 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
13317}
13318
699c914a
MS
13319#ifndef TARGET_FIX_AND_CONTINUE
13320#define TARGET_FIX_AND_CONTINUE 0
13321#endif
13322
9ebbca7d
GK
13323/* Emit function prologue as insns. */
13324
9878760c 13325void
863d938c 13326rs6000_emit_prologue (void)
9878760c 13327{
4697a36c 13328 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 13329 enum machine_mode reg_mode = Pmode;
327e5343 13330 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
13331 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
13332 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
13333 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 13334 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
13335 rtx insn;
13336 int saving_FPRs_inline;
13337 int using_store_multiple;
13338 HOST_WIDE_INT sp_offset = 0;
f676971a 13339
699c914a
MS
13340 if (TARGET_FIX_AND_CONTINUE)
13341 {
13342 /* gdb on darwin arranges to forward a function from the old
13343 address by modifying the first 4 instructions of the function
13344 to branch to the overriding function. This is necessary to
13345 permit function pointers that point to the old function to
13346 actually forward to the new function. */
13347 emit_insn (gen_nop ());
13348 emit_insn (gen_nop ());
13349 emit_insn (gen_nop ());
13350 emit_insn (gen_nop ());
13351 }
13352
13353 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
13354 {
13355 reg_mode = V2SImode;
13356 reg_size = 8;
13357 }
a3170dc6 13358
9ebbca7d 13359 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
13360 && (!TARGET_SPE_ABI
13361 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
13362 && info->first_gp_reg_save < 31);
13363 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 13364 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 13365 || current_function_calls_eh_return
8c29550d 13366 || cfun->machine->ra_need_lr);
9ebbca7d
GK
13367
13368 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 13369 if (info->push_p
acd0b319
AM
13370 && (DEFAULT_ABI == ABI_V4
13371 || current_function_calls_eh_return))
9ebbca7d
GK
13372 {
13373 if (info->total_size < 32767)
13374 sp_offset = info->total_size;
13375 else
13376 frame_reg_rtx = frame_ptr_rtx;
f676971a 13377 rs6000_emit_allocate_stack (info->total_size,
9ebbca7d
GK
13378 (frame_reg_rtx != sp_reg_rtx
13379 && (info->cr_save_p
13380 || info->lr_save_p
13381 || info->first_fp_reg_save < 64
13382 || info->first_gp_reg_save < 32
13383 )));
13384 if (frame_reg_rtx != sp_reg_rtx)
13385 rs6000_emit_stack_tie ();
13386 }
13387
d62294f5
FJ
13388 /* Handle world saves specially here. */
13389 if (info->world_save_p)
13390 {
13391 int i, j, sz;
13392 rtx treg;
13393 rtvec p;
13394
13395 /* save_world expects lr in r0. */
13396 if (info->lr_save_p)
c4ad648e
AM
13397 {
13398 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13399 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13400 RTX_FRAME_RELATED_P (insn) = 1;
13401 }
d62294f5
FJ
13402
13403 /* The SAVE_WORLD and RESTORE_WORLD routines make a number of
c4ad648e
AM
13404 assumptions about the offsets of various bits of the stack
13405 frame. Abort if things aren't what they should be. */
d62294f5 13406 if (info->gp_save_offset != -220
c4ad648e
AM
13407 || info->fp_save_offset != -144
13408 || info->lr_save_offset != 8
13409 || info->cr_save_offset != 4
13410 || !info->push_p
13411 || !info->lr_save_p
13412 || (current_function_calls_eh_return && info->ehrd_offset != -432)
13413 || (info->vrsave_save_offset != -224
13414 || info->altivec_save_offset != (-224 -16 -192)))
13415 abort ();
d62294f5
FJ
13416
13417 treg = gen_rtx_REG (SImode, 11);
13418 emit_move_insn (treg, GEN_INT (-info->total_size));
13419
13420 /* SAVE_WORLD takes the caller's LR in R0 and the frame size
c4ad648e 13421 in R11. It also clobbers R12, so beware! */
d62294f5
FJ
13422
13423 /* Preserve CR2 for save_world prologues */
13424 sz = 6;
13425 sz += 32 - info->first_gp_reg_save;
13426 sz += 64 - info->first_fp_reg_save;
13427 sz += LAST_ALTIVEC_REGNO - info->first_altivec_reg_save + 1;
13428 p = rtvec_alloc (sz);
13429 j = 0;
13430 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode,
c4ad648e
AM
13431 gen_rtx_REG (Pmode,
13432 LINK_REGISTER_REGNUM));
d62294f5 13433 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
c4ad648e
AM
13434 gen_rtx_SYMBOL_REF (Pmode,
13435 "*save_world"));
d62294f5 13436 /* We do floats first so that the instruction pattern matches
c4ad648e
AM
13437 properly. */
13438 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13439 {
13440 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13441 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13442 GEN_INT (info->fp_save_offset
13443 + sp_offset + 8 * i));
13444 rtx mem = gen_rtx_MEM (DFmode, addr);
13445 set_mem_alias_set (mem, rs6000_sr_alias_set);
13446
13447 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13448 }
d62294f5 13449 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
c4ad648e
AM
13450 {
13451 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
13452 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13453 GEN_INT (info->altivec_save_offset
13454 + sp_offset + 16 * i));
13455 rtx mem = gen_rtx_MEM (V4SImode, addr);
13456 set_mem_alias_set (mem, rs6000_sr_alias_set);
13457
13458 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13459 }
d62294f5 13460 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
c4ad648e
AM
13461 {
13462 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13463 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13464 GEN_INT (info->gp_save_offset
13465 + sp_offset + reg_size * i));
13466 rtx mem = gen_rtx_MEM (reg_mode, addr);
13467 set_mem_alias_set (mem, rs6000_sr_alias_set);
13468
13469 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13470 }
13471
13472 {
13473 /* CR register traditionally saved as CR2. */
13474 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
13475 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13476 GEN_INT (info->cr_save_offset
13477 + sp_offset));
13478 rtx mem = gen_rtx_MEM (reg_mode, addr);
13479 set_mem_alias_set (mem, rs6000_sr_alias_set);
13480
13481 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13482 }
d62294f5
FJ
13483 /* Prevent any attempt to delete the setting of r0 and treg! */
13484 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, 0));
13485 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, treg);
13486 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode, sp_reg_rtx);
13487
13488 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
13489 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
c4ad648e 13490 NULL_RTX, NULL_RTX);
d62294f5
FJ
13491
13492 if (current_function_calls_eh_return)
c4ad648e
AM
13493 {
13494 unsigned int i;
13495 for (i = 0; ; ++i)
13496 {
13497 unsigned int regno = EH_RETURN_DATA_REGNO (i);
13498 if (regno == INVALID_REGNUM)
13499 break;
13500 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13501 info->ehrd_offset + sp_offset
13502 + reg_size * (int) i,
13503 info->total_size);
13504 }
13505 }
d62294f5
FJ
13506 }
13507
9aa86737 13508 /* Save AltiVec registers if needed. */
d62294f5 13509 if (! info->world_save_p && TARGET_ALTIVEC_ABI && info->altivec_size != 0)
9aa86737
AH
13510 {
13511 int i;
13512
13513 /* There should be a non inline version of this, for when we
13514 are saving lots of vector registers. */
13515 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
13516 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
13517 {
13518 rtx areg, savereg, mem;
13519 int offset;
13520
13521 offset = info->altivec_save_offset + sp_offset
13522 + 16 * (i - info->first_altivec_reg_save);
13523
13524 savereg = gen_rtx_REG (V4SImode, i);
13525
13526 areg = gen_rtx_REG (Pmode, 0);
13527 emit_move_insn (areg, GEN_INT (offset));
13528
13529 /* AltiVec addressing mode is [reg+reg]. */
13530 mem = gen_rtx_MEM (V4SImode,
13531 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
f676971a 13532
9aa86737
AH
13533 set_mem_alias_set (mem, rs6000_sr_alias_set);
13534
13535 insn = emit_move_insn (mem, savereg);
13536
5c242421
SB
13537 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13538 areg, GEN_INT (offset));
9aa86737
AH
13539 }
13540 }
13541
13542 /* VRSAVE is a bit vector representing which AltiVec registers
13543 are used. The OS uses this to determine which vector
13544 registers to save on a context switch. We need to save
13545 VRSAVE on the stack frame, add whatever AltiVec registers we
13546 used in this function, and do the corresponding magic in the
13547 epilogue. */
13548
4d774ff8 13549 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
d62294f5 13550 && ! info->world_save_p && info->vrsave_mask != 0)
9aa86737 13551 {
a004eb82 13552 rtx reg, mem, vrsave;
9aa86737
AH
13553 int offset;
13554
13555 /* Get VRSAVE onto a GPR. */
13556 reg = gen_rtx_REG (SImode, 12);
a004eb82 13557 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
13558 if (TARGET_MACHO)
13559 emit_insn (gen_get_vrsave_internal (reg));
13560 else
13561 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
13562
13563 /* Save VRSAVE. */
13564 offset = info->vrsave_save_offset + sp_offset;
13565 mem
13566 = gen_rtx_MEM (SImode,
13567 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
13568 set_mem_alias_set (mem, rs6000_sr_alias_set);
13569 insn = emit_move_insn (mem, reg);
13570
13571 /* Include the registers in the mask. */
13572 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
13573
13574 insn = emit_insn (generate_set_vrsave (reg, info, 0));
13575 }
13576
9ebbca7d 13577 /* If we use the link register, get it into r0. */
d62294f5 13578 if (! info->world_save_p && info->lr_save_p)
f8a57be8
GK
13579 {
13580 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13581 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13582 RTX_FRAME_RELATED_P (insn) = 1;
13583 }
9ebbca7d
GK
13584
13585 /* If we need to save CR, put it into r12. */
d62294f5 13586 if (! info->world_save_p && info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
9ebbca7d 13587 {
f8a57be8 13588 rtx set;
f676971a 13589
9ebbca7d 13590 cr_save_rtx = gen_rtx_REG (SImode, 12);
f8a57be8
GK
13591 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13592 RTX_FRAME_RELATED_P (insn) = 1;
13593 /* Now, there's no way that dwarf2out_frame_debug_expr is going
13594 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
13595 But that's OK. All we have to do is specify that _one_ condition
13596 code register is saved in this stack slot. The thrower's epilogue
13597 will then restore all the call-saved registers.
13598 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
13599 set = gen_rtx_SET (VOIDmode, cr_save_rtx,
13600 gen_rtx_REG (SImode, CR2_REGNO));
13601 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13602 set,
13603 REG_NOTES (insn));
9ebbca7d
GK
13604 }
13605
a4f6c312
SS
13606 /* Do any required saving of fpr's. If only one or two to save, do
13607 it ourselves. Otherwise, call function. */
d62294f5 13608 if (! info->world_save_p && saving_FPRs_inline)
9ebbca7d
GK
13609 {
13610 int i;
13611 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 13612 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d 13613 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
13614 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
13615 info->first_fp_reg_save + i,
13616 info->fp_save_offset + sp_offset + 8 * i,
13617 info->total_size);
9ebbca7d 13618 }
d62294f5 13619 else if (! info->world_save_p && info->first_fp_reg_save != 64)
9ebbca7d
GK
13620 {
13621 int i;
13622 char rname[30];
520a57c8 13623 const char *alloc_rname;
9ebbca7d
GK
13624 rtvec p;
13625 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
f676971a
EC
13626
13627 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
13628 gen_rtx_REG (Pmode,
9ebbca7d
GK
13629 LINK_REGISTER_REGNUM));
13630 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
13631 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 13632 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
13633 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
13634 gen_rtx_SYMBOL_REF (Pmode,
13635 alloc_rname));
13636 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13637 {
13638 rtx addr, reg, mem;
13639 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13640 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a 13641 GEN_INT (info->fp_save_offset
9ebbca7d
GK
13642 + sp_offset + 8*i));
13643 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 13644 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13645
13646 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
13647 }
13648 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13649 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d
GK
13650 NULL_RTX, NULL_RTX);
13651 }
b6c9286a 13652
9ebbca7d
GK
13653 /* Save GPRs. This is done as a PARALLEL if we are using
13654 the store-multiple instructions. */
d62294f5 13655 if (! info->world_save_p && using_store_multiple)
b6c9286a 13656 {
308c142a 13657 rtvec p;
9ebbca7d
GK
13658 int i;
13659 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
13660 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13661 {
13662 rtx addr, reg, mem;
13663 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
f676971a
EC
13664 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13665 GEN_INT (info->gp_save_offset
13666 + sp_offset
9ebbca7d
GK
13667 + reg_size * i));
13668 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 13669 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13670
13671 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
13672 }
13673 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13674 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d 13675 NULL_RTX, NULL_RTX);
b6c9286a 13676 }
d62294f5 13677 else if (! info->world_save_p)
b6c9286a 13678 {
9ebbca7d
GK
13679 int i;
13680 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 13681 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
13682 && (! call_used_regs[info->first_gp_reg_save+i]
13683 || (i+info->first_gp_reg_save
13684 == RS6000_PIC_OFFSET_TABLE_REGNUM
13685 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 13686 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 13687 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 13688 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
13689 {
13690 rtx addr, reg, mem;
13691 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13692
c19de7aa 13693 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13694 {
13695 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
13696 rtx b;
13697
13698 if (!SPE_CONST_OFFSET_OK (offset))
13699 {
13700 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13701 emit_move_insn (b, GEN_INT (offset));
13702 }
13703 else
13704 b = GEN_INT (offset);
13705
13706 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
13707 mem = gen_rtx_MEM (V2SImode, addr);
13708 set_mem_alias_set (mem, rs6000_sr_alias_set);
13709 insn = emit_move_insn (mem, reg);
13710
13711 if (GET_CODE (b) == CONST_INT)
13712 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13713 NULL_RTX, NULL_RTX);
13714 else
13715 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13716 b, GEN_INT (offset));
13717 }
13718 else
13719 {
f676971a
EC
13720 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13721 GEN_INT (info->gp_save_offset
13722 + sp_offset
a3170dc6
AH
13723 + reg_size * i));
13724 mem = gen_rtx_MEM (reg_mode, addr);
13725 set_mem_alias_set (mem, rs6000_sr_alias_set);
13726
13727 insn = emit_move_insn (mem, reg);
f676971a 13728 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a3170dc6
AH
13729 NULL_RTX, NULL_RTX);
13730 }
13731 }
9ebbca7d
GK
13732 }
13733
83720594
RH
13734 /* ??? There's no need to emit actual instructions here, but it's the
13735 easiest way to get the frame unwind information emitted. */
d62294f5 13736 if (! info->world_save_p && current_function_calls_eh_return)
83720594 13737 {
78e1b90d
DE
13738 unsigned int i, regno;
13739
fc4767bb
JJ
13740 /* In AIX ABI we need to pretend we save r2 here. */
13741 if (TARGET_AIX)
13742 {
13743 rtx addr, reg, mem;
13744
13745 reg = gen_rtx_REG (reg_mode, 2);
13746 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13747 GEN_INT (sp_offset + 5 * reg_size));
13748 mem = gen_rtx_MEM (reg_mode, addr);
13749 set_mem_alias_set (mem, rs6000_sr_alias_set);
13750
13751 insn = emit_move_insn (mem, reg);
f676971a 13752 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
fc4767bb
JJ
13753 NULL_RTX, NULL_RTX);
13754 PATTERN (insn) = gen_blockage ();
13755 }
13756
83720594
RH
13757 for (i = 0; ; ++i)
13758 {
83720594
RH
13759 regno = EH_RETURN_DATA_REGNO (i);
13760 if (regno == INVALID_REGNUM)
13761 break;
13762
89e7058f
AH
13763 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13764 info->ehrd_offset + sp_offset
13765 + reg_size * (int) i,
13766 info->total_size);
83720594
RH
13767 }
13768 }
13769
9ebbca7d 13770 /* Save lr if we used it. */
d62294f5 13771 if (! info->world_save_p && info->lr_save_p)
9ebbca7d
GK
13772 {
13773 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13774 GEN_INT (info->lr_save_offset + sp_offset));
13775 rtx reg = gen_rtx_REG (Pmode, 0);
13776 rtx mem = gen_rtx_MEM (Pmode, addr);
13777 /* This should not be of rs6000_sr_alias_set, because of
13778 __builtin_return_address. */
f676971a 13779
9ebbca7d 13780 insn = emit_move_insn (mem, reg);
f676971a 13781 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13782 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13783 }
13784
13785 /* Save CR if we use any that must be preserved. */
d62294f5 13786 if (! info->world_save_p && info->cr_save_p)
9ebbca7d
GK
13787 {
13788 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13789 GEN_INT (info->cr_save_offset + sp_offset));
13790 rtx mem = gen_rtx_MEM (SImode, addr);
f8a57be8
GK
13791 /* See the large comment above about why CR2_REGNO is used. */
13792 rtx magic_eh_cr_reg = gen_rtx_REG (SImode, CR2_REGNO);
ba4828e0
RK
13793
13794 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13795
13796 /* If r12 was used to hold the original sp, copy cr into r0 now
13797 that it's free. */
13798 if (REGNO (frame_reg_rtx) == 12)
13799 {
f8a57be8
GK
13800 rtx set;
13801
9ebbca7d 13802 cr_save_rtx = gen_rtx_REG (SImode, 0);
f8a57be8
GK
13803 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13804 RTX_FRAME_RELATED_P (insn) = 1;
13805 set = gen_rtx_SET (VOIDmode, cr_save_rtx, magic_eh_cr_reg);
13806 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13807 set,
13808 REG_NOTES (insn));
f676971a 13809
9ebbca7d
GK
13810 }
13811 insn = emit_move_insn (mem, cr_save_rtx);
13812
f676971a 13813 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13814 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13815 }
13816
f676971a 13817 /* Update stack and set back pointer unless this is V.4,
9ebbca7d 13818 for which it was done previously. */
d62294f5 13819 if (! info->world_save_p && info->push_p
fc4767bb 13820 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
13821 rs6000_emit_allocate_stack (info->total_size, FALSE);
13822
13823 /* Set frame pointer, if needed. */
13824 if (frame_pointer_needed)
13825 {
f676971a 13826 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
13827 sp_reg_rtx);
13828 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 13829 }
9878760c 13830
1db02437 13831 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 13832 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 13833 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 13834 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
c4ad648e
AM
13835 {
13836 /* If emit_load_toc_table will use the link register, we need to save
13837 it. We use R12 for this purpose because emit_load_toc_table
13838 can use register 0. This allows us to use a plain 'blr' to return
13839 from the procedure more often. */
13840 int save_LR_around_toc_setup = (TARGET_ELF
13841 && DEFAULT_ABI != ABI_AIX
13842 && flag_pic
13843 && ! info->lr_save_p
13844 && EDGE_COUNT (EXIT_BLOCK_PTR->preds) > 0);
13845 if (save_LR_around_toc_setup)
13846 {
13847 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f8a57be8 13848
c4ad648e
AM
13849 insn = emit_move_insn (frame_ptr_rtx, lr);
13850 rs6000_maybe_dead (insn);
13851 RTX_FRAME_RELATED_P (insn) = 1;
f8a57be8 13852
c4ad648e 13853 rs6000_emit_load_toc_table (TRUE);
f8a57be8 13854
c4ad648e
AM
13855 insn = emit_move_insn (lr, frame_ptr_rtx);
13856 rs6000_maybe_dead (insn);
13857 RTX_FRAME_RELATED_P (insn) = 1;
13858 }
13859 else
13860 rs6000_emit_load_toc_table (TRUE);
13861 }
ee890fe2 13862
fcce224d 13863#if TARGET_MACHO
ee890fe2
SS
13864 if (DEFAULT_ABI == ABI_DARWIN
13865 && flag_pic && current_function_uses_pic_offset_table)
13866 {
f8a57be8 13867 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
11abc112 13868 rtx src = machopic_function_base_sym ();
ee890fe2 13869
f8a57be8 13870 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (lr, src)));
ee890fe2 13871
f676971a 13872 insn = emit_move_insn (gen_rtx_REG (Pmode,
f8a57be8
GK
13873 RS6000_PIC_OFFSET_TABLE_REGNUM),
13874 lr);
13875 rs6000_maybe_dead (insn);
ee890fe2 13876 }
fcce224d 13877#endif
9ebbca7d
GK
13878}
13879
9ebbca7d 13880/* Write function prologue. */
a4f6c312 13881
08c148a8 13882static void
f676971a 13883rs6000_output_function_prologue (FILE *file,
a2369ed3 13884 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
13885{
13886 rs6000_stack_t *info = rs6000_stack_info ();
13887
4697a36c
MM
13888 if (TARGET_DEBUG_STACK)
13889 debug_stack_info (info);
9878760c 13890
a4f6c312
SS
13891 /* Write .extern for any function we will call to save and restore
13892 fp values. */
13893 if (info->first_fp_reg_save < 64
13894 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 13895 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 13896 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
13897 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
13898 RESTORE_FP_SUFFIX);
9878760c 13899
c764f757
RK
13900 /* Write .extern for AIX common mode routines, if needed. */
13901 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
13902 {
f6709c70
JW
13903 fputs ("\t.extern __mulh\n", file);
13904 fputs ("\t.extern __mull\n", file);
13905 fputs ("\t.extern __divss\n", file);
13906 fputs ("\t.extern __divus\n", file);
13907 fputs ("\t.extern __quoss\n", file);
13908 fputs ("\t.extern __quous\n", file);
c764f757
RK
13909 common_mode_defined = 1;
13910 }
9878760c 13911
9ebbca7d 13912 if (! HAVE_prologue)
979721f8 13913 {
9ebbca7d 13914 start_sequence ();
9dda4cc8 13915
a4f6c312
SS
13916 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
13917 the "toplevel" insn chain. */
2e040219 13918 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13919 rs6000_emit_prologue ();
2e040219 13920 emit_note (NOTE_INSN_DELETED);
178c3eff 13921
a3c9585f 13922 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
13923 {
13924 rtx insn;
13925 unsigned addr = 0;
13926 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
13927 {
13928 INSN_ADDRESSES_NEW (insn, addr);
13929 addr += 4;
13930 }
13931 }
9dda4cc8 13932
9ebbca7d 13933 if (TARGET_DEBUG_STACK)
a4f6c312
SS
13934 debug_rtx_list (get_insns (), 100);
13935 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 13936 end_sequence ();
979721f8
MM
13937 }
13938
9ebbca7d
GK
13939 rs6000_pic_labelno++;
13940}
f676971a 13941
9ebbca7d 13942/* Emit function epilogue as insns.
9878760c 13943
9ebbca7d
GK
13944 At present, dwarf2out_frame_debug_expr doesn't understand
13945 register restores, so we don't bother setting RTX_FRAME_RELATED_P
13946 anywhere in the epilogue. Most of the insns below would in any case
13947 need special notes to explain where r11 is in relation to the stack. */
9878760c 13948
9ebbca7d 13949void
a2369ed3 13950rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
13951{
13952 rs6000_stack_t *info;
13953 int restoring_FPRs_inline;
13954 int using_load_multiple;
13955 int using_mfcr_multiple;
13956 int use_backchain_to_restore_sp;
13957 int sp_offset = 0;
13958 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
13959 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 13960 enum machine_mode reg_mode = Pmode;
327e5343 13961 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
13962 int i;
13963
c19de7aa
AH
13964 info = rs6000_stack_info ();
13965
13966 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13967 {
13968 reg_mode = V2SImode;
13969 reg_size = 8;
13970 }
13971
9ebbca7d 13972 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
13973 && (!TARGET_SPE_ABI
13974 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
13975 && info->first_gp_reg_save < 31);
13976 restoring_FPRs_inline = (sibcall
83720594 13977 || current_function_calls_eh_return
9ebbca7d
GK
13978 || info->first_fp_reg_save == 64
13979 || FP_SAVE_INLINE (info->first_fp_reg_save));
f676971a 13980 use_backchain_to_restore_sp = (frame_pointer_needed
9ebbca7d
GK
13981 || current_function_calls_alloca
13982 || info->total_size > 32767);
13983 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
13984 || rs6000_cpu == PROCESSOR_PPC603
13985 || rs6000_cpu == PROCESSOR_PPC750
13986 || optimize_size);
13987
d62294f5
FJ
13988 if (info->world_save_p)
13989 {
13990 int i, j;
13991 char rname[30];
13992 const char *alloc_rname;
13993 rtvec p;
13994
13995 /* eh_rest_world_r10 will return to the location saved in the LR
c4ad648e
AM
13996 stack slot (which is not likely to be our caller.)
13997 Input: R10 -- stack adjustment. Clobbers R0, R11, R12, R7, R8.
13998 rest_world is similar, except any R10 parameter is ignored.
13999 The exception-handling stuff that was here in 2.95 is no
14000 longer necessary. */
d62294f5
FJ
14001
14002 p = rtvec_alloc (9
14003 + 1
f676971a 14004 + 32 - info->first_gp_reg_save
c4ad648e
AM
14005 + LAST_ALTIVEC_REGNO + 1 - info->first_altivec_reg_save
14006 + 63 + 1 - info->first_fp_reg_save);
d62294f5 14007
c4ad648e
AM
14008 strcpy (rname, ((current_function_calls_eh_return) ?
14009 "*eh_rest_world_r10" : "*rest_world"));
d62294f5
FJ
14010 alloc_rname = ggc_strdup (rname);
14011
14012 j = 0;
14013 RTVEC_ELT (p, j++) = gen_rtx_RETURN (VOIDmode);
14014 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
c4ad648e
AM
14015 gen_rtx_REG (Pmode,
14016 LINK_REGISTER_REGNUM));
d62294f5 14017 RTVEC_ELT (p, j++)
c4ad648e 14018 = gen_rtx_USE (VOIDmode, gen_rtx_SYMBOL_REF (Pmode, alloc_rname));
d62294f5 14019 /* The instruction pattern requires a clobber here;
c4ad648e 14020 it is shared with the restVEC helper. */
d62294f5 14021 RTVEC_ELT (p, j++)
c4ad648e 14022 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
d62294f5
FJ
14023
14024 {
c4ad648e
AM
14025 /* CR register traditionally saved as CR2. */
14026 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
14027 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14028 GEN_INT (info->cr_save_offset));
14029 rtx mem = gen_rtx_MEM (reg_mode, addr);
14030 set_mem_alias_set (mem, rs6000_sr_alias_set);
14031
14032 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
d62294f5
FJ
14033 }
14034
14035 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
c4ad648e
AM
14036 {
14037 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
14038 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14039 GEN_INT (info->gp_save_offset
14040 + reg_size * i));
14041 rtx mem = gen_rtx_MEM (reg_mode, addr);
14042 set_mem_alias_set (mem, rs6000_sr_alias_set);
14043
14044 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14045 }
d62294f5 14046 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
c4ad648e
AM
14047 {
14048 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
14049 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14050 GEN_INT (info->altivec_save_offset
14051 + 16 * i));
14052 rtx mem = gen_rtx_MEM (V4SImode, addr);
14053 set_mem_alias_set (mem, rs6000_sr_alias_set);
14054
14055 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14056 }
d62294f5 14057 for (i = 0; info->first_fp_reg_save + i <= 63; i++)
c4ad648e
AM
14058 {
14059 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
14060 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14061 GEN_INT (info->fp_save_offset
14062 + 8 * i));
14063 rtx mem = gen_rtx_MEM (DFmode, addr);
14064 set_mem_alias_set (mem, rs6000_sr_alias_set);
14065
14066 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14067 }
d62294f5 14068 RTVEC_ELT (p, j++)
c4ad648e 14069 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 0));
d62294f5 14070 RTVEC_ELT (p, j++)
c4ad648e 14071 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 12));
d62294f5 14072 RTVEC_ELT (p, j++)
c4ad648e 14073 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 7));
d62294f5 14074 RTVEC_ELT (p, j++)
c4ad648e 14075 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 8));
d62294f5 14076 RTVEC_ELT (p, j++)
c4ad648e 14077 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 10));
d62294f5
FJ
14078 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
14079
14080 return;
14081 }
14082
9ebbca7d
GK
14083 /* If we have a frame pointer, a call to alloca, or a large stack
14084 frame, restore the old stack pointer using the backchain. Otherwise,
14085 we know what size to update it with. */
14086 if (use_backchain_to_restore_sp)
bacbde18 14087 {
9ebbca7d
GK
14088 /* Under V.4, don't reset the stack pointer until after we're done
14089 loading the saved registers. */
f607bc57 14090 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 14091 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 14092
9ebbca7d
GK
14093 emit_move_insn (frame_reg_rtx,
14094 gen_rtx_MEM (Pmode, sp_reg_rtx));
f676971a 14095
bacbde18 14096 }
9ebbca7d 14097 else if (info->push_p)
85638c0d 14098 {
fc4767bb
JJ
14099 if (DEFAULT_ABI == ABI_V4
14100 || current_function_calls_eh_return)
9ebbca7d
GK
14101 sp_offset = info->total_size;
14102 else
14103 {
14104 emit_insn (TARGET_32BIT
14105 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
14106 GEN_INT (info->total_size))
14107 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
14108 GEN_INT (info->total_size)));
14109 }
85638c0d 14110 }
f676971a 14111
9aa86737
AH
14112 /* Restore AltiVec registers if needed. */
14113 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
14114 {
14115 int i;
14116
14117 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
14118 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
14119 {
14120 rtx addr, areg, mem;
14121
14122 areg = gen_rtx_REG (Pmode, 0);
14123 emit_move_insn
14124 (areg, GEN_INT (info->altivec_save_offset
14125 + sp_offset
14126 + 16 * (i - info->first_altivec_reg_save)));
14127
14128 /* AltiVec addressing mode is [reg+reg]. */
14129 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
14130 mem = gen_rtx_MEM (V4SImode, addr);
14131 set_mem_alias_set (mem, rs6000_sr_alias_set);
14132
14133 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
14134 }
14135 }
14136
14137 /* Restore VRSAVE if needed. */
44688022 14138 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
4d774ff8 14139 && info->vrsave_mask != 0)
9aa86737
AH
14140 {
14141 rtx addr, mem, reg;
14142
14143 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14144 GEN_INT (info->vrsave_save_offset + sp_offset));
14145 mem = gen_rtx_MEM (SImode, addr);
14146 set_mem_alias_set (mem, rs6000_sr_alias_set);
14147 reg = gen_rtx_REG (SImode, 12);
14148 emit_move_insn (reg, mem);
14149
14150 emit_insn (generate_set_vrsave (reg, info, 1));
14151 }
14152
9ebbca7d
GK
14153 /* Get the old lr if we saved it. */
14154 if (info->lr_save_p)
b6c9286a 14155 {
a3170dc6
AH
14156 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
14157 info->lr_save_offset + sp_offset);
ba4828e0
RK
14158
14159 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 14160
9ebbca7d 14161 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 14162 }
f676971a 14163
9ebbca7d
GK
14164 /* Get the old cr if we saved it. */
14165 if (info->cr_save_p)
14166 {
14167 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14168 GEN_INT (info->cr_save_offset + sp_offset));
14169 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
14170
14171 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 14172
9ebbca7d
GK
14173 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
14174 }
f676971a 14175
9ebbca7d 14176 /* Set LR here to try to overlap restores below. */
4697a36c 14177 if (info->lr_save_p)
9ebbca7d
GK
14178 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
14179 gen_rtx_REG (Pmode, 0));
f676971a 14180
83720594
RH
14181 /* Load exception handler data registers, if needed. */
14182 if (current_function_calls_eh_return)
14183 {
78e1b90d
DE
14184 unsigned int i, regno;
14185
fc4767bb
JJ
14186 if (TARGET_AIX)
14187 {
14188 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14189 GEN_INT (sp_offset + 5 * reg_size));
14190 rtx mem = gen_rtx_MEM (reg_mode, addr);
14191
14192 set_mem_alias_set (mem, rs6000_sr_alias_set);
14193
14194 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
14195 }
14196
83720594
RH
14197 for (i = 0; ; ++i)
14198 {
a3170dc6 14199 rtx mem;
83720594
RH
14200
14201 regno = EH_RETURN_DATA_REGNO (i);
14202 if (regno == INVALID_REGNUM)
14203 break;
14204
a3170dc6
AH
14205 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
14206 info->ehrd_offset + sp_offset
14207 + reg_size * (int) i);
ba4828e0 14208 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
14209
14210 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
14211 }
14212 }
f676971a 14213
9ebbca7d
GK
14214 /* Restore GPRs. This is done as a PARALLEL if we are using
14215 the load-multiple instructions. */
14216 if (using_load_multiple)
979721f8 14217 {
9ebbca7d
GK
14218 rtvec p;
14219 p = rtvec_alloc (32 - info->first_gp_reg_save);
14220 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 14221 {
f676971a
EC
14222 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14223 GEN_INT (info->gp_save_offset
14224 + sp_offset
9ebbca7d
GK
14225 + reg_size * i));
14226 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
14227
14228 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14229
f676971a 14230 RTVEC_ELT (p, i) =
9ebbca7d
GK
14231 gen_rtx_SET (VOIDmode,
14232 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
14233 mem);
979721f8 14234 }
9ebbca7d 14235 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 14236 }
9ebbca7d
GK
14237 else
14238 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 14239 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
14240 && (! call_used_regs[info->first_gp_reg_save+i]
14241 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14242 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 14243 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 14244 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 14245 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d 14246 {
f676971a
EC
14247 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14248 GEN_INT (info->gp_save_offset
14249 + sp_offset
9ebbca7d
GK
14250 + reg_size * i));
14251 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 14252
a3170dc6 14253 /* Restore 64-bit quantities for SPE. */
c19de7aa 14254 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
14255 {
14256 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
14257 rtx b;
14258
14259 if (!SPE_CONST_OFFSET_OK (offset))
14260 {
14261 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
14262 emit_move_insn (b, GEN_INT (offset));
14263 }
14264 else
14265 b = GEN_INT (offset);
14266
14267 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
14268 mem = gen_rtx_MEM (V2SImode, addr);
14269 }
14270
ba4828e0 14271 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14272
f676971a 14273 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 14274 info->first_gp_reg_save + i), mem);
9ebbca7d 14275 }
9878760c 14276
9ebbca7d
GK
14277 /* Restore fpr's if we need to do it without calling a function. */
14278 if (restoring_FPRs_inline)
14279 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 14280 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d
GK
14281 && ! call_used_regs[info->first_fp_reg_save+i]))
14282 {
14283 rtx addr, mem;
14284 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a
EC
14285 GEN_INT (info->fp_save_offset
14286 + sp_offset
a4f6c312 14287 + 8 * i));
9ebbca7d 14288 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14289 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14290
f676971a 14291 emit_move_insn (gen_rtx_REG (DFmode,
9ebbca7d
GK
14292 info->first_fp_reg_save + i),
14293 mem);
14294 }
8d30c4ee 14295
9ebbca7d
GK
14296 /* If we saved cr, restore it here. Just those that were used. */
14297 if (info->cr_save_p)
979721f8 14298 {
9ebbca7d 14299 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 14300 int count = 0;
f676971a 14301
9ebbca7d 14302 if (using_mfcr_multiple)
979721f8 14303 {
9ebbca7d
GK
14304 for (i = 0; i < 8; i++)
14305 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 14306 count++;
9ebbca7d 14307 if (count == 0)
e35b9579
GK
14308 abort ();
14309 }
14310
14311 if (using_mfcr_multiple && count > 1)
14312 {
14313 rtvec p;
14314 int ndx;
f676971a 14315
e35b9579 14316 p = rtvec_alloc (count);
9ebbca7d 14317
e35b9579 14318 ndx = 0;
9ebbca7d
GK
14319 for (i = 0; i < 8; i++)
14320 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
14321 {
14322 rtvec r = rtvec_alloc (2);
14323 RTVEC_ELT (r, 0) = r12_rtx;
14324 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 14325 RTVEC_ELT (p, ndx) =
f676971a 14326 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 14327 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 14328 ndx++;
9ebbca7d
GK
14329 }
14330 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
14331 if (ndx != count)
14332 abort ();
979721f8
MM
14333 }
14334 else
9ebbca7d
GK
14335 for (i = 0; i < 8; i++)
14336 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 14337 {
f676971a 14338 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
9ebbca7d
GK
14339 CR0_REGNO+i),
14340 r12_rtx));
979721f8 14341 }
979721f8
MM
14342 }
14343
9ebbca7d
GK
14344 /* If this is V.4, unwind the stack pointer after all of the loads
14345 have been done. We need to emit a block here so that sched
14346 doesn't decide to move the sp change before the register restores
14347 (which may not have any obvious dependency on the stack). This
14348 doesn't hurt performance, because there is no scheduling that can
14349 be done after this point. */
fc4767bb
JJ
14350 if (DEFAULT_ABI == ABI_V4
14351 || current_function_calls_eh_return)
b6c9286a 14352 {
9ebbca7d 14353 if (frame_reg_rtx != sp_reg_rtx)
c4ad648e 14354 rs6000_emit_stack_tie ();
b6c9286a 14355
9ebbca7d 14356 if (use_backchain_to_restore_sp)
b6c9286a 14357 {
9ebbca7d 14358 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 14359 }
9ebbca7d 14360 else if (sp_offset != 0)
13f1623b 14361 {
5b71a4e7 14362 emit_insn (TARGET_32BIT
9ebbca7d
GK
14363 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
14364 GEN_INT (sp_offset))
14365 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
14366 GEN_INT (sp_offset)));
13f1623b 14367 }
9ebbca7d 14368 }
b6c9286a 14369
83720594
RH
14370 if (current_function_calls_eh_return)
14371 {
14372 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 14373 emit_insn (TARGET_32BIT
83720594
RH
14374 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
14375 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
14376 }
14377
9ebbca7d
GK
14378 if (!sibcall)
14379 {
14380 rtvec p;
14381 if (! restoring_FPRs_inline)
14382 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
14383 else
14384 p = rtvec_alloc (2);
b6c9286a 14385
e35b9579 14386 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
f676971a
EC
14387 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
14388 gen_rtx_REG (Pmode,
9ebbca7d 14389 LINK_REGISTER_REGNUM));
9ebbca7d
GK
14390
14391 /* If we have to restore more than two FP registers, branch to the
14392 restore function. It will return to our caller. */
14393 if (! restoring_FPRs_inline)
14394 {
14395 int i;
14396 char rname[30];
520a57c8 14397 const char *alloc_rname;
979721f8 14398
f676971a 14399 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
9ebbca7d 14400 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 14401 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
14402 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
14403 gen_rtx_SYMBOL_REF (Pmode,
14404 alloc_rname));
b6c9286a 14405
9ebbca7d
GK
14406 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
14407 {
14408 rtx addr, mem;
14409 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
14410 GEN_INT (info->fp_save_offset + 8*i));
14411 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14412 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14413
f676971a 14414 RTVEC_ELT (p, i+3) =
9ebbca7d
GK
14415 gen_rtx_SET (VOIDmode,
14416 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
14417 mem);
b6c9286a
MM
14418 }
14419 }
f676971a 14420
9ebbca7d 14421 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 14422 }
9878760c
RK
14423}
14424
14425/* Write function epilogue. */
14426
08c148a8 14427static void
f676971a 14428rs6000_output_function_epilogue (FILE *file,
a2369ed3 14429 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 14430{
4697a36c 14431 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 14432
9ebbca7d 14433 if (! HAVE_epilogue)
9878760c 14434 {
9ebbca7d
GK
14435 rtx insn = get_last_insn ();
14436 /* If the last insn was a BARRIER, we don't have to write anything except
14437 the trace table. */
14438 if (GET_CODE (insn) == NOTE)
14439 insn = prev_nonnote_insn (insn);
14440 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 14441 {
9ebbca7d
GK
14442 /* This is slightly ugly, but at least we don't have two
14443 copies of the epilogue-emitting code. */
14444 start_sequence ();
14445
14446 /* A NOTE_INSN_DELETED is supposed to be at the start
14447 and end of the "toplevel" insn chain. */
2e040219 14448 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14449 rs6000_emit_epilogue (FALSE);
2e040219 14450 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14451
a3c9585f 14452 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
14453 {
14454 rtx insn;
14455 unsigned addr = 0;
14456 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
14457 {
14458 INSN_ADDRESSES_NEW (insn, addr);
14459 addr += 4;
14460 }
14461 }
14462
9ebbca7d 14463 if (TARGET_DEBUG_STACK)
a4f6c312
SS
14464 debug_rtx_list (get_insns (), 100);
14465 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 14466 end_sequence ();
4697a36c 14467 }
9878760c 14468 }
b4ac57ab 14469
efdba735
SH
14470#if TARGET_MACHO
14471 macho_branch_islands ();
0e5da0be
GK
14472 /* Mach-O doesn't support labels at the end of objects, so if
14473 it looks like we might want one, insert a NOP. */
14474 {
14475 rtx insn = get_last_insn ();
14476 while (insn
14477 && NOTE_P (insn)
14478 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
14479 insn = PREV_INSN (insn);
f676971a
EC
14480 if (insn
14481 && (LABEL_P (insn)
0e5da0be
GK
14482 || (NOTE_P (insn)
14483 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
14484 fputs ("\tnop\n", file);
14485 }
14486#endif
14487
9b30bae2 14488 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
14489 on its format.
14490
14491 We don't output a traceback table if -finhibit-size-directive was
14492 used. The documentation for -finhibit-size-directive reads
14493 ``don't output a @code{.size} assembler directive, or anything
14494 else that would cause trouble if the function is split in the
14495 middle, and the two halves are placed at locations far apart in
14496 memory.'' The traceback table has this property, since it
14497 includes the offset from the start of the function to the
4d30c363
MM
14498 traceback table itself.
14499
14500 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 14501 different traceback table. */
57ac7be9
AM
14502 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
14503 && rs6000_traceback != traceback_none)
9b30bae2 14504 {
69c75916 14505 const char *fname = NULL;
3ac88239 14506 const char *language_string = lang_hooks.name;
6041bf2f 14507 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 14508 int i;
57ac7be9
AM
14509 int optional_tbtab;
14510
14511 if (rs6000_traceback == traceback_full)
14512 optional_tbtab = 1;
14513 else if (rs6000_traceback == traceback_part)
14514 optional_tbtab = 0;
14515 else
14516 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 14517
69c75916
AM
14518 if (optional_tbtab)
14519 {
14520 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
14521 while (*fname == '.') /* V.4 encodes . in the name */
14522 fname++;
14523
14524 /* Need label immediately before tbtab, so we can compute
14525 its offset from the function start. */
14526 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
14527 ASM_OUTPUT_LABEL (file, fname);
14528 }
314fc5a9
ILT
14529
14530 /* The .tbtab pseudo-op can only be used for the first eight
14531 expressions, since it can't handle the possibly variable
14532 length fields that follow. However, if you omit the optional
14533 fields, the assembler outputs zeros for all optional fields
14534 anyways, giving each variable length field is minimum length
14535 (as defined in sys/debug.h). Thus we can not use the .tbtab
14536 pseudo-op at all. */
14537
14538 /* An all-zero word flags the start of the tbtab, for debuggers
14539 that have to find it by searching forward from the entry
14540 point or from the current pc. */
19d2d16f 14541 fputs ("\t.long 0\n", file);
314fc5a9
ILT
14542
14543 /* Tbtab format type. Use format type 0. */
19d2d16f 14544 fputs ("\t.byte 0,", file);
314fc5a9 14545
5fc921c1
DE
14546 /* Language type. Unfortunately, there does not seem to be any
14547 official way to discover the language being compiled, so we
14548 use language_string.
14549 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
14550 Java is 13. Objective-C is 14. */
14551 if (! strcmp (language_string, "GNU C"))
314fc5a9 14552 i = 0;
6de9cd9a
DN
14553 else if (! strcmp (language_string, "GNU F77")
14554 || ! strcmp (language_string, "GNU F95"))
314fc5a9 14555 i = 1;
8b83775b 14556 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 14557 i = 2;
5fc921c1
DE
14558 else if (! strcmp (language_string, "GNU Ada"))
14559 i = 3;
314fc5a9
ILT
14560 else if (! strcmp (language_string, "GNU C++"))
14561 i = 9;
9517ead8
AG
14562 else if (! strcmp (language_string, "GNU Java"))
14563 i = 13;
5fc921c1
DE
14564 else if (! strcmp (language_string, "GNU Objective-C"))
14565 i = 14;
314fc5a9
ILT
14566 else
14567 abort ();
14568 fprintf (file, "%d,", i);
14569
14570 /* 8 single bit fields: global linkage (not set for C extern linkage,
14571 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
14572 from start of procedure stored in tbtab, internal function, function
14573 has controlled storage, function has no toc, function uses fp,
14574 function logs/aborts fp operations. */
14575 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
14576 fprintf (file, "%d,",
14577 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
14578
14579 /* 6 bitfields: function is interrupt handler, name present in
14580 proc table, function calls alloca, on condition directives
14581 (controls stack walks, 3 bits), saves condition reg, saves
14582 link reg. */
14583 /* The `function calls alloca' bit seems to be set whenever reg 31 is
14584 set up as a frame pointer, even when there is no alloca call. */
14585 fprintf (file, "%d,",
6041bf2f
DE
14586 ((optional_tbtab << 6)
14587 | ((optional_tbtab & frame_pointer_needed) << 5)
14588 | (info->cr_save_p << 1)
14589 | (info->lr_save_p)));
314fc5a9 14590
6041bf2f 14591 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
14592 (6 bits). */
14593 fprintf (file, "%d,",
4697a36c 14594 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
14595
14596 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
14597 fprintf (file, "%d,", (32 - first_reg_to_save ()));
14598
6041bf2f
DE
14599 if (optional_tbtab)
14600 {
14601 /* Compute the parameter info from the function decl argument
14602 list. */
14603 tree decl;
14604 int next_parm_info_bit = 31;
314fc5a9 14605
6041bf2f
DE
14606 for (decl = DECL_ARGUMENTS (current_function_decl);
14607 decl; decl = TREE_CHAIN (decl))
14608 {
14609 rtx parameter = DECL_INCOMING_RTL (decl);
14610 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 14611
6041bf2f
DE
14612 if (GET_CODE (parameter) == REG)
14613 {
14614 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
14615 {
14616 int bits;
14617
14618 float_parms++;
14619
14620 if (mode == SFmode)
14621 bits = 0x2;
fcce224d 14622 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
14623 bits = 0x3;
14624 else
14625 abort ();
14626
14627 /* If only one bit will fit, don't or in this entry. */
14628 if (next_parm_info_bit > 0)
14629 parm_info |= (bits << (next_parm_info_bit - 1));
14630 next_parm_info_bit -= 2;
14631 }
14632 else
14633 {
14634 fixed_parms += ((GET_MODE_SIZE (mode)
14635 + (UNITS_PER_WORD - 1))
14636 / UNITS_PER_WORD);
14637 next_parm_info_bit -= 1;
14638 }
14639 }
14640 }
14641 }
314fc5a9
ILT
14642
14643 /* Number of fixed point parameters. */
14644 /* This is actually the number of words of fixed point parameters; thus
14645 an 8 byte struct counts as 2; and thus the maximum value is 8. */
14646 fprintf (file, "%d,", fixed_parms);
14647
14648 /* 2 bitfields: number of floating point parameters (7 bits), parameters
14649 all on stack. */
14650 /* This is actually the number of fp registers that hold parameters;
14651 and thus the maximum value is 13. */
14652 /* Set parameters on stack bit if parameters are not in their original
14653 registers, regardless of whether they are on the stack? Xlc
14654 seems to set the bit when not optimizing. */
14655 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
14656
6041bf2f
DE
14657 if (! optional_tbtab)
14658 return;
14659
314fc5a9
ILT
14660 /* Optional fields follow. Some are variable length. */
14661
14662 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
14663 11 double float. */
14664 /* There is an entry for each parameter in a register, in the order that
14665 they occur in the parameter list. Any intervening arguments on the
14666 stack are ignored. If the list overflows a long (max possible length
14667 34 bits) then completely leave off all elements that don't fit. */
14668 /* Only emit this long if there was at least one parameter. */
14669 if (fixed_parms || float_parms)
14670 fprintf (file, "\t.long %d\n", parm_info);
14671
14672 /* Offset from start of code to tb table. */
19d2d16f 14673 fputs ("\t.long ", file);
314fc5a9 14674 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
85b776df
AM
14675 if (TARGET_AIX)
14676 RS6000_OUTPUT_BASENAME (file, fname);
14677 else
14678 assemble_name (file, fname);
14679 putc ('-', file);
14680 rs6000_output_function_entry (file, fname);
19d2d16f 14681 putc ('\n', file);
314fc5a9
ILT
14682
14683 /* Interrupt handler mask. */
14684 /* Omit this long, since we never set the interrupt handler bit
14685 above. */
14686
14687 /* Number of CTL (controlled storage) anchors. */
14688 /* Omit this long, since the has_ctl bit is never set above. */
14689
14690 /* Displacement into stack of each CTL anchor. */
14691 /* Omit this list of longs, because there are no CTL anchors. */
14692
14693 /* Length of function name. */
69c75916
AM
14694 if (*fname == '*')
14695 ++fname;
296b8152 14696 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
14697
14698 /* Function name. */
14699 assemble_string (fname, strlen (fname));
14700
14701 /* Register for alloca automatic storage; this is always reg 31.
14702 Only emit this if the alloca bit was set above. */
14703 if (frame_pointer_needed)
19d2d16f 14704 fputs ("\t.byte 31\n", file);
b1765bde
DE
14705
14706 fputs ("\t.align 2\n", file);
9b30bae2 14707 }
9878760c 14708}
17167fd8 14709\f
a4f6c312
SS
14710/* A C compound statement that outputs the assembler code for a thunk
14711 function, used to implement C++ virtual function calls with
14712 multiple inheritance. The thunk acts as a wrapper around a virtual
14713 function, adjusting the implicit object parameter before handing
14714 control off to the real function.
14715
14716 First, emit code to add the integer DELTA to the location that
14717 contains the incoming first argument. Assume that this argument
14718 contains a pointer, and is the one used to pass the `this' pointer
14719 in C++. This is the incoming argument *before* the function
14720 prologue, e.g. `%o0' on a sparc. The addition must preserve the
14721 values of all other incoming arguments.
17167fd8
MM
14722
14723 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
14724 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
14725 not touch the return address. Hence returning from FUNCTION will
14726 return to whoever called the current `thunk'.
17167fd8 14727
a4f6c312
SS
14728 The effect must be as if FUNCTION had been called directly with the
14729 adjusted first argument. This macro is responsible for emitting
14730 all of the code for a thunk function; output_function_prologue()
14731 and output_function_epilogue() are not invoked.
17167fd8 14732
a4f6c312
SS
14733 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
14734 been extracted from it.) It might possibly be useful on some
14735 targets, but probably not.
17167fd8 14736
a4f6c312
SS
14737 If you do not define this macro, the target-independent code in the
14738 C++ frontend will generate a less efficient heavyweight thunk that
14739 calls FUNCTION instead of jumping to it. The generic approach does
14740 not support varargs. */
17167fd8 14741
3961e8fe 14742static void
f676971a
EC
14743rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
14744 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
a2369ed3 14745 tree function)
17167fd8 14746{
5b71a4e7 14747 rtx this, insn, funexp;
17167fd8 14748
5b71a4e7 14749 reload_completed = 1;
fe3ad572 14750 epilogue_completed = 1;
5b71a4e7 14751 no_new_pseudos = 1;
6429e3be 14752 reset_block_changes ();
56a7189a 14753
5b71a4e7 14754 /* Mark the end of the (empty) prologue. */
2e040219 14755 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 14756
5b71a4e7
DE
14757 /* Find the "this" pointer. If the function returns a structure,
14758 the structure return pointer is in r3. */
61f71b34 14759 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 14760 this = gen_rtx_REG (Pmode, 4);
56a7189a 14761 else
5b71a4e7 14762 this = gen_rtx_REG (Pmode, 3);
17167fd8 14763
5b71a4e7
DE
14764 /* Apply the constant offset, if required. */
14765 if (delta)
14766 {
14767 rtx delta_rtx = GEN_INT (delta);
14768 emit_insn (TARGET_32BIT
14769 ? gen_addsi3 (this, this, delta_rtx)
14770 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
14771 }
14772
5b71a4e7
DE
14773 /* Apply the offset from the vtable, if required. */
14774 if (vcall_offset)
17167fd8 14775 {
5b71a4e7
DE
14776 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
14777 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 14778
5b71a4e7 14779 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
14780 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
14781 {
14782 emit_insn (TARGET_32BIT
14783 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
14784 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
14785 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
14786 }
14787 else
14788 {
14789 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
14790
14791 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
14792 }
5b71a4e7
DE
14793 emit_insn (TARGET_32BIT
14794 ? gen_addsi3 (this, this, tmp)
14795 : gen_adddi3 (this, this, tmp));
17167fd8
MM
14796 }
14797
5b71a4e7
DE
14798 /* Generate a tail call to the target function. */
14799 if (!TREE_USED (function))
14800 {
14801 assemble_external (function);
14802 TREE_USED (function) = 1;
14803 }
14804 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 14805 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
14806
14807#if TARGET_MACHO
ab82a49f 14808 if (MACHOPIC_INDIRECT)
5b71a4e7 14809 funexp = machopic_indirect_call_target (funexp);
ee890fe2 14810#endif
5b71a4e7
DE
14811
14812 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
14813 generate sibcall RTL explicitly to avoid constraint abort. */
14814 insn = emit_call_insn (
14815 gen_rtx_PARALLEL (VOIDmode,
14816 gen_rtvec (4,
14817 gen_rtx_CALL (VOIDmode,
14818 funexp, const0_rtx),
14819 gen_rtx_USE (VOIDmode, const0_rtx),
14820 gen_rtx_USE (VOIDmode,
14821 gen_rtx_REG (SImode,
14822 LINK_REGISTER_REGNUM)),
14823 gen_rtx_RETURN (VOIDmode))));
14824 SIBLING_CALL_P (insn) = 1;
14825 emit_barrier ();
14826
14827 /* Run just enough of rest_of_compilation to get the insns emitted.
14828 There's not really enough bulk here to make other passes such as
14829 instruction scheduling worth while. Note that use_thunk calls
14830 assemble_start_function and assemble_end_function. */
14831 insn = get_insns ();
a2855205 14832 insn_locators_initialize ();
5b71a4e7
DE
14833 shorten_branches (insn);
14834 final_start_function (insn, file, 1);
14835 final (insn, file, 1, 0);
14836 final_end_function ();
14837
14838 reload_completed = 0;
fe3ad572 14839 epilogue_completed = 0;
5b71a4e7 14840 no_new_pseudos = 0;
9ebbca7d 14841}
9ebbca7d
GK
14842\f
14843/* A quick summary of the various types of 'constant-pool tables'
14844 under PowerPC:
14845
f676971a 14846 Target Flags Name One table per
9ebbca7d
GK
14847 AIX (none) AIX TOC object file
14848 AIX -mfull-toc AIX TOC object file
14849 AIX -mminimal-toc AIX minimal TOC translation unit
14850 SVR4/EABI (none) SVR4 SDATA object file
14851 SVR4/EABI -fpic SVR4 pic object file
14852 SVR4/EABI -fPIC SVR4 PIC translation unit
14853 SVR4/EABI -mrelocatable EABI TOC function
14854 SVR4/EABI -maix AIX TOC object file
f676971a 14855 SVR4/EABI -maix -mminimal-toc
9ebbca7d
GK
14856 AIX minimal TOC translation unit
14857
14858 Name Reg. Set by entries contains:
14859 made by addrs? fp? sum?
14860
14861 AIX TOC 2 crt0 as Y option option
14862 AIX minimal TOC 30 prolog gcc Y Y option
14863 SVR4 SDATA 13 crt0 gcc N Y N
14864 SVR4 pic 30 prolog ld Y not yet N
14865 SVR4 PIC 30 prolog gcc Y option option
14866 EABI TOC 30 prolog gcc Y option option
14867
14868*/
14869
9ebbca7d
GK
14870/* Hash functions for the hash table. */
14871
14872static unsigned
a2369ed3 14873rs6000_hash_constant (rtx k)
9ebbca7d 14874{
46b33600
RH
14875 enum rtx_code code = GET_CODE (k);
14876 enum machine_mode mode = GET_MODE (k);
14877 unsigned result = (code << 3) ^ mode;
14878 const char *format;
14879 int flen, fidx;
f676971a 14880
46b33600
RH
14881 format = GET_RTX_FORMAT (code);
14882 flen = strlen (format);
14883 fidx = 0;
9ebbca7d 14884
46b33600
RH
14885 switch (code)
14886 {
14887 case LABEL_REF:
14888 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
14889
14890 case CONST_DOUBLE:
14891 if (mode != VOIDmode)
14892 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
14893 flen = 2;
14894 break;
14895
14896 case CODE_LABEL:
14897 fidx = 3;
14898 break;
14899
14900 default:
14901 break;
14902 }
9ebbca7d
GK
14903
14904 for (; fidx < flen; fidx++)
14905 switch (format[fidx])
14906 {
14907 case 's':
14908 {
14909 unsigned i, len;
14910 const char *str = XSTR (k, fidx);
14911 len = strlen (str);
14912 result = result * 613 + len;
14913 for (i = 0; i < len; i++)
14914 result = result * 613 + (unsigned) str[i];
17167fd8
MM
14915 break;
14916 }
9ebbca7d
GK
14917 case 'u':
14918 case 'e':
14919 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
14920 break;
14921 case 'i':
14922 case 'n':
14923 result = result * 613 + (unsigned) XINT (k, fidx);
14924 break;
14925 case 'w':
14926 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
14927 result = result * 613 + (unsigned) XWINT (k, fidx);
14928 else
14929 {
14930 size_t i;
14931 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
14932 result = result * 613 + (unsigned) (XWINT (k, fidx)
14933 >> CHAR_BIT * i);
14934 }
14935 break;
09501938
DE
14936 case '0':
14937 break;
9ebbca7d 14938 default:
a4f6c312 14939 abort ();
9ebbca7d 14940 }
46b33600 14941
9ebbca7d
GK
14942 return result;
14943}
14944
14945static unsigned
a2369ed3 14946toc_hash_function (const void *hash_entry)
9ebbca7d 14947{
f676971a 14948 const struct toc_hash_struct *thc =
a9098fd0
GK
14949 (const struct toc_hash_struct *) hash_entry;
14950 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
14951}
14952
14953/* Compare H1 and H2 for equivalence. */
14954
14955static int
a2369ed3 14956toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
14957{
14958 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
14959 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
14960
a9098fd0
GK
14961 if (((const struct toc_hash_struct *) h1)->key_mode
14962 != ((const struct toc_hash_struct *) h2)->key_mode)
14963 return 0;
14964
5692c7bc 14965 return rtx_equal_p (r1, r2);
9ebbca7d
GK
14966}
14967
28e510bd
MM
14968/* These are the names given by the C++ front-end to vtables, and
14969 vtable-like objects. Ideally, this logic should not be here;
14970 instead, there should be some programmatic way of inquiring as
14971 to whether or not an object is a vtable. */
14972
14973#define VTABLE_NAME_P(NAME) \
14974 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
14975 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
14976 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 14977 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
f676971a 14978 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
28e510bd
MM
14979
14980void
a2369ed3 14981rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
14982{
14983 /* Currently C++ toc references to vtables can be emitted before it
14984 is decided whether the vtable is public or private. If this is
14985 the case, then the linker will eventually complain that there is
f676971a 14986 a reference to an unknown section. Thus, for vtables only,
28e510bd
MM
14987 we emit the TOC reference to reference the symbol and not the
14988 section. */
14989 const char *name = XSTR (x, 0);
54ee9799 14990
f676971a 14991 if (VTABLE_NAME_P (name))
54ee9799
DE
14992 {
14993 RS6000_OUTPUT_BASENAME (file, name);
14994 }
14995 else
14996 assemble_name (file, name);
28e510bd
MM
14997}
14998
a4f6c312
SS
14999/* Output a TOC entry. We derive the entry name from what is being
15000 written. */
9878760c
RK
15001
15002void
a2369ed3 15003output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
15004{
15005 char buf[256];
3cce094d 15006 const char *name = buf;
ec940faa 15007 const char *real_name;
9878760c
RK
15008 rtx base = x;
15009 int offset = 0;
15010
4697a36c
MM
15011 if (TARGET_NO_TOC)
15012 abort ();
15013
9ebbca7d
GK
15014 /* When the linker won't eliminate them, don't output duplicate
15015 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
15016 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
15017 CODE_LABELs. */
15018 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
15019 {
15020 struct toc_hash_struct *h;
15021 void * * found;
f676971a 15022
17211ab5 15023 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
c4ad648e 15024 time because GGC is not initialized at that point. */
17211ab5 15025 if (toc_hash_table == NULL)
f676971a 15026 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
17211ab5
GK
15027 toc_hash_eq, NULL);
15028
9ebbca7d
GK
15029 h = ggc_alloc (sizeof (*h));
15030 h->key = x;
a9098fd0 15031 h->key_mode = mode;
9ebbca7d 15032 h->labelno = labelno;
f676971a 15033
9ebbca7d
GK
15034 found = htab_find_slot (toc_hash_table, h, 1);
15035 if (*found == NULL)
15036 *found = h;
f676971a 15037 else /* This is indeed a duplicate.
9ebbca7d
GK
15038 Set this label equal to that label. */
15039 {
15040 fputs ("\t.set ", file);
15041 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
15042 fprintf (file, "%d,", labelno);
15043 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
f676971a 15044 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
9ebbca7d
GK
15045 found)->labelno));
15046 return;
15047 }
15048 }
15049
15050 /* If we're going to put a double constant in the TOC, make sure it's
15051 aligned properly when strict alignment is on. */
ff1720ed
RK
15052 if (GET_CODE (x) == CONST_DOUBLE
15053 && STRICT_ALIGNMENT
a9098fd0 15054 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
15055 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
15056 ASM_OUTPUT_ALIGN (file, 3);
15057 }
15058
4977bab6 15059 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 15060
37c37a57
RK
15061 /* Handle FP constants specially. Note that if we have a minimal
15062 TOC, things we put here aren't actually in the TOC, so we can allow
15063 FP constants. */
fcce224d
DE
15064 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
15065 {
15066 REAL_VALUE_TYPE rv;
15067 long k[4];
15068
15069 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15070 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
15071
15072 if (TARGET_64BIT)
15073 {
15074 if (TARGET_MINIMAL_TOC)
15075 fputs (DOUBLE_INT_ASM_OP, file);
15076 else
15077 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
15078 k[0] & 0xffffffff, k[1] & 0xffffffff,
15079 k[2] & 0xffffffff, k[3] & 0xffffffff);
15080 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
15081 k[0] & 0xffffffff, k[1] & 0xffffffff,
15082 k[2] & 0xffffffff, k[3] & 0xffffffff);
15083 return;
15084 }
15085 else
15086 {
15087 if (TARGET_MINIMAL_TOC)
15088 fputs ("\t.long ", file);
15089 else
15090 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
15091 k[0] & 0xffffffff, k[1] & 0xffffffff,
15092 k[2] & 0xffffffff, k[3] & 0xffffffff);
15093 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
15094 k[0] & 0xffffffff, k[1] & 0xffffffff,
15095 k[2] & 0xffffffff, k[3] & 0xffffffff);
15096 return;
15097 }
15098 }
15099 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 15100 {
042259f2
DE
15101 REAL_VALUE_TYPE rv;
15102 long k[2];
0adc764e 15103
042259f2
DE
15104 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15105 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 15106
13ded975
DE
15107 if (TARGET_64BIT)
15108 {
15109 if (TARGET_MINIMAL_TOC)
2bfcf297 15110 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 15111 else
2f0552b6
AM
15112 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
15113 k[0] & 0xffffffff, k[1] & 0xffffffff);
15114 fprintf (file, "0x%lx%08lx\n",
15115 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
15116 return;
15117 }
1875cc88 15118 else
13ded975
DE
15119 {
15120 if (TARGET_MINIMAL_TOC)
2bfcf297 15121 fputs ("\t.long ", file);
13ded975 15122 else
2f0552b6
AM
15123 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
15124 k[0] & 0xffffffff, k[1] & 0xffffffff);
15125 fprintf (file, "0x%lx,0x%lx\n",
15126 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
15127 return;
15128 }
9878760c 15129 }
a9098fd0 15130 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 15131 {
042259f2
DE
15132 REAL_VALUE_TYPE rv;
15133 long l;
9878760c 15134
042259f2
DE
15135 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15136 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
15137
31bfaa0b
DE
15138 if (TARGET_64BIT)
15139 {
15140 if (TARGET_MINIMAL_TOC)
2bfcf297 15141 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 15142 else
2f0552b6
AM
15143 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
15144 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
15145 return;
15146 }
042259f2 15147 else
31bfaa0b
DE
15148 {
15149 if (TARGET_MINIMAL_TOC)
2bfcf297 15150 fputs ("\t.long ", file);
31bfaa0b 15151 else
2f0552b6
AM
15152 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
15153 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
15154 return;
15155 }
042259f2 15156 }
f176e826 15157 else if (GET_MODE (x) == VOIDmode
a9098fd0 15158 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 15159 {
e2c953b6 15160 unsigned HOST_WIDE_INT low;
042259f2
DE
15161 HOST_WIDE_INT high;
15162
15163 if (GET_CODE (x) == CONST_DOUBLE)
15164 {
15165 low = CONST_DOUBLE_LOW (x);
15166 high = CONST_DOUBLE_HIGH (x);
15167 }
15168 else
15169#if HOST_BITS_PER_WIDE_INT == 32
15170 {
15171 low = INTVAL (x);
0858c623 15172 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
15173 }
15174#else
15175 {
c4ad648e
AM
15176 low = INTVAL (x) & 0xffffffff;
15177 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
042259f2
DE
15178 }
15179#endif
9878760c 15180
a9098fd0
GK
15181 /* TOC entries are always Pmode-sized, but since this
15182 is a bigendian machine then if we're putting smaller
15183 integer constants in the TOC we have to pad them.
15184 (This is still a win over putting the constants in
15185 a separate constant pool, because then we'd have
02a4ec28
FS
15186 to have both a TOC entry _and_ the actual constant.)
15187
15188 For a 32-bit target, CONST_INT values are loaded and shifted
15189 entirely within `low' and can be stored in one TOC entry. */
15190
15191 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 15192 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
15193
15194 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
15195 {
15196#if HOST_BITS_PER_WIDE_INT == 32
15197 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
15198 POINTER_SIZE, &low, &high, 0);
15199#else
15200 low |= high << 32;
15201 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
15202 high = (HOST_WIDE_INT) low >> 32;
15203 low &= 0xffffffff;
15204#endif
15205 }
a9098fd0 15206
13ded975
DE
15207 if (TARGET_64BIT)
15208 {
15209 if (TARGET_MINIMAL_TOC)
2bfcf297 15210 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 15211 else
2f0552b6
AM
15212 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
15213 (long) high & 0xffffffff, (long) low & 0xffffffff);
15214 fprintf (file, "0x%lx%08lx\n",
15215 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
15216 return;
15217 }
1875cc88 15218 else
13ded975 15219 {
02a4ec28
FS
15220 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
15221 {
15222 if (TARGET_MINIMAL_TOC)
2bfcf297 15223 fputs ("\t.long ", file);
02a4ec28 15224 else
2bfcf297 15225 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
15226 (long) high & 0xffffffff, (long) low & 0xffffffff);
15227 fprintf (file, "0x%lx,0x%lx\n",
15228 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 15229 }
13ded975 15230 else
02a4ec28
FS
15231 {
15232 if (TARGET_MINIMAL_TOC)
2bfcf297 15233 fputs ("\t.long ", file);
02a4ec28 15234 else
2f0552b6
AM
15235 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
15236 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 15237 }
13ded975
DE
15238 return;
15239 }
9878760c
RK
15240 }
15241
15242 if (GET_CODE (x) == CONST)
15243 {
2bfcf297
DB
15244 if (GET_CODE (XEXP (x, 0)) != PLUS)
15245 abort ();
15246
9878760c
RK
15247 base = XEXP (XEXP (x, 0), 0);
15248 offset = INTVAL (XEXP (XEXP (x, 0), 1));
15249 }
f676971a 15250
9878760c
RK
15251 if (GET_CODE (base) == SYMBOL_REF)
15252 name = XSTR (base, 0);
15253 else if (GET_CODE (base) == LABEL_REF)
15254 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
15255 else if (GET_CODE (base) == CODE_LABEL)
15256 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
15257 else
15258 abort ();
15259
772c5265 15260 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 15261 if (TARGET_MINIMAL_TOC)
2bfcf297 15262 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
15263 else
15264 {
b6c9286a 15265 fprintf (file, "\t.tc %s", real_name);
9878760c 15266
1875cc88
JW
15267 if (offset < 0)
15268 fprintf (file, ".N%d", - offset);
15269 else if (offset)
15270 fprintf (file, ".P%d", offset);
9878760c 15271
19d2d16f 15272 fputs ("[TC],", file);
1875cc88 15273 }
581bc4de
MM
15274
15275 /* Currently C++ toc references to vtables can be emitted before it
15276 is decided whether the vtable is public or private. If this is
15277 the case, then the linker will eventually complain that there is
15278 a TOC reference to an unknown section. Thus, for vtables only,
15279 we emit the TOC reference to reference the symbol and not the
15280 section. */
28e510bd 15281 if (VTABLE_NAME_P (name))
581bc4de 15282 {
54ee9799 15283 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
15284 if (offset < 0)
15285 fprintf (file, "%d", offset);
15286 else if (offset > 0)
15287 fprintf (file, "+%d", offset);
15288 }
15289 else
15290 output_addr_const (file, x);
19d2d16f 15291 putc ('\n', file);
9878760c
RK
15292}
15293\f
15294/* Output an assembler pseudo-op to write an ASCII string of N characters
15295 starting at P to FILE.
15296
15297 On the RS/6000, we have to do this using the .byte operation and
15298 write out special characters outside the quoted string.
15299 Also, the assembler is broken; very long strings are truncated,
a4f6c312 15300 so we must artificially break them up early. */
9878760c
RK
15301
15302void
a2369ed3 15303output_ascii (FILE *file, const char *p, int n)
9878760c
RK
15304{
15305 char c;
15306 int i, count_string;
d330fd93
KG
15307 const char *for_string = "\t.byte \"";
15308 const char *for_decimal = "\t.byte ";
15309 const char *to_close = NULL;
9878760c
RK
15310
15311 count_string = 0;
15312 for (i = 0; i < n; i++)
15313 {
15314 c = *p++;
15315 if (c >= ' ' && c < 0177)
15316 {
15317 if (for_string)
15318 fputs (for_string, file);
15319 putc (c, file);
15320
15321 /* Write two quotes to get one. */
15322 if (c == '"')
15323 {
15324 putc (c, file);
15325 ++count_string;
15326 }
15327
15328 for_string = NULL;
15329 for_decimal = "\"\n\t.byte ";
15330 to_close = "\"\n";
15331 ++count_string;
15332
15333 if (count_string >= 512)
15334 {
15335 fputs (to_close, file);
15336
15337 for_string = "\t.byte \"";
15338 for_decimal = "\t.byte ";
15339 to_close = NULL;
15340 count_string = 0;
15341 }
15342 }
15343 else
15344 {
15345 if (for_decimal)
15346 fputs (for_decimal, file);
15347 fprintf (file, "%d", c);
15348
15349 for_string = "\n\t.byte \"";
15350 for_decimal = ", ";
15351 to_close = "\n";
15352 count_string = 0;
15353 }
15354 }
15355
15356 /* Now close the string if we have written one. Then end the line. */
15357 if (to_close)
9ebbca7d 15358 fputs (to_close, file);
9878760c
RK
15359}
15360\f
15361/* Generate a unique section name for FILENAME for a section type
15362 represented by SECTION_DESC. Output goes into BUF.
15363
15364 SECTION_DESC can be any string, as long as it is different for each
15365 possible section type.
15366
15367 We name the section in the same manner as xlc. The name begins with an
15368 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
15369 names) with the last period replaced by the string SECTION_DESC. If
15370 FILENAME does not contain a period, SECTION_DESC is appended to the end of
15371 the name. */
9878760c
RK
15372
15373void
f676971a 15374rs6000_gen_section_name (char **buf, const char *filename,
c4ad648e 15375 const char *section_desc)
9878760c 15376{
9ebbca7d 15377 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
15378 char *p;
15379 int len;
9878760c
RK
15380
15381 after_last_slash = filename;
15382 for (q = filename; *q; q++)
11e5fe42
RK
15383 {
15384 if (*q == '/')
15385 after_last_slash = q + 1;
15386 else if (*q == '.')
15387 last_period = q;
15388 }
9878760c 15389
11e5fe42 15390 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 15391 *buf = (char *) xmalloc (len);
9878760c
RK
15392
15393 p = *buf;
15394 *p++ = '_';
15395
15396 for (q = after_last_slash; *q; q++)
15397 {
11e5fe42 15398 if (q == last_period)
c4ad648e 15399 {
9878760c
RK
15400 strcpy (p, section_desc);
15401 p += strlen (section_desc);
e3981aab 15402 break;
c4ad648e 15403 }
9878760c 15404
e9a780ec 15405 else if (ISALNUM (*q))
c4ad648e 15406 *p++ = *q;
9878760c
RK
15407 }
15408
11e5fe42 15409 if (last_period == 0)
9878760c
RK
15410 strcpy (p, section_desc);
15411 else
15412 *p = '\0';
15413}
e165f3f0 15414\f
a4f6c312 15415/* Emit profile function. */
411707f4 15416
411707f4 15417void
a2369ed3 15418output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 15419{
ffcfcb5f
AM
15420 if (TARGET_PROFILE_KERNEL)
15421 return;
15422
8480e480
CC
15423 if (DEFAULT_ABI == ABI_AIX)
15424 {
9739c90c
JJ
15425#ifndef NO_PROFILE_COUNTERS
15426# define NO_PROFILE_COUNTERS 0
15427#endif
f676971a 15428 if (NO_PROFILE_COUNTERS)
9739c90c
JJ
15429 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
15430 else
15431 {
15432 char buf[30];
15433 const char *label_name;
15434 rtx fun;
411707f4 15435
9739c90c
JJ
15436 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
15437 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
15438 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 15439
9739c90c
JJ
15440 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
15441 fun, Pmode);
15442 }
8480e480 15443 }
ee890fe2
SS
15444 else if (DEFAULT_ABI == ABI_DARWIN)
15445 {
d5fa86ba 15446 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
15447 int caller_addr_regno = LINK_REGISTER_REGNUM;
15448
15449 /* Be conservative and always set this, at least for now. */
15450 current_function_uses_pic_offset_table = 1;
15451
15452#if TARGET_MACHO
15453 /* For PIC code, set up a stub and collect the caller's address
15454 from r0, which is where the prologue puts it. */
11abc112
MM
15455 if (MACHOPIC_INDIRECT
15456 && current_function_uses_pic_offset_table)
15457 caller_addr_regno = 0;
ee890fe2
SS
15458#endif
15459 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
15460 0, VOIDmode, 1,
15461 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
15462 }
411707f4
CC
15463}
15464
a4f6c312 15465/* Write function profiler code. */
e165f3f0
RK
15466
15467void
a2369ed3 15468output_function_profiler (FILE *file, int labelno)
e165f3f0 15469{
3daf36a4 15470 char buf[100];
09eeeacb 15471 int save_lr = 8;
e165f3f0 15472
38c1f2d7 15473 switch (DEFAULT_ABI)
3daf36a4 15474 {
38c1f2d7
MM
15475 default:
15476 abort ();
15477
15478 case ABI_V4:
09eeeacb 15479 save_lr = 4;
09eeeacb
AM
15480 if (!TARGET_32BIT)
15481 {
15482 warning ("no profiling of 64-bit code for this ABI");
15483 return;
15484 }
ffcfcb5f 15485 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
15486 fprintf (file, "\tmflr %s\n", reg_names[0]);
15487 if (flag_pic == 1)
15488 {
dfdfa60f 15489 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
15490 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15491 reg_names[0], save_lr, reg_names[1]);
17167fd8 15492 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 15493 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 15494 assemble_name (file, buf);
17167fd8 15495 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 15496 }
9ebbca7d 15497 else if (flag_pic > 1)
38c1f2d7 15498 {
09eeeacb
AM
15499 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15500 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
15501 /* Now, we need to get the address of the label. */
15502 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 15503 assemble_name (file, buf);
9ebbca7d
GK
15504 fputs ("-.\n1:", file);
15505 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
f676971a 15506 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
9ebbca7d
GK
15507 reg_names[0], reg_names[11]);
15508 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
15509 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 15510 }
38c1f2d7
MM
15511 else
15512 {
17167fd8 15513 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 15514 assemble_name (file, buf);
dfdfa60f 15515 fputs ("@ha\n", file);
09eeeacb
AM
15516 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15517 reg_names[0], save_lr, reg_names[1]);
a260abc9 15518 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 15519 assemble_name (file, buf);
17167fd8 15520 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
15521 }
15522
50d440bc 15523 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
15524 fprintf (file, "\tbl %s%s\n",
15525 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
15526 break;
15527
15528 case ABI_AIX:
ee890fe2 15529 case ABI_DARWIN:
ffcfcb5f
AM
15530 if (!TARGET_PROFILE_KERNEL)
15531 {
a3c9585f 15532 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
15533 }
15534 else
15535 {
15536 if (TARGET_32BIT)
15537 abort ();
15538
15539 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
15540 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
15541
6de9cd9a 15542 if (cfun->static_chain_decl != NULL)
ffcfcb5f
AM
15543 {
15544 asm_fprintf (file, "\tstd %s,24(%s)\n",
15545 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15546 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15547 asm_fprintf (file, "\tld %s,24(%s)\n",
15548 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15549 }
15550 else
15551 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15552 }
38c1f2d7
MM
15553 break;
15554 }
e165f3f0 15555}
a251ffd0 15556
b54cf83a 15557\f
b54cf83a
DE
15558/* Power4 load update and store update instructions are cracked into a
15559 load or store and an integer insn which are executed in the same cycle.
15560 Branches have their own dispatch slot which does not count against the
15561 GCC issue rate, but it changes the program flow so there are no other
15562 instructions to issue in this cycle. */
15563
15564static int
f676971a
EC
15565rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
15566 int verbose ATTRIBUTE_UNUSED,
a2369ed3 15567 rtx insn, int more)
b54cf83a
DE
15568{
15569 if (GET_CODE (PATTERN (insn)) == USE
15570 || GET_CODE (PATTERN (insn)) == CLOBBER)
15571 return more;
15572
ec507f2d 15573 if (rs6000_sched_groups)
b54cf83a 15574 {
cbe26ab8 15575 if (is_microcoded_insn (insn))
c4ad648e 15576 return 0;
cbe26ab8 15577 else if (is_cracked_insn (insn))
c4ad648e 15578 return more > 2 ? more - 2 : 0;
b54cf83a 15579 }
165b263e
DE
15580
15581 return more - 1;
b54cf83a
DE
15582}
15583
a251ffd0
TG
15584/* Adjust the cost of a scheduling dependency. Return the new cost of
15585 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
15586
c237e94a 15587static int
0a4f0294 15588rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
a251ffd0
TG
15589{
15590 if (! recog_memoized (insn))
15591 return 0;
15592
15593 if (REG_NOTE_KIND (link) != 0)
15594 return 0;
15595
15596 if (REG_NOTE_KIND (link) == 0)
15597 {
ed947a96
DJ
15598 /* Data dependency; DEP_INSN writes a register that INSN reads
15599 some cycles later. */
15600 switch (get_attr_type (insn))
15601 {
15602 case TYPE_JMPREG:
309323c2 15603 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
15604 a mtctr and bctr (and mtlr and br/blr). The first
15605 scheduling pass will not know about this latency since
15606 the mtctr instruction, which has the latency associated
15607 to it, will be generated by reload. */
309323c2 15608 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
15609 case TYPE_BRANCH:
15610 /* Leave some extra cycles between a compare and its
15611 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
15612 if ((rs6000_cpu_attr == CPU_PPC603
15613 || rs6000_cpu_attr == CPU_PPC604
15614 || rs6000_cpu_attr == CPU_PPC604E
15615 || rs6000_cpu_attr == CPU_PPC620
15616 || rs6000_cpu_attr == CPU_PPC630
15617 || rs6000_cpu_attr == CPU_PPC750
15618 || rs6000_cpu_attr == CPU_PPC7400
15619 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
15620 || rs6000_cpu_attr == CPU_POWER4
15621 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
15622 && recog_memoized (dep_insn)
15623 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
15624 && (get_attr_type (dep_insn) == TYPE_CMP
15625 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 15626 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
15627 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
15628 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 15629 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
15630 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
15631 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
15632 return cost + 2;
15633 default:
15634 break;
15635 }
a251ffd0
TG
15636 /* Fall out to return default cost. */
15637 }
15638
15639 return cost;
15640}
b6c9286a 15641
cbe26ab8 15642/* The function returns a true if INSN is microcoded.
839a4992 15643 Return false otherwise. */
cbe26ab8
DN
15644
15645static bool
15646is_microcoded_insn (rtx insn)
15647{
15648 if (!insn || !INSN_P (insn)
15649 || GET_CODE (PATTERN (insn)) == USE
15650 || GET_CODE (PATTERN (insn)) == CLOBBER)
15651 return false;
15652
ec507f2d 15653 if (rs6000_sched_groups)
cbe26ab8
DN
15654 {
15655 enum attr_type type = get_attr_type (insn);
15656 if (type == TYPE_LOAD_EXT_U
15657 || type == TYPE_LOAD_EXT_UX
15658 || type == TYPE_LOAD_UX
15659 || type == TYPE_STORE_UX
15660 || type == TYPE_MFCR)
c4ad648e 15661 return true;
cbe26ab8
DN
15662 }
15663
15664 return false;
15665}
15666
5c425df5 15667/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
15668 as the first insn in a dispatch group ("dispatch-slot restricted").
15669 In this case, the returned value indicates how many dispatch slots
15670 the insn occupies (at the beginning of the group).
79ae11c4
DN
15671 Return 0 otherwise. */
15672
cbe26ab8 15673static int
79ae11c4
DN
15674is_dispatch_slot_restricted (rtx insn)
15675{
15676 enum attr_type type;
15677
ec507f2d 15678 if (!rs6000_sched_groups)
79ae11c4
DN
15679 return 0;
15680
15681 if (!insn
15682 || insn == NULL_RTX
15683 || GET_CODE (insn) == NOTE
15684 || GET_CODE (PATTERN (insn)) == USE
15685 || GET_CODE (PATTERN (insn)) == CLOBBER)
15686 return 0;
15687
15688 type = get_attr_type (insn);
15689
ec507f2d
DE
15690 switch (type)
15691 {
15692 case TYPE_MFCR:
15693 case TYPE_MFCRF:
15694 case TYPE_MTCR:
15695 case TYPE_DELAYED_CR:
15696 case TYPE_CR_LOGICAL:
15697 case TYPE_MTJMPR:
15698 case TYPE_MFJMPR:
15699 return 1;
15700 case TYPE_IDIV:
15701 case TYPE_LDIV:
15702 return 2;
15703 default:
15704 if (rs6000_cpu == PROCESSOR_POWER5
15705 && is_cracked_insn (insn))
15706 return 2;
15707 return 0;
15708 }
79ae11c4
DN
15709}
15710
cbe26ab8
DN
15711/* The function returns true if INSN is cracked into 2 instructions
15712 by the processor (and therefore occupies 2 issue slots). */
15713
15714static bool
15715is_cracked_insn (rtx insn)
15716{
15717 if (!insn || !INSN_P (insn)
15718 || GET_CODE (PATTERN (insn)) == USE
15719 || GET_CODE (PATTERN (insn)) == CLOBBER)
15720 return false;
15721
ec507f2d 15722 if (rs6000_sched_groups)
cbe26ab8
DN
15723 {
15724 enum attr_type type = get_attr_type (insn);
15725 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
c4ad648e
AM
15726 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
15727 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
15728 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
15729 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
15730 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
15731 || type == TYPE_IDIV || type == TYPE_LDIV
15732 || type == TYPE_INSERT_WORD)
15733 return true;
cbe26ab8
DN
15734 }
15735
15736 return false;
15737}
15738
15739/* The function returns true if INSN can be issued only from
a3c9585f 15740 the branch slot. */
cbe26ab8
DN
15741
15742static bool
15743is_branch_slot_insn (rtx insn)
15744{
15745 if (!insn || !INSN_P (insn)
15746 || GET_CODE (PATTERN (insn)) == USE
15747 || GET_CODE (PATTERN (insn)) == CLOBBER)
15748 return false;
15749
ec507f2d 15750 if (rs6000_sched_groups)
cbe26ab8
DN
15751 {
15752 enum attr_type type = get_attr_type (insn);
15753 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
f676971a 15754 return true;
cbe26ab8
DN
15755 return false;
15756 }
15757
15758 return false;
15759}
79ae11c4 15760
a4f6c312 15761/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
15762 priority INSN_PRIORITY (INSN). Increase the priority to execute the
15763 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
15764 define this macro if you do not need to adjust the scheduling
15765 priorities of insns. */
bef84347 15766
c237e94a 15767static int
a2369ed3 15768rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 15769{
a4f6c312
SS
15770 /* On machines (like the 750) which have asymmetric integer units,
15771 where one integer unit can do multiply and divides and the other
15772 can't, reduce the priority of multiply/divide so it is scheduled
15773 before other integer operations. */
bef84347
VM
15774
15775#if 0
2c3c49de 15776 if (! INSN_P (insn))
bef84347
VM
15777 return priority;
15778
15779 if (GET_CODE (PATTERN (insn)) == USE)
15780 return priority;
15781
15782 switch (rs6000_cpu_attr) {
15783 case CPU_PPC750:
15784 switch (get_attr_type (insn))
15785 {
15786 default:
15787 break;
15788
15789 case TYPE_IMUL:
15790 case TYPE_IDIV:
3cb999d8
DE
15791 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
15792 priority, priority);
bef84347
VM
15793 if (priority >= 0 && priority < 0x01000000)
15794 priority >>= 3;
15795 break;
15796 }
15797 }
15798#endif
15799
79ae11c4
DN
15800 if (is_dispatch_slot_restricted (insn)
15801 && reload_completed
f676971a 15802 && current_sched_info->sched_max_insns_priority
79ae11c4
DN
15803 && rs6000_sched_restricted_insns_priority)
15804 {
15805
c4ad648e
AM
15806 /* Prioritize insns that can be dispatched only in the first
15807 dispatch slot. */
79ae11c4 15808 if (rs6000_sched_restricted_insns_priority == 1)
f676971a
EC
15809 /* Attach highest priority to insn. This means that in
15810 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
79ae11c4 15811 precede 'priority' (critical path) considerations. */
f676971a 15812 return current_sched_info->sched_max_insns_priority;
79ae11c4 15813 else if (rs6000_sched_restricted_insns_priority == 2)
f676971a 15814 /* Increase priority of insn by a minimal amount. This means that in
c4ad648e
AM
15815 haifa-sched.c:ready_sort(), only 'priority' (critical path)
15816 considerations precede dispatch-slot restriction considerations. */
f676971a
EC
15817 return (priority + 1);
15818 }
79ae11c4 15819
bef84347
VM
15820 return priority;
15821}
15822
a4f6c312
SS
15823/* Return how many instructions the machine can issue per cycle. */
15824
c237e94a 15825static int
863d938c 15826rs6000_issue_rate (void)
b6c9286a 15827{
3317bab1
DE
15828 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
15829 if (!reload_completed)
15830 return 1;
15831
b6c9286a 15832 switch (rs6000_cpu_attr) {
3cb999d8
DE
15833 case CPU_RIOS1: /* ? */
15834 case CPU_RS64A:
15835 case CPU_PPC601: /* ? */
ed947a96 15836 case CPU_PPC7450:
3cb999d8 15837 return 3;
b54cf83a 15838 case CPU_PPC440:
b6c9286a 15839 case CPU_PPC603:
bef84347 15840 case CPU_PPC750:
ed947a96 15841 case CPU_PPC7400:
be12c2b0 15842 case CPU_PPC8540:
f676971a 15843 return 2;
3cb999d8 15844 case CPU_RIOS2:
b6c9286a 15845 case CPU_PPC604:
19684119 15846 case CPU_PPC604E:
b6c9286a 15847 case CPU_PPC620:
3cb999d8 15848 case CPU_PPC630:
b6c9286a 15849 return 4;
cbe26ab8 15850 case CPU_POWER4:
ec507f2d 15851 case CPU_POWER5:
cbe26ab8 15852 return 5;
b6c9286a
MM
15853 default:
15854 return 1;
15855 }
15856}
15857
be12c2b0
VM
15858/* Return how many instructions to look ahead for better insn
15859 scheduling. */
15860
15861static int
863d938c 15862rs6000_use_sched_lookahead (void)
be12c2b0
VM
15863{
15864 if (rs6000_cpu_attr == CPU_PPC8540)
15865 return 4;
15866 return 0;
15867}
15868
569fa502
DN
15869/* Determine is PAT refers to memory. */
15870
15871static bool
15872is_mem_ref (rtx pat)
15873{
15874 const char * fmt;
15875 int i, j;
15876 bool ret = false;
15877
15878 if (GET_CODE (pat) == MEM)
15879 return true;
15880
15881 /* Recursively process the pattern. */
15882 fmt = GET_RTX_FORMAT (GET_CODE (pat));
15883
15884 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
15885 {
15886 if (fmt[i] == 'e')
15887 ret |= is_mem_ref (XEXP (pat, i));
15888 else if (fmt[i] == 'E')
15889 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
15890 ret |= is_mem_ref (XVECEXP (pat, i, j));
15891 }
15892
15893 return ret;
15894}
15895
15896/* Determine if PAT is a PATTERN of a load insn. */
f676971a 15897
569fa502
DN
15898static bool
15899is_load_insn1 (rtx pat)
15900{
15901 if (!pat || pat == NULL_RTX)
15902 return false;
15903
15904 if (GET_CODE (pat) == SET)
15905 return is_mem_ref (SET_SRC (pat));
15906
15907 if (GET_CODE (pat) == PARALLEL)
15908 {
15909 int i;
15910
15911 for (i = 0; i < XVECLEN (pat, 0); i++)
15912 if (is_load_insn1 (XVECEXP (pat, 0, i)))
15913 return true;
15914 }
15915
15916 return false;
15917}
15918
15919/* Determine if INSN loads from memory. */
15920
15921static bool
15922is_load_insn (rtx insn)
15923{
15924 if (!insn || !INSN_P (insn))
15925 return false;
15926
15927 if (GET_CODE (insn) == CALL_INSN)
15928 return false;
15929
15930 return is_load_insn1 (PATTERN (insn));
15931}
15932
15933/* Determine if PAT is a PATTERN of a store insn. */
15934
15935static bool
15936is_store_insn1 (rtx pat)
15937{
15938 if (!pat || pat == NULL_RTX)
15939 return false;
15940
15941 if (GET_CODE (pat) == SET)
15942 return is_mem_ref (SET_DEST (pat));
15943
15944 if (GET_CODE (pat) == PARALLEL)
15945 {
15946 int i;
15947
15948 for (i = 0; i < XVECLEN (pat, 0); i++)
15949 if (is_store_insn1 (XVECEXP (pat, 0, i)))
15950 return true;
15951 }
15952
15953 return false;
15954}
15955
15956/* Determine if INSN stores to memory. */
15957
15958static bool
15959is_store_insn (rtx insn)
15960{
15961 if (!insn || !INSN_P (insn))
15962 return false;
15963
15964 return is_store_insn1 (PATTERN (insn));
15965}
15966
15967/* Returns whether the dependence between INSN and NEXT is considered
15968 costly by the given target. */
15969
15970static bool
c4ad648e
AM
15971rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost,
15972 int distance)
f676971a 15973{
569fa502 15974 /* If the flag is not enbled - no dependence is considered costly;
f676971a 15975 allow all dependent insns in the same group.
569fa502
DN
15976 This is the most aggressive option. */
15977 if (rs6000_sched_costly_dep == no_dep_costly)
15978 return false;
15979
f676971a 15980 /* If the flag is set to 1 - a dependence is always considered costly;
569fa502
DN
15981 do not allow dependent instructions in the same group.
15982 This is the most conservative option. */
15983 if (rs6000_sched_costly_dep == all_deps_costly)
f676971a 15984 return true;
569fa502 15985
f676971a
EC
15986 if (rs6000_sched_costly_dep == store_to_load_dep_costly
15987 && is_load_insn (next)
569fa502
DN
15988 && is_store_insn (insn))
15989 /* Prevent load after store in the same group. */
15990 return true;
15991
15992 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
f676971a 15993 && is_load_insn (next)
569fa502
DN
15994 && is_store_insn (insn)
15995 && (!link || (int) REG_NOTE_KIND (link) == 0))
c4ad648e
AM
15996 /* Prevent load after store in the same group if it is a true
15997 dependence. */
569fa502 15998 return true;
f676971a
EC
15999
16000 /* The flag is set to X; dependences with latency >= X are considered costly,
569fa502
DN
16001 and will not be scheduled in the same group. */
16002 if (rs6000_sched_costly_dep <= max_dep_latency
16003 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
16004 return true;
16005
16006 return false;
16007}
16008
f676971a 16009/* Return the next insn after INSN that is found before TAIL is reached,
cbe26ab8
DN
16010 skipping any "non-active" insns - insns that will not actually occupy
16011 an issue slot. Return NULL_RTX if such an insn is not found. */
16012
16013static rtx
16014get_next_active_insn (rtx insn, rtx tail)
16015{
16016 rtx next_insn;
16017
16018 if (!insn || insn == tail)
16019 return NULL_RTX;
16020
16021 next_insn = NEXT_INSN (insn);
16022
16023 while (next_insn
16024 && next_insn != tail
16025 && (GET_CODE(next_insn) == NOTE
16026 || GET_CODE (PATTERN (next_insn)) == USE
16027 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
16028 {
16029 next_insn = NEXT_INSN (next_insn);
16030 }
16031
16032 if (!next_insn || next_insn == tail)
16033 return NULL_RTX;
16034
16035 return next_insn;
16036}
16037
839a4992 16038/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
16039 of group WHICH_GROUP.
16040
16041 If WHICH_GROUP == current_group, this function will return true if INSN
16042 causes the termination of the current group (i.e, the dispatch group to
16043 which INSN belongs). This means that INSN will be the last insn in the
16044 group it belongs to.
16045
16046 If WHICH_GROUP == previous_group, this function will return true if INSN
16047 causes the termination of the previous group (i.e, the dispatch group that
16048 precedes the group to which INSN belongs). This means that INSN will be
16049 the first insn in the group it belongs to). */
16050
16051static bool
16052insn_terminates_group_p (rtx insn, enum group_termination which_group)
16053{
16054 enum attr_type type;
16055
16056 if (! insn)
16057 return false;
569fa502 16058
cbe26ab8
DN
16059 type = get_attr_type (insn);
16060
16061 if (is_microcoded_insn (insn))
16062 return true;
16063
16064 if (which_group == current_group)
16065 {
16066 if (is_branch_slot_insn (insn))
c4ad648e 16067 return true;
cbe26ab8
DN
16068 return false;
16069 }
16070 else if (which_group == previous_group)
16071 {
16072 if (is_dispatch_slot_restricted (insn))
c4ad648e 16073 return true;
cbe26ab8
DN
16074 return false;
16075 }
16076
16077 return false;
16078}
16079
839a4992 16080/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
16081 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
16082
16083static bool
16084is_costly_group (rtx *group_insns, rtx next_insn)
16085{
16086 int i;
16087 rtx link;
16088 int cost;
16089 int issue_rate = rs6000_issue_rate ();
16090
16091 for (i = 0; i < issue_rate; i++)
16092 {
16093 rtx insn = group_insns[i];
16094 if (!insn)
c4ad648e 16095 continue;
cbe26ab8 16096 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
c4ad648e
AM
16097 {
16098 rtx next = XEXP (link, 0);
16099 if (next == next_insn)
16100 {
16101 cost = insn_cost (insn, link, next_insn);
16102 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
16103 return true;
16104 }
16105 }
cbe26ab8
DN
16106 }
16107
16108 return false;
16109}
16110
f676971a 16111/* Utility of the function redefine_groups.
cbe26ab8
DN
16112 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
16113 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
16114 to keep it "far" (in a separate group) from GROUP_INSNS, following
16115 one of the following schemes, depending on the value of the flag
16116 -minsert_sched_nops = X:
16117 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 16118 in order to force NEXT_INSN into a separate group.
f676971a
EC
16119 (2) X < sched_finish_regroup_exact: insert exactly X nops.
16120 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
cbe26ab8
DN
16121 insertion (has a group just ended, how many vacant issue slots remain in the
16122 last group, and how many dispatch groups were encountered so far). */
16123
f676971a 16124static int
c4ad648e
AM
16125force_new_group (int sched_verbose, FILE *dump, rtx *group_insns,
16126 rtx next_insn, bool *group_end, int can_issue_more,
16127 int *group_count)
cbe26ab8
DN
16128{
16129 rtx nop;
16130 bool force;
16131 int issue_rate = rs6000_issue_rate ();
16132 bool end = *group_end;
16133 int i;
16134
16135 if (next_insn == NULL_RTX)
16136 return can_issue_more;
16137
16138 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
16139 return can_issue_more;
16140
16141 force = is_costly_group (group_insns, next_insn);
16142 if (!force)
16143 return can_issue_more;
16144
16145 if (sched_verbose > 6)
16146 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
c4ad648e 16147 *group_count ,can_issue_more);
cbe26ab8
DN
16148
16149 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
16150 {
16151 if (*group_end)
c4ad648e 16152 can_issue_more = 0;
cbe26ab8
DN
16153
16154 /* Since only a branch can be issued in the last issue_slot, it is
16155 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
16156 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
c4ad648e
AM
16157 in this case the last nop will start a new group and the branch
16158 will be forced to the new group. */
cbe26ab8 16159 if (can_issue_more && !is_branch_slot_insn (next_insn))
c4ad648e 16160 can_issue_more--;
cbe26ab8
DN
16161
16162 while (can_issue_more > 0)
c4ad648e
AM
16163 {
16164 nop = gen_nop();
16165 emit_insn_before (nop, next_insn);
16166 can_issue_more--;
16167 }
cbe26ab8
DN
16168
16169 *group_end = true;
16170 return 0;
f676971a 16171 }
cbe26ab8
DN
16172
16173 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
16174 {
16175 int n_nops = rs6000_sched_insert_nops;
16176
f676971a 16177 /* Nops can't be issued from the branch slot, so the effective
c4ad648e 16178 issue_rate for nops is 'issue_rate - 1'. */
cbe26ab8 16179 if (can_issue_more == 0)
c4ad648e 16180 can_issue_more = issue_rate;
cbe26ab8
DN
16181 can_issue_more--;
16182 if (can_issue_more == 0)
c4ad648e
AM
16183 {
16184 can_issue_more = issue_rate - 1;
16185 (*group_count)++;
16186 end = true;
16187 for (i = 0; i < issue_rate; i++)
16188 {
16189 group_insns[i] = 0;
16190 }
16191 }
cbe26ab8
DN
16192
16193 while (n_nops > 0)
c4ad648e
AM
16194 {
16195 nop = gen_nop ();
16196 emit_insn_before (nop, next_insn);
16197 if (can_issue_more == issue_rate - 1) /* new group begins */
16198 end = false;
16199 can_issue_more--;
16200 if (can_issue_more == 0)
16201 {
16202 can_issue_more = issue_rate - 1;
16203 (*group_count)++;
16204 end = true;
16205 for (i = 0; i < issue_rate; i++)
16206 {
16207 group_insns[i] = 0;
16208 }
16209 }
16210 n_nops--;
16211 }
cbe26ab8
DN
16212
16213 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
f676971a 16214 can_issue_more++;
cbe26ab8 16215
c4ad648e
AM
16216 /* Is next_insn going to start a new group? */
16217 *group_end
16218 = (end
cbe26ab8
DN
16219 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
16220 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
16221 || (can_issue_more < issue_rate &&
c4ad648e 16222 insn_terminates_group_p (next_insn, previous_group)));
cbe26ab8 16223 if (*group_end && end)
c4ad648e 16224 (*group_count)--;
cbe26ab8
DN
16225
16226 if (sched_verbose > 6)
c4ad648e
AM
16227 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
16228 *group_count, can_issue_more);
f676971a
EC
16229 return can_issue_more;
16230 }
cbe26ab8
DN
16231
16232 return can_issue_more;
16233}
16234
16235/* This function tries to synch the dispatch groups that the compiler "sees"
f676971a 16236 with the dispatch groups that the processor dispatcher is expected to
cbe26ab8
DN
16237 form in practice. It tries to achieve this synchronization by forcing the
16238 estimated processor grouping on the compiler (as opposed to the function
16239 'pad_goups' which tries to force the scheduler's grouping on the processor).
16240
16241 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
16242 examines the (estimated) dispatch groups that will be formed by the processor
16243 dispatcher. It marks these group boundaries to reflect the estimated
16244 processor grouping, overriding the grouping that the scheduler had marked.
16245 Depending on the value of the flag '-minsert-sched-nops' this function can
16246 force certain insns into separate groups or force a certain distance between
16247 them by inserting nops, for example, if there exists a "costly dependence"
16248 between the insns.
16249
16250 The function estimates the group boundaries that the processor will form as
16251 folllows: It keeps track of how many vacant issue slots are available after
16252 each insn. A subsequent insn will start a new group if one of the following
16253 4 cases applies:
16254 - no more vacant issue slots remain in the current dispatch group.
16255 - only the last issue slot, which is the branch slot, is vacant, but the next
16256 insn is not a branch.
16257 - only the last 2 or less issue slots, including the branch slot, are vacant,
16258 which means that a cracked insn (which occupies two issue slots) can't be
16259 issued in this group.
f676971a 16260 - less than 'issue_rate' slots are vacant, and the next insn always needs to
cbe26ab8
DN
16261 start a new group. */
16262
16263static int
16264redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
16265{
16266 rtx insn, next_insn;
16267 int issue_rate;
16268 int can_issue_more;
16269 int slot, i;
16270 bool group_end;
16271 int group_count = 0;
16272 rtx *group_insns;
16273
16274 /* Initialize. */
16275 issue_rate = rs6000_issue_rate ();
16276 group_insns = alloca (issue_rate * sizeof (rtx));
f676971a 16277 for (i = 0; i < issue_rate; i++)
cbe26ab8
DN
16278 {
16279 group_insns[i] = 0;
16280 }
16281 can_issue_more = issue_rate;
16282 slot = 0;
16283 insn = get_next_active_insn (prev_head_insn, tail);
16284 group_end = false;
16285
16286 while (insn != NULL_RTX)
16287 {
16288 slot = (issue_rate - can_issue_more);
16289 group_insns[slot] = insn;
16290 can_issue_more =
c4ad648e 16291 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
cbe26ab8 16292 if (insn_terminates_group_p (insn, current_group))
c4ad648e 16293 can_issue_more = 0;
cbe26ab8
DN
16294
16295 next_insn = get_next_active_insn (insn, tail);
16296 if (next_insn == NULL_RTX)
c4ad648e 16297 return group_count + 1;
cbe26ab8 16298
c4ad648e
AM
16299 /* Is next_insn going to start a new group? */
16300 group_end
16301 = (can_issue_more == 0
16302 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
16303 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
16304 || (can_issue_more < issue_rate &&
16305 insn_terminates_group_p (next_insn, previous_group)));
cbe26ab8 16306
f676971a 16307 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
c4ad648e
AM
16308 next_insn, &group_end, can_issue_more,
16309 &group_count);
cbe26ab8
DN
16310
16311 if (group_end)
c4ad648e
AM
16312 {
16313 group_count++;
16314 can_issue_more = 0;
16315 for (i = 0; i < issue_rate; i++)
16316 {
16317 group_insns[i] = 0;
16318 }
16319 }
cbe26ab8
DN
16320
16321 if (GET_MODE (next_insn) == TImode && can_issue_more)
c4ad648e 16322 PUT_MODE(next_insn, VOIDmode);
cbe26ab8 16323 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
c4ad648e 16324 PUT_MODE (next_insn, TImode);
cbe26ab8
DN
16325
16326 insn = next_insn;
16327 if (can_issue_more == 0)
c4ad648e
AM
16328 can_issue_more = issue_rate;
16329 } /* while */
cbe26ab8
DN
16330
16331 return group_count;
16332}
16333
16334/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
16335 dispatch group boundaries that the scheduler had marked. Pad with nops
16336 any dispatch groups which have vacant issue slots, in order to force the
16337 scheduler's grouping on the processor dispatcher. The function
16338 returns the number of dispatch groups found. */
16339
16340static int
16341pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
16342{
16343 rtx insn, next_insn;
16344 rtx nop;
16345 int issue_rate;
16346 int can_issue_more;
16347 int group_end;
16348 int group_count = 0;
16349
16350 /* Initialize issue_rate. */
16351 issue_rate = rs6000_issue_rate ();
16352 can_issue_more = issue_rate;
16353
16354 insn = get_next_active_insn (prev_head_insn, tail);
16355 next_insn = get_next_active_insn (insn, tail);
16356
16357 while (insn != NULL_RTX)
16358 {
16359 can_issue_more =
16360 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
16361
16362 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
16363
16364 if (next_insn == NULL_RTX)
c4ad648e 16365 break;
cbe26ab8
DN
16366
16367 if (group_end)
c4ad648e
AM
16368 {
16369 /* If the scheduler had marked group termination at this location
16370 (between insn and next_indn), and neither insn nor next_insn will
16371 force group termination, pad the group with nops to force group
16372 termination. */
16373 if (can_issue_more
16374 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
16375 && !insn_terminates_group_p (insn, current_group)
16376 && !insn_terminates_group_p (next_insn, previous_group))
16377 {
16378 if (!is_branch_slot_insn(next_insn))
16379 can_issue_more--;
16380
16381 while (can_issue_more)
16382 {
16383 nop = gen_nop ();
16384 emit_insn_before (nop, next_insn);
16385 can_issue_more--;
16386 }
16387 }
16388
16389 can_issue_more = issue_rate;
16390 group_count++;
16391 }
cbe26ab8
DN
16392
16393 insn = next_insn;
16394 next_insn = get_next_active_insn (insn, tail);
16395 }
16396
16397 return group_count;
16398}
16399
16400/* The following function is called at the end of scheduling BB.
16401 After reload, it inserts nops at insn group bundling. */
16402
16403static void
38f391a5 16404rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
16405{
16406 int n_groups;
16407
16408 if (sched_verbose)
16409 fprintf (dump, "=== Finishing schedule.\n");
16410
ec507f2d 16411 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
16412 {
16413 if (rs6000_sched_insert_nops == sched_finish_none)
c4ad648e 16414 return;
cbe26ab8
DN
16415
16416 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
c4ad648e
AM
16417 n_groups = pad_groups (dump, sched_verbose,
16418 current_sched_info->prev_head,
16419 current_sched_info->next_tail);
cbe26ab8 16420 else
c4ad648e
AM
16421 n_groups = redefine_groups (dump, sched_verbose,
16422 current_sched_info->prev_head,
16423 current_sched_info->next_tail);
cbe26ab8
DN
16424
16425 if (sched_verbose >= 6)
16426 {
16427 fprintf (dump, "ngroups = %d\n", n_groups);
16428 print_rtl (dump, current_sched_info->prev_head);
16429 fprintf (dump, "Done finish_sched\n");
16430 }
16431 }
16432}
b6c9286a 16433\f
b6c9286a
MM
16434/* Length in units of the trampoline for entering a nested function. */
16435
16436int
863d938c 16437rs6000_trampoline_size (void)
b6c9286a
MM
16438{
16439 int ret = 0;
16440
16441 switch (DEFAULT_ABI)
16442 {
16443 default:
16444 abort ();
16445
16446 case ABI_AIX:
8f802bfb 16447 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
16448 break;
16449
4dabc42d 16450 case ABI_DARWIN:
b6c9286a 16451 case ABI_V4:
03a7e1a5 16452 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 16453 break;
b6c9286a
MM
16454 }
16455
16456 return ret;
16457}
16458
16459/* Emit RTL insns to initialize the variable parts of a trampoline.
16460 FNADDR is an RTX for the address of the function's pure code.
16461 CXT is an RTX for the static chain value for the function. */
16462
16463void
a2369ed3 16464rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 16465{
ac2a93a1 16466 enum machine_mode pmode = Pmode;
8bd04c56
MM
16467 int regsize = (TARGET_32BIT) ? 4 : 8;
16468 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
16469
16470 switch (DEFAULT_ABI)
16471 {
16472 default:
16473 abort ();
16474
8bd04c56 16475/* Macros to shorten the code expansions below. */
39403d82 16476#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
16477#define MEM_PLUS(addr,offset) \
16478 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 16479
b6c9286a
MM
16480 /* Under AIX, just build the 3 word function descriptor */
16481 case ABI_AIX:
8bd04c56
MM
16482 {
16483 rtx fn_reg = gen_reg_rtx (pmode);
16484 rtx toc_reg = gen_reg_rtx (pmode);
16485 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 16486 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
16487 emit_move_insn (MEM_DEREF (addr), fn_reg);
16488 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
16489 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
16490 }
b6c9286a
MM
16491 break;
16492
4dabc42d
TC
16493 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
16494 case ABI_DARWIN:
b6c9286a 16495 case ABI_V4:
39403d82 16496 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
16497 FALSE, VOIDmode, 4,
16498 addr, pmode,
16499 GEN_INT (rs6000_trampoline_size ()), SImode,
16500 fnaddr, pmode,
16501 ctx_reg, pmode);
b6c9286a 16502 break;
b6c9286a
MM
16503 }
16504
16505 return;
16506}
7509c759
MM
16507
16508\f
91d231cb 16509/* Table of valid machine attributes. */
a4f6c312 16510
91d231cb 16511const struct attribute_spec rs6000_attribute_table[] =
7509c759 16512{
91d231cb 16513 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 16514 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
16515 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16516 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16517 { NULL, 0, 0, false, false, false, NULL }
91d231cb 16518};
7509c759 16519
8bb418a3
ZL
16520/* Handle the "altivec" attribute. The attribute may have
16521 arguments as follows:
f676971a 16522
8bb418a3
ZL
16523 __attribute__((altivec(vector__)))
16524 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
16525 __attribute__((altivec(bool__))) (always followed by 'unsigned')
16526
16527 and may appear more than once (e.g., 'vector bool char') in a
16528 given declaration. */
16529
16530static tree
16531rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
16532 int flags ATTRIBUTE_UNUSED,
16533 bool *no_add_attrs)
16534{
16535 tree type = *node, result = NULL_TREE;
16536 enum machine_mode mode;
16537 int unsigned_p;
16538 char altivec_type
16539 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
16540 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
16541 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
f676971a 16542 : '?');
8bb418a3
ZL
16543
16544 while (POINTER_TYPE_P (type)
16545 || TREE_CODE (type) == FUNCTION_TYPE
16546 || TREE_CODE (type) == METHOD_TYPE
16547 || TREE_CODE (type) == ARRAY_TYPE)
16548 type = TREE_TYPE (type);
16549
16550 mode = TYPE_MODE (type);
16551
16552 if (rs6000_warn_altivec_long
16553 && (type == long_unsigned_type_node || type == long_integer_type_node))
16554 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
16555
16556 switch (altivec_type)
16557 {
16558 case 'v':
8df83eae 16559 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
16560 switch (mode)
16561 {
c4ad648e
AM
16562 case SImode:
16563 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
16564 break;
16565 case HImode:
16566 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
16567 break;
16568 case QImode:
16569 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
16570 break;
16571 case SFmode: result = V4SF_type_node; break;
16572 /* If the user says 'vector int bool', we may be handed the 'bool'
16573 attribute _before_ the 'vector' attribute, and so select the
16574 proper type in the 'b' case below. */
16575 case V4SImode: case V8HImode: case V16QImode: case V4SFmode:
16576 result = type;
16577 default: break;
8bb418a3
ZL
16578 }
16579 break;
16580 case 'b':
16581 switch (mode)
16582 {
c4ad648e
AM
16583 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
16584 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
16585 case QImode: case V16QImode: result = bool_V16QI_type_node;
16586 default: break;
8bb418a3
ZL
16587 }
16588 break;
16589 case 'p':
16590 switch (mode)
16591 {
c4ad648e
AM
16592 case V8HImode: result = pixel_V8HI_type_node;
16593 default: break;
8bb418a3
ZL
16594 }
16595 default: break;
16596 }
16597
7958a2a6
FJ
16598 if (result && result != type && TYPE_READONLY (type))
16599 result = build_qualified_type (result, TYPE_QUAL_CONST);
16600
8bb418a3
ZL
16601 *no_add_attrs = true; /* No need to hang on to the attribute. */
16602
16603 if (!result)
16604 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
16605 else
16606 *node = reconstruct_complex_type (*node, result);
16607
16608 return NULL_TREE;
16609}
16610
f18eca82
ZL
16611/* AltiVec defines four built-in scalar types that serve as vector
16612 elements; we must teach the compiler how to mangle them. */
16613
16614static const char *
16615rs6000_mangle_fundamental_type (tree type)
16616{
16617 if (type == bool_char_type_node) return "U6__boolc";
16618 if (type == bool_short_type_node) return "U6__bools";
16619 if (type == pixel_type_node) return "u7__pixel";
16620 if (type == bool_int_type_node) return "U6__booli";
16621
16622 /* For all other types, use normal C++ mangling. */
16623 return NULL;
16624}
16625
a5c76ee6
ZW
16626/* Handle a "longcall" or "shortcall" attribute; arguments as in
16627 struct attribute_spec.handler. */
a4f6c312 16628
91d231cb 16629static tree
f676971a
EC
16630rs6000_handle_longcall_attribute (tree *node, tree name,
16631 tree args ATTRIBUTE_UNUSED,
16632 int flags ATTRIBUTE_UNUSED,
a2369ed3 16633 bool *no_add_attrs)
91d231cb
JM
16634{
16635 if (TREE_CODE (*node) != FUNCTION_TYPE
16636 && TREE_CODE (*node) != FIELD_DECL
16637 && TREE_CODE (*node) != TYPE_DECL)
16638 {
16639 warning ("`%s' attribute only applies to functions",
16640 IDENTIFIER_POINTER (name));
16641 *no_add_attrs = true;
16642 }
6a4cee5f 16643
91d231cb 16644 return NULL_TREE;
7509c759
MM
16645}
16646
a5c76ee6
ZW
16647/* Set longcall attributes on all functions declared when
16648 rs6000_default_long_calls is true. */
16649static void
a2369ed3 16650rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
16651{
16652 if (rs6000_default_long_calls
16653 && (TREE_CODE (type) == FUNCTION_TYPE
16654 || TREE_CODE (type) == METHOD_TYPE))
16655 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
16656 NULL_TREE,
16657 TYPE_ATTRIBUTES (type));
16658}
16659
3cb999d8
DE
16660/* Return a reference suitable for calling a function with the
16661 longcall attribute. */
a4f6c312 16662
6a4cee5f 16663struct rtx_def *
a2369ed3 16664rs6000_longcall_ref (rtx call_ref)
6a4cee5f 16665{
d330fd93 16666 const char *call_name;
6a4cee5f
MM
16667 tree node;
16668
16669 if (GET_CODE (call_ref) != SYMBOL_REF)
16670 return call_ref;
16671
16672 /* System V adds '.' to the internal name, so skip them. */
16673 call_name = XSTR (call_ref, 0);
16674 if (*call_name == '.')
16675 {
16676 while (*call_name == '.')
16677 call_name++;
16678
16679 node = get_identifier (call_name);
39403d82 16680 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
16681 }
16682
16683 return force_reg (Pmode, call_ref);
16684}
7509c759 16685\f
b64a1b53
RH
16686#ifdef USING_ELFOS_H
16687
7509c759
MM
16688/* A C statement or statements to switch to the appropriate section
16689 for output of RTX in mode MODE. You can assume that RTX is some
16690 kind of constant in RTL. The argument MODE is redundant except in
16691 the case of a `const_int' rtx. Select the section by calling
16692 `text_section' or one of the alternatives for other sections.
16693
16694 Do not define this macro if you put all constants in the read-only
16695 data section. */
16696
b64a1b53 16697static void
f676971a 16698rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
a2369ed3 16699 unsigned HOST_WIDE_INT align)
7509c759 16700{
a9098fd0 16701 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 16702 toc_section ();
7509c759 16703 else
b64a1b53 16704 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
16705}
16706
16707/* A C statement or statements to switch to the appropriate
16708 section for output of DECL. DECL is either a `VAR_DECL' node
16709 or a constant of some sort. RELOC indicates whether forming
16710 the initial value of DECL requires link-time relocations. */
16711
ae46c4e0 16712static void
f676971a 16713rs6000_elf_select_section (tree decl, int reloc,
a2369ed3 16714 unsigned HOST_WIDE_INT align)
7509c759 16715{
f1384257
AM
16716 /* Pretend that we're always building for a shared library when
16717 ABI_AIX, because otherwise we end up with dynamic relocations
16718 in read-only sections. This happens for function pointers,
16719 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
16720 default_elf_select_section_1 (decl, reloc, align,
16721 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
16722}
16723
16724/* A C statement to build up a unique section name, expressed as a
16725 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
16726 RELOC indicates whether the initial value of EXP requires
16727 link-time relocations. If you do not define this macro, GCC will use
16728 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 16729 macro can now be called for uninitialized data items as well as
4912a07c 16730 initialized data and functions. */
63019373 16731
ae46c4e0 16732static void
a2369ed3 16733rs6000_elf_unique_section (tree decl, int reloc)
63019373 16734{
f1384257
AM
16735 /* As above, pretend that we're always building for a shared library
16736 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
16737 default_unique_section_1 (decl, reloc,
16738 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 16739}
d9407988 16740\f
d1908feb
JJ
16741/* For a SYMBOL_REF, set generic flags and then perform some
16742 target-specific processing.
16743
d1908feb
JJ
16744 When the AIX ABI is requested on a non-AIX system, replace the
16745 function name with the real name (with a leading .) rather than the
16746 function descriptor name. This saves a lot of overriding code to
16747 read the prefixes. */
d9407988 16748
fb49053f 16749static void
a2369ed3 16750rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 16751{
d1908feb 16752 default_encode_section_info (decl, rtl, first);
b2003250 16753
d1908feb
JJ
16754 if (first
16755 && TREE_CODE (decl) == FUNCTION_DECL
16756 && !TARGET_AIX
16757 && DEFAULT_ABI == ABI_AIX)
d9407988 16758 {
c6a2438a 16759 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
16760 size_t len = strlen (XSTR (sym_ref, 0));
16761 char *str = alloca (len + 2);
16762 str[0] = '.';
16763 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
16764 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 16765 }
d9407988
MM
16766}
16767
0e5dbd9b 16768static bool
a2369ed3 16769rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
16770{
16771 if (rs6000_sdata == SDATA_NONE)
16772 return false;
16773
16774 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
16775 {
16776 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
16777 if (strcmp (section, ".sdata") == 0
16778 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
16779 || strcmp (section, ".sbss") == 0
16780 || strcmp (section, ".sbss2") == 0
16781 || strcmp (section, ".PPC.EMB.sdata0") == 0
16782 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
16783 return true;
16784 }
16785 else
16786 {
16787 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
16788
16789 if (size > 0
307b599c 16790 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
16791 /* If it's not public, and we're not going to reference it there,
16792 there's no need to put it in the small data section. */
0e5dbd9b
DE
16793 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
16794 return true;
16795 }
16796
16797 return false;
16798}
16799
b91da81f 16800#endif /* USING_ELFOS_H */
000034eb 16801
a6c2a102 16802\f
000034eb 16803/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
16804 ADDR can be effectively incremented by incrementing REG.
16805
16806 r0 is special and we must not select it as an address
16807 register by this routine since our caller will try to
16808 increment the returned register via an "la" instruction. */
000034eb
DE
16809
16810struct rtx_def *
a2369ed3 16811find_addr_reg (rtx addr)
000034eb
DE
16812{
16813 while (GET_CODE (addr) == PLUS)
16814 {
02441cd6
JL
16815 if (GET_CODE (XEXP (addr, 0)) == REG
16816 && REGNO (XEXP (addr, 0)) != 0)
000034eb 16817 addr = XEXP (addr, 0);
02441cd6
JL
16818 else if (GET_CODE (XEXP (addr, 1)) == REG
16819 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
16820 addr = XEXP (addr, 1);
16821 else if (CONSTANT_P (XEXP (addr, 0)))
16822 addr = XEXP (addr, 1);
16823 else if (CONSTANT_P (XEXP (addr, 1)))
16824 addr = XEXP (addr, 0);
16825 else
16826 abort ();
16827 }
02441cd6 16828 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
16829 return addr;
16830 abort ();
16831}
16832
a6c2a102 16833void
a2369ed3 16834rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
16835{
16836 fatal_insn ("bad address", op);
16837}
c8023011 16838
ee890fe2
SS
16839#if TARGET_MACHO
16840
16841#if 0
16842/* Returns 1 if OP is either a symbol reference or a sum of a symbol
16843 reference and a constant. */
16844
16845int
a2369ed3 16846symbolic_operand (rtx op)
ee890fe2
SS
16847{
16848 switch (GET_CODE (op))
16849 {
16850 case SYMBOL_REF:
16851 case LABEL_REF:
16852 return 1;
16853 case CONST:
16854 op = XEXP (op, 0);
16855 return (GET_CODE (op) == SYMBOL_REF ||
16856 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
16857 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
16858 && GET_CODE (XEXP (op, 1)) == CONST_INT);
16859 default:
16860 return 0;
16861 }
c8023011 16862}
ee890fe2
SS
16863#endif
16864
efdba735 16865#if TARGET_MACHO
ee890fe2 16866
efdba735 16867static tree branch_island_list = 0;
ee890fe2 16868
efdba735
SH
16869/* Remember to generate a branch island for far calls to the given
16870 function. */
ee890fe2 16871
f676971a 16872static void
c4ad648e
AM
16873add_compiler_branch_island (tree label_name, tree function_name,
16874 int line_number)
ee890fe2 16875{
efdba735 16876 tree branch_island = build_tree_list (function_name, label_name);
7d60be94 16877 TREE_TYPE (branch_island) = build_int_cst (NULL_TREE, line_number);
efdba735
SH
16878 TREE_CHAIN (branch_island) = branch_island_list;
16879 branch_island_list = branch_island;
ee890fe2
SS
16880}
16881
efdba735
SH
16882#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
16883#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
16884#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
16885 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 16886
efdba735
SH
16887/* Generate far-jump branch islands for everything on the
16888 branch_island_list. Invoked immediately after the last instruction
16889 of the epilogue has been emitted; the branch-islands must be
16890 appended to, and contiguous with, the function body. Mach-O stubs
16891 are generated in machopic_output_stub(). */
ee890fe2 16892
efdba735
SH
16893static void
16894macho_branch_islands (void)
16895{
16896 char tmp_buf[512];
16897 tree branch_island;
16898
16899 for (branch_island = branch_island_list;
16900 branch_island;
16901 branch_island = TREE_CHAIN (branch_island))
16902 {
16903 const char *label =
16904 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
16905 const char *name =
11abc112 16906 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island));
efdba735
SH
16907 char name_buf[512];
16908 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
16909 if (name[0] == '*' || name[0] == '&')
16910 strcpy (name_buf, name+1);
16911 else
16912 {
16913 name_buf[0] = '_';
16914 strcpy (name_buf+1, name);
16915 }
16916 strcpy (tmp_buf, "\n");
16917 strcat (tmp_buf, label);
ee890fe2 16918#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16919 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16920 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16921 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 16922#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
16923 if (flag_pic)
16924 {
16925 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
16926 strcat (tmp_buf, label);
16927 strcat (tmp_buf, "_pic\n");
16928 strcat (tmp_buf, label);
16929 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
f676971a 16930
efdba735
SH
16931 strcat (tmp_buf, "\taddis r11,r11,ha16(");
16932 strcat (tmp_buf, name_buf);
16933 strcat (tmp_buf, " - ");
16934 strcat (tmp_buf, label);
16935 strcat (tmp_buf, "_pic)\n");
f676971a 16936
efdba735 16937 strcat (tmp_buf, "\tmtlr r0\n");
f676971a 16938
efdba735
SH
16939 strcat (tmp_buf, "\taddi r12,r11,lo16(");
16940 strcat (tmp_buf, name_buf);
16941 strcat (tmp_buf, " - ");
16942 strcat (tmp_buf, label);
16943 strcat (tmp_buf, "_pic)\n");
f676971a 16944
efdba735
SH
16945 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
16946 }
16947 else
16948 {
16949 strcat (tmp_buf, ":\nlis r12,hi16(");
16950 strcat (tmp_buf, name_buf);
16951 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
16952 strcat (tmp_buf, name_buf);
16953 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
16954 }
16955 output_asm_insn (tmp_buf, 0);
ee890fe2 16956#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16957 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16958 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16959 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 16960#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 16961 }
ee890fe2 16962
efdba735 16963 branch_island_list = 0;
ee890fe2
SS
16964}
16965
16966/* NO_PREVIOUS_DEF checks in the link list whether the function name is
16967 already there or not. */
16968
efdba735 16969static int
a2369ed3 16970no_previous_def (tree function_name)
ee890fe2 16971{
efdba735
SH
16972 tree branch_island;
16973 for (branch_island = branch_island_list;
16974 branch_island;
16975 branch_island = TREE_CHAIN (branch_island))
16976 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
16977 return 0;
16978 return 1;
16979}
16980
16981/* GET_PREV_LABEL gets the label name from the previous definition of
16982 the function. */
16983
efdba735 16984static tree
a2369ed3 16985get_prev_label (tree function_name)
ee890fe2 16986{
efdba735
SH
16987 tree branch_island;
16988 for (branch_island = branch_island_list;
16989 branch_island;
16990 branch_island = TREE_CHAIN (branch_island))
16991 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
16992 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
16993 return 0;
16994}
16995
16996/* INSN is either a function call or a millicode call. It may have an
f676971a 16997 unconditional jump in its delay slot.
ee890fe2
SS
16998
16999 CALL_DEST is the routine we are calling. */
17000
17001char *
c4ad648e
AM
17002output_call (rtx insn, rtx *operands, int dest_operand_number,
17003 int cookie_operand_number)
ee890fe2
SS
17004{
17005 static char buf[256];
efdba735
SH
17006 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
17007 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
17008 {
17009 tree labelname;
efdba735 17010 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
f676971a 17011
ee890fe2
SS
17012 if (no_previous_def (funname))
17013 {
308c142a 17014 int line_number = 0;
ee890fe2
SS
17015 rtx label_rtx = gen_label_rtx ();
17016 char *label_buf, temp_buf[256];
17017 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
17018 CODE_LABEL_NUMBER (label_rtx));
17019 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
17020 labelname = get_identifier (label_buf);
17021 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
17022 if (insn)
17023 line_number = NOTE_LINE_NUMBER (insn);
efdba735 17024 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
17025 }
17026 else
17027 labelname = get_prev_label (funname);
17028
efdba735
SH
17029 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
17030 instruction will reach 'foo', otherwise link as 'bl L42'".
17031 "L42" should be a 'branch island', that will do a far jump to
17032 'foo'. Branch islands are generated in
17033 macho_branch_islands(). */
ee890fe2 17034 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 17035 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
17036 }
17037 else
efdba735
SH
17038 sprintf (buf, "bl %%z%d", dest_operand_number);
17039 return buf;
ee890fe2
SS
17040}
17041
efdba735 17042#endif /* TARGET_MACHO */
ee890fe2 17043
ee890fe2
SS
17044/* Generate PIC and indirect symbol stubs. */
17045
17046void
a2369ed3 17047machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
17048{
17049 unsigned int length;
a4f6c312
SS
17050 char *symbol_name, *lazy_ptr_name;
17051 char *local_label_0;
ee890fe2
SS
17052 static int label = 0;
17053
df56a27f 17054 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 17055 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 17056
ee890fe2 17057
ee890fe2
SS
17058 length = strlen (symb);
17059 symbol_name = alloca (length + 32);
17060 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
17061
17062 lazy_ptr_name = alloca (length + 32);
17063 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
17064
ee890fe2 17065 if (flag_pic == 2)
d3c300d2 17066 machopic_picsymbol_stub1_section ();
ee890fe2 17067 else
d3c300d2 17068 machopic_symbol_stub1_section ();
ee890fe2
SS
17069
17070 if (flag_pic == 2)
17071 {
d974312d
DJ
17072 fprintf (file, "\t.align 5\n");
17073
17074 fprintf (file, "%s:\n", stub);
17075 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
17076
876455fa
AP
17077 label++;
17078 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
17079 sprintf (local_label_0, "\"L%011d$spb\"", label);
f676971a 17080
ee890fe2
SS
17081 fprintf (file, "\tmflr r0\n");
17082 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
17083 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
17084 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
17085 lazy_ptr_name, local_label_0);
17086 fprintf (file, "\tmtlr r0\n");
d3c300d2 17087 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
17088 lazy_ptr_name, local_label_0);
17089 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
17090 fprintf (file, "\tbctr\n");
17091 }
17092 else
d974312d
DJ
17093 {
17094 fprintf (file, "\t.align 4\n");
17095
17096 fprintf (file, "%s:\n", stub);
17097 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
17098
17099 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
17100 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
17101 fprintf (file, "\tmtctr r12\n");
17102 fprintf (file, "\tbctr\n");
17103 }
f676971a 17104
ee890fe2
SS
17105 machopic_lazy_symbol_ptr_section ();
17106 fprintf (file, "%s:\n", lazy_ptr_name);
17107 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
49bd1d27
SS
17108 fprintf (file, "%sdyld_stub_binding_helper\n",
17109 (TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t"));
ee890fe2
SS
17110}
17111
17112/* Legitimize PIC addresses. If the address is already
17113 position-independent, we return ORIG. Newly generated
17114 position-independent addresses go into a reg. This is REG if non
17115 zero, otherwise we allocate register(s) as necessary. */
17116
c859cda6 17117#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
17118
17119rtx
f676971a 17120rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
a2369ed3 17121 rtx reg)
ee890fe2
SS
17122{
17123 rtx base, offset;
17124
17125 if (reg == NULL && ! reload_in_progress && ! reload_completed)
17126 reg = gen_reg_rtx (Pmode);
17127
17128 if (GET_CODE (orig) == CONST)
17129 {
17130 if (GET_CODE (XEXP (orig, 0)) == PLUS
17131 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
17132 return orig;
17133
17134 if (GET_CODE (XEXP (orig, 0)) == PLUS)
17135 {
2cf520bf 17136 /* Use a different reg for the intermediate value, as
a3c9585f 17137 it will be marked UNCHANGING. */
2cf520bf
GK
17138 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
17139
a4f6c312
SS
17140 base =
17141 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 17142 Pmode, reg_temp);
a4f6c312
SS
17143 offset =
17144 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
17145 Pmode, reg);
ee890fe2
SS
17146 }
17147 else
17148 abort ();
17149
17150 if (GET_CODE (offset) == CONST_INT)
17151 {
17152 if (SMALL_INT (offset))
ed8908e7 17153 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
17154 else if (! reload_in_progress && ! reload_completed)
17155 offset = force_reg (Pmode, offset);
17156 else
c859cda6
DJ
17157 {
17158 rtx mem = force_const_mem (Pmode, orig);
17159 return machopic_legitimize_pic_address (mem, Pmode, reg);
17160 }
ee890fe2 17161 }
f1c25d3b 17162 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
17163 }
17164
17165 /* Fall back on generic machopic code. */
17166 return machopic_legitimize_pic_address (orig, mode, reg);
17167}
17168
17169/* This is just a placeholder to make linking work without having to
17170 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
17171 ever needed for Darwin (not too likely!) this would have to get a
17172 real definition. */
17173
17174void
863d938c 17175toc_section (void)
ee890fe2
SS
17176{
17177}
17178
17179#endif /* TARGET_MACHO */
7c262518
RH
17180
17181#if TARGET_ELF
17182static unsigned int
a2369ed3 17183rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 17184{
1ff8f81a
AM
17185 return default_section_type_flags_1 (decl, name, reloc,
17186 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 17187}
d9f6800d
RH
17188
17189/* Record an element in the table of global constructors. SYMBOL is
17190 a SYMBOL_REF of the function to be called; PRIORITY is a number
17191 between 0 and MAX_INIT_PRIORITY.
17192
17193 This differs from default_named_section_asm_out_constructor in
17194 that we have special handling for -mrelocatable. */
17195
17196static void
a2369ed3 17197rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
17198{
17199 const char *section = ".ctors";
17200 char buf[16];
17201
17202 if (priority != DEFAULT_INIT_PRIORITY)
17203 {
17204 sprintf (buf, ".ctors.%.5u",
c4ad648e
AM
17205 /* Invert the numbering so the linker puts us in the proper
17206 order; constructors are run from right to left, and the
17207 linker sorts in increasing order. */
17208 MAX_INIT_PRIORITY - priority);
d9f6800d
RH
17209 section = buf;
17210 }
17211
715bdd29
RH
17212 named_section_flags (section, SECTION_WRITE);
17213 assemble_align (POINTER_SIZE);
d9f6800d
RH
17214
17215 if (TARGET_RELOCATABLE)
17216 {
17217 fputs ("\t.long (", asm_out_file);
17218 output_addr_const (asm_out_file, symbol);
17219 fputs (")@fixup\n", asm_out_file);
17220 }
17221 else
c8af3574 17222 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
17223}
17224
17225static void
a2369ed3 17226rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
17227{
17228 const char *section = ".dtors";
17229 char buf[16];
17230
17231 if (priority != DEFAULT_INIT_PRIORITY)
17232 {
17233 sprintf (buf, ".dtors.%.5u",
c4ad648e
AM
17234 /* Invert the numbering so the linker puts us in the proper
17235 order; constructors are run from right to left, and the
17236 linker sorts in increasing order. */
17237 MAX_INIT_PRIORITY - priority);
d9f6800d
RH
17238 section = buf;
17239 }
17240
715bdd29
RH
17241 named_section_flags (section, SECTION_WRITE);
17242 assemble_align (POINTER_SIZE);
d9f6800d
RH
17243
17244 if (TARGET_RELOCATABLE)
17245 {
17246 fputs ("\t.long (", asm_out_file);
17247 output_addr_const (asm_out_file, symbol);
17248 fputs (")@fixup\n", asm_out_file);
17249 }
17250 else
c8af3574 17251 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 17252}
9739c90c
JJ
17253
17254void
a2369ed3 17255rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
17256{
17257 if (TARGET_64BIT)
17258 {
17259 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
17260 ASM_OUTPUT_LABEL (file, name);
17261 fputs (DOUBLE_INT_ASM_OP, file);
85b776df
AM
17262 rs6000_output_function_entry (file, name);
17263 fputs (",.TOC.@tocbase,0\n\t.previous\n", file);
17264 if (DOT_SYMBOLS)
9739c90c 17265 {
85b776df 17266 fputs ("\t.size\t", file);
9739c90c 17267 assemble_name (file, name);
85b776df
AM
17268 fputs (",24\n\t.type\t.", file);
17269 assemble_name (file, name);
17270 fputs (",@function\n", file);
17271 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
17272 {
17273 fputs ("\t.globl\t.", file);
17274 assemble_name (file, name);
17275 putc ('\n', file);
17276 }
9739c90c 17277 }
85b776df
AM
17278 else
17279 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
9739c90c 17280 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
85b776df
AM
17281 rs6000_output_function_entry (file, name);
17282 fputs (":\n", file);
9739c90c
JJ
17283 return;
17284 }
17285
17286 if (TARGET_RELOCATABLE
17287 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 17288 && uses_TOC ())
9739c90c
JJ
17289 {
17290 char buf[256];
17291
17292 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
17293
17294 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
17295 fprintf (file, "\t.long ");
17296 assemble_name (file, buf);
17297 putc ('-', file);
17298 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
17299 assemble_name (file, buf);
17300 putc ('\n', file);
17301 }
17302
17303 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
17304 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
17305
17306 if (DEFAULT_ABI == ABI_AIX)
17307 {
17308 const char *desc_name, *orig_name;
17309
17310 orig_name = (*targetm.strip_name_encoding) (name);
17311 desc_name = orig_name;
17312 while (*desc_name == '.')
17313 desc_name++;
17314
17315 if (TREE_PUBLIC (decl))
17316 fprintf (file, "\t.globl %s\n", desc_name);
17317
17318 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
17319 fprintf (file, "%s:\n", desc_name);
17320 fprintf (file, "\t.long %s\n", orig_name);
17321 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
17322 if (DEFAULT_ABI == ABI_AIX)
17323 fputs ("\t.long 0\n", file);
17324 fprintf (file, "\t.previous\n");
17325 }
17326 ASM_OUTPUT_LABEL (file, name);
17327}
7c262518
RH
17328#endif
17329
cbaaba19 17330#if TARGET_XCOFF
7c262518 17331static void
a2369ed3 17332rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
17333{
17334 fputs (GLOBAL_ASM_OP, stream);
17335 RS6000_OUTPUT_BASENAME (stream, name);
17336 putc ('\n', stream);
17337}
17338
17339static void
c18a5b6c
MM
17340rs6000_xcoff_asm_named_section (const char *name, unsigned int flags,
17341 tree decl ATTRIBUTE_UNUSED)
7c262518 17342{
0e5dbd9b
DE
17343 int smclass;
17344 static const char * const suffix[3] = { "PR", "RO", "RW" };
17345
17346 if (flags & SECTION_CODE)
17347 smclass = 0;
17348 else if (flags & SECTION_WRITE)
17349 smclass = 2;
17350 else
17351 smclass = 1;
17352
5b5198f7 17353 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 17354 (flags & SECTION_CODE) ? "." : "",
5b5198f7 17355 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 17356}
ae46c4e0
RH
17357
17358static void
f676971a 17359rs6000_xcoff_select_section (tree decl, int reloc,
c4ad648e 17360 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 17361{
5add3202 17362 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 17363 {
0e5dbd9b 17364 if (TREE_PUBLIC (decl))
c4ad648e 17365 read_only_data_section ();
ae46c4e0 17366 else
c4ad648e 17367 read_only_private_data_section ();
ae46c4e0
RH
17368 }
17369 else
17370 {
0e5dbd9b 17371 if (TREE_PUBLIC (decl))
c4ad648e 17372 data_section ();
ae46c4e0 17373 else
c4ad648e 17374 private_data_section ();
ae46c4e0
RH
17375 }
17376}
17377
17378static void
a2369ed3 17379rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
17380{
17381 const char *name;
ae46c4e0 17382
5b5198f7
DE
17383 /* Use select_section for private and uninitialized data. */
17384 if (!TREE_PUBLIC (decl)
17385 || DECL_COMMON (decl)
0e5dbd9b
DE
17386 || DECL_INITIAL (decl) == NULL_TREE
17387 || DECL_INITIAL (decl) == error_mark_node
17388 || (flag_zero_initialized_in_bss
17389 && initializer_zerop (DECL_INITIAL (decl))))
17390 return;
17391
17392 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17393 name = (*targetm.strip_name_encoding) (name);
17394 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 17395}
b64a1b53 17396
fb49053f
RH
17397/* Select section for constant in constant pool.
17398
17399 On RS/6000, all constants are in the private read-only data area.
17400 However, if this is being placed in the TOC it must be output as a
17401 toc entry. */
17402
b64a1b53 17403static void
f676971a 17404rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
c4ad648e 17405 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
17406{
17407 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
17408 toc_section ();
17409 else
17410 read_only_private_data_section ();
17411}
772c5265
RH
17412
17413/* Remove any trailing [DS] or the like from the symbol name. */
17414
17415static const char *
a2369ed3 17416rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
17417{
17418 size_t len;
17419 if (*name == '*')
17420 name++;
17421 len = strlen (name);
17422 if (name[len - 1] == ']')
17423 return ggc_alloc_string (name, len - 4);
17424 else
17425 return name;
17426}
17427
5add3202
DE
17428/* Section attributes. AIX is always PIC. */
17429
17430static unsigned int
a2369ed3 17431rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 17432{
5b5198f7
DE
17433 unsigned int align;
17434 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
17435
17436 /* Align to at least UNIT size. */
17437 if (flags & SECTION_CODE)
17438 align = MIN_UNITS_PER_WORD;
17439 else
17440 /* Increase alignment of large objects if not already stricter. */
17441 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
17442 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
17443 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
17444
17445 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 17446}
a5fe455b 17447
1bc7c5b6
ZW
17448/* Output at beginning of assembler file.
17449
17450 Initialize the section names for the RS/6000 at this point.
17451
17452 Specify filename, including full path, to assembler.
17453
17454 We want to go into the TOC section so at least one .toc will be emitted.
17455 Also, in order to output proper .bs/.es pairs, we need at least one static
17456 [RW] section emitted.
17457
17458 Finally, declare mcount when profiling to make the assembler happy. */
17459
17460static void
863d938c 17461rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
17462{
17463 rs6000_gen_section_name (&xcoff_bss_section_name,
17464 main_input_filename, ".bss_");
17465 rs6000_gen_section_name (&xcoff_private_data_section_name,
17466 main_input_filename, ".rw_");
17467 rs6000_gen_section_name (&xcoff_read_only_section_name,
17468 main_input_filename, ".ro_");
17469
17470 fputs ("\t.file\t", asm_out_file);
17471 output_quoted_string (asm_out_file, main_input_filename);
17472 fputc ('\n', asm_out_file);
17473 toc_section ();
17474 if (write_symbols != NO_DEBUG)
17475 private_data_section ();
17476 text_section ();
17477 if (profile_flag)
17478 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
17479 rs6000_file_start ();
17480}
17481
a5fe455b
ZW
17482/* Output at end of assembler file.
17483 On the RS/6000, referencing data should automatically pull in text. */
17484
17485static void
863d938c 17486rs6000_xcoff_file_end (void)
a5fe455b
ZW
17487{
17488 text_section ();
17489 fputs ("_section_.text:\n", asm_out_file);
17490 data_section ();
17491 fputs (TARGET_32BIT
17492 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
17493 asm_out_file);
17494}
f1384257 17495#endif /* TARGET_XCOFF */
0e5dbd9b 17496
f1384257
AM
17497#if TARGET_MACHO
17498/* Cross-module name binding. Darwin does not support overriding
7f3d8013 17499 functions at dynamic-link time. */
0e5dbd9b 17500
2bcc50d0 17501static bool
a2369ed3 17502rs6000_binds_local_p (tree decl)
0e5dbd9b 17503{
f1384257 17504 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 17505}
f1384257 17506#endif
34bb030a 17507
3c50106f
RH
17508/* Compute a (partial) cost for rtx X. Return true if the complete
17509 cost has been computed, and false if subexpressions should be
17510 scanned. In either case, *TOTAL contains the cost result. */
17511
17512static bool
1494c534 17513rs6000_rtx_costs (rtx x, int code, int outer_code, int *total)
3c50106f 17514{
f0517163
RS
17515 enum machine_mode mode = GET_MODE (x);
17516
3c50106f
RH
17517 switch (code)
17518 {
30a555d9 17519 /* On the RS/6000, if it is valid in the insn, it is free. */
3c50106f 17520 case CONST_INT:
066cd967
DE
17521 if (((outer_code == SET
17522 || outer_code == PLUS
17523 || outer_code == MINUS)
17524 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17525 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
17526 || ((outer_code == IOR || outer_code == XOR)
17527 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17528 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
627b6fe2
DJ
17529 || ((outer_code == DIV || outer_code == UDIV
17530 || outer_code == MOD || outer_code == UMOD)
17531 && exact_log2 (INTVAL (x)) >= 0)
066cd967
DE
17532 || (outer_code == AND
17533 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17534 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17535 || mask_operand (x, VOIDmode)))
066cd967
DE
17536 || outer_code == ASHIFT
17537 || outer_code == ASHIFTRT
17538 || outer_code == LSHIFTRT
17539 || outer_code == ROTATE
17540 || outer_code == ROTATERT
d5861a7a 17541 || outer_code == ZERO_EXTRACT
066cd967
DE
17542 || (outer_code == MULT
17543 && CONST_OK_FOR_LETTER_P (INTVAL (x), 'I'))
17544 || (outer_code == COMPARE
17545 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17546 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'K'))))
17547 {
17548 *total = 0;
17549 return true;
17550 }
17551 else if ((outer_code == PLUS
17552 && reg_or_add_cint64_operand (x, VOIDmode))
17553 || (outer_code == MINUS
17554 && reg_or_sub_cint64_operand (x, VOIDmode))
17555 || ((outer_code == SET
17556 || outer_code == IOR
17557 || outer_code == XOR)
17558 && (INTVAL (x)
17559 & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0))
17560 {
17561 *total = COSTS_N_INSNS (1);
17562 return true;
17563 }
17564 /* FALLTHRU */
17565
17566 case CONST_DOUBLE:
17567 if (mode == DImode
17568 && ((outer_code == AND
17569 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17570 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17571 || mask64_operand (x, DImode)))
066cd967
DE
17572 || ((outer_code == IOR || outer_code == XOR)
17573 && CONST_DOUBLE_HIGH (x) == 0
17574 && (CONST_DOUBLE_LOW (x)
17575 & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0)))
17576 {
17577 *total = 0;
17578 return true;
17579 }
17580 else if (mode == DImode
17581 && (outer_code == SET
17582 || outer_code == IOR
17583 || outer_code == XOR)
17584 && CONST_DOUBLE_HIGH (x) == 0)
17585 {
17586 *total = COSTS_N_INSNS (1);
17587 return true;
17588 }
17589 /* FALLTHRU */
17590
3c50106f 17591 case CONST:
066cd967 17592 case HIGH:
3c50106f 17593 case SYMBOL_REF:
066cd967
DE
17594 case MEM:
17595 /* When optimizing for size, MEM should be slightly more expensive
17596 than generating address, e.g., (plus (reg) (const)).
c112cf2b 17597 L1 cache latency is about two instructions. */
066cd967 17598 *total = optimize_size ? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (2);
3c50106f
RH
17599 return true;
17600
30a555d9
DE
17601 case LABEL_REF:
17602 *total = 0;
17603 return true;
17604
3c50106f 17605 case PLUS:
f0517163 17606 if (mode == DFmode)
066cd967
DE
17607 {
17608 if (GET_CODE (XEXP (x, 0)) == MULT)
17609 {
17610 /* FNMA accounted in outer NEG. */
17611 if (outer_code == NEG)
17612 *total = rs6000_cost->dmul - rs6000_cost->fp;
17613 else
17614 *total = rs6000_cost->dmul;
17615 }
17616 else
17617 *total = rs6000_cost->fp;
17618 }
f0517163 17619 else if (mode == SFmode)
066cd967
DE
17620 {
17621 /* FNMA accounted in outer NEG. */
17622 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17623 *total = 0;
17624 else
17625 *total = rs6000_cost->fp;
17626 }
938bf747
RS
17627 else if (GET_CODE (XEXP (x, 0)) == MULT)
17628 {
17629 /* The rs6000 doesn't have shift-and-add instructions. */
17630 rs6000_rtx_costs (XEXP (x, 0), MULT, PLUS, total);
17631 *total += COSTS_N_INSNS (1);
17632 }
f0517163 17633 else
066cd967
DE
17634 *total = COSTS_N_INSNS (1);
17635 return false;
3c50106f 17636
52190329 17637 case MINUS:
f0517163 17638 if (mode == DFmode)
066cd967
DE
17639 {
17640 if (GET_CODE (XEXP (x, 0)) == MULT)
17641 {
17642 /* FNMA accounted in outer NEG. */
17643 if (outer_code == NEG)
17644 *total = 0;
17645 else
17646 *total = rs6000_cost->dmul;
17647 }
17648 else
17649 *total = rs6000_cost->fp;
17650 }
f0517163 17651 else if (mode == SFmode)
066cd967
DE
17652 {
17653 /* FNMA accounted in outer NEG. */
17654 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17655 *total = 0;
17656 else
17657 *total = rs6000_cost->fp;
17658 }
938bf747
RS
17659 else if (GET_CODE (XEXP (x, 0)) == MULT)
17660 {
17661 /* The rs6000 doesn't have shift-and-sub instructions. */
17662 rs6000_rtx_costs (XEXP (x, 0), MULT, MINUS, total);
17663 *total += COSTS_N_INSNS (1);
17664 }
f0517163 17665 else
c4ad648e 17666 *total = COSTS_N_INSNS (1);
066cd967 17667 return false;
3c50106f
RH
17668
17669 case MULT:
8b897cfa 17670 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3c50106f 17671 {
8b897cfa
RS
17672 if (INTVAL (XEXP (x, 1)) >= -256
17673 && INTVAL (XEXP (x, 1)) <= 255)
06a67bdd 17674 *total = rs6000_cost->mulsi_const9;
8b897cfa 17675 else
06a67bdd 17676 *total = rs6000_cost->mulsi_const;
3c50106f 17677 }
066cd967
DE
17678 /* FMA accounted in outer PLUS/MINUS. */
17679 else if ((mode == DFmode || mode == SFmode)
17680 && (outer_code == PLUS || outer_code == MINUS))
17681 *total = 0;
f0517163 17682 else if (mode == DFmode)
06a67bdd 17683 *total = rs6000_cost->dmul;
f0517163 17684 else if (mode == SFmode)
06a67bdd 17685 *total = rs6000_cost->fp;
f0517163 17686 else if (mode == DImode)
06a67bdd 17687 *total = rs6000_cost->muldi;
8b897cfa 17688 else
06a67bdd 17689 *total = rs6000_cost->mulsi;
066cd967 17690 return false;
3c50106f
RH
17691
17692 case DIV:
17693 case MOD:
f0517163
RS
17694 if (FLOAT_MODE_P (mode))
17695 {
06a67bdd
RS
17696 *total = mode == DFmode ? rs6000_cost->ddiv
17697 : rs6000_cost->sdiv;
066cd967 17698 return false;
f0517163 17699 }
5efb1046 17700 /* FALLTHRU */
3c50106f
RH
17701
17702 case UDIV:
17703 case UMOD:
627b6fe2
DJ
17704 if (GET_CODE (XEXP (x, 1)) == CONST_INT
17705 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
17706 {
17707 if (code == DIV || code == MOD)
17708 /* Shift, addze */
17709 *total = COSTS_N_INSNS (2);
17710 else
17711 /* Shift */
17712 *total = COSTS_N_INSNS (1);
17713 }
c4ad648e 17714 else
627b6fe2
DJ
17715 {
17716 if (GET_MODE (XEXP (x, 1)) == DImode)
17717 *total = rs6000_cost->divdi;
17718 else
17719 *total = rs6000_cost->divsi;
17720 }
17721 /* Add in shift and subtract for MOD. */
17722 if (code == MOD || code == UMOD)
17723 *total += COSTS_N_INSNS (2);
066cd967 17724 return false;
3c50106f
RH
17725
17726 case FFS:
17727 *total = COSTS_N_INSNS (4);
066cd967 17728 return false;
3c50106f 17729
06a67bdd 17730 case NOT:
066cd967
DE
17731 if (outer_code == AND || outer_code == IOR || outer_code == XOR)
17732 {
17733 *total = 0;
17734 return false;
17735 }
17736 /* FALLTHRU */
17737
17738 case AND:
17739 case IOR:
17740 case XOR:
d5861a7a
DE
17741 case ZERO_EXTRACT:
17742 *total = COSTS_N_INSNS (1);
17743 return false;
17744
066cd967
DE
17745 case ASHIFT:
17746 case ASHIFTRT:
17747 case LSHIFTRT:
17748 case ROTATE:
17749 case ROTATERT:
d5861a7a 17750 /* Handle mul_highpart. */
066cd967
DE
17751 if (outer_code == TRUNCATE
17752 && GET_CODE (XEXP (x, 0)) == MULT)
17753 {
17754 if (mode == DImode)
17755 *total = rs6000_cost->muldi;
17756 else
17757 *total = rs6000_cost->mulsi;
17758 return true;
17759 }
d5861a7a
DE
17760 else if (outer_code == AND)
17761 *total = 0;
17762 else
17763 *total = COSTS_N_INSNS (1);
17764 return false;
17765
17766 case SIGN_EXTEND:
17767 case ZERO_EXTEND:
17768 if (GET_CODE (XEXP (x, 0)) == MEM)
17769 *total = 0;
17770 else
17771 *total = COSTS_N_INSNS (1);
066cd967 17772 return false;
06a67bdd 17773
066cd967
DE
17774 case COMPARE:
17775 case NEG:
17776 case ABS:
17777 if (!FLOAT_MODE_P (mode))
17778 {
17779 *total = COSTS_N_INSNS (1);
17780 return false;
17781 }
17782 /* FALLTHRU */
17783
17784 case FLOAT:
17785 case UNSIGNED_FLOAT:
17786 case FIX:
17787 case UNSIGNED_FIX:
17788 case FLOAT_EXTEND:
06a67bdd
RS
17789 case FLOAT_TRUNCATE:
17790 *total = rs6000_cost->fp;
066cd967 17791 return false;
06a67bdd
RS
17792
17793 case UNSPEC:
17794 switch (XINT (x, 1))
17795 {
17796 case UNSPEC_FRSP:
17797 *total = rs6000_cost->fp;
17798 return true;
17799
17800 default:
17801 break;
17802 }
17803 break;
17804
17805 case CALL:
17806 case IF_THEN_ELSE:
17807 if (optimize_size)
17808 {
17809 *total = COSTS_N_INSNS (1);
17810 return true;
17811 }
066cd967
DE
17812 else if (FLOAT_MODE_P (mode)
17813 && TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS)
17814 {
17815 *total = rs6000_cost->fp;
17816 return false;
17817 }
17818
06a67bdd
RS
17819 break;
17820
3c50106f 17821 default:
06a67bdd 17822 break;
3c50106f 17823 }
06a67bdd
RS
17824
17825 return false;
3c50106f
RH
17826}
17827
34bb030a
DE
17828/* A C expression returning the cost of moving data from a register of class
17829 CLASS1 to one of CLASS2. */
17830
17831int
f676971a 17832rs6000_register_move_cost (enum machine_mode mode,
a2369ed3 17833 enum reg_class from, enum reg_class to)
34bb030a
DE
17834{
17835 /* Moves from/to GENERAL_REGS. */
17836 if (reg_classes_intersect_p (to, GENERAL_REGS)
17837 || reg_classes_intersect_p (from, GENERAL_REGS))
17838 {
17839 if (! reg_classes_intersect_p (to, GENERAL_REGS))
17840 from = to;
17841
17842 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
17843 return (rs6000_memory_move_cost (mode, from, 0)
17844 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
17845
c4ad648e
AM
17846 /* It's more expensive to move CR_REGS than CR0_REGS because of the
17847 shift. */
34bb030a
DE
17848 else if (from == CR_REGS)
17849 return 4;
17850
17851 else
c4ad648e 17852 /* A move will cost one instruction per GPR moved. */
34bb030a
DE
17853 return 2 * HARD_REGNO_NREGS (0, mode);
17854 }
17855
c4ad648e 17856 /* Moving between two similar registers is just one instruction. */
34bb030a
DE
17857 else if (reg_classes_intersect_p (to, from))
17858 return mode == TFmode ? 4 : 2;
17859
c4ad648e 17860 /* Everything else has to go through GENERAL_REGS. */
34bb030a 17861 else
f676971a 17862 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
34bb030a
DE
17863 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
17864}
17865
17866/* A C expressions returning the cost of moving data of MODE from a register to
17867 or from memory. */
17868
17869int
f676971a 17870rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
a2369ed3 17871 int in ATTRIBUTE_UNUSED)
34bb030a
DE
17872{
17873 if (reg_classes_intersect_p (class, GENERAL_REGS))
17874 return 4 * HARD_REGNO_NREGS (0, mode);
17875 else if (reg_classes_intersect_p (class, FLOAT_REGS))
17876 return 4 * HARD_REGNO_NREGS (32, mode);
17877 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
17878 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
17879 else
17880 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
17881}
17882
ded9bf77
AH
17883/* Return an RTX representing where to find the function value of a
17884 function returning MODE. */
17885static rtx
17886rs6000_complex_function_value (enum machine_mode mode)
17887{
17888 unsigned int regno;
17889 rtx r1, r2;
17890 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 17891 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77 17892
4ed78545 17893 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
ded9bf77
AH
17894 regno = FP_ARG_RETURN;
17895 else
17896 {
17897 regno = GP_ARG_RETURN;
17898
17899 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 17900 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
17901 return gen_rtx_REG (mode, regno);
17902 }
17903
fb7e4164
AM
17904 if (inner_bytes >= 8)
17905 return gen_rtx_REG (mode, regno);
17906
ded9bf77
AH
17907 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
17908 const0_rtx);
17909 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 17910 GEN_INT (inner_bytes));
ded9bf77
AH
17911 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
17912}
17913
a6ebc39a
AH
17914/* Define how to find the value returned by a function.
17915 VALTYPE is the data type of the value (as a tree).
17916 If the precise function being called is known, FUNC is its FUNCTION_DECL;
17917 otherwise, FUNC is 0.
17918
17919 On the SPE, both FPs and vectors are returned in r3.
17920
17921 On RS/6000 an integer value is in r3 and a floating-point value is in
17922 fp1, unless -msoft-float. */
17923
17924rtx
17925rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
17926{
17927 enum machine_mode mode;
2a8fa26c 17928 unsigned int regno;
a6ebc39a 17929
0e67400a
FJ
17930 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
17931 {
17932 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
17933 return gen_rtx_PARALLEL (DImode,
17934 gen_rtvec (2,
17935 gen_rtx_EXPR_LIST (VOIDmode,
17936 gen_rtx_REG (SImode, GP_ARG_RETURN),
17937 const0_rtx),
17938 gen_rtx_EXPR_LIST (VOIDmode,
17939 gen_rtx_REG (SImode,
17940 GP_ARG_RETURN + 1),
17941 GEN_INT (4))));
17942 }
17943
a6ebc39a
AH
17944 if ((INTEGRAL_TYPE_P (valtype)
17945 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
17946 || POINTER_TYPE_P (valtype))
b78d48dd 17947 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
17948 else
17949 mode = TYPE_MODE (valtype);
17950
4ed78545 17951 if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS)
2a8fa26c 17952 regno = FP_ARG_RETURN;
ded9bf77 17953 else if (TREE_CODE (valtype) == COMPLEX_TYPE
42ba5130 17954 && targetm.calls.split_complex_arg)
ded9bf77 17955 return rs6000_complex_function_value (mode);
44688022 17956 else if (TREE_CODE (valtype) == VECTOR_TYPE
d0b2079e
FJ
17957 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI
17958 && ALTIVEC_VECTOR_MODE(mode))
a6ebc39a
AH
17959 regno = ALTIVEC_ARG_RETURN;
17960 else
17961 regno = GP_ARG_RETURN;
17962
17963 return gen_rtx_REG (mode, regno);
17964}
17965
ded9bf77
AH
17966/* Define how to find the value returned by a library function
17967 assuming the value has mode MODE. */
17968rtx
17969rs6000_libcall_value (enum machine_mode mode)
17970{
17971 unsigned int regno;
17972
2e6c9641
FJ
17973 if (TARGET_32BIT && TARGET_POWERPC64 && mode == DImode)
17974 {
17975 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
17976 return gen_rtx_PARALLEL (DImode,
17977 gen_rtvec (2,
17978 gen_rtx_EXPR_LIST (VOIDmode,
17979 gen_rtx_REG (SImode, GP_ARG_RETURN),
17980 const0_rtx),
17981 gen_rtx_EXPR_LIST (VOIDmode,
17982 gen_rtx_REG (SImode,
17983 GP_ARG_RETURN + 1),
17984 GEN_INT (4))));
17985 }
17986
ded9bf77
AH
17987 if (GET_MODE_CLASS (mode) == MODE_FLOAT
17988 && TARGET_HARD_FLOAT && TARGET_FPRS)
17989 regno = FP_ARG_RETURN;
44688022
AM
17990 else if (ALTIVEC_VECTOR_MODE (mode)
17991 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
ded9bf77 17992 regno = ALTIVEC_ARG_RETURN;
42ba5130 17993 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
17994 return rs6000_complex_function_value (mode);
17995 else
17996 regno = GP_ARG_RETURN;
17997
17998 return gen_rtx_REG (mode, regno);
17999}
18000
d1d0c603
JJ
18001/* Define the offset between two registers, FROM to be eliminated and its
18002 replacement TO, at the start of a routine. */
18003HOST_WIDE_INT
18004rs6000_initial_elimination_offset (int from, int to)
18005{
18006 rs6000_stack_t *info = rs6000_stack_info ();
18007 HOST_WIDE_INT offset;
18008
18009 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
18010 offset = info->push_p ? 0 : -info->total_size;
18011 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
18012 offset = info->total_size;
18013 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
18014 offset = info->push_p ? info->total_size : 0;
18015 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
18016 offset = 0;
18017 else
18018 abort ();
18019
18020 return offset;
18021}
18022
62e1dfcf
NC
18023/* Return true if TYPE is of type __ev64_opaque__. */
18024
c8e4f0e9 18025static bool
a2369ed3 18026is_ev64_opaque_type (tree type)
62e1dfcf 18027{
c8e4f0e9 18028 return (TARGET_SPE
2abe3e28
AH
18029 && (type == opaque_V2SI_type_node
18030 || type == opaque_V2SF_type_node
36252949 18031 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
18032}
18033
96714395 18034static rtx
a2369ed3 18035rs6000_dwarf_register_span (rtx reg)
96714395
AH
18036{
18037 unsigned regno;
18038
18039 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
18040 return NULL_RTX;
18041
18042 regno = REGNO (reg);
18043
18044 /* The duality of the SPE register size wreaks all kinds of havoc.
18045 This is a way of distinguishing r0 in 32-bits from r0 in
18046 64-bits. */
18047 return
18048 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
18049 BYTES_BIG_ENDIAN
18050 ? gen_rtvec (2,
18051 gen_rtx_REG (SImode, regno + 1200),
18052 gen_rtx_REG (SImode, regno))
18053 : gen_rtvec (2,
18054 gen_rtx_REG (SImode, regno),
18055 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
18056}
18057
93c9d1ba
AM
18058/* Map internal gcc register numbers to DWARF2 register numbers. */
18059
18060unsigned int
18061rs6000_dbx_register_number (unsigned int regno)
18062{
18063 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
18064 return regno;
18065 if (regno == MQ_REGNO)
18066 return 100;
18067 if (regno == LINK_REGISTER_REGNUM)
18068 return 108;
18069 if (regno == COUNT_REGISTER_REGNUM)
18070 return 109;
18071 if (CR_REGNO_P (regno))
18072 return regno - CR0_REGNO + 86;
18073 if (regno == XER_REGNO)
18074 return 101;
18075 if (ALTIVEC_REGNO_P (regno))
18076 return regno - FIRST_ALTIVEC_REGNO + 1124;
18077 if (regno == VRSAVE_REGNO)
18078 return 356;
18079 if (regno == VSCR_REGNO)
18080 return 67;
18081 if (regno == SPE_ACC_REGNO)
18082 return 99;
18083 if (regno == SPEFSCR_REGNO)
18084 return 612;
18085 /* SPE high reg number. We get these values of regno from
18086 rs6000_dwarf_register_span. */
18087 if (regno >= 1200 && regno < 1232)
18088 return regno;
18089
18090 abort ();
18091}
18092
93f90be6 18093/* target hook eh_return_filter_mode */
f676971a 18094static enum machine_mode
93f90be6
FJ
18095rs6000_eh_return_filter_mode (void)
18096{
18097 return TARGET_32BIT ? SImode : word_mode;
18098}
18099
f676971a
EC
18100/* Target hook for vector_mode_supported_p. */
18101static bool
18102rs6000_vector_mode_supported_p (enum machine_mode mode)
18103{
18104
18105 if (TARGET_SPE && SPE_VECTOR_MODE (mode))
18106 return true;
18107
18108 else if (TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
18109 return true;
18110
18111 else
18112 return false;
18113}
18114
17211ab5 18115#include "gt-rs6000.h"