]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
natClass.cc (_Jv_LayoutVTableMethods): Cast pointers to uaddr, not int.
[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 145/* Support targetm.vectorize.builtin_mask_for_load. */
13c62176 146static GTY(()) tree altivec_builtin_mask_for_load;
7ccf35ed 147/* Support targetm.vectorize.builtin_mask_for_store. */
13c62176 148static GTY(()) tree altivec_builtin_mask_for_store;
7ccf35ed 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);
c4e18b1c 757static void rs6000_darwin_file_start (void);
efdba735
SH
758#endif
759
c35d187f 760static tree rs6000_build_builtin_va_list (void);
23a60a04 761static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *);
fe984136 762static bool rs6000_must_pass_in_stack (enum machine_mode, tree);
f676971a 763static bool rs6000_vector_mode_supported_p (enum machine_mode);
21213b4c
DP
764static int get_vec_cmp_insn (enum rtx_code, enum machine_mode,
765 enum machine_mode);
766static rtx rs6000_emit_vector_compare (enum rtx_code, rtx, rtx,
767 enum machine_mode);
768static int get_vsel_insn (enum machine_mode);
769static void rs6000_emit_vector_select (rtx, rtx, rtx, rtx);
17211ab5 770
21213b4c
DP
771
772const int INSN_NOT_AVAILABLE = -1;
93f90be6
FJ
773static enum machine_mode rs6000_eh_return_filter_mode (void);
774
17211ab5
GK
775/* Hash table stuff for keeping track of TOC entries. */
776
777struct toc_hash_struct GTY(())
778{
779 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
780 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
781 rtx key;
782 enum machine_mode key_mode;
783 int labelno;
784};
785
786static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
787\f
788/* Default register names. */
789char rs6000_reg_names[][8] =
790{
802a0058
MM
791 "0", "1", "2", "3", "4", "5", "6", "7",
792 "8", "9", "10", "11", "12", "13", "14", "15",
793 "16", "17", "18", "19", "20", "21", "22", "23",
794 "24", "25", "26", "27", "28", "29", "30", "31",
795 "0", "1", "2", "3", "4", "5", "6", "7",
796 "8", "9", "10", "11", "12", "13", "14", "15",
797 "16", "17", "18", "19", "20", "21", "22", "23",
798 "24", "25", "26", "27", "28", "29", "30", "31",
799 "mq", "lr", "ctr","ap",
800 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
801 "xer",
802 /* AltiVec registers. */
0cd5e3a1
AH
803 "0", "1", "2", "3", "4", "5", "6", "7",
804 "8", "9", "10", "11", "12", "13", "14", "15",
805 "16", "17", "18", "19", "20", "21", "22", "23",
806 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
807 "vrsave", "vscr",
808 /* SPE registers. */
809 "spe_acc", "spefscr"
c81bebd7
MM
810};
811
812#ifdef TARGET_REGNAMES
8b60264b 813static const char alt_reg_names[][8] =
c81bebd7 814{
802a0058
MM
815 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
816 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
817 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
818 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
819 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
820 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
821 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
822 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
823 "mq", "lr", "ctr", "ap",
824 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 825 "xer",
59a4c851 826 /* AltiVec registers. */
0ac081f6 827 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
828 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
829 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
830 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
831 "vrsave", "vscr",
832 /* SPE registers. */
833 "spe_acc", "spefscr"
c81bebd7
MM
834};
835#endif
9878760c 836\f
daf11973
MM
837#ifndef MASK_STRICT_ALIGN
838#define MASK_STRICT_ALIGN 0
839#endif
ffcfcb5f
AM
840#ifndef TARGET_PROFILE_KERNEL
841#define TARGET_PROFILE_KERNEL 0
842#endif
3961e8fe
RH
843
844/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
845#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
846
847/* Return 1 for a symbol ref for a thread-local storage symbol. */
848#define RS6000_SYMBOL_REF_TLS_P(RTX) \
849 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
850\f
851/* Initialize the GCC target structure. */
91d231cb
JM
852#undef TARGET_ATTRIBUTE_TABLE
853#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
854#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
855#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 856
301d03af
RS
857#undef TARGET_ASM_ALIGNED_DI_OP
858#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
859
860/* Default unaligned ops are only provided for ELF. Find the ops needed
861 for non-ELF systems. */
862#ifndef OBJECT_FORMAT_ELF
cbaaba19 863#if TARGET_XCOFF
ae6c1efd 864/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
865 64-bit targets. */
866#undef TARGET_ASM_UNALIGNED_HI_OP
867#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
868#undef TARGET_ASM_UNALIGNED_SI_OP
869#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
870#undef TARGET_ASM_UNALIGNED_DI_OP
871#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
872#else
873/* For Darwin. */
874#undef TARGET_ASM_UNALIGNED_HI_OP
875#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
876#undef TARGET_ASM_UNALIGNED_SI_OP
877#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
49bd1d27
SS
878#undef TARGET_ASM_UNALIGNED_DI_OP
879#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
880#undef TARGET_ASM_ALIGNED_DI_OP
881#define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
301d03af
RS
882#endif
883#endif
884
885/* This hook deals with fixups for relocatable code and DI-mode objects
886 in 64-bit code. */
887#undef TARGET_ASM_INTEGER
888#define TARGET_ASM_INTEGER rs6000_assemble_integer
889
93638d7a
AM
890#ifdef HAVE_GAS_HIDDEN
891#undef TARGET_ASM_ASSEMBLE_VISIBILITY
892#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
893#endif
894
c4501e62
JJ
895#undef TARGET_HAVE_TLS
896#define TARGET_HAVE_TLS HAVE_AS_TLS
897
898#undef TARGET_CANNOT_FORCE_CONST_MEM
899#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
900
08c148a8
NB
901#undef TARGET_ASM_FUNCTION_PROLOGUE
902#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
903#undef TARGET_ASM_FUNCTION_EPILOGUE
904#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
905
b54cf83a
DE
906#undef TARGET_SCHED_VARIABLE_ISSUE
907#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
908
c237e94a
ZW
909#undef TARGET_SCHED_ISSUE_RATE
910#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
911#undef TARGET_SCHED_ADJUST_COST
912#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
913#undef TARGET_SCHED_ADJUST_PRIORITY
914#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
f676971a 915#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
569fa502 916#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
917#undef TARGET_SCHED_FINISH
918#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 919
be12c2b0
VM
920#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
921#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
922
7ccf35ed
DN
923#undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
924#define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load
925
926#undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE
927#define TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE rs6000_builtin_mask_for_store
928
0ac081f6
AH
929#undef TARGET_INIT_BUILTINS
930#define TARGET_INIT_BUILTINS rs6000_init_builtins
931
932#undef TARGET_EXPAND_BUILTIN
933#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
934
f18eca82
ZL
935#undef TARGET_MANGLE_FUNDAMENTAL_TYPE
936#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
937
c15c90bb
ZW
938#undef TARGET_INIT_LIBFUNCS
939#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
940
f1384257 941#if TARGET_MACHO
0e5dbd9b
DE
942#undef TARGET_BINDS_LOCAL_P
943#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 944#endif
0e5dbd9b 945
3961e8fe
RH
946#undef TARGET_ASM_OUTPUT_MI_THUNK
947#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
948
3961e8fe 949#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 950#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 951
4977bab6
ZW
952#undef TARGET_FUNCTION_OK_FOR_SIBCALL
953#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
954
3c50106f
RH
955#undef TARGET_RTX_COSTS
956#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
957#undef TARGET_ADDRESS_COST
958#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 959
c8e4f0e9
AH
960#undef TARGET_VECTOR_OPAQUE_P
961#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 962
96714395
AH
963#undef TARGET_DWARF_REGISTER_SPAN
964#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
965
c6e8c921
GK
966/* On rs6000, function arguments are promoted, as are function return
967 values. */
968#undef TARGET_PROMOTE_FUNCTION_ARGS
969#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
970#undef TARGET_PROMOTE_FUNCTION_RETURN
971#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
972
c6e8c921
GK
973#undef TARGET_RETURN_IN_MEMORY
974#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
975
976#undef TARGET_SETUP_INCOMING_VARARGS
977#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
978
979/* Always strict argument naming on rs6000. */
980#undef TARGET_STRICT_ARGUMENT_NAMING
981#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
982#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
983#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
984#undef TARGET_SPLIT_COMPLEX_ARG
985#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
fe984136
RH
986#undef TARGET_MUST_PASS_IN_STACK
987#define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
8cd5a4e0
RH
988#undef TARGET_PASS_BY_REFERENCE
989#define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
c6e8c921 990
c35d187f
RH
991#undef TARGET_BUILD_BUILTIN_VA_LIST
992#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
993
cd3ce9b4
JM
994#undef TARGET_GIMPLIFY_VA_ARG_EXPR
995#define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
996
93f90be6
FJ
997#undef TARGET_EH_RETURN_FILTER_MODE
998#define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
999
f676971a
EC
1000#undef TARGET_VECTOR_MODE_SUPPORTED_P
1001#define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
1002
f6897b10 1003struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 1004\f
0d1fbc8c
AH
1005
1006/* Value is 1 if hard register REGNO can hold a value of machine-mode
1007 MODE. */
1008static int
1009rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
1010{
1011 /* The GPRs can hold any mode, but values bigger than one register
1012 cannot go past R31. */
1013 if (INT_REGNO_P (regno))
1014 return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1);
1015
1016 /* The float registers can only hold floating modes and DImode. */
1017 if (FP_REGNO_P (regno))
1018 return
1019 (GET_MODE_CLASS (mode) == MODE_FLOAT
1020 && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1))
1021 || (GET_MODE_CLASS (mode) == MODE_INT
1022 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD);
1023
1024 /* The CR register can only hold CC modes. */
1025 if (CR_REGNO_P (regno))
1026 return GET_MODE_CLASS (mode) == MODE_CC;
1027
1028 if (XER_REGNO_P (regno))
1029 return mode == PSImode;
1030
1031 /* AltiVec only in AldyVec registers. */
1032 if (ALTIVEC_REGNO_P (regno))
1033 return ALTIVEC_VECTOR_MODE (mode);
1034
1035 /* ...but GPRs can hold SIMD data on the SPE in one register. */
1036 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1037 return 1;
1038
1039 /* We cannot put TImode anywhere except general register and it must be
1040 able to fit within the register set. */
1041
1042 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1043}
1044
1045/* Initialize rs6000_hard_regno_mode_ok_p table. */
1046static void
1047rs6000_init_hard_regno_mode_ok (void)
1048{
1049 int r, m;
1050
1051 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
1052 for (m = 0; m < NUM_MACHINE_MODES; ++m)
1053 if (rs6000_hard_regno_mode_ok (r, m))
1054 rs6000_hard_regno_mode_ok_p[m][r] = true;
1055}
1056
c1e55850
GK
1057/* If not otherwise specified by a target, make 'long double' equivalent to
1058 'double'. */
1059
1060#ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
1061#define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
1062#endif
1063
5248c961
RK
1064/* Override command line options. Mostly we process the processor
1065 type and sometimes adjust other TARGET_ options. */
1066
1067void
d779d0dc 1068rs6000_override_options (const char *default_cpu)
5248c961 1069{
c4d38ccb 1070 size_t i, j;
8e3f41e7 1071 struct rs6000_cpu_select *ptr;
66188a7e 1072 int set_masks;
5248c961 1073
66188a7e 1074 /* Simplifications for entries below. */
85638c0d 1075
66188a7e
GK
1076 enum {
1077 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
1078 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
1079 };
85638c0d 1080
66188a7e
GK
1081 /* This table occasionally claims that a processor does not support
1082 a particular feature even though it does, but the feature is slower
1083 than the alternative. Thus, it shouldn't be relied on as a
f676971a 1084 complete description of the processor's support.
66188a7e
GK
1085
1086 Please keep this list in order, and don't forget to update the
1087 documentation in invoke.texi when adding a new processor or
1088 flag. */
5248c961
RK
1089 static struct ptt
1090 {
8b60264b
KG
1091 const char *const name; /* Canonical processor name. */
1092 const enum processor_type processor; /* Processor type enum value. */
1093 const int target_enable; /* Target flags to enable. */
8b60264b 1094 } const processor_target_table[]
66188a7e 1095 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 1096 {"403", PROCESSOR_PPC403,
66188a7e
GK
1097 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
1098 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1099 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
1100 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1101 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
1102 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 1103 {"601", PROCESSOR_PPC601,
66188a7e
GK
1104 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
1105 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1106 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1107 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1108 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1109 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
1110 {"620", PROCESSOR_PPC620,
1111 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1112 {"630", PROCESSOR_PPC630,
1113 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
1114 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1115 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
1116 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1117 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1118 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1119 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1120 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1121 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1122 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 1123 {"970", PROCESSOR_POWER4,
66188a7e
GK
1124 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1125 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
1126 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1127 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1128 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 1129 {"G5", PROCESSOR_POWER4,
66188a7e
GK
1130 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1131 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1132 {"power2", PROCESSOR_POWER,
1133 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
1134 {"power3", PROCESSOR_PPC630,
1135 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1136 {"power4", PROCESSOR_POWER4,
fc091c8e 1137 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
ec507f2d 1138 {"power5", PROCESSOR_POWER5,
fc091c8e 1139 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
66188a7e
GK
1140 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
1141 {"powerpc64", PROCESSOR_POWERPC64,
1142 POWERPC_BASE_MASK | MASK_POWERPC64},
1143 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1144 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1145 {"rios2", PROCESSOR_RIOS2,
1146 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1147 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1148 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 1149 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 1150 };
5248c961 1151
ca7558fc 1152 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 1153
66188a7e
GK
1154 /* Some OSs don't support saving the high part of 64-bit registers on
1155 context switch. Other OSs don't support saving Altivec registers.
1156 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
1157 settings; if the user wants either, the user must explicitly specify
1158 them and we won't interfere with the user's specification. */
1159
1160 enum {
1161 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
f676971a 1162 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
66188a7e
GK
1163 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
1164 | MASK_MFCRF)
1165 };
0d1fbc8c
AH
1166
1167 rs6000_init_hard_regno_mode_ok ();
1168
c4ad648e 1169 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
66188a7e
GK
1170#ifdef OS_MISSING_POWERPC64
1171 if (OS_MISSING_POWERPC64)
1172 set_masks &= ~MASK_POWERPC64;
1173#endif
1174#ifdef OS_MISSING_ALTIVEC
1175 if (OS_MISSING_ALTIVEC)
1176 set_masks &= ~MASK_ALTIVEC;
1177#endif
1178
957211c3
AM
1179 /* Don't override these by the processor default if given explicitly. */
1180 set_masks &= ~(target_flags_explicit
1181 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
1182
a4f6c312 1183 /* Identify the processor type. */
8e3f41e7 1184 rs6000_select[0].string = default_cpu;
3cb999d8 1185 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 1186
b6a1cbae 1187 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 1188 {
8e3f41e7
MM
1189 ptr = &rs6000_select[i];
1190 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 1191 {
8e3f41e7
MM
1192 for (j = 0; j < ptt_size; j++)
1193 if (! strcmp (ptr->string, processor_target_table[j].name))
1194 {
1195 if (ptr->set_tune_p)
1196 rs6000_cpu = processor_target_table[j].processor;
1197
1198 if (ptr->set_arch_p)
1199 {
66188a7e
GK
1200 target_flags &= ~set_masks;
1201 target_flags |= (processor_target_table[j].target_enable
1202 & set_masks);
8e3f41e7
MM
1203 }
1204 break;
1205 }
1206
4406229e 1207 if (j == ptt_size)
8e3f41e7 1208 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
1209 }
1210 }
8a61d227 1211
993f19a8 1212 if (TARGET_E500)
a3170dc6
AH
1213 rs6000_isel = 1;
1214
dff9f1b6
DE
1215 /* If we are optimizing big endian systems for space, use the load/store
1216 multiple and string instructions. */
ef792183 1217 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 1218 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 1219
a4f6c312
SS
1220 /* Don't allow -mmultiple or -mstring on little endian systems
1221 unless the cpu is a 750, because the hardware doesn't support the
1222 instructions used in little endian mode, and causes an alignment
1223 trap. The 750 does not cause an alignment trap (except when the
1224 target is unaligned). */
bef84347 1225
b21fb038 1226 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
1227 {
1228 if (TARGET_MULTIPLE)
1229 {
1230 target_flags &= ~MASK_MULTIPLE;
b21fb038 1231 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
1232 warning ("-mmultiple is not supported on little endian systems");
1233 }
1234
1235 if (TARGET_STRING)
1236 {
1237 target_flags &= ~MASK_STRING;
b21fb038 1238 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 1239 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
1240 }
1241 }
3933e0e1 1242
38c1f2d7
MM
1243 /* Set debug flags */
1244 if (rs6000_debug_name)
1245 {
bfc79d3b 1246 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 1247 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 1248 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 1249 rs6000_debug_stack = 1;
bfc79d3b 1250 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
1251 rs6000_debug_arg = 1;
1252 else
c725bd79 1253 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
1254 }
1255
57ac7be9
AM
1256 if (rs6000_traceback_name)
1257 {
1258 if (! strncmp (rs6000_traceback_name, "full", 4))
1259 rs6000_traceback = traceback_full;
1260 else if (! strncmp (rs6000_traceback_name, "part", 4))
1261 rs6000_traceback = traceback_part;
1262 else if (! strncmp (rs6000_traceback_name, "no", 2))
1263 rs6000_traceback = traceback_none;
1264 else
1265 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
1266 rs6000_traceback_name);
1267 }
1268
6fa3f289 1269 /* Set size of long double */
c1e55850 1270 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
6fa3f289
ZW
1271 if (rs6000_long_double_size_string)
1272 {
1273 char *tail;
1274 int size = strtol (rs6000_long_double_size_string, &tail, 10);
1275 if (*tail != '\0' || (size != 64 && size != 128))
1276 error ("Unknown switch -mlong-double-%s",
1277 rs6000_long_double_size_string);
1278 else
1279 rs6000_long_double_type_size = size;
1280 }
1281
6d0ef01e
HP
1282 /* Set Altivec ABI as default for powerpc64 linux. */
1283 if (TARGET_ELF && TARGET_64BIT)
1284 {
1285 rs6000_altivec_abi = 1;
1286 rs6000_altivec_vrsave = 1;
1287 }
1288
0ac081f6
AH
1289 /* Handle -mabi= options. */
1290 rs6000_parse_abi_options ();
1291
025d9908
KH
1292 /* Handle -malign-XXXXX option. */
1293 rs6000_parse_alignment_option ();
1294
5da702b1
AH
1295 /* Handle generic -mFOO=YES/NO options. */
1296 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
1297 &rs6000_altivec_vrsave);
1298 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
1299 &rs6000_isel);
1300 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
1301 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
1302 &rs6000_float_gprs);
993f19a8 1303
c4501e62
JJ
1304 /* Handle -mtls-size option. */
1305 rs6000_parse_tls_size_option ();
1306
a7ae18e2
AH
1307#ifdef SUBTARGET_OVERRIDE_OPTIONS
1308 SUBTARGET_OVERRIDE_OPTIONS;
1309#endif
1310#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
1311 SUBSUBTARGET_OVERRIDE_OPTIONS;
1312#endif
1313
5da702b1
AH
1314 if (TARGET_E500)
1315 {
e4463bf1
AH
1316 if (TARGET_ALTIVEC)
1317 error ("AltiVec and E500 instructions cannot coexist");
1318
5da702b1
AH
1319 /* The e500 does not have string instructions, and we set
1320 MASK_STRING above when optimizing for size. */
1321 if ((target_flags & MASK_STRING) != 0)
1322 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
1323
1324 /* No SPE means 64-bit long doubles, even if an E500. */
1325 if (rs6000_spe_string != 0
c4ad648e 1326 && !strcmp (rs6000_spe_string, "no"))
b6e59a3a 1327 rs6000_long_double_type_size = 64;
5da702b1
AH
1328 }
1329 else if (rs6000_select[1].string != NULL)
1330 {
1331 /* For the powerpc-eabispe configuration, we set all these by
1332 default, so let's unset them if we manually set another
1333 CPU that is not the E500. */
1334 if (rs6000_abi_string == 0)
1335 rs6000_spe_abi = 0;
1336 if (rs6000_spe_string == 0)
1337 rs6000_spe = 0;
1338 if (rs6000_float_gprs_string == 0)
1339 rs6000_float_gprs = 0;
1340 if (rs6000_isel_string == 0)
1341 rs6000_isel = 0;
b6e59a3a 1342 if (rs6000_long_double_size_string == 0)
c1e55850 1343 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
5da702b1 1344 }
b5044283 1345
ec507f2d
DE
1346 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
1347 && rs6000_cpu != PROCESSOR_POWER5);
1348 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
1349 || rs6000_cpu == PROCESSOR_POWER5);
1350
a5c76ee6
ZW
1351 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
1352 using TARGET_OPTIONS to handle a toggle switch, but we're out of
1353 bits in target_flags so TARGET_SWITCHES cannot be used.
1354 Assumption here is that rs6000_longcall_switch points into the
1355 text of the complete option, rather than being a copy, so we can
1356 scan back for the presence or absence of the no- modifier. */
1357 if (rs6000_longcall_switch)
1358 {
1359 const char *base = rs6000_longcall_switch;
1360 while (base[-1] != 'm') base--;
1361
1362 if (*rs6000_longcall_switch != '\0')
1363 error ("invalid option `%s'", base);
1364 rs6000_default_long_calls = (base[0] != 'n');
1365 }
1366
8bb418a3
ZL
1367 /* Handle -m(no-)warn-altivec-long similarly. */
1368 if (rs6000_warn_altivec_long_switch)
1369 {
1370 const char *base = rs6000_warn_altivec_long_switch;
1371 while (base[-1] != 'm') base--;
1372
1373 if (*rs6000_warn_altivec_long_switch != '\0')
1374 error ("invalid option `%s'", base);
1375 rs6000_warn_altivec_long = (base[0] != 'n');
1376 }
1377
cbe26ab8 1378 /* Handle -mprioritize-restricted-insns option. */
ec507f2d
DE
1379 rs6000_sched_restricted_insns_priority
1380 = (rs6000_sched_groups ? 1 : 0);
79ae11c4
DN
1381 if (rs6000_sched_restricted_insns_priority_str)
1382 rs6000_sched_restricted_insns_priority =
1383 atoi (rs6000_sched_restricted_insns_priority_str);
1384
569fa502 1385 /* Handle -msched-costly-dep option. */
ec507f2d
DE
1386 rs6000_sched_costly_dep
1387 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
569fa502
DN
1388 if (rs6000_sched_costly_dep_str)
1389 {
f676971a 1390 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
c4ad648e 1391 rs6000_sched_costly_dep = no_dep_costly;
569fa502 1392 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
c4ad648e 1393 rs6000_sched_costly_dep = all_deps_costly;
569fa502 1394 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
c4ad648e 1395 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
569fa502 1396 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
c4ad648e 1397 rs6000_sched_costly_dep = store_to_load_dep_costly;
f676971a 1398 else
c4ad648e 1399 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
cbe26ab8
DN
1400 }
1401
1402 /* Handle -minsert-sched-nops option. */
ec507f2d
DE
1403 rs6000_sched_insert_nops
1404 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
cbe26ab8
DN
1405 if (rs6000_sched_insert_nops_str)
1406 {
1407 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
c4ad648e 1408 rs6000_sched_insert_nops = sched_finish_none;
cbe26ab8 1409 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
c4ad648e 1410 rs6000_sched_insert_nops = sched_finish_pad_groups;
cbe26ab8 1411 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
c4ad648e 1412 rs6000_sched_insert_nops = sched_finish_regroup_exact;
cbe26ab8 1413 else
c4ad648e 1414 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
1415 }
1416
c81bebd7 1417#ifdef TARGET_REGNAMES
a4f6c312
SS
1418 /* If the user desires alternate register names, copy in the
1419 alternate names now. */
c81bebd7 1420 if (TARGET_REGNAMES)
4e135bdd 1421 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
1422#endif
1423
6fa3f289
ZW
1424 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
1425 If -maix-struct-return or -msvr4-struct-return was explicitly
1426 used, don't override with the ABI default. */
b21fb038 1427 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
1428 {
1429 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
1430 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
1431 else
1432 target_flags |= MASK_AIX_STRUCT_RET;
1433 }
1434
fcce224d
DE
1435 if (TARGET_LONG_DOUBLE_128
1436 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 1437 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 1438
9ebbca7d
GK
1439 /* Allocate an alias set for register saves & restores from stack. */
1440 rs6000_sr_alias_set = new_alias_set ();
1441
f676971a 1442 if (TARGET_TOC)
9ebbca7d 1443 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 1444
301d03af
RS
1445 /* We can only guarantee the availability of DI pseudo-ops when
1446 assembling for 64-bit targets. */
ae6c1efd 1447 if (!TARGET_64BIT)
301d03af
RS
1448 {
1449 targetm.asm_out.aligned_op.di = NULL;
1450 targetm.asm_out.unaligned_op.di = NULL;
1451 }
1452
1494c534
DE
1453 /* Set branch target alignment, if not optimizing for size. */
1454 if (!optimize_size)
1455 {
1456 if (rs6000_sched_groups)
1457 {
1458 if (align_functions <= 0)
1459 align_functions = 16;
1460 if (align_jumps <= 0)
1461 align_jumps = 16;
1462 if (align_loops <= 0)
1463 align_loops = 16;
1464 }
1465 if (align_jumps_max_skip <= 0)
1466 align_jumps_max_skip = 15;
1467 if (align_loops_max_skip <= 0)
1468 align_loops_max_skip = 15;
1469 }
2792d578 1470
71f123ca
FS
1471 /* Arrange to save and restore machine status around nested functions. */
1472 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1473
1474 /* We should always be splitting complex arguments, but we can't break
1475 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1476 if (DEFAULT_ABI != ABI_AIX)
1477 targetm.calls.split_complex_arg = NULL;
8b897cfa
RS
1478
1479 /* Initialize rs6000_cost with the appropriate target costs. */
1480 if (optimize_size)
1481 rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
1482 else
1483 switch (rs6000_cpu)
1484 {
1485 case PROCESSOR_RIOS1:
1486 rs6000_cost = &rios1_cost;
1487 break;
1488
1489 case PROCESSOR_RIOS2:
1490 rs6000_cost = &rios2_cost;
1491 break;
1492
1493 case PROCESSOR_RS64A:
1494 rs6000_cost = &rs64a_cost;
1495 break;
1496
1497 case PROCESSOR_MPCCORE:
1498 rs6000_cost = &mpccore_cost;
1499 break;
1500
1501 case PROCESSOR_PPC403:
1502 rs6000_cost = &ppc403_cost;
1503 break;
1504
1505 case PROCESSOR_PPC405:
1506 rs6000_cost = &ppc405_cost;
1507 break;
1508
1509 case PROCESSOR_PPC440:
1510 rs6000_cost = &ppc440_cost;
1511 break;
1512
1513 case PROCESSOR_PPC601:
1514 rs6000_cost = &ppc601_cost;
1515 break;
1516
1517 case PROCESSOR_PPC603:
1518 rs6000_cost = &ppc603_cost;
1519 break;
1520
1521 case PROCESSOR_PPC604:
1522 rs6000_cost = &ppc604_cost;
1523 break;
1524
1525 case PROCESSOR_PPC604e:
1526 rs6000_cost = &ppc604e_cost;
1527 break;
1528
1529 case PROCESSOR_PPC620:
8b897cfa
RS
1530 rs6000_cost = &ppc620_cost;
1531 break;
1532
f0517163
RS
1533 case PROCESSOR_PPC630:
1534 rs6000_cost = &ppc630_cost;
1535 break;
1536
8b897cfa
RS
1537 case PROCESSOR_PPC750:
1538 case PROCESSOR_PPC7400:
1539 rs6000_cost = &ppc750_cost;
1540 break;
1541
1542 case PROCESSOR_PPC7450:
1543 rs6000_cost = &ppc7450_cost;
1544 break;
1545
1546 case PROCESSOR_PPC8540:
1547 rs6000_cost = &ppc8540_cost;
1548 break;
1549
1550 case PROCESSOR_POWER4:
1551 case PROCESSOR_POWER5:
1552 rs6000_cost = &power4_cost;
1553 break;
1554
1555 default:
1556 abort ();
1557 }
5248c961 1558}
5accd822 1559
7ccf35ed
DN
1560/* Implement targetm.vectorize.builtin_mask_for_load. */
1561static tree
1562rs6000_builtin_mask_for_load (void)
1563{
1564 if (TARGET_ALTIVEC)
1565 return altivec_builtin_mask_for_load;
1566 else
1567 return 0;
1568}
1569
1570/* Implement targetm.vectorize.builtin_mask_for_store. */
1571static tree
1572rs6000_builtin_mask_for_store (void)
1573{
1574 if (TARGET_ALTIVEC)
1575 return altivec_builtin_mask_for_store;
1576 else
1577 return 0;
1578}
1579
5da702b1
AH
1580/* Handle generic options of the form -mfoo=yes/no.
1581 NAME is the option name.
1582 VALUE is the option value.
1583 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1584 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1585static void
5da702b1 1586rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1587{
5da702b1 1588 if (value == 0)
993f19a8 1589 return;
5da702b1
AH
1590 else if (!strcmp (value, "yes"))
1591 *flag = 1;
1592 else if (!strcmp (value, "no"))
1593 *flag = 0;
08b57fb3 1594 else
5da702b1 1595 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1596}
1597
0ac081f6 1598/* Handle -mabi= options. */
00b960c7 1599static void
863d938c 1600rs6000_parse_abi_options (void)
0ac081f6
AH
1601{
1602 if (rs6000_abi_string == 0)
1603 return;
1604 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1605 {
1606 rs6000_altivec_abi = 1;
1607 rs6000_spe_abi = 0;
1608 }
76a773f3
AH
1609 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1610 rs6000_altivec_abi = 0;
a3170dc6 1611 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1612 {
1613 rs6000_spe_abi = 1;
5cc73f91 1614 rs6000_altivec_abi = 0;
01f4962d
NS
1615 if (!TARGET_SPE_ABI)
1616 error ("not configured for ABI: '%s'", rs6000_abi_string);
1617 }
f676971a 1618
a3170dc6
AH
1619 else if (! strcmp (rs6000_abi_string, "no-spe"))
1620 rs6000_spe_abi = 0;
0ac081f6 1621 else
c725bd79 1622 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1623}
1624
025d9908
KH
1625/* Handle -malign-XXXXXX options. */
1626static void
863d938c 1627rs6000_parse_alignment_option (void)
025d9908 1628{
b20a9cca
AM
1629 if (rs6000_alignment_string == 0)
1630 return;
1631 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1632 rs6000_alignment_flags = MASK_ALIGN_POWER;
1633 else if (! strcmp (rs6000_alignment_string, "natural"))
1634 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1635 else
1636 error ("unknown -malign-XXXXX option specified: '%s'",
1637 rs6000_alignment_string);
1638}
1639
c4501e62
JJ
1640/* Validate and record the size specified with the -mtls-size option. */
1641
1642static void
863d938c 1643rs6000_parse_tls_size_option (void)
c4501e62
JJ
1644{
1645 if (rs6000_tls_size_string == 0)
1646 return;
1647 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1648 rs6000_tls_size = 16;
1649 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1650 rs6000_tls_size = 32;
1651 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1652 rs6000_tls_size = 64;
1653 else
1654 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1655}
1656
5accd822 1657void
a2369ed3 1658optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1659{
5accd822 1660}
3cfa4909
MM
1661\f
1662/* Do anything needed at the start of the asm file. */
1663
1bc7c5b6 1664static void
863d938c 1665rs6000_file_start (void)
3cfa4909 1666{
c4d38ccb 1667 size_t i;
3cfa4909 1668 char buffer[80];
d330fd93 1669 const char *start = buffer;
3cfa4909 1670 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1671 const char *default_cpu = TARGET_CPU_DEFAULT;
1672 FILE *file = asm_out_file;
1673
1674 default_file_start ();
1675
1676#ifdef TARGET_BI_ARCH
1677 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1678 default_cpu = 0;
1679#endif
3cfa4909
MM
1680
1681 if (flag_verbose_asm)
1682 {
1683 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1684 rs6000_select[0].string = default_cpu;
1685
b6a1cbae 1686 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1687 {
1688 ptr = &rs6000_select[i];
1689 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1690 {
1691 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1692 start = "";
1693 }
1694 }
1695
b91da81f 1696#ifdef USING_ELFOS_H
3cfa4909
MM
1697 switch (rs6000_sdata)
1698 {
1699 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1700 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1701 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1702 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1703 }
1704
1705 if (rs6000_sdata && g_switch_value)
1706 {
307b599c
MK
1707 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1708 g_switch_value);
3cfa4909
MM
1709 start = "";
1710 }
1711#endif
1712
1713 if (*start == '\0')
949ea356 1714 putc ('\n', file);
3cfa4909
MM
1715 }
1716}
c4e18b1c 1717
5248c961 1718\f
a0ab749a 1719/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1720
1721int
863d938c 1722direct_return (void)
9878760c 1723{
4697a36c
MM
1724 if (reload_completed)
1725 {
1726 rs6000_stack_t *info = rs6000_stack_info ();
1727
1728 if (info->first_gp_reg_save == 32
1729 && info->first_fp_reg_save == 64
00b960c7 1730 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1731 && ! info->lr_save_p
1732 && ! info->cr_save_p
00b960c7 1733 && info->vrsave_mask == 0
c81fc13e 1734 && ! info->push_p)
4697a36c
MM
1735 return 1;
1736 }
1737
1738 return 0;
9878760c
RK
1739}
1740
1741/* Returns 1 always. */
1742
1743int
f676971a 1744any_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 1745 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1746{
1747 return 1;
1748}
1749
85d346f1
DE
1750/* Returns 1 always. */
1751
1752int
f676971a 1753any_parallel_operand (rtx op ATTRIBUTE_UNUSED,
85d346f1
DE
1754 enum machine_mode mode ATTRIBUTE_UNUSED)
1755{
1756 return 1;
1757}
1758
a4f6c312 1759/* Returns 1 if op is the count register. */
85d346f1 1760
38c1f2d7 1761int
a2369ed3 1762count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1763{
1764 if (GET_CODE (op) != REG)
1765 return 0;
1766
1767 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1768 return 1;
1769
1770 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1771 return 1;
1772
1773 return 0;
1774}
1775
0ec4e2a8 1776/* Returns 1 if op is an altivec register. */
85d346f1 1777
0ec4e2a8 1778int
a2369ed3 1779altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8 1780{
0ec4e2a8
AH
1781 return (register_operand (op, mode)
1782 && (GET_CODE (op) != REG
1783 || REGNO (op) > FIRST_PSEUDO_REGISTER
1784 || ALTIVEC_REGNO_P (REGNO (op))));
1785}
1786
38c1f2d7 1787int
a2369ed3 1788xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1789{
1790 if (GET_CODE (op) != REG)
1791 return 0;
1792
9ebbca7d 1793 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1794 return 1;
1795
802a0058
MM
1796 return 0;
1797}
1798
c859cda6 1799/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1800 by such constants completes more quickly. */
c859cda6
DJ
1801
1802int
a2369ed3 1803s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6 1804{
c4ad648e 1805 return (GET_CODE (op) == CONST_INT
c859cda6
DJ
1806 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1807}
1808
9878760c
RK
1809/* Return 1 if OP is a constant that can fit in a D field. */
1810
1811int
a2369ed3 1812short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1813{
5f59ecb7
DE
1814 return (GET_CODE (op) == CONST_INT
1815 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1816}
1817
5519a4f9 1818/* Similar for an unsigned D field. */
9878760c
RK
1819
1820int
a2369ed3 1821u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1822{
19684119 1823 return (GET_CODE (op) == CONST_INT
c1f11548 1824 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1825}
1826
dcfedcd0
RK
1827/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1828
1829int
a2369ed3 1830non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1831{
1832 return (GET_CODE (op) == CONST_INT
a7653a2c 1833 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1834}
1835
2bfcf297
DB
1836/* Returns 1 if OP is a CONST_INT that is a positive value
1837 and an exact power of 2. */
1838
1839int
a2369ed3 1840exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1841{
1842 return (GET_CODE (op) == CONST_INT
1843 && INTVAL (op) > 0
1844 && exact_log2 (INTVAL (op)) >= 0);
1845}
1846
9878760c
RK
1847/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1848 ctr, or lr). */
1849
1850int
a2369ed3 1851gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1852{
1853 return (register_operand (op, mode)
802a0058 1854 && (GET_CODE (op) != REG
f676971a 1855 || (REGNO (op) >= ARG_POINTER_REGNUM
9ebbca7d
GK
1856 && !XER_REGNO_P (REGNO (op)))
1857 || REGNO (op) < MQ_REGNO));
9878760c
RK
1858}
1859
1860/* Returns 1 if OP is either a pseudo-register or a register denoting a
1861 CR field. */
1862
1863int
a2369ed3 1864cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1865{
1866 return (register_operand (op, mode)
1867 && (GET_CODE (op) != REG
1868 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1869 || CR_REGNO_P (REGNO (op))));
1870}
1871
815cdc52
MM
1872/* Returns 1 if OP is either a pseudo-register or a register denoting a
1873 CR field that isn't CR0. */
1874
1875int
a2369ed3 1876cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1877{
1878 return (register_operand (op, mode)
1879 && (GET_CODE (op) != REG
1880 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1881 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1882}
1883
a4f6c312
SS
1884/* Returns 1 if OP is either a constant integer valid for a D-field or
1885 a non-special register. If a register, it must be in the proper
1886 mode unless MODE is VOIDmode. */
9878760c
RK
1887
1888int
a2369ed3 1889reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1890{
f5a28898 1891 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1892}
1893
a4f6c312 1894/* Similar, except check if the negation of the constant would be
42f806e5
AM
1895 valid for a D-field. Don't allow a constant zero, since all the
1896 patterns that call this predicate use "addic r1,r2,-constant" on
1897 a constant value to set a carry when r2 is greater or equal to
1898 "constant". That doesn't work for zero. */
9878760c
RK
1899
1900int
a2369ed3 1901reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1902{
1903 if (GET_CODE (op) == CONST_INT)
42f806e5 1904 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P') && INTVAL (op) != 0;
9878760c 1905
cd2b37d9 1906 return gpc_reg_operand (op, mode);
9878760c
RK
1907}
1908
768070a0
TR
1909/* Returns 1 if OP is either a constant integer valid for a DS-field or
1910 a non-special register. If a register, it must be in the proper
1911 mode unless MODE is VOIDmode. */
1912
1913int
a2369ed3 1914reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1915{
1916 if (gpc_reg_operand (op, mode))
1917 return 1;
1918 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1919 return 1;
1920
1921 return 0;
1922}
1923
1924
a4f6c312
SS
1925/* Return 1 if the operand is either a register or an integer whose
1926 high-order 16 bits are zero. */
9878760c
RK
1927
1928int
a2369ed3 1929reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1930{
e675f625 1931 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1932}
1933
1934/* Return 1 is the operand is either a non-special register or ANY
1935 constant integer. */
1936
1937int
a2369ed3 1938reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1939{
a4f6c312 1940 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1941}
1942
1943/* Return 1 is the operand is either a non-special register or ANY
1944 32-bit signed constant integer. */
1945
1946int
a2369ed3 1947reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1948{
a4f6c312
SS
1949 return (gpc_reg_operand (op, mode)
1950 || (GET_CODE (op) == CONST_INT
f6bf7de2 1951#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1952 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1953 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1954#endif
a4f6c312 1955 ));
9878760c
RK
1956}
1957
2bfcf297
DB
1958/* Return 1 is the operand is either a non-special register or a 32-bit
1959 signed constant integer valid for 64-bit addition. */
1960
1961int
a2369ed3 1962reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1963{
a4f6c312
SS
1964 return (gpc_reg_operand (op, mode)
1965 || (GET_CODE (op) == CONST_INT
a65c591c 1966#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1967 && INTVAL (op) < 0x7fff8000
a65c591c 1968#else
a4f6c312
SS
1969 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1970 < 0x100000000ll)
2bfcf297 1971#endif
a4f6c312 1972 ));
2bfcf297
DB
1973}
1974
1975/* Return 1 is the operand is either a non-special register or a 32-bit
1976 signed constant integer valid for 64-bit subtraction. */
1977
1978int
a2369ed3 1979reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1980{
a4f6c312
SS
1981 return (gpc_reg_operand (op, mode)
1982 || (GET_CODE (op) == CONST_INT
a65c591c 1983#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1984 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1985#else
a4f6c312
SS
1986 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1987 < 0x100000000ll)
2bfcf297 1988#endif
a4f6c312 1989 ));
2bfcf297
DB
1990}
1991
9ebbca7d
GK
1992/* Return 1 is the operand is either a non-special register or ANY
1993 32-bit unsigned constant integer. */
1994
1995int
a2369ed3 1996reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1997{
1d328b19
GK
1998 if (GET_CODE (op) == CONST_INT)
1999 {
2000 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
2001 {
2002 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 2003 abort ();
1d328b19
GK
2004
2005 if (INTVAL (op) < 0)
2006 return 0;
2007 }
2008
2009 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 2010 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
2011 }
2012 else if (GET_CODE (op) == CONST_DOUBLE)
2013 {
2014 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2015 || mode != DImode)
a4f6c312 2016 abort ();
1d328b19
GK
2017
2018 return CONST_DOUBLE_HIGH (op) == 0;
2019 }
f676971a 2020 else
1d328b19 2021 return gpc_reg_operand (op, mode);
9ebbca7d
GK
2022}
2023
51d3e7d6 2024/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
2025
2026int
a2369ed3 2027got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
2028{
2029 return (GET_CODE (op) == SYMBOL_REF
2030 || GET_CODE (op) == CONST
2031 || GET_CODE (op) == LABEL_REF);
2032}
2033
38c1f2d7
MM
2034/* Return 1 if the operand is a simple references that can be loaded via
2035 the GOT (labels involving addition aren't allowed). */
2036
2037int
a2369ed3 2038got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
2039{
2040 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
2041}
2042
4e74d8ec
MM
2043/* Return the number of instructions it takes to form a constant in an
2044 integer register. */
2045
2046static int
a2369ed3 2047num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
2048{
2049 /* signed constant loadable with {cal|addi} */
5f59ecb7 2050 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
2051 return 1;
2052
4e74d8ec 2053 /* constant loadable with {cau|addis} */
5f59ecb7 2054 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
2055 return 1;
2056
5f59ecb7 2057#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 2058 else if (TARGET_POWERPC64)
4e74d8ec 2059 {
a65c591c
DE
2060 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
2061 HOST_WIDE_INT high = value >> 31;
4e74d8ec 2062
a65c591c 2063 if (high == 0 || high == -1)
4e74d8ec
MM
2064 return 2;
2065
a65c591c 2066 high >>= 1;
4e74d8ec 2067
a65c591c 2068 if (low == 0)
4e74d8ec 2069 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
2070 else
2071 return (num_insns_constant_wide (high)
e396202a 2072 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
2073 }
2074#endif
2075
2076 else
2077 return 2;
2078}
2079
2080int
a2369ed3 2081num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 2082{
4e74d8ec 2083 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
2084 {
2085#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
2086 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
2087 && mask64_operand (op, mode))
c4ad648e 2088 return 2;
0d30d435
DE
2089 else
2090#endif
2091 return num_insns_constant_wide (INTVAL (op));
2092 }
4e74d8ec 2093
6fc48950
MM
2094 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
2095 {
2096 long l;
2097 REAL_VALUE_TYPE rv;
2098
2099 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2100 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 2101 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
2102 }
2103
47ad8c61 2104 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 2105 {
47ad8c61
MM
2106 HOST_WIDE_INT low;
2107 HOST_WIDE_INT high;
2108 long l[2];
2109 REAL_VALUE_TYPE rv;
2110 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 2111
47ad8c61
MM
2112 if (mode == VOIDmode || mode == DImode)
2113 {
2114 high = CONST_DOUBLE_HIGH (op);
2115 low = CONST_DOUBLE_LOW (op);
2116 }
2117 else
2118 {
2119 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2120 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
2121 high = l[endian];
2122 low = l[1 - endian];
2123 }
4e74d8ec 2124
47ad8c61
MM
2125 if (TARGET_32BIT)
2126 return (num_insns_constant_wide (low)
2127 + num_insns_constant_wide (high));
4e74d8ec
MM
2128
2129 else
47ad8c61 2130 {
e72247f4 2131 if (high == 0 && low >= 0)
47ad8c61
MM
2132 return num_insns_constant_wide (low);
2133
e72247f4 2134 else if (high == -1 && low < 0)
47ad8c61
MM
2135 return num_insns_constant_wide (low);
2136
a260abc9
DE
2137 else if (mask64_operand (op, mode))
2138 return 2;
2139
47ad8c61
MM
2140 else if (low == 0)
2141 return num_insns_constant_wide (high) + 1;
2142
2143 else
2144 return (num_insns_constant_wide (high)
2145 + num_insns_constant_wide (low) + 1);
2146 }
4e74d8ec
MM
2147 }
2148
2149 else
2150 abort ();
2151}
2152
a4f6c312
SS
2153/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
2154 register with one instruction per word. We only do this if we can
2155 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
2156
2157int
a2369ed3 2158easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 2159{
9878760c
RK
2160 if (GET_CODE (op) != CONST_DOUBLE
2161 || GET_MODE (op) != mode
4e74d8ec 2162 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
2163 return 0;
2164
a4f6c312 2165 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
2166 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
2167 && mode != DImode)
b6c9286a
MM
2168 return 1;
2169
a4f6c312 2170 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 2171 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
2172 return 0;
2173
5ae4759c 2174#ifdef TARGET_RELOCATABLE
a4f6c312
SS
2175 /* Similarly if we are using -mrelocatable, consider all constants
2176 to be hard. */
5ae4759c
MM
2177 if (TARGET_RELOCATABLE)
2178 return 0;
2179#endif
2180
fcce224d
DE
2181 if (mode == TFmode)
2182 {
2183 long k[4];
2184 REAL_VALUE_TYPE rv;
2185
2186 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2187 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
2188
2189 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2190 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
2191 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
2192 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
2193 }
2194
2195 else if (mode == DFmode)
042259f2
DE
2196 {
2197 long k[2];
2198 REAL_VALUE_TYPE rv;
2199
2200 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2201 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 2202
a65c591c
DE
2203 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2204 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 2205 }
4e74d8ec
MM
2206
2207 else if (mode == SFmode)
042259f2
DE
2208 {
2209 long l;
2210 REAL_VALUE_TYPE rv;
2211
2212 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2213 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 2214
4e74d8ec 2215 return num_insns_constant_wide (l) == 1;
042259f2 2216 }
4e74d8ec 2217
a260abc9 2218 else if (mode == DImode)
c81fc13e 2219 return ((TARGET_POWERPC64
a260abc9
DE
2220 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
2221 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 2222
a9098fd0
GK
2223 else if (mode == SImode)
2224 return 1;
4e74d8ec
MM
2225 else
2226 abort ();
9878760c 2227}
8f75773e 2228
effa5d5d 2229/* Returns the constant for the splat instruction, if exists. */
452a7d36
HP
2230
2231static int
2232easy_vector_splat_const (int cst, enum machine_mode mode)
2233{
f676971a 2234 switch (mode)
452a7d36
HP
2235 {
2236 case V4SImode:
f676971a
EC
2237 if (EASY_VECTOR_15 (cst)
2238 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2239 return cst;
2240 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
2241 break;
2242 cst = cst >> 16;
c4ad648e
AM
2243 /* Fall thru */
2244
452a7d36 2245 case V8HImode:
f676971a
EC
2246 if (EASY_VECTOR_15 (cst)
2247 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2248 return cst;
2249 if ((cst & 0xff) != ((cst >> 8) & 0xff))
2250 break;
2251 cst = cst >> 8;
c4ad648e
AM
2252 /* Fall thru */
2253
452a7d36 2254 case V16QImode:
c4ad648e
AM
2255 if (EASY_VECTOR_15 (cst)
2256 || EASY_VECTOR_15_ADD_SELF (cst))
2257 return cst;
f676971a 2258 default:
452a7d36
HP
2259 break;
2260 }
2261 return 0;
2262}
2263
2264
72ac76be 2265/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
2266
2267static int
a2369ed3 2268easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
2269{
2270 int units, i, cst;
2271
2272 units = CONST_VECTOR_NUNITS (op);
2273
2274 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2275 for (i = 1; i < units; ++i)
2276 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
2277 break;
452a7d36 2278 if (i == units && easy_vector_splat_const (cst, mode))
d744e06e
AH
2279 return 1;
2280 return 0;
2281}
2282
2283/* Return 1 if the operand is a CONST_INT and can be put into a
2284 register without using memory. */
2285
2286int
a2369ed3 2287easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 2288{
d744e06e 2289 int cst, cst2;
69ef87e2 2290
d744e06e
AH
2291 if (GET_CODE (op) != CONST_VECTOR
2292 || (!TARGET_ALTIVEC
2293 && !TARGET_SPE))
69ef87e2
AH
2294 return 0;
2295
d744e06e
AH
2296 if (zero_constant (op, mode)
2297 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
2298 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
2299 return 1;
69ef87e2 2300
d744e06e
AH
2301 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
2302 return 0;
2303
f5119d10
AH
2304 if (TARGET_SPE && mode == V1DImode)
2305 return 0;
2306
d744e06e
AH
2307 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2308 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
2309
2310 /* Limit SPE vectors to 15 bits signed. These we can generate with:
2311 li r0, CONSTANT1
2312 evmergelo r0, r0, r0
2313 li r0, CONSTANT2
2314
2315 I don't know how efficient it would be to allow bigger constants,
2316 considering we'll have an extra 'ori' for every 'li'. I doubt 5
2317 instructions is better than a 64-bit memory load, but I don't
2318 have the e500 timing specs. */
2319 if (TARGET_SPE && mode == V2SImode
2320 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 2321 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
2322 return 1;
2323
f676971a 2324 if (TARGET_ALTIVEC
452a7d36
HP
2325 && easy_vector_same (op, mode))
2326 {
2327 cst = easy_vector_splat_const (cst, mode);
f676971a 2328 if (EASY_VECTOR_15_ADD_SELF (cst)
452a7d36
HP
2329 || EASY_VECTOR_15 (cst))
2330 return 1;
f676971a 2331 }
d744e06e
AH
2332 return 0;
2333}
2334
2335/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
2336
2337int
a2369ed3 2338easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
2339{
2340 int cst;
452a7d36
HP
2341 if (TARGET_ALTIVEC
2342 && GET_CODE (op) == CONST_VECTOR
2343 && easy_vector_same (op, mode))
2344 {
2345 cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode);
2346 if (EASY_VECTOR_15_ADD_SELF (cst))
f676971a 2347 return 1;
452a7d36
HP
2348 }
2349 return 0;
2350}
d744e06e 2351
452a7d36 2352/* Generate easy_vector_constant out of a easy_vector_constant_add_self. */
d744e06e 2353
f676971a 2354rtx
452a7d36
HP
2355gen_easy_vector_constant_add_self (rtx op)
2356{
2357 int i, units;
2358 rtvec v;
2359 units = GET_MODE_NUNITS (GET_MODE (op));
2360 v = rtvec_alloc (units);
2361
2362 for (i = 0; i < units; i++)
f676971a 2363 RTVEC_ELT (v, i) =
452a7d36
HP
2364 GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1);
2365 return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v);
d744e06e
AH
2366}
2367
2368const char *
a2369ed3 2369output_vec_const_move (rtx *operands)
d744e06e
AH
2370{
2371 int cst, cst2;
2372 enum machine_mode mode;
2373 rtx dest, vec;
2374
2375 dest = operands[0];
2376 vec = operands[1];
69ef87e2 2377
d744e06e
AH
2378 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
2379 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
2380 mode = GET_MODE (dest);
69ef87e2 2381
d744e06e
AH
2382 if (TARGET_ALTIVEC)
2383 {
2384 if (zero_constant (vec, mode))
2385 return "vxor %0,%0,%0";
ce1f50b2 2386 else if (easy_vector_constant (vec, mode))
98ef3137 2387 {
d744e06e
AH
2388 operands[1] = GEN_INT (cst);
2389 switch (mode)
2390 {
2391 case V4SImode:
452a7d36 2392 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2393 {
2394 operands[1] = GEN_INT (cst);
2395 return "vspltisw %0,%1";
2396 }
452a7d36
HP
2397 else if (EASY_VECTOR_15_ADD_SELF (cst))
2398 return "#";
ce1f50b2 2399 cst = cst >> 16;
c4ad648e
AM
2400 /* Fall thru */
2401
d744e06e 2402 case V8HImode:
452a7d36 2403 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2404 {
2405 operands[1] = GEN_INT (cst);
2406 return "vspltish %0,%1";
2407 }
452a7d36
HP
2408 else if (EASY_VECTOR_15_ADD_SELF (cst))
2409 return "#";
ce1f50b2 2410 cst = cst >> 8;
c4ad648e
AM
2411 /* Fall thru */
2412
d744e06e 2413 case V16QImode:
452a7d36 2414 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2415 {
2416 operands[1] = GEN_INT (cst);
2417 return "vspltisb %0,%1";
2418 }
452a7d36
HP
2419 else if (EASY_VECTOR_15_ADD_SELF (cst))
2420 return "#";
c4ad648e 2421
d744e06e
AH
2422 default:
2423 abort ();
2424 }
98ef3137 2425 }
d744e06e
AH
2426 else
2427 abort ();
69ef87e2
AH
2428 }
2429
d744e06e
AH
2430 if (TARGET_SPE)
2431 {
2432 /* Vector constant 0 is handled as a splitter of V2SI, and in the
2433 pattern of V1DI, V4HI, and V2SF.
2434
c1207243 2435 FIXME: We should probably return # and add post reload
c4ad648e 2436 splitters for these, but this way is so easy ;-). */
d744e06e
AH
2437 operands[1] = GEN_INT (cst);
2438 operands[2] = GEN_INT (cst2);
2439 if (cst == cst2)
2440 return "li %0,%1\n\tevmergelo %0,%0,%0";
2441 else
2442 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
2443 }
2444
2445 abort ();
69ef87e2
AH
2446}
2447
2448/* Return 1 if the operand is the constant 0. This works for scalars
2449 as well as vectors. */
2450int
a2369ed3 2451zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
2452{
2453 return op == CONST0_RTX (mode);
2454}
2455
50a0b056
GK
2456/* Return 1 if the operand is 0.0. */
2457int
a2369ed3 2458zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
2459{
2460 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
2461}
2462
a4f6c312
SS
2463/* Return 1 if the operand is in volatile memory. Note that during
2464 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
2465 volatile memory references. So this function allows us to
2466 recognize volatile references where its safe. */
2467
2468int
a2369ed3 2469volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
2470{
2471 if (GET_CODE (op) != MEM)
2472 return 0;
2473
2474 if (!MEM_VOLATILE_P (op))
2475 return 0;
2476
2477 if (mode != GET_MODE (op))
2478 return 0;
2479
2480 if (reload_completed)
2481 return memory_operand (op, mode);
2482
2483 if (reload_in_progress)
2484 return strict_memory_address_p (mode, XEXP (op, 0));
2485
2486 return memory_address_p (mode, XEXP (op, 0));
2487}
2488
97f6e72f 2489/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
2490
2491int
a2369ed3 2492offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 2493{
97f6e72f 2494 return ((GET_CODE (op) == MEM)
677a9668 2495 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 2496 mode, XEXP (op, 0)));
914c2e77
RK
2497}
2498
9878760c
RK
2499/* Return 1 if the operand is either an easy FP constant (see above) or
2500 memory. */
2501
2502int
a2369ed3 2503mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
2504{
2505 return memory_operand (op, mode) || easy_fp_constant (op, mode);
2506}
2507
2508/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 2509 that can be used as the operand of a `mode' add insn. */
9878760c
RK
2510
2511int
a2369ed3 2512add_operand (rtx op, enum machine_mode mode)
9878760c 2513{
2bfcf297 2514 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
2515 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2516 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
2517
2518 return gpc_reg_operand (op, mode);
9878760c
RK
2519}
2520
dcfedcd0
RK
2521/* Return 1 if OP is a constant but not a valid add_operand. */
2522
2523int
a2369ed3 2524non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
2525{
2526 return (GET_CODE (op) == CONST_INT
e72247f4
DE
2527 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2528 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
2529}
2530
9878760c
RK
2531/* Return 1 if the operand is a non-special register or a constant that
2532 can be used as the operand of an OR or XOR insn on the RS/6000. */
2533
2534int
a2369ed3 2535logical_operand (rtx op, enum machine_mode mode)
9878760c 2536{
40501e5f 2537 HOST_WIDE_INT opl, oph;
1d328b19 2538
dfbdccdb
GK
2539 if (gpc_reg_operand (op, mode))
2540 return 1;
1d328b19 2541
dfbdccdb 2542 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
2543 {
2544 opl = INTVAL (op) & GET_MODE_MASK (mode);
2545
2546#if HOST_BITS_PER_WIDE_INT <= 32
2547 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
2548 return 0;
2549#endif
2550 }
dfbdccdb
GK
2551 else if (GET_CODE (op) == CONST_DOUBLE)
2552 {
1d328b19 2553 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 2554 abort ();
1d328b19
GK
2555
2556 opl = CONST_DOUBLE_LOW (op);
2557 oph = CONST_DOUBLE_HIGH (op);
40501e5f 2558 if (oph != 0)
38886f37 2559 return 0;
dfbdccdb
GK
2560 }
2561 else
2562 return 0;
1d328b19 2563
40501e5f
AM
2564 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
2565 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
2566}
2567
dcfedcd0 2568/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 2569 above), but could be split into one. */
dcfedcd0
RK
2570
2571int
a2369ed3 2572non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 2573{
dfbdccdb 2574 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
2575 && ! logical_operand (op, mode)
2576 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
2577}
2578
19ba8161 2579/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
2580 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
2581 Reject all ones and all zeros, since these should have been optimized
2582 away and confuse the making of MB and ME. */
2583
2584int
a2369ed3 2585mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 2586{
02071907 2587 HOST_WIDE_INT c, lsb;
9878760c 2588
19ba8161
DE
2589 if (GET_CODE (op) != CONST_INT)
2590 return 0;
2591
2592 c = INTVAL (op);
2593
57deb3a1
AM
2594 /* Fail in 64-bit mode if the mask wraps around because the upper
2595 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
2596 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
2597 return 0;
2598
c5059423
AM
2599 /* We don't change the number of transitions by inverting,
2600 so make sure we start with the LS bit zero. */
2601 if (c & 1)
2602 c = ~c;
2603
2604 /* Reject all zeros or all ones. */
2605 if (c == 0)
9878760c
RK
2606 return 0;
2607
c5059423
AM
2608 /* Find the first transition. */
2609 lsb = c & -c;
2610
2611 /* Invert to look for a second transition. */
2612 c = ~c;
9878760c 2613
c5059423
AM
2614 /* Erase first transition. */
2615 c &= -lsb;
9878760c 2616
c5059423
AM
2617 /* Find the second transition (if any). */
2618 lsb = c & -c;
2619
2620 /* Match if all the bits above are 1's (or c is zero). */
2621 return c == -lsb;
9878760c
RK
2622}
2623
0ba1b2ff
AM
2624/* Return 1 for the PowerPC64 rlwinm corner case. */
2625
2626int
a2369ed3 2627mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2628{
2629 HOST_WIDE_INT c, lsb;
2630
2631 if (GET_CODE (op) != CONST_INT)
2632 return 0;
2633
2634 c = INTVAL (op);
2635
2636 if ((c & 0x80000001) != 0x80000001)
2637 return 0;
2638
2639 c = ~c;
2640 if (c == 0)
2641 return 0;
2642
2643 lsb = c & -c;
2644 c = ~c;
2645 c &= -lsb;
2646 lsb = c & -c;
2647 return c == -lsb;
2648}
2649
a260abc9
DE
2650/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2651 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2652 Reject all zeros, since zero should have been optimized away and
2653 confuses the making of MB and ME. */
9878760c
RK
2654
2655int
a2369ed3 2656mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2657{
2658 if (GET_CODE (op) == CONST_INT)
2659 {
02071907 2660 HOST_WIDE_INT c, lsb;
a260abc9 2661
c5059423 2662 c = INTVAL (op);
a260abc9 2663
0ba1b2ff 2664 /* Reject all zeros. */
c5059423 2665 if (c == 0)
e2c953b6
DE
2666 return 0;
2667
0ba1b2ff
AM
2668 /* We don't change the number of transitions by inverting,
2669 so make sure we start with the LS bit zero. */
2670 if (c & 1)
2671 c = ~c;
2672
c5059423
AM
2673 /* Find the transition, and check that all bits above are 1's. */
2674 lsb = c & -c;
e3981aab
DE
2675
2676 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2677 return c == -lsb;
e2c953b6 2678 }
0ba1b2ff
AM
2679 return 0;
2680}
2681
2682/* Like mask64_operand, but allow up to three transitions. This
2683 predicate is used by insn patterns that generate two rldicl or
2684 rldicr machine insns. */
2685
2686int
a2369ed3 2687mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2688{
2689 if (GET_CODE (op) == CONST_INT)
a260abc9 2690 {
0ba1b2ff 2691 HOST_WIDE_INT c, lsb;
a260abc9 2692
0ba1b2ff 2693 c = INTVAL (op);
a260abc9 2694
0ba1b2ff
AM
2695 /* Disallow all zeros. */
2696 if (c == 0)
2697 return 0;
a260abc9 2698
0ba1b2ff
AM
2699 /* We don't change the number of transitions by inverting,
2700 so make sure we start with the LS bit zero. */
2701 if (c & 1)
2702 c = ~c;
a260abc9 2703
0ba1b2ff
AM
2704 /* Find the first transition. */
2705 lsb = c & -c;
a260abc9 2706
0ba1b2ff
AM
2707 /* Invert to look for a second transition. */
2708 c = ~c;
2709
2710 /* Erase first transition. */
2711 c &= -lsb;
2712
2713 /* Find the second transition. */
2714 lsb = c & -c;
2715
2716 /* Invert to look for a third transition. */
2717 c = ~c;
2718
2719 /* Erase second transition. */
2720 c &= -lsb;
2721
2722 /* Find the third transition (if any). */
2723 lsb = c & -c;
2724
2725 /* Match if all the bits above are 1's (or c is zero). */
2726 return c == -lsb;
2727 }
2728 return 0;
2729}
2730
2731/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2732 implement ANDing by the mask IN. */
2733void
a2369ed3 2734build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2735{
2736#if HOST_BITS_PER_WIDE_INT >= 64
2737 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2738 int shift;
2739
2740 if (GET_CODE (in) != CONST_INT)
2741 abort ();
2742
2743 c = INTVAL (in);
2744 if (c & 1)
2745 {
2746 /* Assume c initially something like 0x00fff000000fffff. The idea
2747 is to rotate the word so that the middle ^^^^^^ group of zeros
2748 is at the MS end and can be cleared with an rldicl mask. We then
2749 rotate back and clear off the MS ^^ group of zeros with a
2750 second rldicl. */
2751 c = ~c; /* c == 0xff000ffffff00000 */
2752 lsb = c & -c; /* lsb == 0x0000000000100000 */
2753 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2754 c = ~c; /* c == 0x00fff000000fffff */
2755 c &= -lsb; /* c == 0x00fff00000000000 */
2756 lsb = c & -c; /* lsb == 0x0000100000000000 */
2757 c = ~c; /* c == 0xff000fffffffffff */
2758 c &= -lsb; /* c == 0xff00000000000000 */
2759 shift = 0;
2760 while ((lsb >>= 1) != 0)
2761 shift++; /* shift == 44 on exit from loop */
2762 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2763 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2764 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2765 }
2766 else
0ba1b2ff
AM
2767 {
2768 /* Assume c initially something like 0xff000f0000000000. The idea
2769 is to rotate the word so that the ^^^ middle group of zeros
2770 is at the LS end and can be cleared with an rldicr mask. We then
2771 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2772 a second rldicr. */
2773 lsb = c & -c; /* lsb == 0x0000010000000000 */
2774 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2775 c = ~c; /* c == 0x00fff0ffffffffff */
2776 c &= -lsb; /* c == 0x00fff00000000000 */
2777 lsb = c & -c; /* lsb == 0x0000100000000000 */
2778 c = ~c; /* c == 0xff000fffffffffff */
2779 c &= -lsb; /* c == 0xff00000000000000 */
2780 shift = 0;
2781 while ((lsb >>= 1) != 0)
2782 shift++; /* shift == 44 on exit from loop */
2783 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2784 m1 >>= shift; /* m1 == 0x0000000000000fff */
2785 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2786 }
2787
2788 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2789 masks will be all 1's. We are guaranteed more than one transition. */
2790 out[0] = GEN_INT (64 - shift);
2791 out[1] = GEN_INT (m1);
2792 out[2] = GEN_INT (shift);
2793 out[3] = GEN_INT (m2);
2794#else
045572c7
GK
2795 (void)in;
2796 (void)out;
0ba1b2ff
AM
2797 abort ();
2798#endif
a260abc9
DE
2799}
2800
2801/* Return 1 if the operand is either a non-special register or a constant
2802 that can be used as the operand of a PowerPC64 logical AND insn. */
2803
2804int
a2369ed3 2805and64_operand (rtx op, enum machine_mode mode)
9878760c 2806{
a4f6c312 2807 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2808 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2809
2810 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2811}
2812
0ba1b2ff
AM
2813/* Like the above, but also match constants that can be implemented
2814 with two rldicl or rldicr insns. */
2815
2816int
a2369ed3 2817and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2818{
a3c9585f 2819 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2820 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2821
2822 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2823}
2824
a260abc9
DE
2825/* Return 1 if the operand is either a non-special register or a
2826 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2827
2828int
a2369ed3 2829and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2830{
a4f6c312 2831 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2832 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2833
2834 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2835}
2836
9878760c
RK
2837/* Return 1 if the operand is a general register or memory operand. */
2838
2839int
a2369ed3 2840reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2841{
b6c9286a
MM
2842 return (gpc_reg_operand (op, mode)
2843 || memory_operand (op, mode)
4c81e946 2844 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2845 || volatile_mem_operand (op, mode));
9878760c
RK
2846}
2847
a7a813f7 2848/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2849 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2850 instruction. */
2851
2852int
a2369ed3 2853lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2854{
2855 rtx inner = op;
2856
2857 if (reload_completed && GET_CODE (inner) == SUBREG)
2858 inner = SUBREG_REG (inner);
f676971a 2859
a7a813f7
RK
2860 return gpc_reg_operand (inner, mode)
2861 || (memory_operand (inner, mode)
2862 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2863 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2864 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2865 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2866 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2867}
2868
cc4d5fec
JH
2869/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2870
2871int
a2369ed3 2872symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2873{
2874 if (mode != VOIDmode && GET_MODE (op) != mode)
2875 return 0;
2876
473f51b6
DE
2877 return (GET_CODE (op) == SYMBOL_REF
2878 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2879}
2880
9878760c 2881/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2882 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2883
2884int
a2369ed3 2885call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2886{
2887 if (mode != VOIDmode && GET_MODE (op) != mode)
2888 return 0;
2889
2890 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2891 || (GET_CODE (op) == REG
2892 && (REGNO (op) == LINK_REGISTER_REGNUM
2893 || REGNO (op) == COUNT_REGISTER_REGNUM
2894 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2895}
2896
2af3d377 2897/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2898 this file. */
2af3d377
RK
2899
2900int
f676971a 2901current_file_function_operand (rtx op,
c4ad648e 2902 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2903{
473f51b6
DE
2904 return (GET_CODE (op) == SYMBOL_REF
2905 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2906 && (SYMBOL_REF_LOCAL_P (op)
2907 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2908}
2909
9878760c
RK
2910/* Return 1 if this operand is a valid input for a move insn. */
2911
2912int
a2369ed3 2913input_operand (rtx op, enum machine_mode mode)
9878760c 2914{
eb4e8003 2915 /* Memory is always valid. */
9878760c
RK
2916 if (memory_operand (op, mode))
2917 return 1;
2918
eb4e8003
RK
2919 /* For floating-point, easy constants are valid. */
2920 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2921 && CONSTANT_P (op)
2922 && easy_fp_constant (op, mode))
2923 return 1;
2924
4e74d8ec
MM
2925 /* Allow any integer constant. */
2926 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2927 && (GET_CODE (op) == CONST_INT
e675f625 2928 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2929 return 1;
2930
d744e06e
AH
2931 /* Allow easy vector constants. */
2932 if (GET_CODE (op) == CONST_VECTOR
2933 && easy_vector_constant (op, mode))
2934 return 1;
2935
eb4e8003
RK
2936 /* For floating-point or multi-word mode, the only remaining valid type
2937 is a register. */
9878760c
RK
2938 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2939 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2940 return register_operand (op, mode);
9878760c 2941
88fe15a1
RK
2942 /* The only cases left are integral modes one word or smaller (we
2943 do not get called for MODE_CC values). These can be in any
2944 register. */
2945 if (register_operand (op, mode))
a8b3aeda 2946 return 1;
88fe15a1 2947
84cf9dda 2948 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2949 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2950 return 1;
2951
9ebbca7d 2952 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2953 if (toc_relative_expr_p (op))
b6c9286a
MM
2954 return 1;
2955
88228c4b
MM
2956 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2957 to be valid. */
f607bc57 2958 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2959 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2960 && small_data_operand (op, Pmode))
2961 return 1;
2962
042259f2 2963 return 0;
9878760c 2964}
7509c759 2965
95727fb8
AP
2966
2967/* Darwin, AIX increases natural record alignment to doubleword if the first
2968 field is an FP double while the FP fields remain word aligned. */
2969
19d66194 2970unsigned int
95727fb8
AP
2971rs6000_special_round_type_align (tree type, int computed, int specified)
2972{
2973 tree field = TYPE_FIELDS (type);
95727fb8
AP
2974
2975 /* Skip all the static variables only if ABI is greater than
71cc389b 2976 1 or equal to 0. */
3ce5437a 2977 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2978 field = TREE_CHAIN (field);
2979
3ce5437a 2980 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2981 return MAX (computed, specified);
2982
2983 return MAX (MAX (computed, specified), 64);
2984}
2985
a4f6c312 2986/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2987
2988int
f676971a 2989small_data_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 2990 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2991{
38c1f2d7 2992#if TARGET_ELF
5f59ecb7 2993 rtx sym_ref;
7509c759 2994
d9407988 2995 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2996 return 0;
a54d04b7 2997
f607bc57 2998 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2999 return 0;
3000
88228c4b
MM
3001 if (GET_CODE (op) == SYMBOL_REF)
3002 sym_ref = op;
3003
3004 else if (GET_CODE (op) != CONST
3005 || GET_CODE (XEXP (op, 0)) != PLUS
3006 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
3007 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
3008 return 0;
3009
88228c4b 3010 else
dbf55e53
MM
3011 {
3012 rtx sum = XEXP (op, 0);
3013 HOST_WIDE_INT summand;
3014
3015 /* We have to be careful here, because it is the referenced address
c4ad648e 3016 that must be 32k from _SDA_BASE_, not just the symbol. */
dbf55e53 3017 summand = INTVAL (XEXP (sum, 1));
307b599c 3018 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
3019 return 0;
3020
3021 sym_ref = XEXP (sum, 0);
3022 }
88228c4b 3023
20bfcd69 3024 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
3025#else
3026 return 0;
3027#endif
7509c759 3028}
46c07df8 3029
d2288d5d
HP
3030/* Return true, if operand is a memory operand and has a
3031 displacement divisible by 4. */
3032
3033int
3034word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3035{
3036 rtx addr;
3037 int off = 0;
3038
3039 if (!memory_operand (op, mode))
3040 return 0;
3041
3042 addr = XEXP (op, 0);
3043 if (GET_CODE (addr) == PLUS
3044 && GET_CODE (XEXP (addr, 0)) == REG
3045 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
3046 off = INTVAL (XEXP (addr, 1));
3047
3048 return (off % 4) == 0;
3049}
3050
3a1f863f 3051/* Return true if either operand is a general purpose register. */
46c07df8 3052
3a1f863f
DE
3053bool
3054gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 3055{
3a1f863f
DE
3056 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
3057 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
3058}
3059
9ebbca7d 3060\f
4d588c14
RH
3061/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
3062
f676971a
EC
3063static int
3064constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d 3065{
f676971a 3066 switch (GET_CODE(op))
9ebbca7d
GK
3067 {
3068 case SYMBOL_REF:
c4501e62
JJ
3069 if (RS6000_SYMBOL_REF_TLS_P (op))
3070 return 0;
3071 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
3072 {
3073 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
3074 {
3075 *have_sym = 1;
3076 return 1;
3077 }
3078 else
3079 return 0;
3080 }
3081 else if (! strcmp (XSTR (op, 0), toc_label_name))
3082 {
3083 *have_toc = 1;
3084 return 1;
3085 }
3086 else
3087 return 0;
9ebbca7d
GK
3088 case PLUS:
3089 case MINUS:
c1f11548
DE
3090 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
3091 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 3092 case CONST:
a4f6c312 3093 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 3094 case CONST_INT:
a4f6c312 3095 return 1;
9ebbca7d 3096 default:
a4f6c312 3097 return 0;
9ebbca7d
GK
3098 }
3099}
3100
4d588c14 3101static bool
a2369ed3 3102constant_pool_expr_p (rtx op)
9ebbca7d
GK
3103{
3104 int have_sym = 0;
3105 int have_toc = 0;
3106 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
3107}
3108
4d588c14 3109static bool
a2369ed3 3110toc_relative_expr_p (rtx op)
9ebbca7d 3111{
4d588c14
RH
3112 int have_sym = 0;
3113 int have_toc = 0;
3114 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
3115}
3116
4d588c14 3117bool
a2369ed3 3118legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
3119{
3120 return (TARGET_TOC
3121 && GET_CODE (x) == PLUS
3122 && GET_CODE (XEXP (x, 0)) == REG
3123 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
3124 && constant_pool_expr_p (XEXP (x, 1)));
3125}
3126
3127static bool
a2369ed3 3128legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
3129{
3130 return (DEFAULT_ABI == ABI_V4
3131 && !flag_pic && !TARGET_TOC
3132 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
3133 && small_data_operand (x, mode));
3134}
3135
60cdabab
DE
3136/* SPE offset addressing is limited to 5-bits worth of double words. */
3137#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
3138
76d2b81d
DJ
3139bool
3140rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3141{
3142 unsigned HOST_WIDE_INT offset, extra;
3143
3144 if (GET_CODE (x) != PLUS)
3145 return false;
3146 if (GET_CODE (XEXP (x, 0)) != REG)
3147 return false;
3148 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3149 return false;
60cdabab
DE
3150 if (legitimate_constant_pool_address_p (x))
3151 return true;
4d588c14
RH
3152 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3153 return false;
3154
3155 offset = INTVAL (XEXP (x, 1));
3156 extra = 0;
3157 switch (mode)
3158 {
3159 case V16QImode:
3160 case V8HImode:
3161 case V4SFmode:
3162 case V4SImode:
3163 /* AltiVec vector modes. Only reg+reg addressing is valid here,
3164 which leaves the only valid constant offset of zero, which by
3165 canonicalization rules is also invalid. */
3166 return false;
3167
3168 case V4HImode:
3169 case V2SImode:
3170 case V1DImode:
3171 case V2SFmode:
3172 /* SPE vector modes. */
3173 return SPE_CONST_OFFSET_OK (offset);
3174
3175 case DFmode:
3176 case DImode:
3364872d 3177 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
3178 extra = 4;
3179 else if (offset & 3)
3180 return false;
3181 break;
3182
3183 case TFmode:
3184 case TImode:
3364872d 3185 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
3186 extra = 12;
3187 else if (offset & 3)
3188 return false;
3189 else
3190 extra = 8;
3191 break;
3192
3193 default:
3194 break;
3195 }
3196
b1917422
AM
3197 offset += 0x8000;
3198 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
3199}
3200
3201static bool
a2369ed3 3202legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
3203{
3204 rtx op0, op1;
3205
3206 if (GET_CODE (x) != PLUS)
3207 return false;
850e8d3d 3208
4d588c14
RH
3209 op0 = XEXP (x, 0);
3210 op1 = XEXP (x, 1);
3211
3212 if (!REG_P (op0) || !REG_P (op1))
3213 return false;
3214
3215 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
3216 && INT_REG_OK_FOR_INDEX_P (op1, strict))
3217 || (INT_REG_OK_FOR_BASE_P (op1, strict)
3218 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
3219}
3220
4d588c14 3221static inline bool
a2369ed3 3222legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
3223{
3224 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
3225}
3226
4c81e946
FJ
3227static bool
3228macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
3229{
c4ad648e
AM
3230 if (!TARGET_MACHO || !flag_pic
3231 || mode != SImode || GET_CODE(x) != MEM)
3232 return false;
3233 x = XEXP (x, 0);
4c81e946
FJ
3234
3235 if (GET_CODE (x) != LO_SUM)
3236 return false;
3237 if (GET_CODE (XEXP (x, 0)) != REG)
3238 return false;
3239 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
3240 return false;
3241 x = XEXP (x, 1);
3242
3243 return CONSTANT_P (x);
3244}
3245
4d588c14 3246static bool
a2369ed3 3247legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3248{
3249 if (GET_CODE (x) != LO_SUM)
3250 return false;
3251 if (GET_CODE (XEXP (x, 0)) != REG)
3252 return false;
3253 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3254 return false;
3255 x = XEXP (x, 1);
3256
8622e235 3257 if (TARGET_ELF || TARGET_MACHO)
4d588c14 3258 {
a29077da 3259 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
3260 return false;
3261 if (TARGET_TOC)
3262 return false;
3263 if (GET_MODE_NUNITS (mode) != 1)
3264 return false;
c1e55850 3265 if (GET_MODE_BITSIZE (mode) > 64)
4d588c14
RH
3266 return false;
3267
3268 return CONSTANT_P (x);
3269 }
3270
3271 return false;
3272}
3273
3274
9ebbca7d
GK
3275/* Try machine-dependent ways of modifying an illegitimate address
3276 to be legitimate. If we find one, return the new, valid address.
3277 This is used from only one place: `memory_address' in explow.c.
3278
a4f6c312
SS
3279 OLDX is the address as it was before break_out_memory_refs was
3280 called. In some cases it is useful to look at this to decide what
3281 needs to be done.
9ebbca7d 3282
a4f6c312 3283 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 3284
a4f6c312
SS
3285 It is always safe for this function to do nothing. It exists to
3286 recognize opportunities to optimize the output.
9ebbca7d
GK
3287
3288 On RS/6000, first check for the sum of a register with a constant
3289 integer that is out of range. If so, generate code to add the
3290 constant with the low-order 16 bits masked to the register and force
3291 this result into another register (this can be done with `cau').
3292 Then generate an address of REG+(CONST&0xffff), allowing for the
3293 possibility of bit 16 being a one.
3294
3295 Then check for the sum of a register and something not constant, try to
3296 load the other things into a register and return the sum. */
4d588c14 3297
9ebbca7d 3298rtx
a2369ed3
DJ
3299rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3300 enum machine_mode mode)
0ac081f6 3301{
c4501e62
JJ
3302 if (GET_CODE (x) == SYMBOL_REF)
3303 {
3304 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
3305 if (model != 0)
3306 return rs6000_legitimize_tls_address (x, model);
3307 }
3308
f676971a 3309 if (GET_CODE (x) == PLUS
9ebbca7d
GK
3310 && GET_CODE (XEXP (x, 0)) == REG
3311 && GET_CODE (XEXP (x, 1)) == CONST_INT
3312 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
f676971a 3313 {
9ebbca7d
GK
3314 HOST_WIDE_INT high_int, low_int;
3315 rtx sum;
a65c591c
DE
3316 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
3317 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
3318 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
3319 GEN_INT (high_int)), 0);
3320 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
3321 }
f676971a 3322 else if (GET_CODE (x) == PLUS
9ebbca7d
GK
3323 && GET_CODE (XEXP (x, 0)) == REG
3324 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 3325 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
3326 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3327 || TARGET_POWERPC64
fcce224d 3328 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
3329 && (TARGET_POWERPC64 || mode != DImode)
3330 && mode != TImode)
3331 {
3332 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
3333 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
3334 }
0ac081f6
AH
3335 else if (ALTIVEC_VECTOR_MODE (mode))
3336 {
3337 rtx reg;
3338
3339 /* Make sure both operands are registers. */
3340 if (GET_CODE (x) == PLUS)
9f85ed45 3341 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
3342 force_reg (Pmode, XEXP (x, 1)));
3343
3344 reg = force_reg (Pmode, x);
3345 return reg;
3346 }
a3170dc6
AH
3347 else if (SPE_VECTOR_MODE (mode))
3348 {
3349 /* We accept [reg + reg] and [reg + OFFSET]. */
3350
3351 if (GET_CODE (x) == PLUS)
c4ad648e
AM
3352 {
3353 rtx op1 = XEXP (x, 0);
3354 rtx op2 = XEXP (x, 1);
a3170dc6 3355
c4ad648e 3356 op1 = force_reg (Pmode, op1);
a3170dc6 3357
c4ad648e
AM
3358 if (GET_CODE (op2) != REG
3359 && (GET_CODE (op2) != CONST_INT
3360 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
3361 op2 = force_reg (Pmode, op2);
a3170dc6 3362
c4ad648e
AM
3363 return gen_rtx_PLUS (Pmode, op1, op2);
3364 }
a3170dc6
AH
3365
3366 return force_reg (Pmode, x);
3367 }
f1384257
AM
3368 else if (TARGET_ELF
3369 && TARGET_32BIT
3370 && TARGET_NO_TOC
3371 && ! flag_pic
9ebbca7d 3372 && GET_CODE (x) != CONST_INT
f676971a 3373 && GET_CODE (x) != CONST_DOUBLE
9ebbca7d 3374 && CONSTANT_P (x)
6ac7bf2c
GK
3375 && GET_MODE_NUNITS (mode) == 1
3376 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 3377 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
3378 {
3379 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3380 emit_insn (gen_elf_high (reg, x));
3381 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 3382 }
ee890fe2
SS
3383 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
3384 && ! flag_pic
ab82a49f
AP
3385#if TARGET_MACHO
3386 && ! MACHO_DYNAMIC_NO_PIC_P
3387#endif
ee890fe2 3388 && GET_CODE (x) != CONST_INT
f676971a 3389 && GET_CODE (x) != CONST_DOUBLE
ee890fe2 3390 && CONSTANT_P (x)
a3170dc6 3391 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
f676971a 3392 && mode != DImode
ee890fe2
SS
3393 && mode != TImode)
3394 {
3395 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3396 emit_insn (gen_macho_high (reg, x));
3397 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 3398 }
f676971a 3399 else if (TARGET_TOC
4d588c14 3400 && constant_pool_expr_p (x)
a9098fd0 3401 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
3402 {
3403 return create_TOC_reference (x);
3404 }
3405 else
3406 return NULL_RTX;
3407}
258bfae2 3408
c973d557
JJ
3409/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
3410 We need to emit DTP-relative relocations. */
3411
3412void
3413rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
3414{
3415 switch (size)
3416 {
3417 case 4:
3418 fputs ("\t.long\t", file);
3419 break;
3420 case 8:
3421 fputs (DOUBLE_INT_ASM_OP, file);
3422 break;
3423 default:
3424 abort ();
3425 }
3426 output_addr_const (file, x);
3427 fputs ("@dtprel+0x8000", file);
3428}
3429
c4501e62
JJ
3430/* Construct the SYMBOL_REF for the tls_get_addr function. */
3431
3432static GTY(()) rtx rs6000_tls_symbol;
3433static rtx
863d938c 3434rs6000_tls_get_addr (void)
c4501e62
JJ
3435{
3436 if (!rs6000_tls_symbol)
3437 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
3438
3439 return rs6000_tls_symbol;
3440}
3441
3442/* Construct the SYMBOL_REF for TLS GOT references. */
3443
3444static GTY(()) rtx rs6000_got_symbol;
3445static rtx
863d938c 3446rs6000_got_sym (void)
c4501e62
JJ
3447{
3448 if (!rs6000_got_symbol)
3449 {
3450 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3451 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
3452 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
f676971a 3453 }
c4501e62
JJ
3454
3455 return rs6000_got_symbol;
3456}
3457
3458/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3459 this (thread-local) address. */
3460
3461static rtx
a2369ed3 3462rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
3463{
3464 rtx dest, insn;
3465
3466 dest = gen_reg_rtx (Pmode);
3467 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
3468 {
3469 rtx tlsreg;
3470
3471 if (TARGET_64BIT)
3472 {
3473 tlsreg = gen_rtx_REG (Pmode, 13);
3474 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
3475 }
3476 else
3477 {
3478 tlsreg = gen_rtx_REG (Pmode, 2);
3479 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
3480 }
3481 emit_insn (insn);
3482 }
3483 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
3484 {
3485 rtx tlsreg, tmp;
3486
3487 tmp = gen_reg_rtx (Pmode);
3488 if (TARGET_64BIT)
3489 {
3490 tlsreg = gen_rtx_REG (Pmode, 13);
3491 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
3492 }
3493 else
3494 {
3495 tlsreg = gen_rtx_REG (Pmode, 2);
3496 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
3497 }
3498 emit_insn (insn);
3499 if (TARGET_64BIT)
3500 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3501 else
3502 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3503 emit_insn (insn);
3504 }
3505 else
3506 {
3507 rtx r3, got, tga, tmp1, tmp2, eqv;
3508
3509 if (TARGET_64BIT)
3510 got = gen_rtx_REG (Pmode, TOC_REGISTER);
3511 else
3512 {
3513 if (flag_pic == 1)
3514 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3515 else
3516 {
3517 rtx gsym = rs6000_got_sym ();
3518 got = gen_reg_rtx (Pmode);
3519 if (flag_pic == 0)
3520 rs6000_emit_move (got, gsym, Pmode);
3521 else
3522 {
3523 char buf[30];
3524 static int tls_got_labelno = 0;
3525 rtx tempLR, lab, tmp3, mem;
3526 rtx first, last;
3527
3528 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
3529 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
3530 tempLR = gen_reg_rtx (Pmode);
3531 tmp1 = gen_reg_rtx (Pmode);
3532 tmp2 = gen_reg_rtx (Pmode);
3533 tmp3 = gen_reg_rtx (Pmode);
542a8afa 3534 mem = gen_const_mem (Pmode, tmp1);
c4501e62
JJ
3535
3536 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
3537 gsym));
3538 emit_move_insn (tmp1, tempLR);
3539 emit_move_insn (tmp2, mem);
3540 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
3541 last = emit_move_insn (got, tmp3);
3542 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
3543 REG_NOTES (last));
3544 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3545 REG_NOTES (first));
3546 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3547 REG_NOTES (last));
3548 }
3549 }
3550 }
3551
3552 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3553 {
3554 r3 = gen_rtx_REG (Pmode, 3);
3555 if (TARGET_64BIT)
3556 insn = gen_tls_gd_64 (r3, got, addr);
3557 else
3558 insn = gen_tls_gd_32 (r3, got, addr);
3559 start_sequence ();
3560 emit_insn (insn);
3561 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3562 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3563 insn = emit_call_insn (insn);
3564 CONST_OR_PURE_CALL_P (insn) = 1;
3565 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3566 insn = get_insns ();
3567 end_sequence ();
3568 emit_libcall_block (insn, dest, r3, addr);
3569 }
3570 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3571 {
3572 r3 = gen_rtx_REG (Pmode, 3);
3573 if (TARGET_64BIT)
3574 insn = gen_tls_ld_64 (r3, got);
3575 else
3576 insn = gen_tls_ld_32 (r3, got);
3577 start_sequence ();
3578 emit_insn (insn);
3579 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3580 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3581 insn = emit_call_insn (insn);
3582 CONST_OR_PURE_CALL_P (insn) = 1;
3583 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3584 insn = get_insns ();
3585 end_sequence ();
3586 tmp1 = gen_reg_rtx (Pmode);
3587 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3588 UNSPEC_TLSLD);
3589 emit_libcall_block (insn, tmp1, r3, eqv);
3590 if (rs6000_tls_size == 16)
3591 {
3592 if (TARGET_64BIT)
3593 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3594 else
3595 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3596 }
3597 else if (rs6000_tls_size == 32)
3598 {
3599 tmp2 = gen_reg_rtx (Pmode);
3600 if (TARGET_64BIT)
3601 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3602 else
3603 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3604 emit_insn (insn);
3605 if (TARGET_64BIT)
3606 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3607 else
3608 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3609 }
3610 else
3611 {
3612 tmp2 = gen_reg_rtx (Pmode);
3613 if (TARGET_64BIT)
3614 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3615 else
3616 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3617 emit_insn (insn);
3618 insn = gen_rtx_SET (Pmode, dest,
3619 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3620 }
3621 emit_insn (insn);
3622 }
3623 else
3624 {
3625 /* IE, or 64 bit offset LE. */
3626 tmp2 = gen_reg_rtx (Pmode);
3627 if (TARGET_64BIT)
3628 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3629 else
3630 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3631 emit_insn (insn);
3632 if (TARGET_64BIT)
3633 insn = gen_tls_tls_64 (dest, tmp2, addr);
3634 else
3635 insn = gen_tls_tls_32 (dest, tmp2, addr);
3636 emit_insn (insn);
3637 }
3638 }
3639
3640 return dest;
3641}
3642
3643/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3644 instruction definitions. */
3645
3646int
a2369ed3 3647rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3648{
3649 return RS6000_SYMBOL_REF_TLS_P (x);
3650}
3651
3652/* Return 1 if X contains a thread-local symbol. */
3653
3654bool
a2369ed3 3655rs6000_tls_referenced_p (rtx x)
c4501e62 3656{
cd413cab
AP
3657 if (! TARGET_HAVE_TLS)
3658 return false;
3659
c4501e62
JJ
3660 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3661}
3662
3663/* Return 1 if *X is a thread-local symbol. This is the same as
3664 rs6000_tls_symbol_ref except for the type of the unused argument. */
3665
3666static inline int
a2369ed3 3667rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3668{
3669 return RS6000_SYMBOL_REF_TLS_P (*x);
3670}
3671
24ea750e
DJ
3672/* The convention appears to be to define this wherever it is used.
3673 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3674 is now used here. */
3675#ifndef REG_MODE_OK_FOR_BASE_P
3676#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3677#endif
3678
3679/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3680 replace the input X, or the original X if no replacement is called for.
3681 The output parameter *WIN is 1 if the calling macro should goto WIN,
3682 0 if it should not.
3683
3684 For RS/6000, we wish to handle large displacements off a base
3685 register by splitting the addend across an addiu/addis and the mem insn.
3686 This cuts number of extra insns needed from 3 to 1.
3687
3688 On Darwin, we use this to generate code for floating point constants.
3689 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3690 The Darwin code is inside #if TARGET_MACHO because only then is
3691 machopic_function_base_name() defined. */
3692rtx
f676971a 3693rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
c4ad648e
AM
3694 int opnum, int type,
3695 int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e 3696{
f676971a 3697 /* We must recognize output that we have already generated ourselves. */
24ea750e
DJ
3698 if (GET_CODE (x) == PLUS
3699 && GET_CODE (XEXP (x, 0)) == PLUS
3700 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3701 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3702 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3703 {
3704 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3705 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3706 opnum, (enum reload_type)type);
24ea750e
DJ
3707 *win = 1;
3708 return x;
3709 }
3deb2758 3710
24ea750e
DJ
3711#if TARGET_MACHO
3712 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3713 && GET_CODE (x) == LO_SUM
3714 && GET_CODE (XEXP (x, 0)) == PLUS
3715 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3716 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3717 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3718 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3719 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3720 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3721 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3722 {
3723 /* Result of previous invocation of this function on Darwin
6f317ef3 3724 floating point constant. */
24ea750e 3725 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3726 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3727 opnum, (enum reload_type)type);
24ea750e
DJ
3728 *win = 1;
3729 return x;
3730 }
3731#endif
3732 if (GET_CODE (x) == PLUS
3733 && GET_CODE (XEXP (x, 0)) == REG
3734 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3735 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3736 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3737 && !SPE_VECTOR_MODE (mode)
78c875e8 3738 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3739 {
3740 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3741 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3742 HOST_WIDE_INT high
c4ad648e 3743 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
24ea750e
DJ
3744
3745 /* Check for 32-bit overflow. */
3746 if (high + low != val)
c4ad648e 3747 {
24ea750e
DJ
3748 *win = 0;
3749 return x;
3750 }
3751
3752 /* Reload the high part into a base reg; leave the low part
c4ad648e 3753 in the mem directly. */
24ea750e
DJ
3754
3755 x = gen_rtx_PLUS (GET_MODE (x),
c4ad648e
AM
3756 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3757 GEN_INT (high)),
3758 GEN_INT (low));
24ea750e
DJ
3759
3760 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3761 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3762 opnum, (enum reload_type)type);
24ea750e
DJ
3763 *win = 1;
3764 return x;
3765 }
3766#if TARGET_MACHO
3767 if (GET_CODE (x) == SYMBOL_REF
3768 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3769 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3770 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3771 /* Don't do this for TFmode, since the result isn't offsettable. */
3772 && mode != TFmode)
24ea750e 3773 {
a29077da
GK
3774 if (flag_pic)
3775 {
3776 rtx offset = gen_rtx_CONST (Pmode,
3777 gen_rtx_MINUS (Pmode, x,
11abc112 3778 machopic_function_base_sym ()));
a29077da
GK
3779 x = gen_rtx_LO_SUM (GET_MODE (x),
3780 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3781 gen_rtx_HIGH (Pmode, offset)), offset);
3782 }
3783 else
3784 x = gen_rtx_LO_SUM (GET_MODE (x),
c4ad648e 3785 gen_rtx_HIGH (Pmode, x), x);
a29077da 3786
24ea750e 3787 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3788 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3789 opnum, (enum reload_type)type);
24ea750e
DJ
3790 *win = 1;
3791 return x;
3792 }
3793#endif
3794 if (TARGET_TOC
4d588c14 3795 && constant_pool_expr_p (x)
c1f11548 3796 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3797 {
3798 (x) = create_TOC_reference (x);
3799 *win = 1;
3800 return x;
3801 }
3802 *win = 0;
3803 return x;
f676971a 3804}
24ea750e 3805
258bfae2
FS
3806/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3807 that is a valid memory address for an instruction.
3808 The MODE argument is the machine mode for the MEM expression
3809 that wants to use this address.
3810
3811 On the RS/6000, there are four valid address: a SYMBOL_REF that
3812 refers to a constant pool entry of an address (or the sum of it
3813 plus a constant), a short (16-bit signed) constant plus a register,
3814 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3815 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3816 we must ensure that both words are addressable or PowerPC64 with offset
3817 word aligned.
3818
3819 For modes spanning multiple registers (DFmode in 32-bit GPRs,
76d2b81d 3820 32-bit DImode, TImode, TFmode), indexed addressing cannot be used because
258bfae2
FS
3821 adjacent memory cells are accessed by adding word-sized offsets
3822 during assembly output. */
3823int
a2369ed3 3824rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3825{
850e8d3d
DN
3826 /* If this is an unaligned stvx/ldvx type address, discard the outer AND. */
3827 if (TARGET_ALTIVEC
3828 && ALTIVEC_VECTOR_MODE (mode)
3829 && GET_CODE (x) == AND
3830 && GET_CODE (XEXP (x, 1)) == CONST_INT
3831 && INTVAL (XEXP (x, 1)) == -16)
3832 x = XEXP (x, 0);
3833
c4501e62
JJ
3834 if (RS6000_SYMBOL_REF_TLS_P (x))
3835 return 0;
4d588c14 3836 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3837 return 1;
3838 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3839 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3840 && !SPE_VECTOR_MODE (mode)
258bfae2 3841 && TARGET_UPDATE
4d588c14 3842 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3843 return 1;
4d588c14 3844 if (legitimate_small_data_p (mode, x))
258bfae2 3845 return 1;
4d588c14 3846 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3847 return 1;
3848 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3849 if (! reg_ok_strict
3850 && GET_CODE (x) == PLUS
3851 && GET_CODE (XEXP (x, 0)) == REG
708d2456 3852 && (XEXP (x, 0) == virtual_stack_vars_rtx
c4ad648e 3853 || XEXP (x, 0) == arg_pointer_rtx)
258bfae2
FS
3854 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3855 return 1;
76d2b81d 3856 if (rs6000_legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3857 return 1;
3858 if (mode != TImode
76d2b81d 3859 && mode != TFmode
a3170dc6
AH
3860 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3861 || TARGET_POWERPC64
fcce224d 3862 || (mode != DFmode && mode != TFmode))
258bfae2 3863 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3864 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3865 return 1;
4d588c14 3866 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3867 return 1;
3868 return 0;
3869}
4d588c14
RH
3870
3871/* Go to LABEL if ADDR (a legitimate address expression)
3872 has an effect that depends on the machine mode it is used for.
3873
3874 On the RS/6000 this is true of all integral offsets (since AltiVec
3875 modes don't allow them) or is a pre-increment or decrement.
3876
3877 ??? Except that due to conceptual problems in offsettable_address_p
3878 we can't really report the problems of integral offsets. So leave
f676971a 3879 this assuming that the adjustable offset must be valid for the
4d588c14
RH
3880 sub-words of a TFmode operand, which is what we had before. */
3881
3882bool
a2369ed3 3883rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3884{
3885 switch (GET_CODE (addr))
3886 {
3887 case PLUS:
3888 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3889 {
3890 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3891 return val + 12 + 0x8000 >= 0x10000;
3892 }
3893 break;
3894
3895 case LO_SUM:
3896 return true;
3897
3898 case PRE_INC:
3899 case PRE_DEC:
3900 return TARGET_UPDATE;
3901
3902 default:
3903 break;
3904 }
3905
3906 return false;
3907}
d8ecbcdb
AH
3908
3909/* Return number of consecutive hard regs needed starting at reg REGNO
3910 to hold something of mode MODE.
3911 This is ordinarily the length in words of a value of mode MODE
3912 but can be less for certain modes in special long registers.
3913
3914 For the SPE, GPRs are 64 bits but only 32 bits are visible in
3915 scalar instructions. The upper 32 bits are only available to the
3916 SIMD instructions.
3917
3918 POWER and PowerPC GPRs hold 32 bits worth;
3919 PowerPC64 GPRs and FPRs point register holds 64 bits worth. */
3920
3921int
3922rs6000_hard_regno_nregs (int regno, enum machine_mode mode)
3923{
3924 if (FP_REGNO_P (regno))
3925 return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD;
3926
3927 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
3928 return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD;
3929
3930 if (ALTIVEC_REGNO_P (regno))
3931 return
3932 (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD;
3933
3934 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3935}
2aa4498c
AH
3936
3937/* Change register usage conditional on target flags. */
3938void
3939rs6000_conditional_register_usage (void)
3940{
3941 int i;
3942
3943 /* Set MQ register fixed (already call_used) if not POWER
3944 architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not
3945 be allocated. */
3946 if (! TARGET_POWER)
3947 fixed_regs[64] = 1;
3948
3949 /* 64-bit AIX reserves GPR13 for thread-private data. */
3950 if (TARGET_64BIT)
3951 fixed_regs[13] = call_used_regs[13]
3952 = call_really_used_regs[13] = 1;
3953
3954 /* Conditionally disable FPRs. */
3955 if (TARGET_SOFT_FLOAT || !TARGET_FPRS)
3956 for (i = 32; i < 64; i++)
3957 fixed_regs[i] = call_used_regs[i]
c4ad648e 3958 = call_really_used_regs[i] = 1;
2aa4498c
AH
3959
3960 if (DEFAULT_ABI == ABI_V4
3961 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3962 && flag_pic == 2)
3963 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3964
3965 if (DEFAULT_ABI == ABI_V4
3966 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3967 && flag_pic == 1)
3968 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3969 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3970 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3971
3972 if (DEFAULT_ABI == ABI_DARWIN
3973 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
3974 global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3975 = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3976 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3977 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3978
b4db40bf
JJ
3979 if (TARGET_TOC && TARGET_MINIMAL_TOC)
3980 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3981 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3982
2aa4498c
AH
3983 if (TARGET_ALTIVEC)
3984 global_regs[VSCR_REGNO] = 1;
3985
3986 if (TARGET_SPE)
3987 {
3988 global_regs[SPEFSCR_REGNO] = 1;
3989 fixed_regs[FIXED_SCRATCH]
c4ad648e 3990 = call_used_regs[FIXED_SCRATCH]
2aa4498c
AH
3991 = call_really_used_regs[FIXED_SCRATCH] = 1;
3992 }
3993
3994 if (! TARGET_ALTIVEC)
3995 {
3996 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
3997 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
3998 call_really_used_regs[VRSAVE_REGNO] = 1;
3999 }
4000
4001 if (TARGET_ALTIVEC_ABI)
4002 for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i)
4003 call_used_regs[i] = call_really_used_regs[i] = 1;
4004}
fb4d4348 4005\f
a4f6c312
SS
4006/* Try to output insns to set TARGET equal to the constant C if it can
4007 be done in less than N insns. Do all computations in MODE.
4008 Returns the place where the output has been placed if it can be
4009 done and the insns have been emitted. If it would take more than N
4010 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
4011
4012rtx
f676971a 4013rs6000_emit_set_const (rtx dest, enum machine_mode mode,
a2369ed3 4014 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 4015{
af8cb5c5 4016 rtx result, insn, set;
2bfcf297
DB
4017 HOST_WIDE_INT c0, c1;
4018
af8cb5c5 4019 if (mode == QImode || mode == HImode)
2bfcf297
DB
4020 {
4021 if (dest == NULL)
c4ad648e 4022 dest = gen_reg_rtx (mode);
2bfcf297
DB
4023 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
4024 return dest;
4025 }
af8cb5c5 4026 else if (mode == SImode)
2bfcf297 4027 {
af8cb5c5
DE
4028 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
4029
4030 emit_insn (gen_rtx_SET (VOIDmode, result,
4031 GEN_INT (INTVAL (source)
4032 & (~ (HOST_WIDE_INT) 0xffff))));
4033 emit_insn (gen_rtx_SET (VOIDmode, dest,
4034 gen_rtx_IOR (SImode, result,
4035 GEN_INT (INTVAL (source) & 0xffff))));
4036 result = dest;
2bfcf297 4037 }
af8cb5c5 4038 else if (mode == DImode)
2bfcf297 4039 {
af8cb5c5
DE
4040 if (GET_CODE (source) == CONST_INT)
4041 {
4042 c0 = INTVAL (source);
4043 c1 = -(c0 < 0);
4044 }
4045 else if (GET_CODE (source) == CONST_DOUBLE)
4046 {
2bfcf297 4047#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
4048 c0 = CONST_DOUBLE_LOW (source);
4049 c1 = -(c0 < 0);
2bfcf297 4050#else
af8cb5c5
DE
4051 c0 = CONST_DOUBLE_LOW (source);
4052 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 4053#endif
af8cb5c5
DE
4054 }
4055 else
4056 abort ();
4057
4058 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
4059 }
4060 else
a4f6c312 4061 abort ();
2bfcf297 4062
af8cb5c5
DE
4063 insn = get_last_insn ();
4064 set = single_set (insn);
4065 if (! CONSTANT_P (SET_SRC (set)))
4066 set_unique_reg_note (insn, REG_EQUAL, source);
4067
4068 return result;
2bfcf297
DB
4069}
4070
4071/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
4072 fall back to a straight forward decomposition. We do this to avoid
4073 exponential run times encountered when looking for longer sequences
4074 with rs6000_emit_set_const. */
4075static rtx
a2369ed3 4076rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
4077{
4078 if (!TARGET_POWERPC64)
4079 {
4080 rtx operand1, operand2;
4081
4082 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
4083 DImode);
4084 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
4085 DImode);
4086 emit_move_insn (operand1, GEN_INT (c1));
4087 emit_move_insn (operand2, GEN_INT (c2));
4088 }
4089 else
4090 {
bc06712d 4091 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 4092
bc06712d 4093 ud1 = c1 & 0xffff;
f921c9c9 4094 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 4095#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 4096 c2 = c1 >> 32;
2bfcf297 4097#endif
bc06712d 4098 ud3 = c2 & 0xffff;
f921c9c9 4099 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 4100
f676971a 4101 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
bc06712d 4102 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 4103 {
bc06712d 4104 if (ud1 & 0x8000)
b78d48dd 4105 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
4106 else
4107 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 4108 }
2bfcf297 4109
f676971a 4110 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
bc06712d 4111 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 4112 {
bc06712d 4113 if (ud2 & 0x8000)
f676971a 4114 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
bc06712d 4115 - 0x80000000));
252b88f7 4116 else
bc06712d
TR
4117 emit_move_insn (dest, GEN_INT (ud2 << 16));
4118 if (ud1 != 0)
4119 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 4120 }
f676971a 4121 else if ((ud4 == 0xffff && (ud3 & 0x8000))
bc06712d
TR
4122 || (ud4 == 0 && ! (ud3 & 0x8000)))
4123 {
4124 if (ud3 & 0x8000)
f676971a 4125 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
bc06712d
TR
4126 - 0x80000000));
4127 else
4128 emit_move_insn (dest, GEN_INT (ud3 << 16));
4129
4130 if (ud2 != 0)
4131 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
4132 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
4133 if (ud1 != 0)
4134 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4135 }
f676971a 4136 else
bc06712d
TR
4137 {
4138 if (ud4 & 0x8000)
f676971a 4139 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
bc06712d
TR
4140 - 0x80000000));
4141 else
4142 emit_move_insn (dest, GEN_INT (ud4 << 16));
4143
4144 if (ud3 != 0)
4145 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 4146
bc06712d
TR
4147 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
4148 if (ud2 != 0)
f676971a
EC
4149 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
4150 GEN_INT (ud2 << 16)));
bc06712d
TR
4151 if (ud1 != 0)
4152 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4153 }
4154 }
2bfcf297
DB
4155 return dest;
4156}
4157
76d2b81d
DJ
4158/* Helper for the following. Get rid of [r+r] memory refs
4159 in cases where it won't work (TImode, TFmode). */
4160
4161static void
4162rs6000_eliminate_indexed_memrefs (rtx operands[2])
4163{
4164 if (GET_CODE (operands[0]) == MEM
4165 && GET_CODE (XEXP (operands[0], 0)) != REG
4166 && ! reload_in_progress)
4167 operands[0]
4168 = replace_equiv_address (operands[0],
4169 copy_addr_to_reg (XEXP (operands[0], 0)));
4170
4171 if (GET_CODE (operands[1]) == MEM
4172 && GET_CODE (XEXP (operands[1], 0)) != REG
4173 && ! reload_in_progress)
4174 operands[1]
4175 = replace_equiv_address (operands[1],
4176 copy_addr_to_reg (XEXP (operands[1], 0)));
4177}
4178
fb4d4348
GK
4179/* Emit a move from SOURCE to DEST in mode MODE. */
4180void
a2369ed3 4181rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
4182{
4183 rtx operands[2];
4184 operands[0] = dest;
4185 operands[1] = source;
f676971a 4186
fb4d4348
GK
4187 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
4188 if (GET_CODE (operands[1]) == CONST_DOUBLE
4189 && ! FLOAT_MODE_P (mode)
4190 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
4191 {
4192 /* FIXME. This should never happen. */
4193 /* Since it seems that it does, do the safe thing and convert
4194 to a CONST_INT. */
2496c7bd 4195 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
4196 }
4197 if (GET_CODE (operands[1]) == CONST_DOUBLE
4198 && ! FLOAT_MODE_P (mode)
4199 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
4200 && CONST_DOUBLE_LOW (operands[1]) >= 0)
4201 || (CONST_DOUBLE_HIGH (operands[1]) == -1
4202 && CONST_DOUBLE_LOW (operands[1]) < 0)))
4203 abort ();
c9e8cb32
DD
4204
4205 /* Check if GCC is setting up a block move that will end up using FP
4206 registers as temporaries. We must make sure this is acceptable. */
4207 if (GET_CODE (operands[0]) == MEM
4208 && GET_CODE (operands[1]) == MEM
4209 && mode == DImode
41543739
GK
4210 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
4211 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
4212 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
4213 ? 32 : MEM_ALIGN (operands[0])))
4214 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
f676971a 4215 ? 32
41543739
GK
4216 : MEM_ALIGN (operands[1]))))
4217 && ! MEM_VOLATILE_P (operands [0])
4218 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 4219 {
41543739
GK
4220 emit_move_insn (adjust_address (operands[0], SImode, 0),
4221 adjust_address (operands[1], SImode, 0));
4222 emit_move_insn (adjust_address (operands[0], SImode, 4),
4223 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
4224 return;
4225 }
630d42a0 4226
67cef334
DE
4227 if (!no_new_pseudos)
4228 {
4229 if (GET_CODE (operands[1]) == MEM && optimize > 0
4230 && (mode == QImode || mode == HImode || mode == SImode)
4231 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
4232 {
4233 rtx reg = gen_reg_rtx (word_mode);
4234
4235 emit_insn (gen_rtx_SET (word_mode, reg,
4236 gen_rtx_ZERO_EXTEND (word_mode,
4237 operands[1])));
4238 operands[1] = gen_lowpart (mode, reg);
4239 }
4240 if (GET_CODE (operands[0]) != REG)
4241 operands[1] = force_reg (mode, operands[1]);
4242 }
a9098fd0 4243
a3170dc6
AH
4244 if (mode == SFmode && ! TARGET_POWERPC
4245 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 4246 && GET_CODE (operands[0]) == MEM)
fb4d4348 4247 {
ffc14f31
GK
4248 int regnum;
4249
4250 if (reload_in_progress || reload_completed)
4251 regnum = true_regnum (operands[1]);
4252 else if (GET_CODE (operands[1]) == REG)
4253 regnum = REGNO (operands[1]);
4254 else
4255 regnum = -1;
f676971a 4256
fb4d4348
GK
4257 /* If operands[1] is a register, on POWER it may have
4258 double-precision data in it, so truncate it to single
4259 precision. */
4260 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
4261 {
4262 rtx newreg;
4263 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
4264 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
4265 operands[1] = newreg;
4266 }
4267 }
4268
c4501e62
JJ
4269 /* Recognize the case where operand[1] is a reference to thread-local
4270 data and load its address to a register. */
4271 if (GET_CODE (operands[1]) == SYMBOL_REF)
4272 {
4273 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
4274 if (model != 0)
4275 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
4276 }
4277
8f4e6caf
RH
4278 /* Handle the case where reload calls us with an invalid address. */
4279 if (reload_in_progress && mode == Pmode
69ef87e2 4280 && (! general_operand (operands[1], mode)
8f4e6caf
RH
4281 || ! nonimmediate_operand (operands[0], mode)))
4282 goto emit_set;
4283
a9baceb1
GK
4284 /* 128-bit constant floating-point values on Darwin should really be
4285 loaded as two parts. */
4286 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
4287 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
4288 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
4289 {
4290 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
4291 know how to get a DFmode SUBREG of a TFmode. */
4292 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
4293 simplify_gen_subreg (DImode, operands[1], mode, 0),
4294 DImode);
4295 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
4296 GET_MODE_SIZE (DImode)),
4297 simplify_gen_subreg (DImode, operands[1], mode,
4298 GET_MODE_SIZE (DImode)),
4299 DImode);
4300 return;
4301 }
4302
fb4d4348
GK
4303 /* FIXME: In the long term, this switch statement should go away
4304 and be replaced by a sequence of tests based on things like
4305 mode == Pmode. */
4306 switch (mode)
4307 {
4308 case HImode:
4309 case QImode:
4310 if (CONSTANT_P (operands[1])
4311 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 4312 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
4313 break;
4314
06f4e019 4315 case TFmode:
76d2b81d
DJ
4316 rs6000_eliminate_indexed_memrefs (operands);
4317 /* fall through */
4318
fb4d4348
GK
4319 case DFmode:
4320 case SFmode:
f676971a 4321 if (CONSTANT_P (operands[1])
fb4d4348 4322 && ! easy_fp_constant (operands[1], mode))
a9098fd0 4323 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4324 break;
f676971a 4325
0ac081f6
AH
4326 case V16QImode:
4327 case V8HImode:
4328 case V4SFmode:
4329 case V4SImode:
a3170dc6
AH
4330 case V4HImode:
4331 case V2SFmode:
4332 case V2SImode:
00a892b8 4333 case V1DImode:
69ef87e2 4334 if (CONSTANT_P (operands[1])
d744e06e 4335 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
4336 operands[1] = force_const_mem (mode, operands[1]);
4337 break;
f676971a 4338
fb4d4348 4339 case SImode:
a9098fd0 4340 case DImode:
fb4d4348
GK
4341 /* Use default pattern for address of ELF small data */
4342 if (TARGET_ELF
a9098fd0 4343 && mode == Pmode
f607bc57 4344 && DEFAULT_ABI == ABI_V4
f676971a 4345 && (GET_CODE (operands[1]) == SYMBOL_REF
a9098fd0
GK
4346 || GET_CODE (operands[1]) == CONST)
4347 && small_data_operand (operands[1], mode))
fb4d4348
GK
4348 {
4349 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4350 return;
4351 }
4352
f607bc57 4353 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
4354 && mode == Pmode && mode == SImode
4355 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
4356 {
4357 emit_insn (gen_movsi_got (operands[0], operands[1]));
4358 return;
4359 }
4360
ee890fe2 4361 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
4362 && TARGET_NO_TOC
4363 && ! flag_pic
a9098fd0 4364 && mode == Pmode
fb4d4348
GK
4365 && CONSTANT_P (operands[1])
4366 && GET_CODE (operands[1]) != HIGH
4367 && GET_CODE (operands[1]) != CONST_INT)
4368 {
a9098fd0 4369 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
4370
4371 /* If this is a function address on -mcall-aixdesc,
4372 convert it to the address of the descriptor. */
4373 if (DEFAULT_ABI == ABI_AIX
4374 && GET_CODE (operands[1]) == SYMBOL_REF
4375 && XSTR (operands[1], 0)[0] == '.')
4376 {
4377 const char *name = XSTR (operands[1], 0);
4378 rtx new_ref;
4379 while (*name == '.')
4380 name++;
4381 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
4382 CONSTANT_POOL_ADDRESS_P (new_ref)
4383 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 4384 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 4385 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 4386 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
4387 operands[1] = new_ref;
4388 }
7509c759 4389
ee890fe2
SS
4390 if (DEFAULT_ABI == ABI_DARWIN)
4391 {
ab82a49f
AP
4392#if TARGET_MACHO
4393 if (MACHO_DYNAMIC_NO_PIC_P)
4394 {
4395 /* Take care of any required data indirection. */
4396 operands[1] = rs6000_machopic_legitimize_pic_address (
4397 operands[1], mode, operands[0]);
4398 if (operands[0] != operands[1])
4399 emit_insn (gen_rtx_SET (VOIDmode,
c4ad648e 4400 operands[0], operands[1]));
ab82a49f
AP
4401 return;
4402 }
4403#endif
ac9e2cff
AP
4404 if (mode == DImode)
4405 {
4406 emit_insn (gen_macho_high_di (target, operands[1]));
4407 emit_insn (gen_macho_low_di (operands[0], target, operands[1]));
4408 }
4409 else
4410 {
4411 emit_insn (gen_macho_high (target, operands[1]));
4412 emit_insn (gen_macho_low (operands[0], target, operands[1]));
4413 }
ee890fe2
SS
4414 return;
4415 }
4416
fb4d4348
GK
4417 emit_insn (gen_elf_high (target, operands[1]));
4418 emit_insn (gen_elf_low (operands[0], target, operands[1]));
4419 return;
4420 }
4421
a9098fd0
GK
4422 /* If this is a SYMBOL_REF that refers to a constant pool entry,
4423 and we have put it in the TOC, we just need to make a TOC-relative
4424 reference to it. */
4425 if (TARGET_TOC
4426 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 4427 && constant_pool_expr_p (operands[1])
a9098fd0
GK
4428 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
4429 get_pool_mode (operands[1])))
fb4d4348 4430 {
a9098fd0 4431 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 4432 }
a9098fd0
GK
4433 else if (mode == Pmode
4434 && CONSTANT_P (operands[1])
38886f37
AO
4435 && ((GET_CODE (operands[1]) != CONST_INT
4436 && ! easy_fp_constant (operands[1], mode))
4437 || (GET_CODE (operands[1]) == CONST_INT
4438 && num_insns_constant (operands[1], mode) > 2)
4439 || (GET_CODE (operands[0]) == REG
4440 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 4441 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
4442 && ! legitimate_constant_pool_address_p (operands[1])
4443 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
4444 {
4445 /* Emit a USE operation so that the constant isn't deleted if
4446 expensive optimizations are turned on because nobody
4447 references it. This should only be done for operands that
4448 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
4449 This should not be done for operands that contain LABEL_REFs.
4450 For now, we just handle the obvious case. */
4451 if (GET_CODE (operands[1]) != LABEL_REF)
4452 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
4453
c859cda6 4454#if TARGET_MACHO
ee890fe2 4455 /* Darwin uses a special PIC legitimizer. */
ab82a49f 4456 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 4457 {
ee890fe2
SS
4458 operands[1] =
4459 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
4460 operands[0]);
4461 if (operands[0] != operands[1])
4462 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
4463 return;
4464 }
c859cda6 4465#endif
ee890fe2 4466
fb4d4348
GK
4467 /* If we are to limit the number of things we put in the TOC and
4468 this is a symbol plus a constant we can add in one insn,
4469 just put the symbol in the TOC and add the constant. Don't do
4470 this if reload is in progress. */
4471 if (GET_CODE (operands[1]) == CONST
4472 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
4473 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 4474 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
4475 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
4476 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
4477 && ! side_effects_p (operands[0]))
4478 {
a4f6c312
SS
4479 rtx sym =
4480 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
4481 rtx other = XEXP (XEXP (operands[1], 0), 1);
4482
a9098fd0
GK
4483 sym = force_reg (mode, sym);
4484 if (mode == SImode)
4485 emit_insn (gen_addsi3 (operands[0], sym, other));
4486 else
4487 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
4488 return;
4489 }
4490
a9098fd0 4491 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4492
f676971a 4493 if (TARGET_TOC
4d588c14 4494 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
4495 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
4496 get_pool_constant (XEXP (operands[1], 0)),
4497 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 4498 {
ba4828e0 4499 operands[1]
542a8afa 4500 = gen_const_mem (mode,
c4ad648e 4501 create_TOC_reference (XEXP (operands[1], 0)));
ba4828e0 4502 set_mem_alias_set (operands[1], get_TOC_alias_set ());
a9098fd0 4503 }
fb4d4348
GK
4504 }
4505 break;
a9098fd0 4506
fb4d4348 4507 case TImode:
76d2b81d
DJ
4508 rs6000_eliminate_indexed_memrefs (operands);
4509
27dc0551
DE
4510 if (TARGET_POWER)
4511 {
4512 emit_insn (gen_rtx_PARALLEL (VOIDmode,
4513 gen_rtvec (2,
4514 gen_rtx_SET (VOIDmode,
4515 operands[0], operands[1]),
4516 gen_rtx_CLOBBER (VOIDmode,
4517 gen_rtx_SCRATCH (SImode)))));
4518 return;
4519 }
fb4d4348
GK
4520 break;
4521
4522 default:
4523 abort ();
4524 }
4525
a9098fd0
GK
4526 /* Above, we may have called force_const_mem which may have returned
4527 an invalid address. If we can, fix this up; otherwise, reload will
4528 have to deal with it. */
8f4e6caf
RH
4529 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
4530 operands[1] = validize_mem (operands[1]);
a9098fd0 4531
8f4e6caf 4532 emit_set:
fb4d4348
GK
4533 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4534}
4697a36c 4535\f
2858f73a
GK
4536/* Nonzero if we can use a floating-point register to pass this arg. */
4537#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
4538 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
4539 && (CUM)->fregno <= FP_ARG_MAX_REG \
4540 && TARGET_HARD_FLOAT && TARGET_FPRS)
4541
4542/* Nonzero if we can use an AltiVec register to pass this arg. */
4543#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
4544 (ALTIVEC_VECTOR_MODE (MODE) \
4545 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
4546 && TARGET_ALTIVEC_ABI \
83953138 4547 && (NAMED))
2858f73a 4548
c6e8c921
GK
4549/* Return a nonzero value to say to return the function value in
4550 memory, just as large structures are always returned. TYPE will be
4551 the data type of the value, and FNTYPE will be the type of the
4552 function doing the returning, or @code{NULL} for libcalls.
4553
4554 The AIX ABI for the RS/6000 specifies that all structures are
4555 returned in memory. The Darwin ABI does the same. The SVR4 ABI
4556 specifies that structures <= 8 bytes are returned in r3/r4, but a
4557 draft put them in memory, and GCC used to implement the draft
4558 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
4559 controls this instead of DEFAULT_ABI; V.4 targets needing backward
4560 compatibility can change DRAFT_V4_STRUCT_RET to override the
4561 default, and -m switches get the final word. See
4562 rs6000_override_options for more details.
4563
4564 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
4565 long double support is enabled. These values are returned in memory.
4566
4567 int_size_in_bytes returns -1 for variable size objects, which go in
4568 memory always. The cast to unsigned makes -1 > 8. */
4569
4570static bool
4571rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4572{
4573 if (AGGREGATE_TYPE_P (type)
4574 && (TARGET_AIX_STRUCT_RET
4575 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
4576 return true;
4577 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
4578 return true;
4579 return false;
4580}
4581
4697a36c
MM
4582/* Initialize a variable CUM of type CUMULATIVE_ARGS
4583 for a call to a function whose data type is FNTYPE.
4584 For a library call, FNTYPE is 0.
4585
4586 For incoming args we set the number of arguments in the prototype large
1c20ae99 4587 so we never return a PARALLEL. */
4697a36c
MM
4588
4589void
f676971a 4590init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
4591 rtx libname ATTRIBUTE_UNUSED, int incoming,
4592 int libcall, int n_named_args)
4697a36c
MM
4593{
4594 static CUMULATIVE_ARGS zero_cumulative;
4595
4596 *cum = zero_cumulative;
4597 cum->words = 0;
4598 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 4599 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 4600 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
4601 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
4602 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 4603 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
4604 cum->stdarg = fntype
4605 && (TYPE_ARG_TYPES (fntype) != 0
4606 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4607 != void_type_node));
4697a36c 4608
0f6937fe
AM
4609 cum->nargs_prototype = 0;
4610 if (incoming || cum->prototype)
4611 cum->nargs_prototype = n_named_args;
4697a36c 4612
a5c76ee6
ZW
4613 /* Check for a longcall attribute. */
4614 if (fntype
4615 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
4616 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
4617 cum->call_cookie = CALL_LONG;
4618
4697a36c
MM
4619 if (TARGET_DEBUG_ARG)
4620 {
4621 fprintf (stderr, "\ninit_cumulative_args:");
4622 if (fntype)
4623 {
4624 tree ret_type = TREE_TYPE (fntype);
4625 fprintf (stderr, " ret code = %s,",
4626 tree_code_name[ (int)TREE_CODE (ret_type) ]);
4627 }
4628
6a4cee5f
MM
4629 if (cum->call_cookie & CALL_LONG)
4630 fprintf (stderr, " longcall,");
4631
4697a36c
MM
4632 fprintf (stderr, " proto = %d, nargs = %d\n",
4633 cum->prototype, cum->nargs_prototype);
4634 }
f676971a 4635
c4ad648e
AM
4636 if (fntype
4637 && !TARGET_ALTIVEC
4638 && TARGET_ALTIVEC_ABI
4639 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
4640 {
4641 error ("Cannot return value in vector register because"
4642 " altivec instructions are disabled, use -maltivec"
4643 " to enable them.");
4644 }
4697a36c
MM
4645}
4646\f
fe984136
RH
4647/* Return true if TYPE must be passed on the stack and not in registers. */
4648
4649static bool
4650rs6000_must_pass_in_stack (enum machine_mode mode, tree type)
4651{
4652 if (DEFAULT_ABI == ABI_AIX || TARGET_64BIT)
4653 return must_pass_in_stack_var_size (mode, type);
4654 else
4655 return must_pass_in_stack_var_size_or_pad (mode, type);
4656}
4657
c229cba9
DE
4658/* If defined, a C expression which determines whether, and in which
4659 direction, to pad out an argument with extra space. The value
4660 should be of type `enum direction': either `upward' to pad above
4661 the argument, `downward' to pad below, or `none' to inhibit
4662 padding.
4663
4664 For the AIX ABI structs are always stored left shifted in their
4665 argument slot. */
4666
9ebbca7d 4667enum direction
a2369ed3 4668function_arg_padding (enum machine_mode mode, tree type)
c229cba9 4669{
6e985040
AM
4670#ifndef AGGREGATE_PADDING_FIXED
4671#define AGGREGATE_PADDING_FIXED 0
4672#endif
4673#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
4674#define AGGREGATES_PAD_UPWARD_ALWAYS 0
4675#endif
4676
4677 if (!AGGREGATE_PADDING_FIXED)
4678 {
4679 /* GCC used to pass structures of the same size as integer types as
4680 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
19525b57 4681 i.e. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
6e985040
AM
4682 passed padded downward, except that -mstrict-align further
4683 muddied the water in that multi-component structures of 2 and 4
4684 bytes in size were passed padded upward.
4685
4686 The following arranges for best compatibility with previous
4687 versions of gcc, but removes the -mstrict-align dependency. */
4688 if (BYTES_BIG_ENDIAN)
4689 {
4690 HOST_WIDE_INT size = 0;
4691
4692 if (mode == BLKmode)
4693 {
4694 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4695 size = int_size_in_bytes (type);
4696 }
4697 else
4698 size = GET_MODE_SIZE (mode);
4699
4700 if (size == 1 || size == 2 || size == 4)
4701 return downward;
4702 }
4703 return upward;
4704 }
4705
4706 if (AGGREGATES_PAD_UPWARD_ALWAYS)
4707 {
4708 if (type != 0 && AGGREGATE_TYPE_P (type))
4709 return upward;
4710 }
c229cba9 4711
d3704c46
KH
4712 /* Fall back to the default. */
4713 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
4714}
4715
b6c9286a 4716/* If defined, a C expression that gives the alignment boundary, in bits,
f676971a 4717 of an argument with the specified mode and type. If it is not defined,
b6c9286a 4718 PARM_BOUNDARY is used for all arguments.
f676971a 4719
2310f99a 4720 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
4721
4722int
a2369ed3 4723function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 4724{
4ed78545
AM
4725 if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8)
4726 return 64;
4727 else if (SPE_VECTOR_MODE (mode))
e1f83b4d 4728 return 64;
b2d04ecf 4729 else if (ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4730 return 128;
9ebbca7d 4731 else
b6c9286a 4732 return PARM_BOUNDARY;
b6c9286a 4733}
c53bdcf5
AM
4734
4735/* Compute the size (in words) of a function argument. */
4736
4737static unsigned long
4738rs6000_arg_size (enum machine_mode mode, tree type)
4739{
4740 unsigned long size;
4741
4742 if (mode != BLKmode)
4743 size = GET_MODE_SIZE (mode);
4744 else
4745 size = int_size_in_bytes (type);
4746
4747 if (TARGET_32BIT)
4748 return (size + 3) >> 2;
4749 else
4750 return (size + 7) >> 3;
4751}
b6c9286a 4752\f
4697a36c
MM
4753/* Update the data in CUM to advance over an argument
4754 of mode MODE and data type TYPE.
b2d04ecf
AM
4755 (TYPE is null for libcalls where that information may not be available.)
4756
4757 Note that for args passed by reference, function_arg will be called
4758 with MODE and TYPE set to that of the pointer to the arg, not the arg
4759 itself. */
4697a36c
MM
4760
4761void
f676971a 4762function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 4763 tree type, int named)
4697a36c
MM
4764{
4765 cum->nargs_prototype--;
4766
0ac081f6
AH
4767 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4768 {
4ed78545
AM
4769 bool stack = false;
4770
2858f73a 4771 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c4ad648e 4772 {
6d0ef01e
HP
4773 cum->vregno++;
4774 if (!TARGET_ALTIVEC)
4775 error ("Cannot pass argument in vector register because"
4776 " altivec instructions are disabled, use -maltivec"
4777 " to enable them.");
4ed78545
AM
4778
4779 /* PowerPC64 Linux and AIX allocate GPRs for a vector argument
f676971a 4780 even if it is going to be passed in a vector register.
4ed78545
AM
4781 Darwin does the same for variable-argument functions. */
4782 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4783 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4784 stack = true;
6d0ef01e 4785 }
4ed78545
AM
4786 else
4787 stack = true;
4788
4789 if (stack)
c4ad648e 4790 {
a594a19c 4791 int align;
f676971a 4792
2858f73a
GK
4793 /* Vector parameters must be 16-byte aligned. This places
4794 them at 2 mod 4 in terms of words in 32-bit mode, since
4795 the parameter save area starts at offset 24 from the
4796 stack. In 64-bit mode, they just have to start on an
4797 even word, since the parameter save area is 16-byte
4798 aligned. Space for GPRs is reserved even if the argument
4799 will be passed in memory. */
4800 if (TARGET_32BIT)
4ed78545 4801 align = (2 - cum->words) & 3;
2858f73a
GK
4802 else
4803 align = cum->words & 1;
c53bdcf5 4804 cum->words += align + rs6000_arg_size (mode, type);
f676971a 4805
a594a19c
GK
4806 if (TARGET_DEBUG_ARG)
4807 {
f676971a 4808 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
a594a19c
GK
4809 cum->words, align);
4810 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
f676971a 4811 cum->nargs_prototype, cum->prototype,
2858f73a 4812 GET_MODE_NAME (mode));
a594a19c
GK
4813 }
4814 }
0ac081f6 4815 }
a4b0320c 4816 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4817 && !cum->stdarg
4818 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4819 cum->sysv_gregno++;
f607bc57 4820 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4821 {
a3170dc6 4822 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4823 && (mode == SFmode || mode == DFmode))
4697a36c 4824 {
4cc833b7
RH
4825 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4826 cum->fregno++;
4827 else
4828 {
4829 if (mode == DFmode)
c4ad648e 4830 cum->words += cum->words & 1;
c53bdcf5 4831 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4832 }
4697a36c 4833 }
4cc833b7
RH
4834 else
4835 {
b2d04ecf 4836 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4837 int gregno = cum->sysv_gregno;
4838
4ed78545
AM
4839 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4840 (r7,r8) or (r9,r10). As does any other 2 word item such
4841 as complex int due to a historical mistake. */
4842 if (n_words == 2)
4843 gregno += (1 - gregno) & 1;
4cc833b7 4844
4ed78545 4845 /* Multi-reg args are not split between registers and stack. */
4cc833b7
RH
4846 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4847 {
4ed78545
AM
4848 /* Long long and SPE vectors are aligned on the stack.
4849 So are other 2 word items such as complex int due to
4850 a historical mistake. */
4cc833b7
RH
4851 if (n_words == 2)
4852 cum->words += cum->words & 1;
4853 cum->words += n_words;
4854 }
4697a36c 4855
4cc833b7
RH
4856 /* Note: continuing to accumulate gregno past when we've started
4857 spilling to the stack indicates the fact that we've started
4858 spilling to the stack to expand_builtin_saveregs. */
4859 cum->sysv_gregno = gregno + n_words;
4860 }
4697a36c 4861
4cc833b7
RH
4862 if (TARGET_DEBUG_ARG)
4863 {
4864 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4865 cum->words, cum->fregno);
4866 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4867 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4868 fprintf (stderr, "mode = %4s, named = %d\n",
4869 GET_MODE_NAME (mode), named);
4870 }
4697a36c
MM
4871 }
4872 else
4cc833b7 4873 {
b2d04ecf
AM
4874 int n_words = rs6000_arg_size (mode, type);
4875 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
a4f6c312 4876
b2d04ecf
AM
4877 /* The simple alignment calculation here works because
4878 function_arg_boundary / PARM_BOUNDARY will only be 1 or 2.
4879 If we ever want to handle alignments larger than 8 bytes for
4880 32-bit or 16 bytes for 64-bit, then we'll need to take into
4881 account the offset to the start of the parm save area. */
4882 align &= cum->words;
4883 cum->words += align + n_words;
4697a36c 4884
a3170dc6
AH
4885 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4886 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4887 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4888
4889 if (TARGET_DEBUG_ARG)
4890 {
4891 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4892 cum->words, cum->fregno);
4893 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4894 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4895 fprintf (stderr, "named = %d, align = %d\n", named, align);
4896 }
4897 }
4697a36c 4898}
a6c9bed4
AH
4899
4900/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4901
a6c9bed4 4902static rtx
f676971a 4903rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 4904 tree type)
a6c9bed4
AH
4905{
4906 if (cum->stdarg)
4907 {
4908 int gregno = cum->sysv_gregno;
c53bdcf5 4909 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4910
4911 /* SPE vectors are put in odd registers. */
4912 if (n_words == 2 && (gregno & 1) == 0)
4913 gregno += 1;
4914
4915 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4916 {
4917 rtx r1, r2;
4918 enum machine_mode m = SImode;
4919
4920 r1 = gen_rtx_REG (m, gregno);
4921 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4922 r2 = gen_rtx_REG (m, gregno + 1);
4923 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4924 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4925 }
4926 else
b78d48dd 4927 return NULL_RTX;
a6c9bed4
AH
4928 }
4929 else
4930 {
4931 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4932 return gen_rtx_REG (mode, cum->sysv_gregno);
4933 else
b78d48dd 4934 return NULL_RTX;
a6c9bed4
AH
4935 }
4936}
4937
b78d48dd
FJ
4938/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4939
4940static rtx
ec6376ab 4941rs6000_mixed_function_arg (enum machine_mode mode, tree type, int align_words)
b78d48dd 4942{
ec6376ab
AM
4943 int n_units;
4944 int i, k;
4945 rtx rvec[GP_ARG_NUM_REG + 1];
4946
4947 if (align_words >= GP_ARG_NUM_REG)
4948 return NULL_RTX;
4949
4950 n_units = rs6000_arg_size (mode, type);
4951
4952 /* Optimize the simple case where the arg fits in one gpr, except in
4953 the case of BLKmode due to assign_parms assuming that registers are
4954 BITS_PER_WORD wide. */
4955 if (n_units == 0
4956 || (n_units == 1 && mode != BLKmode))
4957 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4958
4959 k = 0;
4960 if (align_words + n_units > GP_ARG_NUM_REG)
4961 /* Not all of the arg fits in gprs. Say that it goes in memory too,
4962 using a magic NULL_RTX component.
4963 FIXME: This is not strictly correct. Only some of the arg
4964 belongs in memory, not all of it. However, there isn't any way
4965 to do this currently, apart from building rtx descriptions for
4966 the pieces of memory we want stored. Due to bugs in the generic
4967 code we can't use the normal function_arg_partial_nregs scheme
4968 with the PARALLEL arg description we emit here.
4969 In any case, the code to store the whole arg to memory is often
4970 more efficient than code to store pieces, and we know that space
4971 is available in the right place for the whole arg. */
4972 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4973
4974 i = 0;
4975 do
36a454e1 4976 {
ec6376ab
AM
4977 rtx r = gen_rtx_REG (SImode, GP_ARG_MIN_REG + align_words);
4978 rtx off = GEN_INT (i++ * 4);
4979 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
36a454e1 4980 }
ec6376ab
AM
4981 while (++align_words < GP_ARG_NUM_REG && --n_units != 0);
4982
4983 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
b78d48dd
FJ
4984}
4985
4697a36c
MM
4986/* Determine where to put an argument to a function.
4987 Value is zero to push the argument on the stack,
4988 or a hard register in which to store the argument.
4989
4990 MODE is the argument's machine mode.
4991 TYPE is the data type of the argument (as a tree).
4992 This is null for libcalls where that information may
4993 not be available.
4994 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4995 the preceding args and about the function being called.
4996 NAMED is nonzero if this argument is a named parameter
4997 (otherwise it is an extra parameter matching an ellipsis).
4998
4999 On RS/6000 the first eight words of non-FP are normally in registers
5000 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
5001 Under V.4, the first 8 FP args are in registers.
5002
5003 If this is floating-point and no prototype is specified, we use
5004 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 5005 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 5006 so we can pass the FP value just in one register. emit_library_function
b2d04ecf
AM
5007 doesn't support PARALLEL anyway.
5008
5009 Note that for args passed by reference, function_arg will be called
5010 with MODE and TYPE set to that of the pointer to the arg, not the arg
5011 itself. */
4697a36c
MM
5012
5013struct rtx_def *
f676971a 5014function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 5015 tree type, int named)
4697a36c 5016{
4cc833b7 5017 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 5018
a4f6c312
SS
5019 /* Return a marker to indicate whether CR1 needs to set or clear the
5020 bit that V.4 uses to say fp args were passed in registers.
5021 Assume that we don't need the marker for software floating point,
5022 or compiler generated library calls. */
4697a36c
MM
5023 if (mode == VOIDmode)
5024 {
f607bc57 5025 if (abi == ABI_V4
7509c759 5026 && cum->nargs_prototype < 0
b9599e46
FS
5027 && (cum->call_cookie & CALL_LIBCALL) == 0
5028 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 5029 {
a3170dc6
AH
5030 /* For the SPE, we need to crxor CR6 always. */
5031 if (TARGET_SPE_ABI)
5032 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
5033 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
5034 return GEN_INT (cum->call_cookie
5035 | ((cum->fregno == FP_ARG_MIN_REG)
5036 ? CALL_V4_SET_FP_ARGS
5037 : CALL_V4_CLEAR_FP_ARGS));
7509c759 5038 }
4697a36c 5039
7509c759 5040 return GEN_INT (cum->call_cookie);
4697a36c
MM
5041 }
5042
2858f73a 5043 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
5044 if (TARGET_64BIT && ! cum->prototype)
5045 {
c4ad648e
AM
5046 /* Vector parameters get passed in vector register
5047 and also in GPRs or memory, in absence of prototype. */
5048 int align_words;
5049 rtx slot;
5050 align_words = (cum->words + 1) & ~1;
5051
5052 if (align_words >= GP_ARG_NUM_REG)
5053 {
5054 slot = NULL_RTX;
5055 }
5056 else
5057 {
5058 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5059 }
5060 return gen_rtx_PARALLEL (mode,
5061 gen_rtvec (2,
5062 gen_rtx_EXPR_LIST (VOIDmode,
5063 slot, const0_rtx),
5064 gen_rtx_EXPR_LIST (VOIDmode,
5065 gen_rtx_REG (mode, cum->vregno),
5066 const0_rtx)));
c72d6c26
HP
5067 }
5068 else
5069 return gen_rtx_REG (mode, cum->vregno);
2858f73a 5070 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 5071 {
2858f73a 5072 if (named || abi == ABI_V4)
a594a19c 5073 return NULL_RTX;
0ac081f6 5074 else
a594a19c
GK
5075 {
5076 /* Vector parameters to varargs functions under AIX or Darwin
5077 get passed in memory and possibly also in GPRs. */
ec6376ab
AM
5078 int align, align_words, n_words;
5079 enum machine_mode part_mode;
a594a19c
GK
5080
5081 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
5082 2 mod 4 in terms of words in 32-bit mode, since the parameter
5083 save area starts at offset 24 from the stack. In 64-bit mode,
5084 they just have to start on an even word, since the parameter
5085 save area is 16-byte aligned. */
5086 if (TARGET_32BIT)
4ed78545 5087 align = (2 - cum->words) & 3;
2858f73a
GK
5088 else
5089 align = cum->words & 1;
a594a19c
GK
5090 align_words = cum->words + align;
5091
5092 /* Out of registers? Memory, then. */
5093 if (align_words >= GP_ARG_NUM_REG)
5094 return NULL_RTX;
ec6376ab
AM
5095
5096 if (TARGET_32BIT && TARGET_POWERPC64)
5097 return rs6000_mixed_function_arg (mode, type, align_words);
5098
2858f73a
GK
5099 /* The vector value goes in GPRs. Only the part of the
5100 value in GPRs is reported here. */
ec6376ab
AM
5101 part_mode = mode;
5102 n_words = rs6000_arg_size (mode, type);
5103 if (align_words + n_words > GP_ARG_NUM_REG)
839a4992 5104 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
5105 is either wholly in GPRs or half in GPRs and half not. */
5106 part_mode = DImode;
ec6376ab
AM
5107
5108 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 5109 }
0ac081f6 5110 }
a6c9bed4
AH
5111 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
5112 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 5113 else if (abi == ABI_V4)
4697a36c 5114 {
a3170dc6 5115 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
5116 && (mode == SFmode || mode == DFmode))
5117 {
5118 if (cum->fregno <= FP_ARG_V4_MAX_REG)
5119 return gen_rtx_REG (mode, cum->fregno);
5120 else
b78d48dd 5121 return NULL_RTX;
4cc833b7
RH
5122 }
5123 else
5124 {
b2d04ecf 5125 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
5126 int gregno = cum->sysv_gregno;
5127
4ed78545
AM
5128 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
5129 (r7,r8) or (r9,r10). As does any other 2 word item such
5130 as complex int due to a historical mistake. */
5131 if (n_words == 2)
5132 gregno += (1 - gregno) & 1;
4cc833b7 5133
4ed78545 5134 /* Multi-reg args are not split between registers and stack. */
ec6376ab 5135 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
b78d48dd 5136 return NULL_RTX;
ec6376ab
AM
5137
5138 if (TARGET_32BIT && TARGET_POWERPC64)
5139 return rs6000_mixed_function_arg (mode, type,
5140 gregno - GP_ARG_MIN_REG);
5141 return gen_rtx_REG (mode, gregno);
4cc833b7 5142 }
4697a36c 5143 }
4cc833b7
RH
5144 else
5145 {
b2d04ecf
AM
5146 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5147 int align_words = cum->words + (cum->words & align);
b78d48dd 5148
2858f73a 5149 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 5150 {
ec6376ab
AM
5151 rtx rvec[GP_ARG_NUM_REG + 1];
5152 rtx r;
5153 int k;
c53bdcf5
AM
5154 bool needs_psave;
5155 enum machine_mode fmode = mode;
c53bdcf5
AM
5156 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
5157
5158 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
5159 {
c53bdcf5
AM
5160 /* Currently, we only ever need one reg here because complex
5161 doubles are split. */
ec6376ab 5162 if (cum->fregno != FP_ARG_MAX_REG || fmode != TFmode)
c53bdcf5 5163 abort ();
ec6376ab
AM
5164
5165 /* Long double split over regs and memory. */
5166 fmode = DFmode;
c53bdcf5 5167 }
c53bdcf5
AM
5168
5169 /* Do we also need to pass this arg in the parameter save
5170 area? */
5171 needs_psave = (type
5172 && (cum->nargs_prototype <= 0
5173 || (DEFAULT_ABI == ABI_AIX
5174 && TARGET_XL_CALL
5175 && align_words >= GP_ARG_NUM_REG)));
5176
5177 if (!needs_psave && mode == fmode)
ec6376ab 5178 return gen_rtx_REG (fmode, cum->fregno);
c53bdcf5 5179
ec6376ab 5180 k = 0;
c53bdcf5
AM
5181 if (needs_psave)
5182 {
ec6376ab 5183 /* Describe the part that goes in gprs or the stack.
c53bdcf5 5184 This piece must come first, before the fprs. */
c53bdcf5
AM
5185 if (align_words < GP_ARG_NUM_REG)
5186 {
5187 unsigned long n_words = rs6000_arg_size (mode, type);
ec6376ab
AM
5188
5189 if (align_words + n_words > GP_ARG_NUM_REG
5190 || (TARGET_32BIT && TARGET_POWERPC64))
5191 {
5192 /* If this is partially on the stack, then we only
5193 include the portion actually in registers here. */
5194 enum machine_mode rmode = TARGET_32BIT ? SImode : DImode;
5195 rtx off;
2e6c9641 5196 int i=0;
c4ad648e
AM
5197 if (align_words + n_words > GP_ARG_NUM_REG
5198 && (TARGET_32BIT && TARGET_POWERPC64))
5199 /* Not all of the arg fits in gprs. Say that it
5200 goes in memory too, using a magic NULL_RTX
5201 component. Also see comment in
5202 rs6000_mixed_function_arg for why the normal
5203 function_arg_partial_nregs scheme doesn't work
5204 in this case. */
5205 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX,
5206 const0_rtx);
ec6376ab
AM
5207 do
5208 {
5209 r = gen_rtx_REG (rmode,
5210 GP_ARG_MIN_REG + align_words);
2e6c9641 5211 off = GEN_INT (i++ * GET_MODE_SIZE (rmode));
ec6376ab
AM
5212 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
5213 }
5214 while (++align_words < GP_ARG_NUM_REG && --n_words != 0);
5215 }
5216 else
5217 {
5218 /* The whole arg fits in gprs. */
5219 r = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5220 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5221 }
c53bdcf5 5222 }
ec6376ab
AM
5223 else
5224 /* It's entirely in memory. */
5225 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
c53bdcf5
AM
5226 }
5227
ec6376ab
AM
5228 /* Describe where this piece goes in the fprs. */
5229 r = gen_rtx_REG (fmode, cum->fregno);
5230 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5231
5232 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
4cc833b7
RH
5233 }
5234 else if (align_words < GP_ARG_NUM_REG)
b2d04ecf 5235 {
ec6376ab
AM
5236 if (TARGET_32BIT && TARGET_POWERPC64)
5237 return rs6000_mixed_function_arg (mode, type, align_words);
b2d04ecf
AM
5238
5239 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5240 }
4cc833b7
RH
5241 else
5242 return NULL_RTX;
4697a36c 5243 }
4697a36c
MM
5244}
5245\f
ec6376ab
AM
5246/* For an arg passed partly in registers and partly in memory, this is
5247 the number of registers used. For args passed entirely in registers
5248 or entirely in memory, zero. When an arg is described by a PARALLEL,
5249 perhaps using more than one register type, this function returns the
5250 number of registers used by the first element of the PARALLEL. */
4697a36c
MM
5251
5252int
f676971a 5253function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 5254 tree type, int named)
4697a36c 5255{
c53bdcf5 5256 int ret = 0;
ec6376ab
AM
5257 int align;
5258 int parm_offset;
5259 int align_words;
c53bdcf5 5260
f607bc57 5261 if (DEFAULT_ABI == ABI_V4)
4697a36c 5262 return 0;
4697a36c 5263
c53bdcf5
AM
5264 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
5265 && cum->nargs_prototype >= 0)
5266 return 0;
5267
ec6376ab
AM
5268 align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5269 parm_offset = TARGET_32BIT ? 2 : 0;
5270 align_words = cum->words + ((parm_offset - cum->words) & align);
5271
5272 if (USE_FP_FOR_ARG_P (cum, mode, type)
5273 /* If we are passing this arg in gprs as well, then this function
5274 should return the number of gprs (or memory) partially passed,
5275 *not* the number of fprs. */
5276 && !(type
5277 && (cum->nargs_prototype <= 0
5278 || (DEFAULT_ABI == ABI_AIX
5279 && TARGET_XL_CALL
5280 && align_words >= GP_ARG_NUM_REG))))
4697a36c 5281 {
c53bdcf5 5282 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
ec6376ab 5283 ret = FP_ARG_MAX_REG + 1 - cum->fregno;
c53bdcf5 5284 else if (cum->nargs_prototype >= 0)
4697a36c
MM
5285 return 0;
5286 }
5287
ec6376ab
AM
5288 if (align_words < GP_ARG_NUM_REG
5289 && GP_ARG_NUM_REG < align_words + rs6000_arg_size (mode, type))
5290 ret = GP_ARG_NUM_REG - align_words;
4697a36c 5291
c53bdcf5
AM
5292 if (ret != 0 && TARGET_DEBUG_ARG)
5293 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 5294
c53bdcf5 5295 return ret;
4697a36c
MM
5296}
5297\f
5298/* A C expression that indicates when an argument must be passed by
5299 reference. If nonzero for an argument, a copy of that argument is
5300 made in memory and a pointer to the argument is passed instead of
5301 the argument itself. The pointer is passed in whatever way is
5302 appropriate for passing a pointer to that type.
5303
b2d04ecf
AM
5304 Under V.4, aggregates and long double are passed by reference.
5305
5306 As an extension to all 32-bit ABIs, AltiVec vectors are passed by
5307 reference unless the AltiVec vector extension ABI is in force.
c8c99a68
DE
5308
5309 As an extension to all ABIs, variable sized types are passed by
5310 reference. */
4697a36c 5311
8cd5a4e0 5312static bool
f676971a
EC
5313rs6000_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5314 enum machine_mode mode ATTRIBUTE_UNUSED,
8cd5a4e0 5315 tree type, bool named ATTRIBUTE_UNUSED)
4697a36c 5316{
b2d04ecf
AM
5317 if ((DEFAULT_ABI == ABI_V4
5318 && ((type && AGGREGATE_TYPE_P (type))
5319 || mode == TFmode))
5320 || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
5321 || (type && int_size_in_bytes (type) < 0))
4697a36c
MM
5322 {
5323 if (TARGET_DEBUG_ARG)
b2d04ecf 5324 fprintf (stderr, "function_arg_pass_by_reference\n");
4697a36c
MM
5325
5326 return 1;
5327 }
b2d04ecf 5328 return 0;
4697a36c 5329}
5985c7a6
FJ
5330
5331static void
2d9db8eb 5332rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
5333{
5334 int i;
5335 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
5336
5337 if (nregs == 0)
5338 return;
5339
c4ad648e 5340 for (i = 0; i < nregs; i++)
5985c7a6
FJ
5341 {
5342 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
5343 if (reload_completed)
c4ad648e
AM
5344 {
5345 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
5346 tem = NULL_RTX;
5347 else
5348 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
5349 i * GET_MODE_SIZE(reg_mode));
5350 }
5985c7a6
FJ
5351 else
5352 tem = replace_equiv_address (tem, XEXP (tem, 0));
5353
5354 if (tem == NULL_RTX)
c4ad648e 5355 abort ();
5985c7a6
FJ
5356
5357 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
5358 }
5359}
4697a36c
MM
5360\f
5361/* Perform any needed actions needed for a function that is receiving a
f676971a 5362 variable number of arguments.
4697a36c
MM
5363
5364 CUM is as above.
5365
5366 MODE and TYPE are the mode and type of the current parameter.
5367
5368 PRETEND_SIZE is a variable that should be set to the amount of stack
5369 that must be pushed by the prolog to pretend that our caller pushed
5370 it.
5371
5372 Normally, this macro will push all remaining incoming registers on the
5373 stack and set PRETEND_SIZE to the length of the registers pushed. */
5374
c6e8c921 5375static void
f676971a 5376setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
c4ad648e
AM
5377 tree type, int *pretend_size ATTRIBUTE_UNUSED,
5378 int no_rtl)
4697a36c 5379{
4cc833b7
RH
5380 CUMULATIVE_ARGS next_cum;
5381 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 5382 rtx save_area = NULL_RTX, mem;
dfafc897 5383 int first_reg_offset, set;
4697a36c 5384
f31bf321 5385 /* Skip the last named argument. */
d34c5b80 5386 next_cum = *cum;
f31bf321 5387 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 5388
f607bc57 5389 if (DEFAULT_ABI == ABI_V4)
d34c5b80 5390 {
60e2d0ca 5391 if (! no_rtl)
2c4974b7 5392 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 5393 - RS6000_VARARGS_SIZE);
4cc833b7
RH
5394
5395 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 5396 }
60e2d0ca 5397 else
4697a36c 5398 {
d34c5b80 5399 first_reg_offset = next_cum.words;
4cc833b7 5400 save_area = virtual_incoming_args_rtx;
4697a36c 5401
fe984136 5402 if (targetm.calls.must_pass_in_stack (mode, type))
c53bdcf5 5403 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 5404 }
4697a36c 5405
dfafc897 5406 set = get_varargs_alias_set ();
5496b36f 5407 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 5408 {
dfafc897 5409 mem = gen_rtx_MEM (BLKmode,
c4ad648e 5410 plus_constant (save_area,
dfafc897 5411 first_reg_offset * reg_size)),
ba4828e0 5412 set_mem_alias_set (mem, set);
8ac61af7 5413 set_mem_align (mem, BITS_PER_WORD);
dfafc897 5414
f676971a 5415 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
c4ad648e 5416 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
5417 }
5418
4697a36c 5419 /* Save FP registers if needed. */
f607bc57 5420 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
5421 && TARGET_HARD_FLOAT && TARGET_FPRS
5422 && ! no_rtl
5496b36f 5423 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 5424 {
5496b36f 5425 int fregno = next_cum.fregno;
9ebbca7d 5426 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
5427 rtx lab = gen_label_rtx ();
5428 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 5429
c4ad648e
AM
5430 emit_jump_insn
5431 (gen_rtx_SET (VOIDmode,
5432 pc_rtx,
5433 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7 5434 gen_rtx_NE (VOIDmode, cr1,
c4ad648e 5435 const0_rtx),
39403d82 5436 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
5437 pc_rtx)));
5438
5496b36f 5439 while (fregno <= FP_ARG_V4_MAX_REG)
4cc833b7 5440 {
5496b36f 5441 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
c4ad648e 5442 set_mem_alias_set (mem, set);
dfafc897 5443 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
5496b36f
JJ
5444 fregno++;
5445 off += 8;
4697a36c 5446 }
4cc833b7
RH
5447
5448 emit_label (lab);
4697a36c 5449 }
4697a36c 5450}
4697a36c 5451
dfafc897 5452/* Create the va_list data type. */
2c4974b7 5453
c35d187f
RH
5454static tree
5455rs6000_build_builtin_va_list (void)
dfafc897 5456{
64c2816f 5457 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 5458
9ebbca7d
GK
5459 /* For AIX, prefer 'char *' because that's what the system
5460 header files like. */
f607bc57 5461 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 5462 return build_pointer_type (char_type_node);
dfafc897 5463
f1e639b1 5464 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 5465 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 5466
f676971a 5467 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
9ebbca7d 5468 unsigned_char_type_node);
f676971a 5469 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
9ebbca7d 5470 unsigned_char_type_node);
64c2816f
DT
5471 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
5472 every user file. */
5473 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
5474 short_unsigned_type_node);
dfafc897
FS
5475 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
5476 ptr_type_node);
5477 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
5478 ptr_type_node);
5479
5480 DECL_FIELD_CONTEXT (f_gpr) = record;
5481 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 5482 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
5483 DECL_FIELD_CONTEXT (f_ovf) = record;
5484 DECL_FIELD_CONTEXT (f_sav) = record;
5485
bab45a51
FS
5486 TREE_CHAIN (record) = type_decl;
5487 TYPE_NAME (record) = type_decl;
dfafc897
FS
5488 TYPE_FIELDS (record) = f_gpr;
5489 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
5490 TREE_CHAIN (f_fpr) = f_res;
5491 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
5492 TREE_CHAIN (f_ovf) = f_sav;
5493
5494 layout_type (record);
5495
5496 /* The correct type is an array type of one element. */
5497 return build_array_type (record, build_index_type (size_zero_node));
5498}
5499
5500/* Implement va_start. */
5501
5502void
a2369ed3 5503rs6000_va_start (tree valist, rtx nextarg)
4697a36c 5504{
dfafc897 5505 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 5506 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 5507 tree gpr, fpr, ovf, sav, t;
2c4974b7 5508
dfafc897 5509 /* Only SVR4 needs something special. */
f607bc57 5510 if (DEFAULT_ABI != ABI_V4)
dfafc897 5511 {
e5faf155 5512 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
5513 return;
5514 }
5515
973a648b 5516 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5517 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5518 f_res = TREE_CHAIN (f_fpr);
5519 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5520 f_sav = TREE_CHAIN (f_ovf);
5521
8ebecc3b 5522 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
44de5aeb
RK
5523 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5524 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5525 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5526 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
dfafc897
FS
5527
5528 /* Count number of gp and fp argument registers used. */
4cc833b7 5529 words = current_function_args_info.words;
dfafc897
FS
5530 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
5531 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
5532
5533 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
5534 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
5535 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
5536 words, n_gpr, n_fpr);
dfafc897 5537
5496b36f
JJ
5538 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr,
5539 build_int_cst (NULL_TREE, n_gpr));
5540 TREE_SIDE_EFFECTS (t) = 1;
5541 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
58c8adc1 5542
5496b36f
JJ
5543 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr,
5544 build_int_cst (NULL_TREE, n_fpr));
5545 TREE_SIDE_EFFECTS (t) = 1;
5546 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
dfafc897
FS
5547
5548 /* Find the overflow area. */
5549 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
5550 if (words != 0)
5551 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
7d60be94 5552 build_int_cst (NULL_TREE, words * UNITS_PER_WORD));
dfafc897
FS
5553 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5554 TREE_SIDE_EFFECTS (t) = 1;
5555 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5556
5557 /* Find the register save area. */
5558 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
5559 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
7d60be94 5560 build_int_cst (NULL_TREE, -RS6000_VARARGS_SIZE));
dfafc897
FS
5561 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
5562 TREE_SIDE_EFFECTS (t) = 1;
5563 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5564}
5565
5566/* Implement va_arg. */
5567
23a60a04
JM
5568tree
5569rs6000_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
cd3ce9b4 5570{
cd3ce9b4
JM
5571 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
5572 tree gpr, fpr, ovf, sav, reg, t, u;
08b0dc1b 5573 int size, rsize, n_reg, sav_ofs, sav_scale;
cd3ce9b4
JM
5574 tree lab_false, lab_over, addr;
5575 int align;
5576 tree ptrtype = build_pointer_type (type);
5577
08b0dc1b
RH
5578 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
5579 {
5580 t = rs6000_gimplify_va_arg (valist, ptrtype, pre_p, post_p);
5581 return build_fold_indirect_ref (t);
5582 }
5583
cd3ce9b4
JM
5584 if (DEFAULT_ABI != ABI_V4)
5585 {
08b0dc1b 5586 if (targetm.calls.split_complex_arg && TREE_CODE (type) == COMPLEX_TYPE)
cd3ce9b4
JM
5587 {
5588 tree elem_type = TREE_TYPE (type);
5589 enum machine_mode elem_mode = TYPE_MODE (elem_type);
5590 int elem_size = GET_MODE_SIZE (elem_mode);
5591
5592 if (elem_size < UNITS_PER_WORD)
5593 {
23a60a04 5594 tree real_part, imag_part;
cd3ce9b4
JM
5595 tree post = NULL_TREE;
5596
23a60a04
JM
5597 real_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5598 &post);
5599 /* Copy the value into a temporary, lest the formal temporary
5600 be reused out from under us. */
5601 real_part = get_initialized_tmp_var (real_part, pre_p, &post);
cd3ce9b4
JM
5602 append_to_statement_list (post, pre_p);
5603
23a60a04
JM
5604 imag_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5605 post_p);
cd3ce9b4 5606
23a60a04 5607 return build (COMPLEX_EXPR, type, real_part, imag_part);
cd3ce9b4
JM
5608 }
5609 }
5610
23a60a04 5611 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
cd3ce9b4
JM
5612 }
5613
5614 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
5615 f_fpr = TREE_CHAIN (f_gpr);
5616 f_res = TREE_CHAIN (f_fpr);
5617 f_ovf = TREE_CHAIN (f_res);
5618 f_sav = TREE_CHAIN (f_ovf);
5619
5620 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
44de5aeb
RK
5621 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5622 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5623 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5624 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
cd3ce9b4
JM
5625
5626 size = int_size_in_bytes (type);
5627 rsize = (size + 3) / 4;
5628 align = 1;
5629
08b0dc1b
RH
5630 if (TARGET_HARD_FLOAT && TARGET_FPRS
5631 && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode))
cd3ce9b4
JM
5632 {
5633 /* FP args go in FP registers, if present. */
cd3ce9b4
JM
5634 reg = fpr;
5635 n_reg = 1;
5636 sav_ofs = 8*4;
5637 sav_scale = 8;
5638 if (TYPE_MODE (type) == DFmode)
5639 align = 8;
5640 }
5641 else
5642 {
5643 /* Otherwise into GP registers. */
cd3ce9b4
JM
5644 reg = gpr;
5645 n_reg = rsize;
5646 sav_ofs = 0;
5647 sav_scale = 4;
5648 if (n_reg == 2)
5649 align = 8;
5650 }
5651
5652 /* Pull the value out of the saved registers.... */
5653
5654 lab_over = NULL;
5655 addr = create_tmp_var (ptr_type_node, "addr");
5656 DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
5657
5658 /* AltiVec vectors never go in registers when -mabi=altivec. */
5659 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
5660 align = 16;
5661 else
5662 {
5663 lab_false = create_artificial_label ();
5664 lab_over = create_artificial_label ();
5665
5666 /* Long long and SPE vectors are aligned in the registers.
5667 As are any other 2 gpr item such as complex int due to a
5668 historical mistake. */
5669 u = reg;
5670 if (n_reg == 2)
5671 {
5672 u = build2 (BIT_AND_EXPR, TREE_TYPE (reg), reg,
95674810 5673 size_int (n_reg - 1));
cd3ce9b4
JM
5674 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u);
5675 }
5676
95674810 5677 t = fold_convert (TREE_TYPE (reg), size_int (8 - n_reg + 1));
cd3ce9b4
JM
5678 t = build2 (GE_EXPR, boolean_type_node, u, t);
5679 u = build1 (GOTO_EXPR, void_type_node, lab_false);
5680 t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE);
5681 gimplify_and_add (t, pre_p);
5682
5683 t = sav;
5684 if (sav_ofs)
95674810 5685 t = build2 (PLUS_EXPR, ptr_type_node, sav, size_int (sav_ofs));
cd3ce9b4 5686
95674810 5687 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, size_int (n_reg));
cd3ce9b4 5688 u = build1 (CONVERT_EXPR, integer_type_node, u);
95674810 5689 u = build2 (MULT_EXPR, integer_type_node, u, size_int (sav_scale));
cd3ce9b4
JM
5690 t = build2 (PLUS_EXPR, ptr_type_node, t, u);
5691
5692 t = build2 (MODIFY_EXPR, void_type_node, addr, t);
5693 gimplify_and_add (t, pre_p);
5694
5695 t = build1 (GOTO_EXPR, void_type_node, lab_over);
5696 gimplify_and_add (t, pre_p);
5697
5698 t = build1 (LABEL_EXPR, void_type_node, lab_false);
5699 append_to_statement_list (t, pre_p);
5700
5701 if (n_reg > 2)
5702 {
5703 /* Ensure that we don't find any more args in regs.
5704 Alignment has taken care of the n_reg == 2 case. */
95674810 5705 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, size_int (8));
cd3ce9b4
JM
5706 gimplify_and_add (t, pre_p);
5707 }
5708 }
5709
5710 /* ... otherwise out of the overflow area. */
5711
5712 /* Care for on-stack alignment if needed. */
5713 t = ovf;
5714 if (align != 1)
5715 {
95674810 5716 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (align - 1));
4a90aeeb 5717 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
7d60be94 5718 build_int_cst (NULL_TREE, -align));
cd3ce9b4
JM
5719 }
5720 gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
5721
5722 u = build2 (MODIFY_EXPR, void_type_node, addr, t);
5723 gimplify_and_add (u, pre_p);
5724
95674810 5725 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (size));
cd3ce9b4
JM
5726 t = build2 (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5727 gimplify_and_add (t, pre_p);
5728
5729 if (lab_over)
5730 {
5731 t = build1 (LABEL_EXPR, void_type_node, lab_over);
5732 append_to_statement_list (t, pre_p);
5733 }
5734
08b0dc1b 5735 addr = fold_convert (ptrtype, addr);
23a60a04 5736 return build_fold_indirect_ref (addr);
cd3ce9b4
JM
5737}
5738
0ac081f6
AH
5739/* Builtins. */
5740
6e34d3a3
JM
5741#define def_builtin(MASK, NAME, TYPE, CODE) \
5742do { \
5743 if ((MASK) & target_flags) \
5744 lang_hooks.builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
5745 NULL, NULL_TREE); \
0ac081f6
AH
5746} while (0)
5747
24408032
AH
5748/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
5749
2212663f 5750static const struct builtin_description bdesc_3arg[] =
24408032
AH
5751{
5752 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
5753 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
5754 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
5755 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
5756 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
5757 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
5758 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
5759 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
5760 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
5761 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
f676971a 5762 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
24408032
AH
5763 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
5764 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
5765 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
5766 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
5767 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
5768 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
5769 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
5770 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
5771 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
5772 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
5773 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
5774 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
5775};
2212663f 5776
95385cbb
AH
5777/* DST operations: void foo (void *, const int, const char). */
5778
5779static const struct builtin_description bdesc_dst[] =
5780{
5781 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
5782 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
5783 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
5784 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
5785};
5786
2212663f 5787/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 5788
a3170dc6 5789static struct builtin_description bdesc_2arg[] =
0ac081f6 5790{
f18c054f
DB
5791 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
5792 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
5793 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
5794 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
5795 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
5796 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
5797 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
5798 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
5799 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
5800 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
5801 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 5802 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
5803 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
5804 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
5805 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
5806 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
5807 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
5808 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
5809 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
5810 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
5811 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
5812 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
5813 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
5814 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5815 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5816 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5817 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5818 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5819 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5820 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5821 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5822 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5823 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5824 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5825 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5826 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5827 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5828 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5829 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5830 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5831 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5832 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5833 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5834 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5835 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5836 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5837 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5838 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5839 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5840 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5841 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5842 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5843 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5844 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5845 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5846 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5847 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5848 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5849 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5850 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5851 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5852 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5853 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5854 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5855 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5856 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5857 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5858 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5859 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5860 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5861 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5862 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5863 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5864 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5865 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5866 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5867 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5868 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5869 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5870 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5871 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5872 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5873 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5874 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5875 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5876 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5877 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5878 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5879 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5880 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5881 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5882 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5883 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5884 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5885 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5886 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5887 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5888 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5889 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5890 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5891 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5892 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5893 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5894 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5895 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5896 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5897 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5898 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5899 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5900 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5901 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5902 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5903 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5904
5905 /* Place holder, leave as first spe builtin. */
5906 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5907 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5908 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5909 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5910 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5911 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5912 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5913 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5914 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5915 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5916 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5917 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5918 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5919 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5920 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5921 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5922 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5923 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5924 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5925 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5926 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5927 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5928 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5929 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5930 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5931 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5932 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5933 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5934 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5935 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5936 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5937 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5938 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5939 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5940 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5941 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5942 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5943 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5944 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5945 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5946 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5947 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5948 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5949 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5950 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5951 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5952 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5953 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5954 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5955 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5956 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5957 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5958 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5959 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5960 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5961 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5962 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5963 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5964 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5965 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5966 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5967 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5968 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5969 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5970 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5971 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5972 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5973 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5974 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5975 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5976 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5977 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5978 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5979 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5980 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5981 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5982 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5983 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5984 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5985 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5986 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5987 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5988 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5989 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5990 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5991 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5992 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5993 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5994 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5995 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5996 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5997 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5998 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5999 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
6000 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
6001 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
6002 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
6003 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
6004 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
6005 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
6006 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
6007 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
6008 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
6009 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
6010 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
6011 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
6012 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
6013 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
6014 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
6015
6016 /* SPE binary operations expecting a 5-bit unsigned literal. */
6017 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
6018
6019 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
6020 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
6021 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
6022 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
6023 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
6024 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
6025 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
6026 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
6027 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
6028 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
6029 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
6030 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
6031 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
6032 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
6033 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
6034 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
6035 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
6036 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
6037 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
6038 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
6039 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
6040 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
6041 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
6042 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
6043 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
6044 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
6045
6046 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 6047 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
6048};
6049
6050/* AltiVec predicates. */
6051
6052struct builtin_description_predicates
6053{
6054 const unsigned int mask;
6055 const enum insn_code icode;
6056 const char *opcode;
6057 const char *const name;
6058 const enum rs6000_builtins code;
6059};
6060
6061static const struct builtin_description_predicates bdesc_altivec_preds[] =
6062{
6063 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
6064 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
6065 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
6066 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
6067 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
6068 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
6069 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
6070 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
6071 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
6072 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
6073 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
6074 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
6075 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 6076};
24408032 6077
a3170dc6
AH
6078/* SPE predicates. */
6079static struct builtin_description bdesc_spe_predicates[] =
6080{
6081 /* Place-holder. Leave as first. */
6082 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
6083 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
6084 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
6085 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
6086 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
6087 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
6088 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
6089 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
6090 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
6091 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
6092 /* Place-holder. Leave as last. */
6093 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
6094};
6095
6096/* SPE evsel predicates. */
6097static struct builtin_description bdesc_spe_evsel[] =
6098{
6099 /* Place-holder. Leave as first. */
6100 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
6101 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
6102 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
6103 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
6104 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
6105 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
6106 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
6107 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
6108 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
6109 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
6110 /* Place-holder. Leave as last. */
6111 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
6112};
6113
b6d08ca1 6114/* ABS* operations. */
100c4561
AH
6115
6116static const struct builtin_description bdesc_abs[] =
6117{
6118 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
6119 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
6120 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
6121 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
6122 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
6123 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
6124 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
6125};
6126
617e0e1d
DB
6127/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
6128 foo (VECa). */
24408032 6129
a3170dc6 6130static struct builtin_description bdesc_1arg[] =
2212663f 6131{
617e0e1d
DB
6132 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
6133 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
6134 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
6135 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
6136 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
6137 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
6138 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
6139 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
6140 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
6141 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
6142 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
6143 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
6144 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
6145 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
6146 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
6147 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
6148 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
6149
6150 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
6151 end with SPE_BUILTIN_EVSUBFUSIAAW. */
6152 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
6153 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
6154 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
6155 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
6156 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
6157 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
6158 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
6159 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
6160 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
6161 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
6162 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
6163 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
6164 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
6165 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
6166 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
6167 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
6168 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
6169 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
6170 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
6171 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
6172 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
6173 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
6174 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
6a599451 6175 { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
a3170dc6
AH
6176 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
6177 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
6178 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
6179 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
6180
6181 /* Place-holder. Leave as last unary SPE builtin. */
6182 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
6183};
6184
6185static rtx
a2369ed3 6186rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6187{
6188 rtx pat;
6189 tree arg0 = TREE_VALUE (arglist);
6190 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6191 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6192 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6193
0559cc77
DE
6194 if (icode == CODE_FOR_nothing)
6195 /* Builtin not supported on this processor. */
6196 return 0;
6197
20e26713
AH
6198 /* If we got invalid arguments bail out before generating bad rtl. */
6199 if (arg0 == error_mark_node)
9a171fcd 6200 return const0_rtx;
20e26713 6201
0559cc77
DE
6202 if (icode == CODE_FOR_altivec_vspltisb
6203 || icode == CODE_FOR_altivec_vspltish
6204 || icode == CODE_FOR_altivec_vspltisw
6205 || icode == CODE_FOR_spe_evsplatfi
6206 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
6207 {
6208 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
6209 if (GET_CODE (op0) != CONST_INT
6210 || INTVAL (op0) > 0x1f
6211 || INTVAL (op0) < -0x1f)
6212 {
6213 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 6214 return const0_rtx;
b44140e7 6215 }
b44140e7
AH
6216 }
6217
c62f2db5 6218 if (target == 0
2212663f
DB
6219 || GET_MODE (target) != tmode
6220 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6221 target = gen_reg_rtx (tmode);
6222
6223 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6224 op0 = copy_to_mode_reg (mode0, op0);
6225
6226 pat = GEN_FCN (icode) (target, op0);
6227 if (! pat)
6228 return 0;
6229 emit_insn (pat);
0ac081f6 6230
2212663f
DB
6231 return target;
6232}
ae4b4a02 6233
100c4561 6234static rtx
a2369ed3 6235altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
6236{
6237 rtx pat, scratch1, scratch2;
6238 tree arg0 = TREE_VALUE (arglist);
6239 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6240 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6241 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6242
6243 /* If we have invalid arguments, bail out before generating bad rtl. */
6244 if (arg0 == error_mark_node)
9a171fcd 6245 return const0_rtx;
100c4561
AH
6246
6247 if (target == 0
6248 || GET_MODE (target) != tmode
6249 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6250 target = gen_reg_rtx (tmode);
6251
6252 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6253 op0 = copy_to_mode_reg (mode0, op0);
6254
6255 scratch1 = gen_reg_rtx (mode0);
6256 scratch2 = gen_reg_rtx (mode0);
6257
6258 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
6259 if (! pat)
6260 return 0;
6261 emit_insn (pat);
6262
6263 return target;
6264}
6265
0ac081f6 6266static rtx
a2369ed3 6267rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
6268{
6269 rtx pat;
6270 tree arg0 = TREE_VALUE (arglist);
6271 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6272 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6273 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6274 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6275 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6276 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6277
0559cc77
DE
6278 if (icode == CODE_FOR_nothing)
6279 /* Builtin not supported on this processor. */
6280 return 0;
6281
20e26713
AH
6282 /* If we got invalid arguments bail out before generating bad rtl. */
6283 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6284 return const0_rtx;
20e26713 6285
0559cc77
DE
6286 if (icode == CODE_FOR_altivec_vcfux
6287 || icode == CODE_FOR_altivec_vcfsx
6288 || icode == CODE_FOR_altivec_vctsxs
6289 || icode == CODE_FOR_altivec_vctuxs
6290 || icode == CODE_FOR_altivec_vspltb
6291 || icode == CODE_FOR_altivec_vsplth
6292 || icode == CODE_FOR_altivec_vspltw
6293 || icode == CODE_FOR_spe_evaddiw
6294 || icode == CODE_FOR_spe_evldd
6295 || icode == CODE_FOR_spe_evldh
6296 || icode == CODE_FOR_spe_evldw
6297 || icode == CODE_FOR_spe_evlhhesplat
6298 || icode == CODE_FOR_spe_evlhhossplat
6299 || icode == CODE_FOR_spe_evlhhousplat
6300 || icode == CODE_FOR_spe_evlwhe
6301 || icode == CODE_FOR_spe_evlwhos
6302 || icode == CODE_FOR_spe_evlwhou
6303 || icode == CODE_FOR_spe_evlwhsplat
6304 || icode == CODE_FOR_spe_evlwwsplat
6305 || icode == CODE_FOR_spe_evrlwi
6306 || icode == CODE_FOR_spe_evslwi
6307 || icode == CODE_FOR_spe_evsrwis
f5119d10 6308 || icode == CODE_FOR_spe_evsubifw
0559cc77 6309 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
6310 {
6311 /* Only allow 5-bit unsigned literals. */
8bb418a3 6312 STRIP_NOPS (arg1);
b44140e7
AH
6313 if (TREE_CODE (arg1) != INTEGER_CST
6314 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6315 {
6316 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 6317 return const0_rtx;
b44140e7 6318 }
b44140e7
AH
6319 }
6320
c62f2db5 6321 if (target == 0
0ac081f6
AH
6322 || GET_MODE (target) != tmode
6323 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6324 target = gen_reg_rtx (tmode);
6325
6326 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6327 op0 = copy_to_mode_reg (mode0, op0);
6328 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6329 op1 = copy_to_mode_reg (mode1, op1);
6330
6331 pat = GEN_FCN (icode) (target, op0, op1);
6332 if (! pat)
6333 return 0;
6334 emit_insn (pat);
6335
6336 return target;
6337}
6525c0e7 6338
ae4b4a02 6339static rtx
f676971a 6340altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
a2369ed3 6341 tree arglist, rtx target)
ae4b4a02
AH
6342{
6343 rtx pat, scratch;
6344 tree cr6_form = TREE_VALUE (arglist);
6345 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6346 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6347 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6348 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6349 enum machine_mode tmode = SImode;
6350 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6351 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6352 int cr6_form_int;
6353
6354 if (TREE_CODE (cr6_form) != INTEGER_CST)
6355 {
6356 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 6357 return const0_rtx;
ae4b4a02
AH
6358 }
6359 else
6360 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
6361
6362 if (mode0 != mode1)
6363 abort ();
6364
6365 /* If we have invalid arguments, bail out before generating bad rtl. */
6366 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6367 return const0_rtx;
ae4b4a02
AH
6368
6369 if (target == 0
6370 || GET_MODE (target) != tmode
6371 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6372 target = gen_reg_rtx (tmode);
6373
6374 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6375 op0 = copy_to_mode_reg (mode0, op0);
6376 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6377 op1 = copy_to_mode_reg (mode1, op1);
6378
6379 scratch = gen_reg_rtx (mode0);
6380
6381 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 6382 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
6383 if (! pat)
6384 return 0;
6385 emit_insn (pat);
6386
6387 /* The vec_any* and vec_all* predicates use the same opcodes for two
6388 different operations, but the bits in CR6 will be different
6389 depending on what information we want. So we have to play tricks
6390 with CR6 to get the right bits out.
6391
6392 If you think this is disgusting, look at the specs for the
6393 AltiVec predicates. */
6394
c4ad648e
AM
6395 switch (cr6_form_int)
6396 {
6397 case 0:
6398 emit_insn (gen_cr6_test_for_zero (target));
6399 break;
6400 case 1:
6401 emit_insn (gen_cr6_test_for_zero_reverse (target));
6402 break;
6403 case 2:
6404 emit_insn (gen_cr6_test_for_lt (target));
6405 break;
6406 case 3:
6407 emit_insn (gen_cr6_test_for_lt_reverse (target));
6408 break;
6409 default:
6410 error ("argument 1 of __builtin_altivec_predicate is out of range");
6411 break;
6412 }
ae4b4a02
AH
6413
6414 return target;
6415}
6416
b4a62fa0 6417static rtx
38f391a5 6418altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
6419{
6420 rtx pat, addr;
6421 tree arg0 = TREE_VALUE (arglist);
6422 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6423 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6424 enum machine_mode mode0 = Pmode;
6425 enum machine_mode mode1 = Pmode;
6426 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6427 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6428
6429 if (icode == CODE_FOR_nothing)
6430 /* Builtin not supported on this processor. */
6431 return 0;
6432
6433 /* If we got invalid arguments bail out before generating bad rtl. */
6434 if (arg0 == error_mark_node || arg1 == error_mark_node)
6435 return const0_rtx;
6436
6437 if (target == 0
6438 || GET_MODE (target) != tmode
6439 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6440 target = gen_reg_rtx (tmode);
6441
f676971a 6442 op1 = copy_to_mode_reg (mode1, op1);
b4a62fa0
SB
6443
6444 if (op0 == const0_rtx)
6445 {
6446 addr = gen_rtx_MEM (tmode, op1);
6447 }
6448 else
6449 {
6450 op0 = copy_to_mode_reg (mode0, op0);
6451 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
6452 }
6453
6454 pat = GEN_FCN (icode) (target, addr);
6455
6456 if (! pat)
6457 return 0;
6458 emit_insn (pat);
6459
6460 return target;
6461}
6462
61bea3b0
AH
6463static rtx
6464spe_expand_stv_builtin (enum insn_code icode, tree arglist)
6465{
6466 tree arg0 = TREE_VALUE (arglist);
6467 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6468 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6469 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6470 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6471 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6472 rtx pat;
6473 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
6474 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
6475 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
6476
6477 /* Invalid arguments. Bail before doing anything stoopid! */
6478 if (arg0 == error_mark_node
6479 || arg1 == error_mark_node
6480 || arg2 == error_mark_node)
6481 return const0_rtx;
6482
6483 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
6484 op0 = copy_to_mode_reg (mode2, op0);
6485 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
6486 op1 = copy_to_mode_reg (mode0, op1);
6487 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6488 op2 = copy_to_mode_reg (mode1, op2);
6489
6490 pat = GEN_FCN (icode) (op1, op2, op0);
6491 if (pat)
6492 emit_insn (pat);
6493 return NULL_RTX;
6494}
6495
6525c0e7 6496static rtx
a2369ed3 6497altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
6498{
6499 tree arg0 = TREE_VALUE (arglist);
6500 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6501 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6502 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6503 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6504 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
6505 rtx pat, addr;
6506 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6507 enum machine_mode mode1 = Pmode;
6508 enum machine_mode mode2 = Pmode;
6525c0e7
AH
6509
6510 /* Invalid arguments. Bail before doing anything stoopid! */
6511 if (arg0 == error_mark_node
6512 || arg1 == error_mark_node
6513 || arg2 == error_mark_node)
9a171fcd 6514 return const0_rtx;
6525c0e7 6515
b4a62fa0
SB
6516 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
6517 op0 = copy_to_mode_reg (tmode, op0);
6518
f676971a 6519 op2 = copy_to_mode_reg (mode2, op2);
b4a62fa0
SB
6520
6521 if (op1 == const0_rtx)
6522 {
6523 addr = gen_rtx_MEM (tmode, op2);
6524 }
6525 else
6526 {
6527 op1 = copy_to_mode_reg (mode1, op1);
6528 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
6529 }
6525c0e7 6530
b4a62fa0 6531 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
6532 if (pat)
6533 emit_insn (pat);
6534 return NULL_RTX;
6535}
6536
2212663f 6537static rtx
a2369ed3 6538rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6539{
6540 rtx pat;
6541 tree arg0 = TREE_VALUE (arglist);
6542 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6543 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6544 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6545 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6546 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6547 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6548 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6549 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6550 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 6551
774b5662
DE
6552 if (icode == CODE_FOR_nothing)
6553 /* Builtin not supported on this processor. */
6554 return 0;
6555
20e26713
AH
6556 /* If we got invalid arguments bail out before generating bad rtl. */
6557 if (arg0 == error_mark_node
6558 || arg1 == error_mark_node
6559 || arg2 == error_mark_node)
9a171fcd 6560 return const0_rtx;
20e26713 6561
774b5662
DE
6562 if (icode == CODE_FOR_altivec_vsldoi_4sf
6563 || icode == CODE_FOR_altivec_vsldoi_4si
6564 || icode == CODE_FOR_altivec_vsldoi_8hi
6565 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
6566 {
6567 /* Only allow 4-bit unsigned literals. */
8bb418a3 6568 STRIP_NOPS (arg2);
b44140e7
AH
6569 if (TREE_CODE (arg2) != INTEGER_CST
6570 || TREE_INT_CST_LOW (arg2) & ~0xf)
6571 {
6572 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 6573 return const0_rtx;
b44140e7 6574 }
b44140e7
AH
6575 }
6576
c62f2db5 6577 if (target == 0
2212663f
DB
6578 || GET_MODE (target) != tmode
6579 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6580 target = gen_reg_rtx (tmode);
6581
6582 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6583 op0 = copy_to_mode_reg (mode0, op0);
6584 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6585 op1 = copy_to_mode_reg (mode1, op1);
6586 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
6587 op2 = copy_to_mode_reg (mode2, op2);
6588
6589 pat = GEN_FCN (icode) (target, op0, op1, op2);
6590 if (! pat)
6591 return 0;
6592 emit_insn (pat);
6593
6594 return target;
6595}
92898235 6596
3a9b8c7e 6597/* Expand the lvx builtins. */
0ac081f6 6598static rtx
a2369ed3 6599altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 6600{
0ac081f6
AH
6601 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6602 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 6603 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
6604 tree arg0;
6605 enum machine_mode tmode, mode0;
7c3abc73 6606 rtx pat, op0;
3a9b8c7e 6607 enum insn_code icode;
92898235 6608
0ac081f6
AH
6609 switch (fcode)
6610 {
f18c054f
DB
6611 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
6612 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 6613 break;
f18c054f
DB
6614 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
6615 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
6616 break;
6617 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
6618 icode = CODE_FOR_altivec_lvx_4si;
6619 break;
6620 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
6621 icode = CODE_FOR_altivec_lvx_4sf;
6622 break;
6623 default:
6624 *expandedp = false;
6625 return NULL_RTX;
6626 }
0ac081f6 6627
3a9b8c7e 6628 *expandedp = true;
f18c054f 6629
3a9b8c7e
AH
6630 arg0 = TREE_VALUE (arglist);
6631 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6632 tmode = insn_data[icode].operand[0].mode;
6633 mode0 = insn_data[icode].operand[1].mode;
f18c054f 6634
3a9b8c7e
AH
6635 if (target == 0
6636 || GET_MODE (target) != tmode
6637 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6638 target = gen_reg_rtx (tmode);
24408032 6639
3a9b8c7e
AH
6640 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6641 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 6642
3a9b8c7e
AH
6643 pat = GEN_FCN (icode) (target, op0);
6644 if (! pat)
6645 return 0;
6646 emit_insn (pat);
6647 return target;
6648}
f18c054f 6649
3a9b8c7e
AH
6650/* Expand the stvx builtins. */
6651static rtx
f676971a 6652altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 6653 bool *expandedp)
3a9b8c7e
AH
6654{
6655 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6656 tree arglist = TREE_OPERAND (exp, 1);
6657 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6658 tree arg0, arg1;
6659 enum machine_mode mode0, mode1;
7c3abc73 6660 rtx pat, op0, op1;
3a9b8c7e 6661 enum insn_code icode;
f18c054f 6662
3a9b8c7e
AH
6663 switch (fcode)
6664 {
6665 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
6666 icode = CODE_FOR_altivec_stvx_16qi;
6667 break;
6668 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
6669 icode = CODE_FOR_altivec_stvx_8hi;
6670 break;
6671 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
6672 icode = CODE_FOR_altivec_stvx_4si;
6673 break;
6674 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
6675 icode = CODE_FOR_altivec_stvx_4sf;
6676 break;
6677 default:
6678 *expandedp = false;
6679 return NULL_RTX;
6680 }
24408032 6681
3a9b8c7e
AH
6682 arg0 = TREE_VALUE (arglist);
6683 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6684 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6685 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6686 mode0 = insn_data[icode].operand[0].mode;
6687 mode1 = insn_data[icode].operand[1].mode;
f18c054f 6688
3a9b8c7e
AH
6689 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6690 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
6691 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6692 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 6693
3a9b8c7e
AH
6694 pat = GEN_FCN (icode) (op0, op1);
6695 if (pat)
6696 emit_insn (pat);
f18c054f 6697
3a9b8c7e
AH
6698 *expandedp = true;
6699 return NULL_RTX;
6700}
f18c054f 6701
3a9b8c7e
AH
6702/* Expand the dst builtins. */
6703static rtx
f676971a 6704altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 6705 bool *expandedp)
3a9b8c7e
AH
6706{
6707 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6708 tree arglist = TREE_OPERAND (exp, 1);
6709 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6710 tree arg0, arg1, arg2;
6711 enum machine_mode mode0, mode1, mode2;
7c3abc73 6712 rtx pat, op0, op1, op2;
3a9b8c7e 6713 struct builtin_description *d;
a3170dc6 6714 size_t i;
f18c054f 6715
3a9b8c7e 6716 *expandedp = false;
f18c054f 6717
3a9b8c7e
AH
6718 /* Handle DST variants. */
6719 d = (struct builtin_description *) bdesc_dst;
6720 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
6721 if (d->code == fcode)
6722 {
6723 arg0 = TREE_VALUE (arglist);
6724 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6725 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6726 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6727 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6728 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6729 mode0 = insn_data[d->icode].operand[0].mode;
6730 mode1 = insn_data[d->icode].operand[1].mode;
6731 mode2 = insn_data[d->icode].operand[2].mode;
24408032 6732
3a9b8c7e
AH
6733 /* Invalid arguments, bail out before generating bad rtl. */
6734 if (arg0 == error_mark_node
6735 || arg1 == error_mark_node
6736 || arg2 == error_mark_node)
6737 return const0_rtx;
f18c054f 6738
86e7df90 6739 *expandedp = true;
8bb418a3 6740 STRIP_NOPS (arg2);
3a9b8c7e
AH
6741 if (TREE_CODE (arg2) != INTEGER_CST
6742 || TREE_INT_CST_LOW (arg2) & ~0x3)
6743 {
6744 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
6745 return const0_rtx;
6746 }
f18c054f 6747
3a9b8c7e 6748 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 6749 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
6750 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
6751 op1 = copy_to_mode_reg (mode1, op1);
24408032 6752
3a9b8c7e
AH
6753 pat = GEN_FCN (d->icode) (op0, op1, op2);
6754 if (pat != 0)
6755 emit_insn (pat);
f18c054f 6756
3a9b8c7e
AH
6757 return NULL_RTX;
6758 }
f18c054f 6759
3a9b8c7e
AH
6760 return NULL_RTX;
6761}
24408032 6762
3a9b8c7e
AH
6763/* Expand the builtin in EXP and store the result in TARGET. Store
6764 true in *EXPANDEDP if we found a builtin to expand. */
6765static rtx
a2369ed3 6766altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
6767{
6768 struct builtin_description *d;
6769 struct builtin_description_predicates *dp;
6770 size_t i;
6771 enum insn_code icode;
6772 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6773 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
6774 tree arg0;
6775 rtx op0, pat;
6776 enum machine_mode tmode, mode0;
3a9b8c7e 6777 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 6778
3a9b8c7e
AH
6779 target = altivec_expand_ld_builtin (exp, target, expandedp);
6780 if (*expandedp)
6781 return target;
0ac081f6 6782
3a9b8c7e
AH
6783 target = altivec_expand_st_builtin (exp, target, expandedp);
6784 if (*expandedp)
6785 return target;
6786
6787 target = altivec_expand_dst_builtin (exp, target, expandedp);
6788 if (*expandedp)
6789 return target;
6790
6791 *expandedp = true;
95385cbb 6792
3a9b8c7e
AH
6793 switch (fcode)
6794 {
6525c0e7
AH
6795 case ALTIVEC_BUILTIN_STVX:
6796 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
6797 case ALTIVEC_BUILTIN_STVEBX:
6798 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
6799 case ALTIVEC_BUILTIN_STVEHX:
6800 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
6801 case ALTIVEC_BUILTIN_STVEWX:
6802 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
6803 case ALTIVEC_BUILTIN_STVXL:
6804 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 6805
95385cbb
AH
6806 case ALTIVEC_BUILTIN_MFVSCR:
6807 icode = CODE_FOR_altivec_mfvscr;
6808 tmode = insn_data[icode].operand[0].mode;
6809
6810 if (target == 0
6811 || GET_MODE (target) != tmode
6812 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6813 target = gen_reg_rtx (tmode);
f676971a 6814
95385cbb 6815 pat = GEN_FCN (icode) (target);
0ac081f6
AH
6816 if (! pat)
6817 return 0;
6818 emit_insn (pat);
95385cbb
AH
6819 return target;
6820
6821 case ALTIVEC_BUILTIN_MTVSCR:
6822 icode = CODE_FOR_altivec_mtvscr;
6823 arg0 = TREE_VALUE (arglist);
6824 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6825 mode0 = insn_data[icode].operand[0].mode;
6826
6827 /* If we got invalid arguments bail out before generating bad rtl. */
6828 if (arg0 == error_mark_node)
9a171fcd 6829 return const0_rtx;
95385cbb
AH
6830
6831 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6832 op0 = copy_to_mode_reg (mode0, op0);
6833
6834 pat = GEN_FCN (icode) (op0);
6835 if (pat)
6836 emit_insn (pat);
6837 return NULL_RTX;
3a9b8c7e 6838
95385cbb
AH
6839 case ALTIVEC_BUILTIN_DSSALL:
6840 emit_insn (gen_altivec_dssall ());
6841 return NULL_RTX;
6842
6843 case ALTIVEC_BUILTIN_DSS:
6844 icode = CODE_FOR_altivec_dss;
6845 arg0 = TREE_VALUE (arglist);
8bb418a3 6846 STRIP_NOPS (arg0);
95385cbb
AH
6847 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6848 mode0 = insn_data[icode].operand[0].mode;
6849
6850 /* If we got invalid arguments bail out before generating bad rtl. */
6851 if (arg0 == error_mark_node)
9a171fcd 6852 return const0_rtx;
95385cbb 6853
b44140e7
AH
6854 if (TREE_CODE (arg0) != INTEGER_CST
6855 || TREE_INT_CST_LOW (arg0) & ~0x3)
6856 {
6857 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6858 return const0_rtx;
b44140e7
AH
6859 }
6860
95385cbb
AH
6861 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6862 op0 = copy_to_mode_reg (mode0, op0);
6863
6864 emit_insn (gen_altivec_dss (op0));
0ac081f6 6865 return NULL_RTX;
f676971a 6866
8bb418a3
ZL
6867 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
6868 arg0 = TREE_VALUE (arglist);
97dc04b3 6869 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR
c4ad648e 6870 || TREE_CODE (arg0) == ARRAY_REF)
8bb418a3
ZL
6871 arg0 = TREE_OPERAND (arg0, 0);
6872 error ("invalid parameter combination for `%s' AltiVec intrinsic",
6873 TREE_STRING_POINTER (arg0));
6874
6875 return const0_rtx;
0ac081f6 6876 }
24408032 6877
100c4561
AH
6878 /* Expand abs* operations. */
6879 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6880 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6881 if (d->code == fcode)
6882 return altivec_expand_abs_builtin (d->icode, arglist, target);
6883
ae4b4a02
AH
6884 /* Expand the AltiVec predicates. */
6885 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6886 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02 6887 if (dp->code == fcode)
c4ad648e
AM
6888 return altivec_expand_predicate_builtin (dp->icode, dp->opcode,
6889 arglist, target);
ae4b4a02 6890
6525c0e7
AH
6891 /* LV* are funky. We initialized them differently. */
6892 switch (fcode)
6893 {
6894 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6895 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
c4ad648e 6896 arglist, target);
6525c0e7 6897 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6898 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
c4ad648e 6899 arglist, target);
6525c0e7 6900 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6901 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
c4ad648e 6902 arglist, target);
6525c0e7 6903 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6904 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
c4ad648e 6905 arglist, target);
6525c0e7 6906 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6907 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
c4ad648e 6908 arglist, target);
6525c0e7 6909 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6910 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
c4ad648e 6911 arglist, target);
6525c0e7 6912 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6913 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
c4ad648e 6914 arglist, target);
6525c0e7
AH
6915 default:
6916 break;
6917 /* Fall through. */
6918 }
95385cbb 6919
92898235 6920 *expandedp = false;
0ac081f6
AH
6921 return NULL_RTX;
6922}
6923
a3170dc6
AH
6924/* Binops that need to be initialized manually, but can be expanded
6925 automagically by rs6000_expand_binop_builtin. */
6926static struct builtin_description bdesc_2arg_spe[] =
6927{
6928 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6929 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6930 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6931 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6932 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6933 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6934 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6935 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6936 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6937 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6938 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6939 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6940 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6941 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6942 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6943 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6944 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6945 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6946 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6947 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6948 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6949 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6950};
6951
6952/* Expand the builtin in EXP and store the result in TARGET. Store
6953 true in *EXPANDEDP if we found a builtin to expand.
6954
6955 This expands the SPE builtins that are not simple unary and binary
6956 operations. */
6957static rtx
a2369ed3 6958spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6959{
6960 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6961 tree arglist = TREE_OPERAND (exp, 1);
6962 tree arg1, arg0;
6963 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6964 enum insn_code icode;
6965 enum machine_mode tmode, mode0;
6966 rtx pat, op0;
6967 struct builtin_description *d;
6968 size_t i;
6969
6970 *expandedp = true;
6971
6972 /* Syntax check for a 5-bit unsigned immediate. */
6973 switch (fcode)
6974 {
6975 case SPE_BUILTIN_EVSTDD:
6976 case SPE_BUILTIN_EVSTDH:
6977 case SPE_BUILTIN_EVSTDW:
6978 case SPE_BUILTIN_EVSTWHE:
6979 case SPE_BUILTIN_EVSTWHO:
6980 case SPE_BUILTIN_EVSTWWE:
6981 case SPE_BUILTIN_EVSTWWO:
6982 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6983 if (TREE_CODE (arg1) != INTEGER_CST
6984 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6985 {
6986 error ("argument 2 must be a 5-bit unsigned literal");
6987 return const0_rtx;
6988 }
6989 break;
6990 default:
6991 break;
6992 }
6993
00332c9f
AH
6994 /* The evsplat*i instructions are not quite generic. */
6995 switch (fcode)
6996 {
6997 case SPE_BUILTIN_EVSPLATFI:
6998 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6999 arglist, target);
7000 case SPE_BUILTIN_EVSPLATI:
7001 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
7002 arglist, target);
7003 default:
7004 break;
7005 }
7006
a3170dc6
AH
7007 d = (struct builtin_description *) bdesc_2arg_spe;
7008 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
7009 if (d->code == fcode)
7010 return rs6000_expand_binop_builtin (d->icode, arglist, target);
7011
7012 d = (struct builtin_description *) bdesc_spe_predicates;
7013 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
7014 if (d->code == fcode)
7015 return spe_expand_predicate_builtin (d->icode, arglist, target);
7016
7017 d = (struct builtin_description *) bdesc_spe_evsel;
7018 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
7019 if (d->code == fcode)
7020 return spe_expand_evsel_builtin (d->icode, arglist, target);
7021
7022 switch (fcode)
7023 {
7024 case SPE_BUILTIN_EVSTDDX:
61bea3b0 7025 return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
a3170dc6 7026 case SPE_BUILTIN_EVSTDHX:
61bea3b0 7027 return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
a3170dc6 7028 case SPE_BUILTIN_EVSTDWX:
61bea3b0 7029 return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
a3170dc6 7030 case SPE_BUILTIN_EVSTWHEX:
61bea3b0 7031 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
a3170dc6 7032 case SPE_BUILTIN_EVSTWHOX:
61bea3b0 7033 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
a3170dc6 7034 case SPE_BUILTIN_EVSTWWEX:
61bea3b0 7035 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
a3170dc6 7036 case SPE_BUILTIN_EVSTWWOX:
61bea3b0 7037 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
a3170dc6 7038 case SPE_BUILTIN_EVSTDD:
61bea3b0 7039 return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
a3170dc6 7040 case SPE_BUILTIN_EVSTDH:
61bea3b0 7041 return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
a3170dc6 7042 case SPE_BUILTIN_EVSTDW:
61bea3b0 7043 return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
a3170dc6 7044 case SPE_BUILTIN_EVSTWHE:
61bea3b0 7045 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
a3170dc6 7046 case SPE_BUILTIN_EVSTWHO:
61bea3b0 7047 return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
a3170dc6 7048 case SPE_BUILTIN_EVSTWWE:
61bea3b0 7049 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
a3170dc6 7050 case SPE_BUILTIN_EVSTWWO:
61bea3b0 7051 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
a3170dc6
AH
7052 case SPE_BUILTIN_MFSPEFSCR:
7053 icode = CODE_FOR_spe_mfspefscr;
7054 tmode = insn_data[icode].operand[0].mode;
7055
7056 if (target == 0
7057 || GET_MODE (target) != tmode
7058 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7059 target = gen_reg_rtx (tmode);
f676971a 7060
a3170dc6
AH
7061 pat = GEN_FCN (icode) (target);
7062 if (! pat)
7063 return 0;
7064 emit_insn (pat);
7065 return target;
7066 case SPE_BUILTIN_MTSPEFSCR:
7067 icode = CODE_FOR_spe_mtspefscr;
7068 arg0 = TREE_VALUE (arglist);
7069 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7070 mode0 = insn_data[icode].operand[0].mode;
7071
7072 if (arg0 == error_mark_node)
7073 return const0_rtx;
7074
7075 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
7076 op0 = copy_to_mode_reg (mode0, op0);
7077
7078 pat = GEN_FCN (icode) (op0);
7079 if (pat)
7080 emit_insn (pat);
7081 return NULL_RTX;
7082 default:
7083 break;
7084 }
7085
7086 *expandedp = false;
7087 return NULL_RTX;
7088}
7089
7090static rtx
a2369ed3 7091spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7092{
7093 rtx pat, scratch, tmp;
7094 tree form = TREE_VALUE (arglist);
7095 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
7096 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7097 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7098 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7099 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7100 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7101 int form_int;
7102 enum rtx_code code;
7103
7104 if (TREE_CODE (form) != INTEGER_CST)
7105 {
7106 error ("argument 1 of __builtin_spe_predicate must be a constant");
7107 return const0_rtx;
7108 }
7109 else
7110 form_int = TREE_INT_CST_LOW (form);
7111
7112 if (mode0 != mode1)
7113 abort ();
7114
7115 if (arg0 == error_mark_node || arg1 == error_mark_node)
7116 return const0_rtx;
7117
7118 if (target == 0
7119 || GET_MODE (target) != SImode
7120 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
7121 target = gen_reg_rtx (SImode);
7122
7123 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7124 op0 = copy_to_mode_reg (mode0, op0);
7125 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
7126 op1 = copy_to_mode_reg (mode1, op1);
7127
7128 scratch = gen_reg_rtx (CCmode);
7129
7130 pat = GEN_FCN (icode) (scratch, op0, op1);
7131 if (! pat)
7132 return const0_rtx;
7133 emit_insn (pat);
7134
7135 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
7136 _lower_. We use one compare, but look in different bits of the
7137 CR for each variant.
7138
7139 There are 2 elements in each SPE simd type (upper/lower). The CR
7140 bits are set as follows:
7141
7142 BIT0 | BIT 1 | BIT 2 | BIT 3
7143 U | L | (U | L) | (U & L)
7144
7145 So, for an "all" relationship, BIT 3 would be set.
7146 For an "any" relationship, BIT 2 would be set. Etc.
7147
7148 Following traditional nomenclature, these bits map to:
7149
7150 BIT0 | BIT 1 | BIT 2 | BIT 3
7151 LT | GT | EQ | OV
7152
7153 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
7154 */
7155
7156 switch (form_int)
7157 {
7158 /* All variant. OV bit. */
7159 case 0:
7160 /* We need to get to the OV bit, which is the ORDERED bit. We
7161 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
7162 that's ugly and will trigger a validate_condition_mode abort.
7163 So let's just use another pattern. */
7164 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
7165 return target;
7166 /* Any variant. EQ bit. */
7167 case 1:
7168 code = EQ;
7169 break;
7170 /* Upper variant. LT bit. */
7171 case 2:
7172 code = LT;
7173 break;
7174 /* Lower variant. GT bit. */
7175 case 3:
7176 code = GT;
7177 break;
7178 default:
7179 error ("argument 1 of __builtin_spe_predicate is out of range");
7180 return const0_rtx;
7181 }
7182
7183 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
7184 emit_move_insn (target, tmp);
7185
7186 return target;
7187}
7188
7189/* The evsel builtins look like this:
7190
7191 e = __builtin_spe_evsel_OP (a, b, c, d);
7192
7193 and work like this:
7194
7195 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
7196 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
7197*/
7198
7199static rtx
a2369ed3 7200spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7201{
7202 rtx pat, scratch;
7203 tree arg0 = TREE_VALUE (arglist);
7204 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
7205 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7206 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
7207 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7208 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7209 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
7210 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
7211 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7212 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7213
7214 if (mode0 != mode1)
7215 abort ();
7216
7217 if (arg0 == error_mark_node || arg1 == error_mark_node
7218 || arg2 == error_mark_node || arg3 == error_mark_node)
7219 return const0_rtx;
7220
7221 if (target == 0
7222 || GET_MODE (target) != mode0
7223 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
7224 target = gen_reg_rtx (mode0);
7225
7226 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7227 op0 = copy_to_mode_reg (mode0, op0);
7228 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
7229 op1 = copy_to_mode_reg (mode0, op1);
7230 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
7231 op2 = copy_to_mode_reg (mode0, op2);
7232 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
7233 op3 = copy_to_mode_reg (mode0, op3);
7234
7235 /* Generate the compare. */
7236 scratch = gen_reg_rtx (CCmode);
7237 pat = GEN_FCN (icode) (scratch, op0, op1);
7238 if (! pat)
7239 return const0_rtx;
7240 emit_insn (pat);
7241
7242 if (mode0 == V2SImode)
7243 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
7244 else
7245 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
7246
7247 return target;
7248}
7249
0ac081f6
AH
7250/* Expand an expression EXP that calls a built-in function,
7251 with result going to TARGET if that's convenient
7252 (and in mode MODE if that's convenient).
7253 SUBTARGET may be used as the target for computing one of EXP's operands.
7254 IGNORE is nonzero if the value is to be ignored. */
7255
7256static rtx
a2369ed3 7257rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
c4ad648e
AM
7258 enum machine_mode mode ATTRIBUTE_UNUSED,
7259 int ignore ATTRIBUTE_UNUSED)
0ac081f6 7260{
92898235
AH
7261 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7262 tree arglist = TREE_OPERAND (exp, 1);
7263 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
7264 struct builtin_description *d;
7265 size_t i;
7266 rtx ret;
7267 bool success;
f676971a 7268
7ccf35ed
DN
7269 if (fcode == ALTIVEC_BUILTIN_MASK_FOR_LOAD
7270 || fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE)
7271 {
7272 int icode = (int) CODE_FOR_altivec_lvsr;
7273 enum machine_mode tmode = insn_data[icode].operand[0].mode;
7274 enum machine_mode mode = insn_data[icode].operand[1].mode;
7275 tree arg;
7276 rtx op, addr, pat;
7277
7278 if (!TARGET_ALTIVEC)
7279 abort ();
7280
7281 arg = TREE_VALUE (arglist);
7282 if (TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE)
7283 abort ();
7284 op = expand_expr (arg, NULL_RTX, Pmode, EXPAND_NORMAL);
7285 addr = memory_address (mode, op);
7286 if (fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE)
7287 op = addr;
7288 else
7289 {
7290 /* For the load case need to negate the address. */
7291 op = gen_reg_rtx (GET_MODE (addr));
7292 emit_insn (gen_rtx_SET (VOIDmode, op,
7293 gen_rtx_NEG (GET_MODE (addr), addr)));
c4ad648e 7294 }
7ccf35ed
DN
7295 op = gen_rtx_MEM (mode, op);
7296
7297 if (target == 0
7298 || GET_MODE (target) != tmode
7299 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7300 target = gen_reg_rtx (tmode);
7301
7302 /*pat = gen_altivec_lvsr (target, op);*/
7303 pat = GEN_FCN (icode) (target, op);
7304 if (!pat)
7305 return 0;
7306 emit_insn (pat);
7307
7308 return target;
7309 }
7310
0ac081f6 7311 if (TARGET_ALTIVEC)
92898235
AH
7312 {
7313 ret = altivec_expand_builtin (exp, target, &success);
7314
a3170dc6
AH
7315 if (success)
7316 return ret;
7317 }
7318 if (TARGET_SPE)
7319 {
7320 ret = spe_expand_builtin (exp, target, &success);
7321
92898235
AH
7322 if (success)
7323 return ret;
7324 }
7325
0559cc77
DE
7326 if (TARGET_ALTIVEC || TARGET_SPE)
7327 {
7328 /* Handle simple unary operations. */
7329 d = (struct builtin_description *) bdesc_1arg;
7330 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
7331 if (d->code == fcode)
7332 return rs6000_expand_unop_builtin (d->icode, arglist, target);
7333
7334 /* Handle simple binary operations. */
7335 d = (struct builtin_description *) bdesc_2arg;
7336 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
7337 if (d->code == fcode)
7338 return rs6000_expand_binop_builtin (d->icode, arglist, target);
7339
7340 /* Handle simple ternary operations. */
7341 d = (struct builtin_description *) bdesc_3arg;
7342 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
7343 if (d->code == fcode)
7344 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
7345 }
0ac081f6
AH
7346
7347 abort ();
92898235 7348 return NULL_RTX;
0ac081f6
AH
7349}
7350
7c62e993
PB
7351static tree
7352build_opaque_vector_type (tree node, int nunits)
7353{
7354 node = copy_node (node);
7355 TYPE_MAIN_VARIANT (node) = node;
7356 return build_vector_type (node, nunits);
7357}
7358
0ac081f6 7359static void
863d938c 7360rs6000_init_builtins (void)
0ac081f6 7361{
4a5eab38
PB
7362 V2SI_type_node = build_vector_type (intSI_type_node, 2);
7363 V2SF_type_node = build_vector_type (float_type_node, 2);
7364 V4HI_type_node = build_vector_type (intHI_type_node, 4);
7365 V4SI_type_node = build_vector_type (intSI_type_node, 4);
7366 V4SF_type_node = build_vector_type (float_type_node, 4);
7e463bda 7367 V8HI_type_node = build_vector_type (intHI_type_node, 8);
4a5eab38
PB
7368 V16QI_type_node = build_vector_type (intQI_type_node, 16);
7369
7370 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
7371 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
7372 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
7373
7c62e993
PB
7374 opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2);
7375 opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2);
6035d635 7376 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 7377
8bb418a3
ZL
7378 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
7379 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
7380 'vector unsigned short'. */
7381
8dd16ecc
NS
7382 bool_char_type_node = build_distinct_type_copy (unsigned_intQI_type_node);
7383 bool_short_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
7384 bool_int_type_node = build_distinct_type_copy (unsigned_intSI_type_node);
7385 pixel_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
8bb418a3
ZL
7386
7387 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7388 get_identifier ("__bool char"),
7389 bool_char_type_node));
7390 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7391 get_identifier ("__bool short"),
7392 bool_short_type_node));
7393 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7394 get_identifier ("__bool int"),
7395 bool_int_type_node));
7396 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7397 get_identifier ("__pixel"),
7398 pixel_type_node));
7399
4a5eab38
PB
7400 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
7401 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
7402 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
7403 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
8bb418a3
ZL
7404
7405 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7406 get_identifier ("__vector unsigned char"),
7407 unsigned_V16QI_type_node));
7408 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7409 get_identifier ("__vector signed char"),
7410 V16QI_type_node));
7411 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7412 get_identifier ("__vector __bool char"),
7413 bool_V16QI_type_node));
7414
7415 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7416 get_identifier ("__vector unsigned short"),
7417 unsigned_V8HI_type_node));
7418 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7419 get_identifier ("__vector signed short"),
7420 V8HI_type_node));
7421 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7422 get_identifier ("__vector __bool short"),
7423 bool_V8HI_type_node));
7424
7425 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7426 get_identifier ("__vector unsigned int"),
7427 unsigned_V4SI_type_node));
7428 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7429 get_identifier ("__vector signed int"),
7430 V4SI_type_node));
7431 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7432 get_identifier ("__vector __bool int"),
7433 bool_V4SI_type_node));
7434
7435 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7436 get_identifier ("__vector float"),
7437 V4SF_type_node));
7438 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7439 get_identifier ("__vector __pixel"),
7440 pixel_V8HI_type_node));
7441
a3170dc6 7442 if (TARGET_SPE)
3fdaa45a 7443 spe_init_builtins ();
0ac081f6
AH
7444 if (TARGET_ALTIVEC)
7445 altivec_init_builtins ();
0559cc77
DE
7446 if (TARGET_ALTIVEC || TARGET_SPE)
7447 rs6000_common_init_builtins ();
0ac081f6
AH
7448}
7449
a3170dc6
AH
7450/* Search through a set of builtins and enable the mask bits.
7451 DESC is an array of builtins.
b6d08ca1 7452 SIZE is the total number of builtins.
a3170dc6
AH
7453 START is the builtin enum at which to start.
7454 END is the builtin enum at which to end. */
0ac081f6 7455static void
a2369ed3 7456enable_mask_for_builtins (struct builtin_description *desc, int size,
f676971a 7457 enum rs6000_builtins start,
a2369ed3 7458 enum rs6000_builtins end)
a3170dc6
AH
7459{
7460 int i;
7461
7462 for (i = 0; i < size; ++i)
7463 if (desc[i].code == start)
7464 break;
7465
7466 if (i == size)
7467 return;
7468
7469 for (; i < size; ++i)
7470 {
7471 /* Flip all the bits on. */
7472 desc[i].mask = target_flags;
7473 if (desc[i].code == end)
7474 break;
7475 }
7476}
7477
7478static void
863d938c 7479spe_init_builtins (void)
0ac081f6 7480{
a3170dc6
AH
7481 tree endlink = void_list_node;
7482 tree puint_type_node = build_pointer_type (unsigned_type_node);
7483 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 7484 struct builtin_description *d;
0ac081f6
AH
7485 size_t i;
7486
a3170dc6
AH
7487 tree v2si_ftype_4_v2si
7488 = build_function_type
3fdaa45a
AH
7489 (opaque_V2SI_type_node,
7490 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7491 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7492 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7493 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7494 endlink)))));
7495
7496 tree v2sf_ftype_4_v2sf
7497 = build_function_type
3fdaa45a
AH
7498 (opaque_V2SF_type_node,
7499 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7500 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7501 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7502 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7503 endlink)))));
7504
7505 tree int_ftype_int_v2si_v2si
7506 = build_function_type
7507 (integer_type_node,
7508 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7509 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7510 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7511 endlink))));
7512
7513 tree int_ftype_int_v2sf_v2sf
7514 = build_function_type
7515 (integer_type_node,
7516 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7517 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7518 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7519 endlink))));
7520
7521 tree void_ftype_v2si_puint_int
7522 = build_function_type (void_type_node,
3fdaa45a 7523 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7524 tree_cons (NULL_TREE, puint_type_node,
7525 tree_cons (NULL_TREE,
7526 integer_type_node,
7527 endlink))));
7528
7529 tree void_ftype_v2si_puint_char
7530 = build_function_type (void_type_node,
3fdaa45a 7531 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7532 tree_cons (NULL_TREE, puint_type_node,
7533 tree_cons (NULL_TREE,
7534 char_type_node,
7535 endlink))));
7536
7537 tree void_ftype_v2si_pv2si_int
7538 = build_function_type (void_type_node,
3fdaa45a 7539 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7540 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7541 tree_cons (NULL_TREE,
7542 integer_type_node,
7543 endlink))));
7544
7545 tree void_ftype_v2si_pv2si_char
7546 = build_function_type (void_type_node,
3fdaa45a 7547 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7548 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7549 tree_cons (NULL_TREE,
7550 char_type_node,
7551 endlink))));
7552
7553 tree void_ftype_int
7554 = build_function_type (void_type_node,
7555 tree_cons (NULL_TREE, integer_type_node, endlink));
7556
7557 tree int_ftype_void
36e8d515 7558 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
7559
7560 tree v2si_ftype_pv2si_int
3fdaa45a 7561 = build_function_type (opaque_V2SI_type_node,
6035d635 7562 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7563 tree_cons (NULL_TREE, integer_type_node,
7564 endlink)));
7565
7566 tree v2si_ftype_puint_int
3fdaa45a 7567 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7568 tree_cons (NULL_TREE, puint_type_node,
7569 tree_cons (NULL_TREE, integer_type_node,
7570 endlink)));
7571
7572 tree v2si_ftype_pushort_int
3fdaa45a 7573 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7574 tree_cons (NULL_TREE, pushort_type_node,
7575 tree_cons (NULL_TREE, integer_type_node,
7576 endlink)));
7577
00332c9f
AH
7578 tree v2si_ftype_signed_char
7579 = build_function_type (opaque_V2SI_type_node,
7580 tree_cons (NULL_TREE, signed_char_type_node,
7581 endlink));
7582
a3170dc6
AH
7583 /* The initialization of the simple binary and unary builtins is
7584 done in rs6000_common_init_builtins, but we have to enable the
7585 mask bits here manually because we have run out of `target_flags'
7586 bits. We really need to redesign this mask business. */
7587
7588 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
7589 ARRAY_SIZE (bdesc_2arg),
7590 SPE_BUILTIN_EVADDW,
7591 SPE_BUILTIN_EVXOR);
7592 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
7593 ARRAY_SIZE (bdesc_1arg),
7594 SPE_BUILTIN_EVABS,
7595 SPE_BUILTIN_EVSUBFUSIAAW);
7596 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
7597 ARRAY_SIZE (bdesc_spe_predicates),
7598 SPE_BUILTIN_EVCMPEQ,
7599 SPE_BUILTIN_EVFSTSTLT);
7600 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
7601 ARRAY_SIZE (bdesc_spe_evsel),
7602 SPE_BUILTIN_EVSEL_CMPGTS,
7603 SPE_BUILTIN_EVSEL_FSTSTEQ);
7604
36252949
AH
7605 (*lang_hooks.decls.pushdecl)
7606 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
7607 opaque_V2SI_type_node));
7608
a3170dc6 7609 /* Initialize irregular SPE builtins. */
f676971a 7610
a3170dc6
AH
7611 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
7612 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
7613 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
7614 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
7615 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
7616 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
7617 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
7618 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
7619 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
7620 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
7621 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
7622 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
7623 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
7624 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
7625 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
7626 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
7627 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
7628 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
7629
7630 /* Loads. */
7631 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
7632 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
7633 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
7634 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
7635 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
7636 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
7637 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
7638 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
7639 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
7640 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
7641 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
7642 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
7643 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
7644 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
7645 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
7646 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
7647 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
7648 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
7649 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
7650 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
7651 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
7652 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
7653
7654 /* Predicates. */
7655 d = (struct builtin_description *) bdesc_spe_predicates;
7656 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
7657 {
7658 tree type;
7659
7660 switch (insn_data[d->icode].operand[1].mode)
7661 {
7662 case V2SImode:
7663 type = int_ftype_int_v2si_v2si;
7664 break;
7665 case V2SFmode:
7666 type = int_ftype_int_v2sf_v2sf;
7667 break;
7668 default:
7669 abort ();
7670 }
7671
7672 def_builtin (d->mask, d->name, type, d->code);
7673 }
7674
7675 /* Evsel predicates. */
7676 d = (struct builtin_description *) bdesc_spe_evsel;
7677 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
7678 {
7679 tree type;
7680
7681 switch (insn_data[d->icode].operand[1].mode)
7682 {
7683 case V2SImode:
7684 type = v2si_ftype_4_v2si;
7685 break;
7686 case V2SFmode:
7687 type = v2sf_ftype_4_v2sf;
7688 break;
7689 default:
7690 abort ();
7691 }
7692
7693 def_builtin (d->mask, d->name, type, d->code);
7694 }
7695}
7696
7697static void
863d938c 7698altivec_init_builtins (void)
a3170dc6
AH
7699{
7700 struct builtin_description *d;
7701 struct builtin_description_predicates *dp;
7702 size_t i;
7703 tree pfloat_type_node = build_pointer_type (float_type_node);
7704 tree pint_type_node = build_pointer_type (integer_type_node);
7705 tree pshort_type_node = build_pointer_type (short_integer_type_node);
7706 tree pchar_type_node = build_pointer_type (char_type_node);
7707
7708 tree pvoid_type_node = build_pointer_type (void_type_node);
7709
0dbc3651
ZW
7710 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
7711 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
7712 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
7713 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
7714
7715 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
7716
a3170dc6
AH
7717 tree int_ftype_int_v4si_v4si
7718 = build_function_type_list (integer_type_node,
7719 integer_type_node, V4SI_type_node,
7720 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7721 tree v4sf_ftype_pcfloat
7722 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 7723 tree void_ftype_pfloat_v4sf
b4de2f7d 7724 = build_function_type_list (void_type_node,
a3170dc6 7725 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
7726 tree v4si_ftype_pcint
7727 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
7728 tree void_ftype_pint_v4si
b4de2f7d
AH
7729 = build_function_type_list (void_type_node,
7730 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7731 tree v8hi_ftype_pcshort
7732 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 7733 tree void_ftype_pshort_v8hi
b4de2f7d
AH
7734 = build_function_type_list (void_type_node,
7735 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
7736 tree v16qi_ftype_pcchar
7737 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 7738 tree void_ftype_pchar_v16qi
b4de2f7d
AH
7739 = build_function_type_list (void_type_node,
7740 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 7741 tree void_ftype_v4si
b4de2f7d 7742 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7743 tree v8hi_ftype_void
7744 = build_function_type (V8HI_type_node, void_list_node);
7745 tree void_ftype_void
7746 = build_function_type (void_type_node, void_list_node);
e34b6648
JJ
7747 tree void_ftype_int
7748 = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
0dbc3651 7749
b4a62fa0 7750 tree v16qi_ftype_long_pcvoid
a3170dc6 7751 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
7752 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7753 tree v8hi_ftype_long_pcvoid
a3170dc6 7754 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
7755 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7756 tree v4si_ftype_long_pcvoid
a3170dc6 7757 = build_function_type_list (V4SI_type_node,
b4a62fa0 7758 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 7759
b4a62fa0 7760 tree void_ftype_v4si_long_pvoid
b4de2f7d 7761 = build_function_type_list (void_type_node,
b4a62fa0 7762 V4SI_type_node, long_integer_type_node,
b4de2f7d 7763 pvoid_type_node, NULL_TREE);
b4a62fa0 7764 tree void_ftype_v16qi_long_pvoid
b4de2f7d 7765 = build_function_type_list (void_type_node,
b4a62fa0 7766 V16QI_type_node, long_integer_type_node,
b4de2f7d 7767 pvoid_type_node, NULL_TREE);
b4a62fa0 7768 tree void_ftype_v8hi_long_pvoid
b4de2f7d 7769 = build_function_type_list (void_type_node,
b4a62fa0 7770 V8HI_type_node, long_integer_type_node,
b4de2f7d 7771 pvoid_type_node, NULL_TREE);
a3170dc6
AH
7772 tree int_ftype_int_v8hi_v8hi
7773 = build_function_type_list (integer_type_node,
7774 integer_type_node, V8HI_type_node,
7775 V8HI_type_node, NULL_TREE);
7776 tree int_ftype_int_v16qi_v16qi
7777 = build_function_type_list (integer_type_node,
7778 integer_type_node, V16QI_type_node,
7779 V16QI_type_node, NULL_TREE);
7780 tree int_ftype_int_v4sf_v4sf
7781 = build_function_type_list (integer_type_node,
7782 integer_type_node, V4SF_type_node,
7783 V4SF_type_node, NULL_TREE);
7784 tree v4si_ftype_v4si
7785 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
7786 tree v8hi_ftype_v8hi
7787 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
7788 tree v16qi_ftype_v16qi
7789 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
7790 tree v4sf_ftype_v4sf
7791 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 7792 tree void_ftype_pcvoid_int_int
a3170dc6 7793 = build_function_type_list (void_type_node,
0dbc3651 7794 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
7795 integer_type_node, NULL_TREE);
7796 tree int_ftype_pcchar
7797 = build_function_type_list (integer_type_node,
7798 pcchar_type_node, NULL_TREE);
7799
0dbc3651
ZW
7800 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
7801 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
7802 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
7803 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
7804 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
7805 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
7806 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
7807 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
7808 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
7809 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
7810 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
7811 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
7812 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
7813 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
7814 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
7815 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
7816 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
7817 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
7818 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
e34b6648 7819 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_int, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
7820 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
7821 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
7822 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
7823 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
7824 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
7825 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
7826 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
7827 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
7828 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
7829 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
7830 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
7831 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 7832
8bb418a3
ZL
7833 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
7834 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
7835 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
7836
a3170dc6
AH
7837 /* Add the DST variants. */
7838 d = (struct builtin_description *) bdesc_dst;
7839 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 7840 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
7841
7842 /* Initialize the predicates. */
7843 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
7844 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
7845 {
7846 enum machine_mode mode1;
7847 tree type;
7848
7849 mode1 = insn_data[dp->icode].operand[1].mode;
7850
7851 switch (mode1)
7852 {
7853 case V4SImode:
7854 type = int_ftype_int_v4si_v4si;
7855 break;
7856 case V8HImode:
7857 type = int_ftype_int_v8hi_v8hi;
7858 break;
7859 case V16QImode:
7860 type = int_ftype_int_v16qi_v16qi;
7861 break;
7862 case V4SFmode:
7863 type = int_ftype_int_v4sf_v4sf;
7864 break;
7865 default:
7866 abort ();
7867 }
f676971a 7868
a3170dc6
AH
7869 def_builtin (dp->mask, dp->name, type, dp->code);
7870 }
7871
7872 /* Initialize the abs* operators. */
7873 d = (struct builtin_description *) bdesc_abs;
7874 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
7875 {
7876 enum machine_mode mode0;
7877 tree type;
7878
7879 mode0 = insn_data[d->icode].operand[0].mode;
7880
7881 switch (mode0)
7882 {
7883 case V4SImode:
7884 type = v4si_ftype_v4si;
7885 break;
7886 case V8HImode:
7887 type = v8hi_ftype_v8hi;
7888 break;
7889 case V16QImode:
7890 type = v16qi_ftype_v16qi;
7891 break;
7892 case V4SFmode:
7893 type = v4sf_ftype_v4sf;
7894 break;
7895 default:
7896 abort ();
7897 }
f676971a 7898
a3170dc6
AH
7899 def_builtin (d->mask, d->name, type, d->code);
7900 }
7ccf35ed 7901
13c62176
DN
7902 if (TARGET_ALTIVEC)
7903 {
7904 tree decl;
7905
7906 /* Initialize target builtin that implements
7907 targetm.vectorize.builtin_mask_for_load. */
7908
7909 decl = lang_hooks.builtin_function ("__builtin_altivec_mask_for_load",
7910 v16qi_ftype_long_pcvoid,
7911 ALTIVEC_BUILTIN_MASK_FOR_LOAD,
7912 BUILT_IN_MD, NULL, NULL_TREE);
7913 /* Record the decl. Will be used by rs6000_builtin_mask_for_load. */
7914 altivec_builtin_mask_for_load = decl;
7915
7916
7917 /* Initialize target builtin that implements
7918 targetm.vectorize.builtin_mask_for_store. */
7919
7920 decl = lang_hooks.builtin_function ("__builtin_altivec_mask_for_store",
7921 v16qi_ftype_long_pcvoid,
7922 ALTIVEC_BUILTIN_MASK_FOR_STORE,
7923 BUILT_IN_MD, NULL, NULL_TREE);
7924 /* Record the decl. Will be used by rs6000_builtin_mask_for_store. */
7925 altivec_builtin_mask_for_store = decl;
7926 }
a3170dc6
AH
7927}
7928
7929static void
863d938c 7930rs6000_common_init_builtins (void)
a3170dc6
AH
7931{
7932 struct builtin_description *d;
7933 size_t i;
7934
7935 tree v4sf_ftype_v4sf_v4sf_v16qi
7936 = build_function_type_list (V4SF_type_node,
7937 V4SF_type_node, V4SF_type_node,
7938 V16QI_type_node, NULL_TREE);
7939 tree v4si_ftype_v4si_v4si_v16qi
7940 = build_function_type_list (V4SI_type_node,
7941 V4SI_type_node, V4SI_type_node,
7942 V16QI_type_node, NULL_TREE);
7943 tree v8hi_ftype_v8hi_v8hi_v16qi
7944 = build_function_type_list (V8HI_type_node,
7945 V8HI_type_node, V8HI_type_node,
7946 V16QI_type_node, NULL_TREE);
7947 tree v16qi_ftype_v16qi_v16qi_v16qi
7948 = build_function_type_list (V16QI_type_node,
7949 V16QI_type_node, V16QI_type_node,
7950 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
7951 tree v4si_ftype_int
7952 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
7953 tree v8hi_ftype_int
7954 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
7955 tree v16qi_ftype_int
7956 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
7957 tree v8hi_ftype_v16qi
7958 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
7959 tree v4sf_ftype_v4sf
7960 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
7961
7962 tree v2si_ftype_v2si_v2si
2abe3e28
AH
7963 = build_function_type_list (opaque_V2SI_type_node,
7964 opaque_V2SI_type_node,
7965 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7966
7967 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
7968 = build_function_type_list (opaque_V2SF_type_node,
7969 opaque_V2SF_type_node,
7970 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7971
7972 tree v2si_ftype_int_int
2abe3e28 7973 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7974 integer_type_node, integer_type_node,
7975 NULL_TREE);
7976
7977 tree v2si_ftype_v2si
2abe3e28
AH
7978 = build_function_type_list (opaque_V2SI_type_node,
7979 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7980
7981 tree v2sf_ftype_v2sf
2abe3e28
AH
7982 = build_function_type_list (opaque_V2SF_type_node,
7983 opaque_V2SF_type_node, NULL_TREE);
f676971a 7984
a3170dc6 7985 tree v2sf_ftype_v2si
2abe3e28
AH
7986 = build_function_type_list (opaque_V2SF_type_node,
7987 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7988
7989 tree v2si_ftype_v2sf
2abe3e28
AH
7990 = build_function_type_list (opaque_V2SI_type_node,
7991 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7992
7993 tree v2si_ftype_v2si_char
2abe3e28
AH
7994 = build_function_type_list (opaque_V2SI_type_node,
7995 opaque_V2SI_type_node,
7996 char_type_node, NULL_TREE);
a3170dc6
AH
7997
7998 tree v2si_ftype_int_char
2abe3e28 7999 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
8000 integer_type_node, char_type_node, NULL_TREE);
8001
8002 tree v2si_ftype_char
2abe3e28
AH
8003 = build_function_type_list (opaque_V2SI_type_node,
8004 char_type_node, NULL_TREE);
a3170dc6
AH
8005
8006 tree int_ftype_int_int
8007 = build_function_type_list (integer_type_node,
8008 integer_type_node, integer_type_node,
8009 NULL_TREE);
95385cbb 8010
0ac081f6 8011 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
8012 = build_function_type_list (V4SI_type_node,
8013 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 8014 tree v4sf_ftype_v4si_int
b4de2f7d 8015 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
8016 V4SI_type_node, integer_type_node, NULL_TREE);
8017 tree v4si_ftype_v4sf_int
b4de2f7d 8018 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
8019 V4SF_type_node, integer_type_node, NULL_TREE);
8020 tree v4si_ftype_v4si_int
b4de2f7d 8021 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
8022 V4SI_type_node, integer_type_node, NULL_TREE);
8023 tree v8hi_ftype_v8hi_int
b4de2f7d 8024 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
8025 V8HI_type_node, integer_type_node, NULL_TREE);
8026 tree v16qi_ftype_v16qi_int
b4de2f7d 8027 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
8028 V16QI_type_node, integer_type_node, NULL_TREE);
8029 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
8030 = build_function_type_list (V16QI_type_node,
8031 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
8032 integer_type_node, NULL_TREE);
8033 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
8034 = build_function_type_list (V8HI_type_node,
8035 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
8036 integer_type_node, NULL_TREE);
8037 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
8038 = build_function_type_list (V4SI_type_node,
8039 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
8040 integer_type_node, NULL_TREE);
8041 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
8042 = build_function_type_list (V4SF_type_node,
8043 V4SF_type_node, V4SF_type_node,
b9e4e5d1 8044 integer_type_node, NULL_TREE);
0ac081f6 8045 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
8046 = build_function_type_list (V4SF_type_node,
8047 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 8048 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
8049 = build_function_type_list (V4SF_type_node,
8050 V4SF_type_node, V4SF_type_node,
8051 V4SI_type_node, NULL_TREE);
2212663f 8052 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
8053 = build_function_type_list (V4SF_type_node,
8054 V4SF_type_node, V4SF_type_node,
8055 V4SF_type_node, NULL_TREE);
f676971a 8056 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
8057 = build_function_type_list (V4SI_type_node,
8058 V4SI_type_node, V4SI_type_node,
8059 V4SI_type_node, NULL_TREE);
0ac081f6 8060 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
8061 = build_function_type_list (V8HI_type_node,
8062 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 8063 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
8064 = build_function_type_list (V8HI_type_node,
8065 V8HI_type_node, V8HI_type_node,
8066 V8HI_type_node, NULL_TREE);
c4ad648e 8067 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
8068 = build_function_type_list (V4SI_type_node,
8069 V8HI_type_node, V8HI_type_node,
8070 V4SI_type_node, NULL_TREE);
c4ad648e 8071 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
8072 = build_function_type_list (V4SI_type_node,
8073 V16QI_type_node, V16QI_type_node,
8074 V4SI_type_node, NULL_TREE);
0ac081f6 8075 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
8076 = build_function_type_list (V16QI_type_node,
8077 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8078 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
8079 = build_function_type_list (V4SI_type_node,
8080 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 8081 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
8082 = build_function_type_list (V8HI_type_node,
8083 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8084 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
8085 = build_function_type_list (V4SI_type_node,
8086 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8087 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
8088 = build_function_type_list (V8HI_type_node,
8089 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 8090 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
8091 = build_function_type_list (V16QI_type_node,
8092 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8093 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
8094 = build_function_type_list (V4SI_type_node,
8095 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 8096 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
8097 = build_function_type_list (V4SI_type_node,
8098 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8099 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
8100 = build_function_type_list (V4SI_type_node,
8101 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
8102 tree v4si_ftype_v8hi
8103 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
8104 tree int_ftype_v4si_v4si
8105 = build_function_type_list (integer_type_node,
8106 V4SI_type_node, V4SI_type_node, NULL_TREE);
8107 tree int_ftype_v4sf_v4sf
8108 = build_function_type_list (integer_type_node,
8109 V4SF_type_node, V4SF_type_node, NULL_TREE);
8110 tree int_ftype_v16qi_v16qi
8111 = build_function_type_list (integer_type_node,
8112 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8113 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
8114 = build_function_type_list (integer_type_node,
8115 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8116
6f317ef3 8117 /* Add the simple ternary operators. */
2212663f 8118 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 8119 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f 8120 {
f676971a 8121
2212663f
DB
8122 enum machine_mode mode0, mode1, mode2, mode3;
8123 tree type;
8124
0559cc77 8125 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 8126 continue;
f676971a 8127
2212663f
DB
8128 mode0 = insn_data[d->icode].operand[0].mode;
8129 mode1 = insn_data[d->icode].operand[1].mode;
8130 mode2 = insn_data[d->icode].operand[2].mode;
8131 mode3 = insn_data[d->icode].operand[3].mode;
f676971a 8132
2212663f
DB
8133 /* When all four are of the same mode. */
8134 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
8135 {
8136 switch (mode0)
8137 {
617e0e1d
DB
8138 case V4SImode:
8139 type = v4si_ftype_v4si_v4si_v4si;
8140 break;
2212663f
DB
8141 case V4SFmode:
8142 type = v4sf_ftype_v4sf_v4sf_v4sf;
8143 break;
8144 case V8HImode:
8145 type = v8hi_ftype_v8hi_v8hi_v8hi;
f676971a 8146 break;
2212663f
DB
8147 case V16QImode:
8148 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8149 break;
2212663f 8150 default:
f676971a 8151 abort();
2212663f
DB
8152 }
8153 }
8154 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
c4ad648e 8155 {
2212663f
DB
8156 switch (mode0)
8157 {
8158 case V4SImode:
8159 type = v4si_ftype_v4si_v4si_v16qi;
8160 break;
8161 case V4SFmode:
8162 type = v4sf_ftype_v4sf_v4sf_v16qi;
8163 break;
8164 case V8HImode:
8165 type = v8hi_ftype_v8hi_v8hi_v16qi;
f676971a 8166 break;
2212663f
DB
8167 case V16QImode:
8168 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8169 break;
2212663f 8170 default:
f676971a 8171 abort();
2212663f
DB
8172 }
8173 }
f676971a 8174 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
2212663f 8175 && mode3 == V4SImode)
24408032 8176 type = v4si_ftype_v16qi_v16qi_v4si;
f676971a 8177 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
2212663f 8178 && mode3 == V4SImode)
24408032 8179 type = v4si_ftype_v8hi_v8hi_v4si;
f676971a 8180 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
617e0e1d 8181 && mode3 == V4SImode)
24408032
AH
8182 type = v4sf_ftype_v4sf_v4sf_v4si;
8183
8184 /* vchar, vchar, vchar, 4 bit literal. */
8185 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
8186 && mode3 == QImode)
b9e4e5d1 8187 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
8188
8189 /* vshort, vshort, vshort, 4 bit literal. */
8190 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
8191 && mode3 == QImode)
b9e4e5d1 8192 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
8193
8194 /* vint, vint, vint, 4 bit literal. */
8195 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
8196 && mode3 == QImode)
b9e4e5d1 8197 type = v4si_ftype_v4si_v4si_int;
24408032
AH
8198
8199 /* vfloat, vfloat, vfloat, 4 bit literal. */
8200 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
8201 && mode3 == QImode)
b9e4e5d1 8202 type = v4sf_ftype_v4sf_v4sf_int;
24408032 8203
2212663f
DB
8204 else
8205 abort ();
8206
8207 def_builtin (d->mask, d->name, type, d->code);
8208 }
8209
0ac081f6 8210 /* Add the simple binary operators. */
00b960c7 8211 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 8212 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
8213 {
8214 enum machine_mode mode0, mode1, mode2;
8215 tree type;
8216
0559cc77 8217 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6 8218 continue;
f676971a 8219
0ac081f6
AH
8220 mode0 = insn_data[d->icode].operand[0].mode;
8221 mode1 = insn_data[d->icode].operand[1].mode;
8222 mode2 = insn_data[d->icode].operand[2].mode;
8223
8224 /* When all three operands are of the same mode. */
8225 if (mode0 == mode1 && mode1 == mode2)
8226 {
8227 switch (mode0)
8228 {
8229 case V4SFmode:
8230 type = v4sf_ftype_v4sf_v4sf;
8231 break;
8232 case V4SImode:
8233 type = v4si_ftype_v4si_v4si;
8234 break;
8235 case V16QImode:
8236 type = v16qi_ftype_v16qi_v16qi;
8237 break;
8238 case V8HImode:
8239 type = v8hi_ftype_v8hi_v8hi;
8240 break;
a3170dc6
AH
8241 case V2SImode:
8242 type = v2si_ftype_v2si_v2si;
8243 break;
8244 case V2SFmode:
8245 type = v2sf_ftype_v2sf_v2sf;
8246 break;
8247 case SImode:
8248 type = int_ftype_int_int;
8249 break;
0ac081f6
AH
8250 default:
8251 abort ();
8252 }
8253 }
8254
8255 /* A few other combos we really don't want to do manually. */
8256
8257 /* vint, vfloat, vfloat. */
8258 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
8259 type = v4si_ftype_v4sf_v4sf;
8260
8261 /* vshort, vchar, vchar. */
8262 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
8263 type = v8hi_ftype_v16qi_v16qi;
8264
8265 /* vint, vshort, vshort. */
8266 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
8267 type = v4si_ftype_v8hi_v8hi;
8268
8269 /* vshort, vint, vint. */
8270 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
8271 type = v8hi_ftype_v4si_v4si;
8272
8273 /* vchar, vshort, vshort. */
8274 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
8275 type = v16qi_ftype_v8hi_v8hi;
8276
8277 /* vint, vchar, vint. */
8278 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
8279 type = v4si_ftype_v16qi_v4si;
8280
fa066a23
AH
8281 /* vint, vchar, vchar. */
8282 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
8283 type = v4si_ftype_v16qi_v16qi;
8284
0ac081f6
AH
8285 /* vint, vshort, vint. */
8286 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
8287 type = v4si_ftype_v8hi_v4si;
f676971a 8288
2212663f
DB
8289 /* vint, vint, 5 bit literal. */
8290 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8291 type = v4si_ftype_v4si_int;
f676971a 8292
2212663f
DB
8293 /* vshort, vshort, 5 bit literal. */
8294 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 8295 type = v8hi_ftype_v8hi_int;
f676971a 8296
2212663f
DB
8297 /* vchar, vchar, 5 bit literal. */
8298 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 8299 type = v16qi_ftype_v16qi_int;
0ac081f6 8300
617e0e1d
DB
8301 /* vfloat, vint, 5 bit literal. */
8302 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8303 type = v4sf_ftype_v4si_int;
f676971a 8304
617e0e1d
DB
8305 /* vint, vfloat, 5 bit literal. */
8306 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 8307 type = v4si_ftype_v4sf_int;
617e0e1d 8308
a3170dc6
AH
8309 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
8310 type = v2si_ftype_int_int;
8311
8312 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
8313 type = v2si_ftype_v2si_char;
8314
8315 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
8316 type = v2si_ftype_int_char;
8317
0ac081f6
AH
8318 /* int, x, x. */
8319 else if (mode0 == SImode)
8320 {
8321 switch (mode1)
8322 {
8323 case V4SImode:
8324 type = int_ftype_v4si_v4si;
8325 break;
8326 case V4SFmode:
8327 type = int_ftype_v4sf_v4sf;
8328 break;
8329 case V16QImode:
8330 type = int_ftype_v16qi_v16qi;
8331 break;
8332 case V8HImode:
8333 type = int_ftype_v8hi_v8hi;
8334 break;
8335 default:
8336 abort ();
8337 }
8338 }
8339
8340 else
8341 abort ();
8342
2212663f
DB
8343 def_builtin (d->mask, d->name, type, d->code);
8344 }
24408032 8345
2212663f
DB
8346 /* Add the simple unary operators. */
8347 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 8348 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
8349 {
8350 enum machine_mode mode0, mode1;
8351 tree type;
8352
0559cc77 8353 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 8354 continue;
f676971a 8355
2212663f
DB
8356 mode0 = insn_data[d->icode].operand[0].mode;
8357 mode1 = insn_data[d->icode].operand[1].mode;
8358
8359 if (mode0 == V4SImode && mode1 == QImode)
c4ad648e 8360 type = v4si_ftype_int;
2212663f 8361 else if (mode0 == V8HImode && mode1 == QImode)
c4ad648e 8362 type = v8hi_ftype_int;
2212663f 8363 else if (mode0 == V16QImode && mode1 == QImode)
c4ad648e 8364 type = v16qi_ftype_int;
617e0e1d
DB
8365 else if (mode0 == V4SFmode && mode1 == V4SFmode)
8366 type = v4sf_ftype_v4sf;
20e26713
AH
8367 else if (mode0 == V8HImode && mode1 == V16QImode)
8368 type = v8hi_ftype_v16qi;
8369 else if (mode0 == V4SImode && mode1 == V8HImode)
8370 type = v4si_ftype_v8hi;
a3170dc6
AH
8371 else if (mode0 == V2SImode && mode1 == V2SImode)
8372 type = v2si_ftype_v2si;
8373 else if (mode0 == V2SFmode && mode1 == V2SFmode)
8374 type = v2sf_ftype_v2sf;
8375 else if (mode0 == V2SFmode && mode1 == V2SImode)
8376 type = v2sf_ftype_v2si;
8377 else if (mode0 == V2SImode && mode1 == V2SFmode)
8378 type = v2si_ftype_v2sf;
8379 else if (mode0 == V2SImode && mode1 == QImode)
8380 type = v2si_ftype_char;
2212663f
DB
8381 else
8382 abort ();
8383
0ac081f6
AH
8384 def_builtin (d->mask, d->name, type, d->code);
8385 }
8386}
8387
c15c90bb
ZW
8388static void
8389rs6000_init_libfuncs (void)
8390{
8391 if (!TARGET_HARD_FLOAT)
8392 return;
8393
c9034561 8394 if (DEFAULT_ABI != ABI_V4)
c15c90bb 8395 {
c9034561 8396 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 8397 {
c9034561 8398 /* AIX library routines for float->int conversion. */
85363ca0
ZW
8399 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
8400 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
8401 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
8402 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
8403 }
8404
c9034561 8405 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8406 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
8407 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
8408 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
8409 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
8410 }
c9034561 8411 else
c15c90bb 8412 {
c9034561 8413 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8414
8415 set_optab_libfunc (add_optab, TFmode, "_q_add");
8416 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
8417 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
8418 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
8419 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
8420 if (TARGET_PPC_GPOPT || TARGET_POWER2)
8421 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
8422
c9034561
ZW
8423 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
8424 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
8425 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
8426 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
8427 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
8428 set_optab_libfunc (le_optab, TFmode, "_q_fle");
8429
85363ca0
ZW
8430 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
8431 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
8432 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
8433 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
8434 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
8435 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
8436 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
8437 }
8438}
fba73eb1
DE
8439
8440\f
8441/* Expand a block clear operation, and return 1 if successful. Return 0
8442 if we should let the compiler generate normal code.
8443
8444 operands[0] is the destination
8445 operands[1] is the length
8446 operands[2] is the alignment */
8447
8448int
8449expand_block_clear (rtx operands[])
8450{
8451 rtx orig_dest = operands[0];
8452 rtx bytes_rtx = operands[1];
8453 rtx align_rtx = operands[2];
5514620a
GK
8454 bool constp = (GET_CODE (bytes_rtx) == CONST_INT);
8455 HOST_WIDE_INT align;
8456 HOST_WIDE_INT bytes;
fba73eb1
DE
8457 int offset;
8458 int clear_bytes;
5514620a 8459 int clear_step;
fba73eb1
DE
8460
8461 /* If this is not a fixed size move, just call memcpy */
8462 if (! constp)
8463 return 0;
8464
8465 /* If this is not a fixed size alignment, abort */
8466 if (GET_CODE (align_rtx) != CONST_INT)
8467 abort ();
8468 align = INTVAL (align_rtx) * BITS_PER_UNIT;
8469
8470 /* Anything to clear? */
8471 bytes = INTVAL (bytes_rtx);
8472 if (bytes <= 0)
8473 return 1;
8474
5514620a
GK
8475 /* Use the builtin memset after a point, to avoid huge code bloat.
8476 When optimize_size, avoid any significant code bloat; calling
8477 memset is about 4 instructions, so allow for one instruction to
8478 load zero and three to do clearing. */
8479 if (TARGET_ALTIVEC && align >= 128)
8480 clear_step = 16;
8481 else if (TARGET_POWERPC64 && align >= 32)
8482 clear_step = 8;
8483 else
8484 clear_step = 4;
fba73eb1 8485
5514620a
GK
8486 if (optimize_size && bytes > 3 * clear_step)
8487 return 0;
8488 if (! optimize_size && bytes > 8 * clear_step)
fba73eb1
DE
8489 return 0;
8490
8491 for (offset = 0; bytes > 0; offset += clear_bytes, bytes -= clear_bytes)
8492 {
fba73eb1
DE
8493 enum machine_mode mode = BLKmode;
8494 rtx dest;
f676971a 8495
5514620a
GK
8496 if (bytes >= 16 && TARGET_ALTIVEC && align >= 128)
8497 {
8498 clear_bytes = 16;
8499 mode = V4SImode;
8500 }
8501 else if (bytes >= 8 && TARGET_POWERPC64
8502 /* 64-bit loads and stores require word-aligned
8503 displacements. */
8504 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
fba73eb1
DE
8505 {
8506 clear_bytes = 8;
8507 mode = DImode;
fba73eb1 8508 }
5514620a 8509 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
fba73eb1
DE
8510 { /* move 4 bytes */
8511 clear_bytes = 4;
8512 mode = SImode;
fba73eb1 8513 }
5514620a 8514 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
fba73eb1
DE
8515 { /* move 2 bytes */
8516 clear_bytes = 2;
8517 mode = HImode;
fba73eb1
DE
8518 }
8519 else /* move 1 byte at a time */
8520 {
8521 clear_bytes = 1;
8522 mode = QImode;
fba73eb1 8523 }
f676971a 8524
fba73eb1 8525 dest = adjust_address (orig_dest, mode, offset);
f676971a 8526
5514620a 8527 emit_move_insn (dest, CONST0_RTX (mode));
fba73eb1
DE
8528 }
8529
8530 return 1;
8531}
8532
35aff10b 8533\f
7e69e155
MM
8534/* Expand a block move operation, and return 1 if successful. Return 0
8535 if we should let the compiler generate normal code.
8536
8537 operands[0] is the destination
8538 operands[1] is the source
8539 operands[2] is the length
8540 operands[3] is the alignment */
8541
3933e0e1
MM
8542#define MAX_MOVE_REG 4
8543
7e69e155 8544int
a2369ed3 8545expand_block_move (rtx operands[])
7e69e155 8546{
b6c9286a
MM
8547 rtx orig_dest = operands[0];
8548 rtx orig_src = operands[1];
7e69e155 8549 rtx bytes_rtx = operands[2];
7e69e155 8550 rtx align_rtx = operands[3];
3933e0e1 8551 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 8552 int align;
3933e0e1
MM
8553 int bytes;
8554 int offset;
7e69e155 8555 int move_bytes;
cabfd258
GK
8556 rtx stores[MAX_MOVE_REG];
8557 int num_reg = 0;
7e69e155 8558
3933e0e1 8559 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 8560 if (! constp)
3933e0e1
MM
8561 return 0;
8562
5ee95df6
FS
8563 /* If this is not a fixed size alignment, abort */
8564 if (GET_CODE (align_rtx) != CONST_INT)
8565 abort ();
fba73eb1 8566 align = INTVAL (align_rtx) * BITS_PER_UNIT;
5ee95df6 8567
7e69e155 8568 /* Anything to move? */
3933e0e1
MM
8569 bytes = INTVAL (bytes_rtx);
8570 if (bytes <= 0)
7e69e155
MM
8571 return 1;
8572
ea9982a8 8573 /* store_one_arg depends on expand_block_move to handle at least the size of
f676971a 8574 reg_parm_stack_space. */
ea9982a8 8575 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
8576 return 0;
8577
cabfd258 8578 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 8579 {
cabfd258 8580 union {
70128ad9 8581 rtx (*movmemsi) (rtx, rtx, rtx, rtx);
a2369ed3 8582 rtx (*mov) (rtx, rtx);
cabfd258
GK
8583 } gen_func;
8584 enum machine_mode mode = BLKmode;
8585 rtx src, dest;
f676971a 8586
5514620a
GK
8587 /* Altivec first, since it will be faster than a string move
8588 when it applies, and usually not significantly larger. */
8589 if (TARGET_ALTIVEC && bytes >= 16 && align >= 128)
8590 {
8591 move_bytes = 16;
8592 mode = V4SImode;
8593 gen_func.mov = gen_movv4si;
8594 }
8595 else if (TARGET_STRING
cabfd258
GK
8596 && bytes > 24 /* move up to 32 bytes at a time */
8597 && ! fixed_regs[5]
8598 && ! fixed_regs[6]
8599 && ! fixed_regs[7]
8600 && ! fixed_regs[8]
8601 && ! fixed_regs[9]
8602 && ! fixed_regs[10]
8603 && ! fixed_regs[11]
8604 && ! fixed_regs[12])
7e69e155 8605 {
cabfd258 8606 move_bytes = (bytes > 32) ? 32 : bytes;
70128ad9 8607 gen_func.movmemsi = gen_movmemsi_8reg;
cabfd258
GK
8608 }
8609 else if (TARGET_STRING
8610 && bytes > 16 /* move up to 24 bytes at a time */
8611 && ! fixed_regs[5]
8612 && ! fixed_regs[6]
8613 && ! fixed_regs[7]
8614 && ! fixed_regs[8]
8615 && ! fixed_regs[9]
8616 && ! fixed_regs[10])
8617 {
8618 move_bytes = (bytes > 24) ? 24 : bytes;
70128ad9 8619 gen_func.movmemsi = gen_movmemsi_6reg;
cabfd258
GK
8620 }
8621 else if (TARGET_STRING
8622 && bytes > 8 /* move up to 16 bytes at a time */
8623 && ! fixed_regs[5]
8624 && ! fixed_regs[6]
8625 && ! fixed_regs[7]
8626 && ! fixed_regs[8])
8627 {
8628 move_bytes = (bytes > 16) ? 16 : bytes;
70128ad9 8629 gen_func.movmemsi = gen_movmemsi_4reg;
cabfd258
GK
8630 }
8631 else if (bytes >= 8 && TARGET_POWERPC64
8632 /* 64-bit loads and stores require word-aligned
8633 displacements. */
fba73eb1 8634 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
cabfd258
GK
8635 {
8636 move_bytes = 8;
8637 mode = DImode;
8638 gen_func.mov = gen_movdi;
8639 }
8640 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
8641 { /* move up to 8 bytes at a time */
8642 move_bytes = (bytes > 8) ? 8 : bytes;
70128ad9 8643 gen_func.movmemsi = gen_movmemsi_2reg;
cabfd258 8644 }
cd7d9ca4 8645 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
cabfd258
GK
8646 { /* move 4 bytes */
8647 move_bytes = 4;
8648 mode = SImode;
8649 gen_func.mov = gen_movsi;
8650 }
cd7d9ca4 8651 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
cabfd258
GK
8652 { /* move 2 bytes */
8653 move_bytes = 2;
8654 mode = HImode;
8655 gen_func.mov = gen_movhi;
8656 }
8657 else if (TARGET_STRING && bytes > 1)
8658 { /* move up to 4 bytes at a time */
8659 move_bytes = (bytes > 4) ? 4 : bytes;
70128ad9 8660 gen_func.movmemsi = gen_movmemsi_1reg;
cabfd258
GK
8661 }
8662 else /* move 1 byte at a time */
8663 {
8664 move_bytes = 1;
8665 mode = QImode;
8666 gen_func.mov = gen_movqi;
8667 }
f676971a 8668
cabfd258
GK
8669 src = adjust_address (orig_src, mode, offset);
8670 dest = adjust_address (orig_dest, mode, offset);
f676971a
EC
8671
8672 if (mode != BLKmode)
cabfd258
GK
8673 {
8674 rtx tmp_reg = gen_reg_rtx (mode);
f676971a 8675
cabfd258
GK
8676 emit_insn ((*gen_func.mov) (tmp_reg, src));
8677 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 8678 }
3933e0e1 8679
cabfd258
GK
8680 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
8681 {
8682 int i;
8683 for (i = 0; i < num_reg; i++)
8684 emit_insn (stores[i]);
8685 num_reg = 0;
8686 }
35aff10b 8687
cabfd258 8688 if (mode == BLKmode)
7e69e155 8689 {
70128ad9 8690 /* Move the address into scratch registers. The movmemsi
cabfd258
GK
8691 patterns require zero offset. */
8692 if (!REG_P (XEXP (src, 0)))
b6c9286a 8693 {
cabfd258
GK
8694 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
8695 src = replace_equiv_address (src, src_reg);
b6c9286a 8696 }
cabfd258 8697 set_mem_size (src, GEN_INT (move_bytes));
f676971a 8698
cabfd258 8699 if (!REG_P (XEXP (dest, 0)))
3933e0e1 8700 {
cabfd258
GK
8701 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
8702 dest = replace_equiv_address (dest, dest_reg);
7e69e155 8703 }
cabfd258 8704 set_mem_size (dest, GEN_INT (move_bytes));
f676971a 8705
70128ad9 8706 emit_insn ((*gen_func.movmemsi) (dest, src,
cabfd258
GK
8707 GEN_INT (move_bytes & 31),
8708 align_rtx));
7e69e155 8709 }
7e69e155
MM
8710 }
8711
8712 return 1;
8713}
8714
d62294f5
FJ
8715\f
8716/* Return 1 if OP is suitable for a save_world call in prologue. It is
8717 known to be a PARALLEL. */
8718int
8719save_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8720{
8721 int index;
8722 int i;
8723 rtx elt;
8724 int count = XVECLEN (op, 0);
8725
8726 if (count != 55)
8727 return 0;
8728
8729 index = 0;
8730 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8731 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8732 return 0;
8733
8734 for (i=1; i <= 18; i++)
8735 {
8736 elt = XVECEXP (op, 0, index++);
8737 if (GET_CODE (elt) != SET
8738 || GET_CODE (SET_DEST (elt)) != MEM
8739 || ! memory_operand (SET_DEST (elt), DFmode)
8740 || GET_CODE (SET_SRC (elt)) != REG
8741 || GET_MODE (SET_SRC (elt)) != DFmode)
8742 return 0;
8743 }
8744
8745 for (i=1; i <= 12; i++)
8746 {
8747 elt = XVECEXP (op, 0, index++);
8748 if (GET_CODE (elt) != SET
8749 || GET_CODE (SET_DEST (elt)) != MEM
8750 || GET_CODE (SET_SRC (elt)) != REG
8751 || GET_MODE (SET_SRC (elt)) != V4SImode)
8752 return 0;
8753 }
8754
8755 for (i=1; i <= 19; i++)
8756 {
8757 elt = XVECEXP (op, 0, index++);
8758 if (GET_CODE (elt) != SET
8759 || GET_CODE (SET_DEST (elt)) != MEM
8760 || ! memory_operand (SET_DEST (elt), Pmode)
8761 || GET_CODE (SET_SRC (elt)) != REG
8762 || GET_MODE (SET_SRC (elt)) != Pmode)
8763 return 0;
8764 }
8765
8766 elt = XVECEXP (op, 0, index++);
8767 if (GET_CODE (elt) != SET
8768 || GET_CODE (SET_DEST (elt)) != MEM
8769 || ! memory_operand (SET_DEST (elt), Pmode)
8770 || GET_CODE (SET_SRC (elt)) != REG
8771 || REGNO (SET_SRC (elt)) != CR2_REGNO
8772 || GET_MODE (SET_SRC (elt)) != Pmode)
8773 return 0;
8774
8775 if (GET_CODE (XVECEXP (op, 0, index++)) != USE
8776 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8777 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8778 return 0;
8779 return 1;
8780}
8781
8782/* Return 1 if OP is suitable for a save_world call in prologue. It is
8783 known to be a PARALLEL. */
8784int
8785restore_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8786{
8787 int index;
8788 int i;
8789 rtx elt;
8790 int count = XVECLEN (op, 0);
8791
8792 if (count != 59)
8793 return 0;
8794
8795 index = 0;
8796 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
8797 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8798 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8799 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8800 return 0;
8801
8802 elt = XVECEXP (op, 0, index++);
8803 if (GET_CODE (elt) != SET
8804 || GET_CODE (SET_SRC (elt)) != MEM
8805 || ! memory_operand (SET_SRC (elt), Pmode)
8806 || GET_CODE (SET_DEST (elt)) != REG
8807 || REGNO (SET_DEST (elt)) != CR2_REGNO
8808 || GET_MODE (SET_DEST (elt)) != Pmode)
8809 return 0;
8810
8811 for (i=1; i <= 19; i++)
8812 {
8813 elt = XVECEXP (op, 0, index++);
8814 if (GET_CODE (elt) != SET
8815 || GET_CODE (SET_SRC (elt)) != MEM
8816 || ! memory_operand (SET_SRC (elt), Pmode)
8817 || GET_CODE (SET_DEST (elt)) != REG
8818 || GET_MODE (SET_DEST (elt)) != Pmode)
8819 return 0;
8820 }
8821
8822 for (i=1; i <= 12; i++)
8823 {
8824 elt = XVECEXP (op, 0, index++);
8825 if (GET_CODE (elt) != SET
8826 || GET_CODE (SET_SRC (elt)) != MEM
8827 || GET_CODE (SET_DEST (elt)) != REG
8828 || GET_MODE (SET_DEST (elt)) != V4SImode)
8829 return 0;
8830 }
8831
8832 for (i=1; i <= 18; i++)
8833 {
8834 elt = XVECEXP (op, 0, index++);
8835 if (GET_CODE (elt) != SET
8836 || GET_CODE (SET_SRC (elt)) != MEM
8837 || ! memory_operand (SET_SRC (elt), DFmode)
8838 || GET_CODE (SET_DEST (elt)) != REG
8839 || GET_MODE (SET_DEST (elt)) != DFmode)
8840 return 0;
8841 }
8842
8843 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8844 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8845 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8846 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8847 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8848 return 0;
8849 return 1;
8850}
8851
9878760c
RK
8852\f
8853/* Return 1 if OP is a load multiple operation. It is known to be a
8854 PARALLEL and the first section will be tested. */
8855
8856int
a2369ed3 8857load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8858{
8859 int count = XVECLEN (op, 0);
e2c953b6 8860 unsigned int dest_regno;
9878760c
RK
8861 rtx src_addr;
8862 int i;
8863
8864 /* Perform a quick check so we don't blow up below. */
8865 if (count <= 1
8866 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8867 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8868 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8869 return 0;
8870
8871 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8872 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8873
8874 for (i = 1; i < count; i++)
8875 {
8876 rtx elt = XVECEXP (op, 0, i);
8877
8878 if (GET_CODE (elt) != SET
8879 || GET_CODE (SET_DEST (elt)) != REG
8880 || GET_MODE (SET_DEST (elt)) != SImode
8881 || REGNO (SET_DEST (elt)) != dest_regno + i
8882 || GET_CODE (SET_SRC (elt)) != MEM
8883 || GET_MODE (SET_SRC (elt)) != SImode
8884 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
8885 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
8886 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
8887 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
8888 return 0;
8889 }
8890
8891 return 1;
8892}
8893
8894/* Similar, but tests for store multiple. Here, the second vector element
8895 is a CLOBBER. It will be tested later. */
8896
8897int
a2369ed3 8898store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8899{
8900 int count = XVECLEN (op, 0) - 1;
e2c953b6 8901 unsigned int src_regno;
9878760c
RK
8902 rtx dest_addr;
8903 int i;
8904
8905 /* Perform a quick check so we don't blow up below. */
8906 if (count <= 1
8907 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8908 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8909 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8910 return 0;
8911
8912 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8913 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8914
8915 for (i = 1; i < count; i++)
8916 {
8917 rtx elt = XVECEXP (op, 0, i + 1);
8918
8919 if (GET_CODE (elt) != SET
8920 || GET_CODE (SET_SRC (elt)) != REG
8921 || GET_MODE (SET_SRC (elt)) != SImode
8922 || REGNO (SET_SRC (elt)) != src_regno + i
8923 || GET_CODE (SET_DEST (elt)) != MEM
8924 || GET_MODE (SET_DEST (elt)) != SImode
8925 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
8926 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
8927 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
8928 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
8929 return 0;
8930 }
8931
8932 return 1;
8933}
9ebbca7d 8934
9caa3eb2
DE
8935/* Return a string to perform a load_multiple operation.
8936 operands[0] is the vector.
8937 operands[1] is the source address.
8938 operands[2] is the first destination register. */
8939
8940const char *
a2369ed3 8941rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
8942{
8943 /* We have to handle the case where the pseudo used to contain the address
8944 is assigned to one of the output registers. */
8945 int i, j;
8946 int words = XVECLEN (operands[0], 0);
8947 rtx xop[10];
8948
8949 if (XVECLEN (operands[0], 0) == 1)
8950 return "{l|lwz} %2,0(%1)";
8951
8952 for (i = 0; i < words; i++)
8953 if (refers_to_regno_p (REGNO (operands[2]) + i,
8954 REGNO (operands[2]) + i + 1, operands[1], 0))
8955 {
8956 if (i == words-1)
8957 {
8958 xop[0] = GEN_INT (4 * (words-1));
8959 xop[1] = operands[1];
8960 xop[2] = operands[2];
8961 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
8962 return "";
8963 }
8964 else if (i == 0)
8965 {
8966 xop[0] = GEN_INT (4 * (words-1));
8967 xop[1] = operands[1];
8968 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
8969 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);
8970 return "";
8971 }
8972 else
8973 {
8974 for (j = 0; j < words; j++)
8975 if (j != i)
8976 {
8977 xop[0] = GEN_INT (j * 4);
8978 xop[1] = operands[1];
8979 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
8980 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
8981 }
8982 xop[0] = GEN_INT (i * 4);
8983 xop[1] = operands[1];
8984 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
8985 return "";
8986 }
8987 }
8988
8989 return "{lsi|lswi} %2,%1,%N0";
8990}
8991
00b960c7
AH
8992/* Return 1 for a parallel vrsave operation. */
8993
8994int
a2369ed3 8995vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
8996{
8997 int count = XVECLEN (op, 0);
8998 unsigned int dest_regno, src_regno;
8999 int i;
9000
9001 if (count <= 1
9002 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9003 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 9004 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
9005 return 0;
9006
9007 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9008 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9009
9010 if (dest_regno != VRSAVE_REGNO
9011 && src_regno != VRSAVE_REGNO)
9012 return 0;
9013
9014 for (i = 1; i < count; i++)
9015 {
9016 rtx elt = XVECEXP (op, 0, i);
9017
9aa86737
AH
9018 if (GET_CODE (elt) != CLOBBER
9019 && GET_CODE (elt) != SET)
00b960c7
AH
9020 return 0;
9021 }
9022
9023 return 1;
9024}
9025
2c4a9cff
DE
9026/* Return 1 for an PARALLEL suitable for mfcr. */
9027
9028int
a2369ed3 9029mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
9030{
9031 int count = XVECLEN (op, 0);
9032 int i;
9033
9034 /* Perform a quick check so we don't blow up below. */
9035 if (count < 1
9036 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9037 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
9038 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9039 return 0;
9040
9041 for (i = 0; i < count; i++)
9042 {
9043 rtx exp = XVECEXP (op, 0, i);
9044 rtx unspec;
9045 int maskval;
9046 rtx src_reg;
9047
9048 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
9049
9050 if (GET_CODE (src_reg) != REG
9051 || GET_MODE (src_reg) != CCmode
9052 || ! CR_REGNO_P (REGNO (src_reg)))
9053 return 0;
9054
9055 if (GET_CODE (exp) != SET
9056 || GET_CODE (SET_DEST (exp)) != REG
9057 || GET_MODE (SET_DEST (exp)) != SImode
9058 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
9059 return 0;
9060 unspec = SET_SRC (exp);
9061 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
9062
9063 if (GET_CODE (unspec) != UNSPEC
9064 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
9065 || XVECLEN (unspec, 0) != 2
9066 || XVECEXP (unspec, 0, 0) != src_reg
9067 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
9068 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
9069 return 0;
9070 }
9071 return 1;
9072}
9073
a4f6c312 9074/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
9075
9076int
a2369ed3 9077mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9078{
9079 int count = XVECLEN (op, 0);
9080 int i;
9ebbca7d
GK
9081 rtx src_reg;
9082
9083 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
9084 if (count < 1
9085 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9086 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
9087 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 9088 return 0;
e35b9579 9089 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
f676971a 9090
9ebbca7d
GK
9091 if (GET_CODE (src_reg) != REG
9092 || GET_MODE (src_reg) != SImode
9093 || ! INT_REGNO_P (REGNO (src_reg)))
9094 return 0;
9095
e35b9579 9096 for (i = 0; i < count; i++)
9ebbca7d
GK
9097 {
9098 rtx exp = XVECEXP (op, 0, i);
9099 rtx unspec;
9100 int maskval;
f676971a 9101
9ebbca7d
GK
9102 if (GET_CODE (exp) != SET
9103 || GET_CODE (SET_DEST (exp)) != REG
9104 || GET_MODE (SET_DEST (exp)) != CCmode
9105 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
9106 return 0;
9107 unspec = SET_SRC (exp);
9108 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
f676971a 9109
9ebbca7d 9110 if (GET_CODE (unspec) != UNSPEC
615158e2 9111 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
9112 || XVECLEN (unspec, 0) != 2
9113 || XVECEXP (unspec, 0, 0) != src_reg
9114 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
9115 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
9116 return 0;
9117 }
e35b9579 9118 return 1;
9ebbca7d
GK
9119}
9120
a4f6c312 9121/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
9122
9123int
a2369ed3 9124lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9125{
9126 int count = XVECLEN (op, 0);
e2c953b6 9127 unsigned int dest_regno;
9ebbca7d 9128 rtx src_addr;
e2c953b6 9129 unsigned int base_regno;
9ebbca7d
GK
9130 HOST_WIDE_INT offset;
9131 int i;
9132
9133 /* Perform a quick check so we don't blow up below. */
9134 if (count <= 1
9135 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9136 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
9137 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
9138 return 0;
9139
9140 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9141 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
9142
9143 if (dest_regno > 31
e2c953b6 9144 || count != 32 - (int) dest_regno)
9ebbca7d
GK
9145 return 0;
9146
4d588c14 9147 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
9148 {
9149 offset = 0;
9150 base_regno = REGNO (src_addr);
9151 if (base_regno == 0)
9152 return 0;
9153 }
76d2b81d 9154 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
9155 {
9156 offset = INTVAL (XEXP (src_addr, 1));
9157 base_regno = REGNO (XEXP (src_addr, 0));
9158 }
9159 else
9160 return 0;
9161
9162 for (i = 0; i < count; i++)
9163 {
9164 rtx elt = XVECEXP (op, 0, i);
9165 rtx newaddr;
9166 rtx addr_reg;
9167 HOST_WIDE_INT newoffset;
9168
9169 if (GET_CODE (elt) != SET
9170 || GET_CODE (SET_DEST (elt)) != REG
9171 || GET_MODE (SET_DEST (elt)) != SImode
9172 || REGNO (SET_DEST (elt)) != dest_regno + i
9173 || GET_CODE (SET_SRC (elt)) != MEM
9174 || GET_MODE (SET_SRC (elt)) != SImode)
9175 return 0;
9176 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 9177 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9178 {
9179 newoffset = 0;
9180 addr_reg = newaddr;
9181 }
76d2b81d 9182 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9183 {
9184 addr_reg = XEXP (newaddr, 0);
9185 newoffset = INTVAL (XEXP (newaddr, 1));
9186 }
9187 else
9188 return 0;
9189 if (REGNO (addr_reg) != base_regno
9190 || newoffset != offset + 4 * i)
9191 return 0;
9192 }
9193
9194 return 1;
9195}
9196
a4f6c312 9197/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
9198
9199int
a2369ed3 9200stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9201{
9202 int count = XVECLEN (op, 0);
e2c953b6 9203 unsigned int src_regno;
9ebbca7d 9204 rtx dest_addr;
e2c953b6 9205 unsigned int base_regno;
9ebbca7d
GK
9206 HOST_WIDE_INT offset;
9207 int i;
9208
9209 /* Perform a quick check so we don't blow up below. */
9210 if (count <= 1
9211 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9212 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
9213 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
9214 return 0;
9215
9216 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9217 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
9218
9219 if (src_regno > 31
e2c953b6 9220 || count != 32 - (int) src_regno)
9ebbca7d
GK
9221 return 0;
9222
4d588c14 9223 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
9224 {
9225 offset = 0;
9226 base_regno = REGNO (dest_addr);
9227 if (base_regno == 0)
9228 return 0;
9229 }
76d2b81d 9230 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
9231 {
9232 offset = INTVAL (XEXP (dest_addr, 1));
9233 base_regno = REGNO (XEXP (dest_addr, 0));
9234 }
9235 else
9236 return 0;
9237
9238 for (i = 0; i < count; i++)
9239 {
9240 rtx elt = XVECEXP (op, 0, i);
9241 rtx newaddr;
9242 rtx addr_reg;
9243 HOST_WIDE_INT newoffset;
9244
9245 if (GET_CODE (elt) != SET
9246 || GET_CODE (SET_SRC (elt)) != REG
9247 || GET_MODE (SET_SRC (elt)) != SImode
9248 || REGNO (SET_SRC (elt)) != src_regno + i
9249 || GET_CODE (SET_DEST (elt)) != MEM
9250 || GET_MODE (SET_DEST (elt)) != SImode)
9251 return 0;
9252 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 9253 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9254 {
9255 newoffset = 0;
9256 addr_reg = newaddr;
9257 }
76d2b81d 9258 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9259 {
9260 addr_reg = XEXP (newaddr, 0);
9261 newoffset = INTVAL (XEXP (newaddr, 1));
9262 }
9263 else
9264 return 0;
9265 if (REGNO (addr_reg) != base_regno
9266 || newoffset != offset + 4 * i)
9267 return 0;
9268 }
9269
9270 return 1;
9271}
9878760c 9272\f
a4f6c312
SS
9273/* A validation routine: say whether CODE, a condition code, and MODE
9274 match. The other alternatives either don't make sense or should
9275 never be generated. */
39a10a29 9276
39a10a29 9277static void
a2369ed3 9278validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 9279{
ec8e098d
PB
9280 if ((GET_RTX_CLASS (code) != RTX_COMPARE
9281 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
9282 || GET_MODE_CLASS (mode) != MODE_CC)
9283 abort ();
9284
9285 /* These don't make sense. */
9286 if ((code == GT || code == LT || code == GE || code == LE)
9287 && mode == CCUNSmode)
9288 abort ();
9289
9290 if ((code == GTU || code == LTU || code == GEU || code == LEU)
9291 && mode != CCUNSmode)
9292 abort ();
9293
9294 if (mode != CCFPmode
9295 && (code == ORDERED || code == UNORDERED
9296 || code == UNEQ || code == LTGT
9297 || code == UNGT || code == UNLT
9298 || code == UNGE || code == UNLE))
a4f6c312 9299 abort ();
f676971a
EC
9300
9301 /* These should never be generated except for
bc9ec0e0 9302 flag_finite_math_only. */
39a10a29 9303 if (mode == CCFPmode
ad72b533 9304 && ! flag_finite_math_only
39a10a29
GK
9305 && (code == LE || code == GE
9306 || code == UNEQ || code == LTGT
9307 || code == UNGT || code == UNLT))
9308 abort ();
9309
9310 /* These are invalid; the information is not there. */
f676971a 9311 if (mode == CCEQmode
39a10a29
GK
9312 && code != EQ && code != NE)
9313 abort ();
9314}
9315
9878760c
RK
9316/* Return 1 if OP is a comparison operation that is valid for a branch insn.
9317 We only check the opcode against the mode of the CC value here. */
9318
9319int
a2369ed3 9320branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
9321{
9322 enum rtx_code code = GET_CODE (op);
9323 enum machine_mode cc_mode;
9324
ec8e098d 9325 if (!COMPARISON_P (op))
9878760c
RK
9326 return 0;
9327
9328 cc_mode = GET_MODE (XEXP (op, 0));
9329 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
9330 return 0;
9331
39a10a29 9332 validate_condition_mode (code, cc_mode);
9878760c 9333
39a10a29
GK
9334 return 1;
9335}
9336
9337/* Return 1 if OP is a comparison operation that is valid for a branch
9338 insn and which is true if the corresponding bit in the CC register
9339 is set. */
9340
9341int
a2369ed3 9342branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
9343{
9344 enum rtx_code code;
9345
8daf2e65 9346 if (! branch_comparison_operator (op, mode))
9878760c
RK
9347 return 0;
9348
39a10a29
GK
9349 code = GET_CODE (op);
9350 return (code == EQ || code == LT || code == GT
9351 || code == LTU || code == GTU
9352 || code == UNORDERED);
9878760c
RK
9353}
9354
b7053a3f
GK
9355/* Return 1 if OP is a comparison operation that is valid for an scc
9356 insn: it must be a positive comparison. */
9878760c
RK
9357
9358int
a2369ed3 9359scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 9360{
b7053a3f 9361 return branch_positive_comparison_operator (op, mode);
9878760c 9362}
e0cd0770
JC
9363
9364int
a2369ed3 9365trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
9366{
9367 if (mode != VOIDmode && mode != GET_MODE (op))
9368 return 0;
ec8e098d 9369 return COMPARISON_P (op);
e0cd0770 9370}
dfbdccdb
GK
9371
9372int
a2369ed3 9373boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
9374{
9375 enum rtx_code code = GET_CODE (op);
9376 return (code == AND || code == IOR || code == XOR);
9377}
1d328b19
GK
9378
9379int
a2369ed3 9380boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
9381{
9382 enum rtx_code code = GET_CODE (op);
9383 return (code == IOR || code == XOR);
9384}
50a0b056
GK
9385
9386int
a2369ed3 9387min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
9388{
9389 enum rtx_code code = GET_CODE (op);
9390 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
9391}
9878760c
RK
9392\f
9393/* Return 1 if ANDOP is a mask that has no bits on that are not in the
9394 mask required to convert the result of a rotate insn into a shift
b1765bde 9395 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
9396
9397int
a2369ed3 9398includes_lshift_p (rtx shiftop, rtx andop)
9878760c 9399{
e2c953b6
DE
9400 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9401
9402 shift_mask <<= INTVAL (shiftop);
9878760c 9403
b1765bde 9404 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
9405}
9406
9407/* Similar, but for right shift. */
9408
9409int
a2369ed3 9410includes_rshift_p (rtx shiftop, rtx andop)
9878760c 9411{
a7653a2c 9412 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
9413
9414 shift_mask >>= INTVAL (shiftop);
9415
b1765bde 9416 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
9417}
9418
c5059423
AM
9419/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
9420 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 9421 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
9422
9423int
a2369ed3 9424includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 9425{
c5059423
AM
9426 if (GET_CODE (andop) == CONST_INT)
9427 {
02071907 9428 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 9429
c5059423 9430 c = INTVAL (andop);
02071907 9431 if (c == 0 || c == ~0)
c5059423 9432 return 0;
e2c953b6 9433
02071907 9434 shift_mask = ~0;
c5059423
AM
9435 shift_mask <<= INTVAL (shiftop);
9436
b6d08ca1 9437 /* Find the least significant one bit. */
c5059423
AM
9438 lsb = c & -c;
9439
9440 /* It must coincide with the LSB of the shift mask. */
9441 if (-lsb != shift_mask)
9442 return 0;
e2c953b6 9443
c5059423
AM
9444 /* Invert to look for the next transition (if any). */
9445 c = ~c;
9446
9447 /* Remove the low group of ones (originally low group of zeros). */
9448 c &= -lsb;
9449
9450 /* Again find the lsb, and check we have all 1's above. */
9451 lsb = c & -c;
9452 return c == -lsb;
9453 }
9454 else if (GET_CODE (andop) == CONST_DOUBLE
9455 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9456 {
02071907
AM
9457 HOST_WIDE_INT low, high, lsb;
9458 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
9459
9460 low = CONST_DOUBLE_LOW (andop);
9461 if (HOST_BITS_PER_WIDE_INT < 64)
9462 high = CONST_DOUBLE_HIGH (andop);
9463
9464 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 9465 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
9466 return 0;
9467
9468 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9469 {
02071907 9470 shift_mask_high = ~0;
c5059423
AM
9471 if (INTVAL (shiftop) > 32)
9472 shift_mask_high <<= INTVAL (shiftop) - 32;
9473
9474 lsb = high & -high;
9475
9476 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
9477 return 0;
9478
9479 high = ~high;
9480 high &= -lsb;
9481
9482 lsb = high & -high;
9483 return high == -lsb;
9484 }
9485
02071907 9486 shift_mask_low = ~0;
c5059423
AM
9487 shift_mask_low <<= INTVAL (shiftop);
9488
9489 lsb = low & -low;
9490
9491 if (-lsb != shift_mask_low)
9492 return 0;
9493
9494 if (HOST_BITS_PER_WIDE_INT < 64)
9495 high = ~high;
9496 low = ~low;
9497 low &= -lsb;
9498
9499 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9500 {
9501 lsb = high & -high;
9502 return high == -lsb;
9503 }
9504
9505 lsb = low & -low;
9506 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
9507 }
9508 else
9509 return 0;
9510}
e2c953b6 9511
c5059423
AM
9512/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
9513 to perform a left shift. It must have SHIFTOP or more least
c1207243 9514 significant 0's, with the remainder of the word 1's. */
e2c953b6 9515
c5059423 9516int
a2369ed3 9517includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 9518{
e2c953b6 9519 if (GET_CODE (andop) == CONST_INT)
c5059423 9520 {
02071907 9521 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 9522
02071907 9523 shift_mask = ~0;
c5059423
AM
9524 shift_mask <<= INTVAL (shiftop);
9525 c = INTVAL (andop);
9526
c1207243 9527 /* Find the least significant one bit. */
c5059423
AM
9528 lsb = c & -c;
9529
9530 /* It must be covered by the shift mask.
a4f6c312 9531 This test also rejects c == 0. */
c5059423
AM
9532 if ((lsb & shift_mask) == 0)
9533 return 0;
9534
9535 /* Check we have all 1's above the transition, and reject all 1's. */
9536 return c == -lsb && lsb != 1;
9537 }
9538 else if (GET_CODE (andop) == CONST_DOUBLE
9539 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9540 {
02071907 9541 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
9542
9543 low = CONST_DOUBLE_LOW (andop);
9544
9545 if (HOST_BITS_PER_WIDE_INT < 64)
9546 {
02071907 9547 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
9548
9549 high = CONST_DOUBLE_HIGH (andop);
9550
9551 if (low == 0)
9552 {
02071907 9553 shift_mask_high = ~0;
c5059423
AM
9554 if (INTVAL (shiftop) > 32)
9555 shift_mask_high <<= INTVAL (shiftop) - 32;
9556
9557 lsb = high & -high;
9558
9559 if ((lsb & shift_mask_high) == 0)
9560 return 0;
9561
9562 return high == -lsb;
9563 }
9564 if (high != ~0)
9565 return 0;
9566 }
9567
02071907 9568 shift_mask_low = ~0;
c5059423
AM
9569 shift_mask_low <<= INTVAL (shiftop);
9570
9571 lsb = low & -low;
9572
9573 if ((lsb & shift_mask_low) == 0)
9574 return 0;
9575
9576 return low == -lsb && lsb != 1;
9577 }
e2c953b6 9578 else
c5059423 9579 return 0;
9878760c 9580}
35068b43 9581
11ac38b2
DE
9582/* Return 1 if operands will generate a valid arguments to rlwimi
9583instruction for insert with right shift in 64-bit mode. The mask may
9584not start on the first bit or stop on the last bit because wrap-around
9585effects of instruction do not correspond to semantics of RTL insn. */
9586
9587int
9588insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop)
9589{
9590 if (INTVAL (startop) < 64
9591 && INTVAL (startop) > 32
9592 && (INTVAL (sizeop) + INTVAL (startop) < 64)
9593 && (INTVAL (sizeop) + INTVAL (startop) > 33)
9594 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) < 96)
9595 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) >= 64)
9596 && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop))
9597 return 1;
9598
9599 return 0;
9600}
9601
35068b43 9602/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
90f81f99 9603 for lfq and stfq insns iff the registers are hard registers. */
35068b43
RK
9604
9605int
a2369ed3 9606registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
9607{
9608 /* We might have been passed a SUBREG. */
f676971a 9609 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
35068b43 9610 return 0;
f676971a 9611
90f81f99
AP
9612 /* We might have been passed non floating point registers. */
9613 if (!FP_REGNO_P (REGNO (reg1))
9614 || !FP_REGNO_P (REGNO (reg2)))
9615 return 0;
35068b43
RK
9616
9617 return (REGNO (reg1) == REGNO (reg2) - 1);
9618}
9619
a4f6c312
SS
9620/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
9621 addr1 and addr2 must be in consecutive memory locations
9622 (addr2 == addr1 + 8). */
35068b43
RK
9623
9624int
90f81f99 9625mems_ok_for_quad_peep (rtx mem1, rtx mem2)
35068b43 9626{
90f81f99 9627 rtx addr1, addr2;
e2c953b6 9628 unsigned int reg1;
35068b43
RK
9629 int offset1;
9630
90f81f99
AP
9631 /* The mems cannot be volatile. */
9632 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
9633 return 0;
f676971a 9634
90f81f99
AP
9635 addr1 = XEXP (mem1, 0);
9636 addr2 = XEXP (mem2, 0);
9637
35068b43
RK
9638 /* Extract an offset (if used) from the first addr. */
9639 if (GET_CODE (addr1) == PLUS)
9640 {
9641 /* If not a REG, return zero. */
9642 if (GET_CODE (XEXP (addr1, 0)) != REG)
9643 return 0;
9644 else
9645 {
c4ad648e 9646 reg1 = REGNO (XEXP (addr1, 0));
35068b43
RK
9647 /* The offset must be constant! */
9648 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
c4ad648e
AM
9649 return 0;
9650 offset1 = INTVAL (XEXP (addr1, 1));
35068b43
RK
9651 }
9652 }
9653 else if (GET_CODE (addr1) != REG)
9654 return 0;
9655 else
9656 {
9657 reg1 = REGNO (addr1);
9658 /* This was a simple (mem (reg)) expression. Offset is 0. */
9659 offset1 = 0;
9660 }
9661
a2369ed3 9662 /* Make sure the second address is a (mem (plus (reg) (const_int)))
f676971a 9663 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
0f6937fe 9664 register as addr1. */
984e25ac 9665 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 9666 return 1;
35068b43
RK
9667 if (GET_CODE (addr2) != PLUS)
9668 return 0;
9669
9670 if (GET_CODE (XEXP (addr2, 0)) != REG
9671 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
9672 return 0;
9673
9674 if (reg1 != REGNO (XEXP (addr2, 0)))
9675 return 0;
9676
9677 /* The offset for the second addr must be 8 more than the first addr. */
9678 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
9679 return 0;
9680
9681 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
9682 instructions. */
9683 return 1;
9684}
9878760c
RK
9685\f
9686/* Return the register class of a scratch register needed to copy IN into
9687 or out of a register in CLASS in MODE. If it can be done directly,
9688 NO_REGS is returned. */
9689
9690enum reg_class
f676971a 9691secondary_reload_class (enum reg_class class,
a9baceb1
GK
9692 enum machine_mode mode ATTRIBUTE_UNUSED,
9693 rtx in)
9878760c 9694{
5accd822 9695 int regno;
9878760c 9696
ab82a49f
AP
9697 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
9698#if TARGET_MACHO
c4ad648e 9699 && MACHOPIC_INDIRECT
ab82a49f 9700#endif
c4ad648e 9701 ))
46fad5b7
DJ
9702 {
9703 /* We cannot copy a symbolic operand directly into anything
c4ad648e
AM
9704 other than BASE_REGS for TARGET_ELF. So indicate that a
9705 register from BASE_REGS is needed as an intermediate
9706 register.
f676971a 9707
46fad5b7
DJ
9708 On Darwin, pic addresses require a load from memory, which
9709 needs a base register. */
9710 if (class != BASE_REGS
c4ad648e
AM
9711 && (GET_CODE (in) == SYMBOL_REF
9712 || GET_CODE (in) == HIGH
9713 || GET_CODE (in) == LABEL_REF
9714 || GET_CODE (in) == CONST))
9715 return BASE_REGS;
46fad5b7 9716 }
e7b7998a 9717
5accd822
DE
9718 if (GET_CODE (in) == REG)
9719 {
9720 regno = REGNO (in);
9721 if (regno >= FIRST_PSEUDO_REGISTER)
9722 {
9723 regno = true_regnum (in);
9724 if (regno >= FIRST_PSEUDO_REGISTER)
9725 regno = -1;
9726 }
9727 }
9728 else if (GET_CODE (in) == SUBREG)
9729 {
9730 regno = true_regnum (in);
9731 if (regno >= FIRST_PSEUDO_REGISTER)
9732 regno = -1;
9733 }
9734 else
9735 regno = -1;
9736
9878760c
RK
9737 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
9738 into anything. */
9739 if (class == GENERAL_REGS || class == BASE_REGS
9740 || (regno >= 0 && INT_REGNO_P (regno)))
9741 return NO_REGS;
9742
9743 /* Constants, memory, and FP registers can go into FP registers. */
9744 if ((regno == -1 || FP_REGNO_P (regno))
9745 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
9746 return NO_REGS;
9747
0ac081f6
AH
9748 /* Memory, and AltiVec registers can go into AltiVec registers. */
9749 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
9750 && class == ALTIVEC_REGS)
9751 return NO_REGS;
9752
9878760c
RK
9753 /* We can copy among the CR registers. */
9754 if ((class == CR_REGS || class == CR0_REGS)
9755 && regno >= 0 && CR_REGNO_P (regno))
9756 return NO_REGS;
9757
9758 /* Otherwise, we need GENERAL_REGS. */
9759 return GENERAL_REGS;
9760}
9761\f
9762/* Given a comparison operation, return the bit number in CCR to test. We
f676971a 9763 know this is a valid comparison.
9878760c
RK
9764
9765 SCC_P is 1 if this is for an scc. That means that %D will have been
9766 used instead of %C, so the bits will be in different places.
9767
b4ac57ab 9768 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
9769
9770int
a2369ed3 9771ccr_bit (rtx op, int scc_p)
9878760c
RK
9772{
9773 enum rtx_code code = GET_CODE (op);
9774 enum machine_mode cc_mode;
9775 int cc_regnum;
9776 int base_bit;
9ebbca7d 9777 rtx reg;
9878760c 9778
ec8e098d 9779 if (!COMPARISON_P (op))
9878760c
RK
9780 return -1;
9781
9ebbca7d
GK
9782 reg = XEXP (op, 0);
9783
9784 if (GET_CODE (reg) != REG
9785 || ! CR_REGNO_P (REGNO (reg)))
9786 abort ();
9787
9788 cc_mode = GET_MODE (reg);
9789 cc_regnum = REGNO (reg);
9790 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 9791
39a10a29 9792 validate_condition_mode (code, cc_mode);
c5defebb 9793
b7053a3f
GK
9794 /* When generating a sCOND operation, only positive conditions are
9795 allowed. */
9796 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
9797 && code != GTU && code != LTU)
9798 abort ();
f676971a 9799
9878760c
RK
9800 switch (code)
9801 {
9802 case NE:
9803 return scc_p ? base_bit + 3 : base_bit + 2;
9804 case EQ:
9805 return base_bit + 2;
1c882ea4 9806 case GT: case GTU: case UNLE:
9878760c 9807 return base_bit + 1;
1c882ea4 9808 case LT: case LTU: case UNGE:
9878760c 9809 return base_bit;
1c882ea4
GK
9810 case ORDERED: case UNORDERED:
9811 return base_bit + 3;
9878760c
RK
9812
9813 case GE: case GEU:
39a10a29 9814 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
9815 unordered position. So test that bit. For integer, this is ! LT
9816 unless this is an scc insn. */
39a10a29 9817 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
9818
9819 case LE: case LEU:
39a10a29 9820 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 9821
9878760c
RK
9822 default:
9823 abort ();
9824 }
9825}
1ff7789b 9826\f
8d30c4ee 9827/* Return the GOT register. */
1ff7789b
MM
9828
9829struct rtx_def *
a2369ed3 9830rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 9831{
a4f6c312
SS
9832 /* The second flow pass currently (June 1999) can't update
9833 regs_ever_live without disturbing other parts of the compiler, so
9834 update it here to make the prolog/epilogue code happy. */
1db02437
FS
9835 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
9836 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 9837
8d30c4ee 9838 current_function_uses_pic_offset_table = 1;
3cb999d8 9839
1ff7789b
MM
9840 return pic_offset_table_rtx;
9841}
a7df97e6 9842\f
e2500fed
GK
9843/* Function to init struct machine_function.
9844 This will be called, via a pointer variable,
9845 from push_function_context. */
a7df97e6 9846
e2500fed 9847static struct machine_function *
863d938c 9848rs6000_init_machine_status (void)
a7df97e6 9849{
e2500fed 9850 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 9851}
9878760c 9852\f
0ba1b2ff
AM
9853/* These macros test for integers and extract the low-order bits. */
9854#define INT_P(X) \
9855((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
9856 && GET_MODE (X) == VOIDmode)
9857
9858#define INT_LOWPART(X) \
9859 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
9860
9861int
a2369ed3 9862extract_MB (rtx op)
0ba1b2ff
AM
9863{
9864 int i;
9865 unsigned long val = INT_LOWPART (op);
9866
9867 /* If the high bit is zero, the value is the first 1 bit we find
9868 from the left. */
9869 if ((val & 0x80000000) == 0)
9870 {
9871 if ((val & 0xffffffff) == 0)
9872 abort ();
9873
9874 i = 1;
9875 while (((val <<= 1) & 0x80000000) == 0)
9876 ++i;
9877 return i;
9878 }
9879
9880 /* If the high bit is set and the low bit is not, or the mask is all
9881 1's, the value is zero. */
9882 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
9883 return 0;
9884
9885 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9886 from the right. */
9887 i = 31;
9888 while (((val >>= 1) & 1) != 0)
9889 --i;
9890
9891 return i;
9892}
9893
9894int
a2369ed3 9895extract_ME (rtx op)
0ba1b2ff
AM
9896{
9897 int i;
9898 unsigned long val = INT_LOWPART (op);
9899
9900 /* If the low bit is zero, the value is the first 1 bit we find from
9901 the right. */
9902 if ((val & 1) == 0)
9903 {
9904 if ((val & 0xffffffff) == 0)
9905 abort ();
9906
9907 i = 30;
9908 while (((val >>= 1) & 1) == 0)
9909 --i;
9910
9911 return i;
9912 }
9913
9914 /* If the low bit is set and the high bit is not, or the mask is all
9915 1's, the value is 31. */
9916 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
9917 return 31;
9918
9919 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9920 from the left. */
9921 i = 0;
9922 while (((val <<= 1) & 0x80000000) != 0)
9923 ++i;
9924
9925 return i;
9926}
9927
c4501e62
JJ
9928/* Locate some local-dynamic symbol still in use by this function
9929 so that we can print its name in some tls_ld pattern. */
9930
9931static const char *
863d938c 9932rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
9933{
9934 rtx insn;
9935
9936 if (cfun->machine->some_ld_name)
9937 return cfun->machine->some_ld_name;
9938
9939 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
9940 if (INSN_P (insn)
9941 && for_each_rtx (&PATTERN (insn),
9942 rs6000_get_some_local_dynamic_name_1, 0))
9943 return cfun->machine->some_ld_name;
9944
9945 abort ();
9946}
9947
9948/* Helper function for rs6000_get_some_local_dynamic_name. */
9949
9950static int
a2369ed3 9951rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
9952{
9953 rtx x = *px;
9954
9955 if (GET_CODE (x) == SYMBOL_REF)
9956 {
9957 const char *str = XSTR (x, 0);
9958 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
9959 {
9960 cfun->machine->some_ld_name = str;
9961 return 1;
9962 }
9963 }
9964
9965 return 0;
9966}
9967
85b776df
AM
9968/* Write out a function code label. */
9969
9970void
9971rs6000_output_function_entry (FILE *file, const char *fname)
9972{
9973 if (fname[0] != '.')
9974 {
9975 switch (DEFAULT_ABI)
9976 {
9977 default:
9978 abort ();
9979
9980 case ABI_AIX:
9981 if (DOT_SYMBOLS)
9982 putc ('.', file);
9983 else
9984 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "L.");
9985 break;
9986
9987 case ABI_V4:
9988 case ABI_DARWIN:
9989 break;
9990 }
9991 }
9992 if (TARGET_AIX)
9993 RS6000_OUTPUT_BASENAME (file, fname);
9994 else
9995 assemble_name (file, fname);
9996}
9997
9878760c
RK
9998/* Print an operand. Recognize special options, documented below. */
9999
38c1f2d7 10000#if TARGET_ELF
d9407988 10001#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 10002#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
10003#else
10004#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 10005#define SMALL_DATA_REG 0
ba5e43aa
MM
10006#endif
10007
9878760c 10008void
a2369ed3 10009print_operand (FILE *file, rtx x, int code)
9878760c
RK
10010{
10011 int i;
a260abc9 10012 HOST_WIDE_INT val;
0ba1b2ff 10013 unsigned HOST_WIDE_INT uval;
9878760c
RK
10014
10015 switch (code)
10016 {
a8b3aeda 10017 case '.':
a85d226b
RK
10018 /* Write out an instruction after the call which may be replaced
10019 with glue code by the loader. This depends on the AIX version. */
10020 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
10021 return;
10022
81eace42
GK
10023 /* %a is output_address. */
10024
9854d9ed
RK
10025 case 'A':
10026 /* If X is a constant integer whose low-order 5 bits are zero,
10027 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 10028 in the AIX assembler where "sri" with a zero shift count
20e26713 10029 writes a trash instruction. */
9854d9ed 10030 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 10031 putc ('l', file);
9854d9ed 10032 else
76229ac8 10033 putc ('r', file);
9854d9ed
RK
10034 return;
10035
10036 case 'b':
e2c953b6
DE
10037 /* If constant, low-order 16 bits of constant, unsigned.
10038 Otherwise, write normally. */
10039 if (INT_P (x))
10040 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
10041 else
10042 print_operand (file, x, 0);
cad12a8d
RK
10043 return;
10044
a260abc9
DE
10045 case 'B':
10046 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
10047 for 64-bit mask direction. */
296b8152 10048 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 10049 return;
a260abc9 10050
81eace42
GK
10051 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
10052 output_operand. */
10053
423c1189
AH
10054 case 'c':
10055 /* X is a CR register. Print the number of the GT bit of the CR. */
10056 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10057 output_operand_lossage ("invalid %%E value");
10058 else
10059 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1);
10060 return;
10061
10062 case 'D':
6b1fedc3 10063 /* Like 'J' but get to the EQ bit. */
423c1189
AH
10064 if (GET_CODE (x) != REG)
10065 abort ();
10066
6b1fedc3
AH
10067 /* Bit 1 is EQ bit. */
10068 i = 4 * (REGNO (x) - CR0_REGNO) + 2;
423c1189
AH
10069
10070 /* If we want bit 31, write a shift count of zero, not 32. */
10071 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10072 return;
10073
9854d9ed 10074 case 'E':
39a10a29 10075 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
10076 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10077 output_operand_lossage ("invalid %%E value");
78fbdbf7 10078 else
39a10a29 10079 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 10080 return;
9854d9ed
RK
10081
10082 case 'f':
10083 /* X is a CR register. Print the shift count needed to move it
10084 to the high-order four bits. */
10085 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10086 output_operand_lossage ("invalid %%f value");
10087 else
9ebbca7d 10088 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
10089 return;
10090
10091 case 'F':
10092 /* Similar, but print the count for the rotate in the opposite
10093 direction. */
10094 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10095 output_operand_lossage ("invalid %%F value");
10096 else
9ebbca7d 10097 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
10098 return;
10099
10100 case 'G':
10101 /* X is a constant integer. If it is negative, print "m",
43aa4e05 10102 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
10103 if (GET_CODE (x) != CONST_INT)
10104 output_operand_lossage ("invalid %%G value");
10105 else if (INTVAL (x) >= 0)
76229ac8 10106 putc ('z', file);
9854d9ed 10107 else
76229ac8 10108 putc ('m', file);
9854d9ed 10109 return;
e2c953b6 10110
9878760c 10111 case 'h':
a4f6c312
SS
10112 /* If constant, output low-order five bits. Otherwise, write
10113 normally. */
9878760c 10114 if (INT_P (x))
5f59ecb7 10115 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
10116 else
10117 print_operand (file, x, 0);
10118 return;
10119
64305719 10120 case 'H':
a4f6c312
SS
10121 /* If constant, output low-order six bits. Otherwise, write
10122 normally. */
64305719 10123 if (INT_P (x))
5f59ecb7 10124 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
10125 else
10126 print_operand (file, x, 0);
10127 return;
10128
9854d9ed
RK
10129 case 'I':
10130 /* Print `i' if this is a constant, else nothing. */
9878760c 10131 if (INT_P (x))
76229ac8 10132 putc ('i', file);
9878760c
RK
10133 return;
10134
9854d9ed
RK
10135 case 'j':
10136 /* Write the bit number in CCR for jump. */
10137 i = ccr_bit (x, 0);
10138 if (i == -1)
10139 output_operand_lossage ("invalid %%j code");
9878760c 10140 else
9854d9ed 10141 fprintf (file, "%d", i);
9878760c
RK
10142 return;
10143
9854d9ed
RK
10144 case 'J':
10145 /* Similar, but add one for shift count in rlinm for scc and pass
10146 scc flag to `ccr_bit'. */
10147 i = ccr_bit (x, 1);
10148 if (i == -1)
10149 output_operand_lossage ("invalid %%J code");
10150 else
a0466a68
RK
10151 /* If we want bit 31, write a shift count of zero, not 32. */
10152 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
10153 return;
10154
9854d9ed
RK
10155 case 'k':
10156 /* X must be a constant. Write the 1's complement of the
10157 constant. */
9878760c 10158 if (! INT_P (x))
9854d9ed 10159 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
10160 else
10161 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
10162 return;
10163
81eace42 10164 case 'K':
9ebbca7d
GK
10165 /* X must be a symbolic constant on ELF. Write an
10166 expression suitable for an 'addi' that adds in the low 16
10167 bits of the MEM. */
10168 if (GET_CODE (x) != CONST)
10169 {
10170 print_operand_address (file, x);
10171 fputs ("@l", file);
10172 }
10173 else
10174 {
10175 if (GET_CODE (XEXP (x, 0)) != PLUS
10176 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
10177 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
10178 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 10179 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
10180 print_operand_address (file, XEXP (XEXP (x, 0), 0));
10181 fputs ("@l", file);
ed8d2920
MM
10182 /* For GNU as, there must be a non-alphanumeric character
10183 between 'l' and the number. The '-' is added by
10184 print_operand() already. */
10185 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
10186 fputs ("+", file);
9ebbca7d
GK
10187 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
10188 }
81eace42
GK
10189 return;
10190
10191 /* %l is output_asm_label. */
9ebbca7d 10192
9854d9ed
RK
10193 case 'L':
10194 /* Write second word of DImode or DFmode reference. Works on register
10195 or non-indexed memory only. */
10196 if (GET_CODE (x) == REG)
fb5c67a7 10197 fputs (reg_names[REGNO (x) + 1], file);
9854d9ed
RK
10198 else if (GET_CODE (x) == MEM)
10199 {
10200 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 10201 we have already done it, we can just use an offset of word. */
9854d9ed
RK
10202 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10203 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
10204 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
10205 UNITS_PER_WORD));
9854d9ed 10206 else
d7624dc0
RK
10207 output_address (XEXP (adjust_address_nv (x, SImode,
10208 UNITS_PER_WORD),
10209 0));
ed8908e7 10210
ba5e43aa 10211 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10212 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10213 reg_names[SMALL_DATA_REG]);
9854d9ed 10214 }
9878760c 10215 return;
f676971a 10216
9878760c
RK
10217 case 'm':
10218 /* MB value for a mask operand. */
b1765bde 10219 if (! mask_operand (x, SImode))
9878760c
RK
10220 output_operand_lossage ("invalid %%m value");
10221
0ba1b2ff 10222 fprintf (file, "%d", extract_MB (x));
9878760c
RK
10223 return;
10224
10225 case 'M':
10226 /* ME value for a mask operand. */
b1765bde 10227 if (! mask_operand (x, SImode))
a260abc9 10228 output_operand_lossage ("invalid %%M value");
9878760c 10229
0ba1b2ff 10230 fprintf (file, "%d", extract_ME (x));
9878760c
RK
10231 return;
10232
81eace42
GK
10233 /* %n outputs the negative of its operand. */
10234
9878760c
RK
10235 case 'N':
10236 /* Write the number of elements in the vector times 4. */
10237 if (GET_CODE (x) != PARALLEL)
10238 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
10239 else
10240 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
10241 return;
10242
10243 case 'O':
10244 /* Similar, but subtract 1 first. */
10245 if (GET_CODE (x) != PARALLEL)
1427100a 10246 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
10247 else
10248 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
10249 return;
10250
9854d9ed
RK
10251 case 'p':
10252 /* X is a CONST_INT that is a power of two. Output the logarithm. */
10253 if (! INT_P (x)
2bfcf297 10254 || INT_LOWPART (x) < 0
9854d9ed
RK
10255 || (i = exact_log2 (INT_LOWPART (x))) < 0)
10256 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
10257 else
10258 fprintf (file, "%d", i);
9854d9ed
RK
10259 return;
10260
9878760c
RK
10261 case 'P':
10262 /* The operand must be an indirect memory reference. The result
8bb418a3 10263 is the register name. */
9878760c
RK
10264 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
10265 || REGNO (XEXP (x, 0)) >= 32)
10266 output_operand_lossage ("invalid %%P value");
e2c953b6 10267 else
fb5c67a7 10268 fputs (reg_names[REGNO (XEXP (x, 0))], file);
9878760c
RK
10269 return;
10270
dfbdccdb
GK
10271 case 'q':
10272 /* This outputs the logical code corresponding to a boolean
10273 expression. The expression may have one or both operands
39a10a29 10274 negated (if one, only the first one). For condition register
c4ad648e
AM
10275 logical operations, it will also treat the negated
10276 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 10277 {
63bc1d05 10278 const char *const *t = 0;
dfbdccdb
GK
10279 const char *s;
10280 enum rtx_code code = GET_CODE (x);
10281 static const char * const tbl[3][3] = {
10282 { "and", "andc", "nor" },
10283 { "or", "orc", "nand" },
10284 { "xor", "eqv", "xor" } };
10285
10286 if (code == AND)
10287 t = tbl[0];
10288 else if (code == IOR)
10289 t = tbl[1];
10290 else if (code == XOR)
10291 t = tbl[2];
10292 else
10293 output_operand_lossage ("invalid %%q value");
10294
10295 if (GET_CODE (XEXP (x, 0)) != NOT)
10296 s = t[0];
10297 else
10298 {
10299 if (GET_CODE (XEXP (x, 1)) == NOT)
10300 s = t[2];
10301 else
10302 s = t[1];
10303 }
f676971a 10304
dfbdccdb
GK
10305 fputs (s, file);
10306 }
10307 return;
10308
2c4a9cff
DE
10309 case 'Q':
10310 if (TARGET_MFCRF)
3b6ce0af 10311 fputc (',', file);
5efb1046 10312 /* FALLTHRU */
2c4a9cff
DE
10313 else
10314 return;
10315
9854d9ed
RK
10316 case 'R':
10317 /* X is a CR register. Print the mask for `mtcrf'. */
10318 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10319 output_operand_lossage ("invalid %%R value");
10320 else
9ebbca7d 10321 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 10322 return;
9854d9ed
RK
10323
10324 case 's':
10325 /* Low 5 bits of 32 - value */
10326 if (! INT_P (x))
10327 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
10328 else
10329 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 10330 return;
9854d9ed 10331
a260abc9 10332 case 'S':
0ba1b2ff 10333 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
10334 CONST_INT 32-bit mask is considered sign-extended so any
10335 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 10336 if (! mask64_operand (x, DImode))
a260abc9
DE
10337 output_operand_lossage ("invalid %%S value");
10338
0ba1b2ff 10339 uval = INT_LOWPART (x);
a260abc9 10340
0ba1b2ff 10341 if (uval & 1) /* Clear Left */
a260abc9 10342 {
f099d360
GK
10343#if HOST_BITS_PER_WIDE_INT > 64
10344 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10345#endif
0ba1b2ff 10346 i = 64;
a260abc9 10347 }
0ba1b2ff 10348 else /* Clear Right */
a260abc9 10349 {
0ba1b2ff 10350 uval = ~uval;
f099d360
GK
10351#if HOST_BITS_PER_WIDE_INT > 64
10352 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10353#endif
0ba1b2ff 10354 i = 63;
a260abc9 10355 }
0ba1b2ff
AM
10356 while (uval != 0)
10357 --i, uval >>= 1;
10358 if (i < 0)
10359 abort ();
10360 fprintf (file, "%d", i);
10361 return;
a260abc9 10362
a3170dc6
AH
10363 case 't':
10364 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
10365 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
10366 abort ();
10367
10368 /* Bit 3 is OV bit. */
10369 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
10370
10371 /* If we want bit 31, write a shift count of zero, not 32. */
10372 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10373 return;
10374
cccf3bdc
DE
10375 case 'T':
10376 /* Print the symbolic name of a branch target register. */
10377 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
10378 && REGNO (x) != COUNT_REGISTER_REGNUM))
10379 output_operand_lossage ("invalid %%T value");
e2c953b6 10380 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
10381 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
10382 else
10383 fputs ("ctr", file);
10384 return;
10385
9854d9ed 10386 case 'u':
802a0058 10387 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
10388 if (! INT_P (x))
10389 output_operand_lossage ("invalid %%u value");
e2c953b6 10390 else
f676971a 10391 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
e2c953b6 10392 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
10393 return;
10394
802a0058
MM
10395 case 'v':
10396 /* High-order 16 bits of constant for use in signed operand. */
10397 if (! INT_P (x))
10398 output_operand_lossage ("invalid %%v value");
e2c953b6 10399 else
134c32f6
DE
10400 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
10401 (INT_LOWPART (x) >> 16) & 0xffff);
10402 return;
802a0058 10403
9854d9ed
RK
10404 case 'U':
10405 /* Print `u' if this has an auto-increment or auto-decrement. */
10406 if (GET_CODE (x) == MEM
10407 && (GET_CODE (XEXP (x, 0)) == PRE_INC
10408 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 10409 putc ('u', file);
9854d9ed 10410 return;
9878760c 10411
e0cd0770
JC
10412 case 'V':
10413 /* Print the trap code for this operand. */
10414 switch (GET_CODE (x))
10415 {
10416 case EQ:
10417 fputs ("eq", file); /* 4 */
10418 break;
10419 case NE:
10420 fputs ("ne", file); /* 24 */
10421 break;
10422 case LT:
10423 fputs ("lt", file); /* 16 */
10424 break;
10425 case LE:
10426 fputs ("le", file); /* 20 */
10427 break;
10428 case GT:
10429 fputs ("gt", file); /* 8 */
10430 break;
10431 case GE:
10432 fputs ("ge", file); /* 12 */
10433 break;
10434 case LTU:
10435 fputs ("llt", file); /* 2 */
10436 break;
10437 case LEU:
10438 fputs ("lle", file); /* 6 */
10439 break;
10440 case GTU:
10441 fputs ("lgt", file); /* 1 */
10442 break;
10443 case GEU:
10444 fputs ("lge", file); /* 5 */
10445 break;
10446 default:
10447 abort ();
10448 }
10449 break;
10450
9854d9ed
RK
10451 case 'w':
10452 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
10453 normally. */
10454 if (INT_P (x))
f676971a 10455 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5f59ecb7 10456 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
10457 else
10458 print_operand (file, x, 0);
9878760c
RK
10459 return;
10460
9854d9ed 10461 case 'W':
e2c953b6 10462 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
10463 val = (GET_CODE (x) == CONST_INT
10464 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
10465
10466 if (val < 0)
10467 i = -1;
9854d9ed 10468 else
e2c953b6
DE
10469 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
10470 if ((val <<= 1) < 0)
10471 break;
10472
10473#if HOST_BITS_PER_WIDE_INT == 32
10474 if (GET_CODE (x) == CONST_INT && i >= 0)
10475 i += 32; /* zero-extend high-part was all 0's */
10476 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
10477 {
10478 val = CONST_DOUBLE_LOW (x);
10479
10480 if (val == 0)
a4f6c312 10481 abort ();
e2c953b6
DE
10482 else if (val < 0)
10483 --i;
10484 else
10485 for ( ; i < 64; i++)
10486 if ((val <<= 1) < 0)
10487 break;
10488 }
10489#endif
10490
10491 fprintf (file, "%d", i + 1);
9854d9ed 10492 return;
9878760c 10493
9854d9ed
RK
10494 case 'X':
10495 if (GET_CODE (x) == MEM
4d588c14 10496 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 10497 putc ('x', file);
9854d9ed 10498 return;
9878760c 10499
9854d9ed
RK
10500 case 'Y':
10501 /* Like 'L', for third word of TImode */
10502 if (GET_CODE (x) == REG)
fb5c67a7 10503 fputs (reg_names[REGNO (x) + 2], file);
9854d9ed 10504 else if (GET_CODE (x) == MEM)
9878760c 10505 {
9854d9ed
RK
10506 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10507 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10508 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 10509 else
d7624dc0 10510 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 10511 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10512 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10513 reg_names[SMALL_DATA_REG]);
9878760c
RK
10514 }
10515 return;
f676971a 10516
9878760c 10517 case 'z':
b4ac57ab
RS
10518 /* X is a SYMBOL_REF. Write out the name preceded by a
10519 period and without any trailing data in brackets. Used for function
4d30c363
MM
10520 names. If we are configured for System V (or the embedded ABI) on
10521 the PowerPC, do not emit the period, since those systems do not use
10522 TOCs and the like. */
9878760c
RK
10523 if (GET_CODE (x) != SYMBOL_REF)
10524 abort ();
10525
c4ad648e
AM
10526 /* Mark the decl as referenced so that cgraph will output the
10527 function. */
9bf6462a 10528 if (SYMBOL_REF_DECL (x))
c4ad648e 10529 mark_decl_referenced (SYMBOL_REF_DECL (x));
9bf6462a 10530
85b776df 10531 /* For macho, check to see if we need a stub. */
f9da97f0
AP
10532 if (TARGET_MACHO)
10533 {
10534 const char *name = XSTR (x, 0);
a031e781 10535#if TARGET_MACHO
3b48085e 10536 if (MACHOPIC_INDIRECT
11abc112
MM
10537 && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10538 name = machopic_indirection_name (x, /*stub_p=*/true);
f9da97f0
AP
10539#endif
10540 assemble_name (file, name);
10541 }
85b776df 10542 else if (!DOT_SYMBOLS)
9739c90c 10543 assemble_name (file, XSTR (x, 0));
85b776df
AM
10544 else
10545 rs6000_output_function_entry (file, XSTR (x, 0));
9878760c
RK
10546 return;
10547
9854d9ed
RK
10548 case 'Z':
10549 /* Like 'L', for last word of TImode. */
10550 if (GET_CODE (x) == REG)
fb5c67a7 10551 fputs (reg_names[REGNO (x) + 3], file);
9854d9ed
RK
10552 else if (GET_CODE (x) == MEM)
10553 {
10554 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10555 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10556 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 10557 else
d7624dc0 10558 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 10559 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10560 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10561 reg_names[SMALL_DATA_REG]);
9854d9ed 10562 }
5c23c401 10563 return;
0ac081f6 10564
a3170dc6 10565 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
10566 case 'y':
10567 {
10568 rtx tmp;
10569
10570 if (GET_CODE (x) != MEM)
10571 abort ();
10572
10573 tmp = XEXP (x, 0);
10574
993f19a8 10575 if (TARGET_E500)
a3170dc6
AH
10576 {
10577 /* Handle [reg]. */
10578 if (GET_CODE (tmp) == REG)
10579 {
10580 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
10581 break;
10582 }
10583 /* Handle [reg+UIMM]. */
10584 else if (GET_CODE (tmp) == PLUS &&
10585 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
10586 {
10587 int x;
10588
10589 if (GET_CODE (XEXP (tmp, 0)) != REG)
10590 abort ();
10591
10592 x = INTVAL (XEXP (tmp, 1));
10593 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
10594 break;
10595 }
10596
10597 /* Fall through. Must be [reg+reg]. */
10598 }
850e8d3d
DN
10599 if (TARGET_ALTIVEC
10600 && GET_CODE (tmp) == AND
10601 && GET_CODE (XEXP (tmp, 1)) == CONST_INT
10602 && INTVAL (XEXP (tmp, 1)) == -16)
10603 tmp = XEXP (tmp, 0);
0ac081f6 10604 if (GET_CODE (tmp) == REG)
c62f2db5 10605 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
10606 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
10607 {
10608 if (REGNO (XEXP (tmp, 0)) == 0)
10609 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
10610 reg_names[ REGNO (XEXP (tmp, 0)) ]);
10611 else
10612 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
10613 reg_names[ REGNO (XEXP (tmp, 1)) ]);
10614 }
10615 else
10616 abort ();
10617 break;
10618 }
f676971a 10619
9878760c
RK
10620 case 0:
10621 if (GET_CODE (x) == REG)
10622 fprintf (file, "%s", reg_names[REGNO (x)]);
10623 else if (GET_CODE (x) == MEM)
10624 {
10625 /* We need to handle PRE_INC and PRE_DEC here, since we need to
10626 know the width from the mode. */
10627 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
10628 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
10629 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10630 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
10631 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
10632 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10633 else
a54d04b7 10634 output_address (XEXP (x, 0));
9878760c
RK
10635 }
10636 else
a54d04b7 10637 output_addr_const (file, x);
a85d226b 10638 return;
9878760c 10639
c4501e62
JJ
10640 case '&':
10641 assemble_name (file, rs6000_get_some_local_dynamic_name ());
10642 return;
10643
9878760c
RK
10644 default:
10645 output_operand_lossage ("invalid %%xn code");
10646 }
10647}
10648\f
10649/* Print the address of an operand. */
10650
10651void
a2369ed3 10652print_operand_address (FILE *file, rtx x)
9878760c
RK
10653{
10654 if (GET_CODE (x) == REG)
4697a36c 10655 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
10656 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
10657 || GET_CODE (x) == LABEL_REF)
9878760c
RK
10658 {
10659 output_addr_const (file, x);
ba5e43aa 10660 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10661 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10662 reg_names[SMALL_DATA_REG]);
9ebbca7d 10663 else if (TARGET_TOC)
a4f6c312 10664 abort ();
9878760c
RK
10665 }
10666 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
10667 {
10668 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
10669 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
10670 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 10671 else
4697a36c
MM
10672 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
10673 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
10674 }
10675 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
10676 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
10677 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
10678#if TARGET_ELF
10679 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
c4ad648e 10680 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
10681 {
10682 output_addr_const (file, XEXP (x, 1));
10683 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10684 }
c859cda6
DJ
10685#endif
10686#if TARGET_MACHO
10687 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
c4ad648e 10688 && CONSTANT_P (XEXP (x, 1)))
c859cda6
DJ
10689 {
10690 fprintf (file, "lo16(");
10691 output_addr_const (file, XEXP (x, 1));
10692 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10693 }
3cb999d8 10694#endif
4d588c14 10695 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 10696 {
2bfcf297 10697 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 10698 {
2bfcf297
DB
10699 rtx contains_minus = XEXP (x, 1);
10700 rtx minus, symref;
10701 const char *name;
f676971a 10702
9ebbca7d 10703 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 10704 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
10705 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
10706 contains_minus = XEXP (contains_minus, 0);
10707
2bfcf297
DB
10708 minus = XEXP (contains_minus, 0);
10709 symref = XEXP (minus, 0);
10710 XEXP (contains_minus, 0) = symref;
10711 if (TARGET_ELF)
10712 {
10713 char *newname;
10714
10715 name = XSTR (symref, 0);
10716 newname = alloca (strlen (name) + sizeof ("@toc"));
10717 strcpy (newname, name);
10718 strcat (newname, "@toc");
10719 XSTR (symref, 0) = newname;
10720 }
10721 output_addr_const (file, XEXP (x, 1));
10722 if (TARGET_ELF)
10723 XSTR (symref, 0) = name;
9ebbca7d
GK
10724 XEXP (contains_minus, 0) = minus;
10725 }
10726 else
10727 output_addr_const (file, XEXP (x, 1));
10728
10729 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
10730 }
9878760c
RK
10731 else
10732 abort ();
10733}
10734\f
88cad84b 10735/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
10736 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
10737 is defined. It also needs to handle DI-mode objects on 64-bit
10738 targets. */
10739
10740static bool
a2369ed3 10741rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
10742{
10743#ifdef RELOCATABLE_NEEDS_FIXUP
10744 /* Special handling for SI values. */
10745 if (size == 4 && aligned_p)
10746 {
a2369ed3 10747 extern int in_toc_section (void);
301d03af 10748 static int recurse = 0;
f676971a 10749
301d03af
RS
10750 /* For -mrelocatable, we mark all addresses that need to be fixed up
10751 in the .fixup section. */
10752 if (TARGET_RELOCATABLE
10753 && !in_toc_section ()
10754 && !in_text_section ()
642af3be 10755 && !in_unlikely_text_section ()
301d03af
RS
10756 && !recurse
10757 && GET_CODE (x) != CONST_INT
10758 && GET_CODE (x) != CONST_DOUBLE
10759 && CONSTANT_P (x))
10760 {
10761 char buf[256];
10762
10763 recurse = 1;
10764 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
10765 fixuplabelno++;
10766 ASM_OUTPUT_LABEL (asm_out_file, buf);
10767 fprintf (asm_out_file, "\t.long\t(");
10768 output_addr_const (asm_out_file, x);
10769 fprintf (asm_out_file, ")@fixup\n");
10770 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
10771 ASM_OUTPUT_ALIGN (asm_out_file, 2);
10772 fprintf (asm_out_file, "\t.long\t");
10773 assemble_name (asm_out_file, buf);
10774 fprintf (asm_out_file, "\n\t.previous\n");
10775 recurse = 0;
10776 return true;
10777 }
10778 /* Remove initial .'s to turn a -mcall-aixdesc function
10779 address into the address of the descriptor, not the function
10780 itself. */
10781 else if (GET_CODE (x) == SYMBOL_REF
10782 && XSTR (x, 0)[0] == '.'
10783 && DEFAULT_ABI == ABI_AIX)
10784 {
10785 const char *name = XSTR (x, 0);
10786 while (*name == '.')
10787 name++;
10788
10789 fprintf (asm_out_file, "\t.long\t%s\n", name);
10790 return true;
10791 }
10792 }
10793#endif /* RELOCATABLE_NEEDS_FIXUP */
10794 return default_assemble_integer (x, size, aligned_p);
10795}
93638d7a
AM
10796
10797#ifdef HAVE_GAS_HIDDEN
10798/* Emit an assembler directive to set symbol visibility for DECL to
10799 VISIBILITY_TYPE. */
10800
5add3202 10801static void
a2369ed3 10802rs6000_assemble_visibility (tree decl, int vis)
93638d7a 10803{
93638d7a
AM
10804 /* Functions need to have their entry point symbol visibility set as
10805 well as their descriptor symbol visibility. */
85b776df
AM
10806 if (DEFAULT_ABI == ABI_AIX
10807 && DOT_SYMBOLS
10808 && TREE_CODE (decl) == FUNCTION_DECL)
93638d7a 10809 {
25fdb4dc 10810 static const char * const visibility_types[] = {
c4ad648e 10811 NULL, "internal", "hidden", "protected"
25fdb4dc
RH
10812 };
10813
10814 const char *name, *type;
93638d7a
AM
10815
10816 name = ((* targetm.strip_name_encoding)
10817 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 10818 type = visibility_types[vis];
93638d7a 10819
25fdb4dc
RH
10820 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
10821 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 10822 }
25fdb4dc
RH
10823 else
10824 default_assemble_visibility (decl, vis);
93638d7a
AM
10825}
10826#endif
301d03af 10827\f
39a10a29 10828enum rtx_code
a2369ed3 10829rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
10830{
10831 /* Reversal of FP compares takes care -- an ordered compare
10832 becomes an unordered compare and vice versa. */
f676971a 10833 if (mode == CCFPmode
bc9ec0e0
GK
10834 && (!flag_finite_math_only
10835 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
10836 || code == UNEQ || code == LTGT))
bab6226b 10837 return reverse_condition_maybe_unordered (code);
39a10a29 10838 else
bab6226b 10839 return reverse_condition (code);
39a10a29
GK
10840}
10841
39a10a29
GK
10842/* Generate a compare for CODE. Return a brand-new rtx that
10843 represents the result of the compare. */
a4f6c312 10844
39a10a29 10845static rtx
a2369ed3 10846rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
10847{
10848 enum machine_mode comp_mode;
10849 rtx compare_result;
10850
10851 if (rs6000_compare_fp_p)
10852 comp_mode = CCFPmode;
10853 else if (code == GTU || code == LTU
c4ad648e 10854 || code == GEU || code == LEU)
39a10a29
GK
10855 comp_mode = CCUNSmode;
10856 else
10857 comp_mode = CCmode;
10858
10859 /* First, the compare. */
10860 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
10861
10862 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
10863 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10864 && rs6000_compare_fp_p)
a3170dc6
AH
10865 {
10866 rtx cmp, or1, or2, or_result, compare_result2;
10867
423c1189
AH
10868 /* Note: The E500 comparison instructions set the GT bit (x +
10869 1), on success. This explains the mess. */
10870
a3170dc6
AH
10871 switch (code)
10872 {
423c1189 10873 case EQ: case UNEQ: case NE: case LTGT:
bc9ec0e0 10874 cmp = flag_finite_math_only
a3170dc6
AH
10875 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
10876 rs6000_compare_op1)
10877 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
10878 rs6000_compare_op1);
10879 break;
423c1189 10880 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
bc9ec0e0 10881 cmp = flag_finite_math_only
a3170dc6
AH
10882 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
10883 rs6000_compare_op1)
10884 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
10885 rs6000_compare_op1);
10886 break;
423c1189 10887 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
bc9ec0e0 10888 cmp = flag_finite_math_only
a3170dc6
AH
10889 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
10890 rs6000_compare_op1)
10891 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
10892 rs6000_compare_op1);
10893 break;
10894 default:
10895 abort ();
10896 }
10897
10898 /* Synthesize LE and GE from LT/GT || EQ. */
10899 if (code == LE || code == GE || code == LEU || code == GEU)
10900 {
a3170dc6
AH
10901 emit_insn (cmp);
10902
10903 switch (code)
10904 {
10905 case LE: code = LT; break;
10906 case GE: code = GT; break;
10907 case LEU: code = LT; break;
10908 case GEU: code = GT; break;
10909 default: abort ();
10910 }
10911
10912 or1 = gen_reg_rtx (SImode);
10913 or2 = gen_reg_rtx (SImode);
10914 or_result = gen_reg_rtx (CCEQmode);
10915 compare_result2 = gen_reg_rtx (CCFPmode);
10916
10917 /* Do the EQ. */
bc9ec0e0 10918 cmp = flag_finite_math_only
a3170dc6
AH
10919 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
10920 rs6000_compare_op1)
10921 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
10922 rs6000_compare_op1);
10923 emit_insn (cmp);
10924
423c1189
AH
10925 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
10926 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
10927
10928 /* OR them together. */
10929 cmp = gen_rtx_SET (VOIDmode, or_result,
10930 gen_rtx_COMPARE (CCEQmode,
10931 gen_rtx_IOR (SImode, or1, or2),
10932 const_true_rtx));
10933 compare_result = or_result;
10934 code = EQ;
10935 }
10936 else
10937 {
a3170dc6 10938 if (code == NE || code == LTGT)
a3170dc6 10939 code = NE;
423c1189
AH
10940 else
10941 code = EQ;
a3170dc6
AH
10942 }
10943
10944 emit_insn (cmp);
10945 }
10946 else
10947 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
10948 gen_rtx_COMPARE (comp_mode,
f676971a 10949 rs6000_compare_op0,
a3170dc6 10950 rs6000_compare_op1)));
f676971a 10951
ca5adc63 10952 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 10953 under flag_finite_math_only we don't bother. */
39a10a29 10954 if (rs6000_compare_fp_p
bc9ec0e0 10955 && ! flag_finite_math_only
993f19a8 10956 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
10957 && (code == LE || code == GE
10958 || code == UNEQ || code == LTGT
10959 || code == UNGT || code == UNLT))
10960 {
10961 enum rtx_code or1, or2;
10962 rtx or1_rtx, or2_rtx, compare2_rtx;
10963 rtx or_result = gen_reg_rtx (CCEQmode);
f676971a 10964
39a10a29
GK
10965 switch (code)
10966 {
10967 case LE: or1 = LT; or2 = EQ; break;
10968 case GE: or1 = GT; or2 = EQ; break;
10969 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
10970 case LTGT: or1 = LT; or2 = GT; break;
10971 case UNGT: or1 = UNORDERED; or2 = GT; break;
10972 case UNLT: or1 = UNORDERED; or2 = LT; break;
10973 default: abort ();
10974 }
10975 validate_condition_mode (or1, comp_mode);
10976 validate_condition_mode (or2, comp_mode);
1c563bed
KH
10977 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
10978 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
10979 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
10980 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
10981 const_true_rtx);
10982 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
10983
10984 compare_result = or_result;
10985 code = EQ;
10986 }
10987
10988 validate_condition_mode (code, GET_MODE (compare_result));
f676971a 10989
1c563bed 10990 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
10991}
10992
10993
10994/* Emit the RTL for an sCOND pattern. */
10995
10996void
a2369ed3 10997rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
10998{
10999 rtx condition_rtx;
11000 enum machine_mode op_mode;
b7053a3f 11001 enum rtx_code cond_code;
39a10a29
GK
11002
11003 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
11004 cond_code = GET_CODE (condition_rtx);
11005
423c1189
AH
11006 if (TARGET_E500 && rs6000_compare_fp_p
11007 && !TARGET_FPRS && TARGET_HARD_FLOAT)
11008 {
11009 rtx t;
11010
11011 PUT_MODE (condition_rtx, SImode);
11012 t = XEXP (condition_rtx, 0);
11013
11014 if (cond_code != NE && cond_code != EQ)
11015 abort ();
11016
11017 if (cond_code == NE)
6b1fedc3 11018 emit_insn (gen_e500_flip_eq_bit (t, t));
423c1189 11019
6b1fedc3 11020 emit_insn (gen_move_from_CR_eq_bit (result, t));
423c1189
AH
11021 return;
11022 }
11023
b7053a3f
GK
11024 if (cond_code == NE
11025 || cond_code == GE || cond_code == LE
11026 || cond_code == GEU || cond_code == LEU
11027 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
11028 {
11029 rtx not_result = gen_reg_rtx (CCEQmode);
11030 rtx not_op, rev_cond_rtx;
11031 enum machine_mode cc_mode;
f676971a 11032
b7053a3f
GK
11033 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
11034
1c563bed 11035 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 11036 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
11037 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
11038 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
11039 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
11040 }
39a10a29
GK
11041
11042 op_mode = GET_MODE (rs6000_compare_op0);
11043 if (op_mode == VOIDmode)
11044 op_mode = GET_MODE (rs6000_compare_op1);
11045
11046 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
11047 {
11048 PUT_MODE (condition_rtx, DImode);
11049 convert_move (result, condition_rtx, 0);
11050 }
11051 else
11052 {
11053 PUT_MODE (condition_rtx, SImode);
11054 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
11055 }
11056}
11057
39a10a29
GK
11058/* Emit a branch of kind CODE to location LOC. */
11059
11060void
a2369ed3 11061rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
11062{
11063 rtx condition_rtx, loc_ref;
11064
11065 condition_rtx = rs6000_generate_compare (code);
11066 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
11067 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
11068 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
11069 loc_ref, pc_rtx)));
11070}
11071
12a4e8c5
GK
11072/* Return the string to output a conditional branch to LABEL, which is
11073 the operand number of the label, or -1 if the branch is really a
f676971a 11074 conditional return.
12a4e8c5
GK
11075
11076 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
11077 condition code register and its mode specifies what kind of
11078 comparison we made.
11079
a0ab749a 11080 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
11081
11082 INSN is the insn. */
11083
11084char *
a2369ed3 11085output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
11086{
11087 static char string[64];
11088 enum rtx_code code = GET_CODE (op);
11089 rtx cc_reg = XEXP (op, 0);
11090 enum machine_mode mode = GET_MODE (cc_reg);
11091 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 11092 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
11093 int really_reversed = reversed ^ need_longbranch;
11094 char *s = string;
11095 const char *ccode;
11096 const char *pred;
11097 rtx note;
11098
39a10a29
GK
11099 validate_condition_mode (code, mode);
11100
11101 /* Work out which way this really branches. We could use
11102 reverse_condition_maybe_unordered here always but this
11103 makes the resulting assembler clearer. */
12a4e8c5 11104 if (really_reversed)
de40e1df
DJ
11105 {
11106 /* Reversal of FP compares takes care -- an ordered compare
11107 becomes an unordered compare and vice versa. */
11108 if (mode == CCFPmode)
11109 code = reverse_condition_maybe_unordered (code);
11110 else
11111 code = reverse_condition (code);
11112 }
12a4e8c5 11113
993f19a8 11114 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
11115 {
11116 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
11117 to the GT bit. */
11118 if (code == EQ)
11119 /* Opposite of GT. */
a3170dc6 11120 code = GT;
423c1189
AH
11121 else if (code == NE)
11122 code = UNLE;
a3170dc6
AH
11123 else
11124 abort ();
11125 }
11126
39a10a29 11127 switch (code)
12a4e8c5
GK
11128 {
11129 /* Not all of these are actually distinct opcodes, but
11130 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
11131 case NE: case LTGT:
11132 ccode = "ne"; break;
11133 case EQ: case UNEQ:
11134 ccode = "eq"; break;
f676971a 11135 case GE: case GEU:
50a0b056 11136 ccode = "ge"; break;
f676971a 11137 case GT: case GTU: case UNGT:
50a0b056 11138 ccode = "gt"; break;
f676971a 11139 case LE: case LEU:
50a0b056 11140 ccode = "le"; break;
f676971a 11141 case LT: case LTU: case UNLT:
50a0b056 11142 ccode = "lt"; break;
12a4e8c5
GK
11143 case UNORDERED: ccode = "un"; break;
11144 case ORDERED: ccode = "nu"; break;
11145 case UNGE: ccode = "nl"; break;
11146 case UNLE: ccode = "ng"; break;
11147 default:
a4f6c312 11148 abort ();
12a4e8c5 11149 }
f676971a
EC
11150
11151 /* Maybe we have a guess as to how likely the branch is.
94a54f47 11152 The old mnemonics don't have a way to specify this information. */
f4857b9b 11153 pred = "";
12a4e8c5
GK
11154 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
11155 if (note != NULL_RTX)
11156 {
11157 /* PROB is the difference from 50%. */
11158 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
11159
11160 /* Only hint for highly probable/improbable branches on newer
11161 cpus as static prediction overrides processor dynamic
11162 prediction. For older cpus we may as well always hint, but
11163 assume not taken for branches that are very close to 50% as a
11164 mispredicted taken branch is more expensive than a
f676971a 11165 mispredicted not-taken branch. */
ec507f2d 11166 if (rs6000_always_hint
f4857b9b
AM
11167 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
11168 {
11169 if (abs (prob) > REG_BR_PROB_BASE / 20
11170 && ((prob > 0) ^ need_longbranch))
c4ad648e 11171 pred = "+";
f4857b9b
AM
11172 else
11173 pred = "-";
11174 }
12a4e8c5 11175 }
12a4e8c5
GK
11176
11177 if (label == NULL)
94a54f47 11178 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 11179 else
94a54f47 11180 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 11181
37c67319 11182 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 11183 Assume they'd only be the first character.... */
37c67319
GK
11184 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
11185 *s++ = '%';
94a54f47 11186 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
11187
11188 if (label != NULL)
11189 {
11190 /* If the branch distance was too far, we may have to use an
11191 unconditional branch to go the distance. */
11192 if (need_longbranch)
44518ddd 11193 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
11194 else
11195 s += sprintf (s, ",%s", label);
11196 }
11197
11198 return string;
11199}
50a0b056 11200
6b1fedc3 11201/* Return the string to flip the EQ bit on a CR. */
423c1189 11202char *
6b1fedc3 11203output_e500_flip_eq_bit (rtx dst, rtx src)
423c1189
AH
11204{
11205 static char string[64];
11206 int a, b;
11207
11208 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
11209 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
11210 abort ();
11211
6b1fedc3
AH
11212 /* EQ bit. */
11213 a = 4 * (REGNO (dst) - CR0_REGNO) + 2;
11214 b = 4 * (REGNO (src) - CR0_REGNO) + 2;
423c1189
AH
11215
11216 sprintf (string, "crnot %d,%d", a, b);
11217 return string;
11218}
11219
21213b4c
DP
11220/* Return insn index for the vector compare instruction for given CODE,
11221 and DEST_MODE, OP_MODE. Return INSN_NOT_AVAILABLE if valid insn is
11222 not available. */
11223
11224static int
11225get_vec_cmp_insn (enum rtx_code code,
11226 enum machine_mode dest_mode,
11227 enum machine_mode op_mode)
11228{
11229 if (!TARGET_ALTIVEC)
11230 return INSN_NOT_AVAILABLE;
11231
11232 switch (code)
11233 {
11234 case EQ:
11235 if (dest_mode == V16QImode && op_mode == V16QImode)
11236 return UNSPEC_VCMPEQUB;
11237 if (dest_mode == V8HImode && op_mode == V8HImode)
11238 return UNSPEC_VCMPEQUH;
11239 if (dest_mode == V4SImode && op_mode == V4SImode)
11240 return UNSPEC_VCMPEQUW;
11241 if (dest_mode == V4SImode && op_mode == V4SFmode)
11242 return UNSPEC_VCMPEQFP;
11243 break;
11244 case GE:
11245 if (dest_mode == V4SImode && op_mode == V4SFmode)
11246 return UNSPEC_VCMPGEFP;
11247 case GT:
11248 if (dest_mode == V16QImode && op_mode == V16QImode)
11249 return UNSPEC_VCMPGTSB;
11250 if (dest_mode == V8HImode && op_mode == V8HImode)
11251 return UNSPEC_VCMPGTSH;
11252 if (dest_mode == V4SImode && op_mode == V4SImode)
11253 return UNSPEC_VCMPGTSW;
11254 if (dest_mode == V4SImode && op_mode == V4SFmode)
11255 return UNSPEC_VCMPGTFP;
11256 break;
11257 case GTU:
11258 if (dest_mode == V16QImode && op_mode == V16QImode)
11259 return UNSPEC_VCMPGTUB;
11260 if (dest_mode == V8HImode && op_mode == V8HImode)
11261 return UNSPEC_VCMPGTUH;
11262 if (dest_mode == V4SImode && op_mode == V4SImode)
11263 return UNSPEC_VCMPGTUW;
11264 break;
11265 default:
11266 break;
11267 }
11268 return INSN_NOT_AVAILABLE;
11269}
11270
11271/* Emit vector compare for operands OP0 and OP1 using code RCODE.
11272 DMODE is expected destination mode. This is a recursive function. */
11273
11274static rtx
11275rs6000_emit_vector_compare (enum rtx_code rcode,
11276 rtx op0, rtx op1,
11277 enum machine_mode dmode)
11278{
11279 int vec_cmp_insn;
11280 rtx mask;
11281 enum machine_mode dest_mode;
11282 enum machine_mode op_mode = GET_MODE (op1);
11283
11284#ifdef ENABLE_CHECKING
11285 if (!TARGET_ALTIVEC)
11286 abort ();
11287
11288 if (GET_MODE (op0) != GET_MODE (op1))
11289 abort ();
11290#endif
11291
11292 /* Floating point vector compare instructions uses destination V4SImode.
11293 Move destination to appropriate mode later. */
11294 if (dmode == V4SFmode)
11295 dest_mode = V4SImode;
11296 else
11297 dest_mode = dmode;
11298
11299 mask = gen_reg_rtx (dest_mode);
11300 vec_cmp_insn = get_vec_cmp_insn (rcode, dest_mode, op_mode);
11301
11302 if (vec_cmp_insn == INSN_NOT_AVAILABLE)
11303 {
11304 bool swap_operands = false;
11305 bool try_again = false;
11306 switch (rcode)
11307 {
11308 case LT:
11309 rcode = GT;
11310 swap_operands = true;
11311 try_again = true;
11312 break;
11313 case LTU:
11314 rcode = GTU;
11315 swap_operands = true;
11316 try_again = true;
11317 break;
11318 case NE:
11319 /* Treat A != B as ~(A==B). */
11320 {
11321 enum insn_code nor_code;
11322 rtx eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1,
11323 dest_mode);
11324
11325 nor_code = one_cmpl_optab->handlers[(int)dest_mode].insn_code;
11326 if (nor_code == CODE_FOR_nothing)
11327 abort ();
11328 emit_insn (GEN_FCN (nor_code) (mask, eq_rtx));
11329
11330 if (dmode != dest_mode)
11331 {
11332 rtx temp = gen_reg_rtx (dest_mode);
11333 convert_move (temp, mask, 0);
11334 return temp;
11335 }
11336 return mask;
11337 }
11338 break;
11339 case GE:
11340 case GEU:
11341 case LE:
11342 case LEU:
11343 /* Try GT/GTU/LT/LTU OR EQ */
11344 {
11345 rtx c_rtx, eq_rtx;
11346 enum insn_code ior_code;
11347 enum rtx_code new_code;
11348
11349 if (rcode == GE)
11350 new_code = GT;
11351 else if (rcode == GEU)
11352 new_code = GTU;
11353 else if (rcode == LE)
11354 new_code = LT;
11355 else if (rcode == LEU)
11356 new_code = LTU;
11357 else
11358 abort ();
11359
11360 c_rtx = rs6000_emit_vector_compare (new_code,
11361 op0, op1, dest_mode);
11362 eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1,
11363 dest_mode);
11364
11365 ior_code = ior_optab->handlers[(int)dest_mode].insn_code;
11366 if (ior_code == CODE_FOR_nothing)
11367 abort ();
11368 emit_insn (GEN_FCN (ior_code) (mask, c_rtx, eq_rtx));
11369 if (dmode != dest_mode)
11370 {
11371 rtx temp = gen_reg_rtx (dest_mode);
11372 convert_move (temp, mask, 0);
11373 return temp;
11374 }
11375 return mask;
11376 }
11377 break;
11378 default:
11379 abort ();
11380 }
11381
11382 if (try_again)
11383 {
11384 vec_cmp_insn = get_vec_cmp_insn (rcode, dest_mode, op_mode);
11385 if (vec_cmp_insn == INSN_NOT_AVAILABLE)
11386 /* You only get two chances. */
11387 abort ();
11388 }
11389
11390 if (swap_operands)
11391 {
11392 rtx tmp;
11393 tmp = op0;
11394 op0 = op1;
11395 op1 = tmp;
11396 }
11397 }
11398
11399 emit_insn (gen_rtx_fmt_ee (SET,
11400 VOIDmode,
11401 mask,
11402 gen_rtx_fmt_Ei (UNSPEC, dest_mode,
11403 gen_rtvec (2, op0, op1),
11404 vec_cmp_insn)));
11405 if (dmode != dest_mode)
11406 {
11407 rtx temp = gen_reg_rtx (dest_mode);
11408 convert_move (temp, mask, 0);
11409 return temp;
11410 }
11411 return mask;
11412}
11413
11414/* Return vector select instruction for MODE. Return INSN_NOT_AVAILABLE, if
11415 valid insn doesn exist for given mode. */
11416
11417static int
11418get_vsel_insn (enum machine_mode mode)
11419{
11420 switch (mode)
11421 {
11422 case V4SImode:
11423 return UNSPEC_VSEL4SI;
11424 break;
11425 case V4SFmode:
11426 return UNSPEC_VSEL4SF;
11427 break;
11428 case V8HImode:
11429 return UNSPEC_VSEL8HI;
11430 break;
11431 case V16QImode:
11432 return UNSPEC_VSEL16QI;
11433 break;
11434 default:
11435 return INSN_NOT_AVAILABLE;
11436 break;
11437 }
11438 return INSN_NOT_AVAILABLE;
11439}
11440
11441/* Emit vector select insn where DEST is destination using
11442 operands OP1, OP2 and MASK. */
11443
11444static void
11445rs6000_emit_vector_select (rtx dest, rtx op1, rtx op2, rtx mask)
11446{
11447 rtx t, temp;
11448 enum machine_mode dest_mode = GET_MODE (dest);
11449 int vsel_insn_index = get_vsel_insn (GET_MODE (dest));
11450
11451 temp = gen_reg_rtx (dest_mode);
11452
11453 t = gen_rtx_fmt_ee (SET, VOIDmode, temp,
11454 gen_rtx_fmt_Ei (UNSPEC, dest_mode,
11455 gen_rtvec (3, op1, op2, mask),
11456 vsel_insn_index));
11457 emit_insn (t);
11458 emit_move_insn (dest, temp);
11459 return;
11460}
11461
11462/* Emit vector conditional expression.
11463 DEST is destination. OP1 and OP2 are two VEC_COND_EXPR operands.
11464 CC_OP0 and CC_OP1 are the two operands for the relation operation COND. */
11465
11466int
11467rs6000_emit_vector_cond_expr (rtx dest, rtx op1, rtx op2,
11468 rtx cond, rtx cc_op0, rtx cc_op1)
11469{
11470 enum machine_mode dest_mode = GET_MODE (dest);
11471 enum rtx_code rcode = GET_CODE (cond);
11472 rtx mask;
11473
11474 if (!TARGET_ALTIVEC)
11475 return 0;
11476
11477 /* Get the vector mask for the given relational operations. */
11478 mask = rs6000_emit_vector_compare (rcode, cc_op0, cc_op1, dest_mode);
11479
11480 rs6000_emit_vector_select (dest, op1, op2, mask);
11481
11482 return 1;
11483}
11484
50a0b056
GK
11485/* Emit a conditional move: move TRUE_COND to DEST if OP of the
11486 operands of the last comparison is nonzero/true, FALSE_COND if it
11487 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 11488
50a0b056 11489int
a2369ed3 11490rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
11491{
11492 enum rtx_code code = GET_CODE (op);
11493 rtx op0 = rs6000_compare_op0;
11494 rtx op1 = rs6000_compare_op1;
11495 REAL_VALUE_TYPE c1;
3148ad6d
DJ
11496 enum machine_mode compare_mode = GET_MODE (op0);
11497 enum machine_mode result_mode = GET_MODE (dest);
50a0b056 11498 rtx temp;
add2402e 11499 bool is_against_zero;
50a0b056 11500
a3c9585f 11501 /* These modes should always match. */
a3170dc6
AH
11502 if (GET_MODE (op1) != compare_mode
11503 /* In the isel case however, we can use a compare immediate, so
11504 op1 may be a small constant. */
11505 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 11506 return 0;
178c3eff 11507 if (GET_MODE (true_cond) != result_mode)
3148ad6d 11508 return 0;
178c3eff 11509 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
11510 return 0;
11511
50a0b056 11512 /* First, work out if the hardware can do this at all, or
a3c9585f 11513 if it's too slow.... */
50a0b056 11514 if (! rs6000_compare_fp_p)
a3170dc6
AH
11515 {
11516 if (TARGET_ISEL)
11517 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
11518 return 0;
11519 }
fef98bf2
AH
11520 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
11521 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
11522 return 0;
50a0b056 11523
add2402e
GK
11524 is_against_zero = op1 == CONST0_RTX (compare_mode);
11525
11526 /* A floating-point subtract might overflow, underflow, or produce
11527 an inexact result, thus changing the floating-point flags, so it
11528 can't be generated if we care about that. It's safe if one side
11529 of the construct is zero, since then no subtract will be
11530 generated. */
11531 if (GET_MODE_CLASS (compare_mode) == MODE_FLOAT
11532 && flag_trapping_math && ! is_against_zero)
11533 return 0;
11534
50a0b056
GK
11535 /* Eliminate half of the comparisons by switching operands, this
11536 makes the remaining code simpler. */
11537 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 11538 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
11539 {
11540 code = reverse_condition_maybe_unordered (code);
11541 temp = true_cond;
11542 true_cond = false_cond;
11543 false_cond = temp;
11544 }
11545
11546 /* UNEQ and LTGT take four instructions for a comparison with zero,
11547 it'll probably be faster to use a branch here too. */
bc9ec0e0 11548 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056 11549 return 0;
f676971a 11550
50a0b056
GK
11551 if (GET_CODE (op1) == CONST_DOUBLE)
11552 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
f676971a 11553
b6d08ca1 11554 /* We're going to try to implement comparisons by performing
50a0b056
GK
11555 a subtract, then comparing against zero. Unfortunately,
11556 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 11557 know that the operand is finite and the comparison
50a0b056 11558 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 11559 if (HONOR_INFINITIES (compare_mode)
50a0b056 11560 && code != GT && code != UNGE
045572c7 11561 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
11562 /* Constructs of the form (a OP b ? a : b) are safe. */
11563 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
f676971a 11564 || (! rtx_equal_p (op0, true_cond)
50a0b056
GK
11565 && ! rtx_equal_p (op1, true_cond))))
11566 return 0;
add2402e 11567
50a0b056
GK
11568 /* At this point we know we can use fsel. */
11569
11570 /* Reduce the comparison to a comparison against zero. */
add2402e
GK
11571 if (! is_against_zero)
11572 {
11573 temp = gen_reg_rtx (compare_mode);
11574 emit_insn (gen_rtx_SET (VOIDmode, temp,
11575 gen_rtx_MINUS (compare_mode, op0, op1)));
11576 op0 = temp;
11577 op1 = CONST0_RTX (compare_mode);
11578 }
50a0b056
GK
11579
11580 /* If we don't care about NaNs we can reduce some of the comparisons
11581 down to faster ones. */
bc9ec0e0 11582 if (! HONOR_NANS (compare_mode))
50a0b056
GK
11583 switch (code)
11584 {
11585 case GT:
11586 code = LE;
11587 temp = true_cond;
11588 true_cond = false_cond;
11589 false_cond = temp;
11590 break;
11591 case UNGE:
11592 code = GE;
11593 break;
11594 case UNEQ:
11595 code = EQ;
11596 break;
11597 default:
11598 break;
11599 }
11600
11601 /* Now, reduce everything down to a GE. */
11602 switch (code)
11603 {
11604 case GE:
11605 break;
11606
11607 case LE:
3148ad6d
DJ
11608 temp = gen_reg_rtx (compare_mode);
11609 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11610 op0 = temp;
11611 break;
11612
11613 case ORDERED:
3148ad6d
DJ
11614 temp = gen_reg_rtx (compare_mode);
11615 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
11616 op0 = temp;
11617 break;
11618
11619 case EQ:
3148ad6d 11620 temp = gen_reg_rtx (compare_mode);
f676971a 11621 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
11622 gen_rtx_NEG (compare_mode,
11623 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
11624 op0 = temp;
11625 break;
11626
11627 case UNGE:
bc9ec0e0 11628 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 11629 temp = gen_reg_rtx (result_mode);
50a0b056 11630 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 11631 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11632 gen_rtx_GE (VOIDmode,
11633 op0, op1),
11634 true_cond, false_cond)));
bc9ec0e0
GK
11635 false_cond = true_cond;
11636 true_cond = temp;
50a0b056 11637
3148ad6d
DJ
11638 temp = gen_reg_rtx (compare_mode);
11639 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11640 op0 = temp;
11641 break;
11642
11643 case GT:
bc9ec0e0 11644 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 11645 temp = gen_reg_rtx (result_mode);
50a0b056 11646 emit_insn (gen_rtx_SET (VOIDmode, temp,
f676971a 11647 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11648 gen_rtx_GE (VOIDmode,
11649 op0, op1),
11650 true_cond, false_cond)));
bc9ec0e0
GK
11651 true_cond = false_cond;
11652 false_cond = temp;
50a0b056 11653
3148ad6d
DJ
11654 temp = gen_reg_rtx (compare_mode);
11655 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11656 op0 = temp;
11657 break;
11658
11659 default:
11660 abort ();
11661 }
11662
11663 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 11664 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11665 gen_rtx_GE (VOIDmode,
11666 op0, op1),
11667 true_cond, false_cond)));
11668 return 1;
11669}
11670
a3170dc6
AH
11671/* Same as above, but for ints (isel). */
11672
11673static int
a2369ed3 11674rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
11675{
11676 rtx condition_rtx, cr;
11677
11678 /* All isel implementations thus far are 32-bits. */
11679 if (GET_MODE (rs6000_compare_op0) != SImode)
11680 return 0;
11681
11682 /* We still have to do the compare, because isel doesn't do a
11683 compare, it just looks at the CRx bits set by a previous compare
11684 instruction. */
11685 condition_rtx = rs6000_generate_compare (GET_CODE (op));
11686 cr = XEXP (condition_rtx, 0);
11687
11688 if (GET_MODE (cr) == CCmode)
11689 emit_insn (gen_isel_signed (dest, condition_rtx,
11690 true_cond, false_cond, cr));
11691 else
11692 emit_insn (gen_isel_unsigned (dest, condition_rtx,
11693 true_cond, false_cond, cr));
11694
11695 return 1;
11696}
11697
11698const char *
a2369ed3 11699output_isel (rtx *operands)
a3170dc6
AH
11700{
11701 enum rtx_code code;
11702
11703 code = GET_CODE (operands[1]);
11704 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
11705 {
11706 PUT_CODE (operands[1], reverse_condition (code));
11707 return "isel %0,%3,%2,%j1";
11708 }
11709 else
11710 return "isel %0,%2,%3,%j1";
11711}
11712
50a0b056 11713void
a2369ed3 11714rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
11715{
11716 enum machine_mode mode = GET_MODE (op0);
5dc8d536 11717 enum rtx_code c;
50a0b056 11718 rtx target;
5dc8d536
AH
11719
11720 if (code == SMAX || code == SMIN)
11721 c = GE;
11722 else
11723 c = GEU;
11724
50a0b056 11725 if (code == SMAX || code == UMAX)
f676971a 11726 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11727 op0, op1, mode, 0);
11728 else
f676971a 11729 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11730 op1, op0, mode, 0);
11731 if (target == NULL_RTX)
11732 abort ();
11733 if (target != dest)
11734 emit_move_insn (dest, target);
11735}
46c07df8 11736
a9baceb1
GK
11737/* Emit instructions to move SRC to DST. Called by splitters for
11738 multi-register moves. It will emit at most one instruction for
11739 each register that is accessed; that is, it won't emit li/lis pairs
11740 (or equivalent for 64-bit code). One of SRC or DST must be a hard
11741 register. */
46c07df8 11742
46c07df8 11743void
a9baceb1 11744rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 11745{
a9baceb1
GK
11746 /* The register number of the first register being moved. */
11747 int reg;
11748 /* The mode that is to be moved. */
11749 enum machine_mode mode;
11750 /* The mode that the move is being done in, and its size. */
11751 enum machine_mode reg_mode;
11752 int reg_mode_size;
11753 /* The number of registers that will be moved. */
11754 int nregs;
11755
11756 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
11757 mode = GET_MODE (dst);
11758 nregs = HARD_REGNO_NREGS (reg, mode);
11759 if (FP_REGNO_P (reg))
11760 reg_mode = DFmode;
11761 else if (ALTIVEC_REGNO_P (reg))
11762 reg_mode = V16QImode;
11763 else
11764 reg_mode = word_mode;
11765 reg_mode_size = GET_MODE_SIZE (reg_mode);
f676971a 11766
a9baceb1
GK
11767 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
11768 abort ();
f676971a 11769
a9baceb1
GK
11770 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
11771 {
11772 /* Move register range backwards, if we might have destructive
11773 overlap. */
11774 int i;
11775 for (i = nregs - 1; i >= 0; i--)
f676971a 11776 emit_insn (gen_rtx_SET (VOIDmode,
a9baceb1
GK
11777 simplify_gen_subreg (reg_mode, dst, mode,
11778 i * reg_mode_size),
11779 simplify_gen_subreg (reg_mode, src, mode,
11780 i * reg_mode_size)));
11781 }
46c07df8
HP
11782 else
11783 {
a9baceb1
GK
11784 int i;
11785 int j = -1;
11786 bool used_update = false;
46c07df8 11787
c1e55850 11788 if (MEM_P (src) && INT_REGNO_P (reg))
c4ad648e
AM
11789 {
11790 rtx breg;
3a1f863f 11791
a9baceb1
GK
11792 if (GET_CODE (XEXP (src, 0)) == PRE_INC
11793 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
11794 {
11795 rtx delta_rtx;
a9baceb1 11796 breg = XEXP (XEXP (src, 0), 0);
c4ad648e
AM
11797 delta_rtx = (GET_CODE (XEXP (src, 0)) == PRE_INC
11798 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
11799 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src))));
a9baceb1
GK
11800 emit_insn (TARGET_32BIT
11801 ? gen_addsi3 (breg, breg, delta_rtx)
11802 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11803 src = gen_rtx_MEM (mode, breg);
11804 }
c1e55850
GK
11805 else if (! offsettable_memref_p (src))
11806 {
11807 rtx newsrc, basereg;
11808 basereg = gen_rtx_REG (Pmode, reg);
11809 emit_insn (gen_rtx_SET (VOIDmode, basereg, XEXP (src, 0)));
11810 newsrc = gen_rtx_MEM (GET_MODE (src), basereg);
11811 MEM_COPY_ATTRIBUTES (newsrc, src);
11812 src = newsrc;
11813 }
3a1f863f 11814
0423421f
AM
11815 breg = XEXP (src, 0);
11816 if (GET_CODE (breg) == PLUS || GET_CODE (breg) == LO_SUM)
11817 breg = XEXP (breg, 0);
11818
11819 /* If the base register we are using to address memory is
11820 also a destination reg, then change that register last. */
11821 if (REG_P (breg)
11822 && REGNO (breg) >= REGNO (dst)
3a1f863f
DE
11823 && REGNO (breg) < REGNO (dst) + nregs)
11824 j = REGNO (breg) - REGNO (dst);
c4ad648e 11825 }
46c07df8 11826
a9baceb1 11827 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
11828 {
11829 rtx breg;
11830
a9baceb1
GK
11831 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
11832 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
11833 {
11834 rtx delta_rtx;
a9baceb1 11835 breg = XEXP (XEXP (dst, 0), 0);
c4ad648e
AM
11836 delta_rtx = (GET_CODE (XEXP (dst, 0)) == PRE_INC
11837 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
11838 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst))));
3a1f863f
DE
11839
11840 /* We have to update the breg before doing the store.
11841 Use store with update, if available. */
11842
11843 if (TARGET_UPDATE)
11844 {
a9baceb1 11845 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
c4ad648e
AM
11846 emit_insn (TARGET_32BIT
11847 ? (TARGET_POWERPC64
11848 ? gen_movdi_si_update (breg, breg, delta_rtx, nsrc)
11849 : gen_movsi_update (breg, breg, delta_rtx, nsrc))
11850 : gen_movdi_di_update (breg, breg, delta_rtx, nsrc));
a9baceb1 11851 used_update = true;
3a1f863f
DE
11852 }
11853 else
a9baceb1
GK
11854 emit_insn (TARGET_32BIT
11855 ? gen_addsi3 (breg, breg, delta_rtx)
11856 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11857 dst = gen_rtx_MEM (mode, breg);
11858 }
c1e55850 11859 else if (! offsettable_memref_p (dst))
112ccb83 11860 abort ();
3a1f863f
DE
11861 }
11862
46c07df8 11863 for (i = 0; i < nregs; i++)
f676971a 11864 {
3a1f863f
DE
11865 /* Calculate index to next subword. */
11866 ++j;
f676971a 11867 if (j == nregs)
3a1f863f 11868 j = 0;
46c07df8 11869
112cdef5 11870 /* If compiler already emitted move of first word by
a9baceb1 11871 store with update, no need to do anything. */
3a1f863f 11872 if (j == 0 && used_update)
a9baceb1 11873 continue;
f676971a 11874
a9baceb1
GK
11875 emit_insn (gen_rtx_SET (VOIDmode,
11876 simplify_gen_subreg (reg_mode, dst, mode,
11877 j * reg_mode_size),
11878 simplify_gen_subreg (reg_mode, src, mode,
11879 j * reg_mode_size)));
3a1f863f 11880 }
46c07df8
HP
11881 }
11882}
11883
12a4e8c5 11884\f
a4f6c312
SS
11885/* This page contains routines that are used to determine what the
11886 function prologue and epilogue code will do and write them out. */
9878760c 11887
a4f6c312
SS
11888/* Return the first fixed-point register that is required to be
11889 saved. 32 if none. */
9878760c
RK
11890
11891int
863d938c 11892first_reg_to_save (void)
9878760c
RK
11893{
11894 int first_reg;
11895
11896 /* Find lowest numbered live register. */
11897 for (first_reg = 13; first_reg <= 31; first_reg++)
f676971a 11898 if (regs_ever_live[first_reg]
a38d360d 11899 && (! call_used_regs[first_reg]
1db02437 11900 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11901 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
b4db40bf
JJ
11902 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)
11903 || (TARGET_TOC && TARGET_MINIMAL_TOC)))))
9878760c
RK
11904 break;
11905
ee890fe2 11906#if TARGET_MACHO
93638d7a
AM
11907 if (flag_pic
11908 && current_function_uses_pic_offset_table
11909 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 11910 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
11911#endif
11912
9878760c
RK
11913 return first_reg;
11914}
11915
11916/* Similar, for FP regs. */
11917
11918int
863d938c 11919first_fp_reg_to_save (void)
9878760c
RK
11920{
11921 int first_reg;
11922
11923 /* Find lowest numbered live register. */
11924 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
11925 if (regs_ever_live[first_reg])
11926 break;
11927
11928 return first_reg;
11929}
00b960c7
AH
11930
11931/* Similar, for AltiVec regs. */
11932
11933static int
863d938c 11934first_altivec_reg_to_save (void)
00b960c7
AH
11935{
11936 int i;
11937
11938 /* Stack frame remains as is unless we are in AltiVec ABI. */
11939 if (! TARGET_ALTIVEC_ABI)
11940 return LAST_ALTIVEC_REGNO + 1;
11941
11942 /* Find lowest numbered live register. */
11943 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
11944 if (regs_ever_live[i])
11945 break;
11946
11947 return i;
11948}
11949
11950/* Return a 32-bit mask of the AltiVec registers we need to set in
11951 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
11952 the 32-bit word is 0. */
11953
11954static unsigned int
863d938c 11955compute_vrsave_mask (void)
00b960c7
AH
11956{
11957 unsigned int i, mask = 0;
11958
11959 /* First, find out if we use _any_ altivec registers. */
11960 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11961 if (regs_ever_live[i])
11962 mask |= ALTIVEC_REG_BIT (i);
11963
11964 if (mask == 0)
11965 return mask;
11966
00b960c7
AH
11967 /* Next, remove the argument registers from the set. These must
11968 be in the VRSAVE mask set by the caller, so we don't need to add
11969 them in again. More importantly, the mask we compute here is
11970 used to generate CLOBBERs in the set_vrsave insn, and we do not
11971 wish the argument registers to die. */
a6cf80f2 11972 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
11973 mask &= ~ALTIVEC_REG_BIT (i);
11974
11975 /* Similarly, remove the return value from the set. */
11976 {
11977 bool yes = false;
11978 diddle_return_value (is_altivec_return_reg, &yes);
11979 if (yes)
11980 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
11981 }
11982
11983 return mask;
11984}
11985
d62294f5
FJ
11986/* For a very restricted set of circumstances, we can cut down the
11987 size of prologs/epilogs by calling our own save/restore-the-world
11988 routines. */
11989
11990static void
11991compute_save_world_info(rs6000_stack_t *info_ptr)
11992{
11993 info_ptr->world_save_p =
11994 (DEFAULT_ABI == ABI_DARWIN)
11995 && ! (current_function_calls_setjmp && flag_exceptions)
11996 && info_ptr->first_fp_reg_save == FIRST_SAVED_FP_REGNO
11997 && info_ptr->first_gp_reg_save == FIRST_SAVED_GP_REGNO
11998 && info_ptr->first_altivec_reg_save == FIRST_SAVED_ALTIVEC_REGNO
11999 && info_ptr->cr_save_p;
f676971a 12000
d62294f5
FJ
12001 /* This will not work in conjunction with sibcalls. Make sure there
12002 are none. (This check is expensive, but seldom executed.) */
12003 if ( info_ptr->world_save_p )
f676971a 12004 {
d62294f5
FJ
12005 rtx insn;
12006 for ( insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn))
c4ad648e
AM
12007 if ( GET_CODE (insn) == CALL_INSN
12008 && SIBLING_CALL_P (insn))
12009 {
12010 info_ptr->world_save_p = 0;
12011 break;
12012 }
d62294f5 12013 }
f676971a 12014
d62294f5
FJ
12015 if (info_ptr->world_save_p)
12016 {
12017 /* Even if we're not touching VRsave, make sure there's room on the
12018 stack for it, if it looks like we're calling SAVE_WORLD, which
c4ad648e 12019 will attempt to save it. */
d62294f5
FJ
12020 info_ptr->vrsave_size = 4;
12021
12022 /* "Save" the VRsave register too if we're saving the world. */
12023 if (info_ptr->vrsave_mask == 0)
c4ad648e 12024 info_ptr->vrsave_mask = compute_vrsave_mask ();
d62294f5
FJ
12025
12026 /* Because the Darwin register save/restore routines only handle
c4ad648e
AM
12027 F14 .. F31 and V20 .. V31 as per the ABI, perform a consistency
12028 check and abort if there's something worng. */
f676971a 12029 if (info_ptr->first_fp_reg_save < FIRST_SAVED_FP_REGNO
c4ad648e
AM
12030 || info_ptr->first_altivec_reg_save < FIRST_SAVED_ALTIVEC_REGNO)
12031 abort ();
d62294f5 12032 }
f676971a 12033 return;
d62294f5
FJ
12034}
12035
12036
00b960c7 12037static void
a2369ed3 12038is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
12039{
12040 bool *yes = (bool *) xyes;
12041 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
12042 *yes = true;
12043}
12044
4697a36c
MM
12045\f
12046/* Calculate the stack information for the current function. This is
12047 complicated by having two separate calling sequences, the AIX calling
12048 sequence and the V.4 calling sequence.
12049
592696dd 12050 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 12051 32-bit 64-bit
4697a36c 12052 SP----> +---------------------------------------+
a260abc9 12053 | back chain to caller | 0 0
4697a36c 12054 +---------------------------------------+
a260abc9 12055 | saved CR | 4 8 (8-11)
4697a36c 12056 +---------------------------------------+
a260abc9 12057 | saved LR | 8 16
4697a36c 12058 +---------------------------------------+
a260abc9 12059 | reserved for compilers | 12 24
4697a36c 12060 +---------------------------------------+
a260abc9 12061 | reserved for binders | 16 32
4697a36c 12062 +---------------------------------------+
a260abc9 12063 | saved TOC pointer | 20 40
4697a36c 12064 +---------------------------------------+
a260abc9 12065 | Parameter save area (P) | 24 48
4697a36c 12066 +---------------------------------------+
a260abc9 12067 | Alloca space (A) | 24+P etc.
802a0058 12068 +---------------------------------------+
a7df97e6 12069 | Local variable space (L) | 24+P+A
4697a36c 12070 +---------------------------------------+
a7df97e6 12071 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 12072 +---------------------------------------+
00b960c7
AH
12073 | Save area for AltiVec registers (W) | 24+P+A+L+X
12074 +---------------------------------------+
12075 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
12076 +---------------------------------------+
12077 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 12078 +---------------------------------------+
00b960c7
AH
12079 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
12080 +---------------------------------------+
12081 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
12082 +---------------------------------------+
12083 old SP->| back chain to caller's caller |
12084 +---------------------------------------+
12085
5376a30c
KR
12086 The required alignment for AIX configurations is two words (i.e., 8
12087 or 16 bytes).
12088
12089
4697a36c
MM
12090 V.4 stack frames look like:
12091
12092 SP----> +---------------------------------------+
12093 | back chain to caller | 0
12094 +---------------------------------------+
5eb387b8 12095 | caller's saved LR | 4
4697a36c
MM
12096 +---------------------------------------+
12097 | Parameter save area (P) | 8
12098 +---------------------------------------+
a7df97e6 12099 | Alloca space (A) | 8+P
f676971a 12100 +---------------------------------------+
a7df97e6 12101 | Varargs save area (V) | 8+P+A
f676971a 12102 +---------------------------------------+
a7df97e6 12103 | Local variable space (L) | 8+P+A+V
f676971a 12104 +---------------------------------------+
a7df97e6 12105 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 12106 +---------------------------------------+
00b960c7
AH
12107 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
12108 +---------------------------------------+
12109 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
12110 +---------------------------------------+
12111 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
12112 +---------------------------------------+
c4ad648e
AM
12113 | SPE: area for 64-bit GP registers |
12114 +---------------------------------------+
12115 | SPE alignment padding |
12116 +---------------------------------------+
00b960c7 12117 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
f676971a 12118 +---------------------------------------+
00b960c7 12119 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
f676971a 12120 +---------------------------------------+
00b960c7 12121 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
12122 +---------------------------------------+
12123 old SP->| back chain to caller's caller |
12124 +---------------------------------------+
b6c9286a 12125
5376a30c
KR
12126 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
12127 given. (But note below and in sysv4.h that we require only 8 and
12128 may round up the size of our stack frame anyways. The historical
12129 reason is early versions of powerpc-linux which didn't properly
12130 align the stack at program startup. A happy side-effect is that
12131 -mno-eabi libraries can be used with -meabi programs.)
12132
50d440bc 12133 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
12134 the stack alignment requirements may differ. If -mno-eabi is not
12135 given, the required stack alignment is 8 bytes; if -mno-eabi is
12136 given, the required alignment is 16 bytes. (But see V.4 comment
12137 above.) */
4697a36c 12138
61b2fbe7
MM
12139#ifndef ABI_STACK_BOUNDARY
12140#define ABI_STACK_BOUNDARY STACK_BOUNDARY
12141#endif
12142
d1d0c603 12143static rs6000_stack_t *
863d938c 12144rs6000_stack_info (void)
4697a36c
MM
12145{
12146 static rs6000_stack_t info, zero_info;
12147 rs6000_stack_t *info_ptr = &info;
327e5343 12148 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 12149 int ehrd_size;
64045029 12150 int save_align;
44688022 12151 HOST_WIDE_INT non_fixed_size;
4697a36c 12152
a4f6c312 12153 /* Zero all fields portably. */
4697a36c
MM
12154 info = zero_info;
12155
c19de7aa
AH
12156 if (TARGET_SPE)
12157 {
12158 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
12159 if (cfun->machine->insn_chain_scanned_p == 0)
12160 {
12161 cfun->machine->insn_chain_scanned_p = 1;
12162 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
12163 }
c19de7aa
AH
12164 }
12165
a4f6c312 12166 /* Select which calling sequence. */
178274da 12167 info_ptr->abi = DEFAULT_ABI;
9878760c 12168
a4f6c312 12169 /* Calculate which registers need to be saved & save area size. */
4697a36c 12170 info_ptr->first_gp_reg_save = first_reg_to_save ();
f676971a 12171 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 12172 even if it currently looks like we won't. */
2bfcf297 12173 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
12174 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
12175 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
12176 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
12177 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
12178 else
12179 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 12180
a3170dc6
AH
12181 /* For the SPE, we have an additional upper 32-bits on each GPR.
12182 Ideally we should save the entire 64-bits only when the upper
12183 half is used in SIMD instructions. Since we only record
12184 registers live (not the size they are used in), this proves
12185 difficult because we'd have to traverse the instruction chain at
12186 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
12187 so we opt to save the GPRs in 64-bits always if but one register
12188 gets used in 64-bits. Otherwise, all the registers in the frame
12189 get saved in 32-bits.
a3170dc6 12190
c19de7aa 12191 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 12192 traditional GP save area will be empty. */
c19de7aa 12193 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
12194 info_ptr->gp_size = 0;
12195
4697a36c
MM
12196 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
12197 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
12198
00b960c7
AH
12199 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
12200 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
12201 - info_ptr->first_altivec_reg_save);
12202
592696dd 12203 /* Does this function call anything? */
71f123ca
FS
12204 info_ptr->calls_p = (! current_function_is_leaf
12205 || cfun->machine->ra_needs_full_frame);
b6c9286a 12206
a4f6c312 12207 /* Determine if we need to save the link register. */
71f123ca 12208 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
12209 || (DEFAULT_ABI == ABI_AIX
12210 && current_function_profile
12211 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
12212#ifdef TARGET_RELOCATABLE
12213 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
12214#endif
12215 || (info_ptr->first_fp_reg_save != 64
12216 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 12217 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 12218 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
12219 || (DEFAULT_ABI == ABI_DARWIN
12220 && flag_pic
12221 && current_function_uses_pic_offset_table)
4697a36c
MM
12222 || info_ptr->calls_p)
12223 {
12224 info_ptr->lr_save_p = 1;
9ebbca7d 12225 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
12226 }
12227
9ebbca7d 12228 /* Determine if we need to save the condition code registers. */
f676971a 12229 if (regs_ever_live[CR2_REGNO]
9ebbca7d
GK
12230 || regs_ever_live[CR3_REGNO]
12231 || regs_ever_live[CR4_REGNO])
4697a36c
MM
12232 {
12233 info_ptr->cr_save_p = 1;
178274da 12234 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
12235 info_ptr->cr_size = reg_size;
12236 }
12237
83720594
RH
12238 /* If the current function calls __builtin_eh_return, then we need
12239 to allocate stack space for registers that will hold data for
12240 the exception handler. */
12241 if (current_function_calls_eh_return)
12242 {
12243 unsigned int i;
12244 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
12245 continue;
a3170dc6
AH
12246
12247 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
12248 ehrd_size = i * (TARGET_SPE_ABI
12249 && info_ptr->spe_64bit_regs_used != 0
12250 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
12251 }
12252 else
12253 ehrd_size = 0;
12254
592696dd 12255 /* Determine various sizes. */
4697a36c
MM
12256 info_ptr->reg_size = reg_size;
12257 info_ptr->fixed_size = RS6000_SAVE_AREA;
12258 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 12259 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 12260 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 12261 TARGET_ALTIVEC ? 16 : 8);
00b960c7 12262
c19de7aa 12263 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
12264 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
12265 else
12266 info_ptr->spe_gp_size = 0;
12267
4d774ff8
HP
12268 if (TARGET_ALTIVEC_ABI)
12269 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 12270 else
4d774ff8
HP
12271 info_ptr->vrsave_mask = 0;
12272
12273 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
12274 info_ptr->vrsave_size = 4;
12275 else
12276 info_ptr->vrsave_size = 0;
b6c9286a 12277
d62294f5
FJ
12278 compute_save_world_info (info_ptr);
12279
592696dd 12280 /* Calculate the offsets. */
178274da 12281 switch (DEFAULT_ABI)
4697a36c 12282 {
b6c9286a 12283 case ABI_NONE:
24d304eb 12284 default:
b6c9286a
MM
12285 abort ();
12286
12287 case ABI_AIX:
ee890fe2 12288 case ABI_DARWIN:
b6c9286a
MM
12289 info_ptr->fp_save_offset = - info_ptr->fp_size;
12290 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
12291
12292 if (TARGET_ALTIVEC_ABI)
12293 {
12294 info_ptr->vrsave_save_offset
12295 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
12296
12297 /* Align stack so vector save area is on a quadword boundary. */
12298 if (info_ptr->altivec_size != 0)
12299 info_ptr->altivec_padding_size
12300 = 16 - (-info_ptr->vrsave_save_offset % 16);
12301 else
12302 info_ptr->altivec_padding_size = 0;
12303
12304 info_ptr->altivec_save_offset
12305 = info_ptr->vrsave_save_offset
12306 - info_ptr->altivec_padding_size
12307 - info_ptr->altivec_size;
12308
12309 /* Adjust for AltiVec case. */
12310 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
12311 }
12312 else
12313 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
12314 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
12315 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
12316 break;
12317
12318 case ABI_V4:
b6c9286a
MM
12319 info_ptr->fp_save_offset = - info_ptr->fp_size;
12320 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 12321 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 12322
c19de7aa 12323 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
c4ad648e
AM
12324 {
12325 /* Align stack so SPE GPR save area is aligned on a
12326 double-word boundary. */
12327 if (info_ptr->spe_gp_size != 0)
12328 info_ptr->spe_padding_size
12329 = 8 - (-info_ptr->cr_save_offset % 8);
12330 else
12331 info_ptr->spe_padding_size = 0;
12332
12333 info_ptr->spe_gp_save_offset
12334 = info_ptr->cr_save_offset
12335 - info_ptr->spe_padding_size
12336 - info_ptr->spe_gp_size;
12337
12338 /* Adjust for SPE case. */
12339 info_ptr->toc_save_offset
12340 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
12341 }
a3170dc6 12342 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
12343 {
12344 info_ptr->vrsave_save_offset
12345 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
12346
12347 /* Align stack so vector save area is on a quadword boundary. */
12348 if (info_ptr->altivec_size != 0)
12349 info_ptr->altivec_padding_size
12350 = 16 - (-info_ptr->vrsave_save_offset % 16);
12351 else
12352 info_ptr->altivec_padding_size = 0;
12353
12354 info_ptr->altivec_save_offset
12355 = info_ptr->vrsave_save_offset
12356 - info_ptr->altivec_padding_size
12357 - info_ptr->altivec_size;
12358
12359 /* Adjust for AltiVec case. */
12360 info_ptr->toc_save_offset
12361 = info_ptr->altivec_save_offset - info_ptr->toc_size;
12362 }
12363 else
12364 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 12365 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
12366 info_ptr->lr_save_offset = reg_size;
12367 break;
4697a36c
MM
12368 }
12369
64045029 12370 save_align = (TARGET_ALTIVEC_ABI || DEFAULT_ABI == ABI_DARWIN) ? 16 : 8;
00b960c7
AH
12371 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
12372 + info_ptr->gp_size
12373 + info_ptr->altivec_size
12374 + info_ptr->altivec_padding_size
a3170dc6
AH
12375 + info_ptr->spe_gp_size
12376 + info_ptr->spe_padding_size
00b960c7
AH
12377 + ehrd_size
12378 + info_ptr->cr_size
12379 + info_ptr->lr_size
12380 + info_ptr->vrsave_size
12381 + info_ptr->toc_size,
64045029 12382 save_align);
00b960c7 12383
44688022 12384 non_fixed_size = (info_ptr->vars_size
ff381587 12385 + info_ptr->parm_size
ff381587 12386 + info_ptr->save_size
44688022 12387 + info_ptr->varargs_size);
ff381587 12388
44688022
AM
12389 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
12390 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
12391
12392 /* Determine if we need to allocate any stack frame:
12393
a4f6c312
SS
12394 For AIX we need to push the stack if a frame pointer is needed
12395 (because the stack might be dynamically adjusted), if we are
12396 debugging, if we make calls, or if the sum of fp_save, gp_save,
12397 and local variables are more than the space needed to save all
12398 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
12399 + 18*8 = 288 (GPR13 reserved).
ff381587 12400
a4f6c312
SS
12401 For V.4 we don't have the stack cushion that AIX uses, but assume
12402 that the debugger can handle stackless frames. */
ff381587
MM
12403
12404 if (info_ptr->calls_p)
12405 info_ptr->push_p = 1;
12406
178274da 12407 else if (DEFAULT_ABI == ABI_V4)
44688022 12408 info_ptr->push_p = non_fixed_size != 0;
ff381587 12409
178274da
AM
12410 else if (frame_pointer_needed)
12411 info_ptr->push_p = 1;
12412
12413 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
12414 info_ptr->push_p = 1;
12415
ff381587 12416 else
44688022 12417 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 12418
a4f6c312 12419 /* Zero offsets if we're not saving those registers. */
8dda1a21 12420 if (info_ptr->fp_size == 0)
4697a36c
MM
12421 info_ptr->fp_save_offset = 0;
12422
8dda1a21 12423 if (info_ptr->gp_size == 0)
4697a36c
MM
12424 info_ptr->gp_save_offset = 0;
12425
00b960c7
AH
12426 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
12427 info_ptr->altivec_save_offset = 0;
12428
12429 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
12430 info_ptr->vrsave_save_offset = 0;
12431
c19de7aa
AH
12432 if (! TARGET_SPE_ABI
12433 || info_ptr->spe_64bit_regs_used == 0
12434 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
12435 info_ptr->spe_gp_save_offset = 0;
12436
c81fc13e 12437 if (! info_ptr->lr_save_p)
4697a36c
MM
12438 info_ptr->lr_save_offset = 0;
12439
c81fc13e 12440 if (! info_ptr->cr_save_p)
4697a36c
MM
12441 info_ptr->cr_save_offset = 0;
12442
c81fc13e 12443 if (! info_ptr->toc_save_p)
b6c9286a
MM
12444 info_ptr->toc_save_offset = 0;
12445
4697a36c
MM
12446 return info_ptr;
12447}
12448
c19de7aa
AH
12449/* Return true if the current function uses any GPRs in 64-bit SIMD
12450 mode. */
12451
12452static bool
863d938c 12453spe_func_has_64bit_regs_p (void)
c19de7aa
AH
12454{
12455 rtx insns, insn;
12456
12457 /* Functions that save and restore all the call-saved registers will
12458 need to save/restore the registers in 64-bits. */
12459 if (current_function_calls_eh_return
12460 || current_function_calls_setjmp
12461 || current_function_has_nonlocal_goto)
12462 return true;
12463
12464 insns = get_insns ();
12465
12466 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
12467 {
12468 if (INSN_P (insn))
12469 {
12470 rtx i;
12471
12472 i = PATTERN (insn);
12473 if (GET_CODE (i) == SET
12474 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
12475 return true;
12476 }
12477 }
12478
12479 return false;
12480}
12481
d1d0c603 12482static void
a2369ed3 12483debug_stack_info (rs6000_stack_t *info)
9878760c 12484{
d330fd93 12485 const char *abi_string;
24d304eb 12486
c81fc13e 12487 if (! info)
4697a36c
MM
12488 info = rs6000_stack_info ();
12489
12490 fprintf (stderr, "\nStack information for function %s:\n",
12491 ((current_function_decl && DECL_NAME (current_function_decl))
12492 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
12493 : "<unknown>"));
12494
24d304eb
RK
12495 switch (info->abi)
12496 {
b6c9286a
MM
12497 default: abi_string = "Unknown"; break;
12498 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 12499 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 12500 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 12501 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
12502 }
12503
12504 fprintf (stderr, "\tABI = %5s\n", abi_string);
12505
00b960c7
AH
12506 if (TARGET_ALTIVEC_ABI)
12507 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
12508
a3170dc6
AH
12509 if (TARGET_SPE_ABI)
12510 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
12511
4697a36c
MM
12512 if (info->first_gp_reg_save != 32)
12513 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
12514
12515 if (info->first_fp_reg_save != 64)
12516 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 12517
00b960c7
AH
12518 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
12519 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
12520 info->first_altivec_reg_save);
12521
4697a36c
MM
12522 if (info->lr_save_p)
12523 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 12524
4697a36c
MM
12525 if (info->cr_save_p)
12526 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
12527
b6c9286a
MM
12528 if (info->toc_save_p)
12529 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
12530
00b960c7
AH
12531 if (info->vrsave_mask)
12532 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
12533
4697a36c
MM
12534 if (info->push_p)
12535 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
12536
12537 if (info->calls_p)
12538 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
12539
4697a36c
MM
12540 if (info->gp_save_offset)
12541 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
12542
12543 if (info->fp_save_offset)
12544 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
12545
00b960c7
AH
12546 if (info->altivec_save_offset)
12547 fprintf (stderr, "\taltivec_save_offset = %5d\n",
12548 info->altivec_save_offset);
12549
a3170dc6
AH
12550 if (info->spe_gp_save_offset)
12551 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
12552 info->spe_gp_save_offset);
12553
00b960c7
AH
12554 if (info->vrsave_save_offset)
12555 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
12556 info->vrsave_save_offset);
12557
4697a36c
MM
12558 if (info->lr_save_offset)
12559 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
12560
12561 if (info->cr_save_offset)
12562 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
12563
b6c9286a
MM
12564 if (info->toc_save_offset)
12565 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
12566
4697a36c
MM
12567 if (info->varargs_save_offset)
12568 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
12569
12570 if (info->total_size)
d1d0c603
JJ
12571 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12572 info->total_size);
4697a36c
MM
12573
12574 if (info->varargs_size)
12575 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
12576
12577 if (info->vars_size)
d1d0c603
JJ
12578 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12579 info->vars_size);
4697a36c
MM
12580
12581 if (info->parm_size)
12582 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
12583
12584 if (info->fixed_size)
12585 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
12586
12587 if (info->gp_size)
12588 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
12589
a3170dc6
AH
12590 if (info->spe_gp_size)
12591 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
12592
4697a36c
MM
12593 if (info->fp_size)
12594 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
12595
00b960c7
AH
12596 if (info->altivec_size)
12597 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
12598
12599 if (info->vrsave_size)
12600 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
12601
12602 if (info->altivec_padding_size)
12603 fprintf (stderr, "\taltivec_padding_size= %5d\n",
12604 info->altivec_padding_size);
12605
a3170dc6
AH
12606 if (info->spe_padding_size)
12607 fprintf (stderr, "\tspe_padding_size = %5d\n",
12608 info->spe_padding_size);
12609
a4f6c312 12610 if (info->lr_size)
ed947a96 12611 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 12612
4697a36c
MM
12613 if (info->cr_size)
12614 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
12615
a4f6c312 12616 if (info->toc_size)
b6c9286a
MM
12617 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
12618
4697a36c
MM
12619 if (info->save_size)
12620 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
12621
12622 if (info->reg_size != 4)
12623 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
12624
12625 fprintf (stderr, "\n");
9878760c 12626}
71f123ca
FS
12627
12628rtx
a2369ed3 12629rs6000_return_addr (int count, rtx frame)
71f123ca 12630{
a4f6c312
SS
12631 /* Currently we don't optimize very well between prolog and body
12632 code and for PIC code the code can be actually quite bad, so
12633 don't try to be too clever here. */
f1384257 12634 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
12635 {
12636 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
12637
12638 return
12639 gen_rtx_MEM
12640 (Pmode,
12641 memory_address
12642 (Pmode,
12643 plus_constant (copy_to_reg
12644 (gen_rtx_MEM (Pmode,
12645 memory_address (Pmode, frame))),
12646 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
12647 }
12648
8c29550d 12649 cfun->machine->ra_need_lr = 1;
9e2f7ec7 12650 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
12651}
12652
5e1bf043
DJ
12653/* Say whether a function is a candidate for sibcall handling or not.
12654 We do not allow indirect calls to be optimized into sibling calls.
12655 Also, we can't do it if there are any vector parameters; there's
12656 nowhere to put the VRsave code so it works; note that functions with
12657 vector parameters are required to have a prototype, so the argument
12658 type info must be available here. (The tail recursion case can work
12659 with vector parameters, but there's no way to distinguish here.) */
4977bab6 12660static bool
a2369ed3 12661rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
12662{
12663 tree type;
4977bab6 12664 if (decl)
5e1bf043
DJ
12665 {
12666 if (TARGET_ALTIVEC_VRSAVE)
c4ad648e 12667 {
4977bab6 12668 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
12669 type; type = TREE_CHAIN (type))
12670 {
c15b529f 12671 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 12672 return false;
5e1bf043 12673 }
c4ad648e 12674 }
5e1bf043 12675 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 12676 || (*targetm.binds_local_p) (decl))
2bcc50d0 12677 {
4977bab6 12678 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
12679
12680 if (!lookup_attribute ("longcall", attr_list)
12681 || lookup_attribute ("shortcall", attr_list))
4977bab6 12682 return true;
2bcc50d0 12683 }
5e1bf043 12684 }
4977bab6 12685 return false;
5e1bf043
DJ
12686}
12687
71f123ca 12688static int
863d938c 12689rs6000_ra_ever_killed (void)
71f123ca
FS
12690{
12691 rtx top;
5e1bf043
DJ
12692 rtx reg;
12693 rtx insn;
71f123ca 12694
dd292d0a 12695 if (current_function_is_thunk)
71f123ca 12696 return 0;
eb0424da 12697
36f7e964
AH
12698 /* regs_ever_live has LR marked as used if any sibcalls are present,
12699 but this should not force saving and restoring in the
12700 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 12701 clobbers LR, so that is inappropriate. */
36f7e964 12702
5e1bf043
DJ
12703 /* Also, the prologue can generate a store into LR that
12704 doesn't really count, like this:
36f7e964 12705
5e1bf043
DJ
12706 move LR->R0
12707 bcl to set PIC register
12708 move LR->R31
12709 move R0->LR
36f7e964
AH
12710
12711 When we're called from the epilogue, we need to avoid counting
12712 this as a store. */
f676971a 12713
71f123ca
FS
12714 push_topmost_sequence ();
12715 top = get_insns ();
12716 pop_topmost_sequence ();
5e1bf043 12717 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 12718
5e1bf043
DJ
12719 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
12720 {
12721 if (INSN_P (insn))
12722 {
12723 if (FIND_REG_INC_NOTE (insn, reg))
12724 return 1;
f676971a 12725 else if (GET_CODE (insn) == CALL_INSN
c15b529f 12726 && !SIBLING_CALL_P (insn))
5e1bf043 12727 return 1;
36f7e964
AH
12728 else if (set_of (reg, insn) != NULL_RTX
12729 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
12730 return 1;
12731 }
12732 }
12733 return 0;
71f123ca 12734}
4697a36c 12735\f
8cd8f856
GK
12736/* Add a REG_MAYBE_DEAD note to the insn. */
12737static void
a2369ed3 12738rs6000_maybe_dead (rtx insn)
8cd8f856
GK
12739{
12740 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
12741 const0_rtx,
12742 REG_NOTES (insn));
12743}
12744
9ebbca7d 12745/* Emit instructions needed to load the TOC register.
c7ca610e 12746 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 12747 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
12748
12749void
a2369ed3 12750rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 12751{
027fbf43 12752 rtx dest, insn;
1db02437 12753 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 12754
20b71b17
AM
12755 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
12756 {
12757 rtx temp = (fromprolog
12758 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12759 : gen_reg_rtx (Pmode));
027fbf43
JJ
12760 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
12761 if (fromprolog)
12762 rs6000_maybe_dead (insn);
12763 insn = emit_move_insn (dest, temp);
12764 if (fromprolog)
12765 rs6000_maybe_dead (insn);
20b71b17
AM
12766 }
12767 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
12768 {
12769 char buf[30];
12770 rtx tempLR = (fromprolog
12771 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12772 : gen_reg_rtx (Pmode));
12773 rtx temp0 = (fromprolog
12774 ? gen_rtx_REG (Pmode, 0)
12775 : gen_reg_rtx (Pmode));
12776 rtx symF;
12777
12778 /* possibly create the toc section */
12779 if (! toc_initialized)
38c1f2d7 12780 {
20b71b17
AM
12781 toc_section ();
12782 function_section (current_function_decl);
38c1f2d7 12783 }
9ebbca7d 12784
20b71b17
AM
12785 if (fromprolog)
12786 {
12787 rtx symL;
38c1f2d7 12788
20b71b17
AM
12789 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
12790 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 12791
20b71b17
AM
12792 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
12793 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12794
12795 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
12796 symF)));
12797 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
12798 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
12799 symL,
12800 symF)));
9ebbca7d
GK
12801 }
12802 else
20b71b17
AM
12803 {
12804 rtx tocsym;
12805 static int reload_toc_labelno = 0;
12806
12807 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
12808
12809 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
12810 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12811
027fbf43
JJ
12812 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
12813 emit_move_insn (dest, tempLR);
12814 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 12815 }
027fbf43
JJ
12816 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
12817 if (fromprolog)
12818 rs6000_maybe_dead (insn);
9ebbca7d 12819 }
20b71b17
AM
12820 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
12821 {
12822 /* This is for AIX code running in non-PIC ELF32. */
12823 char buf[30];
12824 rtx realsym;
12825 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
12826 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12827
027fbf43
JJ
12828 insn = emit_insn (gen_elf_high (dest, realsym));
12829 if (fromprolog)
12830 rs6000_maybe_dead (insn);
12831 insn = emit_insn (gen_elf_low (dest, dest, realsym));
12832 if (fromprolog)
12833 rs6000_maybe_dead (insn);
20b71b17
AM
12834 }
12835 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
12836 {
12837 if (TARGET_32BIT)
027fbf43 12838 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 12839 else
027fbf43
JJ
12840 insn = emit_insn (gen_load_toc_aix_di (dest));
12841 if (fromprolog)
12842 rs6000_maybe_dead (insn);
9ebbca7d 12843 }
20b71b17
AM
12844 else
12845 abort ();
9ebbca7d
GK
12846}
12847
d1d0c603
JJ
12848/* Emit instructions to restore the link register after determining where
12849 its value has been stored. */
12850
12851void
12852rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
12853{
12854 rs6000_stack_t *info = rs6000_stack_info ();
12855 rtx operands[2];
12856
12857 operands[0] = source;
12858 operands[1] = scratch;
12859
12860 if (info->lr_save_p)
12861 {
12862 rtx frame_rtx = stack_pointer_rtx;
12863 HOST_WIDE_INT sp_offset = 0;
12864 rtx tmp;
12865
12866 if (frame_pointer_needed
12867 || current_function_calls_alloca
12868 || info->total_size > 32767)
12869 {
12870 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
12871 frame_rtx = operands[1];
12872 }
12873 else if (info->push_p)
12874 sp_offset = info->total_size;
12875
12876 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
12877 tmp = gen_rtx_MEM (Pmode, tmp);
12878 emit_move_insn (tmp, operands[0]);
12879 }
12880 else
12881 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
12882}
12883
f103e34d
GK
12884static GTY(()) int set = -1;
12885
f676971a 12886int
863d938c 12887get_TOC_alias_set (void)
9ebbca7d 12888{
f103e34d
GK
12889 if (set == -1)
12890 set = new_alias_set ();
12891 return set;
f676971a 12892}
9ebbca7d 12893
c1207243 12894/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
12895 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
12896 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 12897#if TARGET_ELF
3c9eb5f4 12898static int
f676971a 12899uses_TOC (void)
9ebbca7d 12900{
c4501e62 12901 rtx insn;
38c1f2d7 12902
c4501e62
JJ
12903 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
12904 if (INSN_P (insn))
12905 {
12906 rtx pat = PATTERN (insn);
12907 int i;
9ebbca7d 12908
f676971a 12909 if (GET_CODE (pat) == PARALLEL)
c4501e62
JJ
12910 for (i = 0; i < XVECLEN (pat, 0); i++)
12911 {
12912 rtx sub = XVECEXP (pat, 0, i);
12913 if (GET_CODE (sub) == USE)
12914 {
12915 sub = XEXP (sub, 0);
12916 if (GET_CODE (sub) == UNSPEC
12917 && XINT (sub, 1) == UNSPEC_TOC)
12918 return 1;
12919 }
12920 }
12921 }
12922 return 0;
9ebbca7d 12923}
c954844a 12924#endif
38c1f2d7 12925
9ebbca7d 12926rtx
f676971a 12927create_TOC_reference (rtx symbol)
9ebbca7d 12928{
f676971a 12929 return gen_rtx_PLUS (Pmode,
a8a05998 12930 gen_rtx_REG (Pmode, TOC_REGISTER),
f676971a
EC
12931 gen_rtx_CONST (Pmode,
12932 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 12933 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 12934}
38c1f2d7 12935
fc4767bb
JJ
12936/* If _Unwind_* has been called from within the same module,
12937 toc register is not guaranteed to be saved to 40(1) on function
12938 entry. Save it there in that case. */
c7ca610e 12939
9ebbca7d 12940void
863d938c 12941rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
12942{
12943 rtx mem;
12944 rtx stack_top = gen_reg_rtx (Pmode);
12945 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
12946 rtx opcode = gen_reg_rtx (SImode);
12947 rtx tocompare = gen_reg_rtx (SImode);
12948 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
12949
12950 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
12951 emit_move_insn (stack_top, mem);
12952
fc4767bb
JJ
12953 mem = gen_rtx_MEM (Pmode,
12954 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
12955 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
12956 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
12957 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
12958 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 12959 : 0xE8410028, SImode));
9ebbca7d 12960
fc4767bb 12961 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 12962 SImode, NULL_RTX, NULL_RTX,
fc4767bb 12963 no_toc_save_needed);
9ebbca7d 12964
fc4767bb
JJ
12965 mem = gen_rtx_MEM (Pmode,
12966 gen_rtx_PLUS (Pmode, stack_top,
12967 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
12968 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
12969 emit_label (no_toc_save_needed);
9ebbca7d 12970}
38c1f2d7 12971\f
ba4828e0
RK
12972/* This ties together stack memory (MEM with an alias set of
12973 rs6000_sr_alias_set) and the change to the stack pointer. */
12974
9ebbca7d 12975static void
863d938c 12976rs6000_emit_stack_tie (void)
9ebbca7d 12977{
ba4828e0
RK
12978 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
12979
12980 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12981 emit_insn (gen_stack_tie (mem));
12982}
38c1f2d7 12983
9ebbca7d
GK
12984/* Emit the correct code for allocating stack space, as insns.
12985 If COPY_R12, make sure a copy of the old frame is left in r12.
12986 The generated code may use hard register 0 as a temporary. */
12987
12988static void
a2369ed3 12989rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 12990{
9ebbca7d
GK
12991 rtx insn;
12992 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12993 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
12994 rtx todec = GEN_INT (-size);
a157febd
GK
12995
12996 if (current_function_limit_stack)
12997 {
12998 if (REG_P (stack_limit_rtx)
f676971a 12999 && REGNO (stack_limit_rtx) > 1
a157febd
GK
13000 && REGNO (stack_limit_rtx) <= 31)
13001 {
5b71a4e7 13002 emit_insn (TARGET_32BIT
9ebbca7d
GK
13003 ? gen_addsi3 (tmp_reg,
13004 stack_limit_rtx,
13005 GEN_INT (size))
13006 : gen_adddi3 (tmp_reg,
13007 stack_limit_rtx,
13008 GEN_INT (size)));
5b71a4e7 13009
9ebbca7d
GK
13010 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
13011 const0_rtx));
a157febd
GK
13012 }
13013 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 13014 && TARGET_32BIT
f607bc57 13015 && DEFAULT_ABI == ABI_V4)
a157febd 13016 {
9ebbca7d 13017 rtx toload = gen_rtx_CONST (VOIDmode,
f676971a
EC
13018 gen_rtx_PLUS (Pmode,
13019 stack_limit_rtx,
9ebbca7d 13020 GEN_INT (size)));
5b71a4e7 13021
9ebbca7d
GK
13022 emit_insn (gen_elf_high (tmp_reg, toload));
13023 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
13024 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
13025 const0_rtx));
a157febd
GK
13026 }
13027 else
13028 warning ("stack limit expression is not supported");
13029 }
13030
9ebbca7d
GK
13031 if (copy_r12 || ! TARGET_UPDATE)
13032 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
13033
38c1f2d7
MM
13034 if (TARGET_UPDATE)
13035 {
9ebbca7d 13036 if (size > 32767)
38c1f2d7 13037 {
9ebbca7d
GK
13038 /* Need a note here so that try_split doesn't get confused. */
13039 if (get_last_insn() == NULL_RTX)
2e040219 13040 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
13041 insn = emit_move_insn (tmp_reg, todec);
13042 try_split (PATTERN (insn), insn, 0);
13043 todec = tmp_reg;
38c1f2d7 13044 }
5b71a4e7
DE
13045
13046 insn = emit_insn (TARGET_32BIT
13047 ? gen_movsi_update (stack_reg, stack_reg,
13048 todec, stack_reg)
c4ad648e 13049 : gen_movdi_di_update (stack_reg, stack_reg,
9ebbca7d 13050 todec, stack_reg));
38c1f2d7
MM
13051 }
13052 else
13053 {
5b71a4e7
DE
13054 insn = emit_insn (TARGET_32BIT
13055 ? gen_addsi3 (stack_reg, stack_reg, todec)
13056 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
13057 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
13058 gen_rtx_REG (Pmode, 12));
13059 }
f676971a 13060
9ebbca7d 13061 RTX_FRAME_RELATED_P (insn) = 1;
f676971a 13062 REG_NOTES (insn) =
9ebbca7d 13063 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
f676971a 13064 gen_rtx_SET (VOIDmode, stack_reg,
9ebbca7d
GK
13065 gen_rtx_PLUS (Pmode, stack_reg,
13066 GEN_INT (-size))),
13067 REG_NOTES (insn));
13068}
13069
a4f6c312
SS
13070/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
13071 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
13072 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
13073 deduce these equivalences by itself so it wasn't necessary to hold
13074 its hand so much. */
9ebbca7d
GK
13075
13076static void
f676971a 13077rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
a2369ed3 13078 rtx reg2, rtx rreg)
9ebbca7d
GK
13079{
13080 rtx real, temp;
13081
e56c4463
JL
13082 /* copy_rtx will not make unique copies of registers, so we need to
13083 ensure we don't have unwanted sharing here. */
13084 if (reg == reg2)
13085 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
13086
13087 if (reg == rreg)
13088 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
13089
9ebbca7d
GK
13090 real = copy_rtx (PATTERN (insn));
13091
89e7058f
AH
13092 if (reg2 != NULL_RTX)
13093 real = replace_rtx (real, reg2, rreg);
f676971a
EC
13094
13095 real = replace_rtx (real, reg,
9ebbca7d
GK
13096 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
13097 STACK_POINTER_REGNUM),
13098 GEN_INT (val)));
f676971a 13099
9ebbca7d
GK
13100 /* We expect that 'real' is either a SET or a PARALLEL containing
13101 SETs (and possibly other stuff). In a PARALLEL, all the SETs
13102 are important so they all have to be marked RTX_FRAME_RELATED_P. */
13103
13104 if (GET_CODE (real) == SET)
13105 {
13106 rtx set = real;
f676971a 13107
9ebbca7d
GK
13108 temp = simplify_rtx (SET_SRC (set));
13109 if (temp)
13110 SET_SRC (set) = temp;
13111 temp = simplify_rtx (SET_DEST (set));
13112 if (temp)
13113 SET_DEST (set) = temp;
13114 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 13115 {
9ebbca7d
GK
13116 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
13117 if (temp)
13118 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 13119 }
38c1f2d7 13120 }
9ebbca7d
GK
13121 else if (GET_CODE (real) == PARALLEL)
13122 {
13123 int i;
13124 for (i = 0; i < XVECLEN (real, 0); i++)
13125 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
13126 {
13127 rtx set = XVECEXP (real, 0, i);
f676971a 13128
9ebbca7d
GK
13129 temp = simplify_rtx (SET_SRC (set));
13130 if (temp)
13131 SET_SRC (set) = temp;
13132 temp = simplify_rtx (SET_DEST (set));
13133 if (temp)
13134 SET_DEST (set) = temp;
13135 if (GET_CODE (SET_DEST (set)) == MEM)
13136 {
13137 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
13138 if (temp)
13139 XEXP (SET_DEST (set), 0) = temp;
13140 }
13141 RTX_FRAME_RELATED_P (set) = 1;
13142 }
13143 }
13144 else
a4f6c312 13145 abort ();
c19de7aa
AH
13146
13147 if (TARGET_SPE)
13148 real = spe_synthesize_frame_save (real);
13149
9ebbca7d
GK
13150 RTX_FRAME_RELATED_P (insn) = 1;
13151 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13152 real,
13153 REG_NOTES (insn));
38c1f2d7
MM
13154}
13155
c19de7aa
AH
13156/* Given an SPE frame note, return a PARALLEL of SETs with the
13157 original note, plus a synthetic register save. */
13158
13159static rtx
a2369ed3 13160spe_synthesize_frame_save (rtx real)
c19de7aa
AH
13161{
13162 rtx synth, offset, reg, real2;
13163
13164 if (GET_CODE (real) != SET
13165 || GET_MODE (SET_SRC (real)) != V2SImode)
13166 return real;
13167
13168 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
13169 frame related note. The parallel contains a set of the register
41f3a930 13170 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
13171 This is so we can differentiate between 64-bit and 32-bit saves.
13172 Words cannot describe this nastiness. */
13173
13174 if (GET_CODE (SET_DEST (real)) != MEM
13175 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
13176 || GET_CODE (SET_SRC (real)) != REG)
13177 abort ();
13178
13179 /* Transform:
13180 (set (mem (plus (reg x) (const y)))
13181 (reg z))
13182 into:
13183 (set (mem (plus (reg x) (const y+4)))
41f3a930 13184 (reg z+1200))
c19de7aa
AH
13185 */
13186
13187 real2 = copy_rtx (real);
13188 PUT_MODE (SET_DEST (real2), SImode);
13189 reg = SET_SRC (real2);
13190 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
13191 synth = copy_rtx (real2);
13192
13193 if (BYTES_BIG_ENDIAN)
13194 {
13195 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
13196 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
13197 }
13198
13199 reg = SET_SRC (synth);
41f3a930 13200
c19de7aa 13201 synth = replace_rtx (synth, reg,
41f3a930 13202 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
13203
13204 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
13205 synth = replace_rtx (synth, offset,
13206 GEN_INT (INTVAL (offset)
13207 + (BYTES_BIG_ENDIAN ? 0 : 4)));
13208
13209 RTX_FRAME_RELATED_P (synth) = 1;
13210 RTX_FRAME_RELATED_P (real2) = 1;
13211 if (BYTES_BIG_ENDIAN)
13212 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
13213 else
13214 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
13215
13216 return real;
13217}
13218
00b960c7
AH
13219/* Returns an insn that has a vrsave set operation with the
13220 appropriate CLOBBERs. */
13221
13222static rtx
a2369ed3 13223generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
13224{
13225 int nclobs, i;
13226 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 13227 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 13228
a004eb82
AH
13229 clobs[0]
13230 = gen_rtx_SET (VOIDmode,
13231 vrsave,
13232 gen_rtx_UNSPEC_VOLATILE (SImode,
13233 gen_rtvec (2, reg, vrsave),
13234 30));
00b960c7
AH
13235
13236 nclobs = 1;
13237
9aa86737
AH
13238 /* We need to clobber the registers in the mask so the scheduler
13239 does not move sets to VRSAVE before sets of AltiVec registers.
13240
13241 However, if the function receives nonlocal gotos, reload will set
13242 all call saved registers live. We will end up with:
13243
13244 (set (reg 999) (mem))
13245 (parallel [ (set (reg vrsave) (unspec blah))
13246 (clobber (reg 999))])
13247
13248 The clobber will cause the store into reg 999 to be dead, and
13249 flow will attempt to delete an epilogue insn. In this case, we
13250 need an unspec use/set of the register. */
00b960c7
AH
13251
13252 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
44688022 13253 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
9aa86737
AH
13254 {
13255 if (!epiloguep || call_used_regs [i])
13256 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
13257 gen_rtx_REG (V4SImode, i));
13258 else
13259 {
13260 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
13261
13262 clobs[nclobs++]
a004eb82
AH
13263 = gen_rtx_SET (VOIDmode,
13264 reg,
13265 gen_rtx_UNSPEC (V4SImode,
13266 gen_rtvec (1, reg), 27));
9aa86737
AH
13267 }
13268 }
00b960c7
AH
13269
13270 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
13271
13272 for (i = 0; i < nclobs; ++i)
13273 XVECEXP (insn, 0, i) = clobs[i];
13274
13275 return insn;
13276}
13277
89e7058f
AH
13278/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
13279 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
13280
13281static void
f676971a 13282emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 13283 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
13284{
13285 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
13286 rtx replacea, replaceb;
13287
13288 int_rtx = GEN_INT (offset);
13289
13290 /* Some cases that need register indexed addressing. */
13291 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
13292 || (TARGET_SPE_ABI
13293 && SPE_VECTOR_MODE (mode)
13294 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
13295 {
13296 /* Whomever calls us must make sure r11 is available in the
c4ad648e 13297 flow path of instructions in the prologue. */
89e7058f
AH
13298 offset_rtx = gen_rtx_REG (Pmode, 11);
13299 emit_move_insn (offset_rtx, int_rtx);
13300
13301 replacea = offset_rtx;
13302 replaceb = int_rtx;
13303 }
13304 else
13305 {
13306 offset_rtx = int_rtx;
13307 replacea = NULL_RTX;
13308 replaceb = NULL_RTX;
13309 }
13310
13311 reg = gen_rtx_REG (mode, regno);
13312 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
13313 mem = gen_rtx_MEM (mode, addr);
13314 set_mem_alias_set (mem, rs6000_sr_alias_set);
13315
13316 insn = emit_move_insn (mem, reg);
13317
13318 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
13319}
13320
a3170dc6
AH
13321/* Emit an offset memory reference suitable for a frame store, while
13322 converting to a valid addressing mode. */
13323
13324static rtx
a2369ed3 13325gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
13326{
13327 rtx int_rtx, offset_rtx;
13328
13329 int_rtx = GEN_INT (offset);
13330
13331 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
13332 {
13333 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13334 emit_move_insn (offset_rtx, int_rtx);
13335 }
13336 else
13337 offset_rtx = int_rtx;
13338
13339 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
13340}
13341
699c914a
MS
13342#ifndef TARGET_FIX_AND_CONTINUE
13343#define TARGET_FIX_AND_CONTINUE 0
13344#endif
13345
9ebbca7d
GK
13346/* Emit function prologue as insns. */
13347
9878760c 13348void
863d938c 13349rs6000_emit_prologue (void)
9878760c 13350{
4697a36c 13351 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 13352 enum machine_mode reg_mode = Pmode;
327e5343 13353 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
13354 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
13355 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
13356 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 13357 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
13358 rtx insn;
13359 int saving_FPRs_inline;
13360 int using_store_multiple;
13361 HOST_WIDE_INT sp_offset = 0;
f676971a 13362
699c914a
MS
13363 if (TARGET_FIX_AND_CONTINUE)
13364 {
13365 /* gdb on darwin arranges to forward a function from the old
13366 address by modifying the first 4 instructions of the function
13367 to branch to the overriding function. This is necessary to
13368 permit function pointers that point to the old function to
13369 actually forward to the new function. */
13370 emit_insn (gen_nop ());
13371 emit_insn (gen_nop ());
13372 emit_insn (gen_nop ());
13373 emit_insn (gen_nop ());
13374 }
13375
13376 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
13377 {
13378 reg_mode = V2SImode;
13379 reg_size = 8;
13380 }
a3170dc6 13381
9ebbca7d 13382 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
13383 && (!TARGET_SPE_ABI
13384 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
13385 && info->first_gp_reg_save < 31);
13386 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 13387 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 13388 || current_function_calls_eh_return
8c29550d 13389 || cfun->machine->ra_need_lr);
9ebbca7d
GK
13390
13391 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 13392 if (info->push_p
acd0b319
AM
13393 && (DEFAULT_ABI == ABI_V4
13394 || current_function_calls_eh_return))
9ebbca7d
GK
13395 {
13396 if (info->total_size < 32767)
13397 sp_offset = info->total_size;
13398 else
13399 frame_reg_rtx = frame_ptr_rtx;
f676971a 13400 rs6000_emit_allocate_stack (info->total_size,
9ebbca7d
GK
13401 (frame_reg_rtx != sp_reg_rtx
13402 && (info->cr_save_p
13403 || info->lr_save_p
13404 || info->first_fp_reg_save < 64
13405 || info->first_gp_reg_save < 32
13406 )));
13407 if (frame_reg_rtx != sp_reg_rtx)
13408 rs6000_emit_stack_tie ();
13409 }
13410
d62294f5
FJ
13411 /* Handle world saves specially here. */
13412 if (info->world_save_p)
13413 {
13414 int i, j, sz;
13415 rtx treg;
13416 rtvec p;
13417
13418 /* save_world expects lr in r0. */
13419 if (info->lr_save_p)
c4ad648e
AM
13420 {
13421 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13422 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13423 RTX_FRAME_RELATED_P (insn) = 1;
13424 }
d62294f5
FJ
13425
13426 /* The SAVE_WORLD and RESTORE_WORLD routines make a number of
c4ad648e
AM
13427 assumptions about the offsets of various bits of the stack
13428 frame. Abort if things aren't what they should be. */
d62294f5 13429 if (info->gp_save_offset != -220
c4ad648e
AM
13430 || info->fp_save_offset != -144
13431 || info->lr_save_offset != 8
13432 || info->cr_save_offset != 4
13433 || !info->push_p
13434 || !info->lr_save_p
13435 || (current_function_calls_eh_return && info->ehrd_offset != -432)
13436 || (info->vrsave_save_offset != -224
13437 || info->altivec_save_offset != (-224 -16 -192)))
13438 abort ();
d62294f5
FJ
13439
13440 treg = gen_rtx_REG (SImode, 11);
13441 emit_move_insn (treg, GEN_INT (-info->total_size));
13442
13443 /* SAVE_WORLD takes the caller's LR in R0 and the frame size
c4ad648e 13444 in R11. It also clobbers R12, so beware! */
d62294f5
FJ
13445
13446 /* Preserve CR2 for save_world prologues */
13447 sz = 6;
13448 sz += 32 - info->first_gp_reg_save;
13449 sz += 64 - info->first_fp_reg_save;
13450 sz += LAST_ALTIVEC_REGNO - info->first_altivec_reg_save + 1;
13451 p = rtvec_alloc (sz);
13452 j = 0;
13453 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode,
c4ad648e
AM
13454 gen_rtx_REG (Pmode,
13455 LINK_REGISTER_REGNUM));
d62294f5 13456 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
c4ad648e
AM
13457 gen_rtx_SYMBOL_REF (Pmode,
13458 "*save_world"));
d62294f5 13459 /* We do floats first so that the instruction pattern matches
c4ad648e
AM
13460 properly. */
13461 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13462 {
13463 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13464 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13465 GEN_INT (info->fp_save_offset
13466 + sp_offset + 8 * i));
13467 rtx mem = gen_rtx_MEM (DFmode, addr);
13468 set_mem_alias_set (mem, rs6000_sr_alias_set);
13469
13470 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13471 }
d62294f5 13472 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
c4ad648e
AM
13473 {
13474 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
13475 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13476 GEN_INT (info->altivec_save_offset
13477 + sp_offset + 16 * i));
13478 rtx mem = gen_rtx_MEM (V4SImode, 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 13483 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
c4ad648e
AM
13484 {
13485 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13486 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13487 GEN_INT (info->gp_save_offset
13488 + sp_offset + reg_size * i));
13489 rtx mem = gen_rtx_MEM (reg_mode, addr);
13490 set_mem_alias_set (mem, rs6000_sr_alias_set);
13491
13492 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13493 }
13494
13495 {
13496 /* CR register traditionally saved as CR2. */
13497 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
13498 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13499 GEN_INT (info->cr_save_offset
13500 + sp_offset));
13501 rtx mem = gen_rtx_MEM (reg_mode, addr);
13502 set_mem_alias_set (mem, rs6000_sr_alias_set);
13503
13504 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13505 }
d62294f5
FJ
13506 /* Prevent any attempt to delete the setting of r0 and treg! */
13507 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, 0));
13508 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, treg);
13509 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode, sp_reg_rtx);
13510
13511 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
13512 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
c4ad648e 13513 NULL_RTX, NULL_RTX);
d62294f5
FJ
13514
13515 if (current_function_calls_eh_return)
c4ad648e
AM
13516 {
13517 unsigned int i;
13518 for (i = 0; ; ++i)
13519 {
13520 unsigned int regno = EH_RETURN_DATA_REGNO (i);
13521 if (regno == INVALID_REGNUM)
13522 break;
13523 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13524 info->ehrd_offset + sp_offset
13525 + reg_size * (int) i,
13526 info->total_size);
13527 }
13528 }
d62294f5
FJ
13529 }
13530
9aa86737 13531 /* Save AltiVec registers if needed. */
d62294f5 13532 if (! info->world_save_p && TARGET_ALTIVEC_ABI && info->altivec_size != 0)
9aa86737
AH
13533 {
13534 int i;
13535
13536 /* There should be a non inline version of this, for when we
13537 are saving lots of vector registers. */
13538 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
13539 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
13540 {
13541 rtx areg, savereg, mem;
13542 int offset;
13543
13544 offset = info->altivec_save_offset + sp_offset
13545 + 16 * (i - info->first_altivec_reg_save);
13546
13547 savereg = gen_rtx_REG (V4SImode, i);
13548
13549 areg = gen_rtx_REG (Pmode, 0);
13550 emit_move_insn (areg, GEN_INT (offset));
13551
13552 /* AltiVec addressing mode is [reg+reg]. */
13553 mem = gen_rtx_MEM (V4SImode,
13554 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
f676971a 13555
9aa86737
AH
13556 set_mem_alias_set (mem, rs6000_sr_alias_set);
13557
13558 insn = emit_move_insn (mem, savereg);
13559
5c242421
SB
13560 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13561 areg, GEN_INT (offset));
9aa86737
AH
13562 }
13563 }
13564
13565 /* VRSAVE is a bit vector representing which AltiVec registers
13566 are used. The OS uses this to determine which vector
13567 registers to save on a context switch. We need to save
13568 VRSAVE on the stack frame, add whatever AltiVec registers we
13569 used in this function, and do the corresponding magic in the
13570 epilogue. */
13571
4d774ff8 13572 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
d62294f5 13573 && ! info->world_save_p && info->vrsave_mask != 0)
9aa86737 13574 {
a004eb82 13575 rtx reg, mem, vrsave;
9aa86737
AH
13576 int offset;
13577
13578 /* Get VRSAVE onto a GPR. */
13579 reg = gen_rtx_REG (SImode, 12);
a004eb82 13580 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
13581 if (TARGET_MACHO)
13582 emit_insn (gen_get_vrsave_internal (reg));
13583 else
13584 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
13585
13586 /* Save VRSAVE. */
13587 offset = info->vrsave_save_offset + sp_offset;
13588 mem
13589 = gen_rtx_MEM (SImode,
13590 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
13591 set_mem_alias_set (mem, rs6000_sr_alias_set);
13592 insn = emit_move_insn (mem, reg);
13593
13594 /* Include the registers in the mask. */
13595 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
13596
13597 insn = emit_insn (generate_set_vrsave (reg, info, 0));
13598 }
13599
9ebbca7d 13600 /* If we use the link register, get it into r0. */
d62294f5 13601 if (! info->world_save_p && info->lr_save_p)
f8a57be8
GK
13602 {
13603 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13604 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13605 RTX_FRAME_RELATED_P (insn) = 1;
13606 }
9ebbca7d
GK
13607
13608 /* If we need to save CR, put it into r12. */
d62294f5 13609 if (! info->world_save_p && info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
9ebbca7d 13610 {
f8a57be8 13611 rtx set;
f676971a 13612
9ebbca7d 13613 cr_save_rtx = gen_rtx_REG (SImode, 12);
f8a57be8
GK
13614 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13615 RTX_FRAME_RELATED_P (insn) = 1;
13616 /* Now, there's no way that dwarf2out_frame_debug_expr is going
13617 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
13618 But that's OK. All we have to do is specify that _one_ condition
13619 code register is saved in this stack slot. The thrower's epilogue
13620 will then restore all the call-saved registers.
13621 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
13622 set = gen_rtx_SET (VOIDmode, cr_save_rtx,
13623 gen_rtx_REG (SImode, CR2_REGNO));
13624 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13625 set,
13626 REG_NOTES (insn));
9ebbca7d
GK
13627 }
13628
a4f6c312
SS
13629 /* Do any required saving of fpr's. If only one or two to save, do
13630 it ourselves. Otherwise, call function. */
d62294f5 13631 if (! info->world_save_p && saving_FPRs_inline)
9ebbca7d
GK
13632 {
13633 int i;
13634 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 13635 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d 13636 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
13637 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
13638 info->first_fp_reg_save + i,
13639 info->fp_save_offset + sp_offset + 8 * i,
13640 info->total_size);
9ebbca7d 13641 }
d62294f5 13642 else if (! info->world_save_p && info->first_fp_reg_save != 64)
9ebbca7d
GK
13643 {
13644 int i;
13645 char rname[30];
520a57c8 13646 const char *alloc_rname;
9ebbca7d
GK
13647 rtvec p;
13648 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
f676971a
EC
13649
13650 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
13651 gen_rtx_REG (Pmode,
9ebbca7d
GK
13652 LINK_REGISTER_REGNUM));
13653 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
13654 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 13655 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
13656 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
13657 gen_rtx_SYMBOL_REF (Pmode,
13658 alloc_rname));
13659 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13660 {
13661 rtx addr, reg, mem;
13662 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13663 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a 13664 GEN_INT (info->fp_save_offset
9ebbca7d
GK
13665 + sp_offset + 8*i));
13666 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 13667 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13668
13669 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
13670 }
13671 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13672 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d
GK
13673 NULL_RTX, NULL_RTX);
13674 }
b6c9286a 13675
9ebbca7d
GK
13676 /* Save GPRs. This is done as a PARALLEL if we are using
13677 the store-multiple instructions. */
d62294f5 13678 if (! info->world_save_p && using_store_multiple)
b6c9286a 13679 {
308c142a 13680 rtvec p;
9ebbca7d
GK
13681 int i;
13682 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
13683 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13684 {
13685 rtx addr, reg, mem;
13686 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
f676971a
EC
13687 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13688 GEN_INT (info->gp_save_offset
13689 + sp_offset
9ebbca7d
GK
13690 + reg_size * i));
13691 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 13692 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13693
13694 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
13695 }
13696 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13697 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d 13698 NULL_RTX, NULL_RTX);
b6c9286a 13699 }
d62294f5 13700 else if (! info->world_save_p)
b6c9286a 13701 {
9ebbca7d
GK
13702 int i;
13703 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 13704 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
13705 && (! call_used_regs[info->first_gp_reg_save+i]
13706 || (i+info->first_gp_reg_save
13707 == RS6000_PIC_OFFSET_TABLE_REGNUM
13708 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 13709 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 13710 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 13711 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
13712 {
13713 rtx addr, reg, mem;
13714 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13715
c19de7aa 13716 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13717 {
13718 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
13719 rtx b;
13720
13721 if (!SPE_CONST_OFFSET_OK (offset))
13722 {
13723 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13724 emit_move_insn (b, GEN_INT (offset));
13725 }
13726 else
13727 b = GEN_INT (offset);
13728
13729 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
13730 mem = gen_rtx_MEM (V2SImode, addr);
13731 set_mem_alias_set (mem, rs6000_sr_alias_set);
13732 insn = emit_move_insn (mem, reg);
13733
13734 if (GET_CODE (b) == CONST_INT)
13735 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13736 NULL_RTX, NULL_RTX);
13737 else
13738 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13739 b, GEN_INT (offset));
13740 }
13741 else
13742 {
f676971a
EC
13743 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13744 GEN_INT (info->gp_save_offset
13745 + sp_offset
a3170dc6
AH
13746 + reg_size * i));
13747 mem = gen_rtx_MEM (reg_mode, addr);
13748 set_mem_alias_set (mem, rs6000_sr_alias_set);
13749
13750 insn = emit_move_insn (mem, reg);
f676971a 13751 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a3170dc6
AH
13752 NULL_RTX, NULL_RTX);
13753 }
13754 }
9ebbca7d
GK
13755 }
13756
83720594
RH
13757 /* ??? There's no need to emit actual instructions here, but it's the
13758 easiest way to get the frame unwind information emitted. */
d62294f5 13759 if (! info->world_save_p && current_function_calls_eh_return)
83720594 13760 {
78e1b90d
DE
13761 unsigned int i, regno;
13762
fc4767bb
JJ
13763 /* In AIX ABI we need to pretend we save r2 here. */
13764 if (TARGET_AIX)
13765 {
13766 rtx addr, reg, mem;
13767
13768 reg = gen_rtx_REG (reg_mode, 2);
13769 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13770 GEN_INT (sp_offset + 5 * reg_size));
13771 mem = gen_rtx_MEM (reg_mode, addr);
13772 set_mem_alias_set (mem, rs6000_sr_alias_set);
13773
13774 insn = emit_move_insn (mem, reg);
f676971a 13775 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
fc4767bb
JJ
13776 NULL_RTX, NULL_RTX);
13777 PATTERN (insn) = gen_blockage ();
13778 }
13779
83720594
RH
13780 for (i = 0; ; ++i)
13781 {
83720594
RH
13782 regno = EH_RETURN_DATA_REGNO (i);
13783 if (regno == INVALID_REGNUM)
13784 break;
13785
89e7058f
AH
13786 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13787 info->ehrd_offset + sp_offset
13788 + reg_size * (int) i,
13789 info->total_size);
83720594
RH
13790 }
13791 }
13792
9ebbca7d 13793 /* Save lr if we used it. */
d62294f5 13794 if (! info->world_save_p && info->lr_save_p)
9ebbca7d
GK
13795 {
13796 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13797 GEN_INT (info->lr_save_offset + sp_offset));
13798 rtx reg = gen_rtx_REG (Pmode, 0);
13799 rtx mem = gen_rtx_MEM (Pmode, addr);
13800 /* This should not be of rs6000_sr_alias_set, because of
13801 __builtin_return_address. */
f676971a 13802
9ebbca7d 13803 insn = emit_move_insn (mem, reg);
f676971a 13804 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13805 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13806 }
13807
13808 /* Save CR if we use any that must be preserved. */
d62294f5 13809 if (! info->world_save_p && info->cr_save_p)
9ebbca7d
GK
13810 {
13811 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13812 GEN_INT (info->cr_save_offset + sp_offset));
13813 rtx mem = gen_rtx_MEM (SImode, addr);
f8a57be8
GK
13814 /* See the large comment above about why CR2_REGNO is used. */
13815 rtx magic_eh_cr_reg = gen_rtx_REG (SImode, CR2_REGNO);
ba4828e0
RK
13816
13817 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13818
13819 /* If r12 was used to hold the original sp, copy cr into r0 now
13820 that it's free. */
13821 if (REGNO (frame_reg_rtx) == 12)
13822 {
f8a57be8
GK
13823 rtx set;
13824
9ebbca7d 13825 cr_save_rtx = gen_rtx_REG (SImode, 0);
f8a57be8
GK
13826 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13827 RTX_FRAME_RELATED_P (insn) = 1;
13828 set = gen_rtx_SET (VOIDmode, cr_save_rtx, magic_eh_cr_reg);
13829 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13830 set,
13831 REG_NOTES (insn));
f676971a 13832
9ebbca7d
GK
13833 }
13834 insn = emit_move_insn (mem, cr_save_rtx);
13835
f676971a 13836 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13837 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13838 }
13839
f676971a 13840 /* Update stack and set back pointer unless this is V.4,
9ebbca7d 13841 for which it was done previously. */
d62294f5 13842 if (! info->world_save_p && info->push_p
fc4767bb 13843 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
13844 rs6000_emit_allocate_stack (info->total_size, FALSE);
13845
13846 /* Set frame pointer, if needed. */
13847 if (frame_pointer_needed)
13848 {
f676971a 13849 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
13850 sp_reg_rtx);
13851 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 13852 }
9878760c 13853
1db02437 13854 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 13855 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 13856 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 13857 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
c4ad648e
AM
13858 {
13859 /* If emit_load_toc_table will use the link register, we need to save
13860 it. We use R12 for this purpose because emit_load_toc_table
13861 can use register 0. This allows us to use a plain 'blr' to return
13862 from the procedure more often. */
13863 int save_LR_around_toc_setup = (TARGET_ELF
13864 && DEFAULT_ABI != ABI_AIX
13865 && flag_pic
13866 && ! info->lr_save_p
13867 && EDGE_COUNT (EXIT_BLOCK_PTR->preds) > 0);
13868 if (save_LR_around_toc_setup)
13869 {
13870 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f8a57be8 13871
c4ad648e
AM
13872 insn = emit_move_insn (frame_ptr_rtx, lr);
13873 rs6000_maybe_dead (insn);
13874 RTX_FRAME_RELATED_P (insn) = 1;
f8a57be8 13875
c4ad648e 13876 rs6000_emit_load_toc_table (TRUE);
f8a57be8 13877
c4ad648e
AM
13878 insn = emit_move_insn (lr, frame_ptr_rtx);
13879 rs6000_maybe_dead (insn);
13880 RTX_FRAME_RELATED_P (insn) = 1;
13881 }
13882 else
13883 rs6000_emit_load_toc_table (TRUE);
13884 }
ee890fe2 13885
fcce224d 13886#if TARGET_MACHO
ee890fe2
SS
13887 if (DEFAULT_ABI == ABI_DARWIN
13888 && flag_pic && current_function_uses_pic_offset_table)
13889 {
f8a57be8 13890 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
11abc112 13891 rtx src = machopic_function_base_sym ();
ee890fe2 13892
f8a57be8 13893 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (lr, src)));
ee890fe2 13894
f676971a 13895 insn = emit_move_insn (gen_rtx_REG (Pmode,
f8a57be8
GK
13896 RS6000_PIC_OFFSET_TABLE_REGNUM),
13897 lr);
13898 rs6000_maybe_dead (insn);
ee890fe2 13899 }
fcce224d 13900#endif
9ebbca7d
GK
13901}
13902
9ebbca7d 13903/* Write function prologue. */
a4f6c312 13904
08c148a8 13905static void
f676971a 13906rs6000_output_function_prologue (FILE *file,
a2369ed3 13907 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
13908{
13909 rs6000_stack_t *info = rs6000_stack_info ();
13910
4697a36c
MM
13911 if (TARGET_DEBUG_STACK)
13912 debug_stack_info (info);
9878760c 13913
a4f6c312
SS
13914 /* Write .extern for any function we will call to save and restore
13915 fp values. */
13916 if (info->first_fp_reg_save < 64
13917 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 13918 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 13919 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
13920 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
13921 RESTORE_FP_SUFFIX);
9878760c 13922
c764f757
RK
13923 /* Write .extern for AIX common mode routines, if needed. */
13924 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
13925 {
f6709c70
JW
13926 fputs ("\t.extern __mulh\n", file);
13927 fputs ("\t.extern __mull\n", file);
13928 fputs ("\t.extern __divss\n", file);
13929 fputs ("\t.extern __divus\n", file);
13930 fputs ("\t.extern __quoss\n", file);
13931 fputs ("\t.extern __quous\n", file);
c764f757
RK
13932 common_mode_defined = 1;
13933 }
9878760c 13934
9ebbca7d 13935 if (! HAVE_prologue)
979721f8 13936 {
9ebbca7d 13937 start_sequence ();
9dda4cc8 13938
a4f6c312
SS
13939 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
13940 the "toplevel" insn chain. */
2e040219 13941 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13942 rs6000_emit_prologue ();
2e040219 13943 emit_note (NOTE_INSN_DELETED);
178c3eff 13944
a3c9585f 13945 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
13946 {
13947 rtx insn;
13948 unsigned addr = 0;
13949 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
13950 {
13951 INSN_ADDRESSES_NEW (insn, addr);
13952 addr += 4;
13953 }
13954 }
9dda4cc8 13955
9ebbca7d 13956 if (TARGET_DEBUG_STACK)
a4f6c312
SS
13957 debug_rtx_list (get_insns (), 100);
13958 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 13959 end_sequence ();
979721f8
MM
13960 }
13961
9ebbca7d
GK
13962 rs6000_pic_labelno++;
13963}
f676971a 13964
9ebbca7d 13965/* Emit function epilogue as insns.
9878760c 13966
9ebbca7d
GK
13967 At present, dwarf2out_frame_debug_expr doesn't understand
13968 register restores, so we don't bother setting RTX_FRAME_RELATED_P
13969 anywhere in the epilogue. Most of the insns below would in any case
13970 need special notes to explain where r11 is in relation to the stack. */
9878760c 13971
9ebbca7d 13972void
a2369ed3 13973rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
13974{
13975 rs6000_stack_t *info;
13976 int restoring_FPRs_inline;
13977 int using_load_multiple;
13978 int using_mfcr_multiple;
13979 int use_backchain_to_restore_sp;
13980 int sp_offset = 0;
13981 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
13982 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 13983 enum machine_mode reg_mode = Pmode;
327e5343 13984 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
13985 int i;
13986
c19de7aa
AH
13987 info = rs6000_stack_info ();
13988
13989 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13990 {
13991 reg_mode = V2SImode;
13992 reg_size = 8;
13993 }
13994
9ebbca7d 13995 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
13996 && (!TARGET_SPE_ABI
13997 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
13998 && info->first_gp_reg_save < 31);
13999 restoring_FPRs_inline = (sibcall
83720594 14000 || current_function_calls_eh_return
9ebbca7d
GK
14001 || info->first_fp_reg_save == 64
14002 || FP_SAVE_INLINE (info->first_fp_reg_save));
f676971a 14003 use_backchain_to_restore_sp = (frame_pointer_needed
9ebbca7d
GK
14004 || current_function_calls_alloca
14005 || info->total_size > 32767);
14006 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
14007 || rs6000_cpu == PROCESSOR_PPC603
14008 || rs6000_cpu == PROCESSOR_PPC750
14009 || optimize_size);
14010
d62294f5
FJ
14011 if (info->world_save_p)
14012 {
14013 int i, j;
14014 char rname[30];
14015 const char *alloc_rname;
14016 rtvec p;
14017
14018 /* eh_rest_world_r10 will return to the location saved in the LR
c4ad648e
AM
14019 stack slot (which is not likely to be our caller.)
14020 Input: R10 -- stack adjustment. Clobbers R0, R11, R12, R7, R8.
14021 rest_world is similar, except any R10 parameter is ignored.
14022 The exception-handling stuff that was here in 2.95 is no
14023 longer necessary. */
d62294f5
FJ
14024
14025 p = rtvec_alloc (9
14026 + 1
f676971a 14027 + 32 - info->first_gp_reg_save
c4ad648e
AM
14028 + LAST_ALTIVEC_REGNO + 1 - info->first_altivec_reg_save
14029 + 63 + 1 - info->first_fp_reg_save);
d62294f5 14030
c4ad648e
AM
14031 strcpy (rname, ((current_function_calls_eh_return) ?
14032 "*eh_rest_world_r10" : "*rest_world"));
d62294f5
FJ
14033 alloc_rname = ggc_strdup (rname);
14034
14035 j = 0;
14036 RTVEC_ELT (p, j++) = gen_rtx_RETURN (VOIDmode);
14037 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
c4ad648e
AM
14038 gen_rtx_REG (Pmode,
14039 LINK_REGISTER_REGNUM));
d62294f5 14040 RTVEC_ELT (p, j++)
c4ad648e 14041 = gen_rtx_USE (VOIDmode, gen_rtx_SYMBOL_REF (Pmode, alloc_rname));
d62294f5 14042 /* The instruction pattern requires a clobber here;
c4ad648e 14043 it is shared with the restVEC helper. */
d62294f5 14044 RTVEC_ELT (p, j++)
c4ad648e 14045 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
d62294f5
FJ
14046
14047 {
c4ad648e
AM
14048 /* CR register traditionally saved as CR2. */
14049 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
14050 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14051 GEN_INT (info->cr_save_offset));
14052 rtx mem = gen_rtx_MEM (reg_mode, addr);
14053 set_mem_alias_set (mem, rs6000_sr_alias_set);
14054
14055 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
d62294f5
FJ
14056 }
14057
14058 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
c4ad648e
AM
14059 {
14060 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
14061 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14062 GEN_INT (info->gp_save_offset
14063 + reg_size * i));
14064 rtx mem = gen_rtx_MEM (reg_mode, addr);
14065 set_mem_alias_set (mem, rs6000_sr_alias_set);
14066
14067 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14068 }
d62294f5 14069 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
c4ad648e
AM
14070 {
14071 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
14072 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14073 GEN_INT (info->altivec_save_offset
14074 + 16 * i));
14075 rtx mem = gen_rtx_MEM (V4SImode, addr);
14076 set_mem_alias_set (mem, rs6000_sr_alias_set);
14077
14078 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14079 }
d62294f5 14080 for (i = 0; info->first_fp_reg_save + i <= 63; i++)
c4ad648e
AM
14081 {
14082 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
14083 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14084 GEN_INT (info->fp_save_offset
14085 + 8 * i));
14086 rtx mem = gen_rtx_MEM (DFmode, addr);
14087 set_mem_alias_set (mem, rs6000_sr_alias_set);
14088
14089 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14090 }
d62294f5 14091 RTVEC_ELT (p, j++)
c4ad648e 14092 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 0));
d62294f5 14093 RTVEC_ELT (p, j++)
c4ad648e 14094 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 12));
d62294f5 14095 RTVEC_ELT (p, j++)
c4ad648e 14096 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 7));
d62294f5 14097 RTVEC_ELT (p, j++)
c4ad648e 14098 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 8));
d62294f5 14099 RTVEC_ELT (p, j++)
c4ad648e 14100 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 10));
d62294f5
FJ
14101 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
14102
14103 return;
14104 }
14105
9ebbca7d
GK
14106 /* If we have a frame pointer, a call to alloca, or a large stack
14107 frame, restore the old stack pointer using the backchain. Otherwise,
14108 we know what size to update it with. */
14109 if (use_backchain_to_restore_sp)
bacbde18 14110 {
9ebbca7d
GK
14111 /* Under V.4, don't reset the stack pointer until after we're done
14112 loading the saved registers. */
f607bc57 14113 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 14114 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 14115
9ebbca7d
GK
14116 emit_move_insn (frame_reg_rtx,
14117 gen_rtx_MEM (Pmode, sp_reg_rtx));
f676971a 14118
bacbde18 14119 }
9ebbca7d 14120 else if (info->push_p)
85638c0d 14121 {
fc4767bb
JJ
14122 if (DEFAULT_ABI == ABI_V4
14123 || current_function_calls_eh_return)
9ebbca7d
GK
14124 sp_offset = info->total_size;
14125 else
14126 {
14127 emit_insn (TARGET_32BIT
14128 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
14129 GEN_INT (info->total_size))
14130 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
14131 GEN_INT (info->total_size)));
14132 }
85638c0d 14133 }
f676971a 14134
9aa86737
AH
14135 /* Restore AltiVec registers if needed. */
14136 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
14137 {
14138 int i;
14139
14140 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
14141 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
14142 {
14143 rtx addr, areg, mem;
14144
14145 areg = gen_rtx_REG (Pmode, 0);
14146 emit_move_insn
14147 (areg, GEN_INT (info->altivec_save_offset
14148 + sp_offset
14149 + 16 * (i - info->first_altivec_reg_save)));
14150
14151 /* AltiVec addressing mode is [reg+reg]. */
14152 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
14153 mem = gen_rtx_MEM (V4SImode, addr);
14154 set_mem_alias_set (mem, rs6000_sr_alias_set);
14155
14156 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
14157 }
14158 }
14159
14160 /* Restore VRSAVE if needed. */
44688022 14161 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
4d774ff8 14162 && info->vrsave_mask != 0)
9aa86737
AH
14163 {
14164 rtx addr, mem, reg;
14165
14166 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14167 GEN_INT (info->vrsave_save_offset + sp_offset));
14168 mem = gen_rtx_MEM (SImode, addr);
14169 set_mem_alias_set (mem, rs6000_sr_alias_set);
14170 reg = gen_rtx_REG (SImode, 12);
14171 emit_move_insn (reg, mem);
14172
14173 emit_insn (generate_set_vrsave (reg, info, 1));
14174 }
14175
9ebbca7d
GK
14176 /* Get the old lr if we saved it. */
14177 if (info->lr_save_p)
b6c9286a 14178 {
a3170dc6
AH
14179 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
14180 info->lr_save_offset + sp_offset);
ba4828e0
RK
14181
14182 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 14183
9ebbca7d 14184 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 14185 }
f676971a 14186
9ebbca7d
GK
14187 /* Get the old cr if we saved it. */
14188 if (info->cr_save_p)
14189 {
14190 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14191 GEN_INT (info->cr_save_offset + sp_offset));
14192 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
14193
14194 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 14195
9ebbca7d
GK
14196 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
14197 }
f676971a 14198
9ebbca7d 14199 /* Set LR here to try to overlap restores below. */
4697a36c 14200 if (info->lr_save_p)
9ebbca7d
GK
14201 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
14202 gen_rtx_REG (Pmode, 0));
f676971a 14203
83720594
RH
14204 /* Load exception handler data registers, if needed. */
14205 if (current_function_calls_eh_return)
14206 {
78e1b90d
DE
14207 unsigned int i, regno;
14208
fc4767bb
JJ
14209 if (TARGET_AIX)
14210 {
14211 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14212 GEN_INT (sp_offset + 5 * reg_size));
14213 rtx mem = gen_rtx_MEM (reg_mode, addr);
14214
14215 set_mem_alias_set (mem, rs6000_sr_alias_set);
14216
14217 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
14218 }
14219
83720594
RH
14220 for (i = 0; ; ++i)
14221 {
a3170dc6 14222 rtx mem;
83720594
RH
14223
14224 regno = EH_RETURN_DATA_REGNO (i);
14225 if (regno == INVALID_REGNUM)
14226 break;
14227
a3170dc6
AH
14228 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
14229 info->ehrd_offset + sp_offset
14230 + reg_size * (int) i);
ba4828e0 14231 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
14232
14233 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
14234 }
14235 }
f676971a 14236
9ebbca7d
GK
14237 /* Restore GPRs. This is done as a PARALLEL if we are using
14238 the load-multiple instructions. */
14239 if (using_load_multiple)
979721f8 14240 {
9ebbca7d
GK
14241 rtvec p;
14242 p = rtvec_alloc (32 - info->first_gp_reg_save);
14243 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 14244 {
f676971a
EC
14245 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14246 GEN_INT (info->gp_save_offset
14247 + sp_offset
9ebbca7d
GK
14248 + reg_size * i));
14249 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
14250
14251 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14252
f676971a 14253 RTVEC_ELT (p, i) =
9ebbca7d
GK
14254 gen_rtx_SET (VOIDmode,
14255 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
14256 mem);
979721f8 14257 }
9ebbca7d 14258 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 14259 }
9ebbca7d
GK
14260 else
14261 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 14262 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
14263 && (! call_used_regs[info->first_gp_reg_save+i]
14264 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14265 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 14266 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 14267 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 14268 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d 14269 {
f676971a
EC
14270 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14271 GEN_INT (info->gp_save_offset
14272 + sp_offset
9ebbca7d
GK
14273 + reg_size * i));
14274 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 14275
a3170dc6 14276 /* Restore 64-bit quantities for SPE. */
c19de7aa 14277 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
14278 {
14279 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
14280 rtx b;
14281
14282 if (!SPE_CONST_OFFSET_OK (offset))
14283 {
14284 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
14285 emit_move_insn (b, GEN_INT (offset));
14286 }
14287 else
14288 b = GEN_INT (offset);
14289
14290 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
14291 mem = gen_rtx_MEM (V2SImode, addr);
14292 }
14293
ba4828e0 14294 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14295
f676971a 14296 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 14297 info->first_gp_reg_save + i), mem);
9ebbca7d 14298 }
9878760c 14299
9ebbca7d
GK
14300 /* Restore fpr's if we need to do it without calling a function. */
14301 if (restoring_FPRs_inline)
14302 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 14303 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d
GK
14304 && ! call_used_regs[info->first_fp_reg_save+i]))
14305 {
14306 rtx addr, mem;
14307 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a
EC
14308 GEN_INT (info->fp_save_offset
14309 + sp_offset
a4f6c312 14310 + 8 * i));
9ebbca7d 14311 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14312 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14313
f676971a 14314 emit_move_insn (gen_rtx_REG (DFmode,
9ebbca7d
GK
14315 info->first_fp_reg_save + i),
14316 mem);
14317 }
8d30c4ee 14318
9ebbca7d
GK
14319 /* If we saved cr, restore it here. Just those that were used. */
14320 if (info->cr_save_p)
979721f8 14321 {
9ebbca7d 14322 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 14323 int count = 0;
f676971a 14324
9ebbca7d 14325 if (using_mfcr_multiple)
979721f8 14326 {
9ebbca7d
GK
14327 for (i = 0; i < 8; i++)
14328 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 14329 count++;
9ebbca7d 14330 if (count == 0)
e35b9579
GK
14331 abort ();
14332 }
14333
14334 if (using_mfcr_multiple && count > 1)
14335 {
14336 rtvec p;
14337 int ndx;
f676971a 14338
e35b9579 14339 p = rtvec_alloc (count);
9ebbca7d 14340
e35b9579 14341 ndx = 0;
9ebbca7d
GK
14342 for (i = 0; i < 8; i++)
14343 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
14344 {
14345 rtvec r = rtvec_alloc (2);
14346 RTVEC_ELT (r, 0) = r12_rtx;
14347 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 14348 RTVEC_ELT (p, ndx) =
f676971a 14349 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 14350 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 14351 ndx++;
9ebbca7d
GK
14352 }
14353 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
14354 if (ndx != count)
14355 abort ();
979721f8
MM
14356 }
14357 else
9ebbca7d
GK
14358 for (i = 0; i < 8; i++)
14359 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 14360 {
f676971a 14361 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
9ebbca7d
GK
14362 CR0_REGNO+i),
14363 r12_rtx));
979721f8 14364 }
979721f8
MM
14365 }
14366
9ebbca7d
GK
14367 /* If this is V.4, unwind the stack pointer after all of the loads
14368 have been done. We need to emit a block here so that sched
14369 doesn't decide to move the sp change before the register restores
14370 (which may not have any obvious dependency on the stack). This
14371 doesn't hurt performance, because there is no scheduling that can
14372 be done after this point. */
fc4767bb
JJ
14373 if (DEFAULT_ABI == ABI_V4
14374 || current_function_calls_eh_return)
b6c9286a 14375 {
9ebbca7d 14376 if (frame_reg_rtx != sp_reg_rtx)
c4ad648e 14377 rs6000_emit_stack_tie ();
b6c9286a 14378
9ebbca7d 14379 if (use_backchain_to_restore_sp)
b6c9286a 14380 {
9ebbca7d 14381 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 14382 }
9ebbca7d 14383 else if (sp_offset != 0)
13f1623b 14384 {
5b71a4e7 14385 emit_insn (TARGET_32BIT
9ebbca7d
GK
14386 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
14387 GEN_INT (sp_offset))
14388 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
14389 GEN_INT (sp_offset)));
13f1623b 14390 }
9ebbca7d 14391 }
b6c9286a 14392
83720594
RH
14393 if (current_function_calls_eh_return)
14394 {
14395 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 14396 emit_insn (TARGET_32BIT
83720594
RH
14397 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
14398 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
14399 }
14400
9ebbca7d
GK
14401 if (!sibcall)
14402 {
14403 rtvec p;
14404 if (! restoring_FPRs_inline)
14405 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
14406 else
14407 p = rtvec_alloc (2);
b6c9286a 14408
e35b9579 14409 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
f676971a
EC
14410 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
14411 gen_rtx_REG (Pmode,
9ebbca7d 14412 LINK_REGISTER_REGNUM));
9ebbca7d
GK
14413
14414 /* If we have to restore more than two FP registers, branch to the
14415 restore function. It will return to our caller. */
14416 if (! restoring_FPRs_inline)
14417 {
14418 int i;
14419 char rname[30];
520a57c8 14420 const char *alloc_rname;
979721f8 14421
f676971a 14422 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
9ebbca7d 14423 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 14424 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
14425 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
14426 gen_rtx_SYMBOL_REF (Pmode,
14427 alloc_rname));
b6c9286a 14428
9ebbca7d
GK
14429 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
14430 {
14431 rtx addr, mem;
14432 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
14433 GEN_INT (info->fp_save_offset + 8*i));
14434 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14435 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14436
f676971a 14437 RTVEC_ELT (p, i+3) =
9ebbca7d
GK
14438 gen_rtx_SET (VOIDmode,
14439 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
14440 mem);
b6c9286a
MM
14441 }
14442 }
f676971a 14443
9ebbca7d 14444 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 14445 }
9878760c
RK
14446}
14447
14448/* Write function epilogue. */
14449
08c148a8 14450static void
f676971a 14451rs6000_output_function_epilogue (FILE *file,
a2369ed3 14452 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 14453{
4697a36c 14454 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 14455
9ebbca7d 14456 if (! HAVE_epilogue)
9878760c 14457 {
9ebbca7d
GK
14458 rtx insn = get_last_insn ();
14459 /* If the last insn was a BARRIER, we don't have to write anything except
14460 the trace table. */
14461 if (GET_CODE (insn) == NOTE)
14462 insn = prev_nonnote_insn (insn);
14463 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 14464 {
9ebbca7d
GK
14465 /* This is slightly ugly, but at least we don't have two
14466 copies of the epilogue-emitting code. */
14467 start_sequence ();
14468
14469 /* A NOTE_INSN_DELETED is supposed to be at the start
14470 and end of the "toplevel" insn chain. */
2e040219 14471 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14472 rs6000_emit_epilogue (FALSE);
2e040219 14473 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14474
a3c9585f 14475 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
14476 {
14477 rtx insn;
14478 unsigned addr = 0;
14479 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
14480 {
14481 INSN_ADDRESSES_NEW (insn, addr);
14482 addr += 4;
14483 }
14484 }
14485
9ebbca7d 14486 if (TARGET_DEBUG_STACK)
a4f6c312
SS
14487 debug_rtx_list (get_insns (), 100);
14488 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 14489 end_sequence ();
4697a36c 14490 }
9878760c 14491 }
b4ac57ab 14492
efdba735
SH
14493#if TARGET_MACHO
14494 macho_branch_islands ();
0e5da0be
GK
14495 /* Mach-O doesn't support labels at the end of objects, so if
14496 it looks like we might want one, insert a NOP. */
14497 {
14498 rtx insn = get_last_insn ();
14499 while (insn
14500 && NOTE_P (insn)
14501 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
14502 insn = PREV_INSN (insn);
f676971a
EC
14503 if (insn
14504 && (LABEL_P (insn)
0e5da0be
GK
14505 || (NOTE_P (insn)
14506 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
14507 fputs ("\tnop\n", file);
14508 }
14509#endif
14510
9b30bae2 14511 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
14512 on its format.
14513
14514 We don't output a traceback table if -finhibit-size-directive was
14515 used. The documentation for -finhibit-size-directive reads
14516 ``don't output a @code{.size} assembler directive, or anything
14517 else that would cause trouble if the function is split in the
14518 middle, and the two halves are placed at locations far apart in
14519 memory.'' The traceback table has this property, since it
14520 includes the offset from the start of the function to the
4d30c363
MM
14521 traceback table itself.
14522
14523 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 14524 different traceback table. */
57ac7be9
AM
14525 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
14526 && rs6000_traceback != traceback_none)
9b30bae2 14527 {
69c75916 14528 const char *fname = NULL;
3ac88239 14529 const char *language_string = lang_hooks.name;
6041bf2f 14530 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 14531 int i;
57ac7be9
AM
14532 int optional_tbtab;
14533
14534 if (rs6000_traceback == traceback_full)
14535 optional_tbtab = 1;
14536 else if (rs6000_traceback == traceback_part)
14537 optional_tbtab = 0;
14538 else
14539 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 14540
69c75916
AM
14541 if (optional_tbtab)
14542 {
14543 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
14544 while (*fname == '.') /* V.4 encodes . in the name */
14545 fname++;
14546
14547 /* Need label immediately before tbtab, so we can compute
14548 its offset from the function start. */
14549 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
14550 ASM_OUTPUT_LABEL (file, fname);
14551 }
314fc5a9
ILT
14552
14553 /* The .tbtab pseudo-op can only be used for the first eight
14554 expressions, since it can't handle the possibly variable
14555 length fields that follow. However, if you omit the optional
14556 fields, the assembler outputs zeros for all optional fields
14557 anyways, giving each variable length field is minimum length
14558 (as defined in sys/debug.h). Thus we can not use the .tbtab
14559 pseudo-op at all. */
14560
14561 /* An all-zero word flags the start of the tbtab, for debuggers
14562 that have to find it by searching forward from the entry
14563 point or from the current pc. */
19d2d16f 14564 fputs ("\t.long 0\n", file);
314fc5a9
ILT
14565
14566 /* Tbtab format type. Use format type 0. */
19d2d16f 14567 fputs ("\t.byte 0,", file);
314fc5a9 14568
5fc921c1
DE
14569 /* Language type. Unfortunately, there does not seem to be any
14570 official way to discover the language being compiled, so we
14571 use language_string.
14572 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
14573 Java is 13. Objective-C is 14. */
14574 if (! strcmp (language_string, "GNU C"))
314fc5a9 14575 i = 0;
6de9cd9a
DN
14576 else if (! strcmp (language_string, "GNU F77")
14577 || ! strcmp (language_string, "GNU F95"))
314fc5a9 14578 i = 1;
8b83775b 14579 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 14580 i = 2;
5fc921c1
DE
14581 else if (! strcmp (language_string, "GNU Ada"))
14582 i = 3;
314fc5a9
ILT
14583 else if (! strcmp (language_string, "GNU C++"))
14584 i = 9;
9517ead8
AG
14585 else if (! strcmp (language_string, "GNU Java"))
14586 i = 13;
5fc921c1
DE
14587 else if (! strcmp (language_string, "GNU Objective-C"))
14588 i = 14;
314fc5a9
ILT
14589 else
14590 abort ();
14591 fprintf (file, "%d,", i);
14592
14593 /* 8 single bit fields: global linkage (not set for C extern linkage,
14594 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
14595 from start of procedure stored in tbtab, internal function, function
14596 has controlled storage, function has no toc, function uses fp,
14597 function logs/aborts fp operations. */
14598 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
14599 fprintf (file, "%d,",
14600 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
14601
14602 /* 6 bitfields: function is interrupt handler, name present in
14603 proc table, function calls alloca, on condition directives
14604 (controls stack walks, 3 bits), saves condition reg, saves
14605 link reg. */
14606 /* The `function calls alloca' bit seems to be set whenever reg 31 is
14607 set up as a frame pointer, even when there is no alloca call. */
14608 fprintf (file, "%d,",
6041bf2f
DE
14609 ((optional_tbtab << 6)
14610 | ((optional_tbtab & frame_pointer_needed) << 5)
14611 | (info->cr_save_p << 1)
14612 | (info->lr_save_p)));
314fc5a9 14613
6041bf2f 14614 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
14615 (6 bits). */
14616 fprintf (file, "%d,",
4697a36c 14617 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
14618
14619 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
14620 fprintf (file, "%d,", (32 - first_reg_to_save ()));
14621
6041bf2f
DE
14622 if (optional_tbtab)
14623 {
14624 /* Compute the parameter info from the function decl argument
14625 list. */
14626 tree decl;
14627 int next_parm_info_bit = 31;
314fc5a9 14628
6041bf2f
DE
14629 for (decl = DECL_ARGUMENTS (current_function_decl);
14630 decl; decl = TREE_CHAIN (decl))
14631 {
14632 rtx parameter = DECL_INCOMING_RTL (decl);
14633 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 14634
6041bf2f
DE
14635 if (GET_CODE (parameter) == REG)
14636 {
14637 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
14638 {
14639 int bits;
14640
14641 float_parms++;
14642
14643 if (mode == SFmode)
14644 bits = 0x2;
fcce224d 14645 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
14646 bits = 0x3;
14647 else
14648 abort ();
14649
14650 /* If only one bit will fit, don't or in this entry. */
14651 if (next_parm_info_bit > 0)
14652 parm_info |= (bits << (next_parm_info_bit - 1));
14653 next_parm_info_bit -= 2;
14654 }
14655 else
14656 {
14657 fixed_parms += ((GET_MODE_SIZE (mode)
14658 + (UNITS_PER_WORD - 1))
14659 / UNITS_PER_WORD);
14660 next_parm_info_bit -= 1;
14661 }
14662 }
14663 }
14664 }
314fc5a9
ILT
14665
14666 /* Number of fixed point parameters. */
14667 /* This is actually the number of words of fixed point parameters; thus
14668 an 8 byte struct counts as 2; and thus the maximum value is 8. */
14669 fprintf (file, "%d,", fixed_parms);
14670
14671 /* 2 bitfields: number of floating point parameters (7 bits), parameters
14672 all on stack. */
14673 /* This is actually the number of fp registers that hold parameters;
14674 and thus the maximum value is 13. */
14675 /* Set parameters on stack bit if parameters are not in their original
14676 registers, regardless of whether they are on the stack? Xlc
14677 seems to set the bit when not optimizing. */
14678 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
14679
6041bf2f
DE
14680 if (! optional_tbtab)
14681 return;
14682
314fc5a9
ILT
14683 /* Optional fields follow. Some are variable length. */
14684
14685 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
14686 11 double float. */
14687 /* There is an entry for each parameter in a register, in the order that
14688 they occur in the parameter list. Any intervening arguments on the
14689 stack are ignored. If the list overflows a long (max possible length
14690 34 bits) then completely leave off all elements that don't fit. */
14691 /* Only emit this long if there was at least one parameter. */
14692 if (fixed_parms || float_parms)
14693 fprintf (file, "\t.long %d\n", parm_info);
14694
14695 /* Offset from start of code to tb table. */
19d2d16f 14696 fputs ("\t.long ", file);
314fc5a9 14697 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
85b776df
AM
14698 if (TARGET_AIX)
14699 RS6000_OUTPUT_BASENAME (file, fname);
14700 else
14701 assemble_name (file, fname);
14702 putc ('-', file);
14703 rs6000_output_function_entry (file, fname);
19d2d16f 14704 putc ('\n', file);
314fc5a9
ILT
14705
14706 /* Interrupt handler mask. */
14707 /* Omit this long, since we never set the interrupt handler bit
14708 above. */
14709
14710 /* Number of CTL (controlled storage) anchors. */
14711 /* Omit this long, since the has_ctl bit is never set above. */
14712
14713 /* Displacement into stack of each CTL anchor. */
14714 /* Omit this list of longs, because there are no CTL anchors. */
14715
14716 /* Length of function name. */
69c75916
AM
14717 if (*fname == '*')
14718 ++fname;
296b8152 14719 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
14720
14721 /* Function name. */
14722 assemble_string (fname, strlen (fname));
14723
14724 /* Register for alloca automatic storage; this is always reg 31.
14725 Only emit this if the alloca bit was set above. */
14726 if (frame_pointer_needed)
19d2d16f 14727 fputs ("\t.byte 31\n", file);
b1765bde
DE
14728
14729 fputs ("\t.align 2\n", file);
9b30bae2 14730 }
9878760c 14731}
17167fd8 14732\f
a4f6c312
SS
14733/* A C compound statement that outputs the assembler code for a thunk
14734 function, used to implement C++ virtual function calls with
14735 multiple inheritance. The thunk acts as a wrapper around a virtual
14736 function, adjusting the implicit object parameter before handing
14737 control off to the real function.
14738
14739 First, emit code to add the integer DELTA to the location that
14740 contains the incoming first argument. Assume that this argument
14741 contains a pointer, and is the one used to pass the `this' pointer
14742 in C++. This is the incoming argument *before* the function
14743 prologue, e.g. `%o0' on a sparc. The addition must preserve the
14744 values of all other incoming arguments.
17167fd8
MM
14745
14746 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
14747 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
14748 not touch the return address. Hence returning from FUNCTION will
14749 return to whoever called the current `thunk'.
17167fd8 14750
a4f6c312
SS
14751 The effect must be as if FUNCTION had been called directly with the
14752 adjusted first argument. This macro is responsible for emitting
14753 all of the code for a thunk function; output_function_prologue()
14754 and output_function_epilogue() are not invoked.
17167fd8 14755
a4f6c312
SS
14756 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
14757 been extracted from it.) It might possibly be useful on some
14758 targets, but probably not.
17167fd8 14759
a4f6c312
SS
14760 If you do not define this macro, the target-independent code in the
14761 C++ frontend will generate a less efficient heavyweight thunk that
14762 calls FUNCTION instead of jumping to it. The generic approach does
14763 not support varargs. */
17167fd8 14764
3961e8fe 14765static void
f676971a
EC
14766rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
14767 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
a2369ed3 14768 tree function)
17167fd8 14769{
5b71a4e7 14770 rtx this, insn, funexp;
17167fd8 14771
5b71a4e7 14772 reload_completed = 1;
fe3ad572 14773 epilogue_completed = 1;
5b71a4e7 14774 no_new_pseudos = 1;
6429e3be 14775 reset_block_changes ();
56a7189a 14776
5b71a4e7 14777 /* Mark the end of the (empty) prologue. */
2e040219 14778 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 14779
5b71a4e7
DE
14780 /* Find the "this" pointer. If the function returns a structure,
14781 the structure return pointer is in r3. */
61f71b34 14782 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 14783 this = gen_rtx_REG (Pmode, 4);
56a7189a 14784 else
5b71a4e7 14785 this = gen_rtx_REG (Pmode, 3);
17167fd8 14786
5b71a4e7
DE
14787 /* Apply the constant offset, if required. */
14788 if (delta)
14789 {
14790 rtx delta_rtx = GEN_INT (delta);
14791 emit_insn (TARGET_32BIT
14792 ? gen_addsi3 (this, this, delta_rtx)
14793 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
14794 }
14795
5b71a4e7
DE
14796 /* Apply the offset from the vtable, if required. */
14797 if (vcall_offset)
17167fd8 14798 {
5b71a4e7
DE
14799 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
14800 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 14801
5b71a4e7 14802 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
14803 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
14804 {
14805 emit_insn (TARGET_32BIT
14806 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
14807 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
14808 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
14809 }
14810 else
14811 {
14812 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
14813
14814 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
14815 }
5b71a4e7
DE
14816 emit_insn (TARGET_32BIT
14817 ? gen_addsi3 (this, this, tmp)
14818 : gen_adddi3 (this, this, tmp));
17167fd8
MM
14819 }
14820
5b71a4e7
DE
14821 /* Generate a tail call to the target function. */
14822 if (!TREE_USED (function))
14823 {
14824 assemble_external (function);
14825 TREE_USED (function) = 1;
14826 }
14827 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 14828 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
14829
14830#if TARGET_MACHO
ab82a49f 14831 if (MACHOPIC_INDIRECT)
5b71a4e7 14832 funexp = machopic_indirect_call_target (funexp);
ee890fe2 14833#endif
5b71a4e7
DE
14834
14835 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
14836 generate sibcall RTL explicitly to avoid constraint abort. */
14837 insn = emit_call_insn (
14838 gen_rtx_PARALLEL (VOIDmode,
14839 gen_rtvec (4,
14840 gen_rtx_CALL (VOIDmode,
14841 funexp, const0_rtx),
14842 gen_rtx_USE (VOIDmode, const0_rtx),
14843 gen_rtx_USE (VOIDmode,
14844 gen_rtx_REG (SImode,
14845 LINK_REGISTER_REGNUM)),
14846 gen_rtx_RETURN (VOIDmode))));
14847 SIBLING_CALL_P (insn) = 1;
14848 emit_barrier ();
14849
14850 /* Run just enough of rest_of_compilation to get the insns emitted.
14851 There's not really enough bulk here to make other passes such as
14852 instruction scheduling worth while. Note that use_thunk calls
14853 assemble_start_function and assemble_end_function. */
14854 insn = get_insns ();
a2855205 14855 insn_locators_initialize ();
5b71a4e7
DE
14856 shorten_branches (insn);
14857 final_start_function (insn, file, 1);
14858 final (insn, file, 1, 0);
14859 final_end_function ();
14860
14861 reload_completed = 0;
fe3ad572 14862 epilogue_completed = 0;
5b71a4e7 14863 no_new_pseudos = 0;
9ebbca7d 14864}
9ebbca7d
GK
14865\f
14866/* A quick summary of the various types of 'constant-pool tables'
14867 under PowerPC:
14868
f676971a 14869 Target Flags Name One table per
9ebbca7d
GK
14870 AIX (none) AIX TOC object file
14871 AIX -mfull-toc AIX TOC object file
14872 AIX -mminimal-toc AIX minimal TOC translation unit
14873 SVR4/EABI (none) SVR4 SDATA object file
14874 SVR4/EABI -fpic SVR4 pic object file
14875 SVR4/EABI -fPIC SVR4 PIC translation unit
14876 SVR4/EABI -mrelocatable EABI TOC function
14877 SVR4/EABI -maix AIX TOC object file
f676971a 14878 SVR4/EABI -maix -mminimal-toc
9ebbca7d
GK
14879 AIX minimal TOC translation unit
14880
14881 Name Reg. Set by entries contains:
14882 made by addrs? fp? sum?
14883
14884 AIX TOC 2 crt0 as Y option option
14885 AIX minimal TOC 30 prolog gcc Y Y option
14886 SVR4 SDATA 13 crt0 gcc N Y N
14887 SVR4 pic 30 prolog ld Y not yet N
14888 SVR4 PIC 30 prolog gcc Y option option
14889 EABI TOC 30 prolog gcc Y option option
14890
14891*/
14892
9ebbca7d
GK
14893/* Hash functions for the hash table. */
14894
14895static unsigned
a2369ed3 14896rs6000_hash_constant (rtx k)
9ebbca7d 14897{
46b33600
RH
14898 enum rtx_code code = GET_CODE (k);
14899 enum machine_mode mode = GET_MODE (k);
14900 unsigned result = (code << 3) ^ mode;
14901 const char *format;
14902 int flen, fidx;
f676971a 14903
46b33600
RH
14904 format = GET_RTX_FORMAT (code);
14905 flen = strlen (format);
14906 fidx = 0;
9ebbca7d 14907
46b33600
RH
14908 switch (code)
14909 {
14910 case LABEL_REF:
14911 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
14912
14913 case CONST_DOUBLE:
14914 if (mode != VOIDmode)
14915 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
14916 flen = 2;
14917 break;
14918
14919 case CODE_LABEL:
14920 fidx = 3;
14921 break;
14922
14923 default:
14924 break;
14925 }
9ebbca7d
GK
14926
14927 for (; fidx < flen; fidx++)
14928 switch (format[fidx])
14929 {
14930 case 's':
14931 {
14932 unsigned i, len;
14933 const char *str = XSTR (k, fidx);
14934 len = strlen (str);
14935 result = result * 613 + len;
14936 for (i = 0; i < len; i++)
14937 result = result * 613 + (unsigned) str[i];
17167fd8
MM
14938 break;
14939 }
9ebbca7d
GK
14940 case 'u':
14941 case 'e':
14942 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
14943 break;
14944 case 'i':
14945 case 'n':
14946 result = result * 613 + (unsigned) XINT (k, fidx);
14947 break;
14948 case 'w':
14949 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
14950 result = result * 613 + (unsigned) XWINT (k, fidx);
14951 else
14952 {
14953 size_t i;
14954 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
14955 result = result * 613 + (unsigned) (XWINT (k, fidx)
14956 >> CHAR_BIT * i);
14957 }
14958 break;
09501938
DE
14959 case '0':
14960 break;
9ebbca7d 14961 default:
a4f6c312 14962 abort ();
9ebbca7d 14963 }
46b33600 14964
9ebbca7d
GK
14965 return result;
14966}
14967
14968static unsigned
a2369ed3 14969toc_hash_function (const void *hash_entry)
9ebbca7d 14970{
f676971a 14971 const struct toc_hash_struct *thc =
a9098fd0
GK
14972 (const struct toc_hash_struct *) hash_entry;
14973 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
14974}
14975
14976/* Compare H1 and H2 for equivalence. */
14977
14978static int
a2369ed3 14979toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
14980{
14981 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
14982 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
14983
a9098fd0
GK
14984 if (((const struct toc_hash_struct *) h1)->key_mode
14985 != ((const struct toc_hash_struct *) h2)->key_mode)
14986 return 0;
14987
5692c7bc 14988 return rtx_equal_p (r1, r2);
9ebbca7d
GK
14989}
14990
28e510bd
MM
14991/* These are the names given by the C++ front-end to vtables, and
14992 vtable-like objects. Ideally, this logic should not be here;
14993 instead, there should be some programmatic way of inquiring as
14994 to whether or not an object is a vtable. */
14995
14996#define VTABLE_NAME_P(NAME) \
14997 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
14998 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
14999 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 15000 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
f676971a 15001 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
28e510bd
MM
15002
15003void
a2369ed3 15004rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
15005{
15006 /* Currently C++ toc references to vtables can be emitted before it
15007 is decided whether the vtable is public or private. If this is
15008 the case, then the linker will eventually complain that there is
f676971a 15009 a reference to an unknown section. Thus, for vtables only,
28e510bd
MM
15010 we emit the TOC reference to reference the symbol and not the
15011 section. */
15012 const char *name = XSTR (x, 0);
54ee9799 15013
f676971a 15014 if (VTABLE_NAME_P (name))
54ee9799
DE
15015 {
15016 RS6000_OUTPUT_BASENAME (file, name);
15017 }
15018 else
15019 assemble_name (file, name);
28e510bd
MM
15020}
15021
a4f6c312
SS
15022/* Output a TOC entry. We derive the entry name from what is being
15023 written. */
9878760c
RK
15024
15025void
a2369ed3 15026output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
15027{
15028 char buf[256];
3cce094d 15029 const char *name = buf;
ec940faa 15030 const char *real_name;
9878760c
RK
15031 rtx base = x;
15032 int offset = 0;
15033
4697a36c
MM
15034 if (TARGET_NO_TOC)
15035 abort ();
15036
9ebbca7d
GK
15037 /* When the linker won't eliminate them, don't output duplicate
15038 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
15039 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
15040 CODE_LABELs. */
15041 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
15042 {
15043 struct toc_hash_struct *h;
15044 void * * found;
f676971a 15045
17211ab5 15046 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
c4ad648e 15047 time because GGC is not initialized at that point. */
17211ab5 15048 if (toc_hash_table == NULL)
f676971a 15049 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
17211ab5
GK
15050 toc_hash_eq, NULL);
15051
9ebbca7d
GK
15052 h = ggc_alloc (sizeof (*h));
15053 h->key = x;
a9098fd0 15054 h->key_mode = mode;
9ebbca7d 15055 h->labelno = labelno;
f676971a 15056
9ebbca7d
GK
15057 found = htab_find_slot (toc_hash_table, h, 1);
15058 if (*found == NULL)
15059 *found = h;
f676971a 15060 else /* This is indeed a duplicate.
9ebbca7d
GK
15061 Set this label equal to that label. */
15062 {
15063 fputs ("\t.set ", file);
15064 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
15065 fprintf (file, "%d,", labelno);
15066 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
f676971a 15067 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
9ebbca7d
GK
15068 found)->labelno));
15069 return;
15070 }
15071 }
15072
15073 /* If we're going to put a double constant in the TOC, make sure it's
15074 aligned properly when strict alignment is on. */
ff1720ed
RK
15075 if (GET_CODE (x) == CONST_DOUBLE
15076 && STRICT_ALIGNMENT
a9098fd0 15077 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
15078 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
15079 ASM_OUTPUT_ALIGN (file, 3);
15080 }
15081
4977bab6 15082 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 15083
37c37a57
RK
15084 /* Handle FP constants specially. Note that if we have a minimal
15085 TOC, things we put here aren't actually in the TOC, so we can allow
15086 FP constants. */
fcce224d
DE
15087 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
15088 {
15089 REAL_VALUE_TYPE rv;
15090 long k[4];
15091
15092 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15093 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
15094
15095 if (TARGET_64BIT)
15096 {
15097 if (TARGET_MINIMAL_TOC)
15098 fputs (DOUBLE_INT_ASM_OP, file);
15099 else
15100 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
15101 k[0] & 0xffffffff, k[1] & 0xffffffff,
15102 k[2] & 0xffffffff, k[3] & 0xffffffff);
15103 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
15104 k[0] & 0xffffffff, k[1] & 0xffffffff,
15105 k[2] & 0xffffffff, k[3] & 0xffffffff);
15106 return;
15107 }
15108 else
15109 {
15110 if (TARGET_MINIMAL_TOC)
15111 fputs ("\t.long ", file);
15112 else
15113 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
15114 k[0] & 0xffffffff, k[1] & 0xffffffff,
15115 k[2] & 0xffffffff, k[3] & 0xffffffff);
15116 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
15117 k[0] & 0xffffffff, k[1] & 0xffffffff,
15118 k[2] & 0xffffffff, k[3] & 0xffffffff);
15119 return;
15120 }
15121 }
15122 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 15123 {
042259f2
DE
15124 REAL_VALUE_TYPE rv;
15125 long k[2];
0adc764e 15126
042259f2
DE
15127 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15128 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 15129
13ded975
DE
15130 if (TARGET_64BIT)
15131 {
15132 if (TARGET_MINIMAL_TOC)
2bfcf297 15133 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 15134 else
2f0552b6
AM
15135 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
15136 k[0] & 0xffffffff, k[1] & 0xffffffff);
15137 fprintf (file, "0x%lx%08lx\n",
15138 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
15139 return;
15140 }
1875cc88 15141 else
13ded975
DE
15142 {
15143 if (TARGET_MINIMAL_TOC)
2bfcf297 15144 fputs ("\t.long ", file);
13ded975 15145 else
2f0552b6
AM
15146 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
15147 k[0] & 0xffffffff, k[1] & 0xffffffff);
15148 fprintf (file, "0x%lx,0x%lx\n",
15149 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
15150 return;
15151 }
9878760c 15152 }
a9098fd0 15153 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 15154 {
042259f2
DE
15155 REAL_VALUE_TYPE rv;
15156 long l;
9878760c 15157
042259f2
DE
15158 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15159 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
15160
31bfaa0b
DE
15161 if (TARGET_64BIT)
15162 {
15163 if (TARGET_MINIMAL_TOC)
2bfcf297 15164 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 15165 else
2f0552b6
AM
15166 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
15167 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
15168 return;
15169 }
042259f2 15170 else
31bfaa0b
DE
15171 {
15172 if (TARGET_MINIMAL_TOC)
2bfcf297 15173 fputs ("\t.long ", file);
31bfaa0b 15174 else
2f0552b6
AM
15175 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
15176 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
15177 return;
15178 }
042259f2 15179 }
f176e826 15180 else if (GET_MODE (x) == VOIDmode
a9098fd0 15181 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 15182 {
e2c953b6 15183 unsigned HOST_WIDE_INT low;
042259f2
DE
15184 HOST_WIDE_INT high;
15185
15186 if (GET_CODE (x) == CONST_DOUBLE)
15187 {
15188 low = CONST_DOUBLE_LOW (x);
15189 high = CONST_DOUBLE_HIGH (x);
15190 }
15191 else
15192#if HOST_BITS_PER_WIDE_INT == 32
15193 {
15194 low = INTVAL (x);
0858c623 15195 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
15196 }
15197#else
15198 {
c4ad648e
AM
15199 low = INTVAL (x) & 0xffffffff;
15200 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
042259f2
DE
15201 }
15202#endif
9878760c 15203
a9098fd0
GK
15204 /* TOC entries are always Pmode-sized, but since this
15205 is a bigendian machine then if we're putting smaller
15206 integer constants in the TOC we have to pad them.
15207 (This is still a win over putting the constants in
15208 a separate constant pool, because then we'd have
02a4ec28
FS
15209 to have both a TOC entry _and_ the actual constant.)
15210
15211 For a 32-bit target, CONST_INT values are loaded and shifted
15212 entirely within `low' and can be stored in one TOC entry. */
15213
15214 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 15215 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
15216
15217 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
15218 {
15219#if HOST_BITS_PER_WIDE_INT == 32
15220 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
15221 POINTER_SIZE, &low, &high, 0);
15222#else
15223 low |= high << 32;
15224 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
15225 high = (HOST_WIDE_INT) low >> 32;
15226 low &= 0xffffffff;
15227#endif
15228 }
a9098fd0 15229
13ded975
DE
15230 if (TARGET_64BIT)
15231 {
15232 if (TARGET_MINIMAL_TOC)
2bfcf297 15233 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 15234 else
2f0552b6
AM
15235 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
15236 (long) high & 0xffffffff, (long) low & 0xffffffff);
15237 fprintf (file, "0x%lx%08lx\n",
15238 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
15239 return;
15240 }
1875cc88 15241 else
13ded975 15242 {
02a4ec28
FS
15243 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
15244 {
15245 if (TARGET_MINIMAL_TOC)
2bfcf297 15246 fputs ("\t.long ", file);
02a4ec28 15247 else
2bfcf297 15248 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
15249 (long) high & 0xffffffff, (long) low & 0xffffffff);
15250 fprintf (file, "0x%lx,0x%lx\n",
15251 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 15252 }
13ded975 15253 else
02a4ec28
FS
15254 {
15255 if (TARGET_MINIMAL_TOC)
2bfcf297 15256 fputs ("\t.long ", file);
02a4ec28 15257 else
2f0552b6
AM
15258 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
15259 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 15260 }
13ded975
DE
15261 return;
15262 }
9878760c
RK
15263 }
15264
15265 if (GET_CODE (x) == CONST)
15266 {
2bfcf297
DB
15267 if (GET_CODE (XEXP (x, 0)) != PLUS)
15268 abort ();
15269
9878760c
RK
15270 base = XEXP (XEXP (x, 0), 0);
15271 offset = INTVAL (XEXP (XEXP (x, 0), 1));
15272 }
f676971a 15273
9878760c
RK
15274 if (GET_CODE (base) == SYMBOL_REF)
15275 name = XSTR (base, 0);
15276 else if (GET_CODE (base) == LABEL_REF)
15277 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
15278 else if (GET_CODE (base) == CODE_LABEL)
15279 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
15280 else
15281 abort ();
15282
772c5265 15283 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 15284 if (TARGET_MINIMAL_TOC)
2bfcf297 15285 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
15286 else
15287 {
b6c9286a 15288 fprintf (file, "\t.tc %s", real_name);
9878760c 15289
1875cc88
JW
15290 if (offset < 0)
15291 fprintf (file, ".N%d", - offset);
15292 else if (offset)
15293 fprintf (file, ".P%d", offset);
9878760c 15294
19d2d16f 15295 fputs ("[TC],", file);
1875cc88 15296 }
581bc4de
MM
15297
15298 /* Currently C++ toc references to vtables can be emitted before it
15299 is decided whether the vtable is public or private. If this is
15300 the case, then the linker will eventually complain that there is
15301 a TOC reference to an unknown section. Thus, for vtables only,
15302 we emit the TOC reference to reference the symbol and not the
15303 section. */
28e510bd 15304 if (VTABLE_NAME_P (name))
581bc4de 15305 {
54ee9799 15306 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
15307 if (offset < 0)
15308 fprintf (file, "%d", offset);
15309 else if (offset > 0)
15310 fprintf (file, "+%d", offset);
15311 }
15312 else
15313 output_addr_const (file, x);
19d2d16f 15314 putc ('\n', file);
9878760c
RK
15315}
15316\f
15317/* Output an assembler pseudo-op to write an ASCII string of N characters
15318 starting at P to FILE.
15319
15320 On the RS/6000, we have to do this using the .byte operation and
15321 write out special characters outside the quoted string.
15322 Also, the assembler is broken; very long strings are truncated,
a4f6c312 15323 so we must artificially break them up early. */
9878760c
RK
15324
15325void
a2369ed3 15326output_ascii (FILE *file, const char *p, int n)
9878760c
RK
15327{
15328 char c;
15329 int i, count_string;
d330fd93
KG
15330 const char *for_string = "\t.byte \"";
15331 const char *for_decimal = "\t.byte ";
15332 const char *to_close = NULL;
9878760c
RK
15333
15334 count_string = 0;
15335 for (i = 0; i < n; i++)
15336 {
15337 c = *p++;
15338 if (c >= ' ' && c < 0177)
15339 {
15340 if (for_string)
15341 fputs (for_string, file);
15342 putc (c, file);
15343
15344 /* Write two quotes to get one. */
15345 if (c == '"')
15346 {
15347 putc (c, file);
15348 ++count_string;
15349 }
15350
15351 for_string = NULL;
15352 for_decimal = "\"\n\t.byte ";
15353 to_close = "\"\n";
15354 ++count_string;
15355
15356 if (count_string >= 512)
15357 {
15358 fputs (to_close, file);
15359
15360 for_string = "\t.byte \"";
15361 for_decimal = "\t.byte ";
15362 to_close = NULL;
15363 count_string = 0;
15364 }
15365 }
15366 else
15367 {
15368 if (for_decimal)
15369 fputs (for_decimal, file);
15370 fprintf (file, "%d", c);
15371
15372 for_string = "\n\t.byte \"";
15373 for_decimal = ", ";
15374 to_close = "\n";
15375 count_string = 0;
15376 }
15377 }
15378
15379 /* Now close the string if we have written one. Then end the line. */
15380 if (to_close)
9ebbca7d 15381 fputs (to_close, file);
9878760c
RK
15382}
15383\f
15384/* Generate a unique section name for FILENAME for a section type
15385 represented by SECTION_DESC. Output goes into BUF.
15386
15387 SECTION_DESC can be any string, as long as it is different for each
15388 possible section type.
15389
15390 We name the section in the same manner as xlc. The name begins with an
15391 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
15392 names) with the last period replaced by the string SECTION_DESC. If
15393 FILENAME does not contain a period, SECTION_DESC is appended to the end of
15394 the name. */
9878760c
RK
15395
15396void
f676971a 15397rs6000_gen_section_name (char **buf, const char *filename,
c4ad648e 15398 const char *section_desc)
9878760c 15399{
9ebbca7d 15400 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
15401 char *p;
15402 int len;
9878760c
RK
15403
15404 after_last_slash = filename;
15405 for (q = filename; *q; q++)
11e5fe42
RK
15406 {
15407 if (*q == '/')
15408 after_last_slash = q + 1;
15409 else if (*q == '.')
15410 last_period = q;
15411 }
9878760c 15412
11e5fe42 15413 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 15414 *buf = (char *) xmalloc (len);
9878760c
RK
15415
15416 p = *buf;
15417 *p++ = '_';
15418
15419 for (q = after_last_slash; *q; q++)
15420 {
11e5fe42 15421 if (q == last_period)
c4ad648e 15422 {
9878760c
RK
15423 strcpy (p, section_desc);
15424 p += strlen (section_desc);
e3981aab 15425 break;
c4ad648e 15426 }
9878760c 15427
e9a780ec 15428 else if (ISALNUM (*q))
c4ad648e 15429 *p++ = *q;
9878760c
RK
15430 }
15431
11e5fe42 15432 if (last_period == 0)
9878760c
RK
15433 strcpy (p, section_desc);
15434 else
15435 *p = '\0';
15436}
e165f3f0 15437\f
a4f6c312 15438/* Emit profile function. */
411707f4 15439
411707f4 15440void
a2369ed3 15441output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 15442{
ffcfcb5f
AM
15443 if (TARGET_PROFILE_KERNEL)
15444 return;
15445
8480e480
CC
15446 if (DEFAULT_ABI == ABI_AIX)
15447 {
9739c90c
JJ
15448#ifndef NO_PROFILE_COUNTERS
15449# define NO_PROFILE_COUNTERS 0
15450#endif
f676971a 15451 if (NO_PROFILE_COUNTERS)
9739c90c
JJ
15452 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
15453 else
15454 {
15455 char buf[30];
15456 const char *label_name;
15457 rtx fun;
411707f4 15458
9739c90c
JJ
15459 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
15460 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
15461 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 15462
9739c90c
JJ
15463 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
15464 fun, Pmode);
15465 }
8480e480 15466 }
ee890fe2
SS
15467 else if (DEFAULT_ABI == ABI_DARWIN)
15468 {
d5fa86ba 15469 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
15470 int caller_addr_regno = LINK_REGISTER_REGNUM;
15471
15472 /* Be conservative and always set this, at least for now. */
15473 current_function_uses_pic_offset_table = 1;
15474
15475#if TARGET_MACHO
15476 /* For PIC code, set up a stub and collect the caller's address
15477 from r0, which is where the prologue puts it. */
11abc112
MM
15478 if (MACHOPIC_INDIRECT
15479 && current_function_uses_pic_offset_table)
15480 caller_addr_regno = 0;
ee890fe2
SS
15481#endif
15482 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
15483 0, VOIDmode, 1,
15484 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
15485 }
411707f4
CC
15486}
15487
a4f6c312 15488/* Write function profiler code. */
e165f3f0
RK
15489
15490void
a2369ed3 15491output_function_profiler (FILE *file, int labelno)
e165f3f0 15492{
3daf36a4 15493 char buf[100];
09eeeacb 15494 int save_lr = 8;
e165f3f0 15495
38c1f2d7 15496 switch (DEFAULT_ABI)
3daf36a4 15497 {
38c1f2d7
MM
15498 default:
15499 abort ();
15500
15501 case ABI_V4:
09eeeacb 15502 save_lr = 4;
09eeeacb
AM
15503 if (!TARGET_32BIT)
15504 {
15505 warning ("no profiling of 64-bit code for this ABI");
15506 return;
15507 }
ffcfcb5f 15508 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
15509 fprintf (file, "\tmflr %s\n", reg_names[0]);
15510 if (flag_pic == 1)
15511 {
dfdfa60f 15512 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
15513 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15514 reg_names[0], save_lr, reg_names[1]);
17167fd8 15515 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 15516 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 15517 assemble_name (file, buf);
17167fd8 15518 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 15519 }
9ebbca7d 15520 else if (flag_pic > 1)
38c1f2d7 15521 {
09eeeacb
AM
15522 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15523 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
15524 /* Now, we need to get the address of the label. */
15525 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 15526 assemble_name (file, buf);
9ebbca7d
GK
15527 fputs ("-.\n1:", file);
15528 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
f676971a 15529 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
9ebbca7d
GK
15530 reg_names[0], reg_names[11]);
15531 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
15532 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 15533 }
38c1f2d7
MM
15534 else
15535 {
17167fd8 15536 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 15537 assemble_name (file, buf);
dfdfa60f 15538 fputs ("@ha\n", file);
09eeeacb
AM
15539 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15540 reg_names[0], save_lr, reg_names[1]);
a260abc9 15541 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 15542 assemble_name (file, buf);
17167fd8 15543 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
15544 }
15545
50d440bc 15546 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
15547 fprintf (file, "\tbl %s%s\n",
15548 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
15549 break;
15550
15551 case ABI_AIX:
ee890fe2 15552 case ABI_DARWIN:
ffcfcb5f
AM
15553 if (!TARGET_PROFILE_KERNEL)
15554 {
a3c9585f 15555 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
15556 }
15557 else
15558 {
15559 if (TARGET_32BIT)
15560 abort ();
15561
15562 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
15563 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
15564
6de9cd9a 15565 if (cfun->static_chain_decl != NULL)
ffcfcb5f
AM
15566 {
15567 asm_fprintf (file, "\tstd %s,24(%s)\n",
15568 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15569 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15570 asm_fprintf (file, "\tld %s,24(%s)\n",
15571 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15572 }
15573 else
15574 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15575 }
38c1f2d7
MM
15576 break;
15577 }
e165f3f0 15578}
a251ffd0 15579
b54cf83a 15580\f
b54cf83a
DE
15581/* Power4 load update and store update instructions are cracked into a
15582 load or store and an integer insn which are executed in the same cycle.
15583 Branches have their own dispatch slot which does not count against the
15584 GCC issue rate, but it changes the program flow so there are no other
15585 instructions to issue in this cycle. */
15586
15587static int
f676971a
EC
15588rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
15589 int verbose ATTRIBUTE_UNUSED,
a2369ed3 15590 rtx insn, int more)
b54cf83a
DE
15591{
15592 if (GET_CODE (PATTERN (insn)) == USE
15593 || GET_CODE (PATTERN (insn)) == CLOBBER)
15594 return more;
15595
ec507f2d 15596 if (rs6000_sched_groups)
b54cf83a 15597 {
cbe26ab8 15598 if (is_microcoded_insn (insn))
c4ad648e 15599 return 0;
cbe26ab8 15600 else if (is_cracked_insn (insn))
c4ad648e 15601 return more > 2 ? more - 2 : 0;
b54cf83a 15602 }
165b263e
DE
15603
15604 return more - 1;
b54cf83a
DE
15605}
15606
a251ffd0
TG
15607/* Adjust the cost of a scheduling dependency. Return the new cost of
15608 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
15609
c237e94a 15610static int
0a4f0294 15611rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
a251ffd0
TG
15612{
15613 if (! recog_memoized (insn))
15614 return 0;
15615
15616 if (REG_NOTE_KIND (link) != 0)
15617 return 0;
15618
15619 if (REG_NOTE_KIND (link) == 0)
15620 {
ed947a96
DJ
15621 /* Data dependency; DEP_INSN writes a register that INSN reads
15622 some cycles later. */
15623 switch (get_attr_type (insn))
15624 {
15625 case TYPE_JMPREG:
309323c2 15626 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
15627 a mtctr and bctr (and mtlr and br/blr). The first
15628 scheduling pass will not know about this latency since
15629 the mtctr instruction, which has the latency associated
15630 to it, will be generated by reload. */
309323c2 15631 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
15632 case TYPE_BRANCH:
15633 /* Leave some extra cycles between a compare and its
15634 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
15635 if ((rs6000_cpu_attr == CPU_PPC603
15636 || rs6000_cpu_attr == CPU_PPC604
15637 || rs6000_cpu_attr == CPU_PPC604E
15638 || rs6000_cpu_attr == CPU_PPC620
15639 || rs6000_cpu_attr == CPU_PPC630
15640 || rs6000_cpu_attr == CPU_PPC750
15641 || rs6000_cpu_attr == CPU_PPC7400
15642 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
15643 || rs6000_cpu_attr == CPU_POWER4
15644 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
15645 && recog_memoized (dep_insn)
15646 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
15647 && (get_attr_type (dep_insn) == TYPE_CMP
15648 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 15649 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
15650 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
15651 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 15652 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
15653 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
15654 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
15655 return cost + 2;
15656 default:
15657 break;
15658 }
a251ffd0
TG
15659 /* Fall out to return default cost. */
15660 }
15661
15662 return cost;
15663}
b6c9286a 15664
cbe26ab8 15665/* The function returns a true if INSN is microcoded.
839a4992 15666 Return false otherwise. */
cbe26ab8
DN
15667
15668static bool
15669is_microcoded_insn (rtx insn)
15670{
15671 if (!insn || !INSN_P (insn)
15672 || GET_CODE (PATTERN (insn)) == USE
15673 || GET_CODE (PATTERN (insn)) == CLOBBER)
15674 return false;
15675
ec507f2d 15676 if (rs6000_sched_groups)
cbe26ab8
DN
15677 {
15678 enum attr_type type = get_attr_type (insn);
15679 if (type == TYPE_LOAD_EXT_U
15680 || type == TYPE_LOAD_EXT_UX
15681 || type == TYPE_LOAD_UX
15682 || type == TYPE_STORE_UX
15683 || type == TYPE_MFCR)
c4ad648e 15684 return true;
cbe26ab8
DN
15685 }
15686
15687 return false;
15688}
15689
5c425df5 15690/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
15691 as the first insn in a dispatch group ("dispatch-slot restricted").
15692 In this case, the returned value indicates how many dispatch slots
15693 the insn occupies (at the beginning of the group).
79ae11c4
DN
15694 Return 0 otherwise. */
15695
cbe26ab8 15696static int
79ae11c4
DN
15697is_dispatch_slot_restricted (rtx insn)
15698{
15699 enum attr_type type;
15700
ec507f2d 15701 if (!rs6000_sched_groups)
79ae11c4
DN
15702 return 0;
15703
15704 if (!insn
15705 || insn == NULL_RTX
15706 || GET_CODE (insn) == NOTE
15707 || GET_CODE (PATTERN (insn)) == USE
15708 || GET_CODE (PATTERN (insn)) == CLOBBER)
15709 return 0;
15710
15711 type = get_attr_type (insn);
15712
ec507f2d
DE
15713 switch (type)
15714 {
15715 case TYPE_MFCR:
15716 case TYPE_MFCRF:
15717 case TYPE_MTCR:
15718 case TYPE_DELAYED_CR:
15719 case TYPE_CR_LOGICAL:
15720 case TYPE_MTJMPR:
15721 case TYPE_MFJMPR:
15722 return 1;
15723 case TYPE_IDIV:
15724 case TYPE_LDIV:
15725 return 2;
15726 default:
15727 if (rs6000_cpu == PROCESSOR_POWER5
15728 && is_cracked_insn (insn))
15729 return 2;
15730 return 0;
15731 }
79ae11c4
DN
15732}
15733
cbe26ab8
DN
15734/* The function returns true if INSN is cracked into 2 instructions
15735 by the processor (and therefore occupies 2 issue slots). */
15736
15737static bool
15738is_cracked_insn (rtx insn)
15739{
15740 if (!insn || !INSN_P (insn)
15741 || GET_CODE (PATTERN (insn)) == USE
15742 || GET_CODE (PATTERN (insn)) == CLOBBER)
15743 return false;
15744
ec507f2d 15745 if (rs6000_sched_groups)
cbe26ab8
DN
15746 {
15747 enum attr_type type = get_attr_type (insn);
15748 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
c4ad648e
AM
15749 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
15750 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
15751 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
15752 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
15753 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
15754 || type == TYPE_IDIV || type == TYPE_LDIV
15755 || type == TYPE_INSERT_WORD)
15756 return true;
cbe26ab8
DN
15757 }
15758
15759 return false;
15760}
15761
15762/* The function returns true if INSN can be issued only from
a3c9585f 15763 the branch slot. */
cbe26ab8
DN
15764
15765static bool
15766is_branch_slot_insn (rtx insn)
15767{
15768 if (!insn || !INSN_P (insn)
15769 || GET_CODE (PATTERN (insn)) == USE
15770 || GET_CODE (PATTERN (insn)) == CLOBBER)
15771 return false;
15772
ec507f2d 15773 if (rs6000_sched_groups)
cbe26ab8
DN
15774 {
15775 enum attr_type type = get_attr_type (insn);
15776 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
f676971a 15777 return true;
cbe26ab8
DN
15778 return false;
15779 }
15780
15781 return false;
15782}
79ae11c4 15783
a4f6c312 15784/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
15785 priority INSN_PRIORITY (INSN). Increase the priority to execute the
15786 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
15787 define this macro if you do not need to adjust the scheduling
15788 priorities of insns. */
bef84347 15789
c237e94a 15790static int
a2369ed3 15791rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 15792{
a4f6c312
SS
15793 /* On machines (like the 750) which have asymmetric integer units,
15794 where one integer unit can do multiply and divides and the other
15795 can't, reduce the priority of multiply/divide so it is scheduled
15796 before other integer operations. */
bef84347
VM
15797
15798#if 0
2c3c49de 15799 if (! INSN_P (insn))
bef84347
VM
15800 return priority;
15801
15802 if (GET_CODE (PATTERN (insn)) == USE)
15803 return priority;
15804
15805 switch (rs6000_cpu_attr) {
15806 case CPU_PPC750:
15807 switch (get_attr_type (insn))
15808 {
15809 default:
15810 break;
15811
15812 case TYPE_IMUL:
15813 case TYPE_IDIV:
3cb999d8
DE
15814 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
15815 priority, priority);
bef84347
VM
15816 if (priority >= 0 && priority < 0x01000000)
15817 priority >>= 3;
15818 break;
15819 }
15820 }
15821#endif
15822
79ae11c4
DN
15823 if (is_dispatch_slot_restricted (insn)
15824 && reload_completed
f676971a 15825 && current_sched_info->sched_max_insns_priority
79ae11c4
DN
15826 && rs6000_sched_restricted_insns_priority)
15827 {
15828
c4ad648e
AM
15829 /* Prioritize insns that can be dispatched only in the first
15830 dispatch slot. */
79ae11c4 15831 if (rs6000_sched_restricted_insns_priority == 1)
f676971a
EC
15832 /* Attach highest priority to insn. This means that in
15833 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
79ae11c4 15834 precede 'priority' (critical path) considerations. */
f676971a 15835 return current_sched_info->sched_max_insns_priority;
79ae11c4 15836 else if (rs6000_sched_restricted_insns_priority == 2)
f676971a 15837 /* Increase priority of insn by a minimal amount. This means that in
c4ad648e
AM
15838 haifa-sched.c:ready_sort(), only 'priority' (critical path)
15839 considerations precede dispatch-slot restriction considerations. */
f676971a
EC
15840 return (priority + 1);
15841 }
79ae11c4 15842
bef84347
VM
15843 return priority;
15844}
15845
a4f6c312
SS
15846/* Return how many instructions the machine can issue per cycle. */
15847
c237e94a 15848static int
863d938c 15849rs6000_issue_rate (void)
b6c9286a 15850{
3317bab1
DE
15851 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
15852 if (!reload_completed)
15853 return 1;
15854
b6c9286a 15855 switch (rs6000_cpu_attr) {
3cb999d8
DE
15856 case CPU_RIOS1: /* ? */
15857 case CPU_RS64A:
15858 case CPU_PPC601: /* ? */
ed947a96 15859 case CPU_PPC7450:
3cb999d8 15860 return 3;
b54cf83a 15861 case CPU_PPC440:
b6c9286a 15862 case CPU_PPC603:
bef84347 15863 case CPU_PPC750:
ed947a96 15864 case CPU_PPC7400:
be12c2b0 15865 case CPU_PPC8540:
f676971a 15866 return 2;
3cb999d8 15867 case CPU_RIOS2:
b6c9286a 15868 case CPU_PPC604:
19684119 15869 case CPU_PPC604E:
b6c9286a 15870 case CPU_PPC620:
3cb999d8 15871 case CPU_PPC630:
b6c9286a 15872 return 4;
cbe26ab8 15873 case CPU_POWER4:
ec507f2d 15874 case CPU_POWER5:
cbe26ab8 15875 return 5;
b6c9286a
MM
15876 default:
15877 return 1;
15878 }
15879}
15880
be12c2b0
VM
15881/* Return how many instructions to look ahead for better insn
15882 scheduling. */
15883
15884static int
863d938c 15885rs6000_use_sched_lookahead (void)
be12c2b0
VM
15886{
15887 if (rs6000_cpu_attr == CPU_PPC8540)
15888 return 4;
15889 return 0;
15890}
15891
569fa502
DN
15892/* Determine is PAT refers to memory. */
15893
15894static bool
15895is_mem_ref (rtx pat)
15896{
15897 const char * fmt;
15898 int i, j;
15899 bool ret = false;
15900
15901 if (GET_CODE (pat) == MEM)
15902 return true;
15903
15904 /* Recursively process the pattern. */
15905 fmt = GET_RTX_FORMAT (GET_CODE (pat));
15906
15907 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
15908 {
15909 if (fmt[i] == 'e')
15910 ret |= is_mem_ref (XEXP (pat, i));
15911 else if (fmt[i] == 'E')
15912 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
15913 ret |= is_mem_ref (XVECEXP (pat, i, j));
15914 }
15915
15916 return ret;
15917}
15918
15919/* Determine if PAT is a PATTERN of a load insn. */
f676971a 15920
569fa502
DN
15921static bool
15922is_load_insn1 (rtx pat)
15923{
15924 if (!pat || pat == NULL_RTX)
15925 return false;
15926
15927 if (GET_CODE (pat) == SET)
15928 return is_mem_ref (SET_SRC (pat));
15929
15930 if (GET_CODE (pat) == PARALLEL)
15931 {
15932 int i;
15933
15934 for (i = 0; i < XVECLEN (pat, 0); i++)
15935 if (is_load_insn1 (XVECEXP (pat, 0, i)))
15936 return true;
15937 }
15938
15939 return false;
15940}
15941
15942/* Determine if INSN loads from memory. */
15943
15944static bool
15945is_load_insn (rtx insn)
15946{
15947 if (!insn || !INSN_P (insn))
15948 return false;
15949
15950 if (GET_CODE (insn) == CALL_INSN)
15951 return false;
15952
15953 return is_load_insn1 (PATTERN (insn));
15954}
15955
15956/* Determine if PAT is a PATTERN of a store insn. */
15957
15958static bool
15959is_store_insn1 (rtx pat)
15960{
15961 if (!pat || pat == NULL_RTX)
15962 return false;
15963
15964 if (GET_CODE (pat) == SET)
15965 return is_mem_ref (SET_DEST (pat));
15966
15967 if (GET_CODE (pat) == PARALLEL)
15968 {
15969 int i;
15970
15971 for (i = 0; i < XVECLEN (pat, 0); i++)
15972 if (is_store_insn1 (XVECEXP (pat, 0, i)))
15973 return true;
15974 }
15975
15976 return false;
15977}
15978
15979/* Determine if INSN stores to memory. */
15980
15981static bool
15982is_store_insn (rtx insn)
15983{
15984 if (!insn || !INSN_P (insn))
15985 return false;
15986
15987 return is_store_insn1 (PATTERN (insn));
15988}
15989
15990/* Returns whether the dependence between INSN and NEXT is considered
15991 costly by the given target. */
15992
15993static bool
c4ad648e
AM
15994rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost,
15995 int distance)
f676971a 15996{
569fa502 15997 /* If the flag is not enbled - no dependence is considered costly;
f676971a 15998 allow all dependent insns in the same group.
569fa502
DN
15999 This is the most aggressive option. */
16000 if (rs6000_sched_costly_dep == no_dep_costly)
16001 return false;
16002
f676971a 16003 /* If the flag is set to 1 - a dependence is always considered costly;
569fa502
DN
16004 do not allow dependent instructions in the same group.
16005 This is the most conservative option. */
16006 if (rs6000_sched_costly_dep == all_deps_costly)
f676971a 16007 return true;
569fa502 16008
f676971a
EC
16009 if (rs6000_sched_costly_dep == store_to_load_dep_costly
16010 && is_load_insn (next)
569fa502
DN
16011 && is_store_insn (insn))
16012 /* Prevent load after store in the same group. */
16013 return true;
16014
16015 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
f676971a 16016 && is_load_insn (next)
569fa502
DN
16017 && is_store_insn (insn)
16018 && (!link || (int) REG_NOTE_KIND (link) == 0))
c4ad648e
AM
16019 /* Prevent load after store in the same group if it is a true
16020 dependence. */
569fa502 16021 return true;
f676971a
EC
16022
16023 /* The flag is set to X; dependences with latency >= X are considered costly,
569fa502
DN
16024 and will not be scheduled in the same group. */
16025 if (rs6000_sched_costly_dep <= max_dep_latency
16026 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
16027 return true;
16028
16029 return false;
16030}
16031
f676971a 16032/* Return the next insn after INSN that is found before TAIL is reached,
cbe26ab8
DN
16033 skipping any "non-active" insns - insns that will not actually occupy
16034 an issue slot. Return NULL_RTX if such an insn is not found. */
16035
16036static rtx
16037get_next_active_insn (rtx insn, rtx tail)
16038{
16039 rtx next_insn;
16040
16041 if (!insn || insn == tail)
16042 return NULL_RTX;
16043
16044 next_insn = NEXT_INSN (insn);
16045
16046 while (next_insn
16047 && next_insn != tail
16048 && (GET_CODE(next_insn) == NOTE
16049 || GET_CODE (PATTERN (next_insn)) == USE
16050 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
16051 {
16052 next_insn = NEXT_INSN (next_insn);
16053 }
16054
16055 if (!next_insn || next_insn == tail)
16056 return NULL_RTX;
16057
16058 return next_insn;
16059}
16060
839a4992 16061/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
16062 of group WHICH_GROUP.
16063
16064 If WHICH_GROUP == current_group, this function will return true if INSN
16065 causes the termination of the current group (i.e, the dispatch group to
16066 which INSN belongs). This means that INSN will be the last insn in the
16067 group it belongs to.
16068
16069 If WHICH_GROUP == previous_group, this function will return true if INSN
16070 causes the termination of the previous group (i.e, the dispatch group that
16071 precedes the group to which INSN belongs). This means that INSN will be
16072 the first insn in the group it belongs to). */
16073
16074static bool
16075insn_terminates_group_p (rtx insn, enum group_termination which_group)
16076{
16077 enum attr_type type;
16078
16079 if (! insn)
16080 return false;
569fa502 16081
cbe26ab8
DN
16082 type = get_attr_type (insn);
16083
16084 if (is_microcoded_insn (insn))
16085 return true;
16086
16087 if (which_group == current_group)
16088 {
16089 if (is_branch_slot_insn (insn))
c4ad648e 16090 return true;
cbe26ab8
DN
16091 return false;
16092 }
16093 else if (which_group == previous_group)
16094 {
16095 if (is_dispatch_slot_restricted (insn))
c4ad648e 16096 return true;
cbe26ab8
DN
16097 return false;
16098 }
16099
16100 return false;
16101}
16102
839a4992 16103/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
16104 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
16105
16106static bool
16107is_costly_group (rtx *group_insns, rtx next_insn)
16108{
16109 int i;
16110 rtx link;
16111 int cost;
16112 int issue_rate = rs6000_issue_rate ();
16113
16114 for (i = 0; i < issue_rate; i++)
16115 {
16116 rtx insn = group_insns[i];
16117 if (!insn)
c4ad648e 16118 continue;
cbe26ab8 16119 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
c4ad648e
AM
16120 {
16121 rtx next = XEXP (link, 0);
16122 if (next == next_insn)
16123 {
16124 cost = insn_cost (insn, link, next_insn);
16125 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
16126 return true;
16127 }
16128 }
cbe26ab8
DN
16129 }
16130
16131 return false;
16132}
16133
f676971a 16134/* Utility of the function redefine_groups.
cbe26ab8
DN
16135 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
16136 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
16137 to keep it "far" (in a separate group) from GROUP_INSNS, following
16138 one of the following schemes, depending on the value of the flag
16139 -minsert_sched_nops = X:
16140 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 16141 in order to force NEXT_INSN into a separate group.
f676971a
EC
16142 (2) X < sched_finish_regroup_exact: insert exactly X nops.
16143 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
cbe26ab8
DN
16144 insertion (has a group just ended, how many vacant issue slots remain in the
16145 last group, and how many dispatch groups were encountered so far). */
16146
f676971a 16147static int
c4ad648e
AM
16148force_new_group (int sched_verbose, FILE *dump, rtx *group_insns,
16149 rtx next_insn, bool *group_end, int can_issue_more,
16150 int *group_count)
cbe26ab8
DN
16151{
16152 rtx nop;
16153 bool force;
16154 int issue_rate = rs6000_issue_rate ();
16155 bool end = *group_end;
16156 int i;
16157
16158 if (next_insn == NULL_RTX)
16159 return can_issue_more;
16160
16161 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
16162 return can_issue_more;
16163
16164 force = is_costly_group (group_insns, next_insn);
16165 if (!force)
16166 return can_issue_more;
16167
16168 if (sched_verbose > 6)
16169 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
c4ad648e 16170 *group_count ,can_issue_more);
cbe26ab8
DN
16171
16172 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
16173 {
16174 if (*group_end)
c4ad648e 16175 can_issue_more = 0;
cbe26ab8
DN
16176
16177 /* Since only a branch can be issued in the last issue_slot, it is
16178 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
16179 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
c4ad648e
AM
16180 in this case the last nop will start a new group and the branch
16181 will be forced to the new group. */
cbe26ab8 16182 if (can_issue_more && !is_branch_slot_insn (next_insn))
c4ad648e 16183 can_issue_more--;
cbe26ab8
DN
16184
16185 while (can_issue_more > 0)
c4ad648e
AM
16186 {
16187 nop = gen_nop();
16188 emit_insn_before (nop, next_insn);
16189 can_issue_more--;
16190 }
cbe26ab8
DN
16191
16192 *group_end = true;
16193 return 0;
f676971a 16194 }
cbe26ab8
DN
16195
16196 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
16197 {
16198 int n_nops = rs6000_sched_insert_nops;
16199
f676971a 16200 /* Nops can't be issued from the branch slot, so the effective
c4ad648e 16201 issue_rate for nops is 'issue_rate - 1'. */
cbe26ab8 16202 if (can_issue_more == 0)
c4ad648e 16203 can_issue_more = issue_rate;
cbe26ab8
DN
16204 can_issue_more--;
16205 if (can_issue_more == 0)
c4ad648e
AM
16206 {
16207 can_issue_more = issue_rate - 1;
16208 (*group_count)++;
16209 end = true;
16210 for (i = 0; i < issue_rate; i++)
16211 {
16212 group_insns[i] = 0;
16213 }
16214 }
cbe26ab8
DN
16215
16216 while (n_nops > 0)
c4ad648e
AM
16217 {
16218 nop = gen_nop ();
16219 emit_insn_before (nop, next_insn);
16220 if (can_issue_more == issue_rate - 1) /* new group begins */
16221 end = false;
16222 can_issue_more--;
16223 if (can_issue_more == 0)
16224 {
16225 can_issue_more = issue_rate - 1;
16226 (*group_count)++;
16227 end = true;
16228 for (i = 0; i < issue_rate; i++)
16229 {
16230 group_insns[i] = 0;
16231 }
16232 }
16233 n_nops--;
16234 }
cbe26ab8
DN
16235
16236 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
f676971a 16237 can_issue_more++;
cbe26ab8 16238
c4ad648e
AM
16239 /* Is next_insn going to start a new group? */
16240 *group_end
16241 = (end
cbe26ab8
DN
16242 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
16243 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
16244 || (can_issue_more < issue_rate &&
c4ad648e 16245 insn_terminates_group_p (next_insn, previous_group)));
cbe26ab8 16246 if (*group_end && end)
c4ad648e 16247 (*group_count)--;
cbe26ab8
DN
16248
16249 if (sched_verbose > 6)
c4ad648e
AM
16250 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
16251 *group_count, can_issue_more);
f676971a
EC
16252 return can_issue_more;
16253 }
cbe26ab8
DN
16254
16255 return can_issue_more;
16256}
16257
16258/* This function tries to synch the dispatch groups that the compiler "sees"
f676971a 16259 with the dispatch groups that the processor dispatcher is expected to
cbe26ab8
DN
16260 form in practice. It tries to achieve this synchronization by forcing the
16261 estimated processor grouping on the compiler (as opposed to the function
16262 'pad_goups' which tries to force the scheduler's grouping on the processor).
16263
16264 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
16265 examines the (estimated) dispatch groups that will be formed by the processor
16266 dispatcher. It marks these group boundaries to reflect the estimated
16267 processor grouping, overriding the grouping that the scheduler had marked.
16268 Depending on the value of the flag '-minsert-sched-nops' this function can
16269 force certain insns into separate groups or force a certain distance between
16270 them by inserting nops, for example, if there exists a "costly dependence"
16271 between the insns.
16272
16273 The function estimates the group boundaries that the processor will form as
16274 folllows: It keeps track of how many vacant issue slots are available after
16275 each insn. A subsequent insn will start a new group if one of the following
16276 4 cases applies:
16277 - no more vacant issue slots remain in the current dispatch group.
16278 - only the last issue slot, which is the branch slot, is vacant, but the next
16279 insn is not a branch.
16280 - only the last 2 or less issue slots, including the branch slot, are vacant,
16281 which means that a cracked insn (which occupies two issue slots) can't be
16282 issued in this group.
f676971a 16283 - less than 'issue_rate' slots are vacant, and the next insn always needs to
cbe26ab8
DN
16284 start a new group. */
16285
16286static int
16287redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
16288{
16289 rtx insn, next_insn;
16290 int issue_rate;
16291 int can_issue_more;
16292 int slot, i;
16293 bool group_end;
16294 int group_count = 0;
16295 rtx *group_insns;
16296
16297 /* Initialize. */
16298 issue_rate = rs6000_issue_rate ();
16299 group_insns = alloca (issue_rate * sizeof (rtx));
f676971a 16300 for (i = 0; i < issue_rate; i++)
cbe26ab8
DN
16301 {
16302 group_insns[i] = 0;
16303 }
16304 can_issue_more = issue_rate;
16305 slot = 0;
16306 insn = get_next_active_insn (prev_head_insn, tail);
16307 group_end = false;
16308
16309 while (insn != NULL_RTX)
16310 {
16311 slot = (issue_rate - can_issue_more);
16312 group_insns[slot] = insn;
16313 can_issue_more =
c4ad648e 16314 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
cbe26ab8 16315 if (insn_terminates_group_p (insn, current_group))
c4ad648e 16316 can_issue_more = 0;
cbe26ab8
DN
16317
16318 next_insn = get_next_active_insn (insn, tail);
16319 if (next_insn == NULL_RTX)
c4ad648e 16320 return group_count + 1;
cbe26ab8 16321
c4ad648e
AM
16322 /* Is next_insn going to start a new group? */
16323 group_end
16324 = (can_issue_more == 0
16325 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
16326 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
16327 || (can_issue_more < issue_rate &&
16328 insn_terminates_group_p (next_insn, previous_group)));
cbe26ab8 16329
f676971a 16330 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
c4ad648e
AM
16331 next_insn, &group_end, can_issue_more,
16332 &group_count);
cbe26ab8
DN
16333
16334 if (group_end)
c4ad648e
AM
16335 {
16336 group_count++;
16337 can_issue_more = 0;
16338 for (i = 0; i < issue_rate; i++)
16339 {
16340 group_insns[i] = 0;
16341 }
16342 }
cbe26ab8
DN
16343
16344 if (GET_MODE (next_insn) == TImode && can_issue_more)
c4ad648e 16345 PUT_MODE(next_insn, VOIDmode);
cbe26ab8 16346 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
c4ad648e 16347 PUT_MODE (next_insn, TImode);
cbe26ab8
DN
16348
16349 insn = next_insn;
16350 if (can_issue_more == 0)
c4ad648e
AM
16351 can_issue_more = issue_rate;
16352 } /* while */
cbe26ab8
DN
16353
16354 return group_count;
16355}
16356
16357/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
16358 dispatch group boundaries that the scheduler had marked. Pad with nops
16359 any dispatch groups which have vacant issue slots, in order to force the
16360 scheduler's grouping on the processor dispatcher. The function
16361 returns the number of dispatch groups found. */
16362
16363static int
16364pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
16365{
16366 rtx insn, next_insn;
16367 rtx nop;
16368 int issue_rate;
16369 int can_issue_more;
16370 int group_end;
16371 int group_count = 0;
16372
16373 /* Initialize issue_rate. */
16374 issue_rate = rs6000_issue_rate ();
16375 can_issue_more = issue_rate;
16376
16377 insn = get_next_active_insn (prev_head_insn, tail);
16378 next_insn = get_next_active_insn (insn, tail);
16379
16380 while (insn != NULL_RTX)
16381 {
16382 can_issue_more =
16383 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
16384
16385 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
16386
16387 if (next_insn == NULL_RTX)
c4ad648e 16388 break;
cbe26ab8
DN
16389
16390 if (group_end)
c4ad648e
AM
16391 {
16392 /* If the scheduler had marked group termination at this location
16393 (between insn and next_indn), and neither insn nor next_insn will
16394 force group termination, pad the group with nops to force group
16395 termination. */
16396 if (can_issue_more
16397 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
16398 && !insn_terminates_group_p (insn, current_group)
16399 && !insn_terminates_group_p (next_insn, previous_group))
16400 {
16401 if (!is_branch_slot_insn(next_insn))
16402 can_issue_more--;
16403
16404 while (can_issue_more)
16405 {
16406 nop = gen_nop ();
16407 emit_insn_before (nop, next_insn);
16408 can_issue_more--;
16409 }
16410 }
16411
16412 can_issue_more = issue_rate;
16413 group_count++;
16414 }
cbe26ab8
DN
16415
16416 insn = next_insn;
16417 next_insn = get_next_active_insn (insn, tail);
16418 }
16419
16420 return group_count;
16421}
16422
16423/* The following function is called at the end of scheduling BB.
16424 After reload, it inserts nops at insn group bundling. */
16425
16426static void
38f391a5 16427rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
16428{
16429 int n_groups;
16430
16431 if (sched_verbose)
16432 fprintf (dump, "=== Finishing schedule.\n");
16433
ec507f2d 16434 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
16435 {
16436 if (rs6000_sched_insert_nops == sched_finish_none)
c4ad648e 16437 return;
cbe26ab8
DN
16438
16439 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
c4ad648e
AM
16440 n_groups = pad_groups (dump, sched_verbose,
16441 current_sched_info->prev_head,
16442 current_sched_info->next_tail);
cbe26ab8 16443 else
c4ad648e
AM
16444 n_groups = redefine_groups (dump, sched_verbose,
16445 current_sched_info->prev_head,
16446 current_sched_info->next_tail);
cbe26ab8
DN
16447
16448 if (sched_verbose >= 6)
16449 {
16450 fprintf (dump, "ngroups = %d\n", n_groups);
16451 print_rtl (dump, current_sched_info->prev_head);
16452 fprintf (dump, "Done finish_sched\n");
16453 }
16454 }
16455}
b6c9286a 16456\f
b6c9286a
MM
16457/* Length in units of the trampoline for entering a nested function. */
16458
16459int
863d938c 16460rs6000_trampoline_size (void)
b6c9286a
MM
16461{
16462 int ret = 0;
16463
16464 switch (DEFAULT_ABI)
16465 {
16466 default:
16467 abort ();
16468
16469 case ABI_AIX:
8f802bfb 16470 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
16471 break;
16472
4dabc42d 16473 case ABI_DARWIN:
b6c9286a 16474 case ABI_V4:
03a7e1a5 16475 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 16476 break;
b6c9286a
MM
16477 }
16478
16479 return ret;
16480}
16481
16482/* Emit RTL insns to initialize the variable parts of a trampoline.
16483 FNADDR is an RTX for the address of the function's pure code.
16484 CXT is an RTX for the static chain value for the function. */
16485
16486void
a2369ed3 16487rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 16488{
ac2a93a1 16489 enum machine_mode pmode = Pmode;
8bd04c56
MM
16490 int regsize = (TARGET_32BIT) ? 4 : 8;
16491 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
16492
16493 switch (DEFAULT_ABI)
16494 {
16495 default:
16496 abort ();
16497
8bd04c56 16498/* Macros to shorten the code expansions below. */
39403d82 16499#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
16500#define MEM_PLUS(addr,offset) \
16501 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 16502
b6c9286a
MM
16503 /* Under AIX, just build the 3 word function descriptor */
16504 case ABI_AIX:
8bd04c56
MM
16505 {
16506 rtx fn_reg = gen_reg_rtx (pmode);
16507 rtx toc_reg = gen_reg_rtx (pmode);
16508 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 16509 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
16510 emit_move_insn (MEM_DEREF (addr), fn_reg);
16511 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
16512 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
16513 }
b6c9286a
MM
16514 break;
16515
4dabc42d
TC
16516 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
16517 case ABI_DARWIN:
b6c9286a 16518 case ABI_V4:
39403d82 16519 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
16520 FALSE, VOIDmode, 4,
16521 addr, pmode,
16522 GEN_INT (rs6000_trampoline_size ()), SImode,
16523 fnaddr, pmode,
16524 ctx_reg, pmode);
b6c9286a 16525 break;
b6c9286a
MM
16526 }
16527
16528 return;
16529}
7509c759
MM
16530
16531\f
91d231cb 16532/* Table of valid machine attributes. */
a4f6c312 16533
91d231cb 16534const struct attribute_spec rs6000_attribute_table[] =
7509c759 16535{
91d231cb 16536 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 16537 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
16538 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16539 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16540 { NULL, 0, 0, false, false, false, NULL }
91d231cb 16541};
7509c759 16542
8bb418a3
ZL
16543/* Handle the "altivec" attribute. The attribute may have
16544 arguments as follows:
f676971a 16545
8bb418a3
ZL
16546 __attribute__((altivec(vector__)))
16547 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
16548 __attribute__((altivec(bool__))) (always followed by 'unsigned')
16549
16550 and may appear more than once (e.g., 'vector bool char') in a
16551 given declaration. */
16552
16553static tree
16554rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
16555 int flags ATTRIBUTE_UNUSED,
16556 bool *no_add_attrs)
16557{
16558 tree type = *node, result = NULL_TREE;
16559 enum machine_mode mode;
16560 int unsigned_p;
16561 char altivec_type
16562 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
16563 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
16564 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
f676971a 16565 : '?');
8bb418a3
ZL
16566
16567 while (POINTER_TYPE_P (type)
16568 || TREE_CODE (type) == FUNCTION_TYPE
16569 || TREE_CODE (type) == METHOD_TYPE
16570 || TREE_CODE (type) == ARRAY_TYPE)
16571 type = TREE_TYPE (type);
16572
16573 mode = TYPE_MODE (type);
16574
16575 if (rs6000_warn_altivec_long
16576 && (type == long_unsigned_type_node || type == long_integer_type_node))
16577 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
16578
16579 switch (altivec_type)
16580 {
16581 case 'v':
8df83eae 16582 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
16583 switch (mode)
16584 {
c4ad648e
AM
16585 case SImode:
16586 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
16587 break;
16588 case HImode:
16589 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
16590 break;
16591 case QImode:
16592 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
16593 break;
16594 case SFmode: result = V4SF_type_node; break;
16595 /* If the user says 'vector int bool', we may be handed the 'bool'
16596 attribute _before_ the 'vector' attribute, and so select the
16597 proper type in the 'b' case below. */
16598 case V4SImode: case V8HImode: case V16QImode: case V4SFmode:
16599 result = type;
16600 default: break;
8bb418a3
ZL
16601 }
16602 break;
16603 case 'b':
16604 switch (mode)
16605 {
c4ad648e
AM
16606 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
16607 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
16608 case QImode: case V16QImode: result = bool_V16QI_type_node;
16609 default: break;
8bb418a3
ZL
16610 }
16611 break;
16612 case 'p':
16613 switch (mode)
16614 {
c4ad648e
AM
16615 case V8HImode: result = pixel_V8HI_type_node;
16616 default: break;
8bb418a3
ZL
16617 }
16618 default: break;
16619 }
16620
7958a2a6
FJ
16621 if (result && result != type && TYPE_READONLY (type))
16622 result = build_qualified_type (result, TYPE_QUAL_CONST);
16623
8bb418a3
ZL
16624 *no_add_attrs = true; /* No need to hang on to the attribute. */
16625
16626 if (!result)
16627 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
16628 else
16629 *node = reconstruct_complex_type (*node, result);
16630
16631 return NULL_TREE;
16632}
16633
f18eca82
ZL
16634/* AltiVec defines four built-in scalar types that serve as vector
16635 elements; we must teach the compiler how to mangle them. */
16636
16637static const char *
16638rs6000_mangle_fundamental_type (tree type)
16639{
16640 if (type == bool_char_type_node) return "U6__boolc";
16641 if (type == bool_short_type_node) return "U6__bools";
16642 if (type == pixel_type_node) return "u7__pixel";
16643 if (type == bool_int_type_node) return "U6__booli";
16644
16645 /* For all other types, use normal C++ mangling. */
16646 return NULL;
16647}
16648
a5c76ee6
ZW
16649/* Handle a "longcall" or "shortcall" attribute; arguments as in
16650 struct attribute_spec.handler. */
a4f6c312 16651
91d231cb 16652static tree
f676971a
EC
16653rs6000_handle_longcall_attribute (tree *node, tree name,
16654 tree args ATTRIBUTE_UNUSED,
16655 int flags ATTRIBUTE_UNUSED,
a2369ed3 16656 bool *no_add_attrs)
91d231cb
JM
16657{
16658 if (TREE_CODE (*node) != FUNCTION_TYPE
16659 && TREE_CODE (*node) != FIELD_DECL
16660 && TREE_CODE (*node) != TYPE_DECL)
16661 {
16662 warning ("`%s' attribute only applies to functions",
16663 IDENTIFIER_POINTER (name));
16664 *no_add_attrs = true;
16665 }
6a4cee5f 16666
91d231cb 16667 return NULL_TREE;
7509c759
MM
16668}
16669
a5c76ee6
ZW
16670/* Set longcall attributes on all functions declared when
16671 rs6000_default_long_calls is true. */
16672static void
a2369ed3 16673rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
16674{
16675 if (rs6000_default_long_calls
16676 && (TREE_CODE (type) == FUNCTION_TYPE
16677 || TREE_CODE (type) == METHOD_TYPE))
16678 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
16679 NULL_TREE,
16680 TYPE_ATTRIBUTES (type));
16681}
16682
3cb999d8
DE
16683/* Return a reference suitable for calling a function with the
16684 longcall attribute. */
a4f6c312 16685
6a4cee5f 16686struct rtx_def *
a2369ed3 16687rs6000_longcall_ref (rtx call_ref)
6a4cee5f 16688{
d330fd93 16689 const char *call_name;
6a4cee5f
MM
16690 tree node;
16691
16692 if (GET_CODE (call_ref) != SYMBOL_REF)
16693 return call_ref;
16694
16695 /* System V adds '.' to the internal name, so skip them. */
16696 call_name = XSTR (call_ref, 0);
16697 if (*call_name == '.')
16698 {
16699 while (*call_name == '.')
16700 call_name++;
16701
16702 node = get_identifier (call_name);
39403d82 16703 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
16704 }
16705
16706 return force_reg (Pmode, call_ref);
16707}
7509c759 16708\f
b64a1b53
RH
16709#ifdef USING_ELFOS_H
16710
7509c759
MM
16711/* A C statement or statements to switch to the appropriate section
16712 for output of RTX in mode MODE. You can assume that RTX is some
16713 kind of constant in RTL. The argument MODE is redundant except in
16714 the case of a `const_int' rtx. Select the section by calling
16715 `text_section' or one of the alternatives for other sections.
16716
16717 Do not define this macro if you put all constants in the read-only
16718 data section. */
16719
b64a1b53 16720static void
f676971a 16721rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
a2369ed3 16722 unsigned HOST_WIDE_INT align)
7509c759 16723{
a9098fd0 16724 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 16725 toc_section ();
7509c759 16726 else
b64a1b53 16727 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
16728}
16729
16730/* A C statement or statements to switch to the appropriate
16731 section for output of DECL. DECL is either a `VAR_DECL' node
16732 or a constant of some sort. RELOC indicates whether forming
16733 the initial value of DECL requires link-time relocations. */
16734
ae46c4e0 16735static void
f676971a 16736rs6000_elf_select_section (tree decl, int reloc,
a2369ed3 16737 unsigned HOST_WIDE_INT align)
7509c759 16738{
f1384257
AM
16739 /* Pretend that we're always building for a shared library when
16740 ABI_AIX, because otherwise we end up with dynamic relocations
16741 in read-only sections. This happens for function pointers,
16742 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
16743 default_elf_select_section_1 (decl, reloc, align,
16744 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
16745}
16746
16747/* A C statement to build up a unique section name, expressed as a
16748 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
16749 RELOC indicates whether the initial value of EXP requires
16750 link-time relocations. If you do not define this macro, GCC will use
16751 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 16752 macro can now be called for uninitialized data items as well as
4912a07c 16753 initialized data and functions. */
63019373 16754
ae46c4e0 16755static void
a2369ed3 16756rs6000_elf_unique_section (tree decl, int reloc)
63019373 16757{
f1384257
AM
16758 /* As above, pretend that we're always building for a shared library
16759 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
16760 default_unique_section_1 (decl, reloc,
16761 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 16762}
d9407988 16763\f
d1908feb
JJ
16764/* For a SYMBOL_REF, set generic flags and then perform some
16765 target-specific processing.
16766
d1908feb
JJ
16767 When the AIX ABI is requested on a non-AIX system, replace the
16768 function name with the real name (with a leading .) rather than the
16769 function descriptor name. This saves a lot of overriding code to
16770 read the prefixes. */
d9407988 16771
fb49053f 16772static void
a2369ed3 16773rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 16774{
d1908feb 16775 default_encode_section_info (decl, rtl, first);
b2003250 16776
d1908feb
JJ
16777 if (first
16778 && TREE_CODE (decl) == FUNCTION_DECL
16779 && !TARGET_AIX
16780 && DEFAULT_ABI == ABI_AIX)
d9407988 16781 {
c6a2438a 16782 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
16783 size_t len = strlen (XSTR (sym_ref, 0));
16784 char *str = alloca (len + 2);
16785 str[0] = '.';
16786 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
16787 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 16788 }
d9407988
MM
16789}
16790
0e5dbd9b 16791static bool
a2369ed3 16792rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
16793{
16794 if (rs6000_sdata == SDATA_NONE)
16795 return false;
16796
16797 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
16798 {
16799 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
16800 if (strcmp (section, ".sdata") == 0
16801 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
16802 || strcmp (section, ".sbss") == 0
16803 || strcmp (section, ".sbss2") == 0
16804 || strcmp (section, ".PPC.EMB.sdata0") == 0
16805 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
16806 return true;
16807 }
16808 else
16809 {
16810 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
16811
16812 if (size > 0
307b599c 16813 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
16814 /* If it's not public, and we're not going to reference it there,
16815 there's no need to put it in the small data section. */
0e5dbd9b
DE
16816 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
16817 return true;
16818 }
16819
16820 return false;
16821}
16822
b91da81f 16823#endif /* USING_ELFOS_H */
000034eb 16824
a6c2a102 16825\f
000034eb 16826/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
16827 ADDR can be effectively incremented by incrementing REG.
16828
16829 r0 is special and we must not select it as an address
16830 register by this routine since our caller will try to
16831 increment the returned register via an "la" instruction. */
000034eb
DE
16832
16833struct rtx_def *
a2369ed3 16834find_addr_reg (rtx addr)
000034eb
DE
16835{
16836 while (GET_CODE (addr) == PLUS)
16837 {
02441cd6
JL
16838 if (GET_CODE (XEXP (addr, 0)) == REG
16839 && REGNO (XEXP (addr, 0)) != 0)
000034eb 16840 addr = XEXP (addr, 0);
02441cd6
JL
16841 else if (GET_CODE (XEXP (addr, 1)) == REG
16842 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
16843 addr = XEXP (addr, 1);
16844 else if (CONSTANT_P (XEXP (addr, 0)))
16845 addr = XEXP (addr, 1);
16846 else if (CONSTANT_P (XEXP (addr, 1)))
16847 addr = XEXP (addr, 0);
16848 else
16849 abort ();
16850 }
02441cd6 16851 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
16852 return addr;
16853 abort ();
16854}
16855
a6c2a102 16856void
a2369ed3 16857rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
16858{
16859 fatal_insn ("bad address", op);
16860}
c8023011 16861
ee890fe2
SS
16862#if TARGET_MACHO
16863
efdba735 16864static tree branch_island_list = 0;
ee890fe2 16865
efdba735
SH
16866/* Remember to generate a branch island for far calls to the given
16867 function. */
ee890fe2 16868
f676971a 16869static void
c4ad648e
AM
16870add_compiler_branch_island (tree label_name, tree function_name,
16871 int line_number)
ee890fe2 16872{
efdba735 16873 tree branch_island = build_tree_list (function_name, label_name);
7d60be94 16874 TREE_TYPE (branch_island) = build_int_cst (NULL_TREE, line_number);
efdba735
SH
16875 TREE_CHAIN (branch_island) = branch_island_list;
16876 branch_island_list = branch_island;
ee890fe2
SS
16877}
16878
efdba735
SH
16879#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
16880#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
16881#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
16882 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 16883
efdba735
SH
16884/* Generate far-jump branch islands for everything on the
16885 branch_island_list. Invoked immediately after the last instruction
16886 of the epilogue has been emitted; the branch-islands must be
16887 appended to, and contiguous with, the function body. Mach-O stubs
16888 are generated in machopic_output_stub(). */
ee890fe2 16889
efdba735
SH
16890static void
16891macho_branch_islands (void)
16892{
16893 char tmp_buf[512];
16894 tree branch_island;
16895
16896 for (branch_island = branch_island_list;
16897 branch_island;
16898 branch_island = TREE_CHAIN (branch_island))
16899 {
16900 const char *label =
16901 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
16902 const char *name =
11abc112 16903 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island));
efdba735
SH
16904 char name_buf[512];
16905 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
16906 if (name[0] == '*' || name[0] == '&')
16907 strcpy (name_buf, name+1);
16908 else
16909 {
16910 name_buf[0] = '_';
16911 strcpy (name_buf+1, name);
16912 }
16913 strcpy (tmp_buf, "\n");
16914 strcat (tmp_buf, label);
ee890fe2 16915#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16916 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16917 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16918 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 16919#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
16920 if (flag_pic)
16921 {
16922 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
16923 strcat (tmp_buf, label);
16924 strcat (tmp_buf, "_pic\n");
16925 strcat (tmp_buf, label);
16926 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
f676971a 16927
efdba735
SH
16928 strcat (tmp_buf, "\taddis r11,r11,ha16(");
16929 strcat (tmp_buf, name_buf);
16930 strcat (tmp_buf, " - ");
16931 strcat (tmp_buf, label);
16932 strcat (tmp_buf, "_pic)\n");
f676971a 16933
efdba735 16934 strcat (tmp_buf, "\tmtlr r0\n");
f676971a 16935
efdba735
SH
16936 strcat (tmp_buf, "\taddi r12,r11,lo16(");
16937 strcat (tmp_buf, name_buf);
16938 strcat (tmp_buf, " - ");
16939 strcat (tmp_buf, label);
16940 strcat (tmp_buf, "_pic)\n");
f676971a 16941
efdba735
SH
16942 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
16943 }
16944 else
16945 {
16946 strcat (tmp_buf, ":\nlis r12,hi16(");
16947 strcat (tmp_buf, name_buf);
16948 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
16949 strcat (tmp_buf, name_buf);
16950 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
16951 }
16952 output_asm_insn (tmp_buf, 0);
ee890fe2 16953#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16954 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16955 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16956 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 16957#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 16958 }
ee890fe2 16959
efdba735 16960 branch_island_list = 0;
ee890fe2
SS
16961}
16962
16963/* NO_PREVIOUS_DEF checks in the link list whether the function name is
16964 already there or not. */
16965
efdba735 16966static int
a2369ed3 16967no_previous_def (tree function_name)
ee890fe2 16968{
efdba735
SH
16969 tree branch_island;
16970 for (branch_island = branch_island_list;
16971 branch_island;
16972 branch_island = TREE_CHAIN (branch_island))
16973 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
16974 return 0;
16975 return 1;
16976}
16977
16978/* GET_PREV_LABEL gets the label name from the previous definition of
16979 the function. */
16980
efdba735 16981static tree
a2369ed3 16982get_prev_label (tree function_name)
ee890fe2 16983{
efdba735
SH
16984 tree branch_island;
16985 for (branch_island = branch_island_list;
16986 branch_island;
16987 branch_island = TREE_CHAIN (branch_island))
16988 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
16989 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
16990 return 0;
16991}
16992
16993/* INSN is either a function call or a millicode call. It may have an
f676971a 16994 unconditional jump in its delay slot.
ee890fe2
SS
16995
16996 CALL_DEST is the routine we are calling. */
16997
16998char *
c4ad648e
AM
16999output_call (rtx insn, rtx *operands, int dest_operand_number,
17000 int cookie_operand_number)
ee890fe2
SS
17001{
17002 static char buf[256];
efdba735
SH
17003 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
17004 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
17005 {
17006 tree labelname;
efdba735 17007 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
f676971a 17008
ee890fe2
SS
17009 if (no_previous_def (funname))
17010 {
308c142a 17011 int line_number = 0;
ee890fe2
SS
17012 rtx label_rtx = gen_label_rtx ();
17013 char *label_buf, temp_buf[256];
17014 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
17015 CODE_LABEL_NUMBER (label_rtx));
17016 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
17017 labelname = get_identifier (label_buf);
17018 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
17019 if (insn)
17020 line_number = NOTE_LINE_NUMBER (insn);
efdba735 17021 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
17022 }
17023 else
17024 labelname = get_prev_label (funname);
17025
efdba735
SH
17026 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
17027 instruction will reach 'foo', otherwise link as 'bl L42'".
17028 "L42" should be a 'branch island', that will do a far jump to
17029 'foo'. Branch islands are generated in
17030 macho_branch_islands(). */
ee890fe2 17031 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 17032 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
17033 }
17034 else
efdba735
SH
17035 sprintf (buf, "bl %%z%d", dest_operand_number);
17036 return buf;
ee890fe2
SS
17037}
17038
ee890fe2
SS
17039/* Generate PIC and indirect symbol stubs. */
17040
17041void
a2369ed3 17042machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
17043{
17044 unsigned int length;
a4f6c312
SS
17045 char *symbol_name, *lazy_ptr_name;
17046 char *local_label_0;
ee890fe2
SS
17047 static int label = 0;
17048
df56a27f 17049 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 17050 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 17051
ee890fe2 17052
ee890fe2
SS
17053 length = strlen (symb);
17054 symbol_name = alloca (length + 32);
17055 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
17056
17057 lazy_ptr_name = alloca (length + 32);
17058 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
17059
ee890fe2 17060 if (flag_pic == 2)
d3c300d2 17061 machopic_picsymbol_stub1_section ();
ee890fe2 17062 else
d3c300d2 17063 machopic_symbol_stub1_section ();
ee890fe2
SS
17064
17065 if (flag_pic == 2)
17066 {
d974312d
DJ
17067 fprintf (file, "\t.align 5\n");
17068
17069 fprintf (file, "%s:\n", stub);
17070 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
17071
876455fa
AP
17072 label++;
17073 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
17074 sprintf (local_label_0, "\"L%011d$spb\"", label);
f676971a 17075
ee890fe2
SS
17076 fprintf (file, "\tmflr r0\n");
17077 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
17078 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
17079 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
17080 lazy_ptr_name, local_label_0);
17081 fprintf (file, "\tmtlr r0\n");
d3c300d2 17082 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
17083 lazy_ptr_name, local_label_0);
17084 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
17085 fprintf (file, "\tbctr\n");
17086 }
17087 else
d974312d
DJ
17088 {
17089 fprintf (file, "\t.align 4\n");
17090
17091 fprintf (file, "%s:\n", stub);
17092 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
17093
17094 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
17095 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
17096 fprintf (file, "\tmtctr r12\n");
17097 fprintf (file, "\tbctr\n");
17098 }
f676971a 17099
ee890fe2
SS
17100 machopic_lazy_symbol_ptr_section ();
17101 fprintf (file, "%s:\n", lazy_ptr_name);
17102 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
49bd1d27
SS
17103 fprintf (file, "%sdyld_stub_binding_helper\n",
17104 (TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t"));
ee890fe2
SS
17105}
17106
17107/* Legitimize PIC addresses. If the address is already
17108 position-independent, we return ORIG. Newly generated
17109 position-independent addresses go into a reg. This is REG if non
17110 zero, otherwise we allocate register(s) as necessary. */
17111
c859cda6 17112#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
17113
17114rtx
f676971a 17115rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
a2369ed3 17116 rtx reg)
ee890fe2
SS
17117{
17118 rtx base, offset;
17119
17120 if (reg == NULL && ! reload_in_progress && ! reload_completed)
17121 reg = gen_reg_rtx (Pmode);
17122
17123 if (GET_CODE (orig) == CONST)
17124 {
17125 if (GET_CODE (XEXP (orig, 0)) == PLUS
17126 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
17127 return orig;
17128
17129 if (GET_CODE (XEXP (orig, 0)) == PLUS)
17130 {
2cf520bf 17131 /* Use a different reg for the intermediate value, as
a3c9585f 17132 it will be marked UNCHANGING. */
2cf520bf
GK
17133 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
17134
a4f6c312
SS
17135 base =
17136 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 17137 Pmode, reg_temp);
a4f6c312
SS
17138 offset =
17139 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
17140 Pmode, reg);
ee890fe2
SS
17141 }
17142 else
17143 abort ();
17144
17145 if (GET_CODE (offset) == CONST_INT)
17146 {
17147 if (SMALL_INT (offset))
ed8908e7 17148 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
17149 else if (! reload_in_progress && ! reload_completed)
17150 offset = force_reg (Pmode, offset);
17151 else
c859cda6
DJ
17152 {
17153 rtx mem = force_const_mem (Pmode, orig);
17154 return machopic_legitimize_pic_address (mem, Pmode, reg);
17155 }
ee890fe2 17156 }
f1c25d3b 17157 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
17158 }
17159
17160 /* Fall back on generic machopic code. */
17161 return machopic_legitimize_pic_address (orig, mode, reg);
17162}
17163
17164/* This is just a placeholder to make linking work without having to
17165 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
17166 ever needed for Darwin (not too likely!) this would have to get a
17167 real definition. */
17168
17169void
863d938c 17170toc_section (void)
ee890fe2
SS
17171{
17172}
17173
c4e18b1c
GK
17174/* Output a .machine directive for the Darwin assembler, and call
17175 the generic start_file routine. */
17176
17177static void
17178rs6000_darwin_file_start (void)
17179{
17180 static const struct
17181 {
17182 const char *arg;
17183 const char *name;
17184 int if_set;
17185 } mapping[] = {
17186 { "970", "ppc970", MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64 },
17187 { "power4", "ppc970", 0 },
17188 { "G5", "ppc970", 0 },
17189 { "7450", "ppc7450", 0 },
17190 { "7400", "ppc7400", MASK_ALTIVEC },
17191 { "G4", "ppc7400", 0 },
17192 { "750", "ppc750", 0 },
17193 { "740", "ppc750", 0 },
17194 { "G3", "ppc750", 0 },
17195 { "604e", "ppc604e", 0 },
17196 { "604", "ppc604", 0 },
17197 { "603e", "ppc603", 0 },
17198 { "603", "ppc603", 0 },
17199 { "601", "ppc601", 0 },
17200 { NULL, "ppc", 0 } };
17201 const char *cpu_id = "";
17202 size_t i;
17203
17204 rs6000_file_start();
17205
17206 /* Determine the argument to -mcpu=. Default to G3 if not specified. */
17207 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
17208 if (rs6000_select[i].set_arch_p && rs6000_select[i].string
17209 && rs6000_select[i].string[0] != '\0')
17210 cpu_id = rs6000_select[i].string;
17211
17212 /* Look through the mapping array. Pick the first name that either
17213 matches the argument, has a bit set in IF_SET that is also set
17214 in the target flags, or has a NULL name. */
17215
17216 i = 0;
17217 while (mapping[i].arg != NULL
17218 && strcmp (mapping[i].arg, cpu_id) != 0
17219 && (mapping[i].if_set & target_flags) == 0)
17220 i++;
17221
17222 fprintf (asm_out_file, "\t.machine %s\n", mapping[i].name);
17223}
17224
ee890fe2 17225#endif /* TARGET_MACHO */
7c262518
RH
17226
17227#if TARGET_ELF
17228static unsigned int
a2369ed3 17229rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 17230{
1ff8f81a
AM
17231 return default_section_type_flags_1 (decl, name, reloc,
17232 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 17233}
d9f6800d
RH
17234
17235/* Record an element in the table of global constructors. SYMBOL is
17236 a SYMBOL_REF of the function to be called; PRIORITY is a number
17237 between 0 and MAX_INIT_PRIORITY.
17238
17239 This differs from default_named_section_asm_out_constructor in
17240 that we have special handling for -mrelocatable. */
17241
17242static void
a2369ed3 17243rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
17244{
17245 const char *section = ".ctors";
17246 char buf[16];
17247
17248 if (priority != DEFAULT_INIT_PRIORITY)
17249 {
17250 sprintf (buf, ".ctors.%.5u",
c4ad648e
AM
17251 /* Invert the numbering so the linker puts us in the proper
17252 order; constructors are run from right to left, and the
17253 linker sorts in increasing order. */
17254 MAX_INIT_PRIORITY - priority);
d9f6800d
RH
17255 section = buf;
17256 }
17257
715bdd29
RH
17258 named_section_flags (section, SECTION_WRITE);
17259 assemble_align (POINTER_SIZE);
d9f6800d
RH
17260
17261 if (TARGET_RELOCATABLE)
17262 {
17263 fputs ("\t.long (", asm_out_file);
17264 output_addr_const (asm_out_file, symbol);
17265 fputs (")@fixup\n", asm_out_file);
17266 }
17267 else
c8af3574 17268 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
17269}
17270
17271static void
a2369ed3 17272rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
17273{
17274 const char *section = ".dtors";
17275 char buf[16];
17276
17277 if (priority != DEFAULT_INIT_PRIORITY)
17278 {
17279 sprintf (buf, ".dtors.%.5u",
c4ad648e
AM
17280 /* Invert the numbering so the linker puts us in the proper
17281 order; constructors are run from right to left, and the
17282 linker sorts in increasing order. */
17283 MAX_INIT_PRIORITY - priority);
d9f6800d
RH
17284 section = buf;
17285 }
17286
715bdd29
RH
17287 named_section_flags (section, SECTION_WRITE);
17288 assemble_align (POINTER_SIZE);
d9f6800d
RH
17289
17290 if (TARGET_RELOCATABLE)
17291 {
17292 fputs ("\t.long (", asm_out_file);
17293 output_addr_const (asm_out_file, symbol);
17294 fputs (")@fixup\n", asm_out_file);
17295 }
17296 else
c8af3574 17297 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 17298}
9739c90c
JJ
17299
17300void
a2369ed3 17301rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
17302{
17303 if (TARGET_64BIT)
17304 {
17305 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
17306 ASM_OUTPUT_LABEL (file, name);
17307 fputs (DOUBLE_INT_ASM_OP, file);
85b776df
AM
17308 rs6000_output_function_entry (file, name);
17309 fputs (",.TOC.@tocbase,0\n\t.previous\n", file);
17310 if (DOT_SYMBOLS)
9739c90c 17311 {
85b776df 17312 fputs ("\t.size\t", file);
9739c90c 17313 assemble_name (file, name);
85b776df
AM
17314 fputs (",24\n\t.type\t.", file);
17315 assemble_name (file, name);
17316 fputs (",@function\n", file);
17317 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
17318 {
17319 fputs ("\t.globl\t.", file);
17320 assemble_name (file, name);
17321 putc ('\n', file);
17322 }
9739c90c 17323 }
85b776df
AM
17324 else
17325 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
9739c90c 17326 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
85b776df
AM
17327 rs6000_output_function_entry (file, name);
17328 fputs (":\n", file);
9739c90c
JJ
17329 return;
17330 }
17331
17332 if (TARGET_RELOCATABLE
17333 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 17334 && uses_TOC ())
9739c90c
JJ
17335 {
17336 char buf[256];
17337
17338 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
17339
17340 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
17341 fprintf (file, "\t.long ");
17342 assemble_name (file, buf);
17343 putc ('-', file);
17344 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
17345 assemble_name (file, buf);
17346 putc ('\n', file);
17347 }
17348
17349 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
17350 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
17351
17352 if (DEFAULT_ABI == ABI_AIX)
17353 {
17354 const char *desc_name, *orig_name;
17355
17356 orig_name = (*targetm.strip_name_encoding) (name);
17357 desc_name = orig_name;
17358 while (*desc_name == '.')
17359 desc_name++;
17360
17361 if (TREE_PUBLIC (decl))
17362 fprintf (file, "\t.globl %s\n", desc_name);
17363
17364 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
17365 fprintf (file, "%s:\n", desc_name);
17366 fprintf (file, "\t.long %s\n", orig_name);
17367 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
17368 if (DEFAULT_ABI == ABI_AIX)
17369 fputs ("\t.long 0\n", file);
17370 fprintf (file, "\t.previous\n");
17371 }
17372 ASM_OUTPUT_LABEL (file, name);
17373}
7c262518
RH
17374#endif
17375
cbaaba19 17376#if TARGET_XCOFF
7c262518 17377static void
a2369ed3 17378rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
17379{
17380 fputs (GLOBAL_ASM_OP, stream);
17381 RS6000_OUTPUT_BASENAME (stream, name);
17382 putc ('\n', stream);
17383}
17384
17385static void
c18a5b6c
MM
17386rs6000_xcoff_asm_named_section (const char *name, unsigned int flags,
17387 tree decl ATTRIBUTE_UNUSED)
7c262518 17388{
0e5dbd9b
DE
17389 int smclass;
17390 static const char * const suffix[3] = { "PR", "RO", "RW" };
17391
17392 if (flags & SECTION_CODE)
17393 smclass = 0;
17394 else if (flags & SECTION_WRITE)
17395 smclass = 2;
17396 else
17397 smclass = 1;
17398
5b5198f7 17399 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 17400 (flags & SECTION_CODE) ? "." : "",
5b5198f7 17401 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 17402}
ae46c4e0
RH
17403
17404static void
f676971a 17405rs6000_xcoff_select_section (tree decl, int reloc,
c4ad648e 17406 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 17407{
5add3202 17408 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 17409 {
0e5dbd9b 17410 if (TREE_PUBLIC (decl))
c4ad648e 17411 read_only_data_section ();
ae46c4e0 17412 else
c4ad648e 17413 read_only_private_data_section ();
ae46c4e0
RH
17414 }
17415 else
17416 {
0e5dbd9b 17417 if (TREE_PUBLIC (decl))
c4ad648e 17418 data_section ();
ae46c4e0 17419 else
c4ad648e 17420 private_data_section ();
ae46c4e0
RH
17421 }
17422}
17423
17424static void
a2369ed3 17425rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
17426{
17427 const char *name;
ae46c4e0 17428
5b5198f7
DE
17429 /* Use select_section for private and uninitialized data. */
17430 if (!TREE_PUBLIC (decl)
17431 || DECL_COMMON (decl)
0e5dbd9b
DE
17432 || DECL_INITIAL (decl) == NULL_TREE
17433 || DECL_INITIAL (decl) == error_mark_node
17434 || (flag_zero_initialized_in_bss
17435 && initializer_zerop (DECL_INITIAL (decl))))
17436 return;
17437
17438 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17439 name = (*targetm.strip_name_encoding) (name);
17440 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 17441}
b64a1b53 17442
fb49053f
RH
17443/* Select section for constant in constant pool.
17444
17445 On RS/6000, all constants are in the private read-only data area.
17446 However, if this is being placed in the TOC it must be output as a
17447 toc entry. */
17448
b64a1b53 17449static void
f676971a 17450rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
c4ad648e 17451 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
17452{
17453 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
17454 toc_section ();
17455 else
17456 read_only_private_data_section ();
17457}
772c5265
RH
17458
17459/* Remove any trailing [DS] or the like from the symbol name. */
17460
17461static const char *
a2369ed3 17462rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
17463{
17464 size_t len;
17465 if (*name == '*')
17466 name++;
17467 len = strlen (name);
17468 if (name[len - 1] == ']')
17469 return ggc_alloc_string (name, len - 4);
17470 else
17471 return name;
17472}
17473
5add3202
DE
17474/* Section attributes. AIX is always PIC. */
17475
17476static unsigned int
a2369ed3 17477rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 17478{
5b5198f7
DE
17479 unsigned int align;
17480 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
17481
17482 /* Align to at least UNIT size. */
17483 if (flags & SECTION_CODE)
17484 align = MIN_UNITS_PER_WORD;
17485 else
17486 /* Increase alignment of large objects if not already stricter. */
17487 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
17488 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
17489 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
17490
17491 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 17492}
a5fe455b 17493
1bc7c5b6
ZW
17494/* Output at beginning of assembler file.
17495
17496 Initialize the section names for the RS/6000 at this point.
17497
17498 Specify filename, including full path, to assembler.
17499
17500 We want to go into the TOC section so at least one .toc will be emitted.
17501 Also, in order to output proper .bs/.es pairs, we need at least one static
17502 [RW] section emitted.
17503
17504 Finally, declare mcount when profiling to make the assembler happy. */
17505
17506static void
863d938c 17507rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
17508{
17509 rs6000_gen_section_name (&xcoff_bss_section_name,
17510 main_input_filename, ".bss_");
17511 rs6000_gen_section_name (&xcoff_private_data_section_name,
17512 main_input_filename, ".rw_");
17513 rs6000_gen_section_name (&xcoff_read_only_section_name,
17514 main_input_filename, ".ro_");
17515
17516 fputs ("\t.file\t", asm_out_file);
17517 output_quoted_string (asm_out_file, main_input_filename);
17518 fputc ('\n', asm_out_file);
17519 toc_section ();
17520 if (write_symbols != NO_DEBUG)
17521 private_data_section ();
17522 text_section ();
17523 if (profile_flag)
17524 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
17525 rs6000_file_start ();
17526}
17527
a5fe455b
ZW
17528/* Output at end of assembler file.
17529 On the RS/6000, referencing data should automatically pull in text. */
17530
17531static void
863d938c 17532rs6000_xcoff_file_end (void)
a5fe455b
ZW
17533{
17534 text_section ();
17535 fputs ("_section_.text:\n", asm_out_file);
17536 data_section ();
17537 fputs (TARGET_32BIT
17538 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
17539 asm_out_file);
17540}
f1384257 17541#endif /* TARGET_XCOFF */
0e5dbd9b 17542
f1384257
AM
17543#if TARGET_MACHO
17544/* Cross-module name binding. Darwin does not support overriding
7f3d8013 17545 functions at dynamic-link time. */
0e5dbd9b 17546
2bcc50d0 17547static bool
a2369ed3 17548rs6000_binds_local_p (tree decl)
0e5dbd9b 17549{
f1384257 17550 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 17551}
f1384257 17552#endif
34bb030a 17553
3c50106f
RH
17554/* Compute a (partial) cost for rtx X. Return true if the complete
17555 cost has been computed, and false if subexpressions should be
17556 scanned. In either case, *TOTAL contains the cost result. */
17557
17558static bool
1494c534 17559rs6000_rtx_costs (rtx x, int code, int outer_code, int *total)
3c50106f 17560{
f0517163
RS
17561 enum machine_mode mode = GET_MODE (x);
17562
3c50106f
RH
17563 switch (code)
17564 {
30a555d9 17565 /* On the RS/6000, if it is valid in the insn, it is free. */
3c50106f 17566 case CONST_INT:
066cd967
DE
17567 if (((outer_code == SET
17568 || outer_code == PLUS
17569 || outer_code == MINUS)
17570 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17571 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
17572 || ((outer_code == IOR || outer_code == XOR)
17573 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17574 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
627b6fe2
DJ
17575 || ((outer_code == DIV || outer_code == UDIV
17576 || outer_code == MOD || outer_code == UMOD)
17577 && exact_log2 (INTVAL (x)) >= 0)
066cd967
DE
17578 || (outer_code == AND
17579 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17580 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17581 || mask_operand (x, VOIDmode)))
066cd967
DE
17582 || outer_code == ASHIFT
17583 || outer_code == ASHIFTRT
17584 || outer_code == LSHIFTRT
17585 || outer_code == ROTATE
17586 || outer_code == ROTATERT
d5861a7a 17587 || outer_code == ZERO_EXTRACT
066cd967
DE
17588 || (outer_code == MULT
17589 && CONST_OK_FOR_LETTER_P (INTVAL (x), 'I'))
17590 || (outer_code == COMPARE
17591 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17592 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'K'))))
17593 {
17594 *total = 0;
17595 return true;
17596 }
17597 else if ((outer_code == PLUS
17598 && reg_or_add_cint64_operand (x, VOIDmode))
17599 || (outer_code == MINUS
17600 && reg_or_sub_cint64_operand (x, VOIDmode))
17601 || ((outer_code == SET
17602 || outer_code == IOR
17603 || outer_code == XOR)
17604 && (INTVAL (x)
17605 & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0))
17606 {
17607 *total = COSTS_N_INSNS (1);
17608 return true;
17609 }
17610 /* FALLTHRU */
17611
17612 case CONST_DOUBLE:
17613 if (mode == DImode
17614 && ((outer_code == AND
17615 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17616 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17617 || mask64_operand (x, DImode)))
066cd967
DE
17618 || ((outer_code == IOR || outer_code == XOR)
17619 && CONST_DOUBLE_HIGH (x) == 0
17620 && (CONST_DOUBLE_LOW (x)
17621 & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0)))
17622 {
17623 *total = 0;
17624 return true;
17625 }
17626 else if (mode == DImode
17627 && (outer_code == SET
17628 || outer_code == IOR
17629 || outer_code == XOR)
17630 && CONST_DOUBLE_HIGH (x) == 0)
17631 {
17632 *total = COSTS_N_INSNS (1);
17633 return true;
17634 }
17635 /* FALLTHRU */
17636
3c50106f 17637 case CONST:
066cd967 17638 case HIGH:
3c50106f 17639 case SYMBOL_REF:
066cd967
DE
17640 case MEM:
17641 /* When optimizing for size, MEM should be slightly more expensive
17642 than generating address, e.g., (plus (reg) (const)).
c112cf2b 17643 L1 cache latency is about two instructions. */
066cd967 17644 *total = optimize_size ? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (2);
3c50106f
RH
17645 return true;
17646
30a555d9
DE
17647 case LABEL_REF:
17648 *total = 0;
17649 return true;
17650
3c50106f 17651 case PLUS:
f0517163 17652 if (mode == DFmode)
066cd967
DE
17653 {
17654 if (GET_CODE (XEXP (x, 0)) == MULT)
17655 {
17656 /* FNMA accounted in outer NEG. */
17657 if (outer_code == NEG)
17658 *total = rs6000_cost->dmul - rs6000_cost->fp;
17659 else
17660 *total = rs6000_cost->dmul;
17661 }
17662 else
17663 *total = rs6000_cost->fp;
17664 }
f0517163 17665 else if (mode == SFmode)
066cd967
DE
17666 {
17667 /* FNMA accounted in outer NEG. */
17668 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17669 *total = 0;
17670 else
17671 *total = rs6000_cost->fp;
17672 }
938bf747
RS
17673 else if (GET_CODE (XEXP (x, 0)) == MULT)
17674 {
17675 /* The rs6000 doesn't have shift-and-add instructions. */
17676 rs6000_rtx_costs (XEXP (x, 0), MULT, PLUS, total);
17677 *total += COSTS_N_INSNS (1);
17678 }
f0517163 17679 else
066cd967
DE
17680 *total = COSTS_N_INSNS (1);
17681 return false;
3c50106f 17682
52190329 17683 case MINUS:
f0517163 17684 if (mode == DFmode)
066cd967
DE
17685 {
17686 if (GET_CODE (XEXP (x, 0)) == MULT)
17687 {
17688 /* FNMA accounted in outer NEG. */
17689 if (outer_code == NEG)
17690 *total = 0;
17691 else
17692 *total = rs6000_cost->dmul;
17693 }
17694 else
17695 *total = rs6000_cost->fp;
17696 }
f0517163 17697 else if (mode == SFmode)
066cd967
DE
17698 {
17699 /* FNMA accounted in outer NEG. */
17700 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17701 *total = 0;
17702 else
17703 *total = rs6000_cost->fp;
17704 }
938bf747
RS
17705 else if (GET_CODE (XEXP (x, 0)) == MULT)
17706 {
17707 /* The rs6000 doesn't have shift-and-sub instructions. */
17708 rs6000_rtx_costs (XEXP (x, 0), MULT, MINUS, total);
17709 *total += COSTS_N_INSNS (1);
17710 }
f0517163 17711 else
c4ad648e 17712 *total = COSTS_N_INSNS (1);
066cd967 17713 return false;
3c50106f
RH
17714
17715 case MULT:
8b897cfa 17716 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3c50106f 17717 {
8b897cfa
RS
17718 if (INTVAL (XEXP (x, 1)) >= -256
17719 && INTVAL (XEXP (x, 1)) <= 255)
06a67bdd 17720 *total = rs6000_cost->mulsi_const9;
8b897cfa 17721 else
06a67bdd 17722 *total = rs6000_cost->mulsi_const;
3c50106f 17723 }
066cd967
DE
17724 /* FMA accounted in outer PLUS/MINUS. */
17725 else if ((mode == DFmode || mode == SFmode)
17726 && (outer_code == PLUS || outer_code == MINUS))
17727 *total = 0;
f0517163 17728 else if (mode == DFmode)
06a67bdd 17729 *total = rs6000_cost->dmul;
f0517163 17730 else if (mode == SFmode)
06a67bdd 17731 *total = rs6000_cost->fp;
f0517163 17732 else if (mode == DImode)
06a67bdd 17733 *total = rs6000_cost->muldi;
8b897cfa 17734 else
06a67bdd 17735 *total = rs6000_cost->mulsi;
066cd967 17736 return false;
3c50106f
RH
17737
17738 case DIV:
17739 case MOD:
f0517163
RS
17740 if (FLOAT_MODE_P (mode))
17741 {
06a67bdd
RS
17742 *total = mode == DFmode ? rs6000_cost->ddiv
17743 : rs6000_cost->sdiv;
066cd967 17744 return false;
f0517163 17745 }
5efb1046 17746 /* FALLTHRU */
3c50106f
RH
17747
17748 case UDIV:
17749 case UMOD:
627b6fe2
DJ
17750 if (GET_CODE (XEXP (x, 1)) == CONST_INT
17751 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
17752 {
17753 if (code == DIV || code == MOD)
17754 /* Shift, addze */
17755 *total = COSTS_N_INSNS (2);
17756 else
17757 /* Shift */
17758 *total = COSTS_N_INSNS (1);
17759 }
c4ad648e 17760 else
627b6fe2
DJ
17761 {
17762 if (GET_MODE (XEXP (x, 1)) == DImode)
17763 *total = rs6000_cost->divdi;
17764 else
17765 *total = rs6000_cost->divsi;
17766 }
17767 /* Add in shift and subtract for MOD. */
17768 if (code == MOD || code == UMOD)
17769 *total += COSTS_N_INSNS (2);
066cd967 17770 return false;
3c50106f
RH
17771
17772 case FFS:
17773 *total = COSTS_N_INSNS (4);
066cd967 17774 return false;
3c50106f 17775
06a67bdd 17776 case NOT:
066cd967
DE
17777 if (outer_code == AND || outer_code == IOR || outer_code == XOR)
17778 {
17779 *total = 0;
17780 return false;
17781 }
17782 /* FALLTHRU */
17783
17784 case AND:
17785 case IOR:
17786 case XOR:
d5861a7a
DE
17787 case ZERO_EXTRACT:
17788 *total = COSTS_N_INSNS (1);
17789 return false;
17790
066cd967
DE
17791 case ASHIFT:
17792 case ASHIFTRT:
17793 case LSHIFTRT:
17794 case ROTATE:
17795 case ROTATERT:
d5861a7a 17796 /* Handle mul_highpart. */
066cd967
DE
17797 if (outer_code == TRUNCATE
17798 && GET_CODE (XEXP (x, 0)) == MULT)
17799 {
17800 if (mode == DImode)
17801 *total = rs6000_cost->muldi;
17802 else
17803 *total = rs6000_cost->mulsi;
17804 return true;
17805 }
d5861a7a
DE
17806 else if (outer_code == AND)
17807 *total = 0;
17808 else
17809 *total = COSTS_N_INSNS (1);
17810 return false;
17811
17812 case SIGN_EXTEND:
17813 case ZERO_EXTEND:
17814 if (GET_CODE (XEXP (x, 0)) == MEM)
17815 *total = 0;
17816 else
17817 *total = COSTS_N_INSNS (1);
066cd967 17818 return false;
06a67bdd 17819
066cd967
DE
17820 case COMPARE:
17821 case NEG:
17822 case ABS:
17823 if (!FLOAT_MODE_P (mode))
17824 {
17825 *total = COSTS_N_INSNS (1);
17826 return false;
17827 }
17828 /* FALLTHRU */
17829
17830 case FLOAT:
17831 case UNSIGNED_FLOAT:
17832 case FIX:
17833 case UNSIGNED_FIX:
17834 case FLOAT_EXTEND:
06a67bdd
RS
17835 case FLOAT_TRUNCATE:
17836 *total = rs6000_cost->fp;
066cd967 17837 return false;
06a67bdd
RS
17838
17839 case UNSPEC:
17840 switch (XINT (x, 1))
17841 {
17842 case UNSPEC_FRSP:
17843 *total = rs6000_cost->fp;
17844 return true;
17845
17846 default:
17847 break;
17848 }
17849 break;
17850
17851 case CALL:
17852 case IF_THEN_ELSE:
17853 if (optimize_size)
17854 {
17855 *total = COSTS_N_INSNS (1);
17856 return true;
17857 }
066cd967
DE
17858 else if (FLOAT_MODE_P (mode)
17859 && TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS)
17860 {
17861 *total = rs6000_cost->fp;
17862 return false;
17863 }
17864
06a67bdd
RS
17865 break;
17866
3c50106f 17867 default:
06a67bdd 17868 break;
3c50106f 17869 }
06a67bdd
RS
17870
17871 return false;
3c50106f
RH
17872}
17873
34bb030a
DE
17874/* A C expression returning the cost of moving data from a register of class
17875 CLASS1 to one of CLASS2. */
17876
17877int
f676971a 17878rs6000_register_move_cost (enum machine_mode mode,
a2369ed3 17879 enum reg_class from, enum reg_class to)
34bb030a
DE
17880{
17881 /* Moves from/to GENERAL_REGS. */
17882 if (reg_classes_intersect_p (to, GENERAL_REGS)
17883 || reg_classes_intersect_p (from, GENERAL_REGS))
17884 {
17885 if (! reg_classes_intersect_p (to, GENERAL_REGS))
17886 from = to;
17887
17888 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
17889 return (rs6000_memory_move_cost (mode, from, 0)
17890 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
17891
c4ad648e
AM
17892 /* It's more expensive to move CR_REGS than CR0_REGS because of the
17893 shift. */
34bb030a
DE
17894 else if (from == CR_REGS)
17895 return 4;
17896
17897 else
c4ad648e 17898 /* A move will cost one instruction per GPR moved. */
34bb030a
DE
17899 return 2 * HARD_REGNO_NREGS (0, mode);
17900 }
17901
c4ad648e 17902 /* Moving between two similar registers is just one instruction. */
34bb030a
DE
17903 else if (reg_classes_intersect_p (to, from))
17904 return mode == TFmode ? 4 : 2;
17905
c4ad648e 17906 /* Everything else has to go through GENERAL_REGS. */
34bb030a 17907 else
f676971a 17908 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
34bb030a
DE
17909 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
17910}
17911
17912/* A C expressions returning the cost of moving data of MODE from a register to
17913 or from memory. */
17914
17915int
f676971a 17916rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
a2369ed3 17917 int in ATTRIBUTE_UNUSED)
34bb030a
DE
17918{
17919 if (reg_classes_intersect_p (class, GENERAL_REGS))
17920 return 4 * HARD_REGNO_NREGS (0, mode);
17921 else if (reg_classes_intersect_p (class, FLOAT_REGS))
17922 return 4 * HARD_REGNO_NREGS (32, mode);
17923 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
17924 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
17925 else
17926 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
17927}
17928
ded9bf77
AH
17929/* Return an RTX representing where to find the function value of a
17930 function returning MODE. */
17931static rtx
17932rs6000_complex_function_value (enum machine_mode mode)
17933{
17934 unsigned int regno;
17935 rtx r1, r2;
17936 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 17937 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77 17938
4ed78545 17939 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
ded9bf77
AH
17940 regno = FP_ARG_RETURN;
17941 else
17942 {
17943 regno = GP_ARG_RETURN;
17944
17945 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 17946 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
17947 return gen_rtx_REG (mode, regno);
17948 }
17949
fb7e4164
AM
17950 if (inner_bytes >= 8)
17951 return gen_rtx_REG (mode, regno);
17952
ded9bf77
AH
17953 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
17954 const0_rtx);
17955 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 17956 GEN_INT (inner_bytes));
ded9bf77
AH
17957 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
17958}
17959
a6ebc39a
AH
17960/* Define how to find the value returned by a function.
17961 VALTYPE is the data type of the value (as a tree).
17962 If the precise function being called is known, FUNC is its FUNCTION_DECL;
17963 otherwise, FUNC is 0.
17964
17965 On the SPE, both FPs and vectors are returned in r3.
17966
17967 On RS/6000 an integer value is in r3 and a floating-point value is in
17968 fp1, unless -msoft-float. */
17969
17970rtx
17971rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
17972{
17973 enum machine_mode mode;
2a8fa26c 17974 unsigned int regno;
a6ebc39a 17975
0e67400a
FJ
17976 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
17977 {
17978 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
17979 return gen_rtx_PARALLEL (DImode,
17980 gen_rtvec (2,
17981 gen_rtx_EXPR_LIST (VOIDmode,
17982 gen_rtx_REG (SImode, GP_ARG_RETURN),
17983 const0_rtx),
17984 gen_rtx_EXPR_LIST (VOIDmode,
17985 gen_rtx_REG (SImode,
17986 GP_ARG_RETURN + 1),
17987 GEN_INT (4))));
17988 }
17989
a6ebc39a
AH
17990 if ((INTEGRAL_TYPE_P (valtype)
17991 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
17992 || POINTER_TYPE_P (valtype))
b78d48dd 17993 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
17994 else
17995 mode = TYPE_MODE (valtype);
17996
4ed78545 17997 if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS)
2a8fa26c 17998 regno = FP_ARG_RETURN;
ded9bf77 17999 else if (TREE_CODE (valtype) == COMPLEX_TYPE
42ba5130 18000 && targetm.calls.split_complex_arg)
ded9bf77 18001 return rs6000_complex_function_value (mode);
44688022 18002 else if (TREE_CODE (valtype) == VECTOR_TYPE
d0b2079e
FJ
18003 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI
18004 && ALTIVEC_VECTOR_MODE(mode))
a6ebc39a
AH
18005 regno = ALTIVEC_ARG_RETURN;
18006 else
18007 regno = GP_ARG_RETURN;
18008
18009 return gen_rtx_REG (mode, regno);
18010}
18011
ded9bf77
AH
18012/* Define how to find the value returned by a library function
18013 assuming the value has mode MODE. */
18014rtx
18015rs6000_libcall_value (enum machine_mode mode)
18016{
18017 unsigned int regno;
18018
2e6c9641
FJ
18019 if (TARGET_32BIT && TARGET_POWERPC64 && mode == DImode)
18020 {
18021 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
18022 return gen_rtx_PARALLEL (DImode,
18023 gen_rtvec (2,
18024 gen_rtx_EXPR_LIST (VOIDmode,
18025 gen_rtx_REG (SImode, GP_ARG_RETURN),
18026 const0_rtx),
18027 gen_rtx_EXPR_LIST (VOIDmode,
18028 gen_rtx_REG (SImode,
18029 GP_ARG_RETURN + 1),
18030 GEN_INT (4))));
18031 }
18032
ded9bf77
AH
18033 if (GET_MODE_CLASS (mode) == MODE_FLOAT
18034 && TARGET_HARD_FLOAT && TARGET_FPRS)
18035 regno = FP_ARG_RETURN;
44688022
AM
18036 else if (ALTIVEC_VECTOR_MODE (mode)
18037 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
ded9bf77 18038 regno = ALTIVEC_ARG_RETURN;
42ba5130 18039 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
18040 return rs6000_complex_function_value (mode);
18041 else
18042 regno = GP_ARG_RETURN;
18043
18044 return gen_rtx_REG (mode, regno);
18045}
18046
d1d0c603
JJ
18047/* Define the offset between two registers, FROM to be eliminated and its
18048 replacement TO, at the start of a routine. */
18049HOST_WIDE_INT
18050rs6000_initial_elimination_offset (int from, int to)
18051{
18052 rs6000_stack_t *info = rs6000_stack_info ();
18053 HOST_WIDE_INT offset;
18054
18055 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
18056 offset = info->push_p ? 0 : -info->total_size;
18057 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
18058 offset = info->total_size;
18059 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
18060 offset = info->push_p ? info->total_size : 0;
18061 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
18062 offset = 0;
18063 else
18064 abort ();
18065
18066 return offset;
18067}
18068
62e1dfcf
NC
18069/* Return true if TYPE is of type __ev64_opaque__. */
18070
c8e4f0e9 18071static bool
a2369ed3 18072is_ev64_opaque_type (tree type)
62e1dfcf 18073{
c8e4f0e9 18074 return (TARGET_SPE
2abe3e28
AH
18075 && (type == opaque_V2SI_type_node
18076 || type == opaque_V2SF_type_node
36252949 18077 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
18078}
18079
96714395 18080static rtx
a2369ed3 18081rs6000_dwarf_register_span (rtx reg)
96714395
AH
18082{
18083 unsigned regno;
18084
18085 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
18086 return NULL_RTX;
18087
18088 regno = REGNO (reg);
18089
18090 /* The duality of the SPE register size wreaks all kinds of havoc.
18091 This is a way of distinguishing r0 in 32-bits from r0 in
18092 64-bits. */
18093 return
18094 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
18095 BYTES_BIG_ENDIAN
18096 ? gen_rtvec (2,
18097 gen_rtx_REG (SImode, regno + 1200),
18098 gen_rtx_REG (SImode, regno))
18099 : gen_rtvec (2,
18100 gen_rtx_REG (SImode, regno),
18101 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
18102}
18103
93c9d1ba
AM
18104/* Map internal gcc register numbers to DWARF2 register numbers. */
18105
18106unsigned int
18107rs6000_dbx_register_number (unsigned int regno)
18108{
18109 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
18110 return regno;
18111 if (regno == MQ_REGNO)
18112 return 100;
18113 if (regno == LINK_REGISTER_REGNUM)
18114 return 108;
18115 if (regno == COUNT_REGISTER_REGNUM)
18116 return 109;
18117 if (CR_REGNO_P (regno))
18118 return regno - CR0_REGNO + 86;
18119 if (regno == XER_REGNO)
18120 return 101;
18121 if (ALTIVEC_REGNO_P (regno))
18122 return regno - FIRST_ALTIVEC_REGNO + 1124;
18123 if (regno == VRSAVE_REGNO)
18124 return 356;
18125 if (regno == VSCR_REGNO)
18126 return 67;
18127 if (regno == SPE_ACC_REGNO)
18128 return 99;
18129 if (regno == SPEFSCR_REGNO)
18130 return 612;
18131 /* SPE high reg number. We get these values of regno from
18132 rs6000_dwarf_register_span. */
18133 if (regno >= 1200 && regno < 1232)
18134 return regno;
18135
18136 abort ();
18137}
18138
93f90be6 18139/* target hook eh_return_filter_mode */
f676971a 18140static enum machine_mode
93f90be6
FJ
18141rs6000_eh_return_filter_mode (void)
18142{
18143 return TARGET_32BIT ? SImode : word_mode;
18144}
18145
f676971a
EC
18146/* Target hook for vector_mode_supported_p. */
18147static bool
18148rs6000_vector_mode_supported_p (enum machine_mode mode)
18149{
18150
18151 if (TARGET_SPE && SPE_VECTOR_MODE (mode))
18152 return true;
18153
18154 else if (TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
18155 return true;
18156
18157 else
18158 return false;
18159}
18160
17211ab5 18161#include "gt-rs6000.h"