]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
* gcc.c-torture/compile/20030219-1.c: New test.
[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));
89e7058f
AH
178static void emit_frame_save PARAMS ((rtx, rtx, enum machine_mode,
179 unsigned int, int, int));
a3170dc6 180static rtx gen_frame_mem_offset PARAMS ((enum machine_mode, rtx, int));
9ebbca7d
GK
181static void rs6000_emit_allocate_stack PARAMS ((HOST_WIDE_INT, int));
182static unsigned rs6000_hash_constant PARAMS ((rtx));
183static unsigned toc_hash_function PARAMS ((const void *));
184static int toc_hash_eq PARAMS ((const void *, const void *));
9ebbca7d 185static int constant_pool_expr_1 PARAMS ((rtx, int *, int *));
e2500fed 186static struct machine_function * rs6000_init_machine_status PARAMS ((void));
301d03af 187static bool rs6000_assemble_integer PARAMS ((rtx, unsigned int, int));
5add3202 188#ifdef HAVE_GAS_HIDDEN
25fdb4dc 189static void rs6000_assemble_visibility PARAMS ((tree, int));
5add3202 190#endif
71f123ca 191static int rs6000_ra_ever_killed PARAMS ((void));
91d231cb
JM
192static tree rs6000_handle_longcall_attribute PARAMS ((tree *, tree, tree, int, bool *));
193const struct attribute_spec rs6000_attribute_table[];
a5c76ee6 194static void rs6000_set_default_type_attributes PARAMS ((tree));
08c148a8
NB
195static void rs6000_output_function_prologue PARAMS ((FILE *, HOST_WIDE_INT));
196static void rs6000_output_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT));
3961e8fe
RH
197static void rs6000_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
198 HOST_WIDE_INT, tree));
2bfcf297
DB
199static rtx rs6000_emit_set_long_const PARAMS ((rtx,
200 HOST_WIDE_INT, HOST_WIDE_INT));
7c262518
RH
201#if TARGET_ELF
202static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *,
203 int));
d9f6800d
RH
204static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
205static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
ae46c4e0 206static void rs6000_elf_select_section PARAMS ((tree, int,
5b71a4e7 207 unsigned HOST_WIDE_INT));
ae46c4e0 208static void rs6000_elf_unique_section PARAMS ((tree, int));
b64a1b53
RH
209static void rs6000_elf_select_rtx_section PARAMS ((enum machine_mode, rtx,
210 unsigned HOST_WIDE_INT));
0e5dbd9b
DE
211static void rs6000_elf_encode_section_info PARAMS ((tree, int))
212 ATTRIBUTE_UNUSED;
772c5265 213static const char *rs6000_elf_strip_name_encoding PARAMS ((const char *));
0e5dbd9b 214static bool rs6000_elf_in_small_data_p PARAMS ((tree));
7c262518 215#endif
cbaaba19 216#if TARGET_XCOFF
b275d088
DE
217static void rs6000_xcoff_asm_globalize_label PARAMS ((FILE *, const char *));
218static void rs6000_xcoff_asm_named_section PARAMS ((const char *, unsigned int));
ae46c4e0
RH
219static void rs6000_xcoff_select_section PARAMS ((tree, int,
220 unsigned HOST_WIDE_INT));
221static void rs6000_xcoff_unique_section PARAMS ((tree, int));
b64a1b53
RH
222static void rs6000_xcoff_select_rtx_section PARAMS ((enum machine_mode, rtx,
223 unsigned HOST_WIDE_INT));
772c5265 224static const char * rs6000_xcoff_strip_name_encoding PARAMS ((const char *));
5add3202 225static unsigned int rs6000_xcoff_section_type_flags PARAMS ((tree, const char *, int));
7c262518 226#endif
fb49053f
RH
227static void rs6000_xcoff_encode_section_info PARAMS ((tree, int))
228 ATTRIBUTE_UNUSED;
2bcc50d0 229static bool rs6000_binds_local_p PARAMS ((tree));
b54cf83a
DE
230static int rs6000_use_dfa_pipeline_interface PARAMS ((void));
231static int rs6000_multipass_dfa_lookahead PARAMS ((void));
232static int rs6000_variable_issue PARAMS ((FILE *, int, rtx, int));
3c50106f 233static bool rs6000_rtx_costs PARAMS ((rtx, int, int, int *));
c237e94a
ZW
234static int rs6000_adjust_cost PARAMS ((rtx, rtx, rtx, int));
235static int rs6000_adjust_priority PARAMS ((rtx, int));
236static int rs6000_issue_rate PARAMS ((void));
237
6fa3f289 238static void rs6000_init_builtins PARAMS ((void));
92898235
AH
239static rtx rs6000_expand_unop_builtin PARAMS ((enum insn_code, tree, rtx));
240static rtx rs6000_expand_binop_builtin PARAMS ((enum insn_code, tree, rtx));
241static rtx rs6000_expand_ternop_builtin PARAMS ((enum insn_code, tree, rtx));
0ac081f6 242static rtx rs6000_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
92898235 243static void altivec_init_builtins PARAMS ((void));
a3170dc6
AH
244static void rs6000_common_init_builtins PARAMS ((void));
245
246static void enable_mask_for_builtins PARAMS ((struct builtin_description *,
247 int, enum rs6000_builtins,
248 enum rs6000_builtins));
249static void spe_init_builtins PARAMS ((void));
250static rtx spe_expand_builtin PARAMS ((tree, rtx, bool *));
251static rtx spe_expand_predicate_builtin PARAMS ((enum insn_code, tree, rtx));
252static rtx spe_expand_evsel_builtin PARAMS ((enum insn_code, tree, rtx));
253static int rs6000_emit_int_cmove PARAMS ((rtx, rtx, rtx, rtx));
254
92898235 255static rtx altivec_expand_builtin PARAMS ((tree, rtx, bool *));
3a9b8c7e
AH
256static rtx altivec_expand_ld_builtin PARAMS ((tree, rtx, bool *));
257static rtx altivec_expand_st_builtin PARAMS ((tree, rtx, bool *));
258static rtx altivec_expand_dst_builtin PARAMS ((tree, rtx, bool *));
100c4561 259static rtx altivec_expand_abs_builtin PARAMS ((enum insn_code, tree, rtx));
ae4b4a02 260static rtx altivec_expand_predicate_builtin PARAMS ((enum insn_code, const char *, tree, rtx));
6525c0e7 261static rtx altivec_expand_stv_builtin PARAMS ((enum insn_code, tree));
0ac081f6 262static void rs6000_parse_abi_options PARAMS ((void));
08b57fb3 263static void rs6000_parse_vrsave_option PARAMS ((void));
a3170dc6 264static void rs6000_parse_isel_option PARAMS ((void));
00b960c7
AH
265static int first_altivec_reg_to_save PARAMS ((void));
266static unsigned int compute_vrsave_mask PARAMS ((void));
267static void is_altivec_return_reg PARAMS ((rtx, void *));
9aa86737
AH
268static rtx generate_set_vrsave PARAMS ((rtx, rs6000_stack_t *, int));
269static void altivec_frame_fixup PARAMS ((rtx, rtx, HOST_WIDE_INT));
69ef87e2 270static int easy_vector_constant PARAMS ((rtx));
62e1dfcf
NC
271static int is_ev64_opaque_type PARAMS ((tree));
272static bool rs6000_spe_vector_types_compatible PARAMS ((tree, tree));
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
390#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
391#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_multipass_dfa_lookahead
392#undef TARGET_SCHED_VARIABLE_ISSUE
393#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
394
c237e94a
ZW
395#undef TARGET_SCHED_ISSUE_RATE
396#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
397#undef TARGET_SCHED_ADJUST_COST
398#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
399#undef TARGET_SCHED_ADJUST_PRIORITY
400#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
401
0ac081f6
AH
402#undef TARGET_INIT_BUILTINS
403#define TARGET_INIT_BUILTINS rs6000_init_builtins
404
405#undef TARGET_EXPAND_BUILTIN
406#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
407
0e5dbd9b
DE
408#undef TARGET_BINDS_LOCAL_P
409#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
410
3961e8fe
RH
411#undef TARGET_ASM_OUTPUT_MI_THUNK
412#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
413
3961e8fe 414#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 415#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 416
4977bab6
ZW
417#undef TARGET_FUNCTION_OK_FOR_SIBCALL
418#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
419
3c50106f
RH
420#undef TARGET_RTX_COSTS
421#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
422#undef TARGET_ADDRESS_COST
423#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 424
62e1dfcf
NC
425#undef TARGET_VECTOR_TYPES_COMPATIBLE
426#define TARGET_VECTOR_TYPES_COMPATIBLE rs6000_spe_vector_types_compatible
427
f6897b10 428struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 429\f
5248c961
RK
430/* Override command line options. Mostly we process the processor
431 type and sometimes adjust other TARGET_ options. */
432
433void
8e3f41e7 434rs6000_override_options (default_cpu)
d330fd93 435 const char *default_cpu;
5248c961 436{
c4d38ccb 437 size_t i, j;
8e3f41e7 438 struct rs6000_cpu_select *ptr;
5248c961 439
85638c0d
RK
440 /* Simplify the entries below by making a mask for any POWER
441 variant and any PowerPC variant. */
442
938937d8 443#define POWER_MASKS (MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING)
68c49ffa
RK
444#define POWERPC_MASKS (MASK_POWERPC | MASK_PPC_GPOPT \
445 | MASK_PPC_GFXOPT | MASK_POWERPC64)
446#define POWERPC_OPT_MASKS (MASK_PPC_GPOPT | MASK_PPC_GFXOPT)
85638c0d 447
5248c961
RK
448 static struct ptt
449 {
8b60264b
KG
450 const char *const name; /* Canonical processor name. */
451 const enum processor_type processor; /* Processor type enum value. */
452 const int target_enable; /* Target flags to enable. */
453 const int target_disable; /* Target flags to disable. */
454 } const processor_target_table[]
cf27b467
MM
455 = {{"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS,
456 POWER_MASKS | POWERPC_MASKS},
db7f1e43 457 {"power", PROCESSOR_POWER,
938937d8 458 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43 459 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
8e3f41e7
MM
460 {"power2", PROCESSOR_POWER,
461 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
462 POWERPC_MASKS | MASK_NEW_MNEMONICS},
c71791e0
DE
463 {"power3", PROCESSOR_PPC630,
464 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
465 POWER_MASKS | MASK_PPC_GPOPT},
309323c2
DE
466 {"power4", PROCESSOR_POWER4,
467 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
468 POWER_MASKS | MASK_PPC_GPOPT},
db7f1e43
RK
469 {"powerpc", PROCESSOR_POWERPC,
470 MASK_POWERPC | MASK_NEW_MNEMONICS,
68c49ffa 471 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
3cb999d8
DE
472 {"powerpc64", PROCESSOR_POWERPC64,
473 MASK_POWERPC | MASK_POWERPC64 | MASK_NEW_MNEMONICS,
474 POWER_MASKS | POWERPC_OPT_MASKS},
db7f1e43 475 {"rios", PROCESSOR_RIOS1,
938937d8 476 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
477 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
478 {"rios1", PROCESSOR_RIOS1,
938937d8 479 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
480 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
481 {"rsc", PROCESSOR_PPC601,
938937d8 482 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
483 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
484 {"rsc1", PROCESSOR_PPC601,
938937d8 485 MASK_POWER | MASK_MULTIPLE | MASK_STRING,
db7f1e43
RK
486 MASK_POWER2 | POWERPC_MASKS | MASK_NEW_MNEMONICS},
487 {"rios2", PROCESSOR_RIOS2,
938937d8 488 MASK_POWER | MASK_MULTIPLE | MASK_STRING | MASK_POWER2,
db7f1e43 489 POWERPC_MASKS | MASK_NEW_MNEMONICS},
3cb999d8
DE
490 {"rs64a", PROCESSOR_RS64A,
491 MASK_POWERPC | MASK_NEW_MNEMONICS,
492 POWER_MASKS | POWERPC_OPT_MASKS},
a3a1dbf6
MM
493 {"401", PROCESSOR_PPC403,
494 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
495 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
49a0b204 496 {"403", PROCESSOR_PPC403,
daf11973 497 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS | MASK_STRICT_ALIGN,
49a0b204 498 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
d7a5e253
DE
499 {"405", PROCESSOR_PPC405,
500 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
501 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
4977bab6
ZW
502 {"405f", PROCESSOR_PPC405,
503 MASK_POWERPC | MASK_NEW_MNEMONICS,
504 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
505 {"505", PROCESSOR_MPCCORE,
506 MASK_POWERPC | MASK_NEW_MNEMONICS,
507 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 508 {"601", PROCESSOR_PPC601,
938937d8 509 MASK_POWER | MASK_POWERPC | MASK_NEW_MNEMONICS | MASK_MULTIPLE | MASK_STRING,
68c49ffa 510 MASK_POWER2 | POWERPC_OPT_MASKS | MASK_POWERPC64},
1ec26da6 511 {"602", PROCESSOR_PPC603,
cf27b467
MM
512 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
513 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
5248c961 514 {"603", PROCESSOR_PPC603,
68c49ffa
RK
515 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
516 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a
MM
517 {"603e", PROCESSOR_PPC603,
518 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
519 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b5370a88 520 {"ec603e", PROCESSOR_PPC603,
a3a1dbf6
MM
521 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
522 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
5248c961 523 {"604", PROCESSOR_PPC604,
b6c9286a
MM
524 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
525 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
cac8ce95 526 {"604e", PROCESSOR_PPC604e,
07e6159a
MM
527 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
528 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
b6c9286a 529 {"620", PROCESSOR_PPC620,
68c49ffa 530 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
a260abc9 531 POWER_MASKS | MASK_PPC_GPOPT},
3cb999d8
DE
532 {"630", PROCESSOR_PPC630,
533 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
534 POWER_MASKS | MASK_PPC_GPOPT},
bef84347
VM
535 {"740", PROCESSOR_PPC750,
536 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
537 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
538 {"750", PROCESSOR_PPC750,
539 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
540 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a4f6c312
SS
541 {"7400", PROCESSOR_PPC7400,
542 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
543 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
544 {"7450", PROCESSOR_PPC7450,
545 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
546 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
a3170dc6
AH
547 {"8540", PROCESSOR_PPC8540,
548 MASK_POWERPC | MASK_PPC_GFXOPT | MASK_NEW_MNEMONICS,
549 POWER_MASKS | MASK_PPC_GPOPT | MASK_POWERPC64},
07e6159a
MM
550 {"801", PROCESSOR_MPCCORE,
551 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
552 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
553 {"821", PROCESSOR_MPCCORE,
554 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
555 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
07e6159a
MM
556 {"823", PROCESSOR_MPCCORE,
557 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
558 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64},
cf27b467
MM
559 {"860", PROCESSOR_MPCCORE,
560 MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
561 POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
5248c961 562
ca7558fc 563 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 564
a4f6c312
SS
565 /* Save current -mmultiple/-mno-multiple status. */
566 int multiple = TARGET_MULTIPLE;
567 /* Save current -mstring/-mno-string status. */
568 int string = TARGET_STRING;
8a61d227 569
a4f6c312 570 /* Identify the processor type. */
8e3f41e7 571 rs6000_select[0].string = default_cpu;
3cb999d8 572 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 573
b6a1cbae 574 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 575 {
8e3f41e7
MM
576 ptr = &rs6000_select[i];
577 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 578 {
8e3f41e7
MM
579 for (j = 0; j < ptt_size; j++)
580 if (! strcmp (ptr->string, processor_target_table[j].name))
581 {
582 if (ptr->set_tune_p)
583 rs6000_cpu = processor_target_table[j].processor;
584
585 if (ptr->set_arch_p)
586 {
587 target_flags |= processor_target_table[j].target_enable;
588 target_flags &= ~processor_target_table[j].target_disable;
589 }
590 break;
591 }
592
4406229e 593 if (j == ptt_size)
8e3f41e7 594 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
595 }
596 }
8a61d227 597
a3170dc6
AH
598 if (rs6000_cpu == PROCESSOR_PPC8540)
599 rs6000_isel = 1;
600
dff9f1b6
DE
601 /* If we are optimizing big endian systems for space, use the load/store
602 multiple and string instructions. */
ef792183 603 if (BYTES_BIG_ENDIAN && optimize_size)
dff9f1b6 604 target_flags |= MASK_MULTIPLE | MASK_STRING;
ef792183 605
8a61d227
MM
606 /* If -mmultiple or -mno-multiple was explicitly used, don't
607 override with the processor default */
b21fb038 608 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
8a61d227 609 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 610
a4f6c312
SS
611 /* If -mstring or -mno-string was explicitly used, don't override
612 with the processor default. */
b21fb038 613 if ((target_flags_explicit & MASK_STRING) != 0)
1f5515bf 614 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 615
a4f6c312
SS
616 /* Don't allow -mmultiple or -mstring on little endian systems
617 unless the cpu is a 750, because the hardware doesn't support the
618 instructions used in little endian mode, and causes an alignment
619 trap. The 750 does not cause an alignment trap (except when the
620 target is unaligned). */
bef84347 621
b21fb038 622 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
623 {
624 if (TARGET_MULTIPLE)
625 {
626 target_flags &= ~MASK_MULTIPLE;
b21fb038 627 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
628 warning ("-mmultiple is not supported on little endian systems");
629 }
630
631 if (TARGET_STRING)
632 {
633 target_flags &= ~MASK_STRING;
b21fb038 634 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 635 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
636 }
637 }
3933e0e1 638
ee2ca2a2 639 if (flag_pic != 0 && DEFAULT_ABI == ABI_AIX)
a260abc9 640 {
0e5dbd9b 641 rs6000_flag_pic = flag_pic;
ee2ca2a2 642 flag_pic = 0;
a260abc9
DE
643 }
644
c72bfda7
SS
645 /* For Darwin, always silently make -fpic and -fPIC identical. */
646 if (flag_pic == 1 && DEFAULT_ABI == ABI_DARWIN)
647 flag_pic = 2;
648
38c1f2d7
MM
649 /* Set debug flags */
650 if (rs6000_debug_name)
651 {
bfc79d3b 652 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 653 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 654 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 655 rs6000_debug_stack = 1;
bfc79d3b 656 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
657 rs6000_debug_arg = 1;
658 else
c725bd79 659 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
660 }
661
57ac7be9
AM
662 if (rs6000_traceback_name)
663 {
664 if (! strncmp (rs6000_traceback_name, "full", 4))
665 rs6000_traceback = traceback_full;
666 else if (! strncmp (rs6000_traceback_name, "part", 4))
667 rs6000_traceback = traceback_part;
668 else if (! strncmp (rs6000_traceback_name, "no", 2))
669 rs6000_traceback = traceback_none;
670 else
671 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
672 rs6000_traceback_name);
673 }
674
6fa3f289
ZW
675 /* Set size of long double */
676 rs6000_long_double_type_size = 64;
677 if (rs6000_long_double_size_string)
678 {
679 char *tail;
680 int size = strtol (rs6000_long_double_size_string, &tail, 10);
681 if (*tail != '\0' || (size != 64 && size != 128))
682 error ("Unknown switch -mlong-double-%s",
683 rs6000_long_double_size_string);
684 else
685 rs6000_long_double_type_size = size;
686 }
687
0ac081f6
AH
688 /* Handle -mabi= options. */
689 rs6000_parse_abi_options ();
690
08b57fb3
AH
691 /* Handle -mvrsave= option. */
692 rs6000_parse_vrsave_option ();
693
a3170dc6
AH
694 /* Handle -misel= option. */
695 rs6000_parse_isel_option ();
696
a7ae18e2
AH
697#ifdef SUBTARGET_OVERRIDE_OPTIONS
698 SUBTARGET_OVERRIDE_OPTIONS;
699#endif
700#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
701 SUBSUBTARGET_OVERRIDE_OPTIONS;
702#endif
703
a5c76ee6
ZW
704 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
705 using TARGET_OPTIONS to handle a toggle switch, but we're out of
706 bits in target_flags so TARGET_SWITCHES cannot be used.
707 Assumption here is that rs6000_longcall_switch points into the
708 text of the complete option, rather than being a copy, so we can
709 scan back for the presence or absence of the no- modifier. */
710 if (rs6000_longcall_switch)
711 {
712 const char *base = rs6000_longcall_switch;
713 while (base[-1] != 'm') base--;
714
715 if (*rs6000_longcall_switch != '\0')
716 error ("invalid option `%s'", base);
717 rs6000_default_long_calls = (base[0] != 'n');
718 }
719
c81bebd7 720#ifdef TARGET_REGNAMES
a4f6c312
SS
721 /* If the user desires alternate register names, copy in the
722 alternate names now. */
c81bebd7 723 if (TARGET_REGNAMES)
4e135bdd 724 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
725#endif
726
6fa3f289
ZW
727 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
728 If -maix-struct-return or -msvr4-struct-return was explicitly
729 used, don't override with the ABI default. */
b21fb038 730 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
731 {
732 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
733 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
734 else
735 target_flags |= MASK_AIX_STRUCT_RET;
736 }
737
fcce224d
DE
738 if (TARGET_LONG_DOUBLE_128
739 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
740 real_format_for_mode[TFmode - QFmode] = &ibm_extended_format;
741
9ebbca7d
GK
742 /* Allocate an alias set for register saves & restores from stack. */
743 rs6000_sr_alias_set = new_alias_set ();
744
745 if (TARGET_TOC)
746 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 747
301d03af
RS
748 /* We can only guarantee the availability of DI pseudo-ops when
749 assembling for 64-bit targets. */
ae6c1efd 750 if (!TARGET_64BIT)
301d03af
RS
751 {
752 targetm.asm_out.aligned_op.di = NULL;
753 targetm.asm_out.unaligned_op.di = NULL;
754 }
755
71f123ca
FS
756 /* Arrange to save and restore machine status around nested functions. */
757 init_machine_status = rs6000_init_machine_status;
5248c961 758}
5accd822 759
a3170dc6
AH
760/* Handle -misel= option. */
761static void
762rs6000_parse_isel_option ()
763{
764 if (rs6000_isel_string == 0)
765 return;
766 else if (! strcmp (rs6000_isel_string, "yes"))
767 rs6000_isel = 1;
768 else if (! strcmp (rs6000_isel_string, "no"))
769 rs6000_isel = 0;
770 else
771 error ("unknown -misel= option specified: '%s'",
772 rs6000_isel_string);
773}
774
08b57fb3
AH
775/* Handle -mvrsave= options. */
776static void
777rs6000_parse_vrsave_option ()
778{
779 /* Generate VRSAVE instructions by default. */
780 if (rs6000_altivec_vrsave_string == 0
781 || ! strcmp (rs6000_altivec_vrsave_string, "yes"))
782 rs6000_altivec_vrsave = 1;
783 else if (! strcmp (rs6000_altivec_vrsave_string, "no"))
784 rs6000_altivec_vrsave = 0;
785 else
786 error ("unknown -mvrsave= option specified: '%s'",
787 rs6000_altivec_vrsave_string);
788}
789
0ac081f6 790/* Handle -mabi= options. */
00b960c7
AH
791static void
792rs6000_parse_abi_options ()
0ac081f6
AH
793{
794 if (rs6000_abi_string == 0)
795 return;
796 else if (! strcmp (rs6000_abi_string, "altivec"))
6fa3f289 797 rs6000_altivec_abi = 1;
76a773f3
AH
798 else if (! strcmp (rs6000_abi_string, "no-altivec"))
799 rs6000_altivec_abi = 0;
a3170dc6 800 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
801 {
802 rs6000_spe_abi = 1;
803 if (!TARGET_SPE_ABI)
804 error ("not configured for ABI: '%s'", rs6000_abi_string);
805 }
806
a3170dc6
AH
807 else if (! strcmp (rs6000_abi_string, "no-spe"))
808 rs6000_spe_abi = 0;
0ac081f6 809 else
c725bd79 810 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
811}
812
5accd822
DE
813void
814optimization_options (level, size)
e2c953b6 815 int level ATTRIBUTE_UNUSED;
5accd822
DE
816 int size ATTRIBUTE_UNUSED;
817{
5accd822 818}
3cfa4909
MM
819\f
820/* Do anything needed at the start of the asm file. */
821
822void
823rs6000_file_start (file, default_cpu)
824 FILE *file;
d330fd93 825 const char *default_cpu;
3cfa4909 826{
c4d38ccb 827 size_t i;
3cfa4909 828 char buffer[80];
d330fd93 829 const char *start = buffer;
3cfa4909
MM
830 struct rs6000_cpu_select *ptr;
831
832 if (flag_verbose_asm)
833 {
834 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
835 rs6000_select[0].string = default_cpu;
836
b6a1cbae 837 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
838 {
839 ptr = &rs6000_select[i];
840 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
841 {
842 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
843 start = "";
844 }
845 }
846
b91da81f 847#ifdef USING_ELFOS_H
3cfa4909
MM
848 switch (rs6000_sdata)
849 {
850 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
851 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
852 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
853 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
854 }
855
856 if (rs6000_sdata && g_switch_value)
857 {
858 fprintf (file, "%s -G %d", start, g_switch_value);
859 start = "";
860 }
861#endif
862
863 if (*start == '\0')
949ea356 864 putc ('\n', file);
3cfa4909
MM
865 }
866}
5248c961 867\f
a0ab749a 868/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
869
870int
871direct_return ()
872{
4697a36c
MM
873 if (reload_completed)
874 {
875 rs6000_stack_t *info = rs6000_stack_info ();
876
877 if (info->first_gp_reg_save == 32
878 && info->first_fp_reg_save == 64
00b960c7 879 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
880 && ! info->lr_save_p
881 && ! info->cr_save_p
00b960c7 882 && info->vrsave_mask == 0
c81fc13e 883 && ! info->push_p)
4697a36c
MM
884 return 1;
885 }
886
887 return 0;
9878760c
RK
888}
889
890/* Returns 1 always. */
891
892int
893any_operand (op, mode)
592696dd 894 rtx op ATTRIBUTE_UNUSED;
296b8152 895 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
896{
897 return 1;
898}
899
a4f6c312 900/* Returns 1 if op is the count register. */
38c1f2d7 901int
a4f6c312 902count_register_operand (op, mode)
592696dd 903 rtx op;
296b8152 904 enum machine_mode mode ATTRIBUTE_UNUSED;
b6c9286a
MM
905{
906 if (GET_CODE (op) != REG)
907 return 0;
908
909 if (REGNO (op) == COUNT_REGISTER_REGNUM)
910 return 1;
911
912 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
913 return 1;
914
915 return 0;
916}
917
0ec4e2a8
AH
918/* Returns 1 if op is an altivec register. */
919int
920altivec_register_operand (op, mode)
921 rtx op;
922 enum machine_mode mode ATTRIBUTE_UNUSED;
923{
924
925 return (register_operand (op, mode)
926 && (GET_CODE (op) != REG
927 || REGNO (op) > FIRST_PSEUDO_REGISTER
928 || ALTIVEC_REGNO_P (REGNO (op))));
929}
930
38c1f2d7 931int
a4f6c312 932xer_operand (op, mode)
592696dd 933 rtx op;
296b8152 934 enum machine_mode mode ATTRIBUTE_UNUSED;
802a0058
MM
935{
936 if (GET_CODE (op) != REG)
937 return 0;
938
9ebbca7d 939 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
940 return 1;
941
802a0058
MM
942 return 0;
943}
944
c859cda6 945/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 946 by such constants completes more quickly. */
c859cda6
DJ
947
948int
949s8bit_cint_operand (op, mode)
950 rtx op;
951 enum machine_mode mode ATTRIBUTE_UNUSED;
952{
953 return ( GET_CODE (op) == CONST_INT
954 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
955}
956
9878760c
RK
957/* Return 1 if OP is a constant that can fit in a D field. */
958
959int
960short_cint_operand (op, mode)
592696dd 961 rtx op;
296b8152 962 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 963{
5f59ecb7
DE
964 return (GET_CODE (op) == CONST_INT
965 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
966}
967
5519a4f9 968/* Similar for an unsigned D field. */
9878760c
RK
969
970int
971u_short_cint_operand (op, mode)
592696dd 972 rtx op;
296b8152 973 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 974{
19684119 975 return (GET_CODE (op) == CONST_INT
c1f11548 976 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
977}
978
dcfedcd0
RK
979/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
980
981int
982non_short_cint_operand (op, mode)
592696dd 983 rtx op;
296b8152 984 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
985{
986 return (GET_CODE (op) == CONST_INT
a7653a2c 987 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
988}
989
2bfcf297
DB
990/* Returns 1 if OP is a CONST_INT that is a positive value
991 and an exact power of 2. */
992
993int
994exact_log2_cint_operand (op, mode)
592696dd 995 rtx op;
2bfcf297
DB
996 enum machine_mode mode ATTRIBUTE_UNUSED;
997{
998 return (GET_CODE (op) == CONST_INT
999 && INTVAL (op) > 0
1000 && exact_log2 (INTVAL (op)) >= 0);
1001}
1002
9878760c
RK
1003/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1004 ctr, or lr). */
1005
1006int
cd2b37d9 1007gpc_reg_operand (op, mode)
592696dd 1008 rtx op;
9878760c
RK
1009 enum machine_mode mode;
1010{
1011 return (register_operand (op, mode)
802a0058 1012 && (GET_CODE (op) != REG
9ebbca7d
GK
1013 || (REGNO (op) >= ARG_POINTER_REGNUM
1014 && !XER_REGNO_P (REGNO (op)))
1015 || REGNO (op) < MQ_REGNO));
9878760c
RK
1016}
1017
1018/* Returns 1 if OP is either a pseudo-register or a register denoting a
1019 CR field. */
1020
1021int
1022cc_reg_operand (op, mode)
592696dd 1023 rtx op;
9878760c
RK
1024 enum machine_mode mode;
1025{
1026 return (register_operand (op, mode)
1027 && (GET_CODE (op) != REG
1028 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1029 || CR_REGNO_P (REGNO (op))));
1030}
1031
815cdc52
MM
1032/* Returns 1 if OP is either a pseudo-register or a register denoting a
1033 CR field that isn't CR0. */
1034
1035int
1036cc_reg_not_cr0_operand (op, mode)
592696dd 1037 rtx op;
815cdc52
MM
1038 enum machine_mode mode;
1039{
1040 return (register_operand (op, mode)
1041 && (GET_CODE (op) != REG
1042 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1043 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1044}
1045
a4f6c312
SS
1046/* Returns 1 if OP is either a constant integer valid for a D-field or
1047 a non-special register. If a register, it must be in the proper
1048 mode unless MODE is VOIDmode. */
9878760c
RK
1049
1050int
1051reg_or_short_operand (op, mode)
592696dd 1052 rtx op;
9878760c
RK
1053 enum machine_mode mode;
1054{
f5a28898 1055 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1056}
1057
a4f6c312
SS
1058/* Similar, except check if the negation of the constant would be
1059 valid for a D-field. */
9878760c
RK
1060
1061int
1062reg_or_neg_short_operand (op, mode)
592696dd 1063 rtx op;
9878760c
RK
1064 enum machine_mode mode;
1065{
1066 if (GET_CODE (op) == CONST_INT)
1067 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1068
cd2b37d9 1069 return gpc_reg_operand (op, mode);
9878760c
RK
1070}
1071
768070a0
TR
1072/* Returns 1 if OP is either a constant integer valid for a DS-field or
1073 a non-special register. If a register, it must be in the proper
1074 mode unless MODE is VOIDmode. */
1075
1076int
1077reg_or_aligned_short_operand (op, mode)
1078 rtx op;
1079 enum machine_mode mode;
1080{
1081 if (gpc_reg_operand (op, mode))
1082 return 1;
1083 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1084 return 1;
1085
1086 return 0;
1087}
1088
1089
a4f6c312
SS
1090/* Return 1 if the operand is either a register or an integer whose
1091 high-order 16 bits are zero. */
9878760c
RK
1092
1093int
1094reg_or_u_short_operand (op, mode)
592696dd 1095 rtx op;
9878760c
RK
1096 enum machine_mode mode;
1097{
e675f625 1098 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1099}
1100
1101/* Return 1 is the operand is either a non-special register or ANY
1102 constant integer. */
1103
1104int
1105reg_or_cint_operand (op, mode)
592696dd 1106 rtx op;
9878760c
RK
1107 enum machine_mode mode;
1108{
a4f6c312 1109 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1110}
1111
1112/* Return 1 is the operand is either a non-special register or ANY
1113 32-bit signed constant integer. */
1114
1115int
1116reg_or_arith_cint_operand (op, mode)
592696dd 1117 rtx op;
f6bf7de2
DE
1118 enum machine_mode mode;
1119{
a4f6c312
SS
1120 return (gpc_reg_operand (op, mode)
1121 || (GET_CODE (op) == CONST_INT
f6bf7de2 1122#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1123 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1124 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1125#endif
a4f6c312 1126 ));
9878760c
RK
1127}
1128
2bfcf297
DB
1129/* Return 1 is the operand is either a non-special register or a 32-bit
1130 signed constant integer valid for 64-bit addition. */
1131
1132int
1133reg_or_add_cint64_operand (op, mode)
592696dd 1134 rtx op;
2bfcf297
DB
1135 enum machine_mode mode;
1136{
a4f6c312
SS
1137 return (gpc_reg_operand (op, mode)
1138 || (GET_CODE (op) == CONST_INT
a65c591c 1139#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1140 && INTVAL (op) < 0x7fff8000
a65c591c 1141#else
a4f6c312
SS
1142 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1143 < 0x100000000ll)
2bfcf297 1144#endif
a4f6c312 1145 ));
2bfcf297
DB
1146}
1147
1148/* Return 1 is the operand is either a non-special register or a 32-bit
1149 signed constant integer valid for 64-bit subtraction. */
1150
1151int
1152reg_or_sub_cint64_operand (op, mode)
592696dd 1153 rtx op;
2bfcf297
DB
1154 enum machine_mode mode;
1155{
a4f6c312
SS
1156 return (gpc_reg_operand (op, mode)
1157 || (GET_CODE (op) == CONST_INT
a65c591c 1158#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1159 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1160#else
a4f6c312
SS
1161 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1162 < 0x100000000ll)
2bfcf297 1163#endif
a4f6c312 1164 ));
2bfcf297
DB
1165}
1166
9ebbca7d
GK
1167/* Return 1 is the operand is either a non-special register or ANY
1168 32-bit unsigned constant integer. */
1169
1170int
1d328b19 1171reg_or_logical_cint_operand (op, mode)
592696dd 1172 rtx op;
9ebbca7d
GK
1173 enum machine_mode mode;
1174{
1d328b19
GK
1175 if (GET_CODE (op) == CONST_INT)
1176 {
1177 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1178 {
1179 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1180 abort ();
1d328b19
GK
1181
1182 if (INTVAL (op) < 0)
1183 return 0;
1184 }
1185
1186 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1187 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1188 }
1189 else if (GET_CODE (op) == CONST_DOUBLE)
1190 {
1191 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1192 || mode != DImode)
a4f6c312 1193 abort ();
1d328b19
GK
1194
1195 return CONST_DOUBLE_HIGH (op) == 0;
1196 }
1197 else
1198 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1199}
1200
51d3e7d6 1201/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1202
1203int
1204got_operand (op, mode)
592696dd 1205 rtx op;
296b8152 1206 enum machine_mode mode ATTRIBUTE_UNUSED;
766a866c
MM
1207{
1208 return (GET_CODE (op) == SYMBOL_REF
1209 || GET_CODE (op) == CONST
1210 || GET_CODE (op) == LABEL_REF);
1211}
1212
38c1f2d7
MM
1213/* Return 1 if the operand is a simple references that can be loaded via
1214 the GOT (labels involving addition aren't allowed). */
1215
1216int
1217got_no_const_operand (op, mode)
592696dd 1218 rtx op;
296b8152 1219 enum machine_mode mode ATTRIBUTE_UNUSED;
38c1f2d7
MM
1220{
1221 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1222}
1223
4e74d8ec
MM
1224/* Return the number of instructions it takes to form a constant in an
1225 integer register. */
1226
1227static int
1228num_insns_constant_wide (value)
1229 HOST_WIDE_INT value;
1230{
1231 /* signed constant loadable with {cal|addi} */
5f59ecb7 1232 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1233 return 1;
1234
4e74d8ec 1235 /* constant loadable with {cau|addis} */
5f59ecb7 1236 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1237 return 1;
1238
5f59ecb7 1239#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1240 else if (TARGET_POWERPC64)
4e74d8ec 1241 {
a65c591c
DE
1242 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1243 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1244
a65c591c 1245 if (high == 0 || high == -1)
4e74d8ec
MM
1246 return 2;
1247
a65c591c 1248 high >>= 1;
4e74d8ec 1249
a65c591c 1250 if (low == 0)
4e74d8ec 1251 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1252 else
1253 return (num_insns_constant_wide (high)
e396202a 1254 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1255 }
1256#endif
1257
1258 else
1259 return 2;
1260}
1261
1262int
1263num_insns_constant (op, mode)
1264 rtx op;
1265 enum machine_mode mode;
1266{
4e74d8ec 1267 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1268 {
1269#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1270 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1271 && mask64_operand (op, mode))
0d30d435
DE
1272 return 2;
1273 else
1274#endif
1275 return num_insns_constant_wide (INTVAL (op));
1276 }
4e74d8ec 1277
6fc48950
MM
1278 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1279 {
1280 long l;
1281 REAL_VALUE_TYPE rv;
1282
1283 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1284 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1285 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1286 }
1287
47ad8c61 1288 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1289 {
47ad8c61
MM
1290 HOST_WIDE_INT low;
1291 HOST_WIDE_INT high;
1292 long l[2];
1293 REAL_VALUE_TYPE rv;
1294 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1295
47ad8c61
MM
1296 if (mode == VOIDmode || mode == DImode)
1297 {
1298 high = CONST_DOUBLE_HIGH (op);
1299 low = CONST_DOUBLE_LOW (op);
1300 }
1301 else
1302 {
1303 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1304 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1305 high = l[endian];
1306 low = l[1 - endian];
1307 }
4e74d8ec 1308
47ad8c61
MM
1309 if (TARGET_32BIT)
1310 return (num_insns_constant_wide (low)
1311 + num_insns_constant_wide (high));
4e74d8ec
MM
1312
1313 else
47ad8c61 1314 {
e72247f4 1315 if (high == 0 && low >= 0)
47ad8c61
MM
1316 return num_insns_constant_wide (low);
1317
e72247f4 1318 else if (high == -1 && low < 0)
47ad8c61
MM
1319 return num_insns_constant_wide (low);
1320
a260abc9
DE
1321 else if (mask64_operand (op, mode))
1322 return 2;
1323
47ad8c61
MM
1324 else if (low == 0)
1325 return num_insns_constant_wide (high) + 1;
1326
1327 else
1328 return (num_insns_constant_wide (high)
1329 + num_insns_constant_wide (low) + 1);
1330 }
4e74d8ec
MM
1331 }
1332
1333 else
1334 abort ();
1335}
1336
a4f6c312
SS
1337/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1338 register with one instruction per word. We only do this if we can
1339 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1340
1341int
1342easy_fp_constant (op, mode)
592696dd
SS
1343 rtx op;
1344 enum machine_mode mode;
9878760c 1345{
9878760c
RK
1346 if (GET_CODE (op) != CONST_DOUBLE
1347 || GET_MODE (op) != mode
4e74d8ec 1348 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1349 return 0;
1350
a4f6c312 1351 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1352 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1353 && mode != DImode)
b6c9286a
MM
1354 return 1;
1355
a4f6c312 1356 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1357 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1358 return 0;
1359
5ae4759c 1360#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1361 /* Similarly if we are using -mrelocatable, consider all constants
1362 to be hard. */
5ae4759c
MM
1363 if (TARGET_RELOCATABLE)
1364 return 0;
1365#endif
1366
fcce224d
DE
1367 if (mode == TFmode)
1368 {
1369 long k[4];
1370 REAL_VALUE_TYPE rv;
1371
1372 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1373 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1374
1375 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1376 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1377 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1378 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1379 }
1380
1381 else if (mode == DFmode)
042259f2
DE
1382 {
1383 long k[2];
1384 REAL_VALUE_TYPE rv;
1385
1386 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1387 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1388
a65c591c
DE
1389 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1390 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1391 }
4e74d8ec
MM
1392
1393 else if (mode == SFmode)
042259f2
DE
1394 {
1395 long l;
1396 REAL_VALUE_TYPE rv;
1397
1398 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1399 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1400
4e74d8ec 1401 return num_insns_constant_wide (l) == 1;
042259f2 1402 }
4e74d8ec 1403
a260abc9 1404 else if (mode == DImode)
c81fc13e 1405 return ((TARGET_POWERPC64
a260abc9
DE
1406 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1407 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1408
a9098fd0
GK
1409 else if (mode == SImode)
1410 return 1;
4e74d8ec
MM
1411 else
1412 abort ();
9878760c 1413}
8f75773e 1414
69ef87e2
AH
1415/* Return 1 if the operand is a CONST_INT and can be put into a
1416 register with one instruction. */
1417
1418static int
1419easy_vector_constant (op)
1420 rtx op;
1421{
1422 rtx elt;
1423 int units, i;
1424
1425 if (GET_CODE (op) != CONST_VECTOR)
1426 return 0;
1427
1428 units = CONST_VECTOR_NUNITS (op);
1429
1430 /* We can generate 0 easily. Look for that. */
1431 for (i = 0; i < units; ++i)
1432 {
1433 elt = CONST_VECTOR_ELT (op, i);
1434
1435 /* We could probably simplify this by just checking for equality
1436 with CONST0_RTX for the current mode, but let's be safe
1437 instead. */
1438
98ef3137
JJ
1439 switch (GET_CODE (elt))
1440 {
1441 case CONST_INT:
1442 if (INTVAL (elt) != 0)
1443 return 0;
1444 break;
1445 case CONST_DOUBLE:
1446 if (CONST_DOUBLE_LOW (elt) != 0 || CONST_DOUBLE_HIGH (elt) != 0)
1447 return 0;
1448 break;
1449 default:
1450 return 0;
1451 }
69ef87e2
AH
1452 }
1453
1454 /* We could probably generate a few other constants trivially, but
1455 gcc doesn't generate them yet. FIXME later. */
98ef3137 1456 return 1;
69ef87e2
AH
1457}
1458
1459/* Return 1 if the operand is the constant 0. This works for scalars
1460 as well as vectors. */
1461int
1462zero_constant (op, mode)
1463 rtx op;
1464 enum machine_mode mode;
1465{
1466 return op == CONST0_RTX (mode);
1467}
1468
50a0b056
GK
1469/* Return 1 if the operand is 0.0. */
1470int
1471zero_fp_constant (op, mode)
592696dd
SS
1472 rtx op;
1473 enum machine_mode mode;
50a0b056
GK
1474{
1475 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1476}
1477
a4f6c312
SS
1478/* Return 1 if the operand is in volatile memory. Note that during
1479 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1480 volatile memory references. So this function allows us to
1481 recognize volatile references where its safe. */
1482
1483int
1484volatile_mem_operand (op, mode)
592696dd 1485 rtx op;
b6c9286a
MM
1486 enum machine_mode mode;
1487{
1488 if (GET_CODE (op) != MEM)
1489 return 0;
1490
1491 if (!MEM_VOLATILE_P (op))
1492 return 0;
1493
1494 if (mode != GET_MODE (op))
1495 return 0;
1496
1497 if (reload_completed)
1498 return memory_operand (op, mode);
1499
1500 if (reload_in_progress)
1501 return strict_memory_address_p (mode, XEXP (op, 0));
1502
1503 return memory_address_p (mode, XEXP (op, 0));
1504}
1505
97f6e72f 1506/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1507
1508int
97f6e72f 1509offsettable_mem_operand (op, mode)
592696dd 1510 rtx op;
914c2e77
RK
1511 enum machine_mode mode;
1512{
97f6e72f 1513 return ((GET_CODE (op) == MEM)
677a9668 1514 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1515 mode, XEXP (op, 0)));
914c2e77
RK
1516}
1517
9878760c
RK
1518/* Return 1 if the operand is either an easy FP constant (see above) or
1519 memory. */
1520
1521int
1522mem_or_easy_const_operand (op, mode)
592696dd 1523 rtx op;
9878760c
RK
1524 enum machine_mode mode;
1525{
1526 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1527}
1528
1529/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1530 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1531
1532int
1533add_operand (op, mode)
592696dd 1534 rtx op;
9878760c
RK
1535 enum machine_mode mode;
1536{
2bfcf297 1537 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1538 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1539 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1540
1541 return gpc_reg_operand (op, mode);
9878760c
RK
1542}
1543
dcfedcd0
RK
1544/* Return 1 if OP is a constant but not a valid add_operand. */
1545
1546int
1547non_add_cint_operand (op, mode)
592696dd 1548 rtx op;
296b8152 1549 enum machine_mode mode ATTRIBUTE_UNUSED;
dcfedcd0
RK
1550{
1551 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1552 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1553 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1554}
1555
9878760c
RK
1556/* Return 1 if the operand is a non-special register or a constant that
1557 can be used as the operand of an OR or XOR insn on the RS/6000. */
1558
1559int
1560logical_operand (op, mode)
592696dd 1561 rtx op;
9878760c
RK
1562 enum machine_mode mode;
1563{
40501e5f 1564 HOST_WIDE_INT opl, oph;
1d328b19 1565
dfbdccdb
GK
1566 if (gpc_reg_operand (op, mode))
1567 return 1;
1d328b19 1568
dfbdccdb 1569 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1570 {
1571 opl = INTVAL (op) & GET_MODE_MASK (mode);
1572
1573#if HOST_BITS_PER_WIDE_INT <= 32
1574 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1575 return 0;
1576#endif
1577 }
dfbdccdb
GK
1578 else if (GET_CODE (op) == CONST_DOUBLE)
1579 {
1d328b19 1580 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1581 abort ();
1d328b19
GK
1582
1583 opl = CONST_DOUBLE_LOW (op);
1584 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1585 if (oph != 0)
38886f37 1586 return 0;
dfbdccdb
GK
1587 }
1588 else
1589 return 0;
1d328b19 1590
40501e5f
AM
1591 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1592 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1593}
1594
dcfedcd0 1595/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1596 above), but could be split into one. */
dcfedcd0
RK
1597
1598int
1599non_logical_cint_operand (op, mode)
592696dd 1600 rtx op;
5f59ecb7 1601 enum machine_mode mode;
dcfedcd0 1602{
dfbdccdb 1603 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1604 && ! logical_operand (op, mode)
1605 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1606}
1607
19ba8161 1608/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1609 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1610 Reject all ones and all zeros, since these should have been optimized
1611 away and confuse the making of MB and ME. */
1612
1613int
19ba8161 1614mask_operand (op, mode)
592696dd 1615 rtx op;
19ba8161 1616 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c 1617{
02071907 1618 HOST_WIDE_INT c, lsb;
9878760c 1619
19ba8161
DE
1620 if (GET_CODE (op) != CONST_INT)
1621 return 0;
1622
1623 c = INTVAL (op);
1624
57deb3a1
AM
1625 /* Fail in 64-bit mode if the mask wraps around because the upper
1626 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1627 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1628 return 0;
1629
c5059423
AM
1630 /* We don't change the number of transitions by inverting,
1631 so make sure we start with the LS bit zero. */
1632 if (c & 1)
1633 c = ~c;
1634
1635 /* Reject all zeros or all ones. */
1636 if (c == 0)
9878760c
RK
1637 return 0;
1638
c5059423
AM
1639 /* Find the first transition. */
1640 lsb = c & -c;
1641
1642 /* Invert to look for a second transition. */
1643 c = ~c;
9878760c 1644
c5059423
AM
1645 /* Erase first transition. */
1646 c &= -lsb;
9878760c 1647
c5059423
AM
1648 /* Find the second transition (if any). */
1649 lsb = c & -c;
1650
1651 /* Match if all the bits above are 1's (or c is zero). */
1652 return c == -lsb;
9878760c
RK
1653}
1654
0ba1b2ff
AM
1655/* Return 1 for the PowerPC64 rlwinm corner case. */
1656
1657int
1658mask_operand_wrap (op, mode)
1659 rtx op;
1660 enum machine_mode mode ATTRIBUTE_UNUSED;
1661{
1662 HOST_WIDE_INT c, lsb;
1663
1664 if (GET_CODE (op) != CONST_INT)
1665 return 0;
1666
1667 c = INTVAL (op);
1668
1669 if ((c & 0x80000001) != 0x80000001)
1670 return 0;
1671
1672 c = ~c;
1673 if (c == 0)
1674 return 0;
1675
1676 lsb = c & -c;
1677 c = ~c;
1678 c &= -lsb;
1679 lsb = c & -c;
1680 return c == -lsb;
1681}
1682
a260abc9
DE
1683/* Return 1 if the operand is a constant that is a PowerPC64 mask.
1684 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
1685 Reject all zeros, since zero should have been optimized away and
1686 confuses the making of MB and ME. */
9878760c
RK
1687
1688int
a260abc9 1689mask64_operand (op, mode)
592696dd 1690 rtx op;
0ba1b2ff 1691 enum machine_mode mode ATTRIBUTE_UNUSED;
a260abc9
DE
1692{
1693 if (GET_CODE (op) == CONST_INT)
1694 {
02071907 1695 HOST_WIDE_INT c, lsb;
a260abc9 1696
c5059423 1697 c = INTVAL (op);
a260abc9 1698
0ba1b2ff 1699 /* Reject all zeros. */
c5059423 1700 if (c == 0)
e2c953b6
DE
1701 return 0;
1702
0ba1b2ff
AM
1703 /* We don't change the number of transitions by inverting,
1704 so make sure we start with the LS bit zero. */
1705 if (c & 1)
1706 c = ~c;
1707
c5059423
AM
1708 /* Find the transition, and check that all bits above are 1's. */
1709 lsb = c & -c;
e3981aab
DE
1710
1711 /* Match if all the bits above are 1's (or c is zero). */
c5059423 1712 return c == -lsb;
e2c953b6 1713 }
0ba1b2ff
AM
1714 return 0;
1715}
1716
1717/* Like mask64_operand, but allow up to three transitions. This
1718 predicate is used by insn patterns that generate two rldicl or
1719 rldicr machine insns. */
1720
1721int
1722mask64_2_operand (op, mode)
1723 rtx op;
1724 enum machine_mode mode ATTRIBUTE_UNUSED;
1725{
1726 if (GET_CODE (op) == CONST_INT)
a260abc9 1727 {
0ba1b2ff 1728 HOST_WIDE_INT c, lsb;
a260abc9 1729
0ba1b2ff 1730 c = INTVAL (op);
a260abc9 1731
0ba1b2ff
AM
1732 /* Disallow all zeros. */
1733 if (c == 0)
1734 return 0;
a260abc9 1735
0ba1b2ff
AM
1736 /* We don't change the number of transitions by inverting,
1737 so make sure we start with the LS bit zero. */
1738 if (c & 1)
1739 c = ~c;
a260abc9 1740
0ba1b2ff
AM
1741 /* Find the first transition. */
1742 lsb = c & -c;
a260abc9 1743
0ba1b2ff
AM
1744 /* Invert to look for a second transition. */
1745 c = ~c;
1746
1747 /* Erase first transition. */
1748 c &= -lsb;
1749
1750 /* Find the second transition. */
1751 lsb = c & -c;
1752
1753 /* Invert to look for a third transition. */
1754 c = ~c;
1755
1756 /* Erase second transition. */
1757 c &= -lsb;
1758
1759 /* Find the third transition (if any). */
1760 lsb = c & -c;
1761
1762 /* Match if all the bits above are 1's (or c is zero). */
1763 return c == -lsb;
1764 }
1765 return 0;
1766}
1767
1768/* Generates shifts and masks for a pair of rldicl or rldicr insns to
1769 implement ANDing by the mask IN. */
1770void
1771build_mask64_2_operands (in, out)
1772 rtx in;
1773 rtx *out;
1774{
1775#if HOST_BITS_PER_WIDE_INT >= 64
1776 unsigned HOST_WIDE_INT c, lsb, m1, m2;
1777 int shift;
1778
1779 if (GET_CODE (in) != CONST_INT)
1780 abort ();
1781
1782 c = INTVAL (in);
1783 if (c & 1)
1784 {
1785 /* Assume c initially something like 0x00fff000000fffff. The idea
1786 is to rotate the word so that the middle ^^^^^^ group of zeros
1787 is at the MS end and can be cleared with an rldicl mask. We then
1788 rotate back and clear off the MS ^^ group of zeros with a
1789 second rldicl. */
1790 c = ~c; /* c == 0xff000ffffff00000 */
1791 lsb = c & -c; /* lsb == 0x0000000000100000 */
1792 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
1793 c = ~c; /* c == 0x00fff000000fffff */
1794 c &= -lsb; /* c == 0x00fff00000000000 */
1795 lsb = c & -c; /* lsb == 0x0000100000000000 */
1796 c = ~c; /* c == 0xff000fffffffffff */
1797 c &= -lsb; /* c == 0xff00000000000000 */
1798 shift = 0;
1799 while ((lsb >>= 1) != 0)
1800 shift++; /* shift == 44 on exit from loop */
1801 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
1802 m1 = ~m1; /* m1 == 0x000000ffffffffff */
1803 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
1804 }
1805 else
0ba1b2ff
AM
1806 {
1807 /* Assume c initially something like 0xff000f0000000000. The idea
1808 is to rotate the word so that the ^^^ middle group of zeros
1809 is at the LS end and can be cleared with an rldicr mask. We then
1810 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
1811 a second rldicr. */
1812 lsb = c & -c; /* lsb == 0x0000010000000000 */
1813 m2 = -lsb; /* m2 == 0xffffff0000000000 */
1814 c = ~c; /* c == 0x00fff0ffffffffff */
1815 c &= -lsb; /* c == 0x00fff00000000000 */
1816 lsb = c & -c; /* lsb == 0x0000100000000000 */
1817 c = ~c; /* c == 0xff000fffffffffff */
1818 c &= -lsb; /* c == 0xff00000000000000 */
1819 shift = 0;
1820 while ((lsb >>= 1) != 0)
1821 shift++; /* shift == 44 on exit from loop */
1822 m1 = ~c; /* m1 == 0x00ffffffffffffff */
1823 m1 >>= shift; /* m1 == 0x0000000000000fff */
1824 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
1825 }
1826
1827 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
1828 masks will be all 1's. We are guaranteed more than one transition. */
1829 out[0] = GEN_INT (64 - shift);
1830 out[1] = GEN_INT (m1);
1831 out[2] = GEN_INT (shift);
1832 out[3] = GEN_INT (m2);
1833#else
045572c7
GK
1834 (void)in;
1835 (void)out;
0ba1b2ff
AM
1836 abort ();
1837#endif
a260abc9
DE
1838}
1839
1840/* Return 1 if the operand is either a non-special register or a constant
1841 that can be used as the operand of a PowerPC64 logical AND insn. */
1842
1843int
1844and64_operand (op, mode)
592696dd 1845 rtx op;
9878760c
RK
1846 enum machine_mode mode;
1847{
a4f6c312 1848 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1849 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
1850
1851 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
1852}
1853
0ba1b2ff
AM
1854/* Like the above, but also match constants that can be implemented
1855 with two rldicl or rldicr insns. */
1856
1857int
1858and64_2_operand (op, mode)
1859 rtx op;
1860 enum machine_mode mode;
1861{
1862 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
1863 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
1864
1865 return logical_operand (op, mode) || mask64_2_operand (op, mode);
1866}
1867
a260abc9
DE
1868/* Return 1 if the operand is either a non-special register or a
1869 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
1870
1871int
a260abc9 1872and_operand (op, mode)
592696dd 1873 rtx op;
a260abc9 1874 enum machine_mode mode;
dcfedcd0 1875{
a4f6c312 1876 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
1877 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
1878
1879 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
1880}
1881
9878760c
RK
1882/* Return 1 if the operand is a general register or memory operand. */
1883
1884int
1885reg_or_mem_operand (op, mode)
592696dd
SS
1886 rtx op;
1887 enum machine_mode mode;
9878760c 1888{
b6c9286a
MM
1889 return (gpc_reg_operand (op, mode)
1890 || memory_operand (op, mode)
1891 || volatile_mem_operand (op, mode));
9878760c
RK
1892}
1893
a7a813f7 1894/* Return 1 if the operand is a general register or memory operand without
3cb999d8 1895 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
1896 instruction. */
1897
1898int
1899lwa_operand (op, mode)
592696dd
SS
1900 rtx op;
1901 enum machine_mode mode;
a7a813f7
RK
1902{
1903 rtx inner = op;
1904
1905 if (reload_completed && GET_CODE (inner) == SUBREG)
1906 inner = SUBREG_REG (inner);
1907
1908 return gpc_reg_operand (inner, mode)
1909 || (memory_operand (inner, mode)
1910 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
1911 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
1912 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
1913 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
1914 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
1915}
1916
cc4d5fec
JH
1917/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
1918
1919int
1920symbol_ref_operand (op, mode)
1921 rtx op;
1922 enum machine_mode mode;
1923{
1924 if (mode != VOIDmode && GET_MODE (op) != mode)
1925 return 0;
1926
1927 return (GET_CODE (op) == SYMBOL_REF);
1928}
1929
9878760c 1930/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 1931 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
1932
1933int
1934call_operand (op, mode)
592696dd 1935 rtx op;
9878760c
RK
1936 enum machine_mode mode;
1937{
1938 if (mode != VOIDmode && GET_MODE (op) != mode)
1939 return 0;
1940
1941 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
1942 || (GET_CODE (op) == REG
1943 && (REGNO (op) == LINK_REGISTER_REGNUM
1944 || REGNO (op) == COUNT_REGISTER_REGNUM
1945 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
1946}
1947
2af3d377 1948/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
a4f6c312 1949 this file and the function is not weakly defined. */
2af3d377
RK
1950
1951int
1952current_file_function_operand (op, mode)
592696dd 1953 rtx op;
296b8152 1954 enum machine_mode mode ATTRIBUTE_UNUSED;
2af3d377
RK
1955{
1956 return (GET_CODE (op) == SYMBOL_REF
1957 && (SYMBOL_REF_FLAG (op)
8f1b829e 1958 || (op == XEXP (DECL_RTL (current_function_decl), 0)
c81fc13e 1959 && ! DECL_WEAK (current_function_decl))));
2af3d377
RK
1960}
1961
9878760c
RK
1962/* Return 1 if this operand is a valid input for a move insn. */
1963
1964int
1965input_operand (op, mode)
592696dd 1966 rtx op;
9878760c
RK
1967 enum machine_mode mode;
1968{
eb4e8003 1969 /* Memory is always valid. */
9878760c
RK
1970 if (memory_operand (op, mode))
1971 return 1;
1972
34792e82 1973 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 1974 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
1975 return 1;
1976
eb4e8003
RK
1977 /* For floating-point, easy constants are valid. */
1978 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1979 && CONSTANT_P (op)
1980 && easy_fp_constant (op, mode))
1981 return 1;
1982
4e74d8ec
MM
1983 /* Allow any integer constant. */
1984 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 1985 && (GET_CODE (op) == CONST_INT
e675f625 1986 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
1987 return 1;
1988
eb4e8003
RK
1989 /* For floating-point or multi-word mode, the only remaining valid type
1990 is a register. */
9878760c
RK
1991 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1992 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 1993 return register_operand (op, mode);
9878760c 1994
88fe15a1
RK
1995 /* The only cases left are integral modes one word or smaller (we
1996 do not get called for MODE_CC values). These can be in any
1997 register. */
1998 if (register_operand (op, mode))
a8b3aeda 1999 return 1;
88fe15a1 2000
84cf9dda 2001 /* A SYMBOL_REF referring to the TOC is valid. */
7fec4abd 2002 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (op))
84cf9dda
RK
2003 return 1;
2004
9ebbca7d
GK
2005 /* A constant pool expression (relative to the TOC) is valid */
2006 if (TOC_RELATIVE_EXPR_P (op))
b6c9286a
MM
2007 return 1;
2008
88228c4b
MM
2009 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2010 to be valid. */
f607bc57 2011 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2012 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2013 && small_data_operand (op, Pmode))
2014 return 1;
2015
042259f2 2016 return 0;
9878760c 2017}
7509c759 2018
a4f6c312 2019/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2020
2021int
2022small_data_operand (op, mode)
296b8152
KG
2023 rtx op ATTRIBUTE_UNUSED;
2024 enum machine_mode mode ATTRIBUTE_UNUSED;
7509c759 2025{
38c1f2d7 2026#if TARGET_ELF
5f59ecb7 2027 rtx sym_ref;
7509c759 2028
d9407988 2029 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2030 return 0;
a54d04b7 2031
f607bc57 2032 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2033 return 0;
2034
88228c4b
MM
2035 if (GET_CODE (op) == SYMBOL_REF)
2036 sym_ref = op;
2037
2038 else if (GET_CODE (op) != CONST
2039 || GET_CODE (XEXP (op, 0)) != PLUS
2040 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2041 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2042 return 0;
2043
88228c4b 2044 else
dbf55e53
MM
2045 {
2046 rtx sum = XEXP (op, 0);
2047 HOST_WIDE_INT summand;
2048
2049 /* We have to be careful here, because it is the referenced address
2050 that must be 32k from _SDA_BASE_, not just the symbol. */
2051 summand = INTVAL (XEXP (sum, 1));
2052 if (summand < 0 || summand > g_switch_value)
2053 return 0;
2054
2055 sym_ref = XEXP (sum, 0);
2056 }
88228c4b
MM
2057
2058 if (*XSTR (sym_ref, 0) != '@')
7509c759
MM
2059 return 0;
2060
2061 return 1;
d9407988
MM
2062
2063#else
2064 return 0;
2065#endif
7509c759 2066}
9ebbca7d
GK
2067\f
2068static int
2069constant_pool_expr_1 (op, have_sym, have_toc)
2070 rtx op;
2071 int *have_sym;
2072 int *have_toc;
2073{
2074 switch (GET_CODE(op))
2075 {
2076 case SYMBOL_REF:
a4f6c312
SS
2077 if (CONSTANT_POOL_ADDRESS_P (op))
2078 {
2079 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2080 {
2081 *have_sym = 1;
2082 return 1;
2083 }
2084 else
2085 return 0;
2086 }
2087 else if (! strcmp (XSTR (op, 0), toc_label_name))
2088 {
2089 *have_toc = 1;
2090 return 1;
2091 }
2092 else
2093 return 0;
9ebbca7d
GK
2094 case PLUS:
2095 case MINUS:
c1f11548
DE
2096 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2097 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2098 case CONST:
a4f6c312 2099 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2100 case CONST_INT:
a4f6c312 2101 return 1;
9ebbca7d 2102 default:
a4f6c312 2103 return 0;
9ebbca7d
GK
2104 }
2105}
2106
2107int
2108constant_pool_expr_p (op)
2109 rtx op;
2110{
2111 int have_sym = 0;
2112 int have_toc = 0;
2113 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2114}
2115
2116int
2117toc_relative_expr_p (op)
2118 rtx op;
2119{
2120 int have_sym = 0;
2121 int have_toc = 0;
2122 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2123}
2124
2125/* Try machine-dependent ways of modifying an illegitimate address
2126 to be legitimate. If we find one, return the new, valid address.
2127 This is used from only one place: `memory_address' in explow.c.
2128
a4f6c312
SS
2129 OLDX is the address as it was before break_out_memory_refs was
2130 called. In some cases it is useful to look at this to decide what
2131 needs to be done.
9ebbca7d 2132
a4f6c312 2133 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2134
a4f6c312
SS
2135 It is always safe for this function to do nothing. It exists to
2136 recognize opportunities to optimize the output.
9ebbca7d
GK
2137
2138 On RS/6000, first check for the sum of a register with a constant
2139 integer that is out of range. If so, generate code to add the
2140 constant with the low-order 16 bits masked to the register and force
2141 this result into another register (this can be done with `cau').
2142 Then generate an address of REG+(CONST&0xffff), allowing for the
2143 possibility of bit 16 being a one.
2144
2145 Then check for the sum of a register and something not constant, try to
2146 load the other things into a register and return the sum. */
2147rtx
2148rs6000_legitimize_address (x, oldx, mode)
2149 rtx x;
2150 rtx oldx ATTRIBUTE_UNUSED;
2151 enum machine_mode mode;
0ac081f6 2152{
9ebbca7d
GK
2153 if (GET_CODE (x) == PLUS
2154 && GET_CODE (XEXP (x, 0)) == REG
2155 && GET_CODE (XEXP (x, 1)) == CONST_INT
2156 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2157 {
2158 HOST_WIDE_INT high_int, low_int;
2159 rtx sum;
a65c591c
DE
2160 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2161 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2162 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2163 GEN_INT (high_int)), 0);
2164 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2165 }
2166 else if (GET_CODE (x) == PLUS
2167 && GET_CODE (XEXP (x, 0)) == REG
2168 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2169 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2170 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2171 || TARGET_POWERPC64
fcce224d 2172 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2173 && (TARGET_POWERPC64 || mode != DImode)
2174 && mode != TImode)
2175 {
2176 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2177 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2178 }
0ac081f6
AH
2179 else if (ALTIVEC_VECTOR_MODE (mode))
2180 {
2181 rtx reg;
2182
2183 /* Make sure both operands are registers. */
2184 if (GET_CODE (x) == PLUS)
9f85ed45 2185 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2186 force_reg (Pmode, XEXP (x, 1)));
2187
2188 reg = force_reg (Pmode, x);
2189 return reg;
2190 }
a3170dc6
AH
2191 else if (SPE_VECTOR_MODE (mode))
2192 {
2193 /* We accept [reg + reg] and [reg + OFFSET]. */
2194
2195 if (GET_CODE (x) == PLUS)
2196 {
2197 rtx op1 = XEXP (x, 0);
2198 rtx op2 = XEXP (x, 1);
2199
2200 op1 = force_reg (Pmode, op1);
2201
2202 if (GET_CODE (op2) != REG
2203 && (GET_CODE (op2) != CONST_INT
2204 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2205 op2 = force_reg (Pmode, op2);
2206
2207 return gen_rtx_PLUS (Pmode, op1, op2);
2208 }
2209
2210 return force_reg (Pmode, x);
2211 }
9ebbca7d
GK
2212 else if (TARGET_ELF && TARGET_32BIT && TARGET_NO_TOC && ! flag_pic
2213 && GET_CODE (x) != CONST_INT
2214 && GET_CODE (x) != CONST_DOUBLE
2215 && CONSTANT_P (x)
6ac7bf2c
GK
2216 && GET_MODE_NUNITS (mode) == 1
2217 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2218 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2219 {
2220 rtx reg = gen_reg_rtx (Pmode);
2221 emit_insn (gen_elf_high (reg, (x)));
2222 return gen_rtx_LO_SUM (Pmode, reg, (x));
2223 }
ee890fe2
SS
2224 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2225 && ! flag_pic
2226 && GET_CODE (x) != CONST_INT
2227 && GET_CODE (x) != CONST_DOUBLE
2228 && CONSTANT_P (x)
a3170dc6 2229 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2230 && mode != DImode
2231 && mode != TImode)
2232 {
2233 rtx reg = gen_reg_rtx (Pmode);
2234 emit_insn (gen_macho_high (reg, (x)));
2235 return gen_rtx_LO_SUM (Pmode, reg, (x));
2236 }
9ebbca7d
GK
2237 else if (TARGET_TOC
2238 && CONSTANT_POOL_EXPR_P (x)
a9098fd0 2239 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2240 {
2241 return create_TOC_reference (x);
2242 }
2243 else
2244 return NULL_RTX;
2245}
258bfae2 2246
24ea750e
DJ
2247/* The convention appears to be to define this wherever it is used.
2248 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
2249 is now used here. */
2250#ifndef REG_MODE_OK_FOR_BASE_P
2251#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
2252#endif
2253
2254/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
2255 replace the input X, or the original X if no replacement is called for.
2256 The output parameter *WIN is 1 if the calling macro should goto WIN,
2257 0 if it should not.
2258
2259 For RS/6000, we wish to handle large displacements off a base
2260 register by splitting the addend across an addiu/addis and the mem insn.
2261 This cuts number of extra insns needed from 3 to 1.
2262
2263 On Darwin, we use this to generate code for floating point constants.
2264 A movsf_low is generated so we wind up with 2 instructions rather than 3.
2265 The Darwin code is inside #if TARGET_MACHO because only then is
2266 machopic_function_base_name() defined. */
2267rtx
2268rs6000_legitimize_reload_address (x, mode, opnum, type, ind_levels, win)
2269 rtx x;
2270 enum machine_mode mode;
2271 int opnum;
2272 int type;
2273 int ind_levels ATTRIBUTE_UNUSED;
2274 int *win;
2275{
2276 /* We must recognize output that we have already generated ourselves. */
2277 if (GET_CODE (x) == PLUS
2278 && GET_CODE (XEXP (x, 0)) == PLUS
2279 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
2280 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
2281 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2282 {
2283 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2284 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2285 opnum, (enum reload_type)type);
2286 *win = 1;
2287 return x;
2288 }
3deb2758 2289
24ea750e
DJ
2290#if TARGET_MACHO
2291 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
2292 && GET_CODE (x) == LO_SUM
2293 && GET_CODE (XEXP (x, 0)) == PLUS
2294 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
2295 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
2296 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
2297 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
2298 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
2299 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
2300 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
2301 {
2302 /* Result of previous invocation of this function on Darwin
6f317ef3 2303 floating point constant. */
24ea750e
DJ
2304 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2305 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2306 opnum, (enum reload_type)type);
2307 *win = 1;
2308 return x;
2309 }
2310#endif
2311 if (GET_CODE (x) == PLUS
2312 && GET_CODE (XEXP (x, 0)) == REG
2313 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
2314 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 2315 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 2316 && !SPE_VECTOR_MODE (mode)
78c875e8 2317 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
2318 {
2319 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
2320 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
2321 HOST_WIDE_INT high
2322 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
2323
2324 /* Check for 32-bit overflow. */
2325 if (high + low != val)
2326 {
2327 *win = 0;
2328 return x;
2329 }
2330
2331 /* Reload the high part into a base reg; leave the low part
2332 in the mem directly. */
2333
2334 x = gen_rtx_PLUS (GET_MODE (x),
2335 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
2336 GEN_INT (high)),
2337 GEN_INT (low));
2338
2339 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2340 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
2341 opnum, (enum reload_type)type);
2342 *win = 1;
2343 return x;
2344 }
2345#if TARGET_MACHO
2346 if (GET_CODE (x) == SYMBOL_REF
2347 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 2348 && !ALTIVEC_VECTOR_MODE (mode)
24ea750e
DJ
2349 && flag_pic)
2350 {
2351 /* Darwin load of floating point constant. */
2352 rtx offset = gen_rtx (CONST, Pmode,
2353 gen_rtx (MINUS, Pmode, x,
2354 gen_rtx (SYMBOL_REF, Pmode,
2355 machopic_function_base_name ())));
2356 x = gen_rtx (LO_SUM, GET_MODE (x),
2357 gen_rtx (PLUS, Pmode, pic_offset_table_rtx,
2358 gen_rtx (HIGH, Pmode, offset)), offset);
2359 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
2360 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
2361 opnum, (enum reload_type)type);
2362 *win = 1;
2363 return x;
2364 }
2365#endif
2366 if (TARGET_TOC
c1f11548
DE
2367 && CONSTANT_POOL_EXPR_P (x)
2368 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
2369 {
2370 (x) = create_TOC_reference (x);
2371 *win = 1;
2372 return x;
2373 }
2374 *win = 0;
2375 return x;
2376}
2377
258bfae2
FS
2378/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
2379 that is a valid memory address for an instruction.
2380 The MODE argument is the machine mode for the MEM expression
2381 that wants to use this address.
2382
2383 On the RS/6000, there are four valid address: a SYMBOL_REF that
2384 refers to a constant pool entry of an address (or the sum of it
2385 plus a constant), a short (16-bit signed) constant plus a register,
2386 the sum of two registers, or a register indirect, possibly with an
5bdc5878 2387 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
2388 we must ensure that both words are addressable or PowerPC64 with offset
2389 word aligned.
2390
2391 For modes spanning multiple registers (DFmode in 32-bit GPRs,
2392 32-bit DImode, TImode), indexed addressing cannot be used because
2393 adjacent memory cells are accessed by adding word-sized offsets
2394 during assembly output. */
2395int
2396rs6000_legitimate_address (mode, x, reg_ok_strict)
2397 enum machine_mode mode;
2398 rtx x;
2399 int reg_ok_strict;
2400{
2401 if (LEGITIMATE_INDIRECT_ADDRESS_P (x, reg_ok_strict))
2402 return 1;
2403 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 2404 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 2405 && !SPE_VECTOR_MODE (mode)
258bfae2
FS
2406 && TARGET_UPDATE
2407 && LEGITIMATE_INDIRECT_ADDRESS_P (XEXP (x, 0), reg_ok_strict))
2408 return 1;
2409 if (LEGITIMATE_SMALL_DATA_P (mode, x))
2410 return 1;
2411 if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
2412 return 1;
2413 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
2414 if (! reg_ok_strict
2415 && GET_CODE (x) == PLUS
2416 && GET_CODE (XEXP (x, 0)) == REG
2417 && XEXP (x, 0) == virtual_stack_vars_rtx
2418 && GET_CODE (XEXP (x, 1)) == CONST_INT)
2419 return 1;
2420 if (LEGITIMATE_OFFSET_ADDRESS_P (mode, x, reg_ok_strict))
2421 return 1;
2422 if (mode != TImode
a3170dc6
AH
2423 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2424 || TARGET_POWERPC64
fcce224d 2425 || (mode != DFmode && mode != TFmode))
258bfae2
FS
2426 && (TARGET_POWERPC64 || mode != DImode)
2427 && LEGITIMATE_INDEXED_ADDRESS_P (x, reg_ok_strict))
2428 return 1;
2429 if (LEGITIMATE_LO_SUM_ADDRESS_P (mode, x, reg_ok_strict))
2430 return 1;
2431 return 0;
2432}
fb4d4348 2433\f
a4f6c312
SS
2434/* Try to output insns to set TARGET equal to the constant C if it can
2435 be done in less than N insns. Do all computations in MODE.
2436 Returns the place where the output has been placed if it can be
2437 done and the insns have been emitted. If it would take more than N
2438 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
2439
2440rtx
2441rs6000_emit_set_const (dest, mode, source, n)
2442 rtx dest, source;
2443 enum machine_mode mode;
2444 int n ATTRIBUTE_UNUSED;
2445{
af8cb5c5 2446 rtx result, insn, set;
2bfcf297
DB
2447 HOST_WIDE_INT c0, c1;
2448
af8cb5c5 2449 if (mode == QImode || mode == HImode)
2bfcf297
DB
2450 {
2451 if (dest == NULL)
2452 dest = gen_reg_rtx (mode);
2453 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
2454 return dest;
2455 }
af8cb5c5 2456 else if (mode == SImode)
2bfcf297 2457 {
af8cb5c5
DE
2458 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
2459
2460 emit_insn (gen_rtx_SET (VOIDmode, result,
2461 GEN_INT (INTVAL (source)
2462 & (~ (HOST_WIDE_INT) 0xffff))));
2463 emit_insn (gen_rtx_SET (VOIDmode, dest,
2464 gen_rtx_IOR (SImode, result,
2465 GEN_INT (INTVAL (source) & 0xffff))));
2466 result = dest;
2bfcf297 2467 }
af8cb5c5 2468 else if (mode == DImode)
2bfcf297 2469 {
af8cb5c5
DE
2470 if (GET_CODE (source) == CONST_INT)
2471 {
2472 c0 = INTVAL (source);
2473 c1 = -(c0 < 0);
2474 }
2475 else if (GET_CODE (source) == CONST_DOUBLE)
2476 {
2bfcf297 2477#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
2478 c0 = CONST_DOUBLE_LOW (source);
2479 c1 = -(c0 < 0);
2bfcf297 2480#else
af8cb5c5
DE
2481 c0 = CONST_DOUBLE_LOW (source);
2482 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 2483#endif
af8cb5c5
DE
2484 }
2485 else
2486 abort ();
2487
2488 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
2489 }
2490 else
a4f6c312 2491 abort ();
2bfcf297 2492
af8cb5c5
DE
2493 insn = get_last_insn ();
2494 set = single_set (insn);
2495 if (! CONSTANT_P (SET_SRC (set)))
2496 set_unique_reg_note (insn, REG_EQUAL, source);
2497
2498 return result;
2bfcf297
DB
2499}
2500
2501/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
2502 fall back to a straight forward decomposition. We do this to avoid
2503 exponential run times encountered when looking for longer sequences
2504 with rs6000_emit_set_const. */
2505static rtx
2506rs6000_emit_set_long_const (dest, c1, c2)
2507 rtx dest;
2508 HOST_WIDE_INT c1, c2;
2509{
2510 if (!TARGET_POWERPC64)
2511 {
2512 rtx operand1, operand2;
2513
2514 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
2515 DImode);
2516 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
2517 DImode);
2518 emit_move_insn (operand1, GEN_INT (c1));
2519 emit_move_insn (operand2, GEN_INT (c2));
2520 }
2521 else
2522 {
bc06712d 2523 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 2524
bc06712d
TR
2525 ud1 = c1 & 0xffff;
2526 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 2527#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 2528 c2 = c1 >> 32;
2bfcf297 2529#endif
bc06712d
TR
2530 ud3 = c2 & 0xffff;
2531 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 2532
bc06712d
TR
2533 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
2534 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 2535 {
bc06712d
TR
2536 if (ud1 & 0x8000)
2537 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
2538 else
2539 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 2540 }
2bfcf297 2541
bc06712d
TR
2542 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
2543 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 2544 {
bc06712d
TR
2545 if (ud2 & 0x8000)
2546 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
2547 - 0x80000000));
252b88f7 2548 else
bc06712d
TR
2549 emit_move_insn (dest, GEN_INT (ud2 << 16));
2550 if (ud1 != 0)
2551 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 2552 }
bc06712d
TR
2553 else if ((ud4 == 0xffff && (ud3 & 0x8000))
2554 || (ud4 == 0 && ! (ud3 & 0x8000)))
2555 {
2556 if (ud3 & 0x8000)
2557 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
2558 - 0x80000000));
2559 else
2560 emit_move_insn (dest, GEN_INT (ud3 << 16));
2561
2562 if (ud2 != 0)
2563 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
2564 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
2565 if (ud1 != 0)
2566 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
2567 }
2568 else
2569 {
2570 if (ud4 & 0x8000)
2571 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
2572 - 0x80000000));
2573 else
2574 emit_move_insn (dest, GEN_INT (ud4 << 16));
2575
2576 if (ud3 != 0)
2577 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 2578
bc06712d
TR
2579 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
2580 if (ud2 != 0)
2581 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
2582 GEN_INT (ud2 << 16)));
2583 if (ud1 != 0)
2584 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
2585 }
2586 }
2bfcf297
DB
2587 return dest;
2588}
2589
fb4d4348
GK
2590/* Emit a move from SOURCE to DEST in mode MODE. */
2591void
2592rs6000_emit_move (dest, source, mode)
2593 rtx dest;
2594 rtx source;
2595 enum machine_mode mode;
2596{
2597 rtx operands[2];
2598 operands[0] = dest;
2599 operands[1] = source;
2600
2601 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
2602 if (GET_CODE (operands[1]) == CONST_DOUBLE
2603 && ! FLOAT_MODE_P (mode)
2604 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
2605 {
2606 /* FIXME. This should never happen. */
2607 /* Since it seems that it does, do the safe thing and convert
2608 to a CONST_INT. */
2496c7bd 2609 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
2610 }
2611 if (GET_CODE (operands[1]) == CONST_DOUBLE
2612 && ! FLOAT_MODE_P (mode)
2613 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
2614 && CONST_DOUBLE_LOW (operands[1]) >= 0)
2615 || (CONST_DOUBLE_HIGH (operands[1]) == -1
2616 && CONST_DOUBLE_LOW (operands[1]) < 0)))
2617 abort ();
c9e8cb32
DD
2618
2619 /* Check if GCC is setting up a block move that will end up using FP
2620 registers as temporaries. We must make sure this is acceptable. */
2621 if (GET_CODE (operands[0]) == MEM
2622 && GET_CODE (operands[1]) == MEM
2623 && mode == DImode
41543739
GK
2624 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
2625 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
2626 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
2627 ? 32 : MEM_ALIGN (operands[0])))
2628 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
2629 ? 32
2630 : MEM_ALIGN (operands[1]))))
2631 && ! MEM_VOLATILE_P (operands [0])
2632 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 2633 {
41543739
GK
2634 emit_move_insn (adjust_address (operands[0], SImode, 0),
2635 adjust_address (operands[1], SImode, 0));
2636 emit_move_insn (adjust_address (operands[0], SImode, 4),
2637 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
2638 return;
2639 }
fb4d4348 2640
67cef334
DE
2641 if (!no_new_pseudos)
2642 {
2643 if (GET_CODE (operands[1]) == MEM && optimize > 0
2644 && (mode == QImode || mode == HImode || mode == SImode)
2645 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
2646 {
2647 rtx reg = gen_reg_rtx (word_mode);
2648
2649 emit_insn (gen_rtx_SET (word_mode, reg,
2650 gen_rtx_ZERO_EXTEND (word_mode,
2651 operands[1])));
2652 operands[1] = gen_lowpart (mode, reg);
2653 }
2654 if (GET_CODE (operands[0]) != REG)
2655 operands[1] = force_reg (mode, operands[1]);
2656 }
a9098fd0 2657
a3170dc6
AH
2658 if (mode == SFmode && ! TARGET_POWERPC
2659 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 2660 && GET_CODE (operands[0]) == MEM)
fb4d4348 2661 {
ffc14f31
GK
2662 int regnum;
2663
2664 if (reload_in_progress || reload_completed)
2665 regnum = true_regnum (operands[1]);
2666 else if (GET_CODE (operands[1]) == REG)
2667 regnum = REGNO (operands[1]);
2668 else
2669 regnum = -1;
fb4d4348
GK
2670
2671 /* If operands[1] is a register, on POWER it may have
2672 double-precision data in it, so truncate it to single
2673 precision. */
2674 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
2675 {
2676 rtx newreg;
2677 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
2678 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
2679 operands[1] = newreg;
2680 }
2681 }
2682
a9098fd0
GK
2683 /* Handle the case where reload calls us with an invalid address;
2684 and the case of CONSTANT_P_RTX. */
16861f33 2685 if (!ALTIVEC_VECTOR_MODE (mode)
69ef87e2
AH
2686 && (! general_operand (operands[1], mode)
2687 || ! nonimmediate_operand (operands[0], mode)
2688 || GET_CODE (operands[1]) == CONSTANT_P_RTX))
fb4d4348
GK
2689 {
2690 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2691 return;
2692 }
a9098fd0 2693
fb4d4348
GK
2694 /* FIXME: In the long term, this switch statement should go away
2695 and be replaced by a sequence of tests based on things like
2696 mode == Pmode. */
2697 switch (mode)
2698 {
2699 case HImode:
2700 case QImode:
2701 if (CONSTANT_P (operands[1])
2702 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 2703 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2704 break;
2705
06f4e019 2706 case TFmode:
fb4d4348
GK
2707 case DFmode:
2708 case SFmode:
2709 if (CONSTANT_P (operands[1])
2710 && ! easy_fp_constant (operands[1], mode))
a9098fd0 2711 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2712 break;
2713
0ac081f6
AH
2714 case V16QImode:
2715 case V8HImode:
2716 case V4SFmode:
2717 case V4SImode:
a3170dc6
AH
2718 case V4HImode:
2719 case V2SFmode:
2720 case V2SImode:
00a892b8 2721 case V1DImode:
69ef87e2
AH
2722 if (CONSTANT_P (operands[1])
2723 && !easy_vector_constant (operands[1]))
0ac081f6
AH
2724 operands[1] = force_const_mem (mode, operands[1]);
2725 break;
2726
fb4d4348 2727 case SImode:
a9098fd0 2728 case DImode:
fb4d4348
GK
2729 /* Use default pattern for address of ELF small data */
2730 if (TARGET_ELF
a9098fd0 2731 && mode == Pmode
f607bc57 2732 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
2733 && (GET_CODE (operands[1]) == SYMBOL_REF
2734 || GET_CODE (operands[1]) == CONST)
2735 && small_data_operand (operands[1], mode))
fb4d4348
GK
2736 {
2737 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
2738 return;
2739 }
2740
f607bc57 2741 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
2742 && mode == Pmode && mode == SImode
2743 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
2744 {
2745 emit_insn (gen_movsi_got (operands[0], operands[1]));
2746 return;
2747 }
2748
ee890fe2
SS
2749 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
2750 && TARGET_NO_TOC && ! flag_pic
a9098fd0 2751 && mode == Pmode
fb4d4348
GK
2752 && CONSTANT_P (operands[1])
2753 && GET_CODE (operands[1]) != HIGH
2754 && GET_CODE (operands[1]) != CONST_INT)
2755 {
a9098fd0 2756 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
2757
2758 /* If this is a function address on -mcall-aixdesc,
2759 convert it to the address of the descriptor. */
2760 if (DEFAULT_ABI == ABI_AIX
2761 && GET_CODE (operands[1]) == SYMBOL_REF
2762 && XSTR (operands[1], 0)[0] == '.')
2763 {
2764 const char *name = XSTR (operands[1], 0);
2765 rtx new_ref;
2766 while (*name == '.')
2767 name++;
2768 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
2769 CONSTANT_POOL_ADDRESS_P (new_ref)
2770 = CONSTANT_POOL_ADDRESS_P (operands[1]);
2771 SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
2772 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
2773 operands[1] = new_ref;
2774 }
7509c759 2775
ee890fe2
SS
2776 if (DEFAULT_ABI == ABI_DARWIN)
2777 {
2778 emit_insn (gen_macho_high (target, operands[1]));
2779 emit_insn (gen_macho_low (operands[0], target, operands[1]));
2780 return;
2781 }
2782
fb4d4348
GK
2783 emit_insn (gen_elf_high (target, operands[1]));
2784 emit_insn (gen_elf_low (operands[0], target, operands[1]));
2785 return;
2786 }
2787
a9098fd0
GK
2788 /* If this is a SYMBOL_REF that refers to a constant pool entry,
2789 and we have put it in the TOC, we just need to make a TOC-relative
2790 reference to it. */
2791 if (TARGET_TOC
2792 && GET_CODE (operands[1]) == SYMBOL_REF
2793 && CONSTANT_POOL_EXPR_P (operands[1])
2794 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
2795 get_pool_mode (operands[1])))
fb4d4348 2796 {
a9098fd0 2797 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 2798 }
a9098fd0
GK
2799 else if (mode == Pmode
2800 && CONSTANT_P (operands[1])
38886f37
AO
2801 && ((GET_CODE (operands[1]) != CONST_INT
2802 && ! easy_fp_constant (operands[1], mode))
2803 || (GET_CODE (operands[1]) == CONST_INT
2804 && num_insns_constant (operands[1], mode) > 2)
2805 || (GET_CODE (operands[0]) == REG
2806 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0
GK
2807 && GET_CODE (operands[1]) != HIGH
2808 && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1])
2809 && ! TOC_RELATIVE_EXPR_P (operands[1]))
fb4d4348
GK
2810 {
2811 /* Emit a USE operation so that the constant isn't deleted if
2812 expensive optimizations are turned on because nobody
2813 references it. This should only be done for operands that
2814 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
2815 This should not be done for operands that contain LABEL_REFs.
2816 For now, we just handle the obvious case. */
2817 if (GET_CODE (operands[1]) != LABEL_REF)
2818 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
2819
c859cda6 2820#if TARGET_MACHO
ee890fe2
SS
2821 /* Darwin uses a special PIC legitimizer. */
2822 if (DEFAULT_ABI == ABI_DARWIN && flag_pic)
2823 {
ee890fe2
SS
2824 operands[1] =
2825 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
2826 operands[0]);
2827 if (operands[0] != operands[1])
2828 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
2829 return;
2830 }
c859cda6 2831#endif
ee890fe2 2832
fb4d4348
GK
2833 /* If we are to limit the number of things we put in the TOC and
2834 this is a symbol plus a constant we can add in one insn,
2835 just put the symbol in the TOC and add the constant. Don't do
2836 this if reload is in progress. */
2837 if (GET_CODE (operands[1]) == CONST
2838 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
2839 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 2840 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
2841 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
2842 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
2843 && ! side_effects_p (operands[0]))
2844 {
a4f6c312
SS
2845 rtx sym =
2846 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
2847 rtx other = XEXP (XEXP (operands[1], 0), 1);
2848
a9098fd0
GK
2849 sym = force_reg (mode, sym);
2850 if (mode == SImode)
2851 emit_insn (gen_addsi3 (operands[0], sym, other));
2852 else
2853 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
2854 return;
2855 }
2856
a9098fd0 2857 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
2858
2859 if (TARGET_TOC
d34c5b80
DE
2860 && CONSTANT_POOL_EXPR_P (XEXP (operands[1], 0))
2861 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
2862 get_pool_constant (XEXP (operands[1], 0)),
2863 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 2864 {
ba4828e0
RK
2865 operands[1]
2866 = gen_rtx_MEM (mode,
2867 create_TOC_reference (XEXP (operands[1], 0)));
2868 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 2869 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 2870 }
fb4d4348
GK
2871 }
2872 break;
a9098fd0 2873
fb4d4348
GK
2874 case TImode:
2875 if (GET_CODE (operands[0]) == MEM
2876 && GET_CODE (XEXP (operands[0], 0)) != REG
2877 && ! reload_in_progress)
792760b9
RK
2878 operands[0]
2879 = replace_equiv_address (operands[0],
2880 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
2881
2882 if (GET_CODE (operands[1]) == MEM
2883 && GET_CODE (XEXP (operands[1], 0)) != REG
2884 && ! reload_in_progress)
792760b9
RK
2885 operands[1]
2886 = replace_equiv_address (operands[1],
2887 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
2888 if (TARGET_POWER)
2889 {
2890 emit_insn (gen_rtx_PARALLEL (VOIDmode,
2891 gen_rtvec (2,
2892 gen_rtx_SET (VOIDmode,
2893 operands[0], operands[1]),
2894 gen_rtx_CLOBBER (VOIDmode,
2895 gen_rtx_SCRATCH (SImode)))));
2896 return;
2897 }
fb4d4348
GK
2898 break;
2899
2900 default:
2901 abort ();
2902 }
2903
a9098fd0
GK
2904 /* Above, we may have called force_const_mem which may have returned
2905 an invalid address. If we can, fix this up; otherwise, reload will
2906 have to deal with it. */
2907 if (GET_CODE (operands[1]) == MEM
2908 && ! memory_address_p (mode, XEXP (operands[1], 0))
2909 && ! reload_in_progress)
f4ef873c 2910 operands[1] = adjust_address (operands[1], mode, 0);
a9098fd0 2911
fb4d4348 2912 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
02a4ec28 2913 return;
fb4d4348 2914}
4697a36c
MM
2915\f
2916/* Initialize a variable CUM of type CUMULATIVE_ARGS
2917 for a call to a function whose data type is FNTYPE.
2918 For a library call, FNTYPE is 0.
2919
2920 For incoming args we set the number of arguments in the prototype large
1c20ae99 2921 so we never return a PARALLEL. */
4697a36c
MM
2922
2923void
2924init_cumulative_args (cum, fntype, libname, incoming)
2925 CUMULATIVE_ARGS *cum;
2926 tree fntype;
296b8152 2927 rtx libname ATTRIBUTE_UNUSED;
4697a36c
MM
2928 int incoming;
2929{
2930 static CUMULATIVE_ARGS zero_cumulative;
2931
2932 *cum = zero_cumulative;
2933 cum->words = 0;
2934 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 2935 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 2936 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
7509c759 2937 cum->call_cookie = CALL_NORMAL;
4cc833b7 2938 cum->sysv_gregno = GP_ARG_MIN_REG;
4697a36c
MM
2939
2940 if (incoming)
bd227acc 2941 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
2942
2943 else if (cum->prototype)
2944 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
2945 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
2946 || RETURN_IN_MEMORY (TREE_TYPE (fntype))));
2947
2948 else
2949 cum->nargs_prototype = 0;
2950
2951 cum->orig_nargs = cum->nargs_prototype;
7509c759 2952
a5c76ee6
ZW
2953 /* Check for a longcall attribute. */
2954 if (fntype
2955 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
2956 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
2957 cum->call_cookie = CALL_LONG;
2958
4697a36c
MM
2959 if (TARGET_DEBUG_ARG)
2960 {
2961 fprintf (stderr, "\ninit_cumulative_args:");
2962 if (fntype)
2963 {
2964 tree ret_type = TREE_TYPE (fntype);
2965 fprintf (stderr, " ret code = %s,",
2966 tree_code_name[ (int)TREE_CODE (ret_type) ]);
2967 }
2968
6a4cee5f
MM
2969 if (cum->call_cookie & CALL_LONG)
2970 fprintf (stderr, " longcall,");
2971
4697a36c
MM
2972 fprintf (stderr, " proto = %d, nargs = %d\n",
2973 cum->prototype, cum->nargs_prototype);
2974 }
2975}
2976\f
c229cba9
DE
2977/* If defined, a C expression which determines whether, and in which
2978 direction, to pad out an argument with extra space. The value
2979 should be of type `enum direction': either `upward' to pad above
2980 the argument, `downward' to pad below, or `none' to inhibit
2981 padding.
2982
2983 For the AIX ABI structs are always stored left shifted in their
2984 argument slot. */
2985
9ebbca7d 2986enum direction
c229cba9
DE
2987function_arg_padding (mode, type)
2988 enum machine_mode mode;
2989 tree type;
2990{
c85f7c16 2991 if (type != 0 && AGGREGATE_TYPE_P (type))
9ebbca7d 2992 return upward;
c229cba9
DE
2993
2994 /* This is the default definition. */
2995 return (! BYTES_BIG_ENDIAN
9ebbca7d 2996 ? upward
c229cba9
DE
2997 : ((mode == BLKmode
2998 ? (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
2999 && int_size_in_bytes (type) < (PARM_BOUNDARY / BITS_PER_UNIT))
3000 : GET_MODE_BITSIZE (mode) < PARM_BOUNDARY)
9ebbca7d 3001 ? downward : upward));
c229cba9
DE
3002}
3003
b6c9286a
MM
3004/* If defined, a C expression that gives the alignment boundary, in bits,
3005 of an argument with the specified mode and type. If it is not defined,
3006 PARM_BOUNDARY is used for all arguments.
3007
2310f99a 3008 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3009
3010int
3011function_arg_boundary (mode, type)
3012 enum machine_mode mode;
9ebbca7d 3013 tree type ATTRIBUTE_UNUSED;
b6c9286a 3014{
f607bc57 3015 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3016 return 64;
a3170dc6
AH
3017 else if (SPE_VECTOR_MODE (mode))
3018 return 64;
0ac081f6
AH
3019 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3020 return 128;
9ebbca7d 3021 else
b6c9286a 3022 return PARM_BOUNDARY;
b6c9286a
MM
3023}
3024\f
4697a36c
MM
3025/* Update the data in CUM to advance over an argument
3026 of mode MODE and data type TYPE.
3027 (TYPE is null for libcalls where that information may not be available.) */
3028
3029void
3030function_arg_advance (cum, mode, type, named)
3031 CUMULATIVE_ARGS *cum;
3032 enum machine_mode mode;
3033 tree type;
3034 int named;
3035{
3036 cum->nargs_prototype--;
3037
0ac081f6
AH
3038 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3039 {
3040 if (cum->vregno <= ALTIVEC_ARG_MAX_REG && cum->nargs_prototype >= 0)
3041 cum->vregno++;
3042 else
3043 cum->words += RS6000_ARG_SIZE (mode, type);
3044 }
a4b0320c
AH
3045 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
3046 && named && cum->sysv_gregno <= GP_ARG_MAX_REG)
3047 cum->sysv_gregno++;
f607bc57 3048 else if (DEFAULT_ABI == ABI_V4)
4697a36c 3049 {
a3170dc6 3050 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 3051 && (mode == SFmode || mode == DFmode))
4697a36c 3052 {
4cc833b7
RH
3053 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3054 cum->fregno++;
3055 else
3056 {
3057 if (mode == DFmode)
3058 cum->words += cum->words & 1;
d34c5b80 3059 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 3060 }
4697a36c 3061 }
4cc833b7
RH
3062 else
3063 {
3064 int n_words;
3065 int gregno = cum->sysv_gregno;
3066
3067 /* Aggregates and IEEE quad get passed by reference. */
3068 if ((type && AGGREGATE_TYPE_P (type))
3069 || mode == TFmode)
3070 n_words = 1;
3071 else
d34c5b80 3072 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3073
a4b0320c 3074 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3075 if (n_words == 2 && (gregno & 1) == 0)
3076 gregno += 1;
3077
a4b0320c
AH
3078 /* Long long and SPE vectors are not split between registers
3079 and stack. */
4cc833b7
RH
3080 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
3081 {
3082 /* Long long is aligned on the stack. */
3083 if (n_words == 2)
3084 cum->words += cum->words & 1;
3085 cum->words += n_words;
3086 }
4697a36c 3087
4cc833b7
RH
3088 /* Note: continuing to accumulate gregno past when we've started
3089 spilling to the stack indicates the fact that we've started
3090 spilling to the stack to expand_builtin_saveregs. */
3091 cum->sysv_gregno = gregno + n_words;
3092 }
4697a36c 3093
4cc833b7
RH
3094 if (TARGET_DEBUG_ARG)
3095 {
3096 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3097 cum->words, cum->fregno);
3098 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
3099 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
3100 fprintf (stderr, "mode = %4s, named = %d\n",
3101 GET_MODE_NAME (mode), named);
3102 }
4697a36c
MM
3103 }
3104 else
4cc833b7
RH
3105 {
3106 int align = (TARGET_32BIT && (cum->words & 1) != 0
3107 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 3108
d34c5b80 3109 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 3110
a3170dc6
AH
3111 if (GET_MODE_CLASS (mode) == MODE_FLOAT
3112 && TARGET_HARD_FLOAT && TARGET_FPRS)
fcce224d 3113 cum->fregno += (mode == TFmode ? 2 : 1);
4cc833b7
RH
3114
3115 if (TARGET_DEBUG_ARG)
3116 {
3117 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
3118 cum->words, cum->fregno);
3119 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
3120 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
3121 fprintf (stderr, "named = %d, align = %d\n", named, align);
3122 }
3123 }
4697a36c
MM
3124}
3125\f
3126/* Determine where to put an argument to a function.
3127 Value is zero to push the argument on the stack,
3128 or a hard register in which to store the argument.
3129
3130 MODE is the argument's machine mode.
3131 TYPE is the data type of the argument (as a tree).
3132 This is null for libcalls where that information may
3133 not be available.
3134 CUM is a variable of type CUMULATIVE_ARGS which gives info about
3135 the preceding args and about the function being called.
3136 NAMED is nonzero if this argument is a named parameter
3137 (otherwise it is an extra parameter matching an ellipsis).
3138
3139 On RS/6000 the first eight words of non-FP are normally in registers
3140 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
3141 Under V.4, the first 8 FP args are in registers.
3142
3143 If this is floating-point and no prototype is specified, we use
3144 both an FP and integer register (or possibly FP reg and stack). Library
3145 functions (when TYPE is zero) always have the proper types for args,
3146 so we can pass the FP value just in one register. emit_library_function
1c20ae99 3147 doesn't support PARALLEL anyway. */
4697a36c
MM
3148
3149struct rtx_def *
3150function_arg (cum, mode, type, named)
3151 CUMULATIVE_ARGS *cum;
3152 enum machine_mode mode;
3153 tree type;
20c29ebe 3154 int named;
4697a36c 3155{
4cc833b7 3156 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 3157
a4f6c312
SS
3158 /* Return a marker to indicate whether CR1 needs to set or clear the
3159 bit that V.4 uses to say fp args were passed in registers.
3160 Assume that we don't need the marker for software floating point,
3161 or compiler generated library calls. */
4697a36c
MM
3162 if (mode == VOIDmode)
3163 {
f607bc57 3164 if (abi == ABI_V4
7509c759 3165 && cum->nargs_prototype < 0
4697a36c 3166 && type && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 3167 {
a3170dc6
AH
3168 /* For the SPE, we need to crxor CR6 always. */
3169 if (TARGET_SPE_ABI)
3170 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
3171 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
3172 return GEN_INT (cum->call_cookie
3173 | ((cum->fregno == FP_ARG_MIN_REG)
3174 ? CALL_V4_SET_FP_ARGS
3175 : CALL_V4_CLEAR_FP_ARGS));
7509c759 3176 }
4697a36c 3177
7509c759 3178 return GEN_INT (cum->call_cookie);
4697a36c
MM
3179 }
3180
0ac081f6
AH
3181 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3182 {
20c29ebe 3183 if (named && cum->vregno <= ALTIVEC_ARG_MAX_REG)
0ac081f6
AH
3184 return gen_rtx_REG (mode, cum->vregno);
3185 else
3186 return NULL;
3187 }
a4b0320c 3188 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode) && named)
a3170dc6 3189 {
a4b0320c 3190 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
a3170dc6
AH
3191 return gen_rtx_REG (mode, cum->sysv_gregno);
3192 else
3193 return NULL;
3194 }
f607bc57 3195 else if (abi == ABI_V4)
4697a36c 3196 {
a3170dc6 3197 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
3198 && (mode == SFmode || mode == DFmode))
3199 {
3200 if (cum->fregno <= FP_ARG_V4_MAX_REG)
3201 return gen_rtx_REG (mode, cum->fregno);
3202 else
3203 return NULL;
3204 }
3205 else
3206 {
3207 int n_words;
3208 int gregno = cum->sysv_gregno;
3209
3210 /* Aggregates and IEEE quad get passed by reference. */
3211 if ((type && AGGREGATE_TYPE_P (type))
3212 || mode == TFmode)
3213 n_words = 1;
3214 else
d34c5b80 3215 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 3216
a4b0320c 3217 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
3218 if (n_words == 2 && (gregno & 1) == 0)
3219 gregno += 1;
3220
a4b0320c
AH
3221 /* Long long and SPE vectors are not split between registers
3222 and stack. */
4cc833b7 3223 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a4b0320c
AH
3224 {
3225 /* SPE vectors in ... get split into 2 registers. */
3226 if (TARGET_SPE && TARGET_SPE_ABI
3227 && SPE_VECTOR_MODE (mode) && !named)
3228 {
3229 rtx r1, r2;
57de2c8f 3230 enum machine_mode m = SImode;
f9dd72da 3231
a4b0320c
AH
3232 r1 = gen_rtx_REG (m, gregno);
3233 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
3234 r2 = gen_rtx_REG (m, gregno + 1);
3235 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
3236 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
3237 }
3238 return gen_rtx_REG (mode, gregno);
3239 }
4cc833b7
RH
3240 else
3241 return NULL;
3242 }
4697a36c 3243 }
4cc833b7
RH
3244 else
3245 {
3246 int align = (TARGET_32BIT && (cum->words & 1) != 0
3247 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
3248 int align_words = cum->words + align;
4697a36c 3249
4cc833b7
RH
3250 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
3251 return NULL_RTX;
3252
3253 if (USE_FP_FOR_ARG_P (*cum, mode, type))
3254 {
3255 if (! type
3256 || ((cum->nargs_prototype > 0)
3257 /* IBM AIX extended its linkage convention definition always
3258 to require FP args after register save area hole on the
3259 stack. */
3260 && (DEFAULT_ABI != ABI_AIX
3261 || ! TARGET_XL_CALL
3262 || (align_words < GP_ARG_NUM_REG))))
3263 return gen_rtx_REG (mode, cum->fregno);
3264
3265 return gen_rtx_PARALLEL (mode,
3266 gen_rtvec (2,
39403d82 3267 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
3268 ((align_words >= GP_ARG_NUM_REG)
3269 ? NULL_RTX
3270 : (align_words
d34c5b80 3271 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
3272 > GP_ARG_NUM_REG
3273 /* If this is partially on the stack, then
3274 we only include the portion actually
3275 in registers here. */
39403d82 3276 ? gen_rtx_REG (SImode,
1c20ae99 3277 GP_ARG_MIN_REG + align_words)
39403d82 3278 : gen_rtx_REG (mode,
1c20ae99
JW
3279 GP_ARG_MIN_REG + align_words))),
3280 const0_rtx),
39403d82
DE
3281 gen_rtx_EXPR_LIST (VOIDmode,
3282 gen_rtx_REG (mode, cum->fregno),
1c20ae99 3283 const0_rtx)));
4cc833b7
RH
3284 }
3285 else if (align_words < GP_ARG_NUM_REG)
3286 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
3287 else
3288 return NULL_RTX;
4697a36c 3289 }
4697a36c
MM
3290}
3291\f
3292/* For an arg passed partly in registers and partly in memory,
3293 this is the number of registers used.
3294 For args passed entirely in registers or entirely in memory, zero. */
3295
3296int
3297function_arg_partial_nregs (cum, mode, type, named)
3298 CUMULATIVE_ARGS *cum;
3299 enum machine_mode mode;
3300 tree type;
d34c5b80 3301 int named ATTRIBUTE_UNUSED;
4697a36c 3302{
f607bc57 3303 if (DEFAULT_ABI == ABI_V4)
4697a36c 3304 return 0;
4697a36c 3305
0ac081f6
AH
3306 if (USE_FP_FOR_ARG_P (*cum, mode, type)
3307 || USE_ALTIVEC_FOR_ARG_P (*cum, mode, type))
4697a36c
MM
3308 {
3309 if (cum->nargs_prototype >= 0)
3310 return 0;
3311 }
3312
3313 if (cum->words < GP_ARG_NUM_REG
d34c5b80 3314 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
3315 {
3316 int ret = GP_ARG_NUM_REG - cum->words;
3317 if (ret && TARGET_DEBUG_ARG)
3318 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
3319
3320 return ret;
3321 }
3322
3323 return 0;
3324}
3325\f
3326/* A C expression that indicates when an argument must be passed by
3327 reference. If nonzero for an argument, a copy of that argument is
3328 made in memory and a pointer to the argument is passed instead of
3329 the argument itself. The pointer is passed in whatever way is
3330 appropriate for passing a pointer to that type.
3331
c8c99a68
DE
3332 Under V.4, structures and unions are passed by reference.
3333
3334 As an extension to all ABIs, variable sized types are passed by
3335 reference. */
4697a36c
MM
3336
3337int
3338function_arg_pass_by_reference (cum, mode, type, named)
296b8152
KG
3339 CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED;
3340 enum machine_mode mode ATTRIBUTE_UNUSED;
4697a36c 3341 tree type;
296b8152 3342 int named ATTRIBUTE_UNUSED;
4697a36c 3343{
f607bc57 3344 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
3345 && ((type && AGGREGATE_TYPE_P (type))
3346 || mode == TFmode))
4697a36c
MM
3347 {
3348 if (TARGET_DEBUG_ARG)
3349 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
3350
3351 return 1;
3352 }
c8c99a68 3353 return type && int_size_in_bytes (type) <= 0;
4697a36c 3354}
4697a36c
MM
3355\f
3356/* Perform any needed actions needed for a function that is receiving a
3357 variable number of arguments.
3358
3359 CUM is as above.
3360
3361 MODE and TYPE are the mode and type of the current parameter.
3362
3363 PRETEND_SIZE is a variable that should be set to the amount of stack
3364 that must be pushed by the prolog to pretend that our caller pushed
3365 it.
3366
3367 Normally, this macro will push all remaining incoming registers on the
3368 stack and set PRETEND_SIZE to the length of the registers pushed. */
3369
3370void
3371setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
3372 CUMULATIVE_ARGS *cum;
3373 enum machine_mode mode;
3374 tree type;
de62b72c 3375 int *pretend_size ATTRIBUTE_UNUSED;
4697a36c
MM
3376 int no_rtl;
3377
3378{
4cc833b7
RH
3379 CUMULATIVE_ARGS next_cum;
3380 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 3381 rtx save_area = NULL_RTX, mem;
dfafc897 3382 int first_reg_offset, set;
d34c5b80
DE
3383 tree fntype;
3384 int stdarg_p;
4697a36c 3385
d34c5b80
DE
3386 fntype = TREE_TYPE (current_function_decl);
3387 stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
3388 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3389 != void_type_node));
4cc833b7 3390
d34c5b80
DE
3391 /* For varargs, we do not want to skip the dummy va_dcl argument.
3392 For stdargs, we do want to skip the last named argument. */
3393 next_cum = *cum;
3394 if (stdarg_p)
3395 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 3396
f607bc57 3397 if (DEFAULT_ABI == ABI_V4)
d34c5b80 3398 {
4cc833b7 3399 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 3400 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 3401 if (! no_rtl)
2c4974b7 3402 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 3403 - RS6000_VARARGS_SIZE);
4cc833b7
RH
3404
3405 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 3406 }
60e2d0ca 3407 else
4697a36c 3408 {
d34c5b80 3409 first_reg_offset = next_cum.words;
4cc833b7 3410 save_area = virtual_incoming_args_rtx;
00dba523 3411 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
3412
3413 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 3414 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 3415 }
4697a36c 3416
dfafc897 3417 set = get_varargs_alias_set ();
c81fc13e 3418 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 3419 {
dfafc897
FS
3420 mem = gen_rtx_MEM (BLKmode,
3421 plus_constant (save_area,
3422 first_reg_offset * reg_size)),
ba4828e0 3423 set_mem_alias_set (mem, set);
8ac61af7 3424 set_mem_align (mem, BITS_PER_WORD);
dfafc897 3425
4cc833b7 3426 move_block_from_reg
dfafc897 3427 (GP_ARG_MIN_REG + first_reg_offset, mem,
4cc833b7
RH
3428 GP_ARG_NUM_REG - first_reg_offset,
3429 (GP_ARG_NUM_REG - first_reg_offset) * UNITS_PER_WORD);
4697a36c
MM
3430 }
3431
4697a36c 3432 /* Save FP registers if needed. */
f607bc57 3433 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
3434 && TARGET_HARD_FLOAT && TARGET_FPRS
3435 && ! no_rtl
4cc833b7 3436 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 3437 {
4cc833b7 3438 int fregno = next_cum.fregno;
9ebbca7d 3439 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
3440 rtx lab = gen_label_rtx ();
3441 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 3442
4cc833b7 3443 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 3444 pc_rtx,
39403d82 3445 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
3446 gen_rtx_NE (VOIDmode, cr1,
3447 const0_rtx),
39403d82 3448 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
3449 pc_rtx)));
3450
4cc833b7
RH
3451 while (fregno <= FP_ARG_V4_MAX_REG)
3452 {
dfafc897 3453 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 3454 set_mem_alias_set (mem, set);
dfafc897 3455 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
3456 fregno++;
3457 off += 8;
4697a36c 3458 }
4cc833b7
RH
3459
3460 emit_label (lab);
4697a36c 3461 }
4697a36c 3462}
4697a36c 3463
dfafc897 3464/* Create the va_list data type. */
2c4974b7 3465
dfafc897
FS
3466tree
3467rs6000_build_va_list ()
3468{
bab45a51 3469 tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
4697a36c 3470
9ebbca7d
GK
3471 /* For AIX, prefer 'char *' because that's what the system
3472 header files like. */
f607bc57 3473 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 3474 return build_pointer_type (char_type_node);
dfafc897 3475
f1e639b1 3476 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 3477 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 3478
9ebbca7d
GK
3479 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
3480 unsigned_char_type_node);
3481 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
3482 unsigned_char_type_node);
dfafc897
FS
3483 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
3484 ptr_type_node);
3485 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
3486 ptr_type_node);
3487
3488 DECL_FIELD_CONTEXT (f_gpr) = record;
3489 DECL_FIELD_CONTEXT (f_fpr) = record;
3490 DECL_FIELD_CONTEXT (f_ovf) = record;
3491 DECL_FIELD_CONTEXT (f_sav) = record;
3492
bab45a51
FS
3493 TREE_CHAIN (record) = type_decl;
3494 TYPE_NAME (record) = type_decl;
dfafc897
FS
3495 TYPE_FIELDS (record) = f_gpr;
3496 TREE_CHAIN (f_gpr) = f_fpr;
3497 TREE_CHAIN (f_fpr) = f_ovf;
3498 TREE_CHAIN (f_ovf) = f_sav;
3499
3500 layout_type (record);
3501
3502 /* The correct type is an array type of one element. */
3503 return build_array_type (record, build_index_type (size_zero_node));
3504}
3505
3506/* Implement va_start. */
3507
3508void
e5faf155 3509rs6000_va_start (valist, nextarg)
dfafc897
FS
3510 tree valist;
3511 rtx nextarg;
4697a36c 3512{
dfafc897
FS
3513 HOST_WIDE_INT words, n_gpr, n_fpr;
3514 tree f_gpr, f_fpr, f_ovf, f_sav;
3515 tree gpr, fpr, ovf, sav, t;
2c4974b7 3516
dfafc897 3517 /* Only SVR4 needs something special. */
f607bc57 3518 if (DEFAULT_ABI != ABI_V4)
dfafc897 3519 {
e5faf155 3520 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
3521 return;
3522 }
3523
973a648b 3524 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
3525 f_fpr = TREE_CHAIN (f_gpr);
3526 f_ovf = TREE_CHAIN (f_fpr);
3527 f_sav = TREE_CHAIN (f_ovf);
3528
8ebecc3b 3529 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
3530 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
3531 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
3532 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
3533 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
3534
3535 /* Count number of gp and fp argument registers used. */
4cc833b7 3536 words = current_function_args_info.words;
dfafc897
FS
3537 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
3538 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
3539
3540 if (TARGET_DEBUG_ARG)
78e1b90d
DE
3541 {
3542 fputs ("va_start: words = ", stderr);
3543 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, words);
3544 fputs (", n_gpr = ", stderr);
3545 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_gpr);
3546 fputs (", n_fpr = ", stderr);
3547 fprintf (stderr, HOST_WIDE_INT_PRINT_DEC, n_fpr);
3548 putc ('\n', stderr);
3549 }
dfafc897
FS
3550
3551 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
3552 TREE_SIDE_EFFECTS (t) = 1;
3553 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3554
3555 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
3556 TREE_SIDE_EFFECTS (t) = 1;
3557 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3558
3559 /* Find the overflow area. */
3560 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
3561 if (words != 0)
3562 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
3563 build_int_2 (words * UNITS_PER_WORD, 0));
3564 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
3565 TREE_SIDE_EFFECTS (t) = 1;
3566 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3567
3568 /* Find the register save area. */
3569 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
3570 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
3571 build_int_2 (-RS6000_VARARGS_SIZE, -1));
3572 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
3573 TREE_SIDE_EFFECTS (t) = 1;
3574 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3575}
3576
3577/* Implement va_arg. */
3578
3579rtx
3580rs6000_va_arg (valist, type)
3581 tree valist, type;
3582{
3583 tree f_gpr, f_fpr, f_ovf, f_sav;
3584 tree gpr, fpr, ovf, sav, reg, t, u;
3585 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
3586 rtx lab_false, lab_over, addr_rtx, r;
3587
f607bc57 3588 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
3589 {
3590 /* Variable sized types are passed by reference. */
3591 if (int_size_in_bytes (type) <= 0)
3592 {
3593 u = build_pointer_type (type);
3594
3595 /* Args grow upward. */
3596 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
3597 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
3598 TREE_SIDE_EFFECTS (t) = 1;
3599
3600 t = build1 (NOP_EXPR, build_pointer_type (u), t);
3601 TREE_SIDE_EFFECTS (t) = 1;
3602
3603 t = build1 (INDIRECT_REF, u, t);
3604 TREE_SIDE_EFFECTS (t) = 1;
3605
3606 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
3607 }
3608 else
3609 return std_expand_builtin_va_arg (valist, type);
3610 }
dfafc897 3611
973a648b 3612 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897
FS
3613 f_fpr = TREE_CHAIN (f_gpr);
3614 f_ovf = TREE_CHAIN (f_fpr);
3615 f_sav = TREE_CHAIN (f_ovf);
3616
8ebecc3b 3617 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
3618 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
3619 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
3620 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
3621 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
3622
3623 size = int_size_in_bytes (type);
3624 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 3625
dfafc897 3626 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 3627 {
dfafc897
FS
3628 /* Aggregates and long doubles are passed by reference. */
3629 indirect_p = 1;
3630 reg = gpr;
3631 n_reg = 1;
3632 sav_ofs = 0;
3633 sav_scale = 4;
d3294cd9
FS
3634 size = UNITS_PER_WORD;
3635 rsize = 1;
dfafc897 3636 }
a3170dc6 3637 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
3638 {
3639 /* FP args go in FP registers, if present. */
3640 indirect_p = 0;
3641 reg = fpr;
3642 n_reg = 1;
3643 sav_ofs = 8*4;
3644 sav_scale = 8;
4cc833b7 3645 }
dfafc897
FS
3646 else
3647 {
3648 /* Otherwise into GP registers. */
3649 indirect_p = 0;
3650 reg = gpr;
3651 n_reg = rsize;
3652 sav_ofs = 0;
3653 sav_scale = 4;
3654 }
3655
a4f6c312 3656 /* Pull the value out of the saved registers ... */
dfafc897
FS
3657
3658 lab_false = gen_label_rtx ();
3659 lab_over = gen_label_rtx ();
3660 addr_rtx = gen_reg_rtx (Pmode);
3661
16861f33
AH
3662 /* AltiVec vectors never go in registers. */
3663 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 3664 {
41daaf0e
AH
3665 TREE_THIS_VOLATILE (reg) = 1;
3666 emit_cmp_and_jump_insns
3667 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
3668 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
3669 lab_false);
dfafc897 3670
41daaf0e
AH
3671 /* Long long is aligned in the registers. */
3672 if (n_reg > 1)
3673 {
3674 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
3675 build_int_2 (n_reg - 1, 0));
3676 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
3677 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
3678 TREE_SIDE_EFFECTS (u) = 1;
3679 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
3680 }
2c4974b7 3681
41daaf0e
AH
3682 if (sav_ofs)
3683 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
3684 else
3685 t = sav;
2c4974b7 3686
41daaf0e
AH
3687 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
3688 build_int_2 (n_reg, 0));
3689 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 3690
41daaf0e
AH
3691 u = build1 (CONVERT_EXPR, integer_type_node, u);
3692 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 3693
41daaf0e
AH
3694 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
3695 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 3696
41daaf0e
AH
3697 t = build (PLUS_EXPR, ptr_type_node, t, u);
3698 TREE_SIDE_EFFECTS (t) = 1;
3699
3700 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
3701 if (r != addr_rtx)
3702 emit_move_insn (addr_rtx, r);
3703
3704 emit_jump_insn (gen_jump (lab_over));
3705 emit_barrier ();
3706 }
dfafc897 3707
dfafc897
FS
3708 emit_label (lab_false);
3709
a4f6c312 3710 /* ... otherwise out of the overflow area. */
dfafc897 3711
41daaf0e
AH
3712 /* Make sure we don't find reg 7 for the next int arg.
3713
3714 All AltiVec vectors go in the overflow area. So in the AltiVec
3715 case we need to get the vectors from the overflow area, but
3716 remember where the GPRs and FPRs are. */
16861f33
AH
3717 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
3718 || !TARGET_ALTIVEC))
dfafc897
FS
3719 {
3720 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
3721 TREE_SIDE_EFFECTS (t) = 1;
3722 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3723 }
3724
3725 /* Care for on-stack alignment if needed. */
3726 if (rsize <= 1)
3727 t = ovf;
3728 else
3729 {
41daaf0e
AH
3730 int align;
3731
16861f33
AH
3732 /* AltiVec vectors are 16 byte aligned. */
3733 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
3734 align = 15;
3735 else
3736 align = 7;
3737
3738 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
3739 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
3740 }
3741 t = save_expr (t);
3742
3743 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
3744 if (r != addr_rtx)
3745 emit_move_insn (addr_rtx, r);
3746
3747 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
3748 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
3749 TREE_SIDE_EFFECTS (t) = 1;
3750 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
3751
3752 emit_label (lab_over);
3753
3754 if (indirect_p)
3755 {
3756 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 3757 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
3758 emit_move_insn (addr_rtx, r);
3759 }
3760
3761 return addr_rtx;
4697a36c 3762}
0ac081f6
AH
3763
3764/* Builtins. */
3765
6a2dd09a
RS
3766#define def_builtin(MASK, NAME, TYPE, CODE) \
3767do { \
3768 if ((MASK) & target_flags) \
3769 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
3770 NULL, NULL_TREE); \
0ac081f6
AH
3771} while (0)
3772
24408032
AH
3773/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
3774
2212663f 3775static const struct builtin_description bdesc_3arg[] =
24408032
AH
3776{
3777 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
3778 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
3779 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
3780 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
3781 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
3782 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
3783 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
3784 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
3785 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
3786 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
3787 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
3788 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
3789 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
3790 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
3791 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
3792 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
3793 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
3794 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
3795 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
3796 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
3797 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
3798 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
3799 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
3800};
2212663f 3801
95385cbb
AH
3802/* DST operations: void foo (void *, const int, const char). */
3803
3804static const struct builtin_description bdesc_dst[] =
3805{
3806 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
3807 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
3808 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
3809 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
3810};
3811
2212663f 3812/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 3813
a3170dc6 3814static struct builtin_description bdesc_2arg[] =
0ac081f6 3815{
f18c054f
DB
3816 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
3817 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
3818 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
3819 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
3820 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
3821 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
3822 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
3823 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
3824 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
3825 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
3826 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 3827 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
3828 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
3829 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
3830 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
3831 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
3832 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
3833 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
3834 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
3835 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
3836 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
3837 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
3838 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
3839 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
3840 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
3841 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
3842 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
3843 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
3844 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
3845 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
3846 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
3847 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
3848 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
3849 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
3850 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
3851 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
3852 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
3853 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
3854 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
3855 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
3856 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
3857 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
3858 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
3859 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
3860 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
3861 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
3862 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
3863 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
3864 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
3865 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
3866 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
3867 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
3868 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
3869 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
3870 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
3871 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
3872 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
3873 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
3874 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
3875 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
3876 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
3877 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
3878 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
3879 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
3880 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 3881 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
3882 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
3883 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
3884 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
3885 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
3886 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
3887 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
3888 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
3889 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
3890 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
3891 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
3892 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
3893 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
3894 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
3895 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
3896 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
3897 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
3898 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
3899 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
3900 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
3901 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
3902 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
3903 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 3904 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
3905 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
3906 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
3907 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
3908 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
3909 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
3910 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
3911 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
3912 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
3913 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
3914 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
3915 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
3916 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
3917 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
3918 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
3919 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
3920 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
3921 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
3922 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
3923 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
3924 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
3925 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
3926 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
3927 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 3928 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
3929
3930 /* Place holder, leave as first spe builtin. */
3931 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
3932 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
3933 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
3934 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
3935 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
3936 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
3937 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
3938 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
3939 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
3940 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
3941 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
3942 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
3943 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
3944 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
3945 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
3946 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
3947 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
3948 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
3949 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
3950 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
3951 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
3952 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
3953 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
3954 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
3955 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
3956 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
3957 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
3958 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
3959 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
3960 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
3961 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
3962 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
3963 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
3964 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
3965 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
3966 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
3967 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
3968 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
3969 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
3970 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
3971 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
3972 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
3973 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
3974 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
3975 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
3976 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
3977 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
3978 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
3979 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
3980 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
3981 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
3982 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
3983 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
3984 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
3985 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
3986 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
3987 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
3988 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
3989 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
3990 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
3991 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
3992 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
3993 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
3994 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
3995 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
3996 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
3997 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
3998 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
3999 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
4000 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
4001 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
4002 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
4003 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
4004 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
4005 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
4006 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
4007 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
4008 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
4009 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
4010 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
4011 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
4012 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
4013 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
4014 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
4015 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
4016 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
4017 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
4018 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
4019 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
4020 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
4021 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
4022 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
4023 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
4024 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
4025 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
4026 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
4027 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
4028 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
4029 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
4030 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
4031 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
4032 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
4033 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
4034 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
4035 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
4036 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
4037 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
4038 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
4039 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
4040
4041 /* SPE binary operations expecting a 5-bit unsigned literal. */
4042 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
4043
4044 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
4045 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
4046 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
4047 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
4048 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
4049 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
4050 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
4051 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
4052 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
4053 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
4054 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
4055 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
4056 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
4057 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
4058 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
4059 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
4060 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
4061 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
4062 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
4063 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
4064 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
4065 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
4066 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
4067 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
4068 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
4069 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
4070
4071 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 4072 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
4073};
4074
4075/* AltiVec predicates. */
4076
4077struct builtin_description_predicates
4078{
4079 const unsigned int mask;
4080 const enum insn_code icode;
4081 const char *opcode;
4082 const char *const name;
4083 const enum rs6000_builtins code;
4084};
4085
4086static const struct builtin_description_predicates bdesc_altivec_preds[] =
4087{
4088 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
4089 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
4090 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
4091 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
4092 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
4093 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
4094 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
4095 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
4096 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
4097 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
4098 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
4099 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
4100 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 4101};
24408032 4102
a3170dc6
AH
4103/* SPE predicates. */
4104static struct builtin_description bdesc_spe_predicates[] =
4105{
4106 /* Place-holder. Leave as first. */
4107 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
4108 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
4109 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
4110 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
4111 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
4112 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
4113 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
4114 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
4115 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
4116 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
4117 /* Place-holder. Leave as last. */
4118 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
4119};
4120
4121/* SPE evsel predicates. */
4122static struct builtin_description bdesc_spe_evsel[] =
4123{
4124 /* Place-holder. Leave as first. */
4125 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
4126 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
4127 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
4128 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
4129 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
4130 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
4131 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
4132 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
4133 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
4134 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
4135 /* Place-holder. Leave as last. */
4136 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
4137};
4138
b6d08ca1 4139/* ABS* operations. */
100c4561
AH
4140
4141static const struct builtin_description bdesc_abs[] =
4142{
4143 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
4144 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
4145 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
4146 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
4147 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
4148 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
4149 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
4150};
4151
617e0e1d
DB
4152/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
4153 foo (VECa). */
24408032 4154
a3170dc6 4155static struct builtin_description bdesc_1arg[] =
2212663f 4156{
617e0e1d
DB
4157 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
4158 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
4159 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
4160 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
4161 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
4162 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
4163 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
4164 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
4165 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
4166 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
4167 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
4168 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
4169 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
4170 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
4171 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
4172 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
4173 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
4174
4175 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
4176 end with SPE_BUILTIN_EVSUBFUSIAAW. */
4177 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
4178 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
4179 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
4180 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
4181 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
4182 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
4183 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
4184 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
4185 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
4186 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
4187 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
4188 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
4189 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
4190 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
4191 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
4192 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
4193 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
4194 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
4195 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
4196 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
4197 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
4198 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
4199 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
4200 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
4201 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
4202 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
4203 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
4204 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
4205 { 0, CODE_FOR_spe_evsplatfi, "__builtin_spe_evsplatfi", SPE_BUILTIN_EVSPLATFI },
4206 { 0, CODE_FOR_spe_evsplati, "__builtin_spe_evsplati", SPE_BUILTIN_EVSPLATI },
4207
4208 /* Place-holder. Leave as last unary SPE builtin. */
4209 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
4210};
4211
4212static rtx
92898235 4213rs6000_expand_unop_builtin (icode, arglist, target)
2212663f
DB
4214 enum insn_code icode;
4215 tree arglist;
4216 rtx target;
4217{
4218 rtx pat;
4219 tree arg0 = TREE_VALUE (arglist);
4220 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4221 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4222 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4223
0559cc77
DE
4224 if (icode == CODE_FOR_nothing)
4225 /* Builtin not supported on this processor. */
4226 return 0;
4227
20e26713
AH
4228 /* If we got invalid arguments bail out before generating bad rtl. */
4229 if (arg0 == error_mark_node)
9a171fcd 4230 return const0_rtx;
20e26713 4231
0559cc77
DE
4232 if (icode == CODE_FOR_altivec_vspltisb
4233 || icode == CODE_FOR_altivec_vspltish
4234 || icode == CODE_FOR_altivec_vspltisw
4235 || icode == CODE_FOR_spe_evsplatfi
4236 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
4237 {
4238 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
4239 if (GET_CODE (op0) != CONST_INT
4240 || INTVAL (op0) > 0x1f
4241 || INTVAL (op0) < -0x1f)
4242 {
4243 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 4244 return const0_rtx;
b44140e7 4245 }
b44140e7
AH
4246 }
4247
c62f2db5 4248 if (target == 0
2212663f
DB
4249 || GET_MODE (target) != tmode
4250 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4251 target = gen_reg_rtx (tmode);
4252
4253 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4254 op0 = copy_to_mode_reg (mode0, op0);
4255
4256 pat = GEN_FCN (icode) (target, op0);
4257 if (! pat)
4258 return 0;
4259 emit_insn (pat);
0ac081f6 4260
2212663f
DB
4261 return target;
4262}
ae4b4a02 4263
100c4561
AH
4264static rtx
4265altivec_expand_abs_builtin (icode, arglist, target)
4266 enum insn_code icode;
4267 tree arglist;
4268 rtx target;
4269{
4270 rtx pat, scratch1, scratch2;
4271 tree arg0 = TREE_VALUE (arglist);
4272 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4273 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4274 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4275
4276 /* If we have invalid arguments, bail out before generating bad rtl. */
4277 if (arg0 == error_mark_node)
9a171fcd 4278 return const0_rtx;
100c4561
AH
4279
4280 if (target == 0
4281 || GET_MODE (target) != tmode
4282 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4283 target = gen_reg_rtx (tmode);
4284
4285 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4286 op0 = copy_to_mode_reg (mode0, op0);
4287
4288 scratch1 = gen_reg_rtx (mode0);
4289 scratch2 = gen_reg_rtx (mode0);
4290
4291 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
4292 if (! pat)
4293 return 0;
4294 emit_insn (pat);
4295
4296 return target;
4297}
4298
0ac081f6 4299static rtx
92898235 4300rs6000_expand_binop_builtin (icode, arglist, target)
0ac081f6
AH
4301 enum insn_code icode;
4302 tree arglist;
4303 rtx target;
4304{
4305 rtx pat;
4306 tree arg0 = TREE_VALUE (arglist);
4307 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4308 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4309 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4310 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4311 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4312 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4313
0559cc77
DE
4314 if (icode == CODE_FOR_nothing)
4315 /* Builtin not supported on this processor. */
4316 return 0;
4317
20e26713
AH
4318 /* If we got invalid arguments bail out before generating bad rtl. */
4319 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 4320 return const0_rtx;
20e26713 4321
0559cc77
DE
4322 if (icode == CODE_FOR_altivec_vcfux
4323 || icode == CODE_FOR_altivec_vcfsx
4324 || icode == CODE_FOR_altivec_vctsxs
4325 || icode == CODE_FOR_altivec_vctuxs
4326 || icode == CODE_FOR_altivec_vspltb
4327 || icode == CODE_FOR_altivec_vsplth
4328 || icode == CODE_FOR_altivec_vspltw
4329 || icode == CODE_FOR_spe_evaddiw
4330 || icode == CODE_FOR_spe_evldd
4331 || icode == CODE_FOR_spe_evldh
4332 || icode == CODE_FOR_spe_evldw
4333 || icode == CODE_FOR_spe_evlhhesplat
4334 || icode == CODE_FOR_spe_evlhhossplat
4335 || icode == CODE_FOR_spe_evlhhousplat
4336 || icode == CODE_FOR_spe_evlwhe
4337 || icode == CODE_FOR_spe_evlwhos
4338 || icode == CODE_FOR_spe_evlwhou
4339 || icode == CODE_FOR_spe_evlwhsplat
4340 || icode == CODE_FOR_spe_evlwwsplat
4341 || icode == CODE_FOR_spe_evrlwi
4342 || icode == CODE_FOR_spe_evslwi
4343 || icode == CODE_FOR_spe_evsrwis
4344 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
4345 {
4346 /* Only allow 5-bit unsigned literals. */
b44140e7
AH
4347 if (TREE_CODE (arg1) != INTEGER_CST
4348 || TREE_INT_CST_LOW (arg1) & ~0x1f)
4349 {
4350 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 4351 return const0_rtx;
b44140e7 4352 }
b44140e7
AH
4353 }
4354
c62f2db5 4355 if (target == 0
0ac081f6
AH
4356 || GET_MODE (target) != tmode
4357 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4358 target = gen_reg_rtx (tmode);
4359
4360 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4361 op0 = copy_to_mode_reg (mode0, op0);
4362 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4363 op1 = copy_to_mode_reg (mode1, op1);
4364
4365 pat = GEN_FCN (icode) (target, op0, op1);
4366 if (! pat)
4367 return 0;
4368 emit_insn (pat);
4369
4370 return target;
4371}
6525c0e7 4372
ae4b4a02
AH
4373static rtx
4374altivec_expand_predicate_builtin (icode, opcode, arglist, target)
4375 enum insn_code icode;
4376 const char *opcode;
4377 tree arglist;
4378 rtx target;
4379{
4380 rtx pat, scratch;
4381 tree cr6_form = TREE_VALUE (arglist);
4382 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
4383 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4384 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4385 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4386 enum machine_mode tmode = SImode;
4387 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4388 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4389 int cr6_form_int;
4390
4391 if (TREE_CODE (cr6_form) != INTEGER_CST)
4392 {
4393 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 4394 return const0_rtx;
ae4b4a02
AH
4395 }
4396 else
4397 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
4398
4399 if (mode0 != mode1)
4400 abort ();
4401
4402 /* If we have invalid arguments, bail out before generating bad rtl. */
4403 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 4404 return const0_rtx;
ae4b4a02
AH
4405
4406 if (target == 0
4407 || GET_MODE (target) != tmode
4408 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4409 target = gen_reg_rtx (tmode);
4410
4411 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4412 op0 = copy_to_mode_reg (mode0, op0);
4413 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4414 op1 = copy_to_mode_reg (mode1, op1);
4415
4416 scratch = gen_reg_rtx (mode0);
4417
4418 pat = GEN_FCN (icode) (scratch, op0, op1,
4419 gen_rtx (SYMBOL_REF, Pmode, opcode));
4420 if (! pat)
4421 return 0;
4422 emit_insn (pat);
4423
4424 /* The vec_any* and vec_all* predicates use the same opcodes for two
4425 different operations, but the bits in CR6 will be different
4426 depending on what information we want. So we have to play tricks
4427 with CR6 to get the right bits out.
4428
4429 If you think this is disgusting, look at the specs for the
4430 AltiVec predicates. */
4431
4432 switch (cr6_form_int)
4433 {
4434 case 0:
4435 emit_insn (gen_cr6_test_for_zero (target));
4436 break;
4437 case 1:
4438 emit_insn (gen_cr6_test_for_zero_reverse (target));
4439 break;
4440 case 2:
4441 emit_insn (gen_cr6_test_for_lt (target));
4442 break;
4443 case 3:
4444 emit_insn (gen_cr6_test_for_lt_reverse (target));
4445 break;
4446 default:
4447 error ("argument 1 of __builtin_altivec_predicate is out of range");
4448 break;
4449 }
4450
4451 return target;
4452}
4453
6525c0e7
AH
4454static rtx
4455altivec_expand_stv_builtin (icode, arglist)
4456 enum insn_code icode;
4457 tree arglist;
4458{
4459 tree arg0 = TREE_VALUE (arglist);
4460 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4461 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4462 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4463 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4464 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4465 rtx pat;
4466 enum machine_mode mode0 = insn_data[icode].operand[0].mode;
4467 enum machine_mode mode1 = insn_data[icode].operand[1].mode;
4468 enum machine_mode mode2 = insn_data[icode].operand[2].mode;
4469
4470 /* Invalid arguments. Bail before doing anything stoopid! */
4471 if (arg0 == error_mark_node
4472 || arg1 == error_mark_node
4473 || arg2 == error_mark_node)
9a171fcd 4474 return const0_rtx;
6525c0e7
AH
4475
4476 if (! (*insn_data[icode].operand[2].predicate) (op0, mode2))
4477 op0 = copy_to_mode_reg (mode2, op0);
4478 if (! (*insn_data[icode].operand[0].predicate) (op1, mode0))
4479 op1 = copy_to_mode_reg (mode0, op1);
4480 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
4481 op2 = copy_to_mode_reg (mode1, op2);
4482
4483 pat = GEN_FCN (icode) (op1, op2, op0);
4484 if (pat)
4485 emit_insn (pat);
4486 return NULL_RTX;
4487}
4488
2212663f 4489static rtx
92898235 4490rs6000_expand_ternop_builtin (icode, arglist, target)
2212663f
DB
4491 enum insn_code icode;
4492 tree arglist;
4493 rtx target;
4494{
4495 rtx pat;
4496 tree arg0 = TREE_VALUE (arglist);
4497 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4498 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4499 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4500 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4501 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4502 enum machine_mode tmode = insn_data[icode].operand[0].mode;
4503 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
4504 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
4505 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 4506
774b5662
DE
4507 if (icode == CODE_FOR_nothing)
4508 /* Builtin not supported on this processor. */
4509 return 0;
4510
20e26713
AH
4511 /* If we got invalid arguments bail out before generating bad rtl. */
4512 if (arg0 == error_mark_node
4513 || arg1 == error_mark_node
4514 || arg2 == error_mark_node)
9a171fcd 4515 return const0_rtx;
20e26713 4516
774b5662
DE
4517 if (icode == CODE_FOR_altivec_vsldoi_4sf
4518 || icode == CODE_FOR_altivec_vsldoi_4si
4519 || icode == CODE_FOR_altivec_vsldoi_8hi
4520 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
4521 {
4522 /* Only allow 4-bit unsigned literals. */
b44140e7
AH
4523 if (TREE_CODE (arg2) != INTEGER_CST
4524 || TREE_INT_CST_LOW (arg2) & ~0xf)
4525 {
4526 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 4527 return const0_rtx;
b44140e7 4528 }
b44140e7
AH
4529 }
4530
c62f2db5 4531 if (target == 0
2212663f
DB
4532 || GET_MODE (target) != tmode
4533 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4534 target = gen_reg_rtx (tmode);
4535
4536 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4537 op0 = copy_to_mode_reg (mode0, op0);
4538 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
4539 op1 = copy_to_mode_reg (mode1, op1);
4540 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
4541 op2 = copy_to_mode_reg (mode2, op2);
4542
4543 pat = GEN_FCN (icode) (target, op0, op1, op2);
4544 if (! pat)
4545 return 0;
4546 emit_insn (pat);
4547
4548 return target;
4549}
92898235 4550
3a9b8c7e 4551/* Expand the lvx builtins. */
0ac081f6 4552static rtx
3a9b8c7e 4553altivec_expand_ld_builtin (exp, target, expandedp)
0ac081f6
AH
4554 tree exp;
4555 rtx target;
92898235 4556 bool *expandedp;
0ac081f6 4557{
0ac081f6
AH
4558 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4559 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 4560 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
4561 tree arg0;
4562 enum machine_mode tmode, mode0;
7c3abc73 4563 rtx pat, op0;
3a9b8c7e 4564 enum insn_code icode;
92898235 4565
0ac081f6
AH
4566 switch (fcode)
4567 {
f18c054f
DB
4568 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
4569 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 4570 break;
f18c054f
DB
4571 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
4572 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
4573 break;
4574 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
4575 icode = CODE_FOR_altivec_lvx_4si;
4576 break;
4577 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
4578 icode = CODE_FOR_altivec_lvx_4sf;
4579 break;
4580 default:
4581 *expandedp = false;
4582 return NULL_RTX;
4583 }
0ac081f6 4584
3a9b8c7e 4585 *expandedp = true;
f18c054f 4586
3a9b8c7e
AH
4587 arg0 = TREE_VALUE (arglist);
4588 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4589 tmode = insn_data[icode].operand[0].mode;
4590 mode0 = insn_data[icode].operand[1].mode;
f18c054f 4591
3a9b8c7e
AH
4592 if (target == 0
4593 || GET_MODE (target) != tmode
4594 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4595 target = gen_reg_rtx (tmode);
24408032 4596
3a9b8c7e
AH
4597 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
4598 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 4599
3a9b8c7e
AH
4600 pat = GEN_FCN (icode) (target, op0);
4601 if (! pat)
4602 return 0;
4603 emit_insn (pat);
4604 return target;
4605}
f18c054f 4606
3a9b8c7e
AH
4607/* Expand the stvx builtins. */
4608static rtx
4609altivec_expand_st_builtin (exp, target, expandedp)
4610 tree exp;
7c3abc73 4611 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
4612 bool *expandedp;
4613{
4614 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4615 tree arglist = TREE_OPERAND (exp, 1);
4616 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4617 tree arg0, arg1;
4618 enum machine_mode mode0, mode1;
7c3abc73 4619 rtx pat, op0, op1;
3a9b8c7e 4620 enum insn_code icode;
f18c054f 4621
3a9b8c7e
AH
4622 switch (fcode)
4623 {
4624 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
4625 icode = CODE_FOR_altivec_stvx_16qi;
4626 break;
4627 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
4628 icode = CODE_FOR_altivec_stvx_8hi;
4629 break;
4630 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
4631 icode = CODE_FOR_altivec_stvx_4si;
4632 break;
4633 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
4634 icode = CODE_FOR_altivec_stvx_4sf;
4635 break;
4636 default:
4637 *expandedp = false;
4638 return NULL_RTX;
4639 }
24408032 4640
3a9b8c7e
AH
4641 arg0 = TREE_VALUE (arglist);
4642 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4643 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4644 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4645 mode0 = insn_data[icode].operand[0].mode;
4646 mode1 = insn_data[icode].operand[1].mode;
f18c054f 4647
3a9b8c7e
AH
4648 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4649 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
4650 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
4651 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 4652
3a9b8c7e
AH
4653 pat = GEN_FCN (icode) (op0, op1);
4654 if (pat)
4655 emit_insn (pat);
f18c054f 4656
3a9b8c7e
AH
4657 *expandedp = true;
4658 return NULL_RTX;
4659}
f18c054f 4660
3a9b8c7e
AH
4661/* Expand the dst builtins. */
4662static rtx
4663altivec_expand_dst_builtin (exp, target, expandedp)
4664 tree exp;
7c3abc73 4665 rtx target ATTRIBUTE_UNUSED;
3a9b8c7e
AH
4666 bool *expandedp;
4667{
4668 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4669 tree arglist = TREE_OPERAND (exp, 1);
4670 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4671 tree arg0, arg1, arg2;
4672 enum machine_mode mode0, mode1, mode2;
7c3abc73 4673 rtx pat, op0, op1, op2;
3a9b8c7e 4674 struct builtin_description *d;
a3170dc6 4675 size_t i;
f18c054f 4676
3a9b8c7e 4677 *expandedp = false;
f18c054f 4678
3a9b8c7e
AH
4679 /* Handle DST variants. */
4680 d = (struct builtin_description *) bdesc_dst;
4681 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
4682 if (d->code == fcode)
4683 {
4684 arg0 = TREE_VALUE (arglist);
4685 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
4686 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4687 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4688 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
4689 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
4690 mode0 = insn_data[d->icode].operand[0].mode;
4691 mode1 = insn_data[d->icode].operand[1].mode;
4692 mode2 = insn_data[d->icode].operand[2].mode;
24408032 4693
3a9b8c7e
AH
4694 /* Invalid arguments, bail out before generating bad rtl. */
4695 if (arg0 == error_mark_node
4696 || arg1 == error_mark_node
4697 || arg2 == error_mark_node)
4698 return const0_rtx;
f18c054f 4699
3a9b8c7e
AH
4700 if (TREE_CODE (arg2) != INTEGER_CST
4701 || TREE_INT_CST_LOW (arg2) & ~0x3)
4702 {
4703 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
4704 return const0_rtx;
4705 }
f18c054f 4706
3a9b8c7e
AH
4707 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
4708 op0 = copy_to_mode_reg (mode0, op0);
4709 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
4710 op1 = copy_to_mode_reg (mode1, op1);
24408032 4711
3a9b8c7e
AH
4712 pat = GEN_FCN (d->icode) (op0, op1, op2);
4713 if (pat != 0)
4714 emit_insn (pat);
f18c054f 4715
3a9b8c7e
AH
4716 *expandedp = true;
4717 return NULL_RTX;
4718 }
f18c054f 4719
3a9b8c7e
AH
4720 return NULL_RTX;
4721}
24408032 4722
3a9b8c7e
AH
4723/* Expand the builtin in EXP and store the result in TARGET. Store
4724 true in *EXPANDEDP if we found a builtin to expand. */
4725static rtx
4726altivec_expand_builtin (exp, target, expandedp)
4727 tree exp;
4728 rtx target;
4729 bool *expandedp;
4730{
4731 struct builtin_description *d;
4732 struct builtin_description_predicates *dp;
4733 size_t i;
4734 enum insn_code icode;
4735 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4736 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
4737 tree arg0;
4738 rtx op0, pat;
4739 enum machine_mode tmode, mode0;
3a9b8c7e 4740 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 4741
3a9b8c7e
AH
4742 target = altivec_expand_ld_builtin (exp, target, expandedp);
4743 if (*expandedp)
4744 return target;
0ac081f6 4745
3a9b8c7e
AH
4746 target = altivec_expand_st_builtin (exp, target, expandedp);
4747 if (*expandedp)
4748 return target;
4749
4750 target = altivec_expand_dst_builtin (exp, target, expandedp);
4751 if (*expandedp)
4752 return target;
4753
4754 *expandedp = true;
95385cbb 4755
3a9b8c7e
AH
4756 switch (fcode)
4757 {
6525c0e7
AH
4758 case ALTIVEC_BUILTIN_STVX:
4759 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
4760 case ALTIVEC_BUILTIN_STVEBX:
4761 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
4762 case ALTIVEC_BUILTIN_STVEHX:
4763 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
4764 case ALTIVEC_BUILTIN_STVEWX:
4765 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
4766 case ALTIVEC_BUILTIN_STVXL:
4767 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 4768
95385cbb
AH
4769 case ALTIVEC_BUILTIN_MFVSCR:
4770 icode = CODE_FOR_altivec_mfvscr;
4771 tmode = insn_data[icode].operand[0].mode;
4772
4773 if (target == 0
4774 || GET_MODE (target) != tmode
4775 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
4776 target = gen_reg_rtx (tmode);
4777
4778 pat = GEN_FCN (icode) (target);
0ac081f6
AH
4779 if (! pat)
4780 return 0;
4781 emit_insn (pat);
95385cbb
AH
4782 return target;
4783
4784 case ALTIVEC_BUILTIN_MTVSCR:
4785 icode = CODE_FOR_altivec_mtvscr;
4786 arg0 = TREE_VALUE (arglist);
4787 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4788 mode0 = insn_data[icode].operand[0].mode;
4789
4790 /* If we got invalid arguments bail out before generating bad rtl. */
4791 if (arg0 == error_mark_node)
9a171fcd 4792 return const0_rtx;
95385cbb
AH
4793
4794 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4795 op0 = copy_to_mode_reg (mode0, op0);
4796
4797 pat = GEN_FCN (icode) (op0);
4798 if (pat)
4799 emit_insn (pat);
4800 return NULL_RTX;
3a9b8c7e 4801
95385cbb
AH
4802 case ALTIVEC_BUILTIN_DSSALL:
4803 emit_insn (gen_altivec_dssall ());
4804 return NULL_RTX;
4805
4806 case ALTIVEC_BUILTIN_DSS:
4807 icode = CODE_FOR_altivec_dss;
4808 arg0 = TREE_VALUE (arglist);
4809 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
4810 mode0 = insn_data[icode].operand[0].mode;
4811
4812 /* If we got invalid arguments bail out before generating bad rtl. */
4813 if (arg0 == error_mark_node)
9a171fcd 4814 return const0_rtx;
95385cbb 4815
b44140e7
AH
4816 if (TREE_CODE (arg0) != INTEGER_CST
4817 || TREE_INT_CST_LOW (arg0) & ~0x3)
4818 {
4819 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 4820 return const0_rtx;
b44140e7
AH
4821 }
4822
95385cbb
AH
4823 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
4824 op0 = copy_to_mode_reg (mode0, op0);
4825
4826 emit_insn (gen_altivec_dss (op0));
0ac081f6
AH
4827 return NULL_RTX;
4828 }
24408032 4829
100c4561
AH
4830 /* Expand abs* operations. */
4831 d = (struct builtin_description *) bdesc_abs;
ca7558fc 4832 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
4833 if (d->code == fcode)
4834 return altivec_expand_abs_builtin (d->icode, arglist, target);
4835
ae4b4a02
AH
4836 /* Expand the AltiVec predicates. */
4837 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 4838 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
4839 if (dp->code == fcode)
4840 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
4841
6525c0e7
AH
4842 /* LV* are funky. We initialized them differently. */
4843 switch (fcode)
4844 {
4845 case ALTIVEC_BUILTIN_LVSL:
92898235 4846 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
4847 arglist, target);
4848 case ALTIVEC_BUILTIN_LVSR:
92898235
AH
4849 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvsr,
4850 arglist, target);
6525c0e7 4851 case ALTIVEC_BUILTIN_LVEBX:
92898235
AH
4852 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvebx,
4853 arglist, target);
6525c0e7 4854 case ALTIVEC_BUILTIN_LVEHX:
92898235
AH
4855 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvehx,
4856 arglist, target);
6525c0e7 4857 case ALTIVEC_BUILTIN_LVEWX:
92898235
AH
4858 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvewx,
4859 arglist, target);
6525c0e7 4860 case ALTIVEC_BUILTIN_LVXL:
92898235
AH
4861 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvxl,
4862 arglist, target);
6525c0e7 4863 case ALTIVEC_BUILTIN_LVX:
92898235
AH
4864 return rs6000_expand_binop_builtin (CODE_FOR_altivec_lvx,
4865 arglist, target);
6525c0e7
AH
4866 default:
4867 break;
4868 /* Fall through. */
4869 }
95385cbb 4870
92898235 4871 *expandedp = false;
0ac081f6
AH
4872 return NULL_RTX;
4873}
4874
a3170dc6
AH
4875/* Binops that need to be initialized manually, but can be expanded
4876 automagically by rs6000_expand_binop_builtin. */
4877static struct builtin_description bdesc_2arg_spe[] =
4878{
4879 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
4880 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
4881 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
4882 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
4883 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
4884 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
4885 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
4886 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
4887 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
4888 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
4889 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
4890 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
4891 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
4892 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
4893 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
4894 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
4895 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
4896 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
4897 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
4898 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
4899 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
4900 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
4901};
4902
4903/* Expand the builtin in EXP and store the result in TARGET. Store
4904 true in *EXPANDEDP if we found a builtin to expand.
4905
4906 This expands the SPE builtins that are not simple unary and binary
4907 operations. */
4908static rtx
4909spe_expand_builtin (exp, target, expandedp)
4910 tree exp;
4911 rtx target;
4912 bool *expandedp;
4913{
4914 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
4915 tree arglist = TREE_OPERAND (exp, 1);
4916 tree arg1, arg0;
4917 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
4918 enum insn_code icode;
4919 enum machine_mode tmode, mode0;
4920 rtx pat, op0;
4921 struct builtin_description *d;
4922 size_t i;
4923
4924 *expandedp = true;
4925
4926 /* Syntax check for a 5-bit unsigned immediate. */
4927 switch (fcode)
4928 {
4929 case SPE_BUILTIN_EVSTDD:
4930 case SPE_BUILTIN_EVSTDH:
4931 case SPE_BUILTIN_EVSTDW:
4932 case SPE_BUILTIN_EVSTWHE:
4933 case SPE_BUILTIN_EVSTWHO:
4934 case SPE_BUILTIN_EVSTWWE:
4935 case SPE_BUILTIN_EVSTWWO:
4936 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
4937 if (TREE_CODE (arg1) != INTEGER_CST
4938 || TREE_INT_CST_LOW (arg1) & ~0x1f)
4939 {
4940 error ("argument 2 must be a 5-bit unsigned literal");
4941 return const0_rtx;
4942 }
4943 break;
4944 default:
4945 break;
4946 }
4947
4948 d = (struct builtin_description *) bdesc_2arg_spe;
4949 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
4950 if (d->code == fcode)
4951 return rs6000_expand_binop_builtin (d->icode, arglist, target);
4952
4953 d = (struct builtin_description *) bdesc_spe_predicates;
4954 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
4955 if (d->code == fcode)
4956 return spe_expand_predicate_builtin (d->icode, arglist, target);
4957
4958 d = (struct builtin_description *) bdesc_spe_evsel;
4959 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
4960 if (d->code == fcode)
4961 return spe_expand_evsel_builtin (d->icode, arglist, target);
4962
4963 switch (fcode)
4964 {
4965 case SPE_BUILTIN_EVSTDDX:
4966 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
4967 case SPE_BUILTIN_EVSTDHX:
4968 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
4969 case SPE_BUILTIN_EVSTDWX:
4970 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
4971 case SPE_BUILTIN_EVSTWHEX:
4972 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
4973 case SPE_BUILTIN_EVSTWHOX:
4974 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
4975 case SPE_BUILTIN_EVSTWWEX:
4976 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
4977 case SPE_BUILTIN_EVSTWWOX:
4978 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
4979 case SPE_BUILTIN_EVSTDD:
4980 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
4981 case SPE_BUILTIN_EVSTDH:
4982 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
4983 case SPE_BUILTIN_EVSTDW:
4984 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
4985 case SPE_BUILTIN_EVSTWHE:
4986 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
4987 case SPE_BUILTIN_EVSTWHO:
4988 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
4989 case SPE_BUILTIN_EVSTWWE:
4990 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
4991 case SPE_BUILTIN_EVSTWWO:
4992 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
4993 case SPE_BUILTIN_MFSPEFSCR:
4994 icode = CODE_FOR_spe_mfspefscr;
4995 tmode = insn_data[icode].operand[0].mode;
4996
4997 if (target == 0
4998 || GET_MODE (target) != tmode
4999 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5000 target = gen_reg_rtx (tmode);
5001
5002 pat = GEN_FCN (icode) (target);
5003 if (! pat)
5004 return 0;
5005 emit_insn (pat);
5006 return target;
5007 case SPE_BUILTIN_MTSPEFSCR:
5008 icode = CODE_FOR_spe_mtspefscr;
5009 arg0 = TREE_VALUE (arglist);
5010 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5011 mode0 = insn_data[icode].operand[0].mode;
5012
5013 if (arg0 == error_mark_node)
5014 return const0_rtx;
5015
5016 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5017 op0 = copy_to_mode_reg (mode0, op0);
5018
5019 pat = GEN_FCN (icode) (op0);
5020 if (pat)
5021 emit_insn (pat);
5022 return NULL_RTX;
5023 default:
5024 break;
5025 }
5026
5027 *expandedp = false;
5028 return NULL_RTX;
5029}
5030
5031static rtx
5032spe_expand_predicate_builtin (icode, arglist, target)
5033 enum insn_code icode;
5034 tree arglist;
5035 rtx target;
5036{
5037 rtx pat, scratch, tmp;
5038 tree form = TREE_VALUE (arglist);
5039 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5040 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5041 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5042 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5043 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5044 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5045 int form_int;
5046 enum rtx_code code;
5047
5048 if (TREE_CODE (form) != INTEGER_CST)
5049 {
5050 error ("argument 1 of __builtin_spe_predicate must be a constant");
5051 return const0_rtx;
5052 }
5053 else
5054 form_int = TREE_INT_CST_LOW (form);
5055
5056 if (mode0 != mode1)
5057 abort ();
5058
5059 if (arg0 == error_mark_node || arg1 == error_mark_node)
5060 return const0_rtx;
5061
5062 if (target == 0
5063 || GET_MODE (target) != SImode
5064 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
5065 target = gen_reg_rtx (SImode);
5066
5067 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5068 op0 = copy_to_mode_reg (mode0, op0);
5069 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5070 op1 = copy_to_mode_reg (mode1, op1);
5071
5072 scratch = gen_reg_rtx (CCmode);
5073
5074 pat = GEN_FCN (icode) (scratch, op0, op1);
5075 if (! pat)
5076 return const0_rtx;
5077 emit_insn (pat);
5078
5079 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
5080 _lower_. We use one compare, but look in different bits of the
5081 CR for each variant.
5082
5083 There are 2 elements in each SPE simd type (upper/lower). The CR
5084 bits are set as follows:
5085
5086 BIT0 | BIT 1 | BIT 2 | BIT 3
5087 U | L | (U | L) | (U & L)
5088
5089 So, for an "all" relationship, BIT 3 would be set.
5090 For an "any" relationship, BIT 2 would be set. Etc.
5091
5092 Following traditional nomenclature, these bits map to:
5093
5094 BIT0 | BIT 1 | BIT 2 | BIT 3
5095 LT | GT | EQ | OV
5096
5097 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
5098 */
5099
5100 switch (form_int)
5101 {
5102 /* All variant. OV bit. */
5103 case 0:
5104 /* We need to get to the OV bit, which is the ORDERED bit. We
5105 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
5106 that's ugly and will trigger a validate_condition_mode abort.
5107 So let's just use another pattern. */
5108 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
5109 return target;
5110 /* Any variant. EQ bit. */
5111 case 1:
5112 code = EQ;
5113 break;
5114 /* Upper variant. LT bit. */
5115 case 2:
5116 code = LT;
5117 break;
5118 /* Lower variant. GT bit. */
5119 case 3:
5120 code = GT;
5121 break;
5122 default:
5123 error ("argument 1 of __builtin_spe_predicate is out of range");
5124 return const0_rtx;
5125 }
5126
5127 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
5128 emit_move_insn (target, tmp);
5129
5130 return target;
5131}
5132
5133/* The evsel builtins look like this:
5134
5135 e = __builtin_spe_evsel_OP (a, b, c, d);
5136
5137 and work like this:
5138
5139 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
5140 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
5141*/
5142
5143static rtx
5144spe_expand_evsel_builtin (icode, arglist, target)
5145 enum insn_code icode;
5146 tree arglist;
5147 rtx target;
5148{
5149 rtx pat, scratch;
5150 tree arg0 = TREE_VALUE (arglist);
5151 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5152 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5153 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
5154 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5155 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5156 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5157 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
5158 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5159 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5160
5161 if (mode0 != mode1)
5162 abort ();
5163
5164 if (arg0 == error_mark_node || arg1 == error_mark_node
5165 || arg2 == error_mark_node || arg3 == error_mark_node)
5166 return const0_rtx;
5167
5168 if (target == 0
5169 || GET_MODE (target) != mode0
5170 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
5171 target = gen_reg_rtx (mode0);
5172
5173 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5174 op0 = copy_to_mode_reg (mode0, op0);
5175 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5176 op1 = copy_to_mode_reg (mode0, op1);
5177 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
5178 op2 = copy_to_mode_reg (mode0, op2);
5179 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
5180 op3 = copy_to_mode_reg (mode0, op3);
5181
5182 /* Generate the compare. */
5183 scratch = gen_reg_rtx (CCmode);
5184 pat = GEN_FCN (icode) (scratch, op0, op1);
5185 if (! pat)
5186 return const0_rtx;
5187 emit_insn (pat);
5188
5189 if (mode0 == V2SImode)
5190 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
5191 else
5192 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
5193
5194 return target;
5195}
5196
0ac081f6
AH
5197/* Expand an expression EXP that calls a built-in function,
5198 with result going to TARGET if that's convenient
5199 (and in mode MODE if that's convenient).
5200 SUBTARGET may be used as the target for computing one of EXP's operands.
5201 IGNORE is nonzero if the value is to be ignored. */
5202
5203static rtx
5204rs6000_expand_builtin (exp, target, subtarget, mode, ignore)
5205 tree exp;
5206 rtx target;
00b960c7
AH
5207 rtx subtarget ATTRIBUTE_UNUSED;
5208 enum machine_mode mode ATTRIBUTE_UNUSED;
5209 int ignore ATTRIBUTE_UNUSED;
0ac081f6 5210{
92898235
AH
5211 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5212 tree arglist = TREE_OPERAND (exp, 1);
5213 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5214 struct builtin_description *d;
5215 size_t i;
5216 rtx ret;
5217 bool success;
5218
0ac081f6 5219 if (TARGET_ALTIVEC)
92898235
AH
5220 {
5221 ret = altivec_expand_builtin (exp, target, &success);
5222
a3170dc6
AH
5223 if (success)
5224 return ret;
5225 }
5226 if (TARGET_SPE)
5227 {
5228 ret = spe_expand_builtin (exp, target, &success);
5229
92898235
AH
5230 if (success)
5231 return ret;
5232 }
5233
0559cc77
DE
5234 if (TARGET_ALTIVEC || TARGET_SPE)
5235 {
5236 /* Handle simple unary operations. */
5237 d = (struct builtin_description *) bdesc_1arg;
5238 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
5239 if (d->code == fcode)
5240 return rs6000_expand_unop_builtin (d->icode, arglist, target);
5241
5242 /* Handle simple binary operations. */
5243 d = (struct builtin_description *) bdesc_2arg;
5244 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
5245 if (d->code == fcode)
5246 return rs6000_expand_binop_builtin (d->icode, arglist, target);
5247
5248 /* Handle simple ternary operations. */
5249 d = (struct builtin_description *) bdesc_3arg;
5250 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
5251 if (d->code == fcode)
5252 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
5253 }
0ac081f6
AH
5254
5255 abort ();
92898235 5256 return NULL_RTX;
0ac081f6
AH
5257}
5258
5259static void
6fa3f289 5260rs6000_init_builtins ()
0ac081f6 5261{
a3170dc6
AH
5262 if (TARGET_SPE)
5263 spe_init_builtins ();
0ac081f6
AH
5264 if (TARGET_ALTIVEC)
5265 altivec_init_builtins ();
0559cc77
DE
5266 if (TARGET_ALTIVEC || TARGET_SPE)
5267 rs6000_common_init_builtins ();
0ac081f6
AH
5268}
5269
a3170dc6
AH
5270/* Search through a set of builtins and enable the mask bits.
5271 DESC is an array of builtins.
b6d08ca1 5272 SIZE is the total number of builtins.
a3170dc6
AH
5273 START is the builtin enum at which to start.
5274 END is the builtin enum at which to end. */
0ac081f6 5275static void
a3170dc6
AH
5276enable_mask_for_builtins (desc, size, start, end)
5277 struct builtin_description *desc;
5278 int size;
5279 enum rs6000_builtins start, end;
5280{
5281 int i;
5282
5283 for (i = 0; i < size; ++i)
5284 if (desc[i].code == start)
5285 break;
5286
5287 if (i == size)
5288 return;
5289
5290 for (; i < size; ++i)
5291 {
5292 /* Flip all the bits on. */
5293 desc[i].mask = target_flags;
5294 if (desc[i].code == end)
5295 break;
5296 }
5297}
5298
5299static void
b24c9d35 5300spe_init_builtins ()
0ac081f6 5301{
a3170dc6
AH
5302 tree endlink = void_list_node;
5303 tree puint_type_node = build_pointer_type (unsigned_type_node);
5304 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
5305 tree pv2si_type_node = build_pointer_type (V2SI_type_node);
ae4b4a02 5306 struct builtin_description *d;
0ac081f6
AH
5307 size_t i;
5308
a3170dc6
AH
5309 tree v2si_ftype_4_v2si
5310 = build_function_type
5311 (V2SI_type_node,
5312 tree_cons (NULL_TREE, V2SI_type_node,
5313 tree_cons (NULL_TREE, V2SI_type_node,
5314 tree_cons (NULL_TREE, V2SI_type_node,
5315 tree_cons (NULL_TREE, V2SI_type_node,
5316 endlink)))));
5317
5318 tree v2sf_ftype_4_v2sf
5319 = build_function_type
5320 (V2SF_type_node,
5321 tree_cons (NULL_TREE, V2SF_type_node,
5322 tree_cons (NULL_TREE, V2SF_type_node,
5323 tree_cons (NULL_TREE, V2SF_type_node,
5324 tree_cons (NULL_TREE, V2SF_type_node,
5325 endlink)))));
5326
5327 tree int_ftype_int_v2si_v2si
5328 = build_function_type
5329 (integer_type_node,
5330 tree_cons (NULL_TREE, integer_type_node,
5331 tree_cons (NULL_TREE, V2SI_type_node,
5332 tree_cons (NULL_TREE, V2SI_type_node,
5333 endlink))));
5334
5335 tree int_ftype_int_v2sf_v2sf
5336 = build_function_type
5337 (integer_type_node,
5338 tree_cons (NULL_TREE, integer_type_node,
5339 tree_cons (NULL_TREE, V2SF_type_node,
5340 tree_cons (NULL_TREE, V2SF_type_node,
5341 endlink))));
5342
5343 tree void_ftype_v2si_puint_int
5344 = build_function_type (void_type_node,
5345 tree_cons (NULL_TREE, V2SI_type_node,
5346 tree_cons (NULL_TREE, puint_type_node,
5347 tree_cons (NULL_TREE,
5348 integer_type_node,
5349 endlink))));
5350
5351 tree void_ftype_v2si_puint_char
5352 = build_function_type (void_type_node,
5353 tree_cons (NULL_TREE, V2SI_type_node,
5354 tree_cons (NULL_TREE, puint_type_node,
5355 tree_cons (NULL_TREE,
5356 char_type_node,
5357 endlink))));
5358
5359 tree void_ftype_v2si_pv2si_int
5360 = build_function_type (void_type_node,
5361 tree_cons (NULL_TREE, V2SI_type_node,
5362 tree_cons (NULL_TREE, pv2si_type_node,
5363 tree_cons (NULL_TREE,
5364 integer_type_node,
5365 endlink))));
5366
5367 tree void_ftype_v2si_pv2si_char
5368 = build_function_type (void_type_node,
5369 tree_cons (NULL_TREE, V2SI_type_node,
5370 tree_cons (NULL_TREE, pv2si_type_node,
5371 tree_cons (NULL_TREE,
5372 char_type_node,
5373 endlink))));
5374
5375 tree void_ftype_int
5376 = build_function_type (void_type_node,
5377 tree_cons (NULL_TREE, integer_type_node, endlink));
5378
5379 tree int_ftype_void
5380 = build_function_type (integer_type_node,
5381 tree_cons (NULL_TREE, void_type_node, endlink));
5382
5383 tree v2si_ftype_pv2si_int
5384 = build_function_type (V2SI_type_node,
5385 tree_cons (NULL_TREE, pv2si_type_node,
5386 tree_cons (NULL_TREE, integer_type_node,
5387 endlink)));
5388
5389 tree v2si_ftype_puint_int
5390 = build_function_type (V2SI_type_node,
5391 tree_cons (NULL_TREE, puint_type_node,
5392 tree_cons (NULL_TREE, integer_type_node,
5393 endlink)));
5394
5395 tree v2si_ftype_pushort_int
5396 = build_function_type (V2SI_type_node,
5397 tree_cons (NULL_TREE, pushort_type_node,
5398 tree_cons (NULL_TREE, integer_type_node,
5399 endlink)));
5400
5401 /* The initialization of the simple binary and unary builtins is
5402 done in rs6000_common_init_builtins, but we have to enable the
5403 mask bits here manually because we have run out of `target_flags'
5404 bits. We really need to redesign this mask business. */
5405
5406 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
5407 ARRAY_SIZE (bdesc_2arg),
5408 SPE_BUILTIN_EVADDW,
5409 SPE_BUILTIN_EVXOR);
5410 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
5411 ARRAY_SIZE (bdesc_1arg),
5412 SPE_BUILTIN_EVABS,
5413 SPE_BUILTIN_EVSUBFUSIAAW);
5414 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
5415 ARRAY_SIZE (bdesc_spe_predicates),
5416 SPE_BUILTIN_EVCMPEQ,
5417 SPE_BUILTIN_EVFSTSTLT);
5418 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
5419 ARRAY_SIZE (bdesc_spe_evsel),
5420 SPE_BUILTIN_EVSEL_CMPGTS,
5421 SPE_BUILTIN_EVSEL_FSTSTEQ);
5422
5423 /* Initialize irregular SPE builtins. */
5424
5425 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
5426 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
5427 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
5428 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
5429 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
5430 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
5431 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
5432 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
5433 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
5434 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
5435 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
5436 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
5437 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
5438 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
5439 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
5440 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
5441
5442 /* Loads. */
5443 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
5444 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
5445 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
5446 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
5447 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
5448 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
5449 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
5450 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
5451 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
5452 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
5453 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
5454 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
5455 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
5456 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
5457 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
5458 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
5459 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
5460 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
5461 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
5462 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
5463 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
5464 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
5465
5466 /* Predicates. */
5467 d = (struct builtin_description *) bdesc_spe_predicates;
5468 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
5469 {
5470 tree type;
5471
5472 switch (insn_data[d->icode].operand[1].mode)
5473 {
5474 case V2SImode:
5475 type = int_ftype_int_v2si_v2si;
5476 break;
5477 case V2SFmode:
5478 type = int_ftype_int_v2sf_v2sf;
5479 break;
5480 default:
5481 abort ();
5482 }
5483
5484 def_builtin (d->mask, d->name, type, d->code);
5485 }
5486
5487 /* Evsel predicates. */
5488 d = (struct builtin_description *) bdesc_spe_evsel;
5489 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
5490 {
5491 tree type;
5492
5493 switch (insn_data[d->icode].operand[1].mode)
5494 {
5495 case V2SImode:
5496 type = v2si_ftype_4_v2si;
5497 break;
5498 case V2SFmode:
5499 type = v2sf_ftype_4_v2sf;
5500 break;
5501 default:
5502 abort ();
5503 }
5504
5505 def_builtin (d->mask, d->name, type, d->code);
5506 }
5507}
5508
5509static void
b24c9d35 5510altivec_init_builtins ()
a3170dc6
AH
5511{
5512 struct builtin_description *d;
5513 struct builtin_description_predicates *dp;
5514 size_t i;
5515 tree pfloat_type_node = build_pointer_type (float_type_node);
5516 tree pint_type_node = build_pointer_type (integer_type_node);
5517 tree pshort_type_node = build_pointer_type (short_integer_type_node);
5518 tree pchar_type_node = build_pointer_type (char_type_node);
5519
5520 tree pvoid_type_node = build_pointer_type (void_type_node);
5521
0dbc3651
ZW
5522 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
5523 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
5524 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
5525 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
5526
5527 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
5528
a3170dc6
AH
5529 tree int_ftype_int_v4si_v4si
5530 = build_function_type_list (integer_type_node,
5531 integer_type_node, V4SI_type_node,
5532 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
5533 tree v4sf_ftype_pcfloat
5534 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 5535 tree void_ftype_pfloat_v4sf
b4de2f7d 5536 = build_function_type_list (void_type_node,
a3170dc6 5537 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
5538 tree v4si_ftype_pcint
5539 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
5540 tree void_ftype_pint_v4si
b4de2f7d
AH
5541 = build_function_type_list (void_type_node,
5542 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
5543 tree v8hi_ftype_pcshort
5544 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 5545 tree void_ftype_pshort_v8hi
b4de2f7d
AH
5546 = build_function_type_list (void_type_node,
5547 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
5548 tree v16qi_ftype_pcchar
5549 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 5550 tree void_ftype_pchar_v16qi
b4de2f7d
AH
5551 = build_function_type_list (void_type_node,
5552 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 5553 tree void_ftype_v4si
b4de2f7d 5554 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
5555 tree v8hi_ftype_void
5556 = build_function_type (V8HI_type_node, void_list_node);
5557 tree void_ftype_void
5558 = build_function_type (void_type_node, void_list_node);
5559 tree void_ftype_qi
5560 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651
ZW
5561
5562 tree v16qi_ftype_int_pcvoid
a3170dc6 5563 = build_function_type_list (V16QI_type_node,
0dbc3651
ZW
5564 integer_type_node, pcvoid_type_node, NULL_TREE);
5565 tree v8hi_ftype_int_pcvoid
a3170dc6 5566 = build_function_type_list (V8HI_type_node,
0dbc3651
ZW
5567 integer_type_node, pcvoid_type_node, NULL_TREE);
5568 tree v4si_ftype_int_pcvoid
a3170dc6 5569 = build_function_type_list (V4SI_type_node,
0dbc3651
ZW
5570 integer_type_node, pcvoid_type_node, NULL_TREE);
5571
14b32f4e 5572 tree void_ftype_v4si_int_pvoid
b4de2f7d
AH
5573 = build_function_type_list (void_type_node,
5574 V4SI_type_node, integer_type_node,
5575 pvoid_type_node, NULL_TREE);
6525c0e7 5576 tree void_ftype_v16qi_int_pvoid
b4de2f7d
AH
5577 = build_function_type_list (void_type_node,
5578 V16QI_type_node, integer_type_node,
5579 pvoid_type_node, NULL_TREE);
6525c0e7 5580 tree void_ftype_v8hi_int_pvoid
b4de2f7d
AH
5581 = build_function_type_list (void_type_node,
5582 V8HI_type_node, integer_type_node,
5583 pvoid_type_node, NULL_TREE);
a3170dc6
AH
5584 tree int_ftype_int_v8hi_v8hi
5585 = build_function_type_list (integer_type_node,
5586 integer_type_node, V8HI_type_node,
5587 V8HI_type_node, NULL_TREE);
5588 tree int_ftype_int_v16qi_v16qi
5589 = build_function_type_list (integer_type_node,
5590 integer_type_node, V16QI_type_node,
5591 V16QI_type_node, NULL_TREE);
5592 tree int_ftype_int_v4sf_v4sf
5593 = build_function_type_list (integer_type_node,
5594 integer_type_node, V4SF_type_node,
5595 V4SF_type_node, NULL_TREE);
5596 tree v4si_ftype_v4si
5597 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
5598 tree v8hi_ftype_v8hi
5599 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
5600 tree v16qi_ftype_v16qi
5601 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
5602 tree v4sf_ftype_v4sf
5603 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
0dbc3651 5604 tree void_ftype_pcvoid_int_char
a3170dc6 5605 = build_function_type_list (void_type_node,
0dbc3651 5606 pcvoid_type_node, integer_type_node,
a3170dc6 5607 char_type_node, NULL_TREE);
0dbc3651
ZW
5608
5609 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
5610 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
5611 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
5612 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
5613 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
5614 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
5615 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
5616 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
5617 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
5618 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
5619 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
5620 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
5621 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
5622 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
5623 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
5624 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
5625 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
5626 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
5627 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
5628 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
0dbc3651
ZW
5629 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSL);
5630 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVSR);
5631 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEBX);
5632 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEHX);
5633 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVEWX);
5634 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVXL);
5635 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_int_pcvoid, ALTIVEC_BUILTIN_LVX);
a3170dc6
AH
5636 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVX);
5637 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVEWX);
5638 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_int_pvoid, ALTIVEC_BUILTIN_STVXL);
5639 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_int_pvoid, ALTIVEC_BUILTIN_STVEBX);
5640 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_int_pvoid, ALTIVEC_BUILTIN_STVEHX);
5641
5642 /* Add the DST variants. */
5643 d = (struct builtin_description *) bdesc_dst;
5644 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
0dbc3651 5645 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code);
a3170dc6
AH
5646
5647 /* Initialize the predicates. */
5648 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
5649 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
5650 {
5651 enum machine_mode mode1;
5652 tree type;
5653
5654 mode1 = insn_data[dp->icode].operand[1].mode;
5655
5656 switch (mode1)
5657 {
5658 case V4SImode:
5659 type = int_ftype_int_v4si_v4si;
5660 break;
5661 case V8HImode:
5662 type = int_ftype_int_v8hi_v8hi;
5663 break;
5664 case V16QImode:
5665 type = int_ftype_int_v16qi_v16qi;
5666 break;
5667 case V4SFmode:
5668 type = int_ftype_int_v4sf_v4sf;
5669 break;
5670 default:
5671 abort ();
5672 }
5673
5674 def_builtin (dp->mask, dp->name, type, dp->code);
5675 }
5676
5677 /* Initialize the abs* operators. */
5678 d = (struct builtin_description *) bdesc_abs;
5679 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
5680 {
5681 enum machine_mode mode0;
5682 tree type;
5683
5684 mode0 = insn_data[d->icode].operand[0].mode;
5685
5686 switch (mode0)
5687 {
5688 case V4SImode:
5689 type = v4si_ftype_v4si;
5690 break;
5691 case V8HImode:
5692 type = v8hi_ftype_v8hi;
5693 break;
5694 case V16QImode:
5695 type = v16qi_ftype_v16qi;
5696 break;
5697 case V4SFmode:
5698 type = v4sf_ftype_v4sf;
5699 break;
5700 default:
5701 abort ();
5702 }
5703
5704 def_builtin (d->mask, d->name, type, d->code);
5705 }
5706}
5707
5708static void
b24c9d35 5709rs6000_common_init_builtins ()
a3170dc6
AH
5710{
5711 struct builtin_description *d;
5712 size_t i;
5713
5714 tree v4sf_ftype_v4sf_v4sf_v16qi
5715 = build_function_type_list (V4SF_type_node,
5716 V4SF_type_node, V4SF_type_node,
5717 V16QI_type_node, NULL_TREE);
5718 tree v4si_ftype_v4si_v4si_v16qi
5719 = build_function_type_list (V4SI_type_node,
5720 V4SI_type_node, V4SI_type_node,
5721 V16QI_type_node, NULL_TREE);
5722 tree v8hi_ftype_v8hi_v8hi_v16qi
5723 = build_function_type_list (V8HI_type_node,
5724 V8HI_type_node, V8HI_type_node,
5725 V16QI_type_node, NULL_TREE);
5726 tree v16qi_ftype_v16qi_v16qi_v16qi
5727 = build_function_type_list (V16QI_type_node,
5728 V16QI_type_node, V16QI_type_node,
5729 V16QI_type_node, NULL_TREE);
5730 tree v4si_ftype_char
5731 = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE);
5732 tree v8hi_ftype_char
5733 = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE);
5734 tree v16qi_ftype_char
5735 = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE);
5736 tree v8hi_ftype_v16qi
5737 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
5738 tree v4sf_ftype_v4sf
5739 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
5740
5741 tree v2si_ftype_v2si_v2si
5742 = build_function_type_list (V2SI_type_node,
5743 V2SI_type_node, V2SI_type_node, NULL_TREE);
5744
5745 tree v2sf_ftype_v2sf_v2sf
5746 = build_function_type_list (V2SF_type_node,
5747 V2SF_type_node, V2SF_type_node, NULL_TREE);
5748
5749 tree v2si_ftype_int_int
5750 = build_function_type_list (V2SI_type_node,
5751 integer_type_node, integer_type_node,
5752 NULL_TREE);
5753
5754 tree v2si_ftype_v2si
5755 = build_function_type_list (V2SI_type_node, V2SI_type_node, NULL_TREE);
5756
5757 tree v2sf_ftype_v2sf
5758 = build_function_type_list (V2SF_type_node,
5759 V2SF_type_node, NULL_TREE);
5760
5761 tree v2sf_ftype_v2si
5762 = build_function_type_list (V2SF_type_node,
5763 V2SI_type_node, NULL_TREE);
5764
5765 tree v2si_ftype_v2sf
5766 = build_function_type_list (V2SI_type_node,
5767 V2SF_type_node, NULL_TREE);
5768
5769 tree v2si_ftype_v2si_char
5770 = build_function_type_list (V2SI_type_node,
5771 V2SI_type_node, char_type_node, NULL_TREE);
5772
5773 tree v2si_ftype_int_char
5774 = build_function_type_list (V2SI_type_node,
5775 integer_type_node, char_type_node, NULL_TREE);
5776
5777 tree v2si_ftype_char
5778 = build_function_type_list (V2SI_type_node, char_type_node, NULL_TREE);
5779
5780 tree int_ftype_int_int
5781 = build_function_type_list (integer_type_node,
5782 integer_type_node, integer_type_node,
5783 NULL_TREE);
95385cbb 5784
0ac081f6 5785 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
5786 = build_function_type_list (V4SI_type_node,
5787 V4SI_type_node, V4SI_type_node, NULL_TREE);
617e0e1d 5788 tree v4sf_ftype_v4si_char
b4de2f7d
AH
5789 = build_function_type_list (V4SF_type_node,
5790 V4SI_type_node, char_type_node, NULL_TREE);
617e0e1d 5791 tree v4si_ftype_v4sf_char
b4de2f7d
AH
5792 = build_function_type_list (V4SI_type_node,
5793 V4SF_type_node, char_type_node, NULL_TREE);
2212663f 5794 tree v4si_ftype_v4si_char
b4de2f7d
AH
5795 = build_function_type_list (V4SI_type_node,
5796 V4SI_type_node, char_type_node, NULL_TREE);
2212663f 5797 tree v8hi_ftype_v8hi_char
b4de2f7d
AH
5798 = build_function_type_list (V8HI_type_node,
5799 V8HI_type_node, char_type_node, NULL_TREE);
2212663f 5800 tree v16qi_ftype_v16qi_char
b4de2f7d
AH
5801 = build_function_type_list (V16QI_type_node,
5802 V16QI_type_node, char_type_node, NULL_TREE);
24408032 5803 tree v16qi_ftype_v16qi_v16qi_char
b4de2f7d
AH
5804 = build_function_type_list (V16QI_type_node,
5805 V16QI_type_node, V16QI_type_node,
5806 char_type_node, NULL_TREE);
24408032 5807 tree v8hi_ftype_v8hi_v8hi_char
b4de2f7d
AH
5808 = build_function_type_list (V8HI_type_node,
5809 V8HI_type_node, V8HI_type_node,
5810 char_type_node, NULL_TREE);
24408032 5811 tree v4si_ftype_v4si_v4si_char
b4de2f7d
AH
5812 = build_function_type_list (V4SI_type_node,
5813 V4SI_type_node, V4SI_type_node,
5814 char_type_node, NULL_TREE);
24408032 5815 tree v4sf_ftype_v4sf_v4sf_char
b4de2f7d
AH
5816 = build_function_type_list (V4SF_type_node,
5817 V4SF_type_node, V4SF_type_node,
5818 char_type_node, NULL_TREE);
0ac081f6 5819 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
5820 = build_function_type_list (V4SF_type_node,
5821 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 5822 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
5823 = build_function_type_list (V4SF_type_node,
5824 V4SF_type_node, V4SF_type_node,
5825 V4SI_type_node, NULL_TREE);
2212663f 5826 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
5827 = build_function_type_list (V4SF_type_node,
5828 V4SF_type_node, V4SF_type_node,
5829 V4SF_type_node, NULL_TREE);
617e0e1d 5830 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
5831 = build_function_type_list (V4SI_type_node,
5832 V4SI_type_node, V4SI_type_node,
5833 V4SI_type_node, NULL_TREE);
0ac081f6 5834 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
5835 = build_function_type_list (V8HI_type_node,
5836 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 5837 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
5838 = build_function_type_list (V8HI_type_node,
5839 V8HI_type_node, V8HI_type_node,
5840 V8HI_type_node, NULL_TREE);
2212663f 5841 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
5842 = build_function_type_list (V4SI_type_node,
5843 V8HI_type_node, V8HI_type_node,
5844 V4SI_type_node, NULL_TREE);
2212663f 5845 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
5846 = build_function_type_list (V4SI_type_node,
5847 V16QI_type_node, V16QI_type_node,
5848 V4SI_type_node, NULL_TREE);
0ac081f6 5849 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
5850 = build_function_type_list (V16QI_type_node,
5851 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5852 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
5853 = build_function_type_list (V4SI_type_node,
5854 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 5855 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
5856 = build_function_type_list (V8HI_type_node,
5857 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5858 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
5859 = build_function_type_list (V4SI_type_node,
5860 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5861 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
5862 = build_function_type_list (V8HI_type_node,
5863 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 5864 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
5865 = build_function_type_list (V16QI_type_node,
5866 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5867 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
5868 = build_function_type_list (V4SI_type_node,
5869 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 5870 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
5871 = build_function_type_list (V4SI_type_node,
5872 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5873 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
5874 = build_function_type_list (V4SI_type_node,
5875 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
5876 tree v4si_ftype_v8hi
5877 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
5878 tree int_ftype_v4si_v4si
5879 = build_function_type_list (integer_type_node,
5880 V4SI_type_node, V4SI_type_node, NULL_TREE);
5881 tree int_ftype_v4sf_v4sf
5882 = build_function_type_list (integer_type_node,
5883 V4SF_type_node, V4SF_type_node, NULL_TREE);
5884 tree int_ftype_v16qi_v16qi
5885 = build_function_type_list (integer_type_node,
5886 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 5887 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
5888 = build_function_type_list (integer_type_node,
5889 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 5890
6f317ef3 5891 /* Add the simple ternary operators. */
2212663f 5892 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 5893 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
5894 {
5895
5896 enum machine_mode mode0, mode1, mode2, mode3;
5897 tree type;
5898
0559cc77 5899 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
5900 continue;
5901
5902 mode0 = insn_data[d->icode].operand[0].mode;
5903 mode1 = insn_data[d->icode].operand[1].mode;
5904 mode2 = insn_data[d->icode].operand[2].mode;
5905 mode3 = insn_data[d->icode].operand[3].mode;
5906
5907 /* When all four are of the same mode. */
5908 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
5909 {
5910 switch (mode0)
5911 {
617e0e1d
DB
5912 case V4SImode:
5913 type = v4si_ftype_v4si_v4si_v4si;
5914 break;
2212663f
DB
5915 case V4SFmode:
5916 type = v4sf_ftype_v4sf_v4sf_v4sf;
5917 break;
5918 case V8HImode:
5919 type = v8hi_ftype_v8hi_v8hi_v8hi;
5920 break;
5921 case V16QImode:
5922 type = v16qi_ftype_v16qi_v16qi_v16qi;
5923 break;
5924 default:
5925 abort();
5926 }
5927 }
5928 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
5929 {
5930 switch (mode0)
5931 {
5932 case V4SImode:
5933 type = v4si_ftype_v4si_v4si_v16qi;
5934 break;
5935 case V4SFmode:
5936 type = v4sf_ftype_v4sf_v4sf_v16qi;
5937 break;
5938 case V8HImode:
5939 type = v8hi_ftype_v8hi_v8hi_v16qi;
5940 break;
5941 case V16QImode:
5942 type = v16qi_ftype_v16qi_v16qi_v16qi;
5943 break;
5944 default:
5945 abort();
5946 }
5947 }
5948 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
5949 && mode3 == V4SImode)
24408032 5950 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
5951 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
5952 && mode3 == V4SImode)
24408032 5953 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
5954 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
5955 && mode3 == V4SImode)
24408032
AH
5956 type = v4sf_ftype_v4sf_v4sf_v4si;
5957
5958 /* vchar, vchar, vchar, 4 bit literal. */
5959 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
5960 && mode3 == QImode)
5961 type = v16qi_ftype_v16qi_v16qi_char;
5962
5963 /* vshort, vshort, vshort, 4 bit literal. */
5964 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
5965 && mode3 == QImode)
5966 type = v8hi_ftype_v8hi_v8hi_char;
5967
5968 /* vint, vint, vint, 4 bit literal. */
5969 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
5970 && mode3 == QImode)
5971 type = v4si_ftype_v4si_v4si_char;
5972
5973 /* vfloat, vfloat, vfloat, 4 bit literal. */
5974 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
5975 && mode3 == QImode)
5976 type = v4sf_ftype_v4sf_v4sf_char;
5977
2212663f
DB
5978 else
5979 abort ();
5980
5981 def_builtin (d->mask, d->name, type, d->code);
5982 }
5983
0ac081f6 5984 /* Add the simple binary operators. */
00b960c7 5985 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 5986 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
5987 {
5988 enum machine_mode mode0, mode1, mode2;
5989 tree type;
5990
0559cc77 5991 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
5992 continue;
5993
5994 mode0 = insn_data[d->icode].operand[0].mode;
5995 mode1 = insn_data[d->icode].operand[1].mode;
5996 mode2 = insn_data[d->icode].operand[2].mode;
5997
5998 /* When all three operands are of the same mode. */
5999 if (mode0 == mode1 && mode1 == mode2)
6000 {
6001 switch (mode0)
6002 {
6003 case V4SFmode:
6004 type = v4sf_ftype_v4sf_v4sf;
6005 break;
6006 case V4SImode:
6007 type = v4si_ftype_v4si_v4si;
6008 break;
6009 case V16QImode:
6010 type = v16qi_ftype_v16qi_v16qi;
6011 break;
6012 case V8HImode:
6013 type = v8hi_ftype_v8hi_v8hi;
6014 break;
a3170dc6
AH
6015 case V2SImode:
6016 type = v2si_ftype_v2si_v2si;
6017 break;
6018 case V2SFmode:
6019 type = v2sf_ftype_v2sf_v2sf;
6020 break;
6021 case SImode:
6022 type = int_ftype_int_int;
6023 break;
0ac081f6
AH
6024 default:
6025 abort ();
6026 }
6027 }
6028
6029 /* A few other combos we really don't want to do manually. */
6030
6031 /* vint, vfloat, vfloat. */
6032 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
6033 type = v4si_ftype_v4sf_v4sf;
6034
6035 /* vshort, vchar, vchar. */
6036 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
6037 type = v8hi_ftype_v16qi_v16qi;
6038
6039 /* vint, vshort, vshort. */
6040 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
6041 type = v4si_ftype_v8hi_v8hi;
6042
6043 /* vshort, vint, vint. */
6044 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
6045 type = v8hi_ftype_v4si_v4si;
6046
6047 /* vchar, vshort, vshort. */
6048 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
6049 type = v16qi_ftype_v8hi_v8hi;
6050
6051 /* vint, vchar, vint. */
6052 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
6053 type = v4si_ftype_v16qi_v4si;
6054
fa066a23
AH
6055 /* vint, vchar, vchar. */
6056 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
6057 type = v4si_ftype_v16qi_v16qi;
6058
0ac081f6
AH
6059 /* vint, vshort, vint. */
6060 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
6061 type = v4si_ftype_v8hi_v4si;
2212663f
DB
6062
6063 /* vint, vint, 5 bit literal. */
6064 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
6065 type = v4si_ftype_v4si_char;
6066
6067 /* vshort, vshort, 5 bit literal. */
6068 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
6069 type = v8hi_ftype_v8hi_char;
6070
6071 /* vchar, vchar, 5 bit literal. */
6072 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
6073 type = v16qi_ftype_v16qi_char;
0ac081f6 6074
617e0e1d
DB
6075 /* vfloat, vint, 5 bit literal. */
6076 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
6077 type = v4sf_ftype_v4si_char;
6078
6079 /* vint, vfloat, 5 bit literal. */
6080 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
6081 type = v4si_ftype_v4sf_char;
6082
a3170dc6
AH
6083 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
6084 type = v2si_ftype_int_int;
6085
6086 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
6087 type = v2si_ftype_v2si_char;
6088
6089 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
6090 type = v2si_ftype_int_char;
6091
0ac081f6
AH
6092 /* int, x, x. */
6093 else if (mode0 == SImode)
6094 {
6095 switch (mode1)
6096 {
6097 case V4SImode:
6098 type = int_ftype_v4si_v4si;
6099 break;
6100 case V4SFmode:
6101 type = int_ftype_v4sf_v4sf;
6102 break;
6103 case V16QImode:
6104 type = int_ftype_v16qi_v16qi;
6105 break;
6106 case V8HImode:
6107 type = int_ftype_v8hi_v8hi;
6108 break;
6109 default:
6110 abort ();
6111 }
6112 }
6113
6114 else
6115 abort ();
6116
2212663f
DB
6117 def_builtin (d->mask, d->name, type, d->code);
6118 }
24408032 6119
2212663f
DB
6120 /* Add the simple unary operators. */
6121 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 6122 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
6123 {
6124 enum machine_mode mode0, mode1;
6125 tree type;
6126
0559cc77 6127 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
6128 continue;
6129
6130 mode0 = insn_data[d->icode].operand[0].mode;
6131 mode1 = insn_data[d->icode].operand[1].mode;
6132
6133 if (mode0 == V4SImode && mode1 == QImode)
6134 type = v4si_ftype_char;
6135 else if (mode0 == V8HImode && mode1 == QImode)
6136 type = v8hi_ftype_char;
6137 else if (mode0 == V16QImode && mode1 == QImode)
6138 type = v16qi_ftype_char;
617e0e1d
DB
6139 else if (mode0 == V4SFmode && mode1 == V4SFmode)
6140 type = v4sf_ftype_v4sf;
20e26713
AH
6141 else if (mode0 == V8HImode && mode1 == V16QImode)
6142 type = v8hi_ftype_v16qi;
6143 else if (mode0 == V4SImode && mode1 == V8HImode)
6144 type = v4si_ftype_v8hi;
a3170dc6
AH
6145 else if (mode0 == V2SImode && mode1 == V2SImode)
6146 type = v2si_ftype_v2si;
6147 else if (mode0 == V2SFmode && mode1 == V2SFmode)
6148 type = v2sf_ftype_v2sf;
6149 else if (mode0 == V2SFmode && mode1 == V2SImode)
6150 type = v2sf_ftype_v2si;
6151 else if (mode0 == V2SImode && mode1 == V2SFmode)
6152 type = v2si_ftype_v2sf;
6153 else if (mode0 == V2SImode && mode1 == QImode)
6154 type = v2si_ftype_char;
2212663f
DB
6155 else
6156 abort ();
6157
0ac081f6
AH
6158 def_builtin (d->mask, d->name, type, d->code);
6159 }
6160}
6161
35aff10b 6162\f
7e69e155
MM
6163/* Expand a block move operation, and return 1 if successful. Return 0
6164 if we should let the compiler generate normal code.
6165
6166 operands[0] is the destination
6167 operands[1] is the source
6168 operands[2] is the length
6169 operands[3] is the alignment */
6170
3933e0e1
MM
6171#define MAX_MOVE_REG 4
6172
7e69e155
MM
6173int
6174expand_block_move (operands)
6175 rtx operands[];
6176{
b6c9286a
MM
6177 rtx orig_dest = operands[0];
6178 rtx orig_src = operands[1];
7e69e155 6179 rtx bytes_rtx = operands[2];
7e69e155 6180 rtx align_rtx = operands[3];
3933e0e1 6181 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 6182 int align;
3933e0e1
MM
6183 int bytes;
6184 int offset;
7e69e155
MM
6185 int move_bytes;
6186
3933e0e1 6187 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 6188 if (! constp)
3933e0e1
MM
6189 return 0;
6190
5ee95df6
FS
6191 /* If this is not a fixed size alignment, abort */
6192 if (GET_CODE (align_rtx) != CONST_INT)
6193 abort ();
6194 align = INTVAL (align_rtx);
6195
7e69e155 6196 /* Anything to move? */
3933e0e1
MM
6197 bytes = INTVAL (bytes_rtx);
6198 if (bytes <= 0)
7e69e155
MM
6199 return 1;
6200
ea9982a8 6201 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 6202 reg_parm_stack_space. */
ea9982a8 6203 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
6204 return 0;
6205
3933e0e1 6206 if (TARGET_STRING) /* string instructions are available */
7e69e155 6207 {
35aff10b 6208 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 6209 {
35aff10b
AM
6210 union {
6211 rtx (*movstrsi) PARAMS ((rtx, rtx, rtx, rtx));
6212 rtx (*mov) PARAMS ((rtx, rtx));
6213 } gen_func;
6214 enum machine_mode mode = BLKmode;
6215 rtx src, dest;
6216
3933e0e1 6217 if (bytes > 24 /* move up to 32 bytes at a time */
cc0d9ba8
DE
6218 && ! fixed_regs[5]
6219 && ! fixed_regs[6]
6220 && ! fixed_regs[7]
6221 && ! fixed_regs[8]
6222 && ! fixed_regs[9]
6223 && ! fixed_regs[10]
6224 && ! fixed_regs[11]
6225 && ! fixed_regs[12])
3933e0e1
MM
6226 {
6227 move_bytes = (bytes > 32) ? 32 : bytes;
35aff10b 6228 gen_func.movstrsi = gen_movstrsi_8reg;
3933e0e1
MM
6229 }
6230 else if (bytes > 16 /* move up to 24 bytes at a time */
f9562f27
DE
6231 && ! fixed_regs[5]
6232 && ! fixed_regs[6]
cc0d9ba8
DE
6233 && ! fixed_regs[7]
6234 && ! fixed_regs[8]
6235 && ! fixed_regs[9]
f9562f27 6236 && ! fixed_regs[10])
3933e0e1
MM
6237 {
6238 move_bytes = (bytes > 24) ? 24 : bytes;
35aff10b 6239 gen_func.movstrsi = gen_movstrsi_6reg;
3933e0e1
MM
6240 }
6241 else if (bytes > 8 /* move up to 16 bytes at a time */
f9562f27
DE
6242 && ! fixed_regs[5]
6243 && ! fixed_regs[6]
6244 && ! fixed_regs[7]
6245 && ! fixed_regs[8])
3933e0e1
MM
6246 {
6247 move_bytes = (bytes > 16) ? 16 : bytes;
35aff10b 6248 gen_func.movstrsi = gen_movstrsi_4reg;
3933e0e1 6249 }
acad7ed3 6250 else if (bytes >= 8 && TARGET_POWERPC64
a4f6c312 6251 /* 64-bit loads and stores require word-aligned
82e41834 6252 displacements. */
a4f6c312 6253 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
acad7ed3
DE
6254 {
6255 move_bytes = 8;
35aff10b
AM
6256 mode = DImode;
6257 gen_func.mov = gen_movdi;
acad7ed3 6258 }
09a625f7 6259 else if (bytes > 4 && !TARGET_POWERPC64)
3933e0e1
MM
6260 { /* move up to 8 bytes at a time */
6261 move_bytes = (bytes > 8) ? 8 : bytes;
35aff10b 6262 gen_func.movstrsi = gen_movstrsi_2reg;
3933e0e1 6263 }
cc0d9ba8 6264 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6265 { /* move 4 bytes */
6266 move_bytes = 4;
35aff10b
AM
6267 mode = SImode;
6268 gen_func.mov = gen_movsi;
3933e0e1 6269 }
cc0d9ba8 6270 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6271 { /* move 2 bytes */
6272 move_bytes = 2;
35aff10b
AM
6273 mode = HImode;
6274 gen_func.mov = gen_movhi;
3933e0e1
MM
6275 }
6276 else if (bytes == 1) /* move 1 byte */
6277 {
6278 move_bytes = 1;
35aff10b
AM
6279 mode = QImode;
6280 gen_func.mov = gen_movqi;
3933e0e1
MM
6281 }
6282 else
6283 { /* move up to 4 bytes at a time */
6284 move_bytes = (bytes > 4) ? 4 : bytes;
35aff10b 6285 gen_func.movstrsi = gen_movstrsi_1reg;
3933e0e1 6286 }
4c64a852 6287
35aff10b
AM
6288 src = adjust_address (orig_src, mode, offset);
6289 dest = adjust_address (orig_dest, mode, offset);
6290
6291 if (mode == BLKmode)
015892ee 6292 {
35aff10b
AM
6293 /* Move the address into scratch registers. The movstrsi
6294 patterns require zero offset. */
6295 if (!REG_P (XEXP (src, 0)))
cc0d9ba8 6296 {
35aff10b
AM
6297 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
6298 src = replace_equiv_address (src, src_reg);
cc0d9ba8 6299 }
35aff10b
AM
6300 set_mem_size (src, GEN_INT (move_bytes));
6301
6302 if (!REG_P (XEXP (dest, 0)))
cc0d9ba8 6303 {
35aff10b
AM
6304 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
6305 dest = replace_equiv_address (dest, dest_reg);
cc0d9ba8 6306 }
35aff10b
AM
6307 set_mem_size (dest, GEN_INT (move_bytes));
6308
6309 emit_insn ((*gen_func.movstrsi) (dest, src,
6310 GEN_INT (move_bytes & 31),
6311 align_rtx));
6312 }
6313 else
6314 {
6315 rtx tmp_reg = gen_reg_rtx (mode);
6316
6317 emit_insn ((*gen_func.mov) (tmp_reg, src));
6318 emit_insn ((*gen_func.mov) (dest, tmp_reg));
015892ee 6319 }
4c64a852 6320 }
3933e0e1
MM
6321 }
6322
6323 else /* string instructions not available */
6324 {
35aff10b
AM
6325 rtx stores[MAX_MOVE_REG];
6326 int num_reg = 0;
6327 int i;
6328
6329 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 6330 {
35aff10b
AM
6331 rtx (*gen_mov_func) PARAMS ((rtx, rtx));
6332 enum machine_mode mode;
6333 rtx src, dest, tmp_reg;
3933e0e1 6334
cc0d9ba8
DE
6335 /* Generate the appropriate load and store, saving the stores
6336 for later. */
6337 if (bytes >= 8 && TARGET_POWERPC64
a4f6c312
SS
6338 /* 64-bit loads and stores require word-aligned
6339 displacements. */
cc0d9ba8 6340 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
b6c9286a
MM
6341 {
6342 move_bytes = 8;
35aff10b
AM
6343 mode = DImode;
6344 gen_mov_func = gen_movdi;
b6c9286a 6345 }
cc0d9ba8 6346 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6347 {
6348 move_bytes = 4;
35aff10b
AM
6349 mode = SImode;
6350 gen_mov_func = gen_movsi;
3933e0e1 6351 }
cc0d9ba8 6352 else if (bytes >= 2 && (align >= 2 || ! STRICT_ALIGNMENT))
3933e0e1
MM
6353 {
6354 move_bytes = 2;
35aff10b
AM
6355 mode = HImode;
6356 gen_mov_func = gen_movhi;
3933e0e1
MM
6357 }
6358 else
6359 {
6360 move_bytes = 1;
35aff10b
AM
6361 mode = QImode;
6362 gen_mov_func = gen_movqi;
3933e0e1
MM
6363 }
6364
35aff10b
AM
6365 src = adjust_address (orig_src, mode, offset);
6366 dest = adjust_address (orig_dest, mode, offset);
6367 tmp_reg = gen_reg_rtx (mode);
6368
6369 emit_insn ((*gen_mov_func) (tmp_reg, src));
6370 stores[num_reg++] = (*gen_mov_func) (dest, tmp_reg);
6371
3933e0e1
MM
6372 if (num_reg >= MAX_MOVE_REG)
6373 {
6374 for (i = 0; i < num_reg; i++)
6375 emit_insn (stores[i]);
6376 num_reg = 0;
7e69e155
MM
6377 }
6378 }
3933e0e1 6379
b6c9286a
MM
6380 for (i = 0; i < num_reg; i++)
6381 emit_insn (stores[i]);
7e69e155
MM
6382 }
6383
6384 return 1;
6385}
6386
9878760c
RK
6387\f
6388/* Return 1 if OP is a load multiple operation. It is known to be a
6389 PARALLEL and the first section will be tested. */
6390
6391int
6392load_multiple_operation (op, mode)
6393 rtx op;
296b8152 6394 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6395{
6396 int count = XVECLEN (op, 0);
e2c953b6 6397 unsigned int dest_regno;
9878760c
RK
6398 rtx src_addr;
6399 int i;
6400
6401 /* Perform a quick check so we don't blow up below. */
6402 if (count <= 1
6403 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6404 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
6405 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
6406 return 0;
6407
6408 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6409 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
6410
6411 for (i = 1; i < count; i++)
6412 {
6413 rtx elt = XVECEXP (op, 0, i);
6414
6415 if (GET_CODE (elt) != SET
6416 || GET_CODE (SET_DEST (elt)) != REG
6417 || GET_MODE (SET_DEST (elt)) != SImode
6418 || REGNO (SET_DEST (elt)) != dest_regno + i
6419 || GET_CODE (SET_SRC (elt)) != MEM
6420 || GET_MODE (SET_SRC (elt)) != SImode
6421 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
6422 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
6423 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
6424 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
6425 return 0;
6426 }
6427
6428 return 1;
6429}
6430
6431/* Similar, but tests for store multiple. Here, the second vector element
6432 is a CLOBBER. It will be tested later. */
6433
6434int
6435store_multiple_operation (op, mode)
6436 rtx op;
296b8152 6437 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6438{
6439 int count = XVECLEN (op, 0) - 1;
e2c953b6 6440 unsigned int src_regno;
9878760c
RK
6441 rtx dest_addr;
6442 int i;
6443
6444 /* Perform a quick check so we don't blow up below. */
6445 if (count <= 1
6446 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6447 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
6448 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
6449 return 0;
6450
6451 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6452 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
6453
6454 for (i = 1; i < count; i++)
6455 {
6456 rtx elt = XVECEXP (op, 0, i + 1);
6457
6458 if (GET_CODE (elt) != SET
6459 || GET_CODE (SET_SRC (elt)) != REG
6460 || GET_MODE (SET_SRC (elt)) != SImode
6461 || REGNO (SET_SRC (elt)) != src_regno + i
6462 || GET_CODE (SET_DEST (elt)) != MEM
6463 || GET_MODE (SET_DEST (elt)) != SImode
6464 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
6465 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
6466 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
6467 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
6468 return 0;
6469 }
6470
6471 return 1;
6472}
9ebbca7d 6473
9caa3eb2
DE
6474/* Return a string to perform a load_multiple operation.
6475 operands[0] is the vector.
6476 operands[1] is the source address.
6477 operands[2] is the first destination register. */
6478
6479const char *
6480rs6000_output_load_multiple (operands)
ebe637e3 6481 rtx operands[3];
9caa3eb2
DE
6482{
6483 /* We have to handle the case where the pseudo used to contain the address
6484 is assigned to one of the output registers. */
6485 int i, j;
6486 int words = XVECLEN (operands[0], 0);
6487 rtx xop[10];
6488
6489 if (XVECLEN (operands[0], 0) == 1)
6490 return "{l|lwz} %2,0(%1)";
6491
6492 for (i = 0; i < words; i++)
6493 if (refers_to_regno_p (REGNO (operands[2]) + i,
6494 REGNO (operands[2]) + i + 1, operands[1], 0))
6495 {
6496 if (i == words-1)
6497 {
6498 xop[0] = GEN_INT (4 * (words-1));
6499 xop[1] = operands[1];
6500 xop[2] = operands[2];
6501 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
6502 return "";
6503 }
6504 else if (i == 0)
6505 {
6506 xop[0] = GEN_INT (4 * (words-1));
6507 xop[1] = operands[1];
6508 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
6509 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);
6510 return "";
6511 }
6512 else
6513 {
6514 for (j = 0; j < words; j++)
6515 if (j != i)
6516 {
6517 xop[0] = GEN_INT (j * 4);
6518 xop[1] = operands[1];
6519 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
6520 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
6521 }
6522 xop[0] = GEN_INT (i * 4);
6523 xop[1] = operands[1];
6524 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
6525 return "";
6526 }
6527 }
6528
6529 return "{lsi|lswi} %2,%1,%N0";
6530}
6531
00b960c7
AH
6532/* Return 1 for a parallel vrsave operation. */
6533
6534int
6535vrsave_operation (op, mode)
6536 rtx op;
6537 enum machine_mode mode ATTRIBUTE_UNUSED;
6538{
6539 int count = XVECLEN (op, 0);
6540 unsigned int dest_regno, src_regno;
6541 int i;
6542
6543 if (count <= 1
6544 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6545 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 6546 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
6547 return 0;
6548
6549 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6550 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6551
6552 if (dest_regno != VRSAVE_REGNO
6553 && src_regno != VRSAVE_REGNO)
6554 return 0;
6555
6556 for (i = 1; i < count; i++)
6557 {
6558 rtx elt = XVECEXP (op, 0, i);
6559
9aa86737
AH
6560 if (GET_CODE (elt) != CLOBBER
6561 && GET_CODE (elt) != SET)
00b960c7
AH
6562 return 0;
6563 }
6564
6565 return 1;
6566}
6567
a4f6c312 6568/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
6569
6570int
6571mtcrf_operation (op, mode)
6572 rtx op;
6573 enum machine_mode mode ATTRIBUTE_UNUSED;
6574{
6575 int count = XVECLEN (op, 0);
6576 int i;
9ebbca7d
GK
6577 rtx src_reg;
6578
6579 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
6580 if (count < 1
6581 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6582 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
6583 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 6584 return 0;
e35b9579 6585 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
6586
6587 if (GET_CODE (src_reg) != REG
6588 || GET_MODE (src_reg) != SImode
6589 || ! INT_REGNO_P (REGNO (src_reg)))
6590 return 0;
6591
e35b9579 6592 for (i = 0; i < count; i++)
9ebbca7d
GK
6593 {
6594 rtx exp = XVECEXP (op, 0, i);
6595 rtx unspec;
6596 int maskval;
6597
6598 if (GET_CODE (exp) != SET
6599 || GET_CODE (SET_DEST (exp)) != REG
6600 || GET_MODE (SET_DEST (exp)) != CCmode
6601 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
6602 return 0;
6603 unspec = SET_SRC (exp);
6604 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
6605
6606 if (GET_CODE (unspec) != UNSPEC
6607 || XINT (unspec, 1) != 20
6608 || XVECLEN (unspec, 0) != 2
6609 || XVECEXP (unspec, 0, 0) != src_reg
6610 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
6611 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
6612 return 0;
6613 }
e35b9579 6614 return 1;
9ebbca7d
GK
6615}
6616
a4f6c312 6617/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
6618
6619int
6620lmw_operation (op, mode)
6621 rtx op;
6622 enum machine_mode mode ATTRIBUTE_UNUSED;
6623{
6624 int count = XVECLEN (op, 0);
e2c953b6 6625 unsigned int dest_regno;
9ebbca7d 6626 rtx src_addr;
e2c953b6 6627 unsigned int base_regno;
9ebbca7d
GK
6628 HOST_WIDE_INT offset;
6629 int i;
6630
6631 /* Perform a quick check so we don't blow up below. */
6632 if (count <= 1
6633 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6634 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
6635 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
6636 return 0;
6637
6638 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
6639 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
6640
6641 if (dest_regno > 31
e2c953b6 6642 || count != 32 - (int) dest_regno)
9ebbca7d
GK
6643 return 0;
6644
258bfae2 6645 if (LEGITIMATE_INDIRECT_ADDRESS_P (src_addr, 0))
9ebbca7d
GK
6646 {
6647 offset = 0;
6648 base_regno = REGNO (src_addr);
6649 if (base_regno == 0)
6650 return 0;
6651 }
258bfae2 6652 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, src_addr, 0))
9ebbca7d
GK
6653 {
6654 offset = INTVAL (XEXP (src_addr, 1));
6655 base_regno = REGNO (XEXP (src_addr, 0));
6656 }
6657 else
6658 return 0;
6659
6660 for (i = 0; i < count; i++)
6661 {
6662 rtx elt = XVECEXP (op, 0, i);
6663 rtx newaddr;
6664 rtx addr_reg;
6665 HOST_WIDE_INT newoffset;
6666
6667 if (GET_CODE (elt) != SET
6668 || GET_CODE (SET_DEST (elt)) != REG
6669 || GET_MODE (SET_DEST (elt)) != SImode
6670 || REGNO (SET_DEST (elt)) != dest_regno + i
6671 || GET_CODE (SET_SRC (elt)) != MEM
6672 || GET_MODE (SET_SRC (elt)) != SImode)
6673 return 0;
6674 newaddr = XEXP (SET_SRC (elt), 0);
258bfae2 6675 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
6676 {
6677 newoffset = 0;
6678 addr_reg = newaddr;
6679 }
258bfae2 6680 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
6681 {
6682 addr_reg = XEXP (newaddr, 0);
6683 newoffset = INTVAL (XEXP (newaddr, 1));
6684 }
6685 else
6686 return 0;
6687 if (REGNO (addr_reg) != base_regno
6688 || newoffset != offset + 4 * i)
6689 return 0;
6690 }
6691
6692 return 1;
6693}
6694
a4f6c312 6695/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
6696
6697int
6698stmw_operation (op, mode)
6699 rtx op;
6700 enum machine_mode mode ATTRIBUTE_UNUSED;
6701{
6702 int count = XVECLEN (op, 0);
e2c953b6 6703 unsigned int src_regno;
9ebbca7d 6704 rtx dest_addr;
e2c953b6 6705 unsigned int base_regno;
9ebbca7d
GK
6706 HOST_WIDE_INT offset;
6707 int i;
6708
6709 /* Perform a quick check so we don't blow up below. */
6710 if (count <= 1
6711 || GET_CODE (XVECEXP (op, 0, 0)) != SET
6712 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
6713 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
6714 return 0;
6715
6716 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
6717 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
6718
6719 if (src_regno > 31
e2c953b6 6720 || count != 32 - (int) src_regno)
9ebbca7d
GK
6721 return 0;
6722
258bfae2 6723 if (LEGITIMATE_INDIRECT_ADDRESS_P (dest_addr, 0))
9ebbca7d
GK
6724 {
6725 offset = 0;
6726 base_regno = REGNO (dest_addr);
6727 if (base_regno == 0)
6728 return 0;
6729 }
258bfae2 6730 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, dest_addr, 0))
9ebbca7d
GK
6731 {
6732 offset = INTVAL (XEXP (dest_addr, 1));
6733 base_regno = REGNO (XEXP (dest_addr, 0));
6734 }
6735 else
6736 return 0;
6737
6738 for (i = 0; i < count; i++)
6739 {
6740 rtx elt = XVECEXP (op, 0, i);
6741 rtx newaddr;
6742 rtx addr_reg;
6743 HOST_WIDE_INT newoffset;
6744
6745 if (GET_CODE (elt) != SET
6746 || GET_CODE (SET_SRC (elt)) != REG
6747 || GET_MODE (SET_SRC (elt)) != SImode
6748 || REGNO (SET_SRC (elt)) != src_regno + i
6749 || GET_CODE (SET_DEST (elt)) != MEM
6750 || GET_MODE (SET_DEST (elt)) != SImode)
6751 return 0;
6752 newaddr = XEXP (SET_DEST (elt), 0);
258bfae2 6753 if (LEGITIMATE_INDIRECT_ADDRESS_P (newaddr, 0))
9ebbca7d
GK
6754 {
6755 newoffset = 0;
6756 addr_reg = newaddr;
6757 }
258bfae2 6758 else if (LEGITIMATE_OFFSET_ADDRESS_P (SImode, newaddr, 0))
9ebbca7d
GK
6759 {
6760 addr_reg = XEXP (newaddr, 0);
6761 newoffset = INTVAL (XEXP (newaddr, 1));
6762 }
6763 else
6764 return 0;
6765 if (REGNO (addr_reg) != base_regno
6766 || newoffset != offset + 4 * i)
6767 return 0;
6768 }
6769
6770 return 1;
6771}
9878760c 6772\f
a4f6c312
SS
6773/* A validation routine: say whether CODE, a condition code, and MODE
6774 match. The other alternatives either don't make sense or should
6775 never be generated. */
39a10a29 6776
39a10a29
GK
6777static void
6778validate_condition_mode (code, mode)
6779 enum rtx_code code;
6780 enum machine_mode mode;
6781{
6782 if (GET_RTX_CLASS (code) != '<'
6783 || GET_MODE_CLASS (mode) != MODE_CC)
6784 abort ();
6785
6786 /* These don't make sense. */
6787 if ((code == GT || code == LT || code == GE || code == LE)
6788 && mode == CCUNSmode)
6789 abort ();
6790
6791 if ((code == GTU || code == LTU || code == GEU || code == LEU)
6792 && mode != CCUNSmode)
6793 abort ();
6794
6795 if (mode != CCFPmode
6796 && (code == ORDERED || code == UNORDERED
6797 || code == UNEQ || code == LTGT
6798 || code == UNGT || code == UNLT
6799 || code == UNGE || code == UNLE))
a4f6c312 6800 abort ();
39a10a29 6801
de6c5979 6802 /* These should never be generated except for
ad72b533 6803 flag_unsafe_math_optimizations and flag_finite_math_only. */
39a10a29 6804 if (mode == CCFPmode
de6c5979 6805 && ! flag_unsafe_math_optimizations
ad72b533 6806 && ! flag_finite_math_only
39a10a29
GK
6807 && (code == LE || code == GE
6808 || code == UNEQ || code == LTGT
6809 || code == UNGT || code == UNLT))
6810 abort ();
6811
6812 /* These are invalid; the information is not there. */
6813 if (mode == CCEQmode
6814 && code != EQ && code != NE)
6815 abort ();
6816}
6817
9878760c
RK
6818/* Return 1 if OP is a comparison operation that is valid for a branch insn.
6819 We only check the opcode against the mode of the CC value here. */
6820
6821int
6822branch_comparison_operator (op, mode)
592696dd 6823 rtx op;
296b8152 6824 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
6825{
6826 enum rtx_code code = GET_CODE (op);
6827 enum machine_mode cc_mode;
6828
6829 if (GET_RTX_CLASS (code) != '<')
6830 return 0;
6831
6832 cc_mode = GET_MODE (XEXP (op, 0));
6833 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
6834 return 0;
6835
39a10a29 6836 validate_condition_mode (code, cc_mode);
9878760c 6837
39a10a29
GK
6838 return 1;
6839}
6840
6841/* Return 1 if OP is a comparison operation that is valid for a branch
6842 insn and which is true if the corresponding bit in the CC register
6843 is set. */
6844
6845int
6846branch_positive_comparison_operator (op, mode)
592696dd 6847 rtx op;
39a10a29
GK
6848 enum machine_mode mode;
6849{
6850 enum rtx_code code;
6851
6852 if (! branch_comparison_operator (op, mode))
9878760c
RK
6853 return 0;
6854
39a10a29
GK
6855 code = GET_CODE (op);
6856 return (code == EQ || code == LT || code == GT
a3170dc6 6857 || (TARGET_SPE && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
6858 || code == LTU || code == GTU
6859 || code == UNORDERED);
9878760c
RK
6860}
6861
6862/* Return 1 if OP is a comparison operation that is valid for an scc insn.
6863 We check the opcode against the mode of the CC value and disallow EQ or
6864 NE comparisons for integers. */
6865
6866int
6867scc_comparison_operator (op, mode)
592696dd 6868 rtx op;
9878760c
RK
6869 enum machine_mode mode;
6870{
6871 enum rtx_code code = GET_CODE (op);
6872 enum machine_mode cc_mode;
6873
6874 if (GET_MODE (op) != mode && mode != VOIDmode)
6875 return 0;
6876
6877 if (GET_RTX_CLASS (code) != '<')
6878 return 0;
6879
6880 cc_mode = GET_MODE (XEXP (op, 0));
6881 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
6882 return 0;
6883
39a10a29 6884 validate_condition_mode (code, cc_mode);
9878760c 6885
39a10a29 6886 if (code == NE && cc_mode != CCFPmode)
c5defebb
RK
6887 return 0;
6888
9878760c
RK
6889 return 1;
6890}
e0cd0770
JC
6891
6892int
6893trap_comparison_operator (op, mode)
6894 rtx op;
6895 enum machine_mode mode;
6896{
6897 if (mode != VOIDmode && mode != GET_MODE (op))
6898 return 0;
39a10a29 6899 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 6900}
dfbdccdb
GK
6901
6902int
6903boolean_operator (op, mode)
6904 rtx op;
6905 enum machine_mode mode ATTRIBUTE_UNUSED;
6906{
6907 enum rtx_code code = GET_CODE (op);
6908 return (code == AND || code == IOR || code == XOR);
6909}
1d328b19
GK
6910
6911int
6912boolean_or_operator (op, mode)
6913 rtx op;
6914 enum machine_mode mode ATTRIBUTE_UNUSED;
6915{
6916 enum rtx_code code = GET_CODE (op);
6917 return (code == IOR || code == XOR);
6918}
50a0b056
GK
6919
6920int
6921min_max_operator (op, mode)
6922 rtx op;
6923 enum machine_mode mode ATTRIBUTE_UNUSED;
6924{
6925 enum rtx_code code = GET_CODE (op);
6926 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
6927}
9878760c
RK
6928\f
6929/* Return 1 if ANDOP is a mask that has no bits on that are not in the
6930 mask required to convert the result of a rotate insn into a shift
b1765bde 6931 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
6932
6933int
6934includes_lshift_p (shiftop, andop)
592696dd
SS
6935 rtx shiftop;
6936 rtx andop;
9878760c 6937{
e2c953b6
DE
6938 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
6939
6940 shift_mask <<= INTVAL (shiftop);
9878760c 6941
b1765bde 6942 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
6943}
6944
6945/* Similar, but for right shift. */
6946
6947int
6948includes_rshift_p (shiftop, andop)
592696dd
SS
6949 rtx shiftop;
6950 rtx andop;
9878760c 6951{
a7653a2c 6952 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
6953
6954 shift_mask >>= INTVAL (shiftop);
6955
b1765bde 6956 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
6957}
6958
c5059423
AM
6959/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
6960 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 6961 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
6962
6963int
c5059423 6964includes_rldic_lshift_p (shiftop, andop)
592696dd
SS
6965 rtx shiftop;
6966 rtx andop;
e2c953b6 6967{
c5059423
AM
6968 if (GET_CODE (andop) == CONST_INT)
6969 {
02071907 6970 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 6971
c5059423 6972 c = INTVAL (andop);
02071907 6973 if (c == 0 || c == ~0)
c5059423 6974 return 0;
e2c953b6 6975
02071907 6976 shift_mask = ~0;
c5059423
AM
6977 shift_mask <<= INTVAL (shiftop);
6978
b6d08ca1 6979 /* Find the least significant one bit. */
c5059423
AM
6980 lsb = c & -c;
6981
6982 /* It must coincide with the LSB of the shift mask. */
6983 if (-lsb != shift_mask)
6984 return 0;
e2c953b6 6985
c5059423
AM
6986 /* Invert to look for the next transition (if any). */
6987 c = ~c;
6988
6989 /* Remove the low group of ones (originally low group of zeros). */
6990 c &= -lsb;
6991
6992 /* Again find the lsb, and check we have all 1's above. */
6993 lsb = c & -c;
6994 return c == -lsb;
6995 }
6996 else if (GET_CODE (andop) == CONST_DOUBLE
6997 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
6998 {
02071907
AM
6999 HOST_WIDE_INT low, high, lsb;
7000 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
7001
7002 low = CONST_DOUBLE_LOW (andop);
7003 if (HOST_BITS_PER_WIDE_INT < 64)
7004 high = CONST_DOUBLE_HIGH (andop);
7005
7006 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 7007 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
7008 return 0;
7009
7010 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7011 {
02071907 7012 shift_mask_high = ~0;
c5059423
AM
7013 if (INTVAL (shiftop) > 32)
7014 shift_mask_high <<= INTVAL (shiftop) - 32;
7015
7016 lsb = high & -high;
7017
7018 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
7019 return 0;
7020
7021 high = ~high;
7022 high &= -lsb;
7023
7024 lsb = high & -high;
7025 return high == -lsb;
7026 }
7027
02071907 7028 shift_mask_low = ~0;
c5059423
AM
7029 shift_mask_low <<= INTVAL (shiftop);
7030
7031 lsb = low & -low;
7032
7033 if (-lsb != shift_mask_low)
7034 return 0;
7035
7036 if (HOST_BITS_PER_WIDE_INT < 64)
7037 high = ~high;
7038 low = ~low;
7039 low &= -lsb;
7040
7041 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
7042 {
7043 lsb = high & -high;
7044 return high == -lsb;
7045 }
7046
7047 lsb = low & -low;
7048 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
7049 }
7050 else
7051 return 0;
7052}
e2c953b6 7053
c5059423
AM
7054/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
7055 to perform a left shift. It must have SHIFTOP or more least
7056 signifigant 0's, with the remainder of the word 1's. */
e2c953b6 7057
c5059423
AM
7058int
7059includes_rldicr_lshift_p (shiftop, andop)
592696dd
SS
7060 rtx shiftop;
7061 rtx andop;
c5059423 7062{
e2c953b6 7063 if (GET_CODE (andop) == CONST_INT)
c5059423 7064 {
02071907 7065 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 7066
02071907 7067 shift_mask = ~0;
c5059423
AM
7068 shift_mask <<= INTVAL (shiftop);
7069 c = INTVAL (andop);
7070
7071 /* Find the least signifigant one bit. */
7072 lsb = c & -c;
7073
7074 /* It must be covered by the shift mask.
a4f6c312 7075 This test also rejects c == 0. */
c5059423
AM
7076 if ((lsb & shift_mask) == 0)
7077 return 0;
7078
7079 /* Check we have all 1's above the transition, and reject all 1's. */
7080 return c == -lsb && lsb != 1;
7081 }
7082 else if (GET_CODE (andop) == CONST_DOUBLE
7083 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
7084 {
02071907 7085 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
7086
7087 low = CONST_DOUBLE_LOW (andop);
7088
7089 if (HOST_BITS_PER_WIDE_INT < 64)
7090 {
02071907 7091 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
7092
7093 high = CONST_DOUBLE_HIGH (andop);
7094
7095 if (low == 0)
7096 {
02071907 7097 shift_mask_high = ~0;
c5059423
AM
7098 if (INTVAL (shiftop) > 32)
7099 shift_mask_high <<= INTVAL (shiftop) - 32;
7100
7101 lsb = high & -high;
7102
7103 if ((lsb & shift_mask_high) == 0)
7104 return 0;
7105
7106 return high == -lsb;
7107 }
7108 if (high != ~0)
7109 return 0;
7110 }
7111
02071907 7112 shift_mask_low = ~0;
c5059423
AM
7113 shift_mask_low <<= INTVAL (shiftop);
7114
7115 lsb = low & -low;
7116
7117 if ((lsb & shift_mask_low) == 0)
7118 return 0;
7119
7120 return low == -lsb && lsb != 1;
7121 }
e2c953b6 7122 else
c5059423 7123 return 0;
9878760c 7124}
35068b43
RK
7125
7126/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
7127 for lfq and stfq insns.
7128
7129 Note reg1 and reg2 *must* be hard registers. To be sure we will
7130 abort if we are passed pseudo registers. */
7131
7132int
7133registers_ok_for_quad_peep (reg1, reg2)
7134 rtx reg1, reg2;
7135{
7136 /* We might have been passed a SUBREG. */
7137 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
7138 return 0;
7139
7140 return (REGNO (reg1) == REGNO (reg2) - 1);
7141}
7142
a4f6c312
SS
7143/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
7144 addr1 and addr2 must be in consecutive memory locations
7145 (addr2 == addr1 + 8). */
35068b43
RK
7146
7147int
7148addrs_ok_for_quad_peep (addr1, addr2)
592696dd
SS
7149 rtx addr1;
7150 rtx addr2;
35068b43 7151{
e2c953b6 7152 unsigned int reg1;
35068b43
RK
7153 int offset1;
7154
7155 /* Extract an offset (if used) from the first addr. */
7156 if (GET_CODE (addr1) == PLUS)
7157 {
7158 /* If not a REG, return zero. */
7159 if (GET_CODE (XEXP (addr1, 0)) != REG)
7160 return 0;
7161 else
7162 {
7163 reg1 = REGNO (XEXP (addr1, 0));
7164 /* The offset must be constant! */
7165 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
7166 return 0;
7167 offset1 = INTVAL (XEXP (addr1, 1));
7168 }
7169 }
7170 else if (GET_CODE (addr1) != REG)
7171 return 0;
7172 else
7173 {
7174 reg1 = REGNO (addr1);
7175 /* This was a simple (mem (reg)) expression. Offset is 0. */
7176 offset1 = 0;
7177 }
7178
acad7ed3 7179 /* Make sure the second address is a (mem (plus (reg) (const_int))). */
35068b43
RK
7180 if (GET_CODE (addr2) != PLUS)
7181 return 0;
7182
7183 if (GET_CODE (XEXP (addr2, 0)) != REG
7184 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
7185 return 0;
7186
7187 if (reg1 != REGNO (XEXP (addr2, 0)))
7188 return 0;
7189
7190 /* The offset for the second addr must be 8 more than the first addr. */
7191 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
7192 return 0;
7193
7194 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
7195 instructions. */
7196 return 1;
7197}
9878760c
RK
7198\f
7199/* Return the register class of a scratch register needed to copy IN into
7200 or out of a register in CLASS in MODE. If it can be done directly,
7201 NO_REGS is returned. */
7202
7203enum reg_class
7204secondary_reload_class (class, mode, in)
7205 enum reg_class class;
296b8152 7206 enum machine_mode mode ATTRIBUTE_UNUSED;
9878760c
RK
7207 rtx in;
7208{
5accd822 7209 int regno;
9878760c 7210
46fad5b7
DJ
7211 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN && flag_pic))
7212 {
7213 /* We cannot copy a symbolic operand directly into anything
7214 other than BASE_REGS for TARGET_ELF. So indicate that a
7215 register from BASE_REGS is needed as an intermediate
7216 register.
7217
7218 On Darwin, pic addresses require a load from memory, which
7219 needs a base register. */
7220 if (class != BASE_REGS
7221 && (GET_CODE (in) == SYMBOL_REF
7222 || GET_CODE (in) == HIGH
7223 || GET_CODE (in) == LABEL_REF
7224 || GET_CODE (in) == CONST))
7225 return BASE_REGS;
7226 }
e7b7998a 7227
5accd822
DE
7228 if (GET_CODE (in) == REG)
7229 {
7230 regno = REGNO (in);
7231 if (regno >= FIRST_PSEUDO_REGISTER)
7232 {
7233 regno = true_regnum (in);
7234 if (regno >= FIRST_PSEUDO_REGISTER)
7235 regno = -1;
7236 }
7237 }
7238 else if (GET_CODE (in) == SUBREG)
7239 {
7240 regno = true_regnum (in);
7241 if (regno >= FIRST_PSEUDO_REGISTER)
7242 regno = -1;
7243 }
7244 else
7245 regno = -1;
7246
9878760c
RK
7247 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
7248 into anything. */
7249 if (class == GENERAL_REGS || class == BASE_REGS
7250 || (regno >= 0 && INT_REGNO_P (regno)))
7251 return NO_REGS;
7252
7253 /* Constants, memory, and FP registers can go into FP registers. */
7254 if ((regno == -1 || FP_REGNO_P (regno))
7255 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
7256 return NO_REGS;
7257
0ac081f6
AH
7258 /* Memory, and AltiVec registers can go into AltiVec registers. */
7259 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
7260 && class == ALTIVEC_REGS)
7261 return NO_REGS;
7262
9878760c
RK
7263 /* We can copy among the CR registers. */
7264 if ((class == CR_REGS || class == CR0_REGS)
7265 && regno >= 0 && CR_REGNO_P (regno))
7266 return NO_REGS;
7267
7268 /* Otherwise, we need GENERAL_REGS. */
7269 return GENERAL_REGS;
7270}
7271\f
7272/* Given a comparison operation, return the bit number in CCR to test. We
7273 know this is a valid comparison.
7274
7275 SCC_P is 1 if this is for an scc. That means that %D will have been
7276 used instead of %C, so the bits will be in different places.
7277
b4ac57ab 7278 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
7279
7280int
7281ccr_bit (op, scc_p)
592696dd 7282 rtx op;
9878760c
RK
7283 int scc_p;
7284{
7285 enum rtx_code code = GET_CODE (op);
7286 enum machine_mode cc_mode;
7287 int cc_regnum;
7288 int base_bit;
9ebbca7d 7289 rtx reg;
9878760c
RK
7290
7291 if (GET_RTX_CLASS (code) != '<')
7292 return -1;
7293
9ebbca7d
GK
7294 reg = XEXP (op, 0);
7295
7296 if (GET_CODE (reg) != REG
7297 || ! CR_REGNO_P (REGNO (reg)))
7298 abort ();
7299
7300 cc_mode = GET_MODE (reg);
7301 cc_regnum = REGNO (reg);
7302 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 7303
39a10a29 7304 validate_condition_mode (code, cc_mode);
c5defebb 7305
9878760c
RK
7306 switch (code)
7307 {
7308 case NE:
a3170dc6
AH
7309 if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
7310 return base_bit + 1;
9878760c
RK
7311 return scc_p ? base_bit + 3 : base_bit + 2;
7312 case EQ:
a3170dc6
AH
7313 if (TARGET_SPE && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
7314 return base_bit + 1;
9878760c 7315 return base_bit + 2;
1c882ea4 7316 case GT: case GTU: case UNLE:
9878760c 7317 return base_bit + 1;
1c882ea4 7318 case LT: case LTU: case UNGE:
9878760c 7319 return base_bit;
1c882ea4
GK
7320 case ORDERED: case UNORDERED:
7321 return base_bit + 3;
9878760c
RK
7322
7323 case GE: case GEU:
39a10a29 7324 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
7325 unordered position. So test that bit. For integer, this is ! LT
7326 unless this is an scc insn. */
39a10a29 7327 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
7328
7329 case LE: case LEU:
39a10a29 7330 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 7331
9878760c
RK
7332 default:
7333 abort ();
7334 }
7335}
1ff7789b 7336\f
8d30c4ee 7337/* Return the GOT register. */
1ff7789b
MM
7338
7339struct rtx_def *
7340rs6000_got_register (value)
5f59ecb7 7341 rtx value ATTRIBUTE_UNUSED;
1ff7789b 7342{
a4f6c312
SS
7343 /* The second flow pass currently (June 1999) can't update
7344 regs_ever_live without disturbing other parts of the compiler, so
7345 update it here to make the prolog/epilogue code happy. */
1db02437
FS
7346 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
7347 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 7348
8d30c4ee 7349 current_function_uses_pic_offset_table = 1;
3cb999d8 7350
1ff7789b
MM
7351 return pic_offset_table_rtx;
7352}
a7df97e6 7353\f
e2500fed
GK
7354/* Function to init struct machine_function.
7355 This will be called, via a pointer variable,
7356 from push_function_context. */
a7df97e6 7357
e2500fed
GK
7358static struct machine_function *
7359rs6000_init_machine_status ()
a7df97e6 7360{
e2500fed 7361 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 7362}
9878760c 7363\f
0ba1b2ff
AM
7364/* These macros test for integers and extract the low-order bits. */
7365#define INT_P(X) \
7366((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
7367 && GET_MODE (X) == VOIDmode)
7368
7369#define INT_LOWPART(X) \
7370 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
7371
7372int
7373extract_MB (op)
7374 rtx op;
7375{
7376 int i;
7377 unsigned long val = INT_LOWPART (op);
7378
7379 /* If the high bit is zero, the value is the first 1 bit we find
7380 from the left. */
7381 if ((val & 0x80000000) == 0)
7382 {
7383 if ((val & 0xffffffff) == 0)
7384 abort ();
7385
7386 i = 1;
7387 while (((val <<= 1) & 0x80000000) == 0)
7388 ++i;
7389 return i;
7390 }
7391
7392 /* If the high bit is set and the low bit is not, or the mask is all
7393 1's, the value is zero. */
7394 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
7395 return 0;
7396
7397 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
7398 from the right. */
7399 i = 31;
7400 while (((val >>= 1) & 1) != 0)
7401 --i;
7402
7403 return i;
7404}
7405
7406int
7407extract_ME (op)
7408 rtx op;
7409{
7410 int i;
7411 unsigned long val = INT_LOWPART (op);
7412
7413 /* If the low bit is zero, the value is the first 1 bit we find from
7414 the right. */
7415 if ((val & 1) == 0)
7416 {
7417 if ((val & 0xffffffff) == 0)
7418 abort ();
7419
7420 i = 30;
7421 while (((val >>= 1) & 1) == 0)
7422 --i;
7423
7424 return i;
7425 }
7426
7427 /* If the low bit is set and the high bit is not, or the mask is all
7428 1's, the value is 31. */
7429 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
7430 return 31;
7431
7432 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
7433 from the left. */
7434 i = 0;
7435 while (((val <<= 1) & 0x80000000) != 0)
7436 ++i;
7437
7438 return i;
7439}
7440
9878760c
RK
7441/* Print an operand. Recognize special options, documented below. */
7442
38c1f2d7 7443#if TARGET_ELF
d9407988 7444#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 7445#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
7446#else
7447#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 7448#define SMALL_DATA_REG 0
ba5e43aa
MM
7449#endif
7450
9878760c
RK
7451void
7452print_operand (file, x, code)
7453 FILE *file;
7454 rtx x;
9ebbca7d 7455 int code;
9878760c
RK
7456{
7457 int i;
a260abc9 7458 HOST_WIDE_INT val;
0ba1b2ff 7459 unsigned HOST_WIDE_INT uval;
9878760c
RK
7460
7461 switch (code)
7462 {
a8b3aeda 7463 case '.':
a85d226b
RK
7464 /* Write out an instruction after the call which may be replaced
7465 with glue code by the loader. This depends on the AIX version. */
7466 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
7467 return;
7468
81eace42
GK
7469 /* %a is output_address. */
7470
9854d9ed
RK
7471 case 'A':
7472 /* If X is a constant integer whose low-order 5 bits are zero,
7473 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 7474 in the AIX assembler where "sri" with a zero shift count
20e26713 7475 writes a trash instruction. */
9854d9ed 7476 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 7477 putc ('l', file);
9854d9ed 7478 else
76229ac8 7479 putc ('r', file);
9854d9ed
RK
7480 return;
7481
7482 case 'b':
e2c953b6
DE
7483 /* If constant, low-order 16 bits of constant, unsigned.
7484 Otherwise, write normally. */
7485 if (INT_P (x))
7486 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
7487 else
7488 print_operand (file, x, 0);
cad12a8d
RK
7489 return;
7490
a260abc9
DE
7491 case 'B':
7492 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
7493 for 64-bit mask direction. */
296b8152 7494 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 7495 return;
a260abc9 7496
81eace42
GK
7497 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
7498 output_operand. */
7499
9854d9ed 7500 case 'D':
39a10a29
GK
7501 /* There used to be a comment for 'C' reading "This is an
7502 optional cror needed for certain floating-point
7503 comparisons. Otherwise write nothing." */
7504
9854d9ed
RK
7505 /* Similar, except that this is for an scc, so we must be able to
7506 encode the test in a single bit that is one. We do the above
7507 for any LE, GE, GEU, or LEU and invert the bit for NE. */
7508 if (GET_CODE (x) == LE || GET_CODE (x) == GE
7509 || GET_CODE (x) == LEU || GET_CODE (x) == GEU)
7510 {
9ebbca7d 7511 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
7512
7513 fprintf (file, "cror %d,%d,%d\n\t", base_bit + 3,
7514 base_bit + 2,
7515 base_bit + (GET_CODE (x) == GE || GET_CODE (x) == GEU));
7516 }
7517
7518 else if (GET_CODE (x) == NE)
7519 {
9ebbca7d 7520 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
9854d9ed
RK
7521
7522 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 3,
7523 base_bit + 2, base_bit + 2);
7524 }
a3170dc6
AH
7525 else if (TARGET_SPE && TARGET_HARD_FLOAT
7526 && GET_CODE (x) == EQ
7527 && GET_MODE (XEXP (x, 0)) == CCFPmode)
7528 {
7529 int base_bit = 4 * (REGNO (XEXP (x, 0)) - CR0_REGNO);
7530
7531 fprintf (file, "crnor %d,%d,%d\n\t", base_bit + 1,
7532 base_bit + 1, base_bit + 1);
7533 }
9854d9ed
RK
7534 return;
7535
7536 case 'E':
39a10a29 7537 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
7538 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7539 output_operand_lossage ("invalid %%E value");
78fbdbf7 7540 else
39a10a29 7541 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 7542 return;
9854d9ed
RK
7543
7544 case 'f':
7545 /* X is a CR register. Print the shift count needed to move it
7546 to the high-order four bits. */
7547 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7548 output_operand_lossage ("invalid %%f value");
7549 else
9ebbca7d 7550 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
7551 return;
7552
7553 case 'F':
7554 /* Similar, but print the count for the rotate in the opposite
7555 direction. */
7556 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7557 output_operand_lossage ("invalid %%F value");
7558 else
9ebbca7d 7559 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
7560 return;
7561
7562 case 'G':
7563 /* X is a constant integer. If it is negative, print "m",
43aa4e05 7564 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
7565 if (GET_CODE (x) != CONST_INT)
7566 output_operand_lossage ("invalid %%G value");
7567 else if (INTVAL (x) >= 0)
76229ac8 7568 putc ('z', file);
9854d9ed 7569 else
76229ac8 7570 putc ('m', file);
9854d9ed 7571 return;
e2c953b6 7572
9878760c 7573 case 'h':
a4f6c312
SS
7574 /* If constant, output low-order five bits. Otherwise, write
7575 normally. */
9878760c 7576 if (INT_P (x))
5f59ecb7 7577 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
7578 else
7579 print_operand (file, x, 0);
7580 return;
7581
64305719 7582 case 'H':
a4f6c312
SS
7583 /* If constant, output low-order six bits. Otherwise, write
7584 normally. */
64305719 7585 if (INT_P (x))
5f59ecb7 7586 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
7587 else
7588 print_operand (file, x, 0);
7589 return;
7590
9854d9ed
RK
7591 case 'I':
7592 /* Print `i' if this is a constant, else nothing. */
9878760c 7593 if (INT_P (x))
76229ac8 7594 putc ('i', file);
9878760c
RK
7595 return;
7596
9854d9ed
RK
7597 case 'j':
7598 /* Write the bit number in CCR for jump. */
7599 i = ccr_bit (x, 0);
7600 if (i == -1)
7601 output_operand_lossage ("invalid %%j code");
9878760c 7602 else
9854d9ed 7603 fprintf (file, "%d", i);
9878760c
RK
7604 return;
7605
9854d9ed
RK
7606 case 'J':
7607 /* Similar, but add one for shift count in rlinm for scc and pass
7608 scc flag to `ccr_bit'. */
7609 i = ccr_bit (x, 1);
7610 if (i == -1)
7611 output_operand_lossage ("invalid %%J code");
7612 else
a0466a68
RK
7613 /* If we want bit 31, write a shift count of zero, not 32. */
7614 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
7615 return;
7616
9854d9ed
RK
7617 case 'k':
7618 /* X must be a constant. Write the 1's complement of the
7619 constant. */
9878760c 7620 if (! INT_P (x))
9854d9ed 7621 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
7622 else
7623 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
7624 return;
7625
81eace42 7626 case 'K':
9ebbca7d
GK
7627 /* X must be a symbolic constant on ELF. Write an
7628 expression suitable for an 'addi' that adds in the low 16
7629 bits of the MEM. */
7630 if (GET_CODE (x) != CONST)
7631 {
7632 print_operand_address (file, x);
7633 fputs ("@l", file);
7634 }
7635 else
7636 {
7637 if (GET_CODE (XEXP (x, 0)) != PLUS
7638 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
7639 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
7640 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 7641 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
7642 print_operand_address (file, XEXP (XEXP (x, 0), 0));
7643 fputs ("@l", file);
ed8d2920
MM
7644 /* For GNU as, there must be a non-alphanumeric character
7645 between 'l' and the number. The '-' is added by
7646 print_operand() already. */
7647 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
7648 fputs ("+", file);
9ebbca7d
GK
7649 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
7650 }
81eace42
GK
7651 return;
7652
7653 /* %l is output_asm_label. */
9ebbca7d 7654
9854d9ed
RK
7655 case 'L':
7656 /* Write second word of DImode or DFmode reference. Works on register
7657 or non-indexed memory only. */
7658 if (GET_CODE (x) == REG)
5ebfb2ba 7659 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
7660 else if (GET_CODE (x) == MEM)
7661 {
7662 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 7663 we have already done it, we can just use an offset of word. */
9854d9ed
RK
7664 if (GET_CODE (XEXP (x, 0)) == PRE_INC
7665 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
7666 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
7667 UNITS_PER_WORD));
9854d9ed 7668 else
d7624dc0
RK
7669 output_address (XEXP (adjust_address_nv (x, SImode,
7670 UNITS_PER_WORD),
7671 0));
ed8908e7 7672
ba5e43aa 7673 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
7674 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
7675 reg_names[SMALL_DATA_REG]);
9854d9ed 7676 }
9878760c 7677 return;
9854d9ed 7678
9878760c
RK
7679 case 'm':
7680 /* MB value for a mask operand. */
b1765bde 7681 if (! mask_operand (x, SImode))
9878760c
RK
7682 output_operand_lossage ("invalid %%m value");
7683
0ba1b2ff 7684 fprintf (file, "%d", extract_MB (x));
9878760c
RK
7685 return;
7686
7687 case 'M':
7688 /* ME value for a mask operand. */
b1765bde 7689 if (! mask_operand (x, SImode))
a260abc9 7690 output_operand_lossage ("invalid %%M value");
9878760c 7691
0ba1b2ff 7692 fprintf (file, "%d", extract_ME (x));
9878760c
RK
7693 return;
7694
81eace42
GK
7695 /* %n outputs the negative of its operand. */
7696
9878760c
RK
7697 case 'N':
7698 /* Write the number of elements in the vector times 4. */
7699 if (GET_CODE (x) != PARALLEL)
7700 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
7701 else
7702 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
7703 return;
7704
7705 case 'O':
7706 /* Similar, but subtract 1 first. */
7707 if (GET_CODE (x) != PARALLEL)
1427100a 7708 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
7709 else
7710 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
7711 return;
7712
9854d9ed
RK
7713 case 'p':
7714 /* X is a CONST_INT that is a power of two. Output the logarithm. */
7715 if (! INT_P (x)
2bfcf297 7716 || INT_LOWPART (x) < 0
9854d9ed
RK
7717 || (i = exact_log2 (INT_LOWPART (x))) < 0)
7718 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
7719 else
7720 fprintf (file, "%d", i);
9854d9ed
RK
7721 return;
7722
9878760c
RK
7723 case 'P':
7724 /* The operand must be an indirect memory reference. The result
a4f6c312 7725 is the register number. */
9878760c
RK
7726 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
7727 || REGNO (XEXP (x, 0)) >= 32)
7728 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
7729 else
7730 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
7731 return;
7732
dfbdccdb
GK
7733 case 'q':
7734 /* This outputs the logical code corresponding to a boolean
7735 expression. The expression may have one or both operands
39a10a29
GK
7736 negated (if one, only the first one). For condition register
7737 logical operations, it will also treat the negated
7738 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 7739 {
63bc1d05 7740 const char *const *t = 0;
dfbdccdb
GK
7741 const char *s;
7742 enum rtx_code code = GET_CODE (x);
7743 static const char * const tbl[3][3] = {
7744 { "and", "andc", "nor" },
7745 { "or", "orc", "nand" },
7746 { "xor", "eqv", "xor" } };
7747
7748 if (code == AND)
7749 t = tbl[0];
7750 else if (code == IOR)
7751 t = tbl[1];
7752 else if (code == XOR)
7753 t = tbl[2];
7754 else
7755 output_operand_lossage ("invalid %%q value");
7756
7757 if (GET_CODE (XEXP (x, 0)) != NOT)
7758 s = t[0];
7759 else
7760 {
7761 if (GET_CODE (XEXP (x, 1)) == NOT)
7762 s = t[2];
7763 else
7764 s = t[1];
7765 }
7766
7767 fputs (s, file);
7768 }
7769 return;
7770
9854d9ed
RK
7771 case 'R':
7772 /* X is a CR register. Print the mask for `mtcrf'. */
7773 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
7774 output_operand_lossage ("invalid %%R value");
7775 else
9ebbca7d 7776 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 7777 return;
9854d9ed
RK
7778
7779 case 's':
7780 /* Low 5 bits of 32 - value */
7781 if (! INT_P (x))
7782 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
7783 else
7784 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 7785 return;
9854d9ed 7786
a260abc9 7787 case 'S':
0ba1b2ff 7788 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
7789 CONST_INT 32-bit mask is considered sign-extended so any
7790 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 7791 if (! mask64_operand (x, DImode))
a260abc9
DE
7792 output_operand_lossage ("invalid %%S value");
7793
0ba1b2ff 7794 uval = INT_LOWPART (x);
a260abc9 7795
0ba1b2ff 7796 if (uval & 1) /* Clear Left */
a260abc9 7797 {
f099d360
GK
7798#if HOST_BITS_PER_WIDE_INT > 64
7799 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
7800#endif
0ba1b2ff 7801 i = 64;
a260abc9 7802 }
0ba1b2ff 7803 else /* Clear Right */
a260abc9 7804 {
0ba1b2ff 7805 uval = ~uval;
f099d360
GK
7806#if HOST_BITS_PER_WIDE_INT > 64
7807 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
7808#endif
0ba1b2ff 7809 i = 63;
a260abc9 7810 }
0ba1b2ff
AM
7811 while (uval != 0)
7812 --i, uval >>= 1;
7813 if (i < 0)
7814 abort ();
7815 fprintf (file, "%d", i);
7816 return;
a260abc9 7817
a3170dc6
AH
7818 case 't':
7819 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
7820 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
7821 abort ();
7822
7823 /* Bit 3 is OV bit. */
7824 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
7825
7826 /* If we want bit 31, write a shift count of zero, not 32. */
7827 fprintf (file, "%d", i == 31 ? 0 : i + 1);
7828 return;
7829
cccf3bdc
DE
7830 case 'T':
7831 /* Print the symbolic name of a branch target register. */
7832 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
7833 && REGNO (x) != COUNT_REGISTER_REGNUM))
7834 output_operand_lossage ("invalid %%T value");
e2c953b6 7835 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
7836 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
7837 else
7838 fputs ("ctr", file);
7839 return;
7840
9854d9ed 7841 case 'u':
802a0058 7842 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
7843 if (! INT_P (x))
7844 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
7845 else
7846 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
7847 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
7848 return;
7849
802a0058
MM
7850 case 'v':
7851 /* High-order 16 bits of constant for use in signed operand. */
7852 if (! INT_P (x))
7853 output_operand_lossage ("invalid %%v value");
e2c953b6 7854 else
134c32f6
DE
7855 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
7856 (INT_LOWPART (x) >> 16) & 0xffff);
7857 return;
802a0058 7858
9854d9ed
RK
7859 case 'U':
7860 /* Print `u' if this has an auto-increment or auto-decrement. */
7861 if (GET_CODE (x) == MEM
7862 && (GET_CODE (XEXP (x, 0)) == PRE_INC
7863 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 7864 putc ('u', file);
9854d9ed 7865 return;
9878760c 7866
e0cd0770
JC
7867 case 'V':
7868 /* Print the trap code for this operand. */
7869 switch (GET_CODE (x))
7870 {
7871 case EQ:
7872 fputs ("eq", file); /* 4 */
7873 break;
7874 case NE:
7875 fputs ("ne", file); /* 24 */
7876 break;
7877 case LT:
7878 fputs ("lt", file); /* 16 */
7879 break;
7880 case LE:
7881 fputs ("le", file); /* 20 */
7882 break;
7883 case GT:
7884 fputs ("gt", file); /* 8 */
7885 break;
7886 case GE:
7887 fputs ("ge", file); /* 12 */
7888 break;
7889 case LTU:
7890 fputs ("llt", file); /* 2 */
7891 break;
7892 case LEU:
7893 fputs ("lle", file); /* 6 */
7894 break;
7895 case GTU:
7896 fputs ("lgt", file); /* 1 */
7897 break;
7898 case GEU:
7899 fputs ("lge", file); /* 5 */
7900 break;
7901 default:
7902 abort ();
7903 }
7904 break;
7905
9854d9ed
RK
7906 case 'w':
7907 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
7908 normally. */
7909 if (INT_P (x))
5f59ecb7
DE
7910 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
7911 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
7912 else
7913 print_operand (file, x, 0);
9878760c
RK
7914 return;
7915
9854d9ed 7916 case 'W':
e2c953b6 7917 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
7918 val = (GET_CODE (x) == CONST_INT
7919 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
7920
7921 if (val < 0)
7922 i = -1;
9854d9ed 7923 else
e2c953b6
DE
7924 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
7925 if ((val <<= 1) < 0)
7926 break;
7927
7928#if HOST_BITS_PER_WIDE_INT == 32
7929 if (GET_CODE (x) == CONST_INT && i >= 0)
7930 i += 32; /* zero-extend high-part was all 0's */
7931 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
7932 {
7933 val = CONST_DOUBLE_LOW (x);
7934
7935 if (val == 0)
a4f6c312 7936 abort ();
e2c953b6
DE
7937 else if (val < 0)
7938 --i;
7939 else
7940 for ( ; i < 64; i++)
7941 if ((val <<= 1) < 0)
7942 break;
7943 }
7944#endif
7945
7946 fprintf (file, "%d", i + 1);
9854d9ed 7947 return;
9878760c 7948
9854d9ed
RK
7949 case 'X':
7950 if (GET_CODE (x) == MEM
258bfae2 7951 && LEGITIMATE_INDEXED_ADDRESS_P (XEXP (x, 0), 0))
76229ac8 7952 putc ('x', file);
9854d9ed 7953 return;
9878760c 7954
9854d9ed
RK
7955 case 'Y':
7956 /* Like 'L', for third word of TImode */
7957 if (GET_CODE (x) == REG)
5ebfb2ba 7958 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 7959 else if (GET_CODE (x) == MEM)
9878760c 7960 {
9854d9ed
RK
7961 if (GET_CODE (XEXP (x, 0)) == PRE_INC
7962 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 7963 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 7964 else
d7624dc0 7965 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 7966 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
7967 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
7968 reg_names[SMALL_DATA_REG]);
9878760c
RK
7969 }
7970 return;
9854d9ed 7971
9878760c 7972 case 'z':
b4ac57ab
RS
7973 /* X is a SYMBOL_REF. Write out the name preceded by a
7974 period and without any trailing data in brackets. Used for function
4d30c363
MM
7975 names. If we are configured for System V (or the embedded ABI) on
7976 the PowerPC, do not emit the period, since those systems do not use
7977 TOCs and the like. */
9878760c
RK
7978 if (GET_CODE (x) != SYMBOL_REF)
7979 abort ();
7980
b6c9286a
MM
7981 if (XSTR (x, 0)[0] != '.')
7982 {
7983 switch (DEFAULT_ABI)
7984 {
7985 default:
7986 abort ();
7987
7988 case ABI_AIX:
7989 putc ('.', file);
7990 break;
7991
7992 case ABI_V4:
7993 case ABI_AIX_NODESC:
ee890fe2 7994 case ABI_DARWIN:
b6c9286a 7995 break;
b6c9286a
MM
7996 }
7997 }
54ee9799
DE
7998#if TARGET_AIX
7999 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
8000#else
9ebbca7d 8001 assemble_name (file, XSTR (x, 0));
54ee9799 8002#endif
9878760c
RK
8003 return;
8004
9854d9ed
RK
8005 case 'Z':
8006 /* Like 'L', for last word of TImode. */
8007 if (GET_CODE (x) == REG)
5ebfb2ba 8008 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
8009 else if (GET_CODE (x) == MEM)
8010 {
8011 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8012 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 8013 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 8014 else
d7624dc0 8015 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 8016 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8017 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8018 reg_names[SMALL_DATA_REG]);
9854d9ed 8019 }
5c23c401 8020 return;
0ac081f6 8021
a3170dc6 8022 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
8023 case 'y':
8024 {
8025 rtx tmp;
8026
8027 if (GET_CODE (x) != MEM)
8028 abort ();
8029
8030 tmp = XEXP (x, 0);
8031
a3170dc6
AH
8032 if (TARGET_SPE)
8033 {
8034 /* Handle [reg]. */
8035 if (GET_CODE (tmp) == REG)
8036 {
8037 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
8038 break;
8039 }
8040 /* Handle [reg+UIMM]. */
8041 else if (GET_CODE (tmp) == PLUS &&
8042 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
8043 {
8044 int x;
8045
8046 if (GET_CODE (XEXP (tmp, 0)) != REG)
8047 abort ();
8048
8049 x = INTVAL (XEXP (tmp, 1));
8050 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
8051 break;
8052 }
8053
8054 /* Fall through. Must be [reg+reg]. */
8055 }
0ac081f6 8056 if (GET_CODE (tmp) == REG)
c62f2db5 8057 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
8058 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
8059 {
8060 if (REGNO (XEXP (tmp, 0)) == 0)
8061 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
8062 reg_names[ REGNO (XEXP (tmp, 0)) ]);
8063 else
8064 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
8065 reg_names[ REGNO (XEXP (tmp, 1)) ]);
8066 }
8067 else
8068 abort ();
8069 break;
8070 }
9854d9ed 8071
9878760c
RK
8072 case 0:
8073 if (GET_CODE (x) == REG)
8074 fprintf (file, "%s", reg_names[REGNO (x)]);
8075 else if (GET_CODE (x) == MEM)
8076 {
8077 /* We need to handle PRE_INC and PRE_DEC here, since we need to
8078 know the width from the mode. */
8079 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
8080 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
8081 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8082 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
8083 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
8084 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 8085 else
a54d04b7 8086 output_address (XEXP (x, 0));
9878760c
RK
8087 }
8088 else
a54d04b7 8089 output_addr_const (file, x);
a85d226b 8090 return;
9878760c
RK
8091
8092 default:
8093 output_operand_lossage ("invalid %%xn code");
8094 }
8095}
8096\f
8097/* Print the address of an operand. */
8098
8099void
8100print_operand_address (file, x)
8101 FILE *file;
592696dd 8102 rtx x;
9878760c
RK
8103{
8104 if (GET_CODE (x) == REG)
4697a36c 8105 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
8106 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
8107 || GET_CODE (x) == LABEL_REF)
9878760c
RK
8108 {
8109 output_addr_const (file, x);
ba5e43aa 8110 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8111 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8112 reg_names[SMALL_DATA_REG]);
9ebbca7d 8113 else if (TARGET_TOC)
a4f6c312 8114 abort ();
9878760c
RK
8115 }
8116 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
8117 {
8118 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
8119 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
8120 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 8121 else
4697a36c
MM
8122 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
8123 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
8124 }
8125 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
5f59ecb7
DE
8126 {
8127 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (XEXP (x, 1)));
8128 fprintf (file, "(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8129 }
3cb999d8
DE
8130#if TARGET_ELF
8131 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8132 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
8133 {
8134 output_addr_const (file, XEXP (x, 1));
8135 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8136 }
c859cda6
DJ
8137#endif
8138#if TARGET_MACHO
8139 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
8140 && CONSTANT_P (XEXP (x, 1)))
8141 {
8142 fprintf (file, "lo16(");
8143 output_addr_const (file, XEXP (x, 1));
8144 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
8145 }
3cb999d8 8146#endif
9ebbca7d
GK
8147 else if (LEGITIMATE_CONSTANT_POOL_ADDRESS_P (x))
8148 {
2bfcf297 8149 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 8150 {
2bfcf297
DB
8151 rtx contains_minus = XEXP (x, 1);
8152 rtx minus, symref;
8153 const char *name;
9ebbca7d
GK
8154
8155 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 8156 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
8157 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
8158 contains_minus = XEXP (contains_minus, 0);
8159
2bfcf297
DB
8160 minus = XEXP (contains_minus, 0);
8161 symref = XEXP (minus, 0);
8162 XEXP (contains_minus, 0) = symref;
8163 if (TARGET_ELF)
8164 {
8165 char *newname;
8166
8167 name = XSTR (symref, 0);
8168 newname = alloca (strlen (name) + sizeof ("@toc"));
8169 strcpy (newname, name);
8170 strcat (newname, "@toc");
8171 XSTR (symref, 0) = newname;
8172 }
8173 output_addr_const (file, XEXP (x, 1));
8174 if (TARGET_ELF)
8175 XSTR (symref, 0) = name;
9ebbca7d
GK
8176 XEXP (contains_minus, 0) = minus;
8177 }
8178 else
8179 output_addr_const (file, XEXP (x, 1));
8180
8181 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
8182 }
9878760c
RK
8183 else
8184 abort ();
8185}
8186\f
88cad84b 8187/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
8188 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
8189 is defined. It also needs to handle DI-mode objects on 64-bit
8190 targets. */
8191
8192static bool
8193rs6000_assemble_integer (x, size, aligned_p)
8194 rtx x;
8195 unsigned int size;
8196 int aligned_p;
8197{
8198#ifdef RELOCATABLE_NEEDS_FIXUP
8199 /* Special handling for SI values. */
8200 if (size == 4 && aligned_p)
8201 {
8202 extern int in_toc_section PARAMS ((void));
8203 static int recurse = 0;
8204
8205 /* For -mrelocatable, we mark all addresses that need to be fixed up
8206 in the .fixup section. */
8207 if (TARGET_RELOCATABLE
8208 && !in_toc_section ()
8209 && !in_text_section ()
8210 && !recurse
8211 && GET_CODE (x) != CONST_INT
8212 && GET_CODE (x) != CONST_DOUBLE
8213 && CONSTANT_P (x))
8214 {
8215 char buf[256];
8216
8217 recurse = 1;
8218 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
8219 fixuplabelno++;
8220 ASM_OUTPUT_LABEL (asm_out_file, buf);
8221 fprintf (asm_out_file, "\t.long\t(");
8222 output_addr_const (asm_out_file, x);
8223 fprintf (asm_out_file, ")@fixup\n");
8224 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
8225 ASM_OUTPUT_ALIGN (asm_out_file, 2);
8226 fprintf (asm_out_file, "\t.long\t");
8227 assemble_name (asm_out_file, buf);
8228 fprintf (asm_out_file, "\n\t.previous\n");
8229 recurse = 0;
8230 return true;
8231 }
8232 /* Remove initial .'s to turn a -mcall-aixdesc function
8233 address into the address of the descriptor, not the function
8234 itself. */
8235 else if (GET_CODE (x) == SYMBOL_REF
8236 && XSTR (x, 0)[0] == '.'
8237 && DEFAULT_ABI == ABI_AIX)
8238 {
8239 const char *name = XSTR (x, 0);
8240 while (*name == '.')
8241 name++;
8242
8243 fprintf (asm_out_file, "\t.long\t%s\n", name);
8244 return true;
8245 }
8246 }
8247#endif /* RELOCATABLE_NEEDS_FIXUP */
8248 return default_assemble_integer (x, size, aligned_p);
8249}
93638d7a
AM
8250
8251#ifdef HAVE_GAS_HIDDEN
8252/* Emit an assembler directive to set symbol visibility for DECL to
8253 VISIBILITY_TYPE. */
8254
5add3202 8255static void
25fdb4dc 8256rs6000_assemble_visibility (decl, vis)
93638d7a 8257 tree decl;
25fdb4dc 8258 int vis;
93638d7a 8259{
93638d7a
AM
8260 /* Functions need to have their entry point symbol visibility set as
8261 well as their descriptor symbol visibility. */
8262 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
8263 {
25fdb4dc
RH
8264 static const char * const visibility_types[] = {
8265 NULL, "internal", "hidden", "protected"
8266 };
8267
8268 const char *name, *type;
93638d7a
AM
8269
8270 name = ((* targetm.strip_name_encoding)
8271 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 8272 type = visibility_types[vis];
93638d7a 8273
25fdb4dc
RH
8274 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
8275 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 8276 }
25fdb4dc
RH
8277 else
8278 default_assemble_visibility (decl, vis);
93638d7a
AM
8279}
8280#endif
301d03af 8281\f
39a10a29
GK
8282enum rtx_code
8283rs6000_reverse_condition (mode, code)
8284 enum machine_mode mode;
8285 enum rtx_code code;
8286{
8287 /* Reversal of FP compares takes care -- an ordered compare
8288 becomes an unordered compare and vice versa. */
de40e1df 8289 if (mode == CCFPmode && !flag_unsafe_math_optimizations)
bab6226b 8290 return reverse_condition_maybe_unordered (code);
39a10a29 8291 else
bab6226b 8292 return reverse_condition (code);
39a10a29
GK
8293}
8294
39a10a29
GK
8295/* Generate a compare for CODE. Return a brand-new rtx that
8296 represents the result of the compare. */
a4f6c312 8297
39a10a29
GK
8298static rtx
8299rs6000_generate_compare (code)
8300 enum rtx_code code;
8301{
8302 enum machine_mode comp_mode;
8303 rtx compare_result;
8304
8305 if (rs6000_compare_fp_p)
8306 comp_mode = CCFPmode;
8307 else if (code == GTU || code == LTU
8308 || code == GEU || code == LEU)
8309 comp_mode = CCUNSmode;
8310 else
8311 comp_mode = CCmode;
8312
8313 /* First, the compare. */
8314 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
8315
8316 /* SPE FP compare instructions on the GPRs. Yuck! */
8317 if ((TARGET_SPE && TARGET_HARD_FLOAT) && rs6000_compare_fp_p)
8318 {
8319 rtx cmp, or1, or2, or_result, compare_result2;
8320
8321 switch (code)
8322 {
8323 case EQ:
8324 case UNEQ:
8325 case NE:
8326 case LTGT:
8327 cmp = flag_unsafe_math_optimizations
8328 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
8329 rs6000_compare_op1)
8330 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
8331 rs6000_compare_op1);
8332 break;
8333 case GT:
8334 case GTU:
8335 case UNGT:
8336 case UNGE:
8337 case GE:
8338 case GEU:
8339 cmp = flag_unsafe_math_optimizations
8340 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
8341 rs6000_compare_op1)
8342 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
8343 rs6000_compare_op1);
8344 break;
8345 case LT:
8346 case LTU:
8347 case UNLT:
8348 case UNLE:
8349 case LE:
8350 case LEU:
8351 cmp = flag_unsafe_math_optimizations
8352 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
8353 rs6000_compare_op1)
8354 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
8355 rs6000_compare_op1);
8356 break;
8357 default:
8358 abort ();
8359 }
8360
8361 /* Synthesize LE and GE from LT/GT || EQ. */
8362 if (code == LE || code == GE || code == LEU || code == GEU)
8363 {
8364 /* Synthesize GE/LE frome GT/LT || EQ. */
8365
8366 emit_insn (cmp);
8367
8368 switch (code)
8369 {
8370 case LE: code = LT; break;
8371 case GE: code = GT; break;
8372 case LEU: code = LT; break;
8373 case GEU: code = GT; break;
8374 default: abort ();
8375 }
8376
8377 or1 = gen_reg_rtx (SImode);
8378 or2 = gen_reg_rtx (SImode);
8379 or_result = gen_reg_rtx (CCEQmode);
8380 compare_result2 = gen_reg_rtx (CCFPmode);
8381
8382 /* Do the EQ. */
8383 cmp = flag_unsafe_math_optimizations
8384 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
8385 rs6000_compare_op1)
8386 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
8387 rs6000_compare_op1);
8388 emit_insn (cmp);
8389
8390 /* The MC8540 FP compare instructions set the CR bits
8391 differently than other PPC compare instructions. For
8392 that matter, there is no generic test instruction, but a
8393 testgt, testlt, and testeq. For a true condition, bit 2
8394 is set (x1xx) in the CR. Following the traditional CR
8395 values:
8396
8397 LT GT EQ OV
8398 bit3 bit2 bit1 bit0
8399
8400 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 8401 look in the GT bits for the branch instructions.
a3170dc6
AH
8402 However, we must be careful to emit correct RTL in
8403 the meantime, so optimizations don't get confused. */
8404
8405 or1 = gen_rtx (NE, SImode, compare_result, const0_rtx);
8406 or2 = gen_rtx (NE, SImode, compare_result2, const0_rtx);
8407
8408 /* OR them together. */
8409 cmp = gen_rtx_SET (VOIDmode, or_result,
8410 gen_rtx_COMPARE (CCEQmode,
8411 gen_rtx_IOR (SImode, or1, or2),
8412 const_true_rtx));
8413 compare_result = or_result;
8414 code = EQ;
8415 }
8416 else
8417 {
8418 /* We only care about 1 bit (x1xx), so map everything to NE to
8419 maintain rtl sanity. We'll get to the right bit (x1xx) at
8420 code output time. */
8421 if (code == NE || code == LTGT)
8422 /* Do the inverse here because we have no cmpne
8423 instruction. We use the cmpeq instruction and expect
8424 to get a 0 instead. */
8425 code = EQ;
8426 else
8427 code = NE;
8428 }
8429
8430 emit_insn (cmp);
8431 }
8432 else
8433 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
8434 gen_rtx_COMPARE (comp_mode,
8435 rs6000_compare_op0,
8436 rs6000_compare_op1)));
39a10a29 8437
ca5adc63 8438 /* Some kinds of FP comparisons need an OR operation;
de6c5979 8439 except for flag_unsafe_math_optimizations we don't bother. */
39a10a29 8440 if (rs6000_compare_fp_p
de6c5979 8441 && ! flag_unsafe_math_optimizations
a3170dc6 8442 && ! (TARGET_HARD_FLOAT && TARGET_SPE)
39a10a29
GK
8443 && (code == LE || code == GE
8444 || code == UNEQ || code == LTGT
8445 || code == UNGT || code == UNLT))
8446 {
8447 enum rtx_code or1, or2;
8448 rtx or1_rtx, or2_rtx, compare2_rtx;
8449 rtx or_result = gen_reg_rtx (CCEQmode);
8450
8451 switch (code)
8452 {
8453 case LE: or1 = LT; or2 = EQ; break;
8454 case GE: or1 = GT; or2 = EQ; break;
8455 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
8456 case LTGT: or1 = LT; or2 = GT; break;
8457 case UNGT: or1 = UNORDERED; or2 = GT; break;
8458 case UNLT: or1 = UNORDERED; or2 = LT; break;
8459 default: abort ();
8460 }
8461 validate_condition_mode (or1, comp_mode);
8462 validate_condition_mode (or2, comp_mode);
8463 or1_rtx = gen_rtx (or1, SImode, compare_result, const0_rtx);
8464 or2_rtx = gen_rtx (or2, SImode, compare_result, const0_rtx);
8465 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
8466 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
8467 const_true_rtx);
8468 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
8469
8470 compare_result = or_result;
8471 code = EQ;
8472 }
8473
8474 validate_condition_mode (code, GET_MODE (compare_result));
8475
8476 return gen_rtx (code, VOIDmode, compare_result, const0_rtx);
8477}
8478
8479
8480/* Emit the RTL for an sCOND pattern. */
8481
8482void
8483rs6000_emit_sCOND (code, result)
8484 enum rtx_code code;
8485 rtx result;
8486{
8487 rtx condition_rtx;
8488 enum machine_mode op_mode;
8489
8490 condition_rtx = rs6000_generate_compare (code);
8491
8492 op_mode = GET_MODE (rs6000_compare_op0);
8493 if (op_mode == VOIDmode)
8494 op_mode = GET_MODE (rs6000_compare_op1);
8495
8496 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
8497 {
8498 PUT_MODE (condition_rtx, DImode);
8499 convert_move (result, condition_rtx, 0);
8500 }
8501 else
8502 {
8503 PUT_MODE (condition_rtx, SImode);
8504 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
8505 }
8506}
8507
39a10a29
GK
8508/* Emit a branch of kind CODE to location LOC. */
8509
8510void
8511rs6000_emit_cbranch (code, loc)
8512 enum rtx_code code;
8513 rtx loc;
8514{
8515 rtx condition_rtx, loc_ref;
8516
8517 condition_rtx = rs6000_generate_compare (code);
8518 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
8519 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
8520 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
8521 loc_ref, pc_rtx)));
8522}
8523
12a4e8c5
GK
8524/* Return the string to output a conditional branch to LABEL, which is
8525 the operand number of the label, or -1 if the branch is really a
8526 conditional return.
8527
8528 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
8529 condition code register and its mode specifies what kind of
8530 comparison we made.
8531
a0ab749a 8532 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
8533
8534 INSN is the insn. */
8535
8536char *
8537output_cbranch (op, label, reversed, insn)
8538 rtx op;
8539 const char * label;
8540 int reversed;
8541 rtx insn;
8542{
8543 static char string[64];
8544 enum rtx_code code = GET_CODE (op);
8545 rtx cc_reg = XEXP (op, 0);
8546 enum machine_mode mode = GET_MODE (cc_reg);
8547 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 8548 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
8549 int really_reversed = reversed ^ need_longbranch;
8550 char *s = string;
8551 const char *ccode;
8552 const char *pred;
8553 rtx note;
8554
39a10a29
GK
8555 validate_condition_mode (code, mode);
8556
8557 /* Work out which way this really branches. We could use
8558 reverse_condition_maybe_unordered here always but this
8559 makes the resulting assembler clearer. */
12a4e8c5 8560 if (really_reversed)
de40e1df
DJ
8561 {
8562 /* Reversal of FP compares takes care -- an ordered compare
8563 becomes an unordered compare and vice versa. */
8564 if (mode == CCFPmode)
8565 code = reverse_condition_maybe_unordered (code);
8566 else
8567 code = reverse_condition (code);
8568 }
12a4e8c5 8569
a3170dc6
AH
8570 if ((TARGET_SPE && TARGET_HARD_FLOAT) && mode == CCFPmode)
8571 {
8572 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
8573 to the GT bit. */
8574 if (code == EQ)
8575 /* Opposite of GT. */
8576 code = UNLE;
8577 else if (code == NE)
8578 code = GT;
8579 else
8580 abort ();
8581 }
8582
39a10a29 8583 switch (code)
12a4e8c5
GK
8584 {
8585 /* Not all of these are actually distinct opcodes, but
8586 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
8587 case NE: case LTGT:
8588 ccode = "ne"; break;
8589 case EQ: case UNEQ:
8590 ccode = "eq"; break;
8591 case GE: case GEU:
8592 ccode = "ge"; break;
8593 case GT: case GTU: case UNGT:
8594 ccode = "gt"; break;
8595 case LE: case LEU:
8596 ccode = "le"; break;
8597 case LT: case LTU: case UNLT:
8598 ccode = "lt"; break;
12a4e8c5
GK
8599 case UNORDERED: ccode = "un"; break;
8600 case ORDERED: ccode = "nu"; break;
8601 case UNGE: ccode = "nl"; break;
8602 case UNLE: ccode = "ng"; break;
8603 default:
a4f6c312 8604 abort ();
12a4e8c5
GK
8605 }
8606
94a54f47
GK
8607 /* Maybe we have a guess as to how likely the branch is.
8608 The old mnemonics don't have a way to specify this information. */
f4857b9b 8609 pred = "";
12a4e8c5
GK
8610 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
8611 if (note != NULL_RTX)
8612 {
8613 /* PROB is the difference from 50%. */
8614 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
8615 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
8616
8617 /* Only hint for highly probable/improbable branches on newer
8618 cpus as static prediction overrides processor dynamic
8619 prediction. For older cpus we may as well always hint, but
8620 assume not taken for branches that are very close to 50% as a
8621 mispredicted taken branch is more expensive than a
8622 mispredicted not-taken branch. */
8623 if (always_hint
8624 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
8625 {
8626 if (abs (prob) > REG_BR_PROB_BASE / 20
8627 && ((prob > 0) ^ need_longbranch))
8628 pred = "+";
8629 else
8630 pred = "-";
8631 }
12a4e8c5 8632 }
12a4e8c5
GK
8633
8634 if (label == NULL)
94a54f47 8635 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 8636 else
94a54f47 8637 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 8638
37c67319
GK
8639 /* We need to escape any '%' characters in the reg_names string.
8640 Assume they'd only be the first character... */
8641 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
8642 *s++ = '%';
94a54f47 8643 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
8644
8645 if (label != NULL)
8646 {
8647 /* If the branch distance was too far, we may have to use an
8648 unconditional branch to go the distance. */
8649 if (need_longbranch)
44518ddd 8650 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
8651 else
8652 s += sprintf (s, ",%s", label);
8653 }
8654
8655 return string;
8656}
50a0b056
GK
8657
8658/* Emit a conditional move: move TRUE_COND to DEST if OP of the
8659 operands of the last comparison is nonzero/true, FALSE_COND if it
8660 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 8661
50a0b056
GK
8662int
8663rs6000_emit_cmove (dest, op, true_cond, false_cond)
8664 rtx dest;
8665 rtx op;
8666 rtx true_cond;
8667 rtx false_cond;
8668{
8669 enum rtx_code code = GET_CODE (op);
8670 rtx op0 = rs6000_compare_op0;
8671 rtx op1 = rs6000_compare_op1;
8672 REAL_VALUE_TYPE c1;
3148ad6d
DJ
8673 enum machine_mode compare_mode = GET_MODE (op0);
8674 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
8675 rtx temp;
8676
3148ad6d 8677 /* These modes should always match. */
a3170dc6
AH
8678 if (GET_MODE (op1) != compare_mode
8679 /* In the isel case however, we can use a compare immediate, so
8680 op1 may be a small constant. */
8681 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 8682 return 0;
178c3eff 8683 if (GET_MODE (true_cond) != result_mode)
3148ad6d 8684 return 0;
178c3eff 8685 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
8686 return 0;
8687
50a0b056
GK
8688 /* First, work out if the hardware can do this at all, or
8689 if it's too slow... */
50a0b056 8690 if (! rs6000_compare_fp_p)
a3170dc6
AH
8691 {
8692 if (TARGET_ISEL)
8693 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
8694 return 0;
8695 }
50a0b056
GK
8696
8697 /* Eliminate half of the comparisons by switching operands, this
8698 makes the remaining code simpler. */
8699 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
8700 || code == LTGT || code == LT)
8701 {
8702 code = reverse_condition_maybe_unordered (code);
8703 temp = true_cond;
8704 true_cond = false_cond;
8705 false_cond = temp;
8706 }
8707
8708 /* UNEQ and LTGT take four instructions for a comparison with zero,
8709 it'll probably be faster to use a branch here too. */
8710 if (code == UNEQ)
8711 return 0;
8712
8713 if (GET_CODE (op1) == CONST_DOUBLE)
8714 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
8715
b6d08ca1 8716 /* We're going to try to implement comparisons by performing
50a0b056
GK
8717 a subtract, then comparing against zero. Unfortunately,
8718 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 8719 know that the operand is finite and the comparison
50a0b056
GK
8720 would treat EQ different to UNORDERED, we can't do it. */
8721 if (! flag_unsafe_math_optimizations
8722 && code != GT && code != UNGE
045572c7 8723 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
8724 /* Constructs of the form (a OP b ? a : b) are safe. */
8725 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
8726 || (! rtx_equal_p (op0, true_cond)
8727 && ! rtx_equal_p (op1, true_cond))))
8728 return 0;
8729 /* At this point we know we can use fsel. */
8730
8731 /* Reduce the comparison to a comparison against zero. */
3148ad6d 8732 temp = gen_reg_rtx (compare_mode);
50a0b056 8733 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8734 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 8735 op0 = temp;
3148ad6d 8736 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
8737
8738 /* If we don't care about NaNs we can reduce some of the comparisons
8739 down to faster ones. */
8740 if (flag_unsafe_math_optimizations)
8741 switch (code)
8742 {
8743 case GT:
8744 code = LE;
8745 temp = true_cond;
8746 true_cond = false_cond;
8747 false_cond = temp;
8748 break;
8749 case UNGE:
8750 code = GE;
8751 break;
8752 case UNEQ:
8753 code = EQ;
8754 break;
8755 default:
8756 break;
8757 }
8758
8759 /* Now, reduce everything down to a GE. */
8760 switch (code)
8761 {
8762 case GE:
8763 break;
8764
8765 case LE:
3148ad6d
DJ
8766 temp = gen_reg_rtx (compare_mode);
8767 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8768 op0 = temp;
8769 break;
8770
8771 case ORDERED:
3148ad6d
DJ
8772 temp = gen_reg_rtx (compare_mode);
8773 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
8774 op0 = temp;
8775 break;
8776
8777 case EQ:
3148ad6d 8778 temp = gen_reg_rtx (compare_mode);
50a0b056 8779 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
8780 gen_rtx_NEG (compare_mode,
8781 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
8782 op0 = temp;
8783 break;
8784
8785 case UNGE:
3148ad6d 8786 temp = gen_reg_rtx (result_mode);
50a0b056 8787 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8788 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8789 gen_rtx_GE (VOIDmode,
8790 op0, op1),
8791 true_cond, false_cond)));
8792 false_cond = temp;
8793 true_cond = false_cond;
8794
3148ad6d
DJ
8795 temp = gen_reg_rtx (compare_mode);
8796 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8797 op0 = temp;
8798 break;
8799
8800 case GT:
3148ad6d 8801 temp = gen_reg_rtx (result_mode);
50a0b056 8802 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 8803 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8804 gen_rtx_GE (VOIDmode,
8805 op0, op1),
8806 true_cond, false_cond)));
8807 true_cond = temp;
8808 false_cond = true_cond;
8809
3148ad6d
DJ
8810 temp = gen_reg_rtx (compare_mode);
8811 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
8812 op0 = temp;
8813 break;
8814
8815 default:
8816 abort ();
8817 }
8818
8819 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 8820 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
8821 gen_rtx_GE (VOIDmode,
8822 op0, op1),
8823 true_cond, false_cond)));
8824 return 1;
8825}
8826
a3170dc6
AH
8827/* Same as above, but for ints (isel). */
8828
8829static int
8830rs6000_emit_int_cmove (dest, op, true_cond, false_cond)
8831 rtx dest;
8832 rtx op;
8833 rtx true_cond;
8834 rtx false_cond;
8835{
8836 rtx condition_rtx, cr;
8837
8838 /* All isel implementations thus far are 32-bits. */
8839 if (GET_MODE (rs6000_compare_op0) != SImode)
8840 return 0;
8841
8842 /* We still have to do the compare, because isel doesn't do a
8843 compare, it just looks at the CRx bits set by a previous compare
8844 instruction. */
8845 condition_rtx = rs6000_generate_compare (GET_CODE (op));
8846 cr = XEXP (condition_rtx, 0);
8847
8848 if (GET_MODE (cr) == CCmode)
8849 emit_insn (gen_isel_signed (dest, condition_rtx,
8850 true_cond, false_cond, cr));
8851 else
8852 emit_insn (gen_isel_unsigned (dest, condition_rtx,
8853 true_cond, false_cond, cr));
8854
8855 return 1;
8856}
8857
8858const char *
8859output_isel (operands)
8860 rtx *operands;
8861{
8862 enum rtx_code code;
8863
8864 code = GET_CODE (operands[1]);
8865 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
8866 {
8867 PUT_CODE (operands[1], reverse_condition (code));
8868 return "isel %0,%3,%2,%j1";
8869 }
8870 else
8871 return "isel %0,%2,%3,%j1";
8872}
8873
50a0b056
GK
8874void
8875rs6000_emit_minmax (dest, code, op0, op1)
8876 rtx dest;
8877 enum rtx_code code;
8878 rtx op0;
8879 rtx op1;
8880{
8881 enum machine_mode mode = GET_MODE (op0);
5dc8d536 8882 enum rtx_code c;
50a0b056 8883 rtx target;
5dc8d536
AH
8884
8885 if (code == SMAX || code == SMIN)
8886 c = GE;
8887 else
8888 c = GEU;
8889
50a0b056 8890 if (code == SMAX || code == UMAX)
5dc8d536 8891 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
8892 op0, op1, mode, 0);
8893 else
5dc8d536 8894 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
8895 op1, op0, mode, 0);
8896 if (target == NULL_RTX)
8897 abort ();
8898 if (target != dest)
8899 emit_move_insn (dest, target);
8900}
12a4e8c5 8901\f
a4f6c312
SS
8902/* This page contains routines that are used to determine what the
8903 function prologue and epilogue code will do and write them out. */
9878760c 8904
a4f6c312
SS
8905/* Return the first fixed-point register that is required to be
8906 saved. 32 if none. */
9878760c
RK
8907
8908int
8909first_reg_to_save ()
8910{
8911 int first_reg;
8912
8913 /* Find lowest numbered live register. */
8914 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
8915 if (regs_ever_live[first_reg]
8916 && (! call_used_regs[first_reg]
1db02437 8917 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
f607bc57
ZW
8918 && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1)
8919 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
8920 break;
8921
ee890fe2 8922#if TARGET_MACHO
93638d7a
AM
8923 if (flag_pic
8924 && current_function_uses_pic_offset_table
8925 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 8926 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
8927#endif
8928
9878760c
RK
8929 return first_reg;
8930}
8931
8932/* Similar, for FP regs. */
8933
8934int
8935first_fp_reg_to_save ()
8936{
8937 int first_reg;
8938
8939 /* Find lowest numbered live register. */
8940 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
8941 if (regs_ever_live[first_reg])
8942 break;
8943
8944 return first_reg;
8945}
00b960c7
AH
8946
8947/* Similar, for AltiVec regs. */
8948
8949static int
8950first_altivec_reg_to_save ()
8951{
8952 int i;
8953
8954 /* Stack frame remains as is unless we are in AltiVec ABI. */
8955 if (! TARGET_ALTIVEC_ABI)
8956 return LAST_ALTIVEC_REGNO + 1;
8957
8958 /* Find lowest numbered live register. */
8959 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
8960 if (regs_ever_live[i])
8961 break;
8962
8963 return i;
8964}
8965
8966/* Return a 32-bit mask of the AltiVec registers we need to set in
8967 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
8968 the 32-bit word is 0. */
8969
8970static unsigned int
8971compute_vrsave_mask ()
8972{
8973 unsigned int i, mask = 0;
8974
8975 /* First, find out if we use _any_ altivec registers. */
8976 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
8977 if (regs_ever_live[i])
8978 mask |= ALTIVEC_REG_BIT (i);
8979
8980 if (mask == 0)
8981 return mask;
8982
8983 /* Next, add all registers that are call-clobbered. We do this
8984 because post-reload register optimizers such as regrename_optimize
8985 may choose to use them. They never change the register class
8986 chosen by reload, so cannot create new uses of altivec registers
8987 if there were none before, so the early exit above is safe. */
8988 /* ??? Alternately, we could define HARD_REGNO_RENAME_OK to disallow
8989 altivec registers not saved in the mask, which might well make the
8990 adjustments below more effective in eliding the save/restore of
8991 VRSAVE in small functions. */
8992 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
8993 if (call_used_regs[i])
8994 mask |= ALTIVEC_REG_BIT (i);
8995
8996 /* Next, remove the argument registers from the set. These must
8997 be in the VRSAVE mask set by the caller, so we don't need to add
8998 them in again. More importantly, the mask we compute here is
8999 used to generate CLOBBERs in the set_vrsave insn, and we do not
9000 wish the argument registers to die. */
9001 for (i = cfun->args_info.vregno; i >= ALTIVEC_ARG_MIN_REG; --i)
9002 mask &= ~ALTIVEC_REG_BIT (i);
9003
9004 /* Similarly, remove the return value from the set. */
9005 {
9006 bool yes = false;
9007 diddle_return_value (is_altivec_return_reg, &yes);
9008 if (yes)
9009 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
9010 }
9011
9012 return mask;
9013}
9014
9015static void
9016is_altivec_return_reg (reg, xyes)
9017 rtx reg;
9018 void *xyes;
9019{
9020 bool *yes = (bool *) xyes;
9021 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
9022 *yes = true;
9023}
9024
4697a36c
MM
9025\f
9026/* Calculate the stack information for the current function. This is
9027 complicated by having two separate calling sequences, the AIX calling
9028 sequence and the V.4 calling sequence.
9029
592696dd 9030 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 9031 32-bit 64-bit
4697a36c 9032 SP----> +---------------------------------------+
a260abc9 9033 | back chain to caller | 0 0
4697a36c 9034 +---------------------------------------+
a260abc9 9035 | saved CR | 4 8 (8-11)
4697a36c 9036 +---------------------------------------+
a260abc9 9037 | saved LR | 8 16
4697a36c 9038 +---------------------------------------+
a260abc9 9039 | reserved for compilers | 12 24
4697a36c 9040 +---------------------------------------+
a260abc9 9041 | reserved for binders | 16 32
4697a36c 9042 +---------------------------------------+
a260abc9 9043 | saved TOC pointer | 20 40
4697a36c 9044 +---------------------------------------+
a260abc9 9045 | Parameter save area (P) | 24 48
4697a36c 9046 +---------------------------------------+
a260abc9 9047 | Alloca space (A) | 24+P etc.
802a0058 9048 +---------------------------------------+
a7df97e6 9049 | Local variable space (L) | 24+P+A
4697a36c 9050 +---------------------------------------+
a7df97e6 9051 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 9052 +---------------------------------------+
00b960c7
AH
9053 | Save area for AltiVec registers (W) | 24+P+A+L+X
9054 +---------------------------------------+
9055 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
9056 +---------------------------------------+
9057 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 9058 +---------------------------------------+
00b960c7
AH
9059 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
9060 +---------------------------------------+
9061 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
9062 +---------------------------------------+
9063 old SP->| back chain to caller's caller |
9064 +---------------------------------------+
9065
5376a30c
KR
9066 The required alignment for AIX configurations is two words (i.e., 8
9067 or 16 bytes).
9068
9069
4697a36c
MM
9070 V.4 stack frames look like:
9071
9072 SP----> +---------------------------------------+
9073 | back chain to caller | 0
9074 +---------------------------------------+
5eb387b8 9075 | caller's saved LR | 4
4697a36c
MM
9076 +---------------------------------------+
9077 | Parameter save area (P) | 8
9078 +---------------------------------------+
a7df97e6
MM
9079 | Alloca space (A) | 8+P
9080 +---------------------------------------+
9081 | Varargs save area (V) | 8+P+A
9082 +---------------------------------------+
9083 | Local variable space (L) | 8+P+A+V
9084 +---------------------------------------+
9085 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 9086 +---------------------------------------+
00b960c7
AH
9087 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
9088 +---------------------------------------+
9089 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
9090 +---------------------------------------+
9091 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
9092 +---------------------------------------+
a3170dc6
AH
9093 | SPE: area for 64-bit GP registers |
9094 +---------------------------------------+
9095 | SPE alignment padding |
9096 +---------------------------------------+
00b960c7 9097 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 9098 +---------------------------------------+
00b960c7 9099 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 9100 +---------------------------------------+
00b960c7 9101 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
9102 +---------------------------------------+
9103 old SP->| back chain to caller's caller |
9104 +---------------------------------------+
b6c9286a 9105
5376a30c
KR
9106 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
9107 given. (But note below and in sysv4.h that we require only 8 and
9108 may round up the size of our stack frame anyways. The historical
9109 reason is early versions of powerpc-linux which didn't properly
9110 align the stack at program startup. A happy side-effect is that
9111 -mno-eabi libraries can be used with -meabi programs.)
9112
5376a30c
KR
9113 The EABI configuration defaults to the V.4 layout, unless
9114 -mcall-aix is used, in which case the AIX layout is used. However,
9115 the stack alignment requirements may differ. If -mno-eabi is not
9116 given, the required stack alignment is 8 bytes; if -mno-eabi is
9117 given, the required alignment is 16 bytes. (But see V.4 comment
9118 above.) */
4697a36c 9119
61b2fbe7
MM
9120#ifndef ABI_STACK_BOUNDARY
9121#define ABI_STACK_BOUNDARY STACK_BOUNDARY
9122#endif
9123
4697a36c
MM
9124rs6000_stack_t *
9125rs6000_stack_info ()
9126{
9127 static rs6000_stack_t info, zero_info;
9128 rs6000_stack_t *info_ptr = &info;
9ebbca7d 9129 int reg_size = TARGET_POWERPC64 ? 8 : 4;
24d304eb 9130 enum rs6000_abi abi;
83720594 9131 int ehrd_size;
b6c9286a 9132 int total_raw_size;
4697a36c 9133
a4f6c312 9134 /* Zero all fields portably. */
4697a36c
MM
9135 info = zero_info;
9136
a4f6c312 9137 /* Select which calling sequence. */
b6c9286a 9138 info_ptr->abi = abi = DEFAULT_ABI;
9878760c 9139
a4f6c312 9140 /* Calculate which registers need to be saved & save area size. */
4697a36c 9141 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 9142 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 9143 even if it currently looks like we won't. */
2bfcf297 9144 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
f607bc57
ZW
9145 || (flag_pic == 1 && abi == ABI_V4)
9146 || (flag_pic && abi == ABI_DARWIN))
1db02437
FS
9147 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
9148 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
9149 else
9150 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 9151
a3170dc6
AH
9152 /* For the SPE, we have an additional upper 32-bits on each GPR.
9153 Ideally we should save the entire 64-bits only when the upper
9154 half is used in SIMD instructions. Since we only record
9155 registers live (not the size they are used in), this proves
9156 difficult because we'd have to traverse the instruction chain at
9157 the right time, taking reload into account. This is a real pain,
9158 so we opt to save the GPRs in 64-bits always. Anyone overly
9159 concerned with frame size can fix this. ;-).
9160
9161 So... since we save all GPRs (except the SP) in 64-bits, the
9162 traditional GP save area will be empty. */
9163 if (TARGET_SPE_ABI)
9164 info_ptr->gp_size = 0;
9165
4697a36c
MM
9166 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
9167 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
9168
00b960c7
AH
9169 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
9170 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
9171 - info_ptr->first_altivec_reg_save);
9172
592696dd 9173 /* Does this function call anything? */
71f123ca
FS
9174 info_ptr->calls_p = (! current_function_is_leaf
9175 || cfun->machine->ra_needs_full_frame);
b6c9286a 9176
a4f6c312 9177 /* Determine if we need to save the link register. */
71f123ca 9178 if (rs6000_ra_ever_killed ()
70f4f91c 9179 || (DEFAULT_ABI == ABI_AIX && current_function_profile)
4697a36c
MM
9180#ifdef TARGET_RELOCATABLE
9181 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
9182#endif
9183 || (info_ptr->first_fp_reg_save != 64
9184 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 9185 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
24d304eb 9186 || (abi == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
9187 || (DEFAULT_ABI == ABI_DARWIN
9188 && flag_pic
9189 && current_function_uses_pic_offset_table)
4697a36c
MM
9190 || info_ptr->calls_p)
9191 {
9192 info_ptr->lr_save_p = 1;
9ebbca7d 9193 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
9194 }
9195
9ebbca7d
GK
9196 /* Determine if we need to save the condition code registers. */
9197 if (regs_ever_live[CR2_REGNO]
9198 || regs_ever_live[CR3_REGNO]
9199 || regs_ever_live[CR4_REGNO])
4697a36c
MM
9200 {
9201 info_ptr->cr_save_p = 1;
f607bc57 9202 if (abi == ABI_V4)
4697a36c
MM
9203 info_ptr->cr_size = reg_size;
9204 }
9205
83720594
RH
9206 /* If the current function calls __builtin_eh_return, then we need
9207 to allocate stack space for registers that will hold data for
9208 the exception handler. */
9209 if (current_function_calls_eh_return)
9210 {
9211 unsigned int i;
9212 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
9213 continue;
a3170dc6
AH
9214
9215 /* SPE saves EH registers in 64-bits. */
9216 ehrd_size = i * (TARGET_SPE_ABI ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
9217 }
9218 else
9219 ehrd_size = 0;
9220
592696dd 9221 /* Determine various sizes. */
4697a36c
MM
9222 info_ptr->reg_size = reg_size;
9223 info_ptr->fixed_size = RS6000_SAVE_AREA;
9224 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 9225 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
9226 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
9227 8);
00b960c7 9228
a3170dc6
AH
9229 if (TARGET_SPE_ABI)
9230 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
9231 else
9232 info_ptr->spe_gp_size = 0;
9233
08b57fb3 9234 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE)
00b960c7
AH
9235 {
9236 info_ptr->vrsave_mask = compute_vrsave_mask ();
9237 info_ptr->vrsave_size = info_ptr->vrsave_mask ? 4 : 0;
9238 }
9239 else
9240 {
9241 info_ptr->vrsave_mask = 0;
9242 info_ptr->vrsave_size = 0;
9243 }
b6c9286a 9244
592696dd 9245 /* Calculate the offsets. */
24d304eb 9246 switch (abi)
4697a36c 9247 {
b6c9286a 9248 case ABI_NONE:
24d304eb 9249 default:
b6c9286a
MM
9250 abort ();
9251
9252 case ABI_AIX:
9253 case ABI_AIX_NODESC:
ee890fe2 9254 case ABI_DARWIN:
b6c9286a
MM
9255 info_ptr->fp_save_offset = - info_ptr->fp_size;
9256 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
9257
9258 if (TARGET_ALTIVEC_ABI)
9259 {
9260 info_ptr->vrsave_save_offset
9261 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
9262
9263 /* Align stack so vector save area is on a quadword boundary. */
9264 if (info_ptr->altivec_size != 0)
9265 info_ptr->altivec_padding_size
9266 = 16 - (-info_ptr->vrsave_save_offset % 16);
9267 else
9268 info_ptr->altivec_padding_size = 0;
9269
9270 info_ptr->altivec_save_offset
9271 = info_ptr->vrsave_save_offset
9272 - info_ptr->altivec_padding_size
9273 - info_ptr->altivec_size;
9274
9275 /* Adjust for AltiVec case. */
9276 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
9277 }
9278 else
9279 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
9280 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
9281 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
9282 break;
9283
9284 case ABI_V4:
b6c9286a
MM
9285 info_ptr->fp_save_offset = - info_ptr->fp_size;
9286 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 9287 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 9288
a3170dc6
AH
9289 if (TARGET_SPE_ABI)
9290 {
9291 /* Align stack so SPE GPR save area is aligned on a
9292 double-word boundary. */
9293 if (info_ptr->spe_gp_size != 0)
9294 info_ptr->spe_padding_size
9295 = 8 - (-info_ptr->cr_save_offset % 8);
9296 else
9297 info_ptr->spe_padding_size = 0;
9298
9299 info_ptr->spe_gp_save_offset
9300 = info_ptr->cr_save_offset
9301 - info_ptr->spe_padding_size
9302 - info_ptr->spe_gp_size;
9303
9304 /* Adjust for SPE case. */
9305 info_ptr->toc_save_offset
9306 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
9307 }
9308 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
9309 {
9310 info_ptr->vrsave_save_offset
9311 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
9312
9313 /* Align stack so vector save area is on a quadword boundary. */
9314 if (info_ptr->altivec_size != 0)
9315 info_ptr->altivec_padding_size
9316 = 16 - (-info_ptr->vrsave_save_offset % 16);
9317 else
9318 info_ptr->altivec_padding_size = 0;
9319
9320 info_ptr->altivec_save_offset
9321 = info_ptr->vrsave_save_offset
9322 - info_ptr->altivec_padding_size
9323 - info_ptr->altivec_size;
9324
9325 /* Adjust for AltiVec case. */
9326 info_ptr->toc_save_offset
9327 = info_ptr->altivec_save_offset - info_ptr->toc_size;
9328 }
9329 else
9330 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 9331 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
9332 info_ptr->lr_save_offset = reg_size;
9333 break;
4697a36c
MM
9334 }
9335
00b960c7
AH
9336 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
9337 + info_ptr->gp_size
9338 + info_ptr->altivec_size
9339 + info_ptr->altivec_padding_size
9340 + info_ptr->vrsave_size
a3170dc6
AH
9341 + info_ptr->spe_gp_size
9342 + info_ptr->spe_padding_size
00b960c7
AH
9343 + ehrd_size
9344 + info_ptr->cr_size
9345 + info_ptr->lr_size
9346 + info_ptr->vrsave_size
9347 + info_ptr->toc_size,
9348 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
9349 ? 16 : 8);
9350
ff381587
MM
9351 total_raw_size = (info_ptr->vars_size
9352 + info_ptr->parm_size
ff381587
MM
9353 + info_ptr->save_size
9354 + info_ptr->varargs_size
9355 + info_ptr->fixed_size);
9356
a4f6c312
SS
9357 info_ptr->total_size =
9358 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
9359
9360 /* Determine if we need to allocate any stack frame:
9361
a4f6c312
SS
9362 For AIX we need to push the stack if a frame pointer is needed
9363 (because the stack might be dynamically adjusted), if we are
9364 debugging, if we make calls, or if the sum of fp_save, gp_save,
9365 and local variables are more than the space needed to save all
9366 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
9367 + 18*8 = 288 (GPR13 reserved).
ff381587 9368
a4f6c312
SS
9369 For V.4 we don't have the stack cushion that AIX uses, but assume
9370 that the debugger can handle stackless frames. */
ff381587
MM
9371
9372 if (info_ptr->calls_p)
9373 info_ptr->push_p = 1;
9374
f607bc57 9375 else if (abi == ABI_V4)
e72247f4 9376 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587
MM
9377
9378 else
9379 info_ptr->push_p = (frame_pointer_needed
ee890fe2 9380 || (abi != ABI_DARWIN && write_symbols != NO_DEBUG)
ff381587 9381 || ((total_raw_size - info_ptr->fixed_size)
bfc79d3b 9382 > (TARGET_32BIT ? 220 : 288)));
ff381587 9383
a4f6c312 9384 /* Zero offsets if we're not saving those registers. */
8dda1a21 9385 if (info_ptr->fp_size == 0)
4697a36c
MM
9386 info_ptr->fp_save_offset = 0;
9387
8dda1a21 9388 if (info_ptr->gp_size == 0)
4697a36c
MM
9389 info_ptr->gp_save_offset = 0;
9390
00b960c7
AH
9391 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
9392 info_ptr->altivec_save_offset = 0;
9393
9394 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
9395 info_ptr->vrsave_save_offset = 0;
9396
a3170dc6
AH
9397 if (! TARGET_SPE_ABI || info_ptr->spe_gp_size == 0)
9398 info_ptr->spe_gp_save_offset = 0;
9399
c81fc13e 9400 if (! info_ptr->lr_save_p)
4697a36c
MM
9401 info_ptr->lr_save_offset = 0;
9402
c81fc13e 9403 if (! info_ptr->cr_save_p)
4697a36c
MM
9404 info_ptr->cr_save_offset = 0;
9405
c81fc13e 9406 if (! info_ptr->toc_save_p)
b6c9286a
MM
9407 info_ptr->toc_save_offset = 0;
9408
4697a36c
MM
9409 return info_ptr;
9410}
9411
9412void
9413debug_stack_info (info)
9414 rs6000_stack_t *info;
9878760c 9415{
d330fd93 9416 const char *abi_string;
24d304eb 9417
c81fc13e 9418 if (! info)
4697a36c
MM
9419 info = rs6000_stack_info ();
9420
9421 fprintf (stderr, "\nStack information for function %s:\n",
9422 ((current_function_decl && DECL_NAME (current_function_decl))
9423 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
9424 : "<unknown>"));
9425
24d304eb
RK
9426 switch (info->abi)
9427 {
b6c9286a
MM
9428 default: abi_string = "Unknown"; break;
9429 case ABI_NONE: abi_string = "NONE"; break;
f607bc57 9430 case ABI_AIX:
b6c9286a 9431 case ABI_AIX_NODESC: abi_string = "AIX"; break;
ee890fe2 9432 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 9433 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
9434 }
9435
9436 fprintf (stderr, "\tABI = %5s\n", abi_string);
9437
00b960c7
AH
9438 if (TARGET_ALTIVEC_ABI)
9439 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
9440
a3170dc6
AH
9441 if (TARGET_SPE_ABI)
9442 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
9443
4697a36c
MM
9444 if (info->first_gp_reg_save != 32)
9445 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
9446
9447 if (info->first_fp_reg_save != 64)
9448 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 9449
00b960c7
AH
9450 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
9451 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
9452 info->first_altivec_reg_save);
9453
4697a36c
MM
9454 if (info->lr_save_p)
9455 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 9456
4697a36c
MM
9457 if (info->cr_save_p)
9458 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
9459
b6c9286a
MM
9460 if (info->toc_save_p)
9461 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
9462
00b960c7
AH
9463 if (info->vrsave_mask)
9464 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
9465
4697a36c
MM
9466 if (info->push_p)
9467 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
9468
9469 if (info->calls_p)
9470 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
9471
4697a36c
MM
9472 if (info->gp_save_offset)
9473 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
9474
9475 if (info->fp_save_offset)
9476 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
9477
00b960c7
AH
9478 if (info->altivec_save_offset)
9479 fprintf (stderr, "\taltivec_save_offset = %5d\n",
9480 info->altivec_save_offset);
9481
a3170dc6
AH
9482 if (info->spe_gp_save_offset)
9483 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
9484 info->spe_gp_save_offset);
9485
00b960c7
AH
9486 if (info->vrsave_save_offset)
9487 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
9488 info->vrsave_save_offset);
9489
4697a36c
MM
9490 if (info->lr_save_offset)
9491 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
9492
9493 if (info->cr_save_offset)
9494 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
9495
b6c9286a
MM
9496 if (info->toc_save_offset)
9497 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
9498
4697a36c
MM
9499 if (info->varargs_save_offset)
9500 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
9501
9502 if (info->total_size)
9503 fprintf (stderr, "\ttotal_size = %5d\n", info->total_size);
9504
9505 if (info->varargs_size)
9506 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
9507
9508 if (info->vars_size)
9509 fprintf (stderr, "\tvars_size = %5d\n", info->vars_size);
9510
9511 if (info->parm_size)
9512 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
9513
9514 if (info->fixed_size)
9515 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
9516
9517 if (info->gp_size)
9518 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
9519
a3170dc6
AH
9520 if (info->spe_gp_size)
9521 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
9522
4697a36c
MM
9523 if (info->fp_size)
9524 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
9525
00b960c7
AH
9526 if (info->altivec_size)
9527 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
9528
9529 if (info->vrsave_size)
9530 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
9531
9532 if (info->altivec_padding_size)
9533 fprintf (stderr, "\taltivec_padding_size= %5d\n",
9534 info->altivec_padding_size);
9535
a3170dc6
AH
9536 if (info->spe_padding_size)
9537 fprintf (stderr, "\tspe_padding_size = %5d\n",
9538 info->spe_padding_size);
9539
a4f6c312 9540 if (info->lr_size)
ed947a96 9541 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 9542
4697a36c
MM
9543 if (info->cr_size)
9544 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
9545
a4f6c312 9546 if (info->toc_size)
b6c9286a
MM
9547 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
9548
4697a36c
MM
9549 if (info->save_size)
9550 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
9551
9552 if (info->reg_size != 4)
9553 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
9554
9555 fprintf (stderr, "\n");
9878760c 9556}
71f123ca
FS
9557
9558rtx
9559rs6000_return_addr (count, frame)
9560 int count;
9561 rtx frame;
9562{
a4f6c312
SS
9563 /* Currently we don't optimize very well between prolog and body
9564 code and for PIC code the code can be actually quite bad, so
9565 don't try to be too clever here. */
f585a356 9566 if (count != 0 || flag_pic != 0)
71f123ca
FS
9567 {
9568 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
9569
9570 return
9571 gen_rtx_MEM
9572 (Pmode,
9573 memory_address
9574 (Pmode,
9575 plus_constant (copy_to_reg
9576 (gen_rtx_MEM (Pmode,
9577 memory_address (Pmode, frame))),
9578 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
9579 }
9580
9e2f7ec7 9581 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
9582}
9583
5e1bf043
DJ
9584/* Say whether a function is a candidate for sibcall handling or not.
9585 We do not allow indirect calls to be optimized into sibling calls.
9586 Also, we can't do it if there are any vector parameters; there's
9587 nowhere to put the VRsave code so it works; note that functions with
9588 vector parameters are required to have a prototype, so the argument
9589 type info must be available here. (The tail recursion case can work
9590 with vector parameters, but there's no way to distinguish here.) */
4977bab6
ZW
9591static bool
9592rs6000_function_ok_for_sibcall (decl, exp)
9593 tree decl;
9594 tree exp ATTRIBUTE_UNUSED;
5e1bf043
DJ
9595{
9596 tree type;
4977bab6 9597 if (decl)
5e1bf043
DJ
9598 {
9599 if (TARGET_ALTIVEC_VRSAVE)
9600 {
4977bab6 9601 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
9602 type; type = TREE_CHAIN (type))
9603 {
c15b529f 9604 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 9605 return false;
5e1bf043
DJ
9606 }
9607 }
9608 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 9609 || (*targetm.binds_local_p) (decl))
2bcc50d0 9610 {
4977bab6 9611 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
9612
9613 if (!lookup_attribute ("longcall", attr_list)
9614 || lookup_attribute ("shortcall", attr_list))
4977bab6 9615 return true;
2bcc50d0 9616 }
5e1bf043 9617 }
4977bab6 9618 return false;
5e1bf043
DJ
9619}
9620
71f123ca
FS
9621static int
9622rs6000_ra_ever_killed ()
9623{
9624 rtx top;
5e1bf043
DJ
9625 rtx reg;
9626 rtx insn;
71f123ca 9627
3961e8fe
RH
9628 /* Irritatingly, there are two kinds of thunks -- those created with
9629 TARGET_ASM_OUTPUT_MI_THUNK and those with DECL_THUNK_P that go
9630 through the regular part of the compiler. This is a very hacky
9631 way to tell them apart. */
9632 if (current_function_is_thunk && !no_new_pseudos)
71f123ca 9633 return 0;
eb0424da 9634
36f7e964
AH
9635 /* regs_ever_live has LR marked as used if any sibcalls are present,
9636 but this should not force saving and restoring in the
9637 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
9638 clobbers LR, so that is inappropriate. */
9639
5e1bf043
DJ
9640 /* Also, the prologue can generate a store into LR that
9641 doesn't really count, like this:
36f7e964 9642
5e1bf043
DJ
9643 move LR->R0
9644 bcl to set PIC register
9645 move LR->R31
9646 move R0->LR
36f7e964
AH
9647
9648 When we're called from the epilogue, we need to avoid counting
9649 this as a store. */
5e1bf043 9650
71f123ca
FS
9651 push_topmost_sequence ();
9652 top = get_insns ();
9653 pop_topmost_sequence ();
5e1bf043 9654 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 9655
5e1bf043
DJ
9656 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
9657 {
9658 if (INSN_P (insn))
9659 {
9660 if (FIND_REG_INC_NOTE (insn, reg))
9661 return 1;
9662 else if (GET_CODE (insn) == CALL_INSN
c15b529f 9663 && !SIBLING_CALL_P (insn))
5e1bf043 9664 return 1;
36f7e964
AH
9665 else if (set_of (reg, insn) != NULL_RTX
9666 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
9667 return 1;
9668 }
9669 }
9670 return 0;
71f123ca 9671}
4697a36c 9672\f
8cd8f856
GK
9673/* Add a REG_MAYBE_DEAD note to the insn. */
9674static void
9675rs6000_maybe_dead (insn)
9676 rtx insn;
9677{
9678 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
9679 const0_rtx,
9680 REG_NOTES (insn));
9681}
9682
9ebbca7d 9683/* Emit instructions needed to load the TOC register.
c7ca610e 9684 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 9685 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
9686
9687void
9ebbca7d
GK
9688rs6000_emit_load_toc_table (fromprolog)
9689 int fromprolog;
c7ca610e 9690{
9ebbca7d 9691 rtx dest;
1db02437 9692 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 9693
20b71b17
AM
9694 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
9695 {
9696 rtx temp = (fromprolog
9697 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
9698 : gen_reg_rtx (Pmode));
9699 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_pic_si (temp)));
9700 rs6000_maybe_dead (emit_move_insn (dest, temp));
9701 }
9702 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
9703 {
9704 char buf[30];
9705 rtx tempLR = (fromprolog
9706 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
9707 : gen_reg_rtx (Pmode));
9708 rtx temp0 = (fromprolog
9709 ? gen_rtx_REG (Pmode, 0)
9710 : gen_reg_rtx (Pmode));
9711 rtx symF;
9712
9713 /* possibly create the toc section */
9714 if (! toc_initialized)
38c1f2d7 9715 {
20b71b17
AM
9716 toc_section ();
9717 function_section (current_function_decl);
38c1f2d7 9718 }
9ebbca7d 9719
20b71b17
AM
9720 if (fromprolog)
9721 {
9722 rtx symL;
38c1f2d7 9723
20b71b17
AM
9724 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
9725 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 9726
20b71b17
AM
9727 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
9728 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9729
9730 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
9731 symF)));
9732 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
9733 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
9734 symL,
9735 symF)));
9ebbca7d
GK
9736 }
9737 else
20b71b17
AM
9738 {
9739 rtx tocsym;
9740 static int reload_toc_labelno = 0;
9741
9742 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
9743
9744 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
9745 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9746
9747 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1b (tempLR,
9748 symF,
9749 tocsym)));
9750 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
9751 rs6000_maybe_dead (emit_move_insn (temp0,
9752 gen_rtx_MEM (Pmode, dest)));
9753 }
9754 rs6000_maybe_dead (emit_insn (gen_addsi3 (dest, temp0, dest)));
9ebbca7d 9755 }
20b71b17
AM
9756 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
9757 {
9758 /* This is for AIX code running in non-PIC ELF32. */
9759 char buf[30];
9760 rtx realsym;
9761 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
9762 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9763
9764 rs6000_maybe_dead (emit_insn (gen_elf_high (dest, realsym)));
9765 rs6000_maybe_dead (emit_insn (gen_elf_low (dest, dest, realsym)));
9766 }
9767 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
9768 {
9769 if (TARGET_32BIT)
20b71b17 9770 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_si (dest)));
9ebbca7d 9771 else
20b71b17 9772 rs6000_maybe_dead (emit_insn (gen_load_toc_aix_di (dest)));
9ebbca7d 9773 }
20b71b17
AM
9774 else
9775 abort ();
9ebbca7d
GK
9776}
9777
9778int
9779get_TOC_alias_set ()
9780{
9781 static int set = -1;
9782 if (set == -1)
9783 set = new_alias_set ();
9784 return set;
9785}
9786
9787/* This retuns nonzero if the current function uses the TOC. This is
9788 determined by the presence of (unspec ... 7), which is generated by
9789 the various load_toc_* patterns. */
a4f6c312 9790
9ebbca7d
GK
9791int
9792uses_TOC ()
9793{
9794 rtx insn;
38c1f2d7 9795
9ebbca7d 9796 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2c3c49de 9797 if (INSN_P (insn))
9ebbca7d
GK
9798 {
9799 rtx pat = PATTERN (insn);
9800 int i;
9801
8cd8f856 9802 if (GET_CODE (pat) == PARALLEL)
9ebbca7d
GK
9803 for (i = 0; i < XVECLEN (PATTERN (insn), 0); i++)
9804 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == UNSPEC
9805 && XINT (XVECEXP (PATTERN (insn), 0, i), 1) == 7)
9806 return 1;
38c1f2d7 9807 }
9ebbca7d
GK
9808 return 0;
9809}
38c1f2d7 9810
9ebbca7d 9811rtx
a4f6c312 9812create_TOC_reference (symbol)
9ebbca7d
GK
9813 rtx symbol;
9814{
a8a05998
ZW
9815 return gen_rtx_PLUS (Pmode,
9816 gen_rtx_REG (Pmode, TOC_REGISTER),
9817 gen_rtx_CONST (Pmode,
9818 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 9819 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 9820}
38c1f2d7 9821
9ebbca7d
GK
9822#if TARGET_AIX
9823/* __throw will restore its own return address to be the same as the
9824 return address of the function that the throw is being made to.
9825 This is unfortunate, because we want to check the original
9826 return address to see if we need to restore the TOC.
9827 So we have to squirrel it away here.
9828 This is used only in compiling __throw and __rethrow.
c7ca610e 9829
9ebbca7d
GK
9830 Most of this code should be removed by CSE. */
9831static rtx insn_after_throw;
c7ca610e 9832
a4f6c312 9833/* This does the saving... */
9ebbca7d
GK
9834void
9835rs6000_aix_emit_builtin_unwind_init ()
9836{
9837 rtx mem;
9838 rtx stack_top = gen_reg_rtx (Pmode);
9839 rtx opcode_addr = gen_reg_rtx (Pmode);
9840
9841 insn_after_throw = gen_reg_rtx (SImode);
9842
9843 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
9844 emit_move_insn (stack_top, mem);
9845
9846 mem = gen_rtx_MEM (Pmode,
9847 gen_rtx_PLUS (Pmode, stack_top,
9848 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
9849 emit_move_insn (opcode_addr, mem);
9850 emit_move_insn (insn_after_throw, gen_rtx_MEM (SImode, opcode_addr));
c7ca610e
RK
9851}
9852
a4f6c312
SS
9853/* Emit insns to _restore_ the TOC register, at runtime (specifically
9854 in _eh.o). Only used on AIX.
9ebbca7d
GK
9855
9856 The idea is that on AIX, function calls look like this:
9857 bl somefunction-trampoline
9858 lwz r2,20(sp)
9859
a4f6c312 9860 and later,
9ebbca7d
GK
9861 somefunction-trampoline:
9862 stw r2,20(sp)
9863 ... load function address in the count register ...
9864 bctr
9865 or like this, if the linker determines that this is not a cross-module call
9866 and so the TOC need not be restored:
9867 bl somefunction
9868 nop
9869 or like this, if the compiler could determine that this is not a
9870 cross-module call:
9871 bl somefunction
9872 now, the tricky bit here is that register 2 is saved and restored
9873 by the _linker_, so we can't readily generate debugging information
9874 for it. So we need to go back up the call chain looking at the
9875 insns at return addresses to see which calls saved the TOC register
9876 and so see where it gets restored from.
9877
9878 Oh, and all this gets done in RTL inside the eh_epilogue pattern,
9879 just before the actual epilogue.
9880
9881 On the bright side, this incurs no space or time overhead unless an
9882 exception is thrown, except for the extra code in libgcc.a.
9883
9884 The parameter STACKSIZE is a register containing (at runtime)
9885 the amount to be popped off the stack in addition to the stack frame
9886 of this routine (which will be __throw or __rethrow, and so is
9887 guaranteed to have a stack frame). */
a4f6c312 9888
9ebbca7d
GK
9889void
9890rs6000_emit_eh_toc_restore (stacksize)
9891 rtx stacksize;
9892{
9893 rtx top_of_stack;
9894 rtx bottom_of_stack = gen_reg_rtx (Pmode);
9895 rtx tocompare = gen_reg_rtx (SImode);
9896 rtx opcode = gen_reg_rtx (SImode);
9897 rtx opcode_addr = gen_reg_rtx (Pmode);
9898 rtx mem;
9899 rtx loop_start = gen_label_rtx ();
9900 rtx no_toc_restore_needed = gen_label_rtx ();
9901 rtx loop_exit = gen_label_rtx ();
9902
9903 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
ba4828e0 9904 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
9905 emit_move_insn (bottom_of_stack, mem);
9906
9907 top_of_stack = expand_binop (Pmode, add_optab,
9908 bottom_of_stack, stacksize,
9909 NULL_RTX, 1, OPTAB_WIDEN);
9910
2496c7bd
LB
9911 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
9912 : 0xE8410028, SImode));
9ebbca7d
GK
9913
9914 if (insn_after_throw == NULL_RTX)
a4f6c312 9915 abort ();
9ebbca7d
GK
9916 emit_move_insn (opcode, insn_after_throw);
9917
6496a589 9918 emit_note (NULL, NOTE_INSN_LOOP_BEG);
9ebbca7d
GK
9919 emit_label (loop_start);
9920
9921 do_compare_rtx_and_jump (opcode, tocompare, NE, 1,
06f4e019 9922 SImode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
9923 no_toc_restore_needed);
9924
9925 mem = gen_rtx_MEM (Pmode,
9926 gen_rtx_PLUS (Pmode, bottom_of_stack,
9927 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
9928 emit_move_insn (gen_rtx_REG (Pmode, 2), mem);
9929
9930 emit_label (no_toc_restore_needed);
9931 do_compare_rtx_and_jump (top_of_stack, bottom_of_stack, EQ, 1,
06f4e019 9932 Pmode, NULL_RTX, NULL_RTX,
9ebbca7d
GK
9933 loop_exit);
9934
9935 mem = gen_rtx_MEM (Pmode, bottom_of_stack);
ba4828e0 9936 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
9937 emit_move_insn (bottom_of_stack, mem);
9938
9939 mem = gen_rtx_MEM (Pmode,
9940 gen_rtx_PLUS (Pmode, bottom_of_stack,
9941 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
9942 emit_move_insn (opcode_addr, mem);
9943 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
9944
6496a589 9945 emit_note (NULL, NOTE_INSN_LOOP_CONT);
9ebbca7d 9946 emit_jump (loop_start);
6496a589 9947 emit_note (NULL, NOTE_INSN_LOOP_END);
9ebbca7d
GK
9948 emit_label (loop_exit);
9949}
9950#endif /* TARGET_AIX */
38c1f2d7 9951\f
ba4828e0
RK
9952/* This ties together stack memory (MEM with an alias set of
9953 rs6000_sr_alias_set) and the change to the stack pointer. */
9954
9ebbca7d
GK
9955static void
9956rs6000_emit_stack_tie ()
9957{
ba4828e0
RK
9958 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
9959
9960 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
9961 emit_insn (gen_stack_tie (mem));
9962}
38c1f2d7 9963
9ebbca7d
GK
9964/* Emit the correct code for allocating stack space, as insns.
9965 If COPY_R12, make sure a copy of the old frame is left in r12.
9966 The generated code may use hard register 0 as a temporary. */
9967
9968static void
9969rs6000_emit_allocate_stack (size, copy_r12)
9970 HOST_WIDE_INT size;
38c1f2d7
MM
9971 int copy_r12;
9972{
9ebbca7d
GK
9973 rtx insn;
9974 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
9975 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
9976 rtx todec = GEN_INT (-size);
a157febd
GK
9977
9978 if (current_function_limit_stack)
9979 {
9980 if (REG_P (stack_limit_rtx)
9981 && REGNO (stack_limit_rtx) > 1
9982 && REGNO (stack_limit_rtx) <= 31)
9983 {
5b71a4e7 9984 emit_insn (TARGET_32BIT
9ebbca7d
GK
9985 ? gen_addsi3 (tmp_reg,
9986 stack_limit_rtx,
9987 GEN_INT (size))
9988 : gen_adddi3 (tmp_reg,
9989 stack_limit_rtx,
9990 GEN_INT (size)));
5b71a4e7 9991
9ebbca7d
GK
9992 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
9993 const0_rtx));
a157febd
GK
9994 }
9995 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 9996 && TARGET_32BIT
f607bc57 9997 && DEFAULT_ABI == ABI_V4)
a157febd 9998 {
9ebbca7d
GK
9999 rtx toload = gen_rtx_CONST (VOIDmode,
10000 gen_rtx_PLUS (Pmode,
10001 stack_limit_rtx,
10002 GEN_INT (size)));
5b71a4e7 10003
9ebbca7d
GK
10004 emit_insn (gen_elf_high (tmp_reg, toload));
10005 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
10006 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
10007 const0_rtx));
a157febd
GK
10008 }
10009 else
10010 warning ("stack limit expression is not supported");
10011 }
10012
9ebbca7d
GK
10013 if (copy_r12 || ! TARGET_UPDATE)
10014 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
10015
38c1f2d7
MM
10016 if (TARGET_UPDATE)
10017 {
9ebbca7d 10018 if (size > 32767)
38c1f2d7 10019 {
9ebbca7d
GK
10020 /* Need a note here so that try_split doesn't get confused. */
10021 if (get_last_insn() == NULL_RTX)
10022 emit_note (0, NOTE_INSN_DELETED);
10023 insn = emit_move_insn (tmp_reg, todec);
10024 try_split (PATTERN (insn), insn, 0);
10025 todec = tmp_reg;
38c1f2d7 10026 }
5b71a4e7
DE
10027
10028 insn = emit_insn (TARGET_32BIT
10029 ? gen_movsi_update (stack_reg, stack_reg,
10030 todec, stack_reg)
10031 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 10032 todec, stack_reg));
38c1f2d7
MM
10033 }
10034 else
10035 {
5b71a4e7
DE
10036 insn = emit_insn (TARGET_32BIT
10037 ? gen_addsi3 (stack_reg, stack_reg, todec)
10038 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
10039 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
10040 gen_rtx_REG (Pmode, 12));
10041 }
5b71a4e7 10042
9ebbca7d
GK
10043 RTX_FRAME_RELATED_P (insn) = 1;
10044 REG_NOTES (insn) =
10045 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10046 gen_rtx_SET (VOIDmode, stack_reg,
10047 gen_rtx_PLUS (Pmode, stack_reg,
10048 GEN_INT (-size))),
10049 REG_NOTES (insn));
10050}
10051
9aa86737
AH
10052/* Add a RTX_FRAME_RELATED note so that dwarf2out_frame_debug_expr
10053 knows that:
10054
10055 (mem (plus (blah) (regXX)))
10056
10057 is really:
10058
10059 (mem (plus (blah) (const VALUE_OF_REGXX))). */
10060
10061static void
10062altivec_frame_fixup (insn, reg, val)
10063 rtx insn, reg;
10064 HOST_WIDE_INT val;
10065{
10066 rtx real;
10067
10068 real = copy_rtx (PATTERN (insn));
10069
10070 real = replace_rtx (real, reg, GEN_INT (val));
10071
10072 RTX_FRAME_RELATED_P (insn) = 1;
10073 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10074 real,
10075 REG_NOTES (insn));
10076}
10077
a4f6c312
SS
10078/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
10079 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
10080 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
10081 deduce these equivalences by itself so it wasn't necessary to hold
10082 its hand so much. */
9ebbca7d
GK
10083
10084static void
10085rs6000_frame_related (insn, reg, val, reg2, rreg)
10086 rtx insn;
10087 rtx reg;
10088 HOST_WIDE_INT val;
10089 rtx reg2;
10090 rtx rreg;
10091{
10092 rtx real, temp;
10093
e56c4463
JL
10094 /* copy_rtx will not make unique copies of registers, so we need to
10095 ensure we don't have unwanted sharing here. */
10096 if (reg == reg2)
10097 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10098
10099 if (reg == rreg)
10100 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
10101
9ebbca7d
GK
10102 real = copy_rtx (PATTERN (insn));
10103
89e7058f
AH
10104 if (reg2 != NULL_RTX)
10105 real = replace_rtx (real, reg2, rreg);
10106
9ebbca7d
GK
10107 real = replace_rtx (real, reg,
10108 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
10109 STACK_POINTER_REGNUM),
10110 GEN_INT (val)));
10111
10112 /* We expect that 'real' is either a SET or a PARALLEL containing
10113 SETs (and possibly other stuff). In a PARALLEL, all the SETs
10114 are important so they all have to be marked RTX_FRAME_RELATED_P. */
10115
10116 if (GET_CODE (real) == SET)
10117 {
10118 rtx set = real;
10119
10120 temp = simplify_rtx (SET_SRC (set));
10121 if (temp)
10122 SET_SRC (set) = temp;
10123 temp = simplify_rtx (SET_DEST (set));
10124 if (temp)
10125 SET_DEST (set) = temp;
10126 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 10127 {
9ebbca7d
GK
10128 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10129 if (temp)
10130 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 10131 }
38c1f2d7 10132 }
9ebbca7d
GK
10133 else if (GET_CODE (real) == PARALLEL)
10134 {
10135 int i;
10136 for (i = 0; i < XVECLEN (real, 0); i++)
10137 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
10138 {
10139 rtx set = XVECEXP (real, 0, i);
10140
10141 temp = simplify_rtx (SET_SRC (set));
10142 if (temp)
10143 SET_SRC (set) = temp;
10144 temp = simplify_rtx (SET_DEST (set));
10145 if (temp)
10146 SET_DEST (set) = temp;
10147 if (GET_CODE (SET_DEST (set)) == MEM)
10148 {
10149 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
10150 if (temp)
10151 XEXP (SET_DEST (set), 0) = temp;
10152 }
10153 RTX_FRAME_RELATED_P (set) = 1;
10154 }
10155 }
10156 else
a4f6c312 10157 abort ();
9ebbca7d 10158
9ebbca7d
GK
10159 RTX_FRAME_RELATED_P (insn) = 1;
10160 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
10161 real,
10162 REG_NOTES (insn));
38c1f2d7
MM
10163}
10164
00b960c7
AH
10165/* Returns an insn that has a vrsave set operation with the
10166 appropriate CLOBBERs. */
10167
10168static rtx
9aa86737 10169generate_set_vrsave (reg, info, epiloguep)
00b960c7
AH
10170 rtx reg;
10171 rs6000_stack_t *info;
9aa86737 10172 int epiloguep;
00b960c7
AH
10173{
10174 int nclobs, i;
10175 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 10176 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 10177
a004eb82
AH
10178 clobs[0]
10179 = gen_rtx_SET (VOIDmode,
10180 vrsave,
10181 gen_rtx_UNSPEC_VOLATILE (SImode,
10182 gen_rtvec (2, reg, vrsave),
10183 30));
00b960c7
AH
10184
10185 nclobs = 1;
10186
9aa86737
AH
10187 /* We need to clobber the registers in the mask so the scheduler
10188 does not move sets to VRSAVE before sets of AltiVec registers.
10189
10190 However, if the function receives nonlocal gotos, reload will set
10191 all call saved registers live. We will end up with:
10192
10193 (set (reg 999) (mem))
10194 (parallel [ (set (reg vrsave) (unspec blah))
10195 (clobber (reg 999))])
10196
10197 The clobber will cause the store into reg 999 to be dead, and
10198 flow will attempt to delete an epilogue insn. In this case, we
10199 need an unspec use/set of the register. */
00b960c7
AH
10200
10201 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10202 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
10203 {
10204 if (!epiloguep || call_used_regs [i])
10205 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
10206 gen_rtx_REG (V4SImode, i));
10207 else
10208 {
10209 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
10210
10211 clobs[nclobs++]
a004eb82
AH
10212 = gen_rtx_SET (VOIDmode,
10213 reg,
10214 gen_rtx_UNSPEC (V4SImode,
10215 gen_rtvec (1, reg), 27));
9aa86737
AH
10216 }
10217 }
00b960c7
AH
10218
10219 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
10220
10221 for (i = 0; i < nclobs; ++i)
10222 XVECEXP (insn, 0, i) = clobs[i];
10223
10224 return insn;
10225}
10226
89e7058f
AH
10227/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
10228 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
10229
10230static void
10231emit_frame_save (frame_reg, frame_ptr, mode, regno, offset, total_size)
10232 rtx frame_reg;
10233 rtx frame_ptr;
10234 enum machine_mode mode;
10235 unsigned int regno;
10236 int offset;
10237 int total_size;
10238{
10239 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
10240 rtx replacea, replaceb;
10241
10242 int_rtx = GEN_INT (offset);
10243
10244 /* Some cases that need register indexed addressing. */
10245 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
10246 || (TARGET_SPE_ABI
10247 && SPE_VECTOR_MODE (mode)
10248 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
10249 {
10250 /* Whomever calls us must make sure r11 is available in the
10251 flow path of instructions in the prologue. */
10252 offset_rtx = gen_rtx_REG (Pmode, 11);
10253 emit_move_insn (offset_rtx, int_rtx);
10254
10255 replacea = offset_rtx;
10256 replaceb = int_rtx;
10257 }
10258 else
10259 {
10260 offset_rtx = int_rtx;
10261 replacea = NULL_RTX;
10262 replaceb = NULL_RTX;
10263 }
10264
10265 reg = gen_rtx_REG (mode, regno);
10266 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
10267 mem = gen_rtx_MEM (mode, addr);
10268 set_mem_alias_set (mem, rs6000_sr_alias_set);
10269
10270 insn = emit_move_insn (mem, reg);
10271
10272 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
10273}
10274
a3170dc6
AH
10275/* Emit an offset memory reference suitable for a frame store, while
10276 converting to a valid addressing mode. */
10277
10278static rtx
10279gen_frame_mem_offset (mode, reg, offset)
10280 enum machine_mode mode;
10281 rtx reg;
10282 int offset;
10283{
10284 rtx int_rtx, offset_rtx;
10285
10286 int_rtx = GEN_INT (offset);
10287
10288 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
10289 {
10290 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
10291 emit_move_insn (offset_rtx, int_rtx);
10292 }
10293 else
10294 offset_rtx = int_rtx;
10295
10296 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
10297}
10298
9ebbca7d
GK
10299/* Emit function prologue as insns. */
10300
9878760c 10301void
83720594 10302rs6000_emit_prologue ()
9878760c 10303{
4697a36c 10304 rs6000_stack_t *info = rs6000_stack_info ();
9ebbca7d
GK
10305 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
10306 int reg_size = TARGET_POWERPC64 ? 8 : 4;
10307 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
10308 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
10309 rtx frame_reg_rtx = sp_reg_rtx;
10310 rtx cr_save_rtx = NULL;
10311 rtx insn;
10312 int saving_FPRs_inline;
10313 int using_store_multiple;
10314 HOST_WIDE_INT sp_offset = 0;
10315
a3170dc6
AH
10316 if (TARGET_SPE_ABI)
10317 {
10318 reg_mode = V2SImode;
10319 reg_size = 8;
10320 }
10321
9ebbca7d 10322 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
a3170dc6 10323 && !TARGET_SPE_ABI
9ebbca7d
GK
10324 && info->first_gp_reg_save < 31);
10325 saving_FPRs_inline = (info->first_fp_reg_save == 64
10326 || FP_SAVE_INLINE (info->first_fp_reg_save));
10327
10328 /* For V.4, update stack before we do any saving and set back pointer. */
f607bc57 10329 if (info->push_p && DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
10330 {
10331 if (info->total_size < 32767)
10332 sp_offset = info->total_size;
10333 else
10334 frame_reg_rtx = frame_ptr_rtx;
10335 rs6000_emit_allocate_stack (info->total_size,
10336 (frame_reg_rtx != sp_reg_rtx
10337 && (info->cr_save_p
10338 || info->lr_save_p
10339 || info->first_fp_reg_save < 64
10340 || info->first_gp_reg_save < 32
10341 )));
10342 if (frame_reg_rtx != sp_reg_rtx)
10343 rs6000_emit_stack_tie ();
10344 }
10345
9aa86737
AH
10346 /* Save AltiVec registers if needed. */
10347 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
10348 {
10349 int i;
10350
10351 /* There should be a non inline version of this, for when we
10352 are saving lots of vector registers. */
10353 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
10354 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
10355 {
10356 rtx areg, savereg, mem;
10357 int offset;
10358
10359 offset = info->altivec_save_offset + sp_offset
10360 + 16 * (i - info->first_altivec_reg_save);
10361
10362 savereg = gen_rtx_REG (V4SImode, i);
10363
10364 areg = gen_rtx_REG (Pmode, 0);
10365 emit_move_insn (areg, GEN_INT (offset));
10366
10367 /* AltiVec addressing mode is [reg+reg]. */
10368 mem = gen_rtx_MEM (V4SImode,
10369 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
10370
10371 set_mem_alias_set (mem, rs6000_sr_alias_set);
10372
10373 insn = emit_move_insn (mem, savereg);
10374
10375 altivec_frame_fixup (insn, areg, offset);
10376 }
10377 }
10378
10379 /* VRSAVE is a bit vector representing which AltiVec registers
10380 are used. The OS uses this to determine which vector
10381 registers to save on a context switch. We need to save
10382 VRSAVE on the stack frame, add whatever AltiVec registers we
10383 used in this function, and do the corresponding magic in the
10384 epilogue. */
10385
10386 if (TARGET_ALTIVEC && info->vrsave_mask != 0)
10387 {
a004eb82 10388 rtx reg, mem, vrsave;
9aa86737
AH
10389 int offset;
10390
10391 /* Get VRSAVE onto a GPR. */
10392 reg = gen_rtx_REG (SImode, 12);
a004eb82 10393 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
10394 if (TARGET_MACHO)
10395 emit_insn (gen_get_vrsave_internal (reg));
10396 else
10397 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
10398
10399 /* Save VRSAVE. */
10400 offset = info->vrsave_save_offset + sp_offset;
10401 mem
10402 = gen_rtx_MEM (SImode,
10403 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
10404 set_mem_alias_set (mem, rs6000_sr_alias_set);
10405 insn = emit_move_insn (mem, reg);
10406
10407 /* Include the registers in the mask. */
10408 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
10409
10410 insn = emit_insn (generate_set_vrsave (reg, info, 0));
10411 }
10412
9ebbca7d
GK
10413 /* If we use the link register, get it into r0. */
10414 if (info->lr_save_p)
71f123ca 10415 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
10416 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10417
10418 /* If we need to save CR, put it into r12. */
10419 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
10420 {
10421 cr_save_rtx = gen_rtx_REG (SImode, 12);
10422 emit_insn (gen_movesi_from_cr (cr_save_rtx));
10423 }
10424
a4f6c312
SS
10425 /* Do any required saving of fpr's. If only one or two to save, do
10426 it ourselves. Otherwise, call function. */
9ebbca7d
GK
10427 if (saving_FPRs_inline)
10428 {
10429 int i;
10430 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
10431 if ((regs_ever_live[info->first_fp_reg_save+i]
10432 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
10433 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
10434 info->first_fp_reg_save + i,
10435 info->fp_save_offset + sp_offset + 8 * i,
10436 info->total_size);
9ebbca7d
GK
10437 }
10438 else if (info->first_fp_reg_save != 64)
10439 {
10440 int i;
10441 char rname[30];
520a57c8 10442 const char *alloc_rname;
9ebbca7d
GK
10443 rtvec p;
10444 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
10445
10446 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
10447 gen_rtx_REG (Pmode,
10448 LINK_REGISTER_REGNUM));
10449 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
10450 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 10451 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
10452 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
10453 gen_rtx_SYMBOL_REF (Pmode,
10454 alloc_rname));
10455 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
10456 {
10457 rtx addr, reg, mem;
10458 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
10459 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10460 GEN_INT (info->fp_save_offset
10461 + sp_offset + 8*i));
10462 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 10463 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10464
10465 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
10466 }
10467 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
10468 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10469 NULL_RTX, NULL_RTX);
10470 }
b6c9286a 10471
9ebbca7d
GK
10472 /* Save GPRs. This is done as a PARALLEL if we are using
10473 the store-multiple instructions. */
10474 if (using_store_multiple)
b6c9286a 10475 {
308c142a 10476 rtvec p;
9ebbca7d
GK
10477 int i;
10478 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
10479 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
10480 {
10481 rtx addr, reg, mem;
10482 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
10483 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10484 GEN_INT (info->gp_save_offset
10485 + sp_offset
10486 + reg_size * i));
10487 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 10488 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10489
10490 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
10491 }
10492 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
10493 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10494 NULL_RTX, NULL_RTX);
b6c9286a
MM
10495 }
10496 else
10497 {
9ebbca7d
GK
10498 int i;
10499 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
10500 if ((regs_ever_live[info->first_gp_reg_save+i]
10501 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 10502 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
f607bc57
ZW
10503 && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10504 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
10505 {
10506 rtx addr, reg, mem;
10507 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
10508
10509 if (TARGET_SPE_ABI)
10510 {
10511 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
10512 rtx b;
10513
10514 if (!SPE_CONST_OFFSET_OK (offset))
10515 {
10516 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
10517 emit_move_insn (b, GEN_INT (offset));
10518 }
10519 else
10520 b = GEN_INT (offset);
10521
10522 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
10523 mem = gen_rtx_MEM (V2SImode, addr);
10524 set_mem_alias_set (mem, rs6000_sr_alias_set);
10525 insn = emit_move_insn (mem, reg);
10526
10527 if (GET_CODE (b) == CONST_INT)
10528 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10529 NULL_RTX, NULL_RTX);
10530 else
10531 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10532 b, GEN_INT (offset));
10533 }
10534 else
10535 {
10536 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10537 GEN_INT (info->gp_save_offset
10538 + sp_offset
10539 + reg_size * i));
10540 mem = gen_rtx_MEM (reg_mode, addr);
10541 set_mem_alias_set (mem, rs6000_sr_alias_set);
10542
10543 insn = emit_move_insn (mem, reg);
10544 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10545 NULL_RTX, NULL_RTX);
10546 }
10547 }
9ebbca7d
GK
10548 }
10549
83720594
RH
10550 /* ??? There's no need to emit actual instructions here, but it's the
10551 easiest way to get the frame unwind information emitted. */
10552 if (current_function_calls_eh_return)
10553 {
78e1b90d
DE
10554 unsigned int i, regno;
10555
83720594
RH
10556 for (i = 0; ; ++i)
10557 {
83720594
RH
10558 regno = EH_RETURN_DATA_REGNO (i);
10559 if (regno == INVALID_REGNUM)
10560 break;
10561
89e7058f
AH
10562 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
10563 info->ehrd_offset + sp_offset
10564 + reg_size * (int) i,
10565 info->total_size);
83720594
RH
10566 }
10567 }
10568
9ebbca7d
GK
10569 /* Save lr if we used it. */
10570 if (info->lr_save_p)
10571 {
10572 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10573 GEN_INT (info->lr_save_offset + sp_offset));
10574 rtx reg = gen_rtx_REG (Pmode, 0);
10575 rtx mem = gen_rtx_MEM (Pmode, addr);
10576 /* This should not be of rs6000_sr_alias_set, because of
10577 __builtin_return_address. */
10578
10579 insn = emit_move_insn (mem, reg);
10580 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
10581 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10582 }
10583
10584 /* Save CR if we use any that must be preserved. */
10585 if (info->cr_save_p)
10586 {
10587 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10588 GEN_INT (info->cr_save_offset + sp_offset));
10589 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
10590
10591 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10592
10593 /* If r12 was used to hold the original sp, copy cr into r0 now
10594 that it's free. */
10595 if (REGNO (frame_reg_rtx) == 12)
10596 {
10597 cr_save_rtx = gen_rtx_REG (SImode, 0);
10598 emit_insn (gen_movesi_from_cr (cr_save_rtx));
10599 }
10600 insn = emit_move_insn (mem, cr_save_rtx);
10601
10602 /* Now, there's no way that dwarf2out_frame_debug_expr is going
10603 to understand '(unspec:SI [(reg:CC 68) ...] 19)'. But that's
10604 OK. All we have to do is specify that _one_ condition code
10605 register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
10606 will then restore all the call-saved registers.
10607 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 10608 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 10609 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
10610 }
10611
10612 /* Update stack and set back pointer unless this is V.4,
10613 for which it was done previously. */
f607bc57 10614 if (info->push_p && DEFAULT_ABI != ABI_V4)
9ebbca7d
GK
10615 rs6000_emit_allocate_stack (info->total_size, FALSE);
10616
10617 /* Set frame pointer, if needed. */
10618 if (frame_pointer_needed)
10619 {
a3170dc6 10620 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
10621 sp_reg_rtx);
10622 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 10623 }
9878760c 10624
1db02437 10625 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 10626 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 10627 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 10628 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
10629 {
10630 /* If emit_load_toc_table will use the link register, we need to save
10631 it. We use R11 for this purpose because emit_load_toc_table
10632 can use register 0. This allows us to use a plain 'blr' to return
10633 from the procedure more often. */
d5fa86ba
GK
10634 int save_LR_around_toc_setup = (TARGET_ELF && flag_pic != 0
10635 && ! info->lr_save_p
10636 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d
GK
10637 if (save_LR_around_toc_setup)
10638 emit_move_insn (gen_rtx_REG (Pmode, 11),
10639 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
10640
10641 rs6000_emit_load_toc_table (TRUE);
10642
10643 if (save_LR_around_toc_setup)
10644 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
10645 gen_rtx_REG (Pmode, 11));
10646 }
ee890fe2 10647
fcce224d 10648#if TARGET_MACHO
ee890fe2
SS
10649 if (DEFAULT_ABI == ABI_DARWIN
10650 && flag_pic && current_function_uses_pic_offset_table)
10651 {
10652 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 10653 const char *picbase = machopic_function_base_name ();
f51eee6a 10654 rtx src = gen_rtx_SYMBOL_REF (Pmode, ggc_alloc_string (picbase, -1));
ee890fe2 10655
f51eee6a 10656 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
10657
10658 rs6000_maybe_dead (
1db02437 10659 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
10660 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
10661 }
fcce224d 10662#endif
9ebbca7d
GK
10663}
10664
9ebbca7d 10665/* Write function prologue. */
a4f6c312 10666
08c148a8
NB
10667static void
10668rs6000_output_function_prologue (file, size)
9ebbca7d 10669 FILE *file;
08c148a8 10670 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9ebbca7d
GK
10671{
10672 rs6000_stack_t *info = rs6000_stack_info ();
10673
4697a36c
MM
10674 if (TARGET_DEBUG_STACK)
10675 debug_stack_info (info);
9878760c 10676
a4f6c312
SS
10677 /* Write .extern for any function we will call to save and restore
10678 fp values. */
10679 if (info->first_fp_reg_save < 64
10680 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 10681 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 10682 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
10683 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
10684 RESTORE_FP_SUFFIX);
9878760c 10685
c764f757
RK
10686 /* Write .extern for AIX common mode routines, if needed. */
10687 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
10688 {
f6709c70
JW
10689 fputs ("\t.extern __mulh\n", file);
10690 fputs ("\t.extern __mull\n", file);
10691 fputs ("\t.extern __divss\n", file);
10692 fputs ("\t.extern __divus\n", file);
10693 fputs ("\t.extern __quoss\n", file);
10694 fputs ("\t.extern __quous\n", file);
c764f757
RK
10695 common_mode_defined = 1;
10696 }
9878760c 10697
9ebbca7d 10698 if (! HAVE_prologue)
979721f8 10699 {
9ebbca7d 10700 start_sequence ();
9dda4cc8 10701
a4f6c312
SS
10702 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
10703 the "toplevel" insn chain. */
9ebbca7d
GK
10704 emit_note (0, NOTE_INSN_DELETED);
10705 rs6000_emit_prologue ();
10706 emit_note (0, NOTE_INSN_DELETED);
178c3eff
DJ
10707
10708 /* Expand INSN_ADDRESSES so final() doesn't crash. */
10709 {
10710 rtx insn;
10711 unsigned addr = 0;
10712 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
10713 {
10714 INSN_ADDRESSES_NEW (insn, addr);
10715 addr += 4;
10716 }
10717 }
9dda4cc8 10718
9ebbca7d 10719 if (TARGET_DEBUG_STACK)
a4f6c312
SS
10720 debug_rtx_list (get_insns (), 100);
10721 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 10722 end_sequence ();
979721f8
MM
10723 }
10724
9ebbca7d
GK
10725 rs6000_pic_labelno++;
10726}
10727
10728/* Emit function epilogue as insns.
9878760c 10729
9ebbca7d
GK
10730 At present, dwarf2out_frame_debug_expr doesn't understand
10731 register restores, so we don't bother setting RTX_FRAME_RELATED_P
10732 anywhere in the epilogue. Most of the insns below would in any case
10733 need special notes to explain where r11 is in relation to the stack. */
9878760c 10734
9ebbca7d 10735void
83720594 10736rs6000_emit_epilogue (sibcall)
9ebbca7d
GK
10737 int sibcall;
10738{
10739 rs6000_stack_t *info;
10740 int restoring_FPRs_inline;
10741 int using_load_multiple;
10742 int using_mfcr_multiple;
10743 int use_backchain_to_restore_sp;
10744 int sp_offset = 0;
10745 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
10746 rtx frame_reg_rtx = sp_reg_rtx;
10747 enum machine_mode reg_mode = TARGET_POWERPC64 ? DImode : SImode;
10748 int reg_size = TARGET_POWERPC64 ? 8 : 4;
10749 int i;
10750
a3170dc6
AH
10751 if (TARGET_SPE_ABI)
10752 {
10753 reg_mode = V2SImode;
10754 reg_size = 8;
10755 }
10756
9ebbca7d
GK
10757 info = rs6000_stack_info ();
10758 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
a3170dc6 10759 && !TARGET_SPE_ABI
9ebbca7d
GK
10760 && info->first_gp_reg_save < 31);
10761 restoring_FPRs_inline = (sibcall
83720594 10762 || current_function_calls_eh_return
9ebbca7d
GK
10763 || info->first_fp_reg_save == 64
10764 || FP_SAVE_INLINE (info->first_fp_reg_save));
10765 use_backchain_to_restore_sp = (frame_pointer_needed
10766 || current_function_calls_alloca
10767 || info->total_size > 32767);
10768 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
10769 || rs6000_cpu == PROCESSOR_PPC603
10770 || rs6000_cpu == PROCESSOR_PPC750
10771 || optimize_size);
10772
10773 /* If we have a frame pointer, a call to alloca, or a large stack
10774 frame, restore the old stack pointer using the backchain. Otherwise,
10775 we know what size to update it with. */
10776 if (use_backchain_to_restore_sp)
bacbde18 10777 {
9ebbca7d
GK
10778 /* Under V.4, don't reset the stack pointer until after we're done
10779 loading the saved registers. */
f607bc57 10780 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 10781 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 10782
9ebbca7d
GK
10783 emit_move_insn (frame_reg_rtx,
10784 gen_rtx_MEM (Pmode, sp_reg_rtx));
10785
bacbde18 10786 }
9ebbca7d 10787 else if (info->push_p)
85638c0d 10788 {
f607bc57 10789 if (DEFAULT_ABI == ABI_V4)
9ebbca7d
GK
10790 sp_offset = info->total_size;
10791 else
10792 {
10793 emit_insn (TARGET_32BIT
10794 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
10795 GEN_INT (info->total_size))
10796 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
10797 GEN_INT (info->total_size)));
10798 }
85638c0d 10799 }
9ebbca7d 10800
9aa86737
AH
10801 /* Restore AltiVec registers if needed. */
10802 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
10803 {
10804 int i;
10805
10806 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
10807 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
10808 {
10809 rtx addr, areg, mem;
10810
10811 areg = gen_rtx_REG (Pmode, 0);
10812 emit_move_insn
10813 (areg, GEN_INT (info->altivec_save_offset
10814 + sp_offset
10815 + 16 * (i - info->first_altivec_reg_save)));
10816
10817 /* AltiVec addressing mode is [reg+reg]. */
10818 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
10819 mem = gen_rtx_MEM (V4SImode, addr);
10820 set_mem_alias_set (mem, rs6000_sr_alias_set);
10821
10822 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
10823 }
10824 }
10825
10826 /* Restore VRSAVE if needed. */
10827 if (TARGET_ALTIVEC_ABI && info->vrsave_mask != 0)
10828 {
10829 rtx addr, mem, reg;
10830
10831 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10832 GEN_INT (info->vrsave_save_offset + sp_offset));
10833 mem = gen_rtx_MEM (SImode, addr);
10834 set_mem_alias_set (mem, rs6000_sr_alias_set);
10835 reg = gen_rtx_REG (SImode, 12);
10836 emit_move_insn (reg, mem);
10837
10838 emit_insn (generate_set_vrsave (reg, info, 1));
10839 }
10840
9ebbca7d
GK
10841 /* Get the old lr if we saved it. */
10842 if (info->lr_save_p)
b6c9286a 10843 {
a3170dc6
AH
10844 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
10845 info->lr_save_offset + sp_offset);
ba4828e0
RK
10846
10847 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 10848
9ebbca7d 10849 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 10850 }
9ebbca7d
GK
10851
10852 /* Get the old cr if we saved it. */
10853 if (info->cr_save_p)
10854 {
10855 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10856 GEN_INT (info->cr_save_offset + sp_offset));
10857 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
10858
10859 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 10860
9ebbca7d
GK
10861 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
10862 }
10863
10864 /* Set LR here to try to overlap restores below. */
4697a36c 10865 if (info->lr_save_p)
9ebbca7d
GK
10866 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
10867 gen_rtx_REG (Pmode, 0));
10868
83720594
RH
10869 /* Load exception handler data registers, if needed. */
10870 if (current_function_calls_eh_return)
10871 {
78e1b90d
DE
10872 unsigned int i, regno;
10873
83720594
RH
10874 for (i = 0; ; ++i)
10875 {
a3170dc6 10876 rtx mem;
83720594
RH
10877
10878 regno = EH_RETURN_DATA_REGNO (i);
10879 if (regno == INVALID_REGNUM)
10880 break;
10881
a3170dc6
AH
10882 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
10883 info->ehrd_offset + sp_offset
10884 + reg_size * (int) i);
ba4828e0 10885 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
10886
10887 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
10888 }
10889 }
9ebbca7d
GK
10890
10891 /* Restore GPRs. This is done as a PARALLEL if we are using
10892 the load-multiple instructions. */
10893 if (using_load_multiple)
979721f8 10894 {
9ebbca7d
GK
10895 rtvec p;
10896 p = rtvec_alloc (32 - info->first_gp_reg_save);
10897 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 10898 {
9ebbca7d
GK
10899 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10900 GEN_INT (info->gp_save_offset
10901 + sp_offset
10902 + reg_size * i));
10903 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
10904
10905 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10906
10907 RTVEC_ELT (p, i) =
10908 gen_rtx_SET (VOIDmode,
10909 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
10910 mem);
979721f8 10911 }
9ebbca7d 10912 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 10913 }
9ebbca7d
GK
10914 else
10915 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
10916 if ((regs_ever_live[info->first_gp_reg_save+i]
10917 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 10918 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
f607bc57
ZW
10919 && ((DEFAULT_ABI == ABI_V4 && flag_pic == 1)
10920 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
10921 {
10922 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10923 GEN_INT (info->gp_save_offset
10924 + sp_offset
10925 + reg_size * i));
10926 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 10927
a3170dc6
AH
10928 /* Restore 64-bit quantities for SPE. */
10929 if (TARGET_SPE_ABI)
10930 {
10931 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
10932 rtx b;
10933
10934 if (!SPE_CONST_OFFSET_OK (offset))
10935 {
10936 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
10937 emit_move_insn (b, GEN_INT (offset));
10938 }
10939 else
10940 b = GEN_INT (offset);
10941
10942 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
10943 mem = gen_rtx_MEM (V2SImode, addr);
10944 }
10945
ba4828e0 10946 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10947
10948 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 10949 info->first_gp_reg_save + i), mem);
9ebbca7d 10950 }
9878760c 10951
9ebbca7d
GK
10952 /* Restore fpr's if we need to do it without calling a function. */
10953 if (restoring_FPRs_inline)
10954 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
10955 if ((regs_ever_live[info->first_fp_reg_save+i]
10956 && ! call_used_regs[info->first_fp_reg_save+i]))
10957 {
10958 rtx addr, mem;
10959 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
10960 GEN_INT (info->fp_save_offset
10961 + sp_offset
a4f6c312 10962 + 8 * i));
9ebbca7d 10963 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 10964 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
10965
10966 emit_move_insn (gen_rtx_REG (DFmode,
10967 info->first_fp_reg_save + i),
10968 mem);
10969 }
8d30c4ee 10970
9ebbca7d
GK
10971 /* If we saved cr, restore it here. Just those that were used. */
10972 if (info->cr_save_p)
979721f8 10973 {
9ebbca7d 10974 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 10975 int count = 0;
9ebbca7d
GK
10976
10977 if (using_mfcr_multiple)
979721f8 10978 {
9ebbca7d
GK
10979 for (i = 0; i < 8; i++)
10980 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 10981 count++;
9ebbca7d 10982 if (count == 0)
e35b9579
GK
10983 abort ();
10984 }
10985
10986 if (using_mfcr_multiple && count > 1)
10987 {
10988 rtvec p;
10989 int ndx;
9ebbca7d 10990
e35b9579 10991 p = rtvec_alloc (count);
9ebbca7d 10992
e35b9579 10993 ndx = 0;
9ebbca7d
GK
10994 for (i = 0; i < 8; i++)
10995 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
10996 {
10997 rtvec r = rtvec_alloc (2);
10998 RTVEC_ELT (r, 0) = r12_rtx;
10999 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 11000 RTVEC_ELT (p, ndx) =
9ebbca7d
GK
11001 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
11002 gen_rtx_UNSPEC (CCmode, r, 20));
e35b9579 11003 ndx++;
9ebbca7d
GK
11004 }
11005 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
11006 if (ndx != count)
11007 abort ();
979721f8
MM
11008 }
11009 else
9ebbca7d
GK
11010 for (i = 0; i < 8; i++)
11011 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 11012 {
9ebbca7d
GK
11013 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
11014 CR0_REGNO+i),
11015 r12_rtx));
979721f8 11016 }
979721f8
MM
11017 }
11018
9ebbca7d
GK
11019 /* If this is V.4, unwind the stack pointer after all of the loads
11020 have been done. We need to emit a block here so that sched
11021 doesn't decide to move the sp change before the register restores
11022 (which may not have any obvious dependency on the stack). This
11023 doesn't hurt performance, because there is no scheduling that can
11024 be done after this point. */
f607bc57 11025 if (DEFAULT_ABI == ABI_V4)
b6c9286a 11026 {
9ebbca7d
GK
11027 if (frame_reg_rtx != sp_reg_rtx)
11028 rs6000_emit_stack_tie ();
b6c9286a 11029
9ebbca7d 11030 if (use_backchain_to_restore_sp)
b6c9286a 11031 {
9ebbca7d 11032 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 11033 }
9ebbca7d 11034 else if (sp_offset != 0)
13f1623b 11035 {
5b71a4e7 11036 emit_insn (TARGET_32BIT
9ebbca7d
GK
11037 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
11038 GEN_INT (sp_offset))
11039 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
11040 GEN_INT (sp_offset)));
13f1623b 11041 }
9ebbca7d 11042 }
b6c9286a 11043
83720594
RH
11044 if (current_function_calls_eh_return)
11045 {
11046 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 11047 emit_insn (TARGET_32BIT
83720594
RH
11048 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
11049 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
11050 }
11051
9ebbca7d
GK
11052 if (!sibcall)
11053 {
11054 rtvec p;
11055 if (! restoring_FPRs_inline)
11056 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
11057 else
11058 p = rtvec_alloc (2);
b6c9286a 11059
e35b9579
GK
11060 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
11061 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
11062 gen_rtx_REG (Pmode,
11063 LINK_REGISTER_REGNUM));
9ebbca7d
GK
11064
11065 /* If we have to restore more than two FP registers, branch to the
11066 restore function. It will return to our caller. */
11067 if (! restoring_FPRs_inline)
11068 {
11069 int i;
11070 char rname[30];
520a57c8 11071 const char *alloc_rname;
979721f8 11072
9ebbca7d
GK
11073 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
11074 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 11075 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11076 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
11077 gen_rtx_SYMBOL_REF (Pmode,
11078 alloc_rname));
b6c9286a 11079
9ebbca7d
GK
11080 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11081 {
11082 rtx addr, mem;
11083 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
11084 GEN_INT (info->fp_save_offset + 8*i));
11085 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11086 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11087
11088 RTVEC_ELT (p, i+3) =
11089 gen_rtx_SET (VOIDmode,
11090 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
11091 mem);
b6c9286a
MM
11092 }
11093 }
9ebbca7d
GK
11094
11095 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 11096 }
9878760c
RK
11097}
11098
11099/* Write function epilogue. */
11100
08c148a8
NB
11101static void
11102rs6000_output_function_epilogue (file, size)
9878760c 11103 FILE *file;
08c148a8 11104 HOST_WIDE_INT size ATTRIBUTE_UNUSED;
9878760c 11105{
4697a36c 11106 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 11107
9ebbca7d 11108 if (! HAVE_epilogue)
9878760c 11109 {
9ebbca7d
GK
11110 rtx insn = get_last_insn ();
11111 /* If the last insn was a BARRIER, we don't have to write anything except
11112 the trace table. */
11113 if (GET_CODE (insn) == NOTE)
11114 insn = prev_nonnote_insn (insn);
11115 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 11116 {
9ebbca7d
GK
11117 /* This is slightly ugly, but at least we don't have two
11118 copies of the epilogue-emitting code. */
11119 start_sequence ();
11120
11121 /* A NOTE_INSN_DELETED is supposed to be at the start
11122 and end of the "toplevel" insn chain. */
11123 emit_note (0, NOTE_INSN_DELETED);
11124 rs6000_emit_epilogue (FALSE);
11125 emit_note (0, NOTE_INSN_DELETED);
11126
178c3eff
DJ
11127 /* Expand INSN_ADDRESSES so final() doesn't crash. */
11128 {
11129 rtx insn;
11130 unsigned addr = 0;
11131 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
11132 {
11133 INSN_ADDRESSES_NEW (insn, addr);
11134 addr += 4;
11135 }
11136 }
11137
9ebbca7d 11138 if (TARGET_DEBUG_STACK)
a4f6c312
SS
11139 debug_rtx_list (get_insns (), 100);
11140 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 11141 end_sequence ();
4697a36c 11142 }
9878760c 11143 }
b4ac57ab 11144
9b30bae2 11145 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
11146 on its format.
11147
11148 We don't output a traceback table if -finhibit-size-directive was
11149 used. The documentation for -finhibit-size-directive reads
11150 ``don't output a @code{.size} assembler directive, or anything
11151 else that would cause trouble if the function is split in the
11152 middle, and the two halves are placed at locations far apart in
11153 memory.'' The traceback table has this property, since it
11154 includes the offset from the start of the function to the
4d30c363
MM
11155 traceback table itself.
11156
11157 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 11158 different traceback table. */
57ac7be9
AM
11159 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
11160 && rs6000_traceback != traceback_none)
9b30bae2 11161 {
69c75916 11162 const char *fname = NULL;
3ac88239 11163 const char *language_string = lang_hooks.name;
6041bf2f 11164 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 11165 int i;
57ac7be9
AM
11166 int optional_tbtab;
11167
11168 if (rs6000_traceback == traceback_full)
11169 optional_tbtab = 1;
11170 else if (rs6000_traceback == traceback_part)
11171 optional_tbtab = 0;
11172 else
11173 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 11174
69c75916
AM
11175 if (optional_tbtab)
11176 {
11177 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
11178 while (*fname == '.') /* V.4 encodes . in the name */
11179 fname++;
11180
11181 /* Need label immediately before tbtab, so we can compute
11182 its offset from the function start. */
11183 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
11184 ASM_OUTPUT_LABEL (file, fname);
11185 }
314fc5a9
ILT
11186
11187 /* The .tbtab pseudo-op can only be used for the first eight
11188 expressions, since it can't handle the possibly variable
11189 length fields that follow. However, if you omit the optional
11190 fields, the assembler outputs zeros for all optional fields
11191 anyways, giving each variable length field is minimum length
11192 (as defined in sys/debug.h). Thus we can not use the .tbtab
11193 pseudo-op at all. */
11194
11195 /* An all-zero word flags the start of the tbtab, for debuggers
11196 that have to find it by searching forward from the entry
11197 point or from the current pc. */
19d2d16f 11198 fputs ("\t.long 0\n", file);
314fc5a9
ILT
11199
11200 /* Tbtab format type. Use format type 0. */
19d2d16f 11201 fputs ("\t.byte 0,", file);
314fc5a9
ILT
11202
11203 /* Language type. Unfortunately, there doesn't seem to be any
11204 official way to get this info, so we use language_string. C
11205 is 0. C++ is 9. No number defined for Obj-C, so use the
9517ead8 11206 value for C for now. There is no official value for Java,
6f573ff9 11207 although IBM appears to be using 13. There is no official value
f710504c 11208 for Chill, so we've chosen 44 pseudo-randomly. */
314fc5a9 11209 if (! strcmp (language_string, "GNU C")
e2c953b6 11210 || ! strcmp (language_string, "GNU Objective-C"))
314fc5a9
ILT
11211 i = 0;
11212 else if (! strcmp (language_string, "GNU F77"))
11213 i = 1;
11214 else if (! strcmp (language_string, "GNU Ada"))
11215 i = 3;
8b83775b 11216 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9
ILT
11217 i = 2;
11218 else if (! strcmp (language_string, "GNU C++"))
11219 i = 9;
9517ead8
AG
11220 else if (! strcmp (language_string, "GNU Java"))
11221 i = 13;
6f573ff9
JL
11222 else if (! strcmp (language_string, "GNU CHILL"))
11223 i = 44;
314fc5a9
ILT
11224 else
11225 abort ();
11226 fprintf (file, "%d,", i);
11227
11228 /* 8 single bit fields: global linkage (not set for C extern linkage,
11229 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
11230 from start of procedure stored in tbtab, internal function, function
11231 has controlled storage, function has no toc, function uses fp,
11232 function logs/aborts fp operations. */
11233 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
11234 fprintf (file, "%d,",
11235 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
11236
11237 /* 6 bitfields: function is interrupt handler, name present in
11238 proc table, function calls alloca, on condition directives
11239 (controls stack walks, 3 bits), saves condition reg, saves
11240 link reg. */
11241 /* The `function calls alloca' bit seems to be set whenever reg 31 is
11242 set up as a frame pointer, even when there is no alloca call. */
11243 fprintf (file, "%d,",
6041bf2f
DE
11244 ((optional_tbtab << 6)
11245 | ((optional_tbtab & frame_pointer_needed) << 5)
11246 | (info->cr_save_p << 1)
11247 | (info->lr_save_p)));
314fc5a9 11248
6041bf2f 11249 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
11250 (6 bits). */
11251 fprintf (file, "%d,",
4697a36c 11252 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
11253
11254 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
11255 fprintf (file, "%d,", (32 - first_reg_to_save ()));
11256
6041bf2f
DE
11257 if (optional_tbtab)
11258 {
11259 /* Compute the parameter info from the function decl argument
11260 list. */
11261 tree decl;
11262 int next_parm_info_bit = 31;
314fc5a9 11263
6041bf2f
DE
11264 for (decl = DECL_ARGUMENTS (current_function_decl);
11265 decl; decl = TREE_CHAIN (decl))
11266 {
11267 rtx parameter = DECL_INCOMING_RTL (decl);
11268 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 11269
6041bf2f
DE
11270 if (GET_CODE (parameter) == REG)
11271 {
11272 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
11273 {
11274 int bits;
11275
11276 float_parms++;
11277
11278 if (mode == SFmode)
11279 bits = 0x2;
fcce224d 11280 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
11281 bits = 0x3;
11282 else
11283 abort ();
11284
11285 /* If only one bit will fit, don't or in this entry. */
11286 if (next_parm_info_bit > 0)
11287 parm_info |= (bits << (next_parm_info_bit - 1));
11288 next_parm_info_bit -= 2;
11289 }
11290 else
11291 {
11292 fixed_parms += ((GET_MODE_SIZE (mode)
11293 + (UNITS_PER_WORD - 1))
11294 / UNITS_PER_WORD);
11295 next_parm_info_bit -= 1;
11296 }
11297 }
11298 }
11299 }
314fc5a9
ILT
11300
11301 /* Number of fixed point parameters. */
11302 /* This is actually the number of words of fixed point parameters; thus
11303 an 8 byte struct counts as 2; and thus the maximum value is 8. */
11304 fprintf (file, "%d,", fixed_parms);
11305
11306 /* 2 bitfields: number of floating point parameters (7 bits), parameters
11307 all on stack. */
11308 /* This is actually the number of fp registers that hold parameters;
11309 and thus the maximum value is 13. */
11310 /* Set parameters on stack bit if parameters are not in their original
11311 registers, regardless of whether they are on the stack? Xlc
11312 seems to set the bit when not optimizing. */
11313 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
11314
6041bf2f
DE
11315 if (! optional_tbtab)
11316 return;
11317
314fc5a9
ILT
11318 /* Optional fields follow. Some are variable length. */
11319
11320 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
11321 11 double float. */
11322 /* There is an entry for each parameter in a register, in the order that
11323 they occur in the parameter list. Any intervening arguments on the
11324 stack are ignored. If the list overflows a long (max possible length
11325 34 bits) then completely leave off all elements that don't fit. */
11326 /* Only emit this long if there was at least one parameter. */
11327 if (fixed_parms || float_parms)
11328 fprintf (file, "\t.long %d\n", parm_info);
11329
11330 /* Offset from start of code to tb table. */
19d2d16f 11331 fputs ("\t.long ", file);
314fc5a9 11332 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
11333#if TARGET_AIX
11334 RS6000_OUTPUT_BASENAME (file, fname);
11335#else
9ebbca7d 11336 assemble_name (file, fname);
54ee9799 11337#endif
19d2d16f 11338 fputs ("-.", file);
54ee9799
DE
11339#if TARGET_AIX
11340 RS6000_OUTPUT_BASENAME (file, fname);
11341#else
9ebbca7d 11342 assemble_name (file, fname);
54ee9799 11343#endif
19d2d16f 11344 putc ('\n', file);
314fc5a9
ILT
11345
11346 /* Interrupt handler mask. */
11347 /* Omit this long, since we never set the interrupt handler bit
11348 above. */
11349
11350 /* Number of CTL (controlled storage) anchors. */
11351 /* Omit this long, since the has_ctl bit is never set above. */
11352
11353 /* Displacement into stack of each CTL anchor. */
11354 /* Omit this list of longs, because there are no CTL anchors. */
11355
11356 /* Length of function name. */
69c75916
AM
11357 if (*fname == '*')
11358 ++fname;
296b8152 11359 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
11360
11361 /* Function name. */
11362 assemble_string (fname, strlen (fname));
11363
11364 /* Register for alloca automatic storage; this is always reg 31.
11365 Only emit this if the alloca bit was set above. */
11366 if (frame_pointer_needed)
19d2d16f 11367 fputs ("\t.byte 31\n", file);
b1765bde
DE
11368
11369 fputs ("\t.align 2\n", file);
9b30bae2 11370 }
9878760c 11371}
17167fd8 11372\f
a4f6c312
SS
11373/* A C compound statement that outputs the assembler code for a thunk
11374 function, used to implement C++ virtual function calls with
11375 multiple inheritance. The thunk acts as a wrapper around a virtual
11376 function, adjusting the implicit object parameter before handing
11377 control off to the real function.
11378
11379 First, emit code to add the integer DELTA to the location that
11380 contains the incoming first argument. Assume that this argument
11381 contains a pointer, and is the one used to pass the `this' pointer
11382 in C++. This is the incoming argument *before* the function
11383 prologue, e.g. `%o0' on a sparc. The addition must preserve the
11384 values of all other incoming arguments.
17167fd8
MM
11385
11386 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
11387 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
11388 not touch the return address. Hence returning from FUNCTION will
11389 return to whoever called the current `thunk'.
17167fd8 11390
a4f6c312
SS
11391 The effect must be as if FUNCTION had been called directly with the
11392 adjusted first argument. This macro is responsible for emitting
11393 all of the code for a thunk function; output_function_prologue()
11394 and output_function_epilogue() are not invoked.
17167fd8 11395
a4f6c312
SS
11396 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
11397 been extracted from it.) It might possibly be useful on some
11398 targets, but probably not.
17167fd8 11399
a4f6c312
SS
11400 If you do not define this macro, the target-independent code in the
11401 C++ frontend will generate a less efficient heavyweight thunk that
11402 calls FUNCTION instead of jumping to it. The generic approach does
11403 not support varargs. */
17167fd8 11404
3961e8fe
RH
11405static void
11406rs6000_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function)
17167fd8 11407 FILE *file;
d330fd93 11408 tree thunk_fndecl ATTRIBUTE_UNUSED;
eb0424da 11409 HOST_WIDE_INT delta;
5b71a4e7 11410 HOST_WIDE_INT vcall_offset;
17167fd8
MM
11411 tree function;
11412{
5b71a4e7 11413 rtx this, insn, funexp;
17167fd8 11414
5b71a4e7
DE
11415 reload_completed = 1;
11416 no_new_pseudos = 1;
56a7189a 11417
5b71a4e7
DE
11418 /* Mark the end of the (empty) prologue. */
11419 emit_note (NULL, NOTE_INSN_PROLOGUE_END);
17167fd8 11420
5b71a4e7
DE
11421 /* Find the "this" pointer. If the function returns a structure,
11422 the structure return pointer is in r3. */
11423 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
11424 this = gen_rtx_REG (Pmode, 4);
56a7189a 11425 else
5b71a4e7 11426 this = gen_rtx_REG (Pmode, 3);
17167fd8 11427
5b71a4e7
DE
11428 /* Apply the constant offset, if required. */
11429 if (delta)
11430 {
11431 rtx delta_rtx = GEN_INT (delta);
11432 emit_insn (TARGET_32BIT
11433 ? gen_addsi3 (this, this, delta_rtx)
11434 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
11435 }
11436
5b71a4e7
DE
11437 /* Apply the offset from the vtable, if required. */
11438 if (vcall_offset)
17167fd8 11439 {
5b71a4e7
DE
11440 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
11441 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 11442
5b71a4e7
DE
11443 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
11444 emit_insn (TARGET_32BIT
11445 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
11446 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
11447 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
11448 emit_insn (TARGET_32BIT
11449 ? gen_addsi3 (this, this, tmp)
11450 : gen_adddi3 (this, this, tmp));
17167fd8
MM
11451 }
11452
5b71a4e7
DE
11453 /* Generate a tail call to the target function. */
11454 if (!TREE_USED (function))
11455 {
11456 assemble_external (function);
11457 TREE_USED (function) = 1;
11458 }
11459 funexp = XEXP (DECL_RTL (function), 0);
42820a49 11460
5b71a4e7
DE
11461 SYMBOL_REF_FLAG (funexp) = 0;
11462 if (current_file_function_operand (funexp, VOIDmode)
a5c76ee6
ZW
11463 && (! lookup_attribute ("longcall",
11464 TYPE_ATTRIBUTES (TREE_TYPE (function)))
11465 || lookup_attribute ("shortcall",
11466 TYPE_ATTRIBUTES (TREE_TYPE (function)))))
5b71a4e7 11467 SYMBOL_REF_FLAG (funexp) = 1;
17167fd8 11468
5b71a4e7 11469 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
11470
11471#if TARGET_MACHO
5b71a4e7
DE
11472 if (flag_pic)
11473 funexp = machopic_indirect_call_target (funexp);
ee890fe2 11474#endif
5b71a4e7
DE
11475
11476 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
11477 generate sibcall RTL explicitly to avoid constraint abort. */
11478 insn = emit_call_insn (
11479 gen_rtx_PARALLEL (VOIDmode,
11480 gen_rtvec (4,
11481 gen_rtx_CALL (VOIDmode,
11482 funexp, const0_rtx),
11483 gen_rtx_USE (VOIDmode, const0_rtx),
11484 gen_rtx_USE (VOIDmode,
11485 gen_rtx_REG (SImode,
11486 LINK_REGISTER_REGNUM)),
11487 gen_rtx_RETURN (VOIDmode))));
11488 SIBLING_CALL_P (insn) = 1;
11489 emit_barrier ();
11490
11491 /* Run just enough of rest_of_compilation to get the insns emitted.
11492 There's not really enough bulk here to make other passes such as
11493 instruction scheduling worth while. Note that use_thunk calls
11494 assemble_start_function and assemble_end_function. */
11495 insn = get_insns ();
11496 shorten_branches (insn);
11497 final_start_function (insn, file, 1);
11498 final (insn, file, 1, 0);
11499 final_end_function ();
11500
11501 reload_completed = 0;
11502 no_new_pseudos = 0;
9ebbca7d 11503}
9ebbca7d
GK
11504\f
11505/* A quick summary of the various types of 'constant-pool tables'
11506 under PowerPC:
11507
11508 Target Flags Name One table per
11509 AIX (none) AIX TOC object file
11510 AIX -mfull-toc AIX TOC object file
11511 AIX -mminimal-toc AIX minimal TOC translation unit
11512 SVR4/EABI (none) SVR4 SDATA object file
11513 SVR4/EABI -fpic SVR4 pic object file
11514 SVR4/EABI -fPIC SVR4 PIC translation unit
11515 SVR4/EABI -mrelocatable EABI TOC function
11516 SVR4/EABI -maix AIX TOC object file
11517 SVR4/EABI -maix -mminimal-toc
11518 AIX minimal TOC translation unit
11519
11520 Name Reg. Set by entries contains:
11521 made by addrs? fp? sum?
11522
11523 AIX TOC 2 crt0 as Y option option
11524 AIX minimal TOC 30 prolog gcc Y Y option
11525 SVR4 SDATA 13 crt0 gcc N Y N
11526 SVR4 pic 30 prolog ld Y not yet N
11527 SVR4 PIC 30 prolog gcc Y option option
11528 EABI TOC 30 prolog gcc Y option option
11529
11530*/
11531
9ebbca7d
GK
11532/* Hash functions for the hash table. */
11533
11534static unsigned
11535rs6000_hash_constant (k)
11536 rtx k;
11537{
46b33600
RH
11538 enum rtx_code code = GET_CODE (k);
11539 enum machine_mode mode = GET_MODE (k);
11540 unsigned result = (code << 3) ^ mode;
11541 const char *format;
11542 int flen, fidx;
9ebbca7d 11543
46b33600
RH
11544 format = GET_RTX_FORMAT (code);
11545 flen = strlen (format);
11546 fidx = 0;
9ebbca7d 11547
46b33600
RH
11548 switch (code)
11549 {
11550 case LABEL_REF:
11551 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
11552
11553 case CONST_DOUBLE:
11554 if (mode != VOIDmode)
11555 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
11556 flen = 2;
11557 break;
11558
11559 case CODE_LABEL:
11560 fidx = 3;
11561 break;
11562
11563 default:
11564 break;
11565 }
9ebbca7d
GK
11566
11567 for (; fidx < flen; fidx++)
11568 switch (format[fidx])
11569 {
11570 case 's':
11571 {
11572 unsigned i, len;
11573 const char *str = XSTR (k, fidx);
11574 len = strlen (str);
11575 result = result * 613 + len;
11576 for (i = 0; i < len; i++)
11577 result = result * 613 + (unsigned) str[i];
17167fd8
MM
11578 break;
11579 }
9ebbca7d
GK
11580 case 'u':
11581 case 'e':
11582 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
11583 break;
11584 case 'i':
11585 case 'n':
11586 result = result * 613 + (unsigned) XINT (k, fidx);
11587 break;
11588 case 'w':
11589 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
11590 result = result * 613 + (unsigned) XWINT (k, fidx);
11591 else
11592 {
11593 size_t i;
11594 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
11595 result = result * 613 + (unsigned) (XWINT (k, fidx)
11596 >> CHAR_BIT * i);
11597 }
11598 break;
11599 default:
a4f6c312 11600 abort ();
9ebbca7d 11601 }
46b33600 11602
9ebbca7d
GK
11603 return result;
11604}
11605
11606static unsigned
11607toc_hash_function (hash_entry)
11608 const void * hash_entry;
11609{
a9098fd0
GK
11610 const struct toc_hash_struct *thc =
11611 (const struct toc_hash_struct *) hash_entry;
11612 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
11613}
11614
11615/* Compare H1 and H2 for equivalence. */
11616
11617static int
11618toc_hash_eq (h1, h2)
11619 const void * h1;
11620 const void * h2;
11621{
11622 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
11623 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
11624
a9098fd0
GK
11625 if (((const struct toc_hash_struct *) h1)->key_mode
11626 != ((const struct toc_hash_struct *) h2)->key_mode)
11627 return 0;
11628
5692c7bc 11629 return rtx_equal_p (r1, r2);
9ebbca7d
GK
11630}
11631
28e510bd
MM
11632/* These are the names given by the C++ front-end to vtables, and
11633 vtable-like objects. Ideally, this logic should not be here;
11634 instead, there should be some programmatic way of inquiring as
11635 to whether or not an object is a vtable. */
11636
11637#define VTABLE_NAME_P(NAME) \
11638 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
11639 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
11640 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
11641 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
11642
11643void
11644rs6000_output_symbol_ref (file, x)
11645 FILE *file;
11646 rtx x;
11647{
11648 /* Currently C++ toc references to vtables can be emitted before it
11649 is decided whether the vtable is public or private. If this is
11650 the case, then the linker will eventually complain that there is
11651 a reference to an unknown section. Thus, for vtables only,
11652 we emit the TOC reference to reference the symbol and not the
11653 section. */
11654 const char *name = XSTR (x, 0);
54ee9799
DE
11655
11656 if (VTABLE_NAME_P (name))
11657 {
11658 RS6000_OUTPUT_BASENAME (file, name);
11659 }
11660 else
11661 assemble_name (file, name);
28e510bd
MM
11662}
11663
a4f6c312
SS
11664/* Output a TOC entry. We derive the entry name from what is being
11665 written. */
9878760c
RK
11666
11667void
a9098fd0 11668output_toc (file, x, labelno, mode)
9878760c
RK
11669 FILE *file;
11670 rtx x;
11671 int labelno;
a9098fd0 11672 enum machine_mode mode;
9878760c
RK
11673{
11674 char buf[256];
3cce094d 11675 const char *name = buf;
ec940faa 11676 const char *real_name;
9878760c
RK
11677 rtx base = x;
11678 int offset = 0;
11679
4697a36c
MM
11680 if (TARGET_NO_TOC)
11681 abort ();
11682
9ebbca7d
GK
11683 /* When the linker won't eliminate them, don't output duplicate
11684 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
11685 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
11686 CODE_LABELs. */
11687 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
11688 {
11689 struct toc_hash_struct *h;
11690 void * * found;
11691
17211ab5
GK
11692 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
11693 time because GGC is not initialised at that point. */
11694 if (toc_hash_table == NULL)
11695 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
11696 toc_hash_eq, NULL);
11697
9ebbca7d
GK
11698 h = ggc_alloc (sizeof (*h));
11699 h->key = x;
a9098fd0 11700 h->key_mode = mode;
9ebbca7d
GK
11701 h->labelno = labelno;
11702
11703 found = htab_find_slot (toc_hash_table, h, 1);
11704 if (*found == NULL)
11705 *found = h;
11706 else /* This is indeed a duplicate.
11707 Set this label equal to that label. */
11708 {
11709 fputs ("\t.set ", file);
11710 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
11711 fprintf (file, "%d,", labelno);
11712 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
11713 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
11714 found)->labelno));
11715 return;
11716 }
11717 }
11718
11719 /* If we're going to put a double constant in the TOC, make sure it's
11720 aligned properly when strict alignment is on. */
ff1720ed
RK
11721 if (GET_CODE (x) == CONST_DOUBLE
11722 && STRICT_ALIGNMENT
a9098fd0 11723 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
11724 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
11725 ASM_OUTPUT_ALIGN (file, 3);
11726 }
11727
4977bab6 11728 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 11729
37c37a57
RK
11730 /* Handle FP constants specially. Note that if we have a minimal
11731 TOC, things we put here aren't actually in the TOC, so we can allow
11732 FP constants. */
fcce224d
DE
11733 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
11734 {
11735 REAL_VALUE_TYPE rv;
11736 long k[4];
11737
11738 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11739 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
11740
11741 if (TARGET_64BIT)
11742 {
11743 if (TARGET_MINIMAL_TOC)
11744 fputs (DOUBLE_INT_ASM_OP, file);
11745 else
11746 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
11747 k[0] & 0xffffffff, k[1] & 0xffffffff,
11748 k[2] & 0xffffffff, k[3] & 0xffffffff);
11749 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
11750 k[0] & 0xffffffff, k[1] & 0xffffffff,
11751 k[2] & 0xffffffff, k[3] & 0xffffffff);
11752 return;
11753 }
11754 else
11755 {
11756 if (TARGET_MINIMAL_TOC)
11757 fputs ("\t.long ", file);
11758 else
11759 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
11760 k[0] & 0xffffffff, k[1] & 0xffffffff,
11761 k[2] & 0xffffffff, k[3] & 0xffffffff);
11762 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
11763 k[0] & 0xffffffff, k[1] & 0xffffffff,
11764 k[2] & 0xffffffff, k[3] & 0xffffffff);
11765 return;
11766 }
11767 }
11768 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 11769 {
042259f2
DE
11770 REAL_VALUE_TYPE rv;
11771 long k[2];
0adc764e 11772
042259f2
DE
11773 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11774 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 11775
13ded975
DE
11776 if (TARGET_64BIT)
11777 {
11778 if (TARGET_MINIMAL_TOC)
2bfcf297 11779 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 11780 else
2f0552b6
AM
11781 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
11782 k[0] & 0xffffffff, k[1] & 0xffffffff);
11783 fprintf (file, "0x%lx%08lx\n",
11784 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
11785 return;
11786 }
1875cc88 11787 else
13ded975
DE
11788 {
11789 if (TARGET_MINIMAL_TOC)
2bfcf297 11790 fputs ("\t.long ", file);
13ded975 11791 else
2f0552b6
AM
11792 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
11793 k[0] & 0xffffffff, k[1] & 0xffffffff);
11794 fprintf (file, "0x%lx,0x%lx\n",
11795 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
11796 return;
11797 }
9878760c 11798 }
a9098fd0 11799 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 11800 {
042259f2
DE
11801 REAL_VALUE_TYPE rv;
11802 long l;
9878760c 11803
042259f2
DE
11804 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
11805 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
11806
31bfaa0b
DE
11807 if (TARGET_64BIT)
11808 {
11809 if (TARGET_MINIMAL_TOC)
2bfcf297 11810 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 11811 else
2f0552b6
AM
11812 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
11813 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
11814 return;
11815 }
042259f2 11816 else
31bfaa0b
DE
11817 {
11818 if (TARGET_MINIMAL_TOC)
2bfcf297 11819 fputs ("\t.long ", file);
31bfaa0b 11820 else
2f0552b6
AM
11821 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
11822 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
11823 return;
11824 }
042259f2 11825 }
f176e826 11826 else if (GET_MODE (x) == VOIDmode
a9098fd0 11827 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 11828 {
e2c953b6 11829 unsigned HOST_WIDE_INT low;
042259f2
DE
11830 HOST_WIDE_INT high;
11831
11832 if (GET_CODE (x) == CONST_DOUBLE)
11833 {
11834 low = CONST_DOUBLE_LOW (x);
11835 high = CONST_DOUBLE_HIGH (x);
11836 }
11837 else
11838#if HOST_BITS_PER_WIDE_INT == 32
11839 {
11840 low = INTVAL (x);
0858c623 11841 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
11842 }
11843#else
11844 {
0858c623 11845 low = INTVAL (x) & 0xffffffff;
042259f2
DE
11846 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
11847 }
11848#endif
9878760c 11849
a9098fd0
GK
11850 /* TOC entries are always Pmode-sized, but since this
11851 is a bigendian machine then if we're putting smaller
11852 integer constants in the TOC we have to pad them.
11853 (This is still a win over putting the constants in
11854 a separate constant pool, because then we'd have
02a4ec28
FS
11855 to have both a TOC entry _and_ the actual constant.)
11856
11857 For a 32-bit target, CONST_INT values are loaded and shifted
11858 entirely within `low' and can be stored in one TOC entry. */
11859
11860 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 11861 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
11862
11863 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
11864 {
11865#if HOST_BITS_PER_WIDE_INT == 32
11866 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
11867 POINTER_SIZE, &low, &high, 0);
11868#else
11869 low |= high << 32;
11870 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
11871 high = (HOST_WIDE_INT) low >> 32;
11872 low &= 0xffffffff;
11873#endif
11874 }
a9098fd0 11875
13ded975
DE
11876 if (TARGET_64BIT)
11877 {
11878 if (TARGET_MINIMAL_TOC)
2bfcf297 11879 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 11880 else
2f0552b6
AM
11881 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
11882 (long) high & 0xffffffff, (long) low & 0xffffffff);
11883 fprintf (file, "0x%lx%08lx\n",
11884 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
11885 return;
11886 }
1875cc88 11887 else
13ded975 11888 {
02a4ec28
FS
11889 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
11890 {
11891 if (TARGET_MINIMAL_TOC)
2bfcf297 11892 fputs ("\t.long ", file);
02a4ec28 11893 else
2bfcf297 11894 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
11895 (long) high & 0xffffffff, (long) low & 0xffffffff);
11896 fprintf (file, "0x%lx,0x%lx\n",
11897 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 11898 }
13ded975 11899 else
02a4ec28
FS
11900 {
11901 if (TARGET_MINIMAL_TOC)
2bfcf297 11902 fputs ("\t.long ", file);
02a4ec28 11903 else
2f0552b6
AM
11904 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
11905 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 11906 }
13ded975
DE
11907 return;
11908 }
9878760c
RK
11909 }
11910
11911 if (GET_CODE (x) == CONST)
11912 {
2bfcf297
DB
11913 if (GET_CODE (XEXP (x, 0)) != PLUS)
11914 abort ();
11915
9878760c
RK
11916 base = XEXP (XEXP (x, 0), 0);
11917 offset = INTVAL (XEXP (XEXP (x, 0), 1));
11918 }
11919
11920 if (GET_CODE (base) == SYMBOL_REF)
11921 name = XSTR (base, 0);
11922 else if (GET_CODE (base) == LABEL_REF)
11923 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
11924 else if (GET_CODE (base) == CODE_LABEL)
11925 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
11926 else
11927 abort ();
11928
772c5265 11929 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 11930 if (TARGET_MINIMAL_TOC)
2bfcf297 11931 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
11932 else
11933 {
b6c9286a 11934 fprintf (file, "\t.tc %s", real_name);
9878760c 11935
1875cc88
JW
11936 if (offset < 0)
11937 fprintf (file, ".N%d", - offset);
11938 else if (offset)
11939 fprintf (file, ".P%d", offset);
9878760c 11940
19d2d16f 11941 fputs ("[TC],", file);
1875cc88 11942 }
581bc4de
MM
11943
11944 /* Currently C++ toc references to vtables can be emitted before it
11945 is decided whether the vtable is public or private. If this is
11946 the case, then the linker will eventually complain that there is
11947 a TOC reference to an unknown section. Thus, for vtables only,
11948 we emit the TOC reference to reference the symbol and not the
11949 section. */
28e510bd 11950 if (VTABLE_NAME_P (name))
581bc4de 11951 {
54ee9799 11952 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
11953 if (offset < 0)
11954 fprintf (file, "%d", offset);
11955 else if (offset > 0)
11956 fprintf (file, "+%d", offset);
11957 }
11958 else
11959 output_addr_const (file, x);
19d2d16f 11960 putc ('\n', file);
9878760c
RK
11961}
11962\f
11963/* Output an assembler pseudo-op to write an ASCII string of N characters
11964 starting at P to FILE.
11965
11966 On the RS/6000, we have to do this using the .byte operation and
11967 write out special characters outside the quoted string.
11968 Also, the assembler is broken; very long strings are truncated,
a4f6c312 11969 so we must artificially break them up early. */
9878760c
RK
11970
11971void
11972output_ascii (file, p, n)
11973 FILE *file;
d330fd93 11974 const char *p;
9878760c
RK
11975 int n;
11976{
11977 char c;
11978 int i, count_string;
d330fd93
KG
11979 const char *for_string = "\t.byte \"";
11980 const char *for_decimal = "\t.byte ";
11981 const char *to_close = NULL;
9878760c
RK
11982
11983 count_string = 0;
11984 for (i = 0; i < n; i++)
11985 {
11986 c = *p++;
11987 if (c >= ' ' && c < 0177)
11988 {
11989 if (for_string)
11990 fputs (for_string, file);
11991 putc (c, file);
11992
11993 /* Write two quotes to get one. */
11994 if (c == '"')
11995 {
11996 putc (c, file);
11997 ++count_string;
11998 }
11999
12000 for_string = NULL;
12001 for_decimal = "\"\n\t.byte ";
12002 to_close = "\"\n";
12003 ++count_string;
12004
12005 if (count_string >= 512)
12006 {
12007 fputs (to_close, file);
12008
12009 for_string = "\t.byte \"";
12010 for_decimal = "\t.byte ";
12011 to_close = NULL;
12012 count_string = 0;
12013 }
12014 }
12015 else
12016 {
12017 if (for_decimal)
12018 fputs (for_decimal, file);
12019 fprintf (file, "%d", c);
12020
12021 for_string = "\n\t.byte \"";
12022 for_decimal = ", ";
12023 to_close = "\n";
12024 count_string = 0;
12025 }
12026 }
12027
12028 /* Now close the string if we have written one. Then end the line. */
12029 if (to_close)
9ebbca7d 12030 fputs (to_close, file);
9878760c
RK
12031}
12032\f
12033/* Generate a unique section name for FILENAME for a section type
12034 represented by SECTION_DESC. Output goes into BUF.
12035
12036 SECTION_DESC can be any string, as long as it is different for each
12037 possible section type.
12038
12039 We name the section in the same manner as xlc. The name begins with an
12040 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
12041 names) with the last period replaced by the string SECTION_DESC. If
12042 FILENAME does not contain a period, SECTION_DESC is appended to the end of
12043 the name. */
9878760c
RK
12044
12045void
12046rs6000_gen_section_name (buf, filename, section_desc)
12047 char **buf;
9ebbca7d
GK
12048 const char *filename;
12049 const char *section_desc;
9878760c 12050{
9ebbca7d 12051 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
12052 char *p;
12053 int len;
9878760c
RK
12054
12055 after_last_slash = filename;
12056 for (q = filename; *q; q++)
11e5fe42
RK
12057 {
12058 if (*q == '/')
12059 after_last_slash = q + 1;
12060 else if (*q == '.')
12061 last_period = q;
12062 }
9878760c 12063
11e5fe42 12064 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 12065 *buf = (char *) xmalloc (len);
9878760c
RK
12066
12067 p = *buf;
12068 *p++ = '_';
12069
12070 for (q = after_last_slash; *q; q++)
12071 {
11e5fe42 12072 if (q == last_period)
9878760c
RK
12073 {
12074 strcpy (p, section_desc);
12075 p += strlen (section_desc);
e3981aab 12076 break;
9878760c
RK
12077 }
12078
e9a780ec 12079 else if (ISALNUM (*q))
9878760c
RK
12080 *p++ = *q;
12081 }
12082
11e5fe42 12083 if (last_period == 0)
9878760c
RK
12084 strcpy (p, section_desc);
12085 else
12086 *p = '\0';
12087}
e165f3f0 12088\f
a4f6c312 12089/* Emit profile function. */
411707f4 12090
411707f4
CC
12091void
12092output_profile_hook (labelno)
57ac7be9 12093 int labelno ATTRIBUTE_UNUSED;
411707f4 12094{
8480e480
CC
12095 if (DEFAULT_ABI == ABI_AIX)
12096 {
57ac7be9
AM
12097#ifdef NO_PROFILE_COUNTERS
12098 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
12099#else
8480e480 12100 char buf[30];
40501e5f 12101 const char *label_name;
8480e480 12102 rtx fun;
411707f4 12103
8480e480 12104 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
772c5265 12105 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
8480e480 12106 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 12107
8480e480
CC
12108 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
12109 fun, Pmode);
57ac7be9 12110#endif
8480e480 12111 }
ee890fe2
SS
12112 else if (DEFAULT_ABI == ABI_DARWIN)
12113 {
d5fa86ba 12114 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
12115 int caller_addr_regno = LINK_REGISTER_REGNUM;
12116
12117 /* Be conservative and always set this, at least for now. */
12118 current_function_uses_pic_offset_table = 1;
12119
12120#if TARGET_MACHO
12121 /* For PIC code, set up a stub and collect the caller's address
12122 from r0, which is where the prologue puts it. */
12123 if (flag_pic)
12124 {
12125 mcount_name = machopic_stub_name (mcount_name);
12126 if (current_function_uses_pic_offset_table)
12127 caller_addr_regno = 0;
12128 }
12129#endif
12130 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
12131 0, VOIDmode, 1,
12132 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
12133 }
411707f4
CC
12134}
12135
a4f6c312 12136/* Write function profiler code. */
e165f3f0
RK
12137
12138void
12139output_function_profiler (file, labelno)
12140 FILE *file;
12141 int labelno;
12142{
3daf36a4 12143 char buf[100];
09eeeacb 12144 int save_lr = 8;
e165f3f0 12145
3daf36a4 12146 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7 12147 switch (DEFAULT_ABI)
3daf36a4 12148 {
38c1f2d7
MM
12149 default:
12150 abort ();
12151
12152 case ABI_V4:
09eeeacb
AM
12153 save_lr = 4;
12154 /* Fall through. */
12155
38c1f2d7 12156 case ABI_AIX_NODESC:
09eeeacb
AM
12157 if (!TARGET_32BIT)
12158 {
12159 warning ("no profiling of 64-bit code for this ABI");
12160 return;
12161 }
38c1f2d7
MM
12162 fprintf (file, "\tmflr %s\n", reg_names[0]);
12163 if (flag_pic == 1)
12164 {
dfdfa60f 12165 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
12166 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12167 reg_names[0], save_lr, reg_names[1]);
17167fd8 12168 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 12169 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 12170 assemble_name (file, buf);
17167fd8 12171 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 12172 }
9ebbca7d 12173 else if (flag_pic > 1)
38c1f2d7 12174 {
09eeeacb
AM
12175 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12176 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
12177 /* Now, we need to get the address of the label. */
12178 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 12179 assemble_name (file, buf);
9ebbca7d
GK
12180 fputs ("-.\n1:", file);
12181 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
12182 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
12183 reg_names[0], reg_names[11]);
12184 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
12185 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 12186 }
38c1f2d7
MM
12187 else
12188 {
17167fd8 12189 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 12190 assemble_name (file, buf);
dfdfa60f 12191 fputs ("@ha\n", file);
09eeeacb
AM
12192 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12193 reg_names[0], save_lr, reg_names[1]);
a260abc9 12194 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 12195 assemble_name (file, buf);
17167fd8 12196 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
12197 }
12198
09eeeacb
AM
12199 if (current_function_needs_context && DEFAULT_ABI == ABI_AIX_NODESC)
12200 {
12201 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
12202 reg_names[STATIC_CHAIN_REGNUM],
12203 12, reg_names[1]);
12204 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
12205 asm_fprintf (file, "\t{l|lwz} %s,%d(%s)\n",
12206 reg_names[STATIC_CHAIN_REGNUM],
12207 12, reg_names[1]);
12208 }
12209 else
12210 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
12211 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
38c1f2d7
MM
12212 break;
12213
12214 case ABI_AIX:
ee890fe2 12215 case ABI_DARWIN:
a4f6c312 12216 /* Don't do anything, done in output_profile_hook (). */
38c1f2d7
MM
12217 break;
12218 }
e165f3f0 12219}
a251ffd0 12220
b54cf83a
DE
12221\f
12222static int
12223rs6000_use_dfa_pipeline_interface ()
12224{
12225 return 1;
12226}
12227
12228static int
12229rs6000_multipass_dfa_lookahead ()
12230{
12231 if (rs6000_cpu == PROCESSOR_POWER4)
12232 return 4;
12233 else
12234 return 1;
12235}
12236
12237/* Power4 load update and store update instructions are cracked into a
12238 load or store and an integer insn which are executed in the same cycle.
12239 Branches have their own dispatch slot which does not count against the
12240 GCC issue rate, but it changes the program flow so there are no other
12241 instructions to issue in this cycle. */
12242
12243static int
12244rs6000_variable_issue (stream, verbose, insn, more)
12245 FILE *stream ATTRIBUTE_UNUSED;
12246 int verbose ATTRIBUTE_UNUSED;
12247 rtx insn;
12248 int more;
12249{
12250 if (GET_CODE (PATTERN (insn)) == USE
12251 || GET_CODE (PATTERN (insn)) == CLOBBER)
12252 return more;
12253
12254 if (rs6000_cpu == PROCESSOR_POWER4)
12255 {
12256 enum attr_type type = get_attr_type (insn);
12257 if (type == TYPE_LOAD_EXT_U || type == TYPE_LOAD_EXT_UX
12258 || type == TYPE_LOAD_UX || type == TYPE_STORE_UX
12259 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX)
12260 return 0;
12261 else if (type == TYPE_LOAD_U || type == TYPE_STORE_U
12262 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
12263 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR)
12264 return more - 2;
12265 else
12266 return more - 1;
12267 }
12268 else
12269 return more - 1;
12270}
12271
a251ffd0
TG
12272/* Adjust the cost of a scheduling dependency. Return the new cost of
12273 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
12274
c237e94a 12275static int
a06faf84 12276rs6000_adjust_cost (insn, link, dep_insn, cost)
a251ffd0
TG
12277 rtx insn;
12278 rtx link;
296b8152 12279 rtx dep_insn ATTRIBUTE_UNUSED;
a251ffd0
TG
12280 int cost;
12281{
12282 if (! recog_memoized (insn))
12283 return 0;
12284
12285 if (REG_NOTE_KIND (link) != 0)
12286 return 0;
12287
12288 if (REG_NOTE_KIND (link) == 0)
12289 {
ed947a96
DJ
12290 /* Data dependency; DEP_INSN writes a register that INSN reads
12291 some cycles later. */
12292 switch (get_attr_type (insn))
12293 {
12294 case TYPE_JMPREG:
309323c2 12295 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
12296 a mtctr and bctr (and mtlr and br/blr). The first
12297 scheduling pass will not know about this latency since
12298 the mtctr instruction, which has the latency associated
12299 to it, will be generated by reload. */
309323c2 12300 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
12301 case TYPE_BRANCH:
12302 /* Leave some extra cycles between a compare and its
12303 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
12304 if ((rs6000_cpu_attr == CPU_PPC603
12305 || rs6000_cpu_attr == CPU_PPC604
12306 || rs6000_cpu_attr == CPU_PPC604E
12307 || rs6000_cpu_attr == CPU_PPC620
12308 || rs6000_cpu_attr == CPU_PPC630
12309 || rs6000_cpu_attr == CPU_PPC750
12310 || rs6000_cpu_attr == CPU_PPC7400
12311 || rs6000_cpu_attr == CPU_PPC7450
12312 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
12313 && recog_memoized (dep_insn)
12314 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
12315 && (get_attr_type (dep_insn) == TYPE_CMP
12316 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96
DJ
12317 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
12318 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
12319 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
12320 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
12321 return cost + 2;
12322 default:
12323 break;
12324 }
a251ffd0
TG
12325 /* Fall out to return default cost. */
12326 }
12327
12328 return cost;
12329}
b6c9286a 12330
a4f6c312
SS
12331/* A C statement (sans semicolon) to update the integer scheduling
12332 priority INSN_PRIORITY (INSN). Reduce the priority to execute the
12333 INSN earlier, increase the priority to execute INSN later. Do not
12334 define this macro if you do not need to adjust the scheduling
12335 priorities of insns. */
bef84347 12336
c237e94a 12337static int
bef84347 12338rs6000_adjust_priority (insn, priority)
d330fd93 12339 rtx insn ATTRIBUTE_UNUSED;
bef84347
VM
12340 int priority;
12341{
a4f6c312
SS
12342 /* On machines (like the 750) which have asymmetric integer units,
12343 where one integer unit can do multiply and divides and the other
12344 can't, reduce the priority of multiply/divide so it is scheduled
12345 before other integer operations. */
bef84347
VM
12346
12347#if 0
2c3c49de 12348 if (! INSN_P (insn))
bef84347
VM
12349 return priority;
12350
12351 if (GET_CODE (PATTERN (insn)) == USE)
12352 return priority;
12353
12354 switch (rs6000_cpu_attr) {
12355 case CPU_PPC750:
12356 switch (get_attr_type (insn))
12357 {
12358 default:
12359 break;
12360
12361 case TYPE_IMUL:
12362 case TYPE_IDIV:
3cb999d8
DE
12363 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
12364 priority, priority);
bef84347
VM
12365 if (priority >= 0 && priority < 0x01000000)
12366 priority >>= 3;
12367 break;
12368 }
12369 }
12370#endif
12371
12372 return priority;
12373}
12374
a4f6c312
SS
12375/* Return how many instructions the machine can issue per cycle. */
12376
c237e94a
ZW
12377static int
12378rs6000_issue_rate ()
b6c9286a
MM
12379{
12380 switch (rs6000_cpu_attr) {
3cb999d8
DE
12381 case CPU_RIOS1: /* ? */
12382 case CPU_RS64A:
12383 case CPU_PPC601: /* ? */
ed947a96 12384 case CPU_PPC7450:
3cb999d8 12385 return 3;
b54cf83a 12386 case CPU_PPC440:
b6c9286a 12387 case CPU_PPC603:
bef84347 12388 case CPU_PPC750:
ed947a96 12389 case CPU_PPC7400:
bef84347 12390 return 2;
3cb999d8 12391 case CPU_RIOS2:
b6c9286a 12392 case CPU_PPC604:
19684119 12393 case CPU_PPC604E:
b6c9286a 12394 case CPU_PPC620:
3cb999d8 12395 case CPU_PPC630:
309323c2 12396 case CPU_POWER4:
b6c9286a
MM
12397 return 4;
12398 default:
12399 return 1;
12400 }
12401}
12402
b6c9286a 12403\f
b6c9286a
MM
12404/* Length in units of the trampoline for entering a nested function. */
12405
12406int
12407rs6000_trampoline_size ()
12408{
12409 int ret = 0;
12410
12411 switch (DEFAULT_ABI)
12412 {
12413 default:
12414 abort ();
12415
12416 case ABI_AIX:
8f802bfb 12417 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
12418 break;
12419
4dabc42d 12420 case ABI_DARWIN:
b6c9286a
MM
12421 case ABI_V4:
12422 case ABI_AIX_NODESC:
03a7e1a5 12423 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 12424 break;
b6c9286a
MM
12425 }
12426
12427 return ret;
12428}
12429
12430/* Emit RTL insns to initialize the variable parts of a trampoline.
12431 FNADDR is an RTX for the address of the function's pure code.
12432 CXT is an RTX for the static chain value for the function. */
12433
12434void
12435rs6000_initialize_trampoline (addr, fnaddr, cxt)
12436 rtx addr;
12437 rtx fnaddr;
12438 rtx cxt;
12439{
ac2a93a1 12440 enum machine_mode pmode = Pmode;
8bd04c56
MM
12441 int regsize = (TARGET_32BIT) ? 4 : 8;
12442 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
12443
12444 switch (DEFAULT_ABI)
12445 {
12446 default:
12447 abort ();
12448
8bd04c56 12449/* Macros to shorten the code expansions below. */
39403d82 12450#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
12451#define MEM_PLUS(addr,offset) \
12452 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 12453
b6c9286a
MM
12454 /* Under AIX, just build the 3 word function descriptor */
12455 case ABI_AIX:
8bd04c56
MM
12456 {
12457 rtx fn_reg = gen_reg_rtx (pmode);
12458 rtx toc_reg = gen_reg_rtx (pmode);
12459 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 12460 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
12461 emit_move_insn (MEM_DEREF (addr), fn_reg);
12462 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
12463 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
12464 }
b6c9286a
MM
12465 break;
12466
4dabc42d
TC
12467 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
12468 case ABI_DARWIN:
b6c9286a
MM
12469 case ABI_V4:
12470 case ABI_AIX_NODESC:
39403d82 12471 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
12472 FALSE, VOIDmode, 4,
12473 addr, pmode,
12474 GEN_INT (rs6000_trampoline_size ()), SImode,
12475 fnaddr, pmode,
12476 ctx_reg, pmode);
b6c9286a 12477 break;
b6c9286a
MM
12478 }
12479
12480 return;
12481}
7509c759
MM
12482
12483\f
91d231cb 12484/* Table of valid machine attributes. */
a4f6c312 12485
91d231cb 12486const struct attribute_spec rs6000_attribute_table[] =
7509c759 12487{
91d231cb 12488 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
a5c76ee6
ZW
12489 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
12490 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
12491 { NULL, 0, 0, false, false, false, NULL }
91d231cb 12492};
7509c759 12493
a5c76ee6
ZW
12494/* Handle a "longcall" or "shortcall" attribute; arguments as in
12495 struct attribute_spec.handler. */
a4f6c312 12496
91d231cb
JM
12497static tree
12498rs6000_handle_longcall_attribute (node, name, args, flags, no_add_attrs)
12499 tree *node;
12500 tree name;
12501 tree args ATTRIBUTE_UNUSED;
12502 int flags ATTRIBUTE_UNUSED;
12503 bool *no_add_attrs;
12504{
12505 if (TREE_CODE (*node) != FUNCTION_TYPE
12506 && TREE_CODE (*node) != FIELD_DECL
12507 && TREE_CODE (*node) != TYPE_DECL)
12508 {
12509 warning ("`%s' attribute only applies to functions",
12510 IDENTIFIER_POINTER (name));
12511 *no_add_attrs = true;
12512 }
6a4cee5f 12513
91d231cb 12514 return NULL_TREE;
7509c759
MM
12515}
12516
a5c76ee6
ZW
12517/* Set longcall attributes on all functions declared when
12518 rs6000_default_long_calls is true. */
12519static void
12520rs6000_set_default_type_attributes (type)
12521 tree type;
12522{
12523 if (rs6000_default_long_calls
12524 && (TREE_CODE (type) == FUNCTION_TYPE
12525 || TREE_CODE (type) == METHOD_TYPE))
12526 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
12527 NULL_TREE,
12528 TYPE_ATTRIBUTES (type));
12529}
12530
3cb999d8
DE
12531/* Return a reference suitable for calling a function with the
12532 longcall attribute. */
a4f6c312 12533
6a4cee5f
MM
12534struct rtx_def *
12535rs6000_longcall_ref (call_ref)
12536 rtx call_ref;
12537{
d330fd93 12538 const char *call_name;
6a4cee5f
MM
12539 tree node;
12540
12541 if (GET_CODE (call_ref) != SYMBOL_REF)
12542 return call_ref;
12543
12544 /* System V adds '.' to the internal name, so skip them. */
12545 call_name = XSTR (call_ref, 0);
12546 if (*call_name == '.')
12547 {
12548 while (*call_name == '.')
12549 call_name++;
12550
12551 node = get_identifier (call_name);
39403d82 12552 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
12553 }
12554
12555 return force_reg (Pmode, call_ref);
12556}
12557
7509c759 12558\f
b64a1b53
RH
12559#ifdef USING_ELFOS_H
12560
7509c759
MM
12561/* A C statement or statements to switch to the appropriate section
12562 for output of RTX in mode MODE. You can assume that RTX is some
12563 kind of constant in RTL. The argument MODE is redundant except in
12564 the case of a `const_int' rtx. Select the section by calling
12565 `text_section' or one of the alternatives for other sections.
12566
12567 Do not define this macro if you put all constants in the read-only
12568 data section. */
12569
b64a1b53
RH
12570static void
12571rs6000_elf_select_rtx_section (mode, x, align)
a9098fd0 12572 enum machine_mode mode;
7509c759 12573 rtx x;
b64a1b53 12574 unsigned HOST_WIDE_INT align;
7509c759 12575{
a9098fd0 12576 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 12577 toc_section ();
7509c759 12578 else
b64a1b53 12579 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
12580}
12581
12582/* A C statement or statements to switch to the appropriate
12583 section for output of DECL. DECL is either a `VAR_DECL' node
12584 or a constant of some sort. RELOC indicates whether forming
12585 the initial value of DECL requires link-time relocations. */
12586
ae46c4e0
RH
12587static void
12588rs6000_elf_select_section (decl, reloc, align)
7509c759
MM
12589 tree decl;
12590 int reloc;
0e5dbd9b 12591 unsigned HOST_WIDE_INT align;
7509c759 12592{
0e5dbd9b
DE
12593 default_elf_select_section_1 (decl, reloc, align,
12594 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
12595}
12596
12597/* A C statement to build up a unique section name, expressed as a
12598 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
12599 RELOC indicates whether the initial value of EXP requires
12600 link-time relocations. If you do not define this macro, GCC will use
12601 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 12602 macro can now be called for uninitialized data items as well as
4912a07c 12603 initialized data and functions. */
63019373 12604
ae46c4e0
RH
12605static void
12606rs6000_elf_unique_section (decl, reloc)
63019373
GK
12607 tree decl;
12608 int reloc;
12609{
0e5dbd9b
DE
12610 default_unique_section_1 (decl, reloc,
12611 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 12612}
d9407988
MM
12613
12614\f
d9407988
MM
12615/* If we are referencing a function that is static or is known to be
12616 in this file, make the SYMBOL_REF special. We can use this to indicate
12617 that we can branch to this function without emitting a no-op after the
9ebbca7d 12618 call. For real AIX calling sequences, we also replace the
d9407988
MM
12619 function name with the real name (1 or 2 leading .'s), rather than
12620 the function descriptor name. This saves a lot of overriding code
a260abc9 12621 to read the prefixes. */
d9407988 12622
fb49053f
RH
12623static void
12624rs6000_elf_encode_section_info (decl, first)
d9407988 12625 tree decl;
b2003250 12626 int first;
d9407988 12627{
b2003250
RH
12628 if (!first)
12629 return;
12630
d9407988
MM
12631 if (TREE_CODE (decl) == FUNCTION_DECL)
12632 {
12633 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
b629ba0c 12634 if ((*targetm.binds_local_p) (decl))
d9407988
MM
12635 SYMBOL_REF_FLAG (sym_ref) = 1;
12636
9ebbca7d 12637 if (DEFAULT_ABI == ABI_AIX)
d9407988 12638 {
ff669a6c
RH
12639 size_t len1 = (DEFAULT_ABI == ABI_AIX) ? 1 : 2;
12640 size_t len2 = strlen (XSTR (sym_ref, 0));
520a57c8 12641 char *str = alloca (len1 + len2 + 1);
ff669a6c
RH
12642 str[0] = '.';
12643 str[1] = '.';
12644 memcpy (str + len1, XSTR (sym_ref, 0), len2 + 1);
12645
520a57c8 12646 XSTR (sym_ref, 0) = ggc_alloc_string (str, len1 + len2);
d9407988
MM
12647 }
12648 }
12649 else if (rs6000_sdata != SDATA_NONE
f607bc57 12650 && DEFAULT_ABI == ABI_V4
d9407988
MM
12651 && TREE_CODE (decl) == VAR_DECL)
12652 {
c40e5172 12653 rtx sym_ref = XEXP (DECL_RTL (decl), 0);
d9407988
MM
12654 int size = int_size_in_bytes (TREE_TYPE (decl));
12655 tree section_name = DECL_SECTION_NAME (decl);
d330fd93 12656 const char *name = (char *)0;
d9407988
MM
12657 int len = 0;
12658
c40e5172
JS
12659 if ((*targetm.binds_local_p) (decl))
12660 SYMBOL_REF_FLAG (sym_ref) = 1;
12661
d9407988
MM
12662 if (section_name)
12663 {
12664 if (TREE_CODE (section_name) == STRING_CST)
12665 {
12666 name = TREE_STRING_POINTER (section_name);
12667 len = TREE_STRING_LENGTH (section_name);
12668 }
12669 else
12670 abort ();
12671 }
12672
12673 if ((size > 0 && size <= g_switch_value)
12674 || (name
5f59ecb7 12675 && ((len == sizeof (".sdata") - 1
3cb999d8 12676 && strcmp (name, ".sdata") == 0)
5f59ecb7 12677 || (len == sizeof (".sdata2") - 1
3cb999d8 12678 && strcmp (name, ".sdata2") == 0)
5f59ecb7 12679 || (len == sizeof (".sbss") - 1
3cb999d8 12680 && strcmp (name, ".sbss") == 0)
5f59ecb7 12681 || (len == sizeof (".sbss2") - 1
3cb999d8 12682 && strcmp (name, ".sbss2") == 0)
5f59ecb7 12683 || (len == sizeof (".PPC.EMB.sdata0") - 1
3cb999d8 12684 && strcmp (name, ".PPC.EMB.sdata0") == 0)
5f59ecb7 12685 || (len == sizeof (".PPC.EMB.sbss0") - 1
3cb999d8 12686 && strcmp (name, ".PPC.EMB.sbss0") == 0))))
d9407988 12687 {
ff669a6c 12688 size_t len = strlen (XSTR (sym_ref, 0));
88c1e412 12689 char *str = alloca (len + 2);
ff669a6c 12690
ff669a6c
RH
12691 str[0] = '@';
12692 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
88c1e412 12693 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988
MM
12694 }
12695 }
12696}
12697
772c5265
RH
12698static const char *
12699rs6000_elf_strip_name_encoding (str)
12700 const char *str;
12701{
12702 while (*str == '*' || *str == '@')
12703 str++;
12704 return str;
12705}
12706
0e5dbd9b
DE
12707static bool
12708rs6000_elf_in_small_data_p (decl)
12709 tree decl;
12710{
12711 if (rs6000_sdata == SDATA_NONE)
12712 return false;
12713
12714 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
12715 {
12716 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
12717 if (strcmp (section, ".sdata") == 0
12718 || strcmp (section, ".sdata2") == 0
12719 || strcmp (section, ".sbss") == 0)
12720 return true;
12721 }
12722 else
12723 {
12724 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
12725
12726 if (size > 0
12727 && size <= g_switch_value
12728 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
12729 return true;
12730 }
12731
12732 return false;
12733}
12734
b91da81f 12735#endif /* USING_ELFOS_H */
000034eb 12736
a6c2a102 12737\f
000034eb 12738/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
12739 ADDR can be effectively incremented by incrementing REG.
12740
12741 r0 is special and we must not select it as an address
12742 register by this routine since our caller will try to
12743 increment the returned register via an "la" instruction. */
000034eb
DE
12744
12745struct rtx_def *
12746find_addr_reg (addr)
12747 rtx addr;
12748{
12749 while (GET_CODE (addr) == PLUS)
12750 {
02441cd6
JL
12751 if (GET_CODE (XEXP (addr, 0)) == REG
12752 && REGNO (XEXP (addr, 0)) != 0)
000034eb 12753 addr = XEXP (addr, 0);
02441cd6
JL
12754 else if (GET_CODE (XEXP (addr, 1)) == REG
12755 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
12756 addr = XEXP (addr, 1);
12757 else if (CONSTANT_P (XEXP (addr, 0)))
12758 addr = XEXP (addr, 1);
12759 else if (CONSTANT_P (XEXP (addr, 1)))
12760 addr = XEXP (addr, 0);
12761 else
12762 abort ();
12763 }
02441cd6 12764 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
12765 return addr;
12766 abort ();
12767}
12768
a6c2a102
DE
12769void
12770rs6000_fatal_bad_address (op)
12771 rtx op;
12772{
12773 fatal_insn ("bad address", op);
12774}
c8023011 12775
ee890fe2
SS
12776#if TARGET_MACHO
12777
12778#if 0
12779/* Returns 1 if OP is either a symbol reference or a sum of a symbol
12780 reference and a constant. */
12781
12782int
12783symbolic_operand (op)
592696dd 12784 rtx op;
ee890fe2
SS
12785{
12786 switch (GET_CODE (op))
12787 {
12788 case SYMBOL_REF:
12789 case LABEL_REF:
12790 return 1;
12791 case CONST:
12792 op = XEXP (op, 0);
12793 return (GET_CODE (op) == SYMBOL_REF ||
12794 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
12795 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
12796 && GET_CODE (XEXP (op, 1)) == CONST_INT);
12797 default:
12798 return 0;
12799 }
c8023011 12800}
ee890fe2
SS
12801#endif
12802
12803#ifdef RS6000_LONG_BRANCH
12804
12805static tree stub_list = 0;
12806
12807/* ADD_COMPILER_STUB adds the compiler generated stub for handling
12808 procedure calls to the linked list. */
12809
12810void
12811add_compiler_stub (label_name, function_name, line_number)
12812 tree label_name;
12813 tree function_name;
12814 int line_number;
12815{
12816 tree stub = build_tree_list (function_name, label_name);
12817 TREE_TYPE (stub) = build_int_2 (line_number, 0);
12818 TREE_CHAIN (stub) = stub_list;
12819 stub_list = stub;
12820}
12821
12822#define STUB_LABEL_NAME(STUB) TREE_VALUE (STUB)
12823#define STUB_FUNCTION_NAME(STUB) TREE_PURPOSE (STUB)
12824#define STUB_LINE_NUMBER(STUB) TREE_INT_CST_LOW (TREE_TYPE (STUB))
12825
a4f6c312
SS
12826/* OUTPUT_COMPILER_STUB outputs the compiler generated stub for
12827 handling procedure calls from the linked list and initializes the
12828 linked list. */
ee890fe2 12829
a4f6c312
SS
12830void
12831output_compiler_stub ()
ee890fe2
SS
12832{
12833 char tmp_buf[256];
12834 char label_buf[256];
308c142a 12835 tree stub;
ee890fe2
SS
12836
12837 if (!flag_pic)
12838 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
12839 {
12840 fprintf (asm_out_file,
12841 "%s:\n", IDENTIFIER_POINTER(STUB_LABEL_NAME(stub)));
12842
12843#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
12844 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
12845 fprintf (asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER(stub));
12846#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
12847
12848 if (IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))[0] == '*')
12849 strcpy (label_buf,
12850 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub))+1);
12851 else
12852 {
12853 label_buf[0] = '_';
12854 strcpy (label_buf+1,
12855 IDENTIFIER_POINTER (STUB_FUNCTION_NAME (stub)));
12856 }
12857
12858 strcpy (tmp_buf, "lis r12,hi16(");
12859 strcat (tmp_buf, label_buf);
12860 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
12861 strcat (tmp_buf, label_buf);
12862 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
12863 output_asm_insn (tmp_buf, 0);
12864
12865#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
12866 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
12867 fprintf(asm_out_file, "\t.stabd 68,0,%d\n", STUB_LINE_NUMBER (stub));
12868#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
12869 }
12870
12871 stub_list = 0;
12872}
12873
12874/* NO_PREVIOUS_DEF checks in the link list whether the function name is
12875 already there or not. */
12876
a4f6c312
SS
12877int
12878no_previous_def (function_name)
ee890fe2
SS
12879 tree function_name;
12880{
12881 tree stub;
12882 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
12883 if (function_name == STUB_FUNCTION_NAME (stub))
12884 return 0;
12885 return 1;
12886}
12887
12888/* GET_PREV_LABEL gets the label name from the previous definition of
12889 the function. */
12890
a4f6c312
SS
12891tree
12892get_prev_label (function_name)
ee890fe2
SS
12893 tree function_name;
12894{
12895 tree stub;
12896 for (stub = stub_list; stub; stub = TREE_CHAIN (stub))
12897 if (function_name == STUB_FUNCTION_NAME (stub))
12898 return STUB_LABEL_NAME (stub);
12899 return 0;
12900}
12901
12902/* INSN is either a function call or a millicode call. It may have an
12903 unconditional jump in its delay slot.
12904
12905 CALL_DEST is the routine we are calling. */
12906
12907char *
12908output_call (insn, call_dest, operand_number)
12909 rtx insn;
12910 rtx call_dest;
12911 int operand_number;
12912{
12913 static char buf[256];
12914 if (GET_CODE (call_dest) == SYMBOL_REF && TARGET_LONG_BRANCH && !flag_pic)
12915 {
12916 tree labelname;
12917 tree funname = get_identifier (XSTR (call_dest, 0));
12918
12919 if (no_previous_def (funname))
12920 {
308c142a 12921 int line_number = 0;
ee890fe2
SS
12922 rtx label_rtx = gen_label_rtx ();
12923 char *label_buf, temp_buf[256];
12924 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
12925 CODE_LABEL_NUMBER (label_rtx));
12926 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
12927 labelname = get_identifier (label_buf);
12928 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
12929 if (insn)
12930 line_number = NOTE_LINE_NUMBER (insn);
12931 add_compiler_stub (labelname, funname, line_number);
12932 }
12933 else
12934 labelname = get_prev_label (funname);
12935
12936 sprintf (buf, "jbsr %%z%d,%.246s",
12937 operand_number, IDENTIFIER_POINTER (labelname));
12938 return buf;
12939 }
12940 else
12941 {
12942 sprintf (buf, "bl %%z%d", operand_number);
12943 return buf;
12944 }
12945}
12946
12947#endif /* RS6000_LONG_BRANCH */
12948
12949#define GEN_LOCAL_LABEL_FOR_SYMBOL(BUF,SYMBOL,LENGTH,N) \
12950 do { \
83182544 12951 const char *const symbol_ = (SYMBOL); \
ee890fe2
SS
12952 char *buffer_ = (BUF); \
12953 if (symbol_[0] == '"') \
12954 { \
12955 sprintf(buffer_, "\"L%d$%s", (N), symbol_+1); \
12956 } \
12957 else if (name_needs_quotes(symbol_)) \
12958 { \
12959 sprintf(buffer_, "\"L%d$%s\"", (N), symbol_); \
12960 } \
12961 else \
12962 { \
12963 sprintf(buffer_, "L%d$%s", (N), symbol_); \
12964 } \
12965 } while (0)
12966
12967
12968/* Generate PIC and indirect symbol stubs. */
12969
12970void
12971machopic_output_stub (file, symb, stub)
12972 FILE *file;
12973 const char *symb, *stub;
12974{
12975 unsigned int length;
a4f6c312
SS
12976 char *symbol_name, *lazy_ptr_name;
12977 char *local_label_0;
ee890fe2
SS
12978 static int label = 0;
12979
df56a27f 12980 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 12981 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 12982
ee890fe2
SS
12983 label += 1;
12984
ee890fe2
SS
12985 length = strlen (symb);
12986 symbol_name = alloca (length + 32);
12987 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
12988
12989 lazy_ptr_name = alloca (length + 32);
12990 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
12991
12992 local_label_0 = alloca (length + 32);
12993 GEN_LOCAL_LABEL_FOR_SYMBOL (local_label_0, symb, length, 0);
12994
ee890fe2 12995 if (flag_pic == 2)
d3c300d2 12996 machopic_picsymbol_stub1_section ();
ee890fe2 12997 else
d3c300d2
DJ
12998 machopic_symbol_stub1_section ();
12999 fprintf (file, "\t.align 2\n");
ee890fe2
SS
13000
13001 fprintf (file, "%s:\n", stub);
13002 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13003
13004 if (flag_pic == 2)
13005 {
13006 fprintf (file, "\tmflr r0\n");
13007 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
13008 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
13009 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
13010 lazy_ptr_name, local_label_0);
13011 fprintf (file, "\tmtlr r0\n");
d3c300d2 13012 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
13013 lazy_ptr_name, local_label_0);
13014 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
13015 fprintf (file, "\tbctr\n");
13016 }
13017 else
13018 fprintf (file, "non-pure not supported\n");
13019
13020 machopic_lazy_symbol_ptr_section ();
13021 fprintf (file, "%s:\n", lazy_ptr_name);
13022 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
13023 fprintf (file, "\t.long dyld_stub_binding_helper\n");
13024}
13025
13026/* Legitimize PIC addresses. If the address is already
13027 position-independent, we return ORIG. Newly generated
13028 position-independent addresses go into a reg. This is REG if non
13029 zero, otherwise we allocate register(s) as necessary. */
13030
c859cda6 13031#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
13032
13033rtx
13034rs6000_machopic_legitimize_pic_address (orig, mode, reg)
13035 rtx orig;
13036 enum machine_mode mode;
13037 rtx reg;
13038{
13039 rtx base, offset;
13040
13041 if (reg == NULL && ! reload_in_progress && ! reload_completed)
13042 reg = gen_reg_rtx (Pmode);
13043
13044 if (GET_CODE (orig) == CONST)
13045 {
13046 if (GET_CODE (XEXP (orig, 0)) == PLUS
13047 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
13048 return orig;
13049
13050 if (GET_CODE (XEXP (orig, 0)) == PLUS)
13051 {
a4f6c312
SS
13052 base =
13053 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
13054 Pmode, reg);
13055 offset =
13056 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
13057 Pmode, reg);
ee890fe2
SS
13058 }
13059 else
13060 abort ();
13061
13062 if (GET_CODE (offset) == CONST_INT)
13063 {
13064 if (SMALL_INT (offset))
ed8908e7 13065 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
13066 else if (! reload_in_progress && ! reload_completed)
13067 offset = force_reg (Pmode, offset);
13068 else
c859cda6
DJ
13069 {
13070 rtx mem = force_const_mem (Pmode, orig);
13071 return machopic_legitimize_pic_address (mem, Pmode, reg);
13072 }
ee890fe2
SS
13073 }
13074 return gen_rtx (PLUS, Pmode, base, offset);
13075 }
13076
13077 /* Fall back on generic machopic code. */
13078 return machopic_legitimize_pic_address (orig, mode, reg);
13079}
13080
13081/* This is just a placeholder to make linking work without having to
13082 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
13083 ever needed for Darwin (not too likely!) this would have to get a
13084 real definition. */
13085
13086void
13087toc_section ()
13088{
13089}
13090
13091#endif /* TARGET_MACHO */
7c262518
RH
13092
13093#if TARGET_ELF
13094static unsigned int
13095rs6000_elf_section_type_flags (decl, name, reloc)
13096 tree decl;
13097 const char *name;
13098 int reloc;
13099{
5add3202
DE
13100 unsigned int flags
13101 = default_section_type_flags_1 (decl, name, reloc,
13102 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 13103
270fc29b
RH
13104 if (TARGET_RELOCATABLE)
13105 flags |= SECTION_WRITE;
7c262518 13106
d0101753 13107 return flags;
7c262518 13108}
d9f6800d
RH
13109
13110/* Record an element in the table of global constructors. SYMBOL is
13111 a SYMBOL_REF of the function to be called; PRIORITY is a number
13112 between 0 and MAX_INIT_PRIORITY.
13113
13114 This differs from default_named_section_asm_out_constructor in
13115 that we have special handling for -mrelocatable. */
13116
13117static void
13118rs6000_elf_asm_out_constructor (symbol, priority)
13119 rtx symbol;
13120 int priority;
13121{
13122 const char *section = ".ctors";
13123 char buf[16];
13124
13125 if (priority != DEFAULT_INIT_PRIORITY)
13126 {
13127 sprintf (buf, ".ctors.%.5u",
13128 /* Invert the numbering so the linker puts us in the proper
13129 order; constructors are run from right to left, and the
13130 linker sorts in increasing order. */
13131 MAX_INIT_PRIORITY - priority);
13132 section = buf;
13133 }
13134
715bdd29
RH
13135 named_section_flags (section, SECTION_WRITE);
13136 assemble_align (POINTER_SIZE);
d9f6800d
RH
13137
13138 if (TARGET_RELOCATABLE)
13139 {
13140 fputs ("\t.long (", asm_out_file);
13141 output_addr_const (asm_out_file, symbol);
13142 fputs (")@fixup\n", asm_out_file);
13143 }
13144 else
c8af3574 13145 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
13146}
13147
13148static void
13149rs6000_elf_asm_out_destructor (symbol, priority)
13150 rtx symbol;
13151 int priority;
13152{
13153 const char *section = ".dtors";
13154 char buf[16];
13155
13156 if (priority != DEFAULT_INIT_PRIORITY)
13157 {
13158 sprintf (buf, ".dtors.%.5u",
13159 /* Invert the numbering so the linker puts us in the proper
13160 order; constructors are run from right to left, and the
13161 linker sorts in increasing order. */
13162 MAX_INIT_PRIORITY - priority);
13163 section = buf;
13164 }
13165
715bdd29
RH
13166 named_section_flags (section, SECTION_WRITE);
13167 assemble_align (POINTER_SIZE);
d9f6800d
RH
13168
13169 if (TARGET_RELOCATABLE)
13170 {
13171 fputs ("\t.long (", asm_out_file);
13172 output_addr_const (asm_out_file, symbol);
13173 fputs (")@fixup\n", asm_out_file);
13174 }
13175 else
c8af3574 13176 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 13177}
7c262518
RH
13178#endif
13179
cbaaba19 13180#if TARGET_XCOFF
7c262518 13181static void
b275d088
DE
13182rs6000_xcoff_asm_globalize_label (stream, name)
13183 FILE *stream;
13184 const char *name;
13185{
13186 fputs (GLOBAL_ASM_OP, stream);
13187 RS6000_OUTPUT_BASENAME (stream, name);
13188 putc ('\n', stream);
13189}
13190
13191static void
13192rs6000_xcoff_asm_named_section (name, flags)
7c262518 13193 const char *name;
0e5dbd9b 13194 unsigned int flags;
7c262518 13195{
0e5dbd9b
DE
13196 int smclass;
13197 static const char * const suffix[3] = { "PR", "RO", "RW" };
13198
13199 if (flags & SECTION_CODE)
13200 smclass = 0;
13201 else if (flags & SECTION_WRITE)
13202 smclass = 2;
13203 else
13204 smclass = 1;
13205
5b5198f7 13206 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 13207 (flags & SECTION_CODE) ? "." : "",
5b5198f7 13208 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 13209}
ae46c4e0
RH
13210
13211static void
0e5dbd9b
DE
13212rs6000_xcoff_select_section (decl, reloc, align)
13213 tree decl;
ae46c4e0
RH
13214 int reloc;
13215 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
13216{
5add3202 13217 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 13218 {
0e5dbd9b 13219 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13220 read_only_data_section ();
13221 else
13222 read_only_private_data_section ();
13223 }
13224 else
13225 {
0e5dbd9b 13226 if (TREE_PUBLIC (decl))
ae46c4e0
RH
13227 data_section ();
13228 else
13229 private_data_section ();
13230 }
13231}
13232
13233static void
13234rs6000_xcoff_unique_section (decl, reloc)
13235 tree decl;
772c5265 13236 int reloc ATTRIBUTE_UNUSED;
ae46c4e0
RH
13237{
13238 const char *name;
ae46c4e0 13239
5b5198f7
DE
13240 /* Use select_section for private and uninitialized data. */
13241 if (!TREE_PUBLIC (decl)
13242 || DECL_COMMON (decl)
0e5dbd9b
DE
13243 || DECL_INITIAL (decl) == NULL_TREE
13244 || DECL_INITIAL (decl) == error_mark_node
13245 || (flag_zero_initialized_in_bss
13246 && initializer_zerop (DECL_INITIAL (decl))))
13247 return;
13248
13249 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
13250 name = (*targetm.strip_name_encoding) (name);
13251 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 13252}
b64a1b53 13253
fb49053f
RH
13254/* Select section for constant in constant pool.
13255
13256 On RS/6000, all constants are in the private read-only data area.
13257 However, if this is being placed in the TOC it must be output as a
13258 toc entry. */
13259
b64a1b53
RH
13260static void
13261rs6000_xcoff_select_rtx_section (mode, x, align)
13262 enum machine_mode mode;
13263 rtx x;
13264 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
13265{
13266 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
13267 toc_section ();
13268 else
13269 read_only_private_data_section ();
13270}
772c5265
RH
13271
13272/* Remove any trailing [DS] or the like from the symbol name. */
13273
13274static const char *
13275rs6000_xcoff_strip_name_encoding (name)
13276 const char *name;
13277{
13278 size_t len;
13279 if (*name == '*')
13280 name++;
13281 len = strlen (name);
13282 if (name[len - 1] == ']')
13283 return ggc_alloc_string (name, len - 4);
13284 else
13285 return name;
13286}
13287
5add3202
DE
13288/* Section attributes. AIX is always PIC. */
13289
13290static unsigned int
13291rs6000_xcoff_section_type_flags (decl, name, reloc)
13292 tree decl;
13293 const char *name;
13294 int reloc;
13295{
5b5198f7
DE
13296 unsigned int align;
13297 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
13298
13299 /* Align to at least UNIT size. */
13300 if (flags & SECTION_CODE)
13301 align = MIN_UNITS_PER_WORD;
13302 else
13303 /* Increase alignment of large objects if not already stricter. */
13304 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
13305 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
13306 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
13307
13308 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202
DE
13309}
13310
cbaaba19 13311#endif /* TARGET_XCOFF */
fb49053f 13312
0e5dbd9b 13313/* Note that this is also used for PPC64 Linux. */
fb49053f
RH
13314
13315static void
13316rs6000_xcoff_encode_section_info (decl, first)
13317 tree decl;
13318 int first ATTRIBUTE_UNUSED;
13319{
13320 if (TREE_CODE (decl) == FUNCTION_DECL
b629ba0c 13321 && (*targetm.binds_local_p) (decl))
fb49053f
RH
13322 SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
13323}
0e5dbd9b
DE
13324
13325/* Cross-module name binding. For AIX and PPC64 Linux, which always are
13326 PIC, use private copy of flag_pic. */
13327
2bcc50d0 13328static bool
0e5dbd9b
DE
13329rs6000_binds_local_p (decl)
13330 tree decl;
13331{
5add3202 13332 return default_binds_local_p_1 (decl, flag_pic || rs6000_flag_pic);
0e5dbd9b 13333}
34bb030a 13334
3c50106f
RH
13335/* Compute a (partial) cost for rtx X. Return true if the complete
13336 cost has been computed, and false if subexpressions should be
13337 scanned. In either case, *TOTAL contains the cost result. */
13338
13339static bool
13340rs6000_rtx_costs (x, code, outer_code, total)
13341 rtx x;
13342 int code, outer_code ATTRIBUTE_UNUSED;
13343 int *total;
13344{
13345 switch (code)
13346 {
13347 /* On the RS/6000, if it is valid in the insn, it is free.
13348 So this always returns 0. */
13349 case CONST_INT:
13350 case CONST:
13351 case LABEL_REF:
13352 case SYMBOL_REF:
13353 case CONST_DOUBLE:
13354 case HIGH:
13355 *total = 0;
13356 return true;
13357
13358 case PLUS:
13359 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
13360 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
13361 + 0x8000) >= 0x10000)
13362 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
13363 ? COSTS_N_INSNS (2)
13364 : COSTS_N_INSNS (1));
13365 return true;
13366
13367 case AND:
13368 case IOR:
13369 case XOR:
13370 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
13371 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
13372 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
13373 ? COSTS_N_INSNS (2)
13374 : COSTS_N_INSNS (1));
13375 return true;
13376
13377 case MULT:
13378 if (optimize_size)
13379 {
13380 *total = COSTS_N_INSNS (2);
13381 return true;
13382 }
13383 switch (rs6000_cpu)
13384 {
13385 case PROCESSOR_RIOS1:
13386 case PROCESSOR_PPC405:
13387 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13388 ? COSTS_N_INSNS (5)
13389 : (INTVAL (XEXP (x, 1)) >= -256
13390 && INTVAL (XEXP (x, 1)) <= 255)
13391 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
13392 return true;
13393
13394 case PROCESSOR_RS64A:
13395 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13396 ? GET_MODE (XEXP (x, 1)) != DImode
13397 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
13398 : (INTVAL (XEXP (x, 1)) >= -256
13399 && INTVAL (XEXP (x, 1)) <= 255)
13400 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
13401 return true;
13402
13403 case PROCESSOR_RIOS2:
13404 case PROCESSOR_MPCCORE:
13405 case PROCESSOR_PPC604e:
13406 *total = COSTS_N_INSNS (2);
13407 return true;
13408
13409 case PROCESSOR_PPC601:
13410 *total = COSTS_N_INSNS (5);
13411 return true;
13412
13413 case PROCESSOR_PPC603:
13414 case PROCESSOR_PPC7400:
13415 case PROCESSOR_PPC750:
13416 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13417 ? COSTS_N_INSNS (5)
13418 : (INTVAL (XEXP (x, 1)) >= -256
13419 && INTVAL (XEXP (x, 1)) <= 255)
13420 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
13421 return true;
13422
13423 case PROCESSOR_PPC7450:
13424 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13425 ? COSTS_N_INSNS (4)
13426 : COSTS_N_INSNS (3));
13427 return true;
13428
13429 case PROCESSOR_PPC403:
13430 case PROCESSOR_PPC604:
13431 case PROCESSOR_PPC8540:
13432 *total = COSTS_N_INSNS (4);
13433 return true;
13434
13435 case PROCESSOR_PPC620:
13436 case PROCESSOR_PPC630:
13437 case PROCESSOR_POWER4:
13438 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
13439 ? GET_MODE (XEXP (x, 1)) != DImode
13440 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
13441 : (INTVAL (XEXP (x, 1)) >= -256
13442 && INTVAL (XEXP (x, 1)) <= 255)
13443 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
13444 return true;
13445
13446 default:
13447 abort ();
13448 }
13449
13450 case DIV:
13451 case MOD:
13452 if (GET_CODE (XEXP (x, 1)) == CONST_INT
13453 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
13454 {
13455 *total = COSTS_N_INSNS (2);
13456 return true;
13457 }
13458 /* FALLTHRU */
13459
13460 case UDIV:
13461 case UMOD:
13462 switch (rs6000_cpu)
13463 {
13464 case PROCESSOR_RIOS1:
13465 *total = COSTS_N_INSNS (19);
13466 return true;
13467
13468 case PROCESSOR_RIOS2:
13469 *total = COSTS_N_INSNS (13);
13470 return true;
13471
13472 case PROCESSOR_RS64A:
13473 *total = (GET_MODE (XEXP (x, 1)) != DImode
13474 ? COSTS_N_INSNS (65)
13475 : COSTS_N_INSNS (67));
13476 return true;
13477
13478 case PROCESSOR_MPCCORE:
13479 *total = COSTS_N_INSNS (6);
13480 return true;
13481
13482 case PROCESSOR_PPC403:
13483 *total = COSTS_N_INSNS (33);
13484 return true;
13485
13486 case PROCESSOR_PPC405:
13487 *total = COSTS_N_INSNS (35);
13488 return true;
13489
13490 case PROCESSOR_PPC601:
13491 *total = COSTS_N_INSNS (36);
13492 return true;
13493
13494 case PROCESSOR_PPC603:
13495 *total = COSTS_N_INSNS (37);
13496 return true;
13497
13498 case PROCESSOR_PPC604:
13499 case PROCESSOR_PPC604e:
13500 *total = COSTS_N_INSNS (20);
13501 return true;
13502
13503 case PROCESSOR_PPC620:
13504 case PROCESSOR_PPC630:
13505 case PROCESSOR_POWER4:
13506 *total = (GET_MODE (XEXP (x, 1)) != DImode
13507 ? COSTS_N_INSNS (21)
13508 : COSTS_N_INSNS (37));
13509 return true;
13510
13511 case PROCESSOR_PPC750:
13512 case PROCESSOR_PPC8540:
13513 case PROCESSOR_PPC7400:
13514 *total = COSTS_N_INSNS (19);
13515 return true;
13516
13517 case PROCESSOR_PPC7450:
13518 *total = COSTS_N_INSNS (23);
13519 return true;
13520
13521 default:
13522 abort ();
13523 }
13524
13525 case FFS:
13526 *total = COSTS_N_INSNS (4);
13527 return true;
13528
13529 case MEM:
13530 /* MEM should be slightly more expensive than (plus (reg) (const)) */
13531 *total = 5;
13532 return true;
13533
13534 default:
13535 return false;
13536 }
13537}
13538
34bb030a
DE
13539/* A C expression returning the cost of moving data from a register of class
13540 CLASS1 to one of CLASS2. */
13541
13542int
13543rs6000_register_move_cost (mode, from, to)
13544 enum machine_mode mode;
13545 enum reg_class from, to;
13546{
13547 /* Moves from/to GENERAL_REGS. */
13548 if (reg_classes_intersect_p (to, GENERAL_REGS)
13549 || reg_classes_intersect_p (from, GENERAL_REGS))
13550 {
13551 if (! reg_classes_intersect_p (to, GENERAL_REGS))
13552 from = to;
13553
13554 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
13555 return (rs6000_memory_move_cost (mode, from, 0)
13556 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
13557
13558/* It's more expensive to move CR_REGS than CR0_REGS because of the shift...*/
13559 else if (from == CR_REGS)
13560 return 4;
13561
13562 else
13563/* A move will cost one instruction per GPR moved. */
13564 return 2 * HARD_REGNO_NREGS (0, mode);
13565 }
13566
13567/* Moving between two similar registers is just one instruction. */
13568 else if (reg_classes_intersect_p (to, from))
13569 return mode == TFmode ? 4 : 2;
13570
13571/* Everything else has to go through GENERAL_REGS. */
13572 else
13573 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
13574 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
13575}
13576
13577/* A C expressions returning the cost of moving data of MODE from a register to
13578 or from memory. */
13579
13580int
13581rs6000_memory_move_cost (mode, class, in)
13582 enum machine_mode mode;
13583 enum reg_class class;
13584 int in ATTRIBUTE_UNUSED;
13585{
13586 if (reg_classes_intersect_p (class, GENERAL_REGS))
13587 return 4 * HARD_REGNO_NREGS (0, mode);
13588 else if (reg_classes_intersect_p (class, FLOAT_REGS))
13589 return 4 * HARD_REGNO_NREGS (32, mode);
13590 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
13591 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
13592 else
13593 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
13594}
13595
62e1dfcf
NC
13596/* Return true if TYPE is of type __ev64_opaque__. */
13597
13598static int
13599is_ev64_opaque_type (type)
13600 tree type;
13601{
13602 return (TYPE_NAME (type)
13603 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
13604 && DECL_NAME (TYPE_NAME (type))
13605 && strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))),
13606 "__ev64_opaque__") == 0);
13607}
13608
13609/* Return true if vector type1 can be converted into vector type2. */
13610
13611static bool
13612rs6000_spe_vector_types_compatible (t1, t2)
13613 tree t1;
13614 tree t2;
13615{
13616 if (!TARGET_SPE
13617 || TREE_CODE (t1) != VECTOR_TYPE || TREE_CODE (t2) != VECTOR_TYPE)
13618 return 0;
13619
13620 if (TYPE_NAME (t1) || TYPE_NAME (t2))
13621 return is_ev64_opaque_type (t1) || is_ev64_opaque_type (t2);
13622
13623 /* FIXME: We assume V2SI is the opaque type, so we accidentally
13624 allow inter conversion to and from V2SI modes. We could use
13625 V1D1, and rewrite <spe.h> accordingly. */
13626 return t1 == V2SI_type_node || t2 == V2SI_type_node;
13627}
13628
17211ab5 13629#include "gt-rs6000.h"