]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
toplev.c (independent_decode_option): Return success for --help, --target-help and...
[thirdparty/gcc.git] / gcc / config / rs6000 / rs6000.c
CommitLineData
9878760c 1/* Subroutines used for code generation on IBM RS/6000.
9ebbca7d 2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
d3c300d2 3 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
fab3bcc3 4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
9878760c
RK
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13GNU CC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU CC; see the file COPYING. If not, write to
c15c9075
RK
20the Free Software Foundation, 59 Temple Place - Suite 330,
21Boston, 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"
9b30bae2 53
7509c759
MM
54#ifndef TARGET_NO_PROTOTYPE
55#define TARGET_NO_PROTOTYPE 0
56#endif
57
9878760c
RK
58#define min(A,B) ((A) < (B) ? (A) : (B))
59#define max(A,B) ((A) > (B) ? (A) : (B))
60
5248c961
RK
61/* Target cpu type */
62
63enum processor_type rs6000_cpu;
8e3f41e7
MM
64struct rs6000_cpu_select rs6000_select[3] =
65{
815cdc52
MM
66 /* switch name, tune arch */
67 { (const char *)0, "--with-cpu=", 1, 1 },
68 { (const char *)0, "-mcpu=", 1, 1 },
69 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 70};
5248c961 71
6fa3f289
ZW
72/* Size of long double */
73const char *rs6000_long_double_size_string;
74int rs6000_long_double_type_size;
75
76/* Whether -mabi=altivec has appeared */
77int rs6000_altivec_abi;
78
08b57fb3
AH
79/* Whether VRSAVE instructions should be generated. */
80int rs6000_altivec_vrsave;
81
82/* String from -mvrsave= option. */
83const char *rs6000_altivec_vrsave_string;
84
a3170dc6
AH
85/* Nonzero if we want SPE ABI extensions. */
86int rs6000_spe_abi;
87
88/* Whether isel instructions should be generated. */
89int rs6000_isel;
90
91/* Nonzero if we have FPRs. */
92int rs6000_fprs = 1;
93
94/* String from -misel=. */
95const char *rs6000_isel_string;
96
a0ab749a 97/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 98static GTY(()) int common_mode_defined;
c81bebd7 99
0e5dbd9b
DE
100/* Private copy of original value of flag_pic for ABI_AIX. */
101static int rs6000_flag_pic;
102
9878760c
RK
103/* Save information from a "cmpxx" operation until the branch or scc is
104 emitted. */
9878760c
RK
105rtx rs6000_compare_op0, rs6000_compare_op1;
106int rs6000_compare_fp_p;
874a0744 107
874a0744
MM
108/* Label number of label created for -mrelocatable, to call to so we can
109 get the address of the GOT section */
110int rs6000_pic_labelno;
c81bebd7 111
b91da81f 112#ifdef USING_ELFOS_H
c81bebd7 113/* Which abi to adhere to */
815cdc52 114const char *rs6000_abi_name = RS6000_ABI_NAME;
d9407988
MM
115
116/* Semantics of the small data area */
117enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
118
119/* Which small data model to use */
815cdc52 120const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
121
122/* Counter for labels which are to be placed in .fixup. */
123int fixuplabelno = 0;
874a0744 124#endif
4697a36c 125
b6c9286a
MM
126/* ABI enumeration available for subtarget to use. */
127enum rs6000_abi rs6000_current_abi;
128
0ac081f6
AH
129/* ABI string from -mabi= option. */
130const char *rs6000_abi_string;
131
38c1f2d7 132/* Debug flags */
815cdc52 133const char *rs6000_debug_name;
38c1f2d7
MM
134int rs6000_debug_stack; /* debug stack applications */
135int rs6000_debug_arg; /* debug argument handling */
136
57ac7be9
AM
137const char *rs6000_traceback_name;
138static enum {
139 traceback_default = 0,
140 traceback_none,
141 traceback_part,
142 traceback_full
143} rs6000_traceback;
144
38c1f2d7
MM
145/* Flag to say the TOC is initialized */
146int toc_initialized;
9ebbca7d 147char toc_label_name[10];
38c1f2d7 148
9ebbca7d
GK
149/* Alias set for saves and restores from the rs6000 stack. */
150static int rs6000_sr_alias_set;
c8023011 151
a5c76ee6
ZW
152/* Call distance, overridden by -mlongcall and #pragma longcall(1).
153 The only place that looks at this is rs6000_set_default_type_attributes;
154 everywhere else should rely on the presence or absence of a longcall
155 attribute on the function declaration. */
156int rs6000_default_long_calls;
157const char *rs6000_longcall_switch;
158
a3170dc6
AH
159struct builtin_description
160{
161 /* mask is not const because we're going to alter it below. This
162 nonsense will go away when we rewrite the -march infrastructure
163 to give us more target flag bits. */
164 unsigned int mask;
165 const enum insn_code icode;
166 const char *const name;
167 const enum rs6000_builtins code;
168};
169
4977bab6 170static bool rs6000_function_ok_for_sibcall PARAMS ((tree, tree));
9ebbca7d 171static int num_insns_constant_wide PARAMS ((HOST_WIDE_INT));
39a10a29
GK
172static void validate_condition_mode
173 PARAMS ((enum rtx_code, enum machine_mode));
174static rtx rs6000_generate_compare PARAMS ((enum rtx_code));
e50f5f3d 175static void rs6000_maybe_dead PARAMS ((rtx));
9ebbca7d
GK
176static void rs6000_emit_stack_tie PARAMS ((void));
177static void rs6000_frame_related PARAMS ((rtx, rtx, HOST_WIDE_INT, rtx, rtx));
c19de7aa
AH
178static rtx spe_synthesize_frame_save PARAMS ((rtx));
179static bool spe_func_has_64bit_regs_p PARAMS ((void));
89e7058f
AH
180static void emit_frame_save PARAMS ((rtx, rtx, enum machine_mode,
181 unsigned int, int, int));
a3170dc6 182static rtx gen_frame_mem_offset PARAMS ((enum machine_mode, rtx, int));
9ebbca7d
GK
183static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
184static unsigned rs6000_hash_constant PARAMS ((rtx));
185static unsigned toc_hash_function PARAMS ((const void *));
186static int toc_hash_eq PARAMS ((const void *, const void *));
9ebbca7d 187static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
e2500fed 188static struct machine_function * rs6000_init_machine_status PARAMS ((void));
301d03af 189static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int));
5add3202 190#ifdef HAVE_GAS_HIDDEN
25fdb4dc 191static void rs6000_assemble_visibility PARAMS ((tree, int));
5add3202 192#endif
71f123ca 193static int rs6000_ra_ever_killed PARAMS ((void));
91d231cb
JM
194static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *));
195const struct attribute_spec rs6000_attribute_table[];
a5c76ee6 196static void rs6000_set_default_type_attributes PARAMS ((tree));
08c148a8
NB
197static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
198static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
3961e8fe
RH
199static void rs6000_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
200 HOST_WIDE_INT, tree));
2bfcf297
DB
201static rtx rs6000_emit_set_long_const PARAMS ((rtx,
202 HOST_WIDE_INT, HOST_WIDE_INT));
7c262518
RH
203#if TARGET_ELF
204static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *,
205 int));
d9f6800d
RH
206static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
207static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
ae46c4e0 208static void rs6000_elf_select_section PARAMS ((tree, int,
5b71a4e7 209 unsigned HOST_WIDE_INT));
ae46c4e0 210static void rs6000_elf_unique_section PARAMS ((tree, int));
b64a1b53
RH
211static void rs6000_elf_select_rtx_section PARAMS ((enum machine_mode, rtx,
212 unsigned HOST_WIDE_INT));
0e5dbd9b
DE
213static void rs6000_elf_encode_section_info PARAMS ((tree, int))
214 ATTRIBUTE_UNUSED;
772c5265 215static const char *rs6000_elf_strip_name_encoding PARAMS ((const char *));
0e5dbd9b 216static bool rs6000_elf_in_small_data_p PARAMS ((tree));
7c262518 217#endif
cbaaba19 218#if TARGET_XCOFF
b275d088
DE
219static void rs6000_xcoff_asm_globalize_label PARAMS ((FILE *, const char *));
220static void rs6000_xcoff_asm_named_section PARAMS ((const char *, unsigned int));
ae46c4e0
RH
221static void rs6000_xcoff_select_section PARAMS ((tree, int,
222 unsigned HOST_WIDE_INT));
223static void rs6000_xcoff_unique_section PARAMS ((tree, int));
b64a1b53
RH
224static void rs6000_xcoff_select_rtx_section PARAMS ((enum machine_mode, rtx,
225 unsigned HOST_WIDE_INT));
772c5265 226static const char * rs6000_xcoff_strip_name_encoding PARAMS ((const char *));
5add3202 227static unsigned int rs6000_xcoff_section_type_flags PARAMS ((tree, const char *, int));
7c262518 228#endif
fb49053f
RH
229static void rs6000_xcoff_encode_section_info PARAMS ((tree, int))
230 ATTRIBUTE_UNUSED;
2bcc50d0 231static bool rs6000_binds_local_p PARAMS ((tree));
b54cf83a 232static int rs6000_use_dfa_pipeline_interface PARAMS ((void));
b54cf83a 233static int rs6000_variable_issue PARAMS ((FILE *, int, rtx, int));
3c50106f 234static bool rs6000_rtx_costs PARAMS ((rtx, int, int, int *));
c237e94a
ZW
235static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int));
236static int rs6000_adjust_priority PARAMS ((rtx, int));
237static int rs6000_issue_rate PARAMS ((void));
238
6fa3f289 239static void rs6000_init_builtins PARAMS ((void));
92898235
AH
240static rtx rs6000_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
241static rtx rs6000_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
242static rtx rs6000_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
0ac081f6 243static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
92898235 244static void altivec_init_builtins PARAMS ((void));
a3170dc6
AH
245static void rs6000_common_init_builtins PARAMS ((void));
246
247static void enable_mask_for_builtins PARAMS ((struct builtin_description *,
248 int, enum rs6000_builtins,
249 enum rs6000_builtins));
250static void spe_init_builtins PARAMS ((void));
251static rtx spe_expand_builtin PARAMS ((tree, rtx, bool *));
252static rtx spe_expand_predicate_builtin PARAMS ((enum insn_code, tree, rtx));
253static rtx spe_expand_evsel_builtin PARAMS ((enum insn_code, tree, rtx));
254static int rs6000_emit_int_cmove PARAMS ((rtx, rtx, rtx, rtx));
255
92898235 256static rtx altivec_expand_builtin PARAMS ((tree, rtx, bool *));
3a9b8c7e
AH
257static rtx altivec_expand_ld_builtin PARAMS ((tree, rtx, bool *));
258static rtx altivec_expand_st_builtin PARAMS ((tree, rtx, bool *));
259static rtx altivec_expand_dst_builtin PARAMS ((tree, rtx, bool *));
100c4561 260static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx));
ae4b4a02 261static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
6525c0e7 262static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
0ac081f6 263static void rs6000_parse_abi_options PARAMS ((void));
08b57fb3 264static void rs6000_parse_vrsave_option PARAMS ((void));
a3170dc6 265static void rs6000_parse_isel_option PARAMS ((void));
00b960c7
AH
266static int first_altivec_reg_to_save PARAMS ((void));
267static unsigned int compute_vrsave_mask PARAMS ((void));
268static void is_altivec_return_reg PARAMS ((rtx, void *));
9aa86737 269static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
69ef87e2 270static int easy_vector_constant PARAMS ((rtx));
c8e4f0e9 271static bool is_ev64_opaque_type PARAMS ((tree));
96714395 272static rtx rs6000_dwarf_register_span PARAMS ((rtx));
17211ab5
GK
273
274/* Hash table stuff for keeping track of TOC entries. */
275
276struct toc_hash_struct GTY(())
277{
278 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
279 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
280 rtx key;
281 enum machine_mode key_mode;
282 int labelno;
283};
284
285static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
286\f
287/* Default register names. */
288char rs6000_reg_names[][8] =
289{
802a0058
MM
290 "0", "1", "2", "3", "4", "5", "6", "7",
291 "8", "9", "10", "11", "12", "13", "14", "15",
292 "16", "17", "18", "19", "20", "21", "22", "23",
293 "24", "25", "26", "27", "28", "29", "30", "31",
294 "0", "1", "2", "3", "4", "5", "6", "7",
295 "8", "9", "10", "11", "12", "13", "14", "15",
296 "16", "17", "18", "19", "20", "21", "22", "23",
297 "24", "25", "26", "27", "28", "29", "30", "31",
298 "mq", "lr", "ctr","ap",
299 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
300 "xer",
301 /* AltiVec registers. */
0cd5e3a1
AH
302 "0", "1", "2", "3", "4", "5", "6", "7",
303 "8", "9", "10", "11", "12", "13", "14", "15",
304 "16", "17", "18", "19", "20", "21", "22", "23",
305 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
306 "vrsave", "vscr",
307 /* SPE registers. */
308 "spe_acc", "spefscr"
c81bebd7
MM
309};
310
311#ifdef TARGET_REGNAMES
8b60264b 312static const char alt_reg_names[][8] =
c81bebd7 313{
802a0058
MM
314 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
315 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
316 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
317 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
318 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
319 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
320 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
321 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
322 "mq", "lr", "ctr", "ap",
323 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 324 "xer",
59a4c851 325 /* AltiVec registers. */
0ac081f6 326 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
327 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
328 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
329 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
330 "vrsave", "vscr",
331 /* SPE registers. */
332 "spe_acc", "spefscr"
c81bebd7
MM
333};
334#endif
9878760c 335\f
daf11973
MM
336#ifndef MASK_STRICT_ALIGN
337#define MASK_STRICT_ALIGN 0
338#endif
3961e8fe
RH
339
340/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
341#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
672a6f42
NB
342\f
343/* Initialize the GCC target structure. */
91d231cb
JM
344#undef TARGET_ATTRIBUTE_TABLE
345#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
346#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
347#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 348
301d03af
RS
349#undef TARGET_ASM_ALIGNED_DI_OP
350#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
351
352/* Default unaligned ops are only provided for ELF. Find the ops needed
353 for non-ELF systems. */
354#ifndef OBJECT_FORMAT_ELF
cbaaba19 355#if TARGET_XCOFF
ae6c1efd 356/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
357 64-bit targets. */
358#undef TARGET_ASM_UNALIGNED_HI_OP
359#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
360#undef TARGET_ASM_UNALIGNED_SI_OP
361#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
362#undef TARGET_ASM_UNALIGNED_DI_OP
363#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
364#else
365/* For Darwin. */
366#undef TARGET_ASM_UNALIGNED_HI_OP
367#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
368#undef TARGET_ASM_UNALIGNED_SI_OP
369#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
370#endif
371#endif
372
373/* This hook deals with fixups for relocatable code and DI-mode objects
374 in 64-bit code. */
375#undef TARGET_ASM_INTEGER
376#define TARGET_ASM_INTEGER rs6000_assemble_integer
377
93638d7a
AM
378#ifdef HAVE_GAS_HIDDEN
379#undef TARGET_ASM_ASSEMBLE_VISIBILITY
380#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
381#endif
382
08c148a8
NB
383#undef TARGET_ASM_FUNCTION_PROLOGUE
384#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
385#undef TARGET_ASM_FUNCTION_EPILOGUE
386#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
387
b54cf83a
DE
388#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
389#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
390#undef TARGET_SCHED_VARIABLE_ISSUE
391#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
392
c237e94a
ZW
393#undef TARGET_SCHED_ISSUE_RATE
394#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
395#undef TARGET_SCHED_ADJUST_COST
396#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
397#undef TARGET_SCHED_ADJUST_PRIORITY
398#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
399
0ac081f6
AH
400#undef TARGET_INIT_BUILTINS
401#define TARGET_INIT_BUILTINS rs6000_init_builtins
402
403#undef TARGET_EXPAND_BUILTIN
404#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
405
0e5dbd9b
DE
406#undef TARGET_BINDS_LOCAL_P
407#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
408
3961e8fe
RH
409#undef TARGET_ASM_OUTPUT_MI_THUNK
410#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
411
3961e8fe 412#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 413#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 414
4977bab6
ZW
415#undef TARGET_FUNCTION_OK_FOR_SIBCALL
416#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
417
3c50106f
RH
418#undef TARGET_RTX_COSTS
419#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
420#undef TARGET_ADDRESS_COST
421#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 422
c8e4f0e9
AH
423#undef TARGET_VECTOR_OPAQUE_P
424#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 425
96714395
AH
426#undef TARGET_DWARF_REGISTER_SPAN
427#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
428
f6897b10 429struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 430\f
5248c961
RK
431/* Override command line options. Mostly we process the processor
432 type and sometimes adjust other TARGET_ options. */
433
434void
8e3f41e7 435rs6000_override_options (default_cpu)
d330fd93 436 const char *default_cpu;
5248c961 437{
c4d38ccb 438 size_t i, j;
8e3f41e7 439 struct rs6000_cpu_select *ptr;
5248c961 440
85638c0d
RK
441 /* Simplify the entries below by making a mask for any POWER
442 variant and any PowerPC variant. */
443
938937d8 444#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
445#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
446 | MASK_PPC_GFXOPT | MASK_POWERPC64)
447#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 448
5248c961
RK
449 static struct ptt
450 {
8b60264b
KG
451 const char *const name; /* Canonical processor name. */
452 const enum processor_type processor; /* Processor type enum value. */
453 const int target_enable; /* Target flags to enable. */
454 const int target_disable; /* Target flags to disable. */
455 } const processor_target_table[]
cf27b467
MM
456 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
457 POWER_MASKS | POWERPC_MASKS},
db7f1e43 458 {"power", PROCESSOR_POWER,
938937d8 459 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 460 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
461 {"power2", PROCESSOR_POWER,
462 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
463 POWERPC_MASKS | MASK_NEW_MNEMONICS},
c71791e0
DE
464 {"power3", PROCESSOR_PPC630,
465 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 466 POWER_MASKS},
309323c2 467 {"power4", PROCESSOR_POWER4,
7f3d8013
DJ
468 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
469 POWER_MASKS | MASK_PPC_GPOPT},
db7f1e43
RK
470 {"powerpc", PROCESSOR_POWERPC,
471 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 472 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
3cb999d8
DE
473 {"powerpc64", PROCESSOR_POWERPC64,
474 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
475 POWER_MASKS | POWERPC_OPT_MASKS},
db7f1e43 476 {"rios", PROCESSOR_RIOS1,
938937d8 477 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
478 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
479 {"rios1", PROCESSOR_RIOS1,
938937d8 480 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
481 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
482 {"rsc", PROCESSOR_PPC601,
938937d8 483 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
484 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
485 {"rsc1", PROCESSOR_PPC601,
938937d8 486 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
487 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
488 {"rios2", PROCESSOR_RIOS2,
938937d8 489 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 490 POWERPC_MASKS | MASK_NEW_MNEMONICS},
3cb999d8
DE
491 {"rs64a", PROCESSOR_RS64A,
492 MASK_POWERPC | MASK_NEW_MNEMONICS,
493 POWER_MASKS | POWERPC_OPT_MASKS},
a3a1dbf6
MM
494 {"401", PROCESSOR_PPC403,
495 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
496 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
49a0b204 497 {"403", PROCESSOR_PPC403,
daf11973 498 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 499 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
d7a5e253
DE
500 {"405", PROCESSOR_PPC405,
501 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
502 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
4977bab6
ZW
503 {"405f", PROCESSOR_PPC405,
504 MASK_POWERPC | MASK_NEW_MNEMONICS,
505 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
506 {"505", PROCESSOR_MPCCORE,
507 MASK_POWERPC | MASK_NEW_MNEMONICS,
508 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 509 {"601", PROCESSOR_PPC601,
938937d8 510 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 511 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 512 {"602", PROCESSOR_PPC603,
cf27b467
MM
513 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
514 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 515 {"603", PROCESSOR_PPC603,
68c49ffa
RK
516 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
517 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
518 {"603e", PROCESSOR_PPC603,
519 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
520 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b5370a88 521 {"ec603e", PROCESSOR_PPC603,
a3a1dbf6
MM
522 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
523 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 524 {"604", PROCESSOR_PPC604,
b6c9286a
MM
525 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
526 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
cac8ce95 527 {"604e", PROCESSOR_PPC604e,
07e6159a
MM
528 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
529 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 530 {"620", PROCESSOR_PPC620,
68c49ffa 531 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 532 POWER_MASKS},
3cb999d8
DE
533 {"630", PROCESSOR_PPC630,
534 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
d7b53ca4 535 POWER_MASKS},
bef84347
VM
536 {"740", PROCESSOR_PPC750,
537 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
538 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
539 {"750", PROCESSOR_PPC750,
540 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
541 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a4f6c312
SS
542 {"7400", PROCESSOR_PPC7400,
543 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
544 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
545 {"7450", PROCESSOR_PPC7450,
546 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
547 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a3170dc6
AH
548 {"8540", PROCESSOR_PPC8540,
549 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
550 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
551 {"801", PROCESSOR_MPCCORE,
552 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
553 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
554 {"821", PROCESSOR_MPCCORE,
555 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
556 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
557 {"823", PROCESSOR_MPCCORE,
558 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
559 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
560 {"860", PROCESSOR_MPCCORE,
561 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
562 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
5248c961 563
ca7558fc 564 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 565
a4f6c312
SS
566 /* Save current -mmultiple/-mno-multiple status. */
567 int multiple = TARGET_MULTIPLE;
568 /* Save current -mstring/-mno-string status. */
569 int string = TARGET_STRING;
8a61d227 570
a4f6c312 571 /* Identify the processor type. */
8e3f41e7 572 rs6000_select[0].string = default_cpu;
3cb999d8 573 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 574
b6a1cbae 575 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 576 {
8e3f41e7
MM
577 ptr = &rs6000_select[i];
578 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 579 {
8e3f41e7
MM
580 for (j = 0; j < ptt_size; j++)
581 if (! strcmp (ptr->string, processor_target_table[j].name))
582 {
583 if (ptr->set_tune_p)
584 rs6000_cpu = processor_target_table[j].processor;
585
586 if (ptr->set_arch_p)
587 {
588 target_flags |= processor_target_table[j].target_enable;
589 target_flags &= ~processor_target_table[j].target_disable;
590 }
591 break;
592 }
593
4406229e 594 if (j == ptt_size)
8e3f41e7 595 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
596 }
597 }
8a61d227 598
a3170dc6
AH
599 if (rs6000_cpu == PROCESSOR_PPC8540)
600 rs6000_isel = 1;
601
dff9f1b6
DE
602 /* If we are optimizing big endian systems for space, use the load/store
603 multiple and string instructions. */
ef792183 604 if (BYTES_BIG_ENDIAN && optimize_size)
dff9f1b6 605 target_flags |= MASK_MULTIPLE | MASK_STRING;
ef792183 606
8a61d227
MM
607 /* If -mmultiple or -mno-multiple was explicitly used, don't
608 override with the processor default */
b21fb038 609 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
8a61d227 610 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 611
a4f6c312
SS
612 /* If -mstring or -mno-string was explicitly used, don't override
613 with the processor default. */
b21fb038 614 if ((target_flags_explicit & MASK_STRING) != 0)
1f5515bf 615 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 616
a4f6c312
SS
617 /* Don't allow -mmultiple or -mstring on little endian systems
618 unless the cpu is a 750, because the hardware doesn't support the
619 instructions used in little endian mode, and causes an alignment
620 trap. The 750 does not cause an alignment trap (except when the
621 target is unaligned). */
bef84347 622
b21fb038 623 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
624 {
625 if (TARGET_MULTIPLE)
626 {
627 target_flags &= ~MASK_MULTIPLE;
b21fb038 628 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
629 warning ("-mmultiple is not supported on little endian systems");
630 }
631
632 if (TARGET_STRING)
633 {
634 target_flags &= ~MASK_STRING;
b21fb038 635 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 636 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
637 }
638 }
3933e0e1 639
ee2ca2a2 640 if (flag_pic != 0 && DEFAULT_ABI == ABI_AIX)
a260abc9 641 {
0e5dbd9b 642 rs6000_flag_pic = flag_pic;
ee2ca2a2 643 flag_pic = 0;
a260abc9
DE
644 }
645
38c1f2d7
MM
646 /* Set debug flags */
647 if (rs6000_debug_name)
648 {
bfc79d3b 649 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 650 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 651 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 652 rs6000_debug_stack = 1;
bfc79d3b 653 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
654 rs6000_debug_arg = 1;
655 else
c725bd79 656 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
657 }
658
57ac7be9
AM
659 if (rs6000_traceback_name)
660 {
661 if (! strncmp (rs6000_traceback_name, "full", 4))
662 rs6000_traceback = traceback_full;
663 else if (! strncmp (rs6000_traceback_name, "part", 4))
664 rs6000_traceback = traceback_part;
665 else if (! strncmp (rs6000_traceback_name, "no", 2))
666 rs6000_traceback = traceback_none;
667 else
668 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
669 rs6000_traceback_name);
670 }
671
6fa3f289
ZW
672 /* Set size of long double */
673 rs6000_long_double_type_size = 64;
674 if (rs6000_long_double_size_string)
675 {
676 char *tail;
677 int size = strtol (rs6000_long_double_size_string, &tail, 10);
678 if (*tail != '\0' || (size != 64 && size != 128))
679 error ("Unknown switch -mlong-double-%s",
680 rs6000_long_double_size_string);
681 else
682 rs6000_long_double_type_size = size;
683 }
684
0ac081f6
AH
685 /* Handle -mabi= options. */
686 rs6000_parse_abi_options ();
687
08b57fb3
AH
688 /* Handle -mvrsave= option. */
689 rs6000_parse_vrsave_option ();
690
a3170dc6
AH
691 /* Handle -misel= option. */
692 rs6000_parse_isel_option ();
693
a7ae18e2
AH
694#ifdef SUBTARGET_OVERRIDE_OPTIONS
695 SUBTARGET_OVERRIDE_OPTIONS;
696#endif
697#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
698 SUBSUBTARGET_OVERRIDE_OPTIONS;
699#endif
700
b5044283
AH
701 /* The e500 does not have string instructions, and we set
702 MASK_STRING above when optimizing for size. */
703 if (TARGET_SPE && (target_flags & MASK_STRING) != 0)
704 target_flags = target_flags & ~MASK_STRING;
705
a5c76ee6
ZW
706 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
707 using TARGET_OPTIONS to handle a toggle switch, but we're out of
708 bits in target_flags so TARGET_SWITCHES cannot be used.
709 Assumption here is that rs6000_longcall_switch points into the
710 text of the complete option, rather than being a copy, so we can
711 scan back for the presence or absence of the no- modifier. */
712 if (rs6000_longcall_switch)
713 {
714 const char *base = rs6000_longcall_switch;
715 while (base[-1] != 'm') base--;
716
717 if (*rs6000_longcall_switch != '\0')
718 error ("invalid option `%s'", base);
719 rs6000_default_long_calls = (base[0] != 'n');
720 }
721
c81bebd7 722#ifdef TARGET_REGNAMES
a4f6c312
SS
723 /* If the user desires alternate register names, copy in the
724 alternate names now. */
c81bebd7 725 if (TARGET_REGNAMES)
4e135bdd 726 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
727#endif
728
6fa3f289
ZW
729 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
730 If -maix-struct-return or -msvr4-struct-return was explicitly
731 used, don't override with the ABI default. */
b21fb038 732 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
733 {
734 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
735 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
736 else
737 target_flags |= MASK_AIX_STRUCT_RET;
738 }
739
fcce224d
DE
740 if (TARGET_LONG_DOUBLE_128
741 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
742 real_format_for_mode[TFmode - QFmode] = &ibm_extended_format;
743
9ebbca7d
GK
744 /* Allocate an alias set for register saves & restores from stack. */
745 rs6000_sr_alias_set = new_alias_set ();
746
747 if (TARGET_TOC)
748 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 749
301d03af
RS
750 /* We can only guarantee the availability of DI pseudo-ops when
751 assembling for 64-bit targets. */
ae6c1efd 752 if (!TARGET_64BIT)
301d03af
RS
753 {
754 targetm.asm_out.aligned_op.di = NULL;
755 targetm.asm_out.unaligned_op.di = NULL;
756 }
757
2792d578
DE
758 /* Set maximum branch target alignment at two instructions, eight bytes. */
759 align_jumps_max_skip = 8;
760 align_loops_max_skip = 8;
761
71f123ca
FS
762 /* Arrange to save and restore machine status around nested functions. */
763 init_machine_status = rs6000_init_machine_status;
5248c961 764}
5accd822 765
a3170dc6
AH
766/* Handle -misel= option. */
767static void
768rs6000_parse_isel_option ()
769{
770 if (rs6000_isel_string == 0)
771 return;
772 else if (! strcmp (rs6000_isel_string, "yes"))
773 rs6000_isel = 1;
774 else if (! strcmp (rs6000_isel_string, "no"))
775 rs6000_isel = 0;
776 else
777 error ("unknown -misel= option specified: '%s'",
778 rs6000_isel_string);
779}
780
08b57fb3
AH
781/* Handle -mvrsave= options. */
782static void
783rs6000_parse_vrsave_option ()
784{
785 /* Generate VRSAVE instructions by default. */
786 if (rs6000_altivec_vrsave_string == 0
787 || ! strcmp (rs6000_altivec_vrsave_string, "yes"))
788 rs6000_altivec_vrsave = 1;
789 else if (! strcmp (rs6000_altivec_vrsave_string, "no"))
790 rs6000_altivec_vrsave = 0;
791 else
792 error ("unknown -mvrsave= option specified: '%s'",
793 rs6000_altivec_vrsave_string);
794}
795
0ac081f6 796/* Handle -mabi= options. */
00b960c7
AH
797static void
798rs6000_parse_abi_options ()
0ac081f6
AH
799{
800 if (rs6000_abi_string == 0)
801 return;
802 else if (! strcmp (rs6000_abi_string, "altivec"))
6fa3f289 803 rs6000_altivec_abi = 1;
76a773f3
AH
804 else if (! strcmp (rs6000_abi_string, "no-altivec"))
805 rs6000_altivec_abi = 0;
a3170dc6 806 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
807 {
808 rs6000_spe_abi = 1;
809 if (!TARGET_SPE_ABI)
810 error ("not configured for ABI: '%s'", rs6000_abi_string);
811 }
812
a3170dc6
AH
813 else if (! strcmp (rs6000_abi_string, "no-spe"))
814 rs6000_spe_abi = 0;
0ac081f6 815 else
c725bd79 816 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
817}
818
5accd822
DE
819void
820optimization_options (level, size)
e2c953b6 821 int level ATTRIBUTE_UNUSED;
5accd822
DE
822 int size ATTRIBUTE_UNUSED;
823{
5accd822 824}
3cfa4909
MM
825\f
826/* Do anything needed at the start of the asm file. */
827
828void
829rs6000_file_start (file, default_cpu)
830 FILE *file;
d330fd93 831 const char *default_cpu;
3cfa4909 832{
c4d38ccb 833 size_t i;
3cfa4909 834 char buffer[80];
d330fd93 835 const char *start = buffer;
3cfa4909
MM
836 struct rs6000_cpu_select *ptr;
837
838 if (flag_verbose_asm)
839 {
840 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
841 rs6000_select[0].string = default_cpu;
842
b6a1cbae 843 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
844 {
845 ptr = &rs6000_select[i];
846 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
847 {
848 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
849 start = "";
850 }
851 }
852
b91da81f 853#ifdef USING_ELFOS_H
3cfa4909
MM
854 switch (rs6000_sdata)
855 {
856 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
857 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
858 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
859 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
860 }
861
862 if (rs6000_sdata && g_switch_value)
863 {
864 fprintf (file, "%s -G %d", start, g_switch_value);
865 start = "";
866 }
867#endif
868
869 if (*start == '\0')
949ea356 870 putc ('\n', file);
3cfa4909
MM
871 }
872}
5248c961 873\f
a0ab749a 874/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
875
876int
877direct_return ()
878{
4697a36c
MM
879 if (reload_completed)
880 {
881 rs6000_stack_t *info = rs6000_stack_info ();
882
883 if (info->first_gp_reg_save == 32
884 && info->first_fp_reg_save == 64
00b960c7 885 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
886 && ! info->lr_save_p
887 && ! info->cr_save_p
00b960c7 888 && info->vrsave_mask == 0
c81fc13e 889 && ! info->push_p)
4697a36c
MM
890 return 1;
891 }
892
893 return 0;
9878760c
RK
894}
895
896/* Returns 1 always. */
897
898int
899any_operand (op, mode)
592696dd 900 rtx op ATTRIBUTE_UNUSED;
296b8152 901 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
902{
903 return 1;
904}
905
a4f6c312 906/* Returns 1 if op is the count register. */
38c1f2d7 907int
a4f6c312 908count_register_operand (op, mode)
592696dd 909 rtx op;
296b8152 910 enum machine_mode mode ATTRIBUTE_UNUSED;
b6c9286a
MM
911{
912 if (GET_CODE (op) != REG)
913 return 0;
914
915 if (REGNO (op) == COUNT_REGISTER_REGNUM)
916 return 1;
917
918 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
919 return 1;
920
921 return 0;
922}
923
0ec4e2a8
AH
924/* Returns 1 if op is an altivec register. */
925int
926altivec_register_operand (op, mode)
927 rtx op;
928 enum machine_mode mode ATTRIBUTE_UNUSED;
929{
930
931 return (register_operand (op, mode)
932 && (GET_CODE (op) != REG
933 || REGNO (op) > FIRST_PSEUDO_REGISTER
934 || ALTIVEC_REGNO_P (REGNO (op))));
935}
936
38c1f2d7 937int
a4f6c312 938xer_operand (op, mode)
592696dd 939 rtx op;
296b8152 940 enum machine_mode mode ATTRIBUTE_UNUSED;
802a0058
MM
941{
942 if (GET_CODE (op) != REG)
943 return 0;
944
9ebbca7d 945 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
946 return 1;
947
802a0058
MM
948 return 0;
949}
950
c859cda6 951/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 952 by such constants completes more quickly. */
c859cda6
DJ
953
954int
955s8bit_cint_operand (op, mode)
956 rtx op;
957 enum machine_mode mode ATTRIBUTE_UNUSED;
958{
959 return ( GET_CODE (op) == CONST_INT
960 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
961}
962
9878760c
RK
963/* Return 1 if OP is a constant that can fit in a D field. */
964
965int
966short_cint_operand (op, mode)
592696dd 967 rtx op;
296b8152 968 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 969{
5f59ecb7
DE
970 return (GET_CODE (op) == CONST_INT
971 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
972}
973
5519a4f9 974/* Similar for an unsigned D field. */
9878760c
RK
975
976int
977u_short_cint_operand (op, mode)
592696dd 978 rtx op;
296b8152 979 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 980{
19684119 981 return (GET_CODE (op) == CONST_INT
c1f11548 982 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
983}
984
dcfedcd0
RK
985/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
986
987int
988non_short_cint_operand (op, mode)
592696dd 989 rtx op;
296b8152 990 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
991{
992 return (GET_CODE (op) == CONST_INT
a7653a2c 993 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
994}
995
2bfcf297
DB
996/* Returns 1 if OP is a CONST_INT that is a positive value
997 and an exact power of 2. */
998
999int
1000exact_log2_cint_operand (op, mode)
592696dd 1001 rtx op;
2bfcf297
DB
1002 enum machine_mode mode ATTRIBUTE_UNUSED;
1003{
1004 return (GET_CODE (op) == CONST_INT
1005 && INTVAL (op) > 0
1006 && exact_log2 (INTVAL (op)) >= 0);
1007}
1008
9878760c
RK
1009/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1010 ctr, or lr). */
1011
1012int
cd2b37d9 1013gpc_reg_operand (op, mode)
592696dd 1014 rtx op;
9878760c
RK
1015 enum machine_mode mode;
1016{
1017 return (register_operand (op, mode)
802a0058 1018 && (GET_CODE (op) != REG
9ebbca7d
GK
1019 || (REGNO (op) >= ARG_POINTER_REGNUM
1020 && !XER_REGNO_P (REGNO (op)))
1021 || REGNO (op) < MQ_REGNO));
9878760c
RK
1022}
1023
1024/* Returns 1 if OP is either a pseudo-register or a register denoting a
1025 CR field. */
1026
1027int
1028cc_reg_operand (op, mode)
592696dd 1029 rtx op;
9878760c
RK
1030 enum machine_mode mode;
1031{
1032 return (register_operand (op, mode)
1033 && (GET_CODE (op) != REG
1034 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1035 || CR_REGNO_P (REGNO (op))));
1036}
1037
815cdc52
MM
1038/* Returns 1 if OP is either a pseudo-register or a register denoting a
1039 CR field that isn't CR0. */
1040
1041int
1042cc_reg_not_cr0_operand (op, mode)
592696dd 1043 rtx op;
815cdc52
MM
1044 enum machine_mode mode;
1045{
1046 return (register_operand (op, mode)
1047 && (GET_CODE (op) != REG
1048 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1049 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1050}
1051
a4f6c312
SS
1052/* Returns 1 if OP is either a constant integer valid for a D-field or
1053 a non-special register. If a register, it must be in the proper
1054 mode unless MODE is VOIDmode. */
9878760c
RK
1055
1056int
1057reg_or_short_operand (op, mode)
592696dd 1058 rtx op;
9878760c
RK
1059 enum machine_mode mode;
1060{
f5a28898 1061 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1062}
1063
a4f6c312
SS
1064/* Similar, except check if the negation of the constant would be
1065 valid for a D-field. */
9878760c
RK
1066
1067int
1068reg_or_neg_short_operand (op, mode)
592696dd 1069 rtx op;
9878760c
RK
1070 enum machine_mode mode;
1071{
1072 if (GET_CODE (op) == CONST_INT)
1073 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1074
cd2b37d9 1075 return gpc_reg_operand (op, mode);
9878760c
RK
1076}
1077
768070a0
TR
1078/* Returns 1 if OP is either a constant integer valid for a DS-field or
1079 a non-special register. If a register, it must be in the proper
1080 mode unless MODE is VOIDmode. */
1081
1082int
1083reg_or_aligned_short_operand (op, mode)
1084 rtx op;
1085 enum machine_mode mode;
1086{
1087 if (gpc_reg_operand (op, mode))
1088 return 1;
1089 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1090 return 1;
1091
1092 return 0;
1093}
1094
1095
a4f6c312
SS
1096/* Return 1 if the operand is either a register or an integer whose
1097 high-order 16 bits are zero. */
9878760c
RK
1098
1099int
1100reg_or_u_short_operand (op, mode)
592696dd 1101 rtx op;
9878760c
RK
1102 enum machine_mode mode;
1103{
e675f625 1104 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1105}
1106
1107/* Return 1 is the operand is either a non-special register or ANY
1108 constant integer. */
1109
1110int
1111reg_or_cint_operand (op, mode)
592696dd 1112 rtx op;
9878760c
RK
1113 enum machine_mode mode;
1114{
a4f6c312 1115 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1116}
1117
1118/* Return 1 is the operand is either a non-special register or ANY
1119 32-bit signed constant integer. */
1120
1121int
1122reg_or_arith_cint_operand (op, mode)
592696dd 1123 rtx op;
f6bf7de2
DE
1124 enum machine_mode mode;
1125{
a4f6c312
SS
1126 return (gpc_reg_operand (op, mode)
1127 || (GET_CODE (op) == CONST_INT
f6bf7de2 1128#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1129 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1130 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1131#endif
a4f6c312 1132 ));
9878760c
RK
1133}
1134
2bfcf297
DB
1135/* Return 1 is the operand is either a non-special register or a 32-bit
1136 signed constant integer valid for 64-bit addition. */
1137
1138int
1139reg_or_add_cint64_operand (op, mode)
592696dd 1140 rtx op;
2bfcf297
DB
1141 enum machine_mode mode;
1142{
a4f6c312
SS
1143 return (gpc_reg_operand (op, mode)
1144 || (GET_CODE (op) == CONST_INT
a65c591c 1145#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1146 && INTVAL (op) < 0x7fff8000
a65c591c 1147#else
a4f6c312
SS
1148 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1149 < 0x100000000ll)
2bfcf297 1150#endif
a4f6c312 1151 ));
2bfcf297
DB
1152}
1153
1154/* Return 1 is the operand is either a non-special register or a 32-bit
1155 signed constant integer valid for 64-bit subtraction. */
1156
1157int
1158reg_or_sub_cint64_operand (op, mode)
592696dd 1159 rtx op;
2bfcf297
DB
1160 enum machine_mode mode;
1161{
a4f6c312
SS
1162 return (gpc_reg_operand (op, mode)
1163 || (GET_CODE (op) == CONST_INT
a65c591c 1164#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1165 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1166#else
a4f6c312
SS
1167 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1168 < 0x100000000ll)
2bfcf297 1169#endif
a4f6c312 1170 ));
2bfcf297
DB
1171}
1172
9ebbca7d
GK
1173/* Return 1 is the operand is either a non-special register or ANY
1174 32-bit unsigned constant integer. */
1175
1176int
1d328b19 1177reg_or_logical_cint_operand (op, mode)
592696dd 1178 rtx op;
9ebbca7d
GK
1179 enum machine_mode mode;
1180{
1d328b19
GK
1181 if (GET_CODE (op) == CONST_INT)
1182 {
1183 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1184 {
1185 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1186 abort ();
1d328b19
GK
1187
1188 if (INTVAL (op) < 0)
1189 return 0;
1190 }
1191
1192 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1193 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1194 }
1195 else if (GET_CODE (op) == CONST_DOUBLE)
1196 {
1197 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1198 || mode != DImode)
a4f6c312 1199 abort ();
1d328b19
GK
1200
1201 return CONST_DOUBLE_HIGH (op) == 0;
1202 }
1203 else
1204 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1205}
1206
51d3e7d6 1207/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1208
1209int
1210got_operand (op, mode)
592696dd 1211 rtx op;
296b8152 1212 enum machine_mode mode ATTRIBUTE_UNUSED;
766a866c
MM
1213{
1214 return (GET_CODE (op) == SYMBOL_REF
1215 || GET_CODE (op) == CONST
1216 || GET_CODE (op) == LABEL_REF);
1217}
1218
38c1f2d7
MM
1219/* Return 1 if the operand is a simple references that can be loaded via
1220 the GOT (labels involving addition aren't allowed). */
1221
1222int
1223got_no_const_operand (op, mode)
592696dd 1224 rtx op;
296b8152 1225 enum machine_mode mode ATTRIBUTE_UNUSED;
38c1f2d7
MM
1226{
1227 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1228}
1229
4e74d8ec
MM
1230/* Return the number of instructions it takes to form a constant in an
1231 integer register. */
1232
1233static int
1234num_insns_constant_wide (value)
1235 HOST_WIDE_INT value;
1236{
1237 /* signed constant loadable with {cal|addi} */
5f59ecb7 1238 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1239 return 1;
1240
4e74d8ec 1241 /* constant loadable with {cau|addis} */
5f59ecb7 1242 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1243 return 1;
1244
5f59ecb7 1245#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1246 else if (TARGET_POWERPC64)
4e74d8ec 1247 {
a65c591c
DE
1248 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1249 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1250
a65c591c 1251 if (high == 0 || high == -1)
4e74d8ec
MM
1252 return 2;
1253
a65c591c 1254 high >>= 1;
4e74d8ec 1255
a65c591c 1256 if (low == 0)
4e74d8ec 1257 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1258 else
1259 return (num_insns_constant_wide (high)
e396202a 1260 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1261 }
1262#endif
1263
1264 else
1265 return 2;
1266}
1267
1268int
1269num_insns_constant (op, mode)
1270 rtx op;
1271 enum machine_mode mode;
1272{
4e74d8ec 1273 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1274 {
1275#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1276 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1277 && mask64_operand (op, mode))
0d30d435
DE
1278 return 2;
1279 else
1280#endif
1281 return num_insns_constant_wide (INTVAL (op));
1282 }
4e74d8ec 1283
6fc48950
MM
1284 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1285 {
1286 long l;
1287 REAL_VALUE_TYPE rv;
1288
1289 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1290 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1291 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1292 }
1293
47ad8c61 1294 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1295 {
47ad8c61
MM
1296 HOST_WIDE_INT low;
1297 HOST_WIDE_INT high;
1298 long l[2];
1299 REAL_VALUE_TYPE rv;
1300 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1301
47ad8c61
MM
1302 if (mode == VOIDmode || mode == DImode)
1303 {
1304 high = CONST_DOUBLE_HIGH (op);
1305 low = CONST_DOUBLE_LOW (op);
1306 }
1307 else
1308 {
1309 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1310 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1311 high = l[endian];
1312 low = l[1 - endian];
1313 }
4e74d8ec 1314
47ad8c61
MM
1315 if (TARGET_32BIT)
1316 return (num_insns_constant_wide (low)
1317 + num_insns_constant_wide (high));
4e74d8ec
MM
1318
1319 else
47ad8c61 1320 {
e72247f4 1321 if (high == 0 && low >= 0)
47ad8c61
MM
1322 return num_insns_constant_wide (low);
1323
e72247f4 1324 else if (high == -1 && low < 0)
47ad8c61
MM
1325 return num_insns_constant_wide (low);
1326
a260abc9
DE
1327 else if (mask64_operand (op, mode))
1328 return 2;
1329
47ad8c61
MM
1330 else if (low == 0)
1331 return num_insns_constant_wide (high) + 1;
1332
1333 else
1334 return (num_insns_constant_wide (high)
1335 + num_insns_constant_wide (low) + 1);
1336 }
4e74d8ec
MM
1337 }
1338
1339 else
1340 abort ();
1341}
1342
a4f6c312
SS
1343/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1344 register with one instruction per word. We only do this if we can
1345 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1346
1347int
1348easy_fp_constant (op, mode)
592696dd
SS
1349 rtx op;
1350 enum machine_mode mode;
9878760c 1351{
9878760c
RK
1352 if (GET_CODE (op) != CONST_DOUBLE
1353 || GET_MODE (op) != mode
4e74d8ec 1354 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1355 return 0;
1356
a4f6c312 1357 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1358 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1359 && mode != DImode)
b6c9286a
MM
1360 return 1;
1361
a4f6c312 1362 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1363 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1364 return 0;
1365
5ae4759c 1366#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1367 /* Similarly if we are using -mrelocatable, consider all constants
1368 to be hard. */
5ae4759c
MM
1369 if (TARGET_RELOCATABLE)
1370 return 0;
1371#endif
1372
fcce224d
DE
1373 if (mode == TFmode)
1374 {
1375 long k[4];
1376 REAL_VALUE_TYPE rv;
1377
1378 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1379 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1380
1381 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1382 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1383 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1384 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1385 }
1386
1387 else if (mode == DFmode)
042259f2
DE
1388 {
1389 long k[2];
1390 REAL_VALUE_TYPE rv;
1391
1392 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1393 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1394
a65c591c
DE
1395 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1396 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1397 }
4e74d8ec
MM
1398
1399 else if (mode == SFmode)
042259f2
DE
1400 {
1401 long l;
1402 REAL_VALUE_TYPE rv;
1403
1404 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1405 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1406
4e74d8ec 1407 return num_insns_constant_wide (l) == 1;
042259f2 1408 }
4e74d8ec 1409
a260abc9 1410 else if (mode == DImode)
c81fc13e 1411 return ((TARGET_POWERPC64
a260abc9
DE
1412 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1413 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1414
a9098fd0
GK
1415 else if (mode == SImode)
1416 return 1;
4e74d8ec
MM
1417 else
1418 abort ();
9878760c 1419}
8f75773e 1420
69ef87e2
AH
1421/* Return 1 if the operand is a CONST_INT and can be put into a
1422 register with one instruction. */
1423
1424static int
1425easy_vector_constant (op)
1426 rtx op;
1427{
1428 rtx elt;
1429 int units, i;
1430
1431 if (GET_CODE (op) != CONST_VECTOR)
1432 return 0;
1433
1434 units = CONST_VECTOR_NUNITS (op);
1435
1436 /* We can generate 0 easily. Look for that. */
1437 for (i = 0; i < units; ++i)
1438 {
1439 elt = CONST_VECTOR_ELT (op, i);
1440
1441 /* We could probably simplify this by just checking for equality
1442 with CONST0_RTX for the current mode, but let's be safe
1443 instead. */
1444
98ef3137
JJ
1445 switch (GET_CODE (elt))
1446 {
1447 case CONST_INT:
1448 if (INTVAL (elt) != 0)
1449 return 0;
1450 break;
1451 case CONST_DOUBLE:
1452 if (CONST_DOUBLE_LOW (elt) != 0 || CONST_DOUBLE_HIGH (elt) != 0)
1453 return 0;
1454 break;
1455 default:
1456 return 0;
1457 }
69ef87e2
AH
1458 }
1459
1460 /* We could probably generate a few other constants trivially, but
1461 gcc doesn't generate them yet. FIXME later. */
98ef3137 1462 return 1;
69ef87e2
AH
1463}
1464
1465/* Return 1 if the operand is the constant 0. This works for scalars
1466 as well as vectors. */
1467int
1468zero_constant (op, mode)
1469 rtx op;
1470 enum machine_mode mode;
1471{
1472 return op == CONST0_RTX (mode);
1473}
1474
50a0b056
GK
1475/* Return 1 if the operand is 0.0. */
1476int
1477zero_fp_constant (op, mode)
592696dd
SS
1478 rtx op;
1479 enum machine_mode mode;
50a0b056
GK
1480{
1481 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1482}
1483
a4f6c312
SS
1484/* Return 1 if the operand is in volatile memory. Note that during
1485 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1486 volatile memory references. So this function allows us to
1487 recognize volatile references where its safe. */
1488
1489int
1490volatile_mem_operand (op, mode)
592696dd 1491 rtx op;
b6c9286a
MM
1492 enum machine_mode mode;
1493{
1494 if (GET_CODE (op) != MEM)
1495 return 0;
1496
1497 if (!MEM_VOLATILE_P (op))
1498 return 0;
1499
1500 if (mode != GET_MODE (op))
1501 return 0;
1502
1503 if (reload_completed)
1504 return memory_operand (op, mode);
1505
1506 if (reload_in_progress)
1507 return strict_memory_address_p (mode, XEXP (op, 0));
1508
1509 return memory_address_p (mode, XEXP (op, 0));
1510}
1511
97f6e72f 1512/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1513
1514int
97f6e72f 1515offsettable_mem_operand (op, mode)
592696dd 1516 rtx op;
914c2e77
RK
1517 enum machine_mode mode;
1518{
97f6e72f 1519 return ((GET_CODE (op) == MEM)
677a9668 1520 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1521 mode, XEXP (op, 0)));
914c2e77
RK
1522}
1523
9878760c
RK
1524/* Return 1 if the operand is either an easy FP constant (see above) or
1525 memory. */
1526
1527int
1528mem_or_easy_const_operand (op, mode)
592696dd 1529 rtx op;
9878760c
RK
1530 enum machine_mode mode;
1531{
1532 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1533}
1534
1535/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1536 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1537
1538int
1539add_operand (op, mode)
592696dd 1540 rtx op;
9878760c
RK
1541 enum machine_mode mode;
1542{
2bfcf297 1543 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1544 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1545 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1546
1547 return gpc_reg_operand (op, mode);
9878760c
RK
1548}
1549
dcfedcd0
RK
1550/* Return 1 if OP is a constant but not a valid add_operand. */
1551
1552int
1553non_add_cint_operand (op, mode)
592696dd 1554 rtx op;
296b8152 1555 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
1556{
1557 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1558 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1559 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1560}
1561
9878760c
RK
1562/* Return 1 if the operand is a non-special register or a constant that
1563 can be used as the operand of an OR or XOR insn on the RS/6000. */
1564
1565int
1566logical_operand (op, mode)
592696dd 1567 rtx op;
9878760c
RK
1568 enum machine_mode mode;
1569{
40501e5f 1570 HOST_WIDE_INT opl, oph;
1d328b19 1571
dfbdccdb
GK
1572 if (gpc_reg_operand (op, mode))
1573 return 1;
1d328b19 1574
dfbdccdb 1575 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1576 {
1577 opl = INTVAL (op) & GET_MODE_MASK (mode);
1578
1579#if HOST_BITS_PER_WIDE_INT <= 32
1580 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1581 return 0;
1582#endif
1583 }
dfbdccdb
GK
1584 else if (GET_CODE (op) == CONST_DOUBLE)
1585 {
1d328b19 1586 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1587 abort ();
1d328b19
GK
1588
1589 opl = CONST_DOUBLE_LOW (op);
1590 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1591 if (oph != 0)
38886f37 1592 return 0;
dfbdccdb
GK
1593 }
1594 else
1595 return 0;
1d328b19 1596
40501e5f
AM
1597 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1598 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1599}
1600
dcfedcd0 1601/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1602 above), but could be split into one. */
dcfedcd0
RK
1603
1604int
1605non_logical_cint_operand (op, mode)
592696dd 1606 rtx op;
5f59ecb7 1607 enum machine_mode mode;
dcfedcd0 1608{
dfbdccdb 1609 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1610 && ! logical_operand (op, mode)
1611 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1612}
1613
19ba8161 1614/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1615 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1616 Reject all ones and all zeros, since these should have been optimized
1617 away and confuse the making of MB and ME. */
1618
1619int
19ba8161 1620mask_operand (op, mode)
592696dd 1621 rtx op;
19ba8161 1622 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1623{
02071907 1624 HOST_WIDE_INT c, lsb;
9878760c 1625
19ba8161
DE
1626 if (GET_CODE (op) != CONST_INT)
1627 return 0;
1628
1629 c = INTVAL (op);
1630
57deb3a1
AM
1631 /* Fail in 64-bit mode if the mask wraps around because the upper
1632 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1633 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1634 return 0;
1635
c5059423
AM
1636 /* We don't change the number of transitions by inverting,
1637 so make sure we start with the LS bit zero. */
1638 if (c & 1)
1639 c = ~c;
1640
1641 /* Reject all zeros or all ones. */
1642 if (c == 0)
9878760c
RK
1643 return 0;
1644
c5059423
AM
1645 /* Find the first transition. */
1646 lsb = c & -c;
1647
1648 /* Invert to look for a second transition. */
1649 c = ~c;
9878760c 1650
c5059423
AM
1651 /* Erase first transition. */
1652 c &= -lsb;
9878760c 1653
c5059423
AM
1654 /* Find the second transition (if any). */
1655 lsb = c & -c;
1656
1657 /* Match if all the bits above are 1's (or c is zero). */
1658 return c == -lsb;
9878760c
RK
1659}
1660
0ba1b2ff
AM
1661/* Return 1 for the PowerPC64 rlwinm corner case. */
1662
1663int
1664mask_operand_wrap (op, mode)
1665 rtx op;
1666 enum machine_mode mode ATTRIBUTE_UNUSED;
1667{
1668 HOST_WIDE_INT c, lsb;
1669
1670 if (GET_CODE (op) != CONST_INT)
1671 return 0;
1672
1673 c = INTVAL (op);
1674
1675 if ((c & 0x80000001) != 0x80000001)
1676 return 0;
1677
1678 c = ~c;
1679 if (c == 0)
1680 return 0;
1681
1682 lsb = c & -c;
1683 c = ~c;
1684 c &= -lsb;
1685 lsb = c & -c;
1686 return c == -lsb;
1687}
1688
a260abc9
DE
1689/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1690 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
1691 Reject all zeros, since zero should have been optimized away and
1692 confuses the making of MB and ME. */
9878760c
RK
1693
1694int
a260abc9 1695mask64_operand (op, mode)
592696dd 1696 rtx op;
0ba1b2ff 1697 enum machine_mode mode ATTRIBUTE_UNUSED;
a260abc9
DE
1698{
1699 if (GET_CODE (op) == CONST_INT)
1700 {
02071907 1701 HOST_WIDE_INT c, lsb;
a260abc9 1702
c5059423 1703 c = INTVAL (op);
a260abc9 1704
0ba1b2ff 1705 /* Reject all zeros. */
c5059423 1706 if (c == 0)
e2c953b6
DE
1707 return 0;
1708
0ba1b2ff
AM
1709 /* We don't change the number of transitions by inverting,
1710 so make sure we start with the LS bit zero. */
1711 if (c & 1)
1712 c = ~c;
1713
c5059423
AM
1714 /* Find the transition, and check that all bits above are 1's. */
1715 lsb = c & -c;
e3981aab
DE
1716
1717 /* Match if all the bits above are 1's (or c is zero). */
c5059423 1718 return c == -lsb;
e2c953b6 1719 }
0ba1b2ff
AM
1720 return 0;
1721}
1722
1723/* Like mask64_operand, but allow up to three transitions. This
1724 predicate is used by insn patterns that generate two rldicl or
1725 rldicr machine insns. */
1726
1727int
1728mask64_2_operand (op, mode)
1729 rtx op;
1730 enum machine_mode mode ATTRIBUTE_UNUSED;
1731{
1732 if (GET_CODE (op) == CONST_INT)
a260abc9 1733 {
0ba1b2ff 1734 HOST_WIDE_INT c, lsb;
a260abc9 1735
0ba1b2ff 1736 c = INTVAL (op);
a260abc9 1737
0ba1b2ff
AM
1738 /* Disallow all zeros. */
1739 if (c == 0)
1740 return 0;
a260abc9 1741
0ba1b2ff
AM
1742 /* We don't change the number of transitions by inverting,
1743 so make sure we start with the LS bit zero. */
1744 if (c & 1)
1745 c = ~c;
a260abc9 1746
0ba1b2ff
AM
1747 /* Find the first transition. */
1748 lsb = c & -c;
a260abc9 1749
0ba1b2ff
AM
1750 /* Invert to look for a second transition. */
1751 c = ~c;
1752
1753 /* Erase first transition. */
1754 c &= -lsb;
1755
1756 /* Find the second transition. */
1757 lsb = c & -c;
1758
1759 /* Invert to look for a third transition. */
1760 c = ~c;
1761
1762 /* Erase second transition. */
1763 c &= -lsb;
1764
1765 /* Find the third transition (if any). */
1766 lsb = c & -c;
1767
1768 /* Match if all the bits above are 1's (or c is zero). */
1769 return c == -lsb;
1770 }
1771 return 0;
1772}
1773
1774/* Generates shifts and masks for a pair of rldicl or rldicr insns to
1775 implement ANDing by the mask IN. */
1776void
1777build_mask64_2_operands (in, out)
1778 rtx in;
1779 rtx *out;
1780{
1781#if HOST_BITS_PER_WIDE_INT >= 64
1782 unsigned HOST_WIDE_INT c, lsb, m1, m2;
1783 int shift;
1784
1785 if (GET_CODE (in) != CONST_INT)
1786 abort ();
1787
1788 c = INTVAL (in);
1789 if (c & 1)
1790 {
1791 /* Assume c initially something like 0x00fff000000fffff. The idea
1792 is to rotate the word so that the middle ^^^^^^ group of zeros
1793 is at the MS end and can be cleared with an rldicl mask. We then
1794 rotate back and clear off the MS ^^ group of zeros with a
1795 second rldicl. */
1796 c = ~c; /* c == 0xff000ffffff00000 */
1797 lsb = c & -c; /* lsb == 0x0000000000100000 */
1798 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
1799 c = ~c; /* c == 0x00fff000000fffff */
1800 c &= -lsb; /* c == 0x00fff00000000000 */
1801 lsb = c & -c; /* lsb == 0x0000100000000000 */
1802 c = ~c; /* c == 0xff000fffffffffff */
1803 c &= -lsb; /* c == 0xff00000000000000 */
1804 shift = 0;
1805 while ((lsb >>= 1) != 0)
1806 shift++; /* shift == 44 on exit from loop */
1807 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
1808 m1 = ~m1; /* m1 == 0x000000ffffffffff */
1809 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
1810 }
1811 else
0ba1b2ff
AM
1812 {
1813 /* Assume c initially something like 0xff000f0000000000. The idea
1814 is to rotate the word so that the ^^^ middle group of zeros
1815 is at the LS end and can be cleared with an rldicr mask. We then
1816 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
1817 a second rldicr. */
1818 lsb = c & -c; /* lsb == 0x0000010000000000 */
1819 m2 = -lsb; /* m2 == 0xffffff0000000000 */
1820 c = ~c; /* c == 0x00fff0ffffffffff */
1821 c &= -lsb; /* c == 0x00fff00000000000 */
1822 lsb = c & -c; /* lsb == 0x0000100000000000 */
1823 c = ~c; /* c == 0xff000fffffffffff */
1824 c &= -lsb; /* c == 0xff00000000000000 */
1825 shift = 0;
1826 while ((lsb >>= 1) != 0)
1827 shift++; /* shift == 44 on exit from loop */
1828 m1 = ~c; /* m1 == 0x00ffffffffffffff */
1829 m1 >>= shift; /* m1 == 0x0000000000000fff */
1830 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
1831 }
1832
1833 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
1834 masks will be all 1's. We are guaranteed more than one transition. */
1835 out[0] = GEN_INT (64 - shift);
1836 out[1] = GEN_INT (m1);
1837 out[2] = GEN_INT (shift);
1838 out[3] = GEN_INT (m2);
1839#else
045572c7
GK
1840 (void)in;
1841 (void)out;
0ba1b2ff
AM
1842 abort ();
1843#endif
a260abc9
DE
1844}
1845
1846/* Return 1 if the operand is either a non-special register or a constant
1847 that can be used as the operand of a PowerPC64 logical AND insn. */
1848
1849int
1850and64_operand (op, mode)
592696dd 1851 rtx op;
9878760c
RK
1852 enum machine_mode mode;
1853{
a4f6c312 1854 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1855 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1856
1857 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
1858}
1859
0ba1b2ff
AM
1860/* Like the above, but also match constants that can be implemented
1861 with two rldicl or rldicr insns. */
1862
1863int
1864and64_2_operand (op, mode)
1865 rtx op;
1866 enum machine_mode mode;
1867{
1868 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1869 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
1870
1871 return logical_operand (op, mode) || mask64_2_operand (op, mode);
1872}
1873
a260abc9
DE
1874/* Return 1 if the operand is either a non-special register or a
1875 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
1876
1877int
a260abc9 1878and_operand (op, mode)
592696dd 1879 rtx op;
a260abc9 1880 enum machine_mode mode;
dcfedcd0 1881{
a4f6c312 1882 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1883 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1884
1885 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
1886}
1887
9878760c
RK
1888/* Return 1 if the operand is a general register or memory operand. */
1889
1890int
1891reg_or_mem_operand (op, mode)
592696dd
SS
1892 rtx op;
1893 enum machine_mode mode;
9878760c 1894{
b6c9286a
MM
1895 return (gpc_reg_operand (op, mode)
1896 || memory_operand (op, mode)
1897 || volatile_mem_operand (op, mode));
9878760c
RK
1898}
1899
a7a813f7 1900/* Return 1 if the operand is a general register or memory operand without
3cb999d8 1901 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
1902 instruction. */
1903
1904int
1905lwa_operand (op, mode)
592696dd
SS
1906 rtx op;
1907 enum machine_mode mode;
a7a813f7
RK
1908{
1909 rtx inner = op;
1910
1911 if (reload_completed && GET_CODE (inner) == SUBREG)
1912 inner = SUBREG_REG (inner);
1913
1914 return gpc_reg_operand (inner, mode)
1915 || (memory_operand (inner, mode)
1916 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
1917 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
1918 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
1919 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
1920 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
1921}
1922
cc4d5fec
JH
1923/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
1924
1925int
1926symbol_ref_operand (op, mode)
1927 rtx op;
1928 enum machine_mode mode;
1929{
1930 if (mode != VOIDmode && GET_MODE (op) != mode)
1931 return 0;
1932
1933 return (GET_CODE (op) == SYMBOL_REF);
1934}
1935
9878760c 1936/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 1937 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
1938
1939int
1940call_operand (op, mode)
592696dd 1941 rtx op;
9878760c
RK
1942 enum machine_mode mode;
1943{
1944 if (mode != VOIDmode && GET_MODE (op) != mode)
1945 return 0;
1946
1947 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
1948 || (GET_CODE (op) == REG
1949 && (REGNO (op) == LINK_REGISTER_REGNUM
1950 || REGNO (op) == COUNT_REGISTER_REGNUM
1951 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
1952}
1953
2af3d377 1954/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
a4f6c312 1955 this file and the function is not weakly defined. */
2af3d377
RK
1956
1957int
1958current_file_function_operand (op, mode)
592696dd 1959 rtx op;
296b8152 1960 enum machine_mode mode ATTRIBUTE_UNUSED;
2af3d377
RK
1961{
1962 return (GET_CODE (op) == SYMBOL_REF
1963 && (SYMBOL_REF_FLAG (op)
8f1b829e 1964 || (op == XEXP (DECL_RTL (current_function_decl), 0)
c81fc13e 1965 && ! DECL_WEAK (current_function_decl))));
2af3d377
RK
1966}
1967
9878760c
RK
1968/* Return 1 if this operand is a valid input for a move insn. */
1969
1970int
1971input_operand (op, mode)
592696dd 1972 rtx op;
9878760c
RK
1973 enum machine_mode mode;
1974{
eb4e8003 1975 /* Memory is always valid. */
9878760c
RK
1976 if (memory_operand (op, mode))
1977 return 1;
1978
34792e82 1979 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 1980 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
1981 return 1;
1982
eb4e8003
RK
1983 /* For floating-point, easy constants are valid. */
1984 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1985 && CONSTANT_P (op)
1986 && easy_fp_constant (op, mode))
1987 return 1;
1988
4e74d8ec
MM
1989 /* Allow any integer constant. */
1990 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 1991 && (GET_CODE (op) == CONST_INT
e675f625 1992 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
1993 return 1;
1994
eb4e8003
RK
1995 /* For floating-point or multi-word mode, the only remaining valid type
1996 is a register. */
9878760c
RK
1997 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1998 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 1999 return register_operand (op, mode);
9878760c 2000
88fe15a1
RK
2001 /* The only cases left are integral modes one word or smaller (we
2002 do not get called for MODE_CC values). These can be in any
2003 register. */
2004 if (register_operand (op, mode))
a8b3aeda 2005 return 1;
88fe15a1 2006
84cf9dda 2007 /* A SYMBOL_REF referring to the TOC is valid. */
7fec4abd 2008 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
84cf9dda
RK
2009 return 1;
2010
9ebbca7d
GK
2011 /* A constant pool expression (relative to the TOC) is valid */
2012 if (TOC_RELATIVE_EXPR_P (op))
b6c9286a
MM
2013 return 1;
2014
88228c4b
MM
2015 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2016 to be valid. */
f607bc57 2017 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2018 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2019 && small_data_operand (op, Pmode))
2020 return 1;
2021
042259f2 2022 return 0;
9878760c 2023}
7509c759 2024
a4f6c312 2025/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2026
2027int
2028small_data_operand (op, mode)
296b8152
KG
2029 rtx op ATTRIBUTE_UNUSED;
2030 enum machine_mode mode ATTRIBUTE_UNUSED;
7509c759 2031{
38c1f2d7 2032#if TARGET_ELF
5f59ecb7 2033 rtx sym_ref;
7509c759 2034
d9407988 2035 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2036 return 0;
a54d04b7 2037
f607bc57 2038 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2039 return 0;
2040
88228c4b
MM
2041 if (GET_CODE (op) == SYMBOL_REF)
2042 sym_ref = op;
2043
2044 else if (GET_CODE (op) != CONST
2045 || GET_CODE (XEXP (op, 0)) != PLUS
2046 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2047 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2048 return 0;
2049
88228c4b 2050 else
dbf55e53
MM
2051 {
2052 rtx sum = XEXP (op, 0);
2053 HOST_WIDE_INT summand;
2054
2055 /* We have to be careful here, because it is the referenced address
2056 that must be 32k from _SDA_BASE_, not just the symbol. */
2057 summand = INTVAL (XEXP (sum, 1));
2058 if (summand < 0 || summand > g_switch_value)
2059 return 0;
2060
2061 sym_ref = XEXP (sum, 0);
2062 }
88228c4b
MM
2063
2064 if (*XSTR (sym_ref, 0) != '@')
7509c759
MM
2065 return 0;
2066
2067 return 1;
d9407988
MM
2068
2069#else
2070 return 0;
2071#endif
7509c759 2072}
9ebbca7d
GK
2073\f
2074static int
2075constant_pool_expr_1 (op, have_sym, have_toc)
2076 rtx op;
2077 int *have_sym;
2078 int *have_toc;
2079{
2080 switch (GET_CODE(op))
2081 {
2082 case SYMBOL_REF:
a4f6c312
SS
2083 if (CONSTANT_POOL_ADDRESS_P (op))
2084 {
2085 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2086 {
2087 *have_sym = 1;
2088 return 1;
2089 }
2090 else
2091 return 0;
2092 }
2093 else if (! strcmp (XSTR (op, 0), toc_label_name))
2094 {
2095 *have_toc = 1;
2096 return 1;
2097 }
2098 else
2099 return 0;
9ebbca7d
GK
2100 case PLUS:
2101 case MINUS:
c1f11548
DE
2102 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2103 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2104 case CONST:
a4f6c312 2105 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2106 case CONST_INT:
a4f6c312 2107 return 1;
9ebbca7d 2108 default:
a4f6c312 2109 return 0;
9ebbca7d
GK
2110 }
2111}
2112
2113int
2114constant_pool_expr_p (op)
2115 rtx op;
2116{
2117 int have_sym = 0;
2118 int have_toc = 0;
2119 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2120}
2121
2122int
2123toc_relative_expr_p (op)
2124 rtx op;
2125{
2126 int have_sym = 0;
2127 int have_toc = 0;
2128 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2129}
2130
2131/* Try machine-dependent ways of modifying an illegitimate address
2132 to be legitimate. If we find one, return the new, valid address.
2133 This is used from only one place: `memory_address' in explow.c.
2134
a4f6c312
SS
2135 OLDX is the address as it was before break_out_memory_refs was
2136 called. In some cases it is useful to look at this to decide what
2137 needs to be done.
9ebbca7d 2138
a4f6c312 2139 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2140
a4f6c312
SS
2141 It is always safe for this function to do nothing. It exists to
2142 recognize opportunities to optimize the output.
9ebbca7d
GK
2143
2144 On RS/6000, first check for the sum of a register with a constant
2145 integer that is out of range. If so, generate code to add the
2146 constant with the low-order 16 bits masked to the register and force
2147 this result into another register (this can be done with `cau').
2148 Then generate an address of REG+(CONST&0xffff), allowing for the
2149 possibility of bit 16 being a one.
2150
2151 Then check for the sum of a register and something not constant, try to
2152 load the other things into a register and return the sum. */
2153rtx
2154rs6000_legitimize_address (x, oldx, mode)
2155 rtx x;
2156 rtx oldx ATTRIBUTE_UNUSED;
2157 enum machine_mode mode;
0ac081f6 2158{
9ebbca7d
GK
2159 if (GET_CODE (x) == PLUS
2160 && GET_CODE (XEXP (x, 0)) == REG
2161 && GET_CODE (XEXP (x, 1)) == CONST_INT
2162 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2163 {
2164 HOST_WIDE_INT high_int, low_int;
2165 rtx sum;
a65c591c
DE
2166 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2167 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2168 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2169 GEN_INT (high_int)), 0);
2170 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2171 }
2172 else if (GET_CODE (x) == PLUS
2173 && GET_CODE (XEXP (x, 0)) == REG
2174 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2175 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2176 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2177 || TARGET_POWERPC64
fcce224d 2178 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2179 && (TARGET_POWERPC64 || mode != DImode)
2180 && mode != TImode)
2181 {
2182 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2183 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2184 }
0ac081f6
AH
2185 else if (ALTIVEC_VECTOR_MODE (mode))
2186 {
2187 rtx reg;
2188
2189 /* Make sure both operands are registers. */
2190 if (GET_CODE (x) == PLUS)
9f85ed45 2191 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2192 force_reg (Pmode, XEXP (x, 1)));
2193
2194 reg = force_reg (Pmode, x);
2195 return reg;
2196 }
a3170dc6
AH
2197 else if (SPE_VECTOR_MODE (mode))
2198 {
2199 /* We accept [reg + reg] and [reg + OFFSET]. */
2200
2201 if (GET_CODE (x) == PLUS)
2202 {
2203 rtx op1 = XEXP (x, 0);
2204 rtx op2 = XEXP (x, 1);
2205
2206 op1 = force_reg (Pmode, op1);
2207
2208 if (GET_CODE (op2) != REG
2209 && (GET_CODE (op2) != CONST_INT
2210 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2211 op2 = force_reg (Pmode, op2);
2212
2213 return gen_rtx_PLUS (Pmode, op1, op2);
2214 }
2215
2216 return force_reg (Pmode, x);
2217 }
9ebbca7d
GK
2218 else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
2219 && GET_CODE (x) != CONST_INT
2220 && GET_CODE (x) != CONST_DOUBLE
2221 && CONSTANT_P (x)
6ac7bf2c
GK
2222 && GET_MODE_NUNITS (mode) == 1
2223 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2224 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2225 {
2226 rtx reg = gen_reg_rtx (Pmode);
2227 emit_insn (gen_elf_high (reg, (x)));
2228 return gen_rtx_LO_SUM (Pmode, reg, (x));
2229 }
ee890fe2
SS
2230 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2231 && ! flag_pic
ab82a49f
AP
2232#if TARGET_MACHO
2233 && ! MACHO_DYNAMIC_NO_PIC_P
2234#endif
ee890fe2
SS
2235 && GET_CODE (x) != CONST_INT
2236 && GET_CODE (x) != CONST_DOUBLE
2237 && CONSTANT_P (x)
a3170dc6 2238 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2239 && mode != DImode
2240 && mode != TImode)
2241 {
2242 rtx reg = gen_reg_rtx (Pmode);
2243 emit_insn (gen_macho_high (reg, (x)));
2244 return gen_rtx_LO_SUM (Pmode, reg, (x));
2245 }
9ebbca7d
GK
2246 else if (TARGET_TOC
2247 && CONSTANT_POOL_EXPR_P (x)
a9098fd0 2248 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2249 {
2250 return create_TOC_reference (x);
2251 }
2252 else
2253 return NULL_RTX;
2254}
258bfae2 2255
24ea750e
DJ
2256/* The convention appears to be to define this wherever it is used.
2257 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
2258 is now used here. */
2259#ifndef REG_MODE_OK_FOR_BASE_P
2260#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
2261#endif
2262
2263/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
2264 replace the input X, or the original X if no replacement is called for.
2265 The output parameter *WIN is 1 if the calling macro should goto WIN,
2266 0 if it should not.
2267
2268 For RS/6000, we wish to handle large displacements off a base
2269 register by splitting the addend across an addiu/addis and the mem insn.
2270 This cuts number of extra insns needed from 3 to 1.
2271
2272 On Darwin, we use this to generate code for floating point constants.
2273 A movsf_low is generated so we wind up with 2 instructions rather than 3.
2274 The Darwin code is inside #if TARGET_MACHO because only then is
2275 machopic_function_base_name() defined. */
2276rtx
2277rs6000_legitimize_reload_address (x, mode, opnum, type, ind_levels, win)
2278 rtx x;
2279 enum machine_mode mode;
2280 int opnum;
2281 int type;
2282 int ind_levels ATTRIBUTE_UNUSED;
2283 int *win;
2284{
2285 /* We must recognize output that we have already generated ourselves. */
2286 if (GET_CODE (x) == PLUS
2287 && GET_CODE (XEXP (x, 0)) == PLUS
2288 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2289 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2290 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2291 {
2292 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2293 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2294 opnum, (enum reload_type)type);
2295 *win = 1;
2296 return x;
2297 }
3deb2758 2298
24ea750e
DJ
2299#if TARGET_MACHO
2300 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
2301 && GET_CODE (x) == LO_SUM
2302 && GET_CODE (XEXP (x, 0)) == PLUS
2303 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
2304 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
2305 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
2306 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
2307 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
2308 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
2309 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
2310 {
2311 /* Result of previous invocation of this function on Darwin
6f317ef3 2312 floating point constant. */
24ea750e
DJ
2313 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2314 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2315 opnum, (enum reload_type)type);
2316 *win = 1;
2317 return x;
2318 }
2319#endif
2320 if (GET_CODE (x) == PLUS
2321 && GET_CODE (XEXP (x, 0)) == REG
2322 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2323 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 2324 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 2325 && !SPE_VECTOR_MODE (mode)
78c875e8 2326 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
2327 {
2328 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2329 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2330 HOST_WIDE_INT high
2331 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2332
2333 /* Check for 32-bit overflow. */
2334 if (high + low != val)
2335 {
2336 *win = 0;
2337 return x;
2338 }
2339
2340 /* Reload the high part into a base reg; leave the low part
2341 in the mem directly. */
2342
2343 x = gen_rtx_PLUS (GET_MODE (x),
2344 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2345 GEN_INT (high)),
2346 GEN_INT (low));
2347
2348 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2349 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2350 opnum, (enum reload_type)type);
2351 *win = 1;
2352 return x;
2353 }
2354#if TARGET_MACHO
2355 if (GET_CODE (x) == SYMBOL_REF
2356 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 2357 && !ALTIVEC_VECTOR_MODE (mode)
24ea750e
DJ
2358 && flag_pic)
2359 {
2360 /* Darwin load of floating point constant. */
2361 rtx offset = gen_rtx (CONST, Pmode,
2362 gen_rtx (MINUS, Pmode, x,
2363 gen_rtx (SYMBOL_REF, Pmode,
2364 machopic_function_base_name ())));
2365 x = gen_rtx (LO_SUM, GET_MODE (x),
2366 gen_rtx (PLUS, Pmode, pic_offset_table_rtx,
2367 gen_rtx (HIGH, Pmode, offset)), offset);
2368 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2369 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2370 opnum, (enum reload_type)type);
2371 *win = 1;
2372 return x;
2373 }
ab82a49f
AP
2374 if (GET_CODE (x) == SYMBOL_REF
2375 && DEFAULT_ABI == ABI_DARWIN
2376 && !ALTIVEC_VECTOR_MODE (mode)
2377 && MACHO_DYNAMIC_NO_PIC_P)
2378 {
2379 /* Darwin load of floating point constant. */
2380 x = gen_rtx (LO_SUM, GET_MODE (x),
2381 gen_rtx (HIGH, Pmode, x), x);
2382 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2383 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2384 opnum, (enum reload_type)type);
2385 *win = 1;
2386 return x;
2387 }
24ea750e
DJ
2388#endif
2389 if (TARGET_TOC
c1f11548
DE
2390 && CONSTANT_POOL_EXPR_P (x)
2391 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
2392 {
2393 (x) = create_TOC_reference (x);
2394 *win = 1;
2395 return x;
2396 }
2397 *win = 0;
2398 return x;
2399}
2400
258bfae2
FS
2401/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
2402 that is a valid memory address for an instruction.
2403 The MODE argument is the machine mode for the MEM expression
2404 that wants to use this address.
2405
2406 On the RS/6000, there are four valid address: a SYMBOL_REF that
2407 refers to a constant pool entry of an address (or the sum of it
2408 plus a constant), a short (16-bit signed) constant plus a register,
2409 the sum of two registers, or a register indirect, possibly with an
5bdc5878 2410 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
2411 we must ensure that both words are addressable or PowerPC64 with offset
2412 word aligned.
2413
2414 For modes spanning multiple registers (DFmode in 32-bit GPRs,
2415 32-bit DImode, TImode), indexed addressing cannot be used because
2416 adjacent memory cells are accessed by adding word-sized offsets
2417 during assembly output. */
2418int
2419rs6000_legitimate_address (mode, x, reg_ok_strict)
2420 enum machine_mode mode;
2421 rtx x;
2422 int reg_ok_strict;
2423{
2424 if (LEGITIMATE_INDIRECT_ADDRESS_P (x, reg_ok_strict))
2425 return 1;
2426 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 2427 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 2428 && !SPE_VECTOR_MODE (mode)
258bfae2
FS
2429 && TARGET_UPDATE
2430 && LEGITIMATE_INDIRECT_ADDRESS_P (XEXP (x, 0), reg_ok_strict))
2431 return 1;
2432 if (LEGITIMATE_SMALL_DATA_P (mode, x))
2433 return 1;
2434 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
2435 return 1;
2436 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
2437 if (! reg_ok_strict
2438 && GET_CODE (x) == PLUS
2439 && GET_CODE (XEXP (x, 0)) == REG
2440 && XEXP (x, 0) == virtual_stack_vars_rtx
2441 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2442 return 1;
2443 if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x, reg_ok_strict))
2444 return 1;
2445 if (mode != TImode
a3170dc6
AH
2446 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2447 || TARGET_POWERPC64
fcce224d 2448 || (mode != DFmode && mode != TFmode))
258bfae2
FS
2449 && (TARGET_POWERPC64 || mode != DImode)
2450 && LEGITIMATE_INDEXED_ADDRESS_P (x, reg_ok_strict))
2451 return 1;
2452 if (LEGITIMATE_LO_SUM_ADDRESS_P (mode, x, reg_ok_strict))
2453 return 1;
2454 return 0;
2455}
fb4d4348 2456\f
a4f6c312
SS
2457/* Try to output insns to set TARGET equal to the constant C if it can
2458 be done in less than N insns. Do all computations in MODE.
2459 Returns the place where the output has been placed if it can be
2460 done and the insns have been emitted. If it would take more than N
2461 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
2462
2463rtx
2464rs6000_emit_set_const (dest, mode, source, n)
2465 rtx dest, source;
2466 enum machine_mode mode;
2467 int n ATTRIBUTE_UNUSED;
2468{
af8cb5c5 2469 rtx result, insn, set;
2bfcf297
DB
2470 HOST_WIDE_INT c0, c1;
2471
af8cb5c5 2472 if (mode == QImode || mode == HImode)
2bfcf297
DB
2473 {
2474 if (dest == NULL)
2475 dest = gen_reg_rtx (mode);
2476 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
2477 return dest;
2478 }
af8cb5c5 2479 else if (mode == SImode)
2bfcf297 2480 {
af8cb5c5
DE
2481 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
2482
2483 emit_insn (gen_rtx_SET (VOIDmode, result,
2484 GEN_INT (INTVAL (source)
2485 & (~ (HOST_WIDE_INT) 0xffff))));
2486 emit_insn (gen_rtx_SET (VOIDmode, dest,
2487 gen_rtx_IOR (SImode, result,
2488 GEN_INT (INTVAL (source) & 0xffff))));
2489 result = dest;
2bfcf297 2490 }
af8cb5c5 2491 else if (mode == DImode)
2bfcf297 2492 {
af8cb5c5
DE
2493 if (GET_CODE (source) == CONST_INT)
2494 {
2495 c0 = INTVAL (source);
2496 c1 = -(c0 < 0);
2497 }
2498 else if (GET_CODE (source) == CONST_DOUBLE)
2499 {
2bfcf297 2500#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
2501 c0 = CONST_DOUBLE_LOW (source);
2502 c1 = -(c0 < 0);
2bfcf297 2503#else
af8cb5c5
DE
2504 c0 = CONST_DOUBLE_LOW (source);
2505 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 2506#endif
af8cb5c5
DE
2507 }
2508 else
2509 abort ();
2510
2511 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
2512 }
2513 else
a4f6c312 2514 abort ();
2bfcf297 2515
af8cb5c5
DE
2516 insn = get_last_insn ();
2517 set = single_set (insn);
2518 if (! CONSTANT_P (SET_SRC (set)))
2519 set_unique_reg_note (insn, REG_EQUAL, source);
2520
2521 return result;
2bfcf297
DB
2522}
2523
2524/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
2525 fall back to a straight forward decomposition. We do this to avoid
2526 exponential run times encountered when looking for longer sequences
2527 with rs6000_emit_set_const. */
2528static rtx
2529rs6000_emit_set_long_const (dest, c1, c2)
2530 rtx dest;
2531 HOST_WIDE_INT c1, c2;
2532{
2533 if (!TARGET_POWERPC64)
2534 {
2535 rtx operand1, operand2;
2536
2537 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
2538 DImode);
2539 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
2540 DImode);
2541 emit_move_insn (operand1, GEN_INT (c1));
2542 emit_move_insn (operand2, GEN_INT (c2));
2543 }
2544 else
2545 {
bc06712d 2546 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 2547
bc06712d
TR
2548 ud1 = c1 & 0xffff;
2549 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 2550#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 2551 c2 = c1 >> 32;
2bfcf297 2552#endif
bc06712d
TR
2553 ud3 = c2 & 0xffff;
2554 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 2555
bc06712d
TR
2556 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
2557 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 2558 {
bc06712d
TR
2559 if (ud1 & 0x8000)
2560 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
2561 else
2562 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 2563 }
2bfcf297 2564
bc06712d
TR
2565 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
2566 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 2567 {
bc06712d
TR
2568 if (ud2 & 0x8000)
2569 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
2570 - 0x80000000));
252b88f7 2571 else
bc06712d
TR
2572 emit_move_insn (dest, GEN_INT (ud2 << 16));
2573 if (ud1 != 0)
2574 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 2575 }
bc06712d
TR
2576 else if ((ud4 == 0xffff && (ud3 & 0x8000))
2577 || (ud4 == 0 && ! (ud3 & 0x8000)))
2578 {
2579 if (ud3 & 0x8000)
2580 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
2581 - 0x80000000));
2582 else
2583 emit_move_insn (dest, GEN_INT (ud3 << 16));
2584
2585 if (ud2 != 0)
2586 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
2587 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
2588 if (ud1 != 0)
2589 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
2590 }
2591 else
2592 {
2593 if (ud4 & 0x8000)
2594 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
2595 - 0x80000000));
2596 else
2597 emit_move_insn (dest, GEN_INT (ud4 << 16));
2598
2599 if (ud3 != 0)
2600 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 2601
bc06712d
TR
2602 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
2603 if (ud2 != 0)
2604 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
2605 GEN_INT (ud2 << 16)));
2606 if (ud1 != 0)
2607 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
2608 }
2609 }
2bfcf297
DB
2610 return dest;
2611}
2612
fb4d4348
GK
2613/* Emit a move from SOURCE to DEST in mode MODE. */
2614void
2615rs6000_emit_move (dest, source, mode)
2616 rtx dest;
2617 rtx source;
2618 enum machine_mode mode;
2619{
2620 rtx operands[2];
2621 operands[0] = dest;
2622 operands[1] = source;
2623
2624 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
2625 if (GET_CODE (operands[1]) == CONST_DOUBLE
2626 && ! FLOAT_MODE_P (mode)
2627 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
2628 {
2629 /* FIXME. This should never happen. */
2630 /* Since it seems that it does, do the safe thing and convert
2631 to a CONST_INT. */
2496c7bd 2632 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
2633 }
2634 if (GET_CODE (operands[1]) == CONST_DOUBLE
2635 && ! FLOAT_MODE_P (mode)
2636 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
2637 && CONST_DOUBLE_LOW (operands[1]) >= 0)
2638 || (CONST_DOUBLE_HIGH (operands[1]) == -1
2639 && CONST_DOUBLE_LOW (operands[1]) < 0)))
2640 abort ();
c9e8cb32
DD
2641
2642 /* Check if GCC is setting up a block move that will end up using FP
2643 registers as temporaries. We must make sure this is acceptable. */
2644 if (GET_CODE (operands[0]) == MEM
2645 && GET_CODE (operands[1]) == MEM
2646 && mode == DImode
41543739
GK
2647 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
2648 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
2649 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
2650 ? 32 : MEM_ALIGN (operands[0])))
2651 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
2652 ? 32
2653 : MEM_ALIGN (operands[1]))))
2654 && ! MEM_VOLATILE_P (operands [0])
2655 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 2656 {
41543739
GK
2657 emit_move_insn (adjust_address (operands[0], SImode, 0),
2658 adjust_address (operands[1], SImode, 0));
2659 emit_move_insn (adjust_address (operands[0], SImode, 4),
2660 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
2661 return;
2662 }
fb4d4348 2663
67cef334
DE
2664 if (!no_new_pseudos)
2665 {
2666 if (GET_CODE (operands[1]) == MEM && optimize > 0
2667 && (mode == QImode || mode == HImode || mode == SImode)
2668 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2669 {
2670 rtx reg = gen_reg_rtx (word_mode);
2671
2672 emit_insn (gen_rtx_SET (word_mode, reg,
2673 gen_rtx_ZERO_EXTEND (word_mode,
2674 operands[1])));
2675 operands[1] = gen_lowpart (mode, reg);
2676 }
2677 if (GET_CODE (operands[0]) != REG)
2678 operands[1] = force_reg (mode, operands[1]);
2679 }
a9098fd0 2680
a3170dc6
AH
2681 if (mode == SFmode && ! TARGET_POWERPC
2682 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 2683 && GET_CODE (operands[0]) == MEM)
fb4d4348 2684 {
ffc14f31
GK
2685 int regnum;
2686
2687 if (reload_in_progress || reload_completed)
2688 regnum = true_regnum (operands[1]);
2689 else if (GET_CODE (operands[1]) == REG)
2690 regnum = REGNO (operands[1]);
2691 else
2692 regnum = -1;
fb4d4348
GK
2693
2694 /* If operands[1] is a register, on POWER it may have
2695 double-precision data in it, so truncate it to single
2696 precision. */
2697 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
2698 {
2699 rtx newreg;
2700 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
2701 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
2702 operands[1] = newreg;
2703 }
2704 }
2705
a9098fd0
GK
2706 /* Handle the case where reload calls us with an invalid address;
2707 and the case of CONSTANT_P_RTX. */
16861f33 2708 if (!ALTIVEC_VECTOR_MODE (mode)
69ef87e2
AH
2709 && (! general_operand (operands[1], mode)
2710 || ! nonimmediate_operand (operands[0], mode)
2711 || GET_CODE (operands[1]) == CONSTANT_P_RTX))
fb4d4348
GK
2712 {
2713 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2714 return;
2715 }
a9098fd0 2716
fb4d4348
GK
2717 /* FIXME: In the long term, this switch statement should go away
2718 and be replaced by a sequence of tests based on things like
2719 mode == Pmode. */
2720 switch (mode)
2721 {
2722 case HImode:
2723 case QImode:
2724 if (CONSTANT_P (operands[1])
2725 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 2726 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2727 break;
2728
06f4e019 2729 case TFmode:
fb4d4348
GK
2730 case DFmode:
2731 case SFmode:
2732 if (CONSTANT_P (operands[1])
2733 && ! easy_fp_constant (operands[1], mode))
a9098fd0 2734 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2735 break;
2736
0ac081f6
AH
2737 case V16QImode:
2738 case V8HImode:
2739 case V4SFmode:
2740 case V4SImode:
a3170dc6
AH
2741 case V4HImode:
2742 case V2SFmode:
2743 case V2SImode:
00a892b8 2744 case V1DImode:
69ef87e2
AH
2745 if (CONSTANT_P (operands[1])
2746 && !easy_vector_constant (operands[1]))
0ac081f6
AH
2747 operands[1] = force_const_mem (mode, operands[1]);
2748 break;
2749
fb4d4348 2750 case SImode:
a9098fd0 2751 case DImode:
fb4d4348
GK
2752 /* Use default pattern for address of ELF small data */
2753 if (TARGET_ELF
a9098fd0 2754 && mode == Pmode
f607bc57 2755 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
2756 && (GET_CODE (operands[1]) == SYMBOL_REF
2757 || GET_CODE (operands[1]) == CONST)
2758 && small_data_operand (operands[1], mode))
fb4d4348
GK
2759 {
2760 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2761 return;
2762 }
2763
f607bc57 2764 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
2765 && mode == Pmode && mode == SImode
2766 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
2767 {
2768 emit_insn (gen_movsi_got (operands[0], operands[1]));
2769 return;
2770 }
2771
ee890fe2
SS
2772 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
2773 && TARGET_NO_TOC && ! flag_pic
a9098fd0 2774 && mode == Pmode
fb4d4348
GK
2775 && CONSTANT_P (operands[1])
2776 && GET_CODE (operands[1]) != HIGH
2777 && GET_CODE (operands[1]) != CONST_INT)
2778 {
a9098fd0 2779 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
2780
2781 /* If this is a function address on -mcall-aixdesc,
2782 convert it to the address of the descriptor. */
2783 if (DEFAULT_ABI == ABI_AIX
2784 && GET_CODE (operands[1]) == SYMBOL_REF
2785 && XSTR (operands[1], 0)[0] == '.')
2786 {
2787 const char *name = XSTR (operands[1], 0);
2788 rtx new_ref;
2789 while (*name == '.')
2790 name++;
2791 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
2792 CONSTANT_POOL_ADDRESS_P (new_ref)
2793 = CONSTANT_POOL_ADDRESS_P (operands[1]);
2794 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
2795 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
2796 operands[1] = new_ref;
2797 }
7509c759 2798
ee890fe2
SS
2799 if (DEFAULT_ABI == ABI_DARWIN)
2800 {
ab82a49f
AP
2801#if TARGET_MACHO
2802 if (MACHO_DYNAMIC_NO_PIC_P)
2803 {
2804 /* Take care of any required data indirection. */
2805 operands[1] = rs6000_machopic_legitimize_pic_address (
2806 operands[1], mode, operands[0]);
2807 if (operands[0] != operands[1])
2808 emit_insn (gen_rtx_SET (VOIDmode,
2809 operands[0], operands[1]));
2810 return;
2811 }
2812#endif
ee890fe2
SS
2813 emit_insn (gen_macho_high (target, operands[1]));
2814 emit_insn (gen_macho_low (operands[0], target, operands[1]));
2815 return;
2816 }
2817
fb4d4348
GK
2818 emit_insn (gen_elf_high (target, operands[1]));
2819 emit_insn (gen_elf_low (operands[0], target, operands[1]));
2820 return;
2821 }
2822
a9098fd0
GK
2823 /* If this is a SYMBOL_REF that refers to a constant pool entry,
2824 and we have put it in the TOC, we just need to make a TOC-relative
2825 reference to it. */
2826 if (TARGET_TOC
2827 && GET_CODE (operands[1]) == SYMBOL_REF
2828 && CONSTANT_POOL_EXPR_P (operands[1])
2829 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
2830 get_pool_mode (operands[1])))
fb4d4348 2831 {
a9098fd0 2832 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 2833 }
a9098fd0
GK
2834 else if (mode == Pmode
2835 && CONSTANT_P (operands[1])
38886f37
AO
2836 && ((GET_CODE (operands[1]) != CONST_INT
2837 && ! easy_fp_constant (operands[1], mode))
2838 || (GET_CODE (operands[1]) == CONST_INT
2839 && num_insns_constant (operands[1], mode) > 2)
2840 || (GET_CODE (operands[0]) == REG
2841 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0
GK
2842 && GET_CODE (operands[1]) != HIGH
2843 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
2844 && ! TOC_RELATIVE_EXPR_P (operands[1]))
fb4d4348
GK
2845 {
2846 /* Emit a USE operation so that the constant isn't deleted if
2847 expensive optimizations are turned on because nobody
2848 references it. This should only be done for operands that
2849 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
2850 This should not be done for operands that contain LABEL_REFs.
2851 For now, we just handle the obvious case. */
2852 if (GET_CODE (operands[1]) != LABEL_REF)
2853 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
2854
c859cda6 2855#if TARGET_MACHO
ee890fe2 2856 /* Darwin uses a special PIC legitimizer. */
ab82a49f 2857 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 2858 {
ee890fe2
SS
2859 operands[1] =
2860 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
2861 operands[0]);
2862 if (operands[0] != operands[1])
2863 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
2864 return;
2865 }
c859cda6 2866#endif
ee890fe2 2867
fb4d4348
GK
2868 /* If we are to limit the number of things we put in the TOC and
2869 this is a symbol plus a constant we can add in one insn,
2870 just put the symbol in the TOC and add the constant. Don't do
2871 this if reload is in progress. */
2872 if (GET_CODE (operands[1]) == CONST
2873 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
2874 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 2875 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
2876 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
2877 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
2878 && ! side_effects_p (operands[0]))
2879 {
a4f6c312
SS
2880 rtx sym =
2881 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
2882 rtx other = XEXP (XEXP (operands[1], 0), 1);
2883
a9098fd0
GK
2884 sym = force_reg (mode, sym);
2885 if (mode == SImode)
2886 emit_insn (gen_addsi3 (operands[0], sym, other));
2887 else
2888 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
2889 return;
2890 }
2891
a9098fd0 2892 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2893
2894 if (TARGET_TOC
d34c5b80
DE
2895 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))
2896 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
2897 get_pool_constant (XEXP (operands[1], 0)),
2898 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 2899 {
ba4828e0
RK
2900 operands[1]
2901 = gen_rtx_MEM (mode,
2902 create_TOC_reference (XEXP (operands[1], 0)));
2903 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 2904 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 2905 }
fb4d4348
GK
2906 }
2907 break;
a9098fd0 2908
fb4d4348
GK
2909 case TImode:
2910 if (GET_CODE (operands[0]) == MEM
2911 && GET_CODE (XEXP (operands[0], 0)) != REG
2912 && ! reload_in_progress)
792760b9
RK
2913 operands[0]
2914 = replace_equiv_address (operands[0],
2915 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
2916
2917 if (GET_CODE (operands[1]) == MEM
2918 && GET_CODE (XEXP (operands[1], 0)) != REG
2919 && ! reload_in_progress)
792760b9
RK
2920 operands[1]
2921 = replace_equiv_address (operands[1],
2922 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
2923 if (TARGET_POWER)
2924 {
2925 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2926 gen_rtvec (2,
2927 gen_rtx_SET (VOIDmode,
2928 operands[0], operands[1]),
2929 gen_rtx_CLOBBER (VOIDmode,
2930 gen_rtx_SCRATCH (SImode)))));
2931 return;
2932 }
fb4d4348
GK
2933 break;
2934
2935 default:
2936 abort ();
2937 }
2938
a9098fd0
GK
2939 /* Above, we may have called force_const_mem which may have returned
2940 an invalid address. If we can, fix this up; otherwise, reload will
2941 have to deal with it. */
2942 if (GET_CODE (operands[1]) == MEM
2943 && ! memory_address_p (mode, XEXP (operands[1], 0))
2944 && ! reload_in_progress)
f4ef873c 2945 operands[1] = adjust_address (operands[1], mode, 0);
a9098fd0 2946
fb4d4348 2947 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
02a4ec28 2948 return;
fb4d4348 2949}
4697a36c
MM
2950\f
2951/* Initialize a variable CUM of type CUMULATIVE_ARGS
2952 for a call to a function whose data type is FNTYPE.
2953 For a library call, FNTYPE is 0.
2954
2955 For incoming args we set the number of arguments in the prototype large
1c20ae99 2956 so we never return a PARALLEL. */
4697a36c
MM
2957
2958void
2959init_cumulative_args (cum, fntype, libname, incoming)
2960 CUMULATIVE_ARGS *cum;
2961 tree fntype;
296b8152 2962 rtx libname ATTRIBUTE_UNUSED;
4697a36c
MM
2963 int incoming;
2964{
2965 static CUMULATIVE_ARGS zero_cumulative;
2966
2967 *cum = zero_cumulative;
2968 cum->words = 0;
2969 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 2970 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 2971 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
7509c759 2972 cum->call_cookie = CALL_NORMAL;
4cc833b7 2973 cum->sysv_gregno = GP_ARG_MIN_REG;
4697a36c
MM
2974
2975 if (incoming)
bd227acc 2976 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
2977
2978 else if (cum->prototype)
2979 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
2980 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
2981 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
2982
2983 else
2984 cum->nargs_prototype = 0;
2985
2986 cum->orig_nargs = cum->nargs_prototype;
7509c759 2987
a5c76ee6
ZW
2988 /* Check for a longcall attribute. */
2989 if (fntype
2990 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
2991 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
2992 cum->call_cookie = CALL_LONG;
2993
4697a36c
MM
2994 if (TARGET_DEBUG_ARG)
2995 {
2996 fprintf (stderr, "\ninit_cumulative_args:");
2997 if (fntype)
2998 {
2999 tree ret_type = TREE_TYPE (fntype);
3000 fprintf (stderr, " ret code = %s,",
3001 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3002 }
3003
6a4cee5f
MM
3004 if (cum->call_cookie & CALL_LONG)
3005 fprintf (stderr, " longcall,");
3006
4697a36c
MM
3007 fprintf (stderr, " proto = %d, nargs = %d\n",
3008 cum->prototype, cum->nargs_prototype);
3009 }
3010}
3011\f
c229cba9
DE
3012/* If defined, a C expression which determines whether, and in which
3013 direction, to pad out an argument with extra space. The value
3014 should be of type `enum direction': either `upward' to pad above
3015 the argument, `downward' to pad below, or `none' to inhibit
3016 padding.
3017
3018 For the AIX ABI structs are always stored left shifted in their
3019 argument slot. */
3020
9ebbca7d 3021enum direction
c229cba9
DE
3022function_arg_padding (mode, type)
3023 enum machine_mode mode;
3024 tree type;
3025{
c85f7c16 3026 if (type != 0 && AGGREGATE_TYPE_P (type))
9ebbca7d 3027 return upward;
c229cba9
DE
3028
3029 /* This is the default definition. */
3030 return (! BYTES_BIG_ENDIAN
9ebbca7d 3031 ? upward
c229cba9
DE
3032 : ((mode == BLKmode
3033 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
3034 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
3035 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
9ebbca7d 3036 ? downward : upward));
c229cba9
DE
3037}
3038
b6c9286a
MM
3039/* If defined, a C expression that gives the alignment boundary, in bits,
3040 of an argument with the specified mode and type. If it is not defined,
3041 PARM_BOUNDARY is used for all arguments.
3042
2310f99a 3043 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3044
3045int
3046function_arg_boundary (mode, type)
3047 enum machine_mode mode;
9ebbca7d 3048 tree type ATTRIBUTE_UNUSED;
b6c9286a 3049{
f607bc57 3050 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3051 return 64;
a3170dc6
AH
3052 else if (SPE_VECTOR_MODE (mode))
3053 return 64;
0ac081f6
AH
3054 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3055 return 128;
9ebbca7d 3056 else
b6c9286a 3057 return PARM_BOUNDARY;
b6c9286a
MM
3058}
3059\f
4697a36c
MM
3060/* Update the data in CUM to advance over an argument
3061 of mode MODE and data type TYPE.
3062 (TYPE is null for libcalls where that information may not be available.) */
3063
3064void
3065function_arg_advance (cum, mode, type, named)
3066 CUMULATIVE_ARGS *cum;
3067 enum machine_mode mode;
3068 tree type;
3069 int named;
3070{
3071 cum->nargs_prototype--;
3072
0ac081f6
AH
3073 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3074 {
3075 if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0)
3076 cum->vregno++;
3077 else
3078 cum->words += RS6000_ARG_SIZE (mode, type);
3079 }
a4b0320c
AH
3080 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
3081 && named && cum->sysv_gregno <= GP_ARG_MAX_REG)
3082 cum->sysv_gregno++;
f607bc57 3083 else if (DEFAULT_ABI == ABI_V4)
4697a36c 3084 {
a3170dc6 3085 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 3086 && (mode == SFmode || mode == DFmode))
4697a36c 3087 {
4cc833b7
RH
3088 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3089 cum->fregno++;
3090 else
3091 {
3092 if (mode == DFmode)
3093 cum->words += cum->words & 1;
d34c5b80 3094 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 3095 }
4697a36c 3096 }
4cc833b7
RH
3097 else
3098 {
3099 int n_words;
3100 int gregno = cum->sysv_gregno;
3101
3102 /* Aggregates and IEEE quad get passed by reference. */
3103 if ((type && AGGREGATE_TYPE_P (type))
3104 || mode == TFmode)
3105 n_words = 1;
3106 else
d34c5b80 3107 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3108
a4b0320c 3109 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3110 if (n_words == 2 && (gregno & 1) == 0)
3111 gregno += 1;
3112
a4b0320c
AH
3113 /* Long long and SPE vectors are not split between registers
3114 and stack. */
4cc833b7
RH
3115 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
3116 {
3117 /* Long long is aligned on the stack. */
3118 if (n_words == 2)
3119 cum->words += cum->words & 1;
3120 cum->words += n_words;
3121 }
4697a36c 3122
4cc833b7
RH
3123 /* Note: continuing to accumulate gregno past when we've started
3124 spilling to the stack indicates the fact that we've started
3125 spilling to the stack to expand_builtin_saveregs. */
3126 cum->sysv_gregno = gregno + n_words;
3127 }
4697a36c 3128
4cc833b7
RH
3129 if (TARGET_DEBUG_ARG)
3130 {
3131 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3132 cum->words, cum->fregno);
3133 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
3134 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
3135 fprintf (stderr, "mode = %4s, named = %d\n",
3136 GET_MODE_NAME (mode), named);
3137 }
4697a36c
MM
3138 }
3139 else
4cc833b7
RH
3140 {
3141 int align = (TARGET_32BIT && (cum->words & 1) != 0
3142 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 3143
d34c5b80 3144 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 3145
a3170dc6
AH
3146 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3147 && TARGET_HARD_FLOAT && TARGET_FPRS)
fcce224d 3148 cum->fregno += (mode == TFmode ? 2 : 1);
4cc833b7
RH
3149
3150 if (TARGET_DEBUG_ARG)
3151 {
3152 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3153 cum->words, cum->fregno);
3154 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
3155 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
3156 fprintf (stderr, "named = %d, align = %d\n", named, align);
3157 }
3158 }
4697a36c
MM
3159}
3160\f
3161/* Determine where to put an argument to a function.
3162 Value is zero to push the argument on the stack,
3163 or a hard register in which to store the argument.
3164
3165 MODE is the argument's machine mode.
3166 TYPE is the data type of the argument (as a tree).
3167 This is null for libcalls where that information may
3168 not be available.
3169 CUM is a variable of type CUMULATIVE_ARGS which gives info about
3170 the preceding args and about the function being called.
3171 NAMED is nonzero if this argument is a named parameter
3172 (otherwise it is an extra parameter matching an ellipsis).
3173
3174 On RS/6000 the first eight words of non-FP are normally in registers
3175 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
3176 Under V.4, the first 8 FP args are in registers.
3177
3178 If this is floating-point and no prototype is specified, we use
3179 both an FP and integer register (or possibly FP reg and stack). Library
3180 functions (when TYPE is zero) always have the proper types for args,
3181 so we can pass the FP value just in one register. emit_library_function
1c20ae99 3182 doesn't support PARALLEL anyway. */
4697a36c
MM
3183
3184struct rtx_def *
3185function_arg (cum, mode, type, named)
3186 CUMULATIVE_ARGS *cum;
3187 enum machine_mode mode;
3188 tree type;
20c29ebe 3189 int named;
4697a36c 3190{
4cc833b7 3191 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 3192
a4f6c312
SS
3193 /* Return a marker to indicate whether CR1 needs to set or clear the
3194 bit that V.4 uses to say fp args were passed in registers.
3195 Assume that we don't need the marker for software floating point,
3196 or compiler generated library calls. */
4697a36c
MM
3197 if (mode == VOIDmode)
3198 {
f607bc57 3199 if (abi == ABI_V4
7509c759 3200 && cum->nargs_prototype < 0
4697a36c 3201 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 3202 {
a3170dc6
AH
3203 /* For the SPE, we need to crxor CR6 always. */
3204 if (TARGET_SPE_ABI)
3205 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
3206 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
3207 return GEN_INT (cum->call_cookie
3208 | ((cum->fregno == FP_ARG_MIN_REG)
3209 ? CALL_V4_SET_FP_ARGS
3210 : CALL_V4_CLEAR_FP_ARGS));
7509c759 3211 }
4697a36c 3212
7509c759 3213 return GEN_INT (cum->call_cookie);
4697a36c
MM
3214 }
3215
0ac081f6
AH
3216 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3217 {
20c29ebe 3218 if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG)
0ac081f6
AH
3219 return gen_rtx_REG (mode, cum->vregno);
3220 else
3221 return NULL;
3222 }
a4b0320c 3223 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) && named)
a3170dc6 3224 {
a4b0320c 3225 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
a3170dc6
AH
3226 return gen_rtx_REG (mode, cum->sysv_gregno);
3227 else
3228 return NULL;
3229 }
f607bc57 3230 else if (abi == ABI_V4)
4697a36c 3231 {
a3170dc6 3232 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
3233 && (mode == SFmode || mode == DFmode))
3234 {
3235 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3236 return gen_rtx_REG (mode, cum->fregno);
3237 else
3238 return NULL;
3239 }
3240 else
3241 {
3242 int n_words;
3243 int gregno = cum->sysv_gregno;
3244
3245 /* Aggregates and IEEE quad get passed by reference. */
3246 if ((type && AGGREGATE_TYPE_P (type))
3247 || mode == TFmode)
3248 n_words = 1;
3249 else
d34c5b80 3250 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3251
a4b0320c 3252 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3253 if (n_words == 2 && (gregno & 1) == 0)
3254 gregno += 1;
3255
a4b0320c
AH
3256 /* Long long and SPE vectors are not split between registers
3257 and stack. */
4cc833b7 3258 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a4b0320c
AH
3259 {
3260 /* SPE vectors in ... get split into 2 registers. */
3261 if (TARGET_SPE && TARGET_SPE_ABI
3262 && SPE_VECTOR_MODE (mode) && !named)
3263 {
3264 rtx r1, r2;
57de2c8f 3265 enum machine_mode m = SImode;
f9dd72da 3266
a4b0320c
AH
3267 r1 = gen_rtx_REG (m, gregno);
3268 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
3269 r2 = gen_rtx_REG (m, gregno + 1);
3270 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
3271 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
3272 }
3273 return gen_rtx_REG (mode, gregno);
3274 }
4cc833b7
RH
3275 else
3276 return NULL;
3277 }
4697a36c 3278 }
4cc833b7
RH
3279 else
3280 {
3281 int align = (TARGET_32BIT && (cum->words & 1) != 0
3282 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
3283 int align_words = cum->words + align;
4697a36c 3284
4cc833b7
RH
3285 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3286 return NULL_RTX;
3287
3288 if (USE_FP_FOR_ARG_P (*cum, mode, type))
3289 {
3290 if (! type
3291 || ((cum->nargs_prototype > 0)
3292 /* IBM AIX extended its linkage convention definition always
3293 to require FP args after register save area hole on the
3294 stack. */
3295 && (DEFAULT_ABI != ABI_AIX
3296 || ! TARGET_XL_CALL
3297 || (align_words < GP_ARG_NUM_REG))))
3298 return gen_rtx_REG (mode, cum->fregno);
3299
3300 return gen_rtx_PARALLEL (mode,
3301 gen_rtvec (2,
39403d82 3302 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
3303 ((align_words >= GP_ARG_NUM_REG)
3304 ? NULL_RTX
3305 : (align_words
d34c5b80 3306 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
3307 > GP_ARG_NUM_REG
3308 /* If this is partially on the stack, then
3309 we only include the portion actually
3310 in registers here. */
39403d82 3311 ? gen_rtx_REG (SImode,
1c20ae99 3312 GP_ARG_MIN_REG + align_words)
39403d82 3313 : gen_rtx_REG (mode,
1c20ae99
JW
3314 GP_ARG_MIN_REG + align_words))),
3315 const0_rtx),
39403d82
DE
3316 gen_rtx_EXPR_LIST (VOIDmode,
3317 gen_rtx_REG (mode, cum->fregno),
1c20ae99 3318 const0_rtx)));
4cc833b7
RH
3319 }
3320 else if (align_words < GP_ARG_NUM_REG)
3321 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
3322 else
3323 return NULL_RTX;
4697a36c 3324 }
4697a36c
MM
3325}
3326\f
3327/* For an arg passed partly in registers and partly in memory,
3328 this is the number of registers used.
3329 For args passed entirely in registers or entirely in memory, zero. */
3330
3331int
3332function_arg_partial_nregs (cum, mode, type, named)
3333 CUMULATIVE_ARGS *cum;
3334 enum machine_mode mode;
3335 tree type;
d34c5b80 3336 int named ATTRIBUTE_UNUSED;
4697a36c 3337{
f607bc57 3338 if (DEFAULT_ABI == ABI_V4)
4697a36c 3339 return 0;
4697a36c 3340
0ac081f6
AH
3341 if (USE_FP_FOR_ARG_P (*cum, mode, type)
3342 || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type))
4697a36c
MM
3343 {
3344 if (cum->nargs_prototype >= 0)
3345 return 0;
3346 }
3347
3348 if (cum->words < GP_ARG_NUM_REG
d34c5b80 3349 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
3350 {
3351 int ret = GP_ARG_NUM_REG - cum->words;
3352 if (ret && TARGET_DEBUG_ARG)
3353 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
3354
3355 return ret;
3356 }
3357
3358 return 0;
3359}
3360\f
3361/* A C expression that indicates when an argument must be passed by
3362 reference. If nonzero for an argument, a copy of that argument is
3363 made in memory and a pointer to the argument is passed instead of
3364 the argument itself. The pointer is passed in whatever way is
3365 appropriate for passing a pointer to that type.
3366
c8c99a68
DE
3367 Under V.4, structures and unions are passed by reference.
3368
3369 As an extension to all ABIs, variable sized types are passed by
3370 reference. */
4697a36c
MM
3371
3372int
3373function_arg_pass_by_reference (cum, mode, type, named)
296b8152
KG
3374 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3375 enum machine_mode mode ATTRIBUTE_UNUSED;
4697a36c 3376 tree type;
296b8152 3377 int named ATTRIBUTE_UNUSED;
4697a36c 3378{
f607bc57 3379 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
3380 && ((type && AGGREGATE_TYPE_P (type))
3381 || mode == TFmode))
4697a36c
MM
3382 {
3383 if (TARGET_DEBUG_ARG)
3384 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
3385
3386 return 1;
3387 }
c8c99a68 3388 return type && int_size_in_bytes (type) <= 0;
4697a36c 3389}
4697a36c
MM
3390\f
3391/* Perform any needed actions needed for a function that is receiving a
3392 variable number of arguments.
3393
3394 CUM is as above.
3395
3396 MODE and TYPE are the mode and type of the current parameter.
3397
3398 PRETEND_SIZE is a variable that should be set to the amount of stack
3399 that must be pushed by the prolog to pretend that our caller pushed
3400 it.
3401
3402 Normally, this macro will push all remaining incoming registers on the
3403 stack and set PRETEND_SIZE to the length of the registers pushed. */
3404
3405void
3406setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
3407 CUMULATIVE_ARGS *cum;
3408 enum machine_mode mode;
3409 tree type;
de62b72c 3410 int *pretend_size ATTRIBUTE_UNUSED;
4697a36c
MM
3411 int no_rtl;
3412
3413{
4cc833b7
RH
3414 CUMULATIVE_ARGS next_cum;
3415 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 3416 rtx save_area = NULL_RTX, mem;
dfafc897 3417 int first_reg_offset, set;
d34c5b80
DE
3418 tree fntype;
3419 int stdarg_p;
4697a36c 3420
d34c5b80
DE
3421 fntype = TREE_TYPE (current_function_decl);
3422 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
3423 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3424 != void_type_node));
4cc833b7 3425
d34c5b80
DE
3426 /* For varargs, we do not want to skip the dummy va_dcl argument.
3427 For stdargs, we do want to skip the last named argument. */
3428 next_cum = *cum;
3429 if (stdarg_p)
3430 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 3431
f607bc57 3432 if (DEFAULT_ABI == ABI_V4)
d34c5b80 3433 {
4cc833b7 3434 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 3435 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 3436 if (! no_rtl)
2c4974b7 3437 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 3438 - RS6000_VARARGS_SIZE);
4cc833b7
RH
3439
3440 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 3441 }
60e2d0ca 3442 else
4697a36c 3443 {
d34c5b80 3444 first_reg_offset = next_cum.words;
4cc833b7 3445 save_area = virtual_incoming_args_rtx;
00dba523 3446 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
3447
3448 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 3449 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 3450 }
4697a36c 3451
dfafc897 3452 set = get_varargs_alias_set ();
c81fc13e 3453 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 3454 {
dfafc897
FS
3455 mem = gen_rtx_MEM (BLKmode,
3456 plus_constant (save_area,
3457 first_reg_offset * reg_size)),
ba4828e0 3458 set_mem_alias_set (mem, set);
8ac61af7 3459 set_mem_align (mem, BITS_PER_WORD);
dfafc897 3460
4cc833b7 3461 move_block_from_reg
dfafc897 3462 (GP_ARG_MIN_REG + first_reg_offset, mem,
4cc833b7
RH
3463 GP_ARG_NUM_REG - first_reg_offset,
3464 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
4697a36c
MM
3465 }
3466
4697a36c 3467 /* Save FP registers if needed. */
f607bc57 3468 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
3469 && TARGET_HARD_FLOAT && TARGET_FPRS
3470 && ! no_rtl
4cc833b7 3471 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 3472 {
4cc833b7 3473 int fregno = next_cum.fregno;
9ebbca7d 3474 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
3475 rtx lab = gen_label_rtx ();
3476 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 3477
4cc833b7 3478 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 3479 pc_rtx,
39403d82 3480 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
3481 gen_rtx_NE (VOIDmode, cr1,
3482 const0_rtx),
39403d82 3483 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
3484 pc_rtx)));
3485
4cc833b7
RH
3486 while (fregno <= FP_ARG_V4_MAX_REG)
3487 {
dfafc897 3488 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 3489 set_mem_alias_set (mem, set);
dfafc897 3490 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
3491 fregno++;
3492 off += 8;
4697a36c 3493 }
4cc833b7
RH
3494
3495 emit_label (lab);
4697a36c 3496 }
4697a36c 3497}
4697a36c 3498
dfafc897 3499/* Create the va_list data type. */
2c4974b7 3500
dfafc897
FS
3501tree
3502rs6000_build_va_list ()
3503{
bab45a51 3504 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4697a36c 3505
9ebbca7d
GK
3506 /* For AIX, prefer 'char *' because that's what the system
3507 header files like. */
f607bc57 3508 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 3509 return build_pointer_type (char_type_node);
dfafc897 3510
f1e639b1 3511 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 3512 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 3513
9ebbca7d
GK
3514 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
3515 unsigned_char_type_node);
3516 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
3517 unsigned_char_type_node);
dfafc897
FS
3518 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
3519 ptr_type_node);
3520 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
3521 ptr_type_node);
3522
3523 DECL_FIELD_CONTEXT (f_gpr) = record;
3524 DECL_FIELD_CONTEXT (f_fpr) = record;
3525 DECL_FIELD_CONTEXT (f_ovf) = record;
3526 DECL_FIELD_CONTEXT (f_sav) = record;
3527
bab45a51
FS
3528 TREE_CHAIN (record) = type_decl;
3529 TYPE_NAME (record) = type_decl;
dfafc897
FS
3530 TYPE_FIELDS (record) = f_gpr;
3531 TREE_CHAIN (f_gpr) = f_fpr;
3532 TREE_CHAIN (f_fpr) = f_ovf;
3533 TREE_CHAIN (f_ovf) = f_sav;
3534
3535 layout_type (record);
3536
3537 /* The correct type is an array type of one element. */
3538 return build_array_type (record, build_index_type (size_zero_node));
3539}
3540
3541/* Implement va_start. */
3542
3543void
e5faf155 3544rs6000_va_start (valist, nextarg)
dfafc897
FS
3545 tree valist;
3546 rtx nextarg;
4697a36c 3547{
dfafc897
FS
3548 HOST_WIDE_INT words, n_gpr, n_fpr;
3549 tree f_gpr, f_fpr, f_ovf, f_sav;
3550 tree gpr, fpr, ovf, sav, t;
2c4974b7 3551
dfafc897 3552 /* Only SVR4 needs something special. */
f607bc57 3553 if (DEFAULT_ABI != ABI_V4)
dfafc897 3554 {
e5faf155 3555 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
3556 return;
3557 }
3558
973a648b 3559 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
3560 f_fpr = TREE_CHAIN (f_gpr);
3561 f_ovf = TREE_CHAIN (f_fpr);
3562 f_sav = TREE_CHAIN (f_ovf);
3563
8ebecc3b 3564 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
3565 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
3566 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
3567 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
3568 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
3569
3570 /* Count number of gp and fp argument registers used. */
4cc833b7 3571 words = current_function_args_info.words;
dfafc897
FS
3572 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
3573 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
3574
3575 if (TARGET_DEBUG_ARG)
78e1b90d
DE
3576 {
3577 fputs ("va_start: words = ", stderr);
3578 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, words);
3579 fputs (", n_gpr = ", stderr);
3580 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_gpr);
3581 fputs (", n_fpr = ", stderr);
3582 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_fpr);
3583 putc ('\n', stderr);
3584 }
dfafc897
FS
3585
3586 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
3587 TREE_SIDE_EFFECTS (t) = 1;
3588 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3589
3590 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
3591 TREE_SIDE_EFFECTS (t) = 1;
3592 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3593
3594 /* Find the overflow area. */
3595 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
3596 if (words != 0)
3597 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
3598 build_int_2 (words * UNITS_PER_WORD, 0));
3599 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
3600 TREE_SIDE_EFFECTS (t) = 1;
3601 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3602
3603 /* Find the register save area. */
3604 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
3605 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
3606 build_int_2 (-RS6000_VARARGS_SIZE, -1));
3607 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
3608 TREE_SIDE_EFFECTS (t) = 1;
3609 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3610}
3611
3612/* Implement va_arg. */
3613
3614rtx
3615rs6000_va_arg (valist, type)
3616 tree valist, type;
3617{
3618 tree f_gpr, f_fpr, f_ovf, f_sav;
3619 tree gpr, fpr, ovf, sav, reg, t, u;
3620 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
3621 rtx lab_false, lab_over, addr_rtx, r;
3622
f607bc57 3623 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
3624 {
3625 /* Variable sized types are passed by reference. */
3626 if (int_size_in_bytes (type) <= 0)
3627 {
3628 u = build_pointer_type (type);
3629
3630 /* Args grow upward. */
3631 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
3632 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
3633 TREE_SIDE_EFFECTS (t) = 1;
3634
3635 t = build1 (NOP_EXPR, build_pointer_type (u), t);
3636 TREE_SIDE_EFFECTS (t) = 1;
3637
3638 t = build1 (INDIRECT_REF, u, t);
3639 TREE_SIDE_EFFECTS (t) = 1;
3640
3641 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
3642 }
3643 else
3644 return std_expand_builtin_va_arg (valist, type);
3645 }
dfafc897 3646
973a648b 3647 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
3648 f_fpr = TREE_CHAIN (f_gpr);
3649 f_ovf = TREE_CHAIN (f_fpr);
3650 f_sav = TREE_CHAIN (f_ovf);
3651
8ebecc3b 3652 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
3653 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
3654 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
3655 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
3656 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
3657
3658 size = int_size_in_bytes (type);
3659 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 3660
dfafc897 3661 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 3662 {
dfafc897
FS
3663 /* Aggregates and long doubles are passed by reference. */
3664 indirect_p = 1;
3665 reg = gpr;
3666 n_reg = 1;
3667 sav_ofs = 0;
3668 sav_scale = 4;
d3294cd9
FS
3669 size = UNITS_PER_WORD;
3670 rsize = 1;
dfafc897 3671 }
a3170dc6 3672 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
3673 {
3674 /* FP args go in FP registers, if present. */
3675 indirect_p = 0;
3676 reg = fpr;
3677 n_reg = 1;
3678 sav_ofs = 8*4;
3679 sav_scale = 8;
4cc833b7 3680 }
dfafc897
FS
3681 else
3682 {
3683 /* Otherwise into GP registers. */
3684 indirect_p = 0;
3685 reg = gpr;
3686 n_reg = rsize;
3687 sav_ofs = 0;
3688 sav_scale = 4;
3689 }
3690
a4f6c312 3691 /* Pull the value out of the saved registers ... */
dfafc897
FS
3692
3693 lab_false = gen_label_rtx ();
3694 lab_over = gen_label_rtx ();
3695 addr_rtx = gen_reg_rtx (Pmode);
3696
16861f33
AH
3697 /* AltiVec vectors never go in registers. */
3698 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 3699 {
41daaf0e
AH
3700 TREE_THIS_VOLATILE (reg) = 1;
3701 emit_cmp_and_jump_insns
3702 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
3703 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
3704 lab_false);
dfafc897 3705
41daaf0e
AH
3706 /* Long long is aligned in the registers. */
3707 if (n_reg > 1)
3708 {
3709 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
3710 build_int_2 (n_reg - 1, 0));
3711 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
3712 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
3713 TREE_SIDE_EFFECTS (u) = 1;
3714 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
3715 }
2c4974b7 3716
41daaf0e
AH
3717 if (sav_ofs)
3718 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
3719 else
3720 t = sav;
2c4974b7 3721
41daaf0e
AH
3722 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
3723 build_int_2 (n_reg, 0));
3724 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 3725
41daaf0e
AH
3726 u = build1 (CONVERT_EXPR, integer_type_node, u);
3727 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 3728
41daaf0e
AH
3729 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
3730 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 3731
41daaf0e
AH
3732 t = build (PLUS_EXPR, ptr_type_node, t, u);
3733 TREE_SIDE_EFFECTS (t) = 1;
3734
3735 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
3736 if (r != addr_rtx)
3737 emit_move_insn (addr_rtx, r);
3738
3739 emit_jump_insn (gen_jump (lab_over));
3740 emit_barrier ();
3741 }
dfafc897 3742
dfafc897
FS
3743 emit_label (lab_false);
3744
a4f6c312 3745 /* ... otherwise out of the overflow area. */
dfafc897 3746
41daaf0e
AH
3747 /* Make sure we don't find reg 7 for the next int arg.
3748
3749 All AltiVec vectors go in the overflow area. So in the AltiVec
3750 case we need to get the vectors from the overflow area, but
3751 remember where the GPRs and FPRs are. */
16861f33
AH
3752 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
3753 || !TARGET_ALTIVEC))
dfafc897
FS
3754 {
3755 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
3756 TREE_SIDE_EFFECTS (t) = 1;
3757 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3758 }
3759
3760 /* Care for on-stack alignment if needed. */
3761 if (rsize <= 1)
3762 t = ovf;
3763 else
3764 {
41daaf0e
AH
3765 int align;
3766
16861f33
AH
3767 /* AltiVec vectors are 16 byte aligned. */
3768 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
3769 align = 15;
3770 else
3771 align = 7;
3772
3773 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
3774 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
3775 }
3776 t = save_expr (t);
3777
3778 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
3779 if (r != addr_rtx)
3780 emit_move_insn (addr_rtx, r);
3781
3782 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
3783 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
3784 TREE_SIDE_EFFECTS (t) = 1;
3785 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3786
3787 emit_label (lab_over);
3788
3789 if (indirect_p)
3790 {
3791 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 3792 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
3793 emit_move_insn (addr_rtx, r);
3794 }
3795
3796 return addr_rtx;
4697a36c 3797}
0ac081f6
AH
3798
3799/* Builtins. */
3800
6a2dd09a
RS
3801#define def_builtin(MASK, NAME, TYPE, CODE) \
3802do { \
3803 if ((MASK) & target_flags) \
3804 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
3805 NULL, NULL_TREE); \
0ac081f6
AH
3806} while (0)
3807
24408032
AH
3808/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
3809
2212663f 3810static const struct builtin_description bdesc_3arg[] =
24408032
AH
3811{
3812 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
3813 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
3814 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
3815 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
3816 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
3817 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
3818 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
3819 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
3820 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
3821 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
3822 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
3823 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
3824 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
3825 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
3826 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
3827 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
3828 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
3829 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
3830 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
3831 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
3832 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
3833 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
3834 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
3835};
2212663f 3836
95385cbb
AH
3837/* DST operations: void foo (void *, const int, const char). */
3838
3839static const struct builtin_description bdesc_dst[] =
3840{
3841 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
3842 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
3843 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
3844 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
3845};
3846
2212663f 3847/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 3848
a3170dc6 3849static struct builtin_description bdesc_2arg[] =
0ac081f6 3850{
f18c054f
DB
3851 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
3852 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
3853 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
3854 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
3855 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
3856 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
3857 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
3858 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
3859 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
3860 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
3861 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 3862 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
3863 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
3864 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
3865 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
3866 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
3867 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
3868 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
3869 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
3870 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
3871 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
3872 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
3873 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
3874 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
3875 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
3876 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
3877 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
3878 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
3879 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
3880 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
3881 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
3882 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
3883 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
3884 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
3885 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
3886 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
3887 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
3888 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
3889 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
3890 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
3891 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
3892 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
3893 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
3894 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
3895 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
3896 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
3897 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
3898 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
3899 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
3900 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
3901 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
3902 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
3903 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
3904 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
3905 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
3906 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
3907 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
3908 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
3909 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
3910 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
3911 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
3912 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
3913 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
3914 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
3915 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 3916 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
3917 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
3918 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
3919 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
3920 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
3921 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
3922 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
3923 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
3924 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
3925 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
3926 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
3927 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
3928 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
3929 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
3930 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
3931 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
3932 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
3933 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
3934 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
3935 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
3936 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
3937 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
3938 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 3939 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
3940 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
3941 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
3942 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
3943 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
3944 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
3945 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
3946 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
3947 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
3948 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
3949 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
3950 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
3951 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
3952 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
3953 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
3954 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
3955 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
3956 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
3957 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
3958 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
3959 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
3960 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
3961 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
3962 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 3963 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
3964
3965 /* Place holder, leave as first spe builtin. */
3966 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
3967 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
3968 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
3969 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
3970 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
3971 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
3972 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
3973 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
3974 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
3975 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
3976 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
3977 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
3978 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
3979 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
3980 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
3981 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
3982 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
3983 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
3984 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
3985 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
3986 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
3987 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
3988 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
3989 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
3990 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
3991 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
3992 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
3993 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
3994 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
3995 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
3996 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
3997 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
3998 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
3999 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
4000 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
4001 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
4002 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
4003 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
4004 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
4005 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
4006 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
4007 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
4008 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
4009 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
4010 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
4011 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
4012 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
4013 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
4014 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
4015 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
4016 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
4017 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
4018 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
4019 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
4020 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
4021 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
4022 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
4023 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
4024 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
4025 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
4026 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
4027 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
4028 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
4029 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
4030 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
4031 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
4032 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
4033 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
4034 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
4035 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
4036 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
4037 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
4038 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
4039 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
4040 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
4041 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
4042 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
4043 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
4044 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
4045 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
4046 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
4047 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
4048 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
4049 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
4050 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
4051 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
4052 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
4053 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
4054 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
4055 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
4056 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
4057 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
4058 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
4059 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
4060 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
4061 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
4062 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
4063 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
4064 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
4065 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
4066 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
4067 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
4068 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
4069 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
4070 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
4071 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
4072 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
4073 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
4074 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
4075
4076 /* SPE binary operations expecting a 5-bit unsigned literal. */
4077 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
4078
4079 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
4080 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
4081 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
4082 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
4083 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
4084 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
4085 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
4086 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
4087 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
4088 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
4089 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
4090 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
4091 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
4092 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
4093 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
4094 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
4095 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
4096 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
4097 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
4098 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
4099 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
4100 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
4101 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
4102 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
4103 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
4104 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
4105
4106 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 4107 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
4108};
4109
4110/* AltiVec predicates. */
4111
4112struct builtin_description_predicates
4113{
4114 const unsigned int mask;
4115 const enum insn_code icode;
4116 const char *opcode;
4117 const char *const name;
4118 const enum rs6000_builtins code;
4119};
4120
4121static const struct builtin_description_predicates bdesc_altivec_preds[] =
4122{
4123 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
4124 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
4125 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
4126 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
4127 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
4128 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
4129 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
4130 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
4131 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
4132 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
4133 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
4134 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
4135 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 4136};
24408032 4137
a3170dc6
AH
4138/* SPE predicates. */
4139static struct builtin_description bdesc_spe_predicates[] =
4140{
4141 /* Place-holder. Leave as first. */
4142 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
4143 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
4144 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
4145 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
4146 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
4147 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
4148 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
4149 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
4150 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
4151 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
4152 /* Place-holder. Leave as last. */
4153 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
4154};
4155
4156/* SPE evsel predicates. */
4157static struct builtin_description bdesc_spe_evsel[] =
4158{
4159 /* Place-holder. Leave as first. */
4160 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
4161 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
4162 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
4163 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
4164 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
4165 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
4166 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
4167 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
4168 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
4169 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
4170 /* Place-holder. Leave as last. */
4171 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
4172};
4173
b6d08ca1 4174/* ABS* operations. */
100c4561
AH
4175
4176static const struct builtin_description bdesc_abs[] =
4177{
4178 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
4179 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
4180 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
4181 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
4182 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
4183 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
4184 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
4185};
4186
617e0e1d
DB
4187/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
4188 foo (VECa). */
24408032 4189
a3170dc6 4190static struct builtin_description bdesc_1arg[] =
2212663f 4191{
617e0e1d
DB
4192 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
4193 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
4194 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
4195 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
4196 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
4197 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
4198 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
4199 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
4200 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
4201 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
4202 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
4203 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
4204 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
4205 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
4206 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
4207 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
4208 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
4209
4210 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
4211 end with SPE_BUILTIN_EVSUBFUSIAAW. */
4212 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
4213 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
4214 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
4215 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
4216 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
4217 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
4218 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
4219 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
4220 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
4221 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
4222 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
4223 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
4224 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
4225 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
4226 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
4227 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
4228 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
4229 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
4230 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
4231 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
4232 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
4233 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
4234 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
4235 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
4236 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
4237 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
4238 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
4239 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
4240 { 0, CODE_FOR_spe_evsplatfi, "__builtin_spe_evsplatfi", SPE_BUILTIN_EVSPLATFI },
4241 { 0, CODE_FOR_spe_evsplati, "__builtin_spe_evsplati", SPE_BUILTIN_EVSPLATI },
4242
4243 /* Place-holder. Leave as last unary SPE builtin. */
4244 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
4245};
4246
4247static rtx
92898235 4248rs6000_expand_unop_builtin (icode, arglist, target)
2212663f
DB
4249 enum insn_code icode;
4250 tree arglist;
4251 rtx target;
4252{
4253 rtx pat;
4254 tree arg0 = TREE_VALUE (arglist);
4255 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4256 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4257 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4258
0559cc77
DE
4259 if (icode == CODE_FOR_nothing)
4260 /* Builtin not supported on this processor. */
4261 return 0;
4262
20e26713
AH
4263 /* If we got invalid arguments bail out before generating bad rtl. */
4264 if (arg0 == error_mark_node)
9a171fcd 4265 return const0_rtx;
20e26713 4266
0559cc77
DE
4267 if (icode == CODE_FOR_altivec_vspltisb
4268 || icode == CODE_FOR_altivec_vspltish
4269 || icode == CODE_FOR_altivec_vspltisw
4270 || icode == CODE_FOR_spe_evsplatfi
4271 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
4272 {
4273 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
4274 if (GET_CODE (op0) != CONST_INT
4275 || INTVAL (op0) > 0x1f
4276 || INTVAL (op0) < -0x1f)
4277 {
4278 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 4279 return const0_rtx;
b44140e7 4280 }
b44140e7
AH
4281 }
4282
c62f2db5 4283 if (target == 0
2212663f
DB
4284 || GET_MODE (target) != tmode
4285 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4286 target = gen_reg_rtx (tmode);
4287
4288 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4289 op0 = copy_to_mode_reg (mode0, op0);
4290
4291 pat = GEN_FCN (icode) (target, op0);
4292 if (! pat)
4293 return 0;
4294 emit_insn (pat);
0ac081f6 4295
2212663f
DB
4296 return target;
4297}
ae4b4a02 4298
100c4561
AH
4299static rtx
4300altivec_expand_abs_builtin (icode, arglist, target)
4301 enum insn_code icode;
4302 tree arglist;
4303 rtx target;
4304{
4305 rtx pat, scratch1, scratch2;
4306 tree arg0 = TREE_VALUE (arglist);
4307 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4308 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4309 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4310
4311 /* If we have invalid arguments, bail out before generating bad rtl. */
4312 if (arg0 == error_mark_node)
9a171fcd 4313 return const0_rtx;
100c4561
AH
4314
4315 if (target == 0
4316 || GET_MODE (target) != tmode
4317 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4318 target = gen_reg_rtx (tmode);
4319
4320 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4321 op0 = copy_to_mode_reg (mode0, op0);
4322
4323 scratch1 = gen_reg_rtx (mode0);
4324 scratch2 = gen_reg_rtx (mode0);
4325
4326 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
4327 if (! pat)
4328 return 0;
4329 emit_insn (pat);
4330
4331 return target;
4332}
4333
0ac081f6 4334static rtx
92898235 4335rs6000_expand_binop_builtin (icode, arglist, target)
0ac081f6
AH
4336 enum insn_code icode;
4337 tree arglist;
4338 rtx target;
4339{
4340 rtx pat;
4341 tree arg0 = TREE_VALUE (arglist);
4342 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4343 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4344 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4345 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4346 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4347 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4348
0559cc77
DE
4349 if (icode == CODE_FOR_nothing)
4350 /* Builtin not supported on this processor. */
4351 return 0;
4352
20e26713
AH
4353 /* If we got invalid arguments bail out before generating bad rtl. */
4354 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 4355 return const0_rtx;
20e26713 4356
0559cc77
DE
4357 if (icode == CODE_FOR_altivec_vcfux
4358 || icode == CODE_FOR_altivec_vcfsx
4359 || icode == CODE_FOR_altivec_vctsxs
4360 || icode == CODE_FOR_altivec_vctuxs
4361 || icode == CODE_FOR_altivec_vspltb
4362 || icode == CODE_FOR_altivec_vsplth
4363 || icode == CODE_FOR_altivec_vspltw
4364 || icode == CODE_FOR_spe_evaddiw
4365 || icode == CODE_FOR_spe_evldd
4366 || icode == CODE_FOR_spe_evldh
4367 || icode == CODE_FOR_spe_evldw
4368 || icode == CODE_FOR_spe_evlhhesplat
4369 || icode == CODE_FOR_spe_evlhhossplat
4370 || icode == CODE_FOR_spe_evlhhousplat
4371 || icode == CODE_FOR_spe_evlwhe
4372 || icode == CODE_FOR_spe_evlwhos
4373 || icode == CODE_FOR_spe_evlwhou
4374 || icode == CODE_FOR_spe_evlwhsplat
4375 || icode == CODE_FOR_spe_evlwwsplat
4376 || icode == CODE_FOR_spe_evrlwi
4377 || icode == CODE_FOR_spe_evslwi
4378 || icode == CODE_FOR_spe_evsrwis
4379 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
4380 {
4381 /* Only allow 5-bit unsigned literals. */
b44140e7
AH
4382 if (TREE_CODE (arg1) != INTEGER_CST
4383 || TREE_INT_CST_LOW (arg1) & ~0x1f)
4384 {
4385 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 4386 return const0_rtx;
b44140e7 4387 }
b44140e7
AH
4388 }
4389
c62f2db5 4390 if (target == 0
0ac081f6
AH
4391 || GET_MODE (target) != tmode
4392 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4393 target = gen_reg_rtx (tmode);
4394
4395 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4396 op0 = copy_to_mode_reg (mode0, op0);
4397 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4398 op1 = copy_to_mode_reg (mode1, op1);
4399
4400 pat = GEN_FCN (icode) (target, op0, op1);
4401 if (! pat)
4402 return 0;
4403 emit_insn (pat);
4404
4405 return target;
4406}
6525c0e7 4407
ae4b4a02
AH
4408static rtx
4409altivec_expand_predicate_builtin (icode, opcode, arglist, target)
4410 enum insn_code icode;
4411 const char *opcode;
4412 tree arglist;
4413 rtx target;
4414{
4415 rtx pat, scratch;
4416 tree cr6_form = TREE_VALUE (arglist);
4417 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
4418 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4419 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4420 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4421 enum machine_mode tmode = SImode;
4422 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4423 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4424 int cr6_form_int;
4425
4426 if (TREE_CODE (cr6_form) != INTEGER_CST)
4427 {
4428 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 4429 return const0_rtx;
ae4b4a02
AH
4430 }
4431 else
4432 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
4433
4434 if (mode0 != mode1)
4435 abort ();
4436
4437 /* If we have invalid arguments, bail out before generating bad rtl. */
4438 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 4439 return const0_rtx;
ae4b4a02
AH
4440
4441 if (target == 0
4442 || GET_MODE (target) != tmode
4443 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4444 target = gen_reg_rtx (tmode);
4445
4446 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4447 op0 = copy_to_mode_reg (mode0, op0);
4448 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4449 op1 = copy_to_mode_reg (mode1, op1);
4450
4451 scratch = gen_reg_rtx (mode0);
4452
4453 pat = GEN_FCN (icode) (scratch, op0, op1,
4454 gen_rtx (SYMBOL_REF, Pmode, opcode));
4455 if (! pat)
4456 return 0;
4457 emit_insn (pat);
4458
4459 /* The vec_any* and vec_all* predicates use the same opcodes for two
4460 different operations, but the bits in CR6 will be different
4461 depending on what information we want. So we have to play tricks
4462 with CR6 to get the right bits out.
4463
4464 If you think this is disgusting, look at the specs for the
4465 AltiVec predicates. */
4466
4467 switch (cr6_form_int)
4468 {
4469 case 0:
4470 emit_insn (gen_cr6_test_for_zero (target));
4471 break;
4472 case 1:
4473 emit_insn (gen_cr6_test_for_zero_reverse (target));
4474 break;
4475 case 2:
4476 emit_insn (gen_cr6_test_for_lt (target));
4477 break;
4478 case 3:
4479 emit_insn (gen_cr6_test_for_lt_reverse (target));
4480 break;
4481 default:
4482 error ("argument 1 of __builtin_altivec_predicate is out of range");
4483 break;
4484 }
4485
4486 return target;
4487}
4488
6525c0e7
AH
4489static rtx
4490altivec_expand_stv_builtin (icode, arglist)
4491 enum insn_code icode;
4492 tree arglist;
4493{
4494 tree arg0 = TREE_VALUE (arglist);
4495 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4496 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4497 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4498 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4499 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4500 rtx pat;
4501 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
4502 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
4503 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
4504
4505 /* Invalid arguments. Bail before doing anything stoopid! */
4506 if (arg0 == error_mark_node
4507 || arg1 == error_mark_node
4508 || arg2 == error_mark_node)
9a171fcd 4509 return const0_rtx;
6525c0e7
AH
4510
4511 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
4512 op0 = copy_to_mode_reg (mode2, op0);
4513 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
4514 op1 = copy_to_mode_reg (mode0, op1);
4515 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
4516 op2 = copy_to_mode_reg (mode1, op2);
4517
4518 pat = GEN_FCN (icode) (op1, op2, op0);
4519 if (pat)
4520 emit_insn (pat);
4521 return NULL_RTX;
4522}
4523
2212663f 4524static rtx
92898235 4525rs6000_expand_ternop_builtin (icode, arglist, target)
2212663f
DB
4526 enum insn_code icode;
4527 tree arglist;
4528 rtx target;
4529{
4530 rtx pat;
4531 tree arg0 = TREE_VALUE (arglist);
4532 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4533 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4534 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4535 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4536 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4537 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4538 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4539 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4540 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 4541
774b5662
DE
4542 if (icode == CODE_FOR_nothing)
4543 /* Builtin not supported on this processor. */
4544 return 0;
4545
20e26713
AH
4546 /* If we got invalid arguments bail out before generating bad rtl. */
4547 if (arg0 == error_mark_node
4548 || arg1 == error_mark_node
4549 || arg2 == error_mark_node)
9a171fcd 4550 return const0_rtx;
20e26713 4551
774b5662
DE
4552 if (icode == CODE_FOR_altivec_vsldoi_4sf
4553 || icode == CODE_FOR_altivec_vsldoi_4si
4554 || icode == CODE_FOR_altivec_vsldoi_8hi
4555 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
4556 {
4557 /* Only allow 4-bit unsigned literals. */
b44140e7
AH
4558 if (TREE_CODE (arg2) != INTEGER_CST
4559 || TREE_INT_CST_LOW (arg2) & ~0xf)
4560 {
4561 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 4562 return const0_rtx;
b44140e7 4563 }
b44140e7
AH
4564 }
4565
c62f2db5 4566 if (target == 0
2212663f
DB
4567 || GET_MODE (target) != tmode
4568 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4569 target = gen_reg_rtx (tmode);
4570
4571 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4572 op0 = copy_to_mode_reg (mode0, op0);
4573 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4574 op1 = copy_to_mode_reg (mode1, op1);
4575 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
4576 op2 = copy_to_mode_reg (mode2, op2);
4577
4578 pat = GEN_FCN (icode) (target, op0, op1, op2);
4579 if (! pat)
4580 return 0;
4581 emit_insn (pat);
4582
4583 return target;
4584}
92898235 4585
3a9b8c7e 4586/* Expand the lvx builtins. */
0ac081f6 4587static rtx
3a9b8c7e 4588altivec_expand_ld_builtin (exp, target, expandedp)
0ac081f6
AH
4589 tree exp;
4590 rtx target;
92898235 4591 bool *expandedp;
0ac081f6 4592{
0ac081f6
AH
4593 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4594 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 4595 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
4596 tree arg0;
4597 enum machine_mode tmode, mode0;
7c3abc73 4598 rtx pat, op0;
3a9b8c7e 4599 enum insn_code icode;
92898235 4600
0ac081f6
AH
4601 switch (fcode)
4602 {
f18c054f
DB
4603 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
4604 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 4605 break;
f18c054f
DB
4606 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
4607 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
4608 break;
4609 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
4610 icode = CODE_FOR_altivec_lvx_4si;
4611 break;
4612 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
4613 icode = CODE_FOR_altivec_lvx_4sf;
4614 break;
4615 default:
4616 *expandedp = false;
4617 return NULL_RTX;
4618 }
0ac081f6 4619
3a9b8c7e 4620 *expandedp = true;
f18c054f 4621
3a9b8c7e
AH
4622 arg0 = TREE_VALUE (arglist);
4623 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4624 tmode = insn_data[icode].operand[0].mode;
4625 mode0 = insn_data[icode].operand[1].mode;
f18c054f 4626
3a9b8c7e
AH
4627 if (target == 0
4628 || GET_MODE (target) != tmode
4629 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4630 target = gen_reg_rtx (tmode);
24408032 4631
3a9b8c7e
AH
4632 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4633 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 4634
3a9b8c7e
AH
4635 pat = GEN_FCN (icode) (target, op0);
4636 if (! pat)
4637 return 0;
4638 emit_insn (pat);
4639 return target;
4640}
f18c054f 4641
3a9b8c7e
AH
4642/* Expand the stvx builtins. */
4643static rtx
4644altivec_expand_st_builtin (exp, target, expandedp)
4645 tree exp;
7c3abc73 4646 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
4647 bool *expandedp;
4648{
4649 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4650 tree arglist = TREE_OPERAND (exp, 1);
4651 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4652 tree arg0, arg1;
4653 enum machine_mode mode0, mode1;
7c3abc73 4654 rtx pat, op0, op1;
3a9b8c7e 4655 enum insn_code icode;
f18c054f 4656
3a9b8c7e
AH
4657 switch (fcode)
4658 {
4659 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
4660 icode = CODE_FOR_altivec_stvx_16qi;
4661 break;
4662 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
4663 icode = CODE_FOR_altivec_stvx_8hi;
4664 break;
4665 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
4666 icode = CODE_FOR_altivec_stvx_4si;
4667 break;
4668 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
4669 icode = CODE_FOR_altivec_stvx_4sf;
4670 break;
4671 default:
4672 *expandedp = false;
4673 return NULL_RTX;
4674 }
24408032 4675
3a9b8c7e
AH
4676 arg0 = TREE_VALUE (arglist);
4677 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4678 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4679 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4680 mode0 = insn_data[icode].operand[0].mode;
4681 mode1 = insn_data[icode].operand[1].mode;
f18c054f 4682
3a9b8c7e
AH
4683 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4684 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
4685 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
4686 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 4687
3a9b8c7e
AH
4688 pat = GEN_FCN (icode) (op0, op1);
4689 if (pat)
4690 emit_insn (pat);
f18c054f 4691
3a9b8c7e
AH
4692 *expandedp = true;
4693 return NULL_RTX;
4694}
f18c054f 4695
3a9b8c7e
AH
4696/* Expand the dst builtins. */
4697static rtx
4698altivec_expand_dst_builtin (exp, target, expandedp)
4699 tree exp;
7c3abc73 4700 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
4701 bool *expandedp;
4702{
4703 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4704 tree arglist = TREE_OPERAND (exp, 1);
4705 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4706 tree arg0, arg1, arg2;
4707 enum machine_mode mode0, mode1, mode2;
7c3abc73 4708 rtx pat, op0, op1, op2;
3a9b8c7e 4709 struct builtin_description *d;
a3170dc6 4710 size_t i;
f18c054f 4711
3a9b8c7e 4712 *expandedp = false;
f18c054f 4713
3a9b8c7e
AH
4714 /* Handle DST variants. */
4715 d = (struct builtin_description *) bdesc_dst;
4716 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
4717 if (d->code == fcode)
4718 {
4719 arg0 = TREE_VALUE (arglist);
4720 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4721 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4722 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4723 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4724 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4725 mode0 = insn_data[d->icode].operand[0].mode;
4726 mode1 = insn_data[d->icode].operand[1].mode;
4727 mode2 = insn_data[d->icode].operand[2].mode;
24408032 4728
3a9b8c7e
AH
4729 /* Invalid arguments, bail out before generating bad rtl. */
4730 if (arg0 == error_mark_node
4731 || arg1 == error_mark_node
4732 || arg2 == error_mark_node)
4733 return const0_rtx;
f18c054f 4734
3a9b8c7e
AH
4735 if (TREE_CODE (arg2) != INTEGER_CST
4736 || TREE_INT_CST_LOW (arg2) & ~0x3)
4737 {
4738 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
4739 return const0_rtx;
4740 }
f18c054f 4741
3a9b8c7e
AH
4742 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
4743 op0 = copy_to_mode_reg (mode0, op0);
4744 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
4745 op1 = copy_to_mode_reg (mode1, op1);
24408032 4746
3a9b8c7e
AH
4747 pat = GEN_FCN (d->icode) (op0, op1, op2);
4748 if (pat != 0)
4749 emit_insn (pat);
f18c054f 4750
3a9b8c7e
AH
4751 *expandedp = true;
4752 return NULL_RTX;
4753 }
f18c054f 4754
3a9b8c7e
AH
4755 return NULL_RTX;
4756}
24408032 4757
3a9b8c7e
AH
4758/* Expand the builtin in EXP and store the result in TARGET. Store
4759 true in *EXPANDEDP if we found a builtin to expand. */
4760static rtx
4761altivec_expand_builtin (exp, target, expandedp)
4762 tree exp;
4763 rtx target;
4764 bool *expandedp;
4765{
4766 struct builtin_description *d;
4767 struct builtin_description_predicates *dp;
4768 size_t i;
4769 enum insn_code icode;
4770 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4771 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
4772 tree arg0;
4773 rtx op0, pat;
4774 enum machine_mode tmode, mode0;
3a9b8c7e 4775 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 4776
3a9b8c7e
AH
4777 target = altivec_expand_ld_builtin (exp, target, expandedp);
4778 if (*expandedp)
4779 return target;
0ac081f6 4780
3a9b8c7e
AH
4781 target = altivec_expand_st_builtin (exp, target, expandedp);
4782 if (*expandedp)
4783 return target;
4784
4785 target = altivec_expand_dst_builtin (exp, target, expandedp);
4786 if (*expandedp)
4787 return target;
4788
4789 *expandedp = true;
95385cbb 4790
3a9b8c7e
AH
4791 switch (fcode)
4792 {
6525c0e7
AH
4793 case ALTIVEC_BUILTIN_STVX:
4794 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
4795 case ALTIVEC_BUILTIN_STVEBX:
4796 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
4797 case ALTIVEC_BUILTIN_STVEHX:
4798 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
4799 case ALTIVEC_BUILTIN_STVEWX:
4800 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
4801 case ALTIVEC_BUILTIN_STVXL:
4802 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 4803
95385cbb
AH
4804 case ALTIVEC_BUILTIN_MFVSCR:
4805 icode = CODE_FOR_altivec_mfvscr;
4806 tmode = insn_data[icode].operand[0].mode;
4807
4808 if (target == 0
4809 || GET_MODE (target) != tmode
4810 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4811 target = gen_reg_rtx (tmode);
4812
4813 pat = GEN_FCN (icode) (target);
0ac081f6
AH
4814 if (! pat)
4815 return 0;
4816 emit_insn (pat);
95385cbb
AH
4817 return target;
4818
4819 case ALTIVEC_BUILTIN_MTVSCR:
4820 icode = CODE_FOR_altivec_mtvscr;
4821 arg0 = TREE_VALUE (arglist);
4822 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4823 mode0 = insn_data[icode].operand[0].mode;
4824
4825 /* If we got invalid arguments bail out before generating bad rtl. */
4826 if (arg0 == error_mark_node)
9a171fcd 4827 return const0_rtx;
95385cbb
AH
4828
4829 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4830 op0 = copy_to_mode_reg (mode0, op0);
4831
4832 pat = GEN_FCN (icode) (op0);
4833 if (pat)
4834 emit_insn (pat);
4835 return NULL_RTX;
3a9b8c7e 4836
95385cbb
AH
4837 case ALTIVEC_BUILTIN_DSSALL:
4838 emit_insn (gen_altivec_dssall ());
4839 return NULL_RTX;
4840
4841 case ALTIVEC_BUILTIN_DSS:
4842 icode = CODE_FOR_altivec_dss;
4843 arg0 = TREE_VALUE (arglist);
4844 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4845 mode0 = insn_data[icode].operand[0].mode;
4846
4847 /* If we got invalid arguments bail out before generating bad rtl. */
4848 if (arg0 == error_mark_node)
9a171fcd 4849 return const0_rtx;
95385cbb 4850
b44140e7
AH
4851 if (TREE_CODE (arg0) != INTEGER_CST
4852 || TREE_INT_CST_LOW (arg0) & ~0x3)
4853 {
4854 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 4855 return const0_rtx;
b44140e7
AH
4856 }
4857
95385cbb
AH
4858 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4859 op0 = copy_to_mode_reg (mode0, op0);
4860
4861 emit_insn (gen_altivec_dss (op0));
0ac081f6
AH
4862 return NULL_RTX;
4863 }
24408032 4864
100c4561
AH
4865 /* Expand abs* operations. */
4866 d = (struct builtin_description *) bdesc_abs;
ca7558fc 4867 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
4868 if (d->code == fcode)
4869 return altivec_expand_abs_builtin (d->icode, arglist, target);
4870
ae4b4a02
AH
4871 /* Expand the AltiVec predicates. */
4872 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 4873 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
4874 if (dp->code == fcode)
4875 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
4876
6525c0e7
AH
4877 /* LV* are funky. We initialized them differently. */
4878 switch (fcode)
4879 {
4880 case ALTIVEC_BUILTIN_LVSL:
92898235 4881 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
4882 arglist, target);
4883 case ALTIVEC_BUILTIN_LVSR:
92898235
AH
4884 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsr,
4885 arglist, target);
6525c0e7 4886 case ALTIVEC_BUILTIN_LVEBX:
92898235
AH
4887 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvebx,
4888 arglist, target);
6525c0e7 4889 case ALTIVEC_BUILTIN_LVEHX:
92898235
AH
4890 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvehx,
4891 arglist, target);
6525c0e7 4892 case ALTIVEC_BUILTIN_LVEWX:
92898235
AH
4893 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvewx,
4894 arglist, target);
6525c0e7 4895 case ALTIVEC_BUILTIN_LVXL:
92898235
AH
4896 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvxl,
4897 arglist, target);
6525c0e7 4898 case ALTIVEC_BUILTIN_LVX:
92898235
AH
4899 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvx,
4900 arglist, target);
6525c0e7
AH
4901 default:
4902 break;
4903 /* Fall through. */
4904 }
95385cbb 4905
92898235 4906 *expandedp = false;
0ac081f6
AH
4907 return NULL_RTX;
4908}
4909
a3170dc6
AH
4910/* Binops that need to be initialized manually, but can be expanded
4911 automagically by rs6000_expand_binop_builtin. */
4912static struct builtin_description bdesc_2arg_spe[] =
4913{
4914 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
4915 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
4916 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
4917 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
4918 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
4919 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
4920 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
4921 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
4922 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
4923 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
4924 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
4925 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
4926 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
4927 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
4928 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
4929 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
4930 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
4931 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
4932 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
4933 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
4934 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
4935 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
4936};
4937
4938/* Expand the builtin in EXP and store the result in TARGET. Store
4939 true in *EXPANDEDP if we found a builtin to expand.
4940
4941 This expands the SPE builtins that are not simple unary and binary
4942 operations. */
4943static rtx
4944spe_expand_builtin (exp, target, expandedp)
4945 tree exp;
4946 rtx target;
4947 bool *expandedp;
4948{
4949 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4950 tree arglist = TREE_OPERAND (exp, 1);
4951 tree arg1, arg0;
4952 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4953 enum insn_code icode;
4954 enum machine_mode tmode, mode0;
4955 rtx pat, op0;
4956 struct builtin_description *d;
4957 size_t i;
4958
4959 *expandedp = true;
4960
4961 /* Syntax check for a 5-bit unsigned immediate. */
4962 switch (fcode)
4963 {
4964 case SPE_BUILTIN_EVSTDD:
4965 case SPE_BUILTIN_EVSTDH:
4966 case SPE_BUILTIN_EVSTDW:
4967 case SPE_BUILTIN_EVSTWHE:
4968 case SPE_BUILTIN_EVSTWHO:
4969 case SPE_BUILTIN_EVSTWWE:
4970 case SPE_BUILTIN_EVSTWWO:
4971 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4972 if (TREE_CODE (arg1) != INTEGER_CST
4973 || TREE_INT_CST_LOW (arg1) & ~0x1f)
4974 {
4975 error ("argument 2 must be a 5-bit unsigned literal");
4976 return const0_rtx;
4977 }
4978 break;
4979 default:
4980 break;
4981 }
4982
4983 d = (struct builtin_description *) bdesc_2arg_spe;
4984 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
4985 if (d->code == fcode)
4986 return rs6000_expand_binop_builtin (d->icode, arglist, target);
4987
4988 d = (struct builtin_description *) bdesc_spe_predicates;
4989 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
4990 if (d->code == fcode)
4991 return spe_expand_predicate_builtin (d->icode, arglist, target);
4992
4993 d = (struct builtin_description *) bdesc_spe_evsel;
4994 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
4995 if (d->code == fcode)
4996 return spe_expand_evsel_builtin (d->icode, arglist, target);
4997
4998 switch (fcode)
4999 {
5000 case SPE_BUILTIN_EVSTDDX:
5001 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
5002 case SPE_BUILTIN_EVSTDHX:
5003 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
5004 case SPE_BUILTIN_EVSTDWX:
5005 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
5006 case SPE_BUILTIN_EVSTWHEX:
5007 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
5008 case SPE_BUILTIN_EVSTWHOX:
5009 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
5010 case SPE_BUILTIN_EVSTWWEX:
5011 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
5012 case SPE_BUILTIN_EVSTWWOX:
5013 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
5014 case SPE_BUILTIN_EVSTDD:
5015 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
5016 case SPE_BUILTIN_EVSTDH:
5017 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
5018 case SPE_BUILTIN_EVSTDW:
5019 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
5020 case SPE_BUILTIN_EVSTWHE:
5021 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
5022 case SPE_BUILTIN_EVSTWHO:
5023 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
5024 case SPE_BUILTIN_EVSTWWE:
5025 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
5026 case SPE_BUILTIN_EVSTWWO:
5027 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
5028 case SPE_BUILTIN_MFSPEFSCR:
5029 icode = CODE_FOR_spe_mfspefscr;
5030 tmode = insn_data[icode].operand[0].mode;
5031
5032 if (target == 0
5033 || GET_MODE (target) != tmode
5034 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5035 target = gen_reg_rtx (tmode);
5036
5037 pat = GEN_FCN (icode) (target);
5038 if (! pat)
5039 return 0;
5040 emit_insn (pat);
5041 return target;
5042 case SPE_BUILTIN_MTSPEFSCR:
5043 icode = CODE_FOR_spe_mtspefscr;
5044 arg0 = TREE_VALUE (arglist);
5045 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5046 mode0 = insn_data[icode].operand[0].mode;
5047
5048 if (arg0 == error_mark_node)
5049 return const0_rtx;
5050
5051 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5052 op0 = copy_to_mode_reg (mode0, op0);
5053
5054 pat = GEN_FCN (icode) (op0);
5055 if (pat)
5056 emit_insn (pat);
5057 return NULL_RTX;
5058 default:
5059 break;
5060 }
5061
5062 *expandedp = false;
5063 return NULL_RTX;
5064}
5065
5066static rtx
5067spe_expand_predicate_builtin (icode, arglist, target)
5068 enum insn_code icode;
5069 tree arglist;
5070 rtx target;
5071{
5072 rtx pat, scratch, tmp;
5073 tree form = TREE_VALUE (arglist);
5074 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5075 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5076 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5077 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5078 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5079 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5080 int form_int;
5081 enum rtx_code code;
5082
5083 if (TREE_CODE (form) != INTEGER_CST)
5084 {
5085 error ("argument 1 of __builtin_spe_predicate must be a constant");
5086 return const0_rtx;
5087 }
5088 else
5089 form_int = TREE_INT_CST_LOW (form);
5090
5091 if (mode0 != mode1)
5092 abort ();
5093
5094 if (arg0 == error_mark_node || arg1 == error_mark_node)
5095 return const0_rtx;
5096
5097 if (target == 0
5098 || GET_MODE (target) != SImode
5099 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
5100 target = gen_reg_rtx (SImode);
5101
5102 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5103 op0 = copy_to_mode_reg (mode0, op0);
5104 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5105 op1 = copy_to_mode_reg (mode1, op1);
5106
5107 scratch = gen_reg_rtx (CCmode);
5108
5109 pat = GEN_FCN (icode) (scratch, op0, op1);
5110 if (! pat)
5111 return const0_rtx;
5112 emit_insn (pat);
5113
5114 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
5115 _lower_. We use one compare, but look in different bits of the
5116 CR for each variant.
5117
5118 There are 2 elements in each SPE simd type (upper/lower). The CR
5119 bits are set as follows:
5120
5121 BIT0 | BIT 1 | BIT 2 | BIT 3
5122 U | L | (U | L) | (U & L)
5123
5124 So, for an "all" relationship, BIT 3 would be set.
5125 For an "any" relationship, BIT 2 would be set. Etc.
5126
5127 Following traditional nomenclature, these bits map to:
5128
5129 BIT0 | BIT 1 | BIT 2 | BIT 3
5130 LT | GT | EQ | OV
5131
5132 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
5133 */
5134
5135 switch (form_int)
5136 {
5137 /* All variant. OV bit. */
5138 case 0:
5139 /* We need to get to the OV bit, which is the ORDERED bit. We
5140 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
5141 that's ugly and will trigger a validate_condition_mode abort.
5142 So let's just use another pattern. */
5143 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
5144 return target;
5145 /* Any variant. EQ bit. */
5146 case 1:
5147 code = EQ;
5148 break;
5149 /* Upper variant. LT bit. */
5150 case 2:
5151 code = LT;
5152 break;
5153 /* Lower variant. GT bit. */
5154 case 3:
5155 code = GT;
5156 break;
5157 default:
5158 error ("argument 1 of __builtin_spe_predicate is out of range");
5159 return const0_rtx;
5160 }
5161
5162 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
5163 emit_move_insn (target, tmp);
5164
5165 return target;
5166}
5167
5168/* The evsel builtins look like this:
5169
5170 e = __builtin_spe_evsel_OP (a, b, c, d);
5171
5172 and work like this:
5173
5174 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
5175 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
5176*/
5177
5178static rtx
5179spe_expand_evsel_builtin (icode, arglist, target)
5180 enum insn_code icode;
5181 tree arglist;
5182 rtx target;
5183{
5184 rtx pat, scratch;
5185 tree arg0 = TREE_VALUE (arglist);
5186 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5187 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5188 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
5189 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5190 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5191 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5192 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
5193 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5194 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5195
5196 if (mode0 != mode1)
5197 abort ();
5198
5199 if (arg0 == error_mark_node || arg1 == error_mark_node
5200 || arg2 == error_mark_node || arg3 == error_mark_node)
5201 return const0_rtx;
5202
5203 if (target == 0
5204 || GET_MODE (target) != mode0
5205 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
5206 target = gen_reg_rtx (mode0);
5207
5208 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5209 op0 = copy_to_mode_reg (mode0, op0);
5210 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5211 op1 = copy_to_mode_reg (mode0, op1);
5212 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
5213 op2 = copy_to_mode_reg (mode0, op2);
5214 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
5215 op3 = copy_to_mode_reg (mode0, op3);
5216
5217 /* Generate the compare. */
5218 scratch = gen_reg_rtx (CCmode);
5219 pat = GEN_FCN (icode) (scratch, op0, op1);
5220 if (! pat)
5221 return const0_rtx;
5222 emit_insn (pat);
5223
5224 if (mode0 == V2SImode)
5225 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
5226 else
5227 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
5228
5229 return target;
5230}
5231
0ac081f6
AH
5232/* Expand an expression EXP that calls a built-in function,
5233 with result going to TARGET if that's convenient
5234 (and in mode MODE if that's convenient).
5235 SUBTARGET may be used as the target for computing one of EXP's operands.
5236 IGNORE is nonzero if the value is to be ignored. */
5237
5238static rtx
5239rs6000_expand_builtin (exp, target, subtarget, mode, ignore)
5240 tree exp;
5241 rtx target;
00b960c7
AH
5242 rtx subtarget ATTRIBUTE_UNUSED;
5243 enum machine_mode mode ATTRIBUTE_UNUSED;
5244 int ignore ATTRIBUTE_UNUSED;
0ac081f6 5245{
92898235
AH
5246 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5247 tree arglist = TREE_OPERAND (exp, 1);
5248 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5249 struct builtin_description *d;
5250 size_t i;
5251 rtx ret;
5252 bool success;
5253
0ac081f6 5254 if (TARGET_ALTIVEC)
92898235
AH
5255 {
5256 ret = altivec_expand_builtin (exp, target, &success);
5257
a3170dc6
AH
5258 if (success)
5259 return ret;
5260 }
5261 if (TARGET_SPE)
5262 {
5263 ret = spe_expand_builtin (exp, target, &success);
5264
92898235
AH
5265 if (success)
5266 return ret;
5267 }
5268
0559cc77
DE
5269 if (TARGET_ALTIVEC || TARGET_SPE)
5270 {
5271 /* Handle simple unary operations. */
5272 d = (struct builtin_description *) bdesc_1arg;
5273 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
5274 if (d->code == fcode)
5275 return rs6000_expand_unop_builtin (d->icode, arglist, target);
5276
5277 /* Handle simple binary operations. */
5278 d = (struct builtin_description *) bdesc_2arg;
5279 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
5280 if (d->code == fcode)
5281 return rs6000_expand_binop_builtin (d->icode, arglist, target);
5282
5283 /* Handle simple ternary operations. */
5284 d = (struct builtin_description *) bdesc_3arg;
5285 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
5286 if (d->code == fcode)
5287 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
5288 }
0ac081f6
AH
5289
5290 abort ();
92898235 5291 return NULL_RTX;
0ac081f6
AH
5292}
5293
5294static void
6fa3f289 5295rs6000_init_builtins ()
0ac081f6 5296{
a3170dc6
AH
5297 if (TARGET_SPE)
5298 spe_init_builtins ();
0ac081f6
AH
5299 if (TARGET_ALTIVEC)
5300 altivec_init_builtins ();
0559cc77
DE
5301 if (TARGET_ALTIVEC || TARGET_SPE)
5302 rs6000_common_init_builtins ();
0ac081f6
AH
5303}
5304
a3170dc6
AH
5305/* Search through a set of builtins and enable the mask bits.
5306 DESC is an array of builtins.
b6d08ca1 5307 SIZE is the total number of builtins.
a3170dc6
AH
5308 START is the builtin enum at which to start.
5309 END is the builtin enum at which to end. */
0ac081f6 5310static void
a3170dc6
AH
5311enable_mask_for_builtins (desc, size, start, end)
5312 struct builtin_description *desc;
5313 int size;
5314 enum rs6000_builtins start, end;
5315{
5316 int i;
5317
5318 for (i = 0; i < size; ++i)
5319 if (desc[i].code == start)
5320 break;
5321
5322 if (i == size)
5323 return;
5324
5325 for (; i < size; ++i)
5326 {
5327 /* Flip all the bits on. */
5328 desc[i].mask = target_flags;
5329 if (desc[i].code == end)
5330 break;
5331 }
5332}
5333
5334static void
b24c9d35 5335spe_init_builtins ()
0ac081f6 5336{
a3170dc6
AH
5337 tree endlink = void_list_node;
5338 tree puint_type_node = build_pointer_type (unsigned_type_node);
5339 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
5340 tree pv2si_type_node = build_pointer_type (V2SI_type_node);
ae4b4a02 5341 struct builtin_description *d;
0ac081f6
AH
5342 size_t i;
5343
a3170dc6
AH
5344 tree v2si_ftype_4_v2si
5345 = build_function_type
5346 (V2SI_type_node,
5347 tree_cons (NULL_TREE, V2SI_type_node,
5348 tree_cons (NULL_TREE, V2SI_type_node,
5349 tree_cons (NULL_TREE, V2SI_type_node,
5350 tree_cons (NULL_TREE, V2SI_type_node,
5351 endlink)))));
5352
5353 tree v2sf_ftype_4_v2sf
5354 = build_function_type
5355 (V2SF_type_node,
5356 tree_cons (NULL_TREE, V2SF_type_node,
5357 tree_cons (NULL_TREE, V2SF_type_node,
5358 tree_cons (NULL_TREE, V2SF_type_node,
5359 tree_cons (NULL_TREE, V2SF_type_node,
5360 endlink)))));
5361
5362 tree int_ftype_int_v2si_v2si
5363 = build_function_type
5364 (integer_type_node,
5365 tree_cons (NULL_TREE, integer_type_node,
5366 tree_cons (NULL_TREE, V2SI_type_node,
5367 tree_cons (NULL_TREE, V2SI_type_node,
5368 endlink))));
5369
5370 tree int_ftype_int_v2sf_v2sf
5371 = build_function_type
5372 (integer_type_node,
5373 tree_cons (NULL_TREE, integer_type_node,
5374 tree_cons (NULL_TREE, V2SF_type_node,
5375 tree_cons (NULL_TREE, V2SF_type_node,
5376 endlink))));
5377
5378 tree void_ftype_v2si_puint_int
5379 = build_function_type (void_type_node,
5380 tree_cons (NULL_TREE, V2SI_type_node,
5381 tree_cons (NULL_TREE, puint_type_node,
5382 tree_cons (NULL_TREE,
5383 integer_type_node,
5384 endlink))));
5385
5386 tree void_ftype_v2si_puint_char
5387 = build_function_type (void_type_node,
5388 tree_cons (NULL_TREE, V2SI_type_node,
5389 tree_cons (NULL_TREE, puint_type_node,
5390 tree_cons (NULL_TREE,
5391 char_type_node,
5392 endlink))));
5393
5394 tree void_ftype_v2si_pv2si_int
5395 = build_function_type (void_type_node,
5396 tree_cons (NULL_TREE, V2SI_type_node,
5397 tree_cons (NULL_TREE, pv2si_type_node,
5398 tree_cons (NULL_TREE,
5399 integer_type_node,
5400 endlink))));
5401
5402 tree void_ftype_v2si_pv2si_char
5403 = build_function_type (void_type_node,
5404 tree_cons (NULL_TREE, V2SI_type_node,
5405 tree_cons (NULL_TREE, pv2si_type_node,
5406 tree_cons (NULL_TREE,
5407 char_type_node,
5408 endlink))));
5409
5410 tree void_ftype_int
5411 = build_function_type (void_type_node,
5412 tree_cons (NULL_TREE, integer_type_node, endlink));
5413
5414 tree int_ftype_void
5415 = build_function_type (integer_type_node,
5416 tree_cons (NULL_TREE, void_type_node, endlink));
5417
5418 tree v2si_ftype_pv2si_int
5419 = build_function_type (V2SI_type_node,
5420 tree_cons (NULL_TREE, pv2si_type_node,
5421 tree_cons (NULL_TREE, integer_type_node,
5422 endlink)));
5423
5424 tree v2si_ftype_puint_int
5425 = build_function_type (V2SI_type_node,
5426 tree_cons (NULL_TREE, puint_type_node,
5427 tree_cons (NULL_TREE, integer_type_node,
5428 endlink)));
5429
5430 tree v2si_ftype_pushort_int
5431 = build_function_type (V2SI_type_node,
5432 tree_cons (NULL_TREE, pushort_type_node,
5433 tree_cons (NULL_TREE, integer_type_node,
5434 endlink)));
5435
5436 /* The initialization of the simple binary and unary builtins is
5437 done in rs6000_common_init_builtins, but we have to enable the
5438 mask bits here manually because we have run out of `target_flags'
5439 bits. We really need to redesign this mask business. */
5440
5441 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
5442 ARRAY_SIZE (bdesc_2arg),
5443 SPE_BUILTIN_EVADDW,
5444 SPE_BUILTIN_EVXOR);
5445 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
5446 ARRAY_SIZE (bdesc_1arg),
5447 SPE_BUILTIN_EVABS,
5448 SPE_BUILTIN_EVSUBFUSIAAW);
5449 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
5450 ARRAY_SIZE (bdesc_spe_predicates),
5451 SPE_BUILTIN_EVCMPEQ,
5452 SPE_BUILTIN_EVFSTSTLT);
5453 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
5454 ARRAY_SIZE (bdesc_spe_evsel),
5455 SPE_BUILTIN_EVSEL_CMPGTS,
5456 SPE_BUILTIN_EVSEL_FSTSTEQ);
5457
5458 /* Initialize irregular SPE builtins. */
5459
5460 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
5461 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
5462 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
5463 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
5464 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
5465 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
5466 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
5467 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
5468 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
5469 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
5470 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
5471 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
5472 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
5473 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
5474 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
5475 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
5476
5477 /* Loads. */
5478 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
5479 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
5480 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
5481 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
5482 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
5483 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
5484 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
5485 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
5486 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
5487 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
5488 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
5489 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
5490 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
5491 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
5492 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
5493 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
5494 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
5495 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
5496 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
5497 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
5498 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
5499 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
5500
5501 /* Predicates. */
5502 d = (struct builtin_description *) bdesc_spe_predicates;
5503 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
5504 {
5505 tree type;
5506
5507 switch (insn_data[d->icode].operand[1].mode)
5508 {
5509 case V2SImode:
5510 type = int_ftype_int_v2si_v2si;
5511 break;
5512 case V2SFmode:
5513 type = int_ftype_int_v2sf_v2sf;
5514 break;
5515 default:
5516 abort ();
5517 }
5518
5519 def_builtin (d->mask, d->name, type, d->code);
5520 }
5521
5522 /* Evsel predicates. */
5523 d = (struct builtin_description *) bdesc_spe_evsel;
5524 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
5525 {
5526 tree type;
5527
5528 switch (insn_data[d->icode].operand[1].mode)
5529 {
5530 case V2SImode:
5531 type = v2si_ftype_4_v2si;
5532 break;
5533 case V2SFmode:
5534 type = v2sf_ftype_4_v2sf;
5535 break;
5536 default:
5537 abort ();
5538 }
5539
5540 def_builtin (d->mask, d->name, type, d->code);
5541 }
5542}
5543
5544static void
b24c9d35 5545altivec_init_builtins ()
a3170dc6
AH
5546{
5547 struct builtin_description *d;
5548 struct builtin_description_predicates *dp;
5549 size_t i;
5550 tree pfloat_type_node = build_pointer_type (float_type_node);
5551 tree pint_type_node = build_pointer_type (integer_type_node);
5552 tree pshort_type_node = build_pointer_type (short_integer_type_node);
5553 tree pchar_type_node = build_pointer_type (char_type_node);
5554
5555 tree pvoid_type_node = build_pointer_type (void_type_node);
5556
0dbc3651
ZW
5557 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
5558 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
5559 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
5560 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
5561
5562 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
5563
a3170dc6
AH
5564 tree int_ftype_int_v4si_v4si
5565 = build_function_type_list (integer_type_node,
5566 integer_type_node, V4SI_type_node,
5567 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
5568 tree v4sf_ftype_pcfloat
5569 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 5570 tree void_ftype_pfloat_v4sf
b4de2f7d 5571 = build_function_type_list (void_type_node,
a3170dc6 5572 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
5573 tree v4si_ftype_pcint
5574 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
5575 tree void_ftype_pint_v4si
b4de2f7d
AH
5576 = build_function_type_list (void_type_node,
5577 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
5578 tree v8hi_ftype_pcshort
5579 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 5580 tree void_ftype_pshort_v8hi
b4de2f7d
AH
5581 = build_function_type_list (void_type_node,
5582 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
5583 tree v16qi_ftype_pcchar
5584 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 5585 tree void_ftype_pchar_v16qi
b4de2f7d
AH
5586 = build_function_type_list (void_type_node,
5587 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 5588 tree void_ftype_v4si
b4de2f7d 5589 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
5590 tree v8hi_ftype_void
5591 = build_function_type (V8HI_type_node, void_list_node);
5592 tree void_ftype_void
5593 = build_function_type (void_type_node, void_list_node);
5594 tree void_ftype_qi
5595 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651
ZW
5596
5597 tree v16qi_ftype_int_pcvoid
a3170dc6 5598 = build_function_type_list (V16QI_type_node,
0dbc3651
ZW
5599 integer_type_node, pcvoid_type_node, NULL_TREE);
5600 tree v8hi_ftype_int_pcvoid
a3170dc6 5601 = build_function_type_list (V8HI_type_node,
0dbc3651
ZW
5602 integer_type_node, pcvoid_type_node, NULL_TREE);
5603 tree v4si_ftype_int_pcvoid
a3170dc6 5604 = build_function_type_list (V4SI_type_node,
0dbc3651
ZW
5605 integer_type_node, pcvoid_type_node, NULL_TREE);
5606
14b32f4e 5607 tree void_ftype_v4si_int_pvoid
b4de2f7d
AH
5608 = build_function_type_list (void_type_node,
5609 V4SI_type_node, integer_type_node,
5610 pvoid_type_node, NULL_TREE);
6525c0e7 5611 tree void_ftype_v16qi_int_pvoid
b4de2f7d
AH
5612 = build_function_type_list (void_type_node,
5613 V16QI_type_node, integer_type_node,
5614 pvoid_type_node, NULL_TREE);
6525c0e7 5615 tree void_ftype_v8hi_int_pvoid
b4de2f7d
AH
5616 = build_function_type_list (void_type_node,
5617 V8HI_type_node, integer_type_node,
5618 pvoid_type_node, NULL_TREE);
a3170dc6
AH
5619 tree int_ftype_int_v8hi_v8hi
5620 = build_function_type_list (integer_type_node,
5621 integer_type_node, V8HI_type_node,
5622 V8HI_type_node, NULL_TREE);
5623 tree int_ftype_int_v16qi_v16qi
5624 = build_function_type_list (integer_type_node,
5625 integer_type_node, V16QI_type_node,
5626 V16QI_type_node, NULL_TREE);
5627 tree int_ftype_int_v4sf_v4sf
5628 = build_function_type_list (integer_type_node,
5629 integer_type_node, V4SF_type_node,
5630 V4SF_type_node, NULL_TREE);
5631 tree v4si_ftype_v4si
5632 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
5633 tree v8hi_ftype_v8hi
5634 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
5635 tree v16qi_ftype_v16qi
5636 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
5637 tree v4sf_ftype_v4sf
5638 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
0dbc3651 5639 tree void_ftype_pcvoid_int_char
a3170dc6 5640 = build_function_type_list (void_type_node,
0dbc3651 5641 pcvoid_type_node, integer_type_node,
a3170dc6 5642 char_type_node, NULL_TREE);
0dbc3651
ZW
5643
5644 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
5645 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
5646 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
5647 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
5648 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
5649 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
5650 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
5651 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
5652 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
5653 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
5654 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
5655 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
5656 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
5657 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
5658 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
5659 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
5660 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
5661 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
5662 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
5663 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
0dbc3651
ZW
5664 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSL);
5665 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSR);
5666 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEBX);
5667 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEHX);
5668 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEWX);
5669 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVXL);
5670 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVX);
a3170dc6
AH
5671 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVX);
5672 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVEWX);
5673 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVXL);
5674 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_int_pvoid, ALTIVEC_BUILTIN_STVEBX);
5675 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_int_pvoid, ALTIVEC_BUILTIN_STVEHX);
5676
5677 /* Add the DST variants. */
5678 d = (struct builtin_description *) bdesc_dst;
5679 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
0dbc3651 5680 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code);
a3170dc6
AH
5681
5682 /* Initialize the predicates. */
5683 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
5684 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
5685 {
5686 enum machine_mode mode1;
5687 tree type;
5688
5689 mode1 = insn_data[dp->icode].operand[1].mode;
5690
5691 switch (mode1)
5692 {
5693 case V4SImode:
5694 type = int_ftype_int_v4si_v4si;
5695 break;
5696 case V8HImode:
5697 type = int_ftype_int_v8hi_v8hi;
5698 break;
5699 case V16QImode:
5700 type = int_ftype_int_v16qi_v16qi;
5701 break;
5702 case V4SFmode:
5703 type = int_ftype_int_v4sf_v4sf;
5704 break;
5705 default:
5706 abort ();
5707 }
5708
5709 def_builtin (dp->mask, dp->name, type, dp->code);
5710 }
5711
5712 /* Initialize the abs* operators. */
5713 d = (struct builtin_description *) bdesc_abs;
5714 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
5715 {
5716 enum machine_mode mode0;
5717 tree type;
5718
5719 mode0 = insn_data[d->icode].operand[0].mode;
5720
5721 switch (mode0)
5722 {
5723 case V4SImode:
5724 type = v4si_ftype_v4si;
5725 break;
5726 case V8HImode:
5727 type = v8hi_ftype_v8hi;
5728 break;
5729 case V16QImode:
5730 type = v16qi_ftype_v16qi;
5731 break;
5732 case V4SFmode:
5733 type = v4sf_ftype_v4sf;
5734 break;
5735 default:
5736 abort ();
5737 }
5738
5739 def_builtin (d->mask, d->name, type, d->code);
5740 }
5741}
5742
5743static void
b24c9d35 5744rs6000_common_init_builtins ()
a3170dc6
AH
5745{
5746 struct builtin_description *d;
5747 size_t i;
5748
5749 tree v4sf_ftype_v4sf_v4sf_v16qi
5750 = build_function_type_list (V4SF_type_node,
5751 V4SF_type_node, V4SF_type_node,
5752 V16QI_type_node, NULL_TREE);
5753 tree v4si_ftype_v4si_v4si_v16qi
5754 = build_function_type_list (V4SI_type_node,
5755 V4SI_type_node, V4SI_type_node,
5756 V16QI_type_node, NULL_TREE);
5757 tree v8hi_ftype_v8hi_v8hi_v16qi
5758 = build_function_type_list (V8HI_type_node,
5759 V8HI_type_node, V8HI_type_node,
5760 V16QI_type_node, NULL_TREE);
5761 tree v16qi_ftype_v16qi_v16qi_v16qi
5762 = build_function_type_list (V16QI_type_node,
5763 V16QI_type_node, V16QI_type_node,
5764 V16QI_type_node, NULL_TREE);
5765 tree v4si_ftype_char
5766 = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE);
5767 tree v8hi_ftype_char
5768 = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE);
5769 tree v16qi_ftype_char
5770 = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE);
5771 tree v8hi_ftype_v16qi
5772 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
5773 tree v4sf_ftype_v4sf
5774 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
5775
5776 tree v2si_ftype_v2si_v2si
5777 = build_function_type_list (V2SI_type_node,
5778 V2SI_type_node, V2SI_type_node, NULL_TREE);
5779
5780 tree v2sf_ftype_v2sf_v2sf
5781 = build_function_type_list (V2SF_type_node,
5782 V2SF_type_node, V2SF_type_node, NULL_TREE);
5783
5784 tree v2si_ftype_int_int
5785 = build_function_type_list (V2SI_type_node,
5786 integer_type_node, integer_type_node,
5787 NULL_TREE);
5788
5789 tree v2si_ftype_v2si
5790 = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
5791
5792 tree v2sf_ftype_v2sf
5793 = build_function_type_list (V2SF_type_node,
5794 V2SF_type_node, NULL_TREE);
5795
5796 tree v2sf_ftype_v2si
5797 = build_function_type_list (V2SF_type_node,
5798 V2SI_type_node, NULL_TREE);
5799
5800 tree v2si_ftype_v2sf
5801 = build_function_type_list (V2SI_type_node,
5802 V2SF_type_node, NULL_TREE);
5803
5804 tree v2si_ftype_v2si_char
5805 = build_function_type_list (V2SI_type_node,
5806 V2SI_type_node, char_type_node, NULL_TREE);
5807
5808 tree v2si_ftype_int_char
5809 = build_function_type_list (V2SI_type_node,
5810 integer_type_node, char_type_node, NULL_TREE);
5811
5812 tree v2si_ftype_char
5813 = build_function_type_list (V2SI_type_node, char_type_node, NULL_TREE);
5814
5815 tree int_ftype_int_int
5816 = build_function_type_list (integer_type_node,
5817 integer_type_node, integer_type_node,
5818 NULL_TREE);
95385cbb 5819
0ac081f6 5820 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
5821 = build_function_type_list (V4SI_type_node,
5822 V4SI_type_node, V4SI_type_node, NULL_TREE);
617e0e1d 5823 tree v4sf_ftype_v4si_char
b4de2f7d
AH
5824 = build_function_type_list (V4SF_type_node,
5825 V4SI_type_node, char_type_node, NULL_TREE);
617e0e1d 5826 tree v4si_ftype_v4sf_char
b4de2f7d
AH
5827 = build_function_type_list (V4SI_type_node,
5828 V4SF_type_node, char_type_node, NULL_TREE);
2212663f 5829 tree v4si_ftype_v4si_char
b4de2f7d
AH
5830 = build_function_type_list (V4SI_type_node,
5831 V4SI_type_node, char_type_node, NULL_TREE);
2212663f 5832 tree v8hi_ftype_v8hi_char
b4de2f7d
AH
5833 = build_function_type_list (V8HI_type_node,
5834 V8HI_type_node, char_type_node, NULL_TREE);
2212663f 5835 tree v16qi_ftype_v16qi_char
b4de2f7d
AH
5836 = build_function_type_list (V16QI_type_node,
5837 V16QI_type_node, char_type_node, NULL_TREE);
24408032 5838 tree v16qi_ftype_v16qi_v16qi_char
b4de2f7d
AH
5839 = build_function_type_list (V16QI_type_node,
5840 V16QI_type_node, V16QI_type_node,
5841 char_type_node, NULL_TREE);
24408032 5842 tree v8hi_ftype_v8hi_v8hi_char
b4de2f7d
AH
5843 = build_function_type_list (V8HI_type_node,
5844 V8HI_type_node, V8HI_type_node,
5845 char_type_node, NULL_TREE);
24408032 5846 tree v4si_ftype_v4si_v4si_char
b4de2f7d
AH
5847 = build_function_type_list (V4SI_type_node,
5848 V4SI_type_node, V4SI_type_node,
5849 char_type_node, NULL_TREE);
24408032 5850 tree v4sf_ftype_v4sf_v4sf_char
b4de2f7d
AH
5851 = build_function_type_list (V4SF_type_node,
5852 V4SF_type_node, V4SF_type_node,
5853 char_type_node, NULL_TREE);
0ac081f6 5854 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
5855 = build_function_type_list (V4SF_type_node,
5856 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 5857 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
5858 = build_function_type_list (V4SF_type_node,
5859 V4SF_type_node, V4SF_type_node,
5860 V4SI_type_node, NULL_TREE);
2212663f 5861 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
5862 = build_function_type_list (V4SF_type_node,
5863 V4SF_type_node, V4SF_type_node,
5864 V4SF_type_node, NULL_TREE);
617e0e1d 5865 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
5866 = build_function_type_list (V4SI_type_node,
5867 V4SI_type_node, V4SI_type_node,
5868 V4SI_type_node, NULL_TREE);
0ac081f6 5869 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
5870 = build_function_type_list (V8HI_type_node,
5871 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 5872 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
5873 = build_function_type_list (V8HI_type_node,
5874 V8HI_type_node, V8HI_type_node,
5875 V8HI_type_node, NULL_TREE);
2212663f 5876 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
5877 = build_function_type_list (V4SI_type_node,
5878 V8HI_type_node, V8HI_type_node,
5879 V4SI_type_node, NULL_TREE);
2212663f 5880 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
5881 = build_function_type_list (V4SI_type_node,
5882 V16QI_type_node, V16QI_type_node,
5883 V4SI_type_node, NULL_TREE);
0ac081f6 5884 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
5885 = build_function_type_list (V16QI_type_node,
5886 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5887 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
5888 = build_function_type_list (V4SI_type_node,
5889 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 5890 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
5891 = build_function_type_list (V8HI_type_node,
5892 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5893 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
5894 = build_function_type_list (V4SI_type_node,
5895 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5896 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
5897 = build_function_type_list (V8HI_type_node,
5898 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 5899 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
5900 = build_function_type_list (V16QI_type_node,
5901 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5902 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
5903 = build_function_type_list (V4SI_type_node,
5904 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 5905 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
5906 = build_function_type_list (V4SI_type_node,
5907 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5908 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
5909 = build_function_type_list (V4SI_type_node,
5910 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
5911 tree v4si_ftype_v8hi
5912 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
5913 tree int_ftype_v4si_v4si
5914 = build_function_type_list (integer_type_node,
5915 V4SI_type_node, V4SI_type_node, NULL_TREE);
5916 tree int_ftype_v4sf_v4sf
5917 = build_function_type_list (integer_type_node,
5918 V4SF_type_node, V4SF_type_node, NULL_TREE);
5919 tree int_ftype_v16qi_v16qi
5920 = build_function_type_list (integer_type_node,
5921 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5922 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
5923 = build_function_type_list (integer_type_node,
5924 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5925
6f317ef3 5926 /* Add the simple ternary operators. */
2212663f 5927 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 5928 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
5929 {
5930
5931 enum machine_mode mode0, mode1, mode2, mode3;
5932 tree type;
5933
0559cc77 5934 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
5935 continue;
5936
5937 mode0 = insn_data[d->icode].operand[0].mode;
5938 mode1 = insn_data[d->icode].operand[1].mode;
5939 mode2 = insn_data[d->icode].operand[2].mode;
5940 mode3 = insn_data[d->icode].operand[3].mode;
5941
5942 /* When all four are of the same mode. */
5943 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
5944 {
5945 switch (mode0)
5946 {
617e0e1d
DB
5947 case V4SImode:
5948 type = v4si_ftype_v4si_v4si_v4si;
5949 break;
2212663f
DB
5950 case V4SFmode:
5951 type = v4sf_ftype_v4sf_v4sf_v4sf;
5952 break;
5953 case V8HImode:
5954 type = v8hi_ftype_v8hi_v8hi_v8hi;
5955 break;
5956 case V16QImode:
5957 type = v16qi_ftype_v16qi_v16qi_v16qi;
5958 break;
5959 default:
5960 abort();
5961 }
5962 }
5963 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
5964 {
5965 switch (mode0)
5966 {
5967 case V4SImode:
5968 type = v4si_ftype_v4si_v4si_v16qi;
5969 break;
5970 case V4SFmode:
5971 type = v4sf_ftype_v4sf_v4sf_v16qi;
5972 break;
5973 case V8HImode:
5974 type = v8hi_ftype_v8hi_v8hi_v16qi;
5975 break;
5976 case V16QImode:
5977 type = v16qi_ftype_v16qi_v16qi_v16qi;
5978 break;
5979 default:
5980 abort();
5981 }
5982 }
5983 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
5984 && mode3 == V4SImode)
24408032 5985 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
5986 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
5987 && mode3 == V4SImode)
24408032 5988 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
5989 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
5990 && mode3 == V4SImode)
24408032
AH
5991 type = v4sf_ftype_v4sf_v4sf_v4si;
5992
5993 /* vchar, vchar, vchar, 4 bit literal. */
5994 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
5995 && mode3 == QImode)
5996 type = v16qi_ftype_v16qi_v16qi_char;
5997
5998 /* vshort, vshort, vshort, 4 bit literal. */
5999 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
6000 && mode3 == QImode)
6001 type = v8hi_ftype_v8hi_v8hi_char;
6002
6003 /* vint, vint, vint, 4 bit literal. */
6004 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
6005 && mode3 == QImode)
6006 type = v4si_ftype_v4si_v4si_char;
6007
6008 /* vfloat, vfloat, vfloat, 4 bit literal. */
6009 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
6010 && mode3 == QImode)
6011 type = v4sf_ftype_v4sf_v4sf_char;
6012
2212663f
DB
6013 else
6014 abort ();
6015
6016 def_builtin (d->mask, d->name, type, d->code);
6017 }
6018
0ac081f6 6019 /* Add the simple binary operators. */
00b960c7 6020 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 6021 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
6022 {
6023 enum machine_mode mode0, mode1, mode2;
6024 tree type;
6025
0559cc77 6026 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
6027 continue;
6028
6029 mode0 = insn_data[d->icode].operand[0].mode;
6030 mode1 = insn_data[d->icode].operand[1].mode;
6031 mode2 = insn_data[d->icode].operand[2].mode;
6032
6033 /* When all three operands are of the same mode. */
6034 if (mode0 == mode1 && mode1 == mode2)
6035 {
6036 switch (mode0)
6037 {
6038 case V4SFmode:
6039 type = v4sf_ftype_v4sf_v4sf;
6040 break;
6041 case V4SImode:
6042 type = v4si_ftype_v4si_v4si;
6043 break;
6044 case V16QImode:
6045 type = v16qi_ftype_v16qi_v16qi;
6046 break;
6047 case V8HImode:
6048 type = v8hi_ftype_v8hi_v8hi;
6049 break;
a3170dc6
AH
6050 case V2SImode:
6051 type = v2si_ftype_v2si_v2si;
6052 break;
6053 case V2SFmode:
6054 type = v2sf_ftype_v2sf_v2sf;
6055 break;
6056 case SImode:
6057 type = int_ftype_int_int;
6058 break;
0ac081f6
AH
6059 default:
6060 abort ();
6061 }
6062 }
6063
6064 /* A few other combos we really don't want to do manually. */
6065
6066 /* vint, vfloat, vfloat. */
6067 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
6068 type = v4si_ftype_v4sf_v4sf;
6069
6070 /* vshort, vchar, vchar. */
6071 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
6072 type = v8hi_ftype_v16qi_v16qi;
6073
6074 /* vint, vshort, vshort. */
6075 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
6076 type = v4si_ftype_v8hi_v8hi;
6077
6078 /* vshort, vint, vint. */
6079 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
6080 type = v8hi_ftype_v4si_v4si;
6081
6082 /* vchar, vshort, vshort. */
6083 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
6084 type = v16qi_ftype_v8hi_v8hi;
6085
6086 /* vint, vchar, vint. */
6087 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
6088 type = v4si_ftype_v16qi_v4si;
6089
fa066a23
AH
6090 /* vint, vchar, vchar. */
6091 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
6092 type = v4si_ftype_v16qi_v16qi;
6093
0ac081f6
AH
6094 /* vint, vshort, vint. */
6095 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
6096 type = v4si_ftype_v8hi_v4si;
2212663f
DB
6097
6098 /* vint, vint, 5 bit literal. */
6099 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
6100 type = v4si_ftype_v4si_char;
6101
6102 /* vshort, vshort, 5 bit literal. */
6103 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
6104 type = v8hi_ftype_v8hi_char;
6105
6106 /* vchar, vchar, 5 bit literal. */
6107 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
6108 type = v16qi_ftype_v16qi_char;
0ac081f6 6109
617e0e1d
DB
6110 /* vfloat, vint, 5 bit literal. */
6111 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
6112 type = v4sf_ftype_v4si_char;
6113
6114 /* vint, vfloat, 5 bit literal. */
6115 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
6116 type = v4si_ftype_v4sf_char;
6117
a3170dc6
AH
6118 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
6119 type = v2si_ftype_int_int;
6120
6121 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
6122 type = v2si_ftype_v2si_char;
6123
6124 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
6125 type = v2si_ftype_int_char;
6126
0ac081f6
AH
6127 /* int, x, x. */
6128 else if (mode0 == SImode)
6129 {
6130 switch (mode1)
6131 {
6132 case V4SImode:
6133 type = int_ftype_v4si_v4si;
6134 break;
6135 case V4SFmode:
6136 type = int_ftype_v4sf_v4sf;
6137 break;
6138 case V16QImode:
6139 type = int_ftype_v16qi_v16qi;
6140 break;
6141 case V8HImode:
6142 type = int_ftype_v8hi_v8hi;
6143 break;
6144 default:
6145 abort ();
6146 }
6147 }
6148
6149 else
6150 abort ();
6151
2212663f
DB
6152 def_builtin (d->mask, d->name, type, d->code);
6153 }
24408032 6154
2212663f
DB
6155 /* Add the simple unary operators. */
6156 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 6157 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
6158 {
6159 enum machine_mode mode0, mode1;
6160 tree type;
6161
0559cc77 6162 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
6163 continue;
6164
6165 mode0 = insn_data[d->icode].operand[0].mode;
6166 mode1 = insn_data[d->icode].operand[1].mode;
6167
6168 if (mode0 == V4SImode && mode1 == QImode)
6169 type = v4si_ftype_char;
6170 else if (mode0 == V8HImode && mode1 == QImode)
6171 type = v8hi_ftype_char;
6172 else if (mode0 == V16QImode && mode1 == QImode)
6173 type = v16qi_ftype_char;
617e0e1d
DB
6174 else if (mode0 == V4SFmode && mode1 == V4SFmode)
6175 type = v4sf_ftype_v4sf;
20e26713
AH
6176 else if (mode0 == V8HImode && mode1 == V16QImode)
6177 type = v8hi_ftype_v16qi;
6178 else if (mode0 == V4SImode && mode1 == V8HImode)
6179 type = v4si_ftype_v8hi;
a3170dc6
AH
6180 else if (mode0 == V2SImode && mode1 == V2SImode)
6181 type = v2si_ftype_v2si;
6182 else if (mode0 == V2SFmode && mode1 == V2SFmode)
6183 type = v2sf_ftype_v2sf;
6184 else if (mode0 == V2SFmode && mode1 == V2SImode)
6185 type = v2sf_ftype_v2si;
6186 else if (mode0 == V2SImode && mode1 == V2SFmode)
6187 type = v2si_ftype_v2sf;
6188 else if (mode0 == V2SImode && mode1 == QImode)
6189 type = v2si_ftype_char;
2212663f
DB
6190 else
6191 abort ();
6192
0ac081f6
AH
6193 def_builtin (d->mask, d->name, type, d->code);
6194 }
6195}
6196
35aff10b 6197\f
7e69e155
MM
6198/* Expand a block move operation, and return 1 if successful. Return 0
6199 if we should let the compiler generate normal code.
6200
6201 operands[0] is the destination
6202 operands[1] is the source
6203 operands[2] is the length
6204 operands[3] is the alignment */
6205
3933e0e1
MM
6206#define MAX_MOVE_REG 4
6207
7e69e155
MM
6208int
6209expand_block_move (operands)
6210 rtx operands[];
6211{
b6c9286a
MM
6212 rtx orig_dest = operands[0];
6213 rtx orig_src = operands[1];
7e69e155 6214 rtx bytes_rtx = operands[2];
7e69e155 6215 rtx align_rtx = operands[3];
3933e0e1 6216 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 6217 int align;
3933e0e1
MM
6218 int bytes;
6219 int offset;
7e69e155
MM
6220 int move_bytes;
6221
3933e0e1 6222 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 6223 if (! constp)
3933e0e1
MM
6224 return 0;
6225
5ee95df6
FS
6226 /* If this is not a fixed size alignment, abort */
6227 if (GET_CODE (align_rtx) != CONST_INT)
6228 abort ();
6229 align = INTVAL (align_rtx);
6230
7e69e155 6231 /* Anything to move? */
3933e0e1
MM
6232 bytes = INTVAL (bytes_rtx);
6233 if (bytes <= 0)
7e69e155
MM
6234 return 1;
6235
ea9982a8 6236 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 6237 reg_parm_stack_space. */
ea9982a8 6238 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
6239 return 0;
6240
3933e0e1 6241 if (TARGET_STRING) /* string instructions are available */
7e69e155 6242 {
35aff10b 6243 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 6244 {
35aff10b
AM
6245 union {
6246 rtx (*movstrsi) PARAMS ((rtx, rtx, rtx, rtx));
6247 rtx (*mov) PARAMS ((rtx, rtx));
6248 } gen_func;
6249 enum machine_mode mode = BLKmode;
6250 rtx src, dest;
6251
3933e0e1 6252 if (bytes > 24 /* move up to 32 bytes at a time */
cc0d9ba8
DE
6253 && ! fixed_regs[5]
6254 && ! fixed_regs[6]
6255 && ! fixed_regs[7]
6256 && ! fixed_regs[8]
6257 && ! fixed_regs[9]
6258 && ! fixed_regs[10]
6259 && ! fixed_regs[11]
6260 && ! fixed_regs[12])
3933e0e1
MM
6261 {
6262 move_bytes = (bytes > 32) ? 32 : bytes;
35aff10b 6263 gen_func.movstrsi = gen_movstrsi_8reg;
3933e0e1
MM
6264 }
6265 else if (bytes > 16 /* move up to 24 bytes at a time */
f9562f27
DE
6266 && ! fixed_regs[5]
6267 && ! fixed_regs[6]
cc0d9ba8
DE
6268 && ! fixed_regs[7]
6269 && ! fixed_regs[8]
6270 && ! fixed_regs[9]
f9562f27 6271 && ! fixed_regs[10])
3933e0e1
MM
6272 {
6273 move_bytes = (bytes > 24) ? 24 : bytes;
35aff10b 6274 gen_func.movstrsi = gen_movstrsi_6reg;
3933e0e1
MM
6275 }
6276 else if (bytes > 8 /* move up to 16 bytes at a time */
f9562f27
DE
6277 && ! fixed_regs[5]
6278 && ! fixed_regs[6]
6279 && ! fixed_regs[7]
6280 && ! fixed_regs[8])
3933e0e1
MM
6281 {
6282 move_bytes = (bytes > 16) ? 16 : bytes;
35aff10b 6283 gen_func.movstrsi = gen_movstrsi_4reg;
3933e0e1 6284 }
acad7ed3 6285 else if (bytes >= 8 && TARGET_POWERPC64
a4f6c312 6286 /* 64-bit loads and stores require word-aligned
82e41834 6287 displacements. */
a4f6c312 6288 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
acad7ed3
DE
6289 {
6290 move_bytes = 8;
35aff10b
AM
6291 mode = DImode;
6292 gen_func.mov = gen_movdi;
acad7ed3 6293 }
09a625f7 6294 else if (bytes > 4 && !TARGET_POWERPC64)
3933e0e1
MM
6295 { /* move up to 8 bytes at a time */
6296 move_bytes = (bytes > 8) ? 8 : bytes;
35aff10b 6297 gen_func.movstrsi = gen_movstrsi_2reg;
3933e0e1 6298 }
cc0d9ba8 6299 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6300 { /* move 4 bytes */
6301 move_bytes = 4;
35aff10b
AM
6302 mode = SImode;
6303 gen_func.mov = gen_movsi;
3933e0e1 6304 }
cc0d9ba8 6305 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6306 { /* move 2 bytes */
6307 move_bytes = 2;
35aff10b
AM
6308 mode = HImode;
6309 gen_func.mov = gen_movhi;
3933e0e1
MM
6310 }
6311 else if (bytes == 1) /* move 1 byte */
6312 {
6313 move_bytes = 1;
35aff10b
AM
6314 mode = QImode;
6315 gen_func.mov = gen_movqi;
3933e0e1
MM
6316 }
6317 else
6318 { /* move up to 4 bytes at a time */
6319 move_bytes = (bytes > 4) ? 4 : bytes;
35aff10b 6320 gen_func.movstrsi = gen_movstrsi_1reg;
3933e0e1 6321 }
4c64a852 6322
35aff10b
AM
6323 src = adjust_address (orig_src, mode, offset);
6324 dest = adjust_address (orig_dest, mode, offset);
6325
6326 if (mode == BLKmode)
015892ee 6327 {
35aff10b
AM
6328 /* Move the address into scratch registers. The movstrsi
6329 patterns require zero offset. */
6330 if (!REG_P (XEXP (src, 0)))
cc0d9ba8 6331 {
35aff10b
AM
6332 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
6333 src = replace_equiv_address (src, src_reg);
cc0d9ba8 6334 }
35aff10b
AM
6335 set_mem_size (src, GEN_INT (move_bytes));
6336
6337 if (!REG_P (XEXP (dest, 0)))
cc0d9ba8 6338 {
35aff10b
AM
6339 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
6340 dest = replace_equiv_address (dest, dest_reg);
cc0d9ba8 6341 }
35aff10b
AM
6342 set_mem_size (dest, GEN_INT (move_bytes));
6343
6344 emit_insn ((*gen_func.movstrsi) (dest, src,
6345 GEN_INT (move_bytes & 31),
6346 align_rtx));
6347 }
6348 else
6349 {
6350 rtx tmp_reg = gen_reg_rtx (mode);
6351
6352 emit_insn ((*gen_func.mov) (tmp_reg, src));
6353 emit_insn ((*gen_func.mov) (dest, tmp_reg));
015892ee 6354 }
4c64a852 6355 }
3933e0e1
MM
6356 }
6357
6358 else /* string instructions not available */
6359 {
35aff10b
AM
6360 rtx stores[MAX_MOVE_REG];
6361 int num_reg = 0;
6362 int i;
6363
6364 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 6365 {
35aff10b
AM
6366 rtx (*gen_mov_func) PARAMS ((rtx, rtx));
6367 enum machine_mode mode;
6368 rtx src, dest, tmp_reg;
3933e0e1 6369
cc0d9ba8
DE
6370 /* Generate the appropriate load and store, saving the stores
6371 for later. */
6372 if (bytes >= 8 && TARGET_POWERPC64
a4f6c312
SS
6373 /* 64-bit loads and stores require word-aligned
6374 displacements. */
cc0d9ba8 6375 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
b6c9286a
MM
6376 {
6377 move_bytes = 8;
35aff10b
AM
6378 mode = DImode;
6379 gen_mov_func = gen_movdi;
b6c9286a 6380 }
cc0d9ba8 6381 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6382 {
6383 move_bytes = 4;
35aff10b
AM
6384 mode = SImode;
6385 gen_mov_func = gen_movsi;
3933e0e1 6386 }
cc0d9ba8 6387 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6388 {
6389 move_bytes = 2;
35aff10b
AM
6390 mode = HImode;
6391 gen_mov_func = gen_movhi;
3933e0e1
MM
6392 }
6393 else
6394 {
6395 move_bytes = 1;
35aff10b
AM
6396 mode = QImode;
6397 gen_mov_func = gen_movqi;
3933e0e1
MM
6398 }
6399
35aff10b
AM
6400 src = adjust_address (orig_src, mode, offset);
6401 dest = adjust_address (orig_dest, mode, offset);
6402 tmp_reg = gen_reg_rtx (mode);
6403
6404 emit_insn ((*gen_mov_func) (tmp_reg, src));
6405 stores[num_reg++] = (*gen_mov_func) (dest, tmp_reg);
6406
3933e0e1
MM
6407 if (num_reg >= MAX_MOVE_REG)
6408 {
6409 for (i = 0; i < num_reg; i++)
6410 emit_insn (stores[i]);
6411 num_reg = 0;
7e69e155
MM
6412 }
6413 }
3933e0e1 6414
b6c9286a
MM
6415 for (i = 0; i < num_reg; i++)
6416 emit_insn (stores[i]);
7e69e155
MM
6417 }
6418
6419 return 1;
6420}
6421
9878760c
RK
6422\f
6423/* Return 1 if OP is a load multiple operation. It is known to be a
6424 PARALLEL and the first section will be tested. */
6425
6426int
6427load_multiple_operation (op, mode)
6428 rtx op;
296b8152 6429 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6430{
6431 int count = XVECLEN (op, 0);
e2c953b6 6432 unsigned int dest_regno;
9878760c
RK
6433 rtx src_addr;
6434 int i;
6435
6436 /* Perform a quick check so we don't blow up below. */
6437 if (count <= 1
6438 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6439 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
6440 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
6441 return 0;
6442
6443 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6444 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
6445
6446 for (i = 1; i < count; i++)
6447 {
6448 rtx elt = XVECEXP (op, 0, i);
6449
6450 if (GET_CODE (elt) != SET
6451 || GET_CODE (SET_DEST (elt)) != REG
6452 || GET_MODE (SET_DEST (elt)) != SImode
6453 || REGNO (SET_DEST (elt)) != dest_regno + i
6454 || GET_CODE (SET_SRC (elt)) != MEM
6455 || GET_MODE (SET_SRC (elt)) != SImode
6456 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
6457 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
6458 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
6459 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
6460 return 0;
6461 }
6462
6463 return 1;
6464}
6465
6466/* Similar, but tests for store multiple. Here, the second vector element
6467 is a CLOBBER. It will be tested later. */
6468
6469int
6470store_multiple_operation (op, mode)
6471 rtx op;
296b8152 6472 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6473{
6474 int count = XVECLEN (op, 0) - 1;
e2c953b6 6475 unsigned int src_regno;
9878760c
RK
6476 rtx dest_addr;
6477 int i;
6478
6479 /* Perform a quick check so we don't blow up below. */
6480 if (count <= 1
6481 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6482 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
6483 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
6484 return 0;
6485
6486 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6487 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
6488
6489 for (i = 1; i < count; i++)
6490 {
6491 rtx elt = XVECEXP (op, 0, i + 1);
6492
6493 if (GET_CODE (elt) != SET
6494 || GET_CODE (SET_SRC (elt)) != REG
6495 || GET_MODE (SET_SRC (elt)) != SImode
6496 || REGNO (SET_SRC (elt)) != src_regno + i
6497 || GET_CODE (SET_DEST (elt)) != MEM
6498 || GET_MODE (SET_DEST (elt)) != SImode
6499 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
6500 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
6501 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
6502 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
6503 return 0;
6504 }
6505
6506 return 1;
6507}
9ebbca7d 6508
9caa3eb2
DE
6509/* Return a string to perform a load_multiple operation.
6510 operands[0] is the vector.
6511 operands[1] is the source address.
6512 operands[2] is the first destination register. */
6513
6514const char *
6515rs6000_output_load_multiple (operands)
ebe637e3 6516 rtx operands[3];
9caa3eb2
DE
6517{
6518 /* We have to handle the case where the pseudo used to contain the address
6519 is assigned to one of the output registers. */
6520 int i, j;
6521 int words = XVECLEN (operands[0], 0);
6522 rtx xop[10];
6523
6524 if (XVECLEN (operands[0], 0) == 1)
6525 return "{l|lwz} %2,0(%1)";
6526
6527 for (i = 0; i < words; i++)
6528 if (refers_to_regno_p (REGNO (operands[2]) + i,
6529 REGNO (operands[2]) + i + 1, operands[1], 0))
6530 {
6531 if (i == words-1)
6532 {
6533 xop[0] = GEN_INT (4 * (words-1));
6534 xop[1] = operands[1];
6535 xop[2] = operands[2];
6536 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
6537 return "";
6538 }
6539 else if (i == 0)
6540 {
6541 xop[0] = GEN_INT (4 * (words-1));
6542 xop[1] = operands[1];
6543 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6544 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);
6545 return "";
6546 }
6547 else
6548 {
6549 for (j = 0; j < words; j++)
6550 if (j != i)
6551 {
6552 xop[0] = GEN_INT (j * 4);
6553 xop[1] = operands[1];
6554 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
6555 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
6556 }
6557 xop[0] = GEN_INT (i * 4);
6558 xop[1] = operands[1];
6559 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
6560 return "";
6561 }
6562 }
6563
6564 return "{lsi|lswi} %2,%1,%N0";
6565}
6566
00b960c7
AH
6567/* Return 1 for a parallel vrsave operation. */
6568
6569int
6570vrsave_operation (op, mode)
6571 rtx op;
6572 enum machine_mode mode ATTRIBUTE_UNUSED;
6573{
6574 int count = XVECLEN (op, 0);
6575 unsigned int dest_regno, src_regno;
6576 int i;
6577
6578 if (count <= 1
6579 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6580 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 6581 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
6582 return 0;
6583
6584 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6585 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6586
6587 if (dest_regno != VRSAVE_REGNO
6588 && src_regno != VRSAVE_REGNO)
6589 return 0;
6590
6591 for (i = 1; i < count; i++)
6592 {
6593 rtx elt = XVECEXP (op, 0, i);
6594
9aa86737
AH
6595 if (GET_CODE (elt) != CLOBBER
6596 && GET_CODE (elt) != SET)
00b960c7
AH
6597 return 0;
6598 }
6599
6600 return 1;
6601}
6602
a4f6c312 6603/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
6604
6605int
6606mtcrf_operation (op, mode)
6607 rtx op;
6608 enum machine_mode mode ATTRIBUTE_UNUSED;
6609{
6610 int count = XVECLEN (op, 0);
6611 int i;
9ebbca7d
GK
6612 rtx src_reg;
6613
6614 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
6615 if (count < 1
6616 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6617 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
6618 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 6619 return 0;
e35b9579 6620 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
6621
6622 if (GET_CODE (src_reg) != REG
6623 || GET_MODE (src_reg) != SImode
6624 || ! INT_REGNO_P (REGNO (src_reg)))
6625 return 0;
6626
e35b9579 6627 for (i = 0; i < count; i++)
9ebbca7d
GK
6628 {
6629 rtx exp = XVECEXP (op, 0, i);
6630 rtx unspec;
6631 int maskval;
6632
6633 if (GET_CODE (exp) != SET
6634 || GET_CODE (SET_DEST (exp)) != REG
6635 || GET_MODE (SET_DEST (exp)) != CCmode
6636 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
6637 return 0;
6638 unspec = SET_SRC (exp);
6639 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
6640
6641 if (GET_CODE (unspec) != UNSPEC
6642 || XINT (unspec, 1) != 20
6643 || XVECLEN (unspec, 0) != 2
6644 || XVECEXP (unspec, 0, 0) != src_reg
6645 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
6646 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
6647 return 0;
6648 }
e35b9579 6649 return 1;
9ebbca7d
GK
6650}
6651
a4f6c312 6652/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
6653
6654int
6655lmw_operation (op, mode)
6656 rtx op;
6657 enum machine_mode mode ATTRIBUTE_UNUSED;
6658{
6659 int count = XVECLEN (op, 0);
e2c953b6 6660 unsigned int dest_regno;
9ebbca7d 6661 rtx src_addr;
e2c953b6 6662 unsigned int base_regno;
9ebbca7d
GK
6663 HOST_WIDE_INT offset;
6664 int i;
6665
6666 /* Perform a quick check so we don't blow up below. */
6667 if (count <= 1
6668 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6669 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
6670 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
6671 return 0;
6672
6673 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6674 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
6675
6676 if (dest_regno > 31
e2c953b6 6677 || count != 32 - (int) dest_regno)
9ebbca7d
GK
6678 return 0;
6679
258bfae2 6680 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr, 0))
9ebbca7d
GK
6681 {
6682 offset = 0;
6683 base_regno = REGNO (src_addr);
6684 if (base_regno == 0)
6685 return 0;
6686 }
258bfae2 6687 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr, 0))
9ebbca7d
GK
6688 {
6689 offset = INTVAL (XEXP (src_addr, 1));
6690 base_regno = REGNO (XEXP (src_addr, 0));
6691 }
6692 else
6693 return 0;
6694
6695 for (i = 0; i < count; i++)
6696 {
6697 rtx elt = XVECEXP (op, 0, i);
6698 rtx newaddr;
6699 rtx addr_reg;
6700 HOST_WIDE_INT newoffset;
6701
6702 if (GET_CODE (elt) != SET
6703 || GET_CODE (SET_DEST (elt)) != REG
6704 || GET_MODE (SET_DEST (elt)) != SImode
6705 || REGNO (SET_DEST (elt)) != dest_regno + i
6706 || GET_CODE (SET_SRC (elt)) != MEM
6707 || GET_MODE (SET_SRC (elt)) != SImode)
6708 return 0;
6709 newaddr = XEXP (SET_SRC (elt), 0);
258bfae2 6710 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
6711 {
6712 newoffset = 0;
6713 addr_reg = newaddr;
6714 }
258bfae2 6715 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
6716 {
6717 addr_reg = XEXP (newaddr, 0);
6718 newoffset = INTVAL (XEXP (newaddr, 1));
6719 }
6720 else
6721 return 0;
6722 if (REGNO (addr_reg) != base_regno
6723 || newoffset != offset + 4 * i)
6724 return 0;
6725 }
6726
6727 return 1;
6728}
6729
a4f6c312 6730/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
6731
6732int
6733stmw_operation (op, mode)
6734 rtx op;
6735 enum machine_mode mode ATTRIBUTE_UNUSED;
6736{
6737 int count = XVECLEN (op, 0);
e2c953b6 6738 unsigned int src_regno;
9ebbca7d 6739 rtx dest_addr;
e2c953b6 6740 unsigned int base_regno;
9ebbca7d
GK
6741 HOST_WIDE_INT offset;
6742 int i;
6743
6744 /* Perform a quick check so we don't blow up below. */
6745 if (count <= 1
6746 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6747 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
6748 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
6749 return 0;
6750
6751 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6752 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
6753
6754 if (src_regno > 31
e2c953b6 6755 || count != 32 - (int) src_regno)
9ebbca7d
GK
6756 return 0;
6757
258bfae2 6758 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr, 0))
9ebbca7d
GK
6759 {
6760 offset = 0;
6761 base_regno = REGNO (dest_addr);
6762 if (base_regno == 0)
6763 return 0;
6764 }
258bfae2 6765 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr, 0))
9ebbca7d
GK
6766 {
6767 offset = INTVAL (XEXP (dest_addr, 1));
6768 base_regno = REGNO (XEXP (dest_addr, 0));
6769 }
6770 else
6771 return 0;
6772
6773 for (i = 0; i < count; i++)
6774 {
6775 rtx elt = XVECEXP (op, 0, i);
6776 rtx newaddr;
6777 rtx addr_reg;
6778 HOST_WIDE_INT newoffset;
6779
6780 if (GET_CODE (elt) != SET
6781 || GET_CODE (SET_SRC (elt)) != REG
6782 || GET_MODE (SET_SRC (elt)) != SImode
6783 || REGNO (SET_SRC (elt)) != src_regno + i
6784 || GET_CODE (SET_DEST (elt)) != MEM
6785 || GET_MODE (SET_DEST (elt)) != SImode)
6786 return 0;
6787 newaddr = XEXP (SET_DEST (elt), 0);
258bfae2 6788 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
6789 {
6790 newoffset = 0;
6791 addr_reg = newaddr;
6792 }
258bfae2 6793 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
6794 {
6795 addr_reg = XEXP (newaddr, 0);
6796 newoffset = INTVAL (XEXP (newaddr, 1));
6797 }
6798 else
6799 return 0;
6800 if (REGNO (addr_reg) != base_regno
6801 || newoffset != offset + 4 * i)
6802 return 0;
6803 }
6804
6805 return 1;
6806}
9878760c 6807\f
a4f6c312
SS
6808/* A validation routine: say whether CODE, a condition code, and MODE
6809 match. The other alternatives either don't make sense or should
6810 never be generated. */
39a10a29 6811
39a10a29
GK
6812static void
6813validate_condition_mode (code, mode)
6814 enum rtx_code code;
6815 enum machine_mode mode;
6816{
6817 if (GET_RTX_CLASS (code) != '<'
6818 || GET_MODE_CLASS (mode) != MODE_CC)
6819 abort ();
6820
6821 /* These don't make sense. */
6822 if ((code == GT || code == LT || code == GE || code == LE)
6823 && mode == CCUNSmode)
6824 abort ();
6825
6826 if ((code == GTU || code == LTU || code == GEU || code == LEU)
6827 && mode != CCUNSmode)
6828 abort ();
6829
6830 if (mode != CCFPmode
6831 && (code == ORDERED || code == UNORDERED
6832 || code == UNEQ || code == LTGT
6833 || code == UNGT || code == UNLT
6834 || code == UNGE || code == UNLE))
a4f6c312 6835 abort ();
39a10a29 6836
de6c5979 6837 /* These should never be generated except for
ad72b533 6838 flag_unsafe_math_optimizations and flag_finite_math_only. */
39a10a29 6839 if (mode == CCFPmode
de6c5979 6840 && ! flag_unsafe_math_optimizations
ad72b533 6841 && ! flag_finite_math_only
39a10a29
GK
6842 && (code == LE || code == GE
6843 || code == UNEQ || code == LTGT
6844 || code == UNGT || code == UNLT))
6845 abort ();
6846
6847 /* These are invalid; the information is not there. */
6848 if (mode == CCEQmode
6849 && code != EQ && code != NE)
6850 abort ();
6851}
6852
9878760c
RK
6853/* Return 1 if OP is a comparison operation that is valid for a branch insn.
6854 We only check the opcode against the mode of the CC value here. */
6855
6856int
6857branch_comparison_operator (op, mode)
592696dd 6858 rtx op;
296b8152 6859 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6860{
6861 enum rtx_code code = GET_CODE (op);
6862 enum machine_mode cc_mode;
6863
6864 if (GET_RTX_CLASS (code) != '<')
6865 return 0;
6866
6867 cc_mode = GET_MODE (XEXP (op, 0));
6868 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
6869 return 0;
6870
39a10a29 6871 validate_condition_mode (code, cc_mode);
9878760c 6872
39a10a29
GK
6873 return 1;
6874}
6875
6876/* Return 1 if OP is a comparison operation that is valid for a branch
6877 insn and which is true if the corresponding bit in the CC register
6878 is set. */
6879
6880int
6881branch_positive_comparison_operator (op, mode)
592696dd 6882 rtx op;
39a10a29
GK
6883 enum machine_mode mode;
6884{
6885 enum rtx_code code;
6886
6887 if (! branch_comparison_operator (op, mode))
9878760c
RK
6888 return 0;
6889
39a10a29
GK
6890 code = GET_CODE (op);
6891 return (code == EQ || code == LT || code == GT
a3170dc6 6892 || (TARGET_SPE && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
6893 || code == LTU || code == GTU
6894 || code == UNORDERED);
9878760c
RK
6895}
6896
6897/* Return 1 if OP is a comparison operation that is valid for an scc insn.
6898 We check the opcode against the mode of the CC value and disallow EQ or
6899 NE comparisons for integers. */
6900
6901int
6902scc_comparison_operator (op, mode)
592696dd 6903 rtx op;
9878760c
RK
6904 enum machine_mode mode;
6905{
6906 enum rtx_code code = GET_CODE (op);
6907 enum machine_mode cc_mode;
6908
6909 if (GET_MODE (op) != mode && mode != VOIDmode)
6910 return 0;
6911
6912 if (GET_RTX_CLASS (code) != '<')
6913 return 0;
6914
6915 cc_mode = GET_MODE (XEXP (op, 0));
6916 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
6917 return 0;
6918
39a10a29 6919 validate_condition_mode (code, cc_mode);
9878760c 6920
39a10a29 6921 if (code == NE && cc_mode != CCFPmode)
c5defebb
RK
6922 return 0;
6923
9878760c
RK
6924 return 1;
6925}
e0cd0770
JC
6926
6927int
6928trap_comparison_operator (op, mode)
6929 rtx op;
6930 enum machine_mode mode;
6931{
6932 if (mode != VOIDmode && mode != GET_MODE (op))
6933 return 0;
39a10a29 6934 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 6935}
dfbdccdb
GK
6936
6937int
6938boolean_operator (op, mode)
6939 rtx op;
6940 enum machine_mode mode ATTRIBUTE_UNUSED;
6941{
6942 enum rtx_code code = GET_CODE (op);
6943 return (code == AND || code == IOR || code == XOR);
6944}
1d328b19
GK
6945
6946int
6947boolean_or_operator (op, mode)
6948 rtx op;
6949 enum machine_mode mode ATTRIBUTE_UNUSED;
6950{
6951 enum rtx_code code = GET_CODE (op);
6952 return (code == IOR || code == XOR);
6953}
50a0b056
GK
6954
6955int
6956min_max_operator (op, mode)
6957 rtx op;
6958 enum machine_mode mode ATTRIBUTE_UNUSED;
6959{
6960 enum rtx_code code = GET_CODE (op);
6961 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
6962}
9878760c
RK
6963\f
6964/* Return 1 if ANDOP is a mask that has no bits on that are not in the
6965 mask required to convert the result of a rotate insn into a shift
b1765bde 6966 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
6967
6968int
6969includes_lshift_p (shiftop, andop)
592696dd
SS
6970 rtx shiftop;
6971 rtx andop;
9878760c 6972{
e2c953b6
DE
6973 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
6974
6975 shift_mask <<= INTVAL (shiftop);
9878760c 6976
b1765bde 6977 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
6978}
6979
6980/* Similar, but for right shift. */
6981
6982int
6983includes_rshift_p (shiftop, andop)
592696dd
SS
6984 rtx shiftop;
6985 rtx andop;
9878760c 6986{
a7653a2c 6987 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
6988
6989 shift_mask >>= INTVAL (shiftop);
6990
b1765bde 6991 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
6992}
6993
c5059423
AM
6994/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
6995 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 6996 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
6997
6998int
c5059423 6999includes_rldic_lshift_p (shiftop, andop)
592696dd
SS
7000 rtx shiftop;
7001 rtx andop;
e2c953b6 7002{
c5059423
AM
7003 if (GET_CODE (andop) == CONST_INT)
7004 {
02071907 7005 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 7006
c5059423 7007 c = INTVAL (andop);
02071907 7008 if (c == 0 || c == ~0)
c5059423 7009 return 0;
e2c953b6 7010
02071907 7011 shift_mask = ~0;
c5059423
AM
7012 shift_mask <<= INTVAL (shiftop);
7013
b6d08ca1 7014 /* Find the least significant one bit. */
c5059423
AM
7015 lsb = c & -c;
7016
7017 /* It must coincide with the LSB of the shift mask. */
7018 if (-lsb != shift_mask)
7019 return 0;
e2c953b6 7020
c5059423
AM
7021 /* Invert to look for the next transition (if any). */
7022 c = ~c;
7023
7024 /* Remove the low group of ones (originally low group of zeros). */
7025 c &= -lsb;
7026
7027 /* Again find the lsb, and check we have all 1's above. */
7028 lsb = c & -c;
7029 return c == -lsb;
7030 }
7031 else if (GET_CODE (andop) == CONST_DOUBLE
7032 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7033 {
02071907
AM
7034 HOST_WIDE_INT low, high, lsb;
7035 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
7036
7037 low = CONST_DOUBLE_LOW (andop);
7038 if (HOST_BITS_PER_WIDE_INT < 64)
7039 high = CONST_DOUBLE_HIGH (andop);
7040
7041 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 7042 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
7043 return 0;
7044
7045 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7046 {
02071907 7047 shift_mask_high = ~0;
c5059423
AM
7048 if (INTVAL (shiftop) > 32)
7049 shift_mask_high <<= INTVAL (shiftop) - 32;
7050
7051 lsb = high & -high;
7052
7053 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
7054 return 0;
7055
7056 high = ~high;
7057 high &= -lsb;
7058
7059 lsb = high & -high;
7060 return high == -lsb;
7061 }
7062
02071907 7063 shift_mask_low = ~0;
c5059423
AM
7064 shift_mask_low <<= INTVAL (shiftop);
7065
7066 lsb = low & -low;
7067
7068 if (-lsb != shift_mask_low)
7069 return 0;
7070
7071 if (HOST_BITS_PER_WIDE_INT < 64)
7072 high = ~high;
7073 low = ~low;
7074 low &= -lsb;
7075
7076 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7077 {
7078 lsb = high & -high;
7079 return high == -lsb;
7080 }
7081
7082 lsb = low & -low;
7083 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
7084 }
7085 else
7086 return 0;
7087}
e2c953b6 7088
c5059423
AM
7089/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
7090 to perform a left shift. It must have SHIFTOP or more least
7091 signifigant 0's, with the remainder of the word 1's. */
e2c953b6 7092
c5059423
AM
7093int
7094includes_rldicr_lshift_p (shiftop, andop)
592696dd
SS
7095 rtx shiftop;
7096 rtx andop;
c5059423 7097{
e2c953b6 7098 if (GET_CODE (andop) == CONST_INT)
c5059423 7099 {
02071907 7100 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 7101
02071907 7102 shift_mask = ~0;
c5059423
AM
7103 shift_mask <<= INTVAL (shiftop);
7104 c = INTVAL (andop);
7105
7106 /* Find the least signifigant one bit. */
7107 lsb = c & -c;
7108
7109 /* It must be covered by the shift mask.
a4f6c312 7110 This test also rejects c == 0. */
c5059423
AM
7111 if ((lsb & shift_mask) == 0)
7112 return 0;
7113
7114 /* Check we have all 1's above the transition, and reject all 1's. */
7115 return c == -lsb && lsb != 1;
7116 }
7117 else if (GET_CODE (andop) == CONST_DOUBLE
7118 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7119 {
02071907 7120 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
7121
7122 low = CONST_DOUBLE_LOW (andop);
7123
7124 if (HOST_BITS_PER_WIDE_INT < 64)
7125 {
02071907 7126 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
7127
7128 high = CONST_DOUBLE_HIGH (andop);
7129
7130 if (low == 0)
7131 {
02071907 7132 shift_mask_high = ~0;
c5059423
AM
7133 if (INTVAL (shiftop) > 32)
7134 shift_mask_high <<= INTVAL (shiftop) - 32;
7135
7136 lsb = high & -high;
7137
7138 if ((lsb & shift_mask_high) == 0)
7139 return 0;
7140
7141 return high == -lsb;
7142 }
7143 if (high != ~0)
7144 return 0;
7145 }
7146
02071907 7147 shift_mask_low = ~0;
c5059423
AM
7148 shift_mask_low <<= INTVAL (shiftop);
7149
7150 lsb = low & -low;
7151
7152 if ((lsb & shift_mask_low) == 0)
7153 return 0;
7154
7155 return low == -lsb && lsb != 1;
7156 }
e2c953b6 7157 else
c5059423 7158 return 0;
9878760c 7159}
35068b43
RK
7160
7161/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
7162 for lfq and stfq insns.
7163
7164 Note reg1 and reg2 *must* be hard registers. To be sure we will
7165 abort if we are passed pseudo registers. */
7166
7167int
7168registers_ok_for_quad_peep (reg1, reg2)
7169 rtx reg1, reg2;
7170{
7171 /* We might have been passed a SUBREG. */
7172 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
7173 return 0;
7174
7175 return (REGNO (reg1) == REGNO (reg2) - 1);
7176}
7177
a4f6c312
SS
7178/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
7179 addr1 and addr2 must be in consecutive memory locations
7180 (addr2 == addr1 + 8). */
35068b43
RK
7181
7182int
7183addrs_ok_for_quad_peep (addr1, addr2)
592696dd
SS
7184 rtx addr1;
7185 rtx addr2;
35068b43 7186{
e2c953b6 7187 unsigned int reg1;
35068b43
RK
7188 int offset1;
7189
7190 /* Extract an offset (if used) from the first addr. */
7191 if (GET_CODE (addr1) == PLUS)
7192 {
7193 /* If not a REG, return zero. */
7194 if (GET_CODE (XEXP (addr1, 0)) != REG)
7195 return 0;
7196 else
7197 {
7198 reg1 = REGNO (XEXP (addr1, 0));
7199 /* The offset must be constant! */
7200 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
7201 return 0;
7202 offset1 = INTVAL (XEXP (addr1, 1));
7203 }
7204 }
7205 else if (GET_CODE (addr1) != REG)
7206 return 0;
7207 else
7208 {
7209 reg1 = REGNO (addr1);
7210 /* This was a simple (mem (reg)) expression. Offset is 0. */
7211 offset1 = 0;
7212 }
7213
acad7ed3 7214 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
35068b43
RK
7215 if (GET_CODE (addr2) != PLUS)
7216 return 0;
7217
7218 if (GET_CODE (XEXP (addr2, 0)) != REG
7219 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7220 return 0;
7221
7222 if (reg1 != REGNO (XEXP (addr2, 0)))
7223 return 0;
7224
7225 /* The offset for the second addr must be 8 more than the first addr. */
7226 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
7227 return 0;
7228
7229 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
7230 instructions. */
7231 return 1;
7232}
9878760c
RK
7233\f
7234/* Return the register class of a scratch register needed to copy IN into
7235 or out of a register in CLASS in MODE. If it can be done directly,
7236 NO_REGS is returned. */
7237
7238enum reg_class
7239secondary_reload_class (class, mode, in)
7240 enum reg_class class;
296b8152 7241 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
7242 rtx in;
7243{
5accd822 7244 int regno;
9878760c 7245
ab82a49f
AP
7246 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
7247#if TARGET_MACHO
7248 && MACHOPIC_INDIRECT
7249#endif
7250 ))
46fad5b7
DJ
7251 {
7252 /* We cannot copy a symbolic operand directly into anything
7253 other than BASE_REGS for TARGET_ELF. So indicate that a
7254 register from BASE_REGS is needed as an intermediate
7255 register.
7256
7257 On Darwin, pic addresses require a load from memory, which
7258 needs a base register. */
7259 if (class != BASE_REGS
7260 && (GET_CODE (in) == SYMBOL_REF
7261 || GET_CODE (in) == HIGH
7262 || GET_CODE (in) == LABEL_REF
7263 || GET_CODE (in) == CONST))
7264 return BASE_REGS;
7265 }
e7b7998a 7266
5accd822
DE
7267 if (GET_CODE (in) == REG)
7268 {
7269 regno = REGNO (in);
7270 if (regno >= FIRST_PSEUDO_REGISTER)
7271 {
7272 regno = true_regnum (in);
7273 if (regno >= FIRST_PSEUDO_REGISTER)
7274 regno = -1;
7275 }
7276 }
7277 else if (GET_CODE (in) == SUBREG)
7278 {
7279 regno = true_regnum (in);
7280 if (regno >= FIRST_PSEUDO_REGISTER)
7281 regno = -1;
7282 }
7283 else
7284 regno = -1;
7285
9878760c
RK
7286 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
7287 into anything. */
7288 if (class == GENERAL_REGS || class == BASE_REGS
7289 || (regno >= 0 && INT_REGNO_P (regno)))
7290 return NO_REGS;
7291
7292 /* Constants, memory, and FP registers can go into FP registers. */
7293 if ((regno == -1 || FP_REGNO_P (regno))
7294 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
7295 return NO_REGS;
7296
0ac081f6
AH
7297 /* Memory, and AltiVec registers can go into AltiVec registers. */
7298 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
7299 && class == ALTIVEC_REGS)
7300 return NO_REGS;
7301
9878760c
RK
7302 /* We can copy among the CR registers. */
7303 if ((class == CR_REGS || class == CR0_REGS)
7304 && regno >= 0 && CR_REGNO_P (regno))
7305 return NO_REGS;
7306
7307 /* Otherwise, we need GENERAL_REGS. */
7308 return GENERAL_REGS;
7309}
7310\f
7311/* Given a comparison operation, return the bit number in CCR to test. We
7312 know this is a valid comparison.
7313
7314 SCC_P is 1 if this is for an scc. That means that %D will have been
7315 used instead of %C, so the bits will be in different places.
7316
b4ac57ab 7317 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
7318
7319int
7320ccr_bit (op, scc_p)
592696dd 7321 rtx op;
9878760c
RK
7322 int scc_p;
7323{
7324 enum rtx_code code = GET_CODE (op);
7325 enum machine_mode cc_mode;
7326 int cc_regnum;
7327 int base_bit;
9ebbca7d 7328 rtx reg;
9878760c
RK
7329
7330 if (GET_RTX_CLASS (code) != '<')
7331 return -1;
7332
9ebbca7d
GK
7333 reg = XEXP (op, 0);
7334
7335 if (GET_CODE (reg) != REG
7336 || ! CR_REGNO_P (REGNO (reg)))
7337 abort ();
7338
7339 cc_mode = GET_MODE (reg);
7340 cc_regnum = REGNO (reg);
7341 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 7342
39a10a29 7343 validate_condition_mode (code, cc_mode);
c5defebb 7344
9878760c
RK
7345 switch (code)
7346 {
7347 case NE:
a3170dc6
AH
7348 if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
7349 return base_bit + 1;
9878760c
RK
7350 return scc_p ? base_bit + 3 : base_bit + 2;
7351 case EQ:
a3170dc6
AH
7352 if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
7353 return base_bit + 1;
9878760c 7354 return base_bit + 2;
1c882ea4 7355 case GT: case GTU: case UNLE:
9878760c 7356 return base_bit + 1;
1c882ea4 7357 case LT: case LTU: case UNGE:
9878760c 7358 return base_bit;
1c882ea4
GK
7359 case ORDERED: case UNORDERED:
7360 return base_bit + 3;
9878760c
RK
7361
7362 case GE: case GEU:
39a10a29 7363 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
7364 unordered position. So test that bit. For integer, this is ! LT
7365 unless this is an scc insn. */
39a10a29 7366 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
7367
7368 case LE: case LEU:
39a10a29 7369 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 7370
9878760c
RK
7371 default:
7372 abort ();
7373 }
7374}
1ff7789b 7375\f
8d30c4ee 7376/* Return the GOT register. */
1ff7789b
MM
7377
7378struct rtx_def *
7379rs6000_got_register (value)
5f59ecb7 7380 rtx value ATTRIBUTE_UNUSED;
1ff7789b 7381{
a4f6c312
SS
7382 /* The second flow pass currently (June 1999) can't update
7383 regs_ever_live without disturbing other parts of the compiler, so
7384 update it here to make the prolog/epilogue code happy. */
1db02437
FS
7385 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
7386 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 7387
8d30c4ee 7388 current_function_uses_pic_offset_table = 1;
3cb999d8 7389
1ff7789b
MM
7390 return pic_offset_table_rtx;
7391}
a7df97e6 7392\f
e2500fed
GK
7393/* Function to init struct machine_function.
7394 This will be called, via a pointer variable,
7395 from push_function_context. */
a7df97e6 7396
e2500fed
GK
7397static struct machine_function *
7398rs6000_init_machine_status ()
a7df97e6 7399{
e2500fed 7400 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 7401}
9878760c 7402\f
0ba1b2ff
AM
7403/* These macros test for integers and extract the low-order bits. */
7404#define INT_P(X) \
7405((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
7406 && GET_MODE (X) == VOIDmode)
7407
7408#define INT_LOWPART(X) \
7409 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
7410
7411int
7412extract_MB (op)
7413 rtx op;
7414{
7415 int i;
7416 unsigned long val = INT_LOWPART (op);
7417
7418 /* If the high bit is zero, the value is the first 1 bit we find
7419 from the left. */
7420 if ((val & 0x80000000) == 0)
7421 {
7422 if ((val & 0xffffffff) == 0)
7423 abort ();
7424
7425 i = 1;
7426 while (((val <<= 1) & 0x80000000) == 0)
7427 ++i;
7428 return i;
7429 }
7430
7431 /* If the high bit is set and the low bit is not, or the mask is all
7432 1's, the value is zero. */
7433 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
7434 return 0;
7435
7436 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
7437 from the right. */
7438 i = 31;
7439 while (((val >>= 1) & 1) != 0)
7440 --i;
7441
7442 return i;
7443}
7444
7445int
7446extract_ME (op)
7447 rtx op;
7448{
7449 int i;
7450 unsigned long val = INT_LOWPART (op);
7451
7452 /* If the low bit is zero, the value is the first 1 bit we find from
7453 the right. */
7454 if ((val & 1) == 0)
7455 {
7456 if ((val & 0xffffffff) == 0)
7457 abort ();
7458
7459 i = 30;
7460 while (((val >>= 1) & 1) == 0)
7461 --i;
7462
7463 return i;
7464 }
7465
7466 /* If the low bit is set and the high bit is not, or the mask is all
7467 1's, the value is 31. */
7468 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
7469 return 31;
7470
7471 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
7472 from the left. */
7473 i = 0;
7474 while (((val <<= 1) & 0x80000000) != 0)
7475 ++i;
7476
7477 return i;
7478}
7479
9878760c
RK
7480/* Print an operand. Recognize special options, documented below. */
7481
38c1f2d7 7482#if TARGET_ELF
d9407988 7483#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 7484#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
7485#else
7486#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 7487#define SMALL_DATA_REG 0
ba5e43aa
MM
7488#endif
7489
9878760c
RK
7490void
7491print_operand (file, x, code)
7492 FILE *file;
7493 rtx x;
9ebbca7d 7494 int code;
9878760c
RK
7495{
7496 int i;
a260abc9 7497 HOST_WIDE_INT val;
0ba1b2ff 7498 unsigned HOST_WIDE_INT uval;
9878760c
RK
7499
7500 switch (code)
7501 {
a8b3aeda 7502 case '.':
a85d226b
RK
7503 /* Write out an instruction after the call which may be replaced
7504 with glue code by the loader. This depends on the AIX version. */
7505 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
7506 return;
7507
81eace42
GK
7508 /* %a is output_address. */
7509
9854d9ed
RK
7510 case 'A':
7511 /* If X is a constant integer whose low-order 5 bits are zero,
7512 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 7513 in the AIX assembler where "sri" with a zero shift count
20e26713 7514 writes a trash instruction. */
9854d9ed 7515 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 7516 putc ('l', file);
9854d9ed 7517 else
76229ac8 7518 putc ('r', file);
9854d9ed
RK
7519 return;
7520
7521 case 'b':
e2c953b6
DE
7522 /* If constant, low-order 16 bits of constant, unsigned.
7523 Otherwise, write normally. */
7524 if (INT_P (x))
7525 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
7526 else
7527 print_operand (file, x, 0);
cad12a8d
RK
7528 return;
7529
a260abc9
DE
7530 case 'B':
7531 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
7532 for 64-bit mask direction. */
296b8152 7533 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 7534 return;
a260abc9 7535
81eace42
GK
7536 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
7537 output_operand. */
7538
9854d9ed 7539 case 'D':
39a10a29
GK
7540 /* There used to be a comment for 'C' reading "This is an
7541 optional cror needed for certain floating-point
7542 comparisons. Otherwise write nothing." */
7543
9854d9ed
RK
7544 /* Similar, except that this is for an scc, so we must be able to
7545 encode the test in a single bit that is one. We do the above
7546 for any LE, GE, GEU, or LEU and invert the bit for NE. */
7547 if (GET_CODE (x) == LE || GET_CODE (x) == GE
7548 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
7549 {
9ebbca7d 7550 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
7551
7552 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
7553 base_bit + 2,
7554 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
7555 }
7556
7557 else if (GET_CODE (x) == NE)
7558 {
9ebbca7d 7559 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
7560
7561 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
7562 base_bit + 2, base_bit + 2);
7563 }
a3170dc6
AH
7564 else if (TARGET_SPE && TARGET_HARD_FLOAT
7565 && GET_CODE (x) == EQ
7566 && GET_MODE (XEXP (x, 0)) == CCFPmode)
7567 {
7568 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
7569
7570 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 1,
7571 base_bit + 1, base_bit + 1);
7572 }
9854d9ed
RK
7573 return;
7574
7575 case 'E':
39a10a29 7576 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
7577 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7578 output_operand_lossage ("invalid %%E value");
78fbdbf7 7579 else
39a10a29 7580 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 7581 return;
9854d9ed
RK
7582
7583 case 'f':
7584 /* X is a CR register. Print the shift count needed to move it
7585 to the high-order four bits. */
7586 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7587 output_operand_lossage ("invalid %%f value");
7588 else
9ebbca7d 7589 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
7590 return;
7591
7592 case 'F':
7593 /* Similar, but print the count for the rotate in the opposite
7594 direction. */
7595 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7596 output_operand_lossage ("invalid %%F value");
7597 else
9ebbca7d 7598 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
7599 return;
7600
7601 case 'G':
7602 /* X is a constant integer. If it is negative, print "m",
43aa4e05 7603 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
7604 if (GET_CODE (x) != CONST_INT)
7605 output_operand_lossage ("invalid %%G value");
7606 else if (INTVAL (x) >= 0)
76229ac8 7607 putc ('z', file);
9854d9ed 7608 else
76229ac8 7609 putc ('m', file);
9854d9ed 7610 return;
e2c953b6 7611
9878760c 7612 case 'h':
a4f6c312
SS
7613 /* If constant, output low-order five bits. Otherwise, write
7614 normally. */
9878760c 7615 if (INT_P (x))
5f59ecb7 7616 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
7617 else
7618 print_operand (file, x, 0);
7619 return;
7620
64305719 7621 case 'H':
a4f6c312
SS
7622 /* If constant, output low-order six bits. Otherwise, write
7623 normally. */
64305719 7624 if (INT_P (x))
5f59ecb7 7625 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
7626 else
7627 print_operand (file, x, 0);
7628 return;
7629
9854d9ed
RK
7630 case 'I':
7631 /* Print `i' if this is a constant, else nothing. */
9878760c 7632 if (INT_P (x))
76229ac8 7633 putc ('i', file);
9878760c
RK
7634 return;
7635
9854d9ed
RK
7636 case 'j':
7637 /* Write the bit number in CCR for jump. */
7638 i = ccr_bit (x, 0);
7639 if (i == -1)
7640 output_operand_lossage ("invalid %%j code");
9878760c 7641 else
9854d9ed 7642 fprintf (file, "%d", i);
9878760c
RK
7643 return;
7644
9854d9ed
RK
7645 case 'J':
7646 /* Similar, but add one for shift count in rlinm for scc and pass
7647 scc flag to `ccr_bit'. */
7648 i = ccr_bit (x, 1);
7649 if (i == -1)
7650 output_operand_lossage ("invalid %%J code");
7651 else
a0466a68
RK
7652 /* If we want bit 31, write a shift count of zero, not 32. */
7653 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
7654 return;
7655
9854d9ed
RK
7656 case 'k':
7657 /* X must be a constant. Write the 1's complement of the
7658 constant. */
9878760c 7659 if (! INT_P (x))
9854d9ed 7660 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
7661 else
7662 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
7663 return;
7664
81eace42 7665 case 'K':
9ebbca7d
GK
7666 /* X must be a symbolic constant on ELF. Write an
7667 expression suitable for an 'addi' that adds in the low 16
7668 bits of the MEM. */
7669 if (GET_CODE (x) != CONST)
7670 {
7671 print_operand_address (file, x);
7672 fputs ("@l", file);
7673 }
7674 else
7675 {
7676 if (GET_CODE (XEXP (x, 0)) != PLUS
7677 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
7678 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
7679 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 7680 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
7681 print_operand_address (file, XEXP (XEXP (x, 0), 0));
7682 fputs ("@l", file);
ed8d2920
MM
7683 /* For GNU as, there must be a non-alphanumeric character
7684 between 'l' and the number. The '-' is added by
7685 print_operand() already. */
7686 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
7687 fputs ("+", file);
9ebbca7d
GK
7688 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
7689 }
81eace42
GK
7690 return;
7691
7692 /* %l is output_asm_label. */
9ebbca7d 7693
9854d9ed
RK
7694 case 'L':
7695 /* Write second word of DImode or DFmode reference. Works on register
7696 or non-indexed memory only. */
7697 if (GET_CODE (x) == REG)
5ebfb2ba 7698 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
7699 else if (GET_CODE (x) == MEM)
7700 {
7701 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 7702 we have already done it, we can just use an offset of word. */
9854d9ed
RK
7703 if (GET_CODE (XEXP (x, 0)) == PRE_INC
7704 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
7705 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
7706 UNITS_PER_WORD));
9854d9ed 7707 else
d7624dc0
RK
7708 output_address (XEXP (adjust_address_nv (x, SImode,
7709 UNITS_PER_WORD),
7710 0));
ed8908e7 7711
ba5e43aa 7712 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
7713 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
7714 reg_names[SMALL_DATA_REG]);
9854d9ed 7715 }
9878760c 7716 return;
9854d9ed 7717
9878760c
RK
7718 case 'm':
7719 /* MB value for a mask operand. */
b1765bde 7720 if (! mask_operand (x, SImode))
9878760c
RK
7721 output_operand_lossage ("invalid %%m value");
7722
0ba1b2ff 7723 fprintf (file, "%d", extract_MB (x));
9878760c
RK
7724 return;
7725
7726 case 'M':
7727 /* ME value for a mask operand. */
b1765bde 7728 if (! mask_operand (x, SImode))
a260abc9 7729 output_operand_lossage ("invalid %%M value");
9878760c 7730
0ba1b2ff 7731 fprintf (file, "%d", extract_ME (x));
9878760c
RK
7732 return;
7733
81eace42
GK
7734 /* %n outputs the negative of its operand. */
7735
9878760c
RK
7736 case 'N':
7737 /* Write the number of elements in the vector times 4. */
7738 if (GET_CODE (x) != PARALLEL)
7739 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
7740 else
7741 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
7742 return;
7743
7744 case 'O':
7745 /* Similar, but subtract 1 first. */
7746 if (GET_CODE (x) != PARALLEL)
1427100a 7747 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
7748 else
7749 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
7750 return;
7751
9854d9ed
RK
7752 case 'p':
7753 /* X is a CONST_INT that is a power of two. Output the logarithm. */
7754 if (! INT_P (x)
2bfcf297 7755 || INT_LOWPART (x) < 0
9854d9ed
RK
7756 || (i = exact_log2 (INT_LOWPART (x))) < 0)
7757 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
7758 else
7759 fprintf (file, "%d", i);
9854d9ed
RK
7760 return;
7761
9878760c
RK
7762 case 'P':
7763 /* The operand must be an indirect memory reference. The result
a4f6c312 7764 is the register number. */
9878760c
RK
7765 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
7766 || REGNO (XEXP (x, 0)) >= 32)
7767 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
7768 else
7769 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
7770 return;
7771
dfbdccdb
GK
7772 case 'q':
7773 /* This outputs the logical code corresponding to a boolean
7774 expression. The expression may have one or both operands
39a10a29
GK
7775 negated (if one, only the first one). For condition register
7776 logical operations, it will also treat the negated
7777 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 7778 {
63bc1d05 7779 const char *const *t = 0;
dfbdccdb
GK
7780 const char *s;
7781 enum rtx_code code = GET_CODE (x);
7782 static const char * const tbl[3][3] = {
7783 { "and", "andc", "nor" },
7784 { "or", "orc", "nand" },
7785 { "xor", "eqv", "xor" } };
7786
7787 if (code == AND)
7788 t = tbl[0];
7789 else if (code == IOR)
7790 t = tbl[1];
7791 else if (code == XOR)
7792 t = tbl[2];
7793 else
7794 output_operand_lossage ("invalid %%q value");
7795
7796 if (GET_CODE (XEXP (x, 0)) != NOT)
7797 s = t[0];
7798 else
7799 {
7800 if (GET_CODE (XEXP (x, 1)) == NOT)
7801 s = t[2];
7802 else
7803 s = t[1];
7804 }
7805
7806 fputs (s, file);
7807 }
7808 return;
7809
9854d9ed
RK
7810 case 'R':
7811 /* X is a CR register. Print the mask for `mtcrf'. */
7812 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7813 output_operand_lossage ("invalid %%R value");
7814 else
9ebbca7d 7815 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 7816 return;
9854d9ed
RK
7817
7818 case 's':
7819 /* Low 5 bits of 32 - value */
7820 if (! INT_P (x))
7821 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
7822 else
7823 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 7824 return;
9854d9ed 7825
a260abc9 7826 case 'S':
0ba1b2ff 7827 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
7828 CONST_INT 32-bit mask is considered sign-extended so any
7829 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 7830 if (! mask64_operand (x, DImode))
a260abc9
DE
7831 output_operand_lossage ("invalid %%S value");
7832
0ba1b2ff 7833 uval = INT_LOWPART (x);
a260abc9 7834
0ba1b2ff 7835 if (uval & 1) /* Clear Left */
a260abc9 7836 {
f099d360
GK
7837#if HOST_BITS_PER_WIDE_INT > 64
7838 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
7839#endif
0ba1b2ff 7840 i = 64;
a260abc9 7841 }
0ba1b2ff 7842 else /* Clear Right */
a260abc9 7843 {
0ba1b2ff 7844 uval = ~uval;
f099d360
GK
7845#if HOST_BITS_PER_WIDE_INT > 64
7846 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
7847#endif
0ba1b2ff 7848 i = 63;
a260abc9 7849 }
0ba1b2ff
AM
7850 while (uval != 0)
7851 --i, uval >>= 1;
7852 if (i < 0)
7853 abort ();
7854 fprintf (file, "%d", i);
7855 return;
a260abc9 7856
a3170dc6
AH
7857 case 't':
7858 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
7859 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
7860 abort ();
7861
7862 /* Bit 3 is OV bit. */
7863 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
7864
7865 /* If we want bit 31, write a shift count of zero, not 32. */
7866 fprintf (file, "%d", i == 31 ? 0 : i + 1);
7867 return;
7868
cccf3bdc
DE
7869 case 'T':
7870 /* Print the symbolic name of a branch target register. */
7871 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
7872 && REGNO (x) != COUNT_REGISTER_REGNUM))
7873 output_operand_lossage ("invalid %%T value");
e2c953b6 7874 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
7875 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
7876 else
7877 fputs ("ctr", file);
7878 return;
7879
9854d9ed 7880 case 'u':
802a0058 7881 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
7882 if (! INT_P (x))
7883 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
7884 else
7885 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
7886 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
7887 return;
7888
802a0058
MM
7889 case 'v':
7890 /* High-order 16 bits of constant for use in signed operand. */
7891 if (! INT_P (x))
7892 output_operand_lossage ("invalid %%v value");
e2c953b6 7893 else
134c32f6
DE
7894 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
7895 (INT_LOWPART (x) >> 16) & 0xffff);
7896 return;
802a0058 7897
9854d9ed
RK
7898 case 'U':
7899 /* Print `u' if this has an auto-increment or auto-decrement. */
7900 if (GET_CODE (x) == MEM
7901 && (GET_CODE (XEXP (x, 0)) == PRE_INC
7902 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 7903 putc ('u', file);
9854d9ed 7904 return;
9878760c 7905
e0cd0770
JC
7906 case 'V':
7907 /* Print the trap code for this operand. */
7908 switch (GET_CODE (x))
7909 {
7910 case EQ:
7911 fputs ("eq", file); /* 4 */
7912 break;
7913 case NE:
7914 fputs ("ne", file); /* 24 */
7915 break;
7916 case LT:
7917 fputs ("lt", file); /* 16 */
7918 break;
7919 case LE:
7920 fputs ("le", file); /* 20 */
7921 break;
7922 case GT:
7923 fputs ("gt", file); /* 8 */
7924 break;
7925 case GE:
7926 fputs ("ge", file); /* 12 */
7927 break;
7928 case LTU:
7929 fputs ("llt", file); /* 2 */
7930 break;
7931 case LEU:
7932 fputs ("lle", file); /* 6 */
7933 break;
7934 case GTU:
7935 fputs ("lgt", file); /* 1 */
7936 break;
7937 case GEU:
7938 fputs ("lge", file); /* 5 */
7939 break;
7940 default:
7941 abort ();
7942 }
7943 break;
7944
9854d9ed
RK
7945 case 'w':
7946 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
7947 normally. */
7948 if (INT_P (x))
5f59ecb7
DE
7949 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
7950 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
7951 else
7952 print_operand (file, x, 0);
9878760c
RK
7953 return;
7954
9854d9ed 7955 case 'W':
e2c953b6 7956 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
7957 val = (GET_CODE (x) == CONST_INT
7958 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
7959
7960 if (val < 0)
7961 i = -1;
9854d9ed 7962 else
e2c953b6
DE
7963 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
7964 if ((val <<= 1) < 0)
7965 break;
7966
7967#if HOST_BITS_PER_WIDE_INT == 32
7968 if (GET_CODE (x) == CONST_INT && i >= 0)
7969 i += 32; /* zero-extend high-part was all 0's */
7970 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
7971 {
7972 val = CONST_DOUBLE_LOW (x);
7973
7974 if (val == 0)
a4f6c312 7975 abort ();
e2c953b6
DE
7976 else if (val < 0)
7977 --i;
7978 else
7979 for ( ; i < 64; i++)
7980 if ((val <<= 1) < 0)
7981 break;
7982 }
7983#endif
7984
7985 fprintf (file, "%d", i + 1);
9854d9ed 7986 return;
9878760c 7987
9854d9ed
RK
7988 case 'X':
7989 if (GET_CODE (x) == MEM
258bfae2 7990 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0), 0))
76229ac8 7991 putc ('x', file);
9854d9ed 7992 return;
9878760c 7993
9854d9ed
RK
7994 case 'Y':
7995 /* Like 'L', for third word of TImode */
7996 if (GET_CODE (x) == REG)
5ebfb2ba 7997 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 7998 else if (GET_CODE (x) == MEM)
9878760c 7999 {
9854d9ed
RK
8000 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8001 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8002 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 8003 else
d7624dc0 8004 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 8005 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8006 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8007 reg_names[SMALL_DATA_REG]);
9878760c
RK
8008 }
8009 return;
9854d9ed 8010
9878760c 8011 case 'z':
b4ac57ab
RS
8012 /* X is a SYMBOL_REF. Write out the name preceded by a
8013 period and without any trailing data in brackets. Used for function
4d30c363
MM
8014 names. If we are configured for System V (or the embedded ABI) on
8015 the PowerPC, do not emit the period, since those systems do not use
8016 TOCs and the like. */
9878760c
RK
8017 if (GET_CODE (x) != SYMBOL_REF)
8018 abort ();
8019
b6c9286a
MM
8020 if (XSTR (x, 0)[0] != '.')
8021 {
8022 switch (DEFAULT_ABI)
8023 {
8024 default:
8025 abort ();
8026
8027 case ABI_AIX:
8028 putc ('.', file);
8029 break;
8030
8031 case ABI_V4:
8032 case ABI_AIX_NODESC:
ee890fe2 8033 case ABI_DARWIN:
b6c9286a 8034 break;
b6c9286a
MM
8035 }
8036 }
54ee9799
DE
8037#if TARGET_AIX
8038 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
8039#else
9ebbca7d 8040 assemble_name (file, XSTR (x, 0));
54ee9799 8041#endif
9878760c
RK
8042 return;
8043
9854d9ed
RK
8044 case 'Z':
8045 /* Like 'L', for last word of TImode. */
8046 if (GET_CODE (x) == REG)
5ebfb2ba 8047 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
8048 else if (GET_CODE (x) == MEM)
8049 {
8050 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8051 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8052 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 8053 else
d7624dc0 8054 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 8055 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8056 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8057 reg_names[SMALL_DATA_REG]);
9854d9ed 8058 }
5c23c401 8059 return;
0ac081f6 8060
a3170dc6 8061 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
8062 case 'y':
8063 {
8064 rtx tmp;
8065
8066 if (GET_CODE (x) != MEM)
8067 abort ();
8068
8069 tmp = XEXP (x, 0);
8070
a3170dc6
AH
8071 if (TARGET_SPE)
8072 {
8073 /* Handle [reg]. */
8074 if (GET_CODE (tmp) == REG)
8075 {
8076 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
8077 break;
8078 }
8079 /* Handle [reg+UIMM]. */
8080 else if (GET_CODE (tmp) == PLUS &&
8081 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
8082 {
8083 int x;
8084
8085 if (GET_CODE (XEXP (tmp, 0)) != REG)
8086 abort ();
8087
8088 x = INTVAL (XEXP (tmp, 1));
8089 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
8090 break;
8091 }
8092
8093 /* Fall through. Must be [reg+reg]. */
8094 }
0ac081f6 8095 if (GET_CODE (tmp) == REG)
c62f2db5 8096 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
8097 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
8098 {
8099 if (REGNO (XEXP (tmp, 0)) == 0)
8100 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
8101 reg_names[ REGNO (XEXP (tmp, 0)) ]);
8102 else
8103 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
8104 reg_names[ REGNO (XEXP (tmp, 1)) ]);
8105 }
8106 else
8107 abort ();
8108 break;
8109 }
9854d9ed 8110
9878760c
RK
8111 case 0:
8112 if (GET_CODE (x) == REG)
8113 fprintf (file, "%s", reg_names[REGNO (x)]);
8114 else if (GET_CODE (x) == MEM)
8115 {
8116 /* We need to handle PRE_INC and PRE_DEC here, since we need to
8117 know the width from the mode. */
8118 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
8119 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
8120 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8121 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
8122 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
8123 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8124 else
a54d04b7 8125 output_address (XEXP (x, 0));
9878760c
RK
8126 }
8127 else
a54d04b7 8128 output_addr_const (file, x);
a85d226b 8129 return;
9878760c
RK
8130
8131 default:
8132 output_operand_lossage ("invalid %%xn code");
8133 }
8134}
8135\f
8136/* Print the address of an operand. */
8137
8138void
8139print_operand_address (file, x)
8140 FILE *file;
592696dd 8141 rtx x;
9878760c
RK
8142{
8143 if (GET_CODE (x) == REG)
4697a36c 8144 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
8145 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
8146 || GET_CODE (x) == LABEL_REF)
9878760c
RK
8147 {
8148 output_addr_const (file, x);
ba5e43aa 8149 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8150 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8151 reg_names[SMALL_DATA_REG]);
9ebbca7d 8152 else if (TARGET_TOC)
a4f6c312 8153 abort ();
9878760c
RK
8154 }
8155 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
8156 {
8157 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
8158 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
8159 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 8160 else
4697a36c
MM
8161 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
8162 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
8163 }
8164 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
5f59ecb7
DE
8165 {
8166 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
8167 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8168 }
3cb999d8
DE
8169#if TARGET_ELF
8170 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8171 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
8172 {
8173 output_addr_const (file, XEXP (x, 1));
8174 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8175 }
c859cda6
DJ
8176#endif
8177#if TARGET_MACHO
8178 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8179 && CONSTANT_P (XEXP (x, 1)))
8180 {
8181 fprintf (file, "lo16(");
8182 output_addr_const (file, XEXP (x, 1));
8183 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8184 }
3cb999d8 8185#endif
9ebbca7d
GK
8186 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
8187 {
2bfcf297 8188 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 8189 {
2bfcf297
DB
8190 rtx contains_minus = XEXP (x, 1);
8191 rtx minus, symref;
8192 const char *name;
9ebbca7d
GK
8193
8194 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 8195 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
8196 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
8197 contains_minus = XEXP (contains_minus, 0);
8198
2bfcf297
DB
8199 minus = XEXP (contains_minus, 0);
8200 symref = XEXP (minus, 0);
8201 XEXP (contains_minus, 0) = symref;
8202 if (TARGET_ELF)
8203 {
8204 char *newname;
8205
8206 name = XSTR (symref, 0);
8207 newname = alloca (strlen (name) + sizeof ("@toc"));
8208 strcpy (newname, name);
8209 strcat (newname, "@toc");
8210 XSTR (symref, 0) = newname;
8211 }
8212 output_addr_const (file, XEXP (x, 1));
8213 if (TARGET_ELF)
8214 XSTR (symref, 0) = name;
9ebbca7d
GK
8215 XEXP (contains_minus, 0) = minus;
8216 }
8217 else
8218 output_addr_const (file, XEXP (x, 1));
8219
8220 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
8221 }
9878760c
RK
8222 else
8223 abort ();
8224}
8225\f
88cad84b 8226/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
8227 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
8228 is defined. It also needs to handle DI-mode objects on 64-bit
8229 targets. */
8230
8231static bool
8232rs6000_assemble_integer (x, size, aligned_p)
8233 rtx x;
8234 unsigned int size;
8235 int aligned_p;
8236{
8237#ifdef RELOCATABLE_NEEDS_FIXUP
8238 /* Special handling for SI values. */
8239 if (size == 4 && aligned_p)
8240 {
8241 extern int in_toc_section PARAMS ((void));
8242 static int recurse = 0;
8243
8244 /* For -mrelocatable, we mark all addresses that need to be fixed up
8245 in the .fixup section. */
8246 if (TARGET_RELOCATABLE
8247 && !in_toc_section ()
8248 && !in_text_section ()
8249 && !recurse
8250 && GET_CODE (x) != CONST_INT
8251 && GET_CODE (x) != CONST_DOUBLE
8252 && CONSTANT_P (x))
8253 {
8254 char buf[256];
8255
8256 recurse = 1;
8257 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
8258 fixuplabelno++;
8259 ASM_OUTPUT_LABEL (asm_out_file, buf);
8260 fprintf (asm_out_file, "\t.long\t(");
8261 output_addr_const (asm_out_file, x);
8262 fprintf (asm_out_file, ")@fixup\n");
8263 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
8264 ASM_OUTPUT_ALIGN (asm_out_file, 2);
8265 fprintf (asm_out_file, "\t.long\t");
8266 assemble_name (asm_out_file, buf);
8267 fprintf (asm_out_file, "\n\t.previous\n");
8268 recurse = 0;
8269 return true;
8270 }
8271 /* Remove initial .'s to turn a -mcall-aixdesc function
8272 address into the address of the descriptor, not the function
8273 itself. */
8274 else if (GET_CODE (x) == SYMBOL_REF
8275 && XSTR (x, 0)[0] == '.'
8276 && DEFAULT_ABI == ABI_AIX)
8277 {
8278 const char *name = XSTR (x, 0);
8279 while (*name == '.')
8280 name++;
8281
8282 fprintf (asm_out_file, "\t.long\t%s\n", name);
8283 return true;
8284 }
8285 }
8286#endif /* RELOCATABLE_NEEDS_FIXUP */
8287 return default_assemble_integer (x, size, aligned_p);
8288}
93638d7a
AM
8289
8290#ifdef HAVE_GAS_HIDDEN
8291/* Emit an assembler directive to set symbol visibility for DECL to
8292 VISIBILITY_TYPE. */
8293
5add3202 8294static void
25fdb4dc 8295rs6000_assemble_visibility (decl, vis)
93638d7a 8296 tree decl;
25fdb4dc 8297 int vis;
93638d7a 8298{
93638d7a
AM
8299 /* Functions need to have their entry point symbol visibility set as
8300 well as their descriptor symbol visibility. */
8301 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
8302 {
25fdb4dc
RH
8303 static const char * const visibility_types[] = {
8304 NULL, "internal", "hidden", "protected"
8305 };
8306
8307 const char *name, *type;
93638d7a
AM
8308
8309 name = ((* targetm.strip_name_encoding)
8310 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 8311 type = visibility_types[vis];
93638d7a 8312
25fdb4dc
RH
8313 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
8314 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 8315 }
25fdb4dc
RH
8316 else
8317 default_assemble_visibility (decl, vis);
93638d7a
AM
8318}
8319#endif
301d03af 8320\f
39a10a29
GK
8321enum rtx_code
8322rs6000_reverse_condition (mode, code)
8323 enum machine_mode mode;
8324 enum rtx_code code;
8325{
8326 /* Reversal of FP compares takes care -- an ordered compare
8327 becomes an unordered compare and vice versa. */
de40e1df 8328 if (mode == CCFPmode && !flag_unsafe_math_optimizations)
bab6226b 8329 return reverse_condition_maybe_unordered (code);
39a10a29 8330 else
bab6226b 8331 return reverse_condition (code);
39a10a29
GK
8332}
8333
39a10a29
GK
8334/* Generate a compare for CODE. Return a brand-new rtx that
8335 represents the result of the compare. */
a4f6c312 8336
39a10a29
GK
8337static rtx
8338rs6000_generate_compare (code)
8339 enum rtx_code code;
8340{
8341 enum machine_mode comp_mode;
8342 rtx compare_result;
8343
8344 if (rs6000_compare_fp_p)
8345 comp_mode = CCFPmode;
8346 else if (code == GTU || code == LTU
8347 || code == GEU || code == LEU)
8348 comp_mode = CCUNSmode;
8349 else
8350 comp_mode = CCmode;
8351
8352 /* First, the compare. */
8353 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
8354
8355 /* SPE FP compare instructions on the GPRs. Yuck! */
8356 if ((TARGET_SPE && TARGET_HARD_FLOAT) && rs6000_compare_fp_p)
8357 {
8358 rtx cmp, or1, or2, or_result, compare_result2;
8359
8360 switch (code)
8361 {
8362 case EQ:
8363 case UNEQ:
8364 case NE:
8365 case LTGT:
8366 cmp = flag_unsafe_math_optimizations
8367 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
8368 rs6000_compare_op1)
8369 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
8370 rs6000_compare_op1);
8371 break;
8372 case GT:
8373 case GTU:
8374 case UNGT:
8375 case UNGE:
8376 case GE:
8377 case GEU:
8378 cmp = flag_unsafe_math_optimizations
8379 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
8380 rs6000_compare_op1)
8381 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
8382 rs6000_compare_op1);
8383 break;
8384 case LT:
8385 case LTU:
8386 case UNLT:
8387 case UNLE:
8388 case LE:
8389 case LEU:
8390 cmp = flag_unsafe_math_optimizations
8391 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
8392 rs6000_compare_op1)
8393 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
8394 rs6000_compare_op1);
8395 break;
8396 default:
8397 abort ();
8398 }
8399
8400 /* Synthesize LE and GE from LT/GT || EQ. */
8401 if (code == LE || code == GE || code == LEU || code == GEU)
8402 {
8403 /* Synthesize GE/LE frome GT/LT || EQ. */
8404
8405 emit_insn (cmp);
8406
8407 switch (code)
8408 {
8409 case LE: code = LT; break;
8410 case GE: code = GT; break;
8411 case LEU: code = LT; break;
8412 case GEU: code = GT; break;
8413 default: abort ();
8414 }
8415
8416 or1 = gen_reg_rtx (SImode);
8417 or2 = gen_reg_rtx (SImode);
8418 or_result = gen_reg_rtx (CCEQmode);
8419 compare_result2 = gen_reg_rtx (CCFPmode);
8420
8421 /* Do the EQ. */
8422 cmp = flag_unsafe_math_optimizations
8423 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
8424 rs6000_compare_op1)
8425 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
8426 rs6000_compare_op1);
8427 emit_insn (cmp);
8428
8429 /* The MC8540 FP compare instructions set the CR bits
8430 differently than other PPC compare instructions. For
8431 that matter, there is no generic test instruction, but a
8432 testgt, testlt, and testeq. For a true condition, bit 2
8433 is set (x1xx) in the CR. Following the traditional CR
8434 values:
8435
8436 LT GT EQ OV
8437 bit3 bit2 bit1 bit0
8438
8439 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 8440 look in the GT bits for the branch instructions.
a3170dc6
AH
8441 However, we must be careful to emit correct RTL in
8442 the meantime, so optimizations don't get confused. */
8443
8444 or1 = gen_rtx (NE, SImode, compare_result, const0_rtx);
8445 or2 = gen_rtx (NE, SImode, compare_result2, const0_rtx);
8446
8447 /* OR them together. */
8448 cmp = gen_rtx_SET (VOIDmode, or_result,
8449 gen_rtx_COMPARE (CCEQmode,
8450 gen_rtx_IOR (SImode, or1, or2),
8451 const_true_rtx));
8452 compare_result = or_result;
8453 code = EQ;
8454 }
8455 else
8456 {
8457 /* We only care about 1 bit (x1xx), so map everything to NE to
8458 maintain rtl sanity. We'll get to the right bit (x1xx) at
8459 code output time. */
8460 if (code == NE || code == LTGT)
8461 /* Do the inverse here because we have no cmpne
8462 instruction. We use the cmpeq instruction and expect
8463 to get a 0 instead. */
8464 code = EQ;
8465 else
8466 code = NE;
8467 }
8468
8469 emit_insn (cmp);
8470 }
8471 else
8472 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
8473 gen_rtx_COMPARE (comp_mode,
8474 rs6000_compare_op0,
8475 rs6000_compare_op1)));
39a10a29 8476
ca5adc63 8477 /* Some kinds of FP comparisons need an OR operation;
de6c5979 8478 except for flag_unsafe_math_optimizations we don't bother. */
39a10a29 8479 if (rs6000_compare_fp_p
de6c5979 8480 && ! flag_unsafe_math_optimizations
a3170dc6 8481 && ! (TARGET_HARD_FLOAT && TARGET_SPE)
39a10a29
GK
8482 && (code == LE || code == GE
8483 || code == UNEQ || code == LTGT
8484 || code == UNGT || code == UNLT))
8485 {
8486 enum rtx_code or1, or2;
8487 rtx or1_rtx, or2_rtx, compare2_rtx;
8488 rtx or_result = gen_reg_rtx (CCEQmode);
8489
8490 switch (code)
8491 {
8492 case LE: or1 = LT; or2 = EQ; break;
8493 case GE: or1 = GT; or2 = EQ; break;
8494 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
8495 case LTGT: or1 = LT; or2 = GT; break;
8496 case UNGT: or1 = UNORDERED; or2 = GT; break;
8497 case UNLT: or1 = UNORDERED; or2 = LT; break;
8498 default: abort ();
8499 }
8500 validate_condition_mode (or1, comp_mode);
8501 validate_condition_mode (or2, comp_mode);
8502 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
8503 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
8504 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
8505 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
8506 const_true_rtx);
8507 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
8508
8509 compare_result = or_result;
8510 code = EQ;
8511 }
8512
8513 validate_condition_mode (code, GET_MODE (compare_result));
8514
8515 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
8516}
8517
8518
8519/* Emit the RTL for an sCOND pattern. */
8520
8521void
8522rs6000_emit_sCOND (code, result)
8523 enum rtx_code code;
8524 rtx result;
8525{
8526 rtx condition_rtx;
8527 enum machine_mode op_mode;
8528
8529 condition_rtx = rs6000_generate_compare (code);
8530
8531 op_mode = GET_MODE (rs6000_compare_op0);
8532 if (op_mode == VOIDmode)
8533 op_mode = GET_MODE (rs6000_compare_op1);
8534
8535 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
8536 {
8537 PUT_MODE (condition_rtx, DImode);
8538 convert_move (result, condition_rtx, 0);
8539 }
8540 else
8541 {
8542 PUT_MODE (condition_rtx, SImode);
8543 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
8544 }
8545}
8546
39a10a29
GK
8547/* Emit a branch of kind CODE to location LOC. */
8548
8549void
8550rs6000_emit_cbranch (code, loc)
8551 enum rtx_code code;
8552 rtx loc;
8553{
8554 rtx condition_rtx, loc_ref;
8555
8556 condition_rtx = rs6000_generate_compare (code);
8557 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
8558 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
8559 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
8560 loc_ref, pc_rtx)));
8561}
8562
12a4e8c5
GK
8563/* Return the string to output a conditional branch to LABEL, which is
8564 the operand number of the label, or -1 if the branch is really a
8565 conditional return.
8566
8567 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
8568 condition code register and its mode specifies what kind of
8569 comparison we made.
8570
a0ab749a 8571 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
8572
8573 INSN is the insn. */
8574
8575char *
8576output_cbranch (op, label, reversed, insn)
8577 rtx op;
8578 const char * label;
8579 int reversed;
8580 rtx insn;
8581{
8582 static char string[64];
8583 enum rtx_code code = GET_CODE (op);
8584 rtx cc_reg = XEXP (op, 0);
8585 enum machine_mode mode = GET_MODE (cc_reg);
8586 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 8587 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
8588 int really_reversed = reversed ^ need_longbranch;
8589 char *s = string;
8590 const char *ccode;
8591 const char *pred;
8592 rtx note;
8593
39a10a29
GK
8594 validate_condition_mode (code, mode);
8595
8596 /* Work out which way this really branches. We could use
8597 reverse_condition_maybe_unordered here always but this
8598 makes the resulting assembler clearer. */
12a4e8c5 8599 if (really_reversed)
de40e1df
DJ
8600 {
8601 /* Reversal of FP compares takes care -- an ordered compare
8602 becomes an unordered compare and vice versa. */
8603 if (mode == CCFPmode)
8604 code = reverse_condition_maybe_unordered (code);
8605 else
8606 code = reverse_condition (code);
8607 }
12a4e8c5 8608
a3170dc6
AH
8609 if ((TARGET_SPE && TARGET_HARD_FLOAT) && mode == CCFPmode)
8610 {
8611 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
8612 to the GT bit. */
8613 if (code == EQ)
8614 /* Opposite of GT. */
8615 code = UNLE;
8616 else if (code == NE)
8617 code = GT;
8618 else
8619 abort ();
8620 }
8621
39a10a29 8622 switch (code)
12a4e8c5
GK
8623 {
8624 /* Not all of these are actually distinct opcodes, but
8625 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
8626 case NE: case LTGT:
8627 ccode = "ne"; break;
8628 case EQ: case UNEQ:
8629 ccode = "eq"; break;
8630 case GE: case GEU:
8631 ccode = "ge"; break;
8632 case GT: case GTU: case UNGT:
8633 ccode = "gt"; break;
8634 case LE: case LEU:
8635 ccode = "le"; break;
8636 case LT: case LTU: case UNLT:
8637 ccode = "lt"; break;
12a4e8c5
GK
8638 case UNORDERED: ccode = "un"; break;
8639 case ORDERED: ccode = "nu"; break;
8640 case UNGE: ccode = "nl"; break;
8641 case UNLE: ccode = "ng"; break;
8642 default:
a4f6c312 8643 abort ();
12a4e8c5
GK
8644 }
8645
94a54f47
GK
8646 /* Maybe we have a guess as to how likely the branch is.
8647 The old mnemonics don't have a way to specify this information. */
f4857b9b 8648 pred = "";
12a4e8c5
GK
8649 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
8650 if (note != NULL_RTX)
8651 {
8652 /* PROB is the difference from 50%. */
8653 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
8654 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
8655
8656 /* Only hint for highly probable/improbable branches on newer
8657 cpus as static prediction overrides processor dynamic
8658 prediction. For older cpus we may as well always hint, but
8659 assume not taken for branches that are very close to 50% as a
8660 mispredicted taken branch is more expensive than a
8661 mispredicted not-taken branch. */
8662 if (always_hint
8663 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
8664 {
8665 if (abs (prob) > REG_BR_PROB_BASE / 20
8666 && ((prob > 0) ^ need_longbranch))
7f3d8013 8667 pred = "+";
f4857b9b
AM
8668 else
8669 pred = "-";
8670 }
12a4e8c5 8671 }
12a4e8c5
GK
8672
8673 if (label == NULL)
94a54f47 8674 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 8675 else
94a54f47 8676 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 8677
37c67319
GK
8678 /* We need to escape any '%' characters in the reg_names string.
8679 Assume they'd only be the first character... */
8680 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
8681 *s++ = '%';
94a54f47 8682 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
8683
8684 if (label != NULL)
8685 {
8686 /* If the branch distance was too far, we may have to use an
8687 unconditional branch to go the distance. */
8688 if (need_longbranch)
44518ddd 8689 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
8690 else
8691 s += sprintf (s, ",%s", label);
8692 }
8693
8694 return string;
8695}
50a0b056
GK
8696
8697/* Emit a conditional move: move TRUE_COND to DEST if OP of the
8698 operands of the last comparison is nonzero/true, FALSE_COND if it
8699 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 8700
50a0b056
GK
8701int
8702rs6000_emit_cmove (dest, op, true_cond, false_cond)
8703 rtx dest;
8704 rtx op;
8705 rtx true_cond;
8706 rtx false_cond;
8707{
8708 enum rtx_code code = GET_CODE (op);
8709 rtx op0 = rs6000_compare_op0;
8710 rtx op1 = rs6000_compare_op1;
8711 REAL_VALUE_TYPE c1;
3148ad6d
DJ
8712 enum machine_mode compare_mode = GET_MODE (op0);
8713 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
8714 rtx temp;
8715
3148ad6d 8716 /* These modes should always match. */
a3170dc6
AH
8717 if (GET_MODE (op1) != compare_mode
8718 /* In the isel case however, we can use a compare immediate, so
8719 op1 may be a small constant. */
8720 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 8721 return 0;
178c3eff 8722 if (GET_MODE (true_cond) != result_mode)
3148ad6d 8723 return 0;
178c3eff 8724 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
8725 return 0;
8726
50a0b056
GK
8727 /* First, work out if the hardware can do this at all, or
8728 if it's too slow... */
50a0b056 8729 if (! rs6000_compare_fp_p)
a3170dc6
AH
8730 {
8731 if (TARGET_ISEL)
8732 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
8733 return 0;
8734 }
50a0b056
GK
8735
8736 /* Eliminate half of the comparisons by switching operands, this
8737 makes the remaining code simpler. */
8738 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
8739 || code == LTGT || code == LT)
8740 {
8741 code = reverse_condition_maybe_unordered (code);
8742 temp = true_cond;
8743 true_cond = false_cond;
8744 false_cond = temp;
8745 }
8746
8747 /* UNEQ and LTGT take four instructions for a comparison with zero,
8748 it'll probably be faster to use a branch here too. */
8749 if (code == UNEQ)
8750 return 0;
8751
8752 if (GET_CODE (op1) == CONST_DOUBLE)
8753 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
8754
b6d08ca1 8755 /* We're going to try to implement comparisons by performing
50a0b056
GK
8756 a subtract, then comparing against zero. Unfortunately,
8757 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 8758 know that the operand is finite and the comparison
50a0b056
GK
8759 would treat EQ different to UNORDERED, we can't do it. */
8760 if (! flag_unsafe_math_optimizations
8761 && code != GT && code != UNGE
045572c7 8762 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
8763 /* Constructs of the form (a OP b ? a : b) are safe. */
8764 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
8765 || (! rtx_equal_p (op0, true_cond)
8766 && ! rtx_equal_p (op1, true_cond))))
8767 return 0;
8768 /* At this point we know we can use fsel. */
8769
8770 /* Reduce the comparison to a comparison against zero. */
3148ad6d 8771 temp = gen_reg_rtx (compare_mode);
50a0b056 8772 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8773 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 8774 op0 = temp;
3148ad6d 8775 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
8776
8777 /* If we don't care about NaNs we can reduce some of the comparisons
8778 down to faster ones. */
8779 if (flag_unsafe_math_optimizations)
8780 switch (code)
8781 {
8782 case GT:
8783 code = LE;
8784 temp = true_cond;
8785 true_cond = false_cond;
8786 false_cond = temp;
8787 break;
8788 case UNGE:
8789 code = GE;
8790 break;
8791 case UNEQ:
8792 code = EQ;
8793 break;
8794 default:
8795 break;
8796 }
8797
8798 /* Now, reduce everything down to a GE. */
8799 switch (code)
8800 {
8801 case GE:
8802 break;
8803
8804 case LE:
3148ad6d
DJ
8805 temp = gen_reg_rtx (compare_mode);
8806 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8807 op0 = temp;
8808 break;
8809
8810 case ORDERED:
3148ad6d
DJ
8811 temp = gen_reg_rtx (compare_mode);
8812 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
8813 op0 = temp;
8814 break;
8815
8816 case EQ:
3148ad6d 8817 temp = gen_reg_rtx (compare_mode);
50a0b056 8818 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
8819 gen_rtx_NEG (compare_mode,
8820 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
8821 op0 = temp;
8822 break;
8823
8824 case UNGE:
3148ad6d 8825 temp = gen_reg_rtx (result_mode);
50a0b056 8826 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8827 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8828 gen_rtx_GE (VOIDmode,
8829 op0, op1),
8830 true_cond, false_cond)));
8831 false_cond = temp;
8832 true_cond = false_cond;
8833
3148ad6d
DJ
8834 temp = gen_reg_rtx (compare_mode);
8835 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8836 op0 = temp;
8837 break;
8838
8839 case GT:
3148ad6d 8840 temp = gen_reg_rtx (result_mode);
50a0b056 8841 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8842 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8843 gen_rtx_GE (VOIDmode,
8844 op0, op1),
8845 true_cond, false_cond)));
8846 true_cond = temp;
8847 false_cond = true_cond;
8848
3148ad6d
DJ
8849 temp = gen_reg_rtx (compare_mode);
8850 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8851 op0 = temp;
8852 break;
8853
8854 default:
8855 abort ();
8856 }
8857
8858 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 8859 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8860 gen_rtx_GE (VOIDmode,
8861 op0, op1),
8862 true_cond, false_cond)));
8863 return 1;
8864}
8865
a3170dc6
AH
8866/* Same as above, but for ints (isel). */
8867
8868static int
8869rs6000_emit_int_cmove (dest, op, true_cond, false_cond)
8870 rtx dest;
8871 rtx op;
8872 rtx true_cond;
8873 rtx false_cond;
8874{
8875 rtx condition_rtx, cr;
8876
8877 /* All isel implementations thus far are 32-bits. */
8878 if (GET_MODE (rs6000_compare_op0) != SImode)
8879 return 0;
8880
8881 /* We still have to do the compare, because isel doesn't do a
8882 compare, it just looks at the CRx bits set by a previous compare
8883 instruction. */
8884 condition_rtx = rs6000_generate_compare (GET_CODE (op));
8885 cr = XEXP (condition_rtx, 0);
8886
8887 if (GET_MODE (cr) == CCmode)
8888 emit_insn (gen_isel_signed (dest, condition_rtx,
8889 true_cond, false_cond, cr));
8890 else
8891 emit_insn (gen_isel_unsigned (dest, condition_rtx,
8892 true_cond, false_cond, cr));
8893
8894 return 1;
8895}
8896
8897const char *
8898output_isel (operands)
8899 rtx *operands;
8900{
8901 enum rtx_code code;
8902
8903 code = GET_CODE (operands[1]);
8904 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
8905 {
8906 PUT_CODE (operands[1], reverse_condition (code));
8907 return "isel %0,%3,%2,%j1";
8908 }
8909 else
8910 return "isel %0,%2,%3,%j1";
8911}
8912
50a0b056
GK
8913void
8914rs6000_emit_minmax (dest, code, op0, op1)
8915 rtx dest;
8916 enum rtx_code code;
8917 rtx op0;
8918 rtx op1;
8919{
8920 enum machine_mode mode = GET_MODE (op0);
5dc8d536 8921 enum rtx_code c;
50a0b056 8922 rtx target;
5dc8d536
AH
8923
8924 if (code == SMAX || code == SMIN)
8925 c = GE;
8926 else
8927 c = GEU;
8928
50a0b056 8929 if (code == SMAX || code == UMAX)
5dc8d536 8930 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
8931 op0, op1, mode, 0);
8932 else
5dc8d536 8933 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
8934 op1, op0, mode, 0);
8935 if (target == NULL_RTX)
8936 abort ();
8937 if (target != dest)
8938 emit_move_insn (dest, target);
8939}
12a4e8c5 8940\f
a4f6c312
SS
8941/* This page contains routines that are used to determine what the
8942 function prologue and epilogue code will do and write them out. */
9878760c 8943
a4f6c312
SS
8944/* Return the first fixed-point register that is required to be
8945 saved. 32 if none. */
9878760c
RK
8946
8947int
8948first_reg_to_save ()
8949{
8950 int first_reg;
8951
8952 /* Find lowest numbered live register. */
8953 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
8954 if (regs_ever_live[first_reg]
8955 && (! call_used_regs[first_reg]
1db02437 8956 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 8957 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 8958 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
8959 break;
8960
ee890fe2 8961#if TARGET_MACHO
93638d7a
AM
8962 if (flag_pic
8963 && current_function_uses_pic_offset_table
8964 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 8965 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
8966#endif
8967
9878760c
RK
8968 return first_reg;
8969}
8970
8971/* Similar, for FP regs. */
8972
8973int
8974first_fp_reg_to_save ()
8975{
8976 int first_reg;
8977
8978 /* Find lowest numbered live register. */
8979 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
8980 if (regs_ever_live[first_reg])
8981 break;
8982
8983 return first_reg;
8984}
00b960c7
AH
8985
8986/* Similar, for AltiVec regs. */
8987
8988static int
8989first_altivec_reg_to_save ()
8990{
8991 int i;
8992
8993 /* Stack frame remains as is unless we are in AltiVec ABI. */
8994 if (! TARGET_ALTIVEC_ABI)
8995 return LAST_ALTIVEC_REGNO + 1;
8996
8997 /* Find lowest numbered live register. */
8998 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
8999 if (regs_ever_live[i])
9000 break;
9001
9002 return i;
9003}
9004
9005/* Return a 32-bit mask of the AltiVec registers we need to set in
9006 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
9007 the 32-bit word is 0. */
9008
9009static unsigned int
9010compute_vrsave_mask ()
9011{
9012 unsigned int i, mask = 0;
9013
9014 /* First, find out if we use _any_ altivec registers. */
9015 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
9016 if (regs_ever_live[i])
9017 mask |= ALTIVEC_REG_BIT (i);
9018
9019 if (mask == 0)
9020 return mask;
9021
9022 /* Next, add all registers that are call-clobbered. We do this
9023 because post-reload register optimizers such as regrename_optimize
9024 may choose to use them. They never change the register class
9025 chosen by reload, so cannot create new uses of altivec registers
9026 if there were none before, so the early exit above is safe. */
9027 /* ??? Alternately, we could define HARD_REGNO_RENAME_OK to disallow
9028 altivec registers not saved in the mask, which might well make the
9029 adjustments below more effective in eliding the save/restore of
9030 VRSAVE in small functions. */
9031 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
9032 if (call_used_regs[i])
9033 mask |= ALTIVEC_REG_BIT (i);
9034
9035 /* Next, remove the argument registers from the set. These must
9036 be in the VRSAVE mask set by the caller, so we don't need to add
9037 them in again. More importantly, the mask we compute here is
9038 used to generate CLOBBERs in the set_vrsave insn, and we do not
9039 wish the argument registers to die. */
9040 for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i)
9041 mask &= ~ALTIVEC_REG_BIT (i);
9042
9043 /* Similarly, remove the return value from the set. */
9044 {
9045 bool yes = false;
9046 diddle_return_value (is_altivec_return_reg, &yes);
9047 if (yes)
9048 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
9049 }
9050
9051 return mask;
9052}
9053
9054static void
9055is_altivec_return_reg (reg, xyes)
9056 rtx reg;
9057 void *xyes;
9058{
9059 bool *yes = (bool *) xyes;
9060 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
9061 *yes = true;
9062}
9063
4697a36c
MM
9064\f
9065/* Calculate the stack information for the current function. This is
9066 complicated by having two separate calling sequences, the AIX calling
9067 sequence and the V.4 calling sequence.
9068
592696dd 9069 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 9070 32-bit 64-bit
4697a36c 9071 SP----> +---------------------------------------+
a260abc9 9072 | back chain to caller | 0 0
4697a36c 9073 +---------------------------------------+
a260abc9 9074 | saved CR | 4 8 (8-11)
4697a36c 9075 +---------------------------------------+
a260abc9 9076 | saved LR | 8 16
4697a36c 9077 +---------------------------------------+
a260abc9 9078 | reserved for compilers | 12 24
4697a36c 9079 +---------------------------------------+
a260abc9 9080 | reserved for binders | 16 32
4697a36c 9081 +---------------------------------------+
a260abc9 9082 | saved TOC pointer | 20 40
4697a36c 9083 +---------------------------------------+
a260abc9 9084 | Parameter save area (P) | 24 48
4697a36c 9085 +---------------------------------------+
a260abc9 9086 | Alloca space (A) | 24+P etc.
802a0058 9087 +---------------------------------------+
a7df97e6 9088 | Local variable space (L) | 24+P+A
4697a36c 9089 +---------------------------------------+
a7df97e6 9090 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 9091 +---------------------------------------+
00b960c7
AH
9092 | Save area for AltiVec registers (W) | 24+P+A+L+X
9093 +---------------------------------------+
9094 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
9095 +---------------------------------------+
9096 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 9097 +---------------------------------------+
00b960c7
AH
9098 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
9099 +---------------------------------------+
9100 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
9101 +---------------------------------------+
9102 old SP->| back chain to caller's caller |
9103 +---------------------------------------+
9104
5376a30c
KR
9105 The required alignment for AIX configurations is two words (i.e., 8
9106 or 16 bytes).
9107
9108
4697a36c
MM
9109 V.4 stack frames look like:
9110
9111 SP----> +---------------------------------------+
9112 | back chain to caller | 0
9113 +---------------------------------------+
5eb387b8 9114 | caller's saved LR | 4
4697a36c
MM
9115 +---------------------------------------+
9116 | Parameter save area (P) | 8
9117 +---------------------------------------+
a7df97e6
MM
9118 | Alloca space (A) | 8+P
9119 +---------------------------------------+
9120 | Varargs save area (V) | 8+P+A
9121 +---------------------------------------+
9122 | Local variable space (L) | 8+P+A+V
9123 +---------------------------------------+
9124 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 9125 +---------------------------------------+
00b960c7
AH
9126 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
9127 +---------------------------------------+
9128 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
9129 +---------------------------------------+
9130 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
9131 +---------------------------------------+
a3170dc6
AH
9132 | SPE: area for 64-bit GP registers |
9133 +---------------------------------------+
9134 | SPE alignment padding |
9135 +---------------------------------------+
00b960c7 9136 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 9137 +---------------------------------------+
00b960c7 9138 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 9139 +---------------------------------------+
00b960c7 9140 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
9141 +---------------------------------------+
9142 old SP->| back chain to caller's caller |
9143 +---------------------------------------+
b6c9286a 9144
5376a30c
KR
9145 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
9146 given. (But note below and in sysv4.h that we require only 8 and
9147 may round up the size of our stack frame anyways. The historical
9148 reason is early versions of powerpc-linux which didn't properly
9149 align the stack at program startup. A happy side-effect is that
9150 -mno-eabi libraries can be used with -meabi programs.)
9151
5376a30c
KR
9152 The EABI configuration defaults to the V.4 layout, unless
9153 -mcall-aix is used, in which case the AIX layout is used. However,
9154 the stack alignment requirements may differ. If -mno-eabi is not
9155 given, the required stack alignment is 8 bytes; if -mno-eabi is
9156 given, the required alignment is 16 bytes. (But see V.4 comment
9157 above.) */
4697a36c 9158
61b2fbe7
MM
9159#ifndef ABI_STACK_BOUNDARY
9160#define ABI_STACK_BOUNDARY STACK_BOUNDARY
9161#endif
9162
4697a36c
MM
9163rs6000_stack_t *
9164rs6000_stack_info ()
9165{
9166 static rs6000_stack_t info, zero_info;
9167 rs6000_stack_t *info_ptr = &info;
9ebbca7d 9168 int reg_size = TARGET_POWERPC64 ? 8 : 4;
24d304eb 9169 enum rs6000_abi abi;
83720594 9170 int ehrd_size;
b6c9286a 9171 int total_raw_size;
c19de7aa 9172 static int insn_chain_scanned = -1;
4697a36c 9173
a4f6c312 9174 /* Zero all fields portably. */
4697a36c
MM
9175 info = zero_info;
9176
c19de7aa
AH
9177 if (TARGET_SPE)
9178 {
9179 /* Cache value so we don't rescan instruction chain over and over. */
9180 if (insn_chain_scanned < 0)
9181 insn_chain_scanned = (int) spe_func_has_64bit_regs_p ();
9182 info_ptr->spe_64bit_regs_used = insn_chain_scanned;
9183 }
9184
a4f6c312 9185 /* Select which calling sequence. */
b6c9286a 9186 info_ptr->abi = abi = DEFAULT_ABI;
9878760c 9187
a4f6c312 9188 /* Calculate which registers need to be saved & save area size. */
4697a36c 9189 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 9190 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 9191 even if it currently looks like we won't. */
2bfcf297 9192 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
f607bc57
ZW
9193 || (flag_pic == 1 && abi == ABI_V4)
9194 || (flag_pic && abi == ABI_DARWIN))
1db02437
FS
9195 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
9196 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
9197 else
9198 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 9199
a3170dc6
AH
9200 /* For the SPE, we have an additional upper 32-bits on each GPR.
9201 Ideally we should save the entire 64-bits only when the upper
9202 half is used in SIMD instructions. Since we only record
9203 registers live (not the size they are used in), this proves
9204 difficult because we'd have to traverse the instruction chain at
9205 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
9206 so we opt to save the GPRs in 64-bits always if but one register
9207 gets used in 64-bits. Otherwise, all the registers in the frame
9208 get saved in 32-bits.
a3170dc6 9209
c19de7aa 9210 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 9211 traditional GP save area will be empty. */
c19de7aa 9212 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9213 info_ptr->gp_size = 0;
9214
4697a36c
MM
9215 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
9216 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
9217
00b960c7
AH
9218 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
9219 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
9220 - info_ptr->first_altivec_reg_save);
9221
592696dd 9222 /* Does this function call anything? */
71f123ca
FS
9223 info_ptr->calls_p = (! current_function_is_leaf
9224 || cfun->machine->ra_needs_full_frame);
b6c9286a 9225
a4f6c312 9226 /* Determine if we need to save the link register. */
71f123ca 9227 if (rs6000_ra_ever_killed ()
70f4f91c 9228 || (DEFAULT_ABI == ABI_AIX && current_function_profile)
4697a36c
MM
9229#ifdef TARGET_RELOCATABLE
9230 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
9231#endif
9232 || (info_ptr->first_fp_reg_save != 64
9233 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 9234 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
24d304eb 9235 || (abi == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
9236 || (DEFAULT_ABI == ABI_DARWIN
9237 && flag_pic
9238 && current_function_uses_pic_offset_table)
4697a36c
MM
9239 || info_ptr->calls_p)
9240 {
9241 info_ptr->lr_save_p = 1;
9ebbca7d 9242 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
9243 }
9244
9ebbca7d
GK
9245 /* Determine if we need to save the condition code registers. */
9246 if (regs_ever_live[CR2_REGNO]
9247 || regs_ever_live[CR3_REGNO]
9248 || regs_ever_live[CR4_REGNO])
4697a36c
MM
9249 {
9250 info_ptr->cr_save_p = 1;
f607bc57 9251 if (abi == ABI_V4)
4697a36c
MM
9252 info_ptr->cr_size = reg_size;
9253 }
9254
83720594
RH
9255 /* If the current function calls __builtin_eh_return, then we need
9256 to allocate stack space for registers that will hold data for
9257 the exception handler. */
9258 if (current_function_calls_eh_return)
9259 {
9260 unsigned int i;
9261 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
9262 continue;
a3170dc6
AH
9263
9264 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
9265 ehrd_size = i * (TARGET_SPE_ABI
9266 && info_ptr->spe_64bit_regs_used != 0
9267 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
9268 }
9269 else
9270 ehrd_size = 0;
9271
592696dd 9272 /* Determine various sizes. */
4697a36c
MM
9273 info_ptr->reg_size = reg_size;
9274 info_ptr->fixed_size = RS6000_SAVE_AREA;
9275 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 9276 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
9277 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
9278 8);
00b960c7 9279
c19de7aa 9280 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9281 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
9282 else
9283 info_ptr->spe_gp_size = 0;
9284
08b57fb3 9285 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE)
00b960c7
AH
9286 {
9287 info_ptr->vrsave_mask = compute_vrsave_mask ();
9288 info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0;
9289 }
9290 else
9291 {
9292 info_ptr->vrsave_mask = 0;
9293 info_ptr->vrsave_size = 0;
9294 }
b6c9286a 9295
592696dd 9296 /* Calculate the offsets. */
24d304eb 9297 switch (abi)
4697a36c 9298 {
b6c9286a 9299 case ABI_NONE:
24d304eb 9300 default:
b6c9286a
MM
9301 abort ();
9302
9303 case ABI_AIX:
9304 case ABI_AIX_NODESC:
ee890fe2 9305 case ABI_DARWIN:
b6c9286a
MM
9306 info_ptr->fp_save_offset = - info_ptr->fp_size;
9307 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
9308
9309 if (TARGET_ALTIVEC_ABI)
9310 {
9311 info_ptr->vrsave_save_offset
9312 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
9313
9314 /* Align stack so vector save area is on a quadword boundary. */
9315 if (info_ptr->altivec_size != 0)
9316 info_ptr->altivec_padding_size
9317 = 16 - (-info_ptr->vrsave_save_offset % 16);
9318 else
9319 info_ptr->altivec_padding_size = 0;
9320
9321 info_ptr->altivec_save_offset
9322 = info_ptr->vrsave_save_offset
9323 - info_ptr->altivec_padding_size
9324 - info_ptr->altivec_size;
9325
9326 /* Adjust for AltiVec case. */
9327 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
9328 }
9329 else
9330 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
9331 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
9332 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
9333 break;
9334
9335 case ABI_V4:
b6c9286a
MM
9336 info_ptr->fp_save_offset = - info_ptr->fp_size;
9337 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 9338 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 9339
c19de7aa 9340 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
9341 {
9342 /* Align stack so SPE GPR save area is aligned on a
9343 double-word boundary. */
9344 if (info_ptr->spe_gp_size != 0)
9345 info_ptr->spe_padding_size
9346 = 8 - (-info_ptr->cr_save_offset % 8);
9347 else
9348 info_ptr->spe_padding_size = 0;
9349
9350 info_ptr->spe_gp_save_offset
9351 = info_ptr->cr_save_offset
9352 - info_ptr->spe_padding_size
9353 - info_ptr->spe_gp_size;
9354
9355 /* Adjust for SPE case. */
9356 info_ptr->toc_save_offset
9357 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
9358 }
9359 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
9360 {
9361 info_ptr->vrsave_save_offset
9362 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
9363
9364 /* Align stack so vector save area is on a quadword boundary. */
9365 if (info_ptr->altivec_size != 0)
9366 info_ptr->altivec_padding_size
9367 = 16 - (-info_ptr->vrsave_save_offset % 16);
9368 else
9369 info_ptr->altivec_padding_size = 0;
9370
9371 info_ptr->altivec_save_offset
9372 = info_ptr->vrsave_save_offset
9373 - info_ptr->altivec_padding_size
9374 - info_ptr->altivec_size;
9375
9376 /* Adjust for AltiVec case. */
9377 info_ptr->toc_save_offset
9378 = info_ptr->altivec_save_offset - info_ptr->toc_size;
9379 }
9380 else
9381 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 9382 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
9383 info_ptr->lr_save_offset = reg_size;
9384 break;
4697a36c
MM
9385 }
9386
00b960c7
AH
9387 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
9388 + info_ptr->gp_size
9389 + info_ptr->altivec_size
9390 + info_ptr->altivec_padding_size
9391 + info_ptr->vrsave_size
a3170dc6
AH
9392 + info_ptr->spe_gp_size
9393 + info_ptr->spe_padding_size
00b960c7
AH
9394 + ehrd_size
9395 + info_ptr->cr_size
9396 + info_ptr->lr_size
9397 + info_ptr->vrsave_size
9398 + info_ptr->toc_size,
9399 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
9400 ? 16 : 8);
9401
ff381587
MM
9402 total_raw_size = (info_ptr->vars_size
9403 + info_ptr->parm_size
ff381587
MM
9404 + info_ptr->save_size
9405 + info_ptr->varargs_size
9406 + info_ptr->fixed_size);
9407
a4f6c312
SS
9408 info_ptr->total_size =
9409 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
9410
9411 /* Determine if we need to allocate any stack frame:
9412
a4f6c312
SS
9413 For AIX we need to push the stack if a frame pointer is needed
9414 (because the stack might be dynamically adjusted), if we are
9415 debugging, if we make calls, or if the sum of fp_save, gp_save,
9416 and local variables are more than the space needed to save all
9417 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
9418 + 18*8 = 288 (GPR13 reserved).
ff381587 9419
a4f6c312
SS
9420 For V.4 we don't have the stack cushion that AIX uses, but assume
9421 that the debugger can handle stackless frames. */
ff381587
MM
9422
9423 if (info_ptr->calls_p)
9424 info_ptr->push_p = 1;
9425
f607bc57 9426 else if (abi == ABI_V4)
e72247f4 9427 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587
MM
9428
9429 else
9430 info_ptr->push_p = (frame_pointer_needed
ee890fe2 9431 || (abi != ABI_DARWIN && write_symbols != NO_DEBUG)
ff381587 9432 || ((total_raw_size - info_ptr->fixed_size)
bfc79d3b 9433 > (TARGET_32BIT ? 220 : 288)));
ff381587 9434
a4f6c312 9435 /* Zero offsets if we're not saving those registers. */
8dda1a21 9436 if (info_ptr->fp_size == 0)
4697a36c
MM
9437 info_ptr->fp_save_offset = 0;
9438
8dda1a21 9439 if (info_ptr->gp_size == 0)
4697a36c
MM
9440 info_ptr->gp_save_offset = 0;
9441
00b960c7
AH
9442 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
9443 info_ptr->altivec_save_offset = 0;
9444
9445 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
9446 info_ptr->vrsave_save_offset = 0;
9447
c19de7aa
AH
9448 if (! TARGET_SPE_ABI
9449 || info_ptr->spe_64bit_regs_used == 0
9450 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
9451 info_ptr->spe_gp_save_offset = 0;
9452
c81fc13e 9453 if (! info_ptr->lr_save_p)
4697a36c
MM
9454 info_ptr->lr_save_offset = 0;
9455
c81fc13e 9456 if (! info_ptr->cr_save_p)
4697a36c
MM
9457 info_ptr->cr_save_offset = 0;
9458
c81fc13e 9459 if (! info_ptr->toc_save_p)
b6c9286a
MM
9460 info_ptr->toc_save_offset = 0;
9461
4697a36c
MM
9462 return info_ptr;
9463}
9464
c19de7aa
AH
9465/* Return true if the current function uses any GPRs in 64-bit SIMD
9466 mode. */
9467
9468static bool
9469spe_func_has_64bit_regs_p ()
9470{
9471 rtx insns, insn;
9472
9473 /* Functions that save and restore all the call-saved registers will
9474 need to save/restore the registers in 64-bits. */
9475 if (current_function_calls_eh_return
9476 || current_function_calls_setjmp
9477 || current_function_has_nonlocal_goto)
9478 return true;
9479
9480 insns = get_insns ();
9481
9482 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
9483 {
9484 if (INSN_P (insn))
9485 {
9486 rtx i;
9487
9488 i = PATTERN (insn);
9489 if (GET_CODE (i) == SET
9490 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
9491 return true;
9492 }
9493 }
9494
9495 return false;
9496}
9497
4697a36c
MM
9498void
9499debug_stack_info (info)
9500 rs6000_stack_t *info;
9878760c 9501{
d330fd93 9502 const char *abi_string;
24d304eb 9503
c81fc13e 9504 if (! info)
4697a36c
MM
9505 info = rs6000_stack_info ();
9506
9507 fprintf (stderr, "\nStack information for function %s:\n",
9508 ((current_function_decl && DECL_NAME (current_function_decl))
9509 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
9510 : "<unknown>"));
9511
24d304eb
RK
9512 switch (info->abi)
9513 {
b6c9286a
MM
9514 default: abi_string = "Unknown"; break;
9515 case ABI_NONE: abi_string = "NONE"; break;
f607bc57 9516 case ABI_AIX:
b6c9286a 9517 case ABI_AIX_NODESC: abi_string = "AIX"; break;
ee890fe2 9518 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 9519 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
9520 }
9521
9522 fprintf (stderr, "\tABI = %5s\n", abi_string);
9523
00b960c7
AH
9524 if (TARGET_ALTIVEC_ABI)
9525 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
9526
a3170dc6
AH
9527 if (TARGET_SPE_ABI)
9528 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
9529
4697a36c
MM
9530 if (info->first_gp_reg_save != 32)
9531 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
9532
9533 if (info->first_fp_reg_save != 64)
9534 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 9535
00b960c7
AH
9536 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
9537 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
9538 info->first_altivec_reg_save);
9539
4697a36c
MM
9540 if (info->lr_save_p)
9541 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 9542
4697a36c
MM
9543 if (info->cr_save_p)
9544 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
9545
b6c9286a
MM
9546 if (info->toc_save_p)
9547 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
9548
00b960c7
AH
9549 if (info->vrsave_mask)
9550 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
9551
4697a36c
MM
9552 if (info->push_p)
9553 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
9554
9555 if (info->calls_p)
9556 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
9557
4697a36c
MM
9558 if (info->gp_save_offset)
9559 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
9560
9561 if (info->fp_save_offset)
9562 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
9563
00b960c7
AH
9564 if (info->altivec_save_offset)
9565 fprintf (stderr, "\taltivec_save_offset = %5d\n",
9566 info->altivec_save_offset);
9567
a3170dc6
AH
9568 if (info->spe_gp_save_offset)
9569 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
9570 info->spe_gp_save_offset);
9571
00b960c7
AH
9572 if (info->vrsave_save_offset)
9573 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
9574 info->vrsave_save_offset);
9575
4697a36c
MM
9576 if (info->lr_save_offset)
9577 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
9578
9579 if (info->cr_save_offset)
9580 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
9581
b6c9286a
MM
9582 if (info->toc_save_offset)
9583 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
9584
4697a36c
MM
9585 if (info->varargs_save_offset)
9586 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
9587
9588 if (info->total_size)
9589 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
9590
9591 if (info->varargs_size)
9592 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
9593
9594 if (info->vars_size)
9595 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
9596
9597 if (info->parm_size)
9598 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
9599
9600 if (info->fixed_size)
9601 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
9602
9603 if (info->gp_size)
9604 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
9605
a3170dc6
AH
9606 if (info->spe_gp_size)
9607 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
9608
4697a36c
MM
9609 if (info->fp_size)
9610 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
9611
00b960c7
AH
9612 if (info->altivec_size)
9613 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
9614
9615 if (info->vrsave_size)
9616 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
9617
9618 if (info->altivec_padding_size)
9619 fprintf (stderr, "\taltivec_padding_size= %5d\n",
9620 info->altivec_padding_size);
9621
a3170dc6
AH
9622 if (info->spe_padding_size)
9623 fprintf (stderr, "\tspe_padding_size = %5d\n",
9624 info->spe_padding_size);
9625
a4f6c312 9626 if (info->lr_size)
ed947a96 9627 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 9628
4697a36c
MM
9629 if (info->cr_size)
9630 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
9631
a4f6c312 9632 if (info->toc_size)
b6c9286a
MM
9633 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
9634
4697a36c
MM
9635 if (info->save_size)
9636 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
9637
9638 if (info->reg_size != 4)
9639 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
9640
9641 fprintf (stderr, "\n");
9878760c 9642}
71f123ca
FS
9643
9644rtx
9645rs6000_return_addr (count, frame)
9646 int count;
9647 rtx frame;
9648{
a4f6c312
SS
9649 /* Currently we don't optimize very well between prolog and body
9650 code and for PIC code the code can be actually quite bad, so
9651 don't try to be too clever here. */
f585a356 9652 if (count != 0 || flag_pic != 0)
71f123ca
FS
9653 {
9654 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
9655
9656 return
9657 gen_rtx_MEM
9658 (Pmode,
9659 memory_address
9660 (Pmode,
9661 plus_constant (copy_to_reg
9662 (gen_rtx_MEM (Pmode,
9663 memory_address (Pmode, frame))),
9664 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
9665 }
9666
9e2f7ec7 9667 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
9668}
9669
5e1bf043
DJ
9670/* Say whether a function is a candidate for sibcall handling or not.
9671 We do not allow indirect calls to be optimized into sibling calls.
9672 Also, we can't do it if there are any vector parameters; there's
9673 nowhere to put the VRsave code so it works; note that functions with
9674 vector parameters are required to have a prototype, so the argument
9675 type info must be available here. (The tail recursion case can work
9676 with vector parameters, but there's no way to distinguish here.) */
4977bab6
ZW
9677static bool
9678rs6000_function_ok_for_sibcall (decl, exp)
9679 tree decl;
9680 tree exp ATTRIBUTE_UNUSED;
5e1bf043
DJ
9681{
9682 tree type;
4977bab6 9683 if (decl)
5e1bf043
DJ
9684 {
9685 if (TARGET_ALTIVEC_VRSAVE)
9686 {
4977bab6 9687 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
9688 type; type = TREE_CHAIN (type))
9689 {
c15b529f 9690 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 9691 return false;
5e1bf043
DJ
9692 }
9693 }
9694 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 9695 || (*targetm.binds_local_p) (decl))
2bcc50d0 9696 {
4977bab6 9697 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
9698
9699 if (!lookup_attribute ("longcall", attr_list)
9700 || lookup_attribute ("shortcall", attr_list))
4977bab6 9701 return true;
2bcc50d0 9702 }
5e1bf043 9703 }
4977bab6 9704 return false;
5e1bf043
DJ
9705}
9706
71f123ca
FS
9707static int
9708rs6000_ra_ever_killed ()
9709{
9710 rtx top;
5e1bf043
DJ
9711 rtx reg;
9712 rtx insn;
71f123ca 9713
3961e8fe
RH
9714 /* Irritatingly, there are two kinds of thunks -- those created with
9715 TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go
9716 through the regular part of the compiler. This is a very hacky
9717 way to tell them apart. */
9718 if (current_function_is_thunk && !no_new_pseudos)
71f123ca 9719 return 0;
eb0424da 9720
36f7e964
AH
9721 /* regs_ever_live has LR marked as used if any sibcalls are present,
9722 but this should not force saving and restoring in the
9723 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
9724 clobbers LR, so that is inappropriate. */
9725
5e1bf043
DJ
9726 /* Also, the prologue can generate a store into LR that
9727 doesn't really count, like this:
36f7e964 9728
5e1bf043
DJ
9729 move LR->R0
9730 bcl to set PIC register
9731 move LR->R31
9732 move R0->LR
36f7e964
AH
9733
9734 When we're called from the epilogue, we need to avoid counting
9735 this as a store. */
5e1bf043 9736
71f123ca
FS
9737 push_topmost_sequence ();
9738 top = get_insns ();
9739 pop_topmost_sequence ();
5e1bf043 9740 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 9741
5e1bf043
DJ
9742 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
9743 {
9744 if (INSN_P (insn))
9745 {
9746 if (FIND_REG_INC_NOTE (insn, reg))
9747 return 1;
9748 else if (GET_CODE (insn) == CALL_INSN
c15b529f 9749 && !SIBLING_CALL_P (insn))
5e1bf043 9750 return 1;
36f7e964
AH
9751 else if (set_of (reg, insn) != NULL_RTX
9752 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
9753 return 1;
9754 }
9755 }
9756 return 0;
71f123ca 9757}
4697a36c 9758\f
8cd8f856
GK
9759/* Add a REG_MAYBE_DEAD note to the insn. */
9760static void
9761rs6000_maybe_dead (insn)
9762 rtx insn;
9763{
9764 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
9765 const0_rtx,
9766 REG_NOTES (insn));
9767}
9768
9ebbca7d 9769/* Emit instructions needed to load the TOC register.
c7ca610e 9770 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 9771 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
9772
9773void
9ebbca7d
GK
9774rs6000_emit_load_toc_table (fromprolog)
9775 int fromprolog;
c7ca610e 9776{
9ebbca7d 9777 rtx dest;
1db02437 9778 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 9779
20b71b17
AM
9780 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
9781 {
9782 rtx temp = (fromprolog
9783 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
9784 : gen_reg_rtx (Pmode));
9785 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp)));
9786 rs6000_maybe_dead (emit_move_insn (dest, temp));
9787 }
9788 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
9789 {
9790 char buf[30];
9791 rtx tempLR = (fromprolog
9792 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
9793 : gen_reg_rtx (Pmode));
9794 rtx temp0 = (fromprolog
9795 ? gen_rtx_REG (Pmode, 0)
9796 : gen_reg_rtx (Pmode));
9797 rtx symF;
9798
9799 /* possibly create the toc section */
9800 if (! toc_initialized)
38c1f2d7 9801 {
20b71b17
AM
9802 toc_section ();
9803 function_section (current_function_decl);
38c1f2d7 9804 }
9ebbca7d 9805
20b71b17
AM
9806 if (fromprolog)
9807 {
9808 rtx symL;
38c1f2d7 9809
20b71b17
AM
9810 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
9811 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 9812
20b71b17
AM
9813 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
9814 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9815
9816 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
9817 symF)));
9818 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
9819 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
9820 symL,
9821 symF)));
9ebbca7d
GK
9822 }
9823 else
20b71b17
AM
9824 {
9825 rtx tocsym;
9826 static int reload_toc_labelno = 0;
9827
9828 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
9829
9830 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
9831 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9832
9833 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR,
9834 symF,
9835 tocsym)));
9836 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
9837 rs6000_maybe_dead (emit_move_insn (temp0,
9838 gen_rtx_MEM (Pmode, dest)));
9839 }
9840 rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest)));
9ebbca7d 9841 }
20b71b17
AM
9842 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
9843 {
9844 /* This is for AIX code running in non-PIC ELF32. */
9845 char buf[30];
9846 rtx realsym;
9847 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
9848 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9849
9850 rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym)));
9851 rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym)));
9852 }
9853 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
9854 {
9855 if (TARGET_32BIT)
20b71b17 9856 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest)));
9ebbca7d 9857 else
20b71b17 9858 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest)));
9ebbca7d 9859 }
20b71b17
AM
9860 else
9861 abort ();
9ebbca7d
GK
9862}
9863
9864int
9865get_TOC_alias_set ()
9866{
9867 static int set = -1;
9868 if (set == -1)
9869 set = new_alias_set ();
9870 return set;
9871}
9872
9873/* This retuns nonzero if the current function uses the TOC. This is
9874 determined by the presence of (unspec ... 7), which is generated by
9875 the various load_toc_* patterns. */
a4f6c312 9876
9ebbca7d
GK
9877int
9878uses_TOC ()
9879{
9880 rtx insn;
38c1f2d7 9881
9ebbca7d 9882 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2c3c49de 9883 if (INSN_P (insn))
9ebbca7d
GK
9884 {
9885 rtx pat = PATTERN (insn);
9886 int i;
9887
8cd8f856 9888 if (GET_CODE (pat) == PARALLEL)
9ebbca7d
GK
9889 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
9890 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
9891 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
9892 return 1;
38c1f2d7 9893 }
9ebbca7d
GK
9894 return 0;
9895}
38c1f2d7 9896
9ebbca7d 9897rtx
a4f6c312 9898create_TOC_reference (symbol)
9ebbca7d
GK
9899 rtx symbol;
9900{
a8a05998
ZW
9901 return gen_rtx_PLUS (Pmode,
9902 gen_rtx_REG (Pmode, TOC_REGISTER),
9903 gen_rtx_CONST (Pmode,
9904 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 9905 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 9906}
38c1f2d7 9907
9ebbca7d
GK
9908#if TARGET_AIX
9909/* __throw will restore its own return address to be the same as the
9910 return address of the function that the throw is being made to.
9911 This is unfortunate, because we want to check the original
9912 return address to see if we need to restore the TOC.
9913 So we have to squirrel it away here.
9914 This is used only in compiling __throw and __rethrow.
c7ca610e 9915
9ebbca7d
GK
9916 Most of this code should be removed by CSE. */
9917static rtx insn_after_throw;
c7ca610e 9918
a4f6c312 9919/* This does the saving... */
9ebbca7d
GK
9920void
9921rs6000_aix_emit_builtin_unwind_init ()
9922{
9923 rtx mem;
9924 rtx stack_top = gen_reg_rtx (Pmode);
9925 rtx opcode_addr = gen_reg_rtx (Pmode);
9926
9927 insn_after_throw = gen_reg_rtx (SImode);
9928
9929 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
9930 emit_move_insn (stack_top, mem);
9931
9932 mem = gen_rtx_MEM (Pmode,
9933 gen_rtx_PLUS (Pmode, stack_top,
9934 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
9935 emit_move_insn (opcode_addr, mem);
9936 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
c7ca610e
RK
9937}
9938
a4f6c312
SS
9939/* Emit insns to _restore_ the TOC register, at runtime (specifically
9940 in _eh.o). Only used on AIX.
9ebbca7d
GK
9941
9942 The idea is that on AIX, function calls look like this:
9943 bl somefunction-trampoline
9944 lwz r2,20(sp)
9945
a4f6c312 9946 and later,
9ebbca7d
GK
9947 somefunction-trampoline:
9948 stw r2,20(sp)
9949 ... load function address in the count register ...
9950 bctr
9951 or like this, if the linker determines that this is not a cross-module call
9952 and so the TOC need not be restored:
9953 bl somefunction
9954 nop
9955 or like this, if the compiler could determine that this is not a
9956 cross-module call:
9957 bl somefunction
9958 now, the tricky bit here is that register 2 is saved and restored
9959 by the _linker_, so we can't readily generate debugging information
9960 for it. So we need to go back up the call chain looking at the
9961 insns at return addresses to see which calls saved the TOC register
9962 and so see where it gets restored from.
9963
9964 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
9965 just before the actual epilogue.
9966
9967 On the bright side, this incurs no space or time overhead unless an
9968 exception is thrown, except for the extra code in libgcc.a.
9969
9970 The parameter STACKSIZE is a register containing (at runtime)
9971 the amount to be popped off the stack in addition to the stack frame
9972 of this routine (which will be __throw or __rethrow, and so is
9973 guaranteed to have a stack frame). */
a4f6c312 9974
9ebbca7d
GK
9975void
9976rs6000_emit_eh_toc_restore (stacksize)
9977 rtx stacksize;
9978{
9979 rtx top_of_stack;
9980 rtx bottom_of_stack = gen_reg_rtx (Pmode);
9981 rtx tocompare = gen_reg_rtx (SImode);
9982 rtx opcode = gen_reg_rtx (SImode);
9983 rtx opcode_addr = gen_reg_rtx (Pmode);
9984 rtx mem;
9985 rtx loop_start = gen_label_rtx ();
9986 rtx no_toc_restore_needed = gen_label_rtx ();
9987 rtx loop_exit = gen_label_rtx ();
9988
9989 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
ba4828e0 9990 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
9991 emit_move_insn (bottom_of_stack, mem);
9992
9993 top_of_stack = expand_binop (Pmode, add_optab,
9994 bottom_of_stack, stacksize,
9995 NULL_RTX, 1, OPTAB_WIDEN);
9996
2496c7bd
LB
9997 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
9998 : 0xE8410028, SImode));
9ebbca7d
GK
9999
10000 if (insn_after_throw == NULL_RTX)
a4f6c312 10001 abort ();
9ebbca7d
GK
10002 emit_move_insn (opcode, insn_after_throw);
10003
6496a589 10004 emit_note (NULL, NOTE_INSN_LOOP_BEG);
9ebbca7d
GK
10005 emit_label (loop_start);
10006
10007 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
06f4e019 10008 SImode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
10009 no_toc_restore_needed);
10010
10011 mem = gen_rtx_MEM (Pmode,
10012 gen_rtx_PLUS (Pmode, bottom_of_stack,
10013 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
10014 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
10015
10016 emit_label (no_toc_restore_needed);
10017 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
06f4e019 10018 Pmode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
10019 loop_exit);
10020
10021 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
ba4828e0 10022 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10023 emit_move_insn (bottom_of_stack, mem);
10024
10025 mem = gen_rtx_MEM (Pmode,
10026 gen_rtx_PLUS (Pmode, bottom_of_stack,
10027 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
10028 emit_move_insn (opcode_addr, mem);
10029 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
10030
6496a589 10031 emit_note (NULL, NOTE_INSN_LOOP_CONT);
9ebbca7d 10032 emit_jump (loop_start);
6496a589 10033 emit_note (NULL, NOTE_INSN_LOOP_END);
9ebbca7d
GK
10034 emit_label (loop_exit);
10035}
10036#endif /* TARGET_AIX */
38c1f2d7 10037\f
ba4828e0
RK
10038/* This ties together stack memory (MEM with an alias set of
10039 rs6000_sr_alias_set) and the change to the stack pointer. */
10040
9ebbca7d
GK
10041static void
10042rs6000_emit_stack_tie ()
10043{
ba4828e0
RK
10044 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
10045
10046 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10047 emit_insn (gen_stack_tie (mem));
10048}
38c1f2d7 10049
9ebbca7d
GK
10050/* Emit the correct code for allocating stack space, as insns.
10051 If COPY_R12, make sure a copy of the old frame is left in r12.
10052 The generated code may use hard register 0 as a temporary. */
10053
10054static void
10055rs6000_emit_allocate_stack (size, copy_r12)
10056 HOST_WIDE_INT size;
38c1f2d7
MM
10057 int copy_r12;
10058{
9ebbca7d
GK
10059 rtx insn;
10060 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
10061 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
10062 rtx todec = GEN_INT (-size);
a157febd
GK
10063
10064 if (current_function_limit_stack)
10065 {
10066 if (REG_P (stack_limit_rtx)
10067 && REGNO (stack_limit_rtx) > 1
10068 && REGNO (stack_limit_rtx) <= 31)
10069 {
5b71a4e7 10070 emit_insn (TARGET_32BIT
9ebbca7d
GK
10071 ? gen_addsi3 (tmp_reg,
10072 stack_limit_rtx,
10073 GEN_INT (size))
10074 : gen_adddi3 (tmp_reg,
10075 stack_limit_rtx,
10076 GEN_INT (size)));
5b71a4e7 10077
9ebbca7d
GK
10078 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10079 const0_rtx));
a157febd
GK
10080 }
10081 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 10082 && TARGET_32BIT
f607bc57 10083 && DEFAULT_ABI == ABI_V4)
a157febd 10084 {
9ebbca7d
GK
10085 rtx toload = gen_rtx_CONST (VOIDmode,
10086 gen_rtx_PLUS (Pmode,
10087 stack_limit_rtx,
10088 GEN_INT (size)));
5b71a4e7 10089
9ebbca7d
GK
10090 emit_insn (gen_elf_high (tmp_reg, toload));
10091 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
10092 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10093 const0_rtx));
a157febd
GK
10094 }
10095 else
10096 warning ("stack limit expression is not supported");
10097 }
10098
9ebbca7d
GK
10099 if (copy_r12 || ! TARGET_UPDATE)
10100 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
10101
38c1f2d7
MM
10102 if (TARGET_UPDATE)
10103 {
9ebbca7d 10104 if (size > 32767)
38c1f2d7 10105 {
9ebbca7d
GK
10106 /* Need a note here so that try_split doesn't get confused. */
10107 if (get_last_insn() == NULL_RTX)
10108 emit_note (0, NOTE_INSN_DELETED);
10109 insn = emit_move_insn (tmp_reg, todec);
10110 try_split (PATTERN (insn), insn, 0);
10111 todec = tmp_reg;
38c1f2d7 10112 }
5b71a4e7
DE
10113
10114 insn = emit_insn (TARGET_32BIT
10115 ? gen_movsi_update (stack_reg, stack_reg,
10116 todec, stack_reg)
10117 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 10118 todec, stack_reg));
38c1f2d7
MM
10119 }
10120 else
10121 {
5b71a4e7
DE
10122 insn = emit_insn (TARGET_32BIT
10123 ? gen_addsi3 (stack_reg, stack_reg, todec)
10124 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
10125 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
10126 gen_rtx_REG (Pmode, 12));
10127 }
5b71a4e7 10128
9ebbca7d
GK
10129 RTX_FRAME_RELATED_P (insn) = 1;
10130 REG_NOTES (insn) =
10131 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10132 gen_rtx_SET (VOIDmode, stack_reg,
10133 gen_rtx_PLUS (Pmode, stack_reg,
10134 GEN_INT (-size))),
10135 REG_NOTES (insn));
10136}
10137
a4f6c312
SS
10138/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
10139 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
10140 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
10141 deduce these equivalences by itself so it wasn't necessary to hold
10142 its hand so much. */
9ebbca7d
GK
10143
10144static void
10145rs6000_frame_related (insn, reg, val, reg2, rreg)
10146 rtx insn;
10147 rtx reg;
10148 HOST_WIDE_INT val;
10149 rtx reg2;
10150 rtx rreg;
10151{
10152 rtx real, temp;
10153
e56c4463
JL
10154 /* copy_rtx will not make unique copies of registers, so we need to
10155 ensure we don't have unwanted sharing here. */
10156 if (reg == reg2)
10157 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10158
10159 if (reg == rreg)
10160 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10161
9ebbca7d
GK
10162 real = copy_rtx (PATTERN (insn));
10163
89e7058f
AH
10164 if (reg2 != NULL_RTX)
10165 real = replace_rtx (real, reg2, rreg);
10166
9ebbca7d
GK
10167 real = replace_rtx (real, reg,
10168 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
10169 STACK_POINTER_REGNUM),
10170 GEN_INT (val)));
10171
10172 /* We expect that 'real' is either a SET or a PARALLEL containing
10173 SETs (and possibly other stuff). In a PARALLEL, all the SETs
10174 are important so they all have to be marked RTX_FRAME_RELATED_P. */
10175
10176 if (GET_CODE (real) == SET)
10177 {
10178 rtx set = real;
10179
10180 temp = simplify_rtx (SET_SRC (set));
10181 if (temp)
10182 SET_SRC (set) = temp;
10183 temp = simplify_rtx (SET_DEST (set));
10184 if (temp)
10185 SET_DEST (set) = temp;
10186 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 10187 {
9ebbca7d
GK
10188 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10189 if (temp)
10190 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 10191 }
38c1f2d7 10192 }
9ebbca7d
GK
10193 else if (GET_CODE (real) == PARALLEL)
10194 {
10195 int i;
10196 for (i = 0; i < XVECLEN (real, 0); i++)
10197 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
10198 {
10199 rtx set = XVECEXP (real, 0, i);
10200
10201 temp = simplify_rtx (SET_SRC (set));
10202 if (temp)
10203 SET_SRC (set) = temp;
10204 temp = simplify_rtx (SET_DEST (set));
10205 if (temp)
10206 SET_DEST (set) = temp;
10207 if (GET_CODE (SET_DEST (set)) == MEM)
10208 {
10209 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10210 if (temp)
10211 XEXP (SET_DEST (set), 0) = temp;
10212 }
10213 RTX_FRAME_RELATED_P (set) = 1;
10214 }
10215 }
10216 else
a4f6c312 10217 abort ();
c19de7aa
AH
10218
10219 if (TARGET_SPE)
10220 real = spe_synthesize_frame_save (real);
10221
9ebbca7d
GK
10222 RTX_FRAME_RELATED_P (insn) = 1;
10223 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10224 real,
10225 REG_NOTES (insn));
38c1f2d7
MM
10226}
10227
c19de7aa
AH
10228/* Given an SPE frame note, return a PARALLEL of SETs with the
10229 original note, plus a synthetic register save. */
10230
10231static rtx
10232spe_synthesize_frame_save (real)
10233 rtx real;
10234{
10235 rtx synth, offset, reg, real2;
10236
10237 if (GET_CODE (real) != SET
10238 || GET_MODE (SET_SRC (real)) != V2SImode)
10239 return real;
10240
10241 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
10242 frame related note. The parallel contains a set of the register
41f3a930 10243 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
10244 This is so we can differentiate between 64-bit and 32-bit saves.
10245 Words cannot describe this nastiness. */
10246
10247 if (GET_CODE (SET_DEST (real)) != MEM
10248 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
10249 || GET_CODE (SET_SRC (real)) != REG)
10250 abort ();
10251
10252 /* Transform:
10253 (set (mem (plus (reg x) (const y)))
10254 (reg z))
10255 into:
10256 (set (mem (plus (reg x) (const y+4)))
41f3a930 10257 (reg z+1200))
c19de7aa
AH
10258 */
10259
10260 real2 = copy_rtx (real);
10261 PUT_MODE (SET_DEST (real2), SImode);
10262 reg = SET_SRC (real2);
10263 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
10264 synth = copy_rtx (real2);
10265
10266 if (BYTES_BIG_ENDIAN)
10267 {
10268 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
10269 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
10270 }
10271
10272 reg = SET_SRC (synth);
41f3a930 10273
c19de7aa 10274 synth = replace_rtx (synth, reg,
41f3a930 10275 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
10276
10277 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
10278 synth = replace_rtx (synth, offset,
10279 GEN_INT (INTVAL (offset)
10280 + (BYTES_BIG_ENDIAN ? 0 : 4)));
10281
10282 RTX_FRAME_RELATED_P (synth) = 1;
10283 RTX_FRAME_RELATED_P (real2) = 1;
10284 if (BYTES_BIG_ENDIAN)
10285 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
10286 else
10287 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
10288
10289 return real;
10290}
10291
00b960c7
AH
10292/* Returns an insn that has a vrsave set operation with the
10293 appropriate CLOBBERs. */
10294
10295static rtx
9aa86737 10296generate_set_vrsave (reg, info, epiloguep)
00b960c7
AH
10297 rtx reg;
10298 rs6000_stack_t *info;
9aa86737 10299 int epiloguep;
00b960c7
AH
10300{
10301 int nclobs, i;
10302 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 10303 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 10304
a004eb82
AH
10305 clobs[0]
10306 = gen_rtx_SET (VOIDmode,
10307 vrsave,
10308 gen_rtx_UNSPEC_VOLATILE (SImode,
10309 gen_rtvec (2, reg, vrsave),
10310 30));
00b960c7
AH
10311
10312 nclobs = 1;
10313
9aa86737
AH
10314 /* We need to clobber the registers in the mask so the scheduler
10315 does not move sets to VRSAVE before sets of AltiVec registers.
10316
10317 However, if the function receives nonlocal gotos, reload will set
10318 all call saved registers live. We will end up with:
10319
10320 (set (reg 999) (mem))
10321 (parallel [ (set (reg vrsave) (unspec blah))
10322 (clobber (reg 999))])
10323
10324 The clobber will cause the store into reg 999 to be dead, and
10325 flow will attempt to delete an epilogue insn. In this case, we
10326 need an unspec use/set of the register. */
00b960c7
AH
10327
10328 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10329 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
10330 {
10331 if (!epiloguep || call_used_regs [i])
10332 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
10333 gen_rtx_REG (V4SImode, i));
10334 else
10335 {
10336 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
10337
10338 clobs[nclobs++]
a004eb82
AH
10339 = gen_rtx_SET (VOIDmode,
10340 reg,
10341 gen_rtx_UNSPEC (V4SImode,
10342 gen_rtvec (1, reg), 27));
9aa86737
AH
10343 }
10344 }
00b960c7
AH
10345
10346 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
10347
10348 for (i = 0; i < nclobs; ++i)
10349 XVECEXP (insn, 0, i) = clobs[i];
10350
10351 return insn;
10352}
10353
89e7058f
AH
10354/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
10355 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
10356
10357static void
10358emit_frame_save (frame_reg, frame_ptr, mode, regno, offset, total_size)
10359 rtx frame_reg;
10360 rtx frame_ptr;
10361 enum machine_mode mode;
10362 unsigned int regno;
10363 int offset;
10364 int total_size;
10365{
10366 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
10367 rtx replacea, replaceb;
10368
10369 int_rtx = GEN_INT (offset);
10370
10371 /* Some cases that need register indexed addressing. */
10372 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
10373 || (TARGET_SPE_ABI
10374 && SPE_VECTOR_MODE (mode)
10375 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
10376 {
10377 /* Whomever calls us must make sure r11 is available in the
10378 flow path of instructions in the prologue. */
10379 offset_rtx = gen_rtx_REG (Pmode, 11);
10380 emit_move_insn (offset_rtx, int_rtx);
10381
10382 replacea = offset_rtx;
10383 replaceb = int_rtx;
10384 }
10385 else
10386 {
10387 offset_rtx = int_rtx;
10388 replacea = NULL_RTX;
10389 replaceb = NULL_RTX;
10390 }
10391
10392 reg = gen_rtx_REG (mode, regno);
10393 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
10394 mem = gen_rtx_MEM (mode, addr);
10395 set_mem_alias_set (mem, rs6000_sr_alias_set);
10396
10397 insn = emit_move_insn (mem, reg);
10398
10399 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
10400}
10401
a3170dc6
AH
10402/* Emit an offset memory reference suitable for a frame store, while
10403 converting to a valid addressing mode. */
10404
10405static rtx
10406gen_frame_mem_offset (mode, reg, offset)
10407 enum machine_mode mode;
10408 rtx reg;
10409 int offset;
10410{
10411 rtx int_rtx, offset_rtx;
10412
10413 int_rtx = GEN_INT (offset);
10414
10415 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
10416 {
10417 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
10418 emit_move_insn (offset_rtx, int_rtx);
10419 }
10420 else
10421 offset_rtx = int_rtx;
10422
10423 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
10424}
10425
9ebbca7d
GK
10426/* Emit function prologue as insns. */
10427
9878760c 10428void
83720594 10429rs6000_emit_prologue ()
9878760c 10430{
4697a36c 10431 rs6000_stack_t *info = rs6000_stack_info ();
9ebbca7d
GK
10432 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
10433 int reg_size = TARGET_POWERPC64 ? 8 : 4;
10434 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
10435 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
10436 rtx frame_reg_rtx = sp_reg_rtx;
10437 rtx cr_save_rtx = NULL;
10438 rtx insn;
10439 int saving_FPRs_inline;
10440 int using_store_multiple;
10441 HOST_WIDE_INT sp_offset = 0;
10442
c19de7aa 10443 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
10444 {
10445 reg_mode = V2SImode;
10446 reg_size = 8;
10447 }
10448
9ebbca7d 10449 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
10450 && (!TARGET_SPE_ABI
10451 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
10452 && info->first_gp_reg_save < 31);
10453 saving_FPRs_inline = (info->first_fp_reg_save == 64
10454 || FP_SAVE_INLINE (info->first_fp_reg_save));
10455
10456 /* For V.4, update stack before we do any saving and set back pointer. */
f607bc57 10457 if (info->push_p && DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
10458 {
10459 if (info->total_size < 32767)
10460 sp_offset = info->total_size;
10461 else
10462 frame_reg_rtx = frame_ptr_rtx;
10463 rs6000_emit_allocate_stack (info->total_size,
10464 (frame_reg_rtx != sp_reg_rtx
10465 && (info->cr_save_p
10466 || info->lr_save_p
10467 || info->first_fp_reg_save < 64
10468 || info->first_gp_reg_save < 32
10469 )));
10470 if (frame_reg_rtx != sp_reg_rtx)
10471 rs6000_emit_stack_tie ();
10472 }
10473
9aa86737
AH
10474 /* Save AltiVec registers if needed. */
10475 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
10476 {
10477 int i;
10478
10479 /* There should be a non inline version of this, for when we
10480 are saving lots of vector registers. */
10481 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
10482 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
10483 {
10484 rtx areg, savereg, mem;
10485 int offset;
10486
10487 offset = info->altivec_save_offset + sp_offset
10488 + 16 * (i - info->first_altivec_reg_save);
10489
10490 savereg = gen_rtx_REG (V4SImode, i);
10491
10492 areg = gen_rtx_REG (Pmode, 0);
10493 emit_move_insn (areg, GEN_INT (offset));
10494
10495 /* AltiVec addressing mode is [reg+reg]. */
10496 mem = gen_rtx_MEM (V4SImode,
10497 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
10498
10499 set_mem_alias_set (mem, rs6000_sr_alias_set);
10500
10501 insn = emit_move_insn (mem, savereg);
10502
5c242421
SB
10503 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10504 areg, GEN_INT (offset));
9aa86737
AH
10505 }
10506 }
10507
10508 /* VRSAVE is a bit vector representing which AltiVec registers
10509 are used. The OS uses this to determine which vector
10510 registers to save on a context switch. We need to save
10511 VRSAVE on the stack frame, add whatever AltiVec registers we
10512 used in this function, and do the corresponding magic in the
10513 epilogue. */
10514
10515 if (TARGET_ALTIVEC && info->vrsave_mask != 0)
10516 {
a004eb82 10517 rtx reg, mem, vrsave;
9aa86737
AH
10518 int offset;
10519
10520 /* Get VRSAVE onto a GPR. */
10521 reg = gen_rtx_REG (SImode, 12);
a004eb82 10522 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
10523 if (TARGET_MACHO)
10524 emit_insn (gen_get_vrsave_internal (reg));
10525 else
10526 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
10527
10528 /* Save VRSAVE. */
10529 offset = info->vrsave_save_offset + sp_offset;
10530 mem
10531 = gen_rtx_MEM (SImode,
10532 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
10533 set_mem_alias_set (mem, rs6000_sr_alias_set);
10534 insn = emit_move_insn (mem, reg);
10535
10536 /* Include the registers in the mask. */
10537 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
10538
10539 insn = emit_insn (generate_set_vrsave (reg, info, 0));
10540 }
10541
9ebbca7d
GK
10542 /* If we use the link register, get it into r0. */
10543 if (info->lr_save_p)
71f123ca 10544 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
10545 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10546
10547 /* If we need to save CR, put it into r12. */
10548 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
10549 {
10550 cr_save_rtx = gen_rtx_REG (SImode, 12);
10551 emit_insn (gen_movesi_from_cr (cr_save_rtx));
10552 }
10553
a4f6c312
SS
10554 /* Do any required saving of fpr's. If only one or two to save, do
10555 it ourselves. Otherwise, call function. */
9ebbca7d
GK
10556 if (saving_FPRs_inline)
10557 {
10558 int i;
10559 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
10560 if ((regs_ever_live[info->first_fp_reg_save+i]
10561 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
10562 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
10563 info->first_fp_reg_save + i,
10564 info->fp_save_offset + sp_offset + 8 * i,
10565 info->total_size);
9ebbca7d
GK
10566 }
10567 else if (info->first_fp_reg_save != 64)
10568 {
10569 int i;
10570 char rname[30];
520a57c8 10571 const char *alloc_rname;
9ebbca7d
GK
10572 rtvec p;
10573 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
10574
10575 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
10576 gen_rtx_REG (Pmode,
10577 LINK_REGISTER_REGNUM));
10578 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
10579 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 10580 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
10581 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
10582 gen_rtx_SYMBOL_REF (Pmode,
10583 alloc_rname));
10584 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
10585 {
10586 rtx addr, reg, mem;
10587 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
10588 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10589 GEN_INT (info->fp_save_offset
10590 + sp_offset + 8*i));
10591 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 10592 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10593
10594 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
10595 }
10596 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
10597 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10598 NULL_RTX, NULL_RTX);
10599 }
b6c9286a 10600
9ebbca7d
GK
10601 /* Save GPRs. This is done as a PARALLEL if we are using
10602 the store-multiple instructions. */
10603 if (using_store_multiple)
b6c9286a 10604 {
308c142a 10605 rtvec p;
9ebbca7d
GK
10606 int i;
10607 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
10608 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
10609 {
10610 rtx addr, reg, mem;
10611 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
10612 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10613 GEN_INT (info->gp_save_offset
10614 + sp_offset
10615 + reg_size * i));
10616 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 10617 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10618
10619 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
10620 }
10621 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
10622 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10623 NULL_RTX, NULL_RTX);
b6c9286a
MM
10624 }
10625 else
10626 {
9ebbca7d
GK
10627 int i;
10628 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
10629 if ((regs_ever_live[info->first_gp_reg_save+i]
10630 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 10631 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10632 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10633 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
10634 {
10635 rtx addr, reg, mem;
10636 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
10637
c19de7aa 10638 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
10639 {
10640 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
10641 rtx b;
10642
10643 if (!SPE_CONST_OFFSET_OK (offset))
10644 {
10645 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
10646 emit_move_insn (b, GEN_INT (offset));
10647 }
10648 else
10649 b = GEN_INT (offset);
10650
10651 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
10652 mem = gen_rtx_MEM (V2SImode, addr);
10653 set_mem_alias_set (mem, rs6000_sr_alias_set);
10654 insn = emit_move_insn (mem, reg);
10655
10656 if (GET_CODE (b) == CONST_INT)
10657 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10658 NULL_RTX, NULL_RTX);
10659 else
10660 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10661 b, GEN_INT (offset));
10662 }
10663 else
10664 {
10665 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10666 GEN_INT (info->gp_save_offset
10667 + sp_offset
10668 + reg_size * i));
10669 mem = gen_rtx_MEM (reg_mode, addr);
10670 set_mem_alias_set (mem, rs6000_sr_alias_set);
10671
10672 insn = emit_move_insn (mem, reg);
10673 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10674 NULL_RTX, NULL_RTX);
10675 }
10676 }
9ebbca7d
GK
10677 }
10678
83720594
RH
10679 /* ??? There's no need to emit actual instructions here, but it's the
10680 easiest way to get the frame unwind information emitted. */
10681 if (current_function_calls_eh_return)
10682 {
78e1b90d
DE
10683 unsigned int i, regno;
10684
83720594
RH
10685 for (i = 0; ; ++i)
10686 {
83720594
RH
10687 regno = EH_RETURN_DATA_REGNO (i);
10688 if (regno == INVALID_REGNUM)
10689 break;
10690
89e7058f
AH
10691 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
10692 info->ehrd_offset + sp_offset
10693 + reg_size * (int) i,
10694 info->total_size);
83720594
RH
10695 }
10696 }
10697
9ebbca7d
GK
10698 /* Save lr if we used it. */
10699 if (info->lr_save_p)
10700 {
10701 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10702 GEN_INT (info->lr_save_offset + sp_offset));
10703 rtx reg = gen_rtx_REG (Pmode, 0);
10704 rtx mem = gen_rtx_MEM (Pmode, addr);
10705 /* This should not be of rs6000_sr_alias_set, because of
10706 __builtin_return_address. */
10707
10708 insn = emit_move_insn (mem, reg);
10709 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10710 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10711 }
10712
10713 /* Save CR if we use any that must be preserved. */
10714 if (info->cr_save_p)
10715 {
10716 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10717 GEN_INT (info->cr_save_offset + sp_offset));
10718 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
10719
10720 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10721
10722 /* If r12 was used to hold the original sp, copy cr into r0 now
10723 that it's free. */
10724 if (REGNO (frame_reg_rtx) == 12)
10725 {
10726 cr_save_rtx = gen_rtx_REG (SImode, 0);
10727 emit_insn (gen_movesi_from_cr (cr_save_rtx));
10728 }
10729 insn = emit_move_insn (mem, cr_save_rtx);
10730
10731 /* Now, there's no way that dwarf2out_frame_debug_expr is going
10732 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
10733 OK. All we have to do is specify that _one_ condition code
10734 register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
10735 will then restore all the call-saved registers.
10736 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 10737 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 10738 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
10739 }
10740
10741 /* Update stack and set back pointer unless this is V.4,
10742 for which it was done previously. */
f607bc57 10743 if (info->push_p && DEFAULT_ABI != ABI_V4)
9ebbca7d
GK
10744 rs6000_emit_allocate_stack (info->total_size, FALSE);
10745
10746 /* Set frame pointer, if needed. */
10747 if (frame_pointer_needed)
10748 {
a3170dc6 10749 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
10750 sp_reg_rtx);
10751 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 10752 }
9878760c 10753
1db02437 10754 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 10755 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 10756 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 10757 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
10758 {
10759 /* If emit_load_toc_table will use the link register, we need to save
10760 it. We use R11 for this purpose because emit_load_toc_table
10761 can use register 0. This allows us to use a plain 'blr' to return
10762 from the procedure more often. */
d5fa86ba
GK
10763 int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0
10764 && ! info->lr_save_p
10765 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d
GK
10766 if (save_LR_around_toc_setup)
10767 emit_move_insn (gen_rtx_REG (Pmode, 11),
10768 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10769
10770 rs6000_emit_load_toc_table (TRUE);
10771
10772 if (save_LR_around_toc_setup)
10773 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
10774 gen_rtx_REG (Pmode, 11));
10775 }
ee890fe2 10776
fcce224d 10777#if TARGET_MACHO
ee890fe2
SS
10778 if (DEFAULT_ABI == ABI_DARWIN
10779 && flag_pic && current_function_uses_pic_offset_table)
10780 {
10781 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 10782 const char *picbase = machopic_function_base_name ();
f51eee6a 10783 rtx src = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
ee890fe2 10784
f51eee6a 10785 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
10786
10787 rs6000_maybe_dead (
1db02437 10788 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
10789 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
10790 }
fcce224d 10791#endif
9ebbca7d
GK
10792}
10793
9ebbca7d 10794/* Write function prologue. */
a4f6c312 10795
08c148a8
NB
10796static void
10797rs6000_output_function_prologue (file, size)
9ebbca7d 10798 FILE *file;
08c148a8 10799 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9ebbca7d
GK
10800{
10801 rs6000_stack_t *info = rs6000_stack_info ();
10802
4697a36c
MM
10803 if (TARGET_DEBUG_STACK)
10804 debug_stack_info (info);
9878760c 10805
a4f6c312
SS
10806 /* Write .extern for any function we will call to save and restore
10807 fp values. */
10808 if (info->first_fp_reg_save < 64
10809 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 10810 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 10811 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
10812 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
10813 RESTORE_FP_SUFFIX);
9878760c 10814
c764f757
RK
10815 /* Write .extern for AIX common mode routines, if needed. */
10816 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
10817 {
f6709c70
JW
10818 fputs ("\t.extern __mulh\n", file);
10819 fputs ("\t.extern __mull\n", file);
10820 fputs ("\t.extern __divss\n", file);
10821 fputs ("\t.extern __divus\n", file);
10822 fputs ("\t.extern __quoss\n", file);
10823 fputs ("\t.extern __quous\n", file);
c764f757
RK
10824 common_mode_defined = 1;
10825 }
9878760c 10826
9ebbca7d 10827 if (! HAVE_prologue)
979721f8 10828 {
9ebbca7d 10829 start_sequence ();
9dda4cc8 10830
a4f6c312
SS
10831 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
10832 the "toplevel" insn chain. */
9ebbca7d
GK
10833 emit_note (0, NOTE_INSN_DELETED);
10834 rs6000_emit_prologue ();
10835 emit_note (0, NOTE_INSN_DELETED);
178c3eff
DJ
10836
10837 /* Expand INSN_ADDRESSES so final() doesn't crash. */
10838 {
10839 rtx insn;
10840 unsigned addr = 0;
10841 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
10842 {
10843 INSN_ADDRESSES_NEW (insn, addr);
10844 addr += 4;
10845 }
10846 }
9dda4cc8 10847
9ebbca7d 10848 if (TARGET_DEBUG_STACK)
a4f6c312
SS
10849 debug_rtx_list (get_insns (), 100);
10850 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 10851 end_sequence ();
979721f8
MM
10852 }
10853
9ebbca7d
GK
10854 rs6000_pic_labelno++;
10855}
10856
10857/* Emit function epilogue as insns.
9878760c 10858
9ebbca7d
GK
10859 At present, dwarf2out_frame_debug_expr doesn't understand
10860 register restores, so we don't bother setting RTX_FRAME_RELATED_P
10861 anywhere in the epilogue. Most of the insns below would in any case
10862 need special notes to explain where r11 is in relation to the stack. */
9878760c 10863
9ebbca7d 10864void
83720594 10865rs6000_emit_epilogue (sibcall)
9ebbca7d
GK
10866 int sibcall;
10867{
10868 rs6000_stack_t *info;
10869 int restoring_FPRs_inline;
10870 int using_load_multiple;
10871 int using_mfcr_multiple;
10872 int use_backchain_to_restore_sp;
10873 int sp_offset = 0;
10874 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
10875 rtx frame_reg_rtx = sp_reg_rtx;
10876 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
10877 int reg_size = TARGET_POWERPC64 ? 8 : 4;
10878 int i;
10879
c19de7aa
AH
10880 info = rs6000_stack_info ();
10881
10882 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
10883 {
10884 reg_mode = V2SImode;
10885 reg_size = 8;
10886 }
10887
9ebbca7d 10888 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
10889 && (!TARGET_SPE_ABI
10890 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
10891 && info->first_gp_reg_save < 31);
10892 restoring_FPRs_inline = (sibcall
83720594 10893 || current_function_calls_eh_return
9ebbca7d
GK
10894 || info->first_fp_reg_save == 64
10895 || FP_SAVE_INLINE (info->first_fp_reg_save));
10896 use_backchain_to_restore_sp = (frame_pointer_needed
10897 || current_function_calls_alloca
10898 || info->total_size > 32767);
10899 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
10900 || rs6000_cpu == PROCESSOR_PPC603
10901 || rs6000_cpu == PROCESSOR_PPC750
10902 || optimize_size);
10903
10904 /* If we have a frame pointer, a call to alloca, or a large stack
10905 frame, restore the old stack pointer using the backchain. Otherwise,
10906 we know what size to update it with. */
10907 if (use_backchain_to_restore_sp)
bacbde18 10908 {
9ebbca7d
GK
10909 /* Under V.4, don't reset the stack pointer until after we're done
10910 loading the saved registers. */
f607bc57 10911 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 10912 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 10913
9ebbca7d
GK
10914 emit_move_insn (frame_reg_rtx,
10915 gen_rtx_MEM (Pmode, sp_reg_rtx));
10916
bacbde18 10917 }
9ebbca7d 10918 else if (info->push_p)
85638c0d 10919 {
f607bc57 10920 if (DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
10921 sp_offset = info->total_size;
10922 else
10923 {
10924 emit_insn (TARGET_32BIT
10925 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
10926 GEN_INT (info->total_size))
10927 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
10928 GEN_INT (info->total_size)));
10929 }
85638c0d 10930 }
9ebbca7d 10931
9aa86737
AH
10932 /* Restore AltiVec registers if needed. */
10933 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
10934 {
10935 int i;
10936
10937 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
10938 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
10939 {
10940 rtx addr, areg, mem;
10941
10942 areg = gen_rtx_REG (Pmode, 0);
10943 emit_move_insn
10944 (areg, GEN_INT (info->altivec_save_offset
10945 + sp_offset
10946 + 16 * (i - info->first_altivec_reg_save)));
10947
10948 /* AltiVec addressing mode is [reg+reg]. */
10949 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
10950 mem = gen_rtx_MEM (V4SImode, addr);
10951 set_mem_alias_set (mem, rs6000_sr_alias_set);
10952
10953 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
10954 }
10955 }
10956
10957 /* Restore VRSAVE if needed. */
10958 if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0)
10959 {
10960 rtx addr, mem, reg;
10961
10962 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10963 GEN_INT (info->vrsave_save_offset + sp_offset));
10964 mem = gen_rtx_MEM (SImode, addr);
10965 set_mem_alias_set (mem, rs6000_sr_alias_set);
10966 reg = gen_rtx_REG (SImode, 12);
10967 emit_move_insn (reg, mem);
10968
10969 emit_insn (generate_set_vrsave (reg, info, 1));
10970 }
10971
9ebbca7d
GK
10972 /* Get the old lr if we saved it. */
10973 if (info->lr_save_p)
b6c9286a 10974 {
a3170dc6
AH
10975 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
10976 info->lr_save_offset + sp_offset);
ba4828e0
RK
10977
10978 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 10979
9ebbca7d 10980 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 10981 }
9ebbca7d
GK
10982
10983 /* Get the old cr if we saved it. */
10984 if (info->cr_save_p)
10985 {
10986 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10987 GEN_INT (info->cr_save_offset + sp_offset));
10988 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
10989
10990 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 10991
9ebbca7d
GK
10992 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
10993 }
10994
10995 /* Set LR here to try to overlap restores below. */
4697a36c 10996 if (info->lr_save_p)
9ebbca7d
GK
10997 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
10998 gen_rtx_REG (Pmode, 0));
10999
83720594
RH
11000 /* Load exception handler data registers, if needed. */
11001 if (current_function_calls_eh_return)
11002 {
78e1b90d
DE
11003 unsigned int i, regno;
11004
83720594
RH
11005 for (i = 0; ; ++i)
11006 {
a3170dc6 11007 rtx mem;
83720594
RH
11008
11009 regno = EH_RETURN_DATA_REGNO (i);
11010 if (regno == INVALID_REGNUM)
11011 break;
11012
a3170dc6
AH
11013 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
11014 info->ehrd_offset + sp_offset
11015 + reg_size * (int) i);
ba4828e0 11016 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
11017
11018 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
11019 }
11020 }
9ebbca7d
GK
11021
11022 /* Restore GPRs. This is done as a PARALLEL if we are using
11023 the load-multiple instructions. */
11024 if (using_load_multiple)
979721f8 11025 {
9ebbca7d
GK
11026 rtvec p;
11027 p = rtvec_alloc (32 - info->first_gp_reg_save);
11028 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 11029 {
9ebbca7d
GK
11030 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11031 GEN_INT (info->gp_save_offset
11032 + sp_offset
11033 + reg_size * i));
11034 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
11035
11036 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11037
11038 RTVEC_ELT (p, i) =
11039 gen_rtx_SET (VOIDmode,
11040 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
11041 mem);
979721f8 11042 }
9ebbca7d 11043 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 11044 }
9ebbca7d
GK
11045 else
11046 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11047 if ((regs_ever_live[info->first_gp_reg_save+i]
11048 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11049 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11050 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11051 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
11052 {
11053 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11054 GEN_INT (info->gp_save_offset
11055 + sp_offset
11056 + reg_size * i));
11057 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11058
a3170dc6 11059 /* Restore 64-bit quantities for SPE. */
c19de7aa 11060 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11061 {
11062 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11063 rtx b;
11064
11065 if (!SPE_CONST_OFFSET_OK (offset))
11066 {
11067 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11068 emit_move_insn (b, GEN_INT (offset));
11069 }
11070 else
11071 b = GEN_INT (offset);
11072
11073 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11074 mem = gen_rtx_MEM (V2SImode, addr);
11075 }
11076
ba4828e0 11077 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11078
11079 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 11080 info->first_gp_reg_save + i), mem);
9ebbca7d 11081 }
9878760c 11082
9ebbca7d
GK
11083 /* Restore fpr's if we need to do it without calling a function. */
11084 if (restoring_FPRs_inline)
11085 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11086 if ((regs_ever_live[info->first_fp_reg_save+i]
11087 && ! call_used_regs[info->first_fp_reg_save+i]))
11088 {
11089 rtx addr, mem;
11090 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11091 GEN_INT (info->fp_save_offset
11092 + sp_offset
a4f6c312 11093 + 8 * i));
9ebbca7d 11094 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11095 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11096
11097 emit_move_insn (gen_rtx_REG (DFmode,
11098 info->first_fp_reg_save + i),
11099 mem);
11100 }
8d30c4ee 11101
9ebbca7d
GK
11102 /* If we saved cr, restore it here. Just those that were used. */
11103 if (info->cr_save_p)
979721f8 11104 {
9ebbca7d 11105 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 11106 int count = 0;
9ebbca7d
GK
11107
11108 if (using_mfcr_multiple)
979721f8 11109 {
9ebbca7d
GK
11110 for (i = 0; i < 8; i++)
11111 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 11112 count++;
9ebbca7d 11113 if (count == 0)
e35b9579
GK
11114 abort ();
11115 }
11116
11117 if (using_mfcr_multiple && count > 1)
11118 {
11119 rtvec p;
11120 int ndx;
9ebbca7d 11121
e35b9579 11122 p = rtvec_alloc (count);
9ebbca7d 11123
e35b9579 11124 ndx = 0;
9ebbca7d
GK
11125 for (i = 0; i < 8; i++)
11126 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
11127 {
11128 rtvec r = rtvec_alloc (2);
11129 RTVEC_ELT (r, 0) = r12_rtx;
11130 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 11131 RTVEC_ELT (p, ndx) =
9ebbca7d
GK
11132 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
11133 gen_rtx_UNSPEC (CCmode, r, 20));
e35b9579 11134 ndx++;
9ebbca7d
GK
11135 }
11136 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
11137 if (ndx != count)
11138 abort ();
979721f8
MM
11139 }
11140 else
9ebbca7d
GK
11141 for (i = 0; i < 8; i++)
11142 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 11143 {
9ebbca7d
GK
11144 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
11145 CR0_REGNO+i),
11146 r12_rtx));
979721f8 11147 }
979721f8
MM
11148 }
11149
9ebbca7d
GK
11150 /* If this is V.4, unwind the stack pointer after all of the loads
11151 have been done. We need to emit a block here so that sched
11152 doesn't decide to move the sp change before the register restores
11153 (which may not have any obvious dependency on the stack). This
11154 doesn't hurt performance, because there is no scheduling that can
11155 be done after this point. */
f607bc57 11156 if (DEFAULT_ABI == ABI_V4)
b6c9286a 11157 {
9ebbca7d
GK
11158 if (frame_reg_rtx != sp_reg_rtx)
11159 rs6000_emit_stack_tie ();
b6c9286a 11160
9ebbca7d 11161 if (use_backchain_to_restore_sp)
b6c9286a 11162 {
9ebbca7d 11163 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 11164 }
9ebbca7d 11165 else if (sp_offset != 0)
13f1623b 11166 {
5b71a4e7 11167 emit_insn (TARGET_32BIT
9ebbca7d
GK
11168 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
11169 GEN_INT (sp_offset))
11170 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
11171 GEN_INT (sp_offset)));
13f1623b 11172 }
9ebbca7d 11173 }
b6c9286a 11174
83720594
RH
11175 if (current_function_calls_eh_return)
11176 {
11177 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 11178 emit_insn (TARGET_32BIT
83720594
RH
11179 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
11180 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
11181 }
11182
9ebbca7d
GK
11183 if (!sibcall)
11184 {
11185 rtvec p;
11186 if (! restoring_FPRs_inline)
11187 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
11188 else
11189 p = rtvec_alloc (2);
b6c9286a 11190
e35b9579
GK
11191 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
11192 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
11193 gen_rtx_REG (Pmode,
11194 LINK_REGISTER_REGNUM));
9ebbca7d
GK
11195
11196 /* If we have to restore more than two FP registers, branch to the
11197 restore function. It will return to our caller. */
11198 if (! restoring_FPRs_inline)
11199 {
11200 int i;
11201 char rname[30];
520a57c8 11202 const char *alloc_rname;
979721f8 11203
9ebbca7d
GK
11204 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
11205 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 11206 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11207 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
11208 gen_rtx_SYMBOL_REF (Pmode,
11209 alloc_rname));
b6c9286a 11210
9ebbca7d
GK
11211 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11212 {
11213 rtx addr, mem;
11214 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
11215 GEN_INT (info->fp_save_offset + 8*i));
11216 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11217 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11218
11219 RTVEC_ELT (p, i+3) =
11220 gen_rtx_SET (VOIDmode,
11221 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
11222 mem);
b6c9286a
MM
11223 }
11224 }
9ebbca7d
GK
11225
11226 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 11227 }
9878760c
RK
11228}
11229
11230/* Write function epilogue. */
11231
08c148a8
NB
11232static void
11233rs6000_output_function_epilogue (file, size)
9878760c 11234 FILE *file;
08c148a8 11235 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9878760c 11236{
4697a36c 11237 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 11238
9ebbca7d 11239 if (! HAVE_epilogue)
9878760c 11240 {
9ebbca7d
GK
11241 rtx insn = get_last_insn ();
11242 /* If the last insn was a BARRIER, we don't have to write anything except
11243 the trace table. */
11244 if (GET_CODE (insn) == NOTE)
11245 insn = prev_nonnote_insn (insn);
11246 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 11247 {
9ebbca7d
GK
11248 /* This is slightly ugly, but at least we don't have two
11249 copies of the epilogue-emitting code. */
11250 start_sequence ();
11251
11252 /* A NOTE_INSN_DELETED is supposed to be at the start
11253 and end of the "toplevel" insn chain. */
11254 emit_note (0, NOTE_INSN_DELETED);
11255 rs6000_emit_epilogue (FALSE);
11256 emit_note (0, NOTE_INSN_DELETED);
11257
178c3eff
DJ
11258 /* Expand INSN_ADDRESSES so final() doesn't crash. */
11259 {
11260 rtx insn;
11261 unsigned addr = 0;
11262 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
11263 {
11264 INSN_ADDRESSES_NEW (insn, addr);
11265 addr += 4;
11266 }
11267 }
11268
9ebbca7d 11269 if (TARGET_DEBUG_STACK)
a4f6c312
SS
11270 debug_rtx_list (get_insns (), 100);
11271 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 11272 end_sequence ();
4697a36c 11273 }
9878760c 11274 }
b4ac57ab 11275
9b30bae2 11276 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
11277 on its format.
11278
11279 We don't output a traceback table if -finhibit-size-directive was
11280 used. The documentation for -finhibit-size-directive reads
11281 ``don't output a @code{.size} assembler directive, or anything
11282 else that would cause trouble if the function is split in the
11283 middle, and the two halves are placed at locations far apart in
11284 memory.'' The traceback table has this property, since it
11285 includes the offset from the start of the function to the
4d30c363
MM
11286 traceback table itself.
11287
11288 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 11289 different traceback table. */
57ac7be9
AM
11290 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
11291 && rs6000_traceback != traceback_none)
9b30bae2 11292 {
69c75916 11293 const char *fname = NULL;
3ac88239 11294 const char *language_string = lang_hooks.name;
6041bf2f 11295 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 11296 int i;
57ac7be9
AM
11297 int optional_tbtab;
11298
11299 if (rs6000_traceback == traceback_full)
11300 optional_tbtab = 1;
11301 else if (rs6000_traceback == traceback_part)
11302 optional_tbtab = 0;
11303 else
11304 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 11305
69c75916
AM
11306 if (optional_tbtab)
11307 {
11308 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
11309 while (*fname == '.') /* V.4 encodes . in the name */
11310 fname++;
11311
11312 /* Need label immediately before tbtab, so we can compute
11313 its offset from the function start. */
11314 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
11315 ASM_OUTPUT_LABEL (file, fname);
11316 }
314fc5a9
ILT
11317
11318 /* The .tbtab pseudo-op can only be used for the first eight
11319 expressions, since it can't handle the possibly variable
11320 length fields that follow. However, if you omit the optional
11321 fields, the assembler outputs zeros for all optional fields
11322 anyways, giving each variable length field is minimum length
11323 (as defined in sys/debug.h). Thus we can not use the .tbtab
11324 pseudo-op at all. */
11325
11326 /* An all-zero word flags the start of the tbtab, for debuggers
11327 that have to find it by searching forward from the entry
11328 point or from the current pc. */
19d2d16f 11329 fputs ("\t.long 0\n", file);
314fc5a9
ILT
11330
11331 /* Tbtab format type. Use format type 0. */
19d2d16f 11332 fputs ("\t.byte 0,", file);
314fc5a9
ILT
11333
11334 /* Language type. Unfortunately, there doesn't seem to be any
11335 official way to get this info, so we use language_string. C
11336 is 0. C++ is 9. No number defined for Obj-C, so use the
9517ead8 11337 value for C for now. There is no official value for Java,
6f573ff9 11338 although IBM appears to be using 13. There is no official value
f710504c 11339 for Chill, so we've chosen 44 pseudo-randomly. */
314fc5a9 11340 if (! strcmp (language_string, "GNU C")
e2c953b6 11341 || ! strcmp (language_string, "GNU Objective-C"))
314fc5a9
ILT
11342 i = 0;
11343 else if (! strcmp (language_string, "GNU F77"))
11344 i = 1;
11345 else if (! strcmp (language_string, "GNU Ada"))
11346 i = 3;
8b83775b 11347 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
11348 i = 2;
11349 else if (! strcmp (language_string, "GNU C++"))
11350 i = 9;
9517ead8
AG
11351 else if (! strcmp (language_string, "GNU Java"))
11352 i = 13;
6f573ff9
JL
11353 else if (! strcmp (language_string, "GNU CHILL"))
11354 i = 44;
314fc5a9
ILT
11355 else
11356 abort ();
11357 fprintf (file, "%d,", i);
11358
11359 /* 8 single bit fields: global linkage (not set for C extern linkage,
11360 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
11361 from start of procedure stored in tbtab, internal function, function
11362 has controlled storage, function has no toc, function uses fp,
11363 function logs/aborts fp operations. */
11364 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
11365 fprintf (file, "%d,",
11366 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
11367
11368 /* 6 bitfields: function is interrupt handler, name present in
11369 proc table, function calls alloca, on condition directives
11370 (controls stack walks, 3 bits), saves condition reg, saves
11371 link reg. */
11372 /* The `function calls alloca' bit seems to be set whenever reg 31 is
11373 set up as a frame pointer, even when there is no alloca call. */
11374 fprintf (file, "%d,",
6041bf2f
DE
11375 ((optional_tbtab << 6)
11376 | ((optional_tbtab & frame_pointer_needed) << 5)
11377 | (info->cr_save_p << 1)
11378 | (info->lr_save_p)));
314fc5a9 11379
6041bf2f 11380 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
11381 (6 bits). */
11382 fprintf (file, "%d,",
4697a36c 11383 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
11384
11385 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
11386 fprintf (file, "%d,", (32 - first_reg_to_save ()));
11387
6041bf2f
DE
11388 if (optional_tbtab)
11389 {
11390 /* Compute the parameter info from the function decl argument
11391 list. */
11392 tree decl;
11393 int next_parm_info_bit = 31;
314fc5a9 11394
6041bf2f
DE
11395 for (decl = DECL_ARGUMENTS (current_function_decl);
11396 decl; decl = TREE_CHAIN (decl))
11397 {
11398 rtx parameter = DECL_INCOMING_RTL (decl);
11399 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 11400
6041bf2f
DE
11401 if (GET_CODE (parameter) == REG)
11402 {
11403 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
11404 {
11405 int bits;
11406
11407 float_parms++;
11408
11409 if (mode == SFmode)
11410 bits = 0x2;
fcce224d 11411 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
11412 bits = 0x3;
11413 else
11414 abort ();
11415
11416 /* If only one bit will fit, don't or in this entry. */
11417 if (next_parm_info_bit > 0)
11418 parm_info |= (bits << (next_parm_info_bit - 1));
11419 next_parm_info_bit -= 2;
11420 }
11421 else
11422 {
11423 fixed_parms += ((GET_MODE_SIZE (mode)
11424 + (UNITS_PER_WORD - 1))
11425 / UNITS_PER_WORD);
11426 next_parm_info_bit -= 1;
11427 }
11428 }
11429 }
11430 }
314fc5a9
ILT
11431
11432 /* Number of fixed point parameters. */
11433 /* This is actually the number of words of fixed point parameters; thus
11434 an 8 byte struct counts as 2; and thus the maximum value is 8. */
11435 fprintf (file, "%d,", fixed_parms);
11436
11437 /* 2 bitfields: number of floating point parameters (7 bits), parameters
11438 all on stack. */
11439 /* This is actually the number of fp registers that hold parameters;
11440 and thus the maximum value is 13. */
11441 /* Set parameters on stack bit if parameters are not in their original
11442 registers, regardless of whether they are on the stack? Xlc
11443 seems to set the bit when not optimizing. */
11444 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
11445
6041bf2f
DE
11446 if (! optional_tbtab)
11447 return;
11448
314fc5a9
ILT
11449 /* Optional fields follow. Some are variable length. */
11450
11451 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
11452 11 double float. */
11453 /* There is an entry for each parameter in a register, in the order that
11454 they occur in the parameter list. Any intervening arguments on the
11455 stack are ignored. If the list overflows a long (max possible length
11456 34 bits) then completely leave off all elements that don't fit. */
11457 /* Only emit this long if there was at least one parameter. */
11458 if (fixed_parms || float_parms)
11459 fprintf (file, "\t.long %d\n", parm_info);
11460
11461 /* Offset from start of code to tb table. */
19d2d16f 11462 fputs ("\t.long ", file);
314fc5a9 11463 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
11464#if TARGET_AIX
11465 RS6000_OUTPUT_BASENAME (file, fname);
11466#else
9ebbca7d 11467 assemble_name (file, fname);
54ee9799 11468#endif
19d2d16f 11469 fputs ("-.", file);
54ee9799
DE
11470#if TARGET_AIX
11471 RS6000_OUTPUT_BASENAME (file, fname);
11472#else
9ebbca7d 11473 assemble_name (file, fname);
54ee9799 11474#endif
19d2d16f 11475 putc ('\n', file);
314fc5a9
ILT
11476
11477 /* Interrupt handler mask. */
11478 /* Omit this long, since we never set the interrupt handler bit
11479 above. */
11480
11481 /* Number of CTL (controlled storage) anchors. */
11482 /* Omit this long, since the has_ctl bit is never set above. */
11483
11484 /* Displacement into stack of each CTL anchor. */
11485 /* Omit this list of longs, because there are no CTL anchors. */
11486
11487 /* Length of function name. */
69c75916
AM
11488 if (*fname == '*')
11489 ++fname;
296b8152 11490 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
11491
11492 /* Function name. */
11493 assemble_string (fname, strlen (fname));
11494
11495 /* Register for alloca automatic storage; this is always reg 31.
11496 Only emit this if the alloca bit was set above. */
11497 if (frame_pointer_needed)
19d2d16f 11498 fputs ("\t.byte 31\n", file);
b1765bde
DE
11499
11500 fputs ("\t.align 2\n", file);
9b30bae2 11501 }
9878760c 11502}
17167fd8 11503\f
a4f6c312
SS
11504/* A C compound statement that outputs the assembler code for a thunk
11505 function, used to implement C++ virtual function calls with
11506 multiple inheritance. The thunk acts as a wrapper around a virtual
11507 function, adjusting the implicit object parameter before handing
11508 control off to the real function.
11509
11510 First, emit code to add the integer DELTA to the location that
11511 contains the incoming first argument. Assume that this argument
11512 contains a pointer, and is the one used to pass the `this' pointer
11513 in C++. This is the incoming argument *before* the function
11514 prologue, e.g. `%o0' on a sparc. The addition must preserve the
11515 values of all other incoming arguments.
17167fd8
MM
11516
11517 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
11518 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
11519 not touch the return address. Hence returning from FUNCTION will
11520 return to whoever called the current `thunk'.
17167fd8 11521
a4f6c312
SS
11522 The effect must be as if FUNCTION had been called directly with the
11523 adjusted first argument. This macro is responsible for emitting
11524 all of the code for a thunk function; output_function_prologue()
11525 and output_function_epilogue() are not invoked.
17167fd8 11526
a4f6c312
SS
11527 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
11528 been extracted from it.) It might possibly be useful on some
11529 targets, but probably not.
17167fd8 11530
a4f6c312
SS
11531 If you do not define this macro, the target-independent code in the
11532 C++ frontend will generate a less efficient heavyweight thunk that
11533 calls FUNCTION instead of jumping to it. The generic approach does
11534 not support varargs. */
17167fd8 11535
3961e8fe
RH
11536static void
11537rs6000_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
17167fd8 11538 FILE *file;
d330fd93 11539 tree thunk_fndecl ATTRIBUTE_UNUSED;
eb0424da 11540 HOST_WIDE_INT delta;
5b71a4e7 11541 HOST_WIDE_INT vcall_offset;
17167fd8
MM
11542 tree function;
11543{
5b71a4e7 11544 rtx this, insn, funexp;
17167fd8 11545
5b71a4e7
DE
11546 reload_completed = 1;
11547 no_new_pseudos = 1;
56a7189a 11548
5b71a4e7
DE
11549 /* Mark the end of the (empty) prologue. */
11550 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
17167fd8 11551
5b71a4e7
DE
11552 /* Find the "this" pointer. If the function returns a structure,
11553 the structure return pointer is in r3. */
11554 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
11555 this = gen_rtx_REG (Pmode, 4);
56a7189a 11556 else
5b71a4e7 11557 this = gen_rtx_REG (Pmode, 3);
17167fd8 11558
5b71a4e7
DE
11559 /* Apply the constant offset, if required. */
11560 if (delta)
11561 {
11562 rtx delta_rtx = GEN_INT (delta);
11563 emit_insn (TARGET_32BIT
11564 ? gen_addsi3 (this, this, delta_rtx)
11565 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
11566 }
11567
5b71a4e7
DE
11568 /* Apply the offset from the vtable, if required. */
11569 if (vcall_offset)
17167fd8 11570 {
5b71a4e7
DE
11571 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
11572 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 11573
5b71a4e7
DE
11574 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
11575 emit_insn (TARGET_32BIT
11576 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
11577 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
11578 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
11579 emit_insn (TARGET_32BIT
11580 ? gen_addsi3 (this, this, tmp)
11581 : gen_adddi3 (this, this, tmp));
17167fd8
MM
11582 }
11583
5b71a4e7
DE
11584 /* Generate a tail call to the target function. */
11585 if (!TREE_USED (function))
11586 {
11587 assemble_external (function);
11588 TREE_USED (function) = 1;
11589 }
11590 funexp = XEXP (DECL_RTL (function), 0);
42820a49 11591
5b71a4e7
DE
11592 SYMBOL_REF_FLAG (funexp) = 0;
11593 if (current_file_function_operand (funexp, VOIDmode)
a5c76ee6
ZW
11594 && (! lookup_attribute ("longcall",
11595 TYPE_ATTRIBUTES (TREE_TYPE (function)))
11596 || lookup_attribute ("shortcall",
11597 TYPE_ATTRIBUTES (TREE_TYPE (function)))))
5b71a4e7 11598 SYMBOL_REF_FLAG (funexp) = 1;
17167fd8 11599
5b71a4e7 11600 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
11601
11602#if TARGET_MACHO
ab82a49f 11603 if (MACHOPIC_INDIRECT)
5b71a4e7 11604 funexp = machopic_indirect_call_target (funexp);
ee890fe2 11605#endif
5b71a4e7
DE
11606
11607 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
11608 generate sibcall RTL explicitly to avoid constraint abort. */
11609 insn = emit_call_insn (
11610 gen_rtx_PARALLEL (VOIDmode,
11611 gen_rtvec (4,
11612 gen_rtx_CALL (VOIDmode,
11613 funexp, const0_rtx),
11614 gen_rtx_USE (VOIDmode, const0_rtx),
11615 gen_rtx_USE (VOIDmode,
11616 gen_rtx_REG (SImode,
11617 LINK_REGISTER_REGNUM)),
11618 gen_rtx_RETURN (VOIDmode))));
11619 SIBLING_CALL_P (insn) = 1;
11620 emit_barrier ();
11621
11622 /* Run just enough of rest_of_compilation to get the insns emitted.
11623 There's not really enough bulk here to make other passes such as
11624 instruction scheduling worth while. Note that use_thunk calls
11625 assemble_start_function and assemble_end_function. */
11626 insn = get_insns ();
11627 shorten_branches (insn);
11628 final_start_function (insn, file, 1);
11629 final (insn, file, 1, 0);
11630 final_end_function ();
11631
11632 reload_completed = 0;
11633 no_new_pseudos = 0;
9ebbca7d 11634}
9ebbca7d
GK
11635\f
11636/* A quick summary of the various types of 'constant-pool tables'
11637 under PowerPC:
11638
11639 Target Flags Name One table per
11640 AIX (none) AIX TOC object file
11641 AIX -mfull-toc AIX TOC object file
11642 AIX -mminimal-toc AIX minimal TOC translation unit
11643 SVR4/EABI (none) SVR4 SDATA object file
11644 SVR4/EABI -fpic SVR4 pic object file
11645 SVR4/EABI -fPIC SVR4 PIC translation unit
11646 SVR4/EABI -mrelocatable EABI TOC function
11647 SVR4/EABI -maix AIX TOC object file
11648 SVR4/EABI -maix -mminimal-toc
11649 AIX minimal TOC translation unit
11650
11651 Name Reg. Set by entries contains:
11652 made by addrs? fp? sum?
11653
11654 AIX TOC 2 crt0 as Y option option
11655 AIX minimal TOC 30 prolog gcc Y Y option
11656 SVR4 SDATA 13 crt0 gcc N Y N
11657 SVR4 pic 30 prolog ld Y not yet N
11658 SVR4 PIC 30 prolog gcc Y option option
11659 EABI TOC 30 prolog gcc Y option option
11660
11661*/
11662
9ebbca7d
GK
11663/* Hash functions for the hash table. */
11664
11665static unsigned
11666rs6000_hash_constant (k)
11667 rtx k;
11668{
46b33600
RH
11669 enum rtx_code code = GET_CODE (k);
11670 enum machine_mode mode = GET_MODE (k);
11671 unsigned result = (code << 3) ^ mode;
11672 const char *format;
11673 int flen, fidx;
9ebbca7d 11674
46b33600
RH
11675 format = GET_RTX_FORMAT (code);
11676 flen = strlen (format);
11677 fidx = 0;
9ebbca7d 11678
46b33600
RH
11679 switch (code)
11680 {
11681 case LABEL_REF:
11682 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
11683
11684 case CONST_DOUBLE:
11685 if (mode != VOIDmode)
11686 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
11687 flen = 2;
11688 break;
11689
11690 case CODE_LABEL:
11691 fidx = 3;
11692 break;
11693
11694 default:
11695 break;
11696 }
9ebbca7d
GK
11697
11698 for (; fidx < flen; fidx++)
11699 switch (format[fidx])
11700 {
11701 case 's':
11702 {
11703 unsigned i, len;
11704 const char *str = XSTR (k, fidx);
11705 len = strlen (str);
11706 result = result * 613 + len;
11707 for (i = 0; i < len; i++)
11708 result = result * 613 + (unsigned) str[i];
17167fd8
MM
11709 break;
11710 }
9ebbca7d
GK
11711 case 'u':
11712 case 'e':
11713 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
11714 break;
11715 case 'i':
11716 case 'n':
11717 result = result * 613 + (unsigned) XINT (k, fidx);
11718 break;
11719 case 'w':
11720 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
11721 result = result * 613 + (unsigned) XWINT (k, fidx);
11722 else
11723 {
11724 size_t i;
11725 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
11726 result = result * 613 + (unsigned) (XWINT (k, fidx)
11727 >> CHAR_BIT * i);
11728 }
11729 break;
11730 default:
a4f6c312 11731 abort ();
9ebbca7d 11732 }
46b33600 11733
9ebbca7d
GK
11734 return result;
11735}
11736
11737static unsigned
11738toc_hash_function (hash_entry)
11739 const void * hash_entry;
11740{
a9098fd0
GK
11741 const struct toc_hash_struct *thc =
11742 (const struct toc_hash_struct *) hash_entry;
11743 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
11744}
11745
11746/* Compare H1 and H2 for equivalence. */
11747
11748static int
11749toc_hash_eq (h1, h2)
11750 const void * h1;
11751 const void * h2;
11752{
11753 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
11754 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
11755
a9098fd0
GK
11756 if (((const struct toc_hash_struct *) h1)->key_mode
11757 != ((const struct toc_hash_struct *) h2)->key_mode)
11758 return 0;
11759
5692c7bc 11760 return rtx_equal_p (r1, r2);
9ebbca7d
GK
11761}
11762
28e510bd
MM
11763/* These are the names given by the C++ front-end to vtables, and
11764 vtable-like objects. Ideally, this logic should not be here;
11765 instead, there should be some programmatic way of inquiring as
11766 to whether or not an object is a vtable. */
11767
11768#define VTABLE_NAME_P(NAME) \
11769 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
11770 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
11771 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
11772 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
11773
11774void
11775rs6000_output_symbol_ref (file, x)
11776 FILE *file;
11777 rtx x;
11778{
11779 /* Currently C++ toc references to vtables can be emitted before it
11780 is decided whether the vtable is public or private. If this is
11781 the case, then the linker will eventually complain that there is
11782 a reference to an unknown section. Thus, for vtables only,
11783 we emit the TOC reference to reference the symbol and not the
11784 section. */
11785 const char *name = XSTR (x, 0);
54ee9799
DE
11786
11787 if (VTABLE_NAME_P (name))
11788 {
11789 RS6000_OUTPUT_BASENAME (file, name);
11790 }
11791 else
11792 assemble_name (file, name);
28e510bd
MM
11793}
11794
a4f6c312
SS
11795/* Output a TOC entry. We derive the entry name from what is being
11796 written. */
9878760c
RK
11797
11798void
a9098fd0 11799output_toc (file, x, labelno, mode)
9878760c
RK
11800 FILE *file;
11801 rtx x;
11802 int labelno;
a9098fd0 11803 enum machine_mode mode;
9878760c
RK
11804{
11805 char buf[256];
3cce094d 11806 const char *name = buf;
ec940faa 11807 const char *real_name;
9878760c
RK
11808 rtx base = x;
11809 int offset = 0;
11810
4697a36c
MM
11811 if (TARGET_NO_TOC)
11812 abort ();
11813
9ebbca7d
GK
11814 /* When the linker won't eliminate them, don't output duplicate
11815 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
11816 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
11817 CODE_LABELs. */
11818 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
11819 {
11820 struct toc_hash_struct *h;
11821 void * * found;
11822
17211ab5
GK
11823 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
11824 time because GGC is not initialised at that point. */
11825 if (toc_hash_table == NULL)
11826 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
11827 toc_hash_eq, NULL);
11828
9ebbca7d
GK
11829 h = ggc_alloc (sizeof (*h));
11830 h->key = x;
a9098fd0 11831 h->key_mode = mode;
9ebbca7d
GK
11832 h->labelno = labelno;
11833
11834 found = htab_find_slot (toc_hash_table, h, 1);
11835 if (*found == NULL)
11836 *found = h;
11837 else /* This is indeed a duplicate.
11838 Set this label equal to that label. */
11839 {
11840 fputs ("\t.set ", file);
11841 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
11842 fprintf (file, "%d,", labelno);
11843 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
11844 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
11845 found)->labelno));
11846 return;
11847 }
11848 }
11849
11850 /* If we're going to put a double constant in the TOC, make sure it's
11851 aligned properly when strict alignment is on. */
ff1720ed
RK
11852 if (GET_CODE (x) == CONST_DOUBLE
11853 && STRICT_ALIGNMENT
a9098fd0 11854 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
11855 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
11856 ASM_OUTPUT_ALIGN (file, 3);
11857 }
11858
4977bab6 11859 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 11860
37c37a57
RK
11861 /* Handle FP constants specially. Note that if we have a minimal
11862 TOC, things we put here aren't actually in the TOC, so we can allow
11863 FP constants. */
fcce224d
DE
11864 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
11865 {
11866 REAL_VALUE_TYPE rv;
11867 long k[4];
11868
11869 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11870 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
11871
11872 if (TARGET_64BIT)
11873 {
11874 if (TARGET_MINIMAL_TOC)
11875 fputs (DOUBLE_INT_ASM_OP, file);
11876 else
11877 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
11878 k[0] & 0xffffffff, k[1] & 0xffffffff,
11879 k[2] & 0xffffffff, k[3] & 0xffffffff);
11880 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
11881 k[0] & 0xffffffff, k[1] & 0xffffffff,
11882 k[2] & 0xffffffff, k[3] & 0xffffffff);
11883 return;
11884 }
11885 else
11886 {
11887 if (TARGET_MINIMAL_TOC)
11888 fputs ("\t.long ", file);
11889 else
11890 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
11891 k[0] & 0xffffffff, k[1] & 0xffffffff,
11892 k[2] & 0xffffffff, k[3] & 0xffffffff);
11893 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
11894 k[0] & 0xffffffff, k[1] & 0xffffffff,
11895 k[2] & 0xffffffff, k[3] & 0xffffffff);
11896 return;
11897 }
11898 }
11899 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 11900 {
042259f2
DE
11901 REAL_VALUE_TYPE rv;
11902 long k[2];
0adc764e 11903
042259f2
DE
11904 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11905 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 11906
13ded975
DE
11907 if (TARGET_64BIT)
11908 {
11909 if (TARGET_MINIMAL_TOC)
2bfcf297 11910 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 11911 else
2f0552b6
AM
11912 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
11913 k[0] & 0xffffffff, k[1] & 0xffffffff);
11914 fprintf (file, "0x%lx%08lx\n",
11915 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
11916 return;
11917 }
1875cc88 11918 else
13ded975
DE
11919 {
11920 if (TARGET_MINIMAL_TOC)
2bfcf297 11921 fputs ("\t.long ", file);
13ded975 11922 else
2f0552b6
AM
11923 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
11924 k[0] & 0xffffffff, k[1] & 0xffffffff);
11925 fprintf (file, "0x%lx,0x%lx\n",
11926 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
11927 return;
11928 }
9878760c 11929 }
a9098fd0 11930 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 11931 {
042259f2
DE
11932 REAL_VALUE_TYPE rv;
11933 long l;
9878760c 11934
042259f2
DE
11935 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11936 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
11937
31bfaa0b
DE
11938 if (TARGET_64BIT)
11939 {
11940 if (TARGET_MINIMAL_TOC)
2bfcf297 11941 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 11942 else
2f0552b6
AM
11943 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
11944 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
11945 return;
11946 }
042259f2 11947 else
31bfaa0b
DE
11948 {
11949 if (TARGET_MINIMAL_TOC)
2bfcf297 11950 fputs ("\t.long ", file);
31bfaa0b 11951 else
2f0552b6
AM
11952 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
11953 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
11954 return;
11955 }
042259f2 11956 }
f176e826 11957 else if (GET_MODE (x) == VOIDmode
a9098fd0 11958 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 11959 {
e2c953b6 11960 unsigned HOST_WIDE_INT low;
042259f2
DE
11961 HOST_WIDE_INT high;
11962
11963 if (GET_CODE (x) == CONST_DOUBLE)
11964 {
11965 low = CONST_DOUBLE_LOW (x);
11966 high = CONST_DOUBLE_HIGH (x);
11967 }
11968 else
11969#if HOST_BITS_PER_WIDE_INT == 32
11970 {
11971 low = INTVAL (x);
0858c623 11972 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
11973 }
11974#else
11975 {
0858c623 11976 low = INTVAL (x) & 0xffffffff;
042259f2
DE
11977 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
11978 }
11979#endif
9878760c 11980
a9098fd0
GK
11981 /* TOC entries are always Pmode-sized, but since this
11982 is a bigendian machine then if we're putting smaller
11983 integer constants in the TOC we have to pad them.
11984 (This is still a win over putting the constants in
11985 a separate constant pool, because then we'd have
02a4ec28
FS
11986 to have both a TOC entry _and_ the actual constant.)
11987
11988 For a 32-bit target, CONST_INT values are loaded and shifted
11989 entirely within `low' and can be stored in one TOC entry. */
11990
11991 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 11992 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
11993
11994 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
11995 {
11996#if HOST_BITS_PER_WIDE_INT == 32
11997 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
11998 POINTER_SIZE, &low, &high, 0);
11999#else
12000 low |= high << 32;
12001 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
12002 high = (HOST_WIDE_INT) low >> 32;
12003 low &= 0xffffffff;
12004#endif
12005 }
a9098fd0 12006
13ded975
DE
12007 if (TARGET_64BIT)
12008 {
12009 if (TARGET_MINIMAL_TOC)
2bfcf297 12010 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 12011 else
2f0552b6
AM
12012 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
12013 (long) high & 0xffffffff, (long) low & 0xffffffff);
12014 fprintf (file, "0x%lx%08lx\n",
12015 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
12016 return;
12017 }
1875cc88 12018 else
13ded975 12019 {
02a4ec28
FS
12020 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
12021 {
12022 if (TARGET_MINIMAL_TOC)
2bfcf297 12023 fputs ("\t.long ", file);
02a4ec28 12024 else
2bfcf297 12025 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
12026 (long) high & 0xffffffff, (long) low & 0xffffffff);
12027 fprintf (file, "0x%lx,0x%lx\n",
12028 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 12029 }
13ded975 12030 else
02a4ec28
FS
12031 {
12032 if (TARGET_MINIMAL_TOC)
2bfcf297 12033 fputs ("\t.long ", file);
02a4ec28 12034 else
2f0552b6
AM
12035 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
12036 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 12037 }
13ded975
DE
12038 return;
12039 }
9878760c
RK
12040 }
12041
12042 if (GET_CODE (x) == CONST)
12043 {
2bfcf297
DB
12044 if (GET_CODE (XEXP (x, 0)) != PLUS)
12045 abort ();
12046
9878760c
RK
12047 base = XEXP (XEXP (x, 0), 0);
12048 offset = INTVAL (XEXP (XEXP (x, 0), 1));
12049 }
12050
12051 if (GET_CODE (base) == SYMBOL_REF)
12052 name = XSTR (base, 0);
12053 else if (GET_CODE (base) == LABEL_REF)
12054 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
12055 else if (GET_CODE (base) == CODE_LABEL)
12056 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
12057 else
12058 abort ();
12059
772c5265 12060 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 12061 if (TARGET_MINIMAL_TOC)
2bfcf297 12062 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
12063 else
12064 {
b6c9286a 12065 fprintf (file, "\t.tc %s", real_name);
9878760c 12066
1875cc88
JW
12067 if (offset < 0)
12068 fprintf (file, ".N%d", - offset);
12069 else if (offset)
12070 fprintf (file, ".P%d", offset);
9878760c 12071
19d2d16f 12072 fputs ("[TC],", file);
1875cc88 12073 }
581bc4de
MM
12074
12075 /* Currently C++ toc references to vtables can be emitted before it
12076 is decided whether the vtable is public or private. If this is
12077 the case, then the linker will eventually complain that there is
12078 a TOC reference to an unknown section. Thus, for vtables only,
12079 we emit the TOC reference to reference the symbol and not the
12080 section. */
28e510bd 12081 if (VTABLE_NAME_P (name))
581bc4de 12082 {
54ee9799 12083 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
12084 if (offset < 0)
12085 fprintf (file, "%d", offset);
12086 else if (offset > 0)
12087 fprintf (file, "+%d", offset);
12088 }
12089 else
12090 output_addr_const (file, x);
19d2d16f 12091 putc ('\n', file);
9878760c
RK
12092}
12093\f
12094/* Output an assembler pseudo-op to write an ASCII string of N characters
12095 starting at P to FILE.
12096
12097 On the RS/6000, we have to do this using the .byte operation and
12098 write out special characters outside the quoted string.
12099 Also, the assembler is broken; very long strings are truncated,
a4f6c312 12100 so we must artificially break them up early. */
9878760c
RK
12101
12102void
12103output_ascii (file, p, n)
12104 FILE *file;
d330fd93 12105 const char *p;
9878760c
RK
12106 int n;
12107{
12108 char c;
12109 int i, count_string;
d330fd93
KG
12110 const char *for_string = "\t.byte \"";
12111 const char *for_decimal = "\t.byte ";
12112 const char *to_close = NULL;
9878760c
RK
12113
12114 count_string = 0;
12115 for (i = 0; i < n; i++)
12116 {
12117 c = *p++;
12118 if (c >= ' ' && c < 0177)
12119 {
12120 if (for_string)
12121 fputs (for_string, file);
12122 putc (c, file);
12123
12124 /* Write two quotes to get one. */
12125 if (c == '"')
12126 {
12127 putc (c, file);
12128 ++count_string;
12129 }
12130
12131 for_string = NULL;
12132 for_decimal = "\"\n\t.byte ";
12133 to_close = "\"\n";
12134 ++count_string;
12135
12136 if (count_string >= 512)
12137 {
12138 fputs (to_close, file);
12139
12140 for_string = "\t.byte \"";
12141 for_decimal = "\t.byte ";
12142 to_close = NULL;
12143 count_string = 0;
12144 }
12145 }
12146 else
12147 {
12148 if (for_decimal)
12149 fputs (for_decimal, file);
12150 fprintf (file, "%d", c);
12151
12152 for_string = "\n\t.byte \"";
12153 for_decimal = ", ";
12154 to_close = "\n";
12155 count_string = 0;
12156 }
12157 }
12158
12159 /* Now close the string if we have written one. Then end the line. */
12160 if (to_close)
9ebbca7d 12161 fputs (to_close, file);
9878760c
RK
12162}
12163\f
12164/* Generate a unique section name for FILENAME for a section type
12165 represented by SECTION_DESC. Output goes into BUF.
12166
12167 SECTION_DESC can be any string, as long as it is different for each
12168 possible section type.
12169
12170 We name the section in the same manner as xlc. The name begins with an
12171 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
12172 names) with the last period replaced by the string SECTION_DESC. If
12173 FILENAME does not contain a period, SECTION_DESC is appended to the end of
12174 the name. */
9878760c
RK
12175
12176void
12177rs6000_gen_section_name (buf, filename, section_desc)
12178 char **buf;
9ebbca7d
GK
12179 const char *filename;
12180 const char *section_desc;
9878760c 12181{
9ebbca7d 12182 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
12183 char *p;
12184 int len;
9878760c
RK
12185
12186 after_last_slash = filename;
12187 for (q = filename; *q; q++)
11e5fe42
RK
12188 {
12189 if (*q == '/')
12190 after_last_slash = q + 1;
12191 else if (*q == '.')
12192 last_period = q;
12193 }
9878760c 12194
11e5fe42 12195 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 12196 *buf = (char *) xmalloc (len);
9878760c
RK
12197
12198 p = *buf;
12199 *p++ = '_';
12200
12201 for (q = after_last_slash; *q; q++)
12202 {
11e5fe42 12203 if (q == last_period)
9878760c
RK
12204 {
12205 strcpy (p, section_desc);
12206 p += strlen (section_desc);
e3981aab 12207 break;
9878760c
RK
12208 }
12209
e9a780ec 12210 else if (ISALNUM (*q))
9878760c
RK
12211 *p++ = *q;
12212 }
12213
11e5fe42 12214 if (last_period == 0)
9878760c
RK
12215 strcpy (p, section_desc);
12216 else
12217 *p = '\0';
12218}
e165f3f0 12219\f
a4f6c312 12220/* Emit profile function. */
411707f4 12221
411707f4
CC
12222void
12223output_profile_hook (labelno)
57ac7be9 12224 int labelno ATTRIBUTE_UNUSED;
411707f4 12225{
8480e480
CC
12226 if (DEFAULT_ABI == ABI_AIX)
12227 {
57ac7be9
AM
12228#ifdef NO_PROFILE_COUNTERS
12229 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
12230#else
8480e480 12231 char buf[30];
40501e5f 12232 const char *label_name;
8480e480 12233 rtx fun;
411707f4 12234
8480e480 12235 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
772c5265 12236 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
8480e480 12237 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 12238
8480e480
CC
12239 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
12240 fun, Pmode);
57ac7be9 12241#endif
8480e480 12242 }
ee890fe2
SS
12243 else if (DEFAULT_ABI == ABI_DARWIN)
12244 {
d5fa86ba 12245 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
12246 int caller_addr_regno = LINK_REGISTER_REGNUM;
12247
12248 /* Be conservative and always set this, at least for now. */
12249 current_function_uses_pic_offset_table = 1;
12250
12251#if TARGET_MACHO
12252 /* For PIC code, set up a stub and collect the caller's address
12253 from r0, which is where the prologue puts it. */
ab82a49f 12254 if (MACHOPIC_INDIRECT)
ee890fe2
SS
12255 {
12256 mcount_name = machopic_stub_name (mcount_name);
12257 if (current_function_uses_pic_offset_table)
12258 caller_addr_regno = 0;
12259 }
12260#endif
12261 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
12262 0, VOIDmode, 1,
12263 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
12264 }
411707f4
CC
12265}
12266
a4f6c312 12267/* Write function profiler code. */
e165f3f0
RK
12268
12269void
12270output_function_profiler (file, labelno)
12271 FILE *file;
12272 int labelno;
12273{
3daf36a4 12274 char buf[100];
09eeeacb 12275 int save_lr = 8;
e165f3f0 12276
3daf36a4 12277 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7 12278 switch (DEFAULT_ABI)
3daf36a4 12279 {
38c1f2d7
MM
12280 default:
12281 abort ();
12282
12283 case ABI_V4:
09eeeacb
AM
12284 save_lr = 4;
12285 /* Fall through. */
12286
38c1f2d7 12287 case ABI_AIX_NODESC:
09eeeacb
AM
12288 if (!TARGET_32BIT)
12289 {
12290 warning ("no profiling of 64-bit code for this ABI");
12291 return;
12292 }
38c1f2d7
MM
12293 fprintf (file, "\tmflr %s\n", reg_names[0]);
12294 if (flag_pic == 1)
12295 {
dfdfa60f 12296 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
12297 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12298 reg_names[0], save_lr, reg_names[1]);
17167fd8 12299 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 12300 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 12301 assemble_name (file, buf);
17167fd8 12302 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 12303 }
9ebbca7d 12304 else if (flag_pic > 1)
38c1f2d7 12305 {
09eeeacb
AM
12306 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12307 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
12308 /* Now, we need to get the address of the label. */
12309 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 12310 assemble_name (file, buf);
9ebbca7d
GK
12311 fputs ("-.\n1:", file);
12312 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
12313 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
12314 reg_names[0], reg_names[11]);
12315 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
12316 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 12317 }
38c1f2d7
MM
12318 else
12319 {
17167fd8 12320 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 12321 assemble_name (file, buf);
dfdfa60f 12322 fputs ("@ha\n", file);
09eeeacb
AM
12323 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12324 reg_names[0], save_lr, reg_names[1]);
a260abc9 12325 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 12326 assemble_name (file, buf);
17167fd8 12327 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
12328 }
12329
09eeeacb
AM
12330 if (current_function_needs_context && DEFAULT_ABI == ABI_AIX_NODESC)
12331 {
12332 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12333 reg_names[STATIC_CHAIN_REGNUM],
12334 12, reg_names[1]);
12335 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
12336 asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n",
12337 reg_names[STATIC_CHAIN_REGNUM],
12338 12, reg_names[1]);
12339 }
12340 else
12341 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
12342 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
38c1f2d7
MM
12343 break;
12344
12345 case ABI_AIX:
ee890fe2 12346 case ABI_DARWIN:
a4f6c312 12347 /* Don't do anything, done in output_profile_hook (). */
38c1f2d7
MM
12348 break;
12349 }
e165f3f0 12350}
a251ffd0 12351
b54cf83a
DE
12352\f
12353static int
12354rs6000_use_dfa_pipeline_interface ()
12355{
12356 return 1;
12357}
12358
b54cf83a
DE
12359/* Power4 load update and store update instructions are cracked into a
12360 load or store and an integer insn which are executed in the same cycle.
12361 Branches have their own dispatch slot which does not count against the
12362 GCC issue rate, but it changes the program flow so there are no other
12363 instructions to issue in this cycle. */
12364
12365static int
12366rs6000_variable_issue (stream, verbose, insn, more)
12367 FILE *stream ATTRIBUTE_UNUSED;
12368 int verbose ATTRIBUTE_UNUSED;
12369 rtx insn;
12370 int more;
12371{
12372 if (GET_CODE (PATTERN (insn)) == USE
12373 || GET_CODE (PATTERN (insn)) == CLOBBER)
12374 return more;
12375
12376 if (rs6000_cpu == PROCESSOR_POWER4)
12377 {
12378 enum attr_type type = get_attr_type (insn);
12379 if (type == TYPE_LOAD_EXT_U || type == TYPE_LOAD_EXT_UX
12380 || type == TYPE_LOAD_UX || type == TYPE_STORE_UX
12381 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX)
12382 return 0;
12383 else if (type == TYPE_LOAD_U || type == TYPE_STORE_U
12384 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
12385 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR)
3317bab1 12386 return more > 2 ? more - 2 : 0;
b54cf83a 12387 }
165b263e
DE
12388
12389 return more - 1;
b54cf83a
DE
12390}
12391
a251ffd0
TG
12392/* Adjust the cost of a scheduling dependency. Return the new cost of
12393 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
12394
c237e94a 12395static int
a06faf84 12396rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
12397 rtx insn;
12398 rtx link;
296b8152 12399 rtx dep_insn ATTRIBUTE_UNUSED;
a251ffd0
TG
12400 int cost;
12401{
12402 if (! recog_memoized (insn))
12403 return 0;
12404
12405 if (REG_NOTE_KIND (link) != 0)
12406 return 0;
12407
12408 if (REG_NOTE_KIND (link) == 0)
12409 {
ed947a96
DJ
12410 /* Data dependency; DEP_INSN writes a register that INSN reads
12411 some cycles later. */
12412 switch (get_attr_type (insn))
12413 {
12414 case TYPE_JMPREG:
309323c2 12415 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
12416 a mtctr and bctr (and mtlr and br/blr). The first
12417 scheduling pass will not know about this latency since
12418 the mtctr instruction, which has the latency associated
12419 to it, will be generated by reload. */
309323c2 12420 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
12421 case TYPE_BRANCH:
12422 /* Leave some extra cycles between a compare and its
12423 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
12424 if ((rs6000_cpu_attr == CPU_PPC603
12425 || rs6000_cpu_attr == CPU_PPC604
12426 || rs6000_cpu_attr == CPU_PPC604E
12427 || rs6000_cpu_attr == CPU_PPC620
12428 || rs6000_cpu_attr == CPU_PPC630
12429 || rs6000_cpu_attr == CPU_PPC750
12430 || rs6000_cpu_attr == CPU_PPC7400
12431 || rs6000_cpu_attr == CPU_PPC7450
12432 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
12433 && recog_memoized (dep_insn)
12434 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
12435 && (get_attr_type (dep_insn) == TYPE_CMP
12436 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96
DJ
12437 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
12438 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
12439 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
12440 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
12441 return cost + 2;
12442 default:
12443 break;
12444 }
a251ffd0
TG
12445 /* Fall out to return default cost. */
12446 }
12447
12448 return cost;
12449}
b6c9286a 12450
a4f6c312
SS
12451/* A C statement (sans semicolon) to update the integer scheduling
12452 priority INSN_PRIORITY (INSN). Reduce the priority to execute the
12453 INSN earlier, increase the priority to execute INSN later. Do not
12454 define this macro if you do not need to adjust the scheduling
12455 priorities of insns. */
bef84347 12456
c237e94a 12457static int
bef84347 12458rs6000_adjust_priority (insn, priority)
d330fd93 12459 rtx insn ATTRIBUTE_UNUSED;
bef84347
VM
12460 int priority;
12461{
a4f6c312
SS
12462 /* On machines (like the 750) which have asymmetric integer units,
12463 where one integer unit can do multiply and divides and the other
12464 can't, reduce the priority of multiply/divide so it is scheduled
12465 before other integer operations. */
bef84347
VM
12466
12467#if 0
2c3c49de 12468 if (! INSN_P (insn))
bef84347
VM
12469 return priority;
12470
12471 if (GET_CODE (PATTERN (insn)) == USE)
12472 return priority;
12473
12474 switch (rs6000_cpu_attr) {
12475 case CPU_PPC750:
12476 switch (get_attr_type (insn))
12477 {
12478 default:
12479 break;
12480
12481 case TYPE_IMUL:
12482 case TYPE_IDIV:
3cb999d8
DE
12483 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
12484 priority, priority);
bef84347
VM
12485 if (priority >= 0 && priority < 0x01000000)
12486 priority >>= 3;
12487 break;
12488 }
12489 }
12490#endif
12491
12492 return priority;
12493}
12494
a4f6c312
SS
12495/* Return how many instructions the machine can issue per cycle. */
12496
c237e94a
ZW
12497static int
12498rs6000_issue_rate ()
b6c9286a 12499{
3317bab1
DE
12500 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
12501 if (!reload_completed)
12502 return 1;
12503
b6c9286a 12504 switch (rs6000_cpu_attr) {
3cb999d8
DE
12505 case CPU_RIOS1: /* ? */
12506 case CPU_RS64A:
12507 case CPU_PPC601: /* ? */
ed947a96 12508 case CPU_PPC7450:
3cb999d8 12509 return 3;
b54cf83a 12510 case CPU_PPC440:
b6c9286a 12511 case CPU_PPC603:
bef84347 12512 case CPU_PPC750:
ed947a96 12513 case CPU_PPC7400:
bef84347 12514 return 2;
3cb999d8 12515 case CPU_RIOS2:
b6c9286a 12516 case CPU_PPC604:
19684119 12517 case CPU_PPC604E:
b6c9286a 12518 case CPU_PPC620:
3cb999d8 12519 case CPU_PPC630:
309323c2 12520 case CPU_POWER4:
b6c9286a
MM
12521 return 4;
12522 default:
12523 return 1;
12524 }
12525}
12526
b6c9286a 12527\f
b6c9286a
MM
12528/* Length in units of the trampoline for entering a nested function. */
12529
12530int
12531rs6000_trampoline_size ()
12532{
12533 int ret = 0;
12534
12535 switch (DEFAULT_ABI)
12536 {
12537 default:
12538 abort ();
12539
12540 case ABI_AIX:
8f802bfb 12541 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
12542 break;
12543
4dabc42d 12544 case ABI_DARWIN:
b6c9286a
MM
12545 case ABI_V4:
12546 case ABI_AIX_NODESC:
03a7e1a5 12547 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 12548 break;
b6c9286a
MM
12549 }
12550
12551 return ret;
12552}
12553
12554/* Emit RTL insns to initialize the variable parts of a trampoline.
12555 FNADDR is an RTX for the address of the function's pure code.
12556 CXT is an RTX for the static chain value for the function. */
12557
12558void
12559rs6000_initialize_trampoline (addr, fnaddr, cxt)
12560 rtx addr;
12561 rtx fnaddr;
12562 rtx cxt;
12563{
ac2a93a1 12564 enum machine_mode pmode = Pmode;
8bd04c56
MM
12565 int regsize = (TARGET_32BIT) ? 4 : 8;
12566 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
12567
12568 switch (DEFAULT_ABI)
12569 {
12570 default:
12571 abort ();
12572
8bd04c56 12573/* Macros to shorten the code expansions below. */
39403d82 12574#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
12575#define MEM_PLUS(addr,offset) \
12576 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 12577
b6c9286a
MM
12578 /* Under AIX, just build the 3 word function descriptor */
12579 case ABI_AIX:
8bd04c56
MM
12580 {
12581 rtx fn_reg = gen_reg_rtx (pmode);
12582 rtx toc_reg = gen_reg_rtx (pmode);
12583 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 12584 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
12585 emit_move_insn (MEM_DEREF (addr), fn_reg);
12586 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
12587 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
12588 }
b6c9286a
MM
12589 break;
12590
4dabc42d
TC
12591 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
12592 case ABI_DARWIN:
b6c9286a
MM
12593 case ABI_V4:
12594 case ABI_AIX_NODESC:
39403d82 12595 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
12596 FALSE, VOIDmode, 4,
12597 addr, pmode,
12598 GEN_INT (rs6000_trampoline_size ()), SImode,
12599 fnaddr, pmode,
12600 ctx_reg, pmode);
b6c9286a 12601 break;
b6c9286a
MM
12602 }
12603
12604 return;
12605}
7509c759
MM
12606
12607\f
91d231cb 12608/* Table of valid machine attributes. */
a4f6c312 12609
91d231cb 12610const struct attribute_spec rs6000_attribute_table[] =
7509c759 12611{
91d231cb 12612 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
a5c76ee6
ZW
12613 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
12614 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
12615 { NULL, 0, 0, false, false, false, NULL }
91d231cb 12616};
7509c759 12617
a5c76ee6
ZW
12618/* Handle a "longcall" or "shortcall" attribute; arguments as in
12619 struct attribute_spec.handler. */
a4f6c312 12620
91d231cb
JM
12621static tree
12622rs6000_handle_longcall_attribute (node, name, args, flags, no_add_attrs)
12623 tree *node;
12624 tree name;
12625 tree args ATTRIBUTE_UNUSED;
12626 int flags ATTRIBUTE_UNUSED;
12627 bool *no_add_attrs;
12628{
12629 if (TREE_CODE (*node) != FUNCTION_TYPE
12630 && TREE_CODE (*node) != FIELD_DECL
12631 && TREE_CODE (*node) != TYPE_DECL)
12632 {
12633 warning ("`%s' attribute only applies to functions",
12634 IDENTIFIER_POINTER (name));
12635 *no_add_attrs = true;
12636 }
6a4cee5f 12637
91d231cb 12638 return NULL_TREE;
7509c759
MM
12639}
12640
a5c76ee6
ZW
12641/* Set longcall attributes on all functions declared when
12642 rs6000_default_long_calls is true. */
12643static void
12644rs6000_set_default_type_attributes (type)
12645 tree type;
12646{
12647 if (rs6000_default_long_calls
12648 && (TREE_CODE (type) == FUNCTION_TYPE
12649 || TREE_CODE (type) == METHOD_TYPE))
12650 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
12651 NULL_TREE,
12652 TYPE_ATTRIBUTES (type));
12653}
12654
3cb999d8
DE
12655/* Return a reference suitable for calling a function with the
12656 longcall attribute. */
a4f6c312 12657
6a4cee5f
MM
12658struct rtx_def *
12659rs6000_longcall_ref (call_ref)
12660 rtx call_ref;
12661{
d330fd93 12662 const char *call_name;
6a4cee5f
MM
12663 tree node;
12664
12665 if (GET_CODE (call_ref) != SYMBOL_REF)
12666 return call_ref;
12667
12668 /* System V adds '.' to the internal name, so skip them. */
12669 call_name = XSTR (call_ref, 0);
12670 if (*call_name == '.')
12671 {
12672 while (*call_name == '.')
12673 call_name++;
12674
12675 node = get_identifier (call_name);
39403d82 12676 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
12677 }
12678
12679 return force_reg (Pmode, call_ref);
12680}
12681
7509c759 12682\f
b64a1b53
RH
12683#ifdef USING_ELFOS_H
12684
7509c759
MM
12685/* A C statement or statements to switch to the appropriate section
12686 for output of RTX in mode MODE. You can assume that RTX is some
12687 kind of constant in RTL. The argument MODE is redundant except in
12688 the case of a `const_int' rtx. Select the section by calling
12689 `text_section' or one of the alternatives for other sections.
12690
12691 Do not define this macro if you put all constants in the read-only
12692 data section. */
12693
b64a1b53
RH
12694static void
12695rs6000_elf_select_rtx_section (mode, x, align)
a9098fd0 12696 enum machine_mode mode;
7509c759 12697 rtx x;
b64a1b53 12698 unsigned HOST_WIDE_INT align;
7509c759 12699{
a9098fd0 12700 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 12701 toc_section ();
7509c759 12702 else
b64a1b53 12703 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
12704}
12705
12706/* A C statement or statements to switch to the appropriate
12707 section for output of DECL. DECL is either a `VAR_DECL' node
12708 or a constant of some sort. RELOC indicates whether forming
12709 the initial value of DECL requires link-time relocations. */
12710
ae46c4e0
RH
12711static void
12712rs6000_elf_select_section (decl, reloc, align)
7509c759
MM
12713 tree decl;
12714 int reloc;
0e5dbd9b 12715 unsigned HOST_WIDE_INT align;
7509c759 12716{
0e5dbd9b
DE
12717 default_elf_select_section_1 (decl, reloc, align,
12718 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
12719}
12720
12721/* A C statement to build up a unique section name, expressed as a
12722 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
12723 RELOC indicates whether the initial value of EXP requires
12724 link-time relocations. If you do not define this macro, GCC will use
12725 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 12726 macro can now be called for uninitialized data items as well as
4912a07c 12727 initialized data and functions. */
63019373 12728
ae46c4e0
RH
12729static void
12730rs6000_elf_unique_section (decl, reloc)
63019373
GK
12731 tree decl;
12732 int reloc;
12733{
0e5dbd9b
DE
12734 default_unique_section_1 (decl, reloc,
12735 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 12736}
d9407988
MM
12737
12738\f
d9407988
MM
12739/* If we are referencing a function that is static or is known to be
12740 in this file, make the SYMBOL_REF special. We can use this to indicate
12741 that we can branch to this function without emitting a no-op after the
9ebbca7d 12742 call. For real AIX calling sequences, we also replace the
d9407988
MM
12743 function name with the real name (1 or 2 leading .'s), rather than
12744 the function descriptor name. This saves a lot of overriding code
a260abc9 12745 to read the prefixes. */
d9407988 12746
fb49053f
RH
12747static void
12748rs6000_elf_encode_section_info (decl, first)
d9407988 12749 tree decl;
b2003250 12750 int first;
d9407988 12751{
b2003250
RH
12752 if (!first)
12753 return;
12754
d9407988
MM
12755 if (TREE_CODE (decl) == FUNCTION_DECL)
12756 {
12757 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
b629ba0c 12758 if ((*targetm.binds_local_p) (decl))
d9407988
MM
12759 SYMBOL_REF_FLAG (sym_ref) = 1;
12760
9ebbca7d 12761 if (DEFAULT_ABI == ABI_AIX)
d9407988 12762 {
ff669a6c
RH
12763 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
12764 size_t len2 = strlen (XSTR (sym_ref, 0));
520a57c8 12765 char *str = alloca (len1 + len2 + 1);
ff669a6c
RH
12766 str[0] = '.';
12767 str[1] = '.';
12768 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
12769
520a57c8 12770 XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
d9407988
MM
12771 }
12772 }
12773 else if (rs6000_sdata != SDATA_NONE
f607bc57 12774 && DEFAULT_ABI == ABI_V4
d9407988
MM
12775 && TREE_CODE (decl) == VAR_DECL)
12776 {
c40e5172 12777 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
d9407988
MM
12778 int size = int_size_in_bytes (TREE_TYPE (decl));
12779 tree section_name = DECL_SECTION_NAME (decl);
d330fd93 12780 const char *name = (char *)0;
d9407988
MM
12781 int len = 0;
12782
c40e5172
JS
12783 if ((*targetm.binds_local_p) (decl))
12784 SYMBOL_REF_FLAG (sym_ref) = 1;
12785
d9407988
MM
12786 if (section_name)
12787 {
12788 if (TREE_CODE (section_name) == STRING_CST)
12789 {
12790 name = TREE_STRING_POINTER (section_name);
12791 len = TREE_STRING_LENGTH (section_name);
12792 }
12793 else
12794 abort ();
12795 }
12796
2792d578
DE
12797 if (name
12798 ? ((len == sizeof (".sdata") - 1
12799 && strcmp (name, ".sdata") == 0)
12800 || (len == sizeof (".sdata2") - 1
12801 && strcmp (name, ".sdata2") == 0)
12802 || (len == sizeof (".sbss") - 1
12803 && strcmp (name, ".sbss") == 0)
12804 || (len == sizeof (".sbss2") - 1
12805 && strcmp (name, ".sbss2") == 0)
12806 || (len == sizeof (".PPC.EMB.sdata0") - 1
12807 && strcmp (name, ".PPC.EMB.sdata0") == 0)
12808 || (len == sizeof (".PPC.EMB.sbss0") - 1
12809 && strcmp (name, ".PPC.EMB.sbss0") == 0))
12810 : (size > 0 && size <= g_switch_value))
d9407988 12811 {
ff669a6c 12812 size_t len = strlen (XSTR (sym_ref, 0));
88c1e412 12813 char *str = alloca (len + 2);
ff669a6c 12814
ff669a6c
RH
12815 str[0] = '@';
12816 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
88c1e412 12817 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988
MM
12818 }
12819 }
12820}
12821
772c5265
RH
12822static const char *
12823rs6000_elf_strip_name_encoding (str)
12824 const char *str;
12825{
12826 while (*str == '*' || *str == '@')
12827 str++;
12828 return str;
12829}
12830
0e5dbd9b
DE
12831static bool
12832rs6000_elf_in_small_data_p (decl)
12833 tree decl;
12834{
12835 if (rs6000_sdata == SDATA_NONE)
12836 return false;
12837
12838 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
12839 {
12840 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
12841 if (strcmp (section, ".sdata") == 0
12842 || strcmp (section, ".sdata2") == 0
12843 || strcmp (section, ".sbss") == 0)
12844 return true;
12845 }
12846 else
12847 {
12848 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
12849
12850 if (size > 0
12851 && size <= g_switch_value
12852 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
12853 return true;
12854 }
12855
12856 return false;
12857}
12858
b91da81f 12859#endif /* USING_ELFOS_H */
000034eb 12860
a6c2a102 12861\f
000034eb 12862/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
12863 ADDR can be effectively incremented by incrementing REG.
12864
12865 r0 is special and we must not select it as an address
12866 register by this routine since our caller will try to
12867 increment the returned register via an "la" instruction. */
000034eb
DE
12868
12869struct rtx_def *
12870find_addr_reg (addr)
12871 rtx addr;
12872{
12873 while (GET_CODE (addr) == PLUS)
12874 {
02441cd6
JL
12875 if (GET_CODE (XEXP (addr, 0)) == REG
12876 && REGNO (XEXP (addr, 0)) != 0)
000034eb 12877 addr = XEXP (addr, 0);
02441cd6
JL
12878 else if (GET_CODE (XEXP (addr, 1)) == REG
12879 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
12880 addr = XEXP (addr, 1);
12881 else if (CONSTANT_P (XEXP (addr, 0)))
12882 addr = XEXP (addr, 1);
12883 else if (CONSTANT_P (XEXP (addr, 1)))
12884 addr = XEXP (addr, 0);
12885 else
12886 abort ();
12887 }
02441cd6 12888 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
12889 return addr;
12890 abort ();
12891}
12892
a6c2a102
DE
12893void
12894rs6000_fatal_bad_address (op)
12895 rtx op;
12896{
12897 fatal_insn ("bad address", op);
12898}
c8023011 12899
ee890fe2
SS
12900#if TARGET_MACHO
12901
12902#if 0
12903/* Returns 1 if OP is either a symbol reference or a sum of a symbol
12904 reference and a constant. */
12905
12906int
12907symbolic_operand (op)
592696dd 12908 rtx op;
ee890fe2
SS
12909{
12910 switch (GET_CODE (op))
12911 {
12912 case SYMBOL_REF:
12913 case LABEL_REF:
12914 return 1;
12915 case CONST:
12916 op = XEXP (op, 0);
12917 return (GET_CODE (op) == SYMBOL_REF ||
12918 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
12919 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
12920 && GET_CODE (XEXP (op, 1)) == CONST_INT);
12921 default:
12922 return 0;
12923 }
c8023011 12924}
ee890fe2
SS
12925#endif
12926
12927#ifdef RS6000_LONG_BRANCH
12928
12929static tree stub_list = 0;
12930
12931/* ADD_COMPILER_STUB adds the compiler generated stub for handling
12932 procedure calls to the linked list. */
12933
12934void
12935add_compiler_stub (label_name, function_name, line_number)
12936 tree label_name;
12937 tree function_name;
12938 int line_number;
12939{
12940 tree stub = build_tree_list (function_name, label_name);
12941 TREE_TYPE (stub) = build_int_2 (line_number, 0);
12942 TREE_CHAIN (stub) = stub_list;
12943 stub_list = stub;
12944}
12945
12946#define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
12947#define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
12948#define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
12949
a4f6c312
SS
12950/* OUTPUT_COMPILER_STUB outputs the compiler generated stub for
12951 handling procedure calls from the linked list and initializes the
12952 linked list. */
ee890fe2 12953
a4f6c312
SS
12954void
12955output_compiler_stub ()
ee890fe2
SS
12956{
12957 char tmp_buf[256];
12958 char label_buf[256];
308c142a 12959 tree stub;
ee890fe2
SS
12960
12961 if (!flag_pic)
12962 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
12963 {
12964 fprintf (asm_out_file,
12965 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
12966
12967#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
12968 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
12969 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
12970#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
12971
12972 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
12973 strcpy (label_buf,
12974 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
12975 else
12976 {
12977 label_buf[0] = '_';
12978 strcpy (label_buf+1,
12979 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
12980 }
12981
12982 strcpy (tmp_buf, "lis r12,hi16(");
12983 strcat (tmp_buf, label_buf);
12984 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
12985 strcat (tmp_buf, label_buf);
12986 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
12987 output_asm_insn (tmp_buf, 0);
12988
12989#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
12990 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
12991 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
12992#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
12993 }
12994
12995 stub_list = 0;
12996}
12997
12998/* NO_PREVIOUS_DEF checks in the link list whether the function name is
12999 already there or not. */
13000
a4f6c312
SS
13001int
13002no_previous_def (function_name)
ee890fe2
SS
13003 tree function_name;
13004{
13005 tree stub;
13006 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13007 if (function_name == STUB_FUNCTION_NAME (stub))
13008 return 0;
13009 return 1;
13010}
13011
13012/* GET_PREV_LABEL gets the label name from the previous definition of
13013 the function. */
13014
a4f6c312
SS
13015tree
13016get_prev_label (function_name)
ee890fe2
SS
13017 tree function_name;
13018{
13019 tree stub;
13020 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
13021 if (function_name == STUB_FUNCTION_NAME (stub))
13022 return STUB_LABEL_NAME (stub);
13023 return 0;
13024}
13025
13026/* INSN is either a function call or a millicode call. It may have an
13027 unconditional jump in its delay slot.
13028
13029 CALL_DEST is the routine we are calling. */
13030
13031char *
13032output_call (insn, call_dest, operand_number)
13033 rtx insn;
13034 rtx call_dest;
13035 int operand_number;
13036{
13037 static char buf[256];
13038 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
13039 {
13040 tree labelname;
13041 tree funname = get_identifier (XSTR (call_dest, 0));
13042
13043 if (no_previous_def (funname))
13044 {
308c142a 13045 int line_number = 0;
ee890fe2
SS
13046 rtx label_rtx = gen_label_rtx ();
13047 char *label_buf, temp_buf[256];
13048 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
13049 CODE_LABEL_NUMBER (label_rtx));
13050 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
13051 labelname = get_identifier (label_buf);
13052 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
13053 if (insn)
13054 line_number = NOTE_LINE_NUMBER (insn);
13055 add_compiler_stub (labelname, funname, line_number);
13056 }
13057 else
13058 labelname = get_prev_label (funname);
13059
13060 sprintf (buf, "jbsr %%z%d,%.246s",
13061 operand_number, IDENTIFIER_POINTER (labelname));
13062 return buf;
13063 }
13064 else
13065 {
13066 sprintf (buf, "bl %%z%d", operand_number);
13067 return buf;
13068 }
13069}
13070
13071#endif /* RS6000_LONG_BRANCH */
13072
13073#define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \
13074 do { \
83182544 13075 const char *const symbol_ = (SYMBOL); \
ee890fe2
SS
13076 char *buffer_ = (BUF); \
13077 if (symbol_[0] == '"') \
13078 { \
13079 sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \
13080 } \
13081 else if (name_needs_quotes(symbol_)) \
13082 { \
13083 sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \
13084 } \
13085 else \
13086 { \
13087 sprintf(buffer_, "L%d$%s", (N), symbol_); \
13088 } \
13089 } while (0)
13090
13091
13092/* Generate PIC and indirect symbol stubs. */
13093
13094void
13095machopic_output_stub (file, symb, stub)
13096 FILE *file;
13097 const char *symb, *stub;
13098{
13099 unsigned int length;
a4f6c312
SS
13100 char *symbol_name, *lazy_ptr_name;
13101 char *local_label_0;
ee890fe2
SS
13102 static int label = 0;
13103
df56a27f 13104 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 13105 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 13106
ee890fe2
SS
13107 label += 1;
13108
ee890fe2
SS
13109 length = strlen (symb);
13110 symbol_name = alloca (length + 32);
13111 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
13112
13113 lazy_ptr_name = alloca (length + 32);
13114 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
13115
13116 local_label_0 = alloca (length + 32);
13117 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0);
13118
ee890fe2 13119 if (flag_pic == 2)
d3c300d2 13120 machopic_picsymbol_stub1_section ();
ee890fe2 13121 else
d3c300d2
DJ
13122 machopic_symbol_stub1_section ();
13123 fprintf (file, "\t.align 2\n");
ee890fe2
SS
13124
13125 fprintf (file, "%s:\n", stub);
13126 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13127
13128 if (flag_pic == 2)
13129 {
13130 fprintf (file, "\tmflr r0\n");
13131 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
13132 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
13133 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
13134 lazy_ptr_name, local_label_0);
13135 fprintf (file, "\tmtlr r0\n");
d3c300d2 13136 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
13137 lazy_ptr_name, local_label_0);
13138 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
13139 fprintf (file, "\tbctr\n");
13140 }
13141 else
ab82a49f
AP
13142 {
13143 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
13144 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
13145 fprintf (file, "\tmtctr r12\n");
13146 fprintf (file, "\tbctr\n");
13147 }
ee890fe2
SS
13148
13149 machopic_lazy_symbol_ptr_section ();
13150 fprintf (file, "%s:\n", lazy_ptr_name);
13151 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13152 fprintf (file, "\t.long dyld_stub_binding_helper\n");
13153}
13154
13155/* Legitimize PIC addresses. If the address is already
13156 position-independent, we return ORIG. Newly generated
13157 position-independent addresses go into a reg. This is REG if non
13158 zero, otherwise we allocate register(s) as necessary. */
13159
c859cda6 13160#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
13161
13162rtx
13163rs6000_machopic_legitimize_pic_address (orig, mode, reg)
13164 rtx orig;
13165 enum machine_mode mode;
13166 rtx reg;
13167{
13168 rtx base, offset;
13169
13170 if (reg == NULL && ! reload_in_progress && ! reload_completed)
13171 reg = gen_reg_rtx (Pmode);
13172
13173 if (GET_CODE (orig) == CONST)
13174 {
13175 if (GET_CODE (XEXP (orig, 0)) == PLUS
13176 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
13177 return orig;
13178
13179 if (GET_CODE (XEXP (orig, 0)) == PLUS)
13180 {
a4f6c312
SS
13181 base =
13182 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
13183 Pmode, reg);
13184 offset =
13185 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
13186 Pmode, reg);
ee890fe2
SS
13187 }
13188 else
13189 abort ();
13190
13191 if (GET_CODE (offset) == CONST_INT)
13192 {
13193 if (SMALL_INT (offset))
ed8908e7 13194 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
13195 else if (! reload_in_progress && ! reload_completed)
13196 offset = force_reg (Pmode, offset);
13197 else
c859cda6
DJ
13198 {
13199 rtx mem = force_const_mem (Pmode, orig);
13200 return machopic_legitimize_pic_address (mem, Pmode, reg);
13201 }
ee890fe2
SS
13202 }
13203 return gen_rtx (PLUS, Pmode, base, offset);
13204 }
13205
13206 /* Fall back on generic machopic code. */
13207 return machopic_legitimize_pic_address (orig, mode, reg);
13208}
13209
13210/* This is just a placeholder to make linking work without having to
13211 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
13212 ever needed for Darwin (not too likely!) this would have to get a
13213 real definition. */
13214
13215void
13216toc_section ()
13217{
13218}
13219
13220#endif /* TARGET_MACHO */
7c262518
RH
13221
13222#if TARGET_ELF
13223static unsigned int
13224rs6000_elf_section_type_flags (decl, name, reloc)
13225 tree decl;
13226 const char *name;
13227 int reloc;
13228{
5add3202
DE
13229 unsigned int flags
13230 = default_section_type_flags_1 (decl, name, reloc,
13231 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 13232
270fc29b
RH
13233 if (TARGET_RELOCATABLE)
13234 flags |= SECTION_WRITE;
7c262518 13235
d0101753 13236 return flags;
7c262518 13237}
d9f6800d
RH
13238
13239/* Record an element in the table of global constructors. SYMBOL is
13240 a SYMBOL_REF of the function to be called; PRIORITY is a number
13241 between 0 and MAX_INIT_PRIORITY.
13242
13243 This differs from default_named_section_asm_out_constructor in
13244 that we have special handling for -mrelocatable. */
13245
13246static void
13247rs6000_elf_asm_out_constructor (symbol, priority)
13248 rtx symbol;
13249 int priority;
13250{
13251 const char *section = ".ctors";
13252 char buf[16];
13253
13254 if (priority != DEFAULT_INIT_PRIORITY)
13255 {
13256 sprintf (buf, ".ctors.%.5u",
13257 /* Invert the numbering so the linker puts us in the proper
13258 order; constructors are run from right to left, and the
13259 linker sorts in increasing order. */
13260 MAX_INIT_PRIORITY - priority);
13261 section = buf;
13262 }
13263
715bdd29
RH
13264 named_section_flags (section, SECTION_WRITE);
13265 assemble_align (POINTER_SIZE);
d9f6800d
RH
13266
13267 if (TARGET_RELOCATABLE)
13268 {
13269 fputs ("\t.long (", asm_out_file);
13270 output_addr_const (asm_out_file, symbol);
13271 fputs (")@fixup\n", asm_out_file);
13272 }
13273 else
c8af3574 13274 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
13275}
13276
13277static void
13278rs6000_elf_asm_out_destructor (symbol, priority)
13279 rtx symbol;
13280 int priority;
13281{
13282 const char *section = ".dtors";
13283 char buf[16];
13284
13285 if (priority != DEFAULT_INIT_PRIORITY)
13286 {
13287 sprintf (buf, ".dtors.%.5u",
13288 /* Invert the numbering so the linker puts us in the proper
13289 order; constructors are run from right to left, and the
13290 linker sorts in increasing order. */
13291 MAX_INIT_PRIORITY - priority);
13292 section = buf;
13293 }
13294
715bdd29
RH
13295 named_section_flags (section, SECTION_WRITE);
13296 assemble_align (POINTER_SIZE);
d9f6800d
RH
13297
13298 if (TARGET_RELOCATABLE)
13299 {
13300 fputs ("\t.long (", asm_out_file);
13301 output_addr_const (asm_out_file, symbol);
13302 fputs (")@fixup\n", asm_out_file);
13303 }
13304 else
c8af3574 13305 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 13306}
7c262518
RH
13307#endif
13308
cbaaba19 13309#if TARGET_XCOFF
7c262518 13310static void
b275d088
DE
13311rs6000_xcoff_asm_globalize_label (stream, name)
13312 FILE *stream;
13313 const char *name;
13314{
13315 fputs (GLOBAL_ASM_OP, stream);
13316 RS6000_OUTPUT_BASENAME (stream, name);
13317 putc ('\n', stream);
13318}
13319
13320static void
13321rs6000_xcoff_asm_named_section (name, flags)
7c262518 13322 const char *name;
0e5dbd9b 13323 unsigned int flags;
7c262518 13324{
0e5dbd9b
DE
13325 int smclass;
13326 static const char * const suffix[3] = { "PR", "RO", "RW" };
13327
13328 if (flags & SECTION_CODE)
13329 smclass = 0;
13330 else if (flags & SECTION_WRITE)
13331 smclass = 2;
13332 else
13333 smclass = 1;
13334
5b5198f7 13335 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 13336 (flags & SECTION_CODE) ? "." : "",
5b5198f7 13337 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 13338}
ae46c4e0
RH
13339
13340static void
0e5dbd9b
DE
13341rs6000_xcoff_select_section (decl, reloc, align)
13342 tree decl;
ae46c4e0
RH
13343 int reloc;
13344 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
13345{
5add3202 13346 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 13347 {
0e5dbd9b 13348 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13349 read_only_data_section ();
13350 else
13351 read_only_private_data_section ();
13352 }
13353 else
13354 {
0e5dbd9b 13355 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13356 data_section ();
13357 else
13358 private_data_section ();
13359 }
13360}
13361
13362static void
13363rs6000_xcoff_unique_section (decl, reloc)
13364 tree decl;
772c5265 13365 int reloc ATTRIBUTE_UNUSED;
ae46c4e0
RH
13366{
13367 const char *name;
ae46c4e0 13368
5b5198f7
DE
13369 /* Use select_section for private and uninitialized data. */
13370 if (!TREE_PUBLIC (decl)
13371 || DECL_COMMON (decl)
0e5dbd9b
DE
13372 || DECL_INITIAL (decl) == NULL_TREE
13373 || DECL_INITIAL (decl) == error_mark_node
13374 || (flag_zero_initialized_in_bss
13375 && initializer_zerop (DECL_INITIAL (decl))))
13376 return;
13377
13378 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
13379 name = (*targetm.strip_name_encoding) (name);
13380 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 13381}
b64a1b53 13382
fb49053f
RH
13383/* Select section for constant in constant pool.
13384
13385 On RS/6000, all constants are in the private read-only data area.
13386 However, if this is being placed in the TOC it must be output as a
13387 toc entry. */
13388
b64a1b53
RH
13389static void
13390rs6000_xcoff_select_rtx_section (mode, x, align)
13391 enum machine_mode mode;
13392 rtx x;
13393 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
13394{
13395 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
13396 toc_section ();
13397 else
13398 read_only_private_data_section ();
13399}
772c5265
RH
13400
13401/* Remove any trailing [DS] or the like from the symbol name. */
13402
13403static const char *
13404rs6000_xcoff_strip_name_encoding (name)
13405 const char *name;
13406{
13407 size_t len;
13408 if (*name == '*')
13409 name++;
13410 len = strlen (name);
13411 if (name[len - 1] == ']')
13412 return ggc_alloc_string (name, len - 4);
13413 else
13414 return name;
13415}
13416
5add3202
DE
13417/* Section attributes. AIX is always PIC. */
13418
13419static unsigned int
13420rs6000_xcoff_section_type_flags (decl, name, reloc)
13421 tree decl;
13422 const char *name;
13423 int reloc;
13424{
5b5198f7
DE
13425 unsigned int align;
13426 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
13427
13428 /* Align to at least UNIT size. */
13429 if (flags & SECTION_CODE)
13430 align = MIN_UNITS_PER_WORD;
13431 else
13432 /* Increase alignment of large objects if not already stricter. */
13433 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
13434 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
13435 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
13436
13437 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202
DE
13438}
13439
cbaaba19 13440#endif /* TARGET_XCOFF */
fb49053f 13441
0e5dbd9b 13442/* Note that this is also used for PPC64 Linux. */
fb49053f
RH
13443
13444static void
13445rs6000_xcoff_encode_section_info (decl, first)
13446 tree decl;
13447 int first ATTRIBUTE_UNUSED;
13448{
13449 if (TREE_CODE (decl) == FUNCTION_DECL
b629ba0c 13450 && (*targetm.binds_local_p) (decl))
fb49053f
RH
13451 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
13452}
0e5dbd9b
DE
13453
13454/* Cross-module name binding. For AIX and PPC64 Linux, which always are
7f3d8013
DJ
13455 PIC, use private copy of flag_pic. Darwin does not support overriding
13456 functions at dynamic-link time. */
0e5dbd9b 13457
2bcc50d0 13458static bool
0e5dbd9b
DE
13459rs6000_binds_local_p (decl)
13460 tree decl;
13461{
7f3d8013
DJ
13462 return default_binds_local_p_1 (decl,
13463 DEFAULT_ABI == ABI_DARWIN ? 0 : flag_pic || rs6000_flag_pic);
0e5dbd9b 13464}
34bb030a 13465
3c50106f
RH
13466/* Compute a (partial) cost for rtx X. Return true if the complete
13467 cost has been computed, and false if subexpressions should be
13468 scanned. In either case, *TOTAL contains the cost result. */
13469
13470static bool
13471rs6000_rtx_costs (x, code, outer_code, total)
13472 rtx x;
13473 int code, outer_code ATTRIBUTE_UNUSED;
13474 int *total;
13475{
13476 switch (code)
13477 {
13478 /* On the RS/6000, if it is valid in the insn, it is free.
13479 So this always returns 0. */
13480 case CONST_INT:
13481 case CONST:
13482 case LABEL_REF:
13483 case SYMBOL_REF:
13484 case CONST_DOUBLE:
13485 case HIGH:
13486 *total = 0;
13487 return true;
13488
13489 case PLUS:
13490 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
13491 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
13492 + 0x8000) >= 0x10000)
13493 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
13494 ? COSTS_N_INSNS (2)
13495 : COSTS_N_INSNS (1));
13496 return true;
13497
13498 case AND:
13499 case IOR:
13500 case XOR:
13501 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
13502 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
13503 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
13504 ? COSTS_N_INSNS (2)
13505 : COSTS_N_INSNS (1));
13506 return true;
13507
13508 case MULT:
13509 if (optimize_size)
13510 {
13511 *total = COSTS_N_INSNS (2);
13512 return true;
13513 }
13514 switch (rs6000_cpu)
13515 {
13516 case PROCESSOR_RIOS1:
13517 case PROCESSOR_PPC405:
13518 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13519 ? COSTS_N_INSNS (5)
13520 : (INTVAL (XEXP (x, 1)) >= -256
13521 && INTVAL (XEXP (x, 1)) <= 255)
13522 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
13523 return true;
13524
13525 case PROCESSOR_RS64A:
13526 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13527 ? GET_MODE (XEXP (x, 1)) != DImode
13528 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
13529 : (INTVAL (XEXP (x, 1)) >= -256
13530 && INTVAL (XEXP (x, 1)) <= 255)
13531 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
13532 return true;
13533
13534 case PROCESSOR_RIOS2:
13535 case PROCESSOR_MPCCORE:
13536 case PROCESSOR_PPC604e:
13537 *total = COSTS_N_INSNS (2);
13538 return true;
13539
13540 case PROCESSOR_PPC601:
13541 *total = COSTS_N_INSNS (5);
13542 return true;
13543
13544 case PROCESSOR_PPC603:
13545 case PROCESSOR_PPC7400:
13546 case PROCESSOR_PPC750:
13547 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13548 ? COSTS_N_INSNS (5)
13549 : (INTVAL (XEXP (x, 1)) >= -256
13550 && INTVAL (XEXP (x, 1)) <= 255)
13551 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
13552 return true;
13553
13554 case PROCESSOR_PPC7450:
13555 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13556 ? COSTS_N_INSNS (4)
13557 : COSTS_N_INSNS (3));
13558 return true;
13559
13560 case PROCESSOR_PPC403:
13561 case PROCESSOR_PPC604:
13562 case PROCESSOR_PPC8540:
13563 *total = COSTS_N_INSNS (4);
13564 return true;
13565
13566 case PROCESSOR_PPC620:
13567 case PROCESSOR_PPC630:
13568 case PROCESSOR_POWER4:
13569 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13570 ? GET_MODE (XEXP (x, 1)) != DImode
13571 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
13572 : (INTVAL (XEXP (x, 1)) >= -256
13573 && INTVAL (XEXP (x, 1)) <= 255)
13574 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
13575 return true;
13576
13577 default:
13578 abort ();
13579 }
13580
13581 case DIV:
13582 case MOD:
13583 if (GET_CODE (XEXP (x, 1)) == CONST_INT
13584 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
13585 {
13586 *total = COSTS_N_INSNS (2);
13587 return true;
13588 }
13589 /* FALLTHRU */
13590
13591 case UDIV:
13592 case UMOD:
13593 switch (rs6000_cpu)
13594 {
13595 case PROCESSOR_RIOS1:
13596 *total = COSTS_N_INSNS (19);
13597 return true;
13598
13599 case PROCESSOR_RIOS2:
13600 *total = COSTS_N_INSNS (13);
13601 return true;
13602
13603 case PROCESSOR_RS64A:
13604 *total = (GET_MODE (XEXP (x, 1)) != DImode
13605 ? COSTS_N_INSNS (65)
13606 : COSTS_N_INSNS (67));
13607 return true;
13608
13609 case PROCESSOR_MPCCORE:
13610 *total = COSTS_N_INSNS (6);
13611 return true;
13612
13613 case PROCESSOR_PPC403:
13614 *total = COSTS_N_INSNS (33);
13615 return true;
13616
13617 case PROCESSOR_PPC405:
13618 *total = COSTS_N_INSNS (35);
13619 return true;
13620
13621 case PROCESSOR_PPC601:
13622 *total = COSTS_N_INSNS (36);
13623 return true;
13624
13625 case PROCESSOR_PPC603:
13626 *total = COSTS_N_INSNS (37);
13627 return true;
13628
13629 case PROCESSOR_PPC604:
13630 case PROCESSOR_PPC604e:
13631 *total = COSTS_N_INSNS (20);
13632 return true;
13633
13634 case PROCESSOR_PPC620:
13635 case PROCESSOR_PPC630:
13636 case PROCESSOR_POWER4:
13637 *total = (GET_MODE (XEXP (x, 1)) != DImode
13638 ? COSTS_N_INSNS (21)
13639 : COSTS_N_INSNS (37));
13640 return true;
13641
13642 case PROCESSOR_PPC750:
13643 case PROCESSOR_PPC8540:
13644 case PROCESSOR_PPC7400:
13645 *total = COSTS_N_INSNS (19);
13646 return true;
13647
13648 case PROCESSOR_PPC7450:
13649 *total = COSTS_N_INSNS (23);
13650 return true;
13651
13652 default:
13653 abort ();
13654 }
13655
13656 case FFS:
13657 *total = COSTS_N_INSNS (4);
13658 return true;
13659
13660 case MEM:
13661 /* MEM should be slightly more expensive than (plus (reg) (const)) */
13662 *total = 5;
13663 return true;
13664
13665 default:
13666 return false;
13667 }
13668}
13669
34bb030a
DE
13670/* A C expression returning the cost of moving data from a register of class
13671 CLASS1 to one of CLASS2. */
13672
13673int
13674rs6000_register_move_cost (mode, from, to)
13675 enum machine_mode mode;
13676 enum reg_class from, to;
13677{
13678 /* Moves from/to GENERAL_REGS. */
13679 if (reg_classes_intersect_p (to, GENERAL_REGS)
13680 || reg_classes_intersect_p (from, GENERAL_REGS))
13681 {
13682 if (! reg_classes_intersect_p (to, GENERAL_REGS))
13683 from = to;
13684
13685 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
13686 return (rs6000_memory_move_cost (mode, from, 0)
13687 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
13688
13689/* It's more expensive to move CR_REGS than CR0_REGS because of the shift...*/
13690 else if (from == CR_REGS)
13691 return 4;
13692
13693 else
13694/* A move will cost one instruction per GPR moved. */
13695 return 2 * HARD_REGNO_NREGS (0, mode);
13696 }
13697
13698/* Moving between two similar registers is just one instruction. */
13699 else if (reg_classes_intersect_p (to, from))
13700 return mode == TFmode ? 4 : 2;
13701
13702/* Everything else has to go through GENERAL_REGS. */
13703 else
13704 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
13705 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
13706}
13707
13708/* A C expressions returning the cost of moving data of MODE from a register to
13709 or from memory. */
13710
13711int
13712rs6000_memory_move_cost (mode, class, in)
13713 enum machine_mode mode;
13714 enum reg_class class;
13715 int in ATTRIBUTE_UNUSED;
13716{
13717 if (reg_classes_intersect_p (class, GENERAL_REGS))
13718 return 4 * HARD_REGNO_NREGS (0, mode);
13719 else if (reg_classes_intersect_p (class, FLOAT_REGS))
13720 return 4 * HARD_REGNO_NREGS (32, mode);
13721 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
13722 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
13723 else
13724 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
13725}
13726
62e1dfcf
NC
13727/* Return true if TYPE is of type __ev64_opaque__. */
13728
c8e4f0e9 13729static bool
62e1dfcf
NC
13730is_ev64_opaque_type (type)
13731 tree type;
13732{
c8e4f0e9
AH
13733 return (TARGET_SPE
13734 && TREE_CODE (type) == VECTOR_TYPE
13735 && TYPE_NAME (type)
62e1dfcf
NC
13736 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13737 && DECL_NAME (TYPE_NAME (type))
13738 && strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
13739 "__ev64_opaque__") == 0);
13740}
13741
96714395
AH
13742static rtx
13743rs6000_dwarf_register_span (reg)
13744 rtx reg;
13745{
13746 unsigned regno;
13747
13748 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
13749 return NULL_RTX;
13750
13751 regno = REGNO (reg);
13752
13753 /* The duality of the SPE register size wreaks all kinds of havoc.
13754 This is a way of distinguishing r0 in 32-bits from r0 in
13755 64-bits. */
13756 return
13757 gen_rtx_PARALLEL (VOIDmode,
13758 gen_rtvec (2,
13759 gen_rtx_REG (SImode, regno),
13760 /* Who, where, what? 1200? This
13761 will get changed to a sane value
13762 when the SPE ABI finalizes. */
13763 gen_rtx_REG (SImode, regno + 1200)));
13764}
13765
17211ab5 13766#include "gt-rs6000.h"