]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
output.h (unlikely_section_label): Delete declaration.
[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];
5514620a
GK
8322 bool constp = (GET_CODE (bytes_rtx) == CONST_INT);
8323 HOST_WIDE_INT align;
8324 HOST_WIDE_INT bytes;
fba73eb1
DE
8325 int offset;
8326 int clear_bytes;
5514620a 8327 int clear_step;
fba73eb1
DE
8328
8329 /* If this is not a fixed size move, just call memcpy */
8330 if (! constp)
8331 return 0;
8332
8333 /* If this is not a fixed size alignment, abort */
8334 if (GET_CODE (align_rtx) != CONST_INT)
8335 abort ();
8336 align = INTVAL (align_rtx) * BITS_PER_UNIT;
8337
8338 /* Anything to clear? */
8339 bytes = INTVAL (bytes_rtx);
8340 if (bytes <= 0)
8341 return 1;
8342
5514620a
GK
8343 /* Use the builtin memset after a point, to avoid huge code bloat.
8344 When optimize_size, avoid any significant code bloat; calling
8345 memset is about 4 instructions, so allow for one instruction to
8346 load zero and three to do clearing. */
8347 if (TARGET_ALTIVEC && align >= 128)
8348 clear_step = 16;
8349 else if (TARGET_POWERPC64 && align >= 32)
8350 clear_step = 8;
8351 else
8352 clear_step = 4;
fba73eb1 8353
5514620a
GK
8354 if (optimize_size && bytes > 3 * clear_step)
8355 return 0;
8356 if (! optimize_size && bytes > 8 * clear_step)
fba73eb1
DE
8357 return 0;
8358
8359 for (offset = 0; bytes > 0; offset += clear_bytes, bytes -= clear_bytes)
8360 {
fba73eb1
DE
8361 enum machine_mode mode = BLKmode;
8362 rtx dest;
f676971a 8363
5514620a
GK
8364 if (bytes >= 16 && TARGET_ALTIVEC && align >= 128)
8365 {
8366 clear_bytes = 16;
8367 mode = V4SImode;
8368 }
8369 else if (bytes >= 8 && TARGET_POWERPC64
8370 /* 64-bit loads and stores require word-aligned
8371 displacements. */
8372 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
fba73eb1
DE
8373 {
8374 clear_bytes = 8;
8375 mode = DImode;
fba73eb1 8376 }
5514620a 8377 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
fba73eb1
DE
8378 { /* move 4 bytes */
8379 clear_bytes = 4;
8380 mode = SImode;
fba73eb1 8381 }
5514620a 8382 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
fba73eb1
DE
8383 { /* move 2 bytes */
8384 clear_bytes = 2;
8385 mode = HImode;
fba73eb1
DE
8386 }
8387 else /* move 1 byte at a time */
8388 {
8389 clear_bytes = 1;
8390 mode = QImode;
fba73eb1 8391 }
f676971a 8392
fba73eb1 8393 dest = adjust_address (orig_dest, mode, offset);
f676971a 8394
5514620a 8395 emit_move_insn (dest, CONST0_RTX (mode));
fba73eb1
DE
8396 }
8397
8398 return 1;
8399}
8400
35aff10b 8401\f
7e69e155
MM
8402/* Expand a block move operation, and return 1 if successful. Return 0
8403 if we should let the compiler generate normal code.
8404
8405 operands[0] is the destination
8406 operands[1] is the source
8407 operands[2] is the length
8408 operands[3] is the alignment */
8409
3933e0e1
MM
8410#define MAX_MOVE_REG 4
8411
7e69e155 8412int
a2369ed3 8413expand_block_move (rtx operands[])
7e69e155 8414{
b6c9286a
MM
8415 rtx orig_dest = operands[0];
8416 rtx orig_src = operands[1];
7e69e155 8417 rtx bytes_rtx = operands[2];
7e69e155 8418 rtx align_rtx = operands[3];
3933e0e1 8419 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 8420 int align;
3933e0e1
MM
8421 int bytes;
8422 int offset;
7e69e155 8423 int move_bytes;
cabfd258
GK
8424 rtx stores[MAX_MOVE_REG];
8425 int num_reg = 0;
7e69e155 8426
3933e0e1 8427 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 8428 if (! constp)
3933e0e1
MM
8429 return 0;
8430
5ee95df6
FS
8431 /* If this is not a fixed size alignment, abort */
8432 if (GET_CODE (align_rtx) != CONST_INT)
8433 abort ();
fba73eb1 8434 align = INTVAL (align_rtx) * BITS_PER_UNIT;
5ee95df6 8435
7e69e155 8436 /* Anything to move? */
3933e0e1
MM
8437 bytes = INTVAL (bytes_rtx);
8438 if (bytes <= 0)
7e69e155
MM
8439 return 1;
8440
ea9982a8 8441 /* store_one_arg depends on expand_block_move to handle at least the size of
f676971a 8442 reg_parm_stack_space. */
ea9982a8 8443 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
8444 return 0;
8445
cabfd258 8446 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 8447 {
cabfd258 8448 union {
70128ad9 8449 rtx (*movmemsi) (rtx, rtx, rtx, rtx);
a2369ed3 8450 rtx (*mov) (rtx, rtx);
cabfd258
GK
8451 } gen_func;
8452 enum machine_mode mode = BLKmode;
8453 rtx src, dest;
f676971a 8454
5514620a
GK
8455 /* Altivec first, since it will be faster than a string move
8456 when it applies, and usually not significantly larger. */
8457 if (TARGET_ALTIVEC && bytes >= 16 && align >= 128)
8458 {
8459 move_bytes = 16;
8460 mode = V4SImode;
8461 gen_func.mov = gen_movv4si;
8462 }
8463 else if (TARGET_STRING
cabfd258
GK
8464 && bytes > 24 /* move up to 32 bytes at a time */
8465 && ! fixed_regs[5]
8466 && ! fixed_regs[6]
8467 && ! fixed_regs[7]
8468 && ! fixed_regs[8]
8469 && ! fixed_regs[9]
8470 && ! fixed_regs[10]
8471 && ! fixed_regs[11]
8472 && ! fixed_regs[12])
7e69e155 8473 {
cabfd258 8474 move_bytes = (bytes > 32) ? 32 : bytes;
70128ad9 8475 gen_func.movmemsi = gen_movmemsi_8reg;
cabfd258
GK
8476 }
8477 else if (TARGET_STRING
8478 && bytes > 16 /* move up to 24 bytes at a time */
8479 && ! fixed_regs[5]
8480 && ! fixed_regs[6]
8481 && ! fixed_regs[7]
8482 && ! fixed_regs[8]
8483 && ! fixed_regs[9]
8484 && ! fixed_regs[10])
8485 {
8486 move_bytes = (bytes > 24) ? 24 : bytes;
70128ad9 8487 gen_func.movmemsi = gen_movmemsi_6reg;
cabfd258
GK
8488 }
8489 else if (TARGET_STRING
8490 && bytes > 8 /* move up to 16 bytes at a time */
8491 && ! fixed_regs[5]
8492 && ! fixed_regs[6]
8493 && ! fixed_regs[7]
8494 && ! fixed_regs[8])
8495 {
8496 move_bytes = (bytes > 16) ? 16 : bytes;
70128ad9 8497 gen_func.movmemsi = gen_movmemsi_4reg;
cabfd258
GK
8498 }
8499 else if (bytes >= 8 && TARGET_POWERPC64
8500 /* 64-bit loads and stores require word-aligned
8501 displacements. */
fba73eb1 8502 && (align >= 64 || (!STRICT_ALIGNMENT && align >= 32)))
cabfd258
GK
8503 {
8504 move_bytes = 8;
8505 mode = DImode;
8506 gen_func.mov = gen_movdi;
8507 }
8508 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
8509 { /* move up to 8 bytes at a time */
8510 move_bytes = (bytes > 8) ? 8 : bytes;
70128ad9 8511 gen_func.movmemsi = gen_movmemsi_2reg;
cabfd258 8512 }
cd7d9ca4 8513 else if (bytes >= 4 && (align >= 32 || !STRICT_ALIGNMENT))
cabfd258
GK
8514 { /* move 4 bytes */
8515 move_bytes = 4;
8516 mode = SImode;
8517 gen_func.mov = gen_movsi;
8518 }
cd7d9ca4 8519 else if (bytes == 2 && (align >= 16 || !STRICT_ALIGNMENT))
cabfd258
GK
8520 { /* move 2 bytes */
8521 move_bytes = 2;
8522 mode = HImode;
8523 gen_func.mov = gen_movhi;
8524 }
8525 else if (TARGET_STRING && bytes > 1)
8526 { /* move up to 4 bytes at a time */
8527 move_bytes = (bytes > 4) ? 4 : bytes;
70128ad9 8528 gen_func.movmemsi = gen_movmemsi_1reg;
cabfd258
GK
8529 }
8530 else /* move 1 byte at a time */
8531 {
8532 move_bytes = 1;
8533 mode = QImode;
8534 gen_func.mov = gen_movqi;
8535 }
f676971a 8536
cabfd258
GK
8537 src = adjust_address (orig_src, mode, offset);
8538 dest = adjust_address (orig_dest, mode, offset);
f676971a
EC
8539
8540 if (mode != BLKmode)
cabfd258
GK
8541 {
8542 rtx tmp_reg = gen_reg_rtx (mode);
f676971a 8543
cabfd258
GK
8544 emit_insn ((*gen_func.mov) (tmp_reg, src));
8545 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 8546 }
3933e0e1 8547
cabfd258
GK
8548 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
8549 {
8550 int i;
8551 for (i = 0; i < num_reg; i++)
8552 emit_insn (stores[i]);
8553 num_reg = 0;
8554 }
35aff10b 8555
cabfd258 8556 if (mode == BLKmode)
7e69e155 8557 {
70128ad9 8558 /* Move the address into scratch registers. The movmemsi
cabfd258
GK
8559 patterns require zero offset. */
8560 if (!REG_P (XEXP (src, 0)))
b6c9286a 8561 {
cabfd258
GK
8562 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
8563 src = replace_equiv_address (src, src_reg);
b6c9286a 8564 }
cabfd258 8565 set_mem_size (src, GEN_INT (move_bytes));
f676971a 8566
cabfd258 8567 if (!REG_P (XEXP (dest, 0)))
3933e0e1 8568 {
cabfd258
GK
8569 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
8570 dest = replace_equiv_address (dest, dest_reg);
7e69e155 8571 }
cabfd258 8572 set_mem_size (dest, GEN_INT (move_bytes));
f676971a 8573
70128ad9 8574 emit_insn ((*gen_func.movmemsi) (dest, src,
cabfd258
GK
8575 GEN_INT (move_bytes & 31),
8576 align_rtx));
7e69e155 8577 }
7e69e155
MM
8578 }
8579
8580 return 1;
8581}
8582
d62294f5
FJ
8583\f
8584/* Return 1 if OP is suitable for a save_world call in prologue. It is
8585 known to be a PARALLEL. */
8586int
8587save_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8588{
8589 int index;
8590 int i;
8591 rtx elt;
8592 int count = XVECLEN (op, 0);
8593
8594 if (count != 55)
8595 return 0;
8596
8597 index = 0;
8598 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8599 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8600 return 0;
8601
8602 for (i=1; i <= 18; i++)
8603 {
8604 elt = XVECEXP (op, 0, index++);
8605 if (GET_CODE (elt) != SET
8606 || GET_CODE (SET_DEST (elt)) != MEM
8607 || ! memory_operand (SET_DEST (elt), DFmode)
8608 || GET_CODE (SET_SRC (elt)) != REG
8609 || GET_MODE (SET_SRC (elt)) != DFmode)
8610 return 0;
8611 }
8612
8613 for (i=1; i <= 12; i++)
8614 {
8615 elt = XVECEXP (op, 0, index++);
8616 if (GET_CODE (elt) != SET
8617 || GET_CODE (SET_DEST (elt)) != MEM
8618 || GET_CODE (SET_SRC (elt)) != REG
8619 || GET_MODE (SET_SRC (elt)) != V4SImode)
8620 return 0;
8621 }
8622
8623 for (i=1; i <= 19; i++)
8624 {
8625 elt = XVECEXP (op, 0, index++);
8626 if (GET_CODE (elt) != SET
8627 || GET_CODE (SET_DEST (elt)) != MEM
8628 || ! memory_operand (SET_DEST (elt), Pmode)
8629 || GET_CODE (SET_SRC (elt)) != REG
8630 || GET_MODE (SET_SRC (elt)) != Pmode)
8631 return 0;
8632 }
8633
8634 elt = XVECEXP (op, 0, index++);
8635 if (GET_CODE (elt) != SET
8636 || GET_CODE (SET_DEST (elt)) != MEM
8637 || ! memory_operand (SET_DEST (elt), Pmode)
8638 || GET_CODE (SET_SRC (elt)) != REG
8639 || REGNO (SET_SRC (elt)) != CR2_REGNO
8640 || GET_MODE (SET_SRC (elt)) != Pmode)
8641 return 0;
8642
8643 if (GET_CODE (XVECEXP (op, 0, index++)) != USE
8644 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8645 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8646 return 0;
8647 return 1;
8648}
8649
8650/* Return 1 if OP is suitable for a save_world call in prologue. It is
8651 known to be a PARALLEL. */
8652int
8653restore_world_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
8654{
8655 int index;
8656 int i;
8657 rtx elt;
8658 int count = XVECLEN (op, 0);
8659
8660 if (count != 59)
8661 return 0;
8662
8663 index = 0;
8664 if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
8665 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8666 || GET_CODE (XVECEXP (op, 0, index++)) != USE
8667 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
8668 return 0;
8669
8670 elt = XVECEXP (op, 0, index++);
8671 if (GET_CODE (elt) != SET
8672 || GET_CODE (SET_SRC (elt)) != MEM
8673 || ! memory_operand (SET_SRC (elt), Pmode)
8674 || GET_CODE (SET_DEST (elt)) != REG
8675 || REGNO (SET_DEST (elt)) != CR2_REGNO
8676 || GET_MODE (SET_DEST (elt)) != Pmode)
8677 return 0;
8678
8679 for (i=1; i <= 19; i++)
8680 {
8681 elt = XVECEXP (op, 0, index++);
8682 if (GET_CODE (elt) != SET
8683 || GET_CODE (SET_SRC (elt)) != MEM
8684 || ! memory_operand (SET_SRC (elt), Pmode)
8685 || GET_CODE (SET_DEST (elt)) != REG
8686 || GET_MODE (SET_DEST (elt)) != Pmode)
8687 return 0;
8688 }
8689
8690 for (i=1; i <= 12; i++)
8691 {
8692 elt = XVECEXP (op, 0, index++);
8693 if (GET_CODE (elt) != SET
8694 || GET_CODE (SET_SRC (elt)) != MEM
8695 || GET_CODE (SET_DEST (elt)) != REG
8696 || GET_MODE (SET_DEST (elt)) != V4SImode)
8697 return 0;
8698 }
8699
8700 for (i=1; i <= 18; i++)
8701 {
8702 elt = XVECEXP (op, 0, index++);
8703 if (GET_CODE (elt) != SET
8704 || GET_CODE (SET_SRC (elt)) != MEM
8705 || ! memory_operand (SET_SRC (elt), DFmode)
8706 || GET_CODE (SET_DEST (elt)) != REG
8707 || GET_MODE (SET_DEST (elt)) != DFmode)
8708 return 0;
8709 }
8710
8711 if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8712 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8713 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8714 || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
8715 || GET_CODE (XVECEXP (op, 0, index++)) != USE)
8716 return 0;
8717 return 1;
8718}
8719
9878760c
RK
8720\f
8721/* Return 1 if OP is a load multiple operation. It is known to be a
8722 PARALLEL and the first section will be tested. */
8723
8724int
a2369ed3 8725load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8726{
8727 int count = XVECLEN (op, 0);
e2c953b6 8728 unsigned int dest_regno;
9878760c
RK
8729 rtx src_addr;
8730 int i;
8731
8732 /* Perform a quick check so we don't blow up below. */
8733 if (count <= 1
8734 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8735 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8736 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8737 return 0;
8738
8739 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8740 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8741
8742 for (i = 1; i < count; i++)
8743 {
8744 rtx elt = XVECEXP (op, 0, i);
8745
8746 if (GET_CODE (elt) != SET
8747 || GET_CODE (SET_DEST (elt)) != REG
8748 || GET_MODE (SET_DEST (elt)) != SImode
8749 || REGNO (SET_DEST (elt)) != dest_regno + i
8750 || GET_CODE (SET_SRC (elt)) != MEM
8751 || GET_MODE (SET_SRC (elt)) != SImode
8752 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
8753 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
8754 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
8755 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
8756 return 0;
8757 }
8758
8759 return 1;
8760}
8761
8762/* Similar, but tests for store multiple. Here, the second vector element
8763 is a CLOBBER. It will be tested later. */
8764
8765int
a2369ed3 8766store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8767{
8768 int count = XVECLEN (op, 0) - 1;
e2c953b6 8769 unsigned int src_regno;
9878760c
RK
8770 rtx dest_addr;
8771 int i;
8772
8773 /* Perform a quick check so we don't blow up below. */
8774 if (count <= 1
8775 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8776 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8777 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8778 return 0;
8779
8780 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8781 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8782
8783 for (i = 1; i < count; i++)
8784 {
8785 rtx elt = XVECEXP (op, 0, i + 1);
8786
8787 if (GET_CODE (elt) != SET
8788 || GET_CODE (SET_SRC (elt)) != REG
8789 || GET_MODE (SET_SRC (elt)) != SImode
8790 || REGNO (SET_SRC (elt)) != src_regno + i
8791 || GET_CODE (SET_DEST (elt)) != MEM
8792 || GET_MODE (SET_DEST (elt)) != SImode
8793 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
8794 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
8795 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
8796 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
8797 return 0;
8798 }
8799
8800 return 1;
8801}
9ebbca7d 8802
9caa3eb2
DE
8803/* Return a string to perform a load_multiple operation.
8804 operands[0] is the vector.
8805 operands[1] is the source address.
8806 operands[2] is the first destination register. */
8807
8808const char *
a2369ed3 8809rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
8810{
8811 /* We have to handle the case where the pseudo used to contain the address
8812 is assigned to one of the output registers. */
8813 int i, j;
8814 int words = XVECLEN (operands[0], 0);
8815 rtx xop[10];
8816
8817 if (XVECLEN (operands[0], 0) == 1)
8818 return "{l|lwz} %2,0(%1)";
8819
8820 for (i = 0; i < words; i++)
8821 if (refers_to_regno_p (REGNO (operands[2]) + i,
8822 REGNO (operands[2]) + i + 1, operands[1], 0))
8823 {
8824 if (i == words-1)
8825 {
8826 xop[0] = GEN_INT (4 * (words-1));
8827 xop[1] = operands[1];
8828 xop[2] = operands[2];
8829 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
8830 return "";
8831 }
8832 else if (i == 0)
8833 {
8834 xop[0] = GEN_INT (4 * (words-1));
8835 xop[1] = operands[1];
8836 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
8837 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);
8838 return "";
8839 }
8840 else
8841 {
8842 for (j = 0; j < words; j++)
8843 if (j != i)
8844 {
8845 xop[0] = GEN_INT (j * 4);
8846 xop[1] = operands[1];
8847 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
8848 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
8849 }
8850 xop[0] = GEN_INT (i * 4);
8851 xop[1] = operands[1];
8852 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
8853 return "";
8854 }
8855 }
8856
8857 return "{lsi|lswi} %2,%1,%N0";
8858}
8859
00b960c7
AH
8860/* Return 1 for a parallel vrsave operation. */
8861
8862int
a2369ed3 8863vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
8864{
8865 int count = XVECLEN (op, 0);
8866 unsigned int dest_regno, src_regno;
8867 int i;
8868
8869 if (count <= 1
8870 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8871 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 8872 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
8873 return 0;
8874
8875 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8876 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8877
8878 if (dest_regno != VRSAVE_REGNO
8879 && src_regno != VRSAVE_REGNO)
8880 return 0;
8881
8882 for (i = 1; i < count; i++)
8883 {
8884 rtx elt = XVECEXP (op, 0, i);
8885
9aa86737
AH
8886 if (GET_CODE (elt) != CLOBBER
8887 && GET_CODE (elt) != SET)
00b960c7
AH
8888 return 0;
8889 }
8890
8891 return 1;
8892}
8893
2c4a9cff
DE
8894/* Return 1 for an PARALLEL suitable for mfcr. */
8895
8896int
a2369ed3 8897mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
8898{
8899 int count = XVECLEN (op, 0);
8900 int i;
8901
8902 /* Perform a quick check so we don't blow up below. */
8903 if (count < 1
8904 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8905 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8906 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
8907 return 0;
8908
8909 for (i = 0; i < count; i++)
8910 {
8911 rtx exp = XVECEXP (op, 0, i);
8912 rtx unspec;
8913 int maskval;
8914 rtx src_reg;
8915
8916 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
8917
8918 if (GET_CODE (src_reg) != REG
8919 || GET_MODE (src_reg) != CCmode
8920 || ! CR_REGNO_P (REGNO (src_reg)))
8921 return 0;
8922
8923 if (GET_CODE (exp) != SET
8924 || GET_CODE (SET_DEST (exp)) != REG
8925 || GET_MODE (SET_DEST (exp)) != SImode
8926 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
8927 return 0;
8928 unspec = SET_SRC (exp);
8929 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
8930
8931 if (GET_CODE (unspec) != UNSPEC
8932 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
8933 || XVECLEN (unspec, 0) != 2
8934 || XVECEXP (unspec, 0, 0) != src_reg
8935 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8936 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8937 return 0;
8938 }
8939 return 1;
8940}
8941
a4f6c312 8942/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
8943
8944int
a2369ed3 8945mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8946{
8947 int count = XVECLEN (op, 0);
8948 int i;
9ebbca7d
GK
8949 rtx src_reg;
8950
8951 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
8952 if (count < 1
8953 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8954 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8955 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 8956 return 0;
e35b9579 8957 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
f676971a 8958
9ebbca7d
GK
8959 if (GET_CODE (src_reg) != REG
8960 || GET_MODE (src_reg) != SImode
8961 || ! INT_REGNO_P (REGNO (src_reg)))
8962 return 0;
8963
e35b9579 8964 for (i = 0; i < count; i++)
9ebbca7d
GK
8965 {
8966 rtx exp = XVECEXP (op, 0, i);
8967 rtx unspec;
8968 int maskval;
f676971a 8969
9ebbca7d
GK
8970 if (GET_CODE (exp) != SET
8971 || GET_CODE (SET_DEST (exp)) != REG
8972 || GET_MODE (SET_DEST (exp)) != CCmode
8973 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
8974 return 0;
8975 unspec = SET_SRC (exp);
8976 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
f676971a 8977
9ebbca7d 8978 if (GET_CODE (unspec) != UNSPEC
615158e2 8979 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
8980 || XVECLEN (unspec, 0) != 2
8981 || XVECEXP (unspec, 0, 0) != src_reg
8982 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8983 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8984 return 0;
8985 }
e35b9579 8986 return 1;
9ebbca7d
GK
8987}
8988
a4f6c312 8989/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
8990
8991int
a2369ed3 8992lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8993{
8994 int count = XVECLEN (op, 0);
e2c953b6 8995 unsigned int dest_regno;
9ebbca7d 8996 rtx src_addr;
e2c953b6 8997 unsigned int base_regno;
9ebbca7d
GK
8998 HOST_WIDE_INT offset;
8999 int i;
9000
9001 /* Perform a quick check so we don't blow up below. */
9002 if (count <= 1
9003 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9004 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
9005 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
9006 return 0;
9007
9008 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
9009 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
9010
9011 if (dest_regno > 31
e2c953b6 9012 || count != 32 - (int) dest_regno)
9ebbca7d
GK
9013 return 0;
9014
4d588c14 9015 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
9016 {
9017 offset = 0;
9018 base_regno = REGNO (src_addr);
9019 if (base_regno == 0)
9020 return 0;
9021 }
76d2b81d 9022 else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
9023 {
9024 offset = INTVAL (XEXP (src_addr, 1));
9025 base_regno = REGNO (XEXP (src_addr, 0));
9026 }
9027 else
9028 return 0;
9029
9030 for (i = 0; i < count; i++)
9031 {
9032 rtx elt = XVECEXP (op, 0, i);
9033 rtx newaddr;
9034 rtx addr_reg;
9035 HOST_WIDE_INT newoffset;
9036
9037 if (GET_CODE (elt) != SET
9038 || GET_CODE (SET_DEST (elt)) != REG
9039 || GET_MODE (SET_DEST (elt)) != SImode
9040 || REGNO (SET_DEST (elt)) != dest_regno + i
9041 || GET_CODE (SET_SRC (elt)) != MEM
9042 || GET_MODE (SET_SRC (elt)) != SImode)
9043 return 0;
9044 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 9045 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9046 {
9047 newoffset = 0;
9048 addr_reg = newaddr;
9049 }
76d2b81d 9050 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9051 {
9052 addr_reg = XEXP (newaddr, 0);
9053 newoffset = INTVAL (XEXP (newaddr, 1));
9054 }
9055 else
9056 return 0;
9057 if (REGNO (addr_reg) != base_regno
9058 || newoffset != offset + 4 * i)
9059 return 0;
9060 }
9061
9062 return 1;
9063}
9064
a4f6c312 9065/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
9066
9067int
a2369ed3 9068stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
9069{
9070 int count = XVECLEN (op, 0);
e2c953b6 9071 unsigned int src_regno;
9ebbca7d 9072 rtx dest_addr;
e2c953b6 9073 unsigned int base_regno;
9ebbca7d
GK
9074 HOST_WIDE_INT offset;
9075 int i;
9076
9077 /* Perform a quick check so we don't blow up below. */
9078 if (count <= 1
9079 || GET_CODE (XVECEXP (op, 0, 0)) != SET
9080 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
9081 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
9082 return 0;
9083
9084 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
9085 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
9086
9087 if (src_regno > 31
e2c953b6 9088 || count != 32 - (int) src_regno)
9ebbca7d
GK
9089 return 0;
9090
4d588c14 9091 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
9092 {
9093 offset = 0;
9094 base_regno = REGNO (dest_addr);
9095 if (base_regno == 0)
9096 return 0;
9097 }
76d2b81d 9098 else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
9099 {
9100 offset = INTVAL (XEXP (dest_addr, 1));
9101 base_regno = REGNO (XEXP (dest_addr, 0));
9102 }
9103 else
9104 return 0;
9105
9106 for (i = 0; i < count; i++)
9107 {
9108 rtx elt = XVECEXP (op, 0, i);
9109 rtx newaddr;
9110 rtx addr_reg;
9111 HOST_WIDE_INT newoffset;
9112
9113 if (GET_CODE (elt) != SET
9114 || GET_CODE (SET_SRC (elt)) != REG
9115 || GET_MODE (SET_SRC (elt)) != SImode
9116 || REGNO (SET_SRC (elt)) != src_regno + i
9117 || GET_CODE (SET_DEST (elt)) != MEM
9118 || GET_MODE (SET_DEST (elt)) != SImode)
9119 return 0;
9120 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 9121 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
9122 {
9123 newoffset = 0;
9124 addr_reg = newaddr;
9125 }
76d2b81d 9126 else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
9127 {
9128 addr_reg = XEXP (newaddr, 0);
9129 newoffset = INTVAL (XEXP (newaddr, 1));
9130 }
9131 else
9132 return 0;
9133 if (REGNO (addr_reg) != base_regno
9134 || newoffset != offset + 4 * i)
9135 return 0;
9136 }
9137
9138 return 1;
9139}
9878760c 9140\f
a4f6c312
SS
9141/* A validation routine: say whether CODE, a condition code, and MODE
9142 match. The other alternatives either don't make sense or should
9143 never be generated. */
39a10a29 9144
39a10a29 9145static void
a2369ed3 9146validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 9147{
ec8e098d
PB
9148 if ((GET_RTX_CLASS (code) != RTX_COMPARE
9149 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
9150 || GET_MODE_CLASS (mode) != MODE_CC)
9151 abort ();
9152
9153 /* These don't make sense. */
9154 if ((code == GT || code == LT || code == GE || code == LE)
9155 && mode == CCUNSmode)
9156 abort ();
9157
9158 if ((code == GTU || code == LTU || code == GEU || code == LEU)
9159 && mode != CCUNSmode)
9160 abort ();
9161
9162 if (mode != CCFPmode
9163 && (code == ORDERED || code == UNORDERED
9164 || code == UNEQ || code == LTGT
9165 || code == UNGT || code == UNLT
9166 || code == UNGE || code == UNLE))
a4f6c312 9167 abort ();
f676971a
EC
9168
9169 /* These should never be generated except for
bc9ec0e0 9170 flag_finite_math_only. */
39a10a29 9171 if (mode == CCFPmode
ad72b533 9172 && ! flag_finite_math_only
39a10a29
GK
9173 && (code == LE || code == GE
9174 || code == UNEQ || code == LTGT
9175 || code == UNGT || code == UNLT))
9176 abort ();
9177
9178 /* These are invalid; the information is not there. */
f676971a 9179 if (mode == CCEQmode
39a10a29
GK
9180 && code != EQ && code != NE)
9181 abort ();
9182}
9183
9878760c
RK
9184/* Return 1 if OP is a comparison operation that is valid for a branch insn.
9185 We only check the opcode against the mode of the CC value here. */
9186
9187int
a2369ed3 9188branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
9189{
9190 enum rtx_code code = GET_CODE (op);
9191 enum machine_mode cc_mode;
9192
ec8e098d 9193 if (!COMPARISON_P (op))
9878760c
RK
9194 return 0;
9195
9196 cc_mode = GET_MODE (XEXP (op, 0));
9197 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
9198 return 0;
9199
39a10a29 9200 validate_condition_mode (code, cc_mode);
9878760c 9201
39a10a29
GK
9202 return 1;
9203}
9204
9205/* Return 1 if OP is a comparison operation that is valid for a branch
9206 insn and which is true if the corresponding bit in the CC register
9207 is set. */
9208
9209int
a2369ed3 9210branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
9211{
9212 enum rtx_code code;
9213
8daf2e65 9214 if (! branch_comparison_operator (op, mode))
9878760c
RK
9215 return 0;
9216
39a10a29
GK
9217 code = GET_CODE (op);
9218 return (code == EQ || code == LT || code == GT
9219 || code == LTU || code == GTU
9220 || code == UNORDERED);
9878760c
RK
9221}
9222
b7053a3f
GK
9223/* Return 1 if OP is a comparison operation that is valid for an scc
9224 insn: it must be a positive comparison. */
9878760c
RK
9225
9226int
a2369ed3 9227scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 9228{
b7053a3f 9229 return branch_positive_comparison_operator (op, mode);
9878760c 9230}
e0cd0770
JC
9231
9232int
a2369ed3 9233trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
9234{
9235 if (mode != VOIDmode && mode != GET_MODE (op))
9236 return 0;
ec8e098d 9237 return COMPARISON_P (op);
e0cd0770 9238}
dfbdccdb
GK
9239
9240int
a2369ed3 9241boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
9242{
9243 enum rtx_code code = GET_CODE (op);
9244 return (code == AND || code == IOR || code == XOR);
9245}
1d328b19
GK
9246
9247int
a2369ed3 9248boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
9249{
9250 enum rtx_code code = GET_CODE (op);
9251 return (code == IOR || code == XOR);
9252}
50a0b056
GK
9253
9254int
a2369ed3 9255min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
9256{
9257 enum rtx_code code = GET_CODE (op);
9258 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
9259}
9878760c
RK
9260\f
9261/* Return 1 if ANDOP is a mask that has no bits on that are not in the
9262 mask required to convert the result of a rotate insn into a shift
b1765bde 9263 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
9264
9265int
a2369ed3 9266includes_lshift_p (rtx shiftop, rtx andop)
9878760c 9267{
e2c953b6
DE
9268 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9269
9270 shift_mask <<= INTVAL (shiftop);
9878760c 9271
b1765bde 9272 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
9273}
9274
9275/* Similar, but for right shift. */
9276
9277int
a2369ed3 9278includes_rshift_p (rtx shiftop, rtx andop)
9878760c 9279{
a7653a2c 9280 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
9281
9282 shift_mask >>= INTVAL (shiftop);
9283
b1765bde 9284 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
9285}
9286
c5059423
AM
9287/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
9288 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 9289 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
9290
9291int
a2369ed3 9292includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 9293{
c5059423
AM
9294 if (GET_CODE (andop) == CONST_INT)
9295 {
02071907 9296 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 9297
c5059423 9298 c = INTVAL (andop);
02071907 9299 if (c == 0 || c == ~0)
c5059423 9300 return 0;
e2c953b6 9301
02071907 9302 shift_mask = ~0;
c5059423
AM
9303 shift_mask <<= INTVAL (shiftop);
9304
b6d08ca1 9305 /* Find the least significant one bit. */
c5059423
AM
9306 lsb = c & -c;
9307
9308 /* It must coincide with the LSB of the shift mask. */
9309 if (-lsb != shift_mask)
9310 return 0;
e2c953b6 9311
c5059423
AM
9312 /* Invert to look for the next transition (if any). */
9313 c = ~c;
9314
9315 /* Remove the low group of ones (originally low group of zeros). */
9316 c &= -lsb;
9317
9318 /* Again find the lsb, and check we have all 1's above. */
9319 lsb = c & -c;
9320 return c == -lsb;
9321 }
9322 else if (GET_CODE (andop) == CONST_DOUBLE
9323 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9324 {
02071907
AM
9325 HOST_WIDE_INT low, high, lsb;
9326 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
9327
9328 low = CONST_DOUBLE_LOW (andop);
9329 if (HOST_BITS_PER_WIDE_INT < 64)
9330 high = CONST_DOUBLE_HIGH (andop);
9331
9332 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 9333 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
9334 return 0;
9335
9336 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9337 {
02071907 9338 shift_mask_high = ~0;
c5059423
AM
9339 if (INTVAL (shiftop) > 32)
9340 shift_mask_high <<= INTVAL (shiftop) - 32;
9341
9342 lsb = high & -high;
9343
9344 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
9345 return 0;
9346
9347 high = ~high;
9348 high &= -lsb;
9349
9350 lsb = high & -high;
9351 return high == -lsb;
9352 }
9353
02071907 9354 shift_mask_low = ~0;
c5059423
AM
9355 shift_mask_low <<= INTVAL (shiftop);
9356
9357 lsb = low & -low;
9358
9359 if (-lsb != shift_mask_low)
9360 return 0;
9361
9362 if (HOST_BITS_PER_WIDE_INT < 64)
9363 high = ~high;
9364 low = ~low;
9365 low &= -lsb;
9366
9367 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
9368 {
9369 lsb = high & -high;
9370 return high == -lsb;
9371 }
9372
9373 lsb = low & -low;
9374 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
9375 }
9376 else
9377 return 0;
9378}
e2c953b6 9379
c5059423
AM
9380/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
9381 to perform a left shift. It must have SHIFTOP or more least
c1207243 9382 significant 0's, with the remainder of the word 1's. */
e2c953b6 9383
c5059423 9384int
a2369ed3 9385includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 9386{
e2c953b6 9387 if (GET_CODE (andop) == CONST_INT)
c5059423 9388 {
02071907 9389 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 9390
02071907 9391 shift_mask = ~0;
c5059423
AM
9392 shift_mask <<= INTVAL (shiftop);
9393 c = INTVAL (andop);
9394
c1207243 9395 /* Find the least significant one bit. */
c5059423
AM
9396 lsb = c & -c;
9397
9398 /* It must be covered by the shift mask.
a4f6c312 9399 This test also rejects c == 0. */
c5059423
AM
9400 if ((lsb & shift_mask) == 0)
9401 return 0;
9402
9403 /* Check we have all 1's above the transition, and reject all 1's. */
9404 return c == -lsb && lsb != 1;
9405 }
9406 else if (GET_CODE (andop) == CONST_DOUBLE
9407 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
9408 {
02071907 9409 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
9410
9411 low = CONST_DOUBLE_LOW (andop);
9412
9413 if (HOST_BITS_PER_WIDE_INT < 64)
9414 {
02071907 9415 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
9416
9417 high = CONST_DOUBLE_HIGH (andop);
9418
9419 if (low == 0)
9420 {
02071907 9421 shift_mask_high = ~0;
c5059423
AM
9422 if (INTVAL (shiftop) > 32)
9423 shift_mask_high <<= INTVAL (shiftop) - 32;
9424
9425 lsb = high & -high;
9426
9427 if ((lsb & shift_mask_high) == 0)
9428 return 0;
9429
9430 return high == -lsb;
9431 }
9432 if (high != ~0)
9433 return 0;
9434 }
9435
02071907 9436 shift_mask_low = ~0;
c5059423
AM
9437 shift_mask_low <<= INTVAL (shiftop);
9438
9439 lsb = low & -low;
9440
9441 if ((lsb & shift_mask_low) == 0)
9442 return 0;
9443
9444 return low == -lsb && lsb != 1;
9445 }
e2c953b6 9446 else
c5059423 9447 return 0;
9878760c 9448}
35068b43 9449
11ac38b2
DE
9450/* Return 1 if operands will generate a valid arguments to rlwimi
9451instruction for insert with right shift in 64-bit mode. The mask may
9452not start on the first bit or stop on the last bit because wrap-around
9453effects of instruction do not correspond to semantics of RTL insn. */
9454
9455int
9456insvdi_rshift_rlwimi_p (rtx sizeop, rtx startop, rtx shiftop)
9457{
9458 if (INTVAL (startop) < 64
9459 && INTVAL (startop) > 32
9460 && (INTVAL (sizeop) + INTVAL (startop) < 64)
9461 && (INTVAL (sizeop) + INTVAL (startop) > 33)
9462 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) < 96)
9463 && (INTVAL (sizeop) + INTVAL (startop) + INTVAL (shiftop) >= 64)
9464 && (64 - (INTVAL (shiftop) & 63)) >= INTVAL (sizeop))
9465 return 1;
9466
9467 return 0;
9468}
9469
35068b43 9470/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
90f81f99 9471 for lfq and stfq insns iff the registers are hard registers. */
35068b43
RK
9472
9473int
a2369ed3 9474registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
9475{
9476 /* We might have been passed a SUBREG. */
f676971a 9477 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
35068b43 9478 return 0;
f676971a 9479
90f81f99
AP
9480 /* We might have been passed non floating point registers. */
9481 if (!FP_REGNO_P (REGNO (reg1))
9482 || !FP_REGNO_P (REGNO (reg2)))
9483 return 0;
35068b43
RK
9484
9485 return (REGNO (reg1) == REGNO (reg2) - 1);
9486}
9487
a4f6c312
SS
9488/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
9489 addr1 and addr2 must be in consecutive memory locations
9490 (addr2 == addr1 + 8). */
35068b43
RK
9491
9492int
90f81f99 9493mems_ok_for_quad_peep (rtx mem1, rtx mem2)
35068b43 9494{
90f81f99 9495 rtx addr1, addr2;
e2c953b6 9496 unsigned int reg1;
35068b43
RK
9497 int offset1;
9498
90f81f99
AP
9499 /* The mems cannot be volatile. */
9500 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
9501 return 0;
f676971a 9502
90f81f99
AP
9503 addr1 = XEXP (mem1, 0);
9504 addr2 = XEXP (mem2, 0);
9505
35068b43
RK
9506 /* Extract an offset (if used) from the first addr. */
9507 if (GET_CODE (addr1) == PLUS)
9508 {
9509 /* If not a REG, return zero. */
9510 if (GET_CODE (XEXP (addr1, 0)) != REG)
9511 return 0;
9512 else
9513 {
9514 reg1 = REGNO (XEXP (addr1, 0));
9515 /* The offset must be constant! */
9516 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
9517 return 0;
9518 offset1 = INTVAL (XEXP (addr1, 1));
9519 }
9520 }
9521 else if (GET_CODE (addr1) != REG)
9522 return 0;
9523 else
9524 {
9525 reg1 = REGNO (addr1);
9526 /* This was a simple (mem (reg)) expression. Offset is 0. */
9527 offset1 = 0;
9528 }
9529
a2369ed3 9530 /* Make sure the second address is a (mem (plus (reg) (const_int)))
f676971a 9531 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
0f6937fe 9532 register as addr1. */
984e25ac 9533 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 9534 return 1;
35068b43
RK
9535 if (GET_CODE (addr2) != PLUS)
9536 return 0;
9537
9538 if (GET_CODE (XEXP (addr2, 0)) != REG
9539 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
9540 return 0;
9541
9542 if (reg1 != REGNO (XEXP (addr2, 0)))
9543 return 0;
9544
9545 /* The offset for the second addr must be 8 more than the first addr. */
9546 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
9547 return 0;
9548
9549 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
9550 instructions. */
9551 return 1;
9552}
9878760c
RK
9553\f
9554/* Return the register class of a scratch register needed to copy IN into
9555 or out of a register in CLASS in MODE. If it can be done directly,
9556 NO_REGS is returned. */
9557
9558enum reg_class
f676971a 9559secondary_reload_class (enum reg_class class,
a9baceb1
GK
9560 enum machine_mode mode ATTRIBUTE_UNUSED,
9561 rtx in)
9878760c 9562{
5accd822 9563 int regno;
9878760c 9564
ab82a49f
AP
9565 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
9566#if TARGET_MACHO
9567 && MACHOPIC_INDIRECT
9568#endif
9569 ))
46fad5b7
DJ
9570 {
9571 /* We cannot copy a symbolic operand directly into anything
9572 other than BASE_REGS for TARGET_ELF. So indicate that a
9573 register from BASE_REGS is needed as an intermediate
9574 register.
f676971a 9575
46fad5b7
DJ
9576 On Darwin, pic addresses require a load from memory, which
9577 needs a base register. */
9578 if (class != BASE_REGS
9579 && (GET_CODE (in) == SYMBOL_REF
9580 || GET_CODE (in) == HIGH
9581 || GET_CODE (in) == LABEL_REF
9582 || GET_CODE (in) == CONST))
9583 return BASE_REGS;
9584 }
e7b7998a 9585
5accd822
DE
9586 if (GET_CODE (in) == REG)
9587 {
9588 regno = REGNO (in);
9589 if (regno >= FIRST_PSEUDO_REGISTER)
9590 {
9591 regno = true_regnum (in);
9592 if (regno >= FIRST_PSEUDO_REGISTER)
9593 regno = -1;
9594 }
9595 }
9596 else if (GET_CODE (in) == SUBREG)
9597 {
9598 regno = true_regnum (in);
9599 if (regno >= FIRST_PSEUDO_REGISTER)
9600 regno = -1;
9601 }
9602 else
9603 regno = -1;
9604
9878760c
RK
9605 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
9606 into anything. */
9607 if (class == GENERAL_REGS || class == BASE_REGS
9608 || (regno >= 0 && INT_REGNO_P (regno)))
9609 return NO_REGS;
9610
9611 /* Constants, memory, and FP registers can go into FP registers. */
9612 if ((regno == -1 || FP_REGNO_P (regno))
9613 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
9614 return NO_REGS;
9615
0ac081f6
AH
9616 /* Memory, and AltiVec registers can go into AltiVec registers. */
9617 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
9618 && class == ALTIVEC_REGS)
9619 return NO_REGS;
9620
9878760c
RK
9621 /* We can copy among the CR registers. */
9622 if ((class == CR_REGS || class == CR0_REGS)
9623 && regno >= 0 && CR_REGNO_P (regno))
9624 return NO_REGS;
9625
9626 /* Otherwise, we need GENERAL_REGS. */
9627 return GENERAL_REGS;
9628}
9629\f
9630/* Given a comparison operation, return the bit number in CCR to test. We
f676971a 9631 know this is a valid comparison.
9878760c
RK
9632
9633 SCC_P is 1 if this is for an scc. That means that %D will have been
9634 used instead of %C, so the bits will be in different places.
9635
b4ac57ab 9636 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
9637
9638int
a2369ed3 9639ccr_bit (rtx op, int scc_p)
9878760c
RK
9640{
9641 enum rtx_code code = GET_CODE (op);
9642 enum machine_mode cc_mode;
9643 int cc_regnum;
9644 int base_bit;
9ebbca7d 9645 rtx reg;
9878760c 9646
ec8e098d 9647 if (!COMPARISON_P (op))
9878760c
RK
9648 return -1;
9649
9ebbca7d
GK
9650 reg = XEXP (op, 0);
9651
9652 if (GET_CODE (reg) != REG
9653 || ! CR_REGNO_P (REGNO (reg)))
9654 abort ();
9655
9656 cc_mode = GET_MODE (reg);
9657 cc_regnum = REGNO (reg);
9658 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 9659
39a10a29 9660 validate_condition_mode (code, cc_mode);
c5defebb 9661
b7053a3f
GK
9662 /* When generating a sCOND operation, only positive conditions are
9663 allowed. */
9664 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
9665 && code != GTU && code != LTU)
9666 abort ();
f676971a 9667
9878760c
RK
9668 switch (code)
9669 {
9670 case NE:
9671 return scc_p ? base_bit + 3 : base_bit + 2;
9672 case EQ:
9673 return base_bit + 2;
1c882ea4 9674 case GT: case GTU: case UNLE:
9878760c 9675 return base_bit + 1;
1c882ea4 9676 case LT: case LTU: case UNGE:
9878760c 9677 return base_bit;
1c882ea4
GK
9678 case ORDERED: case UNORDERED:
9679 return base_bit + 3;
9878760c
RK
9680
9681 case GE: case GEU:
39a10a29 9682 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
9683 unordered position. So test that bit. For integer, this is ! LT
9684 unless this is an scc insn. */
39a10a29 9685 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
9686
9687 case LE: case LEU:
39a10a29 9688 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 9689
9878760c
RK
9690 default:
9691 abort ();
9692 }
9693}
1ff7789b 9694\f
8d30c4ee 9695/* Return the GOT register. */
1ff7789b
MM
9696
9697struct rtx_def *
a2369ed3 9698rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 9699{
a4f6c312
SS
9700 /* The second flow pass currently (June 1999) can't update
9701 regs_ever_live without disturbing other parts of the compiler, so
9702 update it here to make the prolog/epilogue code happy. */
1db02437
FS
9703 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
9704 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 9705
8d30c4ee 9706 current_function_uses_pic_offset_table = 1;
3cb999d8 9707
1ff7789b
MM
9708 return pic_offset_table_rtx;
9709}
a7df97e6 9710\f
e2500fed
GK
9711/* Function to init struct machine_function.
9712 This will be called, via a pointer variable,
9713 from push_function_context. */
a7df97e6 9714
e2500fed 9715static struct machine_function *
863d938c 9716rs6000_init_machine_status (void)
a7df97e6 9717{
e2500fed 9718 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 9719}
9878760c 9720\f
0ba1b2ff
AM
9721/* These macros test for integers and extract the low-order bits. */
9722#define INT_P(X) \
9723((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
9724 && GET_MODE (X) == VOIDmode)
9725
9726#define INT_LOWPART(X) \
9727 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
9728
9729int
a2369ed3 9730extract_MB (rtx op)
0ba1b2ff
AM
9731{
9732 int i;
9733 unsigned long val = INT_LOWPART (op);
9734
9735 /* If the high bit is zero, the value is the first 1 bit we find
9736 from the left. */
9737 if ((val & 0x80000000) == 0)
9738 {
9739 if ((val & 0xffffffff) == 0)
9740 abort ();
9741
9742 i = 1;
9743 while (((val <<= 1) & 0x80000000) == 0)
9744 ++i;
9745 return i;
9746 }
9747
9748 /* If the high bit is set and the low bit is not, or the mask is all
9749 1's, the value is zero. */
9750 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
9751 return 0;
9752
9753 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9754 from the right. */
9755 i = 31;
9756 while (((val >>= 1) & 1) != 0)
9757 --i;
9758
9759 return i;
9760}
9761
9762int
a2369ed3 9763extract_ME (rtx op)
0ba1b2ff
AM
9764{
9765 int i;
9766 unsigned long val = INT_LOWPART (op);
9767
9768 /* If the low bit is zero, the value is the first 1 bit we find from
9769 the right. */
9770 if ((val & 1) == 0)
9771 {
9772 if ((val & 0xffffffff) == 0)
9773 abort ();
9774
9775 i = 30;
9776 while (((val >>= 1) & 1) == 0)
9777 --i;
9778
9779 return i;
9780 }
9781
9782 /* If the low bit is set and the high bit is not, or the mask is all
9783 1's, the value is 31. */
9784 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
9785 return 31;
9786
9787 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9788 from the left. */
9789 i = 0;
9790 while (((val <<= 1) & 0x80000000) != 0)
9791 ++i;
9792
9793 return i;
9794}
9795
c4501e62
JJ
9796/* Locate some local-dynamic symbol still in use by this function
9797 so that we can print its name in some tls_ld pattern. */
9798
9799static const char *
863d938c 9800rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
9801{
9802 rtx insn;
9803
9804 if (cfun->machine->some_ld_name)
9805 return cfun->machine->some_ld_name;
9806
9807 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
9808 if (INSN_P (insn)
9809 && for_each_rtx (&PATTERN (insn),
9810 rs6000_get_some_local_dynamic_name_1, 0))
9811 return cfun->machine->some_ld_name;
9812
9813 abort ();
9814}
9815
9816/* Helper function for rs6000_get_some_local_dynamic_name. */
9817
9818static int
a2369ed3 9819rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
9820{
9821 rtx x = *px;
9822
9823 if (GET_CODE (x) == SYMBOL_REF)
9824 {
9825 const char *str = XSTR (x, 0);
9826 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
9827 {
9828 cfun->machine->some_ld_name = str;
9829 return 1;
9830 }
9831 }
9832
9833 return 0;
9834}
9835
85b776df
AM
9836/* Write out a function code label. */
9837
9838void
9839rs6000_output_function_entry (FILE *file, const char *fname)
9840{
9841 if (fname[0] != '.')
9842 {
9843 switch (DEFAULT_ABI)
9844 {
9845 default:
9846 abort ();
9847
9848 case ABI_AIX:
9849 if (DOT_SYMBOLS)
9850 putc ('.', file);
9851 else
9852 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "L.");
9853 break;
9854
9855 case ABI_V4:
9856 case ABI_DARWIN:
9857 break;
9858 }
9859 }
9860 if (TARGET_AIX)
9861 RS6000_OUTPUT_BASENAME (file, fname);
9862 else
9863 assemble_name (file, fname);
9864}
9865
9878760c
RK
9866/* Print an operand. Recognize special options, documented below. */
9867
38c1f2d7 9868#if TARGET_ELF
d9407988 9869#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 9870#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
9871#else
9872#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 9873#define SMALL_DATA_REG 0
ba5e43aa
MM
9874#endif
9875
9878760c 9876void
a2369ed3 9877print_operand (FILE *file, rtx x, int code)
9878760c
RK
9878{
9879 int i;
a260abc9 9880 HOST_WIDE_INT val;
0ba1b2ff 9881 unsigned HOST_WIDE_INT uval;
9878760c
RK
9882
9883 switch (code)
9884 {
a8b3aeda 9885 case '.':
a85d226b
RK
9886 /* Write out an instruction after the call which may be replaced
9887 with glue code by the loader. This depends on the AIX version. */
9888 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
9889 return;
9890
81eace42
GK
9891 /* %a is output_address. */
9892
9854d9ed
RK
9893 case 'A':
9894 /* If X is a constant integer whose low-order 5 bits are zero,
9895 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 9896 in the AIX assembler where "sri" with a zero shift count
20e26713 9897 writes a trash instruction. */
9854d9ed 9898 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 9899 putc ('l', file);
9854d9ed 9900 else
76229ac8 9901 putc ('r', file);
9854d9ed
RK
9902 return;
9903
9904 case 'b':
e2c953b6
DE
9905 /* If constant, low-order 16 bits of constant, unsigned.
9906 Otherwise, write normally. */
9907 if (INT_P (x))
9908 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
9909 else
9910 print_operand (file, x, 0);
cad12a8d
RK
9911 return;
9912
a260abc9
DE
9913 case 'B':
9914 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
9915 for 64-bit mask direction. */
296b8152 9916 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 9917 return;
a260abc9 9918
81eace42
GK
9919 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
9920 output_operand. */
9921
423c1189
AH
9922 case 'c':
9923 /* X is a CR register. Print the number of the GT bit of the CR. */
9924 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9925 output_operand_lossage ("invalid %%E value");
9926 else
9927 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1);
9928 return;
9929
9930 case 'D':
6b1fedc3 9931 /* Like 'J' but get to the EQ bit. */
423c1189
AH
9932 if (GET_CODE (x) != REG)
9933 abort ();
9934
6b1fedc3
AH
9935 /* Bit 1 is EQ bit. */
9936 i = 4 * (REGNO (x) - CR0_REGNO) + 2;
423c1189
AH
9937
9938 /* If we want bit 31, write a shift count of zero, not 32. */
9939 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9940 return;
9941
9854d9ed 9942 case 'E':
39a10a29 9943 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
9944 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9945 output_operand_lossage ("invalid %%E value");
78fbdbf7 9946 else
39a10a29 9947 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 9948 return;
9854d9ed
RK
9949
9950 case 'f':
9951 /* X is a CR register. Print the shift count needed to move it
9952 to the high-order four bits. */
9953 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9954 output_operand_lossage ("invalid %%f value");
9955 else
9ebbca7d 9956 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9957 return;
9958
9959 case 'F':
9960 /* Similar, but print the count for the rotate in the opposite
9961 direction. */
9962 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9963 output_operand_lossage ("invalid %%F value");
9964 else
9ebbca7d 9965 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9966 return;
9967
9968 case 'G':
9969 /* X is a constant integer. If it is negative, print "m",
43aa4e05 9970 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
9971 if (GET_CODE (x) != CONST_INT)
9972 output_operand_lossage ("invalid %%G value");
9973 else if (INTVAL (x) >= 0)
76229ac8 9974 putc ('z', file);
9854d9ed 9975 else
76229ac8 9976 putc ('m', file);
9854d9ed 9977 return;
e2c953b6 9978
9878760c 9979 case 'h':
a4f6c312
SS
9980 /* If constant, output low-order five bits. Otherwise, write
9981 normally. */
9878760c 9982 if (INT_P (x))
5f59ecb7 9983 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
9984 else
9985 print_operand (file, x, 0);
9986 return;
9987
64305719 9988 case 'H':
a4f6c312
SS
9989 /* If constant, output low-order six bits. Otherwise, write
9990 normally. */
64305719 9991 if (INT_P (x))
5f59ecb7 9992 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
9993 else
9994 print_operand (file, x, 0);
9995 return;
9996
9854d9ed
RK
9997 case 'I':
9998 /* Print `i' if this is a constant, else nothing. */
9878760c 9999 if (INT_P (x))
76229ac8 10000 putc ('i', file);
9878760c
RK
10001 return;
10002
9854d9ed
RK
10003 case 'j':
10004 /* Write the bit number in CCR for jump. */
10005 i = ccr_bit (x, 0);
10006 if (i == -1)
10007 output_operand_lossage ("invalid %%j code");
9878760c 10008 else
9854d9ed 10009 fprintf (file, "%d", i);
9878760c
RK
10010 return;
10011
9854d9ed
RK
10012 case 'J':
10013 /* Similar, but add one for shift count in rlinm for scc and pass
10014 scc flag to `ccr_bit'. */
10015 i = ccr_bit (x, 1);
10016 if (i == -1)
10017 output_operand_lossage ("invalid %%J code");
10018 else
a0466a68
RK
10019 /* If we want bit 31, write a shift count of zero, not 32. */
10020 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
10021 return;
10022
9854d9ed
RK
10023 case 'k':
10024 /* X must be a constant. Write the 1's complement of the
10025 constant. */
9878760c 10026 if (! INT_P (x))
9854d9ed 10027 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
10028 else
10029 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
10030 return;
10031
81eace42 10032 case 'K':
9ebbca7d
GK
10033 /* X must be a symbolic constant on ELF. Write an
10034 expression suitable for an 'addi' that adds in the low 16
10035 bits of the MEM. */
10036 if (GET_CODE (x) != CONST)
10037 {
10038 print_operand_address (file, x);
10039 fputs ("@l", file);
10040 }
10041 else
10042 {
10043 if (GET_CODE (XEXP (x, 0)) != PLUS
10044 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
10045 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
10046 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 10047 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
10048 print_operand_address (file, XEXP (XEXP (x, 0), 0));
10049 fputs ("@l", file);
ed8d2920
MM
10050 /* For GNU as, there must be a non-alphanumeric character
10051 between 'l' and the number. The '-' is added by
10052 print_operand() already. */
10053 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
10054 fputs ("+", file);
9ebbca7d
GK
10055 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
10056 }
81eace42
GK
10057 return;
10058
10059 /* %l is output_asm_label. */
9ebbca7d 10060
9854d9ed
RK
10061 case 'L':
10062 /* Write second word of DImode or DFmode reference. Works on register
10063 or non-indexed memory only. */
10064 if (GET_CODE (x) == REG)
5ebfb2ba 10065 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
10066 else if (GET_CODE (x) == MEM)
10067 {
10068 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 10069 we have already done it, we can just use an offset of word. */
9854d9ed
RK
10070 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10071 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
10072 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
10073 UNITS_PER_WORD));
9854d9ed 10074 else
d7624dc0
RK
10075 output_address (XEXP (adjust_address_nv (x, SImode,
10076 UNITS_PER_WORD),
10077 0));
ed8908e7 10078
ba5e43aa 10079 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10080 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10081 reg_names[SMALL_DATA_REG]);
9854d9ed 10082 }
9878760c 10083 return;
f676971a 10084
9878760c
RK
10085 case 'm':
10086 /* MB value for a mask operand. */
b1765bde 10087 if (! mask_operand (x, SImode))
9878760c
RK
10088 output_operand_lossage ("invalid %%m value");
10089
0ba1b2ff 10090 fprintf (file, "%d", extract_MB (x));
9878760c
RK
10091 return;
10092
10093 case 'M':
10094 /* ME value for a mask operand. */
b1765bde 10095 if (! mask_operand (x, SImode))
a260abc9 10096 output_operand_lossage ("invalid %%M value");
9878760c 10097
0ba1b2ff 10098 fprintf (file, "%d", extract_ME (x));
9878760c
RK
10099 return;
10100
81eace42
GK
10101 /* %n outputs the negative of its operand. */
10102
9878760c
RK
10103 case 'N':
10104 /* Write the number of elements in the vector times 4. */
10105 if (GET_CODE (x) != PARALLEL)
10106 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
10107 else
10108 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
10109 return;
10110
10111 case 'O':
10112 /* Similar, but subtract 1 first. */
10113 if (GET_CODE (x) != PARALLEL)
1427100a 10114 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
10115 else
10116 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
10117 return;
10118
9854d9ed
RK
10119 case 'p':
10120 /* X is a CONST_INT that is a power of two. Output the logarithm. */
10121 if (! INT_P (x)
2bfcf297 10122 || INT_LOWPART (x) < 0
9854d9ed
RK
10123 || (i = exact_log2 (INT_LOWPART (x))) < 0)
10124 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
10125 else
10126 fprintf (file, "%d", i);
9854d9ed
RK
10127 return;
10128
9878760c
RK
10129 case 'P':
10130 /* The operand must be an indirect memory reference. The result
8bb418a3 10131 is the register name. */
9878760c
RK
10132 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
10133 || REGNO (XEXP (x, 0)) >= 32)
10134 output_operand_lossage ("invalid %%P value");
e2c953b6 10135 else
8bb418a3 10136 fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]);
9878760c
RK
10137 return;
10138
dfbdccdb
GK
10139 case 'q':
10140 /* This outputs the logical code corresponding to a boolean
10141 expression. The expression may have one or both operands
39a10a29
GK
10142 negated (if one, only the first one). For condition register
10143 logical operations, it will also treat the negated
10144 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 10145 {
63bc1d05 10146 const char *const *t = 0;
dfbdccdb
GK
10147 const char *s;
10148 enum rtx_code code = GET_CODE (x);
10149 static const char * const tbl[3][3] = {
10150 { "and", "andc", "nor" },
10151 { "or", "orc", "nand" },
10152 { "xor", "eqv", "xor" } };
10153
10154 if (code == AND)
10155 t = tbl[0];
10156 else if (code == IOR)
10157 t = tbl[1];
10158 else if (code == XOR)
10159 t = tbl[2];
10160 else
10161 output_operand_lossage ("invalid %%q value");
10162
10163 if (GET_CODE (XEXP (x, 0)) != NOT)
10164 s = t[0];
10165 else
10166 {
10167 if (GET_CODE (XEXP (x, 1)) == NOT)
10168 s = t[2];
10169 else
10170 s = t[1];
10171 }
f676971a 10172
dfbdccdb
GK
10173 fputs (s, file);
10174 }
10175 return;
10176
2c4a9cff
DE
10177 case 'Q':
10178 if (TARGET_MFCRF)
3b6ce0af 10179 fputc (',', file);
5efb1046 10180 /* FALLTHRU */
2c4a9cff
DE
10181 else
10182 return;
10183
9854d9ed
RK
10184 case 'R':
10185 /* X is a CR register. Print the mask for `mtcrf'. */
10186 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
10187 output_operand_lossage ("invalid %%R value");
10188 else
9ebbca7d 10189 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 10190 return;
9854d9ed
RK
10191
10192 case 's':
10193 /* Low 5 bits of 32 - value */
10194 if (! INT_P (x))
10195 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
10196 else
10197 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 10198 return;
9854d9ed 10199
a260abc9 10200 case 'S':
0ba1b2ff 10201 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
10202 CONST_INT 32-bit mask is considered sign-extended so any
10203 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 10204 if (! mask64_operand (x, DImode))
a260abc9
DE
10205 output_operand_lossage ("invalid %%S value");
10206
0ba1b2ff 10207 uval = INT_LOWPART (x);
a260abc9 10208
0ba1b2ff 10209 if (uval & 1) /* Clear Left */
a260abc9 10210 {
f099d360
GK
10211#if HOST_BITS_PER_WIDE_INT > 64
10212 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10213#endif
0ba1b2ff 10214 i = 64;
a260abc9 10215 }
0ba1b2ff 10216 else /* Clear Right */
a260abc9 10217 {
0ba1b2ff 10218 uval = ~uval;
f099d360
GK
10219#if HOST_BITS_PER_WIDE_INT > 64
10220 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
10221#endif
0ba1b2ff 10222 i = 63;
a260abc9 10223 }
0ba1b2ff
AM
10224 while (uval != 0)
10225 --i, uval >>= 1;
10226 if (i < 0)
10227 abort ();
10228 fprintf (file, "%d", i);
10229 return;
a260abc9 10230
a3170dc6
AH
10231 case 't':
10232 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
10233 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
10234 abort ();
10235
10236 /* Bit 3 is OV bit. */
10237 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
10238
10239 /* If we want bit 31, write a shift count of zero, not 32. */
10240 fprintf (file, "%d", i == 31 ? 0 : i + 1);
10241 return;
10242
cccf3bdc
DE
10243 case 'T':
10244 /* Print the symbolic name of a branch target register. */
10245 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
10246 && REGNO (x) != COUNT_REGISTER_REGNUM))
10247 output_operand_lossage ("invalid %%T value");
e2c953b6 10248 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
10249 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
10250 else
10251 fputs ("ctr", file);
10252 return;
10253
9854d9ed 10254 case 'u':
802a0058 10255 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
10256 if (! INT_P (x))
10257 output_operand_lossage ("invalid %%u value");
e2c953b6 10258 else
f676971a 10259 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
e2c953b6 10260 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
10261 return;
10262
802a0058
MM
10263 case 'v':
10264 /* High-order 16 bits of constant for use in signed operand. */
10265 if (! INT_P (x))
10266 output_operand_lossage ("invalid %%v value");
e2c953b6 10267 else
134c32f6
DE
10268 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
10269 (INT_LOWPART (x) >> 16) & 0xffff);
10270 return;
802a0058 10271
9854d9ed
RK
10272 case 'U':
10273 /* Print `u' if this has an auto-increment or auto-decrement. */
10274 if (GET_CODE (x) == MEM
10275 && (GET_CODE (XEXP (x, 0)) == PRE_INC
10276 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 10277 putc ('u', file);
9854d9ed 10278 return;
9878760c 10279
e0cd0770
JC
10280 case 'V':
10281 /* Print the trap code for this operand. */
10282 switch (GET_CODE (x))
10283 {
10284 case EQ:
10285 fputs ("eq", file); /* 4 */
10286 break;
10287 case NE:
10288 fputs ("ne", file); /* 24 */
10289 break;
10290 case LT:
10291 fputs ("lt", file); /* 16 */
10292 break;
10293 case LE:
10294 fputs ("le", file); /* 20 */
10295 break;
10296 case GT:
10297 fputs ("gt", file); /* 8 */
10298 break;
10299 case GE:
10300 fputs ("ge", file); /* 12 */
10301 break;
10302 case LTU:
10303 fputs ("llt", file); /* 2 */
10304 break;
10305 case LEU:
10306 fputs ("lle", file); /* 6 */
10307 break;
10308 case GTU:
10309 fputs ("lgt", file); /* 1 */
10310 break;
10311 case GEU:
10312 fputs ("lge", file); /* 5 */
10313 break;
10314 default:
10315 abort ();
10316 }
10317 break;
10318
9854d9ed
RK
10319 case 'w':
10320 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
10321 normally. */
10322 if (INT_P (x))
f676971a 10323 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
5f59ecb7 10324 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
10325 else
10326 print_operand (file, x, 0);
9878760c
RK
10327 return;
10328
9854d9ed 10329 case 'W':
e2c953b6 10330 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
10331 val = (GET_CODE (x) == CONST_INT
10332 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
10333
10334 if (val < 0)
10335 i = -1;
9854d9ed 10336 else
e2c953b6
DE
10337 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
10338 if ((val <<= 1) < 0)
10339 break;
10340
10341#if HOST_BITS_PER_WIDE_INT == 32
10342 if (GET_CODE (x) == CONST_INT && i >= 0)
10343 i += 32; /* zero-extend high-part was all 0's */
10344 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
10345 {
10346 val = CONST_DOUBLE_LOW (x);
10347
10348 if (val == 0)
a4f6c312 10349 abort ();
e2c953b6
DE
10350 else if (val < 0)
10351 --i;
10352 else
10353 for ( ; i < 64; i++)
10354 if ((val <<= 1) < 0)
10355 break;
10356 }
10357#endif
10358
10359 fprintf (file, "%d", i + 1);
9854d9ed 10360 return;
9878760c 10361
9854d9ed
RK
10362 case 'X':
10363 if (GET_CODE (x) == MEM
4d588c14 10364 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 10365 putc ('x', file);
9854d9ed 10366 return;
9878760c 10367
9854d9ed
RK
10368 case 'Y':
10369 /* Like 'L', for third word of TImode */
10370 if (GET_CODE (x) == REG)
5ebfb2ba 10371 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 10372 else if (GET_CODE (x) == MEM)
9878760c 10373 {
9854d9ed
RK
10374 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10375 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10376 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 10377 else
d7624dc0 10378 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 10379 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10380 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10381 reg_names[SMALL_DATA_REG]);
9878760c
RK
10382 }
10383 return;
f676971a 10384
9878760c 10385 case 'z':
b4ac57ab
RS
10386 /* X is a SYMBOL_REF. Write out the name preceded by a
10387 period and without any trailing data in brackets. Used for function
4d30c363
MM
10388 names. If we are configured for System V (or the embedded ABI) on
10389 the PowerPC, do not emit the period, since those systems do not use
10390 TOCs and the like. */
9878760c
RK
10391 if (GET_CODE (x) != SYMBOL_REF)
10392 abort ();
10393
9bf6462a
AP
10394 /* Mark the decl as referenced so that cgraph will output the function. */
10395 if (SYMBOL_REF_DECL (x))
10396 mark_decl_referenced (SYMBOL_REF_DECL (x));
10397
85b776df 10398 /* For macho, check to see if we need a stub. */
f9da97f0
AP
10399 if (TARGET_MACHO)
10400 {
10401 const char *name = XSTR (x, 0);
a031e781 10402#if TARGET_MACHO
3b48085e 10403 if (MACHOPIC_INDIRECT
11abc112
MM
10404 && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
10405 name = machopic_indirection_name (x, /*stub_p=*/true);
f9da97f0
AP
10406#endif
10407 assemble_name (file, name);
10408 }
85b776df 10409 else if (!DOT_SYMBOLS)
9739c90c 10410 assemble_name (file, XSTR (x, 0));
85b776df
AM
10411 else
10412 rs6000_output_function_entry (file, XSTR (x, 0));
9878760c
RK
10413 return;
10414
9854d9ed
RK
10415 case 'Z':
10416 /* Like 'L', for last word of TImode. */
10417 if (GET_CODE (x) == REG)
5ebfb2ba 10418 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
10419 else if (GET_CODE (x) == MEM)
10420 {
10421 if (GET_CODE (XEXP (x, 0)) == PRE_INC
10422 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 10423 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 10424 else
d7624dc0 10425 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 10426 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10427 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10428 reg_names[SMALL_DATA_REG]);
9854d9ed 10429 }
5c23c401 10430 return;
0ac081f6 10431
a3170dc6 10432 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
10433 case 'y':
10434 {
10435 rtx tmp;
10436
10437 if (GET_CODE (x) != MEM)
10438 abort ();
10439
10440 tmp = XEXP (x, 0);
10441
993f19a8 10442 if (TARGET_E500)
a3170dc6
AH
10443 {
10444 /* Handle [reg]. */
10445 if (GET_CODE (tmp) == REG)
10446 {
10447 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
10448 break;
10449 }
10450 /* Handle [reg+UIMM]. */
10451 else if (GET_CODE (tmp) == PLUS &&
10452 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
10453 {
10454 int x;
10455
10456 if (GET_CODE (XEXP (tmp, 0)) != REG)
10457 abort ();
10458
10459 x = INTVAL (XEXP (tmp, 1));
10460 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
10461 break;
10462 }
10463
10464 /* Fall through. Must be [reg+reg]. */
10465 }
0ac081f6 10466 if (GET_CODE (tmp) == REG)
c62f2db5 10467 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
10468 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
10469 {
10470 if (REGNO (XEXP (tmp, 0)) == 0)
10471 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
10472 reg_names[ REGNO (XEXP (tmp, 0)) ]);
10473 else
10474 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
10475 reg_names[ REGNO (XEXP (tmp, 1)) ]);
10476 }
10477 else
10478 abort ();
10479 break;
10480 }
f676971a 10481
9878760c
RK
10482 case 0:
10483 if (GET_CODE (x) == REG)
10484 fprintf (file, "%s", reg_names[REGNO (x)]);
10485 else if (GET_CODE (x) == MEM)
10486 {
10487 /* We need to handle PRE_INC and PRE_DEC here, since we need to
10488 know the width from the mode. */
10489 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
10490 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
10491 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10492 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
10493 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
10494 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 10495 else
a54d04b7 10496 output_address (XEXP (x, 0));
9878760c
RK
10497 }
10498 else
a54d04b7 10499 output_addr_const (file, x);
a85d226b 10500 return;
9878760c 10501
c4501e62
JJ
10502 case '&':
10503 assemble_name (file, rs6000_get_some_local_dynamic_name ());
10504 return;
10505
9878760c
RK
10506 default:
10507 output_operand_lossage ("invalid %%xn code");
10508 }
10509}
10510\f
10511/* Print the address of an operand. */
10512
10513void
a2369ed3 10514print_operand_address (FILE *file, rtx x)
9878760c
RK
10515{
10516 if (GET_CODE (x) == REG)
4697a36c 10517 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
10518 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
10519 || GET_CODE (x) == LABEL_REF)
9878760c
RK
10520 {
10521 output_addr_const (file, x);
ba5e43aa 10522 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
10523 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
10524 reg_names[SMALL_DATA_REG]);
9ebbca7d 10525 else if (TARGET_TOC)
a4f6c312 10526 abort ();
9878760c
RK
10527 }
10528 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
10529 {
10530 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
10531 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
10532 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 10533 else
4697a36c
MM
10534 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
10535 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
10536 }
10537 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
10538 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
10539 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
10540#if TARGET_ELF
10541 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
10542 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
10543 {
10544 output_addr_const (file, XEXP (x, 1));
10545 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10546 }
c859cda6
DJ
10547#endif
10548#if TARGET_MACHO
10549 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
10550 && CONSTANT_P (XEXP (x, 1)))
10551 {
10552 fprintf (file, "lo16(");
10553 output_addr_const (file, XEXP (x, 1));
10554 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
10555 }
3cb999d8 10556#endif
4d588c14 10557 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 10558 {
2bfcf297 10559 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 10560 {
2bfcf297
DB
10561 rtx contains_minus = XEXP (x, 1);
10562 rtx minus, symref;
10563 const char *name;
f676971a 10564
9ebbca7d 10565 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 10566 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
10567 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
10568 contains_minus = XEXP (contains_minus, 0);
10569
2bfcf297
DB
10570 minus = XEXP (contains_minus, 0);
10571 symref = XEXP (minus, 0);
10572 XEXP (contains_minus, 0) = symref;
10573 if (TARGET_ELF)
10574 {
10575 char *newname;
10576
10577 name = XSTR (symref, 0);
10578 newname = alloca (strlen (name) + sizeof ("@toc"));
10579 strcpy (newname, name);
10580 strcat (newname, "@toc");
10581 XSTR (symref, 0) = newname;
10582 }
10583 output_addr_const (file, XEXP (x, 1));
10584 if (TARGET_ELF)
10585 XSTR (symref, 0) = name;
9ebbca7d
GK
10586 XEXP (contains_minus, 0) = minus;
10587 }
10588 else
10589 output_addr_const (file, XEXP (x, 1));
10590
10591 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
10592 }
9878760c
RK
10593 else
10594 abort ();
10595}
10596\f
88cad84b 10597/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
10598 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
10599 is defined. It also needs to handle DI-mode objects on 64-bit
10600 targets. */
10601
10602static bool
a2369ed3 10603rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
10604{
10605#ifdef RELOCATABLE_NEEDS_FIXUP
10606 /* Special handling for SI values. */
10607 if (size == 4 && aligned_p)
10608 {
a2369ed3 10609 extern int in_toc_section (void);
301d03af 10610 static int recurse = 0;
f676971a 10611
301d03af
RS
10612 /* For -mrelocatable, we mark all addresses that need to be fixed up
10613 in the .fixup section. */
10614 if (TARGET_RELOCATABLE
10615 && !in_toc_section ()
10616 && !in_text_section ()
642af3be 10617 && !in_unlikely_text_section ()
301d03af
RS
10618 && !recurse
10619 && GET_CODE (x) != CONST_INT
10620 && GET_CODE (x) != CONST_DOUBLE
10621 && CONSTANT_P (x))
10622 {
10623 char buf[256];
10624
10625 recurse = 1;
10626 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
10627 fixuplabelno++;
10628 ASM_OUTPUT_LABEL (asm_out_file, buf);
10629 fprintf (asm_out_file, "\t.long\t(");
10630 output_addr_const (asm_out_file, x);
10631 fprintf (asm_out_file, ")@fixup\n");
10632 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
10633 ASM_OUTPUT_ALIGN (asm_out_file, 2);
10634 fprintf (asm_out_file, "\t.long\t");
10635 assemble_name (asm_out_file, buf);
10636 fprintf (asm_out_file, "\n\t.previous\n");
10637 recurse = 0;
10638 return true;
10639 }
10640 /* Remove initial .'s to turn a -mcall-aixdesc function
10641 address into the address of the descriptor, not the function
10642 itself. */
10643 else if (GET_CODE (x) == SYMBOL_REF
10644 && XSTR (x, 0)[0] == '.'
10645 && DEFAULT_ABI == ABI_AIX)
10646 {
10647 const char *name = XSTR (x, 0);
10648 while (*name == '.')
10649 name++;
10650
10651 fprintf (asm_out_file, "\t.long\t%s\n", name);
10652 return true;
10653 }
10654 }
10655#endif /* RELOCATABLE_NEEDS_FIXUP */
10656 return default_assemble_integer (x, size, aligned_p);
10657}
93638d7a
AM
10658
10659#ifdef HAVE_GAS_HIDDEN
10660/* Emit an assembler directive to set symbol visibility for DECL to
10661 VISIBILITY_TYPE. */
10662
5add3202 10663static void
a2369ed3 10664rs6000_assemble_visibility (tree decl, int vis)
93638d7a 10665{
93638d7a
AM
10666 /* Functions need to have their entry point symbol visibility set as
10667 well as their descriptor symbol visibility. */
85b776df
AM
10668 if (DEFAULT_ABI == ABI_AIX
10669 && DOT_SYMBOLS
10670 && TREE_CODE (decl) == FUNCTION_DECL)
93638d7a 10671 {
25fdb4dc
RH
10672 static const char * const visibility_types[] = {
10673 NULL, "internal", "hidden", "protected"
10674 };
10675
10676 const char *name, *type;
93638d7a
AM
10677
10678 name = ((* targetm.strip_name_encoding)
10679 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 10680 type = visibility_types[vis];
93638d7a 10681
25fdb4dc
RH
10682 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
10683 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 10684 }
25fdb4dc
RH
10685 else
10686 default_assemble_visibility (decl, vis);
93638d7a
AM
10687}
10688#endif
301d03af 10689\f
39a10a29 10690enum rtx_code
a2369ed3 10691rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
10692{
10693 /* Reversal of FP compares takes care -- an ordered compare
10694 becomes an unordered compare and vice versa. */
f676971a 10695 if (mode == CCFPmode
bc9ec0e0
GK
10696 && (!flag_finite_math_only
10697 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
10698 || code == UNEQ || code == LTGT))
bab6226b 10699 return reverse_condition_maybe_unordered (code);
39a10a29 10700 else
bab6226b 10701 return reverse_condition (code);
39a10a29
GK
10702}
10703
39a10a29
GK
10704/* Generate a compare for CODE. Return a brand-new rtx that
10705 represents the result of the compare. */
a4f6c312 10706
39a10a29 10707static rtx
a2369ed3 10708rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
10709{
10710 enum machine_mode comp_mode;
10711 rtx compare_result;
10712
10713 if (rs6000_compare_fp_p)
10714 comp_mode = CCFPmode;
10715 else if (code == GTU || code == LTU
10716 || code == GEU || code == LEU)
10717 comp_mode = CCUNSmode;
10718 else
10719 comp_mode = CCmode;
10720
10721 /* First, the compare. */
10722 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
10723
10724 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
10725 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10726 && rs6000_compare_fp_p)
a3170dc6
AH
10727 {
10728 rtx cmp, or1, or2, or_result, compare_result2;
10729
423c1189
AH
10730 /* Note: The E500 comparison instructions set the GT bit (x +
10731 1), on success. This explains the mess. */
10732
a3170dc6
AH
10733 switch (code)
10734 {
423c1189 10735 case EQ: case UNEQ: case NE: case LTGT:
bc9ec0e0 10736 cmp = flag_finite_math_only
a3170dc6
AH
10737 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
10738 rs6000_compare_op1)
10739 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
10740 rs6000_compare_op1);
10741 break;
423c1189 10742 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
bc9ec0e0 10743 cmp = flag_finite_math_only
a3170dc6
AH
10744 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
10745 rs6000_compare_op1)
10746 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
10747 rs6000_compare_op1);
10748 break;
423c1189 10749 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
bc9ec0e0 10750 cmp = flag_finite_math_only
a3170dc6
AH
10751 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
10752 rs6000_compare_op1)
10753 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
10754 rs6000_compare_op1);
10755 break;
10756 default:
10757 abort ();
10758 }
10759
10760 /* Synthesize LE and GE from LT/GT || EQ. */
10761 if (code == LE || code == GE || code == LEU || code == GEU)
10762 {
a3170dc6
AH
10763 emit_insn (cmp);
10764
10765 switch (code)
10766 {
10767 case LE: code = LT; break;
10768 case GE: code = GT; break;
10769 case LEU: code = LT; break;
10770 case GEU: code = GT; break;
10771 default: abort ();
10772 }
10773
10774 or1 = gen_reg_rtx (SImode);
10775 or2 = gen_reg_rtx (SImode);
10776 or_result = gen_reg_rtx (CCEQmode);
10777 compare_result2 = gen_reg_rtx (CCFPmode);
10778
10779 /* Do the EQ. */
bc9ec0e0 10780 cmp = flag_finite_math_only
a3170dc6
AH
10781 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
10782 rs6000_compare_op1)
10783 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
10784 rs6000_compare_op1);
10785 emit_insn (cmp);
10786
423c1189
AH
10787 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
10788 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
10789
10790 /* OR them together. */
10791 cmp = gen_rtx_SET (VOIDmode, or_result,
10792 gen_rtx_COMPARE (CCEQmode,
10793 gen_rtx_IOR (SImode, or1, or2),
10794 const_true_rtx));
10795 compare_result = or_result;
10796 code = EQ;
10797 }
10798 else
10799 {
a3170dc6 10800 if (code == NE || code == LTGT)
a3170dc6 10801 code = NE;
423c1189
AH
10802 else
10803 code = EQ;
a3170dc6
AH
10804 }
10805
10806 emit_insn (cmp);
10807 }
10808 else
10809 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
10810 gen_rtx_COMPARE (comp_mode,
f676971a 10811 rs6000_compare_op0,
a3170dc6 10812 rs6000_compare_op1)));
f676971a 10813
ca5adc63 10814 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 10815 under flag_finite_math_only we don't bother. */
39a10a29 10816 if (rs6000_compare_fp_p
bc9ec0e0 10817 && ! flag_finite_math_only
993f19a8 10818 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
10819 && (code == LE || code == GE
10820 || code == UNEQ || code == LTGT
10821 || code == UNGT || code == UNLT))
10822 {
10823 enum rtx_code or1, or2;
10824 rtx or1_rtx, or2_rtx, compare2_rtx;
10825 rtx or_result = gen_reg_rtx (CCEQmode);
f676971a 10826
39a10a29
GK
10827 switch (code)
10828 {
10829 case LE: or1 = LT; or2 = EQ; break;
10830 case GE: or1 = GT; or2 = EQ; break;
10831 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
10832 case LTGT: or1 = LT; or2 = GT; break;
10833 case UNGT: or1 = UNORDERED; or2 = GT; break;
10834 case UNLT: or1 = UNORDERED; or2 = LT; break;
10835 default: abort ();
10836 }
10837 validate_condition_mode (or1, comp_mode);
10838 validate_condition_mode (or2, comp_mode);
1c563bed
KH
10839 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
10840 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
10841 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
10842 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
10843 const_true_rtx);
10844 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
10845
10846 compare_result = or_result;
10847 code = EQ;
10848 }
10849
10850 validate_condition_mode (code, GET_MODE (compare_result));
f676971a 10851
1c563bed 10852 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
10853}
10854
10855
10856/* Emit the RTL for an sCOND pattern. */
10857
10858void
a2369ed3 10859rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
10860{
10861 rtx condition_rtx;
10862 enum machine_mode op_mode;
b7053a3f 10863 enum rtx_code cond_code;
39a10a29
GK
10864
10865 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
10866 cond_code = GET_CODE (condition_rtx);
10867
423c1189
AH
10868 if (TARGET_E500 && rs6000_compare_fp_p
10869 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10870 {
10871 rtx t;
10872
10873 PUT_MODE (condition_rtx, SImode);
10874 t = XEXP (condition_rtx, 0);
10875
10876 if (cond_code != NE && cond_code != EQ)
10877 abort ();
10878
10879 if (cond_code == NE)
6b1fedc3 10880 emit_insn (gen_e500_flip_eq_bit (t, t));
423c1189 10881
6b1fedc3 10882 emit_insn (gen_move_from_CR_eq_bit (result, t));
423c1189
AH
10883 return;
10884 }
10885
b7053a3f
GK
10886 if (cond_code == NE
10887 || cond_code == GE || cond_code == LE
10888 || cond_code == GEU || cond_code == LEU
10889 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
10890 {
10891 rtx not_result = gen_reg_rtx (CCEQmode);
10892 rtx not_op, rev_cond_rtx;
10893 enum machine_mode cc_mode;
f676971a 10894
b7053a3f
GK
10895 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
10896
1c563bed 10897 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 10898 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
10899 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
10900 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
10901 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
10902 }
39a10a29
GK
10903
10904 op_mode = GET_MODE (rs6000_compare_op0);
10905 if (op_mode == VOIDmode)
10906 op_mode = GET_MODE (rs6000_compare_op1);
10907
10908 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
10909 {
10910 PUT_MODE (condition_rtx, DImode);
10911 convert_move (result, condition_rtx, 0);
10912 }
10913 else
10914 {
10915 PUT_MODE (condition_rtx, SImode);
10916 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
10917 }
10918}
10919
39a10a29
GK
10920/* Emit a branch of kind CODE to location LOC. */
10921
10922void
a2369ed3 10923rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
10924{
10925 rtx condition_rtx, loc_ref;
10926
10927 condition_rtx = rs6000_generate_compare (code);
10928 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
10929 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
10930 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
10931 loc_ref, pc_rtx)));
10932}
10933
12a4e8c5
GK
10934/* Return the string to output a conditional branch to LABEL, which is
10935 the operand number of the label, or -1 if the branch is really a
f676971a 10936 conditional return.
12a4e8c5
GK
10937
10938 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
10939 condition code register and its mode specifies what kind of
10940 comparison we made.
10941
a0ab749a 10942 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
10943
10944 INSN is the insn. */
10945
10946char *
a2369ed3 10947output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
10948{
10949 static char string[64];
10950 enum rtx_code code = GET_CODE (op);
10951 rtx cc_reg = XEXP (op, 0);
10952 enum machine_mode mode = GET_MODE (cc_reg);
10953 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 10954 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
10955 int really_reversed = reversed ^ need_longbranch;
10956 char *s = string;
10957 const char *ccode;
10958 const char *pred;
10959 rtx note;
10960
39a10a29
GK
10961 validate_condition_mode (code, mode);
10962
10963 /* Work out which way this really branches. We could use
10964 reverse_condition_maybe_unordered here always but this
10965 makes the resulting assembler clearer. */
12a4e8c5 10966 if (really_reversed)
de40e1df
DJ
10967 {
10968 /* Reversal of FP compares takes care -- an ordered compare
10969 becomes an unordered compare and vice versa. */
10970 if (mode == CCFPmode)
10971 code = reverse_condition_maybe_unordered (code);
10972 else
10973 code = reverse_condition (code);
10974 }
12a4e8c5 10975
993f19a8 10976 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
10977 {
10978 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
10979 to the GT bit. */
10980 if (code == EQ)
10981 /* Opposite of GT. */
a3170dc6 10982 code = GT;
423c1189
AH
10983 else if (code == NE)
10984 code = UNLE;
a3170dc6
AH
10985 else
10986 abort ();
10987 }
10988
39a10a29 10989 switch (code)
12a4e8c5
GK
10990 {
10991 /* Not all of these are actually distinct opcodes, but
10992 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
10993 case NE: case LTGT:
10994 ccode = "ne"; break;
10995 case EQ: case UNEQ:
10996 ccode = "eq"; break;
f676971a 10997 case GE: case GEU:
50a0b056 10998 ccode = "ge"; break;
f676971a 10999 case GT: case GTU: case UNGT:
50a0b056 11000 ccode = "gt"; break;
f676971a 11001 case LE: case LEU:
50a0b056 11002 ccode = "le"; break;
f676971a 11003 case LT: case LTU: case UNLT:
50a0b056 11004 ccode = "lt"; break;
12a4e8c5
GK
11005 case UNORDERED: ccode = "un"; break;
11006 case ORDERED: ccode = "nu"; break;
11007 case UNGE: ccode = "nl"; break;
11008 case UNLE: ccode = "ng"; break;
11009 default:
a4f6c312 11010 abort ();
12a4e8c5 11011 }
f676971a
EC
11012
11013 /* Maybe we have a guess as to how likely the branch is.
94a54f47 11014 The old mnemonics don't have a way to specify this information. */
f4857b9b 11015 pred = "";
12a4e8c5
GK
11016 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
11017 if (note != NULL_RTX)
11018 {
11019 /* PROB is the difference from 50%. */
11020 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
11021
11022 /* Only hint for highly probable/improbable branches on newer
11023 cpus as static prediction overrides processor dynamic
11024 prediction. For older cpus we may as well always hint, but
11025 assume not taken for branches that are very close to 50% as a
11026 mispredicted taken branch is more expensive than a
f676971a 11027 mispredicted not-taken branch. */
ec507f2d 11028 if (rs6000_always_hint
f4857b9b
AM
11029 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
11030 {
11031 if (abs (prob) > REG_BR_PROB_BASE / 20
11032 && ((prob > 0) ^ need_longbranch))
7f3d8013 11033 pred = "+";
f4857b9b
AM
11034 else
11035 pred = "-";
11036 }
12a4e8c5 11037 }
12a4e8c5
GK
11038
11039 if (label == NULL)
94a54f47 11040 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 11041 else
94a54f47 11042 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 11043
37c67319 11044 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 11045 Assume they'd only be the first character.... */
37c67319
GK
11046 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
11047 *s++ = '%';
94a54f47 11048 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
11049
11050 if (label != NULL)
11051 {
11052 /* If the branch distance was too far, we may have to use an
11053 unconditional branch to go the distance. */
11054 if (need_longbranch)
44518ddd 11055 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
11056 else
11057 s += sprintf (s, ",%s", label);
11058 }
11059
11060 return string;
11061}
50a0b056 11062
6b1fedc3 11063/* Return the string to flip the EQ bit on a CR. */
423c1189 11064char *
6b1fedc3 11065output_e500_flip_eq_bit (rtx dst, rtx src)
423c1189
AH
11066{
11067 static char string[64];
11068 int a, b;
11069
11070 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
11071 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
11072 abort ();
11073
6b1fedc3
AH
11074 /* EQ bit. */
11075 a = 4 * (REGNO (dst) - CR0_REGNO) + 2;
11076 b = 4 * (REGNO (src) - CR0_REGNO) + 2;
423c1189
AH
11077
11078 sprintf (string, "crnot %d,%d", a, b);
11079 return string;
11080}
11081
50a0b056
GK
11082/* Emit a conditional move: move TRUE_COND to DEST if OP of the
11083 operands of the last comparison is nonzero/true, FALSE_COND if it
11084 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 11085
50a0b056 11086int
a2369ed3 11087rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
11088{
11089 enum rtx_code code = GET_CODE (op);
11090 rtx op0 = rs6000_compare_op0;
11091 rtx op1 = rs6000_compare_op1;
11092 REAL_VALUE_TYPE c1;
3148ad6d
DJ
11093 enum machine_mode compare_mode = GET_MODE (op0);
11094 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
11095 rtx temp;
11096
a3c9585f 11097 /* These modes should always match. */
a3170dc6
AH
11098 if (GET_MODE (op1) != compare_mode
11099 /* In the isel case however, we can use a compare immediate, so
11100 op1 may be a small constant. */
11101 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 11102 return 0;
178c3eff 11103 if (GET_MODE (true_cond) != result_mode)
3148ad6d 11104 return 0;
178c3eff 11105 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
11106 return 0;
11107
50a0b056 11108 /* First, work out if the hardware can do this at all, or
a3c9585f 11109 if it's too slow.... */
50a0b056 11110 if (! rs6000_compare_fp_p)
a3170dc6
AH
11111 {
11112 if (TARGET_ISEL)
11113 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
11114 return 0;
11115 }
fef98bf2
AH
11116 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
11117 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
11118 return 0;
50a0b056
GK
11119
11120 /* Eliminate half of the comparisons by switching operands, this
11121 makes the remaining code simpler. */
11122 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 11123 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
11124 {
11125 code = reverse_condition_maybe_unordered (code);
11126 temp = true_cond;
11127 true_cond = false_cond;
11128 false_cond = temp;
11129 }
11130
11131 /* UNEQ and LTGT take four instructions for a comparison with zero,
11132 it'll probably be faster to use a branch here too. */
bc9ec0e0 11133 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056 11134 return 0;
f676971a 11135
50a0b056
GK
11136 if (GET_CODE (op1) == CONST_DOUBLE)
11137 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
f676971a 11138
b6d08ca1 11139 /* We're going to try to implement comparisons by performing
50a0b056
GK
11140 a subtract, then comparing against zero. Unfortunately,
11141 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 11142 know that the operand is finite and the comparison
50a0b056 11143 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 11144 if (HONOR_INFINITIES (compare_mode)
50a0b056 11145 && code != GT && code != UNGE
045572c7 11146 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
11147 /* Constructs of the form (a OP b ? a : b) are safe. */
11148 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
f676971a 11149 || (! rtx_equal_p (op0, true_cond)
50a0b056
GK
11150 && ! rtx_equal_p (op1, true_cond))))
11151 return 0;
11152 /* At this point we know we can use fsel. */
11153
11154 /* Reduce the comparison to a comparison against zero. */
3148ad6d 11155 temp = gen_reg_rtx (compare_mode);
50a0b056 11156 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 11157 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 11158 op0 = temp;
3148ad6d 11159 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
11160
11161 /* If we don't care about NaNs we can reduce some of the comparisons
11162 down to faster ones. */
bc9ec0e0 11163 if (! HONOR_NANS (compare_mode))
50a0b056
GK
11164 switch (code)
11165 {
11166 case GT:
11167 code = LE;
11168 temp = true_cond;
11169 true_cond = false_cond;
11170 false_cond = temp;
11171 break;
11172 case UNGE:
11173 code = GE;
11174 break;
11175 case UNEQ:
11176 code = EQ;
11177 break;
11178 default:
11179 break;
11180 }
11181
11182 /* Now, reduce everything down to a GE. */
11183 switch (code)
11184 {
11185 case GE:
11186 break;
11187
11188 case LE:
3148ad6d
DJ
11189 temp = gen_reg_rtx (compare_mode);
11190 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11191 op0 = temp;
11192 break;
11193
11194 case ORDERED:
3148ad6d
DJ
11195 temp = gen_reg_rtx (compare_mode);
11196 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
11197 op0 = temp;
11198 break;
11199
11200 case EQ:
3148ad6d 11201 temp = gen_reg_rtx (compare_mode);
f676971a 11202 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
11203 gen_rtx_NEG (compare_mode,
11204 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
11205 op0 = temp;
11206 break;
11207
11208 case UNGE:
bc9ec0e0 11209 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 11210 temp = gen_reg_rtx (result_mode);
50a0b056 11211 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 11212 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11213 gen_rtx_GE (VOIDmode,
11214 op0, op1),
11215 true_cond, false_cond)));
bc9ec0e0
GK
11216 false_cond = true_cond;
11217 true_cond = temp;
50a0b056 11218
3148ad6d
DJ
11219 temp = gen_reg_rtx (compare_mode);
11220 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11221 op0 = temp;
11222 break;
11223
11224 case GT:
bc9ec0e0 11225 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 11226 temp = gen_reg_rtx (result_mode);
50a0b056 11227 emit_insn (gen_rtx_SET (VOIDmode, temp,
f676971a 11228 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11229 gen_rtx_GE (VOIDmode,
11230 op0, op1),
11231 true_cond, false_cond)));
bc9ec0e0
GK
11232 true_cond = false_cond;
11233 false_cond = temp;
50a0b056 11234
3148ad6d
DJ
11235 temp = gen_reg_rtx (compare_mode);
11236 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
11237 op0 = temp;
11238 break;
11239
11240 default:
11241 abort ();
11242 }
11243
11244 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 11245 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
11246 gen_rtx_GE (VOIDmode,
11247 op0, op1),
11248 true_cond, false_cond)));
11249 return 1;
11250}
11251
a3170dc6
AH
11252/* Same as above, but for ints (isel). */
11253
11254static int
a2369ed3 11255rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
11256{
11257 rtx condition_rtx, cr;
11258
11259 /* All isel implementations thus far are 32-bits. */
11260 if (GET_MODE (rs6000_compare_op0) != SImode)
11261 return 0;
11262
11263 /* We still have to do the compare, because isel doesn't do a
11264 compare, it just looks at the CRx bits set by a previous compare
11265 instruction. */
11266 condition_rtx = rs6000_generate_compare (GET_CODE (op));
11267 cr = XEXP (condition_rtx, 0);
11268
11269 if (GET_MODE (cr) == CCmode)
11270 emit_insn (gen_isel_signed (dest, condition_rtx,
11271 true_cond, false_cond, cr));
11272 else
11273 emit_insn (gen_isel_unsigned (dest, condition_rtx,
11274 true_cond, false_cond, cr));
11275
11276 return 1;
11277}
11278
11279const char *
a2369ed3 11280output_isel (rtx *operands)
a3170dc6
AH
11281{
11282 enum rtx_code code;
11283
11284 code = GET_CODE (operands[1]);
11285 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
11286 {
11287 PUT_CODE (operands[1], reverse_condition (code));
11288 return "isel %0,%3,%2,%j1";
11289 }
11290 else
11291 return "isel %0,%2,%3,%j1";
11292}
11293
50a0b056 11294void
a2369ed3 11295rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
11296{
11297 enum machine_mode mode = GET_MODE (op0);
5dc8d536 11298 enum rtx_code c;
50a0b056 11299 rtx target;
5dc8d536
AH
11300
11301 if (code == SMAX || code == SMIN)
11302 c = GE;
11303 else
11304 c = GEU;
11305
50a0b056 11306 if (code == SMAX || code == UMAX)
f676971a 11307 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11308 op0, op1, mode, 0);
11309 else
f676971a 11310 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
11311 op1, op0, mode, 0);
11312 if (target == NULL_RTX)
11313 abort ();
11314 if (target != dest)
11315 emit_move_insn (dest, target);
11316}
46c07df8 11317
a9baceb1
GK
11318/* Emit instructions to move SRC to DST. Called by splitters for
11319 multi-register moves. It will emit at most one instruction for
11320 each register that is accessed; that is, it won't emit li/lis pairs
11321 (or equivalent for 64-bit code). One of SRC or DST must be a hard
11322 register. */
46c07df8 11323
46c07df8 11324void
a9baceb1 11325rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 11326{
a9baceb1
GK
11327 /* The register number of the first register being moved. */
11328 int reg;
11329 /* The mode that is to be moved. */
11330 enum machine_mode mode;
11331 /* The mode that the move is being done in, and its size. */
11332 enum machine_mode reg_mode;
11333 int reg_mode_size;
11334 /* The number of registers that will be moved. */
11335 int nregs;
11336
11337 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
11338 mode = GET_MODE (dst);
11339 nregs = HARD_REGNO_NREGS (reg, mode);
11340 if (FP_REGNO_P (reg))
11341 reg_mode = DFmode;
11342 else if (ALTIVEC_REGNO_P (reg))
11343 reg_mode = V16QImode;
11344 else
11345 reg_mode = word_mode;
11346 reg_mode_size = GET_MODE_SIZE (reg_mode);
f676971a 11347
a9baceb1
GK
11348 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
11349 abort ();
f676971a 11350
a9baceb1
GK
11351 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
11352 {
11353 /* Move register range backwards, if we might have destructive
11354 overlap. */
11355 int i;
11356 for (i = nregs - 1; i >= 0; i--)
f676971a 11357 emit_insn (gen_rtx_SET (VOIDmode,
a9baceb1
GK
11358 simplify_gen_subreg (reg_mode, dst, mode,
11359 i * reg_mode_size),
11360 simplify_gen_subreg (reg_mode, src, mode,
11361 i * reg_mode_size)));
11362 }
46c07df8
HP
11363 else
11364 {
a9baceb1
GK
11365 int i;
11366 int j = -1;
11367 bool used_update = false;
46c07df8 11368
c1e55850 11369 if (MEM_P (src) && INT_REGNO_P (reg))
46c07df8
HP
11370 {
11371 rtx breg;
3a1f863f 11372
a9baceb1
GK
11373 if (GET_CODE (XEXP (src, 0)) == PRE_INC
11374 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
11375 {
11376 rtx delta_rtx;
a9baceb1 11377 breg = XEXP (XEXP (src, 0), 0);
f676971a
EC
11378 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
11379 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
11380 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
a9baceb1
GK
11381 emit_insn (TARGET_32BIT
11382 ? gen_addsi3 (breg, breg, delta_rtx)
11383 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11384 src = gen_rtx_MEM (mode, breg);
11385 }
c1e55850
GK
11386 else if (! offsettable_memref_p (src))
11387 {
11388 rtx newsrc, basereg;
11389 basereg = gen_rtx_REG (Pmode, reg);
11390 emit_insn (gen_rtx_SET (VOIDmode, basereg, XEXP (src, 0)));
11391 newsrc = gen_rtx_MEM (GET_MODE (src), basereg);
11392 MEM_COPY_ATTRIBUTES (newsrc, src);
11393 src = newsrc;
11394 }
3a1f863f 11395
0423421f
AM
11396 breg = XEXP (src, 0);
11397 if (GET_CODE (breg) == PLUS || GET_CODE (breg) == LO_SUM)
11398 breg = XEXP (breg, 0);
11399
11400 /* If the base register we are using to address memory is
11401 also a destination reg, then change that register last. */
11402 if (REG_P (breg)
11403 && REGNO (breg) >= REGNO (dst)
3a1f863f
DE
11404 && REGNO (breg) < REGNO (dst) + nregs)
11405 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
11406 }
11407
a9baceb1 11408 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
11409 {
11410 rtx breg;
11411
a9baceb1
GK
11412 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
11413 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
11414 {
11415 rtx delta_rtx;
a9baceb1 11416 breg = XEXP (XEXP (dst, 0), 0);
f676971a
EC
11417 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
11418 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
11419 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
11420
11421 /* We have to update the breg before doing the store.
11422 Use store with update, if available. */
11423
11424 if (TARGET_UPDATE)
11425 {
a9baceb1 11426 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
2e6c9641
FJ
11427 emit_insn (TARGET_32BIT
11428 ? (TARGET_POWERPC64
11429 ? gen_movdi_si_update (breg, breg, delta_rtx, nsrc)
11430 : gen_movsi_update (breg, breg, delta_rtx, nsrc))
11431 : gen_movdi_di_update (breg, breg, delta_rtx, nsrc));
a9baceb1 11432 used_update = true;
3a1f863f
DE
11433 }
11434 else
a9baceb1
GK
11435 emit_insn (TARGET_32BIT
11436 ? gen_addsi3 (breg, breg, delta_rtx)
11437 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
11438 dst = gen_rtx_MEM (mode, breg);
11439 }
c1e55850 11440 else if (! offsettable_memref_p (dst))
112ccb83 11441 abort ();
3a1f863f
DE
11442 }
11443
46c07df8 11444 for (i = 0; i < nregs; i++)
f676971a 11445 {
3a1f863f
DE
11446 /* Calculate index to next subword. */
11447 ++j;
f676971a 11448 if (j == nregs)
3a1f863f 11449 j = 0;
46c07df8 11450
f676971a 11451 /* If compiler already emited move of first word by
a9baceb1 11452 store with update, no need to do anything. */
3a1f863f 11453 if (j == 0 && used_update)
a9baceb1 11454 continue;
f676971a 11455
a9baceb1
GK
11456 emit_insn (gen_rtx_SET (VOIDmode,
11457 simplify_gen_subreg (reg_mode, dst, mode,
11458 j * reg_mode_size),
11459 simplify_gen_subreg (reg_mode, src, mode,
11460 j * reg_mode_size)));
3a1f863f 11461 }
46c07df8
HP
11462 }
11463}
11464
12a4e8c5 11465\f
a4f6c312
SS
11466/* This page contains routines that are used to determine what the
11467 function prologue and epilogue code will do and write them out. */
9878760c 11468
a4f6c312
SS
11469/* Return the first fixed-point register that is required to be
11470 saved. 32 if none. */
9878760c
RK
11471
11472int
863d938c 11473first_reg_to_save (void)
9878760c
RK
11474{
11475 int first_reg;
11476
11477 /* Find lowest numbered live register. */
11478 for (first_reg = 13; first_reg <= 31; first_reg++)
f676971a 11479 if (regs_ever_live[first_reg]
a38d360d 11480 && (! call_used_regs[first_reg]
1db02437 11481 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11482 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
b4db40bf
JJ
11483 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)
11484 || (TARGET_TOC && TARGET_MINIMAL_TOC)))))
9878760c
RK
11485 break;
11486
ee890fe2 11487#if TARGET_MACHO
93638d7a
AM
11488 if (flag_pic
11489 && current_function_uses_pic_offset_table
11490 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 11491 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
11492#endif
11493
9878760c
RK
11494 return first_reg;
11495}
11496
11497/* Similar, for FP regs. */
11498
11499int
863d938c 11500first_fp_reg_to_save (void)
9878760c
RK
11501{
11502 int first_reg;
11503
11504 /* Find lowest numbered live register. */
11505 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
11506 if (regs_ever_live[first_reg])
11507 break;
11508
11509 return first_reg;
11510}
00b960c7
AH
11511
11512/* Similar, for AltiVec regs. */
11513
11514static int
863d938c 11515first_altivec_reg_to_save (void)
00b960c7
AH
11516{
11517 int i;
11518
11519 /* Stack frame remains as is unless we are in AltiVec ABI. */
11520 if (! TARGET_ALTIVEC_ABI)
11521 return LAST_ALTIVEC_REGNO + 1;
11522
11523 /* Find lowest numbered live register. */
11524 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
11525 if (regs_ever_live[i])
11526 break;
11527
11528 return i;
11529}
11530
11531/* Return a 32-bit mask of the AltiVec registers we need to set in
11532 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
11533 the 32-bit word is 0. */
11534
11535static unsigned int
863d938c 11536compute_vrsave_mask (void)
00b960c7
AH
11537{
11538 unsigned int i, mask = 0;
11539
11540 /* First, find out if we use _any_ altivec registers. */
11541 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11542 if (regs_ever_live[i])
11543 mask |= ALTIVEC_REG_BIT (i);
11544
11545 if (mask == 0)
11546 return mask;
11547
00b960c7
AH
11548 /* Next, remove the argument registers from the set. These must
11549 be in the VRSAVE mask set by the caller, so we don't need to add
11550 them in again. More importantly, the mask we compute here is
11551 used to generate CLOBBERs in the set_vrsave insn, and we do not
11552 wish the argument registers to die. */
a6cf80f2 11553 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
11554 mask &= ~ALTIVEC_REG_BIT (i);
11555
11556 /* Similarly, remove the return value from the set. */
11557 {
11558 bool yes = false;
11559 diddle_return_value (is_altivec_return_reg, &yes);
11560 if (yes)
11561 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
11562 }
11563
11564 return mask;
11565}
11566
d62294f5
FJ
11567/* For a very restricted set of circumstances, we can cut down the
11568 size of prologs/epilogs by calling our own save/restore-the-world
11569 routines. */
11570
11571static void
11572compute_save_world_info(rs6000_stack_t *info_ptr)
11573{
11574 info_ptr->world_save_p =
11575 (DEFAULT_ABI == ABI_DARWIN)
11576 && ! (current_function_calls_setjmp && flag_exceptions)
11577 && info_ptr->first_fp_reg_save == FIRST_SAVED_FP_REGNO
11578 && info_ptr->first_gp_reg_save == FIRST_SAVED_GP_REGNO
11579 && info_ptr->first_altivec_reg_save == FIRST_SAVED_ALTIVEC_REGNO
11580 && info_ptr->cr_save_p;
f676971a 11581
d62294f5
FJ
11582 /* This will not work in conjunction with sibcalls. Make sure there
11583 are none. (This check is expensive, but seldom executed.) */
11584 if ( info_ptr->world_save_p )
f676971a 11585 {
d62294f5
FJ
11586 rtx insn;
11587 for ( insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn))
11588 if ( GET_CODE (insn) == CALL_INSN
11589 && SIBLING_CALL_P (insn))
f676971a 11590 {
d62294f5
FJ
11591 info_ptr->world_save_p = 0;
11592 break;
11593 }
11594 }
f676971a 11595
d62294f5
FJ
11596 if (info_ptr->world_save_p)
11597 {
11598 /* Even if we're not touching VRsave, make sure there's room on the
11599 stack for it, if it looks like we're calling SAVE_WORLD, which
11600 will attempt to save it. */
11601 info_ptr->vrsave_size = 4;
11602
11603 /* "Save" the VRsave register too if we're saving the world. */
11604 if (info_ptr->vrsave_mask == 0)
11605 info_ptr->vrsave_mask = compute_vrsave_mask ();
11606
11607 /* Because the Darwin register save/restore routines only handle
11608 F14 .. F31 and V20 .. V31 as per the ABI, perform a consistancy
11609 check and abort if there's something worng. */
f676971a 11610 if (info_ptr->first_fp_reg_save < FIRST_SAVED_FP_REGNO
d62294f5
FJ
11611 || info_ptr->first_altivec_reg_save < FIRST_SAVED_ALTIVEC_REGNO)
11612 abort ();
11613 }
f676971a 11614 return;
d62294f5
FJ
11615}
11616
11617
00b960c7 11618static void
a2369ed3 11619is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
11620{
11621 bool *yes = (bool *) xyes;
11622 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
11623 *yes = true;
11624}
11625
4697a36c
MM
11626\f
11627/* Calculate the stack information for the current function. This is
11628 complicated by having two separate calling sequences, the AIX calling
11629 sequence and the V.4 calling sequence.
11630
592696dd 11631 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 11632 32-bit 64-bit
4697a36c 11633 SP----> +---------------------------------------+
a260abc9 11634 | back chain to caller | 0 0
4697a36c 11635 +---------------------------------------+
a260abc9 11636 | saved CR | 4 8 (8-11)
4697a36c 11637 +---------------------------------------+
a260abc9 11638 | saved LR | 8 16
4697a36c 11639 +---------------------------------------+
a260abc9 11640 | reserved for compilers | 12 24
4697a36c 11641 +---------------------------------------+
a260abc9 11642 | reserved for binders | 16 32
4697a36c 11643 +---------------------------------------+
a260abc9 11644 | saved TOC pointer | 20 40
4697a36c 11645 +---------------------------------------+
a260abc9 11646 | Parameter save area (P) | 24 48
4697a36c 11647 +---------------------------------------+
a260abc9 11648 | Alloca space (A) | 24+P etc.
802a0058 11649 +---------------------------------------+
a7df97e6 11650 | Local variable space (L) | 24+P+A
4697a36c 11651 +---------------------------------------+
a7df97e6 11652 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 11653 +---------------------------------------+
00b960c7
AH
11654 | Save area for AltiVec registers (W) | 24+P+A+L+X
11655 +---------------------------------------+
11656 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
11657 +---------------------------------------+
11658 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 11659 +---------------------------------------+
00b960c7
AH
11660 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
11661 +---------------------------------------+
11662 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
11663 +---------------------------------------+
11664 old SP->| back chain to caller's caller |
11665 +---------------------------------------+
11666
5376a30c
KR
11667 The required alignment for AIX configurations is two words (i.e., 8
11668 or 16 bytes).
11669
11670
4697a36c
MM
11671 V.4 stack frames look like:
11672
11673 SP----> +---------------------------------------+
11674 | back chain to caller | 0
11675 +---------------------------------------+
5eb387b8 11676 | caller's saved LR | 4
4697a36c
MM
11677 +---------------------------------------+
11678 | Parameter save area (P) | 8
11679 +---------------------------------------+
a7df97e6 11680 | Alloca space (A) | 8+P
f676971a 11681 +---------------------------------------+
a7df97e6 11682 | Varargs save area (V) | 8+P+A
f676971a 11683 +---------------------------------------+
a7df97e6 11684 | Local variable space (L) | 8+P+A+V
f676971a 11685 +---------------------------------------+
a7df97e6 11686 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 11687 +---------------------------------------+
00b960c7
AH
11688 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
11689 +---------------------------------------+
11690 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
11691 +---------------------------------------+
11692 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
11693 +---------------------------------------+
a3170dc6
AH
11694 | SPE: area for 64-bit GP registers |
11695 +---------------------------------------+
11696 | SPE alignment padding |
11697 +---------------------------------------+
00b960c7 11698 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
f676971a 11699 +---------------------------------------+
00b960c7 11700 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
f676971a 11701 +---------------------------------------+
00b960c7 11702 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
11703 +---------------------------------------+
11704 old SP->| back chain to caller's caller |
11705 +---------------------------------------+
b6c9286a 11706
5376a30c
KR
11707 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
11708 given. (But note below and in sysv4.h that we require only 8 and
11709 may round up the size of our stack frame anyways. The historical
11710 reason is early versions of powerpc-linux which didn't properly
11711 align the stack at program startup. A happy side-effect is that
11712 -mno-eabi libraries can be used with -meabi programs.)
11713
50d440bc 11714 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
11715 the stack alignment requirements may differ. If -mno-eabi is not
11716 given, the required stack alignment is 8 bytes; if -mno-eabi is
11717 given, the required alignment is 16 bytes. (But see V.4 comment
11718 above.) */
4697a36c 11719
61b2fbe7
MM
11720#ifndef ABI_STACK_BOUNDARY
11721#define ABI_STACK_BOUNDARY STACK_BOUNDARY
11722#endif
11723
d1d0c603 11724static rs6000_stack_t *
863d938c 11725rs6000_stack_info (void)
4697a36c
MM
11726{
11727 static rs6000_stack_t info, zero_info;
11728 rs6000_stack_t *info_ptr = &info;
327e5343 11729 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 11730 int ehrd_size;
64045029 11731 int save_align;
44688022 11732 HOST_WIDE_INT non_fixed_size;
4697a36c 11733
a4f6c312 11734 /* Zero all fields portably. */
4697a36c
MM
11735 info = zero_info;
11736
c19de7aa
AH
11737 if (TARGET_SPE)
11738 {
11739 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
11740 if (cfun->machine->insn_chain_scanned_p == 0)
11741 {
11742 cfun->machine->insn_chain_scanned_p = 1;
11743 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
11744 }
c19de7aa
AH
11745 }
11746
a4f6c312 11747 /* Select which calling sequence. */
178274da 11748 info_ptr->abi = DEFAULT_ABI;
9878760c 11749
a4f6c312 11750 /* Calculate which registers need to be saved & save area size. */
4697a36c 11751 info_ptr->first_gp_reg_save = first_reg_to_save ();
f676971a 11752 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 11753 even if it currently looks like we won't. */
2bfcf297 11754 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
11755 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
11756 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
11757 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
11758 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
11759 else
11760 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 11761
a3170dc6
AH
11762 /* For the SPE, we have an additional upper 32-bits on each GPR.
11763 Ideally we should save the entire 64-bits only when the upper
11764 half is used in SIMD instructions. Since we only record
11765 registers live (not the size they are used in), this proves
11766 difficult because we'd have to traverse the instruction chain at
11767 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
11768 so we opt to save the GPRs in 64-bits always if but one register
11769 gets used in 64-bits. Otherwise, all the registers in the frame
11770 get saved in 32-bits.
a3170dc6 11771
c19de7aa 11772 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 11773 traditional GP save area will be empty. */
c19de7aa 11774 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11775 info_ptr->gp_size = 0;
11776
4697a36c
MM
11777 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
11778 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
11779
00b960c7
AH
11780 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
11781 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
11782 - info_ptr->first_altivec_reg_save);
11783
592696dd 11784 /* Does this function call anything? */
71f123ca
FS
11785 info_ptr->calls_p = (! current_function_is_leaf
11786 || cfun->machine->ra_needs_full_frame);
b6c9286a 11787
a4f6c312 11788 /* Determine if we need to save the link register. */
71f123ca 11789 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
11790 || (DEFAULT_ABI == ABI_AIX
11791 && current_function_profile
11792 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
11793#ifdef TARGET_RELOCATABLE
11794 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
11795#endif
11796 || (info_ptr->first_fp_reg_save != 64
11797 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 11798 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 11799 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
11800 || (DEFAULT_ABI == ABI_DARWIN
11801 && flag_pic
11802 && current_function_uses_pic_offset_table)
4697a36c
MM
11803 || info_ptr->calls_p)
11804 {
11805 info_ptr->lr_save_p = 1;
9ebbca7d 11806 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
11807 }
11808
9ebbca7d 11809 /* Determine if we need to save the condition code registers. */
f676971a 11810 if (regs_ever_live[CR2_REGNO]
9ebbca7d
GK
11811 || regs_ever_live[CR3_REGNO]
11812 || regs_ever_live[CR4_REGNO])
4697a36c
MM
11813 {
11814 info_ptr->cr_save_p = 1;
178274da 11815 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
11816 info_ptr->cr_size = reg_size;
11817 }
11818
83720594
RH
11819 /* If the current function calls __builtin_eh_return, then we need
11820 to allocate stack space for registers that will hold data for
11821 the exception handler. */
11822 if (current_function_calls_eh_return)
11823 {
11824 unsigned int i;
11825 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
11826 continue;
a3170dc6
AH
11827
11828 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
11829 ehrd_size = i * (TARGET_SPE_ABI
11830 && info_ptr->spe_64bit_regs_used != 0
11831 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
11832 }
11833 else
11834 ehrd_size = 0;
11835
592696dd 11836 /* Determine various sizes. */
4697a36c
MM
11837 info_ptr->reg_size = reg_size;
11838 info_ptr->fixed_size = RS6000_SAVE_AREA;
11839 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 11840 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 11841 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 11842 TARGET_ALTIVEC ? 16 : 8);
00b960c7 11843
c19de7aa 11844 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11845 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
11846 else
11847 info_ptr->spe_gp_size = 0;
11848
4d774ff8
HP
11849 if (TARGET_ALTIVEC_ABI)
11850 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 11851 else
4d774ff8
HP
11852 info_ptr->vrsave_mask = 0;
11853
11854 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
11855 info_ptr->vrsave_size = 4;
11856 else
11857 info_ptr->vrsave_size = 0;
b6c9286a 11858
d62294f5
FJ
11859 compute_save_world_info (info_ptr);
11860
592696dd 11861 /* Calculate the offsets. */
178274da 11862 switch (DEFAULT_ABI)
4697a36c 11863 {
b6c9286a 11864 case ABI_NONE:
24d304eb 11865 default:
b6c9286a
MM
11866 abort ();
11867
11868 case ABI_AIX:
ee890fe2 11869 case ABI_DARWIN:
b6c9286a
MM
11870 info_ptr->fp_save_offset = - info_ptr->fp_size;
11871 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
11872
11873 if (TARGET_ALTIVEC_ABI)
11874 {
11875 info_ptr->vrsave_save_offset
11876 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
11877
11878 /* Align stack so vector save area is on a quadword boundary. */
11879 if (info_ptr->altivec_size != 0)
11880 info_ptr->altivec_padding_size
11881 = 16 - (-info_ptr->vrsave_save_offset % 16);
11882 else
11883 info_ptr->altivec_padding_size = 0;
11884
11885 info_ptr->altivec_save_offset
11886 = info_ptr->vrsave_save_offset
11887 - info_ptr->altivec_padding_size
11888 - info_ptr->altivec_size;
11889
11890 /* Adjust for AltiVec case. */
11891 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
11892 }
11893 else
11894 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
11895 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
11896 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
11897 break;
11898
11899 case ABI_V4:
b6c9286a
MM
11900 info_ptr->fp_save_offset = - info_ptr->fp_size;
11901 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 11902 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 11903
c19de7aa 11904 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11905 {
11906 /* Align stack so SPE GPR save area is aligned on a
11907 double-word boundary. */
11908 if (info_ptr->spe_gp_size != 0)
11909 info_ptr->spe_padding_size
11910 = 8 - (-info_ptr->cr_save_offset % 8);
11911 else
11912 info_ptr->spe_padding_size = 0;
11913
11914 info_ptr->spe_gp_save_offset
11915 = info_ptr->cr_save_offset
11916 - info_ptr->spe_padding_size
11917 - info_ptr->spe_gp_size;
11918
11919 /* Adjust for SPE case. */
11920 info_ptr->toc_save_offset
11921 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
11922 }
11923 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
11924 {
11925 info_ptr->vrsave_save_offset
11926 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
11927
11928 /* Align stack so vector save area is on a quadword boundary. */
11929 if (info_ptr->altivec_size != 0)
11930 info_ptr->altivec_padding_size
11931 = 16 - (-info_ptr->vrsave_save_offset % 16);
11932 else
11933 info_ptr->altivec_padding_size = 0;
11934
11935 info_ptr->altivec_save_offset
11936 = info_ptr->vrsave_save_offset
11937 - info_ptr->altivec_padding_size
11938 - info_ptr->altivec_size;
11939
11940 /* Adjust for AltiVec case. */
11941 info_ptr->toc_save_offset
11942 = info_ptr->altivec_save_offset - info_ptr->toc_size;
11943 }
11944 else
11945 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 11946 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
11947 info_ptr->lr_save_offset = reg_size;
11948 break;
4697a36c
MM
11949 }
11950
64045029 11951 save_align = (TARGET_ALTIVEC_ABI || DEFAULT_ABI == ABI_DARWIN) ? 16 : 8;
00b960c7
AH
11952 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
11953 + info_ptr->gp_size
11954 + info_ptr->altivec_size
11955 + info_ptr->altivec_padding_size
a3170dc6
AH
11956 + info_ptr->spe_gp_size
11957 + info_ptr->spe_padding_size
00b960c7
AH
11958 + ehrd_size
11959 + info_ptr->cr_size
11960 + info_ptr->lr_size
11961 + info_ptr->vrsave_size
11962 + info_ptr->toc_size,
64045029 11963 save_align);
00b960c7 11964
44688022 11965 non_fixed_size = (info_ptr->vars_size
ff381587 11966 + info_ptr->parm_size
ff381587 11967 + info_ptr->save_size
44688022 11968 + info_ptr->varargs_size);
ff381587 11969
44688022
AM
11970 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
11971 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
11972
11973 /* Determine if we need to allocate any stack frame:
11974
a4f6c312
SS
11975 For AIX we need to push the stack if a frame pointer is needed
11976 (because the stack might be dynamically adjusted), if we are
11977 debugging, if we make calls, or if the sum of fp_save, gp_save,
11978 and local variables are more than the space needed to save all
11979 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
11980 + 18*8 = 288 (GPR13 reserved).
ff381587 11981
a4f6c312
SS
11982 For V.4 we don't have the stack cushion that AIX uses, but assume
11983 that the debugger can handle stackless frames. */
ff381587
MM
11984
11985 if (info_ptr->calls_p)
11986 info_ptr->push_p = 1;
11987
178274da 11988 else if (DEFAULT_ABI == ABI_V4)
44688022 11989 info_ptr->push_p = non_fixed_size != 0;
ff381587 11990
178274da
AM
11991 else if (frame_pointer_needed)
11992 info_ptr->push_p = 1;
11993
11994 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
11995 info_ptr->push_p = 1;
11996
ff381587 11997 else
44688022 11998 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 11999
a4f6c312 12000 /* Zero offsets if we're not saving those registers. */
8dda1a21 12001 if (info_ptr->fp_size == 0)
4697a36c
MM
12002 info_ptr->fp_save_offset = 0;
12003
8dda1a21 12004 if (info_ptr->gp_size == 0)
4697a36c
MM
12005 info_ptr->gp_save_offset = 0;
12006
00b960c7
AH
12007 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
12008 info_ptr->altivec_save_offset = 0;
12009
12010 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
12011 info_ptr->vrsave_save_offset = 0;
12012
c19de7aa
AH
12013 if (! TARGET_SPE_ABI
12014 || info_ptr->spe_64bit_regs_used == 0
12015 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
12016 info_ptr->spe_gp_save_offset = 0;
12017
c81fc13e 12018 if (! info_ptr->lr_save_p)
4697a36c
MM
12019 info_ptr->lr_save_offset = 0;
12020
c81fc13e 12021 if (! info_ptr->cr_save_p)
4697a36c
MM
12022 info_ptr->cr_save_offset = 0;
12023
c81fc13e 12024 if (! info_ptr->toc_save_p)
b6c9286a
MM
12025 info_ptr->toc_save_offset = 0;
12026
4697a36c
MM
12027 return info_ptr;
12028}
12029
c19de7aa
AH
12030/* Return true if the current function uses any GPRs in 64-bit SIMD
12031 mode. */
12032
12033static bool
863d938c 12034spe_func_has_64bit_regs_p (void)
c19de7aa
AH
12035{
12036 rtx insns, insn;
12037
12038 /* Functions that save and restore all the call-saved registers will
12039 need to save/restore the registers in 64-bits. */
12040 if (current_function_calls_eh_return
12041 || current_function_calls_setjmp
12042 || current_function_has_nonlocal_goto)
12043 return true;
12044
12045 insns = get_insns ();
12046
12047 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
12048 {
12049 if (INSN_P (insn))
12050 {
12051 rtx i;
12052
12053 i = PATTERN (insn);
12054 if (GET_CODE (i) == SET
12055 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
12056 return true;
12057 }
12058 }
12059
12060 return false;
12061}
12062
d1d0c603 12063static void
a2369ed3 12064debug_stack_info (rs6000_stack_t *info)
9878760c 12065{
d330fd93 12066 const char *abi_string;
24d304eb 12067
c81fc13e 12068 if (! info)
4697a36c
MM
12069 info = rs6000_stack_info ();
12070
12071 fprintf (stderr, "\nStack information for function %s:\n",
12072 ((current_function_decl && DECL_NAME (current_function_decl))
12073 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
12074 : "<unknown>"));
12075
24d304eb
RK
12076 switch (info->abi)
12077 {
b6c9286a
MM
12078 default: abi_string = "Unknown"; break;
12079 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 12080 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 12081 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 12082 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
12083 }
12084
12085 fprintf (stderr, "\tABI = %5s\n", abi_string);
12086
00b960c7
AH
12087 if (TARGET_ALTIVEC_ABI)
12088 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
12089
a3170dc6
AH
12090 if (TARGET_SPE_ABI)
12091 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
12092
4697a36c
MM
12093 if (info->first_gp_reg_save != 32)
12094 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
12095
12096 if (info->first_fp_reg_save != 64)
12097 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 12098
00b960c7
AH
12099 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
12100 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
12101 info->first_altivec_reg_save);
12102
4697a36c
MM
12103 if (info->lr_save_p)
12104 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 12105
4697a36c
MM
12106 if (info->cr_save_p)
12107 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
12108
b6c9286a
MM
12109 if (info->toc_save_p)
12110 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
12111
00b960c7
AH
12112 if (info->vrsave_mask)
12113 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
12114
4697a36c
MM
12115 if (info->push_p)
12116 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
12117
12118 if (info->calls_p)
12119 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
12120
4697a36c
MM
12121 if (info->gp_save_offset)
12122 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
12123
12124 if (info->fp_save_offset)
12125 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
12126
00b960c7
AH
12127 if (info->altivec_save_offset)
12128 fprintf (stderr, "\taltivec_save_offset = %5d\n",
12129 info->altivec_save_offset);
12130
a3170dc6
AH
12131 if (info->spe_gp_save_offset)
12132 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
12133 info->spe_gp_save_offset);
12134
00b960c7
AH
12135 if (info->vrsave_save_offset)
12136 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
12137 info->vrsave_save_offset);
12138
4697a36c
MM
12139 if (info->lr_save_offset)
12140 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
12141
12142 if (info->cr_save_offset)
12143 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
12144
b6c9286a
MM
12145 if (info->toc_save_offset)
12146 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
12147
4697a36c
MM
12148 if (info->varargs_save_offset)
12149 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
12150
12151 if (info->total_size)
d1d0c603
JJ
12152 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12153 info->total_size);
4697a36c
MM
12154
12155 if (info->varargs_size)
12156 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
12157
12158 if (info->vars_size)
d1d0c603
JJ
12159 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
12160 info->vars_size);
4697a36c
MM
12161
12162 if (info->parm_size)
12163 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
12164
12165 if (info->fixed_size)
12166 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
12167
12168 if (info->gp_size)
12169 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
12170
a3170dc6
AH
12171 if (info->spe_gp_size)
12172 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
12173
4697a36c
MM
12174 if (info->fp_size)
12175 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
12176
00b960c7
AH
12177 if (info->altivec_size)
12178 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
12179
12180 if (info->vrsave_size)
12181 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
12182
12183 if (info->altivec_padding_size)
12184 fprintf (stderr, "\taltivec_padding_size= %5d\n",
12185 info->altivec_padding_size);
12186
a3170dc6
AH
12187 if (info->spe_padding_size)
12188 fprintf (stderr, "\tspe_padding_size = %5d\n",
12189 info->spe_padding_size);
12190
a4f6c312 12191 if (info->lr_size)
ed947a96 12192 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 12193
4697a36c
MM
12194 if (info->cr_size)
12195 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
12196
a4f6c312 12197 if (info->toc_size)
b6c9286a
MM
12198 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
12199
4697a36c
MM
12200 if (info->save_size)
12201 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
12202
12203 if (info->reg_size != 4)
12204 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
12205
12206 fprintf (stderr, "\n");
9878760c 12207}
71f123ca
FS
12208
12209rtx
a2369ed3 12210rs6000_return_addr (int count, rtx frame)
71f123ca 12211{
a4f6c312
SS
12212 /* Currently we don't optimize very well between prolog and body
12213 code and for PIC code the code can be actually quite bad, so
12214 don't try to be too clever here. */
f1384257 12215 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
12216 {
12217 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
12218
12219 return
12220 gen_rtx_MEM
12221 (Pmode,
12222 memory_address
12223 (Pmode,
12224 plus_constant (copy_to_reg
12225 (gen_rtx_MEM (Pmode,
12226 memory_address (Pmode, frame))),
12227 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
12228 }
12229
8c29550d 12230 cfun->machine->ra_need_lr = 1;
9e2f7ec7 12231 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
12232}
12233
5e1bf043
DJ
12234/* Say whether a function is a candidate for sibcall handling or not.
12235 We do not allow indirect calls to be optimized into sibling calls.
12236 Also, we can't do it if there are any vector parameters; there's
12237 nowhere to put the VRsave code so it works; note that functions with
12238 vector parameters are required to have a prototype, so the argument
12239 type info must be available here. (The tail recursion case can work
12240 with vector parameters, but there's no way to distinguish here.) */
4977bab6 12241static bool
a2369ed3 12242rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
12243{
12244 tree type;
4977bab6 12245 if (decl)
5e1bf043
DJ
12246 {
12247 if (TARGET_ALTIVEC_VRSAVE)
12248 {
4977bab6 12249 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
12250 type; type = TREE_CHAIN (type))
12251 {
c15b529f 12252 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 12253 return false;
5e1bf043
DJ
12254 }
12255 }
12256 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 12257 || (*targetm.binds_local_p) (decl))
2bcc50d0 12258 {
4977bab6 12259 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
12260
12261 if (!lookup_attribute ("longcall", attr_list)
12262 || lookup_attribute ("shortcall", attr_list))
4977bab6 12263 return true;
2bcc50d0 12264 }
5e1bf043 12265 }
4977bab6 12266 return false;
5e1bf043
DJ
12267}
12268
71f123ca 12269static int
863d938c 12270rs6000_ra_ever_killed (void)
71f123ca
FS
12271{
12272 rtx top;
5e1bf043
DJ
12273 rtx reg;
12274 rtx insn;
71f123ca 12275
dd292d0a 12276 if (current_function_is_thunk)
71f123ca 12277 return 0;
eb0424da 12278
36f7e964
AH
12279 /* regs_ever_live has LR marked as used if any sibcalls are present,
12280 but this should not force saving and restoring in the
12281 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 12282 clobbers LR, so that is inappropriate. */
36f7e964 12283
5e1bf043
DJ
12284 /* Also, the prologue can generate a store into LR that
12285 doesn't really count, like this:
36f7e964 12286
5e1bf043
DJ
12287 move LR->R0
12288 bcl to set PIC register
12289 move LR->R31
12290 move R0->LR
36f7e964
AH
12291
12292 When we're called from the epilogue, we need to avoid counting
12293 this as a store. */
f676971a 12294
71f123ca
FS
12295 push_topmost_sequence ();
12296 top = get_insns ();
12297 pop_topmost_sequence ();
5e1bf043 12298 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 12299
5e1bf043
DJ
12300 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
12301 {
12302 if (INSN_P (insn))
12303 {
12304 if (FIND_REG_INC_NOTE (insn, reg))
12305 return 1;
f676971a 12306 else if (GET_CODE (insn) == CALL_INSN
c15b529f 12307 && !SIBLING_CALL_P (insn))
5e1bf043 12308 return 1;
36f7e964
AH
12309 else if (set_of (reg, insn) != NULL_RTX
12310 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
12311 return 1;
12312 }
12313 }
12314 return 0;
71f123ca 12315}
4697a36c 12316\f
8cd8f856
GK
12317/* Add a REG_MAYBE_DEAD note to the insn. */
12318static void
a2369ed3 12319rs6000_maybe_dead (rtx insn)
8cd8f856
GK
12320{
12321 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
12322 const0_rtx,
12323 REG_NOTES (insn));
12324}
12325
9ebbca7d 12326/* Emit instructions needed to load the TOC register.
c7ca610e 12327 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 12328 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
12329
12330void
a2369ed3 12331rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 12332{
027fbf43 12333 rtx dest, insn;
1db02437 12334 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 12335
20b71b17
AM
12336 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
12337 {
12338 rtx temp = (fromprolog
12339 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12340 : gen_reg_rtx (Pmode));
027fbf43
JJ
12341 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
12342 if (fromprolog)
12343 rs6000_maybe_dead (insn);
12344 insn = emit_move_insn (dest, temp);
12345 if (fromprolog)
12346 rs6000_maybe_dead (insn);
20b71b17
AM
12347 }
12348 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
12349 {
12350 char buf[30];
12351 rtx tempLR = (fromprolog
12352 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
12353 : gen_reg_rtx (Pmode));
12354 rtx temp0 = (fromprolog
12355 ? gen_rtx_REG (Pmode, 0)
12356 : gen_reg_rtx (Pmode));
12357 rtx symF;
12358
12359 /* possibly create the toc section */
12360 if (! toc_initialized)
38c1f2d7 12361 {
20b71b17
AM
12362 toc_section ();
12363 function_section (current_function_decl);
38c1f2d7 12364 }
9ebbca7d 12365
20b71b17
AM
12366 if (fromprolog)
12367 {
12368 rtx symL;
38c1f2d7 12369
20b71b17
AM
12370 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
12371 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 12372
20b71b17
AM
12373 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
12374 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12375
12376 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
12377 symF)));
12378 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
12379 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
12380 symL,
12381 symF)));
9ebbca7d
GK
12382 }
12383 else
20b71b17
AM
12384 {
12385 rtx tocsym;
12386 static int reload_toc_labelno = 0;
12387
12388 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
12389
12390 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
12391 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12392
027fbf43
JJ
12393 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
12394 emit_move_insn (dest, tempLR);
12395 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 12396 }
027fbf43
JJ
12397 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
12398 if (fromprolog)
12399 rs6000_maybe_dead (insn);
9ebbca7d 12400 }
20b71b17
AM
12401 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
12402 {
12403 /* This is for AIX code running in non-PIC ELF32. */
12404 char buf[30];
12405 rtx realsym;
12406 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
12407 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
12408
027fbf43
JJ
12409 insn = emit_insn (gen_elf_high (dest, realsym));
12410 if (fromprolog)
12411 rs6000_maybe_dead (insn);
12412 insn = emit_insn (gen_elf_low (dest, dest, realsym));
12413 if (fromprolog)
12414 rs6000_maybe_dead (insn);
20b71b17
AM
12415 }
12416 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
12417 {
12418 if (TARGET_32BIT)
027fbf43 12419 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 12420 else
027fbf43
JJ
12421 insn = emit_insn (gen_load_toc_aix_di (dest));
12422 if (fromprolog)
12423 rs6000_maybe_dead (insn);
9ebbca7d 12424 }
20b71b17
AM
12425 else
12426 abort ();
9ebbca7d
GK
12427}
12428
d1d0c603
JJ
12429/* Emit instructions to restore the link register after determining where
12430 its value has been stored. */
12431
12432void
12433rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
12434{
12435 rs6000_stack_t *info = rs6000_stack_info ();
12436 rtx operands[2];
12437
12438 operands[0] = source;
12439 operands[1] = scratch;
12440
12441 if (info->lr_save_p)
12442 {
12443 rtx frame_rtx = stack_pointer_rtx;
12444 HOST_WIDE_INT sp_offset = 0;
12445 rtx tmp;
12446
12447 if (frame_pointer_needed
12448 || current_function_calls_alloca
12449 || info->total_size > 32767)
12450 {
12451 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
12452 frame_rtx = operands[1];
12453 }
12454 else if (info->push_p)
12455 sp_offset = info->total_size;
12456
12457 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
12458 tmp = gen_rtx_MEM (Pmode, tmp);
12459 emit_move_insn (tmp, operands[0]);
12460 }
12461 else
12462 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
12463}
12464
f103e34d
GK
12465static GTY(()) int set = -1;
12466
f676971a 12467int
863d938c 12468get_TOC_alias_set (void)
9ebbca7d 12469{
f103e34d
GK
12470 if (set == -1)
12471 set = new_alias_set ();
12472 return set;
f676971a 12473}
9ebbca7d 12474
c1207243 12475/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
12476 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
12477 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 12478#if TARGET_ELF
3c9eb5f4 12479static int
f676971a 12480uses_TOC (void)
9ebbca7d 12481{
c4501e62 12482 rtx insn;
38c1f2d7 12483
c4501e62
JJ
12484 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
12485 if (INSN_P (insn))
12486 {
12487 rtx pat = PATTERN (insn);
12488 int i;
9ebbca7d 12489
f676971a 12490 if (GET_CODE (pat) == PARALLEL)
c4501e62
JJ
12491 for (i = 0; i < XVECLEN (pat, 0); i++)
12492 {
12493 rtx sub = XVECEXP (pat, 0, i);
12494 if (GET_CODE (sub) == USE)
12495 {
12496 sub = XEXP (sub, 0);
12497 if (GET_CODE (sub) == UNSPEC
12498 && XINT (sub, 1) == UNSPEC_TOC)
12499 return 1;
12500 }
12501 }
12502 }
12503 return 0;
9ebbca7d 12504}
c954844a 12505#endif
38c1f2d7 12506
9ebbca7d 12507rtx
f676971a 12508create_TOC_reference (rtx symbol)
9ebbca7d 12509{
f676971a 12510 return gen_rtx_PLUS (Pmode,
a8a05998 12511 gen_rtx_REG (Pmode, TOC_REGISTER),
f676971a
EC
12512 gen_rtx_CONST (Pmode,
12513 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 12514 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 12515}
38c1f2d7 12516
fc4767bb
JJ
12517/* If _Unwind_* has been called from within the same module,
12518 toc register is not guaranteed to be saved to 40(1) on function
12519 entry. Save it there in that case. */
c7ca610e 12520
9ebbca7d 12521void
863d938c 12522rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
12523{
12524 rtx mem;
12525 rtx stack_top = gen_reg_rtx (Pmode);
12526 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
12527 rtx opcode = gen_reg_rtx (SImode);
12528 rtx tocompare = gen_reg_rtx (SImode);
12529 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
12530
12531 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
12532 emit_move_insn (stack_top, mem);
12533
fc4767bb
JJ
12534 mem = gen_rtx_MEM (Pmode,
12535 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
12536 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
12537 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
12538 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
12539 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 12540 : 0xE8410028, SImode));
9ebbca7d 12541
fc4767bb 12542 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 12543 SImode, NULL_RTX, NULL_RTX,
fc4767bb 12544 no_toc_save_needed);
9ebbca7d 12545
fc4767bb
JJ
12546 mem = gen_rtx_MEM (Pmode,
12547 gen_rtx_PLUS (Pmode, stack_top,
12548 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
12549 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
12550 emit_label (no_toc_save_needed);
9ebbca7d 12551}
38c1f2d7 12552\f
ba4828e0
RK
12553/* This ties together stack memory (MEM with an alias set of
12554 rs6000_sr_alias_set) and the change to the stack pointer. */
12555
9ebbca7d 12556static void
863d938c 12557rs6000_emit_stack_tie (void)
9ebbca7d 12558{
ba4828e0
RK
12559 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
12560
12561 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12562 emit_insn (gen_stack_tie (mem));
12563}
38c1f2d7 12564
9ebbca7d
GK
12565/* Emit the correct code for allocating stack space, as insns.
12566 If COPY_R12, make sure a copy of the old frame is left in r12.
12567 The generated code may use hard register 0 as a temporary. */
12568
12569static void
a2369ed3 12570rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 12571{
9ebbca7d
GK
12572 rtx insn;
12573 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12574 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
12575 rtx todec = GEN_INT (-size);
a157febd
GK
12576
12577 if (current_function_limit_stack)
12578 {
12579 if (REG_P (stack_limit_rtx)
f676971a 12580 && REGNO (stack_limit_rtx) > 1
a157febd
GK
12581 && REGNO (stack_limit_rtx) <= 31)
12582 {
5b71a4e7 12583 emit_insn (TARGET_32BIT
9ebbca7d
GK
12584 ? gen_addsi3 (tmp_reg,
12585 stack_limit_rtx,
12586 GEN_INT (size))
12587 : gen_adddi3 (tmp_reg,
12588 stack_limit_rtx,
12589 GEN_INT (size)));
5b71a4e7 12590
9ebbca7d
GK
12591 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
12592 const0_rtx));
a157febd
GK
12593 }
12594 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 12595 && TARGET_32BIT
f607bc57 12596 && DEFAULT_ABI == ABI_V4)
a157febd 12597 {
9ebbca7d 12598 rtx toload = gen_rtx_CONST (VOIDmode,
f676971a
EC
12599 gen_rtx_PLUS (Pmode,
12600 stack_limit_rtx,
9ebbca7d 12601 GEN_INT (size)));
5b71a4e7 12602
9ebbca7d
GK
12603 emit_insn (gen_elf_high (tmp_reg, toload));
12604 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
12605 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
12606 const0_rtx));
a157febd
GK
12607 }
12608 else
12609 warning ("stack limit expression is not supported");
12610 }
12611
9ebbca7d
GK
12612 if (copy_r12 || ! TARGET_UPDATE)
12613 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
12614
38c1f2d7
MM
12615 if (TARGET_UPDATE)
12616 {
9ebbca7d 12617 if (size > 32767)
38c1f2d7 12618 {
9ebbca7d
GK
12619 /* Need a note here so that try_split doesn't get confused. */
12620 if (get_last_insn() == NULL_RTX)
2e040219 12621 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
12622 insn = emit_move_insn (tmp_reg, todec);
12623 try_split (PATTERN (insn), insn, 0);
12624 todec = tmp_reg;
38c1f2d7 12625 }
5b71a4e7
DE
12626
12627 insn = emit_insn (TARGET_32BIT
12628 ? gen_movsi_update (stack_reg, stack_reg,
12629 todec, stack_reg)
2e6c9641 12630 : gen_movdi_di_update (stack_reg, stack_reg,
9ebbca7d 12631 todec, stack_reg));
38c1f2d7
MM
12632 }
12633 else
12634 {
5b71a4e7
DE
12635 insn = emit_insn (TARGET_32BIT
12636 ? gen_addsi3 (stack_reg, stack_reg, todec)
12637 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
12638 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
12639 gen_rtx_REG (Pmode, 12));
12640 }
f676971a 12641
9ebbca7d 12642 RTX_FRAME_RELATED_P (insn) = 1;
f676971a 12643 REG_NOTES (insn) =
9ebbca7d 12644 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
f676971a 12645 gen_rtx_SET (VOIDmode, stack_reg,
9ebbca7d
GK
12646 gen_rtx_PLUS (Pmode, stack_reg,
12647 GEN_INT (-size))),
12648 REG_NOTES (insn));
12649}
12650
a4f6c312
SS
12651/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
12652 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
12653 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
12654 deduce these equivalences by itself so it wasn't necessary to hold
12655 its hand so much. */
9ebbca7d
GK
12656
12657static void
f676971a 12658rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
a2369ed3 12659 rtx reg2, rtx rreg)
9ebbca7d
GK
12660{
12661 rtx real, temp;
12662
e56c4463
JL
12663 /* copy_rtx will not make unique copies of registers, so we need to
12664 ensure we don't have unwanted sharing here. */
12665 if (reg == reg2)
12666 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
12667
12668 if (reg == rreg)
12669 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
12670
9ebbca7d
GK
12671 real = copy_rtx (PATTERN (insn));
12672
89e7058f
AH
12673 if (reg2 != NULL_RTX)
12674 real = replace_rtx (real, reg2, rreg);
f676971a
EC
12675
12676 real = replace_rtx (real, reg,
9ebbca7d
GK
12677 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
12678 STACK_POINTER_REGNUM),
12679 GEN_INT (val)));
f676971a 12680
9ebbca7d
GK
12681 /* We expect that 'real' is either a SET or a PARALLEL containing
12682 SETs (and possibly other stuff). In a PARALLEL, all the SETs
12683 are important so they all have to be marked RTX_FRAME_RELATED_P. */
12684
12685 if (GET_CODE (real) == SET)
12686 {
12687 rtx set = real;
f676971a 12688
9ebbca7d
GK
12689 temp = simplify_rtx (SET_SRC (set));
12690 if (temp)
12691 SET_SRC (set) = temp;
12692 temp = simplify_rtx (SET_DEST (set));
12693 if (temp)
12694 SET_DEST (set) = temp;
12695 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 12696 {
9ebbca7d
GK
12697 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
12698 if (temp)
12699 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 12700 }
38c1f2d7 12701 }
9ebbca7d
GK
12702 else if (GET_CODE (real) == PARALLEL)
12703 {
12704 int i;
12705 for (i = 0; i < XVECLEN (real, 0); i++)
12706 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
12707 {
12708 rtx set = XVECEXP (real, 0, i);
f676971a 12709
9ebbca7d
GK
12710 temp = simplify_rtx (SET_SRC (set));
12711 if (temp)
12712 SET_SRC (set) = temp;
12713 temp = simplify_rtx (SET_DEST (set));
12714 if (temp)
12715 SET_DEST (set) = temp;
12716 if (GET_CODE (SET_DEST (set)) == MEM)
12717 {
12718 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
12719 if (temp)
12720 XEXP (SET_DEST (set), 0) = temp;
12721 }
12722 RTX_FRAME_RELATED_P (set) = 1;
12723 }
12724 }
12725 else
a4f6c312 12726 abort ();
c19de7aa
AH
12727
12728 if (TARGET_SPE)
12729 real = spe_synthesize_frame_save (real);
12730
9ebbca7d
GK
12731 RTX_FRAME_RELATED_P (insn) = 1;
12732 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
12733 real,
12734 REG_NOTES (insn));
38c1f2d7
MM
12735}
12736
c19de7aa
AH
12737/* Given an SPE frame note, return a PARALLEL of SETs with the
12738 original note, plus a synthetic register save. */
12739
12740static rtx
a2369ed3 12741spe_synthesize_frame_save (rtx real)
c19de7aa
AH
12742{
12743 rtx synth, offset, reg, real2;
12744
12745 if (GET_CODE (real) != SET
12746 || GET_MODE (SET_SRC (real)) != V2SImode)
12747 return real;
12748
12749 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
12750 frame related note. The parallel contains a set of the register
41f3a930 12751 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
12752 This is so we can differentiate between 64-bit and 32-bit saves.
12753 Words cannot describe this nastiness. */
12754
12755 if (GET_CODE (SET_DEST (real)) != MEM
12756 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
12757 || GET_CODE (SET_SRC (real)) != REG)
12758 abort ();
12759
12760 /* Transform:
12761 (set (mem (plus (reg x) (const y)))
12762 (reg z))
12763 into:
12764 (set (mem (plus (reg x) (const y+4)))
41f3a930 12765 (reg z+1200))
c19de7aa
AH
12766 */
12767
12768 real2 = copy_rtx (real);
12769 PUT_MODE (SET_DEST (real2), SImode);
12770 reg = SET_SRC (real2);
12771 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
12772 synth = copy_rtx (real2);
12773
12774 if (BYTES_BIG_ENDIAN)
12775 {
12776 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
12777 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
12778 }
12779
12780 reg = SET_SRC (synth);
41f3a930 12781
c19de7aa 12782 synth = replace_rtx (synth, reg,
41f3a930 12783 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
12784
12785 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
12786 synth = replace_rtx (synth, offset,
12787 GEN_INT (INTVAL (offset)
12788 + (BYTES_BIG_ENDIAN ? 0 : 4)));
12789
12790 RTX_FRAME_RELATED_P (synth) = 1;
12791 RTX_FRAME_RELATED_P (real2) = 1;
12792 if (BYTES_BIG_ENDIAN)
12793 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
12794 else
12795 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
12796
12797 return real;
12798}
12799
00b960c7
AH
12800/* Returns an insn that has a vrsave set operation with the
12801 appropriate CLOBBERs. */
12802
12803static rtx
a2369ed3 12804generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
12805{
12806 int nclobs, i;
12807 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 12808 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 12809
a004eb82
AH
12810 clobs[0]
12811 = gen_rtx_SET (VOIDmode,
12812 vrsave,
12813 gen_rtx_UNSPEC_VOLATILE (SImode,
12814 gen_rtvec (2, reg, vrsave),
12815 30));
00b960c7
AH
12816
12817 nclobs = 1;
12818
9aa86737
AH
12819 /* We need to clobber the registers in the mask so the scheduler
12820 does not move sets to VRSAVE before sets of AltiVec registers.
12821
12822 However, if the function receives nonlocal gotos, reload will set
12823 all call saved registers live. We will end up with:
12824
12825 (set (reg 999) (mem))
12826 (parallel [ (set (reg vrsave) (unspec blah))
12827 (clobber (reg 999))])
12828
12829 The clobber will cause the store into reg 999 to be dead, and
12830 flow will attempt to delete an epilogue insn. In this case, we
12831 need an unspec use/set of the register. */
00b960c7
AH
12832
12833 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
44688022 12834 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
9aa86737
AH
12835 {
12836 if (!epiloguep || call_used_regs [i])
12837 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
12838 gen_rtx_REG (V4SImode, i));
12839 else
12840 {
12841 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
12842
12843 clobs[nclobs++]
a004eb82
AH
12844 = gen_rtx_SET (VOIDmode,
12845 reg,
12846 gen_rtx_UNSPEC (V4SImode,
12847 gen_rtvec (1, reg), 27));
9aa86737
AH
12848 }
12849 }
00b960c7
AH
12850
12851 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
12852
12853 for (i = 0; i < nclobs; ++i)
12854 XVECEXP (insn, 0, i) = clobs[i];
12855
12856 return insn;
12857}
12858
89e7058f
AH
12859/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
12860 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
12861
12862static void
f676971a 12863emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 12864 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
12865{
12866 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
12867 rtx replacea, replaceb;
12868
12869 int_rtx = GEN_INT (offset);
12870
12871 /* Some cases that need register indexed addressing. */
12872 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
12873 || (TARGET_SPE_ABI
12874 && SPE_VECTOR_MODE (mode)
12875 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
12876 {
12877 /* Whomever calls us must make sure r11 is available in the
12878 flow path of instructions in the prologue. */
12879 offset_rtx = gen_rtx_REG (Pmode, 11);
12880 emit_move_insn (offset_rtx, int_rtx);
12881
12882 replacea = offset_rtx;
12883 replaceb = int_rtx;
12884 }
12885 else
12886 {
12887 offset_rtx = int_rtx;
12888 replacea = NULL_RTX;
12889 replaceb = NULL_RTX;
12890 }
12891
12892 reg = gen_rtx_REG (mode, regno);
12893 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
12894 mem = gen_rtx_MEM (mode, addr);
12895 set_mem_alias_set (mem, rs6000_sr_alias_set);
12896
12897 insn = emit_move_insn (mem, reg);
12898
12899 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
12900}
12901
a3170dc6
AH
12902/* Emit an offset memory reference suitable for a frame store, while
12903 converting to a valid addressing mode. */
12904
12905static rtx
a2369ed3 12906gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
12907{
12908 rtx int_rtx, offset_rtx;
12909
12910 int_rtx = GEN_INT (offset);
12911
12912 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
12913 {
12914 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12915 emit_move_insn (offset_rtx, int_rtx);
12916 }
12917 else
12918 offset_rtx = int_rtx;
12919
12920 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
12921}
12922
699c914a
MS
12923#ifndef TARGET_FIX_AND_CONTINUE
12924#define TARGET_FIX_AND_CONTINUE 0
12925#endif
12926
9ebbca7d
GK
12927/* Emit function prologue as insns. */
12928
9878760c 12929void
863d938c 12930rs6000_emit_prologue (void)
9878760c 12931{
4697a36c 12932 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 12933 enum machine_mode reg_mode = Pmode;
327e5343 12934 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12935 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12936 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
12937 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 12938 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
12939 rtx insn;
12940 int saving_FPRs_inline;
12941 int using_store_multiple;
12942 HOST_WIDE_INT sp_offset = 0;
f676971a 12943
699c914a
MS
12944 if (TARGET_FIX_AND_CONTINUE)
12945 {
12946 /* gdb on darwin arranges to forward a function from the old
12947 address by modifying the first 4 instructions of the function
12948 to branch to the overriding function. This is necessary to
12949 permit function pointers that point to the old function to
12950 actually forward to the new function. */
12951 emit_insn (gen_nop ());
12952 emit_insn (gen_nop ());
12953 emit_insn (gen_nop ());
12954 emit_insn (gen_nop ());
12955 }
12956
12957 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
12958 {
12959 reg_mode = V2SImode;
12960 reg_size = 8;
12961 }
a3170dc6 12962
9ebbca7d 12963 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12964 && (!TARGET_SPE_ABI
12965 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12966 && info->first_gp_reg_save < 31);
12967 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 12968 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 12969 || current_function_calls_eh_return
8c29550d 12970 || cfun->machine->ra_need_lr);
9ebbca7d
GK
12971
12972 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 12973 if (info->push_p
acd0b319
AM
12974 && (DEFAULT_ABI == ABI_V4
12975 || current_function_calls_eh_return))
9ebbca7d
GK
12976 {
12977 if (info->total_size < 32767)
12978 sp_offset = info->total_size;
12979 else
12980 frame_reg_rtx = frame_ptr_rtx;
f676971a 12981 rs6000_emit_allocate_stack (info->total_size,
9ebbca7d
GK
12982 (frame_reg_rtx != sp_reg_rtx
12983 && (info->cr_save_p
12984 || info->lr_save_p
12985 || info->first_fp_reg_save < 64
12986 || info->first_gp_reg_save < 32
12987 )));
12988 if (frame_reg_rtx != sp_reg_rtx)
12989 rs6000_emit_stack_tie ();
12990 }
12991
d62294f5
FJ
12992 /* Handle world saves specially here. */
12993 if (info->world_save_p)
12994 {
12995 int i, j, sz;
12996 rtx treg;
12997 rtvec p;
12998
12999 /* save_world expects lr in r0. */
13000 if (info->lr_save_p)
13001 {
13002 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13003 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13004 RTX_FRAME_RELATED_P (insn) = 1;
13005 }
13006
13007 /* The SAVE_WORLD and RESTORE_WORLD routines make a number of
13008 assumptions about the offsets of various bits of the stack
13009 frame. Abort if things aren't what they should be. */
13010 if (info->gp_save_offset != -220
13011 || info->fp_save_offset != -144
13012 || info->lr_save_offset != 8
13013 || info->cr_save_offset != 4
13014 || !info->push_p
13015 || !info->lr_save_p
13016 || (current_function_calls_eh_return && info->ehrd_offset != -432)
13017 || (info->vrsave_save_offset != -224
13018 || info->altivec_save_offset != (-224 -16 -192)))
13019 abort ();
13020
13021 treg = gen_rtx_REG (SImode, 11);
13022 emit_move_insn (treg, GEN_INT (-info->total_size));
13023
13024 /* SAVE_WORLD takes the caller's LR in R0 and the frame size
13025 in R11. It also clobbers R12, so beware! */
13026
13027 /* Preserve CR2 for save_world prologues */
13028 sz = 6;
13029 sz += 32 - info->first_gp_reg_save;
13030 sz += 64 - info->first_fp_reg_save;
13031 sz += LAST_ALTIVEC_REGNO - info->first_altivec_reg_save + 1;
13032 p = rtvec_alloc (sz);
13033 j = 0;
13034 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode,
13035 gen_rtx_REG (Pmode,
13036 LINK_REGISTER_REGNUM));
13037 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
13038 gen_rtx_SYMBOL_REF (Pmode,
13039 "*save_world"));
13040 /* We do floats first so that the instruction pattern matches
13041 properly. */
13042 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13043 {
13044 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13045 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13046 GEN_INT (info->fp_save_offset
13047 + sp_offset + 8 * i));
13048 rtx mem = gen_rtx_MEM (DFmode, addr);
13049 set_mem_alias_set (mem, rs6000_sr_alias_set);
13050
13051 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13052 }
13053 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
13054 {
13055 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
13056 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13057 GEN_INT (info->altivec_save_offset
13058 + sp_offset + 16 * i));
13059 rtx mem = gen_rtx_MEM (V4SImode, addr);
13060 set_mem_alias_set (mem, rs6000_sr_alias_set);
13061
13062 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13063 }
13064 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13065 {
13066 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13067 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13068 GEN_INT (info->gp_save_offset
13069 + sp_offset + reg_size * i));
13070 rtx mem = gen_rtx_MEM (reg_mode, addr);
13071 set_mem_alias_set (mem, rs6000_sr_alias_set);
13072
13073 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13074 }
13075
13076 {
13077 /* CR register traditionally saved as CR2. */
13078 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
13079 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13080 GEN_INT (info->cr_save_offset
13081 + sp_offset));
13082 rtx mem = gen_rtx_MEM (reg_mode, addr);
13083 set_mem_alias_set (mem, rs6000_sr_alias_set);
13084
13085 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, mem, reg);
13086 }
13087 /* Prevent any attempt to delete the setting of r0 and treg! */
13088 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, gen_rtx_REG (Pmode, 0));
13089 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode, treg);
13090 RTVEC_ELT (p, j++) = gen_rtx_CLOBBER (VOIDmode, sp_reg_rtx);
13091
13092 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
13093 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13094 NULL_RTX, NULL_RTX);
13095
13096 if (current_function_calls_eh_return)
13097 {
13098 unsigned int i;
13099 for (i = 0; ; ++i)
13100 {
13101 unsigned int regno = EH_RETURN_DATA_REGNO (i);
13102 if (regno == INVALID_REGNUM)
13103 break;
13104 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13105 info->ehrd_offset + sp_offset
13106 + reg_size * (int) i,
13107 info->total_size);
13108 }
13109 }
13110 }
13111
9aa86737 13112 /* Save AltiVec registers if needed. */
d62294f5 13113 if (! info->world_save_p && TARGET_ALTIVEC_ABI && info->altivec_size != 0)
9aa86737
AH
13114 {
13115 int i;
13116
13117 /* There should be a non inline version of this, for when we
13118 are saving lots of vector registers. */
13119 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
13120 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
13121 {
13122 rtx areg, savereg, mem;
13123 int offset;
13124
13125 offset = info->altivec_save_offset + sp_offset
13126 + 16 * (i - info->first_altivec_reg_save);
13127
13128 savereg = gen_rtx_REG (V4SImode, i);
13129
13130 areg = gen_rtx_REG (Pmode, 0);
13131 emit_move_insn (areg, GEN_INT (offset));
13132
13133 /* AltiVec addressing mode is [reg+reg]. */
13134 mem = gen_rtx_MEM (V4SImode,
13135 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
f676971a 13136
9aa86737
AH
13137 set_mem_alias_set (mem, rs6000_sr_alias_set);
13138
13139 insn = emit_move_insn (mem, savereg);
13140
5c242421
SB
13141 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13142 areg, GEN_INT (offset));
9aa86737
AH
13143 }
13144 }
13145
13146 /* VRSAVE is a bit vector representing which AltiVec registers
13147 are used. The OS uses this to determine which vector
13148 registers to save on a context switch. We need to save
13149 VRSAVE on the stack frame, add whatever AltiVec registers we
13150 used in this function, and do the corresponding magic in the
13151 epilogue. */
13152
4d774ff8 13153 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
d62294f5 13154 && ! info->world_save_p && info->vrsave_mask != 0)
9aa86737 13155 {
a004eb82 13156 rtx reg, mem, vrsave;
9aa86737
AH
13157 int offset;
13158
13159 /* Get VRSAVE onto a GPR. */
13160 reg = gen_rtx_REG (SImode, 12);
a004eb82 13161 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
13162 if (TARGET_MACHO)
13163 emit_insn (gen_get_vrsave_internal (reg));
13164 else
13165 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
13166
13167 /* Save VRSAVE. */
13168 offset = info->vrsave_save_offset + sp_offset;
13169 mem
13170 = gen_rtx_MEM (SImode,
13171 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
13172 set_mem_alias_set (mem, rs6000_sr_alias_set);
13173 insn = emit_move_insn (mem, reg);
13174
13175 /* Include the registers in the mask. */
13176 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
13177
13178 insn = emit_insn (generate_set_vrsave (reg, info, 0));
13179 }
13180
9ebbca7d 13181 /* If we use the link register, get it into r0. */
d62294f5 13182 if (! info->world_save_p && info->lr_save_p)
f8a57be8
GK
13183 {
13184 insn = emit_move_insn (gen_rtx_REG (Pmode, 0),
13185 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
13186 RTX_FRAME_RELATED_P (insn) = 1;
13187 }
9ebbca7d
GK
13188
13189 /* If we need to save CR, put it into r12. */
d62294f5 13190 if (! info->world_save_p && info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
9ebbca7d 13191 {
f8a57be8 13192 rtx set;
f676971a 13193
9ebbca7d 13194 cr_save_rtx = gen_rtx_REG (SImode, 12);
f8a57be8
GK
13195 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13196 RTX_FRAME_RELATED_P (insn) = 1;
13197 /* Now, there's no way that dwarf2out_frame_debug_expr is going
13198 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
13199 But that's OK. All we have to do is specify that _one_ condition
13200 code register is saved in this stack slot. The thrower's epilogue
13201 will then restore all the call-saved registers.
13202 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
13203 set = gen_rtx_SET (VOIDmode, cr_save_rtx,
13204 gen_rtx_REG (SImode, CR2_REGNO));
13205 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13206 set,
13207 REG_NOTES (insn));
9ebbca7d
GK
13208 }
13209
a4f6c312
SS
13210 /* Do any required saving of fpr's. If only one or two to save, do
13211 it ourselves. Otherwise, call function. */
d62294f5 13212 if (! info->world_save_p && saving_FPRs_inline)
9ebbca7d
GK
13213 {
13214 int i;
13215 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 13216 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d 13217 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
13218 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
13219 info->first_fp_reg_save + i,
13220 info->fp_save_offset + sp_offset + 8 * i,
13221 info->total_size);
9ebbca7d 13222 }
d62294f5 13223 else if (! info->world_save_p && info->first_fp_reg_save != 64)
9ebbca7d
GK
13224 {
13225 int i;
13226 char rname[30];
520a57c8 13227 const char *alloc_rname;
9ebbca7d
GK
13228 rtvec p;
13229 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
f676971a
EC
13230
13231 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
13232 gen_rtx_REG (Pmode,
9ebbca7d
GK
13233 LINK_REGISTER_REGNUM));
13234 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
13235 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 13236 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
13237 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
13238 gen_rtx_SYMBOL_REF (Pmode,
13239 alloc_rname));
13240 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
13241 {
13242 rtx addr, reg, mem;
13243 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13244 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a 13245 GEN_INT (info->fp_save_offset
9ebbca7d
GK
13246 + sp_offset + 8*i));
13247 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 13248 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13249
13250 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
13251 }
13252 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13253 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d
GK
13254 NULL_RTX, NULL_RTX);
13255 }
b6c9286a 13256
9ebbca7d
GK
13257 /* Save GPRs. This is done as a PARALLEL if we are using
13258 the store-multiple instructions. */
d62294f5 13259 if (! info->world_save_p && using_store_multiple)
b6c9286a 13260 {
308c142a 13261 rtvec p;
9ebbca7d
GK
13262 int i;
13263 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
13264 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13265 {
13266 rtx addr, reg, mem;
13267 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
f676971a
EC
13268 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13269 GEN_INT (info->gp_save_offset
13270 + sp_offset
9ebbca7d
GK
13271 + reg_size * i));
13272 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 13273 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13274
13275 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
13276 }
13277 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
f676971a 13278 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
9ebbca7d 13279 NULL_RTX, NULL_RTX);
b6c9286a 13280 }
d62294f5 13281 else if (! info->world_save_p)
b6c9286a 13282 {
9ebbca7d
GK
13283 int i;
13284 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 13285 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
13286 && (! call_used_regs[info->first_gp_reg_save+i]
13287 || (i+info->first_gp_reg_save
13288 == RS6000_PIC_OFFSET_TABLE_REGNUM
13289 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 13290 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 13291 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 13292 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
13293 {
13294 rtx addr, reg, mem;
13295 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13296
c19de7aa 13297 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13298 {
13299 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
13300 rtx b;
13301
13302 if (!SPE_CONST_OFFSET_OK (offset))
13303 {
13304 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13305 emit_move_insn (b, GEN_INT (offset));
13306 }
13307 else
13308 b = GEN_INT (offset);
13309
13310 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
13311 mem = gen_rtx_MEM (V2SImode, addr);
13312 set_mem_alias_set (mem, rs6000_sr_alias_set);
13313 insn = emit_move_insn (mem, reg);
13314
13315 if (GET_CODE (b) == CONST_INT)
13316 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13317 NULL_RTX, NULL_RTX);
13318 else
13319 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
13320 b, GEN_INT (offset));
13321 }
13322 else
13323 {
f676971a
EC
13324 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13325 GEN_INT (info->gp_save_offset
13326 + sp_offset
a3170dc6
AH
13327 + reg_size * i));
13328 mem = gen_rtx_MEM (reg_mode, addr);
13329 set_mem_alias_set (mem, rs6000_sr_alias_set);
13330
13331 insn = emit_move_insn (mem, reg);
f676971a 13332 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a3170dc6
AH
13333 NULL_RTX, NULL_RTX);
13334 }
13335 }
9ebbca7d
GK
13336 }
13337
83720594
RH
13338 /* ??? There's no need to emit actual instructions here, but it's the
13339 easiest way to get the frame unwind information emitted. */
d62294f5 13340 if (! info->world_save_p && current_function_calls_eh_return)
83720594 13341 {
78e1b90d
DE
13342 unsigned int i, regno;
13343
fc4767bb
JJ
13344 /* In AIX ABI we need to pretend we save r2 here. */
13345 if (TARGET_AIX)
13346 {
13347 rtx addr, reg, mem;
13348
13349 reg = gen_rtx_REG (reg_mode, 2);
13350 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13351 GEN_INT (sp_offset + 5 * reg_size));
13352 mem = gen_rtx_MEM (reg_mode, addr);
13353 set_mem_alias_set (mem, rs6000_sr_alias_set);
13354
13355 insn = emit_move_insn (mem, reg);
f676971a 13356 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
fc4767bb
JJ
13357 NULL_RTX, NULL_RTX);
13358 PATTERN (insn) = gen_blockage ();
13359 }
13360
83720594
RH
13361 for (i = 0; ; ++i)
13362 {
83720594
RH
13363 regno = EH_RETURN_DATA_REGNO (i);
13364 if (regno == INVALID_REGNUM)
13365 break;
13366
89e7058f
AH
13367 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
13368 info->ehrd_offset + sp_offset
13369 + reg_size * (int) i,
13370 info->total_size);
83720594
RH
13371 }
13372 }
13373
9ebbca7d 13374 /* Save lr if we used it. */
d62294f5 13375 if (! info->world_save_p && info->lr_save_p)
9ebbca7d
GK
13376 {
13377 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13378 GEN_INT (info->lr_save_offset + sp_offset));
13379 rtx reg = gen_rtx_REG (Pmode, 0);
13380 rtx mem = gen_rtx_MEM (Pmode, addr);
13381 /* This should not be of rs6000_sr_alias_set, because of
13382 __builtin_return_address. */
f676971a 13383
9ebbca7d 13384 insn = emit_move_insn (mem, reg);
f676971a 13385 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13386 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13387 }
13388
13389 /* Save CR if we use any that must be preserved. */
d62294f5 13390 if (! info->world_save_p && info->cr_save_p)
9ebbca7d
GK
13391 {
13392 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13393 GEN_INT (info->cr_save_offset + sp_offset));
13394 rtx mem = gen_rtx_MEM (SImode, addr);
f8a57be8
GK
13395 /* See the large comment above about why CR2_REGNO is used. */
13396 rtx magic_eh_cr_reg = gen_rtx_REG (SImode, CR2_REGNO);
ba4828e0
RK
13397
13398 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
13399
13400 /* If r12 was used to hold the original sp, copy cr into r0 now
13401 that it's free. */
13402 if (REGNO (frame_reg_rtx) == 12)
13403 {
f8a57be8
GK
13404 rtx set;
13405
9ebbca7d 13406 cr_save_rtx = gen_rtx_REG (SImode, 0);
f8a57be8
GK
13407 insn = emit_insn (gen_movesi_from_cr (cr_save_rtx));
13408 RTX_FRAME_RELATED_P (insn) = 1;
13409 set = gen_rtx_SET (VOIDmode, cr_save_rtx, magic_eh_cr_reg);
13410 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
13411 set,
13412 REG_NOTES (insn));
f676971a 13413
9ebbca7d
GK
13414 }
13415 insn = emit_move_insn (mem, cr_save_rtx);
13416
f676971a 13417 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
f8a57be8 13418 NULL_RTX, NULL_RTX);
9ebbca7d
GK
13419 }
13420
f676971a 13421 /* Update stack and set back pointer unless this is V.4,
9ebbca7d 13422 for which it was done previously. */
d62294f5 13423 if (! info->world_save_p && info->push_p
fc4767bb 13424 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
13425 rs6000_emit_allocate_stack (info->total_size, FALSE);
13426
13427 /* Set frame pointer, if needed. */
13428 if (frame_pointer_needed)
13429 {
f676971a 13430 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
13431 sp_reg_rtx);
13432 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 13433 }
9878760c 13434
1db02437 13435 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 13436 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 13437 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 13438 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
13439 {
13440 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 13441 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
13442 can use register 0. This allows us to use a plain 'blr' to return
13443 from the procedure more often. */
f1384257
AM
13444 int save_LR_around_toc_setup = (TARGET_ELF
13445 && DEFAULT_ABI != ABI_AIX
13446 && flag_pic
d5fa86ba
GK
13447 && ! info->lr_save_p
13448 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 13449 if (save_LR_around_toc_setup)
c4501e62
JJ
13450 {
13451 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f8a57be8
GK
13452
13453 insn = emit_move_insn (frame_ptr_rtx, lr);
13454 rs6000_maybe_dead (insn);
13455 RTX_FRAME_RELATED_P (insn) = 1;
13456
c4501e62 13457 rs6000_emit_load_toc_table (TRUE);
f8a57be8
GK
13458
13459 insn = emit_move_insn (lr, frame_ptr_rtx);
13460 rs6000_maybe_dead (insn);
13461 RTX_FRAME_RELATED_P (insn) = 1;
c4501e62
JJ
13462 }
13463 else
13464 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 13465 }
ee890fe2 13466
fcce224d 13467#if TARGET_MACHO
ee890fe2
SS
13468 if (DEFAULT_ABI == ABI_DARWIN
13469 && flag_pic && current_function_uses_pic_offset_table)
13470 {
f8a57be8 13471 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
11abc112 13472 rtx src = machopic_function_base_sym ();
ee890fe2 13473
f8a57be8 13474 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (lr, src)));
ee890fe2 13475
f676971a 13476 insn = emit_move_insn (gen_rtx_REG (Pmode,
f8a57be8
GK
13477 RS6000_PIC_OFFSET_TABLE_REGNUM),
13478 lr);
13479 rs6000_maybe_dead (insn);
ee890fe2 13480 }
fcce224d 13481#endif
9ebbca7d
GK
13482}
13483
9ebbca7d 13484/* Write function prologue. */
a4f6c312 13485
08c148a8 13486static void
f676971a 13487rs6000_output_function_prologue (FILE *file,
a2369ed3 13488 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
13489{
13490 rs6000_stack_t *info = rs6000_stack_info ();
13491
4697a36c
MM
13492 if (TARGET_DEBUG_STACK)
13493 debug_stack_info (info);
9878760c 13494
a4f6c312
SS
13495 /* Write .extern for any function we will call to save and restore
13496 fp values. */
13497 if (info->first_fp_reg_save < 64
13498 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 13499 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 13500 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
13501 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
13502 RESTORE_FP_SUFFIX);
9878760c 13503
c764f757
RK
13504 /* Write .extern for AIX common mode routines, if needed. */
13505 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
13506 {
f6709c70
JW
13507 fputs ("\t.extern __mulh\n", file);
13508 fputs ("\t.extern __mull\n", file);
13509 fputs ("\t.extern __divss\n", file);
13510 fputs ("\t.extern __divus\n", file);
13511 fputs ("\t.extern __quoss\n", file);
13512 fputs ("\t.extern __quous\n", file);
c764f757
RK
13513 common_mode_defined = 1;
13514 }
9878760c 13515
9ebbca7d 13516 if (! HAVE_prologue)
979721f8 13517 {
9ebbca7d 13518 start_sequence ();
9dda4cc8 13519
a4f6c312
SS
13520 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
13521 the "toplevel" insn chain. */
2e040219 13522 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13523 rs6000_emit_prologue ();
2e040219 13524 emit_note (NOTE_INSN_DELETED);
178c3eff 13525
a3c9585f 13526 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
13527 {
13528 rtx insn;
13529 unsigned addr = 0;
13530 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
13531 {
13532 INSN_ADDRESSES_NEW (insn, addr);
13533 addr += 4;
13534 }
13535 }
9dda4cc8 13536
9ebbca7d 13537 if (TARGET_DEBUG_STACK)
a4f6c312
SS
13538 debug_rtx_list (get_insns (), 100);
13539 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 13540 end_sequence ();
979721f8
MM
13541 }
13542
9ebbca7d
GK
13543 rs6000_pic_labelno++;
13544}
f676971a 13545
9ebbca7d 13546/* Emit function epilogue as insns.
9878760c 13547
9ebbca7d
GK
13548 At present, dwarf2out_frame_debug_expr doesn't understand
13549 register restores, so we don't bother setting RTX_FRAME_RELATED_P
13550 anywhere in the epilogue. Most of the insns below would in any case
13551 need special notes to explain where r11 is in relation to the stack. */
9878760c 13552
9ebbca7d 13553void
a2369ed3 13554rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
13555{
13556 rs6000_stack_t *info;
13557 int restoring_FPRs_inline;
13558 int using_load_multiple;
13559 int using_mfcr_multiple;
13560 int use_backchain_to_restore_sp;
13561 int sp_offset = 0;
13562 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
13563 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 13564 enum machine_mode reg_mode = Pmode;
327e5343 13565 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
13566 int i;
13567
c19de7aa
AH
13568 info = rs6000_stack_info ();
13569
13570 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13571 {
13572 reg_mode = V2SImode;
13573 reg_size = 8;
13574 }
13575
9ebbca7d 13576 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
13577 && (!TARGET_SPE_ABI
13578 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
13579 && info->first_gp_reg_save < 31);
13580 restoring_FPRs_inline = (sibcall
83720594 13581 || current_function_calls_eh_return
9ebbca7d
GK
13582 || info->first_fp_reg_save == 64
13583 || FP_SAVE_INLINE (info->first_fp_reg_save));
f676971a 13584 use_backchain_to_restore_sp = (frame_pointer_needed
9ebbca7d
GK
13585 || current_function_calls_alloca
13586 || info->total_size > 32767);
13587 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
13588 || rs6000_cpu == PROCESSOR_PPC603
13589 || rs6000_cpu == PROCESSOR_PPC750
13590 || optimize_size);
13591
d62294f5
FJ
13592 if (info->world_save_p)
13593 {
13594 int i, j;
13595 char rname[30];
13596 const char *alloc_rname;
13597 rtvec p;
13598
13599 /* eh_rest_world_r10 will return to the location saved in the LR
13600 stack slot (which is not likely to be our caller.)
13601 Input: R10 -- stack adjustment. Clobbers R0, R11, R12, R7, R8.
13602 rest_world is similar, except any R10 parameter is ignored.
13603 The exception-handling stuff that was here in 2.95 is no
13604 longer necessary. */
13605
13606 p = rtvec_alloc (9
13607 + 1
f676971a 13608 + 32 - info->first_gp_reg_save
d62294f5
FJ
13609 + LAST_ALTIVEC_REGNO + 1 - info->first_altivec_reg_save
13610 + 63 + 1 - info->first_fp_reg_save);
13611
13612 strcpy (rname, (current_function_calls_eh_return) ?
13613 "*eh_rest_world_r10" : "*rest_world");
13614 alloc_rname = ggc_strdup (rname);
13615
13616 j = 0;
13617 RTVEC_ELT (p, j++) = gen_rtx_RETURN (VOIDmode);
13618 RTVEC_ELT (p, j++) = gen_rtx_USE (VOIDmode,
13619 gen_rtx_REG (Pmode,
13620 LINK_REGISTER_REGNUM));
13621 RTVEC_ELT (p, j++)
13622 = gen_rtx_USE (VOIDmode, gen_rtx_SYMBOL_REF (Pmode, alloc_rname));
13623 /* The instruction pattern requires a clobber here;
13624 it is shared with the restVEC helper. */
13625 RTVEC_ELT (p, j++)
13626 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 11));
13627
13628 {
13629 /* CR register traditionally saved as CR2. */
13630 rtx reg = gen_rtx_REG (reg_mode, CR2_REGNO);
13631 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13632 GEN_INT (info->cr_save_offset));
13633 rtx mem = gen_rtx_MEM (reg_mode, addr);
13634 set_mem_alias_set (mem, rs6000_sr_alias_set);
13635
13636 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13637 }
13638
13639 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
13640 {
13641 rtx reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
13642 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13643 GEN_INT (info->gp_save_offset
13644 + reg_size * i));
13645 rtx mem = gen_rtx_MEM (reg_mode, addr);
13646 set_mem_alias_set (mem, rs6000_sr_alias_set);
13647
13648 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13649 }
13650 for (i = 0; info->first_altivec_reg_save + i <= LAST_ALTIVEC_REGNO; i++)
13651 {
13652 rtx reg = gen_rtx_REG (V4SImode, info->first_altivec_reg_save + i);
13653 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13654 GEN_INT (info->altivec_save_offset
13655 + 16 * i));
13656 rtx mem = gen_rtx_MEM (V4SImode, addr);
13657 set_mem_alias_set (mem, rs6000_sr_alias_set);
13658
13659 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13660 }
13661 for (i = 0; info->first_fp_reg_save + i <= 63; i++)
13662 {
13663 rtx reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
13664 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13665 GEN_INT (info->fp_save_offset
13666 + 8 * i));
13667 rtx mem = gen_rtx_MEM (DFmode, addr);
13668 set_mem_alias_set (mem, rs6000_sr_alias_set);
13669
13670 RTVEC_ELT (p, j++) = gen_rtx_SET (VOIDmode, reg, mem);
13671 }
13672 RTVEC_ELT (p, j++)
13673 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (Pmode, 0));
13674 RTVEC_ELT (p, j++)
13675 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 12));
13676 RTVEC_ELT (p, j++)
13677 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 7));
13678 RTVEC_ELT (p, j++)
13679 = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (SImode, 8));
13680 RTVEC_ELT (p, j++)
13681 = gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 10));
13682 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
13683
13684 return;
13685 }
13686
9ebbca7d
GK
13687 /* If we have a frame pointer, a call to alloca, or a large stack
13688 frame, restore the old stack pointer using the backchain. Otherwise,
13689 we know what size to update it with. */
13690 if (use_backchain_to_restore_sp)
bacbde18 13691 {
9ebbca7d
GK
13692 /* Under V.4, don't reset the stack pointer until after we're done
13693 loading the saved registers. */
f607bc57 13694 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 13695 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 13696
9ebbca7d
GK
13697 emit_move_insn (frame_reg_rtx,
13698 gen_rtx_MEM (Pmode, sp_reg_rtx));
f676971a 13699
bacbde18 13700 }
9ebbca7d 13701 else if (info->push_p)
85638c0d 13702 {
fc4767bb
JJ
13703 if (DEFAULT_ABI == ABI_V4
13704 || current_function_calls_eh_return)
9ebbca7d
GK
13705 sp_offset = info->total_size;
13706 else
13707 {
13708 emit_insn (TARGET_32BIT
13709 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
13710 GEN_INT (info->total_size))
13711 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
13712 GEN_INT (info->total_size)));
13713 }
85638c0d 13714 }
f676971a 13715
9aa86737
AH
13716 /* Restore AltiVec registers if needed. */
13717 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
13718 {
13719 int i;
13720
13721 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
13722 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
13723 {
13724 rtx addr, areg, mem;
13725
13726 areg = gen_rtx_REG (Pmode, 0);
13727 emit_move_insn
13728 (areg, GEN_INT (info->altivec_save_offset
13729 + sp_offset
13730 + 16 * (i - info->first_altivec_reg_save)));
13731
13732 /* AltiVec addressing mode is [reg+reg]. */
13733 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
13734 mem = gen_rtx_MEM (V4SImode, addr);
13735 set_mem_alias_set (mem, rs6000_sr_alias_set);
13736
13737 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
13738 }
13739 }
13740
13741 /* Restore VRSAVE if needed. */
44688022 13742 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
4d774ff8 13743 && info->vrsave_mask != 0)
9aa86737
AH
13744 {
13745 rtx addr, mem, reg;
13746
13747 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13748 GEN_INT (info->vrsave_save_offset + sp_offset));
13749 mem = gen_rtx_MEM (SImode, addr);
13750 set_mem_alias_set (mem, rs6000_sr_alias_set);
13751 reg = gen_rtx_REG (SImode, 12);
13752 emit_move_insn (reg, mem);
13753
13754 emit_insn (generate_set_vrsave (reg, info, 1));
13755 }
13756
9ebbca7d
GK
13757 /* Get the old lr if we saved it. */
13758 if (info->lr_save_p)
b6c9286a 13759 {
a3170dc6
AH
13760 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
13761 info->lr_save_offset + sp_offset);
ba4828e0
RK
13762
13763 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 13764
9ebbca7d 13765 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 13766 }
f676971a 13767
9ebbca7d
GK
13768 /* Get the old cr if we saved it. */
13769 if (info->cr_save_p)
13770 {
13771 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13772 GEN_INT (info->cr_save_offset + sp_offset));
13773 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
13774
13775 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 13776
9ebbca7d
GK
13777 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
13778 }
f676971a 13779
9ebbca7d 13780 /* Set LR here to try to overlap restores below. */
4697a36c 13781 if (info->lr_save_p)
9ebbca7d
GK
13782 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
13783 gen_rtx_REG (Pmode, 0));
f676971a 13784
83720594
RH
13785 /* Load exception handler data registers, if needed. */
13786 if (current_function_calls_eh_return)
13787 {
78e1b90d
DE
13788 unsigned int i, regno;
13789
fc4767bb
JJ
13790 if (TARGET_AIX)
13791 {
13792 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13793 GEN_INT (sp_offset + 5 * reg_size));
13794 rtx mem = gen_rtx_MEM (reg_mode, addr);
13795
13796 set_mem_alias_set (mem, rs6000_sr_alias_set);
13797
13798 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
13799 }
13800
83720594
RH
13801 for (i = 0; ; ++i)
13802 {
a3170dc6 13803 rtx mem;
83720594
RH
13804
13805 regno = EH_RETURN_DATA_REGNO (i);
13806 if (regno == INVALID_REGNUM)
13807 break;
13808
a3170dc6
AH
13809 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
13810 info->ehrd_offset + sp_offset
13811 + reg_size * (int) i);
ba4828e0 13812 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
13813
13814 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
13815 }
13816 }
f676971a 13817
9ebbca7d
GK
13818 /* Restore GPRs. This is done as a PARALLEL if we are using
13819 the load-multiple instructions. */
13820 if (using_load_multiple)
979721f8 13821 {
9ebbca7d
GK
13822 rtvec p;
13823 p = rtvec_alloc (32 - info->first_gp_reg_save);
13824 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 13825 {
f676971a
EC
13826 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13827 GEN_INT (info->gp_save_offset
13828 + sp_offset
9ebbca7d
GK
13829 + reg_size * i));
13830 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
13831
13832 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 13833
f676971a 13834 RTVEC_ELT (p, i) =
9ebbca7d
GK
13835 gen_rtx_SET (VOIDmode,
13836 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
13837 mem);
979721f8 13838 }
9ebbca7d 13839 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 13840 }
9ebbca7d
GK
13841 else
13842 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
f676971a 13843 if ((regs_ever_live[info->first_gp_reg_save+i]
b4db40bf
JJ
13844 && (! call_used_regs[info->first_gp_reg_save+i]
13845 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
13846 && TARGET_TOC && TARGET_MINIMAL_TOC)))
1db02437 13847 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 13848 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 13849 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d 13850 {
f676971a
EC
13851 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
13852 GEN_INT (info->gp_save_offset
13853 + sp_offset
9ebbca7d
GK
13854 + reg_size * i));
13855 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 13856
a3170dc6 13857 /* Restore 64-bit quantities for SPE. */
c19de7aa 13858 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
13859 {
13860 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
13861 rtx b;
13862
13863 if (!SPE_CONST_OFFSET_OK (offset))
13864 {
13865 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
13866 emit_move_insn (b, GEN_INT (offset));
13867 }
13868 else
13869 b = GEN_INT (offset);
13870
13871 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
13872 mem = gen_rtx_MEM (V2SImode, addr);
13873 }
13874
ba4828e0 13875 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 13876
f676971a 13877 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 13878 info->first_gp_reg_save + i), mem);
9ebbca7d 13879 }
9878760c 13880
9ebbca7d
GK
13881 /* Restore fpr's if we need to do it without calling a function. */
13882 if (restoring_FPRs_inline)
13883 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
f676971a 13884 if ((regs_ever_live[info->first_fp_reg_save+i]
9ebbca7d
GK
13885 && ! call_used_regs[info->first_fp_reg_save+i]))
13886 {
13887 rtx addr, mem;
13888 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
f676971a
EC
13889 GEN_INT (info->fp_save_offset
13890 + sp_offset
a4f6c312 13891 + 8 * i));
9ebbca7d 13892 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 13893 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 13894
f676971a 13895 emit_move_insn (gen_rtx_REG (DFmode,
9ebbca7d
GK
13896 info->first_fp_reg_save + i),
13897 mem);
13898 }
8d30c4ee 13899
9ebbca7d
GK
13900 /* If we saved cr, restore it here. Just those that were used. */
13901 if (info->cr_save_p)
979721f8 13902 {
9ebbca7d 13903 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 13904 int count = 0;
f676971a 13905
9ebbca7d 13906 if (using_mfcr_multiple)
979721f8 13907 {
9ebbca7d
GK
13908 for (i = 0; i < 8; i++)
13909 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 13910 count++;
9ebbca7d 13911 if (count == 0)
e35b9579
GK
13912 abort ();
13913 }
13914
13915 if (using_mfcr_multiple && count > 1)
13916 {
13917 rtvec p;
13918 int ndx;
f676971a 13919
e35b9579 13920 p = rtvec_alloc (count);
9ebbca7d 13921
e35b9579 13922 ndx = 0;
9ebbca7d
GK
13923 for (i = 0; i < 8; i++)
13924 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
13925 {
13926 rtvec r = rtvec_alloc (2);
13927 RTVEC_ELT (r, 0) = r12_rtx;
13928 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 13929 RTVEC_ELT (p, ndx) =
f676971a 13930 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 13931 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 13932 ndx++;
9ebbca7d
GK
13933 }
13934 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
13935 if (ndx != count)
13936 abort ();
979721f8
MM
13937 }
13938 else
9ebbca7d
GK
13939 for (i = 0; i < 8; i++)
13940 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 13941 {
f676971a 13942 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
9ebbca7d
GK
13943 CR0_REGNO+i),
13944 r12_rtx));
979721f8 13945 }
979721f8
MM
13946 }
13947
9ebbca7d
GK
13948 /* If this is V.4, unwind the stack pointer after all of the loads
13949 have been done. We need to emit a block here so that sched
13950 doesn't decide to move the sp change before the register restores
13951 (which may not have any obvious dependency on the stack). This
13952 doesn't hurt performance, because there is no scheduling that can
13953 be done after this point. */
fc4767bb
JJ
13954 if (DEFAULT_ABI == ABI_V4
13955 || current_function_calls_eh_return)
b6c9286a 13956 {
9ebbca7d
GK
13957 if (frame_reg_rtx != sp_reg_rtx)
13958 rs6000_emit_stack_tie ();
b6c9286a 13959
9ebbca7d 13960 if (use_backchain_to_restore_sp)
b6c9286a 13961 {
9ebbca7d 13962 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 13963 }
9ebbca7d 13964 else if (sp_offset != 0)
13f1623b 13965 {
5b71a4e7 13966 emit_insn (TARGET_32BIT
9ebbca7d
GK
13967 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
13968 GEN_INT (sp_offset))
13969 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
13970 GEN_INT (sp_offset)));
13f1623b 13971 }
9ebbca7d 13972 }
b6c9286a 13973
83720594
RH
13974 if (current_function_calls_eh_return)
13975 {
13976 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 13977 emit_insn (TARGET_32BIT
83720594
RH
13978 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
13979 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
13980 }
13981
9ebbca7d
GK
13982 if (!sibcall)
13983 {
13984 rtvec p;
13985 if (! restoring_FPRs_inline)
13986 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
13987 else
13988 p = rtvec_alloc (2);
b6c9286a 13989
e35b9579 13990 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
f676971a
EC
13991 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
13992 gen_rtx_REG (Pmode,
9ebbca7d 13993 LINK_REGISTER_REGNUM));
9ebbca7d
GK
13994
13995 /* If we have to restore more than two FP registers, branch to the
13996 restore function. It will return to our caller. */
13997 if (! restoring_FPRs_inline)
13998 {
13999 int i;
14000 char rname[30];
520a57c8 14001 const char *alloc_rname;
979721f8 14002
f676971a 14003 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
9ebbca7d 14004 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 14005 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
14006 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
14007 gen_rtx_SYMBOL_REF (Pmode,
14008 alloc_rname));
b6c9286a 14009
9ebbca7d
GK
14010 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
14011 {
14012 rtx addr, mem;
14013 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
14014 GEN_INT (info->fp_save_offset + 8*i));
14015 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 14016 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d 14017
f676971a 14018 RTVEC_ELT (p, i+3) =
9ebbca7d
GK
14019 gen_rtx_SET (VOIDmode,
14020 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
14021 mem);
b6c9286a
MM
14022 }
14023 }
f676971a 14024
9ebbca7d 14025 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 14026 }
9878760c
RK
14027}
14028
14029/* Write function epilogue. */
14030
08c148a8 14031static void
f676971a 14032rs6000_output_function_epilogue (FILE *file,
a2369ed3 14033 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 14034{
4697a36c 14035 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 14036
9ebbca7d 14037 if (! HAVE_epilogue)
9878760c 14038 {
9ebbca7d
GK
14039 rtx insn = get_last_insn ();
14040 /* If the last insn was a BARRIER, we don't have to write anything except
14041 the trace table. */
14042 if (GET_CODE (insn) == NOTE)
14043 insn = prev_nonnote_insn (insn);
14044 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 14045 {
9ebbca7d
GK
14046 /* This is slightly ugly, but at least we don't have two
14047 copies of the epilogue-emitting code. */
14048 start_sequence ();
14049
14050 /* A NOTE_INSN_DELETED is supposed to be at the start
14051 and end of the "toplevel" insn chain. */
2e040219 14052 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14053 rs6000_emit_epilogue (FALSE);
2e040219 14054 emit_note (NOTE_INSN_DELETED);
9ebbca7d 14055
a3c9585f 14056 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
14057 {
14058 rtx insn;
14059 unsigned addr = 0;
14060 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
14061 {
14062 INSN_ADDRESSES_NEW (insn, addr);
14063 addr += 4;
14064 }
14065 }
14066
9ebbca7d 14067 if (TARGET_DEBUG_STACK)
a4f6c312
SS
14068 debug_rtx_list (get_insns (), 100);
14069 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 14070 end_sequence ();
4697a36c 14071 }
9878760c 14072 }
b4ac57ab 14073
efdba735
SH
14074#if TARGET_MACHO
14075 macho_branch_islands ();
0e5da0be
GK
14076 /* Mach-O doesn't support labels at the end of objects, so if
14077 it looks like we might want one, insert a NOP. */
14078 {
14079 rtx insn = get_last_insn ();
14080 while (insn
14081 && NOTE_P (insn)
14082 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
14083 insn = PREV_INSN (insn);
f676971a
EC
14084 if (insn
14085 && (LABEL_P (insn)
0e5da0be
GK
14086 || (NOTE_P (insn)
14087 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
14088 fputs ("\tnop\n", file);
14089 }
14090#endif
14091
9b30bae2 14092 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
14093 on its format.
14094
14095 We don't output a traceback table if -finhibit-size-directive was
14096 used. The documentation for -finhibit-size-directive reads
14097 ``don't output a @code{.size} assembler directive, or anything
14098 else that would cause trouble if the function is split in the
14099 middle, and the two halves are placed at locations far apart in
14100 memory.'' The traceback table has this property, since it
14101 includes the offset from the start of the function to the
4d30c363
MM
14102 traceback table itself.
14103
14104 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 14105 different traceback table. */
57ac7be9
AM
14106 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
14107 && rs6000_traceback != traceback_none)
9b30bae2 14108 {
69c75916 14109 const char *fname = NULL;
3ac88239 14110 const char *language_string = lang_hooks.name;
6041bf2f 14111 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 14112 int i;
57ac7be9
AM
14113 int optional_tbtab;
14114
14115 if (rs6000_traceback == traceback_full)
14116 optional_tbtab = 1;
14117 else if (rs6000_traceback == traceback_part)
14118 optional_tbtab = 0;
14119 else
14120 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 14121
69c75916
AM
14122 if (optional_tbtab)
14123 {
14124 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
14125 while (*fname == '.') /* V.4 encodes . in the name */
14126 fname++;
14127
14128 /* Need label immediately before tbtab, so we can compute
14129 its offset from the function start. */
14130 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
14131 ASM_OUTPUT_LABEL (file, fname);
14132 }
314fc5a9
ILT
14133
14134 /* The .tbtab pseudo-op can only be used for the first eight
14135 expressions, since it can't handle the possibly variable
14136 length fields that follow. However, if you omit the optional
14137 fields, the assembler outputs zeros for all optional fields
14138 anyways, giving each variable length field is minimum length
14139 (as defined in sys/debug.h). Thus we can not use the .tbtab
14140 pseudo-op at all. */
14141
14142 /* An all-zero word flags the start of the tbtab, for debuggers
14143 that have to find it by searching forward from the entry
14144 point or from the current pc. */
19d2d16f 14145 fputs ("\t.long 0\n", file);
314fc5a9
ILT
14146
14147 /* Tbtab format type. Use format type 0. */
19d2d16f 14148 fputs ("\t.byte 0,", file);
314fc5a9 14149
5fc921c1
DE
14150 /* Language type. Unfortunately, there does not seem to be any
14151 official way to discover the language being compiled, so we
14152 use language_string.
14153 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
14154 Java is 13. Objective-C is 14. */
14155 if (! strcmp (language_string, "GNU C"))
314fc5a9 14156 i = 0;
6de9cd9a
DN
14157 else if (! strcmp (language_string, "GNU F77")
14158 || ! strcmp (language_string, "GNU F95"))
314fc5a9 14159 i = 1;
8b83775b 14160 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 14161 i = 2;
5fc921c1
DE
14162 else if (! strcmp (language_string, "GNU Ada"))
14163 i = 3;
314fc5a9
ILT
14164 else if (! strcmp (language_string, "GNU C++"))
14165 i = 9;
9517ead8
AG
14166 else if (! strcmp (language_string, "GNU Java"))
14167 i = 13;
5fc921c1
DE
14168 else if (! strcmp (language_string, "GNU Objective-C"))
14169 i = 14;
314fc5a9
ILT
14170 else
14171 abort ();
14172 fprintf (file, "%d,", i);
14173
14174 /* 8 single bit fields: global linkage (not set for C extern linkage,
14175 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
14176 from start of procedure stored in tbtab, internal function, function
14177 has controlled storage, function has no toc, function uses fp,
14178 function logs/aborts fp operations. */
14179 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
14180 fprintf (file, "%d,",
14181 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
14182
14183 /* 6 bitfields: function is interrupt handler, name present in
14184 proc table, function calls alloca, on condition directives
14185 (controls stack walks, 3 bits), saves condition reg, saves
14186 link reg. */
14187 /* The `function calls alloca' bit seems to be set whenever reg 31 is
14188 set up as a frame pointer, even when there is no alloca call. */
14189 fprintf (file, "%d,",
6041bf2f
DE
14190 ((optional_tbtab << 6)
14191 | ((optional_tbtab & frame_pointer_needed) << 5)
14192 | (info->cr_save_p << 1)
14193 | (info->lr_save_p)));
314fc5a9 14194
6041bf2f 14195 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
14196 (6 bits). */
14197 fprintf (file, "%d,",
4697a36c 14198 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
14199
14200 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
14201 fprintf (file, "%d,", (32 - first_reg_to_save ()));
14202
6041bf2f
DE
14203 if (optional_tbtab)
14204 {
14205 /* Compute the parameter info from the function decl argument
14206 list. */
14207 tree decl;
14208 int next_parm_info_bit = 31;
314fc5a9 14209
6041bf2f
DE
14210 for (decl = DECL_ARGUMENTS (current_function_decl);
14211 decl; decl = TREE_CHAIN (decl))
14212 {
14213 rtx parameter = DECL_INCOMING_RTL (decl);
14214 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 14215
6041bf2f
DE
14216 if (GET_CODE (parameter) == REG)
14217 {
14218 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
14219 {
14220 int bits;
14221
14222 float_parms++;
14223
14224 if (mode == SFmode)
14225 bits = 0x2;
fcce224d 14226 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
14227 bits = 0x3;
14228 else
14229 abort ();
14230
14231 /* If only one bit will fit, don't or in this entry. */
14232 if (next_parm_info_bit > 0)
14233 parm_info |= (bits << (next_parm_info_bit - 1));
14234 next_parm_info_bit -= 2;
14235 }
14236 else
14237 {
14238 fixed_parms += ((GET_MODE_SIZE (mode)
14239 + (UNITS_PER_WORD - 1))
14240 / UNITS_PER_WORD);
14241 next_parm_info_bit -= 1;
14242 }
14243 }
14244 }
14245 }
314fc5a9
ILT
14246
14247 /* Number of fixed point parameters. */
14248 /* This is actually the number of words of fixed point parameters; thus
14249 an 8 byte struct counts as 2; and thus the maximum value is 8. */
14250 fprintf (file, "%d,", fixed_parms);
14251
14252 /* 2 bitfields: number of floating point parameters (7 bits), parameters
14253 all on stack. */
14254 /* This is actually the number of fp registers that hold parameters;
14255 and thus the maximum value is 13. */
14256 /* Set parameters on stack bit if parameters are not in their original
14257 registers, regardless of whether they are on the stack? Xlc
14258 seems to set the bit when not optimizing. */
14259 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
14260
6041bf2f
DE
14261 if (! optional_tbtab)
14262 return;
14263
314fc5a9
ILT
14264 /* Optional fields follow. Some are variable length. */
14265
14266 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
14267 11 double float. */
14268 /* There is an entry for each parameter in a register, in the order that
14269 they occur in the parameter list. Any intervening arguments on the
14270 stack are ignored. If the list overflows a long (max possible length
14271 34 bits) then completely leave off all elements that don't fit. */
14272 /* Only emit this long if there was at least one parameter. */
14273 if (fixed_parms || float_parms)
14274 fprintf (file, "\t.long %d\n", parm_info);
14275
14276 /* Offset from start of code to tb table. */
19d2d16f 14277 fputs ("\t.long ", file);
314fc5a9 14278 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
85b776df
AM
14279 if (TARGET_AIX)
14280 RS6000_OUTPUT_BASENAME (file, fname);
14281 else
14282 assemble_name (file, fname);
14283 putc ('-', file);
14284 rs6000_output_function_entry (file, fname);
19d2d16f 14285 putc ('\n', file);
314fc5a9
ILT
14286
14287 /* Interrupt handler mask. */
14288 /* Omit this long, since we never set the interrupt handler bit
14289 above. */
14290
14291 /* Number of CTL (controlled storage) anchors. */
14292 /* Omit this long, since the has_ctl bit is never set above. */
14293
14294 /* Displacement into stack of each CTL anchor. */
14295 /* Omit this list of longs, because there are no CTL anchors. */
14296
14297 /* Length of function name. */
69c75916
AM
14298 if (*fname == '*')
14299 ++fname;
296b8152 14300 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
14301
14302 /* Function name. */
14303 assemble_string (fname, strlen (fname));
14304
14305 /* Register for alloca automatic storage; this is always reg 31.
14306 Only emit this if the alloca bit was set above. */
14307 if (frame_pointer_needed)
19d2d16f 14308 fputs ("\t.byte 31\n", file);
b1765bde
DE
14309
14310 fputs ("\t.align 2\n", file);
9b30bae2 14311 }
9878760c 14312}
17167fd8 14313\f
a4f6c312
SS
14314/* A C compound statement that outputs the assembler code for a thunk
14315 function, used to implement C++ virtual function calls with
14316 multiple inheritance. The thunk acts as a wrapper around a virtual
14317 function, adjusting the implicit object parameter before handing
14318 control off to the real function.
14319
14320 First, emit code to add the integer DELTA to the location that
14321 contains the incoming first argument. Assume that this argument
14322 contains a pointer, and is the one used to pass the `this' pointer
14323 in C++. This is the incoming argument *before* the function
14324 prologue, e.g. `%o0' on a sparc. The addition must preserve the
14325 values of all other incoming arguments.
17167fd8
MM
14326
14327 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
14328 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
14329 not touch the return address. Hence returning from FUNCTION will
14330 return to whoever called the current `thunk'.
17167fd8 14331
a4f6c312
SS
14332 The effect must be as if FUNCTION had been called directly with the
14333 adjusted first argument. This macro is responsible for emitting
14334 all of the code for a thunk function; output_function_prologue()
14335 and output_function_epilogue() are not invoked.
17167fd8 14336
a4f6c312
SS
14337 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
14338 been extracted from it.) It might possibly be useful on some
14339 targets, but probably not.
17167fd8 14340
a4f6c312
SS
14341 If you do not define this macro, the target-independent code in the
14342 C++ frontend will generate a less efficient heavyweight thunk that
14343 calls FUNCTION instead of jumping to it. The generic approach does
14344 not support varargs. */
17167fd8 14345
3961e8fe 14346static void
f676971a
EC
14347rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
14348 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
a2369ed3 14349 tree function)
17167fd8 14350{
5b71a4e7 14351 rtx this, insn, funexp;
17167fd8 14352
5b71a4e7 14353 reload_completed = 1;
fe3ad572 14354 epilogue_completed = 1;
5b71a4e7 14355 no_new_pseudos = 1;
6429e3be 14356 reset_block_changes ();
56a7189a 14357
5b71a4e7 14358 /* Mark the end of the (empty) prologue. */
2e040219 14359 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 14360
5b71a4e7
DE
14361 /* Find the "this" pointer. If the function returns a structure,
14362 the structure return pointer is in r3. */
61f71b34 14363 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 14364 this = gen_rtx_REG (Pmode, 4);
56a7189a 14365 else
5b71a4e7 14366 this = gen_rtx_REG (Pmode, 3);
17167fd8 14367
5b71a4e7
DE
14368 /* Apply the constant offset, if required. */
14369 if (delta)
14370 {
14371 rtx delta_rtx = GEN_INT (delta);
14372 emit_insn (TARGET_32BIT
14373 ? gen_addsi3 (this, this, delta_rtx)
14374 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
14375 }
14376
5b71a4e7
DE
14377 /* Apply the offset from the vtable, if required. */
14378 if (vcall_offset)
17167fd8 14379 {
5b71a4e7
DE
14380 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
14381 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 14382
5b71a4e7 14383 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
14384 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
14385 {
14386 emit_insn (TARGET_32BIT
14387 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
14388 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
14389 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
14390 }
14391 else
14392 {
14393 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
14394
14395 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
14396 }
5b71a4e7
DE
14397 emit_insn (TARGET_32BIT
14398 ? gen_addsi3 (this, this, tmp)
14399 : gen_adddi3 (this, this, tmp));
17167fd8
MM
14400 }
14401
5b71a4e7
DE
14402 /* Generate a tail call to the target function. */
14403 if (!TREE_USED (function))
14404 {
14405 assemble_external (function);
14406 TREE_USED (function) = 1;
14407 }
14408 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 14409 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
14410
14411#if TARGET_MACHO
ab82a49f 14412 if (MACHOPIC_INDIRECT)
5b71a4e7 14413 funexp = machopic_indirect_call_target (funexp);
ee890fe2 14414#endif
5b71a4e7
DE
14415
14416 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
14417 generate sibcall RTL explicitly to avoid constraint abort. */
14418 insn = emit_call_insn (
14419 gen_rtx_PARALLEL (VOIDmode,
14420 gen_rtvec (4,
14421 gen_rtx_CALL (VOIDmode,
14422 funexp, const0_rtx),
14423 gen_rtx_USE (VOIDmode, const0_rtx),
14424 gen_rtx_USE (VOIDmode,
14425 gen_rtx_REG (SImode,
14426 LINK_REGISTER_REGNUM)),
14427 gen_rtx_RETURN (VOIDmode))));
14428 SIBLING_CALL_P (insn) = 1;
14429 emit_barrier ();
14430
14431 /* Run just enough of rest_of_compilation to get the insns emitted.
14432 There's not really enough bulk here to make other passes such as
14433 instruction scheduling worth while. Note that use_thunk calls
14434 assemble_start_function and assemble_end_function. */
14435 insn = get_insns ();
a2855205 14436 insn_locators_initialize ();
5b71a4e7
DE
14437 shorten_branches (insn);
14438 final_start_function (insn, file, 1);
14439 final (insn, file, 1, 0);
14440 final_end_function ();
14441
14442 reload_completed = 0;
fe3ad572 14443 epilogue_completed = 0;
5b71a4e7 14444 no_new_pseudos = 0;
9ebbca7d 14445}
9ebbca7d
GK
14446\f
14447/* A quick summary of the various types of 'constant-pool tables'
14448 under PowerPC:
14449
f676971a 14450 Target Flags Name One table per
9ebbca7d
GK
14451 AIX (none) AIX TOC object file
14452 AIX -mfull-toc AIX TOC object file
14453 AIX -mminimal-toc AIX minimal TOC translation unit
14454 SVR4/EABI (none) SVR4 SDATA object file
14455 SVR4/EABI -fpic SVR4 pic object file
14456 SVR4/EABI -fPIC SVR4 PIC translation unit
14457 SVR4/EABI -mrelocatable EABI TOC function
14458 SVR4/EABI -maix AIX TOC object file
f676971a 14459 SVR4/EABI -maix -mminimal-toc
9ebbca7d
GK
14460 AIX minimal TOC translation unit
14461
14462 Name Reg. Set by entries contains:
14463 made by addrs? fp? sum?
14464
14465 AIX TOC 2 crt0 as Y option option
14466 AIX minimal TOC 30 prolog gcc Y Y option
14467 SVR4 SDATA 13 crt0 gcc N Y N
14468 SVR4 pic 30 prolog ld Y not yet N
14469 SVR4 PIC 30 prolog gcc Y option option
14470 EABI TOC 30 prolog gcc Y option option
14471
14472*/
14473
9ebbca7d
GK
14474/* Hash functions for the hash table. */
14475
14476static unsigned
a2369ed3 14477rs6000_hash_constant (rtx k)
9ebbca7d 14478{
46b33600
RH
14479 enum rtx_code code = GET_CODE (k);
14480 enum machine_mode mode = GET_MODE (k);
14481 unsigned result = (code << 3) ^ mode;
14482 const char *format;
14483 int flen, fidx;
f676971a 14484
46b33600
RH
14485 format = GET_RTX_FORMAT (code);
14486 flen = strlen (format);
14487 fidx = 0;
9ebbca7d 14488
46b33600
RH
14489 switch (code)
14490 {
14491 case LABEL_REF:
14492 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
14493
14494 case CONST_DOUBLE:
14495 if (mode != VOIDmode)
14496 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
14497 flen = 2;
14498 break;
14499
14500 case CODE_LABEL:
14501 fidx = 3;
14502 break;
14503
14504 default:
14505 break;
14506 }
9ebbca7d
GK
14507
14508 for (; fidx < flen; fidx++)
14509 switch (format[fidx])
14510 {
14511 case 's':
14512 {
14513 unsigned i, len;
14514 const char *str = XSTR (k, fidx);
14515 len = strlen (str);
14516 result = result * 613 + len;
14517 for (i = 0; i < len; i++)
14518 result = result * 613 + (unsigned) str[i];
17167fd8
MM
14519 break;
14520 }
9ebbca7d
GK
14521 case 'u':
14522 case 'e':
14523 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
14524 break;
14525 case 'i':
14526 case 'n':
14527 result = result * 613 + (unsigned) XINT (k, fidx);
14528 break;
14529 case 'w':
14530 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
14531 result = result * 613 + (unsigned) XWINT (k, fidx);
14532 else
14533 {
14534 size_t i;
14535 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
14536 result = result * 613 + (unsigned) (XWINT (k, fidx)
14537 >> CHAR_BIT * i);
14538 }
14539 break;
09501938
DE
14540 case '0':
14541 break;
9ebbca7d 14542 default:
a4f6c312 14543 abort ();
9ebbca7d 14544 }
46b33600 14545
9ebbca7d
GK
14546 return result;
14547}
14548
14549static unsigned
a2369ed3 14550toc_hash_function (const void *hash_entry)
9ebbca7d 14551{
f676971a 14552 const struct toc_hash_struct *thc =
a9098fd0
GK
14553 (const struct toc_hash_struct *) hash_entry;
14554 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
14555}
14556
14557/* Compare H1 and H2 for equivalence. */
14558
14559static int
a2369ed3 14560toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
14561{
14562 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
14563 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
14564
a9098fd0
GK
14565 if (((const struct toc_hash_struct *) h1)->key_mode
14566 != ((const struct toc_hash_struct *) h2)->key_mode)
14567 return 0;
14568
5692c7bc 14569 return rtx_equal_p (r1, r2);
9ebbca7d
GK
14570}
14571
28e510bd
MM
14572/* These are the names given by the C++ front-end to vtables, and
14573 vtable-like objects. Ideally, this logic should not be here;
14574 instead, there should be some programmatic way of inquiring as
14575 to whether or not an object is a vtable. */
14576
14577#define VTABLE_NAME_P(NAME) \
14578 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
14579 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
14580 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 14581 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
f676971a 14582 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
28e510bd
MM
14583
14584void
a2369ed3 14585rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
14586{
14587 /* Currently C++ toc references to vtables can be emitted before it
14588 is decided whether the vtable is public or private. If this is
14589 the case, then the linker will eventually complain that there is
f676971a 14590 a reference to an unknown section. Thus, for vtables only,
28e510bd
MM
14591 we emit the TOC reference to reference the symbol and not the
14592 section. */
14593 const char *name = XSTR (x, 0);
54ee9799 14594
f676971a 14595 if (VTABLE_NAME_P (name))
54ee9799
DE
14596 {
14597 RS6000_OUTPUT_BASENAME (file, name);
14598 }
14599 else
14600 assemble_name (file, name);
28e510bd
MM
14601}
14602
a4f6c312
SS
14603/* Output a TOC entry. We derive the entry name from what is being
14604 written. */
9878760c
RK
14605
14606void
a2369ed3 14607output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
14608{
14609 char buf[256];
3cce094d 14610 const char *name = buf;
ec940faa 14611 const char *real_name;
9878760c
RK
14612 rtx base = x;
14613 int offset = 0;
14614
4697a36c
MM
14615 if (TARGET_NO_TOC)
14616 abort ();
14617
9ebbca7d
GK
14618 /* When the linker won't eliminate them, don't output duplicate
14619 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
14620 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
14621 CODE_LABELs. */
14622 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
14623 {
14624 struct toc_hash_struct *h;
14625 void * * found;
f676971a 14626
17211ab5 14627 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 14628 time because GGC is not initialized at that point. */
17211ab5 14629 if (toc_hash_table == NULL)
f676971a 14630 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
17211ab5
GK
14631 toc_hash_eq, NULL);
14632
9ebbca7d
GK
14633 h = ggc_alloc (sizeof (*h));
14634 h->key = x;
a9098fd0 14635 h->key_mode = mode;
9ebbca7d 14636 h->labelno = labelno;
f676971a 14637
9ebbca7d
GK
14638 found = htab_find_slot (toc_hash_table, h, 1);
14639 if (*found == NULL)
14640 *found = h;
f676971a 14641 else /* This is indeed a duplicate.
9ebbca7d
GK
14642 Set this label equal to that label. */
14643 {
14644 fputs ("\t.set ", file);
14645 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
14646 fprintf (file, "%d,", labelno);
14647 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
f676971a 14648 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
9ebbca7d
GK
14649 found)->labelno));
14650 return;
14651 }
14652 }
14653
14654 /* If we're going to put a double constant in the TOC, make sure it's
14655 aligned properly when strict alignment is on. */
ff1720ed
RK
14656 if (GET_CODE (x) == CONST_DOUBLE
14657 && STRICT_ALIGNMENT
a9098fd0 14658 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
14659 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
14660 ASM_OUTPUT_ALIGN (file, 3);
14661 }
14662
4977bab6 14663 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 14664
37c37a57
RK
14665 /* Handle FP constants specially. Note that if we have a minimal
14666 TOC, things we put here aren't actually in the TOC, so we can allow
14667 FP constants. */
fcce224d
DE
14668 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
14669 {
14670 REAL_VALUE_TYPE rv;
14671 long k[4];
14672
14673 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
14674 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
14675
14676 if (TARGET_64BIT)
14677 {
14678 if (TARGET_MINIMAL_TOC)
14679 fputs (DOUBLE_INT_ASM_OP, file);
14680 else
14681 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
14682 k[0] & 0xffffffff, k[1] & 0xffffffff,
14683 k[2] & 0xffffffff, k[3] & 0xffffffff);
14684 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
14685 k[0] & 0xffffffff, k[1] & 0xffffffff,
14686 k[2] & 0xffffffff, k[3] & 0xffffffff);
14687 return;
14688 }
14689 else
14690 {
14691 if (TARGET_MINIMAL_TOC)
14692 fputs ("\t.long ", file);
14693 else
14694 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
14695 k[0] & 0xffffffff, k[1] & 0xffffffff,
14696 k[2] & 0xffffffff, k[3] & 0xffffffff);
14697 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
14698 k[0] & 0xffffffff, k[1] & 0xffffffff,
14699 k[2] & 0xffffffff, k[3] & 0xffffffff);
14700 return;
14701 }
14702 }
14703 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 14704 {
042259f2
DE
14705 REAL_VALUE_TYPE rv;
14706 long k[2];
0adc764e 14707
042259f2
DE
14708 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
14709 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 14710
13ded975
DE
14711 if (TARGET_64BIT)
14712 {
14713 if (TARGET_MINIMAL_TOC)
2bfcf297 14714 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 14715 else
2f0552b6
AM
14716 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
14717 k[0] & 0xffffffff, k[1] & 0xffffffff);
14718 fprintf (file, "0x%lx%08lx\n",
14719 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
14720 return;
14721 }
1875cc88 14722 else
13ded975
DE
14723 {
14724 if (TARGET_MINIMAL_TOC)
2bfcf297 14725 fputs ("\t.long ", file);
13ded975 14726 else
2f0552b6
AM
14727 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
14728 k[0] & 0xffffffff, k[1] & 0xffffffff);
14729 fprintf (file, "0x%lx,0x%lx\n",
14730 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
14731 return;
14732 }
9878760c 14733 }
a9098fd0 14734 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 14735 {
042259f2
DE
14736 REAL_VALUE_TYPE rv;
14737 long l;
9878760c 14738
042259f2
DE
14739 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
14740 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
14741
31bfaa0b
DE
14742 if (TARGET_64BIT)
14743 {
14744 if (TARGET_MINIMAL_TOC)
2bfcf297 14745 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 14746 else
2f0552b6
AM
14747 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
14748 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
14749 return;
14750 }
042259f2 14751 else
31bfaa0b
DE
14752 {
14753 if (TARGET_MINIMAL_TOC)
2bfcf297 14754 fputs ("\t.long ", file);
31bfaa0b 14755 else
2f0552b6
AM
14756 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
14757 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
14758 return;
14759 }
042259f2 14760 }
f176e826 14761 else if (GET_MODE (x) == VOIDmode
a9098fd0 14762 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 14763 {
e2c953b6 14764 unsigned HOST_WIDE_INT low;
042259f2
DE
14765 HOST_WIDE_INT high;
14766
14767 if (GET_CODE (x) == CONST_DOUBLE)
14768 {
14769 low = CONST_DOUBLE_LOW (x);
14770 high = CONST_DOUBLE_HIGH (x);
14771 }
14772 else
14773#if HOST_BITS_PER_WIDE_INT == 32
14774 {
14775 low = INTVAL (x);
0858c623 14776 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
14777 }
14778#else
14779 {
0858c623 14780 low = INTVAL (x) & 0xffffffff;
042259f2
DE
14781 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
14782 }
14783#endif
9878760c 14784
a9098fd0
GK
14785 /* TOC entries are always Pmode-sized, but since this
14786 is a bigendian machine then if we're putting smaller
14787 integer constants in the TOC we have to pad them.
14788 (This is still a win over putting the constants in
14789 a separate constant pool, because then we'd have
02a4ec28
FS
14790 to have both a TOC entry _and_ the actual constant.)
14791
14792 For a 32-bit target, CONST_INT values are loaded and shifted
14793 entirely within `low' and can be stored in one TOC entry. */
14794
14795 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 14796 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
14797
14798 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
14799 {
14800#if HOST_BITS_PER_WIDE_INT == 32
14801 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
14802 POINTER_SIZE, &low, &high, 0);
14803#else
14804 low |= high << 32;
14805 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
14806 high = (HOST_WIDE_INT) low >> 32;
14807 low &= 0xffffffff;
14808#endif
14809 }
a9098fd0 14810
13ded975
DE
14811 if (TARGET_64BIT)
14812 {
14813 if (TARGET_MINIMAL_TOC)
2bfcf297 14814 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 14815 else
2f0552b6
AM
14816 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
14817 (long) high & 0xffffffff, (long) low & 0xffffffff);
14818 fprintf (file, "0x%lx%08lx\n",
14819 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
14820 return;
14821 }
1875cc88 14822 else
13ded975 14823 {
02a4ec28
FS
14824 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
14825 {
14826 if (TARGET_MINIMAL_TOC)
2bfcf297 14827 fputs ("\t.long ", file);
02a4ec28 14828 else
2bfcf297 14829 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
14830 (long) high & 0xffffffff, (long) low & 0xffffffff);
14831 fprintf (file, "0x%lx,0x%lx\n",
14832 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 14833 }
13ded975 14834 else
02a4ec28
FS
14835 {
14836 if (TARGET_MINIMAL_TOC)
2bfcf297 14837 fputs ("\t.long ", file);
02a4ec28 14838 else
2f0552b6
AM
14839 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
14840 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 14841 }
13ded975
DE
14842 return;
14843 }
9878760c
RK
14844 }
14845
14846 if (GET_CODE (x) == CONST)
14847 {
2bfcf297
DB
14848 if (GET_CODE (XEXP (x, 0)) != PLUS)
14849 abort ();
14850
9878760c
RK
14851 base = XEXP (XEXP (x, 0), 0);
14852 offset = INTVAL (XEXP (XEXP (x, 0), 1));
14853 }
f676971a 14854
9878760c
RK
14855 if (GET_CODE (base) == SYMBOL_REF)
14856 name = XSTR (base, 0);
14857 else if (GET_CODE (base) == LABEL_REF)
14858 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
14859 else if (GET_CODE (base) == CODE_LABEL)
14860 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
14861 else
14862 abort ();
14863
772c5265 14864 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 14865 if (TARGET_MINIMAL_TOC)
2bfcf297 14866 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
14867 else
14868 {
b6c9286a 14869 fprintf (file, "\t.tc %s", real_name);
9878760c 14870
1875cc88
JW
14871 if (offset < 0)
14872 fprintf (file, ".N%d", - offset);
14873 else if (offset)
14874 fprintf (file, ".P%d", offset);
9878760c 14875
19d2d16f 14876 fputs ("[TC],", file);
1875cc88 14877 }
581bc4de
MM
14878
14879 /* Currently C++ toc references to vtables can be emitted before it
14880 is decided whether the vtable is public or private. If this is
14881 the case, then the linker will eventually complain that there is
14882 a TOC reference to an unknown section. Thus, for vtables only,
14883 we emit the TOC reference to reference the symbol and not the
14884 section. */
28e510bd 14885 if (VTABLE_NAME_P (name))
581bc4de 14886 {
54ee9799 14887 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
14888 if (offset < 0)
14889 fprintf (file, "%d", offset);
14890 else if (offset > 0)
14891 fprintf (file, "+%d", offset);
14892 }
14893 else
14894 output_addr_const (file, x);
19d2d16f 14895 putc ('\n', file);
9878760c
RK
14896}
14897\f
14898/* Output an assembler pseudo-op to write an ASCII string of N characters
14899 starting at P to FILE.
14900
14901 On the RS/6000, we have to do this using the .byte operation and
14902 write out special characters outside the quoted string.
14903 Also, the assembler is broken; very long strings are truncated,
a4f6c312 14904 so we must artificially break them up early. */
9878760c
RK
14905
14906void
a2369ed3 14907output_ascii (FILE *file, const char *p, int n)
9878760c
RK
14908{
14909 char c;
14910 int i, count_string;
d330fd93
KG
14911 const char *for_string = "\t.byte \"";
14912 const char *for_decimal = "\t.byte ";
14913 const char *to_close = NULL;
9878760c
RK
14914
14915 count_string = 0;
14916 for (i = 0; i < n; i++)
14917 {
14918 c = *p++;
14919 if (c >= ' ' && c < 0177)
14920 {
14921 if (for_string)
14922 fputs (for_string, file);
14923 putc (c, file);
14924
14925 /* Write two quotes to get one. */
14926 if (c == '"')
14927 {
14928 putc (c, file);
14929 ++count_string;
14930 }
14931
14932 for_string = NULL;
14933 for_decimal = "\"\n\t.byte ";
14934 to_close = "\"\n";
14935 ++count_string;
14936
14937 if (count_string >= 512)
14938 {
14939 fputs (to_close, file);
14940
14941 for_string = "\t.byte \"";
14942 for_decimal = "\t.byte ";
14943 to_close = NULL;
14944 count_string = 0;
14945 }
14946 }
14947 else
14948 {
14949 if (for_decimal)
14950 fputs (for_decimal, file);
14951 fprintf (file, "%d", c);
14952
14953 for_string = "\n\t.byte \"";
14954 for_decimal = ", ";
14955 to_close = "\n";
14956 count_string = 0;
14957 }
14958 }
14959
14960 /* Now close the string if we have written one. Then end the line. */
14961 if (to_close)
9ebbca7d 14962 fputs (to_close, file);
9878760c
RK
14963}
14964\f
14965/* Generate a unique section name for FILENAME for a section type
14966 represented by SECTION_DESC. Output goes into BUF.
14967
14968 SECTION_DESC can be any string, as long as it is different for each
14969 possible section type.
14970
14971 We name the section in the same manner as xlc. The name begins with an
14972 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
14973 names) with the last period replaced by the string SECTION_DESC. If
14974 FILENAME does not contain a period, SECTION_DESC is appended to the end of
14975 the name. */
9878760c
RK
14976
14977void
f676971a 14978rs6000_gen_section_name (char **buf, const char *filename,
a2369ed3 14979 const char *section_desc)
9878760c 14980{
9ebbca7d 14981 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
14982 char *p;
14983 int len;
9878760c
RK
14984
14985 after_last_slash = filename;
14986 for (q = filename; *q; q++)
11e5fe42
RK
14987 {
14988 if (*q == '/')
14989 after_last_slash = q + 1;
14990 else if (*q == '.')
14991 last_period = q;
14992 }
9878760c 14993
11e5fe42 14994 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 14995 *buf = (char *) xmalloc (len);
9878760c
RK
14996
14997 p = *buf;
14998 *p++ = '_';
14999
15000 for (q = after_last_slash; *q; q++)
15001 {
11e5fe42 15002 if (q == last_period)
9878760c
RK
15003 {
15004 strcpy (p, section_desc);
15005 p += strlen (section_desc);
e3981aab 15006 break;
9878760c
RK
15007 }
15008
e9a780ec 15009 else if (ISALNUM (*q))
9878760c
RK
15010 *p++ = *q;
15011 }
15012
11e5fe42 15013 if (last_period == 0)
9878760c
RK
15014 strcpy (p, section_desc);
15015 else
15016 *p = '\0';
15017}
e165f3f0 15018\f
a4f6c312 15019/* Emit profile function. */
411707f4 15020
411707f4 15021void
a2369ed3 15022output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 15023{
ffcfcb5f
AM
15024 if (TARGET_PROFILE_KERNEL)
15025 return;
15026
8480e480
CC
15027 if (DEFAULT_ABI == ABI_AIX)
15028 {
9739c90c
JJ
15029#ifndef NO_PROFILE_COUNTERS
15030# define NO_PROFILE_COUNTERS 0
15031#endif
f676971a 15032 if (NO_PROFILE_COUNTERS)
9739c90c
JJ
15033 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
15034 else
15035 {
15036 char buf[30];
15037 const char *label_name;
15038 rtx fun;
411707f4 15039
9739c90c
JJ
15040 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
15041 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
15042 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 15043
9739c90c
JJ
15044 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
15045 fun, Pmode);
15046 }
8480e480 15047 }
ee890fe2
SS
15048 else if (DEFAULT_ABI == ABI_DARWIN)
15049 {
d5fa86ba 15050 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
15051 int caller_addr_regno = LINK_REGISTER_REGNUM;
15052
15053 /* Be conservative and always set this, at least for now. */
15054 current_function_uses_pic_offset_table = 1;
15055
15056#if TARGET_MACHO
15057 /* For PIC code, set up a stub and collect the caller's address
15058 from r0, which is where the prologue puts it. */
11abc112
MM
15059 if (MACHOPIC_INDIRECT
15060 && current_function_uses_pic_offset_table)
15061 caller_addr_regno = 0;
ee890fe2
SS
15062#endif
15063 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
15064 0, VOIDmode, 1,
15065 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
15066 }
411707f4
CC
15067}
15068
a4f6c312 15069/* Write function profiler code. */
e165f3f0
RK
15070
15071void
a2369ed3 15072output_function_profiler (FILE *file, int labelno)
e165f3f0 15073{
3daf36a4 15074 char buf[100];
09eeeacb 15075 int save_lr = 8;
e165f3f0 15076
38c1f2d7 15077 switch (DEFAULT_ABI)
3daf36a4 15078 {
38c1f2d7
MM
15079 default:
15080 abort ();
15081
15082 case ABI_V4:
09eeeacb 15083 save_lr = 4;
09eeeacb
AM
15084 if (!TARGET_32BIT)
15085 {
15086 warning ("no profiling of 64-bit code for this ABI");
15087 return;
15088 }
ffcfcb5f 15089 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
15090 fprintf (file, "\tmflr %s\n", reg_names[0]);
15091 if (flag_pic == 1)
15092 {
dfdfa60f 15093 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
15094 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15095 reg_names[0], save_lr, reg_names[1]);
17167fd8 15096 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 15097 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 15098 assemble_name (file, buf);
17167fd8 15099 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 15100 }
9ebbca7d 15101 else if (flag_pic > 1)
38c1f2d7 15102 {
09eeeacb
AM
15103 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15104 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
15105 /* Now, we need to get the address of the label. */
15106 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 15107 assemble_name (file, buf);
9ebbca7d
GK
15108 fputs ("-.\n1:", file);
15109 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
f676971a 15110 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
9ebbca7d
GK
15111 reg_names[0], reg_names[11]);
15112 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
15113 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 15114 }
38c1f2d7
MM
15115 else
15116 {
17167fd8 15117 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 15118 assemble_name (file, buf);
dfdfa60f 15119 fputs ("@ha\n", file);
09eeeacb
AM
15120 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
15121 reg_names[0], save_lr, reg_names[1]);
a260abc9 15122 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 15123 assemble_name (file, buf);
17167fd8 15124 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
15125 }
15126
50d440bc 15127 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
15128 fprintf (file, "\tbl %s%s\n",
15129 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
15130 break;
15131
15132 case ABI_AIX:
ee890fe2 15133 case ABI_DARWIN:
ffcfcb5f
AM
15134 if (!TARGET_PROFILE_KERNEL)
15135 {
a3c9585f 15136 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
15137 }
15138 else
15139 {
15140 if (TARGET_32BIT)
15141 abort ();
15142
15143 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
15144 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
15145
6de9cd9a 15146 if (cfun->static_chain_decl != NULL)
ffcfcb5f
AM
15147 {
15148 asm_fprintf (file, "\tstd %s,24(%s)\n",
15149 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15150 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15151 asm_fprintf (file, "\tld %s,24(%s)\n",
15152 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
15153 }
15154 else
15155 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
15156 }
38c1f2d7
MM
15157 break;
15158 }
e165f3f0 15159}
a251ffd0 15160
b54cf83a 15161\f
b54cf83a
DE
15162/* Power4 load update and store update instructions are cracked into a
15163 load or store and an integer insn which are executed in the same cycle.
15164 Branches have their own dispatch slot which does not count against the
15165 GCC issue rate, but it changes the program flow so there are no other
15166 instructions to issue in this cycle. */
15167
15168static int
f676971a
EC
15169rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
15170 int verbose ATTRIBUTE_UNUSED,
a2369ed3 15171 rtx insn, int more)
b54cf83a
DE
15172{
15173 if (GET_CODE (PATTERN (insn)) == USE
15174 || GET_CODE (PATTERN (insn)) == CLOBBER)
15175 return more;
15176
ec507f2d 15177 if (rs6000_sched_groups)
b54cf83a 15178 {
cbe26ab8
DN
15179 if (is_microcoded_insn (insn))
15180 return 0;
15181 else if (is_cracked_insn (insn))
15182 return more > 2 ? more - 2 : 0;
b54cf83a 15183 }
165b263e
DE
15184
15185 return more - 1;
b54cf83a
DE
15186}
15187
a251ffd0
TG
15188/* Adjust the cost of a scheduling dependency. Return the new cost of
15189 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
15190
c237e94a 15191static int
f676971a 15192rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
a2369ed3 15193 int cost)
a251ffd0
TG
15194{
15195 if (! recog_memoized (insn))
15196 return 0;
15197
15198 if (REG_NOTE_KIND (link) != 0)
15199 return 0;
15200
15201 if (REG_NOTE_KIND (link) == 0)
15202 {
ed947a96
DJ
15203 /* Data dependency; DEP_INSN writes a register that INSN reads
15204 some cycles later. */
15205 switch (get_attr_type (insn))
15206 {
15207 case TYPE_JMPREG:
309323c2 15208 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
15209 a mtctr and bctr (and mtlr and br/blr). The first
15210 scheduling pass will not know about this latency since
15211 the mtctr instruction, which has the latency associated
15212 to it, will be generated by reload. */
309323c2 15213 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
15214 case TYPE_BRANCH:
15215 /* Leave some extra cycles between a compare and its
15216 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
15217 if ((rs6000_cpu_attr == CPU_PPC603
15218 || rs6000_cpu_attr == CPU_PPC604
15219 || rs6000_cpu_attr == CPU_PPC604E
15220 || rs6000_cpu_attr == CPU_PPC620
15221 || rs6000_cpu_attr == CPU_PPC630
15222 || rs6000_cpu_attr == CPU_PPC750
15223 || rs6000_cpu_attr == CPU_PPC7400
15224 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
15225 || rs6000_cpu_attr == CPU_POWER4
15226 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
15227 && recog_memoized (dep_insn)
15228 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
15229 && (get_attr_type (dep_insn) == TYPE_CMP
15230 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 15231 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
15232 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
15233 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 15234 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
15235 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
15236 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
15237 return cost + 2;
15238 default:
15239 break;
15240 }
a251ffd0
TG
15241 /* Fall out to return default cost. */
15242 }
15243
15244 return cost;
15245}
b6c9286a 15246
cbe26ab8 15247/* The function returns a true if INSN is microcoded.
839a4992 15248 Return false otherwise. */
cbe26ab8
DN
15249
15250static bool
15251is_microcoded_insn (rtx insn)
15252{
15253 if (!insn || !INSN_P (insn)
15254 || GET_CODE (PATTERN (insn)) == USE
15255 || GET_CODE (PATTERN (insn)) == CLOBBER)
15256 return false;
15257
ec507f2d 15258 if (rs6000_sched_groups)
cbe26ab8
DN
15259 {
15260 enum attr_type type = get_attr_type (insn);
15261 if (type == TYPE_LOAD_EXT_U
15262 || type == TYPE_LOAD_EXT_UX
15263 || type == TYPE_LOAD_UX
15264 || type == TYPE_STORE_UX
15265 || type == TYPE_MFCR)
15266 return true;
15267 }
15268
15269 return false;
15270}
15271
5c425df5 15272/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
15273 as the first insn in a dispatch group ("dispatch-slot restricted").
15274 In this case, the returned value indicates how many dispatch slots
15275 the insn occupies (at the beginning of the group).
79ae11c4
DN
15276 Return 0 otherwise. */
15277
cbe26ab8 15278static int
79ae11c4
DN
15279is_dispatch_slot_restricted (rtx insn)
15280{
15281 enum attr_type type;
15282
ec507f2d 15283 if (!rs6000_sched_groups)
79ae11c4
DN
15284 return 0;
15285
15286 if (!insn
15287 || insn == NULL_RTX
15288 || GET_CODE (insn) == NOTE
15289 || GET_CODE (PATTERN (insn)) == USE
15290 || GET_CODE (PATTERN (insn)) == CLOBBER)
15291 return 0;
15292
15293 type = get_attr_type (insn);
15294
ec507f2d
DE
15295 switch (type)
15296 {
15297 case TYPE_MFCR:
15298 case TYPE_MFCRF:
15299 case TYPE_MTCR:
15300 case TYPE_DELAYED_CR:
15301 case TYPE_CR_LOGICAL:
15302 case TYPE_MTJMPR:
15303 case TYPE_MFJMPR:
15304 return 1;
15305 case TYPE_IDIV:
15306 case TYPE_LDIV:
15307 return 2;
15308 default:
15309 if (rs6000_cpu == PROCESSOR_POWER5
15310 && is_cracked_insn (insn))
15311 return 2;
15312 return 0;
15313 }
79ae11c4
DN
15314}
15315
cbe26ab8
DN
15316/* The function returns true if INSN is cracked into 2 instructions
15317 by the processor (and therefore occupies 2 issue slots). */
15318
15319static bool
15320is_cracked_insn (rtx insn)
15321{
15322 if (!insn || !INSN_P (insn)
15323 || GET_CODE (PATTERN (insn)) == USE
15324 || GET_CODE (PATTERN (insn)) == CLOBBER)
15325 return false;
15326
ec507f2d 15327 if (rs6000_sched_groups)
cbe26ab8
DN
15328 {
15329 enum attr_type type = get_attr_type (insn);
15330 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
15331 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
15332 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
15333 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
15334 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
15335 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
15336 || type == TYPE_IDIV || type == TYPE_LDIV
15337 || type == TYPE_INSERT_WORD)
15338 return true;
15339 }
15340
15341 return false;
15342}
15343
15344/* The function returns true if INSN can be issued only from
a3c9585f 15345 the branch slot. */
cbe26ab8
DN
15346
15347static bool
15348is_branch_slot_insn (rtx insn)
15349{
15350 if (!insn || !INSN_P (insn)
15351 || GET_CODE (PATTERN (insn)) == USE
15352 || GET_CODE (PATTERN (insn)) == CLOBBER)
15353 return false;
15354
ec507f2d 15355 if (rs6000_sched_groups)
cbe26ab8
DN
15356 {
15357 enum attr_type type = get_attr_type (insn);
15358 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
f676971a 15359 return true;
cbe26ab8
DN
15360 return false;
15361 }
15362
15363 return false;
15364}
79ae11c4 15365
a4f6c312 15366/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
15367 priority INSN_PRIORITY (INSN). Increase the priority to execute the
15368 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
15369 define this macro if you do not need to adjust the scheduling
15370 priorities of insns. */
bef84347 15371
c237e94a 15372static int
a2369ed3 15373rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 15374{
a4f6c312
SS
15375 /* On machines (like the 750) which have asymmetric integer units,
15376 where one integer unit can do multiply and divides and the other
15377 can't, reduce the priority of multiply/divide so it is scheduled
15378 before other integer operations. */
bef84347
VM
15379
15380#if 0
2c3c49de 15381 if (! INSN_P (insn))
bef84347
VM
15382 return priority;
15383
15384 if (GET_CODE (PATTERN (insn)) == USE)
15385 return priority;
15386
15387 switch (rs6000_cpu_attr) {
15388 case CPU_PPC750:
15389 switch (get_attr_type (insn))
15390 {
15391 default:
15392 break;
15393
15394 case TYPE_IMUL:
15395 case TYPE_IDIV:
3cb999d8
DE
15396 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
15397 priority, priority);
bef84347
VM
15398 if (priority >= 0 && priority < 0x01000000)
15399 priority >>= 3;
15400 break;
15401 }
15402 }
15403#endif
15404
79ae11c4
DN
15405 if (is_dispatch_slot_restricted (insn)
15406 && reload_completed
f676971a 15407 && current_sched_info->sched_max_insns_priority
79ae11c4
DN
15408 && rs6000_sched_restricted_insns_priority)
15409 {
15410
15411 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
15412 if (rs6000_sched_restricted_insns_priority == 1)
f676971a
EC
15413 /* Attach highest priority to insn. This means that in
15414 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
79ae11c4 15415 precede 'priority' (critical path) considerations. */
f676971a 15416 return current_sched_info->sched_max_insns_priority;
79ae11c4 15417 else if (rs6000_sched_restricted_insns_priority == 2)
f676971a 15418 /* Increase priority of insn by a minimal amount. This means that in
79ae11c4
DN
15419 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
15420 precede dispatch-slot restriction considerations. */
f676971a
EC
15421 return (priority + 1);
15422 }
79ae11c4 15423
bef84347
VM
15424 return priority;
15425}
15426
a4f6c312
SS
15427/* Return how many instructions the machine can issue per cycle. */
15428
c237e94a 15429static int
863d938c 15430rs6000_issue_rate (void)
b6c9286a 15431{
3317bab1
DE
15432 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
15433 if (!reload_completed)
15434 return 1;
15435
b6c9286a 15436 switch (rs6000_cpu_attr) {
3cb999d8
DE
15437 case CPU_RIOS1: /* ? */
15438 case CPU_RS64A:
15439 case CPU_PPC601: /* ? */
ed947a96 15440 case CPU_PPC7450:
3cb999d8 15441 return 3;
b54cf83a 15442 case CPU_PPC440:
b6c9286a 15443 case CPU_PPC603:
bef84347 15444 case CPU_PPC750:
ed947a96 15445 case CPU_PPC7400:
be12c2b0 15446 case CPU_PPC8540:
f676971a 15447 return 2;
3cb999d8 15448 case CPU_RIOS2:
b6c9286a 15449 case CPU_PPC604:
19684119 15450 case CPU_PPC604E:
b6c9286a 15451 case CPU_PPC620:
3cb999d8 15452 case CPU_PPC630:
b6c9286a 15453 return 4;
cbe26ab8 15454 case CPU_POWER4:
ec507f2d 15455 case CPU_POWER5:
cbe26ab8 15456 return 5;
b6c9286a
MM
15457 default:
15458 return 1;
15459 }
15460}
15461
be12c2b0
VM
15462/* Return how many instructions to look ahead for better insn
15463 scheduling. */
15464
15465static int
863d938c 15466rs6000_use_sched_lookahead (void)
be12c2b0
VM
15467{
15468 if (rs6000_cpu_attr == CPU_PPC8540)
15469 return 4;
15470 return 0;
15471}
15472
569fa502
DN
15473/* Determine is PAT refers to memory. */
15474
15475static bool
15476is_mem_ref (rtx pat)
15477{
15478 const char * fmt;
15479 int i, j;
15480 bool ret = false;
15481
15482 if (GET_CODE (pat) == MEM)
15483 return true;
15484
15485 /* Recursively process the pattern. */
15486 fmt = GET_RTX_FORMAT (GET_CODE (pat));
15487
15488 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
15489 {
15490 if (fmt[i] == 'e')
15491 ret |= is_mem_ref (XEXP (pat, i));
15492 else if (fmt[i] == 'E')
15493 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
15494 ret |= is_mem_ref (XVECEXP (pat, i, j));
15495 }
15496
15497 return ret;
15498}
15499
15500/* Determine if PAT is a PATTERN of a load insn. */
f676971a 15501
569fa502
DN
15502static bool
15503is_load_insn1 (rtx pat)
15504{
15505 if (!pat || pat == NULL_RTX)
15506 return false;
15507
15508 if (GET_CODE (pat) == SET)
15509 return is_mem_ref (SET_SRC (pat));
15510
15511 if (GET_CODE (pat) == PARALLEL)
15512 {
15513 int i;
15514
15515 for (i = 0; i < XVECLEN (pat, 0); i++)
15516 if (is_load_insn1 (XVECEXP (pat, 0, i)))
15517 return true;
15518 }
15519
15520 return false;
15521}
15522
15523/* Determine if INSN loads from memory. */
15524
15525static bool
15526is_load_insn (rtx insn)
15527{
15528 if (!insn || !INSN_P (insn))
15529 return false;
15530
15531 if (GET_CODE (insn) == CALL_INSN)
15532 return false;
15533
15534 return is_load_insn1 (PATTERN (insn));
15535}
15536
15537/* Determine if PAT is a PATTERN of a store insn. */
15538
15539static bool
15540is_store_insn1 (rtx pat)
15541{
15542 if (!pat || pat == NULL_RTX)
15543 return false;
15544
15545 if (GET_CODE (pat) == SET)
15546 return is_mem_ref (SET_DEST (pat));
15547
15548 if (GET_CODE (pat) == PARALLEL)
15549 {
15550 int i;
15551
15552 for (i = 0; i < XVECLEN (pat, 0); i++)
15553 if (is_store_insn1 (XVECEXP (pat, 0, i)))
15554 return true;
15555 }
15556
15557 return false;
15558}
15559
15560/* Determine if INSN stores to memory. */
15561
15562static bool
15563is_store_insn (rtx insn)
15564{
15565 if (!insn || !INSN_P (insn))
15566 return false;
15567
15568 return is_store_insn1 (PATTERN (insn));
15569}
15570
15571/* Returns whether the dependence between INSN and NEXT is considered
15572 costly by the given target. */
15573
15574static bool
15575rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
f676971a 15576{
569fa502 15577 /* If the flag is not enbled - no dependence is considered costly;
f676971a 15578 allow all dependent insns in the same group.
569fa502
DN
15579 This is the most aggressive option. */
15580 if (rs6000_sched_costly_dep == no_dep_costly)
15581 return false;
15582
f676971a 15583 /* If the flag is set to 1 - a dependence is always considered costly;
569fa502
DN
15584 do not allow dependent instructions in the same group.
15585 This is the most conservative option. */
15586 if (rs6000_sched_costly_dep == all_deps_costly)
f676971a 15587 return true;
569fa502 15588
f676971a
EC
15589 if (rs6000_sched_costly_dep == store_to_load_dep_costly
15590 && is_load_insn (next)
569fa502
DN
15591 && is_store_insn (insn))
15592 /* Prevent load after store in the same group. */
15593 return true;
15594
15595 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
f676971a 15596 && is_load_insn (next)
569fa502
DN
15597 && is_store_insn (insn)
15598 && (!link || (int) REG_NOTE_KIND (link) == 0))
15599 /* Prevent load after store in the same group if it is a true dependence. */
15600 return true;
f676971a
EC
15601
15602 /* The flag is set to X; dependences with latency >= X are considered costly,
569fa502
DN
15603 and will not be scheduled in the same group. */
15604 if (rs6000_sched_costly_dep <= max_dep_latency
15605 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
15606 return true;
15607
15608 return false;
15609}
15610
f676971a 15611/* Return the next insn after INSN that is found before TAIL is reached,
cbe26ab8
DN
15612 skipping any "non-active" insns - insns that will not actually occupy
15613 an issue slot. Return NULL_RTX if such an insn is not found. */
15614
15615static rtx
15616get_next_active_insn (rtx insn, rtx tail)
15617{
15618 rtx next_insn;
15619
15620 if (!insn || insn == tail)
15621 return NULL_RTX;
15622
15623 next_insn = NEXT_INSN (insn);
15624
15625 while (next_insn
15626 && next_insn != tail
15627 && (GET_CODE(next_insn) == NOTE
15628 || GET_CODE (PATTERN (next_insn)) == USE
15629 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
15630 {
15631 next_insn = NEXT_INSN (next_insn);
15632 }
15633
15634 if (!next_insn || next_insn == tail)
15635 return NULL_RTX;
15636
15637 return next_insn;
15638}
15639
839a4992 15640/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
15641 of group WHICH_GROUP.
15642
15643 If WHICH_GROUP == current_group, this function will return true if INSN
15644 causes the termination of the current group (i.e, the dispatch group to
15645 which INSN belongs). This means that INSN will be the last insn in the
15646 group it belongs to.
15647
15648 If WHICH_GROUP == previous_group, this function will return true if INSN
15649 causes the termination of the previous group (i.e, the dispatch group that
15650 precedes the group to which INSN belongs). This means that INSN will be
15651 the first insn in the group it belongs to). */
15652
15653static bool
15654insn_terminates_group_p (rtx insn, enum group_termination which_group)
15655{
15656 enum attr_type type;
15657
15658 if (! insn)
15659 return false;
569fa502 15660
cbe26ab8
DN
15661 type = get_attr_type (insn);
15662
15663 if (is_microcoded_insn (insn))
15664 return true;
15665
15666 if (which_group == current_group)
15667 {
15668 if (is_branch_slot_insn (insn))
15669 return true;
15670 return false;
15671 }
15672 else if (which_group == previous_group)
15673 {
15674 if (is_dispatch_slot_restricted (insn))
15675 return true;
15676 return false;
15677 }
15678
15679 return false;
15680}
15681
839a4992 15682/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
15683 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
15684
15685static bool
15686is_costly_group (rtx *group_insns, rtx next_insn)
15687{
15688 int i;
15689 rtx link;
15690 int cost;
15691 int issue_rate = rs6000_issue_rate ();
15692
15693 for (i = 0; i < issue_rate; i++)
15694 {
15695 rtx insn = group_insns[i];
15696 if (!insn)
15697 continue;
15698 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
15699 {
15700 rtx next = XEXP (link, 0);
15701 if (next == next_insn)
15702 {
15703 cost = insn_cost (insn, link, next_insn);
15704 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
15705 return true;
15706 }
15707 }
15708 }
15709
15710 return false;
15711}
15712
f676971a 15713/* Utility of the function redefine_groups.
cbe26ab8
DN
15714 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
15715 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
15716 to keep it "far" (in a separate group) from GROUP_INSNS, following
15717 one of the following schemes, depending on the value of the flag
15718 -minsert_sched_nops = X:
15719 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 15720 in order to force NEXT_INSN into a separate group.
f676971a
EC
15721 (2) X < sched_finish_regroup_exact: insert exactly X nops.
15722 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
cbe26ab8
DN
15723 insertion (has a group just ended, how many vacant issue slots remain in the
15724 last group, and how many dispatch groups were encountered so far). */
15725
f676971a 15726static int
cbe26ab8
DN
15727force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
15728 bool *group_end, int can_issue_more, int *group_count)
15729{
15730 rtx nop;
15731 bool force;
15732 int issue_rate = rs6000_issue_rate ();
15733 bool end = *group_end;
15734 int i;
15735
15736 if (next_insn == NULL_RTX)
15737 return can_issue_more;
15738
15739 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
15740 return can_issue_more;
15741
15742 force = is_costly_group (group_insns, next_insn);
15743 if (!force)
15744 return can_issue_more;
15745
15746 if (sched_verbose > 6)
15747 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
15748 *group_count ,can_issue_more);
15749
15750 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
15751 {
15752 if (*group_end)
15753 can_issue_more = 0;
15754
15755 /* Since only a branch can be issued in the last issue_slot, it is
15756 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
15757 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
15758 in this case the last nop will start a new group and the branch will be
15759 forced to the new group. */
15760 if (can_issue_more && !is_branch_slot_insn (next_insn))
15761 can_issue_more--;
15762
15763 while (can_issue_more > 0)
15764 {
15765 nop = gen_nop();
15766 emit_insn_before (nop, next_insn);
15767 can_issue_more--;
15768 }
15769
15770 *group_end = true;
15771 return 0;
f676971a 15772 }
cbe26ab8
DN
15773
15774 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
15775 {
15776 int n_nops = rs6000_sched_insert_nops;
15777
f676971a 15778 /* Nops can't be issued from the branch slot, so the effective
cbe26ab8
DN
15779 issue_rate for nops is 'issue_rate - 1'. */
15780 if (can_issue_more == 0)
15781 can_issue_more = issue_rate;
15782 can_issue_more--;
15783 if (can_issue_more == 0)
15784 {
15785 can_issue_more = issue_rate - 1;
15786 (*group_count)++;
15787 end = true;
15788 for (i = 0; i < issue_rate; i++)
15789 {
15790 group_insns[i] = 0;
15791 }
15792 }
15793
15794 while (n_nops > 0)
15795 {
15796 nop = gen_nop ();
15797 emit_insn_before (nop, next_insn);
15798 if (can_issue_more == issue_rate - 1) /* new group begins */
15799 end = false;
15800 can_issue_more--;
15801 if (can_issue_more == 0)
15802 {
15803 can_issue_more = issue_rate - 1;
15804 (*group_count)++;
15805 end = true;
15806 for (i = 0; i < issue_rate; i++)
15807 {
15808 group_insns[i] = 0;
f676971a
EC
15809 }
15810 }
cbe26ab8
DN
15811 n_nops--;
15812 }
15813
15814 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
f676971a 15815 can_issue_more++;
cbe26ab8
DN
15816
15817 *group_end = /* Is next_insn going to start a new group? */
f676971a 15818 (end
cbe26ab8
DN
15819 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
15820 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
15821 || (can_issue_more < issue_rate &&
15822 insn_terminates_group_p (next_insn, previous_group)));
15823 if (*group_end && end)
15824 (*group_count)--;
15825
15826 if (sched_verbose > 6)
15827 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
15828 *group_count, can_issue_more);
f676971a
EC
15829 return can_issue_more;
15830 }
cbe26ab8
DN
15831
15832 return can_issue_more;
15833}
15834
15835/* This function tries to synch the dispatch groups that the compiler "sees"
f676971a 15836 with the dispatch groups that the processor dispatcher is expected to
cbe26ab8
DN
15837 form in practice. It tries to achieve this synchronization by forcing the
15838 estimated processor grouping on the compiler (as opposed to the function
15839 'pad_goups' which tries to force the scheduler's grouping on the processor).
15840
15841 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
15842 examines the (estimated) dispatch groups that will be formed by the processor
15843 dispatcher. It marks these group boundaries to reflect the estimated
15844 processor grouping, overriding the grouping that the scheduler had marked.
15845 Depending on the value of the flag '-minsert-sched-nops' this function can
15846 force certain insns into separate groups or force a certain distance between
15847 them by inserting nops, for example, if there exists a "costly dependence"
15848 between the insns.
15849
15850 The function estimates the group boundaries that the processor will form as
15851 folllows: It keeps track of how many vacant issue slots are available after
15852 each insn. A subsequent insn will start a new group if one of the following
15853 4 cases applies:
15854 - no more vacant issue slots remain in the current dispatch group.
15855 - only the last issue slot, which is the branch slot, is vacant, but the next
15856 insn is not a branch.
15857 - only the last 2 or less issue slots, including the branch slot, are vacant,
15858 which means that a cracked insn (which occupies two issue slots) can't be
15859 issued in this group.
f676971a 15860 - less than 'issue_rate' slots are vacant, and the next insn always needs to
cbe26ab8
DN
15861 start a new group. */
15862
15863static int
15864redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
15865{
15866 rtx insn, next_insn;
15867 int issue_rate;
15868 int can_issue_more;
15869 int slot, i;
15870 bool group_end;
15871 int group_count = 0;
15872 rtx *group_insns;
15873
15874 /* Initialize. */
15875 issue_rate = rs6000_issue_rate ();
15876 group_insns = alloca (issue_rate * sizeof (rtx));
f676971a 15877 for (i = 0; i < issue_rate; i++)
cbe26ab8
DN
15878 {
15879 group_insns[i] = 0;
15880 }
15881 can_issue_more = issue_rate;
15882 slot = 0;
15883 insn = get_next_active_insn (prev_head_insn, tail);
15884 group_end = false;
15885
15886 while (insn != NULL_RTX)
15887 {
15888 slot = (issue_rate - can_issue_more);
15889 group_insns[slot] = insn;
15890 can_issue_more =
15891 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
15892 if (insn_terminates_group_p (insn, current_group))
15893 can_issue_more = 0;
15894
15895 next_insn = get_next_active_insn (insn, tail);
15896 if (next_insn == NULL_RTX)
15897 return group_count + 1;
15898
15899 group_end = /* Is next_insn going to start a new group? */
15900 (can_issue_more == 0
15901 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
15902 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
15903 || (can_issue_more < issue_rate &&
15904 insn_terminates_group_p (next_insn, previous_group)));
15905
f676971a 15906 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
cbe26ab8
DN
15907 next_insn, &group_end, can_issue_more, &group_count);
15908
15909 if (group_end)
15910 {
15911 group_count++;
15912 can_issue_more = 0;
15913 for (i = 0; i < issue_rate; i++)
15914 {
15915 group_insns[i] = 0;
15916 }
15917 }
15918
15919 if (GET_MODE (next_insn) == TImode && can_issue_more)
15920 PUT_MODE(next_insn, VOIDmode);
15921 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
15922 PUT_MODE (next_insn, TImode);
15923
15924 insn = next_insn;
15925 if (can_issue_more == 0)
15926 can_issue_more = issue_rate;
15927 } /* while */
15928
15929 return group_count;
15930}
15931
15932/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
15933 dispatch group boundaries that the scheduler had marked. Pad with nops
15934 any dispatch groups which have vacant issue slots, in order to force the
15935 scheduler's grouping on the processor dispatcher. The function
15936 returns the number of dispatch groups found. */
15937
15938static int
15939pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
15940{
15941 rtx insn, next_insn;
15942 rtx nop;
15943 int issue_rate;
15944 int can_issue_more;
15945 int group_end;
15946 int group_count = 0;
15947
15948 /* Initialize issue_rate. */
15949 issue_rate = rs6000_issue_rate ();
15950 can_issue_more = issue_rate;
15951
15952 insn = get_next_active_insn (prev_head_insn, tail);
15953 next_insn = get_next_active_insn (insn, tail);
15954
15955 while (insn != NULL_RTX)
15956 {
15957 can_issue_more =
15958 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
15959
15960 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
15961
15962 if (next_insn == NULL_RTX)
15963 break;
15964
15965 if (group_end)
15966 {
15967 /* If the scheduler had marked group termination at this location
15968 (between insn and next_indn), and neither insn nor next_insn will
15969 force group termination, pad the group with nops to force group
15970 termination. */
15971 if (can_issue_more
15972 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
15973 && !insn_terminates_group_p (insn, current_group)
15974 && !insn_terminates_group_p (next_insn, previous_group))
15975 {
15976 if (!is_branch_slot_insn(next_insn))
15977 can_issue_more--;
15978
15979 while (can_issue_more)
15980 {
15981 nop = gen_nop ();
15982 emit_insn_before (nop, next_insn);
15983 can_issue_more--;
15984 }
15985 }
15986
15987 can_issue_more = issue_rate;
15988 group_count++;
15989 }
15990
15991 insn = next_insn;
15992 next_insn = get_next_active_insn (insn, tail);
15993 }
15994
15995 return group_count;
15996}
15997
15998/* The following function is called at the end of scheduling BB.
15999 After reload, it inserts nops at insn group bundling. */
16000
16001static void
38f391a5 16002rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
16003{
16004 int n_groups;
16005
16006 if (sched_verbose)
16007 fprintf (dump, "=== Finishing schedule.\n");
16008
ec507f2d 16009 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
16010 {
16011 if (rs6000_sched_insert_nops == sched_finish_none)
16012 return;
16013
16014 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
16015 n_groups = pad_groups (dump, sched_verbose,
16016 current_sched_info->prev_head,
16017 current_sched_info->next_tail);
16018 else
16019 n_groups = redefine_groups (dump, sched_verbose,
16020 current_sched_info->prev_head,
16021 current_sched_info->next_tail);
16022
16023 if (sched_verbose >= 6)
16024 {
16025 fprintf (dump, "ngroups = %d\n", n_groups);
16026 print_rtl (dump, current_sched_info->prev_head);
16027 fprintf (dump, "Done finish_sched\n");
16028 }
16029 }
16030}
b6c9286a 16031\f
b6c9286a
MM
16032/* Length in units of the trampoline for entering a nested function. */
16033
16034int
863d938c 16035rs6000_trampoline_size (void)
b6c9286a
MM
16036{
16037 int ret = 0;
16038
16039 switch (DEFAULT_ABI)
16040 {
16041 default:
16042 abort ();
16043
16044 case ABI_AIX:
8f802bfb 16045 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
16046 break;
16047
4dabc42d 16048 case ABI_DARWIN:
b6c9286a 16049 case ABI_V4:
03a7e1a5 16050 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 16051 break;
b6c9286a
MM
16052 }
16053
16054 return ret;
16055}
16056
16057/* Emit RTL insns to initialize the variable parts of a trampoline.
16058 FNADDR is an RTX for the address of the function's pure code.
16059 CXT is an RTX for the static chain value for the function. */
16060
16061void
a2369ed3 16062rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 16063{
ac2a93a1 16064 enum machine_mode pmode = Pmode;
8bd04c56
MM
16065 int regsize = (TARGET_32BIT) ? 4 : 8;
16066 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
16067
16068 switch (DEFAULT_ABI)
16069 {
16070 default:
16071 abort ();
16072
8bd04c56 16073/* Macros to shorten the code expansions below. */
39403d82 16074#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
16075#define MEM_PLUS(addr,offset) \
16076 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 16077
b6c9286a
MM
16078 /* Under AIX, just build the 3 word function descriptor */
16079 case ABI_AIX:
8bd04c56
MM
16080 {
16081 rtx fn_reg = gen_reg_rtx (pmode);
16082 rtx toc_reg = gen_reg_rtx (pmode);
16083 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 16084 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
16085 emit_move_insn (MEM_DEREF (addr), fn_reg);
16086 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
16087 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
16088 }
b6c9286a
MM
16089 break;
16090
4dabc42d
TC
16091 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
16092 case ABI_DARWIN:
b6c9286a 16093 case ABI_V4:
39403d82 16094 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
16095 FALSE, VOIDmode, 4,
16096 addr, pmode,
16097 GEN_INT (rs6000_trampoline_size ()), SImode,
16098 fnaddr, pmode,
16099 ctx_reg, pmode);
b6c9286a 16100 break;
b6c9286a
MM
16101 }
16102
16103 return;
16104}
7509c759
MM
16105
16106\f
91d231cb 16107/* Table of valid machine attributes. */
a4f6c312 16108
91d231cb 16109const struct attribute_spec rs6000_attribute_table[] =
7509c759 16110{
91d231cb 16111 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 16112 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
16113 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16114 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
16115 { NULL, 0, 0, false, false, false, NULL }
91d231cb 16116};
7509c759 16117
8bb418a3
ZL
16118/* Handle the "altivec" attribute. The attribute may have
16119 arguments as follows:
f676971a 16120
8bb418a3
ZL
16121 __attribute__((altivec(vector__)))
16122 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
16123 __attribute__((altivec(bool__))) (always followed by 'unsigned')
16124
16125 and may appear more than once (e.g., 'vector bool char') in a
16126 given declaration. */
16127
16128static tree
16129rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
16130 int flags ATTRIBUTE_UNUSED,
16131 bool *no_add_attrs)
16132{
16133 tree type = *node, result = NULL_TREE;
16134 enum machine_mode mode;
16135 int unsigned_p;
16136 char altivec_type
16137 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
16138 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
16139 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
f676971a 16140 : '?');
8bb418a3
ZL
16141
16142 while (POINTER_TYPE_P (type)
16143 || TREE_CODE (type) == FUNCTION_TYPE
16144 || TREE_CODE (type) == METHOD_TYPE
16145 || TREE_CODE (type) == ARRAY_TYPE)
16146 type = TREE_TYPE (type);
16147
16148 mode = TYPE_MODE (type);
16149
16150 if (rs6000_warn_altivec_long
16151 && (type == long_unsigned_type_node || type == long_integer_type_node))
16152 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
16153
16154 switch (altivec_type)
16155 {
16156 case 'v':
8df83eae 16157 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
16158 switch (mode)
16159 {
16160 case SImode:
16161 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
16162 break;
16163 case HImode:
16164 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
16165 break;
16166 case QImode:
16167 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
16168 break;
16169 case SFmode: result = V4SF_type_node; break;
16170 /* If the user says 'vector int bool', we may be handed the 'bool'
16171 attribute _before_ the 'vector' attribute, and so select the proper
16172 type in the 'b' case below. */
16173 case V4SImode: case V8HImode: case V16QImode: result = type;
16174 default: break;
16175 }
16176 break;
16177 case 'b':
16178 switch (mode)
16179 {
16180 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
16181 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
16182 case QImode: case V16QImode: result = bool_V16QI_type_node;
16183 default: break;
16184 }
16185 break;
16186 case 'p':
16187 switch (mode)
16188 {
16189 case V8HImode: result = pixel_V8HI_type_node;
16190 default: break;
16191 }
16192 default: break;
16193 }
16194
7958a2a6
FJ
16195 if (result && result != type && TYPE_READONLY (type))
16196 result = build_qualified_type (result, TYPE_QUAL_CONST);
16197
8bb418a3
ZL
16198 *no_add_attrs = true; /* No need to hang on to the attribute. */
16199
16200 if (!result)
16201 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
16202 else
16203 *node = reconstruct_complex_type (*node, result);
16204
16205 return NULL_TREE;
16206}
16207
f18eca82
ZL
16208/* AltiVec defines four built-in scalar types that serve as vector
16209 elements; we must teach the compiler how to mangle them. */
16210
16211static const char *
16212rs6000_mangle_fundamental_type (tree type)
16213{
16214 if (type == bool_char_type_node) return "U6__boolc";
16215 if (type == bool_short_type_node) return "U6__bools";
16216 if (type == pixel_type_node) return "u7__pixel";
16217 if (type == bool_int_type_node) return "U6__booli";
16218
16219 /* For all other types, use normal C++ mangling. */
16220 return NULL;
16221}
16222
a5c76ee6
ZW
16223/* Handle a "longcall" or "shortcall" attribute; arguments as in
16224 struct attribute_spec.handler. */
a4f6c312 16225
91d231cb 16226static tree
f676971a
EC
16227rs6000_handle_longcall_attribute (tree *node, tree name,
16228 tree args ATTRIBUTE_UNUSED,
16229 int flags ATTRIBUTE_UNUSED,
a2369ed3 16230 bool *no_add_attrs)
91d231cb
JM
16231{
16232 if (TREE_CODE (*node) != FUNCTION_TYPE
16233 && TREE_CODE (*node) != FIELD_DECL
16234 && TREE_CODE (*node) != TYPE_DECL)
16235 {
16236 warning ("`%s' attribute only applies to functions",
16237 IDENTIFIER_POINTER (name));
16238 *no_add_attrs = true;
16239 }
6a4cee5f 16240
91d231cb 16241 return NULL_TREE;
7509c759
MM
16242}
16243
a5c76ee6
ZW
16244/* Set longcall attributes on all functions declared when
16245 rs6000_default_long_calls is true. */
16246static void
a2369ed3 16247rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
16248{
16249 if (rs6000_default_long_calls
16250 && (TREE_CODE (type) == FUNCTION_TYPE
16251 || TREE_CODE (type) == METHOD_TYPE))
16252 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
16253 NULL_TREE,
16254 TYPE_ATTRIBUTES (type));
16255}
16256
3cb999d8
DE
16257/* Return a reference suitable for calling a function with the
16258 longcall attribute. */
a4f6c312 16259
6a4cee5f 16260struct rtx_def *
a2369ed3 16261rs6000_longcall_ref (rtx call_ref)
6a4cee5f 16262{
d330fd93 16263 const char *call_name;
6a4cee5f
MM
16264 tree node;
16265
16266 if (GET_CODE (call_ref) != SYMBOL_REF)
16267 return call_ref;
16268
16269 /* System V adds '.' to the internal name, so skip them. */
16270 call_name = XSTR (call_ref, 0);
16271 if (*call_name == '.')
16272 {
16273 while (*call_name == '.')
16274 call_name++;
16275
16276 node = get_identifier (call_name);
39403d82 16277 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
16278 }
16279
16280 return force_reg (Pmode, call_ref);
16281}
7509c759 16282\f
b64a1b53
RH
16283#ifdef USING_ELFOS_H
16284
7509c759
MM
16285/* A C statement or statements to switch to the appropriate section
16286 for output of RTX in mode MODE. You can assume that RTX is some
16287 kind of constant in RTL. The argument MODE is redundant except in
16288 the case of a `const_int' rtx. Select the section by calling
16289 `text_section' or one of the alternatives for other sections.
16290
16291 Do not define this macro if you put all constants in the read-only
16292 data section. */
16293
b64a1b53 16294static void
f676971a 16295rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
a2369ed3 16296 unsigned HOST_WIDE_INT align)
7509c759 16297{
a9098fd0 16298 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 16299 toc_section ();
7509c759 16300 else
b64a1b53 16301 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
16302}
16303
16304/* A C statement or statements to switch to the appropriate
16305 section for output of DECL. DECL is either a `VAR_DECL' node
16306 or a constant of some sort. RELOC indicates whether forming
16307 the initial value of DECL requires link-time relocations. */
16308
ae46c4e0 16309static void
f676971a 16310rs6000_elf_select_section (tree decl, int reloc,
a2369ed3 16311 unsigned HOST_WIDE_INT align)
7509c759 16312{
f1384257
AM
16313 /* Pretend that we're always building for a shared library when
16314 ABI_AIX, because otherwise we end up with dynamic relocations
16315 in read-only sections. This happens for function pointers,
16316 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
16317 default_elf_select_section_1 (decl, reloc, align,
16318 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
16319}
16320
16321/* A C statement to build up a unique section name, expressed as a
16322 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
16323 RELOC indicates whether the initial value of EXP requires
16324 link-time relocations. If you do not define this macro, GCC will use
16325 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 16326 macro can now be called for uninitialized data items as well as
4912a07c 16327 initialized data and functions. */
63019373 16328
ae46c4e0 16329static void
a2369ed3 16330rs6000_elf_unique_section (tree decl, int reloc)
63019373 16331{
f1384257
AM
16332 /* As above, pretend that we're always building for a shared library
16333 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
16334 default_unique_section_1 (decl, reloc,
16335 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 16336}
d9407988 16337\f
d1908feb
JJ
16338/* For a SYMBOL_REF, set generic flags and then perform some
16339 target-specific processing.
16340
d1908feb
JJ
16341 When the AIX ABI is requested on a non-AIX system, replace the
16342 function name with the real name (with a leading .) rather than the
16343 function descriptor name. This saves a lot of overriding code to
16344 read the prefixes. */
d9407988 16345
fb49053f 16346static void
a2369ed3 16347rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 16348{
d1908feb 16349 default_encode_section_info (decl, rtl, first);
b2003250 16350
d1908feb
JJ
16351 if (first
16352 && TREE_CODE (decl) == FUNCTION_DECL
16353 && !TARGET_AIX
16354 && DEFAULT_ABI == ABI_AIX)
d9407988 16355 {
c6a2438a 16356 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
16357 size_t len = strlen (XSTR (sym_ref, 0));
16358 char *str = alloca (len + 2);
16359 str[0] = '.';
16360 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
16361 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 16362 }
d9407988
MM
16363}
16364
0e5dbd9b 16365static bool
a2369ed3 16366rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
16367{
16368 if (rs6000_sdata == SDATA_NONE)
16369 return false;
16370
16371 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
16372 {
16373 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
16374 if (strcmp (section, ".sdata") == 0
16375 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
16376 || strcmp (section, ".sbss") == 0
16377 || strcmp (section, ".sbss2") == 0
16378 || strcmp (section, ".PPC.EMB.sdata0") == 0
16379 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
16380 return true;
16381 }
16382 else
16383 {
16384 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
16385
16386 if (size > 0
307b599c 16387 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
16388 /* If it's not public, and we're not going to reference it there,
16389 there's no need to put it in the small data section. */
0e5dbd9b
DE
16390 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
16391 return true;
16392 }
16393
16394 return false;
16395}
16396
b91da81f 16397#endif /* USING_ELFOS_H */
000034eb 16398
a6c2a102 16399\f
000034eb 16400/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
16401 ADDR can be effectively incremented by incrementing REG.
16402
16403 r0 is special and we must not select it as an address
16404 register by this routine since our caller will try to
16405 increment the returned register via an "la" instruction. */
000034eb
DE
16406
16407struct rtx_def *
a2369ed3 16408find_addr_reg (rtx addr)
000034eb
DE
16409{
16410 while (GET_CODE (addr) == PLUS)
16411 {
02441cd6
JL
16412 if (GET_CODE (XEXP (addr, 0)) == REG
16413 && REGNO (XEXP (addr, 0)) != 0)
000034eb 16414 addr = XEXP (addr, 0);
02441cd6
JL
16415 else if (GET_CODE (XEXP (addr, 1)) == REG
16416 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
16417 addr = XEXP (addr, 1);
16418 else if (CONSTANT_P (XEXP (addr, 0)))
16419 addr = XEXP (addr, 1);
16420 else if (CONSTANT_P (XEXP (addr, 1)))
16421 addr = XEXP (addr, 0);
16422 else
16423 abort ();
16424 }
02441cd6 16425 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
16426 return addr;
16427 abort ();
16428}
16429
a6c2a102 16430void
a2369ed3 16431rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
16432{
16433 fatal_insn ("bad address", op);
16434}
c8023011 16435
ee890fe2
SS
16436#if TARGET_MACHO
16437
16438#if 0
16439/* Returns 1 if OP is either a symbol reference or a sum of a symbol
16440 reference and a constant. */
16441
16442int
a2369ed3 16443symbolic_operand (rtx op)
ee890fe2
SS
16444{
16445 switch (GET_CODE (op))
16446 {
16447 case SYMBOL_REF:
16448 case LABEL_REF:
16449 return 1;
16450 case CONST:
16451 op = XEXP (op, 0);
16452 return (GET_CODE (op) == SYMBOL_REF ||
16453 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
16454 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
16455 && GET_CODE (XEXP (op, 1)) == CONST_INT);
16456 default:
16457 return 0;
16458 }
c8023011 16459}
ee890fe2
SS
16460#endif
16461
efdba735 16462#if TARGET_MACHO
ee890fe2 16463
efdba735 16464static tree branch_island_list = 0;
ee890fe2 16465
efdba735
SH
16466/* Remember to generate a branch island for far calls to the given
16467 function. */
ee890fe2 16468
f676971a 16469static void
efdba735 16470add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 16471{
efdba735 16472 tree branch_island = build_tree_list (function_name, label_name);
7d60be94 16473 TREE_TYPE (branch_island) = build_int_cst (NULL_TREE, line_number);
efdba735
SH
16474 TREE_CHAIN (branch_island) = branch_island_list;
16475 branch_island_list = branch_island;
ee890fe2
SS
16476}
16477
efdba735
SH
16478#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
16479#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
16480#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
16481 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 16482
efdba735
SH
16483/* Generate far-jump branch islands for everything on the
16484 branch_island_list. Invoked immediately after the last instruction
16485 of the epilogue has been emitted; the branch-islands must be
16486 appended to, and contiguous with, the function body. Mach-O stubs
16487 are generated in machopic_output_stub(). */
ee890fe2 16488
efdba735
SH
16489static void
16490macho_branch_islands (void)
16491{
16492 char tmp_buf[512];
16493 tree branch_island;
16494
16495 for (branch_island = branch_island_list;
16496 branch_island;
16497 branch_island = TREE_CHAIN (branch_island))
16498 {
16499 const char *label =
16500 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
16501 const char *name =
11abc112 16502 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island));
efdba735
SH
16503 char name_buf[512];
16504 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
16505 if (name[0] == '*' || name[0] == '&')
16506 strcpy (name_buf, name+1);
16507 else
16508 {
16509 name_buf[0] = '_';
16510 strcpy (name_buf+1, name);
16511 }
16512 strcpy (tmp_buf, "\n");
16513 strcat (tmp_buf, label);
ee890fe2 16514#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16515 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16516 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16517 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 16518#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
16519 if (flag_pic)
16520 {
16521 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
16522 strcat (tmp_buf, label);
16523 strcat (tmp_buf, "_pic\n");
16524 strcat (tmp_buf, label);
16525 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
f676971a 16526
efdba735
SH
16527 strcat (tmp_buf, "\taddis r11,r11,ha16(");
16528 strcat (tmp_buf, name_buf);
16529 strcat (tmp_buf, " - ");
16530 strcat (tmp_buf, label);
16531 strcat (tmp_buf, "_pic)\n");
f676971a 16532
efdba735 16533 strcat (tmp_buf, "\tmtlr r0\n");
f676971a 16534
efdba735
SH
16535 strcat (tmp_buf, "\taddi r12,r11,lo16(");
16536 strcat (tmp_buf, name_buf);
16537 strcat (tmp_buf, " - ");
16538 strcat (tmp_buf, label);
16539 strcat (tmp_buf, "_pic)\n");
f676971a 16540
efdba735
SH
16541 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
16542 }
16543 else
16544 {
16545 strcat (tmp_buf, ":\nlis r12,hi16(");
16546 strcat (tmp_buf, name_buf);
16547 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
16548 strcat (tmp_buf, name_buf);
16549 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
16550 }
16551 output_asm_insn (tmp_buf, 0);
ee890fe2 16552#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 16553 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 16554 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 16555 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 16556#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 16557 }
ee890fe2 16558
efdba735 16559 branch_island_list = 0;
ee890fe2
SS
16560}
16561
16562/* NO_PREVIOUS_DEF checks in the link list whether the function name is
16563 already there or not. */
16564
efdba735 16565static int
a2369ed3 16566no_previous_def (tree function_name)
ee890fe2 16567{
efdba735
SH
16568 tree branch_island;
16569 for (branch_island = branch_island_list;
16570 branch_island;
16571 branch_island = TREE_CHAIN (branch_island))
16572 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
16573 return 0;
16574 return 1;
16575}
16576
16577/* GET_PREV_LABEL gets the label name from the previous definition of
16578 the function. */
16579
efdba735 16580static tree
a2369ed3 16581get_prev_label (tree function_name)
ee890fe2 16582{
efdba735
SH
16583 tree branch_island;
16584 for (branch_island = branch_island_list;
16585 branch_island;
16586 branch_island = TREE_CHAIN (branch_island))
16587 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
16588 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
16589 return 0;
16590}
16591
16592/* INSN is either a function call or a millicode call. It may have an
f676971a 16593 unconditional jump in its delay slot.
ee890fe2
SS
16594
16595 CALL_DEST is the routine we are calling. */
16596
16597char *
efdba735 16598output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
16599{
16600 static char buf[256];
efdba735
SH
16601 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
16602 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
16603 {
16604 tree labelname;
efdba735 16605 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
f676971a 16606
ee890fe2
SS
16607 if (no_previous_def (funname))
16608 {
308c142a 16609 int line_number = 0;
ee890fe2
SS
16610 rtx label_rtx = gen_label_rtx ();
16611 char *label_buf, temp_buf[256];
16612 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
16613 CODE_LABEL_NUMBER (label_rtx));
16614 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
16615 labelname = get_identifier (label_buf);
16616 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
16617 if (insn)
16618 line_number = NOTE_LINE_NUMBER (insn);
efdba735 16619 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
16620 }
16621 else
16622 labelname = get_prev_label (funname);
16623
efdba735
SH
16624 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
16625 instruction will reach 'foo', otherwise link as 'bl L42'".
16626 "L42" should be a 'branch island', that will do a far jump to
16627 'foo'. Branch islands are generated in
16628 macho_branch_islands(). */
ee890fe2 16629 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 16630 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
16631 }
16632 else
efdba735
SH
16633 sprintf (buf, "bl %%z%d", dest_operand_number);
16634 return buf;
ee890fe2
SS
16635}
16636
efdba735 16637#endif /* TARGET_MACHO */
ee890fe2 16638
ee890fe2
SS
16639/* Generate PIC and indirect symbol stubs. */
16640
16641void
a2369ed3 16642machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
16643{
16644 unsigned int length;
a4f6c312
SS
16645 char *symbol_name, *lazy_ptr_name;
16646 char *local_label_0;
ee890fe2
SS
16647 static int label = 0;
16648
df56a27f 16649 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 16650 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 16651
ee890fe2 16652
ee890fe2
SS
16653 length = strlen (symb);
16654 symbol_name = alloca (length + 32);
16655 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
16656
16657 lazy_ptr_name = alloca (length + 32);
16658 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
16659
ee890fe2 16660 if (flag_pic == 2)
d3c300d2 16661 machopic_picsymbol_stub1_section ();
ee890fe2 16662 else
d3c300d2 16663 machopic_symbol_stub1_section ();
ee890fe2
SS
16664
16665 if (flag_pic == 2)
16666 {
d974312d
DJ
16667 fprintf (file, "\t.align 5\n");
16668
16669 fprintf (file, "%s:\n", stub);
16670 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
16671
876455fa
AP
16672 label++;
16673 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
16674 sprintf (local_label_0, "\"L%011d$spb\"", label);
f676971a 16675
ee890fe2
SS
16676 fprintf (file, "\tmflr r0\n");
16677 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
16678 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
16679 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
16680 lazy_ptr_name, local_label_0);
16681 fprintf (file, "\tmtlr r0\n");
d3c300d2 16682 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
16683 lazy_ptr_name, local_label_0);
16684 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
16685 fprintf (file, "\tbctr\n");
16686 }
16687 else
d974312d
DJ
16688 {
16689 fprintf (file, "\t.align 4\n");
16690
16691 fprintf (file, "%s:\n", stub);
16692 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
16693
16694 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
16695 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
16696 fprintf (file, "\tmtctr r12\n");
16697 fprintf (file, "\tbctr\n");
16698 }
f676971a 16699
ee890fe2
SS
16700 machopic_lazy_symbol_ptr_section ();
16701 fprintf (file, "%s:\n", lazy_ptr_name);
16702 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
49bd1d27
SS
16703 fprintf (file, "%sdyld_stub_binding_helper\n",
16704 (TARGET_64BIT ? DOUBLE_INT_ASM_OP : "\t.long\t"));
ee890fe2
SS
16705}
16706
16707/* Legitimize PIC addresses. If the address is already
16708 position-independent, we return ORIG. Newly generated
16709 position-independent addresses go into a reg. This is REG if non
16710 zero, otherwise we allocate register(s) as necessary. */
16711
c859cda6 16712#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
16713
16714rtx
f676971a 16715rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
a2369ed3 16716 rtx reg)
ee890fe2
SS
16717{
16718 rtx base, offset;
16719
16720 if (reg == NULL && ! reload_in_progress && ! reload_completed)
16721 reg = gen_reg_rtx (Pmode);
16722
16723 if (GET_CODE (orig) == CONST)
16724 {
16725 if (GET_CODE (XEXP (orig, 0)) == PLUS
16726 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
16727 return orig;
16728
16729 if (GET_CODE (XEXP (orig, 0)) == PLUS)
16730 {
2cf520bf 16731 /* Use a different reg for the intermediate value, as
a3c9585f 16732 it will be marked UNCHANGING. */
2cf520bf
GK
16733 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
16734
a4f6c312
SS
16735 base =
16736 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 16737 Pmode, reg_temp);
a4f6c312
SS
16738 offset =
16739 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
16740 Pmode, reg);
ee890fe2
SS
16741 }
16742 else
16743 abort ();
16744
16745 if (GET_CODE (offset) == CONST_INT)
16746 {
16747 if (SMALL_INT (offset))
ed8908e7 16748 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
16749 else if (! reload_in_progress && ! reload_completed)
16750 offset = force_reg (Pmode, offset);
16751 else
c859cda6
DJ
16752 {
16753 rtx mem = force_const_mem (Pmode, orig);
16754 return machopic_legitimize_pic_address (mem, Pmode, reg);
16755 }
ee890fe2 16756 }
f1c25d3b 16757 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
16758 }
16759
16760 /* Fall back on generic machopic code. */
16761 return machopic_legitimize_pic_address (orig, mode, reg);
16762}
16763
16764/* This is just a placeholder to make linking work without having to
16765 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
16766 ever needed for Darwin (not too likely!) this would have to get a
16767 real definition. */
16768
16769void
863d938c 16770toc_section (void)
ee890fe2
SS
16771{
16772}
16773
16774#endif /* TARGET_MACHO */
7c262518
RH
16775
16776#if TARGET_ELF
16777static unsigned int
a2369ed3 16778rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 16779{
1ff8f81a
AM
16780 return default_section_type_flags_1 (decl, name, reloc,
16781 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 16782}
d9f6800d
RH
16783
16784/* Record an element in the table of global constructors. SYMBOL is
16785 a SYMBOL_REF of the function to be called; PRIORITY is a number
16786 between 0 and MAX_INIT_PRIORITY.
16787
16788 This differs from default_named_section_asm_out_constructor in
16789 that we have special handling for -mrelocatable. */
16790
16791static void
a2369ed3 16792rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
16793{
16794 const char *section = ".ctors";
16795 char buf[16];
16796
16797 if (priority != DEFAULT_INIT_PRIORITY)
16798 {
16799 sprintf (buf, ".ctors.%.5u",
16800 /* Invert the numbering so the linker puts us in the proper
16801 order; constructors are run from right to left, and the
16802 linker sorts in increasing order. */
16803 MAX_INIT_PRIORITY - priority);
16804 section = buf;
16805 }
16806
715bdd29
RH
16807 named_section_flags (section, SECTION_WRITE);
16808 assemble_align (POINTER_SIZE);
d9f6800d
RH
16809
16810 if (TARGET_RELOCATABLE)
16811 {
16812 fputs ("\t.long (", asm_out_file);
16813 output_addr_const (asm_out_file, symbol);
16814 fputs (")@fixup\n", asm_out_file);
16815 }
16816 else
c8af3574 16817 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
16818}
16819
16820static void
a2369ed3 16821rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
16822{
16823 const char *section = ".dtors";
16824 char buf[16];
16825
16826 if (priority != DEFAULT_INIT_PRIORITY)
16827 {
16828 sprintf (buf, ".dtors.%.5u",
16829 /* Invert the numbering so the linker puts us in the proper
16830 order; constructors are run from right to left, and the
16831 linker sorts in increasing order. */
16832 MAX_INIT_PRIORITY - priority);
16833 section = buf;
16834 }
16835
715bdd29
RH
16836 named_section_flags (section, SECTION_WRITE);
16837 assemble_align (POINTER_SIZE);
d9f6800d
RH
16838
16839 if (TARGET_RELOCATABLE)
16840 {
16841 fputs ("\t.long (", asm_out_file);
16842 output_addr_const (asm_out_file, symbol);
16843 fputs (")@fixup\n", asm_out_file);
16844 }
16845 else
c8af3574 16846 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 16847}
9739c90c
JJ
16848
16849void
a2369ed3 16850rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
16851{
16852 if (TARGET_64BIT)
16853 {
16854 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
16855 ASM_OUTPUT_LABEL (file, name);
16856 fputs (DOUBLE_INT_ASM_OP, file);
85b776df
AM
16857 rs6000_output_function_entry (file, name);
16858 fputs (",.TOC.@tocbase,0\n\t.previous\n", file);
16859 if (DOT_SYMBOLS)
9739c90c 16860 {
85b776df 16861 fputs ("\t.size\t", file);
9739c90c 16862 assemble_name (file, name);
85b776df
AM
16863 fputs (",24\n\t.type\t.", file);
16864 assemble_name (file, name);
16865 fputs (",@function\n", file);
16866 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
16867 {
16868 fputs ("\t.globl\t.", file);
16869 assemble_name (file, name);
16870 putc ('\n', file);
16871 }
9739c90c 16872 }
85b776df
AM
16873 else
16874 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
9739c90c 16875 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
85b776df
AM
16876 rs6000_output_function_entry (file, name);
16877 fputs (":\n", file);
9739c90c
JJ
16878 return;
16879 }
16880
16881 if (TARGET_RELOCATABLE
16882 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 16883 && uses_TOC ())
9739c90c
JJ
16884 {
16885 char buf[256];
16886
16887 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
16888
16889 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
16890 fprintf (file, "\t.long ");
16891 assemble_name (file, buf);
16892 putc ('-', file);
16893 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
16894 assemble_name (file, buf);
16895 putc ('\n', file);
16896 }
16897
16898 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
16899 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
16900
16901 if (DEFAULT_ABI == ABI_AIX)
16902 {
16903 const char *desc_name, *orig_name;
16904
16905 orig_name = (*targetm.strip_name_encoding) (name);
16906 desc_name = orig_name;
16907 while (*desc_name == '.')
16908 desc_name++;
16909
16910 if (TREE_PUBLIC (decl))
16911 fprintf (file, "\t.globl %s\n", desc_name);
16912
16913 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
16914 fprintf (file, "%s:\n", desc_name);
16915 fprintf (file, "\t.long %s\n", orig_name);
16916 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
16917 if (DEFAULT_ABI == ABI_AIX)
16918 fputs ("\t.long 0\n", file);
16919 fprintf (file, "\t.previous\n");
16920 }
16921 ASM_OUTPUT_LABEL (file, name);
16922}
7c262518
RH
16923#endif
16924
cbaaba19 16925#if TARGET_XCOFF
7c262518 16926static void
a2369ed3 16927rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
16928{
16929 fputs (GLOBAL_ASM_OP, stream);
16930 RS6000_OUTPUT_BASENAME (stream, name);
16931 putc ('\n', stream);
16932}
16933
16934static void
a2369ed3 16935rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 16936{
0e5dbd9b
DE
16937 int smclass;
16938 static const char * const suffix[3] = { "PR", "RO", "RW" };
16939
16940 if (flags & SECTION_CODE)
16941 smclass = 0;
16942 else if (flags & SECTION_WRITE)
16943 smclass = 2;
16944 else
16945 smclass = 1;
16946
5b5198f7 16947 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 16948 (flags & SECTION_CODE) ? "." : "",
5b5198f7 16949 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 16950}
ae46c4e0
RH
16951
16952static void
f676971a 16953rs6000_xcoff_select_section (tree decl, int reloc,
a2369ed3 16954 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 16955{
5add3202 16956 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 16957 {
0e5dbd9b 16958 if (TREE_PUBLIC (decl))
ae46c4e0
RH
16959 read_only_data_section ();
16960 else
16961 read_only_private_data_section ();
16962 }
16963 else
16964 {
0e5dbd9b 16965 if (TREE_PUBLIC (decl))
ae46c4e0
RH
16966 data_section ();
16967 else
16968 private_data_section ();
16969 }
16970}
16971
16972static void
a2369ed3 16973rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
16974{
16975 const char *name;
ae46c4e0 16976
5b5198f7
DE
16977 /* Use select_section for private and uninitialized data. */
16978 if (!TREE_PUBLIC (decl)
16979 || DECL_COMMON (decl)
0e5dbd9b
DE
16980 || DECL_INITIAL (decl) == NULL_TREE
16981 || DECL_INITIAL (decl) == error_mark_node
16982 || (flag_zero_initialized_in_bss
16983 && initializer_zerop (DECL_INITIAL (decl))))
16984 return;
16985
16986 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
16987 name = (*targetm.strip_name_encoding) (name);
16988 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 16989}
b64a1b53 16990
fb49053f
RH
16991/* Select section for constant in constant pool.
16992
16993 On RS/6000, all constants are in the private read-only data area.
16994 However, if this is being placed in the TOC it must be output as a
16995 toc entry. */
16996
b64a1b53 16997static void
f676971a 16998rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
a2369ed3 16999 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
17000{
17001 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
17002 toc_section ();
17003 else
17004 read_only_private_data_section ();
17005}
772c5265
RH
17006
17007/* Remove any trailing [DS] or the like from the symbol name. */
17008
17009static const char *
a2369ed3 17010rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
17011{
17012 size_t len;
17013 if (*name == '*')
17014 name++;
17015 len = strlen (name);
17016 if (name[len - 1] == ']')
17017 return ggc_alloc_string (name, len - 4);
17018 else
17019 return name;
17020}
17021
5add3202
DE
17022/* Section attributes. AIX is always PIC. */
17023
17024static unsigned int
a2369ed3 17025rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 17026{
5b5198f7
DE
17027 unsigned int align;
17028 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
17029
17030 /* Align to at least UNIT size. */
17031 if (flags & SECTION_CODE)
17032 align = MIN_UNITS_PER_WORD;
17033 else
17034 /* Increase alignment of large objects if not already stricter. */
17035 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
17036 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
17037 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
17038
17039 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 17040}
a5fe455b 17041
1bc7c5b6
ZW
17042/* Output at beginning of assembler file.
17043
17044 Initialize the section names for the RS/6000 at this point.
17045
17046 Specify filename, including full path, to assembler.
17047
17048 We want to go into the TOC section so at least one .toc will be emitted.
17049 Also, in order to output proper .bs/.es pairs, we need at least one static
17050 [RW] section emitted.
17051
17052 Finally, declare mcount when profiling to make the assembler happy. */
17053
17054static void
863d938c 17055rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
17056{
17057 rs6000_gen_section_name (&xcoff_bss_section_name,
17058 main_input_filename, ".bss_");
17059 rs6000_gen_section_name (&xcoff_private_data_section_name,
17060 main_input_filename, ".rw_");
17061 rs6000_gen_section_name (&xcoff_read_only_section_name,
17062 main_input_filename, ".ro_");
17063
17064 fputs ("\t.file\t", asm_out_file);
17065 output_quoted_string (asm_out_file, main_input_filename);
17066 fputc ('\n', asm_out_file);
17067 toc_section ();
17068 if (write_symbols != NO_DEBUG)
17069 private_data_section ();
17070 text_section ();
17071 if (profile_flag)
17072 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
17073 rs6000_file_start ();
17074}
17075
a5fe455b
ZW
17076/* Output at end of assembler file.
17077 On the RS/6000, referencing data should automatically pull in text. */
17078
17079static void
863d938c 17080rs6000_xcoff_file_end (void)
a5fe455b
ZW
17081{
17082 text_section ();
17083 fputs ("_section_.text:\n", asm_out_file);
17084 data_section ();
17085 fputs (TARGET_32BIT
17086 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
17087 asm_out_file);
17088}
f1384257 17089#endif /* TARGET_XCOFF */
0e5dbd9b 17090
f1384257
AM
17091#if TARGET_MACHO
17092/* Cross-module name binding. Darwin does not support overriding
7f3d8013 17093 functions at dynamic-link time. */
0e5dbd9b 17094
2bcc50d0 17095static bool
a2369ed3 17096rs6000_binds_local_p (tree decl)
0e5dbd9b 17097{
f1384257 17098 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 17099}
f1384257 17100#endif
34bb030a 17101
3c50106f
RH
17102/* Compute a (partial) cost for rtx X. Return true if the complete
17103 cost has been computed, and false if subexpressions should be
17104 scanned. In either case, *TOTAL contains the cost result. */
17105
17106static bool
1494c534 17107rs6000_rtx_costs (rtx x, int code, int outer_code, int *total)
3c50106f 17108{
f0517163
RS
17109 enum machine_mode mode = GET_MODE (x);
17110
3c50106f
RH
17111 switch (code)
17112 {
30a555d9 17113 /* On the RS/6000, if it is valid in the insn, it is free. */
3c50106f 17114 case CONST_INT:
066cd967
DE
17115 if (((outer_code == SET
17116 || outer_code == PLUS
17117 || outer_code == MINUS)
17118 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17119 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
17120 || ((outer_code == IOR || outer_code == XOR)
17121 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17122 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')))
627b6fe2
DJ
17123 || ((outer_code == DIV || outer_code == UDIV
17124 || outer_code == MOD || outer_code == UMOD)
17125 && exact_log2 (INTVAL (x)) >= 0)
066cd967
DE
17126 || (outer_code == AND
17127 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17128 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17129 || mask_operand (x, VOIDmode)))
066cd967
DE
17130 || outer_code == ASHIFT
17131 || outer_code == ASHIFTRT
17132 || outer_code == LSHIFTRT
17133 || outer_code == ROTATE
17134 || outer_code == ROTATERT
d5861a7a 17135 || outer_code == ZERO_EXTRACT
066cd967
DE
17136 || (outer_code == MULT
17137 && CONST_OK_FOR_LETTER_P (INTVAL (x), 'I'))
17138 || (outer_code == COMPARE
17139 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'I')
17140 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'K'))))
17141 {
17142 *total = 0;
17143 return true;
17144 }
17145 else if ((outer_code == PLUS
17146 && reg_or_add_cint64_operand (x, VOIDmode))
17147 || (outer_code == MINUS
17148 && reg_or_sub_cint64_operand (x, VOIDmode))
17149 || ((outer_code == SET
17150 || outer_code == IOR
17151 || outer_code == XOR)
17152 && (INTVAL (x)
17153 & ~ (unsigned HOST_WIDE_INT) 0xffffffff) == 0))
17154 {
17155 *total = COSTS_N_INSNS (1);
17156 return true;
17157 }
17158 /* FALLTHRU */
17159
17160 case CONST_DOUBLE:
17161 if (mode == DImode
17162 && ((outer_code == AND
17163 && (CONST_OK_FOR_LETTER_P (INTVAL (x), 'K')
17164 || CONST_OK_FOR_LETTER_P (INTVAL (x), 'L')
d5861a7a 17165 || mask64_operand (x, DImode)))
066cd967
DE
17166 || ((outer_code == IOR || outer_code == XOR)
17167 && CONST_DOUBLE_HIGH (x) == 0
17168 && (CONST_DOUBLE_LOW (x)
17169 & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0)))
17170 {
17171 *total = 0;
17172 return true;
17173 }
17174 else if (mode == DImode
17175 && (outer_code == SET
17176 || outer_code == IOR
17177 || outer_code == XOR)
17178 && CONST_DOUBLE_HIGH (x) == 0)
17179 {
17180 *total = COSTS_N_INSNS (1);
17181 return true;
17182 }
17183 /* FALLTHRU */
17184
3c50106f 17185 case CONST:
066cd967 17186 case HIGH:
3c50106f 17187 case SYMBOL_REF:
066cd967
DE
17188 case MEM:
17189 /* When optimizing for size, MEM should be slightly more expensive
17190 than generating address, e.g., (plus (reg) (const)).
c112cf2b 17191 L1 cache latency is about two instructions. */
066cd967 17192 *total = optimize_size ? COSTS_N_INSNS (1) + 1 : COSTS_N_INSNS (2);
3c50106f
RH
17193 return true;
17194
30a555d9
DE
17195 case LABEL_REF:
17196 *total = 0;
17197 return true;
17198
3c50106f 17199 case PLUS:
f0517163 17200 if (mode == DFmode)
066cd967
DE
17201 {
17202 if (GET_CODE (XEXP (x, 0)) == MULT)
17203 {
17204 /* FNMA accounted in outer NEG. */
17205 if (outer_code == NEG)
17206 *total = rs6000_cost->dmul - rs6000_cost->fp;
17207 else
17208 *total = rs6000_cost->dmul;
17209 }
17210 else
17211 *total = rs6000_cost->fp;
17212 }
f0517163 17213 else if (mode == SFmode)
066cd967
DE
17214 {
17215 /* FNMA accounted in outer NEG. */
17216 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17217 *total = 0;
17218 else
17219 *total = rs6000_cost->fp;
17220 }
938bf747
RS
17221 else if (GET_CODE (XEXP (x, 0)) == MULT)
17222 {
17223 /* The rs6000 doesn't have shift-and-add instructions. */
17224 rs6000_rtx_costs (XEXP (x, 0), MULT, PLUS, total);
17225 *total += COSTS_N_INSNS (1);
17226 }
f0517163 17227 else
066cd967
DE
17228 *total = COSTS_N_INSNS (1);
17229 return false;
3c50106f 17230
52190329 17231 case MINUS:
f0517163 17232 if (mode == DFmode)
066cd967
DE
17233 {
17234 if (GET_CODE (XEXP (x, 0)) == MULT)
17235 {
17236 /* FNMA accounted in outer NEG. */
17237 if (outer_code == NEG)
17238 *total = 0;
17239 else
17240 *total = rs6000_cost->dmul;
17241 }
17242 else
17243 *total = rs6000_cost->fp;
17244 }
f0517163 17245 else if (mode == SFmode)
066cd967
DE
17246 {
17247 /* FNMA accounted in outer NEG. */
17248 if (outer_code == NEG && GET_CODE (XEXP (x, 0)) == MULT)
17249 *total = 0;
17250 else
17251 *total = rs6000_cost->fp;
17252 }
938bf747
RS
17253 else if (GET_CODE (XEXP (x, 0)) == MULT)
17254 {
17255 /* The rs6000 doesn't have shift-and-sub instructions. */
17256 rs6000_rtx_costs (XEXP (x, 0), MULT, MINUS, total);
17257 *total += COSTS_N_INSNS (1);
17258 }
f0517163
RS
17259 else
17260 *total = COSTS_N_INSNS (1);
066cd967 17261 return false;
3c50106f
RH
17262
17263 case MULT:
8b897cfa 17264 if (GET_CODE (XEXP (x, 1)) == CONST_INT)
3c50106f 17265 {
8b897cfa
RS
17266 if (INTVAL (XEXP (x, 1)) >= -256
17267 && INTVAL (XEXP (x, 1)) <= 255)
06a67bdd 17268 *total = rs6000_cost->mulsi_const9;
8b897cfa 17269 else
06a67bdd 17270 *total = rs6000_cost->mulsi_const;
3c50106f 17271 }
066cd967
DE
17272 /* FMA accounted in outer PLUS/MINUS. */
17273 else if ((mode == DFmode || mode == SFmode)
17274 && (outer_code == PLUS || outer_code == MINUS))
17275 *total = 0;
f0517163 17276 else if (mode == DFmode)
06a67bdd 17277 *total = rs6000_cost->dmul;
f0517163 17278 else if (mode == SFmode)
06a67bdd 17279 *total = rs6000_cost->fp;
f0517163 17280 else if (mode == DImode)
06a67bdd 17281 *total = rs6000_cost->muldi;
8b897cfa 17282 else
06a67bdd 17283 *total = rs6000_cost->mulsi;
066cd967 17284 return false;
3c50106f
RH
17285
17286 case DIV:
17287 case MOD:
f0517163
RS
17288 if (FLOAT_MODE_P (mode))
17289 {
06a67bdd
RS
17290 *total = mode == DFmode ? rs6000_cost->ddiv
17291 : rs6000_cost->sdiv;
066cd967 17292 return false;
f0517163 17293 }
5efb1046 17294 /* FALLTHRU */
3c50106f
RH
17295
17296 case UDIV:
17297 case UMOD:
627b6fe2
DJ
17298 if (GET_CODE (XEXP (x, 1)) == CONST_INT
17299 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
17300 {
17301 if (code == DIV || code == MOD)
17302 /* Shift, addze */
17303 *total = COSTS_N_INSNS (2);
17304 else
17305 /* Shift */
17306 *total = COSTS_N_INSNS (1);
17307 }
17308 else
17309 {
17310 if (GET_MODE (XEXP (x, 1)) == DImode)
17311 *total = rs6000_cost->divdi;
17312 else
17313 *total = rs6000_cost->divsi;
17314 }
17315 /* Add in shift and subtract for MOD. */
17316 if (code == MOD || code == UMOD)
17317 *total += COSTS_N_INSNS (2);
066cd967 17318 return false;
3c50106f
RH
17319
17320 case FFS:
17321 *total = COSTS_N_INSNS (4);
066cd967 17322 return false;
3c50106f 17323
06a67bdd 17324 case NOT:
066cd967
DE
17325 if (outer_code == AND || outer_code == IOR || outer_code == XOR)
17326 {
17327 *total = 0;
17328 return false;
17329 }
17330 /* FALLTHRU */
17331
17332 case AND:
17333 case IOR:
17334 case XOR:
d5861a7a
DE
17335 case ZERO_EXTRACT:
17336 *total = COSTS_N_INSNS (1);
17337 return false;
17338
066cd967
DE
17339 case ASHIFT:
17340 case ASHIFTRT:
17341 case LSHIFTRT:
17342 case ROTATE:
17343 case ROTATERT:
d5861a7a 17344 /* Handle mul_highpart. */
066cd967
DE
17345 if (outer_code == TRUNCATE
17346 && GET_CODE (XEXP (x, 0)) == MULT)
17347 {
17348 if (mode == DImode)
17349 *total = rs6000_cost->muldi;
17350 else
17351 *total = rs6000_cost->mulsi;
17352 return true;
17353 }
d5861a7a
DE
17354 else if (outer_code == AND)
17355 *total = 0;
17356 else
17357 *total = COSTS_N_INSNS (1);
17358 return false;
17359
17360 case SIGN_EXTEND:
17361 case ZERO_EXTEND:
17362 if (GET_CODE (XEXP (x, 0)) == MEM)
17363 *total = 0;
17364 else
17365 *total = COSTS_N_INSNS (1);
066cd967 17366 return false;
06a67bdd 17367
066cd967
DE
17368 case COMPARE:
17369 case NEG:
17370 case ABS:
17371 if (!FLOAT_MODE_P (mode))
17372 {
17373 *total = COSTS_N_INSNS (1);
17374 return false;
17375 }
17376 /* FALLTHRU */
17377
17378 case FLOAT:
17379 case UNSIGNED_FLOAT:
17380 case FIX:
17381 case UNSIGNED_FIX:
17382 case FLOAT_EXTEND:
06a67bdd
RS
17383 case FLOAT_TRUNCATE:
17384 *total = rs6000_cost->fp;
066cd967 17385 return false;
06a67bdd
RS
17386
17387 case UNSPEC:
17388 switch (XINT (x, 1))
17389 {
17390 case UNSPEC_FRSP:
17391 *total = rs6000_cost->fp;
17392 return true;
17393
17394 default:
17395 break;
17396 }
17397 break;
17398
17399 case CALL:
17400 case IF_THEN_ELSE:
17401 if (optimize_size)
17402 {
17403 *total = COSTS_N_INSNS (1);
17404 return true;
17405 }
066cd967
DE
17406 else if (FLOAT_MODE_P (mode)
17407 && TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT && TARGET_FPRS)
17408 {
17409 *total = rs6000_cost->fp;
17410 return false;
17411 }
17412
06a67bdd
RS
17413 break;
17414
3c50106f 17415 default:
06a67bdd 17416 break;
3c50106f 17417 }
06a67bdd
RS
17418
17419 return false;
3c50106f
RH
17420}
17421
34bb030a
DE
17422/* A C expression returning the cost of moving data from a register of class
17423 CLASS1 to one of CLASS2. */
17424
17425int
f676971a 17426rs6000_register_move_cost (enum machine_mode mode,
a2369ed3 17427 enum reg_class from, enum reg_class to)
34bb030a
DE
17428{
17429 /* Moves from/to GENERAL_REGS. */
17430 if (reg_classes_intersect_p (to, GENERAL_REGS)
17431 || reg_classes_intersect_p (from, GENERAL_REGS))
17432 {
17433 if (! reg_classes_intersect_p (to, GENERAL_REGS))
17434 from = to;
17435
17436 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
17437 return (rs6000_memory_move_cost (mode, from, 0)
17438 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
17439
a3c9585f 17440/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
17441 else if (from == CR_REGS)
17442 return 4;
17443
17444 else
17445/* A move will cost one instruction per GPR moved. */
17446 return 2 * HARD_REGNO_NREGS (0, mode);
17447 }
17448
17449/* Moving between two similar registers is just one instruction. */
17450 else if (reg_classes_intersect_p (to, from))
17451 return mode == TFmode ? 4 : 2;
17452
17453/* Everything else has to go through GENERAL_REGS. */
17454 else
f676971a 17455 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
34bb030a
DE
17456 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
17457}
17458
17459/* A C expressions returning the cost of moving data of MODE from a register to
17460 or from memory. */
17461
17462int
f676971a 17463rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
a2369ed3 17464 int in ATTRIBUTE_UNUSED)
34bb030a
DE
17465{
17466 if (reg_classes_intersect_p (class, GENERAL_REGS))
17467 return 4 * HARD_REGNO_NREGS (0, mode);
17468 else if (reg_classes_intersect_p (class, FLOAT_REGS))
17469 return 4 * HARD_REGNO_NREGS (32, mode);
17470 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
17471 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
17472 else
17473 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
17474}
17475
ded9bf77
AH
17476/* Return an RTX representing where to find the function value of a
17477 function returning MODE. */
17478static rtx
17479rs6000_complex_function_value (enum machine_mode mode)
17480{
17481 unsigned int regno;
17482 rtx r1, r2;
17483 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 17484 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77 17485
4ed78545 17486 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
ded9bf77
AH
17487 regno = FP_ARG_RETURN;
17488 else
17489 {
17490 regno = GP_ARG_RETURN;
17491
17492 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 17493 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
17494 return gen_rtx_REG (mode, regno);
17495 }
17496
fb7e4164
AM
17497 if (inner_bytes >= 8)
17498 return gen_rtx_REG (mode, regno);
17499
ded9bf77
AH
17500 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
17501 const0_rtx);
17502 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 17503 GEN_INT (inner_bytes));
ded9bf77
AH
17504 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
17505}
17506
a6ebc39a
AH
17507/* Define how to find the value returned by a function.
17508 VALTYPE is the data type of the value (as a tree).
17509 If the precise function being called is known, FUNC is its FUNCTION_DECL;
17510 otherwise, FUNC is 0.
17511
17512 On the SPE, both FPs and vectors are returned in r3.
17513
17514 On RS/6000 an integer value is in r3 and a floating-point value is in
17515 fp1, unless -msoft-float. */
17516
17517rtx
17518rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
17519{
17520 enum machine_mode mode;
2a8fa26c 17521 unsigned int regno;
a6ebc39a 17522
0e67400a
FJ
17523 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
17524 {
17525 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
17526 return gen_rtx_PARALLEL (DImode,
17527 gen_rtvec (2,
17528 gen_rtx_EXPR_LIST (VOIDmode,
17529 gen_rtx_REG (SImode, GP_ARG_RETURN),
17530 const0_rtx),
17531 gen_rtx_EXPR_LIST (VOIDmode,
17532 gen_rtx_REG (SImode,
17533 GP_ARG_RETURN + 1),
17534 GEN_INT (4))));
17535 }
17536
a6ebc39a
AH
17537 if ((INTEGRAL_TYPE_P (valtype)
17538 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
17539 || POINTER_TYPE_P (valtype))
b78d48dd 17540 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
17541 else
17542 mode = TYPE_MODE (valtype);
17543
4ed78545 17544 if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS)
2a8fa26c 17545 regno = FP_ARG_RETURN;
ded9bf77 17546 else if (TREE_CODE (valtype) == COMPLEX_TYPE
42ba5130 17547 && targetm.calls.split_complex_arg)
ded9bf77 17548 return rs6000_complex_function_value (mode);
44688022 17549 else if (TREE_CODE (valtype) == VECTOR_TYPE
d0b2079e
FJ
17550 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI
17551 && ALTIVEC_VECTOR_MODE(mode))
a6ebc39a
AH
17552 regno = ALTIVEC_ARG_RETURN;
17553 else
17554 regno = GP_ARG_RETURN;
17555
17556 return gen_rtx_REG (mode, regno);
17557}
17558
ded9bf77
AH
17559/* Define how to find the value returned by a library function
17560 assuming the value has mode MODE. */
17561rtx
17562rs6000_libcall_value (enum machine_mode mode)
17563{
17564 unsigned int regno;
17565
2e6c9641
FJ
17566 if (TARGET_32BIT && TARGET_POWERPC64 && mode == DImode)
17567 {
17568 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
17569 return gen_rtx_PARALLEL (DImode,
17570 gen_rtvec (2,
17571 gen_rtx_EXPR_LIST (VOIDmode,
17572 gen_rtx_REG (SImode, GP_ARG_RETURN),
17573 const0_rtx),
17574 gen_rtx_EXPR_LIST (VOIDmode,
17575 gen_rtx_REG (SImode,
17576 GP_ARG_RETURN + 1),
17577 GEN_INT (4))));
17578 }
17579
ded9bf77
AH
17580 if (GET_MODE_CLASS (mode) == MODE_FLOAT
17581 && TARGET_HARD_FLOAT && TARGET_FPRS)
17582 regno = FP_ARG_RETURN;
44688022
AM
17583 else if (ALTIVEC_VECTOR_MODE (mode)
17584 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
ded9bf77 17585 regno = ALTIVEC_ARG_RETURN;
42ba5130 17586 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
17587 return rs6000_complex_function_value (mode);
17588 else
17589 regno = GP_ARG_RETURN;
17590
17591 return gen_rtx_REG (mode, regno);
17592}
17593
d1d0c603
JJ
17594/* Define the offset between two registers, FROM to be eliminated and its
17595 replacement TO, at the start of a routine. */
17596HOST_WIDE_INT
17597rs6000_initial_elimination_offset (int from, int to)
17598{
17599 rs6000_stack_t *info = rs6000_stack_info ();
17600 HOST_WIDE_INT offset;
17601
17602 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
17603 offset = info->push_p ? 0 : -info->total_size;
17604 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
17605 offset = info->total_size;
17606 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
17607 offset = info->push_p ? info->total_size : 0;
17608 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
17609 offset = 0;
17610 else
17611 abort ();
17612
17613 return offset;
17614}
17615
62e1dfcf
NC
17616/* Return true if TYPE is of type __ev64_opaque__. */
17617
c8e4f0e9 17618static bool
a2369ed3 17619is_ev64_opaque_type (tree type)
62e1dfcf 17620{
c8e4f0e9 17621 return (TARGET_SPE
2abe3e28
AH
17622 && (type == opaque_V2SI_type_node
17623 || type == opaque_V2SF_type_node
36252949 17624 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
17625}
17626
96714395 17627static rtx
a2369ed3 17628rs6000_dwarf_register_span (rtx reg)
96714395
AH
17629{
17630 unsigned regno;
17631
17632 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
17633 return NULL_RTX;
17634
17635 regno = REGNO (reg);
17636
17637 /* The duality of the SPE register size wreaks all kinds of havoc.
17638 This is a way of distinguishing r0 in 32-bits from r0 in
17639 64-bits. */
17640 return
17641 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
17642 BYTES_BIG_ENDIAN
17643 ? gen_rtvec (2,
17644 gen_rtx_REG (SImode, regno + 1200),
17645 gen_rtx_REG (SImode, regno))
17646 : gen_rtvec (2,
17647 gen_rtx_REG (SImode, regno),
17648 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
17649}
17650
93c9d1ba
AM
17651/* Map internal gcc register numbers to DWARF2 register numbers. */
17652
17653unsigned int
17654rs6000_dbx_register_number (unsigned int regno)
17655{
17656 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
17657 return regno;
17658 if (regno == MQ_REGNO)
17659 return 100;
17660 if (regno == LINK_REGISTER_REGNUM)
17661 return 108;
17662 if (regno == COUNT_REGISTER_REGNUM)
17663 return 109;
17664 if (CR_REGNO_P (regno))
17665 return regno - CR0_REGNO + 86;
17666 if (regno == XER_REGNO)
17667 return 101;
17668 if (ALTIVEC_REGNO_P (regno))
17669 return regno - FIRST_ALTIVEC_REGNO + 1124;
17670 if (regno == VRSAVE_REGNO)
17671 return 356;
17672 if (regno == VSCR_REGNO)
17673 return 67;
17674 if (regno == SPE_ACC_REGNO)
17675 return 99;
17676 if (regno == SPEFSCR_REGNO)
17677 return 612;
17678 /* SPE high reg number. We get these values of regno from
17679 rs6000_dwarf_register_span. */
17680 if (regno >= 1200 && regno < 1232)
17681 return regno;
17682
17683 abort ();
17684}
17685
93f90be6 17686/* target hook eh_return_filter_mode */
f676971a 17687static enum machine_mode
93f90be6
FJ
17688rs6000_eh_return_filter_mode (void)
17689{
17690 return TARGET_32BIT ? SImode : word_mode;
17691}
17692
f676971a
EC
17693/* Target hook for vector_mode_supported_p. */
17694static bool
17695rs6000_vector_mode_supported_p (enum machine_mode mode)
17696{
17697
17698 if (TARGET_SPE && SPE_VECTOR_MODE (mode))
17699 return true;
17700
17701 else if (TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
17702 return true;
17703
17704 else
17705 return false;
17706}
17707
17211ab5 17708#include "gt-rs6000.h"