]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
* rtl.def (RANGE_INFO, RANGE_REG, RANGE_VAR, RANGE_LIVE): Kill.
[thirdparty/gcc.git] / gcc / config / rs6000 / rs6000.c
CommitLineData
9878760c 1/* Subroutines used for code generation on IBM RS/6000.
f676971a 2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
93c9d1ba 3 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
fab3bcc3 4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
9878760c 5
5de601cf 6 This file is part of GCC.
9878760c 7
5de601cf
NC
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2, or (at your
11 option) any later version.
9878760c 12
5de601cf
NC
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
9878760c 17
5de601cf
NC
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the
20 Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
9878760c 22
956d6950 23#include "config.h"
c4d38ccb 24#include "system.h"
4977bab6
ZW
25#include "coretypes.h"
26#include "tm.h"
9878760c
RK
27#include "rtl.h"
28#include "regs.h"
29#include "hard-reg-set.h"
30#include "real.h"
31#include "insn-config.h"
32#include "conditions.h"
9878760c
RK
33#include "insn-attr.h"
34#include "flags.h"
35#include "recog.h"
9878760c 36#include "obstack.h"
9b30bae2 37#include "tree.h"
dfafc897 38#include "expr.h"
2fc1c679 39#include "optabs.h"
2a430ec1 40#include "except.h"
a7df97e6 41#include "function.h"
296b8152 42#include "output.h"
d5fa86ba 43#include "basic-block.h"
d0101753 44#include "integrate.h"
296b8152 45#include "toplev.h"
c8023011 46#include "ggc.h"
9ebbca7d
GK
47#include "hashtab.h"
48#include "tm_p.h"
672a6f42
NB
49#include "target.h"
50#include "target-def.h"
3ac88239 51#include "langhooks.h"
24ea750e 52#include "reload.h"
117dca74 53#include "cfglayout.h"
79ae11c4 54#include "sched-int.h"
cd3ce9b4 55#include "tree-gimple.h"
1bc7c5b6
ZW
56#if TARGET_XCOFF
57#include "xcoffout.h" /* get declarations of xcoff_*_section_name */
58#endif
9b30bae2 59
7509c759
MM
60#ifndef TARGET_NO_PROTOTYPE
61#define TARGET_NO_PROTOTYPE 0
62#endif
63
452a7d36
HP
64#define EASY_VECTOR_15(n) ((n) >= -16 && (n) <= 15)
65#define EASY_VECTOR_15_ADD_SELF(n) ((n) >= 0x10 && (n) <= 0x1e \
66 && !((n) & 1))
d744e06e 67
9878760c
RK
68#define min(A,B) ((A) < (B) ? (A) : (B))
69#define max(A,B) ((A) > (B) ? (A) : (B))
70
d1d0c603
JJ
71/* Structure used to define the rs6000 stack */
72typedef struct rs6000_stack {
73 int first_gp_reg_save; /* first callee saved GP register used */
74 int first_fp_reg_save; /* first callee saved FP register used */
75 int first_altivec_reg_save; /* first callee saved AltiVec register used */
76 int lr_save_p; /* true if the link reg needs to be saved */
77 int cr_save_p; /* true if the CR reg needs to be saved */
78 unsigned int vrsave_mask; /* mask of vec registers to save */
79 int toc_save_p; /* true if the TOC needs to be saved */
80 int push_p; /* true if we need to allocate stack space */
81 int calls_p; /* true if the function makes any calls */
d62294f5
FJ
82 int world_save_p; /* true if we're saving *everything*:
83 r13-r31, cr, f14-f31, vrsave, v20-v31 */
d1d0c603
JJ
84 enum rs6000_abi abi; /* which ABI to use */
85 int gp_save_offset; /* offset to save GP regs from initial SP */
86 int fp_save_offset; /* offset to save FP regs from initial SP */
87 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
88 int lr_save_offset; /* offset to save LR from initial SP */
89 int cr_save_offset; /* offset to save CR from initial SP */
90 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
91 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
92 int toc_save_offset; /* offset to save the TOC pointer */
93 int varargs_save_offset; /* offset to save the varargs registers */
94 int ehrd_offset; /* offset to EH return data */
95 int reg_size; /* register size (4 or 8) */
96 int varargs_size; /* size to hold V.4 args passed in regs */
97 HOST_WIDE_INT vars_size; /* variable save area size */
98 int parm_size; /* outgoing parameter size */
99 int save_size; /* save area size */
100 int fixed_size; /* fixed size of stack frame */
101 int gp_size; /* size of saved GP registers */
102 int fp_size; /* size of saved FP registers */
103 int altivec_size; /* size of saved AltiVec registers */
104 int cr_size; /* size to hold CR if not in save_size */
105 int lr_size; /* size to hold LR if not in save_size */
106 int vrsave_size; /* size to hold VRSAVE if not in save_size */
107 int altivec_padding_size; /* size of altivec alignment padding if
108 not in save_size */
109 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
110 int spe_padding_size;
111 int toc_size; /* size to hold TOC if not in save_size */
112 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
113 int spe_64bit_regs_used;
114} rs6000_stack_t;
115
5248c961
RK
116/* Target cpu type */
117
118enum processor_type rs6000_cpu;
8e3f41e7
MM
119struct rs6000_cpu_select rs6000_select[3] =
120{
815cdc52
MM
121 /* switch name, tune arch */
122 { (const char *)0, "--with-cpu=", 1, 1 },
123 { (const char *)0, "-mcpu=", 1, 1 },
124 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 125};
5248c961 126
ec507f2d
DE
127/* Always emit branch hint bits. */
128static GTY(()) bool rs6000_always_hint;
129
130/* Schedule instructions for group formation. */
131static GTY(()) bool rs6000_sched_groups;
132
f676971a 133/* Support adjust_priority scheduler hook
79ae11c4
DN
134 and -mprioritize-restricted-insns= option. */
135const char *rs6000_sched_restricted_insns_priority_str;
136int rs6000_sched_restricted_insns_priority;
137
569fa502
DN
138/* Support for -msched-costly-dep option. */
139const char *rs6000_sched_costly_dep_str;
140enum rs6000_dependence_cost rs6000_sched_costly_dep;
141
cbe26ab8
DN
142/* Support for -minsert-sched-nops option. */
143const char *rs6000_sched_insert_nops_str;
144enum rs6000_nop_insertion rs6000_sched_insert_nops;
145
6fa3f289
ZW
146/* Size of long double */
147const char *rs6000_long_double_size_string;
148int rs6000_long_double_type_size;
149
150/* Whether -mabi=altivec has appeared */
151int rs6000_altivec_abi;
152
08b57fb3
AH
153/* Whether VRSAVE instructions should be generated. */
154int rs6000_altivec_vrsave;
155
156/* String from -mvrsave= option. */
157const char *rs6000_altivec_vrsave_string;
158
a3170dc6
AH
159/* Nonzero if we want SPE ABI extensions. */
160int rs6000_spe_abi;
161
162/* Whether isel instructions should be generated. */
163int rs6000_isel;
164
993f19a8
AH
165/* Whether SPE simd instructions should be generated. */
166int rs6000_spe;
167
5da702b1
AH
168/* Nonzero if floating point operations are done in the GPRs. */
169int rs6000_float_gprs = 0;
170
171/* String from -mfloat-gprs=. */
172const char *rs6000_float_gprs_string;
a3170dc6
AH
173
174/* String from -misel=. */
175const char *rs6000_isel_string;
176
993f19a8
AH
177/* String from -mspe=. */
178const char *rs6000_spe_string;
179
a0ab749a 180/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 181static GTY(()) int common_mode_defined;
c81bebd7 182
9878760c
RK
183/* Save information from a "cmpxx" operation until the branch or scc is
184 emitted. */
9878760c
RK
185rtx rs6000_compare_op0, rs6000_compare_op1;
186int rs6000_compare_fp_p;
874a0744 187
874a0744
MM
188/* Label number of label created for -mrelocatable, to call to so we can
189 get the address of the GOT section */
190int rs6000_pic_labelno;
c81bebd7 191
b91da81f 192#ifdef USING_ELFOS_H
c81bebd7 193/* Which abi to adhere to */
9739c90c 194const char *rs6000_abi_name;
d9407988
MM
195
196/* Semantics of the small data area */
197enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
198
199/* Which small data model to use */
815cdc52 200const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
201
202/* Counter for labels which are to be placed in .fixup. */
203int fixuplabelno = 0;
874a0744 204#endif
4697a36c 205
c4501e62
JJ
206/* Bit size of immediate TLS offsets and string from which it is decoded. */
207int rs6000_tls_size = 32;
208const char *rs6000_tls_size_string;
209
b6c9286a
MM
210/* ABI enumeration available for subtarget to use. */
211enum rs6000_abi rs6000_current_abi;
212
0ac081f6
AH
213/* ABI string from -mabi= option. */
214const char *rs6000_abi_string;
215
85b776df
AM
216/* Whether to use variant of AIX ABI for PowerPC64 Linux. */
217int dot_symbols;
218
38c1f2d7 219/* Debug flags */
815cdc52 220const char *rs6000_debug_name;
38c1f2d7
MM
221int rs6000_debug_stack; /* debug stack applications */
222int rs6000_debug_arg; /* debug argument handling */
223
0d1fbc8c
AH
224/* Value is TRUE if register/mode pair is accepatable. */
225bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
226
6035d635 227/* Opaque types. */
2abe3e28 228static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 229static GTY(()) tree opaque_V2SF_type_node;
6035d635 230static GTY(()) tree opaque_p_V2SI_type_node;
4a5eab38
PB
231static GTY(()) tree V16QI_type_node;
232static GTY(()) tree V2SI_type_node;
233static GTY(()) tree V2SF_type_node;
234static GTY(()) tree V4HI_type_node;
235static GTY(()) tree V4SI_type_node;
236static GTY(()) tree V4SF_type_node;
237static GTY(()) tree V8HI_type_node;
238static GTY(()) tree unsigned_V16QI_type_node;
239static GTY(()) tree unsigned_V8HI_type_node;
240static GTY(()) tree unsigned_V4SI_type_node;
8bb418a3
ZL
241static GTY(()) tree bool_char_type_node; /* __bool char */
242static GTY(()) tree bool_short_type_node; /* __bool short */
243static GTY(()) tree bool_int_type_node; /* __bool int */
244static GTY(()) tree pixel_type_node; /* __pixel */
245static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */
246static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */
247static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */
248static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */
249
250int rs6000_warn_altivec_long = 1; /* On by default. */
251const char *rs6000_warn_altivec_long_switch;
252
57ac7be9
AM
253const char *rs6000_traceback_name;
254static enum {
255 traceback_default = 0,
256 traceback_none,
257 traceback_part,
258 traceback_full
259} rs6000_traceback;
260
38c1f2d7
MM
261/* Flag to say the TOC is initialized */
262int toc_initialized;
9ebbca7d 263char toc_label_name[10];
38c1f2d7 264
9ebbca7d 265/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 266static GTY(()) int rs6000_sr_alias_set;
c8023011 267
a5c76ee6
ZW
268/* Call distance, overridden by -mlongcall and #pragma longcall(1).
269 The only place that looks at this is rs6000_set_default_type_attributes;
270 everywhere else should rely on the presence or absence of a longcall
271 attribute on the function declaration. */
272int rs6000_default_long_calls;
273const char *rs6000_longcall_switch;
274
a3c9585f
KH
275/* Control alignment for fields within structures. */
276/* String from -malign-XXXXX. */
025d9908
KH
277const char *rs6000_alignment_string;
278int rs6000_alignment_flags;
279
a3170dc6
AH
280struct builtin_description
281{
282 /* mask is not const because we're going to alter it below. This
283 nonsense will go away when we rewrite the -march infrastructure
284 to give us more target flag bits. */
285 unsigned int mask;
286 const enum insn_code icode;
287 const char *const name;
288 const enum rs6000_builtins code;
289};
8b897cfa
RS
290\f
291/* Target cpu costs. */
292
293struct processor_costs {
294 const int mulsi; /* cost of SImode multiplication. */
295 const int mulsi_const; /* cost of SImode multiplication by constant. */
296 const int mulsi_const9; /* cost of SImode mult by short constant. */
297 const int muldi; /* cost of DImode multiplication. */
298 const int divsi; /* cost of SImode division. */
299 const int divdi; /* cost of DImode division. */
f0517163
RS
300 const int fp; /* cost of simple SFmode and DFmode insns. */
301 const int dmul; /* cost of DFmode multiplication (and fmadd). */
302 const int sdiv; /* cost of SFmode division (fdivs). */
303 const int ddiv; /* cost of DFmode division (fdiv). */
8b897cfa
RS
304};
305
306const struct processor_costs *rs6000_cost;
307
308/* Processor costs (relative to an add) */
309
310/* Instruction size costs on 32bit processors. */
311static const
312struct processor_costs size32_cost = {
06a67bdd
RS
313 COSTS_N_INSNS (1), /* mulsi */
314 COSTS_N_INSNS (1), /* mulsi_const */
315 COSTS_N_INSNS (1), /* mulsi_const9 */
316 COSTS_N_INSNS (1), /* muldi */
317 COSTS_N_INSNS (1), /* divsi */
318 COSTS_N_INSNS (1), /* divdi */
319 COSTS_N_INSNS (1), /* fp */
320 COSTS_N_INSNS (1), /* dmul */
321 COSTS_N_INSNS (1), /* sdiv */
322 COSTS_N_INSNS (1), /* ddiv */
8b897cfa
RS
323};
324
325/* Instruction size costs on 64bit processors. */
326static const
327struct processor_costs size64_cost = {
06a67bdd
RS
328 COSTS_N_INSNS (1), /* mulsi */
329 COSTS_N_INSNS (1), /* mulsi_const */
330 COSTS_N_INSNS (1), /* mulsi_const9 */
331 COSTS_N_INSNS (1), /* muldi */
332 COSTS_N_INSNS (1), /* divsi */
333 COSTS_N_INSNS (1), /* divdi */
334 COSTS_N_INSNS (1), /* fp */
335 COSTS_N_INSNS (1), /* dmul */
336 COSTS_N_INSNS (1), /* sdiv */
337 COSTS_N_INSNS (1), /* ddiv */
8b897cfa
RS
338};
339
340/* Instruction costs on RIOS1 processors. */
341static const
342struct processor_costs rios1_cost = {
06a67bdd
RS
343 COSTS_N_INSNS (5), /* mulsi */
344 COSTS_N_INSNS (4), /* mulsi_const */
345 COSTS_N_INSNS (3), /* mulsi_const9 */
346 COSTS_N_INSNS (5), /* muldi */
347 COSTS_N_INSNS (19), /* divsi */
348 COSTS_N_INSNS (19), /* divdi */
349 COSTS_N_INSNS (2), /* fp */
350 COSTS_N_INSNS (2), /* dmul */
351 COSTS_N_INSNS (19), /* sdiv */
352 COSTS_N_INSNS (19), /* ddiv */
8b897cfa
RS
353};
354
355/* Instruction costs on RIOS2 processors. */
356static const
357struct processor_costs rios2_cost = {
06a67bdd
RS
358 COSTS_N_INSNS (2), /* mulsi */
359 COSTS_N_INSNS (2), /* mulsi_const */
360 COSTS_N_INSNS (2), /* mulsi_const9 */
361 COSTS_N_INSNS (2), /* muldi */
362 COSTS_N_INSNS (13), /* divsi */
363 COSTS_N_INSNS (13), /* divdi */
364 COSTS_N_INSNS (2), /* fp */
365 COSTS_N_INSNS (2), /* dmul */
366 COSTS_N_INSNS (17), /* sdiv */
367 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
368};
369
370/* Instruction costs on RS64A processors. */
371static const
372struct processor_costs rs64a_cost = {
06a67bdd
RS
373 COSTS_N_INSNS (20), /* mulsi */
374 COSTS_N_INSNS (12), /* mulsi_const */
375 COSTS_N_INSNS (8), /* mulsi_const9 */
376 COSTS_N_INSNS (34), /* muldi */
377 COSTS_N_INSNS (65), /* divsi */
378 COSTS_N_INSNS (67), /* divdi */
379 COSTS_N_INSNS (4), /* fp */
380 COSTS_N_INSNS (4), /* dmul */
381 COSTS_N_INSNS (31), /* sdiv */
382 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
383};
384
385/* Instruction costs on MPCCORE processors. */
386static const
387struct processor_costs mpccore_cost = {
06a67bdd
RS
388 COSTS_N_INSNS (2), /* mulsi */
389 COSTS_N_INSNS (2), /* mulsi_const */
390 COSTS_N_INSNS (2), /* mulsi_const9 */
391 COSTS_N_INSNS (2), /* muldi */
392 COSTS_N_INSNS (6), /* divsi */
393 COSTS_N_INSNS (6), /* divdi */
394 COSTS_N_INSNS (4), /* fp */
395 COSTS_N_INSNS (5), /* dmul */
396 COSTS_N_INSNS (10), /* sdiv */
397 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
398};
399
400/* Instruction costs on PPC403 processors. */
401static const
402struct processor_costs ppc403_cost = {
06a67bdd
RS
403 COSTS_N_INSNS (4), /* mulsi */
404 COSTS_N_INSNS (4), /* mulsi_const */
405 COSTS_N_INSNS (4), /* mulsi_const9 */
406 COSTS_N_INSNS (4), /* muldi */
407 COSTS_N_INSNS (33), /* divsi */
408 COSTS_N_INSNS (33), /* divdi */
409 COSTS_N_INSNS (11), /* fp */
410 COSTS_N_INSNS (11), /* dmul */
411 COSTS_N_INSNS (11), /* sdiv */
412 COSTS_N_INSNS (11), /* ddiv */
8b897cfa
RS
413};
414
415/* Instruction costs on PPC405 processors. */
416static const
417struct processor_costs ppc405_cost = {
06a67bdd
RS
418 COSTS_N_INSNS (5), /* mulsi */
419 COSTS_N_INSNS (4), /* mulsi_const */
420 COSTS_N_INSNS (3), /* mulsi_const9 */
421 COSTS_N_INSNS (5), /* muldi */
422 COSTS_N_INSNS (35), /* divsi */
423 COSTS_N_INSNS (35), /* divdi */
424 COSTS_N_INSNS (11), /* fp */
425 COSTS_N_INSNS (11), /* dmul */
426 COSTS_N_INSNS (11), /* sdiv */
427 COSTS_N_INSNS (11), /* ddiv */
8b897cfa
RS
428};
429
430/* Instruction costs on PPC440 processors. */
431static const
432struct processor_costs ppc440_cost = {
06a67bdd
RS
433 COSTS_N_INSNS (3), /* mulsi */
434 COSTS_N_INSNS (2), /* mulsi_const */
435 COSTS_N_INSNS (2), /* mulsi_const9 */
436 COSTS_N_INSNS (3), /* muldi */
437 COSTS_N_INSNS (34), /* divsi */
438 COSTS_N_INSNS (34), /* divdi */
439 COSTS_N_INSNS (5), /* fp */
440 COSTS_N_INSNS (5), /* dmul */
441 COSTS_N_INSNS (19), /* sdiv */
442 COSTS_N_INSNS (33), /* ddiv */
8b897cfa
RS
443};
444
445/* Instruction costs on PPC601 processors. */
446static const
447struct processor_costs ppc601_cost = {
06a67bdd
RS
448 COSTS_N_INSNS (5), /* mulsi */
449 COSTS_N_INSNS (5), /* mulsi_const */
450 COSTS_N_INSNS (5), /* mulsi_const9 */
451 COSTS_N_INSNS (5), /* muldi */
452 COSTS_N_INSNS (36), /* divsi */
453 COSTS_N_INSNS (36), /* divdi */
454 COSTS_N_INSNS (4), /* fp */
455 COSTS_N_INSNS (5), /* dmul */
456 COSTS_N_INSNS (17), /* sdiv */
457 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
458};
459
460/* Instruction costs on PPC603 processors. */
461static const
462struct processor_costs ppc603_cost = {
06a67bdd
RS
463 COSTS_N_INSNS (5), /* mulsi */
464 COSTS_N_INSNS (3), /* mulsi_const */
465 COSTS_N_INSNS (2), /* mulsi_const9 */
466 COSTS_N_INSNS (5), /* muldi */
467 COSTS_N_INSNS (37), /* divsi */
468 COSTS_N_INSNS (37), /* divdi */
469 COSTS_N_INSNS (3), /* fp */
470 COSTS_N_INSNS (4), /* dmul */
471 COSTS_N_INSNS (18), /* sdiv */
472 COSTS_N_INSNS (33), /* ddiv */
8b897cfa
RS
473};
474
475/* Instruction costs on PPC604 processors. */
476static const
477struct processor_costs ppc604_cost = {
06a67bdd
RS
478 COSTS_N_INSNS (4), /* mulsi */
479 COSTS_N_INSNS (4), /* mulsi_const */
480 COSTS_N_INSNS (4), /* mulsi_const9 */
481 COSTS_N_INSNS (4), /* muldi */
482 COSTS_N_INSNS (20), /* divsi */
483 COSTS_N_INSNS (20), /* divdi */
484 COSTS_N_INSNS (3), /* fp */
485 COSTS_N_INSNS (3), /* dmul */
486 COSTS_N_INSNS (18), /* sdiv */
487 COSTS_N_INSNS (32), /* ddiv */
8b897cfa
RS
488};
489
490/* Instruction costs on PPC604e processors. */
491static const
492struct processor_costs ppc604e_cost = {
06a67bdd
RS
493 COSTS_N_INSNS (2), /* mulsi */
494 COSTS_N_INSNS (2), /* mulsi_const */
495 COSTS_N_INSNS (2), /* mulsi_const9 */
496 COSTS_N_INSNS (2), /* muldi */
497 COSTS_N_INSNS (20), /* divsi */
498 COSTS_N_INSNS (20), /* divdi */
499 COSTS_N_INSNS (3), /* fp */
500 COSTS_N_INSNS (3), /* dmul */
501 COSTS_N_INSNS (18), /* sdiv */
502 COSTS_N_INSNS (32), /* ddiv */
8b897cfa
RS
503};
504
f0517163 505/* Instruction costs on PPC620 processors. */
8b897cfa
RS
506static const
507struct processor_costs ppc620_cost = {
06a67bdd
RS
508 COSTS_N_INSNS (5), /* mulsi */
509 COSTS_N_INSNS (4), /* mulsi_const */
510 COSTS_N_INSNS (3), /* mulsi_const9 */
511 COSTS_N_INSNS (7), /* muldi */
512 COSTS_N_INSNS (21), /* divsi */
513 COSTS_N_INSNS (37), /* divdi */
514 COSTS_N_INSNS (3), /* fp */
515 COSTS_N_INSNS (3), /* dmul */
516 COSTS_N_INSNS (18), /* sdiv */
517 COSTS_N_INSNS (32), /* ddiv */
f0517163
RS
518};
519
520/* Instruction costs on PPC630 processors. */
521static const
522struct processor_costs ppc630_cost = {
06a67bdd
RS
523 COSTS_N_INSNS (5), /* mulsi */
524 COSTS_N_INSNS (4), /* mulsi_const */
525 COSTS_N_INSNS (3), /* mulsi_const9 */
526 COSTS_N_INSNS (7), /* muldi */
527 COSTS_N_INSNS (21), /* divsi */
528 COSTS_N_INSNS (37), /* divdi */
529 COSTS_N_INSNS (3), /* fp */
530 COSTS_N_INSNS (3), /* dmul */
531 COSTS_N_INSNS (17), /* sdiv */
532 COSTS_N_INSNS (21), /* ddiv */
8b897cfa
RS
533};
534
535/* Instruction costs on PPC750 and PPC7400 processors. */
536static const
537struct processor_costs ppc750_cost = {
06a67bdd
RS
538 COSTS_N_INSNS (5), /* mulsi */
539 COSTS_N_INSNS (3), /* mulsi_const */
540 COSTS_N_INSNS (2), /* mulsi_const9 */
541 COSTS_N_INSNS (5), /* muldi */
542 COSTS_N_INSNS (17), /* divsi */
543 COSTS_N_INSNS (17), /* divdi */
544 COSTS_N_INSNS (3), /* fp */
545 COSTS_N_INSNS (3), /* dmul */
546 COSTS_N_INSNS (17), /* sdiv */
547 COSTS_N_INSNS (31), /* ddiv */
8b897cfa
RS
548};
549
550/* Instruction costs on PPC7450 processors. */
551static const
552struct processor_costs ppc7450_cost = {
06a67bdd
RS
553 COSTS_N_INSNS (4), /* mulsi */
554 COSTS_N_INSNS (3), /* mulsi_const */
555 COSTS_N_INSNS (3), /* mulsi_const9 */
556 COSTS_N_INSNS (4), /* muldi */
557 COSTS_N_INSNS (23), /* divsi */
558 COSTS_N_INSNS (23), /* divdi */
559 COSTS_N_INSNS (5), /* fp */
560 COSTS_N_INSNS (5), /* dmul */
561 COSTS_N_INSNS (21), /* sdiv */
562 COSTS_N_INSNS (35), /* ddiv */
8b897cfa 563};
a3170dc6 564
8b897cfa
RS
565/* Instruction costs on PPC8540 processors. */
566static const
567struct processor_costs ppc8540_cost = {
06a67bdd
RS
568 COSTS_N_INSNS (4), /* mulsi */
569 COSTS_N_INSNS (4), /* mulsi_const */
570 COSTS_N_INSNS (4), /* mulsi_const9 */
571 COSTS_N_INSNS (4), /* muldi */
572 COSTS_N_INSNS (19), /* divsi */
573 COSTS_N_INSNS (19), /* divdi */
574 COSTS_N_INSNS (4), /* fp */
575 COSTS_N_INSNS (4), /* dmul */
576 COSTS_N_INSNS (29), /* sdiv */
577 COSTS_N_INSNS (29), /* ddiv */
8b897cfa
RS
578};
579
580/* Instruction costs on POWER4 and POWER5 processors. */
581static const
582struct processor_costs power4_cost = {
06a67bdd
RS
583 COSTS_N_INSNS (3), /* mulsi */
584 COSTS_N_INSNS (2), /* mulsi_const */
585 COSTS_N_INSNS (2), /* mulsi_const9 */
586 COSTS_N_INSNS (4), /* muldi */
587 COSTS_N_INSNS (18), /* divsi */
588 COSTS_N_INSNS (34), /* divdi */
589 COSTS_N_INSNS (3), /* fp */
590 COSTS_N_INSNS (3), /* dmul */
591 COSTS_N_INSNS (17), /* sdiv */
592 COSTS_N_INSNS (17), /* ddiv */
8b897cfa
RS
593};
594
595\f
a2369ed3
DJ
596static bool rs6000_function_ok_for_sibcall (tree, tree);
597static int num_insns_constant_wide (HOST_WIDE_INT);
598static void validate_condition_mode (enum rtx_code, enum machine_mode);
599static rtx rs6000_generate_compare (enum rtx_code);
600static void rs6000_maybe_dead (rtx);
601static void rs6000_emit_stack_tie (void);
602static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
603static rtx spe_synthesize_frame_save (rtx);
604static bool spe_func_has_64bit_regs_p (void);
b20a9cca 605static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 606 int, HOST_WIDE_INT);
a2369ed3
DJ
607static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
608static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
609static unsigned rs6000_hash_constant (rtx);
610static unsigned toc_hash_function (const void *);
611static int toc_hash_eq (const void *, const void *);
612static int constant_pool_expr_1 (rtx, int *, int *);
613static bool constant_pool_expr_p (rtx);
614static bool toc_relative_expr_p (rtx);
615static bool legitimate_small_data_p (enum machine_mode, rtx);
a2369ed3
DJ
616static bool legitimate_indexed_address_p (rtx, int);
617static bool legitimate_indirect_address_p (rtx, int);
4c81e946 618static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
619static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
620static struct machine_function * rs6000_init_machine_status (void);
621static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 622#ifdef HAVE_GAS_HIDDEN
a2369ed3 623static void rs6000_assemble_visibility (tree, int);
5add3202 624#endif
a2369ed3
DJ
625static int rs6000_ra_ever_killed (void);
626static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
8bb418a3 627static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
76d2b81d 628static void rs6000_eliminate_indexed_memrefs (rtx operands[2]);
f18eca82 629static const char *rs6000_mangle_fundamental_type (tree);
b86fe7b4 630extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
631static void rs6000_set_default_type_attributes (tree);
632static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
633static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
634static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
635 tree);
a2369ed3 636static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 637static bool rs6000_return_in_memory (tree, tree);
a2369ed3 638static void rs6000_file_start (void);
7c262518 639#if TARGET_ELF
a2369ed3
DJ
640static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
641static void rs6000_elf_asm_out_constructor (rtx, int);
642static void rs6000_elf_asm_out_destructor (rtx, int);
643static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
644static void rs6000_elf_unique_section (tree, int);
645static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 646 unsigned HOST_WIDE_INT);
a56d7372 647static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 648 ATTRIBUTE_UNUSED;
a2369ed3 649static bool rs6000_elf_in_small_data_p (tree);
7c262518 650#endif
cbaaba19 651#if TARGET_XCOFF
a2369ed3
DJ
652static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
653static void rs6000_xcoff_asm_named_section (const char *, unsigned int);
654static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
655static void rs6000_xcoff_unique_section (tree, int);
656static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 657 unsigned HOST_WIDE_INT);
a2369ed3
DJ
658static const char * rs6000_xcoff_strip_name_encoding (const char *);
659static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
660static void rs6000_xcoff_file_start (void);
661static void rs6000_xcoff_file_end (void);
f1384257
AM
662#endif
663#if TARGET_MACHO
a2369ed3 664static bool rs6000_binds_local_p (tree);
f1384257 665#endif
a2369ed3
DJ
666static int rs6000_variable_issue (FILE *, int, rtx, int);
667static bool rs6000_rtx_costs (rtx, int, int, int *);
668static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 669static bool is_microcoded_insn (rtx);
79ae11c4 670static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
671static bool is_cracked_insn (rtx);
672static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
673static int rs6000_adjust_priority (rtx, int);
674static int rs6000_issue_rate (void);
569fa502 675static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
676static rtx get_next_active_insn (rtx, rtx);
677static bool insn_terminates_group_p (rtx , enum group_termination);
678static bool is_costly_group (rtx *, rtx);
679static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
680static int redefine_groups (FILE *, int, rtx, rtx);
681static int pad_groups (FILE *, int, rtx, rtx);
682static void rs6000_sched_finish (FILE *, int);
a2369ed3
DJ
683static int rs6000_use_sched_lookahead (void);
684
685static void rs6000_init_builtins (void);
686static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
687static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
688static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
689static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
690static void altivec_init_builtins (void);
691static void rs6000_common_init_builtins (void);
c15c90bb 692static void rs6000_init_libfuncs (void);
a2369ed3 693
b20a9cca
AM
694static void enable_mask_for_builtins (struct builtin_description *, int,
695 enum rs6000_builtins,
696 enum rs6000_builtins);
7c62e993 697static tree build_opaque_vector_type (tree, int);
a2369ed3
DJ
698static void spe_init_builtins (void);
699static rtx spe_expand_builtin (tree, rtx, bool *);
61bea3b0 700static rtx spe_expand_stv_builtin (enum insn_code, tree);
a2369ed3
DJ
701static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
702static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
703static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
704static rs6000_stack_t *rs6000_stack_info (void);
705static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
706
707static rtx altivec_expand_builtin (tree, rtx, bool *);
708static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
709static rtx altivec_expand_st_builtin (tree, rtx, bool *);
710static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
711static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
f676971a 712static rtx altivec_expand_predicate_builtin (enum insn_code,
a2369ed3 713 const char *, tree, rtx);
b4a62fa0 714static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
715static rtx altivec_expand_stv_builtin (enum insn_code, tree);
716static void rs6000_parse_abi_options (void);
717static void rs6000_parse_alignment_option (void);
718static void rs6000_parse_tls_size_option (void);
5da702b1 719static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
720static int first_altivec_reg_to_save (void);
721static unsigned int compute_vrsave_mask (void);
d62294f5 722static void compute_save_world_info(rs6000_stack_t *info_ptr);
a2369ed3
DJ
723static void is_altivec_return_reg (rtx, void *);
724static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
725int easy_vector_constant (rtx, enum machine_mode);
726static int easy_vector_same (rtx, enum machine_mode);
452a7d36 727static int easy_vector_splat_const (int, enum machine_mode);
a2369ed3
DJ
728static bool is_ev64_opaque_type (tree);
729static rtx rs6000_dwarf_register_span (rtx);
730static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
731static rtx rs6000_tls_get_addr (void);
732static rtx rs6000_got_sym (void);
733static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
734static const char *rs6000_get_some_local_dynamic_name (void);
735static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 736static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 737static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 738 enum machine_mode, tree);
ec6376ab 739static rtx rs6000_mixed_function_arg (enum machine_mode, tree, int);
b1917422 740static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
c6e8c921
GK
741static void setup_incoming_varargs (CUMULATIVE_ARGS *,
742 enum machine_mode, tree,
743 int *, int);
8cd5a4e0
RH
744static bool rs6000_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
745 tree, bool);
efdba735
SH
746#if TARGET_MACHO
747static void macho_branch_islands (void);
748static void add_compiler_branch_island (tree, tree, int);
749static int no_previous_def (tree function_name);
750static tree get_prev_label (tree function_name);
751#endif
752
c35d187f 753static tree rs6000_build_builtin_va_list (void);
23a60a04 754static tree rs6000_gimplify_va_arg (tree, tree, tree *, tree *);
fe984136 755static bool rs6000_must_pass_in_stack (enum machine_mode, tree);
f676971a 756static bool rs6000_vector_mode_supported_p (enum machine_mode);
17211ab5 757
93f90be6
FJ
758static enum machine_mode rs6000_eh_return_filter_mode (void);
759
17211ab5
GK
760/* Hash table stuff for keeping track of TOC entries. */
761
762struct toc_hash_struct GTY(())
763{
764 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
765 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
766 rtx key;
767 enum machine_mode key_mode;
768 int labelno;
769};
770
771static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
772\f
773/* Default register names. */
774char rs6000_reg_names[][8] =
775{
802a0058
MM
776 "0", "1", "2", "3", "4", "5", "6", "7",
777 "8", "9", "10", "11", "12", "13", "14", "15",
778 "16", "17", "18", "19", "20", "21", "22", "23",
779 "24", "25", "26", "27", "28", "29", "30", "31",
780 "0", "1", "2", "3", "4", "5", "6", "7",
781 "8", "9", "10", "11", "12", "13", "14", "15",
782 "16", "17", "18", "19", "20", "21", "22", "23",
783 "24", "25", "26", "27", "28", "29", "30", "31",
784 "mq", "lr", "ctr","ap",
785 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
786 "xer",
787 /* AltiVec registers. */
0cd5e3a1
AH
788 "0", "1", "2", "3", "4", "5", "6", "7",
789 "8", "9", "10", "11", "12", "13", "14", "15",
790 "16", "17", "18", "19", "20", "21", "22", "23",
791 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
792 "vrsave", "vscr",
793 /* SPE registers. */
794 "spe_acc", "spefscr"
c81bebd7
MM
795};
796
797#ifdef TARGET_REGNAMES
8b60264b 798static const char alt_reg_names[][8] =
c81bebd7 799{
802a0058
MM
800 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
801 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
802 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
803 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
804 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
805 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
806 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
807 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
808 "mq", "lr", "ctr", "ap",
809 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 810 "xer",
59a4c851 811 /* AltiVec registers. */
0ac081f6 812 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
813 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
814 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
815 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
816 "vrsave", "vscr",
817 /* SPE registers. */
818 "spe_acc", "spefscr"
c81bebd7
MM
819};
820#endif
9878760c 821\f
daf11973
MM
822#ifndef MASK_STRICT_ALIGN
823#define MASK_STRICT_ALIGN 0
824#endif
ffcfcb5f
AM
825#ifndef TARGET_PROFILE_KERNEL
826#define TARGET_PROFILE_KERNEL 0
827#endif
3961e8fe
RH
828
829/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
830#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
831
832/* Return 1 for a symbol ref for a thread-local storage symbol. */
833#define RS6000_SYMBOL_REF_TLS_P(RTX) \
834 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
835\f
836/* Initialize the GCC target structure. */
91d231cb
JM
837#undef TARGET_ATTRIBUTE_TABLE
838#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
839#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
840#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 841
301d03af
RS
842#undef TARGET_ASM_ALIGNED_DI_OP
843#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
844
845/* Default unaligned ops are only provided for ELF. Find the ops needed
846 for non-ELF systems. */
847#ifndef OBJECT_FORMAT_ELF
cbaaba19 848#if TARGET_XCOFF
ae6c1efd 849/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
850 64-bit targets. */
851#undef TARGET_ASM_UNALIGNED_HI_OP
852#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
853#undef TARGET_ASM_UNALIGNED_SI_OP
854#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
855#undef TARGET_ASM_UNALIGNED_DI_OP
856#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
857#else
858/* For Darwin. */
859#undef TARGET_ASM_UNALIGNED_HI_OP
860#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
861#undef TARGET_ASM_UNALIGNED_SI_OP
862#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
49bd1d27
SS
863#undef TARGET_ASM_UNALIGNED_DI_OP
864#define TARGET_ASM_UNALIGNED_DI_OP "\t.quad\t"
865#undef TARGET_ASM_ALIGNED_DI_OP
866#define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
301d03af
RS
867#endif
868#endif
869
870/* This hook deals with fixups for relocatable code and DI-mode objects
871 in 64-bit code. */
872#undef TARGET_ASM_INTEGER
873#define TARGET_ASM_INTEGER rs6000_assemble_integer
874
93638d7a
AM
875#ifdef HAVE_GAS_HIDDEN
876#undef TARGET_ASM_ASSEMBLE_VISIBILITY
877#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
878#endif
879
c4501e62
JJ
880#undef TARGET_HAVE_TLS
881#define TARGET_HAVE_TLS HAVE_AS_TLS
882
883#undef TARGET_CANNOT_FORCE_CONST_MEM
884#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
885
08c148a8
NB
886#undef TARGET_ASM_FUNCTION_PROLOGUE
887#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
888#undef TARGET_ASM_FUNCTION_EPILOGUE
889#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
890
b54cf83a
DE
891#undef TARGET_SCHED_VARIABLE_ISSUE
892#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
893
c237e94a
ZW
894#undef TARGET_SCHED_ISSUE_RATE
895#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
896#undef TARGET_SCHED_ADJUST_COST
897#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
898#undef TARGET_SCHED_ADJUST_PRIORITY
899#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
f676971a 900#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
569fa502 901#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
902#undef TARGET_SCHED_FINISH
903#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 904
be12c2b0
VM
905#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
906#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
907
0ac081f6
AH
908#undef TARGET_INIT_BUILTINS
909#define TARGET_INIT_BUILTINS rs6000_init_builtins
910
911#undef TARGET_EXPAND_BUILTIN
912#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
913
f18eca82
ZL
914#undef TARGET_MANGLE_FUNDAMENTAL_TYPE
915#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
916
c15c90bb
ZW
917#undef TARGET_INIT_LIBFUNCS
918#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
919
f1384257 920#if TARGET_MACHO
0e5dbd9b
DE
921#undef TARGET_BINDS_LOCAL_P
922#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 923#endif
0e5dbd9b 924
3961e8fe
RH
925#undef TARGET_ASM_OUTPUT_MI_THUNK
926#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
927
3961e8fe 928#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 929#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 930
4977bab6
ZW
931#undef TARGET_FUNCTION_OK_FOR_SIBCALL
932#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
933
3c50106f
RH
934#undef TARGET_RTX_COSTS
935#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
936#undef TARGET_ADDRESS_COST
937#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 938
c8e4f0e9
AH
939#undef TARGET_VECTOR_OPAQUE_P
940#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 941
96714395
AH
942#undef TARGET_DWARF_REGISTER_SPAN
943#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
944
c6e8c921
GK
945/* On rs6000, function arguments are promoted, as are function return
946 values. */
947#undef TARGET_PROMOTE_FUNCTION_ARGS
948#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
949#undef TARGET_PROMOTE_FUNCTION_RETURN
950#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
951
c6e8c921
GK
952#undef TARGET_RETURN_IN_MEMORY
953#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
954
955#undef TARGET_SETUP_INCOMING_VARARGS
956#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
957
958/* Always strict argument naming on rs6000. */
959#undef TARGET_STRICT_ARGUMENT_NAMING
960#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
961#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
962#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
963#undef TARGET_SPLIT_COMPLEX_ARG
964#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
fe984136
RH
965#undef TARGET_MUST_PASS_IN_STACK
966#define TARGET_MUST_PASS_IN_STACK rs6000_must_pass_in_stack
8cd5a4e0
RH
967#undef TARGET_PASS_BY_REFERENCE
968#define TARGET_PASS_BY_REFERENCE rs6000_pass_by_reference
c6e8c921 969
c35d187f
RH
970#undef TARGET_BUILD_BUILTIN_VA_LIST
971#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
972
cd3ce9b4
JM
973#undef TARGET_GIMPLIFY_VA_ARG_EXPR
974#define TARGET_GIMPLIFY_VA_ARG_EXPR rs6000_gimplify_va_arg
975
93f90be6
FJ
976#undef TARGET_EH_RETURN_FILTER_MODE
977#define TARGET_EH_RETURN_FILTER_MODE rs6000_eh_return_filter_mode
978
f676971a
EC
979#undef TARGET_VECTOR_MODE_SUPPORTED_P
980#define TARGET_VECTOR_MODE_SUPPORTED_P rs6000_vector_mode_supported_p
981
f6897b10 982struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 983\f
0d1fbc8c
AH
984
985/* Value is 1 if hard register REGNO can hold a value of machine-mode
986 MODE. */
987static int
988rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
989{
990 /* The GPRs can hold any mode, but values bigger than one register
991 cannot go past R31. */
992 if (INT_REGNO_P (regno))
993 return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1);
994
995 /* The float registers can only hold floating modes and DImode. */
996 if (FP_REGNO_P (regno))
997 return
998 (GET_MODE_CLASS (mode) == MODE_FLOAT
999 && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1))
1000 || (GET_MODE_CLASS (mode) == MODE_INT
1001 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD);
1002
1003 /* The CR register can only hold CC modes. */
1004 if (CR_REGNO_P (regno))
1005 return GET_MODE_CLASS (mode) == MODE_CC;
1006
1007 if (XER_REGNO_P (regno))
1008 return mode == PSImode;
1009
1010 /* AltiVec only in AldyVec registers. */
1011 if (ALTIVEC_REGNO_P (regno))
1012 return ALTIVEC_VECTOR_MODE (mode);
1013
1014 /* ...but GPRs can hold SIMD data on the SPE in one register. */
1015 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
1016 return 1;
1017
1018 /* We cannot put TImode anywhere except general register and it must be
1019 able to fit within the register set. */
1020
1021 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
1022}
1023
1024/* Initialize rs6000_hard_regno_mode_ok_p table. */
1025static void
1026rs6000_init_hard_regno_mode_ok (void)
1027{
1028 int r, m;
1029
1030 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
1031 for (m = 0; m < NUM_MACHINE_MODES; ++m)
1032 if (rs6000_hard_regno_mode_ok (r, m))
1033 rs6000_hard_regno_mode_ok_p[m][r] = true;
1034}
1035
c1e55850
GK
1036/* If not otherwise specified by a target, make 'long double' equivalent to
1037 'double'. */
1038
1039#ifndef RS6000_DEFAULT_LONG_DOUBLE_SIZE
1040#define RS6000_DEFAULT_LONG_DOUBLE_SIZE 64
1041#endif
1042
5248c961
RK
1043/* Override command line options. Mostly we process the processor
1044 type and sometimes adjust other TARGET_ options. */
1045
1046void
d779d0dc 1047rs6000_override_options (const char *default_cpu)
5248c961 1048{
c4d38ccb 1049 size_t i, j;
8e3f41e7 1050 struct rs6000_cpu_select *ptr;
66188a7e 1051 int set_masks;
5248c961 1052
66188a7e 1053 /* Simplifications for entries below. */
85638c0d 1054
66188a7e
GK
1055 enum {
1056 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
1057 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
1058 };
85638c0d 1059
66188a7e
GK
1060 /* This table occasionally claims that a processor does not support
1061 a particular feature even though it does, but the feature is slower
1062 than the alternative. Thus, it shouldn't be relied on as a
f676971a 1063 complete description of the processor's support.
66188a7e
GK
1064
1065 Please keep this list in order, and don't forget to update the
1066 documentation in invoke.texi when adding a new processor or
1067 flag. */
5248c961
RK
1068 static struct ptt
1069 {
8b60264b
KG
1070 const char *const name; /* Canonical processor name. */
1071 const enum processor_type processor; /* Processor type enum value. */
1072 const int target_enable; /* Target flags to enable. */
8b60264b 1073 } const processor_target_table[]
66188a7e 1074 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 1075 {"403", PROCESSOR_PPC403,
66188a7e
GK
1076 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
1077 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1078 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
1079 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1080 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
1081 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 1082 {"601", PROCESSOR_PPC601,
66188a7e
GK
1083 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
1084 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1085 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1086 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1087 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1088 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
1089 {"620", PROCESSOR_PPC620,
1090 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1091 {"630", PROCESSOR_PPC630,
1092 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
1093 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1094 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
1095 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
1096 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1097 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1098 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1099 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1100 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1101 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 1102 {"970", PROCESSOR_POWER4,
66188a7e
GK
1103 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1104 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
1105 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
1106 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
1107 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 1108 {"G5", PROCESSOR_POWER4,
66188a7e
GK
1109 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
1110 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1111 {"power2", PROCESSOR_POWER,
1112 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
1113 {"power3", PROCESSOR_PPC630,
1114 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
1115 {"power4", PROCESSOR_POWER4,
fc091c8e 1116 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
ec507f2d 1117 {"power5", PROCESSOR_POWER5,
fc091c8e 1118 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
66188a7e
GK
1119 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
1120 {"powerpc64", PROCESSOR_POWERPC64,
1121 POWERPC_BASE_MASK | MASK_POWERPC64},
1122 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1123 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1124 {"rios2", PROCESSOR_RIOS2,
1125 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
1126 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
1127 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 1128 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 1129 };
5248c961 1130
ca7558fc 1131 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 1132
66188a7e
GK
1133 /* Some OSs don't support saving the high part of 64-bit registers on
1134 context switch. Other OSs don't support saving Altivec registers.
1135 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
1136 settings; if the user wants either, the user must explicitly specify
1137 them and we won't interfere with the user's specification. */
1138
1139 enum {
1140 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
f676971a 1141 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
66188a7e
GK
1142 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
1143 | MASK_MFCRF)
1144 };
0d1fbc8c
AH
1145
1146 rs6000_init_hard_regno_mode_ok ();
1147
66188a7e
GK
1148 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
1149#ifdef OS_MISSING_POWERPC64
1150 if (OS_MISSING_POWERPC64)
1151 set_masks &= ~MASK_POWERPC64;
1152#endif
1153#ifdef OS_MISSING_ALTIVEC
1154 if (OS_MISSING_ALTIVEC)
1155 set_masks &= ~MASK_ALTIVEC;
1156#endif
1157
957211c3
AM
1158 /* Don't override these by the processor default if given explicitly. */
1159 set_masks &= ~(target_flags_explicit
1160 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
1161
a4f6c312 1162 /* Identify the processor type. */
8e3f41e7 1163 rs6000_select[0].string = default_cpu;
3cb999d8 1164 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 1165
b6a1cbae 1166 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 1167 {
8e3f41e7
MM
1168 ptr = &rs6000_select[i];
1169 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 1170 {
8e3f41e7
MM
1171 for (j = 0; j < ptt_size; j++)
1172 if (! strcmp (ptr->string, processor_target_table[j].name))
1173 {
1174 if (ptr->set_tune_p)
1175 rs6000_cpu = processor_target_table[j].processor;
1176
1177 if (ptr->set_arch_p)
1178 {
66188a7e
GK
1179 target_flags &= ~set_masks;
1180 target_flags |= (processor_target_table[j].target_enable
1181 & set_masks);
8e3f41e7
MM
1182 }
1183 break;
1184 }
1185
4406229e 1186 if (j == ptt_size)
8e3f41e7 1187 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
1188 }
1189 }
8a61d227 1190
993f19a8 1191 if (TARGET_E500)
a3170dc6
AH
1192 rs6000_isel = 1;
1193
dff9f1b6
DE
1194 /* If we are optimizing big endian systems for space, use the load/store
1195 multiple and string instructions. */
ef792183 1196 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 1197 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 1198
a4f6c312
SS
1199 /* Don't allow -mmultiple or -mstring on little endian systems
1200 unless the cpu is a 750, because the hardware doesn't support the
1201 instructions used in little endian mode, and causes an alignment
1202 trap. The 750 does not cause an alignment trap (except when the
1203 target is unaligned). */
bef84347 1204
b21fb038 1205 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
1206 {
1207 if (TARGET_MULTIPLE)
1208 {
1209 target_flags &= ~MASK_MULTIPLE;
b21fb038 1210 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
1211 warning ("-mmultiple is not supported on little endian systems");
1212 }
1213
1214 if (TARGET_STRING)
1215 {
1216 target_flags &= ~MASK_STRING;
b21fb038 1217 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 1218 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
1219 }
1220 }
3933e0e1 1221
38c1f2d7
MM
1222 /* Set debug flags */
1223 if (rs6000_debug_name)
1224 {
bfc79d3b 1225 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 1226 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 1227 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 1228 rs6000_debug_stack = 1;
bfc79d3b 1229 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
1230 rs6000_debug_arg = 1;
1231 else
c725bd79 1232 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
1233 }
1234
57ac7be9
AM
1235 if (rs6000_traceback_name)
1236 {
1237 if (! strncmp (rs6000_traceback_name, "full", 4))
1238 rs6000_traceback = traceback_full;
1239 else if (! strncmp (rs6000_traceback_name, "part", 4))
1240 rs6000_traceback = traceback_part;
1241 else if (! strncmp (rs6000_traceback_name, "no", 2))
1242 rs6000_traceback = traceback_none;
1243 else
1244 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
1245 rs6000_traceback_name);
1246 }
1247
6fa3f289 1248 /* Set size of long double */
c1e55850 1249 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
6fa3f289
ZW
1250 if (rs6000_long_double_size_string)
1251 {
1252 char *tail;
1253 int size = strtol (rs6000_long_double_size_string, &tail, 10);
1254 if (*tail != '\0' || (size != 64 && size != 128))
1255 error ("Unknown switch -mlong-double-%s",
1256 rs6000_long_double_size_string);
1257 else
1258 rs6000_long_double_type_size = size;
1259 }
1260
6d0ef01e
HP
1261 /* Set Altivec ABI as default for powerpc64 linux. */
1262 if (TARGET_ELF && TARGET_64BIT)
1263 {
1264 rs6000_altivec_abi = 1;
1265 rs6000_altivec_vrsave = 1;
1266 }
1267
0ac081f6
AH
1268 /* Handle -mabi= options. */
1269 rs6000_parse_abi_options ();
1270
025d9908
KH
1271 /* Handle -malign-XXXXX option. */
1272 rs6000_parse_alignment_option ();
1273
5da702b1
AH
1274 /* Handle generic -mFOO=YES/NO options. */
1275 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
1276 &rs6000_altivec_vrsave);
1277 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
1278 &rs6000_isel);
1279 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
1280 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
1281 &rs6000_float_gprs);
993f19a8 1282
c4501e62
JJ
1283 /* Handle -mtls-size option. */
1284 rs6000_parse_tls_size_option ();
1285
a7ae18e2
AH
1286#ifdef SUBTARGET_OVERRIDE_OPTIONS
1287 SUBTARGET_OVERRIDE_OPTIONS;
1288#endif
1289#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
1290 SUBSUBTARGET_OVERRIDE_OPTIONS;
1291#endif
1292
5da702b1
AH
1293 if (TARGET_E500)
1294 {
e4463bf1
AH
1295 if (TARGET_ALTIVEC)
1296 error ("AltiVec and E500 instructions cannot coexist");
1297
5da702b1
AH
1298 /* The e500 does not have string instructions, and we set
1299 MASK_STRING above when optimizing for size. */
1300 if ((target_flags & MASK_STRING) != 0)
1301 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
1302
1303 /* No SPE means 64-bit long doubles, even if an E500. */
1304 if (rs6000_spe_string != 0
1305 && !strcmp (rs6000_spe_string, "no"))
1306 rs6000_long_double_type_size = 64;
5da702b1
AH
1307 }
1308 else if (rs6000_select[1].string != NULL)
1309 {
1310 /* For the powerpc-eabispe configuration, we set all these by
1311 default, so let's unset them if we manually set another
1312 CPU that is not the E500. */
1313 if (rs6000_abi_string == 0)
1314 rs6000_spe_abi = 0;
1315 if (rs6000_spe_string == 0)
1316 rs6000_spe = 0;
1317 if (rs6000_float_gprs_string == 0)
1318 rs6000_float_gprs = 0;
1319 if (rs6000_isel_string == 0)
1320 rs6000_isel = 0;
b6e59a3a 1321 if (rs6000_long_double_size_string == 0)
c1e55850 1322 rs6000_long_double_type_size = RS6000_DEFAULT_LONG_DOUBLE_SIZE;
5da702b1 1323 }
b5044283 1324
ec507f2d
DE
1325 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
1326 && rs6000_cpu != PROCESSOR_POWER5);
1327 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
1328 || rs6000_cpu == PROCESSOR_POWER5);
1329
a5c76ee6
ZW
1330 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
1331 using TARGET_OPTIONS to handle a toggle switch, but we're out of
1332 bits in target_flags so TARGET_SWITCHES cannot be used.
1333 Assumption here is that rs6000_longcall_switch points into the
1334 text of the complete option, rather than being a copy, so we can
1335 scan back for the presence or absence of the no- modifier. */
1336 if (rs6000_longcall_switch)
1337 {
1338 const char *base = rs6000_longcall_switch;
1339 while (base[-1] != 'm') base--;
1340
1341 if (*rs6000_longcall_switch != '\0')
1342 error ("invalid option `%s'", base);
1343 rs6000_default_long_calls = (base[0] != 'n');
1344 }
1345
8bb418a3
ZL
1346 /* Handle -m(no-)warn-altivec-long similarly. */
1347 if (rs6000_warn_altivec_long_switch)
1348 {
1349 const char *base = rs6000_warn_altivec_long_switch;
1350 while (base[-1] != 'm') base--;
1351
1352 if (*rs6000_warn_altivec_long_switch != '\0')
1353 error ("invalid option `%s'", base);
1354 rs6000_warn_altivec_long = (base[0] != 'n');
1355 }
1356
cbe26ab8 1357 /* Handle -mprioritize-restricted-insns option. */
ec507f2d
DE
1358 rs6000_sched_restricted_insns_priority
1359 = (rs6000_sched_groups ? 1 : 0);
79ae11c4
DN
1360 if (rs6000_sched_restricted_insns_priority_str)
1361 rs6000_sched_restricted_insns_priority =
1362 atoi (rs6000_sched_restricted_insns_priority_str);
1363
569fa502 1364 /* Handle -msched-costly-dep option. */
ec507f2d
DE
1365 rs6000_sched_costly_dep
1366 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
569fa502
DN
1367 if (rs6000_sched_costly_dep_str)
1368 {
f676971a 1369 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
569fa502
DN
1370 rs6000_sched_costly_dep = no_dep_costly;
1371 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
1372 rs6000_sched_costly_dep = all_deps_costly;
1373 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
1374 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
1375 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
1376 rs6000_sched_costly_dep = store_to_load_dep_costly;
f676971a 1377 else
cbe26ab8
DN
1378 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
1379 }
1380
1381 /* Handle -minsert-sched-nops option. */
ec507f2d
DE
1382 rs6000_sched_insert_nops
1383 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
cbe26ab8
DN
1384 if (rs6000_sched_insert_nops_str)
1385 {
1386 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
1387 rs6000_sched_insert_nops = sched_finish_none;
1388 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
1389 rs6000_sched_insert_nops = sched_finish_pad_groups;
1390 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
1391 rs6000_sched_insert_nops = sched_finish_regroup_exact;
1392 else
1393 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
1394 }
1395
c81bebd7 1396#ifdef TARGET_REGNAMES
a4f6c312
SS
1397 /* If the user desires alternate register names, copy in the
1398 alternate names now. */
c81bebd7 1399 if (TARGET_REGNAMES)
4e135bdd 1400 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
1401#endif
1402
6fa3f289
ZW
1403 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
1404 If -maix-struct-return or -msvr4-struct-return was explicitly
1405 used, don't override with the ABI default. */
b21fb038 1406 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
1407 {
1408 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
1409 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
1410 else
1411 target_flags |= MASK_AIX_STRUCT_RET;
1412 }
1413
fcce224d
DE
1414 if (TARGET_LONG_DOUBLE_128
1415 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 1416 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 1417
9ebbca7d
GK
1418 /* Allocate an alias set for register saves & restores from stack. */
1419 rs6000_sr_alias_set = new_alias_set ();
1420
f676971a 1421 if (TARGET_TOC)
9ebbca7d 1422 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 1423
301d03af
RS
1424 /* We can only guarantee the availability of DI pseudo-ops when
1425 assembling for 64-bit targets. */
ae6c1efd 1426 if (!TARGET_64BIT)
301d03af
RS
1427 {
1428 targetm.asm_out.aligned_op.di = NULL;
1429 targetm.asm_out.unaligned_op.di = NULL;
1430 }
1431
1494c534
DE
1432 /* Set branch target alignment, if not optimizing for size. */
1433 if (!optimize_size)
1434 {
1435 if (rs6000_sched_groups)
1436 {
1437 if (align_functions <= 0)
1438 align_functions = 16;
1439 if (align_jumps <= 0)
1440 align_jumps = 16;
1441 if (align_loops <= 0)
1442 align_loops = 16;
1443 }
1444 if (align_jumps_max_skip <= 0)
1445 align_jumps_max_skip = 15;
1446 if (align_loops_max_skip <= 0)
1447 align_loops_max_skip = 15;
1448 }
2792d578 1449
71f123ca
FS
1450 /* Arrange to save and restore machine status around nested functions. */
1451 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1452
1453 /* We should always be splitting complex arguments, but we can't break
1454 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1455 if (DEFAULT_ABI != ABI_AIX)
1456 targetm.calls.split_complex_arg = NULL;
8b897cfa
RS
1457
1458 /* Initialize rs6000_cost with the appropriate target costs. */
1459 if (optimize_size)
1460 rs6000_cost = TARGET_POWERPC64 ? &size64_cost : &size32_cost;
1461 else
1462 switch (rs6000_cpu)
1463 {
1464 case PROCESSOR_RIOS1:
1465 rs6000_cost = &rios1_cost;
1466 break;
1467
1468 case PROCESSOR_RIOS2:
1469 rs6000_cost = &rios2_cost;
1470 break;
1471
1472 case PROCESSOR_RS64A:
1473 rs6000_cost = &rs64a_cost;
1474 break;
1475
1476 case PROCESSOR_MPCCORE:
1477 rs6000_cost = &mpccore_cost;
1478 break;
1479
1480 case PROCESSOR_PPC403:
1481 rs6000_cost = &ppc403_cost;
1482 break;
1483
1484 case PROCESSOR_PPC405:
1485 rs6000_cost = &ppc405_cost;
1486 break;
1487
1488 case PROCESSOR_PPC440:
1489 rs6000_cost = &ppc440_cost;
1490 break;
1491
1492 case PROCESSOR_PPC601:
1493 rs6000_cost = &ppc601_cost;
1494 break;
1495
1496 case PROCESSOR_PPC603:
1497 rs6000_cost = &ppc603_cost;
1498 break;
1499
1500 case PROCESSOR_PPC604:
1501 rs6000_cost = &ppc604_cost;
1502 break;
1503
1504 case PROCESSOR_PPC604e:
1505 rs6000_cost = &ppc604e_cost;
1506 break;
1507
1508 case PROCESSOR_PPC620:
8b897cfa
RS
1509 rs6000_cost = &ppc620_cost;
1510 break;
1511
f0517163
RS
1512 case PROCESSOR_PPC630:
1513 rs6000_cost = &ppc630_cost;
1514 break;
1515
8b897cfa
RS
1516 case PROCESSOR_PPC750:
1517 case PROCESSOR_PPC7400:
1518 rs6000_cost = &ppc750_cost;
1519 break;
1520
1521 case PROCESSOR_PPC7450:
1522 rs6000_cost = &ppc7450_cost;
1523 break;
1524
1525 case PROCESSOR_PPC8540:
1526 rs6000_cost = &ppc8540_cost;
1527 break;
1528
1529 case PROCESSOR_POWER4:
1530 case PROCESSOR_POWER5:
1531 rs6000_cost = &power4_cost;
1532 break;
1533
1534 default:
1535 abort ();
1536 }
5248c961 1537}
5accd822 1538
5da702b1
AH
1539/* Handle generic options of the form -mfoo=yes/no.
1540 NAME is the option name.
1541 VALUE is the option value.
1542 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1543 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1544static void
5da702b1 1545rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1546{
5da702b1 1547 if (value == 0)
993f19a8 1548 return;
5da702b1
AH
1549 else if (!strcmp (value, "yes"))
1550 *flag = 1;
1551 else if (!strcmp (value, "no"))
1552 *flag = 0;
08b57fb3 1553 else
5da702b1 1554 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1555}
1556
0ac081f6 1557/* Handle -mabi= options. */
00b960c7 1558static void
863d938c 1559rs6000_parse_abi_options (void)
0ac081f6
AH
1560{
1561 if (rs6000_abi_string == 0)
1562 return;
1563 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1564 {
1565 rs6000_altivec_abi = 1;
1566 rs6000_spe_abi = 0;
1567 }
76a773f3
AH
1568 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1569 rs6000_altivec_abi = 0;
a3170dc6 1570 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1571 {
1572 rs6000_spe_abi = 1;
5cc73f91 1573 rs6000_altivec_abi = 0;
01f4962d
NS
1574 if (!TARGET_SPE_ABI)
1575 error ("not configured for ABI: '%s'", rs6000_abi_string);
1576 }
f676971a 1577
a3170dc6
AH
1578 else if (! strcmp (rs6000_abi_string, "no-spe"))
1579 rs6000_spe_abi = 0;
0ac081f6 1580 else
c725bd79 1581 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1582}
1583
025d9908
KH
1584/* Handle -malign-XXXXXX options. */
1585static void
863d938c 1586rs6000_parse_alignment_option (void)
025d9908 1587{
b20a9cca
AM
1588 if (rs6000_alignment_string == 0)
1589 return;
1590 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1591 rs6000_alignment_flags = MASK_ALIGN_POWER;
1592 else if (! strcmp (rs6000_alignment_string, "natural"))
1593 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1594 else
1595 error ("unknown -malign-XXXXX option specified: '%s'",
1596 rs6000_alignment_string);
1597}
1598
c4501e62
JJ
1599/* Validate and record the size specified with the -mtls-size option. */
1600
1601static void
863d938c 1602rs6000_parse_tls_size_option (void)
c4501e62
JJ
1603{
1604 if (rs6000_tls_size_string == 0)
1605 return;
1606 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1607 rs6000_tls_size = 16;
1608 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1609 rs6000_tls_size = 32;
1610 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1611 rs6000_tls_size = 64;
1612 else
1613 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1614}
1615
5accd822 1616void
a2369ed3 1617optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1618{
5accd822 1619}
3cfa4909
MM
1620\f
1621/* Do anything needed at the start of the asm file. */
1622
1bc7c5b6 1623static void
863d938c 1624rs6000_file_start (void)
3cfa4909 1625{
c4d38ccb 1626 size_t i;
3cfa4909 1627 char buffer[80];
d330fd93 1628 const char *start = buffer;
3cfa4909 1629 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1630 const char *default_cpu = TARGET_CPU_DEFAULT;
1631 FILE *file = asm_out_file;
1632
1633 default_file_start ();
1634
1635#ifdef TARGET_BI_ARCH
1636 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1637 default_cpu = 0;
1638#endif
3cfa4909
MM
1639
1640 if (flag_verbose_asm)
1641 {
1642 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1643 rs6000_select[0].string = default_cpu;
1644
b6a1cbae 1645 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1646 {
1647 ptr = &rs6000_select[i];
1648 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1649 {
1650 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1651 start = "";
1652 }
1653 }
1654
b91da81f 1655#ifdef USING_ELFOS_H
3cfa4909
MM
1656 switch (rs6000_sdata)
1657 {
1658 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1659 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1660 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1661 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1662 }
1663
1664 if (rs6000_sdata && g_switch_value)
1665 {
307b599c
MK
1666 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1667 g_switch_value);
3cfa4909
MM
1668 start = "";
1669 }
1670#endif
1671
1672 if (*start == '\0')
949ea356 1673 putc ('\n', file);
3cfa4909
MM
1674 }
1675}
5248c961 1676\f
a0ab749a 1677/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1678
1679int
863d938c 1680direct_return (void)
9878760c 1681{
4697a36c
MM
1682 if (reload_completed)
1683 {
1684 rs6000_stack_t *info = rs6000_stack_info ();
1685
1686 if (info->first_gp_reg_save == 32
1687 && info->first_fp_reg_save == 64
00b960c7 1688 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1689 && ! info->lr_save_p
1690 && ! info->cr_save_p
00b960c7 1691 && info->vrsave_mask == 0
c81fc13e 1692 && ! info->push_p)
4697a36c
MM
1693 return 1;
1694 }
1695
1696 return 0;
9878760c
RK
1697}
1698
1699/* Returns 1 always. */
1700
1701int
f676971a 1702any_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 1703 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1704{
1705 return 1;
1706}
1707
85d346f1
DE
1708/* Returns 1 always. */
1709
1710int
f676971a 1711any_parallel_operand (rtx op ATTRIBUTE_UNUSED,
85d346f1
DE
1712 enum machine_mode mode ATTRIBUTE_UNUSED)
1713{
1714 return 1;
1715}
1716
a4f6c312 1717/* Returns 1 if op is the count register. */
85d346f1 1718
38c1f2d7 1719int
a2369ed3 1720count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1721{
1722 if (GET_CODE (op) != REG)
1723 return 0;
1724
1725 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1726 return 1;
1727
1728 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1729 return 1;
1730
1731 return 0;
1732}
1733
0ec4e2a8 1734/* Returns 1 if op is an altivec register. */
85d346f1 1735
0ec4e2a8 1736int
a2369ed3 1737altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8 1738{
f676971a 1739
0ec4e2a8
AH
1740 return (register_operand (op, mode)
1741 && (GET_CODE (op) != REG
1742 || REGNO (op) > FIRST_PSEUDO_REGISTER
1743 || ALTIVEC_REGNO_P (REGNO (op))));
1744}
1745
38c1f2d7 1746int
a2369ed3 1747xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1748{
1749 if (GET_CODE (op) != REG)
1750 return 0;
1751
9ebbca7d 1752 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1753 return 1;
1754
802a0058
MM
1755 return 0;
1756}
1757
c859cda6 1758/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1759 by such constants completes more quickly. */
c859cda6
DJ
1760
1761int
a2369ed3 1762s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6
DJ
1763{
1764 return ( GET_CODE (op) == CONST_INT
1765 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1766}
1767
9878760c
RK
1768/* Return 1 if OP is a constant that can fit in a D field. */
1769
1770int
a2369ed3 1771short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1772{
5f59ecb7
DE
1773 return (GET_CODE (op) == CONST_INT
1774 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1775}
1776
5519a4f9 1777/* Similar for an unsigned D field. */
9878760c
RK
1778
1779int
a2369ed3 1780u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1781{
19684119 1782 return (GET_CODE (op) == CONST_INT
c1f11548 1783 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1784}
1785
dcfedcd0
RK
1786/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1787
1788int
a2369ed3 1789non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1790{
1791 return (GET_CODE (op) == CONST_INT
a7653a2c 1792 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1793}
1794
2bfcf297
DB
1795/* Returns 1 if OP is a CONST_INT that is a positive value
1796 and an exact power of 2. */
1797
1798int
a2369ed3 1799exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1800{
1801 return (GET_CODE (op) == CONST_INT
1802 && INTVAL (op) > 0
1803 && exact_log2 (INTVAL (op)) >= 0);
1804}
1805
9878760c
RK
1806/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1807 ctr, or lr). */
1808
1809int
a2369ed3 1810gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1811{
1812 return (register_operand (op, mode)
802a0058 1813 && (GET_CODE (op) != REG
f676971a 1814 || (REGNO (op) >= ARG_POINTER_REGNUM
9ebbca7d
GK
1815 && !XER_REGNO_P (REGNO (op)))
1816 || REGNO (op) < MQ_REGNO));
9878760c
RK
1817}
1818
1819/* Returns 1 if OP is either a pseudo-register or a register denoting a
1820 CR field. */
1821
1822int
a2369ed3 1823cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1824{
1825 return (register_operand (op, mode)
1826 && (GET_CODE (op) != REG
1827 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1828 || CR_REGNO_P (REGNO (op))));
1829}
1830
815cdc52
MM
1831/* Returns 1 if OP is either a pseudo-register or a register denoting a
1832 CR field that isn't CR0. */
1833
1834int
a2369ed3 1835cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1836{
1837 return (register_operand (op, mode)
1838 && (GET_CODE (op) != REG
1839 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1840 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1841}
1842
a4f6c312
SS
1843/* Returns 1 if OP is either a constant integer valid for a D-field or
1844 a non-special register. If a register, it must be in the proper
1845 mode unless MODE is VOIDmode. */
9878760c
RK
1846
1847int
a2369ed3 1848reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1849{
f5a28898 1850 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1851}
1852
a4f6c312 1853/* Similar, except check if the negation of the constant would be
42f806e5
AM
1854 valid for a D-field. Don't allow a constant zero, since all the
1855 patterns that call this predicate use "addic r1,r2,-constant" on
1856 a constant value to set a carry when r2 is greater or equal to
1857 "constant". That doesn't work for zero. */
9878760c
RK
1858
1859int
a2369ed3 1860reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1861{
1862 if (GET_CODE (op) == CONST_INT)
42f806e5 1863 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P') && INTVAL (op) != 0;
9878760c 1864
cd2b37d9 1865 return gpc_reg_operand (op, mode);
9878760c
RK
1866}
1867
768070a0
TR
1868/* Returns 1 if OP is either a constant integer valid for a DS-field or
1869 a non-special register. If a register, it must be in the proper
1870 mode unless MODE is VOIDmode. */
1871
1872int
a2369ed3 1873reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1874{
1875 if (gpc_reg_operand (op, mode))
1876 return 1;
1877 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1878 return 1;
1879
1880 return 0;
1881}
1882
1883
a4f6c312
SS
1884/* Return 1 if the operand is either a register or an integer whose
1885 high-order 16 bits are zero. */
9878760c
RK
1886
1887int
a2369ed3 1888reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1889{
e675f625 1890 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1891}
1892
1893/* Return 1 is the operand is either a non-special register or ANY
1894 constant integer. */
1895
1896int
a2369ed3 1897reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1898{
a4f6c312 1899 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1900}
1901
1902/* Return 1 is the operand is either a non-special register or ANY
1903 32-bit signed constant integer. */
1904
1905int
a2369ed3 1906reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1907{
a4f6c312
SS
1908 return (gpc_reg_operand (op, mode)
1909 || (GET_CODE (op) == CONST_INT
f6bf7de2 1910#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1911 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1912 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1913#endif
a4f6c312 1914 ));
9878760c
RK
1915}
1916
2bfcf297
DB
1917/* Return 1 is the operand is either a non-special register or a 32-bit
1918 signed constant integer valid for 64-bit addition. */
1919
1920int
a2369ed3 1921reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1922{
a4f6c312
SS
1923 return (gpc_reg_operand (op, mode)
1924 || (GET_CODE (op) == CONST_INT
a65c591c 1925#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1926 && INTVAL (op) < 0x7fff8000
a65c591c 1927#else
a4f6c312
SS
1928 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1929 < 0x100000000ll)
2bfcf297 1930#endif
a4f6c312 1931 ));
2bfcf297
DB
1932}
1933
1934/* Return 1 is the operand is either a non-special register or a 32-bit
1935 signed constant integer valid for 64-bit subtraction. */
1936
1937int
a2369ed3 1938reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1939{
a4f6c312
SS
1940 return (gpc_reg_operand (op, mode)
1941 || (GET_CODE (op) == CONST_INT
a65c591c 1942#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1943 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1944#else
a4f6c312
SS
1945 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1946 < 0x100000000ll)
2bfcf297 1947#endif
a4f6c312 1948 ));
2bfcf297
DB
1949}
1950
9ebbca7d
GK
1951/* Return 1 is the operand is either a non-special register or ANY
1952 32-bit unsigned constant integer. */
1953
1954int
a2369ed3 1955reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1956{
1d328b19
GK
1957 if (GET_CODE (op) == CONST_INT)
1958 {
1959 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1960 {
1961 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1962 abort ();
1d328b19
GK
1963
1964 if (INTVAL (op) < 0)
1965 return 0;
1966 }
1967
1968 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1969 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1970 }
1971 else if (GET_CODE (op) == CONST_DOUBLE)
1972 {
1973 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1974 || mode != DImode)
a4f6c312 1975 abort ();
1d328b19
GK
1976
1977 return CONST_DOUBLE_HIGH (op) == 0;
1978 }
f676971a 1979 else
1d328b19 1980 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1981}
1982
51d3e7d6 1983/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1984
1985int
a2369ed3 1986got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
1987{
1988 return (GET_CODE (op) == SYMBOL_REF
1989 || GET_CODE (op) == CONST
1990 || GET_CODE (op) == LABEL_REF);
1991}
1992
38c1f2d7
MM
1993/* Return 1 if the operand is a simple references that can be loaded via
1994 the GOT (labels involving addition aren't allowed). */
1995
1996int
a2369ed3 1997got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
1998{
1999 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
2000}
2001
4e74d8ec
MM
2002/* Return the number of instructions it takes to form a constant in an
2003 integer register. */
2004
2005static int
a2369ed3 2006num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
2007{
2008 /* signed constant loadable with {cal|addi} */
5f59ecb7 2009 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
2010 return 1;
2011
4e74d8ec 2012 /* constant loadable with {cau|addis} */
5f59ecb7 2013 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
2014 return 1;
2015
5f59ecb7 2016#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 2017 else if (TARGET_POWERPC64)
4e74d8ec 2018 {
a65c591c
DE
2019 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
2020 HOST_WIDE_INT high = value >> 31;
4e74d8ec 2021
a65c591c 2022 if (high == 0 || high == -1)
4e74d8ec
MM
2023 return 2;
2024
a65c591c 2025 high >>= 1;
4e74d8ec 2026
a65c591c 2027 if (low == 0)
4e74d8ec 2028 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
2029 else
2030 return (num_insns_constant_wide (high)
e396202a 2031 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
2032 }
2033#endif
2034
2035 else
2036 return 2;
2037}
2038
2039int
a2369ed3 2040num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 2041{
4e74d8ec 2042 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
2043 {
2044#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
2045 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
2046 && mask64_operand (op, mode))
0d30d435
DE
2047 return 2;
2048 else
2049#endif
2050 return num_insns_constant_wide (INTVAL (op));
2051 }
4e74d8ec 2052
6fc48950
MM
2053 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
2054 {
2055 long l;
2056 REAL_VALUE_TYPE rv;
2057
2058 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2059 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 2060 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
2061 }
2062
47ad8c61 2063 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 2064 {
47ad8c61
MM
2065 HOST_WIDE_INT low;
2066 HOST_WIDE_INT high;
2067 long l[2];
2068 REAL_VALUE_TYPE rv;
2069 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 2070
47ad8c61
MM
2071 if (mode == VOIDmode || mode == DImode)
2072 {
2073 high = CONST_DOUBLE_HIGH (op);
2074 low = CONST_DOUBLE_LOW (op);
2075 }
2076 else
2077 {
2078 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2079 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
2080 high = l[endian];
2081 low = l[1 - endian];
2082 }
4e74d8ec 2083
47ad8c61
MM
2084 if (TARGET_32BIT)
2085 return (num_insns_constant_wide (low)
2086 + num_insns_constant_wide (high));
4e74d8ec
MM
2087
2088 else
47ad8c61 2089 {
e72247f4 2090 if (high == 0 && low >= 0)
47ad8c61
MM
2091 return num_insns_constant_wide (low);
2092
e72247f4 2093 else if (high == -1 && low < 0)
47ad8c61
MM
2094 return num_insns_constant_wide (low);
2095
a260abc9
DE
2096 else if (mask64_operand (op, mode))
2097 return 2;
2098
47ad8c61
MM
2099 else if (low == 0)
2100 return num_insns_constant_wide (high) + 1;
2101
2102 else
2103 return (num_insns_constant_wide (high)
2104 + num_insns_constant_wide (low) + 1);
2105 }
4e74d8ec
MM
2106 }
2107
2108 else
2109 abort ();
2110}
2111
a4f6c312
SS
2112/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
2113 register with one instruction per word. We only do this if we can
2114 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
2115
2116int
a2369ed3 2117easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 2118{
9878760c
RK
2119 if (GET_CODE (op) != CONST_DOUBLE
2120 || GET_MODE (op) != mode
4e74d8ec 2121 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
2122 return 0;
2123
a4f6c312 2124 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
2125 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
2126 && mode != DImode)
b6c9286a
MM
2127 return 1;
2128
a4f6c312 2129 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 2130 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
2131 return 0;
2132
5ae4759c 2133#ifdef TARGET_RELOCATABLE
a4f6c312
SS
2134 /* Similarly if we are using -mrelocatable, consider all constants
2135 to be hard. */
5ae4759c
MM
2136 if (TARGET_RELOCATABLE)
2137 return 0;
2138#endif
2139
fcce224d
DE
2140 if (mode == TFmode)
2141 {
2142 long k[4];
2143 REAL_VALUE_TYPE rv;
2144
2145 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2146 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
2147
2148 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2149 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
2150 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
2151 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
2152 }
2153
2154 else if (mode == DFmode)
042259f2
DE
2155 {
2156 long k[2];
2157 REAL_VALUE_TYPE rv;
2158
2159 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2160 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 2161
a65c591c
DE
2162 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
2163 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 2164 }
4e74d8ec
MM
2165
2166 else if (mode == SFmode)
042259f2
DE
2167 {
2168 long l;
2169 REAL_VALUE_TYPE rv;
2170
2171 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
2172 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 2173
4e74d8ec 2174 return num_insns_constant_wide (l) == 1;
042259f2 2175 }
4e74d8ec 2176
a260abc9 2177 else if (mode == DImode)
c81fc13e 2178 return ((TARGET_POWERPC64
a260abc9
DE
2179 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
2180 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 2181
a9098fd0
GK
2182 else if (mode == SImode)
2183 return 1;
4e74d8ec
MM
2184 else
2185 abort ();
9878760c 2186}
8f75773e 2187
effa5d5d 2188/* Returns the constant for the splat instruction, if exists. */
452a7d36
HP
2189
2190static int
2191easy_vector_splat_const (int cst, enum machine_mode mode)
2192{
f676971a 2193 switch (mode)
452a7d36
HP
2194 {
2195 case V4SImode:
f676971a
EC
2196 if (EASY_VECTOR_15 (cst)
2197 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2198 return cst;
2199 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
2200 break;
2201 cst = cst >> 16;
2202 case V8HImode:
f676971a
EC
2203 if (EASY_VECTOR_15 (cst)
2204 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36
HP
2205 return cst;
2206 if ((cst & 0xff) != ((cst >> 8) & 0xff))
2207 break;
2208 cst = cst >> 8;
2209 case V16QImode:
f676971a
EC
2210 if (EASY_VECTOR_15 (cst)
2211 || EASY_VECTOR_15_ADD_SELF (cst))
452a7d36 2212 return cst;
f676971a 2213 default:
452a7d36
HP
2214 break;
2215 }
2216 return 0;
2217}
2218
2219
72ac76be 2220/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
2221
2222static int
a2369ed3 2223easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
2224{
2225 int units, i, cst;
2226
2227 units = CONST_VECTOR_NUNITS (op);
2228
2229 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2230 for (i = 1; i < units; ++i)
2231 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
2232 break;
452a7d36 2233 if (i == units && easy_vector_splat_const (cst, mode))
d744e06e
AH
2234 return 1;
2235 return 0;
2236}
2237
2238/* Return 1 if the operand is a CONST_INT and can be put into a
2239 register without using memory. */
2240
2241int
a2369ed3 2242easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 2243{
d744e06e 2244 int cst, cst2;
69ef87e2 2245
d744e06e
AH
2246 if (GET_CODE (op) != CONST_VECTOR
2247 || (!TARGET_ALTIVEC
2248 && !TARGET_SPE))
69ef87e2
AH
2249 return 0;
2250
d744e06e
AH
2251 if (zero_constant (op, mode)
2252 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
2253 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
2254 return 1;
69ef87e2 2255
d744e06e
AH
2256 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
2257 return 0;
2258
f5119d10
AH
2259 if (TARGET_SPE && mode == V1DImode)
2260 return 0;
2261
d744e06e
AH
2262 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
2263 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
2264
2265 /* Limit SPE vectors to 15 bits signed. These we can generate with:
2266 li r0, CONSTANT1
2267 evmergelo r0, r0, r0
2268 li r0, CONSTANT2
2269
2270 I don't know how efficient it would be to allow bigger constants,
2271 considering we'll have an extra 'ori' for every 'li'. I doubt 5
2272 instructions is better than a 64-bit memory load, but I don't
2273 have the e500 timing specs. */
2274 if (TARGET_SPE && mode == V2SImode
2275 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 2276 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
2277 return 1;
2278
f676971a 2279 if (TARGET_ALTIVEC
452a7d36
HP
2280 && easy_vector_same (op, mode))
2281 {
2282 cst = easy_vector_splat_const (cst, mode);
f676971a 2283 if (EASY_VECTOR_15_ADD_SELF (cst)
452a7d36
HP
2284 || EASY_VECTOR_15 (cst))
2285 return 1;
f676971a 2286 }
d744e06e
AH
2287 return 0;
2288}
2289
2290/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
2291
2292int
a2369ed3 2293easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
2294{
2295 int cst;
452a7d36
HP
2296 if (TARGET_ALTIVEC
2297 && GET_CODE (op) == CONST_VECTOR
2298 && easy_vector_same (op, mode))
2299 {
2300 cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode);
2301 if (EASY_VECTOR_15_ADD_SELF (cst))
f676971a 2302 return 1;
452a7d36
HP
2303 }
2304 return 0;
2305}
d744e06e 2306
452a7d36 2307/* Generate easy_vector_constant out of a easy_vector_constant_add_self. */
d744e06e 2308
f676971a 2309rtx
452a7d36
HP
2310gen_easy_vector_constant_add_self (rtx op)
2311{
2312 int i, units;
2313 rtvec v;
2314 units = GET_MODE_NUNITS (GET_MODE (op));
2315 v = rtvec_alloc (units);
2316
2317 for (i = 0; i < units; i++)
f676971a 2318 RTVEC_ELT (v, i) =
452a7d36
HP
2319 GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1);
2320 return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v);
d744e06e
AH
2321}
2322
2323const char *
a2369ed3 2324output_vec_const_move (rtx *operands)
d744e06e
AH
2325{
2326 int cst, cst2;
2327 enum machine_mode mode;
2328 rtx dest, vec;
2329
2330 dest = operands[0];
2331 vec = operands[1];
69ef87e2 2332
d744e06e
AH
2333 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
2334 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
2335 mode = GET_MODE (dest);
69ef87e2 2336
d744e06e
AH
2337 if (TARGET_ALTIVEC)
2338 {
2339 if (zero_constant (vec, mode))
2340 return "vxor %0,%0,%0";
ce1f50b2 2341 else if (easy_vector_constant (vec, mode))
98ef3137 2342 {
d744e06e
AH
2343 operands[1] = GEN_INT (cst);
2344 switch (mode)
2345 {
2346 case V4SImode:
452a7d36 2347 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2348 {
2349 operands[1] = GEN_INT (cst);
2350 return "vspltisw %0,%1";
2351 }
452a7d36
HP
2352 else if (EASY_VECTOR_15_ADD_SELF (cst))
2353 return "#";
ce1f50b2 2354 cst = cst >> 16;
d744e06e 2355 case V8HImode:
452a7d36 2356 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2357 {
2358 operands[1] = GEN_INT (cst);
2359 return "vspltish %0,%1";
2360 }
452a7d36
HP
2361 else if (EASY_VECTOR_15_ADD_SELF (cst))
2362 return "#";
ce1f50b2 2363 cst = cst >> 8;
d744e06e 2364 case V16QImode:
452a7d36 2365 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
2366 {
2367 operands[1] = GEN_INT (cst);
2368 return "vspltisb %0,%1";
2369 }
452a7d36
HP
2370 else if (EASY_VECTOR_15_ADD_SELF (cst))
2371 return "#";
d744e06e
AH
2372 default:
2373 abort ();
2374 }
98ef3137 2375 }
d744e06e
AH
2376 else
2377 abort ();
69ef87e2
AH
2378 }
2379
d744e06e
AH
2380 if (TARGET_SPE)
2381 {
2382 /* Vector constant 0 is handled as a splitter of V2SI, and in the
2383 pattern of V1DI, V4HI, and V2SF.
2384
c1207243 2385 FIXME: We should probably return # and add post reload
d744e06e
AH
2386 splitters for these, but this way is so easy ;-).
2387 */
2388 operands[1] = GEN_INT (cst);
2389 operands[2] = GEN_INT (cst2);
2390 if (cst == cst2)
2391 return "li %0,%1\n\tevmergelo %0,%0,%0";
2392 else
2393 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
2394 }
2395
2396 abort ();
69ef87e2
AH
2397}
2398
2399/* Return 1 if the operand is the constant 0. This works for scalars
2400 as well as vectors. */
2401int
a2369ed3 2402zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
2403{
2404 return op == CONST0_RTX (mode);
2405}
2406
50a0b056
GK
2407/* Return 1 if the operand is 0.0. */
2408int
a2369ed3 2409zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
2410{
2411 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
2412}
2413
a4f6c312
SS
2414/* Return 1 if the operand is in volatile memory. Note that during
2415 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
2416 volatile memory references. So this function allows us to
2417 recognize volatile references where its safe. */
2418
2419int
a2369ed3 2420volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
2421{
2422 if (GET_CODE (op) != MEM)
2423 return 0;
2424
2425 if (!MEM_VOLATILE_P (op))
2426 return 0;
2427
2428 if (mode != GET_MODE (op))
2429 return 0;
2430
2431 if (reload_completed)
2432 return memory_operand (op, mode);
2433
2434 if (reload_in_progress)
2435 return strict_memory_address_p (mode, XEXP (op, 0));
2436
2437 return memory_address_p (mode, XEXP (op, 0));
2438}
2439
97f6e72f 2440/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
2441
2442int
a2369ed3 2443offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 2444{
97f6e72f 2445 return ((GET_CODE (op) == MEM)
677a9668 2446 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 2447 mode, XEXP (op, 0)));
914c2e77
RK
2448}
2449
9878760c
RK
2450/* Return 1 if the operand is either an easy FP constant (see above) or
2451 memory. */
2452
2453int
a2369ed3 2454mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
2455{
2456 return memory_operand (op, mode) || easy_fp_constant (op, mode);
2457}
2458
2459/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 2460 that can be used as the operand of a `mode' add insn. */
9878760c
RK
2461
2462int
a2369ed3 2463add_operand (rtx op, enum machine_mode mode)
9878760c 2464{
2bfcf297 2465 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
2466 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2467 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
2468
2469 return gpc_reg_operand (op, mode);
9878760c
RK
2470}
2471
dcfedcd0
RK
2472/* Return 1 if OP is a constant but not a valid add_operand. */
2473
2474int
a2369ed3 2475non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
2476{
2477 return (GET_CODE (op) == CONST_INT
e72247f4
DE
2478 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2479 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
2480}
2481
9878760c
RK
2482/* Return 1 if the operand is a non-special register or a constant that
2483 can be used as the operand of an OR or XOR insn on the RS/6000. */
2484
2485int
a2369ed3 2486logical_operand (rtx op, enum machine_mode mode)
9878760c 2487{
40501e5f 2488 HOST_WIDE_INT opl, oph;
1d328b19 2489
dfbdccdb
GK
2490 if (gpc_reg_operand (op, mode))
2491 return 1;
1d328b19 2492
dfbdccdb 2493 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
2494 {
2495 opl = INTVAL (op) & GET_MODE_MASK (mode);
2496
2497#if HOST_BITS_PER_WIDE_INT <= 32
2498 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
2499 return 0;
2500#endif
2501 }
dfbdccdb
GK
2502 else if (GET_CODE (op) == CONST_DOUBLE)
2503 {
1d328b19 2504 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 2505 abort ();
1d328b19
GK
2506
2507 opl = CONST_DOUBLE_LOW (op);
2508 oph = CONST_DOUBLE_HIGH (op);
40501e5f 2509 if (oph != 0)
38886f37 2510 return 0;
dfbdccdb
GK
2511 }
2512 else
2513 return 0;
1d328b19 2514
40501e5f
AM
2515 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
2516 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
2517}
2518
dcfedcd0 2519/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 2520 above), but could be split into one. */
dcfedcd0
RK
2521
2522int
a2369ed3 2523non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 2524{
dfbdccdb 2525 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
2526 && ! logical_operand (op, mode)
2527 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
2528}
2529
19ba8161 2530/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
2531 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
2532 Reject all ones and all zeros, since these should have been optimized
2533 away and confuse the making of MB and ME. */
2534
2535int
a2369ed3 2536mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 2537{
02071907 2538 HOST_WIDE_INT c, lsb;
9878760c 2539
19ba8161
DE
2540 if (GET_CODE (op) != CONST_INT)
2541 return 0;
2542
2543 c = INTVAL (op);
2544
57deb3a1
AM
2545 /* Fail in 64-bit mode if the mask wraps around because the upper
2546 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
2547 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
2548 return 0;
2549
c5059423
AM
2550 /* We don't change the number of transitions by inverting,
2551 so make sure we start with the LS bit zero. */
2552 if (c & 1)
2553 c = ~c;
2554
2555 /* Reject all zeros or all ones. */
2556 if (c == 0)
9878760c
RK
2557 return 0;
2558
c5059423
AM
2559 /* Find the first transition. */
2560 lsb = c & -c;
2561
2562 /* Invert to look for a second transition. */
2563 c = ~c;
9878760c 2564
c5059423
AM
2565 /* Erase first transition. */
2566 c &= -lsb;
9878760c 2567
c5059423
AM
2568 /* Find the second transition (if any). */
2569 lsb = c & -c;
2570
2571 /* Match if all the bits above are 1's (or c is zero). */
2572 return c == -lsb;
9878760c
RK
2573}
2574
0ba1b2ff
AM
2575/* Return 1 for the PowerPC64 rlwinm corner case. */
2576
2577int
a2369ed3 2578mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2579{
2580 HOST_WIDE_INT c, lsb;
2581
2582 if (GET_CODE (op) != CONST_INT)
2583 return 0;
2584
2585 c = INTVAL (op);
2586
2587 if ((c & 0x80000001) != 0x80000001)
2588 return 0;
2589
2590 c = ~c;
2591 if (c == 0)
2592 return 0;
2593
2594 lsb = c & -c;
2595 c = ~c;
2596 c &= -lsb;
2597 lsb = c & -c;
2598 return c == -lsb;
2599}
2600
a260abc9
DE
2601/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2602 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2603 Reject all zeros, since zero should have been optimized away and
2604 confuses the making of MB and ME. */
9878760c
RK
2605
2606int
a2369ed3 2607mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2608{
2609 if (GET_CODE (op) == CONST_INT)
2610 {
02071907 2611 HOST_WIDE_INT c, lsb;
a260abc9 2612
c5059423 2613 c = INTVAL (op);
a260abc9 2614
0ba1b2ff 2615 /* Reject all zeros. */
c5059423 2616 if (c == 0)
e2c953b6
DE
2617 return 0;
2618
0ba1b2ff
AM
2619 /* We don't change the number of transitions by inverting,
2620 so make sure we start with the LS bit zero. */
2621 if (c & 1)
2622 c = ~c;
2623
c5059423
AM
2624 /* Find the transition, and check that all bits above are 1's. */
2625 lsb = c & -c;
e3981aab
DE
2626
2627 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2628 return c == -lsb;
e2c953b6 2629 }
0ba1b2ff
AM
2630 return 0;
2631}
2632
2633/* Like mask64_operand, but allow up to three transitions. This
2634 predicate is used by insn patterns that generate two rldicl or
2635 rldicr machine insns. */
2636
2637int
a2369ed3 2638mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2639{
2640 if (GET_CODE (op) == CONST_INT)
a260abc9 2641 {
0ba1b2ff 2642 HOST_WIDE_INT c, lsb;
a260abc9 2643
0ba1b2ff 2644 c = INTVAL (op);
a260abc9 2645
0ba1b2ff
AM
2646 /* Disallow all zeros. */
2647 if (c == 0)
2648 return 0;
a260abc9 2649
0ba1b2ff
AM
2650 /* We don't change the number of transitions by inverting,
2651 so make sure we start with the LS bit zero. */
2652 if (c & 1)
2653 c = ~c;
a260abc9 2654
0ba1b2ff
AM
2655 /* Find the first transition. */
2656 lsb = c & -c;
a260abc9 2657
0ba1b2ff
AM
2658 /* Invert to look for a second transition. */
2659 c = ~c;
2660
2661 /* Erase first transition. */
2662 c &= -lsb;
2663
2664 /* Find the second transition. */
2665 lsb = c & -c;
2666
2667 /* Invert to look for a third transition. */
2668 c = ~c;
2669
2670 /* Erase second transition. */
2671 c &= -lsb;
2672
2673 /* Find the third transition (if any). */
2674 lsb = c & -c;
2675
2676 /* Match if all the bits above are 1's (or c is zero). */
2677 return c == -lsb;
2678 }
2679 return 0;
2680}
2681
2682/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2683 implement ANDing by the mask IN. */
2684void
a2369ed3 2685build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2686{
2687#if HOST_BITS_PER_WIDE_INT >= 64
2688 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2689 int shift;
2690
2691 if (GET_CODE (in) != CONST_INT)
2692 abort ();
2693
2694 c = INTVAL (in);
2695 if (c & 1)
2696 {
2697 /* Assume c initially something like 0x00fff000000fffff. The idea
2698 is to rotate the word so that the middle ^^^^^^ group of zeros
2699 is at the MS end and can be cleared with an rldicl mask. We then
2700 rotate back and clear off the MS ^^ group of zeros with a
2701 second rldicl. */
2702 c = ~c; /* c == 0xff000ffffff00000 */
2703 lsb = c & -c; /* lsb == 0x0000000000100000 */
2704 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2705 c = ~c; /* c == 0x00fff000000fffff */
2706 c &= -lsb; /* c == 0x00fff00000000000 */
2707 lsb = c & -c; /* lsb == 0x0000100000000000 */
2708 c = ~c; /* c == 0xff000fffffffffff */
2709 c &= -lsb; /* c == 0xff00000000000000 */
2710 shift = 0;
2711 while ((lsb >>= 1) != 0)
2712 shift++; /* shift == 44 on exit from loop */
2713 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2714 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2715 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2716 }
2717 else
0ba1b2ff
AM
2718 {
2719 /* Assume c initially something like 0xff000f0000000000. The idea
2720 is to rotate the word so that the ^^^ middle group of zeros
2721 is at the LS end and can be cleared with an rldicr mask. We then
2722 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2723 a second rldicr. */
2724 lsb = c & -c; /* lsb == 0x0000010000000000 */
2725 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2726 c = ~c; /* c == 0x00fff0ffffffffff */
2727 c &= -lsb; /* c == 0x00fff00000000000 */
2728 lsb = c & -c; /* lsb == 0x0000100000000000 */
2729 c = ~c; /* c == 0xff000fffffffffff */
2730 c &= -lsb; /* c == 0xff00000000000000 */
2731 shift = 0;
2732 while ((lsb >>= 1) != 0)
2733 shift++; /* shift == 44 on exit from loop */
2734 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2735 m1 >>= shift; /* m1 == 0x0000000000000fff */
2736 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2737 }
2738
2739 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2740 masks will be all 1's. We are guaranteed more than one transition. */
2741 out[0] = GEN_INT (64 - shift);
2742 out[1] = GEN_INT (m1);
2743 out[2] = GEN_INT (shift);
2744 out[3] = GEN_INT (m2);
2745#else
045572c7
GK
2746 (void)in;
2747 (void)out;
0ba1b2ff
AM
2748 abort ();
2749#endif
a260abc9
DE
2750}
2751
2752/* Return 1 if the operand is either a non-special register or a constant
2753 that can be used as the operand of a PowerPC64 logical AND insn. */
2754
2755int
a2369ed3 2756and64_operand (rtx op, enum machine_mode mode)
9878760c 2757{
a4f6c312 2758 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2759 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2760
2761 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2762}
2763
0ba1b2ff
AM
2764/* Like the above, but also match constants that can be implemented
2765 with two rldicl or rldicr insns. */
2766
2767int
a2369ed3 2768and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2769{
a3c9585f 2770 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2771 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2772
2773 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2774}
2775
a260abc9
DE
2776/* Return 1 if the operand is either a non-special register or a
2777 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2778
2779int
a2369ed3 2780and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2781{
a4f6c312 2782 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2783 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2784
2785 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2786}
2787
9878760c
RK
2788/* Return 1 if the operand is a general register or memory operand. */
2789
2790int
a2369ed3 2791reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2792{
b6c9286a
MM
2793 return (gpc_reg_operand (op, mode)
2794 || memory_operand (op, mode)
4c81e946 2795 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2796 || volatile_mem_operand (op, mode));
9878760c
RK
2797}
2798
a7a813f7 2799/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2800 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2801 instruction. */
2802
2803int
a2369ed3 2804lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2805{
2806 rtx inner = op;
2807
2808 if (reload_completed && GET_CODE (inner) == SUBREG)
2809 inner = SUBREG_REG (inner);
f676971a 2810
a7a813f7
RK
2811 return gpc_reg_operand (inner, mode)
2812 || (memory_operand (inner, mode)
2813 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2814 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2815 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2816 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2817 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2818}
2819
cc4d5fec
JH
2820/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2821
2822int
a2369ed3 2823symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2824{
2825 if (mode != VOIDmode && GET_MODE (op) != mode)
2826 return 0;
2827
473f51b6
DE
2828 return (GET_CODE (op) == SYMBOL_REF
2829 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2830}
2831
9878760c 2832/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2833 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2834
2835int
a2369ed3 2836call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2837{
2838 if (mode != VOIDmode && GET_MODE (op) != mode)
2839 return 0;
2840
2841 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2842 || (GET_CODE (op) == REG
2843 && (REGNO (op) == LINK_REGISTER_REGNUM
2844 || REGNO (op) == COUNT_REGISTER_REGNUM
2845 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2846}
2847
2af3d377 2848/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2849 this file. */
2af3d377
RK
2850
2851int
f676971a 2852current_file_function_operand (rtx op,
a2369ed3 2853 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2854{
473f51b6
DE
2855 return (GET_CODE (op) == SYMBOL_REF
2856 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2857 && (SYMBOL_REF_LOCAL_P (op)
2858 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2859}
2860
9878760c
RK
2861/* Return 1 if this operand is a valid input for a move insn. */
2862
2863int
a2369ed3 2864input_operand (rtx op, enum machine_mode mode)
9878760c 2865{
eb4e8003 2866 /* Memory is always valid. */
9878760c
RK
2867 if (memory_operand (op, mode))
2868 return 1;
2869
eb4e8003
RK
2870 /* For floating-point, easy constants are valid. */
2871 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2872 && CONSTANT_P (op)
2873 && easy_fp_constant (op, mode))
2874 return 1;
2875
4e74d8ec
MM
2876 /* Allow any integer constant. */
2877 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2878 && (GET_CODE (op) == CONST_INT
e675f625 2879 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2880 return 1;
2881
d744e06e
AH
2882 /* Allow easy vector constants. */
2883 if (GET_CODE (op) == CONST_VECTOR
2884 && easy_vector_constant (op, mode))
2885 return 1;
2886
eb4e8003
RK
2887 /* For floating-point or multi-word mode, the only remaining valid type
2888 is a register. */
9878760c
RK
2889 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2890 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2891 return register_operand (op, mode);
9878760c 2892
88fe15a1
RK
2893 /* The only cases left are integral modes one word or smaller (we
2894 do not get called for MODE_CC values). These can be in any
2895 register. */
2896 if (register_operand (op, mode))
a8b3aeda 2897 return 1;
88fe15a1 2898
84cf9dda 2899 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2900 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2901 return 1;
2902
9ebbca7d 2903 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2904 if (toc_relative_expr_p (op))
b6c9286a
MM
2905 return 1;
2906
88228c4b
MM
2907 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2908 to be valid. */
f607bc57 2909 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2910 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2911 && small_data_operand (op, Pmode))
2912 return 1;
2913
042259f2 2914 return 0;
9878760c 2915}
7509c759 2916
95727fb8
AP
2917
2918/* Darwin, AIX increases natural record alignment to doubleword if the first
2919 field is an FP double while the FP fields remain word aligned. */
2920
19d66194 2921unsigned int
95727fb8
AP
2922rs6000_special_round_type_align (tree type, int computed, int specified)
2923{
2924 tree field = TYPE_FIELDS (type);
95727fb8
AP
2925
2926 /* Skip all the static variables only if ABI is greater than
71cc389b 2927 1 or equal to 0. */
3ce5437a 2928 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2929 field = TREE_CHAIN (field);
2930
3ce5437a 2931 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2932 return MAX (computed, specified);
2933
2934 return MAX (MAX (computed, specified), 64);
2935}
2936
a4f6c312 2937/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2938
2939int
f676971a 2940small_data_operand (rtx op ATTRIBUTE_UNUSED,
a2369ed3 2941 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2942{
38c1f2d7 2943#if TARGET_ELF
5f59ecb7 2944 rtx sym_ref;
7509c759 2945
d9407988 2946 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2947 return 0;
a54d04b7 2948
f607bc57 2949 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2950 return 0;
2951
88228c4b
MM
2952 if (GET_CODE (op) == SYMBOL_REF)
2953 sym_ref = op;
2954
2955 else if (GET_CODE (op) != CONST
2956 || GET_CODE (XEXP (op, 0)) != PLUS
2957 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2958 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2959 return 0;
2960
88228c4b 2961 else
dbf55e53
MM
2962 {
2963 rtx sum = XEXP (op, 0);
2964 HOST_WIDE_INT summand;
2965
2966 /* We have to be careful here, because it is the referenced address
2967 that must be 32k from _SDA_BASE_, not just the symbol. */
2968 summand = INTVAL (XEXP (sum, 1));
307b599c 2969 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2970 return 0;
2971
2972 sym_ref = XEXP (sum, 0);
2973 }
88228c4b 2974
20bfcd69 2975 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2976#else
2977 return 0;
2978#endif
7509c759 2979}
46c07df8 2980
d2288d5d
HP
2981/* Return true, if operand is a memory operand and has a
2982 displacement divisible by 4. */
2983
2984int
2985word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2986{
2987 rtx addr;
2988 int off = 0;
2989
2990 if (!memory_operand (op, mode))
2991 return 0;
2992
2993 addr = XEXP (op, 0);
2994 if (GET_CODE (addr) == PLUS
2995 && GET_CODE (XEXP (addr, 0)) == REG
2996 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2997 off = INTVAL (XEXP (addr, 1));
2998
2999 return (off % 4) == 0;
3000}
3001
3a1f863f 3002/* Return true if either operand is a general purpose register. */
46c07df8 3003
3a1f863f
DE
3004bool
3005gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 3006{
3a1f863f
DE
3007 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
3008 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
3009}
3010
9ebbca7d 3011\f
4d588c14
RH
3012/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
3013
f676971a
EC
3014static int
3015constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d 3016{
f676971a 3017 switch (GET_CODE(op))
9ebbca7d
GK
3018 {
3019 case SYMBOL_REF:
c4501e62
JJ
3020 if (RS6000_SYMBOL_REF_TLS_P (op))
3021 return 0;
3022 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
3023 {
3024 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
3025 {
3026 *have_sym = 1;
3027 return 1;
3028 }
3029 else
3030 return 0;
3031 }
3032 else if (! strcmp (XSTR (op, 0), toc_label_name))
3033 {
3034 *have_toc = 1;
3035 return 1;
3036 }
3037 else
3038 return 0;
9ebbca7d
GK
3039 case PLUS:
3040 case MINUS:
c1f11548
DE
3041 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
3042 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 3043 case CONST:
a4f6c312 3044 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 3045 case CONST_INT:
a4f6c312 3046 return 1;
9ebbca7d 3047 default:
a4f6c312 3048 return 0;
9ebbca7d
GK
3049 }
3050}
3051
4d588c14 3052static bool
a2369ed3 3053constant_pool_expr_p (rtx op)
9ebbca7d
GK
3054{
3055 int have_sym = 0;
3056 int have_toc = 0;
3057 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
3058}
3059
4d588c14 3060static bool
a2369ed3 3061toc_relative_expr_p (rtx op)
9ebbca7d 3062{
4d588c14
RH
3063 int have_sym = 0;
3064 int have_toc = 0;
3065 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
3066}
3067
4d588c14 3068bool
a2369ed3 3069legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
3070{
3071 return (TARGET_TOC
3072 && GET_CODE (x) == PLUS
3073 && GET_CODE (XEXP (x, 0)) == REG
3074 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
3075 && constant_pool_expr_p (XEXP (x, 1)));
3076}
3077
3078static bool
a2369ed3 3079legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
3080{
3081 return (DEFAULT_ABI == ABI_V4
3082 && !flag_pic && !TARGET_TOC
3083 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
3084 && small_data_operand (x, mode));
3085}
3086
60cdabab
DE
3087/* SPE offset addressing is limited to 5-bits worth of double words. */
3088#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
3089
76d2b81d
DJ
3090bool
3091rs6000_legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3092{
3093 unsigned HOST_WIDE_INT offset, extra;
3094
3095 if (GET_CODE (x) != PLUS)
3096 return false;
3097 if (GET_CODE (XEXP (x, 0)) != REG)
3098 return false;
3099 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3100 return false;
60cdabab
DE
3101 if (legitimate_constant_pool_address_p (x))
3102 return true;
4d588c14
RH
3103 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3104 return false;
3105
3106 offset = INTVAL (XEXP (x, 1));
3107 extra = 0;
3108 switch (mode)
3109 {
3110 case V16QImode:
3111 case V8HImode:
3112 case V4SFmode:
3113 case V4SImode:
3114 /* AltiVec vector modes. Only reg+reg addressing is valid here,
3115 which leaves the only valid constant offset of zero, which by
3116 canonicalization rules is also invalid. */
3117 return false;
3118
3119 case V4HImode:
3120 case V2SImode:
3121 case V1DImode:
3122 case V2SFmode:
3123 /* SPE vector modes. */
3124 return SPE_CONST_OFFSET_OK (offset);
3125
3126 case DFmode:
3127 case DImode:
3364872d 3128 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
3129 extra = 4;
3130 else if (offset & 3)
3131 return false;
3132 break;
3133
3134 case TFmode:
3135 case TImode:
3364872d 3136 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
3137 extra = 12;
3138 else if (offset & 3)
3139 return false;
3140 else
3141 extra = 8;
3142 break;
3143
3144 default:
3145 break;
3146 }
3147
b1917422
AM
3148 offset += 0x8000;
3149 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
3150}
3151
3152static bool
a2369ed3 3153legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
3154{
3155 rtx op0, op1;
3156
3157 if (GET_CODE (x) != PLUS)
3158 return false;
3159 op0 = XEXP (x, 0);
3160 op1 = XEXP (x, 1);
3161
3162 if (!REG_P (op0) || !REG_P (op1))
3163 return false;
3164
3165 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
3166 && INT_REG_OK_FOR_INDEX_P (op1, strict))
3167 || (INT_REG_OK_FOR_BASE_P (op1, strict)
3168 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
3169}
3170
4d588c14 3171static inline bool
a2369ed3 3172legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
3173{
3174 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
3175}
3176
4c81e946
FJ
3177static bool
3178macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
3179{
3180 if (!TARGET_MACHO || !flag_pic
3181 || mode != SImode || GET_CODE(x) != MEM)
3182 return false;
3183 x = XEXP (x, 0);
3184
3185 if (GET_CODE (x) != LO_SUM)
3186 return false;
3187 if (GET_CODE (XEXP (x, 0)) != REG)
3188 return false;
3189 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
3190 return false;
3191 x = XEXP (x, 1);
3192
3193 return CONSTANT_P (x);
3194}
3195
4d588c14 3196static bool
a2369ed3 3197legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
3198{
3199 if (GET_CODE (x) != LO_SUM)
3200 return false;
3201 if (GET_CODE (XEXP (x, 0)) != REG)
3202 return false;
3203 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
3204 return false;
3205 x = XEXP (x, 1);
3206
8622e235 3207 if (TARGET_ELF || TARGET_MACHO)
4d588c14 3208 {
a29077da 3209 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
3210 return false;
3211 if (TARGET_TOC)
3212 return false;
3213 if (GET_MODE_NUNITS (mode) != 1)
3214 return false;
c1e55850 3215 if (GET_MODE_BITSIZE (mode) > 64)
4d588c14
RH
3216 return false;
3217
3218 return CONSTANT_P (x);
3219 }
3220
3221 return false;
3222}
3223
3224
9ebbca7d
GK
3225/* Try machine-dependent ways of modifying an illegitimate address
3226 to be legitimate. If we find one, return the new, valid address.
3227 This is used from only one place: `memory_address' in explow.c.
3228
a4f6c312
SS
3229 OLDX is the address as it was before break_out_memory_refs was
3230 called. In some cases it is useful to look at this to decide what
3231 needs to be done.
9ebbca7d 3232
a4f6c312 3233 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 3234
a4f6c312
SS
3235 It is always safe for this function to do nothing. It exists to
3236 recognize opportunities to optimize the output.
9ebbca7d
GK
3237
3238 On RS/6000, first check for the sum of a register with a constant
3239 integer that is out of range. If so, generate code to add the
3240 constant with the low-order 16 bits masked to the register and force
3241 this result into another register (this can be done with `cau').
3242 Then generate an address of REG+(CONST&0xffff), allowing for the
3243 possibility of bit 16 being a one.
3244
3245 Then check for the sum of a register and something not constant, try to
3246 load the other things into a register and return the sum. */
4d588c14 3247
9ebbca7d 3248rtx
a2369ed3
DJ
3249rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
3250 enum machine_mode mode)
0ac081f6 3251{
c4501e62
JJ
3252 if (GET_CODE (x) == SYMBOL_REF)
3253 {
3254 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
3255 if (model != 0)
3256 return rs6000_legitimize_tls_address (x, model);
3257 }
3258
f676971a 3259 if (GET_CODE (x) == PLUS
9ebbca7d
GK
3260 && GET_CODE (XEXP (x, 0)) == REG
3261 && GET_CODE (XEXP (x, 1)) == CONST_INT
3262 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
f676971a 3263 {
9ebbca7d
GK
3264 HOST_WIDE_INT high_int, low_int;
3265 rtx sum;
a65c591c
DE
3266 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
3267 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
3268 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
3269 GEN_INT (high_int)), 0);
3270 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
3271 }
f676971a 3272 else if (GET_CODE (x) == PLUS
9ebbca7d
GK
3273 && GET_CODE (XEXP (x, 0)) == REG
3274 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 3275 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
3276 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3277 || TARGET_POWERPC64
fcce224d 3278 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
3279 && (TARGET_POWERPC64 || mode != DImode)
3280 && mode != TImode)
3281 {
3282 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
3283 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
3284 }
0ac081f6
AH
3285 else if (ALTIVEC_VECTOR_MODE (mode))
3286 {
3287 rtx reg;
3288
3289 /* Make sure both operands are registers. */
3290 if (GET_CODE (x) == PLUS)
9f85ed45 3291 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
3292 force_reg (Pmode, XEXP (x, 1)));
3293
3294 reg = force_reg (Pmode, x);
3295 return reg;
3296 }
a3170dc6
AH
3297 else if (SPE_VECTOR_MODE (mode))
3298 {
3299 /* We accept [reg + reg] and [reg + OFFSET]. */
3300
3301 if (GET_CODE (x) == PLUS)
3302 {
3303 rtx op1 = XEXP (x, 0);
3304 rtx op2 = XEXP (x, 1);
3305
3306 op1 = force_reg (Pmode, op1);
3307
3308 if (GET_CODE (op2) != REG
3309 && (GET_CODE (op2) != CONST_INT
3310 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
3311 op2 = force_reg (Pmode, op2);
3312
3313 return gen_rtx_PLUS (Pmode, op1, op2);
3314 }
3315
3316 return force_reg (Pmode, x);
3317 }
f1384257
AM
3318 else if (TARGET_ELF
3319 && TARGET_32BIT
3320 && TARGET_NO_TOC
3321 && ! flag_pic
9ebbca7d 3322 && GET_CODE (x) != CONST_INT
f676971a 3323 && GET_CODE (x) != CONST_DOUBLE
9ebbca7d 3324 && CONSTANT_P (x)
6ac7bf2c
GK
3325 && GET_MODE_NUNITS (mode) == 1
3326 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 3327 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
3328 {
3329 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3330 emit_insn (gen_elf_high (reg, x));
3331 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 3332 }
ee890fe2
SS
3333 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
3334 && ! flag_pic
ab82a49f
AP
3335#if TARGET_MACHO
3336 && ! MACHO_DYNAMIC_NO_PIC_P
3337#endif
ee890fe2 3338 && GET_CODE (x) != CONST_INT
f676971a 3339 && GET_CODE (x) != CONST_DOUBLE
ee890fe2 3340 && CONSTANT_P (x)
a3170dc6 3341 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
f676971a 3342 && mode != DImode
ee890fe2
SS
3343 && mode != TImode)
3344 {
3345 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
3346 emit_insn (gen_macho_high (reg, x));
3347 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 3348 }
f676971a 3349 else if (TARGET_TOC
4d588c14 3350 && constant_pool_expr_p (x)
a9098fd0 3351 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
3352 {
3353 return create_TOC_reference (x);
3354 }
3355 else
3356 return NULL_RTX;
3357}
258bfae2 3358
c973d557
JJ
3359/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
3360 We need to emit DTP-relative relocations. */
3361
3362void
3363rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
3364{
3365 switch (size)
3366 {
3367 case 4:
3368 fputs ("\t.long\t", file);
3369 break;
3370 case 8:
3371 fputs (DOUBLE_INT_ASM_OP, file);
3372 break;
3373 default:
3374 abort ();
3375 }
3376 output_addr_const (file, x);
3377 fputs ("@dtprel+0x8000", file);
3378}
3379
c4501e62
JJ
3380/* Construct the SYMBOL_REF for the tls_get_addr function. */
3381
3382static GTY(()) rtx rs6000_tls_symbol;
3383static rtx
863d938c 3384rs6000_tls_get_addr (void)
c4501e62
JJ
3385{
3386 if (!rs6000_tls_symbol)
3387 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
3388
3389 return rs6000_tls_symbol;
3390}
3391
3392/* Construct the SYMBOL_REF for TLS GOT references. */
3393
3394static GTY(()) rtx rs6000_got_symbol;
3395static rtx
863d938c 3396rs6000_got_sym (void)
c4501e62
JJ
3397{
3398 if (!rs6000_got_symbol)
3399 {
3400 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
3401 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
3402 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
f676971a 3403 }
c4501e62
JJ
3404
3405 return rs6000_got_symbol;
3406}
3407
3408/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
3409 this (thread-local) address. */
3410
3411static rtx
a2369ed3 3412rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
3413{
3414 rtx dest, insn;
3415
3416 dest = gen_reg_rtx (Pmode);
3417 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
3418 {
3419 rtx tlsreg;
3420
3421 if (TARGET_64BIT)
3422 {
3423 tlsreg = gen_rtx_REG (Pmode, 13);
3424 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
3425 }
3426 else
3427 {
3428 tlsreg = gen_rtx_REG (Pmode, 2);
3429 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
3430 }
3431 emit_insn (insn);
3432 }
3433 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
3434 {
3435 rtx tlsreg, tmp;
3436
3437 tmp = gen_reg_rtx (Pmode);
3438 if (TARGET_64BIT)
3439 {
3440 tlsreg = gen_rtx_REG (Pmode, 13);
3441 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
3442 }
3443 else
3444 {
3445 tlsreg = gen_rtx_REG (Pmode, 2);
3446 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
3447 }
3448 emit_insn (insn);
3449 if (TARGET_64BIT)
3450 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3451 else
3452 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3453 emit_insn (insn);
3454 }
3455 else
3456 {
3457 rtx r3, got, tga, tmp1, tmp2, eqv;
3458
3459 if (TARGET_64BIT)
3460 got = gen_rtx_REG (Pmode, TOC_REGISTER);
3461 else
3462 {
3463 if (flag_pic == 1)
3464 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3465 else
3466 {
3467 rtx gsym = rs6000_got_sym ();
3468 got = gen_reg_rtx (Pmode);
3469 if (flag_pic == 0)
3470 rs6000_emit_move (got, gsym, Pmode);
3471 else
3472 {
3473 char buf[30];
3474 static int tls_got_labelno = 0;
3475 rtx tempLR, lab, tmp3, mem;
3476 rtx first, last;
3477
3478 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
3479 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
3480 tempLR = gen_reg_rtx (Pmode);
3481 tmp1 = gen_reg_rtx (Pmode);
3482 tmp2 = gen_reg_rtx (Pmode);
3483 tmp3 = gen_reg_rtx (Pmode);
542a8afa 3484 mem = gen_const_mem (Pmode, tmp1);
c4501e62
JJ
3485
3486 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
3487 gsym));
3488 emit_move_insn (tmp1, tempLR);
3489 emit_move_insn (tmp2, mem);
3490 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
3491 last = emit_move_insn (got, tmp3);
3492 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
3493 REG_NOTES (last));
3494 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3495 REG_NOTES (first));
3496 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3497 REG_NOTES (last));
3498 }
3499 }
3500 }
3501
3502 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3503 {
3504 r3 = gen_rtx_REG (Pmode, 3);
3505 if (TARGET_64BIT)
3506 insn = gen_tls_gd_64 (r3, got, addr);
3507 else
3508 insn = gen_tls_gd_32 (r3, got, addr);
3509 start_sequence ();
3510 emit_insn (insn);
3511 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3512 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3513 insn = emit_call_insn (insn);
3514 CONST_OR_PURE_CALL_P (insn) = 1;
3515 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3516 insn = get_insns ();
3517 end_sequence ();
3518 emit_libcall_block (insn, dest, r3, addr);
3519 }
3520 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3521 {
3522 r3 = gen_rtx_REG (Pmode, 3);
3523 if (TARGET_64BIT)
3524 insn = gen_tls_ld_64 (r3, got);
3525 else
3526 insn = gen_tls_ld_32 (r3, got);
3527 start_sequence ();
3528 emit_insn (insn);
3529 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3530 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3531 insn = emit_call_insn (insn);
3532 CONST_OR_PURE_CALL_P (insn) = 1;
3533 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3534 insn = get_insns ();
3535 end_sequence ();
3536 tmp1 = gen_reg_rtx (Pmode);
3537 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3538 UNSPEC_TLSLD);
3539 emit_libcall_block (insn, tmp1, r3, eqv);
3540 if (rs6000_tls_size == 16)
3541 {
3542 if (TARGET_64BIT)
3543 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3544 else
3545 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3546 }
3547 else if (rs6000_tls_size == 32)
3548 {
3549 tmp2 = gen_reg_rtx (Pmode);
3550 if (TARGET_64BIT)
3551 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3552 else
3553 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3554 emit_insn (insn);
3555 if (TARGET_64BIT)
3556 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3557 else
3558 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3559 }
3560 else
3561 {
3562 tmp2 = gen_reg_rtx (Pmode);
3563 if (TARGET_64BIT)
3564 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3565 else
3566 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3567 emit_insn (insn);
3568 insn = gen_rtx_SET (Pmode, dest,
3569 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3570 }
3571 emit_insn (insn);
3572 }
3573 else
3574 {
3575 /* IE, or 64 bit offset LE. */
3576 tmp2 = gen_reg_rtx (Pmode);
3577 if (TARGET_64BIT)
3578 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3579 else
3580 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3581 emit_insn (insn);
3582 if (TARGET_64BIT)
3583 insn = gen_tls_tls_64 (dest, tmp2, addr);
3584 else
3585 insn = gen_tls_tls_32 (dest, tmp2, addr);
3586 emit_insn (insn);
3587 }
3588 }
3589
3590 return dest;
3591}
3592
3593/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3594 instruction definitions. */
3595
3596int
a2369ed3 3597rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3598{
3599 return RS6000_SYMBOL_REF_TLS_P (x);
3600}
3601
3602/* Return 1 if X contains a thread-local symbol. */
3603
3604bool
a2369ed3 3605rs6000_tls_referenced_p (rtx x)
c4501e62 3606{
cd413cab
AP
3607 if (! TARGET_HAVE_TLS)
3608 return false;
3609
c4501e62
JJ
3610 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3611}
3612
3613/* Return 1 if *X is a thread-local symbol. This is the same as
3614 rs6000_tls_symbol_ref except for the type of the unused argument. */
3615
3616static inline int
a2369ed3 3617rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3618{
3619 return RS6000_SYMBOL_REF_TLS_P (*x);
3620}
3621
24ea750e
DJ
3622/* The convention appears to be to define this wherever it is used.
3623 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3624 is now used here. */
3625#ifndef REG_MODE_OK_FOR_BASE_P
3626#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3627#endif
3628
3629/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3630 replace the input X, or the original X if no replacement is called for.
3631 The output parameter *WIN is 1 if the calling macro should goto WIN,
3632 0 if it should not.
3633
3634 For RS/6000, we wish to handle large displacements off a base
3635 register by splitting the addend across an addiu/addis and the mem insn.
3636 This cuts number of extra insns needed from 3 to 1.
3637
3638 On Darwin, we use this to generate code for floating point constants.
3639 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3640 The Darwin code is inside #if TARGET_MACHO because only then is
3641 machopic_function_base_name() defined. */
3642rtx
f676971a 3643rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
a2369ed3 3644 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e 3645{
f676971a 3646 /* We must recognize output that we have already generated ourselves. */
24ea750e
DJ
3647 if (GET_CODE (x) == PLUS
3648 && GET_CODE (XEXP (x, 0)) == PLUS
3649 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3650 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3651 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3652 {
3653 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3654 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3655 opnum, (enum reload_type)type);
3656 *win = 1;
3657 return x;
3658 }
3deb2758 3659
24ea750e
DJ
3660#if TARGET_MACHO
3661 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3662 && GET_CODE (x) == LO_SUM
3663 && GET_CODE (XEXP (x, 0)) == PLUS
3664 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3665 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3666 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3667 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3668 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3669 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3670 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3671 {
3672 /* Result of previous invocation of this function on Darwin
6f317ef3 3673 floating point constant. */
24ea750e
DJ
3674 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3675 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3676 opnum, (enum reload_type)type);
3677 *win = 1;
3678 return x;
3679 }
3680#endif
3681 if (GET_CODE (x) == PLUS
3682 && GET_CODE (XEXP (x, 0)) == REG
3683 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3684 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3685 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3686 && !SPE_VECTOR_MODE (mode)
78c875e8 3687 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3688 {
3689 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3690 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3691 HOST_WIDE_INT high
3692 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3693
3694 /* Check for 32-bit overflow. */
3695 if (high + low != val)
3696 {
3697 *win = 0;
3698 return x;
3699 }
3700
3701 /* Reload the high part into a base reg; leave the low part
3702 in the mem directly. */
3703
3704 x = gen_rtx_PLUS (GET_MODE (x),
3705 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3706 GEN_INT (high)),
3707 GEN_INT (low));
3708
3709 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3710 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3711 opnum, (enum reload_type)type);
3712 *win = 1;
3713 return x;
3714 }
3715#if TARGET_MACHO
3716 if (GET_CODE (x) == SYMBOL_REF
3717 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3718 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3719 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3720 /* Don't do this for TFmode, since the result isn't offsettable. */
3721 && mode != TFmode)
24ea750e 3722 {
a29077da
GK
3723 if (flag_pic)
3724 {
3725 rtx offset = gen_rtx_CONST (Pmode,
3726 gen_rtx_MINUS (Pmode, x,
11abc112 3727 machopic_function_base_sym ()));
a29077da
GK
3728 x = gen_rtx_LO_SUM (GET_MODE (x),
3729 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3730 gen_rtx_HIGH (Pmode, offset)), offset);
3731 }
3732 else
3733 x = gen_rtx_LO_SUM (GET_MODE (x),
3734 gen_rtx_HIGH (Pmode, x), x);
3735
24ea750e 3736 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3737 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3738 opnum, (enum reload_type)type);
24ea750e
DJ
3739 *win = 1;
3740 return x;
3741 }
3742#endif
3743 if (TARGET_TOC
4d588c14 3744 && constant_pool_expr_p (x)
c1f11548 3745 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3746 {
3747 (x) = create_TOC_reference (x);
3748 *win = 1;
3749 return x;
3750 }
3751 *win = 0;
3752 return x;
f676971a 3753}
24ea750e 3754
258bfae2
FS
3755/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3756 that is a valid memory address for an instruction.
3757 The MODE argument is the machine mode for the MEM expression
3758 that wants to use this address.
3759
3760 On the RS/6000, there are four valid address: a SYMBOL_REF that
3761 refers to a constant pool entry of an address (or the sum of it
3762 plus a constant), a short (16-bit signed) constant plus a register,
3763 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3764 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3765 we must ensure that both words are addressable or PowerPC64 with offset
3766 word aligned.
3767
3768 For modes spanning multiple registers (DFmode in 32-bit GPRs,
76d2b81d 3769 32-bit DImode, TImode, TFmode), indexed addressing cannot be used because
258bfae2
FS
3770 adjacent memory cells are accessed by adding word-sized offsets
3771 during assembly output. */
3772int
a2369ed3 3773rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3774{
c4501e62
JJ
3775 if (RS6000_SYMBOL_REF_TLS_P (x))
3776 return 0;
4d588c14 3777 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3778 return 1;
3779 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3780 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3781 && !SPE_VECTOR_MODE (mode)
258bfae2 3782 && TARGET_UPDATE
4d588c14 3783 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3784 return 1;
4d588c14 3785 if (legitimate_small_data_p (mode, x))
258bfae2 3786 return 1;
4d588c14 3787 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3788 return 1;
3789 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3790 if (! reg_ok_strict
3791 && GET_CODE (x) == PLUS
3792 && GET_CODE (XEXP (x, 0)) == REG
708d2456
HP
3793 && (XEXP (x, 0) == virtual_stack_vars_rtx
3794 || XEXP (x, 0) == arg_pointer_rtx)
258bfae2
FS
3795 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3796 return 1;
76d2b81d 3797 if (rs6000_legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3798 return 1;
3799 if (mode != TImode
76d2b81d 3800 && mode != TFmode
a3170dc6
AH
3801 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3802 || TARGET_POWERPC64
fcce224d 3803 || (mode != DFmode && mode != TFmode))
258bfae2 3804 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3805 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3806 return 1;
4d588c14 3807 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3808 return 1;
3809 return 0;
3810}
4d588c14
RH
3811
3812/* Go to LABEL if ADDR (a legitimate address expression)
3813 has an effect that depends on the machine mode it is used for.
3814
3815 On the RS/6000 this is true of all integral offsets (since AltiVec
3816 modes don't allow them) or is a pre-increment or decrement.
3817
3818 ??? Except that due to conceptual problems in offsettable_address_p
3819 we can't really report the problems of integral offsets. So leave
f676971a 3820 this assuming that the adjustable offset must be valid for the
4d588c14
RH
3821 sub-words of a TFmode operand, which is what we had before. */
3822
3823bool
a2369ed3 3824rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3825{
3826 switch (GET_CODE (addr))
3827 {
3828 case PLUS:
3829 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3830 {
3831 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3832 return val + 12 + 0x8000 >= 0x10000;
3833 }
3834 break;
3835
3836 case LO_SUM:
3837 return true;
3838
3839 case PRE_INC:
3840 case PRE_DEC:
3841 return TARGET_UPDATE;
3842
3843 default:
3844 break;
3845 }
3846
3847 return false;
3848}
d8ecbcdb
AH
3849
3850/* Return number of consecutive hard regs needed starting at reg REGNO
3851 to hold something of mode MODE.
3852 This is ordinarily the length in words of a value of mode MODE
3853 but can be less for certain modes in special long registers.
3854
3855 For the SPE, GPRs are 64 bits but only 32 bits are visible in
3856 scalar instructions. The upper 32 bits are only available to the
3857 SIMD instructions.
3858
3859 POWER and PowerPC GPRs hold 32 bits worth;
3860 PowerPC64 GPRs and FPRs point register holds 64 bits worth. */
3861
3862int
3863rs6000_hard_regno_nregs (int regno, enum machine_mode mode)
3864{
3865 if (FP_REGNO_P (regno))
3866 return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD;
3867
3868 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
3869 return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD;
3870
3871 if (ALTIVEC_REGNO_P (regno))
3872 return
3873 (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD;
3874
3875 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3876}
2aa4498c
AH
3877
3878/* Change register usage conditional on target flags. */
3879void
3880rs6000_conditional_register_usage (void)
3881{
3882 int i;
3883
3884 /* Set MQ register fixed (already call_used) if not POWER
3885 architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not
3886 be allocated. */
3887 if (! TARGET_POWER)
3888 fixed_regs[64] = 1;
3889
3890 /* 64-bit AIX reserves GPR13 for thread-private data. */
3891 if (TARGET_64BIT)
3892 fixed_regs[13] = call_used_regs[13]
3893 = call_really_used_regs[13] = 1;
3894
3895 /* Conditionally disable FPRs. */
3896 if (TARGET_SOFT_FLOAT || !TARGET_FPRS)
3897 for (i = 32; i < 64; i++)
3898 fixed_regs[i] = call_used_regs[i]
3899 = call_really_used_regs[i] = 1;
3900
3901 if (DEFAULT_ABI == ABI_V4
3902 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3903 && flag_pic == 2)
3904 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3905
3906 if (DEFAULT_ABI == ABI_V4
3907 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3908 && flag_pic == 1)
3909 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3910 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3911 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3912
3913 if (DEFAULT_ABI == ABI_DARWIN
3914 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
3915 global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3916 = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3917 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3918 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3919
b4db40bf
JJ
3920 if (TARGET_TOC && TARGET_MINIMAL_TOC)
3921 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3922 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3923
2aa4498c
AH
3924 if (TARGET_ALTIVEC)
3925 global_regs[VSCR_REGNO] = 1;
3926
3927 if (TARGET_SPE)
3928 {
3929 global_regs[SPEFSCR_REGNO] = 1;
3930 fixed_regs[FIXED_SCRATCH]
3931 = call_used_regs[FIXED_SCRATCH]
3932 = call_really_used_regs[FIXED_SCRATCH] = 1;
3933 }
3934
3935 if (! TARGET_ALTIVEC)
3936 {
3937 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
3938 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
3939 call_really_used_regs[VRSAVE_REGNO] = 1;
3940 }
3941
3942 if (TARGET_ALTIVEC_ABI)
3943 for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i)
3944 call_used_regs[i] = call_really_used_regs[i] = 1;
3945}
fb4d4348 3946\f
a4f6c312
SS
3947/* Try to output insns to set TARGET equal to the constant C if it can
3948 be done in less than N insns. Do all computations in MODE.
3949 Returns the place where the output has been placed if it can be
3950 done and the insns have been emitted. If it would take more than N
3951 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3952
3953rtx
f676971a 3954rs6000_emit_set_const (rtx dest, enum machine_mode mode,
a2369ed3 3955 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3956{
af8cb5c5 3957 rtx result, insn, set;
2bfcf297
DB
3958 HOST_WIDE_INT c0, c1;
3959
af8cb5c5 3960 if (mode == QImode || mode == HImode)
2bfcf297
DB
3961 {
3962 if (dest == NULL)
3963 dest = gen_reg_rtx (mode);
3964 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3965 return dest;
3966 }
af8cb5c5 3967 else if (mode == SImode)
2bfcf297 3968 {
af8cb5c5
DE
3969 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3970
3971 emit_insn (gen_rtx_SET (VOIDmode, result,
3972 GEN_INT (INTVAL (source)
3973 & (~ (HOST_WIDE_INT) 0xffff))));
3974 emit_insn (gen_rtx_SET (VOIDmode, dest,
3975 gen_rtx_IOR (SImode, result,
3976 GEN_INT (INTVAL (source) & 0xffff))));
3977 result = dest;
2bfcf297 3978 }
af8cb5c5 3979 else if (mode == DImode)
2bfcf297 3980 {
af8cb5c5
DE
3981 if (GET_CODE (source) == CONST_INT)
3982 {
3983 c0 = INTVAL (source);
3984 c1 = -(c0 < 0);
3985 }
3986 else if (GET_CODE (source) == CONST_DOUBLE)
3987 {
2bfcf297 3988#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3989 c0 = CONST_DOUBLE_LOW (source);
3990 c1 = -(c0 < 0);
2bfcf297 3991#else
af8cb5c5
DE
3992 c0 = CONST_DOUBLE_LOW (source);
3993 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3994#endif
af8cb5c5
DE
3995 }
3996 else
3997 abort ();
3998
3999 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
4000 }
4001 else
a4f6c312 4002 abort ();
2bfcf297 4003
af8cb5c5
DE
4004 insn = get_last_insn ();
4005 set = single_set (insn);
4006 if (! CONSTANT_P (SET_SRC (set)))
4007 set_unique_reg_note (insn, REG_EQUAL, source);
4008
4009 return result;
2bfcf297
DB
4010}
4011
4012/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
4013 fall back to a straight forward decomposition. We do this to avoid
4014 exponential run times encountered when looking for longer sequences
4015 with rs6000_emit_set_const. */
4016static rtx
a2369ed3 4017rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
4018{
4019 if (!TARGET_POWERPC64)
4020 {
4021 rtx operand1, operand2;
4022
4023 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
4024 DImode);
4025 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
4026 DImode);
4027 emit_move_insn (operand1, GEN_INT (c1));
4028 emit_move_insn (operand2, GEN_INT (c2));
4029 }
4030 else
4031 {
bc06712d 4032 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 4033
bc06712d 4034 ud1 = c1 & 0xffff;
f921c9c9 4035 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 4036#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 4037 c2 = c1 >> 32;
2bfcf297 4038#endif
bc06712d 4039 ud3 = c2 & 0xffff;
f921c9c9 4040 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 4041
f676971a 4042 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
bc06712d 4043 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 4044 {
bc06712d 4045 if (ud1 & 0x8000)
b78d48dd 4046 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
4047 else
4048 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 4049 }
2bfcf297 4050
f676971a 4051 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
bc06712d 4052 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 4053 {
bc06712d 4054 if (ud2 & 0x8000)
f676971a 4055 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
bc06712d 4056 - 0x80000000));
252b88f7 4057 else
bc06712d
TR
4058 emit_move_insn (dest, GEN_INT (ud2 << 16));
4059 if (ud1 != 0)
4060 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 4061 }
f676971a 4062 else if ((ud4 == 0xffff && (ud3 & 0x8000))
bc06712d
TR
4063 || (ud4 == 0 && ! (ud3 & 0x8000)))
4064 {
4065 if (ud3 & 0x8000)
f676971a 4066 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
bc06712d
TR
4067 - 0x80000000));
4068 else
4069 emit_move_insn (dest, GEN_INT (ud3 << 16));
4070
4071 if (ud2 != 0)
4072 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
4073 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
4074 if (ud1 != 0)
4075 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4076 }
f676971a 4077 else
bc06712d
TR
4078 {
4079 if (ud4 & 0x8000)
f676971a 4080 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
bc06712d
TR
4081 - 0x80000000));
4082 else
4083 emit_move_insn (dest, GEN_INT (ud4 << 16));
4084
4085 if (ud3 != 0)
4086 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 4087
bc06712d
TR
4088 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
4089 if (ud2 != 0)
f676971a
EC
4090 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
4091 GEN_INT (ud2 << 16)));
bc06712d
TR
4092 if (ud1 != 0)
4093 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
4094 }
4095 }
2bfcf297
DB
4096 return dest;
4097}
4098
76d2b81d
DJ
4099/* Helper for the following. Get rid of [r+r] memory refs
4100 in cases where it won't work (TImode, TFmode). */
4101
4102static void
4103rs6000_eliminate_indexed_memrefs (rtx operands[2])
4104{
4105 if (GET_CODE (operands[0]) == MEM
4106 && GET_CODE (XEXP (operands[0], 0)) != REG
4107 && ! reload_in_progress)
4108 operands[0]
4109 = replace_equiv_address (operands[0],
4110 copy_addr_to_reg (XEXP (operands[0], 0)));
4111
4112 if (GET_CODE (operands[1]) == MEM
4113 && GET_CODE (XEXP (operands[1], 0)) != REG
4114 && ! reload_in_progress)
4115 operands[1]
4116 = replace_equiv_address (operands[1],
4117 copy_addr_to_reg (XEXP (operands[1], 0)));
4118}
4119
fb4d4348
GK
4120/* Emit a move from SOURCE to DEST in mode MODE. */
4121void
a2369ed3 4122rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
4123{
4124 rtx operands[2];
4125 operands[0] = dest;
4126 operands[1] = source;
f676971a 4127
fb4d4348
GK
4128 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
4129 if (GET_CODE (operands[1]) == CONST_DOUBLE
4130 && ! FLOAT_MODE_P (mode)
4131 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
4132 {
4133 /* FIXME. This should never happen. */
4134 /* Since it seems that it does, do the safe thing and convert
4135 to a CONST_INT. */
2496c7bd 4136 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
4137 }
4138 if (GET_CODE (operands[1]) == CONST_DOUBLE
4139 && ! FLOAT_MODE_P (mode)
4140 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
4141 && CONST_DOUBLE_LOW (operands[1]) >= 0)
4142 || (CONST_DOUBLE_HIGH (operands[1]) == -1
4143 && CONST_DOUBLE_LOW (operands[1]) < 0)))
4144 abort ();
c9e8cb32
DD
4145
4146 /* Check if GCC is setting up a block move that will end up using FP
4147 registers as temporaries. We must make sure this is acceptable. */
4148 if (GET_CODE (operands[0]) == MEM
4149 && GET_CODE (operands[1]) == MEM
4150 && mode == DImode
41543739
GK
4151 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
4152 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
4153 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
4154 ? 32 : MEM_ALIGN (operands[0])))
4155 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
f676971a 4156 ? 32
41543739
GK
4157 : MEM_ALIGN (operands[1]))))
4158 && ! MEM_VOLATILE_P (operands [0])
4159 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 4160 {
41543739
GK
4161 emit_move_insn (adjust_address (operands[0], SImode, 0),
4162 adjust_address (operands[1], SImode, 0));
4163 emit_move_insn (adjust_address (operands[0], SImode, 4),
4164 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
4165 return;
4166 }
630d42a0 4167
67cef334
DE
4168 if (!no_new_pseudos)
4169 {
4170 if (GET_CODE (operands[1]) == MEM && optimize > 0
4171 && (mode == QImode || mode == HImode || mode == SImode)
4172 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
4173 {
4174 rtx reg = gen_reg_rtx (word_mode);
4175
4176 emit_insn (gen_rtx_SET (word_mode, reg,
4177 gen_rtx_ZERO_EXTEND (word_mode,
4178 operands[1])));
4179 operands[1] = gen_lowpart (mode, reg);
4180 }
4181 if (GET_CODE (operands[0]) != REG)
4182 operands[1] = force_reg (mode, operands[1]);
4183 }
a9098fd0 4184
a3170dc6
AH
4185 if (mode == SFmode && ! TARGET_POWERPC
4186 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 4187 && GET_CODE (operands[0]) == MEM)
fb4d4348 4188 {
ffc14f31
GK
4189 int regnum;
4190
4191 if (reload_in_progress || reload_completed)
4192 regnum = true_regnum (operands[1]);
4193 else if (GET_CODE (operands[1]) == REG)
4194 regnum = REGNO (operands[1]);
4195 else
4196 regnum = -1;
f676971a 4197
fb4d4348
GK
4198 /* If operands[1] is a register, on POWER it may have
4199 double-precision data in it, so truncate it to single
4200 precision. */
4201 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
4202 {
4203 rtx newreg;
4204 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
4205 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
4206 operands[1] = newreg;
4207 }
4208 }
4209
c4501e62
JJ
4210 /* Recognize the case where operand[1] is a reference to thread-local
4211 data and load its address to a register. */
4212 if (GET_CODE (operands[1]) == SYMBOL_REF)
4213 {
4214 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
4215 if (model != 0)
4216 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
4217 }
4218
8f4e6caf
RH
4219 /* Handle the case where reload calls us with an invalid address. */
4220 if (reload_in_progress && mode == Pmode
69ef87e2 4221 && (! general_operand (operands[1], mode)
8f4e6caf
RH
4222 || ! nonimmediate_operand (operands[0], mode)))
4223 goto emit_set;
4224
a9baceb1
GK
4225 /* 128-bit constant floating-point values on Darwin should really be
4226 loaded as two parts. */
4227 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
4228 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
4229 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
4230 {
4231 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
4232 know how to get a DFmode SUBREG of a TFmode. */
4233 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
4234 simplify_gen_subreg (DImode, operands[1], mode, 0),
4235 DImode);
4236 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
4237 GET_MODE_SIZE (DImode)),
4238 simplify_gen_subreg (DImode, operands[1], mode,
4239 GET_MODE_SIZE (DImode)),
4240 DImode);
4241 return;
4242 }
4243
fb4d4348
GK
4244 /* FIXME: In the long term, this switch statement should go away
4245 and be replaced by a sequence of tests based on things like
4246 mode == Pmode. */
4247 switch (mode)
4248 {
4249 case HImode:
4250 case QImode:
4251 if (CONSTANT_P (operands[1])
4252 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 4253 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
4254 break;
4255
06f4e019 4256 case TFmode:
76d2b81d
DJ
4257 rs6000_eliminate_indexed_memrefs (operands);
4258 /* fall through */
4259
fb4d4348
GK
4260 case DFmode:
4261 case SFmode:
f676971a 4262 if (CONSTANT_P (operands[1])
fb4d4348 4263 && ! easy_fp_constant (operands[1], mode))
a9098fd0 4264 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4265 break;
f676971a 4266
0ac081f6
AH
4267 case V16QImode:
4268 case V8HImode:
4269 case V4SFmode:
4270 case V4SImode:
a3170dc6
AH
4271 case V4HImode:
4272 case V2SFmode:
4273 case V2SImode:
00a892b8 4274 case V1DImode:
69ef87e2 4275 if (CONSTANT_P (operands[1])
d744e06e 4276 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
4277 operands[1] = force_const_mem (mode, operands[1]);
4278 break;
f676971a 4279
fb4d4348 4280 case SImode:
a9098fd0 4281 case DImode:
fb4d4348
GK
4282 /* Use default pattern for address of ELF small data */
4283 if (TARGET_ELF
a9098fd0 4284 && mode == Pmode
f607bc57 4285 && DEFAULT_ABI == ABI_V4
f676971a 4286 && (GET_CODE (operands[1]) == SYMBOL_REF
a9098fd0
GK
4287 || GET_CODE (operands[1]) == CONST)
4288 && small_data_operand (operands[1], mode))
fb4d4348
GK
4289 {
4290 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4291 return;
4292 }
4293
f607bc57 4294 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
4295 && mode == Pmode && mode == SImode
4296 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
4297 {
4298 emit_insn (gen_movsi_got (operands[0], operands[1]));
4299 return;
4300 }
4301
ee890fe2 4302 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
4303 && TARGET_NO_TOC
4304 && ! flag_pic
a9098fd0 4305 && mode == Pmode
fb4d4348
GK
4306 && CONSTANT_P (operands[1])
4307 && GET_CODE (operands[1]) != HIGH
4308 && GET_CODE (operands[1]) != CONST_INT)
4309 {
a9098fd0 4310 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
4311
4312 /* If this is a function address on -mcall-aixdesc,
4313 convert it to the address of the descriptor. */
4314 if (DEFAULT_ABI == ABI_AIX
4315 && GET_CODE (operands[1]) == SYMBOL_REF
4316 && XSTR (operands[1], 0)[0] == '.')
4317 {
4318 const char *name = XSTR (operands[1], 0);
4319 rtx new_ref;
4320 while (*name == '.')
4321 name++;
4322 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
4323 CONSTANT_POOL_ADDRESS_P (new_ref)
4324 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 4325 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 4326 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 4327 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
4328 operands[1] = new_ref;
4329 }
7509c759 4330
ee890fe2
SS
4331 if (DEFAULT_ABI == ABI_DARWIN)
4332 {
ab82a49f
AP
4333#if TARGET_MACHO
4334 if (MACHO_DYNAMIC_NO_PIC_P)
4335 {
4336 /* Take care of any required data indirection. */
4337 operands[1] = rs6000_machopic_legitimize_pic_address (
4338 operands[1], mode, operands[0]);
4339 if (operands[0] != operands[1])
4340 emit_insn (gen_rtx_SET (VOIDmode,
4341 operands[0], operands[1]));
4342 return;
4343 }
4344#endif
ac9e2cff
AP
4345 if (mode == DImode)
4346 {
4347 emit_insn (gen_macho_high_di (target, operands[1]));
4348 emit_insn (gen_macho_low_di (operands[0], target, operands[1]));
4349 }
4350 else
4351 {
4352 emit_insn (gen_macho_high (target, operands[1]));
4353 emit_insn (gen_macho_low (operands[0], target, operands[1]));
4354 }
ee890fe2
SS
4355 return;
4356 }
4357
fb4d4348
GK
4358 emit_insn (gen_elf_high (target, operands[1]));
4359 emit_insn (gen_elf_low (operands[0], target, operands[1]));
4360 return;
4361 }
4362
a9098fd0
GK
4363 /* If this is a SYMBOL_REF that refers to a constant pool entry,
4364 and we have put it in the TOC, we just need to make a TOC-relative
4365 reference to it. */
4366 if (TARGET_TOC
4367 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 4368 && constant_pool_expr_p (operands[1])
a9098fd0
GK
4369 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
4370 get_pool_mode (operands[1])))
fb4d4348 4371 {
a9098fd0 4372 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 4373 }
a9098fd0
GK
4374 else if (mode == Pmode
4375 && CONSTANT_P (operands[1])
38886f37
AO
4376 && ((GET_CODE (operands[1]) != CONST_INT
4377 && ! easy_fp_constant (operands[1], mode))
4378 || (GET_CODE (operands[1]) == CONST_INT
4379 && num_insns_constant (operands[1], mode) > 2)
4380 || (GET_CODE (operands[0]) == REG
4381 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 4382 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
4383 && ! legitimate_constant_pool_address_p (operands[1])
4384 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
4385 {
4386 /* Emit a USE operation so that the constant isn't deleted if
4387 expensive optimizations are turned on because nobody
4388 references it. This should only be done for operands that
4389 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
4390 This should not be done for operands that contain LABEL_REFs.
4391 For now, we just handle the obvious case. */
4392 if (GET_CODE (operands[1]) != LABEL_REF)
4393 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
4394
c859cda6 4395#if TARGET_MACHO
ee890fe2 4396 /* Darwin uses a special PIC legitimizer. */
ab82a49f 4397 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 4398 {
ee890fe2
SS
4399 operands[1] =
4400 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
4401 operands[0]);
4402 if (operands[0] != operands[1])
4403 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
4404 return;
4405 }
c859cda6 4406#endif
ee890fe2 4407
fb4d4348
GK
4408 /* If we are to limit the number of things we put in the TOC and
4409 this is a symbol plus a constant we can add in one insn,
4410 just put the symbol in the TOC and add the constant. Don't do
4411 this if reload is in progress. */
4412 if (GET_CODE (operands[1]) == CONST
4413 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
4414 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 4415 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
4416 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
4417 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
4418 && ! side_effects_p (operands[0]))
4419 {
a4f6c312
SS
4420 rtx sym =
4421 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
4422 rtx other = XEXP (XEXP (operands[1], 0), 1);
4423
a9098fd0
GK
4424 sym = force_reg (mode, sym);
4425 if (mode == SImode)
4426 emit_insn (gen_addsi3 (operands[0], sym, other));
4427 else
4428 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
4429 return;
4430 }
4431
a9098fd0 4432 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348 4433
f676971a 4434 if (TARGET_TOC
4d588c14 4435 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
4436 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
4437 get_pool_constant (XEXP (operands[1], 0)),
4438 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 4439 {
ba4828e0 4440 operands[1]
542a8afa
RH
4441 = gen_const_mem (mode,
4442 create_TOC_reference (XEXP (operands[1], 0)));
ba4828e0 4443 set_mem_alias_set (operands[1], get_TOC_alias_set ());
a9098fd0 4444 }
fb4d4348
GK
4445 }
4446 break;
a9098fd0 4447
fb4d4348 4448 case TImode:
76d2b81d
DJ
4449 rs6000_eliminate_indexed_memrefs (operands);
4450
27dc0551
DE
4451 if (TARGET_POWER)
4452 {
4453 emit_insn (gen_rtx_PARALLEL (VOIDmode,
4454 gen_rtvec (2,
4455 gen_rtx_SET (VOIDmode,
4456 operands[0], operands[1]),
4457 gen_rtx_CLOBBER (VOIDmode,
4458 gen_rtx_SCRATCH (SImode)))));
4459 return;
4460 }
fb4d4348
GK
4461 break;
4462
4463 default:
4464 abort ();
4465 }
4466
a9098fd0
GK
4467 /* Above, we may have called force_const_mem which may have returned
4468 an invalid address. If we can, fix this up; otherwise, reload will
4469 have to deal with it. */
8f4e6caf
RH
4470 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
4471 operands[1] = validize_mem (operands[1]);
a9098fd0 4472
8f4e6caf 4473 emit_set:
fb4d4348
GK
4474 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4475}
4697a36c 4476\f
2858f73a
GK
4477/* Nonzero if we can use a floating-point register to pass this arg. */
4478#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
4479 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
4480 && (CUM)->fregno <= FP_ARG_MAX_REG \
4481 && TARGET_HARD_FLOAT && TARGET_FPRS)
4482
4483/* Nonzero if we can use an AltiVec register to pass this arg. */
4484#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
4485 (ALTIVEC_VECTOR_MODE (MODE) \
4486 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
4487 && TARGET_ALTIVEC_ABI \
83953138 4488 && (NAMED))
2858f73a 4489
c6e8c921
GK
4490/* Return a nonzero value to say to return the function value in
4491 memory, just as large structures are always returned. TYPE will be
4492 the data type of the value, and FNTYPE will be the type of the
4493 function doing the returning, or @code{NULL} for libcalls.
4494
4495 The AIX ABI for the RS/6000 specifies that all structures are
4496 returned in memory. The Darwin ABI does the same. The SVR4 ABI
4497 specifies that structures <= 8 bytes are returned in r3/r4, but a
4498 draft put them in memory, and GCC used to implement the draft
4499 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
4500 controls this instead of DEFAULT_ABI; V.4 targets needing backward
4501 compatibility can change DRAFT_V4_STRUCT_RET to override the
4502 default, and -m switches get the final word. See
4503 rs6000_override_options for more details.
4504
4505 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
4506 long double support is enabled. These values are returned in memory.
4507
4508 int_size_in_bytes returns -1 for variable size objects, which go in
4509 memory always. The cast to unsigned makes -1 > 8. */
4510
4511static bool
4512rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4513{
4514 if (AGGREGATE_TYPE_P (type)
4515 && (TARGET_AIX_STRUCT_RET
4516 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
4517 return true;
4518 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
4519 return true;
4520 return false;
4521}
4522
4697a36c
MM
4523/* Initialize a variable CUM of type CUMULATIVE_ARGS
4524 for a call to a function whose data type is FNTYPE.
4525 For a library call, FNTYPE is 0.
4526
4527 For incoming args we set the number of arguments in the prototype large
1c20ae99 4528 so we never return a PARALLEL. */
4697a36c
MM
4529
4530void
f676971a 4531init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
4532 rtx libname ATTRIBUTE_UNUSED, int incoming,
4533 int libcall, int n_named_args)
4697a36c
MM
4534{
4535 static CUMULATIVE_ARGS zero_cumulative;
4536
4537 *cum = zero_cumulative;
4538 cum->words = 0;
4539 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 4540 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 4541 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
4542 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
4543 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 4544 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
4545 cum->stdarg = fntype
4546 && (TYPE_ARG_TYPES (fntype) != 0
4547 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4548 != void_type_node));
4697a36c 4549
0f6937fe
AM
4550 cum->nargs_prototype = 0;
4551 if (incoming || cum->prototype)
4552 cum->nargs_prototype = n_named_args;
4697a36c 4553
a5c76ee6
ZW
4554 /* Check for a longcall attribute. */
4555 if (fntype
4556 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
4557 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
4558 cum->call_cookie = CALL_LONG;
4559
4697a36c
MM
4560 if (TARGET_DEBUG_ARG)
4561 {
4562 fprintf (stderr, "\ninit_cumulative_args:");
4563 if (fntype)
4564 {
4565 tree ret_type = TREE_TYPE (fntype);
4566 fprintf (stderr, " ret code = %s,",
4567 tree_code_name[ (int)TREE_CODE (ret_type) ]);
4568 }
4569
6a4cee5f
MM
4570 if (cum->call_cookie & CALL_LONG)
4571 fprintf (stderr, " longcall,");
4572
4697a36c
MM
4573 fprintf (stderr, " proto = %d, nargs = %d\n",
4574 cum->prototype, cum->nargs_prototype);
4575 }
f676971a
EC
4576
4577 if (fntype
4578 && !TARGET_ALTIVEC
6d0ef01e
HP
4579 && TARGET_ALTIVEC_ABI
4580 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
4581 {
4582 error ("Cannot return value in vector register because"
4583 " altivec instructions are disabled, use -maltivec"
4584 " to enable them.");
4585 }
4697a36c
MM
4586}
4587\f
fe984136
RH
4588/* Return true if TYPE must be passed on the stack and not in registers. */
4589
4590static bool
4591rs6000_must_pass_in_stack (enum machine_mode mode, tree type)
4592{
4593 if (DEFAULT_ABI == ABI_AIX || TARGET_64BIT)
4594 return must_pass_in_stack_var_size (mode, type);
4595 else
4596 return must_pass_in_stack_var_size_or_pad (mode, type);
4597}
4598
c229cba9
DE
4599/* If defined, a C expression which determines whether, and in which
4600 direction, to pad out an argument with extra space. The value
4601 should be of type `enum direction': either `upward' to pad above
4602 the argument, `downward' to pad below, or `none' to inhibit
4603 padding.
4604
4605 For the AIX ABI structs are always stored left shifted in their
4606 argument slot. */
4607
9ebbca7d 4608enum direction
a2369ed3 4609function_arg_padding (enum machine_mode mode, tree type)
c229cba9 4610{
6e985040
AM
4611#ifndef AGGREGATE_PADDING_FIXED
4612#define AGGREGATE_PADDING_FIXED 0
4613#endif
4614#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
4615#define AGGREGATES_PAD_UPWARD_ALWAYS 0
4616#endif
4617
4618 if (!AGGREGATE_PADDING_FIXED)
4619 {
4620 /* GCC used to pass structures of the same size as integer types as
4621 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
4622 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
4623 passed padded downward, except that -mstrict-align further
4624 muddied the water in that multi-component structures of 2 and 4
4625 bytes in size were passed padded upward.
4626
4627 The following arranges for best compatibility with previous
4628 versions of gcc, but removes the -mstrict-align dependency. */
4629 if (BYTES_BIG_ENDIAN)
4630 {
4631 HOST_WIDE_INT size = 0;
4632
4633 if (mode == BLKmode)
4634 {
4635 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4636 size = int_size_in_bytes (type);
4637 }
4638 else
4639 size = GET_MODE_SIZE (mode);
4640
4641 if (size == 1 || size == 2 || size == 4)
4642 return downward;
4643 }
4644 return upward;
4645 }
4646
4647 if (AGGREGATES_PAD_UPWARD_ALWAYS)
4648 {
4649 if (type != 0 && AGGREGATE_TYPE_P (type))
4650 return upward;
4651 }
c229cba9 4652
d3704c46
KH
4653 /* Fall back to the default. */
4654 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
4655}
4656
b6c9286a 4657/* If defined, a C expression that gives the alignment boundary, in bits,
f676971a 4658 of an argument with the specified mode and type. If it is not defined,
b6c9286a 4659 PARM_BOUNDARY is used for all arguments.
f676971a 4660
2310f99a 4661 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
4662
4663int
a2369ed3 4664function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 4665{
4ed78545
AM
4666 if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8)
4667 return 64;
4668 else if (SPE_VECTOR_MODE (mode))
e1f83b4d 4669 return 64;
b2d04ecf 4670 else if (ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4671 return 128;
9ebbca7d 4672 else
b6c9286a 4673 return PARM_BOUNDARY;
b6c9286a 4674}
c53bdcf5
AM
4675
4676/* Compute the size (in words) of a function argument. */
4677
4678static unsigned long
4679rs6000_arg_size (enum machine_mode mode, tree type)
4680{
4681 unsigned long size;
4682
4683 if (mode != BLKmode)
4684 size = GET_MODE_SIZE (mode);
4685 else
4686 size = int_size_in_bytes (type);
4687
4688 if (TARGET_32BIT)
4689 return (size + 3) >> 2;
4690 else
4691 return (size + 7) >> 3;
4692}
b6c9286a 4693\f
4697a36c
MM
4694/* Update the data in CUM to advance over an argument
4695 of mode MODE and data type TYPE.
b2d04ecf
AM
4696 (TYPE is null for libcalls where that information may not be available.)
4697
4698 Note that for args passed by reference, function_arg will be called
4699 with MODE and TYPE set to that of the pointer to the arg, not the arg
4700 itself. */
4697a36c
MM
4701
4702void
f676971a 4703function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 4704 tree type, int named)
4697a36c
MM
4705{
4706 cum->nargs_prototype--;
4707
0ac081f6
AH
4708 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4709 {
4ed78545
AM
4710 bool stack = false;
4711
2858f73a 4712 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
6d0ef01e
HP
4713 {
4714 cum->vregno++;
4715 if (!TARGET_ALTIVEC)
4716 error ("Cannot pass argument in vector register because"
4717 " altivec instructions are disabled, use -maltivec"
4718 " to enable them.");
4ed78545
AM
4719
4720 /* PowerPC64 Linux and AIX allocate GPRs for a vector argument
f676971a 4721 even if it is going to be passed in a vector register.
4ed78545
AM
4722 Darwin does the same for variable-argument functions. */
4723 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4724 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4725 stack = true;
6d0ef01e 4726 }
4ed78545
AM
4727 else
4728 stack = true;
4729
4730 if (stack)
c72d6c26 4731 {
a594a19c 4732 int align;
f676971a 4733
2858f73a
GK
4734 /* Vector parameters must be 16-byte aligned. This places
4735 them at 2 mod 4 in terms of words in 32-bit mode, since
4736 the parameter save area starts at offset 24 from the
4737 stack. In 64-bit mode, they just have to start on an
4738 even word, since the parameter save area is 16-byte
4739 aligned. Space for GPRs is reserved even if the argument
4740 will be passed in memory. */
4741 if (TARGET_32BIT)
4ed78545 4742 align = (2 - cum->words) & 3;
2858f73a
GK
4743 else
4744 align = cum->words & 1;
c53bdcf5 4745 cum->words += align + rs6000_arg_size (mode, type);
f676971a 4746
a594a19c
GK
4747 if (TARGET_DEBUG_ARG)
4748 {
f676971a 4749 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
a594a19c
GK
4750 cum->words, align);
4751 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
f676971a 4752 cum->nargs_prototype, cum->prototype,
2858f73a 4753 GET_MODE_NAME (mode));
a594a19c
GK
4754 }
4755 }
0ac081f6 4756 }
a4b0320c 4757 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4758 && !cum->stdarg
4759 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4760 cum->sysv_gregno++;
f607bc57 4761 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4762 {
a3170dc6 4763 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4764 && (mode == SFmode || mode == DFmode))
4697a36c 4765 {
4cc833b7
RH
4766 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4767 cum->fregno++;
4768 else
4769 {
4770 if (mode == DFmode)
4771 cum->words += cum->words & 1;
c53bdcf5 4772 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4773 }
4697a36c 4774 }
4cc833b7
RH
4775 else
4776 {
b2d04ecf 4777 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4778 int gregno = cum->sysv_gregno;
4779
4ed78545
AM
4780 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4781 (r7,r8) or (r9,r10). As does any other 2 word item such
4782 as complex int due to a historical mistake. */
4783 if (n_words == 2)
4784 gregno += (1 - gregno) & 1;
4cc833b7 4785
4ed78545 4786 /* Multi-reg args are not split between registers and stack. */
4cc833b7
RH
4787 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4788 {
4ed78545
AM
4789 /* Long long and SPE vectors are aligned on the stack.
4790 So are other 2 word items such as complex int due to
4791 a historical mistake. */
4cc833b7
RH
4792 if (n_words == 2)
4793 cum->words += cum->words & 1;
4794 cum->words += n_words;
4795 }
4697a36c 4796
4cc833b7
RH
4797 /* Note: continuing to accumulate gregno past when we've started
4798 spilling to the stack indicates the fact that we've started
4799 spilling to the stack to expand_builtin_saveregs. */
4800 cum->sysv_gregno = gregno + n_words;
4801 }
4697a36c 4802
4cc833b7
RH
4803 if (TARGET_DEBUG_ARG)
4804 {
4805 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4806 cum->words, cum->fregno);
4807 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4808 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4809 fprintf (stderr, "mode = %4s, named = %d\n",
4810 GET_MODE_NAME (mode), named);
4811 }
4697a36c
MM
4812 }
4813 else
4cc833b7 4814 {
b2d04ecf
AM
4815 int n_words = rs6000_arg_size (mode, type);
4816 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
a4f6c312 4817
b2d04ecf
AM
4818 /* The simple alignment calculation here works because
4819 function_arg_boundary / PARM_BOUNDARY will only be 1 or 2.
4820 If we ever want to handle alignments larger than 8 bytes for
4821 32-bit or 16 bytes for 64-bit, then we'll need to take into
4822 account the offset to the start of the parm save area. */
4823 align &= cum->words;
4824 cum->words += align + n_words;
4697a36c 4825
a3170dc6
AH
4826 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4827 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4828 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4829
4830 if (TARGET_DEBUG_ARG)
4831 {
4832 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4833 cum->words, cum->fregno);
4834 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4835 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4836 fprintf (stderr, "named = %d, align = %d\n", named, align);
4837 }
4838 }
4697a36c 4839}
a6c9bed4
AH
4840
4841/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4842
a6c9bed4 4843static rtx
f676971a 4844rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 4845 tree type)
a6c9bed4
AH
4846{
4847 if (cum->stdarg)
4848 {
4849 int gregno = cum->sysv_gregno;
c53bdcf5 4850 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4851
4852 /* SPE vectors are put in odd registers. */
4853 if (n_words == 2 && (gregno & 1) == 0)
4854 gregno += 1;
4855
4856 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4857 {
4858 rtx r1, r2;
4859 enum machine_mode m = SImode;
4860
4861 r1 = gen_rtx_REG (m, gregno);
4862 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4863 r2 = gen_rtx_REG (m, gregno + 1);
4864 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4865 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4866 }
4867 else
b78d48dd 4868 return NULL_RTX;
a6c9bed4
AH
4869 }
4870 else
4871 {
4872 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4873 return gen_rtx_REG (mode, cum->sysv_gregno);
4874 else
b78d48dd 4875 return NULL_RTX;
a6c9bed4
AH
4876 }
4877}
4878
b78d48dd
FJ
4879/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4880
4881static rtx
ec6376ab 4882rs6000_mixed_function_arg (enum machine_mode mode, tree type, int align_words)
b78d48dd 4883{
ec6376ab
AM
4884 int n_units;
4885 int i, k;
4886 rtx rvec[GP_ARG_NUM_REG + 1];
4887
4888 if (align_words >= GP_ARG_NUM_REG)
4889 return NULL_RTX;
4890
4891 n_units = rs6000_arg_size (mode, type);
4892
4893 /* Optimize the simple case where the arg fits in one gpr, except in
4894 the case of BLKmode due to assign_parms assuming that registers are
4895 BITS_PER_WORD wide. */
4896 if (n_units == 0
4897 || (n_units == 1 && mode != BLKmode))
4898 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4899
4900 k = 0;
4901 if (align_words + n_units > GP_ARG_NUM_REG)
4902 /* Not all of the arg fits in gprs. Say that it goes in memory too,
4903 using a magic NULL_RTX component.
4904 FIXME: This is not strictly correct. Only some of the arg
4905 belongs in memory, not all of it. However, there isn't any way
4906 to do this currently, apart from building rtx descriptions for
4907 the pieces of memory we want stored. Due to bugs in the generic
4908 code we can't use the normal function_arg_partial_nregs scheme
4909 with the PARALLEL arg description we emit here.
4910 In any case, the code to store the whole arg to memory is often
4911 more efficient than code to store pieces, and we know that space
4912 is available in the right place for the whole arg. */
4913 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
4914
4915 i = 0;
4916 do
36a454e1 4917 {
ec6376ab
AM
4918 rtx r = gen_rtx_REG (SImode, GP_ARG_MIN_REG + align_words);
4919 rtx off = GEN_INT (i++ * 4);
4920 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
36a454e1 4921 }
ec6376ab
AM
4922 while (++align_words < GP_ARG_NUM_REG && --n_units != 0);
4923
4924 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
b78d48dd
FJ
4925}
4926
4697a36c
MM
4927/* Determine where to put an argument to a function.
4928 Value is zero to push the argument on the stack,
4929 or a hard register in which to store the argument.
4930
4931 MODE is the argument's machine mode.
4932 TYPE is the data type of the argument (as a tree).
4933 This is null for libcalls where that information may
4934 not be available.
4935 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4936 the preceding args and about the function being called.
4937 NAMED is nonzero if this argument is a named parameter
4938 (otherwise it is an extra parameter matching an ellipsis).
4939
4940 On RS/6000 the first eight words of non-FP are normally in registers
4941 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4942 Under V.4, the first 8 FP args are in registers.
4943
4944 If this is floating-point and no prototype is specified, we use
4945 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4946 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4947 so we can pass the FP value just in one register. emit_library_function
b2d04ecf
AM
4948 doesn't support PARALLEL anyway.
4949
4950 Note that for args passed by reference, function_arg will be called
4951 with MODE and TYPE set to that of the pointer to the arg, not the arg
4952 itself. */
4697a36c
MM
4953
4954struct rtx_def *
f676971a 4955function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 4956 tree type, int named)
4697a36c 4957{
4cc833b7 4958 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4959
a4f6c312
SS
4960 /* Return a marker to indicate whether CR1 needs to set or clear the
4961 bit that V.4 uses to say fp args were passed in registers.
4962 Assume that we don't need the marker for software floating point,
4963 or compiler generated library calls. */
4697a36c
MM
4964 if (mode == VOIDmode)
4965 {
f607bc57 4966 if (abi == ABI_V4
7509c759 4967 && cum->nargs_prototype < 0
b9599e46
FS
4968 && (cum->call_cookie & CALL_LIBCALL) == 0
4969 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4970 {
a3170dc6
AH
4971 /* For the SPE, we need to crxor CR6 always. */
4972 if (TARGET_SPE_ABI)
4973 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4974 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4975 return GEN_INT (cum->call_cookie
4976 | ((cum->fregno == FP_ARG_MIN_REG)
4977 ? CALL_V4_SET_FP_ARGS
4978 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4979 }
4697a36c 4980
7509c759 4981 return GEN_INT (cum->call_cookie);
4697a36c
MM
4982 }
4983
2858f73a 4984 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4985 if (TARGET_64BIT && ! cum->prototype)
4986 {
4987 /* Vector parameters get passed in vector register
4988 and also in GPRs or memory, in absence of prototype. */
4989 int align_words;
4990 rtx slot;
4991 align_words = (cum->words + 1) & ~1;
4992
4993 if (align_words >= GP_ARG_NUM_REG)
4994 {
4995 slot = NULL_RTX;
4996 }
4997 else
4998 {
4999 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5000 }
5001 return gen_rtx_PARALLEL (mode,
5002 gen_rtvec (2,
5003 gen_rtx_EXPR_LIST (VOIDmode,
5004 slot, const0_rtx),
5005 gen_rtx_EXPR_LIST (VOIDmode,
5006 gen_rtx_REG (mode, cum->vregno),
5007 const0_rtx)));
5008 }
5009 else
5010 return gen_rtx_REG (mode, cum->vregno);
2858f73a 5011 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 5012 {
2858f73a 5013 if (named || abi == ABI_V4)
a594a19c 5014 return NULL_RTX;
0ac081f6 5015 else
a594a19c
GK
5016 {
5017 /* Vector parameters to varargs functions under AIX or Darwin
5018 get passed in memory and possibly also in GPRs. */
ec6376ab
AM
5019 int align, align_words, n_words;
5020 enum machine_mode part_mode;
a594a19c
GK
5021
5022 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
5023 2 mod 4 in terms of words in 32-bit mode, since the parameter
5024 save area starts at offset 24 from the stack. In 64-bit mode,
5025 they just have to start on an even word, since the parameter
5026 save area is 16-byte aligned. */
5027 if (TARGET_32BIT)
4ed78545 5028 align = (2 - cum->words) & 3;
2858f73a
GK
5029 else
5030 align = cum->words & 1;
a594a19c
GK
5031 align_words = cum->words + align;
5032
5033 /* Out of registers? Memory, then. */
5034 if (align_words >= GP_ARG_NUM_REG)
5035 return NULL_RTX;
ec6376ab
AM
5036
5037 if (TARGET_32BIT && TARGET_POWERPC64)
5038 return rs6000_mixed_function_arg (mode, type, align_words);
5039
2858f73a
GK
5040 /* The vector value goes in GPRs. Only the part of the
5041 value in GPRs is reported here. */
ec6376ab
AM
5042 part_mode = mode;
5043 n_words = rs6000_arg_size (mode, type);
5044 if (align_words + n_words > GP_ARG_NUM_REG)
839a4992 5045 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
5046 is either wholly in GPRs or half in GPRs and half not. */
5047 part_mode = DImode;
ec6376ab
AM
5048
5049 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 5050 }
0ac081f6 5051 }
a6c9bed4
AH
5052 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
5053 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 5054 else if (abi == ABI_V4)
4697a36c 5055 {
a3170dc6 5056 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
5057 && (mode == SFmode || mode == DFmode))
5058 {
5059 if (cum->fregno <= FP_ARG_V4_MAX_REG)
5060 return gen_rtx_REG (mode, cum->fregno);
5061 else
b78d48dd 5062 return NULL_RTX;
4cc833b7
RH
5063 }
5064 else
5065 {
b2d04ecf 5066 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
5067 int gregno = cum->sysv_gregno;
5068
4ed78545
AM
5069 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
5070 (r7,r8) or (r9,r10). As does any other 2 word item such
5071 as complex int due to a historical mistake. */
5072 if (n_words == 2)
5073 gregno += (1 - gregno) & 1;
4cc833b7 5074
4ed78545 5075 /* Multi-reg args are not split between registers and stack. */
ec6376ab 5076 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
b78d48dd 5077 return NULL_RTX;
ec6376ab
AM
5078
5079 if (TARGET_32BIT && TARGET_POWERPC64)
5080 return rs6000_mixed_function_arg (mode, type,
5081 gregno - GP_ARG_MIN_REG);
5082 return gen_rtx_REG (mode, gregno);
4cc833b7 5083 }
4697a36c 5084 }
4cc833b7
RH
5085 else
5086 {
b2d04ecf
AM
5087 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5088 int align_words = cum->words + (cum->words & align);
b78d48dd 5089
2858f73a 5090 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 5091 {
ec6376ab
AM
5092 rtx rvec[GP_ARG_NUM_REG + 1];
5093 rtx r;
5094 int k;
c53bdcf5
AM
5095 bool needs_psave;
5096 enum machine_mode fmode = mode;
c53bdcf5
AM
5097 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
5098
5099 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
5100 {
c53bdcf5
AM
5101 /* Currently, we only ever need one reg here because complex
5102 doubles are split. */
ec6376ab 5103 if (cum->fregno != FP_ARG_MAX_REG || fmode != TFmode)
c53bdcf5 5104 abort ();
ec6376ab
AM
5105
5106 /* Long double split over regs and memory. */
5107 fmode = DFmode;
c53bdcf5 5108 }
c53bdcf5
AM
5109
5110 /* Do we also need to pass this arg in the parameter save
5111 area? */
5112 needs_psave = (type
5113 && (cum->nargs_prototype <= 0
5114 || (DEFAULT_ABI == ABI_AIX
5115 && TARGET_XL_CALL
5116 && align_words >= GP_ARG_NUM_REG)));
5117
5118 if (!needs_psave && mode == fmode)
ec6376ab 5119 return gen_rtx_REG (fmode, cum->fregno);
c53bdcf5 5120
ec6376ab 5121 k = 0;
c53bdcf5
AM
5122 if (needs_psave)
5123 {
ec6376ab 5124 /* Describe the part that goes in gprs or the stack.
c53bdcf5 5125 This piece must come first, before the fprs. */
c53bdcf5
AM
5126 if (align_words < GP_ARG_NUM_REG)
5127 {
5128 unsigned long n_words = rs6000_arg_size (mode, type);
ec6376ab
AM
5129
5130 if (align_words + n_words > GP_ARG_NUM_REG
5131 || (TARGET_32BIT && TARGET_POWERPC64))
5132 {
5133 /* If this is partially on the stack, then we only
5134 include the portion actually in registers here. */
5135 enum machine_mode rmode = TARGET_32BIT ? SImode : DImode;
5136 rtx off;
2e6c9641
FJ
5137 int i=0;
5138 if (align_words + n_words > GP_ARG_NUM_REG
5139 && (TARGET_32BIT && TARGET_POWERPC64))
5140 /* Not all of the arg fits in gprs. Say that it goes in memory too,
5141 using a magic NULL_RTX component. Also see comment in
5142 rs6000_mixed_function_arg for why the normal
5143 function_arg_partial_nregs scheme doesn't work in this case. */
5144 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
ec6376ab
AM
5145 do
5146 {
5147 r = gen_rtx_REG (rmode,
5148 GP_ARG_MIN_REG + align_words);
2e6c9641 5149 off = GEN_INT (i++ * GET_MODE_SIZE (rmode));
ec6376ab
AM
5150 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, off);
5151 }
5152 while (++align_words < GP_ARG_NUM_REG && --n_words != 0);
5153 }
5154 else
5155 {
5156 /* The whole arg fits in gprs. */
5157 r = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5158 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5159 }
c53bdcf5 5160 }
ec6376ab
AM
5161 else
5162 /* It's entirely in memory. */
5163 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx);
c53bdcf5
AM
5164 }
5165
ec6376ab
AM
5166 /* Describe where this piece goes in the fprs. */
5167 r = gen_rtx_REG (fmode, cum->fregno);
5168 rvec[k++] = gen_rtx_EXPR_LIST (VOIDmode, r, const0_rtx);
5169
5170 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rvec));
4cc833b7
RH
5171 }
5172 else if (align_words < GP_ARG_NUM_REG)
b2d04ecf 5173 {
ec6376ab
AM
5174 if (TARGET_32BIT && TARGET_POWERPC64)
5175 return rs6000_mixed_function_arg (mode, type, align_words);
b2d04ecf
AM
5176
5177 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
5178 }
4cc833b7
RH
5179 else
5180 return NULL_RTX;
4697a36c 5181 }
4697a36c
MM
5182}
5183\f
ec6376ab
AM
5184/* For an arg passed partly in registers and partly in memory, this is
5185 the number of registers used. For args passed entirely in registers
5186 or entirely in memory, zero. When an arg is described by a PARALLEL,
5187 perhaps using more than one register type, this function returns the
5188 number of registers used by the first element of the PARALLEL. */
4697a36c
MM
5189
5190int
f676971a 5191function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 5192 tree type, int named)
4697a36c 5193{
c53bdcf5 5194 int ret = 0;
ec6376ab
AM
5195 int align;
5196 int parm_offset;
5197 int align_words;
c53bdcf5 5198
f607bc57 5199 if (DEFAULT_ABI == ABI_V4)
4697a36c 5200 return 0;
4697a36c 5201
c53bdcf5
AM
5202 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
5203 && cum->nargs_prototype >= 0)
5204 return 0;
5205
ec6376ab
AM
5206 align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
5207 parm_offset = TARGET_32BIT ? 2 : 0;
5208 align_words = cum->words + ((parm_offset - cum->words) & align);
5209
5210 if (USE_FP_FOR_ARG_P (cum, mode, type)
5211 /* If we are passing this arg in gprs as well, then this function
5212 should return the number of gprs (or memory) partially passed,
5213 *not* the number of fprs. */
5214 && !(type
5215 && (cum->nargs_prototype <= 0
5216 || (DEFAULT_ABI == ABI_AIX
5217 && TARGET_XL_CALL
5218 && align_words >= GP_ARG_NUM_REG))))
4697a36c 5219 {
c53bdcf5 5220 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
ec6376ab 5221 ret = FP_ARG_MAX_REG + 1 - cum->fregno;
c53bdcf5 5222 else if (cum->nargs_prototype >= 0)
4697a36c
MM
5223 return 0;
5224 }
5225
ec6376ab
AM
5226 if (align_words < GP_ARG_NUM_REG
5227 && GP_ARG_NUM_REG < align_words + rs6000_arg_size (mode, type))
5228 ret = GP_ARG_NUM_REG - align_words;
4697a36c 5229
c53bdcf5
AM
5230 if (ret != 0 && TARGET_DEBUG_ARG)
5231 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 5232
c53bdcf5 5233 return ret;
4697a36c
MM
5234}
5235\f
5236/* A C expression that indicates when an argument must be passed by
5237 reference. If nonzero for an argument, a copy of that argument is
5238 made in memory and a pointer to the argument is passed instead of
5239 the argument itself. The pointer is passed in whatever way is
5240 appropriate for passing a pointer to that type.
5241
b2d04ecf
AM
5242 Under V.4, aggregates and long double are passed by reference.
5243
5244 As an extension to all 32-bit ABIs, AltiVec vectors are passed by
5245 reference unless the AltiVec vector extension ABI is in force.
c8c99a68
DE
5246
5247 As an extension to all ABIs, variable sized types are passed by
5248 reference. */
4697a36c 5249
8cd5a4e0 5250static bool
f676971a
EC
5251rs6000_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
5252 enum machine_mode mode ATTRIBUTE_UNUSED,
8cd5a4e0 5253 tree type, bool named ATTRIBUTE_UNUSED)
4697a36c 5254{
b2d04ecf
AM
5255 if ((DEFAULT_ABI == ABI_V4
5256 && ((type && AGGREGATE_TYPE_P (type))
5257 || mode == TFmode))
5258 || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
5259 || (type && int_size_in_bytes (type) < 0))
4697a36c
MM
5260 {
5261 if (TARGET_DEBUG_ARG)
b2d04ecf 5262 fprintf (stderr, "function_arg_pass_by_reference\n");
4697a36c
MM
5263
5264 return 1;
5265 }
b2d04ecf 5266 return 0;
4697a36c 5267}
5985c7a6
FJ
5268
5269static void
2d9db8eb 5270rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
5271{
5272 int i;
5273 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
5274
5275 if (nregs == 0)
5276 return;
5277
5278 for (i = 0; i < nregs; i++)
5279 {
5280 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
5281 if (reload_completed)
5282 {
5283 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
5284 tem = NULL_RTX;
5285 else
f676971a 5286 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
5985c7a6
FJ
5287 i * GET_MODE_SIZE(reg_mode));
5288 }
5289 else
5290 tem = replace_equiv_address (tem, XEXP (tem, 0));
5291
5292 if (tem == NULL_RTX)
5293 abort ();
5294
5295 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
5296 }
5297}
5298
4697a36c
MM
5299\f
5300/* Perform any needed actions needed for a function that is receiving a
f676971a 5301 variable number of arguments.
4697a36c
MM
5302
5303 CUM is as above.
5304
5305 MODE and TYPE are the mode and type of the current parameter.
5306
5307 PRETEND_SIZE is a variable that should be set to the amount of stack
5308 that must be pushed by the prolog to pretend that our caller pushed
5309 it.
5310
5311 Normally, this macro will push all remaining incoming registers on the
5312 stack and set PRETEND_SIZE to the length of the registers pushed. */
5313
c6e8c921 5314static void
f676971a 5315setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
a2369ed3 5316 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 5317{
4cc833b7
RH
5318 CUMULATIVE_ARGS next_cum;
5319 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 5320 rtx save_area = NULL_RTX, mem;
dfafc897 5321 int first_reg_offset, set;
4697a36c 5322
f31bf321 5323 /* Skip the last named argument. */
d34c5b80 5324 next_cum = *cum;
f31bf321 5325 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 5326
f607bc57 5327 if (DEFAULT_ABI == ABI_V4)
d34c5b80 5328 {
60e2d0ca 5329 if (! no_rtl)
2c4974b7 5330 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 5331 - RS6000_VARARGS_SIZE);
4cc833b7
RH
5332
5333 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 5334 }
60e2d0ca 5335 else
4697a36c 5336 {
d34c5b80 5337 first_reg_offset = next_cum.words;
4cc833b7 5338 save_area = virtual_incoming_args_rtx;
4697a36c 5339
fe984136 5340 if (targetm.calls.must_pass_in_stack (mode, type))
c53bdcf5 5341 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 5342 }
4697a36c 5343
dfafc897 5344 set = get_varargs_alias_set ();
c81fc13e 5345 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 5346 {
dfafc897
FS
5347 mem = gen_rtx_MEM (BLKmode,
5348 plus_constant (save_area,
5349 first_reg_offset * reg_size)),
ba4828e0 5350 set_mem_alias_set (mem, set);
8ac61af7 5351 set_mem_align (mem, BITS_PER_WORD);
dfafc897 5352
f676971a 5353 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
5985c7a6 5354 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
5355 }
5356
4697a36c 5357 /* Save FP registers if needed. */
f607bc57 5358 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
5359 && TARGET_HARD_FLOAT && TARGET_FPRS
5360 && ! no_rtl
4cc833b7 5361 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 5362 {
4cc833b7 5363 int fregno = next_cum.fregno;
9ebbca7d 5364 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
5365 rtx lab = gen_label_rtx ();
5366 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 5367
4cc833b7 5368 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 5369 pc_rtx,
39403d82 5370 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
5371 gen_rtx_NE (VOIDmode, cr1,
5372 const0_rtx),
39403d82 5373 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
5374 pc_rtx)));
5375
4cc833b7
RH
5376 while (fregno <= FP_ARG_V4_MAX_REG)
5377 {
dfafc897 5378 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 5379 set_mem_alias_set (mem, set);
dfafc897 5380 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
5381 fregno++;
5382 off += 8;
4697a36c 5383 }
4cc833b7
RH
5384
5385 emit_label (lab);
4697a36c 5386 }
4697a36c 5387}
4697a36c 5388
dfafc897 5389/* Create the va_list data type. */
2c4974b7 5390
c35d187f
RH
5391static tree
5392rs6000_build_builtin_va_list (void)
dfafc897 5393{
64c2816f 5394 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 5395
9ebbca7d
GK
5396 /* For AIX, prefer 'char *' because that's what the system
5397 header files like. */
f607bc57 5398 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 5399 return build_pointer_type (char_type_node);
dfafc897 5400
f1e639b1 5401 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 5402 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 5403
f676971a 5404 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
9ebbca7d 5405 unsigned_char_type_node);
f676971a 5406 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
9ebbca7d 5407 unsigned_char_type_node);
64c2816f
DT
5408 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
5409 every user file. */
5410 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
5411 short_unsigned_type_node);
dfafc897
FS
5412 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
5413 ptr_type_node);
5414 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
5415 ptr_type_node);
5416
5417 DECL_FIELD_CONTEXT (f_gpr) = record;
5418 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 5419 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
5420 DECL_FIELD_CONTEXT (f_ovf) = record;
5421 DECL_FIELD_CONTEXT (f_sav) = record;
5422
bab45a51
FS
5423 TREE_CHAIN (record) = type_decl;
5424 TYPE_NAME (record) = type_decl;
dfafc897
FS
5425 TYPE_FIELDS (record) = f_gpr;
5426 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
5427 TREE_CHAIN (f_fpr) = f_res;
5428 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
5429 TREE_CHAIN (f_ovf) = f_sav;
5430
5431 layout_type (record);
5432
5433 /* The correct type is an array type of one element. */
5434 return build_array_type (record, build_index_type (size_zero_node));
5435}
5436
5437/* Implement va_start. */
5438
5439void
a2369ed3 5440rs6000_va_start (tree valist, rtx nextarg)
4697a36c 5441{
dfafc897 5442 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 5443 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 5444 tree gpr, fpr, ovf, sav, t;
2c4974b7 5445
dfafc897 5446 /* Only SVR4 needs something special. */
f607bc57 5447 if (DEFAULT_ABI != ABI_V4)
dfafc897 5448 {
e5faf155 5449 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
5450 return;
5451 }
5452
973a648b 5453 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5454 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5455 f_res = TREE_CHAIN (f_fpr);
5456 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5457 f_sav = TREE_CHAIN (f_ovf);
5458
8ebecc3b 5459 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
44de5aeb
RK
5460 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5461 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5462 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5463 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
dfafc897
FS
5464
5465 /* Count number of gp and fp argument registers used. */
4cc833b7 5466 words = current_function_args_info.words;
dfafc897
FS
5467 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
5468 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
5469
5470 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
5471 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
5472 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
5473 words, n_gpr, n_fpr);
dfafc897 5474
4a90aeeb 5475 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr,
7d60be94 5476 build_int_cst (NULL_TREE, n_gpr));
dfafc897
FS
5477 TREE_SIDE_EFFECTS (t) = 1;
5478 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5479
4a90aeeb 5480 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr,
7d60be94 5481 build_int_cst (NULL_TREE, n_fpr));
dfafc897
FS
5482 TREE_SIDE_EFFECTS (t) = 1;
5483 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5484
5485 /* Find the overflow area. */
5486 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
5487 if (words != 0)
5488 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
7d60be94 5489 build_int_cst (NULL_TREE, words * UNITS_PER_WORD));
dfafc897
FS
5490 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5491 TREE_SIDE_EFFECTS (t) = 1;
5492 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5493
5494 /* Find the register save area. */
5495 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
5496 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
7d60be94 5497 build_int_cst (NULL_TREE, -RS6000_VARARGS_SIZE));
dfafc897
FS
5498 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
5499 TREE_SIDE_EFFECTS (t) = 1;
5500 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5501}
5502
5503/* Implement va_arg. */
5504
23a60a04
JM
5505tree
5506rs6000_gimplify_va_arg (tree valist, tree type, tree *pre_p, tree *post_p)
cd3ce9b4 5507{
cd3ce9b4
JM
5508 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
5509 tree gpr, fpr, ovf, sav, reg, t, u;
08b0dc1b 5510 int size, rsize, n_reg, sav_ofs, sav_scale;
cd3ce9b4
JM
5511 tree lab_false, lab_over, addr;
5512 int align;
5513 tree ptrtype = build_pointer_type (type);
5514
08b0dc1b
RH
5515 if (pass_by_reference (NULL, TYPE_MODE (type), type, false))
5516 {
5517 t = rs6000_gimplify_va_arg (valist, ptrtype, pre_p, post_p);
5518 return build_fold_indirect_ref (t);
5519 }
5520
cd3ce9b4
JM
5521 if (DEFAULT_ABI != ABI_V4)
5522 {
08b0dc1b 5523 if (targetm.calls.split_complex_arg && TREE_CODE (type) == COMPLEX_TYPE)
cd3ce9b4
JM
5524 {
5525 tree elem_type = TREE_TYPE (type);
5526 enum machine_mode elem_mode = TYPE_MODE (elem_type);
5527 int elem_size = GET_MODE_SIZE (elem_mode);
5528
5529 if (elem_size < UNITS_PER_WORD)
5530 {
23a60a04 5531 tree real_part, imag_part;
cd3ce9b4
JM
5532 tree post = NULL_TREE;
5533
23a60a04
JM
5534 real_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5535 &post);
5536 /* Copy the value into a temporary, lest the formal temporary
5537 be reused out from under us. */
5538 real_part = get_initialized_tmp_var (real_part, pre_p, &post);
cd3ce9b4
JM
5539 append_to_statement_list (post, pre_p);
5540
23a60a04
JM
5541 imag_part = rs6000_gimplify_va_arg (valist, elem_type, pre_p,
5542 post_p);
cd3ce9b4 5543
23a60a04 5544 return build (COMPLEX_EXPR, type, real_part, imag_part);
cd3ce9b4
JM
5545 }
5546 }
5547
23a60a04 5548 return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
cd3ce9b4
JM
5549 }
5550
5551 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
5552 f_fpr = TREE_CHAIN (f_gpr);
5553 f_res = TREE_CHAIN (f_fpr);
5554 f_ovf = TREE_CHAIN (f_res);
5555 f_sav = TREE_CHAIN (f_ovf);
5556
5557 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
44de5aeb
RK
5558 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr, NULL_TREE);
5559 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
5560 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
5561 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
cd3ce9b4
JM
5562
5563 size = int_size_in_bytes (type);
5564 rsize = (size + 3) / 4;
5565 align = 1;
5566
08b0dc1b
RH
5567 if (TARGET_HARD_FLOAT && TARGET_FPRS
5568 && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode))
cd3ce9b4
JM
5569 {
5570 /* FP args go in FP registers, if present. */
cd3ce9b4
JM
5571 reg = fpr;
5572 n_reg = 1;
5573 sav_ofs = 8*4;
5574 sav_scale = 8;
5575 if (TYPE_MODE (type) == DFmode)
5576 align = 8;
5577 }
5578 else
5579 {
5580 /* Otherwise into GP registers. */
cd3ce9b4
JM
5581 reg = gpr;
5582 n_reg = rsize;
5583 sav_ofs = 0;
5584 sav_scale = 4;
5585 if (n_reg == 2)
5586 align = 8;
5587 }
5588
5589 /* Pull the value out of the saved registers.... */
5590
5591 lab_over = NULL;
5592 addr = create_tmp_var (ptr_type_node, "addr");
5593 DECL_POINTER_ALIAS_SET (addr) = get_varargs_alias_set ();
5594
5595 /* AltiVec vectors never go in registers when -mabi=altivec. */
5596 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
5597 align = 16;
5598 else
5599 {
5600 lab_false = create_artificial_label ();
5601 lab_over = create_artificial_label ();
5602
5603 /* Long long and SPE vectors are aligned in the registers.
5604 As are any other 2 gpr item such as complex int due to a
5605 historical mistake. */
5606 u = reg;
5607 if (n_reg == 2)
5608 {
5609 u = build2 (BIT_AND_EXPR, TREE_TYPE (reg), reg,
95674810 5610 size_int (n_reg - 1));
cd3ce9b4
JM
5611 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u);
5612 }
5613
95674810 5614 t = fold_convert (TREE_TYPE (reg), size_int (8 - n_reg + 1));
cd3ce9b4
JM
5615 t = build2 (GE_EXPR, boolean_type_node, u, t);
5616 u = build1 (GOTO_EXPR, void_type_node, lab_false);
5617 t = build3 (COND_EXPR, void_type_node, t, u, NULL_TREE);
5618 gimplify_and_add (t, pre_p);
5619
5620 t = sav;
5621 if (sav_ofs)
95674810 5622 t = build2 (PLUS_EXPR, ptr_type_node, sav, size_int (sav_ofs));
cd3ce9b4 5623
95674810 5624 u = build2 (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, size_int (n_reg));
cd3ce9b4 5625 u = build1 (CONVERT_EXPR, integer_type_node, u);
95674810 5626 u = build2 (MULT_EXPR, integer_type_node, u, size_int (sav_scale));
cd3ce9b4
JM
5627 t = build2 (PLUS_EXPR, ptr_type_node, t, u);
5628
5629 t = build2 (MODIFY_EXPR, void_type_node, addr, t);
5630 gimplify_and_add (t, pre_p);
5631
5632 t = build1 (GOTO_EXPR, void_type_node, lab_over);
5633 gimplify_and_add (t, pre_p);
5634
5635 t = build1 (LABEL_EXPR, void_type_node, lab_false);
5636 append_to_statement_list (t, pre_p);
5637
5638 if (n_reg > 2)
5639 {
5640 /* Ensure that we don't find any more args in regs.
5641 Alignment has taken care of the n_reg == 2 case. */
95674810 5642 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, size_int (8));
cd3ce9b4
JM
5643 gimplify_and_add (t, pre_p);
5644 }
5645 }
5646
5647 /* ... otherwise out of the overflow area. */
5648
5649 /* Care for on-stack alignment if needed. */
5650 t = ovf;
5651 if (align != 1)
5652 {
95674810 5653 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (align - 1));
4a90aeeb 5654 t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
7d60be94 5655 build_int_cst (NULL_TREE, -align));
cd3ce9b4
JM
5656 }
5657 gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
5658
5659 u = build2 (MODIFY_EXPR, void_type_node, addr, t);
5660 gimplify_and_add (u, pre_p);
5661
95674810 5662 t = build2 (PLUS_EXPR, TREE_TYPE (t), t, size_int (size));
cd3ce9b4
JM
5663 t = build2 (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5664 gimplify_and_add (t, pre_p);
5665
5666 if (lab_over)
5667 {
5668 t = build1 (LABEL_EXPR, void_type_node, lab_over);
5669 append_to_statement_list (t, pre_p);
5670 }
5671
08b0dc1b 5672 addr = fold_convert (ptrtype, addr);
23a60a04 5673 return build_fold_indirect_ref (addr);
cd3ce9b4
JM
5674}
5675
0ac081f6
AH
5676/* Builtins. */
5677
6e34d3a3
JM
5678#define def_builtin(MASK, NAME, TYPE, CODE) \
5679do { \
5680 if ((MASK) & target_flags) \
5681 lang_hooks.builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
5682 NULL, NULL_TREE); \
0ac081f6
AH
5683} while (0)
5684
24408032
AH
5685/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
5686
2212663f 5687static const struct builtin_description bdesc_3arg[] =
24408032
AH
5688{
5689 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
5690 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
5691 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
5692 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
5693 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
5694 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
5695 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
5696 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
5697 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
5698 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
f676971a 5699 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
24408032
AH
5700 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
5701 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
5702 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
5703 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
5704 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
5705 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
5706 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
5707 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
5708 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
5709 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
5710 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
5711 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
5712};
2212663f 5713
95385cbb
AH
5714/* DST operations: void foo (void *, const int, const char). */
5715
5716static const struct builtin_description bdesc_dst[] =
5717{
5718 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
5719 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
5720 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
5721 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
5722};
5723
2212663f 5724/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 5725
a3170dc6 5726static struct builtin_description bdesc_2arg[] =
0ac081f6 5727{
f18c054f
DB
5728 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
5729 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
5730 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
5731 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
5732 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
5733 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
5734 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
5735 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
5736 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
5737 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
5738 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 5739 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
5740 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
5741 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
5742 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
5743 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
5744 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
5745 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
5746 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
5747 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
5748 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
5749 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
5750 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
5751 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5752 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5753 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5754 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5755 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5756 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5757 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5758 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5759 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5760 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5761 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5762 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5763 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5764 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5765 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5766 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5767 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5768 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5769 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5770 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5771 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5772 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5773 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5774 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5775 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5776 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5777 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5778 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5779 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5780 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5781 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5782 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5783 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5784 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5785 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5786 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5787 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5788 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5789 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5790 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5791 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5792 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5793 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5794 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5795 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5796 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5797 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5798 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5799 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5800 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5801 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5802 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5803 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5804 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5805 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5806 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5807 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5808 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5809 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5810 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5811 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5812 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5813 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5814 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5815 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5816 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5817 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5818 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5819 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5820 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5821 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5822 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5823 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5824 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5825 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5826 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5827 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5828 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5829 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5830 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5831 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5832 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5833 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5834 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5835 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5836 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5837 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5838 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5839 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5840 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5841
5842 /* Place holder, leave as first spe builtin. */
5843 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5844 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5845 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5846 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5847 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5848 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5849 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5850 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5851 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5852 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5853 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5854 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5855 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5856 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5857 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5858 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5859 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5860 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5861 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5862 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5863 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5864 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5865 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5866 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5867 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5868 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5869 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5870 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5871 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5872 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5873 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5874 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5875 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5876 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5877 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5878 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5879 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5880 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5881 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5882 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5883 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5884 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5885 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5886 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5887 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5888 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5889 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5890 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5891 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5892 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5893 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5894 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5895 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5896 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5897 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5898 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5899 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5900 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5901 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5902 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5903 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5904 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5905 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5906 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5907 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5908 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5909 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5910 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5911 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5912 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5913 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5914 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5915 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5916 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5917 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5918 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5919 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5920 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5921 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5922 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5923 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5924 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5925 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5926 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5927 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5928 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5929 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5930 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5931 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5932 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5933 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5934 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5935 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5936 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5937 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5938 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
5939 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
5940 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
5941 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
5942 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
5943 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
5944 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
5945 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
5946 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
5947 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
5948 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
5949 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
5950 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
5951 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
5952
5953 /* SPE binary operations expecting a 5-bit unsigned literal. */
5954 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
5955
5956 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
5957 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
5958 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
5959 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
5960 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
5961 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
5962 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
5963 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
5964 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
5965 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
5966 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
5967 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
5968 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
5969 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
5970 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
5971 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
5972 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
5973 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
5974 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
5975 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
5976 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
5977 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
5978 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
5979 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
5980 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
5981 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
5982
5983 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 5984 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
5985};
5986
5987/* AltiVec predicates. */
5988
5989struct builtin_description_predicates
5990{
5991 const unsigned int mask;
5992 const enum insn_code icode;
5993 const char *opcode;
5994 const char *const name;
5995 const enum rs6000_builtins code;
5996};
5997
5998static const struct builtin_description_predicates bdesc_altivec_preds[] =
5999{
6000 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
6001 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
6002 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
6003 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
6004 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
6005 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
6006 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
6007 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
6008 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
6009 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
6010 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
6011 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
6012 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 6013};
24408032 6014
a3170dc6
AH
6015/* SPE predicates. */
6016static struct builtin_description bdesc_spe_predicates[] =
6017{
6018 /* Place-holder. Leave as first. */
6019 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
6020 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
6021 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
6022 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
6023 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
6024 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
6025 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
6026 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
6027 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
6028 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
6029 /* Place-holder. Leave as last. */
6030 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
6031};
6032
6033/* SPE evsel predicates. */
6034static struct builtin_description bdesc_spe_evsel[] =
6035{
6036 /* Place-holder. Leave as first. */
6037 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
6038 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
6039 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
6040 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
6041 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
6042 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
6043 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
6044 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
6045 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
6046 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
6047 /* Place-holder. Leave as last. */
6048 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
6049};
6050
b6d08ca1 6051/* ABS* operations. */
100c4561
AH
6052
6053static const struct builtin_description bdesc_abs[] =
6054{
6055 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
6056 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
6057 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
6058 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
6059 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
6060 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
6061 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
6062};
6063
617e0e1d
DB
6064/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
6065 foo (VECa). */
24408032 6066
a3170dc6 6067static struct builtin_description bdesc_1arg[] =
2212663f 6068{
617e0e1d
DB
6069 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
6070 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
6071 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
6072 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
6073 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
6074 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
6075 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
6076 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
6077 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
6078 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
6079 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
6080 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
6081 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
6082 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
6083 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
6084 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
6085 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
6086
6087 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
6088 end with SPE_BUILTIN_EVSUBFUSIAAW. */
6089 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
6090 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
6091 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
6092 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
6093 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
6094 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
6095 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
6096 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
6097 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
6098 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
6099 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
6100 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
6101 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
6102 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
6103 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
6104 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
6105 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
6106 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
6107 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
6108 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
6109 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
6110 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
6111 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
6a599451 6112 { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
a3170dc6
AH
6113 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
6114 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
6115 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
6116 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
6117
6118 /* Place-holder. Leave as last unary SPE builtin. */
6119 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
6120};
6121
6122static rtx
a2369ed3 6123rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6124{
6125 rtx pat;
6126 tree arg0 = TREE_VALUE (arglist);
6127 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6128 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6129 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6130
0559cc77
DE
6131 if (icode == CODE_FOR_nothing)
6132 /* Builtin not supported on this processor. */
6133 return 0;
6134
20e26713
AH
6135 /* If we got invalid arguments bail out before generating bad rtl. */
6136 if (arg0 == error_mark_node)
9a171fcd 6137 return const0_rtx;
20e26713 6138
0559cc77
DE
6139 if (icode == CODE_FOR_altivec_vspltisb
6140 || icode == CODE_FOR_altivec_vspltish
6141 || icode == CODE_FOR_altivec_vspltisw
6142 || icode == CODE_FOR_spe_evsplatfi
6143 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
6144 {
6145 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
6146 if (GET_CODE (op0) != CONST_INT
6147 || INTVAL (op0) > 0x1f
6148 || INTVAL (op0) < -0x1f)
6149 {
6150 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 6151 return const0_rtx;
b44140e7 6152 }
b44140e7
AH
6153 }
6154
c62f2db5 6155 if (target == 0
2212663f
DB
6156 || GET_MODE (target) != tmode
6157 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6158 target = gen_reg_rtx (tmode);
6159
6160 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6161 op0 = copy_to_mode_reg (mode0, op0);
6162
6163 pat = GEN_FCN (icode) (target, op0);
6164 if (! pat)
6165 return 0;
6166 emit_insn (pat);
0ac081f6 6167
2212663f
DB
6168 return target;
6169}
ae4b4a02 6170
100c4561 6171static rtx
a2369ed3 6172altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
6173{
6174 rtx pat, scratch1, scratch2;
6175 tree arg0 = TREE_VALUE (arglist);
6176 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6177 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6178 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6179
6180 /* If we have invalid arguments, bail out before generating bad rtl. */
6181 if (arg0 == error_mark_node)
9a171fcd 6182 return const0_rtx;
100c4561
AH
6183
6184 if (target == 0
6185 || GET_MODE (target) != tmode
6186 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6187 target = gen_reg_rtx (tmode);
6188
6189 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6190 op0 = copy_to_mode_reg (mode0, op0);
6191
6192 scratch1 = gen_reg_rtx (mode0);
6193 scratch2 = gen_reg_rtx (mode0);
6194
6195 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
6196 if (! pat)
6197 return 0;
6198 emit_insn (pat);
6199
6200 return target;
6201}
6202
0ac081f6 6203static rtx
a2369ed3 6204rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
6205{
6206 rtx pat;
6207 tree arg0 = TREE_VALUE (arglist);
6208 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6209 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6210 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6211 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6212 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6213 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6214
0559cc77
DE
6215 if (icode == CODE_FOR_nothing)
6216 /* Builtin not supported on this processor. */
6217 return 0;
6218
20e26713
AH
6219 /* If we got invalid arguments bail out before generating bad rtl. */
6220 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6221 return const0_rtx;
20e26713 6222
0559cc77
DE
6223 if (icode == CODE_FOR_altivec_vcfux
6224 || icode == CODE_FOR_altivec_vcfsx
6225 || icode == CODE_FOR_altivec_vctsxs
6226 || icode == CODE_FOR_altivec_vctuxs
6227 || icode == CODE_FOR_altivec_vspltb
6228 || icode == CODE_FOR_altivec_vsplth
6229 || icode == CODE_FOR_altivec_vspltw
6230 || icode == CODE_FOR_spe_evaddiw
6231 || icode == CODE_FOR_spe_evldd
6232 || icode == CODE_FOR_spe_evldh
6233 || icode == CODE_FOR_spe_evldw
6234 || icode == CODE_FOR_spe_evlhhesplat
6235 || icode == CODE_FOR_spe_evlhhossplat
6236 || icode == CODE_FOR_spe_evlhhousplat
6237 || icode == CODE_FOR_spe_evlwhe
6238 || icode == CODE_FOR_spe_evlwhos
6239 || icode == CODE_FOR_spe_evlwhou
6240 || icode == CODE_FOR_spe_evlwhsplat
6241 || icode == CODE_FOR_spe_evlwwsplat
6242 || icode == CODE_FOR_spe_evrlwi
6243 || icode == CODE_FOR_spe_evslwi
6244 || icode == CODE_FOR_spe_evsrwis
f5119d10 6245 || icode == CODE_FOR_spe_evsubifw
0559cc77 6246 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
6247 {
6248 /* Only allow 5-bit unsigned literals. */
8bb418a3 6249 STRIP_NOPS (arg1);
b44140e7
AH
6250 if (TREE_CODE (arg1) != INTEGER_CST
6251 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6252 {
6253 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 6254 return const0_rtx;
b44140e7 6255 }
b44140e7
AH
6256 }
6257
c62f2db5 6258 if (target == 0
0ac081f6
AH
6259 || GET_MODE (target) != tmode
6260 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6261 target = gen_reg_rtx (tmode);
6262
6263 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6264 op0 = copy_to_mode_reg (mode0, op0);
6265 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6266 op1 = copy_to_mode_reg (mode1, op1);
6267
6268 pat = GEN_FCN (icode) (target, op0, op1);
6269 if (! pat)
6270 return 0;
6271 emit_insn (pat);
6272
6273 return target;
6274}
6525c0e7 6275
ae4b4a02 6276static rtx
f676971a 6277altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
a2369ed3 6278 tree arglist, rtx target)
ae4b4a02
AH
6279{
6280 rtx pat, scratch;
6281 tree cr6_form = TREE_VALUE (arglist);
6282 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6283 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6284 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6285 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6286 enum machine_mode tmode = SImode;
6287 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6288 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6289 int cr6_form_int;
6290
6291 if (TREE_CODE (cr6_form) != INTEGER_CST)
6292 {
6293 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 6294 return const0_rtx;
ae4b4a02
AH
6295 }
6296 else
6297 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
6298
6299 if (mode0 != mode1)
6300 abort ();
6301
6302 /* If we have invalid arguments, bail out before generating bad rtl. */
6303 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 6304 return const0_rtx;
ae4b4a02
AH
6305
6306 if (target == 0
6307 || GET_MODE (target) != tmode
6308 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6309 target = gen_reg_rtx (tmode);
6310
6311 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6312 op0 = copy_to_mode_reg (mode0, op0);
6313 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6314 op1 = copy_to_mode_reg (mode1, op1);
6315
6316 scratch = gen_reg_rtx (mode0);
6317
6318 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 6319 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
6320 if (! pat)
6321 return 0;
6322 emit_insn (pat);
6323
6324 /* The vec_any* and vec_all* predicates use the same opcodes for two
6325 different operations, but the bits in CR6 will be different
6326 depending on what information we want. So we have to play tricks
6327 with CR6 to get the right bits out.
6328
6329 If you think this is disgusting, look at the specs for the
6330 AltiVec predicates. */
6331
6332 switch (cr6_form_int)
6333 {
6334 case 0:
6335 emit_insn (gen_cr6_test_for_zero (target));
6336 break;
6337 case 1:
6338 emit_insn (gen_cr6_test_for_zero_reverse (target));
6339 break;
6340 case 2:
6341 emit_insn (gen_cr6_test_for_lt (target));
6342 break;
6343 case 3:
6344 emit_insn (gen_cr6_test_for_lt_reverse (target));
6345 break;
6346 default:
6347 error ("argument 1 of __builtin_altivec_predicate is out of range");
6348 break;
6349 }
6350
6351 return target;
6352}
6353
b4a62fa0 6354static rtx
38f391a5 6355altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
6356{
6357 rtx pat, addr;
6358 tree arg0 = TREE_VALUE (arglist);
6359 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6360 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6361 enum machine_mode mode0 = Pmode;
6362 enum machine_mode mode1 = Pmode;
6363 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6364 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6365
6366 if (icode == CODE_FOR_nothing)
6367 /* Builtin not supported on this processor. */
6368 return 0;
6369
6370 /* If we got invalid arguments bail out before generating bad rtl. */
6371 if (arg0 == error_mark_node || arg1 == error_mark_node)
6372 return const0_rtx;
6373
6374 if (target == 0
6375 || GET_MODE (target) != tmode
6376 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6377 target = gen_reg_rtx (tmode);
6378
f676971a 6379 op1 = copy_to_mode_reg (mode1, op1);
b4a62fa0
SB
6380
6381 if (op0 == const0_rtx)
6382 {
6383 addr = gen_rtx_MEM (tmode, op1);
6384 }
6385 else
6386 {
6387 op0 = copy_to_mode_reg (mode0, op0);
6388 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
6389 }
6390
6391 pat = GEN_FCN (icode) (target, addr);
6392
6393 if (! pat)
6394 return 0;
6395 emit_insn (pat);
6396
6397 return target;
6398}
6399
61bea3b0
AH
6400static rtx
6401spe_expand_stv_builtin (enum insn_code icode, tree arglist)
6402{
6403 tree arg0 = TREE_VALUE (arglist);
6404 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6405 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6406 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6407 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6408 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6409 rtx pat;
6410 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
6411 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
6412 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
6413
6414 /* Invalid arguments. Bail before doing anything stoopid! */
6415 if (arg0 == error_mark_node
6416 || arg1 == error_mark_node
6417 || arg2 == error_mark_node)
6418 return const0_rtx;
6419
6420 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
6421 op0 = copy_to_mode_reg (mode2, op0);
6422 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
6423 op1 = copy_to_mode_reg (mode0, op1);
6424 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6425 op2 = copy_to_mode_reg (mode1, op2);
6426
6427 pat = GEN_FCN (icode) (op1, op2, op0);
6428 if (pat)
6429 emit_insn (pat);
6430 return NULL_RTX;
6431}
6432
6525c0e7 6433static rtx
a2369ed3 6434altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
6435{
6436 tree arg0 = TREE_VALUE (arglist);
6437 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6438 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6439 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6440 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6441 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
6442 rtx pat, addr;
6443 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6444 enum machine_mode mode1 = Pmode;
6445 enum machine_mode mode2 = Pmode;
6525c0e7
AH
6446
6447 /* Invalid arguments. Bail before doing anything stoopid! */
6448 if (arg0 == error_mark_node
6449 || arg1 == error_mark_node
6450 || arg2 == error_mark_node)
9a171fcd 6451 return const0_rtx;
6525c0e7 6452
b4a62fa0
SB
6453 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
6454 op0 = copy_to_mode_reg (tmode, op0);
6455
f676971a 6456 op2 = copy_to_mode_reg (mode2, op2);
b4a62fa0
SB
6457
6458 if (op1 == const0_rtx)
6459 {
6460 addr = gen_rtx_MEM (tmode, op2);
6461 }
6462 else
6463 {
6464 op1 = copy_to_mode_reg (mode1, op1);
6465 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
6466 }
6525c0e7 6467
b4a62fa0 6468 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
6469 if (pat)
6470 emit_insn (pat);
6471 return NULL_RTX;
6472}
6473
2212663f 6474static rtx
a2369ed3 6475rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6476{
6477 rtx pat;
6478 tree arg0 = TREE_VALUE (arglist);
6479 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6480 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6481 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6482 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6483 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6484 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6485 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6486 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6487 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 6488
774b5662
DE
6489 if (icode == CODE_FOR_nothing)
6490 /* Builtin not supported on this processor. */
6491 return 0;
6492
20e26713
AH
6493 /* If we got invalid arguments bail out before generating bad rtl. */
6494 if (arg0 == error_mark_node
6495 || arg1 == error_mark_node
6496 || arg2 == error_mark_node)
9a171fcd 6497 return const0_rtx;
20e26713 6498
774b5662
DE
6499 if (icode == CODE_FOR_altivec_vsldoi_4sf
6500 || icode == CODE_FOR_altivec_vsldoi_4si
6501 || icode == CODE_FOR_altivec_vsldoi_8hi
6502 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
6503 {
6504 /* Only allow 4-bit unsigned literals. */
8bb418a3 6505 STRIP_NOPS (arg2);
b44140e7
AH
6506 if (TREE_CODE (arg2) != INTEGER_CST
6507 || TREE_INT_CST_LOW (arg2) & ~0xf)
6508 {
6509 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 6510 return const0_rtx;
b44140e7 6511 }
b44140e7
AH
6512 }
6513
c62f2db5 6514 if (target == 0
2212663f
DB
6515 || GET_MODE (target) != tmode
6516 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6517 target = gen_reg_rtx (tmode);
6518
6519 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6520 op0 = copy_to_mode_reg (mode0, op0);
6521 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6522 op1 = copy_to_mode_reg (mode1, op1);
6523 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
6524 op2 = copy_to_mode_reg (mode2, op2);
6525
6526 pat = GEN_FCN (icode) (target, op0, op1, op2);
6527 if (! pat)
6528 return 0;
6529 emit_insn (pat);
6530
6531 return target;
6532}
92898235 6533
3a9b8c7e 6534/* Expand the lvx builtins. */
0ac081f6 6535static rtx
a2369ed3 6536altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 6537{
0ac081f6
AH
6538 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6539 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 6540 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
6541 tree arg0;
6542 enum machine_mode tmode, mode0;
7c3abc73 6543 rtx pat, op0;
3a9b8c7e 6544 enum insn_code icode;
92898235 6545
0ac081f6
AH
6546 switch (fcode)
6547 {
f18c054f
DB
6548 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
6549 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 6550 break;
f18c054f
DB
6551 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
6552 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
6553 break;
6554 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
6555 icode = CODE_FOR_altivec_lvx_4si;
6556 break;
6557 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
6558 icode = CODE_FOR_altivec_lvx_4sf;
6559 break;
6560 default:
6561 *expandedp = false;
6562 return NULL_RTX;
6563 }
0ac081f6 6564
3a9b8c7e 6565 *expandedp = true;
f18c054f 6566
3a9b8c7e
AH
6567 arg0 = TREE_VALUE (arglist);
6568 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6569 tmode = insn_data[icode].operand[0].mode;
6570 mode0 = insn_data[icode].operand[1].mode;
f18c054f 6571
3a9b8c7e
AH
6572 if (target == 0
6573 || GET_MODE (target) != tmode
6574 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6575 target = gen_reg_rtx (tmode);
24408032 6576
3a9b8c7e
AH
6577 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6578 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 6579
3a9b8c7e
AH
6580 pat = GEN_FCN (icode) (target, op0);
6581 if (! pat)
6582 return 0;
6583 emit_insn (pat);
6584 return target;
6585}
f18c054f 6586
3a9b8c7e
AH
6587/* Expand the stvx builtins. */
6588static rtx
f676971a 6589altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 6590 bool *expandedp)
3a9b8c7e
AH
6591{
6592 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6593 tree arglist = TREE_OPERAND (exp, 1);
6594 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6595 tree arg0, arg1;
6596 enum machine_mode mode0, mode1;
7c3abc73 6597 rtx pat, op0, op1;
3a9b8c7e 6598 enum insn_code icode;
f18c054f 6599
3a9b8c7e
AH
6600 switch (fcode)
6601 {
6602 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
6603 icode = CODE_FOR_altivec_stvx_16qi;
6604 break;
6605 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
6606 icode = CODE_FOR_altivec_stvx_8hi;
6607 break;
6608 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
6609 icode = CODE_FOR_altivec_stvx_4si;
6610 break;
6611 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
6612 icode = CODE_FOR_altivec_stvx_4sf;
6613 break;
6614 default:
6615 *expandedp = false;
6616 return NULL_RTX;
6617 }
24408032 6618
3a9b8c7e
AH
6619 arg0 = TREE_VALUE (arglist);
6620 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6621 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6622 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6623 mode0 = insn_data[icode].operand[0].mode;
6624 mode1 = insn_data[icode].operand[1].mode;
f18c054f 6625
3a9b8c7e
AH
6626 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6627 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
6628 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6629 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 6630
3a9b8c7e
AH
6631 pat = GEN_FCN (icode) (op0, op1);
6632 if (pat)
6633 emit_insn (pat);
f18c054f 6634
3a9b8c7e
AH
6635 *expandedp = true;
6636 return NULL_RTX;
6637}
f18c054f 6638
3a9b8c7e
AH
6639/* Expand the dst builtins. */
6640static rtx
f676971a 6641altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
a2369ed3 6642 bool *expandedp)
3a9b8c7e
AH
6643{
6644 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6645 tree arglist = TREE_OPERAND (exp, 1);
6646 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6647 tree arg0, arg1, arg2;
6648 enum machine_mode mode0, mode1, mode2;
7c3abc73 6649 rtx pat, op0, op1, op2;
3a9b8c7e 6650 struct builtin_description *d;
a3170dc6 6651 size_t i;
f18c054f 6652
3a9b8c7e 6653 *expandedp = false;
f18c054f 6654
3a9b8c7e
AH
6655 /* Handle DST variants. */
6656 d = (struct builtin_description *) bdesc_dst;
6657 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
6658 if (d->code == fcode)
6659 {
6660 arg0 = TREE_VALUE (arglist);
6661 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6662 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6663 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6664 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6665 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6666 mode0 = insn_data[d->icode].operand[0].mode;
6667 mode1 = insn_data[d->icode].operand[1].mode;
6668 mode2 = insn_data[d->icode].operand[2].mode;
24408032 6669
3a9b8c7e
AH
6670 /* Invalid arguments, bail out before generating bad rtl. */
6671 if (arg0 == error_mark_node
6672 || arg1 == error_mark_node
6673 || arg2 == error_mark_node)
6674 return const0_rtx;
f18c054f 6675
86e7df90 6676 *expandedp = true;
8bb418a3 6677 STRIP_NOPS (arg2);
3a9b8c7e
AH
6678 if (TREE_CODE (arg2) != INTEGER_CST
6679 || TREE_INT_CST_LOW (arg2) & ~0x3)
6680 {
6681 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
6682 return const0_rtx;
6683 }
f18c054f 6684
3a9b8c7e 6685 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 6686 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
6687 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
6688 op1 = copy_to_mode_reg (mode1, op1);
24408032 6689
3a9b8c7e
AH
6690 pat = GEN_FCN (d->icode) (op0, op1, op2);
6691 if (pat != 0)
6692 emit_insn (pat);
f18c054f 6693
3a9b8c7e
AH
6694 return NULL_RTX;
6695 }
f18c054f 6696
3a9b8c7e
AH
6697 return NULL_RTX;
6698}
24408032 6699
3a9b8c7e
AH
6700/* Expand the builtin in EXP and store the result in TARGET. Store
6701 true in *EXPANDEDP if we found a builtin to expand. */
6702static rtx
a2369ed3 6703altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
6704{
6705 struct builtin_description *d;
6706 struct builtin_description_predicates *dp;
6707 size_t i;
6708 enum insn_code icode;
6709 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6710 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
6711 tree arg0;
6712 rtx op0, pat;
6713 enum machine_mode tmode, mode0;
3a9b8c7e 6714 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 6715
3a9b8c7e
AH
6716 target = altivec_expand_ld_builtin (exp, target, expandedp);
6717 if (*expandedp)
6718 return target;
0ac081f6 6719
3a9b8c7e
AH
6720 target = altivec_expand_st_builtin (exp, target, expandedp);
6721 if (*expandedp)
6722 return target;
6723
6724 target = altivec_expand_dst_builtin (exp, target, expandedp);
6725 if (*expandedp)
6726 return target;
6727
6728 *expandedp = true;
95385cbb 6729
3a9b8c7e
AH
6730 switch (fcode)
6731 {
6525c0e7
AH
6732 case ALTIVEC_BUILTIN_STVX:
6733 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
6734 case ALTIVEC_BUILTIN_STVEBX:
6735 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
6736 case ALTIVEC_BUILTIN_STVEHX:
6737 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
6738 case ALTIVEC_BUILTIN_STVEWX:
6739 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
6740 case ALTIVEC_BUILTIN_STVXL:
6741 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 6742
95385cbb
AH
6743 case ALTIVEC_BUILTIN_MFVSCR:
6744 icode = CODE_FOR_altivec_mfvscr;
6745 tmode = insn_data[icode].operand[0].mode;
6746
6747 if (target == 0
6748 || GET_MODE (target) != tmode
6749 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6750 target = gen_reg_rtx (tmode);
f676971a 6751
95385cbb 6752 pat = GEN_FCN (icode) (target);
0ac081f6
AH
6753 if (! pat)
6754 return 0;
6755 emit_insn (pat);
95385cbb
AH
6756 return target;
6757
6758 case ALTIVEC_BUILTIN_MTVSCR:
6759 icode = CODE_FOR_altivec_mtvscr;
6760 arg0 = TREE_VALUE (arglist);
6761 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6762 mode0 = insn_data[icode].operand[0].mode;
6763
6764 /* If we got invalid arguments bail out before generating bad rtl. */
6765 if (arg0 == error_mark_node)
9a171fcd 6766 return const0_rtx;
95385cbb
AH
6767
6768 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6769 op0 = copy_to_mode_reg (mode0, op0);
6770
6771 pat = GEN_FCN (icode) (op0);
6772 if (pat)
6773 emit_insn (pat);
6774 return NULL_RTX;
3a9b8c7e 6775
95385cbb
AH
6776 case ALTIVEC_BUILTIN_DSSALL:
6777 emit_insn (gen_altivec_dssall ());
6778 return NULL_RTX;
6779
6780 case ALTIVEC_BUILTIN_DSS:
6781 icode = CODE_FOR_altivec_dss;
6782 arg0 = TREE_VALUE (arglist);
8bb418a3 6783 STRIP_NOPS (arg0);
95385cbb
AH
6784 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6785 mode0 = insn_data[icode].operand[0].mode;
6786
6787 /* If we got invalid arguments bail out before generating bad rtl. */
6788 if (arg0 == error_mark_node)
9a171fcd 6789 return const0_rtx;
95385cbb 6790
b44140e7
AH
6791 if (TREE_CODE (arg0) != INTEGER_CST
6792 || TREE_INT_CST_LOW (arg0) & ~0x3)
6793 {
6794 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6795 return const0_rtx;
b44140e7
AH
6796 }
6797
95385cbb
AH
6798 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6799 op0 = copy_to_mode_reg (mode0, op0);
6800
6801 emit_insn (gen_altivec_dss (op0));
0ac081f6 6802 return NULL_RTX;
f676971a 6803
8bb418a3
ZL
6804 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
6805 arg0 = TREE_VALUE (arglist);
97dc04b3
RH
6806 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR
6807 || TREE_CODE (arg0) == ARRAY_REF)
8bb418a3
ZL
6808 arg0 = TREE_OPERAND (arg0, 0);
6809 error ("invalid parameter combination for `%s' AltiVec intrinsic",
6810 TREE_STRING_POINTER (arg0));
6811
6812 return const0_rtx;
0ac081f6 6813 }
24408032 6814
100c4561
AH
6815 /* Expand abs* operations. */
6816 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6817 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6818 if (d->code == fcode)
6819 return altivec_expand_abs_builtin (d->icode, arglist, target);
6820
ae4b4a02
AH
6821 /* Expand the AltiVec predicates. */
6822 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6823 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
6824 if (dp->code == fcode)
6825 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
6826
6525c0e7
AH
6827 /* LV* are funky. We initialized them differently. */
6828 switch (fcode)
6829 {
6830 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6831 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
6832 arglist, target);
6833 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6834 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
92898235 6835 arglist, target);
6525c0e7 6836 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6837 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
92898235 6838 arglist, target);
6525c0e7 6839 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6840 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
92898235 6841 arglist, target);
6525c0e7 6842 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6843 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
92898235 6844 arglist, target);
6525c0e7 6845 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6846 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
92898235 6847 arglist, target);
6525c0e7 6848 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6849 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
92898235 6850 arglist, target);
6525c0e7
AH
6851 default:
6852 break;
6853 /* Fall through. */
6854 }
95385cbb 6855
92898235 6856 *expandedp = false;
0ac081f6
AH
6857 return NULL_RTX;
6858}
6859
a3170dc6
AH
6860/* Binops that need to be initialized manually, but can be expanded
6861 automagically by rs6000_expand_binop_builtin. */
6862static struct builtin_description bdesc_2arg_spe[] =
6863{
6864 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6865 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6866 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6867 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6868 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6869 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6870 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6871 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6872 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6873 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6874 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6875 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6876 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6877 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6878 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6879 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6880 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6881 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6882 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6883 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6884 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6885 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6886};
6887
6888/* Expand the builtin in EXP and store the result in TARGET. Store
6889 true in *EXPANDEDP if we found a builtin to expand.
6890
6891 This expands the SPE builtins that are not simple unary and binary
6892 operations. */
6893static rtx
a2369ed3 6894spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6895{
6896 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6897 tree arglist = TREE_OPERAND (exp, 1);
6898 tree arg1, arg0;
6899 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6900 enum insn_code icode;
6901 enum machine_mode tmode, mode0;
6902 rtx pat, op0;
6903 struct builtin_description *d;
6904 size_t i;
6905
6906 *expandedp = true;
6907
6908 /* Syntax check for a 5-bit unsigned immediate. */
6909 switch (fcode)
6910 {
6911 case SPE_BUILTIN_EVSTDD:
6912 case SPE_BUILTIN_EVSTDH:
6913 case SPE_BUILTIN_EVSTDW:
6914 case SPE_BUILTIN_EVSTWHE:
6915 case SPE_BUILTIN_EVSTWHO:
6916 case SPE_BUILTIN_EVSTWWE:
6917 case SPE_BUILTIN_EVSTWWO:
6918 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6919 if (TREE_CODE (arg1) != INTEGER_CST
6920 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6921 {
6922 error ("argument 2 must be a 5-bit unsigned literal");
6923 return const0_rtx;
6924 }
6925 break;
6926 default:
6927 break;
6928 }
6929
00332c9f
AH
6930 /* The evsplat*i instructions are not quite generic. */
6931 switch (fcode)
6932 {
6933 case SPE_BUILTIN_EVSPLATFI:
6934 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6935 arglist, target);
6936 case SPE_BUILTIN_EVSPLATI:
6937 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
6938 arglist, target);
6939 default:
6940 break;
6941 }
6942
a3170dc6
AH
6943 d = (struct builtin_description *) bdesc_2arg_spe;
6944 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
6945 if (d->code == fcode)
6946 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6947
6948 d = (struct builtin_description *) bdesc_spe_predicates;
6949 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
6950 if (d->code == fcode)
6951 return spe_expand_predicate_builtin (d->icode, arglist, target);
6952
6953 d = (struct builtin_description *) bdesc_spe_evsel;
6954 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
6955 if (d->code == fcode)
6956 return spe_expand_evsel_builtin (d->icode, arglist, target);
6957
6958 switch (fcode)
6959 {
6960 case SPE_BUILTIN_EVSTDDX:
61bea3b0 6961 return spe_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
a3170dc6 6962 case SPE_BUILTIN_EVSTDHX:
61bea3b0 6963 return spe_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
a3170dc6 6964 case SPE_BUILTIN_EVSTDWX:
61bea3b0 6965 return spe_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
a3170dc6 6966 case SPE_BUILTIN_EVSTWHEX:
61bea3b0 6967 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
a3170dc6 6968 case SPE_BUILTIN_EVSTWHOX:
61bea3b0 6969 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
a3170dc6 6970 case SPE_BUILTIN_EVSTWWEX:
61bea3b0 6971 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
a3170dc6 6972 case SPE_BUILTIN_EVSTWWOX:
61bea3b0 6973 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
a3170dc6 6974 case SPE_BUILTIN_EVSTDD:
61bea3b0 6975 return spe_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
a3170dc6 6976 case SPE_BUILTIN_EVSTDH:
61bea3b0 6977 return spe_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
a3170dc6 6978 case SPE_BUILTIN_EVSTDW:
61bea3b0 6979 return spe_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
a3170dc6 6980 case SPE_BUILTIN_EVSTWHE:
61bea3b0 6981 return spe_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
a3170dc6 6982 case SPE_BUILTIN_EVSTWHO:
61bea3b0 6983 return spe_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
a3170dc6 6984 case SPE_BUILTIN_EVSTWWE:
61bea3b0 6985 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
a3170dc6 6986 case SPE_BUILTIN_EVSTWWO:
61bea3b0 6987 return spe_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
a3170dc6
AH
6988 case SPE_BUILTIN_MFSPEFSCR:
6989 icode = CODE_FOR_spe_mfspefscr;
6990 tmode = insn_data[icode].operand[0].mode;
6991
6992 if (target == 0
6993 || GET_MODE (target) != tmode
6994 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6995 target = gen_reg_rtx (tmode);
f676971a 6996
a3170dc6
AH
6997 pat = GEN_FCN (icode) (target);
6998 if (! pat)
6999 return 0;
7000 emit_insn (pat);
7001 return target;
7002 case SPE_BUILTIN_MTSPEFSCR:
7003 icode = CODE_FOR_spe_mtspefscr;
7004 arg0 = TREE_VALUE (arglist);
7005 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7006 mode0 = insn_data[icode].operand[0].mode;
7007
7008 if (arg0 == error_mark_node)
7009 return const0_rtx;
7010
7011 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
7012 op0 = copy_to_mode_reg (mode0, op0);
7013
7014 pat = GEN_FCN (icode) (op0);
7015 if (pat)
7016 emit_insn (pat);
7017 return NULL_RTX;
7018 default:
7019 break;
7020 }
7021
7022 *expandedp = false;
7023 return NULL_RTX;
7024}
7025
7026static rtx
a2369ed3 7027spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7028{
7029 rtx pat, scratch, tmp;
7030 tree form = TREE_VALUE (arglist);
7031 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
7032 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7033 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7034 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7035 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7036 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7037 int form_int;
7038 enum rtx_code code;
7039
7040 if (TREE_CODE (form) != INTEGER_CST)
7041 {
7042 error ("argument 1 of __builtin_spe_predicate must be a constant");
7043 return const0_rtx;
7044 }
7045 else
7046 form_int = TREE_INT_CST_LOW (form);
7047
7048 if (mode0 != mode1)
7049 abort ();
7050
7051 if (arg0 == error_mark_node || arg1 == error_mark_node)
7052 return const0_rtx;
7053
7054 if (target == 0
7055 || GET_MODE (target) != SImode
7056 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
7057 target = gen_reg_rtx (SImode);
7058
7059 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7060 op0 = copy_to_mode_reg (mode0, op0);
7061 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
7062 op1 = copy_to_mode_reg (mode1, op1);
7063
7064 scratch = gen_reg_rtx (CCmode);
7065
7066 pat = GEN_FCN (icode) (scratch, op0, op1);
7067 if (! pat)
7068 return const0_rtx;
7069 emit_insn (pat);
7070
7071 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
7072 _lower_. We use one compare, but look in different bits of the
7073 CR for each variant.
7074
7075 There are 2 elements in each SPE simd type (upper/lower). The CR
7076 bits are set as follows:
7077
7078 BIT0 | BIT 1 | BIT 2 | BIT 3
7079 U | L | (U | L) | (U & L)
7080
7081 So, for an "all" relationship, BIT 3 would be set.
7082 For an "any" relationship, BIT 2 would be set. Etc.
7083
7084 Following traditional nomenclature, these bits map to:
7085
7086 BIT0 | BIT 1 | BIT 2 | BIT 3
7087 LT | GT | EQ | OV
7088
7089 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
7090 */
7091
7092 switch (form_int)
7093 {
7094 /* All variant. OV bit. */
7095 case 0:
7096 /* We need to get to the OV bit, which is the ORDERED bit. We
7097 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
7098 that's ugly and will trigger a validate_condition_mode abort.
7099 So let's just use another pattern. */
7100 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
7101 return target;
7102 /* Any variant. EQ bit. */
7103 case 1:
7104 code = EQ;
7105 break;
7106 /* Upper variant. LT bit. */
7107 case 2:
7108 code = LT;
7109 break;
7110 /* Lower variant. GT bit. */
7111 case 3:
7112 code = GT;
7113 break;
7114 default:
7115 error ("argument 1 of __builtin_spe_predicate is out of range");
7116 return const0_rtx;
7117 }
7118
7119 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
7120 emit_move_insn (target, tmp);
7121
7122 return target;
7123}
7124
7125/* The evsel builtins look like this:
7126
7127 e = __builtin_spe_evsel_OP (a, b, c, d);
7128
7129 and work like this:
7130
7131 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
7132 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
7133*/
7134
7135static rtx
a2369ed3 7136spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
7137{
7138 rtx pat, scratch;
7139 tree arg0 = TREE_VALUE (arglist);
7140 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
7141 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
7142 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
7143 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
7144 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
7145 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
7146 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
7147 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
7148 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
7149
7150 if (mode0 != mode1)
7151 abort ();
7152
7153 if (arg0 == error_mark_node || arg1 == error_mark_node
7154 || arg2 == error_mark_node || arg3 == error_mark_node)
7155 return const0_rtx;
7156
7157 if (target == 0
7158 || GET_MODE (target) != mode0
7159 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
7160 target = gen_reg_rtx (mode0);
7161
7162 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
7163 op0 = copy_to_mode_reg (mode0, op0);
7164 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
7165 op1 = copy_to_mode_reg (mode0, op1);
7166 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
7167 op2 = copy_to_mode_reg (mode0, op2);
7168 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
7169 op3 = copy_to_mode_reg (mode0, op3);
7170
7171 /* Generate the compare. */
7172 scratch = gen_reg_rtx (CCmode);
7173 pat = GEN_FCN (icode) (scratch, op0, op1);
7174 if (! pat)
7175 return const0_rtx;
7176 emit_insn (pat);
7177
7178 if (mode0 == V2SImode)
7179 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
7180 else
7181 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
7182
7183 return target;
7184}
7185
0ac081f6
AH
7186/* Expand an expression EXP that calls a built-in function,
7187 with result going to TARGET if that's convenient
7188 (and in mode MODE if that's convenient).
7189 SUBTARGET may be used as the target for computing one of EXP's operands.
7190 IGNORE is nonzero if the value is to be ignored. */
7191
7192static rtx
a2369ed3 7193rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
f676971a 7194 enum machine_mode mode ATTRIBUTE_UNUSED,
a2369ed3 7195 int ignore ATTRIBUTE_UNUSED)
0ac081f6 7196{
92898235
AH
7197 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
7198 tree arglist = TREE_OPERAND (exp, 1);
7199 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
7200 struct builtin_description *d;
7201 size_t i;
7202 rtx ret;
7203 bool success;
f676971a 7204
0ac081f6 7205 if (TARGET_ALTIVEC)
92898235
AH
7206 {
7207 ret = altivec_expand_builtin (exp, target, &success);
7208
a3170dc6
AH
7209 if (success)
7210 return ret;
7211 }
7212 if (TARGET_SPE)
7213 {
7214 ret = spe_expand_builtin (exp, target, &success);
7215
92898235
AH
7216 if (success)
7217 return ret;
7218 }
7219
0559cc77
DE
7220 if (TARGET_ALTIVEC || TARGET_SPE)
7221 {
7222 /* Handle simple unary operations. */
7223 d = (struct builtin_description *) bdesc_1arg;
7224 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
7225 if (d->code == fcode)
7226 return rs6000_expand_unop_builtin (d->icode, arglist, target);
7227
7228 /* Handle simple binary operations. */
7229 d = (struct builtin_description *) bdesc_2arg;
7230 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
7231 if (d->code == fcode)
7232 return rs6000_expand_binop_builtin (d->icode, arglist, target);
7233
7234 /* Handle simple ternary operations. */
7235 d = (struct builtin_description *) bdesc_3arg;
7236 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
7237 if (d->code == fcode)
7238 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
7239 }
0ac081f6
AH
7240
7241 abort ();
92898235 7242 return NULL_RTX;
0ac081f6
AH
7243}
7244
7c62e993
PB
7245static tree
7246build_opaque_vector_type (tree node, int nunits)
7247{
7248 node = copy_node (node);
7249 TYPE_MAIN_VARIANT (node) = node;
7250 return build_vector_type (node, nunits);
7251}
7252
0ac081f6 7253static void
863d938c 7254rs6000_init_builtins (void)
0ac081f6 7255{
4a5eab38
PB
7256 V2SI_type_node = build_vector_type (intSI_type_node, 2);
7257 V2SF_type_node = build_vector_type (float_type_node, 2);
7258 V4HI_type_node = build_vector_type (intHI_type_node, 4);
7259 V4SI_type_node = build_vector_type (intSI_type_node, 4);
7260 V4SF_type_node = build_vector_type (float_type_node, 4);
7e463bda 7261 V8HI_type_node = build_vector_type (intHI_type_node, 8);
4a5eab38
PB
7262 V16QI_type_node = build_vector_type (intQI_type_node, 16);
7263
7264 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
7265 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
7266 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
7267
7c62e993
PB
7268 opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2);
7269 opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2);
6035d635 7270 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 7271
8bb418a3
ZL
7272 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
7273 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
7274 'vector unsigned short'. */
7275
8dd16ecc
NS
7276 bool_char_type_node = build_distinct_type_copy (unsigned_intQI_type_node);
7277 bool_short_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
7278 bool_int_type_node = build_distinct_type_copy (unsigned_intSI_type_node);
7279 pixel_type_node = build_distinct_type_copy (unsigned_intHI_type_node);
8bb418a3
ZL
7280
7281 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7282 get_identifier ("__bool char"),
7283 bool_char_type_node));
7284 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7285 get_identifier ("__bool short"),
7286 bool_short_type_node));
7287 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7288 get_identifier ("__bool int"),
7289 bool_int_type_node));
7290 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7291 get_identifier ("__pixel"),
7292 pixel_type_node));
7293
4a5eab38
PB
7294 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
7295 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
7296 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
7297 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
8bb418a3
ZL
7298
7299 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7300 get_identifier ("__vector unsigned char"),
7301 unsigned_V16QI_type_node));
7302 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7303 get_identifier ("__vector signed char"),
7304 V16QI_type_node));
7305 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7306 get_identifier ("__vector __bool char"),
7307 bool_V16QI_type_node));
7308
7309 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7310 get_identifier ("__vector unsigned short"),
7311 unsigned_V8HI_type_node));
7312 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7313 get_identifier ("__vector signed short"),
7314 V8HI_type_node));
7315 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7316 get_identifier ("__vector __bool short"),
7317 bool_V8HI_type_node));
7318
7319 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7320 get_identifier ("__vector unsigned int"),
7321 unsigned_V4SI_type_node));
7322 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7323 get_identifier ("__vector signed int"),
7324 V4SI_type_node));
7325 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7326 get_identifier ("__vector __bool int"),
7327 bool_V4SI_type_node));
7328
7329 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7330 get_identifier ("__vector float"),
7331 V4SF_type_node));
7332 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
7333 get_identifier ("__vector __pixel"),
7334 pixel_V8HI_type_node));
7335
a3170dc6 7336 if (TARGET_SPE)
3fdaa45a 7337 spe_init_builtins ();
0ac081f6
AH
7338 if (TARGET_ALTIVEC)
7339 altivec_init_builtins ();
0559cc77
DE
7340 if (TARGET_ALTIVEC || TARGET_SPE)
7341 rs6000_common_init_builtins ();
0ac081f6
AH
7342}
7343
a3170dc6
AH
7344/* Search through a set of builtins and enable the mask bits.
7345 DESC is an array of builtins.
b6d08ca1 7346 SIZE is the total number of builtins.
a3170dc6
AH
7347 START is the builtin enum at which to start.
7348 END is the builtin enum at which to end. */
0ac081f6 7349static void
a2369ed3 7350enable_mask_for_builtins (struct builtin_description *desc, int size,
f676971a 7351 enum rs6000_builtins start,
a2369ed3 7352 enum rs6000_builtins end)
a3170dc6
AH
7353{
7354 int i;
7355
7356 for (i = 0; i < size; ++i)
7357 if (desc[i].code == start)
7358 break;
7359
7360 if (i == size)
7361 return;
7362
7363 for (; i < size; ++i)
7364 {
7365 /* Flip all the bits on. */
7366 desc[i].mask = target_flags;
7367 if (desc[i].code == end)
7368 break;
7369 }
7370}
7371
7372static void
863d938c 7373spe_init_builtins (void)
0ac081f6 7374{
a3170dc6
AH
7375 tree endlink = void_list_node;
7376 tree puint_type_node = build_pointer_type (unsigned_type_node);
7377 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 7378 struct builtin_description *d;
0ac081f6
AH
7379 size_t i;
7380
a3170dc6
AH
7381 tree v2si_ftype_4_v2si
7382 = build_function_type
3fdaa45a
AH
7383 (opaque_V2SI_type_node,
7384 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7385 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7386 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7387 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7388 endlink)))));
7389
7390 tree v2sf_ftype_4_v2sf
7391 = build_function_type
3fdaa45a
AH
7392 (opaque_V2SF_type_node,
7393 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7394 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7395 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7396 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7397 endlink)))));
7398
7399 tree int_ftype_int_v2si_v2si
7400 = build_function_type
7401 (integer_type_node,
7402 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7403 tree_cons (NULL_TREE, opaque_V2SI_type_node,
7404 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7405 endlink))));
7406
7407 tree int_ftype_int_v2sf_v2sf
7408 = build_function_type
7409 (integer_type_node,
7410 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
7411 tree_cons (NULL_TREE, opaque_V2SF_type_node,
7412 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
7413 endlink))));
7414
7415 tree void_ftype_v2si_puint_int
7416 = build_function_type (void_type_node,
3fdaa45a 7417 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7418 tree_cons (NULL_TREE, puint_type_node,
7419 tree_cons (NULL_TREE,
7420 integer_type_node,
7421 endlink))));
7422
7423 tree void_ftype_v2si_puint_char
7424 = build_function_type (void_type_node,
3fdaa45a 7425 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7426 tree_cons (NULL_TREE, puint_type_node,
7427 tree_cons (NULL_TREE,
7428 char_type_node,
7429 endlink))));
7430
7431 tree void_ftype_v2si_pv2si_int
7432 = build_function_type (void_type_node,
3fdaa45a 7433 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7434 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7435 tree_cons (NULL_TREE,
7436 integer_type_node,
7437 endlink))));
7438
7439 tree void_ftype_v2si_pv2si_char
7440 = build_function_type (void_type_node,
3fdaa45a 7441 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7442 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7443 tree_cons (NULL_TREE,
7444 char_type_node,
7445 endlink))));
7446
7447 tree void_ftype_int
7448 = build_function_type (void_type_node,
7449 tree_cons (NULL_TREE, integer_type_node, endlink));
7450
7451 tree int_ftype_void
36e8d515 7452 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
7453
7454 tree v2si_ftype_pv2si_int
3fdaa45a 7455 = build_function_type (opaque_V2SI_type_node,
6035d635 7456 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7457 tree_cons (NULL_TREE, integer_type_node,
7458 endlink)));
7459
7460 tree v2si_ftype_puint_int
3fdaa45a 7461 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7462 tree_cons (NULL_TREE, puint_type_node,
7463 tree_cons (NULL_TREE, integer_type_node,
7464 endlink)));
7465
7466 tree v2si_ftype_pushort_int
3fdaa45a 7467 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7468 tree_cons (NULL_TREE, pushort_type_node,
7469 tree_cons (NULL_TREE, integer_type_node,
7470 endlink)));
7471
00332c9f
AH
7472 tree v2si_ftype_signed_char
7473 = build_function_type (opaque_V2SI_type_node,
7474 tree_cons (NULL_TREE, signed_char_type_node,
7475 endlink));
7476
a3170dc6
AH
7477 /* The initialization of the simple binary and unary builtins is
7478 done in rs6000_common_init_builtins, but we have to enable the
7479 mask bits here manually because we have run out of `target_flags'
7480 bits. We really need to redesign this mask business. */
7481
7482 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
7483 ARRAY_SIZE (bdesc_2arg),
7484 SPE_BUILTIN_EVADDW,
7485 SPE_BUILTIN_EVXOR);
7486 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
7487 ARRAY_SIZE (bdesc_1arg),
7488 SPE_BUILTIN_EVABS,
7489 SPE_BUILTIN_EVSUBFUSIAAW);
7490 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
7491 ARRAY_SIZE (bdesc_spe_predicates),
7492 SPE_BUILTIN_EVCMPEQ,
7493 SPE_BUILTIN_EVFSTSTLT);
7494 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
7495 ARRAY_SIZE (bdesc_spe_evsel),
7496 SPE_BUILTIN_EVSEL_CMPGTS,
7497 SPE_BUILTIN_EVSEL_FSTSTEQ);
7498
36252949
AH
7499 (*lang_hooks.decls.pushdecl)
7500 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
7501 opaque_V2SI_type_node));
7502
a3170dc6 7503 /* Initialize irregular SPE builtins. */
f676971a 7504
a3170dc6
AH
7505 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
7506 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
7507 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
7508 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
7509 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
7510 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
7511 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
7512 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
7513 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
7514 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
7515 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
7516 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
7517 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
7518 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
7519 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
7520 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
7521 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
7522 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
7523
7524 /* Loads. */
7525 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
7526 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
7527 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
7528 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
7529 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
7530 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
7531 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
7532 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
7533 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
7534 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
7535 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
7536 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
7537 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
7538 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
7539 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
7540 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
7541 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
7542 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
7543 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
7544 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
7545 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
7546 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
7547
7548 /* Predicates. */
7549 d = (struct builtin_description *) bdesc_spe_predicates;
7550 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
7551 {
7552 tree type;
7553
7554 switch (insn_data[d->icode].operand[1].mode)
7555 {
7556 case V2SImode:
7557 type = int_ftype_int_v2si_v2si;
7558 break;
7559 case V2SFmode:
7560 type = int_ftype_int_v2sf_v2sf;
7561 break;
7562 default:
7563 abort ();
7564 }
7565
7566 def_builtin (d->mask, d->name, type, d->code);
7567 }
7568
7569 /* Evsel predicates. */
7570 d = (struct builtin_description *) bdesc_spe_evsel;
7571 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
7572 {
7573 tree type;
7574
7575 switch (insn_data[d->icode].operand[1].mode)
7576 {
7577 case V2SImode:
7578 type = v2si_ftype_4_v2si;
7579 break;
7580 case V2SFmode:
7581 type = v2sf_ftype_4_v2sf;
7582 break;
7583 default:
7584 abort ();
7585 }
7586
7587 def_builtin (d->mask, d->name, type, d->code);
7588 }
7589}
7590
7591static void
863d938c 7592altivec_init_builtins (void)
a3170dc6
AH
7593{
7594 struct builtin_description *d;
7595 struct builtin_description_predicates *dp;
7596 size_t i;
7597 tree pfloat_type_node = build_pointer_type (float_type_node);
7598 tree pint_type_node = build_pointer_type (integer_type_node);
7599 tree pshort_type_node = build_pointer_type (short_integer_type_node);
7600 tree pchar_type_node = build_pointer_type (char_type_node);
7601
7602 tree pvoid_type_node = build_pointer_type (void_type_node);
7603
0dbc3651
ZW
7604 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
7605 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
7606 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
7607 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
7608
7609 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
7610
a3170dc6
AH
7611 tree int_ftype_int_v4si_v4si
7612 = build_function_type_list (integer_type_node,
7613 integer_type_node, V4SI_type_node,
7614 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7615 tree v4sf_ftype_pcfloat
7616 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 7617 tree void_ftype_pfloat_v4sf
b4de2f7d 7618 = build_function_type_list (void_type_node,
a3170dc6 7619 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
7620 tree v4si_ftype_pcint
7621 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
7622 tree void_ftype_pint_v4si
b4de2f7d
AH
7623 = build_function_type_list (void_type_node,
7624 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7625 tree v8hi_ftype_pcshort
7626 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 7627 tree void_ftype_pshort_v8hi
b4de2f7d
AH
7628 = build_function_type_list (void_type_node,
7629 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
7630 tree v16qi_ftype_pcchar
7631 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 7632 tree void_ftype_pchar_v16qi
b4de2f7d
AH
7633 = build_function_type_list (void_type_node,
7634 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 7635 tree void_ftype_v4si
b4de2f7d 7636 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7637 tree v8hi_ftype_void
7638 = build_function_type (V8HI_type_node, void_list_node);
7639 tree void_ftype_void
7640 = build_function_type (void_type_node, void_list_node);
e34b6648
JJ
7641 tree void_ftype_int
7642 = build_function_type_list (void_type_node, integer_type_node, NULL_TREE);
0dbc3651 7643
b4a62fa0 7644 tree v16qi_ftype_long_pcvoid
a3170dc6 7645 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
7646 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7647 tree v8hi_ftype_long_pcvoid
a3170dc6 7648 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
7649 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7650 tree v4si_ftype_long_pcvoid
a3170dc6 7651 = build_function_type_list (V4SI_type_node,
b4a62fa0 7652 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 7653
b4a62fa0 7654 tree void_ftype_v4si_long_pvoid
b4de2f7d 7655 = build_function_type_list (void_type_node,
b4a62fa0 7656 V4SI_type_node, long_integer_type_node,
b4de2f7d 7657 pvoid_type_node, NULL_TREE);
b4a62fa0 7658 tree void_ftype_v16qi_long_pvoid
b4de2f7d 7659 = build_function_type_list (void_type_node,
b4a62fa0 7660 V16QI_type_node, long_integer_type_node,
b4de2f7d 7661 pvoid_type_node, NULL_TREE);
b4a62fa0 7662 tree void_ftype_v8hi_long_pvoid
b4de2f7d 7663 = build_function_type_list (void_type_node,
b4a62fa0 7664 V8HI_type_node, long_integer_type_node,
b4de2f7d 7665 pvoid_type_node, NULL_TREE);
a3170dc6
AH
7666 tree int_ftype_int_v8hi_v8hi
7667 = build_function_type_list (integer_type_node,
7668 integer_type_node, V8HI_type_node,
7669 V8HI_type_node, NULL_TREE);
7670 tree int_ftype_int_v16qi_v16qi
7671 = build_function_type_list (integer_type_node,
7672 integer_type_node, V16QI_type_node,
7673 V16QI_type_node, NULL_TREE);
7674 tree int_ftype_int_v4sf_v4sf
7675 = build_function_type_list (integer_type_node,
7676 integer_type_node, V4SF_type_node,
7677 V4SF_type_node, NULL_TREE);
7678 tree v4si_ftype_v4si
7679 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
7680 tree v8hi_ftype_v8hi
7681 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
7682 tree v16qi_ftype_v16qi
7683 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
7684 tree v4sf_ftype_v4sf
7685 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 7686 tree void_ftype_pcvoid_int_int
a3170dc6 7687 = build_function_type_list (void_type_node,
0dbc3651 7688 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
7689 integer_type_node, NULL_TREE);
7690 tree int_ftype_pcchar
7691 = build_function_type_list (integer_type_node,
7692 pcchar_type_node, NULL_TREE);
7693
0dbc3651
ZW
7694 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
7695 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
7696 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
7697 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
7698 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
7699 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
7700 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
7701 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
7702 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
7703 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
7704 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
7705 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
7706 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
7707 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
7708 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
7709 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
7710 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
7711 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
7712 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
e34b6648 7713 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_int, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
7714 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
7715 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
7716 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
7717 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
7718 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
7719 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
7720 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
7721 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
7722 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
7723 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
7724 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
7725 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 7726
8bb418a3
ZL
7727 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
7728 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
7729 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
7730
a3170dc6
AH
7731 /* Add the DST variants. */
7732 d = (struct builtin_description *) bdesc_dst;
7733 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 7734 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
7735
7736 /* Initialize the predicates. */
7737 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
7738 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
7739 {
7740 enum machine_mode mode1;
7741 tree type;
7742
7743 mode1 = insn_data[dp->icode].operand[1].mode;
7744
7745 switch (mode1)
7746 {
7747 case V4SImode:
7748 type = int_ftype_int_v4si_v4si;
7749 break;
7750 case V8HImode:
7751 type = int_ftype_int_v8hi_v8hi;
7752 break;
7753 case V16QImode:
7754 type = int_ftype_int_v16qi_v16qi;
7755 break;
7756 case V4SFmode:
7757 type = int_ftype_int_v4sf_v4sf;
7758 break;
7759 default:
7760 abort ();
7761 }
f676971a 7762
a3170dc6
AH
7763 def_builtin (dp->mask, dp->name, type, dp->code);
7764 }
7765
7766 /* Initialize the abs* operators. */
7767 d = (struct builtin_description *) bdesc_abs;
7768 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
7769 {
7770 enum machine_mode mode0;
7771 tree type;
7772
7773 mode0 = insn_data[d->icode].operand[0].mode;
7774
7775 switch (mode0)
7776 {
7777 case V4SImode:
7778 type = v4si_ftype_v4si;
7779 break;
7780 case V8HImode:
7781 type = v8hi_ftype_v8hi;
7782 break;
7783 case V16QImode:
7784 type = v16qi_ftype_v16qi;
7785 break;
7786 case V4SFmode:
7787 type = v4sf_ftype_v4sf;
7788 break;
7789 default:
7790 abort ();
7791 }
f676971a 7792
a3170dc6
AH
7793 def_builtin (d->mask, d->name, type, d->code);
7794 }
7795}
7796
7797static void
863d938c 7798rs6000_common_init_builtins (void)
a3170dc6
AH
7799{
7800 struct builtin_description *d;
7801 size_t i;
7802
7803 tree v4sf_ftype_v4sf_v4sf_v16qi
7804 = build_function_type_list (V4SF_type_node,
7805 V4SF_type_node, V4SF_type_node,
7806 V16QI_type_node, NULL_TREE);
7807 tree v4si_ftype_v4si_v4si_v16qi
7808 = build_function_type_list (V4SI_type_node,
7809 V4SI_type_node, V4SI_type_node,
7810 V16QI_type_node, NULL_TREE);
7811 tree v8hi_ftype_v8hi_v8hi_v16qi
7812 = build_function_type_list (V8HI_type_node,
7813 V8HI_type_node, V8HI_type_node,
7814 V16QI_type_node, NULL_TREE);
7815 tree v16qi_ftype_v16qi_v16qi_v16qi
7816 = build_function_type_list (V16QI_type_node,
7817 V16QI_type_node, V16QI_type_node,
7818 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
7819 tree v4si_ftype_int
7820 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
7821 tree v8hi_ftype_int
7822 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
7823 tree v16qi_ftype_int
7824 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
7825 tree v8hi_ftype_v16qi
7826 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
7827 tree v4sf_ftype_v4sf
7828 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
7829
7830 tree v2si_ftype_v2si_v2si
2abe3e28
AH
7831 = build_function_type_list (opaque_V2SI_type_node,
7832 opaque_V2SI_type_node,
7833 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7834
7835 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
7836 = build_function_type_list (opaque_V2SF_type_node,
7837 opaque_V2SF_type_node,
7838 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7839
7840 tree v2si_ftype_int_int
2abe3e28 7841 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7842 integer_type_node, integer_type_node,
7843 NULL_TREE);
7844
7845 tree v2si_ftype_v2si
2abe3e28
AH
7846 = build_function_type_list (opaque_V2SI_type_node,
7847 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7848
7849 tree v2sf_ftype_v2sf
2abe3e28
AH
7850 = build_function_type_list (opaque_V2SF_type_node,
7851 opaque_V2SF_type_node, NULL_TREE);
f676971a 7852
a3170dc6 7853 tree v2sf_ftype_v2si
2abe3e28
AH
7854 = build_function_type_list (opaque_V2SF_type_node,
7855 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7856
7857 tree v2si_ftype_v2sf
2abe3e28
AH
7858 = build_function_type_list (opaque_V2SI_type_node,
7859 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7860
7861 tree v2si_ftype_v2si_char
2abe3e28
AH
7862 = build_function_type_list (opaque_V2SI_type_node,
7863 opaque_V2SI_type_node,
7864 char_type_node, NULL_TREE);
a3170dc6
AH
7865
7866 tree v2si_ftype_int_char
2abe3e28 7867 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7868 integer_type_node, char_type_node, NULL_TREE);
7869
7870 tree v2si_ftype_char
2abe3e28
AH
7871 = build_function_type_list (opaque_V2SI_type_node,
7872 char_type_node, NULL_TREE);
a3170dc6
AH
7873
7874 tree int_ftype_int_int
7875 = build_function_type_list (integer_type_node,
7876 integer_type_node, integer_type_node,
7877 NULL_TREE);
95385cbb 7878
0ac081f6 7879 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
7880 = build_function_type_list (V4SI_type_node,
7881 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 7882 tree v4sf_ftype_v4si_int
b4de2f7d 7883 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
7884 V4SI_type_node, integer_type_node, NULL_TREE);
7885 tree v4si_ftype_v4sf_int
b4de2f7d 7886 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7887 V4SF_type_node, integer_type_node, NULL_TREE);
7888 tree v4si_ftype_v4si_int
b4de2f7d 7889 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7890 V4SI_type_node, integer_type_node, NULL_TREE);
7891 tree v8hi_ftype_v8hi_int
b4de2f7d 7892 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
7893 V8HI_type_node, integer_type_node, NULL_TREE);
7894 tree v16qi_ftype_v16qi_int
b4de2f7d 7895 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
7896 V16QI_type_node, integer_type_node, NULL_TREE);
7897 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
7898 = build_function_type_list (V16QI_type_node,
7899 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
7900 integer_type_node, NULL_TREE);
7901 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
7902 = build_function_type_list (V8HI_type_node,
7903 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
7904 integer_type_node, NULL_TREE);
7905 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
7906 = build_function_type_list (V4SI_type_node,
7907 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
7908 integer_type_node, NULL_TREE);
7909 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
7910 = build_function_type_list (V4SF_type_node,
7911 V4SF_type_node, V4SF_type_node,
b9e4e5d1 7912 integer_type_node, NULL_TREE);
0ac081f6 7913 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
7914 = build_function_type_list (V4SF_type_node,
7915 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 7916 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
7917 = build_function_type_list (V4SF_type_node,
7918 V4SF_type_node, V4SF_type_node,
7919 V4SI_type_node, NULL_TREE);
2212663f 7920 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
7921 = build_function_type_list (V4SF_type_node,
7922 V4SF_type_node, V4SF_type_node,
7923 V4SF_type_node, NULL_TREE);
f676971a 7924 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
7925 = build_function_type_list (V4SI_type_node,
7926 V4SI_type_node, V4SI_type_node,
7927 V4SI_type_node, NULL_TREE);
0ac081f6 7928 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
7929 = build_function_type_list (V8HI_type_node,
7930 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 7931 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
7932 = build_function_type_list (V8HI_type_node,
7933 V8HI_type_node, V8HI_type_node,
7934 V8HI_type_node, NULL_TREE);
2212663f 7935 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
7936 = build_function_type_list (V4SI_type_node,
7937 V8HI_type_node, V8HI_type_node,
7938 V4SI_type_node, NULL_TREE);
2212663f 7939 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
7940 = build_function_type_list (V4SI_type_node,
7941 V16QI_type_node, V16QI_type_node,
7942 V4SI_type_node, NULL_TREE);
0ac081f6 7943 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
7944 = build_function_type_list (V16QI_type_node,
7945 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7946 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
7947 = build_function_type_list (V4SI_type_node,
7948 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 7949 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
7950 = build_function_type_list (V8HI_type_node,
7951 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7952 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
7953 = build_function_type_list (V4SI_type_node,
7954 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7955 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
7956 = build_function_type_list (V8HI_type_node,
7957 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 7958 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
7959 = build_function_type_list (V16QI_type_node,
7960 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7961 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
7962 = build_function_type_list (V4SI_type_node,
7963 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 7964 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
7965 = build_function_type_list (V4SI_type_node,
7966 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7967 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
7968 = build_function_type_list (V4SI_type_node,
7969 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7970 tree v4si_ftype_v8hi
7971 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
7972 tree int_ftype_v4si_v4si
7973 = build_function_type_list (integer_type_node,
7974 V4SI_type_node, V4SI_type_node, NULL_TREE);
7975 tree int_ftype_v4sf_v4sf
7976 = build_function_type_list (integer_type_node,
7977 V4SF_type_node, V4SF_type_node, NULL_TREE);
7978 tree int_ftype_v16qi_v16qi
7979 = build_function_type_list (integer_type_node,
7980 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7981 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
7982 = build_function_type_list (integer_type_node,
7983 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7984
6f317ef3 7985 /* Add the simple ternary operators. */
2212663f 7986 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 7987 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f 7988 {
f676971a 7989
2212663f
DB
7990 enum machine_mode mode0, mode1, mode2, mode3;
7991 tree type;
7992
0559cc77 7993 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 7994 continue;
f676971a 7995
2212663f
DB
7996 mode0 = insn_data[d->icode].operand[0].mode;
7997 mode1 = insn_data[d->icode].operand[1].mode;
7998 mode2 = insn_data[d->icode].operand[2].mode;
7999 mode3 = insn_data[d->icode].operand[3].mode;
f676971a 8000
2212663f
DB
8001 /* When all four are of the same mode. */
8002 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
8003 {
8004 switch (mode0)
8005 {
617e0e1d
DB
8006 case V4SImode:
8007 type = v4si_ftype_v4si_v4si_v4si;
8008 break;
2212663f
DB
8009 case V4SFmode:
8010 type = v4sf_ftype_v4sf_v4sf_v4sf;
8011 break;
8012 case V8HImode:
8013 type = v8hi_ftype_v8hi_v8hi_v8hi;
f676971a 8014 break;
2212663f
DB
8015 case V16QImode:
8016 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8017 break;
2212663f 8018 default:
f676971a 8019 abort();
2212663f
DB
8020 }
8021 }
8022 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
8023 {
8024 switch (mode0)
8025 {
8026 case V4SImode:
8027 type = v4si_ftype_v4si_v4si_v16qi;
8028 break;
8029 case V4SFmode:
8030 type = v4sf_ftype_v4sf_v4sf_v16qi;
8031 break;
8032 case V8HImode:
8033 type = v8hi_ftype_v8hi_v8hi_v16qi;
f676971a 8034 break;
2212663f
DB
8035 case V16QImode:
8036 type = v16qi_ftype_v16qi_v16qi_v16qi;
f676971a 8037 break;
2212663f 8038 default:
f676971a 8039 abort();
2212663f
DB
8040 }
8041 }
f676971a 8042 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
2212663f 8043 && mode3 == V4SImode)
24408032 8044 type = v4si_ftype_v16qi_v16qi_v4si;
f676971a 8045 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
2212663f 8046 && mode3 == V4SImode)
24408032 8047 type = v4si_ftype_v8hi_v8hi_v4si;
f676971a 8048 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
617e0e1d 8049 && mode3 == V4SImode)
24408032
AH
8050 type = v4sf_ftype_v4sf_v4sf_v4si;
8051
8052 /* vchar, vchar, vchar, 4 bit literal. */
8053 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
8054 && mode3 == QImode)
b9e4e5d1 8055 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
8056
8057 /* vshort, vshort, vshort, 4 bit literal. */
8058 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
8059 && mode3 == QImode)
b9e4e5d1 8060 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
8061
8062 /* vint, vint, vint, 4 bit literal. */
8063 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
8064 && mode3 == QImode)
b9e4e5d1 8065 type = v4si_ftype_v4si_v4si_int;
24408032
AH
8066
8067 /* vfloat, vfloat, vfloat, 4 bit literal. */
8068 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
8069 && mode3 == QImode)
b9e4e5d1 8070 type = v4sf_ftype_v4sf_v4sf_int;
24408032 8071
2212663f
DB
8072 else
8073 abort ();
8074
8075 def_builtin (d->mask, d->name, type, d->code);
8076 }
8077
0ac081f6 8078 /* Add the simple binary operators. */
00b960c7 8079 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 8080 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
8081 {
8082 enum machine_mode mode0, mode1, mode2;
8083 tree type;
8084
0559cc77 8085 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6 8086 continue;
f676971a 8087
0ac081f6
AH
8088 mode0 = insn_data[d->icode].operand[0].mode;
8089 mode1 = insn_data[d->icode].operand[1].mode;
8090 mode2 = insn_data[d->icode].operand[2].mode;
8091
8092 /* When all three operands are of the same mode. */
8093 if (mode0 == mode1 && mode1 == mode2)
8094 {
8095 switch (mode0)
8096 {
8097 case V4SFmode:
8098 type = v4sf_ftype_v4sf_v4sf;
8099 break;
8100 case V4SImode:
8101 type = v4si_ftype_v4si_v4si;
8102 break;
8103 case V16QImode:
8104 type = v16qi_ftype_v16qi_v16qi;
8105 break;
8106 case V8HImode:
8107 type = v8hi_ftype_v8hi_v8hi;
8108 break;
a3170dc6
AH
8109 case V2SImode:
8110 type = v2si_ftype_v2si_v2si;
8111 break;
8112 case V2SFmode:
8113 type = v2sf_ftype_v2sf_v2sf;
8114 break;
8115 case SImode:
8116 type = int_ftype_int_int;
8117 break;
0ac081f6
AH
8118 default:
8119 abort ();
8120 }
8121 }
8122
8123 /* A few other combos we really don't want to do manually. */
8124
8125 /* vint, vfloat, vfloat. */
8126 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
8127 type = v4si_ftype_v4sf_v4sf;
8128
8129 /* vshort, vchar, vchar. */
8130 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
8131 type = v8hi_ftype_v16qi_v16qi;
8132
8133 /* vint, vshort, vshort. */
8134 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
8135 type = v4si_ftype_v8hi_v8hi;
8136
8137 /* vshort, vint, vint. */
8138 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
8139 type = v8hi_ftype_v4si_v4si;
8140
8141 /* vchar, vshort, vshort. */
8142 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
8143 type = v16qi_ftype_v8hi_v8hi;
8144
8145 /* vint, vchar, vint. */
8146 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
8147 type = v4si_ftype_v16qi_v4si;
8148
fa066a23
AH
8149 /* vint, vchar, vchar. */
8150 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
8151 type = v4si_ftype_v16qi_v16qi;
8152
0ac081f6
AH
8153 /* vint, vshort, vint. */
8154 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
8155 type = v4si_ftype_v8hi_v4si;
f676971a 8156
2212663f
DB
8157 /* vint, vint, 5 bit literal. */
8158 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8159 type = v4si_ftype_v4si_int;
f676971a 8160
2212663f
DB
8161 /* vshort, vshort, 5 bit literal. */
8162 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 8163 type = v8hi_ftype_v8hi_int;
f676971a 8164
2212663f
DB
8165 /* vchar, vchar, 5 bit literal. */
8166 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 8167 type = v16qi_ftype_v16qi_int;
0ac081f6 8168
617e0e1d
DB
8169 /* vfloat, vint, 5 bit literal. */
8170 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 8171 type = v4sf_ftype_v4si_int;
f676971a 8172
617e0e1d
DB
8173 /* vint, vfloat, 5 bit literal. */
8174 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 8175 type = v4si_ftype_v4sf_int;
617e0e1d 8176
a3170dc6
AH
8177 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
8178 type = v2si_ftype_int_int;
8179
8180 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
8181 type = v2si_ftype_v2si_char;
8182
8183 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
8184 type = v2si_ftype_int_char;
8185
0ac081f6
AH
8186 /* int, x, x. */
8187 else if (mode0 == SImode)
8188 {
8189 switch (mode1)
8190 {
8191 case V4SImode:
8192 type = int_ftype_v4si_v4si;
8193 break;
8194 case V4SFmode:
8195 type = int_ftype_v4sf_v4sf;
8196 break;
8197 case V16QImode:
8198 type = int_ftype_v16qi_v16qi;
8199 break;
8200 case V8HImode:
8201 type = int_ftype_v8hi_v8hi;
8202 break;
8203 default:
8204 abort ();
8205 }
8206 }
8207
8208 else
8209 abort ();
8210
2212663f
DB
8211 def_builtin (d->mask, d->name, type, d->code);
8212 }
24408032 8213
2212663f
DB
8214 /* Add the simple unary operators. */
8215 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 8216 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
8217 {
8218 enum machine_mode mode0, mode1;
8219 tree type;
8220
0559cc77 8221 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f 8222 continue;
f676971a 8223
2212663f
DB
8224 mode0 = insn_data[d->icode].operand[0].mode;
8225 mode1 = insn_data[d->icode].operand[1].mode;
8226
8227 if (mode0 == V4SImode && mode1 == QImode)
b9e4e5d1 8228 type = v4si_ftype_int;
2212663f 8229 else if (mode0 == V8HImode && mode1 == QImode)
b9e4e5d1 8230 type = v8hi_ftype_int;
2212663f 8231 else if (mode0 == V16QImode && mode1 == QImode)
b9e4e5d1 8232 type = v16qi_ftype_int;
617e0e1d
DB
8233 else if (mode0 == V4SFmode && mode1 == V4SFmode)
8234 type = v4sf_ftype_v4sf;
20e26713
AH
8235 else if (mode0 == V8HImode && mode1 == V16QImode)
8236 type = v8hi_ftype_v16qi;
8237 else if (mode0 == V4SImode && mode1 == V8HImode)
8238 type = v4si_ftype_v8hi;
a3170dc6
AH
8239 else if (mode0 == V2SImode && mode1 == V2SImode)
8240 type = v2si_ftype_v2si;
8241 else if (mode0 == V2SFmode && mode1 == V2SFmode)
8242 type = v2sf_ftype_v2sf;
8243 else if (mode0 == V2SFmode && mode1 == V2SImode)
8244 type = v2sf_ftype_v2si;
8245 else if (mode0 == V2SImode && mode1 == V2SFmode)
8246 type = v2si_ftype_v2sf;
8247 else if (mode0 == V2SImode && mode1 == QImode)
8248 type = v2si_ftype_char;
2212663f
DB
8249 else
8250 abort ();
8251
0ac081f6
AH
8252 def_builtin (d->mask, d->name, type, d->code);
8253 }
8254}
8255
c15c90bb
ZW
8256static void
8257rs6000_init_libfuncs (void)
8258{
8259 if (!TARGET_HARD_FLOAT)
8260 return;
8261
c9034561 8262 if (DEFAULT_ABI != ABI_V4)
c15c90bb 8263 {
c9034561 8264 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 8265 {
c9034561 8266 /* AIX library routines for float->int conversion. */
85363ca0
ZW
8267 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
8268 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
8269 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
8270 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
8271 }
8272
c9034561 8273 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8274 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
8275 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
8276 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
8277 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
8278 }
c9034561 8279 else
c15c90bb 8280 {
c9034561 8281 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
8282
8283 set_optab_libfunc (add_optab, TFmode, "_q_add");
8284 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
8285 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
8286 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
8287 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
8288 if (TARGET_PPC_GPOPT || TARGET_POWER2)
8289 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
8290
c9034561
ZW
8291 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
8292 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
8293 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
8294 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
8295 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
8296 set_optab_libfunc (le_optab, TFmode, "_q_fle");
8297
85363ca0
ZW
8298 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
8299 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
8300 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
8301 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
8302 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
8303 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
8304 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
8305 }
8306}
fba73eb1
DE
8307
8308\f
8309/* Expand a block clear operation, and return 1 if successful. Return 0
8310 if we should let the compiler generate normal code.
8311
8312 operands[0] is the destination
8313 operands[1] is the length
8314 operands[2] is the alignment */
8315
8316int
8317expand_block_clear (rtx operands[])
8318{
8319 rtx orig_dest = operands[0];
8320 rtx bytes_rtx = operands[1];
8321 rtx align_rtx = operands[2];
8322 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
8323 int align;
8324 int bytes;
8325 int offset;
8326 int clear_bytes;
8327
8328 /* If this is not a fixed size move, just call memcpy */
8329 if (! constp)
8330 return 0;
8331
8332 /* If this is not a fixed size alignment, abort */
8333 if (GET_CODE (align_rtx) != CONST_INT)
8334 abort ();
8335 align = INTVAL (align_rtx) * BITS_PER_UNIT;
8336
8337 /* Anything to clear? */
8338 bytes = INTVAL (bytes_rtx);
8339 if (bytes <= 0)
8340 return 1;
8341
8342 if (bytes > (TARGET_POWERPC64 && align >= 32 ? 64 : 32))
8343 return 0;
8344
8345 if (optimize_size && bytes > 16)
8346 return 0;
8347
8348 for (offset = 0; bytes > 0; offset += clear_bytes, bytes -= clear_bytes)
8349 {
8350 rtx (*mov) (rtx, rtx);
8351 enum machine_mode mode = BLKmode;
8352 rtx dest;
f676971a 8353
fba73eb1
DE
8354 if (bytes >= 8 && TARGET_POWERPC64
8355 /* 64-bit loads and stores require word-aligned
8356 displacements. */
8357 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
8358 {
8359 clear_bytes = 8;
8360 mode = DImode;
8361 mov = gen_movdi;
8362 }
8363 else if (bytes >= 4 && !STRICT_ALIGNMENT)
8364 { /* move 4 bytes */
8365 clear_bytes = 4;
8366 mode = SImode;
8367 mov = gen_movsi;
8368 }
8369 else if (bytes == 2 && !STRICT_ALIGNMENT)
8370 { /* move 2 bytes */
8371 clear_bytes = 2;
8372 mode = HImode;
8373 mov = gen_movhi;
8374 }
8375 else /* move 1 byte at a time */
8376 {
8377 clear_bytes = 1;
8378 mode = QImode;
8379 mov = gen_movqi;
8380 }
f676971a 8381
fba73eb1 8382 dest = adjust_address (orig_dest, mode, offset);
f676971a 8383
fba73eb1
DE
8384 emit_insn ((*mov) (dest, const0_rtx));
8385 }
8386
8387 return 1;
8388}
8389
35aff10b 8390\f
7e69e155
MM
8391/* Expand a block move operation, and return 1 if successful. Return 0
8392 if we should let the compiler generate normal code.
8393
8394 operands[0] is the destination
8395 operands[1] is the source
8396 operands[2] is the length
8397 operands[3] is the alignment */
8398
3933e0e1
MM
8399#define MAX_MOVE_REG 4
8400
7e69e155 8401int
a2369ed3 8402expand_block_move (rtx operands[])
7e69e155 8403{
b6c9286a
MM
8404 rtx orig_dest = operands[0];
8405 rtx orig_src = operands[1];
7e69e155 8406 rtx bytes_rtx = operands[2];
7e69e155 8407 rtx align_rtx = operands[3];
3933e0e1 8408 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 8409 int align;
3933e0e1
MM
8410 int bytes;
8411 int offset;
7e69e155 8412 int move_bytes;
cabfd258
GK
8413 rtx stores[MAX_MOVE_REG];
8414 int num_reg = 0;
7e69e155 8415
3933e0e1 8416 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 8417 if (! constp)
3933e0e1
MM
8418 return 0;
8419
5ee95df6
FS
8420 /* If this is not a fixed size alignment, abort */
8421 if (GET_CODE (align_rtx) != CONST_INT)
8422 abort ();
fba73eb1 8423 align = INTVAL (align_rtx) * BITS_PER_UNIT;
5ee95df6 8424
7e69e155 8425 /* Anything to move? */
3933e0e1
MM
8426 bytes = INTVAL (bytes_rtx);
8427 if (bytes <= 0)
7e69e155
MM
8428 return 1;
8429
ea9982a8 8430 /* store_one_arg depends on expand_block_move to handle at least the size of
f676971a 8431 reg_parm_stack_space. */
ea9982a8 8432 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
8433 return 0;
8434
cabfd258 8435 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 8436 {
cabfd258 8437 union {
70128ad9 8438 rtx (*movmemsi) (rtx, rtx, rtx, rtx);
a2369ed3 8439 rtx (*mov) (rtx, rtx);
cabfd258
GK
8440 } gen_func;
8441 enum machine_mode mode = BLKmode;
8442 rtx src, dest;
f676971a 8443
cabfd258
GK
8444 if (TARGET_STRING
8445 && bytes > 24 /* move up to 32 bytes at a time */
8446 && ! fixed_regs[5]
8447 && ! fixed_regs[6]
8448 && ! fixed_regs[7]
8449 && ! fixed_regs[8]
8450 && ! fixed_regs[9]
8451 && ! fixed_regs[10]
8452 && ! fixed_regs[11]
8453 && ! fixed_regs[12])
7e69e155 8454 {
cabfd258 8455 move_bytes = (bytes > 32) ? 32 : bytes;
70128ad9 8456 gen_func.movmemsi = gen_movmemsi_8reg;
cabfd258
GK
8457 }
8458 else if (TARGET_STRING
8459 && bytes > 16 /* move up to 24 bytes at a time */
8460 && ! fixed_regs[5]
8461 && ! fixed_regs[6]
8462 && ! fixed_regs[7]
8463 && ! fixed_regs[8]
8464 && ! fixed_regs[9]
8465 && ! fixed_regs[10])
8466 {
8467 move_bytes = (bytes > 24) ? 24 : bytes;
70128ad9 8468 gen_func.movmemsi = gen_movmemsi_6reg;
cabfd258
GK
8469 }
8470 else if (TARGET_STRING
8471 && bytes > 8 /* move up to 16 bytes at a time */
8472 && ! fixed_regs[5]
8473 && ! fixed_regs[6]
8474 && ! fixed_regs[7]
8475 && ! fixed_regs[8])
8476 {
8477 move_bytes = (bytes > 16) ? 16 : bytes;
70128ad9 8478 gen_func.movmemsi = gen_movmemsi_4reg;
cabfd258
GK
8479 }
8480 else if (bytes >= 8 && TARGET_POWERPC64
8481 /* 64-bit loads and stores require word-aligned
8482 displacements. */
fba73eb1 8483 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
cabfd258
GK
8484 {
8485 move_bytes = 8;
8486 mode = DImode;
8487 gen_func.mov = gen_movdi;
8488 }
8489 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
8490 { /* move up to 8 bytes at a time */
8491 move_bytes = (bytes > 8) ? 8 : bytes;
70128ad9 8492 gen_func.movmemsi = gen_movmemsi_2reg;
cabfd258 8493 }
fba73eb1 8494 else if (bytes >= 4 && !STRICT_ALIGNMENT)
cabfd258
GK
8495 { /* move 4 bytes */
8496 move_bytes = 4;
8497 mode = SImode;
8498 gen_func.mov = gen_movsi;
8499 }
fba73eb1 8500 else if (bytes == 2 && !STRICT_ALIGNMENT)
cabfd258
GK
8501 { /* move 2 bytes */
8502 move_bytes = 2;
8503 mode = HImode;
8504 gen_func.mov = gen_movhi;
8505 }
8506 else if (TARGET_STRING && bytes > 1)
8507 { /* move up to 4 bytes at a time */
8508 move_bytes = (bytes > 4) ? 4 : bytes;
70128ad9 8509 gen_func.movmemsi = gen_movmemsi_1reg;
cabfd258
GK
8510 }
8511 else /* move 1 byte at a time */
8512 {
8513 move_bytes = 1;
8514 mode = QImode;
8515 gen_func.mov = gen_movqi;
8516 }
f676971a 8517
cabfd258
GK
8518 src = adjust_address (orig_src, mode, offset);
8519 dest = adjust_address (orig_dest, mode, offset);
f676971a
EC
8520
8521 if (mode != BLKmode)
cabfd258
GK
8522 {
8523 rtx tmp_reg = gen_reg_rtx (mode);
f676971a 8524
cabfd258
GK
8525 emit_insn ((*gen_func.mov) (tmp_reg, src));
8526 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 8527 }
3933e0e1 8528
cabfd258
GK
8529 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
8530 {
8531 int i;
8532 for (i = 0; i < num_reg; i++)
8533 emit_insn (stores[i]);
8534 num_reg = 0;
8535 }
35aff10b 8536
cabfd258 8537 if (mode == BLKmode)
7e69e155 8538 {
70128ad9 8539 /* Move the address into scratch registers. The movmemsi
cabfd258
GK
8540 patterns require zero offset. */
8541 if (!REG_P (XEXP (src, 0)))
b6c9286a 8542 {
cabfd258
GK
8543 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
8544 src = replace_equiv_address (src, src_reg);
b6c9286a 8545 }
cabfd258 8546 set_mem_size (src, GEN_INT (move_bytes));
f676971a 8547
cabfd258 8548 if (!REG_P (XEXP (dest, 0)))
3933e0e1 8549 {
cabfd258
GK
8550 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
8551 dest = replace_equiv_address (dest, dest_reg);
7e69e155 8552 }
cabfd258 8553 set_mem_size (dest, GEN_INT (move_bytes));
f676971a 8554
70128ad9 8555 emit_insn ((*gen_func.movmemsi) (dest, src,
cabfd258
GK
8556 GEN_INT (move_bytes & 31),
8557 align_rtx));
7e69e155 8558 }
7e69e155
MM
8559 }
8560
8561 return 1;
8562}
8563
d62294f5
FJ
8564\f
8565/* Return 1 if OP is suitable for a save_world call in prologue. It is
8566 known to be a PARALLEL. */
8567int
8568save_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8569{
8570 int index;
8571 int i;
8572 rtx elt;
8573 int count = XVECLEN (op, 0);
8574
8575 if (count != 55)
8576 return 0;
8577
8578 index = 0;
8579 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8580 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8581 return 0;
8582
8583 for (i=1; i <= 18; i++)
8584 {
8585 elt = XVECEXP (op, 0, index++);
8586 if (GET_CODE (elt) != SET
8587 || GET_CODE (SET_DEST (elt)) != MEM
8588 || ! memory_operand (SET_DEST (elt), DFmode)
8589 || GET_CODE (SET_SRC (elt)) != REG
8590 || GET_MODE (SET_SRC (elt)) != DFmode)
8591 return 0;
8592 }
8593
8594 for (i=1; i <= 12; i++)
8595 {
8596 elt = XVECEXP (op, 0, index++);
8597 if (GET_CODE (elt) != SET
8598 || GET_CODE (SET_DEST (elt)) != MEM
8599 || GET_CODE (SET_SRC (elt)) != REG
8600 || GET_MODE (SET_SRC (elt)) != V4SImode)
8601 return 0;
8602 }
8603
8604 for (i=1; i <= 19; i++)
8605 {
8606 elt = XVECEXP (op, 0, index++);
8607 if (GET_CODE (elt) != SET
8608 || GET_CODE (SET_DEST (elt)) != MEM
8609 || ! memory_operand (SET_DEST (elt), Pmode)
8610 || GET_CODE (SET_SRC (elt)) != REG
8611 || GET_MODE (SET_SRC (elt)) != Pmode)
8612 return 0;
8613 }
8614
8615 elt = XVECEXP (op, 0, index++);
8616 if (GET_CODE (elt) != SET
8617 || GET_CODE (SET_DEST (elt)) != MEM
8618 || ! memory_operand (SET_DEST (elt), Pmode)
8619 || GET_CODE (SET_SRC (elt)) != REG
8620 || REGNO (SET_SRC (elt)) != CR2_REGNO
8621 || GET_MODE (SET_SRC (elt)) != Pmode)
8622 return 0;
8623
8624 if (GET_CODE (XVECEXP (op, 0, index++)) != USE
8625 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8626 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8627 return 0;
8628 return 1;
8629}
8630
8631/* Return 1 if OP is suitable for a save_world call in prologue. It is
8632 known to be a PARALLEL. */
8633int
8634restore_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8635{
8636 int index;
8637 int i;
8638 rtx elt;
8639 int count = XVECLEN (op, 0);
8640
8641 if (count != 59)
8642 return 0;
8643
8644 index = 0;
8645 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
8646 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8647 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8648 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8649 return 0;
8650
8651 elt = XVECEXP (op, 0, index++);
8652 if (GET_CODE (elt) != SET
8653 || GET_CODE (SET_SRC (elt)) != MEM
8654 || ! memory_operand (SET_SRC (elt), Pmode)
8655 || GET_CODE (SET_DEST (elt)) != REG
8656 || REGNO (SET_DEST (elt)) != CR2_REGNO
8657 || GET_MODE (SET_DEST (elt)) != Pmode)
8658 return 0;
8659
8660 for (i=1; i <= 19; i++)
8661 {
8662 elt = XVECEXP (op, 0, index++);
8663 if (GET_CODE (elt) != SET
8664 || GET_CODE (SET_SRC (elt)) != MEM
8665 || ! memory_operand (SET_SRC (elt), Pmode)
8666 || GET_CODE (SET_DEST (elt)) != REG
8667 || GET_MODE (SET_DEST (elt)) != Pmode)
8668 return 0;
8669 }
8670
8671 for (i=1; i <= 12; i++)
8672 {
8673 elt = XVECEXP (op, 0, index++);
8674 if (GET_CODE (elt) != SET
8675 || GET_CODE (SET_SRC (elt)) != MEM
8676 || GET_CODE (SET_DEST (elt)) != REG
8677 || GET_MODE (SET_DEST (elt)) != V4SImode)
8678 return 0;
8679 }
8680
8681 for (i=1; i <= 18; i++)
8682 {
8683 elt = XVECEXP (op, 0, index++);
8684 if (GET_CODE (elt) != SET
8685 || GET_CODE (SET_SRC (elt)) != MEM
8686 || ! memory_operand (SET_SRC (elt), DFmode)
8687 || GET_CODE (SET_DEST (elt)) != REG
8688 || GET_MODE (SET_DEST (elt)) != DFmode)
8689 return 0;
8690 }
8691
8692 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8693 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8694 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8695 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8696 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8697 return 0;
8698 return 1;
8699}
8700
9878760c
RK
8701\f
8702/* Return 1 if OP is a load multiple operation. It is known to be a
8703 PARALLEL and the first section will be tested. */
8704
8705int
a2369ed3 8706load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8707{
8708 int count = XVECLEN (op, 0);
e2c953b6 8709 unsigned int dest_regno;
9878760c
RK
8710 rtx src_addr;
8711 int i;
8712
8713 /* Perform a quick check so we don't blow up below. */
8714 if (count <= 1
8715 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8716 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8717 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8718 return 0;
8719
8720 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8721 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8722
8723 for (i = 1; i < count; i++)
8724 {
8725 rtx elt = XVECEXP (op, 0, i);
8726
8727 if (GET_CODE (elt) != SET
8728 || GET_CODE (SET_DEST (elt)) != REG
8729 || GET_MODE (SET_DEST (elt)) != SImode
8730 || REGNO (SET_DEST (elt)) != dest_regno + i
8731 || GET_CODE (SET_SRC (elt)) != MEM
8732 || GET_MODE (SET_SRC (elt)) != SImode
8733 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
8734 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
8735 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
8736 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
8737 return 0;
8738 }
8739
8740 return 1;
8741}
8742
8743/* Similar, but tests for store multiple. Here, the second vector element
8744 is a CLOBBER. It will be tested later. */
8745
8746int
a2369ed3 8747store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8748{
8749 int count = XVECLEN (op, 0) - 1;
e2c953b6 8750 unsigned int src_regno;
9878760c
RK
8751 rtx dest_addr;
8752 int i;
8753
8754 /* Perform a quick check so we don't blow up below. */
8755 if (count <= 1
8756 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8757 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8758 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8759 return 0;
8760
8761 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8762 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8763
8764 for (i = 1; i < count; i++)
8765 {
8766 rtx elt = XVECEXP (op, 0, i + 1);
8767
8768 if (GET_CODE (elt) != SET
8769 || GET_CODE (SET_SRC (elt)) != REG
8770 || GET_MODE (SET_SRC (elt)) != SImode
8771 || REGNO (SET_SRC (elt)) != src_regno + i
8772 || GET_CODE (SET_DEST (elt)) != MEM
8773 || GET_MODE (SET_DEST (elt)) != SImode
8774 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
8775 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
8776 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
8777 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
8778 return 0;
8779 }
8780
8781 return 1;
8782}
9ebbca7d 8783
9caa3eb2
DE
8784/* Return a string to perform a load_multiple operation.
8785 operands[0] is the vector.
8786 operands[1] is the source address.
8787 operands[2] is the first destination register. */
8788
8789const char *
a2369ed3 8790rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
8791{
8792 /* We have to handle the case where the pseudo used to contain the address
8793 is assigned to one of the output registers. */
8794 int i, j;
8795 int words = XVECLEN (operands[0], 0);
8796 rtx xop[10];
8797
8798 if (XVECLEN (operands[0], 0) == 1)
8799 return "{l|lwz} %2,0(%1)";
8800
8801 for (i = 0; i < words; i++)
8802 if (refers_to_regno_p (REGNO (operands[2]) + i,
8803 REGNO (operands[2]) + i + 1, operands[1], 0))
8804 {
8805 if (i == words-1)
8806 {
8807 xop[0] = GEN_INT (4 * (words-1));
8808 xop[1] = operands[1];
8809 xop[2] = operands[2];
8810 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
8811 return "";
8812 }
8813 else if (i == 0)
8814 {
8815 xop[0] = GEN_INT (4 * (words-1));
8816 xop[1] = operands[1];
8817 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
8818 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);
8819 return "";
8820 }
8821 else
8822 {
8823 for (j = 0; j < words; j++)
8824 if (j != i)
8825 {
8826 xop[0] = GEN_INT (j * 4);
8827 xop[1] = operands[1];
8828 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
8829 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
8830 }
8831 xop[0] = GEN_INT (i * 4);
8832 xop[1] = operands[1];
8833 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
8834 return "";
8835 }
8836 }
8837
8838 return "{lsi|lswi} %2,%1,%N0";
8839}
8840
00b960c7
AH
8841/* Return 1 for a parallel vrsave operation. */
8842
8843int
a2369ed3 8844vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
8845{
8846 int count = XVECLEN (op, 0);
8847 unsigned int dest_regno, src_regno;
8848 int i;
8849
8850 if (count <= 1
8851 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8852 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 8853 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
8854 return 0;
8855
8856 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8857 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8858
8859 if (dest_regno != VRSAVE_REGNO
8860 && src_regno != VRSAVE_REGNO)
8861 return 0;
8862
8863 for (i = 1; i < count; i++)
8864 {
8865 rtx elt = XVECEXP (op, 0, i);
8866
9aa86737
AH
8867 if (GET_CODE (elt) != CLOBBER
8868 && GET_CODE (elt) != SET)
00b960c7
AH
8869 return 0;
8870 }
8871
8872 return 1;
8873}
8874
2c4a9cff
DE
8875/* Return 1 for an PARALLEL suitable for mfcr. */
8876
8877int
a2369ed3 8878mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
8879{
8880 int count = XVECLEN (op, 0);
8881 int i;
8882
8883 /* Perform a quick check so we don't blow up below. */
8884 if (count < 1
8885 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8886 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8887 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
8888 return 0;
8889
8890 for (i = 0; i < count; i++)
8891 {
8892 rtx exp = XVECEXP (op, 0, i);
8893 rtx unspec;
8894 int maskval;
8895 rtx src_reg;
8896
8897 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
8898
8899 if (GET_CODE (src_reg) != REG
8900 || GET_MODE (src_reg) != CCmode
8901 || ! CR_REGNO_P (REGNO (src_reg)))
8902 return 0;
8903
8904 if (GET_CODE (exp) != SET
8905 || GET_CODE (SET_DEST (exp)) != REG
8906 || GET_MODE (SET_DEST (exp)) != SImode
8907 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
8908 return 0;
8909 unspec = SET_SRC (exp);
8910 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
8911
8912 if (GET_CODE (unspec) != UNSPEC
8913 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
8914 || XVECLEN (unspec, 0) != 2
8915 || XVECEXP (unspec, 0, 0) != src_reg
8916 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8917 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8918 return 0;
8919 }
8920 return 1;
8921}
8922
a4f6c312 8923/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
8924
8925int
a2369ed3 8926mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8927{
8928 int count = XVECLEN (op, 0);
8929 int i;
9ebbca7d
GK
8930 rtx src_reg;
8931
8932 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
8933 if (count < 1
8934 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8935 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8936 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 8937 return 0;
e35b9579 8938 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
f676971a 8939
9ebbca7d
GK
8940 if (GET_CODE (src_reg) != REG
8941 || GET_MODE (src_reg) != SImode
8942 || ! INT_REGNO_P (REGNO (src_reg)))
8943 return 0;
8944
e35b9579 8945 for (i = 0; i < count; i++)
9ebbca7d
GK
8946 {
8947 rtx exp = XVECEXP (op, 0, i);
8948 rtx unspec;
8949 int maskval;
f676971a 8950
9ebbca7d
GK
8951 if (GET_CODE (exp) != SET
8952 || GET_CODE (SET_DEST (exp)) != REG
8953 || GET_MODE (SET_DEST (exp)) != CCmode
8954 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
8955 return 0;
8956 unspec = SET_SRC (exp);
8957 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
f676971a 8958
9ebbca7d 8959 if (GET_CODE (unspec) != UNSPEC
615158e2 8960 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
8961 || XVECLEN (unspec, 0) != 2
8962 || XVECEXP (unspec, 0, 0) != src_reg
8963 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8964 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8965 return 0;
8966 }
e35b9579 8967 return 1;
9ebbca7d
GK
8968}
8969
a4f6c312 8970/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
8971
8972int
a2369ed3 8973lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8974{
8975 int count = XVECLEN (op, 0);
e2c953b6 8976 unsigned int dest_regno;
9ebbca7d 8977 rtx src_addr;
e2c953b6 8978 unsigned int base_regno;
9ebbca7d
GK
8979 HOST_WIDE_INT offset;
8980 int i;
8981
8982 /* Perform a quick check so we don't blow up below. */
8983 if (count <= 1
8984 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8985 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8986 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8987 return 0;
8988
8989 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8990 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8991
8992 if (dest_regno > 31
e2c953b6 8993 || count != 32 - (int) dest_regno)
9ebbca7d
GK
8994 return 0;
8995
4d588c14 8996 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
8997 {
8998 offset = 0;
8999 base_regno = REGNO (src_addr);
9000 if (base_regno == 0)
9001 return 0;
9002 }
76d2b81d 9003 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
9004 {
9005 offset = INTVAL (XEXP (src_addr, 1));
9006 base_regno = REGNO (XEXP (src_addr, 0));
9007 }
9008 else
9009 return 0;
9010
9011 for (i = 0; i < count; i++)
9012 {
9013 rtx elt = XVECEXP (op, 0, i);
9014 rtx newaddr;
9015 rtx addr_reg;
9016 HOST_WIDE_INT newoffset;
9017
9018 if (GET_CODE (elt) != SET
9019 || GET_CODE (SET_DEST (elt)) != REG
9020 || GET_MODE (SET_DEST (elt)) != SImode
9021 || REGNO (SET_DEST (elt)) != dest_regno + i
9022 || GET_CODE (SET_SRC (elt)) != MEM
9023 || GET_MODE (SET_SRC (elt)) != SImode)
9024 return 0;
9025 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 9026 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9027 {
9028 newoffset = 0;
9029 addr_reg = newaddr;
9030 }
76d2b81d 9031 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9032 {
9033 addr_reg = XEXP (newaddr, 0);
9034 newoffset = INTVAL (XEXP (newaddr, 1));
9035 }
9036 else
9037 return 0;
9038 if (REGNO (addr_reg) != base_regno
9039 || newoffset != offset + 4 * i)
9040 return 0;
9041 }
9042
9043 return 1;
9044}
9045
a4f6c312 9046/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
9047
9048int
a2369ed3 9049stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9050{
9051 int count = XVECLEN (op, 0);
e2c953b6 9052 unsigned int src_regno;
9ebbca7d 9053 rtx dest_addr;
e2c953b6 9054 unsigned int base_regno;
9ebbca7d
GK
9055 HOST_WIDE_INT offset;
9056 int i;
9057
9058 /* Perform a quick check so we don't blow up below. */
9059 if (count <= 1
9060 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9061 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
9062 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
9063 return 0;
9064
9065 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9066 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
9067
9068 if (src_regno > 31
e2c953b6 9069 || count != 32 - (int) src_regno)
9ebbca7d
GK
9070 return 0;
9071
4d588c14 9072 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
9073 {
9074 offset = 0;
9075 base_regno = REGNO (dest_addr);
9076 if (base_regno == 0)
9077 return 0;
9078 }
76d2b81d 9079 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
9080 {
9081 offset = INTVAL (XEXP (dest_addr, 1));
9082 base_regno = REGNO (XEXP (dest_addr, 0));
9083 }
9084 else
9085 return 0;
9086
9087 for (i = 0; i < count; i++)
9088 {
9089 rtx elt = XVECEXP (op, 0, i);
9090 rtx newaddr;
9091 rtx addr_reg;
9092 HOST_WIDE_INT newoffset;
9093
9094 if (GET_CODE (elt) != SET
9095 || GET_CODE (SET_SRC (elt)) != REG
9096 || GET_MODE (SET_SRC (elt)) != SImode
9097 || REGNO (SET_SRC (elt)) != src_regno + i
9098 || GET_CODE (SET_DEST (elt)) != MEM
9099 || GET_MODE (SET_DEST (elt)) != SImode)
9100 return 0;
9101 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 9102 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9103 {
9104 newoffset = 0;
9105 addr_reg = newaddr;
9106 }
76d2b81d 9107 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9108 {
9109 addr_reg = XEXP (newaddr, 0);
9110 newoffset = INTVAL (XEXP (newaddr, 1));
9111 }
9112 else
9113 return 0;
9114 if (REGNO (addr_reg) != base_regno
9115 || newoffset != offset + 4 * i)
9116 return 0;
9117 }
9118
9119 return 1;
9120}
9878760c 9121\f
a4f6c312
SS
9122/* A validation routine: say whether CODE, a condition code, and MODE
9123 match. The other alternatives either don't make sense or should
9124 never be generated. */
39a10a29 9125
39a10a29 9126static void
a2369ed3 9127validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 9128{
ec8e098d
PB
9129 if ((GET_RTX_CLASS (code) != RTX_COMPARE
9130 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
9131 || GET_MODE_CLASS (mode) != MODE_CC)
9132 abort ();
9133
9134 /* These don't make sense. */
9135 if ((code == GT || code == LT || code == GE || code == LE)
9136 && mode == CCUNSmode)
9137 abort ();
9138
9139 if ((code == GTU || code == LTU || code == GEU || code == LEU)
9140 && mode != CCUNSmode)
9141 abort ();
9142
9143 if (mode != CCFPmode
9144 && (code == ORDERED || code == UNORDERED
9145 || code == UNEQ || code == LTGT
9146 || code == UNGT || code == UNLT
9147 || code == UNGE || code == UNLE))
a4f6c312 9148 abort ();
f676971a
EC
9149
9150 /* These should never be generated except for
bc9ec0e0 9151 flag_finite_math_only. */
39a10a29 9152 if (mode == CCFPmode
ad72b533 9153 && ! flag_finite_math_only
39a10a29
GK
9154 && (code == LE || code == GE
9155 || code == UNEQ || code == LTGT
9156 || code == UNGT || code == UNLT))
9157 abort ();
9158
9159 /* These are invalid; the information is not there. */
f676971a 9160 if (mode == CCEQmode
39a10a29
GK
9161 && code != EQ && code != NE)
9162 abort ();
9163}
9164
9878760c
RK
9165/* Return 1 if OP is a comparison operation that is valid for a branch insn.
9166 We only check the opcode against the mode of the CC value here. */
9167
9168int
a2369ed3 9169branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
9170{
9171 enum rtx_code code = GET_CODE (op);
9172 enum machine_mode cc_mode;
9173
ec8e098d 9174 if (!COMPARISON_P (op))
9878760c
RK
9175 return 0;
9176
9177 cc_mode = GET_MODE (XEXP (op, 0));
9178 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
9179 return 0;
9180
39a10a29 9181 validate_condition_mode (code, cc_mode);
9878760c 9182
39a10a29
GK
9183 return 1;
9184}
9185
9186/* Return 1 if OP is a comparison operation that is valid for a branch
9187 insn and which is true if the corresponding bit in the CC register
9188 is set. */
9189
9190int
a2369ed3 9191branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
9192{
9193 enum rtx_code code;
9194
8daf2e65 9195 if (! branch_comparison_operator (op, mode))
9878760c
RK
9196 return 0;
9197
39a10a29
GK
9198 code = GET_CODE (op);
9199 return (code == EQ || code == LT || code == GT
9200 || code == LTU || code == GTU
9201 || code == UNORDERED);
9878760c
RK
9202}
9203
b7053a3f
GK
9204/* Return 1 if OP is a comparison operation that is valid for an scc
9205 insn: it must be a positive comparison. */
9878760c
RK
9206
9207int
a2369ed3 9208scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 9209{
b7053a3f 9210 return branch_positive_comparison_operator (op, mode);
9878760c 9211}
e0cd0770
JC
9212
9213int
a2369ed3 9214trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
9215{
9216 if (mode != VOIDmode && mode != GET_MODE (op))
9217 return 0;
ec8e098d 9218 return COMPARISON_P (op);
e0cd0770 9219}
dfbdccdb
GK
9220
9221int
a2369ed3 9222boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
9223{
9224 enum rtx_code code = GET_CODE (op);
9225 return (code == AND || code == IOR || code == XOR);
9226}
1d328b19
GK
9227
9228int
a2369ed3 9229boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
9230{
9231 enum rtx_code code = GET_CODE (op);
9232 return (code == IOR || code == XOR);
9233}
50a0b056
GK
9234
9235int
a2369ed3 9236min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
9237{
9238 enum rtx_code code = GET_CODE (op);
9239 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
9240}
9878760c
RK
9241\f
9242/* Return 1 if ANDOP is a mask that has no bits on that are not in the
9243 mask required to convert the result of a rotate insn into a shift
b1765bde 9244 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
9245
9246int
a2369ed3 9247includes_lshift_p (rtx shiftop, rtx andop)
9878760c 9248{
e2c953b6
DE
9249 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9250
9251 shift_mask <<= INTVAL (shiftop);
9878760c 9252
b1765bde 9253 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
9254}
9255
9256/* Similar, but for right shift. */
9257
9258int
a2369ed3 9259includes_rshift_p (rtx shiftop, rtx andop)
9878760c 9260{
a7653a2c 9261 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
9262
9263 shift_mask >>= INTVAL (shiftop);
9264
b1765bde 9265 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
9266}
9267
c5059423
AM
9268/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
9269 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 9270 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
9271
9272int
a2369ed3 9273includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 9274{
c5059423
AM
9275 if (GET_CODE (andop) == CONST_INT)
9276 {
02071907 9277 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 9278
c5059423 9279 c = INTVAL (andop);
02071907 9280 if (c == 0 || c == ~0)
c5059423 9281 return 0;
e2c953b6 9282
02071907 9283 shift_mask = ~0;
c5059423
AM
9284 shift_mask <<= INTVAL (shiftop);
9285
b6d08ca1 9286 /* Find the least significant one bit. */
c5059423
AM
9287 lsb = c & -c;
9288
9289 /* It must coincide with the LSB of the shift mask. */
9290 if (-lsb != shift_mask)
9291 return 0;
e2c953b6 9292
c5059423
AM
9293 /* Invert to look for the next transition (if any). */
9294 c = ~c;
9295
9296 /* Remove the low group of ones (originally low group of zeros). */
9297 c &= -lsb;
9298
9299 /* Again find the lsb, and check we have all 1's above. */
9300 lsb = c & -c;
9301 return c == -lsb;
9302 }
9303 else if (GET_CODE (andop) == CONST_DOUBLE
9304 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9305 {
02071907
AM
9306 HOST_WIDE_INT low, high, lsb;
9307 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
9308
9309 low = CONST_DOUBLE_LOW (andop);
9310 if (HOST_BITS_PER_WIDE_INT < 64)
9311 high = CONST_DOUBLE_HIGH (andop);
9312
9313 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 9314 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
9315 return 0;
9316
9317 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9318 {
02071907 9319 shift_mask_high = ~0;
c5059423
AM
9320 if (INTVAL (shiftop) > 32)
9321 shift_mask_high <<= INTVAL (shiftop) - 32;
9322
9323 lsb = high & -high;
9324
9325 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
9326 return 0;
9327
9328 high = ~high;
9329 high &= -lsb;
9330
9331 lsb = high & -high;
9332 return high == -lsb;
9333 }
9334
02071907 9335 shift_mask_low = ~0;
c5059423
AM
9336 shift_mask_low <<= INTVAL (shiftop);
9337
9338 lsb = low & -low;
9339
9340 if (-lsb != shift_mask_low)
9341 return 0;
9342
9343 if (HOST_BITS_PER_WIDE_INT < 64)
9344 high = ~high;
9345 low = ~low;
9346 low &= -lsb;
9347
9348 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9349 {
9350 lsb = high & -high;
9351 return high == -lsb;
9352 }
9353
9354 lsb = low & -low;
9355 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
9356 }
9357 else
9358 return 0;
9359}
e2c953b6 9360
c5059423
AM
9361/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
9362 to perform a left shift. It must have SHIFTOP or more least
c1207243 9363 significant 0's, with the remainder of the word 1's. */
e2c953b6 9364
c5059423 9365int
a2369ed3 9366includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 9367{
e2c953b6 9368 if (GET_CODE (andop) == CONST_INT)
c5059423 9369 {
02071907 9370 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 9371
02071907 9372 shift_mask = ~0;
c5059423
AM
9373 shift_mask <<= INTVAL (shiftop);
9374 c = INTVAL (andop);
9375
c1207243 9376 /* Find the least significant one bit. */
c5059423
AM
9377 lsb = c & -c;
9378
9379 /* It must be covered by the shift mask.
a4f6c312 9380 This test also rejects c == 0. */
c5059423
AM
9381 if ((lsb & shift_mask) == 0)
9382 return 0;
9383
9384 /* Check we have all 1's above the transition, and reject all 1's. */
9385 return c == -lsb && lsb != 1;
9386 }
9387 else if (GET_CODE (andop) == CONST_DOUBLE
9388 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9389 {
02071907 9390 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
9391
9392 low = CONST_DOUBLE_LOW (andop);
9393
9394 if (HOST_BITS_PER_WIDE_INT < 64)
9395 {
02071907 9396 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
9397
9398 high = CONST_DOUBLE_HIGH (andop);
9399
9400 if (low == 0)
9401 {
02071907 9402 shift_mask_high = ~0;
c5059423
AM
9403 if (INTVAL (shiftop) > 32)
9404 shift_mask_high <<= INTVAL (shiftop) - 32;
9405
9406 lsb = high & -high;
9407
9408 if ((lsb & shift_mask_high) == 0)
9409 return 0;
9410
9411 return high == -lsb;
9412 }
9413 if (high != ~0)
9414 return 0;
9415 }
9416
02071907 9417 shift_mask_low = ~0;
c5059423
AM
9418 shift_mask_low <<= INTVAL (shiftop);
9419
9420 lsb = low & -low;
9421
9422 if ((lsb & shift_mask_low) == 0)
9423 return 0;
9424
9425 return low == -lsb && lsb != 1;
9426 }
e2c953b6 9427 else
c5059423 9428 return 0;
9878760c 9429}
35068b43 9430
11ac38b2
DE
9431/* Return 1 if operands will generate a valid arguments to rlwimi
9432instruction for insert with right shift in 64-bit mode. The mask may
9433not start on the first bit or stop on the last bit because wrap-around
9434effects of instruction do not correspond to semantics of RTL insn. */
9435
9436int
9437insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop)
9438{
9439 if (INTVAL (startop) < 64
9440 && INTVAL (startop) > 32
9441 && (INTVAL (sizeop) + INTVAL (startop) < 64)
9442 && (INTVAL (sizeop) + INTVAL (startop) > 33)
9443 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) < 96)
9444 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) >= 64)
9445 && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop))
9446 return 1;
9447
9448 return 0;
9449}
9450
35068b43 9451/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
90f81f99 9452 for lfq and stfq insns iff the registers are hard registers. */
35068b43
RK
9453
9454int
a2369ed3 9455registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
9456{
9457 /* We might have been passed a SUBREG. */
f676971a 9458 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
35068b43 9459 return 0;
f676971a 9460
90f81f99
AP
9461 /* We might have been passed non floating point registers. */
9462 if (!FP_REGNO_P (REGNO (reg1))
9463 || !FP_REGNO_P (REGNO (reg2)))
9464 return 0;
35068b43
RK
9465
9466 return (REGNO (reg1) == REGNO (reg2) - 1);
9467}
9468
a4f6c312
SS
9469/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
9470 addr1 and addr2 must be in consecutive memory locations
9471 (addr2 == addr1 + 8). */
35068b43
RK
9472
9473int
90f81f99 9474mems_ok_for_quad_peep (rtx mem1, rtx mem2)
35068b43 9475{
90f81f99 9476 rtx addr1, addr2;
e2c953b6 9477 unsigned int reg1;
35068b43
RK
9478 int offset1;
9479
90f81f99
AP
9480 /* The mems cannot be volatile. */
9481 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
9482 return 0;
f676971a 9483
90f81f99
AP
9484 addr1 = XEXP (mem1, 0);
9485 addr2 = XEXP (mem2, 0);
9486
35068b43
RK
9487 /* Extract an offset (if used) from the first addr. */
9488 if (GET_CODE (addr1) == PLUS)
9489 {
9490 /* If not a REG, return zero. */
9491 if (GET_CODE (XEXP (addr1, 0)) != REG)
9492 return 0;
9493 else
9494 {
9495 reg1 = REGNO (XEXP (addr1, 0));
9496 /* The offset must be constant! */
9497 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
9498 return 0;
9499 offset1 = INTVAL (XEXP (addr1, 1));
9500 }
9501 }
9502 else if (GET_CODE (addr1) != REG)
9503 return 0;
9504 else
9505 {
9506 reg1 = REGNO (addr1);
9507 /* This was a simple (mem (reg)) expression. Offset is 0. */
9508 offset1 = 0;
9509 }
9510
a2369ed3 9511 /* Make sure the second address is a (mem (plus (reg) (const_int)))
f676971a 9512 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
0f6937fe 9513 register as addr1. */
984e25ac 9514 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 9515 return 1;
35068b43
RK
9516 if (GET_CODE (addr2) != PLUS)
9517 return 0;
9518
9519 if (GET_CODE (XEXP (addr2, 0)) != REG
9520 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
9521 return 0;
9522
9523 if (reg1 != REGNO (XEXP (addr2, 0)))
9524 return 0;
9525
9526 /* The offset for the second addr must be 8 more than the first addr. */
9527 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
9528 return 0;
9529
9530 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
9531 instructions. */
9532 return 1;
9533}
9878760c
RK
9534\f
9535/* Return the register class of a scratch register needed to copy IN into
9536 or out of a register in CLASS in MODE. If it can be done directly,
9537 NO_REGS is returned. */
9538
9539enum reg_class
f676971a 9540secondary_reload_class (enum reg_class class,
a9baceb1
GK
9541 enum machine_mode mode ATTRIBUTE_UNUSED,
9542 rtx in)
9878760c 9543{
5accd822 9544 int regno;
9878760c 9545
ab82a49f
AP
9546 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
9547#if TARGET_MACHO
9548 && MACHOPIC_INDIRECT
9549#endif
9550 ))
46fad5b7
DJ
9551 {
9552 /* We cannot copy a symbolic operand directly into anything
9553 other than BASE_REGS for TARGET_ELF. So indicate that a
9554 register from BASE_REGS is needed as an intermediate
9555 register.
f676971a 9556
46fad5b7
DJ
9557 On Darwin, pic addresses require a load from memory, which
9558 needs a base register. */
9559 if (class != BASE_REGS
9560 && (GET_CODE (in) == SYMBOL_REF
9561 || GET_CODE (in) == HIGH
9562 || GET_CODE (in) == LABEL_REF
9563 || GET_CODE (in) == CONST))
9564 return BASE_REGS;
9565 }
e7b7998a 9566
5accd822
DE
9567 if (GET_CODE (in) == REG)
9568 {
9569 regno = REGNO (in);
9570 if (regno >= FIRST_PSEUDO_REGISTER)
9571 {
9572 regno = true_regnum (in);
9573 if (regno >= FIRST_PSEUDO_REGISTER)
9574 regno = -1;
9575 }
9576 }
9577 else if (GET_CODE (in) == SUBREG)
9578 {
9579 regno = true_regnum (in);
9580 if (regno >= FIRST_PSEUDO_REGISTER)
9581 regno = -1;
9582 }
9583 else
9584 regno = -1;
9585
9878760c
RK
9586 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
9587 into anything. */
9588 if (class == GENERAL_REGS || class == BASE_REGS
9589 || (regno >= 0 && INT_REGNO_P (regno)))
9590 return NO_REGS;
9591
9592 /* Constants, memory, and FP registers can go into FP registers. */
9593 if ((regno == -1 || FP_REGNO_P (regno))
9594 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
9595 return NO_REGS;
9596
0ac081f6
AH
9597 /* Memory, and AltiVec registers can go into AltiVec registers. */
9598 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
9599 && class == ALTIVEC_REGS)
9600 return NO_REGS;
9601
9878760c
RK
9602 /* We can copy among the CR registers. */
9603 if ((class == CR_REGS || class == CR0_REGS)
9604 && regno >= 0 && CR_REGNO_P (regno))
9605 return NO_REGS;
9606
9607 /* Otherwise, we need GENERAL_REGS. */
9608 return GENERAL_REGS;
9609}
9610\f
9611/* Given a comparison operation, return the bit number in CCR to test. We
f676971a 9612 know this is a valid comparison.
9878760c
RK
9613
9614 SCC_P is 1 if this is for an scc. That means that %D will have been
9615 used instead of %C, so the bits will be in different places.
9616
b4ac57ab 9617 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
9618
9619int
a2369ed3 9620ccr_bit (rtx op, int scc_p)
9878760c
RK
9621{
9622 enum rtx_code code = GET_CODE (op);
9623 enum machine_mode cc_mode;
9624 int cc_regnum;
9625 int base_bit;
9ebbca7d 9626 rtx reg;
9878760c 9627
ec8e098d 9628 if (!COMPARISON_P (op))
9878760c
RK
9629 return -1;
9630
9ebbca7d
GK
9631 reg = XEXP (op, 0);
9632
9633 if (GET_CODE (reg) != REG
9634 || ! CR_REGNO_P (REGNO (reg)))
9635 abort ();
9636
9637 cc_mode = GET_MODE (reg);
9638 cc_regnum = REGNO (reg);
9639 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 9640
39a10a29 9641 validate_condition_mode (code, cc_mode);
c5defebb 9642
b7053a3f
GK
9643 /* When generating a sCOND operation, only positive conditions are
9644 allowed. */
9645 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
9646 && code != GTU && code != LTU)
9647 abort ();
f676971a 9648
9878760c
RK
9649 switch (code)
9650 {
9651 case NE:
9652 return scc_p ? base_bit + 3 : base_bit + 2;
9653 case EQ:
9654 return base_bit + 2;
1c882ea4 9655 case GT: case GTU: case UNLE:
9878760c 9656 return base_bit + 1;
1c882ea4 9657 case LT: case LTU: case UNGE:
9878760c 9658 return base_bit;
1c882ea4
GK
9659 case ORDERED: case UNORDERED:
9660 return base_bit + 3;
9878760c
RK
9661
9662 case GE: case GEU:
39a10a29 9663 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
9664 unordered position. So test that bit. For integer, this is ! LT
9665 unless this is an scc insn. */
39a10a29 9666 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
9667
9668 case LE: case LEU:
39a10a29 9669 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 9670
9878760c
RK
9671 default:
9672 abort ();
9673 }
9674}
1ff7789b 9675\f
8d30c4ee 9676/* Return the GOT register. */
1ff7789b
MM
9677
9678struct rtx_def *
a2369ed3 9679rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 9680{
a4f6c312
SS
9681 /* The second flow pass currently (June 1999) can't update
9682 regs_ever_live without disturbing other parts of the compiler, so
9683 update it here to make the prolog/epilogue code happy. */
1db02437
FS
9684 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
9685 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 9686
8d30c4ee 9687 current_function_uses_pic_offset_table = 1;
3cb999d8 9688
1ff7789b
MM
9689 return pic_offset_table_rtx;
9690}
a7df97e6 9691\f
e2500fed
GK
9692/* Function to init struct machine_function.
9693 This will be called, via a pointer variable,
9694 from push_function_context. */
a7df97e6 9695
e2500fed 9696static struct machine_function *
863d938c 9697rs6000_init_machine_status (void)
a7df97e6 9698{
e2500fed 9699 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 9700}
9878760c 9701\f
0ba1b2ff
AM
9702/* These macros test for integers and extract the low-order bits. */
9703#define INT_P(X) \
9704((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
9705 && GET_MODE (X) == VOIDmode)
9706
9707#define INT_LOWPART(X) \
9708 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
9709
9710int
a2369ed3 9711extract_MB (rtx op)
0ba1b2ff
AM
9712{
9713 int i;
9714 unsigned long val = INT_LOWPART (op);
9715
9716 /* If the high bit is zero, the value is the first 1 bit we find
9717 from the left. */
9718 if ((val & 0x80000000) == 0)
9719 {
9720 if ((val & 0xffffffff) == 0)
9721 abort ();
9722
9723 i = 1;
9724 while (((val <<= 1) & 0x80000000) == 0)
9725 ++i;
9726 return i;
9727 }
9728
9729 /* If the high bit is set and the low bit is not, or the mask is all
9730 1's, the value is zero. */
9731 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
9732 return 0;
9733
9734 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9735 from the right. */
9736 i = 31;
9737 while (((val >>= 1) & 1) != 0)
9738 --i;
9739
9740 return i;
9741}
9742
9743int
a2369ed3 9744extract_ME (rtx op)
0ba1b2ff
AM
9745{
9746 int i;
9747 unsigned long val = INT_LOWPART (op);
9748
9749 /* If the low bit is zero, the value is the first 1 bit we find from
9750 the right. */
9751 if ((val & 1) == 0)
9752 {
9753 if ((val & 0xffffffff) == 0)
9754 abort ();
9755
9756 i = 30;
9757 while (((val >>= 1) & 1) == 0)
9758 --i;
9759
9760 return i;
9761 }
9762
9763 /* If the low bit is set and the high bit is not, or the mask is all
9764 1's, the value is 31. */
9765 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
9766 return 31;
9767
9768 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9769 from the left. */
9770 i = 0;
9771 while (((val <<= 1) & 0x80000000) != 0)
9772 ++i;
9773
9774 return i;
9775}
9776
c4501e62
JJ
9777/* Locate some local-dynamic symbol still in use by this function
9778 so that we can print its name in some tls_ld pattern. */
9779
9780static const char *
863d938c 9781rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
9782{
9783 rtx insn;
9784
9785 if (cfun->machine->some_ld_name)
9786 return cfun->machine->some_ld_name;
9787
9788 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
9789 if (INSN_P (insn)
9790 && for_each_rtx (&PATTERN (insn),
9791 rs6000_get_some_local_dynamic_name_1, 0))
9792 return cfun->machine->some_ld_name;
9793
9794 abort ();
9795}
9796
9797/* Helper function for rs6000_get_some_local_dynamic_name. */
9798
9799static int
a2369ed3 9800rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
9801{
9802 rtx x = *px;
9803
9804 if (GET_CODE (x) == SYMBOL_REF)
9805 {
9806 const char *str = XSTR (x, 0);
9807 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
9808 {
9809 cfun->machine->some_ld_name = str;
9810 return 1;
9811 }
9812 }
9813
9814 return 0;
9815}
9816
85b776df
AM
9817/* Write out a function code label. */
9818
9819void
9820rs6000_output_function_entry (FILE *file, const char *fname)
9821{
9822 if (fname[0] != '.')
9823 {
9824 switch (DEFAULT_ABI)
9825 {
9826 default:
9827 abort ();
9828
9829 case ABI_AIX:
9830 if (DOT_SYMBOLS)
9831 putc ('.', file);
9832 else
9833 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "L.");
9834 break;
9835
9836 case ABI_V4:
9837 case ABI_DARWIN:
9838 break;
9839 }
9840 }
9841 if (TARGET_AIX)
9842 RS6000_OUTPUT_BASENAME (file, fname);
9843 else
9844 assemble_name (file, fname);
9845}
9846
9878760c
RK
9847/* Print an operand. Recognize special options, documented below. */
9848
38c1f2d7 9849#if TARGET_ELF
d9407988 9850#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 9851#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
9852#else
9853#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 9854#define SMALL_DATA_REG 0
ba5e43aa
MM
9855#endif
9856
9878760c 9857void
a2369ed3 9858print_operand (FILE *file, rtx x, int code)
9878760c
RK
9859{
9860 int i;
a260abc9 9861 HOST_WIDE_INT val;
0ba1b2ff 9862 unsigned HOST_WIDE_INT uval;
9878760c
RK
9863
9864 switch (code)
9865 {
a8b3aeda 9866 case '.':
a85d226b
RK
9867 /* Write out an instruction after the call which may be replaced
9868 with glue code by the loader. This depends on the AIX version. */
9869 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
9870 return;
9871
81eace42
GK
9872 /* %a is output_address. */
9873
9854d9ed
RK
9874 case 'A':
9875 /* If X is a constant integer whose low-order 5 bits are zero,
9876 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 9877 in the AIX assembler where "sri" with a zero shift count
20e26713 9878 writes a trash instruction. */
9854d9ed 9879 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 9880 putc ('l', file);
9854d9ed 9881 else
76229ac8 9882 putc ('r', file);
9854d9ed
RK
9883 return;
9884
9885 case 'b':
e2c953b6
DE
9886 /* If constant, low-order 16 bits of constant, unsigned.
9887 Otherwise, write normally. */
9888 if (INT_P (x))
9889 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
9890 else
9891 print_operand (file, x, 0);
cad12a8d
RK
9892 return;
9893
a260abc9
DE
9894 case 'B':
9895 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
9896 for 64-bit mask direction. */
296b8152 9897 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 9898 return;
a260abc9 9899
81eace42
GK
9900 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
9901 output_operand. */
9902
423c1189
AH
9903 case 'c':
9904 /* X is a CR register. Print the number of the GT bit of the CR. */
9905 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9906 output_operand_lossage ("invalid %%E value");
9907 else
9908 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1);
9909 return;
9910
9911 case 'D':
6b1fedc3 9912 /* Like 'J' but get to the EQ bit. */
423c1189
AH
9913 if (GET_CODE (x) != REG)
9914 abort ();
9915
6b1fedc3
AH
9916 /* Bit 1 is EQ bit. */
9917 i = 4 * (REGNO (x) - CR0_REGNO) + 2;
423c1189
AH
9918
9919 /* If we want bit 31, write a shift count of zero, not 32. */
9920 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9921 return;
9922
9854d9ed 9923 case 'E':
39a10a29 9924 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
9925 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9926 output_operand_lossage ("invalid %%E value");
78fbdbf7 9927 else
39a10a29 9928 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 9929 return;
9854d9ed
RK
9930
9931 case 'f':
9932 /* X is a CR register. Print the shift count needed to move it
9933 to the high-order four bits. */
9934 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9935 output_operand_lossage ("invalid %%f value");
9936 else
9ebbca7d 9937 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9938 return;
9939
9940 case 'F':
9941 /* Similar, but print the count for the rotate in the opposite
9942 direction. */
9943 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9944 output_operand_lossage ("invalid %%F value");
9945 else
9ebbca7d 9946 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9947 return;
9948
9949 case 'G':
9950 /* X is a constant integer. If it is negative, print "m",
43aa4e05 9951 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
9952 if (GET_CODE (x) != CONST_INT)
9953 output_operand_lossage ("invalid %%G value");
9954 else if (INTVAL (x) >= 0)
76229ac8 9955 putc ('z', file);
9854d9ed 9956 else
76229ac8 9957 putc ('m', file);
9854d9ed 9958 return;
e2c953b6 9959
9878760c 9960 case 'h':
a4f6c312
SS
9961 /* If constant, output low-order five bits. Otherwise, write
9962 normally. */
9878760c 9963 if (INT_P (x))
5f59ecb7 9964 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
9965 else
9966 print_operand (file, x, 0);
9967 return;
9968
64305719 9969 case 'H':
a4f6c312
SS
9970 /* If constant, output low-order six bits. Otherwise, write
9971 normally. */
64305719 9972 if (INT_P (x))
5f59ecb7 9973 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
9974 else
9975 print_operand (file, x, 0);
9976 return;
9977
9854d9ed
RK
9978 case 'I':
9979 /* Print `i' if this is a constant, else nothing. */
9878760c 9980 if (INT_P (x))
76229ac8 9981 putc ('i', file);
9878760c
RK
9982 return;
9983
9854d9ed
RK
9984 case 'j':
9985 /* Write the bit number in CCR for jump. */
9986 i = ccr_bit (x, 0);
9987 if (i == -1)
9988 output_operand_lossage ("invalid %%j code");
9878760c 9989 else
9854d9ed 9990 fprintf (file, "%d", i);
9878760c
RK
9991 return;
9992
9854d9ed
RK
9993 case 'J':
9994 /* Similar, but add one for shift count in rlinm for scc and pass
9995 scc flag to `ccr_bit'. */
9996 i = ccr_bit (x, 1);
9997 if (i == -1)
9998 output_operand_lossage ("invalid %%J code");
9999 else
a0466a68
RK
10000 /* If we want bit 31, write a shift count of zero, not 32. */
10001 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
10002 return;
10003
9854d9ed
RK
10004 case 'k':
10005 /* X must be a constant. Write the 1's complement of the
10006 constant. */
9878760c 10007 if (! INT_P (x))
9854d9ed 10008 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
10009 else
10010 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
10011 return;
10012
81eace42 10013 case 'K':
9ebbca7d
GK
10014 /* X must be a symbolic constant on ELF. Write an
10015 expression suitable for an 'addi' that adds in the low 16
10016 bits of the MEM. */
10017 if (GET_CODE (x) != CONST)
10018 {
10019 print_operand_address (file, x);
10020 fputs ("@l", file);
10021 }
10022 else
10023 {
10024 if (GET_CODE (XEXP (x, 0)) != PLUS
10025 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
10026 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
10027 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 10028 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
10029 print_operand_address (file, XEXP (XEXP (x, 0), 0));
10030 fputs ("@l", file);
ed8d2920
MM
10031 /* For GNU as, there must be a non-alphanumeric character
10032 between 'l' and the number. The '-' is added by
10033 print_operand() already. */
10034 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
10035 fputs ("+", file);
9ebbca7d
GK
10036 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
10037 }
81eace42
GK
10038 return;
10039
10040 /* %l is output_asm_label. */
9ebbca7d 10041
9854d9ed
RK
10042 case 'L':
10043 /* Write second word of DImode or DFmode reference. Works on register
10044 or non-indexed memory only. */
10045 if (GET_CODE (x) == REG)
5ebfb2ba 10046 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
10047 else if (GET_CODE (x) == MEM)
10048 {
10049 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 10050 we have already done it, we can just use an offset of word. */
9854d9ed
RK
10051 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10052 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
10053 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
10054 UNITS_PER_WORD));
9854d9ed 10055 else
d7624dc0
RK
10056 output_address (XEXP (adjust_address_nv (x, SImode,
10057 UNITS_PER_WORD),
10058 0));
ed8908e7 10059
ba5e43aa 10060 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10061 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10062 reg_names[SMALL_DATA_REG]);
9854d9ed 10063 }
9878760c 10064 return;
f676971a 10065
9878760c
RK
10066 case 'm':
10067 /* MB value for a mask operand. */
b1765bde 10068 if (! mask_operand (x, SImode))
9878760c
RK
10069 output_operand_lossage ("invalid %%m value");
10070
0ba1b2ff 10071 fprintf (file, "%d", extract_MB (x));
9878760c
RK
10072 return;
10073
10074 case 'M':
10075 /* ME value for a mask operand. */
b1765bde 10076 if (! mask_operand (x, SImode))
a260abc9 10077 output_operand_lossage ("invalid %%M value");
9878760c 10078
0ba1b2ff 10079 fprintf (file, "%d", extract_ME (x));
9878760c
RK
10080 return;
10081
81eace42
GK
10082 /* %n outputs the negative of its operand. */
10083
9878760c
RK
10084 case 'N':
10085 /* Write the number of elements in the vector times 4. */
10086 if (GET_CODE (x) != PARALLEL)
10087 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
10088 else
10089 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
10090 return;
10091
10092 case 'O':
10093 /* Similar, but subtract 1 first. */
10094 if (GET_CODE (x) != PARALLEL)
1427100a 10095 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
10096 else
10097 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
10098 return;
10099
9854d9ed
RK
10100 case 'p':
10101 /* X is a CONST_INT that is a power of two. Output the logarithm. */
10102 if (! INT_P (x)
2bfcf297 10103 || INT_LOWPART (x) < 0
9854d9ed
RK
10104 || (i = exact_log2 (INT_LOWPART (x))) < 0)
10105 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
10106 else
10107 fprintf (file, "%d", i);
9854d9ed
RK
10108 return;
10109
9878760c
RK
10110 case 'P':
10111 /* The operand must be an indirect memory reference. The result
8bb418a3 10112 is the register name. */
9878760c
RK
10113 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
10114 || REGNO (XEXP (x, 0)) >= 32)
10115 output_operand_lossage ("invalid %%P value");
e2c953b6 10116 else
8bb418a3 10117 fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]);
9878760c
RK
10118 return;
10119
dfbdccdb
GK
10120 case 'q':
10121 /* This outputs the logical code corresponding to a boolean
10122 expression. The expression may have one or both operands
39a10a29
GK
10123 negated (if one, only the first one). For condition register
10124 logical operations, it will also treat the negated
10125 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 10126 {
63bc1d05 10127 const char *const *t = 0;
dfbdccdb
GK
10128 const char *s;
10129 enum rtx_code code = GET_CODE (x);
10130 static const char * const tbl[3][3] = {
10131 { "and", "andc", "nor" },
10132 { "or", "orc", "nand" },
10133 { "xor", "eqv", "xor" } };
10134
10135 if (code == AND)
10136 t = tbl[0];
10137 else if (code == IOR)
10138 t = tbl[1];
10139 else if (code == XOR)
10140 t = tbl[2];
10141 else
10142 output_operand_lossage ("invalid %%q value");
10143
10144 if (GET_CODE (XEXP (x, 0)) != NOT)
10145 s = t[0];
10146 else
10147 {
10148 if (GET_CODE (XEXP (x, 1)) == NOT)
10149 s = t[2];
10150 else
10151 s = t[1];
10152 }
f676971a 10153
dfbdccdb
GK
10154 fputs (s, file);
10155 }
10156 return;
10157
2c4a9cff
DE
10158 case 'Q':
10159 if (TARGET_MFCRF)
3b6ce0af 10160 fputc (',', file);
5efb1046 10161 /* FALLTHRU */
2c4a9cff
DE
10162 else
10163 return;
10164
9854d9ed
RK
10165 case 'R':
10166 /* X is a CR register. Print the mask for `mtcrf'. */
10167 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10168 output_operand_lossage ("invalid %%R value");
10169 else
9ebbca7d 10170 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 10171 return;
9854d9ed
RK
10172
10173 case 's':
10174 /* Low 5 bits of 32 - value */
10175 if (! INT_P (x))
10176 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
10177 else
10178 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 10179 return;
9854d9ed 10180
a260abc9 10181 case 'S':
0ba1b2ff 10182 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
10183 CONST_INT 32-bit mask is considered sign-extended so any
10184 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 10185 if (! mask64_operand (x, DImode))
a260abc9
DE
10186 output_operand_lossage ("invalid %%S value");
10187
0ba1b2ff 10188 uval = INT_LOWPART (x);
a260abc9 10189
0ba1b2ff 10190 if (uval & 1) /* Clear Left */
a260abc9 10191 {
f099d360
GK
10192#if HOST_BITS_PER_WIDE_INT > 64
10193 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10194#endif
0ba1b2ff 10195 i = 64;
a260abc9 10196 }
0ba1b2ff 10197 else /* Clear Right */
a260abc9 10198 {
0ba1b2ff 10199 uval = ~uval;
f099d360
GK
10200#if HOST_BITS_PER_WIDE_INT > 64
10201 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10202#endif
0ba1b2ff 10203 i = 63;
a260abc9 10204 }
0ba1b2ff
AM
10205 while (uval != 0)
10206 --i, uval >>= 1;
10207 if (i < 0)
10208 abort ();
10209 fprintf (file, "%d", i);
10210 return;
a260abc9 10211
a3170dc6
AH
10212 case 't':
10213 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
10214 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
10215 abort ();
10216
10217 /* Bit 3 is OV bit. */
10218 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
10219
10220 /* If we want bit 31, write a shift count of zero, not 32. */
10221 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10222 return;
10223
cccf3bdc
DE
10224 case 'T':
10225 /* Print the symbolic name of a branch target register. */
10226 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
10227 && REGNO (x) != COUNT_REGISTER_REGNUM))
10228 output_operand_lossage ("invalid %%T value");
e2c953b6 10229 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
10230 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
10231 else
10232 fputs ("ctr", file);
10233 return;
10234
9854d9ed 10235 case 'u':
802a0058 10236 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
10237 if (! INT_P (x))
10238 output_operand_lossage ("invalid %%u value");
e2c953b6 10239 else
f676971a 10240 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
e2c953b6 10241 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
10242 return;
10243
802a0058
MM
10244 case 'v':
10245 /* High-order 16 bits of constant for use in signed operand. */
10246 if (! INT_P (x))
10247 output_operand_lossage ("invalid %%v value");
e2c953b6 10248 else
134c32f6
DE
10249 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
10250 (INT_LOWPART (x) >> 16) & 0xffff);
10251 return;
802a0058 10252
9854d9ed
RK
10253 case 'U':
10254 /* Print `u' if this has an auto-increment or auto-decrement. */
10255 if (GET_CODE (x) == MEM
10256 && (GET_CODE (XEXP (x, 0)) == PRE_INC
10257 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 10258 putc ('u', file);
9854d9ed 10259 return;
9878760c 10260
e0cd0770
JC
10261 case 'V':
10262 /* Print the trap code for this operand. */
10263 switch (GET_CODE (x))
10264 {
10265 case EQ:
10266 fputs ("eq", file); /* 4 */
10267 break;
10268 case NE:
10269 fputs ("ne", file); /* 24 */
10270 break;
10271 case LT:
10272 fputs ("lt", file); /* 16 */
10273 break;
10274 case LE:
10275 fputs ("le", file); /* 20 */
10276 break;
10277 case GT:
10278 fputs ("gt", file); /* 8 */
10279 break;
10280 case GE:
10281 fputs ("ge", file); /* 12 */
10282 break;
10283 case LTU:
10284 fputs ("llt", file); /* 2 */
10285 break;
10286 case LEU:
10287 fputs ("lle", file); /* 6 */
10288 break;
10289 case GTU:
10290 fputs ("lgt", file); /* 1 */
10291 break;
10292 case GEU:
10293 fputs ("lge", file); /* 5 */
10294 break;
10295 default:
10296 abort ();
10297 }
10298 break;
10299
9854d9ed
RK
10300 case 'w':
10301 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
10302 normally. */
10303 if (INT_P (x))
f676971a 10304 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5f59ecb7 10305 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
10306 else
10307 print_operand (file, x, 0);
9878760c
RK
10308 return;
10309
9854d9ed 10310 case 'W':
e2c953b6 10311 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
10312 val = (GET_CODE (x) == CONST_INT
10313 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
10314
10315 if (val < 0)
10316 i = -1;
9854d9ed 10317 else
e2c953b6
DE
10318 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
10319 if ((val <<= 1) < 0)
10320 break;
10321
10322#if HOST_BITS_PER_WIDE_INT == 32
10323 if (GET_CODE (x) == CONST_INT && i >= 0)
10324 i += 32; /* zero-extend high-part was all 0's */
10325 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
10326 {
10327 val = CONST_DOUBLE_LOW (x);
10328
10329 if (val == 0)
a4f6c312 10330 abort ();
e2c953b6
DE
10331 else if (val < 0)
10332 --i;
10333 else
10334 for ( ; i < 64; i++)
10335 if ((val <<= 1) < 0)
10336 break;
10337 }
10338#endif
10339
10340 fprintf (file, "%d", i + 1);
9854d9ed 10341 return;
9878760c 10342
9854d9ed
RK
10343 case 'X':
10344 if (GET_CODE (x) == MEM
4d588c14 10345 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 10346 putc ('x', file);
9854d9ed 10347 return;
9878760c 10348
9854d9ed
RK
10349 case 'Y':
10350 /* Like 'L', for third word of TImode */
10351 if (GET_CODE (x) == REG)
5ebfb2ba 10352 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 10353 else if (GET_CODE (x) == MEM)
9878760c 10354 {
9854d9ed
RK
10355 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10356 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10357 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 10358 else
d7624dc0 10359 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 10360 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10361 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10362 reg_names[SMALL_DATA_REG]);
9878760c
RK
10363 }
10364 return;
f676971a 10365
9878760c 10366 case 'z':
b4ac57ab
RS
10367 /* X is a SYMBOL_REF. Write out the name preceded by a
10368 period and without any trailing data in brackets. Used for function
4d30c363
MM
10369 names. If we are configured for System V (or the embedded ABI) on
10370 the PowerPC, do not emit the period, since those systems do not use
10371 TOCs and the like. */
9878760c
RK
10372 if (GET_CODE (x) != SYMBOL_REF)
10373 abort ();
10374
9bf6462a
AP
10375 /* Mark the decl as referenced so that cgraph will output the function. */
10376 if (SYMBOL_REF_DECL (x))
10377 mark_decl_referenced (SYMBOL_REF_DECL (x));
10378
85b776df 10379 /* For macho, check to see if we need a stub. */
f9da97f0
AP
10380 if (TARGET_MACHO)
10381 {
10382 const char *name = XSTR (x, 0);
a031e781 10383#if TARGET_MACHO
3b48085e 10384 if (MACHOPIC_INDIRECT
11abc112
MM
10385 && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10386 name = machopic_indirection_name (x, /*stub_p=*/true);
f9da97f0
AP
10387#endif
10388 assemble_name (file, name);
10389 }
85b776df 10390 else if (!DOT_SYMBOLS)
9739c90c 10391 assemble_name (file, XSTR (x, 0));
85b776df
AM
10392 else
10393 rs6000_output_function_entry (file, XSTR (x, 0));
9878760c
RK
10394 return;
10395
9854d9ed
RK
10396 case 'Z':
10397 /* Like 'L', for last word of TImode. */
10398 if (GET_CODE (x) == REG)
5ebfb2ba 10399 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
10400 else if (GET_CODE (x) == MEM)
10401 {
10402 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10403 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10404 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 10405 else
d7624dc0 10406 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 10407 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10408 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10409 reg_names[SMALL_DATA_REG]);
9854d9ed 10410 }
5c23c401 10411 return;
0ac081f6 10412
a3170dc6 10413 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
10414 case 'y':
10415 {
10416 rtx tmp;
10417
10418 if (GET_CODE (x) != MEM)
10419 abort ();
10420
10421 tmp = XEXP (x, 0);
10422
993f19a8 10423 if (TARGET_E500)
a3170dc6
AH
10424 {
10425 /* Handle [reg]. */
10426 if (GET_CODE (tmp) == REG)
10427 {
10428 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
10429 break;
10430 }
10431 /* Handle [reg+UIMM]. */
10432 else if (GET_CODE (tmp) == PLUS &&
10433 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
10434 {
10435 int x;
10436
10437 if (GET_CODE (XEXP (tmp, 0)) != REG)
10438 abort ();
10439
10440 x = INTVAL (XEXP (tmp, 1));
10441 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
10442 break;
10443 }
10444
10445 /* Fall through. Must be [reg+reg]. */
10446 }
0ac081f6 10447 if (GET_CODE (tmp) == REG)
c62f2db5 10448 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
10449 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
10450 {
10451 if (REGNO (XEXP (tmp, 0)) == 0)
10452 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
10453 reg_names[ REGNO (XEXP (tmp, 0)) ]);
10454 else
10455 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
10456 reg_names[ REGNO (XEXP (tmp, 1)) ]);
10457 }
10458 else
10459 abort ();
10460 break;
10461 }
f676971a 10462
9878760c
RK
10463 case 0:
10464 if (GET_CODE (x) == REG)
10465 fprintf (file, "%s", reg_names[REGNO (x)]);
10466 else if (GET_CODE (x) == MEM)
10467 {
10468 /* We need to handle PRE_INC and PRE_DEC here, since we need to
10469 know the width from the mode. */
10470 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
10471 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
10472 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10473 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
10474 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
10475 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10476 else
a54d04b7 10477 output_address (XEXP (x, 0));
9878760c
RK
10478 }
10479 else
a54d04b7 10480 output_addr_const (file, x);
a85d226b 10481 return;
9878760c 10482
c4501e62
JJ
10483 case '&':
10484 assemble_name (file, rs6000_get_some_local_dynamic_name ());
10485 return;
10486
9878760c
RK
10487 default:
10488 output_operand_lossage ("invalid %%xn code");
10489 }
10490}
10491\f
10492/* Print the address of an operand. */
10493
10494void
a2369ed3 10495print_operand_address (FILE *file, rtx x)
9878760c
RK
10496{
10497 if (GET_CODE (x) == REG)
4697a36c 10498 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
10499 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
10500 || GET_CODE (x) == LABEL_REF)
9878760c
RK
10501 {
10502 output_addr_const (file, x);
ba5e43aa 10503 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10504 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10505 reg_names[SMALL_DATA_REG]);
9ebbca7d 10506 else if (TARGET_TOC)
a4f6c312 10507 abort ();
9878760c
RK
10508 }
10509 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
10510 {
10511 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
10512 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
10513 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 10514 else
4697a36c
MM
10515 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
10516 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
10517 }
10518 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
10519 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
10520 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
10521#if TARGET_ELF
10522 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
10523 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
10524 {
10525 output_addr_const (file, XEXP (x, 1));
10526 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10527 }
c859cda6
DJ
10528#endif
10529#if TARGET_MACHO
10530 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
10531 && CONSTANT_P (XEXP (x, 1)))
10532 {
10533 fprintf (file, "lo16(");
10534 output_addr_const (file, XEXP (x, 1));
10535 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10536 }
3cb999d8 10537#endif
4d588c14 10538 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 10539 {
2bfcf297 10540 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 10541 {
2bfcf297
DB
10542 rtx contains_minus = XEXP (x, 1);
10543 rtx minus, symref;
10544 const char *name;
f676971a 10545
9ebbca7d 10546 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 10547 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
10548 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
10549 contains_minus = XEXP (contains_minus, 0);
10550
2bfcf297
DB
10551 minus = XEXP (contains_minus, 0);
10552 symref = XEXP (minus, 0);
10553 XEXP (contains_minus, 0) = symref;
10554 if (TARGET_ELF)
10555 {
10556 char *newname;
10557
10558 name = XSTR (symref, 0);
10559 newname = alloca (strlen (name) + sizeof ("@toc"));
10560 strcpy (newname, name);
10561 strcat (newname, "@toc");
10562 XSTR (symref, 0) = newname;
10563 }
10564 output_addr_const (file, XEXP (x, 1));
10565 if (TARGET_ELF)
10566 XSTR (symref, 0) = name;
9ebbca7d
GK
10567 XEXP (contains_minus, 0) = minus;
10568 }
10569 else
10570 output_addr_const (file, XEXP (x, 1));
10571
10572 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
10573 }
9878760c
RK
10574 else
10575 abort ();
10576}
10577\f
88cad84b 10578/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
10579 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
10580 is defined. It also needs to handle DI-mode objects on 64-bit
10581 targets. */
10582
10583static bool
a2369ed3 10584rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
10585{
10586#ifdef RELOCATABLE_NEEDS_FIXUP
10587 /* Special handling for SI values. */
10588 if (size == 4 && aligned_p)
10589 {
a2369ed3 10590 extern int in_toc_section (void);
301d03af 10591 static int recurse = 0;
f676971a 10592
301d03af
RS
10593 /* For -mrelocatable, we mark all addresses that need to be fixed up
10594 in the .fixup section. */
10595 if (TARGET_RELOCATABLE
10596 && !in_toc_section ()
10597 && !in_text_section ()
642af3be 10598 && !in_unlikely_text_section ()
301d03af
RS
10599 && !recurse
10600 && GET_CODE (x) != CONST_INT
10601 && GET_CODE (x) != CONST_DOUBLE
10602 && CONSTANT_P (x))
10603 {
10604 char buf[256];
10605
10606 recurse = 1;
10607 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
10608 fixuplabelno++;
10609 ASM_OUTPUT_LABEL (asm_out_file, buf);
10610 fprintf (asm_out_file, "\t.long\t(");
10611 output_addr_const (asm_out_file, x);
10612 fprintf (asm_out_file, ")@fixup\n");
10613 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
10614 ASM_OUTPUT_ALIGN (asm_out_file, 2);
10615 fprintf (asm_out_file, "\t.long\t");
10616 assemble_name (asm_out_file, buf);
10617 fprintf (asm_out_file, "\n\t.previous\n");
10618 recurse = 0;
10619 return true;
10620 }
10621 /* Remove initial .'s to turn a -mcall-aixdesc function
10622 address into the address of the descriptor, not the function
10623 itself. */
10624 else if (GET_CODE (x) == SYMBOL_REF
10625 && XSTR (x, 0)[0] == '.'
10626 && DEFAULT_ABI == ABI_AIX)
10627 {
10628 const char *name = XSTR (x, 0);
10629 while (*name == '.')
10630 name++;
10631
10632 fprintf (asm_out_file, "\t.long\t%s\n", name);
10633 return true;
10634 }
10635 }
10636#endif /* RELOCATABLE_NEEDS_FIXUP */
10637 return default_assemble_integer (x, size, aligned_p);
10638}
93638d7a
AM
10639
10640#ifdef HAVE_GAS_HIDDEN
10641/* Emit an assembler directive to set symbol visibility for DECL to
10642 VISIBILITY_TYPE. */
10643
5add3202 10644static void
a2369ed3 10645rs6000_assemble_visibility (tree decl, int vis)
93638d7a 10646{
93638d7a
AM
10647 /* Functions need to have their entry point symbol visibility set as
10648 well as their descriptor symbol visibility. */
85b776df
AM
10649 if (DEFAULT_ABI == ABI_AIX
10650 && DOT_SYMBOLS
10651 && TREE_CODE (decl) == FUNCTION_DECL)
93638d7a 10652 {
25fdb4dc
RH
10653 static const char * const visibility_types[] = {
10654 NULL, "internal", "hidden", "protected"
10655 };
10656
10657 const char *name, *type;
93638d7a
AM
10658
10659 name = ((* targetm.strip_name_encoding)
10660 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 10661 type = visibility_types[vis];
93638d7a 10662
25fdb4dc
RH
10663 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
10664 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 10665 }
25fdb4dc
RH
10666 else
10667 default_assemble_visibility (decl, vis);
93638d7a
AM
10668}
10669#endif
301d03af 10670\f
39a10a29 10671enum rtx_code
a2369ed3 10672rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
10673{
10674 /* Reversal of FP compares takes care -- an ordered compare
10675 becomes an unordered compare and vice versa. */
f676971a 10676 if (mode == CCFPmode
bc9ec0e0
GK
10677 && (!flag_finite_math_only
10678 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
10679 || code == UNEQ || code == LTGT))
bab6226b 10680 return reverse_condition_maybe_unordered (code);
39a10a29 10681 else
bab6226b 10682 return reverse_condition (code);
39a10a29
GK
10683}
10684
39a10a29
GK
10685/* Generate a compare for CODE. Return a brand-new rtx that
10686 represents the result of the compare. */
a4f6c312 10687
39a10a29 10688static rtx
a2369ed3 10689rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
10690{
10691 enum machine_mode comp_mode;
10692 rtx compare_result;
10693
10694 if (rs6000_compare_fp_p)
10695 comp_mode = CCFPmode;
10696 else if (code == GTU || code == LTU
10697 || code == GEU || code == LEU)
10698 comp_mode = CCUNSmode;
10699 else
10700 comp_mode = CCmode;
10701
10702 /* First, the compare. */
10703 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
10704
10705 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
10706 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10707 && rs6000_compare_fp_p)
a3170dc6
AH
10708 {
10709 rtx cmp, or1, or2, or_result, compare_result2;
10710
423c1189
AH
10711 /* Note: The E500 comparison instructions set the GT bit (x +
10712 1), on success. This explains the mess. */
10713
a3170dc6
AH
10714 switch (code)
10715 {
423c1189 10716 case EQ: case UNEQ: case NE: case LTGT:
bc9ec0e0 10717 cmp = flag_finite_math_only
a3170dc6
AH
10718 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
10719 rs6000_compare_op1)
10720 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
10721 rs6000_compare_op1);
10722 break;
423c1189 10723 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
bc9ec0e0 10724 cmp = flag_finite_math_only
a3170dc6
AH
10725 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
10726 rs6000_compare_op1)
10727 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
10728 rs6000_compare_op1);
10729 break;
423c1189 10730 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
bc9ec0e0 10731 cmp = flag_finite_math_only
a3170dc6
AH
10732 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
10733 rs6000_compare_op1)
10734 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
10735 rs6000_compare_op1);
10736 break;
10737 default:
10738 abort ();
10739 }
10740
10741 /* Synthesize LE and GE from LT/GT || EQ. */
10742 if (code == LE || code == GE || code == LEU || code == GEU)
10743 {
a3170dc6
AH
10744 emit_insn (cmp);
10745
10746 switch (code)
10747 {
10748 case LE: code = LT; break;
10749 case GE: code = GT; break;
10750 case LEU: code = LT; break;
10751 case GEU: code = GT; break;
10752 default: abort ();
10753 }
10754
10755 or1 = gen_reg_rtx (SImode);
10756 or2 = gen_reg_rtx (SImode);
10757 or_result = gen_reg_rtx (CCEQmode);
10758 compare_result2 = gen_reg_rtx (CCFPmode);
10759
10760 /* Do the EQ. */
bc9ec0e0 10761 cmp = flag_finite_math_only
a3170dc6
AH
10762 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
10763 rs6000_compare_op1)
10764 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
10765 rs6000_compare_op1);
10766 emit_insn (cmp);
10767
423c1189
AH
10768 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
10769 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
10770
10771 /* OR them together. */
10772 cmp = gen_rtx_SET (VOIDmode, or_result,
10773 gen_rtx_COMPARE (CCEQmode,
10774 gen_rtx_IOR (SImode, or1, or2),
10775 const_true_rtx));
10776 compare_result = or_result;
10777 code = EQ;
10778 }
10779 else
10780 {
a3170dc6 10781 if (code == NE || code == LTGT)
a3170dc6 10782 code = NE;
423c1189
AH
10783 else
10784 code = EQ;
a3170dc6
AH
10785 }
10786
10787 emit_insn (cmp);
10788 }
10789 else
10790 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
10791 gen_rtx_COMPARE (comp_mode,
f676971a 10792 rs6000_compare_op0,
a3170dc6 10793 rs6000_compare_op1)));
f676971a 10794
ca5adc63 10795 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 10796 under flag_finite_math_only we don't bother. */
39a10a29 10797 if (rs6000_compare_fp_p
bc9ec0e0 10798 && ! flag_finite_math_only
993f19a8 10799 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
10800 && (code == LE || code == GE
10801 || code == UNEQ || code == LTGT
10802 || code == UNGT || code == UNLT))
10803 {
10804 enum rtx_code or1, or2;
10805 rtx or1_rtx, or2_rtx, compare2_rtx;
10806 rtx or_result = gen_reg_rtx (CCEQmode);
f676971a 10807
39a10a29
GK
10808 switch (code)
10809 {
10810 case LE: or1 = LT; or2 = EQ; break;
10811 case GE: or1 = GT; or2 = EQ; break;
10812 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
10813 case LTGT: or1 = LT; or2 = GT; break;
10814 case UNGT: or1 = UNORDERED; or2 = GT; break;
10815 case UNLT: or1 = UNORDERED; or2 = LT; break;
10816 default: abort ();
10817 }
10818 validate_condition_mode (or1, comp_mode);
10819 validate_condition_mode (or2, comp_mode);
1c563bed
KH
10820 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
10821 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
10822 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
10823 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
10824 const_true_rtx);
10825 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
10826
10827 compare_result = or_result;
10828 code = EQ;
10829 }
10830
10831 validate_condition_mode (code, GET_MODE (compare_result));
f676971a 10832
1c563bed 10833 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
10834}
10835
10836
10837/* Emit the RTL for an sCOND pattern. */
10838
10839void
a2369ed3 10840rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
10841{
10842 rtx condition_rtx;
10843 enum machine_mode op_mode;
b7053a3f 10844 enum rtx_code cond_code;
39a10a29
GK
10845
10846 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
10847 cond_code = GET_CODE (condition_rtx);
10848
423c1189
AH
10849 if (TARGET_E500 && rs6000_compare_fp_p
10850 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10851 {
10852 rtx t;
10853
10854 PUT_MODE (condition_rtx, SImode);
10855 t = XEXP (condition_rtx, 0);
10856
10857 if (cond_code != NE && cond_code != EQ)
10858 abort ();
10859
10860 if (cond_code == NE)
6b1fedc3 10861 emit_insn (gen_e500_flip_eq_bit (t, t));
423c1189 10862
6b1fedc3 10863 emit_insn (gen_move_from_CR_eq_bit (result, t));
423c1189
AH
10864 return;
10865 }
10866
b7053a3f
GK
10867 if (cond_code == NE
10868 || cond_code == GE || cond_code == LE
10869 || cond_code == GEU || cond_code == LEU
10870 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
10871 {
10872 rtx not_result = gen_reg_rtx (CCEQmode);
10873 rtx not_op, rev_cond_rtx;
10874 enum machine_mode cc_mode;
f676971a 10875
b7053a3f
GK
10876 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
10877
1c563bed 10878 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 10879 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
10880 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
10881 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
10882 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
10883 }
39a10a29
GK
10884
10885 op_mode = GET_MODE (rs6000_compare_op0);
10886 if (op_mode == VOIDmode)
10887 op_mode = GET_MODE (rs6000_compare_op1);
10888
10889 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
10890 {
10891 PUT_MODE (condition_rtx, DImode);
10892 convert_move (result, condition_rtx, 0);
10893 }
10894 else
10895 {
10896 PUT_MODE (condition_rtx, SImode);
10897 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
10898 }
10899}
10900
39a10a29
GK
10901/* Emit a branch of kind CODE to location LOC. */
10902
10903void
a2369ed3 10904rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
10905{
10906 rtx condition_rtx, loc_ref;
10907
10908 condition_rtx = rs6000_generate_compare (code);
10909 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
10910 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
10911 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
10912 loc_ref, pc_rtx)));
10913}
10914
12a4e8c5
GK
10915/* Return the string to output a conditional branch to LABEL, which is
10916 the operand number of the label, or -1 if the branch is really a
f676971a 10917 conditional return.
12a4e8c5
GK
10918
10919 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
10920 condition code register and its mode specifies what kind of
10921 comparison we made.
10922
a0ab749a 10923 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
10924
10925 INSN is the insn. */
10926
10927char *
a2369ed3 10928output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
10929{
10930 static char string[64];
10931 enum rtx_code code = GET_CODE (op);
10932 rtx cc_reg = XEXP (op, 0);
10933 enum machine_mode mode = GET_MODE (cc_reg);
10934 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 10935 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
10936 int really_reversed = reversed ^ need_longbranch;
10937 char *s = string;
10938 const char *ccode;
10939 const char *pred;
10940 rtx note;
10941
39a10a29
GK
10942 validate_condition_mode (code, mode);
10943
10944 /* Work out which way this really branches. We could use
10945 reverse_condition_maybe_unordered here always but this
10946 makes the resulting assembler clearer. */
12a4e8c5 10947 if (really_reversed)
de40e1df
DJ
10948 {
10949 /* Reversal of FP compares takes care -- an ordered compare
10950 becomes an unordered compare and vice versa. */
10951 if (mode == CCFPmode)
10952 code = reverse_condition_maybe_unordered (code);
10953 else
10954 code = reverse_condition (code);
10955 }
12a4e8c5 10956
993f19a8 10957 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
10958 {
10959 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
10960 to the GT bit. */
10961 if (code == EQ)
10962 /* Opposite of GT. */
a3170dc6 10963 code = GT;
423c1189
AH
10964 else if (code == NE)
10965 code = UNLE;
a3170dc6
AH
10966 else
10967 abort ();
10968 }
10969
39a10a29 10970 switch (code)
12a4e8c5
GK
10971 {
10972 /* Not all of these are actually distinct opcodes, but
10973 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
10974 case NE: case LTGT:
10975 ccode = "ne"; break;
10976 case EQ: case UNEQ:
10977 ccode = "eq"; break;
f676971a 10978 case GE: case GEU:
50a0b056 10979 ccode = "ge"; break;
f676971a 10980 case GT: case GTU: case UNGT:
50a0b056 10981 ccode = "gt"; break;
f676971a 10982 case LE: case LEU:
50a0b056 10983 ccode = "le"; break;
f676971a 10984 case LT: case LTU: case UNLT:
50a0b056 10985 ccode = "lt"; break;
12a4e8c5
GK
10986 case UNORDERED: ccode = "un"; break;
10987 case ORDERED: ccode = "nu"; break;
10988 case UNGE: ccode = "nl"; break;
10989 case UNLE: ccode = "ng"; break;
10990 default:
a4f6c312 10991 abort ();
12a4e8c5 10992 }
f676971a
EC
10993
10994 /* Maybe we have a guess as to how likely the branch is.
94a54f47 10995 The old mnemonics don't have a way to specify this information. */
f4857b9b 10996 pred = "";
12a4e8c5
GK
10997 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
10998 if (note != NULL_RTX)
10999 {
11000 /* PROB is the difference from 50%. */
11001 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
11002
11003 /* Only hint for highly probable/improbable branches on newer
11004 cpus as static prediction overrides processor dynamic
11005 prediction. For older cpus we may as well always hint, but
11006 assume not taken for branches that are very close to 50% as a
11007 mispredicted taken branch is more expensive than a
f676971a 11008 mispredicted not-taken branch. */
ec507f2d 11009 if (rs6000_always_hint
f4857b9b
AM
11010 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
11011 {
11012 if (abs (prob) > REG_BR_PROB_BASE / 20
11013 && ((prob > 0) ^ need_longbranch))
7f3d8013 11014 pred = "+";
f4857b9b
AM
11015 else
11016 pred = "-";
11017 }
12a4e8c5 11018 }
12a4e8c5
GK
11019
11020 if (label == NULL)
94a54f47 11021 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 11022 else
94a54f47 11023 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 11024
37c67319 11025 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 11026 Assume they'd only be the first character.... */
37c67319
GK
11027 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
11028 *s++ = '%';
94a54f47 11029 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
11030
11031 if (label != NULL)
11032 {
11033 /* If the branch distance was too far, we may have to use an
11034 unconditional branch to go the distance. */
11035 if (need_longbranch)
44518ddd 11036 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
11037 else
11038 s += sprintf (s, ",%s", label);
11039 }
11040
11041 return string;
11042}
50a0b056 11043
6b1fedc3 11044/* Return the string to flip the EQ bit on a CR. */
423c1189 11045char *
6b1fedc3 11046output_e500_flip_eq_bit (rtx dst, rtx src)
423c1189
AH
11047{
11048 static char string[64];
11049 int a, b;
11050
11051 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
11052 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
11053 abort ();
11054
6b1fedc3
AH
11055 /* EQ bit. */
11056 a = 4 * (REGNO (dst) - CR0_REGNO) + 2;
11057 b = 4 * (REGNO (src) - CR0_REGNO) + 2;
423c1189
AH
11058
11059 sprintf (string, "crnot %d,%d", a, b);
11060 return string;
11061}
11062
50a0b056
GK
11063/* Emit a conditional move: move TRUE_COND to DEST if OP of the
11064 operands of the last comparison is nonzero/true, FALSE_COND if it
11065 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 11066
50a0b056 11067int
a2369ed3 11068rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
11069{
11070 enum rtx_code code = GET_CODE (op);
11071 rtx op0 = rs6000_compare_op0;
11072 rtx op1 = rs6000_compare_op1;
11073 REAL_VALUE_TYPE c1;
3148ad6d
DJ
11074 enum machine_mode compare_mode = GET_MODE (op0);
11075 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
11076 rtx temp;
11077
a3c9585f 11078 /* These modes should always match. */
a3170dc6
AH
11079 if (GET_MODE (op1) != compare_mode
11080 /* In the isel case however, we can use a compare immediate, so
11081 op1 may be a small constant. */
11082 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 11083 return 0;
178c3eff 11084 if (GET_MODE (true_cond) != result_mode)
3148ad6d 11085 return 0;
178c3eff 11086 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
11087 return 0;
11088
50a0b056 11089 /* First, work out if the hardware can do this at all, or
a3c9585f 11090 if it's too slow.... */
50a0b056 11091 if (! rs6000_compare_fp_p)
a3170dc6
AH
11092 {
11093 if (TARGET_ISEL)
11094 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
11095 return 0;
11096 }
fef98bf2
AH
11097 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
11098 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
11099 return 0;
50a0b056
GK
11100
11101 /* Eliminate half of the comparisons by switching operands, this
11102 makes the remaining code simpler. */
11103 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 11104 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
11105 {
11106 code = reverse_condition_maybe_unordered (code);
11107 temp = true_cond;
11108 true_cond = false_cond;
11109 false_cond = temp;
11110 }
11111
11112 /* UNEQ and LTGT take four instructions for a comparison with zero,
11113 it'll probably be faster to use a branch here too. */
bc9ec0e0 11114 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056 11115 return 0;
f676971a 11116
50a0b056
GK
11117 if (GET_CODE (op1) == CONST_DOUBLE)
11118 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
f676971a 11119
b6d08ca1 11120 /* We're going to try to implement comparisons by performing
50a0b056
GK
11121 a subtract, then comparing against zero. Unfortunately,
11122 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 11123 know that the operand is finite and the comparison
50a0b056 11124 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 11125 if (HONOR_INFINITIES (compare_mode)
50a0b056 11126 && code != GT && code != UNGE
045572c7 11127 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
11128 /* Constructs of the form (a OP b ? a : b) are safe. */
11129 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
f676971a 11130 || (! rtx_equal_p (op0, true_cond)
50a0b056
GK
11131 && ! rtx_equal_p (op1, true_cond))))
11132 return 0;
11133 /* At this point we know we can use fsel. */
11134
11135 /* Reduce the comparison to a comparison against zero. */
3148ad6d 11136 temp = gen_reg_rtx (compare_mode);
50a0b056 11137 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 11138 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 11139 op0 = temp;
3148ad6d 11140 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
11141
11142 /* If we don't care about NaNs we can reduce some of the comparisons
11143 down to faster ones. */
bc9ec0e0 11144 if (! HONOR_NANS (compare_mode))
50a0b056
GK
11145 switch (code)
11146 {
11147 case GT:
11148 code = LE;
11149 temp = true_cond;
11150 true_cond = false_cond;
11151 false_cond = temp;
11152 break;
11153 case UNGE:
11154 code = GE;
11155 break;
11156 case UNEQ:
11157 code = EQ;
11158 break;
11159 default:
11160 break;
11161 }
11162
11163 /* Now, reduce everything down to a GE. */
11164 switch (code)
11165 {
11166 case GE:
11167 break;
11168
11169 case LE:
3148ad6d
DJ
11170 temp = gen_reg_rtx (compare_mode);
11171 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11172 op0 = temp;
11173 break;
11174
11175 case ORDERED:
3148ad6d
DJ
11176 temp = gen_reg_rtx (compare_mode);
11177 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
11178 op0 = temp;
11179 break;
11180
11181 case EQ:
3148ad6d 11182 temp = gen_reg_rtx (compare_mode);
f676971a 11183 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
11184 gen_rtx_NEG (compare_mode,
11185 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
11186 op0 = temp;
11187 break;
11188
11189 case UNGE:
bc9ec0e0 11190 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 11191 temp = gen_reg_rtx (result_mode);
50a0b056 11192 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 11193 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11194 gen_rtx_GE (VOIDmode,
11195 op0, op1),
11196 true_cond, false_cond)));
bc9ec0e0
GK
11197 false_cond = true_cond;
11198 true_cond = temp;
50a0b056 11199
3148ad6d
DJ
11200 temp = gen_reg_rtx (compare_mode);
11201 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11202 op0 = temp;
11203 break;
11204
11205 case GT:
bc9ec0e0 11206 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 11207 temp = gen_reg_rtx (result_mode);
50a0b056 11208 emit_insn (gen_rtx_SET (VOIDmode, temp,
f676971a 11209 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11210 gen_rtx_GE (VOIDmode,
11211 op0, op1),
11212 true_cond, false_cond)));
bc9ec0e0
GK
11213 true_cond = false_cond;
11214 false_cond = temp;
50a0b056 11215
3148ad6d
DJ
11216 temp = gen_reg_rtx (compare_mode);
11217 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11218 op0 = temp;
11219 break;
11220
11221 default:
11222 abort ();
11223 }
11224
11225 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 11226 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11227 gen_rtx_GE (VOIDmode,
11228 op0, op1),
11229 true_cond, false_cond)));
11230 return 1;
11231}
11232
a3170dc6
AH
11233/* Same as above, but for ints (isel). */
11234
11235static int
a2369ed3 11236rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
11237{
11238 rtx condition_rtx, cr;
11239
11240 /* All isel implementations thus far are 32-bits. */
11241 if (GET_MODE (rs6000_compare_op0) != SImode)
11242 return 0;
11243
11244 /* We still have to do the compare, because isel doesn't do a
11245 compare, it just looks at the CRx bits set by a previous compare
11246 instruction. */
11247 condition_rtx = rs6000_generate_compare (GET_CODE (op));
11248 cr = XEXP (condition_rtx, 0);
11249
11250 if (GET_MODE (cr) == CCmode)
11251 emit_insn (gen_isel_signed (dest, condition_rtx,
11252 true_cond, false_cond, cr));
11253 else
11254 emit_insn (gen_isel_unsigned (dest, condition_rtx,
11255 true_cond, false_cond, cr));
11256
11257 return 1;
11258}
11259
11260const char *
a2369ed3 11261output_isel (rtx *operands)
a3170dc6
AH
11262{
11263 enum rtx_code code;
11264
11265 code = GET_CODE (operands[1]);
11266 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
11267 {
11268 PUT_CODE (operands[1], reverse_condition (code));
11269 return "isel %0,%3,%2,%j1";
11270 }
11271 else
11272 return "isel %0,%2,%3,%j1";
11273}
11274
50a0b056 11275void
a2369ed3 11276rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
11277{
11278 enum machine_mode mode = GET_MODE (op0);
5dc8d536 11279 enum rtx_code c;
50a0b056 11280 rtx target;
5dc8d536
AH
11281
11282 if (code == SMAX || code == SMIN)
11283 c = GE;
11284 else
11285 c = GEU;
11286
50a0b056 11287 if (code == SMAX || code == UMAX)
f676971a 11288 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11289 op0, op1, mode, 0);
11290 else
f676971a 11291 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11292 op1, op0, mode, 0);
11293 if (target == NULL_RTX)
11294 abort ();
11295 if (target != dest)
11296 emit_move_insn (dest, target);
11297}
46c07df8 11298
a9baceb1
GK
11299/* Emit instructions to move SRC to DST. Called by splitters for
11300 multi-register moves. It will emit at most one instruction for
11301 each register that is accessed; that is, it won't emit li/lis pairs
11302 (or equivalent for 64-bit code). One of SRC or DST must be a hard
11303 register. */
46c07df8 11304
46c07df8 11305void
a9baceb1 11306rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 11307{
a9baceb1
GK
11308 /* The register number of the first register being moved. */
11309 int reg;
11310 /* The mode that is to be moved. */
11311 enum machine_mode mode;
11312 /* The mode that the move is being done in, and its size. */
11313 enum machine_mode reg_mode;
11314 int reg_mode_size;
11315 /* The number of registers that will be moved. */
11316 int nregs;
11317
11318 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
11319 mode = GET_MODE (dst);
11320 nregs = HARD_REGNO_NREGS (reg, mode);
11321 if (FP_REGNO_P (reg))
11322 reg_mode = DFmode;
11323 else if (ALTIVEC_REGNO_P (reg))
11324 reg_mode = V16QImode;
11325 else
11326 reg_mode = word_mode;
11327 reg_mode_size = GET_MODE_SIZE (reg_mode);
f676971a 11328
a9baceb1
GK
11329 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
11330 abort ();
f676971a 11331
a9baceb1
GK
11332 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
11333 {
11334 /* Move register range backwards, if we might have destructive
11335 overlap. */
11336 int i;
11337 for (i = nregs - 1; i >= 0; i--)
f676971a 11338 emit_insn (gen_rtx_SET (VOIDmode,
a9baceb1
GK
11339 simplify_gen_subreg (reg_mode, dst, mode,
11340 i * reg_mode_size),
11341 simplify_gen_subreg (reg_mode, src, mode,
11342 i * reg_mode_size)));
11343 }
46c07df8
HP
11344 else
11345 {
a9baceb1
GK
11346 int i;
11347 int j = -1;
11348 bool used_update = false;
46c07df8 11349
c1e55850 11350 if (MEM_P (src) && INT_REGNO_P (reg))
46c07df8
HP
11351 {
11352 rtx breg;
3a1f863f 11353
a9baceb1
GK
11354 if (GET_CODE (XEXP (src, 0)) == PRE_INC
11355 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
11356 {
11357 rtx delta_rtx;
a9baceb1 11358 breg = XEXP (XEXP (src, 0), 0);
f676971a
EC
11359 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
11360 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
11361 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
a9baceb1
GK
11362 emit_insn (TARGET_32BIT
11363 ? gen_addsi3 (breg, breg, delta_rtx)
11364 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11365 src = gen_rtx_MEM (mode, breg);
11366 }
c1e55850
GK
11367 else if (! offsettable_memref_p (src))
11368 {
11369 rtx newsrc, basereg;
11370 basereg = gen_rtx_REG (Pmode, reg);
11371 emit_insn (gen_rtx_SET (VOIDmode, basereg, XEXP (src, 0)));
11372 newsrc = gen_rtx_MEM (GET_MODE (src), basereg);
11373 MEM_COPY_ATTRIBUTES (newsrc, src);
11374 src = newsrc;
11375 }
3a1f863f 11376
0423421f
AM
11377 breg = XEXP (src, 0);
11378 if (GET_CODE (breg) == PLUS || GET_CODE (breg) == LO_SUM)
11379 breg = XEXP (breg, 0);
11380
11381 /* If the base register we are using to address memory is
11382 also a destination reg, then change that register last. */
11383 if (REG_P (breg)
11384 && REGNO (breg) >= REGNO (dst)
3a1f863f
DE
11385 && REGNO (breg) < REGNO (dst) + nregs)
11386 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
11387 }
11388
a9baceb1 11389 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
11390 {
11391 rtx breg;
11392
a9baceb1
GK
11393 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
11394 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
11395 {
11396 rtx delta_rtx;
a9baceb1 11397 breg = XEXP (XEXP (dst, 0), 0);
f676971a
EC
11398 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
11399 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
11400 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
11401
11402 /* We have to update the breg before doing the store.
11403 Use store with update, if available. */
11404
11405 if (TARGET_UPDATE)
11406 {
a9baceb1 11407 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
2e6c9641
FJ
11408 emit_insn (TARGET_32BIT
11409 ? (TARGET_POWERPC64
11410 ? gen_movdi_si_update (breg, breg, delta_rtx, nsrc)
11411 : gen_movsi_update (breg, breg, delta_rtx, nsrc))
11412 : gen_movdi_di_update (breg, breg, delta_rtx, nsrc));
a9baceb1 11413 used_update = true;
3a1f863f
DE
11414 }
11415 else
a9baceb1
GK
11416 emit_insn (TARGET_32BIT
11417 ? gen_addsi3 (breg, breg, delta_rtx)
11418 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11419 dst = gen_rtx_MEM (mode, breg);
11420 }
c1e55850 11421 else if (! offsettable_memref_p (dst))
112ccb83 11422 abort ();
3a1f863f
DE
11423 }
11424
46c07df8 11425 for (i = 0; i < nregs; i++)
f676971a 11426 {
3a1f863f
DE
11427 /* Calculate index to next subword. */
11428 ++j;
f676971a 11429 if (j == nregs)
3a1f863f 11430 j = 0;
46c07df8 11431
f676971a 11432 /* If compiler already emited move of first word by
a9baceb1 11433 store with update, no need to do anything. */
3a1f863f 11434 if (j == 0 && used_update)
a9baceb1 11435 continue;
f676971a 11436
a9baceb1
GK
11437 emit_insn (gen_rtx_SET (VOIDmode,
11438 simplify_gen_subreg (reg_mode, dst, mode,
11439 j * reg_mode_size),
11440 simplify_gen_subreg (reg_mode, src, mode,
11441 j * reg_mode_size)));
3a1f863f 11442 }
46c07df8
HP
11443 }
11444}
11445
12a4e8c5 11446\f
a4f6c312
SS
11447/* This page contains routines that are used to determine what the
11448 function prologue and epilogue code will do and write them out. */
9878760c 11449
a4f6c312
SS
11450/* Return the first fixed-point register that is required to be
11451 saved. 32 if none. */
9878760c
RK
11452
11453int
863d938c 11454first_reg_to_save (void)
9878760c
RK
11455{
11456 int first_reg;
11457
11458 /* Find lowest numbered live register. */
11459 for (first_reg = 13; first_reg <= 31; first_reg++)
f676971a 11460 if (regs_ever_live[first_reg]
a38d360d 11461 && (! call_used_regs[first_reg]
1db02437 11462 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11463 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
b4db40bf
JJ
11464 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)
11465 || (TARGET_TOC && TARGET_MINIMAL_TOC)))))
9878760c
RK
11466 break;
11467
ee890fe2 11468#if TARGET_MACHO
93638d7a
AM
11469 if (flag_pic
11470 && current_function_uses_pic_offset_table
11471 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 11472 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
11473#endif
11474
9878760c
RK
11475 return first_reg;
11476}
11477
11478/* Similar, for FP regs. */
11479
11480int
863d938c 11481first_fp_reg_to_save (void)
9878760c
RK
11482{
11483 int first_reg;
11484
11485 /* Find lowest numbered live register. */
11486 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
11487 if (regs_ever_live[first_reg])
11488 break;
11489
11490 return first_reg;
11491}
00b960c7
AH
11492
11493/* Similar, for AltiVec regs. */
11494
11495static int
863d938c 11496first_altivec_reg_to_save (void)
00b960c7
AH
11497{
11498 int i;
11499
11500 /* Stack frame remains as is unless we are in AltiVec ABI. */
11501 if (! TARGET_ALTIVEC_ABI)
11502 return LAST_ALTIVEC_REGNO + 1;
11503
11504 /* Find lowest numbered live register. */
11505 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
11506 if (regs_ever_live[i])
11507 break;
11508
11509 return i;
11510}
11511
11512/* Return a 32-bit mask of the AltiVec registers we need to set in
11513 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
11514 the 32-bit word is 0. */
11515
11516static unsigned int
863d938c 11517compute_vrsave_mask (void)
00b960c7
AH
11518{
11519 unsigned int i, mask = 0;
11520
11521 /* First, find out if we use _any_ altivec registers. */
11522 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11523 if (regs_ever_live[i])
11524 mask |= ALTIVEC_REG_BIT (i);
11525
11526 if (mask == 0)
11527 return mask;
11528
00b960c7
AH
11529 /* Next, remove the argument registers from the set. These must
11530 be in the VRSAVE mask set by the caller, so we don't need to add
11531 them in again. More importantly, the mask we compute here is
11532 used to generate CLOBBERs in the set_vrsave insn, and we do not
11533 wish the argument registers to die. */
a6cf80f2 11534 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
11535 mask &= ~ALTIVEC_REG_BIT (i);
11536
11537 /* Similarly, remove the return value from the set. */
11538 {
11539 bool yes = false;
11540 diddle_return_value (is_altivec_return_reg, &yes);
11541 if (yes)
11542 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
11543 }
11544
11545 return mask;
11546}
11547
d62294f5
FJ
11548/* For a very restricted set of circumstances, we can cut down the
11549 size of prologs/epilogs by calling our own save/restore-the-world
11550 routines. */
11551
11552static void
11553compute_save_world_info(rs6000_stack_t *info_ptr)
11554{
11555 info_ptr->world_save_p =
11556 (DEFAULT_ABI == ABI_DARWIN)
11557 && ! (current_function_calls_setjmp && flag_exceptions)
11558 && info_ptr->first_fp_reg_save == FIRST_SAVED_FP_REGNO
11559 && info_ptr->first_gp_reg_save == FIRST_SAVED_GP_REGNO
11560 && info_ptr->first_altivec_reg_save == FIRST_SAVED_ALTIVEC_REGNO
11561 && info_ptr->cr_save_p;
f676971a 11562
d62294f5
FJ
11563 /* This will not work in conjunction with sibcalls. Make sure there
11564 are none. (This check is expensive, but seldom executed.) */
11565 if ( info_ptr->world_save_p )
f676971a 11566 {
d62294f5
FJ
11567 rtx insn;
11568 for ( insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn))
11569 if ( GET_CODE (insn) == CALL_INSN
11570 && SIBLING_CALL_P (insn))
f676971a 11571 {
d62294f5
FJ
11572 info_ptr->world_save_p = 0;
11573 break;
11574 }
11575 }
f676971a 11576
d62294f5
FJ
11577 if (info_ptr->world_save_p)
11578 {
11579 /* Even if we're not touching VRsave, make sure there's room on the
11580 stack for it, if it looks like we're calling SAVE_WORLD, which
11581 will attempt to save it. */
11582 info_ptr->vrsave_size = 4;
11583
11584 /* "Save" the VRsave register too if we're saving the world. */
11585 if (info_ptr->vrsave_mask == 0)
11586 info_ptr->vrsave_mask = compute_vrsave_mask ();
11587
11588 /* Because the Darwin register save/restore routines only handle
11589 F14 .. F31 and V20 .. V31 as per the ABI, perform a consistancy
11590 check and abort if there's something worng. */
f676971a 11591 if (info_ptr->first_fp_reg_save < FIRST_SAVED_FP_REGNO
d62294f5
FJ
11592 || info_ptr->first_altivec_reg_save < FIRST_SAVED_ALTIVEC_REGNO)
11593 abort ();
11594 }
f676971a 11595 return;
d62294f5
FJ
11596}
11597
11598
00b960c7 11599static void
a2369ed3 11600is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
11601{
11602 bool *yes = (bool *) xyes;
11603 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
11604 *yes = true;
11605}
11606
4697a36c
MM
11607\f
11608/* Calculate the stack information for the current function. This is
11609 complicated by having two separate calling sequences, the AIX calling
11610 sequence and the V.4 calling sequence.
11611
592696dd 11612 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 11613 32-bit 64-bit
4697a36c 11614 SP----> +---------------------------------------+
a260abc9 11615 | back chain to caller | 0 0
4697a36c 11616 +---------------------------------------+
a260abc9 11617 | saved CR | 4 8 (8-11)
4697a36c 11618 +---------------------------------------+
a260abc9 11619 | saved LR | 8 16
4697a36c 11620 +---------------------------------------+
a260abc9 11621 | reserved for compilers | 12 24
4697a36c 11622 +---------------------------------------+
a260abc9 11623 | reserved for binders | 16 32
4697a36c 11624 +---------------------------------------+
a260abc9 11625 | saved TOC pointer | 20 40
4697a36c 11626 +---------------------------------------+
a260abc9 11627 | Parameter save area (P) | 24 48
4697a36c 11628 +---------------------------------------+
a260abc9 11629 | Alloca space (A) | 24+P etc.
802a0058 11630 +---------------------------------------+
a7df97e6 11631 | Local variable space (L) | 24+P+A
4697a36c 11632 +---------------------------------------+
a7df97e6 11633 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 11634 +---------------------------------------+
00b960c7
AH
11635 | Save area for AltiVec registers (W) | 24+P+A+L+X
11636 +---------------------------------------+
11637 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
11638 +---------------------------------------+
11639 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 11640 +---------------------------------------+
00b960c7
AH
11641 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
11642 +---------------------------------------+
11643 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
11644 +---------------------------------------+
11645 old SP->| back chain to caller's caller |
11646 +---------------------------------------+
11647
5376a30c
KR
11648 The required alignment for AIX configurations is two words (i.e., 8
11649 or 16 bytes).
11650
11651
4697a36c
MM
11652 V.4 stack frames look like:
11653
11654 SP----> +---------------------------------------+
11655 | back chain to caller | 0
11656 +---------------------------------------+
5eb387b8 11657 | caller's saved LR | 4
4697a36c
MM
11658 +---------------------------------------+
11659 | Parameter save area (P) | 8
11660 +---------------------------------------+
a7df97e6 11661 | Alloca space (A) | 8+P
f676971a 11662 +---------------------------------------+
a7df97e6 11663 | Varargs save area (V) | 8+P+A
f676971a 11664 +---------------------------------------+
a7df97e6 11665 | Local variable space (L) | 8+P+A+V
f676971a 11666 +---------------------------------------+
a7df97e6 11667 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 11668 +---------------------------------------+
00b960c7
AH
11669 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
11670 +---------------------------------------+
11671 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
11672 +---------------------------------------+
11673 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
11674 +---------------------------------------+
a3170dc6
AH
11675 | SPE: area for 64-bit GP registers |
11676 +---------------------------------------+
11677 | SPE alignment padding |
11678 +---------------------------------------+
00b960c7 11679 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
f676971a 11680 +---------------------------------------+
00b960c7 11681 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
f676971a 11682 +---------------------------------------+
00b960c7 11683 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
11684 +---------------------------------------+
11685 old SP->| back chain to caller's caller |
11686 +---------------------------------------+
b6c9286a 11687
5376a30c
KR
11688 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
11689 given. (But note below and in sysv4.h that we require only 8 and
11690 may round up the size of our stack frame anyways. The historical
11691 reason is early versions of powerpc-linux which didn't properly
11692 align the stack at program startup. A happy side-effect is that
11693 -mno-eabi libraries can be used with -meabi programs.)
11694
50d440bc 11695 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
11696 the stack alignment requirements may differ. If -mno-eabi is not
11697 given, the required stack alignment is 8 bytes; if -mno-eabi is
11698 given, the required alignment is 16 bytes. (But see V.4 comment
11699 above.) */
4697a36c 11700
61b2fbe7
MM
11701#ifndef ABI_STACK_BOUNDARY
11702#define ABI_STACK_BOUNDARY STACK_BOUNDARY
11703#endif
11704
d1d0c603 11705static rs6000_stack_t *
863d938c 11706rs6000_stack_info (void)
4697a36c
MM
11707{
11708 static rs6000_stack_t info, zero_info;
11709 rs6000_stack_t *info_ptr = &info;
327e5343 11710 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 11711 int ehrd_size;
44688022 11712 HOST_WIDE_INT non_fixed_size;
4697a36c 11713
a4f6c312 11714 /* Zero all fields portably. */
4697a36c
MM
11715 info = zero_info;
11716
c19de7aa
AH
11717 if (TARGET_SPE)
11718 {
11719 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
11720 if (cfun->machine->insn_chain_scanned_p == 0)
11721 {
11722 cfun->machine->insn_chain_scanned_p = 1;
11723 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
11724 }
c19de7aa
AH
11725 }
11726
a4f6c312 11727 /* Select which calling sequence. */
178274da 11728 info_ptr->abi = DEFAULT_ABI;
9878760c 11729
a4f6c312 11730 /* Calculate which registers need to be saved & save area size. */
4697a36c 11731 info_ptr->first_gp_reg_save = first_reg_to_save ();
f676971a 11732 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 11733 even if it currently looks like we won't. */
2bfcf297 11734 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
11735 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
11736 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
11737 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
11738 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
11739 else
11740 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 11741
a3170dc6
AH
11742 /* For the SPE, we have an additional upper 32-bits on each GPR.
11743 Ideally we should save the entire 64-bits only when the upper
11744 half is used in SIMD instructions. Since we only record
11745 registers live (not the size they are used in), this proves
11746 difficult because we'd have to traverse the instruction chain at
11747 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
11748 so we opt to save the GPRs in 64-bits always if but one register
11749 gets used in 64-bits. Otherwise, all the registers in the frame
11750 get saved in 32-bits.
a3170dc6 11751
c19de7aa 11752 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 11753 traditional GP save area will be empty. */
c19de7aa 11754 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11755 info_ptr->gp_size = 0;
11756
4697a36c
MM
11757 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
11758 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
11759
00b960c7
AH
11760 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
11761 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
11762 - info_ptr->first_altivec_reg_save);
11763
592696dd 11764 /* Does this function call anything? */
71f123ca
FS
11765 info_ptr->calls_p = (! current_function_is_leaf
11766 || cfun->machine->ra_needs_full_frame);
b6c9286a 11767
a4f6c312 11768 /* Determine if we need to save the link register. */
71f123ca 11769 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
11770 || (DEFAULT_ABI == ABI_AIX
11771 && current_function_profile
11772 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
11773#ifdef TARGET_RELOCATABLE
11774 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
11775#endif
11776 || (info_ptr->first_fp_reg_save != 64
11777 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 11778 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 11779 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
11780 || (DEFAULT_ABI == ABI_DARWIN
11781 && flag_pic
11782 && current_function_uses_pic_offset_table)
4697a36c
MM
11783 || info_ptr->calls_p)
11784 {
11785 info_ptr->lr_save_p = 1;
9ebbca7d 11786 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
11787 }
11788
9ebbca7d 11789 /* Determine if we need to save the condition code registers. */
f676971a 11790 if (regs_ever_live[CR2_REGNO]
9ebbca7d
GK
11791 || regs_ever_live[CR3_REGNO]
11792 || regs_ever_live[CR4_REGNO])
4697a36c
MM
11793 {
11794 info_ptr->cr_save_p = 1;
178274da 11795 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
11796 info_ptr->cr_size = reg_size;
11797 }
11798
83720594
RH
11799 /* If the current function calls __builtin_eh_return, then we need
11800 to allocate stack space for registers that will hold data for
11801 the exception handler. */
11802 if (current_function_calls_eh_return)
11803 {
11804 unsigned int i;
11805 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
11806 continue;
a3170dc6
AH
11807
11808 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
11809 ehrd_size = i * (TARGET_SPE_ABI
11810 && info_ptr->spe_64bit_regs_used != 0
11811 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
11812 }
11813 else
11814 ehrd_size = 0;
11815
592696dd 11816 /* Determine various sizes. */
4697a36c
MM
11817 info_ptr->reg_size = reg_size;
11818 info_ptr->fixed_size = RS6000_SAVE_AREA;
11819 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 11820 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 11821 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 11822 TARGET_ALTIVEC ? 16 : 8);
00b960c7 11823
c19de7aa 11824 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11825 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
11826 else
11827 info_ptr->spe_gp_size = 0;
11828
4d774ff8
HP
11829 if (TARGET_ALTIVEC_ABI)
11830 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 11831 else
4d774ff8
HP
11832 info_ptr->vrsave_mask = 0;
11833
11834 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
11835 info_ptr->vrsave_size = 4;
11836 else
11837 info_ptr->vrsave_size = 0;
b6c9286a 11838
d62294f5
FJ
11839 compute_save_world_info (info_ptr);
11840
592696dd 11841 /* Calculate the offsets. */
178274da 11842 switch (DEFAULT_ABI)
4697a36c 11843 {
b6c9286a 11844 case ABI_NONE:
24d304eb 11845 default:
b6c9286a
MM
11846 abort ();
11847
11848 case ABI_AIX:
ee890fe2 11849 case ABI_DARWIN:
b6c9286a
MM
11850 info_ptr->fp_save_offset = - info_ptr->fp_size;
11851 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
11852
11853 if (TARGET_ALTIVEC_ABI)
11854 {
11855 info_ptr->vrsave_save_offset
11856 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
11857
11858 /* Align stack so vector save area is on a quadword boundary. */
11859 if (info_ptr->altivec_size != 0)
11860 info_ptr->altivec_padding_size
11861 = 16 - (-info_ptr->vrsave_save_offset % 16);
11862 else
11863 info_ptr->altivec_padding_size = 0;
11864
11865 info_ptr->altivec_save_offset
11866 = info_ptr->vrsave_save_offset
11867 - info_ptr->altivec_padding_size
11868 - info_ptr->altivec_size;
11869
11870 /* Adjust for AltiVec case. */
11871 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
11872 }
11873 else
11874 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
11875 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
11876 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
11877 break;
11878
11879 case ABI_V4:
b6c9286a
MM
11880 info_ptr->fp_save_offset = - info_ptr->fp_size;
11881 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 11882 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 11883
c19de7aa 11884 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11885 {
11886 /* Align stack so SPE GPR save area is aligned on a
11887 double-word boundary. */
11888 if (info_ptr->spe_gp_size != 0)
11889 info_ptr->spe_padding_size
11890 = 8 - (-info_ptr->cr_save_offset % 8);
11891 else
11892 info_ptr->spe_padding_size = 0;
11893
11894 info_ptr->spe_gp_save_offset
11895 = info_ptr->cr_save_offset
11896 - info_ptr->spe_padding_size
11897 - info_ptr->spe_gp_size;
11898
11899 /* Adjust for SPE case. */
11900 info_ptr->toc_save_offset
11901 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
11902 }
11903 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
11904 {
11905 info_ptr->vrsave_save_offset
11906 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
11907
11908 /* Align stack so vector save area is on a quadword boundary. */
11909 if (info_ptr->altivec_size != 0)
11910 info_ptr->altivec_padding_size
11911 = 16 - (-info_ptr->vrsave_save_offset % 16);
11912 else
11913 info_ptr->altivec_padding_size = 0;
11914
11915 info_ptr->altivec_save_offset
11916 = info_ptr->vrsave_save_offset
11917 - info_ptr->altivec_padding_size
11918 - info_ptr->altivec_size;
11919
11920 /* Adjust for AltiVec case. */
11921 info_ptr->toc_save_offset
11922 = info_ptr->altivec_save_offset - info_ptr->toc_size;
11923 }
11924 else
11925 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 11926 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
11927 info_ptr->lr_save_offset = reg_size;
11928 break;
4697a36c
MM
11929 }
11930
00b960c7
AH
11931 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
11932 + info_ptr->gp_size
11933 + info_ptr->altivec_size
11934 + info_ptr->altivec_padding_size
a3170dc6
AH
11935 + info_ptr->spe_gp_size
11936 + info_ptr->spe_padding_size
00b960c7
AH
11937 + ehrd_size
11938 + info_ptr->cr_size
11939 + info_ptr->lr_size
11940 + info_ptr->vrsave_size
11941 + info_ptr->toc_size,
11942 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
11943 ? 16 : 8);
11944
44688022 11945 non_fixed_size = (info_ptr->vars_size
ff381587 11946 + info_ptr->parm_size
ff381587 11947 + info_ptr->save_size
44688022 11948 + info_ptr->varargs_size);
ff381587 11949
44688022
AM
11950 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
11951 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
11952
11953 /* Determine if we need to allocate any stack frame:
11954
a4f6c312
SS
11955 For AIX we need to push the stack if a frame pointer is needed
11956 (because the stack might be dynamically adjusted), if we are
11957 debugging, if we make calls, or if the sum of fp_save, gp_save,
11958 and local variables are more than the space needed to save all
11959 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
11960 + 18*8 = 288 (GPR13 reserved).
ff381587 11961
a4f6c312
SS
11962 For V.4 we don't have the stack cushion that AIX uses, but assume
11963 that the debugger can handle stackless frames. */
ff381587
MM
11964
11965 if (info_ptr->calls_p)
11966 info_ptr->push_p = 1;
11967
178274da 11968 else if (DEFAULT_ABI == ABI_V4)
44688022 11969 info_ptr->push_p = non_fixed_size != 0;
ff381587 11970
178274da
AM
11971 else if (frame_pointer_needed)
11972 info_ptr->push_p = 1;
11973
11974 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
11975 info_ptr->push_p = 1;
11976
ff381587 11977 else
44688022 11978 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 11979
a4f6c312 11980 /* Zero offsets if we're not saving those registers. */
8dda1a21 11981 if (info_ptr->fp_size == 0)
4697a36c
MM
11982 info_ptr->fp_save_offset = 0;
11983
8dda1a21 11984 if (info_ptr->gp_size == 0)
4697a36c
MM
11985 info_ptr->gp_save_offset = 0;
11986
00b960c7
AH
11987 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
11988 info_ptr->altivec_save_offset = 0;
11989
11990 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
11991 info_ptr->vrsave_save_offset = 0;
11992
c19de7aa
AH
11993 if (! TARGET_SPE_ABI
11994 || info_ptr->spe_64bit_regs_used == 0
11995 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
11996 info_ptr->spe_gp_save_offset = 0;
11997
c81fc13e 11998 if (! info_ptr->lr_save_p)
4697a36c
MM
11999 info_ptr->lr_save_offset = 0;
12000
c81fc13e 12001 if (! info_ptr->cr_save_p)
4697a36c
MM
12002 info_ptr->cr_save_offset = 0;
12003
c81fc13e 12004 if (! info_ptr->toc_save_p)
b6c9286a
MM
12005 info_ptr->toc_save_offset = 0;
12006
4697a36c
MM
12007 return info_ptr;
12008}
12009
c19de7aa
AH
12010/* Return true if the current function uses any GPRs in 64-bit SIMD
12011 mode. */
12012
12013static bool
863d938c 12014spe_func_has_64bit_regs_p (void)
c19de7aa
AH
12015{
12016 rtx insns, insn;
12017
12018 /* Functions that save and restore all the call-saved registers will
12019 need to save/restore the registers in 64-bits. */
12020 if (current_function_calls_eh_return
12021 || current_function_calls_setjmp
12022 || current_function_has_nonlocal_goto)
12023 return true;
12024
12025 insns = get_insns ();
12026
12027 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
12028 {
12029 if (INSN_P (insn))
12030 {
12031 rtx i;
12032
12033 i = PATTERN (insn);
12034 if (GET_CODE (i) == SET
12035 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
12036 return true;
12037 }
12038 }
12039
12040 return false;
12041}
12042
d1d0c603 12043static void
a2369ed3 12044debug_stack_info (rs6000_stack_t *info)
9878760c 12045{
d330fd93 12046 const char *abi_string;
24d304eb 12047
c81fc13e 12048 if (! info)
4697a36c
MM
12049 info = rs6000_stack_info ();
12050
12051 fprintf (stderr, "\nStack information for function %s:\n",
12052 ((current_function_decl && DECL_NAME (current_function_decl))
12053 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
12054 : "<unknown>"));
12055
24d304eb
RK
12056 switch (info->abi)
12057 {
b6c9286a
MM
12058 default: abi_string = "Unknown"; break;
12059 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 12060 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 12061 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 12062 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
12063 }
12064
12065 fprintf (stderr, "\tABI = %5s\n", abi_string);
12066
00b960c7
AH
12067 if (TARGET_ALTIVEC_ABI)
12068 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
12069
a3170dc6
AH
12070 if (TARGET_SPE_ABI)
12071 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
12072
4697a36c
MM
12073 if (info->first_gp_reg_save != 32)
12074 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
12075
12076 if (info->first_fp_reg_save != 64)
12077 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 12078
00b960c7
AH
12079 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
12080 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
12081 info->first_altivec_reg_save);
12082
4697a36c
MM
12083 if (info->lr_save_p)
12084 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 12085
4697a36c
MM
12086 if (info->cr_save_p)
12087 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
12088
b6c9286a
MM
12089 if (info->toc_save_p)
12090 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
12091
00b960c7
AH
12092 if (info->vrsave_mask)
12093 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
12094
4697a36c
MM
12095 if (info->push_p)
12096 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
12097
12098 if (info->calls_p)
12099 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
12100
4697a36c
MM
12101 if (info->gp_save_offset)
12102 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
12103
12104 if (info->fp_save_offset)
12105 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
12106
00b960c7
AH
12107 if (info->altivec_save_offset)
12108 fprintf (stderr, "\taltivec_save_offset = %5d\n",
12109 info->altivec_save_offset);
12110
a3170dc6
AH
12111 if (info->spe_gp_save_offset)
12112 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
12113 info->spe_gp_save_offset);
12114
00b960c7
AH
12115 if (info->vrsave_save_offset)
12116 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
12117 info->vrsave_save_offset);
12118
4697a36c
MM
12119 if (info->lr_save_offset)
12120 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
12121
12122 if (info->cr_save_offset)
12123 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
12124
b6c9286a
MM
12125 if (info->toc_save_offset)
12126 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
12127
4697a36c
MM
12128 if (info->varargs_save_offset)
12129 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
12130
12131 if (info->total_size)
d1d0c603
JJ
12132 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12133 info->total_size);
4697a36c
MM
12134
12135 if (info->varargs_size)
12136 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
12137
12138 if (info->vars_size)
d1d0c603
JJ
12139 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12140 info->vars_size);
4697a36c
MM
12141
12142 if (info->parm_size)
12143 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
12144
12145 if (info->fixed_size)
12146 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
12147
12148 if (info->gp_size)
12149 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
12150
a3170dc6
AH
12151 if (info->spe_gp_size)
12152 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
12153
4697a36c
MM
12154 if (info->fp_size)
12155 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
12156
00b960c7
AH
12157 if (info->altivec_size)
12158 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
12159
12160 if (info->vrsave_size)
12161 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
12162
12163 if (info->altivec_padding_size)
12164 fprintf (stderr, "\taltivec_padding_size= %5d\n",
12165 info->altivec_padding_size);
12166
a3170dc6
AH
12167 if (info->spe_padding_size)
12168 fprintf (stderr, "\tspe_padding_size = %5d\n",
12169 info->spe_padding_size);
12170
a4f6c312 12171 if (info->lr_size)
ed947a96 12172 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 12173
4697a36c
MM
12174 if (info->cr_size)
12175 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
12176
a4f6c312 12177 if (info->toc_size)
b6c9286a
MM
12178 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
12179
4697a36c
MM
12180 if (info->save_size)
12181 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
12182
12183 if (info->reg_size != 4)
12184 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
12185
12186 fprintf (stderr, "\n");
9878760c 12187}
71f123ca
FS
12188
12189rtx
a2369ed3 12190rs6000_return_addr (int count, rtx frame)
71f123ca 12191{
a4f6c312
SS
12192 /* Currently we don't optimize very well between prolog and body
12193 code and for PIC code the code can be actually quite bad, so
12194 don't try to be too clever here. */
f1384257 12195 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
12196 {
12197 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
12198
12199 return
12200 gen_rtx_MEM
12201 (Pmode,
12202 memory_address
12203 (Pmode,
12204 plus_constant (copy_to_reg
12205 (gen_rtx_MEM (Pmode,
12206 memory_address (Pmode, frame))),
12207 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
12208 }
12209
8c29550d 12210 cfun->machine->ra_need_lr = 1;
9e2f7ec7 12211 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
12212}
12213
5e1bf043
DJ
12214/* Say whether a function is a candidate for sibcall handling or not.
12215 We do not allow indirect calls to be optimized into sibling calls.
12216 Also, we can't do it if there are any vector parameters; there's
12217 nowhere to put the VRsave code so it works; note that functions with
12218 vector parameters are required to have a prototype, so the argument
12219 type info must be available here. (The tail recursion case can work
12220 with vector parameters, but there's no way to distinguish here.) */
4977bab6 12221static bool
a2369ed3 12222rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
12223{
12224 tree type;
4977bab6 12225 if (decl)
5e1bf043
DJ
12226 {
12227 if (TARGET_ALTIVEC_VRSAVE)
12228 {
4977bab6 12229 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
12230 type; type = TREE_CHAIN (type))
12231 {
c15b529f 12232 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 12233 return false;
5e1bf043
DJ
12234 }
12235 }
12236 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 12237 || (*targetm.binds_local_p) (decl))
2bcc50d0 12238 {
4977bab6 12239 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
12240
12241 if (!lookup_attribute ("longcall", attr_list)
12242 || lookup_attribute ("shortcall", attr_list))
4977bab6 12243 return true;
2bcc50d0 12244 }
5e1bf043 12245 }
4977bab6 12246 return false;
5e1bf043
DJ
12247}
12248
71f123ca 12249static int
863d938c 12250rs6000_ra_ever_killed (void)
71f123ca
FS
12251{
12252 rtx top;
5e1bf043
DJ
12253 rtx reg;
12254 rtx insn;
71f123ca 12255
dd292d0a 12256 if (current_function_is_thunk)
71f123ca 12257 return 0;
eb0424da 12258
36f7e964
AH
12259 /* regs_ever_live has LR marked as used if any sibcalls are present,
12260 but this should not force saving and restoring in the
12261 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 12262 clobbers LR, so that is inappropriate. */
36f7e964 12263
5e1bf043
DJ
12264 /* Also, the prologue can generate a store into LR that
12265 doesn't really count, like this:
36f7e964 12266
5e1bf043
DJ
12267 move LR->R0
12268 bcl to set PIC register
12269 move LR->R31
12270 move R0->LR
36f7e964
AH
12271
12272 When we're called from the epilogue, we need to avoid counting
12273 this as a store. */
f676971a 12274
71f123ca
FS
12275 push_topmost_sequence ();
12276 top = get_insns ();
12277 pop_topmost_sequence ();
5e1bf043 12278 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 12279
5e1bf043
DJ
12280 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
12281 {
12282 if (INSN_P (insn))
12283 {
12284 if (FIND_REG_INC_NOTE (insn, reg))
12285 return 1;
f676971a 12286 else if (GET_CODE (insn) == CALL_INSN
c15b529f 12287 && !SIBLING_CALL_P (insn))
5e1bf043 12288 return 1;
36f7e964
AH
12289 else if (set_of (reg, insn) != NULL_RTX
12290 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
12291 return 1;
12292 }
12293 }
12294 return 0;
71f123ca 12295}
4697a36c 12296\f
8cd8f856
GK
12297/* Add a REG_MAYBE_DEAD note to the insn. */
12298static void
a2369ed3 12299rs6000_maybe_dead (rtx insn)
8cd8f856
GK
12300{
12301 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
12302 const0_rtx,
12303 REG_NOTES (insn));
12304}
12305
9ebbca7d 12306/* Emit instructions needed to load the TOC register.
c7ca610e 12307 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 12308 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
12309
12310void
a2369ed3 12311rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 12312{
027fbf43 12313 rtx dest, insn;
1db02437 12314 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 12315
20b71b17
AM
12316 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
12317 {
12318 rtx temp = (fromprolog
12319 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12320 : gen_reg_rtx (Pmode));
027fbf43
JJ
12321 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
12322 if (fromprolog)
12323 rs6000_maybe_dead (insn);
12324 insn = emit_move_insn (dest, temp);
12325 if (fromprolog)
12326 rs6000_maybe_dead (insn);
20b71b17
AM
12327 }
12328 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
12329 {
12330 char buf[30];
12331 rtx tempLR = (fromprolog
12332 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12333 : gen_reg_rtx (Pmode));
12334 rtx temp0 = (fromprolog
12335 ? gen_rtx_REG (Pmode, 0)
12336 : gen_reg_rtx (Pmode));
12337 rtx symF;
12338
12339 /* possibly create the toc section */
12340 if (! toc_initialized)
38c1f2d7 12341 {
20b71b17
AM
12342 toc_section ();
12343 function_section (current_function_decl);
38c1f2d7 12344 }
9ebbca7d 12345
20b71b17
AM
12346 if (fromprolog)
12347 {
12348 rtx symL;
38c1f2d7 12349
20b71b17
AM
12350 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
12351 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 12352
20b71b17
AM
12353 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
12354 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12355
12356 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
12357 symF)));
12358 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
12359 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
12360 symL,
12361 symF)));
9ebbca7d
GK
12362 }
12363 else
20b71b17
AM
12364 {
12365 rtx tocsym;
12366 static int reload_toc_labelno = 0;
12367
12368 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
12369
12370 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
12371 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12372
027fbf43
JJ
12373 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
12374 emit_move_insn (dest, tempLR);
12375 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 12376 }
027fbf43
JJ
12377 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
12378 if (fromprolog)
12379 rs6000_maybe_dead (insn);
9ebbca7d 12380 }
20b71b17
AM
12381 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
12382 {
12383 /* This is for AIX code running in non-PIC ELF32. */
12384 char buf[30];
12385 rtx realsym;
12386 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
12387 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12388
027fbf43
JJ
12389 insn = emit_insn (gen_elf_high (dest, realsym));
12390 if (fromprolog)
12391 rs6000_maybe_dead (insn);
12392 insn = emit_insn (gen_elf_low (dest, dest, realsym));
12393 if (fromprolog)
12394 rs6000_maybe_dead (insn);
20b71b17
AM
12395 }
12396 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
12397 {
12398 if (TARGET_32BIT)
027fbf43 12399 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 12400 else
027fbf43
JJ
12401 insn = emit_insn (gen_load_toc_aix_di (dest));
12402 if (fromprolog)
12403 rs6000_maybe_dead (insn);
9ebbca7d 12404 }
20b71b17
AM
12405 else
12406 abort ();
9ebbca7d
GK
12407}
12408
d1d0c603
JJ
12409/* Emit instructions to restore the link register after determining where
12410 its value has been stored. */
12411
12412void
12413rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
12414{
12415 rs6000_stack_t *info = rs6000_stack_info ();
12416 rtx operands[2];
12417
12418 operands[0] = source;
12419 operands[1] = scratch;
12420
12421 if (info->lr_save_p)
12422 {
12423 rtx frame_rtx = stack_pointer_rtx;
12424 HOST_WIDE_INT sp_offset = 0;
12425 rtx tmp;
12426
12427 if (frame_pointer_needed
12428 || current_function_calls_alloca
12429 || info->total_size > 32767)
12430 {
12431 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
12432 frame_rtx = operands[1];
12433 }
12434 else if (info->push_p)
12435 sp_offset = info->total_size;
12436
12437 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
12438 tmp = gen_rtx_MEM (Pmode, tmp);
12439 emit_move_insn (tmp, operands[0]);
12440 }
12441 else
12442 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
12443}
12444
f103e34d
GK
12445static GTY(()) int set = -1;
12446
f676971a 12447int
863d938c 12448get_TOC_alias_set (void)
9ebbca7d 12449{
f103e34d
GK
12450 if (set == -1)
12451 set = new_alias_set ();
12452 return set;
f676971a 12453}
9ebbca7d 12454
c1207243 12455/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
12456 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
12457 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 12458#if TARGET_ELF
3c9eb5f4 12459static int
f676971a 12460uses_TOC (void)
9ebbca7d 12461{
c4501e62 12462 rtx insn;
38c1f2d7 12463
c4501e62
JJ
12464 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
12465 if (INSN_P (insn))
12466 {
12467 rtx pat = PATTERN (insn);
12468 int i;
9ebbca7d 12469
f676971a 12470 if (GET_CODE (pat) == PARALLEL)
c4501e62
JJ
12471 for (i = 0; i < XVECLEN (pat, 0); i++)
12472 {
12473 rtx sub = XVECEXP (pat, 0, i);
12474 if (GET_CODE (sub) == USE)
12475 {
12476 sub = XEXP (sub, 0);
12477 if (GET_CODE (sub) == UNSPEC
12478 && XINT (sub, 1) == UNSPEC_TOC)
12479 return 1;
12480 }
12481 }
12482 }
12483 return 0;
9ebbca7d 12484}
c954844a 12485#endif
38c1f2d7 12486
9ebbca7d 12487rtx
f676971a 12488create_TOC_reference (rtx symbol)
9ebbca7d 12489{
f676971a 12490 return gen_rtx_PLUS (Pmode,
a8a05998 12491 gen_rtx_REG (Pmode, TOC_REGISTER),
f676971a
EC
12492 gen_rtx_CONST (Pmode,
12493 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 12494 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 12495}
38c1f2d7 12496
fc4767bb
JJ
12497/* If _Unwind_* has been called from within the same module,
12498 toc register is not guaranteed to be saved to 40(1) on function
12499 entry. Save it there in that case. */
c7ca610e 12500
9ebbca7d 12501void
863d938c 12502rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
12503{
12504 rtx mem;
12505 rtx stack_top = gen_reg_rtx (Pmode);
12506 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
12507 rtx opcode = gen_reg_rtx (SImode);
12508 rtx tocompare = gen_reg_rtx (SImode);
12509 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
12510
12511 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
12512 emit_move_insn (stack_top, mem);
12513
fc4767bb
JJ
12514 mem = gen_rtx_MEM (Pmode,
12515 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
12516 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
12517 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
12518 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
12519 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 12520 : 0xE8410028, SImode));
9ebbca7d 12521
fc4767bb 12522 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 12523 SImode, NULL_RTX, NULL_RTX,
fc4767bb 12524 no_toc_save_needed);
9ebbca7d 12525
fc4767bb
JJ
12526 mem = gen_rtx_MEM (Pmode,
12527 gen_rtx_PLUS (Pmode, stack_top,
12528 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
12529 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
12530 emit_label (no_toc_save_needed);
9ebbca7d 12531}
38c1f2d7 12532\f
ba4828e0
RK
12533/* This ties together stack memory (MEM with an alias set of
12534 rs6000_sr_alias_set) and the change to the stack pointer. */
12535
9ebbca7d 12536static void
863d938c 12537rs6000_emit_stack_tie (void)
9ebbca7d 12538{
ba4828e0
RK
12539 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
12540
12541 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12542 emit_insn (gen_stack_tie (mem));
12543}
38c1f2d7 12544
9ebbca7d
GK
12545/* Emit the correct code for allocating stack space, as insns.
12546 If COPY_R12, make sure a copy of the old frame is left in r12.
12547 The generated code may use hard register 0 as a temporary. */
12548
12549static void
a2369ed3 12550rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 12551{
9ebbca7d
GK
12552 rtx insn;
12553 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12554 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
12555 rtx todec = GEN_INT (-size);
a157febd
GK
12556
12557 if (current_function_limit_stack)
12558 {
12559 if (REG_P (stack_limit_rtx)
f676971a 12560 && REGNO (stack_limit_rtx) > 1
a157febd
GK
12561 && REGNO (stack_limit_rtx) <= 31)
12562 {
5b71a4e7 12563 emit_insn (TARGET_32BIT
9ebbca7d
GK
12564 ? gen_addsi3 (tmp_reg,
12565 stack_limit_rtx,
12566 GEN_INT (size))
12567 : gen_adddi3 (tmp_reg,
12568 stack_limit_rtx,
12569 GEN_INT (size)));
5b71a4e7 12570
9ebbca7d
GK
12571 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
12572 const0_rtx));
a157febd
GK
12573 }
12574 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 12575 && TARGET_32BIT
f607bc57 12576 && DEFAULT_ABI == ABI_V4)
a157febd 12577 {
9ebbca7d 12578 rtx toload = gen_rtx_CONST (VOIDmode,
f676971a
EC
12579 gen_rtx_PLUS (Pmode,
12580 stack_limit_rtx,
9ebbca7d 12581 GEN_INT (size)));
5b71a4e7 12582
9ebbca7d
GK
12583 emit_insn (gen_elf_high (tmp_reg, toload));
12584 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
12585 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
12586 const0_rtx));
a157febd
GK
12587 }
12588 else
12589 warning ("stack limit expression is not supported");
12590 }
12591
9ebbca7d
GK
12592 if (copy_r12 || ! TARGET_UPDATE)
12593 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
12594
38c1f2d7
MM
12595 if (TARGET_UPDATE)
12596 {
9ebbca7d 12597 if (size > 32767)
38c1f2d7 12598 {
9ebbca7d
GK
12599 /* Need a note here so that try_split doesn't get confused. */
12600 if (get_last_insn() == NULL_RTX)
2e040219 12601 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
12602 insn = emit_move_insn (tmp_reg, todec);
12603 try_split (PATTERN (insn), insn, 0);
12604 todec = tmp_reg;
38c1f2d7 12605 }
5b71a4e7
DE
12606
12607 insn = emit_insn (TARGET_32BIT
12608 ? gen_movsi_update (stack_reg, stack_reg,
12609 todec, stack_reg)
2e6c9641 12610 : gen_movdi_di_update (stack_reg, stack_reg,
9ebbca7d 12611 todec, stack_reg));
38c1f2d7
MM
12612 }
12613 else
12614 {
5b71a4e7
DE
12615 insn = emit_insn (TARGET_32BIT
12616 ? gen_addsi3 (stack_reg, stack_reg, todec)
12617 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
12618 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
12619 gen_rtx_REG (Pmode, 12));
12620 }
f676971a 12621
9ebbca7d 12622 RTX_FRAME_RELATED_P (insn) = 1;
f676971a 12623 REG_NOTES (insn) =
9ebbca7d 12624 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
f676971a 12625 gen_rtx_SET (VOIDmode, stack_reg,
9ebbca7d
GK
12626 gen_rtx_PLUS (Pmode, stack_reg,
12627 GEN_INT (-size))),
12628 REG_NOTES (insn));
12629}
12630
a4f6c312
SS
12631/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
12632 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
12633 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
12634 deduce these equivalences by itself so it wasn't necessary to hold
12635 its hand so much. */
9ebbca7d
GK
12636
12637static void
f676971a 12638rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
a2369ed3 12639 rtx reg2, rtx rreg)
9ebbca7d
GK
12640{
12641 rtx real, temp;
12642
e56c4463
JL
12643 /* copy_rtx will not make unique copies of registers, so we need to
12644 ensure we don't have unwanted sharing here. */
12645 if (reg == reg2)
12646 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
12647
12648 if (reg == rreg)
12649 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
12650
9ebbca7d
GK
12651 real = copy_rtx (PATTERN (insn));
12652
89e7058f
AH
12653 if (reg2 != NULL_RTX)
12654 real = replace_rtx (real, reg2, rreg);
f676971a
EC
12655
12656 real = replace_rtx (real, reg,
9ebbca7d
GK
12657 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
12658 STACK_POINTER_REGNUM),
12659 GEN_INT (val)));
f676971a 12660
9ebbca7d
GK
12661 /* We expect that 'real' is either a SET or a PARALLEL containing
12662 SETs (and possibly other stuff). In a PARALLEL, all the SETs
12663 are important so they all have to be marked RTX_FRAME_RELATED_P. */
12664
12665 if (GET_CODE (real) == SET)
12666 {
12667 rtx set = real;
f676971a 12668
9ebbca7d
GK
12669 temp = simplify_rtx (SET_SRC (set));
12670 if (temp)
12671 SET_SRC (set) = temp;
12672 temp = simplify_rtx (SET_DEST (set));
12673 if (temp)
12674 SET_DEST (set) = temp;
12675 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 12676 {
9ebbca7d
GK
12677 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
12678 if (temp)
12679 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 12680 }
38c1f2d7 12681 }
9ebbca7d
GK
12682 else if (GET_CODE (real) == PARALLEL)
12683 {
12684 int i;
12685 for (i = 0; i < XVECLEN (real, 0); i++)
12686 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
12687 {
12688 rtx set = XVECEXP (real, 0, i);
f676971a 12689
9ebbca7d
GK
12690 temp = simplify_rtx (SET_SRC (set));
12691 if (temp)
12692 SET_SRC (set) = temp;
12693 temp = simplify_rtx (SET_DEST (set));
12694 if (temp)
12695 SET_DEST (set) = temp;
12696 if (GET_CODE (SET_DEST (set)) == MEM)
12697 {
12698 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
12699 if (temp)
12700 XEXP (SET_DEST (set), 0) = temp;
12701 }
12702 RTX_FRAME_RELATED_P (set) = 1;
12703 }
12704 }
12705 else
a4f6c312 12706 abort ();
c19de7aa
AH
12707
12708 if (TARGET_SPE)
12709 real = spe_synthesize_frame_save (real);
12710
9ebbca7d
GK
12711 RTX_FRAME_RELATED_P (insn) = 1;
12712 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
12713 real,
12714 REG_NOTES (insn));
38c1f2d7
MM
12715}
12716
c19de7aa
AH
12717/* Given an SPE frame note, return a PARALLEL of SETs with the
12718 original note, plus a synthetic register save. */
12719
12720static rtx
a2369ed3 12721spe_synthesize_frame_save (rtx real)
c19de7aa
AH
12722{
12723 rtx synth, offset, reg, real2;
12724
12725 if (GET_CODE (real) != SET
12726 || GET_MODE (SET_SRC (real)) != V2SImode)
12727 return real;
12728
12729 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
12730 frame related note. The parallel contains a set of the register
41f3a930 12731 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
12732 This is so we can differentiate between 64-bit and 32-bit saves.
12733 Words cannot describe this nastiness. */
12734
12735 if (GET_CODE (SET_DEST (real)) != MEM
12736 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
12737 || GET_CODE (SET_SRC (real)) != REG)
12738 abort ();
12739
12740 /* Transform:
12741 (set (mem (plus (reg x) (const y)))
12742 (reg z))
12743 into:
12744 (set (mem (plus (reg x) (const y+4)))
41f3a930 12745 (reg z+1200))
c19de7aa
AH
12746 */
12747
12748 real2 = copy_rtx (real);
12749 PUT_MODE (SET_DEST (real2), SImode);
12750 reg = SET_SRC (real2);
12751 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
12752 synth = copy_rtx (real2);
12753
12754 if (BYTES_BIG_ENDIAN)
12755 {
12756 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
12757 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
12758 }
12759
12760 reg = SET_SRC (synth);
41f3a930 12761
c19de7aa 12762 synth = replace_rtx (synth, reg,
41f3a930 12763 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
12764
12765 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
12766 synth = replace_rtx (synth, offset,
12767 GEN_INT (INTVAL (offset)
12768 + (BYTES_BIG_ENDIAN ? 0 : 4)));
12769
12770 RTX_FRAME_RELATED_P (synth) = 1;
12771 RTX_FRAME_RELATED_P (real2) = 1;
12772 if (BYTES_BIG_ENDIAN)
12773 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
12774 else
12775 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
12776
12777 return real;
12778}
12779
00b960c7
AH
12780/* Returns an insn that has a vrsave set operation with the
12781 appropriate CLOBBERs. */
12782
12783static rtx
a2369ed3 12784generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
12785{
12786 int nclobs, i;
12787 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 12788 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 12789
a004eb82
AH
12790 clobs[0]
12791 = gen_rtx_SET (VOIDmode,
12792 vrsave,
12793 gen_rtx_UNSPEC_VOLATILE (SImode,
12794 gen_rtvec (2, reg, vrsave),
12795 30));
00b960c7
AH
12796
12797 nclobs = 1;
12798
9aa86737
AH
12799 /* We need to clobber the registers in the mask so the scheduler
12800 does not move sets to VRSAVE before sets of AltiVec registers.
12801
12802 However, if the function receives nonlocal gotos, reload will set
12803 all call saved registers live. We will end up with:
12804
12805 (set (reg 999) (mem))
12806 (parallel [ (set (reg vrsave) (unspec blah))
12807 (clobber (reg 999))])
12808
12809 The clobber will cause the store into reg 999 to be dead, and
12810 flow will attempt to delete an epilogue insn. In this case, we
12811 need an unspec use/set of the register. */
00b960c7
AH
12812
12813 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
44688022 12814 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
9aa86737
AH
12815 {
12816 if (!epiloguep || call_used_regs [i])
12817 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
12818 gen_rtx_REG (V4SImode, i));
12819 else
12820 {
12821 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
12822
12823 clobs[nclobs++]
a004eb82
AH
12824 = gen_rtx_SET (VOIDmode,
12825 reg,
12826 gen_rtx_UNSPEC (V4SImode,
12827 gen_rtvec (1, reg), 27));
9aa86737
AH
12828 }
12829 }
00b960c7
AH
12830
12831 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
12832
12833 for (i = 0; i < nclobs; ++i)
12834 XVECEXP (insn, 0, i) = clobs[i];
12835
12836 return insn;
12837}
12838
89e7058f
AH
12839/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
12840 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
12841
12842static void
f676971a 12843emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 12844 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
12845{
12846 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
12847 rtx replacea, replaceb;
12848
12849 int_rtx = GEN_INT (offset);
12850
12851 /* Some cases that need register indexed addressing. */
12852 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
12853 || (TARGET_SPE_ABI
12854 && SPE_VECTOR_MODE (mode)
12855 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
12856 {
12857 /* Whomever calls us must make sure r11 is available in the
12858 flow path of instructions in the prologue. */
12859 offset_rtx = gen_rtx_REG (Pmode, 11);
12860 emit_move_insn (offset_rtx, int_rtx);
12861
12862 replacea = offset_rtx;
12863 replaceb = int_rtx;
12864 }
12865 else
12866 {
12867 offset_rtx = int_rtx;
12868 replacea = NULL_RTX;
12869 replaceb = NULL_RTX;
12870 }
12871
12872 reg = gen_rtx_REG (mode, regno);
12873 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
12874 mem = gen_rtx_MEM (mode, addr);
12875 set_mem_alias_set (mem, rs6000_sr_alias_set);
12876
12877 insn = emit_move_insn (mem, reg);
12878
12879 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
12880}
12881
a3170dc6
AH
12882/* Emit an offset memory reference suitable for a frame store, while
12883 converting to a valid addressing mode. */
12884
12885static rtx
a2369ed3 12886gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
12887{
12888 rtx int_rtx, offset_rtx;
12889
12890 int_rtx = GEN_INT (offset);
12891
12892 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
12893 {
12894 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12895 emit_move_insn (offset_rtx, int_rtx);
12896 }
12897 else
12898 offset_rtx = int_rtx;
12899
12900 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
12901}
12902
699c914a
MS
12903#ifndef TARGET_FIX_AND_CONTINUE
12904#define TARGET_FIX_AND_CONTINUE 0
12905#endif
12906
9ebbca7d
GK
12907/* Emit function prologue as insns. */
12908
9878760c 12909void
863d938c 12910rs6000_emit_prologue (void)
9878760c 12911{
4697a36c 12912 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 12913 enum machine_mode reg_mode = Pmode;
327e5343 12914 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12915 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12916 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
12917 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 12918 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
12919 rtx insn;
12920 int saving_FPRs_inline;
12921 int using_store_multiple;
12922 HOST_WIDE_INT sp_offset = 0;
f676971a 12923
699c914a
MS
12924 if (TARGET_FIX_AND_CONTINUE)
12925 {
12926 /* gdb on darwin arranges to forward a function from the old
12927 address by modifying the first 4 instructions of the function
12928 to branch to the overriding function. This is necessary to
12929 permit function pointers that point to the old function to
12930 actually forward to the new function. */
12931 emit_insn (gen_nop ());
12932 emit_insn (gen_nop ());
12933 emit_insn (gen_nop ());
12934 emit_insn (gen_nop ());
12935 }
12936
12937 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
12938 {
12939 reg_mode = V2SImode;
12940 reg_size = 8;
12941 }
a3170dc6 12942
9ebbca7d 12943 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12944 && (!TARGET_SPE_ABI
12945 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12946 && info->first_gp_reg_save < 31);
12947 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 12948 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 12949 || current_function_calls_eh_return
8c29550d 12950 || cfun->machine->ra_need_lr);
9ebbca7d
GK
12951
12952 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 12953 if (info->push_p
acd0b319
AM
12954 && (DEFAULT_ABI == ABI_V4
12955 || current_function_calls_eh_return))
9ebbca7d
GK
12956 {
12957 if (info->total_size < 32767)
12958 sp_offset = info->total_size;
12959 else
12960 frame_reg_rtx = frame_ptr_rtx;
f676971a 12961 rs6000_emit_allocate_stack (info->total_size,
9ebbca7d
GK
12962 (frame_reg_rtx != sp_reg_rtx
12963 && (info->cr_save_p
12964 || info->lr_save_p
12965 || info->first_fp_reg_save < 64
12966 || info->first_gp_reg_save < 32
12967 )));
12968 if (frame_reg_rtx != sp_reg_rtx)
12969 rs6000_emit_stack_tie ();
12970 }
12971
d62294f5
FJ
12972 /* Handle world saves specially here. */
12973 if (info->world_save_p)
12974 {
12975 int i, j, sz;
12976 rtx treg;
12977 rtvec p;
12978
12979 /* save_world expects lr in r0. */
12980 if (info->lr_save_p)
12981 {
12982 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
12983 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12984 RTX_FRAME_RELATED_P (insn) = 1;
12985 }
12986
12987 /* The SAVE_WORLD and RESTORE_WORLD routines make a number of
12988 assumptions about the offsets of various bits of the stack
12989 frame. Abort if things aren't what they should be. */
12990 if (info->gp_save_offset != -220
12991 || info->fp_save_offset != -144
12992 || info->lr_save_offset != 8
12993 || info->cr_save_offset != 4
12994 || !info->push_p
12995 || !info->lr_save_p
12996 || (current_function_calls_eh_return && info->ehrd_offset != -432)
12997 || (info->vrsave_save_offset != -224
12998 || info->altivec_save_offset != (-224 -16 -192)))
12999 abort ();
13000
13001 treg = gen_rtx_REG (SImode, 11);
13002 emit_move_insn (treg, GEN_INT (-info->total_size));
13003
13004 /* SAVE_WORLD takes the caller's LR in R0 and the frame size
13005 in R11. It also clobbers R12, so beware! */
13006
13007 /* Preserve CR2 for save_world prologues */
13008 sz = 6;
13009 sz += 32 - info->first_gp_reg_save;
13010 sz += 64 - info->first_fp_reg_save;
13011 sz += LAST_ALTIVEC_REGNO - info->first_altivec_reg_save + 1;
13012 p = rtvec_alloc (sz);
13013 j = 0;
13014 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode,
13015 gen_rtx_REG (Pmode,
13016 LINK_REGISTER_REGNUM));
13017 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
13018 gen_rtx_SYMBOL_REF (Pmode,
13019 "*save_world"));
13020 /* We do floats first so that the instruction pattern matches
13021 properly. */
13022 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13023 {
13024 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13025 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13026 GEN_INT (info->fp_save_offset
13027 + sp_offset + 8 * i));
13028 rtx mem = gen_rtx_MEM (DFmode, addr);
13029 set_mem_alias_set (mem, rs6000_sr_alias_set);
13030
13031 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13032 }
13033 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
13034 {
13035 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
13036 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13037 GEN_INT (info->altivec_save_offset
13038 + sp_offset + 16 * i));
13039 rtx mem = gen_rtx_MEM (V4SImode, addr);
13040 set_mem_alias_set (mem, rs6000_sr_alias_set);
13041
13042 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13043 }
13044 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13045 {
13046 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13047 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13048 GEN_INT (info->gp_save_offset
13049 + sp_offset + reg_size * i));
13050 rtx mem = gen_rtx_MEM (reg_mode, addr);
13051 set_mem_alias_set (mem, rs6000_sr_alias_set);
13052
13053 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13054 }
13055
13056 {
13057 /* CR register traditionally saved as CR2. */
13058 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
13059 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13060 GEN_INT (info->cr_save_offset
13061 + sp_offset));
13062 rtx mem = gen_rtx_MEM (reg_mode, addr);
13063 set_mem_alias_set (mem, rs6000_sr_alias_set);
13064
13065 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13066 }
13067 /* Prevent any attempt to delete the setting of r0 and treg! */
13068 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, 0));
13069 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, treg);
13070 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode, sp_reg_rtx);
13071
13072 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
13073 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13074 NULL_RTX, NULL_RTX);
13075
13076 if (current_function_calls_eh_return)
13077 {
13078 unsigned int i;
13079 for (i = 0; ; ++i)
13080 {
13081 unsigned int regno = EH_RETURN_DATA_REGNO (i);
13082 if (regno == INVALID_REGNUM)
13083 break;
13084 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13085 info->ehrd_offset + sp_offset
13086 + reg_size * (int) i,
13087 info->total_size);
13088 }
13089 }
13090 }
13091
9aa86737 13092 /* Save AltiVec registers if needed. */
d62294f5 13093 if (! info->world_save_p && TARGET_ALTIVEC_ABI && info->altivec_size != 0)
9aa86737
AH
13094 {
13095 int i;
13096
13097 /* There should be a non inline version of this, for when we
13098 are saving lots of vector registers. */
13099 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
13100 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
13101 {
13102 rtx areg, savereg, mem;
13103 int offset;
13104
13105 offset = info->altivec_save_offset + sp_offset
13106 + 16 * (i - info->first_altivec_reg_save);
13107
13108 savereg = gen_rtx_REG (V4SImode, i);
13109
13110 areg = gen_rtx_REG (Pmode, 0);
13111 emit_move_insn (areg, GEN_INT (offset));
13112
13113 /* AltiVec addressing mode is [reg+reg]. */
13114 mem = gen_rtx_MEM (V4SImode,
13115 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
f676971a 13116
9aa86737
AH
13117 set_mem_alias_set (mem, rs6000_sr_alias_set);
13118
13119 insn = emit_move_insn (mem, savereg);
13120
5c242421
SB
13121 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13122 areg, GEN_INT (offset));
9aa86737
AH
13123 }
13124 }
13125
13126 /* VRSAVE is a bit vector representing which AltiVec registers
13127 are used. The OS uses this to determine which vector
13128 registers to save on a context switch. We need to save
13129 VRSAVE on the stack frame, add whatever AltiVec registers we
13130 used in this function, and do the corresponding magic in the
13131 epilogue. */
13132
4d774ff8 13133 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
d62294f5 13134 && ! info->world_save_p && info->vrsave_mask != 0)
9aa86737 13135 {
a004eb82 13136 rtx reg, mem, vrsave;
9aa86737
AH
13137 int offset;
13138
13139 /* Get VRSAVE onto a GPR. */
13140 reg = gen_rtx_REG (SImode, 12);
a004eb82 13141 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
13142 if (TARGET_MACHO)
13143 emit_insn (gen_get_vrsave_internal (reg));
13144 else
13145 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
13146
13147 /* Save VRSAVE. */
13148 offset = info->vrsave_save_offset + sp_offset;
13149 mem
13150 = gen_rtx_MEM (SImode,
13151 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
13152 set_mem_alias_set (mem, rs6000_sr_alias_set);
13153 insn = emit_move_insn (mem, reg);
13154
13155 /* Include the registers in the mask. */
13156 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
13157
13158 insn = emit_insn (generate_set_vrsave (reg, info, 0));
13159 }
13160
9ebbca7d 13161 /* If we use the link register, get it into r0. */
d62294f5 13162 if (! info->world_save_p && info->lr_save_p)
f8a57be8
GK
13163 {
13164 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13165 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13166 RTX_FRAME_RELATED_P (insn) = 1;
13167 }
9ebbca7d
GK
13168
13169 /* If we need to save CR, put it into r12. */
d62294f5 13170 if (! info->world_save_p && info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
9ebbca7d 13171 {
f8a57be8 13172 rtx set;
f676971a 13173
9ebbca7d 13174 cr_save_rtx = gen_rtx_REG (SImode, 12);
f8a57be8
GK
13175 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13176 RTX_FRAME_RELATED_P (insn) = 1;
13177 /* Now, there's no way that dwarf2out_frame_debug_expr is going
13178 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
13179 But that's OK. All we have to do is specify that _one_ condition
13180 code register is saved in this stack slot. The thrower's epilogue
13181 will then restore all the call-saved registers.
13182 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
13183 set = gen_rtx_SET (VOIDmode, cr_save_rtx,
13184 gen_rtx_REG (SImode, CR2_REGNO));
13185 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13186 set,
13187 REG_NOTES (insn));
9ebbca7d
GK
13188 }
13189
a4f6c312
SS
13190 /* Do any required saving of fpr's. If only one or two to save, do
13191 it ourselves. Otherwise, call function. */
d62294f5 13192 if (! info->world_save_p && saving_FPRs_inline)
9ebbca7d
GK
13193 {
13194 int i;
13195 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 13196 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d 13197 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
13198 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
13199 info->first_fp_reg_save + i,
13200 info->fp_save_offset + sp_offset + 8 * i,
13201 info->total_size);
9ebbca7d 13202 }
d62294f5 13203 else if (! info->world_save_p && info->first_fp_reg_save != 64)
9ebbca7d
GK
13204 {
13205 int i;
13206 char rname[30];
520a57c8 13207 const char *alloc_rname;
9ebbca7d
GK
13208 rtvec p;
13209 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
f676971a
EC
13210
13211 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
13212 gen_rtx_REG (Pmode,
9ebbca7d
GK
13213 LINK_REGISTER_REGNUM));
13214 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
13215 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 13216 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
13217 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
13218 gen_rtx_SYMBOL_REF (Pmode,
13219 alloc_rname));
13220 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13221 {
13222 rtx addr, reg, mem;
13223 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13224 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a 13225 GEN_INT (info->fp_save_offset
9ebbca7d
GK
13226 + sp_offset + 8*i));
13227 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 13228 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13229
13230 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
13231 }
13232 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13233 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d
GK
13234 NULL_RTX, NULL_RTX);
13235 }
b6c9286a 13236
9ebbca7d
GK
13237 /* Save GPRs. This is done as a PARALLEL if we are using
13238 the store-multiple instructions. */
d62294f5 13239 if (! info->world_save_p && using_store_multiple)
b6c9286a 13240 {
308c142a 13241 rtvec p;
9ebbca7d
GK
13242 int i;
13243 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
13244 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13245 {
13246 rtx addr, reg, mem;
13247 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
f676971a
EC
13248 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13249 GEN_INT (info->gp_save_offset
13250 + sp_offset
9ebbca7d
GK
13251 + reg_size * i));
13252 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 13253 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13254
13255 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
13256 }
13257 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13258 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d 13259 NULL_RTX, NULL_RTX);
b6c9286a 13260 }
d62294f5 13261 else if (! info->world_save_p)
b6c9286a 13262 {
9ebbca7d
GK
13263 int i;
13264 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 13265 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
13266 && (! call_used_regs[info->first_gp_reg_save+i]
13267 || (i+info->first_gp_reg_save
13268 == RS6000_PIC_OFFSET_TABLE_REGNUM
13269 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 13270 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 13271 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 13272 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
13273 {
13274 rtx addr, reg, mem;
13275 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13276
c19de7aa 13277 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13278 {
13279 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
13280 rtx b;
13281
13282 if (!SPE_CONST_OFFSET_OK (offset))
13283 {
13284 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13285 emit_move_insn (b, GEN_INT (offset));
13286 }
13287 else
13288 b = GEN_INT (offset);
13289
13290 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
13291 mem = gen_rtx_MEM (V2SImode, addr);
13292 set_mem_alias_set (mem, rs6000_sr_alias_set);
13293 insn = emit_move_insn (mem, reg);
13294
13295 if (GET_CODE (b) == CONST_INT)
13296 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13297 NULL_RTX, NULL_RTX);
13298 else
13299 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13300 b, GEN_INT (offset));
13301 }
13302 else
13303 {
f676971a
EC
13304 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13305 GEN_INT (info->gp_save_offset
13306 + sp_offset
a3170dc6
AH
13307 + reg_size * i));
13308 mem = gen_rtx_MEM (reg_mode, addr);
13309 set_mem_alias_set (mem, rs6000_sr_alias_set);
13310
13311 insn = emit_move_insn (mem, reg);
f676971a 13312 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a3170dc6
AH
13313 NULL_RTX, NULL_RTX);
13314 }
13315 }
9ebbca7d
GK
13316 }
13317
83720594
RH
13318 /* ??? There's no need to emit actual instructions here, but it's the
13319 easiest way to get the frame unwind information emitted. */
d62294f5 13320 if (! info->world_save_p && current_function_calls_eh_return)
83720594 13321 {
78e1b90d
DE
13322 unsigned int i, regno;
13323
fc4767bb
JJ
13324 /* In AIX ABI we need to pretend we save r2 here. */
13325 if (TARGET_AIX)
13326 {
13327 rtx addr, reg, mem;
13328
13329 reg = gen_rtx_REG (reg_mode, 2);
13330 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13331 GEN_INT (sp_offset + 5 * reg_size));
13332 mem = gen_rtx_MEM (reg_mode, addr);
13333 set_mem_alias_set (mem, rs6000_sr_alias_set);
13334
13335 insn = emit_move_insn (mem, reg);
f676971a 13336 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
fc4767bb
JJ
13337 NULL_RTX, NULL_RTX);
13338 PATTERN (insn) = gen_blockage ();
13339 }
13340
83720594
RH
13341 for (i = 0; ; ++i)
13342 {
83720594
RH
13343 regno = EH_RETURN_DATA_REGNO (i);
13344 if (regno == INVALID_REGNUM)
13345 break;
13346
89e7058f
AH
13347 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13348 info->ehrd_offset + sp_offset
13349 + reg_size * (int) i,
13350 info->total_size);
83720594
RH
13351 }
13352 }
13353
9ebbca7d 13354 /* Save lr if we used it. */
d62294f5 13355 if (! info->world_save_p && info->lr_save_p)
9ebbca7d
GK
13356 {
13357 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13358 GEN_INT (info->lr_save_offset + sp_offset));
13359 rtx reg = gen_rtx_REG (Pmode, 0);
13360 rtx mem = gen_rtx_MEM (Pmode, addr);
13361 /* This should not be of rs6000_sr_alias_set, because of
13362 __builtin_return_address. */
f676971a 13363
9ebbca7d 13364 insn = emit_move_insn (mem, reg);
f676971a 13365 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13366 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13367 }
13368
13369 /* Save CR if we use any that must be preserved. */
d62294f5 13370 if (! info->world_save_p && info->cr_save_p)
9ebbca7d
GK
13371 {
13372 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13373 GEN_INT (info->cr_save_offset + sp_offset));
13374 rtx mem = gen_rtx_MEM (SImode, addr);
f8a57be8
GK
13375 /* See the large comment above about why CR2_REGNO is used. */
13376 rtx magic_eh_cr_reg = gen_rtx_REG (SImode, CR2_REGNO);
ba4828e0
RK
13377
13378 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13379
13380 /* If r12 was used to hold the original sp, copy cr into r0 now
13381 that it's free. */
13382 if (REGNO (frame_reg_rtx) == 12)
13383 {
f8a57be8
GK
13384 rtx set;
13385
9ebbca7d 13386 cr_save_rtx = gen_rtx_REG (SImode, 0);
f8a57be8
GK
13387 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13388 RTX_FRAME_RELATED_P (insn) = 1;
13389 set = gen_rtx_SET (VOIDmode, cr_save_rtx, magic_eh_cr_reg);
13390 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13391 set,
13392 REG_NOTES (insn));
f676971a 13393
9ebbca7d
GK
13394 }
13395 insn = emit_move_insn (mem, cr_save_rtx);
13396
f676971a 13397 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13398 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13399 }
13400
f676971a 13401 /* Update stack and set back pointer unless this is V.4,
9ebbca7d 13402 for which it was done previously. */
d62294f5 13403 if (! info->world_save_p && info->push_p
fc4767bb 13404 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
13405 rs6000_emit_allocate_stack (info->total_size, FALSE);
13406
13407 /* Set frame pointer, if needed. */
13408 if (frame_pointer_needed)
13409 {
f676971a 13410 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
13411 sp_reg_rtx);
13412 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 13413 }
9878760c 13414
1db02437 13415 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 13416 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 13417 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 13418 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
13419 {
13420 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 13421 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
13422 can use register 0. This allows us to use a plain 'blr' to return
13423 from the procedure more often. */
f1384257
AM
13424 int save_LR_around_toc_setup = (TARGET_ELF
13425 && DEFAULT_ABI != ABI_AIX
13426 && flag_pic
d5fa86ba
GK
13427 && ! info->lr_save_p
13428 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 13429 if (save_LR_around_toc_setup)
c4501e62
JJ
13430 {
13431 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f8a57be8
GK
13432
13433 insn = emit_move_insn (frame_ptr_rtx, lr);
13434 rs6000_maybe_dead (insn);
13435 RTX_FRAME_RELATED_P (insn) = 1;
13436
c4501e62 13437 rs6000_emit_load_toc_table (TRUE);
f8a57be8
GK
13438
13439 insn = emit_move_insn (lr, frame_ptr_rtx);
13440 rs6000_maybe_dead (insn);
13441 RTX_FRAME_RELATED_P (insn) = 1;
c4501e62
JJ
13442 }
13443 else
13444 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 13445 }
ee890fe2 13446
fcce224d 13447#if TARGET_MACHO
ee890fe2
SS
13448 if (DEFAULT_ABI == ABI_DARWIN
13449 && flag_pic && current_function_uses_pic_offset_table)
13450 {
f8a57be8 13451 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
11abc112 13452 rtx src = machopic_function_base_sym ();
ee890fe2 13453
f8a57be8 13454 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (lr, src)));
ee890fe2 13455
f676971a 13456 insn = emit_move_insn (gen_rtx_REG (Pmode,
f8a57be8
GK
13457 RS6000_PIC_OFFSET_TABLE_REGNUM),
13458 lr);
13459 rs6000_maybe_dead (insn);
ee890fe2 13460 }
fcce224d 13461#endif
9ebbca7d
GK
13462}
13463
9ebbca7d 13464/* Write function prologue. */
a4f6c312 13465
08c148a8 13466static void
f676971a 13467rs6000_output_function_prologue (FILE *file,
a2369ed3 13468 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
13469{
13470 rs6000_stack_t *info = rs6000_stack_info ();
13471
4697a36c
MM
13472 if (TARGET_DEBUG_STACK)
13473 debug_stack_info (info);
9878760c 13474
a4f6c312
SS
13475 /* Write .extern for any function we will call to save and restore
13476 fp values. */
13477 if (info->first_fp_reg_save < 64
13478 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 13479 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 13480 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
13481 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
13482 RESTORE_FP_SUFFIX);
9878760c 13483
c764f757
RK
13484 /* Write .extern for AIX common mode routines, if needed. */
13485 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
13486 {
f6709c70
JW
13487 fputs ("\t.extern __mulh\n", file);
13488 fputs ("\t.extern __mull\n", file);
13489 fputs ("\t.extern __divss\n", file);
13490 fputs ("\t.extern __divus\n", file);
13491 fputs ("\t.extern __quoss\n", file);
13492 fputs ("\t.extern __quous\n", file);
c764f757
RK
13493 common_mode_defined = 1;
13494 }
9878760c 13495
9ebbca7d 13496 if (! HAVE_prologue)
979721f8 13497 {
9ebbca7d 13498 start_sequence ();
9dda4cc8 13499
a4f6c312
SS
13500 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
13501 the "toplevel" insn chain. */
2e040219 13502 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13503 rs6000_emit_prologue ();
2e040219 13504 emit_note (NOTE_INSN_DELETED);
178c3eff 13505
a3c9585f 13506 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
13507 {
13508 rtx insn;
13509 unsigned addr = 0;
13510 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
13511 {
13512 INSN_ADDRESSES_NEW (insn, addr);
13513 addr += 4;
13514 }
13515 }
9dda4cc8 13516
9ebbca7d 13517 if (TARGET_DEBUG_STACK)
a4f6c312
SS
13518 debug_rtx_list (get_insns (), 100);
13519 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 13520 end_sequence ();
979721f8
MM
13521 }
13522
9ebbca7d
GK
13523 rs6000_pic_labelno++;
13524}
f676971a 13525
9ebbca7d 13526/* Emit function epilogue as insns.
9878760c 13527
9ebbca7d
GK
13528 At present, dwarf2out_frame_debug_expr doesn't understand
13529 register restores, so we don't bother setting RTX_FRAME_RELATED_P
13530 anywhere in the epilogue. Most of the insns below would in any case
13531 need special notes to explain where r11 is in relation to the stack. */
9878760c 13532
9ebbca7d 13533void
a2369ed3 13534rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
13535{
13536 rs6000_stack_t *info;
13537 int restoring_FPRs_inline;
13538 int using_load_multiple;
13539 int using_mfcr_multiple;
13540 int use_backchain_to_restore_sp;
13541 int sp_offset = 0;
13542 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
13543 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 13544 enum machine_mode reg_mode = Pmode;
327e5343 13545 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
13546 int i;
13547
c19de7aa
AH
13548 info = rs6000_stack_info ();
13549
13550 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13551 {
13552 reg_mode = V2SImode;
13553 reg_size = 8;
13554 }
13555
9ebbca7d 13556 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
13557 && (!TARGET_SPE_ABI
13558 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
13559 && info->first_gp_reg_save < 31);
13560 restoring_FPRs_inline = (sibcall
83720594 13561 || current_function_calls_eh_return
9ebbca7d
GK
13562 || info->first_fp_reg_save == 64
13563 || FP_SAVE_INLINE (info->first_fp_reg_save));
f676971a 13564 use_backchain_to_restore_sp = (frame_pointer_needed
9ebbca7d
GK
13565 || current_function_calls_alloca
13566 || info->total_size > 32767);
13567 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
13568 || rs6000_cpu == PROCESSOR_PPC603
13569 || rs6000_cpu == PROCESSOR_PPC750
13570 || optimize_size);
13571
d62294f5
FJ
13572 if (info->world_save_p)
13573 {
13574 int i, j;
13575 char rname[30];
13576 const char *alloc_rname;
13577 rtvec p;
13578
13579 /* eh_rest_world_r10 will return to the location saved in the LR
13580 stack slot (which is not likely to be our caller.)
13581 Input: R10 -- stack adjustment. Clobbers R0, R11, R12, R7, R8.
13582 rest_world is similar, except any R10 parameter is ignored.
13583 The exception-handling stuff that was here in 2.95 is no
13584 longer necessary. */
13585
13586 p = rtvec_alloc (9
13587 + 1
f676971a 13588 + 32 - info->first_gp_reg_save
d62294f5
FJ
13589 + LAST_ALTIVEC_REGNO + 1 - info->first_altivec_reg_save
13590 + 63 + 1 - info->first_fp_reg_save);
13591
13592 strcpy (rname, (current_function_calls_eh_return) ?
13593 "*eh_rest_world_r10" : "*rest_world");
13594 alloc_rname = ggc_strdup (rname);
13595
13596 j = 0;
13597 RTVEC_ELT (p, j++) = gen_rtx_RETURN (VOIDmode);
13598 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
13599 gen_rtx_REG (Pmode,
13600 LINK_REGISTER_REGNUM));
13601 RTVEC_ELT (p, j++)
13602 = gen_rtx_USE (VOIDmode, gen_rtx_SYMBOL_REF (Pmode, alloc_rname));
13603 /* The instruction pattern requires a clobber here;
13604 it is shared with the restVEC helper. */
13605 RTVEC_ELT (p, j++)
13606 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
13607
13608 {
13609 /* CR register traditionally saved as CR2. */
13610 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
13611 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13612 GEN_INT (info->cr_save_offset));
13613 rtx mem = gen_rtx_MEM (reg_mode, addr);
13614 set_mem_alias_set (mem, rs6000_sr_alias_set);
13615
13616 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13617 }
13618
13619 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13620 {
13621 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13622 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13623 GEN_INT (info->gp_save_offset
13624 + reg_size * i));
13625 rtx mem = gen_rtx_MEM (reg_mode, addr);
13626 set_mem_alias_set (mem, rs6000_sr_alias_set);
13627
13628 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13629 }
13630 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
13631 {
13632 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
13633 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13634 GEN_INT (info->altivec_save_offset
13635 + 16 * i));
13636 rtx mem = gen_rtx_MEM (V4SImode, addr);
13637 set_mem_alias_set (mem, rs6000_sr_alias_set);
13638
13639 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13640 }
13641 for (i = 0; info->first_fp_reg_save + i <= 63; i++)
13642 {
13643 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13644 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13645 GEN_INT (info->fp_save_offset
13646 + 8 * i));
13647 rtx mem = gen_rtx_MEM (DFmode, addr);
13648 set_mem_alias_set (mem, rs6000_sr_alias_set);
13649
13650 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13651 }
13652 RTVEC_ELT (p, j++)
13653 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 0));
13654 RTVEC_ELT (p, j++)
13655 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 12));
13656 RTVEC_ELT (p, j++)
13657 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 7));
13658 RTVEC_ELT (p, j++)
13659 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 8));
13660 RTVEC_ELT (p, j++)
13661 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 10));
13662 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
13663
13664 return;
13665 }
13666
9ebbca7d
GK
13667 /* If we have a frame pointer, a call to alloca, or a large stack
13668 frame, restore the old stack pointer using the backchain. Otherwise,
13669 we know what size to update it with. */
13670 if (use_backchain_to_restore_sp)
bacbde18 13671 {
9ebbca7d
GK
13672 /* Under V.4, don't reset the stack pointer until after we're done
13673 loading the saved registers. */
f607bc57 13674 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 13675 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 13676
9ebbca7d
GK
13677 emit_move_insn (frame_reg_rtx,
13678 gen_rtx_MEM (Pmode, sp_reg_rtx));
f676971a 13679
bacbde18 13680 }
9ebbca7d 13681 else if (info->push_p)
85638c0d 13682 {
fc4767bb
JJ
13683 if (DEFAULT_ABI == ABI_V4
13684 || current_function_calls_eh_return)
9ebbca7d
GK
13685 sp_offset = info->total_size;
13686 else
13687 {
13688 emit_insn (TARGET_32BIT
13689 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
13690 GEN_INT (info->total_size))
13691 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
13692 GEN_INT (info->total_size)));
13693 }
85638c0d 13694 }
f676971a 13695
9aa86737
AH
13696 /* Restore AltiVec registers if needed. */
13697 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
13698 {
13699 int i;
13700
13701 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
13702 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
13703 {
13704 rtx addr, areg, mem;
13705
13706 areg = gen_rtx_REG (Pmode, 0);
13707 emit_move_insn
13708 (areg, GEN_INT (info->altivec_save_offset
13709 + sp_offset
13710 + 16 * (i - info->first_altivec_reg_save)));
13711
13712 /* AltiVec addressing mode is [reg+reg]. */
13713 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
13714 mem = gen_rtx_MEM (V4SImode, addr);
13715 set_mem_alias_set (mem, rs6000_sr_alias_set);
13716
13717 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
13718 }
13719 }
13720
13721 /* Restore VRSAVE if needed. */
44688022 13722 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
4d774ff8 13723 && info->vrsave_mask != 0)
9aa86737
AH
13724 {
13725 rtx addr, mem, reg;
13726
13727 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13728 GEN_INT (info->vrsave_save_offset + sp_offset));
13729 mem = gen_rtx_MEM (SImode, addr);
13730 set_mem_alias_set (mem, rs6000_sr_alias_set);
13731 reg = gen_rtx_REG (SImode, 12);
13732 emit_move_insn (reg, mem);
13733
13734 emit_insn (generate_set_vrsave (reg, info, 1));
13735 }
13736
9ebbca7d
GK
13737 /* Get the old lr if we saved it. */
13738 if (info->lr_save_p)
b6c9286a 13739 {
a3170dc6
AH
13740 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
13741 info->lr_save_offset + sp_offset);
ba4828e0
RK
13742
13743 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 13744
9ebbca7d 13745 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 13746 }
f676971a 13747
9ebbca7d
GK
13748 /* Get the old cr if we saved it. */
13749 if (info->cr_save_p)
13750 {
13751 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13752 GEN_INT (info->cr_save_offset + sp_offset));
13753 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
13754
13755 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 13756
9ebbca7d
GK
13757 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
13758 }
f676971a 13759
9ebbca7d 13760 /* Set LR here to try to overlap restores below. */
4697a36c 13761 if (info->lr_save_p)
9ebbca7d
GK
13762 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
13763 gen_rtx_REG (Pmode, 0));
f676971a 13764
83720594
RH
13765 /* Load exception handler data registers, if needed. */
13766 if (current_function_calls_eh_return)
13767 {
78e1b90d
DE
13768 unsigned int i, regno;
13769
fc4767bb
JJ
13770 if (TARGET_AIX)
13771 {
13772 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13773 GEN_INT (sp_offset + 5 * reg_size));
13774 rtx mem = gen_rtx_MEM (reg_mode, addr);
13775
13776 set_mem_alias_set (mem, rs6000_sr_alias_set);
13777
13778 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
13779 }
13780
83720594
RH
13781 for (i = 0; ; ++i)
13782 {
a3170dc6 13783 rtx mem;
83720594
RH
13784
13785 regno = EH_RETURN_DATA_REGNO (i);
13786 if (regno == INVALID_REGNUM)
13787 break;
13788
a3170dc6
AH
13789 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
13790 info->ehrd_offset + sp_offset
13791 + reg_size * (int) i);
ba4828e0 13792 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
13793
13794 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
13795 }
13796 }
f676971a 13797
9ebbca7d
GK
13798 /* Restore GPRs. This is done as a PARALLEL if we are using
13799 the load-multiple instructions. */
13800 if (using_load_multiple)
979721f8 13801 {
9ebbca7d
GK
13802 rtvec p;
13803 p = rtvec_alloc (32 - info->first_gp_reg_save);
13804 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 13805 {
f676971a
EC
13806 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13807 GEN_INT (info->gp_save_offset
13808 + sp_offset
9ebbca7d
GK
13809 + reg_size * i));
13810 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
13811
13812 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 13813
f676971a 13814 RTVEC_ELT (p, i) =
9ebbca7d
GK
13815 gen_rtx_SET (VOIDmode,
13816 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
13817 mem);
979721f8 13818 }
9ebbca7d 13819 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 13820 }
9ebbca7d
GK
13821 else
13822 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 13823 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
13824 && (! call_used_regs[info->first_gp_reg_save+i]
13825 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
13826 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 13827 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 13828 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 13829 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d 13830 {
f676971a
EC
13831 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13832 GEN_INT (info->gp_save_offset
13833 + sp_offset
9ebbca7d
GK
13834 + reg_size * i));
13835 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 13836
a3170dc6 13837 /* Restore 64-bit quantities for SPE. */
c19de7aa 13838 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13839 {
13840 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
13841 rtx b;
13842
13843 if (!SPE_CONST_OFFSET_OK (offset))
13844 {
13845 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13846 emit_move_insn (b, GEN_INT (offset));
13847 }
13848 else
13849 b = GEN_INT (offset);
13850
13851 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
13852 mem = gen_rtx_MEM (V2SImode, addr);
13853 }
13854
ba4828e0 13855 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 13856
f676971a 13857 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 13858 info->first_gp_reg_save + i), mem);
9ebbca7d 13859 }
9878760c 13860
9ebbca7d
GK
13861 /* Restore fpr's if we need to do it without calling a function. */
13862 if (restoring_FPRs_inline)
13863 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 13864 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d
GK
13865 && ! call_used_regs[info->first_fp_reg_save+i]))
13866 {
13867 rtx addr, mem;
13868 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a
EC
13869 GEN_INT (info->fp_save_offset
13870 + sp_offset
a4f6c312 13871 + 8 * i));
9ebbca7d 13872 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 13873 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 13874
f676971a 13875 emit_move_insn (gen_rtx_REG (DFmode,
9ebbca7d
GK
13876 info->first_fp_reg_save + i),
13877 mem);
13878 }
8d30c4ee 13879
9ebbca7d
GK
13880 /* If we saved cr, restore it here. Just those that were used. */
13881 if (info->cr_save_p)
979721f8 13882 {
9ebbca7d 13883 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 13884 int count = 0;
f676971a 13885
9ebbca7d 13886 if (using_mfcr_multiple)
979721f8 13887 {
9ebbca7d
GK
13888 for (i = 0; i < 8; i++)
13889 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 13890 count++;
9ebbca7d 13891 if (count == 0)
e35b9579
GK
13892 abort ();
13893 }
13894
13895 if (using_mfcr_multiple && count > 1)
13896 {
13897 rtvec p;
13898 int ndx;
f676971a 13899
e35b9579 13900 p = rtvec_alloc (count);
9ebbca7d 13901
e35b9579 13902 ndx = 0;
9ebbca7d
GK
13903 for (i = 0; i < 8; i++)
13904 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
13905 {
13906 rtvec r = rtvec_alloc (2);
13907 RTVEC_ELT (r, 0) = r12_rtx;
13908 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 13909 RTVEC_ELT (p, ndx) =
f676971a 13910 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 13911 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 13912 ndx++;
9ebbca7d
GK
13913 }
13914 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
13915 if (ndx != count)
13916 abort ();
979721f8
MM
13917 }
13918 else
9ebbca7d
GK
13919 for (i = 0; i < 8; i++)
13920 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 13921 {
f676971a 13922 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
9ebbca7d
GK
13923 CR0_REGNO+i),
13924 r12_rtx));
979721f8 13925 }
979721f8
MM
13926 }
13927
9ebbca7d
GK
13928 /* If this is V.4, unwind the stack pointer after all of the loads
13929 have been done. We need to emit a block here so that sched
13930 doesn't decide to move the sp change before the register restores
13931 (which may not have any obvious dependency on the stack). This
13932 doesn't hurt performance, because there is no scheduling that can
13933 be done after this point. */
fc4767bb
JJ
13934 if (DEFAULT_ABI == ABI_V4
13935 || current_function_calls_eh_return)
b6c9286a 13936 {
9ebbca7d
GK
13937 if (frame_reg_rtx != sp_reg_rtx)
13938 rs6000_emit_stack_tie ();
b6c9286a 13939
9ebbca7d 13940 if (use_backchain_to_restore_sp)
b6c9286a 13941 {
9ebbca7d 13942 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 13943 }
9ebbca7d 13944 else if (sp_offset != 0)
13f1623b 13945 {
5b71a4e7 13946 emit_insn (TARGET_32BIT
9ebbca7d
GK
13947 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
13948 GEN_INT (sp_offset))
13949 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
13950 GEN_INT (sp_offset)));
13f1623b 13951 }
9ebbca7d 13952 }
b6c9286a 13953
83720594
RH
13954 if (current_function_calls_eh_return)
13955 {
13956 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 13957 emit_insn (TARGET_32BIT
83720594
RH
13958 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
13959 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
13960 }
13961
9ebbca7d
GK
13962 if (!sibcall)
13963 {
13964 rtvec p;
13965 if (! restoring_FPRs_inline)
13966 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
13967 else
13968 p = rtvec_alloc (2);
b6c9286a 13969
e35b9579 13970 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
f676971a
EC
13971 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
13972 gen_rtx_REG (Pmode,
9ebbca7d 13973 LINK_REGISTER_REGNUM));
9ebbca7d
GK
13974
13975 /* If we have to restore more than two FP registers, branch to the
13976 restore function. It will return to our caller. */
13977 if (! restoring_FPRs_inline)
13978 {
13979 int i;
13980 char rname[30];
520a57c8 13981 const char *alloc_rname;
979721f8 13982
f676971a 13983 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
9ebbca7d 13984 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 13985 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
13986 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
13987 gen_rtx_SYMBOL_REF (Pmode,
13988 alloc_rname));
b6c9286a 13989
9ebbca7d
GK
13990 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13991 {
13992 rtx addr, mem;
13993 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
13994 GEN_INT (info->fp_save_offset + 8*i));
13995 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 13996 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 13997
f676971a 13998 RTVEC_ELT (p, i+3) =
9ebbca7d
GK
13999 gen_rtx_SET (VOIDmode,
14000 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
14001 mem);
b6c9286a
MM
14002 }
14003 }
f676971a 14004
9ebbca7d 14005 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 14006 }
9878760c
RK
14007}
14008
14009/* Write function epilogue. */
14010
08c148a8 14011static void
f676971a 14012rs6000_output_function_epilogue (FILE *file,
a2369ed3 14013 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 14014{
4697a36c 14015 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 14016
9ebbca7d 14017 if (! HAVE_epilogue)
9878760c 14018 {
9ebbca7d
GK
14019 rtx insn = get_last_insn ();
14020 /* If the last insn was a BARRIER, we don't have to write anything except
14021 the trace table. */
14022 if (GET_CODE (insn) == NOTE)
14023 insn = prev_nonnote_insn (insn);
14024 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 14025 {
9ebbca7d
GK
14026 /* This is slightly ugly, but at least we don't have two
14027 copies of the epilogue-emitting code. */
14028 start_sequence ();
14029
14030 /* A NOTE_INSN_DELETED is supposed to be at the start
14031 and end of the "toplevel" insn chain. */
2e040219 14032 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14033 rs6000_emit_epilogue (FALSE);
2e040219 14034 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14035
a3c9585f 14036 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
14037 {
14038 rtx insn;
14039 unsigned addr = 0;
14040 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
14041 {
14042 INSN_ADDRESSES_NEW (insn, addr);
14043 addr += 4;
14044 }
14045 }
14046
9ebbca7d 14047 if (TARGET_DEBUG_STACK)
a4f6c312
SS
14048 debug_rtx_list (get_insns (), 100);
14049 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 14050 end_sequence ();
4697a36c 14051 }
9878760c 14052 }
b4ac57ab 14053
efdba735
SH
14054#if TARGET_MACHO
14055 macho_branch_islands ();
0e5da0be
GK
14056 /* Mach-O doesn't support labels at the end of objects, so if
14057 it looks like we might want one, insert a NOP. */
14058 {
14059 rtx insn = get_last_insn ();
14060 while (insn
14061 && NOTE_P (insn)
14062 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
14063 insn = PREV_INSN (insn);
f676971a
EC
14064 if (insn
14065 && (LABEL_P (insn)
0e5da0be
GK
14066 || (NOTE_P (insn)
14067 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
14068 fputs ("\tnop\n", file);
14069 }
14070#endif
14071
9b30bae2 14072 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
14073 on its format.
14074
14075 We don't output a traceback table if -finhibit-size-directive was
14076 used. The documentation for -finhibit-size-directive reads
14077 ``don't output a @code{.size} assembler directive, or anything
14078 else that would cause trouble if the function is split in the
14079 middle, and the two halves are placed at locations far apart in
14080 memory.'' The traceback table has this property, since it
14081 includes the offset from the start of the function to the
4d30c363
MM
14082 traceback table itself.
14083
14084 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 14085 different traceback table. */
57ac7be9
AM
14086 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
14087 && rs6000_traceback != traceback_none)
9b30bae2 14088 {
69c75916 14089 const char *fname = NULL;
3ac88239 14090 const char *language_string = lang_hooks.name;
6041bf2f 14091 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 14092 int i;
57ac7be9
AM
14093 int optional_tbtab;
14094
14095 if (rs6000_traceback == traceback_full)
14096 optional_tbtab = 1;
14097 else if (rs6000_traceback == traceback_part)
14098 optional_tbtab = 0;
14099 else
14100 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 14101
69c75916
AM
14102 if (optional_tbtab)
14103 {
14104 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
14105 while (*fname == '.') /* V.4 encodes . in the name */
14106 fname++;
14107
14108 /* Need label immediately before tbtab, so we can compute
14109 its offset from the function start. */
14110 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
14111 ASM_OUTPUT_LABEL (file, fname);
14112 }
314fc5a9
ILT
14113
14114 /* The .tbtab pseudo-op can only be used for the first eight
14115 expressions, since it can't handle the possibly variable
14116 length fields that follow. However, if you omit the optional
14117 fields, the assembler outputs zeros for all optional fields
14118 anyways, giving each variable length field is minimum length
14119 (as defined in sys/debug.h). Thus we can not use the .tbtab
14120 pseudo-op at all. */
14121
14122 /* An all-zero word flags the start of the tbtab, for debuggers
14123 that have to find it by searching forward from the entry
14124 point or from the current pc. */
19d2d16f 14125 fputs ("\t.long 0\n", file);
314fc5a9
ILT
14126
14127 /* Tbtab format type. Use format type 0. */
19d2d16f 14128 fputs ("\t.byte 0,", file);
314fc5a9 14129
5fc921c1
DE
14130 /* Language type. Unfortunately, there does not seem to be any
14131 official way to discover the language being compiled, so we
14132 use language_string.
14133 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
14134 Java is 13. Objective-C is 14. */
14135 if (! strcmp (language_string, "GNU C"))
314fc5a9 14136 i = 0;
6de9cd9a
DN
14137 else if (! strcmp (language_string, "GNU F77")
14138 || ! strcmp (language_string, "GNU F95"))
314fc5a9 14139 i = 1;
8b83775b 14140 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 14141 i = 2;
5fc921c1
DE
14142 else if (! strcmp (language_string, "GNU Ada"))
14143 i = 3;
314fc5a9
ILT
14144 else if (! strcmp (language_string, "GNU C++"))
14145 i = 9;
9517ead8
AG
14146 else if (! strcmp (language_string, "GNU Java"))
14147 i = 13;
5fc921c1
DE
14148 else if (! strcmp (language_string, "GNU Objective-C"))
14149 i = 14;
314fc5a9
ILT
14150 else
14151 abort ();
14152 fprintf (file, "%d,", i);
14153
14154 /* 8 single bit fields: global linkage (not set for C extern linkage,
14155 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
14156 from start of procedure stored in tbtab, internal function, function
14157 has controlled storage, function has no toc, function uses fp,
14158 function logs/aborts fp operations. */
14159 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
14160 fprintf (file, "%d,",
14161 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
14162
14163 /* 6 bitfields: function is interrupt handler, name present in
14164 proc table, function calls alloca, on condition directives
14165 (controls stack walks, 3 bits), saves condition reg, saves
14166 link reg. */
14167 /* The `function calls alloca' bit seems to be set whenever reg 31 is
14168 set up as a frame pointer, even when there is no alloca call. */
14169 fprintf (file, "%d,",
6041bf2f
DE
14170 ((optional_tbtab << 6)
14171 | ((optional_tbtab & frame_pointer_needed) << 5)
14172 | (info->cr_save_p << 1)
14173 | (info->lr_save_p)));
314fc5a9 14174
6041bf2f 14175 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
14176 (6 bits). */
14177 fprintf (file, "%d,",
4697a36c 14178 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
14179
14180 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
14181 fprintf (file, "%d,", (32 - first_reg_to_save ()));
14182
6041bf2f
DE
14183 if (optional_tbtab)
14184 {
14185 /* Compute the parameter info from the function decl argument
14186 list. */
14187 tree decl;
14188 int next_parm_info_bit = 31;
314fc5a9 14189
6041bf2f
DE
14190 for (decl = DECL_ARGUMENTS (current_function_decl);
14191 decl; decl = TREE_CHAIN (decl))
14192 {
14193 rtx parameter = DECL_INCOMING_RTL (decl);
14194 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 14195
6041bf2f
DE
14196 if (GET_CODE (parameter) == REG)
14197 {
14198 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
14199 {
14200 int bits;
14201
14202 float_parms++;
14203
14204 if (mode == SFmode)
14205 bits = 0x2;
fcce224d 14206 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
14207 bits = 0x3;
14208 else
14209 abort ();
14210
14211 /* If only one bit will fit, don't or in this entry. */
14212 if (next_parm_info_bit > 0)
14213 parm_info |= (bits << (next_parm_info_bit - 1));
14214 next_parm_info_bit -= 2;
14215 }
14216 else
14217 {
14218 fixed_parms += ((GET_MODE_SIZE (mode)
14219 + (UNITS_PER_WORD - 1))
14220 / UNITS_PER_WORD);
14221 next_parm_info_bit -= 1;
14222 }
14223 }
14224 }
14225 }
314fc5a9
ILT
14226
14227 /* Number of fixed point parameters. */
14228 /* This is actually the number of words of fixed point parameters; thus
14229 an 8 byte struct counts as 2; and thus the maximum value is 8. */
14230 fprintf (file, "%d,", fixed_parms);
14231
14232 /* 2 bitfields: number of floating point parameters (7 bits), parameters
14233 all on stack. */
14234 /* This is actually the number of fp registers that hold parameters;
14235 and thus the maximum value is 13. */
14236 /* Set parameters on stack bit if parameters are not in their original
14237 registers, regardless of whether they are on the stack? Xlc
14238 seems to set the bit when not optimizing. */
14239 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
14240
6041bf2f
DE
14241 if (! optional_tbtab)
14242 return;
14243
314fc5a9
ILT
14244 /* Optional fields follow. Some are variable length. */
14245
14246 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
14247 11 double float. */
14248 /* There is an entry for each parameter in a register, in the order that
14249 they occur in the parameter list. Any intervening arguments on the
14250 stack are ignored. If the list overflows a long (max possible length
14251 34 bits) then completely leave off all elements that don't fit. */
14252 /* Only emit this long if there was at least one parameter. */
14253 if (fixed_parms || float_parms)
14254 fprintf (file, "\t.long %d\n", parm_info);
14255
14256 /* Offset from start of code to tb table. */
19d2d16f 14257 fputs ("\t.long ", file);
314fc5a9 14258 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
85b776df
AM
14259 if (TARGET_AIX)
14260 RS6000_OUTPUT_BASENAME (file, fname);
14261 else
14262 assemble_name (file, fname);
14263 putc ('-', file);
14264 rs6000_output_function_entry (file, fname);
19d2d16f 14265 putc ('\n', file);
314fc5a9
ILT
14266
14267 /* Interrupt handler mask. */
14268 /* Omit this long, since we never set the interrupt handler bit
14269 above. */
14270
14271 /* Number of CTL (controlled storage) anchors. */
14272 /* Omit this long, since the has_ctl bit is never set above. */
14273
14274 /* Displacement into stack of each CTL anchor. */
14275 /* Omit this list of longs, because there are no CTL anchors. */
14276
14277 /* Length of function name. */
69c75916
AM
14278 if (*fname == '*')
14279 ++fname;
296b8152 14280 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
14281
14282 /* Function name. */
14283 assemble_string (fname, strlen (fname));
14284
14285 /* Register for alloca automatic storage; this is always reg 31.
14286 Only emit this if the alloca bit was set above. */
14287 if (frame_pointer_needed)
19d2d16f 14288 fputs ("\t.byte 31\n", file);
b1765bde
DE
14289
14290 fputs ("\t.align 2\n", file);
9b30bae2 14291 }
9878760c 14292}
17167fd8 14293\f
a4f6c312
SS
14294/* A C compound statement that outputs the assembler code for a thunk
14295 function, used to implement C++ virtual function calls with
14296 multiple inheritance. The thunk acts as a wrapper around a virtual
14297 function, adjusting the implicit object parameter before handing
14298 control off to the real function.
14299
14300 First, emit code to add the integer DELTA to the location that
14301 contains the incoming first argument. Assume that this argument
14302 contains a pointer, and is the one used to pass the `this' pointer
14303 in C++. This is the incoming argument *before* the function
14304 prologue, e.g. `%o0' on a sparc. The addition must preserve the
14305 values of all other incoming arguments.
17167fd8
MM
14306
14307 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
14308 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
14309 not touch the return address. Hence returning from FUNCTION will
14310 return to whoever called the current `thunk'.
17167fd8 14311
a4f6c312
SS
14312 The effect must be as if FUNCTION had been called directly with the
14313 adjusted first argument. This macro is responsible for emitting
14314 all of the code for a thunk function; output_function_prologue()
14315 and output_function_epilogue() are not invoked.
17167fd8 14316
a4f6c312
SS
14317 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
14318 been extracted from it.) It might possibly be useful on some
14319 targets, but probably not.
17167fd8 14320
a4f6c312
SS
14321 If you do not define this macro, the target-independent code in the
14322 C++ frontend will generate a less efficient heavyweight thunk that
14323 calls FUNCTION instead of jumping to it. The generic approach does
14324 not support varargs. */
17167fd8 14325
3961e8fe 14326static void
f676971a
EC
14327rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
14328 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
a2369ed3 14329 tree function)
17167fd8 14330{
5b71a4e7 14331 rtx this, insn, funexp;
17167fd8 14332
5b71a4e7 14333 reload_completed = 1;
fe3ad572 14334 epilogue_completed = 1;
5b71a4e7 14335 no_new_pseudos = 1;
6429e3be 14336 reset_block_changes ();
56a7189a 14337
5b71a4e7 14338 /* Mark the end of the (empty) prologue. */
2e040219 14339 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 14340
5b71a4e7
DE
14341 /* Find the "this" pointer. If the function returns a structure,
14342 the structure return pointer is in r3. */
61f71b34 14343 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 14344 this = gen_rtx_REG (Pmode, 4);
56a7189a 14345 else
5b71a4e7 14346 this = gen_rtx_REG (Pmode, 3);
17167fd8 14347
5b71a4e7
DE
14348 /* Apply the constant offset, if required. */
14349 if (delta)
14350 {
14351 rtx delta_rtx = GEN_INT (delta);
14352 emit_insn (TARGET_32BIT
14353 ? gen_addsi3 (this, this, delta_rtx)
14354 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
14355 }
14356
5b71a4e7
DE
14357 /* Apply the offset from the vtable, if required. */
14358 if (vcall_offset)
17167fd8 14359 {
5b71a4e7
DE
14360 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
14361 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 14362
5b71a4e7 14363 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
14364 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
14365 {
14366 emit_insn (TARGET_32BIT
14367 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
14368 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
14369 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
14370 }
14371 else
14372 {
14373 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
14374
14375 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
14376 }
5b71a4e7
DE
14377 emit_insn (TARGET_32BIT
14378 ? gen_addsi3 (this, this, tmp)
14379 : gen_adddi3 (this, this, tmp));
17167fd8
MM
14380 }
14381
5b71a4e7
DE
14382 /* Generate a tail call to the target function. */
14383 if (!TREE_USED (function))
14384 {
14385 assemble_external (function);
14386 TREE_USED (function) = 1;
14387 }
14388 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 14389 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
14390
14391#if TARGET_MACHO
ab82a49f 14392 if (MACHOPIC_INDIRECT)
5b71a4e7 14393 funexp = machopic_indirect_call_target (funexp);
ee890fe2 14394#endif
5b71a4e7
DE
14395
14396 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
14397 generate sibcall RTL explicitly to avoid constraint abort. */
14398 insn = emit_call_insn (
14399 gen_rtx_PARALLEL (VOIDmode,
14400 gen_rtvec (4,
14401 gen_rtx_CALL (VOIDmode,
14402 funexp, const0_rtx),
14403 gen_rtx_USE (VOIDmode, const0_rtx),
14404 gen_rtx_USE (VOIDmode,
14405 gen_rtx_REG (SImode,
14406 LINK_REGISTER_REGNUM)),
14407 gen_rtx_RETURN (VOIDmode))));
14408 SIBLING_CALL_P (insn) = 1;
14409 emit_barrier ();
14410
14411 /* Run just enough of rest_of_compilation to get the insns emitted.
14412 There's not really enough bulk here to make other passes such as
14413 instruction scheduling worth while. Note that use_thunk calls
14414 assemble_start_function and assemble_end_function. */
14415 insn = get_insns ();
a2855205 14416 insn_locators_initialize ();
5b71a4e7
DE
14417 shorten_branches (insn);
14418 final_start_function (insn, file, 1);
14419 final (insn, file, 1, 0);
14420 final_end_function ();
14421
14422 reload_completed = 0;
fe3ad572 14423 epilogue_completed = 0;
5b71a4e7 14424 no_new_pseudos = 0;
9ebbca7d 14425}
9ebbca7d
GK
14426\f
14427/* A quick summary of the various types of 'constant-pool tables'
14428 under PowerPC:
14429
f676971a 14430 Target Flags Name One table per
9ebbca7d
GK
14431 AIX (none) AIX TOC object file
14432 AIX -mfull-toc AIX TOC object file
14433 AIX -mminimal-toc AIX minimal TOC translation unit
14434 SVR4/EABI (none) SVR4 SDATA object file
14435 SVR4/EABI -fpic SVR4 pic object file
14436 SVR4/EABI -fPIC SVR4 PIC translation unit
14437 SVR4/EABI -mrelocatable EABI TOC function
14438 SVR4/EABI -maix AIX TOC object file
f676971a 14439 SVR4/EABI -maix -mminimal-toc
9ebbca7d
GK
14440 AIX minimal TOC translation unit
14441
14442 Name Reg. Set by entries contains:
14443 made by addrs? fp? sum?
14444
14445 AIX TOC 2 crt0 as Y option option
14446 AIX minimal TOC 30 prolog gcc Y Y option
14447 SVR4 SDATA 13 crt0 gcc N Y N
14448 SVR4 pic 30 prolog ld Y not yet N
14449 SVR4 PIC 30 prolog gcc Y option option
14450 EABI TOC 30 prolog gcc Y option option
14451
14452*/
14453
9ebbca7d
GK
14454/* Hash functions for the hash table. */
14455
14456static unsigned
a2369ed3 14457rs6000_hash_constant (rtx k)
9ebbca7d 14458{
46b33600
RH
14459 enum rtx_code code = GET_CODE (k);
14460 enum machine_mode mode = GET_MODE (k);
14461 unsigned result = (code << 3) ^ mode;
14462 const char *format;
14463 int flen, fidx;
f676971a 14464
46b33600
RH
14465 format = GET_RTX_FORMAT (code);
14466 flen = strlen (format);
14467 fidx = 0;
9ebbca7d 14468
46b33600
RH
14469 switch (code)
14470 {
14471 case LABEL_REF:
14472 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
14473
14474 case CONST_DOUBLE:
14475 if (mode != VOIDmode)
14476 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
14477 flen = 2;
14478 break;
14479
14480 case CODE_LABEL:
14481 fidx = 3;
14482 break;
14483
14484 default:
14485 break;
14486 }
9ebbca7d
GK
14487
14488 for (; fidx < flen; fidx++)
14489 switch (format[fidx])
14490 {
14491 case 's':
14492 {
14493 unsigned i, len;
14494 const char *str = XSTR (k, fidx);
14495 len = strlen (str);
14496 result = result * 613 + len;
14497 for (i = 0; i < len; i++)
14498 result = result * 613 + (unsigned) str[i];
17167fd8
MM
14499 break;
14500 }
9ebbca7d
GK
14501 case 'u':
14502 case 'e':
14503 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
14504 break;
14505 case 'i':
14506 case 'n':
14507 result = result * 613 + (unsigned) XINT (k, fidx);
14508 break;
14509 case 'w':
14510 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
14511 result = result * 613 + (unsigned) XWINT (k, fidx);
14512 else
14513 {
14514 size_t i;
14515 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
14516 result = result * 613 + (unsigned) (XWINT (k, fidx)
14517 >> CHAR_BIT * i);
14518 }
14519 break;
09501938
DE
14520 case '0':
14521 break;
9ebbca7d 14522 default:
a4f6c312 14523 abort ();
9ebbca7d 14524 }
46b33600 14525
9ebbca7d
GK
14526 return result;
14527}
14528
14529static unsigned
a2369ed3 14530toc_hash_function (const void *hash_entry)
9ebbca7d 14531{
f676971a 14532 const struct toc_hash_struct *thc =
a9098fd0
GK
14533 (const struct toc_hash_struct *) hash_entry;
14534 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
14535}
14536
14537/* Compare H1 and H2 for equivalence. */
14538
14539static int
a2369ed3 14540toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
14541{
14542 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
14543 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
14544
a9098fd0
GK
14545 if (((const struct toc_hash_struct *) h1)->key_mode
14546 != ((const struct toc_hash_struct *) h2)->key_mode)
14547 return 0;
14548
5692c7bc 14549 return rtx_equal_p (r1, r2);
9ebbca7d
GK
14550}
14551
28e510bd
MM
14552/* These are the names given by the C++ front-end to vtables, and
14553 vtable-like objects. Ideally, this logic should not be here;
14554 instead, there should be some programmatic way of inquiring as
14555 to whether or not an object is a vtable. */
14556
14557#define VTABLE_NAME_P(NAME) \
14558 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
14559 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
14560 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 14561 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
f676971a 14562 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
28e510bd
MM
14563
14564void
a2369ed3 14565rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
14566{
14567 /* Currently C++ toc references to vtables can be emitted before it
14568 is decided whether the vtable is public or private. If this is
14569 the case, then the linker will eventually complain that there is
f676971a 14570 a reference to an unknown section. Thus, for vtables only,
28e510bd
MM
14571 we emit the TOC reference to reference the symbol and not the
14572 section. */
14573 const char *name = XSTR (x, 0);
54ee9799 14574
f676971a 14575 if (VTABLE_NAME_P (name))
54ee9799
DE
14576 {
14577 RS6000_OUTPUT_BASENAME (file, name);
14578 }
14579 else
14580 assemble_name (file, name);
28e510bd
MM
14581}
14582
a4f6c312
SS
14583/* Output a TOC entry. We derive the entry name from what is being
14584 written. */
9878760c
RK
14585
14586void
a2369ed3 14587output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
14588{
14589 char buf[256];
3cce094d 14590 const char *name = buf;
ec940faa 14591 const char *real_name;
9878760c
RK
14592 rtx base = x;
14593 int offset = 0;
14594
4697a36c
MM
14595 if (TARGET_NO_TOC)
14596 abort ();
14597
9ebbca7d
GK
14598 /* When the linker won't eliminate them, don't output duplicate
14599 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
14600 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
14601 CODE_LABELs. */
14602 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
14603 {
14604 struct toc_hash_struct *h;
14605 void * * found;
f676971a 14606
17211ab5 14607 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 14608 time because GGC is not initialized at that point. */
17211ab5 14609 if (toc_hash_table == NULL)
f676971a 14610 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
17211ab5
GK
14611 toc_hash_eq, NULL);
14612
9ebbca7d
GK
14613 h = ggc_alloc (sizeof (*h));
14614 h->key = x;
a9098fd0 14615 h->key_mode = mode;
9ebbca7d 14616 h->labelno = labelno;
f676971a 14617
9ebbca7d
GK
14618 found = htab_find_slot (toc_hash_table, h, 1);
14619 if (*found == NULL)
14620 *found = h;
f676971a 14621 else /* This is indeed a duplicate.
9ebbca7d
GK
14622 Set this label equal to that label. */
14623 {
14624 fputs ("\t.set ", file);
14625 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
14626 fprintf (file, "%d,", labelno);
14627 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
f676971a 14628 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
9ebbca7d
GK
14629 found)->labelno));
14630 return;
14631 }
14632 }
14633
14634 /* If we're going to put a double constant in the TOC, make sure it's
14635 aligned properly when strict alignment is on. */
ff1720ed
RK
14636 if (GET_CODE (x) == CONST_DOUBLE
14637 && STRICT_ALIGNMENT
a9098fd0 14638 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
14639 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
14640 ASM_OUTPUT_ALIGN (file, 3);
14641 }
14642
4977bab6 14643 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 14644
37c37a57
RK
14645 /* Handle FP constants specially. Note that if we have a minimal
14646 TOC, things we put here aren't actually in the TOC, so we can allow
14647 FP constants. */
fcce224d
DE
14648 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
14649 {
14650 REAL_VALUE_TYPE rv;
14651 long k[4];
14652
14653 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
14654 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
14655
14656 if (TARGET_64BIT)
14657 {
14658 if (TARGET_MINIMAL_TOC)
14659 fputs (DOUBLE_INT_ASM_OP, file);
14660 else
14661 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
14662 k[0] & 0xffffffff, k[1] & 0xffffffff,
14663 k[2] & 0xffffffff, k[3] & 0xffffffff);
14664 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
14665 k[0] & 0xffffffff, k[1] & 0xffffffff,
14666 k[2] & 0xffffffff, k[3] & 0xffffffff);
14667 return;
14668 }
14669 else
14670 {
14671 if (TARGET_MINIMAL_TOC)
14672 fputs ("\t.long ", file);
14673 else
14674 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
14675 k[0] & 0xffffffff, k[1] & 0xffffffff,
14676 k[2] & 0xffffffff, k[3] & 0xffffffff);
14677 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
14678 k[0] & 0xffffffff, k[1] & 0xffffffff,
14679 k[2] & 0xffffffff, k[3] & 0xffffffff);
14680 return;
14681 }
14682 }
14683 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 14684 {
042259f2
DE
14685 REAL_VALUE_TYPE rv;
14686 long k[2];
0adc764e 14687
042259f2
DE
14688 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
14689 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 14690
13ded975
DE
14691 if (TARGET_64BIT)
14692 {
14693 if (TARGET_MINIMAL_TOC)
2bfcf297 14694 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 14695 else
2f0552b6
AM
14696 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
14697 k[0] & 0xffffffff, k[1] & 0xffffffff);
14698 fprintf (file, "0x%lx%08lx\n",
14699 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
14700 return;
14701 }
1875cc88 14702 else
13ded975
DE
14703 {
14704 if (TARGET_MINIMAL_TOC)
2bfcf297 14705 fputs ("\t.long ", file);
13ded975 14706 else
2f0552b6
AM
14707 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
14708 k[0] & 0xffffffff, k[1] & 0xffffffff);
14709 fprintf (file, "0x%lx,0x%lx\n",
14710 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
14711 return;
14712 }
9878760c 14713 }
a9098fd0 14714 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 14715 {
042259f2
DE
14716 REAL_VALUE_TYPE rv;
14717 long l;
9878760c 14718
042259f2
DE
14719 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
14720 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
14721
31bfaa0b
DE
14722 if (TARGET_64BIT)
14723 {
14724 if (TARGET_MINIMAL_TOC)
2bfcf297 14725 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 14726 else
2f0552b6
AM
14727 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
14728 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
14729 return;
14730 }
042259f2 14731 else
31bfaa0b
DE
14732 {
14733 if (TARGET_MINIMAL_TOC)
2bfcf297 14734 fputs ("\t.long ", file);
31bfaa0b 14735 else
2f0552b6
AM
14736 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
14737 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
14738 return;
14739 }
042259f2 14740 }
f176e826 14741 else if (GET_MODE (x) == VOIDmode
a9098fd0 14742 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 14743 {
e2c953b6 14744 unsigned HOST_WIDE_INT low;
042259f2
DE
14745 HOST_WIDE_INT high;
14746
14747 if (GET_CODE (x) == CONST_DOUBLE)
14748 {
14749 low = CONST_DOUBLE_LOW (x);
14750 high = CONST_DOUBLE_HIGH (x);
14751 }
14752 else
14753#if HOST_BITS_PER_WIDE_INT == 32
14754 {
14755 low = INTVAL (x);
0858c623 14756 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
14757 }
14758#else
14759 {
0858c623 14760 low = INTVAL (x) & 0xffffffff;
042259f2
DE
14761 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
14762 }
14763#endif
9878760c 14764
a9098fd0
GK
14765 /* TOC entries are always Pmode-sized, but since this
14766 is a bigendian machine then if we're putting smaller
14767 integer constants in the TOC we have to pad them.
14768 (This is still a win over putting the constants in
14769 a separate constant pool, because then we'd have
02a4ec28
FS
14770 to have both a TOC entry _and_ the actual constant.)
14771
14772 For a 32-bit target, CONST_INT values are loaded and shifted
14773 entirely within `low' and can be stored in one TOC entry. */
14774
14775 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 14776 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
14777
14778 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
14779 {
14780#if HOST_BITS_PER_WIDE_INT == 32
14781 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
14782 POINTER_SIZE, &low, &high, 0);
14783#else
14784 low |= high << 32;
14785 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
14786 high = (HOST_WIDE_INT) low >> 32;
14787 low &= 0xffffffff;
14788#endif
14789 }
a9098fd0 14790
13ded975
DE
14791 if (TARGET_64BIT)
14792 {
14793 if (TARGET_MINIMAL_TOC)
2bfcf297 14794 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 14795 else
2f0552b6
AM
14796 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
14797 (long) high & 0xffffffff, (long) low & 0xffffffff);
14798 fprintf (file, "0x%lx%08lx\n",
14799 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
14800 return;
14801 }
1875cc88 14802 else
13ded975 14803 {
02a4ec28
FS
14804 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
14805 {
14806 if (TARGET_MINIMAL_TOC)
2bfcf297 14807 fputs ("\t.long ", file);
02a4ec28 14808 else
2bfcf297 14809 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
14810 (long) high & 0xffffffff, (long) low & 0xffffffff);
14811 fprintf (file, "0x%lx,0x%lx\n",
14812 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 14813 }
13ded975 14814 else
02a4ec28
FS
14815 {
14816 if (TARGET_MINIMAL_TOC)
2bfcf297 14817 fputs ("\t.long ", file);
02a4ec28 14818 else
2f0552b6
AM
14819 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
14820 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 14821 }
13ded975
DE
14822 return;
14823 }
9878760c
RK
14824 }
14825
14826 if (GET_CODE (x) == CONST)
14827 {
2bfcf297
DB
14828 if (GET_CODE (XEXP (x, 0)) != PLUS)
14829 abort ();
14830
9878760c
RK
14831 base = XEXP (XEXP (x, 0), 0);
14832 offset = INTVAL (XEXP (XEXP (x, 0), 1));
14833 }
f676971a 14834
9878760c
RK
14835 if (GET_CODE (base) == SYMBOL_REF)
14836 name = XSTR (base, 0);
14837 else if (GET_CODE (base) == LABEL_REF)
14838 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
14839 else if (GET_CODE (base) == CODE_LABEL)
14840 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
14841 else
14842 abort ();
14843
772c5265 14844 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 14845 if (TARGET_MINIMAL_TOC)
2bfcf297 14846 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
14847 else
14848 {
b6c9286a 14849 fprintf (file, "\t.tc %s", real_name);
9878760c 14850
1875cc88
JW
14851 if (offset < 0)
14852 fprintf (file, ".N%d", - offset);
14853 else if (offset)
14854 fprintf (file, ".P%d", offset);
9878760c 14855
19d2d16f 14856 fputs ("[TC],", file);
1875cc88 14857 }
581bc4de
MM
14858
14859 /* Currently C++ toc references to vtables can be emitted before it
14860 is decided whether the vtable is public or private. If this is
14861 the case, then the linker will eventually complain that there is
14862 a TOC reference to an unknown section. Thus, for vtables only,
14863 we emit the TOC reference to reference the symbol and not the
14864 section. */
28e510bd 14865 if (VTABLE_NAME_P (name))
581bc4de 14866 {
54ee9799 14867 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
14868 if (offset < 0)
14869 fprintf (file, "%d", offset);
14870 else if (offset > 0)
14871 fprintf (file, "+%d", offset);
14872 }
14873 else
14874 output_addr_const (file, x);
19d2d16f 14875 putc ('\n', file);
9878760c
RK
14876}
14877\f
14878/* Output an assembler pseudo-op to write an ASCII string of N characters
14879 starting at P to FILE.
14880
14881 On the RS/6000, we have to do this using the .byte operation and
14882 write out special characters outside the quoted string.
14883 Also, the assembler is broken; very long strings are truncated,
a4f6c312 14884 so we must artificially break them up early. */
9878760c
RK
14885
14886void
a2369ed3 14887output_ascii (FILE *file, const char *p, int n)
9878760c
RK
14888{
14889 char c;
14890 int i, count_string;
d330fd93
KG
14891 const char *for_string = "\t.byte \"";
14892 const char *for_decimal = "\t.byte ";
14893 const char *to_close = NULL;
9878760c
RK
14894
14895 count_string = 0;
14896 for (i = 0; i < n; i++)
14897 {
14898 c = *p++;
14899 if (c >= ' ' && c < 0177)
14900 {
14901 if (for_string)
14902 fputs (for_string, file);
14903 putc (c, file);
14904
14905 /* Write two quotes to get one. */
14906 if (c == '"')
14907 {
14908 putc (c, file);
14909 ++count_string;
14910 }
14911
14912 for_string = NULL;
14913 for_decimal = "\"\n\t.byte ";
14914 to_close = "\"\n";
14915 ++count_string;
14916
14917 if (count_string >= 512)
14918 {
14919 fputs (to_close, file);
14920
14921 for_string = "\t.byte \"";
14922 for_decimal = "\t.byte ";
14923 to_close = NULL;
14924 count_string = 0;
14925 }
14926 }
14927 else
14928 {
14929 if (for_decimal)
14930 fputs (for_decimal, file);
14931 fprintf (file, "%d", c);
14932
14933 for_string = "\n\t.byte \"";
14934 for_decimal = ", ";
14935 to_close = "\n";
14936 count_string = 0;
14937 }
14938 }
14939
14940 /* Now close the string if we have written one. Then end the line. */
14941 if (to_close)
9ebbca7d 14942 fputs (to_close, file);
9878760c
RK
14943}
14944\f
14945/* Generate a unique section name for FILENAME for a section type
14946 represented by SECTION_DESC. Output goes into BUF.
14947
14948 SECTION_DESC can be any string, as long as it is different for each
14949 possible section type.
14950
14951 We name the section in the same manner as xlc. The name begins with an
14952 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
14953 names) with the last period replaced by the string SECTION_DESC. If
14954 FILENAME does not contain a period, SECTION_DESC is appended to the end of
14955 the name. */
9878760c
RK
14956
14957void
f676971a 14958rs6000_gen_section_name (char **buf, const char *filename,
a2369ed3 14959 const char *section_desc)
9878760c 14960{
9ebbca7d 14961 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
14962 char *p;
14963 int len;
9878760c
RK
14964
14965 after_last_slash = filename;
14966 for (q = filename; *q; q++)
11e5fe42
RK
14967 {
14968 if (*q == '/')
14969 after_last_slash = q + 1;
14970 else if (*q == '.')
14971 last_period = q;
14972 }
9878760c 14973
11e5fe42 14974 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 14975 *buf = (char *) xmalloc (len);
9878760c
RK
14976
14977 p = *buf;
14978 *p++ = '_';
14979
14980 for (q = after_last_slash; *q; q++)
14981 {
11e5fe42 14982 if (q == last_period)
9878760c
RK
14983 {
14984 strcpy (p, section_desc);
14985 p += strlen (section_desc);
e3981aab 14986 break;
9878760c
RK
14987 }
14988
e9a780ec 14989 else if (ISALNUM (*q))
9878760c
RK
14990 *p++ = *q;
14991 }
14992
11e5fe42 14993 if (last_period == 0)
9878760c
RK
14994 strcpy (p, section_desc);
14995 else
14996 *p = '\0';
14997}
e165f3f0 14998\f
a4f6c312 14999/* Emit profile function. */
411707f4 15000
411707f4 15001void
a2369ed3 15002output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 15003{
ffcfcb5f
AM
15004 if (TARGET_PROFILE_KERNEL)
15005 return;
15006
8480e480
CC
15007 if (DEFAULT_ABI == ABI_AIX)
15008 {
9739c90c
JJ
15009#ifndef NO_PROFILE_COUNTERS
15010# define NO_PROFILE_COUNTERS 0
15011#endif
f676971a 15012 if (NO_PROFILE_COUNTERS)
9739c90c
JJ
15013 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
15014 else
15015 {
15016 char buf[30];
15017 const char *label_name;
15018 rtx fun;
411707f4 15019
9739c90c
JJ
15020 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
15021 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
15022 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 15023
9739c90c
JJ
15024 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
15025 fun, Pmode);
15026 }
8480e480 15027 }
ee890fe2
SS
15028 else if (DEFAULT_ABI == ABI_DARWIN)
15029 {
d5fa86ba 15030 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
15031 int caller_addr_regno = LINK_REGISTER_REGNUM;
15032
15033 /* Be conservative and always set this, at least for now. */
15034 current_function_uses_pic_offset_table = 1;
15035
15036#if TARGET_MACHO
15037 /* For PIC code, set up a stub and collect the caller's address
15038 from r0, which is where the prologue puts it. */
11abc112
MM
15039 if (MACHOPIC_INDIRECT
15040 && current_function_uses_pic_offset_table)
15041 caller_addr_regno = 0;
ee890fe2
SS
15042#endif
15043 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
15044 0, VOIDmode, 1,
15045 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
15046 }
411707f4
CC
15047}
15048
a4f6c312 15049/* Write function profiler code. */
e165f3f0
RK
15050
15051void
a2369ed3 15052output_function_profiler (FILE *file, int labelno)
e165f3f0 15053{
3daf36a4 15054 char buf[100];
09eeeacb 15055 int save_lr = 8;
e165f3f0 15056
38c1f2d7 15057 switch (DEFAULT_ABI)
3daf36a4 15058 {
38c1f2d7
MM
15059 default:
15060 abort ();
15061
15062 case ABI_V4:
09eeeacb 15063 save_lr = 4;
09eeeacb
AM
15064 if (!TARGET_32BIT)
15065 {
15066 warning ("no profiling of 64-bit code for this ABI");
15067 return;
15068 }
ffcfcb5f 15069 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
15070 fprintf (file, "\tmflr %s\n", reg_names[0]);
15071 if (flag_pic == 1)
15072 {
dfdfa60f 15073 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
15074 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15075 reg_names[0], save_lr, reg_names[1]);
17167fd8 15076 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 15077 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 15078 assemble_name (file, buf);
17167fd8 15079 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 15080 }
9ebbca7d 15081 else if (flag_pic > 1)
38c1f2d7 15082 {
09eeeacb
AM
15083 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15084 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
15085 /* Now, we need to get the address of the label. */
15086 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 15087 assemble_name (file, buf);
9ebbca7d
GK
15088 fputs ("-.\n1:", file);
15089 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
f676971a 15090 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
9ebbca7d
GK
15091 reg_names[0], reg_names[11]);
15092 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
15093 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 15094 }
38c1f2d7
MM
15095 else
15096 {
17167fd8 15097 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 15098 assemble_name (file, buf);
dfdfa60f 15099 fputs ("@ha\n", file);
09eeeacb
AM
15100 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15101 reg_names[0], save_lr, reg_names[1]);
a260abc9 15102 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 15103 assemble_name (file, buf);
17167fd8 15104 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
15105 }
15106
50d440bc 15107 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
15108 fprintf (file, "\tbl %s%s\n",
15109 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
15110 break;
15111
15112 case ABI_AIX:
ee890fe2 15113 case ABI_DARWIN:
ffcfcb5f
AM
15114 if (!TARGET_PROFILE_KERNEL)
15115 {
a3c9585f 15116 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
15117 }
15118 else
15119 {
15120 if (TARGET_32BIT)
15121 abort ();
15122
15123 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
15124 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
15125
6de9cd9a 15126 if (cfun->static_chain_decl != NULL)
ffcfcb5f
AM
15127 {
15128 asm_fprintf (file, "\tstd %s,24(%s)\n",
15129 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15130 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15131 asm_fprintf (file, "\tld %s,24(%s)\n",
15132 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15133 }
15134 else
15135 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15136 }
38c1f2d7
MM
15137 break;
15138 }
e165f3f0 15139}
a251ffd0 15140
b54cf83a 15141\f
b54cf83a
DE
15142/* Power4 load update and store update instructions are cracked into a
15143 load or store and an integer insn which are executed in the same cycle.
15144 Branches have their own dispatch slot which does not count against the
15145 GCC issue rate, but it changes the program flow so there are no other
15146 instructions to issue in this cycle. */
15147
15148static int
f676971a
EC
15149rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
15150 int verbose ATTRIBUTE_UNUSED,
a2369ed3 15151 rtx insn, int more)
b54cf83a
DE
15152{
15153 if (GET_CODE (PATTERN (insn)) == USE
15154 || GET_CODE (PATTERN (insn)) == CLOBBER)
15155 return more;
15156
ec507f2d 15157 if (rs6000_sched_groups)
b54cf83a 15158 {
cbe26ab8
DN
15159 if (is_microcoded_insn (insn))
15160 return 0;
15161 else if (is_cracked_insn (insn))
15162 return more > 2 ? more - 2 : 0;
b54cf83a 15163 }
165b263e
DE
15164
15165 return more - 1;
b54cf83a
DE
15166}
15167
a251ffd0
TG
15168/* Adjust the cost of a scheduling dependency. Return the new cost of
15169 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
15170
c237e94a 15171static int
f676971a 15172rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
a2369ed3 15173 int cost)
a251ffd0
TG
15174{
15175 if (! recog_memoized (insn))
15176 return 0;
15177
15178 if (REG_NOTE_KIND (link) != 0)
15179 return 0;
15180
15181 if (REG_NOTE_KIND (link) == 0)
15182 {
ed947a96
DJ
15183 /* Data dependency; DEP_INSN writes a register that INSN reads
15184 some cycles later. */
15185 switch (get_attr_type (insn))
15186 {
15187 case TYPE_JMPREG:
309323c2 15188 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
15189 a mtctr and bctr (and mtlr and br/blr). The first
15190 scheduling pass will not know about this latency since
15191 the mtctr instruction, which has the latency associated
15192 to it, will be generated by reload. */
309323c2 15193 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
15194 case TYPE_BRANCH:
15195 /* Leave some extra cycles between a compare and its
15196 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
15197 if ((rs6000_cpu_attr == CPU_PPC603
15198 || rs6000_cpu_attr == CPU_PPC604
15199 || rs6000_cpu_attr == CPU_PPC604E
15200 || rs6000_cpu_attr == CPU_PPC620
15201 || rs6000_cpu_attr == CPU_PPC630
15202 || rs6000_cpu_attr == CPU_PPC750
15203 || rs6000_cpu_attr == CPU_PPC7400
15204 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
15205 || rs6000_cpu_attr == CPU_POWER4
15206 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
15207 && recog_memoized (dep_insn)
15208 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
15209 && (get_attr_type (dep_insn) == TYPE_CMP
15210 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 15211 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
15212 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
15213 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 15214 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
15215 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
15216 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
15217 return cost + 2;
15218 default:
15219 break;
15220 }
a251ffd0
TG
15221 /* Fall out to return default cost. */
15222 }
15223
15224 return cost;
15225}
b6c9286a 15226
cbe26ab8 15227/* The function returns a true if INSN is microcoded.
839a4992 15228 Return false otherwise. */
cbe26ab8
DN
15229
15230static bool
15231is_microcoded_insn (rtx insn)
15232{
15233 if (!insn || !INSN_P (insn)
15234 || GET_CODE (PATTERN (insn)) == USE
15235 || GET_CODE (PATTERN (insn)) == CLOBBER)
15236 return false;
15237
ec507f2d 15238 if (rs6000_sched_groups)
cbe26ab8
DN
15239 {
15240 enum attr_type type = get_attr_type (insn);
15241 if (type == TYPE_LOAD_EXT_U
15242 || type == TYPE_LOAD_EXT_UX
15243 || type == TYPE_LOAD_UX
15244 || type == TYPE_STORE_UX
15245 || type == TYPE_MFCR)
15246 return true;
15247 }
15248
15249 return false;
15250}
15251
5c425df5 15252/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
15253 as the first insn in a dispatch group ("dispatch-slot restricted").
15254 In this case, the returned value indicates how many dispatch slots
15255 the insn occupies (at the beginning of the group).
79ae11c4
DN
15256 Return 0 otherwise. */
15257
cbe26ab8 15258static int
79ae11c4
DN
15259is_dispatch_slot_restricted (rtx insn)
15260{
15261 enum attr_type type;
15262
ec507f2d 15263 if (!rs6000_sched_groups)
79ae11c4
DN
15264 return 0;
15265
15266 if (!insn
15267 || insn == NULL_RTX
15268 || GET_CODE (insn) == NOTE
15269 || GET_CODE (PATTERN (insn)) == USE
15270 || GET_CODE (PATTERN (insn)) == CLOBBER)
15271 return 0;
15272
15273 type = get_attr_type (insn);
15274
ec507f2d
DE
15275 switch (type)
15276 {
15277 case TYPE_MFCR:
15278 case TYPE_MFCRF:
15279 case TYPE_MTCR:
15280 case TYPE_DELAYED_CR:
15281 case TYPE_CR_LOGICAL:
15282 case TYPE_MTJMPR:
15283 case TYPE_MFJMPR:
15284 return 1;
15285 case TYPE_IDIV:
15286 case TYPE_LDIV:
15287 return 2;
15288 default:
15289 if (rs6000_cpu == PROCESSOR_POWER5
15290 && is_cracked_insn (insn))
15291 return 2;
15292 return 0;
15293 }
79ae11c4
DN
15294}
15295
cbe26ab8
DN
15296/* The function returns true if INSN is cracked into 2 instructions
15297 by the processor (and therefore occupies 2 issue slots). */
15298
15299static bool
15300is_cracked_insn (rtx insn)
15301{
15302 if (!insn || !INSN_P (insn)
15303 || GET_CODE (PATTERN (insn)) == USE
15304 || GET_CODE (PATTERN (insn)) == CLOBBER)
15305 return false;
15306
ec507f2d 15307 if (rs6000_sched_groups)
cbe26ab8
DN
15308 {
15309 enum attr_type type = get_attr_type (insn);
15310 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
15311 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
15312 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
15313 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
15314 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
15315 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
15316 || type == TYPE_IDIV || type == TYPE_LDIV
15317 || type == TYPE_INSERT_WORD)
15318 return true;
15319 }
15320
15321 return false;
15322}
15323
15324/* The function returns true if INSN can be issued only from
a3c9585f 15325 the branch slot. */
cbe26ab8
DN
15326
15327static bool
15328is_branch_slot_insn (rtx insn)
15329{
15330 if (!insn || !INSN_P (insn)
15331 || GET_CODE (PATTERN (insn)) == USE
15332 || GET_CODE (PATTERN (insn)) == CLOBBER)
15333 return false;
15334
ec507f2d 15335 if (rs6000_sched_groups)
cbe26ab8
DN
15336 {
15337 enum attr_type type = get_attr_type (insn);
15338 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
f676971a 15339 return true;
cbe26ab8
DN
15340 return false;
15341 }
15342
15343 return false;
15344}
79ae11c4 15345
a4f6c312 15346/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
15347 priority INSN_PRIORITY (INSN). Increase the priority to execute the
15348 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
15349 define this macro if you do not need to adjust the scheduling
15350 priorities of insns. */
bef84347 15351
c237e94a 15352static int
a2369ed3 15353rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 15354{
a4f6c312
SS
15355 /* On machines (like the 750) which have asymmetric integer units,
15356 where one integer unit can do multiply and divides and the other
15357 can't, reduce the priority of multiply/divide so it is scheduled
15358 before other integer operations. */
bef84347
VM
15359
15360#if 0
2c3c49de 15361 if (! INSN_P (insn))
bef84347
VM
15362 return priority;
15363
15364 if (GET_CODE (PATTERN (insn)) == USE)
15365 return priority;
15366
15367 switch (rs6000_cpu_attr) {
15368 case CPU_PPC750:
15369 switch (get_attr_type (insn))
15370 {
15371 default:
15372 break;
15373
15374 case TYPE_IMUL:
15375 case TYPE_IDIV:
3cb999d8
DE
15376 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
15377 priority, priority);
bef84347
VM
15378 if (priority >= 0 && priority < 0x01000000)
15379 priority >>= 3;
15380 break;
15381 }
15382 }
15383#endif
15384
79ae11c4
DN
15385 if (is_dispatch_slot_restricted (insn)
15386 && reload_completed
f676971a 15387 && current_sched_info->sched_max_insns_priority
79ae11c4
DN
15388 && rs6000_sched_restricted_insns_priority)
15389 {
15390
15391 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
15392 if (rs6000_sched_restricted_insns_priority == 1)
f676971a
EC
15393 /* Attach highest priority to insn. This means that in
15394 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
79ae11c4 15395 precede 'priority' (critical path) considerations. */
f676971a 15396 return current_sched_info->sched_max_insns_priority;
79ae11c4 15397 else if (rs6000_sched_restricted_insns_priority == 2)
f676971a 15398 /* Increase priority of insn by a minimal amount. This means that in
79ae11c4
DN
15399 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
15400 precede dispatch-slot restriction considerations. */
f676971a
EC
15401 return (priority + 1);
15402 }
79ae11c4 15403
bef84347
VM
15404 return priority;
15405}
15406
a4f6c312
SS
15407/* Return how many instructions the machine can issue per cycle. */
15408
c237e94a 15409static int
863d938c 15410rs6000_issue_rate (void)
b6c9286a 15411{
3317bab1
DE
15412 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
15413 if (!reload_completed)
15414 return 1;
15415
b6c9286a 15416 switch (rs6000_cpu_attr) {
3cb999d8
DE
15417 case CPU_RIOS1: /* ? */
15418 case CPU_RS64A:
15419 case CPU_PPC601: /* ? */
ed947a96 15420 case CPU_PPC7450:
3cb999d8 15421 return 3;
b54cf83a 15422 case CPU_PPC440:
b6c9286a 15423 case CPU_PPC603:
bef84347 15424 case CPU_PPC750:
ed947a96 15425 case CPU_PPC7400:
be12c2b0 15426 case CPU_PPC8540:
f676971a 15427 return 2;
3cb999d8 15428 case CPU_RIOS2:
b6c9286a 15429 case CPU_PPC604:
19684119 15430 case CPU_PPC604E:
b6c9286a 15431 case CPU_PPC620:
3cb999d8 15432 case CPU_PPC630:
b6c9286a 15433 return 4;
cbe26ab8 15434 case CPU_POWER4:
ec507f2d 15435 case CPU_POWER5:
cbe26ab8 15436 return 5;
b6c9286a
MM
15437 default:
15438 return 1;
15439 }
15440}
15441
be12c2b0
VM
15442/* Return how many instructions to look ahead for better insn
15443 scheduling. */
15444
15445static int
863d938c 15446rs6000_use_sched_lookahead (void)
be12c2b0
VM
15447{
15448 if (rs6000_cpu_attr == CPU_PPC8540)
15449 return 4;
15450 return 0;
15451}
15452
569fa502
DN
15453/* Determine is PAT refers to memory. */
15454
15455static bool
15456is_mem_ref (rtx pat)
15457{
15458 const char * fmt;
15459 int i, j;
15460 bool ret = false;
15461
15462 if (GET_CODE (pat) == MEM)
15463 return true;
15464
15465 /* Recursively process the pattern. */
15466 fmt = GET_RTX_FORMAT (GET_CODE (pat));
15467
15468 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
15469 {
15470 if (fmt[i] == 'e')
15471 ret |= is_mem_ref (XEXP (pat, i));
15472 else if (fmt[i] == 'E')
15473 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
15474 ret |= is_mem_ref (XVECEXP (pat, i, j));
15475 }
15476
15477 return ret;
15478}
15479
15480/* Determine if PAT is a PATTERN of a load insn. */
f676971a 15481
569fa502
DN
15482static bool
15483is_load_insn1 (rtx pat)
15484{
15485 if (!pat || pat == NULL_RTX)
15486 return false;
15487
15488 if (GET_CODE (pat) == SET)
15489 return is_mem_ref (SET_SRC (pat));
15490
15491 if (GET_CODE (pat) == PARALLEL)
15492 {
15493 int i;
15494
15495 for (i = 0; i < XVECLEN (pat, 0); i++)
15496 if (is_load_insn1 (XVECEXP (pat, 0, i)))
15497 return true;
15498 }
15499
15500 return false;
15501}
15502
15503/* Determine if INSN loads from memory. */
15504
15505static bool
15506is_load_insn (rtx insn)
15507{
15508 if (!insn || !INSN_P (insn))
15509 return false;
15510
15511 if (GET_CODE (insn) == CALL_INSN)
15512 return false;
15513
15514 return is_load_insn1 (PATTERN (insn));
15515}
15516
15517/* Determine if PAT is a PATTERN of a store insn. */
15518
15519static bool
15520is_store_insn1 (rtx pat)
15521{
15522 if (!pat || pat == NULL_RTX)
15523 return false;
15524
15525 if (GET_CODE (pat) == SET)
15526 return is_mem_ref (SET_DEST (pat));
15527
15528 if (GET_CODE (pat) == PARALLEL)
15529 {
15530 int i;
15531
15532 for (i = 0; i < XVECLEN (pat, 0); i++)
15533 if (is_store_insn1 (XVECEXP (pat, 0, i)))
15534 return true;
15535 }
15536
15537 return false;
15538}
15539
15540/* Determine if INSN stores to memory. */
15541
15542static bool
15543is_store_insn (rtx insn)
15544{
15545 if (!insn || !INSN_P (insn))
15546 return false;
15547
15548 return is_store_insn1 (PATTERN (insn));
15549}
15550
15551/* Returns whether the dependence between INSN and NEXT is considered
15552 costly by the given target. */
15553
15554static bool
15555rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
f676971a 15556{
569fa502 15557 /* If the flag is not enbled - no dependence is considered costly;
f676971a 15558 allow all dependent insns in the same group.
569fa502
DN
15559 This is the most aggressive option. */
15560 if (rs6000_sched_costly_dep == no_dep_costly)
15561 return false;
15562
f676971a 15563 /* If the flag is set to 1 - a dependence is always considered costly;
569fa502
DN
15564 do not allow dependent instructions in the same group.
15565 This is the most conservative option. */
15566 if (rs6000_sched_costly_dep == all_deps_costly)
f676971a 15567 return true;
569fa502 15568
f676971a
EC
15569 if (rs6000_sched_costly_dep == store_to_load_dep_costly
15570 && is_load_insn (next)
569fa502
DN
15571 && is_store_insn (insn))
15572 /* Prevent load after store in the same group. */
15573 return true;
15574
15575 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
f676971a 15576 && is_load_insn (next)
569fa502
DN
15577 && is_store_insn (insn)
15578 && (!link || (int) REG_NOTE_KIND (link) == 0))
15579 /* Prevent load after store in the same group if it is a true dependence. */
15580 return true;
f676971a
EC
15581
15582 /* The flag is set to X; dependences with latency >= X are considered costly,
569fa502
DN
15583 and will not be scheduled in the same group. */
15584 if (rs6000_sched_costly_dep <= max_dep_latency
15585 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
15586 return true;
15587
15588 return false;
15589}
15590
f676971a 15591/* Return the next insn after INSN that is found before TAIL is reached,
cbe26ab8
DN
15592 skipping any "non-active" insns - insns that will not actually occupy
15593 an issue slot. Return NULL_RTX if such an insn is not found. */
15594
15595static rtx
15596get_next_active_insn (rtx insn, rtx tail)
15597{
15598 rtx next_insn;
15599
15600 if (!insn || insn == tail)
15601 return NULL_RTX;
15602
15603 next_insn = NEXT_INSN (insn);
15604
15605 while (next_insn
15606 && next_insn != tail
15607 && (GET_CODE(next_insn) == NOTE
15608 || GET_CODE (PATTERN (next_insn)) == USE
15609 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
15610 {
15611 next_insn = NEXT_INSN (next_insn);
15612 }
15613
15614 if (!next_insn || next_insn == tail)
15615 return NULL_RTX;
15616
15617 return next_insn;
15618}
15619
839a4992 15620/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
15621 of group WHICH_GROUP.
15622
15623 If WHICH_GROUP == current_group, this function will return true if INSN
15624 causes the termination of the current group (i.e, the dispatch group to
15625 which INSN belongs). This means that INSN will be the last insn in the
15626 group it belongs to.
15627
15628 If WHICH_GROUP == previous_group, this function will return true if INSN
15629 causes the termination of the previous group (i.e, the dispatch group that
15630 precedes the group to which INSN belongs). This means that INSN will be
15631 the first insn in the group it belongs to). */
15632
15633static bool
15634insn_terminates_group_p (rtx insn, enum group_termination which_group)
15635{
15636 enum attr_type type;
15637
15638 if (! insn)
15639 return false;
569fa502 15640
cbe26ab8
DN
15641 type = get_attr_type (insn);
15642
15643 if (is_microcoded_insn (insn))
15644 return true;
15645
15646 if (which_group == current_group)
15647 {
15648 if (is_branch_slot_insn (insn))
15649 return true;
15650 return false;
15651 }
15652 else if (which_group == previous_group)
15653 {
15654 if (is_dispatch_slot_restricted (insn))
15655 return true;
15656 return false;
15657 }
15658
15659 return false;
15660}
15661
839a4992 15662/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
15663 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
15664
15665static bool
15666is_costly_group (rtx *group_insns, rtx next_insn)
15667{
15668 int i;
15669 rtx link;
15670 int cost;
15671 int issue_rate = rs6000_issue_rate ();
15672
15673 for (i = 0; i < issue_rate; i++)
15674 {
15675 rtx insn = group_insns[i];
15676 if (!insn)
15677 continue;
15678 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
15679 {
15680 rtx next = XEXP (link, 0);
15681 if (next == next_insn)
15682 {
15683 cost = insn_cost (insn, link, next_insn);
15684 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
15685 return true;
15686 }
15687 }
15688 }
15689
15690 return false;
15691}
15692
f676971a 15693/* Utility of the function redefine_groups.
cbe26ab8
DN
15694 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
15695 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
15696 to keep it "far" (in a separate group) from GROUP_INSNS, following
15697 one of the following schemes, depending on the value of the flag
15698 -minsert_sched_nops = X:
15699 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 15700 in order to force NEXT_INSN into a separate group.
f676971a
EC
15701 (2) X < sched_finish_regroup_exact: insert exactly X nops.
15702 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
cbe26ab8
DN
15703 insertion (has a group just ended, how many vacant issue slots remain in the
15704 last group, and how many dispatch groups were encountered so far). */
15705
f676971a 15706static int
cbe26ab8
DN
15707force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
15708 bool *group_end, int can_issue_more, int *group_count)
15709{
15710 rtx nop;
15711 bool force;
15712 int issue_rate = rs6000_issue_rate ();
15713 bool end = *group_end;
15714 int i;
15715
15716 if (next_insn == NULL_RTX)
15717 return can_issue_more;
15718
15719 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
15720 return can_issue_more;
15721
15722 force = is_costly_group (group_insns, next_insn);
15723 if (!force)
15724 return can_issue_more;
15725
15726 if (sched_verbose > 6)
15727 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
15728 *group_count ,can_issue_more);
15729
15730 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
15731 {
15732 if (*group_end)
15733 can_issue_more = 0;
15734
15735 /* Since only a branch can be issued in the last issue_slot, it is
15736 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
15737 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
15738 in this case the last nop will start a new group and the branch will be
15739 forced to the new group. */
15740 if (can_issue_more && !is_branch_slot_insn (next_insn))
15741 can_issue_more--;
15742
15743 while (can_issue_more > 0)
15744 {
15745 nop = gen_nop();
15746 emit_insn_before (nop, next_insn);
15747 can_issue_more--;
15748 }
15749
15750 *group_end = true;
15751 return 0;
f676971a 15752 }
cbe26ab8
DN
15753
15754 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
15755 {
15756 int n_nops = rs6000_sched_insert_nops;
15757
f676971a 15758 /* Nops can't be issued from the branch slot, so the effective
cbe26ab8
DN
15759 issue_rate for nops is 'issue_rate - 1'. */
15760 if (can_issue_more == 0)
15761 can_issue_more = issue_rate;
15762 can_issue_more--;
15763 if (can_issue_more == 0)
15764 {
15765 can_issue_more = issue_rate - 1;
15766 (*group_count)++;
15767 end = true;
15768 for (i = 0; i < issue_rate; i++)
15769 {
15770 group_insns[i] = 0;
15771 }
15772 }
15773
15774 while (n_nops > 0)
15775 {
15776 nop = gen_nop ();
15777 emit_insn_before (nop, next_insn);
15778 if (can_issue_more == issue_rate - 1) /* new group begins */
15779 end = false;
15780 can_issue_more--;
15781 if (can_issue_more == 0)
15782 {
15783 can_issue_more = issue_rate - 1;
15784 (*group_count)++;
15785 end = true;
15786 for (i = 0; i < issue_rate; i++)
15787 {
15788 group_insns[i] = 0;
f676971a
EC
15789 }
15790 }
cbe26ab8
DN
15791 n_nops--;
15792 }
15793
15794 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
f676971a 15795 can_issue_more++;
cbe26ab8
DN
15796
15797 *group_end = /* Is next_insn going to start a new group? */
f676971a 15798 (end
cbe26ab8
DN
15799 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
15800 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
15801 || (can_issue_more < issue_rate &&
15802 insn_terminates_group_p (next_insn, previous_group)));
15803 if (*group_end && end)
15804 (*group_count)--;
15805
15806 if (sched_verbose > 6)
15807 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
15808 *group_count, can_issue_more);
f676971a
EC
15809 return can_issue_more;
15810 }
cbe26ab8
DN
15811
15812 return can_issue_more;
15813}
15814
15815/* This function tries to synch the dispatch groups that the compiler "sees"
f676971a 15816 with the dispatch groups that the processor dispatcher is expected to
cbe26ab8
DN
15817 form in practice. It tries to achieve this synchronization by forcing the
15818 estimated processor grouping on the compiler (as opposed to the function
15819 'pad_goups' which tries to force the scheduler's grouping on the processor).
15820
15821 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
15822 examines the (estimated) dispatch groups that will be formed by the processor
15823 dispatcher. It marks these group boundaries to reflect the estimated
15824 processor grouping, overriding the grouping that the scheduler had marked.
15825 Depending on the value of the flag '-minsert-sched-nops' this function can
15826 force certain insns into separate groups or force a certain distance between
15827 them by inserting nops, for example, if there exists a "costly dependence"
15828 between the insns.
15829
15830 The function estimates the group boundaries that the processor will form as
15831 folllows: It keeps track of how many vacant issue slots are available after
15832 each insn. A subsequent insn will start a new group if one of the following
15833 4 cases applies:
15834 - no more vacant issue slots remain in the current dispatch group.
15835 - only the last issue slot, which is the branch slot, is vacant, but the next
15836 insn is not a branch.
15837 - only the last 2 or less issue slots, including the branch slot, are vacant,
15838 which means that a cracked insn (which occupies two issue slots) can't be
15839 issued in this group.
f676971a 15840 - less than 'issue_rate' slots are vacant, and the next insn always needs to
cbe26ab8
DN
15841 start a new group. */
15842
15843static int
15844redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
15845{
15846 rtx insn, next_insn;
15847 int issue_rate;
15848 int can_issue_more;
15849 int slot, i;
15850 bool group_end;
15851 int group_count = 0;
15852 rtx *group_insns;
15853
15854 /* Initialize. */
15855 issue_rate = rs6000_issue_rate ();
15856 group_insns = alloca (issue_rate * sizeof (rtx));
f676971a 15857 for (i = 0; i < issue_rate; i++)
cbe26ab8
DN
15858 {
15859 group_insns[i] = 0;
15860 }
15861 can_issue_more = issue_rate;
15862 slot = 0;
15863 insn = get_next_active_insn (prev_head_insn, tail);
15864 group_end = false;
15865
15866 while (insn != NULL_RTX)
15867 {
15868 slot = (issue_rate - can_issue_more);
15869 group_insns[slot] = insn;
15870 can_issue_more =
15871 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
15872 if (insn_terminates_group_p (insn, current_group))
15873 can_issue_more = 0;
15874
15875 next_insn = get_next_active_insn (insn, tail);
15876 if (next_insn == NULL_RTX)
15877 return group_count + 1;
15878
15879 group_end = /* Is next_insn going to start a new group? */
15880 (can_issue_more == 0
15881 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
15882 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
15883 || (can_issue_more < issue_rate &&
15884 insn_terminates_group_p (next_insn, previous_group)));
15885
f676971a 15886 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
cbe26ab8
DN
15887 next_insn, &group_end, can_issue_more, &group_count);
15888
15889 if (group_end)
15890 {
15891 group_count++;
15892 can_issue_more = 0;
15893 for (i = 0; i < issue_rate; i++)
15894 {
15895 group_insns[i] = 0;
15896 }
15897 }
15898
15899 if (GET_MODE (next_insn) == TImode && can_issue_more)
15900 PUT_MODE(next_insn, VOIDmode);
15901 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
15902 PUT_MODE (next_insn, TImode);
15903
15904 insn = next_insn;
15905 if (can_issue_more == 0)
15906 can_issue_more = issue_rate;
15907 } /* while */
15908
15909 return group_count;
15910}
15911
15912/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
15913 dispatch group boundaries that the scheduler had marked. Pad with nops
15914 any dispatch groups which have vacant issue slots, in order to force the
15915 scheduler's grouping on the processor dispatcher. The function
15916 returns the number of dispatch groups found. */
15917
15918static int
15919pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
15920{
15921 rtx insn, next_insn;
15922 rtx nop;
15923 int issue_rate;
15924 int can_issue_more;
15925 int group_end;
15926 int group_count = 0;
15927
15928 /* Initialize issue_rate. */
15929 issue_rate = rs6000_issue_rate ();
15930 can_issue_more = issue_rate;
15931
15932 insn = get_next_active_insn (prev_head_insn, tail);
15933 next_insn = get_next_active_insn (insn, tail);
15934
15935 while (insn != NULL_RTX)
15936 {
15937 can_issue_more =
15938 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
15939
15940 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
15941
15942 if (next_insn == NULL_RTX)
15943 break;
15944
15945 if (group_end)
15946 {
15947 /* If the scheduler had marked group termination at this location
15948 (between insn and next_indn), and neither insn nor next_insn will
15949 force group termination, pad the group with nops to force group
15950 termination. */
15951 if (can_issue_more
15952 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
15953 && !insn_terminates_group_p (insn, current_group)
15954 && !insn_terminates_group_p (next_insn, previous_group))
15955 {
15956 if (!is_branch_slot_insn(next_insn))
15957 can_issue_more--;
15958
15959 while (can_issue_more)
15960 {
15961 nop = gen_nop ();
15962 emit_insn_before (nop, next_insn);
15963 can_issue_more--;
15964 }
15965 }
15966
15967 can_issue_more = issue_rate;
15968 group_count++;
15969 }
15970
15971 insn = next_insn;
15972 next_insn = get_next_active_insn (insn, tail);
15973 }
15974
15975 return group_count;
15976}
15977
15978/* The following function is called at the end of scheduling BB.
15979 After reload, it inserts nops at insn group bundling. */
15980
15981static void
38f391a5 15982rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
15983{
15984 int n_groups;
15985
15986 if (sched_verbose)
15987 fprintf (dump, "=== Finishing schedule.\n");
15988
ec507f2d 15989 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
15990 {
15991 if (rs6000_sched_insert_nops == sched_finish_none)
15992 return;
15993
15994 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
15995 n_groups = pad_groups (dump, sched_verbose,
15996 current_sched_info->prev_head,
15997 current_sched_info->next_tail);
15998 else
15999 n_groups = redefine_groups (dump, sched_verbose,
16000 current_sched_info->prev_head,
16001 current_sched_info->next_tail);
16002
16003 if (sched_verbose >= 6)
16004 {
16005 fprintf (dump, "ngroups = %d\n", n_groups);
16006 print_rtl (dump, current_sched_info->prev_head);
16007 fprintf (dump, "Done finish_sched\n");
16008 }
16009 }
16010}
b6c9286a 16011\f
b6c9286a
MM
16012/* Length in units of the trampoline for entering a nested function. */
16013
16014int
863d938c 16015rs6000_trampoline_size (void)
b6c9286a
MM
16016{
16017 int ret = 0;
16018
16019 switch (DEFAULT_ABI)
16020 {
16021 default:
16022 abort ();
16023
16024 case ABI_AIX:
8f802bfb 16025 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
16026 break;
16027
4dabc42d 16028 case ABI_DARWIN:
b6c9286a 16029 case ABI_V4:
03a7e1a5 16030 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 16031 break;
b6c9286a
MM
16032 }
16033
16034 return ret;
16035}
16036
16037/* Emit RTL insns to initialize the variable parts of a trampoline.
16038 FNADDR is an RTX for the address of the function's pure code.
16039 CXT is an RTX for the static chain value for the function. */
16040
16041void
a2369ed3 16042rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 16043{
ac2a93a1 16044 enum machine_mode pmode = Pmode;
8bd04c56
MM
16045 int regsize = (TARGET_32BIT) ? 4 : 8;
16046 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
16047
16048 switch (DEFAULT_ABI)
16049 {
16050 default:
16051 abort ();
16052
8bd04c56 16053/* Macros to shorten the code expansions below. */
39403d82 16054#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
16055#define MEM_PLUS(addr,offset) \
16056 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 16057
b6c9286a
MM
16058 /* Under AIX, just build the 3 word function descriptor */
16059 case ABI_AIX:
8bd04c56
MM
16060 {
16061 rtx fn_reg = gen_reg_rtx (pmode);
16062 rtx toc_reg = gen_reg_rtx (pmode);
16063 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 16064 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
16065 emit_move_insn (MEM_DEREF (addr), fn_reg);
16066 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
16067 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
16068 }
b6c9286a
MM
16069 break;
16070
4dabc42d
TC
16071 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
16072 case ABI_DARWIN:
b6c9286a 16073 case ABI_V4:
39403d82 16074 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
16075 FALSE, VOIDmode, 4,
16076 addr, pmode,
16077 GEN_INT (rs6000_trampoline_size ()), SImode,
16078 fnaddr, pmode,
16079 ctx_reg, pmode);
b6c9286a 16080 break;
b6c9286a
MM
16081 }
16082
16083 return;
16084}
7509c759
MM
16085
16086\f
91d231cb 16087/* Table of valid machine attributes. */
a4f6c312 16088
91d231cb 16089const struct attribute_spec rs6000_attribute_table[] =
7509c759 16090{
91d231cb 16091 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 16092 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
16093 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16094 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16095 { NULL, 0, 0, false, false, false, NULL }
91d231cb 16096};
7509c759 16097
8bb418a3
ZL
16098/* Handle the "altivec" attribute. The attribute may have
16099 arguments as follows:
f676971a 16100
8bb418a3
ZL
16101 __attribute__((altivec(vector__)))
16102 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
16103 __attribute__((altivec(bool__))) (always followed by 'unsigned')
16104
16105 and may appear more than once (e.g., 'vector bool char') in a
16106 given declaration. */
16107
16108static tree
16109rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
16110 int flags ATTRIBUTE_UNUSED,
16111 bool *no_add_attrs)
16112{
16113 tree type = *node, result = NULL_TREE;
16114 enum machine_mode mode;
16115 int unsigned_p;
16116 char altivec_type
16117 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
16118 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
16119 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
f676971a 16120 : '?');
8bb418a3
ZL
16121
16122 while (POINTER_TYPE_P (type)
16123 || TREE_CODE (type) == FUNCTION_TYPE
16124 || TREE_CODE (type) == METHOD_TYPE
16125 || TREE_CODE (type) == ARRAY_TYPE)
16126 type = TREE_TYPE (type);
16127
16128 mode = TYPE_MODE (type);
16129
16130 if (rs6000_warn_altivec_long
16131 && (type == long_unsigned_type_node || type == long_integer_type_node))
16132 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
16133
16134 switch (altivec_type)
16135 {
16136 case 'v':
8df83eae 16137 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
16138 switch (mode)
16139 {
16140 case SImode:
16141 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
16142 break;
16143 case HImode:
16144 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
16145 break;
16146 case QImode:
16147 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
16148 break;
16149 case SFmode: result = V4SF_type_node; break;
16150 /* If the user says 'vector int bool', we may be handed the 'bool'
16151 attribute _before_ the 'vector' attribute, and so select the proper
16152 type in the 'b' case below. */
16153 case V4SImode: case V8HImode: case V16QImode: result = type;
16154 default: break;
16155 }
16156 break;
16157 case 'b':
16158 switch (mode)
16159 {
16160 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
16161 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
16162 case QImode: case V16QImode: result = bool_V16QI_type_node;
16163 default: break;
16164 }
16165 break;
16166 case 'p':
16167 switch (mode)
16168 {
16169 case V8HImode: result = pixel_V8HI_type_node;
16170 default: break;
16171 }
16172 default: break;
16173 }
16174
7958a2a6
FJ
16175 if (result && result != type && TYPE_READONLY (type))
16176 result = build_qualified_type (result, TYPE_QUAL_CONST);
16177
8bb418a3
ZL
16178 *no_add_attrs = true; /* No need to hang on to the attribute. */
16179
16180 if (!result)
16181 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
16182 else
16183 *node = reconstruct_complex_type (*node, result);
16184
16185 return NULL_TREE;
16186}
16187
f18eca82
ZL
16188/* AltiVec defines four built-in scalar types that serve as vector
16189 elements; we must teach the compiler how to mangle them. */
16190
16191static const char *
16192rs6000_mangle_fundamental_type (tree type)
16193{
16194 if (type == bool_char_type_node) return "U6__boolc";
16195 if (type == bool_short_type_node) return "U6__bools";
16196 if (type == pixel_type_node) return "u7__pixel";
16197 if (type == bool_int_type_node) return "U6__booli";
16198
16199 /* For all other types, use normal C++ mangling. */
16200 return NULL;
16201}
16202
a5c76ee6
ZW
16203/* Handle a "longcall" or "shortcall" attribute; arguments as in
16204 struct attribute_spec.handler. */
a4f6c312 16205
91d231cb 16206static tree
f676971a
EC
16207rs6000_handle_longcall_attribute (tree *node, tree name,
16208 tree args ATTRIBUTE_UNUSED,
16209 int flags ATTRIBUTE_UNUSED,
a2369ed3 16210 bool *no_add_attrs)
91d231cb
JM
16211{
16212 if (TREE_CODE (*node) != FUNCTION_TYPE
16213 && TREE_CODE (*node) != FIELD_DECL
16214 && TREE_CODE (*node) != TYPE_DECL)
16215 {
16216 warning ("`%s' attribute only applies to functions",
16217 IDENTIFIER_POINTER (name));
16218 *no_add_attrs = true;
16219 }
6a4cee5f 16220
91d231cb 16221 return NULL_TREE;
7509c759
MM
16222}
16223
a5c76ee6
ZW
16224/* Set longcall attributes on all functions declared when
16225 rs6000_default_long_calls is true. */
16226static void
a2369ed3 16227rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
16228{
16229 if (rs6000_default_long_calls
16230 && (TREE_CODE (type) == FUNCTION_TYPE
16231 || TREE_CODE (type) == METHOD_TYPE))
16232 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
16233 NULL_TREE,
16234 TYPE_ATTRIBUTES (type));
16235}
16236
3cb999d8
DE
16237/* Return a reference suitable for calling a function with the
16238 longcall attribute. */
a4f6c312 16239
6a4cee5f 16240struct rtx_def *
a2369ed3 16241rs6000_longcall_ref (rtx call_ref)
6a4cee5f 16242{
d330fd93 16243 const char *call_name;
6a4cee5f
MM
16244 tree node;
16245
16246 if (GET_CODE (call_ref) != SYMBOL_REF)
16247 return call_ref;
16248
16249 /* System V adds '.' to the internal name, so skip them. */
16250 call_name = XSTR (call_ref, 0);
16251 if (*call_name == '.')
16252 {
16253 while (*call_name == '.')
16254 call_name++;
16255
16256 node = get_identifier (call_name);
39403d82 16257 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
16258 }
16259
16260 return force_reg (Pmode, call_ref);
16261}
7509c759 16262\f
b64a1b53
RH
16263#ifdef USING_ELFOS_H
16264
7509c759
MM
16265/* A C statement or statements to switch to the appropriate section
16266 for output of RTX in mode MODE. You can assume that RTX is some
16267 kind of constant in RTL. The argument MODE is redundant except in
16268 the case of a `const_int' rtx. Select the section by calling
16269 `text_section' or one of the alternatives for other sections.
16270
16271 Do not define this macro if you put all constants in the read-only
16272 data section. */
16273
b64a1b53 16274static void
f676971a 16275rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
a2369ed3 16276 unsigned HOST_WIDE_INT align)
7509c759 16277{
a9098fd0 16278 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 16279 toc_section ();
7509c759 16280 else
b64a1b53 16281 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
16282}
16283
16284/* A C statement or statements to switch to the appropriate
16285 section for output of DECL. DECL is either a `VAR_DECL' node
16286 or a constant of some sort. RELOC indicates whether forming
16287 the initial value of DECL requires link-time relocations. */
16288
ae46c4e0 16289static void
f676971a 16290rs6000_elf_select_section (tree decl, int reloc,
a2369ed3 16291 unsigned HOST_WIDE_INT align)
7509c759 16292{
f1384257
AM
16293 /* Pretend that we're always building for a shared library when
16294 ABI_AIX, because otherwise we end up with dynamic relocations
16295 in read-only sections. This happens for function pointers,
16296 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
16297 default_elf_select_section_1 (decl, reloc, align,
16298 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
16299}
16300
16301/* A C statement to build up a unique section name, expressed as a
16302 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
16303 RELOC indicates whether the initial value of EXP requires
16304 link-time relocations. If you do not define this macro, GCC will use
16305 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 16306 macro can now be called for uninitialized data items as well as
4912a07c 16307 initialized data and functions. */
63019373 16308
ae46c4e0 16309static void
a2369ed3 16310rs6000_elf_unique_section (tree decl, int reloc)
63019373 16311{
f1384257
AM
16312 /* As above, pretend that we're always building for a shared library
16313 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
16314 default_unique_section_1 (decl, reloc,
16315 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 16316}
d9407988 16317\f
d1908feb
JJ
16318/* For a SYMBOL_REF, set generic flags and then perform some
16319 target-specific processing.
16320
d1908feb
JJ
16321 When the AIX ABI is requested on a non-AIX system, replace the
16322 function name with the real name (with a leading .) rather than the
16323 function descriptor name. This saves a lot of overriding code to
16324 read the prefixes. */
d9407988 16325
fb49053f 16326static void
a2369ed3 16327rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 16328{
d1908feb 16329 default_encode_section_info (decl, rtl, first);
b2003250 16330
d1908feb
JJ
16331 if (first
16332 && TREE_CODE (decl) == FUNCTION_DECL
16333 && !TARGET_AIX
16334 && DEFAULT_ABI == ABI_AIX)
d9407988 16335 {
c6a2438a 16336 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
16337 size_t len = strlen (XSTR (sym_ref, 0));
16338 char *str = alloca (len + 2);
16339 str[0] = '.';
16340 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
16341 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 16342 }
d9407988
MM
16343}
16344
0e5dbd9b 16345static bool
a2369ed3 16346rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
16347{
16348 if (rs6000_sdata == SDATA_NONE)
16349 return false;
16350
16351 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
16352 {
16353 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
16354 if (strcmp (section, ".sdata") == 0
16355 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
16356 || strcmp (section, ".sbss") == 0
16357 || strcmp (section, ".sbss2") == 0
16358 || strcmp (section, ".PPC.EMB.sdata0") == 0
16359 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
16360 return true;
16361 }
16362 else
16363 {
16364 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
16365
16366 if (size > 0
307b599c 16367 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
16368 /* If it's not public, and we're not going to reference it there,
16369 there's no need to put it in the small data section. */
0e5dbd9b
DE
16370 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
16371 return true;
16372 }
16373
16374 return false;
16375}
16376
b91da81f 16377#endif /* USING_ELFOS_H */
000034eb 16378
a6c2a102 16379\f
000034eb 16380/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
16381 ADDR can be effectively incremented by incrementing REG.
16382
16383 r0 is special and we must not select it as an address
16384 register by this routine since our caller will try to
16385 increment the returned register via an "la" instruction. */
000034eb
DE
16386
16387struct rtx_def *
a2369ed3 16388find_addr_reg (rtx addr)
000034eb
DE
16389{
16390 while (GET_CODE (addr) == PLUS)
16391 {
02441cd6
JL
16392 if (GET_CODE (XEXP (addr, 0)) == REG
16393 && REGNO (XEXP (addr, 0)) != 0)
000034eb 16394 addr = XEXP (addr, 0);
02441cd6
JL
16395 else if (GET_CODE (XEXP (addr, 1)) == REG
16396 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
16397 addr = XEXP (addr, 1);
16398 else if (CONSTANT_P (XEXP (addr, 0)))
16399 addr = XEXP (addr, 1);
16400 else if (CONSTANT_P (XEXP (addr, 1)))
16401 addr = XEXP (addr, 0);
16402 else
16403 abort ();
16404 }
02441cd6 16405 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
16406 return addr;
16407 abort ();
16408}
16409
a6c2a102 16410void
a2369ed3 16411rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
16412{
16413 fatal_insn ("bad address", op);
16414}
c8023011 16415
ee890fe2
SS
16416#if TARGET_MACHO
16417
16418#if 0
16419/* Returns 1 if OP is either a symbol reference or a sum of a symbol
16420 reference and a constant. */
16421
16422int
a2369ed3 16423symbolic_operand (rtx op)
ee890fe2
SS
16424{
16425 switch (GET_CODE (op))
16426 {
16427 case SYMBOL_REF:
16428 case LABEL_REF:
16429 return 1;
16430 case CONST:
16431 op = XEXP (op, 0);
16432 return (GET_CODE (op) == SYMBOL_REF ||
16433 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
16434 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
16435 && GET_CODE (XEXP (op, 1)) == CONST_INT);
16436 default:
16437 return 0;
16438 }
c8023011 16439}
ee890fe2
SS
16440#endif
16441
efdba735 16442#if TARGET_MACHO
ee890fe2 16443
efdba735 16444static tree branch_island_list = 0;
ee890fe2 16445
efdba735
SH
16446/* Remember to generate a branch island for far calls to the given
16447 function. */
ee890fe2 16448
f676971a 16449static void
efdba735 16450add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 16451{
efdba735 16452 tree branch_island = build_tree_list (function_name, label_name);
7d60be94 16453 TREE_TYPE (branch_island) = build_int_cst (NULL_TREE, line_number);
efdba735
SH
16454 TREE_CHAIN (branch_island) = branch_island_list;
16455 branch_island_list = branch_island;
ee890fe2
SS
16456}
16457
efdba735
SH
16458#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
16459#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
16460#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
16461 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 16462
efdba735
SH
16463/* Generate far-jump branch islands for everything on the
16464 branch_island_list. Invoked immediately after the last instruction
16465 of the epilogue has been emitted; the branch-islands must be
16466 appended to, and contiguous with, the function body. Mach-O stubs
16467 are generated in machopic_output_stub(). */
ee890fe2 16468
efdba735
SH
16469static void
16470macho_branch_islands (void)
16471{
16472 char tmp_buf[512];
16473 tree branch_island;
16474
16475 for (branch_island = branch_island_list;
16476 branch_island;
16477 branch_island = TREE_CHAIN (branch_island))
16478 {
16479 const char *label =
16480 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
16481 const char *name =
11abc112 16482 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island));
efdba735
SH
16483 char name_buf[512];
16484 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
16485 if (name[0] == '*' || name[0] == '&')
16486 strcpy (name_buf, name+1);
16487 else
16488 {
16489 name_buf[0] = '_';
16490 strcpy (name_buf+1, name);
16491 }
16492 strcpy (tmp_buf, "\n");
16493 strcat (tmp_buf, label);
ee890fe2 16494#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16495 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16496 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16497 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 16498#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
16499 if (flag_pic)
16500 {
16501 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
16502 strcat (tmp_buf, label);
16503 strcat (tmp_buf, "_pic\n");
16504 strcat (tmp_buf, label);
16505 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
f676971a 16506
efdba735
SH
16507 strcat (tmp_buf, "\taddis r11,r11,ha16(");
16508 strcat (tmp_buf, name_buf);
16509 strcat (tmp_buf, " - ");
16510 strcat (tmp_buf, label);
16511 strcat (tmp_buf, "_pic)\n");
f676971a 16512
efdba735 16513 strcat (tmp_buf, "\tmtlr r0\n");
f676971a 16514
efdba735
SH
16515 strcat (tmp_buf, "\taddi r12,r11,lo16(");
16516 strcat (tmp_buf, name_buf);
16517 strcat (tmp_buf, " - ");
16518 strcat (tmp_buf, label);
16519 strcat (tmp_buf, "_pic)\n");
f676971a 16520
efdba735
SH
16521 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
16522 }
16523 else
16524 {
16525 strcat (tmp_buf, ":\nlis r12,hi16(");
16526 strcat (tmp_buf, name_buf);
16527 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
16528 strcat (tmp_buf, name_buf);
16529 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
16530 }
16531 output_asm_insn (tmp_buf, 0);
ee890fe2 16532#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16533 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16534 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16535 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 16536#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 16537 }
ee890fe2 16538
efdba735 16539 branch_island_list = 0;
ee890fe2
SS
16540}
16541
16542/* NO_PREVIOUS_DEF checks in the link list whether the function name is
16543 already there or not. */
16544
efdba735 16545static int
a2369ed3 16546no_previous_def (tree function_name)
ee890fe2 16547{
efdba735
SH
16548 tree branch_island;
16549 for (branch_island = branch_island_list;
16550 branch_island;
16551 branch_island = TREE_CHAIN (branch_island))
16552 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
16553 return 0;
16554 return 1;
16555}
16556
16557/* GET_PREV_LABEL gets the label name from the previous definition of
16558 the function. */
16559
efdba735 16560static tree
a2369ed3 16561get_prev_label (tree function_name)
ee890fe2 16562{
efdba735
SH
16563 tree branch_island;
16564 for (branch_island = branch_island_list;
16565 branch_island;
16566 branch_island = TREE_CHAIN (branch_island))
16567 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
16568 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
16569 return 0;
16570}
16571
16572/* INSN is either a function call or a millicode call. It may have an
f676971a 16573 unconditional jump in its delay slot.
ee890fe2
SS
16574
16575 CALL_DEST is the routine we are calling. */
16576
16577char *
efdba735 16578output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
16579{
16580 static char buf[256];
efdba735
SH
16581 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
16582 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
16583 {
16584 tree labelname;
efdba735 16585 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
f676971a 16586
ee890fe2
SS
16587 if (no_previous_def (funname))
16588 {
308c142a 16589 int line_number = 0;
ee890fe2
SS
16590 rtx label_rtx = gen_label_rtx ();
16591 char *label_buf, temp_buf[256];
16592 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
16593 CODE_LABEL_NUMBER (label_rtx));
16594 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
16595 labelname = get_identifier (label_buf);
16596 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
16597 if (insn)
16598 line_number = NOTE_LINE_NUMBER (insn);
efdba735 16599 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
16600 }
16601 else
16602 labelname = get_prev_label (funname);
16603
efdba735
SH
16604 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
16605 instruction will reach 'foo', otherwise link as 'bl L42'".
16606 "L42" should be a 'branch island', that will do a far jump to
16607 'foo'. Branch islands are generated in
16608 macho_branch_islands(). */
ee890fe2 16609 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 16610 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
16611 }
16612 else
efdba735
SH
16613 sprintf (buf, "bl %%z%d", dest_operand_number);
16614 return buf;
ee890fe2
SS
16615}
16616
efdba735 16617#endif /* TARGET_MACHO */
ee890fe2 16618
ee890fe2
SS
16619/* Generate PIC and indirect symbol stubs. */
16620
16621void
a2369ed3 16622machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
16623{
16624 unsigned int length;
a4f6c312
SS
16625 char *symbol_name, *lazy_ptr_name;
16626 char *local_label_0;
ee890fe2
SS
16627 static int label = 0;
16628
df56a27f 16629 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 16630 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 16631
ee890fe2 16632
ee890fe2
SS
16633 length = strlen (symb);
16634 symbol_name = alloca (length + 32);
16635 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
16636
16637 lazy_ptr_name = alloca (length + 32);
16638 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
16639
ee890fe2 16640 if (flag_pic == 2)
d3c300d2 16641 machopic_picsymbol_stub1_section ();
ee890fe2 16642 else
d3c300d2 16643 machopic_symbol_stub1_section ();
ee890fe2
SS
16644
16645 if (flag_pic == 2)
16646 {
d974312d
DJ
16647 fprintf (file, "\t.align 5\n");
16648
16649 fprintf (file, "%s:\n", stub);
16650 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
16651
876455fa
AP
16652 label++;
16653 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
16654 sprintf (local_label_0, "\"L%011d$spb\"", label);
f676971a 16655
ee890fe2
SS
16656 fprintf (file, "\tmflr r0\n");
16657 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
16658 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
16659 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
16660 lazy_ptr_name, local_label_0);
16661 fprintf (file, "\tmtlr r0\n");
d3c300d2 16662 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
16663 lazy_ptr_name, local_label_0);
16664 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
16665 fprintf (file, "\tbctr\n");
16666 }
16667 else
d974312d
DJ
16668 {
16669 fprintf (file, "\t.align 4\n");
16670
16671 fprintf (file, "%s:\n", stub);
16672 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
16673
16674 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
16675 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
16676 fprintf (file, "\tmtctr r12\n");
16677 fprintf (file, "\tbctr\n");
16678 }
f676971a 16679
ee890fe2
SS
16680 machopic_lazy_symbol_ptr_section ();
16681 fprintf (file, "%s:\n", lazy_ptr_name);
16682 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
49bd1d27
SS
16683 fprintf (file, "%sdyld_stub_binding_helper\n",
16684 (TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t"));
ee890fe2
SS
16685}
16686
16687/* Legitimize PIC addresses. If the address is already
16688 position-independent, we return ORIG. Newly generated
16689 position-independent addresses go into a reg. This is REG if non
16690 zero, otherwise we allocate register(s) as necessary. */
16691
c859cda6 16692#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
16693
16694rtx
f676971a 16695rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
a2369ed3 16696 rtx reg)
ee890fe2
SS
16697{
16698 rtx base, offset;
16699
16700 if (reg == NULL && ! reload_in_progress && ! reload_completed)
16701 reg = gen_reg_rtx (Pmode);
16702
16703 if (GET_CODE (orig) == CONST)
16704 {
16705 if (GET_CODE (XEXP (orig, 0)) == PLUS
16706 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
16707 return orig;
16708
16709 if (GET_CODE (XEXP (orig, 0)) == PLUS)
16710 {
2cf520bf 16711 /* Use a different reg for the intermediate value, as
a3c9585f 16712 it will be marked UNCHANGING. */
2cf520bf
GK
16713 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
16714
a4f6c312
SS
16715 base =
16716 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 16717 Pmode, reg_temp);
a4f6c312
SS
16718 offset =
16719 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
16720 Pmode, reg);
ee890fe2
SS
16721 }
16722 else
16723 abort ();
16724
16725 if (GET_CODE (offset) == CONST_INT)
16726 {
16727 if (SMALL_INT (offset))
ed8908e7 16728 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
16729 else if (! reload_in_progress && ! reload_completed)
16730 offset = force_reg (Pmode, offset);
16731 else
c859cda6
DJ
16732 {
16733 rtx mem = force_const_mem (Pmode, orig);
16734 return machopic_legitimize_pic_address (mem, Pmode, reg);
16735 }
ee890fe2 16736 }
f1c25d3b 16737 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
16738 }
16739
16740 /* Fall back on generic machopic code. */
16741 return machopic_legitimize_pic_address (orig, mode, reg);
16742}
16743
16744/* This is just a placeholder to make linking work without having to
16745 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
16746 ever needed for Darwin (not too likely!) this would have to get a
16747 real definition. */
16748
16749void
863d938c 16750toc_section (void)
ee890fe2
SS
16751{
16752}
16753
16754#endif /* TARGET_MACHO */
7c262518
RH
16755
16756#if TARGET_ELF
16757static unsigned int
a2369ed3 16758rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 16759{
1ff8f81a
AM
16760 return default_section_type_flags_1 (decl, name, reloc,
16761 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 16762}
d9f6800d
RH
16763
16764/* Record an element in the table of global constructors. SYMBOL is
16765 a SYMBOL_REF of the function to be called; PRIORITY is a number
16766 between 0 and MAX_INIT_PRIORITY.
16767
16768 This differs from default_named_section_asm_out_constructor in
16769 that we have special handling for -mrelocatable. */
16770
16771static void
a2369ed3 16772rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
16773{
16774 const char *section = ".ctors";
16775 char buf[16];
16776
16777 if (priority != DEFAULT_INIT_PRIORITY)
16778 {
16779 sprintf (buf, ".ctors.%.5u",
16780 /* Invert the numbering so the linker puts us in the proper
16781 order; constructors are run from right to left, and the
16782 linker sorts in increasing order. */
16783 MAX_INIT_PRIORITY - priority);
16784 section = buf;
16785 }
16786
715bdd29
RH
16787 named_section_flags (section, SECTION_WRITE);
16788 assemble_align (POINTER_SIZE);
d9f6800d
RH
16789
16790 if (TARGET_RELOCATABLE)
16791 {
16792 fputs ("\t.long (", asm_out_file);
16793 output_addr_const (asm_out_file, symbol);
16794 fputs (")@fixup\n", asm_out_file);
16795 }
16796 else
c8af3574 16797 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
16798}
16799
16800static void
a2369ed3 16801rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
16802{
16803 const char *section = ".dtors";
16804 char buf[16];
16805
16806 if (priority != DEFAULT_INIT_PRIORITY)
16807 {
16808 sprintf (buf, ".dtors.%.5u",
16809 /* Invert the numbering so the linker puts us in the proper
16810 order; constructors are run from right to left, and the
16811 linker sorts in increasing order. */
16812 MAX_INIT_PRIORITY - priority);
16813 section = buf;
16814 }
16815
715bdd29
RH
16816 named_section_flags (section, SECTION_WRITE);
16817 assemble_align (POINTER_SIZE);
d9f6800d
RH
16818
16819 if (TARGET_RELOCATABLE)
16820 {
16821 fputs ("\t.long (", asm_out_file);
16822 output_addr_const (asm_out_file, symbol);
16823 fputs (")@fixup\n", asm_out_file);
16824 }
16825 else
c8af3574 16826 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 16827}
9739c90c
JJ
16828
16829void
a2369ed3 16830rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
16831{
16832 if (TARGET_64BIT)
16833 {
16834 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
16835 ASM_OUTPUT_LABEL (file, name);
16836 fputs (DOUBLE_INT_ASM_OP, file);
85b776df
AM
16837 rs6000_output_function_entry (file, name);
16838 fputs (",.TOC.@tocbase,0\n\t.previous\n", file);
16839 if (DOT_SYMBOLS)
9739c90c 16840 {
85b776df 16841 fputs ("\t.size\t", file);
9739c90c 16842 assemble_name (file, name);
85b776df
AM
16843 fputs (",24\n\t.type\t.", file);
16844 assemble_name (file, name);
16845 fputs (",@function\n", file);
16846 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
16847 {
16848 fputs ("\t.globl\t.", file);
16849 assemble_name (file, name);
16850 putc ('\n', file);
16851 }
9739c90c 16852 }
85b776df
AM
16853 else
16854 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
9739c90c 16855 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
85b776df
AM
16856 rs6000_output_function_entry (file, name);
16857 fputs (":\n", file);
9739c90c
JJ
16858 return;
16859 }
16860
16861 if (TARGET_RELOCATABLE
16862 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 16863 && uses_TOC ())
9739c90c
JJ
16864 {
16865 char buf[256];
16866
16867 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
16868
16869 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
16870 fprintf (file, "\t.long ");
16871 assemble_name (file, buf);
16872 putc ('-', file);
16873 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
16874 assemble_name (file, buf);
16875 putc ('\n', file);
16876 }
16877
16878 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
16879 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
16880
16881 if (DEFAULT_ABI == ABI_AIX)
16882 {
16883 const char *desc_name, *orig_name;
16884
16885 orig_name = (*targetm.strip_name_encoding) (name);
16886 desc_name = orig_name;
16887 while (*desc_name == '.')
16888 desc_name++;
16889
16890 if (TREE_PUBLIC (decl))
16891 fprintf (file, "\t.globl %s\n", desc_name);
16892
16893 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
16894 fprintf (file, "%s:\n", desc_name);
16895 fprintf (file, "\t.long %s\n", orig_name);
16896 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
16897 if (DEFAULT_ABI == ABI_AIX)
16898 fputs ("\t.long 0\n", file);
16899 fprintf (file, "\t.previous\n");
16900 }
16901 ASM_OUTPUT_LABEL (file, name);
16902}
7c262518
RH
16903#endif
16904
cbaaba19 16905#if TARGET_XCOFF
7c262518 16906static void
a2369ed3 16907rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
16908{
16909 fputs (GLOBAL_ASM_OP, stream);
16910 RS6000_OUTPUT_BASENAME (stream, name);
16911 putc ('\n', stream);
16912}
16913
16914static void
a2369ed3 16915rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 16916{
0e5dbd9b
DE
16917 int smclass;
16918 static const char * const suffix[3] = { "PR", "RO", "RW" };
16919
16920 if (flags & SECTION_CODE)
16921 smclass = 0;
16922 else if (flags & SECTION_WRITE)
16923 smclass = 2;
16924 else
16925 smclass = 1;
16926
5b5198f7 16927 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 16928 (flags & SECTION_CODE) ? "." : "",
5b5198f7 16929 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 16930}
ae46c4e0
RH
16931
16932static void
f676971a 16933rs6000_xcoff_select_section (tree decl, int reloc,
a2369ed3 16934 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 16935{
5add3202 16936 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 16937 {
0e5dbd9b 16938 if (TREE_PUBLIC (decl))
ae46c4e0
RH
16939 read_only_data_section ();
16940 else
16941 read_only_private_data_section ();
16942 }
16943 else
16944 {
0e5dbd9b 16945 if (TREE_PUBLIC (decl))
ae46c4e0
RH
16946 data_section ();
16947 else
16948 private_data_section ();
16949 }
16950}
16951
16952static void
a2369ed3 16953rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
16954{
16955 const char *name;
ae46c4e0 16956
5b5198f7
DE
16957 /* Use select_section for private and uninitialized data. */
16958 if (!TREE_PUBLIC (decl)
16959 || DECL_COMMON (decl)
0e5dbd9b
DE
16960 || DECL_INITIAL (decl) == NULL_TREE
16961 || DECL_INITIAL (decl) == error_mark_node
16962 || (flag_zero_initialized_in_bss
16963 && initializer_zerop (DECL_INITIAL (decl))))
16964 return;
16965
16966 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
16967 name = (*targetm.strip_name_encoding) (name);
16968 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 16969}
b64a1b53 16970
fb49053f
RH
16971/* Select section for constant in constant pool.
16972
16973 On RS/6000, all constants are in the private read-only data area.
16974 However, if this is being placed in the TOC it must be output as a
16975 toc entry. */
16976
b64a1b53 16977static void
f676971a 16978rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
a2369ed3 16979 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
16980{
16981 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
16982 toc_section ();
16983 else
16984 read_only_private_data_section ();
16985}
772c5265
RH
16986
16987/* Remove any trailing [DS] or the like from the symbol name. */
16988
16989static const char *
a2369ed3 16990rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
16991{
16992 size_t len;
16993 if (*name == '*')
16994 name++;
16995 len = strlen (name);
16996 if (name[len - 1] == ']')
16997 return ggc_alloc_string (name, len - 4);
16998 else
16999 return name;
17000}
17001
5add3202
DE
17002/* Section attributes. AIX is always PIC. */
17003
17004static unsigned int
a2369ed3 17005rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 17006{
5b5198f7
DE
17007 unsigned int align;
17008 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
17009
17010 /* Align to at least UNIT size. */
17011 if (flags & SECTION_CODE)
17012 align = MIN_UNITS_PER_WORD;
17013 else
17014 /* Increase alignment of large objects if not already stricter. */
17015 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
17016 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
17017 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
17018
17019 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 17020}
a5fe455b 17021
1bc7c5b6
ZW
17022/* Output at beginning of assembler file.
17023
17024 Initialize the section names for the RS/6000 at this point.
17025
17026 Specify filename, including full path, to assembler.
17027
17028 We want to go into the TOC section so at least one .toc will be emitted.
17029 Also, in order to output proper .bs/.es pairs, we need at least one static
17030 [RW] section emitted.
17031
17032 Finally, declare mcount when profiling to make the assembler happy. */
17033
17034static void
863d938c 17035rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
17036{
17037 rs6000_gen_section_name (&xcoff_bss_section_name,
17038 main_input_filename, ".bss_");
17039 rs6000_gen_section_name (&xcoff_private_data_section_name,
17040 main_input_filename, ".rw_");
17041 rs6000_gen_section_name (&xcoff_read_only_section_name,
17042 main_input_filename, ".ro_");
17043
17044 fputs ("\t.file\t", asm_out_file);
17045 output_quoted_string (asm_out_file, main_input_filename);
17046 fputc ('\n', asm_out_file);
17047 toc_section ();
17048 if (write_symbols != NO_DEBUG)
17049 private_data_section ();
17050 text_section ();
17051 if (profile_flag)
17052 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
17053 rs6000_file_start ();
17054}
17055
a5fe455b
ZW
17056/* Output at end of assembler file.
17057 On the RS/6000, referencing data should automatically pull in text. */
17058
17059static void
863d938c 17060rs6000_xcoff_file_end (void)
a5fe455b
ZW
17061{
17062 text_section ();
17063 fputs ("_section_.text:\n", asm_out_file);
17064 data_section ();
17065 fputs (TARGET_32BIT
17066 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
17067 asm_out_file);
17068}
f1384257 17069#endif /* TARGET_XCOFF */
0e5dbd9b 17070
f1384257
AM
17071#if TARGET_MACHO
17072/* Cross-module name binding. Darwin does not support overriding
7f3d8013 17073 functions at dynamic-link time. */
0e5dbd9b 17074
2bcc50d0 17075static bool
a2369ed3 17076rs6000_binds_local_p (tree decl)
0e5dbd9b 17077{
f1384257 17078 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 17079}
f1384257 17080#endif
34bb030a 17081
3c50106f
RH
17082/* Compute a (partial) cost for rtx X. Return true if the complete
17083 cost has been computed, and false if subexpressions should be
17084 scanned. In either case, *TOTAL contains the cost result. */
17085
17086static bool
1494c534 17087rs6000_rtx_costs (rtx x, int code, int outer_code, int *total)
3c50106f 17088{
f0517163
RS
17089 enum machine_mode mode = GET_MODE (x);
17090
3c50106f
RH
17091 switch (code)
17092 {
30a555d9 17093 /* On the RS/6000, if it is valid in the insn, it is free. */
3c50106f 17094 case CONST_INT:
066cd967
DE
17095 if (((outer_code == SET
17096 || outer_code == PLUS
17097 || outer_code == MINUS)
17098 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17099 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
17100 || ((outer_code == IOR || outer_code == XOR)
17101 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17102 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
627b6fe2
DJ
17103 || ((outer_code == DIV || outer_code == UDIV
17104 || outer_code == MOD || outer_code == UMOD)
17105 && exact_log2 (INTVAL (x)) >= 0)
066cd967
DE
17106 || (outer_code == AND
17107 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17108 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17109 || mask_operand (x, VOIDmode)))
066cd967
DE
17110 || outer_code == ASHIFT
17111 || outer_code == ASHIFTRT
17112 || outer_code == LSHIFTRT
17113 || outer_code == ROTATE
17114 || outer_code == ROTATERT
d5861a7a 17115 || outer_code == ZERO_EXTRACT
066cd967
DE
17116 || (outer_code == MULT
17117 && CONST_OK_FOR_LETTER_P (INTVAL (x), 'I'))
17118 || (outer_code == COMPARE
17119 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17120 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'K'))))
17121 {
17122 *total = 0;
17123 return true;
17124 }
17125 else if ((outer_code == PLUS
17126 && reg_or_add_cint64_operand (x, VOIDmode))
17127 || (outer_code == MINUS
17128 && reg_or_sub_cint64_operand (x, VOIDmode))
17129 || ((outer_code == SET
17130 || outer_code == IOR
17131 || outer_code == XOR)
17132 && (INTVAL (x)
17133 & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0))
17134 {
17135 *total = COSTS_N_INSNS (1);
17136 return true;
17137 }
17138 /* FALLTHRU */
17139
17140 case CONST_DOUBLE:
17141 if (mode == DImode
17142 && ((outer_code == AND
17143 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17144 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17145 || mask64_operand (x, DImode)))
066cd967
DE
17146 || ((outer_code == IOR || outer_code == XOR)
17147 && CONST_DOUBLE_HIGH (x) == 0
17148 && (CONST_DOUBLE_LOW (x)
17149 & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0)))
17150 {
17151 *total = 0;
17152 return true;
17153 }
17154 else if (mode == DImode
17155 && (outer_code == SET
17156 || outer_code == IOR
17157 || outer_code == XOR)
17158 && CONST_DOUBLE_HIGH (x) == 0)
17159 {
17160 *total = COSTS_N_INSNS (1);
17161 return true;
17162 }
17163 /* FALLTHRU */
17164
3c50106f 17165 case CONST:
066cd967 17166 case HIGH:
3c50106f 17167 case SYMBOL_REF:
066cd967
DE
17168 case MEM:
17169 /* When optimizing for size, MEM should be slightly more expensive
17170 than generating address, e.g., (plus (reg) (const)).
17171 L1 cache latecy is about two instructions. */
17172 *total = optimize_size ? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (2);
3c50106f
RH
17173 return true;
17174
30a555d9
DE
17175 case LABEL_REF:
17176 *total = 0;
17177 return true;
17178
3c50106f 17179 case PLUS:
f0517163 17180 if (mode == DFmode)
066cd967
DE
17181 {
17182 if (GET_CODE (XEXP (x, 0)) == MULT)
17183 {
17184 /* FNMA accounted in outer NEG. */
17185 if (outer_code == NEG)
17186 *total = rs6000_cost->dmul - rs6000_cost->fp;
17187 else
17188 *total = rs6000_cost->dmul;
17189 }
17190 else
17191 *total = rs6000_cost->fp;
17192 }
f0517163 17193 else if (mode == SFmode)
066cd967
DE
17194 {
17195 /* FNMA accounted in outer NEG. */
17196 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17197 *total = 0;
17198 else
17199 *total = rs6000_cost->fp;
17200 }
938bf747
RS
17201 else if (GET_CODE (XEXP (x, 0)) == MULT)
17202 {
17203 /* The rs6000 doesn't have shift-and-add instructions. */
17204 rs6000_rtx_costs (XEXP (x, 0), MULT, PLUS, total);
17205 *total += COSTS_N_INSNS (1);
17206 }
f0517163 17207 else
066cd967
DE
17208 *total = COSTS_N_INSNS (1);
17209 return false;
3c50106f 17210
52190329 17211 case MINUS:
f0517163 17212 if (mode == DFmode)
066cd967
DE
17213 {
17214 if (GET_CODE (XEXP (x, 0)) == MULT)
17215 {
17216 /* FNMA accounted in outer NEG. */
17217 if (outer_code == NEG)
17218 *total = 0;
17219 else
17220 *total = rs6000_cost->dmul;
17221 }
17222 else
17223 *total = rs6000_cost->fp;
17224 }
f0517163 17225 else if (mode == SFmode)
066cd967
DE
17226 {
17227 /* FNMA accounted in outer NEG. */
17228 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17229 *total = 0;
17230 else
17231 *total = rs6000_cost->fp;
17232 }
938bf747
RS
17233 else if (GET_CODE (XEXP (x, 0)) == MULT)
17234 {
17235 /* The rs6000 doesn't have shift-and-sub instructions. */
17236 rs6000_rtx_costs (XEXP (x, 0), MULT, MINUS, total);
17237 *total += COSTS_N_INSNS (1);
17238 }
f0517163
RS
17239 else
17240 *total = COSTS_N_INSNS (1);
066cd967 17241 return false;
3c50106f
RH
17242
17243 case MULT:
8b897cfa 17244 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3c50106f 17245 {
8b897cfa
RS
17246 if (INTVAL (XEXP (x, 1)) >= -256
17247 && INTVAL (XEXP (x, 1)) <= 255)
06a67bdd 17248 *total = rs6000_cost->mulsi_const9;
8b897cfa 17249 else
06a67bdd 17250 *total = rs6000_cost->mulsi_const;
3c50106f 17251 }
066cd967
DE
17252 /* FMA accounted in outer PLUS/MINUS. */
17253 else if ((mode == DFmode || mode == SFmode)
17254 && (outer_code == PLUS || outer_code == MINUS))
17255 *total = 0;
f0517163 17256 else if (mode == DFmode)
06a67bdd 17257 *total = rs6000_cost->dmul;
f0517163 17258 else if (mode == SFmode)
06a67bdd 17259 *total = rs6000_cost->fp;
f0517163 17260 else if (mode == DImode)
06a67bdd 17261 *total = rs6000_cost->muldi;
8b897cfa 17262 else
06a67bdd 17263 *total = rs6000_cost->mulsi;
066cd967 17264 return false;
3c50106f
RH
17265
17266 case DIV:
17267 case MOD:
f0517163
RS
17268 if (FLOAT_MODE_P (mode))
17269 {
06a67bdd
RS
17270 *total = mode == DFmode ? rs6000_cost->ddiv
17271 : rs6000_cost->sdiv;
066cd967 17272 return false;
f0517163 17273 }
5efb1046 17274 /* FALLTHRU */
3c50106f
RH
17275
17276 case UDIV:
17277 case UMOD:
627b6fe2
DJ
17278 if (GET_CODE (XEXP (x, 1)) == CONST_INT
17279 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
17280 {
17281 if (code == DIV || code == MOD)
17282 /* Shift, addze */
17283 *total = COSTS_N_INSNS (2);
17284 else
17285 /* Shift */
17286 *total = COSTS_N_INSNS (1);
17287 }
17288 else
17289 {
17290 if (GET_MODE (XEXP (x, 1)) == DImode)
17291 *total = rs6000_cost->divdi;
17292 else
17293 *total = rs6000_cost->divsi;
17294 }
17295 /* Add in shift and subtract for MOD. */
17296 if (code == MOD || code == UMOD)
17297 *total += COSTS_N_INSNS (2);
066cd967 17298 return false;
3c50106f
RH
17299
17300 case FFS:
17301 *total = COSTS_N_INSNS (4);
066cd967 17302 return false;
3c50106f 17303
06a67bdd 17304 case NOT:
066cd967
DE
17305 if (outer_code == AND || outer_code == IOR || outer_code == XOR)
17306 {
17307 *total = 0;
17308 return false;
17309 }
17310 /* FALLTHRU */
17311
17312 case AND:
17313 case IOR:
17314 case XOR:
d5861a7a
DE
17315 case ZERO_EXTRACT:
17316 *total = COSTS_N_INSNS (1);
17317 return false;
17318
066cd967
DE
17319 case ASHIFT:
17320 case ASHIFTRT:
17321 case LSHIFTRT:
17322 case ROTATE:
17323 case ROTATERT:
d5861a7a 17324 /* Handle mul_highpart. */
066cd967
DE
17325 if (outer_code == TRUNCATE
17326 && GET_CODE (XEXP (x, 0)) == MULT)
17327 {
17328 if (mode == DImode)
17329 *total = rs6000_cost->muldi;
17330 else
17331 *total = rs6000_cost->mulsi;
17332 return true;
17333 }
d5861a7a
DE
17334 else if (outer_code == AND)
17335 *total = 0;
17336 else
17337 *total = COSTS_N_INSNS (1);
17338 return false;
17339
17340 case SIGN_EXTEND:
17341 case ZERO_EXTEND:
17342 if (GET_CODE (XEXP (x, 0)) == MEM)
17343 *total = 0;
17344 else
17345 *total = COSTS_N_INSNS (1);
066cd967 17346 return false;
06a67bdd 17347
066cd967
DE
17348 case COMPARE:
17349 case NEG:
17350 case ABS:
17351 if (!FLOAT_MODE_P (mode))
17352 {
17353 *total = COSTS_N_INSNS (1);
17354 return false;
17355 }
17356 /* FALLTHRU */
17357
17358 case FLOAT:
17359 case UNSIGNED_FLOAT:
17360 case FIX:
17361 case UNSIGNED_FIX:
17362 case FLOAT_EXTEND:
06a67bdd
RS
17363 case FLOAT_TRUNCATE:
17364 *total = rs6000_cost->fp;
066cd967 17365 return false;
06a67bdd
RS
17366
17367 case UNSPEC:
17368 switch (XINT (x, 1))
17369 {
17370 case UNSPEC_FRSP:
17371 *total = rs6000_cost->fp;
17372 return true;
17373
17374 default:
17375 break;
17376 }
17377 break;
17378
17379 case CALL:
17380 case IF_THEN_ELSE:
17381 if (optimize_size)
17382 {
17383 *total = COSTS_N_INSNS (1);
17384 return true;
17385 }
066cd967
DE
17386 else if (FLOAT_MODE_P (mode)
17387 && TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS)
17388 {
17389 *total = rs6000_cost->fp;
17390 return false;
17391 }
17392
06a67bdd
RS
17393 break;
17394
3c50106f 17395 default:
06a67bdd 17396 break;
3c50106f 17397 }
06a67bdd
RS
17398
17399 return false;
3c50106f
RH
17400}
17401
34bb030a
DE
17402/* A C expression returning the cost of moving data from a register of class
17403 CLASS1 to one of CLASS2. */
17404
17405int
f676971a 17406rs6000_register_move_cost (enum machine_mode mode,
a2369ed3 17407 enum reg_class from, enum reg_class to)
34bb030a
DE
17408{
17409 /* Moves from/to GENERAL_REGS. */
17410 if (reg_classes_intersect_p (to, GENERAL_REGS)
17411 || reg_classes_intersect_p (from, GENERAL_REGS))
17412 {
17413 if (! reg_classes_intersect_p (to, GENERAL_REGS))
17414 from = to;
17415
17416 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
17417 return (rs6000_memory_move_cost (mode, from, 0)
17418 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
17419
a3c9585f 17420/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
17421 else if (from == CR_REGS)
17422 return 4;
17423
17424 else
17425/* A move will cost one instruction per GPR moved. */
17426 return 2 * HARD_REGNO_NREGS (0, mode);
17427 }
17428
17429/* Moving between two similar registers is just one instruction. */
17430 else if (reg_classes_intersect_p (to, from))
17431 return mode == TFmode ? 4 : 2;
17432
17433/* Everything else has to go through GENERAL_REGS. */
17434 else
f676971a 17435 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
34bb030a
DE
17436 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
17437}
17438
17439/* A C expressions returning the cost of moving data of MODE from a register to
17440 or from memory. */
17441
17442int
f676971a 17443rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
a2369ed3 17444 int in ATTRIBUTE_UNUSED)
34bb030a
DE
17445{
17446 if (reg_classes_intersect_p (class, GENERAL_REGS))
17447 return 4 * HARD_REGNO_NREGS (0, mode);
17448 else if (reg_classes_intersect_p (class, FLOAT_REGS))
17449 return 4 * HARD_REGNO_NREGS (32, mode);
17450 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
17451 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
17452 else
17453 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
17454}
17455
ded9bf77
AH
17456/* Return an RTX representing where to find the function value of a
17457 function returning MODE. */
17458static rtx
17459rs6000_complex_function_value (enum machine_mode mode)
17460{
17461 unsigned int regno;
17462 rtx r1, r2;
17463 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 17464 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77 17465
4ed78545 17466 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
ded9bf77
AH
17467 regno = FP_ARG_RETURN;
17468 else
17469 {
17470 regno = GP_ARG_RETURN;
17471
17472 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 17473 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
17474 return gen_rtx_REG (mode, regno);
17475 }
17476
fb7e4164
AM
17477 if (inner_bytes >= 8)
17478 return gen_rtx_REG (mode, regno);
17479
ded9bf77
AH
17480 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
17481 const0_rtx);
17482 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 17483 GEN_INT (inner_bytes));
ded9bf77
AH
17484 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
17485}
17486
a6ebc39a
AH
17487/* Define how to find the value returned by a function.
17488 VALTYPE is the data type of the value (as a tree).
17489 If the precise function being called is known, FUNC is its FUNCTION_DECL;
17490 otherwise, FUNC is 0.
17491
17492 On the SPE, both FPs and vectors are returned in r3.
17493
17494 On RS/6000 an integer value is in r3 and a floating-point value is in
17495 fp1, unless -msoft-float. */
17496
17497rtx
17498rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
17499{
17500 enum machine_mode mode;
2a8fa26c 17501 unsigned int regno;
a6ebc39a 17502
0e67400a
FJ
17503 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
17504 {
17505 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
17506 return gen_rtx_PARALLEL (DImode,
17507 gen_rtvec (2,
17508 gen_rtx_EXPR_LIST (VOIDmode,
17509 gen_rtx_REG (SImode, GP_ARG_RETURN),
17510 const0_rtx),
17511 gen_rtx_EXPR_LIST (VOIDmode,
17512 gen_rtx_REG (SImode,
17513 GP_ARG_RETURN + 1),
17514 GEN_INT (4))));
17515 }
17516
a6ebc39a
AH
17517 if ((INTEGRAL_TYPE_P (valtype)
17518 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
17519 || POINTER_TYPE_P (valtype))
b78d48dd 17520 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
17521 else
17522 mode = TYPE_MODE (valtype);
17523
4ed78545 17524 if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS)
2a8fa26c 17525 regno = FP_ARG_RETURN;
ded9bf77 17526 else if (TREE_CODE (valtype) == COMPLEX_TYPE
42ba5130 17527 && targetm.calls.split_complex_arg)
ded9bf77 17528 return rs6000_complex_function_value (mode);
44688022 17529 else if (TREE_CODE (valtype) == VECTOR_TYPE
d0b2079e
FJ
17530 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI
17531 && ALTIVEC_VECTOR_MODE(mode))
a6ebc39a
AH
17532 regno = ALTIVEC_ARG_RETURN;
17533 else
17534 regno = GP_ARG_RETURN;
17535
17536 return gen_rtx_REG (mode, regno);
17537}
17538
ded9bf77
AH
17539/* Define how to find the value returned by a library function
17540 assuming the value has mode MODE. */
17541rtx
17542rs6000_libcall_value (enum machine_mode mode)
17543{
17544 unsigned int regno;
17545
2e6c9641
FJ
17546 if (TARGET_32BIT && TARGET_POWERPC64 && mode == DImode)
17547 {
17548 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
17549 return gen_rtx_PARALLEL (DImode,
17550 gen_rtvec (2,
17551 gen_rtx_EXPR_LIST (VOIDmode,
17552 gen_rtx_REG (SImode, GP_ARG_RETURN),
17553 const0_rtx),
17554 gen_rtx_EXPR_LIST (VOIDmode,
17555 gen_rtx_REG (SImode,
17556 GP_ARG_RETURN + 1),
17557 GEN_INT (4))));
17558 }
17559
ded9bf77
AH
17560 if (GET_MODE_CLASS (mode) == MODE_FLOAT
17561 && TARGET_HARD_FLOAT && TARGET_FPRS)
17562 regno = FP_ARG_RETURN;
44688022
AM
17563 else if (ALTIVEC_VECTOR_MODE (mode)
17564 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
ded9bf77 17565 regno = ALTIVEC_ARG_RETURN;
42ba5130 17566 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
17567 return rs6000_complex_function_value (mode);
17568 else
17569 regno = GP_ARG_RETURN;
17570
17571 return gen_rtx_REG (mode, regno);
17572}
17573
d1d0c603
JJ
17574/* Define the offset between two registers, FROM to be eliminated and its
17575 replacement TO, at the start of a routine. */
17576HOST_WIDE_INT
17577rs6000_initial_elimination_offset (int from, int to)
17578{
17579 rs6000_stack_t *info = rs6000_stack_info ();
17580 HOST_WIDE_INT offset;
17581
17582 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
17583 offset = info->push_p ? 0 : -info->total_size;
17584 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
17585 offset = info->total_size;
17586 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
17587 offset = info->push_p ? info->total_size : 0;
17588 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
17589 offset = 0;
17590 else
17591 abort ();
17592
17593 return offset;
17594}
17595
62e1dfcf
NC
17596/* Return true if TYPE is of type __ev64_opaque__. */
17597
c8e4f0e9 17598static bool
a2369ed3 17599is_ev64_opaque_type (tree type)
62e1dfcf 17600{
c8e4f0e9 17601 return (TARGET_SPE
2abe3e28
AH
17602 && (type == opaque_V2SI_type_node
17603 || type == opaque_V2SF_type_node
36252949 17604 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
17605}
17606
96714395 17607static rtx
a2369ed3 17608rs6000_dwarf_register_span (rtx reg)
96714395
AH
17609{
17610 unsigned regno;
17611
17612 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
17613 return NULL_RTX;
17614
17615 regno = REGNO (reg);
17616
17617 /* The duality of the SPE register size wreaks all kinds of havoc.
17618 This is a way of distinguishing r0 in 32-bits from r0 in
17619 64-bits. */
17620 return
17621 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
17622 BYTES_BIG_ENDIAN
17623 ? gen_rtvec (2,
17624 gen_rtx_REG (SImode, regno + 1200),
17625 gen_rtx_REG (SImode, regno))
17626 : gen_rtvec (2,
17627 gen_rtx_REG (SImode, regno),
17628 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
17629}
17630
93c9d1ba
AM
17631/* Map internal gcc register numbers to DWARF2 register numbers. */
17632
17633unsigned int
17634rs6000_dbx_register_number (unsigned int regno)
17635{
17636 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
17637 return regno;
17638 if (regno == MQ_REGNO)
17639 return 100;
17640 if (regno == LINK_REGISTER_REGNUM)
17641 return 108;
17642 if (regno == COUNT_REGISTER_REGNUM)
17643 return 109;
17644 if (CR_REGNO_P (regno))
17645 return regno - CR0_REGNO + 86;
17646 if (regno == XER_REGNO)
17647 return 101;
17648 if (ALTIVEC_REGNO_P (regno))
17649 return regno - FIRST_ALTIVEC_REGNO + 1124;
17650 if (regno == VRSAVE_REGNO)
17651 return 356;
17652 if (regno == VSCR_REGNO)
17653 return 67;
17654 if (regno == SPE_ACC_REGNO)
17655 return 99;
17656 if (regno == SPEFSCR_REGNO)
17657 return 612;
17658 /* SPE high reg number. We get these values of regno from
17659 rs6000_dwarf_register_span. */
17660 if (regno >= 1200 && regno < 1232)
17661 return regno;
17662
17663 abort ();
17664}
17665
93f90be6 17666/* target hook eh_return_filter_mode */
f676971a 17667static enum machine_mode
93f90be6
FJ
17668rs6000_eh_return_filter_mode (void)
17669{
17670 return TARGET_32BIT ? SImode : word_mode;
17671}
17672
f676971a
EC
17673/* Target hook for vector_mode_supported_p. */
17674static bool
17675rs6000_vector_mode_supported_p (enum machine_mode mode)
17676{
17677
17678 if (TARGET_SPE && SPE_VECTOR_MODE (mode))
17679 return true;
17680
17681 else if (TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
17682 return true;
17683
17684 else
17685 return false;
17686}
17687
17211ab5 17688#include "gt-rs6000.h"