]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
* fold-const.c: Fix a comment typo.
[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
93a27b7b
ZW
59#if TARGET_MACHO
60#include "gstab.h" /* for N_SLINE */
61#endif
9b30bae2 62
7509c759
MM
63#ifndef TARGET_NO_PROTOTYPE
64#define TARGET_NO_PROTOTYPE 0
65#endif
66
452a7d36 67#define EASY_VECTOR_15(n) ((n) >= -16 && (n) <= 15)
c4ad648e 68#define EASY_VECTOR_15_ADD_SELF(n) ((n) >= 0x10 && (n) <= 0x1e && !((n) & 1))
d744e06e 69
9878760c
RK
70#define min(A,B) ((A) < (B) ? (A) : (B))
71#define max(A,B) ((A) > (B) ? (A) : (B))
72
d1d0c603
JJ
73/* Structure used to define the rs6000 stack */
74typedef struct rs6000_stack {
75 int first_gp_reg_save; /* first callee saved GP register used */
76 int first_fp_reg_save; /* first callee saved FP register used */
77 int first_altivec_reg_save; /* first callee saved AltiVec register used */
78 int lr_save_p; /* true if the link reg needs to be saved */
79 int cr_save_p; /* true if the CR reg needs to be saved */
80 unsigned int vrsave_mask; /* mask of vec registers to save */
81 int toc_save_p; /* true if the TOC needs to be saved */
82 int push_p; /* true if we need to allocate stack space */
83 int calls_p; /* true if the function makes any calls */
c4ad648e 84 int world_save_p; /* true if we're saving *everything*:
d62294f5 85 r13-r31, cr, f14-f31, vrsave, v20-v31 */
d1d0c603
JJ
86 enum rs6000_abi abi; /* which ABI to use */
87 int gp_save_offset; /* offset to save GP regs from initial SP */
88 int fp_save_offset; /* offset to save FP regs from initial SP */
89 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
90 int lr_save_offset; /* offset to save LR from initial SP */
91 int cr_save_offset; /* offset to save CR from initial SP */
92 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
93 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
94 int toc_save_offset; /* offset to save the TOC pointer */
95 int varargs_save_offset; /* offset to save the varargs registers */
96 int ehrd_offset; /* offset to EH return data */
97 int reg_size; /* register size (4 or 8) */
98 int varargs_size; /* size to hold V.4 args passed in regs */
99 HOST_WIDE_INT vars_size; /* variable save area size */
100 int parm_size; /* outgoing parameter size */
101 int save_size; /* save area size */
102 int fixed_size; /* fixed size of stack frame */
103 int gp_size; /* size of saved GP registers */
104 int fp_size; /* size of saved FP registers */
105 int altivec_size; /* size of saved AltiVec registers */
106 int cr_size; /* size to hold CR if not in save_size */
107 int lr_size; /* size to hold LR if not in save_size */
108 int vrsave_size; /* size to hold VRSAVE if not in save_size */
109 int altivec_padding_size; /* size of altivec alignment padding if
110 not in save_size */
111 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
112 int spe_padding_size;
113 int toc_size; /* size to hold TOC if not in save_size */
114 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
115 int spe_64bit_regs_used;
116} rs6000_stack_t;
117
5248c961
RK
118/* Target cpu type */
119
120enum processor_type rs6000_cpu;
8e3f41e7
MM
121struct rs6000_cpu_select rs6000_select[3] =
122{
815cdc52
MM
123 /* switch name, tune arch */
124 { (const char *)0, "--with-cpu=", 1, 1 },
125 { (const char *)0, "-mcpu=", 1, 1 },
126 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 127};
5248c961 128
ec507f2d
DE
129/* Always emit branch hint bits. */
130static GTY(()) bool rs6000_always_hint;
131
132/* Schedule instructions for group formation. */
133static GTY(()) bool rs6000_sched_groups;
134
f676971a 135/* Support adjust_priority scheduler hook
79ae11c4
DN
136 and -mprioritize-restricted-insns= option. */
137const char *rs6000_sched_restricted_insns_priority_str;
138int rs6000_sched_restricted_insns_priority;
139
569fa502
DN
140/* Support for -msched-costly-dep option. */
141const char *rs6000_sched_costly_dep_str;
142enum rs6000_dependence_cost rs6000_sched_costly_dep;
143
cbe26ab8
DN
144/* Support for -minsert-sched-nops option. */
145const char *rs6000_sched_insert_nops_str;
146enum rs6000_nop_insertion rs6000_sched_insert_nops;
147
7ccf35ed 148/* Support targetm.vectorize.builtin_mask_for_load. */
13c62176 149static GTY(()) tree altivec_builtin_mask_for_load;
7ccf35ed 150/* Support targetm.vectorize.builtin_mask_for_store. */
13c62176 151static GTY(()) tree altivec_builtin_mask_for_store;
7ccf35ed 152
6fa3f289
ZW
153/* Size of long double */
154const char *rs6000_long_double_size_string;
155int rs6000_long_double_type_size;
156
157/* Whether -mabi=altivec has appeared */
158int rs6000_altivec_abi;
159
08b57fb3
AH
160/* Whether VRSAVE instructions should be generated. */
161int rs6000_altivec_vrsave;
162
163/* String from -mvrsave= option. */
164const char *rs6000_altivec_vrsave_string;
165
a3170dc6
AH
166/* Nonzero if we want SPE ABI extensions. */
167int rs6000_spe_abi;
168
169/* Whether isel instructions should be generated. */
170int rs6000_isel;
171
993f19a8
AH
172/* Whether SPE simd instructions should be generated. */
173int rs6000_spe;
174
5da702b1
AH
175/* Nonzero if floating point operations are done in the GPRs. */
176int rs6000_float_gprs = 0;
177
594a51fe
SS
178/* Nonzero if we want Darwin's struct-by-value-in-regs ABI. */
179int rs6000_darwin64_abi;
180
5da702b1
AH
181/* String from -mfloat-gprs=. */
182const char *rs6000_float_gprs_string;
a3170dc6
AH
183
184/* String from -misel=. */
185const char *rs6000_isel_string;
186
993f19a8
AH
187/* String from -mspe=. */
188const char *rs6000_spe_string;
189
a0ab749a 190/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 191static GTY(()) int common_mode_defined;
c81bebd7 192
9878760c
RK
193/* Save information from a "cmpxx" operation until the branch or scc is
194 emitted. */
9878760c
RK
195rtx rs6000_compare_op0, rs6000_compare_op1;
196int rs6000_compare_fp_p;
874a0744 197
874a0744
MM
198/* Label number of label created for -mrelocatable, to call to so we can
199 get the address of the GOT section */
200int rs6000_pic_labelno;
c81bebd7 201
b91da81f 202#ifdef USING_ELFOS_H
c81bebd7 203/* Which abi to adhere to */
9739c90c 204const char *rs6000_abi_name;
d9407988
MM
205
206/* Semantics of the small data area */
207enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
208
209/* Which small data model to use */
815cdc52 210const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
211
212/* Counter for labels which are to be placed in .fixup. */
213int fixuplabelno = 0;
874a0744 214#endif
4697a36c 215
c4501e62
JJ
216/* Bit size of immediate TLS offsets and string from which it is decoded. */
217int rs6000_tls_size = 32;
218const char *rs6000_tls_size_string;
219
b6c9286a
MM
220/* ABI enumeration available for subtarget to use. */
221enum rs6000_abi rs6000_current_abi;
222
0ac081f6
AH
223/* ABI string from -mabi= option. */
224const char *rs6000_abi_string;
225
85b776df
AM
226/* Whether to use variant of AIX ABI for PowerPC64 Linux. */
227int dot_symbols;
228
38c1f2d7 229/* Debug flags */
815cdc52 230const char *rs6000_debug_name;
38c1f2d7
MM
231int rs6000_debug_stack; /* debug stack applications */
232int rs6000_debug_arg; /* debug argument handling */
233
0d1fbc8c
AH
234/* Value is TRUE if register/mode pair is accepatable. */
235bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
236
6035d635 237/* Opaque types. */
2abe3e28 238static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 239static GTY(()) tree opaque_V2SF_type_node;
6035d635 240static GTY(()) tree opaque_p_V2SI_type_node;
4a5eab38
PB
241static GTY(()) tree V16QI_type_node;
242static GTY(()) tree V2SI_type_node;
243static GTY(()) tree V2SF_type_node;
244static GTY(()) tree V4HI_type_node;
245static GTY(()) tree V4SI_type_node;
246static GTY(()) tree V4SF_type_node;
247static GTY(()) tree V8HI_type_node;
248static GTY(()) tree unsigned_V16QI_type_node;
249static GTY(()) tree unsigned_V8HI_type_node;
250static GTY(()) tree unsigned_V4SI_type_node;
8bb418a3
ZL
251static GTY(()) tree bool_char_type_node; /* __bool char */
252static GTY(()) tree bool_short_type_node; /* __bool short */
253static GTY(()) tree bool_int_type_node; /* __bool int */
254static GTY(()) tree pixel_type_node; /* __pixel */
255static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */
256static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */
257static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */
258static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */
259
260int rs6000_warn_altivec_long = 1; /* On by default. */
261const char *rs6000_warn_altivec_long_switch;
262
57ac7be9
AM
263const char *rs6000_traceback_name;
264static enum {
265 traceback_default = 0,
266 traceback_none,
267 traceback_part,
268 traceback_full
269} rs6000_traceback;
270
38c1f2d7
MM
271/* Flag to say the TOC is initialized */
272int toc_initialized;
9ebbca7d 273char toc_label_name[10];
38c1f2d7 274
9ebbca7d 275/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 276static GTY(()) int rs6000_sr_alias_set;
c8023011 277
a5c76ee6
ZW
278/* Call distance, overridden by -mlongcall and #pragma longcall(1).
279 The only place that looks at this is rs6000_set_default_type_attributes;
280 everywhere else should rely on the presence or absence of a longcall
3eb4e360
AM
281 attribute on the function declaration. Exception: init_cumulative_args
282 looks at it too, for libcalls. */
a5c76ee6
ZW
283int rs6000_default_long_calls;
284const char *rs6000_longcall_switch;
285
a3c9585f
KH
286/* Control alignment for fields within structures. */
287/* String from -malign-XXXXX. */
025d9908
KH
288const char *rs6000_alignment_string;
289int rs6000_alignment_flags;
290
a3170dc6
AH
291struct builtin_description
292{
293 /* mask is not const because we're going to alter it below. This
294 nonsense will go away when we rewrite the -march infrastructure
295 to give us more target flag bits. */
296 unsigned int mask;
297 const enum insn_code icode;
298 const char *const name;
299 const enum rs6000_builtins code;
300};
8b897cfa
RS
301\f
302/* Target cpu costs. */
303
304struct processor_costs {
c4ad648e 305 const int mulsi; /* cost of SImode multiplication. */
8b897cfa
RS
306 const int mulsi_const; /* cost of SImode multiplication by constant. */
307 const int mulsi_const9; /* cost of SImode mult by short constant. */
c4ad648e
AM
308 const int muldi; /* cost of DImode multiplication. */
309 const int divsi; /* cost of SImode division. */
310 const int divdi; /* cost of DImode division. */
311 const int fp; /* cost of simple SFmode and DFmode insns. */
312 const int dmul; /* cost of DFmode multiplication (and fmadd). */
313 const int sdiv; /* cost of SFmode division (fdivs). */
314 const int ddiv; /* cost of DFmode division (fdiv). */
8b897cfa
RS
315};
316
317const struct processor_costs *rs6000_cost;
318
319/* Processor costs (relative to an add) */
320
321/* Instruction size costs on 32bit processors. */
322static const
323struct processor_costs size32_cost = {
06a67bdd
RS
324 COSTS_N_INSNS (1), /* mulsi */
325 COSTS_N_INSNS (1), /* mulsi_const */
326 COSTS_N_INSNS (1), /* mulsi_const9 */
327 COSTS_N_INSNS (1), /* muldi */
328 COSTS_N_INSNS (1), /* divsi */
329 COSTS_N_INSNS (1), /* divdi */
330 COSTS_N_INSNS (1), /* fp */
331 COSTS_N_INSNS (1), /* dmul */
332 COSTS_N_INSNS (1), /* sdiv */
333 COSTS_N_INSNS (1), /* ddiv */
8b897cfa
RS
334};
335
336/* Instruction size costs on 64bit processors. */
337static const
338struct processor_costs size64_cost = {
06a67bdd
RS
339 COSTS_N_INSNS (1), /* mulsi */
340 COSTS_N_INSNS (1), /* mulsi_const */
341 COSTS_N_INSNS (1), /* mulsi_const9 */
342 COSTS_N_INSNS (1), /* muldi */
343 COSTS_N_INSNS (1), /* divsi */
344 COSTS_N_INSNS (1), /* divdi */
345 COSTS_N_INSNS (1), /* fp */
346 COSTS_N_INSNS (1), /* dmul */
347 COSTS_N_INSNS (1), /* sdiv */
348 COSTS_N_INSNS (1), /* ddiv */
8b897cfa
RS
349};
350
351/* Instruction costs on RIOS1 processors. */
352static const
353struct processor_costs rios1_cost = {
06a67bdd
RS
354 COSTS_N_INSNS (5), /* mulsi */
355 COSTS_N_INSNS (4), /* mulsi_const */
356 COSTS_N_INSNS (3), /* mulsi_const9 */
357 COSTS_N_INSNS (5), /* muldi */
358 COSTS_N_INSNS (19), /* divsi */
359 COSTS_N_INSNS (19), /* divdi */
360 COSTS_N_INSNS (2), /* fp */
361 COSTS_N_INSNS (2), /* dmul */
362 COSTS_N_INSNS (19), /* sdiv */
363 COSTS_N_INSNS (19), /* ddiv */
8b897cfa
RS
364};
365
366/* Instruction costs on RIOS2 processors. */
367static const
368struct processor_costs rios2_cost = {
06a67bdd
RS
369 COSTS_N_INSNS (2), /* mulsi */
370 COSTS_N_INSNS (2), /* mulsi_const */
371 COSTS_N_INSNS (2), /* mulsi_const9 */
372 COSTS_N_INSNS (2), /* muldi */
373 COSTS_N_INSNS (13), /* divsi */
374 COSTS_N_INSNS (13), /* divdi */
375 COSTS_N_INSNS (2), /* fp */
376 COSTS_N_INSNS (2), /* dmul */
377 COSTS_N_INSNS (17), /* sdiv */
378 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
379};
380
381/* Instruction costs on RS64A processors. */
382static const
383struct processor_costs rs64a_cost = {
06a67bdd
RS
384 COSTS_N_INSNS (20), /* mulsi */
385 COSTS_N_INSNS (12), /* mulsi_const */
386 COSTS_N_INSNS (8), /* mulsi_const9 */
387 COSTS_N_INSNS (34), /* muldi */
388 COSTS_N_INSNS (65), /* divsi */
389 COSTS_N_INSNS (67), /* divdi */
390 COSTS_N_INSNS (4), /* fp */
391 COSTS_N_INSNS (4), /* dmul */
392 COSTS_N_INSNS (31), /* sdiv */
393 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
394};
395
396/* Instruction costs on MPCCORE processors. */
397static const
398struct processor_costs mpccore_cost = {
06a67bdd
RS
399 COSTS_N_INSNS (2), /* mulsi */
400 COSTS_N_INSNS (2), /* mulsi_const */
401 COSTS_N_INSNS (2), /* mulsi_const9 */
402 COSTS_N_INSNS (2), /* muldi */
403 COSTS_N_INSNS (6), /* divsi */
404 COSTS_N_INSNS (6), /* divdi */
405 COSTS_N_INSNS (4), /* fp */
406 COSTS_N_INSNS (5), /* dmul */
407 COSTS_N_INSNS (10), /* sdiv */
408 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
409};
410
411/* Instruction costs on PPC403 processors. */
412static const
413struct processor_costs ppc403_cost = {
06a67bdd
RS
414 COSTS_N_INSNS (4), /* mulsi */
415 COSTS_N_INSNS (4), /* mulsi_const */
416 COSTS_N_INSNS (4), /* mulsi_const9 */
417 COSTS_N_INSNS (4), /* muldi */
418 COSTS_N_INSNS (33), /* divsi */
419 COSTS_N_INSNS (33), /* divdi */
420 COSTS_N_INSNS (11), /* fp */
421 COSTS_N_INSNS (11), /* dmul */
422 COSTS_N_INSNS (11), /* sdiv */
423 COSTS_N_INSNS (11), /* ddiv */
8b897cfa
RS
424};
425
426/* Instruction costs on PPC405 processors. */
427static const
428struct processor_costs ppc405_cost = {
06a67bdd
RS
429 COSTS_N_INSNS (5), /* mulsi */
430 COSTS_N_INSNS (4), /* mulsi_const */
431 COSTS_N_INSNS (3), /* mulsi_const9 */
432 COSTS_N_INSNS (5), /* muldi */
433 COSTS_N_INSNS (35), /* divsi */
434 COSTS_N_INSNS (35), /* divdi */
435 COSTS_N_INSNS (11), /* fp */
436 COSTS_N_INSNS (11), /* dmul */
437 COSTS_N_INSNS (11), /* sdiv */
438 COSTS_N_INSNS (11), /* ddiv */
8b897cfa
RS
439};
440
441/* Instruction costs on PPC440 processors. */
442static const
443struct processor_costs ppc440_cost = {
06a67bdd
RS
444 COSTS_N_INSNS (3), /* mulsi */
445 COSTS_N_INSNS (2), /* mulsi_const */
446 COSTS_N_INSNS (2), /* mulsi_const9 */
447 COSTS_N_INSNS (3), /* muldi */
448 COSTS_N_INSNS (34), /* divsi */
449 COSTS_N_INSNS (34), /* divdi */
450 COSTS_N_INSNS (5), /* fp */
451 COSTS_N_INSNS (5), /* dmul */
452 COSTS_N_INSNS (19), /* sdiv */
453 COSTS_N_INSNS (33), /* ddiv */
8b897cfa
RS
454};
455
456/* Instruction costs on PPC601 processors. */
457static const
458struct processor_costs ppc601_cost = {
06a67bdd
RS
459 COSTS_N_INSNS (5), /* mulsi */
460 COSTS_N_INSNS (5), /* mulsi_const */
461 COSTS_N_INSNS (5), /* mulsi_const9 */
462 COSTS_N_INSNS (5), /* muldi */
463 COSTS_N_INSNS (36), /* divsi */
464 COSTS_N_INSNS (36), /* divdi */
465 COSTS_N_INSNS (4), /* fp */
466 COSTS_N_INSNS (5), /* dmul */
467 COSTS_N_INSNS (17), /* sdiv */
468 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
469};
470
471/* Instruction costs on PPC603 processors. */
472static const
473struct processor_costs ppc603_cost = {
06a67bdd
RS
474 COSTS_N_INSNS (5), /* mulsi */
475 COSTS_N_INSNS (3), /* mulsi_const */
476 COSTS_N_INSNS (2), /* mulsi_const9 */
477 COSTS_N_INSNS (5), /* muldi */
478 COSTS_N_INSNS (37), /* divsi */
479 COSTS_N_INSNS (37), /* divdi */
480 COSTS_N_INSNS (3), /* fp */
481 COSTS_N_INSNS (4), /* dmul */
482 COSTS_N_INSNS (18), /* sdiv */
483 COSTS_N_INSNS (33), /* ddiv */
8b897cfa
RS
484};
485
486/* Instruction costs on PPC604 processors. */
487static const
488struct processor_costs ppc604_cost = {
06a67bdd
RS
489 COSTS_N_INSNS (4), /* mulsi */
490 COSTS_N_INSNS (4), /* mulsi_const */
491 COSTS_N_INSNS (4), /* mulsi_const9 */
492 COSTS_N_INSNS (4), /* muldi */
493 COSTS_N_INSNS (20), /* divsi */
494 COSTS_N_INSNS (20), /* divdi */
495 COSTS_N_INSNS (3), /* fp */
496 COSTS_N_INSNS (3), /* dmul */
497 COSTS_N_INSNS (18), /* sdiv */
498 COSTS_N_INSNS (32), /* ddiv */
8b897cfa
RS
499};
500
501/* Instruction costs on PPC604e processors. */
502static const
503struct processor_costs ppc604e_cost = {
06a67bdd
RS
504 COSTS_N_INSNS (2), /* mulsi */
505 COSTS_N_INSNS (2), /* mulsi_const */
506 COSTS_N_INSNS (2), /* mulsi_const9 */
507 COSTS_N_INSNS (2), /* muldi */
508 COSTS_N_INSNS (20), /* divsi */
509 COSTS_N_INSNS (20), /* divdi */
510 COSTS_N_INSNS (3), /* fp */
511 COSTS_N_INSNS (3), /* dmul */
512 COSTS_N_INSNS (18), /* sdiv */
513 COSTS_N_INSNS (32), /* ddiv */
8b897cfa
RS
514};
515
f0517163 516/* Instruction costs on PPC620 processors. */
8b897cfa
RS
517static const
518struct processor_costs ppc620_cost = {
06a67bdd
RS
519 COSTS_N_INSNS (5), /* mulsi */
520 COSTS_N_INSNS (4), /* mulsi_const */
521 COSTS_N_INSNS (3), /* mulsi_const9 */
522 COSTS_N_INSNS (7), /* muldi */
523 COSTS_N_INSNS (21), /* divsi */
524 COSTS_N_INSNS (37), /* divdi */
525 COSTS_N_INSNS (3), /* fp */
526 COSTS_N_INSNS (3), /* dmul */
527 COSTS_N_INSNS (18), /* sdiv */
528 COSTS_N_INSNS (32), /* ddiv */
f0517163
RS
529};
530
531/* Instruction costs on PPC630 processors. */
532static const
533struct processor_costs ppc630_cost = {
06a67bdd
RS
534 COSTS_N_INSNS (5), /* mulsi */
535 COSTS_N_INSNS (4), /* mulsi_const */
536 COSTS_N_INSNS (3), /* mulsi_const9 */
537 COSTS_N_INSNS (7), /* muldi */
538 COSTS_N_INSNS (21), /* divsi */
539 COSTS_N_INSNS (37), /* divdi */
540 COSTS_N_INSNS (3), /* fp */
541 COSTS_N_INSNS (3), /* dmul */
542 COSTS_N_INSNS (17), /* sdiv */
543 COSTS_N_INSNS (21), /* ddiv */
8b897cfa
RS
544};
545
546/* Instruction costs on PPC750 and PPC7400 processors. */
547static const
548struct processor_costs ppc750_cost = {
06a67bdd
RS
549 COSTS_N_INSNS (5), /* mulsi */
550 COSTS_N_INSNS (3), /* mulsi_const */
551 COSTS_N_INSNS (2), /* mulsi_const9 */
552 COSTS_N_INSNS (5), /* muldi */
553 COSTS_N_INSNS (17), /* divsi */
554 COSTS_N_INSNS (17), /* divdi */
555 COSTS_N_INSNS (3), /* fp */
556 COSTS_N_INSNS (3), /* dmul */
557 COSTS_N_INSNS (17), /* sdiv */
558 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
559};
560
561/* Instruction costs on PPC7450 processors. */
562static const
563struct processor_costs ppc7450_cost = {
06a67bdd
RS
564 COSTS_N_INSNS (4), /* mulsi */
565 COSTS_N_INSNS (3), /* mulsi_const */
566 COSTS_N_INSNS (3), /* mulsi_const9 */
567 COSTS_N_INSNS (4), /* muldi */
568 COSTS_N_INSNS (23), /* divsi */
569 COSTS_N_INSNS (23), /* divdi */
570 COSTS_N_INSNS (5), /* fp */
571 COSTS_N_INSNS (5), /* dmul */
572 COSTS_N_INSNS (21), /* sdiv */
573 COSTS_N_INSNS (35), /* ddiv */
8b897cfa 574};
a3170dc6 575
8b897cfa
RS
576/* Instruction costs on PPC8540 processors. */
577static const
578struct processor_costs ppc8540_cost = {
06a67bdd
RS
579 COSTS_N_INSNS (4), /* mulsi */
580 COSTS_N_INSNS (4), /* mulsi_const */
581 COSTS_N_INSNS (4), /* mulsi_const9 */
582 COSTS_N_INSNS (4), /* muldi */
583 COSTS_N_INSNS (19), /* divsi */
584 COSTS_N_INSNS (19), /* divdi */
585 COSTS_N_INSNS (4), /* fp */
586 COSTS_N_INSNS (4), /* dmul */
587 COSTS_N_INSNS (29), /* sdiv */
588 COSTS_N_INSNS (29), /* ddiv */
8b897cfa
RS
589};
590
591/* Instruction costs on POWER4 and POWER5 processors. */
592static const
593struct processor_costs power4_cost = {
06a67bdd
RS
594 COSTS_N_INSNS (3), /* mulsi */
595 COSTS_N_INSNS (2), /* mulsi_const */
596 COSTS_N_INSNS (2), /* mulsi_const9 */
597 COSTS_N_INSNS (4), /* muldi */
598 COSTS_N_INSNS (18), /* divsi */
599 COSTS_N_INSNS (34), /* divdi */
600 COSTS_N_INSNS (3), /* fp */
601 COSTS_N_INSNS (3), /* dmul */
602 COSTS_N_INSNS (17), /* sdiv */
603 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
604};
605
606\f
a2369ed3
DJ
607static bool rs6000_function_ok_for_sibcall (tree, tree);
608static int num_insns_constant_wide (HOST_WIDE_INT);
609static void validate_condition_mode (enum rtx_code, enum machine_mode);
610static rtx rs6000_generate_compare (enum rtx_code);
611static void rs6000_maybe_dead (rtx);
612static void rs6000_emit_stack_tie (void);
613static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
614static rtx spe_synthesize_frame_save (rtx);
615static bool spe_func_has_64bit_regs_p (void);
b20a9cca 616static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 617 int, HOST_WIDE_INT);
a2369ed3
DJ
618static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
619static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
620static unsigned rs6000_hash_constant (rtx);
621static unsigned toc_hash_function (const void *);
622static int toc_hash_eq (const void *, const void *);
623static int constant_pool_expr_1 (rtx, int *, int *);
624static bool constant_pool_expr_p (rtx);
625static bool toc_relative_expr_p (rtx);
626static bool legitimate_small_data_p (enum machine_mode, rtx);
a2369ed3
DJ
627static bool legitimate_indexed_address_p (rtx, int);
628static bool legitimate_indirect_address_p (rtx, int);
4c81e946 629static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
630static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
631static struct machine_function * rs6000_init_machine_status (void);
632static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 633#ifdef HAVE_GAS_HIDDEN
a2369ed3 634static void rs6000_assemble_visibility (tree, int);
5add3202 635#endif
a2369ed3
DJ
636static int rs6000_ra_ever_killed (void);
637static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
8bb418a3 638static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
76d2b81d 639static void rs6000_eliminate_indexed_memrefs (rtx operands[2]);
f18eca82 640static const char *rs6000_mangle_fundamental_type (tree);
b86fe7b4 641extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
642static void rs6000_set_default_type_attributes (tree);
643static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
644static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
645static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
646 tree);
a2369ed3 647static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 648static bool rs6000_return_in_memory (tree, tree);
a2369ed3 649static void rs6000_file_start (void);
7c262518 650#if TARGET_ELF
a2369ed3
DJ
651static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
652static void rs6000_elf_asm_out_constructor (rtx, int);
653static void rs6000_elf_asm_out_destructor (rtx, int);
654static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
655static void rs6000_elf_unique_section (tree, int);
656static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 657 unsigned HOST_WIDE_INT);
a56d7372 658static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 659 ATTRIBUTE_UNUSED;
a2369ed3 660static bool rs6000_elf_in_small_data_p (tree);
7c262518 661#endif
cbaaba19 662#if TARGET_XCOFF
a2369ed3 663static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
8210e4c4 664static void rs6000_xcoff_asm_named_section (const char *, unsigned int, tree);
a2369ed3
DJ
665static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
666static void rs6000_xcoff_unique_section (tree, int);
667static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 668 unsigned HOST_WIDE_INT);
a2369ed3
DJ
669static const char * rs6000_xcoff_strip_name_encoding (const char *);
670static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
671static void rs6000_xcoff_file_start (void);
672static void rs6000_xcoff_file_end (void);
f1384257
AM
673#endif
674#if TARGET_MACHO
a2369ed3 675static bool rs6000_binds_local_p (tree);
f1384257 676#endif
a2369ed3
DJ
677static int rs6000_variable_issue (FILE *, int, rtx, int);
678static bool rs6000_rtx_costs (rtx, int, int, int *);
679static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 680static bool is_microcoded_insn (rtx);
79ae11c4 681static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
682static bool is_cracked_insn (rtx);
683static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
684static int rs6000_adjust_priority (rtx, int);
685static int rs6000_issue_rate (void);
569fa502 686static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
687static rtx get_next_active_insn (rtx, rtx);
688static bool insn_terminates_group_p (rtx , enum group_termination);
689static bool is_costly_group (rtx *, rtx);
690static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
691static int redefine_groups (FILE *, int, rtx, rtx);
692static int pad_groups (FILE *, int, rtx, rtx);
693static void rs6000_sched_finish (FILE *, int);
a2369ed3 694static int rs6000_use_sched_lookahead (void);
7ccf35ed
DN
695static tree rs6000_builtin_mask_for_load (void);
696static tree rs6000_builtin_mask_for_store (void);
a2369ed3
DJ
697
698static void rs6000_init_builtins (void);
699static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
700static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
701static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
702static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
703static void altivec_init_builtins (void);
704static void rs6000_common_init_builtins (void);
c15c90bb 705static void rs6000_init_libfuncs (void);
a2369ed3 706
b20a9cca
AM
707static void enable_mask_for_builtins (struct builtin_description *, int,
708 enum rs6000_builtins,
709 enum rs6000_builtins);
7c62e993 710static tree build_opaque_vector_type (tree, int);
a2369ed3
DJ
711static void spe_init_builtins (void);
712static rtx spe_expand_builtin (tree, rtx, bool *);
61bea3b0 713static rtx spe_expand_stv_builtin (enum insn_code, tree);
a2369ed3
DJ
714static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
715static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
716static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
717static rs6000_stack_t *rs6000_stack_info (void);
718static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
719
720static rtx altivec_expand_builtin (tree, rtx, bool *);
721static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
722static rtx altivec_expand_st_builtin (tree, rtx, bool *);
723static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
724static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
f676971a 725static rtx altivec_expand_predicate_builtin (enum insn_code,
c4ad648e 726 const char *, tree, rtx);
b4a62fa0 727static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
728static rtx altivec_expand_stv_builtin (enum insn_code, tree);
729static void rs6000_parse_abi_options (void);
730static void rs6000_parse_alignment_option (void);
731static void rs6000_parse_tls_size_option (void);
5da702b1 732static void rs6000_parse_yes_no_option (const char *, const char *, int *);
4d4cbc0e 733static void rs6000_parse_float_gprs_option (void);
a2369ed3
DJ
734static int first_altivec_reg_to_save (void);
735static unsigned int compute_vrsave_mask (void);
d62294f5 736static void compute_save_world_info(rs6000_stack_t *info_ptr);
a2369ed3
DJ
737static void is_altivec_return_reg (rtx, void *);
738static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
739int easy_vector_constant (rtx, enum machine_mode);
740static int easy_vector_same (rtx, enum machine_mode);
452a7d36 741static int easy_vector_splat_const (int, enum machine_mode);
a2369ed3
DJ
742static bool is_ev64_opaque_type (tree);
743static rtx rs6000_dwarf_register_span (rtx);
744static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
745static rtx rs6000_tls_get_addr (void);
746static rtx rs6000_got_sym (void);
747static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
748static const char *rs6000_get_some_local_dynamic_name (void);
749static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 750static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 751static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 752 enum machine_mode, tree);
594a51fe
SS
753static rtx rs6000_darwin64_function_arg (CUMULATIVE_ARGS *,
754 enum machine_mode, tree, int);
ec6376ab 755static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int);
b1917422 756static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
c6e8c921
GK
757static void setup_incoming_varargs (CUMULATIVE_ARGS *,
758 enum machine_mode, tree,
759 int *, int);
8cd5a4e0
RH
760static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
761 tree, bool);
efdba735
SH
762#if TARGET_MACHO
763static void macho_branch_islands (void);
764static void add_compiler_branch_island (tree, tree, int);
765static int no_previous_def (tree function_name);
766static tree get_prev_label (tree function_name);
c4e18b1c 767static void rs6000_darwin_file_start (void);
efdba735
SH
768#endif
769
c35d187f 770static tree rs6000_build_builtin_va_list (void);
23a60a04 771static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *);
fe984136 772static bool rs6000_must_pass_in_stack (enum machine_mode, tree);
f676971a 773static bool rs6000_vector_mode_supported_p (enum machine_mode);
94ff898d 774static int get_vec_cmp_insn (enum rtx_code, enum machine_mode,
21213b4c 775 enum machine_mode);
94ff898d 776static rtx rs6000_emit_vector_compare (enum rtx_code, rtx, rtx,
21213b4c
DP
777 enum machine_mode);
778static int get_vsel_insn (enum machine_mode);
779static void rs6000_emit_vector_select (rtx, rtx, rtx, rtx);
17211ab5 780
21213b4c
DP
781
782const int INSN_NOT_AVAILABLE = -1;
93f90be6
FJ
783static enum machine_mode rs6000_eh_return_filter_mode (void);
784
17211ab5
GK
785/* Hash table stuff for keeping track of TOC entries. */
786
787struct toc_hash_struct GTY(())
788{
789 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
790 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
791 rtx key;
792 enum machine_mode key_mode;
793 int labelno;
794};
795
796static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
797\f
798/* Default register names. */
799char rs6000_reg_names[][8] =
800{
802a0058
MM
801 "0", "1", "2", "3", "4", "5", "6", "7",
802 "8", "9", "10", "11", "12", "13", "14", "15",
803 "16", "17", "18", "19", "20", "21", "22", "23",
804 "24", "25", "26", "27", "28", "29", "30", "31",
805 "0", "1", "2", "3", "4", "5", "6", "7",
806 "8", "9", "10", "11", "12", "13", "14", "15",
807 "16", "17", "18", "19", "20", "21", "22", "23",
808 "24", "25", "26", "27", "28", "29", "30", "31",
809 "mq", "lr", "ctr","ap",
810 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
811 "xer",
812 /* AltiVec registers. */
0cd5e3a1
AH
813 "0", "1", "2", "3", "4", "5", "6", "7",
814 "8", "9", "10", "11", "12", "13", "14", "15",
815 "16", "17", "18", "19", "20", "21", "22", "23",
816 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
817 "vrsave", "vscr",
818 /* SPE registers. */
819 "spe_acc", "spefscr"
c81bebd7
MM
820};
821
822#ifdef TARGET_REGNAMES
8b60264b 823static const char alt_reg_names[][8] =
c81bebd7 824{
802a0058
MM
825 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
826 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
827 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
828 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
829 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
830 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
831 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
832 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
833 "mq", "lr", "ctr", "ap",
834 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 835 "xer",
59a4c851 836 /* AltiVec registers. */
0ac081f6 837 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
838 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
839 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
840 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
841 "vrsave", "vscr",
842 /* SPE registers. */
843 "spe_acc", "spefscr"
c81bebd7
MM
844};
845#endif
9878760c 846\f
daf11973
MM
847#ifndef MASK_STRICT_ALIGN
848#define MASK_STRICT_ALIGN 0
849#endif
ffcfcb5f
AM
850#ifndef TARGET_PROFILE_KERNEL
851#define TARGET_PROFILE_KERNEL 0
852#endif
3961e8fe
RH
853
854/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
855#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
856
857/* Return 1 for a symbol ref for a thread-local storage symbol. */
858#define RS6000_SYMBOL_REF_TLS_P(RTX) \
859 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
860\f
861/* Initialize the GCC target structure. */
91d231cb
JM
862#undef TARGET_ATTRIBUTE_TABLE
863#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
864#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
865#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 866
301d03af
RS
867#undef TARGET_ASM_ALIGNED_DI_OP
868#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
869
870/* Default unaligned ops are only provided for ELF. Find the ops needed
871 for non-ELF systems. */
872#ifndef OBJECT_FORMAT_ELF
cbaaba19 873#if TARGET_XCOFF
ae6c1efd 874/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
875 64-bit targets. */
876#undef TARGET_ASM_UNALIGNED_HI_OP
877#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
878#undef TARGET_ASM_UNALIGNED_SI_OP
879#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
880#undef TARGET_ASM_UNALIGNED_DI_OP
881#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
882#else
883/* For Darwin. */
884#undef TARGET_ASM_UNALIGNED_HI_OP
885#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
886#undef TARGET_ASM_UNALIGNED_SI_OP
887#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
49bd1d27
SS
888#undef TARGET_ASM_UNALIGNED_DI_OP
889#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
890#undef TARGET_ASM_ALIGNED_DI_OP
891#define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
301d03af
RS
892#endif
893#endif
894
895/* This hook deals with fixups for relocatable code and DI-mode objects
896 in 64-bit code. */
897#undef TARGET_ASM_INTEGER
898#define TARGET_ASM_INTEGER rs6000_assemble_integer
899
93638d7a
AM
900#ifdef HAVE_GAS_HIDDEN
901#undef TARGET_ASM_ASSEMBLE_VISIBILITY
902#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
903#endif
904
c4501e62
JJ
905#undef TARGET_HAVE_TLS
906#define TARGET_HAVE_TLS HAVE_AS_TLS
907
908#undef TARGET_CANNOT_FORCE_CONST_MEM
909#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
910
08c148a8
NB
911#undef TARGET_ASM_FUNCTION_PROLOGUE
912#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
913#undef TARGET_ASM_FUNCTION_EPILOGUE
914#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
915
b54cf83a
DE
916#undef TARGET_SCHED_VARIABLE_ISSUE
917#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
918
c237e94a
ZW
919#undef TARGET_SCHED_ISSUE_RATE
920#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
921#undef TARGET_SCHED_ADJUST_COST
922#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
923#undef TARGET_SCHED_ADJUST_PRIORITY
924#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
f676971a 925#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
569fa502 926#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
927#undef TARGET_SCHED_FINISH
928#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 929
be12c2b0
VM
930#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
931#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
932
7ccf35ed
DN
933#undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD
934#define TARGET_VECTORIZE_BUILTIN_MASK_FOR_LOAD rs6000_builtin_mask_for_load
935
936#undef TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE
937#define TARGET_VECTORIZE_BUILTIN_MASK_FOR_STORE rs6000_builtin_mask_for_store
938
0ac081f6
AH
939#undef TARGET_INIT_BUILTINS
940#define TARGET_INIT_BUILTINS rs6000_init_builtins
941
942#undef TARGET_EXPAND_BUILTIN
943#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
944
f18eca82
ZL
945#undef TARGET_MANGLE_FUNDAMENTAL_TYPE
946#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
947
c15c90bb
ZW
948#undef TARGET_INIT_LIBFUNCS
949#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
950
f1384257 951#if TARGET_MACHO
0e5dbd9b
DE
952#undef TARGET_BINDS_LOCAL_P
953#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 954#endif
0e5dbd9b 955
3961e8fe
RH
956#undef TARGET_ASM_OUTPUT_MI_THUNK
957#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
958
3961e8fe 959#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 960#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 961
4977bab6
ZW
962#undef TARGET_FUNCTION_OK_FOR_SIBCALL
963#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
964
3c50106f
RH
965#undef TARGET_RTX_COSTS
966#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
967#undef TARGET_ADDRESS_COST
968#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 969
c8e4f0e9
AH
970#undef TARGET_VECTOR_OPAQUE_P
971#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 972
96714395
AH
973#undef TARGET_DWARF_REGISTER_SPAN
974#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
975
c6e8c921
GK
976/* On rs6000, function arguments are promoted, as are function return
977 values. */
978#undef TARGET_PROMOTE_FUNCTION_ARGS
979#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
980#undef TARGET_PROMOTE_FUNCTION_RETURN
981#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
982
c6e8c921
GK
983#undef TARGET_RETURN_IN_MEMORY
984#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
985
986#undef TARGET_SETUP_INCOMING_VARARGS
987#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
988
989/* Always strict argument naming on rs6000. */
990#undef TARGET_STRICT_ARGUMENT_NAMING
991#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
992#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
993#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
994#undef TARGET_SPLIT_COMPLEX_ARG
995#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
fe984136
RH
996#undef TARGET_MUST_PASS_IN_STACK
997#define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
8cd5a4e0
RH
998#undef TARGET_PASS_BY_REFERENCE
999#define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
c6e8c921 1000
c35d187f
RH
1001#undef TARGET_BUILD_BUILTIN_VA_LIST
1002#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
1003
cd3ce9b4
JM
1004#undef TARGET_GIMPLIFY_VA_ARG_EXPR
1005#define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
1006
93f90be6
FJ
1007#undef TARGET_EH_RETURN_FILTER_MODE
1008#define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
1009
f676971a
EC
1010#undef TARGET_VECTOR_MODE_SUPPORTED_P
1011#define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
1012
f6897b10 1013struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 1014\f
0d1fbc8c
AH
1015
1016/* Value is 1 if hard register REGNO can hold a value of machine-mode
1017 MODE. */
1018static int
1019rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
1020{
1021 /* The GPRs can hold any mode, but values bigger than one register
1022 cannot go past R31. */
1023 if (INT_REGNO_P (regno))
1024 return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1);
1025
1026 /* The float registers can only hold floating modes and DImode. */
1027 if (FP_REGNO_P (regno))
1028 return
1029 (GET_MODE_CLASS (mode) == MODE_FLOAT
1030 && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1))
1031 || (GET_MODE_CLASS (mode) == MODE_INT
1032 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD);
1033
1034 /* The CR register can only hold CC modes. */
1035 if (CR_REGNO_P (regno))
1036 return GET_MODE_CLASS (mode) == MODE_CC;
1037
1038 if (XER_REGNO_P (regno))
1039 return mode == PSImode;
1040
1041 /* AltiVec only in AldyVec registers. */
1042 if (ALTIVEC_REGNO_P (regno))
1043 return ALTIVEC_VECTOR_MODE (mode);
1044
1045 /* ...but GPRs can hold SIMD data on the SPE in one register. */
1046 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1047 return 1;
1048
1049 /* We cannot put TImode anywhere except general register and it must be
1050 able to fit within the register set. */
1051
1052 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1053}
1054
1055/* Initialize rs6000_hard_regno_mode_ok_p table. */
1056static void
1057rs6000_init_hard_regno_mode_ok (void)
1058{
1059 int r, m;
1060
1061 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
1062 for (m = 0; m < NUM_MACHINE_MODES; ++m)
1063 if (rs6000_hard_regno_mode_ok (r, m))
1064 rs6000_hard_regno_mode_ok_p[m][r] = true;
1065}
1066
c1e55850
GK
1067/* If not otherwise specified by a target, make 'long double' equivalent to
1068 'double'. */
1069
1070#ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
1071#define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
1072#endif
1073
5248c961
RK
1074/* Override command line options. Mostly we process the processor
1075 type and sometimes adjust other TARGET_ options. */
1076
1077void
d779d0dc 1078rs6000_override_options (const char *default_cpu)
5248c961 1079{
c4d38ccb 1080 size_t i, j;
8e3f41e7 1081 struct rs6000_cpu_select *ptr;
66188a7e 1082 int set_masks;
5248c961 1083
66188a7e 1084 /* Simplifications for entries below. */
85638c0d 1085
66188a7e
GK
1086 enum {
1087 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
1088 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
1089 };
85638c0d 1090
66188a7e
GK
1091 /* This table occasionally claims that a processor does not support
1092 a particular feature even though it does, but the feature is slower
1093 than the alternative. Thus, it shouldn't be relied on as a
f676971a 1094 complete description of the processor's support.
66188a7e
GK
1095
1096 Please keep this list in order, and don't forget to update the
1097 documentation in invoke.texi when adding a new processor or
1098 flag. */
5248c961
RK
1099 static struct ptt
1100 {
8b60264b
KG
1101 const char *const name; /* Canonical processor name. */
1102 const enum processor_type processor; /* Processor type enum value. */
1103 const int target_enable; /* Target flags to enable. */
8b60264b 1104 } const processor_target_table[]
66188a7e 1105 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 1106 {"403", PROCESSOR_PPC403,
66188a7e
GK
1107 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
1108 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1109 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
1110 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1111 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
1112 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 1113 {"601", PROCESSOR_PPC601,
66188a7e
GK
1114 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
1115 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1116 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1117 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1118 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1119 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
1120 {"620", PROCESSOR_PPC620,
1121 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1122 {"630", PROCESSOR_PPC630,
1123 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
1124 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1125 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
1126 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1127 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1128 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1129 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1130 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1131 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
4d4cbc0e
AH
1132 /* 8548 has a dummy entry for now. */
1133 {"8548", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
66188a7e 1134 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 1135 {"970", PROCESSOR_POWER4,
66188a7e
GK
1136 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1137 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
1138 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1139 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1140 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 1141 {"G5", PROCESSOR_POWER4,
66188a7e
GK
1142 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1143 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1144 {"power2", PROCESSOR_POWER,
1145 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
1146 {"power3", PROCESSOR_PPC630,
1147 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1148 {"power4", PROCESSOR_POWER4,
fc091c8e 1149 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
ec507f2d 1150 {"power5", PROCESSOR_POWER5,
fc091c8e 1151 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
66188a7e
GK
1152 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
1153 {"powerpc64", PROCESSOR_POWERPC64,
1154 POWERPC_BASE_MASK | MASK_POWERPC64},
1155 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1156 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1157 {"rios2", PROCESSOR_RIOS2,
1158 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1159 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1160 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 1161 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 1162 };
5248c961 1163
ca7558fc 1164 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 1165
66188a7e
GK
1166 /* Some OSs don't support saving the high part of 64-bit registers on
1167 context switch. Other OSs don't support saving Altivec registers.
1168 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
1169 settings; if the user wants either, the user must explicitly specify
1170 them and we won't interfere with the user's specification. */
1171
1172 enum {
1173 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
f676971a 1174 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
66188a7e
GK
1175 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
1176 | MASK_MFCRF)
1177 };
0d1fbc8c
AH
1178
1179 rs6000_init_hard_regno_mode_ok ();
1180
c4ad648e 1181 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
66188a7e
GK
1182#ifdef OS_MISSING_POWERPC64
1183 if (OS_MISSING_POWERPC64)
1184 set_masks &= ~MASK_POWERPC64;
1185#endif
1186#ifdef OS_MISSING_ALTIVEC
1187 if (OS_MISSING_ALTIVEC)
1188 set_masks &= ~MASK_ALTIVEC;
1189#endif
1190
957211c3
AM
1191 /* Don't override these by the processor default if given explicitly. */
1192 set_masks &= ~(target_flags_explicit
1193 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
1194
a4f6c312 1195 /* Identify the processor type. */
8e3f41e7 1196 rs6000_select[0].string = default_cpu;
3cb999d8 1197 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 1198
b6a1cbae 1199 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 1200 {
8e3f41e7
MM
1201 ptr = &rs6000_select[i];
1202 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 1203 {
8e3f41e7
MM
1204 for (j = 0; j < ptt_size; j++)
1205 if (! strcmp (ptr->string, processor_target_table[j].name))
1206 {
1207 if (ptr->set_tune_p)
1208 rs6000_cpu = processor_target_table[j].processor;
1209
1210 if (ptr->set_arch_p)
1211 {
66188a7e
GK
1212 target_flags &= ~set_masks;
1213 target_flags |= (processor_target_table[j].target_enable
1214 & set_masks);
8e3f41e7
MM
1215 }
1216 break;
1217 }
1218
4406229e 1219 if (j == ptt_size)
8e3f41e7 1220 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
1221 }
1222 }
8a61d227 1223
993f19a8 1224 if (TARGET_E500)
a3170dc6
AH
1225 rs6000_isel = 1;
1226
dff9f1b6
DE
1227 /* If we are optimizing big endian systems for space, use the load/store
1228 multiple and string instructions. */
ef792183 1229 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 1230 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 1231
a4f6c312
SS
1232 /* Don't allow -mmultiple or -mstring on little endian systems
1233 unless the cpu is a 750, because the hardware doesn't support the
1234 instructions used in little endian mode, and causes an alignment
1235 trap. The 750 does not cause an alignment trap (except when the
1236 target is unaligned). */
bef84347 1237
b21fb038 1238 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
1239 {
1240 if (TARGET_MULTIPLE)
1241 {
1242 target_flags &= ~MASK_MULTIPLE;
b21fb038 1243 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
1244 warning ("-mmultiple is not supported on little endian systems");
1245 }
1246
1247 if (TARGET_STRING)
1248 {
1249 target_flags &= ~MASK_STRING;
b21fb038 1250 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 1251 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
1252 }
1253 }
3933e0e1 1254
38c1f2d7
MM
1255 /* Set debug flags */
1256 if (rs6000_debug_name)
1257 {
bfc79d3b 1258 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 1259 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 1260 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 1261 rs6000_debug_stack = 1;
bfc79d3b 1262 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
1263 rs6000_debug_arg = 1;
1264 else
c725bd79 1265 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
1266 }
1267
57ac7be9
AM
1268 if (rs6000_traceback_name)
1269 {
1270 if (! strncmp (rs6000_traceback_name, "full", 4))
1271 rs6000_traceback = traceback_full;
1272 else if (! strncmp (rs6000_traceback_name, "part", 4))
1273 rs6000_traceback = traceback_part;
1274 else if (! strncmp (rs6000_traceback_name, "no", 2))
1275 rs6000_traceback = traceback_none;
1276 else
9e637a26 1277 error ("unknown -mtraceback arg %qs; expecting %<full%>, %<partial%> or %<none%>",
57ac7be9
AM
1278 rs6000_traceback_name);
1279 }
1280
6fa3f289 1281 /* Set size of long double */
c1e55850 1282 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
6fa3f289
ZW
1283 if (rs6000_long_double_size_string)
1284 {
1285 char *tail;
1286 int size = strtol (rs6000_long_double_size_string, &tail, 10);
1287 if (*tail != '\0' || (size != 64 && size != 128))
1288 error ("Unknown switch -mlong-double-%s",
1289 rs6000_long_double_size_string);
1290 else
1291 rs6000_long_double_type_size = size;
1292 }
1293
6d0ef01e
HP
1294 /* Set Altivec ABI as default for powerpc64 linux. */
1295 if (TARGET_ELF && TARGET_64BIT)
1296 {
1297 rs6000_altivec_abi = 1;
1298 rs6000_altivec_vrsave = 1;
1299 }
1300
594a51fe
SS
1301 /* Set the Darwin64 ABI as default for 64-bit Darwin. */
1302 if (DEFAULT_ABI == ABI_DARWIN && TARGET_64BIT)
1303 {
1304 rs6000_darwin64_abi = 1;
1305 }
1306
0ac081f6
AH
1307 /* Handle -mabi= options. */
1308 rs6000_parse_abi_options ();
1309
025d9908
KH
1310 /* Handle -malign-XXXXX option. */
1311 rs6000_parse_alignment_option ();
1312
4d4cbc0e
AH
1313 rs6000_parse_float_gprs_option ();
1314
5da702b1
AH
1315 /* Handle generic -mFOO=YES/NO options. */
1316 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
1317 &rs6000_altivec_vrsave);
1318 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
1319 &rs6000_isel);
1320 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
993f19a8 1321
c4501e62
JJ
1322 /* Handle -mtls-size option. */
1323 rs6000_parse_tls_size_option ();
1324
a7ae18e2
AH
1325#ifdef SUBTARGET_OVERRIDE_OPTIONS
1326 SUBTARGET_OVERRIDE_OPTIONS;
1327#endif
1328#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
1329 SUBSUBTARGET_OVERRIDE_OPTIONS;
1330#endif
4d4cbc0e
AH
1331#ifdef SUB3TARGET_OVERRIDE_OPTIONS
1332 SUB3TARGET_OVERRIDE_OPTIONS;
1333#endif
a7ae18e2 1334
5da702b1
AH
1335 if (TARGET_E500)
1336 {
e4463bf1
AH
1337 if (TARGET_ALTIVEC)
1338 error ("AltiVec and E500 instructions cannot coexist");
1339
5da702b1
AH
1340 /* The e500 does not have string instructions, and we set
1341 MASK_STRING above when optimizing for size. */
1342 if ((target_flags & MASK_STRING) != 0)
1343 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
1344
1345 /* No SPE means 64-bit long doubles, even if an E500. */
1346 if (rs6000_spe_string != 0
c4ad648e 1347 && !strcmp (rs6000_spe_string, "no"))
b6e59a3a 1348 rs6000_long_double_type_size = 64;
5da702b1
AH
1349 }
1350 else if (rs6000_select[1].string != NULL)
1351 {
1352 /* For the powerpc-eabispe configuration, we set all these by
1353 default, so let's unset them if we manually set another
1354 CPU that is not the E500. */
1355 if (rs6000_abi_string == 0)
1356 rs6000_spe_abi = 0;
1357 if (rs6000_spe_string == 0)
1358 rs6000_spe = 0;
1359 if (rs6000_float_gprs_string == 0)
1360 rs6000_float_gprs = 0;
1361 if (rs6000_isel_string == 0)
1362 rs6000_isel = 0;
b6e59a3a 1363 if (rs6000_long_double_size_string == 0)
c1e55850 1364 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
5da702b1 1365 }
b5044283 1366
ec507f2d
DE
1367 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
1368 && rs6000_cpu != PROCESSOR_POWER5);
1369 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
1370 || rs6000_cpu == PROCESSOR_POWER5);
1371
a5c76ee6
ZW
1372 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
1373 using TARGET_OPTIONS to handle a toggle switch, but we're out of
1374 bits in target_flags so TARGET_SWITCHES cannot be used.
1375 Assumption here is that rs6000_longcall_switch points into the
1376 text of the complete option, rather than being a copy, so we can
1377 scan back for the presence or absence of the no- modifier. */
1378 if (rs6000_longcall_switch)
1379 {
1380 const char *base = rs6000_longcall_switch;
1381 while (base[-1] != 'm') base--;
1382
1383 if (*rs6000_longcall_switch != '\0')
9e637a26 1384 error ("invalid option %qs", base);
a5c76ee6
ZW
1385 rs6000_default_long_calls = (base[0] != 'n');
1386 }
1387
8bb418a3
ZL
1388 /* Handle -m(no-)warn-altivec-long similarly. */
1389 if (rs6000_warn_altivec_long_switch)
1390 {
1391 const char *base = rs6000_warn_altivec_long_switch;
1392 while (base[-1] != 'm') base--;
1393
1394 if (*rs6000_warn_altivec_long_switch != '\0')
9e637a26 1395 error ("invalid option %qs", base);
8bb418a3
ZL
1396 rs6000_warn_altivec_long = (base[0] != 'n');
1397 }
1398
cbe26ab8 1399 /* Handle -mprioritize-restricted-insns option. */
ec507f2d
DE
1400 rs6000_sched_restricted_insns_priority
1401 = (rs6000_sched_groups ? 1 : 0);
79ae11c4
DN
1402 if (rs6000_sched_restricted_insns_priority_str)
1403 rs6000_sched_restricted_insns_priority =
1404 atoi (rs6000_sched_restricted_insns_priority_str);
1405
569fa502 1406 /* Handle -msched-costly-dep option. */
ec507f2d
DE
1407 rs6000_sched_costly_dep
1408 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
569fa502
DN
1409 if (rs6000_sched_costly_dep_str)
1410 {
f676971a 1411 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
c4ad648e 1412 rs6000_sched_costly_dep = no_dep_costly;
569fa502 1413 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
c4ad648e 1414 rs6000_sched_costly_dep = all_deps_costly;
569fa502 1415 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
c4ad648e 1416 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
569fa502 1417 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
c4ad648e 1418 rs6000_sched_costly_dep = store_to_load_dep_costly;
f676971a 1419 else
c4ad648e 1420 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
cbe26ab8
DN
1421 }
1422
1423 /* Handle -minsert-sched-nops option. */
ec507f2d
DE
1424 rs6000_sched_insert_nops
1425 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
cbe26ab8
DN
1426 if (rs6000_sched_insert_nops_str)
1427 {
1428 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
c4ad648e 1429 rs6000_sched_insert_nops = sched_finish_none;
cbe26ab8 1430 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
c4ad648e 1431 rs6000_sched_insert_nops = sched_finish_pad_groups;
cbe26ab8 1432 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
c4ad648e 1433 rs6000_sched_insert_nops = sched_finish_regroup_exact;
cbe26ab8 1434 else
c4ad648e 1435 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
1436 }
1437
c81bebd7 1438#ifdef TARGET_REGNAMES
a4f6c312
SS
1439 /* If the user desires alternate register names, copy in the
1440 alternate names now. */
c81bebd7 1441 if (TARGET_REGNAMES)
4e135bdd 1442 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
1443#endif
1444
6fa3f289
ZW
1445 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
1446 If -maix-struct-return or -msvr4-struct-return was explicitly
1447 used, don't override with the ABI default. */
b21fb038 1448 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
1449 {
1450 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
1451 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
1452 else
1453 target_flags |= MASK_AIX_STRUCT_RET;
1454 }
1455
fcce224d
DE
1456 if (TARGET_LONG_DOUBLE_128
1457 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 1458 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 1459
9ebbca7d
GK
1460 /* Allocate an alias set for register saves & restores from stack. */
1461 rs6000_sr_alias_set = new_alias_set ();
1462
f676971a 1463 if (TARGET_TOC)
9ebbca7d 1464 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 1465
301d03af
RS
1466 /* We can only guarantee the availability of DI pseudo-ops when
1467 assembling for 64-bit targets. */
ae6c1efd 1468 if (!TARGET_64BIT)
301d03af
RS
1469 {
1470 targetm.asm_out.aligned_op.di = NULL;
1471 targetm.asm_out.unaligned_op.di = NULL;
1472 }
1473
1494c534
DE
1474 /* Set branch target alignment, if not optimizing for size. */
1475 if (!optimize_size)
1476 {
1477 if (rs6000_sched_groups)
1478 {
1479 if (align_functions <= 0)
1480 align_functions = 16;
1481 if (align_jumps <= 0)
1482 align_jumps = 16;
1483 if (align_loops <= 0)
1484 align_loops = 16;
1485 }
1486 if (align_jumps_max_skip <= 0)
1487 align_jumps_max_skip = 15;
1488 if (align_loops_max_skip <= 0)
1489 align_loops_max_skip = 15;
1490 }
2792d578 1491
71f123ca
FS
1492 /* Arrange to save and restore machine status around nested functions. */
1493 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1494
1495 /* We should always be splitting complex arguments, but we can't break
1496 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
18f63bfa 1497 if (DEFAULT_ABI != ABI_AIX)
42ba5130 1498 targetm.calls.split_complex_arg = NULL;
8b897cfa
RS
1499
1500 /* Initialize rs6000_cost with the appropriate target costs. */
1501 if (optimize_size)
1502 rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
1503 else
1504 switch (rs6000_cpu)
1505 {
1506 case PROCESSOR_RIOS1:
1507 rs6000_cost = &rios1_cost;
1508 break;
1509
1510 case PROCESSOR_RIOS2:
1511 rs6000_cost = &rios2_cost;
1512 break;
1513
1514 case PROCESSOR_RS64A:
1515 rs6000_cost = &rs64a_cost;
1516 break;
1517
1518 case PROCESSOR_MPCCORE:
1519 rs6000_cost = &mpccore_cost;
1520 break;
1521
1522 case PROCESSOR_PPC403:
1523 rs6000_cost = &ppc403_cost;
1524 break;
1525
1526 case PROCESSOR_PPC405:
1527 rs6000_cost = &ppc405_cost;
1528 break;
1529
1530 case PROCESSOR_PPC440:
1531 rs6000_cost = &ppc440_cost;
1532 break;
1533
1534 case PROCESSOR_PPC601:
1535 rs6000_cost = &ppc601_cost;
1536 break;
1537
1538 case PROCESSOR_PPC603:
1539 rs6000_cost = &ppc603_cost;
1540 break;
1541
1542 case PROCESSOR_PPC604:
1543 rs6000_cost = &ppc604_cost;
1544 break;
1545
1546 case PROCESSOR_PPC604e:
1547 rs6000_cost = &ppc604e_cost;
1548 break;
1549
1550 case PROCESSOR_PPC620:
8b897cfa
RS
1551 rs6000_cost = &ppc620_cost;
1552 break;
1553
f0517163
RS
1554 case PROCESSOR_PPC630:
1555 rs6000_cost = &ppc630_cost;
1556 break;
1557
8b897cfa
RS
1558 case PROCESSOR_PPC750:
1559 case PROCESSOR_PPC7400:
1560 rs6000_cost = &ppc750_cost;
1561 break;
1562
1563 case PROCESSOR_PPC7450:
1564 rs6000_cost = &ppc7450_cost;
1565 break;
1566
1567 case PROCESSOR_PPC8540:
1568 rs6000_cost = &ppc8540_cost;
1569 break;
1570
1571 case PROCESSOR_POWER4:
1572 case PROCESSOR_POWER5:
1573 rs6000_cost = &power4_cost;
1574 break;
1575
1576 default:
1577 abort ();
1578 }
5248c961 1579}
5accd822 1580
7ccf35ed
DN
1581/* Implement targetm.vectorize.builtin_mask_for_load. */
1582static tree
1583rs6000_builtin_mask_for_load (void)
1584{
1585 if (TARGET_ALTIVEC)
1586 return altivec_builtin_mask_for_load;
1587 else
1588 return 0;
1589}
1590
1591/* Implement targetm.vectorize.builtin_mask_for_store. */
1592static tree
1593rs6000_builtin_mask_for_store (void)
1594{
1595 if (TARGET_ALTIVEC)
1596 return altivec_builtin_mask_for_store;
1597 else
1598 return 0;
1599}
1600
5da702b1
AH
1601/* Handle generic options of the form -mfoo=yes/no.
1602 NAME is the option name.
1603 VALUE is the option value.
1604 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1605 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1606static void
5da702b1 1607rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1608{
5da702b1 1609 if (value == 0)
993f19a8 1610 return;
5da702b1
AH
1611 else if (!strcmp (value, "yes"))
1612 *flag = 1;
1613 else if (!strcmp (value, "no"))
1614 *flag = 0;
08b57fb3 1615 else
5da702b1 1616 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1617}
1618
0ac081f6 1619/* Handle -mabi= options. */
00b960c7 1620static void
863d938c 1621rs6000_parse_abi_options (void)
0ac081f6
AH
1622{
1623 if (rs6000_abi_string == 0)
1624 return;
1625 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1626 {
1627 rs6000_altivec_abi = 1;
1628 rs6000_spe_abi = 0;
1629 }
76a773f3
AH
1630 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1631 rs6000_altivec_abi = 0;
a3170dc6 1632 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1633 {
1634 rs6000_spe_abi = 1;
5cc73f91 1635 rs6000_altivec_abi = 0;
01f4962d
NS
1636 if (!TARGET_SPE_ABI)
1637 error ("not configured for ABI: '%s'", rs6000_abi_string);
1638 }
f676971a 1639
594a51fe
SS
1640 /* These are here for testing during development only, do not
1641 document in the manual please. */
1642 else if (! strcmp (rs6000_abi_string, "d64"))
1643 {
1644 rs6000_darwin64_abi = 1;
1645 warning ("Using darwin64 ABI");
1646 }
1647 else if (! strcmp (rs6000_abi_string, "d32"))
1648 {
1649 rs6000_darwin64_abi = 0;
1650 warning ("Using old darwin ABI");
1651 }
1652
a3170dc6
AH
1653 else if (! strcmp (rs6000_abi_string, "no-spe"))
1654 rs6000_spe_abi = 0;
0ac081f6 1655 else
c725bd79 1656 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1657}
1658
4d4cbc0e
AH
1659/* Handle -mfloat-gprs= options. */
1660static void
1661rs6000_parse_float_gprs_option (void)
1662{
1663 if (rs6000_float_gprs_string == 0)
1664 return;
1665 else if (! strcmp (rs6000_float_gprs_string, "yes")
1666 || ! strcmp (rs6000_float_gprs_string, "single"))
1667 rs6000_float_gprs = 1;
1668 else if (! strcmp (rs6000_float_gprs_string, "double"))
1669 rs6000_float_gprs = 2;
1670 else if (! strcmp (rs6000_float_gprs_string, "no"))
1671 rs6000_float_gprs = 0;
1672 else
1673 error ("invalid option for -mfloat-gprs");
1674}
1675
025d9908
KH
1676/* Handle -malign-XXXXXX options. */
1677static void
863d938c 1678rs6000_parse_alignment_option (void)
025d9908 1679{
b20a9cca
AM
1680 if (rs6000_alignment_string == 0)
1681 return;
1682 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1683 rs6000_alignment_flags = MASK_ALIGN_POWER;
1684 else if (! strcmp (rs6000_alignment_string, "natural"))
1685 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1686 else
1687 error ("unknown -malign-XXXXX option specified: '%s'",
1688 rs6000_alignment_string);
1689}
1690
c4501e62
JJ
1691/* Validate and record the size specified with the -mtls-size option. */
1692
1693static void
863d938c 1694rs6000_parse_tls_size_option (void)
c4501e62
JJ
1695{
1696 if (rs6000_tls_size_string == 0)
1697 return;
1698 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1699 rs6000_tls_size = 16;
1700 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1701 rs6000_tls_size = 32;
1702 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1703 rs6000_tls_size = 64;
1704 else
9e637a26 1705 error ("bad value %qs for -mtls-size switch", rs6000_tls_size_string);
c4501e62
JJ
1706}
1707
5accd822 1708void
a2369ed3 1709optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1710{
5accd822 1711}
3cfa4909
MM
1712\f
1713/* Do anything needed at the start of the asm file. */
1714
1bc7c5b6 1715static void
863d938c 1716rs6000_file_start (void)
3cfa4909 1717{
c4d38ccb 1718 size_t i;
3cfa4909 1719 char buffer[80];
d330fd93 1720 const char *start = buffer;
3cfa4909 1721 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1722 const char *default_cpu = TARGET_CPU_DEFAULT;
1723 FILE *file = asm_out_file;
1724
1725 default_file_start ();
1726
1727#ifdef TARGET_BI_ARCH
1728 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1729 default_cpu = 0;
1730#endif
3cfa4909
MM
1731
1732 if (flag_verbose_asm)
1733 {
1734 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1735 rs6000_select[0].string = default_cpu;
1736
b6a1cbae 1737 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1738 {
1739 ptr = &rs6000_select[i];
1740 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1741 {
1742 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1743 start = "";
1744 }
1745 }
1746
b91da81f 1747#ifdef USING_ELFOS_H
3cfa4909
MM
1748 switch (rs6000_sdata)
1749 {
1750 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1751 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1752 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1753 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1754 }
1755
1756 if (rs6000_sdata && g_switch_value)
1757 {
307b599c
MK
1758 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1759 g_switch_value);
3cfa4909
MM
1760 start = "";
1761 }
1762#endif
1763
1764 if (*start == '\0')
949ea356 1765 putc ('\n', file);
3cfa4909
MM
1766 }
1767}
c4e18b1c 1768
5248c961 1769\f
a0ab749a 1770/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1771
1772int
863d938c 1773direct_return (void)
9878760c 1774{
4697a36c
MM
1775 if (reload_completed)
1776 {
1777 rs6000_stack_t *info = rs6000_stack_info ();
1778
1779 if (info->first_gp_reg_save == 32
1780 && info->first_fp_reg_save == 64
00b960c7 1781 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1782 && ! info->lr_save_p
1783 && ! info->cr_save_p
00b960c7 1784 && info->vrsave_mask == 0
c81fc13e 1785 && ! info->push_p)
4697a36c
MM
1786 return 1;
1787 }
1788
1789 return 0;
9878760c
RK
1790}
1791
1792/* Returns 1 always. */
1793
1794int
f676971a 1795any_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 1796 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1797{
1798 return 1;
1799}
1800
85d346f1
DE
1801/* Returns 1 always. */
1802
1803int
f676971a 1804any_parallel_operand (rtx op ATTRIBUTE_UNUSED,
85d346f1
DE
1805 enum machine_mode mode ATTRIBUTE_UNUSED)
1806{
1807 return 1;
1808}
1809
a4f6c312 1810/* Returns 1 if op is the count register. */
85d346f1 1811
38c1f2d7 1812int
a2369ed3 1813count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1814{
1815 if (GET_CODE (op) != REG)
1816 return 0;
1817
1818 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1819 return 1;
1820
1821 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1822 return 1;
1823
1824 return 0;
1825}
1826
0ec4e2a8 1827/* Returns 1 if op is an altivec register. */
85d346f1 1828
0ec4e2a8 1829int
a2369ed3 1830altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8 1831{
0ec4e2a8
AH
1832 return (register_operand (op, mode)
1833 && (GET_CODE (op) != REG
1834 || REGNO (op) > FIRST_PSEUDO_REGISTER
1835 || ALTIVEC_REGNO_P (REGNO (op))));
1836}
1837
38c1f2d7 1838int
a2369ed3 1839xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1840{
1841 if (GET_CODE (op) != REG)
1842 return 0;
1843
9ebbca7d 1844 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1845 return 1;
1846
802a0058
MM
1847 return 0;
1848}
1849
c859cda6 1850/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1851 by such constants completes more quickly. */
c859cda6
DJ
1852
1853int
a2369ed3 1854s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6 1855{
c4ad648e 1856 return (GET_CODE (op) == CONST_INT
c859cda6
DJ
1857 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1858}
1859
9878760c
RK
1860/* Return 1 if OP is a constant that can fit in a D field. */
1861
1862int
a2369ed3 1863short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1864{
5f59ecb7
DE
1865 return (GET_CODE (op) == CONST_INT
1866 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1867}
1868
5519a4f9 1869/* Similar for an unsigned D field. */
9878760c
RK
1870
1871int
a2369ed3 1872u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1873{
19684119 1874 return (GET_CODE (op) == CONST_INT
c1f11548 1875 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1876}
1877
dcfedcd0
RK
1878/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1879
1880int
a2369ed3 1881non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1882{
1883 return (GET_CODE (op) == CONST_INT
a7653a2c 1884 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1885}
1886
2bfcf297
DB
1887/* Returns 1 if OP is a CONST_INT that is a positive value
1888 and an exact power of 2. */
1889
1890int
a2369ed3 1891exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1892{
1893 return (GET_CODE (op) == CONST_INT
1894 && INTVAL (op) > 0
1895 && exact_log2 (INTVAL (op)) >= 0);
1896}
1897
9878760c
RK
1898/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1899 ctr, or lr). */
1900
1901int
a2369ed3 1902gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1903{
1904 return (register_operand (op, mode)
802a0058 1905 && (GET_CODE (op) != REG
f676971a 1906 || (REGNO (op) >= ARG_POINTER_REGNUM
9ebbca7d
GK
1907 && !XER_REGNO_P (REGNO (op)))
1908 || REGNO (op) < MQ_REGNO));
9878760c
RK
1909}
1910
1911/* Returns 1 if OP is either a pseudo-register or a register denoting a
1912 CR field. */
1913
1914int
a2369ed3 1915cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1916{
1917 return (register_operand (op, mode)
1918 && (GET_CODE (op) != REG
1919 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1920 || CR_REGNO_P (REGNO (op))));
1921}
1922
815cdc52
MM
1923/* Returns 1 if OP is either a pseudo-register or a register denoting a
1924 CR field that isn't CR0. */
1925
1926int
a2369ed3 1927cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1928{
1929 return (register_operand (op, mode)
1930 && (GET_CODE (op) != REG
1931 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1932 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1933}
1934
a4f6c312
SS
1935/* Returns 1 if OP is either a constant integer valid for a D-field or
1936 a non-special register. If a register, it must be in the proper
1937 mode unless MODE is VOIDmode. */
9878760c
RK
1938
1939int
a2369ed3 1940reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1941{
f5a28898 1942 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1943}
1944
a4f6c312 1945/* Similar, except check if the negation of the constant would be
42f806e5
AM
1946 valid for a D-field. Don't allow a constant zero, since all the
1947 patterns that call this predicate use "addic r1,r2,-constant" on
1948 a constant value to set a carry when r2 is greater or equal to
1949 "constant". That doesn't work for zero. */
9878760c
RK
1950
1951int
a2369ed3 1952reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1953{
1954 if (GET_CODE (op) == CONST_INT)
42f806e5 1955 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P') && INTVAL (op) != 0;
9878760c 1956
cd2b37d9 1957 return gpc_reg_operand (op, mode);
9878760c
RK
1958}
1959
768070a0
TR
1960/* Returns 1 if OP is either a constant integer valid for a DS-field or
1961 a non-special register. If a register, it must be in the proper
1962 mode unless MODE is VOIDmode. */
1963
1964int
a2369ed3 1965reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1966{
1967 if (gpc_reg_operand (op, mode))
1968 return 1;
1969 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1970 return 1;
1971
1972 return 0;
1973}
1974
1975
a4f6c312
SS
1976/* Return 1 if the operand is either a register or an integer whose
1977 high-order 16 bits are zero. */
9878760c
RK
1978
1979int
a2369ed3 1980reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1981{
e675f625 1982 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1983}
1984
1985/* Return 1 is the operand is either a non-special register or ANY
1986 constant integer. */
1987
1988int
a2369ed3 1989reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1990{
a4f6c312 1991 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1992}
1993
1994/* Return 1 is the operand is either a non-special register or ANY
1995 32-bit signed constant integer. */
1996
1997int
a2369ed3 1998reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1999{
a4f6c312
SS
2000 return (gpc_reg_operand (op, mode)
2001 || (GET_CODE (op) == CONST_INT
f6bf7de2 2002#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
2003 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
2004 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 2005#endif
a4f6c312 2006 ));
9878760c
RK
2007}
2008
2bfcf297
DB
2009/* Return 1 is the operand is either a non-special register or a 32-bit
2010 signed constant integer valid for 64-bit addition. */
2011
2012int
a2369ed3 2013reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 2014{
a4f6c312
SS
2015 return (gpc_reg_operand (op, mode)
2016 || (GET_CODE (op) == CONST_INT
a65c591c 2017#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 2018 && INTVAL (op) < 0x7fff8000
a65c591c 2019#else
a4f6c312
SS
2020 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
2021 < 0x100000000ll)
2bfcf297 2022#endif
a4f6c312 2023 ));
2bfcf297
DB
2024}
2025
2026/* Return 1 is the operand is either a non-special register or a 32-bit
2027 signed constant integer valid for 64-bit subtraction. */
2028
2029int
a2369ed3 2030reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 2031{
a4f6c312
SS
2032 return (gpc_reg_operand (op, mode)
2033 || (GET_CODE (op) == CONST_INT
a65c591c 2034#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 2035 && (- INTVAL (op)) < 0x7fff8000
a65c591c 2036#else
a4f6c312
SS
2037 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
2038 < 0x100000000ll)
2bfcf297 2039#endif
a4f6c312 2040 ));
2bfcf297
DB
2041}
2042
9ebbca7d
GK
2043/* Return 1 is the operand is either a non-special register or ANY
2044 32-bit unsigned constant integer. */
2045
2046int
a2369ed3 2047reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 2048{
1d328b19
GK
2049 if (GET_CODE (op) == CONST_INT)
2050 {
2051 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
2052 {
2053 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 2054 abort ();
1d328b19
GK
2055
2056 if (INTVAL (op) < 0)
2057 return 0;
2058 }
2059
2060 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 2061 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
2062 }
2063 else if (GET_CODE (op) == CONST_DOUBLE)
2064 {
2065 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
2066 || mode != DImode)
a4f6c312 2067 abort ();
1d328b19
GK
2068
2069 return CONST_DOUBLE_HIGH (op) == 0;
2070 }
f676971a 2071 else
1d328b19 2072 return gpc_reg_operand (op, mode);
9ebbca7d
GK
2073}
2074
51d3e7d6 2075/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
2076
2077int
a2369ed3 2078got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
2079{
2080 return (GET_CODE (op) == SYMBOL_REF
2081 || GET_CODE (op) == CONST
2082 || GET_CODE (op) == LABEL_REF);
2083}
2084
38c1f2d7
MM
2085/* Return 1 if the operand is a simple references that can be loaded via
2086 the GOT (labels involving addition aren't allowed). */
2087
2088int
a2369ed3 2089got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
2090{
2091 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
2092}
2093
4e74d8ec
MM
2094/* Return the number of instructions it takes to form a constant in an
2095 integer register. */
2096
2097static int
a2369ed3 2098num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
2099{
2100 /* signed constant loadable with {cal|addi} */
5f59ecb7 2101 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
2102 return 1;
2103
4e74d8ec 2104 /* constant loadable with {cau|addis} */
5f59ecb7 2105 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
2106 return 1;
2107
5f59ecb7 2108#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 2109 else if (TARGET_POWERPC64)
4e74d8ec 2110 {
a65c591c
DE
2111 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
2112 HOST_WIDE_INT high = value >> 31;
4e74d8ec 2113
a65c591c 2114 if (high == 0 || high == -1)
4e74d8ec
MM
2115 return 2;
2116
a65c591c 2117 high >>= 1;
4e74d8ec 2118
a65c591c 2119 if (low == 0)
4e74d8ec 2120 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
2121 else
2122 return (num_insns_constant_wide (high)
e396202a 2123 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
2124 }
2125#endif
2126
2127 else
2128 return 2;
2129}
2130
2131int
a2369ed3 2132num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 2133{
4e74d8ec 2134 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
2135 {
2136#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
2137 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
2138 && mask64_operand (op, mode))
c4ad648e 2139 return 2;
0d30d435
DE
2140 else
2141#endif
2142 return num_insns_constant_wide (INTVAL (op));
2143 }
4e74d8ec 2144
6fc48950
MM
2145 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
2146 {
2147 long l;
2148 REAL_VALUE_TYPE rv;
2149
2150 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2151 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 2152 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
2153 }
2154
47ad8c61 2155 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 2156 {
47ad8c61
MM
2157 HOST_WIDE_INT low;
2158 HOST_WIDE_INT high;
2159 long l[2];
2160 REAL_VALUE_TYPE rv;
2161 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 2162
47ad8c61
MM
2163 if (mode == VOIDmode || mode == DImode)
2164 {
2165 high = CONST_DOUBLE_HIGH (op);
2166 low = CONST_DOUBLE_LOW (op);
2167 }
2168 else
2169 {
2170 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2171 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
2172 high = l[endian];
2173 low = l[1 - endian];
2174 }
4e74d8ec 2175
47ad8c61
MM
2176 if (TARGET_32BIT)
2177 return (num_insns_constant_wide (low)
2178 + num_insns_constant_wide (high));
4e74d8ec
MM
2179
2180 else
47ad8c61 2181 {
e72247f4 2182 if (high == 0 && low >= 0)
47ad8c61
MM
2183 return num_insns_constant_wide (low);
2184
e72247f4 2185 else if (high == -1 && low < 0)
47ad8c61
MM
2186 return num_insns_constant_wide (low);
2187
a260abc9
DE
2188 else if (mask64_operand (op, mode))
2189 return 2;
2190
47ad8c61
MM
2191 else if (low == 0)
2192 return num_insns_constant_wide (high) + 1;
2193
2194 else
2195 return (num_insns_constant_wide (high)
2196 + num_insns_constant_wide (low) + 1);
2197 }
4e74d8ec
MM
2198 }
2199
2200 else
2201 abort ();
2202}
2203
a4f6c312
SS
2204/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
2205 register with one instruction per word. We only do this if we can
2206 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
2207
2208int
a2369ed3 2209easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 2210{
9878760c
RK
2211 if (GET_CODE (op) != CONST_DOUBLE
2212 || GET_MODE (op) != mode
4e74d8ec 2213 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
2214 return 0;
2215
a4f6c312 2216 /* Consider all constants with -msoft-float to be easy. */
4d4cbc0e 2217 if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
a3170dc6 2218 && mode != DImode)
b6c9286a
MM
2219 return 1;
2220
a4f6c312 2221 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 2222 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
2223 return 0;
2224
5ae4759c 2225#ifdef TARGET_RELOCATABLE
a4f6c312
SS
2226 /* Similarly if we are using -mrelocatable, consider all constants
2227 to be hard. */
5ae4759c
MM
2228 if (TARGET_RELOCATABLE)
2229 return 0;
2230#endif
2231
fcce224d
DE
2232 if (mode == TFmode)
2233 {
2234 long k[4];
2235 REAL_VALUE_TYPE rv;
2236
2237 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2238 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
2239
2240 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2241 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
2242 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
2243 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
2244 }
2245
2246 else if (mode == DFmode)
042259f2
DE
2247 {
2248 long k[2];
2249 REAL_VALUE_TYPE rv;
2250
4d4cbc0e
AH
2251 if (TARGET_E500_DOUBLE)
2252 return 0;
2253
042259f2
DE
2254 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2255 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 2256
a65c591c
DE
2257 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2258 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 2259 }
4e74d8ec
MM
2260
2261 else if (mode == SFmode)
042259f2
DE
2262 {
2263 long l;
2264 REAL_VALUE_TYPE rv;
2265
2266 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2267 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 2268
4e74d8ec 2269 return num_insns_constant_wide (l) == 1;
042259f2 2270 }
4e74d8ec 2271
a260abc9 2272 else if (mode == DImode)
c81fc13e 2273 return ((TARGET_POWERPC64
a260abc9
DE
2274 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
2275 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 2276
a9098fd0
GK
2277 else if (mode == SImode)
2278 return 1;
4e74d8ec
MM
2279 else
2280 abort ();
9878760c 2281}
8f75773e 2282
effa5d5d 2283/* Returns the constant for the splat instruction, if exists. */
452a7d36
HP
2284
2285static int
2286easy_vector_splat_const (int cst, enum machine_mode mode)
2287{
f676971a 2288 switch (mode)
452a7d36
HP
2289 {
2290 case V4SImode:
f676971a
EC
2291 if (EASY_VECTOR_15 (cst)
2292 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2293 return cst;
2294 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
2295 break;
2296 cst = cst >> 16;
c4ad648e
AM
2297 /* Fall thru */
2298
452a7d36 2299 case V8HImode:
f676971a
EC
2300 if (EASY_VECTOR_15 (cst)
2301 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2302 return cst;
2303 if ((cst & 0xff) != ((cst >> 8) & 0xff))
2304 break;
2305 cst = cst >> 8;
c4ad648e
AM
2306 /* Fall thru */
2307
452a7d36 2308 case V16QImode:
c4ad648e
AM
2309 if (EASY_VECTOR_15 (cst)
2310 || EASY_VECTOR_15_ADD_SELF (cst))
2311 return cst;
f676971a 2312 default:
452a7d36
HP
2313 break;
2314 }
2315 return 0;
2316}
2317
2318
72ac76be 2319/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
2320
2321static int
a2369ed3 2322easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
2323{
2324 int units, i, cst;
2325
2326 units = CONST_VECTOR_NUNITS (op);
2327
2328 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2329 for (i = 1; i < units; ++i)
2330 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
2331 break;
452a7d36 2332 if (i == units && easy_vector_splat_const (cst, mode))
d744e06e
AH
2333 return 1;
2334 return 0;
2335}
2336
2337/* Return 1 if the operand is a CONST_INT and can be put into a
2338 register without using memory. */
2339
2340int
a2369ed3 2341easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 2342{
d744e06e 2343 int cst, cst2;
69ef87e2 2344
d744e06e
AH
2345 if (GET_CODE (op) != CONST_VECTOR
2346 || (!TARGET_ALTIVEC
2347 && !TARGET_SPE))
69ef87e2
AH
2348 return 0;
2349
d744e06e
AH
2350 if (zero_constant (op, mode)
2351 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
2352 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
2353 return 1;
69ef87e2 2354
d744e06e
AH
2355 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
2356 return 0;
2357
f5119d10
AH
2358 if (TARGET_SPE && mode == V1DImode)
2359 return 0;
2360
d744e06e
AH
2361 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2362 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
2363
2364 /* Limit SPE vectors to 15 bits signed. These we can generate with:
2365 li r0, CONSTANT1
2366 evmergelo r0, r0, r0
2367 li r0, CONSTANT2
2368
2369 I don't know how efficient it would be to allow bigger constants,
2370 considering we'll have an extra 'ori' for every 'li'. I doubt 5
2371 instructions is better than a 64-bit memory load, but I don't
2372 have the e500 timing specs. */
2373 if (TARGET_SPE && mode == V2SImode
2374 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 2375 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
2376 return 1;
2377
f676971a 2378 if (TARGET_ALTIVEC
452a7d36
HP
2379 && easy_vector_same (op, mode))
2380 {
2381 cst = easy_vector_splat_const (cst, mode);
f676971a 2382 if (EASY_VECTOR_15_ADD_SELF (cst)
452a7d36
HP
2383 || EASY_VECTOR_15 (cst))
2384 return 1;
f676971a 2385 }
d744e06e
AH
2386 return 0;
2387}
2388
2389/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
2390
2391int
a2369ed3 2392easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
2393{
2394 int cst;
452a7d36
HP
2395 if (TARGET_ALTIVEC
2396 && GET_CODE (op) == CONST_VECTOR
2397 && easy_vector_same (op, mode))
2398 {
2399 cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode);
2400 if (EASY_VECTOR_15_ADD_SELF (cst))
f676971a 2401 return 1;
452a7d36
HP
2402 }
2403 return 0;
2404}
d744e06e 2405
452a7d36 2406/* Generate easy_vector_constant out of a easy_vector_constant_add_self. */
d744e06e 2407
f676971a 2408rtx
452a7d36
HP
2409gen_easy_vector_constant_add_self (rtx op)
2410{
2411 int i, units;
2412 rtvec v;
2413 units = GET_MODE_NUNITS (GET_MODE (op));
2414 v = rtvec_alloc (units);
2415
2416 for (i = 0; i < units; i++)
f676971a 2417 RTVEC_ELT (v, i) =
452a7d36
HP
2418 GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1);
2419 return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v);
d744e06e
AH
2420}
2421
2422const char *
a2369ed3 2423output_vec_const_move (rtx *operands)
d744e06e
AH
2424{
2425 int cst, cst2;
2426 enum machine_mode mode;
2427 rtx dest, vec;
2428
2429 dest = operands[0];
2430 vec = operands[1];
69ef87e2 2431
d744e06e
AH
2432 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
2433 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
2434 mode = GET_MODE (dest);
69ef87e2 2435
d744e06e
AH
2436 if (TARGET_ALTIVEC)
2437 {
2438 if (zero_constant (vec, mode))
2439 return "vxor %0,%0,%0";
ce1f50b2 2440 else if (easy_vector_constant (vec, mode))
98ef3137 2441 {
d744e06e
AH
2442 operands[1] = GEN_INT (cst);
2443 switch (mode)
2444 {
2445 case V4SImode:
452a7d36 2446 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2447 {
2448 operands[1] = GEN_INT (cst);
2449 return "vspltisw %0,%1";
2450 }
452a7d36
HP
2451 else if (EASY_VECTOR_15_ADD_SELF (cst))
2452 return "#";
ce1f50b2 2453 cst = cst >> 16;
c4ad648e
AM
2454 /* Fall thru */
2455
d744e06e 2456 case V8HImode:
452a7d36 2457 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2458 {
2459 operands[1] = GEN_INT (cst);
2460 return "vspltish %0,%1";
2461 }
452a7d36
HP
2462 else if (EASY_VECTOR_15_ADD_SELF (cst))
2463 return "#";
ce1f50b2 2464 cst = cst >> 8;
c4ad648e
AM
2465 /* Fall thru */
2466
d744e06e 2467 case V16QImode:
452a7d36 2468 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2469 {
2470 operands[1] = GEN_INT (cst);
2471 return "vspltisb %0,%1";
2472 }
452a7d36
HP
2473 else if (EASY_VECTOR_15_ADD_SELF (cst))
2474 return "#";
c4ad648e 2475
d744e06e
AH
2476 default:
2477 abort ();
2478 }
98ef3137 2479 }
d744e06e
AH
2480 else
2481 abort ();
69ef87e2
AH
2482 }
2483
d744e06e
AH
2484 if (TARGET_SPE)
2485 {
2486 /* Vector constant 0 is handled as a splitter of V2SI, and in the
2487 pattern of V1DI, V4HI, and V2SF.
2488
c1207243 2489 FIXME: We should probably return # and add post reload
c4ad648e 2490 splitters for these, but this way is so easy ;-). */
d744e06e
AH
2491 operands[1] = GEN_INT (cst);
2492 operands[2] = GEN_INT (cst2);
2493 if (cst == cst2)
2494 return "li %0,%1\n\tevmergelo %0,%0,%0";
2495 else
2496 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
2497 }
2498
2499 abort ();
69ef87e2
AH
2500}
2501
2502/* Return 1 if the operand is the constant 0. This works for scalars
2503 as well as vectors. */
2504int
a2369ed3 2505zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
2506{
2507 return op == CONST0_RTX (mode);
2508}
2509
50a0b056
GK
2510/* Return 1 if the operand is 0.0. */
2511int
a2369ed3 2512zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
2513{
2514 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
2515}
2516
a4f6c312
SS
2517/* Return 1 if the operand is in volatile memory. Note that during
2518 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
2519 volatile memory references. So this function allows us to
2520 recognize volatile references where its safe. */
2521
2522int
a2369ed3 2523volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
2524{
2525 if (GET_CODE (op) != MEM)
2526 return 0;
2527
2528 if (!MEM_VOLATILE_P (op))
2529 return 0;
2530
2531 if (mode != GET_MODE (op))
2532 return 0;
2533
2534 if (reload_completed)
2535 return memory_operand (op, mode);
2536
2537 if (reload_in_progress)
2538 return strict_memory_address_p (mode, XEXP (op, 0));
2539
2540 return memory_address_p (mode, XEXP (op, 0));
2541}
2542
97f6e72f 2543/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
2544
2545int
a2369ed3 2546offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 2547{
97f6e72f 2548 return ((GET_CODE (op) == MEM)
677a9668 2549 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 2550 mode, XEXP (op, 0)));
914c2e77
RK
2551}
2552
9878760c
RK
2553/* Return 1 if the operand is either an easy FP constant (see above) or
2554 memory. */
2555
2556int
a2369ed3 2557mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
2558{
2559 return memory_operand (op, mode) || easy_fp_constant (op, mode);
2560}
2561
2562/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 2563 that can be used as the operand of a `mode' add insn. */
9878760c
RK
2564
2565int
a2369ed3 2566add_operand (rtx op, enum machine_mode mode)
9878760c 2567{
2bfcf297 2568 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
2569 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2570 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
2571
2572 return gpc_reg_operand (op, mode);
9878760c
RK
2573}
2574
dcfedcd0
RK
2575/* Return 1 if OP is a constant but not a valid add_operand. */
2576
2577int
a2369ed3 2578non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
2579{
2580 return (GET_CODE (op) == CONST_INT
e72247f4
DE
2581 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2582 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
2583}
2584
9878760c
RK
2585/* Return 1 if the operand is a non-special register or a constant that
2586 can be used as the operand of an OR or XOR insn on the RS/6000. */
2587
2588int
a2369ed3 2589logical_operand (rtx op, enum machine_mode mode)
9878760c 2590{
40501e5f 2591 HOST_WIDE_INT opl, oph;
1d328b19 2592
dfbdccdb
GK
2593 if (gpc_reg_operand (op, mode))
2594 return 1;
1d328b19 2595
dfbdccdb 2596 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
2597 {
2598 opl = INTVAL (op) & GET_MODE_MASK (mode);
2599
2600#if HOST_BITS_PER_WIDE_INT <= 32
2601 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
2602 return 0;
2603#endif
2604 }
dfbdccdb
GK
2605 else if (GET_CODE (op) == CONST_DOUBLE)
2606 {
1d328b19 2607 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 2608 abort ();
1d328b19
GK
2609
2610 opl = CONST_DOUBLE_LOW (op);
2611 oph = CONST_DOUBLE_HIGH (op);
40501e5f 2612 if (oph != 0)
38886f37 2613 return 0;
dfbdccdb
GK
2614 }
2615 else
2616 return 0;
1d328b19 2617
40501e5f
AM
2618 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
2619 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
2620}
2621
dcfedcd0 2622/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 2623 above), but could be split into one. */
dcfedcd0
RK
2624
2625int
a2369ed3 2626non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 2627{
dfbdccdb 2628 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
2629 && ! logical_operand (op, mode)
2630 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
2631}
2632
19ba8161 2633/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
2634 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
2635 Reject all ones and all zeros, since these should have been optimized
2636 away and confuse the making of MB and ME. */
2637
2638int
a2369ed3 2639mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 2640{
02071907 2641 HOST_WIDE_INT c, lsb;
9878760c 2642
19ba8161
DE
2643 if (GET_CODE (op) != CONST_INT)
2644 return 0;
2645
2646 c = INTVAL (op);
2647
57deb3a1
AM
2648 /* Fail in 64-bit mode if the mask wraps around because the upper
2649 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
2650 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
2651 return 0;
2652
c5059423
AM
2653 /* We don't change the number of transitions by inverting,
2654 so make sure we start with the LS bit zero. */
2655 if (c & 1)
2656 c = ~c;
2657
2658 /* Reject all zeros or all ones. */
2659 if (c == 0)
9878760c
RK
2660 return 0;
2661
c5059423
AM
2662 /* Find the first transition. */
2663 lsb = c & -c;
2664
2665 /* Invert to look for a second transition. */
2666 c = ~c;
9878760c 2667
c5059423
AM
2668 /* Erase first transition. */
2669 c &= -lsb;
9878760c 2670
c5059423
AM
2671 /* Find the second transition (if any). */
2672 lsb = c & -c;
2673
2674 /* Match if all the bits above are 1's (or c is zero). */
2675 return c == -lsb;
9878760c
RK
2676}
2677
0ba1b2ff
AM
2678/* Return 1 for the PowerPC64 rlwinm corner case. */
2679
2680int
a2369ed3 2681mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2682{
2683 HOST_WIDE_INT c, lsb;
2684
2685 if (GET_CODE (op) != CONST_INT)
2686 return 0;
2687
2688 c = INTVAL (op);
2689
2690 if ((c & 0x80000001) != 0x80000001)
2691 return 0;
2692
2693 c = ~c;
2694 if (c == 0)
2695 return 0;
2696
2697 lsb = c & -c;
2698 c = ~c;
2699 c &= -lsb;
2700 lsb = c & -c;
2701 return c == -lsb;
2702}
2703
a260abc9
DE
2704/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2705 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2706 Reject all zeros, since zero should have been optimized away and
2707 confuses the making of MB and ME. */
9878760c
RK
2708
2709int
a2369ed3 2710mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2711{
2712 if (GET_CODE (op) == CONST_INT)
2713 {
02071907 2714 HOST_WIDE_INT c, lsb;
a260abc9 2715
c5059423 2716 c = INTVAL (op);
a260abc9 2717
0ba1b2ff 2718 /* Reject all zeros. */
c5059423 2719 if (c == 0)
e2c953b6
DE
2720 return 0;
2721
0ba1b2ff
AM
2722 /* We don't change the number of transitions by inverting,
2723 so make sure we start with the LS bit zero. */
2724 if (c & 1)
2725 c = ~c;
2726
c5059423
AM
2727 /* Find the transition, and check that all bits above are 1's. */
2728 lsb = c & -c;
e3981aab
DE
2729
2730 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2731 return c == -lsb;
e2c953b6 2732 }
0ba1b2ff
AM
2733 return 0;
2734}
2735
e1e2e653
NS
2736static int
2737mask64_1or2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED,
2738 bool allow_one)
0ba1b2ff
AM
2739{
2740 if (GET_CODE (op) == CONST_INT)
a260abc9 2741 {
0ba1b2ff 2742 HOST_WIDE_INT c, lsb;
e1e2e653
NS
2743 bool one_ok;
2744
0ba1b2ff 2745 c = INTVAL (op);
a260abc9 2746
0ba1b2ff
AM
2747 /* Disallow all zeros. */
2748 if (c == 0)
2749 return 0;
a260abc9 2750
e1e2e653
NS
2751 /* We can use a single rlwinm insn if no upper bits of C are set
2752 AND there are zero, one or two transitions in the _whole_ of
2753 C. */
2754 one_ok = !(c & ~(HOST_WIDE_INT)0xffffffff);
2755
0ba1b2ff
AM
2756 /* We don't change the number of transitions by inverting,
2757 so make sure we start with the LS bit zero. */
2758 if (c & 1)
2759 c = ~c;
a260abc9 2760
0ba1b2ff
AM
2761 /* Find the first transition. */
2762 lsb = c & -c;
a260abc9 2763
0ba1b2ff
AM
2764 /* Invert to look for a second transition. */
2765 c = ~c;
2766
2767 /* Erase first transition. */
2768 c &= -lsb;
2769
2770 /* Find the second transition. */
2771 lsb = c & -c;
2772
2773 /* Invert to look for a third transition. */
2774 c = ~c;
2775
2776 /* Erase second transition. */
2777 c &= -lsb;
2778
e1e2e653
NS
2779 if (one_ok && !(allow_one || c))
2780 return 0;
2781
0ba1b2ff
AM
2782 /* Find the third transition (if any). */
2783 lsb = c & -c;
2784
2785 /* Match if all the bits above are 1's (or c is zero). */
2786 return c == -lsb;
2787 }
2788 return 0;
2789}
2790
e1e2e653
NS
2791/* Like mask64_operand, but allow up to three transitions. This
2792 predicate is used by insn patterns that generate two rldicl or
2793 rldicr machine insns. */
2794int mask64_2_operand (rtx op, enum machine_mode mode)
2795{
2796 return mask64_1or2_operand (op, mode, false);
2797}
2798
0ba1b2ff
AM
2799/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2800 implement ANDing by the mask IN. */
2801void
a2369ed3 2802build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2803{
2804#if HOST_BITS_PER_WIDE_INT >= 64
2805 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2806 int shift;
2807
2808 if (GET_CODE (in) != CONST_INT)
2809 abort ();
2810
2811 c = INTVAL (in);
2812 if (c & 1)
2813 {
2814 /* Assume c initially something like 0x00fff000000fffff. The idea
2815 is to rotate the word so that the middle ^^^^^^ group of zeros
2816 is at the MS end and can be cleared with an rldicl mask. We then
2817 rotate back and clear off the MS ^^ group of zeros with a
2818 second rldicl. */
2819 c = ~c; /* c == 0xff000ffffff00000 */
2820 lsb = c & -c; /* lsb == 0x0000000000100000 */
2821 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2822 c = ~c; /* c == 0x00fff000000fffff */
2823 c &= -lsb; /* c == 0x00fff00000000000 */
2824 lsb = c & -c; /* lsb == 0x0000100000000000 */
2825 c = ~c; /* c == 0xff000fffffffffff */
2826 c &= -lsb; /* c == 0xff00000000000000 */
2827 shift = 0;
2828 while ((lsb >>= 1) != 0)
2829 shift++; /* shift == 44 on exit from loop */
2830 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2831 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2832 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2833 }
2834 else
0ba1b2ff
AM
2835 {
2836 /* Assume c initially something like 0xff000f0000000000. The idea
2837 is to rotate the word so that the ^^^ middle group of zeros
2838 is at the LS end and can be cleared with an rldicr mask. We then
2839 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2840 a second rldicr. */
2841 lsb = c & -c; /* lsb == 0x0000010000000000 */
2842 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2843 c = ~c; /* c == 0x00fff0ffffffffff */
2844 c &= -lsb; /* c == 0x00fff00000000000 */
2845 lsb = c & -c; /* lsb == 0x0000100000000000 */
2846 c = ~c; /* c == 0xff000fffffffffff */
2847 c &= -lsb; /* c == 0xff00000000000000 */
2848 shift = 0;
2849 while ((lsb >>= 1) != 0)
2850 shift++; /* shift == 44 on exit from loop */
2851 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2852 m1 >>= shift; /* m1 == 0x0000000000000fff */
2853 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2854 }
2855
2856 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2857 masks will be all 1's. We are guaranteed more than one transition. */
2858 out[0] = GEN_INT (64 - shift);
2859 out[1] = GEN_INT (m1);
2860 out[2] = GEN_INT (shift);
2861 out[3] = GEN_INT (m2);
2862#else
045572c7
GK
2863 (void)in;
2864 (void)out;
0ba1b2ff
AM
2865 abort ();
2866#endif
a260abc9
DE
2867}
2868
2869/* Return 1 if the operand is either a non-special register or a constant
2870 that can be used as the operand of a PowerPC64 logical AND insn. */
2871
2872int
a2369ed3 2873and64_operand (rtx op, enum machine_mode mode)
9878760c 2874{
a4f6c312 2875 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2876 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2877
2878 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2879}
2880
0ba1b2ff
AM
2881/* Like the above, but also match constants that can be implemented
2882 with two rldicl or rldicr insns. */
2883
2884int
a2369ed3 2885and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2886{
a3c9585f 2887 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
e1e2e653 2888 return gpc_reg_operand (op, mode) || mask64_1or2_operand (op, mode, true);
0ba1b2ff 2889
e1e2e653 2890 return logical_operand (op, mode) || mask64_1or2_operand (op, mode, true);
0ba1b2ff
AM
2891}
2892
a260abc9
DE
2893/* Return 1 if the operand is either a non-special register or a
2894 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2895
2896int
a2369ed3 2897and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2898{
a4f6c312 2899 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2900 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2901
2902 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2903}
2904
9878760c
RK
2905/* Return 1 if the operand is a general register or memory operand. */
2906
2907int
a2369ed3 2908reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2909{
b6c9286a
MM
2910 return (gpc_reg_operand (op, mode)
2911 || memory_operand (op, mode)
4c81e946 2912 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2913 || volatile_mem_operand (op, mode));
9878760c
RK
2914}
2915
a7a813f7 2916/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2917 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2918 instruction. */
2919
2920int
a2369ed3 2921lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2922{
2923 rtx inner = op;
2924
2925 if (reload_completed && GET_CODE (inner) == SUBREG)
2926 inner = SUBREG_REG (inner);
f676971a 2927
a7a813f7
RK
2928 return gpc_reg_operand (inner, mode)
2929 || (memory_operand (inner, mode)
2930 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2931 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2932 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2933 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2934 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2935}
2936
cc4d5fec
JH
2937/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2938
2939int
a2369ed3 2940symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2941{
2942 if (mode != VOIDmode && GET_MODE (op) != mode)
2943 return 0;
2944
473f51b6
DE
2945 return (GET_CODE (op) == SYMBOL_REF
2946 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2947}
2948
9878760c 2949/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2950 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2951
2952int
a2369ed3 2953call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2954{
2955 if (mode != VOIDmode && GET_MODE (op) != mode)
2956 return 0;
2957
2958 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2959 || (GET_CODE (op) == REG
2960 && (REGNO (op) == LINK_REGISTER_REGNUM
2961 || REGNO (op) == COUNT_REGISTER_REGNUM
2962 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2963}
2964
2af3d377 2965/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2966 this file. */
2af3d377
RK
2967
2968int
f676971a 2969current_file_function_operand (rtx op,
c4ad648e 2970 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2971{
473f51b6
DE
2972 return (GET_CODE (op) == SYMBOL_REF
2973 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2974 && (SYMBOL_REF_LOCAL_P (op)
2975 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2976}
2977
9878760c
RK
2978/* Return 1 if this operand is a valid input for a move insn. */
2979
2980int
a2369ed3 2981input_operand (rtx op, enum machine_mode mode)
9878760c 2982{
eb4e8003 2983 /* Memory is always valid. */
9878760c
RK
2984 if (memory_operand (op, mode))
2985 return 1;
2986
eb4e8003
RK
2987 /* For floating-point, easy constants are valid. */
2988 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2989 && CONSTANT_P (op)
2990 && easy_fp_constant (op, mode))
2991 return 1;
2992
4e74d8ec
MM
2993 /* Allow any integer constant. */
2994 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2995 && (GET_CODE (op) == CONST_INT
e675f625 2996 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2997 return 1;
2998
d744e06e
AH
2999 /* Allow easy vector constants. */
3000 if (GET_CODE (op) == CONST_VECTOR
3001 && easy_vector_constant (op, mode))
3002 return 1;
3003
eb4e8003
RK
3004 /* For floating-point or multi-word mode, the only remaining valid type
3005 is a register. */
9878760c
RK
3006 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3007 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 3008 return register_operand (op, mode);
9878760c 3009
88fe15a1
RK
3010 /* The only cases left are integral modes one word or smaller (we
3011 do not get called for MODE_CC values). These can be in any
3012 register. */
3013 if (register_operand (op, mode))
a8b3aeda 3014 return 1;
88fe15a1 3015
84cf9dda 3016 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 3017 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
3018 return 1;
3019
9ebbca7d 3020 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 3021 if (toc_relative_expr_p (op))
b6c9286a
MM
3022 return 1;
3023
88228c4b
MM
3024 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
3025 to be valid. */
f607bc57 3026 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
3027 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
3028 && small_data_operand (op, Pmode))
3029 return 1;
3030
042259f2 3031 return 0;
9878760c 3032}
7509c759 3033
95727fb8
AP
3034
3035/* Darwin, AIX increases natural record alignment to doubleword if the first
3036 field is an FP double while the FP fields remain word aligned. */
3037
19d66194 3038unsigned int
95727fb8
AP
3039rs6000_special_round_type_align (tree type, int computed, int specified)
3040{
3041 tree field = TYPE_FIELDS (type);
95727fb8
AP
3042
3043 /* Skip all the static variables only if ABI is greater than
71cc389b 3044 1 or equal to 0. */
3ce5437a 3045 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
3046 field = TREE_CHAIN (field);
3047
3ce5437a 3048 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
3049 return MAX (computed, specified);
3050
3051 return MAX (MAX (computed, specified), 64);
3052}
3053
a4f6c312 3054/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
3055
3056int
f676971a 3057small_data_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 3058 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 3059{
38c1f2d7 3060#if TARGET_ELF
5f59ecb7 3061 rtx sym_ref;
7509c759 3062
d9407988 3063 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 3064 return 0;
a54d04b7 3065
f607bc57 3066 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
3067 return 0;
3068
88228c4b
MM
3069 if (GET_CODE (op) == SYMBOL_REF)
3070 sym_ref = op;
3071
3072 else if (GET_CODE (op) != CONST
3073 || GET_CODE (XEXP (op, 0)) != PLUS
3074 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
3075 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
3076 return 0;
3077
88228c4b 3078 else
dbf55e53
MM
3079 {
3080 rtx sum = XEXP (op, 0);
3081 HOST_WIDE_INT summand;
3082
3083 /* We have to be careful here, because it is the referenced address
c4ad648e 3084 that must be 32k from _SDA_BASE_, not just the symbol. */
dbf55e53 3085 summand = INTVAL (XEXP (sum, 1));
307b599c 3086 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
3087 return 0;
3088
3089 sym_ref = XEXP (sum, 0);
3090 }
88228c4b 3091
20bfcd69 3092 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
3093#else
3094 return 0;
3095#endif
7509c759 3096}
46c07df8 3097
d2288d5d
HP
3098/* Return true, if operand is a memory operand and has a
3099 displacement divisible by 4. */
3100
3101int
3102word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
3103{
3104 rtx addr;
3105 int off = 0;
3106
3107 if (!memory_operand (op, mode))
3108 return 0;
3109
3110 addr = XEXP (op, 0);
3111 if (GET_CODE (addr) == PLUS
3112 && GET_CODE (XEXP (addr, 0)) == REG
3113 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
3114 off = INTVAL (XEXP (addr, 1));
3115
3116 return (off % 4) == 0;
3117}
3118
3a1f863f 3119/* Return true if either operand is a general purpose register. */
46c07df8 3120
3a1f863f
DE
3121bool
3122gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 3123{
3a1f863f
DE
3124 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
3125 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
3126}
3127
9ebbca7d 3128\f
4d588c14
RH
3129/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
3130
f676971a
EC
3131static int
3132constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d 3133{
f676971a 3134 switch (GET_CODE(op))
9ebbca7d
GK
3135 {
3136 case SYMBOL_REF:
c4501e62
JJ
3137 if (RS6000_SYMBOL_REF_TLS_P (op))
3138 return 0;
3139 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
3140 {
3141 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
3142 {
3143 *have_sym = 1;
3144 return 1;
3145 }
3146 else
3147 return 0;
3148 }
3149 else if (! strcmp (XSTR (op, 0), toc_label_name))
3150 {
3151 *have_toc = 1;
3152 return 1;
3153 }
3154 else
3155 return 0;
9ebbca7d
GK
3156 case PLUS:
3157 case MINUS:
c1f11548
DE
3158 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
3159 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 3160 case CONST:
a4f6c312 3161 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 3162 case CONST_INT:
a4f6c312 3163 return 1;
9ebbca7d 3164 default:
a4f6c312 3165 return 0;
9ebbca7d
GK
3166 }
3167}
3168
4d588c14 3169static bool
a2369ed3 3170constant_pool_expr_p (rtx op)
9ebbca7d
GK
3171{
3172 int have_sym = 0;
3173 int have_toc = 0;
3174 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
3175}
3176
4d588c14 3177static bool
a2369ed3 3178toc_relative_expr_p (rtx op)
9ebbca7d 3179{
4d588c14
RH
3180 int have_sym = 0;
3181 int have_toc = 0;
3182 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
3183}
3184
4d588c14 3185bool
a2369ed3 3186legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
3187{
3188 return (TARGET_TOC
3189 && GET_CODE (x) == PLUS
3190 && GET_CODE (XEXP (x, 0)) == REG
3191 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
3192 && constant_pool_expr_p (XEXP (x, 1)));
3193}
3194
3195static bool
a2369ed3 3196legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
3197{
3198 return (DEFAULT_ABI == ABI_V4
3199 && !flag_pic && !TARGET_TOC
3200 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
3201 && small_data_operand (x, mode));
3202}
3203
60cdabab
DE
3204/* SPE offset addressing is limited to 5-bits worth of double words. */
3205#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
3206
76d2b81d
DJ
3207bool
3208rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3209{
3210 unsigned HOST_WIDE_INT offset, extra;
3211
3212 if (GET_CODE (x) != PLUS)
3213 return false;
3214 if (GET_CODE (XEXP (x, 0)) != REG)
3215 return false;
3216 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3217 return false;
60cdabab
DE
3218 if (legitimate_constant_pool_address_p (x))
3219 return true;
4d588c14
RH
3220 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3221 return false;
3222
3223 offset = INTVAL (XEXP (x, 1));
3224 extra = 0;
3225 switch (mode)
3226 {
3227 case V16QImode:
3228 case V8HImode:
3229 case V4SFmode:
3230 case V4SImode:
3231 /* AltiVec vector modes. Only reg+reg addressing is valid here,
3232 which leaves the only valid constant offset of zero, which by
3233 canonicalization rules is also invalid. */
3234 return false;
3235
3236 case V4HImode:
3237 case V2SImode:
3238 case V1DImode:
3239 case V2SFmode:
3240 /* SPE vector modes. */
3241 return SPE_CONST_OFFSET_OK (offset);
3242
3243 case DFmode:
4d4cbc0e
AH
3244 if (TARGET_E500_DOUBLE)
3245 return SPE_CONST_OFFSET_OK (offset);
3246
4d588c14 3247 case DImode:
3364872d 3248 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
3249 extra = 4;
3250 else if (offset & 3)
3251 return false;
3252 break;
3253
3254 case TFmode:
3255 case TImode:
3364872d 3256 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
3257 extra = 12;
3258 else if (offset & 3)
3259 return false;
3260 else
3261 extra = 8;
3262 break;
3263
3264 default:
3265 break;
3266 }
3267
b1917422
AM
3268 offset += 0x8000;
3269 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
3270}
3271
3272static bool
a2369ed3 3273legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
3274{
3275 rtx op0, op1;
3276
3277 if (GET_CODE (x) != PLUS)
3278 return false;
850e8d3d 3279
4d588c14
RH
3280 op0 = XEXP (x, 0);
3281 op1 = XEXP (x, 1);
3282
3283 if (!REG_P (op0) || !REG_P (op1))
3284 return false;
3285
3286 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
3287 && INT_REG_OK_FOR_INDEX_P (op1, strict))
3288 || (INT_REG_OK_FOR_BASE_P (op1, strict)
3289 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
3290}
3291
4d588c14 3292static inline bool
a2369ed3 3293legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
3294{
3295 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
3296}
3297
4c81e946
FJ
3298static bool
3299macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
3300{
c4ad648e
AM
3301 if (!TARGET_MACHO || !flag_pic
3302 || mode != SImode || GET_CODE(x) != MEM)
3303 return false;
3304 x = XEXP (x, 0);
4c81e946
FJ
3305
3306 if (GET_CODE (x) != LO_SUM)
3307 return false;
3308 if (GET_CODE (XEXP (x, 0)) != REG)
3309 return false;
3310 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
3311 return false;
3312 x = XEXP (x, 1);
3313
3314 return CONSTANT_P (x);
3315}
3316
4d588c14 3317static bool
a2369ed3 3318legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3319{
3320 if (GET_CODE (x) != LO_SUM)
3321 return false;
3322 if (GET_CODE (XEXP (x, 0)) != REG)
3323 return false;
3324 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3325 return false;
f82f556d
AH
3326 if (TARGET_E500_DOUBLE && mode == DFmode)
3327 return false;
4d588c14
RH
3328 x = XEXP (x, 1);
3329
8622e235 3330 if (TARGET_ELF || TARGET_MACHO)
4d588c14 3331 {
a29077da 3332 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
3333 return false;
3334 if (TARGET_TOC)
3335 return false;
3336 if (GET_MODE_NUNITS (mode) != 1)
3337 return false;
c1e55850 3338 if (GET_MODE_BITSIZE (mode) > 64)
4d588c14
RH
3339 return false;
3340
3341 return CONSTANT_P (x);
3342 }
3343
3344 return false;
3345}
3346
3347
9ebbca7d
GK
3348/* Try machine-dependent ways of modifying an illegitimate address
3349 to be legitimate. If we find one, return the new, valid address.
3350 This is used from only one place: `memory_address' in explow.c.
3351
a4f6c312
SS
3352 OLDX is the address as it was before break_out_memory_refs was
3353 called. In some cases it is useful to look at this to decide what
3354 needs to be done.
9ebbca7d 3355
a4f6c312 3356 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 3357
a4f6c312
SS
3358 It is always safe for this function to do nothing. It exists to
3359 recognize opportunities to optimize the output.
9ebbca7d
GK
3360
3361 On RS/6000, first check for the sum of a register with a constant
3362 integer that is out of range. If so, generate code to add the
3363 constant with the low-order 16 bits masked to the register and force
3364 this result into another register (this can be done with `cau').
3365 Then generate an address of REG+(CONST&0xffff), allowing for the
3366 possibility of bit 16 being a one.
3367
3368 Then check for the sum of a register and something not constant, try to
3369 load the other things into a register and return the sum. */
4d588c14 3370
9ebbca7d 3371rtx
a2369ed3
DJ
3372rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3373 enum machine_mode mode)
0ac081f6 3374{
c4501e62
JJ
3375 if (GET_CODE (x) == SYMBOL_REF)
3376 {
3377 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
3378 if (model != 0)
3379 return rs6000_legitimize_tls_address (x, model);
3380 }
3381
f676971a 3382 if (GET_CODE (x) == PLUS
9ebbca7d
GK
3383 && GET_CODE (XEXP (x, 0)) == REG
3384 && GET_CODE (XEXP (x, 1)) == CONST_INT
3385 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
f676971a 3386 {
9ebbca7d
GK
3387 HOST_WIDE_INT high_int, low_int;
3388 rtx sum;
a65c591c
DE
3389 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
3390 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
3391 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
3392 GEN_INT (high_int)), 0);
3393 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
3394 }
f676971a 3395 else if (GET_CODE (x) == PLUS
9ebbca7d
GK
3396 && GET_CODE (XEXP (x, 0)) == REG
3397 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 3398 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
3399 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3400 || TARGET_POWERPC64
4d4cbc0e 3401 || ((mode != DFmode || TARGET_E500_DOUBLE) && mode != TFmode))
9ebbca7d
GK
3402 && (TARGET_POWERPC64 || mode != DImode)
3403 && mode != TImode)
3404 {
3405 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
3406 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
3407 }
0ac081f6
AH
3408 else if (ALTIVEC_VECTOR_MODE (mode))
3409 {
3410 rtx reg;
3411
3412 /* Make sure both operands are registers. */
3413 if (GET_CODE (x) == PLUS)
9f85ed45 3414 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
3415 force_reg (Pmode, XEXP (x, 1)));
3416
3417 reg = force_reg (Pmode, x);
3418 return reg;
3419 }
4d4cbc0e
AH
3420 else if (SPE_VECTOR_MODE (mode)
3421 || (TARGET_E500_DOUBLE && mode == DFmode))
a3170dc6
AH
3422 {
3423 /* We accept [reg + reg] and [reg + OFFSET]. */
3424
3425 if (GET_CODE (x) == PLUS)
c4ad648e
AM
3426 {
3427 rtx op1 = XEXP (x, 0);
3428 rtx op2 = XEXP (x, 1);
a3170dc6 3429
c4ad648e 3430 op1 = force_reg (Pmode, op1);
a3170dc6 3431
c4ad648e
AM
3432 if (GET_CODE (op2) != REG
3433 && (GET_CODE (op2) != CONST_INT
3434 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
3435 op2 = force_reg (Pmode, op2);
a3170dc6 3436
c4ad648e
AM
3437 return gen_rtx_PLUS (Pmode, op1, op2);
3438 }
a3170dc6
AH
3439
3440 return force_reg (Pmode, x);
3441 }
f1384257
AM
3442 else if (TARGET_ELF
3443 && TARGET_32BIT
3444 && TARGET_NO_TOC
3445 && ! flag_pic
9ebbca7d 3446 && GET_CODE (x) != CONST_INT
f676971a 3447 && GET_CODE (x) != CONST_DOUBLE
9ebbca7d 3448 && CONSTANT_P (x)
6ac7bf2c
GK
3449 && GET_MODE_NUNITS (mode) == 1
3450 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 3451 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
3452 {
3453 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3454 emit_insn (gen_elf_high (reg, x));
3455 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 3456 }
ee890fe2
SS
3457 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
3458 && ! flag_pic
ab82a49f
AP
3459#if TARGET_MACHO
3460 && ! MACHO_DYNAMIC_NO_PIC_P
3461#endif
ee890fe2 3462 && GET_CODE (x) != CONST_INT
f676971a 3463 && GET_CODE (x) != CONST_DOUBLE
ee890fe2 3464 && CONSTANT_P (x)
f82f556d 3465 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
f676971a 3466 && mode != DImode
ee890fe2
SS
3467 && mode != TImode)
3468 {
3469 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3470 emit_insn (gen_macho_high (reg, x));
3471 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 3472 }
f676971a 3473 else if (TARGET_TOC
4d588c14 3474 && constant_pool_expr_p (x)
a9098fd0 3475 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
3476 {
3477 return create_TOC_reference (x);
3478 }
3479 else
3480 return NULL_RTX;
3481}
258bfae2 3482
c973d557
JJ
3483/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
3484 We need to emit DTP-relative relocations. */
3485
3486void
3487rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
3488{
3489 switch (size)
3490 {
3491 case 4:
3492 fputs ("\t.long\t", file);
3493 break;
3494 case 8:
3495 fputs (DOUBLE_INT_ASM_OP, file);
3496 break;
3497 default:
3498 abort ();
3499 }
3500 output_addr_const (file, x);
3501 fputs ("@dtprel+0x8000", file);
3502}
3503
c4501e62
JJ
3504/* Construct the SYMBOL_REF for the tls_get_addr function. */
3505
3506static GTY(()) rtx rs6000_tls_symbol;
3507static rtx
863d938c 3508rs6000_tls_get_addr (void)
c4501e62
JJ
3509{
3510 if (!rs6000_tls_symbol)
3511 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
3512
3513 return rs6000_tls_symbol;
3514}
3515
3516/* Construct the SYMBOL_REF for TLS GOT references. */
3517
3518static GTY(()) rtx rs6000_got_symbol;
3519static rtx
863d938c 3520rs6000_got_sym (void)
c4501e62
JJ
3521{
3522 if (!rs6000_got_symbol)
3523 {
3524 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3525 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
3526 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
f676971a 3527 }
c4501e62
JJ
3528
3529 return rs6000_got_symbol;
3530}
3531
3532/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3533 this (thread-local) address. */
3534
3535static rtx
a2369ed3 3536rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
3537{
3538 rtx dest, insn;
3539
3540 dest = gen_reg_rtx (Pmode);
3541 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
3542 {
3543 rtx tlsreg;
3544
3545 if (TARGET_64BIT)
3546 {
3547 tlsreg = gen_rtx_REG (Pmode, 13);
3548 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
3549 }
3550 else
3551 {
3552 tlsreg = gen_rtx_REG (Pmode, 2);
3553 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
3554 }
3555 emit_insn (insn);
3556 }
3557 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
3558 {
3559 rtx tlsreg, tmp;
3560
3561 tmp = gen_reg_rtx (Pmode);
3562 if (TARGET_64BIT)
3563 {
3564 tlsreg = gen_rtx_REG (Pmode, 13);
3565 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
3566 }
3567 else
3568 {
3569 tlsreg = gen_rtx_REG (Pmode, 2);
3570 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
3571 }
3572 emit_insn (insn);
3573 if (TARGET_64BIT)
3574 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3575 else
3576 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3577 emit_insn (insn);
3578 }
3579 else
3580 {
3581 rtx r3, got, tga, tmp1, tmp2, eqv;
3582
3583 if (TARGET_64BIT)
3584 got = gen_rtx_REG (Pmode, TOC_REGISTER);
3585 else
3586 {
3587 if (flag_pic == 1)
3588 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3589 else
3590 {
3591 rtx gsym = rs6000_got_sym ();
3592 got = gen_reg_rtx (Pmode);
3593 if (flag_pic == 0)
3594 rs6000_emit_move (got, gsym, Pmode);
3595 else
3596 {
3597 char buf[30];
3598 static int tls_got_labelno = 0;
3599 rtx tempLR, lab, tmp3, mem;
3600 rtx first, last;
3601
3602 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
3603 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
3604 tempLR = gen_reg_rtx (Pmode);
3605 tmp1 = gen_reg_rtx (Pmode);
3606 tmp2 = gen_reg_rtx (Pmode);
3607 tmp3 = gen_reg_rtx (Pmode);
542a8afa 3608 mem = gen_const_mem (Pmode, tmp1);
c4501e62
JJ
3609
3610 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
3611 gsym));
3612 emit_move_insn (tmp1, tempLR);
3613 emit_move_insn (tmp2, mem);
3614 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
3615 last = emit_move_insn (got, tmp3);
3616 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
3617 REG_NOTES (last));
3618 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3619 REG_NOTES (first));
3620 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3621 REG_NOTES (last));
3622 }
3623 }
3624 }
3625
3626 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3627 {
3628 r3 = gen_rtx_REG (Pmode, 3);
3629 if (TARGET_64BIT)
3630 insn = gen_tls_gd_64 (r3, got, addr);
3631 else
3632 insn = gen_tls_gd_32 (r3, got, addr);
3633 start_sequence ();
3634 emit_insn (insn);
3635 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3636 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3637 insn = emit_call_insn (insn);
3638 CONST_OR_PURE_CALL_P (insn) = 1;
3639 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3640 insn = get_insns ();
3641 end_sequence ();
3642 emit_libcall_block (insn, dest, r3, addr);
3643 }
3644 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3645 {
3646 r3 = gen_rtx_REG (Pmode, 3);
3647 if (TARGET_64BIT)
3648 insn = gen_tls_ld_64 (r3, got);
3649 else
3650 insn = gen_tls_ld_32 (r3, got);
3651 start_sequence ();
3652 emit_insn (insn);
3653 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3654 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3655 insn = emit_call_insn (insn);
3656 CONST_OR_PURE_CALL_P (insn) = 1;
3657 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3658 insn = get_insns ();
3659 end_sequence ();
3660 tmp1 = gen_reg_rtx (Pmode);
3661 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3662 UNSPEC_TLSLD);
3663 emit_libcall_block (insn, tmp1, r3, eqv);
3664 if (rs6000_tls_size == 16)
3665 {
3666 if (TARGET_64BIT)
3667 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3668 else
3669 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3670 }
3671 else if (rs6000_tls_size == 32)
3672 {
3673 tmp2 = gen_reg_rtx (Pmode);
3674 if (TARGET_64BIT)
3675 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3676 else
3677 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3678 emit_insn (insn);
3679 if (TARGET_64BIT)
3680 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3681 else
3682 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3683 }
3684 else
3685 {
3686 tmp2 = gen_reg_rtx (Pmode);
3687 if (TARGET_64BIT)
3688 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3689 else
3690 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3691 emit_insn (insn);
3692 insn = gen_rtx_SET (Pmode, dest,
3693 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3694 }
3695 emit_insn (insn);
3696 }
3697 else
3698 {
3699 /* IE, or 64 bit offset LE. */
3700 tmp2 = gen_reg_rtx (Pmode);
3701 if (TARGET_64BIT)
3702 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3703 else
3704 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3705 emit_insn (insn);
3706 if (TARGET_64BIT)
3707 insn = gen_tls_tls_64 (dest, tmp2, addr);
3708 else
3709 insn = gen_tls_tls_32 (dest, tmp2, addr);
3710 emit_insn (insn);
3711 }
3712 }
3713
3714 return dest;
3715}
3716
3717/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3718 instruction definitions. */
3719
3720int
a2369ed3 3721rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3722{
3723 return RS6000_SYMBOL_REF_TLS_P (x);
3724}
3725
3726/* Return 1 if X contains a thread-local symbol. */
3727
3728bool
a2369ed3 3729rs6000_tls_referenced_p (rtx x)
c4501e62 3730{
cd413cab
AP
3731 if (! TARGET_HAVE_TLS)
3732 return false;
3733
c4501e62
JJ
3734 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3735}
3736
3737/* Return 1 if *X is a thread-local symbol. This is the same as
3738 rs6000_tls_symbol_ref except for the type of the unused argument. */
3739
3740static inline int
a2369ed3 3741rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3742{
3743 return RS6000_SYMBOL_REF_TLS_P (*x);
3744}
3745
24ea750e
DJ
3746/* The convention appears to be to define this wherever it is used.
3747 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3748 is now used here. */
3749#ifndef REG_MODE_OK_FOR_BASE_P
3750#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3751#endif
3752
3753/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3754 replace the input X, or the original X if no replacement is called for.
3755 The output parameter *WIN is 1 if the calling macro should goto WIN,
3756 0 if it should not.
3757
3758 For RS/6000, we wish to handle large displacements off a base
3759 register by splitting the addend across an addiu/addis and the mem insn.
3760 This cuts number of extra insns needed from 3 to 1.
3761
3762 On Darwin, we use this to generate code for floating point constants.
3763 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3764 The Darwin code is inside #if TARGET_MACHO because only then is
3765 machopic_function_base_name() defined. */
3766rtx
f676971a 3767rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
c4ad648e
AM
3768 int opnum, int type,
3769 int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e 3770{
f676971a 3771 /* We must recognize output that we have already generated ourselves. */
24ea750e
DJ
3772 if (GET_CODE (x) == PLUS
3773 && GET_CODE (XEXP (x, 0)) == PLUS
3774 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3775 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3776 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3777 {
3778 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3779 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3780 opnum, (enum reload_type)type);
24ea750e
DJ
3781 *win = 1;
3782 return x;
3783 }
3deb2758 3784
24ea750e
DJ
3785#if TARGET_MACHO
3786 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3787 && GET_CODE (x) == LO_SUM
3788 && GET_CODE (XEXP (x, 0)) == PLUS
3789 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3790 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3791 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3792 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3793 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3794 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3795 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3796 {
3797 /* Result of previous invocation of this function on Darwin
6f317ef3 3798 floating point constant. */
24ea750e 3799 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3800 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3801 opnum, (enum reload_type)type);
24ea750e
DJ
3802 *win = 1;
3803 return x;
3804 }
3805#endif
3806 if (GET_CODE (x) == PLUS
3807 && GET_CODE (XEXP (x, 0)) == REG
3808 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3809 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3810 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3811 && !SPE_VECTOR_MODE (mode)
4d4cbc0e 3812 && !(TARGET_E500_DOUBLE && mode == DFmode)
78c875e8 3813 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3814 {
3815 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3816 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3817 HOST_WIDE_INT high
c4ad648e 3818 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
24ea750e
DJ
3819
3820 /* Check for 32-bit overflow. */
3821 if (high + low != val)
c4ad648e 3822 {
24ea750e
DJ
3823 *win = 0;
3824 return x;
3825 }
3826
3827 /* Reload the high part into a base reg; leave the low part
c4ad648e 3828 in the mem directly. */
24ea750e
DJ
3829
3830 x = gen_rtx_PLUS (GET_MODE (x),
c4ad648e
AM
3831 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3832 GEN_INT (high)),
3833 GEN_INT (low));
24ea750e
DJ
3834
3835 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
c4ad648e
AM
3836 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3837 opnum, (enum reload_type)type);
24ea750e
DJ
3838 *win = 1;
3839 return x;
3840 }
3841#if TARGET_MACHO
3842 if (GET_CODE (x) == SYMBOL_REF
3843 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3844 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3845 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3846 /* Don't do this for TFmode, since the result isn't offsettable. */
3847 && mode != TFmode)
24ea750e 3848 {
a29077da
GK
3849 if (flag_pic)
3850 {
3851 rtx offset = gen_rtx_CONST (Pmode,
3852 gen_rtx_MINUS (Pmode, x,
11abc112 3853 machopic_function_base_sym ()));
a29077da
GK
3854 x = gen_rtx_LO_SUM (GET_MODE (x),
3855 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3856 gen_rtx_HIGH (Pmode, offset)), offset);
3857 }
3858 else
3859 x = gen_rtx_LO_SUM (GET_MODE (x),
c4ad648e 3860 gen_rtx_HIGH (Pmode, x), x);
a29077da 3861
24ea750e 3862 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3863 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3864 opnum, (enum reload_type)type);
24ea750e
DJ
3865 *win = 1;
3866 return x;
3867 }
3868#endif
3869 if (TARGET_TOC
4d588c14 3870 && constant_pool_expr_p (x)
c1f11548 3871 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3872 {
3873 (x) = create_TOC_reference (x);
3874 *win = 1;
3875 return x;
3876 }
3877 *win = 0;
3878 return x;
f676971a 3879}
24ea750e 3880
258bfae2
FS
3881/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3882 that is a valid memory address for an instruction.
3883 The MODE argument is the machine mode for the MEM expression
3884 that wants to use this address.
3885
3886 On the RS/6000, there are four valid address: a SYMBOL_REF that
3887 refers to a constant pool entry of an address (or the sum of it
3888 plus a constant), a short (16-bit signed) constant plus a register,
3889 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3890 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3891 we must ensure that both words are addressable or PowerPC64 with offset
3892 word aligned.
3893
3894 For modes spanning multiple registers (DFmode in 32-bit GPRs,
76d2b81d 3895 32-bit DImode, TImode, TFmode), indexed addressing cannot be used because
258bfae2
FS
3896 adjacent memory cells are accessed by adding word-sized offsets
3897 during assembly output. */
3898int
a2369ed3 3899rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3900{
850e8d3d
DN
3901 /* If this is an unaligned stvx/ldvx type address, discard the outer AND. */
3902 if (TARGET_ALTIVEC
3903 && ALTIVEC_VECTOR_MODE (mode)
3904 && GET_CODE (x) == AND
3905 && GET_CODE (XEXP (x, 1)) == CONST_INT
3906 && INTVAL (XEXP (x, 1)) == -16)
3907 x = XEXP (x, 0);
3908
c4501e62
JJ
3909 if (RS6000_SYMBOL_REF_TLS_P (x))
3910 return 0;
4d588c14 3911 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3912 return 1;
3913 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3914 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3915 && !SPE_VECTOR_MODE (mode)
4d4cbc0e 3916 && !(TARGET_E500_DOUBLE && mode == DFmode)
258bfae2 3917 && TARGET_UPDATE
4d588c14 3918 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3919 return 1;
4d588c14 3920 if (legitimate_small_data_p (mode, x))
258bfae2 3921 return 1;
4d588c14 3922 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3923 return 1;
3924 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3925 if (! reg_ok_strict
3926 && GET_CODE (x) == PLUS
3927 && GET_CODE (XEXP (x, 0)) == REG
708d2456 3928 && (XEXP (x, 0) == virtual_stack_vars_rtx
c4ad648e 3929 || XEXP (x, 0) == arg_pointer_rtx)
258bfae2
FS
3930 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3931 return 1;
76d2b81d 3932 if (rs6000_legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3933 return 1;
3934 if (mode != TImode
76d2b81d 3935 && mode != TFmode
a3170dc6
AH
3936 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3937 || TARGET_POWERPC64
4d4cbc0e 3938 || ((mode != DFmode || TARGET_E500_DOUBLE) && mode != TFmode))
258bfae2 3939 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3940 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3941 return 1;
4d588c14 3942 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3943 return 1;
3944 return 0;
3945}
4d588c14
RH
3946
3947/* Go to LABEL if ADDR (a legitimate address expression)
3948 has an effect that depends on the machine mode it is used for.
3949
3950 On the RS/6000 this is true of all integral offsets (since AltiVec
3951 modes don't allow them) or is a pre-increment or decrement.
3952
3953 ??? Except that due to conceptual problems in offsettable_address_p
3954 we can't really report the problems of integral offsets. So leave
f676971a 3955 this assuming that the adjustable offset must be valid for the
4d588c14
RH
3956 sub-words of a TFmode operand, which is what we had before. */
3957
3958bool
a2369ed3 3959rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3960{
3961 switch (GET_CODE (addr))
3962 {
3963 case PLUS:
3964 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3965 {
3966 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3967 return val + 12 + 0x8000 >= 0x10000;
3968 }
3969 break;
3970
3971 case LO_SUM:
3972 return true;
3973
3974 case PRE_INC:
3975 case PRE_DEC:
3976 return TARGET_UPDATE;
3977
3978 default:
3979 break;
3980 }
3981
3982 return false;
3983}
d8ecbcdb
AH
3984
3985/* Return number of consecutive hard regs needed starting at reg REGNO
3986 to hold something of mode MODE.
3987 This is ordinarily the length in words of a value of mode MODE
3988 but can be less for certain modes in special long registers.
3989
3990 For the SPE, GPRs are 64 bits but only 32 bits are visible in
3991 scalar instructions. The upper 32 bits are only available to the
3992 SIMD instructions.
3993
3994 POWER and PowerPC GPRs hold 32 bits worth;
3995 PowerPC64 GPRs and FPRs point register holds 64 bits worth. */
3996
3997int
3998rs6000_hard_regno_nregs (int regno, enum machine_mode mode)
3999{
4000 if (FP_REGNO_P (regno))
4001 return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD;
4002
4d4cbc0e
AH
4003 if (TARGET_E500_DOUBLE && mode == DFmode)
4004 return 1;
4005
d8ecbcdb
AH
4006 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
4007 return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD;
4008
4009 if (ALTIVEC_REGNO_P (regno))
4010 return
4011 (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD;
4012
4013 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4014}
2aa4498c
AH
4015
4016/* Change register usage conditional on target flags. */
4017void
4018rs6000_conditional_register_usage (void)
4019{
4020 int i;
4021
4022 /* Set MQ register fixed (already call_used) if not POWER
4023 architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not
4024 be allocated. */
4025 if (! TARGET_POWER)
4026 fixed_regs[64] = 1;
4027
4028 /* 64-bit AIX reserves GPR13 for thread-private data. */
4029 if (TARGET_64BIT)
4030 fixed_regs[13] = call_used_regs[13]
4031 = call_really_used_regs[13] = 1;
4032
4033 /* Conditionally disable FPRs. */
4034 if (TARGET_SOFT_FLOAT || !TARGET_FPRS)
4035 for (i = 32; i < 64; i++)
4036 fixed_regs[i] = call_used_regs[i]
c4ad648e 4037 = call_really_used_regs[i] = 1;
2aa4498c
AH
4038
4039 if (DEFAULT_ABI == ABI_V4
4040 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
4041 && flag_pic == 2)
4042 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
4043
4044 if (DEFAULT_ABI == ABI_V4
4045 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
4046 && flag_pic == 1)
4047 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
4048 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
4049 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
4050
4051 if (DEFAULT_ABI == ABI_DARWIN
4052 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
4053 global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
4054 = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
4055 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
4056 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
4057
b4db40bf
JJ
4058 if (TARGET_TOC && TARGET_MINIMAL_TOC)
4059 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
4060 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
4061
2aa4498c
AH
4062 if (TARGET_ALTIVEC)
4063 global_regs[VSCR_REGNO] = 1;
4064
4065 if (TARGET_SPE)
4066 {
4067 global_regs[SPEFSCR_REGNO] = 1;
4068 fixed_regs[FIXED_SCRATCH]
c4ad648e 4069 = call_used_regs[FIXED_SCRATCH]
2aa4498c
AH
4070 = call_really_used_regs[FIXED_SCRATCH] = 1;
4071 }
4072
4073 if (! TARGET_ALTIVEC)
4074 {
4075 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
4076 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
4077 call_really_used_regs[VRSAVE_REGNO] = 1;
4078 }
4079
4080 if (TARGET_ALTIVEC_ABI)
4081 for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i)
4082 call_used_regs[i] = call_really_used_regs[i] = 1;
4083}
fb4d4348 4084\f
a4f6c312
SS
4085/* Try to output insns to set TARGET equal to the constant C if it can
4086 be done in less than N insns. Do all computations in MODE.
4087 Returns the place where the output has been placed if it can be
4088 done and the insns have been emitted. If it would take more than N
4089 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
4090
4091rtx
f676971a 4092rs6000_emit_set_const (rtx dest, enum machine_mode mode,
a2369ed3 4093 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 4094{
af8cb5c5 4095 rtx result, insn, set;
2bfcf297
DB
4096 HOST_WIDE_INT c0, c1;
4097
af8cb5c5 4098 if (mode == QImode || mode == HImode)
2bfcf297
DB
4099 {
4100 if (dest == NULL)
c4ad648e 4101 dest = gen_reg_rtx (mode);
2bfcf297
DB
4102 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
4103 return dest;
4104 }
af8cb5c5 4105 else if (mode == SImode)
2bfcf297 4106 {
af8cb5c5
DE
4107 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
4108
4109 emit_insn (gen_rtx_SET (VOIDmode, result,
4110 GEN_INT (INTVAL (source)
4111 & (~ (HOST_WIDE_INT) 0xffff))));
4112 emit_insn (gen_rtx_SET (VOIDmode, dest,
4113 gen_rtx_IOR (SImode, result,
4114 GEN_INT (INTVAL (source) & 0xffff))));
4115 result = dest;
2bfcf297 4116 }
af8cb5c5 4117 else if (mode == DImode)
2bfcf297 4118 {
af8cb5c5
DE
4119 if (GET_CODE (source) == CONST_INT)
4120 {
4121 c0 = INTVAL (source);
4122 c1 = -(c0 < 0);
4123 }
4124 else if (GET_CODE (source) == CONST_DOUBLE)
4125 {
2bfcf297 4126#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
4127 c0 = CONST_DOUBLE_LOW (source);
4128 c1 = -(c0 < 0);
2bfcf297 4129#else
af8cb5c5
DE
4130 c0 = CONST_DOUBLE_LOW (source);
4131 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 4132#endif
af8cb5c5
DE
4133 }
4134 else
4135 abort ();
4136
4137 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
4138 }
4139 else
a4f6c312 4140 abort ();
2bfcf297 4141
af8cb5c5
DE
4142 insn = get_last_insn ();
4143 set = single_set (insn);
4144 if (! CONSTANT_P (SET_SRC (set)))
4145 set_unique_reg_note (insn, REG_EQUAL, source);
4146
4147 return result;
2bfcf297
DB
4148}
4149
4150/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
4151 fall back to a straight forward decomposition. We do this to avoid
4152 exponential run times encountered when looking for longer sequences
4153 with rs6000_emit_set_const. */
4154static rtx
a2369ed3 4155rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
4156{
4157 if (!TARGET_POWERPC64)
4158 {
4159 rtx operand1, operand2;
4160
4161 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
4162 DImode);
4163 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
4164 DImode);
4165 emit_move_insn (operand1, GEN_INT (c1));
4166 emit_move_insn (operand2, GEN_INT (c2));
4167 }
4168 else
4169 {
bc06712d 4170 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 4171
bc06712d 4172 ud1 = c1 & 0xffff;
f921c9c9 4173 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 4174#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 4175 c2 = c1 >> 32;
2bfcf297 4176#endif
bc06712d 4177 ud3 = c2 & 0xffff;
f921c9c9 4178 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 4179
f676971a 4180 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
bc06712d 4181 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 4182 {
bc06712d 4183 if (ud1 & 0x8000)
b78d48dd 4184 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
4185 else
4186 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 4187 }
2bfcf297 4188
f676971a 4189 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
bc06712d 4190 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 4191 {
bc06712d 4192 if (ud2 & 0x8000)
f676971a 4193 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
bc06712d 4194 - 0x80000000));
252b88f7 4195 else
bc06712d
TR
4196 emit_move_insn (dest, GEN_INT (ud2 << 16));
4197 if (ud1 != 0)
4198 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 4199 }
f676971a 4200 else if ((ud4 == 0xffff && (ud3 & 0x8000))
bc06712d
TR
4201 || (ud4 == 0 && ! (ud3 & 0x8000)))
4202 {
4203 if (ud3 & 0x8000)
f676971a 4204 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
bc06712d
TR
4205 - 0x80000000));
4206 else
4207 emit_move_insn (dest, GEN_INT (ud3 << 16));
4208
4209 if (ud2 != 0)
4210 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
4211 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
4212 if (ud1 != 0)
4213 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4214 }
f676971a 4215 else
bc06712d
TR
4216 {
4217 if (ud4 & 0x8000)
f676971a 4218 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
bc06712d
TR
4219 - 0x80000000));
4220 else
4221 emit_move_insn (dest, GEN_INT (ud4 << 16));
4222
4223 if (ud3 != 0)
4224 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 4225
bc06712d
TR
4226 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
4227 if (ud2 != 0)
f676971a
EC
4228 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
4229 GEN_INT (ud2 << 16)));
bc06712d
TR
4230 if (ud1 != 0)
4231 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4232 }
4233 }
2bfcf297
DB
4234 return dest;
4235}
4236
76d2b81d
DJ
4237/* Helper for the following. Get rid of [r+r] memory refs
4238 in cases where it won't work (TImode, TFmode). */
4239
4240static void
4241rs6000_eliminate_indexed_memrefs (rtx operands[2])
4242{
4243 if (GET_CODE (operands[0]) == MEM
4244 && GET_CODE (XEXP (operands[0], 0)) != REG
4245 && ! reload_in_progress)
4246 operands[0]
4247 = replace_equiv_address (operands[0],
4248 copy_addr_to_reg (XEXP (operands[0], 0)));
4249
4250 if (GET_CODE (operands[1]) == MEM
4251 && GET_CODE (XEXP (operands[1], 0)) != REG
4252 && ! reload_in_progress)
4253 operands[1]
4254 = replace_equiv_address (operands[1],
4255 copy_addr_to_reg (XEXP (operands[1], 0)));
4256}
4257
fb4d4348
GK
4258/* Emit a move from SOURCE to DEST in mode MODE. */
4259void
a2369ed3 4260rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
4261{
4262 rtx operands[2];
4263 operands[0] = dest;
4264 operands[1] = source;
f676971a 4265
fb4d4348
GK
4266 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
4267 if (GET_CODE (operands[1]) == CONST_DOUBLE
4268 && ! FLOAT_MODE_P (mode)
4269 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
4270 {
4271 /* FIXME. This should never happen. */
4272 /* Since it seems that it does, do the safe thing and convert
4273 to a CONST_INT. */
2496c7bd 4274 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
4275 }
4276 if (GET_CODE (operands[1]) == CONST_DOUBLE
4277 && ! FLOAT_MODE_P (mode)
4278 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
4279 && CONST_DOUBLE_LOW (operands[1]) >= 0)
4280 || (CONST_DOUBLE_HIGH (operands[1]) == -1
4281 && CONST_DOUBLE_LOW (operands[1]) < 0)))
4282 abort ();
c9e8cb32
DD
4283
4284 /* Check if GCC is setting up a block move that will end up using FP
4285 registers as temporaries. We must make sure this is acceptable. */
4286 if (GET_CODE (operands[0]) == MEM
4287 && GET_CODE (operands[1]) == MEM
4288 && mode == DImode
41543739
GK
4289 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
4290 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
4291 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
4292 ? 32 : MEM_ALIGN (operands[0])))
4293 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
f676971a 4294 ? 32
41543739
GK
4295 : MEM_ALIGN (operands[1]))))
4296 && ! MEM_VOLATILE_P (operands [0])
4297 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 4298 {
41543739
GK
4299 emit_move_insn (adjust_address (operands[0], SImode, 0),
4300 adjust_address (operands[1], SImode, 0));
4301 emit_move_insn (adjust_address (operands[0], SImode, 4),
4302 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
4303 return;
4304 }
630d42a0 4305
c9dbf840
DE
4306 if (!no_new_pseudos && GET_CODE (operands[0]) != REG
4307 && !gpc_reg_operand (operands[1], mode))
f6219a5e 4308 operands[1] = force_reg (mode, operands[1]);
a9098fd0 4309
a3170dc6
AH
4310 if (mode == SFmode && ! TARGET_POWERPC
4311 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 4312 && GET_CODE (operands[0]) == MEM)
fb4d4348 4313 {
ffc14f31
GK
4314 int regnum;
4315
4316 if (reload_in_progress || reload_completed)
4317 regnum = true_regnum (operands[1]);
4318 else if (GET_CODE (operands[1]) == REG)
4319 regnum = REGNO (operands[1]);
4320 else
4321 regnum = -1;
f676971a 4322
fb4d4348
GK
4323 /* If operands[1] is a register, on POWER it may have
4324 double-precision data in it, so truncate it to single
4325 precision. */
4326 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
4327 {
4328 rtx newreg;
4329 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
4330 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
4331 operands[1] = newreg;
4332 }
4333 }
4334
c4501e62
JJ
4335 /* Recognize the case where operand[1] is a reference to thread-local
4336 data and load its address to a register. */
4337 if (GET_CODE (operands[1]) == SYMBOL_REF)
4338 {
4339 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
4340 if (model != 0)
4341 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
4342 }
4343
8f4e6caf
RH
4344 /* Handle the case where reload calls us with an invalid address. */
4345 if (reload_in_progress && mode == Pmode
69ef87e2 4346 && (! general_operand (operands[1], mode)
8f4e6caf
RH
4347 || ! nonimmediate_operand (operands[0], mode)))
4348 goto emit_set;
4349
a9baceb1
GK
4350 /* 128-bit constant floating-point values on Darwin should really be
4351 loaded as two parts. */
4352 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
4353 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
4354 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
4355 {
4356 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
4357 know how to get a DFmode SUBREG of a TFmode. */
4358 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
4359 simplify_gen_subreg (DImode, operands[1], mode, 0),
4360 DImode);
4361 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
4362 GET_MODE_SIZE (DImode)),
4363 simplify_gen_subreg (DImode, operands[1], mode,
4364 GET_MODE_SIZE (DImode)),
4365 DImode);
4366 return;
4367 }
4368
fb4d4348
GK
4369 /* FIXME: In the long term, this switch statement should go away
4370 and be replaced by a sequence of tests based on things like
4371 mode == Pmode. */
4372 switch (mode)
4373 {
4374 case HImode:
4375 case QImode:
4376 if (CONSTANT_P (operands[1])
4377 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 4378 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
4379 break;
4380
06f4e019 4381 case TFmode:
76d2b81d
DJ
4382 rs6000_eliminate_indexed_memrefs (operands);
4383 /* fall through */
4384
fb4d4348
GK
4385 case DFmode:
4386 case SFmode:
f676971a 4387 if (CONSTANT_P (operands[1])
fb4d4348 4388 && ! easy_fp_constant (operands[1], mode))
a9098fd0 4389 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4390 break;
f676971a 4391
0ac081f6
AH
4392 case V16QImode:
4393 case V8HImode:
4394 case V4SFmode:
4395 case V4SImode:
a3170dc6
AH
4396 case V4HImode:
4397 case V2SFmode:
4398 case V2SImode:
00a892b8 4399 case V1DImode:
69ef87e2 4400 if (CONSTANT_P (operands[1])
d744e06e 4401 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
4402 operands[1] = force_const_mem (mode, operands[1]);
4403 break;
f676971a 4404
fb4d4348 4405 case SImode:
a9098fd0 4406 case DImode:
fb4d4348
GK
4407 /* Use default pattern for address of ELF small data */
4408 if (TARGET_ELF
a9098fd0 4409 && mode == Pmode
f607bc57 4410 && DEFAULT_ABI == ABI_V4
f676971a 4411 && (GET_CODE (operands[1]) == SYMBOL_REF
a9098fd0
GK
4412 || GET_CODE (operands[1]) == CONST)
4413 && small_data_operand (operands[1], mode))
fb4d4348
GK
4414 {
4415 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4416 return;
4417 }
4418
f607bc57 4419 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
4420 && mode == Pmode && mode == SImode
4421 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
4422 {
4423 emit_insn (gen_movsi_got (operands[0], operands[1]));
4424 return;
4425 }
4426
ee890fe2 4427 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
4428 && TARGET_NO_TOC
4429 && ! flag_pic
a9098fd0 4430 && mode == Pmode
fb4d4348
GK
4431 && CONSTANT_P (operands[1])
4432 && GET_CODE (operands[1]) != HIGH
4433 && GET_CODE (operands[1]) != CONST_INT)
4434 {
a9098fd0 4435 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
4436
4437 /* If this is a function address on -mcall-aixdesc,
4438 convert it to the address of the descriptor. */
4439 if (DEFAULT_ABI == ABI_AIX
4440 && GET_CODE (operands[1]) == SYMBOL_REF
4441 && XSTR (operands[1], 0)[0] == '.')
4442 {
4443 const char *name = XSTR (operands[1], 0);
4444 rtx new_ref;
4445 while (*name == '.')
4446 name++;
4447 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
4448 CONSTANT_POOL_ADDRESS_P (new_ref)
4449 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 4450 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 4451 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 4452 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
4453 operands[1] = new_ref;
4454 }
7509c759 4455
ee890fe2
SS
4456 if (DEFAULT_ABI == ABI_DARWIN)
4457 {
ab82a49f
AP
4458#if TARGET_MACHO
4459 if (MACHO_DYNAMIC_NO_PIC_P)
4460 {
4461 /* Take care of any required data indirection. */
4462 operands[1] = rs6000_machopic_legitimize_pic_address (
4463 operands[1], mode, operands[0]);
4464 if (operands[0] != operands[1])
4465 emit_insn (gen_rtx_SET (VOIDmode,
c4ad648e 4466 operands[0], operands[1]));
ab82a49f
AP
4467 return;
4468 }
4469#endif
b8a55285
AP
4470 emit_insn (gen_macho_high (target, operands[1]));
4471 emit_insn (gen_macho_low (operands[0], target, operands[1]));
ee890fe2
SS
4472 return;
4473 }
4474
fb4d4348
GK
4475 emit_insn (gen_elf_high (target, operands[1]));
4476 emit_insn (gen_elf_low (operands[0], target, operands[1]));
4477 return;
4478 }
4479
a9098fd0
GK
4480 /* If this is a SYMBOL_REF that refers to a constant pool entry,
4481 and we have put it in the TOC, we just need to make a TOC-relative
4482 reference to it. */
4483 if (TARGET_TOC
4484 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 4485 && constant_pool_expr_p (operands[1])
a9098fd0
GK
4486 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
4487 get_pool_mode (operands[1])))
fb4d4348 4488 {
a9098fd0 4489 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 4490 }
a9098fd0
GK
4491 else if (mode == Pmode
4492 && CONSTANT_P (operands[1])
38886f37
AO
4493 && ((GET_CODE (operands[1]) != CONST_INT
4494 && ! easy_fp_constant (operands[1], mode))
4495 || (GET_CODE (operands[1]) == CONST_INT
4496 && num_insns_constant (operands[1], mode) > 2)
4497 || (GET_CODE (operands[0]) == REG
4498 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 4499 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
4500 && ! legitimate_constant_pool_address_p (operands[1])
4501 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
4502 {
4503 /* Emit a USE operation so that the constant isn't deleted if
4504 expensive optimizations are turned on because nobody
4505 references it. This should only be done for operands that
4506 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
4507 This should not be done for operands that contain LABEL_REFs.
4508 For now, we just handle the obvious case. */
4509 if (GET_CODE (operands[1]) != LABEL_REF)
4510 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
4511
c859cda6 4512#if TARGET_MACHO
ee890fe2 4513 /* Darwin uses a special PIC legitimizer. */
ab82a49f 4514 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 4515 {
ee890fe2
SS
4516 operands[1] =
4517 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
4518 operands[0]);
4519 if (operands[0] != operands[1])
4520 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
4521 return;
4522 }
c859cda6 4523#endif
ee890fe2 4524
fb4d4348
GK
4525 /* If we are to limit the number of things we put in the TOC and
4526 this is a symbol plus a constant we can add in one insn,
4527 just put the symbol in the TOC and add the constant. Don't do
4528 this if reload is in progress. */
4529 if (GET_CODE (operands[1]) == CONST
4530 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
4531 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 4532 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
4533 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
4534 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
4535 && ! side_effects_p (operands[0]))
4536 {
a4f6c312
SS
4537 rtx sym =
4538 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
4539 rtx other = XEXP (XEXP (operands[1], 0), 1);
4540
a9098fd0
GK
4541 sym = force_reg (mode, sym);
4542 if (mode == SImode)
4543 emit_insn (gen_addsi3 (operands[0], sym, other));
4544 else
4545 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
4546 return;
4547 }
4548
a9098fd0 4549 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4550
f676971a 4551 if (TARGET_TOC
4d588c14 4552 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
4553 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
4554 get_pool_constant (XEXP (operands[1], 0)),
4555 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 4556 {
ba4828e0 4557 operands[1]
542a8afa 4558 = gen_const_mem (mode,
c4ad648e 4559 create_TOC_reference (XEXP (operands[1], 0)));
ba4828e0 4560 set_mem_alias_set (operands[1], get_TOC_alias_set ());
a9098fd0 4561 }
fb4d4348
GK
4562 }
4563 break;
a9098fd0 4564
fb4d4348 4565 case TImode:
76d2b81d
DJ
4566 rs6000_eliminate_indexed_memrefs (operands);
4567
27dc0551
DE
4568 if (TARGET_POWER)
4569 {
4570 emit_insn (gen_rtx_PARALLEL (VOIDmode,
4571 gen_rtvec (2,
4572 gen_rtx_SET (VOIDmode,
4573 operands[0], operands[1]),
4574 gen_rtx_CLOBBER (VOIDmode,
4575 gen_rtx_SCRATCH (SImode)))));
4576 return;
4577 }
fb4d4348
GK
4578 break;
4579
4580 default:
4581 abort ();
4582 }
4583
a9098fd0
GK
4584 /* Above, we may have called force_const_mem which may have returned
4585 an invalid address. If we can, fix this up; otherwise, reload will
4586 have to deal with it. */
8f4e6caf
RH
4587 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
4588 operands[1] = validize_mem (operands[1]);
a9098fd0 4589
8f4e6caf 4590 emit_set:
fb4d4348
GK
4591 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4592}
4697a36c 4593\f
2858f73a
GK
4594/* Nonzero if we can use a floating-point register to pass this arg. */
4595#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
4596 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
4597 && (CUM)->fregno <= FP_ARG_MAX_REG \
4598 && TARGET_HARD_FLOAT && TARGET_FPRS)
4599
4600/* Nonzero if we can use an AltiVec register to pass this arg. */
4601#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
4602 (ALTIVEC_VECTOR_MODE (MODE) \
4603 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
4604 && TARGET_ALTIVEC_ABI \
83953138 4605 && (NAMED))
2858f73a 4606
c6e8c921
GK
4607/* Return a nonzero value to say to return the function value in
4608 memory, just as large structures are always returned. TYPE will be
4609 the data type of the value, and FNTYPE will be the type of the
4610 function doing the returning, or @code{NULL} for libcalls.
4611
4612 The AIX ABI for the RS/6000 specifies that all structures are
4613 returned in memory. The Darwin ABI does the same. The SVR4 ABI
4614 specifies that structures <= 8 bytes are returned in r3/r4, but a
4615 draft put them in memory, and GCC used to implement the draft
4616 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
4617 controls this instead of DEFAULT_ABI; V.4 targets needing backward
4618 compatibility can change DRAFT_V4_STRUCT_RET to override the
4619 default, and -m switches get the final word. See
4620 rs6000_override_options for more details.
4621
4622 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
4623 long double support is enabled. These values are returned in memory.
4624
4625 int_size_in_bytes returns -1 for variable size objects, which go in
4626 memory always. The cast to unsigned makes -1 > 8. */
4627
4628static bool
4629rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4630{
594a51fe
SS
4631 /* In the darwin64 abi, try to use registers for larger structs
4632 if possible. */
4633 if (AGGREGATE_TYPE_P (type)
4634 && rs6000_darwin64_abi
4635 && TREE_CODE (type) == RECORD_TYPE
4636 && ((unsigned HOST_WIDE_INT) int_size_in_bytes (type) <= 32)
4637 && ((unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 0))
4638 return false;
4639
c6e8c921
GK
4640 if (AGGREGATE_TYPE_P (type)
4641 && (TARGET_AIX_STRUCT_RET
4642 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
4643 return true;
b693336b 4644
bada2eb8
DE
4645 /* Allow -maltivec -mabi=no-altivec without warning. Altivec vector
4646 modes only exist for GCC vector types if -maltivec. */
4647 if (TARGET_32BIT && !TARGET_ALTIVEC_ABI
4648 && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
4649 return false;
4650
b693336b
PB
4651 /* Return synthetic vectors in memory. */
4652 if (TREE_CODE (type) == VECTOR_TYPE
ad630bef 4653 && int_size_in_bytes (type) > (TARGET_ALTIVEC_ABI ? 16 : 8))
b693336b
PB
4654 {
4655 static bool warned_for_return_big_vectors = false;
4656 if (!warned_for_return_big_vectors)
4657 {
bada2eb8 4658 warning ("GCC vector returned by reference: "
b693336b
PB
4659 "non-standard ABI extension with no compatibility guarantee");
4660 warned_for_return_big_vectors = true;
4661 }
4662 return true;
4663 }
4664
c6e8c921
GK
4665 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
4666 return true;
ad630bef 4667
c6e8c921
GK
4668 return false;
4669}
4670
4697a36c
MM
4671/* Initialize a variable CUM of type CUMULATIVE_ARGS
4672 for a call to a function whose data type is FNTYPE.
4673 For a library call, FNTYPE is 0.
4674
4675 For incoming args we set the number of arguments in the prototype large
1c20ae99 4676 so we never return a PARALLEL. */
4697a36c
MM
4677
4678void
f676971a 4679init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
4680 rtx libname ATTRIBUTE_UNUSED, int incoming,
4681 int libcall, int n_named_args)
4697a36c
MM
4682{
4683 static CUMULATIVE_ARGS zero_cumulative;
4684
4685 *cum = zero_cumulative;
4686 cum->words = 0;
4687 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 4688 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 4689 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
4690 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
4691 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 4692 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
4693 cum->stdarg = fntype
4694 && (TYPE_ARG_TYPES (fntype) != 0
4695 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4696 != void_type_node));
4697a36c 4697
0f6937fe
AM
4698 cum->nargs_prototype = 0;
4699 if (incoming || cum->prototype)
4700 cum->nargs_prototype = n_named_args;
4697a36c 4701
a5c76ee6 4702 /* Check for a longcall attribute. */
3eb4e360
AM
4703 if ((!fntype && rs6000_default_long_calls)
4704 || (fntype
4705 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
4706 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype))))
4707 cum->call_cookie |= CALL_LONG;
6a4cee5f 4708
4697a36c
MM
4709 if (TARGET_DEBUG_ARG)
4710 {
4711 fprintf (stderr, "\ninit_cumulative_args:");
4712 if (fntype)
4713 {
4714 tree ret_type = TREE_TYPE (fntype);
4715 fprintf (stderr, " ret code = %s,",
4716 tree_code_name[ (int)TREE_CODE (ret_type) ]);
4717 }
4718
6a4cee5f
MM
4719 if (cum->call_cookie & CALL_LONG)
4720 fprintf (stderr, " longcall,");
4721
4697a36c
MM
4722 fprintf (stderr, " proto = %d, nargs = %d\n",
4723 cum->prototype, cum->nargs_prototype);
4724 }
f676971a 4725
c4ad648e
AM
4726 if (fntype
4727 && !TARGET_ALTIVEC
4728 && TARGET_ALTIVEC_ABI
4729 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
4730 {
4731 error ("Cannot return value in vector register because"
4732 " altivec instructions are disabled, use -maltivec"
4733 " to enable them.");
4734 }
4697a36c
MM
4735}
4736\f
fe984136
RH
4737/* Return true if TYPE must be passed on the stack and not in registers. */
4738
4739static bool
4740rs6000_must_pass_in_stack (enum machine_mode mode, tree type)
4741{
4742 if (DEFAULT_ABI == ABI_AIX || TARGET_64BIT)
4743 return must_pass_in_stack_var_size (mode, type);
4744 else
4745 return must_pass_in_stack_var_size_or_pad (mode, type);
4746}
4747
c229cba9
DE
4748/* If defined, a C expression which determines whether, and in which
4749 direction, to pad out an argument with extra space. The value
4750 should be of type `enum direction': either `upward' to pad above
4751 the argument, `downward' to pad below, or `none' to inhibit
4752 padding.
4753
4754 For the AIX ABI structs are always stored left shifted in their
4755 argument slot. */
4756
9ebbca7d 4757enum direction
a2369ed3 4758function_arg_padding (enum machine_mode mode, tree type)
c229cba9 4759{
6e985040
AM
4760#ifndef AGGREGATE_PADDING_FIXED
4761#define AGGREGATE_PADDING_FIXED 0
4762#endif
4763#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
4764#define AGGREGATES_PAD_UPWARD_ALWAYS 0
4765#endif
4766
4767 if (!AGGREGATE_PADDING_FIXED)
4768 {
4769 /* GCC used to pass structures of the same size as integer types as
4770 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
19525b57 4771 i.e. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
6e985040
AM
4772 passed padded downward, except that -mstrict-align further
4773 muddied the water in that multi-component structures of 2 and 4
4774 bytes in size were passed padded upward.
4775
4776 The following arranges for best compatibility with previous
4777 versions of gcc, but removes the -mstrict-align dependency. */
4778 if (BYTES_BIG_ENDIAN)
4779 {
4780 HOST_WIDE_INT size = 0;
4781
4782 if (mode == BLKmode)
4783 {
4784 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4785 size = int_size_in_bytes (type);
4786 }
4787 else
4788 size = GET_MODE_SIZE (mode);
4789
4790 if (size == 1 || size == 2 || size == 4)
4791 return downward;
4792 }
4793 return upward;
4794 }
4795
4796 if (AGGREGATES_PAD_UPWARD_ALWAYS)
4797 {
4798 if (type != 0 && AGGREGATE_TYPE_P (type))
4799 return upward;
4800 }
c229cba9 4801
d3704c46
KH
4802 /* Fall back to the default. */
4803 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
4804}
4805
b6c9286a 4806/* If defined, a C expression that gives the alignment boundary, in bits,
f676971a 4807 of an argument with the specified mode and type. If it is not defined,
b6c9286a 4808 PARM_BOUNDARY is used for all arguments.
f676971a 4809
b693336b
PB
4810 V.4 wants long longs to be double word aligned.
4811 Doubleword align SPE vectors.
4812 Quadword align Altivec vectors.
4813 Quadword align large synthetic vector types. */
b6c9286a
MM
4814
4815int
b693336b 4816function_arg_boundary (enum machine_mode mode, tree type)
b6c9286a 4817{
4ed78545
AM
4818 if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8)
4819 return 64;
ad630bef
DE
4820 else if (SPE_VECTOR_MODE (mode)
4821 || (type && TREE_CODE (type) == VECTOR_TYPE
4822 && int_size_in_bytes (type) >= 8
4823 && int_size_in_bytes (type) < 16))
e1f83b4d 4824 return 64;
ad630bef
DE
4825 else if (ALTIVEC_VECTOR_MODE (mode)
4826 || (type && TREE_CODE (type) == VECTOR_TYPE
4827 && int_size_in_bytes (type) >= 16))
0ac081f6 4828 return 128;
9ebbca7d 4829 else
b6c9286a 4830 return PARM_BOUNDARY;
b6c9286a 4831}
c53bdcf5
AM
4832
4833/* Compute the size (in words) of a function argument. */
4834
4835static unsigned long
4836rs6000_arg_size (enum machine_mode mode, tree type)
4837{
4838 unsigned long size;
4839
4840 if (mode != BLKmode)
4841 size = GET_MODE_SIZE (mode);
4842 else
4843 size = int_size_in_bytes (type);
4844
4845 if (TARGET_32BIT)
4846 return (size + 3) >> 2;
4847 else
4848 return (size + 7) >> 3;
4849}
b6c9286a 4850\f
594a51fe
SS
4851/* The darwin64 ABI calls for us to recurse down through structs,
4852 applying the same rules to struct elements as if a reference to
4853 each were being passed directly. */
4854
4855static void
4856darwin64_function_arg_advance (CUMULATIVE_ARGS *cum, tree type,
4857 int named, int depth)
4858{
4859 tree f, ftype;
4860 int i, tot;
4861
4862 switch (TREE_CODE (type))
4863 {
4864 case RECORD_TYPE:
4865 for (f = TYPE_FIELDS (type); f ; f = TREE_CHAIN (f))
4866 if (TREE_CODE (f) == FIELD_DECL)
4867 {
4868 ftype = TREE_TYPE (f);
4869 function_arg_advance (cum, TYPE_MODE (ftype), ftype,
4870 named, depth + 1);
4871 }
4872 break;
4873
4874 case ARRAY_TYPE:
4875 tot = int_size_in_bytes (type);
4876 if (tot <= 0)
4877 return;
4878 ftype = TREE_TYPE (type);
4879 tot /= int_size_in_bytes (ftype);
4880
4881 for (i = 0; i < tot; ++i)
4882 {
4883 function_arg_advance (cum, TYPE_MODE (ftype), ftype,
4884 named, depth + 1);
4885 }
4886 break;
4887
4888 default:
4889 abort ();
4890 }
4891}
4892
4697a36c
MM
4893/* Update the data in CUM to advance over an argument
4894 of mode MODE and data type TYPE.
b2d04ecf
AM
4895 (TYPE is null for libcalls where that information may not be available.)
4896
4897 Note that for args passed by reference, function_arg will be called
4898 with MODE and TYPE set to that of the pointer to the arg, not the arg
4899 itself. */
4697a36c
MM
4900
4901void
f676971a 4902function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
594a51fe 4903 tree type, int named, int depth)
4697a36c 4904{
594a51fe
SS
4905 /* Only tick off an argument if we're not recursing. */
4906 if (depth == 0)
4907 cum->nargs_prototype--;
4697a36c 4908
ad630bef
DE
4909 if (TARGET_ALTIVEC_ABI
4910 && (ALTIVEC_VECTOR_MODE (mode)
4911 || (type && TREE_CODE (type) == VECTOR_TYPE
4912 && int_size_in_bytes (type) == 16)))
0ac081f6 4913 {
4ed78545
AM
4914 bool stack = false;
4915
2858f73a 4916 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c4ad648e 4917 {
6d0ef01e
HP
4918 cum->vregno++;
4919 if (!TARGET_ALTIVEC)
4920 error ("Cannot pass argument in vector register because"
4921 " altivec instructions are disabled, use -maltivec"
4922 " to enable them.");
4ed78545
AM
4923
4924 /* PowerPC64 Linux and AIX allocate GPRs for a vector argument
f676971a 4925 even if it is going to be passed in a vector register.
4ed78545
AM
4926 Darwin does the same for variable-argument functions. */
4927 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4928 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4929 stack = true;
6d0ef01e 4930 }
4ed78545
AM
4931 else
4932 stack = true;
4933
4934 if (stack)
c4ad648e 4935 {
a594a19c 4936 int align;
f676971a 4937
2858f73a
GK
4938 /* Vector parameters must be 16-byte aligned. This places
4939 them at 2 mod 4 in terms of words in 32-bit mode, since
4940 the parameter save area starts at offset 24 from the
4941 stack. In 64-bit mode, they just have to start on an
4942 even word, since the parameter save area is 16-byte
4943 aligned. Space for GPRs is reserved even if the argument
4944 will be passed in memory. */
4945 if (TARGET_32BIT)
4ed78545 4946 align = (2 - cum->words) & 3;
2858f73a
GK
4947 else
4948 align = cum->words & 1;
c53bdcf5 4949 cum->words += align + rs6000_arg_size (mode, type);
f676971a 4950
a594a19c
GK
4951 if (TARGET_DEBUG_ARG)
4952 {
f676971a 4953 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
a594a19c
GK
4954 cum->words, align);
4955 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
f676971a 4956 cum->nargs_prototype, cum->prototype,
2858f73a 4957 GET_MODE_NAME (mode));
a594a19c
GK
4958 }
4959 }
0ac081f6 4960 }
a4b0320c 4961 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4962 && !cum->stdarg
4963 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4964 cum->sysv_gregno++;
594a51fe
SS
4965
4966 else if (rs6000_darwin64_abi
4967 && mode == BLKmode
4968 && (TREE_CODE (type) == RECORD_TYPE
4969 || TREE_CODE (type) == ARRAY_TYPE))
4970 darwin64_function_arg_advance (cum, type, named, depth);
4971
f607bc57 4972 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4973 {
a3170dc6 4974 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4975 && (mode == SFmode || mode == DFmode))
4697a36c 4976 {
4cc833b7
RH
4977 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4978 cum->fregno++;
4979 else
4980 {
4981 if (mode == DFmode)
c4ad648e 4982 cum->words += cum->words & 1;
c53bdcf5 4983 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4984 }
4697a36c 4985 }
4cc833b7
RH
4986 else
4987 {
b2d04ecf 4988 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4989 int gregno = cum->sysv_gregno;
4990
4ed78545
AM
4991 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4992 (r7,r8) or (r9,r10). As does any other 2 word item such
4993 as complex int due to a historical mistake. */
4994 if (n_words == 2)
4995 gregno += (1 - gregno) & 1;
4cc833b7 4996
4ed78545 4997 /* Multi-reg args are not split between registers and stack. */
4cc833b7
RH
4998 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4999 {
4ed78545
AM
5000 /* Long long and SPE vectors are aligned on the stack.
5001 So are other 2 word items such as complex int due to
5002 a historical mistake. */
4cc833b7
RH
5003 if (n_words == 2)
5004 cum->words += cum->words & 1;
5005 cum->words += n_words;
5006 }
4697a36c 5007
4cc833b7
RH
5008 /* Note: continuing to accumulate gregno past when we've started
5009 spilling to the stack indicates the fact that we've started
5010 spilling to the stack to expand_builtin_saveregs. */
5011 cum->sysv_gregno = gregno + n_words;
5012 }
4697a36c 5013
4cc833b7
RH
5014 if (TARGET_DEBUG_ARG)
5015 {
5016 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
5017 cum->words, cum->fregno);
5018 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
5019 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
5020 fprintf (stderr, "mode = %4s, named = %d\n",
5021 GET_MODE_NAME (mode), named);
5022 }
4697a36c
MM
5023 }
5024 else
4cc833b7 5025 {
b2d04ecf
AM
5026 int n_words = rs6000_arg_size (mode, type);
5027 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
a4f6c312 5028
b2d04ecf
AM
5029 /* The simple alignment calculation here works because
5030 function_arg_boundary / PARM_BOUNDARY will only be 1 or 2.
5031 If we ever want to handle alignments larger than 8 bytes for
5032 32-bit or 16 bytes for 64-bit, then we'll need to take into
5033 account the offset to the start of the parm save area. */
5034 align &= cum->words;
5035 cum->words += align + n_words;
4697a36c 5036
a3170dc6
AH
5037 if (GET_MODE_CLASS (mode) == MODE_FLOAT
5038 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 5039 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
5040
5041 if (TARGET_DEBUG_ARG)
5042 {
5043 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
5044 cum->words, cum->fregno);
5045 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
5046 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
594a51fe
SS
5047 fprintf (stderr, "named = %d, align = %d, depth = %d\n",
5048 named, align, depth);
4cc833b7
RH
5049 }
5050 }
4697a36c 5051}
a6c9bed4 5052
f82f556d
AH
5053static rtx
5054spe_build_register_parallel (enum machine_mode mode, int gregno)
5055{
18f63bfa
AH
5056 rtx r1, r2, r3, r4;
5057 enum machine_mode inner = SImode;
f82f556d
AH
5058
5059 if (mode == DFmode)
5060 {
18f63bfa
AH
5061 r1 = gen_rtx_REG (inner, gregno);
5062 r1 = gen_rtx_EXPR_LIST (SImode, r1, const0_rtx);
5063 r2 = gen_rtx_REG (inner, gregno + 1);
5064 r2 = gen_rtx_EXPR_LIST (SImode, r2, GEN_INT (4));
5065 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
5066 }
5067 else if (mode == DCmode)
5068 {
5069 r1 = gen_rtx_REG (inner, gregno);
5070 r1 = gen_rtx_EXPR_LIST (SImode, r1, const0_rtx);
5071 r2 = gen_rtx_REG (inner, gregno + 1);
5072 r2 = gen_rtx_EXPR_LIST (SImode, r2, GEN_INT (4));
5073 r3 = gen_rtx_REG (inner, gregno + 2);
5074 r3 = gen_rtx_EXPR_LIST (SImode, r3, GEN_INT (8));
5075 r4 = gen_rtx_REG (inner, gregno + 3);
5076 r4 = gen_rtx_EXPR_LIST (SImode, r4, GEN_INT (12));
5077 return gen_rtx_PARALLEL (mode, gen_rtvec (4, r1, r2, r3, r4));
f82f556d 5078 }
f82f556d 5079
18f63bfa
AH
5080 abort ();
5081 return NULL_RTX;
f82f556d 5082}
b78d48dd 5083
f82f556d 5084/* Determine where to put a SIMD argument on the SPE. */
a6c9bed4 5085static rtx
f676971a 5086rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 5087 tree type)
a6c9bed4 5088{
f82f556d
AH
5089 int gregno = cum->sysv_gregno;
5090
5091 /* On E500 v2, double arithmetic is done on the full 64-bit GPR, but
600e1f95 5092 are passed and returned in a pair of GPRs for ABI compatibility. */
18f63bfa 5093 if (TARGET_E500_DOUBLE && (mode == DFmode || mode == DCmode))
f82f556d
AH
5094 {
5095 /* Doubles go in an odd/even register pair (r5/r6, etc). */
5096 gregno += (1 - gregno) & 1;
5097
5098 /* We do not split between registers and stack. */
5099 if (gregno + 1 > GP_ARG_MAX_REG)
5100 return NULL_RTX;
5101
5102 return spe_build_register_parallel (mode, gregno);
5103 }
a6c9bed4
AH
5104 if (cum->stdarg)
5105 {
c53bdcf5 5106 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
5107
5108 /* SPE vectors are put in odd registers. */
5109 if (n_words == 2 && (gregno & 1) == 0)
5110 gregno += 1;
5111
5112 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
5113 {
5114 rtx r1, r2;
5115 enum machine_mode m = SImode;
5116
5117 r1 = gen_rtx_REG (m, gregno);
5118 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
5119 r2 = gen_rtx_REG (m, gregno + 1);
5120 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
5121 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
5122 }
5123 else
b78d48dd 5124 return NULL_RTX;
a6c9bed4
AH
5125 }
5126 else
5127 {
f82f556d
AH
5128 if (gregno <= GP_ARG_MAX_REG)
5129 return gen_rtx_REG (mode, gregno);
a6c9bed4 5130 else
b78d48dd 5131 return NULL_RTX;
a6c9bed4
AH
5132 }
5133}
5134
594a51fe
SS
5135/* For the darwin64 ABI, we want to construct a PARALLEL consisting of
5136 the register(s) to be used for each field and subfield of a struct
5137 being passed by value, along with the offset of where the
5138 register's value may be found in the block. */
5139
5140static rtx
5141rs6000_darwin64_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
5142 tree type, int named)
5143{
5144 tree f, ftype, offset;
5145 rtx rvec[FIRST_PSEUDO_REGISTER], sub, suboff, roffset;
5146 int k = 0, i, j, bytepos, subbytepos, tot;
5147 CUMULATIVE_ARGS saved_cum = *cum;
5148 enum machine_mode submode;
5149
5150 switch (TREE_CODE (type))
5151 {
5152 case RECORD_TYPE:
5153 for (f = TYPE_FIELDS (type); f ; f = TREE_CHAIN (f))
5154 if (TREE_CODE (f) == FIELD_DECL)
5155 {
5156 ftype = TREE_TYPE (f);
5157 offset = DECL_FIELD_OFFSET (f);
5158 bytepos = int_bit_position (f) / BITS_PER_UNIT;
5159 /* Force substructs to be handled as BLKmode even if
5160 they're small enough to be recorded as DImode, so we
5161 drill through to non-record fields. */
5162 submode = TYPE_MODE (ftype);
5163 if (TREE_CODE (ftype) == RECORD_TYPE)
5164 submode = BLKmode;
5165 sub = function_arg (cum, submode, ftype, named);
5166 if (sub == NULL_RTX)
5167 return NULL_RTX;
5168 if (GET_CODE (sub) == PARALLEL)
5169 {
5170 for (i = 0; i < XVECLEN (sub, 0); i++)
5171 {
5172 rtx subsub = XVECEXP (sub, 0, i);
5173 suboff = XEXP (subsub, 1);
5174 subbytepos = INTVAL (suboff);
5175 subbytepos += bytepos;
5176 roffset = gen_rtx_CONST_INT (SImode, subbytepos);
5177 subsub = XEXP (subsub, 0);
5178 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, subsub, roffset);
5179 }
5180 }
5181 else
5182 {
5183 roffset = gen_rtx_CONST_INT (SImode, bytepos);
5184 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, sub, roffset);
5185 }
5186 /* Now do an arg advance to get all the cumulative arg
5187 stuff set correctly for the next subfield. Note that it
5188 has no lasting effect, because it is being done on a
5189 temporary copy of the cumulative arg data. */
5190 function_arg_advance (cum, submode, ftype, named, 1);
5191 }
5192 break;
5193
8ff40a74
SS
5194 case UNION_TYPE:
5195 tot = rs6000_arg_size (mode, type);
5196 if (tot <= 0)
5197 return NULL_RTX;
5198 bytepos = 0;
5199
5200 for (j = 0; j < tot; ++j)
5201 {
5202 sub = gen_rtx_REG ((TARGET_64BIT ? DImode : SImode), GP_ARG_MIN_REG + cum->words++);
5203 roffset = gen_rtx_CONST_INT (SImode, bytepos);
5204 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, sub, roffset);
5205 if (cum->words >= GP_ARG_NUM_REG)
5206 break;
5207 bytepos += (TARGET_64BIT ? 8 : 4);
5208 }
5209 break;
5210
594a51fe
SS
5211 case ARRAY_TYPE:
5212 tot = int_size_in_bytes (type);
5213 if (tot <= 0)
5214 return NULL_RTX;
5215 ftype = TREE_TYPE (type);
5216 tot /= int_size_in_bytes (ftype);
5217 bytepos = 0;
5218
5219 for (j = 0; j < tot; ++j)
5220 {
5221 /* Force substructs to be handled as BLKmode even if
5222 they're small enough to be recorded as DImode, so we
5223 drill through to non-record fields. */
5224 submode = TYPE_MODE (ftype);
5225 if (TREE_CODE (ftype) == RECORD_TYPE)
5226 submode = BLKmode;
5227 sub = function_arg (cum, submode, ftype, named);
5228 if (sub == NULL_RTX)
5229 return NULL_RTX;
5230 if (GET_CODE (sub) == PARALLEL)
5231 {
5232 for (i = 0; i < XVECLEN (sub, 0); i++)
5233 {
5234 rtx subsub = XVECEXP (sub, 0, i);
5235
5236 suboff = XEXP (subsub, 1);
5237 subbytepos = INTVAL (suboff);
5238 subbytepos += bytepos;
5239 roffset = gen_rtx_CONST_INT (SImode, subbytepos);
5240 subsub = XEXP (subsub, 0);
5241 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, subsub, roffset);
5242 }
5243 }
5244 else
5245 {
5246 roffset = gen_rtx_CONST_INT (SImode, bytepos);
5247 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, sub, roffset);
5248 }
5249 /* Now do an arg advance to get all the cumulative arg
5250 stuff set correctly for the next subfield. Note that it
5251 has no lasting effect, because it is being done on a
5252 temporary copy of the cumulative arg data. */
5253 function_arg_advance (cum, submode, ftype, named, 1);
5254 bytepos += int_size_in_bytes (ftype);
5255 }
5256 break;
5257
5258 default:
5259 abort ();
5260 }
5261
5262 *cum = saved_cum;
5263 if (k > 0)
5264 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
5265 else
5266 return NULL_RTX;
5267}
5268
b78d48dd
FJ
5269/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
5270
5271static rtx
ec6376ab 5272rs6000_mixed_function_arg (enum machine_mode mode, tree type, int align_words)
b78d48dd 5273{
ec6376ab
AM
5274 int n_units;
5275 int i, k;
5276 rtx rvec[GP_ARG_NUM_REG + 1];
5277
5278 if (align_words >= GP_ARG_NUM_REG)
5279 return NULL_RTX;
5280
5281 n_units = rs6000_arg_size (mode, type);
5282
5283 /* Optimize the simple case where the arg fits in one gpr, except in
5284 the case of BLKmode due to assign_parms assuming that registers are
5285 BITS_PER_WORD wide. */
5286 if (n_units == 0
5287 || (n_units == 1 && mode != BLKmode))
5288 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5289
5290 k = 0;
5291 if (align_words + n_units > GP_ARG_NUM_REG)
5292 /* Not all of the arg fits in gprs. Say that it goes in memory too,
5293 using a magic NULL_RTX component.
5294 FIXME: This is not strictly correct. Only some of the arg
5295 belongs in memory, not all of it. However, there isn't any way
5296 to do this currently, apart from building rtx descriptions for
5297 the pieces of memory we want stored. Due to bugs in the generic
5298 code we can't use the normal function_arg_partial_nregs scheme
5299 with the PARALLEL arg description we emit here.
5300 In any case, the code to store the whole arg to memory is often
5301 more efficient than code to store pieces, and we know that space
5302 is available in the right place for the whole arg. */
5303 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
5304
5305 i = 0;
5306 do
36a454e1 5307 {
ec6376ab
AM
5308 rtx r = gen_rtx_REG (SImode, GP_ARG_MIN_REG + align_words);
5309 rtx off = GEN_INT (i++ * 4);
5310 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
36a454e1 5311 }
ec6376ab
AM
5312 while (++align_words < GP_ARG_NUM_REG && --n_units != 0);
5313
5314 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
b78d48dd
FJ
5315}
5316
4697a36c
MM
5317/* Determine where to put an argument to a function.
5318 Value is zero to push the argument on the stack,
5319 or a hard register in which to store the argument.
5320
5321 MODE is the argument's machine mode.
5322 TYPE is the data type of the argument (as a tree).
5323 This is null for libcalls where that information may
5324 not be available.
5325 CUM is a variable of type CUMULATIVE_ARGS which gives info about
5326 the preceding args and about the function being called.
5327 NAMED is nonzero if this argument is a named parameter
5328 (otherwise it is an extra parameter matching an ellipsis).
5329
5330 On RS/6000 the first eight words of non-FP are normally in registers
5331 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
5332 Under V.4, the first 8 FP args are in registers.
5333
5334 If this is floating-point and no prototype is specified, we use
5335 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 5336 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 5337 so we can pass the FP value just in one register. emit_library_function
b2d04ecf
AM
5338 doesn't support PARALLEL anyway.
5339
5340 Note that for args passed by reference, function_arg will be called
5341 with MODE and TYPE set to that of the pointer to the arg, not the arg
5342 itself. */
4697a36c
MM
5343
5344struct rtx_def *
f676971a 5345function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 5346 tree type, int named)
4697a36c 5347{
4cc833b7 5348 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 5349
a4f6c312
SS
5350 /* Return a marker to indicate whether CR1 needs to set or clear the
5351 bit that V.4 uses to say fp args were passed in registers.
5352 Assume that we don't need the marker for software floating point,
5353 or compiler generated library calls. */
4697a36c
MM
5354 if (mode == VOIDmode)
5355 {
f607bc57 5356 if (abi == ABI_V4
7509c759 5357 && cum->nargs_prototype < 0
b9599e46
FS
5358 && (cum->call_cookie & CALL_LIBCALL) == 0
5359 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 5360 {
a3170dc6
AH
5361 /* For the SPE, we need to crxor CR6 always. */
5362 if (TARGET_SPE_ABI)
5363 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
5364 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
5365 return GEN_INT (cum->call_cookie
5366 | ((cum->fregno == FP_ARG_MIN_REG)
5367 ? CALL_V4_SET_FP_ARGS
5368 : CALL_V4_CLEAR_FP_ARGS));
7509c759 5369 }
4697a36c 5370
7509c759 5371 return GEN_INT (cum->call_cookie);
4697a36c
MM
5372 }
5373
8ff40a74
SS
5374 if (mode == BLKmode
5375 && rs6000_darwin64_abi
5376 && (TREE_CODE (type) == RECORD_TYPE
5377 || TREE_CODE (type) == UNION_TYPE
5378 || TREE_CODE (type) == ARRAY_TYPE))
5379 {
5380 rtx rslt = rs6000_darwin64_function_arg (cum, mode, type, named);
5381 if (rslt != NULL_RTX)
5382 return rslt;
5383 /* Else fall through to usual handling. */
5384 }
5385
2858f73a 5386 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
5387 if (TARGET_64BIT && ! cum->prototype)
5388 {
c4ad648e
AM
5389 /* Vector parameters get passed in vector register
5390 and also in GPRs or memory, in absence of prototype. */
5391 int align_words;
5392 rtx slot;
5393 align_words = (cum->words + 1) & ~1;
5394
5395 if (align_words >= GP_ARG_NUM_REG)
5396 {
5397 slot = NULL_RTX;
5398 }
5399 else
5400 {
5401 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5402 }
5403 return gen_rtx_PARALLEL (mode,
5404 gen_rtvec (2,
5405 gen_rtx_EXPR_LIST (VOIDmode,
5406 slot, const0_rtx),
5407 gen_rtx_EXPR_LIST (VOIDmode,
5408 gen_rtx_REG (mode, cum->vregno),
5409 const0_rtx)));
c72d6c26
HP
5410 }
5411 else
5412 return gen_rtx_REG (mode, cum->vregno);
ad630bef
DE
5413 else if (TARGET_ALTIVEC_ABI
5414 && (ALTIVEC_VECTOR_MODE (mode)
5415 || (type && TREE_CODE (type) == VECTOR_TYPE
5416 && int_size_in_bytes (type) == 16)))
0ac081f6 5417 {
2858f73a 5418 if (named || abi == ABI_V4)
a594a19c 5419 return NULL_RTX;
0ac081f6 5420 else
a594a19c
GK
5421 {
5422 /* Vector parameters to varargs functions under AIX or Darwin
5423 get passed in memory and possibly also in GPRs. */
ec6376ab
AM
5424 int align, align_words, n_words;
5425 enum machine_mode part_mode;
a594a19c
GK
5426
5427 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
5428 2 mod 4 in terms of words in 32-bit mode, since the parameter
5429 save area starts at offset 24 from the stack. In 64-bit mode,
5430 they just have to start on an even word, since the parameter
5431 save area is 16-byte aligned. */
5432 if (TARGET_32BIT)
4ed78545 5433 align = (2 - cum->words) & 3;
2858f73a
GK
5434 else
5435 align = cum->words & 1;
a594a19c
GK
5436 align_words = cum->words + align;
5437
5438 /* Out of registers? Memory, then. */
5439 if (align_words >= GP_ARG_NUM_REG)
5440 return NULL_RTX;
ec6376ab
AM
5441
5442 if (TARGET_32BIT && TARGET_POWERPC64)
5443 return rs6000_mixed_function_arg (mode, type, align_words);
5444
2858f73a
GK
5445 /* The vector value goes in GPRs. Only the part of the
5446 value in GPRs is reported here. */
ec6376ab
AM
5447 part_mode = mode;
5448 n_words = rs6000_arg_size (mode, type);
5449 if (align_words + n_words > GP_ARG_NUM_REG)
839a4992 5450 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
5451 is either wholly in GPRs or half in GPRs and half not. */
5452 part_mode = DImode;
ec6376ab
AM
5453
5454 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 5455 }
0ac081f6 5456 }
f82f556d
AH
5457 else if (TARGET_SPE_ABI && TARGET_SPE
5458 && (SPE_VECTOR_MODE (mode)
18f63bfa
AH
5459 || (TARGET_E500_DOUBLE && (mode == DFmode
5460 || mode == DCmode))))
a6c9bed4 5461 return rs6000_spe_function_arg (cum, mode, type);
594a51fe 5462
f607bc57 5463 else if (abi == ABI_V4)
4697a36c 5464 {
a3170dc6 5465 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
5466 && (mode == SFmode || mode == DFmode))
5467 {
5468 if (cum->fregno <= FP_ARG_V4_MAX_REG)
5469 return gen_rtx_REG (mode, cum->fregno);
5470 else
b78d48dd 5471 return NULL_RTX;
4cc833b7
RH
5472 }
5473 else
5474 {
b2d04ecf 5475 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
5476 int gregno = cum->sysv_gregno;
5477
4ed78545
AM
5478 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
5479 (r7,r8) or (r9,r10). As does any other 2 word item such
5480 as complex int due to a historical mistake. */
5481 if (n_words == 2)
5482 gregno += (1 - gregno) & 1;
4cc833b7 5483
4ed78545 5484 /* Multi-reg args are not split between registers and stack. */
ec6376ab 5485 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
b78d48dd 5486 return NULL_RTX;
ec6376ab
AM
5487
5488 if (TARGET_32BIT && TARGET_POWERPC64)
5489 return rs6000_mixed_function_arg (mode, type,
5490 gregno - GP_ARG_MIN_REG);
5491 return gen_rtx_REG (mode, gregno);
4cc833b7 5492 }
4697a36c 5493 }
4cc833b7
RH
5494 else
5495 {
b2d04ecf
AM
5496 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5497 int align_words = cum->words + (cum->words & align);
b78d48dd 5498
2858f73a 5499 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 5500 {
ec6376ab
AM
5501 rtx rvec[GP_ARG_NUM_REG + 1];
5502 rtx r;
5503 int k;
c53bdcf5
AM
5504 bool needs_psave;
5505 enum machine_mode fmode = mode;
c53bdcf5
AM
5506 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
5507
5508 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
5509 {
c53bdcf5
AM
5510 /* Currently, we only ever need one reg here because complex
5511 doubles are split. */
ec6376ab 5512 if (cum->fregno != FP_ARG_MAX_REG || fmode != TFmode)
c53bdcf5 5513 abort ();
ec6376ab
AM
5514
5515 /* Long double split over regs and memory. */
5516 fmode = DFmode;
c53bdcf5 5517 }
c53bdcf5
AM
5518
5519 /* Do we also need to pass this arg in the parameter save
5520 area? */
5521 needs_psave = (type
5522 && (cum->nargs_prototype <= 0
5523 || (DEFAULT_ABI == ABI_AIX
5524 && TARGET_XL_CALL
5525 && align_words >= GP_ARG_NUM_REG)));
5526
5527 if (!needs_psave && mode == fmode)
ec6376ab 5528 return gen_rtx_REG (fmode, cum->fregno);
c53bdcf5 5529
ec6376ab 5530 k = 0;
c53bdcf5
AM
5531 if (needs_psave)
5532 {
ec6376ab 5533 /* Describe the part that goes in gprs or the stack.
c53bdcf5 5534 This piece must come first, before the fprs. */
c53bdcf5
AM
5535 if (align_words < GP_ARG_NUM_REG)
5536 {
5537 unsigned long n_words = rs6000_arg_size (mode, type);
ec6376ab
AM
5538
5539 if (align_words + n_words > GP_ARG_NUM_REG
5540 || (TARGET_32BIT && TARGET_POWERPC64))
5541 {
5542 /* If this is partially on the stack, then we only
5543 include the portion actually in registers here. */
5544 enum machine_mode rmode = TARGET_32BIT ? SImode : DImode;
5545 rtx off;
2e6c9641 5546 int i=0;
c4ad648e
AM
5547 if (align_words + n_words > GP_ARG_NUM_REG
5548 && (TARGET_32BIT && TARGET_POWERPC64))
5549 /* Not all of the arg fits in gprs. Say that it
5550 goes in memory too, using a magic NULL_RTX
5551 component. Also see comment in
5552 rs6000_mixed_function_arg for why the normal
5553 function_arg_partial_nregs scheme doesn't work
5554 in this case. */
5555 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX,
5556 const0_rtx);
ec6376ab
AM
5557 do
5558 {
5559 r = gen_rtx_REG (rmode,
5560 GP_ARG_MIN_REG + align_words);
2e6c9641 5561 off = GEN_INT (i++ * GET_MODE_SIZE (rmode));
ec6376ab
AM
5562 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
5563 }
5564 while (++align_words < GP_ARG_NUM_REG && --n_words != 0);
5565 }
5566 else
5567 {
5568 /* The whole arg fits in gprs. */
5569 r = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5570 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5571 }
c53bdcf5 5572 }
ec6376ab
AM
5573 else
5574 /* It's entirely in memory. */
5575 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
c53bdcf5
AM
5576 }
5577
ec6376ab
AM
5578 /* Describe where this piece goes in the fprs. */
5579 r = gen_rtx_REG (fmode, cum->fregno);
5580 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5581
5582 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
4cc833b7
RH
5583 }
5584 else if (align_words < GP_ARG_NUM_REG)
b2d04ecf 5585 {
ec6376ab
AM
5586 if (TARGET_32BIT && TARGET_POWERPC64)
5587 return rs6000_mixed_function_arg (mode, type, align_words);
b2d04ecf 5588
4eeca74f
AM
5589 if (mode == BLKmode)
5590 mode = Pmode;
5591
b2d04ecf
AM
5592 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5593 }
4cc833b7
RH
5594 else
5595 return NULL_RTX;
4697a36c 5596 }
4697a36c
MM
5597}
5598\f
ec6376ab
AM
5599/* For an arg passed partly in registers and partly in memory, this is
5600 the number of registers used. For args passed entirely in registers
5601 or entirely in memory, zero. When an arg is described by a PARALLEL,
5602 perhaps using more than one register type, this function returns the
5603 number of registers used by the first element of the PARALLEL. */
4697a36c
MM
5604
5605int
f676971a 5606function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 5607 tree type, int named)
4697a36c 5608{
c53bdcf5 5609 int ret = 0;
ec6376ab
AM
5610 int align;
5611 int parm_offset;
5612 int align_words;
c53bdcf5 5613
f607bc57 5614 if (DEFAULT_ABI == ABI_V4)
4697a36c 5615 return 0;
4697a36c 5616
c53bdcf5
AM
5617 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
5618 && cum->nargs_prototype >= 0)
5619 return 0;
5620
ec6376ab
AM
5621 align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5622 parm_offset = TARGET_32BIT ? 2 : 0;
5623 align_words = cum->words + ((parm_offset - cum->words) & align);
5624
5625 if (USE_FP_FOR_ARG_P (cum, mode, type)
5626 /* If we are passing this arg in gprs as well, then this function
5627 should return the number of gprs (or memory) partially passed,
5628 *not* the number of fprs. */
5629 && !(type
5630 && (cum->nargs_prototype <= 0
5631 || (DEFAULT_ABI == ABI_AIX
5632 && TARGET_XL_CALL
5633 && align_words >= GP_ARG_NUM_REG))))
4697a36c 5634 {
c53bdcf5 5635 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
ec6376ab 5636 ret = FP_ARG_MAX_REG + 1 - cum->fregno;
c53bdcf5 5637 else if (cum->nargs_prototype >= 0)
4697a36c
MM
5638 return 0;
5639 }
5640
ec6376ab
AM
5641 if (align_words < GP_ARG_NUM_REG
5642 && GP_ARG_NUM_REG < align_words + rs6000_arg_size (mode, type))
5643 ret = GP_ARG_NUM_REG - align_words;
4697a36c 5644
c53bdcf5
AM
5645 if (ret != 0 && TARGET_DEBUG_ARG)
5646 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 5647
c53bdcf5 5648 return ret;
4697a36c
MM
5649}
5650\f
5651/* A C expression that indicates when an argument must be passed by
5652 reference. If nonzero for an argument, a copy of that argument is
5653 made in memory and a pointer to the argument is passed instead of
5654 the argument itself. The pointer is passed in whatever way is
5655 appropriate for passing a pointer to that type.
5656
b2d04ecf
AM
5657 Under V.4, aggregates and long double are passed by reference.
5658
5659 As an extension to all 32-bit ABIs, AltiVec vectors are passed by
5660 reference unless the AltiVec vector extension ABI is in force.
c8c99a68
DE
5661
5662 As an extension to all ABIs, variable sized types are passed by
5663 reference. */
4697a36c 5664
8cd5a4e0 5665static bool
f676971a 5666rs6000_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
bada2eb8
DE
5667 enum machine_mode mode, tree type,
5668 bool named ATTRIBUTE_UNUSED)
4697a36c 5669{
bada2eb8 5670 if (DEFAULT_ABI == ABI_V4 && mode == TFmode)
4697a36c
MM
5671 {
5672 if (TARGET_DEBUG_ARG)
bada2eb8
DE
5673 fprintf (stderr, "function_arg_pass_by_reference: V4 long double\n");
5674 return 1;
5675 }
5676
5677 if (!type)
5678 return 0;
4697a36c 5679
bada2eb8
DE
5680 if (DEFAULT_ABI == ABI_V4 && AGGREGATE_TYPE_P (type))
5681 {
5682 if (TARGET_DEBUG_ARG)
5683 fprintf (stderr, "function_arg_pass_by_reference: V4 aggregate\n");
5684 return 1;
5685 }
5686
5687 if (int_size_in_bytes (type) < 0)
5688 {
5689 if (TARGET_DEBUG_ARG)
5690 fprintf (stderr, "function_arg_pass_by_reference: variable size\n");
5691 return 1;
5692 }
5693
5694 /* Allow -maltivec -mabi=no-altivec without warning. Altivec vector
5695 modes only exist for GCC vector types if -maltivec. */
5696 if (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
5697 {
5698 if (TARGET_DEBUG_ARG)
5699 fprintf (stderr, "function_arg_pass_by_reference: AltiVec\n");
4697a36c
MM
5700 return 1;
5701 }
b693336b
PB
5702
5703 /* Pass synthetic vectors in memory. */
bada2eb8 5704 if (TREE_CODE (type) == VECTOR_TYPE
ad630bef 5705 && int_size_in_bytes (type) > (TARGET_ALTIVEC_ABI ? 16 : 8))
b693336b
PB
5706 {
5707 static bool warned_for_pass_big_vectors = false;
5708 if (TARGET_DEBUG_ARG)
5709 fprintf (stderr, "function_arg_pass_by_reference: synthetic vector\n");
5710 if (!warned_for_pass_big_vectors)
5711 {
bada2eb8 5712 warning ("GCC vector passed by reference: "
b693336b
PB
5713 "non-standard ABI extension with no compatibility guarantee");
5714 warned_for_pass_big_vectors = true;
5715 }
5716 return 1;
5717 }
5718
b2d04ecf 5719 return 0;
4697a36c 5720}
5985c7a6
FJ
5721
5722static void
2d9db8eb 5723rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
5724{
5725 int i;
5726 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
5727
5728 if (nregs == 0)
5729 return;
5730
c4ad648e 5731 for (i = 0; i < nregs; i++)
5985c7a6
FJ
5732 {
5733 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
5734 if (reload_completed)
c4ad648e
AM
5735 {
5736 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
5737 tem = NULL_RTX;
5738 else
5739 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
5740 i * GET_MODE_SIZE(reg_mode));
5741 }
5985c7a6
FJ
5742 else
5743 tem = replace_equiv_address (tem, XEXP (tem, 0));
5744
5745 if (tem == NULL_RTX)
c4ad648e 5746 abort ();
5985c7a6
FJ
5747
5748 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
5749 }
5750}
4697a36c
MM
5751\f
5752/* Perform any needed actions needed for a function that is receiving a
f676971a 5753 variable number of arguments.
4697a36c
MM
5754
5755 CUM is as above.
5756
5757 MODE and TYPE are the mode and type of the current parameter.
5758
5759 PRETEND_SIZE is a variable that should be set to the amount of stack
5760 that must be pushed by the prolog to pretend that our caller pushed
5761 it.
5762
5763 Normally, this macro will push all remaining incoming registers on the
5764 stack and set PRETEND_SIZE to the length of the registers pushed. */
5765
c6e8c921 5766static void
f676971a 5767setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
c4ad648e
AM
5768 tree type, int *pretend_size ATTRIBUTE_UNUSED,
5769 int no_rtl)
4697a36c 5770{
4cc833b7
RH
5771 CUMULATIVE_ARGS next_cum;
5772 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 5773 rtx save_area = NULL_RTX, mem;
dfafc897 5774 int first_reg_offset, set;
4697a36c 5775
f31bf321 5776 /* Skip the last named argument. */
d34c5b80 5777 next_cum = *cum;
594a51fe 5778 function_arg_advance (&next_cum, mode, type, 1, 0);
4cc833b7 5779
f607bc57 5780 if (DEFAULT_ABI == ABI_V4)
d34c5b80 5781 {
60e2d0ca 5782 if (! no_rtl)
2c4974b7 5783 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 5784 - RS6000_VARARGS_SIZE);
4cc833b7
RH
5785
5786 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 5787 }
60e2d0ca 5788 else
4697a36c 5789 {
d34c5b80 5790 first_reg_offset = next_cum.words;
4cc833b7 5791 save_area = virtual_incoming_args_rtx;
4697a36c 5792
fe984136 5793 if (targetm.calls.must_pass_in_stack (mode, type))
c53bdcf5 5794 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 5795 }
4697a36c 5796
dfafc897 5797 set = get_varargs_alias_set ();
5496b36f 5798 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 5799 {
dfafc897 5800 mem = gen_rtx_MEM (BLKmode,
c4ad648e 5801 plus_constant (save_area,
dfafc897 5802 first_reg_offset * reg_size)),
ba4828e0 5803 set_mem_alias_set (mem, set);
8ac61af7 5804 set_mem_align (mem, BITS_PER_WORD);
dfafc897 5805
f676971a 5806 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
c4ad648e 5807 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
5808 }
5809
4697a36c 5810 /* Save FP registers if needed. */
f607bc57 5811 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
5812 && TARGET_HARD_FLOAT && TARGET_FPRS
5813 && ! no_rtl
5496b36f 5814 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 5815 {
5496b36f 5816 int fregno = next_cum.fregno;
9ebbca7d 5817 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
5818 rtx lab = gen_label_rtx ();
5819 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 5820
c4ad648e
AM
5821 emit_jump_insn
5822 (gen_rtx_SET (VOIDmode,
5823 pc_rtx,
5824 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7 5825 gen_rtx_NE (VOIDmode, cr1,
c4ad648e 5826 const0_rtx),
39403d82 5827 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
5828 pc_rtx)));
5829
5496b36f 5830 while (fregno <= FP_ARG_V4_MAX_REG)
4cc833b7 5831 {
5496b36f 5832 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
c4ad648e 5833 set_mem_alias_set (mem, set);
94ff898d 5834 set_mem_align (mem, GET_MODE_ALIGNMENT (DFmode));
dfafc897 5835 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
5496b36f
JJ
5836 fregno++;
5837 off += 8;
4697a36c 5838 }
4cc833b7
RH
5839
5840 emit_label (lab);
4697a36c 5841 }
4697a36c 5842}
4697a36c 5843
dfafc897 5844/* Create the va_list data type. */
2c4974b7 5845
c35d187f
RH
5846static tree
5847rs6000_build_builtin_va_list (void)
dfafc897 5848{
64c2816f 5849 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 5850
9ebbca7d
GK
5851 /* For AIX, prefer 'char *' because that's what the system
5852 header files like. */
f607bc57 5853 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 5854 return build_pointer_type (char_type_node);
dfafc897 5855
f1e639b1 5856 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 5857 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 5858
f676971a 5859 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
9ebbca7d 5860 unsigned_char_type_node);
f676971a 5861 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
9ebbca7d 5862 unsigned_char_type_node);
64c2816f
DT
5863 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
5864 every user file. */
5865 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
5866 short_unsigned_type_node);
dfafc897
FS
5867 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
5868 ptr_type_node);
5869 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
5870 ptr_type_node);
5871
5872 DECL_FIELD_CONTEXT (f_gpr) = record;
5873 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 5874 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
5875 DECL_FIELD_CONTEXT (f_ovf) = record;
5876 DECL_FIELD_CONTEXT (f_sav) = record;
5877
bab45a51
FS
5878 TREE_CHAIN (record) = type_decl;
5879 TYPE_NAME (record) = type_decl;
dfafc897
FS
5880 TYPE_FIELDS (record) = f_gpr;
5881 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
5882 TREE_CHAIN (f_fpr) = f_res;
5883 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
5884 TREE_CHAIN (f_ovf) = f_sav;
5885
5886 layout_type (record);
5887
5888 /* The correct type is an array type of one element. */
5889 return build_array_type (record, build_index_type (size_zero_node));
5890}
5891
5892/* Implement va_start. */
5893
5894void
a2369ed3 5895rs6000_va_start (tree valist, rtx nextarg)
4697a36c 5896{
dfafc897 5897 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 5898 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 5899 tree gpr, fpr, ovf, sav, t;
2c4974b7 5900
dfafc897 5901 /* Only SVR4 needs something special. */
f607bc57 5902 if (DEFAULT_ABI != ABI_V4)
dfafc897 5903 {
e5faf155 5904 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
5905 return;
5906 }
5907
973a648b 5908 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5909 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5910 f_res = TREE_CHAIN (f_fpr);
5911 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5912 f_sav = TREE_CHAIN (f_ovf);
5913
872a65b5 5914 valist = build_va_arg_indirect_ref (valist);
44de5aeb
RK
5915 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5916 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5917 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5918 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
dfafc897
FS
5919
5920 /* Count number of gp and fp argument registers used. */
4cc833b7 5921 words = current_function_args_info.words;
dfafc897
FS
5922 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
5923 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
5924
5925 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
5926 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
5927 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
5928 words, n_gpr, n_fpr);
dfafc897 5929
5496b36f
JJ
5930 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr,
5931 build_int_cst (NULL_TREE, n_gpr));
5932 TREE_SIDE_EFFECTS (t) = 1;
5933 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
58c8adc1 5934
5496b36f
JJ
5935 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr,
5936 build_int_cst (NULL_TREE, n_fpr));
5937 TREE_SIDE_EFFECTS (t) = 1;
5938 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
dfafc897
FS
5939
5940 /* Find the overflow area. */
5941 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
5942 if (words != 0)
5943 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
7d60be94 5944 build_int_cst (NULL_TREE, words * UNITS_PER_WORD));
dfafc897
FS
5945 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5946 TREE_SIDE_EFFECTS (t) = 1;
5947 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5948
5949 /* Find the register save area. */
5950 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
5951 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
7d60be94 5952 build_int_cst (NULL_TREE, -RS6000_VARARGS_SIZE));
dfafc897
FS
5953 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
5954 TREE_SIDE_EFFECTS (t) = 1;
5955 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5956}
5957
5958/* Implement va_arg. */
5959
23a60a04
JM
5960tree
5961rs6000_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
cd3ce9b4 5962{
cd3ce9b4
JM
5963 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
5964 tree gpr, fpr, ovf, sav, reg, t, u;
08b0dc1b 5965 int size, rsize, n_reg, sav_ofs, sav_scale;
cd3ce9b4
JM
5966 tree lab_false, lab_over, addr;
5967 int align;
5968 tree ptrtype = build_pointer_type (type);
5969
08b0dc1b
RH
5970 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
5971 {
5972 t = rs6000_gimplify_va_arg (valist, ptrtype, pre_p, post_p);
872a65b5 5973 return build_va_arg_indirect_ref (t);
08b0dc1b
RH
5974 }
5975
cd3ce9b4
JM
5976 if (DEFAULT_ABI != ABI_V4)
5977 {
08b0dc1b 5978 if (targetm.calls.split_complex_arg && TREE_CODE (type) == COMPLEX_TYPE)
cd3ce9b4
JM
5979 {
5980 tree elem_type = TREE_TYPE (type);
5981 enum machine_mode elem_mode = TYPE_MODE (elem_type);
5982 int elem_size = GET_MODE_SIZE (elem_mode);
5983
5984 if (elem_size < UNITS_PER_WORD)
5985 {
23a60a04 5986 tree real_part, imag_part;
cd3ce9b4
JM
5987 tree post = NULL_TREE;
5988
23a60a04
JM
5989 real_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5990 &post);
5991 /* Copy the value into a temporary, lest the formal temporary
5992 be reused out from under us. */
5993 real_part = get_initialized_tmp_var (real_part, pre_p, &post);
cd3ce9b4
JM
5994 append_to_statement_list (post, pre_p);
5995
23a60a04
JM
5996 imag_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5997 post_p);
cd3ce9b4 5998
23a60a04 5999 return build (COMPLEX_EXPR, type, real_part, imag_part);
cd3ce9b4
JM
6000 }
6001 }
6002
23a60a04 6003 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
cd3ce9b4
JM
6004 }
6005
6006 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
6007 f_fpr = TREE_CHAIN (f_gpr);
6008 f_res = TREE_CHAIN (f_fpr);
6009 f_ovf = TREE_CHAIN (f_res);
6010 f_sav = TREE_CHAIN (f_ovf);
6011
872a65b5 6012 valist = build_va_arg_indirect_ref (valist);
44de5aeb
RK
6013 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
6014 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
6015 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
6016 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
cd3ce9b4
JM
6017
6018 size = int_size_in_bytes (type);
6019 rsize = (size + 3) / 4;
6020 align = 1;
6021
08b0dc1b
RH
6022 if (TARGET_HARD_FLOAT && TARGET_FPRS
6023 && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode))
cd3ce9b4
JM
6024 {
6025 /* FP args go in FP registers, if present. */
cd3ce9b4
JM
6026 reg = fpr;
6027 n_reg = 1;
6028 sav_ofs = 8*4;
6029 sav_scale = 8;
6030 if (TYPE_MODE (type) == DFmode)
6031 align = 8;
6032 }
6033 else
6034 {
6035 /* Otherwise into GP registers. */
cd3ce9b4
JM
6036 reg = gpr;
6037 n_reg = rsize;
6038 sav_ofs = 0;
6039 sav_scale = 4;
6040 if (n_reg == 2)
6041 align = 8;
6042 }
6043
6044 /* Pull the value out of the saved registers.... */
6045
6046 lab_over = NULL;
6047 addr = create_tmp_var (ptr_type_node, "addr");
6048 DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
6049
6050 /* AltiVec vectors never go in registers when -mabi=altivec. */
6051 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
6052 align = 16;
6053 else
6054 {
6055 lab_false = create_artificial_label ();
6056 lab_over = create_artificial_label ();
6057
6058 /* Long long and SPE vectors are aligned in the registers.
6059 As are any other 2 gpr item such as complex int due to a
6060 historical mistake. */
6061 u = reg;
6062 if (n_reg == 2)
6063 {
6064 u = build2 (BIT_AND_EXPR, TREE_TYPE (reg), reg,
95674810 6065 size_int (n_reg - 1));
cd3ce9b4
JM
6066 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u);
6067 }
6068
95674810 6069 t = fold_convert (TREE_TYPE (reg), size_int (8 - n_reg + 1));
cd3ce9b4
JM
6070 t = build2 (GE_EXPR, boolean_type_node, u, t);
6071 u = build1 (GOTO_EXPR, void_type_node, lab_false);
6072 t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE);
6073 gimplify_and_add (t, pre_p);
6074
6075 t = sav;
6076 if (sav_ofs)
95674810 6077 t = build2 (PLUS_EXPR, ptr_type_node, sav, size_int (sav_ofs));
cd3ce9b4 6078
95674810 6079 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, size_int (n_reg));
cd3ce9b4 6080 u = build1 (CONVERT_EXPR, integer_type_node, u);
95674810 6081 u = build2 (MULT_EXPR, integer_type_node, u, size_int (sav_scale));
cd3ce9b4
JM
6082 t = build2 (PLUS_EXPR, ptr_type_node, t, u);
6083
6084 t = build2 (MODIFY_EXPR, void_type_node, addr, t);
6085 gimplify_and_add (t, pre_p);
6086
6087 t = build1 (GOTO_EXPR, void_type_node, lab_over);
6088 gimplify_and_add (t, pre_p);
6089
6090 t = build1 (LABEL_EXPR, void_type_node, lab_false);
6091 append_to_statement_list (t, pre_p);
6092
6093 if (n_reg > 2)
6094 {
6095 /* Ensure that we don't find any more args in regs.
6096 Alignment has taken care of the n_reg == 2 case. */
95674810 6097 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, size_int (8));
cd3ce9b4
JM
6098 gimplify_and_add (t, pre_p);
6099 }
6100 }
6101
6102 /* ... otherwise out of the overflow area. */
6103
6104 /* Care for on-stack alignment if needed. */
6105 t = ovf;
6106 if (align != 1)
6107 {
95674810 6108 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (align - 1));
4a90aeeb 6109 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
7d60be94 6110 build_int_cst (NULL_TREE, -align));
cd3ce9b4
JM
6111 }
6112 gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
6113
6114 u = build2 (MODIFY_EXPR, void_type_node, addr, t);
6115 gimplify_and_add (u, pre_p);
6116
95674810 6117 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (size));
cd3ce9b4
JM
6118 t = build2 (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
6119 gimplify_and_add (t, pre_p);
6120
6121 if (lab_over)
6122 {
6123 t = build1 (LABEL_EXPR, void_type_node, lab_over);
6124 append_to_statement_list (t, pre_p);
6125 }
6126
08b0dc1b 6127 addr = fold_convert (ptrtype, addr);
872a65b5 6128 return build_va_arg_indirect_ref (addr);
cd3ce9b4
JM
6129}
6130
0ac081f6
AH
6131/* Builtins. */
6132
6e34d3a3
JM
6133#define def_builtin(MASK, NAME, TYPE, CODE) \
6134do { \
6135 if ((MASK) & target_flags) \
6136 lang_hooks.builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
6137 NULL, NULL_TREE); \
0ac081f6
AH
6138} while (0)
6139
24408032
AH
6140/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
6141
2212663f 6142static const struct builtin_description bdesc_3arg[] =
24408032
AH
6143{
6144 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
6145 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
6146 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
6147 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
6148 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
6149 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
6150 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
6151 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
6152 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
6153 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
f676971a 6154 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
aba5fb01
NS
6155 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_v4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
6156 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_v4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
6157 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_v8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
6158 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_v16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
6159 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_v4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
6160 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_v4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
6161 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_v8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
6162 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_v16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
6163 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_v16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
6164 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_v8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
6165 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_v4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
6166 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_v4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
24408032 6167};
2212663f 6168
95385cbb
AH
6169/* DST operations: void foo (void *, const int, const char). */
6170
6171static const struct builtin_description bdesc_dst[] =
6172{
6173 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
6174 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
6175 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
6176 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
6177};
6178
2212663f 6179/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 6180
a3170dc6 6181static struct builtin_description bdesc_2arg[] =
0ac081f6 6182{
f18c054f
DB
6183 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
6184 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
6185 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
6186 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
6187 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
6188 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
6189 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
6190 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
6191 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
6192 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
6193 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 6194 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
aba5fb01 6195 { MASK_ALTIVEC, CODE_FOR_andcv4si3, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
0ac081f6
AH
6196 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
6197 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
6198 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
6199 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
6200 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
6201 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
6202 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
6203 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
6204 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
6205 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
6206 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
6207 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
6208 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
6209 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
6210 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
6211 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
6212 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
6213 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
6214 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
6215 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
6216 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
6217 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
6218 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
6219 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
6220 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
6221 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
6222 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
6223 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
6224 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
6225 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
6226 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
6227 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
6228 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
6229 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
6230 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
6231 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
6232 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
6233 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
6234 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
6235 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
6236 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
6237 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
6238 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
6239 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
6240 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
6241 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
6242 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
6243 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
6244 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
6245 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
6246 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
f96bc213 6247 { MASK_ALTIVEC, CODE_FOR_altivec_norv4si3, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 6248 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
6249 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
6250 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
6251 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
6252 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
6253 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
6254 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
6255 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
6256 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
6257 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
6258 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
6259 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
6260 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
6261 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
6262 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
6263 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
6264 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
6265 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
6266 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
6267 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
6268 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
6269 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
6270 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 6271 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
6272 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
6273 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
6274 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
6275 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
6276 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
6277 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
6278 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
6279 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
6280 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
6281 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
6282 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
6283 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
6284 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
6285 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
6286 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
6287 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
6288 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
6289 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
6290 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
6291 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
6292 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
6293 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
6294 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 6295 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
6296
6297 /* Place holder, leave as first spe builtin. */
6298 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
6299 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
6300 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
6301 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
6302 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
6303 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
6304 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
6305 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
6306 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
6307 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
6308 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
6309 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
6310 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
6311 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
6312 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
6313 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
6314 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
6315 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
6316 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
6317 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
6318 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
6319 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
6320 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
6321 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
6322 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
6323 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
6324 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
6325 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
6326 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
6327 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
6328 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
6329 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
6330 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
6331 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
6332 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
6333 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
6334 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
6335 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
6336 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
6337 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
6338 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
6339 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
6340 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
6341 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
6342 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
6343 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
6344 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
6345 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
6346 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
6347 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
6348 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
6349 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
6350 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
6351 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
6352 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
6353 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
6354 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
6355 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
6356 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
6357 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
6358 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
6359 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
6360 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
6361 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
6362 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
6363 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
6364 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
6365 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
6366 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
6367 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
6368 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
6369 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
6370 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
6371 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
6372 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
6373 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
6374 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
6375 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
6376 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
6377 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
6378 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
6379 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
6380 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
6381 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
6382 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
6383 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
6384 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
6385 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
6386 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
6387 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
6388 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
6389 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
6390 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
6391 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
6392 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
6393 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
6394 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
6395 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
6396 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
6397 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
6398 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
6399 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
6400 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
6401 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
6402 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
6403 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
6404 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
6405 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
6406 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
6407
6408 /* SPE binary operations expecting a 5-bit unsigned literal. */
6409 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
6410
6411 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
6412 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
6413 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
6414 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
6415 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
6416 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
6417 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
6418 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
6419 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
6420 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
6421 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
6422 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
6423 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
6424 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
6425 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
6426 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
6427 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
6428 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
6429 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
6430 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
6431 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
6432 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
6433 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
6434 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
6435 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
6436 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
6437
6438 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 6439 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
6440};
6441
6442/* AltiVec predicates. */
6443
6444struct builtin_description_predicates
6445{
6446 const unsigned int mask;
6447 const enum insn_code icode;
6448 const char *opcode;
6449 const char *const name;
6450 const enum rs6000_builtins code;
6451};
6452
6453static const struct builtin_description_predicates bdesc_altivec_preds[] =
6454{
6455 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
6456 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
6457 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
6458 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
6459 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
6460 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
6461 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
6462 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
6463 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
6464 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
6465 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
6466 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
6467 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 6468};
24408032 6469
a3170dc6
AH
6470/* SPE predicates. */
6471static struct builtin_description bdesc_spe_predicates[] =
6472{
6473 /* Place-holder. Leave as first. */
6474 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
6475 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
6476 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
6477 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
6478 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
6479 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
6480 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
6481 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
6482 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
6483 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
6484 /* Place-holder. Leave as last. */
6485 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
6486};
6487
6488/* SPE evsel predicates. */
6489static struct builtin_description bdesc_spe_evsel[] =
6490{
6491 /* Place-holder. Leave as first. */
6492 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
6493 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
6494 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
6495 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
6496 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
6497 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
6498 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
6499 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
6500 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
6501 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
6502 /* Place-holder. Leave as last. */
6503 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
6504};
6505
b6d08ca1 6506/* ABS* operations. */
100c4561
AH
6507
6508static const struct builtin_description bdesc_abs[] =
6509{
6510 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
6511 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
6512 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
6513 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
6514 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
6515 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
6516 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
6517};
6518
617e0e1d
DB
6519/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
6520 foo (VECa). */
24408032 6521
a3170dc6 6522static struct builtin_description bdesc_1arg[] =
2212663f 6523{
617e0e1d
DB
6524 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
6525 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
6526 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
6527 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
6528 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
6529 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
6530 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
6531 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
6532 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
6533 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
6534 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
6535 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
6536 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
6537 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
6538 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
6539 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
6540 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
6541
6542 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
6543 end with SPE_BUILTIN_EVSUBFUSIAAW. */
6544 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
6545 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
6546 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
6547 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
6548 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
6549 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
6550 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
6551 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
6552 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
6553 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
6554 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
6555 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
6556 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
6557 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
6558 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
6559 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
6560 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
6561 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
6562 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
6563 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
6564 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
6565 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
6566 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
6a599451 6567 { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
a3170dc6
AH
6568 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
6569 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
6570 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
6571 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
6572
6573 /* Place-holder. Leave as last unary SPE builtin. */
6574 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
6575};
6576
6577static rtx
a2369ed3 6578rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6579{
6580 rtx pat;
6581 tree arg0 = TREE_VALUE (arglist);
6582 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6583 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6584 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6585
0559cc77
DE
6586 if (icode == CODE_FOR_nothing)
6587 /* Builtin not supported on this processor. */
6588 return 0;
6589
20e26713
AH
6590 /* If we got invalid arguments bail out before generating bad rtl. */
6591 if (arg0 == error_mark_node)
9a171fcd 6592 return const0_rtx;
20e26713 6593
0559cc77
DE
6594 if (icode == CODE_FOR_altivec_vspltisb
6595 || icode == CODE_FOR_altivec_vspltish
6596 || icode == CODE_FOR_altivec_vspltisw
6597 || icode == CODE_FOR_spe_evsplatfi
6598 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
6599 {
6600 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
6601 if (GET_CODE (op0) != CONST_INT
6602 || INTVAL (op0) > 0x1f
6603 || INTVAL (op0) < -0x1f)
6604 {
6605 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 6606 return const0_rtx;
b44140e7 6607 }
b44140e7
AH
6608 }
6609
c62f2db5 6610 if (target == 0
2212663f
DB
6611 || GET_MODE (target) != tmode
6612 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6613 target = gen_reg_rtx (tmode);
6614
6615 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6616 op0 = copy_to_mode_reg (mode0, op0);
6617
6618 pat = GEN_FCN (icode) (target, op0);
6619 if (! pat)
6620 return 0;
6621 emit_insn (pat);
0ac081f6 6622
2212663f
DB
6623 return target;
6624}
ae4b4a02 6625
100c4561 6626static rtx
a2369ed3 6627altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
6628{
6629 rtx pat, scratch1, scratch2;
6630 tree arg0 = TREE_VALUE (arglist);
6631 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6632 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6633 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6634
6635 /* If we have invalid arguments, bail out before generating bad rtl. */
6636 if (arg0 == error_mark_node)
9a171fcd 6637 return const0_rtx;
100c4561
AH
6638
6639 if (target == 0
6640 || GET_MODE (target) != tmode
6641 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6642 target = gen_reg_rtx (tmode);
6643
6644 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6645 op0 = copy_to_mode_reg (mode0, op0);
6646
6647 scratch1 = gen_reg_rtx (mode0);
6648 scratch2 = gen_reg_rtx (mode0);
6649
6650 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
6651 if (! pat)
6652 return 0;
6653 emit_insn (pat);
6654
6655 return target;
6656}
6657
0ac081f6 6658static rtx
a2369ed3 6659rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
6660{
6661 rtx pat;
6662 tree arg0 = TREE_VALUE (arglist);
6663 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6664 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6665 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6666 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6667 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6668 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6669
0559cc77
DE
6670 if (icode == CODE_FOR_nothing)
6671 /* Builtin not supported on this processor. */
6672 return 0;
6673
20e26713
AH
6674 /* If we got invalid arguments bail out before generating bad rtl. */
6675 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6676 return const0_rtx;
20e26713 6677
0559cc77
DE
6678 if (icode == CODE_FOR_altivec_vcfux
6679 || icode == CODE_FOR_altivec_vcfsx
6680 || icode == CODE_FOR_altivec_vctsxs
6681 || icode == CODE_FOR_altivec_vctuxs
6682 || icode == CODE_FOR_altivec_vspltb
6683 || icode == CODE_FOR_altivec_vsplth
6684 || icode == CODE_FOR_altivec_vspltw
6685 || icode == CODE_FOR_spe_evaddiw
6686 || icode == CODE_FOR_spe_evldd
6687 || icode == CODE_FOR_spe_evldh
6688 || icode == CODE_FOR_spe_evldw
6689 || icode == CODE_FOR_spe_evlhhesplat
6690 || icode == CODE_FOR_spe_evlhhossplat
6691 || icode == CODE_FOR_spe_evlhhousplat
6692 || icode == CODE_FOR_spe_evlwhe
6693 || icode == CODE_FOR_spe_evlwhos
6694 || icode == CODE_FOR_spe_evlwhou
6695 || icode == CODE_FOR_spe_evlwhsplat
6696 || icode == CODE_FOR_spe_evlwwsplat
6697 || icode == CODE_FOR_spe_evrlwi
6698 || icode == CODE_FOR_spe_evslwi
6699 || icode == CODE_FOR_spe_evsrwis
f5119d10 6700 || icode == CODE_FOR_spe_evsubifw
0559cc77 6701 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
6702 {
6703 /* Only allow 5-bit unsigned literals. */
8bb418a3 6704 STRIP_NOPS (arg1);
b44140e7
AH
6705 if (TREE_CODE (arg1) != INTEGER_CST
6706 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6707 {
6708 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 6709 return const0_rtx;
b44140e7 6710 }
b44140e7
AH
6711 }
6712
c62f2db5 6713 if (target == 0
0ac081f6
AH
6714 || GET_MODE (target) != tmode
6715 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6716 target = gen_reg_rtx (tmode);
6717
6718 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6719 op0 = copy_to_mode_reg (mode0, op0);
6720 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6721 op1 = copy_to_mode_reg (mode1, op1);
6722
6723 pat = GEN_FCN (icode) (target, op0, op1);
6724 if (! pat)
6725 return 0;
6726 emit_insn (pat);
6727
6728 return target;
6729}
6525c0e7 6730
ae4b4a02 6731static rtx
f676971a 6732altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
a2369ed3 6733 tree arglist, rtx target)
ae4b4a02
AH
6734{
6735 rtx pat, scratch;
6736 tree cr6_form = TREE_VALUE (arglist);
6737 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6738 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6739 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6740 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6741 enum machine_mode tmode = SImode;
6742 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6743 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6744 int cr6_form_int;
6745
6746 if (TREE_CODE (cr6_form) != INTEGER_CST)
6747 {
6748 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 6749 return const0_rtx;
ae4b4a02
AH
6750 }
6751 else
6752 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
6753
6754 if (mode0 != mode1)
6755 abort ();
6756
6757 /* If we have invalid arguments, bail out before generating bad rtl. */
6758 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6759 return const0_rtx;
ae4b4a02
AH
6760
6761 if (target == 0
6762 || GET_MODE (target) != tmode
6763 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6764 target = gen_reg_rtx (tmode);
6765
6766 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6767 op0 = copy_to_mode_reg (mode0, op0);
6768 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6769 op1 = copy_to_mode_reg (mode1, op1);
6770
6771 scratch = gen_reg_rtx (mode0);
6772
6773 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 6774 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
6775 if (! pat)
6776 return 0;
6777 emit_insn (pat);
6778
6779 /* The vec_any* and vec_all* predicates use the same opcodes for two
6780 different operations, but the bits in CR6 will be different
6781 depending on what information we want. So we have to play tricks
6782 with CR6 to get the right bits out.
6783
6784 If you think this is disgusting, look at the specs for the
6785 AltiVec predicates. */
6786
c4ad648e
AM
6787 switch (cr6_form_int)
6788 {
6789 case 0:
6790 emit_insn (gen_cr6_test_for_zero (target));
6791 break;
6792 case 1:
6793 emit_insn (gen_cr6_test_for_zero_reverse (target));
6794 break;
6795 case 2:
6796 emit_insn (gen_cr6_test_for_lt (target));
6797 break;
6798 case 3:
6799 emit_insn (gen_cr6_test_for_lt_reverse (target));
6800 break;
6801 default:
6802 error ("argument 1 of __builtin_altivec_predicate is out of range");
6803 break;
6804 }
ae4b4a02
AH
6805
6806 return target;
6807}
6808
b4a62fa0 6809static rtx
38f391a5 6810altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
6811{
6812 rtx pat, addr;
6813 tree arg0 = TREE_VALUE (arglist);
6814 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6815 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6816 enum machine_mode mode0 = Pmode;
6817 enum machine_mode mode1 = Pmode;
6818 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6819 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6820
6821 if (icode == CODE_FOR_nothing)
6822 /* Builtin not supported on this processor. */
6823 return 0;
6824
6825 /* If we got invalid arguments bail out before generating bad rtl. */
6826 if (arg0 == error_mark_node || arg1 == error_mark_node)
6827 return const0_rtx;
6828
6829 if (target == 0
6830 || GET_MODE (target) != tmode
6831 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6832 target = gen_reg_rtx (tmode);
6833
f676971a 6834 op1 = copy_to_mode_reg (mode1, op1);
b4a62fa0
SB
6835
6836 if (op0 == const0_rtx)
6837 {
6838 addr = gen_rtx_MEM (tmode, op1);
6839 }
6840 else
6841 {
6842 op0 = copy_to_mode_reg (mode0, op0);
6843 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
6844 }
6845
6846 pat = GEN_FCN (icode) (target, addr);
6847
6848 if (! pat)
6849 return 0;
6850 emit_insn (pat);
6851
6852 return target;
6853}
6854
61bea3b0
AH
6855static rtx
6856spe_expand_stv_builtin (enum insn_code icode, tree arglist)
6857{
6858 tree arg0 = TREE_VALUE (arglist);
6859 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6860 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6861 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6862 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6863 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6864 rtx pat;
6865 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
6866 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
6867 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
6868
6869 /* Invalid arguments. Bail before doing anything stoopid! */
6870 if (arg0 == error_mark_node
6871 || arg1 == error_mark_node
6872 || arg2 == error_mark_node)
6873 return const0_rtx;
6874
6875 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
6876 op0 = copy_to_mode_reg (mode2, op0);
6877 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
6878 op1 = copy_to_mode_reg (mode0, op1);
6879 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6880 op2 = copy_to_mode_reg (mode1, op2);
6881
6882 pat = GEN_FCN (icode) (op1, op2, op0);
6883 if (pat)
6884 emit_insn (pat);
6885 return NULL_RTX;
6886}
6887
6525c0e7 6888static rtx
a2369ed3 6889altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
6890{
6891 tree arg0 = TREE_VALUE (arglist);
6892 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6893 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6894 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6895 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6896 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
6897 rtx pat, addr;
6898 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6899 enum machine_mode mode1 = Pmode;
6900 enum machine_mode mode2 = Pmode;
6525c0e7
AH
6901
6902 /* Invalid arguments. Bail before doing anything stoopid! */
6903 if (arg0 == error_mark_node
6904 || arg1 == error_mark_node
6905 || arg2 == error_mark_node)
9a171fcd 6906 return const0_rtx;
6525c0e7 6907
b4a62fa0
SB
6908 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
6909 op0 = copy_to_mode_reg (tmode, op0);
6910
f676971a 6911 op2 = copy_to_mode_reg (mode2, op2);
b4a62fa0
SB
6912
6913 if (op1 == const0_rtx)
6914 {
6915 addr = gen_rtx_MEM (tmode, op2);
6916 }
6917 else
6918 {
6919 op1 = copy_to_mode_reg (mode1, op1);
6920 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
6921 }
6525c0e7 6922
b4a62fa0 6923 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
6924 if (pat)
6925 emit_insn (pat);
6926 return NULL_RTX;
6927}
6928
2212663f 6929static rtx
a2369ed3 6930rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6931{
6932 rtx pat;
6933 tree arg0 = TREE_VALUE (arglist);
6934 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6935 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6936 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6937 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6938 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6939 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6940 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6941 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6942 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 6943
774b5662
DE
6944 if (icode == CODE_FOR_nothing)
6945 /* Builtin not supported on this processor. */
6946 return 0;
6947
20e26713
AH
6948 /* If we got invalid arguments bail out before generating bad rtl. */
6949 if (arg0 == error_mark_node
6950 || arg1 == error_mark_node
6951 || arg2 == error_mark_node)
9a171fcd 6952 return const0_rtx;
20e26713 6953
aba5fb01
NS
6954 if (icode == CODE_FOR_altivec_vsldoi_v4sf
6955 || icode == CODE_FOR_altivec_vsldoi_v4si
6956 || icode == CODE_FOR_altivec_vsldoi_v8hi
6957 || icode == CODE_FOR_altivec_vsldoi_v16qi)
b44140e7
AH
6958 {
6959 /* Only allow 4-bit unsigned literals. */
8bb418a3 6960 STRIP_NOPS (arg2);
b44140e7
AH
6961 if (TREE_CODE (arg2) != INTEGER_CST
6962 || TREE_INT_CST_LOW (arg2) & ~0xf)
6963 {
6964 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 6965 return const0_rtx;
b44140e7 6966 }
b44140e7
AH
6967 }
6968
c62f2db5 6969 if (target == 0
2212663f
DB
6970 || GET_MODE (target) != tmode
6971 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6972 target = gen_reg_rtx (tmode);
6973
6974 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6975 op0 = copy_to_mode_reg (mode0, op0);
6976 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6977 op1 = copy_to_mode_reg (mode1, op1);
6978 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
6979 op2 = copy_to_mode_reg (mode2, op2);
6980
6981 pat = GEN_FCN (icode) (target, op0, op1, op2);
6982 if (! pat)
6983 return 0;
6984 emit_insn (pat);
6985
6986 return target;
6987}
92898235 6988
3a9b8c7e 6989/* Expand the lvx builtins. */
0ac081f6 6990static rtx
a2369ed3 6991altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 6992{
0ac081f6
AH
6993 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6994 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 6995 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
6996 tree arg0;
6997 enum machine_mode tmode, mode0;
7c3abc73 6998 rtx pat, op0;
3a9b8c7e 6999 enum insn_code icode;
92898235 7000
0ac081f6
AH
7001 switch (fcode)
7002 {
f18c054f 7003 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
81466555 7004 icode = CODE_FOR_altivec_lvx_v16qi;
3a9b8c7e 7005 break;
f18c054f 7006 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
81466555 7007 icode = CODE_FOR_altivec_lvx_v8hi;
3a9b8c7e
AH
7008 break;
7009 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
81466555 7010 icode = CODE_FOR_altivec_lvx_v4si;
3a9b8c7e
AH
7011 break;
7012 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
81466555 7013 icode = CODE_FOR_altivec_lvx_v4sf;
3a9b8c7e
AH
7014 break;
7015 default:
7016 *expandedp = false;
7017 return NULL_RTX;
7018 }
0ac081f6 7019
3a9b8c7e 7020 *expandedp = true;
f18c054f 7021
3a9b8c7e
AH
7022 arg0 = TREE_VALUE (arglist);
7023 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7024 tmode = insn_data[icode].operand[0].mode;
7025 mode0 = insn_data[icode].operand[1].mode;
f18c054f 7026
3a9b8c7e
AH
7027 if (target == 0
7028 || GET_MODE (target) != tmode
7029 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7030 target = gen_reg_rtx (tmode);
24408032 7031
3a9b8c7e
AH
7032 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7033 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 7034
3a9b8c7e
AH
7035 pat = GEN_FCN (icode) (target, op0);
7036 if (! pat)
7037 return 0;
7038 emit_insn (pat);
7039 return target;
7040}
f18c054f 7041
3a9b8c7e
AH
7042/* Expand the stvx builtins. */
7043static rtx
f676971a 7044altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 7045 bool *expandedp)
3a9b8c7e
AH
7046{
7047 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7048 tree arglist = TREE_OPERAND (exp, 1);
7049 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
7050 tree arg0, arg1;
7051 enum machine_mode mode0, mode1;
7c3abc73 7052 rtx pat, op0, op1;
3a9b8c7e 7053 enum insn_code icode;
f18c054f 7054
3a9b8c7e
AH
7055 switch (fcode)
7056 {
7057 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
81466555 7058 icode = CODE_FOR_altivec_stvx_v16qi;
3a9b8c7e
AH
7059 break;
7060 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
81466555 7061 icode = CODE_FOR_altivec_stvx_v8hi;
3a9b8c7e
AH
7062 break;
7063 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
81466555 7064 icode = CODE_FOR_altivec_stvx_v4si;
3a9b8c7e
AH
7065 break;
7066 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
81466555 7067 icode = CODE_FOR_altivec_stvx_v4sf;
3a9b8c7e
AH
7068 break;
7069 default:
7070 *expandedp = false;
7071 return NULL_RTX;
7072 }
24408032 7073
3a9b8c7e
AH
7074 arg0 = TREE_VALUE (arglist);
7075 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
7076 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7077 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7078 mode0 = insn_data[icode].operand[0].mode;
7079 mode1 = insn_data[icode].operand[1].mode;
f18c054f 7080
3a9b8c7e
AH
7081 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
7082 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
7083 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
7084 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 7085
3a9b8c7e
AH
7086 pat = GEN_FCN (icode) (op0, op1);
7087 if (pat)
7088 emit_insn (pat);
f18c054f 7089
3a9b8c7e
AH
7090 *expandedp = true;
7091 return NULL_RTX;
7092}
f18c054f 7093
3a9b8c7e
AH
7094/* Expand the dst builtins. */
7095static rtx
f676971a 7096altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 7097 bool *expandedp)
3a9b8c7e
AH
7098{
7099 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7100 tree arglist = TREE_OPERAND (exp, 1);
7101 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
7102 tree arg0, arg1, arg2;
7103 enum machine_mode mode0, mode1, mode2;
7c3abc73 7104 rtx pat, op0, op1, op2;
3a9b8c7e 7105 struct builtin_description *d;
a3170dc6 7106 size_t i;
f18c054f 7107
3a9b8c7e 7108 *expandedp = false;
f18c054f 7109
3a9b8c7e
AH
7110 /* Handle DST variants. */
7111 d = (struct builtin_description *) bdesc_dst;
7112 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
7113 if (d->code == fcode)
7114 {
7115 arg0 = TREE_VALUE (arglist);
7116 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
7117 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7118 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7119 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7120 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
7121 mode0 = insn_data[d->icode].operand[0].mode;
7122 mode1 = insn_data[d->icode].operand[1].mode;
7123 mode2 = insn_data[d->icode].operand[2].mode;
24408032 7124
3a9b8c7e
AH
7125 /* Invalid arguments, bail out before generating bad rtl. */
7126 if (arg0 == error_mark_node
7127 || arg1 == error_mark_node
7128 || arg2 == error_mark_node)
7129 return const0_rtx;
f18c054f 7130
86e7df90 7131 *expandedp = true;
8bb418a3 7132 STRIP_NOPS (arg2);
3a9b8c7e
AH
7133 if (TREE_CODE (arg2) != INTEGER_CST
7134 || TREE_INT_CST_LOW (arg2) & ~0x3)
7135 {
9e637a26 7136 error ("argument to %qs must be a 2-bit unsigned literal", d->name);
3a9b8c7e
AH
7137 return const0_rtx;
7138 }
f18c054f 7139
3a9b8c7e 7140 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 7141 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
7142 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
7143 op1 = copy_to_mode_reg (mode1, op1);
24408032 7144
3a9b8c7e
AH
7145 pat = GEN_FCN (d->icode) (op0, op1, op2);
7146 if (pat != 0)
7147 emit_insn (pat);
f18c054f 7148
3a9b8c7e
AH
7149 return NULL_RTX;
7150 }
f18c054f 7151
3a9b8c7e
AH
7152 return NULL_RTX;
7153}
24408032 7154
3a9b8c7e
AH
7155/* Expand the builtin in EXP and store the result in TARGET. Store
7156 true in *EXPANDEDP if we found a builtin to expand. */
7157static rtx
a2369ed3 7158altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
7159{
7160 struct builtin_description *d;
7161 struct builtin_description_predicates *dp;
7162 size_t i;
7163 enum insn_code icode;
7164 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7165 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
7166 tree arg0;
7167 rtx op0, pat;
7168 enum machine_mode tmode, mode0;
3a9b8c7e 7169 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 7170
3a9b8c7e
AH
7171 target = altivec_expand_ld_builtin (exp, target, expandedp);
7172 if (*expandedp)
7173 return target;
0ac081f6 7174
3a9b8c7e
AH
7175 target = altivec_expand_st_builtin (exp, target, expandedp);
7176 if (*expandedp)
7177 return target;
7178
7179 target = altivec_expand_dst_builtin (exp, target, expandedp);
7180 if (*expandedp)
7181 return target;
7182
7183 *expandedp = true;
95385cbb 7184
3a9b8c7e
AH
7185 switch (fcode)
7186 {
6525c0e7
AH
7187 case ALTIVEC_BUILTIN_STVX:
7188 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
7189 case ALTIVEC_BUILTIN_STVEBX:
7190 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
7191 case ALTIVEC_BUILTIN_STVEHX:
7192 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
7193 case ALTIVEC_BUILTIN_STVEWX:
7194 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
7195 case ALTIVEC_BUILTIN_STVXL:
7196 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 7197
95385cbb
AH
7198 case ALTIVEC_BUILTIN_MFVSCR:
7199 icode = CODE_FOR_altivec_mfvscr;
7200 tmode = insn_data[icode].operand[0].mode;
7201
7202 if (target == 0
7203 || GET_MODE (target) != tmode
7204 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7205 target = gen_reg_rtx (tmode);
f676971a 7206
95385cbb 7207 pat = GEN_FCN (icode) (target);
0ac081f6
AH
7208 if (! pat)
7209 return 0;
7210 emit_insn (pat);
95385cbb
AH
7211 return target;
7212
7213 case ALTIVEC_BUILTIN_MTVSCR:
7214 icode = CODE_FOR_altivec_mtvscr;
7215 arg0 = TREE_VALUE (arglist);
7216 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7217 mode0 = insn_data[icode].operand[0].mode;
7218
7219 /* If we got invalid arguments bail out before generating bad rtl. */
7220 if (arg0 == error_mark_node)
9a171fcd 7221 return const0_rtx;
95385cbb
AH
7222
7223 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
7224 op0 = copy_to_mode_reg (mode0, op0);
7225
7226 pat = GEN_FCN (icode) (op0);
7227 if (pat)
7228 emit_insn (pat);
7229 return NULL_RTX;
3a9b8c7e 7230
95385cbb
AH
7231 case ALTIVEC_BUILTIN_DSSALL:
7232 emit_insn (gen_altivec_dssall ());
7233 return NULL_RTX;
7234
7235 case ALTIVEC_BUILTIN_DSS:
7236 icode = CODE_FOR_altivec_dss;
7237 arg0 = TREE_VALUE (arglist);
8bb418a3 7238 STRIP_NOPS (arg0);
95385cbb
AH
7239 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7240 mode0 = insn_data[icode].operand[0].mode;
7241
7242 /* If we got invalid arguments bail out before generating bad rtl. */
7243 if (arg0 == error_mark_node)
9a171fcd 7244 return const0_rtx;
95385cbb 7245
b44140e7
AH
7246 if (TREE_CODE (arg0) != INTEGER_CST
7247 || TREE_INT_CST_LOW (arg0) & ~0x3)
7248 {
7249 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 7250 return const0_rtx;
b44140e7
AH
7251 }
7252
95385cbb
AH
7253 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
7254 op0 = copy_to_mode_reg (mode0, op0);
7255
7256 emit_insn (gen_altivec_dss (op0));
0ac081f6 7257 return NULL_RTX;
f676971a 7258
8bb418a3
ZL
7259 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
7260 arg0 = TREE_VALUE (arglist);
97dc04b3 7261 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR
c4ad648e 7262 || TREE_CODE (arg0) == ARRAY_REF)
8bb418a3 7263 arg0 = TREE_OPERAND (arg0, 0);
9e637a26 7264 error ("invalid parameter combination for %qs AltiVec intrinsic",
8bb418a3
ZL
7265 TREE_STRING_POINTER (arg0));
7266
7267 return const0_rtx;
0ac081f6 7268 }
24408032 7269
100c4561
AH
7270 /* Expand abs* operations. */
7271 d = (struct builtin_description *) bdesc_abs;
ca7558fc 7272 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
7273 if (d->code == fcode)
7274 return altivec_expand_abs_builtin (d->icode, arglist, target);
7275
ae4b4a02
AH
7276 /* Expand the AltiVec predicates. */
7277 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 7278 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02 7279 if (dp->code == fcode)
c4ad648e
AM
7280 return altivec_expand_predicate_builtin (dp->icode, dp->opcode,
7281 arglist, target);
ae4b4a02 7282
6525c0e7
AH
7283 /* LV* are funky. We initialized them differently. */
7284 switch (fcode)
7285 {
7286 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 7287 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
c4ad648e 7288 arglist, target);
6525c0e7 7289 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 7290 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
c4ad648e 7291 arglist, target);
6525c0e7 7292 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 7293 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
c4ad648e 7294 arglist, target);
6525c0e7 7295 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 7296 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
c4ad648e 7297 arglist, target);
6525c0e7 7298 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 7299 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
c4ad648e 7300 arglist, target);
6525c0e7 7301 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 7302 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
c4ad648e 7303 arglist, target);
6525c0e7 7304 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 7305 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
c4ad648e 7306 arglist, target);
6525c0e7
AH
7307 default:
7308 break;
7309 /* Fall through. */
7310 }
95385cbb 7311
92898235 7312 *expandedp = false;
0ac081f6
AH
7313 return NULL_RTX;
7314}
7315
a3170dc6
AH
7316/* Binops that need to be initialized manually, but can be expanded
7317 automagically by rs6000_expand_binop_builtin. */
7318static struct builtin_description bdesc_2arg_spe[] =
7319{
7320 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
7321 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
7322 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
7323 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
7324 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
7325 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
7326 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
7327 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
7328 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
7329 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
7330 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
7331 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
7332 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
7333 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
7334 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
7335 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
7336 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
7337 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
7338 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
7339 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
7340 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
7341 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
7342};
7343
7344/* Expand the builtin in EXP and store the result in TARGET. Store
7345 true in *EXPANDEDP if we found a builtin to expand.
7346
7347 This expands the SPE builtins that are not simple unary and binary
7348 operations. */
7349static rtx
a2369ed3 7350spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
7351{
7352 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7353 tree arglist = TREE_OPERAND (exp, 1);
7354 tree arg1, arg0;
7355 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
7356 enum insn_code icode;
7357 enum machine_mode tmode, mode0;
7358 rtx pat, op0;
7359 struct builtin_description *d;
7360 size_t i;
7361
7362 *expandedp = true;
7363
7364 /* Syntax check for a 5-bit unsigned immediate. */
7365 switch (fcode)
7366 {
7367 case SPE_BUILTIN_EVSTDD:
7368 case SPE_BUILTIN_EVSTDH:
7369 case SPE_BUILTIN_EVSTDW:
7370 case SPE_BUILTIN_EVSTWHE:
7371 case SPE_BUILTIN_EVSTWHO:
7372 case SPE_BUILTIN_EVSTWWE:
7373 case SPE_BUILTIN_EVSTWWO:
7374 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7375 if (TREE_CODE (arg1) != INTEGER_CST
7376 || TREE_INT_CST_LOW (arg1) & ~0x1f)
7377 {
7378 error ("argument 2 must be a 5-bit unsigned literal");
7379 return const0_rtx;
7380 }
7381 break;
7382 default:
7383 break;
7384 }
7385
00332c9f
AH
7386 /* The evsplat*i instructions are not quite generic. */
7387 switch (fcode)
7388 {
7389 case SPE_BUILTIN_EVSPLATFI:
7390 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
7391 arglist, target);
7392 case SPE_BUILTIN_EVSPLATI:
7393 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
7394 arglist, target);
7395 default:
7396 break;
7397 }
7398
a3170dc6
AH
7399 d = (struct builtin_description *) bdesc_2arg_spe;
7400 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
7401 if (d->code == fcode)
7402 return rs6000_expand_binop_builtin (d->icode, arglist, target);
7403
7404 d = (struct builtin_description *) bdesc_spe_predicates;
7405 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
7406 if (d->code == fcode)
7407 return spe_expand_predicate_builtin (d->icode, arglist, target);
7408
7409 d = (struct builtin_description *) bdesc_spe_evsel;
7410 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
7411 if (d->code == fcode)
7412 return spe_expand_evsel_builtin (d->icode, arglist, target);
7413
7414 switch (fcode)
7415 {
7416 case SPE_BUILTIN_EVSTDDX:
61bea3b0 7417 return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
a3170dc6 7418 case SPE_BUILTIN_EVSTDHX:
61bea3b0 7419 return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
a3170dc6 7420 case SPE_BUILTIN_EVSTDWX:
61bea3b0 7421 return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
a3170dc6 7422 case SPE_BUILTIN_EVSTWHEX:
61bea3b0 7423 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
a3170dc6 7424 case SPE_BUILTIN_EVSTWHOX:
61bea3b0 7425 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
a3170dc6 7426 case SPE_BUILTIN_EVSTWWEX:
61bea3b0 7427 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
a3170dc6 7428 case SPE_BUILTIN_EVSTWWOX:
61bea3b0 7429 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
a3170dc6 7430 case SPE_BUILTIN_EVSTDD:
61bea3b0 7431 return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
a3170dc6 7432 case SPE_BUILTIN_EVSTDH:
61bea3b0 7433 return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
a3170dc6 7434 case SPE_BUILTIN_EVSTDW:
61bea3b0 7435 return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
a3170dc6 7436 case SPE_BUILTIN_EVSTWHE:
61bea3b0 7437 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
a3170dc6 7438 case SPE_BUILTIN_EVSTWHO:
61bea3b0 7439 return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
a3170dc6 7440 case SPE_BUILTIN_EVSTWWE:
61bea3b0 7441 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
a3170dc6 7442 case SPE_BUILTIN_EVSTWWO:
61bea3b0 7443 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
a3170dc6
AH
7444 case SPE_BUILTIN_MFSPEFSCR:
7445 icode = CODE_FOR_spe_mfspefscr;
7446 tmode = insn_data[icode].operand[0].mode;
7447
7448 if (target == 0
7449 || GET_MODE (target) != tmode
7450 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7451 target = gen_reg_rtx (tmode);
f676971a 7452
a3170dc6
AH
7453 pat = GEN_FCN (icode) (target);
7454 if (! pat)
7455 return 0;
7456 emit_insn (pat);
7457 return target;
7458 case SPE_BUILTIN_MTSPEFSCR:
7459 icode = CODE_FOR_spe_mtspefscr;
7460 arg0 = TREE_VALUE (arglist);
7461 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7462 mode0 = insn_data[icode].operand[0].mode;
7463
7464 if (arg0 == error_mark_node)
7465 return const0_rtx;
7466
7467 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
7468 op0 = copy_to_mode_reg (mode0, op0);
7469
7470 pat = GEN_FCN (icode) (op0);
7471 if (pat)
7472 emit_insn (pat);
7473 return NULL_RTX;
7474 default:
7475 break;
7476 }
7477
7478 *expandedp = false;
7479 return NULL_RTX;
7480}
7481
7482static rtx
a2369ed3 7483spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7484{
7485 rtx pat, scratch, tmp;
7486 tree form = TREE_VALUE (arglist);
7487 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
7488 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7489 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7490 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7491 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7492 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7493 int form_int;
7494 enum rtx_code code;
7495
7496 if (TREE_CODE (form) != INTEGER_CST)
7497 {
7498 error ("argument 1 of __builtin_spe_predicate must be a constant");
7499 return const0_rtx;
7500 }
7501 else
7502 form_int = TREE_INT_CST_LOW (form);
7503
7504 if (mode0 != mode1)
7505 abort ();
7506
7507 if (arg0 == error_mark_node || arg1 == error_mark_node)
7508 return const0_rtx;
7509
7510 if (target == 0
7511 || GET_MODE (target) != SImode
7512 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
7513 target = gen_reg_rtx (SImode);
7514
7515 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7516 op0 = copy_to_mode_reg (mode0, op0);
7517 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
7518 op1 = copy_to_mode_reg (mode1, op1);
7519
7520 scratch = gen_reg_rtx (CCmode);
7521
7522 pat = GEN_FCN (icode) (scratch, op0, op1);
7523 if (! pat)
7524 return const0_rtx;
7525 emit_insn (pat);
7526
7527 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
7528 _lower_. We use one compare, but look in different bits of the
7529 CR for each variant.
7530
7531 There are 2 elements in each SPE simd type (upper/lower). The CR
7532 bits are set as follows:
7533
7534 BIT0 | BIT 1 | BIT 2 | BIT 3
7535 U | L | (U | L) | (U & L)
7536
7537 So, for an "all" relationship, BIT 3 would be set.
7538 For an "any" relationship, BIT 2 would be set. Etc.
7539
7540 Following traditional nomenclature, these bits map to:
7541
7542 BIT0 | BIT 1 | BIT 2 | BIT 3
7543 LT | GT | EQ | OV
7544
7545 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
7546 */
7547
7548 switch (form_int)
7549 {
7550 /* All variant. OV bit. */
7551 case 0:
7552 /* We need to get to the OV bit, which is the ORDERED bit. We
7553 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
7554 that's ugly and will trigger a validate_condition_mode abort.
7555 So let's just use another pattern. */
7556 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
7557 return target;
7558 /* Any variant. EQ bit. */
7559 case 1:
7560 code = EQ;
7561 break;
7562 /* Upper variant. LT bit. */
7563 case 2:
7564 code = LT;
7565 break;
7566 /* Lower variant. GT bit. */
7567 case 3:
7568 code = GT;
7569 break;
7570 default:
7571 error ("argument 1 of __builtin_spe_predicate is out of range");
7572 return const0_rtx;
7573 }
7574
7575 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
7576 emit_move_insn (target, tmp);
7577
7578 return target;
7579}
7580
7581/* The evsel builtins look like this:
7582
7583 e = __builtin_spe_evsel_OP (a, b, c, d);
7584
7585 and work like this:
7586
7587 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
7588 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
7589*/
7590
7591static rtx
a2369ed3 7592spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7593{
7594 rtx pat, scratch;
7595 tree arg0 = TREE_VALUE (arglist);
7596 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
7597 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7598 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
7599 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7600 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7601 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
7602 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
7603 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7604 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7605
7606 if (mode0 != mode1)
7607 abort ();
7608
7609 if (arg0 == error_mark_node || arg1 == error_mark_node
7610 || arg2 == error_mark_node || arg3 == error_mark_node)
7611 return const0_rtx;
7612
7613 if (target == 0
7614 || GET_MODE (target) != mode0
7615 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
7616 target = gen_reg_rtx (mode0);
7617
7618 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7619 op0 = copy_to_mode_reg (mode0, op0);
7620 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
7621 op1 = copy_to_mode_reg (mode0, op1);
7622 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
7623 op2 = copy_to_mode_reg (mode0, op2);
7624 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
7625 op3 = copy_to_mode_reg (mode0, op3);
7626
7627 /* Generate the compare. */
7628 scratch = gen_reg_rtx (CCmode);
7629 pat = GEN_FCN (icode) (scratch, op0, op1);
7630 if (! pat)
7631 return const0_rtx;
7632 emit_insn (pat);
7633
7634 if (mode0 == V2SImode)
7635 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
7636 else
7637 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
7638
7639 return target;
7640}
7641
0ac081f6
AH
7642/* Expand an expression EXP that calls a built-in function,
7643 with result going to TARGET if that's convenient
7644 (and in mode MODE if that's convenient).
7645 SUBTARGET may be used as the target for computing one of EXP's operands.
7646 IGNORE is nonzero if the value is to be ignored. */
7647
7648static rtx
a2369ed3 7649rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
c4ad648e
AM
7650 enum machine_mode mode ATTRIBUTE_UNUSED,
7651 int ignore ATTRIBUTE_UNUSED)
0ac081f6 7652{
92898235
AH
7653 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7654 tree arglist = TREE_OPERAND (exp, 1);
7655 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
7656 struct builtin_description *d;
7657 size_t i;
7658 rtx ret;
7659 bool success;
f676971a 7660
7ccf35ed
DN
7661 if (fcode == ALTIVEC_BUILTIN_MASK_FOR_LOAD
7662 || fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE)
7663 {
7664 int icode = (int) CODE_FOR_altivec_lvsr;
7665 enum machine_mode tmode = insn_data[icode].operand[0].mode;
7666 enum machine_mode mode = insn_data[icode].operand[1].mode;
7667 tree arg;
7668 rtx op, addr, pat;
7669
7670 if (!TARGET_ALTIVEC)
7671 abort ();
7672
7673 arg = TREE_VALUE (arglist);
7674 if (TREE_CODE (TREE_TYPE (arg)) != POINTER_TYPE)
7675 abort ();
7676 op = expand_expr (arg, NULL_RTX, Pmode, EXPAND_NORMAL);
7677 addr = memory_address (mode, op);
7678 if (fcode == ALTIVEC_BUILTIN_MASK_FOR_STORE)
7679 op = addr;
7680 else
7681 {
7682 /* For the load case need to negate the address. */
7683 op = gen_reg_rtx (GET_MODE (addr));
7684 emit_insn (gen_rtx_SET (VOIDmode, op,
7685 gen_rtx_NEG (GET_MODE (addr), addr)));
c4ad648e 7686 }
7ccf35ed
DN
7687 op = gen_rtx_MEM (mode, op);
7688
7689 if (target == 0
7690 || GET_MODE (target) != tmode
7691 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
7692 target = gen_reg_rtx (tmode);
7693
7694 /*pat = gen_altivec_lvsr (target, op);*/
7695 pat = GEN_FCN (icode) (target, op);
7696 if (!pat)
7697 return 0;
7698 emit_insn (pat);
7699
7700 return target;
7701 }
7702
0ac081f6 7703 if (TARGET_ALTIVEC)
92898235
AH
7704 {
7705 ret = altivec_expand_builtin (exp, target, &success);
7706
a3170dc6
AH
7707 if (success)
7708 return ret;
7709 }
7710 if (TARGET_SPE)
7711 {
7712 ret = spe_expand_builtin (exp, target, &success);
7713
92898235
AH
7714 if (success)
7715 return ret;
7716 }
7717
0559cc77
DE
7718 if (TARGET_ALTIVEC || TARGET_SPE)
7719 {
7720 /* Handle simple unary operations. */
7721 d = (struct builtin_description *) bdesc_1arg;
7722 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
7723 if (d->code == fcode)
7724 return rs6000_expand_unop_builtin (d->icode, arglist, target);
7725
7726 /* Handle simple binary operations. */
7727 d = (struct builtin_description *) bdesc_2arg;
7728 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
7729 if (d->code == fcode)
7730 return rs6000_expand_binop_builtin (d->icode, arglist, target);
7731
7732 /* Handle simple ternary operations. */
7733 d = (struct builtin_description *) bdesc_3arg;
7734 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
7735 if (d->code == fcode)
7736 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
7737 }
0ac081f6
AH
7738
7739 abort ();
92898235 7740 return NULL_RTX;
0ac081f6
AH
7741}
7742
7c62e993
PB
7743static tree
7744build_opaque_vector_type (tree node, int nunits)
7745{
7746 node = copy_node (node);
7747 TYPE_MAIN_VARIANT (node) = node;
7748 return build_vector_type (node, nunits);
7749}
7750
0ac081f6 7751static void
863d938c 7752rs6000_init_builtins (void)
0ac081f6 7753{
4a5eab38
PB
7754 V2SI_type_node = build_vector_type (intSI_type_node, 2);
7755 V2SF_type_node = build_vector_type (float_type_node, 2);
7756 V4HI_type_node = build_vector_type (intHI_type_node, 4);
7757 V4SI_type_node = build_vector_type (intSI_type_node, 4);
7758 V4SF_type_node = build_vector_type (float_type_node, 4);
7e463bda 7759 V8HI_type_node = build_vector_type (intHI_type_node, 8);
4a5eab38
PB
7760 V16QI_type_node = build_vector_type (intQI_type_node, 16);
7761
7762 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
7763 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
7764 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
7765
7c62e993
PB
7766 opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2);
7767 opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2);
6035d635 7768 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 7769
8bb418a3
ZL
7770 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
7771 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
7772 'vector unsigned short'. */
7773
8dd16ecc
NS
7774 bool_char_type_node = build_distinct_type_copy (unsigned_intQI_type_node);
7775 bool_short_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
7776 bool_int_type_node = build_distinct_type_copy (unsigned_intSI_type_node);
7777 pixel_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
8bb418a3
ZL
7778
7779 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7780 get_identifier ("__bool char"),
7781 bool_char_type_node));
7782 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7783 get_identifier ("__bool short"),
7784 bool_short_type_node));
7785 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7786 get_identifier ("__bool int"),
7787 bool_int_type_node));
7788 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7789 get_identifier ("__pixel"),
7790 pixel_type_node));
7791
4a5eab38
PB
7792 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
7793 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
7794 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
7795 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
8bb418a3
ZL
7796
7797 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7798 get_identifier ("__vector unsigned char"),
7799 unsigned_V16QI_type_node));
7800 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7801 get_identifier ("__vector signed char"),
7802 V16QI_type_node));
7803 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7804 get_identifier ("__vector __bool char"),
7805 bool_V16QI_type_node));
7806
7807 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7808 get_identifier ("__vector unsigned short"),
7809 unsigned_V8HI_type_node));
7810 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7811 get_identifier ("__vector signed short"),
7812 V8HI_type_node));
7813 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7814 get_identifier ("__vector __bool short"),
7815 bool_V8HI_type_node));
7816
7817 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7818 get_identifier ("__vector unsigned int"),
7819 unsigned_V4SI_type_node));
7820 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7821 get_identifier ("__vector signed int"),
7822 V4SI_type_node));
7823 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7824 get_identifier ("__vector __bool int"),
7825 bool_V4SI_type_node));
7826
7827 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7828 get_identifier ("__vector float"),
7829 V4SF_type_node));
7830 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7831 get_identifier ("__vector __pixel"),
7832 pixel_V8HI_type_node));
7833
a3170dc6 7834 if (TARGET_SPE)
3fdaa45a 7835 spe_init_builtins ();
0ac081f6
AH
7836 if (TARGET_ALTIVEC)
7837 altivec_init_builtins ();
0559cc77
DE
7838 if (TARGET_ALTIVEC || TARGET_SPE)
7839 rs6000_common_init_builtins ();
0ac081f6
AH
7840}
7841
a3170dc6
AH
7842/* Search through a set of builtins and enable the mask bits.
7843 DESC is an array of builtins.
b6d08ca1 7844 SIZE is the total number of builtins.
a3170dc6
AH
7845 START is the builtin enum at which to start.
7846 END is the builtin enum at which to end. */
0ac081f6 7847static void
a2369ed3 7848enable_mask_for_builtins (struct builtin_description *desc, int size,
f676971a 7849 enum rs6000_builtins start,
a2369ed3 7850 enum rs6000_builtins end)
a3170dc6
AH
7851{
7852 int i;
7853
7854 for (i = 0; i < size; ++i)
7855 if (desc[i].code == start)
7856 break;
7857
7858 if (i == size)
7859 return;
7860
7861 for (; i < size; ++i)
7862 {
7863 /* Flip all the bits on. */
7864 desc[i].mask = target_flags;
7865 if (desc[i].code == end)
7866 break;
7867 }
7868}
7869
7870static void
863d938c 7871spe_init_builtins (void)
0ac081f6 7872{
a3170dc6
AH
7873 tree endlink = void_list_node;
7874 tree puint_type_node = build_pointer_type (unsigned_type_node);
7875 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 7876 struct builtin_description *d;
0ac081f6
AH
7877 size_t i;
7878
a3170dc6
AH
7879 tree v2si_ftype_4_v2si
7880 = build_function_type
3fdaa45a
AH
7881 (opaque_V2SI_type_node,
7882 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7883 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7884 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7885 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7886 endlink)))));
7887
7888 tree v2sf_ftype_4_v2sf
7889 = build_function_type
3fdaa45a
AH
7890 (opaque_V2SF_type_node,
7891 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7892 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7893 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7894 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7895 endlink)))));
7896
7897 tree int_ftype_int_v2si_v2si
7898 = build_function_type
7899 (integer_type_node,
7900 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7901 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7902 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7903 endlink))));
7904
7905 tree int_ftype_int_v2sf_v2sf
7906 = build_function_type
7907 (integer_type_node,
7908 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7909 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7910 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7911 endlink))));
7912
7913 tree void_ftype_v2si_puint_int
7914 = build_function_type (void_type_node,
3fdaa45a 7915 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7916 tree_cons (NULL_TREE, puint_type_node,
7917 tree_cons (NULL_TREE,
7918 integer_type_node,
7919 endlink))));
7920
7921 tree void_ftype_v2si_puint_char
7922 = build_function_type (void_type_node,
3fdaa45a 7923 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7924 tree_cons (NULL_TREE, puint_type_node,
7925 tree_cons (NULL_TREE,
7926 char_type_node,
7927 endlink))));
7928
7929 tree void_ftype_v2si_pv2si_int
7930 = build_function_type (void_type_node,
3fdaa45a 7931 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7932 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7933 tree_cons (NULL_TREE,
7934 integer_type_node,
7935 endlink))));
7936
7937 tree void_ftype_v2si_pv2si_char
7938 = build_function_type (void_type_node,
3fdaa45a 7939 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7940 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7941 tree_cons (NULL_TREE,
7942 char_type_node,
7943 endlink))));
7944
7945 tree void_ftype_int
7946 = build_function_type (void_type_node,
7947 tree_cons (NULL_TREE, integer_type_node, endlink));
7948
7949 tree int_ftype_void
36e8d515 7950 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
7951
7952 tree v2si_ftype_pv2si_int
3fdaa45a 7953 = build_function_type (opaque_V2SI_type_node,
6035d635 7954 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7955 tree_cons (NULL_TREE, integer_type_node,
7956 endlink)));
7957
7958 tree v2si_ftype_puint_int
3fdaa45a 7959 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7960 tree_cons (NULL_TREE, puint_type_node,
7961 tree_cons (NULL_TREE, integer_type_node,
7962 endlink)));
7963
7964 tree v2si_ftype_pushort_int
3fdaa45a 7965 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7966 tree_cons (NULL_TREE, pushort_type_node,
7967 tree_cons (NULL_TREE, integer_type_node,
7968 endlink)));
7969
00332c9f
AH
7970 tree v2si_ftype_signed_char
7971 = build_function_type (opaque_V2SI_type_node,
7972 tree_cons (NULL_TREE, signed_char_type_node,
7973 endlink));
7974
a3170dc6
AH
7975 /* The initialization of the simple binary and unary builtins is
7976 done in rs6000_common_init_builtins, but we have to enable the
7977 mask bits here manually because we have run out of `target_flags'
7978 bits. We really need to redesign this mask business. */
7979
7980 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
7981 ARRAY_SIZE (bdesc_2arg),
7982 SPE_BUILTIN_EVADDW,
7983 SPE_BUILTIN_EVXOR);
7984 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
7985 ARRAY_SIZE (bdesc_1arg),
7986 SPE_BUILTIN_EVABS,
7987 SPE_BUILTIN_EVSUBFUSIAAW);
7988 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
7989 ARRAY_SIZE (bdesc_spe_predicates),
7990 SPE_BUILTIN_EVCMPEQ,
7991 SPE_BUILTIN_EVFSTSTLT);
7992 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
7993 ARRAY_SIZE (bdesc_spe_evsel),
7994 SPE_BUILTIN_EVSEL_CMPGTS,
7995 SPE_BUILTIN_EVSEL_FSTSTEQ);
7996
36252949
AH
7997 (*lang_hooks.decls.pushdecl)
7998 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
7999 opaque_V2SI_type_node));
8000
a3170dc6 8001 /* Initialize irregular SPE builtins. */
f676971a 8002
a3170dc6
AH
8003 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
8004 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
8005 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
8006 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
8007 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
8008 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
8009 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
8010 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
8011 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
8012 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
8013 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
8014 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
8015 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
8016 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
8017 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
8018 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
8019 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
8020 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
8021
8022 /* Loads. */
8023 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
8024 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
8025 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
8026 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
8027 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
8028 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
8029 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
8030 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
8031 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
8032 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
8033 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
8034 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
8035 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
8036 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
8037 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
8038 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
8039 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
8040 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
8041 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
8042 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
8043 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
8044 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
8045
8046 /* Predicates. */
8047 d = (struct builtin_description *) bdesc_spe_predicates;
8048 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
8049 {
8050 tree type;
8051
8052 switch (insn_data[d->icode].operand[1].mode)
8053 {
8054 case V2SImode:
8055 type = int_ftype_int_v2si_v2si;
8056 break;
8057 case V2SFmode:
8058 type = int_ftype_int_v2sf_v2sf;
8059 break;
8060 default:
8061 abort ();
8062 }
8063
8064 def_builtin (d->mask, d->name, type, d->code);
8065 }
8066
8067 /* Evsel predicates. */
8068 d = (struct builtin_description *) bdesc_spe_evsel;
8069 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
8070 {
8071 tree type;
8072
8073 switch (insn_data[d->icode].operand[1].mode)
8074 {
8075 case V2SImode:
8076 type = v2si_ftype_4_v2si;
8077 break;
8078 case V2SFmode:
8079 type = v2sf_ftype_4_v2sf;
8080 break;
8081 default:
8082 abort ();
8083 }
8084
8085 def_builtin (d->mask, d->name, type, d->code);
8086 }
8087}
8088
8089static void
863d938c 8090altivec_init_builtins (void)
a3170dc6
AH
8091{
8092 struct builtin_description *d;
8093 struct builtin_description_predicates *dp;
8094 size_t i;
8095 tree pfloat_type_node = build_pointer_type (float_type_node);
8096 tree pint_type_node = build_pointer_type (integer_type_node);
8097 tree pshort_type_node = build_pointer_type (short_integer_type_node);
8098 tree pchar_type_node = build_pointer_type (char_type_node);
8099
8100 tree pvoid_type_node = build_pointer_type (void_type_node);
8101
0dbc3651
ZW
8102 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
8103 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
8104 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
8105 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
8106
8107 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
8108
a3170dc6
AH
8109 tree int_ftype_int_v4si_v4si
8110 = build_function_type_list (integer_type_node,
8111 integer_type_node, V4SI_type_node,
8112 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
8113 tree v4sf_ftype_pcfloat
8114 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 8115 tree void_ftype_pfloat_v4sf
b4de2f7d 8116 = build_function_type_list (void_type_node,
a3170dc6 8117 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
8118 tree v4si_ftype_pcint
8119 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
8120 tree void_ftype_pint_v4si
b4de2f7d
AH
8121 = build_function_type_list (void_type_node,
8122 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
8123 tree v8hi_ftype_pcshort
8124 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 8125 tree void_ftype_pshort_v8hi
b4de2f7d
AH
8126 = build_function_type_list (void_type_node,
8127 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
8128 tree v16qi_ftype_pcchar
8129 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 8130 tree void_ftype_pchar_v16qi
b4de2f7d
AH
8131 = build_function_type_list (void_type_node,
8132 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 8133 tree void_ftype_v4si
b4de2f7d 8134 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
8135 tree v8hi_ftype_void
8136 = build_function_type (V8HI_type_node, void_list_node);
8137 tree void_ftype_void
8138 = build_function_type (void_type_node, void_list_node);
e34b6648
JJ
8139 tree void_ftype_int
8140 = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
0dbc3651 8141
b4a62fa0 8142 tree v16qi_ftype_long_pcvoid
a3170dc6 8143 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
8144 long_integer_type_node, pcvoid_type_node, NULL_TREE);
8145 tree v8hi_ftype_long_pcvoid
a3170dc6 8146 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
8147 long_integer_type_node, pcvoid_type_node, NULL_TREE);
8148 tree v4si_ftype_long_pcvoid
a3170dc6 8149 = build_function_type_list (V4SI_type_node,
b4a62fa0 8150 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 8151
b4a62fa0 8152 tree void_ftype_v4si_long_pvoid
b4de2f7d 8153 = build_function_type_list (void_type_node,
b4a62fa0 8154 V4SI_type_node, long_integer_type_node,
b4de2f7d 8155 pvoid_type_node, NULL_TREE);
b4a62fa0 8156 tree void_ftype_v16qi_long_pvoid
b4de2f7d 8157 = build_function_type_list (void_type_node,
b4a62fa0 8158 V16QI_type_node, long_integer_type_node,
b4de2f7d 8159 pvoid_type_node, NULL_TREE);
b4a62fa0 8160 tree void_ftype_v8hi_long_pvoid
b4de2f7d 8161 = build_function_type_list (void_type_node,
b4a62fa0 8162 V8HI_type_node, long_integer_type_node,
b4de2f7d 8163 pvoid_type_node, NULL_TREE);
a3170dc6
AH
8164 tree int_ftype_int_v8hi_v8hi
8165 = build_function_type_list (integer_type_node,
8166 integer_type_node, V8HI_type_node,
8167 V8HI_type_node, NULL_TREE);
8168 tree int_ftype_int_v16qi_v16qi
8169 = build_function_type_list (integer_type_node,
8170 integer_type_node, V16QI_type_node,
8171 V16QI_type_node, NULL_TREE);
8172 tree int_ftype_int_v4sf_v4sf
8173 = build_function_type_list (integer_type_node,
8174 integer_type_node, V4SF_type_node,
8175 V4SF_type_node, NULL_TREE);
8176 tree v4si_ftype_v4si
8177 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
8178 tree v8hi_ftype_v8hi
8179 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
8180 tree v16qi_ftype_v16qi
8181 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
8182 tree v4sf_ftype_v4sf
8183 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 8184 tree void_ftype_pcvoid_int_int
a3170dc6 8185 = build_function_type_list (void_type_node,
0dbc3651 8186 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
8187 integer_type_node, NULL_TREE);
8188 tree int_ftype_pcchar
8189 = build_function_type_list (integer_type_node,
8190 pcchar_type_node, NULL_TREE);
8191
0dbc3651
ZW
8192 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
8193 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
8194 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
8195 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
8196 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
8197 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
8198 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
8199 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
8200 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
8201 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
8202 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
8203 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
8204 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
8205 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
8206 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
8207 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
8208 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
8209 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
8210 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
e34b6648 8211 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_int, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
8212 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
8213 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
8214 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
8215 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
8216 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
8217 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
8218 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
8219 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
8220 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
8221 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
8222 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
8223 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 8224
8bb418a3
ZL
8225 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
8226 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
8227 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
8228
a3170dc6
AH
8229 /* Add the DST variants. */
8230 d = (struct builtin_description *) bdesc_dst;
8231 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 8232 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
8233
8234 /* Initialize the predicates. */
8235 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
8236 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
8237 {
8238 enum machine_mode mode1;
8239 tree type;
8240
8241 mode1 = insn_data[dp->icode].operand[1].mode;
8242
8243 switch (mode1)
8244 {
8245 case V4SImode:
8246 type = int_ftype_int_v4si_v4si;
8247 break;
8248 case V8HImode:
8249 type = int_ftype_int_v8hi_v8hi;
8250 break;
8251 case V16QImode:
8252 type = int_ftype_int_v16qi_v16qi;
8253 break;
8254 case V4SFmode:
8255 type = int_ftype_int_v4sf_v4sf;
8256 break;
8257 default:
8258 abort ();
8259 }
f676971a 8260
a3170dc6
AH
8261 def_builtin (dp->mask, dp->name, type, dp->code);
8262 }
8263
8264 /* Initialize the abs* operators. */
8265 d = (struct builtin_description *) bdesc_abs;
8266 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
8267 {
8268 enum machine_mode mode0;
8269 tree type;
8270
8271 mode0 = insn_data[d->icode].operand[0].mode;
8272
8273 switch (mode0)
8274 {
8275 case V4SImode:
8276 type = v4si_ftype_v4si;
8277 break;
8278 case V8HImode:
8279 type = v8hi_ftype_v8hi;
8280 break;
8281 case V16QImode:
8282 type = v16qi_ftype_v16qi;
8283 break;
8284 case V4SFmode:
8285 type = v4sf_ftype_v4sf;
8286 break;
8287 default:
8288 abort ();
8289 }
f676971a 8290
a3170dc6
AH
8291 def_builtin (d->mask, d->name, type, d->code);
8292 }
7ccf35ed 8293
13c62176
DN
8294 if (TARGET_ALTIVEC)
8295 {
8296 tree decl;
8297
8298 /* Initialize target builtin that implements
8299 targetm.vectorize.builtin_mask_for_load. */
8300
8301 decl = lang_hooks.builtin_function ("__builtin_altivec_mask_for_load",
8302 v16qi_ftype_long_pcvoid,
8303 ALTIVEC_BUILTIN_MASK_FOR_LOAD,
8304 BUILT_IN_MD, NULL, NULL_TREE);
8305 /* Record the decl. Will be used by rs6000_builtin_mask_for_load. */
8306 altivec_builtin_mask_for_load = decl;
8307
8308
8309 /* Initialize target builtin that implements
8310 targetm.vectorize.builtin_mask_for_store. */
8311
8312 decl = lang_hooks.builtin_function ("__builtin_altivec_mask_for_store",
8313 v16qi_ftype_long_pcvoid,
8314 ALTIVEC_BUILTIN_MASK_FOR_STORE,
8315 BUILT_IN_MD, NULL, NULL_TREE);
8316 /* Record the decl. Will be used by rs6000_builtin_mask_for_store. */
8317 altivec_builtin_mask_for_store = decl;
8318 }
a3170dc6
AH
8319}
8320
8321static void
863d938c 8322rs6000_common_init_builtins (void)
a3170dc6
AH
8323{
8324 struct builtin_description *d;
8325 size_t i;
8326
8327 tree v4sf_ftype_v4sf_v4sf_v16qi
8328 = build_function_type_list (V4SF_type_node,
8329 V4SF_type_node, V4SF_type_node,
8330 V16QI_type_node, NULL_TREE);
8331 tree v4si_ftype_v4si_v4si_v16qi
8332 = build_function_type_list (V4SI_type_node,
8333 V4SI_type_node, V4SI_type_node,
8334 V16QI_type_node, NULL_TREE);
8335 tree v8hi_ftype_v8hi_v8hi_v16qi
8336 = build_function_type_list (V8HI_type_node,
8337 V8HI_type_node, V8HI_type_node,
8338 V16QI_type_node, NULL_TREE);
8339 tree v16qi_ftype_v16qi_v16qi_v16qi
8340 = build_function_type_list (V16QI_type_node,
8341 V16QI_type_node, V16QI_type_node,
8342 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
8343 tree v4si_ftype_int
8344 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
8345 tree v8hi_ftype_int
8346 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
8347 tree v16qi_ftype_int
8348 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
8349 tree v8hi_ftype_v16qi
8350 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
8351 tree v4sf_ftype_v4sf
8352 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8353
8354 tree v2si_ftype_v2si_v2si
2abe3e28
AH
8355 = build_function_type_list (opaque_V2SI_type_node,
8356 opaque_V2SI_type_node,
8357 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
8358
8359 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
8360 = build_function_type_list (opaque_V2SF_type_node,
8361 opaque_V2SF_type_node,
8362 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
8363
8364 tree v2si_ftype_int_int
2abe3e28 8365 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
8366 integer_type_node, integer_type_node,
8367 NULL_TREE);
8368
8369 tree v2si_ftype_v2si
2abe3e28
AH
8370 = build_function_type_list (opaque_V2SI_type_node,
8371 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
8372
8373 tree v2sf_ftype_v2sf
2abe3e28
AH
8374 = build_function_type_list (opaque_V2SF_type_node,
8375 opaque_V2SF_type_node, NULL_TREE);
f676971a 8376
a3170dc6 8377 tree v2sf_ftype_v2si
2abe3e28
AH
8378 = build_function_type_list (opaque_V2SF_type_node,
8379 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
8380
8381 tree v2si_ftype_v2sf
2abe3e28
AH
8382 = build_function_type_list (opaque_V2SI_type_node,
8383 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
8384
8385 tree v2si_ftype_v2si_char
2abe3e28
AH
8386 = build_function_type_list (opaque_V2SI_type_node,
8387 opaque_V2SI_type_node,
8388 char_type_node, NULL_TREE);
a3170dc6
AH
8389
8390 tree v2si_ftype_int_char
2abe3e28 8391 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
8392 integer_type_node, char_type_node, NULL_TREE);
8393
8394 tree v2si_ftype_char
2abe3e28
AH
8395 = build_function_type_list (opaque_V2SI_type_node,
8396 char_type_node, NULL_TREE);
a3170dc6
AH
8397
8398 tree int_ftype_int_int
8399 = build_function_type_list (integer_type_node,
8400 integer_type_node, integer_type_node,
8401 NULL_TREE);
95385cbb 8402
0ac081f6 8403 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
8404 = build_function_type_list (V4SI_type_node,
8405 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 8406 tree v4sf_ftype_v4si_int
b4de2f7d 8407 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
8408 V4SI_type_node, integer_type_node, NULL_TREE);
8409 tree v4si_ftype_v4sf_int
b4de2f7d 8410 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
8411 V4SF_type_node, integer_type_node, NULL_TREE);
8412 tree v4si_ftype_v4si_int
b4de2f7d 8413 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
8414 V4SI_type_node, integer_type_node, NULL_TREE);
8415 tree v8hi_ftype_v8hi_int
b4de2f7d 8416 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
8417 V8HI_type_node, integer_type_node, NULL_TREE);
8418 tree v16qi_ftype_v16qi_int
b4de2f7d 8419 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
8420 V16QI_type_node, integer_type_node, NULL_TREE);
8421 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
8422 = build_function_type_list (V16QI_type_node,
8423 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
8424 integer_type_node, NULL_TREE);
8425 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
8426 = build_function_type_list (V8HI_type_node,
8427 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
8428 integer_type_node, NULL_TREE);
8429 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
8430 = build_function_type_list (V4SI_type_node,
8431 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
8432 integer_type_node, NULL_TREE);
8433 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
8434 = build_function_type_list (V4SF_type_node,
8435 V4SF_type_node, V4SF_type_node,
b9e4e5d1 8436 integer_type_node, NULL_TREE);
0ac081f6 8437 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
8438 = build_function_type_list (V4SF_type_node,
8439 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 8440 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
8441 = build_function_type_list (V4SF_type_node,
8442 V4SF_type_node, V4SF_type_node,
8443 V4SI_type_node, NULL_TREE);
2212663f 8444 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
8445 = build_function_type_list (V4SF_type_node,
8446 V4SF_type_node, V4SF_type_node,
8447 V4SF_type_node, NULL_TREE);
f676971a 8448 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
8449 = build_function_type_list (V4SI_type_node,
8450 V4SI_type_node, V4SI_type_node,
8451 V4SI_type_node, NULL_TREE);
0ac081f6 8452 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
8453 = build_function_type_list (V8HI_type_node,
8454 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 8455 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
8456 = build_function_type_list (V8HI_type_node,
8457 V8HI_type_node, V8HI_type_node,
8458 V8HI_type_node, NULL_TREE);
c4ad648e 8459 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
8460 = build_function_type_list (V4SI_type_node,
8461 V8HI_type_node, V8HI_type_node,
8462 V4SI_type_node, NULL_TREE);
c4ad648e 8463 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
8464 = build_function_type_list (V4SI_type_node,
8465 V16QI_type_node, V16QI_type_node,
8466 V4SI_type_node, NULL_TREE);
0ac081f6 8467 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
8468 = build_function_type_list (V16QI_type_node,
8469 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8470 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
8471 = build_function_type_list (V4SI_type_node,
8472 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 8473 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
8474 = build_function_type_list (V8HI_type_node,
8475 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8476 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
8477 = build_function_type_list (V4SI_type_node,
8478 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8479 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
8480 = build_function_type_list (V8HI_type_node,
8481 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 8482 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
8483 = build_function_type_list (V16QI_type_node,
8484 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8485 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
8486 = build_function_type_list (V4SI_type_node,
8487 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 8488 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
8489 = build_function_type_list (V4SI_type_node,
8490 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8491 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
8492 = build_function_type_list (V4SI_type_node,
8493 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
8494 tree v4si_ftype_v8hi
8495 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
8496 tree int_ftype_v4si_v4si
8497 = build_function_type_list (integer_type_node,
8498 V4SI_type_node, V4SI_type_node, NULL_TREE);
8499 tree int_ftype_v4sf_v4sf
8500 = build_function_type_list (integer_type_node,
8501 V4SF_type_node, V4SF_type_node, NULL_TREE);
8502 tree int_ftype_v16qi_v16qi
8503 = build_function_type_list (integer_type_node,
8504 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 8505 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
8506 = build_function_type_list (integer_type_node,
8507 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 8508
6f317ef3 8509 /* Add the simple ternary operators. */
2212663f 8510 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 8511 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f 8512 {
f676971a 8513
2212663f
DB
8514 enum machine_mode mode0, mode1, mode2, mode3;
8515 tree type;
8516
0559cc77 8517 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 8518 continue;
f676971a 8519
2212663f
DB
8520 mode0 = insn_data[d->icode].operand[0].mode;
8521 mode1 = insn_data[d->icode].operand[1].mode;
8522 mode2 = insn_data[d->icode].operand[2].mode;
8523 mode3 = insn_data[d->icode].operand[3].mode;
f676971a 8524
2212663f
DB
8525 /* When all four are of the same mode. */
8526 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
8527 {
8528 switch (mode0)
8529 {
617e0e1d
DB
8530 case V4SImode:
8531 type = v4si_ftype_v4si_v4si_v4si;
8532 break;
2212663f
DB
8533 case V4SFmode:
8534 type = v4sf_ftype_v4sf_v4sf_v4sf;
8535 break;
8536 case V8HImode:
8537 type = v8hi_ftype_v8hi_v8hi_v8hi;
f676971a 8538 break;
2212663f
DB
8539 case V16QImode:
8540 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8541 break;
2212663f 8542 default:
f676971a 8543 abort();
2212663f
DB
8544 }
8545 }
8546 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
c4ad648e 8547 {
2212663f
DB
8548 switch (mode0)
8549 {
8550 case V4SImode:
8551 type = v4si_ftype_v4si_v4si_v16qi;
8552 break;
8553 case V4SFmode:
8554 type = v4sf_ftype_v4sf_v4sf_v16qi;
8555 break;
8556 case V8HImode:
8557 type = v8hi_ftype_v8hi_v8hi_v16qi;
f676971a 8558 break;
2212663f
DB
8559 case V16QImode:
8560 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8561 break;
2212663f 8562 default:
f676971a 8563 abort();
2212663f
DB
8564 }
8565 }
f676971a 8566 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
2212663f 8567 && mode3 == V4SImode)
24408032 8568 type = v4si_ftype_v16qi_v16qi_v4si;
f676971a 8569 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
2212663f 8570 && mode3 == V4SImode)
24408032 8571 type = v4si_ftype_v8hi_v8hi_v4si;
f676971a 8572 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
617e0e1d 8573 && mode3 == V4SImode)
24408032
AH
8574 type = v4sf_ftype_v4sf_v4sf_v4si;
8575
8576 /* vchar, vchar, vchar, 4 bit literal. */
8577 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
8578 && mode3 == QImode)
b9e4e5d1 8579 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
8580
8581 /* vshort, vshort, vshort, 4 bit literal. */
8582 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
8583 && mode3 == QImode)
b9e4e5d1 8584 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
8585
8586 /* vint, vint, vint, 4 bit literal. */
8587 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
8588 && mode3 == QImode)
b9e4e5d1 8589 type = v4si_ftype_v4si_v4si_int;
24408032
AH
8590
8591 /* vfloat, vfloat, vfloat, 4 bit literal. */
8592 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
8593 && mode3 == QImode)
b9e4e5d1 8594 type = v4sf_ftype_v4sf_v4sf_int;
24408032 8595
2212663f
DB
8596 else
8597 abort ();
8598
8599 def_builtin (d->mask, d->name, type, d->code);
8600 }
8601
0ac081f6 8602 /* Add the simple binary operators. */
00b960c7 8603 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 8604 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
8605 {
8606 enum machine_mode mode0, mode1, mode2;
8607 tree type;
8608
0559cc77 8609 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6 8610 continue;
f676971a 8611
0ac081f6
AH
8612 mode0 = insn_data[d->icode].operand[0].mode;
8613 mode1 = insn_data[d->icode].operand[1].mode;
8614 mode2 = insn_data[d->icode].operand[2].mode;
8615
8616 /* When all three operands are of the same mode. */
8617 if (mode0 == mode1 && mode1 == mode2)
8618 {
8619 switch (mode0)
8620 {
8621 case V4SFmode:
8622 type = v4sf_ftype_v4sf_v4sf;
8623 break;
8624 case V4SImode:
8625 type = v4si_ftype_v4si_v4si;
8626 break;
8627 case V16QImode:
8628 type = v16qi_ftype_v16qi_v16qi;
8629 break;
8630 case V8HImode:
8631 type = v8hi_ftype_v8hi_v8hi;
8632 break;
a3170dc6
AH
8633 case V2SImode:
8634 type = v2si_ftype_v2si_v2si;
8635 break;
8636 case V2SFmode:
8637 type = v2sf_ftype_v2sf_v2sf;
8638 break;
8639 case SImode:
8640 type = int_ftype_int_int;
8641 break;
0ac081f6
AH
8642 default:
8643 abort ();
8644 }
8645 }
8646
8647 /* A few other combos we really don't want to do manually. */
8648
8649 /* vint, vfloat, vfloat. */
8650 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
8651 type = v4si_ftype_v4sf_v4sf;
8652
8653 /* vshort, vchar, vchar. */
8654 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
8655 type = v8hi_ftype_v16qi_v16qi;
8656
8657 /* vint, vshort, vshort. */
8658 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
8659 type = v4si_ftype_v8hi_v8hi;
8660
8661 /* vshort, vint, vint. */
8662 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
8663 type = v8hi_ftype_v4si_v4si;
8664
8665 /* vchar, vshort, vshort. */
8666 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
8667 type = v16qi_ftype_v8hi_v8hi;
8668
8669 /* vint, vchar, vint. */
8670 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
8671 type = v4si_ftype_v16qi_v4si;
8672
fa066a23
AH
8673 /* vint, vchar, vchar. */
8674 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
8675 type = v4si_ftype_v16qi_v16qi;
8676
0ac081f6
AH
8677 /* vint, vshort, vint. */
8678 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
8679 type = v4si_ftype_v8hi_v4si;
f676971a 8680
2212663f
DB
8681 /* vint, vint, 5 bit literal. */
8682 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8683 type = v4si_ftype_v4si_int;
f676971a 8684
2212663f
DB
8685 /* vshort, vshort, 5 bit literal. */
8686 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 8687 type = v8hi_ftype_v8hi_int;
f676971a 8688
2212663f
DB
8689 /* vchar, vchar, 5 bit literal. */
8690 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 8691 type = v16qi_ftype_v16qi_int;
0ac081f6 8692
617e0e1d
DB
8693 /* vfloat, vint, 5 bit literal. */
8694 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8695 type = v4sf_ftype_v4si_int;
f676971a 8696
617e0e1d
DB
8697 /* vint, vfloat, 5 bit literal. */
8698 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 8699 type = v4si_ftype_v4sf_int;
617e0e1d 8700
a3170dc6
AH
8701 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
8702 type = v2si_ftype_int_int;
8703
8704 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
8705 type = v2si_ftype_v2si_char;
8706
8707 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
8708 type = v2si_ftype_int_char;
8709
0ac081f6
AH
8710 /* int, x, x. */
8711 else if (mode0 == SImode)
8712 {
8713 switch (mode1)
8714 {
8715 case V4SImode:
8716 type = int_ftype_v4si_v4si;
8717 break;
8718 case V4SFmode:
8719 type = int_ftype_v4sf_v4sf;
8720 break;
8721 case V16QImode:
8722 type = int_ftype_v16qi_v16qi;
8723 break;
8724 case V8HImode:
8725 type = int_ftype_v8hi_v8hi;
8726 break;
8727 default:
8728 abort ();
8729 }
8730 }
8731
8732 else
8733 abort ();
8734
2212663f
DB
8735 def_builtin (d->mask, d->name, type, d->code);
8736 }
24408032 8737
2212663f
DB
8738 /* Add the simple unary operators. */
8739 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 8740 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
8741 {
8742 enum machine_mode mode0, mode1;
8743 tree type;
8744
0559cc77 8745 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 8746 continue;
f676971a 8747
2212663f
DB
8748 mode0 = insn_data[d->icode].operand[0].mode;
8749 mode1 = insn_data[d->icode].operand[1].mode;
8750
8751 if (mode0 == V4SImode && mode1 == QImode)
c4ad648e 8752 type = v4si_ftype_int;
2212663f 8753 else if (mode0 == V8HImode && mode1 == QImode)
c4ad648e 8754 type = v8hi_ftype_int;
2212663f 8755 else if (mode0 == V16QImode && mode1 == QImode)
c4ad648e 8756 type = v16qi_ftype_int;
617e0e1d
DB
8757 else if (mode0 == V4SFmode && mode1 == V4SFmode)
8758 type = v4sf_ftype_v4sf;
20e26713
AH
8759 else if (mode0 == V8HImode && mode1 == V16QImode)
8760 type = v8hi_ftype_v16qi;
8761 else if (mode0 == V4SImode && mode1 == V8HImode)
8762 type = v4si_ftype_v8hi;
a3170dc6
AH
8763 else if (mode0 == V2SImode && mode1 == V2SImode)
8764 type = v2si_ftype_v2si;
8765 else if (mode0 == V2SFmode && mode1 == V2SFmode)
8766 type = v2sf_ftype_v2sf;
8767 else if (mode0 == V2SFmode && mode1 == V2SImode)
8768 type = v2sf_ftype_v2si;
8769 else if (mode0 == V2SImode && mode1 == V2SFmode)
8770 type = v2si_ftype_v2sf;
8771 else if (mode0 == V2SImode && mode1 == QImode)
8772 type = v2si_ftype_char;
2212663f
DB
8773 else
8774 abort ();
8775
0ac081f6
AH
8776 def_builtin (d->mask, d->name, type, d->code);
8777 }
8778}
8779
c15c90bb
ZW
8780static void
8781rs6000_init_libfuncs (void)
8782{
8783 if (!TARGET_HARD_FLOAT)
8784 return;
8785
c9034561 8786 if (DEFAULT_ABI != ABI_V4)
c15c90bb 8787 {
c9034561 8788 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 8789 {
c9034561 8790 /* AIX library routines for float->int conversion. */
85363ca0
ZW
8791 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
8792 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
8793 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
8794 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
8795 }
8796
c9034561 8797 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8798 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
8799 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
8800 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
8801 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
8802 }
c9034561 8803 else
c15c90bb 8804 {
c9034561 8805 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8806
8807 set_optab_libfunc (add_optab, TFmode, "_q_add");
8808 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
8809 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
8810 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
8811 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
8812 if (TARGET_PPC_GPOPT || TARGET_POWER2)
8813 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
8814
c9034561
ZW
8815 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
8816 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
8817 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
8818 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
8819 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
8820 set_optab_libfunc (le_optab, TFmode, "_q_fle");
8821
85363ca0
ZW
8822 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
8823 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
8824 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
8825 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
8826 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
8827 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
8828 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
8829 }
8830}
fba73eb1
DE
8831
8832\f
8833/* Expand a block clear operation, and return 1 if successful. Return 0
8834 if we should let the compiler generate normal code.
8835
8836 operands[0] is the destination
8837 operands[1] is the length
8838 operands[2] is the alignment */
8839
8840int
8841expand_block_clear (rtx operands[])
8842{
8843 rtx orig_dest = operands[0];
8844 rtx bytes_rtx = operands[1];
8845 rtx align_rtx = operands[2];
5514620a
GK
8846 bool constp = (GET_CODE (bytes_rtx) == CONST_INT);
8847 HOST_WIDE_INT align;
8848 HOST_WIDE_INT bytes;
fba73eb1
DE
8849 int offset;
8850 int clear_bytes;
5514620a 8851 int clear_step;
fba73eb1
DE
8852
8853 /* If this is not a fixed size move, just call memcpy */
8854 if (! constp)
8855 return 0;
8856
8857 /* If this is not a fixed size alignment, abort */
8858 if (GET_CODE (align_rtx) != CONST_INT)
8859 abort ();
8860 align = INTVAL (align_rtx) * BITS_PER_UNIT;
8861
8862 /* Anything to clear? */
8863 bytes = INTVAL (bytes_rtx);
8864 if (bytes <= 0)
8865 return 1;
8866
5514620a
GK
8867 /* Use the builtin memset after a point, to avoid huge code bloat.
8868 When optimize_size, avoid any significant code bloat; calling
8869 memset is about 4 instructions, so allow for one instruction to
8870 load zero and three to do clearing. */
8871 if (TARGET_ALTIVEC && align >= 128)
8872 clear_step = 16;
8873 else if (TARGET_POWERPC64 && align >= 32)
8874 clear_step = 8;
8875 else
8876 clear_step = 4;
fba73eb1 8877
5514620a
GK
8878 if (optimize_size && bytes > 3 * clear_step)
8879 return 0;
8880 if (! optimize_size && bytes > 8 * clear_step)
fba73eb1
DE
8881 return 0;
8882
8883 for (offset = 0; bytes > 0; offset += clear_bytes, bytes -= clear_bytes)
8884 {
fba73eb1
DE
8885 enum machine_mode mode = BLKmode;
8886 rtx dest;
f676971a 8887
5514620a
GK
8888 if (bytes >= 16 && TARGET_ALTIVEC && align >= 128)
8889 {
8890 clear_bytes = 16;
8891 mode = V4SImode;
8892 }
8893 else if (bytes >= 8 && TARGET_POWERPC64
8894 /* 64-bit loads and stores require word-aligned
8895 displacements. */
8896 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
fba73eb1
DE
8897 {
8898 clear_bytes = 8;
8899 mode = DImode;
fba73eb1 8900 }
5514620a 8901 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
fba73eb1
DE
8902 { /* move 4 bytes */
8903 clear_bytes = 4;
8904 mode = SImode;
fba73eb1 8905 }
5514620a 8906 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
fba73eb1
DE
8907 { /* move 2 bytes */
8908 clear_bytes = 2;
8909 mode = HImode;
fba73eb1
DE
8910 }
8911 else /* move 1 byte at a time */
8912 {
8913 clear_bytes = 1;
8914 mode = QImode;
fba73eb1 8915 }
f676971a 8916
fba73eb1 8917 dest = adjust_address (orig_dest, mode, offset);
f676971a 8918
5514620a 8919 emit_move_insn (dest, CONST0_RTX (mode));
fba73eb1
DE
8920 }
8921
8922 return 1;
8923}
8924
35aff10b 8925\f
7e69e155
MM
8926/* Expand a block move operation, and return 1 if successful. Return 0
8927 if we should let the compiler generate normal code.
8928
8929 operands[0] is the destination
8930 operands[1] is the source
8931 operands[2] is the length
8932 operands[3] is the alignment */
8933
3933e0e1
MM
8934#define MAX_MOVE_REG 4
8935
7e69e155 8936int
a2369ed3 8937expand_block_move (rtx operands[])
7e69e155 8938{
b6c9286a
MM
8939 rtx orig_dest = operands[0];
8940 rtx orig_src = operands[1];
7e69e155 8941 rtx bytes_rtx = operands[2];
7e69e155 8942 rtx align_rtx = operands[3];
3933e0e1 8943 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 8944 int align;
3933e0e1
MM
8945 int bytes;
8946 int offset;
7e69e155 8947 int move_bytes;
cabfd258
GK
8948 rtx stores[MAX_MOVE_REG];
8949 int num_reg = 0;
7e69e155 8950
3933e0e1 8951 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 8952 if (! constp)
3933e0e1
MM
8953 return 0;
8954
5ee95df6
FS
8955 /* If this is not a fixed size alignment, abort */
8956 if (GET_CODE (align_rtx) != CONST_INT)
8957 abort ();
fba73eb1 8958 align = INTVAL (align_rtx) * BITS_PER_UNIT;
5ee95df6 8959
7e69e155 8960 /* Anything to move? */
3933e0e1
MM
8961 bytes = INTVAL (bytes_rtx);
8962 if (bytes <= 0)
7e69e155
MM
8963 return 1;
8964
ea9982a8 8965 /* store_one_arg depends on expand_block_move to handle at least the size of
f676971a 8966 reg_parm_stack_space. */
ea9982a8 8967 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
8968 return 0;
8969
cabfd258 8970 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 8971 {
cabfd258 8972 union {
70128ad9 8973 rtx (*movmemsi) (rtx, rtx, rtx, rtx);
a2369ed3 8974 rtx (*mov) (rtx, rtx);
cabfd258
GK
8975 } gen_func;
8976 enum machine_mode mode = BLKmode;
8977 rtx src, dest;
f676971a 8978
5514620a
GK
8979 /* Altivec first, since it will be faster than a string move
8980 when it applies, and usually not significantly larger. */
8981 if (TARGET_ALTIVEC && bytes >= 16 && align >= 128)
8982 {
8983 move_bytes = 16;
8984 mode = V4SImode;
8985 gen_func.mov = gen_movv4si;
8986 }
8987 else if (TARGET_STRING
cabfd258
GK
8988 && bytes > 24 /* move up to 32 bytes at a time */
8989 && ! fixed_regs[5]
8990 && ! fixed_regs[6]
8991 && ! fixed_regs[7]
8992 && ! fixed_regs[8]
8993 && ! fixed_regs[9]
8994 && ! fixed_regs[10]
8995 && ! fixed_regs[11]
8996 && ! fixed_regs[12])
7e69e155 8997 {
cabfd258 8998 move_bytes = (bytes > 32) ? 32 : bytes;
70128ad9 8999 gen_func.movmemsi = gen_movmemsi_8reg;
cabfd258
GK
9000 }
9001 else if (TARGET_STRING
9002 && bytes > 16 /* move up to 24 bytes at a time */
9003 && ! fixed_regs[5]
9004 && ! fixed_regs[6]
9005 && ! fixed_regs[7]
9006 && ! fixed_regs[8]
9007 && ! fixed_regs[9]
9008 && ! fixed_regs[10])
9009 {
9010 move_bytes = (bytes > 24) ? 24 : bytes;
70128ad9 9011 gen_func.movmemsi = gen_movmemsi_6reg;
cabfd258
GK
9012 }
9013 else if (TARGET_STRING
9014 && bytes > 8 /* move up to 16 bytes at a time */
9015 && ! fixed_regs[5]
9016 && ! fixed_regs[6]
9017 && ! fixed_regs[7]
9018 && ! fixed_regs[8])
9019 {
9020 move_bytes = (bytes > 16) ? 16 : bytes;
70128ad9 9021 gen_func.movmemsi = gen_movmemsi_4reg;
cabfd258
GK
9022 }
9023 else if (bytes >= 8 && TARGET_POWERPC64
9024 /* 64-bit loads and stores require word-aligned
9025 displacements. */
fba73eb1 9026 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
cabfd258
GK
9027 {
9028 move_bytes = 8;
9029 mode = DImode;
9030 gen_func.mov = gen_movdi;
9031 }
9032 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
9033 { /* move up to 8 bytes at a time */
9034 move_bytes = (bytes > 8) ? 8 : bytes;
70128ad9 9035 gen_func.movmemsi = gen_movmemsi_2reg;
cabfd258 9036 }
cd7d9ca4 9037 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
cabfd258
GK
9038 { /* move 4 bytes */
9039 move_bytes = 4;
9040 mode = SImode;
9041 gen_func.mov = gen_movsi;
9042 }
cd7d9ca4 9043 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
cabfd258
GK
9044 { /* move 2 bytes */
9045 move_bytes = 2;
9046 mode = HImode;
9047 gen_func.mov = gen_movhi;
9048 }
9049 else if (TARGET_STRING && bytes > 1)
9050 { /* move up to 4 bytes at a time */
9051 move_bytes = (bytes > 4) ? 4 : bytes;
70128ad9 9052 gen_func.movmemsi = gen_movmemsi_1reg;
cabfd258
GK
9053 }
9054 else /* move 1 byte at a time */
9055 {
9056 move_bytes = 1;
9057 mode = QImode;
9058 gen_func.mov = gen_movqi;
9059 }
f676971a 9060
cabfd258
GK
9061 src = adjust_address (orig_src, mode, offset);
9062 dest = adjust_address (orig_dest, mode, offset);
f676971a
EC
9063
9064 if (mode != BLKmode)
cabfd258
GK
9065 {
9066 rtx tmp_reg = gen_reg_rtx (mode);
f676971a 9067
cabfd258
GK
9068 emit_insn ((*gen_func.mov) (tmp_reg, src));
9069 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 9070 }
3933e0e1 9071
cabfd258
GK
9072 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
9073 {
9074 int i;
9075 for (i = 0; i < num_reg; i++)
9076 emit_insn (stores[i]);
9077 num_reg = 0;
9078 }
35aff10b 9079
cabfd258 9080 if (mode == BLKmode)
7e69e155 9081 {
70128ad9 9082 /* Move the address into scratch registers. The movmemsi
cabfd258
GK
9083 patterns require zero offset. */
9084 if (!REG_P (XEXP (src, 0)))
b6c9286a 9085 {
cabfd258
GK
9086 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
9087 src = replace_equiv_address (src, src_reg);
b6c9286a 9088 }
cabfd258 9089 set_mem_size (src, GEN_INT (move_bytes));
f676971a 9090
cabfd258 9091 if (!REG_P (XEXP (dest, 0)))
3933e0e1 9092 {
cabfd258
GK
9093 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
9094 dest = replace_equiv_address (dest, dest_reg);
7e69e155 9095 }
cabfd258 9096 set_mem_size (dest, GEN_INT (move_bytes));
f676971a 9097
70128ad9 9098 emit_insn ((*gen_func.movmemsi) (dest, src,
cabfd258
GK
9099 GEN_INT (move_bytes & 31),
9100 align_rtx));
7e69e155 9101 }
7e69e155
MM
9102 }
9103
9104 return 1;
9105}
9106
d62294f5
FJ
9107\f
9108/* Return 1 if OP is suitable for a save_world call in prologue. It is
9109 known to be a PARALLEL. */
9110int
9111save_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9112{
9113 int index;
9114 int i;
9115 rtx elt;
9116 int count = XVECLEN (op, 0);
9117
9118 if (count != 55)
9119 return 0;
9120
9121 index = 0;
9122 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
9123 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
9124 return 0;
9125
9126 for (i=1; i <= 18; i++)
9127 {
9128 elt = XVECEXP (op, 0, index++);
9129 if (GET_CODE (elt) != SET
9130 || GET_CODE (SET_DEST (elt)) != MEM
9131 || ! memory_operand (SET_DEST (elt), DFmode)
9132 || GET_CODE (SET_SRC (elt)) != REG
9133 || GET_MODE (SET_SRC (elt)) != DFmode)
9134 return 0;
9135 }
9136
9137 for (i=1; i <= 12; i++)
9138 {
9139 elt = XVECEXP (op, 0, index++);
9140 if (GET_CODE (elt) != SET
9141 || GET_CODE (SET_DEST (elt)) != MEM
9142 || GET_CODE (SET_SRC (elt)) != REG
9143 || GET_MODE (SET_SRC (elt)) != V4SImode)
9144 return 0;
9145 }
9146
9147 for (i=1; i <= 19; i++)
9148 {
9149 elt = XVECEXP (op, 0, index++);
9150 if (GET_CODE (elt) != SET
9151 || GET_CODE (SET_DEST (elt)) != MEM
9152 || ! memory_operand (SET_DEST (elt), Pmode)
9153 || GET_CODE (SET_SRC (elt)) != REG
9154 || GET_MODE (SET_SRC (elt)) != Pmode)
9155 return 0;
9156 }
9157
9158 elt = XVECEXP (op, 0, index++);
9159 if (GET_CODE (elt) != SET
9160 || GET_CODE (SET_DEST (elt)) != MEM
9161 || ! memory_operand (SET_DEST (elt), Pmode)
9162 || GET_CODE (SET_SRC (elt)) != REG
9163 || REGNO (SET_SRC (elt)) != CR2_REGNO
9164 || GET_MODE (SET_SRC (elt)) != Pmode)
9165 return 0;
9166
9167 if (GET_CODE (XVECEXP (op, 0, index++)) != USE
9168 || GET_CODE (XVECEXP (op, 0, index++)) != USE
9169 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
9170 return 0;
9171 return 1;
9172}
9173
9174/* Return 1 if OP is suitable for a save_world call in prologue. It is
9175 known to be a PARALLEL. */
9176int
9177restore_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9178{
9179 int index;
9180 int i;
9181 rtx elt;
9182 int count = XVECLEN (op, 0);
9183
9184 if (count != 59)
9185 return 0;
9186
9187 index = 0;
9188 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
9189 || GET_CODE (XVECEXP (op, 0, index++)) != USE
9190 || GET_CODE (XVECEXP (op, 0, index++)) != USE
9191 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
9192 return 0;
9193
9194 elt = XVECEXP (op, 0, index++);
9195 if (GET_CODE (elt) != SET
9196 || GET_CODE (SET_SRC (elt)) != MEM
9197 || ! memory_operand (SET_SRC (elt), Pmode)
9198 || GET_CODE (SET_DEST (elt)) != REG
9199 || REGNO (SET_DEST (elt)) != CR2_REGNO
9200 || GET_MODE (SET_DEST (elt)) != Pmode)
9201 return 0;
9202
9203 for (i=1; i <= 19; i++)
9204 {
9205 elt = XVECEXP (op, 0, index++);
9206 if (GET_CODE (elt) != SET
9207 || GET_CODE (SET_SRC (elt)) != MEM
9208 || ! memory_operand (SET_SRC (elt), Pmode)
9209 || GET_CODE (SET_DEST (elt)) != REG
9210 || GET_MODE (SET_DEST (elt)) != Pmode)
9211 return 0;
9212 }
9213
9214 for (i=1; i <= 12; i++)
9215 {
9216 elt = XVECEXP (op, 0, index++);
9217 if (GET_CODE (elt) != SET
9218 || GET_CODE (SET_SRC (elt)) != MEM
9219 || GET_CODE (SET_DEST (elt)) != REG
9220 || GET_MODE (SET_DEST (elt)) != V4SImode)
9221 return 0;
9222 }
9223
9224 for (i=1; i <= 18; i++)
9225 {
9226 elt = XVECEXP (op, 0, index++);
9227 if (GET_CODE (elt) != SET
9228 || GET_CODE (SET_SRC (elt)) != MEM
9229 || ! memory_operand (SET_SRC (elt), DFmode)
9230 || GET_CODE (SET_DEST (elt)) != REG
9231 || GET_MODE (SET_DEST (elt)) != DFmode)
9232 return 0;
9233 }
9234
9235 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
9236 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
9237 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
9238 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
9239 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
9240 return 0;
9241 return 1;
9242}
9243
9878760c
RK
9244\f
9245/* Return 1 if OP is a load multiple operation. It is known to be a
9246 PARALLEL and the first section will be tested. */
9247
9248int
a2369ed3 9249load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
9250{
9251 int count = XVECLEN (op, 0);
e2c953b6 9252 unsigned int dest_regno;
9878760c
RK
9253 rtx src_addr;
9254 int i;
9255
9256 /* Perform a quick check so we don't blow up below. */
9257 if (count <= 1
9258 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9259 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
9260 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
9261 return 0;
9262
9263 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9264 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
9265
9266 for (i = 1; i < count; i++)
9267 {
9268 rtx elt = XVECEXP (op, 0, i);
9269
9270 if (GET_CODE (elt) != SET
9271 || GET_CODE (SET_DEST (elt)) != REG
9272 || GET_MODE (SET_DEST (elt)) != SImode
9273 || REGNO (SET_DEST (elt)) != dest_regno + i
9274 || GET_CODE (SET_SRC (elt)) != MEM
9275 || GET_MODE (SET_SRC (elt)) != SImode
9276 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
9277 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
9278 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
9279 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
9280 return 0;
9281 }
9282
9283 return 1;
9284}
9285
9286/* Similar, but tests for store multiple. Here, the second vector element
9287 is a CLOBBER. It will be tested later. */
9288
9289int
a2369ed3 9290store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
9291{
9292 int count = XVECLEN (op, 0) - 1;
e2c953b6 9293 unsigned int src_regno;
9878760c
RK
9294 rtx dest_addr;
9295 int i;
9296
9297 /* Perform a quick check so we don't blow up below. */
9298 if (count <= 1
9299 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9300 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
9301 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
9302 return 0;
9303
9304 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9305 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
9306
9307 for (i = 1; i < count; i++)
9308 {
9309 rtx elt = XVECEXP (op, 0, i + 1);
9310
9311 if (GET_CODE (elt) != SET
9312 || GET_CODE (SET_SRC (elt)) != REG
9313 || GET_MODE (SET_SRC (elt)) != SImode
9314 || REGNO (SET_SRC (elt)) != src_regno + i
9315 || GET_CODE (SET_DEST (elt)) != MEM
9316 || GET_MODE (SET_DEST (elt)) != SImode
9317 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
9318 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
9319 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
9320 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
9321 return 0;
9322 }
9323
9324 return 1;
9325}
9ebbca7d 9326
9caa3eb2
DE
9327/* Return a string to perform a load_multiple operation.
9328 operands[0] is the vector.
9329 operands[1] is the source address.
9330 operands[2] is the first destination register. */
9331
9332const char *
a2369ed3 9333rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
9334{
9335 /* We have to handle the case where the pseudo used to contain the address
9336 is assigned to one of the output registers. */
9337 int i, j;
9338 int words = XVECLEN (operands[0], 0);
9339 rtx xop[10];
9340
9341 if (XVECLEN (operands[0], 0) == 1)
9342 return "{l|lwz} %2,0(%1)";
9343
9344 for (i = 0; i < words; i++)
9345 if (refers_to_regno_p (REGNO (operands[2]) + i,
9346 REGNO (operands[2]) + i + 1, operands[1], 0))
9347 {
9348 if (i == words-1)
9349 {
9350 xop[0] = GEN_INT (4 * (words-1));
9351 xop[1] = operands[1];
9352 xop[2] = operands[2];
9353 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
9354 return "";
9355 }
9356 else if (i == 0)
9357 {
9358 xop[0] = GEN_INT (4 * (words-1));
9359 xop[1] = operands[1];
9360 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
9361 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);
9362 return "";
9363 }
9364 else
9365 {
9366 for (j = 0; j < words; j++)
9367 if (j != i)
9368 {
9369 xop[0] = GEN_INT (j * 4);
9370 xop[1] = operands[1];
9371 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
9372 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
9373 }
9374 xop[0] = GEN_INT (i * 4);
9375 xop[1] = operands[1];
9376 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
9377 return "";
9378 }
9379 }
9380
9381 return "{lsi|lswi} %2,%1,%N0";
9382}
9383
00b960c7
AH
9384/* Return 1 for a parallel vrsave operation. */
9385
9386int
a2369ed3 9387vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
9388{
9389 int count = XVECLEN (op, 0);
9390 unsigned int dest_regno, src_regno;
9391 int i;
9392
9393 if (count <= 1
9394 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9395 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 9396 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
9397 return 0;
9398
9399 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9400 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9401
9402 if (dest_regno != VRSAVE_REGNO
9403 && src_regno != VRSAVE_REGNO)
9404 return 0;
9405
9406 for (i = 1; i < count; i++)
9407 {
9408 rtx elt = XVECEXP (op, 0, i);
9409
9aa86737
AH
9410 if (GET_CODE (elt) != CLOBBER
9411 && GET_CODE (elt) != SET)
00b960c7
AH
9412 return 0;
9413 }
9414
9415 return 1;
9416}
9417
2c4a9cff
DE
9418/* Return 1 for an PARALLEL suitable for mfcr. */
9419
9420int
a2369ed3 9421mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
9422{
9423 int count = XVECLEN (op, 0);
9424 int i;
9425
9426 /* Perform a quick check so we don't blow up below. */
9427 if (count < 1
9428 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9429 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
9430 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9431 return 0;
9432
9433 for (i = 0; i < count; i++)
9434 {
9435 rtx exp = XVECEXP (op, 0, i);
9436 rtx unspec;
9437 int maskval;
9438 rtx src_reg;
9439
9440 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
9441
9442 if (GET_CODE (src_reg) != REG
9443 || GET_MODE (src_reg) != CCmode
9444 || ! CR_REGNO_P (REGNO (src_reg)))
9445 return 0;
9446
9447 if (GET_CODE (exp) != SET
9448 || GET_CODE (SET_DEST (exp)) != REG
9449 || GET_MODE (SET_DEST (exp)) != SImode
9450 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
9451 return 0;
9452 unspec = SET_SRC (exp);
9453 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
9454
9455 if (GET_CODE (unspec) != UNSPEC
9456 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
9457 || XVECLEN (unspec, 0) != 2
9458 || XVECEXP (unspec, 0, 0) != src_reg
9459 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
9460 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
9461 return 0;
9462 }
9463 return 1;
9464}
9465
a4f6c312 9466/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
9467
9468int
a2369ed3 9469mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9470{
9471 int count = XVECLEN (op, 0);
9472 int i;
9ebbca7d
GK
9473 rtx src_reg;
9474
9475 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
9476 if (count < 1
9477 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9478 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
9479 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 9480 return 0;
e35b9579 9481 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
f676971a 9482
9ebbca7d
GK
9483 if (GET_CODE (src_reg) != REG
9484 || GET_MODE (src_reg) != SImode
9485 || ! INT_REGNO_P (REGNO (src_reg)))
9486 return 0;
9487
e35b9579 9488 for (i = 0; i < count; i++)
9ebbca7d
GK
9489 {
9490 rtx exp = XVECEXP (op, 0, i);
9491 rtx unspec;
9492 int maskval;
f676971a 9493
9ebbca7d
GK
9494 if (GET_CODE (exp) != SET
9495 || GET_CODE (SET_DEST (exp)) != REG
9496 || GET_MODE (SET_DEST (exp)) != CCmode
9497 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
9498 return 0;
9499 unspec = SET_SRC (exp);
9500 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
f676971a 9501
9ebbca7d 9502 if (GET_CODE (unspec) != UNSPEC
615158e2 9503 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
9504 || XVECLEN (unspec, 0) != 2
9505 || XVECEXP (unspec, 0, 0) != src_reg
9506 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
9507 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
9508 return 0;
9509 }
e35b9579 9510 return 1;
9ebbca7d
GK
9511}
9512
a4f6c312 9513/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
9514
9515int
a2369ed3 9516lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9517{
9518 int count = XVECLEN (op, 0);
e2c953b6 9519 unsigned int dest_regno;
9ebbca7d 9520 rtx src_addr;
e2c953b6 9521 unsigned int base_regno;
9ebbca7d
GK
9522 HOST_WIDE_INT offset;
9523 int i;
9524
9525 /* Perform a quick check so we don't blow up below. */
9526 if (count <= 1
9527 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9528 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
9529 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
9530 return 0;
9531
9532 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9533 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
9534
9535 if (dest_regno > 31
e2c953b6 9536 || count != 32 - (int) dest_regno)
9ebbca7d
GK
9537 return 0;
9538
4d588c14 9539 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
9540 {
9541 offset = 0;
9542 base_regno = REGNO (src_addr);
9543 if (base_regno == 0)
9544 return 0;
9545 }
76d2b81d 9546 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
9547 {
9548 offset = INTVAL (XEXP (src_addr, 1));
9549 base_regno = REGNO (XEXP (src_addr, 0));
9550 }
9551 else
9552 return 0;
9553
9554 for (i = 0; i < count; i++)
9555 {
9556 rtx elt = XVECEXP (op, 0, i);
9557 rtx newaddr;
9558 rtx addr_reg;
9559 HOST_WIDE_INT newoffset;
9560
9561 if (GET_CODE (elt) != SET
9562 || GET_CODE (SET_DEST (elt)) != REG
9563 || GET_MODE (SET_DEST (elt)) != SImode
9564 || REGNO (SET_DEST (elt)) != dest_regno + i
9565 || GET_CODE (SET_SRC (elt)) != MEM
9566 || GET_MODE (SET_SRC (elt)) != SImode)
9567 return 0;
9568 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 9569 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9570 {
9571 newoffset = 0;
9572 addr_reg = newaddr;
9573 }
76d2b81d 9574 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9575 {
9576 addr_reg = XEXP (newaddr, 0);
9577 newoffset = INTVAL (XEXP (newaddr, 1));
9578 }
9579 else
9580 return 0;
9581 if (REGNO (addr_reg) != base_regno
9582 || newoffset != offset + 4 * i)
9583 return 0;
9584 }
9585
9586 return 1;
9587}
9588
a4f6c312 9589/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
9590
9591int
a2369ed3 9592stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9593{
9594 int count = XVECLEN (op, 0);
e2c953b6 9595 unsigned int src_regno;
9ebbca7d 9596 rtx dest_addr;
e2c953b6 9597 unsigned int base_regno;
9ebbca7d
GK
9598 HOST_WIDE_INT offset;
9599 int i;
9600
9601 /* Perform a quick check so we don't blow up below. */
9602 if (count <= 1
9603 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9604 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
9605 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
9606 return 0;
9607
9608 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9609 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
9610
9611 if (src_regno > 31
e2c953b6 9612 || count != 32 - (int) src_regno)
9ebbca7d
GK
9613 return 0;
9614
4d588c14 9615 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
9616 {
9617 offset = 0;
9618 base_regno = REGNO (dest_addr);
9619 if (base_regno == 0)
9620 return 0;
9621 }
76d2b81d 9622 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
9623 {
9624 offset = INTVAL (XEXP (dest_addr, 1));
9625 base_regno = REGNO (XEXP (dest_addr, 0));
9626 }
9627 else
9628 return 0;
9629
9630 for (i = 0; i < count; i++)
9631 {
9632 rtx elt = XVECEXP (op, 0, i);
9633 rtx newaddr;
9634 rtx addr_reg;
9635 HOST_WIDE_INT newoffset;
9636
9637 if (GET_CODE (elt) != SET
9638 || GET_CODE (SET_SRC (elt)) != REG
9639 || GET_MODE (SET_SRC (elt)) != SImode
9640 || REGNO (SET_SRC (elt)) != src_regno + i
9641 || GET_CODE (SET_DEST (elt)) != MEM
9642 || GET_MODE (SET_DEST (elt)) != SImode)
9643 return 0;
9644 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 9645 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9646 {
9647 newoffset = 0;
9648 addr_reg = newaddr;
9649 }
76d2b81d 9650 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9651 {
9652 addr_reg = XEXP (newaddr, 0);
9653 newoffset = INTVAL (XEXP (newaddr, 1));
9654 }
9655 else
9656 return 0;
9657 if (REGNO (addr_reg) != base_regno
9658 || newoffset != offset + 4 * i)
9659 return 0;
9660 }
9661
9662 return 1;
9663}
9878760c 9664\f
a4f6c312
SS
9665/* A validation routine: say whether CODE, a condition code, and MODE
9666 match. The other alternatives either don't make sense or should
9667 never be generated. */
39a10a29 9668
39a10a29 9669static void
a2369ed3 9670validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 9671{
ec8e098d
PB
9672 if ((GET_RTX_CLASS (code) != RTX_COMPARE
9673 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
9674 || GET_MODE_CLASS (mode) != MODE_CC)
9675 abort ();
9676
9677 /* These don't make sense. */
9678 if ((code == GT || code == LT || code == GE || code == LE)
9679 && mode == CCUNSmode)
9680 abort ();
9681
9682 if ((code == GTU || code == LTU || code == GEU || code == LEU)
9683 && mode != CCUNSmode)
9684 abort ();
9685
9686 if (mode != CCFPmode
9687 && (code == ORDERED || code == UNORDERED
9688 || code == UNEQ || code == LTGT
9689 || code == UNGT || code == UNLT
9690 || code == UNGE || code == UNLE))
a4f6c312 9691 abort ();
f676971a
EC
9692
9693 /* These should never be generated except for
bc9ec0e0 9694 flag_finite_math_only. */
39a10a29 9695 if (mode == CCFPmode
ad72b533 9696 && ! flag_finite_math_only
39a10a29
GK
9697 && (code == LE || code == GE
9698 || code == UNEQ || code == LTGT
9699 || code == UNGT || code == UNLT))
9700 abort ();
9701
9702 /* These are invalid; the information is not there. */
f676971a 9703 if (mode == CCEQmode
39a10a29
GK
9704 && code != EQ && code != NE)
9705 abort ();
9706}
9707
9878760c
RK
9708/* Return 1 if OP is a comparison operation that is valid for a branch insn.
9709 We only check the opcode against the mode of the CC value here. */
9710
9711int
a2369ed3 9712branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
9713{
9714 enum rtx_code code = GET_CODE (op);
9715 enum machine_mode cc_mode;
9716
ec8e098d 9717 if (!COMPARISON_P (op))
9878760c
RK
9718 return 0;
9719
9720 cc_mode = GET_MODE (XEXP (op, 0));
9721 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
9722 return 0;
9723
39a10a29 9724 validate_condition_mode (code, cc_mode);
9878760c 9725
39a10a29
GK
9726 return 1;
9727}
9728
9729/* Return 1 if OP is a comparison operation that is valid for a branch
9730 insn and which is true if the corresponding bit in the CC register
9731 is set. */
9732
9733int
a2369ed3 9734branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
9735{
9736 enum rtx_code code;
9737
8daf2e65 9738 if (! branch_comparison_operator (op, mode))
9878760c
RK
9739 return 0;
9740
39a10a29
GK
9741 code = GET_CODE (op);
9742 return (code == EQ || code == LT || code == GT
9743 || code == LTU || code == GTU
9744 || code == UNORDERED);
9878760c
RK
9745}
9746
b7053a3f
GK
9747/* Return 1 if OP is a comparison operation that is valid for an scc
9748 insn: it must be a positive comparison. */
9878760c
RK
9749
9750int
a2369ed3 9751scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 9752{
b7053a3f 9753 return branch_positive_comparison_operator (op, mode);
9878760c 9754}
e0cd0770
JC
9755
9756int
a2369ed3 9757trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
9758{
9759 if (mode != VOIDmode && mode != GET_MODE (op))
9760 return 0;
ec8e098d 9761 return COMPARISON_P (op);
e0cd0770 9762}
dfbdccdb
GK
9763
9764int
a2369ed3 9765boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
9766{
9767 enum rtx_code code = GET_CODE (op);
9768 return (code == AND || code == IOR || code == XOR);
9769}
1d328b19
GK
9770
9771int
a2369ed3 9772boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
9773{
9774 enum rtx_code code = GET_CODE (op);
9775 return (code == IOR || code == XOR);
9776}
50a0b056
GK
9777
9778int
a2369ed3 9779min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
9780{
9781 enum rtx_code code = GET_CODE (op);
9782 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
9783}
9878760c
RK
9784\f
9785/* Return 1 if ANDOP is a mask that has no bits on that are not in the
9786 mask required to convert the result of a rotate insn into a shift
b1765bde 9787 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
9788
9789int
a2369ed3 9790includes_lshift_p (rtx shiftop, rtx andop)
9878760c 9791{
e2c953b6
DE
9792 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9793
9794 shift_mask <<= INTVAL (shiftop);
9878760c 9795
b1765bde 9796 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
9797}
9798
9799/* Similar, but for right shift. */
9800
9801int
a2369ed3 9802includes_rshift_p (rtx shiftop, rtx andop)
9878760c 9803{
a7653a2c 9804 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
9805
9806 shift_mask >>= INTVAL (shiftop);
9807
b1765bde 9808 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
9809}
9810
c5059423
AM
9811/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
9812 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 9813 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
9814
9815int
a2369ed3 9816includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 9817{
c5059423
AM
9818 if (GET_CODE (andop) == CONST_INT)
9819 {
02071907 9820 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 9821
c5059423 9822 c = INTVAL (andop);
02071907 9823 if (c == 0 || c == ~0)
c5059423 9824 return 0;
e2c953b6 9825
02071907 9826 shift_mask = ~0;
c5059423
AM
9827 shift_mask <<= INTVAL (shiftop);
9828
b6d08ca1 9829 /* Find the least significant one bit. */
c5059423
AM
9830 lsb = c & -c;
9831
9832 /* It must coincide with the LSB of the shift mask. */
9833 if (-lsb != shift_mask)
9834 return 0;
e2c953b6 9835
c5059423
AM
9836 /* Invert to look for the next transition (if any). */
9837 c = ~c;
9838
9839 /* Remove the low group of ones (originally low group of zeros). */
9840 c &= -lsb;
9841
9842 /* Again find the lsb, and check we have all 1's above. */
9843 lsb = c & -c;
9844 return c == -lsb;
9845 }
9846 else if (GET_CODE (andop) == CONST_DOUBLE
9847 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9848 {
02071907
AM
9849 HOST_WIDE_INT low, high, lsb;
9850 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
9851
9852 low = CONST_DOUBLE_LOW (andop);
9853 if (HOST_BITS_PER_WIDE_INT < 64)
9854 high = CONST_DOUBLE_HIGH (andop);
9855
9856 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 9857 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
9858 return 0;
9859
9860 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9861 {
02071907 9862 shift_mask_high = ~0;
c5059423
AM
9863 if (INTVAL (shiftop) > 32)
9864 shift_mask_high <<= INTVAL (shiftop) - 32;
9865
9866 lsb = high & -high;
9867
9868 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
9869 return 0;
9870
9871 high = ~high;
9872 high &= -lsb;
9873
9874 lsb = high & -high;
9875 return high == -lsb;
9876 }
9877
02071907 9878 shift_mask_low = ~0;
c5059423
AM
9879 shift_mask_low <<= INTVAL (shiftop);
9880
9881 lsb = low & -low;
9882
9883 if (-lsb != shift_mask_low)
9884 return 0;
9885
9886 if (HOST_BITS_PER_WIDE_INT < 64)
9887 high = ~high;
9888 low = ~low;
9889 low &= -lsb;
9890
9891 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9892 {
9893 lsb = high & -high;
9894 return high == -lsb;
9895 }
9896
9897 lsb = low & -low;
9898 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
9899 }
9900 else
9901 return 0;
9902}
e2c953b6 9903
c5059423
AM
9904/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
9905 to perform a left shift. It must have SHIFTOP or more least
c1207243 9906 significant 0's, with the remainder of the word 1's. */
e2c953b6 9907
c5059423 9908int
a2369ed3 9909includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 9910{
e2c953b6 9911 if (GET_CODE (andop) == CONST_INT)
c5059423 9912 {
02071907 9913 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 9914
02071907 9915 shift_mask = ~0;
c5059423
AM
9916 shift_mask <<= INTVAL (shiftop);
9917 c = INTVAL (andop);
9918
c1207243 9919 /* Find the least significant one bit. */
c5059423
AM
9920 lsb = c & -c;
9921
9922 /* It must be covered by the shift mask.
a4f6c312 9923 This test also rejects c == 0. */
c5059423
AM
9924 if ((lsb & shift_mask) == 0)
9925 return 0;
9926
9927 /* Check we have all 1's above the transition, and reject all 1's. */
9928 return c == -lsb && lsb != 1;
9929 }
9930 else if (GET_CODE (andop) == CONST_DOUBLE
9931 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9932 {
02071907 9933 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
9934
9935 low = CONST_DOUBLE_LOW (andop);
9936
9937 if (HOST_BITS_PER_WIDE_INT < 64)
9938 {
02071907 9939 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
9940
9941 high = CONST_DOUBLE_HIGH (andop);
9942
9943 if (low == 0)
9944 {
02071907 9945 shift_mask_high = ~0;
c5059423
AM
9946 if (INTVAL (shiftop) > 32)
9947 shift_mask_high <<= INTVAL (shiftop) - 32;
9948
9949 lsb = high & -high;
9950
9951 if ((lsb & shift_mask_high) == 0)
9952 return 0;
9953
9954 return high == -lsb;
9955 }
9956 if (high != ~0)
9957 return 0;
9958 }
9959
02071907 9960 shift_mask_low = ~0;
c5059423
AM
9961 shift_mask_low <<= INTVAL (shiftop);
9962
9963 lsb = low & -low;
9964
9965 if ((lsb & shift_mask_low) == 0)
9966 return 0;
9967
9968 return low == -lsb && lsb != 1;
9969 }
e2c953b6 9970 else
c5059423 9971 return 0;
9878760c 9972}
35068b43 9973
11ac38b2
DE
9974/* Return 1 if operands will generate a valid arguments to rlwimi
9975instruction for insert with right shift in 64-bit mode. The mask may
9976not start on the first bit or stop on the last bit because wrap-around
9977effects of instruction do not correspond to semantics of RTL insn. */
9978
9979int
9980insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop)
9981{
9982 if (INTVAL (startop) < 64
9983 && INTVAL (startop) > 32
9984 && (INTVAL (sizeop) + INTVAL (startop) < 64)
9985 && (INTVAL (sizeop) + INTVAL (startop) > 33)
9986 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) < 96)
9987 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) >= 64)
9988 && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop))
9989 return 1;
9990
9991 return 0;
9992}
9993
35068b43 9994/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
90f81f99 9995 for lfq and stfq insns iff the registers are hard registers. */
35068b43
RK
9996
9997int
a2369ed3 9998registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
9999{
10000 /* We might have been passed a SUBREG. */
f676971a 10001 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
35068b43 10002 return 0;
f676971a 10003
90f81f99
AP
10004 /* We might have been passed non floating point registers. */
10005 if (!FP_REGNO_P (REGNO (reg1))
10006 || !FP_REGNO_P (REGNO (reg2)))
10007 return 0;
35068b43
RK
10008
10009 return (REGNO (reg1) == REGNO (reg2) - 1);
10010}
10011
a4f6c312
SS
10012/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
10013 addr1 and addr2 must be in consecutive memory locations
10014 (addr2 == addr1 + 8). */
35068b43
RK
10015
10016int
90f81f99 10017mems_ok_for_quad_peep (rtx mem1, rtx mem2)
35068b43 10018{
90f81f99 10019 rtx addr1, addr2;
e2c953b6 10020 unsigned int reg1;
35068b43
RK
10021 int offset1;
10022
90f81f99
AP
10023 /* The mems cannot be volatile. */
10024 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
10025 return 0;
f676971a 10026
90f81f99
AP
10027 addr1 = XEXP (mem1, 0);
10028 addr2 = XEXP (mem2, 0);
10029
35068b43
RK
10030 /* Extract an offset (if used) from the first addr. */
10031 if (GET_CODE (addr1) == PLUS)
10032 {
10033 /* If not a REG, return zero. */
10034 if (GET_CODE (XEXP (addr1, 0)) != REG)
10035 return 0;
10036 else
10037 {
c4ad648e 10038 reg1 = REGNO (XEXP (addr1, 0));
35068b43
RK
10039 /* The offset must be constant! */
10040 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
c4ad648e
AM
10041 return 0;
10042 offset1 = INTVAL (XEXP (addr1, 1));
35068b43
RK
10043 }
10044 }
10045 else if (GET_CODE (addr1) != REG)
10046 return 0;
10047 else
10048 {
10049 reg1 = REGNO (addr1);
10050 /* This was a simple (mem (reg)) expression. Offset is 0. */
10051 offset1 = 0;
10052 }
10053
a2369ed3 10054 /* Make sure the second address is a (mem (plus (reg) (const_int)))
f676971a 10055 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
0f6937fe 10056 register as addr1. */
984e25ac 10057 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 10058 return 1;
35068b43
RK
10059 if (GET_CODE (addr2) != PLUS)
10060 return 0;
10061
10062 if (GET_CODE (XEXP (addr2, 0)) != REG
10063 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
10064 return 0;
10065
10066 if (reg1 != REGNO (XEXP (addr2, 0)))
10067 return 0;
10068
10069 /* The offset for the second addr must be 8 more than the first addr. */
10070 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
10071 return 0;
10072
10073 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
10074 instructions. */
10075 return 1;
10076}
9878760c
RK
10077\f
10078/* Return the register class of a scratch register needed to copy IN into
10079 or out of a register in CLASS in MODE. If it can be done directly,
10080 NO_REGS is returned. */
10081
10082enum reg_class
f676971a 10083secondary_reload_class (enum reg_class class,
a9baceb1
GK
10084 enum machine_mode mode ATTRIBUTE_UNUSED,
10085 rtx in)
9878760c 10086{
5accd822 10087 int regno;
9878760c 10088
ab82a49f
AP
10089 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
10090#if TARGET_MACHO
c4ad648e 10091 && MACHOPIC_INDIRECT
ab82a49f 10092#endif
c4ad648e 10093 ))
46fad5b7
DJ
10094 {
10095 /* We cannot copy a symbolic operand directly into anything
c4ad648e
AM
10096 other than BASE_REGS for TARGET_ELF. So indicate that a
10097 register from BASE_REGS is needed as an intermediate
10098 register.
f676971a 10099
46fad5b7
DJ
10100 On Darwin, pic addresses require a load from memory, which
10101 needs a base register. */
10102 if (class != BASE_REGS
c4ad648e
AM
10103 && (GET_CODE (in) == SYMBOL_REF
10104 || GET_CODE (in) == HIGH
10105 || GET_CODE (in) == LABEL_REF
10106 || GET_CODE (in) == CONST))
10107 return BASE_REGS;
46fad5b7 10108 }
e7b7998a 10109
5accd822
DE
10110 if (GET_CODE (in) == REG)
10111 {
10112 regno = REGNO (in);
10113 if (regno >= FIRST_PSEUDO_REGISTER)
10114 {
10115 regno = true_regnum (in);
10116 if (regno >= FIRST_PSEUDO_REGISTER)
10117 regno = -1;
10118 }
10119 }
10120 else if (GET_CODE (in) == SUBREG)
10121 {
10122 regno = true_regnum (in);
10123 if (regno >= FIRST_PSEUDO_REGISTER)
10124 regno = -1;
10125 }
10126 else
10127 regno = -1;
10128
9878760c
RK
10129 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
10130 into anything. */
10131 if (class == GENERAL_REGS || class == BASE_REGS
10132 || (regno >= 0 && INT_REGNO_P (regno)))
10133 return NO_REGS;
10134
10135 /* Constants, memory, and FP registers can go into FP registers. */
10136 if ((regno == -1 || FP_REGNO_P (regno))
10137 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
10138 return NO_REGS;
10139
0ac081f6
AH
10140 /* Memory, and AltiVec registers can go into AltiVec registers. */
10141 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
10142 && class == ALTIVEC_REGS)
10143 return NO_REGS;
10144
9878760c
RK
10145 /* We can copy among the CR registers. */
10146 if ((class == CR_REGS || class == CR0_REGS)
10147 && regno >= 0 && CR_REGNO_P (regno))
10148 return NO_REGS;
10149
10150 /* Otherwise, we need GENERAL_REGS. */
10151 return GENERAL_REGS;
10152}
10153\f
10154/* Given a comparison operation, return the bit number in CCR to test. We
f676971a 10155 know this is a valid comparison.
9878760c
RK
10156
10157 SCC_P is 1 if this is for an scc. That means that %D will have been
10158 used instead of %C, so the bits will be in different places.
10159
b4ac57ab 10160 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
10161
10162int
a2369ed3 10163ccr_bit (rtx op, int scc_p)
9878760c
RK
10164{
10165 enum rtx_code code = GET_CODE (op);
10166 enum machine_mode cc_mode;
10167 int cc_regnum;
10168 int base_bit;
9ebbca7d 10169 rtx reg;
9878760c 10170
ec8e098d 10171 if (!COMPARISON_P (op))
9878760c
RK
10172 return -1;
10173
9ebbca7d
GK
10174 reg = XEXP (op, 0);
10175
10176 if (GET_CODE (reg) != REG
10177 || ! CR_REGNO_P (REGNO (reg)))
10178 abort ();
10179
10180 cc_mode = GET_MODE (reg);
10181 cc_regnum = REGNO (reg);
10182 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 10183
39a10a29 10184 validate_condition_mode (code, cc_mode);
c5defebb 10185
b7053a3f
GK
10186 /* When generating a sCOND operation, only positive conditions are
10187 allowed. */
10188 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
10189 && code != GTU && code != LTU)
10190 abort ();
f676971a 10191
9878760c
RK
10192 switch (code)
10193 {
10194 case NE:
10195 return scc_p ? base_bit + 3 : base_bit + 2;
10196 case EQ:
10197 return base_bit + 2;
1c882ea4 10198 case GT: case GTU: case UNLE:
9878760c 10199 return base_bit + 1;
1c882ea4 10200 case LT: case LTU: case UNGE:
9878760c 10201 return base_bit;
1c882ea4
GK
10202 case ORDERED: case UNORDERED:
10203 return base_bit + 3;
9878760c
RK
10204
10205 case GE: case GEU:
39a10a29 10206 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
10207 unordered position. So test that bit. For integer, this is ! LT
10208 unless this is an scc insn. */
39a10a29 10209 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
10210
10211 case LE: case LEU:
39a10a29 10212 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 10213
9878760c
RK
10214 default:
10215 abort ();
10216 }
10217}
1ff7789b 10218\f
8d30c4ee 10219/* Return the GOT register. */
1ff7789b
MM
10220
10221struct rtx_def *
a2369ed3 10222rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 10223{
a4f6c312
SS
10224 /* The second flow pass currently (June 1999) can't update
10225 regs_ever_live without disturbing other parts of the compiler, so
10226 update it here to make the prolog/epilogue code happy. */
1db02437
FS
10227 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
10228 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 10229
8d30c4ee 10230 current_function_uses_pic_offset_table = 1;
3cb999d8 10231
1ff7789b
MM
10232 return pic_offset_table_rtx;
10233}
a7df97e6 10234\f
e2500fed
GK
10235/* Function to init struct machine_function.
10236 This will be called, via a pointer variable,
10237 from push_function_context. */
a7df97e6 10238
e2500fed 10239static struct machine_function *
863d938c 10240rs6000_init_machine_status (void)
a7df97e6 10241{
e2500fed 10242 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 10243}
9878760c 10244\f
0ba1b2ff
AM
10245/* These macros test for integers and extract the low-order bits. */
10246#define INT_P(X) \
10247((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
10248 && GET_MODE (X) == VOIDmode)
10249
10250#define INT_LOWPART(X) \
10251 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
10252
10253int
a2369ed3 10254extract_MB (rtx op)
0ba1b2ff
AM
10255{
10256 int i;
10257 unsigned long val = INT_LOWPART (op);
10258
10259 /* If the high bit is zero, the value is the first 1 bit we find
10260 from the left. */
10261 if ((val & 0x80000000) == 0)
10262 {
10263 if ((val & 0xffffffff) == 0)
10264 abort ();
10265
10266 i = 1;
10267 while (((val <<= 1) & 0x80000000) == 0)
10268 ++i;
10269 return i;
10270 }
10271
10272 /* If the high bit is set and the low bit is not, or the mask is all
10273 1's, the value is zero. */
10274 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
10275 return 0;
10276
10277 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
10278 from the right. */
10279 i = 31;
10280 while (((val >>= 1) & 1) != 0)
10281 --i;
10282
10283 return i;
10284}
10285
10286int
a2369ed3 10287extract_ME (rtx op)
0ba1b2ff
AM
10288{
10289 int i;
10290 unsigned long val = INT_LOWPART (op);
10291
10292 /* If the low bit is zero, the value is the first 1 bit we find from
10293 the right. */
10294 if ((val & 1) == 0)
10295 {
10296 if ((val & 0xffffffff) == 0)
10297 abort ();
10298
10299 i = 30;
10300 while (((val >>= 1) & 1) == 0)
10301 --i;
10302
10303 return i;
10304 }
10305
10306 /* If the low bit is set and the high bit is not, or the mask is all
10307 1's, the value is 31. */
10308 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
10309 return 31;
10310
10311 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
10312 from the left. */
10313 i = 0;
10314 while (((val <<= 1) & 0x80000000) != 0)
10315 ++i;
10316
10317 return i;
10318}
10319
c4501e62
JJ
10320/* Locate some local-dynamic symbol still in use by this function
10321 so that we can print its name in some tls_ld pattern. */
10322
10323static const char *
863d938c 10324rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
10325{
10326 rtx insn;
10327
10328 if (cfun->machine->some_ld_name)
10329 return cfun->machine->some_ld_name;
10330
10331 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
10332 if (INSN_P (insn)
10333 && for_each_rtx (&PATTERN (insn),
10334 rs6000_get_some_local_dynamic_name_1, 0))
10335 return cfun->machine->some_ld_name;
10336
10337 abort ();
10338}
10339
10340/* Helper function for rs6000_get_some_local_dynamic_name. */
10341
10342static int
a2369ed3 10343rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
10344{
10345 rtx x = *px;
10346
10347 if (GET_CODE (x) == SYMBOL_REF)
10348 {
10349 const char *str = XSTR (x, 0);
10350 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
10351 {
10352 cfun->machine->some_ld_name = str;
10353 return 1;
10354 }
10355 }
10356
10357 return 0;
10358}
10359
85b776df
AM
10360/* Write out a function code label. */
10361
10362void
10363rs6000_output_function_entry (FILE *file, const char *fname)
10364{
10365 if (fname[0] != '.')
10366 {
10367 switch (DEFAULT_ABI)
10368 {
10369 default:
10370 abort ();
10371
10372 case ABI_AIX:
10373 if (DOT_SYMBOLS)
10374 putc ('.', file);
10375 else
10376 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "L.");
10377 break;
10378
10379 case ABI_V4:
10380 case ABI_DARWIN:
10381 break;
10382 }
10383 }
10384 if (TARGET_AIX)
10385 RS6000_OUTPUT_BASENAME (file, fname);
10386 else
10387 assemble_name (file, fname);
10388}
10389
9878760c
RK
10390/* Print an operand. Recognize special options, documented below. */
10391
38c1f2d7 10392#if TARGET_ELF
d9407988 10393#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 10394#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
10395#else
10396#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 10397#define SMALL_DATA_REG 0
ba5e43aa
MM
10398#endif
10399
9878760c 10400void
a2369ed3 10401print_operand (FILE *file, rtx x, int code)
9878760c
RK
10402{
10403 int i;
a260abc9 10404 HOST_WIDE_INT val;
0ba1b2ff 10405 unsigned HOST_WIDE_INT uval;
9878760c
RK
10406
10407 switch (code)
10408 {
a8b3aeda 10409 case '.':
a85d226b
RK
10410 /* Write out an instruction after the call which may be replaced
10411 with glue code by the loader. This depends on the AIX version. */
10412 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
10413 return;
10414
81eace42
GK
10415 /* %a is output_address. */
10416
9854d9ed
RK
10417 case 'A':
10418 /* If X is a constant integer whose low-order 5 bits are zero,
10419 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 10420 in the AIX assembler where "sri" with a zero shift count
20e26713 10421 writes a trash instruction. */
9854d9ed 10422 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 10423 putc ('l', file);
9854d9ed 10424 else
76229ac8 10425 putc ('r', file);
9854d9ed
RK
10426 return;
10427
10428 case 'b':
e2c953b6
DE
10429 /* If constant, low-order 16 bits of constant, unsigned.
10430 Otherwise, write normally. */
10431 if (INT_P (x))
10432 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
10433 else
10434 print_operand (file, x, 0);
cad12a8d
RK
10435 return;
10436
a260abc9
DE
10437 case 'B':
10438 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
10439 for 64-bit mask direction. */
296b8152 10440 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 10441 return;
a260abc9 10442
81eace42
GK
10443 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
10444 output_operand. */
10445
423c1189
AH
10446 case 'c':
10447 /* X is a CR register. Print the number of the GT bit of the CR. */
10448 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10449 output_operand_lossage ("invalid %%E value");
10450 else
10451 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1);
10452 return;
10453
10454 case 'D':
6b1fedc3 10455 /* Like 'J' but get to the EQ bit. */
423c1189
AH
10456 if (GET_CODE (x) != REG)
10457 abort ();
10458
6b1fedc3
AH
10459 /* Bit 1 is EQ bit. */
10460 i = 4 * (REGNO (x) - CR0_REGNO) + 2;
423c1189
AH
10461
10462 /* If we want bit 31, write a shift count of zero, not 32. */
10463 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10464 return;
10465
9854d9ed 10466 case 'E':
39a10a29 10467 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
10468 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10469 output_operand_lossage ("invalid %%E value");
78fbdbf7 10470 else
39a10a29 10471 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 10472 return;
9854d9ed
RK
10473
10474 case 'f':
10475 /* X is a CR register. Print the shift count needed to move it
10476 to the high-order four bits. */
10477 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10478 output_operand_lossage ("invalid %%f value");
10479 else
9ebbca7d 10480 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
10481 return;
10482
10483 case 'F':
10484 /* Similar, but print the count for the rotate in the opposite
10485 direction. */
10486 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10487 output_operand_lossage ("invalid %%F value");
10488 else
9ebbca7d 10489 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
10490 return;
10491
10492 case 'G':
10493 /* X is a constant integer. If it is negative, print "m",
43aa4e05 10494 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
10495 if (GET_CODE (x) != CONST_INT)
10496 output_operand_lossage ("invalid %%G value");
10497 else if (INTVAL (x) >= 0)
76229ac8 10498 putc ('z', file);
9854d9ed 10499 else
76229ac8 10500 putc ('m', file);
9854d9ed 10501 return;
e2c953b6 10502
9878760c 10503 case 'h':
a4f6c312
SS
10504 /* If constant, output low-order five bits. Otherwise, write
10505 normally. */
9878760c 10506 if (INT_P (x))
5f59ecb7 10507 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
10508 else
10509 print_operand (file, x, 0);
10510 return;
10511
64305719 10512 case 'H':
a4f6c312
SS
10513 /* If constant, output low-order six bits. Otherwise, write
10514 normally. */
64305719 10515 if (INT_P (x))
5f59ecb7 10516 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
10517 else
10518 print_operand (file, x, 0);
10519 return;
10520
9854d9ed
RK
10521 case 'I':
10522 /* Print `i' if this is a constant, else nothing. */
9878760c 10523 if (INT_P (x))
76229ac8 10524 putc ('i', file);
9878760c
RK
10525 return;
10526
9854d9ed
RK
10527 case 'j':
10528 /* Write the bit number in CCR for jump. */
10529 i = ccr_bit (x, 0);
10530 if (i == -1)
10531 output_operand_lossage ("invalid %%j code");
9878760c 10532 else
9854d9ed 10533 fprintf (file, "%d", i);
9878760c
RK
10534 return;
10535
9854d9ed
RK
10536 case 'J':
10537 /* Similar, but add one for shift count in rlinm for scc and pass
10538 scc flag to `ccr_bit'. */
10539 i = ccr_bit (x, 1);
10540 if (i == -1)
10541 output_operand_lossage ("invalid %%J code");
10542 else
a0466a68
RK
10543 /* If we want bit 31, write a shift count of zero, not 32. */
10544 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
10545 return;
10546
9854d9ed
RK
10547 case 'k':
10548 /* X must be a constant. Write the 1's complement of the
10549 constant. */
9878760c 10550 if (! INT_P (x))
9854d9ed 10551 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
10552 else
10553 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
10554 return;
10555
81eace42 10556 case 'K':
9ebbca7d
GK
10557 /* X must be a symbolic constant on ELF. Write an
10558 expression suitable for an 'addi' that adds in the low 16
10559 bits of the MEM. */
10560 if (GET_CODE (x) != CONST)
10561 {
10562 print_operand_address (file, x);
10563 fputs ("@l", file);
10564 }
10565 else
10566 {
10567 if (GET_CODE (XEXP (x, 0)) != PLUS
10568 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
10569 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
10570 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 10571 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
10572 print_operand_address (file, XEXP (XEXP (x, 0), 0));
10573 fputs ("@l", file);
ed8d2920
MM
10574 /* For GNU as, there must be a non-alphanumeric character
10575 between 'l' and the number. The '-' is added by
10576 print_operand() already. */
10577 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
10578 fputs ("+", file);
9ebbca7d
GK
10579 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
10580 }
81eace42
GK
10581 return;
10582
10583 /* %l is output_asm_label. */
9ebbca7d 10584
9854d9ed
RK
10585 case 'L':
10586 /* Write second word of DImode or DFmode reference. Works on register
10587 or non-indexed memory only. */
10588 if (GET_CODE (x) == REG)
fb5c67a7 10589 fputs (reg_names[REGNO (x) + 1], file);
9854d9ed
RK
10590 else if (GET_CODE (x) == MEM)
10591 {
10592 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 10593 we have already done it, we can just use an offset of word. */
9854d9ed
RK
10594 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10595 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
10596 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
10597 UNITS_PER_WORD));
9854d9ed 10598 else
d7624dc0
RK
10599 output_address (XEXP (adjust_address_nv (x, SImode,
10600 UNITS_PER_WORD),
10601 0));
ed8908e7 10602
ba5e43aa 10603 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10604 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10605 reg_names[SMALL_DATA_REG]);
9854d9ed 10606 }
9878760c 10607 return;
f676971a 10608
9878760c
RK
10609 case 'm':
10610 /* MB value for a mask operand. */
b1765bde 10611 if (! mask_operand (x, SImode))
9878760c
RK
10612 output_operand_lossage ("invalid %%m value");
10613
0ba1b2ff 10614 fprintf (file, "%d", extract_MB (x));
9878760c
RK
10615 return;
10616
10617 case 'M':
10618 /* ME value for a mask operand. */
b1765bde 10619 if (! mask_operand (x, SImode))
a260abc9 10620 output_operand_lossage ("invalid %%M value");
9878760c 10621
0ba1b2ff 10622 fprintf (file, "%d", extract_ME (x));
9878760c
RK
10623 return;
10624
81eace42
GK
10625 /* %n outputs the negative of its operand. */
10626
9878760c
RK
10627 case 'N':
10628 /* Write the number of elements in the vector times 4. */
10629 if (GET_CODE (x) != PARALLEL)
10630 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
10631 else
10632 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
10633 return;
10634
10635 case 'O':
10636 /* Similar, but subtract 1 first. */
10637 if (GET_CODE (x) != PARALLEL)
1427100a 10638 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
10639 else
10640 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
10641 return;
10642
9854d9ed
RK
10643 case 'p':
10644 /* X is a CONST_INT that is a power of two. Output the logarithm. */
10645 if (! INT_P (x)
2bfcf297 10646 || INT_LOWPART (x) < 0
9854d9ed
RK
10647 || (i = exact_log2 (INT_LOWPART (x))) < 0)
10648 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
10649 else
10650 fprintf (file, "%d", i);
9854d9ed
RK
10651 return;
10652
9878760c
RK
10653 case 'P':
10654 /* The operand must be an indirect memory reference. The result
8bb418a3 10655 is the register name. */
9878760c
RK
10656 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
10657 || REGNO (XEXP (x, 0)) >= 32)
10658 output_operand_lossage ("invalid %%P value");
e2c953b6 10659 else
fb5c67a7 10660 fputs (reg_names[REGNO (XEXP (x, 0))], file);
9878760c
RK
10661 return;
10662
dfbdccdb
GK
10663 case 'q':
10664 /* This outputs the logical code corresponding to a boolean
10665 expression. The expression may have one or both operands
39a10a29 10666 negated (if one, only the first one). For condition register
c4ad648e
AM
10667 logical operations, it will also treat the negated
10668 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 10669 {
63bc1d05 10670 const char *const *t = 0;
dfbdccdb
GK
10671 const char *s;
10672 enum rtx_code code = GET_CODE (x);
10673 static const char * const tbl[3][3] = {
10674 { "and", "andc", "nor" },
10675 { "or", "orc", "nand" },
10676 { "xor", "eqv", "xor" } };
10677
10678 if (code == AND)
10679 t = tbl[0];
10680 else if (code == IOR)
10681 t = tbl[1];
10682 else if (code == XOR)
10683 t = tbl[2];
10684 else
10685 output_operand_lossage ("invalid %%q value");
10686
10687 if (GET_CODE (XEXP (x, 0)) != NOT)
10688 s = t[0];
10689 else
10690 {
10691 if (GET_CODE (XEXP (x, 1)) == NOT)
10692 s = t[2];
10693 else
10694 s = t[1];
10695 }
f676971a 10696
dfbdccdb
GK
10697 fputs (s, file);
10698 }
10699 return;
10700
2c4a9cff
DE
10701 case 'Q':
10702 if (TARGET_MFCRF)
3b6ce0af 10703 fputc (',', file);
5efb1046 10704 /* FALLTHRU */
2c4a9cff
DE
10705 else
10706 return;
10707
9854d9ed
RK
10708 case 'R':
10709 /* X is a CR register. Print the mask for `mtcrf'. */
10710 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10711 output_operand_lossage ("invalid %%R value");
10712 else
9ebbca7d 10713 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 10714 return;
9854d9ed
RK
10715
10716 case 's':
10717 /* Low 5 bits of 32 - value */
10718 if (! INT_P (x))
10719 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
10720 else
10721 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 10722 return;
9854d9ed 10723
a260abc9 10724 case 'S':
0ba1b2ff 10725 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
10726 CONST_INT 32-bit mask is considered sign-extended so any
10727 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 10728 if (! mask64_operand (x, DImode))
a260abc9
DE
10729 output_operand_lossage ("invalid %%S value");
10730
0ba1b2ff 10731 uval = INT_LOWPART (x);
a260abc9 10732
0ba1b2ff 10733 if (uval & 1) /* Clear Left */
a260abc9 10734 {
f099d360
GK
10735#if HOST_BITS_PER_WIDE_INT > 64
10736 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10737#endif
0ba1b2ff 10738 i = 64;
a260abc9 10739 }
0ba1b2ff 10740 else /* Clear Right */
a260abc9 10741 {
0ba1b2ff 10742 uval = ~uval;
f099d360
GK
10743#if HOST_BITS_PER_WIDE_INT > 64
10744 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10745#endif
0ba1b2ff 10746 i = 63;
a260abc9 10747 }
0ba1b2ff
AM
10748 while (uval != 0)
10749 --i, uval >>= 1;
10750 if (i < 0)
10751 abort ();
10752 fprintf (file, "%d", i);
10753 return;
a260abc9 10754
a3170dc6
AH
10755 case 't':
10756 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
10757 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
10758 abort ();
10759
10760 /* Bit 3 is OV bit. */
10761 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
10762
10763 /* If we want bit 31, write a shift count of zero, not 32. */
10764 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10765 return;
10766
cccf3bdc
DE
10767 case 'T':
10768 /* Print the symbolic name of a branch target register. */
10769 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
10770 && REGNO (x) != COUNT_REGISTER_REGNUM))
10771 output_operand_lossage ("invalid %%T value");
e2c953b6 10772 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
10773 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
10774 else
10775 fputs ("ctr", file);
10776 return;
10777
9854d9ed 10778 case 'u':
802a0058 10779 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
10780 if (! INT_P (x))
10781 output_operand_lossage ("invalid %%u value");
e2c953b6 10782 else
f676971a 10783 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
e2c953b6 10784 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
10785 return;
10786
802a0058
MM
10787 case 'v':
10788 /* High-order 16 bits of constant for use in signed operand. */
10789 if (! INT_P (x))
10790 output_operand_lossage ("invalid %%v value");
e2c953b6 10791 else
134c32f6
DE
10792 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
10793 (INT_LOWPART (x) >> 16) & 0xffff);
10794 return;
802a0058 10795
9854d9ed
RK
10796 case 'U':
10797 /* Print `u' if this has an auto-increment or auto-decrement. */
10798 if (GET_CODE (x) == MEM
10799 && (GET_CODE (XEXP (x, 0)) == PRE_INC
10800 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 10801 putc ('u', file);
9854d9ed 10802 return;
9878760c 10803
e0cd0770
JC
10804 case 'V':
10805 /* Print the trap code for this operand. */
10806 switch (GET_CODE (x))
10807 {
10808 case EQ:
10809 fputs ("eq", file); /* 4 */
10810 break;
10811 case NE:
10812 fputs ("ne", file); /* 24 */
10813 break;
10814 case LT:
10815 fputs ("lt", file); /* 16 */
10816 break;
10817 case LE:
10818 fputs ("le", file); /* 20 */
10819 break;
10820 case GT:
10821 fputs ("gt", file); /* 8 */
10822 break;
10823 case GE:
10824 fputs ("ge", file); /* 12 */
10825 break;
10826 case LTU:
10827 fputs ("llt", file); /* 2 */
10828 break;
10829 case LEU:
10830 fputs ("lle", file); /* 6 */
10831 break;
10832 case GTU:
10833 fputs ("lgt", file); /* 1 */
10834 break;
10835 case GEU:
10836 fputs ("lge", file); /* 5 */
10837 break;
10838 default:
10839 abort ();
10840 }
10841 break;
10842
9854d9ed
RK
10843 case 'w':
10844 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
10845 normally. */
10846 if (INT_P (x))
f676971a 10847 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5f59ecb7 10848 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
10849 else
10850 print_operand (file, x, 0);
9878760c
RK
10851 return;
10852
9854d9ed 10853 case 'W':
e2c953b6 10854 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
10855 val = (GET_CODE (x) == CONST_INT
10856 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
10857
10858 if (val < 0)
10859 i = -1;
9854d9ed 10860 else
e2c953b6
DE
10861 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
10862 if ((val <<= 1) < 0)
10863 break;
10864
10865#if HOST_BITS_PER_WIDE_INT == 32
10866 if (GET_CODE (x) == CONST_INT && i >= 0)
10867 i += 32; /* zero-extend high-part was all 0's */
10868 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
10869 {
10870 val = CONST_DOUBLE_LOW (x);
10871
10872 if (val == 0)
a4f6c312 10873 abort ();
e2c953b6
DE
10874 else if (val < 0)
10875 --i;
10876 else
10877 for ( ; i < 64; i++)
10878 if ((val <<= 1) < 0)
10879 break;
10880 }
10881#endif
10882
10883 fprintf (file, "%d", i + 1);
9854d9ed 10884 return;
9878760c 10885
9854d9ed
RK
10886 case 'X':
10887 if (GET_CODE (x) == MEM
4d588c14 10888 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 10889 putc ('x', file);
9854d9ed 10890 return;
9878760c 10891
9854d9ed
RK
10892 case 'Y':
10893 /* Like 'L', for third word of TImode */
10894 if (GET_CODE (x) == REG)
fb5c67a7 10895 fputs (reg_names[REGNO (x) + 2], file);
9854d9ed 10896 else if (GET_CODE (x) == MEM)
9878760c 10897 {
9854d9ed
RK
10898 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10899 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10900 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 10901 else
d7624dc0 10902 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 10903 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10904 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10905 reg_names[SMALL_DATA_REG]);
9878760c
RK
10906 }
10907 return;
f676971a 10908
9878760c 10909 case 'z':
b4ac57ab
RS
10910 /* X is a SYMBOL_REF. Write out the name preceded by a
10911 period and without any trailing data in brackets. Used for function
4d30c363
MM
10912 names. If we are configured for System V (or the embedded ABI) on
10913 the PowerPC, do not emit the period, since those systems do not use
10914 TOCs and the like. */
9878760c
RK
10915 if (GET_CODE (x) != SYMBOL_REF)
10916 abort ();
10917
c4ad648e
AM
10918 /* Mark the decl as referenced so that cgraph will output the
10919 function. */
9bf6462a 10920 if (SYMBOL_REF_DECL (x))
c4ad648e 10921 mark_decl_referenced (SYMBOL_REF_DECL (x));
9bf6462a 10922
85b776df 10923 /* For macho, check to see if we need a stub. */
f9da97f0
AP
10924 if (TARGET_MACHO)
10925 {
10926 const char *name = XSTR (x, 0);
a031e781 10927#if TARGET_MACHO
3b48085e 10928 if (MACHOPIC_INDIRECT
11abc112
MM
10929 && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10930 name = machopic_indirection_name (x, /*stub_p=*/true);
f9da97f0
AP
10931#endif
10932 assemble_name (file, name);
10933 }
85b776df 10934 else if (!DOT_SYMBOLS)
9739c90c 10935 assemble_name (file, XSTR (x, 0));
85b776df
AM
10936 else
10937 rs6000_output_function_entry (file, XSTR (x, 0));
9878760c
RK
10938 return;
10939
9854d9ed
RK
10940 case 'Z':
10941 /* Like 'L', for last word of TImode. */
10942 if (GET_CODE (x) == REG)
fb5c67a7 10943 fputs (reg_names[REGNO (x) + 3], file);
9854d9ed
RK
10944 else if (GET_CODE (x) == MEM)
10945 {
10946 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10947 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10948 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 10949 else
d7624dc0 10950 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 10951 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10952 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10953 reg_names[SMALL_DATA_REG]);
9854d9ed 10954 }
5c23c401 10955 return;
0ac081f6 10956
a3170dc6 10957 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
10958 case 'y':
10959 {
10960 rtx tmp;
10961
10962 if (GET_CODE (x) != MEM)
10963 abort ();
10964
10965 tmp = XEXP (x, 0);
10966
993f19a8 10967 if (TARGET_E500)
a3170dc6
AH
10968 {
10969 /* Handle [reg]. */
10970 if (GET_CODE (tmp) == REG)
10971 {
10972 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
10973 break;
10974 }
10975 /* Handle [reg+UIMM]. */
10976 else if (GET_CODE (tmp) == PLUS &&
10977 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
10978 {
10979 int x;
10980
10981 if (GET_CODE (XEXP (tmp, 0)) != REG)
10982 abort ();
10983
10984 x = INTVAL (XEXP (tmp, 1));
10985 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
10986 break;
10987 }
10988
10989 /* Fall through. Must be [reg+reg]. */
10990 }
850e8d3d
DN
10991 if (TARGET_ALTIVEC
10992 && GET_CODE (tmp) == AND
10993 && GET_CODE (XEXP (tmp, 1)) == CONST_INT
10994 && INTVAL (XEXP (tmp, 1)) == -16)
10995 tmp = XEXP (tmp, 0);
0ac081f6 10996 if (GET_CODE (tmp) == REG)
c62f2db5 10997 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
10998 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
10999 {
11000 if (REGNO (XEXP (tmp, 0)) == 0)
11001 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
11002 reg_names[ REGNO (XEXP (tmp, 0)) ]);
11003 else
11004 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
11005 reg_names[ REGNO (XEXP (tmp, 1)) ]);
11006 }
11007 else
11008 abort ();
11009 break;
11010 }
f676971a 11011
9878760c
RK
11012 case 0:
11013 if (GET_CODE (x) == REG)
11014 fprintf (file, "%s", reg_names[REGNO (x)]);
11015 else if (GET_CODE (x) == MEM)
11016 {
11017 /* We need to handle PRE_INC and PRE_DEC here, since we need to
11018 know the width from the mode. */
11019 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
11020 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
11021 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 11022 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
11023 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
11024 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 11025 else
a54d04b7 11026 output_address (XEXP (x, 0));
9878760c
RK
11027 }
11028 else
a54d04b7 11029 output_addr_const (file, x);
a85d226b 11030 return;
9878760c 11031
c4501e62
JJ
11032 case '&':
11033 assemble_name (file, rs6000_get_some_local_dynamic_name ());
11034 return;
11035
9878760c
RK
11036 default:
11037 output_operand_lossage ("invalid %%xn code");
11038 }
11039}
11040\f
11041/* Print the address of an operand. */
11042
11043void
a2369ed3 11044print_operand_address (FILE *file, rtx x)
9878760c
RK
11045{
11046 if (GET_CODE (x) == REG)
4697a36c 11047 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
11048 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
11049 || GET_CODE (x) == LABEL_REF)
9878760c
RK
11050 {
11051 output_addr_const (file, x);
ba5e43aa 11052 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
11053 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
11054 reg_names[SMALL_DATA_REG]);
9ebbca7d 11055 else if (TARGET_TOC)
a4f6c312 11056 abort ();
9878760c
RK
11057 }
11058 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
11059 {
11060 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
11061 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
11062 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 11063 else
4697a36c
MM
11064 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
11065 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
11066 }
11067 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
11068 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
11069 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
11070#if TARGET_ELF
11071 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
c4ad648e 11072 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
11073 {
11074 output_addr_const (file, XEXP (x, 1));
11075 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
11076 }
c859cda6
DJ
11077#endif
11078#if TARGET_MACHO
11079 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
c4ad648e 11080 && CONSTANT_P (XEXP (x, 1)))
c859cda6
DJ
11081 {
11082 fprintf (file, "lo16(");
11083 output_addr_const (file, XEXP (x, 1));
11084 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
11085 }
3cb999d8 11086#endif
4d588c14 11087 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 11088 {
2bfcf297 11089 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 11090 {
2bfcf297
DB
11091 rtx contains_minus = XEXP (x, 1);
11092 rtx minus, symref;
11093 const char *name;
f676971a 11094
9ebbca7d 11095 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 11096 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
11097 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
11098 contains_minus = XEXP (contains_minus, 0);
11099
2bfcf297
DB
11100 minus = XEXP (contains_minus, 0);
11101 symref = XEXP (minus, 0);
11102 XEXP (contains_minus, 0) = symref;
11103 if (TARGET_ELF)
11104 {
11105 char *newname;
11106
11107 name = XSTR (symref, 0);
11108 newname = alloca (strlen (name) + sizeof ("@toc"));
11109 strcpy (newname, name);
11110 strcat (newname, "@toc");
11111 XSTR (symref, 0) = newname;
11112 }
11113 output_addr_const (file, XEXP (x, 1));
11114 if (TARGET_ELF)
11115 XSTR (symref, 0) = name;
9ebbca7d
GK
11116 XEXP (contains_minus, 0) = minus;
11117 }
11118 else
11119 output_addr_const (file, XEXP (x, 1));
11120
11121 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
11122 }
9878760c
RK
11123 else
11124 abort ();
11125}
11126\f
88cad84b 11127/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
11128 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
11129 is defined. It also needs to handle DI-mode objects on 64-bit
11130 targets. */
11131
11132static bool
a2369ed3 11133rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
11134{
11135#ifdef RELOCATABLE_NEEDS_FIXUP
11136 /* Special handling for SI values. */
11137 if (size == 4 && aligned_p)
11138 {
a2369ed3 11139 extern int in_toc_section (void);
301d03af 11140 static int recurse = 0;
f676971a 11141
301d03af
RS
11142 /* For -mrelocatable, we mark all addresses that need to be fixed up
11143 in the .fixup section. */
11144 if (TARGET_RELOCATABLE
11145 && !in_toc_section ()
11146 && !in_text_section ()
642af3be 11147 && !in_unlikely_text_section ()
301d03af
RS
11148 && !recurse
11149 && GET_CODE (x) != CONST_INT
11150 && GET_CODE (x) != CONST_DOUBLE
11151 && CONSTANT_P (x))
11152 {
11153 char buf[256];
11154
11155 recurse = 1;
11156 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
11157 fixuplabelno++;
11158 ASM_OUTPUT_LABEL (asm_out_file, buf);
11159 fprintf (asm_out_file, "\t.long\t(");
11160 output_addr_const (asm_out_file, x);
11161 fprintf (asm_out_file, ")@fixup\n");
11162 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
11163 ASM_OUTPUT_ALIGN (asm_out_file, 2);
11164 fprintf (asm_out_file, "\t.long\t");
11165 assemble_name (asm_out_file, buf);
11166 fprintf (asm_out_file, "\n\t.previous\n");
11167 recurse = 0;
11168 return true;
11169 }
11170 /* Remove initial .'s to turn a -mcall-aixdesc function
11171 address into the address of the descriptor, not the function
11172 itself. */
11173 else if (GET_CODE (x) == SYMBOL_REF
11174 && XSTR (x, 0)[0] == '.'
11175 && DEFAULT_ABI == ABI_AIX)
11176 {
11177 const char *name = XSTR (x, 0);
11178 while (*name == '.')
11179 name++;
11180
11181 fprintf (asm_out_file, "\t.long\t%s\n", name);
11182 return true;
11183 }
11184 }
11185#endif /* RELOCATABLE_NEEDS_FIXUP */
11186 return default_assemble_integer (x, size, aligned_p);
11187}
93638d7a
AM
11188
11189#ifdef HAVE_GAS_HIDDEN
11190/* Emit an assembler directive to set symbol visibility for DECL to
11191 VISIBILITY_TYPE. */
11192
5add3202 11193static void
a2369ed3 11194rs6000_assemble_visibility (tree decl, int vis)
93638d7a 11195{
93638d7a
AM
11196 /* Functions need to have their entry point symbol visibility set as
11197 well as their descriptor symbol visibility. */
85b776df
AM
11198 if (DEFAULT_ABI == ABI_AIX
11199 && DOT_SYMBOLS
11200 && TREE_CODE (decl) == FUNCTION_DECL)
93638d7a 11201 {
25fdb4dc 11202 static const char * const visibility_types[] = {
c4ad648e 11203 NULL, "internal", "hidden", "protected"
25fdb4dc
RH
11204 };
11205
11206 const char *name, *type;
93638d7a
AM
11207
11208 name = ((* targetm.strip_name_encoding)
11209 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 11210 type = visibility_types[vis];
93638d7a 11211
25fdb4dc
RH
11212 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
11213 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 11214 }
25fdb4dc
RH
11215 else
11216 default_assemble_visibility (decl, vis);
93638d7a
AM
11217}
11218#endif
301d03af 11219\f
39a10a29 11220enum rtx_code
a2369ed3 11221rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
11222{
11223 /* Reversal of FP compares takes care -- an ordered compare
11224 becomes an unordered compare and vice versa. */
f676971a 11225 if (mode == CCFPmode
bc9ec0e0
GK
11226 && (!flag_finite_math_only
11227 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
11228 || code == UNEQ || code == LTGT))
bab6226b 11229 return reverse_condition_maybe_unordered (code);
39a10a29 11230 else
bab6226b 11231 return reverse_condition (code);
39a10a29
GK
11232}
11233
39a10a29
GK
11234/* Generate a compare for CODE. Return a brand-new rtx that
11235 represents the result of the compare. */
a4f6c312 11236
39a10a29 11237static rtx
a2369ed3 11238rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
11239{
11240 enum machine_mode comp_mode;
11241 rtx compare_result;
11242
11243 if (rs6000_compare_fp_p)
11244 comp_mode = CCFPmode;
11245 else if (code == GTU || code == LTU
c4ad648e 11246 || code == GEU || code == LEU)
39a10a29 11247 comp_mode = CCUNSmode;
60934f9c
NS
11248 else if ((code == EQ || code == NE)
11249 && GET_CODE (rs6000_compare_op0) == SUBREG
11250 && GET_CODE (rs6000_compare_op1) == SUBREG
11251 && SUBREG_PROMOTED_UNSIGNED_P (rs6000_compare_op0)
11252 && SUBREG_PROMOTED_UNSIGNED_P (rs6000_compare_op1))
11253 /* These are unsigned values, perhaps there will be a later
11254 ordering compare that can be shared with this one.
11255 Unfortunately we cannot detect the signedness of the operands
11256 for non-subregs. */
11257 comp_mode = CCUNSmode;
39a10a29
GK
11258 else
11259 comp_mode = CCmode;
11260
11261 /* First, the compare. */
11262 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
11263
11264 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
11265 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
11266 && rs6000_compare_fp_p)
a3170dc6
AH
11267 {
11268 rtx cmp, or1, or2, or_result, compare_result2;
4d4cbc0e
AH
11269 enum machine_mode op_mode = GET_MODE (rs6000_compare_op0);
11270
11271 if (op_mode == VOIDmode)
11272 op_mode = GET_MODE (rs6000_compare_op1);
a3170dc6 11273
423c1189
AH
11274 /* Note: The E500 comparison instructions set the GT bit (x +
11275 1), on success. This explains the mess. */
11276
a3170dc6
AH
11277 switch (code)
11278 {
423c1189 11279 case EQ: case UNEQ: case NE: case LTGT:
4d4cbc0e
AH
11280 if (op_mode == SFmode)
11281 cmp = flag_finite_math_only
11282 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
11283 rs6000_compare_op1)
11284 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
11285 rs6000_compare_op1);
11286 else if (op_mode == DFmode)
11287 cmp = flag_finite_math_only
11288 ? gen_tstdfeq_gpr (compare_result, rs6000_compare_op0,
11289 rs6000_compare_op1)
11290 : gen_cmpdfeq_gpr (compare_result, rs6000_compare_op0,
11291 rs6000_compare_op1);
11292 else abort ();
a3170dc6 11293 break;
423c1189 11294 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
4d4cbc0e
AH
11295 if (op_mode == SFmode)
11296 cmp = flag_finite_math_only
11297 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
11298 rs6000_compare_op1)
11299 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
11300 rs6000_compare_op1);
11301 else if (op_mode == DFmode)
11302 cmp = flag_finite_math_only
11303 ? gen_tstdfgt_gpr (compare_result, rs6000_compare_op0,
11304 rs6000_compare_op1)
11305 : gen_cmpdfgt_gpr (compare_result, rs6000_compare_op0,
11306 rs6000_compare_op1);
11307 else abort ();
a3170dc6 11308 break;
423c1189 11309 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
4d4cbc0e
AH
11310 if (op_mode == SFmode)
11311 cmp = flag_finite_math_only
11312 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
11313 rs6000_compare_op1)
11314 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
11315 rs6000_compare_op1);
11316 else if (op_mode == DFmode)
11317 cmp = flag_finite_math_only
11318 ? gen_tstdflt_gpr (compare_result, rs6000_compare_op0,
11319 rs6000_compare_op1)
11320 : gen_cmpdflt_gpr (compare_result, rs6000_compare_op0,
11321 rs6000_compare_op1);
11322 else abort ();
a3170dc6 11323 break;
4d4cbc0e
AH
11324 default:
11325 abort ();
a3170dc6
AH
11326 }
11327
11328 /* Synthesize LE and GE from LT/GT || EQ. */
11329 if (code == LE || code == GE || code == LEU || code == GEU)
11330 {
a3170dc6
AH
11331 emit_insn (cmp);
11332
11333 switch (code)
11334 {
11335 case LE: code = LT; break;
11336 case GE: code = GT; break;
11337 case LEU: code = LT; break;
11338 case GEU: code = GT; break;
11339 default: abort ();
11340 }
11341
11342 or1 = gen_reg_rtx (SImode);
11343 or2 = gen_reg_rtx (SImode);
11344 or_result = gen_reg_rtx (CCEQmode);
11345 compare_result2 = gen_reg_rtx (CCFPmode);
11346
11347 /* Do the EQ. */
4d4cbc0e
AH
11348 if (op_mode == SFmode)
11349 cmp = flag_finite_math_only
11350 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
11351 rs6000_compare_op1)
11352 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
11353 rs6000_compare_op1);
11354 else if (op_mode == DFmode)
11355 cmp = flag_finite_math_only
11356 ? gen_tstdfeq_gpr (compare_result2, rs6000_compare_op0,
11357 rs6000_compare_op1)
11358 : gen_cmpdfeq_gpr (compare_result2, rs6000_compare_op0,
11359 rs6000_compare_op1);
11360 else abort ();
a3170dc6
AH
11361 emit_insn (cmp);
11362
423c1189
AH
11363 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
11364 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
11365
11366 /* OR them together. */
11367 cmp = gen_rtx_SET (VOIDmode, or_result,
11368 gen_rtx_COMPARE (CCEQmode,
11369 gen_rtx_IOR (SImode, or1, or2),
11370 const_true_rtx));
11371 compare_result = or_result;
11372 code = EQ;
11373 }
11374 else
11375 {
a3170dc6 11376 if (code == NE || code == LTGT)
a3170dc6 11377 code = NE;
423c1189
AH
11378 else
11379 code = EQ;
a3170dc6
AH
11380 }
11381
11382 emit_insn (cmp);
11383 }
11384 else
11385 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
11386 gen_rtx_COMPARE (comp_mode,
f676971a 11387 rs6000_compare_op0,
a3170dc6 11388 rs6000_compare_op1)));
f676971a 11389
ca5adc63 11390 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 11391 under flag_finite_math_only we don't bother. */
39a10a29 11392 if (rs6000_compare_fp_p
bc9ec0e0 11393 && ! flag_finite_math_only
993f19a8 11394 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
11395 && (code == LE || code == GE
11396 || code == UNEQ || code == LTGT
11397 || code == UNGT || code == UNLT))
11398 {
11399 enum rtx_code or1, or2;
11400 rtx or1_rtx, or2_rtx, compare2_rtx;
11401 rtx or_result = gen_reg_rtx (CCEQmode);
f676971a 11402
39a10a29
GK
11403 switch (code)
11404 {
11405 case LE: or1 = LT; or2 = EQ; break;
11406 case GE: or1 = GT; or2 = EQ; break;
11407 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
11408 case LTGT: or1 = LT; or2 = GT; break;
11409 case UNGT: or1 = UNORDERED; or2 = GT; break;
11410 case UNLT: or1 = UNORDERED; or2 = LT; break;
11411 default: abort ();
11412 }
11413 validate_condition_mode (or1, comp_mode);
11414 validate_condition_mode (or2, comp_mode);
1c563bed
KH
11415 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
11416 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
11417 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
11418 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
11419 const_true_rtx);
11420 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
11421
11422 compare_result = or_result;
11423 code = EQ;
11424 }
11425
11426 validate_condition_mode (code, GET_MODE (compare_result));
f676971a 11427
1c563bed 11428 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
11429}
11430
11431
11432/* Emit the RTL for an sCOND pattern. */
11433
11434void
a2369ed3 11435rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
11436{
11437 rtx condition_rtx;
11438 enum machine_mode op_mode;
b7053a3f 11439 enum rtx_code cond_code;
39a10a29
GK
11440
11441 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
11442 cond_code = GET_CODE (condition_rtx);
11443
423c1189
AH
11444 if (TARGET_E500 && rs6000_compare_fp_p
11445 && !TARGET_FPRS && TARGET_HARD_FLOAT)
11446 {
11447 rtx t;
11448
11449 PUT_MODE (condition_rtx, SImode);
11450 t = XEXP (condition_rtx, 0);
11451
11452 if (cond_code != NE && cond_code != EQ)
11453 abort ();
11454
11455 if (cond_code == NE)
6b1fedc3 11456 emit_insn (gen_e500_flip_eq_bit (t, t));
423c1189 11457
6b1fedc3 11458 emit_insn (gen_move_from_CR_eq_bit (result, t));
423c1189
AH
11459 return;
11460 }
11461
b7053a3f
GK
11462 if (cond_code == NE
11463 || cond_code == GE || cond_code == LE
11464 || cond_code == GEU || cond_code == LEU
11465 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
11466 {
11467 rtx not_result = gen_reg_rtx (CCEQmode);
11468 rtx not_op, rev_cond_rtx;
11469 enum machine_mode cc_mode;
f676971a 11470
b7053a3f
GK
11471 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
11472
1c563bed 11473 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 11474 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
11475 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
11476 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
11477 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
11478 }
39a10a29
GK
11479
11480 op_mode = GET_MODE (rs6000_compare_op0);
11481 if (op_mode == VOIDmode)
11482 op_mode = GET_MODE (rs6000_compare_op1);
11483
11484 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
11485 {
11486 PUT_MODE (condition_rtx, DImode);
11487 convert_move (result, condition_rtx, 0);
11488 }
11489 else
11490 {
11491 PUT_MODE (condition_rtx, SImode);
11492 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
11493 }
11494}
11495
39a10a29
GK
11496/* Emit a branch of kind CODE to location LOC. */
11497
11498void
a2369ed3 11499rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
11500{
11501 rtx condition_rtx, loc_ref;
11502
11503 condition_rtx = rs6000_generate_compare (code);
11504 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
11505 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
11506 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
11507 loc_ref, pc_rtx)));
11508}
11509
12a4e8c5
GK
11510/* Return the string to output a conditional branch to LABEL, which is
11511 the operand number of the label, or -1 if the branch is really a
f676971a 11512 conditional return.
12a4e8c5
GK
11513
11514 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
11515 condition code register and its mode specifies what kind of
11516 comparison we made.
11517
a0ab749a 11518 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
11519
11520 INSN is the insn. */
11521
11522char *
a2369ed3 11523output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
11524{
11525 static char string[64];
11526 enum rtx_code code = GET_CODE (op);
11527 rtx cc_reg = XEXP (op, 0);
11528 enum machine_mode mode = GET_MODE (cc_reg);
11529 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 11530 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
11531 int really_reversed = reversed ^ need_longbranch;
11532 char *s = string;
11533 const char *ccode;
11534 const char *pred;
11535 rtx note;
11536
39a10a29
GK
11537 validate_condition_mode (code, mode);
11538
11539 /* Work out which way this really branches. We could use
11540 reverse_condition_maybe_unordered here always but this
11541 makes the resulting assembler clearer. */
12a4e8c5 11542 if (really_reversed)
de40e1df
DJ
11543 {
11544 /* Reversal of FP compares takes care -- an ordered compare
11545 becomes an unordered compare and vice versa. */
11546 if (mode == CCFPmode)
11547 code = reverse_condition_maybe_unordered (code);
11548 else
11549 code = reverse_condition (code);
11550 }
12a4e8c5 11551
993f19a8 11552 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
11553 {
11554 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
11555 to the GT bit. */
11556 if (code == EQ)
11557 /* Opposite of GT. */
a3170dc6 11558 code = GT;
423c1189
AH
11559 else if (code == NE)
11560 code = UNLE;
a3170dc6
AH
11561 else
11562 abort ();
11563 }
11564
39a10a29 11565 switch (code)
12a4e8c5
GK
11566 {
11567 /* Not all of these are actually distinct opcodes, but
11568 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
11569 case NE: case LTGT:
11570 ccode = "ne"; break;
11571 case EQ: case UNEQ:
11572 ccode = "eq"; break;
f676971a 11573 case GE: case GEU:
50a0b056 11574 ccode = "ge"; break;
f676971a 11575 case GT: case GTU: case UNGT:
50a0b056 11576 ccode = "gt"; break;
f676971a 11577 case LE: case LEU:
50a0b056 11578 ccode = "le"; break;
f676971a 11579 case LT: case LTU: case UNLT:
50a0b056 11580 ccode = "lt"; break;
12a4e8c5
GK
11581 case UNORDERED: ccode = "un"; break;
11582 case ORDERED: ccode = "nu"; break;
11583 case UNGE: ccode = "nl"; break;
11584 case UNLE: ccode = "ng"; break;
11585 default:
a4f6c312 11586 abort ();
12a4e8c5 11587 }
f676971a
EC
11588
11589 /* Maybe we have a guess as to how likely the branch is.
94a54f47 11590 The old mnemonics don't have a way to specify this information. */
f4857b9b 11591 pred = "";
12a4e8c5
GK
11592 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
11593 if (note != NULL_RTX)
11594 {
11595 /* PROB is the difference from 50%. */
11596 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
11597
11598 /* Only hint for highly probable/improbable branches on newer
11599 cpus as static prediction overrides processor dynamic
11600 prediction. For older cpus we may as well always hint, but
11601 assume not taken for branches that are very close to 50% as a
11602 mispredicted taken branch is more expensive than a
f676971a 11603 mispredicted not-taken branch. */
ec507f2d 11604 if (rs6000_always_hint
f4857b9b
AM
11605 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
11606 {
11607 if (abs (prob) > REG_BR_PROB_BASE / 20
11608 && ((prob > 0) ^ need_longbranch))
c4ad648e 11609 pred = "+";
f4857b9b
AM
11610 else
11611 pred = "-";
11612 }
12a4e8c5 11613 }
12a4e8c5
GK
11614
11615 if (label == NULL)
94a54f47 11616 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 11617 else
94a54f47 11618 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 11619
37c67319 11620 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 11621 Assume they'd only be the first character.... */
37c67319
GK
11622 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
11623 *s++ = '%';
94a54f47 11624 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
11625
11626 if (label != NULL)
11627 {
11628 /* If the branch distance was too far, we may have to use an
11629 unconditional branch to go the distance. */
11630 if (need_longbranch)
44518ddd 11631 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
11632 else
11633 s += sprintf (s, ",%s", label);
11634 }
11635
11636 return string;
11637}
50a0b056 11638
6b1fedc3 11639/* Return the string to flip the EQ bit on a CR. */
423c1189 11640char *
6b1fedc3 11641output_e500_flip_eq_bit (rtx dst, rtx src)
423c1189
AH
11642{
11643 static char string[64];
11644 int a, b;
11645
11646 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
11647 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
11648 abort ();
11649
6b1fedc3
AH
11650 /* EQ bit. */
11651 a = 4 * (REGNO (dst) - CR0_REGNO) + 2;
11652 b = 4 * (REGNO (src) - CR0_REGNO) + 2;
423c1189
AH
11653
11654 sprintf (string, "crnot %d,%d", a, b);
11655 return string;
11656}
11657
21213b4c
DP
11658/* Return insn index for the vector compare instruction for given CODE,
11659 and DEST_MODE, OP_MODE. Return INSN_NOT_AVAILABLE if valid insn is
11660 not available. */
11661
11662static int
94ff898d 11663get_vec_cmp_insn (enum rtx_code code,
21213b4c
DP
11664 enum machine_mode dest_mode,
11665 enum machine_mode op_mode)
11666{
11667 if (!TARGET_ALTIVEC)
11668 return INSN_NOT_AVAILABLE;
11669
11670 switch (code)
11671 {
11672 case EQ:
11673 if (dest_mode == V16QImode && op_mode == V16QImode)
11674 return UNSPEC_VCMPEQUB;
11675 if (dest_mode == V8HImode && op_mode == V8HImode)
11676 return UNSPEC_VCMPEQUH;
11677 if (dest_mode == V4SImode && op_mode == V4SImode)
11678 return UNSPEC_VCMPEQUW;
11679 if (dest_mode == V4SImode && op_mode == V4SFmode)
11680 return UNSPEC_VCMPEQFP;
11681 break;
11682 case GE:
11683 if (dest_mode == V4SImode && op_mode == V4SFmode)
11684 return UNSPEC_VCMPGEFP;
11685 case GT:
11686 if (dest_mode == V16QImode && op_mode == V16QImode)
11687 return UNSPEC_VCMPGTSB;
11688 if (dest_mode == V8HImode && op_mode == V8HImode)
11689 return UNSPEC_VCMPGTSH;
11690 if (dest_mode == V4SImode && op_mode == V4SImode)
11691 return UNSPEC_VCMPGTSW;
11692 if (dest_mode == V4SImode && op_mode == V4SFmode)
11693 return UNSPEC_VCMPGTFP;
11694 break;
11695 case GTU:
11696 if (dest_mode == V16QImode && op_mode == V16QImode)
11697 return UNSPEC_VCMPGTUB;
11698 if (dest_mode == V8HImode && op_mode == V8HImode)
11699 return UNSPEC_VCMPGTUH;
11700 if (dest_mode == V4SImode && op_mode == V4SImode)
11701 return UNSPEC_VCMPGTUW;
11702 break;
11703 default:
11704 break;
11705 }
11706 return INSN_NOT_AVAILABLE;
11707}
11708
11709/* Emit vector compare for operands OP0 and OP1 using code RCODE.
11710 DMODE is expected destination mode. This is a recursive function. */
11711
11712static rtx
11713rs6000_emit_vector_compare (enum rtx_code rcode,
11714 rtx op0, rtx op1,
11715 enum machine_mode dmode)
11716{
11717 int vec_cmp_insn;
11718 rtx mask;
11719 enum machine_mode dest_mode;
11720 enum machine_mode op_mode = GET_MODE (op1);
11721
11722#ifdef ENABLE_CHECKING
11723 if (!TARGET_ALTIVEC)
11724 abort ();
11725
11726 if (GET_MODE (op0) != GET_MODE (op1))
11727 abort ();
11728#endif
11729
11730 /* Floating point vector compare instructions uses destination V4SImode.
11731 Move destination to appropriate mode later. */
11732 if (dmode == V4SFmode)
11733 dest_mode = V4SImode;
11734 else
11735 dest_mode = dmode;
11736
11737 mask = gen_reg_rtx (dest_mode);
11738 vec_cmp_insn = get_vec_cmp_insn (rcode, dest_mode, op_mode);
11739
11740 if (vec_cmp_insn == INSN_NOT_AVAILABLE)
11741 {
11742 bool swap_operands = false;
11743 bool try_again = false;
11744 switch (rcode)
11745 {
11746 case LT:
11747 rcode = GT;
11748 swap_operands = true;
11749 try_again = true;
11750 break;
11751 case LTU:
11752 rcode = GTU;
11753 swap_operands = true;
11754 try_again = true;
11755 break;
11756 case NE:
11757 /* Treat A != B as ~(A==B). */
11758 {
11759 enum insn_code nor_code;
11760 rtx eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1,
11761 dest_mode);
94ff898d 11762
21213b4c
DP
11763 nor_code = one_cmpl_optab->handlers[(int)dest_mode].insn_code;
11764 if (nor_code == CODE_FOR_nothing)
11765 abort ();
11766 emit_insn (GEN_FCN (nor_code) (mask, eq_rtx));
11767
11768 if (dmode != dest_mode)
11769 {
11770 rtx temp = gen_reg_rtx (dest_mode);
11771 convert_move (temp, mask, 0);
11772 return temp;
11773 }
11774 return mask;
11775 }
11776 break;
11777 case GE:
11778 case GEU:
11779 case LE:
11780 case LEU:
11781 /* Try GT/GTU/LT/LTU OR EQ */
11782 {
11783 rtx c_rtx, eq_rtx;
11784 enum insn_code ior_code;
11785 enum rtx_code new_code;
11786
11787 if (rcode == GE)
11788 new_code = GT;
11789 else if (rcode == GEU)
11790 new_code = GTU;
11791 else if (rcode == LE)
11792 new_code = LT;
11793 else if (rcode == LEU)
11794 new_code = LTU;
11795 else
11796 abort ();
11797
11798 c_rtx = rs6000_emit_vector_compare (new_code,
11799 op0, op1, dest_mode);
11800 eq_rtx = rs6000_emit_vector_compare (EQ, op0, op1,
11801 dest_mode);
11802
11803 ior_code = ior_optab->handlers[(int)dest_mode].insn_code;
11804 if (ior_code == CODE_FOR_nothing)
11805 abort ();
11806 emit_insn (GEN_FCN (ior_code) (mask, c_rtx, eq_rtx));
11807 if (dmode != dest_mode)
11808 {
11809 rtx temp = gen_reg_rtx (dest_mode);
11810 convert_move (temp, mask, 0);
11811 return temp;
11812 }
11813 return mask;
11814 }
11815 break;
11816 default:
11817 abort ();
11818 }
11819
11820 if (try_again)
11821 {
11822 vec_cmp_insn = get_vec_cmp_insn (rcode, dest_mode, op_mode);
11823 if (vec_cmp_insn == INSN_NOT_AVAILABLE)
11824 /* You only get two chances. */
11825 abort ();
11826 }
11827
11828 if (swap_operands)
11829 {
11830 rtx tmp;
11831 tmp = op0;
11832 op0 = op1;
11833 op1 = tmp;
11834 }
11835 }
11836
11837 emit_insn (gen_rtx_fmt_ee (SET,
11838 VOIDmode,
11839 mask,
11840 gen_rtx_fmt_Ei (UNSPEC, dest_mode,
11841 gen_rtvec (2, op0, op1),
11842 vec_cmp_insn)));
11843 if (dmode != dest_mode)
11844 {
11845 rtx temp = gen_reg_rtx (dest_mode);
11846 convert_move (temp, mask, 0);
11847 return temp;
11848 }
11849 return mask;
11850}
11851
11852/* Return vector select instruction for MODE. Return INSN_NOT_AVAILABLE, if
11853 valid insn doesn exist for given mode. */
11854
11855static int
11856get_vsel_insn (enum machine_mode mode)
11857{
11858 switch (mode)
11859 {
11860 case V4SImode:
11861 return UNSPEC_VSEL4SI;
11862 break;
11863 case V4SFmode:
11864 return UNSPEC_VSEL4SF;
11865 break;
11866 case V8HImode:
11867 return UNSPEC_VSEL8HI;
11868 break;
11869 case V16QImode:
11870 return UNSPEC_VSEL16QI;
11871 break;
11872 default:
11873 return INSN_NOT_AVAILABLE;
11874 break;
11875 }
11876 return INSN_NOT_AVAILABLE;
11877}
11878
11879/* Emit vector select insn where DEST is destination using
11880 operands OP1, OP2 and MASK. */
11881
11882static void
11883rs6000_emit_vector_select (rtx dest, rtx op1, rtx op2, rtx mask)
11884{
11885 rtx t, temp;
11886 enum machine_mode dest_mode = GET_MODE (dest);
11887 int vsel_insn_index = get_vsel_insn (GET_MODE (dest));
11888
11889 temp = gen_reg_rtx (dest_mode);
94ff898d 11890
21213b4c
DP
11891 t = gen_rtx_fmt_ee (SET, VOIDmode, temp,
11892 gen_rtx_fmt_Ei (UNSPEC, dest_mode,
11893 gen_rtvec (3, op1, op2, mask),
11894 vsel_insn_index));
11895 emit_insn (t);
11896 emit_move_insn (dest, temp);
11897 return;
11898}
11899
94ff898d 11900/* Emit vector conditional expression.
21213b4c
DP
11901 DEST is destination. OP1 and OP2 are two VEC_COND_EXPR operands.
11902 CC_OP0 and CC_OP1 are the two operands for the relation operation COND. */
11903
11904int
11905rs6000_emit_vector_cond_expr (rtx dest, rtx op1, rtx op2,
11906 rtx cond, rtx cc_op0, rtx cc_op1)
11907{
11908 enum machine_mode dest_mode = GET_MODE (dest);
11909 enum rtx_code rcode = GET_CODE (cond);
11910 rtx mask;
11911
11912 if (!TARGET_ALTIVEC)
11913 return 0;
11914
11915 /* Get the vector mask for the given relational operations. */
11916 mask = rs6000_emit_vector_compare (rcode, cc_op0, cc_op1, dest_mode);
11917
11918 rs6000_emit_vector_select (dest, op1, op2, mask);
11919
11920 return 1;
11921}
11922
50a0b056
GK
11923/* Emit a conditional move: move TRUE_COND to DEST if OP of the
11924 operands of the last comparison is nonzero/true, FALSE_COND if it
11925 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 11926
50a0b056 11927int
a2369ed3 11928rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
11929{
11930 enum rtx_code code = GET_CODE (op);
11931 rtx op0 = rs6000_compare_op0;
11932 rtx op1 = rs6000_compare_op1;
11933 REAL_VALUE_TYPE c1;
3148ad6d
DJ
11934 enum machine_mode compare_mode = GET_MODE (op0);
11935 enum machine_mode result_mode = GET_MODE (dest);
50a0b056 11936 rtx temp;
add2402e 11937 bool is_against_zero;
50a0b056 11938
a3c9585f 11939 /* These modes should always match. */
a3170dc6
AH
11940 if (GET_MODE (op1) != compare_mode
11941 /* In the isel case however, we can use a compare immediate, so
11942 op1 may be a small constant. */
11943 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 11944 return 0;
178c3eff 11945 if (GET_MODE (true_cond) != result_mode)
3148ad6d 11946 return 0;
178c3eff 11947 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
11948 return 0;
11949
50a0b056 11950 /* First, work out if the hardware can do this at all, or
a3c9585f 11951 if it's too slow.... */
50a0b056 11952 if (! rs6000_compare_fp_p)
a3170dc6
AH
11953 {
11954 if (TARGET_ISEL)
11955 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
11956 return 0;
11957 }
fef98bf2
AH
11958 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
11959 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
11960 return 0;
50a0b056 11961
add2402e 11962 is_against_zero = op1 == CONST0_RTX (compare_mode);
94ff898d 11963
add2402e
GK
11964 /* A floating-point subtract might overflow, underflow, or produce
11965 an inexact result, thus changing the floating-point flags, so it
11966 can't be generated if we care about that. It's safe if one side
11967 of the construct is zero, since then no subtract will be
11968 generated. */
11969 if (GET_MODE_CLASS (compare_mode) == MODE_FLOAT
11970 && flag_trapping_math && ! is_against_zero)
11971 return 0;
11972
50a0b056
GK
11973 /* Eliminate half of the comparisons by switching operands, this
11974 makes the remaining code simpler. */
11975 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 11976 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
11977 {
11978 code = reverse_condition_maybe_unordered (code);
11979 temp = true_cond;
11980 true_cond = false_cond;
11981 false_cond = temp;
11982 }
11983
11984 /* UNEQ and LTGT take four instructions for a comparison with zero,
11985 it'll probably be faster to use a branch here too. */
bc9ec0e0 11986 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056 11987 return 0;
f676971a 11988
50a0b056
GK
11989 if (GET_CODE (op1) == CONST_DOUBLE)
11990 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
f676971a 11991
b6d08ca1 11992 /* We're going to try to implement comparisons by performing
50a0b056
GK
11993 a subtract, then comparing against zero. Unfortunately,
11994 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 11995 know that the operand is finite and the comparison
50a0b056 11996 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 11997 if (HONOR_INFINITIES (compare_mode)
50a0b056 11998 && code != GT && code != UNGE
045572c7 11999 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
12000 /* Constructs of the form (a OP b ? a : b) are safe. */
12001 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
f676971a 12002 || (! rtx_equal_p (op0, true_cond)
50a0b056
GK
12003 && ! rtx_equal_p (op1, true_cond))))
12004 return 0;
add2402e 12005
50a0b056
GK
12006 /* At this point we know we can use fsel. */
12007
12008 /* Reduce the comparison to a comparison against zero. */
add2402e
GK
12009 if (! is_against_zero)
12010 {
12011 temp = gen_reg_rtx (compare_mode);
12012 emit_insn (gen_rtx_SET (VOIDmode, temp,
12013 gen_rtx_MINUS (compare_mode, op0, op1)));
12014 op0 = temp;
12015 op1 = CONST0_RTX (compare_mode);
12016 }
50a0b056
GK
12017
12018 /* If we don't care about NaNs we can reduce some of the comparisons
12019 down to faster ones. */
bc9ec0e0 12020 if (! HONOR_NANS (compare_mode))
50a0b056
GK
12021 switch (code)
12022 {
12023 case GT:
12024 code = LE;
12025 temp = true_cond;
12026 true_cond = false_cond;
12027 false_cond = temp;
12028 break;
12029 case UNGE:
12030 code = GE;
12031 break;
12032 case UNEQ:
12033 code = EQ;
12034 break;
12035 default:
12036 break;
12037 }
12038
12039 /* Now, reduce everything down to a GE. */
12040 switch (code)
12041 {
12042 case GE:
12043 break;
12044
12045 case LE:
3148ad6d
DJ
12046 temp = gen_reg_rtx (compare_mode);
12047 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
12048 op0 = temp;
12049 break;
12050
12051 case ORDERED:
3148ad6d
DJ
12052 temp = gen_reg_rtx (compare_mode);
12053 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
12054 op0 = temp;
12055 break;
12056
12057 case EQ:
3148ad6d 12058 temp = gen_reg_rtx (compare_mode);
f676971a 12059 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
12060 gen_rtx_NEG (compare_mode,
12061 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
12062 op0 = temp;
12063 break;
12064
12065 case UNGE:
bc9ec0e0 12066 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 12067 temp = gen_reg_rtx (result_mode);
50a0b056 12068 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 12069 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
12070 gen_rtx_GE (VOIDmode,
12071 op0, op1),
12072 true_cond, false_cond)));
bc9ec0e0
GK
12073 false_cond = true_cond;
12074 true_cond = temp;
50a0b056 12075
3148ad6d
DJ
12076 temp = gen_reg_rtx (compare_mode);
12077 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
12078 op0 = temp;
12079 break;
12080
12081 case GT:
bc9ec0e0 12082 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 12083 temp = gen_reg_rtx (result_mode);
50a0b056 12084 emit_insn (gen_rtx_SET (VOIDmode, temp,
f676971a 12085 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
12086 gen_rtx_GE (VOIDmode,
12087 op0, op1),
12088 true_cond, false_cond)));
bc9ec0e0
GK
12089 true_cond = false_cond;
12090 false_cond = temp;
50a0b056 12091
3148ad6d
DJ
12092 temp = gen_reg_rtx (compare_mode);
12093 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
12094 op0 = temp;
12095 break;
12096
12097 default:
12098 abort ();
12099 }
12100
12101 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 12102 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
12103 gen_rtx_GE (VOIDmode,
12104 op0, op1),
12105 true_cond, false_cond)));
12106 return 1;
12107}
12108
a3170dc6
AH
12109/* Same as above, but for ints (isel). */
12110
12111static int
a2369ed3 12112rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
12113{
12114 rtx condition_rtx, cr;
12115
12116 /* All isel implementations thus far are 32-bits. */
12117 if (GET_MODE (rs6000_compare_op0) != SImode)
12118 return 0;
12119
12120 /* We still have to do the compare, because isel doesn't do a
12121 compare, it just looks at the CRx bits set by a previous compare
12122 instruction. */
12123 condition_rtx = rs6000_generate_compare (GET_CODE (op));
12124 cr = XEXP (condition_rtx, 0);
12125
12126 if (GET_MODE (cr) == CCmode)
12127 emit_insn (gen_isel_signed (dest, condition_rtx,
12128 true_cond, false_cond, cr));
12129 else
12130 emit_insn (gen_isel_unsigned (dest, condition_rtx,
12131 true_cond, false_cond, cr));
12132
12133 return 1;
12134}
12135
12136const char *
a2369ed3 12137output_isel (rtx *operands)
a3170dc6
AH
12138{
12139 enum rtx_code code;
12140
12141 code = GET_CODE (operands[1]);
12142 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
12143 {
12144 PUT_CODE (operands[1], reverse_condition (code));
12145 return "isel %0,%3,%2,%j1";
12146 }
12147 else
12148 return "isel %0,%2,%3,%j1";
12149}
12150
50a0b056 12151void
a2369ed3 12152rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
12153{
12154 enum machine_mode mode = GET_MODE (op0);
5dc8d536 12155 enum rtx_code c;
50a0b056 12156 rtx target;
5dc8d536
AH
12157
12158 if (code == SMAX || code == SMIN)
12159 c = GE;
12160 else
12161 c = GEU;
12162
50a0b056 12163 if (code == SMAX || code == UMAX)
f676971a 12164 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
12165 op0, op1, mode, 0);
12166 else
f676971a 12167 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
12168 op1, op0, mode, 0);
12169 if (target == NULL_RTX)
12170 abort ();
12171 if (target != dest)
12172 emit_move_insn (dest, target);
12173}
46c07df8 12174
a9baceb1
GK
12175/* Emit instructions to move SRC to DST. Called by splitters for
12176 multi-register moves. It will emit at most one instruction for
12177 each register that is accessed; that is, it won't emit li/lis pairs
12178 (or equivalent for 64-bit code). One of SRC or DST must be a hard
12179 register. */
46c07df8 12180
46c07df8 12181void
a9baceb1 12182rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 12183{
a9baceb1
GK
12184 /* The register number of the first register being moved. */
12185 int reg;
12186 /* The mode that is to be moved. */
12187 enum machine_mode mode;
12188 /* The mode that the move is being done in, and its size. */
12189 enum machine_mode reg_mode;
12190 int reg_mode_size;
12191 /* The number of registers that will be moved. */
12192 int nregs;
12193
12194 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
12195 mode = GET_MODE (dst);
12196 nregs = HARD_REGNO_NREGS (reg, mode);
12197 if (FP_REGNO_P (reg))
12198 reg_mode = DFmode;
12199 else if (ALTIVEC_REGNO_P (reg))
12200 reg_mode = V16QImode;
12201 else
12202 reg_mode = word_mode;
12203 reg_mode_size = GET_MODE_SIZE (reg_mode);
f676971a 12204
a9baceb1
GK
12205 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
12206 abort ();
f676971a 12207
a9baceb1
GK
12208 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
12209 {
12210 /* Move register range backwards, if we might have destructive
12211 overlap. */
12212 int i;
12213 for (i = nregs - 1; i >= 0; i--)
f676971a 12214 emit_insn (gen_rtx_SET (VOIDmode,
a9baceb1
GK
12215 simplify_gen_subreg (reg_mode, dst, mode,
12216 i * reg_mode_size),
12217 simplify_gen_subreg (reg_mode, src, mode,
12218 i * reg_mode_size)));
12219 }
46c07df8
HP
12220 else
12221 {
a9baceb1
GK
12222 int i;
12223 int j = -1;
12224 bool used_update = false;
46c07df8 12225
c1e55850 12226 if (MEM_P (src) && INT_REGNO_P (reg))
c4ad648e
AM
12227 {
12228 rtx breg;
3a1f863f 12229
a9baceb1
GK
12230 if (GET_CODE (XEXP (src, 0)) == PRE_INC
12231 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
12232 {
12233 rtx delta_rtx;
a9baceb1 12234 breg = XEXP (XEXP (src, 0), 0);
c4ad648e
AM
12235 delta_rtx = (GET_CODE (XEXP (src, 0)) == PRE_INC
12236 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
12237 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src))));
a9baceb1
GK
12238 emit_insn (TARGET_32BIT
12239 ? gen_addsi3 (breg, breg, delta_rtx)
12240 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
12241 src = gen_rtx_MEM (mode, breg);
12242 }
c1e55850
GK
12243 else if (! offsettable_memref_p (src))
12244 {
12245 rtx newsrc, basereg;
12246 basereg = gen_rtx_REG (Pmode, reg);
12247 emit_insn (gen_rtx_SET (VOIDmode, basereg, XEXP (src, 0)));
12248 newsrc = gen_rtx_MEM (GET_MODE (src), basereg);
12249 MEM_COPY_ATTRIBUTES (newsrc, src);
12250 src = newsrc;
12251 }
3a1f863f 12252
0423421f
AM
12253 breg = XEXP (src, 0);
12254 if (GET_CODE (breg) == PLUS || GET_CODE (breg) == LO_SUM)
12255 breg = XEXP (breg, 0);
12256
12257 /* If the base register we are using to address memory is
12258 also a destination reg, then change that register last. */
12259 if (REG_P (breg)
12260 && REGNO (breg) >= REGNO (dst)
3a1f863f
DE
12261 && REGNO (breg) < REGNO (dst) + nregs)
12262 j = REGNO (breg) - REGNO (dst);
c4ad648e 12263 }
46c07df8 12264
a9baceb1 12265 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
12266 {
12267 rtx breg;
12268
a9baceb1
GK
12269 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
12270 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
12271 {
12272 rtx delta_rtx;
a9baceb1 12273 breg = XEXP (XEXP (dst, 0), 0);
c4ad648e
AM
12274 delta_rtx = (GET_CODE (XEXP (dst, 0)) == PRE_INC
12275 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
12276 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst))));
3a1f863f
DE
12277
12278 /* We have to update the breg before doing the store.
12279 Use store with update, if available. */
12280
12281 if (TARGET_UPDATE)
12282 {
a9baceb1 12283 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
c4ad648e
AM
12284 emit_insn (TARGET_32BIT
12285 ? (TARGET_POWERPC64
12286 ? gen_movdi_si_update (breg, breg, delta_rtx, nsrc)
12287 : gen_movsi_update (breg, breg, delta_rtx, nsrc))
12288 : gen_movdi_di_update (breg, breg, delta_rtx, nsrc));
a9baceb1 12289 used_update = true;
3a1f863f
DE
12290 }
12291 else
a9baceb1
GK
12292 emit_insn (TARGET_32BIT
12293 ? gen_addsi3 (breg, breg, delta_rtx)
12294 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
12295 dst = gen_rtx_MEM (mode, breg);
12296 }
c1e55850 12297 else if (! offsettable_memref_p (dst))
112ccb83 12298 abort ();
3a1f863f
DE
12299 }
12300
46c07df8 12301 for (i = 0; i < nregs; i++)
f676971a 12302 {
3a1f863f
DE
12303 /* Calculate index to next subword. */
12304 ++j;
f676971a 12305 if (j == nregs)
3a1f863f 12306 j = 0;
46c07df8 12307
112cdef5 12308 /* If compiler already emitted move of first word by
a9baceb1 12309 store with update, no need to do anything. */
3a1f863f 12310 if (j == 0 && used_update)
a9baceb1 12311 continue;
f676971a 12312
a9baceb1
GK
12313 emit_insn (gen_rtx_SET (VOIDmode,
12314 simplify_gen_subreg (reg_mode, dst, mode,
12315 j * reg_mode_size),
12316 simplify_gen_subreg (reg_mode, src, mode,
12317 j * reg_mode_size)));
3a1f863f 12318 }
46c07df8
HP
12319 }
12320}
12321
12a4e8c5 12322\f
a4f6c312
SS
12323/* This page contains routines that are used to determine what the
12324 function prologue and epilogue code will do and write them out. */
9878760c 12325
a4f6c312
SS
12326/* Return the first fixed-point register that is required to be
12327 saved. 32 if none. */
9878760c
RK
12328
12329int
863d938c 12330first_reg_to_save (void)
9878760c
RK
12331{
12332 int first_reg;
12333
12334 /* Find lowest numbered live register. */
12335 for (first_reg = 13; first_reg <= 31; first_reg++)
f676971a 12336 if (regs_ever_live[first_reg]
a38d360d 12337 && (! call_used_regs[first_reg]
1db02437 12338 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12339 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
b4db40bf
JJ
12340 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)
12341 || (TARGET_TOC && TARGET_MINIMAL_TOC)))))
9878760c
RK
12342 break;
12343
ee890fe2 12344#if TARGET_MACHO
93638d7a
AM
12345 if (flag_pic
12346 && current_function_uses_pic_offset_table
12347 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 12348 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
12349#endif
12350
9878760c
RK
12351 return first_reg;
12352}
12353
12354/* Similar, for FP regs. */
12355
12356int
863d938c 12357first_fp_reg_to_save (void)
9878760c
RK
12358{
12359 int first_reg;
12360
12361 /* Find lowest numbered live register. */
12362 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
12363 if (regs_ever_live[first_reg])
12364 break;
12365
12366 return first_reg;
12367}
00b960c7
AH
12368
12369/* Similar, for AltiVec regs. */
12370
12371static int
863d938c 12372first_altivec_reg_to_save (void)
00b960c7
AH
12373{
12374 int i;
12375
12376 /* Stack frame remains as is unless we are in AltiVec ABI. */
12377 if (! TARGET_ALTIVEC_ABI)
12378 return LAST_ALTIVEC_REGNO + 1;
12379
12380 /* Find lowest numbered live register. */
12381 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
12382 if (regs_ever_live[i])
12383 break;
12384
12385 return i;
12386}
12387
12388/* Return a 32-bit mask of the AltiVec registers we need to set in
12389 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
12390 the 32-bit word is 0. */
12391
12392static unsigned int
863d938c 12393compute_vrsave_mask (void)
00b960c7
AH
12394{
12395 unsigned int i, mask = 0;
12396
12397 /* First, find out if we use _any_ altivec registers. */
12398 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
12399 if (regs_ever_live[i])
12400 mask |= ALTIVEC_REG_BIT (i);
12401
12402 if (mask == 0)
12403 return mask;
12404
00b960c7
AH
12405 /* Next, remove the argument registers from the set. These must
12406 be in the VRSAVE mask set by the caller, so we don't need to add
12407 them in again. More importantly, the mask we compute here is
12408 used to generate CLOBBERs in the set_vrsave insn, and we do not
12409 wish the argument registers to die. */
a6cf80f2 12410 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
12411 mask &= ~ALTIVEC_REG_BIT (i);
12412
12413 /* Similarly, remove the return value from the set. */
12414 {
12415 bool yes = false;
12416 diddle_return_value (is_altivec_return_reg, &yes);
12417 if (yes)
12418 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
12419 }
12420
12421 return mask;
12422}
12423
d62294f5
FJ
12424/* For a very restricted set of circumstances, we can cut down the
12425 size of prologs/epilogs by calling our own save/restore-the-world
12426 routines. */
12427
12428static void
12429compute_save_world_info(rs6000_stack_t *info_ptr)
12430{
12431 info_ptr->world_save_p =
12432 (DEFAULT_ABI == ABI_DARWIN)
12433 && ! (current_function_calls_setjmp && flag_exceptions)
12434 && info_ptr->first_fp_reg_save == FIRST_SAVED_FP_REGNO
12435 && info_ptr->first_gp_reg_save == FIRST_SAVED_GP_REGNO
12436 && info_ptr->first_altivec_reg_save == FIRST_SAVED_ALTIVEC_REGNO
12437 && info_ptr->cr_save_p;
f676971a 12438
d62294f5
FJ
12439 /* This will not work in conjunction with sibcalls. Make sure there
12440 are none. (This check is expensive, but seldom executed.) */
12441 if ( info_ptr->world_save_p )
f676971a 12442 {
d62294f5
FJ
12443 rtx insn;
12444 for ( insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn))
c4ad648e
AM
12445 if ( GET_CODE (insn) == CALL_INSN
12446 && SIBLING_CALL_P (insn))
12447 {
12448 info_ptr->world_save_p = 0;
12449 break;
12450 }
d62294f5 12451 }
f676971a 12452
d62294f5
FJ
12453 if (info_ptr->world_save_p)
12454 {
12455 /* Even if we're not touching VRsave, make sure there's room on the
12456 stack for it, if it looks like we're calling SAVE_WORLD, which
c4ad648e 12457 will attempt to save it. */
d62294f5
FJ
12458 info_ptr->vrsave_size = 4;
12459
12460 /* "Save" the VRsave register too if we're saving the world. */
12461 if (info_ptr->vrsave_mask == 0)
c4ad648e 12462 info_ptr->vrsave_mask = compute_vrsave_mask ();
d62294f5
FJ
12463
12464 /* Because the Darwin register save/restore routines only handle
c4ad648e
AM
12465 F14 .. F31 and V20 .. V31 as per the ABI, perform a consistency
12466 check and abort if there's something worng. */
f676971a 12467 if (info_ptr->first_fp_reg_save < FIRST_SAVED_FP_REGNO
c4ad648e
AM
12468 || info_ptr->first_altivec_reg_save < FIRST_SAVED_ALTIVEC_REGNO)
12469 abort ();
d62294f5 12470 }
f676971a 12471 return;
d62294f5
FJ
12472}
12473
12474
00b960c7 12475static void
a2369ed3 12476is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
12477{
12478 bool *yes = (bool *) xyes;
12479 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
12480 *yes = true;
12481}
12482
4697a36c
MM
12483\f
12484/* Calculate the stack information for the current function. This is
12485 complicated by having two separate calling sequences, the AIX calling
12486 sequence and the V.4 calling sequence.
12487
592696dd 12488 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 12489 32-bit 64-bit
4697a36c 12490 SP----> +---------------------------------------+
a260abc9 12491 | back chain to caller | 0 0
4697a36c 12492 +---------------------------------------+
a260abc9 12493 | saved CR | 4 8 (8-11)
4697a36c 12494 +---------------------------------------+
a260abc9 12495 | saved LR | 8 16
4697a36c 12496 +---------------------------------------+
a260abc9 12497 | reserved for compilers | 12 24
4697a36c 12498 +---------------------------------------+
a260abc9 12499 | reserved for binders | 16 32
4697a36c 12500 +---------------------------------------+
a260abc9 12501 | saved TOC pointer | 20 40
4697a36c 12502 +---------------------------------------+
a260abc9 12503 | Parameter save area (P) | 24 48
4697a36c 12504 +---------------------------------------+
a260abc9 12505 | Alloca space (A) | 24+P etc.
802a0058 12506 +---------------------------------------+
a7df97e6 12507 | Local variable space (L) | 24+P+A
4697a36c 12508 +---------------------------------------+
a7df97e6 12509 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 12510 +---------------------------------------+
00b960c7
AH
12511 | Save area for AltiVec registers (W) | 24+P+A+L+X
12512 +---------------------------------------+
12513 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
12514 +---------------------------------------+
12515 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 12516 +---------------------------------------+
00b960c7
AH
12517 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
12518 +---------------------------------------+
12519 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
12520 +---------------------------------------+
12521 old SP->| back chain to caller's caller |
12522 +---------------------------------------+
12523
5376a30c
KR
12524 The required alignment for AIX configurations is two words (i.e., 8
12525 or 16 bytes).
12526
12527
4697a36c
MM
12528 V.4 stack frames look like:
12529
12530 SP----> +---------------------------------------+
12531 | back chain to caller | 0
12532 +---------------------------------------+
5eb387b8 12533 | caller's saved LR | 4
4697a36c
MM
12534 +---------------------------------------+
12535 | Parameter save area (P) | 8
12536 +---------------------------------------+
a7df97e6 12537 | Alloca space (A) | 8+P
f676971a 12538 +---------------------------------------+
a7df97e6 12539 | Varargs save area (V) | 8+P+A
f676971a 12540 +---------------------------------------+
a7df97e6 12541 | Local variable space (L) | 8+P+A+V
f676971a 12542 +---------------------------------------+
a7df97e6 12543 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 12544 +---------------------------------------+
00b960c7
AH
12545 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
12546 +---------------------------------------+
12547 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
12548 +---------------------------------------+
12549 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
12550 +---------------------------------------+
c4ad648e
AM
12551 | SPE: area for 64-bit GP registers |
12552 +---------------------------------------+
12553 | SPE alignment padding |
12554 +---------------------------------------+
00b960c7 12555 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
f676971a 12556 +---------------------------------------+
00b960c7 12557 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
f676971a 12558 +---------------------------------------+
00b960c7 12559 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
12560 +---------------------------------------+
12561 old SP->| back chain to caller's caller |
12562 +---------------------------------------+
b6c9286a 12563
5376a30c
KR
12564 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
12565 given. (But note below and in sysv4.h that we require only 8 and
12566 may round up the size of our stack frame anyways. The historical
12567 reason is early versions of powerpc-linux which didn't properly
12568 align the stack at program startup. A happy side-effect is that
12569 -mno-eabi libraries can be used with -meabi programs.)
12570
50d440bc 12571 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
12572 the stack alignment requirements may differ. If -mno-eabi is not
12573 given, the required stack alignment is 8 bytes; if -mno-eabi is
12574 given, the required alignment is 16 bytes. (But see V.4 comment
12575 above.) */
4697a36c 12576
61b2fbe7
MM
12577#ifndef ABI_STACK_BOUNDARY
12578#define ABI_STACK_BOUNDARY STACK_BOUNDARY
12579#endif
12580
d1d0c603 12581static rs6000_stack_t *
863d938c 12582rs6000_stack_info (void)
4697a36c
MM
12583{
12584 static rs6000_stack_t info, zero_info;
12585 rs6000_stack_t *info_ptr = &info;
327e5343 12586 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 12587 int ehrd_size;
64045029 12588 int save_align;
44688022 12589 HOST_WIDE_INT non_fixed_size;
4697a36c 12590
a4f6c312 12591 /* Zero all fields portably. */
4697a36c
MM
12592 info = zero_info;
12593
c19de7aa
AH
12594 if (TARGET_SPE)
12595 {
12596 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
12597 if (cfun->machine->insn_chain_scanned_p == 0)
12598 {
12599 cfun->machine->insn_chain_scanned_p = 1;
12600 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
12601 }
c19de7aa
AH
12602 }
12603
a4f6c312 12604 /* Select which calling sequence. */
178274da 12605 info_ptr->abi = DEFAULT_ABI;
9878760c 12606
a4f6c312 12607 /* Calculate which registers need to be saved & save area size. */
4697a36c 12608 info_ptr->first_gp_reg_save = first_reg_to_save ();
f676971a 12609 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 12610 even if it currently looks like we won't. */
2bfcf297 12611 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
12612 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
12613 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
12614 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
12615 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
12616 else
12617 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 12618
a3170dc6
AH
12619 /* For the SPE, we have an additional upper 32-bits on each GPR.
12620 Ideally we should save the entire 64-bits only when the upper
12621 half is used in SIMD instructions. Since we only record
12622 registers live (not the size they are used in), this proves
12623 difficult because we'd have to traverse the instruction chain at
12624 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
12625 so we opt to save the GPRs in 64-bits always if but one register
12626 gets used in 64-bits. Otherwise, all the registers in the frame
12627 get saved in 32-bits.
a3170dc6 12628
c19de7aa 12629 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 12630 traditional GP save area will be empty. */
c19de7aa 12631 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
12632 info_ptr->gp_size = 0;
12633
4697a36c
MM
12634 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
12635 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
12636
00b960c7
AH
12637 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
12638 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
12639 - info_ptr->first_altivec_reg_save);
12640
592696dd 12641 /* Does this function call anything? */
71f123ca
FS
12642 info_ptr->calls_p = (! current_function_is_leaf
12643 || cfun->machine->ra_needs_full_frame);
b6c9286a 12644
a4f6c312 12645 /* Determine if we need to save the link register. */
71f123ca 12646 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
12647 || (DEFAULT_ABI == ABI_AIX
12648 && current_function_profile
12649 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
12650#ifdef TARGET_RELOCATABLE
12651 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
12652#endif
12653 || (info_ptr->first_fp_reg_save != 64
12654 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 12655 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 12656 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
12657 || (DEFAULT_ABI == ABI_DARWIN
12658 && flag_pic
12659 && current_function_uses_pic_offset_table)
4697a36c
MM
12660 || info_ptr->calls_p)
12661 {
12662 info_ptr->lr_save_p = 1;
9ebbca7d 12663 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
12664 }
12665
9ebbca7d 12666 /* Determine if we need to save the condition code registers. */
f676971a 12667 if (regs_ever_live[CR2_REGNO]
9ebbca7d
GK
12668 || regs_ever_live[CR3_REGNO]
12669 || regs_ever_live[CR4_REGNO])
4697a36c
MM
12670 {
12671 info_ptr->cr_save_p = 1;
178274da 12672 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
12673 info_ptr->cr_size = reg_size;
12674 }
12675
83720594
RH
12676 /* If the current function calls __builtin_eh_return, then we need
12677 to allocate stack space for registers that will hold data for
12678 the exception handler. */
12679 if (current_function_calls_eh_return)
12680 {
12681 unsigned int i;
12682 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
12683 continue;
a3170dc6
AH
12684
12685 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
12686 ehrd_size = i * (TARGET_SPE_ABI
12687 && info_ptr->spe_64bit_regs_used != 0
12688 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
12689 }
12690 else
12691 ehrd_size = 0;
12692
592696dd 12693 /* Determine various sizes. */
4697a36c
MM
12694 info_ptr->reg_size = reg_size;
12695 info_ptr->fixed_size = RS6000_SAVE_AREA;
12696 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 12697 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 12698 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 12699 TARGET_ALTIVEC ? 16 : 8);
00b960c7 12700
c19de7aa 12701 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
12702 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
12703 else
12704 info_ptr->spe_gp_size = 0;
12705
4d774ff8
HP
12706 if (TARGET_ALTIVEC_ABI)
12707 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 12708 else
4d774ff8
HP
12709 info_ptr->vrsave_mask = 0;
12710
12711 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
12712 info_ptr->vrsave_size = 4;
12713 else
12714 info_ptr->vrsave_size = 0;
b6c9286a 12715
d62294f5
FJ
12716 compute_save_world_info (info_ptr);
12717
592696dd 12718 /* Calculate the offsets. */
178274da 12719 switch (DEFAULT_ABI)
4697a36c 12720 {
b6c9286a 12721 case ABI_NONE:
24d304eb 12722 default:
b6c9286a
MM
12723 abort ();
12724
12725 case ABI_AIX:
ee890fe2 12726 case ABI_DARWIN:
b6c9286a
MM
12727 info_ptr->fp_save_offset = - info_ptr->fp_size;
12728 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
12729
12730 if (TARGET_ALTIVEC_ABI)
12731 {
12732 info_ptr->vrsave_save_offset
12733 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
12734
12735 /* Align stack so vector save area is on a quadword boundary. */
12736 if (info_ptr->altivec_size != 0)
12737 info_ptr->altivec_padding_size
12738 = 16 - (-info_ptr->vrsave_save_offset % 16);
12739 else
12740 info_ptr->altivec_padding_size = 0;
12741
12742 info_ptr->altivec_save_offset
12743 = info_ptr->vrsave_save_offset
12744 - info_ptr->altivec_padding_size
12745 - info_ptr->altivec_size;
12746
12747 /* Adjust for AltiVec case. */
12748 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
12749 }
12750 else
12751 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
12752 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
12753 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
12754 break;
12755
12756 case ABI_V4:
b6c9286a
MM
12757 info_ptr->fp_save_offset = - info_ptr->fp_size;
12758 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 12759 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 12760
c19de7aa 12761 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
c4ad648e
AM
12762 {
12763 /* Align stack so SPE GPR save area is aligned on a
12764 double-word boundary. */
12765 if (info_ptr->spe_gp_size != 0)
12766 info_ptr->spe_padding_size
12767 = 8 - (-info_ptr->cr_save_offset % 8);
12768 else
12769 info_ptr->spe_padding_size = 0;
12770
12771 info_ptr->spe_gp_save_offset
12772 = info_ptr->cr_save_offset
12773 - info_ptr->spe_padding_size
12774 - info_ptr->spe_gp_size;
12775
12776 /* Adjust for SPE case. */
12777 info_ptr->toc_save_offset
12778 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
12779 }
a3170dc6 12780 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
12781 {
12782 info_ptr->vrsave_save_offset
12783 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
12784
12785 /* Align stack so vector save area is on a quadword boundary. */
12786 if (info_ptr->altivec_size != 0)
12787 info_ptr->altivec_padding_size
12788 = 16 - (-info_ptr->vrsave_save_offset % 16);
12789 else
12790 info_ptr->altivec_padding_size = 0;
12791
12792 info_ptr->altivec_save_offset
12793 = info_ptr->vrsave_save_offset
12794 - info_ptr->altivec_padding_size
12795 - info_ptr->altivec_size;
12796
12797 /* Adjust for AltiVec case. */
12798 info_ptr->toc_save_offset
12799 = info_ptr->altivec_save_offset - info_ptr->toc_size;
12800 }
12801 else
12802 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 12803 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
12804 info_ptr->lr_save_offset = reg_size;
12805 break;
4697a36c
MM
12806 }
12807
64045029 12808 save_align = (TARGET_ALTIVEC_ABI || DEFAULT_ABI == ABI_DARWIN) ? 16 : 8;
00b960c7
AH
12809 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
12810 + info_ptr->gp_size
12811 + info_ptr->altivec_size
12812 + info_ptr->altivec_padding_size
a3170dc6
AH
12813 + info_ptr->spe_gp_size
12814 + info_ptr->spe_padding_size
00b960c7
AH
12815 + ehrd_size
12816 + info_ptr->cr_size
12817 + info_ptr->lr_size
12818 + info_ptr->vrsave_size
12819 + info_ptr->toc_size,
64045029 12820 save_align);
00b960c7 12821
44688022 12822 non_fixed_size = (info_ptr->vars_size
ff381587 12823 + info_ptr->parm_size
ff381587 12824 + info_ptr->save_size
44688022 12825 + info_ptr->varargs_size);
ff381587 12826
44688022
AM
12827 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
12828 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
12829
12830 /* Determine if we need to allocate any stack frame:
12831
a4f6c312
SS
12832 For AIX we need to push the stack if a frame pointer is needed
12833 (because the stack might be dynamically adjusted), if we are
12834 debugging, if we make calls, or if the sum of fp_save, gp_save,
12835 and local variables are more than the space needed to save all
12836 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
12837 + 18*8 = 288 (GPR13 reserved).
ff381587 12838
a4f6c312
SS
12839 For V.4 we don't have the stack cushion that AIX uses, but assume
12840 that the debugger can handle stackless frames. */
ff381587
MM
12841
12842 if (info_ptr->calls_p)
12843 info_ptr->push_p = 1;
12844
178274da 12845 else if (DEFAULT_ABI == ABI_V4)
44688022 12846 info_ptr->push_p = non_fixed_size != 0;
ff381587 12847
178274da
AM
12848 else if (frame_pointer_needed)
12849 info_ptr->push_p = 1;
12850
12851 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
12852 info_ptr->push_p = 1;
12853
ff381587 12854 else
44688022 12855 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 12856
a4f6c312 12857 /* Zero offsets if we're not saving those registers. */
8dda1a21 12858 if (info_ptr->fp_size == 0)
4697a36c
MM
12859 info_ptr->fp_save_offset = 0;
12860
8dda1a21 12861 if (info_ptr->gp_size == 0)
4697a36c
MM
12862 info_ptr->gp_save_offset = 0;
12863
00b960c7
AH
12864 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
12865 info_ptr->altivec_save_offset = 0;
12866
12867 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
12868 info_ptr->vrsave_save_offset = 0;
12869
c19de7aa
AH
12870 if (! TARGET_SPE_ABI
12871 || info_ptr->spe_64bit_regs_used == 0
12872 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
12873 info_ptr->spe_gp_save_offset = 0;
12874
c81fc13e 12875 if (! info_ptr->lr_save_p)
4697a36c
MM
12876 info_ptr->lr_save_offset = 0;
12877
c81fc13e 12878 if (! info_ptr->cr_save_p)
4697a36c
MM
12879 info_ptr->cr_save_offset = 0;
12880
c81fc13e 12881 if (! info_ptr->toc_save_p)
b6c9286a
MM
12882 info_ptr->toc_save_offset = 0;
12883
4697a36c
MM
12884 return info_ptr;
12885}
12886
c19de7aa
AH
12887/* Return true if the current function uses any GPRs in 64-bit SIMD
12888 mode. */
12889
12890static bool
863d938c 12891spe_func_has_64bit_regs_p (void)
c19de7aa
AH
12892{
12893 rtx insns, insn;
12894
12895 /* Functions that save and restore all the call-saved registers will
12896 need to save/restore the registers in 64-bits. */
12897 if (current_function_calls_eh_return
12898 || current_function_calls_setjmp
12899 || current_function_has_nonlocal_goto)
12900 return true;
12901
12902 insns = get_insns ();
12903
12904 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
12905 {
12906 if (INSN_P (insn))
12907 {
12908 rtx i;
12909
12910 i = PATTERN (insn);
f82f556d
AH
12911 if (GET_CODE (i) == SET)
12912 {
12913 enum machine_mode mode = GET_MODE (SET_SRC (i));
12914
12915 if (SPE_VECTOR_MODE (mode))
12916 return true;
12917 if (TARGET_E500_DOUBLE && mode == DFmode)
12918 return true;
12919 }
c19de7aa
AH
12920 }
12921 }
12922
12923 return false;
12924}
12925
d1d0c603 12926static void
a2369ed3 12927debug_stack_info (rs6000_stack_t *info)
9878760c 12928{
d330fd93 12929 const char *abi_string;
24d304eb 12930
c81fc13e 12931 if (! info)
4697a36c
MM
12932 info = rs6000_stack_info ();
12933
12934 fprintf (stderr, "\nStack information for function %s:\n",
12935 ((current_function_decl && DECL_NAME (current_function_decl))
12936 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
12937 : "<unknown>"));
12938
24d304eb
RK
12939 switch (info->abi)
12940 {
b6c9286a
MM
12941 default: abi_string = "Unknown"; break;
12942 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 12943 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 12944 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 12945 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
12946 }
12947
12948 fprintf (stderr, "\tABI = %5s\n", abi_string);
12949
00b960c7
AH
12950 if (TARGET_ALTIVEC_ABI)
12951 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
12952
a3170dc6
AH
12953 if (TARGET_SPE_ABI)
12954 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
12955
4697a36c
MM
12956 if (info->first_gp_reg_save != 32)
12957 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
12958
12959 if (info->first_fp_reg_save != 64)
12960 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 12961
00b960c7
AH
12962 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
12963 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
12964 info->first_altivec_reg_save);
12965
4697a36c
MM
12966 if (info->lr_save_p)
12967 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 12968
4697a36c
MM
12969 if (info->cr_save_p)
12970 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
12971
b6c9286a
MM
12972 if (info->toc_save_p)
12973 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
12974
00b960c7
AH
12975 if (info->vrsave_mask)
12976 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
12977
4697a36c
MM
12978 if (info->push_p)
12979 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
12980
12981 if (info->calls_p)
12982 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
12983
4697a36c
MM
12984 if (info->gp_save_offset)
12985 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
12986
12987 if (info->fp_save_offset)
12988 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
12989
00b960c7
AH
12990 if (info->altivec_save_offset)
12991 fprintf (stderr, "\taltivec_save_offset = %5d\n",
12992 info->altivec_save_offset);
12993
a3170dc6
AH
12994 if (info->spe_gp_save_offset)
12995 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
12996 info->spe_gp_save_offset);
12997
00b960c7
AH
12998 if (info->vrsave_save_offset)
12999 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
13000 info->vrsave_save_offset);
13001
4697a36c
MM
13002 if (info->lr_save_offset)
13003 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
13004
13005 if (info->cr_save_offset)
13006 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
13007
b6c9286a
MM
13008 if (info->toc_save_offset)
13009 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
13010
4697a36c
MM
13011 if (info->varargs_save_offset)
13012 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
13013
13014 if (info->total_size)
d1d0c603
JJ
13015 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
13016 info->total_size);
4697a36c
MM
13017
13018 if (info->varargs_size)
13019 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
13020
13021 if (info->vars_size)
d1d0c603
JJ
13022 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
13023 info->vars_size);
4697a36c
MM
13024
13025 if (info->parm_size)
13026 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
13027
13028 if (info->fixed_size)
13029 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
13030
13031 if (info->gp_size)
13032 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
13033
a3170dc6
AH
13034 if (info->spe_gp_size)
13035 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
13036
4697a36c
MM
13037 if (info->fp_size)
13038 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
13039
00b960c7
AH
13040 if (info->altivec_size)
13041 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
13042
13043 if (info->vrsave_size)
13044 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
13045
13046 if (info->altivec_padding_size)
13047 fprintf (stderr, "\taltivec_padding_size= %5d\n",
13048 info->altivec_padding_size);
13049
a3170dc6
AH
13050 if (info->spe_padding_size)
13051 fprintf (stderr, "\tspe_padding_size = %5d\n",
13052 info->spe_padding_size);
13053
a4f6c312 13054 if (info->lr_size)
ed947a96 13055 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 13056
4697a36c
MM
13057 if (info->cr_size)
13058 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
13059
a4f6c312 13060 if (info->toc_size)
b6c9286a
MM
13061 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
13062
4697a36c
MM
13063 if (info->save_size)
13064 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
13065
13066 if (info->reg_size != 4)
13067 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
13068
13069 fprintf (stderr, "\n");
9878760c 13070}
71f123ca
FS
13071
13072rtx
a2369ed3 13073rs6000_return_addr (int count, rtx frame)
71f123ca 13074{
a4f6c312
SS
13075 /* Currently we don't optimize very well between prolog and body
13076 code and for PIC code the code can be actually quite bad, so
13077 don't try to be too clever here. */
f1384257 13078 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
13079 {
13080 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
13081
13082 return
13083 gen_rtx_MEM
13084 (Pmode,
13085 memory_address
13086 (Pmode,
13087 plus_constant (copy_to_reg
13088 (gen_rtx_MEM (Pmode,
13089 memory_address (Pmode, frame))),
13090 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
13091 }
13092
8c29550d 13093 cfun->machine->ra_need_lr = 1;
9e2f7ec7 13094 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
13095}
13096
5e1bf043
DJ
13097/* Say whether a function is a candidate for sibcall handling or not.
13098 We do not allow indirect calls to be optimized into sibling calls.
13099 Also, we can't do it if there are any vector parameters; there's
13100 nowhere to put the VRsave code so it works; note that functions with
13101 vector parameters are required to have a prototype, so the argument
13102 type info must be available here. (The tail recursion case can work
13103 with vector parameters, but there's no way to distinguish here.) */
4977bab6 13104static bool
a2369ed3 13105rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
13106{
13107 tree type;
4977bab6 13108 if (decl)
5e1bf043
DJ
13109 {
13110 if (TARGET_ALTIVEC_VRSAVE)
c4ad648e 13111 {
4977bab6 13112 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
13113 type; type = TREE_CHAIN (type))
13114 {
c15b529f 13115 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 13116 return false;
5e1bf043 13117 }
c4ad648e 13118 }
5e1bf043 13119 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 13120 || (*targetm.binds_local_p) (decl))
2bcc50d0 13121 {
4977bab6 13122 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
13123
13124 if (!lookup_attribute ("longcall", attr_list)
13125 || lookup_attribute ("shortcall", attr_list))
4977bab6 13126 return true;
2bcc50d0 13127 }
5e1bf043 13128 }
4977bab6 13129 return false;
5e1bf043
DJ
13130}
13131
71f123ca 13132static int
863d938c 13133rs6000_ra_ever_killed (void)
71f123ca
FS
13134{
13135 rtx top;
5e1bf043
DJ
13136 rtx reg;
13137 rtx insn;
71f123ca 13138
dd292d0a 13139 if (current_function_is_thunk)
71f123ca 13140 return 0;
eb0424da 13141
36f7e964
AH
13142 /* regs_ever_live has LR marked as used if any sibcalls are present,
13143 but this should not force saving and restoring in the
13144 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 13145 clobbers LR, so that is inappropriate. */
36f7e964 13146
5e1bf043
DJ
13147 /* Also, the prologue can generate a store into LR that
13148 doesn't really count, like this:
36f7e964 13149
5e1bf043
DJ
13150 move LR->R0
13151 bcl to set PIC register
13152 move LR->R31
13153 move R0->LR
36f7e964
AH
13154
13155 When we're called from the epilogue, we need to avoid counting
13156 this as a store. */
f676971a 13157
71f123ca
FS
13158 push_topmost_sequence ();
13159 top = get_insns ();
13160 pop_topmost_sequence ();
5e1bf043 13161 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 13162
5e1bf043
DJ
13163 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
13164 {
13165 if (INSN_P (insn))
13166 {
13167 if (FIND_REG_INC_NOTE (insn, reg))
13168 return 1;
f676971a 13169 else if (GET_CODE (insn) == CALL_INSN
c15b529f 13170 && !SIBLING_CALL_P (insn))
5e1bf043 13171 return 1;
36f7e964
AH
13172 else if (set_of (reg, insn) != NULL_RTX
13173 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
13174 return 1;
13175 }
13176 }
13177 return 0;
71f123ca 13178}
4697a36c 13179\f
8cd8f856
GK
13180/* Add a REG_MAYBE_DEAD note to the insn. */
13181static void
a2369ed3 13182rs6000_maybe_dead (rtx insn)
8cd8f856
GK
13183{
13184 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
13185 const0_rtx,
13186 REG_NOTES (insn));
13187}
13188
9ebbca7d 13189/* Emit instructions needed to load the TOC register.
c7ca610e 13190 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 13191 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
13192
13193void
a2369ed3 13194rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 13195{
027fbf43 13196 rtx dest, insn;
1db02437 13197 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 13198
20b71b17
AM
13199 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
13200 {
13201 rtx temp = (fromprolog
13202 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
13203 : gen_reg_rtx (Pmode));
027fbf43
JJ
13204 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
13205 if (fromprolog)
13206 rs6000_maybe_dead (insn);
13207 insn = emit_move_insn (dest, temp);
13208 if (fromprolog)
13209 rs6000_maybe_dead (insn);
20b71b17
AM
13210 }
13211 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
13212 {
13213 char buf[30];
13214 rtx tempLR = (fromprolog
13215 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
13216 : gen_reg_rtx (Pmode));
13217 rtx temp0 = (fromprolog
13218 ? gen_rtx_REG (Pmode, 0)
13219 : gen_reg_rtx (Pmode));
13220 rtx symF;
13221
13222 /* possibly create the toc section */
13223 if (! toc_initialized)
38c1f2d7 13224 {
20b71b17
AM
13225 toc_section ();
13226 function_section (current_function_decl);
38c1f2d7 13227 }
9ebbca7d 13228
20b71b17
AM
13229 if (fromprolog)
13230 {
13231 rtx symL;
38c1f2d7 13232
20b71b17
AM
13233 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
13234 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 13235
20b71b17
AM
13236 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
13237 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
13238
13239 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
13240 symF)));
13241 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
13242 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
13243 symL,
13244 symF)));
9ebbca7d
GK
13245 }
13246 else
20b71b17
AM
13247 {
13248 rtx tocsym;
13249 static int reload_toc_labelno = 0;
13250
13251 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
13252
13253 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
13254 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
13255
027fbf43
JJ
13256 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
13257 emit_move_insn (dest, tempLR);
13258 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 13259 }
027fbf43
JJ
13260 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
13261 if (fromprolog)
13262 rs6000_maybe_dead (insn);
9ebbca7d 13263 }
20b71b17
AM
13264 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
13265 {
13266 /* This is for AIX code running in non-PIC ELF32. */
13267 char buf[30];
13268 rtx realsym;
13269 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
13270 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
13271
027fbf43
JJ
13272 insn = emit_insn (gen_elf_high (dest, realsym));
13273 if (fromprolog)
13274 rs6000_maybe_dead (insn);
13275 insn = emit_insn (gen_elf_low (dest, dest, realsym));
13276 if (fromprolog)
13277 rs6000_maybe_dead (insn);
20b71b17
AM
13278 }
13279 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
13280 {
13281 if (TARGET_32BIT)
027fbf43 13282 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 13283 else
027fbf43
JJ
13284 insn = emit_insn (gen_load_toc_aix_di (dest));
13285 if (fromprolog)
13286 rs6000_maybe_dead (insn);
9ebbca7d 13287 }
20b71b17
AM
13288 else
13289 abort ();
9ebbca7d
GK
13290}
13291
d1d0c603
JJ
13292/* Emit instructions to restore the link register after determining where
13293 its value has been stored. */
13294
13295void
13296rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
13297{
13298 rs6000_stack_t *info = rs6000_stack_info ();
13299 rtx operands[2];
13300
13301 operands[0] = source;
13302 operands[1] = scratch;
13303
13304 if (info->lr_save_p)
13305 {
13306 rtx frame_rtx = stack_pointer_rtx;
13307 HOST_WIDE_INT sp_offset = 0;
13308 rtx tmp;
13309
13310 if (frame_pointer_needed
13311 || current_function_calls_alloca
13312 || info->total_size > 32767)
13313 {
13314 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
13315 frame_rtx = operands[1];
13316 }
13317 else if (info->push_p)
13318 sp_offset = info->total_size;
13319
13320 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
13321 tmp = gen_rtx_MEM (Pmode, tmp);
13322 emit_move_insn (tmp, operands[0]);
13323 }
13324 else
13325 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
13326}
13327
f103e34d
GK
13328static GTY(()) int set = -1;
13329
f676971a 13330int
863d938c 13331get_TOC_alias_set (void)
9ebbca7d 13332{
f103e34d
GK
13333 if (set == -1)
13334 set = new_alias_set ();
13335 return set;
f676971a 13336}
9ebbca7d 13337
c1207243 13338/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
13339 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
13340 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 13341#if TARGET_ELF
3c9eb5f4 13342static int
f676971a 13343uses_TOC (void)
9ebbca7d 13344{
c4501e62 13345 rtx insn;
38c1f2d7 13346
c4501e62
JJ
13347 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
13348 if (INSN_P (insn))
13349 {
13350 rtx pat = PATTERN (insn);
13351 int i;
9ebbca7d 13352
f676971a 13353 if (GET_CODE (pat) == PARALLEL)
c4501e62
JJ
13354 for (i = 0; i < XVECLEN (pat, 0); i++)
13355 {
13356 rtx sub = XVECEXP (pat, 0, i);
13357 if (GET_CODE (sub) == USE)
13358 {
13359 sub = XEXP (sub, 0);
13360 if (GET_CODE (sub) == UNSPEC
13361 && XINT (sub, 1) == UNSPEC_TOC)
13362 return 1;
13363 }
13364 }
13365 }
13366 return 0;
9ebbca7d 13367}
c954844a 13368#endif
38c1f2d7 13369
9ebbca7d 13370rtx
f676971a 13371create_TOC_reference (rtx symbol)
9ebbca7d 13372{
f676971a 13373 return gen_rtx_PLUS (Pmode,
a8a05998 13374 gen_rtx_REG (Pmode, TOC_REGISTER),
f676971a
EC
13375 gen_rtx_CONST (Pmode,
13376 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 13377 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 13378}
38c1f2d7 13379
fc4767bb
JJ
13380/* If _Unwind_* has been called from within the same module,
13381 toc register is not guaranteed to be saved to 40(1) on function
13382 entry. Save it there in that case. */
c7ca610e 13383
9ebbca7d 13384void
863d938c 13385rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
13386{
13387 rtx mem;
13388 rtx stack_top = gen_reg_rtx (Pmode);
13389 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
13390 rtx opcode = gen_reg_rtx (SImode);
13391 rtx tocompare = gen_reg_rtx (SImode);
13392 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
13393
13394 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
13395 emit_move_insn (stack_top, mem);
13396
fc4767bb
JJ
13397 mem = gen_rtx_MEM (Pmode,
13398 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
13399 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
13400 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
13401 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
13402 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 13403 : 0xE8410028, SImode));
9ebbca7d 13404
fc4767bb 13405 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 13406 SImode, NULL_RTX, NULL_RTX,
fc4767bb 13407 no_toc_save_needed);
9ebbca7d 13408
fc4767bb
JJ
13409 mem = gen_rtx_MEM (Pmode,
13410 gen_rtx_PLUS (Pmode, stack_top,
13411 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
13412 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
13413 emit_label (no_toc_save_needed);
9ebbca7d 13414}
38c1f2d7 13415\f
ba4828e0
RK
13416/* This ties together stack memory (MEM with an alias set of
13417 rs6000_sr_alias_set) and the change to the stack pointer. */
13418
9ebbca7d 13419static void
863d938c 13420rs6000_emit_stack_tie (void)
9ebbca7d 13421{
ba4828e0
RK
13422 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
13423
13424 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13425 emit_insn (gen_stack_tie (mem));
13426}
38c1f2d7 13427
9ebbca7d
GK
13428/* Emit the correct code for allocating stack space, as insns.
13429 If COPY_R12, make sure a copy of the old frame is left in r12.
13430 The generated code may use hard register 0 as a temporary. */
13431
13432static void
a2369ed3 13433rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 13434{
9ebbca7d
GK
13435 rtx insn;
13436 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
13437 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
61168ff1
RS
13438 rtx todec = gen_int_mode (-size, Pmode);
13439
13440 if (INTVAL (todec) != -size)
13441 {
13442 warning("stack frame too large");
13443 emit_insn (gen_trap ());
13444 return;
13445 }
a157febd
GK
13446
13447 if (current_function_limit_stack)
13448 {
13449 if (REG_P (stack_limit_rtx)
f676971a 13450 && REGNO (stack_limit_rtx) > 1
a157febd
GK
13451 && REGNO (stack_limit_rtx) <= 31)
13452 {
5b71a4e7 13453 emit_insn (TARGET_32BIT
9ebbca7d
GK
13454 ? gen_addsi3 (tmp_reg,
13455 stack_limit_rtx,
13456 GEN_INT (size))
13457 : gen_adddi3 (tmp_reg,
13458 stack_limit_rtx,
13459 GEN_INT (size)));
5b71a4e7 13460
9ebbca7d
GK
13461 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
13462 const0_rtx));
a157febd
GK
13463 }
13464 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 13465 && TARGET_32BIT
f607bc57 13466 && DEFAULT_ABI == ABI_V4)
a157febd 13467 {
9ebbca7d 13468 rtx toload = gen_rtx_CONST (VOIDmode,
f676971a
EC
13469 gen_rtx_PLUS (Pmode,
13470 stack_limit_rtx,
9ebbca7d 13471 GEN_INT (size)));
5b71a4e7 13472
9ebbca7d
GK
13473 emit_insn (gen_elf_high (tmp_reg, toload));
13474 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
13475 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
13476 const0_rtx));
a157febd
GK
13477 }
13478 else
13479 warning ("stack limit expression is not supported");
13480 }
13481
9ebbca7d
GK
13482 if (copy_r12 || ! TARGET_UPDATE)
13483 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
13484
38c1f2d7
MM
13485 if (TARGET_UPDATE)
13486 {
9ebbca7d 13487 if (size > 32767)
38c1f2d7 13488 {
9ebbca7d
GK
13489 /* Need a note here so that try_split doesn't get confused. */
13490 if (get_last_insn() == NULL_RTX)
2e040219 13491 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
13492 insn = emit_move_insn (tmp_reg, todec);
13493 try_split (PATTERN (insn), insn, 0);
13494 todec = tmp_reg;
38c1f2d7 13495 }
5b71a4e7
DE
13496
13497 insn = emit_insn (TARGET_32BIT
13498 ? gen_movsi_update (stack_reg, stack_reg,
13499 todec, stack_reg)
c4ad648e 13500 : gen_movdi_di_update (stack_reg, stack_reg,
9ebbca7d 13501 todec, stack_reg));
38c1f2d7
MM
13502 }
13503 else
13504 {
5b71a4e7
DE
13505 insn = emit_insn (TARGET_32BIT
13506 ? gen_addsi3 (stack_reg, stack_reg, todec)
13507 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
13508 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
13509 gen_rtx_REG (Pmode, 12));
13510 }
f676971a 13511
9ebbca7d 13512 RTX_FRAME_RELATED_P (insn) = 1;
f676971a 13513 REG_NOTES (insn) =
9ebbca7d 13514 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
f676971a 13515 gen_rtx_SET (VOIDmode, stack_reg,
9ebbca7d
GK
13516 gen_rtx_PLUS (Pmode, stack_reg,
13517 GEN_INT (-size))),
13518 REG_NOTES (insn));
13519}
13520
a4f6c312
SS
13521/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
13522 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
13523 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
13524 deduce these equivalences by itself so it wasn't necessary to hold
13525 its hand so much. */
9ebbca7d
GK
13526
13527static void
f676971a 13528rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
a2369ed3 13529 rtx reg2, rtx rreg)
9ebbca7d
GK
13530{
13531 rtx real, temp;
13532
e56c4463
JL
13533 /* copy_rtx will not make unique copies of registers, so we need to
13534 ensure we don't have unwanted sharing here. */
13535 if (reg == reg2)
13536 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
13537
13538 if (reg == rreg)
13539 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
13540
9ebbca7d
GK
13541 real = copy_rtx (PATTERN (insn));
13542
89e7058f
AH
13543 if (reg2 != NULL_RTX)
13544 real = replace_rtx (real, reg2, rreg);
f676971a
EC
13545
13546 real = replace_rtx (real, reg,
9ebbca7d
GK
13547 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
13548 STACK_POINTER_REGNUM),
13549 GEN_INT (val)));
f676971a 13550
9ebbca7d
GK
13551 /* We expect that 'real' is either a SET or a PARALLEL containing
13552 SETs (and possibly other stuff). In a PARALLEL, all the SETs
13553 are important so they all have to be marked RTX_FRAME_RELATED_P. */
13554
13555 if (GET_CODE (real) == SET)
13556 {
13557 rtx set = real;
f676971a 13558
9ebbca7d
GK
13559 temp = simplify_rtx (SET_SRC (set));
13560 if (temp)
13561 SET_SRC (set) = temp;
13562 temp = simplify_rtx (SET_DEST (set));
13563 if (temp)
13564 SET_DEST (set) = temp;
13565 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 13566 {
9ebbca7d
GK
13567 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
13568 if (temp)
13569 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 13570 }
38c1f2d7 13571 }
9ebbca7d
GK
13572 else if (GET_CODE (real) == PARALLEL)
13573 {
13574 int i;
13575 for (i = 0; i < XVECLEN (real, 0); i++)
13576 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
13577 {
13578 rtx set = XVECEXP (real, 0, i);
f676971a 13579
9ebbca7d
GK
13580 temp = simplify_rtx (SET_SRC (set));
13581 if (temp)
13582 SET_SRC (set) = temp;
13583 temp = simplify_rtx (SET_DEST (set));
13584 if (temp)
13585 SET_DEST (set) = temp;
13586 if (GET_CODE (SET_DEST (set)) == MEM)
13587 {
13588 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
13589 if (temp)
13590 XEXP (SET_DEST (set), 0) = temp;
13591 }
13592 RTX_FRAME_RELATED_P (set) = 1;
13593 }
13594 }
13595 else
a4f6c312 13596 abort ();
c19de7aa
AH
13597
13598 if (TARGET_SPE)
13599 real = spe_synthesize_frame_save (real);
13600
9ebbca7d
GK
13601 RTX_FRAME_RELATED_P (insn) = 1;
13602 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13603 real,
13604 REG_NOTES (insn));
38c1f2d7
MM
13605}
13606
c19de7aa
AH
13607/* Given an SPE frame note, return a PARALLEL of SETs with the
13608 original note, plus a synthetic register save. */
13609
13610static rtx
a2369ed3 13611spe_synthesize_frame_save (rtx real)
c19de7aa
AH
13612{
13613 rtx synth, offset, reg, real2;
13614
13615 if (GET_CODE (real) != SET
13616 || GET_MODE (SET_SRC (real)) != V2SImode)
13617 return real;
13618
13619 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
13620 frame related note. The parallel contains a set of the register
41f3a930 13621 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
13622 This is so we can differentiate between 64-bit and 32-bit saves.
13623 Words cannot describe this nastiness. */
13624
13625 if (GET_CODE (SET_DEST (real)) != MEM
13626 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
13627 || GET_CODE (SET_SRC (real)) != REG)
13628 abort ();
13629
13630 /* Transform:
13631 (set (mem (plus (reg x) (const y)))
13632 (reg z))
13633 into:
13634 (set (mem (plus (reg x) (const y+4)))
41f3a930 13635 (reg z+1200))
c19de7aa
AH
13636 */
13637
13638 real2 = copy_rtx (real);
13639 PUT_MODE (SET_DEST (real2), SImode);
13640 reg = SET_SRC (real2);
13641 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
13642 synth = copy_rtx (real2);
13643
13644 if (BYTES_BIG_ENDIAN)
13645 {
13646 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
13647 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
13648 }
13649
13650 reg = SET_SRC (synth);
41f3a930 13651
c19de7aa 13652 synth = replace_rtx (synth, reg,
41f3a930 13653 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
13654
13655 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
13656 synth = replace_rtx (synth, offset,
13657 GEN_INT (INTVAL (offset)
13658 + (BYTES_BIG_ENDIAN ? 0 : 4)));
13659
13660 RTX_FRAME_RELATED_P (synth) = 1;
13661 RTX_FRAME_RELATED_P (real2) = 1;
13662 if (BYTES_BIG_ENDIAN)
13663 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
13664 else
13665 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
13666
13667 return real;
13668}
13669
00b960c7
AH
13670/* Returns an insn that has a vrsave set operation with the
13671 appropriate CLOBBERs. */
13672
13673static rtx
a2369ed3 13674generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
13675{
13676 int nclobs, i;
13677 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 13678 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 13679
a004eb82
AH
13680 clobs[0]
13681 = gen_rtx_SET (VOIDmode,
13682 vrsave,
13683 gen_rtx_UNSPEC_VOLATILE (SImode,
13684 gen_rtvec (2, reg, vrsave),
13685 30));
00b960c7
AH
13686
13687 nclobs = 1;
13688
9aa86737
AH
13689 /* We need to clobber the registers in the mask so the scheduler
13690 does not move sets to VRSAVE before sets of AltiVec registers.
13691
13692 However, if the function receives nonlocal gotos, reload will set
13693 all call saved registers live. We will end up with:
13694
13695 (set (reg 999) (mem))
13696 (parallel [ (set (reg vrsave) (unspec blah))
13697 (clobber (reg 999))])
13698
13699 The clobber will cause the store into reg 999 to be dead, and
13700 flow will attempt to delete an epilogue insn. In this case, we
13701 need an unspec use/set of the register. */
00b960c7
AH
13702
13703 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
44688022 13704 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
9aa86737
AH
13705 {
13706 if (!epiloguep || call_used_regs [i])
13707 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
13708 gen_rtx_REG (V4SImode, i));
13709 else
13710 {
13711 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
13712
13713 clobs[nclobs++]
a004eb82
AH
13714 = gen_rtx_SET (VOIDmode,
13715 reg,
13716 gen_rtx_UNSPEC (V4SImode,
13717 gen_rtvec (1, reg), 27));
9aa86737
AH
13718 }
13719 }
00b960c7
AH
13720
13721 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
13722
13723 for (i = 0; i < nclobs; ++i)
13724 XVECEXP (insn, 0, i) = clobs[i];
13725
13726 return insn;
13727}
13728
89e7058f
AH
13729/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
13730 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
13731
13732static void
f676971a 13733emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 13734 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
13735{
13736 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
13737 rtx replacea, replaceb;
13738
13739 int_rtx = GEN_INT (offset);
13740
13741 /* Some cases that need register indexed addressing. */
13742 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4d4cbc0e 13743 || (TARGET_E500_DOUBLE && mode == DFmode)
a3170dc6
AH
13744 || (TARGET_SPE_ABI
13745 && SPE_VECTOR_MODE (mode)
13746 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
13747 {
13748 /* Whomever calls us must make sure r11 is available in the
c4ad648e 13749 flow path of instructions in the prologue. */
89e7058f
AH
13750 offset_rtx = gen_rtx_REG (Pmode, 11);
13751 emit_move_insn (offset_rtx, int_rtx);
13752
13753 replacea = offset_rtx;
13754 replaceb = int_rtx;
13755 }
13756 else
13757 {
13758 offset_rtx = int_rtx;
13759 replacea = NULL_RTX;
13760 replaceb = NULL_RTX;
13761 }
13762
13763 reg = gen_rtx_REG (mode, regno);
13764 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
13765 mem = gen_rtx_MEM (mode, addr);
13766 set_mem_alias_set (mem, rs6000_sr_alias_set);
13767
13768 insn = emit_move_insn (mem, reg);
13769
13770 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
13771}
13772
a3170dc6
AH
13773/* Emit an offset memory reference suitable for a frame store, while
13774 converting to a valid addressing mode. */
13775
13776static rtx
a2369ed3 13777gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
13778{
13779 rtx int_rtx, offset_rtx;
13780
13781 int_rtx = GEN_INT (offset);
13782
4d4cbc0e
AH
13783 if ((TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
13784 || (TARGET_E500_DOUBLE && mode == DFmode))
a3170dc6
AH
13785 {
13786 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13787 emit_move_insn (offset_rtx, int_rtx);
13788 }
13789 else
13790 offset_rtx = int_rtx;
13791
13792 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
13793}
13794
699c914a
MS
13795#ifndef TARGET_FIX_AND_CONTINUE
13796#define TARGET_FIX_AND_CONTINUE 0
13797#endif
13798
9ebbca7d
GK
13799/* Emit function prologue as insns. */
13800
9878760c 13801void
863d938c 13802rs6000_emit_prologue (void)
9878760c 13803{
4697a36c 13804 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 13805 enum machine_mode reg_mode = Pmode;
327e5343 13806 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
13807 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
13808 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
13809 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 13810 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
13811 rtx insn;
13812 int saving_FPRs_inline;
13813 int using_store_multiple;
13814 HOST_WIDE_INT sp_offset = 0;
f676971a 13815
699c914a
MS
13816 if (TARGET_FIX_AND_CONTINUE)
13817 {
13818 /* gdb on darwin arranges to forward a function from the old
13819 address by modifying the first 4 instructions of the function
13820 to branch to the overriding function. This is necessary to
13821 permit function pointers that point to the old function to
13822 actually forward to the new function. */
13823 emit_insn (gen_nop ());
13824 emit_insn (gen_nop ());
13825 emit_insn (gen_nop ());
13826 emit_insn (gen_nop ());
13827 }
13828
13829 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
13830 {
13831 reg_mode = V2SImode;
13832 reg_size = 8;
13833 }
a3170dc6 13834
9ebbca7d 13835 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
13836 && (!TARGET_SPE_ABI
13837 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
13838 && info->first_gp_reg_save < 31);
13839 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 13840 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 13841 || current_function_calls_eh_return
8c29550d 13842 || cfun->machine->ra_need_lr);
9ebbca7d
GK
13843
13844 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 13845 if (info->push_p
acd0b319
AM
13846 && (DEFAULT_ABI == ABI_V4
13847 || current_function_calls_eh_return))
9ebbca7d
GK
13848 {
13849 if (info->total_size < 32767)
13850 sp_offset = info->total_size;
13851 else
13852 frame_reg_rtx = frame_ptr_rtx;
f676971a 13853 rs6000_emit_allocate_stack (info->total_size,
9ebbca7d
GK
13854 (frame_reg_rtx != sp_reg_rtx
13855 && (info->cr_save_p
13856 || info->lr_save_p
13857 || info->first_fp_reg_save < 64
13858 || info->first_gp_reg_save < 32
13859 )));
13860 if (frame_reg_rtx != sp_reg_rtx)
13861 rs6000_emit_stack_tie ();
13862 }
13863
d62294f5
FJ
13864 /* Handle world saves specially here. */
13865 if (info->world_save_p)
13866 {
13867 int i, j, sz;
13868 rtx treg;
13869 rtvec p;
13870
13871 /* save_world expects lr in r0. */
13872 if (info->lr_save_p)
c4ad648e
AM
13873 {
13874 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13875 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13876 RTX_FRAME_RELATED_P (insn) = 1;
13877 }
d62294f5
FJ
13878
13879 /* The SAVE_WORLD and RESTORE_WORLD routines make a number of
c4ad648e
AM
13880 assumptions about the offsets of various bits of the stack
13881 frame. Abort if things aren't what they should be. */
d62294f5 13882 if (info->gp_save_offset != -220
c4ad648e
AM
13883 || info->fp_save_offset != -144
13884 || info->lr_save_offset != 8
13885 || info->cr_save_offset != 4
13886 || !info->push_p
13887 || !info->lr_save_p
13888 || (current_function_calls_eh_return && info->ehrd_offset != -432)
13889 || (info->vrsave_save_offset != -224
13890 || info->altivec_save_offset != (-224 -16 -192)))
13891 abort ();
d62294f5
FJ
13892
13893 treg = gen_rtx_REG (SImode, 11);
13894 emit_move_insn (treg, GEN_INT (-info->total_size));
13895
13896 /* SAVE_WORLD takes the caller's LR in R0 and the frame size
c4ad648e 13897 in R11. It also clobbers R12, so beware! */
d62294f5
FJ
13898
13899 /* Preserve CR2 for save_world prologues */
13900 sz = 6;
13901 sz += 32 - info->first_gp_reg_save;
13902 sz += 64 - info->first_fp_reg_save;
13903 sz += LAST_ALTIVEC_REGNO - info->first_altivec_reg_save + 1;
13904 p = rtvec_alloc (sz);
13905 j = 0;
13906 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode,
c4ad648e
AM
13907 gen_rtx_REG (Pmode,
13908 LINK_REGISTER_REGNUM));
d62294f5 13909 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
c4ad648e
AM
13910 gen_rtx_SYMBOL_REF (Pmode,
13911 "*save_world"));
d62294f5 13912 /* We do floats first so that the instruction pattern matches
c4ad648e
AM
13913 properly. */
13914 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13915 {
13916 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13917 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13918 GEN_INT (info->fp_save_offset
13919 + sp_offset + 8 * i));
13920 rtx mem = gen_rtx_MEM (DFmode, addr);
13921 set_mem_alias_set (mem, rs6000_sr_alias_set);
13922
13923 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13924 }
d62294f5 13925 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
c4ad648e
AM
13926 {
13927 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
13928 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13929 GEN_INT (info->altivec_save_offset
13930 + sp_offset + 16 * i));
13931 rtx mem = gen_rtx_MEM (V4SImode, addr);
13932 set_mem_alias_set (mem, rs6000_sr_alias_set);
13933
13934 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13935 }
d62294f5 13936 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
c4ad648e
AM
13937 {
13938 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13939 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13940 GEN_INT (info->gp_save_offset
13941 + sp_offset + reg_size * i));
13942 rtx mem = gen_rtx_MEM (reg_mode, addr);
13943 set_mem_alias_set (mem, rs6000_sr_alias_set);
13944
13945 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13946 }
13947
13948 {
13949 /* CR register traditionally saved as CR2. */
13950 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
13951 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13952 GEN_INT (info->cr_save_offset
13953 + sp_offset));
13954 rtx mem = gen_rtx_MEM (reg_mode, addr);
13955 set_mem_alias_set (mem, rs6000_sr_alias_set);
13956
13957 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13958 }
d62294f5
FJ
13959 /* Prevent any attempt to delete the setting of r0 and treg! */
13960 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, 0));
13961 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, treg);
13962 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode, sp_reg_rtx);
13963
13964 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
13965 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
c4ad648e 13966 NULL_RTX, NULL_RTX);
d62294f5
FJ
13967
13968 if (current_function_calls_eh_return)
c4ad648e
AM
13969 {
13970 unsigned int i;
13971 for (i = 0; ; ++i)
13972 {
13973 unsigned int regno = EH_RETURN_DATA_REGNO (i);
13974 if (regno == INVALID_REGNUM)
13975 break;
13976 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13977 info->ehrd_offset + sp_offset
13978 + reg_size * (int) i,
13979 info->total_size);
13980 }
13981 }
d62294f5
FJ
13982 }
13983
9aa86737 13984 /* Save AltiVec registers if needed. */
d62294f5 13985 if (! info->world_save_p && TARGET_ALTIVEC_ABI && info->altivec_size != 0)
9aa86737
AH
13986 {
13987 int i;
13988
13989 /* There should be a non inline version of this, for when we
13990 are saving lots of vector registers. */
13991 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
13992 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
13993 {
13994 rtx areg, savereg, mem;
13995 int offset;
13996
13997 offset = info->altivec_save_offset + sp_offset
13998 + 16 * (i - info->first_altivec_reg_save);
13999
14000 savereg = gen_rtx_REG (V4SImode, i);
14001
14002 areg = gen_rtx_REG (Pmode, 0);
14003 emit_move_insn (areg, GEN_INT (offset));
14004
14005 /* AltiVec addressing mode is [reg+reg]. */
14006 mem = gen_rtx_MEM (V4SImode,
14007 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
f676971a 14008
9aa86737
AH
14009 set_mem_alias_set (mem, rs6000_sr_alias_set);
14010
14011 insn = emit_move_insn (mem, savereg);
14012
5c242421
SB
14013 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
14014 areg, GEN_INT (offset));
9aa86737
AH
14015 }
14016 }
14017
14018 /* VRSAVE is a bit vector representing which AltiVec registers
14019 are used. The OS uses this to determine which vector
14020 registers to save on a context switch. We need to save
14021 VRSAVE on the stack frame, add whatever AltiVec registers we
14022 used in this function, and do the corresponding magic in the
14023 epilogue. */
14024
4d774ff8 14025 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
d62294f5 14026 && ! info->world_save_p && info->vrsave_mask != 0)
9aa86737 14027 {
a004eb82 14028 rtx reg, mem, vrsave;
9aa86737
AH
14029 int offset;
14030
14031 /* Get VRSAVE onto a GPR. */
14032 reg = gen_rtx_REG (SImode, 12);
a004eb82 14033 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
14034 if (TARGET_MACHO)
14035 emit_insn (gen_get_vrsave_internal (reg));
14036 else
14037 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
14038
14039 /* Save VRSAVE. */
14040 offset = info->vrsave_save_offset + sp_offset;
14041 mem
14042 = gen_rtx_MEM (SImode,
14043 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
14044 set_mem_alias_set (mem, rs6000_sr_alias_set);
14045 insn = emit_move_insn (mem, reg);
14046
14047 /* Include the registers in the mask. */
14048 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
14049
14050 insn = emit_insn (generate_set_vrsave (reg, info, 0));
14051 }
14052
9ebbca7d 14053 /* If we use the link register, get it into r0. */
d62294f5 14054 if (! info->world_save_p && info->lr_save_p)
f8a57be8
GK
14055 {
14056 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
14057 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
14058 RTX_FRAME_RELATED_P (insn) = 1;
14059 }
9ebbca7d
GK
14060
14061 /* If we need to save CR, put it into r12. */
d62294f5 14062 if (! info->world_save_p && info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
9ebbca7d 14063 {
f8a57be8 14064 rtx set;
f676971a 14065
9ebbca7d 14066 cr_save_rtx = gen_rtx_REG (SImode, 12);
f8a57be8
GK
14067 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
14068 RTX_FRAME_RELATED_P (insn) = 1;
14069 /* Now, there's no way that dwarf2out_frame_debug_expr is going
14070 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
14071 But that's OK. All we have to do is specify that _one_ condition
14072 code register is saved in this stack slot. The thrower's epilogue
14073 will then restore all the call-saved registers.
14074 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
14075 set = gen_rtx_SET (VOIDmode, cr_save_rtx,
14076 gen_rtx_REG (SImode, CR2_REGNO));
14077 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
14078 set,
14079 REG_NOTES (insn));
9ebbca7d
GK
14080 }
14081
a4f6c312
SS
14082 /* Do any required saving of fpr's. If only one or two to save, do
14083 it ourselves. Otherwise, call function. */
d62294f5 14084 if (! info->world_save_p && saving_FPRs_inline)
9ebbca7d
GK
14085 {
14086 int i;
14087 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 14088 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d 14089 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
14090 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
14091 info->first_fp_reg_save + i,
14092 info->fp_save_offset + sp_offset + 8 * i,
14093 info->total_size);
9ebbca7d 14094 }
d62294f5 14095 else if (! info->world_save_p && info->first_fp_reg_save != 64)
9ebbca7d
GK
14096 {
14097 int i;
14098 char rname[30];
520a57c8 14099 const char *alloc_rname;
9ebbca7d
GK
14100 rtvec p;
14101 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
f676971a
EC
14102
14103 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
14104 gen_rtx_REG (Pmode,
9ebbca7d
GK
14105 LINK_REGISTER_REGNUM));
14106 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
14107 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 14108 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
14109 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
14110 gen_rtx_SYMBOL_REF (Pmode,
14111 alloc_rname));
14112 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
14113 {
14114 rtx addr, reg, mem;
14115 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
14116 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a 14117 GEN_INT (info->fp_save_offset
9ebbca7d
GK
14118 + sp_offset + 8*i));
14119 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14120 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
14121
14122 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
14123 }
14124 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 14125 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d
GK
14126 NULL_RTX, NULL_RTX);
14127 }
b6c9286a 14128
9ebbca7d
GK
14129 /* Save GPRs. This is done as a PARALLEL if we are using
14130 the store-multiple instructions. */
d62294f5 14131 if (! info->world_save_p && using_store_multiple)
b6c9286a 14132 {
308c142a 14133 rtvec p;
9ebbca7d
GK
14134 int i;
14135 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
14136 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
14137 {
14138 rtx addr, reg, mem;
14139 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
f676971a
EC
14140 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14141 GEN_INT (info->gp_save_offset
14142 + sp_offset
9ebbca7d
GK
14143 + reg_size * i));
14144 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 14145 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
14146
14147 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
14148 }
14149 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 14150 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d 14151 NULL_RTX, NULL_RTX);
b6c9286a 14152 }
d62294f5 14153 else if (! info->world_save_p)
b6c9286a 14154 {
9ebbca7d
GK
14155 int i;
14156 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 14157 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
14158 && (! call_used_regs[info->first_gp_reg_save+i]
14159 || (i+info->first_gp_reg_save
14160 == RS6000_PIC_OFFSET_TABLE_REGNUM
14161 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 14162 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 14163 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 14164 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
14165 {
14166 rtx addr, reg, mem;
14167 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
14168
c19de7aa 14169 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
14170 {
14171 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
14172 rtx b;
14173
14174 if (!SPE_CONST_OFFSET_OK (offset))
14175 {
14176 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
14177 emit_move_insn (b, GEN_INT (offset));
14178 }
14179 else
14180 b = GEN_INT (offset);
14181
14182 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
14183 mem = gen_rtx_MEM (V2SImode, addr);
14184 set_mem_alias_set (mem, rs6000_sr_alias_set);
14185 insn = emit_move_insn (mem, reg);
14186
14187 if (GET_CODE (b) == CONST_INT)
14188 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
14189 NULL_RTX, NULL_RTX);
14190 else
14191 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
14192 b, GEN_INT (offset));
14193 }
14194 else
14195 {
f676971a
EC
14196 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14197 GEN_INT (info->gp_save_offset
14198 + sp_offset
a3170dc6
AH
14199 + reg_size * i));
14200 mem = gen_rtx_MEM (reg_mode, addr);
14201 set_mem_alias_set (mem, rs6000_sr_alias_set);
14202
14203 insn = emit_move_insn (mem, reg);
f676971a 14204 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a3170dc6
AH
14205 NULL_RTX, NULL_RTX);
14206 }
14207 }
9ebbca7d
GK
14208 }
14209
83720594
RH
14210 /* ??? There's no need to emit actual instructions here, but it's the
14211 easiest way to get the frame unwind information emitted. */
d62294f5 14212 if (! info->world_save_p && current_function_calls_eh_return)
83720594 14213 {
78e1b90d
DE
14214 unsigned int i, regno;
14215
fc4767bb
JJ
14216 /* In AIX ABI we need to pretend we save r2 here. */
14217 if (TARGET_AIX)
14218 {
14219 rtx addr, reg, mem;
14220
14221 reg = gen_rtx_REG (reg_mode, 2);
14222 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14223 GEN_INT (sp_offset + 5 * reg_size));
14224 mem = gen_rtx_MEM (reg_mode, addr);
14225 set_mem_alias_set (mem, rs6000_sr_alias_set);
14226
14227 insn = emit_move_insn (mem, reg);
f676971a 14228 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
fc4767bb
JJ
14229 NULL_RTX, NULL_RTX);
14230 PATTERN (insn) = gen_blockage ();
14231 }
14232
83720594
RH
14233 for (i = 0; ; ++i)
14234 {
83720594
RH
14235 regno = EH_RETURN_DATA_REGNO (i);
14236 if (regno == INVALID_REGNUM)
14237 break;
14238
89e7058f
AH
14239 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
14240 info->ehrd_offset + sp_offset
14241 + reg_size * (int) i,
14242 info->total_size);
83720594
RH
14243 }
14244 }
14245
9ebbca7d 14246 /* Save lr if we used it. */
d62294f5 14247 if (! info->world_save_p && info->lr_save_p)
9ebbca7d
GK
14248 {
14249 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14250 GEN_INT (info->lr_save_offset + sp_offset));
14251 rtx reg = gen_rtx_REG (Pmode, 0);
14252 rtx mem = gen_rtx_MEM (Pmode, addr);
14253 /* This should not be of rs6000_sr_alias_set, because of
14254 __builtin_return_address. */
f676971a 14255
9ebbca7d 14256 insn = emit_move_insn (mem, reg);
f676971a 14257 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 14258 NULL_RTX, NULL_RTX);
9ebbca7d
GK
14259 }
14260
14261 /* Save CR if we use any that must be preserved. */
d62294f5 14262 if (! info->world_save_p && info->cr_save_p)
9ebbca7d
GK
14263 {
14264 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14265 GEN_INT (info->cr_save_offset + sp_offset));
14266 rtx mem = gen_rtx_MEM (SImode, addr);
f8a57be8
GK
14267 /* See the large comment above about why CR2_REGNO is used. */
14268 rtx magic_eh_cr_reg = gen_rtx_REG (SImode, CR2_REGNO);
ba4828e0
RK
14269
14270 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
14271
14272 /* If r12 was used to hold the original sp, copy cr into r0 now
14273 that it's free. */
14274 if (REGNO (frame_reg_rtx) == 12)
14275 {
f8a57be8
GK
14276 rtx set;
14277
9ebbca7d 14278 cr_save_rtx = gen_rtx_REG (SImode, 0);
f8a57be8
GK
14279 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
14280 RTX_FRAME_RELATED_P (insn) = 1;
14281 set = gen_rtx_SET (VOIDmode, cr_save_rtx, magic_eh_cr_reg);
14282 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
14283 set,
14284 REG_NOTES (insn));
f676971a 14285
9ebbca7d
GK
14286 }
14287 insn = emit_move_insn (mem, cr_save_rtx);
14288
f676971a 14289 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 14290 NULL_RTX, NULL_RTX);
9ebbca7d
GK
14291 }
14292
f676971a 14293 /* Update stack and set back pointer unless this is V.4,
9ebbca7d 14294 for which it was done previously. */
d62294f5 14295 if (! info->world_save_p && info->push_p
fc4767bb 14296 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
14297 rs6000_emit_allocate_stack (info->total_size, FALSE);
14298
14299 /* Set frame pointer, if needed. */
14300 if (frame_pointer_needed)
14301 {
f676971a 14302 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
14303 sp_reg_rtx);
14304 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 14305 }
9878760c 14306
1db02437 14307 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 14308 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 14309 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 14310 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
c4ad648e
AM
14311 {
14312 /* If emit_load_toc_table will use the link register, we need to save
14313 it. We use R12 for this purpose because emit_load_toc_table
14314 can use register 0. This allows us to use a plain 'blr' to return
14315 from the procedure more often. */
14316 int save_LR_around_toc_setup = (TARGET_ELF
14317 && DEFAULT_ABI != ABI_AIX
14318 && flag_pic
14319 && ! info->lr_save_p
14320 && EDGE_COUNT (EXIT_BLOCK_PTR->preds) > 0);
14321 if (save_LR_around_toc_setup)
14322 {
14323 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f8a57be8 14324
c4ad648e
AM
14325 insn = emit_move_insn (frame_ptr_rtx, lr);
14326 rs6000_maybe_dead (insn);
14327 RTX_FRAME_RELATED_P (insn) = 1;
f8a57be8 14328
c4ad648e 14329 rs6000_emit_load_toc_table (TRUE);
f8a57be8 14330
c4ad648e
AM
14331 insn = emit_move_insn (lr, frame_ptr_rtx);
14332 rs6000_maybe_dead (insn);
14333 RTX_FRAME_RELATED_P (insn) = 1;
14334 }
14335 else
14336 rs6000_emit_load_toc_table (TRUE);
14337 }
ee890fe2 14338
fcce224d 14339#if TARGET_MACHO
ee890fe2
SS
14340 if (DEFAULT_ABI == ABI_DARWIN
14341 && flag_pic && current_function_uses_pic_offset_table)
14342 {
f8a57be8 14343 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
11abc112 14344 rtx src = machopic_function_base_sym ();
ee890fe2 14345
f8a57be8 14346 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (lr, src)));
ee890fe2 14347
f676971a 14348 insn = emit_move_insn (gen_rtx_REG (Pmode,
f8a57be8
GK
14349 RS6000_PIC_OFFSET_TABLE_REGNUM),
14350 lr);
14351 rs6000_maybe_dead (insn);
ee890fe2 14352 }
fcce224d 14353#endif
9ebbca7d
GK
14354}
14355
9ebbca7d 14356/* Write function prologue. */
a4f6c312 14357
08c148a8 14358static void
f676971a 14359rs6000_output_function_prologue (FILE *file,
a2369ed3 14360 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
14361{
14362 rs6000_stack_t *info = rs6000_stack_info ();
14363
4697a36c
MM
14364 if (TARGET_DEBUG_STACK)
14365 debug_stack_info (info);
9878760c 14366
a4f6c312
SS
14367 /* Write .extern for any function we will call to save and restore
14368 fp values. */
14369 if (info->first_fp_reg_save < 64
14370 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 14371 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 14372 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
14373 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
14374 RESTORE_FP_SUFFIX);
9878760c 14375
c764f757
RK
14376 /* Write .extern for AIX common mode routines, if needed. */
14377 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
14378 {
f6709c70
JW
14379 fputs ("\t.extern __mulh\n", file);
14380 fputs ("\t.extern __mull\n", file);
14381 fputs ("\t.extern __divss\n", file);
14382 fputs ("\t.extern __divus\n", file);
14383 fputs ("\t.extern __quoss\n", file);
14384 fputs ("\t.extern __quous\n", file);
c764f757
RK
14385 common_mode_defined = 1;
14386 }
9878760c 14387
9ebbca7d 14388 if (! HAVE_prologue)
979721f8 14389 {
9ebbca7d 14390 start_sequence ();
9dda4cc8 14391
a4f6c312
SS
14392 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
14393 the "toplevel" insn chain. */
2e040219 14394 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14395 rs6000_emit_prologue ();
2e040219 14396 emit_note (NOTE_INSN_DELETED);
178c3eff 14397
a3c9585f 14398 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
14399 {
14400 rtx insn;
14401 unsigned addr = 0;
14402 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
14403 {
14404 INSN_ADDRESSES_NEW (insn, addr);
14405 addr += 4;
14406 }
14407 }
9dda4cc8 14408
9ebbca7d 14409 if (TARGET_DEBUG_STACK)
a4f6c312
SS
14410 debug_rtx_list (get_insns (), 100);
14411 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 14412 end_sequence ();
979721f8
MM
14413 }
14414
9ebbca7d
GK
14415 rs6000_pic_labelno++;
14416}
f676971a 14417
9ebbca7d 14418/* Emit function epilogue as insns.
9878760c 14419
9ebbca7d
GK
14420 At present, dwarf2out_frame_debug_expr doesn't understand
14421 register restores, so we don't bother setting RTX_FRAME_RELATED_P
14422 anywhere in the epilogue. Most of the insns below would in any case
14423 need special notes to explain where r11 is in relation to the stack. */
9878760c 14424
9ebbca7d 14425void
a2369ed3 14426rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
14427{
14428 rs6000_stack_t *info;
14429 int restoring_FPRs_inline;
14430 int using_load_multiple;
14431 int using_mfcr_multiple;
14432 int use_backchain_to_restore_sp;
14433 int sp_offset = 0;
14434 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
14435 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 14436 enum machine_mode reg_mode = Pmode;
327e5343 14437 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
14438 int i;
14439
c19de7aa
AH
14440 info = rs6000_stack_info ();
14441
14442 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
14443 {
14444 reg_mode = V2SImode;
14445 reg_size = 8;
14446 }
14447
9ebbca7d 14448 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
14449 && (!TARGET_SPE_ABI
14450 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
14451 && info->first_gp_reg_save < 31);
14452 restoring_FPRs_inline = (sibcall
83720594 14453 || current_function_calls_eh_return
9ebbca7d
GK
14454 || info->first_fp_reg_save == 64
14455 || FP_SAVE_INLINE (info->first_fp_reg_save));
f676971a 14456 use_backchain_to_restore_sp = (frame_pointer_needed
9ebbca7d
GK
14457 || current_function_calls_alloca
14458 || info->total_size > 32767);
14459 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
14460 || rs6000_cpu == PROCESSOR_PPC603
14461 || rs6000_cpu == PROCESSOR_PPC750
14462 || optimize_size);
14463
d62294f5
FJ
14464 if (info->world_save_p)
14465 {
14466 int i, j;
14467 char rname[30];
14468 const char *alloc_rname;
14469 rtvec p;
14470
14471 /* eh_rest_world_r10 will return to the location saved in the LR
c4ad648e
AM
14472 stack slot (which is not likely to be our caller.)
14473 Input: R10 -- stack adjustment. Clobbers R0, R11, R12, R7, R8.
14474 rest_world is similar, except any R10 parameter is ignored.
14475 The exception-handling stuff that was here in 2.95 is no
14476 longer necessary. */
d62294f5
FJ
14477
14478 p = rtvec_alloc (9
14479 + 1
f676971a 14480 + 32 - info->first_gp_reg_save
c4ad648e
AM
14481 + LAST_ALTIVEC_REGNO + 1 - info->first_altivec_reg_save
14482 + 63 + 1 - info->first_fp_reg_save);
d62294f5 14483
c4ad648e
AM
14484 strcpy (rname, ((current_function_calls_eh_return) ?
14485 "*eh_rest_world_r10" : "*rest_world"));
d62294f5
FJ
14486 alloc_rname = ggc_strdup (rname);
14487
14488 j = 0;
14489 RTVEC_ELT (p, j++) = gen_rtx_RETURN (VOIDmode);
14490 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
c4ad648e
AM
14491 gen_rtx_REG (Pmode,
14492 LINK_REGISTER_REGNUM));
d62294f5 14493 RTVEC_ELT (p, j++)
c4ad648e 14494 = gen_rtx_USE (VOIDmode, gen_rtx_SYMBOL_REF (Pmode, alloc_rname));
d62294f5 14495 /* The instruction pattern requires a clobber here;
c4ad648e 14496 it is shared with the restVEC helper. */
d62294f5 14497 RTVEC_ELT (p, j++)
c4ad648e 14498 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
d62294f5
FJ
14499
14500 {
c4ad648e
AM
14501 /* CR register traditionally saved as CR2. */
14502 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
14503 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14504 GEN_INT (info->cr_save_offset));
14505 rtx mem = gen_rtx_MEM (reg_mode, addr);
14506 set_mem_alias_set (mem, rs6000_sr_alias_set);
14507
14508 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
d62294f5
FJ
14509 }
14510
14511 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
c4ad648e
AM
14512 {
14513 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
14514 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14515 GEN_INT (info->gp_save_offset
14516 + reg_size * i));
14517 rtx mem = gen_rtx_MEM (reg_mode, addr);
14518 set_mem_alias_set (mem, rs6000_sr_alias_set);
14519
14520 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14521 }
d62294f5 14522 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
c4ad648e
AM
14523 {
14524 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
14525 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14526 GEN_INT (info->altivec_save_offset
14527 + 16 * i));
14528 rtx mem = gen_rtx_MEM (V4SImode, addr);
14529 set_mem_alias_set (mem, rs6000_sr_alias_set);
14530
14531 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14532 }
d62294f5 14533 for (i = 0; info->first_fp_reg_save + i <= 63; i++)
c4ad648e
AM
14534 {
14535 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
14536 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14537 GEN_INT (info->fp_save_offset
14538 + 8 * i));
14539 rtx mem = gen_rtx_MEM (DFmode, addr);
14540 set_mem_alias_set (mem, rs6000_sr_alias_set);
14541
14542 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
14543 }
d62294f5 14544 RTVEC_ELT (p, j++)
c4ad648e 14545 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 0));
d62294f5 14546 RTVEC_ELT (p, j++)
c4ad648e 14547 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 12));
d62294f5 14548 RTVEC_ELT (p, j++)
c4ad648e 14549 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 7));
d62294f5 14550 RTVEC_ELT (p, j++)
c4ad648e 14551 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 8));
d62294f5 14552 RTVEC_ELT (p, j++)
c4ad648e 14553 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 10));
d62294f5
FJ
14554 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
14555
14556 return;
14557 }
14558
9ebbca7d
GK
14559 /* If we have a frame pointer, a call to alloca, or a large stack
14560 frame, restore the old stack pointer using the backchain. Otherwise,
14561 we know what size to update it with. */
14562 if (use_backchain_to_restore_sp)
bacbde18 14563 {
9ebbca7d
GK
14564 /* Under V.4, don't reset the stack pointer until after we're done
14565 loading the saved registers. */
f607bc57 14566 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 14567 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 14568
9ebbca7d
GK
14569 emit_move_insn (frame_reg_rtx,
14570 gen_rtx_MEM (Pmode, sp_reg_rtx));
f676971a 14571
bacbde18 14572 }
9ebbca7d 14573 else if (info->push_p)
85638c0d 14574 {
fc4767bb
JJ
14575 if (DEFAULT_ABI == ABI_V4
14576 || current_function_calls_eh_return)
9ebbca7d
GK
14577 sp_offset = info->total_size;
14578 else
14579 {
14580 emit_insn (TARGET_32BIT
14581 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
14582 GEN_INT (info->total_size))
14583 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
14584 GEN_INT (info->total_size)));
14585 }
85638c0d 14586 }
f676971a 14587
9aa86737
AH
14588 /* Restore AltiVec registers if needed. */
14589 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
14590 {
14591 int i;
14592
14593 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
14594 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
14595 {
14596 rtx addr, areg, mem;
14597
14598 areg = gen_rtx_REG (Pmode, 0);
14599 emit_move_insn
14600 (areg, GEN_INT (info->altivec_save_offset
14601 + sp_offset
14602 + 16 * (i - info->first_altivec_reg_save)));
14603
14604 /* AltiVec addressing mode is [reg+reg]. */
14605 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
14606 mem = gen_rtx_MEM (V4SImode, addr);
14607 set_mem_alias_set (mem, rs6000_sr_alias_set);
14608
14609 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
14610 }
14611 }
14612
14613 /* Restore VRSAVE if needed. */
44688022 14614 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
4d774ff8 14615 && info->vrsave_mask != 0)
9aa86737
AH
14616 {
14617 rtx addr, mem, reg;
14618
14619 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14620 GEN_INT (info->vrsave_save_offset + sp_offset));
14621 mem = gen_rtx_MEM (SImode, addr);
14622 set_mem_alias_set (mem, rs6000_sr_alias_set);
14623 reg = gen_rtx_REG (SImode, 12);
14624 emit_move_insn (reg, mem);
14625
14626 emit_insn (generate_set_vrsave (reg, info, 1));
14627 }
14628
9ebbca7d
GK
14629 /* Get the old lr if we saved it. */
14630 if (info->lr_save_p)
b6c9286a 14631 {
a3170dc6
AH
14632 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
14633 info->lr_save_offset + sp_offset);
ba4828e0
RK
14634
14635 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 14636
9ebbca7d 14637 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 14638 }
f676971a 14639
9ebbca7d
GK
14640 /* Get the old cr if we saved it. */
14641 if (info->cr_save_p)
14642 {
14643 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14644 GEN_INT (info->cr_save_offset + sp_offset));
14645 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
14646
14647 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 14648
9ebbca7d
GK
14649 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
14650 }
f676971a 14651
9ebbca7d 14652 /* Set LR here to try to overlap restores below. */
4697a36c 14653 if (info->lr_save_p)
9ebbca7d
GK
14654 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
14655 gen_rtx_REG (Pmode, 0));
f676971a 14656
83720594
RH
14657 /* Load exception handler data registers, if needed. */
14658 if (current_function_calls_eh_return)
14659 {
78e1b90d
DE
14660 unsigned int i, regno;
14661
fc4767bb
JJ
14662 if (TARGET_AIX)
14663 {
14664 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14665 GEN_INT (sp_offset + 5 * reg_size));
14666 rtx mem = gen_rtx_MEM (reg_mode, addr);
14667
14668 set_mem_alias_set (mem, rs6000_sr_alias_set);
14669
14670 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
14671 }
14672
83720594
RH
14673 for (i = 0; ; ++i)
14674 {
a3170dc6 14675 rtx mem;
83720594
RH
14676
14677 regno = EH_RETURN_DATA_REGNO (i);
14678 if (regno == INVALID_REGNUM)
14679 break;
14680
a3170dc6
AH
14681 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
14682 info->ehrd_offset + sp_offset
14683 + reg_size * (int) i);
ba4828e0 14684 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
14685
14686 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
14687 }
14688 }
f676971a 14689
9ebbca7d
GK
14690 /* Restore GPRs. This is done as a PARALLEL if we are using
14691 the load-multiple instructions. */
14692 if (using_load_multiple)
979721f8 14693 {
9ebbca7d
GK
14694 rtvec p;
14695 p = rtvec_alloc (32 - info->first_gp_reg_save);
14696 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 14697 {
f676971a
EC
14698 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14699 GEN_INT (info->gp_save_offset
14700 + sp_offset
9ebbca7d
GK
14701 + reg_size * i));
14702 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
14703
14704 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14705
f676971a 14706 RTVEC_ELT (p, i) =
9ebbca7d
GK
14707 gen_rtx_SET (VOIDmode,
14708 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
14709 mem);
979721f8 14710 }
9ebbca7d 14711 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 14712 }
9ebbca7d
GK
14713 else
14714 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 14715 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
14716 && (! call_used_regs[info->first_gp_reg_save+i]
14717 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14718 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 14719 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 14720 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 14721 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d 14722 {
f676971a
EC
14723 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
14724 GEN_INT (info->gp_save_offset
14725 + sp_offset
9ebbca7d
GK
14726 + reg_size * i));
14727 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 14728
a3170dc6 14729 /* Restore 64-bit quantities for SPE. */
c19de7aa 14730 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
14731 {
14732 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
14733 rtx b;
14734
14735 if (!SPE_CONST_OFFSET_OK (offset))
14736 {
14737 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
14738 emit_move_insn (b, GEN_INT (offset));
14739 }
14740 else
14741 b = GEN_INT (offset);
14742
14743 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
14744 mem = gen_rtx_MEM (V2SImode, addr);
14745 }
14746
ba4828e0 14747 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14748
f676971a 14749 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 14750 info->first_gp_reg_save + i), mem);
9ebbca7d 14751 }
9878760c 14752
9ebbca7d
GK
14753 /* Restore fpr's if we need to do it without calling a function. */
14754 if (restoring_FPRs_inline)
14755 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 14756 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d
GK
14757 && ! call_used_regs[info->first_fp_reg_save+i]))
14758 {
14759 rtx addr, mem;
14760 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a
EC
14761 GEN_INT (info->fp_save_offset
14762 + sp_offset
a4f6c312 14763 + 8 * i));
9ebbca7d 14764 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14765 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14766
f676971a 14767 emit_move_insn (gen_rtx_REG (DFmode,
9ebbca7d
GK
14768 info->first_fp_reg_save + i),
14769 mem);
14770 }
8d30c4ee 14771
9ebbca7d
GK
14772 /* If we saved cr, restore it here. Just those that were used. */
14773 if (info->cr_save_p)
979721f8 14774 {
9ebbca7d 14775 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 14776 int count = 0;
f676971a 14777
9ebbca7d 14778 if (using_mfcr_multiple)
979721f8 14779 {
9ebbca7d
GK
14780 for (i = 0; i < 8; i++)
14781 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 14782 count++;
9ebbca7d 14783 if (count == 0)
e35b9579
GK
14784 abort ();
14785 }
14786
14787 if (using_mfcr_multiple && count > 1)
14788 {
14789 rtvec p;
14790 int ndx;
f676971a 14791
e35b9579 14792 p = rtvec_alloc (count);
9ebbca7d 14793
e35b9579 14794 ndx = 0;
9ebbca7d
GK
14795 for (i = 0; i < 8; i++)
14796 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
14797 {
14798 rtvec r = rtvec_alloc (2);
14799 RTVEC_ELT (r, 0) = r12_rtx;
14800 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 14801 RTVEC_ELT (p, ndx) =
f676971a 14802 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 14803 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 14804 ndx++;
9ebbca7d
GK
14805 }
14806 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
14807 if (ndx != count)
14808 abort ();
979721f8
MM
14809 }
14810 else
9ebbca7d
GK
14811 for (i = 0; i < 8; i++)
14812 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 14813 {
f676971a 14814 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
9ebbca7d
GK
14815 CR0_REGNO+i),
14816 r12_rtx));
979721f8 14817 }
979721f8
MM
14818 }
14819
9ebbca7d
GK
14820 /* If this is V.4, unwind the stack pointer after all of the loads
14821 have been done. We need to emit a block here so that sched
14822 doesn't decide to move the sp change before the register restores
14823 (which may not have any obvious dependency on the stack). This
14824 doesn't hurt performance, because there is no scheduling that can
14825 be done after this point. */
fc4767bb
JJ
14826 if (DEFAULT_ABI == ABI_V4
14827 || current_function_calls_eh_return)
b6c9286a 14828 {
9ebbca7d 14829 if (frame_reg_rtx != sp_reg_rtx)
c4ad648e 14830 rs6000_emit_stack_tie ();
b6c9286a 14831
9ebbca7d 14832 if (use_backchain_to_restore_sp)
b6c9286a 14833 {
9ebbca7d 14834 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 14835 }
9ebbca7d 14836 else if (sp_offset != 0)
13f1623b 14837 {
5b71a4e7 14838 emit_insn (TARGET_32BIT
9ebbca7d
GK
14839 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
14840 GEN_INT (sp_offset))
14841 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
14842 GEN_INT (sp_offset)));
13f1623b 14843 }
9ebbca7d 14844 }
b6c9286a 14845
83720594
RH
14846 if (current_function_calls_eh_return)
14847 {
14848 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 14849 emit_insn (TARGET_32BIT
83720594
RH
14850 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
14851 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
14852 }
14853
9ebbca7d
GK
14854 if (!sibcall)
14855 {
14856 rtvec p;
14857 if (! restoring_FPRs_inline)
14858 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
14859 else
14860 p = rtvec_alloc (2);
b6c9286a 14861
e35b9579 14862 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
f676971a
EC
14863 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
14864 gen_rtx_REG (Pmode,
9ebbca7d 14865 LINK_REGISTER_REGNUM));
9ebbca7d
GK
14866
14867 /* If we have to restore more than two FP registers, branch to the
14868 restore function. It will return to our caller. */
14869 if (! restoring_FPRs_inline)
14870 {
14871 int i;
14872 char rname[30];
520a57c8 14873 const char *alloc_rname;
979721f8 14874
f676971a 14875 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
9ebbca7d 14876 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 14877 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
14878 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
14879 gen_rtx_SYMBOL_REF (Pmode,
14880 alloc_rname));
b6c9286a 14881
9ebbca7d
GK
14882 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
14883 {
14884 rtx addr, mem;
14885 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
14886 GEN_INT (info->fp_save_offset + 8*i));
14887 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14888 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14889
f676971a 14890 RTVEC_ELT (p, i+3) =
9ebbca7d
GK
14891 gen_rtx_SET (VOIDmode,
14892 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
14893 mem);
b6c9286a
MM
14894 }
14895 }
f676971a 14896
9ebbca7d 14897 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 14898 }
9878760c
RK
14899}
14900
14901/* Write function epilogue. */
14902
08c148a8 14903static void
f676971a 14904rs6000_output_function_epilogue (FILE *file,
a2369ed3 14905 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 14906{
4697a36c 14907 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 14908
9ebbca7d 14909 if (! HAVE_epilogue)
9878760c 14910 {
9ebbca7d
GK
14911 rtx insn = get_last_insn ();
14912 /* If the last insn was a BARRIER, we don't have to write anything except
14913 the trace table. */
14914 if (GET_CODE (insn) == NOTE)
14915 insn = prev_nonnote_insn (insn);
14916 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 14917 {
9ebbca7d
GK
14918 /* This is slightly ugly, but at least we don't have two
14919 copies of the epilogue-emitting code. */
14920 start_sequence ();
14921
14922 /* A NOTE_INSN_DELETED is supposed to be at the start
14923 and end of the "toplevel" insn chain. */
2e040219 14924 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14925 rs6000_emit_epilogue (FALSE);
2e040219 14926 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14927
a3c9585f 14928 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
14929 {
14930 rtx insn;
14931 unsigned addr = 0;
14932 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
14933 {
14934 INSN_ADDRESSES_NEW (insn, addr);
14935 addr += 4;
14936 }
14937 }
14938
9ebbca7d 14939 if (TARGET_DEBUG_STACK)
a4f6c312
SS
14940 debug_rtx_list (get_insns (), 100);
14941 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 14942 end_sequence ();
4697a36c 14943 }
9878760c 14944 }
b4ac57ab 14945
efdba735
SH
14946#if TARGET_MACHO
14947 macho_branch_islands ();
0e5da0be
GK
14948 /* Mach-O doesn't support labels at the end of objects, so if
14949 it looks like we might want one, insert a NOP. */
14950 {
14951 rtx insn = get_last_insn ();
14952 while (insn
14953 && NOTE_P (insn)
14954 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
14955 insn = PREV_INSN (insn);
f676971a
EC
14956 if (insn
14957 && (LABEL_P (insn)
0e5da0be
GK
14958 || (NOTE_P (insn)
14959 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
14960 fputs ("\tnop\n", file);
14961 }
14962#endif
14963
9b30bae2 14964 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
14965 on its format.
14966
14967 We don't output a traceback table if -finhibit-size-directive was
14968 used. The documentation for -finhibit-size-directive reads
14969 ``don't output a @code{.size} assembler directive, or anything
14970 else that would cause trouble if the function is split in the
14971 middle, and the two halves are placed at locations far apart in
14972 memory.'' The traceback table has this property, since it
14973 includes the offset from the start of the function to the
4d30c363
MM
14974 traceback table itself.
14975
14976 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 14977 different traceback table. */
57ac7be9
AM
14978 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
14979 && rs6000_traceback != traceback_none)
9b30bae2 14980 {
69c75916 14981 const char *fname = NULL;
3ac88239 14982 const char *language_string = lang_hooks.name;
6041bf2f 14983 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 14984 int i;
57ac7be9
AM
14985 int optional_tbtab;
14986
14987 if (rs6000_traceback == traceback_full)
14988 optional_tbtab = 1;
14989 else if (rs6000_traceback == traceback_part)
14990 optional_tbtab = 0;
14991 else
14992 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 14993
69c75916
AM
14994 if (optional_tbtab)
14995 {
14996 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
14997 while (*fname == '.') /* V.4 encodes . in the name */
14998 fname++;
14999
15000 /* Need label immediately before tbtab, so we can compute
15001 its offset from the function start. */
15002 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
15003 ASM_OUTPUT_LABEL (file, fname);
15004 }
314fc5a9
ILT
15005
15006 /* The .tbtab pseudo-op can only be used for the first eight
15007 expressions, since it can't handle the possibly variable
15008 length fields that follow. However, if you omit the optional
15009 fields, the assembler outputs zeros for all optional fields
15010 anyways, giving each variable length field is minimum length
15011 (as defined in sys/debug.h). Thus we can not use the .tbtab
15012 pseudo-op at all. */
15013
15014 /* An all-zero word flags the start of the tbtab, for debuggers
15015 that have to find it by searching forward from the entry
15016 point or from the current pc. */
19d2d16f 15017 fputs ("\t.long 0\n", file);
314fc5a9
ILT
15018
15019 /* Tbtab format type. Use format type 0. */
19d2d16f 15020 fputs ("\t.byte 0,", file);
314fc5a9 15021
5fc921c1
DE
15022 /* Language type. Unfortunately, there does not seem to be any
15023 official way to discover the language being compiled, so we
15024 use language_string.
15025 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
15026 Java is 13. Objective-C is 14. */
15027 if (! strcmp (language_string, "GNU C"))
314fc5a9 15028 i = 0;
6de9cd9a
DN
15029 else if (! strcmp (language_string, "GNU F77")
15030 || ! strcmp (language_string, "GNU F95"))
314fc5a9 15031 i = 1;
8b83775b 15032 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 15033 i = 2;
5fc921c1
DE
15034 else if (! strcmp (language_string, "GNU Ada"))
15035 i = 3;
314fc5a9
ILT
15036 else if (! strcmp (language_string, "GNU C++"))
15037 i = 9;
9517ead8
AG
15038 else if (! strcmp (language_string, "GNU Java"))
15039 i = 13;
5fc921c1
DE
15040 else if (! strcmp (language_string, "GNU Objective-C"))
15041 i = 14;
314fc5a9
ILT
15042 else
15043 abort ();
15044 fprintf (file, "%d,", i);
15045
15046 /* 8 single bit fields: global linkage (not set for C extern linkage,
15047 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
15048 from start of procedure stored in tbtab, internal function, function
15049 has controlled storage, function has no toc, function uses fp,
15050 function logs/aborts fp operations. */
15051 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
15052 fprintf (file, "%d,",
15053 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
15054
15055 /* 6 bitfields: function is interrupt handler, name present in
15056 proc table, function calls alloca, on condition directives
15057 (controls stack walks, 3 bits), saves condition reg, saves
15058 link reg. */
15059 /* The `function calls alloca' bit seems to be set whenever reg 31 is
15060 set up as a frame pointer, even when there is no alloca call. */
15061 fprintf (file, "%d,",
6041bf2f
DE
15062 ((optional_tbtab << 6)
15063 | ((optional_tbtab & frame_pointer_needed) << 5)
15064 | (info->cr_save_p << 1)
15065 | (info->lr_save_p)));
314fc5a9 15066
6041bf2f 15067 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
15068 (6 bits). */
15069 fprintf (file, "%d,",
4697a36c 15070 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
15071
15072 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
15073 fprintf (file, "%d,", (32 - first_reg_to_save ()));
15074
6041bf2f
DE
15075 if (optional_tbtab)
15076 {
15077 /* Compute the parameter info from the function decl argument
15078 list. */
15079 tree decl;
15080 int next_parm_info_bit = 31;
314fc5a9 15081
6041bf2f
DE
15082 for (decl = DECL_ARGUMENTS (current_function_decl);
15083 decl; decl = TREE_CHAIN (decl))
15084 {
15085 rtx parameter = DECL_INCOMING_RTL (decl);
15086 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 15087
6041bf2f
DE
15088 if (GET_CODE (parameter) == REG)
15089 {
15090 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
15091 {
15092 int bits;
15093
15094 float_parms++;
15095
15096 if (mode == SFmode)
15097 bits = 0x2;
fcce224d 15098 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
15099 bits = 0x3;
15100 else
15101 abort ();
15102
15103 /* If only one bit will fit, don't or in this entry. */
15104 if (next_parm_info_bit > 0)
15105 parm_info |= (bits << (next_parm_info_bit - 1));
15106 next_parm_info_bit -= 2;
15107 }
15108 else
15109 {
15110 fixed_parms += ((GET_MODE_SIZE (mode)
15111 + (UNITS_PER_WORD - 1))
15112 / UNITS_PER_WORD);
15113 next_parm_info_bit -= 1;
15114 }
15115 }
15116 }
15117 }
314fc5a9
ILT
15118
15119 /* Number of fixed point parameters. */
15120 /* This is actually the number of words of fixed point parameters; thus
15121 an 8 byte struct counts as 2; and thus the maximum value is 8. */
15122 fprintf (file, "%d,", fixed_parms);
15123
15124 /* 2 bitfields: number of floating point parameters (7 bits), parameters
15125 all on stack. */
15126 /* This is actually the number of fp registers that hold parameters;
15127 and thus the maximum value is 13. */
15128 /* Set parameters on stack bit if parameters are not in their original
15129 registers, regardless of whether they are on the stack? Xlc
15130 seems to set the bit when not optimizing. */
15131 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
15132
6041bf2f
DE
15133 if (! optional_tbtab)
15134 return;
15135
314fc5a9
ILT
15136 /* Optional fields follow. Some are variable length. */
15137
15138 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
15139 11 double float. */
15140 /* There is an entry for each parameter in a register, in the order that
15141 they occur in the parameter list. Any intervening arguments on the
15142 stack are ignored. If the list overflows a long (max possible length
15143 34 bits) then completely leave off all elements that don't fit. */
15144 /* Only emit this long if there was at least one parameter. */
15145 if (fixed_parms || float_parms)
15146 fprintf (file, "\t.long %d\n", parm_info);
15147
15148 /* Offset from start of code to tb table. */
19d2d16f 15149 fputs ("\t.long ", file);
314fc5a9 15150 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
85b776df
AM
15151 if (TARGET_AIX)
15152 RS6000_OUTPUT_BASENAME (file, fname);
15153 else
15154 assemble_name (file, fname);
15155 putc ('-', file);
15156 rs6000_output_function_entry (file, fname);
19d2d16f 15157 putc ('\n', file);
314fc5a9
ILT
15158
15159 /* Interrupt handler mask. */
15160 /* Omit this long, since we never set the interrupt handler bit
15161 above. */
15162
15163 /* Number of CTL (controlled storage) anchors. */
15164 /* Omit this long, since the has_ctl bit is never set above. */
15165
15166 /* Displacement into stack of each CTL anchor. */
15167 /* Omit this list of longs, because there are no CTL anchors. */
15168
15169 /* Length of function name. */
69c75916
AM
15170 if (*fname == '*')
15171 ++fname;
296b8152 15172 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
15173
15174 /* Function name. */
15175 assemble_string (fname, strlen (fname));
15176
15177 /* Register for alloca automatic storage; this is always reg 31.
15178 Only emit this if the alloca bit was set above. */
15179 if (frame_pointer_needed)
19d2d16f 15180 fputs ("\t.byte 31\n", file);
b1765bde
DE
15181
15182 fputs ("\t.align 2\n", file);
9b30bae2 15183 }
9878760c 15184}
17167fd8 15185\f
a4f6c312
SS
15186/* A C compound statement that outputs the assembler code for a thunk
15187 function, used to implement C++ virtual function calls with
15188 multiple inheritance. The thunk acts as a wrapper around a virtual
15189 function, adjusting the implicit object parameter before handing
15190 control off to the real function.
15191
15192 First, emit code to add the integer DELTA to the location that
15193 contains the incoming first argument. Assume that this argument
15194 contains a pointer, and is the one used to pass the `this' pointer
15195 in C++. This is the incoming argument *before* the function
15196 prologue, e.g. `%o0' on a sparc. The addition must preserve the
15197 values of all other incoming arguments.
17167fd8
MM
15198
15199 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
15200 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
15201 not touch the return address. Hence returning from FUNCTION will
15202 return to whoever called the current `thunk'.
17167fd8 15203
a4f6c312
SS
15204 The effect must be as if FUNCTION had been called directly with the
15205 adjusted first argument. This macro is responsible for emitting
15206 all of the code for a thunk function; output_function_prologue()
15207 and output_function_epilogue() are not invoked.
17167fd8 15208
a4f6c312
SS
15209 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
15210 been extracted from it.) It might possibly be useful on some
15211 targets, but probably not.
17167fd8 15212
a4f6c312
SS
15213 If you do not define this macro, the target-independent code in the
15214 C++ frontend will generate a less efficient heavyweight thunk that
15215 calls FUNCTION instead of jumping to it. The generic approach does
15216 not support varargs. */
17167fd8 15217
3961e8fe 15218static void
f676971a
EC
15219rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
15220 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
a2369ed3 15221 tree function)
17167fd8 15222{
5b71a4e7 15223 rtx this, insn, funexp;
17167fd8 15224
5b71a4e7 15225 reload_completed = 1;
fe3ad572 15226 epilogue_completed = 1;
5b71a4e7 15227 no_new_pseudos = 1;
6429e3be 15228 reset_block_changes ();
56a7189a 15229
5b71a4e7 15230 /* Mark the end of the (empty) prologue. */
2e040219 15231 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 15232
5b71a4e7
DE
15233 /* Find the "this" pointer. If the function returns a structure,
15234 the structure return pointer is in r3. */
61f71b34 15235 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 15236 this = gen_rtx_REG (Pmode, 4);
56a7189a 15237 else
5b71a4e7 15238 this = gen_rtx_REG (Pmode, 3);
17167fd8 15239
5b71a4e7
DE
15240 /* Apply the constant offset, if required. */
15241 if (delta)
15242 {
15243 rtx delta_rtx = GEN_INT (delta);
15244 emit_insn (TARGET_32BIT
15245 ? gen_addsi3 (this, this, delta_rtx)
15246 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
15247 }
15248
5b71a4e7
DE
15249 /* Apply the offset from the vtable, if required. */
15250 if (vcall_offset)
17167fd8 15251 {
5b71a4e7
DE
15252 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
15253 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 15254
5b71a4e7 15255 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
15256 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
15257 {
15258 emit_insn (TARGET_32BIT
15259 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
15260 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
15261 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
15262 }
15263 else
15264 {
15265 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
15266
15267 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
15268 }
5b71a4e7
DE
15269 emit_insn (TARGET_32BIT
15270 ? gen_addsi3 (this, this, tmp)
15271 : gen_adddi3 (this, this, tmp));
17167fd8
MM
15272 }
15273
5b71a4e7
DE
15274 /* Generate a tail call to the target function. */
15275 if (!TREE_USED (function))
15276 {
15277 assemble_external (function);
15278 TREE_USED (function) = 1;
15279 }
15280 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 15281 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
15282
15283#if TARGET_MACHO
ab82a49f 15284 if (MACHOPIC_INDIRECT)
5b71a4e7 15285 funexp = machopic_indirect_call_target (funexp);
ee890fe2 15286#endif
5b71a4e7
DE
15287
15288 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
15289 generate sibcall RTL explicitly to avoid constraint abort. */
15290 insn = emit_call_insn (
15291 gen_rtx_PARALLEL (VOIDmode,
15292 gen_rtvec (4,
15293 gen_rtx_CALL (VOIDmode,
15294 funexp, const0_rtx),
15295 gen_rtx_USE (VOIDmode, const0_rtx),
15296 gen_rtx_USE (VOIDmode,
15297 gen_rtx_REG (SImode,
15298 LINK_REGISTER_REGNUM)),
15299 gen_rtx_RETURN (VOIDmode))));
15300 SIBLING_CALL_P (insn) = 1;
15301 emit_barrier ();
15302
15303 /* Run just enough of rest_of_compilation to get the insns emitted.
15304 There's not really enough bulk here to make other passes such as
15305 instruction scheduling worth while. Note that use_thunk calls
15306 assemble_start_function and assemble_end_function. */
15307 insn = get_insns ();
a2855205 15308 insn_locators_initialize ();
5b71a4e7
DE
15309 shorten_branches (insn);
15310 final_start_function (insn, file, 1);
15311 final (insn, file, 1, 0);
15312 final_end_function ();
15313
15314 reload_completed = 0;
fe3ad572 15315 epilogue_completed = 0;
5b71a4e7 15316 no_new_pseudos = 0;
9ebbca7d 15317}
9ebbca7d
GK
15318\f
15319/* A quick summary of the various types of 'constant-pool tables'
15320 under PowerPC:
15321
f676971a 15322 Target Flags Name One table per
9ebbca7d
GK
15323 AIX (none) AIX TOC object file
15324 AIX -mfull-toc AIX TOC object file
15325 AIX -mminimal-toc AIX minimal TOC translation unit
15326 SVR4/EABI (none) SVR4 SDATA object file
15327 SVR4/EABI -fpic SVR4 pic object file
15328 SVR4/EABI -fPIC SVR4 PIC translation unit
15329 SVR4/EABI -mrelocatable EABI TOC function
15330 SVR4/EABI -maix AIX TOC object file
f676971a 15331 SVR4/EABI -maix -mminimal-toc
9ebbca7d
GK
15332 AIX minimal TOC translation unit
15333
15334 Name Reg. Set by entries contains:
15335 made by addrs? fp? sum?
15336
15337 AIX TOC 2 crt0 as Y option option
15338 AIX minimal TOC 30 prolog gcc Y Y option
15339 SVR4 SDATA 13 crt0 gcc N Y N
15340 SVR4 pic 30 prolog ld Y not yet N
15341 SVR4 PIC 30 prolog gcc Y option option
15342 EABI TOC 30 prolog gcc Y option option
15343
15344*/
15345
9ebbca7d
GK
15346/* Hash functions for the hash table. */
15347
15348static unsigned
a2369ed3 15349rs6000_hash_constant (rtx k)
9ebbca7d 15350{
46b33600
RH
15351 enum rtx_code code = GET_CODE (k);
15352 enum machine_mode mode = GET_MODE (k);
15353 unsigned result = (code << 3) ^ mode;
15354 const char *format;
15355 int flen, fidx;
f676971a 15356
46b33600
RH
15357 format = GET_RTX_FORMAT (code);
15358 flen = strlen (format);
15359 fidx = 0;
9ebbca7d 15360
46b33600
RH
15361 switch (code)
15362 {
15363 case LABEL_REF:
15364 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
15365
15366 case CONST_DOUBLE:
15367 if (mode != VOIDmode)
15368 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
15369 flen = 2;
15370 break;
15371
15372 case CODE_LABEL:
15373 fidx = 3;
15374 break;
15375
15376 default:
15377 break;
15378 }
9ebbca7d
GK
15379
15380 for (; fidx < flen; fidx++)
15381 switch (format[fidx])
15382 {
15383 case 's':
15384 {
15385 unsigned i, len;
15386 const char *str = XSTR (k, fidx);
15387 len = strlen (str);
15388 result = result * 613 + len;
15389 for (i = 0; i < len; i++)
15390 result = result * 613 + (unsigned) str[i];
17167fd8
MM
15391 break;
15392 }
9ebbca7d
GK
15393 case 'u':
15394 case 'e':
15395 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
15396 break;
15397 case 'i':
15398 case 'n':
15399 result = result * 613 + (unsigned) XINT (k, fidx);
15400 break;
15401 case 'w':
15402 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
15403 result = result * 613 + (unsigned) XWINT (k, fidx);
15404 else
15405 {
15406 size_t i;
15407 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
15408 result = result * 613 + (unsigned) (XWINT (k, fidx)
15409 >> CHAR_BIT * i);
15410 }
15411 break;
09501938
DE
15412 case '0':
15413 break;
9ebbca7d 15414 default:
a4f6c312 15415 abort ();
9ebbca7d 15416 }
46b33600 15417
9ebbca7d
GK
15418 return result;
15419}
15420
15421static unsigned
a2369ed3 15422toc_hash_function (const void *hash_entry)
9ebbca7d 15423{
f676971a 15424 const struct toc_hash_struct *thc =
a9098fd0
GK
15425 (const struct toc_hash_struct *) hash_entry;
15426 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
15427}
15428
15429/* Compare H1 and H2 for equivalence. */
15430
15431static int
a2369ed3 15432toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
15433{
15434 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
15435 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
15436
a9098fd0
GK
15437 if (((const struct toc_hash_struct *) h1)->key_mode
15438 != ((const struct toc_hash_struct *) h2)->key_mode)
15439 return 0;
15440
5692c7bc 15441 return rtx_equal_p (r1, r2);
9ebbca7d
GK
15442}
15443
28e510bd
MM
15444/* These are the names given by the C++ front-end to vtables, and
15445 vtable-like objects. Ideally, this logic should not be here;
15446 instead, there should be some programmatic way of inquiring as
15447 to whether or not an object is a vtable. */
15448
15449#define VTABLE_NAME_P(NAME) \
15450 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
15451 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
15452 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 15453 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
f676971a 15454 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
28e510bd
MM
15455
15456void
a2369ed3 15457rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
15458{
15459 /* Currently C++ toc references to vtables can be emitted before it
15460 is decided whether the vtable is public or private. If this is
15461 the case, then the linker will eventually complain that there is
f676971a 15462 a reference to an unknown section. Thus, for vtables only,
28e510bd
MM
15463 we emit the TOC reference to reference the symbol and not the
15464 section. */
15465 const char *name = XSTR (x, 0);
54ee9799 15466
f676971a 15467 if (VTABLE_NAME_P (name))
54ee9799
DE
15468 {
15469 RS6000_OUTPUT_BASENAME (file, name);
15470 }
15471 else
15472 assemble_name (file, name);
28e510bd
MM
15473}
15474
a4f6c312
SS
15475/* Output a TOC entry. We derive the entry name from what is being
15476 written. */
9878760c
RK
15477
15478void
a2369ed3 15479output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
15480{
15481 char buf[256];
3cce094d 15482 const char *name = buf;
ec940faa 15483 const char *real_name;
9878760c
RK
15484 rtx base = x;
15485 int offset = 0;
15486
4697a36c
MM
15487 if (TARGET_NO_TOC)
15488 abort ();
15489
9ebbca7d
GK
15490 /* When the linker won't eliminate them, don't output duplicate
15491 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
15492 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
15493 CODE_LABELs. */
15494 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
15495 {
15496 struct toc_hash_struct *h;
15497 void * * found;
f676971a 15498
17211ab5 15499 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
c4ad648e 15500 time because GGC is not initialized at that point. */
17211ab5 15501 if (toc_hash_table == NULL)
f676971a 15502 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
17211ab5
GK
15503 toc_hash_eq, NULL);
15504
9ebbca7d
GK
15505 h = ggc_alloc (sizeof (*h));
15506 h->key = x;
a9098fd0 15507 h->key_mode = mode;
9ebbca7d 15508 h->labelno = labelno;
f676971a 15509
9ebbca7d
GK
15510 found = htab_find_slot (toc_hash_table, h, 1);
15511 if (*found == NULL)
15512 *found = h;
f676971a 15513 else /* This is indeed a duplicate.
9ebbca7d
GK
15514 Set this label equal to that label. */
15515 {
15516 fputs ("\t.set ", file);
15517 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
15518 fprintf (file, "%d,", labelno);
15519 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
f676971a 15520 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
9ebbca7d
GK
15521 found)->labelno));
15522 return;
15523 }
15524 }
15525
15526 /* If we're going to put a double constant in the TOC, make sure it's
15527 aligned properly when strict alignment is on. */
ff1720ed
RK
15528 if (GET_CODE (x) == CONST_DOUBLE
15529 && STRICT_ALIGNMENT
a9098fd0 15530 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
15531 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
15532 ASM_OUTPUT_ALIGN (file, 3);
15533 }
15534
4977bab6 15535 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 15536
37c37a57
RK
15537 /* Handle FP constants specially. Note that if we have a minimal
15538 TOC, things we put here aren't actually in the TOC, so we can allow
15539 FP constants. */
fcce224d
DE
15540 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
15541 {
15542 REAL_VALUE_TYPE rv;
15543 long k[4];
15544
15545 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15546 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
15547
15548 if (TARGET_64BIT)
15549 {
15550 if (TARGET_MINIMAL_TOC)
15551 fputs (DOUBLE_INT_ASM_OP, file);
15552 else
15553 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
15554 k[0] & 0xffffffff, k[1] & 0xffffffff,
15555 k[2] & 0xffffffff, k[3] & 0xffffffff);
15556 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
15557 k[0] & 0xffffffff, k[1] & 0xffffffff,
15558 k[2] & 0xffffffff, k[3] & 0xffffffff);
15559 return;
15560 }
15561 else
15562 {
15563 if (TARGET_MINIMAL_TOC)
15564 fputs ("\t.long ", file);
15565 else
15566 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
15567 k[0] & 0xffffffff, k[1] & 0xffffffff,
15568 k[2] & 0xffffffff, k[3] & 0xffffffff);
15569 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
15570 k[0] & 0xffffffff, k[1] & 0xffffffff,
15571 k[2] & 0xffffffff, k[3] & 0xffffffff);
15572 return;
15573 }
15574 }
15575 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 15576 {
042259f2
DE
15577 REAL_VALUE_TYPE rv;
15578 long k[2];
0adc764e 15579
042259f2
DE
15580 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15581 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 15582
13ded975
DE
15583 if (TARGET_64BIT)
15584 {
15585 if (TARGET_MINIMAL_TOC)
2bfcf297 15586 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 15587 else
2f0552b6
AM
15588 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
15589 k[0] & 0xffffffff, k[1] & 0xffffffff);
15590 fprintf (file, "0x%lx%08lx\n",
15591 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
15592 return;
15593 }
1875cc88 15594 else
13ded975
DE
15595 {
15596 if (TARGET_MINIMAL_TOC)
2bfcf297 15597 fputs ("\t.long ", file);
13ded975 15598 else
2f0552b6
AM
15599 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
15600 k[0] & 0xffffffff, k[1] & 0xffffffff);
15601 fprintf (file, "0x%lx,0x%lx\n",
15602 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
15603 return;
15604 }
9878760c 15605 }
a9098fd0 15606 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 15607 {
042259f2
DE
15608 REAL_VALUE_TYPE rv;
15609 long l;
9878760c 15610
042259f2
DE
15611 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
15612 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
15613
31bfaa0b
DE
15614 if (TARGET_64BIT)
15615 {
15616 if (TARGET_MINIMAL_TOC)
2bfcf297 15617 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 15618 else
2f0552b6
AM
15619 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
15620 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
15621 return;
15622 }
042259f2 15623 else
31bfaa0b
DE
15624 {
15625 if (TARGET_MINIMAL_TOC)
2bfcf297 15626 fputs ("\t.long ", file);
31bfaa0b 15627 else
2f0552b6
AM
15628 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
15629 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
15630 return;
15631 }
042259f2 15632 }
f176e826 15633 else if (GET_MODE (x) == VOIDmode
a9098fd0 15634 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 15635 {
e2c953b6 15636 unsigned HOST_WIDE_INT low;
042259f2
DE
15637 HOST_WIDE_INT high;
15638
15639 if (GET_CODE (x) == CONST_DOUBLE)
15640 {
15641 low = CONST_DOUBLE_LOW (x);
15642 high = CONST_DOUBLE_HIGH (x);
15643 }
15644 else
15645#if HOST_BITS_PER_WIDE_INT == 32
15646 {
15647 low = INTVAL (x);
0858c623 15648 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
15649 }
15650#else
15651 {
c4ad648e
AM
15652 low = INTVAL (x) & 0xffffffff;
15653 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
042259f2
DE
15654 }
15655#endif
9878760c 15656
a9098fd0
GK
15657 /* TOC entries are always Pmode-sized, but since this
15658 is a bigendian machine then if we're putting smaller
15659 integer constants in the TOC we have to pad them.
15660 (This is still a win over putting the constants in
15661 a separate constant pool, because then we'd have
02a4ec28
FS
15662 to have both a TOC entry _and_ the actual constant.)
15663
15664 For a 32-bit target, CONST_INT values are loaded and shifted
15665 entirely within `low' and can be stored in one TOC entry. */
15666
15667 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 15668 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
15669
15670 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
15671 {
15672#if HOST_BITS_PER_WIDE_INT == 32
15673 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
15674 POINTER_SIZE, &low, &high, 0);
15675#else
15676 low |= high << 32;
15677 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
15678 high = (HOST_WIDE_INT) low >> 32;
15679 low &= 0xffffffff;
15680#endif
15681 }
a9098fd0 15682
13ded975
DE
15683 if (TARGET_64BIT)
15684 {
15685 if (TARGET_MINIMAL_TOC)
2bfcf297 15686 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 15687 else
2f0552b6
AM
15688 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
15689 (long) high & 0xffffffff, (long) low & 0xffffffff);
15690 fprintf (file, "0x%lx%08lx\n",
15691 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
15692 return;
15693 }
1875cc88 15694 else
13ded975 15695 {
02a4ec28
FS
15696 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
15697 {
15698 if (TARGET_MINIMAL_TOC)
2bfcf297 15699 fputs ("\t.long ", file);
02a4ec28 15700 else
2bfcf297 15701 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
15702 (long) high & 0xffffffff, (long) low & 0xffffffff);
15703 fprintf (file, "0x%lx,0x%lx\n",
15704 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 15705 }
13ded975 15706 else
02a4ec28
FS
15707 {
15708 if (TARGET_MINIMAL_TOC)
2bfcf297 15709 fputs ("\t.long ", file);
02a4ec28 15710 else
2f0552b6
AM
15711 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
15712 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 15713 }
13ded975
DE
15714 return;
15715 }
9878760c
RK
15716 }
15717
15718 if (GET_CODE (x) == CONST)
15719 {
2bfcf297
DB
15720 if (GET_CODE (XEXP (x, 0)) != PLUS)
15721 abort ();
15722
9878760c
RK
15723 base = XEXP (XEXP (x, 0), 0);
15724 offset = INTVAL (XEXP (XEXP (x, 0), 1));
15725 }
f676971a 15726
9878760c
RK
15727 if (GET_CODE (base) == SYMBOL_REF)
15728 name = XSTR (base, 0);
15729 else if (GET_CODE (base) == LABEL_REF)
15730 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
15731 else if (GET_CODE (base) == CODE_LABEL)
15732 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
15733 else
15734 abort ();
15735
772c5265 15736 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 15737 if (TARGET_MINIMAL_TOC)
2bfcf297 15738 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
15739 else
15740 {
b6c9286a 15741 fprintf (file, "\t.tc %s", real_name);
9878760c 15742
1875cc88
JW
15743 if (offset < 0)
15744 fprintf (file, ".N%d", - offset);
15745 else if (offset)
15746 fprintf (file, ".P%d", offset);
9878760c 15747
19d2d16f 15748 fputs ("[TC],", file);
1875cc88 15749 }
581bc4de
MM
15750
15751 /* Currently C++ toc references to vtables can be emitted before it
15752 is decided whether the vtable is public or private. If this is
15753 the case, then the linker will eventually complain that there is
15754 a TOC reference to an unknown section. Thus, for vtables only,
15755 we emit the TOC reference to reference the symbol and not the
15756 section. */
28e510bd 15757 if (VTABLE_NAME_P (name))
581bc4de 15758 {
54ee9799 15759 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
15760 if (offset < 0)
15761 fprintf (file, "%d", offset);
15762 else if (offset > 0)
15763 fprintf (file, "+%d", offset);
15764 }
15765 else
15766 output_addr_const (file, x);
19d2d16f 15767 putc ('\n', file);
9878760c
RK
15768}
15769\f
15770/* Output an assembler pseudo-op to write an ASCII string of N characters
15771 starting at P to FILE.
15772
15773 On the RS/6000, we have to do this using the .byte operation and
15774 write out special characters outside the quoted string.
15775 Also, the assembler is broken; very long strings are truncated,
a4f6c312 15776 so we must artificially break them up early. */
9878760c
RK
15777
15778void
a2369ed3 15779output_ascii (FILE *file, const char *p, int n)
9878760c
RK
15780{
15781 char c;
15782 int i, count_string;
d330fd93
KG
15783 const char *for_string = "\t.byte \"";
15784 const char *for_decimal = "\t.byte ";
15785 const char *to_close = NULL;
9878760c
RK
15786
15787 count_string = 0;
15788 for (i = 0; i < n; i++)
15789 {
15790 c = *p++;
15791 if (c >= ' ' && c < 0177)
15792 {
15793 if (for_string)
15794 fputs (for_string, file);
15795 putc (c, file);
15796
15797 /* Write two quotes to get one. */
15798 if (c == '"')
15799 {
15800 putc (c, file);
15801 ++count_string;
15802 }
15803
15804 for_string = NULL;
15805 for_decimal = "\"\n\t.byte ";
15806 to_close = "\"\n";
15807 ++count_string;
15808
15809 if (count_string >= 512)
15810 {
15811 fputs (to_close, file);
15812
15813 for_string = "\t.byte \"";
15814 for_decimal = "\t.byte ";
15815 to_close = NULL;
15816 count_string = 0;
15817 }
15818 }
15819 else
15820 {
15821 if (for_decimal)
15822 fputs (for_decimal, file);
15823 fprintf (file, "%d", c);
15824
15825 for_string = "\n\t.byte \"";
15826 for_decimal = ", ";
15827 to_close = "\n";
15828 count_string = 0;
15829 }
15830 }
15831
15832 /* Now close the string if we have written one. Then end the line. */
15833 if (to_close)
9ebbca7d 15834 fputs (to_close, file);
9878760c
RK
15835}
15836\f
15837/* Generate a unique section name for FILENAME for a section type
15838 represented by SECTION_DESC. Output goes into BUF.
15839
15840 SECTION_DESC can be any string, as long as it is different for each
15841 possible section type.
15842
15843 We name the section in the same manner as xlc. The name begins with an
15844 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
15845 names) with the last period replaced by the string SECTION_DESC. If
15846 FILENAME does not contain a period, SECTION_DESC is appended to the end of
15847 the name. */
9878760c
RK
15848
15849void
f676971a 15850rs6000_gen_section_name (char **buf, const char *filename,
c4ad648e 15851 const char *section_desc)
9878760c 15852{
9ebbca7d 15853 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
15854 char *p;
15855 int len;
9878760c
RK
15856
15857 after_last_slash = filename;
15858 for (q = filename; *q; q++)
11e5fe42
RK
15859 {
15860 if (*q == '/')
15861 after_last_slash = q + 1;
15862 else if (*q == '.')
15863 last_period = q;
15864 }
9878760c 15865
11e5fe42 15866 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 15867 *buf = (char *) xmalloc (len);
9878760c
RK
15868
15869 p = *buf;
15870 *p++ = '_';
15871
15872 for (q = after_last_slash; *q; q++)
15873 {
11e5fe42 15874 if (q == last_period)
c4ad648e 15875 {
9878760c
RK
15876 strcpy (p, section_desc);
15877 p += strlen (section_desc);
e3981aab 15878 break;
c4ad648e 15879 }
9878760c 15880
e9a780ec 15881 else if (ISALNUM (*q))
c4ad648e 15882 *p++ = *q;
9878760c
RK
15883 }
15884
11e5fe42 15885 if (last_period == 0)
9878760c
RK
15886 strcpy (p, section_desc);
15887 else
15888 *p = '\0';
15889}
e165f3f0 15890\f
a4f6c312 15891/* Emit profile function. */
411707f4 15892
411707f4 15893void
a2369ed3 15894output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 15895{
ffcfcb5f
AM
15896 if (TARGET_PROFILE_KERNEL)
15897 return;
15898
8480e480
CC
15899 if (DEFAULT_ABI == ABI_AIX)
15900 {
9739c90c
JJ
15901#ifndef NO_PROFILE_COUNTERS
15902# define NO_PROFILE_COUNTERS 0
15903#endif
f676971a 15904 if (NO_PROFILE_COUNTERS)
9739c90c
JJ
15905 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
15906 else
15907 {
15908 char buf[30];
15909 const char *label_name;
15910 rtx fun;
411707f4 15911
9739c90c
JJ
15912 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
15913 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
15914 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 15915
9739c90c
JJ
15916 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
15917 fun, Pmode);
15918 }
8480e480 15919 }
ee890fe2
SS
15920 else if (DEFAULT_ABI == ABI_DARWIN)
15921 {
d5fa86ba 15922 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
15923 int caller_addr_regno = LINK_REGISTER_REGNUM;
15924
15925 /* Be conservative and always set this, at least for now. */
15926 current_function_uses_pic_offset_table = 1;
15927
15928#if TARGET_MACHO
15929 /* For PIC code, set up a stub and collect the caller's address
15930 from r0, which is where the prologue puts it. */
11abc112
MM
15931 if (MACHOPIC_INDIRECT
15932 && current_function_uses_pic_offset_table)
15933 caller_addr_regno = 0;
ee890fe2
SS
15934#endif
15935 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
15936 0, VOIDmode, 1,
15937 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
15938 }
411707f4
CC
15939}
15940
a4f6c312 15941/* Write function profiler code. */
e165f3f0
RK
15942
15943void
a2369ed3 15944output_function_profiler (FILE *file, int labelno)
e165f3f0 15945{
3daf36a4 15946 char buf[100];
09eeeacb 15947 int save_lr = 8;
e165f3f0 15948
38c1f2d7 15949 switch (DEFAULT_ABI)
3daf36a4 15950 {
38c1f2d7
MM
15951 default:
15952 abort ();
15953
15954 case ABI_V4:
09eeeacb 15955 save_lr = 4;
09eeeacb
AM
15956 if (!TARGET_32BIT)
15957 {
15958 warning ("no profiling of 64-bit code for this ABI");
15959 return;
15960 }
ffcfcb5f 15961 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
15962 fprintf (file, "\tmflr %s\n", reg_names[0]);
15963 if (flag_pic == 1)
15964 {
dfdfa60f 15965 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
15966 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15967 reg_names[0], save_lr, reg_names[1]);
17167fd8 15968 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 15969 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 15970 assemble_name (file, buf);
17167fd8 15971 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 15972 }
9ebbca7d 15973 else if (flag_pic > 1)
38c1f2d7 15974 {
09eeeacb
AM
15975 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15976 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
15977 /* Now, we need to get the address of the label. */
15978 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 15979 assemble_name (file, buf);
9ebbca7d
GK
15980 fputs ("-.\n1:", file);
15981 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
f676971a 15982 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
9ebbca7d
GK
15983 reg_names[0], reg_names[11]);
15984 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
15985 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 15986 }
38c1f2d7
MM
15987 else
15988 {
17167fd8 15989 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 15990 assemble_name (file, buf);
dfdfa60f 15991 fputs ("@ha\n", file);
09eeeacb
AM
15992 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15993 reg_names[0], save_lr, reg_names[1]);
a260abc9 15994 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 15995 assemble_name (file, buf);
17167fd8 15996 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
15997 }
15998
50d440bc 15999 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
16000 fprintf (file, "\tbl %s%s\n",
16001 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
16002 break;
16003
16004 case ABI_AIX:
ee890fe2 16005 case ABI_DARWIN:
ffcfcb5f
AM
16006 if (!TARGET_PROFILE_KERNEL)
16007 {
a3c9585f 16008 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
16009 }
16010 else
16011 {
16012 if (TARGET_32BIT)
16013 abort ();
16014
16015 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
16016 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
16017
6de9cd9a 16018 if (cfun->static_chain_decl != NULL)
ffcfcb5f
AM
16019 {
16020 asm_fprintf (file, "\tstd %s,24(%s)\n",
16021 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
16022 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
16023 asm_fprintf (file, "\tld %s,24(%s)\n",
16024 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
16025 }
16026 else
16027 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
16028 }
38c1f2d7
MM
16029 break;
16030 }
e165f3f0 16031}
a251ffd0 16032
b54cf83a 16033\f
b54cf83a
DE
16034/* Power4 load update and store update instructions are cracked into a
16035 load or store and an integer insn which are executed in the same cycle.
16036 Branches have their own dispatch slot which does not count against the
16037 GCC issue rate, but it changes the program flow so there are no other
16038 instructions to issue in this cycle. */
16039
16040static int
f676971a
EC
16041rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
16042 int verbose ATTRIBUTE_UNUSED,
a2369ed3 16043 rtx insn, int more)
b54cf83a
DE
16044{
16045 if (GET_CODE (PATTERN (insn)) == USE
16046 || GET_CODE (PATTERN (insn)) == CLOBBER)
16047 return more;
16048
ec507f2d 16049 if (rs6000_sched_groups)
b54cf83a 16050 {
cbe26ab8 16051 if (is_microcoded_insn (insn))
c4ad648e 16052 return 0;
cbe26ab8 16053 else if (is_cracked_insn (insn))
c4ad648e 16054 return more > 2 ? more - 2 : 0;
b54cf83a 16055 }
165b263e
DE
16056
16057 return more - 1;
b54cf83a
DE
16058}
16059
a251ffd0
TG
16060/* Adjust the cost of a scheduling dependency. Return the new cost of
16061 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
16062
c237e94a 16063static int
0a4f0294 16064rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn, int cost)
a251ffd0
TG
16065{
16066 if (! recog_memoized (insn))
16067 return 0;
16068
16069 if (REG_NOTE_KIND (link) != 0)
16070 return 0;
16071
16072 if (REG_NOTE_KIND (link) == 0)
16073 {
ed947a96
DJ
16074 /* Data dependency; DEP_INSN writes a register that INSN reads
16075 some cycles later. */
c9dbf840
DE
16076
16077 /* Separate a load from a narrower, dependent store. */
16078 if (rs6000_sched_groups
16079 && GET_CODE (PATTERN (insn)) == SET
16080 && GET_CODE (PATTERN (dep_insn)) == SET
16081 && GET_CODE (XEXP (PATTERN (insn), 1)) == MEM
16082 && GET_CODE (XEXP (PATTERN (dep_insn), 0)) == MEM
16083 && (GET_MODE_SIZE (GET_MODE (XEXP (PATTERN (insn), 1)))
16084 > GET_MODE_SIZE (GET_MODE (XEXP (PATTERN (dep_insn), 0)))))
16085 return cost + 14;
16086
ed947a96
DJ
16087 switch (get_attr_type (insn))
16088 {
16089 case TYPE_JMPREG:
309323c2 16090 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
16091 a mtctr and bctr (and mtlr and br/blr). The first
16092 scheduling pass will not know about this latency since
16093 the mtctr instruction, which has the latency associated
16094 to it, will be generated by reload. */
309323c2 16095 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
16096 case TYPE_BRANCH:
16097 /* Leave some extra cycles between a compare and its
16098 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
16099 if ((rs6000_cpu_attr == CPU_PPC603
16100 || rs6000_cpu_attr == CPU_PPC604
16101 || rs6000_cpu_attr == CPU_PPC604E
16102 || rs6000_cpu_attr == CPU_PPC620
16103 || rs6000_cpu_attr == CPU_PPC630
16104 || rs6000_cpu_attr == CPU_PPC750
16105 || rs6000_cpu_attr == CPU_PPC7400
16106 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
16107 || rs6000_cpu_attr == CPU_POWER4
16108 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
16109 && recog_memoized (dep_insn)
16110 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
16111 && (get_attr_type (dep_insn) == TYPE_CMP
16112 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 16113 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
16114 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
16115 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 16116 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
16117 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
16118 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
16119 return cost + 2;
16120 default:
16121 break;
16122 }
a251ffd0
TG
16123 /* Fall out to return default cost. */
16124 }
16125
16126 return cost;
16127}
b6c9286a 16128
cbe26ab8 16129/* The function returns a true if INSN is microcoded.
839a4992 16130 Return false otherwise. */
cbe26ab8
DN
16131
16132static bool
16133is_microcoded_insn (rtx insn)
16134{
16135 if (!insn || !INSN_P (insn)
16136 || GET_CODE (PATTERN (insn)) == USE
16137 || GET_CODE (PATTERN (insn)) == CLOBBER)
16138 return false;
16139
ec507f2d 16140 if (rs6000_sched_groups)
cbe26ab8
DN
16141 {
16142 enum attr_type type = get_attr_type (insn);
16143 if (type == TYPE_LOAD_EXT_U
16144 || type == TYPE_LOAD_EXT_UX
16145 || type == TYPE_LOAD_UX
16146 || type == TYPE_STORE_UX
16147 || type == TYPE_MFCR)
c4ad648e 16148 return true;
cbe26ab8
DN
16149 }
16150
16151 return false;
16152}
16153
5c425df5 16154/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
16155 as the first insn in a dispatch group ("dispatch-slot restricted").
16156 In this case, the returned value indicates how many dispatch slots
16157 the insn occupies (at the beginning of the group).
79ae11c4
DN
16158 Return 0 otherwise. */
16159
cbe26ab8 16160static int
79ae11c4
DN
16161is_dispatch_slot_restricted (rtx insn)
16162{
16163 enum attr_type type;
16164
ec507f2d 16165 if (!rs6000_sched_groups)
79ae11c4
DN
16166 return 0;
16167
16168 if (!insn
16169 || insn == NULL_RTX
16170 || GET_CODE (insn) == NOTE
16171 || GET_CODE (PATTERN (insn)) == USE
16172 || GET_CODE (PATTERN (insn)) == CLOBBER)
16173 return 0;
16174
16175 type = get_attr_type (insn);
16176
ec507f2d
DE
16177 switch (type)
16178 {
16179 case TYPE_MFCR:
16180 case TYPE_MFCRF:
16181 case TYPE_MTCR:
16182 case TYPE_DELAYED_CR:
16183 case TYPE_CR_LOGICAL:
16184 case TYPE_MTJMPR:
16185 case TYPE_MFJMPR:
16186 return 1;
16187 case TYPE_IDIV:
16188 case TYPE_LDIV:
16189 return 2;
16190 default:
16191 if (rs6000_cpu == PROCESSOR_POWER5
16192 && is_cracked_insn (insn))
16193 return 2;
16194 return 0;
16195 }
79ae11c4
DN
16196}
16197
cbe26ab8
DN
16198/* The function returns true if INSN is cracked into 2 instructions
16199 by the processor (and therefore occupies 2 issue slots). */
16200
16201static bool
16202is_cracked_insn (rtx insn)
16203{
16204 if (!insn || !INSN_P (insn)
16205 || GET_CODE (PATTERN (insn)) == USE
16206 || GET_CODE (PATTERN (insn)) == CLOBBER)
16207 return false;
16208
ec507f2d 16209 if (rs6000_sched_groups)
cbe26ab8
DN
16210 {
16211 enum attr_type type = get_attr_type (insn);
16212 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
c4ad648e
AM
16213 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
16214 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
16215 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
16216 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
16217 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
16218 || type == TYPE_IDIV || type == TYPE_LDIV
16219 || type == TYPE_INSERT_WORD)
16220 return true;
cbe26ab8
DN
16221 }
16222
16223 return false;
16224}
16225
16226/* The function returns true if INSN can be issued only from
a3c9585f 16227 the branch slot. */
cbe26ab8
DN
16228
16229static bool
16230is_branch_slot_insn (rtx insn)
16231{
16232 if (!insn || !INSN_P (insn)
16233 || GET_CODE (PATTERN (insn)) == USE
16234 || GET_CODE (PATTERN (insn)) == CLOBBER)
16235 return false;
16236
ec507f2d 16237 if (rs6000_sched_groups)
cbe26ab8
DN
16238 {
16239 enum attr_type type = get_attr_type (insn);
16240 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
f676971a 16241 return true;
cbe26ab8
DN
16242 return false;
16243 }
16244
16245 return false;
16246}
79ae11c4 16247
a4f6c312 16248/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
16249 priority INSN_PRIORITY (INSN). Increase the priority to execute the
16250 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
16251 define this macro if you do not need to adjust the scheduling
16252 priorities of insns. */
bef84347 16253
c237e94a 16254static int
a2369ed3 16255rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 16256{
a4f6c312
SS
16257 /* On machines (like the 750) which have asymmetric integer units,
16258 where one integer unit can do multiply and divides and the other
16259 can't, reduce the priority of multiply/divide so it is scheduled
16260 before other integer operations. */
bef84347
VM
16261
16262#if 0
2c3c49de 16263 if (! INSN_P (insn))
bef84347
VM
16264 return priority;
16265
16266 if (GET_CODE (PATTERN (insn)) == USE)
16267 return priority;
16268
16269 switch (rs6000_cpu_attr) {
16270 case CPU_PPC750:
16271 switch (get_attr_type (insn))
16272 {
16273 default:
16274 break;
16275
16276 case TYPE_IMUL:
16277 case TYPE_IDIV:
3cb999d8
DE
16278 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
16279 priority, priority);
bef84347
VM
16280 if (priority >= 0 && priority < 0x01000000)
16281 priority >>= 3;
16282 break;
16283 }
16284 }
16285#endif
16286
79ae11c4
DN
16287 if (is_dispatch_slot_restricted (insn)
16288 && reload_completed
f676971a 16289 && current_sched_info->sched_max_insns_priority
79ae11c4
DN
16290 && rs6000_sched_restricted_insns_priority)
16291 {
16292
c4ad648e
AM
16293 /* Prioritize insns that can be dispatched only in the first
16294 dispatch slot. */
79ae11c4 16295 if (rs6000_sched_restricted_insns_priority == 1)
f676971a
EC
16296 /* Attach highest priority to insn. This means that in
16297 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
79ae11c4 16298 precede 'priority' (critical path) considerations. */
f676971a 16299 return current_sched_info->sched_max_insns_priority;
79ae11c4 16300 else if (rs6000_sched_restricted_insns_priority == 2)
f676971a 16301 /* Increase priority of insn by a minimal amount. This means that in
c4ad648e
AM
16302 haifa-sched.c:ready_sort(), only 'priority' (critical path)
16303 considerations precede dispatch-slot restriction considerations. */
f676971a
EC
16304 return (priority + 1);
16305 }
79ae11c4 16306
bef84347
VM
16307 return priority;
16308}
16309
a4f6c312
SS
16310/* Return how many instructions the machine can issue per cycle. */
16311
c237e94a 16312static int
863d938c 16313rs6000_issue_rate (void)
b6c9286a 16314{
3317bab1
DE
16315 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
16316 if (!reload_completed)
16317 return 1;
16318
b6c9286a 16319 switch (rs6000_cpu_attr) {
3cb999d8
DE
16320 case CPU_RIOS1: /* ? */
16321 case CPU_RS64A:
16322 case CPU_PPC601: /* ? */
ed947a96 16323 case CPU_PPC7450:
3cb999d8 16324 return 3;
b54cf83a 16325 case CPU_PPC440:
b6c9286a 16326 case CPU_PPC603:
bef84347 16327 case CPU_PPC750:
ed947a96 16328 case CPU_PPC7400:
be12c2b0 16329 case CPU_PPC8540:
f676971a 16330 return 2;
3cb999d8 16331 case CPU_RIOS2:
b6c9286a 16332 case CPU_PPC604:
19684119 16333 case CPU_PPC604E:
b6c9286a 16334 case CPU_PPC620:
3cb999d8 16335 case CPU_PPC630:
b6c9286a 16336 return 4;
cbe26ab8 16337 case CPU_POWER4:
ec507f2d 16338 case CPU_POWER5:
cbe26ab8 16339 return 5;
b6c9286a
MM
16340 default:
16341 return 1;
16342 }
16343}
16344
be12c2b0
VM
16345/* Return how many instructions to look ahead for better insn
16346 scheduling. */
16347
16348static int
863d938c 16349rs6000_use_sched_lookahead (void)
be12c2b0
VM
16350{
16351 if (rs6000_cpu_attr == CPU_PPC8540)
16352 return 4;
16353 return 0;
16354}
16355
569fa502
DN
16356/* Determine is PAT refers to memory. */
16357
16358static bool
16359is_mem_ref (rtx pat)
16360{
16361 const char * fmt;
16362 int i, j;
16363 bool ret = false;
16364
16365 if (GET_CODE (pat) == MEM)
16366 return true;
16367
16368 /* Recursively process the pattern. */
16369 fmt = GET_RTX_FORMAT (GET_CODE (pat));
16370
16371 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
16372 {
16373 if (fmt[i] == 'e')
16374 ret |= is_mem_ref (XEXP (pat, i));
16375 else if (fmt[i] == 'E')
16376 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
16377 ret |= is_mem_ref (XVECEXP (pat, i, j));
16378 }
16379
16380 return ret;
16381}
16382
16383/* Determine if PAT is a PATTERN of a load insn. */
f676971a 16384
569fa502
DN
16385static bool
16386is_load_insn1 (rtx pat)
16387{
16388 if (!pat || pat == NULL_RTX)
16389 return false;
16390
16391 if (GET_CODE (pat) == SET)
16392 return is_mem_ref (SET_SRC (pat));
16393
16394 if (GET_CODE (pat) == PARALLEL)
16395 {
16396 int i;
16397
16398 for (i = 0; i < XVECLEN (pat, 0); i++)
16399 if (is_load_insn1 (XVECEXP (pat, 0, i)))
16400 return true;
16401 }
16402
16403 return false;
16404}
16405
16406/* Determine if INSN loads from memory. */
16407
16408static bool
16409is_load_insn (rtx insn)
16410{
16411 if (!insn || !INSN_P (insn))
16412 return false;
16413
16414 if (GET_CODE (insn) == CALL_INSN)
16415 return false;
16416
16417 return is_load_insn1 (PATTERN (insn));
16418}
16419
16420/* Determine if PAT is a PATTERN of a store insn. */
16421
16422static bool
16423is_store_insn1 (rtx pat)
16424{
16425 if (!pat || pat == NULL_RTX)
16426 return false;
16427
16428 if (GET_CODE (pat) == SET)
16429 return is_mem_ref (SET_DEST (pat));
16430
16431 if (GET_CODE (pat) == PARALLEL)
16432 {
16433 int i;
16434
16435 for (i = 0; i < XVECLEN (pat, 0); i++)
16436 if (is_store_insn1 (XVECEXP (pat, 0, i)))
16437 return true;
16438 }
16439
16440 return false;
16441}
16442
16443/* Determine if INSN stores to memory. */
16444
16445static bool
16446is_store_insn (rtx insn)
16447{
16448 if (!insn || !INSN_P (insn))
16449 return false;
16450
16451 return is_store_insn1 (PATTERN (insn));
16452}
16453
16454/* Returns whether the dependence between INSN and NEXT is considered
16455 costly by the given target. */
16456
16457static bool
c4ad648e
AM
16458rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost,
16459 int distance)
f676971a 16460{
569fa502 16461 /* If the flag is not enbled - no dependence is considered costly;
f676971a 16462 allow all dependent insns in the same group.
569fa502
DN
16463 This is the most aggressive option. */
16464 if (rs6000_sched_costly_dep == no_dep_costly)
16465 return false;
16466
f676971a 16467 /* If the flag is set to 1 - a dependence is always considered costly;
569fa502
DN
16468 do not allow dependent instructions in the same group.
16469 This is the most conservative option. */
16470 if (rs6000_sched_costly_dep == all_deps_costly)
f676971a 16471 return true;
569fa502 16472
f676971a
EC
16473 if (rs6000_sched_costly_dep == store_to_load_dep_costly
16474 && is_load_insn (next)
569fa502
DN
16475 && is_store_insn (insn))
16476 /* Prevent load after store in the same group. */
16477 return true;
16478
16479 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
f676971a 16480 && is_load_insn (next)
569fa502
DN
16481 && is_store_insn (insn)
16482 && (!link || (int) REG_NOTE_KIND (link) == 0))
c4ad648e
AM
16483 /* Prevent load after store in the same group if it is a true
16484 dependence. */
569fa502 16485 return true;
f676971a
EC
16486
16487 /* The flag is set to X; dependences with latency >= X are considered costly,
569fa502
DN
16488 and will not be scheduled in the same group. */
16489 if (rs6000_sched_costly_dep <= max_dep_latency
16490 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
16491 return true;
16492
16493 return false;
16494}
16495
f676971a 16496/* Return the next insn after INSN that is found before TAIL is reached,
cbe26ab8
DN
16497 skipping any "non-active" insns - insns that will not actually occupy
16498 an issue slot. Return NULL_RTX if such an insn is not found. */
16499
16500static rtx
16501get_next_active_insn (rtx insn, rtx tail)
16502{
16503 rtx next_insn;
16504
16505 if (!insn || insn == tail)
16506 return NULL_RTX;
16507
16508 next_insn = NEXT_INSN (insn);
16509
16510 while (next_insn
16511 && next_insn != tail
16512 && (GET_CODE(next_insn) == NOTE
16513 || GET_CODE (PATTERN (next_insn)) == USE
16514 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
16515 {
16516 next_insn = NEXT_INSN (next_insn);
16517 }
16518
16519 if (!next_insn || next_insn == tail)
16520 return NULL_RTX;
16521
16522 return next_insn;
16523}
16524
839a4992 16525/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
16526 of group WHICH_GROUP.
16527
16528 If WHICH_GROUP == current_group, this function will return true if INSN
16529 causes the termination of the current group (i.e, the dispatch group to
16530 which INSN belongs). This means that INSN will be the last insn in the
16531 group it belongs to.
16532
16533 If WHICH_GROUP == previous_group, this function will return true if INSN
16534 causes the termination of the previous group (i.e, the dispatch group that
16535 precedes the group to which INSN belongs). This means that INSN will be
16536 the first insn in the group it belongs to). */
16537
16538static bool
16539insn_terminates_group_p (rtx insn, enum group_termination which_group)
16540{
16541 enum attr_type type;
16542
16543 if (! insn)
16544 return false;
569fa502 16545
cbe26ab8
DN
16546 type = get_attr_type (insn);
16547
16548 if (is_microcoded_insn (insn))
16549 return true;
16550
16551 if (which_group == current_group)
16552 {
16553 if (is_branch_slot_insn (insn))
c4ad648e 16554 return true;
cbe26ab8
DN
16555 return false;
16556 }
16557 else if (which_group == previous_group)
16558 {
16559 if (is_dispatch_slot_restricted (insn))
c4ad648e 16560 return true;
cbe26ab8
DN
16561 return false;
16562 }
16563
16564 return false;
16565}
16566
839a4992 16567/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
16568 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
16569
16570static bool
16571is_costly_group (rtx *group_insns, rtx next_insn)
16572{
16573 int i;
16574 rtx link;
16575 int cost;
16576 int issue_rate = rs6000_issue_rate ();
16577
16578 for (i = 0; i < issue_rate; i++)
16579 {
16580 rtx insn = group_insns[i];
16581 if (!insn)
c4ad648e 16582 continue;
cbe26ab8 16583 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
c4ad648e
AM
16584 {
16585 rtx next = XEXP (link, 0);
16586 if (next == next_insn)
16587 {
16588 cost = insn_cost (insn, link, next_insn);
16589 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
16590 return true;
16591 }
16592 }
cbe26ab8
DN
16593 }
16594
16595 return false;
16596}
16597
f676971a 16598/* Utility of the function redefine_groups.
cbe26ab8
DN
16599 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
16600 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
16601 to keep it "far" (in a separate group) from GROUP_INSNS, following
16602 one of the following schemes, depending on the value of the flag
16603 -minsert_sched_nops = X:
16604 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 16605 in order to force NEXT_INSN into a separate group.
f676971a
EC
16606 (2) X < sched_finish_regroup_exact: insert exactly X nops.
16607 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
cbe26ab8
DN
16608 insertion (has a group just ended, how many vacant issue slots remain in the
16609 last group, and how many dispatch groups were encountered so far). */
16610
f676971a 16611static int
c4ad648e
AM
16612force_new_group (int sched_verbose, FILE *dump, rtx *group_insns,
16613 rtx next_insn, bool *group_end, int can_issue_more,
16614 int *group_count)
cbe26ab8
DN
16615{
16616 rtx nop;
16617 bool force;
16618 int issue_rate = rs6000_issue_rate ();
16619 bool end = *group_end;
16620 int i;
16621
16622 if (next_insn == NULL_RTX)
16623 return can_issue_more;
16624
16625 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
16626 return can_issue_more;
16627
16628 force = is_costly_group (group_insns, next_insn);
16629 if (!force)
16630 return can_issue_more;
16631
16632 if (sched_verbose > 6)
16633 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
c4ad648e 16634 *group_count ,can_issue_more);
cbe26ab8
DN
16635
16636 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
16637 {
16638 if (*group_end)
c4ad648e 16639 can_issue_more = 0;
cbe26ab8
DN
16640
16641 /* Since only a branch can be issued in the last issue_slot, it is
16642 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
16643 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
c4ad648e
AM
16644 in this case the last nop will start a new group and the branch
16645 will be forced to the new group. */
cbe26ab8 16646 if (can_issue_more && !is_branch_slot_insn (next_insn))
c4ad648e 16647 can_issue_more--;
cbe26ab8
DN
16648
16649 while (can_issue_more > 0)
c4ad648e
AM
16650 {
16651 nop = gen_nop();
16652 emit_insn_before (nop, next_insn);
16653 can_issue_more--;
16654 }
cbe26ab8
DN
16655
16656 *group_end = true;
16657 return 0;
f676971a 16658 }
cbe26ab8
DN
16659
16660 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
16661 {
16662 int n_nops = rs6000_sched_insert_nops;
16663
f676971a 16664 /* Nops can't be issued from the branch slot, so the effective
c4ad648e 16665 issue_rate for nops is 'issue_rate - 1'. */
cbe26ab8 16666 if (can_issue_more == 0)
c4ad648e 16667 can_issue_more = issue_rate;
cbe26ab8
DN
16668 can_issue_more--;
16669 if (can_issue_more == 0)
c4ad648e
AM
16670 {
16671 can_issue_more = issue_rate - 1;
16672 (*group_count)++;
16673 end = true;
16674 for (i = 0; i < issue_rate; i++)
16675 {
16676 group_insns[i] = 0;
16677 }
16678 }
cbe26ab8
DN
16679
16680 while (n_nops > 0)
c4ad648e
AM
16681 {
16682 nop = gen_nop ();
16683 emit_insn_before (nop, next_insn);
16684 if (can_issue_more == issue_rate - 1) /* new group begins */
16685 end = false;
16686 can_issue_more--;
16687 if (can_issue_more == 0)
16688 {
16689 can_issue_more = issue_rate - 1;
16690 (*group_count)++;
16691 end = true;
16692 for (i = 0; i < issue_rate; i++)
16693 {
16694 group_insns[i] = 0;
16695 }
16696 }
16697 n_nops--;
16698 }
cbe26ab8
DN
16699
16700 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
f676971a 16701 can_issue_more++;
cbe26ab8 16702
c4ad648e
AM
16703 /* Is next_insn going to start a new group? */
16704 *group_end
16705 = (end
cbe26ab8
DN
16706 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
16707 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
16708 || (can_issue_more < issue_rate &&
c4ad648e 16709 insn_terminates_group_p (next_insn, previous_group)));
cbe26ab8 16710 if (*group_end && end)
c4ad648e 16711 (*group_count)--;
cbe26ab8
DN
16712
16713 if (sched_verbose > 6)
c4ad648e
AM
16714 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
16715 *group_count, can_issue_more);
f676971a
EC
16716 return can_issue_more;
16717 }
cbe26ab8
DN
16718
16719 return can_issue_more;
16720}
16721
16722/* This function tries to synch the dispatch groups that the compiler "sees"
f676971a 16723 with the dispatch groups that the processor dispatcher is expected to
cbe26ab8
DN
16724 form in practice. It tries to achieve this synchronization by forcing the
16725 estimated processor grouping on the compiler (as opposed to the function
16726 'pad_goups' which tries to force the scheduler's grouping on the processor).
16727
16728 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
16729 examines the (estimated) dispatch groups that will be formed by the processor
16730 dispatcher. It marks these group boundaries to reflect the estimated
16731 processor grouping, overriding the grouping that the scheduler had marked.
16732 Depending on the value of the flag '-minsert-sched-nops' this function can
16733 force certain insns into separate groups or force a certain distance between
16734 them by inserting nops, for example, if there exists a "costly dependence"
16735 between the insns.
16736
16737 The function estimates the group boundaries that the processor will form as
16738 folllows: It keeps track of how many vacant issue slots are available after
16739 each insn. A subsequent insn will start a new group if one of the following
16740 4 cases applies:
16741 - no more vacant issue slots remain in the current dispatch group.
16742 - only the last issue slot, which is the branch slot, is vacant, but the next
16743 insn is not a branch.
16744 - only the last 2 or less issue slots, including the branch slot, are vacant,
16745 which means that a cracked insn (which occupies two issue slots) can't be
16746 issued in this group.
f676971a 16747 - less than 'issue_rate' slots are vacant, and the next insn always needs to
cbe26ab8
DN
16748 start a new group. */
16749
16750static int
16751redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
16752{
16753 rtx insn, next_insn;
16754 int issue_rate;
16755 int can_issue_more;
16756 int slot, i;
16757 bool group_end;
16758 int group_count = 0;
16759 rtx *group_insns;
16760
16761 /* Initialize. */
16762 issue_rate = rs6000_issue_rate ();
16763 group_insns = alloca (issue_rate * sizeof (rtx));
f676971a 16764 for (i = 0; i < issue_rate; i++)
cbe26ab8
DN
16765 {
16766 group_insns[i] = 0;
16767 }
16768 can_issue_more = issue_rate;
16769 slot = 0;
16770 insn = get_next_active_insn (prev_head_insn, tail);
16771 group_end = false;
16772
16773 while (insn != NULL_RTX)
16774 {
16775 slot = (issue_rate - can_issue_more);
16776 group_insns[slot] = insn;
16777 can_issue_more =
c4ad648e 16778 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
cbe26ab8 16779 if (insn_terminates_group_p (insn, current_group))
c4ad648e 16780 can_issue_more = 0;
cbe26ab8
DN
16781
16782 next_insn = get_next_active_insn (insn, tail);
16783 if (next_insn == NULL_RTX)
c4ad648e 16784 return group_count + 1;
cbe26ab8 16785
c4ad648e
AM
16786 /* Is next_insn going to start a new group? */
16787 group_end
16788 = (can_issue_more == 0
16789 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
16790 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
16791 || (can_issue_more < issue_rate &&
16792 insn_terminates_group_p (next_insn, previous_group)));
cbe26ab8 16793
f676971a 16794 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
c4ad648e
AM
16795 next_insn, &group_end, can_issue_more,
16796 &group_count);
cbe26ab8
DN
16797
16798 if (group_end)
c4ad648e
AM
16799 {
16800 group_count++;
16801 can_issue_more = 0;
16802 for (i = 0; i < issue_rate; i++)
16803 {
16804 group_insns[i] = 0;
16805 }
16806 }
cbe26ab8
DN
16807
16808 if (GET_MODE (next_insn) == TImode && can_issue_more)
c4ad648e 16809 PUT_MODE(next_insn, VOIDmode);
cbe26ab8 16810 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
c4ad648e 16811 PUT_MODE (next_insn, TImode);
cbe26ab8
DN
16812
16813 insn = next_insn;
16814 if (can_issue_more == 0)
c4ad648e
AM
16815 can_issue_more = issue_rate;
16816 } /* while */
cbe26ab8
DN
16817
16818 return group_count;
16819}
16820
16821/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
16822 dispatch group boundaries that the scheduler had marked. Pad with nops
16823 any dispatch groups which have vacant issue slots, in order to force the
16824 scheduler's grouping on the processor dispatcher. The function
16825 returns the number of dispatch groups found. */
16826
16827static int
16828pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
16829{
16830 rtx insn, next_insn;
16831 rtx nop;
16832 int issue_rate;
16833 int can_issue_more;
16834 int group_end;
16835 int group_count = 0;
16836
16837 /* Initialize issue_rate. */
16838 issue_rate = rs6000_issue_rate ();
16839 can_issue_more = issue_rate;
16840
16841 insn = get_next_active_insn (prev_head_insn, tail);
16842 next_insn = get_next_active_insn (insn, tail);
16843
16844 while (insn != NULL_RTX)
16845 {
16846 can_issue_more =
16847 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
16848
16849 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
16850
16851 if (next_insn == NULL_RTX)
c4ad648e 16852 break;
cbe26ab8
DN
16853
16854 if (group_end)
c4ad648e
AM
16855 {
16856 /* If the scheduler had marked group termination at this location
16857 (between insn and next_indn), and neither insn nor next_insn will
16858 force group termination, pad the group with nops to force group
16859 termination. */
16860 if (can_issue_more
16861 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
16862 && !insn_terminates_group_p (insn, current_group)
16863 && !insn_terminates_group_p (next_insn, previous_group))
16864 {
16865 if (!is_branch_slot_insn(next_insn))
16866 can_issue_more--;
16867
16868 while (can_issue_more)
16869 {
16870 nop = gen_nop ();
16871 emit_insn_before (nop, next_insn);
16872 can_issue_more--;
16873 }
16874 }
16875
16876 can_issue_more = issue_rate;
16877 group_count++;
16878 }
cbe26ab8
DN
16879
16880 insn = next_insn;
16881 next_insn = get_next_active_insn (insn, tail);
16882 }
16883
16884 return group_count;
16885}
16886
16887/* The following function is called at the end of scheduling BB.
16888 After reload, it inserts nops at insn group bundling. */
16889
16890static void
38f391a5 16891rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
16892{
16893 int n_groups;
16894
16895 if (sched_verbose)
16896 fprintf (dump, "=== Finishing schedule.\n");
16897
ec507f2d 16898 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
16899 {
16900 if (rs6000_sched_insert_nops == sched_finish_none)
c4ad648e 16901 return;
cbe26ab8
DN
16902
16903 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
c4ad648e
AM
16904 n_groups = pad_groups (dump, sched_verbose,
16905 current_sched_info->prev_head,
16906 current_sched_info->next_tail);
cbe26ab8 16907 else
c4ad648e
AM
16908 n_groups = redefine_groups (dump, sched_verbose,
16909 current_sched_info->prev_head,
16910 current_sched_info->next_tail);
cbe26ab8
DN
16911
16912 if (sched_verbose >= 6)
16913 {
16914 fprintf (dump, "ngroups = %d\n", n_groups);
16915 print_rtl (dump, current_sched_info->prev_head);
16916 fprintf (dump, "Done finish_sched\n");
16917 }
16918 }
16919}
b6c9286a 16920\f
b6c9286a
MM
16921/* Length in units of the trampoline for entering a nested function. */
16922
16923int
863d938c 16924rs6000_trampoline_size (void)
b6c9286a
MM
16925{
16926 int ret = 0;
16927
16928 switch (DEFAULT_ABI)
16929 {
16930 default:
16931 abort ();
16932
16933 case ABI_AIX:
8f802bfb 16934 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
16935 break;
16936
4dabc42d 16937 case ABI_DARWIN:
b6c9286a 16938 case ABI_V4:
03a7e1a5 16939 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 16940 break;
b6c9286a
MM
16941 }
16942
16943 return ret;
16944}
16945
16946/* Emit RTL insns to initialize the variable parts of a trampoline.
16947 FNADDR is an RTX for the address of the function's pure code.
16948 CXT is an RTX for the static chain value for the function. */
16949
16950void
a2369ed3 16951rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 16952{
ac2a93a1 16953 enum machine_mode pmode = Pmode;
8bd04c56
MM
16954 int regsize = (TARGET_32BIT) ? 4 : 8;
16955 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
16956
16957 switch (DEFAULT_ABI)
16958 {
16959 default:
16960 abort ();
16961
8bd04c56 16962/* Macros to shorten the code expansions below. */
39403d82 16963#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
16964#define MEM_PLUS(addr,offset) \
16965 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 16966
b6c9286a
MM
16967 /* Under AIX, just build the 3 word function descriptor */
16968 case ABI_AIX:
8bd04c56
MM
16969 {
16970 rtx fn_reg = gen_reg_rtx (pmode);
16971 rtx toc_reg = gen_reg_rtx (pmode);
16972 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 16973 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
16974 emit_move_insn (MEM_DEREF (addr), fn_reg);
16975 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
16976 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
16977 }
b6c9286a
MM
16978 break;
16979
4dabc42d
TC
16980 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
16981 case ABI_DARWIN:
b6c9286a 16982 case ABI_V4:
39403d82 16983 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
16984 FALSE, VOIDmode, 4,
16985 addr, pmode,
16986 GEN_INT (rs6000_trampoline_size ()), SImode,
16987 fnaddr, pmode,
16988 ctx_reg, pmode);
b6c9286a 16989 break;
b6c9286a
MM
16990 }
16991
16992 return;
16993}
7509c759
MM
16994
16995\f
91d231cb 16996/* Table of valid machine attributes. */
a4f6c312 16997
91d231cb 16998const struct attribute_spec rs6000_attribute_table[] =
7509c759 16999{
91d231cb 17000 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 17001 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
17002 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
17003 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
005c1a13
GK
17004#ifdef SUBTARGET_ATTRIBUTE_TABLE
17005 SUBTARGET_ATTRIBUTE_TABLE,
17006#endif
a5c76ee6 17007 { NULL, 0, 0, false, false, false, NULL }
91d231cb 17008};
7509c759 17009
8bb418a3
ZL
17010/* Handle the "altivec" attribute. The attribute may have
17011 arguments as follows:
f676971a 17012
8bb418a3
ZL
17013 __attribute__((altivec(vector__)))
17014 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
17015 __attribute__((altivec(bool__))) (always followed by 'unsigned')
17016
17017 and may appear more than once (e.g., 'vector bool char') in a
17018 given declaration. */
17019
17020static tree
17021rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
17022 int flags ATTRIBUTE_UNUSED,
17023 bool *no_add_attrs)
17024{
17025 tree type = *node, result = NULL_TREE;
17026 enum machine_mode mode;
17027 int unsigned_p;
17028 char altivec_type
17029 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
17030 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
17031 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
f676971a 17032 : '?');
8bb418a3
ZL
17033
17034 while (POINTER_TYPE_P (type)
17035 || TREE_CODE (type) == FUNCTION_TYPE
17036 || TREE_CODE (type) == METHOD_TYPE
17037 || TREE_CODE (type) == ARRAY_TYPE)
17038 type = TREE_TYPE (type);
17039
17040 mode = TYPE_MODE (type);
17041
17042 if (rs6000_warn_altivec_long
17043 && (type == long_unsigned_type_node || type == long_integer_type_node))
17044 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
17045
17046 switch (altivec_type)
17047 {
17048 case 'v':
8df83eae 17049 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
17050 switch (mode)
17051 {
c4ad648e
AM
17052 case SImode:
17053 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
17054 break;
17055 case HImode:
17056 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
17057 break;
17058 case QImode:
17059 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
17060 break;
17061 case SFmode: result = V4SF_type_node; break;
17062 /* If the user says 'vector int bool', we may be handed the 'bool'
17063 attribute _before_ the 'vector' attribute, and so select the
17064 proper type in the 'b' case below. */
17065 case V4SImode: case V8HImode: case V16QImode: case V4SFmode:
17066 result = type;
17067 default: break;
8bb418a3
ZL
17068 }
17069 break;
17070 case 'b':
17071 switch (mode)
17072 {
c4ad648e
AM
17073 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
17074 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
17075 case QImode: case V16QImode: result = bool_V16QI_type_node;
17076 default: break;
8bb418a3
ZL
17077 }
17078 break;
17079 case 'p':
17080 switch (mode)
17081 {
c4ad648e
AM
17082 case V8HImode: result = pixel_V8HI_type_node;
17083 default: break;
8bb418a3
ZL
17084 }
17085 default: break;
17086 }
17087
7958a2a6
FJ
17088 if (result && result != type && TYPE_READONLY (type))
17089 result = build_qualified_type (result, TYPE_QUAL_CONST);
17090
8bb418a3
ZL
17091 *no_add_attrs = true; /* No need to hang on to the attribute. */
17092
17093 if (!result)
9e637a26 17094 warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
8bb418a3
ZL
17095 else
17096 *node = reconstruct_complex_type (*node, result);
17097
17098 return NULL_TREE;
17099}
17100
f18eca82
ZL
17101/* AltiVec defines four built-in scalar types that serve as vector
17102 elements; we must teach the compiler how to mangle them. */
17103
17104static const char *
17105rs6000_mangle_fundamental_type (tree type)
17106{
17107 if (type == bool_char_type_node) return "U6__boolc";
17108 if (type == bool_short_type_node) return "U6__bools";
17109 if (type == pixel_type_node) return "u7__pixel";
17110 if (type == bool_int_type_node) return "U6__booli";
17111
17112 /* For all other types, use normal C++ mangling. */
17113 return NULL;
17114}
17115
a5c76ee6
ZW
17116/* Handle a "longcall" or "shortcall" attribute; arguments as in
17117 struct attribute_spec.handler. */
a4f6c312 17118
91d231cb 17119static tree
f676971a
EC
17120rs6000_handle_longcall_attribute (tree *node, tree name,
17121 tree args ATTRIBUTE_UNUSED,
17122 int flags ATTRIBUTE_UNUSED,
a2369ed3 17123 bool *no_add_attrs)
91d231cb
JM
17124{
17125 if (TREE_CODE (*node) != FUNCTION_TYPE
17126 && TREE_CODE (*node) != FIELD_DECL
17127 && TREE_CODE (*node) != TYPE_DECL)
17128 {
9e637a26 17129 warning ("%qs attribute only applies to functions",
91d231cb
JM
17130 IDENTIFIER_POINTER (name));
17131 *no_add_attrs = true;
17132 }
6a4cee5f 17133
91d231cb 17134 return NULL_TREE;
7509c759
MM
17135}
17136
a5c76ee6
ZW
17137/* Set longcall attributes on all functions declared when
17138 rs6000_default_long_calls is true. */
17139static void
a2369ed3 17140rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
17141{
17142 if (rs6000_default_long_calls
17143 && (TREE_CODE (type) == FUNCTION_TYPE
17144 || TREE_CODE (type) == METHOD_TYPE))
17145 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
17146 NULL_TREE,
17147 TYPE_ATTRIBUTES (type));
17148}
17149
3cb999d8
DE
17150/* Return a reference suitable for calling a function with the
17151 longcall attribute. */
a4f6c312 17152
6a4cee5f 17153struct rtx_def *
a2369ed3 17154rs6000_longcall_ref (rtx call_ref)
6a4cee5f 17155{
d330fd93 17156 const char *call_name;
6a4cee5f
MM
17157 tree node;
17158
17159 if (GET_CODE (call_ref) != SYMBOL_REF)
17160 return call_ref;
17161
17162 /* System V adds '.' to the internal name, so skip them. */
17163 call_name = XSTR (call_ref, 0);
17164 if (*call_name == '.')
17165 {
17166 while (*call_name == '.')
17167 call_name++;
17168
17169 node = get_identifier (call_name);
39403d82 17170 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
17171 }
17172
17173 return force_reg (Pmode, call_ref);
17174}
7509c759 17175\f
b64a1b53
RH
17176#ifdef USING_ELFOS_H
17177
7509c759
MM
17178/* A C statement or statements to switch to the appropriate section
17179 for output of RTX in mode MODE. You can assume that RTX is some
17180 kind of constant in RTL. The argument MODE is redundant except in
17181 the case of a `const_int' rtx. Select the section by calling
17182 `text_section' or one of the alternatives for other sections.
17183
17184 Do not define this macro if you put all constants in the read-only
17185 data section. */
17186
b64a1b53 17187static void
f676971a 17188rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
a2369ed3 17189 unsigned HOST_WIDE_INT align)
7509c759 17190{
a9098fd0 17191 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 17192 toc_section ();
7509c759 17193 else
b64a1b53 17194 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
17195}
17196
17197/* A C statement or statements to switch to the appropriate
17198 section for output of DECL. DECL is either a `VAR_DECL' node
17199 or a constant of some sort. RELOC indicates whether forming
17200 the initial value of DECL requires link-time relocations. */
17201
ae46c4e0 17202static void
f676971a 17203rs6000_elf_select_section (tree decl, int reloc,
a2369ed3 17204 unsigned HOST_WIDE_INT align)
7509c759 17205{
f1384257
AM
17206 /* Pretend that we're always building for a shared library when
17207 ABI_AIX, because otherwise we end up with dynamic relocations
17208 in read-only sections. This happens for function pointers,
17209 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
17210 default_elf_select_section_1 (decl, reloc, align,
17211 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
17212}
17213
17214/* A C statement to build up a unique section name, expressed as a
17215 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
17216 RELOC indicates whether the initial value of EXP requires
17217 link-time relocations. If you do not define this macro, GCC will use
17218 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 17219 macro can now be called for uninitialized data items as well as
4912a07c 17220 initialized data and functions. */
63019373 17221
ae46c4e0 17222static void
a2369ed3 17223rs6000_elf_unique_section (tree decl, int reloc)
63019373 17224{
f1384257
AM
17225 /* As above, pretend that we're always building for a shared library
17226 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
17227 default_unique_section_1 (decl, reloc,
17228 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 17229}
d9407988 17230\f
d1908feb
JJ
17231/* For a SYMBOL_REF, set generic flags and then perform some
17232 target-specific processing.
17233
d1908feb
JJ
17234 When the AIX ABI is requested on a non-AIX system, replace the
17235 function name with the real name (with a leading .) rather than the
17236 function descriptor name. This saves a lot of overriding code to
17237 read the prefixes. */
d9407988 17238
fb49053f 17239static void
a2369ed3 17240rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 17241{
d1908feb 17242 default_encode_section_info (decl, rtl, first);
b2003250 17243
d1908feb
JJ
17244 if (first
17245 && TREE_CODE (decl) == FUNCTION_DECL
17246 && !TARGET_AIX
17247 && DEFAULT_ABI == ABI_AIX)
d9407988 17248 {
c6a2438a 17249 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
17250 size_t len = strlen (XSTR (sym_ref, 0));
17251 char *str = alloca (len + 2);
17252 str[0] = '.';
17253 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
17254 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 17255 }
d9407988
MM
17256}
17257
0e5dbd9b 17258static bool
a2369ed3 17259rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
17260{
17261 if (rs6000_sdata == SDATA_NONE)
17262 return false;
17263
17264 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
17265 {
17266 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
17267 if (strcmp (section, ".sdata") == 0
17268 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
17269 || strcmp (section, ".sbss") == 0
17270 || strcmp (section, ".sbss2") == 0
17271 || strcmp (section, ".PPC.EMB.sdata0") == 0
17272 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
17273 return true;
17274 }
17275 else
17276 {
17277 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
17278
17279 if (size > 0
307b599c 17280 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
17281 /* If it's not public, and we're not going to reference it there,
17282 there's no need to put it in the small data section. */
0e5dbd9b
DE
17283 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
17284 return true;
17285 }
17286
17287 return false;
17288}
17289
b91da81f 17290#endif /* USING_ELFOS_H */
000034eb 17291
a6c2a102 17292\f
000034eb 17293/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
17294 ADDR can be effectively incremented by incrementing REG.
17295
17296 r0 is special and we must not select it as an address
17297 register by this routine since our caller will try to
17298 increment the returned register via an "la" instruction. */
000034eb
DE
17299
17300struct rtx_def *
a2369ed3 17301find_addr_reg (rtx addr)
000034eb
DE
17302{
17303 while (GET_CODE (addr) == PLUS)
17304 {
02441cd6
JL
17305 if (GET_CODE (XEXP (addr, 0)) == REG
17306 && REGNO (XEXP (addr, 0)) != 0)
000034eb 17307 addr = XEXP (addr, 0);
02441cd6
JL
17308 else if (GET_CODE (XEXP (addr, 1)) == REG
17309 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
17310 addr = XEXP (addr, 1);
17311 else if (CONSTANT_P (XEXP (addr, 0)))
17312 addr = XEXP (addr, 1);
17313 else if (CONSTANT_P (XEXP (addr, 1)))
17314 addr = XEXP (addr, 0);
17315 else
17316 abort ();
17317 }
02441cd6 17318 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
17319 return addr;
17320 abort ();
17321}
17322
a6c2a102 17323void
a2369ed3 17324rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
17325{
17326 fatal_insn ("bad address", op);
17327}
c8023011 17328
ee890fe2
SS
17329#if TARGET_MACHO
17330
efdba735 17331static tree branch_island_list = 0;
ee890fe2 17332
efdba735
SH
17333/* Remember to generate a branch island for far calls to the given
17334 function. */
ee890fe2 17335
f676971a 17336static void
c4ad648e
AM
17337add_compiler_branch_island (tree label_name, tree function_name,
17338 int line_number)
ee890fe2 17339{
efdba735 17340 tree branch_island = build_tree_list (function_name, label_name);
7d60be94 17341 TREE_TYPE (branch_island) = build_int_cst (NULL_TREE, line_number);
efdba735
SH
17342 TREE_CHAIN (branch_island) = branch_island_list;
17343 branch_island_list = branch_island;
ee890fe2
SS
17344}
17345
efdba735
SH
17346#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
17347#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
17348#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
17349 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 17350
efdba735
SH
17351/* Generate far-jump branch islands for everything on the
17352 branch_island_list. Invoked immediately after the last instruction
17353 of the epilogue has been emitted; the branch-islands must be
17354 appended to, and contiguous with, the function body. Mach-O stubs
17355 are generated in machopic_output_stub(). */
ee890fe2 17356
efdba735
SH
17357static void
17358macho_branch_islands (void)
17359{
17360 char tmp_buf[512];
17361 tree branch_island;
17362
17363 for (branch_island = branch_island_list;
17364 branch_island;
17365 branch_island = TREE_CHAIN (branch_island))
17366 {
17367 const char *label =
17368 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
17369 const char *name =
11abc112 17370 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island));
efdba735
SH
17371 char name_buf[512];
17372 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
17373 if (name[0] == '*' || name[0] == '&')
17374 strcpy (name_buf, name+1);
17375 else
17376 {
17377 name_buf[0] = '_';
17378 strcpy (name_buf+1, name);
17379 }
17380 strcpy (tmp_buf, "\n");
17381 strcat (tmp_buf, label);
ee890fe2 17382#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 17383 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
93a27b7b 17384 dbxout_stabd (N_SLINE, BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 17385#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
17386 if (flag_pic)
17387 {
17388 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
17389 strcat (tmp_buf, label);
17390 strcat (tmp_buf, "_pic\n");
17391 strcat (tmp_buf, label);
17392 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
f676971a 17393
efdba735
SH
17394 strcat (tmp_buf, "\taddis r11,r11,ha16(");
17395 strcat (tmp_buf, name_buf);
17396 strcat (tmp_buf, " - ");
17397 strcat (tmp_buf, label);
17398 strcat (tmp_buf, "_pic)\n");
f676971a 17399
efdba735 17400 strcat (tmp_buf, "\tmtlr r0\n");
f676971a 17401
efdba735
SH
17402 strcat (tmp_buf, "\taddi r12,r11,lo16(");
17403 strcat (tmp_buf, name_buf);
17404 strcat (tmp_buf, " - ");
17405 strcat (tmp_buf, label);
17406 strcat (tmp_buf, "_pic)\n");
f676971a 17407
efdba735
SH
17408 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
17409 }
17410 else
17411 {
17412 strcat (tmp_buf, ":\nlis r12,hi16(");
17413 strcat (tmp_buf, name_buf);
17414 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
17415 strcat (tmp_buf, name_buf);
17416 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
17417 }
17418 output_asm_insn (tmp_buf, 0);
ee890fe2 17419#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 17420 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
93a27b7b 17421 dbxout_stabd (N_SLINE, BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 17422#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 17423 }
ee890fe2 17424
efdba735 17425 branch_island_list = 0;
ee890fe2
SS
17426}
17427
17428/* NO_PREVIOUS_DEF checks in the link list whether the function name is
17429 already there or not. */
17430
efdba735 17431static int
a2369ed3 17432no_previous_def (tree function_name)
ee890fe2 17433{
efdba735
SH
17434 tree branch_island;
17435 for (branch_island = branch_island_list;
17436 branch_island;
17437 branch_island = TREE_CHAIN (branch_island))
17438 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
17439 return 0;
17440 return 1;
17441}
17442
17443/* GET_PREV_LABEL gets the label name from the previous definition of
17444 the function. */
17445
efdba735 17446static tree
a2369ed3 17447get_prev_label (tree function_name)
ee890fe2 17448{
efdba735
SH
17449 tree branch_island;
17450 for (branch_island = branch_island_list;
17451 branch_island;
17452 branch_island = TREE_CHAIN (branch_island))
17453 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
17454 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
17455 return 0;
17456}
17457
17458/* INSN is either a function call or a millicode call. It may have an
f676971a 17459 unconditional jump in its delay slot.
ee890fe2
SS
17460
17461 CALL_DEST is the routine we are calling. */
17462
17463char *
c4ad648e
AM
17464output_call (rtx insn, rtx *operands, int dest_operand_number,
17465 int cookie_operand_number)
ee890fe2
SS
17466{
17467 static char buf[256];
efdba735
SH
17468 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
17469 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
17470 {
17471 tree labelname;
efdba735 17472 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
f676971a 17473
ee890fe2
SS
17474 if (no_previous_def (funname))
17475 {
308c142a 17476 int line_number = 0;
ee890fe2
SS
17477 rtx label_rtx = gen_label_rtx ();
17478 char *label_buf, temp_buf[256];
17479 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
17480 CODE_LABEL_NUMBER (label_rtx));
17481 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
17482 labelname = get_identifier (label_buf);
17483 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
17484 if (insn)
17485 line_number = NOTE_LINE_NUMBER (insn);
efdba735 17486 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
17487 }
17488 else
17489 labelname = get_prev_label (funname);
17490
efdba735
SH
17491 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
17492 instruction will reach 'foo', otherwise link as 'bl L42'".
17493 "L42" should be a 'branch island', that will do a far jump to
17494 'foo'. Branch islands are generated in
17495 macho_branch_islands(). */
ee890fe2 17496 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 17497 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
17498 }
17499 else
efdba735
SH
17500 sprintf (buf, "bl %%z%d", dest_operand_number);
17501 return buf;
ee890fe2
SS
17502}
17503
ee890fe2
SS
17504/* Generate PIC and indirect symbol stubs. */
17505
17506void
a2369ed3 17507machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
17508{
17509 unsigned int length;
a4f6c312
SS
17510 char *symbol_name, *lazy_ptr_name;
17511 char *local_label_0;
ee890fe2
SS
17512 static int label = 0;
17513
df56a27f 17514 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 17515 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 17516
ee890fe2 17517
ee890fe2
SS
17518 length = strlen (symb);
17519 symbol_name = alloca (length + 32);
17520 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
17521
17522 lazy_ptr_name = alloca (length + 32);
17523 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
17524
ee890fe2 17525 if (flag_pic == 2)
d3c300d2 17526 machopic_picsymbol_stub1_section ();
ee890fe2 17527 else
d3c300d2 17528 machopic_symbol_stub1_section ();
ee890fe2
SS
17529
17530 if (flag_pic == 2)
17531 {
d974312d
DJ
17532 fprintf (file, "\t.align 5\n");
17533
17534 fprintf (file, "%s:\n", stub);
17535 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
17536
876455fa
AP
17537 label++;
17538 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
17539 sprintf (local_label_0, "\"L%011d$spb\"", label);
f676971a 17540
ee890fe2
SS
17541 fprintf (file, "\tmflr r0\n");
17542 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
17543 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
17544 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
17545 lazy_ptr_name, local_label_0);
17546 fprintf (file, "\tmtlr r0\n");
3d0e2d58
SS
17547 fprintf (file, "\t%s r12,lo16(%s-%s)(r11)\n",
17548 (TARGET_64BIT ? "ldu" : "lwzu"),
ee890fe2
SS
17549 lazy_ptr_name, local_label_0);
17550 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
17551 fprintf (file, "\tbctr\n");
17552 }
17553 else
d974312d
DJ
17554 {
17555 fprintf (file, "\t.align 4\n");
17556
17557 fprintf (file, "%s:\n", stub);
17558 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
17559
17560 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
17561 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
17562 fprintf (file, "\tmtctr r12\n");
17563 fprintf (file, "\tbctr\n");
17564 }
f676971a 17565
ee890fe2
SS
17566 machopic_lazy_symbol_ptr_section ();
17567 fprintf (file, "%s:\n", lazy_ptr_name);
17568 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
49bd1d27
SS
17569 fprintf (file, "%sdyld_stub_binding_helper\n",
17570 (TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t"));
ee890fe2
SS
17571}
17572
17573/* Legitimize PIC addresses. If the address is already
17574 position-independent, we return ORIG. Newly generated
17575 position-independent addresses go into a reg. This is REG if non
17576 zero, otherwise we allocate register(s) as necessary. */
17577
c859cda6 17578#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
17579
17580rtx
f676971a 17581rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
a2369ed3 17582 rtx reg)
ee890fe2
SS
17583{
17584 rtx base, offset;
17585
17586 if (reg == NULL && ! reload_in_progress && ! reload_completed)
17587 reg = gen_reg_rtx (Pmode);
17588
17589 if (GET_CODE (orig) == CONST)
17590 {
17591 if (GET_CODE (XEXP (orig, 0)) == PLUS
17592 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
17593 return orig;
17594
17595 if (GET_CODE (XEXP (orig, 0)) == PLUS)
17596 {
2cf520bf 17597 /* Use a different reg for the intermediate value, as
a3c9585f 17598 it will be marked UNCHANGING. */
2cf520bf
GK
17599 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
17600
a4f6c312
SS
17601 base =
17602 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 17603 Pmode, reg_temp);
a4f6c312
SS
17604 offset =
17605 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
17606 Pmode, reg);
ee890fe2
SS
17607 }
17608 else
17609 abort ();
17610
17611 if (GET_CODE (offset) == CONST_INT)
17612 {
17613 if (SMALL_INT (offset))
ed8908e7 17614 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
17615 else if (! reload_in_progress && ! reload_completed)
17616 offset = force_reg (Pmode, offset);
17617 else
c859cda6
DJ
17618 {
17619 rtx mem = force_const_mem (Pmode, orig);
17620 return machopic_legitimize_pic_address (mem, Pmode, reg);
17621 }
ee890fe2 17622 }
f1c25d3b 17623 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
17624 }
17625
17626 /* Fall back on generic machopic code. */
17627 return machopic_legitimize_pic_address (orig, mode, reg);
17628}
17629
17630/* This is just a placeholder to make linking work without having to
17631 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
17632 ever needed for Darwin (not too likely!) this would have to get a
17633 real definition. */
17634
17635void
863d938c 17636toc_section (void)
ee890fe2
SS
17637{
17638}
17639
c4e18b1c
GK
17640/* Output a .machine directive for the Darwin assembler, and call
17641 the generic start_file routine. */
17642
17643static void
17644rs6000_darwin_file_start (void)
17645{
94ff898d 17646 static const struct
c4e18b1c
GK
17647 {
17648 const char *arg;
17649 const char *name;
17650 int if_set;
17651 } mapping[] = {
55dbfb48 17652 { "ppc64", "ppc64", MASK_64BIT },
c4e18b1c
GK
17653 { "970", "ppc970", MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64 },
17654 { "power4", "ppc970", 0 },
17655 { "G5", "ppc970", 0 },
17656 { "7450", "ppc7450", 0 },
17657 { "7400", "ppc7400", MASK_ALTIVEC },
17658 { "G4", "ppc7400", 0 },
17659 { "750", "ppc750", 0 },
17660 { "740", "ppc750", 0 },
17661 { "G3", "ppc750", 0 },
17662 { "604e", "ppc604e", 0 },
17663 { "604", "ppc604", 0 },
17664 { "603e", "ppc603", 0 },
17665 { "603", "ppc603", 0 },
17666 { "601", "ppc601", 0 },
17667 { NULL, "ppc", 0 } };
17668 const char *cpu_id = "";
17669 size_t i;
94ff898d 17670
c4e18b1c
GK
17671 rs6000_file_start();
17672
17673 /* Determine the argument to -mcpu=. Default to G3 if not specified. */
17674 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
17675 if (rs6000_select[i].set_arch_p && rs6000_select[i].string
17676 && rs6000_select[i].string[0] != '\0')
17677 cpu_id = rs6000_select[i].string;
17678
17679 /* Look through the mapping array. Pick the first name that either
17680 matches the argument, has a bit set in IF_SET that is also set
17681 in the target flags, or has a NULL name. */
17682
17683 i = 0;
17684 while (mapping[i].arg != NULL
17685 && strcmp (mapping[i].arg, cpu_id) != 0
17686 && (mapping[i].if_set & target_flags) == 0)
17687 i++;
17688
17689 fprintf (asm_out_file, "\t.machine %s\n", mapping[i].name);
17690}
17691
ee890fe2 17692#endif /* TARGET_MACHO */
7c262518
RH
17693
17694#if TARGET_ELF
17695static unsigned int
a2369ed3 17696rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 17697{
1ff8f81a
AM
17698 return default_section_type_flags_1 (decl, name, reloc,
17699 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 17700}
d9f6800d
RH
17701
17702/* Record an element in the table of global constructors. SYMBOL is
17703 a SYMBOL_REF of the function to be called; PRIORITY is a number
17704 between 0 and MAX_INIT_PRIORITY.
17705
17706 This differs from default_named_section_asm_out_constructor in
17707 that we have special handling for -mrelocatable. */
17708
17709static void
a2369ed3 17710rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
17711{
17712 const char *section = ".ctors";
17713 char buf[16];
17714
17715 if (priority != DEFAULT_INIT_PRIORITY)
17716 {
17717 sprintf (buf, ".ctors.%.5u",
c4ad648e
AM
17718 /* Invert the numbering so the linker puts us in the proper
17719 order; constructors are run from right to left, and the
17720 linker sorts in increasing order. */
17721 MAX_INIT_PRIORITY - priority);
d9f6800d
RH
17722 section = buf;
17723 }
17724
715bdd29
RH
17725 named_section_flags (section, SECTION_WRITE);
17726 assemble_align (POINTER_SIZE);
d9f6800d
RH
17727
17728 if (TARGET_RELOCATABLE)
17729 {
17730 fputs ("\t.long (", asm_out_file);
17731 output_addr_const (asm_out_file, symbol);
17732 fputs (")@fixup\n", asm_out_file);
17733 }
17734 else
c8af3574 17735 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
17736}
17737
17738static void
a2369ed3 17739rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
17740{
17741 const char *section = ".dtors";
17742 char buf[16];
17743
17744 if (priority != DEFAULT_INIT_PRIORITY)
17745 {
17746 sprintf (buf, ".dtors.%.5u",
c4ad648e
AM
17747 /* Invert the numbering so the linker puts us in the proper
17748 order; constructors are run from right to left, and the
17749 linker sorts in increasing order. */
17750 MAX_INIT_PRIORITY - priority);
d9f6800d
RH
17751 section = buf;
17752 }
17753
715bdd29
RH
17754 named_section_flags (section, SECTION_WRITE);
17755 assemble_align (POINTER_SIZE);
d9f6800d
RH
17756
17757 if (TARGET_RELOCATABLE)
17758 {
17759 fputs ("\t.long (", asm_out_file);
17760 output_addr_const (asm_out_file, symbol);
17761 fputs (")@fixup\n", asm_out_file);
17762 }
17763 else
c8af3574 17764 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 17765}
9739c90c
JJ
17766
17767void
a2369ed3 17768rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
17769{
17770 if (TARGET_64BIT)
17771 {
17772 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
17773 ASM_OUTPUT_LABEL (file, name);
17774 fputs (DOUBLE_INT_ASM_OP, file);
85b776df
AM
17775 rs6000_output_function_entry (file, name);
17776 fputs (",.TOC.@tocbase,0\n\t.previous\n", file);
17777 if (DOT_SYMBOLS)
9739c90c 17778 {
85b776df 17779 fputs ("\t.size\t", file);
9739c90c 17780 assemble_name (file, name);
85b776df
AM
17781 fputs (",24\n\t.type\t.", file);
17782 assemble_name (file, name);
17783 fputs (",@function\n", file);
17784 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
17785 {
17786 fputs ("\t.globl\t.", file);
17787 assemble_name (file, name);
17788 putc ('\n', file);
17789 }
9739c90c 17790 }
85b776df
AM
17791 else
17792 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
9739c90c 17793 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
85b776df
AM
17794 rs6000_output_function_entry (file, name);
17795 fputs (":\n", file);
9739c90c
JJ
17796 return;
17797 }
17798
17799 if (TARGET_RELOCATABLE
17800 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 17801 && uses_TOC ())
9739c90c
JJ
17802 {
17803 char buf[256];
17804
17805 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
17806
17807 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
17808 fprintf (file, "\t.long ");
17809 assemble_name (file, buf);
17810 putc ('-', file);
17811 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
17812 assemble_name (file, buf);
17813 putc ('\n', file);
17814 }
17815
17816 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
17817 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
17818
17819 if (DEFAULT_ABI == ABI_AIX)
17820 {
17821 const char *desc_name, *orig_name;
17822
17823 orig_name = (*targetm.strip_name_encoding) (name);
17824 desc_name = orig_name;
17825 while (*desc_name == '.')
17826 desc_name++;
17827
17828 if (TREE_PUBLIC (decl))
17829 fprintf (file, "\t.globl %s\n", desc_name);
17830
17831 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
17832 fprintf (file, "%s:\n", desc_name);
17833 fprintf (file, "\t.long %s\n", orig_name);
17834 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
17835 if (DEFAULT_ABI == ABI_AIX)
17836 fputs ("\t.long 0\n", file);
17837 fprintf (file, "\t.previous\n");
17838 }
17839 ASM_OUTPUT_LABEL (file, name);
17840}
7c262518
RH
17841#endif
17842
cbaaba19 17843#if TARGET_XCOFF
7c262518 17844static void
a2369ed3 17845rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
17846{
17847 fputs (GLOBAL_ASM_OP, stream);
17848 RS6000_OUTPUT_BASENAME (stream, name);
17849 putc ('\n', stream);
17850}
17851
17852static void
c18a5b6c
MM
17853rs6000_xcoff_asm_named_section (const char *name, unsigned int flags,
17854 tree decl ATTRIBUTE_UNUSED)
7c262518 17855{
0e5dbd9b
DE
17856 int smclass;
17857 static const char * const suffix[3] = { "PR", "RO", "RW" };
17858
17859 if (flags & SECTION_CODE)
17860 smclass = 0;
17861 else if (flags & SECTION_WRITE)
17862 smclass = 2;
17863 else
17864 smclass = 1;
17865
5b5198f7 17866 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 17867 (flags & SECTION_CODE) ? "." : "",
5b5198f7 17868 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 17869}
ae46c4e0
RH
17870
17871static void
f676971a 17872rs6000_xcoff_select_section (tree decl, int reloc,
c4ad648e 17873 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 17874{
5add3202 17875 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 17876 {
0e5dbd9b 17877 if (TREE_PUBLIC (decl))
c4ad648e 17878 read_only_data_section ();
ae46c4e0 17879 else
c4ad648e 17880 read_only_private_data_section ();
ae46c4e0
RH
17881 }
17882 else
17883 {
0e5dbd9b 17884 if (TREE_PUBLIC (decl))
c4ad648e 17885 data_section ();
ae46c4e0 17886 else
c4ad648e 17887 private_data_section ();
ae46c4e0
RH
17888 }
17889}
17890
17891static void
a2369ed3 17892rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
17893{
17894 const char *name;
ae46c4e0 17895
5b5198f7
DE
17896 /* Use select_section for private and uninitialized data. */
17897 if (!TREE_PUBLIC (decl)
17898 || DECL_COMMON (decl)
0e5dbd9b
DE
17899 || DECL_INITIAL (decl) == NULL_TREE
17900 || DECL_INITIAL (decl) == error_mark_node
17901 || (flag_zero_initialized_in_bss
17902 && initializer_zerop (DECL_INITIAL (decl))))
17903 return;
17904
17905 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17906 name = (*targetm.strip_name_encoding) (name);
17907 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 17908}
b64a1b53 17909
fb49053f
RH
17910/* Select section for constant in constant pool.
17911
17912 On RS/6000, all constants are in the private read-only data area.
17913 However, if this is being placed in the TOC it must be output as a
17914 toc entry. */
17915
b64a1b53 17916static void
f676971a 17917rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
c4ad648e 17918 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
17919{
17920 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
17921 toc_section ();
17922 else
17923 read_only_private_data_section ();
17924}
772c5265
RH
17925
17926/* Remove any trailing [DS] or the like from the symbol name. */
17927
17928static const char *
a2369ed3 17929rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
17930{
17931 size_t len;
17932 if (*name == '*')
17933 name++;
17934 len = strlen (name);
17935 if (name[len - 1] == ']')
17936 return ggc_alloc_string (name, len - 4);
17937 else
17938 return name;
17939}
17940
5add3202
DE
17941/* Section attributes. AIX is always PIC. */
17942
17943static unsigned int
a2369ed3 17944rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 17945{
5b5198f7
DE
17946 unsigned int align;
17947 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
17948
17949 /* Align to at least UNIT size. */
17950 if (flags & SECTION_CODE)
17951 align = MIN_UNITS_PER_WORD;
17952 else
17953 /* Increase alignment of large objects if not already stricter. */
17954 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
17955 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
17956 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
17957
17958 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 17959}
a5fe455b 17960
1bc7c5b6
ZW
17961/* Output at beginning of assembler file.
17962
17963 Initialize the section names for the RS/6000 at this point.
17964
17965 Specify filename, including full path, to assembler.
17966
17967 We want to go into the TOC section so at least one .toc will be emitted.
17968 Also, in order to output proper .bs/.es pairs, we need at least one static
17969 [RW] section emitted.
17970
17971 Finally, declare mcount when profiling to make the assembler happy. */
17972
17973static void
863d938c 17974rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
17975{
17976 rs6000_gen_section_name (&xcoff_bss_section_name,
17977 main_input_filename, ".bss_");
17978 rs6000_gen_section_name (&xcoff_private_data_section_name,
17979 main_input_filename, ".rw_");
17980 rs6000_gen_section_name (&xcoff_read_only_section_name,
17981 main_input_filename, ".ro_");
17982
17983 fputs ("\t.file\t", asm_out_file);
17984 output_quoted_string (asm_out_file, main_input_filename);
17985 fputc ('\n', asm_out_file);
17986 toc_section ();
17987 if (write_symbols != NO_DEBUG)
17988 private_data_section ();
17989 text_section ();
17990 if (profile_flag)
17991 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
17992 rs6000_file_start ();
17993}
17994
a5fe455b
ZW
17995/* Output at end of assembler file.
17996 On the RS/6000, referencing data should automatically pull in text. */
17997
17998static void
863d938c 17999rs6000_xcoff_file_end (void)
a5fe455b
ZW
18000{
18001 text_section ();
18002 fputs ("_section_.text:\n", asm_out_file);
18003 data_section ();
18004 fputs (TARGET_32BIT
18005 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
18006 asm_out_file);
18007}
f1384257 18008#endif /* TARGET_XCOFF */
0e5dbd9b 18009
f1384257
AM
18010#if TARGET_MACHO
18011/* Cross-module name binding. Darwin does not support overriding
7f3d8013 18012 functions at dynamic-link time. */
0e5dbd9b 18013
2bcc50d0 18014static bool
a2369ed3 18015rs6000_binds_local_p (tree decl)
0e5dbd9b 18016{
f1384257 18017 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 18018}
f1384257 18019#endif
34bb030a 18020
3c50106f
RH
18021/* Compute a (partial) cost for rtx X. Return true if the complete
18022 cost has been computed, and false if subexpressions should be
18023 scanned. In either case, *TOTAL contains the cost result. */
18024
18025static bool
1494c534 18026rs6000_rtx_costs (rtx x, int code, int outer_code, int *total)
3c50106f 18027{
f0517163
RS
18028 enum machine_mode mode = GET_MODE (x);
18029
3c50106f
RH
18030 switch (code)
18031 {
30a555d9 18032 /* On the RS/6000, if it is valid in the insn, it is free. */
3c50106f 18033 case CONST_INT:
066cd967
DE
18034 if (((outer_code == SET
18035 || outer_code == PLUS
18036 || outer_code == MINUS)
18037 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
18038 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
18039 || ((outer_code == IOR || outer_code == XOR)
18040 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
18041 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
627b6fe2
DJ
18042 || ((outer_code == DIV || outer_code == UDIV
18043 || outer_code == MOD || outer_code == UMOD)
18044 && exact_log2 (INTVAL (x)) >= 0)
066cd967
DE
18045 || (outer_code == AND
18046 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
18047 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 18048 || mask_operand (x, VOIDmode)))
066cd967
DE
18049 || outer_code == ASHIFT
18050 || outer_code == ASHIFTRT
18051 || outer_code == LSHIFTRT
18052 || outer_code == ROTATE
18053 || outer_code == ROTATERT
d5861a7a 18054 || outer_code == ZERO_EXTRACT
066cd967
DE
18055 || (outer_code == MULT
18056 && CONST_OK_FOR_LETTER_P (INTVAL (x), 'I'))
18057 || (outer_code == COMPARE
18058 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
18059 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'K'))))
18060 {
18061 *total = 0;
18062 return true;
18063 }
18064 else if ((outer_code == PLUS
18065 && reg_or_add_cint64_operand (x, VOIDmode))
18066 || (outer_code == MINUS
18067 && reg_or_sub_cint64_operand (x, VOIDmode))
18068 || ((outer_code == SET
18069 || outer_code == IOR
18070 || outer_code == XOR)
18071 && (INTVAL (x)
18072 & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0))
18073 {
18074 *total = COSTS_N_INSNS (1);
18075 return true;
18076 }
18077 /* FALLTHRU */
18078
18079 case CONST_DOUBLE:
18080 if (mode == DImode
18081 && ((outer_code == AND
18082 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
18083 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 18084 || mask64_operand (x, DImode)))
066cd967
DE
18085 || ((outer_code == IOR || outer_code == XOR)
18086 && CONST_DOUBLE_HIGH (x) == 0
18087 && (CONST_DOUBLE_LOW (x)
18088 & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0)))
18089 {
18090 *total = 0;
18091 return true;
18092 }
18093 else if (mode == DImode
18094 && (outer_code == SET
18095 || outer_code == IOR
18096 || outer_code == XOR)
18097 && CONST_DOUBLE_HIGH (x) == 0)
18098 {
18099 *total = COSTS_N_INSNS (1);
18100 return true;
18101 }
18102 /* FALLTHRU */
18103
3c50106f 18104 case CONST:
066cd967 18105 case HIGH:
3c50106f 18106 case SYMBOL_REF:
066cd967
DE
18107 case MEM:
18108 /* When optimizing for size, MEM should be slightly more expensive
18109 than generating address, e.g., (plus (reg) (const)).
c112cf2b 18110 L1 cache latency is about two instructions. */
066cd967 18111 *total = optimize_size ? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (2);
3c50106f
RH
18112 return true;
18113
30a555d9
DE
18114 case LABEL_REF:
18115 *total = 0;
18116 return true;
18117
3c50106f 18118 case PLUS:
f0517163 18119 if (mode == DFmode)
066cd967
DE
18120 {
18121 if (GET_CODE (XEXP (x, 0)) == MULT)
18122 {
18123 /* FNMA accounted in outer NEG. */
18124 if (outer_code == NEG)
18125 *total = rs6000_cost->dmul - rs6000_cost->fp;
18126 else
18127 *total = rs6000_cost->dmul;
18128 }
18129 else
18130 *total = rs6000_cost->fp;
18131 }
f0517163 18132 else if (mode == SFmode)
066cd967
DE
18133 {
18134 /* FNMA accounted in outer NEG. */
18135 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
18136 *total = 0;
18137 else
18138 *total = rs6000_cost->fp;
18139 }
938bf747
RS
18140 else if (GET_CODE (XEXP (x, 0)) == MULT)
18141 {
18142 /* The rs6000 doesn't have shift-and-add instructions. */
18143 rs6000_rtx_costs (XEXP (x, 0), MULT, PLUS, total);
18144 *total += COSTS_N_INSNS (1);
18145 }
f0517163 18146 else
066cd967
DE
18147 *total = COSTS_N_INSNS (1);
18148 return false;
3c50106f 18149
52190329 18150 case MINUS:
f0517163 18151 if (mode == DFmode)
066cd967
DE
18152 {
18153 if (GET_CODE (XEXP (x, 0)) == MULT)
18154 {
18155 /* FNMA accounted in outer NEG. */
18156 if (outer_code == NEG)
18157 *total = 0;
18158 else
18159 *total = rs6000_cost->dmul;
18160 }
18161 else
18162 *total = rs6000_cost->fp;
18163 }
f0517163 18164 else if (mode == SFmode)
066cd967
DE
18165 {
18166 /* FNMA accounted in outer NEG. */
18167 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
18168 *total = 0;
18169 else
18170 *total = rs6000_cost->fp;
18171 }
938bf747
RS
18172 else if (GET_CODE (XEXP (x, 0)) == MULT)
18173 {
18174 /* The rs6000 doesn't have shift-and-sub instructions. */
18175 rs6000_rtx_costs (XEXP (x, 0), MULT, MINUS, total);
18176 *total += COSTS_N_INSNS (1);
18177 }
f0517163 18178 else
c4ad648e 18179 *total = COSTS_N_INSNS (1);
066cd967 18180 return false;
3c50106f
RH
18181
18182 case MULT:
c9dbf840
DE
18183 if (GET_CODE (XEXP (x, 1)) == CONST_INT
18184 && CONST_OK_FOR_LETTER_P (INTVAL (XEXP (x, 1)), 'I'))
3c50106f 18185 {
8b897cfa
RS
18186 if (INTVAL (XEXP (x, 1)) >= -256
18187 && INTVAL (XEXP (x, 1)) <= 255)
06a67bdd 18188 *total = rs6000_cost->mulsi_const9;
8b897cfa 18189 else
06a67bdd 18190 *total = rs6000_cost->mulsi_const;
3c50106f 18191 }
066cd967
DE
18192 /* FMA accounted in outer PLUS/MINUS. */
18193 else if ((mode == DFmode || mode == SFmode)
18194 && (outer_code == PLUS || outer_code == MINUS))
18195 *total = 0;
f0517163 18196 else if (mode == DFmode)
06a67bdd 18197 *total = rs6000_cost->dmul;
f0517163 18198 else if (mode == SFmode)
06a67bdd 18199 *total = rs6000_cost->fp;
f0517163 18200 else if (mode == DImode)
06a67bdd 18201 *total = rs6000_cost->muldi;
8b897cfa 18202 else
06a67bdd 18203 *total = rs6000_cost->mulsi;
066cd967 18204 return false;
3c50106f
RH
18205
18206 case DIV:
18207 case MOD:
f0517163
RS
18208 if (FLOAT_MODE_P (mode))
18209 {
06a67bdd
RS
18210 *total = mode == DFmode ? rs6000_cost->ddiv
18211 : rs6000_cost->sdiv;
066cd967 18212 return false;
f0517163 18213 }
5efb1046 18214 /* FALLTHRU */
3c50106f
RH
18215
18216 case UDIV:
18217 case UMOD:
627b6fe2
DJ
18218 if (GET_CODE (XEXP (x, 1)) == CONST_INT
18219 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
18220 {
18221 if (code == DIV || code == MOD)
18222 /* Shift, addze */
18223 *total = COSTS_N_INSNS (2);
18224 else
18225 /* Shift */
18226 *total = COSTS_N_INSNS (1);
18227 }
c4ad648e 18228 else
627b6fe2
DJ
18229 {
18230 if (GET_MODE (XEXP (x, 1)) == DImode)
18231 *total = rs6000_cost->divdi;
18232 else
18233 *total = rs6000_cost->divsi;
18234 }
18235 /* Add in shift and subtract for MOD. */
18236 if (code == MOD || code == UMOD)
18237 *total += COSTS_N_INSNS (2);
066cd967 18238 return false;
3c50106f
RH
18239
18240 case FFS:
18241 *total = COSTS_N_INSNS (4);
066cd967 18242 return false;
3c50106f 18243
06a67bdd 18244 case NOT:
066cd967
DE
18245 if (outer_code == AND || outer_code == IOR || outer_code == XOR)
18246 {
18247 *total = 0;
18248 return false;
18249 }
18250 /* FALLTHRU */
18251
18252 case AND:
18253 case IOR:
18254 case XOR:
d5861a7a
DE
18255 case ZERO_EXTRACT:
18256 *total = COSTS_N_INSNS (1);
18257 return false;
18258
066cd967
DE
18259 case ASHIFT:
18260 case ASHIFTRT:
18261 case LSHIFTRT:
18262 case ROTATE:
18263 case ROTATERT:
d5861a7a 18264 /* Handle mul_highpart. */
066cd967
DE
18265 if (outer_code == TRUNCATE
18266 && GET_CODE (XEXP (x, 0)) == MULT)
18267 {
18268 if (mode == DImode)
18269 *total = rs6000_cost->muldi;
18270 else
18271 *total = rs6000_cost->mulsi;
18272 return true;
18273 }
d5861a7a
DE
18274 else if (outer_code == AND)
18275 *total = 0;
18276 else
18277 *total = COSTS_N_INSNS (1);
18278 return false;
18279
18280 case SIGN_EXTEND:
18281 case ZERO_EXTEND:
18282 if (GET_CODE (XEXP (x, 0)) == MEM)
18283 *total = 0;
18284 else
18285 *total = COSTS_N_INSNS (1);
066cd967 18286 return false;
06a67bdd 18287
066cd967
DE
18288 case COMPARE:
18289 case NEG:
18290 case ABS:
18291 if (!FLOAT_MODE_P (mode))
18292 {
18293 *total = COSTS_N_INSNS (1);
18294 return false;
18295 }
18296 /* FALLTHRU */
18297
18298 case FLOAT:
18299 case UNSIGNED_FLOAT:
18300 case FIX:
18301 case UNSIGNED_FIX:
18302 case FLOAT_EXTEND:
06a67bdd
RS
18303 case FLOAT_TRUNCATE:
18304 *total = rs6000_cost->fp;
066cd967 18305 return false;
06a67bdd
RS
18306
18307 case UNSPEC:
18308 switch (XINT (x, 1))
18309 {
18310 case UNSPEC_FRSP:
18311 *total = rs6000_cost->fp;
18312 return true;
18313
18314 default:
18315 break;
18316 }
18317 break;
18318
18319 case CALL:
18320 case IF_THEN_ELSE:
18321 if (optimize_size)
18322 {
18323 *total = COSTS_N_INSNS (1);
18324 return true;
18325 }
066cd967
DE
18326 else if (FLOAT_MODE_P (mode)
18327 && TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS)
18328 {
18329 *total = rs6000_cost->fp;
18330 return false;
18331 }
06a67bdd
RS
18332 break;
18333
c0600ecd
DE
18334 case EQ:
18335 case GTU:
18336 case LTU:
18337 if (mode == Pmode)
18338 {
18339 switch (outer_code)
18340 {
18341 case PLUS:
18342 case NEG:
18343 /* PLUS or NEG already counted so only add one more. */
18344 *total = COSTS_N_INSNS (1);
18345 break;
18346 case SET:
18347 *total = COSTS_N_INSNS (3);
18348 break;
18349 case COMPARE:
18350 *total = 0;
18351 return true;
18352 default:
18353 break;
18354 }
18355 return false;
18356 }
18357
3c50106f 18358 default:
06a67bdd 18359 break;
3c50106f 18360 }
06a67bdd
RS
18361
18362 return false;
3c50106f
RH
18363}
18364
34bb030a
DE
18365/* A C expression returning the cost of moving data from a register of class
18366 CLASS1 to one of CLASS2. */
18367
18368int
f676971a 18369rs6000_register_move_cost (enum machine_mode mode,
a2369ed3 18370 enum reg_class from, enum reg_class to)
34bb030a
DE
18371{
18372 /* Moves from/to GENERAL_REGS. */
18373 if (reg_classes_intersect_p (to, GENERAL_REGS)
18374 || reg_classes_intersect_p (from, GENERAL_REGS))
18375 {
18376 if (! reg_classes_intersect_p (to, GENERAL_REGS))
18377 from = to;
18378
18379 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
18380 return (rs6000_memory_move_cost (mode, from, 0)
18381 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
18382
c4ad648e
AM
18383 /* It's more expensive to move CR_REGS than CR0_REGS because of the
18384 shift. */
34bb030a
DE
18385 else if (from == CR_REGS)
18386 return 4;
18387
18388 else
c4ad648e 18389 /* A move will cost one instruction per GPR moved. */
34bb030a
DE
18390 return 2 * HARD_REGNO_NREGS (0, mode);
18391 }
18392
c4ad648e 18393 /* Moving between two similar registers is just one instruction. */
34bb030a
DE
18394 else if (reg_classes_intersect_p (to, from))
18395 return mode == TFmode ? 4 : 2;
18396
c4ad648e 18397 /* Everything else has to go through GENERAL_REGS. */
34bb030a 18398 else
f676971a 18399 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
34bb030a
DE
18400 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
18401}
18402
18403/* A C expressions returning the cost of moving data of MODE from a register to
18404 or from memory. */
18405
18406int
f676971a 18407rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
a2369ed3 18408 int in ATTRIBUTE_UNUSED)
34bb030a
DE
18409{
18410 if (reg_classes_intersect_p (class, GENERAL_REGS))
18411 return 4 * HARD_REGNO_NREGS (0, mode);
18412 else if (reg_classes_intersect_p (class, FLOAT_REGS))
18413 return 4 * HARD_REGNO_NREGS (32, mode);
18414 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
18415 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
18416 else
18417 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
18418}
18419
ded9bf77
AH
18420/* Return an RTX representing where to find the function value of a
18421 function returning MODE. */
18422static rtx
18423rs6000_complex_function_value (enum machine_mode mode)
18424{
18425 unsigned int regno;
18426 rtx r1, r2;
18427 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 18428 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77 18429
18f63bfa
AH
18430 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
18431 regno = FP_ARG_RETURN;
354ed18f
AH
18432 else
18433 {
18f63bfa 18434 regno = GP_ARG_RETURN;
ded9bf77 18435
18f63bfa
AH
18436 /* 32-bit is OK since it'll go in r3/r4. */
18437 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
18438 return gen_rtx_REG (mode, regno);
18439 }
18440
18f63bfa
AH
18441 if (inner_bytes >= 8)
18442 return gen_rtx_REG (mode, regno);
18443
ded9bf77
AH
18444 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
18445 const0_rtx);
18446 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 18447 GEN_INT (inner_bytes));
ded9bf77
AH
18448 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
18449}
18450
594a51fe
SS
18451/* Compose a PARALLEL for a darwin64 struct being returned by
18452 value. */
18453
18454static rtx
18455rs6000_darwin64_function_value (CUMULATIVE_ARGS *cum, tree valtype)
18456{
18457 tree f, ftype;
18458 rtx rvec[FIRST_PSEUDO_REGISTER], sub, roffset, suboff;
18459 int k = 0, bytepos, tot, elt, i, subbytepos;
18460 enum machine_mode fmode;
18461
18462 switch (TREE_CODE (valtype))
18463 {
18464 case RECORD_TYPE:
18465 for (f = TYPE_FIELDS (valtype); f ; f = TREE_CHAIN (f))
18466 if (TREE_CODE (f) == FIELD_DECL)
18467 {
18468 ftype = TREE_TYPE (f);
18469 fmode = TYPE_MODE (ftype);
18470 bytepos = int_bit_position (f) / BITS_PER_UNIT;
18471 if (USE_FP_FOR_ARG_P (cum, fmode, ftype))
18472 {
18473 sub = gen_rtx_REG (fmode, cum->fregno++);
18474 cum->sysv_gregno++;
18475 }
18476 else if (USE_ALTIVEC_FOR_ARG_P (cum, fmode, ftype, 1))
18477 {
18478 sub = gen_rtx_REG (fmode, cum->vregno++);
18479 cum->sysv_gregno++;
18480 }
18481 else if (fmode == BLKmode
18482 && (TREE_CODE (ftype) == RECORD_TYPE
18483 || TREE_CODE (ftype) == ARRAY_TYPE))
18484 sub = rs6000_darwin64_function_value (cum, ftype);
18485 else
18486 sub = gen_rtx_REG (fmode, cum->sysv_gregno++);
18487 if (sub == NULL_RTX)
18488 return sub;
18489 else if (GET_CODE (sub) == PARALLEL)
18490 {
18491 for (i = 0; i < XVECLEN (sub, 0); i++)
18492 {
18493 rtx subsub = XVECEXP (sub, 0, i);
18494
18495 suboff = XEXP (subsub, 1);
18496 subbytepos = INTVAL (suboff);
18497 subbytepos += bytepos;
18498 roffset = gen_rtx_CONST_INT (SImode, subbytepos);
18499 subsub = XEXP (subsub, 0);
18500 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, subsub, roffset);
18501 }
18502 }
18503 else
18504 {
18505 roffset = gen_rtx_CONST_INT (SImode, bytepos);
18506 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, sub, roffset);
18507 }
18508 }
18509 if (k > 0)
18510 return gen_rtx_PARALLEL (TYPE_MODE (valtype), gen_rtvec_v (k, rvec));
18511 else
18512 return NULL_RTX;
18513
18514 case ARRAY_TYPE:
18515 /* If passing by value won't work, give up. */
18516 if (int_size_in_bytes (valtype) <= 0)
18517 return NULL_RTX;
18518 ftype = TREE_TYPE (valtype);
18519 fmode = TYPE_MODE (ftype);
18520 tot = int_size_in_bytes (valtype) / int_size_in_bytes (ftype);
18521 bytepos = 0;
18522 for (elt = 0; elt < tot; ++elt)
18523 {
18524 if (USE_FP_FOR_ARG_P (cum, fmode, ftype))
18525 {
18526 sub = gen_rtx_REG (fmode, cum->fregno++);
18527 cum->sysv_gregno++;
18528 }
18529 else if (USE_ALTIVEC_FOR_ARG_P (cum, fmode, ftype, 1))
18530 {
18531 sub = gen_rtx_REG (fmode, cum->vregno++);
18532 cum->sysv_gregno++;
18533 }
18534 else if (fmode == BLKmode
18535 && (TREE_CODE (ftype) == RECORD_TYPE
18536 || TREE_CODE (ftype) == ARRAY_TYPE))
18537 sub = rs6000_darwin64_function_value (cum, ftype);
18538 else
18539 sub = gen_rtx_REG (fmode, cum->sysv_gregno++);
18540 if (sub == NULL_RTX)
18541 return sub;
18542 else if (GET_CODE (sub) == PARALLEL)
18543 {
18544 for (i = 0; i < XVECLEN (sub, 0); i++)
18545 {
18546 rtx subsub = XVECEXP (sub, 0, i);
18547
18548 suboff = XEXP (subsub, 1);
18549 subbytepos = INTVAL (suboff);
18550 subbytepos += bytepos;
18551 roffset = gen_rtx_CONST_INT (SImode, subbytepos);
18552 subsub = XEXP (subsub, 0);
18553 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, subsub, roffset);
18554 }
18555 }
18556 else
18557 {
18558 roffset = gen_rtx_CONST_INT (SImode, bytepos);
18559 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, sub, roffset);
18560 }
18561 bytepos += int_size_in_bytes (ftype);
18562 }
18563 if (k > 0)
18564 return gen_rtx_PARALLEL (TYPE_MODE (valtype), gen_rtvec_v (k, rvec));
18565 else
18566 return NULL_RTX;
18567
18568 default:
18569 abort ();
18570 }
18571}
18572
a6ebc39a
AH
18573/* Define how to find the value returned by a function.
18574 VALTYPE is the data type of the value (as a tree).
18575 If the precise function being called is known, FUNC is its FUNCTION_DECL;
18576 otherwise, FUNC is 0.
18577
18578 On the SPE, both FPs and vectors are returned in r3.
18579
18580 On RS/6000 an integer value is in r3 and a floating-point value is in
18581 fp1, unless -msoft-float. */
18582
18583rtx
18584rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
18585{
18586 enum machine_mode mode;
2a8fa26c 18587 unsigned int regno;
a6ebc39a 18588
594a51fe
SS
18589 /* Special handling for structs in darwin64. */
18590 if (rs6000_darwin64_abi
18591 && TYPE_MODE (valtype) == BLKmode
18592 && (TREE_CODE (valtype) == RECORD_TYPE
18593 || TREE_CODE (valtype) == ARRAY_TYPE))
18594 {
18595 CUMULATIVE_ARGS valcum;
18596 rtx valret;
18597
18598 valcum.sysv_gregno = GP_ARG_RETURN;
18599 valcum.fregno = FP_ARG_MIN_REG;
18600 valcum.vregno = ALTIVEC_ARG_MIN_REG;
18601 valret = rs6000_darwin64_function_value (&valcum, valtype);
18602 if (valret)
18603 return valret;
18604 /* Otherwise fall through to standard ABI rules. */
18605 }
18606
0e67400a
FJ
18607 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
18608 {
18609 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
18610 return gen_rtx_PARALLEL (DImode,
18611 gen_rtvec (2,
18612 gen_rtx_EXPR_LIST (VOIDmode,
18613 gen_rtx_REG (SImode, GP_ARG_RETURN),
18614 const0_rtx),
18615 gen_rtx_EXPR_LIST (VOIDmode,
18616 gen_rtx_REG (SImode,
18617 GP_ARG_RETURN + 1),
18618 GEN_INT (4))));
18619 }
18620
a6ebc39a
AH
18621 if ((INTEGRAL_TYPE_P (valtype)
18622 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
18623 || POINTER_TYPE_P (valtype))
b78d48dd 18624 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
18625 else
18626 mode = TYPE_MODE (valtype);
18627
4ed78545 18628 if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS)
2a8fa26c 18629 regno = FP_ARG_RETURN;
ded9bf77 18630 else if (TREE_CODE (valtype) == COMPLEX_TYPE
42ba5130 18631 && targetm.calls.split_complex_arg)
ded9bf77 18632 return rs6000_complex_function_value (mode);
44688022 18633 else if (TREE_CODE (valtype) == VECTOR_TYPE
d0b2079e 18634 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI
23ba09f0 18635 && ALTIVEC_VECTOR_MODE (mode))
a6ebc39a 18636 regno = ALTIVEC_ARG_RETURN;
18f63bfa
AH
18637 else if (TARGET_E500_DOUBLE && TARGET_HARD_FLOAT
18638 && (mode == DFmode || mode == DCmode))
18639 return spe_build_register_parallel (mode, GP_ARG_RETURN);
a6ebc39a
AH
18640 else
18641 regno = GP_ARG_RETURN;
18642
18643 return gen_rtx_REG (mode, regno);
18644}
18645
ded9bf77
AH
18646/* Define how to find the value returned by a library function
18647 assuming the value has mode MODE. */
18648rtx
18649rs6000_libcall_value (enum machine_mode mode)
18650{
18651 unsigned int regno;
18652
2e6c9641
FJ
18653 if (TARGET_32BIT && TARGET_POWERPC64 && mode == DImode)
18654 {
18655 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
18656 return gen_rtx_PARALLEL (DImode,
18657 gen_rtvec (2,
18658 gen_rtx_EXPR_LIST (VOIDmode,
18659 gen_rtx_REG (SImode, GP_ARG_RETURN),
18660 const0_rtx),
18661 gen_rtx_EXPR_LIST (VOIDmode,
18662 gen_rtx_REG (SImode,
18663 GP_ARG_RETURN + 1),
18664 GEN_INT (4))));
18665 }
18666
ded9bf77
AH
18667 if (GET_MODE_CLASS (mode) == MODE_FLOAT
18668 && TARGET_HARD_FLOAT && TARGET_FPRS)
18669 regno = FP_ARG_RETURN;
44688022
AM
18670 else if (ALTIVEC_VECTOR_MODE (mode)
18671 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
ded9bf77 18672 regno = ALTIVEC_ARG_RETURN;
42ba5130 18673 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77 18674 return rs6000_complex_function_value (mode);
18f63bfa
AH
18675 else if (TARGET_E500_DOUBLE && TARGET_HARD_FLOAT
18676 && (mode == DFmode || mode == DCmode))
18677 return spe_build_register_parallel (mode, GP_ARG_RETURN);
ded9bf77
AH
18678 else
18679 regno = GP_ARG_RETURN;
18680
18681 return gen_rtx_REG (mode, regno);
18682}
18683
d1d0c603
JJ
18684/* Define the offset between two registers, FROM to be eliminated and its
18685 replacement TO, at the start of a routine. */
18686HOST_WIDE_INT
18687rs6000_initial_elimination_offset (int from, int to)
18688{
18689 rs6000_stack_t *info = rs6000_stack_info ();
18690 HOST_WIDE_INT offset;
18691
18692 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
18693 offset = info->push_p ? 0 : -info->total_size;
18694 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
18695 offset = info->total_size;
18696 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
18697 offset = info->push_p ? info->total_size : 0;
18698 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
18699 offset = 0;
18700 else
18701 abort ();
18702
18703 return offset;
18704}
18705
62e1dfcf
NC
18706/* Return true if TYPE is of type __ev64_opaque__. */
18707
c8e4f0e9 18708static bool
a2369ed3 18709is_ev64_opaque_type (tree type)
62e1dfcf 18710{
c8e4f0e9 18711 return (TARGET_SPE
2abe3e28
AH
18712 && (type == opaque_V2SI_type_node
18713 || type == opaque_V2SF_type_node
36252949 18714 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
18715}
18716
96714395 18717static rtx
a2369ed3 18718rs6000_dwarf_register_span (rtx reg)
96714395
AH
18719{
18720 unsigned regno;
18721
4d4cbc0e
AH
18722 if (TARGET_SPE
18723 && (SPE_VECTOR_MODE (GET_MODE (reg))
18724 || (TARGET_E500_DOUBLE && GET_MODE (reg) == DFmode)))
18725 ;
18726 else
96714395
AH
18727 return NULL_RTX;
18728
18729 regno = REGNO (reg);
18730
18731 /* The duality of the SPE register size wreaks all kinds of havoc.
18732 This is a way of distinguishing r0 in 32-bits from r0 in
18733 64-bits. */
18734 return
18735 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
18736 BYTES_BIG_ENDIAN
18737 ? gen_rtvec (2,
18738 gen_rtx_REG (SImode, regno + 1200),
18739 gen_rtx_REG (SImode, regno))
18740 : gen_rtvec (2,
18741 gen_rtx_REG (SImode, regno),
18742 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
18743}
18744
93c9d1ba
AM
18745/* Map internal gcc register numbers to DWARF2 register numbers. */
18746
18747unsigned int
18748rs6000_dbx_register_number (unsigned int regno)
18749{
18750 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
18751 return regno;
18752 if (regno == MQ_REGNO)
18753 return 100;
18754 if (regno == LINK_REGISTER_REGNUM)
18755 return 108;
18756 if (regno == COUNT_REGISTER_REGNUM)
18757 return 109;
18758 if (CR_REGNO_P (regno))
18759 return regno - CR0_REGNO + 86;
18760 if (regno == XER_REGNO)
18761 return 101;
18762 if (ALTIVEC_REGNO_P (regno))
18763 return regno - FIRST_ALTIVEC_REGNO + 1124;
18764 if (regno == VRSAVE_REGNO)
18765 return 356;
18766 if (regno == VSCR_REGNO)
18767 return 67;
18768 if (regno == SPE_ACC_REGNO)
18769 return 99;
18770 if (regno == SPEFSCR_REGNO)
18771 return 612;
18772 /* SPE high reg number. We get these values of regno from
18773 rs6000_dwarf_register_span. */
18774 if (regno >= 1200 && regno < 1232)
18775 return regno;
18776
18777 abort ();
18778}
18779
93f90be6 18780/* target hook eh_return_filter_mode */
f676971a 18781static enum machine_mode
93f90be6
FJ
18782rs6000_eh_return_filter_mode (void)
18783{
18784 return TARGET_32BIT ? SImode : word_mode;
18785}
18786
f676971a
EC
18787/* Target hook for vector_mode_supported_p. */
18788static bool
18789rs6000_vector_mode_supported_p (enum machine_mode mode)
18790{
18791
18792 if (TARGET_SPE && SPE_VECTOR_MODE (mode))
18793 return true;
18794
18795 else if (TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
18796 return true;
18797
18798 else
18799 return false;
18800}
18801
17211ab5 18802#include "gt-rs6000.h"