]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
Makefile.in: Revert most of Arnaud's last change.
[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,
93c9d1ba 3 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
fab3bcc3 4 Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
9878760c 5
5de601cf 6 This file is part of GCC.
9878760c 7
5de601cf
NC
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2, or (at your
11 option) any later version.
9878760c 12
5de601cf
NC
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
9878760c 17
5de601cf
NC
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the
20 Free Software Foundation, 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA. */
9878760c 22
956d6950 23#include "config.h"
c4d38ccb 24#include "system.h"
4977bab6
ZW
25#include "coretypes.h"
26#include "tm.h"
9878760c
RK
27#include "rtl.h"
28#include "regs.h"
29#include "hard-reg-set.h"
30#include "real.h"
31#include "insn-config.h"
32#include "conditions.h"
9878760c
RK
33#include "insn-attr.h"
34#include "flags.h"
35#include "recog.h"
9878760c 36#include "obstack.h"
9b30bae2 37#include "tree.h"
dfafc897 38#include "expr.h"
2fc1c679 39#include "optabs.h"
2a430ec1 40#include "except.h"
a7df97e6 41#include "function.h"
296b8152 42#include "output.h"
d5fa86ba 43#include "basic-block.h"
d0101753 44#include "integrate.h"
296b8152 45#include "toplev.h"
c8023011 46#include "ggc.h"
9ebbca7d
GK
47#include "hashtab.h"
48#include "tm_p.h"
672a6f42
NB
49#include "target.h"
50#include "target-def.h"
3ac88239 51#include "langhooks.h"
24ea750e 52#include "reload.h"
117dca74 53#include "cfglayout.h"
79ae11c4 54#include "sched-int.h"
1bc7c5b6
ZW
55#if TARGET_XCOFF
56#include "xcoffout.h" /* get declarations of xcoff_*_section_name */
57#endif
9b30bae2 58
7509c759
MM
59#ifndef TARGET_NO_PROTOTYPE
60#define TARGET_NO_PROTOTYPE 0
61#endif
62
452a7d36
HP
63#define EASY_VECTOR_15(n) ((n) >= -16 && (n) <= 15)
64#define EASY_VECTOR_15_ADD_SELF(n) ((n) >= 0x10 && (n) <= 0x1e \
65 && !((n) & 1))
d744e06e 66
9878760c
RK
67#define min(A,B) ((A) < (B) ? (A) : (B))
68#define max(A,B) ((A) > (B) ? (A) : (B))
69
d1d0c603
JJ
70/* Structure used to define the rs6000 stack */
71typedef struct rs6000_stack {
72 int first_gp_reg_save; /* first callee saved GP register used */
73 int first_fp_reg_save; /* first callee saved FP register used */
74 int first_altivec_reg_save; /* first callee saved AltiVec register used */
75 int lr_save_p; /* true if the link reg needs to be saved */
76 int cr_save_p; /* true if the CR reg needs to be saved */
77 unsigned int vrsave_mask; /* mask of vec registers to save */
78 int toc_save_p; /* true if the TOC needs to be saved */
79 int push_p; /* true if we need to allocate stack space */
80 int calls_p; /* true if the function makes any calls */
81 enum rs6000_abi abi; /* which ABI to use */
82 int gp_save_offset; /* offset to save GP regs from initial SP */
83 int fp_save_offset; /* offset to save FP regs from initial SP */
84 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
85 int lr_save_offset; /* offset to save LR from initial SP */
86 int cr_save_offset; /* offset to save CR from initial SP */
87 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
88 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
89 int toc_save_offset; /* offset to save the TOC pointer */
90 int varargs_save_offset; /* offset to save the varargs registers */
91 int ehrd_offset; /* offset to EH return data */
92 int reg_size; /* register size (4 or 8) */
93 int varargs_size; /* size to hold V.4 args passed in regs */
94 HOST_WIDE_INT vars_size; /* variable save area size */
95 int parm_size; /* outgoing parameter size */
96 int save_size; /* save area size */
97 int fixed_size; /* fixed size of stack frame */
98 int gp_size; /* size of saved GP registers */
99 int fp_size; /* size of saved FP registers */
100 int altivec_size; /* size of saved AltiVec registers */
101 int cr_size; /* size to hold CR if not in save_size */
102 int lr_size; /* size to hold LR if not in save_size */
103 int vrsave_size; /* size to hold VRSAVE if not in save_size */
104 int altivec_padding_size; /* size of altivec alignment padding if
105 not in save_size */
106 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
107 int spe_padding_size;
108 int toc_size; /* size to hold TOC if not in save_size */
109 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
110 int spe_64bit_regs_used;
111} rs6000_stack_t;
112
5248c961
RK
113/* Target cpu type */
114
115enum processor_type rs6000_cpu;
8e3f41e7
MM
116struct rs6000_cpu_select rs6000_select[3] =
117{
815cdc52
MM
118 /* switch name, tune arch */
119 { (const char *)0, "--with-cpu=", 1, 1 },
120 { (const char *)0, "-mcpu=", 1, 1 },
121 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 122};
5248c961 123
ec507f2d
DE
124/* Always emit branch hint bits. */
125static GTY(()) bool rs6000_always_hint;
126
127/* Schedule instructions for group formation. */
128static GTY(()) bool rs6000_sched_groups;
129
79ae11c4
DN
130/* Support adjust_priority scheduler hook
131 and -mprioritize-restricted-insns= option. */
132const char *rs6000_sched_restricted_insns_priority_str;
133int rs6000_sched_restricted_insns_priority;
134
569fa502
DN
135/* Support for -msched-costly-dep option. */
136const char *rs6000_sched_costly_dep_str;
137enum rs6000_dependence_cost rs6000_sched_costly_dep;
138
cbe26ab8
DN
139/* Support for -minsert-sched-nops option. */
140const char *rs6000_sched_insert_nops_str;
141enum rs6000_nop_insertion rs6000_sched_insert_nops;
142
6fa3f289
ZW
143/* Size of long double */
144const char *rs6000_long_double_size_string;
145int rs6000_long_double_type_size;
146
147/* Whether -mabi=altivec has appeared */
148int rs6000_altivec_abi;
149
08b57fb3
AH
150/* Whether VRSAVE instructions should be generated. */
151int rs6000_altivec_vrsave;
152
153/* String from -mvrsave= option. */
154const char *rs6000_altivec_vrsave_string;
155
a3170dc6
AH
156/* Nonzero if we want SPE ABI extensions. */
157int rs6000_spe_abi;
158
159/* Whether isel instructions should be generated. */
160int rs6000_isel;
161
993f19a8
AH
162/* Whether SPE simd instructions should be generated. */
163int rs6000_spe;
164
5da702b1
AH
165/* Nonzero if floating point operations are done in the GPRs. */
166int rs6000_float_gprs = 0;
167
168/* String from -mfloat-gprs=. */
169const char *rs6000_float_gprs_string;
a3170dc6
AH
170
171/* String from -misel=. */
172const char *rs6000_isel_string;
173
993f19a8
AH
174/* String from -mspe=. */
175const char *rs6000_spe_string;
176
a0ab749a 177/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 178static GTY(()) int common_mode_defined;
c81bebd7 179
9878760c
RK
180/* Save information from a "cmpxx" operation until the branch or scc is
181 emitted. */
9878760c
RK
182rtx rs6000_compare_op0, rs6000_compare_op1;
183int rs6000_compare_fp_p;
874a0744 184
874a0744
MM
185/* Label number of label created for -mrelocatable, to call to so we can
186 get the address of the GOT section */
187int rs6000_pic_labelno;
c81bebd7 188
b91da81f 189#ifdef USING_ELFOS_H
c81bebd7 190/* Which abi to adhere to */
9739c90c 191const char *rs6000_abi_name;
d9407988
MM
192
193/* Semantics of the small data area */
194enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
195
196/* Which small data model to use */
815cdc52 197const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
198
199/* Counter for labels which are to be placed in .fixup. */
200int fixuplabelno = 0;
874a0744 201#endif
4697a36c 202
c4501e62
JJ
203/* Bit size of immediate TLS offsets and string from which it is decoded. */
204int rs6000_tls_size = 32;
205const char *rs6000_tls_size_string;
206
b6c9286a
MM
207/* ABI enumeration available for subtarget to use. */
208enum rs6000_abi rs6000_current_abi;
209
0ac081f6
AH
210/* ABI string from -mabi= option. */
211const char *rs6000_abi_string;
212
38c1f2d7 213/* Debug flags */
815cdc52 214const char *rs6000_debug_name;
38c1f2d7
MM
215int rs6000_debug_stack; /* debug stack applications */
216int rs6000_debug_arg; /* debug argument handling */
217
6035d635 218/* Opaque types. */
2abe3e28 219static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 220static GTY(()) tree opaque_V2SF_type_node;
6035d635 221static GTY(()) tree opaque_p_V2SI_type_node;
4a5eab38
PB
222static GTY(()) tree V16QI_type_node;
223static GTY(()) tree V2SI_type_node;
224static GTY(()) tree V2SF_type_node;
225static GTY(()) tree V4HI_type_node;
226static GTY(()) tree V4SI_type_node;
227static GTY(()) tree V4SF_type_node;
228static GTY(()) tree V8HI_type_node;
229static GTY(()) tree unsigned_V16QI_type_node;
230static GTY(()) tree unsigned_V8HI_type_node;
231static GTY(()) tree unsigned_V4SI_type_node;
8bb418a3
ZL
232static GTY(()) tree bool_char_type_node; /* __bool char */
233static GTY(()) tree bool_short_type_node; /* __bool short */
234static GTY(()) tree bool_int_type_node; /* __bool int */
235static GTY(()) tree pixel_type_node; /* __pixel */
236static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */
237static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */
238static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */
239static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */
240
241int rs6000_warn_altivec_long = 1; /* On by default. */
242const char *rs6000_warn_altivec_long_switch;
243
57ac7be9
AM
244const char *rs6000_traceback_name;
245static enum {
246 traceback_default = 0,
247 traceback_none,
248 traceback_part,
249 traceback_full
250} rs6000_traceback;
251
38c1f2d7
MM
252/* Flag to say the TOC is initialized */
253int toc_initialized;
9ebbca7d 254char toc_label_name[10];
38c1f2d7 255
9ebbca7d 256/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 257static GTY(()) int rs6000_sr_alias_set;
c8023011 258
a5c76ee6
ZW
259/* Call distance, overridden by -mlongcall and #pragma longcall(1).
260 The only place that looks at this is rs6000_set_default_type_attributes;
261 everywhere else should rely on the presence or absence of a longcall
262 attribute on the function declaration. */
263int rs6000_default_long_calls;
264const char *rs6000_longcall_switch;
265
a3c9585f
KH
266/* Control alignment for fields within structures. */
267/* String from -malign-XXXXX. */
025d9908
KH
268const char *rs6000_alignment_string;
269int rs6000_alignment_flags;
270
a3170dc6
AH
271struct builtin_description
272{
273 /* mask is not const because we're going to alter it below. This
274 nonsense will go away when we rewrite the -march infrastructure
275 to give us more target flag bits. */
276 unsigned int mask;
277 const enum insn_code icode;
278 const char *const name;
279 const enum rs6000_builtins code;
280};
281
a2369ed3
DJ
282static bool rs6000_function_ok_for_sibcall (tree, tree);
283static int num_insns_constant_wide (HOST_WIDE_INT);
284static void validate_condition_mode (enum rtx_code, enum machine_mode);
285static rtx rs6000_generate_compare (enum rtx_code);
286static void rs6000_maybe_dead (rtx);
287static void rs6000_emit_stack_tie (void);
288static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
289static rtx spe_synthesize_frame_save (rtx);
290static bool spe_func_has_64bit_regs_p (void);
b20a9cca 291static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 292 int, HOST_WIDE_INT);
a2369ed3
DJ
293static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
294static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
295static unsigned rs6000_hash_constant (rtx);
296static unsigned toc_hash_function (const void *);
297static int toc_hash_eq (const void *, const void *);
298static int constant_pool_expr_1 (rtx, int *, int *);
299static bool constant_pool_expr_p (rtx);
300static bool toc_relative_expr_p (rtx);
301static bool legitimate_small_data_p (enum machine_mode, rtx);
302static bool legitimate_offset_address_p (enum machine_mode, rtx, int);
303static bool legitimate_indexed_address_p (rtx, int);
304static bool legitimate_indirect_address_p (rtx, int);
4c81e946 305static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
306static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
307static struct machine_function * rs6000_init_machine_status (void);
308static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 309#ifdef HAVE_GAS_HIDDEN
a2369ed3 310static void rs6000_assemble_visibility (tree, int);
5add3202 311#endif
a2369ed3
DJ
312static int rs6000_ra_ever_killed (void);
313static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
8bb418a3 314static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
f18eca82 315static const char *rs6000_mangle_fundamental_type (tree);
b86fe7b4 316extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
317static void rs6000_set_default_type_attributes (tree);
318static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
319static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
320static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
321 tree);
a2369ed3 322static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 323static bool rs6000_return_in_memory (tree, tree);
a2369ed3 324static void rs6000_file_start (void);
7c262518 325#if TARGET_ELF
a2369ed3
DJ
326static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
327static void rs6000_elf_asm_out_constructor (rtx, int);
328static void rs6000_elf_asm_out_destructor (rtx, int);
329static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
330static void rs6000_elf_unique_section (tree, int);
331static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 332 unsigned HOST_WIDE_INT);
a56d7372 333static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 334 ATTRIBUTE_UNUSED;
a2369ed3 335static bool rs6000_elf_in_small_data_p (tree);
7c262518 336#endif
cbaaba19 337#if TARGET_XCOFF
a2369ed3
DJ
338static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
339static void rs6000_xcoff_asm_named_section (const char *, unsigned int);
340static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
341static void rs6000_xcoff_unique_section (tree, int);
342static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 343 unsigned HOST_WIDE_INT);
a2369ed3
DJ
344static const char * rs6000_xcoff_strip_name_encoding (const char *);
345static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
346static void rs6000_xcoff_file_start (void);
347static void rs6000_xcoff_file_end (void);
f1384257
AM
348#endif
349#if TARGET_MACHO
a2369ed3 350static bool rs6000_binds_local_p (tree);
f1384257 351#endif
a2369ed3
DJ
352static int rs6000_use_dfa_pipeline_interface (void);
353static int rs6000_variable_issue (FILE *, int, rtx, int);
354static bool rs6000_rtx_costs (rtx, int, int, int *);
355static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 356static bool is_microcoded_insn (rtx);
79ae11c4 357static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
358static bool is_cracked_insn (rtx);
359static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
360static int rs6000_adjust_priority (rtx, int);
361static int rs6000_issue_rate (void);
569fa502 362static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
363static rtx get_next_active_insn (rtx, rtx);
364static bool insn_terminates_group_p (rtx , enum group_termination);
365static bool is_costly_group (rtx *, rtx);
366static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
367static int redefine_groups (FILE *, int, rtx, rtx);
368static int pad_groups (FILE *, int, rtx, rtx);
369static void rs6000_sched_finish (FILE *, int);
a2369ed3
DJ
370static int rs6000_use_sched_lookahead (void);
371
372static void rs6000_init_builtins (void);
373static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
374static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
375static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
376static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
377static void altivec_init_builtins (void);
378static void rs6000_common_init_builtins (void);
c15c90bb 379static void rs6000_init_libfuncs (void);
a2369ed3 380
b20a9cca
AM
381static void enable_mask_for_builtins (struct builtin_description *, int,
382 enum rs6000_builtins,
383 enum rs6000_builtins);
a2369ed3
DJ
384static void spe_init_builtins (void);
385static rtx spe_expand_builtin (tree, rtx, bool *);
386static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
387static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
388static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
389static rs6000_stack_t *rs6000_stack_info (void);
390static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
391
392static rtx altivec_expand_builtin (tree, rtx, bool *);
393static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
394static rtx altivec_expand_st_builtin (tree, rtx, bool *);
395static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
396static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
397static rtx altivec_expand_predicate_builtin (enum insn_code,
398 const char *, tree, rtx);
b4a62fa0 399static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
400static rtx altivec_expand_stv_builtin (enum insn_code, tree);
401static void rs6000_parse_abi_options (void);
402static void rs6000_parse_alignment_option (void);
403static void rs6000_parse_tls_size_option (void);
5da702b1 404static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
405static int first_altivec_reg_to_save (void);
406static unsigned int compute_vrsave_mask (void);
407static void is_altivec_return_reg (rtx, void *);
408static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
409int easy_vector_constant (rtx, enum machine_mode);
410static int easy_vector_same (rtx, enum machine_mode);
452a7d36 411static int easy_vector_splat_const (int, enum machine_mode);
a2369ed3
DJ
412static bool is_ev64_opaque_type (tree);
413static rtx rs6000_dwarf_register_span (rtx);
414static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
415static rtx rs6000_tls_get_addr (void);
416static rtx rs6000_got_sym (void);
417static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
418static const char *rs6000_get_some_local_dynamic_name (void);
419static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 420static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 421static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 422 enum machine_mode, tree);
b78d48dd
FJ
423static rtx rs6000_mixed_function_arg (CUMULATIVE_ARGS *,
424 enum machine_mode, tree, int);
b1917422 425static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
c6e8c921
GK
426static void setup_incoming_varargs (CUMULATIVE_ARGS *,
427 enum machine_mode, tree,
428 int *, int);
efdba735
SH
429#if TARGET_MACHO
430static void macho_branch_islands (void);
431static void add_compiler_branch_island (tree, tree, int);
432static int no_previous_def (tree function_name);
433static tree get_prev_label (tree function_name);
434#endif
435
c35d187f 436static tree rs6000_build_builtin_va_list (void);
17211ab5
GK
437
438/* Hash table stuff for keeping track of TOC entries. */
439
440struct toc_hash_struct GTY(())
441{
442 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
443 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
444 rtx key;
445 enum machine_mode key_mode;
446 int labelno;
447};
448
449static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
450\f
451/* Default register names. */
452char rs6000_reg_names[][8] =
453{
802a0058
MM
454 "0", "1", "2", "3", "4", "5", "6", "7",
455 "8", "9", "10", "11", "12", "13", "14", "15",
456 "16", "17", "18", "19", "20", "21", "22", "23",
457 "24", "25", "26", "27", "28", "29", "30", "31",
458 "0", "1", "2", "3", "4", "5", "6", "7",
459 "8", "9", "10", "11", "12", "13", "14", "15",
460 "16", "17", "18", "19", "20", "21", "22", "23",
461 "24", "25", "26", "27", "28", "29", "30", "31",
462 "mq", "lr", "ctr","ap",
463 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
464 "xer",
465 /* AltiVec registers. */
0cd5e3a1
AH
466 "0", "1", "2", "3", "4", "5", "6", "7",
467 "8", "9", "10", "11", "12", "13", "14", "15",
468 "16", "17", "18", "19", "20", "21", "22", "23",
469 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
470 "vrsave", "vscr",
471 /* SPE registers. */
472 "spe_acc", "spefscr"
c81bebd7
MM
473};
474
475#ifdef TARGET_REGNAMES
8b60264b 476static const char alt_reg_names[][8] =
c81bebd7 477{
802a0058
MM
478 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
479 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
480 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
481 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
482 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
483 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
484 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
485 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
486 "mq", "lr", "ctr", "ap",
487 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 488 "xer",
59a4c851 489 /* AltiVec registers. */
0ac081f6 490 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
491 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
492 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
493 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
494 "vrsave", "vscr",
495 /* SPE registers. */
496 "spe_acc", "spefscr"
c81bebd7
MM
497};
498#endif
9878760c 499\f
daf11973
MM
500#ifndef MASK_STRICT_ALIGN
501#define MASK_STRICT_ALIGN 0
502#endif
ffcfcb5f
AM
503#ifndef TARGET_PROFILE_KERNEL
504#define TARGET_PROFILE_KERNEL 0
505#endif
3961e8fe
RH
506
507/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
508#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
509
510/* Return 1 for a symbol ref for a thread-local storage symbol. */
511#define RS6000_SYMBOL_REF_TLS_P(RTX) \
512 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
513\f
514/* Initialize the GCC target structure. */
91d231cb
JM
515#undef TARGET_ATTRIBUTE_TABLE
516#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
517#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
518#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 519
301d03af
RS
520#undef TARGET_ASM_ALIGNED_DI_OP
521#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
522
523/* Default unaligned ops are only provided for ELF. Find the ops needed
524 for non-ELF systems. */
525#ifndef OBJECT_FORMAT_ELF
cbaaba19 526#if TARGET_XCOFF
ae6c1efd 527/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
528 64-bit targets. */
529#undef TARGET_ASM_UNALIGNED_HI_OP
530#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
531#undef TARGET_ASM_UNALIGNED_SI_OP
532#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
533#undef TARGET_ASM_UNALIGNED_DI_OP
534#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
535#else
536/* For Darwin. */
537#undef TARGET_ASM_UNALIGNED_HI_OP
538#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
539#undef TARGET_ASM_UNALIGNED_SI_OP
540#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
541#endif
542#endif
543
544/* This hook deals with fixups for relocatable code and DI-mode objects
545 in 64-bit code. */
546#undef TARGET_ASM_INTEGER
547#define TARGET_ASM_INTEGER rs6000_assemble_integer
548
93638d7a
AM
549#ifdef HAVE_GAS_HIDDEN
550#undef TARGET_ASM_ASSEMBLE_VISIBILITY
551#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
552#endif
553
c4501e62
JJ
554#undef TARGET_HAVE_TLS
555#define TARGET_HAVE_TLS HAVE_AS_TLS
556
557#undef TARGET_CANNOT_FORCE_CONST_MEM
558#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
559
08c148a8
NB
560#undef TARGET_ASM_FUNCTION_PROLOGUE
561#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
562#undef TARGET_ASM_FUNCTION_EPILOGUE
563#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
564
b54cf83a
DE
565#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
566#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
567#undef TARGET_SCHED_VARIABLE_ISSUE
568#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
569
c237e94a
ZW
570#undef TARGET_SCHED_ISSUE_RATE
571#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
572#undef TARGET_SCHED_ADJUST_COST
573#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
574#undef TARGET_SCHED_ADJUST_PRIORITY
575#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
569fa502
DN
576#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
577#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
578#undef TARGET_SCHED_FINISH
579#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 580
be12c2b0
VM
581#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
582#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
583
0ac081f6
AH
584#undef TARGET_INIT_BUILTINS
585#define TARGET_INIT_BUILTINS rs6000_init_builtins
586
587#undef TARGET_EXPAND_BUILTIN
588#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
589
f18eca82
ZL
590#undef TARGET_MANGLE_FUNDAMENTAL_TYPE
591#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
592
c15c90bb
ZW
593#undef TARGET_INIT_LIBFUNCS
594#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
595
f1384257 596#if TARGET_MACHO
0e5dbd9b
DE
597#undef TARGET_BINDS_LOCAL_P
598#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 599#endif
0e5dbd9b 600
3961e8fe
RH
601#undef TARGET_ASM_OUTPUT_MI_THUNK
602#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
603
3961e8fe 604#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 605#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 606
4977bab6
ZW
607#undef TARGET_FUNCTION_OK_FOR_SIBCALL
608#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
609
3c50106f
RH
610#undef TARGET_RTX_COSTS
611#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
612#undef TARGET_ADDRESS_COST
613#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 614
c8e4f0e9
AH
615#undef TARGET_VECTOR_OPAQUE_P
616#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 617
96714395
AH
618#undef TARGET_DWARF_REGISTER_SPAN
619#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
620
c6e8c921
GK
621/* On rs6000, function arguments are promoted, as are function return
622 values. */
623#undef TARGET_PROMOTE_FUNCTION_ARGS
624#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
625#undef TARGET_PROMOTE_FUNCTION_RETURN
626#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
627
c6e8c921
GK
628#undef TARGET_RETURN_IN_MEMORY
629#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
630
631#undef TARGET_SETUP_INCOMING_VARARGS
632#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
633
634/* Always strict argument naming on rs6000. */
635#undef TARGET_STRICT_ARGUMENT_NAMING
636#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
637#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
638#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
639#undef TARGET_SPLIT_COMPLEX_ARG
640#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
c6e8c921 641
c35d187f
RH
642#undef TARGET_BUILD_BUILTIN_VA_LIST
643#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
644
f6897b10 645struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 646\f
5248c961
RK
647/* Override command line options. Mostly we process the processor
648 type and sometimes adjust other TARGET_ options. */
649
650void
d779d0dc 651rs6000_override_options (const char *default_cpu)
5248c961 652{
c4d38ccb 653 size_t i, j;
8e3f41e7 654 struct rs6000_cpu_select *ptr;
66188a7e 655 int set_masks;
5248c961 656
66188a7e 657 /* Simplifications for entries below. */
85638c0d 658
66188a7e
GK
659 enum {
660 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
661 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
662 };
85638c0d 663
66188a7e
GK
664 /* This table occasionally claims that a processor does not support
665 a particular feature even though it does, but the feature is slower
666 than the alternative. Thus, it shouldn't be relied on as a
667 complete description of the processor's support.
668
669 Please keep this list in order, and don't forget to update the
670 documentation in invoke.texi when adding a new processor or
671 flag. */
5248c961
RK
672 static struct ptt
673 {
8b60264b
KG
674 const char *const name; /* Canonical processor name. */
675 const enum processor_type processor; /* Processor type enum value. */
676 const int target_enable; /* Target flags to enable. */
8b60264b 677 } const processor_target_table[]
66188a7e 678 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 679 {"403", PROCESSOR_PPC403,
66188a7e
GK
680 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
681 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
682 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
683 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
684 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
685 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 686 {"601", PROCESSOR_PPC601,
66188a7e
GK
687 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
688 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
689 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
690 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
691 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
692 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
693 {"620", PROCESSOR_PPC620,
694 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
695 {"630", PROCESSOR_PPC630,
696 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
697 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
698 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
699 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
700 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
701 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
702 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
703 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
704 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
705 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 706 {"970", PROCESSOR_POWER4,
66188a7e
GK
707 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
708 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
709 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
710 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
711 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 712 {"G5", PROCESSOR_POWER4,
66188a7e
GK
713 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
714 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
715 {"power2", PROCESSOR_POWER,
716 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
717 {"power3", PROCESSOR_PPC630,
718 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
719 {"power4", PROCESSOR_POWER4,
fc091c8e 720 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
ec507f2d 721 {"power5", PROCESSOR_POWER5,
fc091c8e 722 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
66188a7e
GK
723 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
724 {"powerpc64", PROCESSOR_POWERPC64,
725 POWERPC_BASE_MASK | MASK_POWERPC64},
726 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
727 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
728 {"rios2", PROCESSOR_RIOS2,
729 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
730 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
731 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 732 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 733 };
5248c961 734
ca7558fc 735 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 736
66188a7e
GK
737 /* Some OSs don't support saving the high part of 64-bit registers on
738 context switch. Other OSs don't support saving Altivec registers.
739 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
740 settings; if the user wants either, the user must explicitly specify
741 them and we won't interfere with the user's specification. */
742
743 enum {
744 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
745 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
746 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
747 | MASK_MFCRF)
748 };
749 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
750#ifdef OS_MISSING_POWERPC64
751 if (OS_MISSING_POWERPC64)
752 set_masks &= ~MASK_POWERPC64;
753#endif
754#ifdef OS_MISSING_ALTIVEC
755 if (OS_MISSING_ALTIVEC)
756 set_masks &= ~MASK_ALTIVEC;
757#endif
758
957211c3
AM
759 /* Don't override these by the processor default if given explicitly. */
760 set_masks &= ~(target_flags_explicit
761 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
762
a4f6c312 763 /* Identify the processor type. */
8e3f41e7 764 rs6000_select[0].string = default_cpu;
3cb999d8 765 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 766
b6a1cbae 767 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 768 {
8e3f41e7
MM
769 ptr = &rs6000_select[i];
770 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 771 {
8e3f41e7
MM
772 for (j = 0; j < ptt_size; j++)
773 if (! strcmp (ptr->string, processor_target_table[j].name))
774 {
775 if (ptr->set_tune_p)
776 rs6000_cpu = processor_target_table[j].processor;
777
778 if (ptr->set_arch_p)
779 {
66188a7e
GK
780 target_flags &= ~set_masks;
781 target_flags |= (processor_target_table[j].target_enable
782 & set_masks);
8e3f41e7
MM
783 }
784 break;
785 }
786
4406229e 787 if (j == ptt_size)
8e3f41e7 788 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
789 }
790 }
8a61d227 791
993f19a8 792 if (TARGET_E500)
a3170dc6
AH
793 rs6000_isel = 1;
794
dff9f1b6
DE
795 /* If we are optimizing big endian systems for space, use the load/store
796 multiple and string instructions. */
ef792183 797 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 798 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 799
a4f6c312
SS
800 /* Don't allow -mmultiple or -mstring on little endian systems
801 unless the cpu is a 750, because the hardware doesn't support the
802 instructions used in little endian mode, and causes an alignment
803 trap. The 750 does not cause an alignment trap (except when the
804 target is unaligned). */
bef84347 805
b21fb038 806 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
807 {
808 if (TARGET_MULTIPLE)
809 {
810 target_flags &= ~MASK_MULTIPLE;
b21fb038 811 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
812 warning ("-mmultiple is not supported on little endian systems");
813 }
814
815 if (TARGET_STRING)
816 {
817 target_flags &= ~MASK_STRING;
b21fb038 818 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 819 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
820 }
821 }
3933e0e1 822
38c1f2d7
MM
823 /* Set debug flags */
824 if (rs6000_debug_name)
825 {
bfc79d3b 826 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 827 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 828 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 829 rs6000_debug_stack = 1;
bfc79d3b 830 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
831 rs6000_debug_arg = 1;
832 else
c725bd79 833 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
834 }
835
57ac7be9
AM
836 if (rs6000_traceback_name)
837 {
838 if (! strncmp (rs6000_traceback_name, "full", 4))
839 rs6000_traceback = traceback_full;
840 else if (! strncmp (rs6000_traceback_name, "part", 4))
841 rs6000_traceback = traceback_part;
842 else if (! strncmp (rs6000_traceback_name, "no", 2))
843 rs6000_traceback = traceback_none;
844 else
845 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
846 rs6000_traceback_name);
847 }
848
6fa3f289
ZW
849 /* Set size of long double */
850 rs6000_long_double_type_size = 64;
851 if (rs6000_long_double_size_string)
852 {
853 char *tail;
854 int size = strtol (rs6000_long_double_size_string, &tail, 10);
855 if (*tail != '\0' || (size != 64 && size != 128))
856 error ("Unknown switch -mlong-double-%s",
857 rs6000_long_double_size_string);
858 else
859 rs6000_long_double_type_size = size;
860 }
861
6d0ef01e
HP
862 /* Set Altivec ABI as default for powerpc64 linux. */
863 if (TARGET_ELF && TARGET_64BIT)
864 {
865 rs6000_altivec_abi = 1;
866 rs6000_altivec_vrsave = 1;
867 }
868
0ac081f6
AH
869 /* Handle -mabi= options. */
870 rs6000_parse_abi_options ();
871
025d9908
KH
872 /* Handle -malign-XXXXX option. */
873 rs6000_parse_alignment_option ();
874
5da702b1
AH
875 /* Handle generic -mFOO=YES/NO options. */
876 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
877 &rs6000_altivec_vrsave);
878 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
879 &rs6000_isel);
880 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
881 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
882 &rs6000_float_gprs);
993f19a8 883
c4501e62
JJ
884 /* Handle -mtls-size option. */
885 rs6000_parse_tls_size_option ();
886
a7ae18e2
AH
887#ifdef SUBTARGET_OVERRIDE_OPTIONS
888 SUBTARGET_OVERRIDE_OPTIONS;
889#endif
890#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
891 SUBSUBTARGET_OVERRIDE_OPTIONS;
892#endif
893
5da702b1
AH
894 if (TARGET_E500)
895 {
e4463bf1
AH
896 if (TARGET_ALTIVEC)
897 error ("AltiVec and E500 instructions cannot coexist");
898
5da702b1
AH
899 /* The e500 does not have string instructions, and we set
900 MASK_STRING above when optimizing for size. */
901 if ((target_flags & MASK_STRING) != 0)
902 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
903
904 /* No SPE means 64-bit long doubles, even if an E500. */
905 if (rs6000_spe_string != 0
906 && !strcmp (rs6000_spe_string, "no"))
907 rs6000_long_double_type_size = 64;
5da702b1
AH
908 }
909 else if (rs6000_select[1].string != NULL)
910 {
911 /* For the powerpc-eabispe configuration, we set all these by
912 default, so let's unset them if we manually set another
913 CPU that is not the E500. */
914 if (rs6000_abi_string == 0)
915 rs6000_spe_abi = 0;
916 if (rs6000_spe_string == 0)
917 rs6000_spe = 0;
918 if (rs6000_float_gprs_string == 0)
919 rs6000_float_gprs = 0;
920 if (rs6000_isel_string == 0)
921 rs6000_isel = 0;
b6e59a3a
AH
922 if (rs6000_long_double_size_string == 0)
923 rs6000_long_double_type_size = 64;
5da702b1 924 }
b5044283 925
ec507f2d
DE
926 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
927 && rs6000_cpu != PROCESSOR_POWER5);
928 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
929 || rs6000_cpu == PROCESSOR_POWER5);
930
a5c76ee6
ZW
931 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
932 using TARGET_OPTIONS to handle a toggle switch, but we're out of
933 bits in target_flags so TARGET_SWITCHES cannot be used.
934 Assumption here is that rs6000_longcall_switch points into the
935 text of the complete option, rather than being a copy, so we can
936 scan back for the presence or absence of the no- modifier. */
937 if (rs6000_longcall_switch)
938 {
939 const char *base = rs6000_longcall_switch;
940 while (base[-1] != 'm') base--;
941
942 if (*rs6000_longcall_switch != '\0')
943 error ("invalid option `%s'", base);
944 rs6000_default_long_calls = (base[0] != 'n');
945 }
946
8bb418a3
ZL
947 /* Handle -m(no-)warn-altivec-long similarly. */
948 if (rs6000_warn_altivec_long_switch)
949 {
950 const char *base = rs6000_warn_altivec_long_switch;
951 while (base[-1] != 'm') base--;
952
953 if (*rs6000_warn_altivec_long_switch != '\0')
954 error ("invalid option `%s'", base);
955 rs6000_warn_altivec_long = (base[0] != 'n');
956 }
957
cbe26ab8 958 /* Handle -mprioritize-restricted-insns option. */
ec507f2d
DE
959 rs6000_sched_restricted_insns_priority
960 = (rs6000_sched_groups ? 1 : 0);
79ae11c4
DN
961 if (rs6000_sched_restricted_insns_priority_str)
962 rs6000_sched_restricted_insns_priority =
963 atoi (rs6000_sched_restricted_insns_priority_str);
964
569fa502 965 /* Handle -msched-costly-dep option. */
ec507f2d
DE
966 rs6000_sched_costly_dep
967 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
569fa502
DN
968 if (rs6000_sched_costly_dep_str)
969 {
970 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
971 rs6000_sched_costly_dep = no_dep_costly;
972 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
973 rs6000_sched_costly_dep = all_deps_costly;
974 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
975 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
976 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
977 rs6000_sched_costly_dep = store_to_load_dep_costly;
cbe26ab8
DN
978 else
979 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
980 }
981
982 /* Handle -minsert-sched-nops option. */
ec507f2d
DE
983 rs6000_sched_insert_nops
984 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
cbe26ab8
DN
985 if (rs6000_sched_insert_nops_str)
986 {
987 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
988 rs6000_sched_insert_nops = sched_finish_none;
989 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
990 rs6000_sched_insert_nops = sched_finish_pad_groups;
991 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
992 rs6000_sched_insert_nops = sched_finish_regroup_exact;
993 else
994 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
995 }
996
c81bebd7 997#ifdef TARGET_REGNAMES
a4f6c312
SS
998 /* If the user desires alternate register names, copy in the
999 alternate names now. */
c81bebd7 1000 if (TARGET_REGNAMES)
4e135bdd 1001 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
1002#endif
1003
6fa3f289
ZW
1004 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
1005 If -maix-struct-return or -msvr4-struct-return was explicitly
1006 used, don't override with the ABI default. */
b21fb038 1007 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
1008 {
1009 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
1010 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
1011 else
1012 target_flags |= MASK_AIX_STRUCT_RET;
1013 }
1014
fcce224d
DE
1015 if (TARGET_LONG_DOUBLE_128
1016 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 1017 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 1018
9ebbca7d
GK
1019 /* Allocate an alias set for register saves & restores from stack. */
1020 rs6000_sr_alias_set = new_alias_set ();
1021
1022 if (TARGET_TOC)
1023 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 1024
301d03af
RS
1025 /* We can only guarantee the availability of DI pseudo-ops when
1026 assembling for 64-bit targets. */
ae6c1efd 1027 if (!TARGET_64BIT)
301d03af
RS
1028 {
1029 targetm.asm_out.aligned_op.di = NULL;
1030 targetm.asm_out.unaligned_op.di = NULL;
1031 }
1032
2792d578
DE
1033 /* Set maximum branch target alignment at two instructions, eight bytes. */
1034 align_jumps_max_skip = 8;
1035 align_loops_max_skip = 8;
1036
71f123ca
FS
1037 /* Arrange to save and restore machine status around nested functions. */
1038 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1039
1040 /* We should always be splitting complex arguments, but we can't break
1041 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1042 if (DEFAULT_ABI != ABI_AIX)
1043 targetm.calls.split_complex_arg = NULL;
5248c961 1044}
5accd822 1045
5da702b1
AH
1046/* Handle generic options of the form -mfoo=yes/no.
1047 NAME is the option name.
1048 VALUE is the option value.
1049 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1050 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1051static void
5da702b1 1052rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1053{
5da702b1 1054 if (value == 0)
993f19a8 1055 return;
5da702b1
AH
1056 else if (!strcmp (value, "yes"))
1057 *flag = 1;
1058 else if (!strcmp (value, "no"))
1059 *flag = 0;
08b57fb3 1060 else
5da702b1 1061 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1062}
1063
0ac081f6 1064/* Handle -mabi= options. */
00b960c7 1065static void
863d938c 1066rs6000_parse_abi_options (void)
0ac081f6
AH
1067{
1068 if (rs6000_abi_string == 0)
1069 return;
1070 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1071 {
1072 rs6000_altivec_abi = 1;
1073 rs6000_spe_abi = 0;
1074 }
76a773f3
AH
1075 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1076 rs6000_altivec_abi = 0;
a3170dc6 1077 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1078 {
1079 rs6000_spe_abi = 1;
5cc73f91 1080 rs6000_altivec_abi = 0;
01f4962d
NS
1081 if (!TARGET_SPE_ABI)
1082 error ("not configured for ABI: '%s'", rs6000_abi_string);
1083 }
1084
a3170dc6
AH
1085 else if (! strcmp (rs6000_abi_string, "no-spe"))
1086 rs6000_spe_abi = 0;
0ac081f6 1087 else
c725bd79 1088 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1089}
1090
025d9908
KH
1091/* Handle -malign-XXXXXX options. */
1092static void
863d938c 1093rs6000_parse_alignment_option (void)
025d9908 1094{
b20a9cca
AM
1095 if (rs6000_alignment_string == 0)
1096 return;
1097 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1098 rs6000_alignment_flags = MASK_ALIGN_POWER;
1099 else if (! strcmp (rs6000_alignment_string, "natural"))
1100 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1101 else
1102 error ("unknown -malign-XXXXX option specified: '%s'",
1103 rs6000_alignment_string);
1104}
1105
c4501e62
JJ
1106/* Validate and record the size specified with the -mtls-size option. */
1107
1108static void
863d938c 1109rs6000_parse_tls_size_option (void)
c4501e62
JJ
1110{
1111 if (rs6000_tls_size_string == 0)
1112 return;
1113 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1114 rs6000_tls_size = 16;
1115 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1116 rs6000_tls_size = 32;
1117 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1118 rs6000_tls_size = 64;
1119 else
1120 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1121}
1122
5accd822 1123void
a2369ed3 1124optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1125{
5accd822 1126}
3cfa4909
MM
1127\f
1128/* Do anything needed at the start of the asm file. */
1129
1bc7c5b6 1130static void
863d938c 1131rs6000_file_start (void)
3cfa4909 1132{
c4d38ccb 1133 size_t i;
3cfa4909 1134 char buffer[80];
d330fd93 1135 const char *start = buffer;
3cfa4909 1136 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1137 const char *default_cpu = TARGET_CPU_DEFAULT;
1138 FILE *file = asm_out_file;
1139
1140 default_file_start ();
1141
1142#ifdef TARGET_BI_ARCH
1143 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1144 default_cpu = 0;
1145#endif
3cfa4909
MM
1146
1147 if (flag_verbose_asm)
1148 {
1149 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1150 rs6000_select[0].string = default_cpu;
1151
b6a1cbae 1152 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1153 {
1154 ptr = &rs6000_select[i];
1155 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1156 {
1157 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1158 start = "";
1159 }
1160 }
1161
b91da81f 1162#ifdef USING_ELFOS_H
3cfa4909
MM
1163 switch (rs6000_sdata)
1164 {
1165 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1166 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1167 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1168 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1169 }
1170
1171 if (rs6000_sdata && g_switch_value)
1172 {
307b599c
MK
1173 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1174 g_switch_value);
3cfa4909
MM
1175 start = "";
1176 }
1177#endif
1178
1179 if (*start == '\0')
949ea356 1180 putc ('\n', file);
3cfa4909
MM
1181 }
1182}
5248c961 1183\f
a0ab749a 1184/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1185
1186int
863d938c 1187direct_return (void)
9878760c 1188{
4697a36c
MM
1189 if (reload_completed)
1190 {
1191 rs6000_stack_t *info = rs6000_stack_info ();
1192
1193 if (info->first_gp_reg_save == 32
1194 && info->first_fp_reg_save == 64
00b960c7 1195 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1196 && ! info->lr_save_p
1197 && ! info->cr_save_p
00b960c7 1198 && info->vrsave_mask == 0
c81fc13e 1199 && ! info->push_p)
4697a36c
MM
1200 return 1;
1201 }
1202
1203 return 0;
9878760c
RK
1204}
1205
1206/* Returns 1 always. */
1207
1208int
a2369ed3
DJ
1209any_operand (rtx op ATTRIBUTE_UNUSED,
1210 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1211{
1212 return 1;
1213}
1214
a4f6c312 1215/* Returns 1 if op is the count register. */
38c1f2d7 1216int
a2369ed3 1217count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1218{
1219 if (GET_CODE (op) != REG)
1220 return 0;
1221
1222 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1223 return 1;
1224
1225 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1226 return 1;
1227
1228 return 0;
1229}
1230
0ec4e2a8
AH
1231/* Returns 1 if op is an altivec register. */
1232int
a2369ed3 1233altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8
AH
1234{
1235
1236 return (register_operand (op, mode)
1237 && (GET_CODE (op) != REG
1238 || REGNO (op) > FIRST_PSEUDO_REGISTER
1239 || ALTIVEC_REGNO_P (REGNO (op))));
1240}
1241
38c1f2d7 1242int
a2369ed3 1243xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1244{
1245 if (GET_CODE (op) != REG)
1246 return 0;
1247
9ebbca7d 1248 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1249 return 1;
1250
802a0058
MM
1251 return 0;
1252}
1253
c859cda6 1254/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1255 by such constants completes more quickly. */
c859cda6
DJ
1256
1257int
a2369ed3 1258s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6
DJ
1259{
1260 return ( GET_CODE (op) == CONST_INT
1261 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1262}
1263
9878760c
RK
1264/* Return 1 if OP is a constant that can fit in a D field. */
1265
1266int
a2369ed3 1267short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1268{
5f59ecb7
DE
1269 return (GET_CODE (op) == CONST_INT
1270 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1271}
1272
5519a4f9 1273/* Similar for an unsigned D field. */
9878760c
RK
1274
1275int
a2369ed3 1276u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1277{
19684119 1278 return (GET_CODE (op) == CONST_INT
c1f11548 1279 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1280}
1281
dcfedcd0
RK
1282/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1283
1284int
a2369ed3 1285non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1286{
1287 return (GET_CODE (op) == CONST_INT
a7653a2c 1288 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1289}
1290
2bfcf297
DB
1291/* Returns 1 if OP is a CONST_INT that is a positive value
1292 and an exact power of 2. */
1293
1294int
a2369ed3 1295exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1296{
1297 return (GET_CODE (op) == CONST_INT
1298 && INTVAL (op) > 0
1299 && exact_log2 (INTVAL (op)) >= 0);
1300}
1301
9878760c
RK
1302/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1303 ctr, or lr). */
1304
1305int
a2369ed3 1306gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1307{
1308 return (register_operand (op, mode)
802a0058 1309 && (GET_CODE (op) != REG
9ebbca7d
GK
1310 || (REGNO (op) >= ARG_POINTER_REGNUM
1311 && !XER_REGNO_P (REGNO (op)))
1312 || REGNO (op) < MQ_REGNO));
9878760c
RK
1313}
1314
1315/* Returns 1 if OP is either a pseudo-register or a register denoting a
1316 CR field. */
1317
1318int
a2369ed3 1319cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1320{
1321 return (register_operand (op, mode)
1322 && (GET_CODE (op) != REG
1323 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1324 || CR_REGNO_P (REGNO (op))));
1325}
1326
815cdc52
MM
1327/* Returns 1 if OP is either a pseudo-register or a register denoting a
1328 CR field that isn't CR0. */
1329
1330int
a2369ed3 1331cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1332{
1333 return (register_operand (op, mode)
1334 && (GET_CODE (op) != REG
1335 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1336 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1337}
1338
a4f6c312
SS
1339/* Returns 1 if OP is either a constant integer valid for a D-field or
1340 a non-special register. If a register, it must be in the proper
1341 mode unless MODE is VOIDmode. */
9878760c
RK
1342
1343int
a2369ed3 1344reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1345{
f5a28898 1346 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1347}
1348
a4f6c312
SS
1349/* Similar, except check if the negation of the constant would be
1350 valid for a D-field. */
9878760c
RK
1351
1352int
a2369ed3 1353reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1354{
1355 if (GET_CODE (op) == CONST_INT)
1356 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1357
cd2b37d9 1358 return gpc_reg_operand (op, mode);
9878760c
RK
1359}
1360
768070a0
TR
1361/* Returns 1 if OP is either a constant integer valid for a DS-field or
1362 a non-special register. If a register, it must be in the proper
1363 mode unless MODE is VOIDmode. */
1364
1365int
a2369ed3 1366reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1367{
1368 if (gpc_reg_operand (op, mode))
1369 return 1;
1370 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1371 return 1;
1372
1373 return 0;
1374}
1375
1376
a4f6c312
SS
1377/* Return 1 if the operand is either a register or an integer whose
1378 high-order 16 bits are zero. */
9878760c
RK
1379
1380int
a2369ed3 1381reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1382{
e675f625 1383 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1384}
1385
1386/* Return 1 is the operand is either a non-special register or ANY
1387 constant integer. */
1388
1389int
a2369ed3 1390reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1391{
a4f6c312 1392 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1393}
1394
1395/* Return 1 is the operand is either a non-special register or ANY
1396 32-bit signed constant integer. */
1397
1398int
a2369ed3 1399reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1400{
a4f6c312
SS
1401 return (gpc_reg_operand (op, mode)
1402 || (GET_CODE (op) == CONST_INT
f6bf7de2 1403#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1404 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1405 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1406#endif
a4f6c312 1407 ));
9878760c
RK
1408}
1409
2bfcf297
DB
1410/* Return 1 is the operand is either a non-special register or a 32-bit
1411 signed constant integer valid for 64-bit addition. */
1412
1413int
a2369ed3 1414reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1415{
a4f6c312
SS
1416 return (gpc_reg_operand (op, mode)
1417 || (GET_CODE (op) == CONST_INT
a65c591c 1418#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1419 && INTVAL (op) < 0x7fff8000
a65c591c 1420#else
a4f6c312
SS
1421 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1422 < 0x100000000ll)
2bfcf297 1423#endif
a4f6c312 1424 ));
2bfcf297
DB
1425}
1426
1427/* Return 1 is the operand is either a non-special register or a 32-bit
1428 signed constant integer valid for 64-bit subtraction. */
1429
1430int
a2369ed3 1431reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1432{
a4f6c312
SS
1433 return (gpc_reg_operand (op, mode)
1434 || (GET_CODE (op) == CONST_INT
a65c591c 1435#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1436 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1437#else
a4f6c312
SS
1438 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1439 < 0x100000000ll)
2bfcf297 1440#endif
a4f6c312 1441 ));
2bfcf297
DB
1442}
1443
9ebbca7d
GK
1444/* Return 1 is the operand is either a non-special register or ANY
1445 32-bit unsigned constant integer. */
1446
1447int
a2369ed3 1448reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1449{
1d328b19
GK
1450 if (GET_CODE (op) == CONST_INT)
1451 {
1452 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1453 {
1454 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1455 abort ();
1d328b19
GK
1456
1457 if (INTVAL (op) < 0)
1458 return 0;
1459 }
1460
1461 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1462 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1463 }
1464 else if (GET_CODE (op) == CONST_DOUBLE)
1465 {
1466 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1467 || mode != DImode)
a4f6c312 1468 abort ();
1d328b19
GK
1469
1470 return CONST_DOUBLE_HIGH (op) == 0;
1471 }
1472 else
1473 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1474}
1475
51d3e7d6 1476/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1477
1478int
a2369ed3 1479got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
1480{
1481 return (GET_CODE (op) == SYMBOL_REF
1482 || GET_CODE (op) == CONST
1483 || GET_CODE (op) == LABEL_REF);
1484}
1485
38c1f2d7
MM
1486/* Return 1 if the operand is a simple references that can be loaded via
1487 the GOT (labels involving addition aren't allowed). */
1488
1489int
a2369ed3 1490got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
1491{
1492 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1493}
1494
4e74d8ec
MM
1495/* Return the number of instructions it takes to form a constant in an
1496 integer register. */
1497
1498static int
a2369ed3 1499num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
1500{
1501 /* signed constant loadable with {cal|addi} */
5f59ecb7 1502 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1503 return 1;
1504
4e74d8ec 1505 /* constant loadable with {cau|addis} */
5f59ecb7 1506 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1507 return 1;
1508
5f59ecb7 1509#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1510 else if (TARGET_POWERPC64)
4e74d8ec 1511 {
a65c591c
DE
1512 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1513 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1514
a65c591c 1515 if (high == 0 || high == -1)
4e74d8ec
MM
1516 return 2;
1517
a65c591c 1518 high >>= 1;
4e74d8ec 1519
a65c591c 1520 if (low == 0)
4e74d8ec 1521 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1522 else
1523 return (num_insns_constant_wide (high)
e396202a 1524 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1525 }
1526#endif
1527
1528 else
1529 return 2;
1530}
1531
1532int
a2369ed3 1533num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 1534{
4e74d8ec 1535 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1536 {
1537#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1538 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1539 && mask64_operand (op, mode))
0d30d435
DE
1540 return 2;
1541 else
1542#endif
1543 return num_insns_constant_wide (INTVAL (op));
1544 }
4e74d8ec 1545
6fc48950
MM
1546 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1547 {
1548 long l;
1549 REAL_VALUE_TYPE rv;
1550
1551 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1552 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1553 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1554 }
1555
47ad8c61 1556 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1557 {
47ad8c61
MM
1558 HOST_WIDE_INT low;
1559 HOST_WIDE_INT high;
1560 long l[2];
1561 REAL_VALUE_TYPE rv;
1562 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1563
47ad8c61
MM
1564 if (mode == VOIDmode || mode == DImode)
1565 {
1566 high = CONST_DOUBLE_HIGH (op);
1567 low = CONST_DOUBLE_LOW (op);
1568 }
1569 else
1570 {
1571 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1572 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1573 high = l[endian];
1574 low = l[1 - endian];
1575 }
4e74d8ec 1576
47ad8c61
MM
1577 if (TARGET_32BIT)
1578 return (num_insns_constant_wide (low)
1579 + num_insns_constant_wide (high));
4e74d8ec
MM
1580
1581 else
47ad8c61 1582 {
e72247f4 1583 if (high == 0 && low >= 0)
47ad8c61
MM
1584 return num_insns_constant_wide (low);
1585
e72247f4 1586 else if (high == -1 && low < 0)
47ad8c61
MM
1587 return num_insns_constant_wide (low);
1588
a260abc9
DE
1589 else if (mask64_operand (op, mode))
1590 return 2;
1591
47ad8c61
MM
1592 else if (low == 0)
1593 return num_insns_constant_wide (high) + 1;
1594
1595 else
1596 return (num_insns_constant_wide (high)
1597 + num_insns_constant_wide (low) + 1);
1598 }
4e74d8ec
MM
1599 }
1600
1601 else
1602 abort ();
1603}
1604
a4f6c312
SS
1605/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1606 register with one instruction per word. We only do this if we can
1607 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1608
1609int
a2369ed3 1610easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 1611{
9878760c
RK
1612 if (GET_CODE (op) != CONST_DOUBLE
1613 || GET_MODE (op) != mode
4e74d8ec 1614 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1615 return 0;
1616
a4f6c312 1617 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1618 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1619 && mode != DImode)
b6c9286a
MM
1620 return 1;
1621
a4f6c312 1622 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1623 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1624 return 0;
1625
5ae4759c 1626#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1627 /* Similarly if we are using -mrelocatable, consider all constants
1628 to be hard. */
5ae4759c
MM
1629 if (TARGET_RELOCATABLE)
1630 return 0;
1631#endif
1632
fcce224d
DE
1633 if (mode == TFmode)
1634 {
1635 long k[4];
1636 REAL_VALUE_TYPE rv;
1637
1638 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1639 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1640
1641 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1642 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1643 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1644 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1645 }
1646
1647 else if (mode == DFmode)
042259f2
DE
1648 {
1649 long k[2];
1650 REAL_VALUE_TYPE rv;
1651
1652 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1653 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1654
a65c591c
DE
1655 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1656 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1657 }
4e74d8ec
MM
1658
1659 else if (mode == SFmode)
042259f2
DE
1660 {
1661 long l;
1662 REAL_VALUE_TYPE rv;
1663
1664 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1665 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1666
4e74d8ec 1667 return num_insns_constant_wide (l) == 1;
042259f2 1668 }
4e74d8ec 1669
a260abc9 1670 else if (mode == DImode)
c81fc13e 1671 return ((TARGET_POWERPC64
a260abc9
DE
1672 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1673 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1674
a9098fd0
GK
1675 else if (mode == SImode)
1676 return 1;
4e74d8ec
MM
1677 else
1678 abort ();
9878760c 1679}
8f75773e 1680
452a7d36
HP
1681/* Returns the constant for the splat instrunction, if exists. */
1682
1683static int
1684easy_vector_splat_const (int cst, enum machine_mode mode)
1685{
1686 switch (mode)
1687 {
1688 case V4SImode:
1689 if (EASY_VECTOR_15 (cst)
1690 || EASY_VECTOR_15_ADD_SELF (cst))
1691 return cst;
1692 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
1693 break;
1694 cst = cst >> 16;
1695 case V8HImode:
1696 if (EASY_VECTOR_15 (cst)
1697 || EASY_VECTOR_15_ADD_SELF (cst))
1698 return cst;
1699 if ((cst & 0xff) != ((cst >> 8) & 0xff))
1700 break;
1701 cst = cst >> 8;
1702 case V16QImode:
1703 if (EASY_VECTOR_15 (cst)
1704 || EASY_VECTOR_15_ADD_SELF (cst))
1705 return cst;
1706 default:
1707 break;
1708 }
1709 return 0;
1710}
1711
1712
72ac76be 1713/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
1714
1715static int
a2369ed3 1716easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
1717{
1718 int units, i, cst;
1719
1720 units = CONST_VECTOR_NUNITS (op);
1721
1722 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1723 for (i = 1; i < units; ++i)
1724 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1725 break;
452a7d36 1726 if (i == units && easy_vector_splat_const (cst, mode))
d744e06e
AH
1727 return 1;
1728 return 0;
1729}
1730
1731/* Return 1 if the operand is a CONST_INT and can be put into a
1732 register without using memory. */
1733
1734int
a2369ed3 1735easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 1736{
d744e06e 1737 int cst, cst2;
69ef87e2 1738
d744e06e
AH
1739 if (GET_CODE (op) != CONST_VECTOR
1740 || (!TARGET_ALTIVEC
1741 && !TARGET_SPE))
69ef87e2
AH
1742 return 0;
1743
d744e06e
AH
1744 if (zero_constant (op, mode)
1745 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1746 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1747 return 1;
69ef87e2 1748
d744e06e
AH
1749 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1750 return 0;
1751
f5119d10
AH
1752 if (TARGET_SPE && mode == V1DImode)
1753 return 0;
1754
d744e06e
AH
1755 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1756 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1757
1758 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1759 li r0, CONSTANT1
1760 evmergelo r0, r0, r0
1761 li r0, CONSTANT2
1762
1763 I don't know how efficient it would be to allow bigger constants,
1764 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1765 instructions is better than a 64-bit memory load, but I don't
1766 have the e500 timing specs. */
1767 if (TARGET_SPE && mode == V2SImode
1768 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 1769 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
1770 return 1;
1771
452a7d36
HP
1772 if (TARGET_ALTIVEC
1773 && easy_vector_same (op, mode))
1774 {
1775 cst = easy_vector_splat_const (cst, mode);
1776 if (EASY_VECTOR_15_ADD_SELF (cst)
1777 || EASY_VECTOR_15 (cst))
1778 return 1;
1779 }
d744e06e
AH
1780 return 0;
1781}
1782
1783/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1784
1785int
a2369ed3 1786easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
1787{
1788 int cst;
452a7d36
HP
1789 if (TARGET_ALTIVEC
1790 && GET_CODE (op) == CONST_VECTOR
1791 && easy_vector_same (op, mode))
1792 {
1793 cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode);
1794 if (EASY_VECTOR_15_ADD_SELF (cst))
1795 return 1;
1796 }
1797 return 0;
1798}
d744e06e 1799
452a7d36 1800/* Generate easy_vector_constant out of a easy_vector_constant_add_self. */
d744e06e 1801
452a7d36
HP
1802rtx
1803gen_easy_vector_constant_add_self (rtx op)
1804{
1805 int i, units;
1806 rtvec v;
1807 units = GET_MODE_NUNITS (GET_MODE (op));
1808 v = rtvec_alloc (units);
1809
1810 for (i = 0; i < units; i++)
1811 RTVEC_ELT (v, i) =
1812 GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1);
1813 return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v);
d744e06e
AH
1814}
1815
1816const char *
a2369ed3 1817output_vec_const_move (rtx *operands)
d744e06e
AH
1818{
1819 int cst, cst2;
1820 enum machine_mode mode;
1821 rtx dest, vec;
1822
1823 dest = operands[0];
1824 vec = operands[1];
69ef87e2 1825
d744e06e
AH
1826 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1827 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1828 mode = GET_MODE (dest);
69ef87e2 1829
d744e06e
AH
1830 if (TARGET_ALTIVEC)
1831 {
1832 if (zero_constant (vec, mode))
1833 return "vxor %0,%0,%0";
ce1f50b2 1834 else if (easy_vector_constant (vec, mode))
98ef3137 1835 {
d744e06e
AH
1836 operands[1] = GEN_INT (cst);
1837 switch (mode)
1838 {
1839 case V4SImode:
452a7d36 1840 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
1841 {
1842 operands[1] = GEN_INT (cst);
1843 return "vspltisw %0,%1";
1844 }
452a7d36
HP
1845 else if (EASY_VECTOR_15_ADD_SELF (cst))
1846 return "#";
ce1f50b2 1847 cst = cst >> 16;
d744e06e 1848 case V8HImode:
452a7d36 1849 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
1850 {
1851 operands[1] = GEN_INT (cst);
1852 return "vspltish %0,%1";
1853 }
452a7d36
HP
1854 else if (EASY_VECTOR_15_ADD_SELF (cst))
1855 return "#";
ce1f50b2 1856 cst = cst >> 8;
d744e06e 1857 case V16QImode:
452a7d36 1858 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
1859 {
1860 operands[1] = GEN_INT (cst);
1861 return "vspltisb %0,%1";
1862 }
452a7d36
HP
1863 else if (EASY_VECTOR_15_ADD_SELF (cst))
1864 return "#";
d744e06e
AH
1865 default:
1866 abort ();
1867 }
98ef3137 1868 }
d744e06e
AH
1869 else
1870 abort ();
69ef87e2
AH
1871 }
1872
d744e06e
AH
1873 if (TARGET_SPE)
1874 {
1875 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1876 pattern of V1DI, V4HI, and V2SF.
1877
c1207243 1878 FIXME: We should probably return # and add post reload
d744e06e
AH
1879 splitters for these, but this way is so easy ;-).
1880 */
1881 operands[1] = GEN_INT (cst);
1882 operands[2] = GEN_INT (cst2);
1883 if (cst == cst2)
1884 return "li %0,%1\n\tevmergelo %0,%0,%0";
1885 else
1886 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1887 }
1888
1889 abort ();
69ef87e2
AH
1890}
1891
1892/* Return 1 if the operand is the constant 0. This works for scalars
1893 as well as vectors. */
1894int
a2369ed3 1895zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
1896{
1897 return op == CONST0_RTX (mode);
1898}
1899
50a0b056
GK
1900/* Return 1 if the operand is 0.0. */
1901int
a2369ed3 1902zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
1903{
1904 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1905}
1906
a4f6c312
SS
1907/* Return 1 if the operand is in volatile memory. Note that during
1908 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1909 volatile memory references. So this function allows us to
1910 recognize volatile references where its safe. */
1911
1912int
a2369ed3 1913volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
1914{
1915 if (GET_CODE (op) != MEM)
1916 return 0;
1917
1918 if (!MEM_VOLATILE_P (op))
1919 return 0;
1920
1921 if (mode != GET_MODE (op))
1922 return 0;
1923
1924 if (reload_completed)
1925 return memory_operand (op, mode);
1926
1927 if (reload_in_progress)
1928 return strict_memory_address_p (mode, XEXP (op, 0));
1929
1930 return memory_address_p (mode, XEXP (op, 0));
1931}
1932
97f6e72f 1933/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1934
1935int
a2369ed3 1936offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 1937{
97f6e72f 1938 return ((GET_CODE (op) == MEM)
677a9668 1939 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1940 mode, XEXP (op, 0)));
914c2e77
RK
1941}
1942
9878760c
RK
1943/* Return 1 if the operand is either an easy FP constant (see above) or
1944 memory. */
1945
1946int
a2369ed3 1947mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
1948{
1949 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1950}
1951
1952/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1953 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1954
1955int
a2369ed3 1956add_operand (rtx op, enum machine_mode mode)
9878760c 1957{
2bfcf297 1958 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1959 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1960 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1961
1962 return gpc_reg_operand (op, mode);
9878760c
RK
1963}
1964
dcfedcd0
RK
1965/* Return 1 if OP is a constant but not a valid add_operand. */
1966
1967int
a2369ed3 1968non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1969{
1970 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1971 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1972 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1973}
1974
9878760c
RK
1975/* Return 1 if the operand is a non-special register or a constant that
1976 can be used as the operand of an OR or XOR insn on the RS/6000. */
1977
1978int
a2369ed3 1979logical_operand (rtx op, enum machine_mode mode)
9878760c 1980{
40501e5f 1981 HOST_WIDE_INT opl, oph;
1d328b19 1982
dfbdccdb
GK
1983 if (gpc_reg_operand (op, mode))
1984 return 1;
1d328b19 1985
dfbdccdb 1986 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1987 {
1988 opl = INTVAL (op) & GET_MODE_MASK (mode);
1989
1990#if HOST_BITS_PER_WIDE_INT <= 32
1991 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1992 return 0;
1993#endif
1994 }
dfbdccdb
GK
1995 else if (GET_CODE (op) == CONST_DOUBLE)
1996 {
1d328b19 1997 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1998 abort ();
1d328b19
GK
1999
2000 opl = CONST_DOUBLE_LOW (op);
2001 oph = CONST_DOUBLE_HIGH (op);
40501e5f 2002 if (oph != 0)
38886f37 2003 return 0;
dfbdccdb
GK
2004 }
2005 else
2006 return 0;
1d328b19 2007
40501e5f
AM
2008 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
2009 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
2010}
2011
dcfedcd0 2012/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 2013 above), but could be split into one. */
dcfedcd0
RK
2014
2015int
a2369ed3 2016non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 2017{
dfbdccdb 2018 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
2019 && ! logical_operand (op, mode)
2020 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
2021}
2022
19ba8161 2023/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
2024 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
2025 Reject all ones and all zeros, since these should have been optimized
2026 away and confuse the making of MB and ME. */
2027
2028int
a2369ed3 2029mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 2030{
02071907 2031 HOST_WIDE_INT c, lsb;
9878760c 2032
19ba8161
DE
2033 if (GET_CODE (op) != CONST_INT)
2034 return 0;
2035
2036 c = INTVAL (op);
2037
57deb3a1
AM
2038 /* Fail in 64-bit mode if the mask wraps around because the upper
2039 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
2040 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
2041 return 0;
2042
c5059423
AM
2043 /* We don't change the number of transitions by inverting,
2044 so make sure we start with the LS bit zero. */
2045 if (c & 1)
2046 c = ~c;
2047
2048 /* Reject all zeros or all ones. */
2049 if (c == 0)
9878760c
RK
2050 return 0;
2051
c5059423
AM
2052 /* Find the first transition. */
2053 lsb = c & -c;
2054
2055 /* Invert to look for a second transition. */
2056 c = ~c;
9878760c 2057
c5059423
AM
2058 /* Erase first transition. */
2059 c &= -lsb;
9878760c 2060
c5059423
AM
2061 /* Find the second transition (if any). */
2062 lsb = c & -c;
2063
2064 /* Match if all the bits above are 1's (or c is zero). */
2065 return c == -lsb;
9878760c
RK
2066}
2067
0ba1b2ff
AM
2068/* Return 1 for the PowerPC64 rlwinm corner case. */
2069
2070int
a2369ed3 2071mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2072{
2073 HOST_WIDE_INT c, lsb;
2074
2075 if (GET_CODE (op) != CONST_INT)
2076 return 0;
2077
2078 c = INTVAL (op);
2079
2080 if ((c & 0x80000001) != 0x80000001)
2081 return 0;
2082
2083 c = ~c;
2084 if (c == 0)
2085 return 0;
2086
2087 lsb = c & -c;
2088 c = ~c;
2089 c &= -lsb;
2090 lsb = c & -c;
2091 return c == -lsb;
2092}
2093
a260abc9
DE
2094/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2095 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2096 Reject all zeros, since zero should have been optimized away and
2097 confuses the making of MB and ME. */
9878760c
RK
2098
2099int
a2369ed3 2100mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2101{
2102 if (GET_CODE (op) == CONST_INT)
2103 {
02071907 2104 HOST_WIDE_INT c, lsb;
a260abc9 2105
c5059423 2106 c = INTVAL (op);
a260abc9 2107
0ba1b2ff 2108 /* Reject all zeros. */
c5059423 2109 if (c == 0)
e2c953b6
DE
2110 return 0;
2111
0ba1b2ff
AM
2112 /* We don't change the number of transitions by inverting,
2113 so make sure we start with the LS bit zero. */
2114 if (c & 1)
2115 c = ~c;
2116
c5059423
AM
2117 /* Find the transition, and check that all bits above are 1's. */
2118 lsb = c & -c;
e3981aab
DE
2119
2120 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2121 return c == -lsb;
e2c953b6 2122 }
0ba1b2ff
AM
2123 return 0;
2124}
2125
2126/* Like mask64_operand, but allow up to three transitions. This
2127 predicate is used by insn patterns that generate two rldicl or
2128 rldicr machine insns. */
2129
2130int
a2369ed3 2131mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2132{
2133 if (GET_CODE (op) == CONST_INT)
a260abc9 2134 {
0ba1b2ff 2135 HOST_WIDE_INT c, lsb;
a260abc9 2136
0ba1b2ff 2137 c = INTVAL (op);
a260abc9 2138
0ba1b2ff
AM
2139 /* Disallow all zeros. */
2140 if (c == 0)
2141 return 0;
a260abc9 2142
0ba1b2ff
AM
2143 /* We don't change the number of transitions by inverting,
2144 so make sure we start with the LS bit zero. */
2145 if (c & 1)
2146 c = ~c;
a260abc9 2147
0ba1b2ff
AM
2148 /* Find the first transition. */
2149 lsb = c & -c;
a260abc9 2150
0ba1b2ff
AM
2151 /* Invert to look for a second transition. */
2152 c = ~c;
2153
2154 /* Erase first transition. */
2155 c &= -lsb;
2156
2157 /* Find the second transition. */
2158 lsb = c & -c;
2159
2160 /* Invert to look for a third transition. */
2161 c = ~c;
2162
2163 /* Erase second transition. */
2164 c &= -lsb;
2165
2166 /* Find the third transition (if any). */
2167 lsb = c & -c;
2168
2169 /* Match if all the bits above are 1's (or c is zero). */
2170 return c == -lsb;
2171 }
2172 return 0;
2173}
2174
2175/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2176 implement ANDing by the mask IN. */
2177void
a2369ed3 2178build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2179{
2180#if HOST_BITS_PER_WIDE_INT >= 64
2181 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2182 int shift;
2183
2184 if (GET_CODE (in) != CONST_INT)
2185 abort ();
2186
2187 c = INTVAL (in);
2188 if (c & 1)
2189 {
2190 /* Assume c initially something like 0x00fff000000fffff. The idea
2191 is to rotate the word so that the middle ^^^^^^ group of zeros
2192 is at the MS end and can be cleared with an rldicl mask. We then
2193 rotate back and clear off the MS ^^ group of zeros with a
2194 second rldicl. */
2195 c = ~c; /* c == 0xff000ffffff00000 */
2196 lsb = c & -c; /* lsb == 0x0000000000100000 */
2197 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2198 c = ~c; /* c == 0x00fff000000fffff */
2199 c &= -lsb; /* c == 0x00fff00000000000 */
2200 lsb = c & -c; /* lsb == 0x0000100000000000 */
2201 c = ~c; /* c == 0xff000fffffffffff */
2202 c &= -lsb; /* c == 0xff00000000000000 */
2203 shift = 0;
2204 while ((lsb >>= 1) != 0)
2205 shift++; /* shift == 44 on exit from loop */
2206 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2207 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2208 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2209 }
2210 else
0ba1b2ff
AM
2211 {
2212 /* Assume c initially something like 0xff000f0000000000. The idea
2213 is to rotate the word so that the ^^^ middle group of zeros
2214 is at the LS end and can be cleared with an rldicr mask. We then
2215 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2216 a second rldicr. */
2217 lsb = c & -c; /* lsb == 0x0000010000000000 */
2218 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2219 c = ~c; /* c == 0x00fff0ffffffffff */
2220 c &= -lsb; /* c == 0x00fff00000000000 */
2221 lsb = c & -c; /* lsb == 0x0000100000000000 */
2222 c = ~c; /* c == 0xff000fffffffffff */
2223 c &= -lsb; /* c == 0xff00000000000000 */
2224 shift = 0;
2225 while ((lsb >>= 1) != 0)
2226 shift++; /* shift == 44 on exit from loop */
2227 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2228 m1 >>= shift; /* m1 == 0x0000000000000fff */
2229 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2230 }
2231
2232 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2233 masks will be all 1's. We are guaranteed more than one transition. */
2234 out[0] = GEN_INT (64 - shift);
2235 out[1] = GEN_INT (m1);
2236 out[2] = GEN_INT (shift);
2237 out[3] = GEN_INT (m2);
2238#else
045572c7
GK
2239 (void)in;
2240 (void)out;
0ba1b2ff
AM
2241 abort ();
2242#endif
a260abc9
DE
2243}
2244
2245/* Return 1 if the operand is either a non-special register or a constant
2246 that can be used as the operand of a PowerPC64 logical AND insn. */
2247
2248int
a2369ed3 2249and64_operand (rtx op, enum machine_mode mode)
9878760c 2250{
a4f6c312 2251 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2252 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2253
2254 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2255}
2256
0ba1b2ff
AM
2257/* Like the above, but also match constants that can be implemented
2258 with two rldicl or rldicr insns. */
2259
2260int
a2369ed3 2261and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2262{
a3c9585f 2263 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2264 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2265
2266 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2267}
2268
a260abc9
DE
2269/* Return 1 if the operand is either a non-special register or a
2270 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2271
2272int
a2369ed3 2273and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2274{
a4f6c312 2275 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2276 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2277
2278 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2279}
2280
9878760c
RK
2281/* Return 1 if the operand is a general register or memory operand. */
2282
2283int
a2369ed3 2284reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2285{
b6c9286a
MM
2286 return (gpc_reg_operand (op, mode)
2287 || memory_operand (op, mode)
4c81e946 2288 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2289 || volatile_mem_operand (op, mode));
9878760c
RK
2290}
2291
a7a813f7 2292/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2293 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2294 instruction. */
2295
2296int
a2369ed3 2297lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2298{
2299 rtx inner = op;
2300
2301 if (reload_completed && GET_CODE (inner) == SUBREG)
2302 inner = SUBREG_REG (inner);
2303
2304 return gpc_reg_operand (inner, mode)
2305 || (memory_operand (inner, mode)
2306 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2307 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2308 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2309 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2310 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2311}
2312
cc4d5fec
JH
2313/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2314
2315int
a2369ed3 2316symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2317{
2318 if (mode != VOIDmode && GET_MODE (op) != mode)
2319 return 0;
2320
473f51b6
DE
2321 return (GET_CODE (op) == SYMBOL_REF
2322 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2323}
2324
9878760c 2325/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2326 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2327
2328int
a2369ed3 2329call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2330{
2331 if (mode != VOIDmode && GET_MODE (op) != mode)
2332 return 0;
2333
2334 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2335 || (GET_CODE (op) == REG
2336 && (REGNO (op) == LINK_REGISTER_REGNUM
2337 || REGNO (op) == COUNT_REGISTER_REGNUM
2338 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2339}
2340
2af3d377 2341/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2342 this file. */
2af3d377
RK
2343
2344int
a2369ed3
DJ
2345current_file_function_operand (rtx op,
2346 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2347{
473f51b6
DE
2348 return (GET_CODE (op) == SYMBOL_REF
2349 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2350 && (SYMBOL_REF_LOCAL_P (op)
2351 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2352}
2353
9878760c
RK
2354/* Return 1 if this operand is a valid input for a move insn. */
2355
2356int
a2369ed3 2357input_operand (rtx op, enum machine_mode mode)
9878760c 2358{
eb4e8003 2359 /* Memory is always valid. */
9878760c
RK
2360 if (memory_operand (op, mode))
2361 return 1;
2362
34792e82 2363 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 2364 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
2365 return 1;
2366
eb4e8003
RK
2367 /* For floating-point, easy constants are valid. */
2368 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2369 && CONSTANT_P (op)
2370 && easy_fp_constant (op, mode))
2371 return 1;
2372
4e74d8ec
MM
2373 /* Allow any integer constant. */
2374 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2375 && (GET_CODE (op) == CONST_INT
e675f625 2376 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2377 return 1;
2378
d744e06e
AH
2379 /* Allow easy vector constants. */
2380 if (GET_CODE (op) == CONST_VECTOR
2381 && easy_vector_constant (op, mode))
2382 return 1;
2383
eb4e8003
RK
2384 /* For floating-point or multi-word mode, the only remaining valid type
2385 is a register. */
9878760c
RK
2386 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2387 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2388 return register_operand (op, mode);
9878760c 2389
88fe15a1
RK
2390 /* The only cases left are integral modes one word or smaller (we
2391 do not get called for MODE_CC values). These can be in any
2392 register. */
2393 if (register_operand (op, mode))
a8b3aeda 2394 return 1;
88fe15a1 2395
84cf9dda 2396 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2397 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2398 return 1;
2399
9ebbca7d 2400 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2401 if (toc_relative_expr_p (op))
b6c9286a
MM
2402 return 1;
2403
88228c4b
MM
2404 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2405 to be valid. */
f607bc57 2406 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2407 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2408 && small_data_operand (op, Pmode))
2409 return 1;
2410
042259f2 2411 return 0;
9878760c 2412}
7509c759 2413
95727fb8
AP
2414
2415/* Darwin, AIX increases natural record alignment to doubleword if the first
2416 field is an FP double while the FP fields remain word aligned. */
2417
19d66194 2418unsigned int
95727fb8
AP
2419rs6000_special_round_type_align (tree type, int computed, int specified)
2420{
2421 tree field = TYPE_FIELDS (type);
95727fb8
AP
2422
2423 /* Skip all the static variables only if ABI is greater than
71cc389b 2424 1 or equal to 0. */
3ce5437a 2425 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2426 field = TREE_CHAIN (field);
2427
3ce5437a 2428 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2429 return MAX (computed, specified);
2430
2431 return MAX (MAX (computed, specified), 64);
2432}
2433
a4f6c312 2434/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2435
2436int
a2369ed3
DJ
2437small_data_operand (rtx op ATTRIBUTE_UNUSED,
2438 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2439{
38c1f2d7 2440#if TARGET_ELF
5f59ecb7 2441 rtx sym_ref;
7509c759 2442
d9407988 2443 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2444 return 0;
a54d04b7 2445
f607bc57 2446 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2447 return 0;
2448
88228c4b
MM
2449 if (GET_CODE (op) == SYMBOL_REF)
2450 sym_ref = op;
2451
2452 else if (GET_CODE (op) != CONST
2453 || GET_CODE (XEXP (op, 0)) != PLUS
2454 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2455 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2456 return 0;
2457
88228c4b 2458 else
dbf55e53
MM
2459 {
2460 rtx sum = XEXP (op, 0);
2461 HOST_WIDE_INT summand;
2462
2463 /* We have to be careful here, because it is the referenced address
2464 that must be 32k from _SDA_BASE_, not just the symbol. */
2465 summand = INTVAL (XEXP (sum, 1));
307b599c 2466 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2467 return 0;
2468
2469 sym_ref = XEXP (sum, 0);
2470 }
88228c4b 2471
20bfcd69 2472 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2473#else
2474 return 0;
2475#endif
7509c759 2476}
46c07df8 2477
d2288d5d
HP
2478/* Return true, if operand is a memory operand and has a
2479 displacement divisible by 4. */
2480
2481int
2482word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2483{
2484 rtx addr;
2485 int off = 0;
2486
2487 if (!memory_operand (op, mode))
2488 return 0;
2489
2490 addr = XEXP (op, 0);
2491 if (GET_CODE (addr) == PLUS
2492 && GET_CODE (XEXP (addr, 0)) == REG
2493 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2494 off = INTVAL (XEXP (addr, 1));
2495
2496 return (off % 4) == 0;
2497}
2498
3a1f863f 2499/* Return true if either operand is a general purpose register. */
46c07df8 2500
3a1f863f
DE
2501bool
2502gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 2503{
3a1f863f
DE
2504 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2505 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
2506}
2507
9ebbca7d 2508\f
4d588c14
RH
2509/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2510
9ebbca7d 2511static int
a2369ed3 2512constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d
GK
2513{
2514 switch (GET_CODE(op))
2515 {
2516 case SYMBOL_REF:
c4501e62
JJ
2517 if (RS6000_SYMBOL_REF_TLS_P (op))
2518 return 0;
2519 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2520 {
2521 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2522 {
2523 *have_sym = 1;
2524 return 1;
2525 }
2526 else
2527 return 0;
2528 }
2529 else if (! strcmp (XSTR (op, 0), toc_label_name))
2530 {
2531 *have_toc = 1;
2532 return 1;
2533 }
2534 else
2535 return 0;
9ebbca7d
GK
2536 case PLUS:
2537 case MINUS:
c1f11548
DE
2538 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2539 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2540 case CONST:
a4f6c312 2541 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2542 case CONST_INT:
a4f6c312 2543 return 1;
9ebbca7d 2544 default:
a4f6c312 2545 return 0;
9ebbca7d
GK
2546 }
2547}
2548
4d588c14 2549static bool
a2369ed3 2550constant_pool_expr_p (rtx op)
9ebbca7d
GK
2551{
2552 int have_sym = 0;
2553 int have_toc = 0;
2554 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2555}
2556
4d588c14 2557static bool
a2369ed3 2558toc_relative_expr_p (rtx op)
9ebbca7d 2559{
4d588c14
RH
2560 int have_sym = 0;
2561 int have_toc = 0;
2562 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2563}
2564
2565/* SPE offset addressing is limited to 5-bits worth of double words. */
2566#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2567
2568bool
a2369ed3 2569legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
2570{
2571 return (TARGET_TOC
2572 && GET_CODE (x) == PLUS
2573 && GET_CODE (XEXP (x, 0)) == REG
2574 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2575 && constant_pool_expr_p (XEXP (x, 1)));
2576}
2577
2578static bool
a2369ed3 2579legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
2580{
2581 return (DEFAULT_ABI == ABI_V4
2582 && !flag_pic && !TARGET_TOC
2583 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2584 && small_data_operand (x, mode));
2585}
2586
2587static bool
a2369ed3 2588legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2589{
2590 unsigned HOST_WIDE_INT offset, extra;
2591
2592 if (GET_CODE (x) != PLUS)
2593 return false;
2594 if (GET_CODE (XEXP (x, 0)) != REG)
2595 return false;
2596 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2597 return false;
2598 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2599 return false;
2600
2601 offset = INTVAL (XEXP (x, 1));
2602 extra = 0;
2603 switch (mode)
2604 {
2605 case V16QImode:
2606 case V8HImode:
2607 case V4SFmode:
2608 case V4SImode:
2609 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2610 which leaves the only valid constant offset of zero, which by
2611 canonicalization rules is also invalid. */
2612 return false;
2613
2614 case V4HImode:
2615 case V2SImode:
2616 case V1DImode:
2617 case V2SFmode:
2618 /* SPE vector modes. */
2619 return SPE_CONST_OFFSET_OK (offset);
2620
2621 case DFmode:
2622 case DImode:
3364872d 2623 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
2624 extra = 4;
2625 else if (offset & 3)
2626 return false;
2627 break;
2628
2629 case TFmode:
2630 case TImode:
3364872d 2631 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
2632 extra = 12;
2633 else if (offset & 3)
2634 return false;
2635 else
2636 extra = 8;
2637 break;
2638
2639 default:
2640 break;
2641 }
2642
b1917422
AM
2643 offset += 0x8000;
2644 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
2645}
2646
2647static bool
a2369ed3 2648legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
2649{
2650 rtx op0, op1;
2651
2652 if (GET_CODE (x) != PLUS)
2653 return false;
2654 op0 = XEXP (x, 0);
2655 op1 = XEXP (x, 1);
2656
2657 if (!REG_P (op0) || !REG_P (op1))
2658 return false;
2659
2660 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2661 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2662 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2663 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2664}
2665
4d588c14 2666static inline bool
a2369ed3 2667legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
2668{
2669 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2670}
2671
4c81e946
FJ
2672static bool
2673macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
2674{
2675 if (!TARGET_MACHO || !flag_pic
2676 || mode != SImode || GET_CODE(x) != MEM)
2677 return false;
2678 x = XEXP (x, 0);
2679
2680 if (GET_CODE (x) != LO_SUM)
2681 return false;
2682 if (GET_CODE (XEXP (x, 0)) != REG)
2683 return false;
2684 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
2685 return false;
2686 x = XEXP (x, 1);
2687
2688 return CONSTANT_P (x);
2689}
2690
4d588c14 2691static bool
a2369ed3 2692legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2693{
2694 if (GET_CODE (x) != LO_SUM)
2695 return false;
2696 if (GET_CODE (XEXP (x, 0)) != REG)
2697 return false;
2698 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2699 return false;
2700 x = XEXP (x, 1);
2701
8622e235 2702 if (TARGET_ELF || TARGET_MACHO)
4d588c14 2703 {
a29077da 2704 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
2705 return false;
2706 if (TARGET_TOC)
2707 return false;
2708 if (GET_MODE_NUNITS (mode) != 1)
2709 return false;
2710 if (GET_MODE_BITSIZE (mode) > 32
2711 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2712 return false;
2713
2714 return CONSTANT_P (x);
2715 }
2716
2717 return false;
2718}
2719
2720
9ebbca7d
GK
2721/* Try machine-dependent ways of modifying an illegitimate address
2722 to be legitimate. If we find one, return the new, valid address.
2723 This is used from only one place: `memory_address' in explow.c.
2724
a4f6c312
SS
2725 OLDX is the address as it was before break_out_memory_refs was
2726 called. In some cases it is useful to look at this to decide what
2727 needs to be done.
9ebbca7d 2728
a4f6c312 2729 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2730
a4f6c312
SS
2731 It is always safe for this function to do nothing. It exists to
2732 recognize opportunities to optimize the output.
9ebbca7d
GK
2733
2734 On RS/6000, first check for the sum of a register with a constant
2735 integer that is out of range. If so, generate code to add the
2736 constant with the low-order 16 bits masked to the register and force
2737 this result into another register (this can be done with `cau').
2738 Then generate an address of REG+(CONST&0xffff), allowing for the
2739 possibility of bit 16 being a one.
2740
2741 Then check for the sum of a register and something not constant, try to
2742 load the other things into a register and return the sum. */
4d588c14 2743
9ebbca7d 2744rtx
a2369ed3
DJ
2745rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2746 enum machine_mode mode)
0ac081f6 2747{
c4501e62
JJ
2748 if (GET_CODE (x) == SYMBOL_REF)
2749 {
2750 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2751 if (model != 0)
2752 return rs6000_legitimize_tls_address (x, model);
2753 }
2754
9ebbca7d
GK
2755 if (GET_CODE (x) == PLUS
2756 && GET_CODE (XEXP (x, 0)) == REG
2757 && GET_CODE (XEXP (x, 1)) == CONST_INT
2758 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2759 {
2760 HOST_WIDE_INT high_int, low_int;
2761 rtx sum;
a65c591c
DE
2762 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2763 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2764 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2765 GEN_INT (high_int)), 0);
2766 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2767 }
2768 else if (GET_CODE (x) == PLUS
2769 && GET_CODE (XEXP (x, 0)) == REG
2770 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2771 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2772 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2773 || TARGET_POWERPC64
fcce224d 2774 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2775 && (TARGET_POWERPC64 || mode != DImode)
2776 && mode != TImode)
2777 {
2778 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2779 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2780 }
0ac081f6
AH
2781 else if (ALTIVEC_VECTOR_MODE (mode))
2782 {
2783 rtx reg;
2784
2785 /* Make sure both operands are registers. */
2786 if (GET_CODE (x) == PLUS)
9f85ed45 2787 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2788 force_reg (Pmode, XEXP (x, 1)));
2789
2790 reg = force_reg (Pmode, x);
2791 return reg;
2792 }
a3170dc6
AH
2793 else if (SPE_VECTOR_MODE (mode))
2794 {
2795 /* We accept [reg + reg] and [reg + OFFSET]. */
2796
2797 if (GET_CODE (x) == PLUS)
2798 {
2799 rtx op1 = XEXP (x, 0);
2800 rtx op2 = XEXP (x, 1);
2801
2802 op1 = force_reg (Pmode, op1);
2803
2804 if (GET_CODE (op2) != REG
2805 && (GET_CODE (op2) != CONST_INT
2806 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2807 op2 = force_reg (Pmode, op2);
2808
2809 return gen_rtx_PLUS (Pmode, op1, op2);
2810 }
2811
2812 return force_reg (Pmode, x);
2813 }
f1384257
AM
2814 else if (TARGET_ELF
2815 && TARGET_32BIT
2816 && TARGET_NO_TOC
2817 && ! flag_pic
9ebbca7d
GK
2818 && GET_CODE (x) != CONST_INT
2819 && GET_CODE (x) != CONST_DOUBLE
2820 && CONSTANT_P (x)
6ac7bf2c
GK
2821 && GET_MODE_NUNITS (mode) == 1
2822 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2823 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2824 {
2825 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2826 emit_insn (gen_elf_high (reg, x));
2827 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 2828 }
ee890fe2
SS
2829 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2830 && ! flag_pic
ab82a49f
AP
2831#if TARGET_MACHO
2832 && ! MACHO_DYNAMIC_NO_PIC_P
2833#endif
ee890fe2
SS
2834 && GET_CODE (x) != CONST_INT
2835 && GET_CODE (x) != CONST_DOUBLE
2836 && CONSTANT_P (x)
a3170dc6 2837 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2838 && mode != DImode
2839 && mode != TImode)
2840 {
2841 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2842 emit_insn (gen_macho_high (reg, x));
2843 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 2844 }
9ebbca7d 2845 else if (TARGET_TOC
4d588c14 2846 && constant_pool_expr_p (x)
a9098fd0 2847 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2848 {
2849 return create_TOC_reference (x);
2850 }
2851 else
2852 return NULL_RTX;
2853}
258bfae2 2854
c973d557
JJ
2855/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
2856 We need to emit DTP-relative relocations. */
2857
2858void
2859rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
2860{
2861 switch (size)
2862 {
2863 case 4:
2864 fputs ("\t.long\t", file);
2865 break;
2866 case 8:
2867 fputs (DOUBLE_INT_ASM_OP, file);
2868 break;
2869 default:
2870 abort ();
2871 }
2872 output_addr_const (file, x);
2873 fputs ("@dtprel+0x8000", file);
2874}
2875
c4501e62
JJ
2876/* Construct the SYMBOL_REF for the tls_get_addr function. */
2877
2878static GTY(()) rtx rs6000_tls_symbol;
2879static rtx
863d938c 2880rs6000_tls_get_addr (void)
c4501e62
JJ
2881{
2882 if (!rs6000_tls_symbol)
2883 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2884
2885 return rs6000_tls_symbol;
2886}
2887
2888/* Construct the SYMBOL_REF for TLS GOT references. */
2889
2890static GTY(()) rtx rs6000_got_symbol;
2891static rtx
863d938c 2892rs6000_got_sym (void)
c4501e62
JJ
2893{
2894 if (!rs6000_got_symbol)
2895 {
2896 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2897 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2898 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2899 }
2900
2901 return rs6000_got_symbol;
2902}
2903
2904/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2905 this (thread-local) address. */
2906
2907static rtx
a2369ed3 2908rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
2909{
2910 rtx dest, insn;
2911
2912 dest = gen_reg_rtx (Pmode);
2913 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2914 {
2915 rtx tlsreg;
2916
2917 if (TARGET_64BIT)
2918 {
2919 tlsreg = gen_rtx_REG (Pmode, 13);
2920 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2921 }
2922 else
2923 {
2924 tlsreg = gen_rtx_REG (Pmode, 2);
2925 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2926 }
2927 emit_insn (insn);
2928 }
2929 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2930 {
2931 rtx tlsreg, tmp;
2932
2933 tmp = gen_reg_rtx (Pmode);
2934 if (TARGET_64BIT)
2935 {
2936 tlsreg = gen_rtx_REG (Pmode, 13);
2937 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2938 }
2939 else
2940 {
2941 tlsreg = gen_rtx_REG (Pmode, 2);
2942 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2943 }
2944 emit_insn (insn);
2945 if (TARGET_64BIT)
2946 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
2947 else
2948 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
2949 emit_insn (insn);
2950 }
2951 else
2952 {
2953 rtx r3, got, tga, tmp1, tmp2, eqv;
2954
2955 if (TARGET_64BIT)
2956 got = gen_rtx_REG (Pmode, TOC_REGISTER);
2957 else
2958 {
2959 if (flag_pic == 1)
2960 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
2961 else
2962 {
2963 rtx gsym = rs6000_got_sym ();
2964 got = gen_reg_rtx (Pmode);
2965 if (flag_pic == 0)
2966 rs6000_emit_move (got, gsym, Pmode);
2967 else
2968 {
2969 char buf[30];
2970 static int tls_got_labelno = 0;
2971 rtx tempLR, lab, tmp3, mem;
2972 rtx first, last;
2973
2974 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
2975 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
2976 tempLR = gen_reg_rtx (Pmode);
2977 tmp1 = gen_reg_rtx (Pmode);
2978 tmp2 = gen_reg_rtx (Pmode);
2979 tmp3 = gen_reg_rtx (Pmode);
2980 mem = gen_rtx_MEM (Pmode, tmp1);
2981 RTX_UNCHANGING_P (mem) = 1;
2982
2983 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
2984 gsym));
2985 emit_move_insn (tmp1, tempLR);
2986 emit_move_insn (tmp2, mem);
2987 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
2988 last = emit_move_insn (got, tmp3);
2989 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
2990 REG_NOTES (last));
2991 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
2992 REG_NOTES (first));
2993 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
2994 REG_NOTES (last));
2995 }
2996 }
2997 }
2998
2999 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3000 {
3001 r3 = gen_rtx_REG (Pmode, 3);
3002 if (TARGET_64BIT)
3003 insn = gen_tls_gd_64 (r3, got, addr);
3004 else
3005 insn = gen_tls_gd_32 (r3, got, addr);
3006 start_sequence ();
3007 emit_insn (insn);
3008 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3009 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3010 insn = emit_call_insn (insn);
3011 CONST_OR_PURE_CALL_P (insn) = 1;
3012 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3013 insn = get_insns ();
3014 end_sequence ();
3015 emit_libcall_block (insn, dest, r3, addr);
3016 }
3017 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3018 {
3019 r3 = gen_rtx_REG (Pmode, 3);
3020 if (TARGET_64BIT)
3021 insn = gen_tls_ld_64 (r3, got);
3022 else
3023 insn = gen_tls_ld_32 (r3, got);
3024 start_sequence ();
3025 emit_insn (insn);
3026 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3027 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3028 insn = emit_call_insn (insn);
3029 CONST_OR_PURE_CALL_P (insn) = 1;
3030 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3031 insn = get_insns ();
3032 end_sequence ();
3033 tmp1 = gen_reg_rtx (Pmode);
3034 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3035 UNSPEC_TLSLD);
3036 emit_libcall_block (insn, tmp1, r3, eqv);
3037 if (rs6000_tls_size == 16)
3038 {
3039 if (TARGET_64BIT)
3040 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3041 else
3042 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3043 }
3044 else if (rs6000_tls_size == 32)
3045 {
3046 tmp2 = gen_reg_rtx (Pmode);
3047 if (TARGET_64BIT)
3048 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3049 else
3050 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3051 emit_insn (insn);
3052 if (TARGET_64BIT)
3053 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3054 else
3055 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3056 }
3057 else
3058 {
3059 tmp2 = gen_reg_rtx (Pmode);
3060 if (TARGET_64BIT)
3061 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3062 else
3063 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3064 emit_insn (insn);
3065 insn = gen_rtx_SET (Pmode, dest,
3066 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3067 }
3068 emit_insn (insn);
3069 }
3070 else
3071 {
3072 /* IE, or 64 bit offset LE. */
3073 tmp2 = gen_reg_rtx (Pmode);
3074 if (TARGET_64BIT)
3075 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3076 else
3077 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3078 emit_insn (insn);
3079 if (TARGET_64BIT)
3080 insn = gen_tls_tls_64 (dest, tmp2, addr);
3081 else
3082 insn = gen_tls_tls_32 (dest, tmp2, addr);
3083 emit_insn (insn);
3084 }
3085 }
3086
3087 return dest;
3088}
3089
3090/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3091 instruction definitions. */
3092
3093int
a2369ed3 3094rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3095{
3096 return RS6000_SYMBOL_REF_TLS_P (x);
3097}
3098
3099/* Return 1 if X contains a thread-local symbol. */
3100
3101bool
a2369ed3 3102rs6000_tls_referenced_p (rtx x)
c4501e62 3103{
cd413cab
AP
3104 if (! TARGET_HAVE_TLS)
3105 return false;
3106
c4501e62
JJ
3107 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3108}
3109
3110/* Return 1 if *X is a thread-local symbol. This is the same as
3111 rs6000_tls_symbol_ref except for the type of the unused argument. */
3112
3113static inline int
a2369ed3 3114rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3115{
3116 return RS6000_SYMBOL_REF_TLS_P (*x);
3117}
3118
24ea750e
DJ
3119/* The convention appears to be to define this wherever it is used.
3120 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3121 is now used here. */
3122#ifndef REG_MODE_OK_FOR_BASE_P
3123#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3124#endif
3125
3126/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3127 replace the input X, or the original X if no replacement is called for.
3128 The output parameter *WIN is 1 if the calling macro should goto WIN,
3129 0 if it should not.
3130
3131 For RS/6000, we wish to handle large displacements off a base
3132 register by splitting the addend across an addiu/addis and the mem insn.
3133 This cuts number of extra insns needed from 3 to 1.
3134
3135 On Darwin, we use this to generate code for floating point constants.
3136 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3137 The Darwin code is inside #if TARGET_MACHO because only then is
3138 machopic_function_base_name() defined. */
3139rtx
a2369ed3
DJ
3140rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
3141 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e
DJ
3142{
3143 /* We must recognize output that we have already generated ourselves. */
3144 if (GET_CODE (x) == PLUS
3145 && GET_CODE (XEXP (x, 0)) == PLUS
3146 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3147 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3148 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3149 {
3150 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3151 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3152 opnum, (enum reload_type)type);
3153 *win = 1;
3154 return x;
3155 }
3deb2758 3156
24ea750e
DJ
3157#if TARGET_MACHO
3158 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3159 && GET_CODE (x) == LO_SUM
3160 && GET_CODE (XEXP (x, 0)) == PLUS
3161 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3162 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3163 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3164 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3165 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3166 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3167 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3168 {
3169 /* Result of previous invocation of this function on Darwin
6f317ef3 3170 floating point constant. */
24ea750e
DJ
3171 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3172 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3173 opnum, (enum reload_type)type);
3174 *win = 1;
3175 return x;
3176 }
3177#endif
3178 if (GET_CODE (x) == PLUS
3179 && GET_CODE (XEXP (x, 0)) == REG
3180 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3181 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3182 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3183 && !SPE_VECTOR_MODE (mode)
78c875e8 3184 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3185 {
3186 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3187 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3188 HOST_WIDE_INT high
3189 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3190
3191 /* Check for 32-bit overflow. */
3192 if (high + low != val)
3193 {
3194 *win = 0;
3195 return x;
3196 }
3197
3198 /* Reload the high part into a base reg; leave the low part
3199 in the mem directly. */
3200
3201 x = gen_rtx_PLUS (GET_MODE (x),
3202 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3203 GEN_INT (high)),
3204 GEN_INT (low));
3205
3206 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3207 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3208 opnum, (enum reload_type)type);
3209 *win = 1;
3210 return x;
3211 }
3212#if TARGET_MACHO
3213 if (GET_CODE (x) == SYMBOL_REF
3214 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3215 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3216 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3217 /* Don't do this for TFmode, since the result isn't offsettable. */
3218 && mode != TFmode)
24ea750e 3219 {
a29077da
GK
3220 if (flag_pic)
3221 {
3222 rtx offset = gen_rtx_CONST (Pmode,
3223 gen_rtx_MINUS (Pmode, x,
3224 gen_rtx_SYMBOL_REF (Pmode,
3225 machopic_function_base_name ())));
3226 x = gen_rtx_LO_SUM (GET_MODE (x),
3227 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3228 gen_rtx_HIGH (Pmode, offset)), offset);
3229 }
3230 else
3231 x = gen_rtx_LO_SUM (GET_MODE (x),
3232 gen_rtx_HIGH (Pmode, x), x);
3233
24ea750e 3234 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3235 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3236 opnum, (enum reload_type)type);
24ea750e
DJ
3237 *win = 1;
3238 return x;
3239 }
3240#endif
3241 if (TARGET_TOC
4d588c14 3242 && constant_pool_expr_p (x)
c1f11548 3243 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3244 {
3245 (x) = create_TOC_reference (x);
3246 *win = 1;
3247 return x;
3248 }
3249 *win = 0;
3250 return x;
3251}
3252
258bfae2
FS
3253/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3254 that is a valid memory address for an instruction.
3255 The MODE argument is the machine mode for the MEM expression
3256 that wants to use this address.
3257
3258 On the RS/6000, there are four valid address: a SYMBOL_REF that
3259 refers to a constant pool entry of an address (or the sum of it
3260 plus a constant), a short (16-bit signed) constant plus a register,
3261 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3262 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3263 we must ensure that both words are addressable or PowerPC64 with offset
3264 word aligned.
3265
3266 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3267 32-bit DImode, TImode), indexed addressing cannot be used because
3268 adjacent memory cells are accessed by adding word-sized offsets
3269 during assembly output. */
3270int
a2369ed3 3271rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3272{
c4501e62
JJ
3273 if (RS6000_SYMBOL_REF_TLS_P (x))
3274 return 0;
4d588c14 3275 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3276 return 1;
3277 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3278 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3279 && !SPE_VECTOR_MODE (mode)
258bfae2 3280 && TARGET_UPDATE
4d588c14 3281 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3282 return 1;
4d588c14 3283 if (legitimate_small_data_p (mode, x))
258bfae2 3284 return 1;
4d588c14 3285 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3286 return 1;
3287 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3288 if (! reg_ok_strict
3289 && GET_CODE (x) == PLUS
3290 && GET_CODE (XEXP (x, 0)) == REG
708d2456
HP
3291 && (XEXP (x, 0) == virtual_stack_vars_rtx
3292 || XEXP (x, 0) == arg_pointer_rtx)
258bfae2
FS
3293 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3294 return 1;
4d588c14 3295 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3296 return 1;
3297 if (mode != TImode
a3170dc6
AH
3298 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3299 || TARGET_POWERPC64
fcce224d 3300 || (mode != DFmode && mode != TFmode))
258bfae2 3301 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3302 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3303 return 1;
4d588c14 3304 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3305 return 1;
3306 return 0;
3307}
4d588c14
RH
3308
3309/* Go to LABEL if ADDR (a legitimate address expression)
3310 has an effect that depends on the machine mode it is used for.
3311
3312 On the RS/6000 this is true of all integral offsets (since AltiVec
3313 modes don't allow them) or is a pre-increment or decrement.
3314
3315 ??? Except that due to conceptual problems in offsettable_address_p
3316 we can't really report the problems of integral offsets. So leave
3317 this assuming that the adjustable offset must be valid for the
3318 sub-words of a TFmode operand, which is what we had before. */
3319
3320bool
a2369ed3 3321rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3322{
3323 switch (GET_CODE (addr))
3324 {
3325 case PLUS:
3326 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3327 {
3328 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3329 return val + 12 + 0x8000 >= 0x10000;
3330 }
3331 break;
3332
3333 case LO_SUM:
3334 return true;
3335
3336 case PRE_INC:
3337 case PRE_DEC:
3338 return TARGET_UPDATE;
3339
3340 default:
3341 break;
3342 }
3343
3344 return false;
3345}
fb4d4348 3346\f
a4f6c312
SS
3347/* Try to output insns to set TARGET equal to the constant C if it can
3348 be done in less than N insns. Do all computations in MODE.
3349 Returns the place where the output has been placed if it can be
3350 done and the insns have been emitted. If it would take more than N
3351 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3352
3353rtx
a2369ed3
DJ
3354rs6000_emit_set_const (rtx dest, enum machine_mode mode,
3355 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3356{
af8cb5c5 3357 rtx result, insn, set;
2bfcf297
DB
3358 HOST_WIDE_INT c0, c1;
3359
af8cb5c5 3360 if (mode == QImode || mode == HImode)
2bfcf297
DB
3361 {
3362 if (dest == NULL)
3363 dest = gen_reg_rtx (mode);
3364 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3365 return dest;
3366 }
af8cb5c5 3367 else if (mode == SImode)
2bfcf297 3368 {
af8cb5c5
DE
3369 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3370
3371 emit_insn (gen_rtx_SET (VOIDmode, result,
3372 GEN_INT (INTVAL (source)
3373 & (~ (HOST_WIDE_INT) 0xffff))));
3374 emit_insn (gen_rtx_SET (VOIDmode, dest,
3375 gen_rtx_IOR (SImode, result,
3376 GEN_INT (INTVAL (source) & 0xffff))));
3377 result = dest;
2bfcf297 3378 }
af8cb5c5 3379 else if (mode == DImode)
2bfcf297 3380 {
af8cb5c5
DE
3381 if (GET_CODE (source) == CONST_INT)
3382 {
3383 c0 = INTVAL (source);
3384 c1 = -(c0 < 0);
3385 }
3386 else if (GET_CODE (source) == CONST_DOUBLE)
3387 {
2bfcf297 3388#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3389 c0 = CONST_DOUBLE_LOW (source);
3390 c1 = -(c0 < 0);
2bfcf297 3391#else
af8cb5c5
DE
3392 c0 = CONST_DOUBLE_LOW (source);
3393 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3394#endif
af8cb5c5
DE
3395 }
3396 else
3397 abort ();
3398
3399 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3400 }
3401 else
a4f6c312 3402 abort ();
2bfcf297 3403
af8cb5c5
DE
3404 insn = get_last_insn ();
3405 set = single_set (insn);
3406 if (! CONSTANT_P (SET_SRC (set)))
3407 set_unique_reg_note (insn, REG_EQUAL, source);
3408
3409 return result;
2bfcf297
DB
3410}
3411
3412/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3413 fall back to a straight forward decomposition. We do this to avoid
3414 exponential run times encountered when looking for longer sequences
3415 with rs6000_emit_set_const. */
3416static rtx
a2369ed3 3417rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
3418{
3419 if (!TARGET_POWERPC64)
3420 {
3421 rtx operand1, operand2;
3422
3423 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3424 DImode);
3425 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3426 DImode);
3427 emit_move_insn (operand1, GEN_INT (c1));
3428 emit_move_insn (operand2, GEN_INT (c2));
3429 }
3430 else
3431 {
bc06712d 3432 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3433
bc06712d 3434 ud1 = c1 & 0xffff;
f921c9c9 3435 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3436#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3437 c2 = c1 >> 32;
2bfcf297 3438#endif
bc06712d 3439 ud3 = c2 & 0xffff;
f921c9c9 3440 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3441
bc06712d
TR
3442 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3443 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3444 {
bc06712d 3445 if (ud1 & 0x8000)
b78d48dd 3446 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
3447 else
3448 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3449 }
2bfcf297 3450
bc06712d
TR
3451 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3452 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3453 {
bc06712d
TR
3454 if (ud2 & 0x8000)
3455 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3456 - 0x80000000));
252b88f7 3457 else
bc06712d
TR
3458 emit_move_insn (dest, GEN_INT (ud2 << 16));
3459 if (ud1 != 0)
3460 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3461 }
bc06712d
TR
3462 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3463 || (ud4 == 0 && ! (ud3 & 0x8000)))
3464 {
3465 if (ud3 & 0x8000)
3466 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3467 - 0x80000000));
3468 else
3469 emit_move_insn (dest, GEN_INT (ud3 << 16));
3470
3471 if (ud2 != 0)
3472 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3473 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3474 if (ud1 != 0)
3475 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3476 }
3477 else
3478 {
3479 if (ud4 & 0x8000)
3480 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3481 - 0x80000000));
3482 else
3483 emit_move_insn (dest, GEN_INT (ud4 << 16));
3484
3485 if (ud3 != 0)
3486 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3487
bc06712d
TR
3488 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3489 if (ud2 != 0)
3490 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3491 GEN_INT (ud2 << 16)));
3492 if (ud1 != 0)
3493 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3494 }
3495 }
2bfcf297
DB
3496 return dest;
3497}
3498
fb4d4348
GK
3499/* Emit a move from SOURCE to DEST in mode MODE. */
3500void
a2369ed3 3501rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
3502{
3503 rtx operands[2];
3504 operands[0] = dest;
3505 operands[1] = source;
3506
3507 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3508 if (GET_CODE (operands[1]) == CONST_DOUBLE
3509 && ! FLOAT_MODE_P (mode)
3510 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3511 {
3512 /* FIXME. This should never happen. */
3513 /* Since it seems that it does, do the safe thing and convert
3514 to a CONST_INT. */
2496c7bd 3515 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3516 }
3517 if (GET_CODE (operands[1]) == CONST_DOUBLE
3518 && ! FLOAT_MODE_P (mode)
3519 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3520 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3521 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3522 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3523 abort ();
c9e8cb32
DD
3524
3525 /* Check if GCC is setting up a block move that will end up using FP
3526 registers as temporaries. We must make sure this is acceptable. */
3527 if (GET_CODE (operands[0]) == MEM
3528 && GET_CODE (operands[1]) == MEM
3529 && mode == DImode
41543739
GK
3530 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3531 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3532 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3533 ? 32 : MEM_ALIGN (operands[0])))
3534 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3535 ? 32
3536 : MEM_ALIGN (operands[1]))))
3537 && ! MEM_VOLATILE_P (operands [0])
3538 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3539 {
41543739
GK
3540 emit_move_insn (adjust_address (operands[0], SImode, 0),
3541 adjust_address (operands[1], SImode, 0));
3542 emit_move_insn (adjust_address (operands[0], SImode, 4),
3543 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3544 return;
3545 }
630d42a0 3546
67cef334
DE
3547 if (!no_new_pseudos)
3548 {
3549 if (GET_CODE (operands[1]) == MEM && optimize > 0
3550 && (mode == QImode || mode == HImode || mode == SImode)
3551 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3552 {
3553 rtx reg = gen_reg_rtx (word_mode);
3554
3555 emit_insn (gen_rtx_SET (word_mode, reg,
3556 gen_rtx_ZERO_EXTEND (word_mode,
3557 operands[1])));
3558 operands[1] = gen_lowpart (mode, reg);
3559 }
3560 if (GET_CODE (operands[0]) != REG)
3561 operands[1] = force_reg (mode, operands[1]);
3562 }
a9098fd0 3563
a3170dc6
AH
3564 if (mode == SFmode && ! TARGET_POWERPC
3565 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3566 && GET_CODE (operands[0]) == MEM)
fb4d4348 3567 {
ffc14f31
GK
3568 int regnum;
3569
3570 if (reload_in_progress || reload_completed)
3571 regnum = true_regnum (operands[1]);
3572 else if (GET_CODE (operands[1]) == REG)
3573 regnum = REGNO (operands[1]);
3574 else
3575 regnum = -1;
fb4d4348
GK
3576
3577 /* If operands[1] is a register, on POWER it may have
3578 double-precision data in it, so truncate it to single
3579 precision. */
3580 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3581 {
3582 rtx newreg;
3583 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3584 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3585 operands[1] = newreg;
3586 }
3587 }
3588
c4501e62
JJ
3589 /* Recognize the case where operand[1] is a reference to thread-local
3590 data and load its address to a register. */
3591 if (GET_CODE (operands[1]) == SYMBOL_REF)
3592 {
3593 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3594 if (model != 0)
3595 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3596 }
3597
8f4e6caf
RH
3598 /* Handle the case where reload calls us with an invalid address. */
3599 if (reload_in_progress && mode == Pmode
69ef87e2 3600 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3601 || ! nonimmediate_operand (operands[0], mode)))
3602 goto emit_set;
3603
3604 /* Handle the case of CONSTANT_P_RTX. */
3605 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3606 goto emit_set;
a9baceb1
GK
3607
3608 /* 128-bit constant floating-point values on Darwin should really be
3609 loaded as two parts. */
3610 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
3611 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
3612 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
3613 {
3614 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
3615 know how to get a DFmode SUBREG of a TFmode. */
3616 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
3617 simplify_gen_subreg (DImode, operands[1], mode, 0),
3618 DImode);
3619 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
3620 GET_MODE_SIZE (DImode)),
3621 simplify_gen_subreg (DImode, operands[1], mode,
3622 GET_MODE_SIZE (DImode)),
3623 DImode);
3624 return;
3625 }
3626
fb4d4348
GK
3627 /* FIXME: In the long term, this switch statement should go away
3628 and be replaced by a sequence of tests based on things like
3629 mode == Pmode. */
3630 switch (mode)
3631 {
3632 case HImode:
3633 case QImode:
3634 if (CONSTANT_P (operands[1])
3635 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3636 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3637 break;
3638
06f4e019 3639 case TFmode:
fb4d4348
GK
3640 case DFmode:
3641 case SFmode:
3642 if (CONSTANT_P (operands[1])
3643 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3644 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3645 break;
3646
0ac081f6
AH
3647 case V16QImode:
3648 case V8HImode:
3649 case V4SFmode:
3650 case V4SImode:
a3170dc6
AH
3651 case V4HImode:
3652 case V2SFmode:
3653 case V2SImode:
00a892b8 3654 case V1DImode:
69ef87e2 3655 if (CONSTANT_P (operands[1])
d744e06e 3656 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3657 operands[1] = force_const_mem (mode, operands[1]);
3658 break;
3659
fb4d4348 3660 case SImode:
a9098fd0 3661 case DImode:
fb4d4348
GK
3662 /* Use default pattern for address of ELF small data */
3663 if (TARGET_ELF
a9098fd0 3664 && mode == Pmode
f607bc57 3665 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3666 && (GET_CODE (operands[1]) == SYMBOL_REF
3667 || GET_CODE (operands[1]) == CONST)
3668 && small_data_operand (operands[1], mode))
fb4d4348
GK
3669 {
3670 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3671 return;
3672 }
3673
f607bc57 3674 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3675 && mode == Pmode && mode == SImode
3676 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3677 {
3678 emit_insn (gen_movsi_got (operands[0], operands[1]));
3679 return;
3680 }
3681
ee890fe2 3682 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3683 && TARGET_NO_TOC
3684 && ! flag_pic
a9098fd0 3685 && mode == Pmode
fb4d4348
GK
3686 && CONSTANT_P (operands[1])
3687 && GET_CODE (operands[1]) != HIGH
3688 && GET_CODE (operands[1]) != CONST_INT)
3689 {
a9098fd0 3690 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3691
3692 /* If this is a function address on -mcall-aixdesc,
3693 convert it to the address of the descriptor. */
3694 if (DEFAULT_ABI == ABI_AIX
3695 && GET_CODE (operands[1]) == SYMBOL_REF
3696 && XSTR (operands[1], 0)[0] == '.')
3697 {
3698 const char *name = XSTR (operands[1], 0);
3699 rtx new_ref;
3700 while (*name == '.')
3701 name++;
3702 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3703 CONSTANT_POOL_ADDRESS_P (new_ref)
3704 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3705 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3706 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3707 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3708 operands[1] = new_ref;
3709 }
7509c759 3710
ee890fe2
SS
3711 if (DEFAULT_ABI == ABI_DARWIN)
3712 {
ab82a49f
AP
3713#if TARGET_MACHO
3714 if (MACHO_DYNAMIC_NO_PIC_P)
3715 {
3716 /* Take care of any required data indirection. */
3717 operands[1] = rs6000_machopic_legitimize_pic_address (
3718 operands[1], mode, operands[0]);
3719 if (operands[0] != operands[1])
3720 emit_insn (gen_rtx_SET (VOIDmode,
3721 operands[0], operands[1]));
3722 return;
3723 }
3724#endif
ee890fe2
SS
3725 emit_insn (gen_macho_high (target, operands[1]));
3726 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3727 return;
3728 }
3729
fb4d4348
GK
3730 emit_insn (gen_elf_high (target, operands[1]));
3731 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3732 return;
3733 }
3734
a9098fd0
GK
3735 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3736 and we have put it in the TOC, we just need to make a TOC-relative
3737 reference to it. */
3738 if (TARGET_TOC
3739 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3740 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3741 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3742 get_pool_mode (operands[1])))
fb4d4348 3743 {
a9098fd0 3744 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3745 }
a9098fd0
GK
3746 else if (mode == Pmode
3747 && CONSTANT_P (operands[1])
38886f37
AO
3748 && ((GET_CODE (operands[1]) != CONST_INT
3749 && ! easy_fp_constant (operands[1], mode))
3750 || (GET_CODE (operands[1]) == CONST_INT
3751 && num_insns_constant (operands[1], mode) > 2)
3752 || (GET_CODE (operands[0]) == REG
3753 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3754 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3755 && ! legitimate_constant_pool_address_p (operands[1])
3756 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3757 {
3758 /* Emit a USE operation so that the constant isn't deleted if
3759 expensive optimizations are turned on because nobody
3760 references it. This should only be done for operands that
3761 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3762 This should not be done for operands that contain LABEL_REFs.
3763 For now, we just handle the obvious case. */
3764 if (GET_CODE (operands[1]) != LABEL_REF)
3765 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3766
c859cda6 3767#if TARGET_MACHO
ee890fe2 3768 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3769 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3770 {
ee890fe2
SS
3771 operands[1] =
3772 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3773 operands[0]);
3774 if (operands[0] != operands[1])
3775 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3776 return;
3777 }
c859cda6 3778#endif
ee890fe2 3779
fb4d4348
GK
3780 /* If we are to limit the number of things we put in the TOC and
3781 this is a symbol plus a constant we can add in one insn,
3782 just put the symbol in the TOC and add the constant. Don't do
3783 this if reload is in progress. */
3784 if (GET_CODE (operands[1]) == CONST
3785 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3786 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3787 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3788 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3789 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3790 && ! side_effects_p (operands[0]))
3791 {
a4f6c312
SS
3792 rtx sym =
3793 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3794 rtx other = XEXP (XEXP (operands[1], 0), 1);
3795
a9098fd0
GK
3796 sym = force_reg (mode, sym);
3797 if (mode == SImode)
3798 emit_insn (gen_addsi3 (operands[0], sym, other));
3799 else
3800 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3801 return;
3802 }
3803
a9098fd0 3804 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3805
3806 if (TARGET_TOC
4d588c14 3807 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3808 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3809 get_pool_constant (XEXP (operands[1], 0)),
3810 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3811 {
ba4828e0
RK
3812 operands[1]
3813 = gen_rtx_MEM (mode,
3814 create_TOC_reference (XEXP (operands[1], 0)));
3815 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3816 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3817 }
fb4d4348
GK
3818 }
3819 break;
a9098fd0 3820
fb4d4348
GK
3821 case TImode:
3822 if (GET_CODE (operands[0]) == MEM
3823 && GET_CODE (XEXP (operands[0], 0)) != REG
3824 && ! reload_in_progress)
792760b9
RK
3825 operands[0]
3826 = replace_equiv_address (operands[0],
3827 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3828
3829 if (GET_CODE (operands[1]) == MEM
3830 && GET_CODE (XEXP (operands[1], 0)) != REG
3831 && ! reload_in_progress)
792760b9
RK
3832 operands[1]
3833 = replace_equiv_address (operands[1],
3834 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3835 if (TARGET_POWER)
3836 {
3837 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3838 gen_rtvec (2,
3839 gen_rtx_SET (VOIDmode,
3840 operands[0], operands[1]),
3841 gen_rtx_CLOBBER (VOIDmode,
3842 gen_rtx_SCRATCH (SImode)))));
3843 return;
3844 }
fb4d4348
GK
3845 break;
3846
3847 default:
3848 abort ();
3849 }
3850
a9098fd0
GK
3851 /* Above, we may have called force_const_mem which may have returned
3852 an invalid address. If we can, fix this up; otherwise, reload will
3853 have to deal with it. */
8f4e6caf
RH
3854 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
3855 operands[1] = validize_mem (operands[1]);
a9098fd0 3856
8f4e6caf 3857 emit_set:
fb4d4348
GK
3858 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3859}
4697a36c 3860\f
2858f73a
GK
3861/* Nonzero if we can use a floating-point register to pass this arg. */
3862#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
3863 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
3864 && (CUM)->fregno <= FP_ARG_MAX_REG \
3865 && TARGET_HARD_FLOAT && TARGET_FPRS)
3866
3867/* Nonzero if we can use an AltiVec register to pass this arg. */
3868#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
3869 (ALTIVEC_VECTOR_MODE (MODE) \
3870 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
3871 && TARGET_ALTIVEC_ABI \
83953138 3872 && (NAMED))
2858f73a 3873
c6e8c921
GK
3874/* Return a nonzero value to say to return the function value in
3875 memory, just as large structures are always returned. TYPE will be
3876 the data type of the value, and FNTYPE will be the type of the
3877 function doing the returning, or @code{NULL} for libcalls.
3878
3879 The AIX ABI for the RS/6000 specifies that all structures are
3880 returned in memory. The Darwin ABI does the same. The SVR4 ABI
3881 specifies that structures <= 8 bytes are returned in r3/r4, but a
3882 draft put them in memory, and GCC used to implement the draft
3883 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
3884 controls this instead of DEFAULT_ABI; V.4 targets needing backward
3885 compatibility can change DRAFT_V4_STRUCT_RET to override the
3886 default, and -m switches get the final word. See
3887 rs6000_override_options for more details.
3888
3889 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
3890 long double support is enabled. These values are returned in memory.
3891
3892 int_size_in_bytes returns -1 for variable size objects, which go in
3893 memory always. The cast to unsigned makes -1 > 8. */
3894
3895static bool
3896rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
3897{
3898 if (AGGREGATE_TYPE_P (type)
3899 && (TARGET_AIX_STRUCT_RET
3900 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
3901 return true;
3902 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
3903 return true;
3904 return false;
3905}
3906
4697a36c
MM
3907/* Initialize a variable CUM of type CUMULATIVE_ARGS
3908 for a call to a function whose data type is FNTYPE.
3909 For a library call, FNTYPE is 0.
3910
3911 For incoming args we set the number of arguments in the prototype large
1c20ae99 3912 so we never return a PARALLEL. */
4697a36c
MM
3913
3914void
a2369ed3 3915init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
3916 rtx libname ATTRIBUTE_UNUSED, int incoming,
3917 int libcall, int n_named_args)
4697a36c
MM
3918{
3919 static CUMULATIVE_ARGS zero_cumulative;
3920
3921 *cum = zero_cumulative;
3922 cum->words = 0;
3923 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 3924 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 3925 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
3926 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
3927 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 3928 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
3929 cum->stdarg = fntype
3930 && (TYPE_ARG_TYPES (fntype) != 0
3931 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3932 != void_type_node));
4697a36c 3933
0f6937fe
AM
3934 cum->nargs_prototype = 0;
3935 if (incoming || cum->prototype)
3936 cum->nargs_prototype = n_named_args;
4697a36c 3937
a5c76ee6
ZW
3938 /* Check for a longcall attribute. */
3939 if (fntype
3940 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
3941 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
3942 cum->call_cookie = CALL_LONG;
3943
4697a36c
MM
3944 if (TARGET_DEBUG_ARG)
3945 {
3946 fprintf (stderr, "\ninit_cumulative_args:");
3947 if (fntype)
3948 {
3949 tree ret_type = TREE_TYPE (fntype);
3950 fprintf (stderr, " ret code = %s,",
3951 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3952 }
3953
6a4cee5f
MM
3954 if (cum->call_cookie & CALL_LONG)
3955 fprintf (stderr, " longcall,");
3956
4697a36c
MM
3957 fprintf (stderr, " proto = %d, nargs = %d\n",
3958 cum->prototype, cum->nargs_prototype);
3959 }
6d0ef01e
HP
3960
3961 if (fntype
3962 && !TARGET_ALTIVEC
3963 && TARGET_ALTIVEC_ABI
3964 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
3965 {
3966 error ("Cannot return value in vector register because"
3967 " altivec instructions are disabled, use -maltivec"
3968 " to enable them.");
3969 }
4697a36c
MM
3970}
3971\f
c229cba9
DE
3972/* If defined, a C expression which determines whether, and in which
3973 direction, to pad out an argument with extra space. The value
3974 should be of type `enum direction': either `upward' to pad above
3975 the argument, `downward' to pad below, or `none' to inhibit
3976 padding.
3977
3978 For the AIX ABI structs are always stored left shifted in their
3979 argument slot. */
3980
9ebbca7d 3981enum direction
a2369ed3 3982function_arg_padding (enum machine_mode mode, tree type)
c229cba9 3983{
6e985040
AM
3984#ifndef AGGREGATE_PADDING_FIXED
3985#define AGGREGATE_PADDING_FIXED 0
3986#endif
3987#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
3988#define AGGREGATES_PAD_UPWARD_ALWAYS 0
3989#endif
3990
3991 if (!AGGREGATE_PADDING_FIXED)
3992 {
3993 /* GCC used to pass structures of the same size as integer types as
3994 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
3995 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
3996 passed padded downward, except that -mstrict-align further
3997 muddied the water in that multi-component structures of 2 and 4
3998 bytes in size were passed padded upward.
3999
4000 The following arranges for best compatibility with previous
4001 versions of gcc, but removes the -mstrict-align dependency. */
4002 if (BYTES_BIG_ENDIAN)
4003 {
4004 HOST_WIDE_INT size = 0;
4005
4006 if (mode == BLKmode)
4007 {
4008 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4009 size = int_size_in_bytes (type);
4010 }
4011 else
4012 size = GET_MODE_SIZE (mode);
4013
4014 if (size == 1 || size == 2 || size == 4)
4015 return downward;
4016 }
4017 return upward;
4018 }
4019
4020 if (AGGREGATES_PAD_UPWARD_ALWAYS)
4021 {
4022 if (type != 0 && AGGREGATE_TYPE_P (type))
4023 return upward;
4024 }
c229cba9 4025
d3704c46
KH
4026 /* Fall back to the default. */
4027 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
4028}
4029
b6c9286a
MM
4030/* If defined, a C expression that gives the alignment boundary, in bits,
4031 of an argument with the specified mode and type. If it is not defined,
4032 PARM_BOUNDARY is used for all arguments.
4033
2310f99a 4034 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
4035
4036int
a2369ed3 4037function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 4038{
f607bc57 4039 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 4040 return 64;
a3170dc6
AH
4041 else if (SPE_VECTOR_MODE (mode))
4042 return 64;
0ac081f6
AH
4043 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4044 return 128;
9ebbca7d 4045 else
b6c9286a 4046 return PARM_BOUNDARY;
b6c9286a 4047}
c53bdcf5
AM
4048
4049/* Compute the size (in words) of a function argument. */
4050
4051static unsigned long
4052rs6000_arg_size (enum machine_mode mode, tree type)
4053{
4054 unsigned long size;
4055
4056 if (mode != BLKmode)
4057 size = GET_MODE_SIZE (mode);
4058 else
4059 size = int_size_in_bytes (type);
4060
4061 if (TARGET_32BIT)
4062 return (size + 3) >> 2;
4063 else
4064 return (size + 7) >> 3;
4065}
b6c9286a 4066\f
4697a36c
MM
4067/* Update the data in CUM to advance over an argument
4068 of mode MODE and data type TYPE.
4069 (TYPE is null for libcalls where that information may not be available.) */
4070
4071void
a2369ed3
DJ
4072function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4073 tree type, int named)
4697a36c
MM
4074{
4075 cum->nargs_prototype--;
4076
0ac081f6
AH
4077 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4078 {
2858f73a 4079 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
6d0ef01e
HP
4080 {
4081 cum->vregno++;
4082 if (!TARGET_ALTIVEC)
4083 error ("Cannot pass argument in vector register because"
4084 " altivec instructions are disabled, use -maltivec"
4085 " to enable them.");
4086 }
c72d6c26
HP
4087 /* PowerPC64 Linux and AIX allocates GPRs for a vector argument
4088 even if it is going to be passed in a vector register.
4089 Darwin does the same for variable-argument functions. */
4090 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4091 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4092 {
a594a19c
GK
4093 int align;
4094
2858f73a
GK
4095 /* Vector parameters must be 16-byte aligned. This places
4096 them at 2 mod 4 in terms of words in 32-bit mode, since
4097 the parameter save area starts at offset 24 from the
4098 stack. In 64-bit mode, they just have to start on an
4099 even word, since the parameter save area is 16-byte
4100 aligned. Space for GPRs is reserved even if the argument
4101 will be passed in memory. */
4102 if (TARGET_32BIT)
4103 align = ((6 - (cum->words & 3)) & 3);
4104 else
4105 align = cum->words & 1;
c53bdcf5 4106 cum->words += align + rs6000_arg_size (mode, type);
2858f73a 4107
a594a19c
GK
4108 if (TARGET_DEBUG_ARG)
4109 {
4110 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
4111 cum->words, align);
4112 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
2858f73a
GK
4113 cum->nargs_prototype, cum->prototype,
4114 GET_MODE_NAME (mode));
a594a19c
GK
4115 }
4116 }
0ac081f6 4117 }
a4b0320c 4118 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4119 && !cum->stdarg
4120 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4121 cum->sysv_gregno++;
f607bc57 4122 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4123 {
a3170dc6 4124 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4125 && (mode == SFmode || mode == DFmode))
4697a36c 4126 {
4cc833b7
RH
4127 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4128 cum->fregno++;
4129 else
4130 {
4131 if (mode == DFmode)
4132 cum->words += cum->words & 1;
c53bdcf5 4133 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4134 }
4697a36c 4135 }
4cc833b7
RH
4136 else
4137 {
4138 int n_words;
4139 int gregno = cum->sysv_gregno;
4140
4141 /* Aggregates and IEEE quad get passed by reference. */
4142 if ((type && AGGREGATE_TYPE_P (type))
4143 || mode == TFmode)
4144 n_words = 1;
4145 else
c53bdcf5 4146 n_words = rs6000_arg_size (mode, type);
4cc833b7 4147
a4b0320c 4148 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4149 if (n_words == 2 && (gregno & 1) == 0)
4150 gregno += 1;
4151
a4b0320c
AH
4152 /* Long long and SPE vectors are not split between registers
4153 and stack. */
4cc833b7
RH
4154 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4155 {
4156 /* Long long is aligned on the stack. */
4157 if (n_words == 2)
4158 cum->words += cum->words & 1;
4159 cum->words += n_words;
4160 }
4697a36c 4161
4cc833b7
RH
4162 /* Note: continuing to accumulate gregno past when we've started
4163 spilling to the stack indicates the fact that we've started
4164 spilling to the stack to expand_builtin_saveregs. */
4165 cum->sysv_gregno = gregno + n_words;
4166 }
4697a36c 4167
4cc833b7
RH
4168 if (TARGET_DEBUG_ARG)
4169 {
4170 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4171 cum->words, cum->fregno);
4172 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4173 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4174 fprintf (stderr, "mode = %4s, named = %d\n",
4175 GET_MODE_NAME (mode), named);
4176 }
4697a36c
MM
4177 }
4178 else
4cc833b7
RH
4179 {
4180 int align = (TARGET_32BIT && (cum->words & 1) != 0
4181 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 4182
c53bdcf5 4183 cum->words += align + rs6000_arg_size (mode, type);
4697a36c 4184
a3170dc6
AH
4185 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4186 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4187 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4188
4189 if (TARGET_DEBUG_ARG)
4190 {
4191 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4192 cum->words, cum->fregno);
4193 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4194 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4195 fprintf (stderr, "named = %d, align = %d\n", named, align);
4196 }
4197 }
4697a36c 4198}
a6c9bed4
AH
4199
4200/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4201
a6c9bed4 4202static rtx
a2369ed3
DJ
4203rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4204 tree type)
a6c9bed4
AH
4205{
4206 if (cum->stdarg)
4207 {
4208 int gregno = cum->sysv_gregno;
c53bdcf5 4209 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4210
4211 /* SPE vectors are put in odd registers. */
4212 if (n_words == 2 && (gregno & 1) == 0)
4213 gregno += 1;
4214
4215 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4216 {
4217 rtx r1, r2;
4218 enum machine_mode m = SImode;
4219
4220 r1 = gen_rtx_REG (m, gregno);
4221 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4222 r2 = gen_rtx_REG (m, gregno + 1);
4223 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4224 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4225 }
4226 else
b78d48dd 4227 return NULL_RTX;
a6c9bed4
AH
4228 }
4229 else
4230 {
4231 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4232 return gen_rtx_REG (mode, cum->sysv_gregno);
4233 else
b78d48dd 4234 return NULL_RTX;
a6c9bed4
AH
4235 }
4236}
4237
b78d48dd
FJ
4238/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4239
4240static rtx
4241rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4242 tree type, int align_words)
4243{
4244 if (mode == DFmode)
4245 {
4246 /* -mpowerpc64 with 32bit ABI splits up a DFmode argument
4247 in vararg list into zero, one or two GPRs */
4248 if (align_words >= GP_ARG_NUM_REG)
4249 return gen_rtx_PARALLEL (DFmode,
4250 gen_rtvec (2,
4251 gen_rtx_EXPR_LIST (VOIDmode,
4252 NULL_RTX, const0_rtx),
4253 gen_rtx_EXPR_LIST (VOIDmode,
4254 gen_rtx_REG (mode,
4255 cum->fregno),
4256 const0_rtx)));
c53bdcf5 4257 else if (align_words + rs6000_arg_size (mode, type)
b78d48dd
FJ
4258 > GP_ARG_NUM_REG)
4259 /* If this is partially on the stack, then we only
a3c9585f 4260 include the portion actually in registers here. */
b78d48dd
FJ
4261 return gen_rtx_PARALLEL (DFmode,
4262 gen_rtvec (2,
4263 gen_rtx_EXPR_LIST (VOIDmode,
4264 gen_rtx_REG (SImode,
4265 GP_ARG_MIN_REG
4266 + align_words),
4267 const0_rtx),
4268 gen_rtx_EXPR_LIST (VOIDmode,
4269 gen_rtx_REG (mode,
4270 cum->fregno),
4271 const0_rtx)));
4272
4273 /* split a DFmode arg into two GPRs */
4274 return gen_rtx_PARALLEL (DFmode,
4275 gen_rtvec (3,
4276 gen_rtx_EXPR_LIST (VOIDmode,
4277 gen_rtx_REG (SImode,
4278 GP_ARG_MIN_REG
4279 + align_words),
4280 const0_rtx),
4281 gen_rtx_EXPR_LIST (VOIDmode,
4282 gen_rtx_REG (SImode,
4283 GP_ARG_MIN_REG
4284 + align_words + 1),
4285 GEN_INT (4)),
4286 gen_rtx_EXPR_LIST (VOIDmode,
4287 gen_rtx_REG (mode, cum->fregno),
4288 const0_rtx)));
4289 }
4290 /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one
4291 or two GPRs */
4292 else if (mode == DImode)
4293 {
4294 if (align_words < GP_ARG_NUM_REG - 1)
4295 return gen_rtx_PARALLEL (DImode,
4296 gen_rtvec (2,
4297 gen_rtx_EXPR_LIST (VOIDmode,
4298 gen_rtx_REG (SImode,
4299 GP_ARG_MIN_REG
4300 + align_words),
4301 const0_rtx),
4302 gen_rtx_EXPR_LIST (VOIDmode,
4303 gen_rtx_REG (SImode,
4304 GP_ARG_MIN_REG
4305 + align_words + 1),
4306 GEN_INT (4))));
4307 else if (align_words == GP_ARG_NUM_REG - 1)
4308 return gen_rtx_PARALLEL (DImode,
4309 gen_rtvec (2,
4310 gen_rtx_EXPR_LIST (VOIDmode,
4311 NULL_RTX, const0_rtx),
4312 gen_rtx_EXPR_LIST (VOIDmode,
4313 gen_rtx_REG (SImode,
4314 GP_ARG_MIN_REG
4315 + align_words),
4316 const0_rtx)));
4317 }
4318 else if (mode == BLKmode && align_words <= (GP_ARG_NUM_REG - 1))
4319 {
4320 int k;
4321 int size = int_size_in_bytes (type);
2f7b62ef 4322 int no_units = ((size - 1) / 4) + 1;
b78d48dd
FJ
4323 int max_no_words = GP_ARG_NUM_REG - align_words;
4324 int rtlvec_len = no_units < max_no_words ? no_units : max_no_words;
4325 rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx));
4326
4327 memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx));
4328
4329 for (k=0; k < rtlvec_len; k++)
4330 rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode,
4331 gen_rtx_REG (SImode,
4332 GP_ARG_MIN_REG
4333 + align_words + k),
4334 k == 0 ? const0_rtx : GEN_INT (k*4));
4335
4336 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (k, rtlvec));
4337 }
4338
4339 return NULL_RTX;
4340}
4341
4697a36c
MM
4342/* Determine where to put an argument to a function.
4343 Value is zero to push the argument on the stack,
4344 or a hard register in which to store the argument.
4345
4346 MODE is the argument's machine mode.
4347 TYPE is the data type of the argument (as a tree).
4348 This is null for libcalls where that information may
4349 not be available.
4350 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4351 the preceding args and about the function being called.
4352 NAMED is nonzero if this argument is a named parameter
4353 (otherwise it is an extra parameter matching an ellipsis).
4354
4355 On RS/6000 the first eight words of non-FP are normally in registers
4356 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4357 Under V.4, the first 8 FP args are in registers.
4358
4359 If this is floating-point and no prototype is specified, we use
4360 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4361 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4362 so we can pass the FP value just in one register. emit_library_function
1c20ae99 4363 doesn't support PARALLEL anyway. */
4697a36c
MM
4364
4365struct rtx_def *
a2369ed3
DJ
4366function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4367 tree type, int named)
4697a36c 4368{
4cc833b7 4369 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4370
a4f6c312
SS
4371 /* Return a marker to indicate whether CR1 needs to set or clear the
4372 bit that V.4 uses to say fp args were passed in registers.
4373 Assume that we don't need the marker for software floating point,
4374 or compiler generated library calls. */
4697a36c
MM
4375 if (mode == VOIDmode)
4376 {
f607bc57 4377 if (abi == ABI_V4
7509c759 4378 && cum->nargs_prototype < 0
b9599e46
FS
4379 && (cum->call_cookie & CALL_LIBCALL) == 0
4380 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4381 {
a3170dc6
AH
4382 /* For the SPE, we need to crxor CR6 always. */
4383 if (TARGET_SPE_ABI)
4384 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4385 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4386 return GEN_INT (cum->call_cookie
4387 | ((cum->fregno == FP_ARG_MIN_REG)
4388 ? CALL_V4_SET_FP_ARGS
4389 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4390 }
4697a36c 4391
7509c759 4392 return GEN_INT (cum->call_cookie);
4697a36c
MM
4393 }
4394
2858f73a 4395 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4396 if (TARGET_64BIT && ! cum->prototype)
4397 {
4398 /* Vector parameters get passed in vector register
4399 and also in GPRs or memory, in absence of prototype. */
4400 int align_words;
4401 rtx slot;
4402 align_words = (cum->words + 1) & ~1;
4403
4404 if (align_words >= GP_ARG_NUM_REG)
4405 {
4406 slot = NULL_RTX;
4407 }
4408 else
4409 {
4410 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4411 }
4412 return gen_rtx_PARALLEL (mode,
4413 gen_rtvec (2,
4414 gen_rtx_EXPR_LIST (VOIDmode,
4415 slot, const0_rtx),
4416 gen_rtx_EXPR_LIST (VOIDmode,
4417 gen_rtx_REG (mode, cum->vregno),
4418 const0_rtx)));
4419 }
4420 else
4421 return gen_rtx_REG (mode, cum->vregno);
2858f73a 4422 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4423 {
2858f73a 4424 if (named || abi == ABI_V4)
a594a19c 4425 return NULL_RTX;
0ac081f6 4426 else
a594a19c
GK
4427 {
4428 /* Vector parameters to varargs functions under AIX or Darwin
4429 get passed in memory and possibly also in GPRs. */
4430 int align, align_words;
2858f73a 4431 enum machine_mode part_mode = mode;
a594a19c
GK
4432
4433 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
4434 2 mod 4 in terms of words in 32-bit mode, since the parameter
4435 save area starts at offset 24 from the stack. In 64-bit mode,
4436 they just have to start on an even word, since the parameter
4437 save area is 16-byte aligned. */
4438 if (TARGET_32BIT)
4439 align = ((6 - (cum->words & 3)) & 3);
4440 else
4441 align = cum->words & 1;
a594a19c
GK
4442 align_words = cum->words + align;
4443
4444 /* Out of registers? Memory, then. */
4445 if (align_words >= GP_ARG_NUM_REG)
4446 return NULL_RTX;
4447
2858f73a
GK
4448 /* The vector value goes in GPRs. Only the part of the
4449 value in GPRs is reported here. */
4450 if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS)
4451 > GP_ARG_NUM_REG)
839a4992 4452 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
4453 is either wholly in GPRs or half in GPRs and half not. */
4454 part_mode = DImode;
4455
4456 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 4457 }
0ac081f6 4458 }
a6c9bed4
AH
4459 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4460 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4461 else if (abi == ABI_V4)
4697a36c 4462 {
a3170dc6 4463 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4464 && (mode == SFmode || mode == DFmode))
4465 {
4466 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4467 return gen_rtx_REG (mode, cum->fregno);
4468 else
b78d48dd 4469 return NULL_RTX;
4cc833b7
RH
4470 }
4471 else
4472 {
4473 int n_words;
4474 int gregno = cum->sysv_gregno;
4475
4476 /* Aggregates and IEEE quad get passed by reference. */
4477 if ((type && AGGREGATE_TYPE_P (type))
4478 || mode == TFmode)
4479 n_words = 1;
4480 else
c53bdcf5 4481 n_words = rs6000_arg_size (mode, type);
4cc833b7 4482
a4b0320c 4483 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4484 if (n_words == 2 && (gregno & 1) == 0)
4485 gregno += 1;
4486
c53bdcf5 4487 /* Long long does not split between registers and stack. */
4cc833b7 4488 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4489 return gen_rtx_REG (mode, gregno);
4cc833b7 4490 else
b78d48dd 4491 return NULL_RTX;
4cc833b7 4492 }
4697a36c 4493 }
4cc833b7
RH
4494 else
4495 {
4496 int align = (TARGET_32BIT && (cum->words & 1) != 0
4497 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
4498 int align_words = cum->words + align;
4697a36c 4499
4cc833b7
RH
4500 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4501 return NULL_RTX;
4502
b78d48dd 4503 if (TARGET_32BIT && TARGET_POWERPC64
e91fa876 4504 && (mode == DImode || mode == BLKmode))
b78d48dd
FJ
4505 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4506
2858f73a 4507 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 4508 {
c53bdcf5
AM
4509 rtx fpr[2];
4510 rtx *r;
4511 bool needs_psave;
4512 enum machine_mode fmode = mode;
4513 int n;
4514 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
4515
4516 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
4517 {
4518 /* Long double split over regs and memory. */
4519 if (fmode == TFmode)
4520 fmode = DFmode;
4521
4522 /* Currently, we only ever need one reg here because complex
4523 doubles are split. */
4524 if (cum->fregno != FP_ARG_MAX_REG - 1)
4525 abort ();
4526 }
4527 fpr[1] = gen_rtx_REG (fmode, cum->fregno);
4528
4529 /* Do we also need to pass this arg in the parameter save
4530 area? */
4531 needs_psave = (type
4532 && (cum->nargs_prototype <= 0
4533 || (DEFAULT_ABI == ABI_AIX
4534 && TARGET_XL_CALL
4535 && align_words >= GP_ARG_NUM_REG)));
4536
4537 if (!needs_psave && mode == fmode)
4538 return fpr[1];
4cc833b7 4539
e91fa876
FJ
4540 if (TARGET_32BIT && TARGET_POWERPC64
4541 && mode == DFmode && cum->stdarg)
4542 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4543
c53bdcf5
AM
4544 /* Describe where this piece goes. */
4545 r = fpr + 1;
4546 *r = gen_rtx_EXPR_LIST (VOIDmode, *r, const0_rtx);
4547 n = 1;
4548
4549 if (needs_psave)
4550 {
4551 /* Now describe the part that goes in gprs or the stack.
4552 This piece must come first, before the fprs. */
4553 rtx reg = NULL_RTX;
4554 if (align_words < GP_ARG_NUM_REG)
4555 {
4556 unsigned long n_words = rs6000_arg_size (mode, type);
4557 enum machine_mode rmode = mode;
4558
4559 if (align_words + n_words > GP_ARG_NUM_REG)
4560 /* If this is partially on the stack, then we only
4561 include the portion actually in registers here.
4562 We know this can only be one register because
4563 complex doubles are splt. */
4564 rmode = Pmode;
4565 reg = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words);
4566 }
4567 *--r = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4568 ++n;
4569 }
4570
4571 return gen_rtx_PARALLEL (mode, gen_rtvec_v (n, r));
4cc833b7
RH
4572 }
4573 else if (align_words < GP_ARG_NUM_REG)
4574 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4575 else
4576 return NULL_RTX;
4697a36c 4577 }
4697a36c
MM
4578}
4579\f
4580/* For an arg passed partly in registers and partly in memory,
4581 this is the number of registers used.
4582 For args passed entirely in registers or entirely in memory, zero. */
4583
4584int
a2369ed3 4585function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 4586 tree type, int named)
4697a36c 4587{
c53bdcf5
AM
4588 int ret = 0;
4589
f607bc57 4590 if (DEFAULT_ABI == ABI_V4)
4697a36c 4591 return 0;
4697a36c 4592
c53bdcf5
AM
4593 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
4594 && cum->nargs_prototype >= 0)
4595 return 0;
4596
4597 if (USE_FP_FOR_ARG_P (cum, mode, type))
4697a36c 4598 {
c53bdcf5
AM
4599 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
4600 ret = FP_ARG_MAX_REG - cum->fregno;
4601 else if (cum->nargs_prototype >= 0)
4697a36c
MM
4602 return 0;
4603 }
4604
4605 if (cum->words < GP_ARG_NUM_REG
c53bdcf5
AM
4606 && GP_ARG_NUM_REG < cum->words + rs6000_arg_size (mode, type))
4607 ret = GP_ARG_NUM_REG - cum->words;
4697a36c 4608
c53bdcf5
AM
4609 if (ret != 0 && TARGET_DEBUG_ARG)
4610 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 4611
c53bdcf5 4612 return ret;
4697a36c
MM
4613}
4614\f
4615/* A C expression that indicates when an argument must be passed by
4616 reference. If nonzero for an argument, a copy of that argument is
4617 made in memory and a pointer to the argument is passed instead of
4618 the argument itself. The pointer is passed in whatever way is
4619 appropriate for passing a pointer to that type.
4620
c8c99a68
DE
4621 Under V.4, structures and unions are passed by reference.
4622
4623 As an extension to all ABIs, variable sized types are passed by
4624 reference. */
4697a36c
MM
4625
4626int
a2369ed3
DJ
4627function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4628 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 4629 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 4630{
f607bc57 4631 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
4632 && ((type && AGGREGATE_TYPE_P (type))
4633 || mode == TFmode))
4697a36c
MM
4634 {
4635 if (TARGET_DEBUG_ARG)
4636 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
4637
4638 return 1;
4639 }
fff2cb99 4640 return type && int_size_in_bytes (type) < 0;
4697a36c 4641}
5985c7a6
FJ
4642
4643static void
2d9db8eb 4644rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
4645{
4646 int i;
4647 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
4648
4649 if (nregs == 0)
4650 return;
4651
4652 for (i = 0; i < nregs; i++)
4653 {
4654 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
4655 if (reload_completed)
4656 {
4657 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
4658 tem = NULL_RTX;
4659 else
4660 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
4661 i * GET_MODE_SIZE(reg_mode));
4662 }
4663 else
4664 tem = replace_equiv_address (tem, XEXP (tem, 0));
4665
4666 if (tem == NULL_RTX)
4667 abort ();
4668
4669 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
4670 }
4671}
4672
4697a36c
MM
4673\f
4674/* Perform any needed actions needed for a function that is receiving a
4675 variable number of arguments.
4676
4677 CUM is as above.
4678
4679 MODE and TYPE are the mode and type of the current parameter.
4680
4681 PRETEND_SIZE is a variable that should be set to the amount of stack
4682 that must be pushed by the prolog to pretend that our caller pushed
4683 it.
4684
4685 Normally, this macro will push all remaining incoming registers on the
4686 stack and set PRETEND_SIZE to the length of the registers pushed. */
4687
c6e8c921 4688static void
a2369ed3
DJ
4689setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4690 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4691{
4cc833b7
RH
4692 CUMULATIVE_ARGS next_cum;
4693 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4694 rtx save_area = NULL_RTX, mem;
dfafc897 4695 int first_reg_offset, set;
4697a36c 4696
f31bf321 4697 /* Skip the last named argument. */
d34c5b80 4698 next_cum = *cum;
f31bf321 4699 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4700
f607bc57 4701 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4702 {
4cc833b7 4703 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4704 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4705 if (! no_rtl)
2c4974b7 4706 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4707 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4708
4709 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4710 }
60e2d0ca 4711 else
4697a36c 4712 {
d34c5b80 4713 first_reg_offset = next_cum.words;
4cc833b7 4714 save_area = virtual_incoming_args_rtx;
00dba523 4715 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4716
4717 if (MUST_PASS_IN_STACK (mode, type))
c53bdcf5 4718 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 4719 }
4697a36c 4720
dfafc897 4721 set = get_varargs_alias_set ();
c81fc13e 4722 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4723 {
dfafc897
FS
4724 mem = gen_rtx_MEM (BLKmode,
4725 plus_constant (save_area,
4726 first_reg_offset * reg_size)),
ba4828e0 4727 set_mem_alias_set (mem, set);
8ac61af7 4728 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4729
5985c7a6
FJ
4730 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4731 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4732 }
4733
4697a36c 4734 /* Save FP registers if needed. */
f607bc57 4735 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4736 && TARGET_HARD_FLOAT && TARGET_FPRS
4737 && ! no_rtl
4cc833b7 4738 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4739 {
4cc833b7 4740 int fregno = next_cum.fregno;
9ebbca7d 4741 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4742 rtx lab = gen_label_rtx ();
4743 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4744
4cc833b7 4745 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4746 pc_rtx,
39403d82 4747 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4748 gen_rtx_NE (VOIDmode, cr1,
4749 const0_rtx),
39403d82 4750 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4751 pc_rtx)));
4752
4cc833b7
RH
4753 while (fregno <= FP_ARG_V4_MAX_REG)
4754 {
dfafc897 4755 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4756 set_mem_alias_set (mem, set);
dfafc897 4757 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4758 fregno++;
4759 off += 8;
4697a36c 4760 }
4cc833b7
RH
4761
4762 emit_label (lab);
4697a36c 4763 }
4697a36c 4764}
4697a36c 4765
dfafc897 4766/* Create the va_list data type. */
2c4974b7 4767
c35d187f
RH
4768static tree
4769rs6000_build_builtin_va_list (void)
dfafc897 4770{
64c2816f 4771 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4772
9ebbca7d
GK
4773 /* For AIX, prefer 'char *' because that's what the system
4774 header files like. */
f607bc57 4775 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4776 return build_pointer_type (char_type_node);
dfafc897 4777
f1e639b1 4778 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4779 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4780
9ebbca7d
GK
4781 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4782 unsigned_char_type_node);
4783 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4784 unsigned_char_type_node);
64c2816f
DT
4785 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4786 every user file. */
4787 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4788 short_unsigned_type_node);
dfafc897
FS
4789 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4790 ptr_type_node);
4791 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4792 ptr_type_node);
4793
4794 DECL_FIELD_CONTEXT (f_gpr) = record;
4795 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4796 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4797 DECL_FIELD_CONTEXT (f_ovf) = record;
4798 DECL_FIELD_CONTEXT (f_sav) = record;
4799
bab45a51
FS
4800 TREE_CHAIN (record) = type_decl;
4801 TYPE_NAME (record) = type_decl;
dfafc897
FS
4802 TYPE_FIELDS (record) = f_gpr;
4803 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4804 TREE_CHAIN (f_fpr) = f_res;
4805 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4806 TREE_CHAIN (f_ovf) = f_sav;
4807
4808 layout_type (record);
4809
4810 /* The correct type is an array type of one element. */
4811 return build_array_type (record, build_index_type (size_zero_node));
4812}
4813
4814/* Implement va_start. */
4815
4816void
a2369ed3 4817rs6000_va_start (tree valist, rtx nextarg)
4697a36c 4818{
dfafc897 4819 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 4820 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 4821 tree gpr, fpr, ovf, sav, t;
2c4974b7 4822
dfafc897 4823 /* Only SVR4 needs something special. */
f607bc57 4824 if (DEFAULT_ABI != ABI_V4)
dfafc897 4825 {
e5faf155 4826 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
4827 return;
4828 }
4829
973a648b 4830 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4831 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4832 f_res = TREE_CHAIN (f_fpr);
4833 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4834 f_sav = TREE_CHAIN (f_ovf);
4835
8ebecc3b 4836 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4837 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4838 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4839 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4840 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4841
4842 /* Count number of gp and fp argument registers used. */
4cc833b7 4843 words = current_function_args_info.words;
dfafc897
FS
4844 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
4845 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
4846
4847 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
4848 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
4849 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
4850 words, n_gpr, n_fpr);
dfafc897
FS
4851
4852 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
4853 TREE_SIDE_EFFECTS (t) = 1;
4854 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4855
4856 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
4857 TREE_SIDE_EFFECTS (t) = 1;
4858 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4859
4860 /* Find the overflow area. */
4861 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
4862 if (words != 0)
4863 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
4864 build_int_2 (words * UNITS_PER_WORD, 0));
4865 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4866 TREE_SIDE_EFFECTS (t) = 1;
4867 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4868
4869 /* Find the register save area. */
4870 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
4871 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
4872 build_int_2 (-RS6000_VARARGS_SIZE, -1));
4873 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
4874 TREE_SIDE_EFFECTS (t) = 1;
4875 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4876}
4877
4878/* Implement va_arg. */
4879
4880rtx
a2369ed3 4881rs6000_va_arg (tree valist, tree type)
dfafc897 4882{
c566f9bd 4883 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
4884 tree gpr, fpr, ovf, sav, reg, t, u;
4885 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
4886 rtx lab_false, lab_over, addr_rtx, r;
4887
f607bc57 4888 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
4889 {
4890 /* Variable sized types are passed by reference. */
fff2cb99 4891 if (int_size_in_bytes (type) < 0)
c8c99a68
DE
4892 {
4893 u = build_pointer_type (type);
4894
4895 /* Args grow upward. */
4896 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
4897 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4898 TREE_SIDE_EFFECTS (t) = 1;
4899
4900 t = build1 (NOP_EXPR, build_pointer_type (u), t);
4901 TREE_SIDE_EFFECTS (t) = 1;
4902
4903 t = build1 (INDIRECT_REF, u, t);
4904 TREE_SIDE_EFFECTS (t) = 1;
4905
4906 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4907 }
fa78dbea 4908 if (targetm.calls.split_complex_arg
c53bdcf5
AM
4909 && TREE_CODE (type) == COMPLEX_TYPE)
4910 {
4911 tree elem_type = TREE_TYPE (type);
4912 enum machine_mode elem_mode = TYPE_MODE (elem_type);
4913 int elem_size = GET_MODE_SIZE (elem_mode);
4914
4915 if (elem_size < UNITS_PER_WORD)
4916 {
4917 rtx real_part, imag_part, dest_real, rr;
4918
4919 real_part = rs6000_va_arg (valist, elem_type);
4920 imag_part = rs6000_va_arg (valist, elem_type);
4921
4922 /* We're not returning the value here, but the address.
4923 real_part and imag_part are not contiguous, and we know
4924 there is space available to pack real_part next to
4925 imag_part. float _Complex is not promoted to
4926 double _Complex by the default promotion rules that
4927 promote float to double. */
4928 if (2 * elem_size > UNITS_PER_WORD)
4929 abort ();
4930
4931 real_part = gen_rtx_MEM (elem_mode, real_part);
4932 imag_part = gen_rtx_MEM (elem_mode, imag_part);
4933
4934 dest_real = adjust_address (imag_part, elem_mode, -elem_size);
4935 rr = gen_reg_rtx (elem_mode);
4936 emit_move_insn (rr, real_part);
4937 emit_move_insn (dest_real, rr);
4938
4939 return XEXP (dest_real, 0);
4940 }
4941 }
4942
4943 return std_expand_builtin_va_arg (valist, type);
c8c99a68 4944 }
dfafc897 4945
973a648b 4946 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4947 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4948 f_res = TREE_CHAIN (f_fpr);
4949 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4950 f_sav = TREE_CHAIN (f_ovf);
4951
8ebecc3b 4952 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4953 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4954 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4955 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4956 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4957
4958 size = int_size_in_bytes (type);
4959 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 4960
dfafc897 4961 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 4962 {
dfafc897
FS
4963 /* Aggregates and long doubles are passed by reference. */
4964 indirect_p = 1;
4965 reg = gpr;
4966 n_reg = 1;
4967 sav_ofs = 0;
4968 sav_scale = 4;
d3294cd9
FS
4969 size = UNITS_PER_WORD;
4970 rsize = 1;
dfafc897 4971 }
a3170dc6 4972 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
4973 {
4974 /* FP args go in FP registers, if present. */
4975 indirect_p = 0;
4976 reg = fpr;
4977 n_reg = 1;
4978 sav_ofs = 8*4;
4979 sav_scale = 8;
4cc833b7 4980 }
dfafc897
FS
4981 else
4982 {
4983 /* Otherwise into GP registers. */
4984 indirect_p = 0;
4985 reg = gpr;
4986 n_reg = rsize;
4987 sav_ofs = 0;
4988 sav_scale = 4;
4989 }
4990
a3c9585f 4991 /* Pull the value out of the saved registers.... */
dfafc897
FS
4992
4993 lab_false = gen_label_rtx ();
4994 lab_over = gen_label_rtx ();
4995 addr_rtx = gen_reg_rtx (Pmode);
4996
16861f33
AH
4997 /* AltiVec vectors never go in registers. */
4998 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 4999 {
41daaf0e
AH
5000 TREE_THIS_VOLATILE (reg) = 1;
5001 emit_cmp_and_jump_insns
5002 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
5003 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
5004 lab_false);
dfafc897 5005
41daaf0e
AH
5006 /* Long long is aligned in the registers. */
5007 if (n_reg > 1)
5008 {
5009 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
5010 build_int_2 (n_reg - 1, 0));
5011 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
5012 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
5013 TREE_SIDE_EFFECTS (u) = 1;
5014 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
5015 }
2c4974b7 5016
41daaf0e
AH
5017 if (sav_ofs)
5018 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
5019 else
5020 t = sav;
2c4974b7 5021
41daaf0e
AH
5022 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
5023 build_int_2 (n_reg, 0));
5024 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 5025
41daaf0e
AH
5026 u = build1 (CONVERT_EXPR, integer_type_node, u);
5027 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 5028
41daaf0e
AH
5029 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
5030 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 5031
41daaf0e
AH
5032 t = build (PLUS_EXPR, ptr_type_node, t, u);
5033 TREE_SIDE_EFFECTS (t) = 1;
5034
5035 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
5036 if (r != addr_rtx)
5037 emit_move_insn (addr_rtx, r);
5038
5039 emit_jump_insn (gen_jump (lab_over));
5040 emit_barrier ();
5041 }
dfafc897 5042
dfafc897
FS
5043 emit_label (lab_false);
5044
a4f6c312 5045 /* ... otherwise out of the overflow area. */
dfafc897 5046
41daaf0e
AH
5047 /* Make sure we don't find reg 7 for the next int arg.
5048
5049 All AltiVec vectors go in the overflow area. So in the AltiVec
5050 case we need to get the vectors from the overflow area, but
5051 remember where the GPRs and FPRs are. */
16861f33
AH
5052 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
5053 || !TARGET_ALTIVEC))
dfafc897
FS
5054 {
5055 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
5056 TREE_SIDE_EFFECTS (t) = 1;
5057 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5058 }
5059
5060 /* Care for on-stack alignment if needed. */
5061 if (rsize <= 1)
5062 t = ovf;
5063 else
5064 {
41daaf0e
AH
5065 int align;
5066
16861f33
AH
5067 /* AltiVec vectors are 16 byte aligned. */
5068 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
5069 align = 15;
5070 else
5071 align = 7;
5072
5073 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
5074 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
5075 }
5076 t = save_expr (t);
5077
5078 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
5079 if (r != addr_rtx)
5080 emit_move_insn (addr_rtx, r);
5081
5082 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
5083 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5084 TREE_SIDE_EFFECTS (t) = 1;
5085 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5086
5087 emit_label (lab_over);
5088
5089 if (indirect_p)
5090 {
5091 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 5092 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
5093 emit_move_insn (addr_rtx, r);
5094 }
5095
5096 return addr_rtx;
4697a36c 5097}
0ac081f6
AH
5098
5099/* Builtins. */
5100
6a2dd09a
RS
5101#define def_builtin(MASK, NAME, TYPE, CODE) \
5102do { \
5103 if ((MASK) & target_flags) \
5104 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
5105 NULL, NULL_TREE); \
0ac081f6
AH
5106} while (0)
5107
24408032
AH
5108/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
5109
2212663f 5110static const struct builtin_description bdesc_3arg[] =
24408032
AH
5111{
5112 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
5113 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
5114 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
5115 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
5116 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
5117 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
5118 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
5119 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
5120 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
5121 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
5122 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
5123 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
5124 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
5125 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
5126 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
5127 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
5128 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
5129 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
5130 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
5131 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
5132 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
5133 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
5134 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
5135};
2212663f 5136
95385cbb
AH
5137/* DST operations: void foo (void *, const int, const char). */
5138
5139static const struct builtin_description bdesc_dst[] =
5140{
5141 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
5142 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
5143 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
5144 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
5145};
5146
2212663f 5147/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 5148
a3170dc6 5149static struct builtin_description bdesc_2arg[] =
0ac081f6 5150{
f18c054f
DB
5151 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
5152 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
5153 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
5154 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
5155 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
5156 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
5157 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
5158 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
5159 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
5160 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
5161 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 5162 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
5163 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
5164 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
5165 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
5166 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
5167 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
5168 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
5169 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
5170 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
5171 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
5172 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
5173 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
5174 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5175 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5176 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5177 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5178 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5179 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5180 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5181 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5182 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5183 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5184 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5185 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5186 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5187 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5188 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5189 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5190 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5191 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5192 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5193 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5194 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5195 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5196 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5197 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5198 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5199 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5200 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5201 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5202 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5203 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5204 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5205 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5206 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5207 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5208 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5209 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5210 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5211 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5212 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5213 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5214 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5215 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5216 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5217 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5218 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5219 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5220 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5221 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5222 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5223 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5224 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5225 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5226 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5227 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5228 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5229 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5230 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5231 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5232 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5233 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5234 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5235 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5236 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5237 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5238 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5239 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5240 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5241 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5242 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5243 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5244 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5245 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5246 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5247 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5248 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5249 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5250 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5251 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5252 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5253 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5254 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5255 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5256 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5257 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5258 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5259 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5260 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5261 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5262 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5263 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5264
5265 /* Place holder, leave as first spe builtin. */
5266 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5267 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5268 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5269 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5270 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5271 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5272 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5273 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5274 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5275 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5276 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5277 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5278 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5279 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5280 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5281 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5282 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5283 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5284 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5285 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5286 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5287 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5288 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5289 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5290 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5291 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5292 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5293 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5294 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5295 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5296 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5297 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5298 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5299 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5300 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5301 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5302 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5303 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5304 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5305 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5306 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5307 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5308 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5309 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5310 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5311 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5312 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5313 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5314 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5315 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5316 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5317 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5318 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5319 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5320 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5321 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5322 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5323 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5324 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5325 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5326 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5327 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5328 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5329 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5330 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5331 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5332 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5333 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5334 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5335 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5336 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5337 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5338 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5339 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5340 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5341 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5342 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5343 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5344 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5345 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5346 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5347 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5348 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5349 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5350 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5351 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5352 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5353 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5354 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5355 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5356 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5357 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5358 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5359 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5360 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5361 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
5362 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
5363 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
5364 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
5365 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
5366 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
5367 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
5368 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
5369 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
5370 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
5371 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
5372 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
5373 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
5374 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
5375
5376 /* SPE binary operations expecting a 5-bit unsigned literal. */
5377 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
5378
5379 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
5380 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
5381 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
5382 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
5383 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
5384 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
5385 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
5386 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
5387 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
5388 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
5389 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
5390 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
5391 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
5392 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
5393 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
5394 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
5395 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
5396 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
5397 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
5398 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
5399 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
5400 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
5401 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
5402 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
5403 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
5404 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
5405
5406 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 5407 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
5408};
5409
5410/* AltiVec predicates. */
5411
5412struct builtin_description_predicates
5413{
5414 const unsigned int mask;
5415 const enum insn_code icode;
5416 const char *opcode;
5417 const char *const name;
5418 const enum rs6000_builtins code;
5419};
5420
5421static const struct builtin_description_predicates bdesc_altivec_preds[] =
5422{
5423 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
5424 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
5425 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
5426 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
5427 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
5428 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
5429 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
5430 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
5431 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
5432 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
5433 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
5434 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
5435 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 5436};
24408032 5437
a3170dc6
AH
5438/* SPE predicates. */
5439static struct builtin_description bdesc_spe_predicates[] =
5440{
5441 /* Place-holder. Leave as first. */
5442 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
5443 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
5444 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
5445 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
5446 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
5447 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
5448 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
5449 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
5450 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
5451 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
5452 /* Place-holder. Leave as last. */
5453 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
5454};
5455
5456/* SPE evsel predicates. */
5457static struct builtin_description bdesc_spe_evsel[] =
5458{
5459 /* Place-holder. Leave as first. */
5460 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
5461 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
5462 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
5463 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
5464 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
5465 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
5466 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
5467 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
5468 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
5469 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
5470 /* Place-holder. Leave as last. */
5471 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
5472};
5473
b6d08ca1 5474/* ABS* operations. */
100c4561
AH
5475
5476static const struct builtin_description bdesc_abs[] =
5477{
5478 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
5479 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
5480 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
5481 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
5482 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
5483 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
5484 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
5485};
5486
617e0e1d
DB
5487/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
5488 foo (VECa). */
24408032 5489
a3170dc6 5490static struct builtin_description bdesc_1arg[] =
2212663f 5491{
617e0e1d
DB
5492 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
5493 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
5494 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
5495 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
5496 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
5497 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
5498 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
5499 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
5500 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
5501 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
5502 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
5503 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
5504 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
5505 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
5506 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
5507 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
5508 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
5509
5510 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
5511 end with SPE_BUILTIN_EVSUBFUSIAAW. */
5512 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
5513 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
5514 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
5515 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
5516 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
5517 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
5518 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
5519 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
5520 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
5521 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
5522 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
5523 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
5524 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
5525 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
5526 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
5527 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
5528 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
5529 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
5530 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
5531 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
5532 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
5533 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
5534 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
5535 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
5536 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
5537 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
5538 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
5539 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
5540
5541 /* Place-holder. Leave as last unary SPE builtin. */
5542 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
5543};
5544
5545static rtx
a2369ed3 5546rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5547{
5548 rtx pat;
5549 tree arg0 = TREE_VALUE (arglist);
5550 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5551 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5552 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5553
0559cc77
DE
5554 if (icode == CODE_FOR_nothing)
5555 /* Builtin not supported on this processor. */
5556 return 0;
5557
20e26713
AH
5558 /* If we got invalid arguments bail out before generating bad rtl. */
5559 if (arg0 == error_mark_node)
9a171fcd 5560 return const0_rtx;
20e26713 5561
0559cc77
DE
5562 if (icode == CODE_FOR_altivec_vspltisb
5563 || icode == CODE_FOR_altivec_vspltish
5564 || icode == CODE_FOR_altivec_vspltisw
5565 || icode == CODE_FOR_spe_evsplatfi
5566 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
5567 {
5568 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
5569 if (GET_CODE (op0) != CONST_INT
5570 || INTVAL (op0) > 0x1f
5571 || INTVAL (op0) < -0x1f)
5572 {
5573 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 5574 return const0_rtx;
b44140e7 5575 }
b44140e7
AH
5576 }
5577
c62f2db5 5578 if (target == 0
2212663f
DB
5579 || GET_MODE (target) != tmode
5580 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5581 target = gen_reg_rtx (tmode);
5582
5583 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5584 op0 = copy_to_mode_reg (mode0, op0);
5585
5586 pat = GEN_FCN (icode) (target, op0);
5587 if (! pat)
5588 return 0;
5589 emit_insn (pat);
0ac081f6 5590
2212663f
DB
5591 return target;
5592}
ae4b4a02 5593
100c4561 5594static rtx
a2369ed3 5595altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
5596{
5597 rtx pat, scratch1, scratch2;
5598 tree arg0 = TREE_VALUE (arglist);
5599 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5600 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5601 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5602
5603 /* If we have invalid arguments, bail out before generating bad rtl. */
5604 if (arg0 == error_mark_node)
9a171fcd 5605 return const0_rtx;
100c4561
AH
5606
5607 if (target == 0
5608 || GET_MODE (target) != tmode
5609 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5610 target = gen_reg_rtx (tmode);
5611
5612 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5613 op0 = copy_to_mode_reg (mode0, op0);
5614
5615 scratch1 = gen_reg_rtx (mode0);
5616 scratch2 = gen_reg_rtx (mode0);
5617
5618 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
5619 if (! pat)
5620 return 0;
5621 emit_insn (pat);
5622
5623 return target;
5624}
5625
0ac081f6 5626static rtx
a2369ed3 5627rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
5628{
5629 rtx pat;
5630 tree arg0 = TREE_VALUE (arglist);
5631 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5632 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5633 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5634 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5635 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5636 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5637
0559cc77
DE
5638 if (icode == CODE_FOR_nothing)
5639 /* Builtin not supported on this processor. */
5640 return 0;
5641
20e26713
AH
5642 /* If we got invalid arguments bail out before generating bad rtl. */
5643 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5644 return const0_rtx;
20e26713 5645
0559cc77
DE
5646 if (icode == CODE_FOR_altivec_vcfux
5647 || icode == CODE_FOR_altivec_vcfsx
5648 || icode == CODE_FOR_altivec_vctsxs
5649 || icode == CODE_FOR_altivec_vctuxs
5650 || icode == CODE_FOR_altivec_vspltb
5651 || icode == CODE_FOR_altivec_vsplth
5652 || icode == CODE_FOR_altivec_vspltw
5653 || icode == CODE_FOR_spe_evaddiw
5654 || icode == CODE_FOR_spe_evldd
5655 || icode == CODE_FOR_spe_evldh
5656 || icode == CODE_FOR_spe_evldw
5657 || icode == CODE_FOR_spe_evlhhesplat
5658 || icode == CODE_FOR_spe_evlhhossplat
5659 || icode == CODE_FOR_spe_evlhhousplat
5660 || icode == CODE_FOR_spe_evlwhe
5661 || icode == CODE_FOR_spe_evlwhos
5662 || icode == CODE_FOR_spe_evlwhou
5663 || icode == CODE_FOR_spe_evlwhsplat
5664 || icode == CODE_FOR_spe_evlwwsplat
5665 || icode == CODE_FOR_spe_evrlwi
5666 || icode == CODE_FOR_spe_evslwi
5667 || icode == CODE_FOR_spe_evsrwis
f5119d10 5668 || icode == CODE_FOR_spe_evsubifw
0559cc77 5669 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
5670 {
5671 /* Only allow 5-bit unsigned literals. */
8bb418a3 5672 STRIP_NOPS (arg1);
b44140e7
AH
5673 if (TREE_CODE (arg1) != INTEGER_CST
5674 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5675 {
5676 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 5677 return const0_rtx;
b44140e7 5678 }
b44140e7
AH
5679 }
5680
c62f2db5 5681 if (target == 0
0ac081f6
AH
5682 || GET_MODE (target) != tmode
5683 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5684 target = gen_reg_rtx (tmode);
5685
5686 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5687 op0 = copy_to_mode_reg (mode0, op0);
5688 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5689 op1 = copy_to_mode_reg (mode1, op1);
5690
5691 pat = GEN_FCN (icode) (target, op0, op1);
5692 if (! pat)
5693 return 0;
5694 emit_insn (pat);
5695
5696 return target;
5697}
6525c0e7 5698
ae4b4a02 5699static rtx
a2369ed3
DJ
5700altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
5701 tree arglist, rtx target)
ae4b4a02
AH
5702{
5703 rtx pat, scratch;
5704 tree cr6_form = TREE_VALUE (arglist);
5705 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5706 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5707 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5708 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5709 enum machine_mode tmode = SImode;
5710 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5711 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5712 int cr6_form_int;
5713
5714 if (TREE_CODE (cr6_form) != INTEGER_CST)
5715 {
5716 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5717 return const0_rtx;
ae4b4a02
AH
5718 }
5719 else
5720 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5721
5722 if (mode0 != mode1)
5723 abort ();
5724
5725 /* If we have invalid arguments, bail out before generating bad rtl. */
5726 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5727 return const0_rtx;
ae4b4a02
AH
5728
5729 if (target == 0
5730 || GET_MODE (target) != tmode
5731 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5732 target = gen_reg_rtx (tmode);
5733
5734 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5735 op0 = copy_to_mode_reg (mode0, op0);
5736 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5737 op1 = copy_to_mode_reg (mode1, op1);
5738
5739 scratch = gen_reg_rtx (mode0);
5740
5741 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 5742 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
5743 if (! pat)
5744 return 0;
5745 emit_insn (pat);
5746
5747 /* The vec_any* and vec_all* predicates use the same opcodes for two
5748 different operations, but the bits in CR6 will be different
5749 depending on what information we want. So we have to play tricks
5750 with CR6 to get the right bits out.
5751
5752 If you think this is disgusting, look at the specs for the
5753 AltiVec predicates. */
5754
5755 switch (cr6_form_int)
5756 {
5757 case 0:
5758 emit_insn (gen_cr6_test_for_zero (target));
5759 break;
5760 case 1:
5761 emit_insn (gen_cr6_test_for_zero_reverse (target));
5762 break;
5763 case 2:
5764 emit_insn (gen_cr6_test_for_lt (target));
5765 break;
5766 case 3:
5767 emit_insn (gen_cr6_test_for_lt_reverse (target));
5768 break;
5769 default:
5770 error ("argument 1 of __builtin_altivec_predicate is out of range");
5771 break;
5772 }
5773
5774 return target;
5775}
5776
b4a62fa0 5777static rtx
38f391a5 5778altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
5779{
5780 rtx pat, addr;
5781 tree arg0 = TREE_VALUE (arglist);
5782 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5783 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5784 enum machine_mode mode0 = Pmode;
5785 enum machine_mode mode1 = Pmode;
5786 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5787 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5788
5789 if (icode == CODE_FOR_nothing)
5790 /* Builtin not supported on this processor. */
5791 return 0;
5792
5793 /* If we got invalid arguments bail out before generating bad rtl. */
5794 if (arg0 == error_mark_node || arg1 == error_mark_node)
5795 return const0_rtx;
5796
5797 if (target == 0
5798 || GET_MODE (target) != tmode
5799 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5800 target = gen_reg_rtx (tmode);
5801
5802 op1 = copy_to_mode_reg (mode1, op1);
5803
5804 if (op0 == const0_rtx)
5805 {
5806 addr = gen_rtx_MEM (tmode, op1);
5807 }
5808 else
5809 {
5810 op0 = copy_to_mode_reg (mode0, op0);
5811 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
5812 }
5813
5814 pat = GEN_FCN (icode) (target, addr);
5815
5816 if (! pat)
5817 return 0;
5818 emit_insn (pat);
5819
5820 return target;
5821}
5822
6525c0e7 5823static rtx
a2369ed3 5824altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
5825{
5826 tree arg0 = TREE_VALUE (arglist);
5827 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5828 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5829 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5830 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5831 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
5832 rtx pat, addr;
5833 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5834 enum machine_mode mode1 = Pmode;
5835 enum machine_mode mode2 = Pmode;
6525c0e7
AH
5836
5837 /* Invalid arguments. Bail before doing anything stoopid! */
5838 if (arg0 == error_mark_node
5839 || arg1 == error_mark_node
5840 || arg2 == error_mark_node)
9a171fcd 5841 return const0_rtx;
6525c0e7 5842
b4a62fa0
SB
5843 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
5844 op0 = copy_to_mode_reg (tmode, op0);
5845
5846 op2 = copy_to_mode_reg (mode2, op2);
5847
5848 if (op1 == const0_rtx)
5849 {
5850 addr = gen_rtx_MEM (tmode, op2);
5851 }
5852 else
5853 {
5854 op1 = copy_to_mode_reg (mode1, op1);
5855 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
5856 }
6525c0e7 5857
b4a62fa0 5858 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
5859 if (pat)
5860 emit_insn (pat);
5861 return NULL_RTX;
5862}
5863
2212663f 5864static rtx
a2369ed3 5865rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5866{
5867 rtx pat;
5868 tree arg0 = TREE_VALUE (arglist);
5869 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5870 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5871 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5872 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5873 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5874 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5875 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5876 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5877 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 5878
774b5662
DE
5879 if (icode == CODE_FOR_nothing)
5880 /* Builtin not supported on this processor. */
5881 return 0;
5882
20e26713
AH
5883 /* If we got invalid arguments bail out before generating bad rtl. */
5884 if (arg0 == error_mark_node
5885 || arg1 == error_mark_node
5886 || arg2 == error_mark_node)
9a171fcd 5887 return const0_rtx;
20e26713 5888
774b5662
DE
5889 if (icode == CODE_FOR_altivec_vsldoi_4sf
5890 || icode == CODE_FOR_altivec_vsldoi_4si
5891 || icode == CODE_FOR_altivec_vsldoi_8hi
5892 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
5893 {
5894 /* Only allow 4-bit unsigned literals. */
8bb418a3 5895 STRIP_NOPS (arg2);
b44140e7
AH
5896 if (TREE_CODE (arg2) != INTEGER_CST
5897 || TREE_INT_CST_LOW (arg2) & ~0xf)
5898 {
5899 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 5900 return const0_rtx;
b44140e7 5901 }
b44140e7
AH
5902 }
5903
c62f2db5 5904 if (target == 0
2212663f
DB
5905 || GET_MODE (target) != tmode
5906 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5907 target = gen_reg_rtx (tmode);
5908
5909 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5910 op0 = copy_to_mode_reg (mode0, op0);
5911 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5912 op1 = copy_to_mode_reg (mode1, op1);
5913 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
5914 op2 = copy_to_mode_reg (mode2, op2);
5915
5916 pat = GEN_FCN (icode) (target, op0, op1, op2);
5917 if (! pat)
5918 return 0;
5919 emit_insn (pat);
5920
5921 return target;
5922}
92898235 5923
3a9b8c7e 5924/* Expand the lvx builtins. */
0ac081f6 5925static rtx
a2369ed3 5926altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 5927{
0ac081f6
AH
5928 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5929 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 5930 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
5931 tree arg0;
5932 enum machine_mode tmode, mode0;
7c3abc73 5933 rtx pat, op0;
3a9b8c7e 5934 enum insn_code icode;
92898235 5935
0ac081f6
AH
5936 switch (fcode)
5937 {
f18c054f
DB
5938 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
5939 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 5940 break;
f18c054f
DB
5941 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
5942 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
5943 break;
5944 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
5945 icode = CODE_FOR_altivec_lvx_4si;
5946 break;
5947 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
5948 icode = CODE_FOR_altivec_lvx_4sf;
5949 break;
5950 default:
5951 *expandedp = false;
5952 return NULL_RTX;
5953 }
0ac081f6 5954
3a9b8c7e 5955 *expandedp = true;
f18c054f 5956
3a9b8c7e
AH
5957 arg0 = TREE_VALUE (arglist);
5958 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5959 tmode = insn_data[icode].operand[0].mode;
5960 mode0 = insn_data[icode].operand[1].mode;
f18c054f 5961
3a9b8c7e
AH
5962 if (target == 0
5963 || GET_MODE (target) != tmode
5964 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5965 target = gen_reg_rtx (tmode);
24408032 5966
3a9b8c7e
AH
5967 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5968 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 5969
3a9b8c7e
AH
5970 pat = GEN_FCN (icode) (target, op0);
5971 if (! pat)
5972 return 0;
5973 emit_insn (pat);
5974 return target;
5975}
f18c054f 5976
3a9b8c7e
AH
5977/* Expand the stvx builtins. */
5978static rtx
a2369ed3
DJ
5979altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5980 bool *expandedp)
3a9b8c7e
AH
5981{
5982 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5983 tree arglist = TREE_OPERAND (exp, 1);
5984 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5985 tree arg0, arg1;
5986 enum machine_mode mode0, mode1;
7c3abc73 5987 rtx pat, op0, op1;
3a9b8c7e 5988 enum insn_code icode;
f18c054f 5989
3a9b8c7e
AH
5990 switch (fcode)
5991 {
5992 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
5993 icode = CODE_FOR_altivec_stvx_16qi;
5994 break;
5995 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
5996 icode = CODE_FOR_altivec_stvx_8hi;
5997 break;
5998 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
5999 icode = CODE_FOR_altivec_stvx_4si;
6000 break;
6001 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
6002 icode = CODE_FOR_altivec_stvx_4sf;
6003 break;
6004 default:
6005 *expandedp = false;
6006 return NULL_RTX;
6007 }
24408032 6008
3a9b8c7e
AH
6009 arg0 = TREE_VALUE (arglist);
6010 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6011 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6012 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6013 mode0 = insn_data[icode].operand[0].mode;
6014 mode1 = insn_data[icode].operand[1].mode;
f18c054f 6015
3a9b8c7e
AH
6016 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6017 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
6018 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6019 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 6020
3a9b8c7e
AH
6021 pat = GEN_FCN (icode) (op0, op1);
6022 if (pat)
6023 emit_insn (pat);
f18c054f 6024
3a9b8c7e
AH
6025 *expandedp = true;
6026 return NULL_RTX;
6027}
f18c054f 6028
3a9b8c7e
AH
6029/* Expand the dst builtins. */
6030static rtx
a2369ed3
DJ
6031altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
6032 bool *expandedp)
3a9b8c7e
AH
6033{
6034 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6035 tree arglist = TREE_OPERAND (exp, 1);
6036 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6037 tree arg0, arg1, arg2;
6038 enum machine_mode mode0, mode1, mode2;
7c3abc73 6039 rtx pat, op0, op1, op2;
3a9b8c7e 6040 struct builtin_description *d;
a3170dc6 6041 size_t i;
f18c054f 6042
3a9b8c7e 6043 *expandedp = false;
f18c054f 6044
3a9b8c7e
AH
6045 /* Handle DST variants. */
6046 d = (struct builtin_description *) bdesc_dst;
6047 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
6048 if (d->code == fcode)
6049 {
6050 arg0 = TREE_VALUE (arglist);
6051 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6052 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6053 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6054 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6055 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6056 mode0 = insn_data[d->icode].operand[0].mode;
6057 mode1 = insn_data[d->icode].operand[1].mode;
6058 mode2 = insn_data[d->icode].operand[2].mode;
24408032 6059
3a9b8c7e
AH
6060 /* Invalid arguments, bail out before generating bad rtl. */
6061 if (arg0 == error_mark_node
6062 || arg1 == error_mark_node
6063 || arg2 == error_mark_node)
6064 return const0_rtx;
f18c054f 6065
86e7df90 6066 *expandedp = true;
8bb418a3 6067 STRIP_NOPS (arg2);
3a9b8c7e
AH
6068 if (TREE_CODE (arg2) != INTEGER_CST
6069 || TREE_INT_CST_LOW (arg2) & ~0x3)
6070 {
6071 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
6072 return const0_rtx;
6073 }
f18c054f 6074
3a9b8c7e 6075 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 6076 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
6077 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
6078 op1 = copy_to_mode_reg (mode1, op1);
24408032 6079
3a9b8c7e
AH
6080 pat = GEN_FCN (d->icode) (op0, op1, op2);
6081 if (pat != 0)
6082 emit_insn (pat);
f18c054f 6083
3a9b8c7e
AH
6084 return NULL_RTX;
6085 }
f18c054f 6086
3a9b8c7e
AH
6087 return NULL_RTX;
6088}
24408032 6089
3a9b8c7e
AH
6090/* Expand the builtin in EXP and store the result in TARGET. Store
6091 true in *EXPANDEDP if we found a builtin to expand. */
6092static rtx
a2369ed3 6093altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
6094{
6095 struct builtin_description *d;
6096 struct builtin_description_predicates *dp;
6097 size_t i;
6098 enum insn_code icode;
6099 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6100 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
6101 tree arg0;
6102 rtx op0, pat;
6103 enum machine_mode tmode, mode0;
3a9b8c7e 6104 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 6105
3a9b8c7e
AH
6106 target = altivec_expand_ld_builtin (exp, target, expandedp);
6107 if (*expandedp)
6108 return target;
0ac081f6 6109
3a9b8c7e
AH
6110 target = altivec_expand_st_builtin (exp, target, expandedp);
6111 if (*expandedp)
6112 return target;
6113
6114 target = altivec_expand_dst_builtin (exp, target, expandedp);
6115 if (*expandedp)
6116 return target;
6117
6118 *expandedp = true;
95385cbb 6119
3a9b8c7e
AH
6120 switch (fcode)
6121 {
6525c0e7
AH
6122 case ALTIVEC_BUILTIN_STVX:
6123 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
6124 case ALTIVEC_BUILTIN_STVEBX:
6125 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
6126 case ALTIVEC_BUILTIN_STVEHX:
6127 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
6128 case ALTIVEC_BUILTIN_STVEWX:
6129 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
6130 case ALTIVEC_BUILTIN_STVXL:
6131 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 6132
95385cbb
AH
6133 case ALTIVEC_BUILTIN_MFVSCR:
6134 icode = CODE_FOR_altivec_mfvscr;
6135 tmode = insn_data[icode].operand[0].mode;
6136
6137 if (target == 0
6138 || GET_MODE (target) != tmode
6139 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6140 target = gen_reg_rtx (tmode);
6141
6142 pat = GEN_FCN (icode) (target);
0ac081f6
AH
6143 if (! pat)
6144 return 0;
6145 emit_insn (pat);
95385cbb
AH
6146 return target;
6147
6148 case ALTIVEC_BUILTIN_MTVSCR:
6149 icode = CODE_FOR_altivec_mtvscr;
6150 arg0 = TREE_VALUE (arglist);
6151 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6152 mode0 = insn_data[icode].operand[0].mode;
6153
6154 /* If we got invalid arguments bail out before generating bad rtl. */
6155 if (arg0 == error_mark_node)
9a171fcd 6156 return const0_rtx;
95385cbb
AH
6157
6158 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6159 op0 = copy_to_mode_reg (mode0, op0);
6160
6161 pat = GEN_FCN (icode) (op0);
6162 if (pat)
6163 emit_insn (pat);
6164 return NULL_RTX;
3a9b8c7e 6165
95385cbb
AH
6166 case ALTIVEC_BUILTIN_DSSALL:
6167 emit_insn (gen_altivec_dssall ());
6168 return NULL_RTX;
6169
6170 case ALTIVEC_BUILTIN_DSS:
6171 icode = CODE_FOR_altivec_dss;
6172 arg0 = TREE_VALUE (arglist);
8bb418a3 6173 STRIP_NOPS (arg0);
95385cbb
AH
6174 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6175 mode0 = insn_data[icode].operand[0].mode;
6176
6177 /* If we got invalid arguments bail out before generating bad rtl. */
6178 if (arg0 == error_mark_node)
9a171fcd 6179 return const0_rtx;
95385cbb 6180
b44140e7
AH
6181 if (TREE_CODE (arg0) != INTEGER_CST
6182 || TREE_INT_CST_LOW (arg0) & ~0x3)
6183 {
6184 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6185 return const0_rtx;
b44140e7
AH
6186 }
6187
95385cbb
AH
6188 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6189 op0 = copy_to_mode_reg (mode0, op0);
6190
6191 emit_insn (gen_altivec_dss (op0));
0ac081f6 6192 return NULL_RTX;
8bb418a3
ZL
6193
6194 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
6195 arg0 = TREE_VALUE (arglist);
6196 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR)
6197 arg0 = TREE_OPERAND (arg0, 0);
6198 error ("invalid parameter combination for `%s' AltiVec intrinsic",
6199 TREE_STRING_POINTER (arg0));
6200
6201 return const0_rtx;
0ac081f6 6202 }
24408032 6203
100c4561
AH
6204 /* Expand abs* operations. */
6205 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6206 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6207 if (d->code == fcode)
6208 return altivec_expand_abs_builtin (d->icode, arglist, target);
6209
ae4b4a02
AH
6210 /* Expand the AltiVec predicates. */
6211 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6212 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
6213 if (dp->code == fcode)
6214 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
6215
6525c0e7
AH
6216 /* LV* are funky. We initialized them differently. */
6217 switch (fcode)
6218 {
6219 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6220 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
6221 arglist, target);
6222 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6223 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
92898235 6224 arglist, target);
6525c0e7 6225 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6226 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
92898235 6227 arglist, target);
6525c0e7 6228 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6229 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
92898235 6230 arglist, target);
6525c0e7 6231 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6232 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
92898235 6233 arglist, target);
6525c0e7 6234 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6235 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
92898235 6236 arglist, target);
6525c0e7 6237 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6238 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
92898235 6239 arglist, target);
6525c0e7
AH
6240 default:
6241 break;
6242 /* Fall through. */
6243 }
95385cbb 6244
92898235 6245 *expandedp = false;
0ac081f6
AH
6246 return NULL_RTX;
6247}
6248
a3170dc6
AH
6249/* Binops that need to be initialized manually, but can be expanded
6250 automagically by rs6000_expand_binop_builtin. */
6251static struct builtin_description bdesc_2arg_spe[] =
6252{
6253 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6254 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6255 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6256 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6257 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6258 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6259 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6260 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6261 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6262 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6263 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6264 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6265 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6266 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6267 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6268 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6269 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6270 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6271 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6272 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6273 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6274 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6275};
6276
6277/* Expand the builtin in EXP and store the result in TARGET. Store
6278 true in *EXPANDEDP if we found a builtin to expand.
6279
6280 This expands the SPE builtins that are not simple unary and binary
6281 operations. */
6282static rtx
a2369ed3 6283spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6284{
6285 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6286 tree arglist = TREE_OPERAND (exp, 1);
6287 tree arg1, arg0;
6288 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6289 enum insn_code icode;
6290 enum machine_mode tmode, mode0;
6291 rtx pat, op0;
6292 struct builtin_description *d;
6293 size_t i;
6294
6295 *expandedp = true;
6296
6297 /* Syntax check for a 5-bit unsigned immediate. */
6298 switch (fcode)
6299 {
6300 case SPE_BUILTIN_EVSTDD:
6301 case SPE_BUILTIN_EVSTDH:
6302 case SPE_BUILTIN_EVSTDW:
6303 case SPE_BUILTIN_EVSTWHE:
6304 case SPE_BUILTIN_EVSTWHO:
6305 case SPE_BUILTIN_EVSTWWE:
6306 case SPE_BUILTIN_EVSTWWO:
6307 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6308 if (TREE_CODE (arg1) != INTEGER_CST
6309 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6310 {
6311 error ("argument 2 must be a 5-bit unsigned literal");
6312 return const0_rtx;
6313 }
6314 break;
6315 default:
6316 break;
6317 }
6318
00332c9f
AH
6319 /* The evsplat*i instructions are not quite generic. */
6320 switch (fcode)
6321 {
6322 case SPE_BUILTIN_EVSPLATFI:
6323 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6324 arglist, target);
6325 case SPE_BUILTIN_EVSPLATI:
6326 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
6327 arglist, target);
6328 default:
6329 break;
6330 }
6331
a3170dc6
AH
6332 d = (struct builtin_description *) bdesc_2arg_spe;
6333 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
6334 if (d->code == fcode)
6335 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6336
6337 d = (struct builtin_description *) bdesc_spe_predicates;
6338 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
6339 if (d->code == fcode)
6340 return spe_expand_predicate_builtin (d->icode, arglist, target);
6341
6342 d = (struct builtin_description *) bdesc_spe_evsel;
6343 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
6344 if (d->code == fcode)
6345 return spe_expand_evsel_builtin (d->icode, arglist, target);
6346
6347 switch (fcode)
6348 {
6349 case SPE_BUILTIN_EVSTDDX:
6350 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
6351 case SPE_BUILTIN_EVSTDHX:
6352 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
6353 case SPE_BUILTIN_EVSTDWX:
6354 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
6355 case SPE_BUILTIN_EVSTWHEX:
6356 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
6357 case SPE_BUILTIN_EVSTWHOX:
6358 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
6359 case SPE_BUILTIN_EVSTWWEX:
6360 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
6361 case SPE_BUILTIN_EVSTWWOX:
6362 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
6363 case SPE_BUILTIN_EVSTDD:
6364 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
6365 case SPE_BUILTIN_EVSTDH:
6366 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
6367 case SPE_BUILTIN_EVSTDW:
6368 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
6369 case SPE_BUILTIN_EVSTWHE:
6370 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
6371 case SPE_BUILTIN_EVSTWHO:
6372 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
6373 case SPE_BUILTIN_EVSTWWE:
6374 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
6375 case SPE_BUILTIN_EVSTWWO:
6376 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
6377 case SPE_BUILTIN_MFSPEFSCR:
6378 icode = CODE_FOR_spe_mfspefscr;
6379 tmode = insn_data[icode].operand[0].mode;
6380
6381 if (target == 0
6382 || GET_MODE (target) != tmode
6383 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6384 target = gen_reg_rtx (tmode);
6385
6386 pat = GEN_FCN (icode) (target);
6387 if (! pat)
6388 return 0;
6389 emit_insn (pat);
6390 return target;
6391 case SPE_BUILTIN_MTSPEFSCR:
6392 icode = CODE_FOR_spe_mtspefscr;
6393 arg0 = TREE_VALUE (arglist);
6394 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6395 mode0 = insn_data[icode].operand[0].mode;
6396
6397 if (arg0 == error_mark_node)
6398 return const0_rtx;
6399
6400 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6401 op0 = copy_to_mode_reg (mode0, op0);
6402
6403 pat = GEN_FCN (icode) (op0);
6404 if (pat)
6405 emit_insn (pat);
6406 return NULL_RTX;
6407 default:
6408 break;
6409 }
6410
6411 *expandedp = false;
6412 return NULL_RTX;
6413}
6414
6415static rtx
a2369ed3 6416spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6417{
6418 rtx pat, scratch, tmp;
6419 tree form = TREE_VALUE (arglist);
6420 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6421 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6422 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6423 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6424 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6425 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6426 int form_int;
6427 enum rtx_code code;
6428
6429 if (TREE_CODE (form) != INTEGER_CST)
6430 {
6431 error ("argument 1 of __builtin_spe_predicate must be a constant");
6432 return const0_rtx;
6433 }
6434 else
6435 form_int = TREE_INT_CST_LOW (form);
6436
6437 if (mode0 != mode1)
6438 abort ();
6439
6440 if (arg0 == error_mark_node || arg1 == error_mark_node)
6441 return const0_rtx;
6442
6443 if (target == 0
6444 || GET_MODE (target) != SImode
6445 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
6446 target = gen_reg_rtx (SImode);
6447
6448 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6449 op0 = copy_to_mode_reg (mode0, op0);
6450 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6451 op1 = copy_to_mode_reg (mode1, op1);
6452
6453 scratch = gen_reg_rtx (CCmode);
6454
6455 pat = GEN_FCN (icode) (scratch, op0, op1);
6456 if (! pat)
6457 return const0_rtx;
6458 emit_insn (pat);
6459
6460 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
6461 _lower_. We use one compare, but look in different bits of the
6462 CR for each variant.
6463
6464 There are 2 elements in each SPE simd type (upper/lower). The CR
6465 bits are set as follows:
6466
6467 BIT0 | BIT 1 | BIT 2 | BIT 3
6468 U | L | (U | L) | (U & L)
6469
6470 So, for an "all" relationship, BIT 3 would be set.
6471 For an "any" relationship, BIT 2 would be set. Etc.
6472
6473 Following traditional nomenclature, these bits map to:
6474
6475 BIT0 | BIT 1 | BIT 2 | BIT 3
6476 LT | GT | EQ | OV
6477
6478 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
6479 */
6480
6481 switch (form_int)
6482 {
6483 /* All variant. OV bit. */
6484 case 0:
6485 /* We need to get to the OV bit, which is the ORDERED bit. We
6486 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
6487 that's ugly and will trigger a validate_condition_mode abort.
6488 So let's just use another pattern. */
6489 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
6490 return target;
6491 /* Any variant. EQ bit. */
6492 case 1:
6493 code = EQ;
6494 break;
6495 /* Upper variant. LT bit. */
6496 case 2:
6497 code = LT;
6498 break;
6499 /* Lower variant. GT bit. */
6500 case 3:
6501 code = GT;
6502 break;
6503 default:
6504 error ("argument 1 of __builtin_spe_predicate is out of range");
6505 return const0_rtx;
6506 }
6507
6508 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
6509 emit_move_insn (target, tmp);
6510
6511 return target;
6512}
6513
6514/* The evsel builtins look like this:
6515
6516 e = __builtin_spe_evsel_OP (a, b, c, d);
6517
6518 and work like this:
6519
6520 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
6521 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
6522*/
6523
6524static rtx
a2369ed3 6525spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6526{
6527 rtx pat, scratch;
6528 tree arg0 = TREE_VALUE (arglist);
6529 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6530 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6531 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
6532 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6533 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6534 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6535 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
6536 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6537 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6538
6539 if (mode0 != mode1)
6540 abort ();
6541
6542 if (arg0 == error_mark_node || arg1 == error_mark_node
6543 || arg2 == error_mark_node || arg3 == error_mark_node)
6544 return const0_rtx;
6545
6546 if (target == 0
6547 || GET_MODE (target) != mode0
6548 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
6549 target = gen_reg_rtx (mode0);
6550
6551 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6552 op0 = copy_to_mode_reg (mode0, op0);
6553 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6554 op1 = copy_to_mode_reg (mode0, op1);
6555 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6556 op2 = copy_to_mode_reg (mode0, op2);
6557 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
6558 op3 = copy_to_mode_reg (mode0, op3);
6559
6560 /* Generate the compare. */
6561 scratch = gen_reg_rtx (CCmode);
6562 pat = GEN_FCN (icode) (scratch, op0, op1);
6563 if (! pat)
6564 return const0_rtx;
6565 emit_insn (pat);
6566
6567 if (mode0 == V2SImode)
6568 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
6569 else
6570 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
6571
6572 return target;
6573}
6574
0ac081f6
AH
6575/* Expand an expression EXP that calls a built-in function,
6576 with result going to TARGET if that's convenient
6577 (and in mode MODE if that's convenient).
6578 SUBTARGET may be used as the target for computing one of EXP's operands.
6579 IGNORE is nonzero if the value is to be ignored. */
6580
6581static rtx
a2369ed3
DJ
6582rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
6583 enum machine_mode mode ATTRIBUTE_UNUSED,
6584 int ignore ATTRIBUTE_UNUSED)
0ac081f6 6585{
92898235
AH
6586 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6587 tree arglist = TREE_OPERAND (exp, 1);
6588 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6589 struct builtin_description *d;
6590 size_t i;
6591 rtx ret;
6592 bool success;
6593
0ac081f6 6594 if (TARGET_ALTIVEC)
92898235
AH
6595 {
6596 ret = altivec_expand_builtin (exp, target, &success);
6597
a3170dc6
AH
6598 if (success)
6599 return ret;
6600 }
6601 if (TARGET_SPE)
6602 {
6603 ret = spe_expand_builtin (exp, target, &success);
6604
92898235
AH
6605 if (success)
6606 return ret;
6607 }
6608
0559cc77
DE
6609 if (TARGET_ALTIVEC || TARGET_SPE)
6610 {
6611 /* Handle simple unary operations. */
6612 d = (struct builtin_description *) bdesc_1arg;
6613 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
6614 if (d->code == fcode)
6615 return rs6000_expand_unop_builtin (d->icode, arglist, target);
6616
6617 /* Handle simple binary operations. */
6618 d = (struct builtin_description *) bdesc_2arg;
6619 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
6620 if (d->code == fcode)
6621 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6622
6623 /* Handle simple ternary operations. */
6624 d = (struct builtin_description *) bdesc_3arg;
6625 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
6626 if (d->code == fcode)
6627 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
6628 }
0ac081f6
AH
6629
6630 abort ();
92898235 6631 return NULL_RTX;
0ac081f6
AH
6632}
6633
6634static void
863d938c 6635rs6000_init_builtins (void)
0ac081f6 6636{
4a5eab38
PB
6637 V2SI_type_node = build_vector_type (intSI_type_node, 2);
6638 V2SF_type_node = build_vector_type (float_type_node, 2);
6639 V4HI_type_node = build_vector_type (intHI_type_node, 4);
6640 V4SI_type_node = build_vector_type (intSI_type_node, 4);
6641 V4SF_type_node = build_vector_type (float_type_node, 4);
7e463bda 6642 V8HI_type_node = build_vector_type (intHI_type_node, 8);
4a5eab38
PB
6643 V16QI_type_node = build_vector_type (intQI_type_node, 16);
6644
6645 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
6646 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
6647 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
6648
3fdaa45a
AH
6649 opaque_V2SI_type_node = copy_node (V2SI_type_node);
6650 opaque_V2SF_type_node = copy_node (V2SF_type_node);
6035d635 6651 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 6652
8bb418a3
ZL
6653 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
6654 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
6655 'vector unsigned short'. */
6656
6657 bool_char_type_node = copy_node (unsigned_intQI_type_node);
6658 TYPE_MAIN_VARIANT (bool_char_type_node) = bool_char_type_node;
6659 bool_short_type_node = copy_node (unsigned_intHI_type_node);
6660 TYPE_MAIN_VARIANT (bool_short_type_node) = bool_short_type_node;
6661 bool_int_type_node = copy_node (unsigned_intSI_type_node);
6662 TYPE_MAIN_VARIANT (bool_int_type_node) = bool_int_type_node;
6663 pixel_type_node = copy_node (unsigned_intHI_type_node);
6664 TYPE_MAIN_VARIANT (pixel_type_node) = pixel_type_node;
6665
6666 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6667 get_identifier ("__bool char"),
6668 bool_char_type_node));
6669 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6670 get_identifier ("__bool short"),
6671 bool_short_type_node));
6672 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6673 get_identifier ("__bool int"),
6674 bool_int_type_node));
6675 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6676 get_identifier ("__pixel"),
6677 pixel_type_node));
6678
4a5eab38
PB
6679 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
6680 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
6681 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
6682 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
8bb418a3
ZL
6683
6684 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6685 get_identifier ("__vector unsigned char"),
6686 unsigned_V16QI_type_node));
6687 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6688 get_identifier ("__vector signed char"),
6689 V16QI_type_node));
6690 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6691 get_identifier ("__vector __bool char"),
6692 bool_V16QI_type_node));
6693
6694 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6695 get_identifier ("__vector unsigned short"),
6696 unsigned_V8HI_type_node));
6697 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6698 get_identifier ("__vector signed short"),
6699 V8HI_type_node));
6700 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6701 get_identifier ("__vector __bool short"),
6702 bool_V8HI_type_node));
6703
6704 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6705 get_identifier ("__vector unsigned int"),
6706 unsigned_V4SI_type_node));
6707 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6708 get_identifier ("__vector signed int"),
6709 V4SI_type_node));
6710 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6711 get_identifier ("__vector __bool int"),
6712 bool_V4SI_type_node));
6713
6714 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6715 get_identifier ("__vector float"),
6716 V4SF_type_node));
6717 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6718 get_identifier ("__vector __pixel"),
6719 pixel_V8HI_type_node));
6720
a3170dc6 6721 if (TARGET_SPE)
3fdaa45a 6722 spe_init_builtins ();
0ac081f6
AH
6723 if (TARGET_ALTIVEC)
6724 altivec_init_builtins ();
0559cc77
DE
6725 if (TARGET_ALTIVEC || TARGET_SPE)
6726 rs6000_common_init_builtins ();
0ac081f6
AH
6727}
6728
a3170dc6
AH
6729/* Search through a set of builtins and enable the mask bits.
6730 DESC is an array of builtins.
b6d08ca1 6731 SIZE is the total number of builtins.
a3170dc6
AH
6732 START is the builtin enum at which to start.
6733 END is the builtin enum at which to end. */
0ac081f6 6734static void
a2369ed3
DJ
6735enable_mask_for_builtins (struct builtin_description *desc, int size,
6736 enum rs6000_builtins start,
6737 enum rs6000_builtins end)
a3170dc6
AH
6738{
6739 int i;
6740
6741 for (i = 0; i < size; ++i)
6742 if (desc[i].code == start)
6743 break;
6744
6745 if (i == size)
6746 return;
6747
6748 for (; i < size; ++i)
6749 {
6750 /* Flip all the bits on. */
6751 desc[i].mask = target_flags;
6752 if (desc[i].code == end)
6753 break;
6754 }
6755}
6756
6757static void
863d938c 6758spe_init_builtins (void)
0ac081f6 6759{
a3170dc6
AH
6760 tree endlink = void_list_node;
6761 tree puint_type_node = build_pointer_type (unsigned_type_node);
6762 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 6763 struct builtin_description *d;
0ac081f6
AH
6764 size_t i;
6765
a3170dc6
AH
6766 tree v2si_ftype_4_v2si
6767 = build_function_type
3fdaa45a
AH
6768 (opaque_V2SI_type_node,
6769 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6770 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6771 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6772 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6773 endlink)))));
6774
6775 tree v2sf_ftype_4_v2sf
6776 = build_function_type
3fdaa45a
AH
6777 (opaque_V2SF_type_node,
6778 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6779 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6780 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6781 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6782 endlink)))));
6783
6784 tree int_ftype_int_v2si_v2si
6785 = build_function_type
6786 (integer_type_node,
6787 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6788 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6789 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6790 endlink))));
6791
6792 tree int_ftype_int_v2sf_v2sf
6793 = build_function_type
6794 (integer_type_node,
6795 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6796 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6797 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6798 endlink))));
6799
6800 tree void_ftype_v2si_puint_int
6801 = build_function_type (void_type_node,
3fdaa45a 6802 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6803 tree_cons (NULL_TREE, puint_type_node,
6804 tree_cons (NULL_TREE,
6805 integer_type_node,
6806 endlink))));
6807
6808 tree void_ftype_v2si_puint_char
6809 = build_function_type (void_type_node,
3fdaa45a 6810 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6811 tree_cons (NULL_TREE, puint_type_node,
6812 tree_cons (NULL_TREE,
6813 char_type_node,
6814 endlink))));
6815
6816 tree void_ftype_v2si_pv2si_int
6817 = build_function_type (void_type_node,
3fdaa45a 6818 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6819 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6820 tree_cons (NULL_TREE,
6821 integer_type_node,
6822 endlink))));
6823
6824 tree void_ftype_v2si_pv2si_char
6825 = build_function_type (void_type_node,
3fdaa45a 6826 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6827 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6828 tree_cons (NULL_TREE,
6829 char_type_node,
6830 endlink))));
6831
6832 tree void_ftype_int
6833 = build_function_type (void_type_node,
6834 tree_cons (NULL_TREE, integer_type_node, endlink));
6835
6836 tree int_ftype_void
36e8d515 6837 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
6838
6839 tree v2si_ftype_pv2si_int
3fdaa45a 6840 = build_function_type (opaque_V2SI_type_node,
6035d635 6841 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6842 tree_cons (NULL_TREE, integer_type_node,
6843 endlink)));
6844
6845 tree v2si_ftype_puint_int
3fdaa45a 6846 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6847 tree_cons (NULL_TREE, puint_type_node,
6848 tree_cons (NULL_TREE, integer_type_node,
6849 endlink)));
6850
6851 tree v2si_ftype_pushort_int
3fdaa45a 6852 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6853 tree_cons (NULL_TREE, pushort_type_node,
6854 tree_cons (NULL_TREE, integer_type_node,
6855 endlink)));
6856
00332c9f
AH
6857 tree v2si_ftype_signed_char
6858 = build_function_type (opaque_V2SI_type_node,
6859 tree_cons (NULL_TREE, signed_char_type_node,
6860 endlink));
6861
a3170dc6
AH
6862 /* The initialization of the simple binary and unary builtins is
6863 done in rs6000_common_init_builtins, but we have to enable the
6864 mask bits here manually because we have run out of `target_flags'
6865 bits. We really need to redesign this mask business. */
6866
6867 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
6868 ARRAY_SIZE (bdesc_2arg),
6869 SPE_BUILTIN_EVADDW,
6870 SPE_BUILTIN_EVXOR);
6871 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
6872 ARRAY_SIZE (bdesc_1arg),
6873 SPE_BUILTIN_EVABS,
6874 SPE_BUILTIN_EVSUBFUSIAAW);
6875 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
6876 ARRAY_SIZE (bdesc_spe_predicates),
6877 SPE_BUILTIN_EVCMPEQ,
6878 SPE_BUILTIN_EVFSTSTLT);
6879 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
6880 ARRAY_SIZE (bdesc_spe_evsel),
6881 SPE_BUILTIN_EVSEL_CMPGTS,
6882 SPE_BUILTIN_EVSEL_FSTSTEQ);
6883
36252949
AH
6884 (*lang_hooks.decls.pushdecl)
6885 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
6886 opaque_V2SI_type_node));
6887
a3170dc6
AH
6888 /* Initialize irregular SPE builtins. */
6889
6890 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
6891 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
6892 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
6893 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
6894 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
6895 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
6896 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
6897 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
6898 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
6899 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
6900 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
6901 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
6902 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
6903 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
6904 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
6905 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
6906 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
6907 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
6908
6909 /* Loads. */
6910 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
6911 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
6912 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
6913 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
6914 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
6915 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
6916 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
6917 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
6918 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
6919 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
6920 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
6921 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
6922 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
6923 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
6924 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
6925 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
6926 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
6927 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
6928 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
6929 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
6930 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
6931 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
6932
6933 /* Predicates. */
6934 d = (struct builtin_description *) bdesc_spe_predicates;
6935 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
6936 {
6937 tree type;
6938
6939 switch (insn_data[d->icode].operand[1].mode)
6940 {
6941 case V2SImode:
6942 type = int_ftype_int_v2si_v2si;
6943 break;
6944 case V2SFmode:
6945 type = int_ftype_int_v2sf_v2sf;
6946 break;
6947 default:
6948 abort ();
6949 }
6950
6951 def_builtin (d->mask, d->name, type, d->code);
6952 }
6953
6954 /* Evsel predicates. */
6955 d = (struct builtin_description *) bdesc_spe_evsel;
6956 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
6957 {
6958 tree type;
6959
6960 switch (insn_data[d->icode].operand[1].mode)
6961 {
6962 case V2SImode:
6963 type = v2si_ftype_4_v2si;
6964 break;
6965 case V2SFmode:
6966 type = v2sf_ftype_4_v2sf;
6967 break;
6968 default:
6969 abort ();
6970 }
6971
6972 def_builtin (d->mask, d->name, type, d->code);
6973 }
6974}
6975
6976static void
863d938c 6977altivec_init_builtins (void)
a3170dc6
AH
6978{
6979 struct builtin_description *d;
6980 struct builtin_description_predicates *dp;
6981 size_t i;
6982 tree pfloat_type_node = build_pointer_type (float_type_node);
6983 tree pint_type_node = build_pointer_type (integer_type_node);
6984 tree pshort_type_node = build_pointer_type (short_integer_type_node);
6985 tree pchar_type_node = build_pointer_type (char_type_node);
6986
6987 tree pvoid_type_node = build_pointer_type (void_type_node);
6988
0dbc3651
ZW
6989 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
6990 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
6991 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
6992 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
6993
6994 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
6995
a3170dc6
AH
6996 tree int_ftype_int_v4si_v4si
6997 = build_function_type_list (integer_type_node,
6998 integer_type_node, V4SI_type_node,
6999 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7000 tree v4sf_ftype_pcfloat
7001 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 7002 tree void_ftype_pfloat_v4sf
b4de2f7d 7003 = build_function_type_list (void_type_node,
a3170dc6 7004 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
7005 tree v4si_ftype_pcint
7006 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
7007 tree void_ftype_pint_v4si
b4de2f7d
AH
7008 = build_function_type_list (void_type_node,
7009 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7010 tree v8hi_ftype_pcshort
7011 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 7012 tree void_ftype_pshort_v8hi
b4de2f7d
AH
7013 = build_function_type_list (void_type_node,
7014 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
7015 tree v16qi_ftype_pcchar
7016 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 7017 tree void_ftype_pchar_v16qi
b4de2f7d
AH
7018 = build_function_type_list (void_type_node,
7019 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 7020 tree void_ftype_v4si
b4de2f7d 7021 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7022 tree v8hi_ftype_void
7023 = build_function_type (V8HI_type_node, void_list_node);
7024 tree void_ftype_void
7025 = build_function_type (void_type_node, void_list_node);
7026 tree void_ftype_qi
7027 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651 7028
b4a62fa0 7029 tree v16qi_ftype_long_pcvoid
a3170dc6 7030 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
7031 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7032 tree v8hi_ftype_long_pcvoid
a3170dc6 7033 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
7034 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7035 tree v4si_ftype_long_pcvoid
a3170dc6 7036 = build_function_type_list (V4SI_type_node,
b4a62fa0 7037 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 7038
b4a62fa0 7039 tree void_ftype_v4si_long_pvoid
b4de2f7d 7040 = build_function_type_list (void_type_node,
b4a62fa0 7041 V4SI_type_node, long_integer_type_node,
b4de2f7d 7042 pvoid_type_node, NULL_TREE);
b4a62fa0 7043 tree void_ftype_v16qi_long_pvoid
b4de2f7d 7044 = build_function_type_list (void_type_node,
b4a62fa0 7045 V16QI_type_node, long_integer_type_node,
b4de2f7d 7046 pvoid_type_node, NULL_TREE);
b4a62fa0 7047 tree void_ftype_v8hi_long_pvoid
b4de2f7d 7048 = build_function_type_list (void_type_node,
b4a62fa0 7049 V8HI_type_node, long_integer_type_node,
b4de2f7d 7050 pvoid_type_node, NULL_TREE);
a3170dc6
AH
7051 tree int_ftype_int_v8hi_v8hi
7052 = build_function_type_list (integer_type_node,
7053 integer_type_node, V8HI_type_node,
7054 V8HI_type_node, NULL_TREE);
7055 tree int_ftype_int_v16qi_v16qi
7056 = build_function_type_list (integer_type_node,
7057 integer_type_node, V16QI_type_node,
7058 V16QI_type_node, NULL_TREE);
7059 tree int_ftype_int_v4sf_v4sf
7060 = build_function_type_list (integer_type_node,
7061 integer_type_node, V4SF_type_node,
7062 V4SF_type_node, NULL_TREE);
7063 tree v4si_ftype_v4si
7064 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
7065 tree v8hi_ftype_v8hi
7066 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
7067 tree v16qi_ftype_v16qi
7068 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
7069 tree v4sf_ftype_v4sf
7070 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 7071 tree void_ftype_pcvoid_int_int
a3170dc6 7072 = build_function_type_list (void_type_node,
0dbc3651 7073 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
7074 integer_type_node, NULL_TREE);
7075 tree int_ftype_pcchar
7076 = build_function_type_list (integer_type_node,
7077 pcchar_type_node, NULL_TREE);
7078
0dbc3651
ZW
7079 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
7080 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
7081 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
7082 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
7083 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
7084 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
7085 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
7086 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
7087 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
7088 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
7089 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
7090 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
7091 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
7092 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
7093 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
7094 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
7095 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
7096 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
7097 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
7098 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
7099 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
7100 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
7101 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
7102 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
7103 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
7104 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
7105 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
7106 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
7107 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
7108 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
7109 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
7110 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 7111
8bb418a3
ZL
7112 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
7113 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
7114 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
7115
a3170dc6
AH
7116 /* Add the DST variants. */
7117 d = (struct builtin_description *) bdesc_dst;
7118 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 7119 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
7120
7121 /* Initialize the predicates. */
7122 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
7123 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
7124 {
7125 enum machine_mode mode1;
7126 tree type;
7127
7128 mode1 = insn_data[dp->icode].operand[1].mode;
7129
7130 switch (mode1)
7131 {
7132 case V4SImode:
7133 type = int_ftype_int_v4si_v4si;
7134 break;
7135 case V8HImode:
7136 type = int_ftype_int_v8hi_v8hi;
7137 break;
7138 case V16QImode:
7139 type = int_ftype_int_v16qi_v16qi;
7140 break;
7141 case V4SFmode:
7142 type = int_ftype_int_v4sf_v4sf;
7143 break;
7144 default:
7145 abort ();
7146 }
7147
7148 def_builtin (dp->mask, dp->name, type, dp->code);
7149 }
7150
7151 /* Initialize the abs* operators. */
7152 d = (struct builtin_description *) bdesc_abs;
7153 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
7154 {
7155 enum machine_mode mode0;
7156 tree type;
7157
7158 mode0 = insn_data[d->icode].operand[0].mode;
7159
7160 switch (mode0)
7161 {
7162 case V4SImode:
7163 type = v4si_ftype_v4si;
7164 break;
7165 case V8HImode:
7166 type = v8hi_ftype_v8hi;
7167 break;
7168 case V16QImode:
7169 type = v16qi_ftype_v16qi;
7170 break;
7171 case V4SFmode:
7172 type = v4sf_ftype_v4sf;
7173 break;
7174 default:
7175 abort ();
7176 }
7177
7178 def_builtin (d->mask, d->name, type, d->code);
7179 }
7180}
7181
7182static void
863d938c 7183rs6000_common_init_builtins (void)
a3170dc6
AH
7184{
7185 struct builtin_description *d;
7186 size_t i;
7187
7188 tree v4sf_ftype_v4sf_v4sf_v16qi
7189 = build_function_type_list (V4SF_type_node,
7190 V4SF_type_node, V4SF_type_node,
7191 V16QI_type_node, NULL_TREE);
7192 tree v4si_ftype_v4si_v4si_v16qi
7193 = build_function_type_list (V4SI_type_node,
7194 V4SI_type_node, V4SI_type_node,
7195 V16QI_type_node, NULL_TREE);
7196 tree v8hi_ftype_v8hi_v8hi_v16qi
7197 = build_function_type_list (V8HI_type_node,
7198 V8HI_type_node, V8HI_type_node,
7199 V16QI_type_node, NULL_TREE);
7200 tree v16qi_ftype_v16qi_v16qi_v16qi
7201 = build_function_type_list (V16QI_type_node,
7202 V16QI_type_node, V16QI_type_node,
7203 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
7204 tree v4si_ftype_int
7205 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
7206 tree v8hi_ftype_int
7207 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
7208 tree v16qi_ftype_int
7209 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
7210 tree v8hi_ftype_v16qi
7211 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
7212 tree v4sf_ftype_v4sf
7213 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
7214
7215 tree v2si_ftype_v2si_v2si
2abe3e28
AH
7216 = build_function_type_list (opaque_V2SI_type_node,
7217 opaque_V2SI_type_node,
7218 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7219
7220 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
7221 = build_function_type_list (opaque_V2SF_type_node,
7222 opaque_V2SF_type_node,
7223 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7224
7225 tree v2si_ftype_int_int
2abe3e28 7226 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7227 integer_type_node, integer_type_node,
7228 NULL_TREE);
7229
7230 tree v2si_ftype_v2si
2abe3e28
AH
7231 = build_function_type_list (opaque_V2SI_type_node,
7232 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7233
7234 tree v2sf_ftype_v2sf
2abe3e28
AH
7235 = build_function_type_list (opaque_V2SF_type_node,
7236 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7237
7238 tree v2sf_ftype_v2si
2abe3e28
AH
7239 = build_function_type_list (opaque_V2SF_type_node,
7240 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7241
7242 tree v2si_ftype_v2sf
2abe3e28
AH
7243 = build_function_type_list (opaque_V2SI_type_node,
7244 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7245
7246 tree v2si_ftype_v2si_char
2abe3e28
AH
7247 = build_function_type_list (opaque_V2SI_type_node,
7248 opaque_V2SI_type_node,
7249 char_type_node, NULL_TREE);
a3170dc6
AH
7250
7251 tree v2si_ftype_int_char
2abe3e28 7252 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7253 integer_type_node, char_type_node, NULL_TREE);
7254
7255 tree v2si_ftype_char
2abe3e28
AH
7256 = build_function_type_list (opaque_V2SI_type_node,
7257 char_type_node, NULL_TREE);
a3170dc6
AH
7258
7259 tree int_ftype_int_int
7260 = build_function_type_list (integer_type_node,
7261 integer_type_node, integer_type_node,
7262 NULL_TREE);
95385cbb 7263
0ac081f6 7264 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
7265 = build_function_type_list (V4SI_type_node,
7266 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 7267 tree v4sf_ftype_v4si_int
b4de2f7d 7268 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
7269 V4SI_type_node, integer_type_node, NULL_TREE);
7270 tree v4si_ftype_v4sf_int
b4de2f7d 7271 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7272 V4SF_type_node, integer_type_node, NULL_TREE);
7273 tree v4si_ftype_v4si_int
b4de2f7d 7274 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7275 V4SI_type_node, integer_type_node, NULL_TREE);
7276 tree v8hi_ftype_v8hi_int
b4de2f7d 7277 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
7278 V8HI_type_node, integer_type_node, NULL_TREE);
7279 tree v16qi_ftype_v16qi_int
b4de2f7d 7280 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
7281 V16QI_type_node, integer_type_node, NULL_TREE);
7282 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
7283 = build_function_type_list (V16QI_type_node,
7284 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
7285 integer_type_node, NULL_TREE);
7286 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
7287 = build_function_type_list (V8HI_type_node,
7288 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
7289 integer_type_node, NULL_TREE);
7290 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
7291 = build_function_type_list (V4SI_type_node,
7292 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
7293 integer_type_node, NULL_TREE);
7294 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
7295 = build_function_type_list (V4SF_type_node,
7296 V4SF_type_node, V4SF_type_node,
b9e4e5d1 7297 integer_type_node, NULL_TREE);
0ac081f6 7298 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
7299 = build_function_type_list (V4SF_type_node,
7300 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 7301 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
7302 = build_function_type_list (V4SF_type_node,
7303 V4SF_type_node, V4SF_type_node,
7304 V4SI_type_node, NULL_TREE);
2212663f 7305 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
7306 = build_function_type_list (V4SF_type_node,
7307 V4SF_type_node, V4SF_type_node,
7308 V4SF_type_node, NULL_TREE);
617e0e1d 7309 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
7310 = build_function_type_list (V4SI_type_node,
7311 V4SI_type_node, V4SI_type_node,
7312 V4SI_type_node, NULL_TREE);
0ac081f6 7313 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
7314 = build_function_type_list (V8HI_type_node,
7315 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 7316 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
7317 = build_function_type_list (V8HI_type_node,
7318 V8HI_type_node, V8HI_type_node,
7319 V8HI_type_node, NULL_TREE);
2212663f 7320 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
7321 = build_function_type_list (V4SI_type_node,
7322 V8HI_type_node, V8HI_type_node,
7323 V4SI_type_node, NULL_TREE);
2212663f 7324 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
7325 = build_function_type_list (V4SI_type_node,
7326 V16QI_type_node, V16QI_type_node,
7327 V4SI_type_node, NULL_TREE);
0ac081f6 7328 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
7329 = build_function_type_list (V16QI_type_node,
7330 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7331 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
7332 = build_function_type_list (V4SI_type_node,
7333 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 7334 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
7335 = build_function_type_list (V8HI_type_node,
7336 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7337 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
7338 = build_function_type_list (V4SI_type_node,
7339 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7340 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
7341 = build_function_type_list (V8HI_type_node,
7342 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 7343 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
7344 = build_function_type_list (V16QI_type_node,
7345 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7346 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
7347 = build_function_type_list (V4SI_type_node,
7348 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 7349 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
7350 = build_function_type_list (V4SI_type_node,
7351 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7352 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
7353 = build_function_type_list (V4SI_type_node,
7354 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7355 tree v4si_ftype_v8hi
7356 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
7357 tree int_ftype_v4si_v4si
7358 = build_function_type_list (integer_type_node,
7359 V4SI_type_node, V4SI_type_node, NULL_TREE);
7360 tree int_ftype_v4sf_v4sf
7361 = build_function_type_list (integer_type_node,
7362 V4SF_type_node, V4SF_type_node, NULL_TREE);
7363 tree int_ftype_v16qi_v16qi
7364 = build_function_type_list (integer_type_node,
7365 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7366 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
7367 = build_function_type_list (integer_type_node,
7368 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7369
6f317ef3 7370 /* Add the simple ternary operators. */
2212663f 7371 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 7372 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
7373 {
7374
7375 enum machine_mode mode0, mode1, mode2, mode3;
7376 tree type;
7377
0559cc77 7378 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7379 continue;
7380
7381 mode0 = insn_data[d->icode].operand[0].mode;
7382 mode1 = insn_data[d->icode].operand[1].mode;
7383 mode2 = insn_data[d->icode].operand[2].mode;
7384 mode3 = insn_data[d->icode].operand[3].mode;
7385
7386 /* When all four are of the same mode. */
7387 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
7388 {
7389 switch (mode0)
7390 {
617e0e1d
DB
7391 case V4SImode:
7392 type = v4si_ftype_v4si_v4si_v4si;
7393 break;
2212663f
DB
7394 case V4SFmode:
7395 type = v4sf_ftype_v4sf_v4sf_v4sf;
7396 break;
7397 case V8HImode:
7398 type = v8hi_ftype_v8hi_v8hi_v8hi;
7399 break;
7400 case V16QImode:
7401 type = v16qi_ftype_v16qi_v16qi_v16qi;
7402 break;
7403 default:
7404 abort();
7405 }
7406 }
7407 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
7408 {
7409 switch (mode0)
7410 {
7411 case V4SImode:
7412 type = v4si_ftype_v4si_v4si_v16qi;
7413 break;
7414 case V4SFmode:
7415 type = v4sf_ftype_v4sf_v4sf_v16qi;
7416 break;
7417 case V8HImode:
7418 type = v8hi_ftype_v8hi_v8hi_v16qi;
7419 break;
7420 case V16QImode:
7421 type = v16qi_ftype_v16qi_v16qi_v16qi;
7422 break;
7423 default:
7424 abort();
7425 }
7426 }
7427 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
7428 && mode3 == V4SImode)
24408032 7429 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
7430 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
7431 && mode3 == V4SImode)
24408032 7432 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
7433 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
7434 && mode3 == V4SImode)
24408032
AH
7435 type = v4sf_ftype_v4sf_v4sf_v4si;
7436
7437 /* vchar, vchar, vchar, 4 bit literal. */
7438 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
7439 && mode3 == QImode)
b9e4e5d1 7440 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
7441
7442 /* vshort, vshort, vshort, 4 bit literal. */
7443 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
7444 && mode3 == QImode)
b9e4e5d1 7445 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
7446
7447 /* vint, vint, vint, 4 bit literal. */
7448 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
7449 && mode3 == QImode)
b9e4e5d1 7450 type = v4si_ftype_v4si_v4si_int;
24408032
AH
7451
7452 /* vfloat, vfloat, vfloat, 4 bit literal. */
7453 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
7454 && mode3 == QImode)
b9e4e5d1 7455 type = v4sf_ftype_v4sf_v4sf_int;
24408032 7456
2212663f
DB
7457 else
7458 abort ();
7459
7460 def_builtin (d->mask, d->name, type, d->code);
7461 }
7462
0ac081f6 7463 /* Add the simple binary operators. */
00b960c7 7464 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 7465 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
7466 {
7467 enum machine_mode mode0, mode1, mode2;
7468 tree type;
7469
0559cc77 7470 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
7471 continue;
7472
7473 mode0 = insn_data[d->icode].operand[0].mode;
7474 mode1 = insn_data[d->icode].operand[1].mode;
7475 mode2 = insn_data[d->icode].operand[2].mode;
7476
7477 /* When all three operands are of the same mode. */
7478 if (mode0 == mode1 && mode1 == mode2)
7479 {
7480 switch (mode0)
7481 {
7482 case V4SFmode:
7483 type = v4sf_ftype_v4sf_v4sf;
7484 break;
7485 case V4SImode:
7486 type = v4si_ftype_v4si_v4si;
7487 break;
7488 case V16QImode:
7489 type = v16qi_ftype_v16qi_v16qi;
7490 break;
7491 case V8HImode:
7492 type = v8hi_ftype_v8hi_v8hi;
7493 break;
a3170dc6
AH
7494 case V2SImode:
7495 type = v2si_ftype_v2si_v2si;
7496 break;
7497 case V2SFmode:
7498 type = v2sf_ftype_v2sf_v2sf;
7499 break;
7500 case SImode:
7501 type = int_ftype_int_int;
7502 break;
0ac081f6
AH
7503 default:
7504 abort ();
7505 }
7506 }
7507
7508 /* A few other combos we really don't want to do manually. */
7509
7510 /* vint, vfloat, vfloat. */
7511 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
7512 type = v4si_ftype_v4sf_v4sf;
7513
7514 /* vshort, vchar, vchar. */
7515 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
7516 type = v8hi_ftype_v16qi_v16qi;
7517
7518 /* vint, vshort, vshort. */
7519 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
7520 type = v4si_ftype_v8hi_v8hi;
7521
7522 /* vshort, vint, vint. */
7523 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
7524 type = v8hi_ftype_v4si_v4si;
7525
7526 /* vchar, vshort, vshort. */
7527 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
7528 type = v16qi_ftype_v8hi_v8hi;
7529
7530 /* vint, vchar, vint. */
7531 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
7532 type = v4si_ftype_v16qi_v4si;
7533
fa066a23
AH
7534 /* vint, vchar, vchar. */
7535 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
7536 type = v4si_ftype_v16qi_v16qi;
7537
0ac081f6
AH
7538 /* vint, vshort, vint. */
7539 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
7540 type = v4si_ftype_v8hi_v4si;
2212663f
DB
7541
7542 /* vint, vint, 5 bit literal. */
7543 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7544 type = v4si_ftype_v4si_int;
2212663f
DB
7545
7546 /* vshort, vshort, 5 bit literal. */
7547 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 7548 type = v8hi_ftype_v8hi_int;
2212663f
DB
7549
7550 /* vchar, vchar, 5 bit literal. */
7551 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 7552 type = v16qi_ftype_v16qi_int;
0ac081f6 7553
617e0e1d
DB
7554 /* vfloat, vint, 5 bit literal. */
7555 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7556 type = v4sf_ftype_v4si_int;
617e0e1d
DB
7557
7558 /* vint, vfloat, 5 bit literal. */
7559 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 7560 type = v4si_ftype_v4sf_int;
617e0e1d 7561
a3170dc6
AH
7562 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
7563 type = v2si_ftype_int_int;
7564
7565 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
7566 type = v2si_ftype_v2si_char;
7567
7568 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
7569 type = v2si_ftype_int_char;
7570
0ac081f6
AH
7571 /* int, x, x. */
7572 else if (mode0 == SImode)
7573 {
7574 switch (mode1)
7575 {
7576 case V4SImode:
7577 type = int_ftype_v4si_v4si;
7578 break;
7579 case V4SFmode:
7580 type = int_ftype_v4sf_v4sf;
7581 break;
7582 case V16QImode:
7583 type = int_ftype_v16qi_v16qi;
7584 break;
7585 case V8HImode:
7586 type = int_ftype_v8hi_v8hi;
7587 break;
7588 default:
7589 abort ();
7590 }
7591 }
7592
7593 else
7594 abort ();
7595
2212663f
DB
7596 def_builtin (d->mask, d->name, type, d->code);
7597 }
24408032 7598
2212663f
DB
7599 /* Add the simple unary operators. */
7600 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 7601 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
7602 {
7603 enum machine_mode mode0, mode1;
7604 tree type;
7605
0559cc77 7606 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7607 continue;
7608
7609 mode0 = insn_data[d->icode].operand[0].mode;
7610 mode1 = insn_data[d->icode].operand[1].mode;
7611
7612 if (mode0 == V4SImode && mode1 == QImode)
b9e4e5d1 7613 type = v4si_ftype_int;
2212663f 7614 else if (mode0 == V8HImode && mode1 == QImode)
b9e4e5d1 7615 type = v8hi_ftype_int;
2212663f 7616 else if (mode0 == V16QImode && mode1 == QImode)
b9e4e5d1 7617 type = v16qi_ftype_int;
617e0e1d
DB
7618 else if (mode0 == V4SFmode && mode1 == V4SFmode)
7619 type = v4sf_ftype_v4sf;
20e26713
AH
7620 else if (mode0 == V8HImode && mode1 == V16QImode)
7621 type = v8hi_ftype_v16qi;
7622 else if (mode0 == V4SImode && mode1 == V8HImode)
7623 type = v4si_ftype_v8hi;
a3170dc6
AH
7624 else if (mode0 == V2SImode && mode1 == V2SImode)
7625 type = v2si_ftype_v2si;
7626 else if (mode0 == V2SFmode && mode1 == V2SFmode)
7627 type = v2sf_ftype_v2sf;
7628 else if (mode0 == V2SFmode && mode1 == V2SImode)
7629 type = v2sf_ftype_v2si;
7630 else if (mode0 == V2SImode && mode1 == V2SFmode)
7631 type = v2si_ftype_v2sf;
7632 else if (mode0 == V2SImode && mode1 == QImode)
7633 type = v2si_ftype_char;
2212663f
DB
7634 else
7635 abort ();
7636
0ac081f6
AH
7637 def_builtin (d->mask, d->name, type, d->code);
7638 }
7639}
7640
c15c90bb
ZW
7641static void
7642rs6000_init_libfuncs (void)
7643{
7644 if (!TARGET_HARD_FLOAT)
7645 return;
7646
c9034561 7647 if (DEFAULT_ABI != ABI_V4)
c15c90bb 7648 {
c9034561 7649 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 7650 {
c9034561 7651 /* AIX library routines for float->int conversion. */
85363ca0
ZW
7652 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
7653 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
7654 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
7655 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
7656 }
7657
c9034561 7658 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7659 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
7660 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
7661 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
7662 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
7663 }
c9034561 7664 else
c15c90bb 7665 {
c9034561 7666 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7667
7668 set_optab_libfunc (add_optab, TFmode, "_q_add");
7669 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
7670 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
7671 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
7672 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
7673 if (TARGET_PPC_GPOPT || TARGET_POWER2)
7674 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
7675
c9034561
ZW
7676 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
7677 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
7678 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
7679 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
7680 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
7681 set_optab_libfunc (le_optab, TFmode, "_q_fle");
7682
85363ca0
ZW
7683 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
7684 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
7685 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
7686 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
7687 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
7688 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
7689 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
7690 }
7691}
35aff10b 7692\f
7e69e155
MM
7693/* Expand a block move operation, and return 1 if successful. Return 0
7694 if we should let the compiler generate normal code.
7695
7696 operands[0] is the destination
7697 operands[1] is the source
7698 operands[2] is the length
7699 operands[3] is the alignment */
7700
3933e0e1
MM
7701#define MAX_MOVE_REG 4
7702
7e69e155 7703int
a2369ed3 7704expand_block_move (rtx operands[])
7e69e155 7705{
b6c9286a
MM
7706 rtx orig_dest = operands[0];
7707 rtx orig_src = operands[1];
7e69e155 7708 rtx bytes_rtx = operands[2];
7e69e155 7709 rtx align_rtx = operands[3];
3933e0e1 7710 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 7711 int align;
3933e0e1
MM
7712 int bytes;
7713 int offset;
7e69e155 7714 int move_bytes;
cabfd258
GK
7715 rtx stores[MAX_MOVE_REG];
7716 int num_reg = 0;
7e69e155 7717
3933e0e1 7718 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 7719 if (! constp)
3933e0e1
MM
7720 return 0;
7721
5ee95df6
FS
7722 /* If this is not a fixed size alignment, abort */
7723 if (GET_CODE (align_rtx) != CONST_INT)
7724 abort ();
7725 align = INTVAL (align_rtx);
7726
7e69e155 7727 /* Anything to move? */
3933e0e1
MM
7728 bytes = INTVAL (bytes_rtx);
7729 if (bytes <= 0)
7e69e155
MM
7730 return 1;
7731
ea9982a8 7732 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 7733 reg_parm_stack_space. */
ea9982a8 7734 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
7735 return 0;
7736
cabfd258 7737 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 7738 {
cabfd258 7739 union {
a2369ed3
DJ
7740 rtx (*movstrsi) (rtx, rtx, rtx, rtx);
7741 rtx (*mov) (rtx, rtx);
cabfd258
GK
7742 } gen_func;
7743 enum machine_mode mode = BLKmode;
7744 rtx src, dest;
7745
7746 if (TARGET_STRING
7747 && bytes > 24 /* move up to 32 bytes at a time */
7748 && ! fixed_regs[5]
7749 && ! fixed_regs[6]
7750 && ! fixed_regs[7]
7751 && ! fixed_regs[8]
7752 && ! fixed_regs[9]
7753 && ! fixed_regs[10]
7754 && ! fixed_regs[11]
7755 && ! fixed_regs[12])
7e69e155 7756 {
cabfd258
GK
7757 move_bytes = (bytes > 32) ? 32 : bytes;
7758 gen_func.movstrsi = gen_movstrsi_8reg;
7759 }
7760 else if (TARGET_STRING
7761 && bytes > 16 /* move up to 24 bytes at a time */
7762 && ! fixed_regs[5]
7763 && ! fixed_regs[6]
7764 && ! fixed_regs[7]
7765 && ! fixed_regs[8]
7766 && ! fixed_regs[9]
7767 && ! fixed_regs[10])
7768 {
7769 move_bytes = (bytes > 24) ? 24 : bytes;
7770 gen_func.movstrsi = gen_movstrsi_6reg;
7771 }
7772 else if (TARGET_STRING
7773 && bytes > 8 /* move up to 16 bytes at a time */
7774 && ! fixed_regs[5]
7775 && ! fixed_regs[6]
7776 && ! fixed_regs[7]
7777 && ! fixed_regs[8])
7778 {
7779 move_bytes = (bytes > 16) ? 16 : bytes;
7780 gen_func.movstrsi = gen_movstrsi_4reg;
7781 }
7782 else if (bytes >= 8 && TARGET_POWERPC64
7783 /* 64-bit loads and stores require word-aligned
7784 displacements. */
7785 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
7786 {
7787 move_bytes = 8;
7788 mode = DImode;
7789 gen_func.mov = gen_movdi;
7790 }
7791 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
7792 { /* move up to 8 bytes at a time */
7793 move_bytes = (bytes > 8) ? 8 : bytes;
7794 gen_func.movstrsi = gen_movstrsi_2reg;
7795 }
7796 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
7797 { /* move 4 bytes */
7798 move_bytes = 4;
7799 mode = SImode;
7800 gen_func.mov = gen_movsi;
7801 }
7802 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
7803 { /* move 2 bytes */
7804 move_bytes = 2;
7805 mode = HImode;
7806 gen_func.mov = gen_movhi;
7807 }
7808 else if (TARGET_STRING && bytes > 1)
7809 { /* move up to 4 bytes at a time */
7810 move_bytes = (bytes > 4) ? 4 : bytes;
7811 gen_func.movstrsi = gen_movstrsi_1reg;
7812 }
7813 else /* move 1 byte at a time */
7814 {
7815 move_bytes = 1;
7816 mode = QImode;
7817 gen_func.mov = gen_movqi;
7818 }
7819
7820 src = adjust_address (orig_src, mode, offset);
7821 dest = adjust_address (orig_dest, mode, offset);
7822
7823 if (mode != BLKmode)
7824 {
7825 rtx tmp_reg = gen_reg_rtx (mode);
7826
7827 emit_insn ((*gen_func.mov) (tmp_reg, src));
7828 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 7829 }
3933e0e1 7830
cabfd258
GK
7831 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
7832 {
7833 int i;
7834 for (i = 0; i < num_reg; i++)
7835 emit_insn (stores[i]);
7836 num_reg = 0;
7837 }
35aff10b 7838
cabfd258 7839 if (mode == BLKmode)
7e69e155 7840 {
cabfd258
GK
7841 /* Move the address into scratch registers. The movstrsi
7842 patterns require zero offset. */
7843 if (!REG_P (XEXP (src, 0)))
b6c9286a 7844 {
cabfd258
GK
7845 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
7846 src = replace_equiv_address (src, src_reg);
b6c9286a 7847 }
cabfd258
GK
7848 set_mem_size (src, GEN_INT (move_bytes));
7849
7850 if (!REG_P (XEXP (dest, 0)))
3933e0e1 7851 {
cabfd258
GK
7852 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
7853 dest = replace_equiv_address (dest, dest_reg);
7e69e155 7854 }
cabfd258
GK
7855 set_mem_size (dest, GEN_INT (move_bytes));
7856
7857 emit_insn ((*gen_func.movstrsi) (dest, src,
7858 GEN_INT (move_bytes & 31),
7859 align_rtx));
7e69e155 7860 }
7e69e155
MM
7861 }
7862
7863 return 1;
7864}
7865
9878760c
RK
7866\f
7867/* Return 1 if OP is a load multiple operation. It is known to be a
7868 PARALLEL and the first section will be tested. */
7869
7870int
a2369ed3 7871load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7872{
7873 int count = XVECLEN (op, 0);
e2c953b6 7874 unsigned int dest_regno;
9878760c
RK
7875 rtx src_addr;
7876 int i;
7877
7878 /* Perform a quick check so we don't blow up below. */
7879 if (count <= 1
7880 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7881 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7882 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7883 return 0;
7884
7885 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7886 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7887
7888 for (i = 1; i < count; i++)
7889 {
7890 rtx elt = XVECEXP (op, 0, i);
7891
7892 if (GET_CODE (elt) != SET
7893 || GET_CODE (SET_DEST (elt)) != REG
7894 || GET_MODE (SET_DEST (elt)) != SImode
7895 || REGNO (SET_DEST (elt)) != dest_regno + i
7896 || GET_CODE (SET_SRC (elt)) != MEM
7897 || GET_MODE (SET_SRC (elt)) != SImode
7898 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
7899 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
7900 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
7901 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
7902 return 0;
7903 }
7904
7905 return 1;
7906}
7907
7908/* Similar, but tests for store multiple. Here, the second vector element
7909 is a CLOBBER. It will be tested later. */
7910
7911int
a2369ed3 7912store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7913{
7914 int count = XVECLEN (op, 0) - 1;
e2c953b6 7915 unsigned int src_regno;
9878760c
RK
7916 rtx dest_addr;
7917 int i;
7918
7919 /* Perform a quick check so we don't blow up below. */
7920 if (count <= 1
7921 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7922 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7923 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7924 return 0;
7925
7926 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7927 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7928
7929 for (i = 1; i < count; i++)
7930 {
7931 rtx elt = XVECEXP (op, 0, i + 1);
7932
7933 if (GET_CODE (elt) != SET
7934 || GET_CODE (SET_SRC (elt)) != REG
7935 || GET_MODE (SET_SRC (elt)) != SImode
7936 || REGNO (SET_SRC (elt)) != src_regno + i
7937 || GET_CODE (SET_DEST (elt)) != MEM
7938 || GET_MODE (SET_DEST (elt)) != SImode
7939 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
7940 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
7941 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
7942 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
7943 return 0;
7944 }
7945
7946 return 1;
7947}
9ebbca7d 7948
9caa3eb2
DE
7949/* Return a string to perform a load_multiple operation.
7950 operands[0] is the vector.
7951 operands[1] is the source address.
7952 operands[2] is the first destination register. */
7953
7954const char *
a2369ed3 7955rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
7956{
7957 /* We have to handle the case where the pseudo used to contain the address
7958 is assigned to one of the output registers. */
7959 int i, j;
7960 int words = XVECLEN (operands[0], 0);
7961 rtx xop[10];
7962
7963 if (XVECLEN (operands[0], 0) == 1)
7964 return "{l|lwz} %2,0(%1)";
7965
7966 for (i = 0; i < words; i++)
7967 if (refers_to_regno_p (REGNO (operands[2]) + i,
7968 REGNO (operands[2]) + i + 1, operands[1], 0))
7969 {
7970 if (i == words-1)
7971 {
7972 xop[0] = GEN_INT (4 * (words-1));
7973 xop[1] = operands[1];
7974 xop[2] = operands[2];
7975 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
7976 return "";
7977 }
7978 else if (i == 0)
7979 {
7980 xop[0] = GEN_INT (4 * (words-1));
7981 xop[1] = operands[1];
7982 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
7983 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);
7984 return "";
7985 }
7986 else
7987 {
7988 for (j = 0; j < words; j++)
7989 if (j != i)
7990 {
7991 xop[0] = GEN_INT (j * 4);
7992 xop[1] = operands[1];
7993 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
7994 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
7995 }
7996 xop[0] = GEN_INT (i * 4);
7997 xop[1] = operands[1];
7998 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
7999 return "";
8000 }
8001 }
8002
8003 return "{lsi|lswi} %2,%1,%N0";
8004}
8005
00b960c7
AH
8006/* Return 1 for a parallel vrsave operation. */
8007
8008int
a2369ed3 8009vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
8010{
8011 int count = XVECLEN (op, 0);
8012 unsigned int dest_regno, src_regno;
8013 int i;
8014
8015 if (count <= 1
8016 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8017 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 8018 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
8019 return 0;
8020
8021 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8022 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8023
8024 if (dest_regno != VRSAVE_REGNO
8025 && src_regno != VRSAVE_REGNO)
8026 return 0;
8027
8028 for (i = 1; i < count; i++)
8029 {
8030 rtx elt = XVECEXP (op, 0, i);
8031
9aa86737
AH
8032 if (GET_CODE (elt) != CLOBBER
8033 && GET_CODE (elt) != SET)
00b960c7
AH
8034 return 0;
8035 }
8036
8037 return 1;
8038}
8039
2c4a9cff
DE
8040/* Return 1 for an PARALLEL suitable for mfcr. */
8041
8042int
a2369ed3 8043mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
8044{
8045 int count = XVECLEN (op, 0);
8046 int i;
8047
8048 /* Perform a quick check so we don't blow up below. */
8049 if (count < 1
8050 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8051 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8052 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
8053 return 0;
8054
8055 for (i = 0; i < count; i++)
8056 {
8057 rtx exp = XVECEXP (op, 0, i);
8058 rtx unspec;
8059 int maskval;
8060 rtx src_reg;
8061
8062 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
8063
8064 if (GET_CODE (src_reg) != REG
8065 || GET_MODE (src_reg) != CCmode
8066 || ! CR_REGNO_P (REGNO (src_reg)))
8067 return 0;
8068
8069 if (GET_CODE (exp) != SET
8070 || GET_CODE (SET_DEST (exp)) != REG
8071 || GET_MODE (SET_DEST (exp)) != SImode
8072 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
8073 return 0;
8074 unspec = SET_SRC (exp);
8075 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
8076
8077 if (GET_CODE (unspec) != UNSPEC
8078 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
8079 || XVECLEN (unspec, 0) != 2
8080 || XVECEXP (unspec, 0, 0) != src_reg
8081 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8082 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8083 return 0;
8084 }
8085 return 1;
8086}
8087
a4f6c312 8088/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
8089
8090int
a2369ed3 8091mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8092{
8093 int count = XVECLEN (op, 0);
8094 int i;
9ebbca7d
GK
8095 rtx src_reg;
8096
8097 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
8098 if (count < 1
8099 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8100 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8101 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 8102 return 0;
e35b9579 8103 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
8104
8105 if (GET_CODE (src_reg) != REG
8106 || GET_MODE (src_reg) != SImode
8107 || ! INT_REGNO_P (REGNO (src_reg)))
8108 return 0;
8109
e35b9579 8110 for (i = 0; i < count; i++)
9ebbca7d
GK
8111 {
8112 rtx exp = XVECEXP (op, 0, i);
8113 rtx unspec;
8114 int maskval;
8115
8116 if (GET_CODE (exp) != SET
8117 || GET_CODE (SET_DEST (exp)) != REG
8118 || GET_MODE (SET_DEST (exp)) != CCmode
8119 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
8120 return 0;
8121 unspec = SET_SRC (exp);
8122 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
8123
8124 if (GET_CODE (unspec) != UNSPEC
615158e2 8125 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
8126 || XVECLEN (unspec, 0) != 2
8127 || XVECEXP (unspec, 0, 0) != src_reg
8128 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8129 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8130 return 0;
8131 }
e35b9579 8132 return 1;
9ebbca7d
GK
8133}
8134
a4f6c312 8135/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
8136
8137int
a2369ed3 8138lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8139{
8140 int count = XVECLEN (op, 0);
e2c953b6 8141 unsigned int dest_regno;
9ebbca7d 8142 rtx src_addr;
e2c953b6 8143 unsigned int base_regno;
9ebbca7d
GK
8144 HOST_WIDE_INT offset;
8145 int i;
8146
8147 /* Perform a quick check so we don't blow up below. */
8148 if (count <= 1
8149 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8150 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8151 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8152 return 0;
8153
8154 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8155 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8156
8157 if (dest_regno > 31
e2c953b6 8158 || count != 32 - (int) dest_regno)
9ebbca7d
GK
8159 return 0;
8160
4d588c14 8161 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
8162 {
8163 offset = 0;
8164 base_regno = REGNO (src_addr);
8165 if (base_regno == 0)
8166 return 0;
8167 }
4d588c14 8168 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
8169 {
8170 offset = INTVAL (XEXP (src_addr, 1));
8171 base_regno = REGNO (XEXP (src_addr, 0));
8172 }
8173 else
8174 return 0;
8175
8176 for (i = 0; i < count; i++)
8177 {
8178 rtx elt = XVECEXP (op, 0, i);
8179 rtx newaddr;
8180 rtx addr_reg;
8181 HOST_WIDE_INT newoffset;
8182
8183 if (GET_CODE (elt) != SET
8184 || GET_CODE (SET_DEST (elt)) != REG
8185 || GET_MODE (SET_DEST (elt)) != SImode
8186 || REGNO (SET_DEST (elt)) != dest_regno + i
8187 || GET_CODE (SET_SRC (elt)) != MEM
8188 || GET_MODE (SET_SRC (elt)) != SImode)
8189 return 0;
8190 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 8191 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8192 {
8193 newoffset = 0;
8194 addr_reg = newaddr;
8195 }
4d588c14 8196 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8197 {
8198 addr_reg = XEXP (newaddr, 0);
8199 newoffset = INTVAL (XEXP (newaddr, 1));
8200 }
8201 else
8202 return 0;
8203 if (REGNO (addr_reg) != base_regno
8204 || newoffset != offset + 4 * i)
8205 return 0;
8206 }
8207
8208 return 1;
8209}
8210
a4f6c312 8211/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
8212
8213int
a2369ed3 8214stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8215{
8216 int count = XVECLEN (op, 0);
e2c953b6 8217 unsigned int src_regno;
9ebbca7d 8218 rtx dest_addr;
e2c953b6 8219 unsigned int base_regno;
9ebbca7d
GK
8220 HOST_WIDE_INT offset;
8221 int i;
8222
8223 /* Perform a quick check so we don't blow up below. */
8224 if (count <= 1
8225 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8226 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8227 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8228 return 0;
8229
8230 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8231 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8232
8233 if (src_regno > 31
e2c953b6 8234 || count != 32 - (int) src_regno)
9ebbca7d
GK
8235 return 0;
8236
4d588c14 8237 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
8238 {
8239 offset = 0;
8240 base_regno = REGNO (dest_addr);
8241 if (base_regno == 0)
8242 return 0;
8243 }
4d588c14 8244 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
8245 {
8246 offset = INTVAL (XEXP (dest_addr, 1));
8247 base_regno = REGNO (XEXP (dest_addr, 0));
8248 }
8249 else
8250 return 0;
8251
8252 for (i = 0; i < count; i++)
8253 {
8254 rtx elt = XVECEXP (op, 0, i);
8255 rtx newaddr;
8256 rtx addr_reg;
8257 HOST_WIDE_INT newoffset;
8258
8259 if (GET_CODE (elt) != SET
8260 || GET_CODE (SET_SRC (elt)) != REG
8261 || GET_MODE (SET_SRC (elt)) != SImode
8262 || REGNO (SET_SRC (elt)) != src_regno + i
8263 || GET_CODE (SET_DEST (elt)) != MEM
8264 || GET_MODE (SET_DEST (elt)) != SImode)
8265 return 0;
8266 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 8267 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8268 {
8269 newoffset = 0;
8270 addr_reg = newaddr;
8271 }
4d588c14 8272 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8273 {
8274 addr_reg = XEXP (newaddr, 0);
8275 newoffset = INTVAL (XEXP (newaddr, 1));
8276 }
8277 else
8278 return 0;
8279 if (REGNO (addr_reg) != base_regno
8280 || newoffset != offset + 4 * i)
8281 return 0;
8282 }
8283
8284 return 1;
8285}
9878760c 8286\f
a4f6c312
SS
8287/* A validation routine: say whether CODE, a condition code, and MODE
8288 match. The other alternatives either don't make sense or should
8289 never be generated. */
39a10a29 8290
39a10a29 8291static void
a2369ed3 8292validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 8293{
ec8e098d
PB
8294 if ((GET_RTX_CLASS (code) != RTX_COMPARE
8295 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
8296 || GET_MODE_CLASS (mode) != MODE_CC)
8297 abort ();
8298
8299 /* These don't make sense. */
8300 if ((code == GT || code == LT || code == GE || code == LE)
8301 && mode == CCUNSmode)
8302 abort ();
8303
8304 if ((code == GTU || code == LTU || code == GEU || code == LEU)
8305 && mode != CCUNSmode)
8306 abort ();
8307
8308 if (mode != CCFPmode
8309 && (code == ORDERED || code == UNORDERED
8310 || code == UNEQ || code == LTGT
8311 || code == UNGT || code == UNLT
8312 || code == UNGE || code == UNLE))
a4f6c312 8313 abort ();
39a10a29 8314
de6c5979 8315 /* These should never be generated except for
bc9ec0e0 8316 flag_finite_math_only. */
39a10a29 8317 if (mode == CCFPmode
ad72b533 8318 && ! flag_finite_math_only
39a10a29
GK
8319 && (code == LE || code == GE
8320 || code == UNEQ || code == LTGT
8321 || code == UNGT || code == UNLT))
8322 abort ();
8323
8324 /* These are invalid; the information is not there. */
8325 if (mode == CCEQmode
8326 && code != EQ && code != NE)
8327 abort ();
8328}
8329
9878760c
RK
8330/* Return 1 if OP is a comparison operation that is valid for a branch insn.
8331 We only check the opcode against the mode of the CC value here. */
8332
8333int
a2369ed3 8334branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8335{
8336 enum rtx_code code = GET_CODE (op);
8337 enum machine_mode cc_mode;
8338
ec8e098d 8339 if (!COMPARISON_P (op))
9878760c
RK
8340 return 0;
8341
8342 cc_mode = GET_MODE (XEXP (op, 0));
8343 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
8344 return 0;
8345
39a10a29 8346 validate_condition_mode (code, cc_mode);
9878760c 8347
39a10a29
GK
8348 return 1;
8349}
8350
8351/* Return 1 if OP is a comparison operation that is valid for a branch
8352 insn and which is true if the corresponding bit in the CC register
8353 is set. */
8354
8355int
a2369ed3 8356branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
8357{
8358 enum rtx_code code;
8359
8daf2e65 8360 if (! branch_comparison_operator (op, mode))
9878760c
RK
8361 return 0;
8362
39a10a29
GK
8363 code = GET_CODE (op);
8364 return (code == EQ || code == LT || code == GT
8365 || code == LTU || code == GTU
8366 || code == UNORDERED);
9878760c
RK
8367}
8368
b7053a3f
GK
8369/* Return 1 if OP is a comparison operation that is valid for an scc
8370 insn: it must be a positive comparison. */
9878760c
RK
8371
8372int
a2369ed3 8373scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 8374{
b7053a3f 8375 return branch_positive_comparison_operator (op, mode);
9878760c 8376}
e0cd0770
JC
8377
8378int
a2369ed3 8379trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
8380{
8381 if (mode != VOIDmode && mode != GET_MODE (op))
8382 return 0;
ec8e098d 8383 return COMPARISON_P (op);
e0cd0770 8384}
dfbdccdb
GK
8385
8386int
a2369ed3 8387boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
8388{
8389 enum rtx_code code = GET_CODE (op);
8390 return (code == AND || code == IOR || code == XOR);
8391}
1d328b19
GK
8392
8393int
a2369ed3 8394boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
8395{
8396 enum rtx_code code = GET_CODE (op);
8397 return (code == IOR || code == XOR);
8398}
50a0b056
GK
8399
8400int
a2369ed3 8401min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
8402{
8403 enum rtx_code code = GET_CODE (op);
8404 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
8405}
9878760c
RK
8406\f
8407/* Return 1 if ANDOP is a mask that has no bits on that are not in the
8408 mask required to convert the result of a rotate insn into a shift
b1765bde 8409 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
8410
8411int
a2369ed3 8412includes_lshift_p (rtx shiftop, rtx andop)
9878760c 8413{
e2c953b6
DE
8414 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
8415
8416 shift_mask <<= INTVAL (shiftop);
9878760c 8417
b1765bde 8418 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
8419}
8420
8421/* Similar, but for right shift. */
8422
8423int
a2369ed3 8424includes_rshift_p (rtx shiftop, rtx andop)
9878760c 8425{
a7653a2c 8426 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
8427
8428 shift_mask >>= INTVAL (shiftop);
8429
b1765bde 8430 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
8431}
8432
c5059423
AM
8433/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
8434 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 8435 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
8436
8437int
a2369ed3 8438includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 8439{
c5059423
AM
8440 if (GET_CODE (andop) == CONST_INT)
8441 {
02071907 8442 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 8443
c5059423 8444 c = INTVAL (andop);
02071907 8445 if (c == 0 || c == ~0)
c5059423 8446 return 0;
e2c953b6 8447
02071907 8448 shift_mask = ~0;
c5059423
AM
8449 shift_mask <<= INTVAL (shiftop);
8450
b6d08ca1 8451 /* Find the least significant one bit. */
c5059423
AM
8452 lsb = c & -c;
8453
8454 /* It must coincide with the LSB of the shift mask. */
8455 if (-lsb != shift_mask)
8456 return 0;
e2c953b6 8457
c5059423
AM
8458 /* Invert to look for the next transition (if any). */
8459 c = ~c;
8460
8461 /* Remove the low group of ones (originally low group of zeros). */
8462 c &= -lsb;
8463
8464 /* Again find the lsb, and check we have all 1's above. */
8465 lsb = c & -c;
8466 return c == -lsb;
8467 }
8468 else if (GET_CODE (andop) == CONST_DOUBLE
8469 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8470 {
02071907
AM
8471 HOST_WIDE_INT low, high, lsb;
8472 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
8473
8474 low = CONST_DOUBLE_LOW (andop);
8475 if (HOST_BITS_PER_WIDE_INT < 64)
8476 high = CONST_DOUBLE_HIGH (andop);
8477
8478 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 8479 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
8480 return 0;
8481
8482 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8483 {
02071907 8484 shift_mask_high = ~0;
c5059423
AM
8485 if (INTVAL (shiftop) > 32)
8486 shift_mask_high <<= INTVAL (shiftop) - 32;
8487
8488 lsb = high & -high;
8489
8490 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
8491 return 0;
8492
8493 high = ~high;
8494 high &= -lsb;
8495
8496 lsb = high & -high;
8497 return high == -lsb;
8498 }
8499
02071907 8500 shift_mask_low = ~0;
c5059423
AM
8501 shift_mask_low <<= INTVAL (shiftop);
8502
8503 lsb = low & -low;
8504
8505 if (-lsb != shift_mask_low)
8506 return 0;
8507
8508 if (HOST_BITS_PER_WIDE_INT < 64)
8509 high = ~high;
8510 low = ~low;
8511 low &= -lsb;
8512
8513 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8514 {
8515 lsb = high & -high;
8516 return high == -lsb;
8517 }
8518
8519 lsb = low & -low;
8520 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
8521 }
8522 else
8523 return 0;
8524}
e2c953b6 8525
c5059423
AM
8526/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
8527 to perform a left shift. It must have SHIFTOP or more least
c1207243 8528 significant 0's, with the remainder of the word 1's. */
e2c953b6 8529
c5059423 8530int
a2369ed3 8531includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 8532{
e2c953b6 8533 if (GET_CODE (andop) == CONST_INT)
c5059423 8534 {
02071907 8535 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 8536
02071907 8537 shift_mask = ~0;
c5059423
AM
8538 shift_mask <<= INTVAL (shiftop);
8539 c = INTVAL (andop);
8540
c1207243 8541 /* Find the least significant one bit. */
c5059423
AM
8542 lsb = c & -c;
8543
8544 /* It must be covered by the shift mask.
a4f6c312 8545 This test also rejects c == 0. */
c5059423
AM
8546 if ((lsb & shift_mask) == 0)
8547 return 0;
8548
8549 /* Check we have all 1's above the transition, and reject all 1's. */
8550 return c == -lsb && lsb != 1;
8551 }
8552 else if (GET_CODE (andop) == CONST_DOUBLE
8553 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8554 {
02071907 8555 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
8556
8557 low = CONST_DOUBLE_LOW (andop);
8558
8559 if (HOST_BITS_PER_WIDE_INT < 64)
8560 {
02071907 8561 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
8562
8563 high = CONST_DOUBLE_HIGH (andop);
8564
8565 if (low == 0)
8566 {
02071907 8567 shift_mask_high = ~0;
c5059423
AM
8568 if (INTVAL (shiftop) > 32)
8569 shift_mask_high <<= INTVAL (shiftop) - 32;
8570
8571 lsb = high & -high;
8572
8573 if ((lsb & shift_mask_high) == 0)
8574 return 0;
8575
8576 return high == -lsb;
8577 }
8578 if (high != ~0)
8579 return 0;
8580 }
8581
02071907 8582 shift_mask_low = ~0;
c5059423
AM
8583 shift_mask_low <<= INTVAL (shiftop);
8584
8585 lsb = low & -low;
8586
8587 if ((lsb & shift_mask_low) == 0)
8588 return 0;
8589
8590 return low == -lsb && lsb != 1;
8591 }
e2c953b6 8592 else
c5059423 8593 return 0;
9878760c 8594}
35068b43
RK
8595
8596/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
8597 for lfq and stfq insns.
8598
8599 Note reg1 and reg2 *must* be hard registers. To be sure we will
8600 abort if we are passed pseudo registers. */
8601
8602int
a2369ed3 8603registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
8604{
8605 /* We might have been passed a SUBREG. */
8606 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8607 return 0;
8608
8609 return (REGNO (reg1) == REGNO (reg2) - 1);
8610}
8611
a4f6c312
SS
8612/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
8613 addr1 and addr2 must be in consecutive memory locations
8614 (addr2 == addr1 + 8). */
35068b43
RK
8615
8616int
a2369ed3 8617addrs_ok_for_quad_peep (rtx addr1, rtx addr2)
35068b43 8618{
e2c953b6 8619 unsigned int reg1;
35068b43
RK
8620 int offset1;
8621
8622 /* Extract an offset (if used) from the first addr. */
8623 if (GET_CODE (addr1) == PLUS)
8624 {
8625 /* If not a REG, return zero. */
8626 if (GET_CODE (XEXP (addr1, 0)) != REG)
8627 return 0;
8628 else
8629 {
8630 reg1 = REGNO (XEXP (addr1, 0));
8631 /* The offset must be constant! */
8632 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8633 return 0;
8634 offset1 = INTVAL (XEXP (addr1, 1));
8635 }
8636 }
8637 else if (GET_CODE (addr1) != REG)
8638 return 0;
8639 else
8640 {
8641 reg1 = REGNO (addr1);
8642 /* This was a simple (mem (reg)) expression. Offset is 0. */
8643 offset1 = 0;
8644 }
8645
a2369ed3 8646 /* Make sure the second address is a (mem (plus (reg) (const_int)))
0f6937fe
AM
8647 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
8648 register as addr1. */
984e25ac 8649 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 8650 return 1;
35068b43
RK
8651 if (GET_CODE (addr2) != PLUS)
8652 return 0;
8653
8654 if (GET_CODE (XEXP (addr2, 0)) != REG
8655 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8656 return 0;
8657
8658 if (reg1 != REGNO (XEXP (addr2, 0)))
8659 return 0;
8660
8661 /* The offset for the second addr must be 8 more than the first addr. */
8662 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
8663 return 0;
8664
8665 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
8666 instructions. */
8667 return 1;
8668}
9878760c
RK
8669\f
8670/* Return the register class of a scratch register needed to copy IN into
8671 or out of a register in CLASS in MODE. If it can be done directly,
8672 NO_REGS is returned. */
8673
8674enum reg_class
a2369ed3 8675secondary_reload_class (enum reg_class class,
a9baceb1
GK
8676 enum machine_mode mode ATTRIBUTE_UNUSED,
8677 rtx in)
9878760c 8678{
5accd822 8679 int regno;
9878760c 8680
ab82a49f
AP
8681 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
8682#if TARGET_MACHO
8683 && MACHOPIC_INDIRECT
8684#endif
8685 ))
46fad5b7
DJ
8686 {
8687 /* We cannot copy a symbolic operand directly into anything
8688 other than BASE_REGS for TARGET_ELF. So indicate that a
8689 register from BASE_REGS is needed as an intermediate
8690 register.
8691
8692 On Darwin, pic addresses require a load from memory, which
8693 needs a base register. */
8694 if (class != BASE_REGS
8695 && (GET_CODE (in) == SYMBOL_REF
8696 || GET_CODE (in) == HIGH
8697 || GET_CODE (in) == LABEL_REF
8698 || GET_CODE (in) == CONST))
8699 return BASE_REGS;
8700 }
e7b7998a 8701
5accd822
DE
8702 if (GET_CODE (in) == REG)
8703 {
8704 regno = REGNO (in);
8705 if (regno >= FIRST_PSEUDO_REGISTER)
8706 {
8707 regno = true_regnum (in);
8708 if (regno >= FIRST_PSEUDO_REGISTER)
8709 regno = -1;
8710 }
8711 }
8712 else if (GET_CODE (in) == SUBREG)
8713 {
8714 regno = true_regnum (in);
8715 if (regno >= FIRST_PSEUDO_REGISTER)
8716 regno = -1;
8717 }
8718 else
8719 regno = -1;
8720
9878760c
RK
8721 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
8722 into anything. */
8723 if (class == GENERAL_REGS || class == BASE_REGS
8724 || (regno >= 0 && INT_REGNO_P (regno)))
8725 return NO_REGS;
8726
8727 /* Constants, memory, and FP registers can go into FP registers. */
8728 if ((regno == -1 || FP_REGNO_P (regno))
8729 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
8730 return NO_REGS;
8731
0ac081f6
AH
8732 /* Memory, and AltiVec registers can go into AltiVec registers. */
8733 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
8734 && class == ALTIVEC_REGS)
8735 return NO_REGS;
8736
9878760c
RK
8737 /* We can copy among the CR registers. */
8738 if ((class == CR_REGS || class == CR0_REGS)
8739 && regno >= 0 && CR_REGNO_P (regno))
8740 return NO_REGS;
8741
8742 /* Otherwise, we need GENERAL_REGS. */
8743 return GENERAL_REGS;
8744}
8745\f
8746/* Given a comparison operation, return the bit number in CCR to test. We
8747 know this is a valid comparison.
8748
8749 SCC_P is 1 if this is for an scc. That means that %D will have been
8750 used instead of %C, so the bits will be in different places.
8751
b4ac57ab 8752 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
8753
8754int
a2369ed3 8755ccr_bit (rtx op, int scc_p)
9878760c
RK
8756{
8757 enum rtx_code code = GET_CODE (op);
8758 enum machine_mode cc_mode;
8759 int cc_regnum;
8760 int base_bit;
9ebbca7d 8761 rtx reg;
9878760c 8762
ec8e098d 8763 if (!COMPARISON_P (op))
9878760c
RK
8764 return -1;
8765
9ebbca7d
GK
8766 reg = XEXP (op, 0);
8767
8768 if (GET_CODE (reg) != REG
8769 || ! CR_REGNO_P (REGNO (reg)))
8770 abort ();
8771
8772 cc_mode = GET_MODE (reg);
8773 cc_regnum = REGNO (reg);
8774 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 8775
39a10a29 8776 validate_condition_mode (code, cc_mode);
c5defebb 8777
b7053a3f
GK
8778 /* When generating a sCOND operation, only positive conditions are
8779 allowed. */
8780 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
8781 && code != GTU && code != LTU)
8782 abort ();
8783
9878760c
RK
8784 switch (code)
8785 {
8786 case NE:
8787 return scc_p ? base_bit + 3 : base_bit + 2;
8788 case EQ:
8789 return base_bit + 2;
1c882ea4 8790 case GT: case GTU: case UNLE:
9878760c 8791 return base_bit + 1;
1c882ea4 8792 case LT: case LTU: case UNGE:
9878760c 8793 return base_bit;
1c882ea4
GK
8794 case ORDERED: case UNORDERED:
8795 return base_bit + 3;
9878760c
RK
8796
8797 case GE: case GEU:
39a10a29 8798 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
8799 unordered position. So test that bit. For integer, this is ! LT
8800 unless this is an scc insn. */
39a10a29 8801 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
8802
8803 case LE: case LEU:
39a10a29 8804 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 8805
9878760c
RK
8806 default:
8807 abort ();
8808 }
8809}
1ff7789b 8810\f
8d30c4ee 8811/* Return the GOT register. */
1ff7789b
MM
8812
8813struct rtx_def *
a2369ed3 8814rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 8815{
a4f6c312
SS
8816 /* The second flow pass currently (June 1999) can't update
8817 regs_ever_live without disturbing other parts of the compiler, so
8818 update it here to make the prolog/epilogue code happy. */
1db02437
FS
8819 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
8820 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 8821
8d30c4ee 8822 current_function_uses_pic_offset_table = 1;
3cb999d8 8823
1ff7789b
MM
8824 return pic_offset_table_rtx;
8825}
a7df97e6 8826\f
e2500fed
GK
8827/* Function to init struct machine_function.
8828 This will be called, via a pointer variable,
8829 from push_function_context. */
a7df97e6 8830
e2500fed 8831static struct machine_function *
863d938c 8832rs6000_init_machine_status (void)
a7df97e6 8833{
e2500fed 8834 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 8835}
9878760c 8836\f
0ba1b2ff
AM
8837/* These macros test for integers and extract the low-order bits. */
8838#define INT_P(X) \
8839((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
8840 && GET_MODE (X) == VOIDmode)
8841
8842#define INT_LOWPART(X) \
8843 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
8844
8845int
a2369ed3 8846extract_MB (rtx op)
0ba1b2ff
AM
8847{
8848 int i;
8849 unsigned long val = INT_LOWPART (op);
8850
8851 /* If the high bit is zero, the value is the first 1 bit we find
8852 from the left. */
8853 if ((val & 0x80000000) == 0)
8854 {
8855 if ((val & 0xffffffff) == 0)
8856 abort ();
8857
8858 i = 1;
8859 while (((val <<= 1) & 0x80000000) == 0)
8860 ++i;
8861 return i;
8862 }
8863
8864 /* If the high bit is set and the low bit is not, or the mask is all
8865 1's, the value is zero. */
8866 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
8867 return 0;
8868
8869 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8870 from the right. */
8871 i = 31;
8872 while (((val >>= 1) & 1) != 0)
8873 --i;
8874
8875 return i;
8876}
8877
8878int
a2369ed3 8879extract_ME (rtx op)
0ba1b2ff
AM
8880{
8881 int i;
8882 unsigned long val = INT_LOWPART (op);
8883
8884 /* If the low bit is zero, the value is the first 1 bit we find from
8885 the right. */
8886 if ((val & 1) == 0)
8887 {
8888 if ((val & 0xffffffff) == 0)
8889 abort ();
8890
8891 i = 30;
8892 while (((val >>= 1) & 1) == 0)
8893 --i;
8894
8895 return i;
8896 }
8897
8898 /* If the low bit is set and the high bit is not, or the mask is all
8899 1's, the value is 31. */
8900 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
8901 return 31;
8902
8903 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8904 from the left. */
8905 i = 0;
8906 while (((val <<= 1) & 0x80000000) != 0)
8907 ++i;
8908
8909 return i;
8910}
8911
c4501e62
JJ
8912/* Locate some local-dynamic symbol still in use by this function
8913 so that we can print its name in some tls_ld pattern. */
8914
8915static const char *
863d938c 8916rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
8917{
8918 rtx insn;
8919
8920 if (cfun->machine->some_ld_name)
8921 return cfun->machine->some_ld_name;
8922
8923 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8924 if (INSN_P (insn)
8925 && for_each_rtx (&PATTERN (insn),
8926 rs6000_get_some_local_dynamic_name_1, 0))
8927 return cfun->machine->some_ld_name;
8928
8929 abort ();
8930}
8931
8932/* Helper function for rs6000_get_some_local_dynamic_name. */
8933
8934static int
a2369ed3 8935rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
8936{
8937 rtx x = *px;
8938
8939 if (GET_CODE (x) == SYMBOL_REF)
8940 {
8941 const char *str = XSTR (x, 0);
8942 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8943 {
8944 cfun->machine->some_ld_name = str;
8945 return 1;
8946 }
8947 }
8948
8949 return 0;
8950}
8951
9878760c
RK
8952/* Print an operand. Recognize special options, documented below. */
8953
38c1f2d7 8954#if TARGET_ELF
d9407988 8955#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 8956#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
8957#else
8958#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 8959#define SMALL_DATA_REG 0
ba5e43aa
MM
8960#endif
8961
9878760c 8962void
a2369ed3 8963print_operand (FILE *file, rtx x, int code)
9878760c
RK
8964{
8965 int i;
a260abc9 8966 HOST_WIDE_INT val;
0ba1b2ff 8967 unsigned HOST_WIDE_INT uval;
9878760c
RK
8968
8969 switch (code)
8970 {
a8b3aeda 8971 case '.':
a85d226b
RK
8972 /* Write out an instruction after the call which may be replaced
8973 with glue code by the loader. This depends on the AIX version. */
8974 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
8975 return;
8976
81eace42
GK
8977 /* %a is output_address. */
8978
9854d9ed
RK
8979 case 'A':
8980 /* If X is a constant integer whose low-order 5 bits are zero,
8981 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 8982 in the AIX assembler where "sri" with a zero shift count
20e26713 8983 writes a trash instruction. */
9854d9ed 8984 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 8985 putc ('l', file);
9854d9ed 8986 else
76229ac8 8987 putc ('r', file);
9854d9ed
RK
8988 return;
8989
8990 case 'b':
e2c953b6
DE
8991 /* If constant, low-order 16 bits of constant, unsigned.
8992 Otherwise, write normally. */
8993 if (INT_P (x))
8994 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
8995 else
8996 print_operand (file, x, 0);
cad12a8d
RK
8997 return;
8998
a260abc9
DE
8999 case 'B':
9000 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
9001 for 64-bit mask direction. */
296b8152 9002 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 9003 return;
a260abc9 9004
81eace42
GK
9005 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
9006 output_operand. */
9007
423c1189
AH
9008 case 'c':
9009 /* X is a CR register. Print the number of the GT bit of the CR. */
9010 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9011 output_operand_lossage ("invalid %%E value");
9012 else
9013 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1);
9014 return;
9015
9016 case 'D':
9017 /* Like 'J' but get to the GT bit. */
9018 if (GET_CODE (x) != REG)
9019 abort ();
9020
9021 /* Bit 1 is GT bit. */
9022 i = 4 * (REGNO (x) - CR0_REGNO) + 1;
9023
9024 /* If we want bit 31, write a shift count of zero, not 32. */
9025 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9026 return;
9027
9854d9ed 9028 case 'E':
39a10a29 9029 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
9030 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9031 output_operand_lossage ("invalid %%E value");
78fbdbf7 9032 else
39a10a29 9033 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 9034 return;
9854d9ed
RK
9035
9036 case 'f':
9037 /* X is a CR register. Print the shift count needed to move it
9038 to the high-order four bits. */
9039 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9040 output_operand_lossage ("invalid %%f value");
9041 else
9ebbca7d 9042 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9043 return;
9044
9045 case 'F':
9046 /* Similar, but print the count for the rotate in the opposite
9047 direction. */
9048 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9049 output_operand_lossage ("invalid %%F value");
9050 else
9ebbca7d 9051 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9052 return;
9053
9054 case 'G':
9055 /* X is a constant integer. If it is negative, print "m",
43aa4e05 9056 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
9057 if (GET_CODE (x) != CONST_INT)
9058 output_operand_lossage ("invalid %%G value");
9059 else if (INTVAL (x) >= 0)
76229ac8 9060 putc ('z', file);
9854d9ed 9061 else
76229ac8 9062 putc ('m', file);
9854d9ed 9063 return;
e2c953b6 9064
9878760c 9065 case 'h':
a4f6c312
SS
9066 /* If constant, output low-order five bits. Otherwise, write
9067 normally. */
9878760c 9068 if (INT_P (x))
5f59ecb7 9069 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
9070 else
9071 print_operand (file, x, 0);
9072 return;
9073
64305719 9074 case 'H':
a4f6c312
SS
9075 /* If constant, output low-order six bits. Otherwise, write
9076 normally. */
64305719 9077 if (INT_P (x))
5f59ecb7 9078 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
9079 else
9080 print_operand (file, x, 0);
9081 return;
9082
9854d9ed
RK
9083 case 'I':
9084 /* Print `i' if this is a constant, else nothing. */
9878760c 9085 if (INT_P (x))
76229ac8 9086 putc ('i', file);
9878760c
RK
9087 return;
9088
9854d9ed
RK
9089 case 'j':
9090 /* Write the bit number in CCR for jump. */
9091 i = ccr_bit (x, 0);
9092 if (i == -1)
9093 output_operand_lossage ("invalid %%j code");
9878760c 9094 else
9854d9ed 9095 fprintf (file, "%d", i);
9878760c
RK
9096 return;
9097
9854d9ed
RK
9098 case 'J':
9099 /* Similar, but add one for shift count in rlinm for scc and pass
9100 scc flag to `ccr_bit'. */
9101 i = ccr_bit (x, 1);
9102 if (i == -1)
9103 output_operand_lossage ("invalid %%J code");
9104 else
a0466a68
RK
9105 /* If we want bit 31, write a shift count of zero, not 32. */
9106 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
9107 return;
9108
9854d9ed
RK
9109 case 'k':
9110 /* X must be a constant. Write the 1's complement of the
9111 constant. */
9878760c 9112 if (! INT_P (x))
9854d9ed 9113 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
9114 else
9115 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
9116 return;
9117
81eace42 9118 case 'K':
9ebbca7d
GK
9119 /* X must be a symbolic constant on ELF. Write an
9120 expression suitable for an 'addi' that adds in the low 16
9121 bits of the MEM. */
9122 if (GET_CODE (x) != CONST)
9123 {
9124 print_operand_address (file, x);
9125 fputs ("@l", file);
9126 }
9127 else
9128 {
9129 if (GET_CODE (XEXP (x, 0)) != PLUS
9130 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
9131 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
9132 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 9133 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
9134 print_operand_address (file, XEXP (XEXP (x, 0), 0));
9135 fputs ("@l", file);
ed8d2920
MM
9136 /* For GNU as, there must be a non-alphanumeric character
9137 between 'l' and the number. The '-' is added by
9138 print_operand() already. */
9139 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
9140 fputs ("+", file);
9ebbca7d
GK
9141 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
9142 }
81eace42
GK
9143 return;
9144
9145 /* %l is output_asm_label. */
9ebbca7d 9146
9854d9ed
RK
9147 case 'L':
9148 /* Write second word of DImode or DFmode reference. Works on register
9149 or non-indexed memory only. */
9150 if (GET_CODE (x) == REG)
5ebfb2ba 9151 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
9152 else if (GET_CODE (x) == MEM)
9153 {
9154 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 9155 we have already done it, we can just use an offset of word. */
9854d9ed
RK
9156 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9157 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
9158 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
9159 UNITS_PER_WORD));
9854d9ed 9160 else
d7624dc0
RK
9161 output_address (XEXP (adjust_address_nv (x, SImode,
9162 UNITS_PER_WORD),
9163 0));
ed8908e7 9164
ba5e43aa 9165 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9166 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9167 reg_names[SMALL_DATA_REG]);
9854d9ed 9168 }
9878760c 9169 return;
9854d9ed 9170
9878760c
RK
9171 case 'm':
9172 /* MB value for a mask operand. */
b1765bde 9173 if (! mask_operand (x, SImode))
9878760c
RK
9174 output_operand_lossage ("invalid %%m value");
9175
0ba1b2ff 9176 fprintf (file, "%d", extract_MB (x));
9878760c
RK
9177 return;
9178
9179 case 'M':
9180 /* ME value for a mask operand. */
b1765bde 9181 if (! mask_operand (x, SImode))
a260abc9 9182 output_operand_lossage ("invalid %%M value");
9878760c 9183
0ba1b2ff 9184 fprintf (file, "%d", extract_ME (x));
9878760c
RK
9185 return;
9186
81eace42
GK
9187 /* %n outputs the negative of its operand. */
9188
9878760c
RK
9189 case 'N':
9190 /* Write the number of elements in the vector times 4. */
9191 if (GET_CODE (x) != PARALLEL)
9192 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
9193 else
9194 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
9195 return;
9196
9197 case 'O':
9198 /* Similar, but subtract 1 first. */
9199 if (GET_CODE (x) != PARALLEL)
1427100a 9200 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
9201 else
9202 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
9203 return;
9204
9854d9ed
RK
9205 case 'p':
9206 /* X is a CONST_INT that is a power of two. Output the logarithm. */
9207 if (! INT_P (x)
2bfcf297 9208 || INT_LOWPART (x) < 0
9854d9ed
RK
9209 || (i = exact_log2 (INT_LOWPART (x))) < 0)
9210 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
9211 else
9212 fprintf (file, "%d", i);
9854d9ed
RK
9213 return;
9214
9878760c
RK
9215 case 'P':
9216 /* The operand must be an indirect memory reference. The result
8bb418a3 9217 is the register name. */
9878760c
RK
9218 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
9219 || REGNO (XEXP (x, 0)) >= 32)
9220 output_operand_lossage ("invalid %%P value");
e2c953b6 9221 else
8bb418a3 9222 fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]);
9878760c
RK
9223 return;
9224
dfbdccdb
GK
9225 case 'q':
9226 /* This outputs the logical code corresponding to a boolean
9227 expression. The expression may have one or both operands
39a10a29
GK
9228 negated (if one, only the first one). For condition register
9229 logical operations, it will also treat the negated
9230 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 9231 {
63bc1d05 9232 const char *const *t = 0;
dfbdccdb
GK
9233 const char *s;
9234 enum rtx_code code = GET_CODE (x);
9235 static const char * const tbl[3][3] = {
9236 { "and", "andc", "nor" },
9237 { "or", "orc", "nand" },
9238 { "xor", "eqv", "xor" } };
9239
9240 if (code == AND)
9241 t = tbl[0];
9242 else if (code == IOR)
9243 t = tbl[1];
9244 else if (code == XOR)
9245 t = tbl[2];
9246 else
9247 output_operand_lossage ("invalid %%q value");
9248
9249 if (GET_CODE (XEXP (x, 0)) != NOT)
9250 s = t[0];
9251 else
9252 {
9253 if (GET_CODE (XEXP (x, 1)) == NOT)
9254 s = t[2];
9255 else
9256 s = t[1];
9257 }
9258
9259 fputs (s, file);
9260 }
9261 return;
9262
2c4a9cff
DE
9263 case 'Q':
9264 if (TARGET_MFCRF)
3b6ce0af 9265 fputc (',', file);
5efb1046 9266 /* FALLTHRU */
2c4a9cff
DE
9267 else
9268 return;
9269
9854d9ed
RK
9270 case 'R':
9271 /* X is a CR register. Print the mask for `mtcrf'. */
9272 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9273 output_operand_lossage ("invalid %%R value");
9274 else
9ebbca7d 9275 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 9276 return;
9854d9ed
RK
9277
9278 case 's':
9279 /* Low 5 bits of 32 - value */
9280 if (! INT_P (x))
9281 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
9282 else
9283 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 9284 return;
9854d9ed 9285
a260abc9 9286 case 'S':
0ba1b2ff 9287 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
9288 CONST_INT 32-bit mask is considered sign-extended so any
9289 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 9290 if (! mask64_operand (x, DImode))
a260abc9
DE
9291 output_operand_lossage ("invalid %%S value");
9292
0ba1b2ff 9293 uval = INT_LOWPART (x);
a260abc9 9294
0ba1b2ff 9295 if (uval & 1) /* Clear Left */
a260abc9 9296 {
f099d360
GK
9297#if HOST_BITS_PER_WIDE_INT > 64
9298 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9299#endif
0ba1b2ff 9300 i = 64;
a260abc9 9301 }
0ba1b2ff 9302 else /* Clear Right */
a260abc9 9303 {
0ba1b2ff 9304 uval = ~uval;
f099d360
GK
9305#if HOST_BITS_PER_WIDE_INT > 64
9306 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9307#endif
0ba1b2ff 9308 i = 63;
a260abc9 9309 }
0ba1b2ff
AM
9310 while (uval != 0)
9311 --i, uval >>= 1;
9312 if (i < 0)
9313 abort ();
9314 fprintf (file, "%d", i);
9315 return;
a260abc9 9316
a3170dc6
AH
9317 case 't':
9318 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
9319 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
9320 abort ();
9321
9322 /* Bit 3 is OV bit. */
9323 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
9324
9325 /* If we want bit 31, write a shift count of zero, not 32. */
9326 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9327 return;
9328
cccf3bdc
DE
9329 case 'T':
9330 /* Print the symbolic name of a branch target register. */
9331 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
9332 && REGNO (x) != COUNT_REGISTER_REGNUM))
9333 output_operand_lossage ("invalid %%T value");
e2c953b6 9334 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
9335 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
9336 else
9337 fputs ("ctr", file);
9338 return;
9339
9854d9ed 9340 case 'u':
802a0058 9341 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
9342 if (! INT_P (x))
9343 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
9344 else
9345 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9346 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
9347 return;
9348
802a0058
MM
9349 case 'v':
9350 /* High-order 16 bits of constant for use in signed operand. */
9351 if (! INT_P (x))
9352 output_operand_lossage ("invalid %%v value");
e2c953b6 9353 else
134c32f6
DE
9354 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9355 (INT_LOWPART (x) >> 16) & 0xffff);
9356 return;
802a0058 9357
9854d9ed
RK
9358 case 'U':
9359 /* Print `u' if this has an auto-increment or auto-decrement. */
9360 if (GET_CODE (x) == MEM
9361 && (GET_CODE (XEXP (x, 0)) == PRE_INC
9362 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 9363 putc ('u', file);
9854d9ed 9364 return;
9878760c 9365
e0cd0770
JC
9366 case 'V':
9367 /* Print the trap code for this operand. */
9368 switch (GET_CODE (x))
9369 {
9370 case EQ:
9371 fputs ("eq", file); /* 4 */
9372 break;
9373 case NE:
9374 fputs ("ne", file); /* 24 */
9375 break;
9376 case LT:
9377 fputs ("lt", file); /* 16 */
9378 break;
9379 case LE:
9380 fputs ("le", file); /* 20 */
9381 break;
9382 case GT:
9383 fputs ("gt", file); /* 8 */
9384 break;
9385 case GE:
9386 fputs ("ge", file); /* 12 */
9387 break;
9388 case LTU:
9389 fputs ("llt", file); /* 2 */
9390 break;
9391 case LEU:
9392 fputs ("lle", file); /* 6 */
9393 break;
9394 case GTU:
9395 fputs ("lgt", file); /* 1 */
9396 break;
9397 case GEU:
9398 fputs ("lge", file); /* 5 */
9399 break;
9400 default:
9401 abort ();
9402 }
9403 break;
9404
9854d9ed
RK
9405 case 'w':
9406 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
9407 normally. */
9408 if (INT_P (x))
5f59ecb7
DE
9409 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
9410 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
9411 else
9412 print_operand (file, x, 0);
9878760c
RK
9413 return;
9414
9854d9ed 9415 case 'W':
e2c953b6 9416 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
9417 val = (GET_CODE (x) == CONST_INT
9418 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
9419
9420 if (val < 0)
9421 i = -1;
9854d9ed 9422 else
e2c953b6
DE
9423 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
9424 if ((val <<= 1) < 0)
9425 break;
9426
9427#if HOST_BITS_PER_WIDE_INT == 32
9428 if (GET_CODE (x) == CONST_INT && i >= 0)
9429 i += 32; /* zero-extend high-part was all 0's */
9430 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
9431 {
9432 val = CONST_DOUBLE_LOW (x);
9433
9434 if (val == 0)
a4f6c312 9435 abort ();
e2c953b6
DE
9436 else if (val < 0)
9437 --i;
9438 else
9439 for ( ; i < 64; i++)
9440 if ((val <<= 1) < 0)
9441 break;
9442 }
9443#endif
9444
9445 fprintf (file, "%d", i + 1);
9854d9ed 9446 return;
9878760c 9447
9854d9ed
RK
9448 case 'X':
9449 if (GET_CODE (x) == MEM
4d588c14 9450 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 9451 putc ('x', file);
9854d9ed 9452 return;
9878760c 9453
9854d9ed
RK
9454 case 'Y':
9455 /* Like 'L', for third word of TImode */
9456 if (GET_CODE (x) == REG)
5ebfb2ba 9457 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 9458 else if (GET_CODE (x) == MEM)
9878760c 9459 {
9854d9ed
RK
9460 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9461 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9462 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 9463 else
d7624dc0 9464 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 9465 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9466 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9467 reg_names[SMALL_DATA_REG]);
9878760c
RK
9468 }
9469 return;
9854d9ed 9470
9878760c 9471 case 'z':
b4ac57ab
RS
9472 /* X is a SYMBOL_REF. Write out the name preceded by a
9473 period and without any trailing data in brackets. Used for function
4d30c363
MM
9474 names. If we are configured for System V (or the embedded ABI) on
9475 the PowerPC, do not emit the period, since those systems do not use
9476 TOCs and the like. */
9878760c
RK
9477 if (GET_CODE (x) != SYMBOL_REF)
9478 abort ();
9479
b6c9286a
MM
9480 if (XSTR (x, 0)[0] != '.')
9481 {
9482 switch (DEFAULT_ABI)
9483 {
9484 default:
9485 abort ();
9486
9487 case ABI_AIX:
9488 putc ('.', file);
9489 break;
9490
9491 case ABI_V4:
ee890fe2 9492 case ABI_DARWIN:
b6c9286a 9493 break;
b6c9286a
MM
9494 }
9495 }
f9da97f0
AP
9496 /* For macho, we need to check it see if we need a stub. */
9497 if (TARGET_MACHO)
9498 {
9499 const char *name = XSTR (x, 0);
a031e781 9500#if TARGET_MACHO
f9da97f0
AP
9501 if (machopic_classify_name (name) == MACHOPIC_UNDEFINED_FUNCTION)
9502 name = machopic_stub_name (name);
9503#endif
9504 assemble_name (file, name);
9505 }
9506 else if (TARGET_AIX)
9739c90c
JJ
9507 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9508 else
9509 assemble_name (file, XSTR (x, 0));
9878760c
RK
9510 return;
9511
9854d9ed
RK
9512 case 'Z':
9513 /* Like 'L', for last word of TImode. */
9514 if (GET_CODE (x) == REG)
5ebfb2ba 9515 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
9516 else if (GET_CODE (x) == MEM)
9517 {
9518 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9519 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9520 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 9521 else
d7624dc0 9522 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 9523 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9524 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9525 reg_names[SMALL_DATA_REG]);
9854d9ed 9526 }
5c23c401 9527 return;
0ac081f6 9528
a3170dc6 9529 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
9530 case 'y':
9531 {
9532 rtx tmp;
9533
9534 if (GET_CODE (x) != MEM)
9535 abort ();
9536
9537 tmp = XEXP (x, 0);
9538
993f19a8 9539 if (TARGET_E500)
a3170dc6
AH
9540 {
9541 /* Handle [reg]. */
9542 if (GET_CODE (tmp) == REG)
9543 {
9544 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
9545 break;
9546 }
9547 /* Handle [reg+UIMM]. */
9548 else if (GET_CODE (tmp) == PLUS &&
9549 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
9550 {
9551 int x;
9552
9553 if (GET_CODE (XEXP (tmp, 0)) != REG)
9554 abort ();
9555
9556 x = INTVAL (XEXP (tmp, 1));
9557 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
9558 break;
9559 }
9560
9561 /* Fall through. Must be [reg+reg]. */
9562 }
0ac081f6 9563 if (GET_CODE (tmp) == REG)
c62f2db5 9564 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
9565 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
9566 {
9567 if (REGNO (XEXP (tmp, 0)) == 0)
9568 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
9569 reg_names[ REGNO (XEXP (tmp, 0)) ]);
9570 else
9571 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
9572 reg_names[ REGNO (XEXP (tmp, 1)) ]);
9573 }
9574 else
9575 abort ();
9576 break;
9577 }
9854d9ed 9578
9878760c
RK
9579 case 0:
9580 if (GET_CODE (x) == REG)
9581 fprintf (file, "%s", reg_names[REGNO (x)]);
9582 else if (GET_CODE (x) == MEM)
9583 {
9584 /* We need to handle PRE_INC and PRE_DEC here, since we need to
9585 know the width from the mode. */
9586 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
9587 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
9588 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9589 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
9590 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
9591 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9592 else
a54d04b7 9593 output_address (XEXP (x, 0));
9878760c
RK
9594 }
9595 else
a54d04b7 9596 output_addr_const (file, x);
a85d226b 9597 return;
9878760c 9598
c4501e62
JJ
9599 case '&':
9600 assemble_name (file, rs6000_get_some_local_dynamic_name ());
9601 return;
9602
9878760c
RK
9603 default:
9604 output_operand_lossage ("invalid %%xn code");
9605 }
9606}
9607\f
9608/* Print the address of an operand. */
9609
9610void
a2369ed3 9611print_operand_address (FILE *file, rtx x)
9878760c
RK
9612{
9613 if (GET_CODE (x) == REG)
4697a36c 9614 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
9615 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
9616 || GET_CODE (x) == LABEL_REF)
9878760c
RK
9617 {
9618 output_addr_const (file, x);
ba5e43aa 9619 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9620 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9621 reg_names[SMALL_DATA_REG]);
9ebbca7d 9622 else if (TARGET_TOC)
a4f6c312 9623 abort ();
9878760c
RK
9624 }
9625 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
9626 {
9627 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
9628 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
9629 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 9630 else
4697a36c
MM
9631 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
9632 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
9633 }
9634 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
9635 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
9636 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
9637#if TARGET_ELF
9638 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9639 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
9640 {
9641 output_addr_const (file, XEXP (x, 1));
9642 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9643 }
c859cda6
DJ
9644#endif
9645#if TARGET_MACHO
9646 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9647 && CONSTANT_P (XEXP (x, 1)))
9648 {
9649 fprintf (file, "lo16(");
9650 output_addr_const (file, XEXP (x, 1));
9651 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9652 }
3cb999d8 9653#endif
4d588c14 9654 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 9655 {
2bfcf297 9656 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 9657 {
2bfcf297
DB
9658 rtx contains_minus = XEXP (x, 1);
9659 rtx minus, symref;
9660 const char *name;
9ebbca7d
GK
9661
9662 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 9663 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
9664 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
9665 contains_minus = XEXP (contains_minus, 0);
9666
2bfcf297
DB
9667 minus = XEXP (contains_minus, 0);
9668 symref = XEXP (minus, 0);
9669 XEXP (contains_minus, 0) = symref;
9670 if (TARGET_ELF)
9671 {
9672 char *newname;
9673
9674 name = XSTR (symref, 0);
9675 newname = alloca (strlen (name) + sizeof ("@toc"));
9676 strcpy (newname, name);
9677 strcat (newname, "@toc");
9678 XSTR (symref, 0) = newname;
9679 }
9680 output_addr_const (file, XEXP (x, 1));
9681 if (TARGET_ELF)
9682 XSTR (symref, 0) = name;
9ebbca7d
GK
9683 XEXP (contains_minus, 0) = minus;
9684 }
9685 else
9686 output_addr_const (file, XEXP (x, 1));
9687
9688 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9689 }
9878760c
RK
9690 else
9691 abort ();
9692}
9693\f
88cad84b 9694/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9695 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9696 is defined. It also needs to handle DI-mode objects on 64-bit
9697 targets. */
9698
9699static bool
a2369ed3 9700rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
9701{
9702#ifdef RELOCATABLE_NEEDS_FIXUP
9703 /* Special handling for SI values. */
9704 if (size == 4 && aligned_p)
9705 {
a2369ed3 9706 extern int in_toc_section (void);
301d03af
RS
9707 static int recurse = 0;
9708
9709 /* For -mrelocatable, we mark all addresses that need to be fixed up
9710 in the .fixup section. */
9711 if (TARGET_RELOCATABLE
9712 && !in_toc_section ()
9713 && !in_text_section ()
642af3be 9714 && !in_unlikely_text_section ()
301d03af
RS
9715 && !recurse
9716 && GET_CODE (x) != CONST_INT
9717 && GET_CODE (x) != CONST_DOUBLE
9718 && CONSTANT_P (x))
9719 {
9720 char buf[256];
9721
9722 recurse = 1;
9723 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9724 fixuplabelno++;
9725 ASM_OUTPUT_LABEL (asm_out_file, buf);
9726 fprintf (asm_out_file, "\t.long\t(");
9727 output_addr_const (asm_out_file, x);
9728 fprintf (asm_out_file, ")@fixup\n");
9729 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9730 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9731 fprintf (asm_out_file, "\t.long\t");
9732 assemble_name (asm_out_file, buf);
9733 fprintf (asm_out_file, "\n\t.previous\n");
9734 recurse = 0;
9735 return true;
9736 }
9737 /* Remove initial .'s to turn a -mcall-aixdesc function
9738 address into the address of the descriptor, not the function
9739 itself. */
9740 else if (GET_CODE (x) == SYMBOL_REF
9741 && XSTR (x, 0)[0] == '.'
9742 && DEFAULT_ABI == ABI_AIX)
9743 {
9744 const char *name = XSTR (x, 0);
9745 while (*name == '.')
9746 name++;
9747
9748 fprintf (asm_out_file, "\t.long\t%s\n", name);
9749 return true;
9750 }
9751 }
9752#endif /* RELOCATABLE_NEEDS_FIXUP */
9753 return default_assemble_integer (x, size, aligned_p);
9754}
93638d7a
AM
9755
9756#ifdef HAVE_GAS_HIDDEN
9757/* Emit an assembler directive to set symbol visibility for DECL to
9758 VISIBILITY_TYPE. */
9759
5add3202 9760static void
a2369ed3 9761rs6000_assemble_visibility (tree decl, int vis)
93638d7a 9762{
93638d7a
AM
9763 /* Functions need to have their entry point symbol visibility set as
9764 well as their descriptor symbol visibility. */
9765 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9766 {
25fdb4dc
RH
9767 static const char * const visibility_types[] = {
9768 NULL, "internal", "hidden", "protected"
9769 };
9770
9771 const char *name, *type;
93638d7a
AM
9772
9773 name = ((* targetm.strip_name_encoding)
9774 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9775 type = visibility_types[vis];
93638d7a 9776
25fdb4dc
RH
9777 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9778 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9779 }
25fdb4dc
RH
9780 else
9781 default_assemble_visibility (decl, vis);
93638d7a
AM
9782}
9783#endif
301d03af 9784\f
39a10a29 9785enum rtx_code
a2369ed3 9786rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
9787{
9788 /* Reversal of FP compares takes care -- an ordered compare
9789 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9790 if (mode == CCFPmode
9791 && (!flag_finite_math_only
9792 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
9793 || code == UNEQ || code == LTGT))
bab6226b 9794 return reverse_condition_maybe_unordered (code);
39a10a29 9795 else
bab6226b 9796 return reverse_condition (code);
39a10a29
GK
9797}
9798
39a10a29
GK
9799/* Generate a compare for CODE. Return a brand-new rtx that
9800 represents the result of the compare. */
a4f6c312 9801
39a10a29 9802static rtx
a2369ed3 9803rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
9804{
9805 enum machine_mode comp_mode;
9806 rtx compare_result;
9807
9808 if (rs6000_compare_fp_p)
9809 comp_mode = CCFPmode;
9810 else if (code == GTU || code == LTU
9811 || code == GEU || code == LEU)
9812 comp_mode = CCUNSmode;
9813 else
9814 comp_mode = CCmode;
9815
9816 /* First, the compare. */
9817 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
9818
9819 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
9820 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
9821 && rs6000_compare_fp_p)
a3170dc6
AH
9822 {
9823 rtx cmp, or1, or2, or_result, compare_result2;
9824
423c1189
AH
9825 /* Note: The E500 comparison instructions set the GT bit (x +
9826 1), on success. This explains the mess. */
9827
a3170dc6
AH
9828 switch (code)
9829 {
423c1189 9830 case EQ: case UNEQ: case NE: case LTGT:
bc9ec0e0 9831 cmp = flag_finite_math_only
a3170dc6
AH
9832 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
9833 rs6000_compare_op1)
9834 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
9835 rs6000_compare_op1);
9836 break;
423c1189 9837 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
bc9ec0e0 9838 cmp = flag_finite_math_only
a3170dc6
AH
9839 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
9840 rs6000_compare_op1)
9841 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
9842 rs6000_compare_op1);
9843 break;
423c1189 9844 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
bc9ec0e0 9845 cmp = flag_finite_math_only
a3170dc6
AH
9846 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
9847 rs6000_compare_op1)
9848 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
9849 rs6000_compare_op1);
9850 break;
9851 default:
9852 abort ();
9853 }
9854
9855 /* Synthesize LE and GE from LT/GT || EQ. */
9856 if (code == LE || code == GE || code == LEU || code == GEU)
9857 {
a3170dc6
AH
9858 emit_insn (cmp);
9859
9860 switch (code)
9861 {
9862 case LE: code = LT; break;
9863 case GE: code = GT; break;
9864 case LEU: code = LT; break;
9865 case GEU: code = GT; break;
9866 default: abort ();
9867 }
9868
9869 or1 = gen_reg_rtx (SImode);
9870 or2 = gen_reg_rtx (SImode);
9871 or_result = gen_reg_rtx (CCEQmode);
9872 compare_result2 = gen_reg_rtx (CCFPmode);
9873
9874 /* Do the EQ. */
bc9ec0e0 9875 cmp = flag_finite_math_only
a3170dc6
AH
9876 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
9877 rs6000_compare_op1)
9878 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
9879 rs6000_compare_op1);
9880 emit_insn (cmp);
9881
423c1189
AH
9882 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
9883 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
9884
9885 /* OR them together. */
9886 cmp = gen_rtx_SET (VOIDmode, or_result,
9887 gen_rtx_COMPARE (CCEQmode,
9888 gen_rtx_IOR (SImode, or1, or2),
9889 const_true_rtx));
9890 compare_result = or_result;
9891 code = EQ;
9892 }
9893 else
9894 {
a3170dc6 9895 if (code == NE || code == LTGT)
a3170dc6 9896 code = NE;
423c1189
AH
9897 else
9898 code = EQ;
a3170dc6
AH
9899 }
9900
9901 emit_insn (cmp);
9902 }
9903 else
9904 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
9905 gen_rtx_COMPARE (comp_mode,
9906 rs6000_compare_op0,
9907 rs6000_compare_op1)));
39a10a29 9908
ca5adc63 9909 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 9910 under flag_finite_math_only we don't bother. */
39a10a29 9911 if (rs6000_compare_fp_p
bc9ec0e0 9912 && ! flag_finite_math_only
993f19a8 9913 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
9914 && (code == LE || code == GE
9915 || code == UNEQ || code == LTGT
9916 || code == UNGT || code == UNLT))
9917 {
9918 enum rtx_code or1, or2;
9919 rtx or1_rtx, or2_rtx, compare2_rtx;
9920 rtx or_result = gen_reg_rtx (CCEQmode);
9921
9922 switch (code)
9923 {
9924 case LE: or1 = LT; or2 = EQ; break;
9925 case GE: or1 = GT; or2 = EQ; break;
9926 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
9927 case LTGT: or1 = LT; or2 = GT; break;
9928 case UNGT: or1 = UNORDERED; or2 = GT; break;
9929 case UNLT: or1 = UNORDERED; or2 = LT; break;
9930 default: abort ();
9931 }
9932 validate_condition_mode (or1, comp_mode);
9933 validate_condition_mode (or2, comp_mode);
1c563bed
KH
9934 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
9935 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
9936 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
9937 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
9938 const_true_rtx);
9939 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
9940
9941 compare_result = or_result;
9942 code = EQ;
9943 }
9944
9945 validate_condition_mode (code, GET_MODE (compare_result));
9946
1c563bed 9947 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
9948}
9949
9950
9951/* Emit the RTL for an sCOND pattern. */
9952
9953void
a2369ed3 9954rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
9955{
9956 rtx condition_rtx;
9957 enum machine_mode op_mode;
b7053a3f 9958 enum rtx_code cond_code;
39a10a29
GK
9959
9960 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
9961 cond_code = GET_CODE (condition_rtx);
9962
423c1189
AH
9963 if (TARGET_E500 && rs6000_compare_fp_p
9964 && !TARGET_FPRS && TARGET_HARD_FLOAT)
9965 {
9966 rtx t;
9967
9968 PUT_MODE (condition_rtx, SImode);
9969 t = XEXP (condition_rtx, 0);
9970
9971 if (cond_code != NE && cond_code != EQ)
9972 abort ();
9973
9974 if (cond_code == NE)
9975 emit_insn (gen_e500_flip_gt_bit (t, t));
9976
9977 emit_insn (gen_move_from_CR_gt_bit (result, t));
9978 return;
9979 }
9980
b7053a3f
GK
9981 if (cond_code == NE
9982 || cond_code == GE || cond_code == LE
9983 || cond_code == GEU || cond_code == LEU
9984 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
9985 {
9986 rtx not_result = gen_reg_rtx (CCEQmode);
9987 rtx not_op, rev_cond_rtx;
9988 enum machine_mode cc_mode;
9989
9990 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
9991
1c563bed 9992 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 9993 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
9994 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
9995 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
9996 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
9997 }
39a10a29
GK
9998
9999 op_mode = GET_MODE (rs6000_compare_op0);
10000 if (op_mode == VOIDmode)
10001 op_mode = GET_MODE (rs6000_compare_op1);
10002
10003 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
10004 {
10005 PUT_MODE (condition_rtx, DImode);
10006 convert_move (result, condition_rtx, 0);
10007 }
10008 else
10009 {
10010 PUT_MODE (condition_rtx, SImode);
10011 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
10012 }
10013}
10014
39a10a29
GK
10015/* Emit a branch of kind CODE to location LOC. */
10016
10017void
a2369ed3 10018rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
10019{
10020 rtx condition_rtx, loc_ref;
10021
10022 condition_rtx = rs6000_generate_compare (code);
10023 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
10024 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
10025 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
10026 loc_ref, pc_rtx)));
10027}
10028
12a4e8c5
GK
10029/* Return the string to output a conditional branch to LABEL, which is
10030 the operand number of the label, or -1 if the branch is really a
10031 conditional return.
10032
10033 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
10034 condition code register and its mode specifies what kind of
10035 comparison we made.
10036
a0ab749a 10037 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
10038
10039 INSN is the insn. */
10040
10041char *
a2369ed3 10042output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
10043{
10044 static char string[64];
10045 enum rtx_code code = GET_CODE (op);
10046 rtx cc_reg = XEXP (op, 0);
10047 enum machine_mode mode = GET_MODE (cc_reg);
10048 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 10049 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
10050 int really_reversed = reversed ^ need_longbranch;
10051 char *s = string;
10052 const char *ccode;
10053 const char *pred;
10054 rtx note;
10055
39a10a29
GK
10056 validate_condition_mode (code, mode);
10057
10058 /* Work out which way this really branches. We could use
10059 reverse_condition_maybe_unordered here always but this
10060 makes the resulting assembler clearer. */
12a4e8c5 10061 if (really_reversed)
de40e1df
DJ
10062 {
10063 /* Reversal of FP compares takes care -- an ordered compare
10064 becomes an unordered compare and vice versa. */
10065 if (mode == CCFPmode)
10066 code = reverse_condition_maybe_unordered (code);
10067 else
10068 code = reverse_condition (code);
10069 }
12a4e8c5 10070
993f19a8 10071 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
10072 {
10073 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
10074 to the GT bit. */
10075 if (code == EQ)
10076 /* Opposite of GT. */
a3170dc6 10077 code = GT;
423c1189
AH
10078 else if (code == NE)
10079 code = UNLE;
a3170dc6
AH
10080 else
10081 abort ();
10082 }
10083
39a10a29 10084 switch (code)
12a4e8c5
GK
10085 {
10086 /* Not all of these are actually distinct opcodes, but
10087 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
10088 case NE: case LTGT:
10089 ccode = "ne"; break;
10090 case EQ: case UNEQ:
10091 ccode = "eq"; break;
10092 case GE: case GEU:
10093 ccode = "ge"; break;
10094 case GT: case GTU: case UNGT:
10095 ccode = "gt"; break;
10096 case LE: case LEU:
10097 ccode = "le"; break;
10098 case LT: case LTU: case UNLT:
10099 ccode = "lt"; break;
12a4e8c5
GK
10100 case UNORDERED: ccode = "un"; break;
10101 case ORDERED: ccode = "nu"; break;
10102 case UNGE: ccode = "nl"; break;
10103 case UNLE: ccode = "ng"; break;
10104 default:
a4f6c312 10105 abort ();
12a4e8c5
GK
10106 }
10107
94a54f47
GK
10108 /* Maybe we have a guess as to how likely the branch is.
10109 The old mnemonics don't have a way to specify this information. */
f4857b9b 10110 pred = "";
12a4e8c5
GK
10111 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
10112 if (note != NULL_RTX)
10113 {
10114 /* PROB is the difference from 50%. */
10115 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
10116
10117 /* Only hint for highly probable/improbable branches on newer
10118 cpus as static prediction overrides processor dynamic
10119 prediction. For older cpus we may as well always hint, but
10120 assume not taken for branches that are very close to 50% as a
10121 mispredicted taken branch is more expensive than a
10122 mispredicted not-taken branch. */
ec507f2d 10123 if (rs6000_always_hint
f4857b9b
AM
10124 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
10125 {
10126 if (abs (prob) > REG_BR_PROB_BASE / 20
10127 && ((prob > 0) ^ need_longbranch))
7f3d8013 10128 pred = "+";
f4857b9b
AM
10129 else
10130 pred = "-";
10131 }
12a4e8c5 10132 }
12a4e8c5
GK
10133
10134 if (label == NULL)
94a54f47 10135 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 10136 else
94a54f47 10137 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 10138
37c67319 10139 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 10140 Assume they'd only be the first character.... */
37c67319
GK
10141 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
10142 *s++ = '%';
94a54f47 10143 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
10144
10145 if (label != NULL)
10146 {
10147 /* If the branch distance was too far, we may have to use an
10148 unconditional branch to go the distance. */
10149 if (need_longbranch)
44518ddd 10150 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
10151 else
10152 s += sprintf (s, ",%s", label);
10153 }
10154
10155 return string;
10156}
50a0b056 10157
423c1189
AH
10158/* Return the string to flip the GT bit on a CR. */
10159char *
10160output_e500_flip_gt_bit (rtx dst, rtx src)
10161{
10162 static char string[64];
10163 int a, b;
10164
10165 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
10166 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
10167 abort ();
10168
10169 /* GT bit. */
10170 a = 4 * (REGNO (dst) - CR0_REGNO) + 1;
10171 b = 4 * (REGNO (src) - CR0_REGNO) + 1;
10172
10173 sprintf (string, "crnot %d,%d", a, b);
10174 return string;
10175}
10176
50a0b056
GK
10177/* Emit a conditional move: move TRUE_COND to DEST if OP of the
10178 operands of the last comparison is nonzero/true, FALSE_COND if it
10179 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 10180
50a0b056 10181int
a2369ed3 10182rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
10183{
10184 enum rtx_code code = GET_CODE (op);
10185 rtx op0 = rs6000_compare_op0;
10186 rtx op1 = rs6000_compare_op1;
10187 REAL_VALUE_TYPE c1;
3148ad6d
DJ
10188 enum machine_mode compare_mode = GET_MODE (op0);
10189 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
10190 rtx temp;
10191
a3c9585f 10192 /* These modes should always match. */
a3170dc6
AH
10193 if (GET_MODE (op1) != compare_mode
10194 /* In the isel case however, we can use a compare immediate, so
10195 op1 may be a small constant. */
10196 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 10197 return 0;
178c3eff 10198 if (GET_MODE (true_cond) != result_mode)
3148ad6d 10199 return 0;
178c3eff 10200 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
10201 return 0;
10202
50a0b056 10203 /* First, work out if the hardware can do this at all, or
a3c9585f 10204 if it's too slow.... */
50a0b056 10205 if (! rs6000_compare_fp_p)
a3170dc6
AH
10206 {
10207 if (TARGET_ISEL)
10208 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
10209 return 0;
10210 }
fef98bf2
AH
10211 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
10212 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
10213 return 0;
50a0b056
GK
10214
10215 /* Eliminate half of the comparisons by switching operands, this
10216 makes the remaining code simpler. */
10217 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 10218 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
10219 {
10220 code = reverse_condition_maybe_unordered (code);
10221 temp = true_cond;
10222 true_cond = false_cond;
10223 false_cond = temp;
10224 }
10225
10226 /* UNEQ and LTGT take four instructions for a comparison with zero,
10227 it'll probably be faster to use a branch here too. */
bc9ec0e0 10228 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
10229 return 0;
10230
10231 if (GET_CODE (op1) == CONST_DOUBLE)
10232 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
10233
b6d08ca1 10234 /* We're going to try to implement comparisons by performing
50a0b056
GK
10235 a subtract, then comparing against zero. Unfortunately,
10236 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 10237 know that the operand is finite and the comparison
50a0b056 10238 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 10239 if (HONOR_INFINITIES (compare_mode)
50a0b056 10240 && code != GT && code != UNGE
045572c7 10241 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
10242 /* Constructs of the form (a OP b ? a : b) are safe. */
10243 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
10244 || (! rtx_equal_p (op0, true_cond)
10245 && ! rtx_equal_p (op1, true_cond))))
10246 return 0;
10247 /* At this point we know we can use fsel. */
10248
10249 /* Reduce the comparison to a comparison against zero. */
3148ad6d 10250 temp = gen_reg_rtx (compare_mode);
50a0b056 10251 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10252 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 10253 op0 = temp;
3148ad6d 10254 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
10255
10256 /* If we don't care about NaNs we can reduce some of the comparisons
10257 down to faster ones. */
bc9ec0e0 10258 if (! HONOR_NANS (compare_mode))
50a0b056
GK
10259 switch (code)
10260 {
10261 case GT:
10262 code = LE;
10263 temp = true_cond;
10264 true_cond = false_cond;
10265 false_cond = temp;
10266 break;
10267 case UNGE:
10268 code = GE;
10269 break;
10270 case UNEQ:
10271 code = EQ;
10272 break;
10273 default:
10274 break;
10275 }
10276
10277 /* Now, reduce everything down to a GE. */
10278 switch (code)
10279 {
10280 case GE:
10281 break;
10282
10283 case LE:
3148ad6d
DJ
10284 temp = gen_reg_rtx (compare_mode);
10285 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10286 op0 = temp;
10287 break;
10288
10289 case ORDERED:
3148ad6d
DJ
10290 temp = gen_reg_rtx (compare_mode);
10291 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
10292 op0 = temp;
10293 break;
10294
10295 case EQ:
3148ad6d 10296 temp = gen_reg_rtx (compare_mode);
50a0b056 10297 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
10298 gen_rtx_NEG (compare_mode,
10299 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
10300 op0 = temp;
10301 break;
10302
10303 case UNGE:
bc9ec0e0 10304 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 10305 temp = gen_reg_rtx (result_mode);
50a0b056 10306 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10307 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10308 gen_rtx_GE (VOIDmode,
10309 op0, op1),
10310 true_cond, false_cond)));
bc9ec0e0
GK
10311 false_cond = true_cond;
10312 true_cond = temp;
50a0b056 10313
3148ad6d
DJ
10314 temp = gen_reg_rtx (compare_mode);
10315 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10316 op0 = temp;
10317 break;
10318
10319 case GT:
bc9ec0e0 10320 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 10321 temp = gen_reg_rtx (result_mode);
50a0b056 10322 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10323 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10324 gen_rtx_GE (VOIDmode,
10325 op0, op1),
10326 true_cond, false_cond)));
bc9ec0e0
GK
10327 true_cond = false_cond;
10328 false_cond = temp;
50a0b056 10329
3148ad6d
DJ
10330 temp = gen_reg_rtx (compare_mode);
10331 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10332 op0 = temp;
10333 break;
10334
10335 default:
10336 abort ();
10337 }
10338
10339 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 10340 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10341 gen_rtx_GE (VOIDmode,
10342 op0, op1),
10343 true_cond, false_cond)));
10344 return 1;
10345}
10346
a3170dc6
AH
10347/* Same as above, but for ints (isel). */
10348
10349static int
a2369ed3 10350rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
10351{
10352 rtx condition_rtx, cr;
10353
10354 /* All isel implementations thus far are 32-bits. */
10355 if (GET_MODE (rs6000_compare_op0) != SImode)
10356 return 0;
10357
10358 /* We still have to do the compare, because isel doesn't do a
10359 compare, it just looks at the CRx bits set by a previous compare
10360 instruction. */
10361 condition_rtx = rs6000_generate_compare (GET_CODE (op));
10362 cr = XEXP (condition_rtx, 0);
10363
10364 if (GET_MODE (cr) == CCmode)
10365 emit_insn (gen_isel_signed (dest, condition_rtx,
10366 true_cond, false_cond, cr));
10367 else
10368 emit_insn (gen_isel_unsigned (dest, condition_rtx,
10369 true_cond, false_cond, cr));
10370
10371 return 1;
10372}
10373
10374const char *
a2369ed3 10375output_isel (rtx *operands)
a3170dc6
AH
10376{
10377 enum rtx_code code;
10378
10379 code = GET_CODE (operands[1]);
10380 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
10381 {
10382 PUT_CODE (operands[1], reverse_condition (code));
10383 return "isel %0,%3,%2,%j1";
10384 }
10385 else
10386 return "isel %0,%2,%3,%j1";
10387}
10388
50a0b056 10389void
a2369ed3 10390rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
10391{
10392 enum machine_mode mode = GET_MODE (op0);
5dc8d536 10393 enum rtx_code c;
50a0b056 10394 rtx target;
5dc8d536
AH
10395
10396 if (code == SMAX || code == SMIN)
10397 c = GE;
10398 else
10399 c = GEU;
10400
50a0b056 10401 if (code == SMAX || code == UMAX)
5dc8d536 10402 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10403 op0, op1, mode, 0);
10404 else
5dc8d536 10405 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10406 op1, op0, mode, 0);
10407 if (target == NULL_RTX)
10408 abort ();
10409 if (target != dest)
10410 emit_move_insn (dest, target);
10411}
46c07df8 10412
a9baceb1
GK
10413/* Emit instructions to move SRC to DST. Called by splitters for
10414 multi-register moves. It will emit at most one instruction for
10415 each register that is accessed; that is, it won't emit li/lis pairs
10416 (or equivalent for 64-bit code). One of SRC or DST must be a hard
10417 register. */
46c07df8 10418
46c07df8 10419void
a9baceb1 10420rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 10421{
a9baceb1
GK
10422 /* The register number of the first register being moved. */
10423 int reg;
10424 /* The mode that is to be moved. */
10425 enum machine_mode mode;
10426 /* The mode that the move is being done in, and its size. */
10427 enum machine_mode reg_mode;
10428 int reg_mode_size;
10429 /* The number of registers that will be moved. */
10430 int nregs;
10431
10432 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
10433 mode = GET_MODE (dst);
10434 nregs = HARD_REGNO_NREGS (reg, mode);
10435 if (FP_REGNO_P (reg))
10436 reg_mode = DFmode;
10437 else if (ALTIVEC_REGNO_P (reg))
10438 reg_mode = V16QImode;
10439 else
10440 reg_mode = word_mode;
10441 reg_mode_size = GET_MODE_SIZE (reg_mode);
46c07df8 10442
a9baceb1
GK
10443 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
10444 abort ();
10445
10446 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
10447 {
10448 /* Move register range backwards, if we might have destructive
10449 overlap. */
10450 int i;
10451 for (i = nregs - 1; i >= 0; i--)
10452 emit_insn (gen_rtx_SET (VOIDmode,
10453 simplify_gen_subreg (reg_mode, dst, mode,
10454 i * reg_mode_size),
10455 simplify_gen_subreg (reg_mode, src, mode,
10456 i * reg_mode_size)));
10457 }
46c07df8
HP
10458 else
10459 {
a9baceb1
GK
10460 int i;
10461 int j = -1;
10462 bool used_update = false;
46c07df8 10463
a9baceb1 10464 if (GET_CODE (src) == MEM && INT_REGNO_P (reg))
46c07df8
HP
10465 {
10466 rtx breg;
3a1f863f 10467
a9baceb1
GK
10468 if (GET_CODE (XEXP (src, 0)) == PRE_INC
10469 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
10470 {
10471 rtx delta_rtx;
a9baceb1
GK
10472 breg = XEXP (XEXP (src, 0), 0);
10473 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
10474 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
10475 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
10476 emit_insn (TARGET_32BIT
10477 ? gen_addsi3 (breg, breg, delta_rtx)
10478 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10479 src = gen_rtx_MEM (mode, breg);
10480 }
10481
10482 /* We have now address involving an base register only.
10483 If we use one of the registers to address memory,
10484 we have change that register last. */
10485
10486 breg = (GET_CODE (XEXP (src, 0)) == PLUS
10487 ? XEXP (XEXP (src, 0), 0)
10488 : XEXP (src, 0));
10489
10490 if (!REG_P (breg))
10491 abort();
10492
10493 if (REGNO (breg) >= REGNO (dst)
10494 && REGNO (breg) < REGNO (dst) + nregs)
10495 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
10496 }
10497
a9baceb1 10498 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
10499 {
10500 rtx breg;
10501
a9baceb1
GK
10502 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
10503 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
10504 {
10505 rtx delta_rtx;
a9baceb1
GK
10506 breg = XEXP (XEXP (dst, 0), 0);
10507 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
10508 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
10509 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
10510
10511 /* We have to update the breg before doing the store.
10512 Use store with update, if available. */
10513
10514 if (TARGET_UPDATE)
10515 {
a9baceb1
GK
10516 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
10517 emit_insn (TARGET_32BIT
10518 ? gen_movsi_update (breg, breg, delta_rtx, nsrc)
10519 : gen_movdi_update (breg, breg, delta_rtx, nsrc));
10520 used_update = true;
3a1f863f
DE
10521 }
10522 else
a9baceb1
GK
10523 emit_insn (TARGET_32BIT
10524 ? gen_addsi3 (breg, breg, delta_rtx)
10525 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10526 dst = gen_rtx_MEM (mode, breg);
10527 }
10528 }
10529
46c07df8 10530 for (i = 0; i < nregs; i++)
3a1f863f
DE
10531 {
10532 /* Calculate index to next subword. */
10533 ++j;
10534 if (j == nregs)
10535 j = 0;
46c07df8 10536
a9baceb1
GK
10537 /* If compiler already emited move of first word by
10538 store with update, no need to do anything. */
3a1f863f 10539 if (j == 0 && used_update)
a9baceb1
GK
10540 continue;
10541
10542 emit_insn (gen_rtx_SET (VOIDmode,
10543 simplify_gen_subreg (reg_mode, dst, mode,
10544 j * reg_mode_size),
10545 simplify_gen_subreg (reg_mode, src, mode,
10546 j * reg_mode_size)));
3a1f863f 10547 }
46c07df8
HP
10548 }
10549}
10550
12a4e8c5 10551\f
a4f6c312
SS
10552/* This page contains routines that are used to determine what the
10553 function prologue and epilogue code will do and write them out. */
9878760c 10554
a4f6c312
SS
10555/* Return the first fixed-point register that is required to be
10556 saved. 32 if none. */
9878760c
RK
10557
10558int
863d938c 10559first_reg_to_save (void)
9878760c
RK
10560{
10561 int first_reg;
10562
10563 /* Find lowest numbered live register. */
10564 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
10565 if (regs_ever_live[first_reg]
10566 && (! call_used_regs[first_reg]
1db02437 10567 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10568 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10569 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
10570 break;
10571
ee890fe2 10572#if TARGET_MACHO
93638d7a
AM
10573 if (flag_pic
10574 && current_function_uses_pic_offset_table
10575 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 10576 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
10577#endif
10578
9878760c
RK
10579 return first_reg;
10580}
10581
10582/* Similar, for FP regs. */
10583
10584int
863d938c 10585first_fp_reg_to_save (void)
9878760c
RK
10586{
10587 int first_reg;
10588
10589 /* Find lowest numbered live register. */
10590 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
10591 if (regs_ever_live[first_reg])
10592 break;
10593
10594 return first_reg;
10595}
00b960c7
AH
10596
10597/* Similar, for AltiVec regs. */
10598
10599static int
863d938c 10600first_altivec_reg_to_save (void)
00b960c7
AH
10601{
10602 int i;
10603
10604 /* Stack frame remains as is unless we are in AltiVec ABI. */
10605 if (! TARGET_ALTIVEC_ABI)
10606 return LAST_ALTIVEC_REGNO + 1;
10607
10608 /* Find lowest numbered live register. */
10609 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
10610 if (regs_ever_live[i])
10611 break;
10612
10613 return i;
10614}
10615
10616/* Return a 32-bit mask of the AltiVec registers we need to set in
10617 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
10618 the 32-bit word is 0. */
10619
10620static unsigned int
863d938c 10621compute_vrsave_mask (void)
00b960c7
AH
10622{
10623 unsigned int i, mask = 0;
10624
10625 /* First, find out if we use _any_ altivec registers. */
10626 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10627 if (regs_ever_live[i])
10628 mask |= ALTIVEC_REG_BIT (i);
10629
10630 if (mask == 0)
10631 return mask;
10632
00b960c7
AH
10633 /* Next, remove the argument registers from the set. These must
10634 be in the VRSAVE mask set by the caller, so we don't need to add
10635 them in again. More importantly, the mask we compute here is
10636 used to generate CLOBBERs in the set_vrsave insn, and we do not
10637 wish the argument registers to die. */
a6cf80f2 10638 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
10639 mask &= ~ALTIVEC_REG_BIT (i);
10640
10641 /* Similarly, remove the return value from the set. */
10642 {
10643 bool yes = false;
10644 diddle_return_value (is_altivec_return_reg, &yes);
10645 if (yes)
10646 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
10647 }
10648
10649 return mask;
10650}
10651
10652static void
a2369ed3 10653is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
10654{
10655 bool *yes = (bool *) xyes;
10656 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
10657 *yes = true;
10658}
10659
4697a36c
MM
10660\f
10661/* Calculate the stack information for the current function. This is
10662 complicated by having two separate calling sequences, the AIX calling
10663 sequence and the V.4 calling sequence.
10664
592696dd 10665 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 10666 32-bit 64-bit
4697a36c 10667 SP----> +---------------------------------------+
a260abc9 10668 | back chain to caller | 0 0
4697a36c 10669 +---------------------------------------+
a260abc9 10670 | saved CR | 4 8 (8-11)
4697a36c 10671 +---------------------------------------+
a260abc9 10672 | saved LR | 8 16
4697a36c 10673 +---------------------------------------+
a260abc9 10674 | reserved for compilers | 12 24
4697a36c 10675 +---------------------------------------+
a260abc9 10676 | reserved for binders | 16 32
4697a36c 10677 +---------------------------------------+
a260abc9 10678 | saved TOC pointer | 20 40
4697a36c 10679 +---------------------------------------+
a260abc9 10680 | Parameter save area (P) | 24 48
4697a36c 10681 +---------------------------------------+
a260abc9 10682 | Alloca space (A) | 24+P etc.
802a0058 10683 +---------------------------------------+
a7df97e6 10684 | Local variable space (L) | 24+P+A
4697a36c 10685 +---------------------------------------+
a7df97e6 10686 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 10687 +---------------------------------------+
00b960c7
AH
10688 | Save area for AltiVec registers (W) | 24+P+A+L+X
10689 +---------------------------------------+
10690 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
10691 +---------------------------------------+
10692 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 10693 +---------------------------------------+
00b960c7
AH
10694 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
10695 +---------------------------------------+
10696 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
10697 +---------------------------------------+
10698 old SP->| back chain to caller's caller |
10699 +---------------------------------------+
10700
5376a30c
KR
10701 The required alignment for AIX configurations is two words (i.e., 8
10702 or 16 bytes).
10703
10704
4697a36c
MM
10705 V.4 stack frames look like:
10706
10707 SP----> +---------------------------------------+
10708 | back chain to caller | 0
10709 +---------------------------------------+
5eb387b8 10710 | caller's saved LR | 4
4697a36c
MM
10711 +---------------------------------------+
10712 | Parameter save area (P) | 8
10713 +---------------------------------------+
a7df97e6
MM
10714 | Alloca space (A) | 8+P
10715 +---------------------------------------+
10716 | Varargs save area (V) | 8+P+A
10717 +---------------------------------------+
10718 | Local variable space (L) | 8+P+A+V
10719 +---------------------------------------+
10720 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10721 +---------------------------------------+
00b960c7
AH
10722 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10723 +---------------------------------------+
10724 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10725 +---------------------------------------+
10726 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10727 +---------------------------------------+
a3170dc6
AH
10728 | SPE: area for 64-bit GP registers |
10729 +---------------------------------------+
10730 | SPE alignment padding |
10731 +---------------------------------------+
00b960c7 10732 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10733 +---------------------------------------+
00b960c7 10734 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10735 +---------------------------------------+
00b960c7 10736 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10737 +---------------------------------------+
10738 old SP->| back chain to caller's caller |
10739 +---------------------------------------+
b6c9286a 10740
5376a30c
KR
10741 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10742 given. (But note below and in sysv4.h that we require only 8 and
10743 may round up the size of our stack frame anyways. The historical
10744 reason is early versions of powerpc-linux which didn't properly
10745 align the stack at program startup. A happy side-effect is that
10746 -mno-eabi libraries can be used with -meabi programs.)
10747
50d440bc 10748 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10749 the stack alignment requirements may differ. If -mno-eabi is not
10750 given, the required stack alignment is 8 bytes; if -mno-eabi is
10751 given, the required alignment is 16 bytes. (But see V.4 comment
10752 above.) */
4697a36c 10753
61b2fbe7
MM
10754#ifndef ABI_STACK_BOUNDARY
10755#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10756#endif
10757
d1d0c603 10758static rs6000_stack_t *
863d938c 10759rs6000_stack_info (void)
4697a36c
MM
10760{
10761 static rs6000_stack_t info, zero_info;
10762 rs6000_stack_t *info_ptr = &info;
327e5343 10763 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 10764 int ehrd_size;
d1d0c603 10765 HOST_WIDE_INT total_raw_size;
4697a36c 10766
a4f6c312 10767 /* Zero all fields portably. */
4697a36c
MM
10768 info = zero_info;
10769
c19de7aa
AH
10770 if (TARGET_SPE)
10771 {
10772 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10773 if (cfun->machine->insn_chain_scanned_p == 0)
10774 {
10775 cfun->machine->insn_chain_scanned_p = 1;
10776 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10777 }
c19de7aa
AH
10778 }
10779
a4f6c312 10780 /* Select which calling sequence. */
178274da 10781 info_ptr->abi = DEFAULT_ABI;
9878760c 10782
a4f6c312 10783 /* Calculate which registers need to be saved & save area size. */
4697a36c 10784 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10785 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10786 even if it currently looks like we won't. */
2bfcf297 10787 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10788 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10789 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10790 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
10791 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
10792 else
10793 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 10794
a3170dc6
AH
10795 /* For the SPE, we have an additional upper 32-bits on each GPR.
10796 Ideally we should save the entire 64-bits only when the upper
10797 half is used in SIMD instructions. Since we only record
10798 registers live (not the size they are used in), this proves
10799 difficult because we'd have to traverse the instruction chain at
10800 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
10801 so we opt to save the GPRs in 64-bits always if but one register
10802 gets used in 64-bits. Otherwise, all the registers in the frame
10803 get saved in 32-bits.
a3170dc6 10804
c19de7aa 10805 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 10806 traditional GP save area will be empty. */
c19de7aa 10807 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10808 info_ptr->gp_size = 0;
10809
4697a36c
MM
10810 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
10811 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
10812
00b960c7
AH
10813 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
10814 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
10815 - info_ptr->first_altivec_reg_save);
10816
592696dd 10817 /* Does this function call anything? */
71f123ca
FS
10818 info_ptr->calls_p = (! current_function_is_leaf
10819 || cfun->machine->ra_needs_full_frame);
b6c9286a 10820
a4f6c312 10821 /* Determine if we need to save the link register. */
71f123ca 10822 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
10823 || (DEFAULT_ABI == ABI_AIX
10824 && current_function_profile
10825 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
10826#ifdef TARGET_RELOCATABLE
10827 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
10828#endif
10829 || (info_ptr->first_fp_reg_save != 64
10830 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 10831 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 10832 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
10833 || (DEFAULT_ABI == ABI_DARWIN
10834 && flag_pic
10835 && current_function_uses_pic_offset_table)
4697a36c
MM
10836 || info_ptr->calls_p)
10837 {
10838 info_ptr->lr_save_p = 1;
9ebbca7d 10839 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
10840 }
10841
9ebbca7d
GK
10842 /* Determine if we need to save the condition code registers. */
10843 if (regs_ever_live[CR2_REGNO]
10844 || regs_ever_live[CR3_REGNO]
10845 || regs_ever_live[CR4_REGNO])
4697a36c
MM
10846 {
10847 info_ptr->cr_save_p = 1;
178274da 10848 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
10849 info_ptr->cr_size = reg_size;
10850 }
10851
83720594
RH
10852 /* If the current function calls __builtin_eh_return, then we need
10853 to allocate stack space for registers that will hold data for
10854 the exception handler. */
10855 if (current_function_calls_eh_return)
10856 {
10857 unsigned int i;
10858 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
10859 continue;
a3170dc6
AH
10860
10861 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
10862 ehrd_size = i * (TARGET_SPE_ABI
10863 && info_ptr->spe_64bit_regs_used != 0
10864 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
10865 }
10866 else
10867 ehrd_size = 0;
10868
592696dd 10869 /* Determine various sizes. */
4697a36c
MM
10870 info_ptr->reg_size = reg_size;
10871 info_ptr->fixed_size = RS6000_SAVE_AREA;
10872 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 10873 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 10874 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 10875 TARGET_ALTIVEC ? 16 : 8);
00b960c7 10876
c19de7aa 10877 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10878 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
10879 else
10880 info_ptr->spe_gp_size = 0;
10881
4d774ff8
HP
10882 if (TARGET_ALTIVEC_ABI)
10883 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 10884 else
4d774ff8
HP
10885 info_ptr->vrsave_mask = 0;
10886
10887 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
10888 info_ptr->vrsave_size = 4;
10889 else
10890 info_ptr->vrsave_size = 0;
b6c9286a 10891
592696dd 10892 /* Calculate the offsets. */
178274da 10893 switch (DEFAULT_ABI)
4697a36c 10894 {
b6c9286a 10895 case ABI_NONE:
24d304eb 10896 default:
b6c9286a
MM
10897 abort ();
10898
10899 case ABI_AIX:
ee890fe2 10900 case ABI_DARWIN:
b6c9286a
MM
10901 info_ptr->fp_save_offset = - info_ptr->fp_size;
10902 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
10903
10904 if (TARGET_ALTIVEC_ABI)
10905 {
10906 info_ptr->vrsave_save_offset
10907 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
10908
10909 /* Align stack so vector save area is on a quadword boundary. */
10910 if (info_ptr->altivec_size != 0)
10911 info_ptr->altivec_padding_size
10912 = 16 - (-info_ptr->vrsave_save_offset % 16);
10913 else
10914 info_ptr->altivec_padding_size = 0;
10915
10916 info_ptr->altivec_save_offset
10917 = info_ptr->vrsave_save_offset
10918 - info_ptr->altivec_padding_size
10919 - info_ptr->altivec_size;
10920
10921 /* Adjust for AltiVec case. */
10922 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
10923 }
10924 else
10925 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
10926 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
10927 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
10928 break;
10929
10930 case ABI_V4:
b6c9286a
MM
10931 info_ptr->fp_save_offset = - info_ptr->fp_size;
10932 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 10933 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 10934
c19de7aa 10935 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10936 {
10937 /* Align stack so SPE GPR save area is aligned on a
10938 double-word boundary. */
10939 if (info_ptr->spe_gp_size != 0)
10940 info_ptr->spe_padding_size
10941 = 8 - (-info_ptr->cr_save_offset % 8);
10942 else
10943 info_ptr->spe_padding_size = 0;
10944
10945 info_ptr->spe_gp_save_offset
10946 = info_ptr->cr_save_offset
10947 - info_ptr->spe_padding_size
10948 - info_ptr->spe_gp_size;
10949
10950 /* Adjust for SPE case. */
10951 info_ptr->toc_save_offset
10952 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
10953 }
10954 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
10955 {
10956 info_ptr->vrsave_save_offset
10957 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
10958
10959 /* Align stack so vector save area is on a quadword boundary. */
10960 if (info_ptr->altivec_size != 0)
10961 info_ptr->altivec_padding_size
10962 = 16 - (-info_ptr->vrsave_save_offset % 16);
10963 else
10964 info_ptr->altivec_padding_size = 0;
10965
10966 info_ptr->altivec_save_offset
10967 = info_ptr->vrsave_save_offset
10968 - info_ptr->altivec_padding_size
10969 - info_ptr->altivec_size;
10970
10971 /* Adjust for AltiVec case. */
10972 info_ptr->toc_save_offset
10973 = info_ptr->altivec_save_offset - info_ptr->toc_size;
10974 }
10975 else
10976 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 10977 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
10978 info_ptr->lr_save_offset = reg_size;
10979 break;
4697a36c
MM
10980 }
10981
00b960c7
AH
10982 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
10983 + info_ptr->gp_size
10984 + info_ptr->altivec_size
10985 + info_ptr->altivec_padding_size
a3170dc6
AH
10986 + info_ptr->spe_gp_size
10987 + info_ptr->spe_padding_size
00b960c7
AH
10988 + ehrd_size
10989 + info_ptr->cr_size
10990 + info_ptr->lr_size
10991 + info_ptr->vrsave_size
10992 + info_ptr->toc_size,
10993 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
10994 ? 16 : 8);
10995
ff381587
MM
10996 total_raw_size = (info_ptr->vars_size
10997 + info_ptr->parm_size
ff381587
MM
10998 + info_ptr->save_size
10999 + info_ptr->varargs_size
11000 + info_ptr->fixed_size);
11001
a4f6c312
SS
11002 info_ptr->total_size =
11003 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
11004
11005 /* Determine if we need to allocate any stack frame:
11006
a4f6c312
SS
11007 For AIX we need to push the stack if a frame pointer is needed
11008 (because the stack might be dynamically adjusted), if we are
11009 debugging, if we make calls, or if the sum of fp_save, gp_save,
11010 and local variables are more than the space needed to save all
11011 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
11012 + 18*8 = 288 (GPR13 reserved).
ff381587 11013
a4f6c312
SS
11014 For V.4 we don't have the stack cushion that AIX uses, but assume
11015 that the debugger can handle stackless frames. */
ff381587
MM
11016
11017 if (info_ptr->calls_p)
11018 info_ptr->push_p = 1;
11019
178274da 11020 else if (DEFAULT_ABI == ABI_V4)
e72247f4 11021 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587 11022
178274da
AM
11023 else if (frame_pointer_needed)
11024 info_ptr->push_p = 1;
11025
11026 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
11027 info_ptr->push_p = 1;
11028
ff381587 11029 else
178274da
AM
11030 info_ptr->push_p
11031 = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 11032
a4f6c312 11033 /* Zero offsets if we're not saving those registers. */
8dda1a21 11034 if (info_ptr->fp_size == 0)
4697a36c
MM
11035 info_ptr->fp_save_offset = 0;
11036
8dda1a21 11037 if (info_ptr->gp_size == 0)
4697a36c
MM
11038 info_ptr->gp_save_offset = 0;
11039
00b960c7
AH
11040 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
11041 info_ptr->altivec_save_offset = 0;
11042
11043 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
11044 info_ptr->vrsave_save_offset = 0;
11045
c19de7aa
AH
11046 if (! TARGET_SPE_ABI
11047 || info_ptr->spe_64bit_regs_used == 0
11048 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
11049 info_ptr->spe_gp_save_offset = 0;
11050
c81fc13e 11051 if (! info_ptr->lr_save_p)
4697a36c
MM
11052 info_ptr->lr_save_offset = 0;
11053
c81fc13e 11054 if (! info_ptr->cr_save_p)
4697a36c
MM
11055 info_ptr->cr_save_offset = 0;
11056
c81fc13e 11057 if (! info_ptr->toc_save_p)
b6c9286a
MM
11058 info_ptr->toc_save_offset = 0;
11059
4697a36c
MM
11060 return info_ptr;
11061}
11062
c19de7aa
AH
11063/* Return true if the current function uses any GPRs in 64-bit SIMD
11064 mode. */
11065
11066static bool
863d938c 11067spe_func_has_64bit_regs_p (void)
c19de7aa
AH
11068{
11069 rtx insns, insn;
11070
11071 /* Functions that save and restore all the call-saved registers will
11072 need to save/restore the registers in 64-bits. */
11073 if (current_function_calls_eh_return
11074 || current_function_calls_setjmp
11075 || current_function_has_nonlocal_goto)
11076 return true;
11077
11078 insns = get_insns ();
11079
11080 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
11081 {
11082 if (INSN_P (insn))
11083 {
11084 rtx i;
11085
11086 i = PATTERN (insn);
11087 if (GET_CODE (i) == SET
11088 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
11089 return true;
11090 }
11091 }
11092
11093 return false;
11094}
11095
d1d0c603 11096static void
a2369ed3 11097debug_stack_info (rs6000_stack_t *info)
9878760c 11098{
d330fd93 11099 const char *abi_string;
24d304eb 11100
c81fc13e 11101 if (! info)
4697a36c
MM
11102 info = rs6000_stack_info ();
11103
11104 fprintf (stderr, "\nStack information for function %s:\n",
11105 ((current_function_decl && DECL_NAME (current_function_decl))
11106 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
11107 : "<unknown>"));
11108
24d304eb
RK
11109 switch (info->abi)
11110 {
b6c9286a
MM
11111 default: abi_string = "Unknown"; break;
11112 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 11113 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 11114 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 11115 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
11116 }
11117
11118 fprintf (stderr, "\tABI = %5s\n", abi_string);
11119
00b960c7
AH
11120 if (TARGET_ALTIVEC_ABI)
11121 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
11122
a3170dc6
AH
11123 if (TARGET_SPE_ABI)
11124 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
11125
4697a36c
MM
11126 if (info->first_gp_reg_save != 32)
11127 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
11128
11129 if (info->first_fp_reg_save != 64)
11130 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 11131
00b960c7
AH
11132 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
11133 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
11134 info->first_altivec_reg_save);
11135
4697a36c
MM
11136 if (info->lr_save_p)
11137 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 11138
4697a36c
MM
11139 if (info->cr_save_p)
11140 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
11141
b6c9286a
MM
11142 if (info->toc_save_p)
11143 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
11144
00b960c7
AH
11145 if (info->vrsave_mask)
11146 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
11147
4697a36c
MM
11148 if (info->push_p)
11149 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
11150
11151 if (info->calls_p)
11152 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
11153
4697a36c
MM
11154 if (info->gp_save_offset)
11155 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
11156
11157 if (info->fp_save_offset)
11158 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
11159
00b960c7
AH
11160 if (info->altivec_save_offset)
11161 fprintf (stderr, "\taltivec_save_offset = %5d\n",
11162 info->altivec_save_offset);
11163
a3170dc6
AH
11164 if (info->spe_gp_save_offset)
11165 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
11166 info->spe_gp_save_offset);
11167
00b960c7
AH
11168 if (info->vrsave_save_offset)
11169 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
11170 info->vrsave_save_offset);
11171
4697a36c
MM
11172 if (info->lr_save_offset)
11173 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
11174
11175 if (info->cr_save_offset)
11176 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
11177
b6c9286a
MM
11178 if (info->toc_save_offset)
11179 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
11180
4697a36c
MM
11181 if (info->varargs_save_offset)
11182 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
11183
11184 if (info->total_size)
d1d0c603
JJ
11185 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11186 info->total_size);
4697a36c
MM
11187
11188 if (info->varargs_size)
11189 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
11190
11191 if (info->vars_size)
d1d0c603
JJ
11192 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11193 info->vars_size);
4697a36c
MM
11194
11195 if (info->parm_size)
11196 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
11197
11198 if (info->fixed_size)
11199 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
11200
11201 if (info->gp_size)
11202 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
11203
a3170dc6
AH
11204 if (info->spe_gp_size)
11205 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
11206
4697a36c
MM
11207 if (info->fp_size)
11208 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
11209
00b960c7
AH
11210 if (info->altivec_size)
11211 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
11212
11213 if (info->vrsave_size)
11214 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
11215
11216 if (info->altivec_padding_size)
11217 fprintf (stderr, "\taltivec_padding_size= %5d\n",
11218 info->altivec_padding_size);
11219
a3170dc6
AH
11220 if (info->spe_padding_size)
11221 fprintf (stderr, "\tspe_padding_size = %5d\n",
11222 info->spe_padding_size);
11223
a4f6c312 11224 if (info->lr_size)
ed947a96 11225 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 11226
4697a36c
MM
11227 if (info->cr_size)
11228 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
11229
a4f6c312 11230 if (info->toc_size)
b6c9286a
MM
11231 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
11232
4697a36c
MM
11233 if (info->save_size)
11234 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
11235
11236 if (info->reg_size != 4)
11237 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
11238
11239 fprintf (stderr, "\n");
9878760c 11240}
71f123ca
FS
11241
11242rtx
a2369ed3 11243rs6000_return_addr (int count, rtx frame)
71f123ca 11244{
a4f6c312
SS
11245 /* Currently we don't optimize very well between prolog and body
11246 code and for PIC code the code can be actually quite bad, so
11247 don't try to be too clever here. */
f1384257 11248 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
11249 {
11250 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
11251
11252 return
11253 gen_rtx_MEM
11254 (Pmode,
11255 memory_address
11256 (Pmode,
11257 plus_constant (copy_to_reg
11258 (gen_rtx_MEM (Pmode,
11259 memory_address (Pmode, frame))),
11260 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
11261 }
11262
8c29550d 11263 cfun->machine->ra_need_lr = 1;
9e2f7ec7 11264 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
11265}
11266
5e1bf043
DJ
11267/* Say whether a function is a candidate for sibcall handling or not.
11268 We do not allow indirect calls to be optimized into sibling calls.
11269 Also, we can't do it if there are any vector parameters; there's
11270 nowhere to put the VRsave code so it works; note that functions with
11271 vector parameters are required to have a prototype, so the argument
11272 type info must be available here. (The tail recursion case can work
11273 with vector parameters, but there's no way to distinguish here.) */
4977bab6 11274static bool
a2369ed3 11275rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
11276{
11277 tree type;
4977bab6 11278 if (decl)
5e1bf043
DJ
11279 {
11280 if (TARGET_ALTIVEC_VRSAVE)
11281 {
4977bab6 11282 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
11283 type; type = TREE_CHAIN (type))
11284 {
c15b529f 11285 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 11286 return false;
5e1bf043
DJ
11287 }
11288 }
11289 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 11290 || (*targetm.binds_local_p) (decl))
2bcc50d0 11291 {
4977bab6 11292 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
11293
11294 if (!lookup_attribute ("longcall", attr_list)
11295 || lookup_attribute ("shortcall", attr_list))
4977bab6 11296 return true;
2bcc50d0 11297 }
5e1bf043 11298 }
4977bab6 11299 return false;
5e1bf043
DJ
11300}
11301
71f123ca 11302static int
863d938c 11303rs6000_ra_ever_killed (void)
71f123ca
FS
11304{
11305 rtx top;
5e1bf043
DJ
11306 rtx reg;
11307 rtx insn;
71f123ca 11308
dd292d0a 11309 if (current_function_is_thunk)
71f123ca 11310 return 0;
eb0424da 11311
36f7e964
AH
11312 /* regs_ever_live has LR marked as used if any sibcalls are present,
11313 but this should not force saving and restoring in the
11314 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 11315 clobbers LR, so that is inappropriate. */
36f7e964 11316
5e1bf043
DJ
11317 /* Also, the prologue can generate a store into LR that
11318 doesn't really count, like this:
36f7e964 11319
5e1bf043
DJ
11320 move LR->R0
11321 bcl to set PIC register
11322 move LR->R31
11323 move R0->LR
36f7e964
AH
11324
11325 When we're called from the epilogue, we need to avoid counting
11326 this as a store. */
5e1bf043 11327
71f123ca
FS
11328 push_topmost_sequence ();
11329 top = get_insns ();
11330 pop_topmost_sequence ();
5e1bf043 11331 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 11332
5e1bf043
DJ
11333 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
11334 {
11335 if (INSN_P (insn))
11336 {
11337 if (FIND_REG_INC_NOTE (insn, reg))
11338 return 1;
11339 else if (GET_CODE (insn) == CALL_INSN
c15b529f 11340 && !SIBLING_CALL_P (insn))
5e1bf043 11341 return 1;
36f7e964
AH
11342 else if (set_of (reg, insn) != NULL_RTX
11343 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
11344 return 1;
11345 }
11346 }
11347 return 0;
71f123ca 11348}
4697a36c 11349\f
8cd8f856
GK
11350/* Add a REG_MAYBE_DEAD note to the insn. */
11351static void
a2369ed3 11352rs6000_maybe_dead (rtx insn)
8cd8f856
GK
11353{
11354 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
11355 const0_rtx,
11356 REG_NOTES (insn));
11357}
11358
9ebbca7d 11359/* Emit instructions needed to load the TOC register.
c7ca610e 11360 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 11361 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
11362
11363void
a2369ed3 11364rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 11365{
027fbf43 11366 rtx dest, insn;
1db02437 11367 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 11368
20b71b17
AM
11369 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11370 {
11371 rtx temp = (fromprolog
11372 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11373 : gen_reg_rtx (Pmode));
027fbf43
JJ
11374 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
11375 if (fromprolog)
11376 rs6000_maybe_dead (insn);
11377 insn = emit_move_insn (dest, temp);
11378 if (fromprolog)
11379 rs6000_maybe_dead (insn);
20b71b17
AM
11380 }
11381 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
11382 {
11383 char buf[30];
11384 rtx tempLR = (fromprolog
11385 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11386 : gen_reg_rtx (Pmode));
11387 rtx temp0 = (fromprolog
11388 ? gen_rtx_REG (Pmode, 0)
11389 : gen_reg_rtx (Pmode));
11390 rtx symF;
11391
11392 /* possibly create the toc section */
11393 if (! toc_initialized)
38c1f2d7 11394 {
20b71b17
AM
11395 toc_section ();
11396 function_section (current_function_decl);
38c1f2d7 11397 }
9ebbca7d 11398
20b71b17
AM
11399 if (fromprolog)
11400 {
11401 rtx symL;
38c1f2d7 11402
20b71b17
AM
11403 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
11404 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 11405
20b71b17
AM
11406 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
11407 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11408
11409 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
11410 symF)));
11411 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
11412 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
11413 symL,
11414 symF)));
9ebbca7d
GK
11415 }
11416 else
20b71b17
AM
11417 {
11418 rtx tocsym;
11419 static int reload_toc_labelno = 0;
11420
11421 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
11422
11423 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
11424 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11425
027fbf43
JJ
11426 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
11427 emit_move_insn (dest, tempLR);
11428 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 11429 }
027fbf43
JJ
11430 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
11431 if (fromprolog)
11432 rs6000_maybe_dead (insn);
9ebbca7d 11433 }
20b71b17
AM
11434 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
11435 {
11436 /* This is for AIX code running in non-PIC ELF32. */
11437 char buf[30];
11438 rtx realsym;
11439 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11440 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11441
027fbf43
JJ
11442 insn = emit_insn (gen_elf_high (dest, realsym));
11443 if (fromprolog)
11444 rs6000_maybe_dead (insn);
11445 insn = emit_insn (gen_elf_low (dest, dest, realsym));
11446 if (fromprolog)
11447 rs6000_maybe_dead (insn);
20b71b17
AM
11448 }
11449 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
11450 {
11451 if (TARGET_32BIT)
027fbf43 11452 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 11453 else
027fbf43
JJ
11454 insn = emit_insn (gen_load_toc_aix_di (dest));
11455 if (fromprolog)
11456 rs6000_maybe_dead (insn);
9ebbca7d 11457 }
20b71b17
AM
11458 else
11459 abort ();
9ebbca7d
GK
11460}
11461
d1d0c603
JJ
11462/* Emit instructions to restore the link register after determining where
11463 its value has been stored. */
11464
11465void
11466rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
11467{
11468 rs6000_stack_t *info = rs6000_stack_info ();
11469 rtx operands[2];
11470
11471 operands[0] = source;
11472 operands[1] = scratch;
11473
11474 if (info->lr_save_p)
11475 {
11476 rtx frame_rtx = stack_pointer_rtx;
11477 HOST_WIDE_INT sp_offset = 0;
11478 rtx tmp;
11479
11480 if (frame_pointer_needed
11481 || current_function_calls_alloca
11482 || info->total_size > 32767)
11483 {
11484 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
11485 frame_rtx = operands[1];
11486 }
11487 else if (info->push_p)
11488 sp_offset = info->total_size;
11489
11490 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
11491 tmp = gen_rtx_MEM (Pmode, tmp);
11492 emit_move_insn (tmp, operands[0]);
11493 }
11494 else
11495 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
11496}
11497
f103e34d
GK
11498static GTY(()) int set = -1;
11499
9ebbca7d 11500int
863d938c 11501get_TOC_alias_set (void)
9ebbca7d 11502{
f103e34d
GK
11503 if (set == -1)
11504 set = new_alias_set ();
11505 return set;
9ebbca7d
GK
11506}
11507
c1207243 11508/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
11509 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
11510 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 11511#if TARGET_ELF
3c9eb5f4 11512static int
38f391a5 11513uses_TOC (void)
9ebbca7d 11514{
c4501e62 11515 rtx insn;
38c1f2d7 11516
c4501e62
JJ
11517 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11518 if (INSN_P (insn))
11519 {
11520 rtx pat = PATTERN (insn);
11521 int i;
9ebbca7d 11522
c4501e62
JJ
11523 if (GET_CODE (pat) == PARALLEL)
11524 for (i = 0; i < XVECLEN (pat, 0); i++)
11525 {
11526 rtx sub = XVECEXP (pat, 0, i);
11527 if (GET_CODE (sub) == USE)
11528 {
11529 sub = XEXP (sub, 0);
11530 if (GET_CODE (sub) == UNSPEC
11531 && XINT (sub, 1) == UNSPEC_TOC)
11532 return 1;
11533 }
11534 }
11535 }
11536 return 0;
9ebbca7d 11537}
c954844a 11538#endif
38c1f2d7 11539
9ebbca7d 11540rtx
a2369ed3 11541create_TOC_reference (rtx symbol)
9ebbca7d 11542{
a8a05998
ZW
11543 return gen_rtx_PLUS (Pmode,
11544 gen_rtx_REG (Pmode, TOC_REGISTER),
11545 gen_rtx_CONST (Pmode,
11546 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 11547 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 11548}
38c1f2d7 11549
fc4767bb
JJ
11550/* If _Unwind_* has been called from within the same module,
11551 toc register is not guaranteed to be saved to 40(1) on function
11552 entry. Save it there in that case. */
c7ca610e 11553
9ebbca7d 11554void
863d938c 11555rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
11556{
11557 rtx mem;
11558 rtx stack_top = gen_reg_rtx (Pmode);
11559 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
11560 rtx opcode = gen_reg_rtx (SImode);
11561 rtx tocompare = gen_reg_rtx (SImode);
11562 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
11563
11564 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
11565 emit_move_insn (stack_top, mem);
11566
fc4767bb
JJ
11567 mem = gen_rtx_MEM (Pmode,
11568 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
11569 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
11570 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
11571 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
11572 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 11573 : 0xE8410028, SImode));
9ebbca7d 11574
fc4767bb 11575 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 11576 SImode, NULL_RTX, NULL_RTX,
fc4767bb 11577 no_toc_save_needed);
9ebbca7d 11578
fc4767bb
JJ
11579 mem = gen_rtx_MEM (Pmode,
11580 gen_rtx_PLUS (Pmode, stack_top,
11581 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
11582 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
11583 emit_label (no_toc_save_needed);
9ebbca7d 11584}
38c1f2d7 11585\f
ba4828e0
RK
11586/* This ties together stack memory (MEM with an alias set of
11587 rs6000_sr_alias_set) and the change to the stack pointer. */
11588
9ebbca7d 11589static void
863d938c 11590rs6000_emit_stack_tie (void)
9ebbca7d 11591{
ba4828e0
RK
11592 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
11593
11594 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11595 emit_insn (gen_stack_tie (mem));
11596}
38c1f2d7 11597
9ebbca7d
GK
11598/* Emit the correct code for allocating stack space, as insns.
11599 If COPY_R12, make sure a copy of the old frame is left in r12.
11600 The generated code may use hard register 0 as a temporary. */
11601
11602static void
a2369ed3 11603rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 11604{
9ebbca7d
GK
11605 rtx insn;
11606 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11607 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
11608 rtx todec = GEN_INT (-size);
a157febd
GK
11609
11610 if (current_function_limit_stack)
11611 {
11612 if (REG_P (stack_limit_rtx)
11613 && REGNO (stack_limit_rtx) > 1
11614 && REGNO (stack_limit_rtx) <= 31)
11615 {
5b71a4e7 11616 emit_insn (TARGET_32BIT
9ebbca7d
GK
11617 ? gen_addsi3 (tmp_reg,
11618 stack_limit_rtx,
11619 GEN_INT (size))
11620 : gen_adddi3 (tmp_reg,
11621 stack_limit_rtx,
11622 GEN_INT (size)));
5b71a4e7 11623
9ebbca7d
GK
11624 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11625 const0_rtx));
a157febd
GK
11626 }
11627 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 11628 && TARGET_32BIT
f607bc57 11629 && DEFAULT_ABI == ABI_V4)
a157febd 11630 {
9ebbca7d
GK
11631 rtx toload = gen_rtx_CONST (VOIDmode,
11632 gen_rtx_PLUS (Pmode,
11633 stack_limit_rtx,
11634 GEN_INT (size)));
5b71a4e7 11635
9ebbca7d
GK
11636 emit_insn (gen_elf_high (tmp_reg, toload));
11637 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
11638 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11639 const0_rtx));
a157febd
GK
11640 }
11641 else
11642 warning ("stack limit expression is not supported");
11643 }
11644
9ebbca7d
GK
11645 if (copy_r12 || ! TARGET_UPDATE)
11646 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
11647
38c1f2d7
MM
11648 if (TARGET_UPDATE)
11649 {
9ebbca7d 11650 if (size > 32767)
38c1f2d7 11651 {
9ebbca7d
GK
11652 /* Need a note here so that try_split doesn't get confused. */
11653 if (get_last_insn() == NULL_RTX)
2e040219 11654 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
11655 insn = emit_move_insn (tmp_reg, todec);
11656 try_split (PATTERN (insn), insn, 0);
11657 todec = tmp_reg;
38c1f2d7 11658 }
5b71a4e7
DE
11659
11660 insn = emit_insn (TARGET_32BIT
11661 ? gen_movsi_update (stack_reg, stack_reg,
11662 todec, stack_reg)
11663 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 11664 todec, stack_reg));
38c1f2d7
MM
11665 }
11666 else
11667 {
5b71a4e7
DE
11668 insn = emit_insn (TARGET_32BIT
11669 ? gen_addsi3 (stack_reg, stack_reg, todec)
11670 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
11671 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
11672 gen_rtx_REG (Pmode, 12));
11673 }
5b71a4e7 11674
9ebbca7d
GK
11675 RTX_FRAME_RELATED_P (insn) = 1;
11676 REG_NOTES (insn) =
11677 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11678 gen_rtx_SET (VOIDmode, stack_reg,
11679 gen_rtx_PLUS (Pmode, stack_reg,
11680 GEN_INT (-size))),
11681 REG_NOTES (insn));
11682}
11683
a4f6c312
SS
11684/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
11685 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
11686 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
11687 deduce these equivalences by itself so it wasn't necessary to hold
11688 its hand so much. */
9ebbca7d
GK
11689
11690static void
a2369ed3
DJ
11691rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
11692 rtx reg2, rtx rreg)
9ebbca7d
GK
11693{
11694 rtx real, temp;
11695
e56c4463
JL
11696 /* copy_rtx will not make unique copies of registers, so we need to
11697 ensure we don't have unwanted sharing here. */
11698 if (reg == reg2)
11699 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11700
11701 if (reg == rreg)
11702 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11703
9ebbca7d
GK
11704 real = copy_rtx (PATTERN (insn));
11705
89e7058f
AH
11706 if (reg2 != NULL_RTX)
11707 real = replace_rtx (real, reg2, rreg);
11708
9ebbca7d
GK
11709 real = replace_rtx (real, reg,
11710 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
11711 STACK_POINTER_REGNUM),
11712 GEN_INT (val)));
11713
11714 /* We expect that 'real' is either a SET or a PARALLEL containing
11715 SETs (and possibly other stuff). In a PARALLEL, all the SETs
11716 are important so they all have to be marked RTX_FRAME_RELATED_P. */
11717
11718 if (GET_CODE (real) == SET)
11719 {
11720 rtx set = real;
11721
11722 temp = simplify_rtx (SET_SRC (set));
11723 if (temp)
11724 SET_SRC (set) = temp;
11725 temp = simplify_rtx (SET_DEST (set));
11726 if (temp)
11727 SET_DEST (set) = temp;
11728 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 11729 {
9ebbca7d
GK
11730 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11731 if (temp)
11732 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 11733 }
38c1f2d7 11734 }
9ebbca7d
GK
11735 else if (GET_CODE (real) == PARALLEL)
11736 {
11737 int i;
11738 for (i = 0; i < XVECLEN (real, 0); i++)
11739 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11740 {
11741 rtx set = XVECEXP (real, 0, i);
11742
11743 temp = simplify_rtx (SET_SRC (set));
11744 if (temp)
11745 SET_SRC (set) = temp;
11746 temp = simplify_rtx (SET_DEST (set));
11747 if (temp)
11748 SET_DEST (set) = temp;
11749 if (GET_CODE (SET_DEST (set)) == MEM)
11750 {
11751 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11752 if (temp)
11753 XEXP (SET_DEST (set), 0) = temp;
11754 }
11755 RTX_FRAME_RELATED_P (set) = 1;
11756 }
11757 }
11758 else
a4f6c312 11759 abort ();
c19de7aa
AH
11760
11761 if (TARGET_SPE)
11762 real = spe_synthesize_frame_save (real);
11763
9ebbca7d
GK
11764 RTX_FRAME_RELATED_P (insn) = 1;
11765 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11766 real,
11767 REG_NOTES (insn));
38c1f2d7
MM
11768}
11769
c19de7aa
AH
11770/* Given an SPE frame note, return a PARALLEL of SETs with the
11771 original note, plus a synthetic register save. */
11772
11773static rtx
a2369ed3 11774spe_synthesize_frame_save (rtx real)
c19de7aa
AH
11775{
11776 rtx synth, offset, reg, real2;
11777
11778 if (GET_CODE (real) != SET
11779 || GET_MODE (SET_SRC (real)) != V2SImode)
11780 return real;
11781
11782 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11783 frame related note. The parallel contains a set of the register
41f3a930 11784 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11785 This is so we can differentiate between 64-bit and 32-bit saves.
11786 Words cannot describe this nastiness. */
11787
11788 if (GET_CODE (SET_DEST (real)) != MEM
11789 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11790 || GET_CODE (SET_SRC (real)) != REG)
11791 abort ();
11792
11793 /* Transform:
11794 (set (mem (plus (reg x) (const y)))
11795 (reg z))
11796 into:
11797 (set (mem (plus (reg x) (const y+4)))
41f3a930 11798 (reg z+1200))
c19de7aa
AH
11799 */
11800
11801 real2 = copy_rtx (real);
11802 PUT_MODE (SET_DEST (real2), SImode);
11803 reg = SET_SRC (real2);
11804 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
11805 synth = copy_rtx (real2);
11806
11807 if (BYTES_BIG_ENDIAN)
11808 {
11809 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
11810 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
11811 }
11812
11813 reg = SET_SRC (synth);
41f3a930 11814
c19de7aa 11815 synth = replace_rtx (synth, reg,
41f3a930 11816 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
11817
11818 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
11819 synth = replace_rtx (synth, offset,
11820 GEN_INT (INTVAL (offset)
11821 + (BYTES_BIG_ENDIAN ? 0 : 4)));
11822
11823 RTX_FRAME_RELATED_P (synth) = 1;
11824 RTX_FRAME_RELATED_P (real2) = 1;
11825 if (BYTES_BIG_ENDIAN)
11826 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
11827 else
11828 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
11829
11830 return real;
11831}
11832
00b960c7
AH
11833/* Returns an insn that has a vrsave set operation with the
11834 appropriate CLOBBERs. */
11835
11836static rtx
a2369ed3 11837generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
11838{
11839 int nclobs, i;
11840 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 11841 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 11842
a004eb82
AH
11843 clobs[0]
11844 = gen_rtx_SET (VOIDmode,
11845 vrsave,
11846 gen_rtx_UNSPEC_VOLATILE (SImode,
11847 gen_rtvec (2, reg, vrsave),
11848 30));
00b960c7
AH
11849
11850 nclobs = 1;
11851
9aa86737
AH
11852 /* We need to clobber the registers in the mask so the scheduler
11853 does not move sets to VRSAVE before sets of AltiVec registers.
11854
11855 However, if the function receives nonlocal gotos, reload will set
11856 all call saved registers live. We will end up with:
11857
11858 (set (reg 999) (mem))
11859 (parallel [ (set (reg vrsave) (unspec blah))
11860 (clobber (reg 999))])
11861
11862 The clobber will cause the store into reg 999 to be dead, and
11863 flow will attempt to delete an epilogue insn. In this case, we
11864 need an unspec use/set of the register. */
00b960c7
AH
11865
11866 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11867 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
11868 {
11869 if (!epiloguep || call_used_regs [i])
11870 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
11871 gen_rtx_REG (V4SImode, i));
11872 else
11873 {
11874 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
11875
11876 clobs[nclobs++]
a004eb82
AH
11877 = gen_rtx_SET (VOIDmode,
11878 reg,
11879 gen_rtx_UNSPEC (V4SImode,
11880 gen_rtvec (1, reg), 27));
9aa86737
AH
11881 }
11882 }
00b960c7
AH
11883
11884 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
11885
11886 for (i = 0; i < nclobs; ++i)
11887 XVECEXP (insn, 0, i) = clobs[i];
11888
11889 return insn;
11890}
11891
89e7058f
AH
11892/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
11893 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
11894
11895static void
a2369ed3 11896emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 11897 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
11898{
11899 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
11900 rtx replacea, replaceb;
11901
11902 int_rtx = GEN_INT (offset);
11903
11904 /* Some cases that need register indexed addressing. */
11905 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
11906 || (TARGET_SPE_ABI
11907 && SPE_VECTOR_MODE (mode)
11908 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
11909 {
11910 /* Whomever calls us must make sure r11 is available in the
11911 flow path of instructions in the prologue. */
11912 offset_rtx = gen_rtx_REG (Pmode, 11);
11913 emit_move_insn (offset_rtx, int_rtx);
11914
11915 replacea = offset_rtx;
11916 replaceb = int_rtx;
11917 }
11918 else
11919 {
11920 offset_rtx = int_rtx;
11921 replacea = NULL_RTX;
11922 replaceb = NULL_RTX;
11923 }
11924
11925 reg = gen_rtx_REG (mode, regno);
11926 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
11927 mem = gen_rtx_MEM (mode, addr);
11928 set_mem_alias_set (mem, rs6000_sr_alias_set);
11929
11930 insn = emit_move_insn (mem, reg);
11931
11932 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
11933}
11934
a3170dc6
AH
11935/* Emit an offset memory reference suitable for a frame store, while
11936 converting to a valid addressing mode. */
11937
11938static rtx
a2369ed3 11939gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
11940{
11941 rtx int_rtx, offset_rtx;
11942
11943 int_rtx = GEN_INT (offset);
11944
11945 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
11946 {
11947 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11948 emit_move_insn (offset_rtx, int_rtx);
11949 }
11950 else
11951 offset_rtx = int_rtx;
11952
11953 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
11954}
11955
9ebbca7d
GK
11956/* Emit function prologue as insns. */
11957
9878760c 11958void
863d938c 11959rs6000_emit_prologue (void)
9878760c 11960{
4697a36c 11961 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 11962 enum machine_mode reg_mode = Pmode;
327e5343 11963 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
11964 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11965 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
11966 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 11967 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
11968 rtx insn;
11969 int saving_FPRs_inline;
11970 int using_store_multiple;
11971 HOST_WIDE_INT sp_offset = 0;
11972
c19de7aa 11973 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11974 {
11975 reg_mode = V2SImode;
11976 reg_size = 8;
11977 }
11978
9ebbca7d 11979 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11980 && (!TARGET_SPE_ABI
11981 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11982 && info->first_gp_reg_save < 31);
11983 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 11984 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 11985 || current_function_calls_eh_return
8c29550d 11986 || cfun->machine->ra_need_lr);
9ebbca7d
GK
11987
11988 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 11989 if (info->push_p
acd0b319
AM
11990 && (DEFAULT_ABI == ABI_V4
11991 || current_function_calls_eh_return))
9ebbca7d
GK
11992 {
11993 if (info->total_size < 32767)
11994 sp_offset = info->total_size;
11995 else
11996 frame_reg_rtx = frame_ptr_rtx;
11997 rs6000_emit_allocate_stack (info->total_size,
11998 (frame_reg_rtx != sp_reg_rtx
11999 && (info->cr_save_p
12000 || info->lr_save_p
12001 || info->first_fp_reg_save < 64
12002 || info->first_gp_reg_save < 32
12003 )));
12004 if (frame_reg_rtx != sp_reg_rtx)
12005 rs6000_emit_stack_tie ();
12006 }
12007
9aa86737
AH
12008 /* Save AltiVec registers if needed. */
12009 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12010 {
12011 int i;
12012
12013 /* There should be a non inline version of this, for when we
12014 are saving lots of vector registers. */
12015 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12016 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12017 {
12018 rtx areg, savereg, mem;
12019 int offset;
12020
12021 offset = info->altivec_save_offset + sp_offset
12022 + 16 * (i - info->first_altivec_reg_save);
12023
12024 savereg = gen_rtx_REG (V4SImode, i);
12025
12026 areg = gen_rtx_REG (Pmode, 0);
12027 emit_move_insn (areg, GEN_INT (offset));
12028
12029 /* AltiVec addressing mode is [reg+reg]. */
12030 mem = gen_rtx_MEM (V4SImode,
12031 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
12032
12033 set_mem_alias_set (mem, rs6000_sr_alias_set);
12034
12035 insn = emit_move_insn (mem, savereg);
12036
5c242421
SB
12037 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12038 areg, GEN_INT (offset));
9aa86737
AH
12039 }
12040 }
12041
12042 /* VRSAVE is a bit vector representing which AltiVec registers
12043 are used. The OS uses this to determine which vector
12044 registers to save on a context switch. We need to save
12045 VRSAVE on the stack frame, add whatever AltiVec registers we
12046 used in this function, and do the corresponding magic in the
12047 epilogue. */
12048
4d774ff8
HP
12049 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
12050 && info->vrsave_mask != 0)
9aa86737 12051 {
a004eb82 12052 rtx reg, mem, vrsave;
9aa86737
AH
12053 int offset;
12054
12055 /* Get VRSAVE onto a GPR. */
12056 reg = gen_rtx_REG (SImode, 12);
a004eb82 12057 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
12058 if (TARGET_MACHO)
12059 emit_insn (gen_get_vrsave_internal (reg));
12060 else
12061 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
12062
12063 /* Save VRSAVE. */
12064 offset = info->vrsave_save_offset + sp_offset;
12065 mem
12066 = gen_rtx_MEM (SImode,
12067 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
12068 set_mem_alias_set (mem, rs6000_sr_alias_set);
12069 insn = emit_move_insn (mem, reg);
12070
12071 /* Include the registers in the mask. */
12072 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
12073
12074 insn = emit_insn (generate_set_vrsave (reg, info, 0));
12075 }
12076
9ebbca7d
GK
12077 /* If we use the link register, get it into r0. */
12078 if (info->lr_save_p)
71f123ca 12079 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
12080 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12081
12082 /* If we need to save CR, put it into r12. */
12083 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
12084 {
12085 cr_save_rtx = gen_rtx_REG (SImode, 12);
12086 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12087 }
12088
a4f6c312
SS
12089 /* Do any required saving of fpr's. If only one or two to save, do
12090 it ourselves. Otherwise, call function. */
9ebbca7d
GK
12091 if (saving_FPRs_inline)
12092 {
12093 int i;
12094 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12095 if ((regs_ever_live[info->first_fp_reg_save+i]
12096 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
12097 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
12098 info->first_fp_reg_save + i,
12099 info->fp_save_offset + sp_offset + 8 * i,
12100 info->total_size);
9ebbca7d
GK
12101 }
12102 else if (info->first_fp_reg_save != 64)
12103 {
12104 int i;
12105 char rname[30];
520a57c8 12106 const char *alloc_rname;
9ebbca7d
GK
12107 rtvec p;
12108 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
12109
12110 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
12111 gen_rtx_REG (Pmode,
12112 LINK_REGISTER_REGNUM));
12113 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
12114 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 12115 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12116 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
12117 gen_rtx_SYMBOL_REF (Pmode,
12118 alloc_rname));
12119 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12120 {
12121 rtx addr, reg, mem;
12122 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
12123 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12124 GEN_INT (info->fp_save_offset
12125 + sp_offset + 8*i));
12126 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12127 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12128
12129 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
12130 }
12131 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12132 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12133 NULL_RTX, NULL_RTX);
12134 }
b6c9286a 12135
9ebbca7d
GK
12136 /* Save GPRs. This is done as a PARALLEL if we are using
12137 the store-multiple instructions. */
12138 if (using_store_multiple)
b6c9286a 12139 {
308c142a 12140 rtvec p;
9ebbca7d
GK
12141 int i;
12142 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
12143 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12144 {
12145 rtx addr, reg, mem;
12146 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12147 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12148 GEN_INT (info->gp_save_offset
12149 + sp_offset
12150 + reg_size * i));
12151 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12152 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12153
12154 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
12155 }
12156 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12157 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12158 NULL_RTX, NULL_RTX);
b6c9286a
MM
12159 }
12160 else
12161 {
9ebbca7d
GK
12162 int i;
12163 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12164 if ((regs_ever_live[info->first_gp_reg_save+i]
12165 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12166 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12167 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12168 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
12169 {
12170 rtx addr, reg, mem;
12171 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12172
c19de7aa 12173 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12174 {
12175 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12176 rtx b;
12177
12178 if (!SPE_CONST_OFFSET_OK (offset))
12179 {
12180 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12181 emit_move_insn (b, GEN_INT (offset));
12182 }
12183 else
12184 b = GEN_INT (offset);
12185
12186 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12187 mem = gen_rtx_MEM (V2SImode, addr);
12188 set_mem_alias_set (mem, rs6000_sr_alias_set);
12189 insn = emit_move_insn (mem, reg);
12190
12191 if (GET_CODE (b) == CONST_INT)
12192 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12193 NULL_RTX, NULL_RTX);
12194 else
12195 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12196 b, GEN_INT (offset));
12197 }
12198 else
12199 {
12200 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12201 GEN_INT (info->gp_save_offset
12202 + sp_offset
12203 + reg_size * i));
12204 mem = gen_rtx_MEM (reg_mode, addr);
12205 set_mem_alias_set (mem, rs6000_sr_alias_set);
12206
12207 insn = emit_move_insn (mem, reg);
12208 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12209 NULL_RTX, NULL_RTX);
12210 }
12211 }
9ebbca7d
GK
12212 }
12213
83720594
RH
12214 /* ??? There's no need to emit actual instructions here, but it's the
12215 easiest way to get the frame unwind information emitted. */
12216 if (current_function_calls_eh_return)
12217 {
78e1b90d
DE
12218 unsigned int i, regno;
12219
fc4767bb
JJ
12220 /* In AIX ABI we need to pretend we save r2 here. */
12221 if (TARGET_AIX)
12222 {
12223 rtx addr, reg, mem;
12224
12225 reg = gen_rtx_REG (reg_mode, 2);
12226 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12227 GEN_INT (sp_offset + 5 * reg_size));
12228 mem = gen_rtx_MEM (reg_mode, addr);
12229 set_mem_alias_set (mem, rs6000_sr_alias_set);
12230
12231 insn = emit_move_insn (mem, reg);
12232 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12233 NULL_RTX, NULL_RTX);
12234 PATTERN (insn) = gen_blockage ();
12235 }
12236
83720594
RH
12237 for (i = 0; ; ++i)
12238 {
83720594
RH
12239 regno = EH_RETURN_DATA_REGNO (i);
12240 if (regno == INVALID_REGNUM)
12241 break;
12242
89e7058f
AH
12243 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
12244 info->ehrd_offset + sp_offset
12245 + reg_size * (int) i,
12246 info->total_size);
83720594
RH
12247 }
12248 }
12249
9ebbca7d
GK
12250 /* Save lr if we used it. */
12251 if (info->lr_save_p)
12252 {
12253 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12254 GEN_INT (info->lr_save_offset + sp_offset));
12255 rtx reg = gen_rtx_REG (Pmode, 0);
12256 rtx mem = gen_rtx_MEM (Pmode, addr);
12257 /* This should not be of rs6000_sr_alias_set, because of
12258 __builtin_return_address. */
12259
12260 insn = emit_move_insn (mem, reg);
12261 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12262 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12263 }
12264
12265 /* Save CR if we use any that must be preserved. */
12266 if (info->cr_save_p)
12267 {
12268 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12269 GEN_INT (info->cr_save_offset + sp_offset));
12270 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12271
12272 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12273
12274 /* If r12 was used to hold the original sp, copy cr into r0 now
12275 that it's free. */
12276 if (REGNO (frame_reg_rtx) == 12)
12277 {
12278 cr_save_rtx = gen_rtx_REG (SImode, 0);
12279 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12280 }
12281 insn = emit_move_insn (mem, cr_save_rtx);
12282
12283 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
12284 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
12285 But that's OK. All we have to do is specify that _one_ condition
12286 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
12287 will then restore all the call-saved registers.
12288 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 12289 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 12290 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
12291 }
12292
12293 /* Update stack and set back pointer unless this is V.4,
12294 for which it was done previously. */
fc4767bb
JJ
12295 if (info->push_p
12296 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
12297 rs6000_emit_allocate_stack (info->total_size, FALSE);
12298
12299 /* Set frame pointer, if needed. */
12300 if (frame_pointer_needed)
12301 {
a3170dc6 12302 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
12303 sp_reg_rtx);
12304 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 12305 }
9878760c 12306
1db02437 12307 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 12308 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 12309 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 12310 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
12311 {
12312 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 12313 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
12314 can use register 0. This allows us to use a plain 'blr' to return
12315 from the procedure more often. */
f1384257
AM
12316 int save_LR_around_toc_setup = (TARGET_ELF
12317 && DEFAULT_ABI != ABI_AIX
12318 && flag_pic
d5fa86ba
GK
12319 && ! info->lr_save_p
12320 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 12321 if (save_LR_around_toc_setup)
c4501e62
JJ
12322 {
12323 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
12324 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
12325 rs6000_emit_load_toc_table (TRUE);
12326 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
12327 }
12328 else
12329 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 12330 }
ee890fe2 12331
fcce224d 12332#if TARGET_MACHO
ee890fe2
SS
12333 if (DEFAULT_ABI == ABI_DARWIN
12334 && flag_pic && current_function_uses_pic_offset_table)
12335 {
12336 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 12337 const char *picbase = machopic_function_base_name ();
6788f5ca 12338 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 12339
f51eee6a 12340 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
12341
12342 rs6000_maybe_dead (
1db02437 12343 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
12344 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
12345 }
fcce224d 12346#endif
9ebbca7d
GK
12347}
12348
9ebbca7d 12349/* Write function prologue. */
a4f6c312 12350
08c148a8 12351static void
a2369ed3
DJ
12352rs6000_output_function_prologue (FILE *file,
12353 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
12354{
12355 rs6000_stack_t *info = rs6000_stack_info ();
12356
4697a36c
MM
12357 if (TARGET_DEBUG_STACK)
12358 debug_stack_info (info);
9878760c 12359
a4f6c312
SS
12360 /* Write .extern for any function we will call to save and restore
12361 fp values. */
12362 if (info->first_fp_reg_save < 64
12363 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 12364 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 12365 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
12366 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
12367 RESTORE_FP_SUFFIX);
9878760c 12368
c764f757
RK
12369 /* Write .extern for AIX common mode routines, if needed. */
12370 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
12371 {
f6709c70
JW
12372 fputs ("\t.extern __mulh\n", file);
12373 fputs ("\t.extern __mull\n", file);
12374 fputs ("\t.extern __divss\n", file);
12375 fputs ("\t.extern __divus\n", file);
12376 fputs ("\t.extern __quoss\n", file);
12377 fputs ("\t.extern __quous\n", file);
c764f757
RK
12378 common_mode_defined = 1;
12379 }
9878760c 12380
9ebbca7d 12381 if (! HAVE_prologue)
979721f8 12382 {
9ebbca7d 12383 start_sequence ();
9dda4cc8 12384
a4f6c312
SS
12385 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
12386 the "toplevel" insn chain. */
2e040219 12387 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12388 rs6000_emit_prologue ();
2e040219 12389 emit_note (NOTE_INSN_DELETED);
178c3eff 12390
a3c9585f 12391 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12392 {
12393 rtx insn;
12394 unsigned addr = 0;
12395 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12396 {
12397 INSN_ADDRESSES_NEW (insn, addr);
12398 addr += 4;
12399 }
12400 }
9dda4cc8 12401
9ebbca7d 12402 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12403 debug_rtx_list (get_insns (), 100);
12404 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12405 end_sequence ();
979721f8
MM
12406 }
12407
9ebbca7d
GK
12408 rs6000_pic_labelno++;
12409}
12410
12411/* Emit function epilogue as insns.
9878760c 12412
9ebbca7d
GK
12413 At present, dwarf2out_frame_debug_expr doesn't understand
12414 register restores, so we don't bother setting RTX_FRAME_RELATED_P
12415 anywhere in the epilogue. Most of the insns below would in any case
12416 need special notes to explain where r11 is in relation to the stack. */
9878760c 12417
9ebbca7d 12418void
a2369ed3 12419rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
12420{
12421 rs6000_stack_t *info;
12422 int restoring_FPRs_inline;
12423 int using_load_multiple;
12424 int using_mfcr_multiple;
12425 int use_backchain_to_restore_sp;
12426 int sp_offset = 0;
12427 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
12428 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 12429 enum machine_mode reg_mode = Pmode;
327e5343 12430 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12431 int i;
12432
c19de7aa
AH
12433 info = rs6000_stack_info ();
12434
12435 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12436 {
12437 reg_mode = V2SImode;
12438 reg_size = 8;
12439 }
12440
9ebbca7d 12441 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12442 && (!TARGET_SPE_ABI
12443 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12444 && info->first_gp_reg_save < 31);
12445 restoring_FPRs_inline = (sibcall
83720594 12446 || current_function_calls_eh_return
9ebbca7d
GK
12447 || info->first_fp_reg_save == 64
12448 || FP_SAVE_INLINE (info->first_fp_reg_save));
12449 use_backchain_to_restore_sp = (frame_pointer_needed
12450 || current_function_calls_alloca
12451 || info->total_size > 32767);
12452 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
12453 || rs6000_cpu == PROCESSOR_PPC603
12454 || rs6000_cpu == PROCESSOR_PPC750
12455 || optimize_size);
12456
12457 /* If we have a frame pointer, a call to alloca, or a large stack
12458 frame, restore the old stack pointer using the backchain. Otherwise,
12459 we know what size to update it with. */
12460 if (use_backchain_to_restore_sp)
bacbde18 12461 {
9ebbca7d
GK
12462 /* Under V.4, don't reset the stack pointer until after we're done
12463 loading the saved registers. */
f607bc57 12464 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 12465 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 12466
9ebbca7d
GK
12467 emit_move_insn (frame_reg_rtx,
12468 gen_rtx_MEM (Pmode, sp_reg_rtx));
12469
bacbde18 12470 }
9ebbca7d 12471 else if (info->push_p)
85638c0d 12472 {
fc4767bb
JJ
12473 if (DEFAULT_ABI == ABI_V4
12474 || current_function_calls_eh_return)
9ebbca7d
GK
12475 sp_offset = info->total_size;
12476 else
12477 {
12478 emit_insn (TARGET_32BIT
12479 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12480 GEN_INT (info->total_size))
12481 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12482 GEN_INT (info->total_size)));
12483 }
85638c0d 12484 }
9ebbca7d 12485
9aa86737
AH
12486 /* Restore AltiVec registers if needed. */
12487 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12488 {
12489 int i;
12490
12491 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12492 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12493 {
12494 rtx addr, areg, mem;
12495
12496 areg = gen_rtx_REG (Pmode, 0);
12497 emit_move_insn
12498 (areg, GEN_INT (info->altivec_save_offset
12499 + sp_offset
12500 + 16 * (i - info->first_altivec_reg_save)));
12501
12502 /* AltiVec addressing mode is [reg+reg]. */
12503 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
12504 mem = gen_rtx_MEM (V4SImode, addr);
12505 set_mem_alias_set (mem, rs6000_sr_alias_set);
12506
12507 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
12508 }
12509 }
12510
12511 /* Restore VRSAVE if needed. */
4d774ff8
HP
12512 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE
12513 && info->vrsave_mask != 0)
9aa86737
AH
12514 {
12515 rtx addr, mem, reg;
12516
12517 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12518 GEN_INT (info->vrsave_save_offset + sp_offset));
12519 mem = gen_rtx_MEM (SImode, addr);
12520 set_mem_alias_set (mem, rs6000_sr_alias_set);
12521 reg = gen_rtx_REG (SImode, 12);
12522 emit_move_insn (reg, mem);
12523
12524 emit_insn (generate_set_vrsave (reg, info, 1));
12525 }
12526
9ebbca7d
GK
12527 /* Get the old lr if we saved it. */
12528 if (info->lr_save_p)
b6c9286a 12529 {
a3170dc6
AH
12530 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
12531 info->lr_save_offset + sp_offset);
ba4828e0
RK
12532
12533 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12534
9ebbca7d 12535 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 12536 }
9ebbca7d
GK
12537
12538 /* Get the old cr if we saved it. */
12539 if (info->cr_save_p)
12540 {
12541 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12542 GEN_INT (info->cr_save_offset + sp_offset));
12543 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12544
12545 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12546
9ebbca7d
GK
12547 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
12548 }
12549
12550 /* Set LR here to try to overlap restores below. */
4697a36c 12551 if (info->lr_save_p)
9ebbca7d
GK
12552 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
12553 gen_rtx_REG (Pmode, 0));
12554
83720594
RH
12555 /* Load exception handler data registers, if needed. */
12556 if (current_function_calls_eh_return)
12557 {
78e1b90d
DE
12558 unsigned int i, regno;
12559
fc4767bb
JJ
12560 if (TARGET_AIX)
12561 {
12562 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12563 GEN_INT (sp_offset + 5 * reg_size));
12564 rtx mem = gen_rtx_MEM (reg_mode, addr);
12565
12566 set_mem_alias_set (mem, rs6000_sr_alias_set);
12567
12568 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
12569 }
12570
83720594
RH
12571 for (i = 0; ; ++i)
12572 {
a3170dc6 12573 rtx mem;
83720594
RH
12574
12575 regno = EH_RETURN_DATA_REGNO (i);
12576 if (regno == INVALID_REGNUM)
12577 break;
12578
a3170dc6
AH
12579 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
12580 info->ehrd_offset + sp_offset
12581 + reg_size * (int) i);
ba4828e0 12582 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
12583
12584 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
12585 }
12586 }
9ebbca7d
GK
12587
12588 /* Restore GPRs. This is done as a PARALLEL if we are using
12589 the load-multiple instructions. */
12590 if (using_load_multiple)
979721f8 12591 {
9ebbca7d
GK
12592 rtvec p;
12593 p = rtvec_alloc (32 - info->first_gp_reg_save);
12594 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 12595 {
9ebbca7d
GK
12596 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12597 GEN_INT (info->gp_save_offset
12598 + sp_offset
12599 + reg_size * i));
12600 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
12601
12602 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12603
12604 RTVEC_ELT (p, i) =
12605 gen_rtx_SET (VOIDmode,
12606 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
12607 mem);
979721f8 12608 }
9ebbca7d 12609 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 12610 }
9ebbca7d
GK
12611 else
12612 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12613 if ((regs_ever_live[info->first_gp_reg_save+i]
12614 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12615 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12616 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12617 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
12618 {
12619 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12620 GEN_INT (info->gp_save_offset
12621 + sp_offset
12622 + reg_size * i));
12623 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12624
a3170dc6 12625 /* Restore 64-bit quantities for SPE. */
c19de7aa 12626 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12627 {
12628 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12629 rtx b;
12630
12631 if (!SPE_CONST_OFFSET_OK (offset))
12632 {
12633 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12634 emit_move_insn (b, GEN_INT (offset));
12635 }
12636 else
12637 b = GEN_INT (offset);
12638
12639 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12640 mem = gen_rtx_MEM (V2SImode, addr);
12641 }
12642
ba4828e0 12643 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12644
12645 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 12646 info->first_gp_reg_save + i), mem);
9ebbca7d 12647 }
9878760c 12648
9ebbca7d
GK
12649 /* Restore fpr's if we need to do it without calling a function. */
12650 if (restoring_FPRs_inline)
12651 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12652 if ((regs_ever_live[info->first_fp_reg_save+i]
12653 && ! call_used_regs[info->first_fp_reg_save+i]))
12654 {
12655 rtx addr, mem;
12656 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12657 GEN_INT (info->fp_save_offset
12658 + sp_offset
a4f6c312 12659 + 8 * i));
9ebbca7d 12660 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12661 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12662
12663 emit_move_insn (gen_rtx_REG (DFmode,
12664 info->first_fp_reg_save + i),
12665 mem);
12666 }
8d30c4ee 12667
9ebbca7d
GK
12668 /* If we saved cr, restore it here. Just those that were used. */
12669 if (info->cr_save_p)
979721f8 12670 {
9ebbca7d 12671 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 12672 int count = 0;
9ebbca7d
GK
12673
12674 if (using_mfcr_multiple)
979721f8 12675 {
9ebbca7d
GK
12676 for (i = 0; i < 8; i++)
12677 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 12678 count++;
9ebbca7d 12679 if (count == 0)
e35b9579
GK
12680 abort ();
12681 }
12682
12683 if (using_mfcr_multiple && count > 1)
12684 {
12685 rtvec p;
12686 int ndx;
9ebbca7d 12687
e35b9579 12688 p = rtvec_alloc (count);
9ebbca7d 12689
e35b9579 12690 ndx = 0;
9ebbca7d
GK
12691 for (i = 0; i < 8; i++)
12692 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
12693 {
12694 rtvec r = rtvec_alloc (2);
12695 RTVEC_ELT (r, 0) = r12_rtx;
12696 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 12697 RTVEC_ELT (p, ndx) =
9ebbca7d 12698 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 12699 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 12700 ndx++;
9ebbca7d
GK
12701 }
12702 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
12703 if (ndx != count)
12704 abort ();
979721f8
MM
12705 }
12706 else
9ebbca7d
GK
12707 for (i = 0; i < 8; i++)
12708 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 12709 {
9ebbca7d
GK
12710 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
12711 CR0_REGNO+i),
12712 r12_rtx));
979721f8 12713 }
979721f8
MM
12714 }
12715
9ebbca7d
GK
12716 /* If this is V.4, unwind the stack pointer after all of the loads
12717 have been done. We need to emit a block here so that sched
12718 doesn't decide to move the sp change before the register restores
12719 (which may not have any obvious dependency on the stack). This
12720 doesn't hurt performance, because there is no scheduling that can
12721 be done after this point. */
fc4767bb
JJ
12722 if (DEFAULT_ABI == ABI_V4
12723 || current_function_calls_eh_return)
b6c9286a 12724 {
9ebbca7d
GK
12725 if (frame_reg_rtx != sp_reg_rtx)
12726 rs6000_emit_stack_tie ();
b6c9286a 12727
9ebbca7d 12728 if (use_backchain_to_restore_sp)
b6c9286a 12729 {
9ebbca7d 12730 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12731 }
9ebbca7d 12732 else if (sp_offset != 0)
13f1623b 12733 {
5b71a4e7 12734 emit_insn (TARGET_32BIT
9ebbca7d
GK
12735 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12736 GEN_INT (sp_offset))
12737 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12738 GEN_INT (sp_offset)));
13f1623b 12739 }
9ebbca7d 12740 }
b6c9286a 12741
83720594
RH
12742 if (current_function_calls_eh_return)
12743 {
12744 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12745 emit_insn (TARGET_32BIT
83720594
RH
12746 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12747 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12748 }
12749
9ebbca7d
GK
12750 if (!sibcall)
12751 {
12752 rtvec p;
12753 if (! restoring_FPRs_inline)
12754 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12755 else
12756 p = rtvec_alloc (2);
b6c9286a 12757
e35b9579
GK
12758 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12759 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12760 gen_rtx_REG (Pmode,
12761 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12762
12763 /* If we have to restore more than two FP registers, branch to the
12764 restore function. It will return to our caller. */
12765 if (! restoring_FPRs_inline)
12766 {
12767 int i;
12768 char rname[30];
520a57c8 12769 const char *alloc_rname;
979721f8 12770
9ebbca7d
GK
12771 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12772 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12773 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12774 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12775 gen_rtx_SYMBOL_REF (Pmode,
12776 alloc_rname));
b6c9286a 12777
9ebbca7d
GK
12778 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12779 {
12780 rtx addr, mem;
12781 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12782 GEN_INT (info->fp_save_offset + 8*i));
12783 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12784 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12785
12786 RTVEC_ELT (p, i+3) =
12787 gen_rtx_SET (VOIDmode,
12788 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12789 mem);
b6c9286a
MM
12790 }
12791 }
9ebbca7d
GK
12792
12793 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 12794 }
9878760c
RK
12795}
12796
12797/* Write function epilogue. */
12798
08c148a8 12799static void
a2369ed3
DJ
12800rs6000_output_function_epilogue (FILE *file,
12801 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 12802{
4697a36c 12803 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 12804
9ebbca7d 12805 if (! HAVE_epilogue)
9878760c 12806 {
9ebbca7d
GK
12807 rtx insn = get_last_insn ();
12808 /* If the last insn was a BARRIER, we don't have to write anything except
12809 the trace table. */
12810 if (GET_CODE (insn) == NOTE)
12811 insn = prev_nonnote_insn (insn);
12812 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 12813 {
9ebbca7d
GK
12814 /* This is slightly ugly, but at least we don't have two
12815 copies of the epilogue-emitting code. */
12816 start_sequence ();
12817
12818 /* A NOTE_INSN_DELETED is supposed to be at the start
12819 and end of the "toplevel" insn chain. */
2e040219 12820 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12821 rs6000_emit_epilogue (FALSE);
2e040219 12822 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12823
a3c9585f 12824 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12825 {
12826 rtx insn;
12827 unsigned addr = 0;
12828 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12829 {
12830 INSN_ADDRESSES_NEW (insn, addr);
12831 addr += 4;
12832 }
12833 }
12834
9ebbca7d 12835 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12836 debug_rtx_list (get_insns (), 100);
12837 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12838 end_sequence ();
4697a36c 12839 }
9878760c 12840 }
b4ac57ab 12841
efdba735
SH
12842#if TARGET_MACHO
12843 macho_branch_islands ();
0e5da0be
GK
12844 /* Mach-O doesn't support labels at the end of objects, so if
12845 it looks like we might want one, insert a NOP. */
12846 {
12847 rtx insn = get_last_insn ();
12848 while (insn
12849 && NOTE_P (insn)
12850 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
12851 insn = PREV_INSN (insn);
12852 if (insn
12853 && (LABEL_P (insn)
12854 || (NOTE_P (insn)
12855 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
12856 fputs ("\tnop\n", file);
12857 }
12858#endif
12859
9b30bae2 12860 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
12861 on its format.
12862
12863 We don't output a traceback table if -finhibit-size-directive was
12864 used. The documentation for -finhibit-size-directive reads
12865 ``don't output a @code{.size} assembler directive, or anything
12866 else that would cause trouble if the function is split in the
12867 middle, and the two halves are placed at locations far apart in
12868 memory.'' The traceback table has this property, since it
12869 includes the offset from the start of the function to the
4d30c363
MM
12870 traceback table itself.
12871
12872 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 12873 different traceback table. */
57ac7be9
AM
12874 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
12875 && rs6000_traceback != traceback_none)
9b30bae2 12876 {
69c75916 12877 const char *fname = NULL;
3ac88239 12878 const char *language_string = lang_hooks.name;
6041bf2f 12879 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 12880 int i;
57ac7be9
AM
12881 int optional_tbtab;
12882
12883 if (rs6000_traceback == traceback_full)
12884 optional_tbtab = 1;
12885 else if (rs6000_traceback == traceback_part)
12886 optional_tbtab = 0;
12887 else
12888 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 12889
69c75916
AM
12890 if (optional_tbtab)
12891 {
12892 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
12893 while (*fname == '.') /* V.4 encodes . in the name */
12894 fname++;
12895
12896 /* Need label immediately before tbtab, so we can compute
12897 its offset from the function start. */
12898 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
12899 ASM_OUTPUT_LABEL (file, fname);
12900 }
314fc5a9
ILT
12901
12902 /* The .tbtab pseudo-op can only be used for the first eight
12903 expressions, since it can't handle the possibly variable
12904 length fields that follow. However, if you omit the optional
12905 fields, the assembler outputs zeros for all optional fields
12906 anyways, giving each variable length field is minimum length
12907 (as defined in sys/debug.h). Thus we can not use the .tbtab
12908 pseudo-op at all. */
12909
12910 /* An all-zero word flags the start of the tbtab, for debuggers
12911 that have to find it by searching forward from the entry
12912 point or from the current pc. */
19d2d16f 12913 fputs ("\t.long 0\n", file);
314fc5a9
ILT
12914
12915 /* Tbtab format type. Use format type 0. */
19d2d16f 12916 fputs ("\t.byte 0,", file);
314fc5a9 12917
5fc921c1
DE
12918 /* Language type. Unfortunately, there does not seem to be any
12919 official way to discover the language being compiled, so we
12920 use language_string.
12921 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
12922 Java is 13. Objective-C is 14. */
12923 if (! strcmp (language_string, "GNU C"))
314fc5a9
ILT
12924 i = 0;
12925 else if (! strcmp (language_string, "GNU F77"))
12926 i = 1;
8b83775b 12927 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 12928 i = 2;
5fc921c1
DE
12929 else if (! strcmp (language_string, "GNU Ada"))
12930 i = 3;
314fc5a9
ILT
12931 else if (! strcmp (language_string, "GNU C++"))
12932 i = 9;
9517ead8
AG
12933 else if (! strcmp (language_string, "GNU Java"))
12934 i = 13;
5fc921c1
DE
12935 else if (! strcmp (language_string, "GNU Objective-C"))
12936 i = 14;
314fc5a9
ILT
12937 else
12938 abort ();
12939 fprintf (file, "%d,", i);
12940
12941 /* 8 single bit fields: global linkage (not set for C extern linkage,
12942 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
12943 from start of procedure stored in tbtab, internal function, function
12944 has controlled storage, function has no toc, function uses fp,
12945 function logs/aborts fp operations. */
12946 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
12947 fprintf (file, "%d,",
12948 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
12949
12950 /* 6 bitfields: function is interrupt handler, name present in
12951 proc table, function calls alloca, on condition directives
12952 (controls stack walks, 3 bits), saves condition reg, saves
12953 link reg. */
12954 /* The `function calls alloca' bit seems to be set whenever reg 31 is
12955 set up as a frame pointer, even when there is no alloca call. */
12956 fprintf (file, "%d,",
6041bf2f
DE
12957 ((optional_tbtab << 6)
12958 | ((optional_tbtab & frame_pointer_needed) << 5)
12959 | (info->cr_save_p << 1)
12960 | (info->lr_save_p)));
314fc5a9 12961
6041bf2f 12962 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
12963 (6 bits). */
12964 fprintf (file, "%d,",
4697a36c 12965 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
12966
12967 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
12968 fprintf (file, "%d,", (32 - first_reg_to_save ()));
12969
6041bf2f
DE
12970 if (optional_tbtab)
12971 {
12972 /* Compute the parameter info from the function decl argument
12973 list. */
12974 tree decl;
12975 int next_parm_info_bit = 31;
314fc5a9 12976
6041bf2f
DE
12977 for (decl = DECL_ARGUMENTS (current_function_decl);
12978 decl; decl = TREE_CHAIN (decl))
12979 {
12980 rtx parameter = DECL_INCOMING_RTL (decl);
12981 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 12982
6041bf2f
DE
12983 if (GET_CODE (parameter) == REG)
12984 {
12985 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
12986 {
12987 int bits;
12988
12989 float_parms++;
12990
12991 if (mode == SFmode)
12992 bits = 0x2;
fcce224d 12993 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
12994 bits = 0x3;
12995 else
12996 abort ();
12997
12998 /* If only one bit will fit, don't or in this entry. */
12999 if (next_parm_info_bit > 0)
13000 parm_info |= (bits << (next_parm_info_bit - 1));
13001 next_parm_info_bit -= 2;
13002 }
13003 else
13004 {
13005 fixed_parms += ((GET_MODE_SIZE (mode)
13006 + (UNITS_PER_WORD - 1))
13007 / UNITS_PER_WORD);
13008 next_parm_info_bit -= 1;
13009 }
13010 }
13011 }
13012 }
314fc5a9
ILT
13013
13014 /* Number of fixed point parameters. */
13015 /* This is actually the number of words of fixed point parameters; thus
13016 an 8 byte struct counts as 2; and thus the maximum value is 8. */
13017 fprintf (file, "%d,", fixed_parms);
13018
13019 /* 2 bitfields: number of floating point parameters (7 bits), parameters
13020 all on stack. */
13021 /* This is actually the number of fp registers that hold parameters;
13022 and thus the maximum value is 13. */
13023 /* Set parameters on stack bit if parameters are not in their original
13024 registers, regardless of whether they are on the stack? Xlc
13025 seems to set the bit when not optimizing. */
13026 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
13027
6041bf2f
DE
13028 if (! optional_tbtab)
13029 return;
13030
314fc5a9
ILT
13031 /* Optional fields follow. Some are variable length. */
13032
13033 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
13034 11 double float. */
13035 /* There is an entry for each parameter in a register, in the order that
13036 they occur in the parameter list. Any intervening arguments on the
13037 stack are ignored. If the list overflows a long (max possible length
13038 34 bits) then completely leave off all elements that don't fit. */
13039 /* Only emit this long if there was at least one parameter. */
13040 if (fixed_parms || float_parms)
13041 fprintf (file, "\t.long %d\n", parm_info);
13042
13043 /* Offset from start of code to tb table. */
19d2d16f 13044 fputs ("\t.long ", file);
314fc5a9 13045 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
13046#if TARGET_AIX
13047 RS6000_OUTPUT_BASENAME (file, fname);
13048#else
9ebbca7d 13049 assemble_name (file, fname);
54ee9799 13050#endif
19d2d16f 13051 fputs ("-.", file);
54ee9799
DE
13052#if TARGET_AIX
13053 RS6000_OUTPUT_BASENAME (file, fname);
13054#else
9ebbca7d 13055 assemble_name (file, fname);
54ee9799 13056#endif
19d2d16f 13057 putc ('\n', file);
314fc5a9
ILT
13058
13059 /* Interrupt handler mask. */
13060 /* Omit this long, since we never set the interrupt handler bit
13061 above. */
13062
13063 /* Number of CTL (controlled storage) anchors. */
13064 /* Omit this long, since the has_ctl bit is never set above. */
13065
13066 /* Displacement into stack of each CTL anchor. */
13067 /* Omit this list of longs, because there are no CTL anchors. */
13068
13069 /* Length of function name. */
69c75916
AM
13070 if (*fname == '*')
13071 ++fname;
296b8152 13072 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
13073
13074 /* Function name. */
13075 assemble_string (fname, strlen (fname));
13076
13077 /* Register for alloca automatic storage; this is always reg 31.
13078 Only emit this if the alloca bit was set above. */
13079 if (frame_pointer_needed)
19d2d16f 13080 fputs ("\t.byte 31\n", file);
b1765bde
DE
13081
13082 fputs ("\t.align 2\n", file);
9b30bae2 13083 }
9878760c 13084}
17167fd8 13085\f
a4f6c312
SS
13086/* A C compound statement that outputs the assembler code for a thunk
13087 function, used to implement C++ virtual function calls with
13088 multiple inheritance. The thunk acts as a wrapper around a virtual
13089 function, adjusting the implicit object parameter before handing
13090 control off to the real function.
13091
13092 First, emit code to add the integer DELTA to the location that
13093 contains the incoming first argument. Assume that this argument
13094 contains a pointer, and is the one used to pass the `this' pointer
13095 in C++. This is the incoming argument *before* the function
13096 prologue, e.g. `%o0' on a sparc. The addition must preserve the
13097 values of all other incoming arguments.
17167fd8
MM
13098
13099 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
13100 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
13101 not touch the return address. Hence returning from FUNCTION will
13102 return to whoever called the current `thunk'.
17167fd8 13103
a4f6c312
SS
13104 The effect must be as if FUNCTION had been called directly with the
13105 adjusted first argument. This macro is responsible for emitting
13106 all of the code for a thunk function; output_function_prologue()
13107 and output_function_epilogue() are not invoked.
17167fd8 13108
a4f6c312
SS
13109 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
13110 been extracted from it.) It might possibly be useful on some
13111 targets, but probably not.
17167fd8 13112
a4f6c312
SS
13113 If you do not define this macro, the target-independent code in the
13114 C++ frontend will generate a less efficient heavyweight thunk that
13115 calls FUNCTION instead of jumping to it. The generic approach does
13116 not support varargs. */
17167fd8 13117
3961e8fe 13118static void
a2369ed3
DJ
13119rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
13120 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
13121 tree function)
17167fd8 13122{
5b71a4e7 13123 rtx this, insn, funexp;
17167fd8 13124
5b71a4e7 13125 reload_completed = 1;
fe3ad572 13126 epilogue_completed = 1;
5b71a4e7 13127 no_new_pseudos = 1;
56a7189a 13128
5b71a4e7 13129 /* Mark the end of the (empty) prologue. */
2e040219 13130 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 13131
5b71a4e7
DE
13132 /* Find the "this" pointer. If the function returns a structure,
13133 the structure return pointer is in r3. */
61f71b34 13134 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 13135 this = gen_rtx_REG (Pmode, 4);
56a7189a 13136 else
5b71a4e7 13137 this = gen_rtx_REG (Pmode, 3);
17167fd8 13138
5b71a4e7
DE
13139 /* Apply the constant offset, if required. */
13140 if (delta)
13141 {
13142 rtx delta_rtx = GEN_INT (delta);
13143 emit_insn (TARGET_32BIT
13144 ? gen_addsi3 (this, this, delta_rtx)
13145 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
13146 }
13147
5b71a4e7
DE
13148 /* Apply the offset from the vtable, if required. */
13149 if (vcall_offset)
17167fd8 13150 {
5b71a4e7
DE
13151 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
13152 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 13153
5b71a4e7 13154 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
13155 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
13156 {
13157 emit_insn (TARGET_32BIT
13158 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
13159 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
13160 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
13161 }
13162 else
13163 {
13164 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
13165
13166 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
13167 }
5b71a4e7
DE
13168 emit_insn (TARGET_32BIT
13169 ? gen_addsi3 (this, this, tmp)
13170 : gen_adddi3 (this, this, tmp));
17167fd8
MM
13171 }
13172
5b71a4e7
DE
13173 /* Generate a tail call to the target function. */
13174 if (!TREE_USED (function))
13175 {
13176 assemble_external (function);
13177 TREE_USED (function) = 1;
13178 }
13179 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 13180 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
13181
13182#if TARGET_MACHO
ab82a49f 13183 if (MACHOPIC_INDIRECT)
5b71a4e7 13184 funexp = machopic_indirect_call_target (funexp);
ee890fe2 13185#endif
5b71a4e7
DE
13186
13187 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
13188 generate sibcall RTL explicitly to avoid constraint abort. */
13189 insn = emit_call_insn (
13190 gen_rtx_PARALLEL (VOIDmode,
13191 gen_rtvec (4,
13192 gen_rtx_CALL (VOIDmode,
13193 funexp, const0_rtx),
13194 gen_rtx_USE (VOIDmode, const0_rtx),
13195 gen_rtx_USE (VOIDmode,
13196 gen_rtx_REG (SImode,
13197 LINK_REGISTER_REGNUM)),
13198 gen_rtx_RETURN (VOIDmode))));
13199 SIBLING_CALL_P (insn) = 1;
13200 emit_barrier ();
13201
13202 /* Run just enough of rest_of_compilation to get the insns emitted.
13203 There's not really enough bulk here to make other passes such as
13204 instruction scheduling worth while. Note that use_thunk calls
13205 assemble_start_function and assemble_end_function. */
13206 insn = get_insns ();
a2855205 13207 insn_locators_initialize ();
5b71a4e7
DE
13208 shorten_branches (insn);
13209 final_start_function (insn, file, 1);
13210 final (insn, file, 1, 0);
13211 final_end_function ();
13212
13213 reload_completed = 0;
fe3ad572 13214 epilogue_completed = 0;
5b71a4e7 13215 no_new_pseudos = 0;
9ebbca7d 13216}
9ebbca7d
GK
13217\f
13218/* A quick summary of the various types of 'constant-pool tables'
13219 under PowerPC:
13220
13221 Target Flags Name One table per
13222 AIX (none) AIX TOC object file
13223 AIX -mfull-toc AIX TOC object file
13224 AIX -mminimal-toc AIX minimal TOC translation unit
13225 SVR4/EABI (none) SVR4 SDATA object file
13226 SVR4/EABI -fpic SVR4 pic object file
13227 SVR4/EABI -fPIC SVR4 PIC translation unit
13228 SVR4/EABI -mrelocatable EABI TOC function
13229 SVR4/EABI -maix AIX TOC object file
13230 SVR4/EABI -maix -mminimal-toc
13231 AIX minimal TOC translation unit
13232
13233 Name Reg. Set by entries contains:
13234 made by addrs? fp? sum?
13235
13236 AIX TOC 2 crt0 as Y option option
13237 AIX minimal TOC 30 prolog gcc Y Y option
13238 SVR4 SDATA 13 crt0 gcc N Y N
13239 SVR4 pic 30 prolog ld Y not yet N
13240 SVR4 PIC 30 prolog gcc Y option option
13241 EABI TOC 30 prolog gcc Y option option
13242
13243*/
13244
9ebbca7d
GK
13245/* Hash functions for the hash table. */
13246
13247static unsigned
a2369ed3 13248rs6000_hash_constant (rtx k)
9ebbca7d 13249{
46b33600
RH
13250 enum rtx_code code = GET_CODE (k);
13251 enum machine_mode mode = GET_MODE (k);
13252 unsigned result = (code << 3) ^ mode;
13253 const char *format;
13254 int flen, fidx;
9ebbca7d 13255
46b33600
RH
13256 format = GET_RTX_FORMAT (code);
13257 flen = strlen (format);
13258 fidx = 0;
9ebbca7d 13259
46b33600
RH
13260 switch (code)
13261 {
13262 case LABEL_REF:
13263 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
13264
13265 case CONST_DOUBLE:
13266 if (mode != VOIDmode)
13267 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
13268 flen = 2;
13269 break;
13270
13271 case CODE_LABEL:
13272 fidx = 3;
13273 break;
13274
13275 default:
13276 break;
13277 }
9ebbca7d
GK
13278
13279 for (; fidx < flen; fidx++)
13280 switch (format[fidx])
13281 {
13282 case 's':
13283 {
13284 unsigned i, len;
13285 const char *str = XSTR (k, fidx);
13286 len = strlen (str);
13287 result = result * 613 + len;
13288 for (i = 0; i < len; i++)
13289 result = result * 613 + (unsigned) str[i];
17167fd8
MM
13290 break;
13291 }
9ebbca7d
GK
13292 case 'u':
13293 case 'e':
13294 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
13295 break;
13296 case 'i':
13297 case 'n':
13298 result = result * 613 + (unsigned) XINT (k, fidx);
13299 break;
13300 case 'w':
13301 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
13302 result = result * 613 + (unsigned) XWINT (k, fidx);
13303 else
13304 {
13305 size_t i;
13306 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
13307 result = result * 613 + (unsigned) (XWINT (k, fidx)
13308 >> CHAR_BIT * i);
13309 }
13310 break;
09501938
DE
13311 case '0':
13312 break;
9ebbca7d 13313 default:
a4f6c312 13314 abort ();
9ebbca7d 13315 }
46b33600 13316
9ebbca7d
GK
13317 return result;
13318}
13319
13320static unsigned
a2369ed3 13321toc_hash_function (const void *hash_entry)
9ebbca7d 13322{
a9098fd0
GK
13323 const struct toc_hash_struct *thc =
13324 (const struct toc_hash_struct *) hash_entry;
13325 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
13326}
13327
13328/* Compare H1 and H2 for equivalence. */
13329
13330static int
a2369ed3 13331toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
13332{
13333 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
13334 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
13335
a9098fd0
GK
13336 if (((const struct toc_hash_struct *) h1)->key_mode
13337 != ((const struct toc_hash_struct *) h2)->key_mode)
13338 return 0;
13339
5692c7bc 13340 return rtx_equal_p (r1, r2);
9ebbca7d
GK
13341}
13342
28e510bd
MM
13343/* These are the names given by the C++ front-end to vtables, and
13344 vtable-like objects. Ideally, this logic should not be here;
13345 instead, there should be some programmatic way of inquiring as
13346 to whether or not an object is a vtable. */
13347
13348#define VTABLE_NAME_P(NAME) \
13349 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
13350 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
13351 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 13352 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
28e510bd
MM
13353 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
13354
13355void
a2369ed3 13356rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
13357{
13358 /* Currently C++ toc references to vtables can be emitted before it
13359 is decided whether the vtable is public or private. If this is
13360 the case, then the linker will eventually complain that there is
13361 a reference to an unknown section. Thus, for vtables only,
13362 we emit the TOC reference to reference the symbol and not the
13363 section. */
13364 const char *name = XSTR (x, 0);
54ee9799
DE
13365
13366 if (VTABLE_NAME_P (name))
13367 {
13368 RS6000_OUTPUT_BASENAME (file, name);
13369 }
13370 else
13371 assemble_name (file, name);
28e510bd
MM
13372}
13373
a4f6c312
SS
13374/* Output a TOC entry. We derive the entry name from what is being
13375 written. */
9878760c
RK
13376
13377void
a2369ed3 13378output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
13379{
13380 char buf[256];
3cce094d 13381 const char *name = buf;
ec940faa 13382 const char *real_name;
9878760c
RK
13383 rtx base = x;
13384 int offset = 0;
13385
4697a36c
MM
13386 if (TARGET_NO_TOC)
13387 abort ();
13388
9ebbca7d
GK
13389 /* When the linker won't eliminate them, don't output duplicate
13390 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
13391 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
13392 CODE_LABELs. */
13393 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
13394 {
13395 struct toc_hash_struct *h;
13396 void * * found;
13397
17211ab5 13398 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 13399 time because GGC is not initialized at that point. */
17211ab5
GK
13400 if (toc_hash_table == NULL)
13401 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
13402 toc_hash_eq, NULL);
13403
9ebbca7d
GK
13404 h = ggc_alloc (sizeof (*h));
13405 h->key = x;
a9098fd0 13406 h->key_mode = mode;
9ebbca7d
GK
13407 h->labelno = labelno;
13408
13409 found = htab_find_slot (toc_hash_table, h, 1);
13410 if (*found == NULL)
13411 *found = h;
13412 else /* This is indeed a duplicate.
13413 Set this label equal to that label. */
13414 {
13415 fputs ("\t.set ", file);
13416 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13417 fprintf (file, "%d,", labelno);
13418 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13419 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
13420 found)->labelno));
13421 return;
13422 }
13423 }
13424
13425 /* If we're going to put a double constant in the TOC, make sure it's
13426 aligned properly when strict alignment is on. */
ff1720ed
RK
13427 if (GET_CODE (x) == CONST_DOUBLE
13428 && STRICT_ALIGNMENT
a9098fd0 13429 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
13430 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
13431 ASM_OUTPUT_ALIGN (file, 3);
13432 }
13433
4977bab6 13434 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 13435
37c37a57
RK
13436 /* Handle FP constants specially. Note that if we have a minimal
13437 TOC, things we put here aren't actually in the TOC, so we can allow
13438 FP constants. */
fcce224d
DE
13439 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
13440 {
13441 REAL_VALUE_TYPE rv;
13442 long k[4];
13443
13444 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13445 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
13446
13447 if (TARGET_64BIT)
13448 {
13449 if (TARGET_MINIMAL_TOC)
13450 fputs (DOUBLE_INT_ASM_OP, file);
13451 else
13452 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13453 k[0] & 0xffffffff, k[1] & 0xffffffff,
13454 k[2] & 0xffffffff, k[3] & 0xffffffff);
13455 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
13456 k[0] & 0xffffffff, k[1] & 0xffffffff,
13457 k[2] & 0xffffffff, k[3] & 0xffffffff);
13458 return;
13459 }
13460 else
13461 {
13462 if (TARGET_MINIMAL_TOC)
13463 fputs ("\t.long ", file);
13464 else
13465 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13466 k[0] & 0xffffffff, k[1] & 0xffffffff,
13467 k[2] & 0xffffffff, k[3] & 0xffffffff);
13468 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
13469 k[0] & 0xffffffff, k[1] & 0xffffffff,
13470 k[2] & 0xffffffff, k[3] & 0xffffffff);
13471 return;
13472 }
13473 }
13474 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 13475 {
042259f2
DE
13476 REAL_VALUE_TYPE rv;
13477 long k[2];
0adc764e 13478
042259f2
DE
13479 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13480 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 13481
13ded975
DE
13482 if (TARGET_64BIT)
13483 {
13484 if (TARGET_MINIMAL_TOC)
2bfcf297 13485 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13486 else
2f0552b6
AM
13487 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13488 k[0] & 0xffffffff, k[1] & 0xffffffff);
13489 fprintf (file, "0x%lx%08lx\n",
13490 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13491 return;
13492 }
1875cc88 13493 else
13ded975
DE
13494 {
13495 if (TARGET_MINIMAL_TOC)
2bfcf297 13496 fputs ("\t.long ", file);
13ded975 13497 else
2f0552b6
AM
13498 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13499 k[0] & 0xffffffff, k[1] & 0xffffffff);
13500 fprintf (file, "0x%lx,0x%lx\n",
13501 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13502 return;
13503 }
9878760c 13504 }
a9098fd0 13505 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 13506 {
042259f2
DE
13507 REAL_VALUE_TYPE rv;
13508 long l;
9878760c 13509
042259f2
DE
13510 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13511 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
13512
31bfaa0b
DE
13513 if (TARGET_64BIT)
13514 {
13515 if (TARGET_MINIMAL_TOC)
2bfcf297 13516 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 13517 else
2f0552b6
AM
13518 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13519 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
13520 return;
13521 }
042259f2 13522 else
31bfaa0b
DE
13523 {
13524 if (TARGET_MINIMAL_TOC)
2bfcf297 13525 fputs ("\t.long ", file);
31bfaa0b 13526 else
2f0552b6
AM
13527 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13528 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
13529 return;
13530 }
042259f2 13531 }
f176e826 13532 else if (GET_MODE (x) == VOIDmode
a9098fd0 13533 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 13534 {
e2c953b6 13535 unsigned HOST_WIDE_INT low;
042259f2
DE
13536 HOST_WIDE_INT high;
13537
13538 if (GET_CODE (x) == CONST_DOUBLE)
13539 {
13540 low = CONST_DOUBLE_LOW (x);
13541 high = CONST_DOUBLE_HIGH (x);
13542 }
13543 else
13544#if HOST_BITS_PER_WIDE_INT == 32
13545 {
13546 low = INTVAL (x);
0858c623 13547 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
13548 }
13549#else
13550 {
0858c623 13551 low = INTVAL (x) & 0xffffffff;
042259f2
DE
13552 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
13553 }
13554#endif
9878760c 13555
a9098fd0
GK
13556 /* TOC entries are always Pmode-sized, but since this
13557 is a bigendian machine then if we're putting smaller
13558 integer constants in the TOC we have to pad them.
13559 (This is still a win over putting the constants in
13560 a separate constant pool, because then we'd have
02a4ec28
FS
13561 to have both a TOC entry _and_ the actual constant.)
13562
13563 For a 32-bit target, CONST_INT values are loaded and shifted
13564 entirely within `low' and can be stored in one TOC entry. */
13565
13566 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 13567 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
13568
13569 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
13570 {
13571#if HOST_BITS_PER_WIDE_INT == 32
13572 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
13573 POINTER_SIZE, &low, &high, 0);
13574#else
13575 low |= high << 32;
13576 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
13577 high = (HOST_WIDE_INT) low >> 32;
13578 low &= 0xffffffff;
13579#endif
13580 }
a9098fd0 13581
13ded975
DE
13582 if (TARGET_64BIT)
13583 {
13584 if (TARGET_MINIMAL_TOC)
2bfcf297 13585 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13586 else
2f0552b6
AM
13587 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
13588 (long) high & 0xffffffff, (long) low & 0xffffffff);
13589 fprintf (file, "0x%lx%08lx\n",
13590 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
13591 return;
13592 }
1875cc88 13593 else
13ded975 13594 {
02a4ec28
FS
13595 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
13596 {
13597 if (TARGET_MINIMAL_TOC)
2bfcf297 13598 fputs ("\t.long ", file);
02a4ec28 13599 else
2bfcf297 13600 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
13601 (long) high & 0xffffffff, (long) low & 0xffffffff);
13602 fprintf (file, "0x%lx,0x%lx\n",
13603 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 13604 }
13ded975 13605 else
02a4ec28
FS
13606 {
13607 if (TARGET_MINIMAL_TOC)
2bfcf297 13608 fputs ("\t.long ", file);
02a4ec28 13609 else
2f0552b6
AM
13610 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
13611 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 13612 }
13ded975
DE
13613 return;
13614 }
9878760c
RK
13615 }
13616
13617 if (GET_CODE (x) == CONST)
13618 {
2bfcf297
DB
13619 if (GET_CODE (XEXP (x, 0)) != PLUS)
13620 abort ();
13621
9878760c
RK
13622 base = XEXP (XEXP (x, 0), 0);
13623 offset = INTVAL (XEXP (XEXP (x, 0), 1));
13624 }
13625
13626 if (GET_CODE (base) == SYMBOL_REF)
13627 name = XSTR (base, 0);
13628 else if (GET_CODE (base) == LABEL_REF)
13629 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
13630 else if (GET_CODE (base) == CODE_LABEL)
13631 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
13632 else
13633 abort ();
13634
772c5265 13635 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 13636 if (TARGET_MINIMAL_TOC)
2bfcf297 13637 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
13638 else
13639 {
b6c9286a 13640 fprintf (file, "\t.tc %s", real_name);
9878760c 13641
1875cc88
JW
13642 if (offset < 0)
13643 fprintf (file, ".N%d", - offset);
13644 else if (offset)
13645 fprintf (file, ".P%d", offset);
9878760c 13646
19d2d16f 13647 fputs ("[TC],", file);
1875cc88 13648 }
581bc4de
MM
13649
13650 /* Currently C++ toc references to vtables can be emitted before it
13651 is decided whether the vtable is public or private. If this is
13652 the case, then the linker will eventually complain that there is
13653 a TOC reference to an unknown section. Thus, for vtables only,
13654 we emit the TOC reference to reference the symbol and not the
13655 section. */
28e510bd 13656 if (VTABLE_NAME_P (name))
581bc4de 13657 {
54ee9799 13658 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
13659 if (offset < 0)
13660 fprintf (file, "%d", offset);
13661 else if (offset > 0)
13662 fprintf (file, "+%d", offset);
13663 }
13664 else
13665 output_addr_const (file, x);
19d2d16f 13666 putc ('\n', file);
9878760c
RK
13667}
13668\f
13669/* Output an assembler pseudo-op to write an ASCII string of N characters
13670 starting at P to FILE.
13671
13672 On the RS/6000, we have to do this using the .byte operation and
13673 write out special characters outside the quoted string.
13674 Also, the assembler is broken; very long strings are truncated,
a4f6c312 13675 so we must artificially break them up early. */
9878760c
RK
13676
13677void
a2369ed3 13678output_ascii (FILE *file, const char *p, int n)
9878760c
RK
13679{
13680 char c;
13681 int i, count_string;
d330fd93
KG
13682 const char *for_string = "\t.byte \"";
13683 const char *for_decimal = "\t.byte ";
13684 const char *to_close = NULL;
9878760c
RK
13685
13686 count_string = 0;
13687 for (i = 0; i < n; i++)
13688 {
13689 c = *p++;
13690 if (c >= ' ' && c < 0177)
13691 {
13692 if (for_string)
13693 fputs (for_string, file);
13694 putc (c, file);
13695
13696 /* Write two quotes to get one. */
13697 if (c == '"')
13698 {
13699 putc (c, file);
13700 ++count_string;
13701 }
13702
13703 for_string = NULL;
13704 for_decimal = "\"\n\t.byte ";
13705 to_close = "\"\n";
13706 ++count_string;
13707
13708 if (count_string >= 512)
13709 {
13710 fputs (to_close, file);
13711
13712 for_string = "\t.byte \"";
13713 for_decimal = "\t.byte ";
13714 to_close = NULL;
13715 count_string = 0;
13716 }
13717 }
13718 else
13719 {
13720 if (for_decimal)
13721 fputs (for_decimal, file);
13722 fprintf (file, "%d", c);
13723
13724 for_string = "\n\t.byte \"";
13725 for_decimal = ", ";
13726 to_close = "\n";
13727 count_string = 0;
13728 }
13729 }
13730
13731 /* Now close the string if we have written one. Then end the line. */
13732 if (to_close)
9ebbca7d 13733 fputs (to_close, file);
9878760c
RK
13734}
13735\f
13736/* Generate a unique section name for FILENAME for a section type
13737 represented by SECTION_DESC. Output goes into BUF.
13738
13739 SECTION_DESC can be any string, as long as it is different for each
13740 possible section type.
13741
13742 We name the section in the same manner as xlc. The name begins with an
13743 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13744 names) with the last period replaced by the string SECTION_DESC. If
13745 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13746 the name. */
9878760c
RK
13747
13748void
a2369ed3
DJ
13749rs6000_gen_section_name (char **buf, const char *filename,
13750 const char *section_desc)
9878760c 13751{
9ebbca7d 13752 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13753 char *p;
13754 int len;
9878760c
RK
13755
13756 after_last_slash = filename;
13757 for (q = filename; *q; q++)
11e5fe42
RK
13758 {
13759 if (*q == '/')
13760 after_last_slash = q + 1;
13761 else if (*q == '.')
13762 last_period = q;
13763 }
9878760c 13764
11e5fe42 13765 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13766 *buf = (char *) xmalloc (len);
9878760c
RK
13767
13768 p = *buf;
13769 *p++ = '_';
13770
13771 for (q = after_last_slash; *q; q++)
13772 {
11e5fe42 13773 if (q == last_period)
9878760c
RK
13774 {
13775 strcpy (p, section_desc);
13776 p += strlen (section_desc);
e3981aab 13777 break;
9878760c
RK
13778 }
13779
e9a780ec 13780 else if (ISALNUM (*q))
9878760c
RK
13781 *p++ = *q;
13782 }
13783
11e5fe42 13784 if (last_period == 0)
9878760c
RK
13785 strcpy (p, section_desc);
13786 else
13787 *p = '\0';
13788}
e165f3f0 13789\f
a4f6c312 13790/* Emit profile function. */
411707f4 13791
411707f4 13792void
a2369ed3 13793output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 13794{
ffcfcb5f
AM
13795 if (TARGET_PROFILE_KERNEL)
13796 return;
13797
8480e480
CC
13798 if (DEFAULT_ABI == ABI_AIX)
13799 {
9739c90c
JJ
13800#ifndef NO_PROFILE_COUNTERS
13801# define NO_PROFILE_COUNTERS 0
13802#endif
13803 if (NO_PROFILE_COUNTERS)
13804 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
13805 else
13806 {
13807 char buf[30];
13808 const char *label_name;
13809 rtx fun;
411707f4 13810
9739c90c
JJ
13811 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
13812 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
13813 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 13814
9739c90c
JJ
13815 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
13816 fun, Pmode);
13817 }
8480e480 13818 }
ee890fe2
SS
13819 else if (DEFAULT_ABI == ABI_DARWIN)
13820 {
d5fa86ba 13821 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
13822 int caller_addr_regno = LINK_REGISTER_REGNUM;
13823
13824 /* Be conservative and always set this, at least for now. */
13825 current_function_uses_pic_offset_table = 1;
13826
13827#if TARGET_MACHO
13828 /* For PIC code, set up a stub and collect the caller's address
13829 from r0, which is where the prologue puts it. */
ab82a49f 13830 if (MACHOPIC_INDIRECT)
ee890fe2
SS
13831 {
13832 mcount_name = machopic_stub_name (mcount_name);
13833 if (current_function_uses_pic_offset_table)
13834 caller_addr_regno = 0;
13835 }
13836#endif
13837 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
13838 0, VOIDmode, 1,
13839 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
13840 }
411707f4
CC
13841}
13842
a4f6c312 13843/* Write function profiler code. */
e165f3f0
RK
13844
13845void
a2369ed3 13846output_function_profiler (FILE *file, int labelno)
e165f3f0 13847{
3daf36a4 13848 char buf[100];
09eeeacb 13849 int save_lr = 8;
e165f3f0 13850
38c1f2d7 13851 switch (DEFAULT_ABI)
3daf36a4 13852 {
38c1f2d7
MM
13853 default:
13854 abort ();
13855
13856 case ABI_V4:
09eeeacb 13857 save_lr = 4;
09eeeacb
AM
13858 if (!TARGET_32BIT)
13859 {
13860 warning ("no profiling of 64-bit code for this ABI");
13861 return;
13862 }
ffcfcb5f 13863 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
13864 fprintf (file, "\tmflr %s\n", reg_names[0]);
13865 if (flag_pic == 1)
13866 {
dfdfa60f 13867 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
13868 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13869 reg_names[0], save_lr, reg_names[1]);
17167fd8 13870 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 13871 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 13872 assemble_name (file, buf);
17167fd8 13873 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 13874 }
9ebbca7d 13875 else if (flag_pic > 1)
38c1f2d7 13876 {
09eeeacb
AM
13877 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13878 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
13879 /* Now, we need to get the address of the label. */
13880 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 13881 assemble_name (file, buf);
9ebbca7d
GK
13882 fputs ("-.\n1:", file);
13883 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
13884 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
13885 reg_names[0], reg_names[11]);
13886 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
13887 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 13888 }
38c1f2d7
MM
13889 else
13890 {
17167fd8 13891 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 13892 assemble_name (file, buf);
dfdfa60f 13893 fputs ("@ha\n", file);
09eeeacb
AM
13894 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13895 reg_names[0], save_lr, reg_names[1]);
a260abc9 13896 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 13897 assemble_name (file, buf);
17167fd8 13898 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
13899 }
13900
50d440bc 13901 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
13902 fprintf (file, "\tbl %s%s\n",
13903 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
13904 break;
13905
13906 case ABI_AIX:
ee890fe2 13907 case ABI_DARWIN:
ffcfcb5f
AM
13908 if (!TARGET_PROFILE_KERNEL)
13909 {
a3c9585f 13910 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
13911 }
13912 else
13913 {
13914 if (TARGET_32BIT)
13915 abort ();
13916
13917 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
13918 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
13919
13920 if (current_function_needs_context)
13921 {
13922 asm_fprintf (file, "\tstd %s,24(%s)\n",
13923 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13924 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13925 asm_fprintf (file, "\tld %s,24(%s)\n",
13926 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13927 }
13928 else
13929 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13930 }
38c1f2d7
MM
13931 break;
13932 }
e165f3f0 13933}
a251ffd0 13934
b54cf83a
DE
13935\f
13936static int
863d938c 13937rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
13938{
13939 return 1;
13940}
13941
b54cf83a
DE
13942/* Power4 load update and store update instructions are cracked into a
13943 load or store and an integer insn which are executed in the same cycle.
13944 Branches have their own dispatch slot which does not count against the
13945 GCC issue rate, but it changes the program flow so there are no other
13946 instructions to issue in this cycle. */
13947
13948static int
a2369ed3
DJ
13949rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
13950 int verbose ATTRIBUTE_UNUSED,
13951 rtx insn, int more)
b54cf83a
DE
13952{
13953 if (GET_CODE (PATTERN (insn)) == USE
13954 || GET_CODE (PATTERN (insn)) == CLOBBER)
13955 return more;
13956
ec507f2d 13957 if (rs6000_sched_groups)
b54cf83a 13958 {
cbe26ab8
DN
13959 if (is_microcoded_insn (insn))
13960 return 0;
13961 else if (is_cracked_insn (insn))
13962 return more > 2 ? more - 2 : 0;
b54cf83a 13963 }
165b263e
DE
13964
13965 return more - 1;
b54cf83a
DE
13966}
13967
a251ffd0
TG
13968/* Adjust the cost of a scheduling dependency. Return the new cost of
13969 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
13970
c237e94a 13971static int
a2369ed3
DJ
13972rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
13973 int cost)
a251ffd0
TG
13974{
13975 if (! recog_memoized (insn))
13976 return 0;
13977
13978 if (REG_NOTE_KIND (link) != 0)
13979 return 0;
13980
13981 if (REG_NOTE_KIND (link) == 0)
13982 {
ed947a96
DJ
13983 /* Data dependency; DEP_INSN writes a register that INSN reads
13984 some cycles later. */
13985 switch (get_attr_type (insn))
13986 {
13987 case TYPE_JMPREG:
309323c2 13988 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
13989 a mtctr and bctr (and mtlr and br/blr). The first
13990 scheduling pass will not know about this latency since
13991 the mtctr instruction, which has the latency associated
13992 to it, will be generated by reload. */
309323c2 13993 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
13994 case TYPE_BRANCH:
13995 /* Leave some extra cycles between a compare and its
13996 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
13997 if ((rs6000_cpu_attr == CPU_PPC603
13998 || rs6000_cpu_attr == CPU_PPC604
13999 || rs6000_cpu_attr == CPU_PPC604E
14000 || rs6000_cpu_attr == CPU_PPC620
14001 || rs6000_cpu_attr == CPU_PPC630
14002 || rs6000_cpu_attr == CPU_PPC750
14003 || rs6000_cpu_attr == CPU_PPC7400
14004 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
14005 || rs6000_cpu_attr == CPU_POWER4
14006 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
14007 && recog_memoized (dep_insn)
14008 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
14009 && (get_attr_type (dep_insn) == TYPE_CMP
14010 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 14011 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
14012 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
14013 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 14014 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
14015 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
14016 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
14017 return cost + 2;
14018 default:
14019 break;
14020 }
a251ffd0
TG
14021 /* Fall out to return default cost. */
14022 }
14023
14024 return cost;
14025}
b6c9286a 14026
cbe26ab8 14027/* The function returns a true if INSN is microcoded.
839a4992 14028 Return false otherwise. */
cbe26ab8
DN
14029
14030static bool
14031is_microcoded_insn (rtx insn)
14032{
14033 if (!insn || !INSN_P (insn)
14034 || GET_CODE (PATTERN (insn)) == USE
14035 || GET_CODE (PATTERN (insn)) == CLOBBER)
14036 return false;
14037
ec507f2d 14038 if (rs6000_sched_groups)
cbe26ab8
DN
14039 {
14040 enum attr_type type = get_attr_type (insn);
14041 if (type == TYPE_LOAD_EXT_U
14042 || type == TYPE_LOAD_EXT_UX
14043 || type == TYPE_LOAD_UX
14044 || type == TYPE_STORE_UX
14045 || type == TYPE_MFCR)
14046 return true;
14047 }
14048
14049 return false;
14050}
14051
5c425df5 14052/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
14053 as the first insn in a dispatch group ("dispatch-slot restricted").
14054 In this case, the returned value indicates how many dispatch slots
14055 the insn occupies (at the beginning of the group).
79ae11c4
DN
14056 Return 0 otherwise. */
14057
cbe26ab8 14058static int
79ae11c4
DN
14059is_dispatch_slot_restricted (rtx insn)
14060{
14061 enum attr_type type;
14062
ec507f2d 14063 if (!rs6000_sched_groups)
79ae11c4
DN
14064 return 0;
14065
14066 if (!insn
14067 || insn == NULL_RTX
14068 || GET_CODE (insn) == NOTE
14069 || GET_CODE (PATTERN (insn)) == USE
14070 || GET_CODE (PATTERN (insn)) == CLOBBER)
14071 return 0;
14072
14073 type = get_attr_type (insn);
14074
ec507f2d
DE
14075 switch (type)
14076 {
14077 case TYPE_MFCR:
14078 case TYPE_MFCRF:
14079 case TYPE_MTCR:
14080 case TYPE_DELAYED_CR:
14081 case TYPE_CR_LOGICAL:
14082 case TYPE_MTJMPR:
14083 case TYPE_MFJMPR:
14084 return 1;
14085 case TYPE_IDIV:
14086 case TYPE_LDIV:
14087 return 2;
14088 default:
14089 if (rs6000_cpu == PROCESSOR_POWER5
14090 && is_cracked_insn (insn))
14091 return 2;
14092 return 0;
14093 }
79ae11c4
DN
14094}
14095
cbe26ab8
DN
14096/* The function returns true if INSN is cracked into 2 instructions
14097 by the processor (and therefore occupies 2 issue slots). */
14098
14099static bool
14100is_cracked_insn (rtx insn)
14101{
14102 if (!insn || !INSN_P (insn)
14103 || GET_CODE (PATTERN (insn)) == USE
14104 || GET_CODE (PATTERN (insn)) == CLOBBER)
14105 return false;
14106
ec507f2d 14107 if (rs6000_sched_groups)
cbe26ab8
DN
14108 {
14109 enum attr_type type = get_attr_type (insn);
14110 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
14111 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
14112 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
14113 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
14114 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
14115 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
14116 || type == TYPE_IDIV || type == TYPE_LDIV
14117 || type == TYPE_INSERT_WORD)
14118 return true;
14119 }
14120
14121 return false;
14122}
14123
14124/* The function returns true if INSN can be issued only from
a3c9585f 14125 the branch slot. */
cbe26ab8
DN
14126
14127static bool
14128is_branch_slot_insn (rtx insn)
14129{
14130 if (!insn || !INSN_P (insn)
14131 || GET_CODE (PATTERN (insn)) == USE
14132 || GET_CODE (PATTERN (insn)) == CLOBBER)
14133 return false;
14134
ec507f2d 14135 if (rs6000_sched_groups)
cbe26ab8
DN
14136 {
14137 enum attr_type type = get_attr_type (insn);
14138 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
14139 return true;
14140 return false;
14141 }
14142
14143 return false;
14144}
79ae11c4 14145
a4f6c312 14146/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
14147 priority INSN_PRIORITY (INSN). Increase the priority to execute the
14148 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
14149 define this macro if you do not need to adjust the scheduling
14150 priorities of insns. */
bef84347 14151
c237e94a 14152static int
a2369ed3 14153rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 14154{
a4f6c312
SS
14155 /* On machines (like the 750) which have asymmetric integer units,
14156 where one integer unit can do multiply and divides and the other
14157 can't, reduce the priority of multiply/divide so it is scheduled
14158 before other integer operations. */
bef84347
VM
14159
14160#if 0
2c3c49de 14161 if (! INSN_P (insn))
bef84347
VM
14162 return priority;
14163
14164 if (GET_CODE (PATTERN (insn)) == USE)
14165 return priority;
14166
14167 switch (rs6000_cpu_attr) {
14168 case CPU_PPC750:
14169 switch (get_attr_type (insn))
14170 {
14171 default:
14172 break;
14173
14174 case TYPE_IMUL:
14175 case TYPE_IDIV:
3cb999d8
DE
14176 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
14177 priority, priority);
bef84347
VM
14178 if (priority >= 0 && priority < 0x01000000)
14179 priority >>= 3;
14180 break;
14181 }
14182 }
14183#endif
14184
79ae11c4
DN
14185 if (is_dispatch_slot_restricted (insn)
14186 && reload_completed
14187 && current_sched_info->sched_max_insns_priority
14188 && rs6000_sched_restricted_insns_priority)
14189 {
14190
14191 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
14192 if (rs6000_sched_restricted_insns_priority == 1)
14193 /* Attach highest priority to insn. This means that in
14194 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
14195 precede 'priority' (critical path) considerations. */
14196 return current_sched_info->sched_max_insns_priority;
14197 else if (rs6000_sched_restricted_insns_priority == 2)
14198 /* Increase priority of insn by a minimal amount. This means that in
14199 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
14200 precede dispatch-slot restriction considerations. */
14201 return (priority + 1);
14202 }
14203
bef84347
VM
14204 return priority;
14205}
14206
a4f6c312
SS
14207/* Return how many instructions the machine can issue per cycle. */
14208
c237e94a 14209static int
863d938c 14210rs6000_issue_rate (void)
b6c9286a 14211{
3317bab1
DE
14212 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
14213 if (!reload_completed)
14214 return 1;
14215
b6c9286a 14216 switch (rs6000_cpu_attr) {
3cb999d8
DE
14217 case CPU_RIOS1: /* ? */
14218 case CPU_RS64A:
14219 case CPU_PPC601: /* ? */
ed947a96 14220 case CPU_PPC7450:
3cb999d8 14221 return 3;
b54cf83a 14222 case CPU_PPC440:
b6c9286a 14223 case CPU_PPC603:
bef84347 14224 case CPU_PPC750:
ed947a96 14225 case CPU_PPC7400:
be12c2b0 14226 case CPU_PPC8540:
bef84347 14227 return 2;
3cb999d8 14228 case CPU_RIOS2:
b6c9286a 14229 case CPU_PPC604:
19684119 14230 case CPU_PPC604E:
b6c9286a 14231 case CPU_PPC620:
3cb999d8 14232 case CPU_PPC630:
b6c9286a 14233 return 4;
cbe26ab8 14234 case CPU_POWER4:
ec507f2d 14235 case CPU_POWER5:
cbe26ab8 14236 return 5;
b6c9286a
MM
14237 default:
14238 return 1;
14239 }
14240}
14241
be12c2b0
VM
14242/* Return how many instructions to look ahead for better insn
14243 scheduling. */
14244
14245static int
863d938c 14246rs6000_use_sched_lookahead (void)
be12c2b0
VM
14247{
14248 if (rs6000_cpu_attr == CPU_PPC8540)
14249 return 4;
14250 return 0;
14251}
14252
569fa502
DN
14253/* Determine is PAT refers to memory. */
14254
14255static bool
14256is_mem_ref (rtx pat)
14257{
14258 const char * fmt;
14259 int i, j;
14260 bool ret = false;
14261
14262 if (GET_CODE (pat) == MEM)
14263 return true;
14264
14265 /* Recursively process the pattern. */
14266 fmt = GET_RTX_FORMAT (GET_CODE (pat));
14267
14268 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
14269 {
14270 if (fmt[i] == 'e')
14271 ret |= is_mem_ref (XEXP (pat, i));
14272 else if (fmt[i] == 'E')
14273 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
14274 ret |= is_mem_ref (XVECEXP (pat, i, j));
14275 }
14276
14277 return ret;
14278}
14279
14280/* Determine if PAT is a PATTERN of a load insn. */
14281
14282static bool
14283is_load_insn1 (rtx pat)
14284{
14285 if (!pat || pat == NULL_RTX)
14286 return false;
14287
14288 if (GET_CODE (pat) == SET)
14289 return is_mem_ref (SET_SRC (pat));
14290
14291 if (GET_CODE (pat) == PARALLEL)
14292 {
14293 int i;
14294
14295 for (i = 0; i < XVECLEN (pat, 0); i++)
14296 if (is_load_insn1 (XVECEXP (pat, 0, i)))
14297 return true;
14298 }
14299
14300 return false;
14301}
14302
14303/* Determine if INSN loads from memory. */
14304
14305static bool
14306is_load_insn (rtx insn)
14307{
14308 if (!insn || !INSN_P (insn))
14309 return false;
14310
14311 if (GET_CODE (insn) == CALL_INSN)
14312 return false;
14313
14314 return is_load_insn1 (PATTERN (insn));
14315}
14316
14317/* Determine if PAT is a PATTERN of a store insn. */
14318
14319static bool
14320is_store_insn1 (rtx pat)
14321{
14322 if (!pat || pat == NULL_RTX)
14323 return false;
14324
14325 if (GET_CODE (pat) == SET)
14326 return is_mem_ref (SET_DEST (pat));
14327
14328 if (GET_CODE (pat) == PARALLEL)
14329 {
14330 int i;
14331
14332 for (i = 0; i < XVECLEN (pat, 0); i++)
14333 if (is_store_insn1 (XVECEXP (pat, 0, i)))
14334 return true;
14335 }
14336
14337 return false;
14338}
14339
14340/* Determine if INSN stores to memory. */
14341
14342static bool
14343is_store_insn (rtx insn)
14344{
14345 if (!insn || !INSN_P (insn))
14346 return false;
14347
14348 return is_store_insn1 (PATTERN (insn));
14349}
14350
14351/* Returns whether the dependence between INSN and NEXT is considered
14352 costly by the given target. */
14353
14354static bool
14355rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
14356{
14357 /* If the flag is not enbled - no dependence is considered costly;
14358 allow all dependent insns in the same group.
14359 This is the most aggressive option. */
14360 if (rs6000_sched_costly_dep == no_dep_costly)
14361 return false;
14362
14363 /* If the flag is set to 1 - a dependence is always considered costly;
14364 do not allow dependent instructions in the same group.
14365 This is the most conservative option. */
14366 if (rs6000_sched_costly_dep == all_deps_costly)
14367 return true;
14368
14369 if (rs6000_sched_costly_dep == store_to_load_dep_costly
14370 && is_load_insn (next)
14371 && is_store_insn (insn))
14372 /* Prevent load after store in the same group. */
14373 return true;
14374
14375 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
14376 && is_load_insn (next)
14377 && is_store_insn (insn)
14378 && (!link || (int) REG_NOTE_KIND (link) == 0))
14379 /* Prevent load after store in the same group if it is a true dependence. */
14380 return true;
14381
14382 /* The flag is set to X; dependences with latency >= X are considered costly,
14383 and will not be scheduled in the same group. */
14384 if (rs6000_sched_costly_dep <= max_dep_latency
14385 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
14386 return true;
14387
14388 return false;
14389}
14390
cbe26ab8
DN
14391/* Return the next insn after INSN that is found before TAIL is reached,
14392 skipping any "non-active" insns - insns that will not actually occupy
14393 an issue slot. Return NULL_RTX if such an insn is not found. */
14394
14395static rtx
14396get_next_active_insn (rtx insn, rtx tail)
14397{
14398 rtx next_insn;
14399
14400 if (!insn || insn == tail)
14401 return NULL_RTX;
14402
14403 next_insn = NEXT_INSN (insn);
14404
14405 while (next_insn
14406 && next_insn != tail
14407 && (GET_CODE(next_insn) == NOTE
14408 || GET_CODE (PATTERN (next_insn)) == USE
14409 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
14410 {
14411 next_insn = NEXT_INSN (next_insn);
14412 }
14413
14414 if (!next_insn || next_insn == tail)
14415 return NULL_RTX;
14416
14417 return next_insn;
14418}
14419
839a4992 14420/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
14421 of group WHICH_GROUP.
14422
14423 If WHICH_GROUP == current_group, this function will return true if INSN
14424 causes the termination of the current group (i.e, the dispatch group to
14425 which INSN belongs). This means that INSN will be the last insn in the
14426 group it belongs to.
14427
14428 If WHICH_GROUP == previous_group, this function will return true if INSN
14429 causes the termination of the previous group (i.e, the dispatch group that
14430 precedes the group to which INSN belongs). This means that INSN will be
14431 the first insn in the group it belongs to). */
14432
14433static bool
14434insn_terminates_group_p (rtx insn, enum group_termination which_group)
14435{
14436 enum attr_type type;
14437
14438 if (! insn)
14439 return false;
569fa502 14440
cbe26ab8
DN
14441 type = get_attr_type (insn);
14442
14443 if (is_microcoded_insn (insn))
14444 return true;
14445
14446 if (which_group == current_group)
14447 {
14448 if (is_branch_slot_insn (insn))
14449 return true;
14450 return false;
14451 }
14452 else if (which_group == previous_group)
14453 {
14454 if (is_dispatch_slot_restricted (insn))
14455 return true;
14456 return false;
14457 }
14458
14459 return false;
14460}
14461
839a4992 14462/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
14463 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
14464
14465static bool
14466is_costly_group (rtx *group_insns, rtx next_insn)
14467{
14468 int i;
14469 rtx link;
14470 int cost;
14471 int issue_rate = rs6000_issue_rate ();
14472
14473 for (i = 0; i < issue_rate; i++)
14474 {
14475 rtx insn = group_insns[i];
14476 if (!insn)
14477 continue;
14478 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
14479 {
14480 rtx next = XEXP (link, 0);
14481 if (next == next_insn)
14482 {
14483 cost = insn_cost (insn, link, next_insn);
14484 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
14485 return true;
14486 }
14487 }
14488 }
14489
14490 return false;
14491}
14492
14493/* Utility of the function redefine_groups.
14494 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
14495 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
14496 to keep it "far" (in a separate group) from GROUP_INSNS, following
14497 one of the following schemes, depending on the value of the flag
14498 -minsert_sched_nops = X:
14499 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 14500 in order to force NEXT_INSN into a separate group.
cbe26ab8
DN
14501 (2) X < sched_finish_regroup_exact: insert exactly X nops.
14502 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
14503 insertion (has a group just ended, how many vacant issue slots remain in the
14504 last group, and how many dispatch groups were encountered so far). */
14505
14506static int
14507force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
14508 bool *group_end, int can_issue_more, int *group_count)
14509{
14510 rtx nop;
14511 bool force;
14512 int issue_rate = rs6000_issue_rate ();
14513 bool end = *group_end;
14514 int i;
14515
14516 if (next_insn == NULL_RTX)
14517 return can_issue_more;
14518
14519 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
14520 return can_issue_more;
14521
14522 force = is_costly_group (group_insns, next_insn);
14523 if (!force)
14524 return can_issue_more;
14525
14526 if (sched_verbose > 6)
14527 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
14528 *group_count ,can_issue_more);
14529
14530 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
14531 {
14532 if (*group_end)
14533 can_issue_more = 0;
14534
14535 /* Since only a branch can be issued in the last issue_slot, it is
14536 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
14537 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
14538 in this case the last nop will start a new group and the branch will be
14539 forced to the new group. */
14540 if (can_issue_more && !is_branch_slot_insn (next_insn))
14541 can_issue_more--;
14542
14543 while (can_issue_more > 0)
14544 {
14545 nop = gen_nop();
14546 emit_insn_before (nop, next_insn);
14547 can_issue_more--;
14548 }
14549
14550 *group_end = true;
14551 return 0;
14552 }
14553
14554 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
14555 {
14556 int n_nops = rs6000_sched_insert_nops;
14557
14558 /* Nops can't be issued from the branch slot, so the effective
14559 issue_rate for nops is 'issue_rate - 1'. */
14560 if (can_issue_more == 0)
14561 can_issue_more = issue_rate;
14562 can_issue_more--;
14563 if (can_issue_more == 0)
14564 {
14565 can_issue_more = issue_rate - 1;
14566 (*group_count)++;
14567 end = true;
14568 for (i = 0; i < issue_rate; i++)
14569 {
14570 group_insns[i] = 0;
14571 }
14572 }
14573
14574 while (n_nops > 0)
14575 {
14576 nop = gen_nop ();
14577 emit_insn_before (nop, next_insn);
14578 if (can_issue_more == issue_rate - 1) /* new group begins */
14579 end = false;
14580 can_issue_more--;
14581 if (can_issue_more == 0)
14582 {
14583 can_issue_more = issue_rate - 1;
14584 (*group_count)++;
14585 end = true;
14586 for (i = 0; i < issue_rate; i++)
14587 {
14588 group_insns[i] = 0;
14589 }
14590 }
14591 n_nops--;
14592 }
14593
14594 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
14595 can_issue_more++;
14596
14597 *group_end = /* Is next_insn going to start a new group? */
14598 (end
14599 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14600 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14601 || (can_issue_more < issue_rate &&
14602 insn_terminates_group_p (next_insn, previous_group)));
14603 if (*group_end && end)
14604 (*group_count)--;
14605
14606 if (sched_verbose > 6)
14607 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
14608 *group_count, can_issue_more);
14609 return can_issue_more;
14610 }
14611
14612 return can_issue_more;
14613}
14614
14615/* This function tries to synch the dispatch groups that the compiler "sees"
14616 with the dispatch groups that the processor dispatcher is expected to
14617 form in practice. It tries to achieve this synchronization by forcing the
14618 estimated processor grouping on the compiler (as opposed to the function
14619 'pad_goups' which tries to force the scheduler's grouping on the processor).
14620
14621 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
14622 examines the (estimated) dispatch groups that will be formed by the processor
14623 dispatcher. It marks these group boundaries to reflect the estimated
14624 processor grouping, overriding the grouping that the scheduler had marked.
14625 Depending on the value of the flag '-minsert-sched-nops' this function can
14626 force certain insns into separate groups or force a certain distance between
14627 them by inserting nops, for example, if there exists a "costly dependence"
14628 between the insns.
14629
14630 The function estimates the group boundaries that the processor will form as
14631 folllows: It keeps track of how many vacant issue slots are available after
14632 each insn. A subsequent insn will start a new group if one of the following
14633 4 cases applies:
14634 - no more vacant issue slots remain in the current dispatch group.
14635 - only the last issue slot, which is the branch slot, is vacant, but the next
14636 insn is not a branch.
14637 - only the last 2 or less issue slots, including the branch slot, are vacant,
14638 which means that a cracked insn (which occupies two issue slots) can't be
14639 issued in this group.
14640 - less than 'issue_rate' slots are vacant, and the next insn always needs to
14641 start a new group. */
14642
14643static int
14644redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14645{
14646 rtx insn, next_insn;
14647 int issue_rate;
14648 int can_issue_more;
14649 int slot, i;
14650 bool group_end;
14651 int group_count = 0;
14652 rtx *group_insns;
14653
14654 /* Initialize. */
14655 issue_rate = rs6000_issue_rate ();
14656 group_insns = alloca (issue_rate * sizeof (rtx));
14657 for (i = 0; i < issue_rate; i++)
14658 {
14659 group_insns[i] = 0;
14660 }
14661 can_issue_more = issue_rate;
14662 slot = 0;
14663 insn = get_next_active_insn (prev_head_insn, tail);
14664 group_end = false;
14665
14666 while (insn != NULL_RTX)
14667 {
14668 slot = (issue_rate - can_issue_more);
14669 group_insns[slot] = insn;
14670 can_issue_more =
14671 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14672 if (insn_terminates_group_p (insn, current_group))
14673 can_issue_more = 0;
14674
14675 next_insn = get_next_active_insn (insn, tail);
14676 if (next_insn == NULL_RTX)
14677 return group_count + 1;
14678
14679 group_end = /* Is next_insn going to start a new group? */
14680 (can_issue_more == 0
14681 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14682 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14683 || (can_issue_more < issue_rate &&
14684 insn_terminates_group_p (next_insn, previous_group)));
14685
14686 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
14687 next_insn, &group_end, can_issue_more, &group_count);
14688
14689 if (group_end)
14690 {
14691 group_count++;
14692 can_issue_more = 0;
14693 for (i = 0; i < issue_rate; i++)
14694 {
14695 group_insns[i] = 0;
14696 }
14697 }
14698
14699 if (GET_MODE (next_insn) == TImode && can_issue_more)
14700 PUT_MODE(next_insn, VOIDmode);
14701 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
14702 PUT_MODE (next_insn, TImode);
14703
14704 insn = next_insn;
14705 if (can_issue_more == 0)
14706 can_issue_more = issue_rate;
14707 } /* while */
14708
14709 return group_count;
14710}
14711
14712/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
14713 dispatch group boundaries that the scheduler had marked. Pad with nops
14714 any dispatch groups which have vacant issue slots, in order to force the
14715 scheduler's grouping on the processor dispatcher. The function
14716 returns the number of dispatch groups found. */
14717
14718static int
14719pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14720{
14721 rtx insn, next_insn;
14722 rtx nop;
14723 int issue_rate;
14724 int can_issue_more;
14725 int group_end;
14726 int group_count = 0;
14727
14728 /* Initialize issue_rate. */
14729 issue_rate = rs6000_issue_rate ();
14730 can_issue_more = issue_rate;
14731
14732 insn = get_next_active_insn (prev_head_insn, tail);
14733 next_insn = get_next_active_insn (insn, tail);
14734
14735 while (insn != NULL_RTX)
14736 {
14737 can_issue_more =
14738 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14739
14740 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
14741
14742 if (next_insn == NULL_RTX)
14743 break;
14744
14745 if (group_end)
14746 {
14747 /* If the scheduler had marked group termination at this location
14748 (between insn and next_indn), and neither insn nor next_insn will
14749 force group termination, pad the group with nops to force group
14750 termination. */
14751 if (can_issue_more
14752 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
14753 && !insn_terminates_group_p (insn, current_group)
14754 && !insn_terminates_group_p (next_insn, previous_group))
14755 {
14756 if (!is_branch_slot_insn(next_insn))
14757 can_issue_more--;
14758
14759 while (can_issue_more)
14760 {
14761 nop = gen_nop ();
14762 emit_insn_before (nop, next_insn);
14763 can_issue_more--;
14764 }
14765 }
14766
14767 can_issue_more = issue_rate;
14768 group_count++;
14769 }
14770
14771 insn = next_insn;
14772 next_insn = get_next_active_insn (insn, tail);
14773 }
14774
14775 return group_count;
14776}
14777
14778/* The following function is called at the end of scheduling BB.
14779 After reload, it inserts nops at insn group bundling. */
14780
14781static void
38f391a5 14782rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
14783{
14784 int n_groups;
14785
14786 if (sched_verbose)
14787 fprintf (dump, "=== Finishing schedule.\n");
14788
ec507f2d 14789 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
14790 {
14791 if (rs6000_sched_insert_nops == sched_finish_none)
14792 return;
14793
14794 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
14795 n_groups = pad_groups (dump, sched_verbose,
14796 current_sched_info->prev_head,
14797 current_sched_info->next_tail);
14798 else
14799 n_groups = redefine_groups (dump, sched_verbose,
14800 current_sched_info->prev_head,
14801 current_sched_info->next_tail);
14802
14803 if (sched_verbose >= 6)
14804 {
14805 fprintf (dump, "ngroups = %d\n", n_groups);
14806 print_rtl (dump, current_sched_info->prev_head);
14807 fprintf (dump, "Done finish_sched\n");
14808 }
14809 }
14810}
b6c9286a 14811\f
b6c9286a
MM
14812/* Length in units of the trampoline for entering a nested function. */
14813
14814int
863d938c 14815rs6000_trampoline_size (void)
b6c9286a
MM
14816{
14817 int ret = 0;
14818
14819 switch (DEFAULT_ABI)
14820 {
14821 default:
14822 abort ();
14823
14824 case ABI_AIX:
8f802bfb 14825 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
14826 break;
14827
4dabc42d 14828 case ABI_DARWIN:
b6c9286a 14829 case ABI_V4:
03a7e1a5 14830 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 14831 break;
b6c9286a
MM
14832 }
14833
14834 return ret;
14835}
14836
14837/* Emit RTL insns to initialize the variable parts of a trampoline.
14838 FNADDR is an RTX for the address of the function's pure code.
14839 CXT is an RTX for the static chain value for the function. */
14840
14841void
a2369ed3 14842rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 14843{
ac2a93a1 14844 enum machine_mode pmode = Pmode;
8bd04c56
MM
14845 int regsize = (TARGET_32BIT) ? 4 : 8;
14846 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
14847
14848 switch (DEFAULT_ABI)
14849 {
14850 default:
14851 abort ();
14852
8bd04c56 14853/* Macros to shorten the code expansions below. */
39403d82 14854#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
14855#define MEM_PLUS(addr,offset) \
14856 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 14857
b6c9286a
MM
14858 /* Under AIX, just build the 3 word function descriptor */
14859 case ABI_AIX:
8bd04c56
MM
14860 {
14861 rtx fn_reg = gen_reg_rtx (pmode);
14862 rtx toc_reg = gen_reg_rtx (pmode);
14863 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 14864 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
14865 emit_move_insn (MEM_DEREF (addr), fn_reg);
14866 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
14867 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
14868 }
b6c9286a
MM
14869 break;
14870
4dabc42d
TC
14871 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
14872 case ABI_DARWIN:
b6c9286a 14873 case ABI_V4:
39403d82 14874 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
14875 FALSE, VOIDmode, 4,
14876 addr, pmode,
14877 GEN_INT (rs6000_trampoline_size ()), SImode,
14878 fnaddr, pmode,
14879 ctx_reg, pmode);
b6c9286a 14880 break;
b6c9286a
MM
14881 }
14882
14883 return;
14884}
7509c759
MM
14885
14886\f
91d231cb 14887/* Table of valid machine attributes. */
a4f6c312 14888
91d231cb 14889const struct attribute_spec rs6000_attribute_table[] =
7509c759 14890{
91d231cb 14891 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 14892 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
14893 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14894 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14895 { NULL, 0, 0, false, false, false, NULL }
91d231cb 14896};
7509c759 14897
8bb418a3
ZL
14898/* Handle the "altivec" attribute. The attribute may have
14899 arguments as follows:
14900
14901 __attribute__((altivec(vector__)))
14902 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
14903 __attribute__((altivec(bool__))) (always followed by 'unsigned')
14904
14905 and may appear more than once (e.g., 'vector bool char') in a
14906 given declaration. */
14907
14908static tree
14909rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
14910 int flags ATTRIBUTE_UNUSED,
14911 bool *no_add_attrs)
14912{
14913 tree type = *node, result = NULL_TREE;
14914 enum machine_mode mode;
14915 int unsigned_p;
14916 char altivec_type
14917 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
14918 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
14919 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
14920 : '?');
14921
14922 while (POINTER_TYPE_P (type)
14923 || TREE_CODE (type) == FUNCTION_TYPE
14924 || TREE_CODE (type) == METHOD_TYPE
14925 || TREE_CODE (type) == ARRAY_TYPE)
14926 type = TREE_TYPE (type);
14927
14928 mode = TYPE_MODE (type);
14929
14930 if (rs6000_warn_altivec_long
14931 && (type == long_unsigned_type_node || type == long_integer_type_node))
14932 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
14933
14934 switch (altivec_type)
14935 {
14936 case 'v':
8df83eae 14937 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
14938 switch (mode)
14939 {
14940 case SImode:
14941 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
14942 break;
14943 case HImode:
14944 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
14945 break;
14946 case QImode:
14947 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
14948 break;
14949 case SFmode: result = V4SF_type_node; break;
14950 /* If the user says 'vector int bool', we may be handed the 'bool'
14951 attribute _before_ the 'vector' attribute, and so select the proper
14952 type in the 'b' case below. */
14953 case V4SImode: case V8HImode: case V16QImode: result = type;
14954 default: break;
14955 }
14956 break;
14957 case 'b':
14958 switch (mode)
14959 {
14960 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
14961 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
14962 case QImode: case V16QImode: result = bool_V16QI_type_node;
14963 default: break;
14964 }
14965 break;
14966 case 'p':
14967 switch (mode)
14968 {
14969 case V8HImode: result = pixel_V8HI_type_node;
14970 default: break;
14971 }
14972 default: break;
14973 }
14974
14975 *no_add_attrs = true; /* No need to hang on to the attribute. */
14976
14977 if (!result)
14978 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
14979 else
14980 *node = reconstruct_complex_type (*node, result);
14981
14982 return NULL_TREE;
14983}
14984
f18eca82
ZL
14985/* AltiVec defines four built-in scalar types that serve as vector
14986 elements; we must teach the compiler how to mangle them. */
14987
14988static const char *
14989rs6000_mangle_fundamental_type (tree type)
14990{
14991 if (type == bool_char_type_node) return "U6__boolc";
14992 if (type == bool_short_type_node) return "U6__bools";
14993 if (type == pixel_type_node) return "u7__pixel";
14994 if (type == bool_int_type_node) return "U6__booli";
14995
14996 /* For all other types, use normal C++ mangling. */
14997 return NULL;
14998}
14999
a5c76ee6
ZW
15000/* Handle a "longcall" or "shortcall" attribute; arguments as in
15001 struct attribute_spec.handler. */
a4f6c312 15002
91d231cb 15003static tree
a2369ed3
DJ
15004rs6000_handle_longcall_attribute (tree *node, tree name,
15005 tree args ATTRIBUTE_UNUSED,
15006 int flags ATTRIBUTE_UNUSED,
15007 bool *no_add_attrs)
91d231cb
JM
15008{
15009 if (TREE_CODE (*node) != FUNCTION_TYPE
15010 && TREE_CODE (*node) != FIELD_DECL
15011 && TREE_CODE (*node) != TYPE_DECL)
15012 {
15013 warning ("`%s' attribute only applies to functions",
15014 IDENTIFIER_POINTER (name));
15015 *no_add_attrs = true;
15016 }
6a4cee5f 15017
91d231cb 15018 return NULL_TREE;
7509c759
MM
15019}
15020
a5c76ee6
ZW
15021/* Set longcall attributes on all functions declared when
15022 rs6000_default_long_calls is true. */
15023static void
a2369ed3 15024rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
15025{
15026 if (rs6000_default_long_calls
15027 && (TREE_CODE (type) == FUNCTION_TYPE
15028 || TREE_CODE (type) == METHOD_TYPE))
15029 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
15030 NULL_TREE,
15031 TYPE_ATTRIBUTES (type));
15032}
15033
3cb999d8
DE
15034/* Return a reference suitable for calling a function with the
15035 longcall attribute. */
a4f6c312 15036
6a4cee5f 15037struct rtx_def *
a2369ed3 15038rs6000_longcall_ref (rtx call_ref)
6a4cee5f 15039{
d330fd93 15040 const char *call_name;
6a4cee5f
MM
15041 tree node;
15042
15043 if (GET_CODE (call_ref) != SYMBOL_REF)
15044 return call_ref;
15045
15046 /* System V adds '.' to the internal name, so skip them. */
15047 call_name = XSTR (call_ref, 0);
15048 if (*call_name == '.')
15049 {
15050 while (*call_name == '.')
15051 call_name++;
15052
15053 node = get_identifier (call_name);
39403d82 15054 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
15055 }
15056
15057 return force_reg (Pmode, call_ref);
15058}
7509c759 15059\f
b64a1b53
RH
15060#ifdef USING_ELFOS_H
15061
7509c759
MM
15062/* A C statement or statements to switch to the appropriate section
15063 for output of RTX in mode MODE. You can assume that RTX is some
15064 kind of constant in RTL. The argument MODE is redundant except in
15065 the case of a `const_int' rtx. Select the section by calling
15066 `text_section' or one of the alternatives for other sections.
15067
15068 Do not define this macro if you put all constants in the read-only
15069 data section. */
15070
b64a1b53 15071static void
a2369ed3
DJ
15072rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
15073 unsigned HOST_WIDE_INT align)
7509c759 15074{
a9098fd0 15075 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 15076 toc_section ();
7509c759 15077 else
b64a1b53 15078 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
15079}
15080
15081/* A C statement or statements to switch to the appropriate
15082 section for output of DECL. DECL is either a `VAR_DECL' node
15083 or a constant of some sort. RELOC indicates whether forming
15084 the initial value of DECL requires link-time relocations. */
15085
ae46c4e0 15086static void
a2369ed3
DJ
15087rs6000_elf_select_section (tree decl, int reloc,
15088 unsigned HOST_WIDE_INT align)
7509c759 15089{
f1384257
AM
15090 /* Pretend that we're always building for a shared library when
15091 ABI_AIX, because otherwise we end up with dynamic relocations
15092 in read-only sections. This happens for function pointers,
15093 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
15094 default_elf_select_section_1 (decl, reloc, align,
15095 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
15096}
15097
15098/* A C statement to build up a unique section name, expressed as a
15099 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
15100 RELOC indicates whether the initial value of EXP requires
15101 link-time relocations. If you do not define this macro, GCC will use
15102 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 15103 macro can now be called for uninitialized data items as well as
4912a07c 15104 initialized data and functions. */
63019373 15105
ae46c4e0 15106static void
a2369ed3 15107rs6000_elf_unique_section (tree decl, int reloc)
63019373 15108{
f1384257
AM
15109 /* As above, pretend that we're always building for a shared library
15110 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
15111 default_unique_section_1 (decl, reloc,
15112 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 15113}
d9407988 15114\f
d1908feb
JJ
15115/* For a SYMBOL_REF, set generic flags and then perform some
15116 target-specific processing.
15117
d1908feb
JJ
15118 When the AIX ABI is requested on a non-AIX system, replace the
15119 function name with the real name (with a leading .) rather than the
15120 function descriptor name. This saves a lot of overriding code to
15121 read the prefixes. */
d9407988 15122
fb49053f 15123static void
a2369ed3 15124rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 15125{
d1908feb 15126 default_encode_section_info (decl, rtl, first);
b2003250 15127
d1908feb
JJ
15128 if (first
15129 && TREE_CODE (decl) == FUNCTION_DECL
15130 && !TARGET_AIX
15131 && DEFAULT_ABI == ABI_AIX)
d9407988 15132 {
c6a2438a 15133 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
15134 size_t len = strlen (XSTR (sym_ref, 0));
15135 char *str = alloca (len + 2);
15136 str[0] = '.';
15137 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
15138 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 15139 }
d9407988
MM
15140}
15141
0e5dbd9b 15142static bool
a2369ed3 15143rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
15144{
15145 if (rs6000_sdata == SDATA_NONE)
15146 return false;
15147
15148 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
15149 {
15150 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
15151 if (strcmp (section, ".sdata") == 0
15152 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
15153 || strcmp (section, ".sbss") == 0
15154 || strcmp (section, ".sbss2") == 0
15155 || strcmp (section, ".PPC.EMB.sdata0") == 0
15156 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
15157 return true;
15158 }
15159 else
15160 {
15161 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
15162
15163 if (size > 0
307b599c 15164 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
15165 /* If it's not public, and we're not going to reference it there,
15166 there's no need to put it in the small data section. */
0e5dbd9b
DE
15167 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
15168 return true;
15169 }
15170
15171 return false;
15172}
15173
b91da81f 15174#endif /* USING_ELFOS_H */
000034eb 15175
a6c2a102 15176\f
000034eb 15177/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
15178 ADDR can be effectively incremented by incrementing REG.
15179
15180 r0 is special and we must not select it as an address
15181 register by this routine since our caller will try to
15182 increment the returned register via an "la" instruction. */
000034eb
DE
15183
15184struct rtx_def *
a2369ed3 15185find_addr_reg (rtx addr)
000034eb
DE
15186{
15187 while (GET_CODE (addr) == PLUS)
15188 {
02441cd6
JL
15189 if (GET_CODE (XEXP (addr, 0)) == REG
15190 && REGNO (XEXP (addr, 0)) != 0)
000034eb 15191 addr = XEXP (addr, 0);
02441cd6
JL
15192 else if (GET_CODE (XEXP (addr, 1)) == REG
15193 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
15194 addr = XEXP (addr, 1);
15195 else if (CONSTANT_P (XEXP (addr, 0)))
15196 addr = XEXP (addr, 1);
15197 else if (CONSTANT_P (XEXP (addr, 1)))
15198 addr = XEXP (addr, 0);
15199 else
15200 abort ();
15201 }
02441cd6 15202 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
15203 return addr;
15204 abort ();
15205}
15206
a6c2a102 15207void
a2369ed3 15208rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
15209{
15210 fatal_insn ("bad address", op);
15211}
c8023011 15212
ee890fe2
SS
15213#if TARGET_MACHO
15214
15215#if 0
15216/* Returns 1 if OP is either a symbol reference or a sum of a symbol
15217 reference and a constant. */
15218
15219int
a2369ed3 15220symbolic_operand (rtx op)
ee890fe2
SS
15221{
15222 switch (GET_CODE (op))
15223 {
15224 case SYMBOL_REF:
15225 case LABEL_REF:
15226 return 1;
15227 case CONST:
15228 op = XEXP (op, 0);
15229 return (GET_CODE (op) == SYMBOL_REF ||
15230 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
15231 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
15232 && GET_CODE (XEXP (op, 1)) == CONST_INT);
15233 default:
15234 return 0;
15235 }
c8023011 15236}
ee890fe2
SS
15237#endif
15238
efdba735 15239#if TARGET_MACHO
ee890fe2 15240
efdba735 15241static tree branch_island_list = 0;
ee890fe2 15242
efdba735
SH
15243/* Remember to generate a branch island for far calls to the given
15244 function. */
ee890fe2 15245
efdba735
SH
15246static void
15247add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 15248{
efdba735
SH
15249 tree branch_island = build_tree_list (function_name, label_name);
15250 TREE_TYPE (branch_island) = build_int_2 (line_number, 0);
15251 TREE_CHAIN (branch_island) = branch_island_list;
15252 branch_island_list = branch_island;
ee890fe2
SS
15253}
15254
efdba735
SH
15255#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
15256#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
15257#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
15258 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 15259
efdba735
SH
15260/* Generate far-jump branch islands for everything on the
15261 branch_island_list. Invoked immediately after the last instruction
15262 of the epilogue has been emitted; the branch-islands must be
15263 appended to, and contiguous with, the function body. Mach-O stubs
15264 are generated in machopic_output_stub(). */
ee890fe2 15265
efdba735
SH
15266static void
15267macho_branch_islands (void)
15268{
15269 char tmp_buf[512];
15270 tree branch_island;
15271
15272 for (branch_island = branch_island_list;
15273 branch_island;
15274 branch_island = TREE_CHAIN (branch_island))
15275 {
15276 const char *label =
15277 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
15278 const char *name =
15279 darwin_strip_name_encoding (
15280 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)));
15281 char name_buf[512];
15282 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
15283 if (name[0] == '*' || name[0] == '&')
15284 strcpy (name_buf, name+1);
15285 else
15286 {
15287 name_buf[0] = '_';
15288 strcpy (name_buf+1, name);
15289 }
15290 strcpy (tmp_buf, "\n");
15291 strcat (tmp_buf, label);
ee890fe2 15292#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15293 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15294 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15295 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 15296#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
15297 if (flag_pic)
15298 {
15299 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
15300 strcat (tmp_buf, label);
15301 strcat (tmp_buf, "_pic\n");
15302 strcat (tmp_buf, label);
15303 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
15304
15305 strcat (tmp_buf, "\taddis r11,r11,ha16(");
15306 strcat (tmp_buf, name_buf);
15307 strcat (tmp_buf, " - ");
15308 strcat (tmp_buf, label);
15309 strcat (tmp_buf, "_pic)\n");
15310
15311 strcat (tmp_buf, "\tmtlr r0\n");
15312
15313 strcat (tmp_buf, "\taddi r12,r11,lo16(");
15314 strcat (tmp_buf, name_buf);
15315 strcat (tmp_buf, " - ");
15316 strcat (tmp_buf, label);
15317 strcat (tmp_buf, "_pic)\n");
15318
15319 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
15320 }
15321 else
15322 {
15323 strcat (tmp_buf, ":\nlis r12,hi16(");
15324 strcat (tmp_buf, name_buf);
15325 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
15326 strcat (tmp_buf, name_buf);
15327 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
15328 }
15329 output_asm_insn (tmp_buf, 0);
ee890fe2 15330#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15331 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15332 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15333 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 15334#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 15335 }
ee890fe2 15336
efdba735 15337 branch_island_list = 0;
ee890fe2
SS
15338}
15339
15340/* NO_PREVIOUS_DEF checks in the link list whether the function name is
15341 already there or not. */
15342
efdba735 15343static int
a2369ed3 15344no_previous_def (tree function_name)
ee890fe2 15345{
efdba735
SH
15346 tree branch_island;
15347 for (branch_island = branch_island_list;
15348 branch_island;
15349 branch_island = TREE_CHAIN (branch_island))
15350 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
15351 return 0;
15352 return 1;
15353}
15354
15355/* GET_PREV_LABEL gets the label name from the previous definition of
15356 the function. */
15357
efdba735 15358static tree
a2369ed3 15359get_prev_label (tree function_name)
ee890fe2 15360{
efdba735
SH
15361 tree branch_island;
15362 for (branch_island = branch_island_list;
15363 branch_island;
15364 branch_island = TREE_CHAIN (branch_island))
15365 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
15366 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
15367 return 0;
15368}
15369
15370/* INSN is either a function call or a millicode call. It may have an
15371 unconditional jump in its delay slot.
15372
15373 CALL_DEST is the routine we are calling. */
15374
15375char *
efdba735 15376output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
15377{
15378 static char buf[256];
efdba735
SH
15379 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
15380 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
15381 {
15382 tree labelname;
efdba735 15383 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
ee890fe2
SS
15384
15385 if (no_previous_def (funname))
15386 {
308c142a 15387 int line_number = 0;
ee890fe2
SS
15388 rtx label_rtx = gen_label_rtx ();
15389 char *label_buf, temp_buf[256];
15390 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
15391 CODE_LABEL_NUMBER (label_rtx));
15392 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
15393 labelname = get_identifier (label_buf);
15394 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
15395 if (insn)
15396 line_number = NOTE_LINE_NUMBER (insn);
efdba735 15397 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
15398 }
15399 else
15400 labelname = get_prev_label (funname);
15401
efdba735
SH
15402 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
15403 instruction will reach 'foo', otherwise link as 'bl L42'".
15404 "L42" should be a 'branch island', that will do a far jump to
15405 'foo'. Branch islands are generated in
15406 macho_branch_islands(). */
ee890fe2 15407 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 15408 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
15409 }
15410 else
efdba735
SH
15411 sprintf (buf, "bl %%z%d", dest_operand_number);
15412 return buf;
ee890fe2
SS
15413}
15414
efdba735 15415#endif /* TARGET_MACHO */
ee890fe2 15416
ee890fe2
SS
15417/* Generate PIC and indirect symbol stubs. */
15418
15419void
a2369ed3 15420machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
15421{
15422 unsigned int length;
a4f6c312
SS
15423 char *symbol_name, *lazy_ptr_name;
15424 char *local_label_0;
ee890fe2
SS
15425 static int label = 0;
15426
df56a27f 15427 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 15428 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 15429
ee890fe2 15430
ee890fe2
SS
15431 length = strlen (symb);
15432 symbol_name = alloca (length + 32);
15433 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
15434
15435 lazy_ptr_name = alloca (length + 32);
15436 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
15437
ee890fe2 15438 if (flag_pic == 2)
d3c300d2 15439 machopic_picsymbol_stub1_section ();
ee890fe2 15440 else
d3c300d2
DJ
15441 machopic_symbol_stub1_section ();
15442 fprintf (file, "\t.align 2\n");
ee890fe2
SS
15443
15444 fprintf (file, "%s:\n", stub);
15445 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15446
15447 if (flag_pic == 2)
15448 {
876455fa
AP
15449 label++;
15450 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
15451 sprintf (local_label_0, "\"L%011d$spb\"", label);
15452
ee890fe2
SS
15453 fprintf (file, "\tmflr r0\n");
15454 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
15455 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
15456 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
15457 lazy_ptr_name, local_label_0);
15458 fprintf (file, "\tmtlr r0\n");
d3c300d2 15459 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
15460 lazy_ptr_name, local_label_0);
15461 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
15462 fprintf (file, "\tbctr\n");
15463 }
15464 else
ab82a49f
AP
15465 {
15466 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
15467 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
15468 fprintf (file, "\tmtctr r12\n");
15469 fprintf (file, "\tbctr\n");
15470 }
ee890fe2
SS
15471
15472 machopic_lazy_symbol_ptr_section ();
15473 fprintf (file, "%s:\n", lazy_ptr_name);
15474 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15475 fprintf (file, "\t.long dyld_stub_binding_helper\n");
15476}
15477
15478/* Legitimize PIC addresses. If the address is already
15479 position-independent, we return ORIG. Newly generated
15480 position-independent addresses go into a reg. This is REG if non
15481 zero, otherwise we allocate register(s) as necessary. */
15482
c859cda6 15483#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
15484
15485rtx
a2369ed3
DJ
15486rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
15487 rtx reg)
ee890fe2
SS
15488{
15489 rtx base, offset;
15490
15491 if (reg == NULL && ! reload_in_progress && ! reload_completed)
15492 reg = gen_reg_rtx (Pmode);
15493
15494 if (GET_CODE (orig) == CONST)
15495 {
15496 if (GET_CODE (XEXP (orig, 0)) == PLUS
15497 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
15498 return orig;
15499
15500 if (GET_CODE (XEXP (orig, 0)) == PLUS)
15501 {
2cf520bf 15502 /* Use a different reg for the intermediate value, as
a3c9585f 15503 it will be marked UNCHANGING. */
2cf520bf
GK
15504 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
15505
a4f6c312
SS
15506 base =
15507 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 15508 Pmode, reg_temp);
a4f6c312
SS
15509 offset =
15510 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
15511 Pmode, reg);
ee890fe2
SS
15512 }
15513 else
15514 abort ();
15515
15516 if (GET_CODE (offset) == CONST_INT)
15517 {
15518 if (SMALL_INT (offset))
ed8908e7 15519 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
15520 else if (! reload_in_progress && ! reload_completed)
15521 offset = force_reg (Pmode, offset);
15522 else
c859cda6
DJ
15523 {
15524 rtx mem = force_const_mem (Pmode, orig);
15525 return machopic_legitimize_pic_address (mem, Pmode, reg);
15526 }
ee890fe2 15527 }
f1c25d3b 15528 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
15529 }
15530
15531 /* Fall back on generic machopic code. */
15532 return machopic_legitimize_pic_address (orig, mode, reg);
15533}
15534
15535/* This is just a placeholder to make linking work without having to
15536 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
15537 ever needed for Darwin (not too likely!) this would have to get a
15538 real definition. */
15539
15540void
863d938c 15541toc_section (void)
ee890fe2
SS
15542{
15543}
15544
15545#endif /* TARGET_MACHO */
7c262518
RH
15546
15547#if TARGET_ELF
15548static unsigned int
a2369ed3 15549rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 15550{
1ff8f81a
AM
15551 return default_section_type_flags_1 (decl, name, reloc,
15552 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 15553}
d9f6800d
RH
15554
15555/* Record an element in the table of global constructors. SYMBOL is
15556 a SYMBOL_REF of the function to be called; PRIORITY is a number
15557 between 0 and MAX_INIT_PRIORITY.
15558
15559 This differs from default_named_section_asm_out_constructor in
15560 that we have special handling for -mrelocatable. */
15561
15562static void
a2369ed3 15563rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
15564{
15565 const char *section = ".ctors";
15566 char buf[16];
15567
15568 if (priority != DEFAULT_INIT_PRIORITY)
15569 {
15570 sprintf (buf, ".ctors.%.5u",
15571 /* Invert the numbering so the linker puts us in the proper
15572 order; constructors are run from right to left, and the
15573 linker sorts in increasing order. */
15574 MAX_INIT_PRIORITY - priority);
15575 section = buf;
15576 }
15577
715bdd29
RH
15578 named_section_flags (section, SECTION_WRITE);
15579 assemble_align (POINTER_SIZE);
d9f6800d
RH
15580
15581 if (TARGET_RELOCATABLE)
15582 {
15583 fputs ("\t.long (", asm_out_file);
15584 output_addr_const (asm_out_file, symbol);
15585 fputs (")@fixup\n", asm_out_file);
15586 }
15587 else
c8af3574 15588 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
15589}
15590
15591static void
a2369ed3 15592rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
15593{
15594 const char *section = ".dtors";
15595 char buf[16];
15596
15597 if (priority != DEFAULT_INIT_PRIORITY)
15598 {
15599 sprintf (buf, ".dtors.%.5u",
15600 /* Invert the numbering so the linker puts us in the proper
15601 order; constructors are run from right to left, and the
15602 linker sorts in increasing order. */
15603 MAX_INIT_PRIORITY - priority);
15604 section = buf;
15605 }
15606
715bdd29
RH
15607 named_section_flags (section, SECTION_WRITE);
15608 assemble_align (POINTER_SIZE);
d9f6800d
RH
15609
15610 if (TARGET_RELOCATABLE)
15611 {
15612 fputs ("\t.long (", asm_out_file);
15613 output_addr_const (asm_out_file, symbol);
15614 fputs (")@fixup\n", asm_out_file);
15615 }
15616 else
c8af3574 15617 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 15618}
9739c90c
JJ
15619
15620void
a2369ed3 15621rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
15622{
15623 if (TARGET_64BIT)
15624 {
15625 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
15626 ASM_OUTPUT_LABEL (file, name);
15627 fputs (DOUBLE_INT_ASM_OP, file);
15628 putc ('.', file);
15629 assemble_name (file, name);
15630 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
15631 assemble_name (file, name);
15632 fputs (",24\n\t.type\t.", file);
15633 assemble_name (file, name);
15634 fputs (",@function\n", file);
15635 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
15636 {
15637 fputs ("\t.globl\t.", file);
15638 assemble_name (file, name);
15639 putc ('\n', file);
15640 }
15641 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15642 putc ('.', file);
15643 ASM_OUTPUT_LABEL (file, name);
15644 return;
15645 }
15646
15647 if (TARGET_RELOCATABLE
15648 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 15649 && uses_TOC ())
9739c90c
JJ
15650 {
15651 char buf[256];
15652
15653 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
15654
15655 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
15656 fprintf (file, "\t.long ");
15657 assemble_name (file, buf);
15658 putc ('-', file);
15659 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
15660 assemble_name (file, buf);
15661 putc ('\n', file);
15662 }
15663
15664 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
15665 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15666
15667 if (DEFAULT_ABI == ABI_AIX)
15668 {
15669 const char *desc_name, *orig_name;
15670
15671 orig_name = (*targetm.strip_name_encoding) (name);
15672 desc_name = orig_name;
15673 while (*desc_name == '.')
15674 desc_name++;
15675
15676 if (TREE_PUBLIC (decl))
15677 fprintf (file, "\t.globl %s\n", desc_name);
15678
15679 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
15680 fprintf (file, "%s:\n", desc_name);
15681 fprintf (file, "\t.long %s\n", orig_name);
15682 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
15683 if (DEFAULT_ABI == ABI_AIX)
15684 fputs ("\t.long 0\n", file);
15685 fprintf (file, "\t.previous\n");
15686 }
15687 ASM_OUTPUT_LABEL (file, name);
15688}
7c262518
RH
15689#endif
15690
cbaaba19 15691#if TARGET_XCOFF
7c262518 15692static void
a2369ed3 15693rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
15694{
15695 fputs (GLOBAL_ASM_OP, stream);
15696 RS6000_OUTPUT_BASENAME (stream, name);
15697 putc ('\n', stream);
15698}
15699
15700static void
a2369ed3 15701rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 15702{
0e5dbd9b
DE
15703 int smclass;
15704 static const char * const suffix[3] = { "PR", "RO", "RW" };
15705
15706 if (flags & SECTION_CODE)
15707 smclass = 0;
15708 else if (flags & SECTION_WRITE)
15709 smclass = 2;
15710 else
15711 smclass = 1;
15712
5b5198f7 15713 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 15714 (flags & SECTION_CODE) ? "." : "",
5b5198f7 15715 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 15716}
ae46c4e0
RH
15717
15718static void
a2369ed3
DJ
15719rs6000_xcoff_select_section (tree decl, int reloc,
15720 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 15721{
5add3202 15722 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 15723 {
0e5dbd9b 15724 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15725 read_only_data_section ();
15726 else
15727 read_only_private_data_section ();
15728 }
15729 else
15730 {
0e5dbd9b 15731 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15732 data_section ();
15733 else
15734 private_data_section ();
15735 }
15736}
15737
15738static void
a2369ed3 15739rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
15740{
15741 const char *name;
ae46c4e0 15742
5b5198f7
DE
15743 /* Use select_section for private and uninitialized data. */
15744 if (!TREE_PUBLIC (decl)
15745 || DECL_COMMON (decl)
0e5dbd9b
DE
15746 || DECL_INITIAL (decl) == NULL_TREE
15747 || DECL_INITIAL (decl) == error_mark_node
15748 || (flag_zero_initialized_in_bss
15749 && initializer_zerop (DECL_INITIAL (decl))))
15750 return;
15751
15752 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15753 name = (*targetm.strip_name_encoding) (name);
15754 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 15755}
b64a1b53 15756
fb49053f
RH
15757/* Select section for constant in constant pool.
15758
15759 On RS/6000, all constants are in the private read-only data area.
15760 However, if this is being placed in the TOC it must be output as a
15761 toc entry. */
15762
b64a1b53 15763static void
a2369ed3
DJ
15764rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
15765 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
15766{
15767 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
15768 toc_section ();
15769 else
15770 read_only_private_data_section ();
15771}
772c5265
RH
15772
15773/* Remove any trailing [DS] or the like from the symbol name. */
15774
15775static const char *
a2369ed3 15776rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
15777{
15778 size_t len;
15779 if (*name == '*')
15780 name++;
15781 len = strlen (name);
15782 if (name[len - 1] == ']')
15783 return ggc_alloc_string (name, len - 4);
15784 else
15785 return name;
15786}
15787
5add3202
DE
15788/* Section attributes. AIX is always PIC. */
15789
15790static unsigned int
a2369ed3 15791rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 15792{
5b5198f7
DE
15793 unsigned int align;
15794 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
15795
15796 /* Align to at least UNIT size. */
15797 if (flags & SECTION_CODE)
15798 align = MIN_UNITS_PER_WORD;
15799 else
15800 /* Increase alignment of large objects if not already stricter. */
15801 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
15802 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
15803 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
15804
15805 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 15806}
a5fe455b 15807
1bc7c5b6
ZW
15808/* Output at beginning of assembler file.
15809
15810 Initialize the section names for the RS/6000 at this point.
15811
15812 Specify filename, including full path, to assembler.
15813
15814 We want to go into the TOC section so at least one .toc will be emitted.
15815 Also, in order to output proper .bs/.es pairs, we need at least one static
15816 [RW] section emitted.
15817
15818 Finally, declare mcount when profiling to make the assembler happy. */
15819
15820static void
863d938c 15821rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
15822{
15823 rs6000_gen_section_name (&xcoff_bss_section_name,
15824 main_input_filename, ".bss_");
15825 rs6000_gen_section_name (&xcoff_private_data_section_name,
15826 main_input_filename, ".rw_");
15827 rs6000_gen_section_name (&xcoff_read_only_section_name,
15828 main_input_filename, ".ro_");
15829
15830 fputs ("\t.file\t", asm_out_file);
15831 output_quoted_string (asm_out_file, main_input_filename);
15832 fputc ('\n', asm_out_file);
15833 toc_section ();
15834 if (write_symbols != NO_DEBUG)
15835 private_data_section ();
15836 text_section ();
15837 if (profile_flag)
15838 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
15839 rs6000_file_start ();
15840}
15841
a5fe455b
ZW
15842/* Output at end of assembler file.
15843 On the RS/6000, referencing data should automatically pull in text. */
15844
15845static void
863d938c 15846rs6000_xcoff_file_end (void)
a5fe455b
ZW
15847{
15848 text_section ();
15849 fputs ("_section_.text:\n", asm_out_file);
15850 data_section ();
15851 fputs (TARGET_32BIT
15852 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
15853 asm_out_file);
15854}
f1384257 15855#endif /* TARGET_XCOFF */
0e5dbd9b 15856
f1384257
AM
15857#if TARGET_MACHO
15858/* Cross-module name binding. Darwin does not support overriding
7f3d8013 15859 functions at dynamic-link time. */
0e5dbd9b 15860
2bcc50d0 15861static bool
a2369ed3 15862rs6000_binds_local_p (tree decl)
0e5dbd9b 15863{
f1384257 15864 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 15865}
f1384257 15866#endif
34bb030a 15867
3c50106f
RH
15868/* Compute a (partial) cost for rtx X. Return true if the complete
15869 cost has been computed, and false if subexpressions should be
15870 scanned. In either case, *TOTAL contains the cost result. */
15871
15872static bool
a2369ed3
DJ
15873rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
15874 int *total)
3c50106f
RH
15875{
15876 switch (code)
15877 {
15878 /* On the RS/6000, if it is valid in the insn, it is free.
15879 So this always returns 0. */
15880 case CONST_INT:
15881 case CONST:
15882 case LABEL_REF:
15883 case SYMBOL_REF:
15884 case CONST_DOUBLE:
15885 case HIGH:
15886 *total = 0;
15887 return true;
15888
15889 case PLUS:
15890 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15891 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
15892 + 0x8000) >= 0x10000)
15893 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15894 ? COSTS_N_INSNS (2)
15895 : COSTS_N_INSNS (1));
15896 return true;
15897
15898 case AND:
15899 case IOR:
15900 case XOR:
15901 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15902 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
15903 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15904 ? COSTS_N_INSNS (2)
15905 : COSTS_N_INSNS (1));
15906 return true;
15907
15908 case MULT:
15909 if (optimize_size)
15910 {
15911 *total = COSTS_N_INSNS (2);
15912 return true;
15913 }
15914 switch (rs6000_cpu)
15915 {
15916 case PROCESSOR_RIOS1:
15917 case PROCESSOR_PPC405:
15918 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15919 ? COSTS_N_INSNS (5)
15920 : (INTVAL (XEXP (x, 1)) >= -256
15921 && INTVAL (XEXP (x, 1)) <= 255)
15922 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15923 return true;
15924
02ca7595
DE
15925 case PROCESSOR_PPC440:
15926 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15927 ? COSTS_N_INSNS (3)
15928 : COSTS_N_INSNS (2));
15929 return true;
15930
3c50106f
RH
15931 case PROCESSOR_RS64A:
15932 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15933 ? GET_MODE (XEXP (x, 1)) != DImode
15934 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
15935 : (INTVAL (XEXP (x, 1)) >= -256
15936 && INTVAL (XEXP (x, 1)) <= 255)
15937 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
15938 return true;
15939
15940 case PROCESSOR_RIOS2:
15941 case PROCESSOR_MPCCORE:
15942 case PROCESSOR_PPC604e:
15943 *total = COSTS_N_INSNS (2);
15944 return true;
15945
15946 case PROCESSOR_PPC601:
15947 *total = COSTS_N_INSNS (5);
15948 return true;
15949
15950 case PROCESSOR_PPC603:
15951 case PROCESSOR_PPC7400:
15952 case PROCESSOR_PPC750:
15953 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15954 ? COSTS_N_INSNS (5)
15955 : (INTVAL (XEXP (x, 1)) >= -256
15956 && INTVAL (XEXP (x, 1)) <= 255)
15957 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
15958 return true;
15959
15960 case PROCESSOR_PPC7450:
15961 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15962 ? COSTS_N_INSNS (4)
15963 : COSTS_N_INSNS (3));
15964 return true;
15965
15966 case PROCESSOR_PPC403:
15967 case PROCESSOR_PPC604:
15968 case PROCESSOR_PPC8540:
15969 *total = COSTS_N_INSNS (4);
15970 return true;
15971
15972 case PROCESSOR_PPC620:
15973 case PROCESSOR_PPC630:
3c50106f
RH
15974 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15975 ? GET_MODE (XEXP (x, 1)) != DImode
15976 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
15977 : (INTVAL (XEXP (x, 1)) >= -256
15978 && INTVAL (XEXP (x, 1)) <= 255)
15979 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15980 return true;
15981
9259f3b0 15982 case PROCESSOR_POWER4:
ec507f2d 15983 case PROCESSOR_POWER5:
9259f3b0
DE
15984 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15985 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
15986 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
15987 : COSTS_N_INSNS (2));
9259f3b0
DE
15988 return true;
15989
3c50106f
RH
15990 default:
15991 abort ();
15992 }
15993
15994 case DIV:
15995 case MOD:
15996 if (GET_CODE (XEXP (x, 1)) == CONST_INT
15997 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
15998 {
15999 *total = COSTS_N_INSNS (2);
16000 return true;
16001 }
5efb1046 16002 /* FALLTHRU */
3c50106f
RH
16003
16004 case UDIV:
16005 case UMOD:
16006 switch (rs6000_cpu)
16007 {
16008 case PROCESSOR_RIOS1:
16009 *total = COSTS_N_INSNS (19);
16010 return true;
16011
16012 case PROCESSOR_RIOS2:
16013 *total = COSTS_N_INSNS (13);
16014 return true;
16015
16016 case PROCESSOR_RS64A:
16017 *total = (GET_MODE (XEXP (x, 1)) != DImode
16018 ? COSTS_N_INSNS (65)
16019 : COSTS_N_INSNS (67));
16020 return true;
16021
16022 case PROCESSOR_MPCCORE:
16023 *total = COSTS_N_INSNS (6);
16024 return true;
16025
16026 case PROCESSOR_PPC403:
16027 *total = COSTS_N_INSNS (33);
16028 return true;
16029
16030 case PROCESSOR_PPC405:
16031 *total = COSTS_N_INSNS (35);
16032 return true;
16033
02ca7595
DE
16034 case PROCESSOR_PPC440:
16035 *total = COSTS_N_INSNS (34);
16036 return true;
16037
3c50106f
RH
16038 case PROCESSOR_PPC601:
16039 *total = COSTS_N_INSNS (36);
16040 return true;
16041
16042 case PROCESSOR_PPC603:
16043 *total = COSTS_N_INSNS (37);
16044 return true;
16045
16046 case PROCESSOR_PPC604:
16047 case PROCESSOR_PPC604e:
16048 *total = COSTS_N_INSNS (20);
16049 return true;
16050
16051 case PROCESSOR_PPC620:
16052 case PROCESSOR_PPC630:
3c50106f
RH
16053 *total = (GET_MODE (XEXP (x, 1)) != DImode
16054 ? COSTS_N_INSNS (21)
16055 : COSTS_N_INSNS (37));
16056 return true;
16057
16058 case PROCESSOR_PPC750:
16059 case PROCESSOR_PPC8540:
16060 case PROCESSOR_PPC7400:
16061 *total = COSTS_N_INSNS (19);
16062 return true;
16063
16064 case PROCESSOR_PPC7450:
16065 *total = COSTS_N_INSNS (23);
16066 return true;
984e25ac
DE
16067
16068 case PROCESSOR_POWER4:
ec507f2d 16069 case PROCESSOR_POWER5:
984e25ac
DE
16070 *total = (GET_MODE (XEXP (x, 1)) != DImode
16071 ? COSTS_N_INSNS (18)
16072 : COSTS_N_INSNS (34));
16073 return true;
3c50106f
RH
16074
16075 default:
16076 abort ();
16077 }
16078
16079 case FFS:
16080 *total = COSTS_N_INSNS (4);
16081 return true;
16082
16083 case MEM:
a3c9585f 16084 /* MEM should be slightly more expensive than (plus (reg) (const)). */
3c50106f
RH
16085 *total = 5;
16086 return true;
16087
16088 default:
16089 return false;
16090 }
16091}
16092
34bb030a
DE
16093/* A C expression returning the cost of moving data from a register of class
16094 CLASS1 to one of CLASS2. */
16095
16096int
a2369ed3
DJ
16097rs6000_register_move_cost (enum machine_mode mode,
16098 enum reg_class from, enum reg_class to)
34bb030a
DE
16099{
16100 /* Moves from/to GENERAL_REGS. */
16101 if (reg_classes_intersect_p (to, GENERAL_REGS)
16102 || reg_classes_intersect_p (from, GENERAL_REGS))
16103 {
16104 if (! reg_classes_intersect_p (to, GENERAL_REGS))
16105 from = to;
16106
16107 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
16108 return (rs6000_memory_move_cost (mode, from, 0)
16109 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
16110
a3c9585f 16111/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
16112 else if (from == CR_REGS)
16113 return 4;
16114
16115 else
16116/* A move will cost one instruction per GPR moved. */
16117 return 2 * HARD_REGNO_NREGS (0, mode);
16118 }
16119
16120/* Moving between two similar registers is just one instruction. */
16121 else if (reg_classes_intersect_p (to, from))
16122 return mode == TFmode ? 4 : 2;
16123
16124/* Everything else has to go through GENERAL_REGS. */
16125 else
16126 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
16127 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
16128}
16129
16130/* A C expressions returning the cost of moving data of MODE from a register to
16131 or from memory. */
16132
16133int
a2369ed3
DJ
16134rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
16135 int in ATTRIBUTE_UNUSED)
34bb030a
DE
16136{
16137 if (reg_classes_intersect_p (class, GENERAL_REGS))
16138 return 4 * HARD_REGNO_NREGS (0, mode);
16139 else if (reg_classes_intersect_p (class, FLOAT_REGS))
16140 return 4 * HARD_REGNO_NREGS (32, mode);
16141 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
16142 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
16143 else
16144 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
16145}
16146
ded9bf77
AH
16147/* Return an RTX representing where to find the function value of a
16148 function returning MODE. */
16149static rtx
16150rs6000_complex_function_value (enum machine_mode mode)
16151{
16152 unsigned int regno;
16153 rtx r1, r2;
16154 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 16155 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77
AH
16156
16157 if (FLOAT_MODE_P (mode))
16158 regno = FP_ARG_RETURN;
16159 else
16160 {
16161 regno = GP_ARG_RETURN;
16162
16163 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 16164 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
16165 return gen_rtx_REG (mode, regno);
16166 }
16167
fb7e4164
AM
16168 if (inner_bytes >= 8)
16169 return gen_rtx_REG (mode, regno);
16170
ded9bf77
AH
16171 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
16172 const0_rtx);
16173 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 16174 GEN_INT (inner_bytes));
ded9bf77
AH
16175 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
16176}
16177
a6ebc39a
AH
16178/* Define how to find the value returned by a function.
16179 VALTYPE is the data type of the value (as a tree).
16180 If the precise function being called is known, FUNC is its FUNCTION_DECL;
16181 otherwise, FUNC is 0.
16182
16183 On the SPE, both FPs and vectors are returned in r3.
16184
16185 On RS/6000 an integer value is in r3 and a floating-point value is in
16186 fp1, unless -msoft-float. */
16187
16188rtx
16189rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
16190{
16191 enum machine_mode mode;
2a8fa26c 16192 unsigned int regno;
a6ebc39a 16193
0e67400a
FJ
16194 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
16195 {
16196 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
16197 return gen_rtx_PARALLEL (DImode,
16198 gen_rtvec (2,
16199 gen_rtx_EXPR_LIST (VOIDmode,
16200 gen_rtx_REG (SImode, GP_ARG_RETURN),
16201 const0_rtx),
16202 gen_rtx_EXPR_LIST (VOIDmode,
16203 gen_rtx_REG (SImode,
16204 GP_ARG_RETURN + 1),
16205 GEN_INT (4))));
16206 }
16207
a6ebc39a
AH
16208 if ((INTEGRAL_TYPE_P (valtype)
16209 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
16210 || POINTER_TYPE_P (valtype))
b78d48dd 16211 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
16212 else
16213 mode = TYPE_MODE (valtype);
16214
2a8fa26c
DE
16215 if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS)
16216 regno = FP_ARG_RETURN;
ded9bf77
AH
16217 else if (TREE_CODE (valtype) == COMPLEX_TYPE
16218 && TARGET_HARD_FLOAT
42ba5130 16219 && targetm.calls.split_complex_arg)
ded9bf77 16220 return rs6000_complex_function_value (mode);
2a8fa26c 16221 else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC)
a6ebc39a
AH
16222 regno = ALTIVEC_ARG_RETURN;
16223 else
16224 regno = GP_ARG_RETURN;
16225
16226 return gen_rtx_REG (mode, regno);
16227}
16228
ded9bf77
AH
16229/* Define how to find the value returned by a library function
16230 assuming the value has mode MODE. */
16231rtx
16232rs6000_libcall_value (enum machine_mode mode)
16233{
16234 unsigned int regno;
16235
16236 if (GET_MODE_CLASS (mode) == MODE_FLOAT
16237 && TARGET_HARD_FLOAT && TARGET_FPRS)
16238 regno = FP_ARG_RETURN;
16239 else if (ALTIVEC_VECTOR_MODE (mode))
16240 regno = ALTIVEC_ARG_RETURN;
42ba5130 16241 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
16242 return rs6000_complex_function_value (mode);
16243 else
16244 regno = GP_ARG_RETURN;
16245
16246 return gen_rtx_REG (mode, regno);
16247}
16248
d1d0c603
JJ
16249/* Define the offset between two registers, FROM to be eliminated and its
16250 replacement TO, at the start of a routine. */
16251HOST_WIDE_INT
16252rs6000_initial_elimination_offset (int from, int to)
16253{
16254 rs6000_stack_t *info = rs6000_stack_info ();
16255 HOST_WIDE_INT offset;
16256
16257 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16258 offset = info->push_p ? 0 : -info->total_size;
16259 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
16260 offset = info->total_size;
16261 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16262 offset = info->push_p ? info->total_size : 0;
16263 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
16264 offset = 0;
16265 else
16266 abort ();
16267
16268 return offset;
16269}
16270
62e1dfcf
NC
16271/* Return true if TYPE is of type __ev64_opaque__. */
16272
c8e4f0e9 16273static bool
a2369ed3 16274is_ev64_opaque_type (tree type)
62e1dfcf 16275{
c8e4f0e9 16276 return (TARGET_SPE
2abe3e28
AH
16277 && (type == opaque_V2SI_type_node
16278 || type == opaque_V2SF_type_node
36252949 16279 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
16280}
16281
96714395 16282static rtx
a2369ed3 16283rs6000_dwarf_register_span (rtx reg)
96714395
AH
16284{
16285 unsigned regno;
16286
16287 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
16288 return NULL_RTX;
16289
16290 regno = REGNO (reg);
16291
16292 /* The duality of the SPE register size wreaks all kinds of havoc.
16293 This is a way of distinguishing r0 in 32-bits from r0 in
16294 64-bits. */
16295 return
16296 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
16297 BYTES_BIG_ENDIAN
16298 ? gen_rtvec (2,
16299 gen_rtx_REG (SImode, regno + 1200),
16300 gen_rtx_REG (SImode, regno))
16301 : gen_rtvec (2,
16302 gen_rtx_REG (SImode, regno),
16303 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
16304}
16305
93c9d1ba
AM
16306/* Map internal gcc register numbers to DWARF2 register numbers. */
16307
16308unsigned int
16309rs6000_dbx_register_number (unsigned int regno)
16310{
16311 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
16312 return regno;
16313 if (regno == MQ_REGNO)
16314 return 100;
16315 if (regno == LINK_REGISTER_REGNUM)
16316 return 108;
16317 if (regno == COUNT_REGISTER_REGNUM)
16318 return 109;
16319 if (CR_REGNO_P (regno))
16320 return regno - CR0_REGNO + 86;
16321 if (regno == XER_REGNO)
16322 return 101;
16323 if (ALTIVEC_REGNO_P (regno))
16324 return regno - FIRST_ALTIVEC_REGNO + 1124;
16325 if (regno == VRSAVE_REGNO)
16326 return 356;
16327 if (regno == VSCR_REGNO)
16328 return 67;
16329 if (regno == SPE_ACC_REGNO)
16330 return 99;
16331 if (regno == SPEFSCR_REGNO)
16332 return 612;
16333 /* SPE high reg number. We get these values of regno from
16334 rs6000_dwarf_register_span. */
16335 if (regno >= 1200 && regno < 1232)
16336 return regno;
16337
16338 abort ();
16339}
16340
17211ab5 16341#include "gt-rs6000.h"