]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
io.c (format_asterisk): Silence compiler warnings by correcting the number of element...
[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
0d1fbc8c
AH
218/* Value is TRUE if register/mode pair is accepatable. */
219bool rs6000_hard_regno_mode_ok_p[NUM_MACHINE_MODES][FIRST_PSEUDO_REGISTER];
220
6035d635 221/* Opaque types. */
2abe3e28 222static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 223static GTY(()) tree opaque_V2SF_type_node;
6035d635 224static GTY(()) tree opaque_p_V2SI_type_node;
4a5eab38
PB
225static GTY(()) tree V16QI_type_node;
226static GTY(()) tree V2SI_type_node;
227static GTY(()) tree V2SF_type_node;
228static GTY(()) tree V4HI_type_node;
229static GTY(()) tree V4SI_type_node;
230static GTY(()) tree V4SF_type_node;
231static GTY(()) tree V8HI_type_node;
232static GTY(()) tree unsigned_V16QI_type_node;
233static GTY(()) tree unsigned_V8HI_type_node;
234static GTY(()) tree unsigned_V4SI_type_node;
8bb418a3
ZL
235static GTY(()) tree bool_char_type_node; /* __bool char */
236static GTY(()) tree bool_short_type_node; /* __bool short */
237static GTY(()) tree bool_int_type_node; /* __bool int */
238static GTY(()) tree pixel_type_node; /* __pixel */
239static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */
240static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */
241static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */
242static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */
243
244int rs6000_warn_altivec_long = 1; /* On by default. */
245const char *rs6000_warn_altivec_long_switch;
246
57ac7be9
AM
247const char *rs6000_traceback_name;
248static enum {
249 traceback_default = 0,
250 traceback_none,
251 traceback_part,
252 traceback_full
253} rs6000_traceback;
254
38c1f2d7
MM
255/* Flag to say the TOC is initialized */
256int toc_initialized;
9ebbca7d 257char toc_label_name[10];
38c1f2d7 258
9ebbca7d 259/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 260static GTY(()) int rs6000_sr_alias_set;
c8023011 261
a5c76ee6
ZW
262/* Call distance, overridden by -mlongcall and #pragma longcall(1).
263 The only place that looks at this is rs6000_set_default_type_attributes;
264 everywhere else should rely on the presence or absence of a longcall
265 attribute on the function declaration. */
266int rs6000_default_long_calls;
267const char *rs6000_longcall_switch;
268
a3c9585f
KH
269/* Control alignment for fields within structures. */
270/* String from -malign-XXXXX. */
025d9908
KH
271const char *rs6000_alignment_string;
272int rs6000_alignment_flags;
273
a3170dc6
AH
274struct builtin_description
275{
276 /* mask is not const because we're going to alter it below. This
277 nonsense will go away when we rewrite the -march infrastructure
278 to give us more target flag bits. */
279 unsigned int mask;
280 const enum insn_code icode;
281 const char *const name;
282 const enum rs6000_builtins code;
283};
284
a2369ed3
DJ
285static bool rs6000_function_ok_for_sibcall (tree, tree);
286static int num_insns_constant_wide (HOST_WIDE_INT);
287static void validate_condition_mode (enum rtx_code, enum machine_mode);
288static rtx rs6000_generate_compare (enum rtx_code);
289static void rs6000_maybe_dead (rtx);
290static void rs6000_emit_stack_tie (void);
291static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
292static rtx spe_synthesize_frame_save (rtx);
293static bool spe_func_has_64bit_regs_p (void);
b20a9cca 294static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 295 int, HOST_WIDE_INT);
a2369ed3
DJ
296static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
297static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
298static unsigned rs6000_hash_constant (rtx);
299static unsigned toc_hash_function (const void *);
300static int toc_hash_eq (const void *, const void *);
301static int constant_pool_expr_1 (rtx, int *, int *);
302static bool constant_pool_expr_p (rtx);
303static bool toc_relative_expr_p (rtx);
304static bool legitimate_small_data_p (enum machine_mode, rtx);
305static bool legitimate_offset_address_p (enum machine_mode, rtx, int);
306static bool legitimate_indexed_address_p (rtx, int);
307static bool legitimate_indirect_address_p (rtx, int);
4c81e946 308static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
309static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
310static struct machine_function * rs6000_init_machine_status (void);
311static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 312#ifdef HAVE_GAS_HIDDEN
a2369ed3 313static void rs6000_assemble_visibility (tree, int);
5add3202 314#endif
a2369ed3
DJ
315static int rs6000_ra_ever_killed (void);
316static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
8bb418a3 317static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
f18eca82 318static const char *rs6000_mangle_fundamental_type (tree);
b86fe7b4 319extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
320static void rs6000_set_default_type_attributes (tree);
321static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
322static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
323static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
324 tree);
a2369ed3 325static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 326static bool rs6000_return_in_memory (tree, tree);
a2369ed3 327static void rs6000_file_start (void);
7c262518 328#if TARGET_ELF
a2369ed3
DJ
329static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
330static void rs6000_elf_asm_out_constructor (rtx, int);
331static void rs6000_elf_asm_out_destructor (rtx, int);
332static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
333static void rs6000_elf_unique_section (tree, int);
334static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 335 unsigned HOST_WIDE_INT);
a56d7372 336static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 337 ATTRIBUTE_UNUSED;
a2369ed3 338static bool rs6000_elf_in_small_data_p (tree);
7c262518 339#endif
cbaaba19 340#if TARGET_XCOFF
a2369ed3
DJ
341static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
342static void rs6000_xcoff_asm_named_section (const char *, unsigned int);
343static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
344static void rs6000_xcoff_unique_section (tree, int);
345static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 346 unsigned HOST_WIDE_INT);
a2369ed3
DJ
347static const char * rs6000_xcoff_strip_name_encoding (const char *);
348static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
349static void rs6000_xcoff_file_start (void);
350static void rs6000_xcoff_file_end (void);
f1384257
AM
351#endif
352#if TARGET_MACHO
a2369ed3 353static bool rs6000_binds_local_p (tree);
f1384257 354#endif
a2369ed3
DJ
355static int rs6000_use_dfa_pipeline_interface (void);
356static int rs6000_variable_issue (FILE *, int, rtx, int);
357static bool rs6000_rtx_costs (rtx, int, int, int *);
358static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 359static bool is_microcoded_insn (rtx);
79ae11c4 360static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
361static bool is_cracked_insn (rtx);
362static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
363static int rs6000_adjust_priority (rtx, int);
364static int rs6000_issue_rate (void);
569fa502 365static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
366static rtx get_next_active_insn (rtx, rtx);
367static bool insn_terminates_group_p (rtx , enum group_termination);
368static bool is_costly_group (rtx *, rtx);
369static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
370static int redefine_groups (FILE *, int, rtx, rtx);
371static int pad_groups (FILE *, int, rtx, rtx);
372static void rs6000_sched_finish (FILE *, int);
a2369ed3
DJ
373static int rs6000_use_sched_lookahead (void);
374
375static void rs6000_init_builtins (void);
376static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
377static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
378static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
379static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
380static void altivec_init_builtins (void);
381static void rs6000_common_init_builtins (void);
c15c90bb 382static void rs6000_init_libfuncs (void);
a2369ed3 383
b20a9cca
AM
384static void enable_mask_for_builtins (struct builtin_description *, int,
385 enum rs6000_builtins,
386 enum rs6000_builtins);
7c62e993 387static tree build_opaque_vector_type (tree, int);
a2369ed3
DJ
388static void spe_init_builtins (void);
389static rtx spe_expand_builtin (tree, rtx, bool *);
390static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
391static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
392static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
393static rs6000_stack_t *rs6000_stack_info (void);
394static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
395
396static rtx altivec_expand_builtin (tree, rtx, bool *);
397static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
398static rtx altivec_expand_st_builtin (tree, rtx, bool *);
399static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
400static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
401static rtx altivec_expand_predicate_builtin (enum insn_code,
402 const char *, tree, rtx);
b4a62fa0 403static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
404static rtx altivec_expand_stv_builtin (enum insn_code, tree);
405static void rs6000_parse_abi_options (void);
406static void rs6000_parse_alignment_option (void);
407static void rs6000_parse_tls_size_option (void);
5da702b1 408static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
409static int first_altivec_reg_to_save (void);
410static unsigned int compute_vrsave_mask (void);
411static void is_altivec_return_reg (rtx, void *);
412static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
413int easy_vector_constant (rtx, enum machine_mode);
414static int easy_vector_same (rtx, enum machine_mode);
452a7d36 415static int easy_vector_splat_const (int, enum machine_mode);
a2369ed3
DJ
416static bool is_ev64_opaque_type (tree);
417static rtx rs6000_dwarf_register_span (rtx);
418static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
419static rtx rs6000_tls_get_addr (void);
420static rtx rs6000_got_sym (void);
421static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
422static const char *rs6000_get_some_local_dynamic_name (void);
423static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 424static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 425static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 426 enum machine_mode, tree);
b78d48dd
FJ
427static rtx rs6000_mixed_function_arg (CUMULATIVE_ARGS *,
428 enum machine_mode, tree, int);
b1917422 429static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
c6e8c921
GK
430static void setup_incoming_varargs (CUMULATIVE_ARGS *,
431 enum machine_mode, tree,
432 int *, int);
efdba735
SH
433#if TARGET_MACHO
434static void macho_branch_islands (void);
435static void add_compiler_branch_island (tree, tree, int);
436static int no_previous_def (tree function_name);
437static tree get_prev_label (tree function_name);
438#endif
439
c35d187f 440static tree rs6000_build_builtin_va_list (void);
17211ab5
GK
441
442/* Hash table stuff for keeping track of TOC entries. */
443
444struct toc_hash_struct GTY(())
445{
446 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
447 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
448 rtx key;
449 enum machine_mode key_mode;
450 int labelno;
451};
452
453static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
454\f
455/* Default register names. */
456char rs6000_reg_names[][8] =
457{
802a0058
MM
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 "0", "1", "2", "3", "4", "5", "6", "7",
463 "8", "9", "10", "11", "12", "13", "14", "15",
464 "16", "17", "18", "19", "20", "21", "22", "23",
465 "24", "25", "26", "27", "28", "29", "30", "31",
466 "mq", "lr", "ctr","ap",
467 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
468 "xer",
469 /* AltiVec registers. */
0cd5e3a1
AH
470 "0", "1", "2", "3", "4", "5", "6", "7",
471 "8", "9", "10", "11", "12", "13", "14", "15",
472 "16", "17", "18", "19", "20", "21", "22", "23",
473 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
474 "vrsave", "vscr",
475 /* SPE registers. */
476 "spe_acc", "spefscr"
c81bebd7
MM
477};
478
479#ifdef TARGET_REGNAMES
8b60264b 480static const char alt_reg_names[][8] =
c81bebd7 481{
802a0058
MM
482 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
483 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
484 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
485 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
486 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
487 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
488 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
489 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
490 "mq", "lr", "ctr", "ap",
491 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 492 "xer",
59a4c851 493 /* AltiVec registers. */
0ac081f6 494 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
495 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
496 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
497 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
498 "vrsave", "vscr",
499 /* SPE registers. */
500 "spe_acc", "spefscr"
c81bebd7
MM
501};
502#endif
9878760c 503\f
daf11973
MM
504#ifndef MASK_STRICT_ALIGN
505#define MASK_STRICT_ALIGN 0
506#endif
ffcfcb5f
AM
507#ifndef TARGET_PROFILE_KERNEL
508#define TARGET_PROFILE_KERNEL 0
509#endif
3961e8fe
RH
510
511/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
512#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
513
514/* Return 1 for a symbol ref for a thread-local storage symbol. */
515#define RS6000_SYMBOL_REF_TLS_P(RTX) \
516 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
517\f
518/* Initialize the GCC target structure. */
91d231cb
JM
519#undef TARGET_ATTRIBUTE_TABLE
520#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
521#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
522#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 523
301d03af
RS
524#undef TARGET_ASM_ALIGNED_DI_OP
525#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
526
527/* Default unaligned ops are only provided for ELF. Find the ops needed
528 for non-ELF systems. */
529#ifndef OBJECT_FORMAT_ELF
cbaaba19 530#if TARGET_XCOFF
ae6c1efd 531/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
532 64-bit targets. */
533#undef TARGET_ASM_UNALIGNED_HI_OP
534#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
535#undef TARGET_ASM_UNALIGNED_SI_OP
536#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
537#undef TARGET_ASM_UNALIGNED_DI_OP
538#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
539#else
540/* For Darwin. */
541#undef TARGET_ASM_UNALIGNED_HI_OP
542#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
543#undef TARGET_ASM_UNALIGNED_SI_OP
544#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
545#endif
546#endif
547
548/* This hook deals with fixups for relocatable code and DI-mode objects
549 in 64-bit code. */
550#undef TARGET_ASM_INTEGER
551#define TARGET_ASM_INTEGER rs6000_assemble_integer
552
93638d7a
AM
553#ifdef HAVE_GAS_HIDDEN
554#undef TARGET_ASM_ASSEMBLE_VISIBILITY
555#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
556#endif
557
c4501e62
JJ
558#undef TARGET_HAVE_TLS
559#define TARGET_HAVE_TLS HAVE_AS_TLS
560
561#undef TARGET_CANNOT_FORCE_CONST_MEM
562#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
563
08c148a8
NB
564#undef TARGET_ASM_FUNCTION_PROLOGUE
565#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
566#undef TARGET_ASM_FUNCTION_EPILOGUE
567#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
568
b54cf83a
DE
569#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
570#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
571#undef TARGET_SCHED_VARIABLE_ISSUE
572#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
573
c237e94a
ZW
574#undef TARGET_SCHED_ISSUE_RATE
575#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
576#undef TARGET_SCHED_ADJUST_COST
577#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
578#undef TARGET_SCHED_ADJUST_PRIORITY
579#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
569fa502
DN
580#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
581#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
582#undef TARGET_SCHED_FINISH
583#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 584
be12c2b0
VM
585#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
586#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
587
0ac081f6
AH
588#undef TARGET_INIT_BUILTINS
589#define TARGET_INIT_BUILTINS rs6000_init_builtins
590
591#undef TARGET_EXPAND_BUILTIN
592#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
593
f18eca82
ZL
594#undef TARGET_MANGLE_FUNDAMENTAL_TYPE
595#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
596
c15c90bb
ZW
597#undef TARGET_INIT_LIBFUNCS
598#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
599
f1384257 600#if TARGET_MACHO
0e5dbd9b
DE
601#undef TARGET_BINDS_LOCAL_P
602#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 603#endif
0e5dbd9b 604
3961e8fe
RH
605#undef TARGET_ASM_OUTPUT_MI_THUNK
606#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
607
3961e8fe 608#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 609#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 610
4977bab6
ZW
611#undef TARGET_FUNCTION_OK_FOR_SIBCALL
612#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
613
3c50106f
RH
614#undef TARGET_RTX_COSTS
615#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
616#undef TARGET_ADDRESS_COST
617#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 618
c8e4f0e9
AH
619#undef TARGET_VECTOR_OPAQUE_P
620#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 621
96714395
AH
622#undef TARGET_DWARF_REGISTER_SPAN
623#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
624
c6e8c921
GK
625/* On rs6000, function arguments are promoted, as are function return
626 values. */
627#undef TARGET_PROMOTE_FUNCTION_ARGS
628#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
629#undef TARGET_PROMOTE_FUNCTION_RETURN
630#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
631
c6e8c921
GK
632#undef TARGET_RETURN_IN_MEMORY
633#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
634
635#undef TARGET_SETUP_INCOMING_VARARGS
636#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
637
638/* Always strict argument naming on rs6000. */
639#undef TARGET_STRICT_ARGUMENT_NAMING
640#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
641#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
642#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
643#undef TARGET_SPLIT_COMPLEX_ARG
644#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
c6e8c921 645
c35d187f
RH
646#undef TARGET_BUILD_BUILTIN_VA_LIST
647#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
648
f6897b10 649struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 650\f
0d1fbc8c
AH
651
652/* Value is 1 if hard register REGNO can hold a value of machine-mode
653 MODE. */
654static int
655rs6000_hard_regno_mode_ok (int regno, enum machine_mode mode)
656{
657 /* The GPRs can hold any mode, but values bigger than one register
658 cannot go past R31. */
659 if (INT_REGNO_P (regno))
660 return INT_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1);
661
662 /* The float registers can only hold floating modes and DImode. */
663 if (FP_REGNO_P (regno))
664 return
665 (GET_MODE_CLASS (mode) == MODE_FLOAT
666 && FP_REGNO_P (regno + HARD_REGNO_NREGS (regno, mode) - 1))
667 || (GET_MODE_CLASS (mode) == MODE_INT
668 && GET_MODE_SIZE (mode) == UNITS_PER_FP_WORD);
669
670 /* The CR register can only hold CC modes. */
671 if (CR_REGNO_P (regno))
672 return GET_MODE_CLASS (mode) == MODE_CC;
673
674 if (XER_REGNO_P (regno))
675 return mode == PSImode;
676
677 /* AltiVec only in AldyVec registers. */
678 if (ALTIVEC_REGNO_P (regno))
679 return ALTIVEC_VECTOR_MODE (mode);
680
681 /* ...but GPRs can hold SIMD data on the SPE in one register. */
682 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
683 return 1;
684
685 /* We cannot put TImode anywhere except general register and it must be
686 able to fit within the register set. */
687
688 return GET_MODE_SIZE (mode) <= UNITS_PER_WORD;
689}
690
691/* Initialize rs6000_hard_regno_mode_ok_p table. */
692static void
693rs6000_init_hard_regno_mode_ok (void)
694{
695 int r, m;
696
697 for (r = 0; r < FIRST_PSEUDO_REGISTER; ++r)
698 for (m = 0; m < NUM_MACHINE_MODES; ++m)
699 if (rs6000_hard_regno_mode_ok (r, m))
700 rs6000_hard_regno_mode_ok_p[m][r] = true;
701}
702
5248c961
RK
703/* Override command line options. Mostly we process the processor
704 type and sometimes adjust other TARGET_ options. */
705
706void
d779d0dc 707rs6000_override_options (const char *default_cpu)
5248c961 708{
c4d38ccb 709 size_t i, j;
8e3f41e7 710 struct rs6000_cpu_select *ptr;
66188a7e 711 int set_masks;
5248c961 712
66188a7e 713 /* Simplifications for entries below. */
85638c0d 714
66188a7e
GK
715 enum {
716 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
717 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
718 };
85638c0d 719
66188a7e
GK
720 /* This table occasionally claims that a processor does not support
721 a particular feature even though it does, but the feature is slower
722 than the alternative. Thus, it shouldn't be relied on as a
723 complete description of the processor's support.
724
725 Please keep this list in order, and don't forget to update the
726 documentation in invoke.texi when adding a new processor or
727 flag. */
5248c961
RK
728 static struct ptt
729 {
8b60264b
KG
730 const char *const name; /* Canonical processor name. */
731 const enum processor_type processor; /* Processor type enum value. */
732 const int target_enable; /* Target flags to enable. */
8b60264b 733 } const processor_target_table[]
66188a7e 734 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 735 {"403", PROCESSOR_PPC403,
66188a7e
GK
736 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
737 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
738 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
739 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
740 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
741 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 742 {"601", PROCESSOR_PPC601,
66188a7e
GK
743 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
744 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
745 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
746 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
747 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
748 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
749 {"620", PROCESSOR_PPC620,
750 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
751 {"630", PROCESSOR_PPC630,
752 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
753 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
754 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
755 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
756 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
757 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
758 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
759 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
760 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
761 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 762 {"970", PROCESSOR_POWER4,
66188a7e
GK
763 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
764 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
765 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
766 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
767 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 768 {"G5", PROCESSOR_POWER4,
66188a7e
GK
769 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
770 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
771 {"power2", PROCESSOR_POWER,
772 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
773 {"power3", PROCESSOR_PPC630,
774 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
775 {"power4", PROCESSOR_POWER4,
fc091c8e 776 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
ec507f2d 777 {"power5", PROCESSOR_POWER5,
fc091c8e 778 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_MFCRF | MASK_POWERPC64},
66188a7e
GK
779 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
780 {"powerpc64", PROCESSOR_POWERPC64,
781 POWERPC_BASE_MASK | MASK_POWERPC64},
782 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
783 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
784 {"rios2", PROCESSOR_RIOS2,
785 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
786 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
787 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 788 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 789 };
5248c961 790
ca7558fc 791 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 792
66188a7e
GK
793 /* Some OSs don't support saving the high part of 64-bit registers on
794 context switch. Other OSs don't support saving Altivec registers.
795 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
796 settings; if the user wants either, the user must explicitly specify
797 them and we won't interfere with the user's specification. */
798
799 enum {
800 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
801 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
802 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
803 | MASK_MFCRF)
804 };
0d1fbc8c
AH
805
806 rs6000_init_hard_regno_mode_ok ();
807
66188a7e
GK
808 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
809#ifdef OS_MISSING_POWERPC64
810 if (OS_MISSING_POWERPC64)
811 set_masks &= ~MASK_POWERPC64;
812#endif
813#ifdef OS_MISSING_ALTIVEC
814 if (OS_MISSING_ALTIVEC)
815 set_masks &= ~MASK_ALTIVEC;
816#endif
817
957211c3
AM
818 /* Don't override these by the processor default if given explicitly. */
819 set_masks &= ~(target_flags_explicit
820 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
821
a4f6c312 822 /* Identify the processor type. */
8e3f41e7 823 rs6000_select[0].string = default_cpu;
3cb999d8 824 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 825
b6a1cbae 826 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 827 {
8e3f41e7
MM
828 ptr = &rs6000_select[i];
829 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 830 {
8e3f41e7
MM
831 for (j = 0; j < ptt_size; j++)
832 if (! strcmp (ptr->string, processor_target_table[j].name))
833 {
834 if (ptr->set_tune_p)
835 rs6000_cpu = processor_target_table[j].processor;
836
837 if (ptr->set_arch_p)
838 {
66188a7e
GK
839 target_flags &= ~set_masks;
840 target_flags |= (processor_target_table[j].target_enable
841 & set_masks);
8e3f41e7
MM
842 }
843 break;
844 }
845
4406229e 846 if (j == ptt_size)
8e3f41e7 847 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
848 }
849 }
8a61d227 850
993f19a8 851 if (TARGET_E500)
a3170dc6
AH
852 rs6000_isel = 1;
853
dff9f1b6
DE
854 /* If we are optimizing big endian systems for space, use the load/store
855 multiple and string instructions. */
ef792183 856 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 857 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 858
a4f6c312
SS
859 /* Don't allow -mmultiple or -mstring on little endian systems
860 unless the cpu is a 750, because the hardware doesn't support the
861 instructions used in little endian mode, and causes an alignment
862 trap. The 750 does not cause an alignment trap (except when the
863 target is unaligned). */
bef84347 864
b21fb038 865 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
866 {
867 if (TARGET_MULTIPLE)
868 {
869 target_flags &= ~MASK_MULTIPLE;
b21fb038 870 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
871 warning ("-mmultiple is not supported on little endian systems");
872 }
873
874 if (TARGET_STRING)
875 {
876 target_flags &= ~MASK_STRING;
b21fb038 877 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 878 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
879 }
880 }
3933e0e1 881
38c1f2d7
MM
882 /* Set debug flags */
883 if (rs6000_debug_name)
884 {
bfc79d3b 885 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 886 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 887 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 888 rs6000_debug_stack = 1;
bfc79d3b 889 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
890 rs6000_debug_arg = 1;
891 else
c725bd79 892 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
893 }
894
57ac7be9
AM
895 if (rs6000_traceback_name)
896 {
897 if (! strncmp (rs6000_traceback_name, "full", 4))
898 rs6000_traceback = traceback_full;
899 else if (! strncmp (rs6000_traceback_name, "part", 4))
900 rs6000_traceback = traceback_part;
901 else if (! strncmp (rs6000_traceback_name, "no", 2))
902 rs6000_traceback = traceback_none;
903 else
904 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
905 rs6000_traceback_name);
906 }
907
6fa3f289
ZW
908 /* Set size of long double */
909 rs6000_long_double_type_size = 64;
910 if (rs6000_long_double_size_string)
911 {
912 char *tail;
913 int size = strtol (rs6000_long_double_size_string, &tail, 10);
914 if (*tail != '\0' || (size != 64 && size != 128))
915 error ("Unknown switch -mlong-double-%s",
916 rs6000_long_double_size_string);
917 else
918 rs6000_long_double_type_size = size;
919 }
920
6d0ef01e
HP
921 /* Set Altivec ABI as default for powerpc64 linux. */
922 if (TARGET_ELF && TARGET_64BIT)
923 {
924 rs6000_altivec_abi = 1;
925 rs6000_altivec_vrsave = 1;
926 }
927
0ac081f6
AH
928 /* Handle -mabi= options. */
929 rs6000_parse_abi_options ();
930
025d9908
KH
931 /* Handle -malign-XXXXX option. */
932 rs6000_parse_alignment_option ();
933
5da702b1
AH
934 /* Handle generic -mFOO=YES/NO options. */
935 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
936 &rs6000_altivec_vrsave);
937 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
938 &rs6000_isel);
939 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
940 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
941 &rs6000_float_gprs);
993f19a8 942
c4501e62
JJ
943 /* Handle -mtls-size option. */
944 rs6000_parse_tls_size_option ();
945
a7ae18e2
AH
946#ifdef SUBTARGET_OVERRIDE_OPTIONS
947 SUBTARGET_OVERRIDE_OPTIONS;
948#endif
949#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
950 SUBSUBTARGET_OVERRIDE_OPTIONS;
951#endif
952
5da702b1
AH
953 if (TARGET_E500)
954 {
e4463bf1
AH
955 if (TARGET_ALTIVEC)
956 error ("AltiVec and E500 instructions cannot coexist");
957
5da702b1
AH
958 /* The e500 does not have string instructions, and we set
959 MASK_STRING above when optimizing for size. */
960 if ((target_flags & MASK_STRING) != 0)
961 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
962
963 /* No SPE means 64-bit long doubles, even if an E500. */
964 if (rs6000_spe_string != 0
965 && !strcmp (rs6000_spe_string, "no"))
966 rs6000_long_double_type_size = 64;
5da702b1
AH
967 }
968 else if (rs6000_select[1].string != NULL)
969 {
970 /* For the powerpc-eabispe configuration, we set all these by
971 default, so let's unset them if we manually set another
972 CPU that is not the E500. */
973 if (rs6000_abi_string == 0)
974 rs6000_spe_abi = 0;
975 if (rs6000_spe_string == 0)
976 rs6000_spe = 0;
977 if (rs6000_float_gprs_string == 0)
978 rs6000_float_gprs = 0;
979 if (rs6000_isel_string == 0)
980 rs6000_isel = 0;
b6e59a3a
AH
981 if (rs6000_long_double_size_string == 0)
982 rs6000_long_double_type_size = 64;
5da702b1 983 }
b5044283 984
ec507f2d
DE
985 rs6000_always_hint = (rs6000_cpu != PROCESSOR_POWER4
986 && rs6000_cpu != PROCESSOR_POWER5);
987 rs6000_sched_groups = (rs6000_cpu == PROCESSOR_POWER4
988 || rs6000_cpu == PROCESSOR_POWER5);
989
a5c76ee6
ZW
990 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
991 using TARGET_OPTIONS to handle a toggle switch, but we're out of
992 bits in target_flags so TARGET_SWITCHES cannot be used.
993 Assumption here is that rs6000_longcall_switch points into the
994 text of the complete option, rather than being a copy, so we can
995 scan back for the presence or absence of the no- modifier. */
996 if (rs6000_longcall_switch)
997 {
998 const char *base = rs6000_longcall_switch;
999 while (base[-1] != 'm') base--;
1000
1001 if (*rs6000_longcall_switch != '\0')
1002 error ("invalid option `%s'", base);
1003 rs6000_default_long_calls = (base[0] != 'n');
1004 }
1005
8bb418a3
ZL
1006 /* Handle -m(no-)warn-altivec-long similarly. */
1007 if (rs6000_warn_altivec_long_switch)
1008 {
1009 const char *base = rs6000_warn_altivec_long_switch;
1010 while (base[-1] != 'm') base--;
1011
1012 if (*rs6000_warn_altivec_long_switch != '\0')
1013 error ("invalid option `%s'", base);
1014 rs6000_warn_altivec_long = (base[0] != 'n');
1015 }
1016
cbe26ab8 1017 /* Handle -mprioritize-restricted-insns option. */
ec507f2d
DE
1018 rs6000_sched_restricted_insns_priority
1019 = (rs6000_sched_groups ? 1 : 0);
79ae11c4
DN
1020 if (rs6000_sched_restricted_insns_priority_str)
1021 rs6000_sched_restricted_insns_priority =
1022 atoi (rs6000_sched_restricted_insns_priority_str);
1023
569fa502 1024 /* Handle -msched-costly-dep option. */
ec507f2d
DE
1025 rs6000_sched_costly_dep
1026 = (rs6000_sched_groups ? store_to_load_dep_costly : no_dep_costly);
569fa502
DN
1027 if (rs6000_sched_costly_dep_str)
1028 {
1029 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
1030 rs6000_sched_costly_dep = no_dep_costly;
1031 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
1032 rs6000_sched_costly_dep = all_deps_costly;
1033 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
1034 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
1035 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
1036 rs6000_sched_costly_dep = store_to_load_dep_costly;
cbe26ab8
DN
1037 else
1038 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
1039 }
1040
1041 /* Handle -minsert-sched-nops option. */
ec507f2d
DE
1042 rs6000_sched_insert_nops
1043 = (rs6000_sched_groups ? sched_finish_regroup_exact : sched_finish_none);
cbe26ab8
DN
1044 if (rs6000_sched_insert_nops_str)
1045 {
1046 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
1047 rs6000_sched_insert_nops = sched_finish_none;
1048 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
1049 rs6000_sched_insert_nops = sched_finish_pad_groups;
1050 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
1051 rs6000_sched_insert_nops = sched_finish_regroup_exact;
1052 else
1053 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
1054 }
1055
c81bebd7 1056#ifdef TARGET_REGNAMES
a4f6c312
SS
1057 /* If the user desires alternate register names, copy in the
1058 alternate names now. */
c81bebd7 1059 if (TARGET_REGNAMES)
4e135bdd 1060 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
1061#endif
1062
6fa3f289
ZW
1063 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
1064 If -maix-struct-return or -msvr4-struct-return was explicitly
1065 used, don't override with the ABI default. */
b21fb038 1066 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
1067 {
1068 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
1069 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
1070 else
1071 target_flags |= MASK_AIX_STRUCT_RET;
1072 }
1073
fcce224d
DE
1074 if (TARGET_LONG_DOUBLE_128
1075 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 1076 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 1077
9ebbca7d
GK
1078 /* Allocate an alias set for register saves & restores from stack. */
1079 rs6000_sr_alias_set = new_alias_set ();
1080
1081 if (TARGET_TOC)
1082 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 1083
301d03af
RS
1084 /* We can only guarantee the availability of DI pseudo-ops when
1085 assembling for 64-bit targets. */
ae6c1efd 1086 if (!TARGET_64BIT)
301d03af
RS
1087 {
1088 targetm.asm_out.aligned_op.di = NULL;
1089 targetm.asm_out.unaligned_op.di = NULL;
1090 }
1091
2792d578
DE
1092 /* Set maximum branch target alignment at two instructions, eight bytes. */
1093 align_jumps_max_skip = 8;
1094 align_loops_max_skip = 8;
1095
71f123ca
FS
1096 /* Arrange to save and restore machine status around nested functions. */
1097 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1098
1099 /* We should always be splitting complex arguments, but we can't break
1100 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1101 if (DEFAULT_ABI != ABI_AIX)
1102 targetm.calls.split_complex_arg = NULL;
5248c961 1103}
5accd822 1104
5da702b1
AH
1105/* Handle generic options of the form -mfoo=yes/no.
1106 NAME is the option name.
1107 VALUE is the option value.
1108 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1109 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1110static void
5da702b1 1111rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1112{
5da702b1 1113 if (value == 0)
993f19a8 1114 return;
5da702b1
AH
1115 else if (!strcmp (value, "yes"))
1116 *flag = 1;
1117 else if (!strcmp (value, "no"))
1118 *flag = 0;
08b57fb3 1119 else
5da702b1 1120 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1121}
1122
0ac081f6 1123/* Handle -mabi= options. */
00b960c7 1124static void
863d938c 1125rs6000_parse_abi_options (void)
0ac081f6
AH
1126{
1127 if (rs6000_abi_string == 0)
1128 return;
1129 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1130 {
1131 rs6000_altivec_abi = 1;
1132 rs6000_spe_abi = 0;
1133 }
76a773f3
AH
1134 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1135 rs6000_altivec_abi = 0;
a3170dc6 1136 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1137 {
1138 rs6000_spe_abi = 1;
5cc73f91 1139 rs6000_altivec_abi = 0;
01f4962d
NS
1140 if (!TARGET_SPE_ABI)
1141 error ("not configured for ABI: '%s'", rs6000_abi_string);
1142 }
1143
a3170dc6
AH
1144 else if (! strcmp (rs6000_abi_string, "no-spe"))
1145 rs6000_spe_abi = 0;
0ac081f6 1146 else
c725bd79 1147 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1148}
1149
025d9908
KH
1150/* Handle -malign-XXXXXX options. */
1151static void
863d938c 1152rs6000_parse_alignment_option (void)
025d9908 1153{
b20a9cca
AM
1154 if (rs6000_alignment_string == 0)
1155 return;
1156 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1157 rs6000_alignment_flags = MASK_ALIGN_POWER;
1158 else if (! strcmp (rs6000_alignment_string, "natural"))
1159 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1160 else
1161 error ("unknown -malign-XXXXX option specified: '%s'",
1162 rs6000_alignment_string);
1163}
1164
c4501e62
JJ
1165/* Validate and record the size specified with the -mtls-size option. */
1166
1167static void
863d938c 1168rs6000_parse_tls_size_option (void)
c4501e62
JJ
1169{
1170 if (rs6000_tls_size_string == 0)
1171 return;
1172 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1173 rs6000_tls_size = 16;
1174 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1175 rs6000_tls_size = 32;
1176 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1177 rs6000_tls_size = 64;
1178 else
1179 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1180}
1181
5accd822 1182void
a2369ed3 1183optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1184{
5accd822 1185}
3cfa4909
MM
1186\f
1187/* Do anything needed at the start of the asm file. */
1188
1bc7c5b6 1189static void
863d938c 1190rs6000_file_start (void)
3cfa4909 1191{
c4d38ccb 1192 size_t i;
3cfa4909 1193 char buffer[80];
d330fd93 1194 const char *start = buffer;
3cfa4909 1195 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1196 const char *default_cpu = TARGET_CPU_DEFAULT;
1197 FILE *file = asm_out_file;
1198
1199 default_file_start ();
1200
1201#ifdef TARGET_BI_ARCH
1202 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1203 default_cpu = 0;
1204#endif
3cfa4909
MM
1205
1206 if (flag_verbose_asm)
1207 {
1208 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1209 rs6000_select[0].string = default_cpu;
1210
b6a1cbae 1211 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1212 {
1213 ptr = &rs6000_select[i];
1214 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1215 {
1216 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1217 start = "";
1218 }
1219 }
1220
b91da81f 1221#ifdef USING_ELFOS_H
3cfa4909
MM
1222 switch (rs6000_sdata)
1223 {
1224 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1225 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1226 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1227 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1228 }
1229
1230 if (rs6000_sdata && g_switch_value)
1231 {
307b599c
MK
1232 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1233 g_switch_value);
3cfa4909
MM
1234 start = "";
1235 }
1236#endif
1237
1238 if (*start == '\0')
949ea356 1239 putc ('\n', file);
3cfa4909
MM
1240 }
1241}
5248c961 1242\f
a0ab749a 1243/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1244
1245int
863d938c 1246direct_return (void)
9878760c 1247{
4697a36c
MM
1248 if (reload_completed)
1249 {
1250 rs6000_stack_t *info = rs6000_stack_info ();
1251
1252 if (info->first_gp_reg_save == 32
1253 && info->first_fp_reg_save == 64
00b960c7 1254 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1255 && ! info->lr_save_p
1256 && ! info->cr_save_p
00b960c7 1257 && info->vrsave_mask == 0
c81fc13e 1258 && ! info->push_p)
4697a36c
MM
1259 return 1;
1260 }
1261
1262 return 0;
9878760c
RK
1263}
1264
1265/* Returns 1 always. */
1266
1267int
a2369ed3
DJ
1268any_operand (rtx op ATTRIBUTE_UNUSED,
1269 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1270{
1271 return 1;
1272}
1273
a4f6c312 1274/* Returns 1 if op is the count register. */
38c1f2d7 1275int
a2369ed3 1276count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1277{
1278 if (GET_CODE (op) != REG)
1279 return 0;
1280
1281 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1282 return 1;
1283
1284 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1285 return 1;
1286
1287 return 0;
1288}
1289
0ec4e2a8
AH
1290/* Returns 1 if op is an altivec register. */
1291int
a2369ed3 1292altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8
AH
1293{
1294
1295 return (register_operand (op, mode)
1296 && (GET_CODE (op) != REG
1297 || REGNO (op) > FIRST_PSEUDO_REGISTER
1298 || ALTIVEC_REGNO_P (REGNO (op))));
1299}
1300
38c1f2d7 1301int
a2369ed3 1302xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1303{
1304 if (GET_CODE (op) != REG)
1305 return 0;
1306
9ebbca7d 1307 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1308 return 1;
1309
802a0058
MM
1310 return 0;
1311}
1312
c859cda6 1313/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1314 by such constants completes more quickly. */
c859cda6
DJ
1315
1316int
a2369ed3 1317s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6
DJ
1318{
1319 return ( GET_CODE (op) == CONST_INT
1320 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1321}
1322
9878760c
RK
1323/* Return 1 if OP is a constant that can fit in a D field. */
1324
1325int
a2369ed3 1326short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1327{
5f59ecb7
DE
1328 return (GET_CODE (op) == CONST_INT
1329 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1330}
1331
5519a4f9 1332/* Similar for an unsigned D field. */
9878760c
RK
1333
1334int
a2369ed3 1335u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1336{
19684119 1337 return (GET_CODE (op) == CONST_INT
c1f11548 1338 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1339}
1340
dcfedcd0
RK
1341/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1342
1343int
a2369ed3 1344non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1345{
1346 return (GET_CODE (op) == CONST_INT
a7653a2c 1347 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1348}
1349
2bfcf297
DB
1350/* Returns 1 if OP is a CONST_INT that is a positive value
1351 and an exact power of 2. */
1352
1353int
a2369ed3 1354exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1355{
1356 return (GET_CODE (op) == CONST_INT
1357 && INTVAL (op) > 0
1358 && exact_log2 (INTVAL (op)) >= 0);
1359}
1360
9878760c
RK
1361/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1362 ctr, or lr). */
1363
1364int
a2369ed3 1365gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1366{
1367 return (register_operand (op, mode)
802a0058 1368 && (GET_CODE (op) != REG
9ebbca7d
GK
1369 || (REGNO (op) >= ARG_POINTER_REGNUM
1370 && !XER_REGNO_P (REGNO (op)))
1371 || REGNO (op) < MQ_REGNO));
9878760c
RK
1372}
1373
1374/* Returns 1 if OP is either a pseudo-register or a register denoting a
1375 CR field. */
1376
1377int
a2369ed3 1378cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1379{
1380 return (register_operand (op, mode)
1381 && (GET_CODE (op) != REG
1382 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1383 || CR_REGNO_P (REGNO (op))));
1384}
1385
815cdc52
MM
1386/* Returns 1 if OP is either a pseudo-register or a register denoting a
1387 CR field that isn't CR0. */
1388
1389int
a2369ed3 1390cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1391{
1392 return (register_operand (op, mode)
1393 && (GET_CODE (op) != REG
1394 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1395 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1396}
1397
a4f6c312
SS
1398/* Returns 1 if OP is either a constant integer valid for a D-field or
1399 a non-special register. If a register, it must be in the proper
1400 mode unless MODE is VOIDmode. */
9878760c
RK
1401
1402int
a2369ed3 1403reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1404{
f5a28898 1405 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1406}
1407
a4f6c312
SS
1408/* Similar, except check if the negation of the constant would be
1409 valid for a D-field. */
9878760c
RK
1410
1411int
a2369ed3 1412reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1413{
1414 if (GET_CODE (op) == CONST_INT)
1415 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1416
cd2b37d9 1417 return gpc_reg_operand (op, mode);
9878760c
RK
1418}
1419
768070a0
TR
1420/* Returns 1 if OP is either a constant integer valid for a DS-field or
1421 a non-special register. If a register, it must be in the proper
1422 mode unless MODE is VOIDmode. */
1423
1424int
a2369ed3 1425reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1426{
1427 if (gpc_reg_operand (op, mode))
1428 return 1;
1429 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1430 return 1;
1431
1432 return 0;
1433}
1434
1435
a4f6c312
SS
1436/* Return 1 if the operand is either a register or an integer whose
1437 high-order 16 bits are zero. */
9878760c
RK
1438
1439int
a2369ed3 1440reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1441{
e675f625 1442 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1443}
1444
1445/* Return 1 is the operand is either a non-special register or ANY
1446 constant integer. */
1447
1448int
a2369ed3 1449reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1450{
a4f6c312 1451 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1452}
1453
1454/* Return 1 is the operand is either a non-special register or ANY
1455 32-bit signed constant integer. */
1456
1457int
a2369ed3 1458reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1459{
a4f6c312
SS
1460 return (gpc_reg_operand (op, mode)
1461 || (GET_CODE (op) == CONST_INT
f6bf7de2 1462#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1463 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1464 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1465#endif
a4f6c312 1466 ));
9878760c
RK
1467}
1468
2bfcf297
DB
1469/* Return 1 is the operand is either a non-special register or a 32-bit
1470 signed constant integer valid for 64-bit addition. */
1471
1472int
a2369ed3 1473reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1474{
a4f6c312
SS
1475 return (gpc_reg_operand (op, mode)
1476 || (GET_CODE (op) == CONST_INT
a65c591c 1477#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1478 && INTVAL (op) < 0x7fff8000
a65c591c 1479#else
a4f6c312
SS
1480 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1481 < 0x100000000ll)
2bfcf297 1482#endif
a4f6c312 1483 ));
2bfcf297
DB
1484}
1485
1486/* Return 1 is the operand is either a non-special register or a 32-bit
1487 signed constant integer valid for 64-bit subtraction. */
1488
1489int
a2369ed3 1490reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1491{
a4f6c312
SS
1492 return (gpc_reg_operand (op, mode)
1493 || (GET_CODE (op) == CONST_INT
a65c591c 1494#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1495 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1496#else
a4f6c312
SS
1497 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1498 < 0x100000000ll)
2bfcf297 1499#endif
a4f6c312 1500 ));
2bfcf297
DB
1501}
1502
9ebbca7d
GK
1503/* Return 1 is the operand is either a non-special register or ANY
1504 32-bit unsigned constant integer. */
1505
1506int
a2369ed3 1507reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1508{
1d328b19
GK
1509 if (GET_CODE (op) == CONST_INT)
1510 {
1511 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1512 {
1513 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1514 abort ();
1d328b19
GK
1515
1516 if (INTVAL (op) < 0)
1517 return 0;
1518 }
1519
1520 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1521 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1522 }
1523 else if (GET_CODE (op) == CONST_DOUBLE)
1524 {
1525 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1526 || mode != DImode)
a4f6c312 1527 abort ();
1d328b19
GK
1528
1529 return CONST_DOUBLE_HIGH (op) == 0;
1530 }
1531 else
1532 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1533}
1534
51d3e7d6 1535/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1536
1537int
a2369ed3 1538got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
1539{
1540 return (GET_CODE (op) == SYMBOL_REF
1541 || GET_CODE (op) == CONST
1542 || GET_CODE (op) == LABEL_REF);
1543}
1544
38c1f2d7
MM
1545/* Return 1 if the operand is a simple references that can be loaded via
1546 the GOT (labels involving addition aren't allowed). */
1547
1548int
a2369ed3 1549got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
1550{
1551 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1552}
1553
4e74d8ec
MM
1554/* Return the number of instructions it takes to form a constant in an
1555 integer register. */
1556
1557static int
a2369ed3 1558num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
1559{
1560 /* signed constant loadable with {cal|addi} */
5f59ecb7 1561 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1562 return 1;
1563
4e74d8ec 1564 /* constant loadable with {cau|addis} */
5f59ecb7 1565 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1566 return 1;
1567
5f59ecb7 1568#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1569 else if (TARGET_POWERPC64)
4e74d8ec 1570 {
a65c591c
DE
1571 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1572 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1573
a65c591c 1574 if (high == 0 || high == -1)
4e74d8ec
MM
1575 return 2;
1576
a65c591c 1577 high >>= 1;
4e74d8ec 1578
a65c591c 1579 if (low == 0)
4e74d8ec 1580 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1581 else
1582 return (num_insns_constant_wide (high)
e396202a 1583 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1584 }
1585#endif
1586
1587 else
1588 return 2;
1589}
1590
1591int
a2369ed3 1592num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 1593{
4e74d8ec 1594 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1595 {
1596#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1597 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1598 && mask64_operand (op, mode))
0d30d435
DE
1599 return 2;
1600 else
1601#endif
1602 return num_insns_constant_wide (INTVAL (op));
1603 }
4e74d8ec 1604
6fc48950
MM
1605 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1606 {
1607 long l;
1608 REAL_VALUE_TYPE rv;
1609
1610 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1611 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1612 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1613 }
1614
47ad8c61 1615 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1616 {
47ad8c61
MM
1617 HOST_WIDE_INT low;
1618 HOST_WIDE_INT high;
1619 long l[2];
1620 REAL_VALUE_TYPE rv;
1621 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1622
47ad8c61
MM
1623 if (mode == VOIDmode || mode == DImode)
1624 {
1625 high = CONST_DOUBLE_HIGH (op);
1626 low = CONST_DOUBLE_LOW (op);
1627 }
1628 else
1629 {
1630 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1631 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1632 high = l[endian];
1633 low = l[1 - endian];
1634 }
4e74d8ec 1635
47ad8c61
MM
1636 if (TARGET_32BIT)
1637 return (num_insns_constant_wide (low)
1638 + num_insns_constant_wide (high));
4e74d8ec
MM
1639
1640 else
47ad8c61 1641 {
e72247f4 1642 if (high == 0 && low >= 0)
47ad8c61
MM
1643 return num_insns_constant_wide (low);
1644
e72247f4 1645 else if (high == -1 && low < 0)
47ad8c61
MM
1646 return num_insns_constant_wide (low);
1647
a260abc9
DE
1648 else if (mask64_operand (op, mode))
1649 return 2;
1650
47ad8c61
MM
1651 else if (low == 0)
1652 return num_insns_constant_wide (high) + 1;
1653
1654 else
1655 return (num_insns_constant_wide (high)
1656 + num_insns_constant_wide (low) + 1);
1657 }
4e74d8ec
MM
1658 }
1659
1660 else
1661 abort ();
1662}
1663
a4f6c312
SS
1664/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1665 register with one instruction per word. We only do this if we can
1666 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1667
1668int
a2369ed3 1669easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 1670{
9878760c
RK
1671 if (GET_CODE (op) != CONST_DOUBLE
1672 || GET_MODE (op) != mode
4e74d8ec 1673 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1674 return 0;
1675
a4f6c312 1676 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1677 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1678 && mode != DImode)
b6c9286a
MM
1679 return 1;
1680
a4f6c312 1681 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1682 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1683 return 0;
1684
5ae4759c 1685#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1686 /* Similarly if we are using -mrelocatable, consider all constants
1687 to be hard. */
5ae4759c
MM
1688 if (TARGET_RELOCATABLE)
1689 return 0;
1690#endif
1691
fcce224d
DE
1692 if (mode == TFmode)
1693 {
1694 long k[4];
1695 REAL_VALUE_TYPE rv;
1696
1697 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1698 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1699
1700 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1701 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1702 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1703 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1704 }
1705
1706 else if (mode == DFmode)
042259f2
DE
1707 {
1708 long k[2];
1709 REAL_VALUE_TYPE rv;
1710
1711 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1712 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1713
a65c591c
DE
1714 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1715 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1716 }
4e74d8ec
MM
1717
1718 else if (mode == SFmode)
042259f2
DE
1719 {
1720 long l;
1721 REAL_VALUE_TYPE rv;
1722
1723 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1724 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1725
4e74d8ec 1726 return num_insns_constant_wide (l) == 1;
042259f2 1727 }
4e74d8ec 1728
a260abc9 1729 else if (mode == DImode)
c81fc13e 1730 return ((TARGET_POWERPC64
a260abc9
DE
1731 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1732 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1733
a9098fd0
GK
1734 else if (mode == SImode)
1735 return 1;
4e74d8ec
MM
1736 else
1737 abort ();
9878760c 1738}
8f75773e 1739
effa5d5d 1740/* Returns the constant for the splat instruction, if exists. */
452a7d36
HP
1741
1742static int
1743easy_vector_splat_const (int cst, enum machine_mode mode)
1744{
1745 switch (mode)
1746 {
1747 case V4SImode:
1748 if (EASY_VECTOR_15 (cst)
1749 || EASY_VECTOR_15_ADD_SELF (cst))
1750 return cst;
1751 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
1752 break;
1753 cst = cst >> 16;
1754 case V8HImode:
1755 if (EASY_VECTOR_15 (cst)
1756 || EASY_VECTOR_15_ADD_SELF (cst))
1757 return cst;
1758 if ((cst & 0xff) != ((cst >> 8) & 0xff))
1759 break;
1760 cst = cst >> 8;
1761 case V16QImode:
1762 if (EASY_VECTOR_15 (cst)
1763 || EASY_VECTOR_15_ADD_SELF (cst))
1764 return cst;
1765 default:
1766 break;
1767 }
1768 return 0;
1769}
1770
1771
72ac76be 1772/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
1773
1774static int
a2369ed3 1775easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
1776{
1777 int units, i, cst;
1778
1779 units = CONST_VECTOR_NUNITS (op);
1780
1781 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1782 for (i = 1; i < units; ++i)
1783 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1784 break;
452a7d36 1785 if (i == units && easy_vector_splat_const (cst, mode))
d744e06e
AH
1786 return 1;
1787 return 0;
1788}
1789
1790/* Return 1 if the operand is a CONST_INT and can be put into a
1791 register without using memory. */
1792
1793int
a2369ed3 1794easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 1795{
d744e06e 1796 int cst, cst2;
69ef87e2 1797
d744e06e
AH
1798 if (GET_CODE (op) != CONST_VECTOR
1799 || (!TARGET_ALTIVEC
1800 && !TARGET_SPE))
69ef87e2
AH
1801 return 0;
1802
d744e06e
AH
1803 if (zero_constant (op, mode)
1804 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1805 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1806 return 1;
69ef87e2 1807
d744e06e
AH
1808 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1809 return 0;
1810
f5119d10
AH
1811 if (TARGET_SPE && mode == V1DImode)
1812 return 0;
1813
d744e06e
AH
1814 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1815 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1816
1817 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1818 li r0, CONSTANT1
1819 evmergelo r0, r0, r0
1820 li r0, CONSTANT2
1821
1822 I don't know how efficient it would be to allow bigger constants,
1823 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1824 instructions is better than a 64-bit memory load, but I don't
1825 have the e500 timing specs. */
1826 if (TARGET_SPE && mode == V2SImode
1827 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 1828 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
1829 return 1;
1830
452a7d36
HP
1831 if (TARGET_ALTIVEC
1832 && easy_vector_same (op, mode))
1833 {
1834 cst = easy_vector_splat_const (cst, mode);
1835 if (EASY_VECTOR_15_ADD_SELF (cst)
1836 || EASY_VECTOR_15 (cst))
1837 return 1;
1838 }
d744e06e
AH
1839 return 0;
1840}
1841
1842/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1843
1844int
a2369ed3 1845easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
1846{
1847 int cst;
452a7d36
HP
1848 if (TARGET_ALTIVEC
1849 && GET_CODE (op) == CONST_VECTOR
1850 && easy_vector_same (op, mode))
1851 {
1852 cst = easy_vector_splat_const (INTVAL (CONST_VECTOR_ELT (op, 0)), mode);
1853 if (EASY_VECTOR_15_ADD_SELF (cst))
1854 return 1;
1855 }
1856 return 0;
1857}
d744e06e 1858
452a7d36 1859/* Generate easy_vector_constant out of a easy_vector_constant_add_self. */
d744e06e 1860
452a7d36
HP
1861rtx
1862gen_easy_vector_constant_add_self (rtx op)
1863{
1864 int i, units;
1865 rtvec v;
1866 units = GET_MODE_NUNITS (GET_MODE (op));
1867 v = rtvec_alloc (units);
1868
1869 for (i = 0; i < units; i++)
1870 RTVEC_ELT (v, i) =
1871 GEN_INT (INTVAL (CONST_VECTOR_ELT (op, i)) >> 1);
1872 return gen_rtx_raw_CONST_VECTOR (GET_MODE (op), v);
d744e06e
AH
1873}
1874
1875const char *
a2369ed3 1876output_vec_const_move (rtx *operands)
d744e06e
AH
1877{
1878 int cst, cst2;
1879 enum machine_mode mode;
1880 rtx dest, vec;
1881
1882 dest = operands[0];
1883 vec = operands[1];
69ef87e2 1884
d744e06e
AH
1885 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1886 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1887 mode = GET_MODE (dest);
69ef87e2 1888
d744e06e
AH
1889 if (TARGET_ALTIVEC)
1890 {
1891 if (zero_constant (vec, mode))
1892 return "vxor %0,%0,%0";
ce1f50b2 1893 else if (easy_vector_constant (vec, mode))
98ef3137 1894 {
d744e06e
AH
1895 operands[1] = GEN_INT (cst);
1896 switch (mode)
1897 {
1898 case V4SImode:
452a7d36 1899 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
1900 {
1901 operands[1] = GEN_INT (cst);
1902 return "vspltisw %0,%1";
1903 }
452a7d36
HP
1904 else if (EASY_VECTOR_15_ADD_SELF (cst))
1905 return "#";
ce1f50b2 1906 cst = cst >> 16;
d744e06e 1907 case V8HImode:
452a7d36 1908 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
1909 {
1910 operands[1] = GEN_INT (cst);
1911 return "vspltish %0,%1";
1912 }
452a7d36
HP
1913 else if (EASY_VECTOR_15_ADD_SELF (cst))
1914 return "#";
ce1f50b2 1915 cst = cst >> 8;
d744e06e 1916 case V16QImode:
452a7d36 1917 if (EASY_VECTOR_15 (cst))
ce1f50b2
HP
1918 {
1919 operands[1] = GEN_INT (cst);
1920 return "vspltisb %0,%1";
1921 }
452a7d36
HP
1922 else if (EASY_VECTOR_15_ADD_SELF (cst))
1923 return "#";
d744e06e
AH
1924 default:
1925 abort ();
1926 }
98ef3137 1927 }
d744e06e
AH
1928 else
1929 abort ();
69ef87e2
AH
1930 }
1931
d744e06e
AH
1932 if (TARGET_SPE)
1933 {
1934 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1935 pattern of V1DI, V4HI, and V2SF.
1936
c1207243 1937 FIXME: We should probably return # and add post reload
d744e06e
AH
1938 splitters for these, but this way is so easy ;-).
1939 */
1940 operands[1] = GEN_INT (cst);
1941 operands[2] = GEN_INT (cst2);
1942 if (cst == cst2)
1943 return "li %0,%1\n\tevmergelo %0,%0,%0";
1944 else
1945 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1946 }
1947
1948 abort ();
69ef87e2
AH
1949}
1950
1951/* Return 1 if the operand is the constant 0. This works for scalars
1952 as well as vectors. */
1953int
a2369ed3 1954zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
1955{
1956 return op == CONST0_RTX (mode);
1957}
1958
50a0b056
GK
1959/* Return 1 if the operand is 0.0. */
1960int
a2369ed3 1961zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
1962{
1963 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1964}
1965
a4f6c312
SS
1966/* Return 1 if the operand is in volatile memory. Note that during
1967 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1968 volatile memory references. So this function allows us to
1969 recognize volatile references where its safe. */
1970
1971int
a2369ed3 1972volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
1973{
1974 if (GET_CODE (op) != MEM)
1975 return 0;
1976
1977 if (!MEM_VOLATILE_P (op))
1978 return 0;
1979
1980 if (mode != GET_MODE (op))
1981 return 0;
1982
1983 if (reload_completed)
1984 return memory_operand (op, mode);
1985
1986 if (reload_in_progress)
1987 return strict_memory_address_p (mode, XEXP (op, 0));
1988
1989 return memory_address_p (mode, XEXP (op, 0));
1990}
1991
97f6e72f 1992/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1993
1994int
a2369ed3 1995offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 1996{
97f6e72f 1997 return ((GET_CODE (op) == MEM)
677a9668 1998 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1999 mode, XEXP (op, 0)));
914c2e77
RK
2000}
2001
9878760c
RK
2002/* Return 1 if the operand is either an easy FP constant (see above) or
2003 memory. */
2004
2005int
a2369ed3 2006mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
2007{
2008 return memory_operand (op, mode) || easy_fp_constant (op, mode);
2009}
2010
2011/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 2012 that can be used as the operand of a `mode' add insn. */
9878760c
RK
2013
2014int
a2369ed3 2015add_operand (rtx op, enum machine_mode mode)
9878760c 2016{
2bfcf297 2017 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
2018 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2019 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
2020
2021 return gpc_reg_operand (op, mode);
9878760c
RK
2022}
2023
dcfedcd0
RK
2024/* Return 1 if OP is a constant but not a valid add_operand. */
2025
2026int
a2369ed3 2027non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
2028{
2029 return (GET_CODE (op) == CONST_INT
e72247f4
DE
2030 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
2031 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
2032}
2033
9878760c
RK
2034/* Return 1 if the operand is a non-special register or a constant that
2035 can be used as the operand of an OR or XOR insn on the RS/6000. */
2036
2037int
a2369ed3 2038logical_operand (rtx op, enum machine_mode mode)
9878760c 2039{
40501e5f 2040 HOST_WIDE_INT opl, oph;
1d328b19 2041
dfbdccdb
GK
2042 if (gpc_reg_operand (op, mode))
2043 return 1;
1d328b19 2044
dfbdccdb 2045 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
2046 {
2047 opl = INTVAL (op) & GET_MODE_MASK (mode);
2048
2049#if HOST_BITS_PER_WIDE_INT <= 32
2050 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
2051 return 0;
2052#endif
2053 }
dfbdccdb
GK
2054 else if (GET_CODE (op) == CONST_DOUBLE)
2055 {
1d328b19 2056 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 2057 abort ();
1d328b19
GK
2058
2059 opl = CONST_DOUBLE_LOW (op);
2060 oph = CONST_DOUBLE_HIGH (op);
40501e5f 2061 if (oph != 0)
38886f37 2062 return 0;
dfbdccdb
GK
2063 }
2064 else
2065 return 0;
1d328b19 2066
40501e5f
AM
2067 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
2068 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
2069}
2070
dcfedcd0 2071/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 2072 above), but could be split into one. */
dcfedcd0
RK
2073
2074int
a2369ed3 2075non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 2076{
dfbdccdb 2077 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
2078 && ! logical_operand (op, mode)
2079 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
2080}
2081
19ba8161 2082/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
2083 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
2084 Reject all ones and all zeros, since these should have been optimized
2085 away and confuse the making of MB and ME. */
2086
2087int
a2369ed3 2088mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 2089{
02071907 2090 HOST_WIDE_INT c, lsb;
9878760c 2091
19ba8161
DE
2092 if (GET_CODE (op) != CONST_INT)
2093 return 0;
2094
2095 c = INTVAL (op);
2096
57deb3a1
AM
2097 /* Fail in 64-bit mode if the mask wraps around because the upper
2098 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
2099 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
2100 return 0;
2101
c5059423
AM
2102 /* We don't change the number of transitions by inverting,
2103 so make sure we start with the LS bit zero. */
2104 if (c & 1)
2105 c = ~c;
2106
2107 /* Reject all zeros or all ones. */
2108 if (c == 0)
9878760c
RK
2109 return 0;
2110
c5059423
AM
2111 /* Find the first transition. */
2112 lsb = c & -c;
2113
2114 /* Invert to look for a second transition. */
2115 c = ~c;
9878760c 2116
c5059423
AM
2117 /* Erase first transition. */
2118 c &= -lsb;
9878760c 2119
c5059423
AM
2120 /* Find the second transition (if any). */
2121 lsb = c & -c;
2122
2123 /* Match if all the bits above are 1's (or c is zero). */
2124 return c == -lsb;
9878760c
RK
2125}
2126
0ba1b2ff
AM
2127/* Return 1 for the PowerPC64 rlwinm corner case. */
2128
2129int
a2369ed3 2130mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2131{
2132 HOST_WIDE_INT c, lsb;
2133
2134 if (GET_CODE (op) != CONST_INT)
2135 return 0;
2136
2137 c = INTVAL (op);
2138
2139 if ((c & 0x80000001) != 0x80000001)
2140 return 0;
2141
2142 c = ~c;
2143 if (c == 0)
2144 return 0;
2145
2146 lsb = c & -c;
2147 c = ~c;
2148 c &= -lsb;
2149 lsb = c & -c;
2150 return c == -lsb;
2151}
2152
a260abc9
DE
2153/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2154 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2155 Reject all zeros, since zero should have been optimized away and
2156 confuses the making of MB and ME. */
9878760c
RK
2157
2158int
a2369ed3 2159mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2160{
2161 if (GET_CODE (op) == CONST_INT)
2162 {
02071907 2163 HOST_WIDE_INT c, lsb;
a260abc9 2164
c5059423 2165 c = INTVAL (op);
a260abc9 2166
0ba1b2ff 2167 /* Reject all zeros. */
c5059423 2168 if (c == 0)
e2c953b6
DE
2169 return 0;
2170
0ba1b2ff
AM
2171 /* We don't change the number of transitions by inverting,
2172 so make sure we start with the LS bit zero. */
2173 if (c & 1)
2174 c = ~c;
2175
c5059423
AM
2176 /* Find the transition, and check that all bits above are 1's. */
2177 lsb = c & -c;
e3981aab
DE
2178
2179 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2180 return c == -lsb;
e2c953b6 2181 }
0ba1b2ff
AM
2182 return 0;
2183}
2184
2185/* Like mask64_operand, but allow up to three transitions. This
2186 predicate is used by insn patterns that generate two rldicl or
2187 rldicr machine insns. */
2188
2189int
a2369ed3 2190mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2191{
2192 if (GET_CODE (op) == CONST_INT)
a260abc9 2193 {
0ba1b2ff 2194 HOST_WIDE_INT c, lsb;
a260abc9 2195
0ba1b2ff 2196 c = INTVAL (op);
a260abc9 2197
0ba1b2ff
AM
2198 /* Disallow all zeros. */
2199 if (c == 0)
2200 return 0;
a260abc9 2201
0ba1b2ff
AM
2202 /* We don't change the number of transitions by inverting,
2203 so make sure we start with the LS bit zero. */
2204 if (c & 1)
2205 c = ~c;
a260abc9 2206
0ba1b2ff
AM
2207 /* Find the first transition. */
2208 lsb = c & -c;
a260abc9 2209
0ba1b2ff
AM
2210 /* Invert to look for a second transition. */
2211 c = ~c;
2212
2213 /* Erase first transition. */
2214 c &= -lsb;
2215
2216 /* Find the second transition. */
2217 lsb = c & -c;
2218
2219 /* Invert to look for a third transition. */
2220 c = ~c;
2221
2222 /* Erase second transition. */
2223 c &= -lsb;
2224
2225 /* Find the third transition (if any). */
2226 lsb = c & -c;
2227
2228 /* Match if all the bits above are 1's (or c is zero). */
2229 return c == -lsb;
2230 }
2231 return 0;
2232}
2233
2234/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2235 implement ANDing by the mask IN. */
2236void
a2369ed3 2237build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2238{
2239#if HOST_BITS_PER_WIDE_INT >= 64
2240 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2241 int shift;
2242
2243 if (GET_CODE (in) != CONST_INT)
2244 abort ();
2245
2246 c = INTVAL (in);
2247 if (c & 1)
2248 {
2249 /* Assume c initially something like 0x00fff000000fffff. The idea
2250 is to rotate the word so that the middle ^^^^^^ group of zeros
2251 is at the MS end and can be cleared with an rldicl mask. We then
2252 rotate back and clear off the MS ^^ group of zeros with a
2253 second rldicl. */
2254 c = ~c; /* c == 0xff000ffffff00000 */
2255 lsb = c & -c; /* lsb == 0x0000000000100000 */
2256 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2257 c = ~c; /* c == 0x00fff000000fffff */
2258 c &= -lsb; /* c == 0x00fff00000000000 */
2259 lsb = c & -c; /* lsb == 0x0000100000000000 */
2260 c = ~c; /* c == 0xff000fffffffffff */
2261 c &= -lsb; /* c == 0xff00000000000000 */
2262 shift = 0;
2263 while ((lsb >>= 1) != 0)
2264 shift++; /* shift == 44 on exit from loop */
2265 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2266 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2267 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2268 }
2269 else
0ba1b2ff
AM
2270 {
2271 /* Assume c initially something like 0xff000f0000000000. The idea
2272 is to rotate the word so that the ^^^ middle group of zeros
2273 is at the LS end and can be cleared with an rldicr mask. We then
2274 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2275 a second rldicr. */
2276 lsb = c & -c; /* lsb == 0x0000010000000000 */
2277 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2278 c = ~c; /* c == 0x00fff0ffffffffff */
2279 c &= -lsb; /* c == 0x00fff00000000000 */
2280 lsb = c & -c; /* lsb == 0x0000100000000000 */
2281 c = ~c; /* c == 0xff000fffffffffff */
2282 c &= -lsb; /* c == 0xff00000000000000 */
2283 shift = 0;
2284 while ((lsb >>= 1) != 0)
2285 shift++; /* shift == 44 on exit from loop */
2286 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2287 m1 >>= shift; /* m1 == 0x0000000000000fff */
2288 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2289 }
2290
2291 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2292 masks will be all 1's. We are guaranteed more than one transition. */
2293 out[0] = GEN_INT (64 - shift);
2294 out[1] = GEN_INT (m1);
2295 out[2] = GEN_INT (shift);
2296 out[3] = GEN_INT (m2);
2297#else
045572c7
GK
2298 (void)in;
2299 (void)out;
0ba1b2ff
AM
2300 abort ();
2301#endif
a260abc9
DE
2302}
2303
2304/* Return 1 if the operand is either a non-special register or a constant
2305 that can be used as the operand of a PowerPC64 logical AND insn. */
2306
2307int
a2369ed3 2308and64_operand (rtx op, enum machine_mode mode)
9878760c 2309{
a4f6c312 2310 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2311 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2312
2313 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2314}
2315
0ba1b2ff
AM
2316/* Like the above, but also match constants that can be implemented
2317 with two rldicl or rldicr insns. */
2318
2319int
a2369ed3 2320and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2321{
a3c9585f 2322 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2323 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2324
2325 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2326}
2327
a260abc9
DE
2328/* Return 1 if the operand is either a non-special register or a
2329 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2330
2331int
a2369ed3 2332and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2333{
a4f6c312 2334 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2335 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2336
2337 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2338}
2339
9878760c
RK
2340/* Return 1 if the operand is a general register or memory operand. */
2341
2342int
a2369ed3 2343reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2344{
b6c9286a
MM
2345 return (gpc_reg_operand (op, mode)
2346 || memory_operand (op, mode)
4c81e946 2347 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2348 || volatile_mem_operand (op, mode));
9878760c
RK
2349}
2350
a7a813f7 2351/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2352 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2353 instruction. */
2354
2355int
a2369ed3 2356lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2357{
2358 rtx inner = op;
2359
2360 if (reload_completed && GET_CODE (inner) == SUBREG)
2361 inner = SUBREG_REG (inner);
2362
2363 return gpc_reg_operand (inner, mode)
2364 || (memory_operand (inner, mode)
2365 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2366 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2367 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2368 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2369 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2370}
2371
cc4d5fec
JH
2372/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2373
2374int
a2369ed3 2375symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2376{
2377 if (mode != VOIDmode && GET_MODE (op) != mode)
2378 return 0;
2379
473f51b6
DE
2380 return (GET_CODE (op) == SYMBOL_REF
2381 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2382}
2383
9878760c 2384/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2385 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2386
2387int
a2369ed3 2388call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2389{
2390 if (mode != VOIDmode && GET_MODE (op) != mode)
2391 return 0;
2392
2393 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2394 || (GET_CODE (op) == REG
2395 && (REGNO (op) == LINK_REGISTER_REGNUM
2396 || REGNO (op) == COUNT_REGISTER_REGNUM
2397 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2398}
2399
2af3d377 2400/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2401 this file. */
2af3d377
RK
2402
2403int
a2369ed3
DJ
2404current_file_function_operand (rtx op,
2405 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2406{
473f51b6
DE
2407 return (GET_CODE (op) == SYMBOL_REF
2408 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2409 && (SYMBOL_REF_LOCAL_P (op)
2410 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2411}
2412
9878760c
RK
2413/* Return 1 if this operand is a valid input for a move insn. */
2414
2415int
a2369ed3 2416input_operand (rtx op, enum machine_mode mode)
9878760c 2417{
eb4e8003 2418 /* Memory is always valid. */
9878760c
RK
2419 if (memory_operand (op, mode))
2420 return 1;
2421
eb4e8003
RK
2422 /* For floating-point, easy constants are valid. */
2423 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2424 && CONSTANT_P (op)
2425 && easy_fp_constant (op, mode))
2426 return 1;
2427
4e74d8ec
MM
2428 /* Allow any integer constant. */
2429 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2430 && (GET_CODE (op) == CONST_INT
e675f625 2431 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2432 return 1;
2433
d744e06e
AH
2434 /* Allow easy vector constants. */
2435 if (GET_CODE (op) == CONST_VECTOR
2436 && easy_vector_constant (op, mode))
2437 return 1;
2438
eb4e8003
RK
2439 /* For floating-point or multi-word mode, the only remaining valid type
2440 is a register. */
9878760c
RK
2441 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2442 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2443 return register_operand (op, mode);
9878760c 2444
88fe15a1
RK
2445 /* The only cases left are integral modes one word or smaller (we
2446 do not get called for MODE_CC values). These can be in any
2447 register. */
2448 if (register_operand (op, mode))
a8b3aeda 2449 return 1;
88fe15a1 2450
84cf9dda 2451 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2452 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2453 return 1;
2454
9ebbca7d 2455 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2456 if (toc_relative_expr_p (op))
b6c9286a
MM
2457 return 1;
2458
88228c4b
MM
2459 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2460 to be valid. */
f607bc57 2461 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2462 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2463 && small_data_operand (op, Pmode))
2464 return 1;
2465
042259f2 2466 return 0;
9878760c 2467}
7509c759 2468
95727fb8
AP
2469
2470/* Darwin, AIX increases natural record alignment to doubleword if the first
2471 field is an FP double while the FP fields remain word aligned. */
2472
19d66194 2473unsigned int
95727fb8
AP
2474rs6000_special_round_type_align (tree type, int computed, int specified)
2475{
2476 tree field = TYPE_FIELDS (type);
95727fb8
AP
2477
2478 /* Skip all the static variables only if ABI is greater than
71cc389b 2479 1 or equal to 0. */
3ce5437a 2480 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2481 field = TREE_CHAIN (field);
2482
3ce5437a 2483 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2484 return MAX (computed, specified);
2485
2486 return MAX (MAX (computed, specified), 64);
2487}
2488
a4f6c312 2489/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2490
2491int
a2369ed3
DJ
2492small_data_operand (rtx op ATTRIBUTE_UNUSED,
2493 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2494{
38c1f2d7 2495#if TARGET_ELF
5f59ecb7 2496 rtx sym_ref;
7509c759 2497
d9407988 2498 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2499 return 0;
a54d04b7 2500
f607bc57 2501 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2502 return 0;
2503
88228c4b
MM
2504 if (GET_CODE (op) == SYMBOL_REF)
2505 sym_ref = op;
2506
2507 else if (GET_CODE (op) != CONST
2508 || GET_CODE (XEXP (op, 0)) != PLUS
2509 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2510 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2511 return 0;
2512
88228c4b 2513 else
dbf55e53
MM
2514 {
2515 rtx sum = XEXP (op, 0);
2516 HOST_WIDE_INT summand;
2517
2518 /* We have to be careful here, because it is the referenced address
2519 that must be 32k from _SDA_BASE_, not just the symbol. */
2520 summand = INTVAL (XEXP (sum, 1));
307b599c 2521 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2522 return 0;
2523
2524 sym_ref = XEXP (sum, 0);
2525 }
88228c4b 2526
20bfcd69 2527 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2528#else
2529 return 0;
2530#endif
7509c759 2531}
46c07df8 2532
d2288d5d
HP
2533/* Return true, if operand is a memory operand and has a
2534 displacement divisible by 4. */
2535
2536int
2537word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2538{
2539 rtx addr;
2540 int off = 0;
2541
2542 if (!memory_operand (op, mode))
2543 return 0;
2544
2545 addr = XEXP (op, 0);
2546 if (GET_CODE (addr) == PLUS
2547 && GET_CODE (XEXP (addr, 0)) == REG
2548 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2549 off = INTVAL (XEXP (addr, 1));
2550
2551 return (off % 4) == 0;
2552}
2553
3a1f863f 2554/* Return true if either operand is a general purpose register. */
46c07df8 2555
3a1f863f
DE
2556bool
2557gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 2558{
3a1f863f
DE
2559 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2560 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
2561}
2562
9ebbca7d 2563\f
4d588c14
RH
2564/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2565
9ebbca7d 2566static int
a2369ed3 2567constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d
GK
2568{
2569 switch (GET_CODE(op))
2570 {
2571 case SYMBOL_REF:
c4501e62
JJ
2572 if (RS6000_SYMBOL_REF_TLS_P (op))
2573 return 0;
2574 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2575 {
2576 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2577 {
2578 *have_sym = 1;
2579 return 1;
2580 }
2581 else
2582 return 0;
2583 }
2584 else if (! strcmp (XSTR (op, 0), toc_label_name))
2585 {
2586 *have_toc = 1;
2587 return 1;
2588 }
2589 else
2590 return 0;
9ebbca7d
GK
2591 case PLUS:
2592 case MINUS:
c1f11548
DE
2593 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2594 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2595 case CONST:
a4f6c312 2596 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2597 case CONST_INT:
a4f6c312 2598 return 1;
9ebbca7d 2599 default:
a4f6c312 2600 return 0;
9ebbca7d
GK
2601 }
2602}
2603
4d588c14 2604static bool
a2369ed3 2605constant_pool_expr_p (rtx op)
9ebbca7d
GK
2606{
2607 int have_sym = 0;
2608 int have_toc = 0;
2609 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2610}
2611
4d588c14 2612static bool
a2369ed3 2613toc_relative_expr_p (rtx op)
9ebbca7d 2614{
4d588c14
RH
2615 int have_sym = 0;
2616 int have_toc = 0;
2617 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2618}
2619
2620/* SPE offset addressing is limited to 5-bits worth of double words. */
2621#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2622
2623bool
a2369ed3 2624legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
2625{
2626 return (TARGET_TOC
2627 && GET_CODE (x) == PLUS
2628 && GET_CODE (XEXP (x, 0)) == REG
2629 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2630 && constant_pool_expr_p (XEXP (x, 1)));
2631}
2632
2633static bool
a2369ed3 2634legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
2635{
2636 return (DEFAULT_ABI == ABI_V4
2637 && !flag_pic && !TARGET_TOC
2638 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2639 && small_data_operand (x, mode));
2640}
2641
2642static bool
a2369ed3 2643legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2644{
2645 unsigned HOST_WIDE_INT offset, extra;
2646
2647 if (GET_CODE (x) != PLUS)
2648 return false;
2649 if (GET_CODE (XEXP (x, 0)) != REG)
2650 return false;
2651 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2652 return false;
2653 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2654 return false;
2655
2656 offset = INTVAL (XEXP (x, 1));
2657 extra = 0;
2658 switch (mode)
2659 {
2660 case V16QImode:
2661 case V8HImode:
2662 case V4SFmode:
2663 case V4SImode:
2664 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2665 which leaves the only valid constant offset of zero, which by
2666 canonicalization rules is also invalid. */
2667 return false;
2668
2669 case V4HImode:
2670 case V2SImode:
2671 case V1DImode:
2672 case V2SFmode:
2673 /* SPE vector modes. */
2674 return SPE_CONST_OFFSET_OK (offset);
2675
2676 case DFmode:
2677 case DImode:
3364872d 2678 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
2679 extra = 4;
2680 else if (offset & 3)
2681 return false;
2682 break;
2683
2684 case TFmode:
2685 case TImode:
3364872d 2686 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
2687 extra = 12;
2688 else if (offset & 3)
2689 return false;
2690 else
2691 extra = 8;
2692 break;
2693
2694 default:
2695 break;
2696 }
2697
b1917422
AM
2698 offset += 0x8000;
2699 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
2700}
2701
2702static bool
a2369ed3 2703legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
2704{
2705 rtx op0, op1;
2706
2707 if (GET_CODE (x) != PLUS)
2708 return false;
2709 op0 = XEXP (x, 0);
2710 op1 = XEXP (x, 1);
2711
2712 if (!REG_P (op0) || !REG_P (op1))
2713 return false;
2714
2715 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2716 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2717 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2718 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2719}
2720
4d588c14 2721static inline bool
a2369ed3 2722legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
2723{
2724 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2725}
2726
4c81e946
FJ
2727static bool
2728macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
2729{
2730 if (!TARGET_MACHO || !flag_pic
2731 || mode != SImode || GET_CODE(x) != MEM)
2732 return false;
2733 x = XEXP (x, 0);
2734
2735 if (GET_CODE (x) != LO_SUM)
2736 return false;
2737 if (GET_CODE (XEXP (x, 0)) != REG)
2738 return false;
2739 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
2740 return false;
2741 x = XEXP (x, 1);
2742
2743 return CONSTANT_P (x);
2744}
2745
4d588c14 2746static bool
a2369ed3 2747legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2748{
2749 if (GET_CODE (x) != LO_SUM)
2750 return false;
2751 if (GET_CODE (XEXP (x, 0)) != REG)
2752 return false;
2753 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2754 return false;
2755 x = XEXP (x, 1);
2756
8622e235 2757 if (TARGET_ELF || TARGET_MACHO)
4d588c14 2758 {
a29077da 2759 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
2760 return false;
2761 if (TARGET_TOC)
2762 return false;
2763 if (GET_MODE_NUNITS (mode) != 1)
2764 return false;
2765 if (GET_MODE_BITSIZE (mode) > 32
2766 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2767 return false;
2768
2769 return CONSTANT_P (x);
2770 }
2771
2772 return false;
2773}
2774
2775
9ebbca7d
GK
2776/* Try machine-dependent ways of modifying an illegitimate address
2777 to be legitimate. If we find one, return the new, valid address.
2778 This is used from only one place: `memory_address' in explow.c.
2779
a4f6c312
SS
2780 OLDX is the address as it was before break_out_memory_refs was
2781 called. In some cases it is useful to look at this to decide what
2782 needs to be done.
9ebbca7d 2783
a4f6c312 2784 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2785
a4f6c312
SS
2786 It is always safe for this function to do nothing. It exists to
2787 recognize opportunities to optimize the output.
9ebbca7d
GK
2788
2789 On RS/6000, first check for the sum of a register with a constant
2790 integer that is out of range. If so, generate code to add the
2791 constant with the low-order 16 bits masked to the register and force
2792 this result into another register (this can be done with `cau').
2793 Then generate an address of REG+(CONST&0xffff), allowing for the
2794 possibility of bit 16 being a one.
2795
2796 Then check for the sum of a register and something not constant, try to
2797 load the other things into a register and return the sum. */
4d588c14 2798
9ebbca7d 2799rtx
a2369ed3
DJ
2800rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2801 enum machine_mode mode)
0ac081f6 2802{
c4501e62
JJ
2803 if (GET_CODE (x) == SYMBOL_REF)
2804 {
2805 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2806 if (model != 0)
2807 return rs6000_legitimize_tls_address (x, model);
2808 }
2809
9ebbca7d
GK
2810 if (GET_CODE (x) == PLUS
2811 && GET_CODE (XEXP (x, 0)) == REG
2812 && GET_CODE (XEXP (x, 1)) == CONST_INT
2813 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2814 {
2815 HOST_WIDE_INT high_int, low_int;
2816 rtx sum;
a65c591c
DE
2817 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2818 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2819 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2820 GEN_INT (high_int)), 0);
2821 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2822 }
2823 else if (GET_CODE (x) == PLUS
2824 && GET_CODE (XEXP (x, 0)) == REG
2825 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2826 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2827 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2828 || TARGET_POWERPC64
fcce224d 2829 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2830 && (TARGET_POWERPC64 || mode != DImode)
2831 && mode != TImode)
2832 {
2833 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2834 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2835 }
0ac081f6
AH
2836 else if (ALTIVEC_VECTOR_MODE (mode))
2837 {
2838 rtx reg;
2839
2840 /* Make sure both operands are registers. */
2841 if (GET_CODE (x) == PLUS)
9f85ed45 2842 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2843 force_reg (Pmode, XEXP (x, 1)));
2844
2845 reg = force_reg (Pmode, x);
2846 return reg;
2847 }
a3170dc6
AH
2848 else if (SPE_VECTOR_MODE (mode))
2849 {
2850 /* We accept [reg + reg] and [reg + OFFSET]. */
2851
2852 if (GET_CODE (x) == PLUS)
2853 {
2854 rtx op1 = XEXP (x, 0);
2855 rtx op2 = XEXP (x, 1);
2856
2857 op1 = force_reg (Pmode, op1);
2858
2859 if (GET_CODE (op2) != REG
2860 && (GET_CODE (op2) != CONST_INT
2861 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2862 op2 = force_reg (Pmode, op2);
2863
2864 return gen_rtx_PLUS (Pmode, op1, op2);
2865 }
2866
2867 return force_reg (Pmode, x);
2868 }
f1384257
AM
2869 else if (TARGET_ELF
2870 && TARGET_32BIT
2871 && TARGET_NO_TOC
2872 && ! flag_pic
9ebbca7d
GK
2873 && GET_CODE (x) != CONST_INT
2874 && GET_CODE (x) != CONST_DOUBLE
2875 && CONSTANT_P (x)
6ac7bf2c
GK
2876 && GET_MODE_NUNITS (mode) == 1
2877 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2878 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2879 {
2880 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2881 emit_insn (gen_elf_high (reg, x));
2882 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 2883 }
ee890fe2
SS
2884 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2885 && ! flag_pic
ab82a49f
AP
2886#if TARGET_MACHO
2887 && ! MACHO_DYNAMIC_NO_PIC_P
2888#endif
ee890fe2
SS
2889 && GET_CODE (x) != CONST_INT
2890 && GET_CODE (x) != CONST_DOUBLE
2891 && CONSTANT_P (x)
a3170dc6 2892 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2893 && mode != DImode
2894 && mode != TImode)
2895 {
2896 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2897 emit_insn (gen_macho_high (reg, x));
2898 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 2899 }
9ebbca7d 2900 else if (TARGET_TOC
4d588c14 2901 && constant_pool_expr_p (x)
a9098fd0 2902 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2903 {
2904 return create_TOC_reference (x);
2905 }
2906 else
2907 return NULL_RTX;
2908}
258bfae2 2909
c973d557
JJ
2910/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
2911 We need to emit DTP-relative relocations. */
2912
2913void
2914rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
2915{
2916 switch (size)
2917 {
2918 case 4:
2919 fputs ("\t.long\t", file);
2920 break;
2921 case 8:
2922 fputs (DOUBLE_INT_ASM_OP, file);
2923 break;
2924 default:
2925 abort ();
2926 }
2927 output_addr_const (file, x);
2928 fputs ("@dtprel+0x8000", file);
2929}
2930
c4501e62
JJ
2931/* Construct the SYMBOL_REF for the tls_get_addr function. */
2932
2933static GTY(()) rtx rs6000_tls_symbol;
2934static rtx
863d938c 2935rs6000_tls_get_addr (void)
c4501e62
JJ
2936{
2937 if (!rs6000_tls_symbol)
2938 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2939
2940 return rs6000_tls_symbol;
2941}
2942
2943/* Construct the SYMBOL_REF for TLS GOT references. */
2944
2945static GTY(()) rtx rs6000_got_symbol;
2946static rtx
863d938c 2947rs6000_got_sym (void)
c4501e62
JJ
2948{
2949 if (!rs6000_got_symbol)
2950 {
2951 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2952 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2953 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2954 }
2955
2956 return rs6000_got_symbol;
2957}
2958
2959/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2960 this (thread-local) address. */
2961
2962static rtx
a2369ed3 2963rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
2964{
2965 rtx dest, insn;
2966
2967 dest = gen_reg_rtx (Pmode);
2968 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2969 {
2970 rtx tlsreg;
2971
2972 if (TARGET_64BIT)
2973 {
2974 tlsreg = gen_rtx_REG (Pmode, 13);
2975 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2976 }
2977 else
2978 {
2979 tlsreg = gen_rtx_REG (Pmode, 2);
2980 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2981 }
2982 emit_insn (insn);
2983 }
2984 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2985 {
2986 rtx tlsreg, tmp;
2987
2988 tmp = gen_reg_rtx (Pmode);
2989 if (TARGET_64BIT)
2990 {
2991 tlsreg = gen_rtx_REG (Pmode, 13);
2992 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2993 }
2994 else
2995 {
2996 tlsreg = gen_rtx_REG (Pmode, 2);
2997 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2998 }
2999 emit_insn (insn);
3000 if (TARGET_64BIT)
3001 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3002 else
3003 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3004 emit_insn (insn);
3005 }
3006 else
3007 {
3008 rtx r3, got, tga, tmp1, tmp2, eqv;
3009
3010 if (TARGET_64BIT)
3011 got = gen_rtx_REG (Pmode, TOC_REGISTER);
3012 else
3013 {
3014 if (flag_pic == 1)
3015 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3016 else
3017 {
3018 rtx gsym = rs6000_got_sym ();
3019 got = gen_reg_rtx (Pmode);
3020 if (flag_pic == 0)
3021 rs6000_emit_move (got, gsym, Pmode);
3022 else
3023 {
3024 char buf[30];
3025 static int tls_got_labelno = 0;
3026 rtx tempLR, lab, tmp3, mem;
3027 rtx first, last;
3028
3029 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
3030 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
3031 tempLR = gen_reg_rtx (Pmode);
3032 tmp1 = gen_reg_rtx (Pmode);
3033 tmp2 = gen_reg_rtx (Pmode);
3034 tmp3 = gen_reg_rtx (Pmode);
3035 mem = gen_rtx_MEM (Pmode, tmp1);
3036 RTX_UNCHANGING_P (mem) = 1;
3037
3038 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
3039 gsym));
3040 emit_move_insn (tmp1, tempLR);
3041 emit_move_insn (tmp2, mem);
3042 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
3043 last = emit_move_insn (got, tmp3);
3044 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
3045 REG_NOTES (last));
3046 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3047 REG_NOTES (first));
3048 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3049 REG_NOTES (last));
3050 }
3051 }
3052 }
3053
3054 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3055 {
3056 r3 = gen_rtx_REG (Pmode, 3);
3057 if (TARGET_64BIT)
3058 insn = gen_tls_gd_64 (r3, got, addr);
3059 else
3060 insn = gen_tls_gd_32 (r3, got, addr);
3061 start_sequence ();
3062 emit_insn (insn);
3063 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3064 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3065 insn = emit_call_insn (insn);
3066 CONST_OR_PURE_CALL_P (insn) = 1;
3067 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3068 insn = get_insns ();
3069 end_sequence ();
3070 emit_libcall_block (insn, dest, r3, addr);
3071 }
3072 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3073 {
3074 r3 = gen_rtx_REG (Pmode, 3);
3075 if (TARGET_64BIT)
3076 insn = gen_tls_ld_64 (r3, got);
3077 else
3078 insn = gen_tls_ld_32 (r3, got);
3079 start_sequence ();
3080 emit_insn (insn);
3081 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3082 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3083 insn = emit_call_insn (insn);
3084 CONST_OR_PURE_CALL_P (insn) = 1;
3085 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3086 insn = get_insns ();
3087 end_sequence ();
3088 tmp1 = gen_reg_rtx (Pmode);
3089 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3090 UNSPEC_TLSLD);
3091 emit_libcall_block (insn, tmp1, r3, eqv);
3092 if (rs6000_tls_size == 16)
3093 {
3094 if (TARGET_64BIT)
3095 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3096 else
3097 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3098 }
3099 else if (rs6000_tls_size == 32)
3100 {
3101 tmp2 = gen_reg_rtx (Pmode);
3102 if (TARGET_64BIT)
3103 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3104 else
3105 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3106 emit_insn (insn);
3107 if (TARGET_64BIT)
3108 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3109 else
3110 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3111 }
3112 else
3113 {
3114 tmp2 = gen_reg_rtx (Pmode);
3115 if (TARGET_64BIT)
3116 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3117 else
3118 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3119 emit_insn (insn);
3120 insn = gen_rtx_SET (Pmode, dest,
3121 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3122 }
3123 emit_insn (insn);
3124 }
3125 else
3126 {
3127 /* IE, or 64 bit offset LE. */
3128 tmp2 = gen_reg_rtx (Pmode);
3129 if (TARGET_64BIT)
3130 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3131 else
3132 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3133 emit_insn (insn);
3134 if (TARGET_64BIT)
3135 insn = gen_tls_tls_64 (dest, tmp2, addr);
3136 else
3137 insn = gen_tls_tls_32 (dest, tmp2, addr);
3138 emit_insn (insn);
3139 }
3140 }
3141
3142 return dest;
3143}
3144
3145/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3146 instruction definitions. */
3147
3148int
a2369ed3 3149rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3150{
3151 return RS6000_SYMBOL_REF_TLS_P (x);
3152}
3153
3154/* Return 1 if X contains a thread-local symbol. */
3155
3156bool
a2369ed3 3157rs6000_tls_referenced_p (rtx x)
c4501e62 3158{
cd413cab
AP
3159 if (! TARGET_HAVE_TLS)
3160 return false;
3161
c4501e62
JJ
3162 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3163}
3164
3165/* Return 1 if *X is a thread-local symbol. This is the same as
3166 rs6000_tls_symbol_ref except for the type of the unused argument. */
3167
3168static inline int
a2369ed3 3169rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3170{
3171 return RS6000_SYMBOL_REF_TLS_P (*x);
3172}
3173
24ea750e
DJ
3174/* The convention appears to be to define this wherever it is used.
3175 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3176 is now used here. */
3177#ifndef REG_MODE_OK_FOR_BASE_P
3178#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3179#endif
3180
3181/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3182 replace the input X, or the original X if no replacement is called for.
3183 The output parameter *WIN is 1 if the calling macro should goto WIN,
3184 0 if it should not.
3185
3186 For RS/6000, we wish to handle large displacements off a base
3187 register by splitting the addend across an addiu/addis and the mem insn.
3188 This cuts number of extra insns needed from 3 to 1.
3189
3190 On Darwin, we use this to generate code for floating point constants.
3191 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3192 The Darwin code is inside #if TARGET_MACHO because only then is
3193 machopic_function_base_name() defined. */
3194rtx
a2369ed3
DJ
3195rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
3196 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e
DJ
3197{
3198 /* We must recognize output that we have already generated ourselves. */
3199 if (GET_CODE (x) == PLUS
3200 && GET_CODE (XEXP (x, 0)) == PLUS
3201 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3202 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3203 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3204 {
3205 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3206 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3207 opnum, (enum reload_type)type);
3208 *win = 1;
3209 return x;
3210 }
3deb2758 3211
24ea750e
DJ
3212#if TARGET_MACHO
3213 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3214 && GET_CODE (x) == LO_SUM
3215 && GET_CODE (XEXP (x, 0)) == PLUS
3216 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3217 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3218 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3219 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3220 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3221 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3222 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3223 {
3224 /* Result of previous invocation of this function on Darwin
6f317ef3 3225 floating point constant. */
24ea750e
DJ
3226 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3227 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3228 opnum, (enum reload_type)type);
3229 *win = 1;
3230 return x;
3231 }
3232#endif
3233 if (GET_CODE (x) == PLUS
3234 && GET_CODE (XEXP (x, 0)) == REG
3235 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3236 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3237 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3238 && !SPE_VECTOR_MODE (mode)
78c875e8 3239 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3240 {
3241 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3242 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3243 HOST_WIDE_INT high
3244 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3245
3246 /* Check for 32-bit overflow. */
3247 if (high + low != val)
3248 {
3249 *win = 0;
3250 return x;
3251 }
3252
3253 /* Reload the high part into a base reg; leave the low part
3254 in the mem directly. */
3255
3256 x = gen_rtx_PLUS (GET_MODE (x),
3257 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3258 GEN_INT (high)),
3259 GEN_INT (low));
3260
3261 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3262 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3263 opnum, (enum reload_type)type);
3264 *win = 1;
3265 return x;
3266 }
3267#if TARGET_MACHO
3268 if (GET_CODE (x) == SYMBOL_REF
3269 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3270 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3271 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3272 /* Don't do this for TFmode, since the result isn't offsettable. */
3273 && mode != TFmode)
24ea750e 3274 {
a29077da
GK
3275 if (flag_pic)
3276 {
3277 rtx offset = gen_rtx_CONST (Pmode,
3278 gen_rtx_MINUS (Pmode, x,
3279 gen_rtx_SYMBOL_REF (Pmode,
3280 machopic_function_base_name ())));
3281 x = gen_rtx_LO_SUM (GET_MODE (x),
3282 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3283 gen_rtx_HIGH (Pmode, offset)), offset);
3284 }
3285 else
3286 x = gen_rtx_LO_SUM (GET_MODE (x),
3287 gen_rtx_HIGH (Pmode, x), x);
3288
24ea750e 3289 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3290 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3291 opnum, (enum reload_type)type);
24ea750e
DJ
3292 *win = 1;
3293 return x;
3294 }
3295#endif
3296 if (TARGET_TOC
4d588c14 3297 && constant_pool_expr_p (x)
c1f11548 3298 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3299 {
3300 (x) = create_TOC_reference (x);
3301 *win = 1;
3302 return x;
3303 }
3304 *win = 0;
3305 return x;
3306}
3307
258bfae2
FS
3308/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3309 that is a valid memory address for an instruction.
3310 The MODE argument is the machine mode for the MEM expression
3311 that wants to use this address.
3312
3313 On the RS/6000, there are four valid address: a SYMBOL_REF that
3314 refers to a constant pool entry of an address (or the sum of it
3315 plus a constant), a short (16-bit signed) constant plus a register,
3316 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3317 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3318 we must ensure that both words are addressable or PowerPC64 with offset
3319 word aligned.
3320
3321 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3322 32-bit DImode, TImode), indexed addressing cannot be used because
3323 adjacent memory cells are accessed by adding word-sized offsets
3324 during assembly output. */
3325int
a2369ed3 3326rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3327{
c4501e62
JJ
3328 if (RS6000_SYMBOL_REF_TLS_P (x))
3329 return 0;
4d588c14 3330 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3331 return 1;
3332 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3333 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3334 && !SPE_VECTOR_MODE (mode)
258bfae2 3335 && TARGET_UPDATE
4d588c14 3336 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3337 return 1;
4d588c14 3338 if (legitimate_small_data_p (mode, x))
258bfae2 3339 return 1;
4d588c14 3340 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3341 return 1;
3342 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3343 if (! reg_ok_strict
3344 && GET_CODE (x) == PLUS
3345 && GET_CODE (XEXP (x, 0)) == REG
708d2456
HP
3346 && (XEXP (x, 0) == virtual_stack_vars_rtx
3347 || XEXP (x, 0) == arg_pointer_rtx)
258bfae2
FS
3348 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3349 return 1;
4d588c14 3350 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3351 return 1;
3352 if (mode != TImode
a3170dc6
AH
3353 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3354 || TARGET_POWERPC64
fcce224d 3355 || (mode != DFmode && mode != TFmode))
258bfae2 3356 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3357 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3358 return 1;
4d588c14 3359 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3360 return 1;
3361 return 0;
3362}
4d588c14
RH
3363
3364/* Go to LABEL if ADDR (a legitimate address expression)
3365 has an effect that depends on the machine mode it is used for.
3366
3367 On the RS/6000 this is true of all integral offsets (since AltiVec
3368 modes don't allow them) or is a pre-increment or decrement.
3369
3370 ??? Except that due to conceptual problems in offsettable_address_p
3371 we can't really report the problems of integral offsets. So leave
3372 this assuming that the adjustable offset must be valid for the
3373 sub-words of a TFmode operand, which is what we had before. */
3374
3375bool
a2369ed3 3376rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3377{
3378 switch (GET_CODE (addr))
3379 {
3380 case PLUS:
3381 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3382 {
3383 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3384 return val + 12 + 0x8000 >= 0x10000;
3385 }
3386 break;
3387
3388 case LO_SUM:
3389 return true;
3390
3391 case PRE_INC:
3392 case PRE_DEC:
3393 return TARGET_UPDATE;
3394
3395 default:
3396 break;
3397 }
3398
3399 return false;
3400}
d8ecbcdb
AH
3401
3402/* Return number of consecutive hard regs needed starting at reg REGNO
3403 to hold something of mode MODE.
3404 This is ordinarily the length in words of a value of mode MODE
3405 but can be less for certain modes in special long registers.
3406
3407 For the SPE, GPRs are 64 bits but only 32 bits are visible in
3408 scalar instructions. The upper 32 bits are only available to the
3409 SIMD instructions.
3410
3411 POWER and PowerPC GPRs hold 32 bits worth;
3412 PowerPC64 GPRs and FPRs point register holds 64 bits worth. */
3413
3414int
3415rs6000_hard_regno_nregs (int regno, enum machine_mode mode)
3416{
3417 if (FP_REGNO_P (regno))
3418 return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD;
3419
3420 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
3421 return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD;
3422
3423 if (ALTIVEC_REGNO_P (regno))
3424 return
3425 (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD;
3426
3427 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3428}
2aa4498c
AH
3429
3430/* Change register usage conditional on target flags. */
3431void
3432rs6000_conditional_register_usage (void)
3433{
3434 int i;
3435
3436 /* Set MQ register fixed (already call_used) if not POWER
3437 architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not
3438 be allocated. */
3439 if (! TARGET_POWER)
3440 fixed_regs[64] = 1;
3441
3442 /* 64-bit AIX reserves GPR13 for thread-private data. */
3443 if (TARGET_64BIT)
3444 fixed_regs[13] = call_used_regs[13]
3445 = call_really_used_regs[13] = 1;
3446
3447 /* Conditionally disable FPRs. */
3448 if (TARGET_SOFT_FLOAT || !TARGET_FPRS)
3449 for (i = 32; i < 64; i++)
3450 fixed_regs[i] = call_used_regs[i]
3451 = call_really_used_regs[i] = 1;
3452
3453 if (DEFAULT_ABI == ABI_V4
3454 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3455 && flag_pic == 2)
3456 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3457
3458 if (DEFAULT_ABI == ABI_V4
3459 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3460 && flag_pic == 1)
3461 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3462 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3463 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3464
3465 if (DEFAULT_ABI == ABI_DARWIN
3466 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
3467 global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3468 = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3469 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3470 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3471
3472 if (TARGET_ALTIVEC)
3473 global_regs[VSCR_REGNO] = 1;
3474
3475 if (TARGET_SPE)
3476 {
3477 global_regs[SPEFSCR_REGNO] = 1;
3478 fixed_regs[FIXED_SCRATCH]
3479 = call_used_regs[FIXED_SCRATCH]
3480 = call_really_used_regs[FIXED_SCRATCH] = 1;
3481 }
3482
3483 if (! TARGET_ALTIVEC)
3484 {
3485 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
3486 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
3487 call_really_used_regs[VRSAVE_REGNO] = 1;
3488 }
3489
3490 if (TARGET_ALTIVEC_ABI)
3491 for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i)
3492 call_used_regs[i] = call_really_used_regs[i] = 1;
3493}
fb4d4348 3494\f
a4f6c312
SS
3495/* Try to output insns to set TARGET equal to the constant C if it can
3496 be done in less than N insns. Do all computations in MODE.
3497 Returns the place where the output has been placed if it can be
3498 done and the insns have been emitted. If it would take more than N
3499 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3500
3501rtx
a2369ed3
DJ
3502rs6000_emit_set_const (rtx dest, enum machine_mode mode,
3503 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3504{
af8cb5c5 3505 rtx result, insn, set;
2bfcf297
DB
3506 HOST_WIDE_INT c0, c1;
3507
af8cb5c5 3508 if (mode == QImode || mode == HImode)
2bfcf297
DB
3509 {
3510 if (dest == NULL)
3511 dest = gen_reg_rtx (mode);
3512 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3513 return dest;
3514 }
af8cb5c5 3515 else if (mode == SImode)
2bfcf297 3516 {
af8cb5c5
DE
3517 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3518
3519 emit_insn (gen_rtx_SET (VOIDmode, result,
3520 GEN_INT (INTVAL (source)
3521 & (~ (HOST_WIDE_INT) 0xffff))));
3522 emit_insn (gen_rtx_SET (VOIDmode, dest,
3523 gen_rtx_IOR (SImode, result,
3524 GEN_INT (INTVAL (source) & 0xffff))));
3525 result = dest;
2bfcf297 3526 }
af8cb5c5 3527 else if (mode == DImode)
2bfcf297 3528 {
af8cb5c5
DE
3529 if (GET_CODE (source) == CONST_INT)
3530 {
3531 c0 = INTVAL (source);
3532 c1 = -(c0 < 0);
3533 }
3534 else if (GET_CODE (source) == CONST_DOUBLE)
3535 {
2bfcf297 3536#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3537 c0 = CONST_DOUBLE_LOW (source);
3538 c1 = -(c0 < 0);
2bfcf297 3539#else
af8cb5c5
DE
3540 c0 = CONST_DOUBLE_LOW (source);
3541 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3542#endif
af8cb5c5
DE
3543 }
3544 else
3545 abort ();
3546
3547 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3548 }
3549 else
a4f6c312 3550 abort ();
2bfcf297 3551
af8cb5c5
DE
3552 insn = get_last_insn ();
3553 set = single_set (insn);
3554 if (! CONSTANT_P (SET_SRC (set)))
3555 set_unique_reg_note (insn, REG_EQUAL, source);
3556
3557 return result;
2bfcf297
DB
3558}
3559
3560/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3561 fall back to a straight forward decomposition. We do this to avoid
3562 exponential run times encountered when looking for longer sequences
3563 with rs6000_emit_set_const. */
3564static rtx
a2369ed3 3565rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
3566{
3567 if (!TARGET_POWERPC64)
3568 {
3569 rtx operand1, operand2;
3570
3571 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3572 DImode);
3573 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3574 DImode);
3575 emit_move_insn (operand1, GEN_INT (c1));
3576 emit_move_insn (operand2, GEN_INT (c2));
3577 }
3578 else
3579 {
bc06712d 3580 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3581
bc06712d 3582 ud1 = c1 & 0xffff;
f921c9c9 3583 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3584#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3585 c2 = c1 >> 32;
2bfcf297 3586#endif
bc06712d 3587 ud3 = c2 & 0xffff;
f921c9c9 3588 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3589
bc06712d
TR
3590 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3591 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3592 {
bc06712d 3593 if (ud1 & 0x8000)
b78d48dd 3594 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
3595 else
3596 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3597 }
2bfcf297 3598
bc06712d
TR
3599 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3600 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3601 {
bc06712d
TR
3602 if (ud2 & 0x8000)
3603 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3604 - 0x80000000));
252b88f7 3605 else
bc06712d
TR
3606 emit_move_insn (dest, GEN_INT (ud2 << 16));
3607 if (ud1 != 0)
3608 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3609 }
bc06712d
TR
3610 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3611 || (ud4 == 0 && ! (ud3 & 0x8000)))
3612 {
3613 if (ud3 & 0x8000)
3614 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3615 - 0x80000000));
3616 else
3617 emit_move_insn (dest, GEN_INT (ud3 << 16));
3618
3619 if (ud2 != 0)
3620 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3621 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3622 if (ud1 != 0)
3623 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3624 }
3625 else
3626 {
3627 if (ud4 & 0x8000)
3628 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3629 - 0x80000000));
3630 else
3631 emit_move_insn (dest, GEN_INT (ud4 << 16));
3632
3633 if (ud3 != 0)
3634 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3635
bc06712d
TR
3636 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3637 if (ud2 != 0)
3638 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3639 GEN_INT (ud2 << 16)));
3640 if (ud1 != 0)
3641 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3642 }
3643 }
2bfcf297
DB
3644 return dest;
3645}
3646
fb4d4348
GK
3647/* Emit a move from SOURCE to DEST in mode MODE. */
3648void
a2369ed3 3649rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
3650{
3651 rtx operands[2];
3652 operands[0] = dest;
3653 operands[1] = source;
3654
3655 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3656 if (GET_CODE (operands[1]) == CONST_DOUBLE
3657 && ! FLOAT_MODE_P (mode)
3658 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3659 {
3660 /* FIXME. This should never happen. */
3661 /* Since it seems that it does, do the safe thing and convert
3662 to a CONST_INT. */
2496c7bd 3663 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3664 }
3665 if (GET_CODE (operands[1]) == CONST_DOUBLE
3666 && ! FLOAT_MODE_P (mode)
3667 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3668 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3669 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3670 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3671 abort ();
c9e8cb32
DD
3672
3673 /* Check if GCC is setting up a block move that will end up using FP
3674 registers as temporaries. We must make sure this is acceptable. */
3675 if (GET_CODE (operands[0]) == MEM
3676 && GET_CODE (operands[1]) == MEM
3677 && mode == DImode
41543739
GK
3678 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3679 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3680 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3681 ? 32 : MEM_ALIGN (operands[0])))
3682 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3683 ? 32
3684 : MEM_ALIGN (operands[1]))))
3685 && ! MEM_VOLATILE_P (operands [0])
3686 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3687 {
41543739
GK
3688 emit_move_insn (adjust_address (operands[0], SImode, 0),
3689 adjust_address (operands[1], SImode, 0));
3690 emit_move_insn (adjust_address (operands[0], SImode, 4),
3691 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3692 return;
3693 }
630d42a0 3694
67cef334
DE
3695 if (!no_new_pseudos)
3696 {
3697 if (GET_CODE (operands[1]) == MEM && optimize > 0
3698 && (mode == QImode || mode == HImode || mode == SImode)
3699 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3700 {
3701 rtx reg = gen_reg_rtx (word_mode);
3702
3703 emit_insn (gen_rtx_SET (word_mode, reg,
3704 gen_rtx_ZERO_EXTEND (word_mode,
3705 operands[1])));
3706 operands[1] = gen_lowpart (mode, reg);
3707 }
3708 if (GET_CODE (operands[0]) != REG)
3709 operands[1] = force_reg (mode, operands[1]);
3710 }
a9098fd0 3711
a3170dc6
AH
3712 if (mode == SFmode && ! TARGET_POWERPC
3713 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3714 && GET_CODE (operands[0]) == MEM)
fb4d4348 3715 {
ffc14f31
GK
3716 int regnum;
3717
3718 if (reload_in_progress || reload_completed)
3719 regnum = true_regnum (operands[1]);
3720 else if (GET_CODE (operands[1]) == REG)
3721 regnum = REGNO (operands[1]);
3722 else
3723 regnum = -1;
fb4d4348
GK
3724
3725 /* If operands[1] is a register, on POWER it may have
3726 double-precision data in it, so truncate it to single
3727 precision. */
3728 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3729 {
3730 rtx newreg;
3731 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3732 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3733 operands[1] = newreg;
3734 }
3735 }
3736
c4501e62
JJ
3737 /* Recognize the case where operand[1] is a reference to thread-local
3738 data and load its address to a register. */
3739 if (GET_CODE (operands[1]) == SYMBOL_REF)
3740 {
3741 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3742 if (model != 0)
3743 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3744 }
3745
8f4e6caf
RH
3746 /* Handle the case where reload calls us with an invalid address. */
3747 if (reload_in_progress && mode == Pmode
69ef87e2 3748 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3749 || ! nonimmediate_operand (operands[0], mode)))
3750 goto emit_set;
3751
a9baceb1
GK
3752 /* 128-bit constant floating-point values on Darwin should really be
3753 loaded as two parts. */
3754 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
3755 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
3756 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
3757 {
3758 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
3759 know how to get a DFmode SUBREG of a TFmode. */
3760 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
3761 simplify_gen_subreg (DImode, operands[1], mode, 0),
3762 DImode);
3763 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
3764 GET_MODE_SIZE (DImode)),
3765 simplify_gen_subreg (DImode, operands[1], mode,
3766 GET_MODE_SIZE (DImode)),
3767 DImode);
3768 return;
3769 }
3770
fb4d4348
GK
3771 /* FIXME: In the long term, this switch statement should go away
3772 and be replaced by a sequence of tests based on things like
3773 mode == Pmode. */
3774 switch (mode)
3775 {
3776 case HImode:
3777 case QImode:
3778 if (CONSTANT_P (operands[1])
3779 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3780 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3781 break;
3782
06f4e019 3783 case TFmode:
fb4d4348
GK
3784 case DFmode:
3785 case SFmode:
3786 if (CONSTANT_P (operands[1])
3787 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3788 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3789 break;
3790
0ac081f6
AH
3791 case V16QImode:
3792 case V8HImode:
3793 case V4SFmode:
3794 case V4SImode:
a3170dc6
AH
3795 case V4HImode:
3796 case V2SFmode:
3797 case V2SImode:
00a892b8 3798 case V1DImode:
69ef87e2 3799 if (CONSTANT_P (operands[1])
d744e06e 3800 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3801 operands[1] = force_const_mem (mode, operands[1]);
3802 break;
3803
fb4d4348 3804 case SImode:
a9098fd0 3805 case DImode:
fb4d4348
GK
3806 /* Use default pattern for address of ELF small data */
3807 if (TARGET_ELF
a9098fd0 3808 && mode == Pmode
f607bc57 3809 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3810 && (GET_CODE (operands[1]) == SYMBOL_REF
3811 || GET_CODE (operands[1]) == CONST)
3812 && small_data_operand (operands[1], mode))
fb4d4348
GK
3813 {
3814 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3815 return;
3816 }
3817
f607bc57 3818 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3819 && mode == Pmode && mode == SImode
3820 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3821 {
3822 emit_insn (gen_movsi_got (operands[0], operands[1]));
3823 return;
3824 }
3825
ee890fe2 3826 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3827 && TARGET_NO_TOC
3828 && ! flag_pic
a9098fd0 3829 && mode == Pmode
fb4d4348
GK
3830 && CONSTANT_P (operands[1])
3831 && GET_CODE (operands[1]) != HIGH
3832 && GET_CODE (operands[1]) != CONST_INT)
3833 {
a9098fd0 3834 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3835
3836 /* If this is a function address on -mcall-aixdesc,
3837 convert it to the address of the descriptor. */
3838 if (DEFAULT_ABI == ABI_AIX
3839 && GET_CODE (operands[1]) == SYMBOL_REF
3840 && XSTR (operands[1], 0)[0] == '.')
3841 {
3842 const char *name = XSTR (operands[1], 0);
3843 rtx new_ref;
3844 while (*name == '.')
3845 name++;
3846 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3847 CONSTANT_POOL_ADDRESS_P (new_ref)
3848 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3849 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3850 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3851 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3852 operands[1] = new_ref;
3853 }
7509c759 3854
ee890fe2
SS
3855 if (DEFAULT_ABI == ABI_DARWIN)
3856 {
ab82a49f
AP
3857#if TARGET_MACHO
3858 if (MACHO_DYNAMIC_NO_PIC_P)
3859 {
3860 /* Take care of any required data indirection. */
3861 operands[1] = rs6000_machopic_legitimize_pic_address (
3862 operands[1], mode, operands[0]);
3863 if (operands[0] != operands[1])
3864 emit_insn (gen_rtx_SET (VOIDmode,
3865 operands[0], operands[1]));
3866 return;
3867 }
3868#endif
ee890fe2
SS
3869 emit_insn (gen_macho_high (target, operands[1]));
3870 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3871 return;
3872 }
3873
fb4d4348
GK
3874 emit_insn (gen_elf_high (target, operands[1]));
3875 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3876 return;
3877 }
3878
a9098fd0
GK
3879 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3880 and we have put it in the TOC, we just need to make a TOC-relative
3881 reference to it. */
3882 if (TARGET_TOC
3883 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3884 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3885 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3886 get_pool_mode (operands[1])))
fb4d4348 3887 {
a9098fd0 3888 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3889 }
a9098fd0
GK
3890 else if (mode == Pmode
3891 && CONSTANT_P (operands[1])
38886f37
AO
3892 && ((GET_CODE (operands[1]) != CONST_INT
3893 && ! easy_fp_constant (operands[1], mode))
3894 || (GET_CODE (operands[1]) == CONST_INT
3895 && num_insns_constant (operands[1], mode) > 2)
3896 || (GET_CODE (operands[0]) == REG
3897 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3898 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3899 && ! legitimate_constant_pool_address_p (operands[1])
3900 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3901 {
3902 /* Emit a USE operation so that the constant isn't deleted if
3903 expensive optimizations are turned on because nobody
3904 references it. This should only be done for operands that
3905 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3906 This should not be done for operands that contain LABEL_REFs.
3907 For now, we just handle the obvious case. */
3908 if (GET_CODE (operands[1]) != LABEL_REF)
3909 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3910
c859cda6 3911#if TARGET_MACHO
ee890fe2 3912 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3913 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3914 {
ee890fe2
SS
3915 operands[1] =
3916 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3917 operands[0]);
3918 if (operands[0] != operands[1])
3919 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3920 return;
3921 }
c859cda6 3922#endif
ee890fe2 3923
fb4d4348
GK
3924 /* If we are to limit the number of things we put in the TOC and
3925 this is a symbol plus a constant we can add in one insn,
3926 just put the symbol in the TOC and add the constant. Don't do
3927 this if reload is in progress. */
3928 if (GET_CODE (operands[1]) == CONST
3929 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3930 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3931 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3932 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3933 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3934 && ! side_effects_p (operands[0]))
3935 {
a4f6c312
SS
3936 rtx sym =
3937 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3938 rtx other = XEXP (XEXP (operands[1], 0), 1);
3939
a9098fd0
GK
3940 sym = force_reg (mode, sym);
3941 if (mode == SImode)
3942 emit_insn (gen_addsi3 (operands[0], sym, other));
3943 else
3944 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3945 return;
3946 }
3947
a9098fd0 3948 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3949
3950 if (TARGET_TOC
4d588c14 3951 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3952 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3953 get_pool_constant (XEXP (operands[1], 0)),
3954 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3955 {
ba4828e0
RK
3956 operands[1]
3957 = gen_rtx_MEM (mode,
3958 create_TOC_reference (XEXP (operands[1], 0)));
3959 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3960 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3961 }
fb4d4348
GK
3962 }
3963 break;
a9098fd0 3964
fb4d4348
GK
3965 case TImode:
3966 if (GET_CODE (operands[0]) == MEM
3967 && GET_CODE (XEXP (operands[0], 0)) != REG
3968 && ! reload_in_progress)
792760b9
RK
3969 operands[0]
3970 = replace_equiv_address (operands[0],
3971 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3972
3973 if (GET_CODE (operands[1]) == MEM
3974 && GET_CODE (XEXP (operands[1], 0)) != REG
3975 && ! reload_in_progress)
792760b9
RK
3976 operands[1]
3977 = replace_equiv_address (operands[1],
3978 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3979 if (TARGET_POWER)
3980 {
3981 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3982 gen_rtvec (2,
3983 gen_rtx_SET (VOIDmode,
3984 operands[0], operands[1]),
3985 gen_rtx_CLOBBER (VOIDmode,
3986 gen_rtx_SCRATCH (SImode)))));
3987 return;
3988 }
fb4d4348
GK
3989 break;
3990
3991 default:
3992 abort ();
3993 }
3994
a9098fd0
GK
3995 /* Above, we may have called force_const_mem which may have returned
3996 an invalid address. If we can, fix this up; otherwise, reload will
3997 have to deal with it. */
8f4e6caf
RH
3998 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
3999 operands[1] = validize_mem (operands[1]);
a9098fd0 4000
8f4e6caf 4001 emit_set:
fb4d4348
GK
4002 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4003}
4697a36c 4004\f
2858f73a
GK
4005/* Nonzero if we can use a floating-point register to pass this arg. */
4006#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
4007 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
4008 && (CUM)->fregno <= FP_ARG_MAX_REG \
4009 && TARGET_HARD_FLOAT && TARGET_FPRS)
4010
4011/* Nonzero if we can use an AltiVec register to pass this arg. */
4012#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
4013 (ALTIVEC_VECTOR_MODE (MODE) \
4014 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
4015 && TARGET_ALTIVEC_ABI \
83953138 4016 && (NAMED))
2858f73a 4017
c6e8c921
GK
4018/* Return a nonzero value to say to return the function value in
4019 memory, just as large structures are always returned. TYPE will be
4020 the data type of the value, and FNTYPE will be the type of the
4021 function doing the returning, or @code{NULL} for libcalls.
4022
4023 The AIX ABI for the RS/6000 specifies that all structures are
4024 returned in memory. The Darwin ABI does the same. The SVR4 ABI
4025 specifies that structures <= 8 bytes are returned in r3/r4, but a
4026 draft put them in memory, and GCC used to implement the draft
4027 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
4028 controls this instead of DEFAULT_ABI; V.4 targets needing backward
4029 compatibility can change DRAFT_V4_STRUCT_RET to override the
4030 default, and -m switches get the final word. See
4031 rs6000_override_options for more details.
4032
4033 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
4034 long double support is enabled. These values are returned in memory.
4035
4036 int_size_in_bytes returns -1 for variable size objects, which go in
4037 memory always. The cast to unsigned makes -1 > 8. */
4038
4039static bool
4040rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4041{
4042 if (AGGREGATE_TYPE_P (type)
4043 && (TARGET_AIX_STRUCT_RET
4044 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
4045 return true;
4046 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
4047 return true;
4048 return false;
4049}
4050
4697a36c
MM
4051/* Initialize a variable CUM of type CUMULATIVE_ARGS
4052 for a call to a function whose data type is FNTYPE.
4053 For a library call, FNTYPE is 0.
4054
4055 For incoming args we set the number of arguments in the prototype large
1c20ae99 4056 so we never return a PARALLEL. */
4697a36c
MM
4057
4058void
a2369ed3 4059init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
4060 rtx libname ATTRIBUTE_UNUSED, int incoming,
4061 int libcall, int n_named_args)
4697a36c
MM
4062{
4063 static CUMULATIVE_ARGS zero_cumulative;
4064
4065 *cum = zero_cumulative;
4066 cum->words = 0;
4067 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 4068 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 4069 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
4070 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
4071 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 4072 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
4073 cum->stdarg = fntype
4074 && (TYPE_ARG_TYPES (fntype) != 0
4075 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4076 != void_type_node));
4697a36c 4077
0f6937fe
AM
4078 cum->nargs_prototype = 0;
4079 if (incoming || cum->prototype)
4080 cum->nargs_prototype = n_named_args;
4697a36c 4081
a5c76ee6
ZW
4082 /* Check for a longcall attribute. */
4083 if (fntype
4084 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
4085 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
4086 cum->call_cookie = CALL_LONG;
4087
4697a36c
MM
4088 if (TARGET_DEBUG_ARG)
4089 {
4090 fprintf (stderr, "\ninit_cumulative_args:");
4091 if (fntype)
4092 {
4093 tree ret_type = TREE_TYPE (fntype);
4094 fprintf (stderr, " ret code = %s,",
4095 tree_code_name[ (int)TREE_CODE (ret_type) ]);
4096 }
4097
6a4cee5f
MM
4098 if (cum->call_cookie & CALL_LONG)
4099 fprintf (stderr, " longcall,");
4100
4697a36c
MM
4101 fprintf (stderr, " proto = %d, nargs = %d\n",
4102 cum->prototype, cum->nargs_prototype);
4103 }
6d0ef01e
HP
4104
4105 if (fntype
4106 && !TARGET_ALTIVEC
4107 && TARGET_ALTIVEC_ABI
4108 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
4109 {
4110 error ("Cannot return value in vector register because"
4111 " altivec instructions are disabled, use -maltivec"
4112 " to enable them.");
4113 }
4697a36c
MM
4114}
4115\f
c229cba9
DE
4116/* If defined, a C expression which determines whether, and in which
4117 direction, to pad out an argument with extra space. The value
4118 should be of type `enum direction': either `upward' to pad above
4119 the argument, `downward' to pad below, or `none' to inhibit
4120 padding.
4121
4122 For the AIX ABI structs are always stored left shifted in their
4123 argument slot. */
4124
9ebbca7d 4125enum direction
a2369ed3 4126function_arg_padding (enum machine_mode mode, tree type)
c229cba9 4127{
6e985040
AM
4128#ifndef AGGREGATE_PADDING_FIXED
4129#define AGGREGATE_PADDING_FIXED 0
4130#endif
4131#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
4132#define AGGREGATES_PAD_UPWARD_ALWAYS 0
4133#endif
4134
4135 if (!AGGREGATE_PADDING_FIXED)
4136 {
4137 /* GCC used to pass structures of the same size as integer types as
4138 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
4139 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
4140 passed padded downward, except that -mstrict-align further
4141 muddied the water in that multi-component structures of 2 and 4
4142 bytes in size were passed padded upward.
4143
4144 The following arranges for best compatibility with previous
4145 versions of gcc, but removes the -mstrict-align dependency. */
4146 if (BYTES_BIG_ENDIAN)
4147 {
4148 HOST_WIDE_INT size = 0;
4149
4150 if (mode == BLKmode)
4151 {
4152 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4153 size = int_size_in_bytes (type);
4154 }
4155 else
4156 size = GET_MODE_SIZE (mode);
4157
4158 if (size == 1 || size == 2 || size == 4)
4159 return downward;
4160 }
4161 return upward;
4162 }
4163
4164 if (AGGREGATES_PAD_UPWARD_ALWAYS)
4165 {
4166 if (type != 0 && AGGREGATE_TYPE_P (type))
4167 return upward;
4168 }
c229cba9 4169
d3704c46
KH
4170 /* Fall back to the default. */
4171 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
4172}
4173
b6c9286a
MM
4174/* If defined, a C expression that gives the alignment boundary, in bits,
4175 of an argument with the specified mode and type. If it is not defined,
4176 PARM_BOUNDARY is used for all arguments.
4177
2310f99a 4178 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
4179
4180int
a2369ed3 4181function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 4182{
4ed78545
AM
4183 if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8)
4184 return 64;
4185 else if (SPE_VECTOR_MODE (mode))
e1f83b4d 4186 return 64;
b2d04ecf 4187 else if (ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4188 return 128;
9ebbca7d 4189 else
b6c9286a 4190 return PARM_BOUNDARY;
b6c9286a 4191}
c53bdcf5
AM
4192
4193/* Compute the size (in words) of a function argument. */
4194
4195static unsigned long
4196rs6000_arg_size (enum machine_mode mode, tree type)
4197{
4198 unsigned long size;
4199
4200 if (mode != BLKmode)
4201 size = GET_MODE_SIZE (mode);
4202 else
4203 size = int_size_in_bytes (type);
4204
4205 if (TARGET_32BIT)
4206 return (size + 3) >> 2;
4207 else
4208 return (size + 7) >> 3;
4209}
b6c9286a 4210\f
4697a36c
MM
4211/* Update the data in CUM to advance over an argument
4212 of mode MODE and data type TYPE.
b2d04ecf
AM
4213 (TYPE is null for libcalls where that information may not be available.)
4214
4215 Note that for args passed by reference, function_arg will be called
4216 with MODE and TYPE set to that of the pointer to the arg, not the arg
4217 itself. */
4697a36c
MM
4218
4219void
a2369ed3
DJ
4220function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4221 tree type, int named)
4697a36c
MM
4222{
4223 cum->nargs_prototype--;
4224
0ac081f6
AH
4225 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4226 {
4ed78545
AM
4227 bool stack = false;
4228
2858f73a 4229 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
6d0ef01e
HP
4230 {
4231 cum->vregno++;
4232 if (!TARGET_ALTIVEC)
4233 error ("Cannot pass argument in vector register because"
4234 " altivec instructions are disabled, use -maltivec"
4235 " to enable them.");
4ed78545
AM
4236
4237 /* PowerPC64 Linux and AIX allocate GPRs for a vector argument
4238 even if it is going to be passed in a vector register.
4239 Darwin does the same for variable-argument functions. */
4240 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4241 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4242 stack = true;
6d0ef01e 4243 }
4ed78545
AM
4244 else
4245 stack = true;
4246
4247 if (stack)
c72d6c26 4248 {
a594a19c
GK
4249 int align;
4250
2858f73a
GK
4251 /* Vector parameters must be 16-byte aligned. This places
4252 them at 2 mod 4 in terms of words in 32-bit mode, since
4253 the parameter save area starts at offset 24 from the
4254 stack. In 64-bit mode, they just have to start on an
4255 even word, since the parameter save area is 16-byte
4256 aligned. Space for GPRs is reserved even if the argument
4257 will be passed in memory. */
4258 if (TARGET_32BIT)
4ed78545 4259 align = (2 - cum->words) & 3;
2858f73a
GK
4260 else
4261 align = cum->words & 1;
c53bdcf5 4262 cum->words += align + rs6000_arg_size (mode, type);
2858f73a 4263
a594a19c
GK
4264 if (TARGET_DEBUG_ARG)
4265 {
4266 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
4267 cum->words, align);
4268 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
2858f73a
GK
4269 cum->nargs_prototype, cum->prototype,
4270 GET_MODE_NAME (mode));
a594a19c
GK
4271 }
4272 }
0ac081f6 4273 }
a4b0320c 4274 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4275 && !cum->stdarg
4276 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4277 cum->sysv_gregno++;
f607bc57 4278 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4279 {
a3170dc6 4280 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4281 && (mode == SFmode || mode == DFmode))
4697a36c 4282 {
4cc833b7
RH
4283 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4284 cum->fregno++;
4285 else
4286 {
4287 if (mode == DFmode)
4288 cum->words += cum->words & 1;
c53bdcf5 4289 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4290 }
4697a36c 4291 }
4cc833b7
RH
4292 else
4293 {
b2d04ecf 4294 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4295 int gregno = cum->sysv_gregno;
4296
4ed78545
AM
4297 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4298 (r7,r8) or (r9,r10). As does any other 2 word item such
4299 as complex int due to a historical mistake. */
4300 if (n_words == 2)
4301 gregno += (1 - gregno) & 1;
4cc833b7 4302
4ed78545 4303 /* Multi-reg args are not split between registers and stack. */
4cc833b7
RH
4304 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4305 {
4ed78545
AM
4306 /* Long long and SPE vectors are aligned on the stack.
4307 So are other 2 word items such as complex int due to
4308 a historical mistake. */
4cc833b7
RH
4309 if (n_words == 2)
4310 cum->words += cum->words & 1;
4311 cum->words += n_words;
4312 }
4697a36c 4313
4cc833b7
RH
4314 /* Note: continuing to accumulate gregno past when we've started
4315 spilling to the stack indicates the fact that we've started
4316 spilling to the stack to expand_builtin_saveregs. */
4317 cum->sysv_gregno = gregno + n_words;
4318 }
4697a36c 4319
4cc833b7
RH
4320 if (TARGET_DEBUG_ARG)
4321 {
4322 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4323 cum->words, cum->fregno);
4324 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4325 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4326 fprintf (stderr, "mode = %4s, named = %d\n",
4327 GET_MODE_NAME (mode), named);
4328 }
4697a36c
MM
4329 }
4330 else
4cc833b7 4331 {
b2d04ecf
AM
4332 int n_words = rs6000_arg_size (mode, type);
4333 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
a4f6c312 4334
b2d04ecf
AM
4335 /* The simple alignment calculation here works because
4336 function_arg_boundary / PARM_BOUNDARY will only be 1 or 2.
4337 If we ever want to handle alignments larger than 8 bytes for
4338 32-bit or 16 bytes for 64-bit, then we'll need to take into
4339 account the offset to the start of the parm save area. */
4340 align &= cum->words;
4341 cum->words += align + n_words;
4697a36c 4342
a3170dc6
AH
4343 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4344 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4345 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4346
4347 if (TARGET_DEBUG_ARG)
4348 {
4349 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4350 cum->words, cum->fregno);
4351 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4352 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4353 fprintf (stderr, "named = %d, align = %d\n", named, align);
4354 }
4355 }
4697a36c 4356}
a6c9bed4
AH
4357
4358/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4359
a6c9bed4 4360static rtx
a2369ed3
DJ
4361rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4362 tree type)
a6c9bed4
AH
4363{
4364 if (cum->stdarg)
4365 {
4366 int gregno = cum->sysv_gregno;
c53bdcf5 4367 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4368
4369 /* SPE vectors are put in odd registers. */
4370 if (n_words == 2 && (gregno & 1) == 0)
4371 gregno += 1;
4372
4373 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4374 {
4375 rtx r1, r2;
4376 enum machine_mode m = SImode;
4377
4378 r1 = gen_rtx_REG (m, gregno);
4379 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4380 r2 = gen_rtx_REG (m, gregno + 1);
4381 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4382 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4383 }
4384 else
b78d48dd 4385 return NULL_RTX;
a6c9bed4
AH
4386 }
4387 else
4388 {
4389 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4390 return gen_rtx_REG (mode, cum->sysv_gregno);
4391 else
b78d48dd 4392 return NULL_RTX;
a6c9bed4
AH
4393 }
4394}
4395
b78d48dd
FJ
4396/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4397
4398static rtx
4399rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4400 tree type, int align_words)
4401{
4402 if (mode == DFmode)
4403 {
4404 /* -mpowerpc64 with 32bit ABI splits up a DFmode argument
4405 in vararg list into zero, one or two GPRs */
4406 if (align_words >= GP_ARG_NUM_REG)
4407 return gen_rtx_PARALLEL (DFmode,
4408 gen_rtvec (2,
4409 gen_rtx_EXPR_LIST (VOIDmode,
4410 NULL_RTX, const0_rtx),
4411 gen_rtx_EXPR_LIST (VOIDmode,
4412 gen_rtx_REG (mode,
4413 cum->fregno),
4414 const0_rtx)));
c53bdcf5 4415 else if (align_words + rs6000_arg_size (mode, type)
b78d48dd
FJ
4416 > GP_ARG_NUM_REG)
4417 /* If this is partially on the stack, then we only
a3c9585f 4418 include the portion actually in registers here. */
b78d48dd
FJ
4419 return gen_rtx_PARALLEL (DFmode,
4420 gen_rtvec (2,
4421 gen_rtx_EXPR_LIST (VOIDmode,
4422 gen_rtx_REG (SImode,
4423 GP_ARG_MIN_REG
4424 + align_words),
4425 const0_rtx),
4426 gen_rtx_EXPR_LIST (VOIDmode,
4427 gen_rtx_REG (mode,
4428 cum->fregno),
4429 const0_rtx)));
4430
4431 /* split a DFmode arg into two GPRs */
4432 return gen_rtx_PARALLEL (DFmode,
4433 gen_rtvec (3,
4434 gen_rtx_EXPR_LIST (VOIDmode,
4435 gen_rtx_REG (SImode,
4436 GP_ARG_MIN_REG
4437 + align_words),
4438 const0_rtx),
4439 gen_rtx_EXPR_LIST (VOIDmode,
4440 gen_rtx_REG (SImode,
4441 GP_ARG_MIN_REG
4442 + align_words + 1),
4443 GEN_INT (4)),
4444 gen_rtx_EXPR_LIST (VOIDmode,
4445 gen_rtx_REG (mode, cum->fregno),
4446 const0_rtx)));
4447 }
4448 /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one
4449 or two GPRs */
4450 else if (mode == DImode)
4451 {
4452 if (align_words < GP_ARG_NUM_REG - 1)
4453 return gen_rtx_PARALLEL (DImode,
4454 gen_rtvec (2,
4455 gen_rtx_EXPR_LIST (VOIDmode,
4456 gen_rtx_REG (SImode,
4457 GP_ARG_MIN_REG
4458 + align_words),
4459 const0_rtx),
4460 gen_rtx_EXPR_LIST (VOIDmode,
4461 gen_rtx_REG (SImode,
4462 GP_ARG_MIN_REG
4463 + align_words + 1),
4464 GEN_INT (4))));
4465 else if (align_words == GP_ARG_NUM_REG - 1)
4466 return gen_rtx_PARALLEL (DImode,
4467 gen_rtvec (2,
4468 gen_rtx_EXPR_LIST (VOIDmode,
4469 NULL_RTX, const0_rtx),
4470 gen_rtx_EXPR_LIST (VOIDmode,
4471 gen_rtx_REG (SImode,
4472 GP_ARG_MIN_REG
4473 + align_words),
4474 const0_rtx)));
4475 }
36a454e1 4476 else if (ALTIVEC_VECTOR_MODE (mode) && align_words == GP_ARG_NUM_REG - 2)
b78d48dd 4477 {
36a454e1
FJ
4478 /* Varargs vector regs must be saved in R9-R10. */
4479 return gen_rtx_PARALLEL (mode,
4480 gen_rtvec (3,
4481 gen_rtx_EXPR_LIST (VOIDmode,
4482 NULL_RTX, const0_rtx),
4483 gen_rtx_EXPR_LIST (VOIDmode,
4484 gen_rtx_REG (SImode,
4485 GP_ARG_MIN_REG
4486 + align_words),
4487 const0_rtx),
4488 gen_rtx_EXPR_LIST (VOIDmode,
4489 gen_rtx_REG (SImode,
4490 GP_ARG_MIN_REG
4491 + align_words + 1),
4492 GEN_INT (4))));
4493 }
4494 else if ((mode == BLKmode || ALTIVEC_VECTOR_MODE (mode))
4495 && align_words <= (GP_ARG_NUM_REG - 1))
4496 {
4497 /* AltiVec vector regs are saved in R5-R8. */
b78d48dd
FJ
4498 int k;
4499 int size = int_size_in_bytes (type);
2f7b62ef 4500 int no_units = ((size - 1) / 4) + 1;
b78d48dd
FJ
4501 int max_no_words = GP_ARG_NUM_REG - align_words;
4502 int rtlvec_len = no_units < max_no_words ? no_units : max_no_words;
4503 rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx));
4504
4505 memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx));
4506
4507 for (k=0; k < rtlvec_len; k++)
4508 rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode,
4509 gen_rtx_REG (SImode,
4510 GP_ARG_MIN_REG
4511 + align_words + k),
4512 k == 0 ? const0_rtx : GEN_INT (k*4));
4513
36a454e1
FJ
4514 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rtlvec));
4515 }
b78d48dd
FJ
4516 return NULL_RTX;
4517}
4518
4697a36c
MM
4519/* Determine where to put an argument to a function.
4520 Value is zero to push the argument on the stack,
4521 or a hard register in which to store the argument.
4522
4523 MODE is the argument's machine mode.
4524 TYPE is the data type of the argument (as a tree).
4525 This is null for libcalls where that information may
4526 not be available.
4527 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4528 the preceding args and about the function being called.
4529 NAMED is nonzero if this argument is a named parameter
4530 (otherwise it is an extra parameter matching an ellipsis).
4531
4532 On RS/6000 the first eight words of non-FP are normally in registers
4533 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4534 Under V.4, the first 8 FP args are in registers.
4535
4536 If this is floating-point and no prototype is specified, we use
4537 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4538 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4539 so we can pass the FP value just in one register. emit_library_function
b2d04ecf
AM
4540 doesn't support PARALLEL anyway.
4541
4542 Note that for args passed by reference, function_arg will be called
4543 with MODE and TYPE set to that of the pointer to the arg, not the arg
4544 itself. */
4697a36c
MM
4545
4546struct rtx_def *
a2369ed3
DJ
4547function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4548 tree type, int named)
4697a36c 4549{
4cc833b7 4550 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4551
a4f6c312
SS
4552 /* Return a marker to indicate whether CR1 needs to set or clear the
4553 bit that V.4 uses to say fp args were passed in registers.
4554 Assume that we don't need the marker for software floating point,
4555 or compiler generated library calls. */
4697a36c
MM
4556 if (mode == VOIDmode)
4557 {
f607bc57 4558 if (abi == ABI_V4
7509c759 4559 && cum->nargs_prototype < 0
b9599e46
FS
4560 && (cum->call_cookie & CALL_LIBCALL) == 0
4561 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4562 {
a3170dc6
AH
4563 /* For the SPE, we need to crxor CR6 always. */
4564 if (TARGET_SPE_ABI)
4565 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4566 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4567 return GEN_INT (cum->call_cookie
4568 | ((cum->fregno == FP_ARG_MIN_REG)
4569 ? CALL_V4_SET_FP_ARGS
4570 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4571 }
4697a36c 4572
7509c759 4573 return GEN_INT (cum->call_cookie);
4697a36c
MM
4574 }
4575
2858f73a 4576 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4577 if (TARGET_64BIT && ! cum->prototype)
4578 {
4579 /* Vector parameters get passed in vector register
4580 and also in GPRs or memory, in absence of prototype. */
4581 int align_words;
4582 rtx slot;
4583 align_words = (cum->words + 1) & ~1;
4584
4585 if (align_words >= GP_ARG_NUM_REG)
4586 {
4587 slot = NULL_RTX;
4588 }
4589 else
4590 {
4591 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4592 }
4593 return gen_rtx_PARALLEL (mode,
4594 gen_rtvec (2,
4595 gen_rtx_EXPR_LIST (VOIDmode,
4596 slot, const0_rtx),
4597 gen_rtx_EXPR_LIST (VOIDmode,
4598 gen_rtx_REG (mode, cum->vregno),
4599 const0_rtx)));
4600 }
4601 else
4602 return gen_rtx_REG (mode, cum->vregno);
2858f73a 4603 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4604 {
2858f73a 4605 if (named || abi == ABI_V4)
a594a19c 4606 return NULL_RTX;
0ac081f6 4607 else
a594a19c
GK
4608 {
4609 /* Vector parameters to varargs functions under AIX or Darwin
4610 get passed in memory and possibly also in GPRs. */
4611 int align, align_words;
2858f73a 4612 enum machine_mode part_mode = mode;
a594a19c
GK
4613
4614 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
4615 2 mod 4 in terms of words in 32-bit mode, since the parameter
4616 save area starts at offset 24 from the stack. In 64-bit mode,
4617 they just have to start on an even word, since the parameter
4618 save area is 16-byte aligned. */
4619 if (TARGET_32BIT)
4ed78545 4620 align = (2 - cum->words) & 3;
2858f73a
GK
4621 else
4622 align = cum->words & 1;
a594a19c
GK
4623 align_words = cum->words + align;
4624
4625 /* Out of registers? Memory, then. */
4626 if (align_words >= GP_ARG_NUM_REG)
4627 return NULL_RTX;
4628
2858f73a
GK
4629 /* The vector value goes in GPRs. Only the part of the
4630 value in GPRs is reported here. */
4631 if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS)
4632 > GP_ARG_NUM_REG)
839a4992 4633 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
4634 is either wholly in GPRs or half in GPRs and half not. */
4635 part_mode = DImode;
4636
36a454e1
FJ
4637 if (TARGET_32BIT
4638 && (TARGET_POWERPC64 || (align_words == GP_ARG_NUM_REG - 2)))
4639 return rs6000_mixed_function_arg (cum, part_mode, type, align_words);
4640 else
4641 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 4642 }
0ac081f6 4643 }
a6c9bed4
AH
4644 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4645 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4646 else if (abi == ABI_V4)
4697a36c 4647 {
a3170dc6 4648 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4649 && (mode == SFmode || mode == DFmode))
4650 {
4651 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4652 return gen_rtx_REG (mode, cum->fregno);
4653 else
b78d48dd 4654 return NULL_RTX;
4cc833b7
RH
4655 }
4656 else
4657 {
b2d04ecf 4658 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4659 int gregno = cum->sysv_gregno;
4660
4ed78545
AM
4661 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4662 (r7,r8) or (r9,r10). As does any other 2 word item such
4663 as complex int due to a historical mistake. */
4664 if (n_words == 2)
4665 gregno += (1 - gregno) & 1;
4cc833b7 4666
4ed78545 4667 /* Multi-reg args are not split between registers and stack. */
4cc833b7 4668 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4669 return gen_rtx_REG (mode, gregno);
4cc833b7 4670 else
b78d48dd 4671 return NULL_RTX;
4cc833b7 4672 }
4697a36c 4673 }
4cc833b7
RH
4674 else
4675 {
b2d04ecf
AM
4676 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
4677 int align_words = cum->words + (cum->words & align);
b78d48dd 4678
2858f73a 4679 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 4680 {
c53bdcf5
AM
4681 rtx fpr[2];
4682 rtx *r;
4683 bool needs_psave;
4684 enum machine_mode fmode = mode;
4685 int n;
4686 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
4687
4688 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
4689 {
4690 /* Long double split over regs and memory. */
4691 if (fmode == TFmode)
4692 fmode = DFmode;
4693
4694 /* Currently, we only ever need one reg here because complex
4695 doubles are split. */
4696 if (cum->fregno != FP_ARG_MAX_REG - 1)
4697 abort ();
4698 }
4699 fpr[1] = gen_rtx_REG (fmode, cum->fregno);
4700
4701 /* Do we also need to pass this arg in the parameter save
4702 area? */
4703 needs_psave = (type
4704 && (cum->nargs_prototype <= 0
4705 || (DEFAULT_ABI == ABI_AIX
4706 && TARGET_XL_CALL
4707 && align_words >= GP_ARG_NUM_REG)));
4708
4709 if (!needs_psave && mode == fmode)
4710 return fpr[1];
4cc833b7 4711
e91fa876
FJ
4712 if (TARGET_32BIT && TARGET_POWERPC64
4713 && mode == DFmode && cum->stdarg)
4714 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4715
c53bdcf5
AM
4716 /* Describe where this piece goes. */
4717 r = fpr + 1;
4718 *r = gen_rtx_EXPR_LIST (VOIDmode, *r, const0_rtx);
4719 n = 1;
4720
4721 if (needs_psave)
4722 {
4723 /* Now describe the part that goes in gprs or the stack.
4724 This piece must come first, before the fprs. */
4725 rtx reg = NULL_RTX;
4726 if (align_words < GP_ARG_NUM_REG)
4727 {
4728 unsigned long n_words = rs6000_arg_size (mode, type);
4729 enum machine_mode rmode = mode;
4730
4731 if (align_words + n_words > GP_ARG_NUM_REG)
4732 /* If this is partially on the stack, then we only
4733 include the portion actually in registers here.
4734 We know this can only be one register because
4735 complex doubles are splt. */
4736 rmode = Pmode;
4737 reg = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words);
4738 }
4739 *--r = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4740 ++n;
4741 }
4742
4743 return gen_rtx_PARALLEL (mode, gen_rtvec_v (n, r));
4cc833b7
RH
4744 }
4745 else if (align_words < GP_ARG_NUM_REG)
b2d04ecf
AM
4746 {
4747 if (TARGET_32BIT && TARGET_POWERPC64
4748 && (mode == DImode || mode == BLKmode))
4749 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4750
4751 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4752 }
4cc833b7
RH
4753 else
4754 return NULL_RTX;
4697a36c 4755 }
4697a36c
MM
4756}
4757\f
4758/* For an arg passed partly in registers and partly in memory,
4759 this is the number of registers used.
4760 For args passed entirely in registers or entirely in memory, zero. */
4761
4762int
a2369ed3 4763function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 4764 tree type, int named)
4697a36c 4765{
c53bdcf5
AM
4766 int ret = 0;
4767
f607bc57 4768 if (DEFAULT_ABI == ABI_V4)
4697a36c 4769 return 0;
4697a36c 4770
c53bdcf5
AM
4771 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
4772 && cum->nargs_prototype >= 0)
4773 return 0;
4774
4775 if (USE_FP_FOR_ARG_P (cum, mode, type))
4697a36c 4776 {
c53bdcf5
AM
4777 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
4778 ret = FP_ARG_MAX_REG - cum->fregno;
4779 else if (cum->nargs_prototype >= 0)
4697a36c
MM
4780 return 0;
4781 }
4782
4783 if (cum->words < GP_ARG_NUM_REG
c53bdcf5
AM
4784 && GP_ARG_NUM_REG < cum->words + rs6000_arg_size (mode, type))
4785 ret = GP_ARG_NUM_REG - cum->words;
4697a36c 4786
c53bdcf5
AM
4787 if (ret != 0 && TARGET_DEBUG_ARG)
4788 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 4789
c53bdcf5 4790 return ret;
4697a36c
MM
4791}
4792\f
4793/* A C expression that indicates when an argument must be passed by
4794 reference. If nonzero for an argument, a copy of that argument is
4795 made in memory and a pointer to the argument is passed instead of
4796 the argument itself. The pointer is passed in whatever way is
4797 appropriate for passing a pointer to that type.
4798
b2d04ecf
AM
4799 Under V.4, aggregates and long double are passed by reference.
4800
4801 As an extension to all 32-bit ABIs, AltiVec vectors are passed by
4802 reference unless the AltiVec vector extension ABI is in force.
c8c99a68
DE
4803
4804 As an extension to all ABIs, variable sized types are passed by
4805 reference. */
4697a36c
MM
4806
4807int
a2369ed3
DJ
4808function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4809 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 4810 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 4811{
b2d04ecf
AM
4812 if ((DEFAULT_ABI == ABI_V4
4813 && ((type && AGGREGATE_TYPE_P (type))
4814 || mode == TFmode))
4815 || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4816 || (type && int_size_in_bytes (type) < 0))
4697a36c
MM
4817 {
4818 if (TARGET_DEBUG_ARG)
b2d04ecf 4819 fprintf (stderr, "function_arg_pass_by_reference\n");
4697a36c
MM
4820
4821 return 1;
4822 }
b2d04ecf 4823 return 0;
4697a36c 4824}
5985c7a6
FJ
4825
4826static void
2d9db8eb 4827rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
4828{
4829 int i;
4830 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
4831
4832 if (nregs == 0)
4833 return;
4834
4835 for (i = 0; i < nregs; i++)
4836 {
4837 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
4838 if (reload_completed)
4839 {
4840 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
4841 tem = NULL_RTX;
4842 else
4843 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
4844 i * GET_MODE_SIZE(reg_mode));
4845 }
4846 else
4847 tem = replace_equiv_address (tem, XEXP (tem, 0));
4848
4849 if (tem == NULL_RTX)
4850 abort ();
4851
4852 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
4853 }
4854}
4855
4697a36c
MM
4856\f
4857/* Perform any needed actions needed for a function that is receiving a
4858 variable number of arguments.
4859
4860 CUM is as above.
4861
4862 MODE and TYPE are the mode and type of the current parameter.
4863
4864 PRETEND_SIZE is a variable that should be set to the amount of stack
4865 that must be pushed by the prolog to pretend that our caller pushed
4866 it.
4867
4868 Normally, this macro will push all remaining incoming registers on the
4869 stack and set PRETEND_SIZE to the length of the registers pushed. */
4870
c6e8c921 4871static void
a2369ed3
DJ
4872setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4873 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4874{
4cc833b7
RH
4875 CUMULATIVE_ARGS next_cum;
4876 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4877 rtx save_area = NULL_RTX, mem;
dfafc897 4878 int first_reg_offset, set;
4697a36c 4879
f31bf321 4880 /* Skip the last named argument. */
d34c5b80 4881 next_cum = *cum;
f31bf321 4882 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4883
f607bc57 4884 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4885 {
4cc833b7 4886 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4887 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4888 if (! no_rtl)
2c4974b7 4889 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4890 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4891
4892 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4893 }
60e2d0ca 4894 else
4697a36c 4895 {
d34c5b80 4896 first_reg_offset = next_cum.words;
4cc833b7 4897 save_area = virtual_incoming_args_rtx;
00dba523 4898 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4899
4900 if (MUST_PASS_IN_STACK (mode, type))
c53bdcf5 4901 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 4902 }
4697a36c 4903
dfafc897 4904 set = get_varargs_alias_set ();
c81fc13e 4905 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4906 {
dfafc897
FS
4907 mem = gen_rtx_MEM (BLKmode,
4908 plus_constant (save_area,
4909 first_reg_offset * reg_size)),
ba4828e0 4910 set_mem_alias_set (mem, set);
8ac61af7 4911 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4912
5985c7a6
FJ
4913 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4914 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4915 }
4916
4697a36c 4917 /* Save FP registers if needed. */
f607bc57 4918 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4919 && TARGET_HARD_FLOAT && TARGET_FPRS
4920 && ! no_rtl
4cc833b7 4921 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4922 {
4cc833b7 4923 int fregno = next_cum.fregno;
9ebbca7d 4924 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4925 rtx lab = gen_label_rtx ();
4926 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4927
4cc833b7 4928 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4929 pc_rtx,
39403d82 4930 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4931 gen_rtx_NE (VOIDmode, cr1,
4932 const0_rtx),
39403d82 4933 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4934 pc_rtx)));
4935
4cc833b7
RH
4936 while (fregno <= FP_ARG_V4_MAX_REG)
4937 {
dfafc897 4938 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4939 set_mem_alias_set (mem, set);
dfafc897 4940 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4941 fregno++;
4942 off += 8;
4697a36c 4943 }
4cc833b7
RH
4944
4945 emit_label (lab);
4697a36c 4946 }
4697a36c 4947}
4697a36c 4948
dfafc897 4949/* Create the va_list data type. */
2c4974b7 4950
c35d187f
RH
4951static tree
4952rs6000_build_builtin_va_list (void)
dfafc897 4953{
64c2816f 4954 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4955
9ebbca7d
GK
4956 /* For AIX, prefer 'char *' because that's what the system
4957 header files like. */
f607bc57 4958 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4959 return build_pointer_type (char_type_node);
dfafc897 4960
f1e639b1 4961 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4962 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4963
9ebbca7d
GK
4964 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4965 unsigned_char_type_node);
4966 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4967 unsigned_char_type_node);
64c2816f
DT
4968 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4969 every user file. */
4970 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4971 short_unsigned_type_node);
dfafc897
FS
4972 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4973 ptr_type_node);
4974 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4975 ptr_type_node);
4976
4977 DECL_FIELD_CONTEXT (f_gpr) = record;
4978 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4979 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4980 DECL_FIELD_CONTEXT (f_ovf) = record;
4981 DECL_FIELD_CONTEXT (f_sav) = record;
4982
bab45a51
FS
4983 TREE_CHAIN (record) = type_decl;
4984 TYPE_NAME (record) = type_decl;
dfafc897
FS
4985 TYPE_FIELDS (record) = f_gpr;
4986 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4987 TREE_CHAIN (f_fpr) = f_res;
4988 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4989 TREE_CHAIN (f_ovf) = f_sav;
4990
4991 layout_type (record);
4992
4993 /* The correct type is an array type of one element. */
4994 return build_array_type (record, build_index_type (size_zero_node));
4995}
4996
4997/* Implement va_start. */
4998
4999void
a2369ed3 5000rs6000_va_start (tree valist, rtx nextarg)
4697a36c 5001{
dfafc897 5002 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 5003 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 5004 tree gpr, fpr, ovf, sav, t;
2c4974b7 5005
dfafc897 5006 /* Only SVR4 needs something special. */
f607bc57 5007 if (DEFAULT_ABI != ABI_V4)
dfafc897 5008 {
e5faf155 5009 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
5010 return;
5011 }
5012
973a648b 5013 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5014 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5015 f_res = TREE_CHAIN (f_fpr);
5016 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5017 f_sav = TREE_CHAIN (f_ovf);
5018
8ebecc3b 5019 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
5020 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
5021 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
5022 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
5023 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
5024
5025 /* Count number of gp and fp argument registers used. */
4cc833b7 5026 words = current_function_args_info.words;
dfafc897
FS
5027 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
5028 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
5029
5030 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
5031 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
5032 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
5033 words, n_gpr, n_fpr);
dfafc897
FS
5034
5035 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
5036 TREE_SIDE_EFFECTS (t) = 1;
5037 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5038
5039 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
5040 TREE_SIDE_EFFECTS (t) = 1;
5041 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5042
5043 /* Find the overflow area. */
5044 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
5045 if (words != 0)
5046 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
5047 build_int_2 (words * UNITS_PER_WORD, 0));
5048 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5049 TREE_SIDE_EFFECTS (t) = 1;
5050 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5051
5052 /* Find the register save area. */
5053 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
5054 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
5055 build_int_2 (-RS6000_VARARGS_SIZE, -1));
5056 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
5057 TREE_SIDE_EFFECTS (t) = 1;
5058 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5059}
5060
5061/* Implement va_arg. */
5062
5063rtx
a2369ed3 5064rs6000_va_arg (tree valist, tree type)
dfafc897 5065{
c566f9bd 5066 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
5067 tree gpr, fpr, ovf, sav, reg, t, u;
5068 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
5069 rtx lab_false, lab_over, addr_rtx, r;
4ed78545 5070 int align;
dfafc897 5071
f607bc57 5072 if (DEFAULT_ABI != ABI_V4)
c8c99a68 5073 {
b2d04ecf
AM
5074 /* Variable sized types are passed by reference, as are AltiVec
5075 vectors when 32-bit and not using the AltiVec ABI extension. */
5076 if (int_size_in_bytes (type) < 0
5077 || (TARGET_32BIT
5078 && !TARGET_ALTIVEC_ABI
5079 && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))))
c8c99a68
DE
5080 {
5081 u = build_pointer_type (type);
5082
5083 /* Args grow upward. */
5084 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
5085 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
5086 TREE_SIDE_EFFECTS (t) = 1;
5087
5088 t = build1 (NOP_EXPR, build_pointer_type (u), t);
5089 TREE_SIDE_EFFECTS (t) = 1;
5090
5091 t = build1 (INDIRECT_REF, u, t);
5092 TREE_SIDE_EFFECTS (t) = 1;
5093
5094 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
5095 }
fa78dbea 5096 if (targetm.calls.split_complex_arg
c53bdcf5
AM
5097 && TREE_CODE (type) == COMPLEX_TYPE)
5098 {
5099 tree elem_type = TREE_TYPE (type);
5100 enum machine_mode elem_mode = TYPE_MODE (elem_type);
5101 int elem_size = GET_MODE_SIZE (elem_mode);
5102
5103 if (elem_size < UNITS_PER_WORD)
5104 {
5105 rtx real_part, imag_part, dest_real, rr;
5106
5107 real_part = rs6000_va_arg (valist, elem_type);
5108 imag_part = rs6000_va_arg (valist, elem_type);
5109
5110 /* We're not returning the value here, but the address.
5111 real_part and imag_part are not contiguous, and we know
5112 there is space available to pack real_part next to
5113 imag_part. float _Complex is not promoted to
5114 double _Complex by the default promotion rules that
5115 promote float to double. */
5116 if (2 * elem_size > UNITS_PER_WORD)
5117 abort ();
5118
5119 real_part = gen_rtx_MEM (elem_mode, real_part);
5120 imag_part = gen_rtx_MEM (elem_mode, imag_part);
5121
5122 dest_real = adjust_address (imag_part, elem_mode, -elem_size);
5123 rr = gen_reg_rtx (elem_mode);
5124 emit_move_insn (rr, real_part);
5125 emit_move_insn (dest_real, rr);
5126
5127 return XEXP (dest_real, 0);
5128 }
5129 }
5130
5131 return std_expand_builtin_va_arg (valist, type);
c8c99a68 5132 }
dfafc897 5133
973a648b 5134 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5135 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5136 f_res = TREE_CHAIN (f_fpr);
5137 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5138 f_sav = TREE_CHAIN (f_ovf);
5139
8ebecc3b 5140 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
5141 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
5142 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
5143 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
5144 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
5145
5146 size = int_size_in_bytes (type);
11c01dcc 5147 rsize = (size + 3) / 4;
4ed78545 5148 align = 1;
4cc833b7 5149
4ed78545
AM
5150 if (AGGREGATE_TYPE_P (type)
5151 || TYPE_MODE (type) == TFmode
5152 || (!TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))))
4cc833b7 5153 {
4ed78545
AM
5154 /* Aggregates, long doubles, and AltiVec vectors are passed by
5155 reference. */
dfafc897
FS
5156 indirect_p = 1;
5157 reg = gpr;
5158 n_reg = 1;
5159 sav_ofs = 0;
5160 sav_scale = 4;
11c01dcc 5161 size = 4;
d3294cd9 5162 rsize = 1;
dfafc897 5163 }
4ed78545
AM
5164 else if (TARGET_HARD_FLOAT && TARGET_FPRS
5165 && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode))
dfafc897
FS
5166 {
5167 /* FP args go in FP registers, if present. */
5168 indirect_p = 0;
5169 reg = fpr;
5170 n_reg = 1;
5171 sav_ofs = 8*4;
5172 sav_scale = 8;
4ed78545
AM
5173 if (TYPE_MODE (type) == DFmode)
5174 align = 8;
4cc833b7 5175 }
dfafc897
FS
5176 else
5177 {
5178 /* Otherwise into GP registers. */
5179 indirect_p = 0;
5180 reg = gpr;
5181 n_reg = rsize;
5182 sav_ofs = 0;
5183 sav_scale = 4;
4ed78545
AM
5184 if (n_reg == 2)
5185 align = 8;
dfafc897
FS
5186 }
5187
a3c9585f 5188 /* Pull the value out of the saved registers.... */
dfafc897 5189
4ed78545 5190 lab_over = NULL_RTX;
dfafc897
FS
5191 addr_rtx = gen_reg_rtx (Pmode);
5192
4ed78545
AM
5193 /* AltiVec vectors never go in registers when -mabi=altivec. */
5194 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
5195 align = 16;
5196 else
2c4974b7 5197 {
4ed78545
AM
5198 lab_false = gen_label_rtx ();
5199 lab_over = gen_label_rtx ();
dfafc897 5200
4ed78545
AM
5201 /* Long long and SPE vectors are aligned in the registers.
5202 As are any other 2 gpr item such as complex int due to a
5203 historical mistake. */
5204 u = reg;
5205 if (n_reg == 2)
41daaf0e
AH
5206 {
5207 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
5208 build_int_2 (n_reg - 1, 0));
4ed78545 5209 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u);
41daaf0e 5210 TREE_SIDE_EFFECTS (u) = 1;
41daaf0e 5211 }
2c4974b7 5212
4ed78545
AM
5213 emit_cmp_and_jump_insns
5214 (expand_expr (u, NULL_RTX, QImode, EXPAND_NORMAL),
5215 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
5216 lab_false);
5217
5218 t = sav;
41daaf0e
AH
5219 if (sav_ofs)
5220 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
2c4974b7 5221
41daaf0e
AH
5222 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
5223 build_int_2 (n_reg, 0));
5224 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 5225
41daaf0e
AH
5226 u = build1 (CONVERT_EXPR, integer_type_node, u);
5227 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 5228
41daaf0e
AH
5229 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
5230 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 5231
41daaf0e
AH
5232 t = build (PLUS_EXPR, ptr_type_node, t, u);
5233 TREE_SIDE_EFFECTS (t) = 1;
5234
5235 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
5236 if (r != addr_rtx)
5237 emit_move_insn (addr_rtx, r);
5238
5239 emit_jump_insn (gen_jump (lab_over));
5240 emit_barrier ();
dfafc897 5241
4ed78545 5242 emit_label (lab_false);
11c01dcc
AM
5243 if (n_reg > 2)
5244 {
5245 /* Ensure that we don't find any more args in regs.
5246 Alignment has taken care of the n_reg == 2 case. */
5247 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
5248 TREE_SIDE_EFFECTS (t) = 1;
5249 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5250 }
4ed78545 5251 }
dfafc897 5252
a4f6c312 5253 /* ... otherwise out of the overflow area. */
dfafc897 5254
dfafc897 5255 /* Care for on-stack alignment if needed. */
4ed78545
AM
5256 t = ovf;
5257 if (align != 1)
dfafc897 5258 {
4ed78545
AM
5259 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (align - 1, 0));
5260 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align, -1));
dfafc897
FS
5261 }
5262 t = save_expr (t);
5263
5264 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
5265 if (r != addr_rtx)
5266 emit_move_insn (addr_rtx, r);
5267
5268 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
5269 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5270 TREE_SIDE_EFFECTS (t) = 1;
5271 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5272
4ed78545
AM
5273 if (lab_over)
5274 emit_label (lab_over);
dfafc897
FS
5275
5276 if (indirect_p)
5277 {
5278 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 5279 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
5280 emit_move_insn (addr_rtx, r);
5281 }
5282
5283 return addr_rtx;
4697a36c 5284}
0ac081f6
AH
5285
5286/* Builtins. */
5287
6a2dd09a
RS
5288#define def_builtin(MASK, NAME, TYPE, CODE) \
5289do { \
5290 if ((MASK) & target_flags) \
5291 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
5292 NULL, NULL_TREE); \
0ac081f6
AH
5293} while (0)
5294
24408032
AH
5295/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
5296
2212663f 5297static const struct builtin_description bdesc_3arg[] =
24408032
AH
5298{
5299 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
5300 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
5301 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
5302 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
5303 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
5304 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
5305 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
5306 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
5307 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
5308 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
5309 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
5310 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
5311 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
5312 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
5313 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
5314 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
5315 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
5316 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
5317 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
5318 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
5319 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
5320 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
5321 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
5322};
2212663f 5323
95385cbb
AH
5324/* DST operations: void foo (void *, const int, const char). */
5325
5326static const struct builtin_description bdesc_dst[] =
5327{
5328 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
5329 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
5330 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
5331 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
5332};
5333
2212663f 5334/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 5335
a3170dc6 5336static struct builtin_description bdesc_2arg[] =
0ac081f6 5337{
f18c054f
DB
5338 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
5339 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
5340 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
5341 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
5342 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
5343 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
5344 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
5345 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
5346 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
5347 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
5348 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 5349 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
5350 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
5351 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
5352 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
5353 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
5354 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
5355 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
5356 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
5357 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
5358 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
5359 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
5360 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
5361 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5362 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5363 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5364 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5365 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5366 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5367 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5368 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5369 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5370 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5371 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5372 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5373 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5374 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5375 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5376 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5377 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5378 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5379 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5380 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5381 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5382 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5383 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5384 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5385 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5386 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5387 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5388 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5389 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5390 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5391 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5392 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5393 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5394 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5395 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5396 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5397 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5398 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5399 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5400 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5401 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5402 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5403 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5404 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5405 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5406 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5407 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5408 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5409 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5410 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5411 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5412 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5413 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5414 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5415 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5416 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5417 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5418 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5419 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5420 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5421 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5422 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5423 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5424 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5425 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5426 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5427 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5428 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5429 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5430 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5431 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5432 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5433 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5434 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5435 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5436 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5437 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5438 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5439 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5440 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5441 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5442 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5443 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5444 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5445 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5446 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5447 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5448 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5449 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5450 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5451
5452 /* Place holder, leave as first spe builtin. */
5453 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5454 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5455 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5456 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5457 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5458 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5459 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5460 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5461 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5462 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5463 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5464 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5465 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5466 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5467 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5468 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5469 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5470 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5471 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5472 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5473 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5474 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5475 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5476 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5477 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5478 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5479 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5480 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5481 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5482 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5483 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5484 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5485 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5486 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5487 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5488 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5489 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5490 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5491 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5492 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5493 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5494 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5495 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5496 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5497 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5498 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5499 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5500 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5501 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5502 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5503 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5504 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5505 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5506 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5507 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5508 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5509 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5510 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5511 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5512 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5513 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5514 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5515 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5516 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5517 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5518 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5519 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5520 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5521 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5522 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5523 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5524 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5525 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5526 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5527 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5528 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5529 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5530 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5531 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5532 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5533 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5534 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5535 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5536 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5537 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5538 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5539 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5540 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5541 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5542 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5543 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5544 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5545 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5546 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5547 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5548 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
5549 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
5550 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
5551 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
5552 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
5553 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
5554 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
5555 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
5556 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
5557 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
5558 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
5559 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
5560 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
5561 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
5562
5563 /* SPE binary operations expecting a 5-bit unsigned literal. */
5564 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
5565
5566 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
5567 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
5568 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
5569 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
5570 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
5571 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
5572 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
5573 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
5574 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
5575 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
5576 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
5577 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
5578 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
5579 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
5580 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
5581 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
5582 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
5583 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
5584 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
5585 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
5586 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
5587 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
5588 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
5589 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
5590 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
5591 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
5592
5593 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 5594 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
5595};
5596
5597/* AltiVec predicates. */
5598
5599struct builtin_description_predicates
5600{
5601 const unsigned int mask;
5602 const enum insn_code icode;
5603 const char *opcode;
5604 const char *const name;
5605 const enum rs6000_builtins code;
5606};
5607
5608static const struct builtin_description_predicates bdesc_altivec_preds[] =
5609{
5610 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
5611 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
5612 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
5613 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
5614 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
5615 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
5616 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
5617 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
5618 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
5619 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
5620 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
5621 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
5622 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 5623};
24408032 5624
a3170dc6
AH
5625/* SPE predicates. */
5626static struct builtin_description bdesc_spe_predicates[] =
5627{
5628 /* Place-holder. Leave as first. */
5629 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
5630 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
5631 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
5632 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
5633 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
5634 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
5635 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
5636 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
5637 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
5638 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
5639 /* Place-holder. Leave as last. */
5640 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
5641};
5642
5643/* SPE evsel predicates. */
5644static struct builtin_description bdesc_spe_evsel[] =
5645{
5646 /* Place-holder. Leave as first. */
5647 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
5648 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
5649 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
5650 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
5651 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
5652 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
5653 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
5654 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
5655 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
5656 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
5657 /* Place-holder. Leave as last. */
5658 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
5659};
5660
b6d08ca1 5661/* ABS* operations. */
100c4561
AH
5662
5663static const struct builtin_description bdesc_abs[] =
5664{
5665 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
5666 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
5667 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
5668 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
5669 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
5670 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
5671 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
5672};
5673
617e0e1d
DB
5674/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
5675 foo (VECa). */
24408032 5676
a3170dc6 5677static struct builtin_description bdesc_1arg[] =
2212663f 5678{
617e0e1d
DB
5679 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
5680 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
5681 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
5682 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
5683 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
5684 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
5685 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
5686 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
5687 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
5688 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
5689 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
5690 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
5691 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
5692 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
5693 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
5694 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
5695 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
5696
5697 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
5698 end with SPE_BUILTIN_EVSUBFUSIAAW. */
5699 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
5700 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
5701 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
5702 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
5703 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
5704 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
5705 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
5706 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
5707 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
5708 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
5709 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
5710 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
5711 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
5712 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
5713 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
5714 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
5715 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
5716 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
5717 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
5718 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
5719 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
5720 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
5721 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
6a599451 5722 { 0, CODE_FOR_negv2si2, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
a3170dc6
AH
5723 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
5724 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
5725 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
5726 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
5727
5728 /* Place-holder. Leave as last unary SPE builtin. */
5729 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
5730};
5731
5732static rtx
a2369ed3 5733rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5734{
5735 rtx pat;
5736 tree arg0 = TREE_VALUE (arglist);
5737 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5738 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5739 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5740
0559cc77
DE
5741 if (icode == CODE_FOR_nothing)
5742 /* Builtin not supported on this processor. */
5743 return 0;
5744
20e26713
AH
5745 /* If we got invalid arguments bail out before generating bad rtl. */
5746 if (arg0 == error_mark_node)
9a171fcd 5747 return const0_rtx;
20e26713 5748
0559cc77
DE
5749 if (icode == CODE_FOR_altivec_vspltisb
5750 || icode == CODE_FOR_altivec_vspltish
5751 || icode == CODE_FOR_altivec_vspltisw
5752 || icode == CODE_FOR_spe_evsplatfi
5753 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
5754 {
5755 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
5756 if (GET_CODE (op0) != CONST_INT
5757 || INTVAL (op0) > 0x1f
5758 || INTVAL (op0) < -0x1f)
5759 {
5760 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 5761 return const0_rtx;
b44140e7 5762 }
b44140e7
AH
5763 }
5764
c62f2db5 5765 if (target == 0
2212663f
DB
5766 || GET_MODE (target) != tmode
5767 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5768 target = gen_reg_rtx (tmode);
5769
5770 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5771 op0 = copy_to_mode_reg (mode0, op0);
5772
5773 pat = GEN_FCN (icode) (target, op0);
5774 if (! pat)
5775 return 0;
5776 emit_insn (pat);
0ac081f6 5777
2212663f
DB
5778 return target;
5779}
ae4b4a02 5780
100c4561 5781static rtx
a2369ed3 5782altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
5783{
5784 rtx pat, scratch1, scratch2;
5785 tree arg0 = TREE_VALUE (arglist);
5786 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5787 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5788 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5789
5790 /* If we have invalid arguments, bail out before generating bad rtl. */
5791 if (arg0 == error_mark_node)
9a171fcd 5792 return const0_rtx;
100c4561
AH
5793
5794 if (target == 0
5795 || GET_MODE (target) != tmode
5796 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5797 target = gen_reg_rtx (tmode);
5798
5799 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5800 op0 = copy_to_mode_reg (mode0, op0);
5801
5802 scratch1 = gen_reg_rtx (mode0);
5803 scratch2 = gen_reg_rtx (mode0);
5804
5805 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
5806 if (! pat)
5807 return 0;
5808 emit_insn (pat);
5809
5810 return target;
5811}
5812
0ac081f6 5813static rtx
a2369ed3 5814rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
5815{
5816 rtx pat;
5817 tree arg0 = TREE_VALUE (arglist);
5818 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5819 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5820 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5821 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5822 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5823 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5824
0559cc77
DE
5825 if (icode == CODE_FOR_nothing)
5826 /* Builtin not supported on this processor. */
5827 return 0;
5828
20e26713
AH
5829 /* If we got invalid arguments bail out before generating bad rtl. */
5830 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5831 return const0_rtx;
20e26713 5832
0559cc77
DE
5833 if (icode == CODE_FOR_altivec_vcfux
5834 || icode == CODE_FOR_altivec_vcfsx
5835 || icode == CODE_FOR_altivec_vctsxs
5836 || icode == CODE_FOR_altivec_vctuxs
5837 || icode == CODE_FOR_altivec_vspltb
5838 || icode == CODE_FOR_altivec_vsplth
5839 || icode == CODE_FOR_altivec_vspltw
5840 || icode == CODE_FOR_spe_evaddiw
5841 || icode == CODE_FOR_spe_evldd
5842 || icode == CODE_FOR_spe_evldh
5843 || icode == CODE_FOR_spe_evldw
5844 || icode == CODE_FOR_spe_evlhhesplat
5845 || icode == CODE_FOR_spe_evlhhossplat
5846 || icode == CODE_FOR_spe_evlhhousplat
5847 || icode == CODE_FOR_spe_evlwhe
5848 || icode == CODE_FOR_spe_evlwhos
5849 || icode == CODE_FOR_spe_evlwhou
5850 || icode == CODE_FOR_spe_evlwhsplat
5851 || icode == CODE_FOR_spe_evlwwsplat
5852 || icode == CODE_FOR_spe_evrlwi
5853 || icode == CODE_FOR_spe_evslwi
5854 || icode == CODE_FOR_spe_evsrwis
f5119d10 5855 || icode == CODE_FOR_spe_evsubifw
0559cc77 5856 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
5857 {
5858 /* Only allow 5-bit unsigned literals. */
8bb418a3 5859 STRIP_NOPS (arg1);
b44140e7
AH
5860 if (TREE_CODE (arg1) != INTEGER_CST
5861 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5862 {
5863 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 5864 return const0_rtx;
b44140e7 5865 }
b44140e7
AH
5866 }
5867
c62f2db5 5868 if (target == 0
0ac081f6
AH
5869 || GET_MODE (target) != tmode
5870 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5871 target = gen_reg_rtx (tmode);
5872
5873 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5874 op0 = copy_to_mode_reg (mode0, op0);
5875 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5876 op1 = copy_to_mode_reg (mode1, op1);
5877
5878 pat = GEN_FCN (icode) (target, op0, op1);
5879 if (! pat)
5880 return 0;
5881 emit_insn (pat);
5882
5883 return target;
5884}
6525c0e7 5885
ae4b4a02 5886static rtx
a2369ed3
DJ
5887altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
5888 tree arglist, rtx target)
ae4b4a02
AH
5889{
5890 rtx pat, scratch;
5891 tree cr6_form = TREE_VALUE (arglist);
5892 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5893 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5894 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5895 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5896 enum machine_mode tmode = SImode;
5897 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5898 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5899 int cr6_form_int;
5900
5901 if (TREE_CODE (cr6_form) != INTEGER_CST)
5902 {
5903 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5904 return const0_rtx;
ae4b4a02
AH
5905 }
5906 else
5907 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5908
5909 if (mode0 != mode1)
5910 abort ();
5911
5912 /* If we have invalid arguments, bail out before generating bad rtl. */
5913 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5914 return const0_rtx;
ae4b4a02
AH
5915
5916 if (target == 0
5917 || GET_MODE (target) != tmode
5918 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5919 target = gen_reg_rtx (tmode);
5920
5921 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5922 op0 = copy_to_mode_reg (mode0, op0);
5923 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5924 op1 = copy_to_mode_reg (mode1, op1);
5925
5926 scratch = gen_reg_rtx (mode0);
5927
5928 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 5929 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
5930 if (! pat)
5931 return 0;
5932 emit_insn (pat);
5933
5934 /* The vec_any* and vec_all* predicates use the same opcodes for two
5935 different operations, but the bits in CR6 will be different
5936 depending on what information we want. So we have to play tricks
5937 with CR6 to get the right bits out.
5938
5939 If you think this is disgusting, look at the specs for the
5940 AltiVec predicates. */
5941
5942 switch (cr6_form_int)
5943 {
5944 case 0:
5945 emit_insn (gen_cr6_test_for_zero (target));
5946 break;
5947 case 1:
5948 emit_insn (gen_cr6_test_for_zero_reverse (target));
5949 break;
5950 case 2:
5951 emit_insn (gen_cr6_test_for_lt (target));
5952 break;
5953 case 3:
5954 emit_insn (gen_cr6_test_for_lt_reverse (target));
5955 break;
5956 default:
5957 error ("argument 1 of __builtin_altivec_predicate is out of range");
5958 break;
5959 }
5960
5961 return target;
5962}
5963
b4a62fa0 5964static rtx
38f391a5 5965altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
5966{
5967 rtx pat, addr;
5968 tree arg0 = TREE_VALUE (arglist);
5969 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5970 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5971 enum machine_mode mode0 = Pmode;
5972 enum machine_mode mode1 = Pmode;
5973 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5974 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5975
5976 if (icode == CODE_FOR_nothing)
5977 /* Builtin not supported on this processor. */
5978 return 0;
5979
5980 /* If we got invalid arguments bail out before generating bad rtl. */
5981 if (arg0 == error_mark_node || arg1 == error_mark_node)
5982 return const0_rtx;
5983
5984 if (target == 0
5985 || GET_MODE (target) != tmode
5986 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5987 target = gen_reg_rtx (tmode);
5988
5989 op1 = copy_to_mode_reg (mode1, op1);
5990
5991 if (op0 == const0_rtx)
5992 {
5993 addr = gen_rtx_MEM (tmode, op1);
5994 }
5995 else
5996 {
5997 op0 = copy_to_mode_reg (mode0, op0);
5998 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
5999 }
6000
6001 pat = GEN_FCN (icode) (target, addr);
6002
6003 if (! pat)
6004 return 0;
6005 emit_insn (pat);
6006
6007 return target;
6008}
6009
6525c0e7 6010static rtx
a2369ed3 6011altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
6012{
6013 tree arg0 = TREE_VALUE (arglist);
6014 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6015 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6016 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6017 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6018 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
6019 rtx pat, addr;
6020 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6021 enum machine_mode mode1 = Pmode;
6022 enum machine_mode mode2 = Pmode;
6525c0e7
AH
6023
6024 /* Invalid arguments. Bail before doing anything stoopid! */
6025 if (arg0 == error_mark_node
6026 || arg1 == error_mark_node
6027 || arg2 == error_mark_node)
9a171fcd 6028 return const0_rtx;
6525c0e7 6029
b4a62fa0
SB
6030 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
6031 op0 = copy_to_mode_reg (tmode, op0);
6032
6033 op2 = copy_to_mode_reg (mode2, op2);
6034
6035 if (op1 == const0_rtx)
6036 {
6037 addr = gen_rtx_MEM (tmode, op2);
6038 }
6039 else
6040 {
6041 op1 = copy_to_mode_reg (mode1, op1);
6042 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
6043 }
6525c0e7 6044
b4a62fa0 6045 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
6046 if (pat)
6047 emit_insn (pat);
6048 return NULL_RTX;
6049}
6050
2212663f 6051static rtx
a2369ed3 6052rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
6053{
6054 rtx pat;
6055 tree arg0 = TREE_VALUE (arglist);
6056 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6057 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6058 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6059 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6060 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6061 enum machine_mode tmode = insn_data[icode].operand[0].mode;
6062 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6063 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6064 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 6065
774b5662
DE
6066 if (icode == CODE_FOR_nothing)
6067 /* Builtin not supported on this processor. */
6068 return 0;
6069
20e26713
AH
6070 /* If we got invalid arguments bail out before generating bad rtl. */
6071 if (arg0 == error_mark_node
6072 || arg1 == error_mark_node
6073 || arg2 == error_mark_node)
9a171fcd 6074 return const0_rtx;
20e26713 6075
774b5662
DE
6076 if (icode == CODE_FOR_altivec_vsldoi_4sf
6077 || icode == CODE_FOR_altivec_vsldoi_4si
6078 || icode == CODE_FOR_altivec_vsldoi_8hi
6079 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
6080 {
6081 /* Only allow 4-bit unsigned literals. */
8bb418a3 6082 STRIP_NOPS (arg2);
b44140e7
AH
6083 if (TREE_CODE (arg2) != INTEGER_CST
6084 || TREE_INT_CST_LOW (arg2) & ~0xf)
6085 {
6086 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 6087 return const0_rtx;
b44140e7 6088 }
b44140e7
AH
6089 }
6090
c62f2db5 6091 if (target == 0
2212663f
DB
6092 || GET_MODE (target) != tmode
6093 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6094 target = gen_reg_rtx (tmode);
6095
6096 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6097 op0 = copy_to_mode_reg (mode0, op0);
6098 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6099 op1 = copy_to_mode_reg (mode1, op1);
6100 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
6101 op2 = copy_to_mode_reg (mode2, op2);
6102
6103 pat = GEN_FCN (icode) (target, op0, op1, op2);
6104 if (! pat)
6105 return 0;
6106 emit_insn (pat);
6107
6108 return target;
6109}
92898235 6110
3a9b8c7e 6111/* Expand the lvx builtins. */
0ac081f6 6112static rtx
a2369ed3 6113altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 6114{
0ac081f6
AH
6115 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6116 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 6117 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
6118 tree arg0;
6119 enum machine_mode tmode, mode0;
7c3abc73 6120 rtx pat, op0;
3a9b8c7e 6121 enum insn_code icode;
92898235 6122
0ac081f6
AH
6123 switch (fcode)
6124 {
f18c054f
DB
6125 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
6126 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 6127 break;
f18c054f
DB
6128 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
6129 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
6130 break;
6131 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
6132 icode = CODE_FOR_altivec_lvx_4si;
6133 break;
6134 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
6135 icode = CODE_FOR_altivec_lvx_4sf;
6136 break;
6137 default:
6138 *expandedp = false;
6139 return NULL_RTX;
6140 }
0ac081f6 6141
3a9b8c7e 6142 *expandedp = true;
f18c054f 6143
3a9b8c7e
AH
6144 arg0 = TREE_VALUE (arglist);
6145 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6146 tmode = insn_data[icode].operand[0].mode;
6147 mode0 = insn_data[icode].operand[1].mode;
f18c054f 6148
3a9b8c7e
AH
6149 if (target == 0
6150 || GET_MODE (target) != tmode
6151 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6152 target = gen_reg_rtx (tmode);
24408032 6153
3a9b8c7e
AH
6154 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6155 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 6156
3a9b8c7e
AH
6157 pat = GEN_FCN (icode) (target, op0);
6158 if (! pat)
6159 return 0;
6160 emit_insn (pat);
6161 return target;
6162}
f18c054f 6163
3a9b8c7e
AH
6164/* Expand the stvx builtins. */
6165static rtx
a2369ed3
DJ
6166altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
6167 bool *expandedp)
3a9b8c7e
AH
6168{
6169 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6170 tree arglist = TREE_OPERAND (exp, 1);
6171 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6172 tree arg0, arg1;
6173 enum machine_mode mode0, mode1;
7c3abc73 6174 rtx pat, op0, op1;
3a9b8c7e 6175 enum insn_code icode;
f18c054f 6176
3a9b8c7e
AH
6177 switch (fcode)
6178 {
6179 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
6180 icode = CODE_FOR_altivec_stvx_16qi;
6181 break;
6182 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
6183 icode = CODE_FOR_altivec_stvx_8hi;
6184 break;
6185 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
6186 icode = CODE_FOR_altivec_stvx_4si;
6187 break;
6188 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
6189 icode = CODE_FOR_altivec_stvx_4sf;
6190 break;
6191 default:
6192 *expandedp = false;
6193 return NULL_RTX;
6194 }
24408032 6195
3a9b8c7e
AH
6196 arg0 = TREE_VALUE (arglist);
6197 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6198 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6199 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6200 mode0 = insn_data[icode].operand[0].mode;
6201 mode1 = insn_data[icode].operand[1].mode;
f18c054f 6202
3a9b8c7e
AH
6203 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6204 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
6205 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6206 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 6207
3a9b8c7e
AH
6208 pat = GEN_FCN (icode) (op0, op1);
6209 if (pat)
6210 emit_insn (pat);
f18c054f 6211
3a9b8c7e
AH
6212 *expandedp = true;
6213 return NULL_RTX;
6214}
f18c054f 6215
3a9b8c7e
AH
6216/* Expand the dst builtins. */
6217static rtx
a2369ed3
DJ
6218altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
6219 bool *expandedp)
3a9b8c7e
AH
6220{
6221 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6222 tree arglist = TREE_OPERAND (exp, 1);
6223 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6224 tree arg0, arg1, arg2;
6225 enum machine_mode mode0, mode1, mode2;
7c3abc73 6226 rtx pat, op0, op1, op2;
3a9b8c7e 6227 struct builtin_description *d;
a3170dc6 6228 size_t i;
f18c054f 6229
3a9b8c7e 6230 *expandedp = false;
f18c054f 6231
3a9b8c7e
AH
6232 /* Handle DST variants. */
6233 d = (struct builtin_description *) bdesc_dst;
6234 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
6235 if (d->code == fcode)
6236 {
6237 arg0 = TREE_VALUE (arglist);
6238 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6239 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6240 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6241 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6242 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6243 mode0 = insn_data[d->icode].operand[0].mode;
6244 mode1 = insn_data[d->icode].operand[1].mode;
6245 mode2 = insn_data[d->icode].operand[2].mode;
24408032 6246
3a9b8c7e
AH
6247 /* Invalid arguments, bail out before generating bad rtl. */
6248 if (arg0 == error_mark_node
6249 || arg1 == error_mark_node
6250 || arg2 == error_mark_node)
6251 return const0_rtx;
f18c054f 6252
86e7df90 6253 *expandedp = true;
8bb418a3 6254 STRIP_NOPS (arg2);
3a9b8c7e
AH
6255 if (TREE_CODE (arg2) != INTEGER_CST
6256 || TREE_INT_CST_LOW (arg2) & ~0x3)
6257 {
6258 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
6259 return const0_rtx;
6260 }
f18c054f 6261
3a9b8c7e 6262 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 6263 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
6264 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
6265 op1 = copy_to_mode_reg (mode1, op1);
24408032 6266
3a9b8c7e
AH
6267 pat = GEN_FCN (d->icode) (op0, op1, op2);
6268 if (pat != 0)
6269 emit_insn (pat);
f18c054f 6270
3a9b8c7e
AH
6271 return NULL_RTX;
6272 }
f18c054f 6273
3a9b8c7e
AH
6274 return NULL_RTX;
6275}
24408032 6276
3a9b8c7e
AH
6277/* Expand the builtin in EXP and store the result in TARGET. Store
6278 true in *EXPANDEDP if we found a builtin to expand. */
6279static rtx
a2369ed3 6280altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
6281{
6282 struct builtin_description *d;
6283 struct builtin_description_predicates *dp;
6284 size_t i;
6285 enum insn_code icode;
6286 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6287 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
6288 tree arg0;
6289 rtx op0, pat;
6290 enum machine_mode tmode, mode0;
3a9b8c7e 6291 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 6292
3a9b8c7e
AH
6293 target = altivec_expand_ld_builtin (exp, target, expandedp);
6294 if (*expandedp)
6295 return target;
0ac081f6 6296
3a9b8c7e
AH
6297 target = altivec_expand_st_builtin (exp, target, expandedp);
6298 if (*expandedp)
6299 return target;
6300
6301 target = altivec_expand_dst_builtin (exp, target, expandedp);
6302 if (*expandedp)
6303 return target;
6304
6305 *expandedp = true;
95385cbb 6306
3a9b8c7e
AH
6307 switch (fcode)
6308 {
6525c0e7
AH
6309 case ALTIVEC_BUILTIN_STVX:
6310 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
6311 case ALTIVEC_BUILTIN_STVEBX:
6312 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
6313 case ALTIVEC_BUILTIN_STVEHX:
6314 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
6315 case ALTIVEC_BUILTIN_STVEWX:
6316 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
6317 case ALTIVEC_BUILTIN_STVXL:
6318 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 6319
95385cbb
AH
6320 case ALTIVEC_BUILTIN_MFVSCR:
6321 icode = CODE_FOR_altivec_mfvscr;
6322 tmode = insn_data[icode].operand[0].mode;
6323
6324 if (target == 0
6325 || GET_MODE (target) != tmode
6326 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6327 target = gen_reg_rtx (tmode);
6328
6329 pat = GEN_FCN (icode) (target);
0ac081f6
AH
6330 if (! pat)
6331 return 0;
6332 emit_insn (pat);
95385cbb
AH
6333 return target;
6334
6335 case ALTIVEC_BUILTIN_MTVSCR:
6336 icode = CODE_FOR_altivec_mtvscr;
6337 arg0 = TREE_VALUE (arglist);
6338 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6339 mode0 = insn_data[icode].operand[0].mode;
6340
6341 /* If we got invalid arguments bail out before generating bad rtl. */
6342 if (arg0 == error_mark_node)
9a171fcd 6343 return const0_rtx;
95385cbb
AH
6344
6345 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6346 op0 = copy_to_mode_reg (mode0, op0);
6347
6348 pat = GEN_FCN (icode) (op0);
6349 if (pat)
6350 emit_insn (pat);
6351 return NULL_RTX;
3a9b8c7e 6352
95385cbb
AH
6353 case ALTIVEC_BUILTIN_DSSALL:
6354 emit_insn (gen_altivec_dssall ());
6355 return NULL_RTX;
6356
6357 case ALTIVEC_BUILTIN_DSS:
6358 icode = CODE_FOR_altivec_dss;
6359 arg0 = TREE_VALUE (arglist);
8bb418a3 6360 STRIP_NOPS (arg0);
95385cbb
AH
6361 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6362 mode0 = insn_data[icode].operand[0].mode;
6363
6364 /* If we got invalid arguments bail out before generating bad rtl. */
6365 if (arg0 == error_mark_node)
9a171fcd 6366 return const0_rtx;
95385cbb 6367
b44140e7
AH
6368 if (TREE_CODE (arg0) != INTEGER_CST
6369 || TREE_INT_CST_LOW (arg0) & ~0x3)
6370 {
6371 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6372 return const0_rtx;
b44140e7
AH
6373 }
6374
95385cbb
AH
6375 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6376 op0 = copy_to_mode_reg (mode0, op0);
6377
6378 emit_insn (gen_altivec_dss (op0));
0ac081f6 6379 return NULL_RTX;
8bb418a3
ZL
6380
6381 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
6382 arg0 = TREE_VALUE (arglist);
6383 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR)
6384 arg0 = TREE_OPERAND (arg0, 0);
6385 error ("invalid parameter combination for `%s' AltiVec intrinsic",
6386 TREE_STRING_POINTER (arg0));
6387
6388 return const0_rtx;
0ac081f6 6389 }
24408032 6390
100c4561
AH
6391 /* Expand abs* operations. */
6392 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6393 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6394 if (d->code == fcode)
6395 return altivec_expand_abs_builtin (d->icode, arglist, target);
6396
ae4b4a02
AH
6397 /* Expand the AltiVec predicates. */
6398 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6399 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
6400 if (dp->code == fcode)
6401 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
6402
6525c0e7
AH
6403 /* LV* are funky. We initialized them differently. */
6404 switch (fcode)
6405 {
6406 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6407 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
6408 arglist, target);
6409 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6410 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
92898235 6411 arglist, target);
6525c0e7 6412 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6413 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
92898235 6414 arglist, target);
6525c0e7 6415 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6416 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
92898235 6417 arglist, target);
6525c0e7 6418 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6419 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
92898235 6420 arglist, target);
6525c0e7 6421 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6422 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
92898235 6423 arglist, target);
6525c0e7 6424 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6425 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
92898235 6426 arglist, target);
6525c0e7
AH
6427 default:
6428 break;
6429 /* Fall through. */
6430 }
95385cbb 6431
92898235 6432 *expandedp = false;
0ac081f6
AH
6433 return NULL_RTX;
6434}
6435
a3170dc6
AH
6436/* Binops that need to be initialized manually, but can be expanded
6437 automagically by rs6000_expand_binop_builtin. */
6438static struct builtin_description bdesc_2arg_spe[] =
6439{
6440 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6441 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6442 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6443 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6444 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6445 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6446 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6447 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6448 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6449 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6450 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6451 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6452 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6453 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6454 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6455 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6456 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6457 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6458 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6459 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6460 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6461 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6462};
6463
6464/* Expand the builtin in EXP and store the result in TARGET. Store
6465 true in *EXPANDEDP if we found a builtin to expand.
6466
6467 This expands the SPE builtins that are not simple unary and binary
6468 operations. */
6469static rtx
a2369ed3 6470spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6471{
6472 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6473 tree arglist = TREE_OPERAND (exp, 1);
6474 tree arg1, arg0;
6475 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6476 enum insn_code icode;
6477 enum machine_mode tmode, mode0;
6478 rtx pat, op0;
6479 struct builtin_description *d;
6480 size_t i;
6481
6482 *expandedp = true;
6483
6484 /* Syntax check for a 5-bit unsigned immediate. */
6485 switch (fcode)
6486 {
6487 case SPE_BUILTIN_EVSTDD:
6488 case SPE_BUILTIN_EVSTDH:
6489 case SPE_BUILTIN_EVSTDW:
6490 case SPE_BUILTIN_EVSTWHE:
6491 case SPE_BUILTIN_EVSTWHO:
6492 case SPE_BUILTIN_EVSTWWE:
6493 case SPE_BUILTIN_EVSTWWO:
6494 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6495 if (TREE_CODE (arg1) != INTEGER_CST
6496 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6497 {
6498 error ("argument 2 must be a 5-bit unsigned literal");
6499 return const0_rtx;
6500 }
6501 break;
6502 default:
6503 break;
6504 }
6505
00332c9f
AH
6506 /* The evsplat*i instructions are not quite generic. */
6507 switch (fcode)
6508 {
6509 case SPE_BUILTIN_EVSPLATFI:
6510 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6511 arglist, target);
6512 case SPE_BUILTIN_EVSPLATI:
6513 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
6514 arglist, target);
6515 default:
6516 break;
6517 }
6518
a3170dc6
AH
6519 d = (struct builtin_description *) bdesc_2arg_spe;
6520 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
6521 if (d->code == fcode)
6522 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6523
6524 d = (struct builtin_description *) bdesc_spe_predicates;
6525 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
6526 if (d->code == fcode)
6527 return spe_expand_predicate_builtin (d->icode, arglist, target);
6528
6529 d = (struct builtin_description *) bdesc_spe_evsel;
6530 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
6531 if (d->code == fcode)
6532 return spe_expand_evsel_builtin (d->icode, arglist, target);
6533
6534 switch (fcode)
6535 {
6536 case SPE_BUILTIN_EVSTDDX:
6537 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
6538 case SPE_BUILTIN_EVSTDHX:
6539 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
6540 case SPE_BUILTIN_EVSTDWX:
6541 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
6542 case SPE_BUILTIN_EVSTWHEX:
6543 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
6544 case SPE_BUILTIN_EVSTWHOX:
6545 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
6546 case SPE_BUILTIN_EVSTWWEX:
6547 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
6548 case SPE_BUILTIN_EVSTWWOX:
6549 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
6550 case SPE_BUILTIN_EVSTDD:
6551 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
6552 case SPE_BUILTIN_EVSTDH:
6553 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
6554 case SPE_BUILTIN_EVSTDW:
6555 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
6556 case SPE_BUILTIN_EVSTWHE:
6557 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
6558 case SPE_BUILTIN_EVSTWHO:
6559 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
6560 case SPE_BUILTIN_EVSTWWE:
6561 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
6562 case SPE_BUILTIN_EVSTWWO:
6563 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
6564 case SPE_BUILTIN_MFSPEFSCR:
6565 icode = CODE_FOR_spe_mfspefscr;
6566 tmode = insn_data[icode].operand[0].mode;
6567
6568 if (target == 0
6569 || GET_MODE (target) != tmode
6570 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6571 target = gen_reg_rtx (tmode);
6572
6573 pat = GEN_FCN (icode) (target);
6574 if (! pat)
6575 return 0;
6576 emit_insn (pat);
6577 return target;
6578 case SPE_BUILTIN_MTSPEFSCR:
6579 icode = CODE_FOR_spe_mtspefscr;
6580 arg0 = TREE_VALUE (arglist);
6581 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6582 mode0 = insn_data[icode].operand[0].mode;
6583
6584 if (arg0 == error_mark_node)
6585 return const0_rtx;
6586
6587 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6588 op0 = copy_to_mode_reg (mode0, op0);
6589
6590 pat = GEN_FCN (icode) (op0);
6591 if (pat)
6592 emit_insn (pat);
6593 return NULL_RTX;
6594 default:
6595 break;
6596 }
6597
6598 *expandedp = false;
6599 return NULL_RTX;
6600}
6601
6602static rtx
a2369ed3 6603spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6604{
6605 rtx pat, scratch, tmp;
6606 tree form = TREE_VALUE (arglist);
6607 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6608 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6609 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6610 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6611 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6612 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6613 int form_int;
6614 enum rtx_code code;
6615
6616 if (TREE_CODE (form) != INTEGER_CST)
6617 {
6618 error ("argument 1 of __builtin_spe_predicate must be a constant");
6619 return const0_rtx;
6620 }
6621 else
6622 form_int = TREE_INT_CST_LOW (form);
6623
6624 if (mode0 != mode1)
6625 abort ();
6626
6627 if (arg0 == error_mark_node || arg1 == error_mark_node)
6628 return const0_rtx;
6629
6630 if (target == 0
6631 || GET_MODE (target) != SImode
6632 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
6633 target = gen_reg_rtx (SImode);
6634
6635 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6636 op0 = copy_to_mode_reg (mode0, op0);
6637 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6638 op1 = copy_to_mode_reg (mode1, op1);
6639
6640 scratch = gen_reg_rtx (CCmode);
6641
6642 pat = GEN_FCN (icode) (scratch, op0, op1);
6643 if (! pat)
6644 return const0_rtx;
6645 emit_insn (pat);
6646
6647 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
6648 _lower_. We use one compare, but look in different bits of the
6649 CR for each variant.
6650
6651 There are 2 elements in each SPE simd type (upper/lower). The CR
6652 bits are set as follows:
6653
6654 BIT0 | BIT 1 | BIT 2 | BIT 3
6655 U | L | (U | L) | (U & L)
6656
6657 So, for an "all" relationship, BIT 3 would be set.
6658 For an "any" relationship, BIT 2 would be set. Etc.
6659
6660 Following traditional nomenclature, these bits map to:
6661
6662 BIT0 | BIT 1 | BIT 2 | BIT 3
6663 LT | GT | EQ | OV
6664
6665 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
6666 */
6667
6668 switch (form_int)
6669 {
6670 /* All variant. OV bit. */
6671 case 0:
6672 /* We need to get to the OV bit, which is the ORDERED bit. We
6673 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
6674 that's ugly and will trigger a validate_condition_mode abort.
6675 So let's just use another pattern. */
6676 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
6677 return target;
6678 /* Any variant. EQ bit. */
6679 case 1:
6680 code = EQ;
6681 break;
6682 /* Upper variant. LT bit. */
6683 case 2:
6684 code = LT;
6685 break;
6686 /* Lower variant. GT bit. */
6687 case 3:
6688 code = GT;
6689 break;
6690 default:
6691 error ("argument 1 of __builtin_spe_predicate is out of range");
6692 return const0_rtx;
6693 }
6694
6695 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
6696 emit_move_insn (target, tmp);
6697
6698 return target;
6699}
6700
6701/* The evsel builtins look like this:
6702
6703 e = __builtin_spe_evsel_OP (a, b, c, d);
6704
6705 and work like this:
6706
6707 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
6708 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
6709*/
6710
6711static rtx
a2369ed3 6712spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6713{
6714 rtx pat, scratch;
6715 tree arg0 = TREE_VALUE (arglist);
6716 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6717 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6718 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
6719 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6720 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6721 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6722 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
6723 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6724 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6725
6726 if (mode0 != mode1)
6727 abort ();
6728
6729 if (arg0 == error_mark_node || arg1 == error_mark_node
6730 || arg2 == error_mark_node || arg3 == error_mark_node)
6731 return const0_rtx;
6732
6733 if (target == 0
6734 || GET_MODE (target) != mode0
6735 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
6736 target = gen_reg_rtx (mode0);
6737
6738 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6739 op0 = copy_to_mode_reg (mode0, op0);
6740 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6741 op1 = copy_to_mode_reg (mode0, op1);
6742 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6743 op2 = copy_to_mode_reg (mode0, op2);
6744 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
6745 op3 = copy_to_mode_reg (mode0, op3);
6746
6747 /* Generate the compare. */
6748 scratch = gen_reg_rtx (CCmode);
6749 pat = GEN_FCN (icode) (scratch, op0, op1);
6750 if (! pat)
6751 return const0_rtx;
6752 emit_insn (pat);
6753
6754 if (mode0 == V2SImode)
6755 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
6756 else
6757 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
6758
6759 return target;
6760}
6761
0ac081f6
AH
6762/* Expand an expression EXP that calls a built-in function,
6763 with result going to TARGET if that's convenient
6764 (and in mode MODE if that's convenient).
6765 SUBTARGET may be used as the target for computing one of EXP's operands.
6766 IGNORE is nonzero if the value is to be ignored. */
6767
6768static rtx
a2369ed3
DJ
6769rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
6770 enum machine_mode mode ATTRIBUTE_UNUSED,
6771 int ignore ATTRIBUTE_UNUSED)
0ac081f6 6772{
92898235
AH
6773 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6774 tree arglist = TREE_OPERAND (exp, 1);
6775 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6776 struct builtin_description *d;
6777 size_t i;
6778 rtx ret;
6779 bool success;
6780
0ac081f6 6781 if (TARGET_ALTIVEC)
92898235
AH
6782 {
6783 ret = altivec_expand_builtin (exp, target, &success);
6784
a3170dc6
AH
6785 if (success)
6786 return ret;
6787 }
6788 if (TARGET_SPE)
6789 {
6790 ret = spe_expand_builtin (exp, target, &success);
6791
92898235
AH
6792 if (success)
6793 return ret;
6794 }
6795
0559cc77
DE
6796 if (TARGET_ALTIVEC || TARGET_SPE)
6797 {
6798 /* Handle simple unary operations. */
6799 d = (struct builtin_description *) bdesc_1arg;
6800 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
6801 if (d->code == fcode)
6802 return rs6000_expand_unop_builtin (d->icode, arglist, target);
6803
6804 /* Handle simple binary operations. */
6805 d = (struct builtin_description *) bdesc_2arg;
6806 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
6807 if (d->code == fcode)
6808 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6809
6810 /* Handle simple ternary operations. */
6811 d = (struct builtin_description *) bdesc_3arg;
6812 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
6813 if (d->code == fcode)
6814 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
6815 }
0ac081f6
AH
6816
6817 abort ();
92898235 6818 return NULL_RTX;
0ac081f6
AH
6819}
6820
7c62e993
PB
6821static tree
6822build_opaque_vector_type (tree node, int nunits)
6823{
6824 node = copy_node (node);
6825 TYPE_MAIN_VARIANT (node) = node;
6826 return build_vector_type (node, nunits);
6827}
6828
0ac081f6 6829static void
863d938c 6830rs6000_init_builtins (void)
0ac081f6 6831{
4a5eab38
PB
6832 V2SI_type_node = build_vector_type (intSI_type_node, 2);
6833 V2SF_type_node = build_vector_type (float_type_node, 2);
6834 V4HI_type_node = build_vector_type (intHI_type_node, 4);
6835 V4SI_type_node = build_vector_type (intSI_type_node, 4);
6836 V4SF_type_node = build_vector_type (float_type_node, 4);
7e463bda 6837 V8HI_type_node = build_vector_type (intHI_type_node, 8);
4a5eab38
PB
6838 V16QI_type_node = build_vector_type (intQI_type_node, 16);
6839
6840 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
6841 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
6842 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
6843
7c62e993
PB
6844 opaque_V2SF_type_node = build_opaque_vector_type (float_type_node, 2);
6845 opaque_V2SI_type_node = build_opaque_vector_type (intSI_type_node, 2);
6035d635 6846 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 6847
8bb418a3
ZL
6848 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
6849 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
6850 'vector unsigned short'. */
6851
6852 bool_char_type_node = copy_node (unsigned_intQI_type_node);
6853 TYPE_MAIN_VARIANT (bool_char_type_node) = bool_char_type_node;
6854 bool_short_type_node = copy_node (unsigned_intHI_type_node);
6855 TYPE_MAIN_VARIANT (bool_short_type_node) = bool_short_type_node;
6856 bool_int_type_node = copy_node (unsigned_intSI_type_node);
6857 TYPE_MAIN_VARIANT (bool_int_type_node) = bool_int_type_node;
6858 pixel_type_node = copy_node (unsigned_intHI_type_node);
6859 TYPE_MAIN_VARIANT (pixel_type_node) = pixel_type_node;
6860
6861 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6862 get_identifier ("__bool char"),
6863 bool_char_type_node));
6864 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6865 get_identifier ("__bool short"),
6866 bool_short_type_node));
6867 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6868 get_identifier ("__bool int"),
6869 bool_int_type_node));
6870 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6871 get_identifier ("__pixel"),
6872 pixel_type_node));
6873
4a5eab38
PB
6874 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
6875 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
6876 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
6877 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
8bb418a3
ZL
6878
6879 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6880 get_identifier ("__vector unsigned char"),
6881 unsigned_V16QI_type_node));
6882 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6883 get_identifier ("__vector signed char"),
6884 V16QI_type_node));
6885 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6886 get_identifier ("__vector __bool char"),
6887 bool_V16QI_type_node));
6888
6889 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6890 get_identifier ("__vector unsigned short"),
6891 unsigned_V8HI_type_node));
6892 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6893 get_identifier ("__vector signed short"),
6894 V8HI_type_node));
6895 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6896 get_identifier ("__vector __bool short"),
6897 bool_V8HI_type_node));
6898
6899 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6900 get_identifier ("__vector unsigned int"),
6901 unsigned_V4SI_type_node));
6902 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6903 get_identifier ("__vector signed int"),
6904 V4SI_type_node));
6905 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6906 get_identifier ("__vector __bool int"),
6907 bool_V4SI_type_node));
6908
6909 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6910 get_identifier ("__vector float"),
6911 V4SF_type_node));
6912 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6913 get_identifier ("__vector __pixel"),
6914 pixel_V8HI_type_node));
6915
a3170dc6 6916 if (TARGET_SPE)
3fdaa45a 6917 spe_init_builtins ();
0ac081f6
AH
6918 if (TARGET_ALTIVEC)
6919 altivec_init_builtins ();
0559cc77
DE
6920 if (TARGET_ALTIVEC || TARGET_SPE)
6921 rs6000_common_init_builtins ();
0ac081f6
AH
6922}
6923
a3170dc6
AH
6924/* Search through a set of builtins and enable the mask bits.
6925 DESC is an array of builtins.
b6d08ca1 6926 SIZE is the total number of builtins.
a3170dc6
AH
6927 START is the builtin enum at which to start.
6928 END is the builtin enum at which to end. */
0ac081f6 6929static void
a2369ed3
DJ
6930enable_mask_for_builtins (struct builtin_description *desc, int size,
6931 enum rs6000_builtins start,
6932 enum rs6000_builtins end)
a3170dc6
AH
6933{
6934 int i;
6935
6936 for (i = 0; i < size; ++i)
6937 if (desc[i].code == start)
6938 break;
6939
6940 if (i == size)
6941 return;
6942
6943 for (; i < size; ++i)
6944 {
6945 /* Flip all the bits on. */
6946 desc[i].mask = target_flags;
6947 if (desc[i].code == end)
6948 break;
6949 }
6950}
6951
6952static void
863d938c 6953spe_init_builtins (void)
0ac081f6 6954{
a3170dc6
AH
6955 tree endlink = void_list_node;
6956 tree puint_type_node = build_pointer_type (unsigned_type_node);
6957 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 6958 struct builtin_description *d;
0ac081f6
AH
6959 size_t i;
6960
a3170dc6
AH
6961 tree v2si_ftype_4_v2si
6962 = build_function_type
3fdaa45a
AH
6963 (opaque_V2SI_type_node,
6964 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6965 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6966 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6967 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6968 endlink)))));
6969
6970 tree v2sf_ftype_4_v2sf
6971 = build_function_type
3fdaa45a
AH
6972 (opaque_V2SF_type_node,
6973 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6974 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6975 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6976 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6977 endlink)))));
6978
6979 tree int_ftype_int_v2si_v2si
6980 = build_function_type
6981 (integer_type_node,
6982 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6983 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6984 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6985 endlink))));
6986
6987 tree int_ftype_int_v2sf_v2sf
6988 = build_function_type
6989 (integer_type_node,
6990 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6991 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6992 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6993 endlink))));
6994
6995 tree void_ftype_v2si_puint_int
6996 = build_function_type (void_type_node,
3fdaa45a 6997 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6998 tree_cons (NULL_TREE, puint_type_node,
6999 tree_cons (NULL_TREE,
7000 integer_type_node,
7001 endlink))));
7002
7003 tree void_ftype_v2si_puint_char
7004 = build_function_type (void_type_node,
3fdaa45a 7005 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
7006 tree_cons (NULL_TREE, puint_type_node,
7007 tree_cons (NULL_TREE,
7008 char_type_node,
7009 endlink))));
7010
7011 tree void_ftype_v2si_pv2si_int
7012 = build_function_type (void_type_node,
3fdaa45a 7013 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7014 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7015 tree_cons (NULL_TREE,
7016 integer_type_node,
7017 endlink))));
7018
7019 tree void_ftype_v2si_pv2si_char
7020 = build_function_type (void_type_node,
3fdaa45a 7021 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 7022 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7023 tree_cons (NULL_TREE,
7024 char_type_node,
7025 endlink))));
7026
7027 tree void_ftype_int
7028 = build_function_type (void_type_node,
7029 tree_cons (NULL_TREE, integer_type_node, endlink));
7030
7031 tree int_ftype_void
36e8d515 7032 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
7033
7034 tree v2si_ftype_pv2si_int
3fdaa45a 7035 = build_function_type (opaque_V2SI_type_node,
6035d635 7036 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
7037 tree_cons (NULL_TREE, integer_type_node,
7038 endlink)));
7039
7040 tree v2si_ftype_puint_int
3fdaa45a 7041 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7042 tree_cons (NULL_TREE, puint_type_node,
7043 tree_cons (NULL_TREE, integer_type_node,
7044 endlink)));
7045
7046 tree v2si_ftype_pushort_int
3fdaa45a 7047 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
7048 tree_cons (NULL_TREE, pushort_type_node,
7049 tree_cons (NULL_TREE, integer_type_node,
7050 endlink)));
7051
00332c9f
AH
7052 tree v2si_ftype_signed_char
7053 = build_function_type (opaque_V2SI_type_node,
7054 tree_cons (NULL_TREE, signed_char_type_node,
7055 endlink));
7056
a3170dc6
AH
7057 /* The initialization of the simple binary and unary builtins is
7058 done in rs6000_common_init_builtins, but we have to enable the
7059 mask bits here manually because we have run out of `target_flags'
7060 bits. We really need to redesign this mask business. */
7061
7062 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
7063 ARRAY_SIZE (bdesc_2arg),
7064 SPE_BUILTIN_EVADDW,
7065 SPE_BUILTIN_EVXOR);
7066 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
7067 ARRAY_SIZE (bdesc_1arg),
7068 SPE_BUILTIN_EVABS,
7069 SPE_BUILTIN_EVSUBFUSIAAW);
7070 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
7071 ARRAY_SIZE (bdesc_spe_predicates),
7072 SPE_BUILTIN_EVCMPEQ,
7073 SPE_BUILTIN_EVFSTSTLT);
7074 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
7075 ARRAY_SIZE (bdesc_spe_evsel),
7076 SPE_BUILTIN_EVSEL_CMPGTS,
7077 SPE_BUILTIN_EVSEL_FSTSTEQ);
7078
36252949
AH
7079 (*lang_hooks.decls.pushdecl)
7080 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
7081 opaque_V2SI_type_node));
7082
a3170dc6
AH
7083 /* Initialize irregular SPE builtins. */
7084
7085 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
7086 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
7087 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
7088 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
7089 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
7090 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
7091 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
7092 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
7093 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
7094 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
7095 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
7096 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
7097 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
7098 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
7099 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
7100 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
7101 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
7102 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
7103
7104 /* Loads. */
7105 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
7106 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
7107 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
7108 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
7109 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
7110 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
7111 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
7112 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
7113 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
7114 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
7115 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
7116 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
7117 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
7118 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
7119 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
7120 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
7121 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
7122 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
7123 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
7124 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
7125 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
7126 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
7127
7128 /* Predicates. */
7129 d = (struct builtin_description *) bdesc_spe_predicates;
7130 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
7131 {
7132 tree type;
7133
7134 switch (insn_data[d->icode].operand[1].mode)
7135 {
7136 case V2SImode:
7137 type = int_ftype_int_v2si_v2si;
7138 break;
7139 case V2SFmode:
7140 type = int_ftype_int_v2sf_v2sf;
7141 break;
7142 default:
7143 abort ();
7144 }
7145
7146 def_builtin (d->mask, d->name, type, d->code);
7147 }
7148
7149 /* Evsel predicates. */
7150 d = (struct builtin_description *) bdesc_spe_evsel;
7151 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
7152 {
7153 tree type;
7154
7155 switch (insn_data[d->icode].operand[1].mode)
7156 {
7157 case V2SImode:
7158 type = v2si_ftype_4_v2si;
7159 break;
7160 case V2SFmode:
7161 type = v2sf_ftype_4_v2sf;
7162 break;
7163 default:
7164 abort ();
7165 }
7166
7167 def_builtin (d->mask, d->name, type, d->code);
7168 }
7169}
7170
7171static void
863d938c 7172altivec_init_builtins (void)
a3170dc6
AH
7173{
7174 struct builtin_description *d;
7175 struct builtin_description_predicates *dp;
7176 size_t i;
7177 tree pfloat_type_node = build_pointer_type (float_type_node);
7178 tree pint_type_node = build_pointer_type (integer_type_node);
7179 tree pshort_type_node = build_pointer_type (short_integer_type_node);
7180 tree pchar_type_node = build_pointer_type (char_type_node);
7181
7182 tree pvoid_type_node = build_pointer_type (void_type_node);
7183
0dbc3651
ZW
7184 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
7185 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
7186 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
7187 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
7188
7189 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
7190
a3170dc6
AH
7191 tree int_ftype_int_v4si_v4si
7192 = build_function_type_list (integer_type_node,
7193 integer_type_node, V4SI_type_node,
7194 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7195 tree v4sf_ftype_pcfloat
7196 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 7197 tree void_ftype_pfloat_v4sf
b4de2f7d 7198 = build_function_type_list (void_type_node,
a3170dc6 7199 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
7200 tree v4si_ftype_pcint
7201 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
7202 tree void_ftype_pint_v4si
b4de2f7d
AH
7203 = build_function_type_list (void_type_node,
7204 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
7205 tree v8hi_ftype_pcshort
7206 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 7207 tree void_ftype_pshort_v8hi
b4de2f7d
AH
7208 = build_function_type_list (void_type_node,
7209 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
7210 tree v16qi_ftype_pcchar
7211 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 7212 tree void_ftype_pchar_v16qi
b4de2f7d
AH
7213 = build_function_type_list (void_type_node,
7214 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 7215 tree void_ftype_v4si
b4de2f7d 7216 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7217 tree v8hi_ftype_void
7218 = build_function_type (V8HI_type_node, void_list_node);
7219 tree void_ftype_void
7220 = build_function_type (void_type_node, void_list_node);
7221 tree void_ftype_qi
7222 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651 7223
b4a62fa0 7224 tree v16qi_ftype_long_pcvoid
a3170dc6 7225 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
7226 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7227 tree v8hi_ftype_long_pcvoid
a3170dc6 7228 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
7229 long_integer_type_node, pcvoid_type_node, NULL_TREE);
7230 tree v4si_ftype_long_pcvoid
a3170dc6 7231 = build_function_type_list (V4SI_type_node,
b4a62fa0 7232 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 7233
b4a62fa0 7234 tree void_ftype_v4si_long_pvoid
b4de2f7d 7235 = build_function_type_list (void_type_node,
b4a62fa0 7236 V4SI_type_node, long_integer_type_node,
b4de2f7d 7237 pvoid_type_node, NULL_TREE);
b4a62fa0 7238 tree void_ftype_v16qi_long_pvoid
b4de2f7d 7239 = build_function_type_list (void_type_node,
b4a62fa0 7240 V16QI_type_node, long_integer_type_node,
b4de2f7d 7241 pvoid_type_node, NULL_TREE);
b4a62fa0 7242 tree void_ftype_v8hi_long_pvoid
b4de2f7d 7243 = build_function_type_list (void_type_node,
b4a62fa0 7244 V8HI_type_node, long_integer_type_node,
b4de2f7d 7245 pvoid_type_node, NULL_TREE);
a3170dc6
AH
7246 tree int_ftype_int_v8hi_v8hi
7247 = build_function_type_list (integer_type_node,
7248 integer_type_node, V8HI_type_node,
7249 V8HI_type_node, NULL_TREE);
7250 tree int_ftype_int_v16qi_v16qi
7251 = build_function_type_list (integer_type_node,
7252 integer_type_node, V16QI_type_node,
7253 V16QI_type_node, NULL_TREE);
7254 tree int_ftype_int_v4sf_v4sf
7255 = build_function_type_list (integer_type_node,
7256 integer_type_node, V4SF_type_node,
7257 V4SF_type_node, NULL_TREE);
7258 tree v4si_ftype_v4si
7259 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
7260 tree v8hi_ftype_v8hi
7261 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
7262 tree v16qi_ftype_v16qi
7263 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
7264 tree v4sf_ftype_v4sf
7265 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 7266 tree void_ftype_pcvoid_int_int
a3170dc6 7267 = build_function_type_list (void_type_node,
0dbc3651 7268 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
7269 integer_type_node, NULL_TREE);
7270 tree int_ftype_pcchar
7271 = build_function_type_list (integer_type_node,
7272 pcchar_type_node, NULL_TREE);
7273
0dbc3651
ZW
7274 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
7275 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
7276 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
7277 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
7278 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
7279 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
7280 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
7281 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
7282 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
7283 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
7284 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
7285 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
7286 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
7287 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
7288 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
7289 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
7290 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
7291 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
7292 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
7293 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
7294 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
7295 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
7296 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
7297 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
7298 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
7299 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
7300 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
7301 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
7302 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
7303 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
7304 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
7305 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 7306
8bb418a3
ZL
7307 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
7308 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
7309 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
7310
a3170dc6
AH
7311 /* Add the DST variants. */
7312 d = (struct builtin_description *) bdesc_dst;
7313 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 7314 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
7315
7316 /* Initialize the predicates. */
7317 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
7318 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
7319 {
7320 enum machine_mode mode1;
7321 tree type;
7322
7323 mode1 = insn_data[dp->icode].operand[1].mode;
7324
7325 switch (mode1)
7326 {
7327 case V4SImode:
7328 type = int_ftype_int_v4si_v4si;
7329 break;
7330 case V8HImode:
7331 type = int_ftype_int_v8hi_v8hi;
7332 break;
7333 case V16QImode:
7334 type = int_ftype_int_v16qi_v16qi;
7335 break;
7336 case V4SFmode:
7337 type = int_ftype_int_v4sf_v4sf;
7338 break;
7339 default:
7340 abort ();
7341 }
7342
7343 def_builtin (dp->mask, dp->name, type, dp->code);
7344 }
7345
7346 /* Initialize the abs* operators. */
7347 d = (struct builtin_description *) bdesc_abs;
7348 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
7349 {
7350 enum machine_mode mode0;
7351 tree type;
7352
7353 mode0 = insn_data[d->icode].operand[0].mode;
7354
7355 switch (mode0)
7356 {
7357 case V4SImode:
7358 type = v4si_ftype_v4si;
7359 break;
7360 case V8HImode:
7361 type = v8hi_ftype_v8hi;
7362 break;
7363 case V16QImode:
7364 type = v16qi_ftype_v16qi;
7365 break;
7366 case V4SFmode:
7367 type = v4sf_ftype_v4sf;
7368 break;
7369 default:
7370 abort ();
7371 }
7372
7373 def_builtin (d->mask, d->name, type, d->code);
7374 }
7375}
7376
7377static void
863d938c 7378rs6000_common_init_builtins (void)
a3170dc6
AH
7379{
7380 struct builtin_description *d;
7381 size_t i;
7382
7383 tree v4sf_ftype_v4sf_v4sf_v16qi
7384 = build_function_type_list (V4SF_type_node,
7385 V4SF_type_node, V4SF_type_node,
7386 V16QI_type_node, NULL_TREE);
7387 tree v4si_ftype_v4si_v4si_v16qi
7388 = build_function_type_list (V4SI_type_node,
7389 V4SI_type_node, V4SI_type_node,
7390 V16QI_type_node, NULL_TREE);
7391 tree v8hi_ftype_v8hi_v8hi_v16qi
7392 = build_function_type_list (V8HI_type_node,
7393 V8HI_type_node, V8HI_type_node,
7394 V16QI_type_node, NULL_TREE);
7395 tree v16qi_ftype_v16qi_v16qi_v16qi
7396 = build_function_type_list (V16QI_type_node,
7397 V16QI_type_node, V16QI_type_node,
7398 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
7399 tree v4si_ftype_int
7400 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
7401 tree v8hi_ftype_int
7402 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
7403 tree v16qi_ftype_int
7404 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
7405 tree v8hi_ftype_v16qi
7406 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
7407 tree v4sf_ftype_v4sf
7408 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
7409
7410 tree v2si_ftype_v2si_v2si
2abe3e28
AH
7411 = build_function_type_list (opaque_V2SI_type_node,
7412 opaque_V2SI_type_node,
7413 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7414
7415 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
7416 = build_function_type_list (opaque_V2SF_type_node,
7417 opaque_V2SF_type_node,
7418 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7419
7420 tree v2si_ftype_int_int
2abe3e28 7421 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7422 integer_type_node, integer_type_node,
7423 NULL_TREE);
7424
7425 tree v2si_ftype_v2si
2abe3e28
AH
7426 = build_function_type_list (opaque_V2SI_type_node,
7427 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7428
7429 tree v2sf_ftype_v2sf
2abe3e28
AH
7430 = build_function_type_list (opaque_V2SF_type_node,
7431 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7432
7433 tree v2sf_ftype_v2si
2abe3e28
AH
7434 = build_function_type_list (opaque_V2SF_type_node,
7435 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7436
7437 tree v2si_ftype_v2sf
2abe3e28
AH
7438 = build_function_type_list (opaque_V2SI_type_node,
7439 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7440
7441 tree v2si_ftype_v2si_char
2abe3e28
AH
7442 = build_function_type_list (opaque_V2SI_type_node,
7443 opaque_V2SI_type_node,
7444 char_type_node, NULL_TREE);
a3170dc6
AH
7445
7446 tree v2si_ftype_int_char
2abe3e28 7447 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7448 integer_type_node, char_type_node, NULL_TREE);
7449
7450 tree v2si_ftype_char
2abe3e28
AH
7451 = build_function_type_list (opaque_V2SI_type_node,
7452 char_type_node, NULL_TREE);
a3170dc6
AH
7453
7454 tree int_ftype_int_int
7455 = build_function_type_list (integer_type_node,
7456 integer_type_node, integer_type_node,
7457 NULL_TREE);
95385cbb 7458
0ac081f6 7459 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
7460 = build_function_type_list (V4SI_type_node,
7461 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 7462 tree v4sf_ftype_v4si_int
b4de2f7d 7463 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
7464 V4SI_type_node, integer_type_node, NULL_TREE);
7465 tree v4si_ftype_v4sf_int
b4de2f7d 7466 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7467 V4SF_type_node, integer_type_node, NULL_TREE);
7468 tree v4si_ftype_v4si_int
b4de2f7d 7469 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7470 V4SI_type_node, integer_type_node, NULL_TREE);
7471 tree v8hi_ftype_v8hi_int
b4de2f7d 7472 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
7473 V8HI_type_node, integer_type_node, NULL_TREE);
7474 tree v16qi_ftype_v16qi_int
b4de2f7d 7475 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
7476 V16QI_type_node, integer_type_node, NULL_TREE);
7477 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
7478 = build_function_type_list (V16QI_type_node,
7479 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
7480 integer_type_node, NULL_TREE);
7481 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
7482 = build_function_type_list (V8HI_type_node,
7483 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
7484 integer_type_node, NULL_TREE);
7485 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
7486 = build_function_type_list (V4SI_type_node,
7487 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
7488 integer_type_node, NULL_TREE);
7489 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
7490 = build_function_type_list (V4SF_type_node,
7491 V4SF_type_node, V4SF_type_node,
b9e4e5d1 7492 integer_type_node, NULL_TREE);
0ac081f6 7493 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
7494 = build_function_type_list (V4SF_type_node,
7495 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 7496 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
7497 = build_function_type_list (V4SF_type_node,
7498 V4SF_type_node, V4SF_type_node,
7499 V4SI_type_node, NULL_TREE);
2212663f 7500 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
7501 = build_function_type_list (V4SF_type_node,
7502 V4SF_type_node, V4SF_type_node,
7503 V4SF_type_node, NULL_TREE);
617e0e1d 7504 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
7505 = build_function_type_list (V4SI_type_node,
7506 V4SI_type_node, V4SI_type_node,
7507 V4SI_type_node, NULL_TREE);
0ac081f6 7508 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
7509 = build_function_type_list (V8HI_type_node,
7510 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 7511 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
7512 = build_function_type_list (V8HI_type_node,
7513 V8HI_type_node, V8HI_type_node,
7514 V8HI_type_node, NULL_TREE);
2212663f 7515 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
7516 = build_function_type_list (V4SI_type_node,
7517 V8HI_type_node, V8HI_type_node,
7518 V4SI_type_node, NULL_TREE);
2212663f 7519 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
7520 = build_function_type_list (V4SI_type_node,
7521 V16QI_type_node, V16QI_type_node,
7522 V4SI_type_node, NULL_TREE);
0ac081f6 7523 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
7524 = build_function_type_list (V16QI_type_node,
7525 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7526 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
7527 = build_function_type_list (V4SI_type_node,
7528 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 7529 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
7530 = build_function_type_list (V8HI_type_node,
7531 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7532 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
7533 = build_function_type_list (V4SI_type_node,
7534 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7535 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
7536 = build_function_type_list (V8HI_type_node,
7537 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 7538 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
7539 = build_function_type_list (V16QI_type_node,
7540 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7541 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
7542 = build_function_type_list (V4SI_type_node,
7543 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 7544 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
7545 = build_function_type_list (V4SI_type_node,
7546 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7547 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
7548 = build_function_type_list (V4SI_type_node,
7549 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7550 tree v4si_ftype_v8hi
7551 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
7552 tree int_ftype_v4si_v4si
7553 = build_function_type_list (integer_type_node,
7554 V4SI_type_node, V4SI_type_node, NULL_TREE);
7555 tree int_ftype_v4sf_v4sf
7556 = build_function_type_list (integer_type_node,
7557 V4SF_type_node, V4SF_type_node, NULL_TREE);
7558 tree int_ftype_v16qi_v16qi
7559 = build_function_type_list (integer_type_node,
7560 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7561 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
7562 = build_function_type_list (integer_type_node,
7563 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7564
6f317ef3 7565 /* Add the simple ternary operators. */
2212663f 7566 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 7567 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
7568 {
7569
7570 enum machine_mode mode0, mode1, mode2, mode3;
7571 tree type;
7572
0559cc77 7573 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7574 continue;
7575
7576 mode0 = insn_data[d->icode].operand[0].mode;
7577 mode1 = insn_data[d->icode].operand[1].mode;
7578 mode2 = insn_data[d->icode].operand[2].mode;
7579 mode3 = insn_data[d->icode].operand[3].mode;
7580
7581 /* When all four are of the same mode. */
7582 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
7583 {
7584 switch (mode0)
7585 {
617e0e1d
DB
7586 case V4SImode:
7587 type = v4si_ftype_v4si_v4si_v4si;
7588 break;
2212663f
DB
7589 case V4SFmode:
7590 type = v4sf_ftype_v4sf_v4sf_v4sf;
7591 break;
7592 case V8HImode:
7593 type = v8hi_ftype_v8hi_v8hi_v8hi;
7594 break;
7595 case V16QImode:
7596 type = v16qi_ftype_v16qi_v16qi_v16qi;
7597 break;
7598 default:
7599 abort();
7600 }
7601 }
7602 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
7603 {
7604 switch (mode0)
7605 {
7606 case V4SImode:
7607 type = v4si_ftype_v4si_v4si_v16qi;
7608 break;
7609 case V4SFmode:
7610 type = v4sf_ftype_v4sf_v4sf_v16qi;
7611 break;
7612 case V8HImode:
7613 type = v8hi_ftype_v8hi_v8hi_v16qi;
7614 break;
7615 case V16QImode:
7616 type = v16qi_ftype_v16qi_v16qi_v16qi;
7617 break;
7618 default:
7619 abort();
7620 }
7621 }
7622 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
7623 && mode3 == V4SImode)
24408032 7624 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
7625 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
7626 && mode3 == V4SImode)
24408032 7627 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
7628 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
7629 && mode3 == V4SImode)
24408032
AH
7630 type = v4sf_ftype_v4sf_v4sf_v4si;
7631
7632 /* vchar, vchar, vchar, 4 bit literal. */
7633 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
7634 && mode3 == QImode)
b9e4e5d1 7635 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
7636
7637 /* vshort, vshort, vshort, 4 bit literal. */
7638 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
7639 && mode3 == QImode)
b9e4e5d1 7640 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
7641
7642 /* vint, vint, vint, 4 bit literal. */
7643 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
7644 && mode3 == QImode)
b9e4e5d1 7645 type = v4si_ftype_v4si_v4si_int;
24408032
AH
7646
7647 /* vfloat, vfloat, vfloat, 4 bit literal. */
7648 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
7649 && mode3 == QImode)
b9e4e5d1 7650 type = v4sf_ftype_v4sf_v4sf_int;
24408032 7651
2212663f
DB
7652 else
7653 abort ();
7654
7655 def_builtin (d->mask, d->name, type, d->code);
7656 }
7657
0ac081f6 7658 /* Add the simple binary operators. */
00b960c7 7659 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 7660 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
7661 {
7662 enum machine_mode mode0, mode1, mode2;
7663 tree type;
7664
0559cc77 7665 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
7666 continue;
7667
7668 mode0 = insn_data[d->icode].operand[0].mode;
7669 mode1 = insn_data[d->icode].operand[1].mode;
7670 mode2 = insn_data[d->icode].operand[2].mode;
7671
7672 /* When all three operands are of the same mode. */
7673 if (mode0 == mode1 && mode1 == mode2)
7674 {
7675 switch (mode0)
7676 {
7677 case V4SFmode:
7678 type = v4sf_ftype_v4sf_v4sf;
7679 break;
7680 case V4SImode:
7681 type = v4si_ftype_v4si_v4si;
7682 break;
7683 case V16QImode:
7684 type = v16qi_ftype_v16qi_v16qi;
7685 break;
7686 case V8HImode:
7687 type = v8hi_ftype_v8hi_v8hi;
7688 break;
a3170dc6
AH
7689 case V2SImode:
7690 type = v2si_ftype_v2si_v2si;
7691 break;
7692 case V2SFmode:
7693 type = v2sf_ftype_v2sf_v2sf;
7694 break;
7695 case SImode:
7696 type = int_ftype_int_int;
7697 break;
0ac081f6
AH
7698 default:
7699 abort ();
7700 }
7701 }
7702
7703 /* A few other combos we really don't want to do manually. */
7704
7705 /* vint, vfloat, vfloat. */
7706 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
7707 type = v4si_ftype_v4sf_v4sf;
7708
7709 /* vshort, vchar, vchar. */
7710 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
7711 type = v8hi_ftype_v16qi_v16qi;
7712
7713 /* vint, vshort, vshort. */
7714 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
7715 type = v4si_ftype_v8hi_v8hi;
7716
7717 /* vshort, vint, vint. */
7718 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
7719 type = v8hi_ftype_v4si_v4si;
7720
7721 /* vchar, vshort, vshort. */
7722 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
7723 type = v16qi_ftype_v8hi_v8hi;
7724
7725 /* vint, vchar, vint. */
7726 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
7727 type = v4si_ftype_v16qi_v4si;
7728
fa066a23
AH
7729 /* vint, vchar, vchar. */
7730 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
7731 type = v4si_ftype_v16qi_v16qi;
7732
0ac081f6
AH
7733 /* vint, vshort, vint. */
7734 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
7735 type = v4si_ftype_v8hi_v4si;
2212663f
DB
7736
7737 /* vint, vint, 5 bit literal. */
7738 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7739 type = v4si_ftype_v4si_int;
2212663f
DB
7740
7741 /* vshort, vshort, 5 bit literal. */
7742 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 7743 type = v8hi_ftype_v8hi_int;
2212663f
DB
7744
7745 /* vchar, vchar, 5 bit literal. */
7746 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 7747 type = v16qi_ftype_v16qi_int;
0ac081f6 7748
617e0e1d
DB
7749 /* vfloat, vint, 5 bit literal. */
7750 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7751 type = v4sf_ftype_v4si_int;
617e0e1d
DB
7752
7753 /* vint, vfloat, 5 bit literal. */
7754 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 7755 type = v4si_ftype_v4sf_int;
617e0e1d 7756
a3170dc6
AH
7757 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
7758 type = v2si_ftype_int_int;
7759
7760 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
7761 type = v2si_ftype_v2si_char;
7762
7763 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
7764 type = v2si_ftype_int_char;
7765
0ac081f6
AH
7766 /* int, x, x. */
7767 else if (mode0 == SImode)
7768 {
7769 switch (mode1)
7770 {
7771 case V4SImode:
7772 type = int_ftype_v4si_v4si;
7773 break;
7774 case V4SFmode:
7775 type = int_ftype_v4sf_v4sf;
7776 break;
7777 case V16QImode:
7778 type = int_ftype_v16qi_v16qi;
7779 break;
7780 case V8HImode:
7781 type = int_ftype_v8hi_v8hi;
7782 break;
7783 default:
7784 abort ();
7785 }
7786 }
7787
7788 else
7789 abort ();
7790
2212663f
DB
7791 def_builtin (d->mask, d->name, type, d->code);
7792 }
24408032 7793
2212663f
DB
7794 /* Add the simple unary operators. */
7795 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 7796 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
7797 {
7798 enum machine_mode mode0, mode1;
7799 tree type;
7800
0559cc77 7801 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7802 continue;
7803
7804 mode0 = insn_data[d->icode].operand[0].mode;
7805 mode1 = insn_data[d->icode].operand[1].mode;
7806
7807 if (mode0 == V4SImode && mode1 == QImode)
b9e4e5d1 7808 type = v4si_ftype_int;
2212663f 7809 else if (mode0 == V8HImode && mode1 == QImode)
b9e4e5d1 7810 type = v8hi_ftype_int;
2212663f 7811 else if (mode0 == V16QImode && mode1 == QImode)
b9e4e5d1 7812 type = v16qi_ftype_int;
617e0e1d
DB
7813 else if (mode0 == V4SFmode && mode1 == V4SFmode)
7814 type = v4sf_ftype_v4sf;
20e26713
AH
7815 else if (mode0 == V8HImode && mode1 == V16QImode)
7816 type = v8hi_ftype_v16qi;
7817 else if (mode0 == V4SImode && mode1 == V8HImode)
7818 type = v4si_ftype_v8hi;
a3170dc6
AH
7819 else if (mode0 == V2SImode && mode1 == V2SImode)
7820 type = v2si_ftype_v2si;
7821 else if (mode0 == V2SFmode && mode1 == V2SFmode)
7822 type = v2sf_ftype_v2sf;
7823 else if (mode0 == V2SFmode && mode1 == V2SImode)
7824 type = v2sf_ftype_v2si;
7825 else if (mode0 == V2SImode && mode1 == V2SFmode)
7826 type = v2si_ftype_v2sf;
7827 else if (mode0 == V2SImode && mode1 == QImode)
7828 type = v2si_ftype_char;
2212663f
DB
7829 else
7830 abort ();
7831
0ac081f6
AH
7832 def_builtin (d->mask, d->name, type, d->code);
7833 }
7834}
7835
c15c90bb
ZW
7836static void
7837rs6000_init_libfuncs (void)
7838{
7839 if (!TARGET_HARD_FLOAT)
7840 return;
7841
c9034561 7842 if (DEFAULT_ABI != ABI_V4)
c15c90bb 7843 {
c9034561 7844 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 7845 {
c9034561 7846 /* AIX library routines for float->int conversion. */
85363ca0
ZW
7847 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
7848 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
7849 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
7850 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
7851 }
7852
c9034561 7853 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7854 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
7855 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
7856 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
7857 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
7858 }
c9034561 7859 else
c15c90bb 7860 {
c9034561 7861 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7862
7863 set_optab_libfunc (add_optab, TFmode, "_q_add");
7864 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
7865 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
7866 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
7867 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
7868 if (TARGET_PPC_GPOPT || TARGET_POWER2)
7869 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
7870
c9034561
ZW
7871 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
7872 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
7873 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
7874 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
7875 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
7876 set_optab_libfunc (le_optab, TFmode, "_q_fle");
7877
85363ca0
ZW
7878 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
7879 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
7880 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
7881 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
7882 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
7883 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
7884 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
7885 }
7886}
35aff10b 7887\f
7e69e155
MM
7888/* Expand a block move operation, and return 1 if successful. Return 0
7889 if we should let the compiler generate normal code.
7890
7891 operands[0] is the destination
7892 operands[1] is the source
7893 operands[2] is the length
7894 operands[3] is the alignment */
7895
3933e0e1
MM
7896#define MAX_MOVE_REG 4
7897
7e69e155 7898int
a2369ed3 7899expand_block_move (rtx operands[])
7e69e155 7900{
b6c9286a
MM
7901 rtx orig_dest = operands[0];
7902 rtx orig_src = operands[1];
7e69e155 7903 rtx bytes_rtx = operands[2];
7e69e155 7904 rtx align_rtx = operands[3];
3933e0e1 7905 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 7906 int align;
3933e0e1
MM
7907 int bytes;
7908 int offset;
7e69e155 7909 int move_bytes;
cabfd258
GK
7910 rtx stores[MAX_MOVE_REG];
7911 int num_reg = 0;
7e69e155 7912
3933e0e1 7913 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 7914 if (! constp)
3933e0e1
MM
7915 return 0;
7916
5ee95df6
FS
7917 /* If this is not a fixed size alignment, abort */
7918 if (GET_CODE (align_rtx) != CONST_INT)
7919 abort ();
7920 align = INTVAL (align_rtx);
7921
7e69e155 7922 /* Anything to move? */
3933e0e1
MM
7923 bytes = INTVAL (bytes_rtx);
7924 if (bytes <= 0)
7e69e155
MM
7925 return 1;
7926
ea9982a8 7927 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 7928 reg_parm_stack_space. */
ea9982a8 7929 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
7930 return 0;
7931
cabfd258 7932 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 7933 {
cabfd258 7934 union {
a2369ed3
DJ
7935 rtx (*movstrsi) (rtx, rtx, rtx, rtx);
7936 rtx (*mov) (rtx, rtx);
cabfd258
GK
7937 } gen_func;
7938 enum machine_mode mode = BLKmode;
7939 rtx src, dest;
7940
7941 if (TARGET_STRING
7942 && bytes > 24 /* move up to 32 bytes at a time */
7943 && ! fixed_regs[5]
7944 && ! fixed_regs[6]
7945 && ! fixed_regs[7]
7946 && ! fixed_regs[8]
7947 && ! fixed_regs[9]
7948 && ! fixed_regs[10]
7949 && ! fixed_regs[11]
7950 && ! fixed_regs[12])
7e69e155 7951 {
cabfd258
GK
7952 move_bytes = (bytes > 32) ? 32 : bytes;
7953 gen_func.movstrsi = gen_movstrsi_8reg;
7954 }
7955 else if (TARGET_STRING
7956 && bytes > 16 /* move up to 24 bytes at a time */
7957 && ! fixed_regs[5]
7958 && ! fixed_regs[6]
7959 && ! fixed_regs[7]
7960 && ! fixed_regs[8]
7961 && ! fixed_regs[9]
7962 && ! fixed_regs[10])
7963 {
7964 move_bytes = (bytes > 24) ? 24 : bytes;
7965 gen_func.movstrsi = gen_movstrsi_6reg;
7966 }
7967 else if (TARGET_STRING
7968 && bytes > 8 /* move up to 16 bytes at a time */
7969 && ! fixed_regs[5]
7970 && ! fixed_regs[6]
7971 && ! fixed_regs[7]
7972 && ! fixed_regs[8])
7973 {
7974 move_bytes = (bytes > 16) ? 16 : bytes;
7975 gen_func.movstrsi = gen_movstrsi_4reg;
7976 }
7977 else if (bytes >= 8 && TARGET_POWERPC64
7978 /* 64-bit loads and stores require word-aligned
7979 displacements. */
7980 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
7981 {
7982 move_bytes = 8;
7983 mode = DImode;
7984 gen_func.mov = gen_movdi;
7985 }
7986 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
7987 { /* move up to 8 bytes at a time */
7988 move_bytes = (bytes > 8) ? 8 : bytes;
7989 gen_func.movstrsi = gen_movstrsi_2reg;
7990 }
7991 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
7992 { /* move 4 bytes */
7993 move_bytes = 4;
7994 mode = SImode;
7995 gen_func.mov = gen_movsi;
7996 }
7997 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
7998 { /* move 2 bytes */
7999 move_bytes = 2;
8000 mode = HImode;
8001 gen_func.mov = gen_movhi;
8002 }
8003 else if (TARGET_STRING && bytes > 1)
8004 { /* move up to 4 bytes at a time */
8005 move_bytes = (bytes > 4) ? 4 : bytes;
8006 gen_func.movstrsi = gen_movstrsi_1reg;
8007 }
8008 else /* move 1 byte at a time */
8009 {
8010 move_bytes = 1;
8011 mode = QImode;
8012 gen_func.mov = gen_movqi;
8013 }
8014
8015 src = adjust_address (orig_src, mode, offset);
8016 dest = adjust_address (orig_dest, mode, offset);
8017
8018 if (mode != BLKmode)
8019 {
8020 rtx tmp_reg = gen_reg_rtx (mode);
8021
8022 emit_insn ((*gen_func.mov) (tmp_reg, src));
8023 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 8024 }
3933e0e1 8025
cabfd258
GK
8026 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
8027 {
8028 int i;
8029 for (i = 0; i < num_reg; i++)
8030 emit_insn (stores[i]);
8031 num_reg = 0;
8032 }
35aff10b 8033
cabfd258 8034 if (mode == BLKmode)
7e69e155 8035 {
cabfd258
GK
8036 /* Move the address into scratch registers. The movstrsi
8037 patterns require zero offset. */
8038 if (!REG_P (XEXP (src, 0)))
b6c9286a 8039 {
cabfd258
GK
8040 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
8041 src = replace_equiv_address (src, src_reg);
b6c9286a 8042 }
cabfd258
GK
8043 set_mem_size (src, GEN_INT (move_bytes));
8044
8045 if (!REG_P (XEXP (dest, 0)))
3933e0e1 8046 {
cabfd258
GK
8047 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
8048 dest = replace_equiv_address (dest, dest_reg);
7e69e155 8049 }
cabfd258
GK
8050 set_mem_size (dest, GEN_INT (move_bytes));
8051
8052 emit_insn ((*gen_func.movstrsi) (dest, src,
8053 GEN_INT (move_bytes & 31),
8054 align_rtx));
7e69e155 8055 }
7e69e155
MM
8056 }
8057
8058 return 1;
8059}
8060
9878760c
RK
8061\f
8062/* Return 1 if OP is a load multiple operation. It is known to be a
8063 PARALLEL and the first section will be tested. */
8064
8065int
a2369ed3 8066load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8067{
8068 int count = XVECLEN (op, 0);
e2c953b6 8069 unsigned int dest_regno;
9878760c
RK
8070 rtx src_addr;
8071 int i;
8072
8073 /* Perform a quick check so we don't blow up below. */
8074 if (count <= 1
8075 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8076 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8077 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8078 return 0;
8079
8080 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8081 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8082
8083 for (i = 1; i < count; i++)
8084 {
8085 rtx elt = XVECEXP (op, 0, i);
8086
8087 if (GET_CODE (elt) != SET
8088 || GET_CODE (SET_DEST (elt)) != REG
8089 || GET_MODE (SET_DEST (elt)) != SImode
8090 || REGNO (SET_DEST (elt)) != dest_regno + i
8091 || GET_CODE (SET_SRC (elt)) != MEM
8092 || GET_MODE (SET_SRC (elt)) != SImode
8093 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
8094 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
8095 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
8096 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
8097 return 0;
8098 }
8099
8100 return 1;
8101}
8102
8103/* Similar, but tests for store multiple. Here, the second vector element
8104 is a CLOBBER. It will be tested later. */
8105
8106int
a2369ed3 8107store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8108{
8109 int count = XVECLEN (op, 0) - 1;
e2c953b6 8110 unsigned int src_regno;
9878760c
RK
8111 rtx dest_addr;
8112 int i;
8113
8114 /* Perform a quick check so we don't blow up below. */
8115 if (count <= 1
8116 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8117 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8118 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8119 return 0;
8120
8121 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8122 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8123
8124 for (i = 1; i < count; i++)
8125 {
8126 rtx elt = XVECEXP (op, 0, i + 1);
8127
8128 if (GET_CODE (elt) != SET
8129 || GET_CODE (SET_SRC (elt)) != REG
8130 || GET_MODE (SET_SRC (elt)) != SImode
8131 || REGNO (SET_SRC (elt)) != src_regno + i
8132 || GET_CODE (SET_DEST (elt)) != MEM
8133 || GET_MODE (SET_DEST (elt)) != SImode
8134 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
8135 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
8136 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
8137 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
8138 return 0;
8139 }
8140
8141 return 1;
8142}
9ebbca7d 8143
9caa3eb2
DE
8144/* Return a string to perform a load_multiple operation.
8145 operands[0] is the vector.
8146 operands[1] is the source address.
8147 operands[2] is the first destination register. */
8148
8149const char *
a2369ed3 8150rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
8151{
8152 /* We have to handle the case where the pseudo used to contain the address
8153 is assigned to one of the output registers. */
8154 int i, j;
8155 int words = XVECLEN (operands[0], 0);
8156 rtx xop[10];
8157
8158 if (XVECLEN (operands[0], 0) == 1)
8159 return "{l|lwz} %2,0(%1)";
8160
8161 for (i = 0; i < words; i++)
8162 if (refers_to_regno_p (REGNO (operands[2]) + i,
8163 REGNO (operands[2]) + i + 1, operands[1], 0))
8164 {
8165 if (i == words-1)
8166 {
8167 xop[0] = GEN_INT (4 * (words-1));
8168 xop[1] = operands[1];
8169 xop[2] = operands[2];
8170 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
8171 return "";
8172 }
8173 else if (i == 0)
8174 {
8175 xop[0] = GEN_INT (4 * (words-1));
8176 xop[1] = operands[1];
8177 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
8178 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);
8179 return "";
8180 }
8181 else
8182 {
8183 for (j = 0; j < words; j++)
8184 if (j != i)
8185 {
8186 xop[0] = GEN_INT (j * 4);
8187 xop[1] = operands[1];
8188 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
8189 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
8190 }
8191 xop[0] = GEN_INT (i * 4);
8192 xop[1] = operands[1];
8193 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
8194 return "";
8195 }
8196 }
8197
8198 return "{lsi|lswi} %2,%1,%N0";
8199}
8200
00b960c7
AH
8201/* Return 1 for a parallel vrsave operation. */
8202
8203int
a2369ed3 8204vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
8205{
8206 int count = XVECLEN (op, 0);
8207 unsigned int dest_regno, src_regno;
8208 int i;
8209
8210 if (count <= 1
8211 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8212 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 8213 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
8214 return 0;
8215
8216 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8217 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8218
8219 if (dest_regno != VRSAVE_REGNO
8220 && src_regno != VRSAVE_REGNO)
8221 return 0;
8222
8223 for (i = 1; i < count; i++)
8224 {
8225 rtx elt = XVECEXP (op, 0, i);
8226
9aa86737
AH
8227 if (GET_CODE (elt) != CLOBBER
8228 && GET_CODE (elt) != SET)
00b960c7
AH
8229 return 0;
8230 }
8231
8232 return 1;
8233}
8234
2c4a9cff
DE
8235/* Return 1 for an PARALLEL suitable for mfcr. */
8236
8237int
a2369ed3 8238mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
8239{
8240 int count = XVECLEN (op, 0);
8241 int i;
8242
8243 /* Perform a quick check so we don't blow up below. */
8244 if (count < 1
8245 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8246 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8247 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
8248 return 0;
8249
8250 for (i = 0; i < count; i++)
8251 {
8252 rtx exp = XVECEXP (op, 0, i);
8253 rtx unspec;
8254 int maskval;
8255 rtx src_reg;
8256
8257 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
8258
8259 if (GET_CODE (src_reg) != REG
8260 || GET_MODE (src_reg) != CCmode
8261 || ! CR_REGNO_P (REGNO (src_reg)))
8262 return 0;
8263
8264 if (GET_CODE (exp) != SET
8265 || GET_CODE (SET_DEST (exp)) != REG
8266 || GET_MODE (SET_DEST (exp)) != SImode
8267 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
8268 return 0;
8269 unspec = SET_SRC (exp);
8270 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
8271
8272 if (GET_CODE (unspec) != UNSPEC
8273 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
8274 || XVECLEN (unspec, 0) != 2
8275 || XVECEXP (unspec, 0, 0) != src_reg
8276 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8277 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8278 return 0;
8279 }
8280 return 1;
8281}
8282
a4f6c312 8283/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
8284
8285int
a2369ed3 8286mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8287{
8288 int count = XVECLEN (op, 0);
8289 int i;
9ebbca7d
GK
8290 rtx src_reg;
8291
8292 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
8293 if (count < 1
8294 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8295 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8296 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 8297 return 0;
e35b9579 8298 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
8299
8300 if (GET_CODE (src_reg) != REG
8301 || GET_MODE (src_reg) != SImode
8302 || ! INT_REGNO_P (REGNO (src_reg)))
8303 return 0;
8304
e35b9579 8305 for (i = 0; i < count; i++)
9ebbca7d
GK
8306 {
8307 rtx exp = XVECEXP (op, 0, i);
8308 rtx unspec;
8309 int maskval;
8310
8311 if (GET_CODE (exp) != SET
8312 || GET_CODE (SET_DEST (exp)) != REG
8313 || GET_MODE (SET_DEST (exp)) != CCmode
8314 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
8315 return 0;
8316 unspec = SET_SRC (exp);
8317 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
8318
8319 if (GET_CODE (unspec) != UNSPEC
615158e2 8320 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
8321 || XVECLEN (unspec, 0) != 2
8322 || XVECEXP (unspec, 0, 0) != src_reg
8323 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8324 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8325 return 0;
8326 }
e35b9579 8327 return 1;
9ebbca7d
GK
8328}
8329
a4f6c312 8330/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
8331
8332int
a2369ed3 8333lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8334{
8335 int count = XVECLEN (op, 0);
e2c953b6 8336 unsigned int dest_regno;
9ebbca7d 8337 rtx src_addr;
e2c953b6 8338 unsigned int base_regno;
9ebbca7d
GK
8339 HOST_WIDE_INT offset;
8340 int i;
8341
8342 /* Perform a quick check so we don't blow up below. */
8343 if (count <= 1
8344 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8345 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8346 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8347 return 0;
8348
8349 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8350 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8351
8352 if (dest_regno > 31
e2c953b6 8353 || count != 32 - (int) dest_regno)
9ebbca7d
GK
8354 return 0;
8355
4d588c14 8356 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
8357 {
8358 offset = 0;
8359 base_regno = REGNO (src_addr);
8360 if (base_regno == 0)
8361 return 0;
8362 }
4d588c14 8363 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
8364 {
8365 offset = INTVAL (XEXP (src_addr, 1));
8366 base_regno = REGNO (XEXP (src_addr, 0));
8367 }
8368 else
8369 return 0;
8370
8371 for (i = 0; i < count; i++)
8372 {
8373 rtx elt = XVECEXP (op, 0, i);
8374 rtx newaddr;
8375 rtx addr_reg;
8376 HOST_WIDE_INT newoffset;
8377
8378 if (GET_CODE (elt) != SET
8379 || GET_CODE (SET_DEST (elt)) != REG
8380 || GET_MODE (SET_DEST (elt)) != SImode
8381 || REGNO (SET_DEST (elt)) != dest_regno + i
8382 || GET_CODE (SET_SRC (elt)) != MEM
8383 || GET_MODE (SET_SRC (elt)) != SImode)
8384 return 0;
8385 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 8386 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8387 {
8388 newoffset = 0;
8389 addr_reg = newaddr;
8390 }
4d588c14 8391 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8392 {
8393 addr_reg = XEXP (newaddr, 0);
8394 newoffset = INTVAL (XEXP (newaddr, 1));
8395 }
8396 else
8397 return 0;
8398 if (REGNO (addr_reg) != base_regno
8399 || newoffset != offset + 4 * i)
8400 return 0;
8401 }
8402
8403 return 1;
8404}
8405
a4f6c312 8406/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
8407
8408int
a2369ed3 8409stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8410{
8411 int count = XVECLEN (op, 0);
e2c953b6 8412 unsigned int src_regno;
9ebbca7d 8413 rtx dest_addr;
e2c953b6 8414 unsigned int base_regno;
9ebbca7d
GK
8415 HOST_WIDE_INT offset;
8416 int i;
8417
8418 /* Perform a quick check so we don't blow up below. */
8419 if (count <= 1
8420 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8421 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8422 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8423 return 0;
8424
8425 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8426 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8427
8428 if (src_regno > 31
e2c953b6 8429 || count != 32 - (int) src_regno)
9ebbca7d
GK
8430 return 0;
8431
4d588c14 8432 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
8433 {
8434 offset = 0;
8435 base_regno = REGNO (dest_addr);
8436 if (base_regno == 0)
8437 return 0;
8438 }
4d588c14 8439 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
8440 {
8441 offset = INTVAL (XEXP (dest_addr, 1));
8442 base_regno = REGNO (XEXP (dest_addr, 0));
8443 }
8444 else
8445 return 0;
8446
8447 for (i = 0; i < count; i++)
8448 {
8449 rtx elt = XVECEXP (op, 0, i);
8450 rtx newaddr;
8451 rtx addr_reg;
8452 HOST_WIDE_INT newoffset;
8453
8454 if (GET_CODE (elt) != SET
8455 || GET_CODE (SET_SRC (elt)) != REG
8456 || GET_MODE (SET_SRC (elt)) != SImode
8457 || REGNO (SET_SRC (elt)) != src_regno + i
8458 || GET_CODE (SET_DEST (elt)) != MEM
8459 || GET_MODE (SET_DEST (elt)) != SImode)
8460 return 0;
8461 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 8462 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8463 {
8464 newoffset = 0;
8465 addr_reg = newaddr;
8466 }
4d588c14 8467 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8468 {
8469 addr_reg = XEXP (newaddr, 0);
8470 newoffset = INTVAL (XEXP (newaddr, 1));
8471 }
8472 else
8473 return 0;
8474 if (REGNO (addr_reg) != base_regno
8475 || newoffset != offset + 4 * i)
8476 return 0;
8477 }
8478
8479 return 1;
8480}
9878760c 8481\f
a4f6c312
SS
8482/* A validation routine: say whether CODE, a condition code, and MODE
8483 match. The other alternatives either don't make sense or should
8484 never be generated. */
39a10a29 8485
39a10a29 8486static void
a2369ed3 8487validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 8488{
ec8e098d
PB
8489 if ((GET_RTX_CLASS (code) != RTX_COMPARE
8490 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
8491 || GET_MODE_CLASS (mode) != MODE_CC)
8492 abort ();
8493
8494 /* These don't make sense. */
8495 if ((code == GT || code == LT || code == GE || code == LE)
8496 && mode == CCUNSmode)
8497 abort ();
8498
8499 if ((code == GTU || code == LTU || code == GEU || code == LEU)
8500 && mode != CCUNSmode)
8501 abort ();
8502
8503 if (mode != CCFPmode
8504 && (code == ORDERED || code == UNORDERED
8505 || code == UNEQ || code == LTGT
8506 || code == UNGT || code == UNLT
8507 || code == UNGE || code == UNLE))
a4f6c312 8508 abort ();
39a10a29 8509
de6c5979 8510 /* These should never be generated except for
bc9ec0e0 8511 flag_finite_math_only. */
39a10a29 8512 if (mode == CCFPmode
ad72b533 8513 && ! flag_finite_math_only
39a10a29
GK
8514 && (code == LE || code == GE
8515 || code == UNEQ || code == LTGT
8516 || code == UNGT || code == UNLT))
8517 abort ();
8518
8519 /* These are invalid; the information is not there. */
8520 if (mode == CCEQmode
8521 && code != EQ && code != NE)
8522 abort ();
8523}
8524
9878760c
RK
8525/* Return 1 if OP is a comparison operation that is valid for a branch insn.
8526 We only check the opcode against the mode of the CC value here. */
8527
8528int
a2369ed3 8529branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8530{
8531 enum rtx_code code = GET_CODE (op);
8532 enum machine_mode cc_mode;
8533
ec8e098d 8534 if (!COMPARISON_P (op))
9878760c
RK
8535 return 0;
8536
8537 cc_mode = GET_MODE (XEXP (op, 0));
8538 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
8539 return 0;
8540
39a10a29 8541 validate_condition_mode (code, cc_mode);
9878760c 8542
39a10a29
GK
8543 return 1;
8544}
8545
8546/* Return 1 if OP is a comparison operation that is valid for a branch
8547 insn and which is true if the corresponding bit in the CC register
8548 is set. */
8549
8550int
a2369ed3 8551branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
8552{
8553 enum rtx_code code;
8554
8daf2e65 8555 if (! branch_comparison_operator (op, mode))
9878760c
RK
8556 return 0;
8557
39a10a29
GK
8558 code = GET_CODE (op);
8559 return (code == EQ || code == LT || code == GT
8560 || code == LTU || code == GTU
8561 || code == UNORDERED);
9878760c
RK
8562}
8563
b7053a3f
GK
8564/* Return 1 if OP is a comparison operation that is valid for an scc
8565 insn: it must be a positive comparison. */
9878760c
RK
8566
8567int
a2369ed3 8568scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 8569{
b7053a3f 8570 return branch_positive_comparison_operator (op, mode);
9878760c 8571}
e0cd0770
JC
8572
8573int
a2369ed3 8574trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
8575{
8576 if (mode != VOIDmode && mode != GET_MODE (op))
8577 return 0;
ec8e098d 8578 return COMPARISON_P (op);
e0cd0770 8579}
dfbdccdb
GK
8580
8581int
a2369ed3 8582boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
8583{
8584 enum rtx_code code = GET_CODE (op);
8585 return (code == AND || code == IOR || code == XOR);
8586}
1d328b19
GK
8587
8588int
a2369ed3 8589boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
8590{
8591 enum rtx_code code = GET_CODE (op);
8592 return (code == IOR || code == XOR);
8593}
50a0b056
GK
8594
8595int
a2369ed3 8596min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
8597{
8598 enum rtx_code code = GET_CODE (op);
8599 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
8600}
9878760c
RK
8601\f
8602/* Return 1 if ANDOP is a mask that has no bits on that are not in the
8603 mask required to convert the result of a rotate insn into a shift
b1765bde 8604 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
8605
8606int
a2369ed3 8607includes_lshift_p (rtx shiftop, rtx andop)
9878760c 8608{
e2c953b6
DE
8609 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
8610
8611 shift_mask <<= INTVAL (shiftop);
9878760c 8612
b1765bde 8613 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
8614}
8615
8616/* Similar, but for right shift. */
8617
8618int
a2369ed3 8619includes_rshift_p (rtx shiftop, rtx andop)
9878760c 8620{
a7653a2c 8621 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
8622
8623 shift_mask >>= INTVAL (shiftop);
8624
b1765bde 8625 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
8626}
8627
c5059423
AM
8628/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
8629 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 8630 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
8631
8632int
a2369ed3 8633includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 8634{
c5059423
AM
8635 if (GET_CODE (andop) == CONST_INT)
8636 {
02071907 8637 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 8638
c5059423 8639 c = INTVAL (andop);
02071907 8640 if (c == 0 || c == ~0)
c5059423 8641 return 0;
e2c953b6 8642
02071907 8643 shift_mask = ~0;
c5059423
AM
8644 shift_mask <<= INTVAL (shiftop);
8645
b6d08ca1 8646 /* Find the least significant one bit. */
c5059423
AM
8647 lsb = c & -c;
8648
8649 /* It must coincide with the LSB of the shift mask. */
8650 if (-lsb != shift_mask)
8651 return 0;
e2c953b6 8652
c5059423
AM
8653 /* Invert to look for the next transition (if any). */
8654 c = ~c;
8655
8656 /* Remove the low group of ones (originally low group of zeros). */
8657 c &= -lsb;
8658
8659 /* Again find the lsb, and check we have all 1's above. */
8660 lsb = c & -c;
8661 return c == -lsb;
8662 }
8663 else if (GET_CODE (andop) == CONST_DOUBLE
8664 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8665 {
02071907
AM
8666 HOST_WIDE_INT low, high, lsb;
8667 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
8668
8669 low = CONST_DOUBLE_LOW (andop);
8670 if (HOST_BITS_PER_WIDE_INT < 64)
8671 high = CONST_DOUBLE_HIGH (andop);
8672
8673 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 8674 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
8675 return 0;
8676
8677 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8678 {
02071907 8679 shift_mask_high = ~0;
c5059423
AM
8680 if (INTVAL (shiftop) > 32)
8681 shift_mask_high <<= INTVAL (shiftop) - 32;
8682
8683 lsb = high & -high;
8684
8685 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
8686 return 0;
8687
8688 high = ~high;
8689 high &= -lsb;
8690
8691 lsb = high & -high;
8692 return high == -lsb;
8693 }
8694
02071907 8695 shift_mask_low = ~0;
c5059423
AM
8696 shift_mask_low <<= INTVAL (shiftop);
8697
8698 lsb = low & -low;
8699
8700 if (-lsb != shift_mask_low)
8701 return 0;
8702
8703 if (HOST_BITS_PER_WIDE_INT < 64)
8704 high = ~high;
8705 low = ~low;
8706 low &= -lsb;
8707
8708 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8709 {
8710 lsb = high & -high;
8711 return high == -lsb;
8712 }
8713
8714 lsb = low & -low;
8715 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
8716 }
8717 else
8718 return 0;
8719}
e2c953b6 8720
c5059423
AM
8721/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
8722 to perform a left shift. It must have SHIFTOP or more least
c1207243 8723 significant 0's, with the remainder of the word 1's. */
e2c953b6 8724
c5059423 8725int
a2369ed3 8726includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 8727{
e2c953b6 8728 if (GET_CODE (andop) == CONST_INT)
c5059423 8729 {
02071907 8730 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 8731
02071907 8732 shift_mask = ~0;
c5059423
AM
8733 shift_mask <<= INTVAL (shiftop);
8734 c = INTVAL (andop);
8735
c1207243 8736 /* Find the least significant one bit. */
c5059423
AM
8737 lsb = c & -c;
8738
8739 /* It must be covered by the shift mask.
a4f6c312 8740 This test also rejects c == 0. */
c5059423
AM
8741 if ((lsb & shift_mask) == 0)
8742 return 0;
8743
8744 /* Check we have all 1's above the transition, and reject all 1's. */
8745 return c == -lsb && lsb != 1;
8746 }
8747 else if (GET_CODE (andop) == CONST_DOUBLE
8748 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8749 {
02071907 8750 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
8751
8752 low = CONST_DOUBLE_LOW (andop);
8753
8754 if (HOST_BITS_PER_WIDE_INT < 64)
8755 {
02071907 8756 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
8757
8758 high = CONST_DOUBLE_HIGH (andop);
8759
8760 if (low == 0)
8761 {
02071907 8762 shift_mask_high = ~0;
c5059423
AM
8763 if (INTVAL (shiftop) > 32)
8764 shift_mask_high <<= INTVAL (shiftop) - 32;
8765
8766 lsb = high & -high;
8767
8768 if ((lsb & shift_mask_high) == 0)
8769 return 0;
8770
8771 return high == -lsb;
8772 }
8773 if (high != ~0)
8774 return 0;
8775 }
8776
02071907 8777 shift_mask_low = ~0;
c5059423
AM
8778 shift_mask_low <<= INTVAL (shiftop);
8779
8780 lsb = low & -low;
8781
8782 if ((lsb & shift_mask_low) == 0)
8783 return 0;
8784
8785 return low == -lsb && lsb != 1;
8786 }
e2c953b6 8787 else
c5059423 8788 return 0;
9878760c 8789}
35068b43
RK
8790
8791/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
90f81f99 8792 for lfq and stfq insns iff the registers are hard registers. */
35068b43
RK
8793
8794int
a2369ed3 8795registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
8796{
8797 /* We might have been passed a SUBREG. */
8798 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8799 return 0;
90f81f99
AP
8800
8801 /* We might have been passed non floating point registers. */
8802 if (!FP_REGNO_P (REGNO (reg1))
8803 || !FP_REGNO_P (REGNO (reg2)))
8804 return 0;
35068b43
RK
8805
8806 return (REGNO (reg1) == REGNO (reg2) - 1);
8807}
8808
a4f6c312
SS
8809/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
8810 addr1 and addr2 must be in consecutive memory locations
8811 (addr2 == addr1 + 8). */
35068b43
RK
8812
8813int
90f81f99 8814mems_ok_for_quad_peep (rtx mem1, rtx mem2)
35068b43 8815{
90f81f99 8816 rtx addr1, addr2;
e2c953b6 8817 unsigned int reg1;
35068b43
RK
8818 int offset1;
8819
90f81f99
AP
8820 /* The mems cannot be volatile. */
8821 if (MEM_VOLATILE_P (mem1) || MEM_VOLATILE_P (mem2))
8822 return 0;
8823
8824 addr1 = XEXP (mem1, 0);
8825 addr2 = XEXP (mem2, 0);
8826
35068b43
RK
8827 /* Extract an offset (if used) from the first addr. */
8828 if (GET_CODE (addr1) == PLUS)
8829 {
8830 /* If not a REG, return zero. */
8831 if (GET_CODE (XEXP (addr1, 0)) != REG)
8832 return 0;
8833 else
8834 {
8835 reg1 = REGNO (XEXP (addr1, 0));
8836 /* The offset must be constant! */
8837 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8838 return 0;
8839 offset1 = INTVAL (XEXP (addr1, 1));
8840 }
8841 }
8842 else if (GET_CODE (addr1) != REG)
8843 return 0;
8844 else
8845 {
8846 reg1 = REGNO (addr1);
8847 /* This was a simple (mem (reg)) expression. Offset is 0. */
8848 offset1 = 0;
8849 }
8850
a2369ed3 8851 /* Make sure the second address is a (mem (plus (reg) (const_int)))
0f6937fe
AM
8852 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
8853 register as addr1. */
984e25ac 8854 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 8855 return 1;
35068b43
RK
8856 if (GET_CODE (addr2) != PLUS)
8857 return 0;
8858
8859 if (GET_CODE (XEXP (addr2, 0)) != REG
8860 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8861 return 0;
8862
8863 if (reg1 != REGNO (XEXP (addr2, 0)))
8864 return 0;
8865
8866 /* The offset for the second addr must be 8 more than the first addr. */
8867 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
8868 return 0;
8869
8870 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
8871 instructions. */
8872 return 1;
8873}
9878760c
RK
8874\f
8875/* Return the register class of a scratch register needed to copy IN into
8876 or out of a register in CLASS in MODE. If it can be done directly,
8877 NO_REGS is returned. */
8878
8879enum reg_class
a2369ed3 8880secondary_reload_class (enum reg_class class,
a9baceb1
GK
8881 enum machine_mode mode ATTRIBUTE_UNUSED,
8882 rtx in)
9878760c 8883{
5accd822 8884 int regno;
9878760c 8885
ab82a49f
AP
8886 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
8887#if TARGET_MACHO
8888 && MACHOPIC_INDIRECT
8889#endif
8890 ))
46fad5b7
DJ
8891 {
8892 /* We cannot copy a symbolic operand directly into anything
8893 other than BASE_REGS for TARGET_ELF. So indicate that a
8894 register from BASE_REGS is needed as an intermediate
8895 register.
8896
8897 On Darwin, pic addresses require a load from memory, which
8898 needs a base register. */
8899 if (class != BASE_REGS
8900 && (GET_CODE (in) == SYMBOL_REF
8901 || GET_CODE (in) == HIGH
8902 || GET_CODE (in) == LABEL_REF
8903 || GET_CODE (in) == CONST))
8904 return BASE_REGS;
8905 }
e7b7998a 8906
5accd822
DE
8907 if (GET_CODE (in) == REG)
8908 {
8909 regno = REGNO (in);
8910 if (regno >= FIRST_PSEUDO_REGISTER)
8911 {
8912 regno = true_regnum (in);
8913 if (regno >= FIRST_PSEUDO_REGISTER)
8914 regno = -1;
8915 }
8916 }
8917 else if (GET_CODE (in) == SUBREG)
8918 {
8919 regno = true_regnum (in);
8920 if (regno >= FIRST_PSEUDO_REGISTER)
8921 regno = -1;
8922 }
8923 else
8924 regno = -1;
8925
9878760c
RK
8926 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
8927 into anything. */
8928 if (class == GENERAL_REGS || class == BASE_REGS
8929 || (regno >= 0 && INT_REGNO_P (regno)))
8930 return NO_REGS;
8931
8932 /* Constants, memory, and FP registers can go into FP registers. */
8933 if ((regno == -1 || FP_REGNO_P (regno))
8934 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
8935 return NO_REGS;
8936
0ac081f6
AH
8937 /* Memory, and AltiVec registers can go into AltiVec registers. */
8938 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
8939 && class == ALTIVEC_REGS)
8940 return NO_REGS;
8941
9878760c
RK
8942 /* We can copy among the CR registers. */
8943 if ((class == CR_REGS || class == CR0_REGS)
8944 && regno >= 0 && CR_REGNO_P (regno))
8945 return NO_REGS;
8946
8947 /* Otherwise, we need GENERAL_REGS. */
8948 return GENERAL_REGS;
8949}
8950\f
8951/* Given a comparison operation, return the bit number in CCR to test. We
8952 know this is a valid comparison.
8953
8954 SCC_P is 1 if this is for an scc. That means that %D will have been
8955 used instead of %C, so the bits will be in different places.
8956
b4ac57ab 8957 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
8958
8959int
a2369ed3 8960ccr_bit (rtx op, int scc_p)
9878760c
RK
8961{
8962 enum rtx_code code = GET_CODE (op);
8963 enum machine_mode cc_mode;
8964 int cc_regnum;
8965 int base_bit;
9ebbca7d 8966 rtx reg;
9878760c 8967
ec8e098d 8968 if (!COMPARISON_P (op))
9878760c
RK
8969 return -1;
8970
9ebbca7d
GK
8971 reg = XEXP (op, 0);
8972
8973 if (GET_CODE (reg) != REG
8974 || ! CR_REGNO_P (REGNO (reg)))
8975 abort ();
8976
8977 cc_mode = GET_MODE (reg);
8978 cc_regnum = REGNO (reg);
8979 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 8980
39a10a29 8981 validate_condition_mode (code, cc_mode);
c5defebb 8982
b7053a3f
GK
8983 /* When generating a sCOND operation, only positive conditions are
8984 allowed. */
8985 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
8986 && code != GTU && code != LTU)
8987 abort ();
8988
9878760c
RK
8989 switch (code)
8990 {
8991 case NE:
8992 return scc_p ? base_bit + 3 : base_bit + 2;
8993 case EQ:
8994 return base_bit + 2;
1c882ea4 8995 case GT: case GTU: case UNLE:
9878760c 8996 return base_bit + 1;
1c882ea4 8997 case LT: case LTU: case UNGE:
9878760c 8998 return base_bit;
1c882ea4
GK
8999 case ORDERED: case UNORDERED:
9000 return base_bit + 3;
9878760c
RK
9001
9002 case GE: case GEU:
39a10a29 9003 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
9004 unordered position. So test that bit. For integer, this is ! LT
9005 unless this is an scc insn. */
39a10a29 9006 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
9007
9008 case LE: case LEU:
39a10a29 9009 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 9010
9878760c
RK
9011 default:
9012 abort ();
9013 }
9014}
1ff7789b 9015\f
8d30c4ee 9016/* Return the GOT register. */
1ff7789b
MM
9017
9018struct rtx_def *
a2369ed3 9019rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 9020{
a4f6c312
SS
9021 /* The second flow pass currently (June 1999) can't update
9022 regs_ever_live without disturbing other parts of the compiler, so
9023 update it here to make the prolog/epilogue code happy. */
1db02437
FS
9024 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
9025 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 9026
8d30c4ee 9027 current_function_uses_pic_offset_table = 1;
3cb999d8 9028
1ff7789b
MM
9029 return pic_offset_table_rtx;
9030}
a7df97e6 9031\f
e2500fed
GK
9032/* Function to init struct machine_function.
9033 This will be called, via a pointer variable,
9034 from push_function_context. */
a7df97e6 9035
e2500fed 9036static struct machine_function *
863d938c 9037rs6000_init_machine_status (void)
a7df97e6 9038{
e2500fed 9039 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 9040}
9878760c 9041\f
0ba1b2ff
AM
9042/* These macros test for integers and extract the low-order bits. */
9043#define INT_P(X) \
9044((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
9045 && GET_MODE (X) == VOIDmode)
9046
9047#define INT_LOWPART(X) \
9048 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
9049
9050int
a2369ed3 9051extract_MB (rtx op)
0ba1b2ff
AM
9052{
9053 int i;
9054 unsigned long val = INT_LOWPART (op);
9055
9056 /* If the high bit is zero, the value is the first 1 bit we find
9057 from the left. */
9058 if ((val & 0x80000000) == 0)
9059 {
9060 if ((val & 0xffffffff) == 0)
9061 abort ();
9062
9063 i = 1;
9064 while (((val <<= 1) & 0x80000000) == 0)
9065 ++i;
9066 return i;
9067 }
9068
9069 /* If the high bit is set and the low bit is not, or the mask is all
9070 1's, the value is zero. */
9071 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
9072 return 0;
9073
9074 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9075 from the right. */
9076 i = 31;
9077 while (((val >>= 1) & 1) != 0)
9078 --i;
9079
9080 return i;
9081}
9082
9083int
a2369ed3 9084extract_ME (rtx op)
0ba1b2ff
AM
9085{
9086 int i;
9087 unsigned long val = INT_LOWPART (op);
9088
9089 /* If the low bit is zero, the value is the first 1 bit we find from
9090 the right. */
9091 if ((val & 1) == 0)
9092 {
9093 if ((val & 0xffffffff) == 0)
9094 abort ();
9095
9096 i = 30;
9097 while (((val >>= 1) & 1) == 0)
9098 --i;
9099
9100 return i;
9101 }
9102
9103 /* If the low bit is set and the high bit is not, or the mask is all
9104 1's, the value is 31. */
9105 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
9106 return 31;
9107
9108 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
9109 from the left. */
9110 i = 0;
9111 while (((val <<= 1) & 0x80000000) != 0)
9112 ++i;
9113
9114 return i;
9115}
9116
c4501e62
JJ
9117/* Locate some local-dynamic symbol still in use by this function
9118 so that we can print its name in some tls_ld pattern. */
9119
9120static const char *
863d938c 9121rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
9122{
9123 rtx insn;
9124
9125 if (cfun->machine->some_ld_name)
9126 return cfun->machine->some_ld_name;
9127
9128 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
9129 if (INSN_P (insn)
9130 && for_each_rtx (&PATTERN (insn),
9131 rs6000_get_some_local_dynamic_name_1, 0))
9132 return cfun->machine->some_ld_name;
9133
9134 abort ();
9135}
9136
9137/* Helper function for rs6000_get_some_local_dynamic_name. */
9138
9139static int
a2369ed3 9140rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
9141{
9142 rtx x = *px;
9143
9144 if (GET_CODE (x) == SYMBOL_REF)
9145 {
9146 const char *str = XSTR (x, 0);
9147 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
9148 {
9149 cfun->machine->some_ld_name = str;
9150 return 1;
9151 }
9152 }
9153
9154 return 0;
9155}
9156
9878760c
RK
9157/* Print an operand. Recognize special options, documented below. */
9158
38c1f2d7 9159#if TARGET_ELF
d9407988 9160#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 9161#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
9162#else
9163#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 9164#define SMALL_DATA_REG 0
ba5e43aa
MM
9165#endif
9166
9878760c 9167void
a2369ed3 9168print_operand (FILE *file, rtx x, int code)
9878760c
RK
9169{
9170 int i;
a260abc9 9171 HOST_WIDE_INT val;
0ba1b2ff 9172 unsigned HOST_WIDE_INT uval;
9878760c
RK
9173
9174 switch (code)
9175 {
a8b3aeda 9176 case '.':
a85d226b
RK
9177 /* Write out an instruction after the call which may be replaced
9178 with glue code by the loader. This depends on the AIX version. */
9179 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
9180 return;
9181
81eace42
GK
9182 /* %a is output_address. */
9183
9854d9ed
RK
9184 case 'A':
9185 /* If X is a constant integer whose low-order 5 bits are zero,
9186 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 9187 in the AIX assembler where "sri" with a zero shift count
20e26713 9188 writes a trash instruction. */
9854d9ed 9189 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 9190 putc ('l', file);
9854d9ed 9191 else
76229ac8 9192 putc ('r', file);
9854d9ed
RK
9193 return;
9194
9195 case 'b':
e2c953b6
DE
9196 /* If constant, low-order 16 bits of constant, unsigned.
9197 Otherwise, write normally. */
9198 if (INT_P (x))
9199 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
9200 else
9201 print_operand (file, x, 0);
cad12a8d
RK
9202 return;
9203
a260abc9
DE
9204 case 'B':
9205 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
9206 for 64-bit mask direction. */
296b8152 9207 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 9208 return;
a260abc9 9209
81eace42
GK
9210 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
9211 output_operand. */
9212
423c1189
AH
9213 case 'c':
9214 /* X is a CR register. Print the number of the GT bit of the CR. */
9215 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9216 output_operand_lossage ("invalid %%E value");
9217 else
9218 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 1);
9219 return;
9220
9221 case 'D':
9222 /* Like 'J' but get to the GT bit. */
9223 if (GET_CODE (x) != REG)
9224 abort ();
9225
9226 /* Bit 1 is GT bit. */
9227 i = 4 * (REGNO (x) - CR0_REGNO) + 1;
9228
9229 /* If we want bit 31, write a shift count of zero, not 32. */
9230 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9231 return;
9232
9854d9ed 9233 case 'E':
39a10a29 9234 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
9235 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9236 output_operand_lossage ("invalid %%E value");
78fbdbf7 9237 else
39a10a29 9238 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 9239 return;
9854d9ed
RK
9240
9241 case 'f':
9242 /* X is a CR register. Print the shift count needed to move it
9243 to the high-order four bits. */
9244 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9245 output_operand_lossage ("invalid %%f value");
9246 else
9ebbca7d 9247 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9248 return;
9249
9250 case 'F':
9251 /* Similar, but print the count for the rotate in the opposite
9252 direction. */
9253 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9254 output_operand_lossage ("invalid %%F value");
9255 else
9ebbca7d 9256 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9257 return;
9258
9259 case 'G':
9260 /* X is a constant integer. If it is negative, print "m",
43aa4e05 9261 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
9262 if (GET_CODE (x) != CONST_INT)
9263 output_operand_lossage ("invalid %%G value");
9264 else if (INTVAL (x) >= 0)
76229ac8 9265 putc ('z', file);
9854d9ed 9266 else
76229ac8 9267 putc ('m', file);
9854d9ed 9268 return;
e2c953b6 9269
9878760c 9270 case 'h':
a4f6c312
SS
9271 /* If constant, output low-order five bits. Otherwise, write
9272 normally. */
9878760c 9273 if (INT_P (x))
5f59ecb7 9274 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
9275 else
9276 print_operand (file, x, 0);
9277 return;
9278
64305719 9279 case 'H':
a4f6c312
SS
9280 /* If constant, output low-order six bits. Otherwise, write
9281 normally. */
64305719 9282 if (INT_P (x))
5f59ecb7 9283 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
9284 else
9285 print_operand (file, x, 0);
9286 return;
9287
9854d9ed
RK
9288 case 'I':
9289 /* Print `i' if this is a constant, else nothing. */
9878760c 9290 if (INT_P (x))
76229ac8 9291 putc ('i', file);
9878760c
RK
9292 return;
9293
9854d9ed
RK
9294 case 'j':
9295 /* Write the bit number in CCR for jump. */
9296 i = ccr_bit (x, 0);
9297 if (i == -1)
9298 output_operand_lossage ("invalid %%j code");
9878760c 9299 else
9854d9ed 9300 fprintf (file, "%d", i);
9878760c
RK
9301 return;
9302
9854d9ed
RK
9303 case 'J':
9304 /* Similar, but add one for shift count in rlinm for scc and pass
9305 scc flag to `ccr_bit'. */
9306 i = ccr_bit (x, 1);
9307 if (i == -1)
9308 output_operand_lossage ("invalid %%J code");
9309 else
a0466a68
RK
9310 /* If we want bit 31, write a shift count of zero, not 32. */
9311 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
9312 return;
9313
9854d9ed
RK
9314 case 'k':
9315 /* X must be a constant. Write the 1's complement of the
9316 constant. */
9878760c 9317 if (! INT_P (x))
9854d9ed 9318 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
9319 else
9320 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
9321 return;
9322
81eace42 9323 case 'K':
9ebbca7d
GK
9324 /* X must be a symbolic constant on ELF. Write an
9325 expression suitable for an 'addi' that adds in the low 16
9326 bits of the MEM. */
9327 if (GET_CODE (x) != CONST)
9328 {
9329 print_operand_address (file, x);
9330 fputs ("@l", file);
9331 }
9332 else
9333 {
9334 if (GET_CODE (XEXP (x, 0)) != PLUS
9335 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
9336 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
9337 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 9338 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
9339 print_operand_address (file, XEXP (XEXP (x, 0), 0));
9340 fputs ("@l", file);
ed8d2920
MM
9341 /* For GNU as, there must be a non-alphanumeric character
9342 between 'l' and the number. The '-' is added by
9343 print_operand() already. */
9344 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
9345 fputs ("+", file);
9ebbca7d
GK
9346 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
9347 }
81eace42
GK
9348 return;
9349
9350 /* %l is output_asm_label. */
9ebbca7d 9351
9854d9ed
RK
9352 case 'L':
9353 /* Write second word of DImode or DFmode reference. Works on register
9354 or non-indexed memory only. */
9355 if (GET_CODE (x) == REG)
5ebfb2ba 9356 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
9357 else if (GET_CODE (x) == MEM)
9358 {
9359 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 9360 we have already done it, we can just use an offset of word. */
9854d9ed
RK
9361 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9362 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
9363 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
9364 UNITS_PER_WORD));
9854d9ed 9365 else
d7624dc0
RK
9366 output_address (XEXP (adjust_address_nv (x, SImode,
9367 UNITS_PER_WORD),
9368 0));
ed8908e7 9369
ba5e43aa 9370 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9371 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9372 reg_names[SMALL_DATA_REG]);
9854d9ed 9373 }
9878760c 9374 return;
9854d9ed 9375
9878760c
RK
9376 case 'm':
9377 /* MB value for a mask operand. */
b1765bde 9378 if (! mask_operand (x, SImode))
9878760c
RK
9379 output_operand_lossage ("invalid %%m value");
9380
0ba1b2ff 9381 fprintf (file, "%d", extract_MB (x));
9878760c
RK
9382 return;
9383
9384 case 'M':
9385 /* ME value for a mask operand. */
b1765bde 9386 if (! mask_operand (x, SImode))
a260abc9 9387 output_operand_lossage ("invalid %%M value");
9878760c 9388
0ba1b2ff 9389 fprintf (file, "%d", extract_ME (x));
9878760c
RK
9390 return;
9391
81eace42
GK
9392 /* %n outputs the negative of its operand. */
9393
9878760c
RK
9394 case 'N':
9395 /* Write the number of elements in the vector times 4. */
9396 if (GET_CODE (x) != PARALLEL)
9397 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
9398 else
9399 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
9400 return;
9401
9402 case 'O':
9403 /* Similar, but subtract 1 first. */
9404 if (GET_CODE (x) != PARALLEL)
1427100a 9405 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
9406 else
9407 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
9408 return;
9409
9854d9ed
RK
9410 case 'p':
9411 /* X is a CONST_INT that is a power of two. Output the logarithm. */
9412 if (! INT_P (x)
2bfcf297 9413 || INT_LOWPART (x) < 0
9854d9ed
RK
9414 || (i = exact_log2 (INT_LOWPART (x))) < 0)
9415 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
9416 else
9417 fprintf (file, "%d", i);
9854d9ed
RK
9418 return;
9419
9878760c
RK
9420 case 'P':
9421 /* The operand must be an indirect memory reference. The result
8bb418a3 9422 is the register name. */
9878760c
RK
9423 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
9424 || REGNO (XEXP (x, 0)) >= 32)
9425 output_operand_lossage ("invalid %%P value");
e2c953b6 9426 else
8bb418a3 9427 fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]);
9878760c
RK
9428 return;
9429
dfbdccdb
GK
9430 case 'q':
9431 /* This outputs the logical code corresponding to a boolean
9432 expression. The expression may have one or both operands
39a10a29
GK
9433 negated (if one, only the first one). For condition register
9434 logical operations, it will also treat the negated
9435 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 9436 {
63bc1d05 9437 const char *const *t = 0;
dfbdccdb
GK
9438 const char *s;
9439 enum rtx_code code = GET_CODE (x);
9440 static const char * const tbl[3][3] = {
9441 { "and", "andc", "nor" },
9442 { "or", "orc", "nand" },
9443 { "xor", "eqv", "xor" } };
9444
9445 if (code == AND)
9446 t = tbl[0];
9447 else if (code == IOR)
9448 t = tbl[1];
9449 else if (code == XOR)
9450 t = tbl[2];
9451 else
9452 output_operand_lossage ("invalid %%q value");
9453
9454 if (GET_CODE (XEXP (x, 0)) != NOT)
9455 s = t[0];
9456 else
9457 {
9458 if (GET_CODE (XEXP (x, 1)) == NOT)
9459 s = t[2];
9460 else
9461 s = t[1];
9462 }
9463
9464 fputs (s, file);
9465 }
9466 return;
9467
2c4a9cff
DE
9468 case 'Q':
9469 if (TARGET_MFCRF)
3b6ce0af 9470 fputc (',', file);
5efb1046 9471 /* FALLTHRU */
2c4a9cff
DE
9472 else
9473 return;
9474
9854d9ed
RK
9475 case 'R':
9476 /* X is a CR register. Print the mask for `mtcrf'. */
9477 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9478 output_operand_lossage ("invalid %%R value");
9479 else
9ebbca7d 9480 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 9481 return;
9854d9ed
RK
9482
9483 case 's':
9484 /* Low 5 bits of 32 - value */
9485 if (! INT_P (x))
9486 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
9487 else
9488 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 9489 return;
9854d9ed 9490
a260abc9 9491 case 'S':
0ba1b2ff 9492 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
9493 CONST_INT 32-bit mask is considered sign-extended so any
9494 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 9495 if (! mask64_operand (x, DImode))
a260abc9
DE
9496 output_operand_lossage ("invalid %%S value");
9497
0ba1b2ff 9498 uval = INT_LOWPART (x);
a260abc9 9499
0ba1b2ff 9500 if (uval & 1) /* Clear Left */
a260abc9 9501 {
f099d360
GK
9502#if HOST_BITS_PER_WIDE_INT > 64
9503 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9504#endif
0ba1b2ff 9505 i = 64;
a260abc9 9506 }
0ba1b2ff 9507 else /* Clear Right */
a260abc9 9508 {
0ba1b2ff 9509 uval = ~uval;
f099d360
GK
9510#if HOST_BITS_PER_WIDE_INT > 64
9511 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9512#endif
0ba1b2ff 9513 i = 63;
a260abc9 9514 }
0ba1b2ff
AM
9515 while (uval != 0)
9516 --i, uval >>= 1;
9517 if (i < 0)
9518 abort ();
9519 fprintf (file, "%d", i);
9520 return;
a260abc9 9521
a3170dc6
AH
9522 case 't':
9523 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
9524 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
9525 abort ();
9526
9527 /* Bit 3 is OV bit. */
9528 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
9529
9530 /* If we want bit 31, write a shift count of zero, not 32. */
9531 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9532 return;
9533
cccf3bdc
DE
9534 case 'T':
9535 /* Print the symbolic name of a branch target register. */
9536 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
9537 && REGNO (x) != COUNT_REGISTER_REGNUM))
9538 output_operand_lossage ("invalid %%T value");
e2c953b6 9539 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
9540 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
9541 else
9542 fputs ("ctr", file);
9543 return;
9544
9854d9ed 9545 case 'u':
802a0058 9546 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
9547 if (! INT_P (x))
9548 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
9549 else
9550 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9551 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
9552 return;
9553
802a0058
MM
9554 case 'v':
9555 /* High-order 16 bits of constant for use in signed operand. */
9556 if (! INT_P (x))
9557 output_operand_lossage ("invalid %%v value");
e2c953b6 9558 else
134c32f6
DE
9559 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9560 (INT_LOWPART (x) >> 16) & 0xffff);
9561 return;
802a0058 9562
9854d9ed
RK
9563 case 'U':
9564 /* Print `u' if this has an auto-increment or auto-decrement. */
9565 if (GET_CODE (x) == MEM
9566 && (GET_CODE (XEXP (x, 0)) == PRE_INC
9567 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 9568 putc ('u', file);
9854d9ed 9569 return;
9878760c 9570
e0cd0770
JC
9571 case 'V':
9572 /* Print the trap code for this operand. */
9573 switch (GET_CODE (x))
9574 {
9575 case EQ:
9576 fputs ("eq", file); /* 4 */
9577 break;
9578 case NE:
9579 fputs ("ne", file); /* 24 */
9580 break;
9581 case LT:
9582 fputs ("lt", file); /* 16 */
9583 break;
9584 case LE:
9585 fputs ("le", file); /* 20 */
9586 break;
9587 case GT:
9588 fputs ("gt", file); /* 8 */
9589 break;
9590 case GE:
9591 fputs ("ge", file); /* 12 */
9592 break;
9593 case LTU:
9594 fputs ("llt", file); /* 2 */
9595 break;
9596 case LEU:
9597 fputs ("lle", file); /* 6 */
9598 break;
9599 case GTU:
9600 fputs ("lgt", file); /* 1 */
9601 break;
9602 case GEU:
9603 fputs ("lge", file); /* 5 */
9604 break;
9605 default:
9606 abort ();
9607 }
9608 break;
9609
9854d9ed
RK
9610 case 'w':
9611 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
9612 normally. */
9613 if (INT_P (x))
5f59ecb7
DE
9614 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
9615 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
9616 else
9617 print_operand (file, x, 0);
9878760c
RK
9618 return;
9619
9854d9ed 9620 case 'W':
e2c953b6 9621 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
9622 val = (GET_CODE (x) == CONST_INT
9623 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
9624
9625 if (val < 0)
9626 i = -1;
9854d9ed 9627 else
e2c953b6
DE
9628 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
9629 if ((val <<= 1) < 0)
9630 break;
9631
9632#if HOST_BITS_PER_WIDE_INT == 32
9633 if (GET_CODE (x) == CONST_INT && i >= 0)
9634 i += 32; /* zero-extend high-part was all 0's */
9635 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
9636 {
9637 val = CONST_DOUBLE_LOW (x);
9638
9639 if (val == 0)
a4f6c312 9640 abort ();
e2c953b6
DE
9641 else if (val < 0)
9642 --i;
9643 else
9644 for ( ; i < 64; i++)
9645 if ((val <<= 1) < 0)
9646 break;
9647 }
9648#endif
9649
9650 fprintf (file, "%d", i + 1);
9854d9ed 9651 return;
9878760c 9652
9854d9ed
RK
9653 case 'X':
9654 if (GET_CODE (x) == MEM
4d588c14 9655 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 9656 putc ('x', file);
9854d9ed 9657 return;
9878760c 9658
9854d9ed
RK
9659 case 'Y':
9660 /* Like 'L', for third word of TImode */
9661 if (GET_CODE (x) == REG)
5ebfb2ba 9662 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 9663 else if (GET_CODE (x) == MEM)
9878760c 9664 {
9854d9ed
RK
9665 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9666 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9667 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 9668 else
d7624dc0 9669 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 9670 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9671 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9672 reg_names[SMALL_DATA_REG]);
9878760c
RK
9673 }
9674 return;
9854d9ed 9675
9878760c 9676 case 'z':
b4ac57ab
RS
9677 /* X is a SYMBOL_REF. Write out the name preceded by a
9678 period and without any trailing data in brackets. Used for function
4d30c363
MM
9679 names. If we are configured for System V (or the embedded ABI) on
9680 the PowerPC, do not emit the period, since those systems do not use
9681 TOCs and the like. */
9878760c
RK
9682 if (GET_CODE (x) != SYMBOL_REF)
9683 abort ();
9684
9bf6462a
AP
9685 /* Mark the decl as referenced so that cgraph will output the function. */
9686 if (SYMBOL_REF_DECL (x))
9687 mark_decl_referenced (SYMBOL_REF_DECL (x));
9688
b6c9286a
MM
9689 if (XSTR (x, 0)[0] != '.')
9690 {
9691 switch (DEFAULT_ABI)
9692 {
9693 default:
9694 abort ();
9695
9696 case ABI_AIX:
9697 putc ('.', file);
9698 break;
9699
9700 case ABI_V4:
ee890fe2 9701 case ABI_DARWIN:
b6c9286a 9702 break;
b6c9286a
MM
9703 }
9704 }
f9da97f0
AP
9705 /* For macho, we need to check it see if we need a stub. */
9706 if (TARGET_MACHO)
9707 {
9708 const char *name = XSTR (x, 0);
a031e781 9709#if TARGET_MACHO
f9da97f0
AP
9710 if (machopic_classify_name (name) == MACHOPIC_UNDEFINED_FUNCTION)
9711 name = machopic_stub_name (name);
9712#endif
9713 assemble_name (file, name);
9714 }
9715 else if (TARGET_AIX)
9739c90c
JJ
9716 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9717 else
9718 assemble_name (file, XSTR (x, 0));
9878760c
RK
9719 return;
9720
9854d9ed
RK
9721 case 'Z':
9722 /* Like 'L', for last word of TImode. */
9723 if (GET_CODE (x) == REG)
5ebfb2ba 9724 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
9725 else if (GET_CODE (x) == MEM)
9726 {
9727 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9728 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9729 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 9730 else
d7624dc0 9731 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 9732 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9733 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9734 reg_names[SMALL_DATA_REG]);
9854d9ed 9735 }
5c23c401 9736 return;
0ac081f6 9737
a3170dc6 9738 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
9739 case 'y':
9740 {
9741 rtx tmp;
9742
9743 if (GET_CODE (x) != MEM)
9744 abort ();
9745
9746 tmp = XEXP (x, 0);
9747
993f19a8 9748 if (TARGET_E500)
a3170dc6
AH
9749 {
9750 /* Handle [reg]. */
9751 if (GET_CODE (tmp) == REG)
9752 {
9753 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
9754 break;
9755 }
9756 /* Handle [reg+UIMM]. */
9757 else if (GET_CODE (tmp) == PLUS &&
9758 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
9759 {
9760 int x;
9761
9762 if (GET_CODE (XEXP (tmp, 0)) != REG)
9763 abort ();
9764
9765 x = INTVAL (XEXP (tmp, 1));
9766 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
9767 break;
9768 }
9769
9770 /* Fall through. Must be [reg+reg]. */
9771 }
0ac081f6 9772 if (GET_CODE (tmp) == REG)
c62f2db5 9773 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
9774 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
9775 {
9776 if (REGNO (XEXP (tmp, 0)) == 0)
9777 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
9778 reg_names[ REGNO (XEXP (tmp, 0)) ]);
9779 else
9780 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
9781 reg_names[ REGNO (XEXP (tmp, 1)) ]);
9782 }
9783 else
9784 abort ();
9785 break;
9786 }
9854d9ed 9787
9878760c
RK
9788 case 0:
9789 if (GET_CODE (x) == REG)
9790 fprintf (file, "%s", reg_names[REGNO (x)]);
9791 else if (GET_CODE (x) == MEM)
9792 {
9793 /* We need to handle PRE_INC and PRE_DEC here, since we need to
9794 know the width from the mode. */
9795 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
9796 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
9797 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9798 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
9799 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
9800 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9801 else
a54d04b7 9802 output_address (XEXP (x, 0));
9878760c
RK
9803 }
9804 else
a54d04b7 9805 output_addr_const (file, x);
a85d226b 9806 return;
9878760c 9807
c4501e62
JJ
9808 case '&':
9809 assemble_name (file, rs6000_get_some_local_dynamic_name ());
9810 return;
9811
9878760c
RK
9812 default:
9813 output_operand_lossage ("invalid %%xn code");
9814 }
9815}
9816\f
9817/* Print the address of an operand. */
9818
9819void
a2369ed3 9820print_operand_address (FILE *file, rtx x)
9878760c
RK
9821{
9822 if (GET_CODE (x) == REG)
4697a36c 9823 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
9824 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
9825 || GET_CODE (x) == LABEL_REF)
9878760c
RK
9826 {
9827 output_addr_const (file, x);
ba5e43aa 9828 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9829 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9830 reg_names[SMALL_DATA_REG]);
9ebbca7d 9831 else if (TARGET_TOC)
a4f6c312 9832 abort ();
9878760c
RK
9833 }
9834 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
9835 {
9836 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
9837 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
9838 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 9839 else
4697a36c
MM
9840 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
9841 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
9842 }
9843 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
9844 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
9845 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
9846#if TARGET_ELF
9847 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9848 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
9849 {
9850 output_addr_const (file, XEXP (x, 1));
9851 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9852 }
c859cda6
DJ
9853#endif
9854#if TARGET_MACHO
9855 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9856 && CONSTANT_P (XEXP (x, 1)))
9857 {
9858 fprintf (file, "lo16(");
9859 output_addr_const (file, XEXP (x, 1));
9860 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9861 }
3cb999d8 9862#endif
4d588c14 9863 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 9864 {
2bfcf297 9865 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 9866 {
2bfcf297
DB
9867 rtx contains_minus = XEXP (x, 1);
9868 rtx minus, symref;
9869 const char *name;
9ebbca7d
GK
9870
9871 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 9872 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
9873 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
9874 contains_minus = XEXP (contains_minus, 0);
9875
2bfcf297
DB
9876 minus = XEXP (contains_minus, 0);
9877 symref = XEXP (minus, 0);
9878 XEXP (contains_minus, 0) = symref;
9879 if (TARGET_ELF)
9880 {
9881 char *newname;
9882
9883 name = XSTR (symref, 0);
9884 newname = alloca (strlen (name) + sizeof ("@toc"));
9885 strcpy (newname, name);
9886 strcat (newname, "@toc");
9887 XSTR (symref, 0) = newname;
9888 }
9889 output_addr_const (file, XEXP (x, 1));
9890 if (TARGET_ELF)
9891 XSTR (symref, 0) = name;
9ebbca7d
GK
9892 XEXP (contains_minus, 0) = minus;
9893 }
9894 else
9895 output_addr_const (file, XEXP (x, 1));
9896
9897 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9898 }
9878760c
RK
9899 else
9900 abort ();
9901}
9902\f
88cad84b 9903/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9904 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9905 is defined. It also needs to handle DI-mode objects on 64-bit
9906 targets. */
9907
9908static bool
a2369ed3 9909rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
9910{
9911#ifdef RELOCATABLE_NEEDS_FIXUP
9912 /* Special handling for SI values. */
9913 if (size == 4 && aligned_p)
9914 {
a2369ed3 9915 extern int in_toc_section (void);
301d03af
RS
9916 static int recurse = 0;
9917
9918 /* For -mrelocatable, we mark all addresses that need to be fixed up
9919 in the .fixup section. */
9920 if (TARGET_RELOCATABLE
9921 && !in_toc_section ()
9922 && !in_text_section ()
642af3be 9923 && !in_unlikely_text_section ()
301d03af
RS
9924 && !recurse
9925 && GET_CODE (x) != CONST_INT
9926 && GET_CODE (x) != CONST_DOUBLE
9927 && CONSTANT_P (x))
9928 {
9929 char buf[256];
9930
9931 recurse = 1;
9932 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9933 fixuplabelno++;
9934 ASM_OUTPUT_LABEL (asm_out_file, buf);
9935 fprintf (asm_out_file, "\t.long\t(");
9936 output_addr_const (asm_out_file, x);
9937 fprintf (asm_out_file, ")@fixup\n");
9938 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9939 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9940 fprintf (asm_out_file, "\t.long\t");
9941 assemble_name (asm_out_file, buf);
9942 fprintf (asm_out_file, "\n\t.previous\n");
9943 recurse = 0;
9944 return true;
9945 }
9946 /* Remove initial .'s to turn a -mcall-aixdesc function
9947 address into the address of the descriptor, not the function
9948 itself. */
9949 else if (GET_CODE (x) == SYMBOL_REF
9950 && XSTR (x, 0)[0] == '.'
9951 && DEFAULT_ABI == ABI_AIX)
9952 {
9953 const char *name = XSTR (x, 0);
9954 while (*name == '.')
9955 name++;
9956
9957 fprintf (asm_out_file, "\t.long\t%s\n", name);
9958 return true;
9959 }
9960 }
9961#endif /* RELOCATABLE_NEEDS_FIXUP */
9962 return default_assemble_integer (x, size, aligned_p);
9963}
93638d7a
AM
9964
9965#ifdef HAVE_GAS_HIDDEN
9966/* Emit an assembler directive to set symbol visibility for DECL to
9967 VISIBILITY_TYPE. */
9968
5add3202 9969static void
a2369ed3 9970rs6000_assemble_visibility (tree decl, int vis)
93638d7a 9971{
93638d7a
AM
9972 /* Functions need to have their entry point symbol visibility set as
9973 well as their descriptor symbol visibility. */
9974 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9975 {
25fdb4dc
RH
9976 static const char * const visibility_types[] = {
9977 NULL, "internal", "hidden", "protected"
9978 };
9979
9980 const char *name, *type;
93638d7a
AM
9981
9982 name = ((* targetm.strip_name_encoding)
9983 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9984 type = visibility_types[vis];
93638d7a 9985
25fdb4dc
RH
9986 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9987 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9988 }
25fdb4dc
RH
9989 else
9990 default_assemble_visibility (decl, vis);
93638d7a
AM
9991}
9992#endif
301d03af 9993\f
39a10a29 9994enum rtx_code
a2369ed3 9995rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
9996{
9997 /* Reversal of FP compares takes care -- an ordered compare
9998 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9999 if (mode == CCFPmode
10000 && (!flag_finite_math_only
10001 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
10002 || code == UNEQ || code == LTGT))
bab6226b 10003 return reverse_condition_maybe_unordered (code);
39a10a29 10004 else
bab6226b 10005 return reverse_condition (code);
39a10a29
GK
10006}
10007
39a10a29
GK
10008/* Generate a compare for CODE. Return a brand-new rtx that
10009 represents the result of the compare. */
a4f6c312 10010
39a10a29 10011static rtx
a2369ed3 10012rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
10013{
10014 enum machine_mode comp_mode;
10015 rtx compare_result;
10016
10017 if (rs6000_compare_fp_p)
10018 comp_mode = CCFPmode;
10019 else if (code == GTU || code == LTU
10020 || code == GEU || code == LEU)
10021 comp_mode = CCUNSmode;
10022 else
10023 comp_mode = CCmode;
10024
10025 /* First, the compare. */
10026 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
10027
10028 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
10029 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10030 && rs6000_compare_fp_p)
a3170dc6
AH
10031 {
10032 rtx cmp, or1, or2, or_result, compare_result2;
10033
423c1189
AH
10034 /* Note: The E500 comparison instructions set the GT bit (x +
10035 1), on success. This explains the mess. */
10036
a3170dc6
AH
10037 switch (code)
10038 {
423c1189 10039 case EQ: case UNEQ: case NE: case LTGT:
bc9ec0e0 10040 cmp = flag_finite_math_only
a3170dc6
AH
10041 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
10042 rs6000_compare_op1)
10043 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
10044 rs6000_compare_op1);
10045 break;
423c1189 10046 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
bc9ec0e0 10047 cmp = flag_finite_math_only
a3170dc6
AH
10048 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
10049 rs6000_compare_op1)
10050 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
10051 rs6000_compare_op1);
10052 break;
423c1189 10053 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
bc9ec0e0 10054 cmp = flag_finite_math_only
a3170dc6
AH
10055 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
10056 rs6000_compare_op1)
10057 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
10058 rs6000_compare_op1);
10059 break;
10060 default:
10061 abort ();
10062 }
10063
10064 /* Synthesize LE and GE from LT/GT || EQ. */
10065 if (code == LE || code == GE || code == LEU || code == GEU)
10066 {
a3170dc6
AH
10067 emit_insn (cmp);
10068
10069 switch (code)
10070 {
10071 case LE: code = LT; break;
10072 case GE: code = GT; break;
10073 case LEU: code = LT; break;
10074 case GEU: code = GT; break;
10075 default: abort ();
10076 }
10077
10078 or1 = gen_reg_rtx (SImode);
10079 or2 = gen_reg_rtx (SImode);
10080 or_result = gen_reg_rtx (CCEQmode);
10081 compare_result2 = gen_reg_rtx (CCFPmode);
10082
10083 /* Do the EQ. */
bc9ec0e0 10084 cmp = flag_finite_math_only
a3170dc6
AH
10085 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
10086 rs6000_compare_op1)
10087 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
10088 rs6000_compare_op1);
10089 emit_insn (cmp);
10090
423c1189
AH
10091 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
10092 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
10093
10094 /* OR them together. */
10095 cmp = gen_rtx_SET (VOIDmode, or_result,
10096 gen_rtx_COMPARE (CCEQmode,
10097 gen_rtx_IOR (SImode, or1, or2),
10098 const_true_rtx));
10099 compare_result = or_result;
10100 code = EQ;
10101 }
10102 else
10103 {
a3170dc6 10104 if (code == NE || code == LTGT)
a3170dc6 10105 code = NE;
423c1189
AH
10106 else
10107 code = EQ;
a3170dc6
AH
10108 }
10109
10110 emit_insn (cmp);
10111 }
10112 else
10113 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
10114 gen_rtx_COMPARE (comp_mode,
10115 rs6000_compare_op0,
10116 rs6000_compare_op1)));
39a10a29 10117
ca5adc63 10118 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 10119 under flag_finite_math_only we don't bother. */
39a10a29 10120 if (rs6000_compare_fp_p
bc9ec0e0 10121 && ! flag_finite_math_only
993f19a8 10122 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
10123 && (code == LE || code == GE
10124 || code == UNEQ || code == LTGT
10125 || code == UNGT || code == UNLT))
10126 {
10127 enum rtx_code or1, or2;
10128 rtx or1_rtx, or2_rtx, compare2_rtx;
10129 rtx or_result = gen_reg_rtx (CCEQmode);
10130
10131 switch (code)
10132 {
10133 case LE: or1 = LT; or2 = EQ; break;
10134 case GE: or1 = GT; or2 = EQ; break;
10135 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
10136 case LTGT: or1 = LT; or2 = GT; break;
10137 case UNGT: or1 = UNORDERED; or2 = GT; break;
10138 case UNLT: or1 = UNORDERED; or2 = LT; break;
10139 default: abort ();
10140 }
10141 validate_condition_mode (or1, comp_mode);
10142 validate_condition_mode (or2, comp_mode);
1c563bed
KH
10143 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
10144 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
10145 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
10146 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
10147 const_true_rtx);
10148 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
10149
10150 compare_result = or_result;
10151 code = EQ;
10152 }
10153
10154 validate_condition_mode (code, GET_MODE (compare_result));
10155
1c563bed 10156 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
10157}
10158
10159
10160/* Emit the RTL for an sCOND pattern. */
10161
10162void
a2369ed3 10163rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
10164{
10165 rtx condition_rtx;
10166 enum machine_mode op_mode;
b7053a3f 10167 enum rtx_code cond_code;
39a10a29
GK
10168
10169 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
10170 cond_code = GET_CODE (condition_rtx);
10171
423c1189
AH
10172 if (TARGET_E500 && rs6000_compare_fp_p
10173 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10174 {
10175 rtx t;
10176
10177 PUT_MODE (condition_rtx, SImode);
10178 t = XEXP (condition_rtx, 0);
10179
10180 if (cond_code != NE && cond_code != EQ)
10181 abort ();
10182
10183 if (cond_code == NE)
10184 emit_insn (gen_e500_flip_gt_bit (t, t));
10185
10186 emit_insn (gen_move_from_CR_gt_bit (result, t));
10187 return;
10188 }
10189
b7053a3f
GK
10190 if (cond_code == NE
10191 || cond_code == GE || cond_code == LE
10192 || cond_code == GEU || cond_code == LEU
10193 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
10194 {
10195 rtx not_result = gen_reg_rtx (CCEQmode);
10196 rtx not_op, rev_cond_rtx;
10197 enum machine_mode cc_mode;
10198
10199 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
10200
1c563bed 10201 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 10202 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
10203 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
10204 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
10205 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
10206 }
39a10a29
GK
10207
10208 op_mode = GET_MODE (rs6000_compare_op0);
10209 if (op_mode == VOIDmode)
10210 op_mode = GET_MODE (rs6000_compare_op1);
10211
10212 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
10213 {
10214 PUT_MODE (condition_rtx, DImode);
10215 convert_move (result, condition_rtx, 0);
10216 }
10217 else
10218 {
10219 PUT_MODE (condition_rtx, SImode);
10220 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
10221 }
10222}
10223
39a10a29
GK
10224/* Emit a branch of kind CODE to location LOC. */
10225
10226void
a2369ed3 10227rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
10228{
10229 rtx condition_rtx, loc_ref;
10230
10231 condition_rtx = rs6000_generate_compare (code);
10232 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
10233 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
10234 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
10235 loc_ref, pc_rtx)));
10236}
10237
12a4e8c5
GK
10238/* Return the string to output a conditional branch to LABEL, which is
10239 the operand number of the label, or -1 if the branch is really a
10240 conditional return.
10241
10242 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
10243 condition code register and its mode specifies what kind of
10244 comparison we made.
10245
a0ab749a 10246 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
10247
10248 INSN is the insn. */
10249
10250char *
a2369ed3 10251output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
10252{
10253 static char string[64];
10254 enum rtx_code code = GET_CODE (op);
10255 rtx cc_reg = XEXP (op, 0);
10256 enum machine_mode mode = GET_MODE (cc_reg);
10257 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 10258 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
10259 int really_reversed = reversed ^ need_longbranch;
10260 char *s = string;
10261 const char *ccode;
10262 const char *pred;
10263 rtx note;
10264
39a10a29
GK
10265 validate_condition_mode (code, mode);
10266
10267 /* Work out which way this really branches. We could use
10268 reverse_condition_maybe_unordered here always but this
10269 makes the resulting assembler clearer. */
12a4e8c5 10270 if (really_reversed)
de40e1df
DJ
10271 {
10272 /* Reversal of FP compares takes care -- an ordered compare
10273 becomes an unordered compare and vice versa. */
10274 if (mode == CCFPmode)
10275 code = reverse_condition_maybe_unordered (code);
10276 else
10277 code = reverse_condition (code);
10278 }
12a4e8c5 10279
993f19a8 10280 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
10281 {
10282 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
10283 to the GT bit. */
10284 if (code == EQ)
10285 /* Opposite of GT. */
a3170dc6 10286 code = GT;
423c1189
AH
10287 else if (code == NE)
10288 code = UNLE;
a3170dc6
AH
10289 else
10290 abort ();
10291 }
10292
39a10a29 10293 switch (code)
12a4e8c5
GK
10294 {
10295 /* Not all of these are actually distinct opcodes, but
10296 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
10297 case NE: case LTGT:
10298 ccode = "ne"; break;
10299 case EQ: case UNEQ:
10300 ccode = "eq"; break;
10301 case GE: case GEU:
10302 ccode = "ge"; break;
10303 case GT: case GTU: case UNGT:
10304 ccode = "gt"; break;
10305 case LE: case LEU:
10306 ccode = "le"; break;
10307 case LT: case LTU: case UNLT:
10308 ccode = "lt"; break;
12a4e8c5
GK
10309 case UNORDERED: ccode = "un"; break;
10310 case ORDERED: ccode = "nu"; break;
10311 case UNGE: ccode = "nl"; break;
10312 case UNLE: ccode = "ng"; break;
10313 default:
a4f6c312 10314 abort ();
12a4e8c5
GK
10315 }
10316
94a54f47
GK
10317 /* Maybe we have a guess as to how likely the branch is.
10318 The old mnemonics don't have a way to specify this information. */
f4857b9b 10319 pred = "";
12a4e8c5
GK
10320 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
10321 if (note != NULL_RTX)
10322 {
10323 /* PROB is the difference from 50%. */
10324 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
10325
10326 /* Only hint for highly probable/improbable branches on newer
10327 cpus as static prediction overrides processor dynamic
10328 prediction. For older cpus we may as well always hint, but
10329 assume not taken for branches that are very close to 50% as a
10330 mispredicted taken branch is more expensive than a
10331 mispredicted not-taken branch. */
ec507f2d 10332 if (rs6000_always_hint
f4857b9b
AM
10333 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
10334 {
10335 if (abs (prob) > REG_BR_PROB_BASE / 20
10336 && ((prob > 0) ^ need_longbranch))
7f3d8013 10337 pred = "+";
f4857b9b
AM
10338 else
10339 pred = "-";
10340 }
12a4e8c5 10341 }
12a4e8c5
GK
10342
10343 if (label == NULL)
94a54f47 10344 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 10345 else
94a54f47 10346 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 10347
37c67319 10348 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 10349 Assume they'd only be the first character.... */
37c67319
GK
10350 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
10351 *s++ = '%';
94a54f47 10352 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
10353
10354 if (label != NULL)
10355 {
10356 /* If the branch distance was too far, we may have to use an
10357 unconditional branch to go the distance. */
10358 if (need_longbranch)
44518ddd 10359 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
10360 else
10361 s += sprintf (s, ",%s", label);
10362 }
10363
10364 return string;
10365}
50a0b056 10366
423c1189
AH
10367/* Return the string to flip the GT bit on a CR. */
10368char *
10369output_e500_flip_gt_bit (rtx dst, rtx src)
10370{
10371 static char string[64];
10372 int a, b;
10373
10374 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
10375 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
10376 abort ();
10377
10378 /* GT bit. */
10379 a = 4 * (REGNO (dst) - CR0_REGNO) + 1;
10380 b = 4 * (REGNO (src) - CR0_REGNO) + 1;
10381
10382 sprintf (string, "crnot %d,%d", a, b);
10383 return string;
10384}
10385
50a0b056
GK
10386/* Emit a conditional move: move TRUE_COND to DEST if OP of the
10387 operands of the last comparison is nonzero/true, FALSE_COND if it
10388 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 10389
50a0b056 10390int
a2369ed3 10391rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
10392{
10393 enum rtx_code code = GET_CODE (op);
10394 rtx op0 = rs6000_compare_op0;
10395 rtx op1 = rs6000_compare_op1;
10396 REAL_VALUE_TYPE c1;
3148ad6d
DJ
10397 enum machine_mode compare_mode = GET_MODE (op0);
10398 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
10399 rtx temp;
10400
a3c9585f 10401 /* These modes should always match. */
a3170dc6
AH
10402 if (GET_MODE (op1) != compare_mode
10403 /* In the isel case however, we can use a compare immediate, so
10404 op1 may be a small constant. */
10405 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 10406 return 0;
178c3eff 10407 if (GET_MODE (true_cond) != result_mode)
3148ad6d 10408 return 0;
178c3eff 10409 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
10410 return 0;
10411
50a0b056 10412 /* First, work out if the hardware can do this at all, or
a3c9585f 10413 if it's too slow.... */
50a0b056 10414 if (! rs6000_compare_fp_p)
a3170dc6
AH
10415 {
10416 if (TARGET_ISEL)
10417 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
10418 return 0;
10419 }
fef98bf2
AH
10420 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
10421 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
10422 return 0;
50a0b056
GK
10423
10424 /* Eliminate half of the comparisons by switching operands, this
10425 makes the remaining code simpler. */
10426 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 10427 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
10428 {
10429 code = reverse_condition_maybe_unordered (code);
10430 temp = true_cond;
10431 true_cond = false_cond;
10432 false_cond = temp;
10433 }
10434
10435 /* UNEQ and LTGT take four instructions for a comparison with zero,
10436 it'll probably be faster to use a branch here too. */
bc9ec0e0 10437 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
10438 return 0;
10439
10440 if (GET_CODE (op1) == CONST_DOUBLE)
10441 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
10442
b6d08ca1 10443 /* We're going to try to implement comparisons by performing
50a0b056
GK
10444 a subtract, then comparing against zero. Unfortunately,
10445 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 10446 know that the operand is finite and the comparison
50a0b056 10447 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 10448 if (HONOR_INFINITIES (compare_mode)
50a0b056 10449 && code != GT && code != UNGE
045572c7 10450 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
10451 /* Constructs of the form (a OP b ? a : b) are safe. */
10452 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
10453 || (! rtx_equal_p (op0, true_cond)
10454 && ! rtx_equal_p (op1, true_cond))))
10455 return 0;
10456 /* At this point we know we can use fsel. */
10457
10458 /* Reduce the comparison to a comparison against zero. */
3148ad6d 10459 temp = gen_reg_rtx (compare_mode);
50a0b056 10460 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10461 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 10462 op0 = temp;
3148ad6d 10463 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
10464
10465 /* If we don't care about NaNs we can reduce some of the comparisons
10466 down to faster ones. */
bc9ec0e0 10467 if (! HONOR_NANS (compare_mode))
50a0b056
GK
10468 switch (code)
10469 {
10470 case GT:
10471 code = LE;
10472 temp = true_cond;
10473 true_cond = false_cond;
10474 false_cond = temp;
10475 break;
10476 case UNGE:
10477 code = GE;
10478 break;
10479 case UNEQ:
10480 code = EQ;
10481 break;
10482 default:
10483 break;
10484 }
10485
10486 /* Now, reduce everything down to a GE. */
10487 switch (code)
10488 {
10489 case GE:
10490 break;
10491
10492 case LE:
3148ad6d
DJ
10493 temp = gen_reg_rtx (compare_mode);
10494 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10495 op0 = temp;
10496 break;
10497
10498 case ORDERED:
3148ad6d
DJ
10499 temp = gen_reg_rtx (compare_mode);
10500 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
10501 op0 = temp;
10502 break;
10503
10504 case EQ:
3148ad6d 10505 temp = gen_reg_rtx (compare_mode);
50a0b056 10506 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
10507 gen_rtx_NEG (compare_mode,
10508 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
10509 op0 = temp;
10510 break;
10511
10512 case UNGE:
bc9ec0e0 10513 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 10514 temp = gen_reg_rtx (result_mode);
50a0b056 10515 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10516 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10517 gen_rtx_GE (VOIDmode,
10518 op0, op1),
10519 true_cond, false_cond)));
bc9ec0e0
GK
10520 false_cond = true_cond;
10521 true_cond = temp;
50a0b056 10522
3148ad6d
DJ
10523 temp = gen_reg_rtx (compare_mode);
10524 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10525 op0 = temp;
10526 break;
10527
10528 case GT:
bc9ec0e0 10529 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 10530 temp = gen_reg_rtx (result_mode);
50a0b056 10531 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10532 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10533 gen_rtx_GE (VOIDmode,
10534 op0, op1),
10535 true_cond, false_cond)));
bc9ec0e0
GK
10536 true_cond = false_cond;
10537 false_cond = temp;
50a0b056 10538
3148ad6d
DJ
10539 temp = gen_reg_rtx (compare_mode);
10540 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10541 op0 = temp;
10542 break;
10543
10544 default:
10545 abort ();
10546 }
10547
10548 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 10549 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10550 gen_rtx_GE (VOIDmode,
10551 op0, op1),
10552 true_cond, false_cond)));
10553 return 1;
10554}
10555
a3170dc6
AH
10556/* Same as above, but for ints (isel). */
10557
10558static int
a2369ed3 10559rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
10560{
10561 rtx condition_rtx, cr;
10562
10563 /* All isel implementations thus far are 32-bits. */
10564 if (GET_MODE (rs6000_compare_op0) != SImode)
10565 return 0;
10566
10567 /* We still have to do the compare, because isel doesn't do a
10568 compare, it just looks at the CRx bits set by a previous compare
10569 instruction. */
10570 condition_rtx = rs6000_generate_compare (GET_CODE (op));
10571 cr = XEXP (condition_rtx, 0);
10572
10573 if (GET_MODE (cr) == CCmode)
10574 emit_insn (gen_isel_signed (dest, condition_rtx,
10575 true_cond, false_cond, cr));
10576 else
10577 emit_insn (gen_isel_unsigned (dest, condition_rtx,
10578 true_cond, false_cond, cr));
10579
10580 return 1;
10581}
10582
10583const char *
a2369ed3 10584output_isel (rtx *operands)
a3170dc6
AH
10585{
10586 enum rtx_code code;
10587
10588 code = GET_CODE (operands[1]);
10589 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
10590 {
10591 PUT_CODE (operands[1], reverse_condition (code));
10592 return "isel %0,%3,%2,%j1";
10593 }
10594 else
10595 return "isel %0,%2,%3,%j1";
10596}
10597
50a0b056 10598void
a2369ed3 10599rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
10600{
10601 enum machine_mode mode = GET_MODE (op0);
5dc8d536 10602 enum rtx_code c;
50a0b056 10603 rtx target;
5dc8d536
AH
10604
10605 if (code == SMAX || code == SMIN)
10606 c = GE;
10607 else
10608 c = GEU;
10609
50a0b056 10610 if (code == SMAX || code == UMAX)
5dc8d536 10611 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10612 op0, op1, mode, 0);
10613 else
5dc8d536 10614 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10615 op1, op0, mode, 0);
10616 if (target == NULL_RTX)
10617 abort ();
10618 if (target != dest)
10619 emit_move_insn (dest, target);
10620}
46c07df8 10621
a9baceb1
GK
10622/* Emit instructions to move SRC to DST. Called by splitters for
10623 multi-register moves. It will emit at most one instruction for
10624 each register that is accessed; that is, it won't emit li/lis pairs
10625 (or equivalent for 64-bit code). One of SRC or DST must be a hard
10626 register. */
46c07df8 10627
46c07df8 10628void
a9baceb1 10629rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 10630{
a9baceb1
GK
10631 /* The register number of the first register being moved. */
10632 int reg;
10633 /* The mode that is to be moved. */
10634 enum machine_mode mode;
10635 /* The mode that the move is being done in, and its size. */
10636 enum machine_mode reg_mode;
10637 int reg_mode_size;
10638 /* The number of registers that will be moved. */
10639 int nregs;
10640
10641 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
10642 mode = GET_MODE (dst);
10643 nregs = HARD_REGNO_NREGS (reg, mode);
10644 if (FP_REGNO_P (reg))
10645 reg_mode = DFmode;
10646 else if (ALTIVEC_REGNO_P (reg))
10647 reg_mode = V16QImode;
10648 else
10649 reg_mode = word_mode;
10650 reg_mode_size = GET_MODE_SIZE (reg_mode);
46c07df8 10651
a9baceb1
GK
10652 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
10653 abort ();
10654
10655 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
10656 {
10657 /* Move register range backwards, if we might have destructive
10658 overlap. */
10659 int i;
10660 for (i = nregs - 1; i >= 0; i--)
10661 emit_insn (gen_rtx_SET (VOIDmode,
10662 simplify_gen_subreg (reg_mode, dst, mode,
10663 i * reg_mode_size),
10664 simplify_gen_subreg (reg_mode, src, mode,
10665 i * reg_mode_size)));
10666 }
46c07df8
HP
10667 else
10668 {
a9baceb1
GK
10669 int i;
10670 int j = -1;
10671 bool used_update = false;
46c07df8 10672
a9baceb1 10673 if (GET_CODE (src) == MEM && INT_REGNO_P (reg))
46c07df8
HP
10674 {
10675 rtx breg;
3a1f863f 10676
a9baceb1
GK
10677 if (GET_CODE (XEXP (src, 0)) == PRE_INC
10678 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
10679 {
10680 rtx delta_rtx;
a9baceb1
GK
10681 breg = XEXP (XEXP (src, 0), 0);
10682 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
10683 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
10684 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
10685 emit_insn (TARGET_32BIT
10686 ? gen_addsi3 (breg, breg, delta_rtx)
10687 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10688 src = gen_rtx_MEM (mode, breg);
10689 }
10690
10691 /* We have now address involving an base register only.
10692 If we use one of the registers to address memory,
10693 we have change that register last. */
10694
10695 breg = (GET_CODE (XEXP (src, 0)) == PLUS
10696 ? XEXP (XEXP (src, 0), 0)
10697 : XEXP (src, 0));
10698
10699 if (!REG_P (breg))
10700 abort();
10701
10702 if (REGNO (breg) >= REGNO (dst)
10703 && REGNO (breg) < REGNO (dst) + nregs)
10704 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
10705 }
10706
a9baceb1 10707 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
10708 {
10709 rtx breg;
10710
a9baceb1
GK
10711 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
10712 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
10713 {
10714 rtx delta_rtx;
a9baceb1
GK
10715 breg = XEXP (XEXP (dst, 0), 0);
10716 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
10717 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
10718 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
10719
10720 /* We have to update the breg before doing the store.
10721 Use store with update, if available. */
10722
10723 if (TARGET_UPDATE)
10724 {
a9baceb1
GK
10725 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
10726 emit_insn (TARGET_32BIT
10727 ? gen_movsi_update (breg, breg, delta_rtx, nsrc)
10728 : gen_movdi_update (breg, breg, delta_rtx, nsrc));
10729 used_update = true;
3a1f863f
DE
10730 }
10731 else
a9baceb1
GK
10732 emit_insn (TARGET_32BIT
10733 ? gen_addsi3 (breg, breg, delta_rtx)
10734 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10735 dst = gen_rtx_MEM (mode, breg);
10736 }
10737 }
10738
46c07df8 10739 for (i = 0; i < nregs; i++)
3a1f863f
DE
10740 {
10741 /* Calculate index to next subword. */
10742 ++j;
10743 if (j == nregs)
10744 j = 0;
46c07df8 10745
a9baceb1
GK
10746 /* If compiler already emited move of first word by
10747 store with update, no need to do anything. */
3a1f863f 10748 if (j == 0 && used_update)
a9baceb1
GK
10749 continue;
10750
10751 emit_insn (gen_rtx_SET (VOIDmode,
10752 simplify_gen_subreg (reg_mode, dst, mode,
10753 j * reg_mode_size),
10754 simplify_gen_subreg (reg_mode, src, mode,
10755 j * reg_mode_size)));
3a1f863f 10756 }
46c07df8
HP
10757 }
10758}
10759
12a4e8c5 10760\f
a4f6c312
SS
10761/* This page contains routines that are used to determine what the
10762 function prologue and epilogue code will do and write them out. */
9878760c 10763
a4f6c312
SS
10764/* Return the first fixed-point register that is required to be
10765 saved. 32 if none. */
9878760c
RK
10766
10767int
863d938c 10768first_reg_to_save (void)
9878760c
RK
10769{
10770 int first_reg;
10771
10772 /* Find lowest numbered live register. */
10773 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
10774 if (regs_ever_live[first_reg]
10775 && (! call_used_regs[first_reg]
1db02437 10776 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10777 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10778 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
10779 break;
10780
ee890fe2 10781#if TARGET_MACHO
93638d7a
AM
10782 if (flag_pic
10783 && current_function_uses_pic_offset_table
10784 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 10785 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
10786#endif
10787
9878760c
RK
10788 return first_reg;
10789}
10790
10791/* Similar, for FP regs. */
10792
10793int
863d938c 10794first_fp_reg_to_save (void)
9878760c
RK
10795{
10796 int first_reg;
10797
10798 /* Find lowest numbered live register. */
10799 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
10800 if (regs_ever_live[first_reg])
10801 break;
10802
10803 return first_reg;
10804}
00b960c7
AH
10805
10806/* Similar, for AltiVec regs. */
10807
10808static int
863d938c 10809first_altivec_reg_to_save (void)
00b960c7
AH
10810{
10811 int i;
10812
10813 /* Stack frame remains as is unless we are in AltiVec ABI. */
10814 if (! TARGET_ALTIVEC_ABI)
10815 return LAST_ALTIVEC_REGNO + 1;
10816
10817 /* Find lowest numbered live register. */
10818 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
10819 if (regs_ever_live[i])
10820 break;
10821
10822 return i;
10823}
10824
10825/* Return a 32-bit mask of the AltiVec registers we need to set in
10826 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
10827 the 32-bit word is 0. */
10828
10829static unsigned int
863d938c 10830compute_vrsave_mask (void)
00b960c7
AH
10831{
10832 unsigned int i, mask = 0;
10833
10834 /* First, find out if we use _any_ altivec registers. */
10835 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10836 if (regs_ever_live[i])
10837 mask |= ALTIVEC_REG_BIT (i);
10838
10839 if (mask == 0)
10840 return mask;
10841
00b960c7
AH
10842 /* Next, remove the argument registers from the set. These must
10843 be in the VRSAVE mask set by the caller, so we don't need to add
10844 them in again. More importantly, the mask we compute here is
10845 used to generate CLOBBERs in the set_vrsave insn, and we do not
10846 wish the argument registers to die. */
a6cf80f2 10847 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
10848 mask &= ~ALTIVEC_REG_BIT (i);
10849
10850 /* Similarly, remove the return value from the set. */
10851 {
10852 bool yes = false;
10853 diddle_return_value (is_altivec_return_reg, &yes);
10854 if (yes)
10855 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
10856 }
10857
10858 return mask;
10859}
10860
10861static void
a2369ed3 10862is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
10863{
10864 bool *yes = (bool *) xyes;
10865 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
10866 *yes = true;
10867}
10868
4697a36c
MM
10869\f
10870/* Calculate the stack information for the current function. This is
10871 complicated by having two separate calling sequences, the AIX calling
10872 sequence and the V.4 calling sequence.
10873
592696dd 10874 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 10875 32-bit 64-bit
4697a36c 10876 SP----> +---------------------------------------+
a260abc9 10877 | back chain to caller | 0 0
4697a36c 10878 +---------------------------------------+
a260abc9 10879 | saved CR | 4 8 (8-11)
4697a36c 10880 +---------------------------------------+
a260abc9 10881 | saved LR | 8 16
4697a36c 10882 +---------------------------------------+
a260abc9 10883 | reserved for compilers | 12 24
4697a36c 10884 +---------------------------------------+
a260abc9 10885 | reserved for binders | 16 32
4697a36c 10886 +---------------------------------------+
a260abc9 10887 | saved TOC pointer | 20 40
4697a36c 10888 +---------------------------------------+
a260abc9 10889 | Parameter save area (P) | 24 48
4697a36c 10890 +---------------------------------------+
a260abc9 10891 | Alloca space (A) | 24+P etc.
802a0058 10892 +---------------------------------------+
a7df97e6 10893 | Local variable space (L) | 24+P+A
4697a36c 10894 +---------------------------------------+
a7df97e6 10895 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 10896 +---------------------------------------+
00b960c7
AH
10897 | Save area for AltiVec registers (W) | 24+P+A+L+X
10898 +---------------------------------------+
10899 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
10900 +---------------------------------------+
10901 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 10902 +---------------------------------------+
00b960c7
AH
10903 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
10904 +---------------------------------------+
10905 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
10906 +---------------------------------------+
10907 old SP->| back chain to caller's caller |
10908 +---------------------------------------+
10909
5376a30c
KR
10910 The required alignment for AIX configurations is two words (i.e., 8
10911 or 16 bytes).
10912
10913
4697a36c
MM
10914 V.4 stack frames look like:
10915
10916 SP----> +---------------------------------------+
10917 | back chain to caller | 0
10918 +---------------------------------------+
5eb387b8 10919 | caller's saved LR | 4
4697a36c
MM
10920 +---------------------------------------+
10921 | Parameter save area (P) | 8
10922 +---------------------------------------+
a7df97e6
MM
10923 | Alloca space (A) | 8+P
10924 +---------------------------------------+
10925 | Varargs save area (V) | 8+P+A
10926 +---------------------------------------+
10927 | Local variable space (L) | 8+P+A+V
10928 +---------------------------------------+
10929 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10930 +---------------------------------------+
00b960c7
AH
10931 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10932 +---------------------------------------+
10933 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10934 +---------------------------------------+
10935 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10936 +---------------------------------------+
a3170dc6
AH
10937 | SPE: area for 64-bit GP registers |
10938 +---------------------------------------+
10939 | SPE alignment padding |
10940 +---------------------------------------+
00b960c7 10941 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10942 +---------------------------------------+
00b960c7 10943 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10944 +---------------------------------------+
00b960c7 10945 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10946 +---------------------------------------+
10947 old SP->| back chain to caller's caller |
10948 +---------------------------------------+
b6c9286a 10949
5376a30c
KR
10950 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10951 given. (But note below and in sysv4.h that we require only 8 and
10952 may round up the size of our stack frame anyways. The historical
10953 reason is early versions of powerpc-linux which didn't properly
10954 align the stack at program startup. A happy side-effect is that
10955 -mno-eabi libraries can be used with -meabi programs.)
10956
50d440bc 10957 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10958 the stack alignment requirements may differ. If -mno-eabi is not
10959 given, the required stack alignment is 8 bytes; if -mno-eabi is
10960 given, the required alignment is 16 bytes. (But see V.4 comment
10961 above.) */
4697a36c 10962
61b2fbe7
MM
10963#ifndef ABI_STACK_BOUNDARY
10964#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10965#endif
10966
d1d0c603 10967static rs6000_stack_t *
863d938c 10968rs6000_stack_info (void)
4697a36c
MM
10969{
10970 static rs6000_stack_t info, zero_info;
10971 rs6000_stack_t *info_ptr = &info;
327e5343 10972 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 10973 int ehrd_size;
44688022 10974 HOST_WIDE_INT non_fixed_size;
4697a36c 10975
a4f6c312 10976 /* Zero all fields portably. */
4697a36c
MM
10977 info = zero_info;
10978
c19de7aa
AH
10979 if (TARGET_SPE)
10980 {
10981 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10982 if (cfun->machine->insn_chain_scanned_p == 0)
10983 {
10984 cfun->machine->insn_chain_scanned_p = 1;
10985 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10986 }
c19de7aa
AH
10987 }
10988
a4f6c312 10989 /* Select which calling sequence. */
178274da 10990 info_ptr->abi = DEFAULT_ABI;
9878760c 10991
a4f6c312 10992 /* Calculate which registers need to be saved & save area size. */
4697a36c 10993 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10994 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10995 even if it currently looks like we won't. */
2bfcf297 10996 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10997 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10998 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10999 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
11000 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
11001 else
11002 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 11003
a3170dc6
AH
11004 /* For the SPE, we have an additional upper 32-bits on each GPR.
11005 Ideally we should save the entire 64-bits only when the upper
11006 half is used in SIMD instructions. Since we only record
11007 registers live (not the size they are used in), this proves
11008 difficult because we'd have to traverse the instruction chain at
11009 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
11010 so we opt to save the GPRs in 64-bits always if but one register
11011 gets used in 64-bits. Otherwise, all the registers in the frame
11012 get saved in 32-bits.
a3170dc6 11013
c19de7aa 11014 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 11015 traditional GP save area will be empty. */
c19de7aa 11016 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11017 info_ptr->gp_size = 0;
11018
4697a36c
MM
11019 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
11020 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
11021
00b960c7
AH
11022 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
11023 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
11024 - info_ptr->first_altivec_reg_save);
11025
592696dd 11026 /* Does this function call anything? */
71f123ca
FS
11027 info_ptr->calls_p = (! current_function_is_leaf
11028 || cfun->machine->ra_needs_full_frame);
b6c9286a 11029
a4f6c312 11030 /* Determine if we need to save the link register. */
71f123ca 11031 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
11032 || (DEFAULT_ABI == ABI_AIX
11033 && current_function_profile
11034 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
11035#ifdef TARGET_RELOCATABLE
11036 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
11037#endif
11038 || (info_ptr->first_fp_reg_save != 64
11039 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 11040 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 11041 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
11042 || (DEFAULT_ABI == ABI_DARWIN
11043 && flag_pic
11044 && current_function_uses_pic_offset_table)
4697a36c
MM
11045 || info_ptr->calls_p)
11046 {
11047 info_ptr->lr_save_p = 1;
9ebbca7d 11048 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
11049 }
11050
9ebbca7d
GK
11051 /* Determine if we need to save the condition code registers. */
11052 if (regs_ever_live[CR2_REGNO]
11053 || regs_ever_live[CR3_REGNO]
11054 || regs_ever_live[CR4_REGNO])
4697a36c
MM
11055 {
11056 info_ptr->cr_save_p = 1;
178274da 11057 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
11058 info_ptr->cr_size = reg_size;
11059 }
11060
83720594
RH
11061 /* If the current function calls __builtin_eh_return, then we need
11062 to allocate stack space for registers that will hold data for
11063 the exception handler. */
11064 if (current_function_calls_eh_return)
11065 {
11066 unsigned int i;
11067 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
11068 continue;
a3170dc6
AH
11069
11070 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
11071 ehrd_size = i * (TARGET_SPE_ABI
11072 && info_ptr->spe_64bit_regs_used != 0
11073 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
11074 }
11075 else
11076 ehrd_size = 0;
11077
592696dd 11078 /* Determine various sizes. */
4697a36c
MM
11079 info_ptr->reg_size = reg_size;
11080 info_ptr->fixed_size = RS6000_SAVE_AREA;
11081 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 11082 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 11083 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 11084 TARGET_ALTIVEC ? 16 : 8);
00b960c7 11085
c19de7aa 11086 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11087 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
11088 else
11089 info_ptr->spe_gp_size = 0;
11090
4d774ff8
HP
11091 if (TARGET_ALTIVEC_ABI)
11092 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 11093 else
4d774ff8
HP
11094 info_ptr->vrsave_mask = 0;
11095
11096 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
11097 info_ptr->vrsave_size = 4;
11098 else
11099 info_ptr->vrsave_size = 0;
b6c9286a 11100
592696dd 11101 /* Calculate the offsets. */
178274da 11102 switch (DEFAULT_ABI)
4697a36c 11103 {
b6c9286a 11104 case ABI_NONE:
24d304eb 11105 default:
b6c9286a
MM
11106 abort ();
11107
11108 case ABI_AIX:
ee890fe2 11109 case ABI_DARWIN:
b6c9286a
MM
11110 info_ptr->fp_save_offset = - info_ptr->fp_size;
11111 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
11112
11113 if (TARGET_ALTIVEC_ABI)
11114 {
11115 info_ptr->vrsave_save_offset
11116 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
11117
11118 /* Align stack so vector save area is on a quadword boundary. */
11119 if (info_ptr->altivec_size != 0)
11120 info_ptr->altivec_padding_size
11121 = 16 - (-info_ptr->vrsave_save_offset % 16);
11122 else
11123 info_ptr->altivec_padding_size = 0;
11124
11125 info_ptr->altivec_save_offset
11126 = info_ptr->vrsave_save_offset
11127 - info_ptr->altivec_padding_size
11128 - info_ptr->altivec_size;
11129
11130 /* Adjust for AltiVec case. */
11131 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
11132 }
11133 else
11134 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
11135 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
11136 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
11137 break;
11138
11139 case ABI_V4:
b6c9286a
MM
11140 info_ptr->fp_save_offset = - info_ptr->fp_size;
11141 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 11142 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 11143
c19de7aa 11144 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11145 {
11146 /* Align stack so SPE GPR save area is aligned on a
11147 double-word boundary. */
11148 if (info_ptr->spe_gp_size != 0)
11149 info_ptr->spe_padding_size
11150 = 8 - (-info_ptr->cr_save_offset % 8);
11151 else
11152 info_ptr->spe_padding_size = 0;
11153
11154 info_ptr->spe_gp_save_offset
11155 = info_ptr->cr_save_offset
11156 - info_ptr->spe_padding_size
11157 - info_ptr->spe_gp_size;
11158
11159 /* Adjust for SPE case. */
11160 info_ptr->toc_save_offset
11161 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
11162 }
11163 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
11164 {
11165 info_ptr->vrsave_save_offset
11166 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
11167
11168 /* Align stack so vector save area is on a quadword boundary. */
11169 if (info_ptr->altivec_size != 0)
11170 info_ptr->altivec_padding_size
11171 = 16 - (-info_ptr->vrsave_save_offset % 16);
11172 else
11173 info_ptr->altivec_padding_size = 0;
11174
11175 info_ptr->altivec_save_offset
11176 = info_ptr->vrsave_save_offset
11177 - info_ptr->altivec_padding_size
11178 - info_ptr->altivec_size;
11179
11180 /* Adjust for AltiVec case. */
11181 info_ptr->toc_save_offset
11182 = info_ptr->altivec_save_offset - info_ptr->toc_size;
11183 }
11184 else
11185 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 11186 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
11187 info_ptr->lr_save_offset = reg_size;
11188 break;
4697a36c
MM
11189 }
11190
00b960c7
AH
11191 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
11192 + info_ptr->gp_size
11193 + info_ptr->altivec_size
11194 + info_ptr->altivec_padding_size
a3170dc6
AH
11195 + info_ptr->spe_gp_size
11196 + info_ptr->spe_padding_size
00b960c7
AH
11197 + ehrd_size
11198 + info_ptr->cr_size
11199 + info_ptr->lr_size
11200 + info_ptr->vrsave_size
11201 + info_ptr->toc_size,
11202 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
11203 ? 16 : 8);
11204
44688022 11205 non_fixed_size = (info_ptr->vars_size
ff381587 11206 + info_ptr->parm_size
ff381587 11207 + info_ptr->save_size
44688022 11208 + info_ptr->varargs_size);
ff381587 11209
44688022
AM
11210 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
11211 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
11212
11213 /* Determine if we need to allocate any stack frame:
11214
a4f6c312
SS
11215 For AIX we need to push the stack if a frame pointer is needed
11216 (because the stack might be dynamically adjusted), if we are
11217 debugging, if we make calls, or if the sum of fp_save, gp_save,
11218 and local variables are more than the space needed to save all
11219 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
11220 + 18*8 = 288 (GPR13 reserved).
ff381587 11221
a4f6c312
SS
11222 For V.4 we don't have the stack cushion that AIX uses, but assume
11223 that the debugger can handle stackless frames. */
ff381587
MM
11224
11225 if (info_ptr->calls_p)
11226 info_ptr->push_p = 1;
11227
178274da 11228 else if (DEFAULT_ABI == ABI_V4)
44688022 11229 info_ptr->push_p = non_fixed_size != 0;
ff381587 11230
178274da
AM
11231 else if (frame_pointer_needed)
11232 info_ptr->push_p = 1;
11233
11234 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
11235 info_ptr->push_p = 1;
11236
ff381587 11237 else
44688022 11238 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 11239
a4f6c312 11240 /* Zero offsets if we're not saving those registers. */
8dda1a21 11241 if (info_ptr->fp_size == 0)
4697a36c
MM
11242 info_ptr->fp_save_offset = 0;
11243
8dda1a21 11244 if (info_ptr->gp_size == 0)
4697a36c
MM
11245 info_ptr->gp_save_offset = 0;
11246
00b960c7
AH
11247 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
11248 info_ptr->altivec_save_offset = 0;
11249
11250 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
11251 info_ptr->vrsave_save_offset = 0;
11252
c19de7aa
AH
11253 if (! TARGET_SPE_ABI
11254 || info_ptr->spe_64bit_regs_used == 0
11255 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
11256 info_ptr->spe_gp_save_offset = 0;
11257
c81fc13e 11258 if (! info_ptr->lr_save_p)
4697a36c
MM
11259 info_ptr->lr_save_offset = 0;
11260
c81fc13e 11261 if (! info_ptr->cr_save_p)
4697a36c
MM
11262 info_ptr->cr_save_offset = 0;
11263
c81fc13e 11264 if (! info_ptr->toc_save_p)
b6c9286a
MM
11265 info_ptr->toc_save_offset = 0;
11266
4697a36c
MM
11267 return info_ptr;
11268}
11269
c19de7aa
AH
11270/* Return true if the current function uses any GPRs in 64-bit SIMD
11271 mode. */
11272
11273static bool
863d938c 11274spe_func_has_64bit_regs_p (void)
c19de7aa
AH
11275{
11276 rtx insns, insn;
11277
11278 /* Functions that save and restore all the call-saved registers will
11279 need to save/restore the registers in 64-bits. */
11280 if (current_function_calls_eh_return
11281 || current_function_calls_setjmp
11282 || current_function_has_nonlocal_goto)
11283 return true;
11284
11285 insns = get_insns ();
11286
11287 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
11288 {
11289 if (INSN_P (insn))
11290 {
11291 rtx i;
11292
11293 i = PATTERN (insn);
11294 if (GET_CODE (i) == SET
11295 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
11296 return true;
11297 }
11298 }
11299
11300 return false;
11301}
11302
d1d0c603 11303static void
a2369ed3 11304debug_stack_info (rs6000_stack_t *info)
9878760c 11305{
d330fd93 11306 const char *abi_string;
24d304eb 11307
c81fc13e 11308 if (! info)
4697a36c
MM
11309 info = rs6000_stack_info ();
11310
11311 fprintf (stderr, "\nStack information for function %s:\n",
11312 ((current_function_decl && DECL_NAME (current_function_decl))
11313 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
11314 : "<unknown>"));
11315
24d304eb
RK
11316 switch (info->abi)
11317 {
b6c9286a
MM
11318 default: abi_string = "Unknown"; break;
11319 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 11320 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 11321 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 11322 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
11323 }
11324
11325 fprintf (stderr, "\tABI = %5s\n", abi_string);
11326
00b960c7
AH
11327 if (TARGET_ALTIVEC_ABI)
11328 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
11329
a3170dc6
AH
11330 if (TARGET_SPE_ABI)
11331 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
11332
4697a36c
MM
11333 if (info->first_gp_reg_save != 32)
11334 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
11335
11336 if (info->first_fp_reg_save != 64)
11337 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 11338
00b960c7
AH
11339 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
11340 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
11341 info->first_altivec_reg_save);
11342
4697a36c
MM
11343 if (info->lr_save_p)
11344 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 11345
4697a36c
MM
11346 if (info->cr_save_p)
11347 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
11348
b6c9286a
MM
11349 if (info->toc_save_p)
11350 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
11351
00b960c7
AH
11352 if (info->vrsave_mask)
11353 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
11354
4697a36c
MM
11355 if (info->push_p)
11356 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
11357
11358 if (info->calls_p)
11359 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
11360
4697a36c
MM
11361 if (info->gp_save_offset)
11362 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
11363
11364 if (info->fp_save_offset)
11365 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
11366
00b960c7
AH
11367 if (info->altivec_save_offset)
11368 fprintf (stderr, "\taltivec_save_offset = %5d\n",
11369 info->altivec_save_offset);
11370
a3170dc6
AH
11371 if (info->spe_gp_save_offset)
11372 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
11373 info->spe_gp_save_offset);
11374
00b960c7
AH
11375 if (info->vrsave_save_offset)
11376 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
11377 info->vrsave_save_offset);
11378
4697a36c
MM
11379 if (info->lr_save_offset)
11380 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
11381
11382 if (info->cr_save_offset)
11383 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
11384
b6c9286a
MM
11385 if (info->toc_save_offset)
11386 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
11387
4697a36c
MM
11388 if (info->varargs_save_offset)
11389 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
11390
11391 if (info->total_size)
d1d0c603
JJ
11392 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11393 info->total_size);
4697a36c
MM
11394
11395 if (info->varargs_size)
11396 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
11397
11398 if (info->vars_size)
d1d0c603
JJ
11399 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11400 info->vars_size);
4697a36c
MM
11401
11402 if (info->parm_size)
11403 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
11404
11405 if (info->fixed_size)
11406 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
11407
11408 if (info->gp_size)
11409 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
11410
a3170dc6
AH
11411 if (info->spe_gp_size)
11412 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
11413
4697a36c
MM
11414 if (info->fp_size)
11415 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
11416
00b960c7
AH
11417 if (info->altivec_size)
11418 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
11419
11420 if (info->vrsave_size)
11421 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
11422
11423 if (info->altivec_padding_size)
11424 fprintf (stderr, "\taltivec_padding_size= %5d\n",
11425 info->altivec_padding_size);
11426
a3170dc6
AH
11427 if (info->spe_padding_size)
11428 fprintf (stderr, "\tspe_padding_size = %5d\n",
11429 info->spe_padding_size);
11430
a4f6c312 11431 if (info->lr_size)
ed947a96 11432 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 11433
4697a36c
MM
11434 if (info->cr_size)
11435 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
11436
a4f6c312 11437 if (info->toc_size)
b6c9286a
MM
11438 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
11439
4697a36c
MM
11440 if (info->save_size)
11441 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
11442
11443 if (info->reg_size != 4)
11444 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
11445
11446 fprintf (stderr, "\n");
9878760c 11447}
71f123ca
FS
11448
11449rtx
a2369ed3 11450rs6000_return_addr (int count, rtx frame)
71f123ca 11451{
a4f6c312
SS
11452 /* Currently we don't optimize very well between prolog and body
11453 code and for PIC code the code can be actually quite bad, so
11454 don't try to be too clever here. */
f1384257 11455 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
11456 {
11457 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
11458
11459 return
11460 gen_rtx_MEM
11461 (Pmode,
11462 memory_address
11463 (Pmode,
11464 plus_constant (copy_to_reg
11465 (gen_rtx_MEM (Pmode,
11466 memory_address (Pmode, frame))),
11467 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
11468 }
11469
8c29550d 11470 cfun->machine->ra_need_lr = 1;
9e2f7ec7 11471 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
11472}
11473
5e1bf043
DJ
11474/* Say whether a function is a candidate for sibcall handling or not.
11475 We do not allow indirect calls to be optimized into sibling calls.
11476 Also, we can't do it if there are any vector parameters; there's
11477 nowhere to put the VRsave code so it works; note that functions with
11478 vector parameters are required to have a prototype, so the argument
11479 type info must be available here. (The tail recursion case can work
11480 with vector parameters, but there's no way to distinguish here.) */
4977bab6 11481static bool
a2369ed3 11482rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
11483{
11484 tree type;
4977bab6 11485 if (decl)
5e1bf043
DJ
11486 {
11487 if (TARGET_ALTIVEC_VRSAVE)
11488 {
4977bab6 11489 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
11490 type; type = TREE_CHAIN (type))
11491 {
c15b529f 11492 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 11493 return false;
5e1bf043
DJ
11494 }
11495 }
11496 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 11497 || (*targetm.binds_local_p) (decl))
2bcc50d0 11498 {
4977bab6 11499 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
11500
11501 if (!lookup_attribute ("longcall", attr_list)
11502 || lookup_attribute ("shortcall", attr_list))
4977bab6 11503 return true;
2bcc50d0 11504 }
5e1bf043 11505 }
4977bab6 11506 return false;
5e1bf043
DJ
11507}
11508
71f123ca 11509static int
863d938c 11510rs6000_ra_ever_killed (void)
71f123ca
FS
11511{
11512 rtx top;
5e1bf043
DJ
11513 rtx reg;
11514 rtx insn;
71f123ca 11515
dd292d0a 11516 if (current_function_is_thunk)
71f123ca 11517 return 0;
eb0424da 11518
36f7e964
AH
11519 /* regs_ever_live has LR marked as used if any sibcalls are present,
11520 but this should not force saving and restoring in the
11521 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 11522 clobbers LR, so that is inappropriate. */
36f7e964 11523
5e1bf043
DJ
11524 /* Also, the prologue can generate a store into LR that
11525 doesn't really count, like this:
36f7e964 11526
5e1bf043
DJ
11527 move LR->R0
11528 bcl to set PIC register
11529 move LR->R31
11530 move R0->LR
36f7e964
AH
11531
11532 When we're called from the epilogue, we need to avoid counting
11533 this as a store. */
5e1bf043 11534
71f123ca
FS
11535 push_topmost_sequence ();
11536 top = get_insns ();
11537 pop_topmost_sequence ();
5e1bf043 11538 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 11539
5e1bf043
DJ
11540 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
11541 {
11542 if (INSN_P (insn))
11543 {
11544 if (FIND_REG_INC_NOTE (insn, reg))
11545 return 1;
11546 else if (GET_CODE (insn) == CALL_INSN
c15b529f 11547 && !SIBLING_CALL_P (insn))
5e1bf043 11548 return 1;
36f7e964
AH
11549 else if (set_of (reg, insn) != NULL_RTX
11550 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
11551 return 1;
11552 }
11553 }
11554 return 0;
71f123ca 11555}
4697a36c 11556\f
8cd8f856
GK
11557/* Add a REG_MAYBE_DEAD note to the insn. */
11558static void
a2369ed3 11559rs6000_maybe_dead (rtx insn)
8cd8f856
GK
11560{
11561 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
11562 const0_rtx,
11563 REG_NOTES (insn));
11564}
11565
9ebbca7d 11566/* Emit instructions needed to load the TOC register.
c7ca610e 11567 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 11568 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
11569
11570void
a2369ed3 11571rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 11572{
027fbf43 11573 rtx dest, insn;
1db02437 11574 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 11575
20b71b17
AM
11576 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11577 {
11578 rtx temp = (fromprolog
11579 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11580 : gen_reg_rtx (Pmode));
027fbf43
JJ
11581 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
11582 if (fromprolog)
11583 rs6000_maybe_dead (insn);
11584 insn = emit_move_insn (dest, temp);
11585 if (fromprolog)
11586 rs6000_maybe_dead (insn);
20b71b17
AM
11587 }
11588 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
11589 {
11590 char buf[30];
11591 rtx tempLR = (fromprolog
11592 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11593 : gen_reg_rtx (Pmode));
11594 rtx temp0 = (fromprolog
11595 ? gen_rtx_REG (Pmode, 0)
11596 : gen_reg_rtx (Pmode));
11597 rtx symF;
11598
11599 /* possibly create the toc section */
11600 if (! toc_initialized)
38c1f2d7 11601 {
20b71b17
AM
11602 toc_section ();
11603 function_section (current_function_decl);
38c1f2d7 11604 }
9ebbca7d 11605
20b71b17
AM
11606 if (fromprolog)
11607 {
11608 rtx symL;
38c1f2d7 11609
20b71b17
AM
11610 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
11611 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 11612
20b71b17
AM
11613 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
11614 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11615
11616 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
11617 symF)));
11618 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
11619 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
11620 symL,
11621 symF)));
9ebbca7d
GK
11622 }
11623 else
20b71b17
AM
11624 {
11625 rtx tocsym;
11626 static int reload_toc_labelno = 0;
11627
11628 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
11629
11630 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
11631 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11632
027fbf43
JJ
11633 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
11634 emit_move_insn (dest, tempLR);
11635 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 11636 }
027fbf43
JJ
11637 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
11638 if (fromprolog)
11639 rs6000_maybe_dead (insn);
9ebbca7d 11640 }
20b71b17
AM
11641 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
11642 {
11643 /* This is for AIX code running in non-PIC ELF32. */
11644 char buf[30];
11645 rtx realsym;
11646 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11647 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11648
027fbf43
JJ
11649 insn = emit_insn (gen_elf_high (dest, realsym));
11650 if (fromprolog)
11651 rs6000_maybe_dead (insn);
11652 insn = emit_insn (gen_elf_low (dest, dest, realsym));
11653 if (fromprolog)
11654 rs6000_maybe_dead (insn);
20b71b17
AM
11655 }
11656 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
11657 {
11658 if (TARGET_32BIT)
027fbf43 11659 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 11660 else
027fbf43
JJ
11661 insn = emit_insn (gen_load_toc_aix_di (dest));
11662 if (fromprolog)
11663 rs6000_maybe_dead (insn);
9ebbca7d 11664 }
20b71b17
AM
11665 else
11666 abort ();
9ebbca7d
GK
11667}
11668
d1d0c603
JJ
11669/* Emit instructions to restore the link register after determining where
11670 its value has been stored. */
11671
11672void
11673rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
11674{
11675 rs6000_stack_t *info = rs6000_stack_info ();
11676 rtx operands[2];
11677
11678 operands[0] = source;
11679 operands[1] = scratch;
11680
11681 if (info->lr_save_p)
11682 {
11683 rtx frame_rtx = stack_pointer_rtx;
11684 HOST_WIDE_INT sp_offset = 0;
11685 rtx tmp;
11686
11687 if (frame_pointer_needed
11688 || current_function_calls_alloca
11689 || info->total_size > 32767)
11690 {
11691 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
11692 frame_rtx = operands[1];
11693 }
11694 else if (info->push_p)
11695 sp_offset = info->total_size;
11696
11697 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
11698 tmp = gen_rtx_MEM (Pmode, tmp);
11699 emit_move_insn (tmp, operands[0]);
11700 }
11701 else
11702 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
11703}
11704
f103e34d
GK
11705static GTY(()) int set = -1;
11706
9ebbca7d 11707int
863d938c 11708get_TOC_alias_set (void)
9ebbca7d 11709{
f103e34d
GK
11710 if (set == -1)
11711 set = new_alias_set ();
11712 return set;
9ebbca7d
GK
11713}
11714
c1207243 11715/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
11716 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
11717 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 11718#if TARGET_ELF
3c9eb5f4 11719static int
38f391a5 11720uses_TOC (void)
9ebbca7d 11721{
c4501e62 11722 rtx insn;
38c1f2d7 11723
c4501e62
JJ
11724 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11725 if (INSN_P (insn))
11726 {
11727 rtx pat = PATTERN (insn);
11728 int i;
9ebbca7d 11729
c4501e62
JJ
11730 if (GET_CODE (pat) == PARALLEL)
11731 for (i = 0; i < XVECLEN (pat, 0); i++)
11732 {
11733 rtx sub = XVECEXP (pat, 0, i);
11734 if (GET_CODE (sub) == USE)
11735 {
11736 sub = XEXP (sub, 0);
11737 if (GET_CODE (sub) == UNSPEC
11738 && XINT (sub, 1) == UNSPEC_TOC)
11739 return 1;
11740 }
11741 }
11742 }
11743 return 0;
9ebbca7d 11744}
c954844a 11745#endif
38c1f2d7 11746
9ebbca7d 11747rtx
a2369ed3 11748create_TOC_reference (rtx symbol)
9ebbca7d 11749{
a8a05998
ZW
11750 return gen_rtx_PLUS (Pmode,
11751 gen_rtx_REG (Pmode, TOC_REGISTER),
11752 gen_rtx_CONST (Pmode,
11753 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 11754 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 11755}
38c1f2d7 11756
fc4767bb
JJ
11757/* If _Unwind_* has been called from within the same module,
11758 toc register is not guaranteed to be saved to 40(1) on function
11759 entry. Save it there in that case. */
c7ca610e 11760
9ebbca7d 11761void
863d938c 11762rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
11763{
11764 rtx mem;
11765 rtx stack_top = gen_reg_rtx (Pmode);
11766 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
11767 rtx opcode = gen_reg_rtx (SImode);
11768 rtx tocompare = gen_reg_rtx (SImode);
11769 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
11770
11771 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
11772 emit_move_insn (stack_top, mem);
11773
fc4767bb
JJ
11774 mem = gen_rtx_MEM (Pmode,
11775 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
11776 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
11777 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
11778 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
11779 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 11780 : 0xE8410028, SImode));
9ebbca7d 11781
fc4767bb 11782 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 11783 SImode, NULL_RTX, NULL_RTX,
fc4767bb 11784 no_toc_save_needed);
9ebbca7d 11785
fc4767bb
JJ
11786 mem = gen_rtx_MEM (Pmode,
11787 gen_rtx_PLUS (Pmode, stack_top,
11788 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
11789 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
11790 emit_label (no_toc_save_needed);
9ebbca7d 11791}
38c1f2d7 11792\f
ba4828e0
RK
11793/* This ties together stack memory (MEM with an alias set of
11794 rs6000_sr_alias_set) and the change to the stack pointer. */
11795
9ebbca7d 11796static void
863d938c 11797rs6000_emit_stack_tie (void)
9ebbca7d 11798{
ba4828e0
RK
11799 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
11800
11801 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11802 emit_insn (gen_stack_tie (mem));
11803}
38c1f2d7 11804
9ebbca7d
GK
11805/* Emit the correct code for allocating stack space, as insns.
11806 If COPY_R12, make sure a copy of the old frame is left in r12.
11807 The generated code may use hard register 0 as a temporary. */
11808
11809static void
a2369ed3 11810rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 11811{
9ebbca7d
GK
11812 rtx insn;
11813 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11814 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
11815 rtx todec = GEN_INT (-size);
a157febd
GK
11816
11817 if (current_function_limit_stack)
11818 {
11819 if (REG_P (stack_limit_rtx)
11820 && REGNO (stack_limit_rtx) > 1
11821 && REGNO (stack_limit_rtx) <= 31)
11822 {
5b71a4e7 11823 emit_insn (TARGET_32BIT
9ebbca7d
GK
11824 ? gen_addsi3 (tmp_reg,
11825 stack_limit_rtx,
11826 GEN_INT (size))
11827 : gen_adddi3 (tmp_reg,
11828 stack_limit_rtx,
11829 GEN_INT (size)));
5b71a4e7 11830
9ebbca7d
GK
11831 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11832 const0_rtx));
a157febd
GK
11833 }
11834 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 11835 && TARGET_32BIT
f607bc57 11836 && DEFAULT_ABI == ABI_V4)
a157febd 11837 {
9ebbca7d
GK
11838 rtx toload = gen_rtx_CONST (VOIDmode,
11839 gen_rtx_PLUS (Pmode,
11840 stack_limit_rtx,
11841 GEN_INT (size)));
5b71a4e7 11842
9ebbca7d
GK
11843 emit_insn (gen_elf_high (tmp_reg, toload));
11844 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
11845 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11846 const0_rtx));
a157febd
GK
11847 }
11848 else
11849 warning ("stack limit expression is not supported");
11850 }
11851
9ebbca7d
GK
11852 if (copy_r12 || ! TARGET_UPDATE)
11853 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
11854
38c1f2d7
MM
11855 if (TARGET_UPDATE)
11856 {
9ebbca7d 11857 if (size > 32767)
38c1f2d7 11858 {
9ebbca7d
GK
11859 /* Need a note here so that try_split doesn't get confused. */
11860 if (get_last_insn() == NULL_RTX)
2e040219 11861 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
11862 insn = emit_move_insn (tmp_reg, todec);
11863 try_split (PATTERN (insn), insn, 0);
11864 todec = tmp_reg;
38c1f2d7 11865 }
5b71a4e7
DE
11866
11867 insn = emit_insn (TARGET_32BIT
11868 ? gen_movsi_update (stack_reg, stack_reg,
11869 todec, stack_reg)
11870 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 11871 todec, stack_reg));
38c1f2d7
MM
11872 }
11873 else
11874 {
5b71a4e7
DE
11875 insn = emit_insn (TARGET_32BIT
11876 ? gen_addsi3 (stack_reg, stack_reg, todec)
11877 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
11878 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
11879 gen_rtx_REG (Pmode, 12));
11880 }
5b71a4e7 11881
9ebbca7d
GK
11882 RTX_FRAME_RELATED_P (insn) = 1;
11883 REG_NOTES (insn) =
11884 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11885 gen_rtx_SET (VOIDmode, stack_reg,
11886 gen_rtx_PLUS (Pmode, stack_reg,
11887 GEN_INT (-size))),
11888 REG_NOTES (insn));
11889}
11890
a4f6c312
SS
11891/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
11892 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
11893 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
11894 deduce these equivalences by itself so it wasn't necessary to hold
11895 its hand so much. */
9ebbca7d
GK
11896
11897static void
a2369ed3
DJ
11898rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
11899 rtx reg2, rtx rreg)
9ebbca7d
GK
11900{
11901 rtx real, temp;
11902
e56c4463
JL
11903 /* copy_rtx will not make unique copies of registers, so we need to
11904 ensure we don't have unwanted sharing here. */
11905 if (reg == reg2)
11906 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11907
11908 if (reg == rreg)
11909 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11910
9ebbca7d
GK
11911 real = copy_rtx (PATTERN (insn));
11912
89e7058f
AH
11913 if (reg2 != NULL_RTX)
11914 real = replace_rtx (real, reg2, rreg);
11915
9ebbca7d
GK
11916 real = replace_rtx (real, reg,
11917 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
11918 STACK_POINTER_REGNUM),
11919 GEN_INT (val)));
11920
11921 /* We expect that 'real' is either a SET or a PARALLEL containing
11922 SETs (and possibly other stuff). In a PARALLEL, all the SETs
11923 are important so they all have to be marked RTX_FRAME_RELATED_P. */
11924
11925 if (GET_CODE (real) == SET)
11926 {
11927 rtx set = real;
11928
11929 temp = simplify_rtx (SET_SRC (set));
11930 if (temp)
11931 SET_SRC (set) = temp;
11932 temp = simplify_rtx (SET_DEST (set));
11933 if (temp)
11934 SET_DEST (set) = temp;
11935 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 11936 {
9ebbca7d
GK
11937 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11938 if (temp)
11939 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 11940 }
38c1f2d7 11941 }
9ebbca7d
GK
11942 else if (GET_CODE (real) == PARALLEL)
11943 {
11944 int i;
11945 for (i = 0; i < XVECLEN (real, 0); i++)
11946 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11947 {
11948 rtx set = XVECEXP (real, 0, i);
11949
11950 temp = simplify_rtx (SET_SRC (set));
11951 if (temp)
11952 SET_SRC (set) = temp;
11953 temp = simplify_rtx (SET_DEST (set));
11954 if (temp)
11955 SET_DEST (set) = temp;
11956 if (GET_CODE (SET_DEST (set)) == MEM)
11957 {
11958 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11959 if (temp)
11960 XEXP (SET_DEST (set), 0) = temp;
11961 }
11962 RTX_FRAME_RELATED_P (set) = 1;
11963 }
11964 }
11965 else
a4f6c312 11966 abort ();
c19de7aa
AH
11967
11968 if (TARGET_SPE)
11969 real = spe_synthesize_frame_save (real);
11970
9ebbca7d
GK
11971 RTX_FRAME_RELATED_P (insn) = 1;
11972 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11973 real,
11974 REG_NOTES (insn));
38c1f2d7
MM
11975}
11976
c19de7aa
AH
11977/* Given an SPE frame note, return a PARALLEL of SETs with the
11978 original note, plus a synthetic register save. */
11979
11980static rtx
a2369ed3 11981spe_synthesize_frame_save (rtx real)
c19de7aa
AH
11982{
11983 rtx synth, offset, reg, real2;
11984
11985 if (GET_CODE (real) != SET
11986 || GET_MODE (SET_SRC (real)) != V2SImode)
11987 return real;
11988
11989 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11990 frame related note. The parallel contains a set of the register
41f3a930 11991 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11992 This is so we can differentiate between 64-bit and 32-bit saves.
11993 Words cannot describe this nastiness. */
11994
11995 if (GET_CODE (SET_DEST (real)) != MEM
11996 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11997 || GET_CODE (SET_SRC (real)) != REG)
11998 abort ();
11999
12000 /* Transform:
12001 (set (mem (plus (reg x) (const y)))
12002 (reg z))
12003 into:
12004 (set (mem (plus (reg x) (const y+4)))
41f3a930 12005 (reg z+1200))
c19de7aa
AH
12006 */
12007
12008 real2 = copy_rtx (real);
12009 PUT_MODE (SET_DEST (real2), SImode);
12010 reg = SET_SRC (real2);
12011 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
12012 synth = copy_rtx (real2);
12013
12014 if (BYTES_BIG_ENDIAN)
12015 {
12016 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
12017 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
12018 }
12019
12020 reg = SET_SRC (synth);
41f3a930 12021
c19de7aa 12022 synth = replace_rtx (synth, reg,
41f3a930 12023 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
12024
12025 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
12026 synth = replace_rtx (synth, offset,
12027 GEN_INT (INTVAL (offset)
12028 + (BYTES_BIG_ENDIAN ? 0 : 4)));
12029
12030 RTX_FRAME_RELATED_P (synth) = 1;
12031 RTX_FRAME_RELATED_P (real2) = 1;
12032 if (BYTES_BIG_ENDIAN)
12033 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
12034 else
12035 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
12036
12037 return real;
12038}
12039
00b960c7
AH
12040/* Returns an insn that has a vrsave set operation with the
12041 appropriate CLOBBERs. */
12042
12043static rtx
a2369ed3 12044generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
12045{
12046 int nclobs, i;
12047 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 12048 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 12049
a004eb82
AH
12050 clobs[0]
12051 = gen_rtx_SET (VOIDmode,
12052 vrsave,
12053 gen_rtx_UNSPEC_VOLATILE (SImode,
12054 gen_rtvec (2, reg, vrsave),
12055 30));
00b960c7
AH
12056
12057 nclobs = 1;
12058
9aa86737
AH
12059 /* We need to clobber the registers in the mask so the scheduler
12060 does not move sets to VRSAVE before sets of AltiVec registers.
12061
12062 However, if the function receives nonlocal gotos, reload will set
12063 all call saved registers live. We will end up with:
12064
12065 (set (reg 999) (mem))
12066 (parallel [ (set (reg vrsave) (unspec blah))
12067 (clobber (reg 999))])
12068
12069 The clobber will cause the store into reg 999 to be dead, and
12070 flow will attempt to delete an epilogue insn. In this case, we
12071 need an unspec use/set of the register. */
00b960c7
AH
12072
12073 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
44688022 12074 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
9aa86737
AH
12075 {
12076 if (!epiloguep || call_used_regs [i])
12077 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
12078 gen_rtx_REG (V4SImode, i));
12079 else
12080 {
12081 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
12082
12083 clobs[nclobs++]
a004eb82
AH
12084 = gen_rtx_SET (VOIDmode,
12085 reg,
12086 gen_rtx_UNSPEC (V4SImode,
12087 gen_rtvec (1, reg), 27));
9aa86737
AH
12088 }
12089 }
00b960c7
AH
12090
12091 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
12092
12093 for (i = 0; i < nclobs; ++i)
12094 XVECEXP (insn, 0, i) = clobs[i];
12095
12096 return insn;
12097}
12098
89e7058f
AH
12099/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
12100 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
12101
12102static void
a2369ed3 12103emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 12104 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
12105{
12106 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
12107 rtx replacea, replaceb;
12108
12109 int_rtx = GEN_INT (offset);
12110
12111 /* Some cases that need register indexed addressing. */
12112 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
12113 || (TARGET_SPE_ABI
12114 && SPE_VECTOR_MODE (mode)
12115 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
12116 {
12117 /* Whomever calls us must make sure r11 is available in the
12118 flow path of instructions in the prologue. */
12119 offset_rtx = gen_rtx_REG (Pmode, 11);
12120 emit_move_insn (offset_rtx, int_rtx);
12121
12122 replacea = offset_rtx;
12123 replaceb = int_rtx;
12124 }
12125 else
12126 {
12127 offset_rtx = int_rtx;
12128 replacea = NULL_RTX;
12129 replaceb = NULL_RTX;
12130 }
12131
12132 reg = gen_rtx_REG (mode, regno);
12133 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
12134 mem = gen_rtx_MEM (mode, addr);
12135 set_mem_alias_set (mem, rs6000_sr_alias_set);
12136
12137 insn = emit_move_insn (mem, reg);
12138
12139 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
12140}
12141
a3170dc6
AH
12142/* Emit an offset memory reference suitable for a frame store, while
12143 converting to a valid addressing mode. */
12144
12145static rtx
a2369ed3 12146gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
12147{
12148 rtx int_rtx, offset_rtx;
12149
12150 int_rtx = GEN_INT (offset);
12151
12152 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
12153 {
12154 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12155 emit_move_insn (offset_rtx, int_rtx);
12156 }
12157 else
12158 offset_rtx = int_rtx;
12159
12160 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
12161}
12162
9ebbca7d
GK
12163/* Emit function prologue as insns. */
12164
9878760c 12165void
863d938c 12166rs6000_emit_prologue (void)
9878760c 12167{
4697a36c 12168 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 12169 enum machine_mode reg_mode = Pmode;
327e5343 12170 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12171 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12172 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
12173 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 12174 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
12175 rtx insn;
12176 int saving_FPRs_inline;
12177 int using_store_multiple;
12178 HOST_WIDE_INT sp_offset = 0;
12179
c19de7aa 12180 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12181 {
12182 reg_mode = V2SImode;
12183 reg_size = 8;
12184 }
12185
9ebbca7d 12186 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12187 && (!TARGET_SPE_ABI
12188 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12189 && info->first_gp_reg_save < 31);
12190 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 12191 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 12192 || current_function_calls_eh_return
8c29550d 12193 || cfun->machine->ra_need_lr);
9ebbca7d
GK
12194
12195 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 12196 if (info->push_p
acd0b319
AM
12197 && (DEFAULT_ABI == ABI_V4
12198 || current_function_calls_eh_return))
9ebbca7d
GK
12199 {
12200 if (info->total_size < 32767)
12201 sp_offset = info->total_size;
12202 else
12203 frame_reg_rtx = frame_ptr_rtx;
12204 rs6000_emit_allocate_stack (info->total_size,
12205 (frame_reg_rtx != sp_reg_rtx
12206 && (info->cr_save_p
12207 || info->lr_save_p
12208 || info->first_fp_reg_save < 64
12209 || info->first_gp_reg_save < 32
12210 )));
12211 if (frame_reg_rtx != sp_reg_rtx)
12212 rs6000_emit_stack_tie ();
12213 }
12214
9aa86737
AH
12215 /* Save AltiVec registers if needed. */
12216 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12217 {
12218 int i;
12219
12220 /* There should be a non inline version of this, for when we
12221 are saving lots of vector registers. */
12222 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12223 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12224 {
12225 rtx areg, savereg, mem;
12226 int offset;
12227
12228 offset = info->altivec_save_offset + sp_offset
12229 + 16 * (i - info->first_altivec_reg_save);
12230
12231 savereg = gen_rtx_REG (V4SImode, i);
12232
12233 areg = gen_rtx_REG (Pmode, 0);
12234 emit_move_insn (areg, GEN_INT (offset));
12235
12236 /* AltiVec addressing mode is [reg+reg]. */
12237 mem = gen_rtx_MEM (V4SImode,
12238 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
12239
12240 set_mem_alias_set (mem, rs6000_sr_alias_set);
12241
12242 insn = emit_move_insn (mem, savereg);
12243
5c242421
SB
12244 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12245 areg, GEN_INT (offset));
9aa86737
AH
12246 }
12247 }
12248
12249 /* VRSAVE is a bit vector representing which AltiVec registers
12250 are used. The OS uses this to determine which vector
12251 registers to save on a context switch. We need to save
12252 VRSAVE on the stack frame, add whatever AltiVec registers we
12253 used in this function, and do the corresponding magic in the
12254 epilogue. */
12255
4d774ff8
HP
12256 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
12257 && info->vrsave_mask != 0)
9aa86737 12258 {
a004eb82 12259 rtx reg, mem, vrsave;
9aa86737
AH
12260 int offset;
12261
12262 /* Get VRSAVE onto a GPR. */
12263 reg = gen_rtx_REG (SImode, 12);
a004eb82 12264 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
12265 if (TARGET_MACHO)
12266 emit_insn (gen_get_vrsave_internal (reg));
12267 else
12268 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
12269
12270 /* Save VRSAVE. */
12271 offset = info->vrsave_save_offset + sp_offset;
12272 mem
12273 = gen_rtx_MEM (SImode,
12274 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
12275 set_mem_alias_set (mem, rs6000_sr_alias_set);
12276 insn = emit_move_insn (mem, reg);
12277
12278 /* Include the registers in the mask. */
12279 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
12280
12281 insn = emit_insn (generate_set_vrsave (reg, info, 0));
12282 }
12283
9ebbca7d
GK
12284 /* If we use the link register, get it into r0. */
12285 if (info->lr_save_p)
71f123ca 12286 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
12287 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12288
12289 /* If we need to save CR, put it into r12. */
12290 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
12291 {
12292 cr_save_rtx = gen_rtx_REG (SImode, 12);
12293 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12294 }
12295
a4f6c312
SS
12296 /* Do any required saving of fpr's. If only one or two to save, do
12297 it ourselves. Otherwise, call function. */
9ebbca7d
GK
12298 if (saving_FPRs_inline)
12299 {
12300 int i;
12301 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12302 if ((regs_ever_live[info->first_fp_reg_save+i]
12303 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
12304 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
12305 info->first_fp_reg_save + i,
12306 info->fp_save_offset + sp_offset + 8 * i,
12307 info->total_size);
9ebbca7d
GK
12308 }
12309 else if (info->first_fp_reg_save != 64)
12310 {
12311 int i;
12312 char rname[30];
520a57c8 12313 const char *alloc_rname;
9ebbca7d
GK
12314 rtvec p;
12315 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
12316
12317 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
12318 gen_rtx_REG (Pmode,
12319 LINK_REGISTER_REGNUM));
12320 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
12321 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 12322 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12323 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
12324 gen_rtx_SYMBOL_REF (Pmode,
12325 alloc_rname));
12326 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12327 {
12328 rtx addr, reg, mem;
12329 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
12330 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12331 GEN_INT (info->fp_save_offset
12332 + sp_offset + 8*i));
12333 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12334 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12335
12336 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
12337 }
12338 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12339 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12340 NULL_RTX, NULL_RTX);
12341 }
b6c9286a 12342
9ebbca7d
GK
12343 /* Save GPRs. This is done as a PARALLEL if we are using
12344 the store-multiple instructions. */
12345 if (using_store_multiple)
b6c9286a 12346 {
308c142a 12347 rtvec p;
9ebbca7d
GK
12348 int i;
12349 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
12350 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12351 {
12352 rtx addr, reg, mem;
12353 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12354 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12355 GEN_INT (info->gp_save_offset
12356 + sp_offset
12357 + reg_size * i));
12358 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12359 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12360
12361 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
12362 }
12363 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12364 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12365 NULL_RTX, NULL_RTX);
b6c9286a
MM
12366 }
12367 else
12368 {
9ebbca7d
GK
12369 int i;
12370 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12371 if ((regs_ever_live[info->first_gp_reg_save+i]
12372 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12373 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12374 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12375 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
12376 {
12377 rtx addr, reg, mem;
12378 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12379
c19de7aa 12380 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12381 {
12382 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12383 rtx b;
12384
12385 if (!SPE_CONST_OFFSET_OK (offset))
12386 {
12387 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12388 emit_move_insn (b, GEN_INT (offset));
12389 }
12390 else
12391 b = GEN_INT (offset);
12392
12393 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12394 mem = gen_rtx_MEM (V2SImode, addr);
12395 set_mem_alias_set (mem, rs6000_sr_alias_set);
12396 insn = emit_move_insn (mem, reg);
12397
12398 if (GET_CODE (b) == CONST_INT)
12399 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12400 NULL_RTX, NULL_RTX);
12401 else
12402 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12403 b, GEN_INT (offset));
12404 }
12405 else
12406 {
12407 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12408 GEN_INT (info->gp_save_offset
12409 + sp_offset
12410 + reg_size * i));
12411 mem = gen_rtx_MEM (reg_mode, addr);
12412 set_mem_alias_set (mem, rs6000_sr_alias_set);
12413
12414 insn = emit_move_insn (mem, reg);
12415 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12416 NULL_RTX, NULL_RTX);
12417 }
12418 }
9ebbca7d
GK
12419 }
12420
83720594
RH
12421 /* ??? There's no need to emit actual instructions here, but it's the
12422 easiest way to get the frame unwind information emitted. */
12423 if (current_function_calls_eh_return)
12424 {
78e1b90d
DE
12425 unsigned int i, regno;
12426
fc4767bb
JJ
12427 /* In AIX ABI we need to pretend we save r2 here. */
12428 if (TARGET_AIX)
12429 {
12430 rtx addr, reg, mem;
12431
12432 reg = gen_rtx_REG (reg_mode, 2);
12433 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12434 GEN_INT (sp_offset + 5 * reg_size));
12435 mem = gen_rtx_MEM (reg_mode, addr);
12436 set_mem_alias_set (mem, rs6000_sr_alias_set);
12437
12438 insn = emit_move_insn (mem, reg);
12439 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12440 NULL_RTX, NULL_RTX);
12441 PATTERN (insn) = gen_blockage ();
12442 }
12443
83720594
RH
12444 for (i = 0; ; ++i)
12445 {
83720594
RH
12446 regno = EH_RETURN_DATA_REGNO (i);
12447 if (regno == INVALID_REGNUM)
12448 break;
12449
89e7058f
AH
12450 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
12451 info->ehrd_offset + sp_offset
12452 + reg_size * (int) i,
12453 info->total_size);
83720594
RH
12454 }
12455 }
12456
9ebbca7d
GK
12457 /* Save lr if we used it. */
12458 if (info->lr_save_p)
12459 {
12460 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12461 GEN_INT (info->lr_save_offset + sp_offset));
12462 rtx reg = gen_rtx_REG (Pmode, 0);
12463 rtx mem = gen_rtx_MEM (Pmode, addr);
12464 /* This should not be of rs6000_sr_alias_set, because of
12465 __builtin_return_address. */
12466
12467 insn = emit_move_insn (mem, reg);
12468 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12469 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12470 }
12471
12472 /* Save CR if we use any that must be preserved. */
12473 if (info->cr_save_p)
12474 {
12475 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12476 GEN_INT (info->cr_save_offset + sp_offset));
12477 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12478
12479 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12480
12481 /* If r12 was used to hold the original sp, copy cr into r0 now
12482 that it's free. */
12483 if (REGNO (frame_reg_rtx) == 12)
12484 {
12485 cr_save_rtx = gen_rtx_REG (SImode, 0);
12486 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12487 }
12488 insn = emit_move_insn (mem, cr_save_rtx);
12489
12490 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
12491 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
12492 But that's OK. All we have to do is specify that _one_ condition
12493 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
12494 will then restore all the call-saved registers.
12495 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 12496 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 12497 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
12498 }
12499
12500 /* Update stack and set back pointer unless this is V.4,
12501 for which it was done previously. */
fc4767bb
JJ
12502 if (info->push_p
12503 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
12504 rs6000_emit_allocate_stack (info->total_size, FALSE);
12505
12506 /* Set frame pointer, if needed. */
12507 if (frame_pointer_needed)
12508 {
a3170dc6 12509 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
12510 sp_reg_rtx);
12511 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 12512 }
9878760c 12513
1db02437 12514 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 12515 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 12516 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 12517 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
12518 {
12519 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 12520 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
12521 can use register 0. This allows us to use a plain 'blr' to return
12522 from the procedure more often. */
f1384257
AM
12523 int save_LR_around_toc_setup = (TARGET_ELF
12524 && DEFAULT_ABI != ABI_AIX
12525 && flag_pic
d5fa86ba
GK
12526 && ! info->lr_save_p
12527 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 12528 if (save_LR_around_toc_setup)
c4501e62
JJ
12529 {
12530 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
12531 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
12532 rs6000_emit_load_toc_table (TRUE);
12533 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
12534 }
12535 else
12536 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 12537 }
ee890fe2 12538
fcce224d 12539#if TARGET_MACHO
ee890fe2
SS
12540 if (DEFAULT_ABI == ABI_DARWIN
12541 && flag_pic && current_function_uses_pic_offset_table)
12542 {
12543 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 12544 const char *picbase = machopic_function_base_name ();
6788f5ca 12545 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 12546
f51eee6a 12547 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
12548
12549 rs6000_maybe_dead (
1db02437 12550 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
12551 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
12552 }
fcce224d 12553#endif
9ebbca7d
GK
12554}
12555
9ebbca7d 12556/* Write function prologue. */
a4f6c312 12557
08c148a8 12558static void
a2369ed3
DJ
12559rs6000_output_function_prologue (FILE *file,
12560 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
12561{
12562 rs6000_stack_t *info = rs6000_stack_info ();
12563
4697a36c
MM
12564 if (TARGET_DEBUG_STACK)
12565 debug_stack_info (info);
9878760c 12566
a4f6c312
SS
12567 /* Write .extern for any function we will call to save and restore
12568 fp values. */
12569 if (info->first_fp_reg_save < 64
12570 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 12571 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 12572 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
12573 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
12574 RESTORE_FP_SUFFIX);
9878760c 12575
c764f757
RK
12576 /* Write .extern for AIX common mode routines, if needed. */
12577 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
12578 {
f6709c70
JW
12579 fputs ("\t.extern __mulh\n", file);
12580 fputs ("\t.extern __mull\n", file);
12581 fputs ("\t.extern __divss\n", file);
12582 fputs ("\t.extern __divus\n", file);
12583 fputs ("\t.extern __quoss\n", file);
12584 fputs ("\t.extern __quous\n", file);
c764f757
RK
12585 common_mode_defined = 1;
12586 }
9878760c 12587
9ebbca7d 12588 if (! HAVE_prologue)
979721f8 12589 {
9ebbca7d 12590 start_sequence ();
9dda4cc8 12591
a4f6c312
SS
12592 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
12593 the "toplevel" insn chain. */
2e040219 12594 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12595 rs6000_emit_prologue ();
2e040219 12596 emit_note (NOTE_INSN_DELETED);
178c3eff 12597
a3c9585f 12598 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12599 {
12600 rtx insn;
12601 unsigned addr = 0;
12602 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12603 {
12604 INSN_ADDRESSES_NEW (insn, addr);
12605 addr += 4;
12606 }
12607 }
9dda4cc8 12608
9ebbca7d 12609 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12610 debug_rtx_list (get_insns (), 100);
12611 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12612 end_sequence ();
979721f8
MM
12613 }
12614
9ebbca7d
GK
12615 rs6000_pic_labelno++;
12616}
12617
12618/* Emit function epilogue as insns.
9878760c 12619
9ebbca7d
GK
12620 At present, dwarf2out_frame_debug_expr doesn't understand
12621 register restores, so we don't bother setting RTX_FRAME_RELATED_P
12622 anywhere in the epilogue. Most of the insns below would in any case
12623 need special notes to explain where r11 is in relation to the stack. */
9878760c 12624
9ebbca7d 12625void
a2369ed3 12626rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
12627{
12628 rs6000_stack_t *info;
12629 int restoring_FPRs_inline;
12630 int using_load_multiple;
12631 int using_mfcr_multiple;
12632 int use_backchain_to_restore_sp;
12633 int sp_offset = 0;
12634 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
12635 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 12636 enum machine_mode reg_mode = Pmode;
327e5343 12637 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12638 int i;
12639
c19de7aa
AH
12640 info = rs6000_stack_info ();
12641
12642 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12643 {
12644 reg_mode = V2SImode;
12645 reg_size = 8;
12646 }
12647
9ebbca7d 12648 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12649 && (!TARGET_SPE_ABI
12650 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12651 && info->first_gp_reg_save < 31);
12652 restoring_FPRs_inline = (sibcall
83720594 12653 || current_function_calls_eh_return
9ebbca7d
GK
12654 || info->first_fp_reg_save == 64
12655 || FP_SAVE_INLINE (info->first_fp_reg_save));
12656 use_backchain_to_restore_sp = (frame_pointer_needed
12657 || current_function_calls_alloca
12658 || info->total_size > 32767);
12659 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
12660 || rs6000_cpu == PROCESSOR_PPC603
12661 || rs6000_cpu == PROCESSOR_PPC750
12662 || optimize_size);
12663
12664 /* If we have a frame pointer, a call to alloca, or a large stack
12665 frame, restore the old stack pointer using the backchain. Otherwise,
12666 we know what size to update it with. */
12667 if (use_backchain_to_restore_sp)
bacbde18 12668 {
9ebbca7d
GK
12669 /* Under V.4, don't reset the stack pointer until after we're done
12670 loading the saved registers. */
f607bc57 12671 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 12672 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 12673
9ebbca7d
GK
12674 emit_move_insn (frame_reg_rtx,
12675 gen_rtx_MEM (Pmode, sp_reg_rtx));
12676
bacbde18 12677 }
9ebbca7d 12678 else if (info->push_p)
85638c0d 12679 {
fc4767bb
JJ
12680 if (DEFAULT_ABI == ABI_V4
12681 || current_function_calls_eh_return)
9ebbca7d
GK
12682 sp_offset = info->total_size;
12683 else
12684 {
12685 emit_insn (TARGET_32BIT
12686 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12687 GEN_INT (info->total_size))
12688 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12689 GEN_INT (info->total_size)));
12690 }
85638c0d 12691 }
9ebbca7d 12692
9aa86737
AH
12693 /* Restore AltiVec registers if needed. */
12694 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12695 {
12696 int i;
12697
12698 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12699 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12700 {
12701 rtx addr, areg, mem;
12702
12703 areg = gen_rtx_REG (Pmode, 0);
12704 emit_move_insn
12705 (areg, GEN_INT (info->altivec_save_offset
12706 + sp_offset
12707 + 16 * (i - info->first_altivec_reg_save)));
12708
12709 /* AltiVec addressing mode is [reg+reg]. */
12710 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
12711 mem = gen_rtx_MEM (V4SImode, addr);
12712 set_mem_alias_set (mem, rs6000_sr_alias_set);
12713
12714 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
12715 }
12716 }
12717
12718 /* Restore VRSAVE if needed. */
44688022 12719 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
4d774ff8 12720 && info->vrsave_mask != 0)
9aa86737
AH
12721 {
12722 rtx addr, mem, reg;
12723
12724 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12725 GEN_INT (info->vrsave_save_offset + sp_offset));
12726 mem = gen_rtx_MEM (SImode, addr);
12727 set_mem_alias_set (mem, rs6000_sr_alias_set);
12728 reg = gen_rtx_REG (SImode, 12);
12729 emit_move_insn (reg, mem);
12730
12731 emit_insn (generate_set_vrsave (reg, info, 1));
12732 }
12733
9ebbca7d
GK
12734 /* Get the old lr if we saved it. */
12735 if (info->lr_save_p)
b6c9286a 12736 {
a3170dc6
AH
12737 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
12738 info->lr_save_offset + sp_offset);
ba4828e0
RK
12739
12740 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12741
9ebbca7d 12742 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 12743 }
9ebbca7d
GK
12744
12745 /* Get the old cr if we saved it. */
12746 if (info->cr_save_p)
12747 {
12748 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12749 GEN_INT (info->cr_save_offset + sp_offset));
12750 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12751
12752 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12753
9ebbca7d
GK
12754 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
12755 }
12756
12757 /* Set LR here to try to overlap restores below. */
4697a36c 12758 if (info->lr_save_p)
9ebbca7d
GK
12759 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
12760 gen_rtx_REG (Pmode, 0));
12761
83720594
RH
12762 /* Load exception handler data registers, if needed. */
12763 if (current_function_calls_eh_return)
12764 {
78e1b90d
DE
12765 unsigned int i, regno;
12766
fc4767bb
JJ
12767 if (TARGET_AIX)
12768 {
12769 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12770 GEN_INT (sp_offset + 5 * reg_size));
12771 rtx mem = gen_rtx_MEM (reg_mode, addr);
12772
12773 set_mem_alias_set (mem, rs6000_sr_alias_set);
12774
12775 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
12776 }
12777
83720594
RH
12778 for (i = 0; ; ++i)
12779 {
a3170dc6 12780 rtx mem;
83720594
RH
12781
12782 regno = EH_RETURN_DATA_REGNO (i);
12783 if (regno == INVALID_REGNUM)
12784 break;
12785
a3170dc6
AH
12786 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
12787 info->ehrd_offset + sp_offset
12788 + reg_size * (int) i);
ba4828e0 12789 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
12790
12791 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
12792 }
12793 }
9ebbca7d
GK
12794
12795 /* Restore GPRs. This is done as a PARALLEL if we are using
12796 the load-multiple instructions. */
12797 if (using_load_multiple)
979721f8 12798 {
9ebbca7d
GK
12799 rtvec p;
12800 p = rtvec_alloc (32 - info->first_gp_reg_save);
12801 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 12802 {
9ebbca7d
GK
12803 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12804 GEN_INT (info->gp_save_offset
12805 + sp_offset
12806 + reg_size * i));
12807 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
12808
12809 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12810
12811 RTVEC_ELT (p, i) =
12812 gen_rtx_SET (VOIDmode,
12813 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
12814 mem);
979721f8 12815 }
9ebbca7d 12816 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 12817 }
9ebbca7d
GK
12818 else
12819 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12820 if ((regs_ever_live[info->first_gp_reg_save+i]
12821 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12822 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12823 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12824 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
12825 {
12826 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12827 GEN_INT (info->gp_save_offset
12828 + sp_offset
12829 + reg_size * i));
12830 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12831
a3170dc6 12832 /* Restore 64-bit quantities for SPE. */
c19de7aa 12833 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12834 {
12835 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12836 rtx b;
12837
12838 if (!SPE_CONST_OFFSET_OK (offset))
12839 {
12840 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12841 emit_move_insn (b, GEN_INT (offset));
12842 }
12843 else
12844 b = GEN_INT (offset);
12845
12846 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12847 mem = gen_rtx_MEM (V2SImode, addr);
12848 }
12849
ba4828e0 12850 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12851
12852 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 12853 info->first_gp_reg_save + i), mem);
9ebbca7d 12854 }
9878760c 12855
9ebbca7d
GK
12856 /* Restore fpr's if we need to do it without calling a function. */
12857 if (restoring_FPRs_inline)
12858 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12859 if ((regs_ever_live[info->first_fp_reg_save+i]
12860 && ! call_used_regs[info->first_fp_reg_save+i]))
12861 {
12862 rtx addr, mem;
12863 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12864 GEN_INT (info->fp_save_offset
12865 + sp_offset
a4f6c312 12866 + 8 * i));
9ebbca7d 12867 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12868 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12869
12870 emit_move_insn (gen_rtx_REG (DFmode,
12871 info->first_fp_reg_save + i),
12872 mem);
12873 }
8d30c4ee 12874
9ebbca7d
GK
12875 /* If we saved cr, restore it here. Just those that were used. */
12876 if (info->cr_save_p)
979721f8 12877 {
9ebbca7d 12878 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 12879 int count = 0;
9ebbca7d
GK
12880
12881 if (using_mfcr_multiple)
979721f8 12882 {
9ebbca7d
GK
12883 for (i = 0; i < 8; i++)
12884 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 12885 count++;
9ebbca7d 12886 if (count == 0)
e35b9579
GK
12887 abort ();
12888 }
12889
12890 if (using_mfcr_multiple && count > 1)
12891 {
12892 rtvec p;
12893 int ndx;
9ebbca7d 12894
e35b9579 12895 p = rtvec_alloc (count);
9ebbca7d 12896
e35b9579 12897 ndx = 0;
9ebbca7d
GK
12898 for (i = 0; i < 8; i++)
12899 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
12900 {
12901 rtvec r = rtvec_alloc (2);
12902 RTVEC_ELT (r, 0) = r12_rtx;
12903 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 12904 RTVEC_ELT (p, ndx) =
9ebbca7d 12905 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 12906 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 12907 ndx++;
9ebbca7d
GK
12908 }
12909 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
12910 if (ndx != count)
12911 abort ();
979721f8
MM
12912 }
12913 else
9ebbca7d
GK
12914 for (i = 0; i < 8; i++)
12915 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 12916 {
9ebbca7d
GK
12917 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
12918 CR0_REGNO+i),
12919 r12_rtx));
979721f8 12920 }
979721f8
MM
12921 }
12922
9ebbca7d
GK
12923 /* If this is V.4, unwind the stack pointer after all of the loads
12924 have been done. We need to emit a block here so that sched
12925 doesn't decide to move the sp change before the register restores
12926 (which may not have any obvious dependency on the stack). This
12927 doesn't hurt performance, because there is no scheduling that can
12928 be done after this point. */
fc4767bb
JJ
12929 if (DEFAULT_ABI == ABI_V4
12930 || current_function_calls_eh_return)
b6c9286a 12931 {
9ebbca7d
GK
12932 if (frame_reg_rtx != sp_reg_rtx)
12933 rs6000_emit_stack_tie ();
b6c9286a 12934
9ebbca7d 12935 if (use_backchain_to_restore_sp)
b6c9286a 12936 {
9ebbca7d 12937 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12938 }
9ebbca7d 12939 else if (sp_offset != 0)
13f1623b 12940 {
5b71a4e7 12941 emit_insn (TARGET_32BIT
9ebbca7d
GK
12942 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12943 GEN_INT (sp_offset))
12944 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12945 GEN_INT (sp_offset)));
13f1623b 12946 }
9ebbca7d 12947 }
b6c9286a 12948
83720594
RH
12949 if (current_function_calls_eh_return)
12950 {
12951 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12952 emit_insn (TARGET_32BIT
83720594
RH
12953 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12954 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12955 }
12956
9ebbca7d
GK
12957 if (!sibcall)
12958 {
12959 rtvec p;
12960 if (! restoring_FPRs_inline)
12961 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12962 else
12963 p = rtvec_alloc (2);
b6c9286a 12964
e35b9579
GK
12965 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12966 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12967 gen_rtx_REG (Pmode,
12968 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12969
12970 /* If we have to restore more than two FP registers, branch to the
12971 restore function. It will return to our caller. */
12972 if (! restoring_FPRs_inline)
12973 {
12974 int i;
12975 char rname[30];
520a57c8 12976 const char *alloc_rname;
979721f8 12977
9ebbca7d
GK
12978 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12979 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12980 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12981 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12982 gen_rtx_SYMBOL_REF (Pmode,
12983 alloc_rname));
b6c9286a 12984
9ebbca7d
GK
12985 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12986 {
12987 rtx addr, mem;
12988 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12989 GEN_INT (info->fp_save_offset + 8*i));
12990 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12991 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12992
12993 RTVEC_ELT (p, i+3) =
12994 gen_rtx_SET (VOIDmode,
12995 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12996 mem);
b6c9286a
MM
12997 }
12998 }
9ebbca7d
GK
12999
13000 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 13001 }
9878760c
RK
13002}
13003
13004/* Write function epilogue. */
13005
08c148a8 13006static void
a2369ed3
DJ
13007rs6000_output_function_epilogue (FILE *file,
13008 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 13009{
4697a36c 13010 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 13011
9ebbca7d 13012 if (! HAVE_epilogue)
9878760c 13013 {
9ebbca7d
GK
13014 rtx insn = get_last_insn ();
13015 /* If the last insn was a BARRIER, we don't have to write anything except
13016 the trace table. */
13017 if (GET_CODE (insn) == NOTE)
13018 insn = prev_nonnote_insn (insn);
13019 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 13020 {
9ebbca7d
GK
13021 /* This is slightly ugly, but at least we don't have two
13022 copies of the epilogue-emitting code. */
13023 start_sequence ();
13024
13025 /* A NOTE_INSN_DELETED is supposed to be at the start
13026 and end of the "toplevel" insn chain. */
2e040219 13027 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13028 rs6000_emit_epilogue (FALSE);
2e040219 13029 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13030
a3c9585f 13031 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
13032 {
13033 rtx insn;
13034 unsigned addr = 0;
13035 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
13036 {
13037 INSN_ADDRESSES_NEW (insn, addr);
13038 addr += 4;
13039 }
13040 }
13041
9ebbca7d 13042 if (TARGET_DEBUG_STACK)
a4f6c312
SS
13043 debug_rtx_list (get_insns (), 100);
13044 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 13045 end_sequence ();
4697a36c 13046 }
9878760c 13047 }
b4ac57ab 13048
efdba735
SH
13049#if TARGET_MACHO
13050 macho_branch_islands ();
0e5da0be
GK
13051 /* Mach-O doesn't support labels at the end of objects, so if
13052 it looks like we might want one, insert a NOP. */
13053 {
13054 rtx insn = get_last_insn ();
13055 while (insn
13056 && NOTE_P (insn)
13057 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
13058 insn = PREV_INSN (insn);
13059 if (insn
13060 && (LABEL_P (insn)
13061 || (NOTE_P (insn)
13062 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
13063 fputs ("\tnop\n", file);
13064 }
13065#endif
13066
9b30bae2 13067 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
13068 on its format.
13069
13070 We don't output a traceback table if -finhibit-size-directive was
13071 used. The documentation for -finhibit-size-directive reads
13072 ``don't output a @code{.size} assembler directive, or anything
13073 else that would cause trouble if the function is split in the
13074 middle, and the two halves are placed at locations far apart in
13075 memory.'' The traceback table has this property, since it
13076 includes the offset from the start of the function to the
4d30c363
MM
13077 traceback table itself.
13078
13079 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 13080 different traceback table. */
57ac7be9
AM
13081 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
13082 && rs6000_traceback != traceback_none)
9b30bae2 13083 {
69c75916 13084 const char *fname = NULL;
3ac88239 13085 const char *language_string = lang_hooks.name;
6041bf2f 13086 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 13087 int i;
57ac7be9
AM
13088 int optional_tbtab;
13089
13090 if (rs6000_traceback == traceback_full)
13091 optional_tbtab = 1;
13092 else if (rs6000_traceback == traceback_part)
13093 optional_tbtab = 0;
13094 else
13095 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 13096
69c75916
AM
13097 if (optional_tbtab)
13098 {
13099 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
13100 while (*fname == '.') /* V.4 encodes . in the name */
13101 fname++;
13102
13103 /* Need label immediately before tbtab, so we can compute
13104 its offset from the function start. */
13105 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
13106 ASM_OUTPUT_LABEL (file, fname);
13107 }
314fc5a9
ILT
13108
13109 /* The .tbtab pseudo-op can only be used for the first eight
13110 expressions, since it can't handle the possibly variable
13111 length fields that follow. However, if you omit the optional
13112 fields, the assembler outputs zeros for all optional fields
13113 anyways, giving each variable length field is minimum length
13114 (as defined in sys/debug.h). Thus we can not use the .tbtab
13115 pseudo-op at all. */
13116
13117 /* An all-zero word flags the start of the tbtab, for debuggers
13118 that have to find it by searching forward from the entry
13119 point or from the current pc. */
19d2d16f 13120 fputs ("\t.long 0\n", file);
314fc5a9
ILT
13121
13122 /* Tbtab format type. Use format type 0. */
19d2d16f 13123 fputs ("\t.byte 0,", file);
314fc5a9 13124
5fc921c1
DE
13125 /* Language type. Unfortunately, there does not seem to be any
13126 official way to discover the language being compiled, so we
13127 use language_string.
13128 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
13129 Java is 13. Objective-C is 14. */
13130 if (! strcmp (language_string, "GNU C"))
314fc5a9 13131 i = 0;
6de9cd9a
DN
13132 else if (! strcmp (language_string, "GNU F77")
13133 || ! strcmp (language_string, "GNU F95"))
314fc5a9 13134 i = 1;
8b83775b 13135 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 13136 i = 2;
5fc921c1
DE
13137 else if (! strcmp (language_string, "GNU Ada"))
13138 i = 3;
314fc5a9
ILT
13139 else if (! strcmp (language_string, "GNU C++"))
13140 i = 9;
9517ead8
AG
13141 else if (! strcmp (language_string, "GNU Java"))
13142 i = 13;
5fc921c1
DE
13143 else if (! strcmp (language_string, "GNU Objective-C"))
13144 i = 14;
314fc5a9
ILT
13145 else
13146 abort ();
13147 fprintf (file, "%d,", i);
13148
13149 /* 8 single bit fields: global linkage (not set for C extern linkage,
13150 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
13151 from start of procedure stored in tbtab, internal function, function
13152 has controlled storage, function has no toc, function uses fp,
13153 function logs/aborts fp operations. */
13154 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
13155 fprintf (file, "%d,",
13156 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
13157
13158 /* 6 bitfields: function is interrupt handler, name present in
13159 proc table, function calls alloca, on condition directives
13160 (controls stack walks, 3 bits), saves condition reg, saves
13161 link reg. */
13162 /* The `function calls alloca' bit seems to be set whenever reg 31 is
13163 set up as a frame pointer, even when there is no alloca call. */
13164 fprintf (file, "%d,",
6041bf2f
DE
13165 ((optional_tbtab << 6)
13166 | ((optional_tbtab & frame_pointer_needed) << 5)
13167 | (info->cr_save_p << 1)
13168 | (info->lr_save_p)));
314fc5a9 13169
6041bf2f 13170 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
13171 (6 bits). */
13172 fprintf (file, "%d,",
4697a36c 13173 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
13174
13175 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
13176 fprintf (file, "%d,", (32 - first_reg_to_save ()));
13177
6041bf2f
DE
13178 if (optional_tbtab)
13179 {
13180 /* Compute the parameter info from the function decl argument
13181 list. */
13182 tree decl;
13183 int next_parm_info_bit = 31;
314fc5a9 13184
6041bf2f
DE
13185 for (decl = DECL_ARGUMENTS (current_function_decl);
13186 decl; decl = TREE_CHAIN (decl))
13187 {
13188 rtx parameter = DECL_INCOMING_RTL (decl);
13189 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 13190
6041bf2f
DE
13191 if (GET_CODE (parameter) == REG)
13192 {
13193 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
13194 {
13195 int bits;
13196
13197 float_parms++;
13198
13199 if (mode == SFmode)
13200 bits = 0x2;
fcce224d 13201 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
13202 bits = 0x3;
13203 else
13204 abort ();
13205
13206 /* If only one bit will fit, don't or in this entry. */
13207 if (next_parm_info_bit > 0)
13208 parm_info |= (bits << (next_parm_info_bit - 1));
13209 next_parm_info_bit -= 2;
13210 }
13211 else
13212 {
13213 fixed_parms += ((GET_MODE_SIZE (mode)
13214 + (UNITS_PER_WORD - 1))
13215 / UNITS_PER_WORD);
13216 next_parm_info_bit -= 1;
13217 }
13218 }
13219 }
13220 }
314fc5a9
ILT
13221
13222 /* Number of fixed point parameters. */
13223 /* This is actually the number of words of fixed point parameters; thus
13224 an 8 byte struct counts as 2; and thus the maximum value is 8. */
13225 fprintf (file, "%d,", fixed_parms);
13226
13227 /* 2 bitfields: number of floating point parameters (7 bits), parameters
13228 all on stack. */
13229 /* This is actually the number of fp registers that hold parameters;
13230 and thus the maximum value is 13. */
13231 /* Set parameters on stack bit if parameters are not in their original
13232 registers, regardless of whether they are on the stack? Xlc
13233 seems to set the bit when not optimizing. */
13234 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
13235
6041bf2f
DE
13236 if (! optional_tbtab)
13237 return;
13238
314fc5a9
ILT
13239 /* Optional fields follow. Some are variable length. */
13240
13241 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
13242 11 double float. */
13243 /* There is an entry for each parameter in a register, in the order that
13244 they occur in the parameter list. Any intervening arguments on the
13245 stack are ignored. If the list overflows a long (max possible length
13246 34 bits) then completely leave off all elements that don't fit. */
13247 /* Only emit this long if there was at least one parameter. */
13248 if (fixed_parms || float_parms)
13249 fprintf (file, "\t.long %d\n", parm_info);
13250
13251 /* Offset from start of code to tb table. */
19d2d16f 13252 fputs ("\t.long ", file);
314fc5a9 13253 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
13254#if TARGET_AIX
13255 RS6000_OUTPUT_BASENAME (file, fname);
13256#else
9ebbca7d 13257 assemble_name (file, fname);
54ee9799 13258#endif
19d2d16f 13259 fputs ("-.", file);
54ee9799
DE
13260#if TARGET_AIX
13261 RS6000_OUTPUT_BASENAME (file, fname);
13262#else
9ebbca7d 13263 assemble_name (file, fname);
54ee9799 13264#endif
19d2d16f 13265 putc ('\n', file);
314fc5a9
ILT
13266
13267 /* Interrupt handler mask. */
13268 /* Omit this long, since we never set the interrupt handler bit
13269 above. */
13270
13271 /* Number of CTL (controlled storage) anchors. */
13272 /* Omit this long, since the has_ctl bit is never set above. */
13273
13274 /* Displacement into stack of each CTL anchor. */
13275 /* Omit this list of longs, because there are no CTL anchors. */
13276
13277 /* Length of function name. */
69c75916
AM
13278 if (*fname == '*')
13279 ++fname;
296b8152 13280 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
13281
13282 /* Function name. */
13283 assemble_string (fname, strlen (fname));
13284
13285 /* Register for alloca automatic storage; this is always reg 31.
13286 Only emit this if the alloca bit was set above. */
13287 if (frame_pointer_needed)
19d2d16f 13288 fputs ("\t.byte 31\n", file);
b1765bde
DE
13289
13290 fputs ("\t.align 2\n", file);
9b30bae2 13291 }
9878760c 13292}
17167fd8 13293\f
a4f6c312
SS
13294/* A C compound statement that outputs the assembler code for a thunk
13295 function, used to implement C++ virtual function calls with
13296 multiple inheritance. The thunk acts as a wrapper around a virtual
13297 function, adjusting the implicit object parameter before handing
13298 control off to the real function.
13299
13300 First, emit code to add the integer DELTA to the location that
13301 contains the incoming first argument. Assume that this argument
13302 contains a pointer, and is the one used to pass the `this' pointer
13303 in C++. This is the incoming argument *before* the function
13304 prologue, e.g. `%o0' on a sparc. The addition must preserve the
13305 values of all other incoming arguments.
17167fd8
MM
13306
13307 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
13308 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
13309 not touch the return address. Hence returning from FUNCTION will
13310 return to whoever called the current `thunk'.
17167fd8 13311
a4f6c312
SS
13312 The effect must be as if FUNCTION had been called directly with the
13313 adjusted first argument. This macro is responsible for emitting
13314 all of the code for a thunk function; output_function_prologue()
13315 and output_function_epilogue() are not invoked.
17167fd8 13316
a4f6c312
SS
13317 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
13318 been extracted from it.) It might possibly be useful on some
13319 targets, but probably not.
17167fd8 13320
a4f6c312
SS
13321 If you do not define this macro, the target-independent code in the
13322 C++ frontend will generate a less efficient heavyweight thunk that
13323 calls FUNCTION instead of jumping to it. The generic approach does
13324 not support varargs. */
17167fd8 13325
3961e8fe 13326static void
a2369ed3
DJ
13327rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
13328 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
13329 tree function)
17167fd8 13330{
5b71a4e7 13331 rtx this, insn, funexp;
17167fd8 13332
5b71a4e7 13333 reload_completed = 1;
fe3ad572 13334 epilogue_completed = 1;
5b71a4e7 13335 no_new_pseudos = 1;
56a7189a 13336
5b71a4e7 13337 /* Mark the end of the (empty) prologue. */
2e040219 13338 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 13339
5b71a4e7
DE
13340 /* Find the "this" pointer. If the function returns a structure,
13341 the structure return pointer is in r3. */
61f71b34 13342 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 13343 this = gen_rtx_REG (Pmode, 4);
56a7189a 13344 else
5b71a4e7 13345 this = gen_rtx_REG (Pmode, 3);
17167fd8 13346
5b71a4e7
DE
13347 /* Apply the constant offset, if required. */
13348 if (delta)
13349 {
13350 rtx delta_rtx = GEN_INT (delta);
13351 emit_insn (TARGET_32BIT
13352 ? gen_addsi3 (this, this, delta_rtx)
13353 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
13354 }
13355
5b71a4e7
DE
13356 /* Apply the offset from the vtable, if required. */
13357 if (vcall_offset)
17167fd8 13358 {
5b71a4e7
DE
13359 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
13360 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 13361
5b71a4e7 13362 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
13363 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
13364 {
13365 emit_insn (TARGET_32BIT
13366 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
13367 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
13368 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
13369 }
13370 else
13371 {
13372 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
13373
13374 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
13375 }
5b71a4e7
DE
13376 emit_insn (TARGET_32BIT
13377 ? gen_addsi3 (this, this, tmp)
13378 : gen_adddi3 (this, this, tmp));
17167fd8
MM
13379 }
13380
5b71a4e7
DE
13381 /* Generate a tail call to the target function. */
13382 if (!TREE_USED (function))
13383 {
13384 assemble_external (function);
13385 TREE_USED (function) = 1;
13386 }
13387 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 13388 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
13389
13390#if TARGET_MACHO
ab82a49f 13391 if (MACHOPIC_INDIRECT)
5b71a4e7 13392 funexp = machopic_indirect_call_target (funexp);
ee890fe2 13393#endif
5b71a4e7
DE
13394
13395 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
13396 generate sibcall RTL explicitly to avoid constraint abort. */
13397 insn = emit_call_insn (
13398 gen_rtx_PARALLEL (VOIDmode,
13399 gen_rtvec (4,
13400 gen_rtx_CALL (VOIDmode,
13401 funexp, const0_rtx),
13402 gen_rtx_USE (VOIDmode, const0_rtx),
13403 gen_rtx_USE (VOIDmode,
13404 gen_rtx_REG (SImode,
13405 LINK_REGISTER_REGNUM)),
13406 gen_rtx_RETURN (VOIDmode))));
13407 SIBLING_CALL_P (insn) = 1;
13408 emit_barrier ();
13409
13410 /* Run just enough of rest_of_compilation to get the insns emitted.
13411 There's not really enough bulk here to make other passes such as
13412 instruction scheduling worth while. Note that use_thunk calls
13413 assemble_start_function and assemble_end_function. */
13414 insn = get_insns ();
a2855205 13415 insn_locators_initialize ();
5b71a4e7
DE
13416 shorten_branches (insn);
13417 final_start_function (insn, file, 1);
13418 final (insn, file, 1, 0);
13419 final_end_function ();
13420
13421 reload_completed = 0;
fe3ad572 13422 epilogue_completed = 0;
5b71a4e7 13423 no_new_pseudos = 0;
9ebbca7d 13424}
9ebbca7d
GK
13425\f
13426/* A quick summary of the various types of 'constant-pool tables'
13427 under PowerPC:
13428
13429 Target Flags Name One table per
13430 AIX (none) AIX TOC object file
13431 AIX -mfull-toc AIX TOC object file
13432 AIX -mminimal-toc AIX minimal TOC translation unit
13433 SVR4/EABI (none) SVR4 SDATA object file
13434 SVR4/EABI -fpic SVR4 pic object file
13435 SVR4/EABI -fPIC SVR4 PIC translation unit
13436 SVR4/EABI -mrelocatable EABI TOC function
13437 SVR4/EABI -maix AIX TOC object file
13438 SVR4/EABI -maix -mminimal-toc
13439 AIX minimal TOC translation unit
13440
13441 Name Reg. Set by entries contains:
13442 made by addrs? fp? sum?
13443
13444 AIX TOC 2 crt0 as Y option option
13445 AIX minimal TOC 30 prolog gcc Y Y option
13446 SVR4 SDATA 13 crt0 gcc N Y N
13447 SVR4 pic 30 prolog ld Y not yet N
13448 SVR4 PIC 30 prolog gcc Y option option
13449 EABI TOC 30 prolog gcc Y option option
13450
13451*/
13452
9ebbca7d
GK
13453/* Hash functions for the hash table. */
13454
13455static unsigned
a2369ed3 13456rs6000_hash_constant (rtx k)
9ebbca7d 13457{
46b33600
RH
13458 enum rtx_code code = GET_CODE (k);
13459 enum machine_mode mode = GET_MODE (k);
13460 unsigned result = (code << 3) ^ mode;
13461 const char *format;
13462 int flen, fidx;
9ebbca7d 13463
46b33600
RH
13464 format = GET_RTX_FORMAT (code);
13465 flen = strlen (format);
13466 fidx = 0;
9ebbca7d 13467
46b33600
RH
13468 switch (code)
13469 {
13470 case LABEL_REF:
13471 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
13472
13473 case CONST_DOUBLE:
13474 if (mode != VOIDmode)
13475 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
13476 flen = 2;
13477 break;
13478
13479 case CODE_LABEL:
13480 fidx = 3;
13481 break;
13482
13483 default:
13484 break;
13485 }
9ebbca7d
GK
13486
13487 for (; fidx < flen; fidx++)
13488 switch (format[fidx])
13489 {
13490 case 's':
13491 {
13492 unsigned i, len;
13493 const char *str = XSTR (k, fidx);
13494 len = strlen (str);
13495 result = result * 613 + len;
13496 for (i = 0; i < len; i++)
13497 result = result * 613 + (unsigned) str[i];
17167fd8
MM
13498 break;
13499 }
9ebbca7d
GK
13500 case 'u':
13501 case 'e':
13502 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
13503 break;
13504 case 'i':
13505 case 'n':
13506 result = result * 613 + (unsigned) XINT (k, fidx);
13507 break;
13508 case 'w':
13509 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
13510 result = result * 613 + (unsigned) XWINT (k, fidx);
13511 else
13512 {
13513 size_t i;
13514 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
13515 result = result * 613 + (unsigned) (XWINT (k, fidx)
13516 >> CHAR_BIT * i);
13517 }
13518 break;
09501938
DE
13519 case '0':
13520 break;
9ebbca7d 13521 default:
a4f6c312 13522 abort ();
9ebbca7d 13523 }
46b33600 13524
9ebbca7d
GK
13525 return result;
13526}
13527
13528static unsigned
a2369ed3 13529toc_hash_function (const void *hash_entry)
9ebbca7d 13530{
a9098fd0
GK
13531 const struct toc_hash_struct *thc =
13532 (const struct toc_hash_struct *) hash_entry;
13533 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
13534}
13535
13536/* Compare H1 and H2 for equivalence. */
13537
13538static int
a2369ed3 13539toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
13540{
13541 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
13542 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
13543
a9098fd0
GK
13544 if (((const struct toc_hash_struct *) h1)->key_mode
13545 != ((const struct toc_hash_struct *) h2)->key_mode)
13546 return 0;
13547
5692c7bc 13548 return rtx_equal_p (r1, r2);
9ebbca7d
GK
13549}
13550
28e510bd
MM
13551/* These are the names given by the C++ front-end to vtables, and
13552 vtable-like objects. Ideally, this logic should not be here;
13553 instead, there should be some programmatic way of inquiring as
13554 to whether or not an object is a vtable. */
13555
13556#define VTABLE_NAME_P(NAME) \
13557 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
13558 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
13559 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 13560 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
28e510bd
MM
13561 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
13562
13563void
a2369ed3 13564rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
13565{
13566 /* Currently C++ toc references to vtables can be emitted before it
13567 is decided whether the vtable is public or private. If this is
13568 the case, then the linker will eventually complain that there is
13569 a reference to an unknown section. Thus, for vtables only,
13570 we emit the TOC reference to reference the symbol and not the
13571 section. */
13572 const char *name = XSTR (x, 0);
54ee9799
DE
13573
13574 if (VTABLE_NAME_P (name))
13575 {
13576 RS6000_OUTPUT_BASENAME (file, name);
13577 }
13578 else
13579 assemble_name (file, name);
28e510bd
MM
13580}
13581
a4f6c312
SS
13582/* Output a TOC entry. We derive the entry name from what is being
13583 written. */
9878760c
RK
13584
13585void
a2369ed3 13586output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
13587{
13588 char buf[256];
3cce094d 13589 const char *name = buf;
ec940faa 13590 const char *real_name;
9878760c
RK
13591 rtx base = x;
13592 int offset = 0;
13593
4697a36c
MM
13594 if (TARGET_NO_TOC)
13595 abort ();
13596
9ebbca7d
GK
13597 /* When the linker won't eliminate them, don't output duplicate
13598 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
13599 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
13600 CODE_LABELs. */
13601 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
13602 {
13603 struct toc_hash_struct *h;
13604 void * * found;
13605
17211ab5 13606 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 13607 time because GGC is not initialized at that point. */
17211ab5
GK
13608 if (toc_hash_table == NULL)
13609 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
13610 toc_hash_eq, NULL);
13611
9ebbca7d
GK
13612 h = ggc_alloc (sizeof (*h));
13613 h->key = x;
a9098fd0 13614 h->key_mode = mode;
9ebbca7d
GK
13615 h->labelno = labelno;
13616
13617 found = htab_find_slot (toc_hash_table, h, 1);
13618 if (*found == NULL)
13619 *found = h;
13620 else /* This is indeed a duplicate.
13621 Set this label equal to that label. */
13622 {
13623 fputs ("\t.set ", file);
13624 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13625 fprintf (file, "%d,", labelno);
13626 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13627 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
13628 found)->labelno));
13629 return;
13630 }
13631 }
13632
13633 /* If we're going to put a double constant in the TOC, make sure it's
13634 aligned properly when strict alignment is on. */
ff1720ed
RK
13635 if (GET_CODE (x) == CONST_DOUBLE
13636 && STRICT_ALIGNMENT
a9098fd0 13637 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
13638 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
13639 ASM_OUTPUT_ALIGN (file, 3);
13640 }
13641
4977bab6 13642 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 13643
37c37a57
RK
13644 /* Handle FP constants specially. Note that if we have a minimal
13645 TOC, things we put here aren't actually in the TOC, so we can allow
13646 FP constants. */
fcce224d
DE
13647 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
13648 {
13649 REAL_VALUE_TYPE rv;
13650 long k[4];
13651
13652 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13653 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
13654
13655 if (TARGET_64BIT)
13656 {
13657 if (TARGET_MINIMAL_TOC)
13658 fputs (DOUBLE_INT_ASM_OP, file);
13659 else
13660 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13661 k[0] & 0xffffffff, k[1] & 0xffffffff,
13662 k[2] & 0xffffffff, k[3] & 0xffffffff);
13663 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
13664 k[0] & 0xffffffff, k[1] & 0xffffffff,
13665 k[2] & 0xffffffff, k[3] & 0xffffffff);
13666 return;
13667 }
13668 else
13669 {
13670 if (TARGET_MINIMAL_TOC)
13671 fputs ("\t.long ", file);
13672 else
13673 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13674 k[0] & 0xffffffff, k[1] & 0xffffffff,
13675 k[2] & 0xffffffff, k[3] & 0xffffffff);
13676 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
13677 k[0] & 0xffffffff, k[1] & 0xffffffff,
13678 k[2] & 0xffffffff, k[3] & 0xffffffff);
13679 return;
13680 }
13681 }
13682 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 13683 {
042259f2
DE
13684 REAL_VALUE_TYPE rv;
13685 long k[2];
0adc764e 13686
042259f2
DE
13687 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13688 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 13689
13ded975
DE
13690 if (TARGET_64BIT)
13691 {
13692 if (TARGET_MINIMAL_TOC)
2bfcf297 13693 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13694 else
2f0552b6
AM
13695 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13696 k[0] & 0xffffffff, k[1] & 0xffffffff);
13697 fprintf (file, "0x%lx%08lx\n",
13698 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13699 return;
13700 }
1875cc88 13701 else
13ded975
DE
13702 {
13703 if (TARGET_MINIMAL_TOC)
2bfcf297 13704 fputs ("\t.long ", file);
13ded975 13705 else
2f0552b6
AM
13706 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13707 k[0] & 0xffffffff, k[1] & 0xffffffff);
13708 fprintf (file, "0x%lx,0x%lx\n",
13709 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13710 return;
13711 }
9878760c 13712 }
a9098fd0 13713 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 13714 {
042259f2
DE
13715 REAL_VALUE_TYPE rv;
13716 long l;
9878760c 13717
042259f2
DE
13718 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13719 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
13720
31bfaa0b
DE
13721 if (TARGET_64BIT)
13722 {
13723 if (TARGET_MINIMAL_TOC)
2bfcf297 13724 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 13725 else
2f0552b6
AM
13726 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13727 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
13728 return;
13729 }
042259f2 13730 else
31bfaa0b
DE
13731 {
13732 if (TARGET_MINIMAL_TOC)
2bfcf297 13733 fputs ("\t.long ", file);
31bfaa0b 13734 else
2f0552b6
AM
13735 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13736 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
13737 return;
13738 }
042259f2 13739 }
f176e826 13740 else if (GET_MODE (x) == VOIDmode
a9098fd0 13741 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 13742 {
e2c953b6 13743 unsigned HOST_WIDE_INT low;
042259f2
DE
13744 HOST_WIDE_INT high;
13745
13746 if (GET_CODE (x) == CONST_DOUBLE)
13747 {
13748 low = CONST_DOUBLE_LOW (x);
13749 high = CONST_DOUBLE_HIGH (x);
13750 }
13751 else
13752#if HOST_BITS_PER_WIDE_INT == 32
13753 {
13754 low = INTVAL (x);
0858c623 13755 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
13756 }
13757#else
13758 {
0858c623 13759 low = INTVAL (x) & 0xffffffff;
042259f2
DE
13760 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
13761 }
13762#endif
9878760c 13763
a9098fd0
GK
13764 /* TOC entries are always Pmode-sized, but since this
13765 is a bigendian machine then if we're putting smaller
13766 integer constants in the TOC we have to pad them.
13767 (This is still a win over putting the constants in
13768 a separate constant pool, because then we'd have
02a4ec28
FS
13769 to have both a TOC entry _and_ the actual constant.)
13770
13771 For a 32-bit target, CONST_INT values are loaded and shifted
13772 entirely within `low' and can be stored in one TOC entry. */
13773
13774 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 13775 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
13776
13777 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
13778 {
13779#if HOST_BITS_PER_WIDE_INT == 32
13780 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
13781 POINTER_SIZE, &low, &high, 0);
13782#else
13783 low |= high << 32;
13784 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
13785 high = (HOST_WIDE_INT) low >> 32;
13786 low &= 0xffffffff;
13787#endif
13788 }
a9098fd0 13789
13ded975
DE
13790 if (TARGET_64BIT)
13791 {
13792 if (TARGET_MINIMAL_TOC)
2bfcf297 13793 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13794 else
2f0552b6
AM
13795 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
13796 (long) high & 0xffffffff, (long) low & 0xffffffff);
13797 fprintf (file, "0x%lx%08lx\n",
13798 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
13799 return;
13800 }
1875cc88 13801 else
13ded975 13802 {
02a4ec28
FS
13803 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
13804 {
13805 if (TARGET_MINIMAL_TOC)
2bfcf297 13806 fputs ("\t.long ", file);
02a4ec28 13807 else
2bfcf297 13808 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
13809 (long) high & 0xffffffff, (long) low & 0xffffffff);
13810 fprintf (file, "0x%lx,0x%lx\n",
13811 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 13812 }
13ded975 13813 else
02a4ec28
FS
13814 {
13815 if (TARGET_MINIMAL_TOC)
2bfcf297 13816 fputs ("\t.long ", file);
02a4ec28 13817 else
2f0552b6
AM
13818 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
13819 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 13820 }
13ded975
DE
13821 return;
13822 }
9878760c
RK
13823 }
13824
13825 if (GET_CODE (x) == CONST)
13826 {
2bfcf297
DB
13827 if (GET_CODE (XEXP (x, 0)) != PLUS)
13828 abort ();
13829
9878760c
RK
13830 base = XEXP (XEXP (x, 0), 0);
13831 offset = INTVAL (XEXP (XEXP (x, 0), 1));
13832 }
13833
13834 if (GET_CODE (base) == SYMBOL_REF)
13835 name = XSTR (base, 0);
13836 else if (GET_CODE (base) == LABEL_REF)
13837 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
13838 else if (GET_CODE (base) == CODE_LABEL)
13839 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
13840 else
13841 abort ();
13842
772c5265 13843 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 13844 if (TARGET_MINIMAL_TOC)
2bfcf297 13845 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
13846 else
13847 {
b6c9286a 13848 fprintf (file, "\t.tc %s", real_name);
9878760c 13849
1875cc88
JW
13850 if (offset < 0)
13851 fprintf (file, ".N%d", - offset);
13852 else if (offset)
13853 fprintf (file, ".P%d", offset);
9878760c 13854
19d2d16f 13855 fputs ("[TC],", file);
1875cc88 13856 }
581bc4de
MM
13857
13858 /* Currently C++ toc references to vtables can be emitted before it
13859 is decided whether the vtable is public or private. If this is
13860 the case, then the linker will eventually complain that there is
13861 a TOC reference to an unknown section. Thus, for vtables only,
13862 we emit the TOC reference to reference the symbol and not the
13863 section. */
28e510bd 13864 if (VTABLE_NAME_P (name))
581bc4de 13865 {
54ee9799 13866 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
13867 if (offset < 0)
13868 fprintf (file, "%d", offset);
13869 else if (offset > 0)
13870 fprintf (file, "+%d", offset);
13871 }
13872 else
13873 output_addr_const (file, x);
19d2d16f 13874 putc ('\n', file);
9878760c
RK
13875}
13876\f
13877/* Output an assembler pseudo-op to write an ASCII string of N characters
13878 starting at P to FILE.
13879
13880 On the RS/6000, we have to do this using the .byte operation and
13881 write out special characters outside the quoted string.
13882 Also, the assembler is broken; very long strings are truncated,
a4f6c312 13883 so we must artificially break them up early. */
9878760c
RK
13884
13885void
a2369ed3 13886output_ascii (FILE *file, const char *p, int n)
9878760c
RK
13887{
13888 char c;
13889 int i, count_string;
d330fd93
KG
13890 const char *for_string = "\t.byte \"";
13891 const char *for_decimal = "\t.byte ";
13892 const char *to_close = NULL;
9878760c
RK
13893
13894 count_string = 0;
13895 for (i = 0; i < n; i++)
13896 {
13897 c = *p++;
13898 if (c >= ' ' && c < 0177)
13899 {
13900 if (for_string)
13901 fputs (for_string, file);
13902 putc (c, file);
13903
13904 /* Write two quotes to get one. */
13905 if (c == '"')
13906 {
13907 putc (c, file);
13908 ++count_string;
13909 }
13910
13911 for_string = NULL;
13912 for_decimal = "\"\n\t.byte ";
13913 to_close = "\"\n";
13914 ++count_string;
13915
13916 if (count_string >= 512)
13917 {
13918 fputs (to_close, file);
13919
13920 for_string = "\t.byte \"";
13921 for_decimal = "\t.byte ";
13922 to_close = NULL;
13923 count_string = 0;
13924 }
13925 }
13926 else
13927 {
13928 if (for_decimal)
13929 fputs (for_decimal, file);
13930 fprintf (file, "%d", c);
13931
13932 for_string = "\n\t.byte \"";
13933 for_decimal = ", ";
13934 to_close = "\n";
13935 count_string = 0;
13936 }
13937 }
13938
13939 /* Now close the string if we have written one. Then end the line. */
13940 if (to_close)
9ebbca7d 13941 fputs (to_close, file);
9878760c
RK
13942}
13943\f
13944/* Generate a unique section name for FILENAME for a section type
13945 represented by SECTION_DESC. Output goes into BUF.
13946
13947 SECTION_DESC can be any string, as long as it is different for each
13948 possible section type.
13949
13950 We name the section in the same manner as xlc. The name begins with an
13951 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13952 names) with the last period replaced by the string SECTION_DESC. If
13953 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13954 the name. */
9878760c
RK
13955
13956void
a2369ed3
DJ
13957rs6000_gen_section_name (char **buf, const char *filename,
13958 const char *section_desc)
9878760c 13959{
9ebbca7d 13960 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13961 char *p;
13962 int len;
9878760c
RK
13963
13964 after_last_slash = filename;
13965 for (q = filename; *q; q++)
11e5fe42
RK
13966 {
13967 if (*q == '/')
13968 after_last_slash = q + 1;
13969 else if (*q == '.')
13970 last_period = q;
13971 }
9878760c 13972
11e5fe42 13973 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13974 *buf = (char *) xmalloc (len);
9878760c
RK
13975
13976 p = *buf;
13977 *p++ = '_';
13978
13979 for (q = after_last_slash; *q; q++)
13980 {
11e5fe42 13981 if (q == last_period)
9878760c
RK
13982 {
13983 strcpy (p, section_desc);
13984 p += strlen (section_desc);
e3981aab 13985 break;
9878760c
RK
13986 }
13987
e9a780ec 13988 else if (ISALNUM (*q))
9878760c
RK
13989 *p++ = *q;
13990 }
13991
11e5fe42 13992 if (last_period == 0)
9878760c
RK
13993 strcpy (p, section_desc);
13994 else
13995 *p = '\0';
13996}
e165f3f0 13997\f
a4f6c312 13998/* Emit profile function. */
411707f4 13999
411707f4 14000void
a2369ed3 14001output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 14002{
ffcfcb5f
AM
14003 if (TARGET_PROFILE_KERNEL)
14004 return;
14005
8480e480
CC
14006 if (DEFAULT_ABI == ABI_AIX)
14007 {
9739c90c
JJ
14008#ifndef NO_PROFILE_COUNTERS
14009# define NO_PROFILE_COUNTERS 0
14010#endif
14011 if (NO_PROFILE_COUNTERS)
14012 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
14013 else
14014 {
14015 char buf[30];
14016 const char *label_name;
14017 rtx fun;
411707f4 14018
9739c90c
JJ
14019 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
14020 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
14021 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 14022
9739c90c
JJ
14023 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
14024 fun, Pmode);
14025 }
8480e480 14026 }
ee890fe2
SS
14027 else if (DEFAULT_ABI == ABI_DARWIN)
14028 {
d5fa86ba 14029 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
14030 int caller_addr_regno = LINK_REGISTER_REGNUM;
14031
14032 /* Be conservative and always set this, at least for now. */
14033 current_function_uses_pic_offset_table = 1;
14034
14035#if TARGET_MACHO
14036 /* For PIC code, set up a stub and collect the caller's address
14037 from r0, which is where the prologue puts it. */
ab82a49f 14038 if (MACHOPIC_INDIRECT)
ee890fe2
SS
14039 {
14040 mcount_name = machopic_stub_name (mcount_name);
14041 if (current_function_uses_pic_offset_table)
14042 caller_addr_regno = 0;
14043 }
14044#endif
14045 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
14046 0, VOIDmode, 1,
14047 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
14048 }
411707f4
CC
14049}
14050
a4f6c312 14051/* Write function profiler code. */
e165f3f0
RK
14052
14053void
a2369ed3 14054output_function_profiler (FILE *file, int labelno)
e165f3f0 14055{
3daf36a4 14056 char buf[100];
09eeeacb 14057 int save_lr = 8;
e165f3f0 14058
38c1f2d7 14059 switch (DEFAULT_ABI)
3daf36a4 14060 {
38c1f2d7
MM
14061 default:
14062 abort ();
14063
14064 case ABI_V4:
09eeeacb 14065 save_lr = 4;
09eeeacb
AM
14066 if (!TARGET_32BIT)
14067 {
14068 warning ("no profiling of 64-bit code for this ABI");
14069 return;
14070 }
ffcfcb5f 14071 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
14072 fprintf (file, "\tmflr %s\n", reg_names[0]);
14073 if (flag_pic == 1)
14074 {
dfdfa60f 14075 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
14076 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
14077 reg_names[0], save_lr, reg_names[1]);
17167fd8 14078 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 14079 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 14080 assemble_name (file, buf);
17167fd8 14081 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 14082 }
9ebbca7d 14083 else if (flag_pic > 1)
38c1f2d7 14084 {
09eeeacb
AM
14085 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
14086 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
14087 /* Now, we need to get the address of the label. */
14088 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 14089 assemble_name (file, buf);
9ebbca7d
GK
14090 fputs ("-.\n1:", file);
14091 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
14092 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
14093 reg_names[0], reg_names[11]);
14094 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
14095 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 14096 }
38c1f2d7
MM
14097 else
14098 {
17167fd8 14099 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 14100 assemble_name (file, buf);
dfdfa60f 14101 fputs ("@ha\n", file);
09eeeacb
AM
14102 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
14103 reg_names[0], save_lr, reg_names[1]);
a260abc9 14104 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 14105 assemble_name (file, buf);
17167fd8 14106 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
14107 }
14108
50d440bc 14109 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
14110 fprintf (file, "\tbl %s%s\n",
14111 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
14112 break;
14113
14114 case ABI_AIX:
ee890fe2 14115 case ABI_DARWIN:
ffcfcb5f
AM
14116 if (!TARGET_PROFILE_KERNEL)
14117 {
a3c9585f 14118 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
14119 }
14120 else
14121 {
14122 if (TARGET_32BIT)
14123 abort ();
14124
14125 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
14126 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
14127
6de9cd9a 14128 if (cfun->static_chain_decl != NULL)
ffcfcb5f
AM
14129 {
14130 asm_fprintf (file, "\tstd %s,24(%s)\n",
14131 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
14132 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
14133 asm_fprintf (file, "\tld %s,24(%s)\n",
14134 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
14135 }
14136 else
14137 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
14138 }
38c1f2d7
MM
14139 break;
14140 }
e165f3f0 14141}
a251ffd0 14142
b54cf83a
DE
14143\f
14144static int
863d938c 14145rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
14146{
14147 return 1;
14148}
14149
b54cf83a
DE
14150/* Power4 load update and store update instructions are cracked into a
14151 load or store and an integer insn which are executed in the same cycle.
14152 Branches have their own dispatch slot which does not count against the
14153 GCC issue rate, but it changes the program flow so there are no other
14154 instructions to issue in this cycle. */
14155
14156static int
a2369ed3
DJ
14157rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
14158 int verbose ATTRIBUTE_UNUSED,
14159 rtx insn, int more)
b54cf83a
DE
14160{
14161 if (GET_CODE (PATTERN (insn)) == USE
14162 || GET_CODE (PATTERN (insn)) == CLOBBER)
14163 return more;
14164
ec507f2d 14165 if (rs6000_sched_groups)
b54cf83a 14166 {
cbe26ab8
DN
14167 if (is_microcoded_insn (insn))
14168 return 0;
14169 else if (is_cracked_insn (insn))
14170 return more > 2 ? more - 2 : 0;
b54cf83a 14171 }
165b263e
DE
14172
14173 return more - 1;
b54cf83a
DE
14174}
14175
a251ffd0
TG
14176/* Adjust the cost of a scheduling dependency. Return the new cost of
14177 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
14178
c237e94a 14179static int
a2369ed3
DJ
14180rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
14181 int cost)
a251ffd0
TG
14182{
14183 if (! recog_memoized (insn))
14184 return 0;
14185
14186 if (REG_NOTE_KIND (link) != 0)
14187 return 0;
14188
14189 if (REG_NOTE_KIND (link) == 0)
14190 {
ed947a96
DJ
14191 /* Data dependency; DEP_INSN writes a register that INSN reads
14192 some cycles later. */
14193 switch (get_attr_type (insn))
14194 {
14195 case TYPE_JMPREG:
309323c2 14196 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
14197 a mtctr and bctr (and mtlr and br/blr). The first
14198 scheduling pass will not know about this latency since
14199 the mtctr instruction, which has the latency associated
14200 to it, will be generated by reload. */
309323c2 14201 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
14202 case TYPE_BRANCH:
14203 /* Leave some extra cycles between a compare and its
14204 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
14205 if ((rs6000_cpu_attr == CPU_PPC603
14206 || rs6000_cpu_attr == CPU_PPC604
14207 || rs6000_cpu_attr == CPU_PPC604E
14208 || rs6000_cpu_attr == CPU_PPC620
14209 || rs6000_cpu_attr == CPU_PPC630
14210 || rs6000_cpu_attr == CPU_PPC750
14211 || rs6000_cpu_attr == CPU_PPC7400
14212 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
14213 || rs6000_cpu_attr == CPU_POWER4
14214 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
14215 && recog_memoized (dep_insn)
14216 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
14217 && (get_attr_type (dep_insn) == TYPE_CMP
14218 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 14219 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
14220 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
14221 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 14222 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
14223 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
14224 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
14225 return cost + 2;
14226 default:
14227 break;
14228 }
a251ffd0
TG
14229 /* Fall out to return default cost. */
14230 }
14231
14232 return cost;
14233}
b6c9286a 14234
cbe26ab8 14235/* The function returns a true if INSN is microcoded.
839a4992 14236 Return false otherwise. */
cbe26ab8
DN
14237
14238static bool
14239is_microcoded_insn (rtx insn)
14240{
14241 if (!insn || !INSN_P (insn)
14242 || GET_CODE (PATTERN (insn)) == USE
14243 || GET_CODE (PATTERN (insn)) == CLOBBER)
14244 return false;
14245
ec507f2d 14246 if (rs6000_sched_groups)
cbe26ab8
DN
14247 {
14248 enum attr_type type = get_attr_type (insn);
14249 if (type == TYPE_LOAD_EXT_U
14250 || type == TYPE_LOAD_EXT_UX
14251 || type == TYPE_LOAD_UX
14252 || type == TYPE_STORE_UX
14253 || type == TYPE_MFCR)
14254 return true;
14255 }
14256
14257 return false;
14258}
14259
5c425df5 14260/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
14261 as the first insn in a dispatch group ("dispatch-slot restricted").
14262 In this case, the returned value indicates how many dispatch slots
14263 the insn occupies (at the beginning of the group).
79ae11c4
DN
14264 Return 0 otherwise. */
14265
cbe26ab8 14266static int
79ae11c4
DN
14267is_dispatch_slot_restricted (rtx insn)
14268{
14269 enum attr_type type;
14270
ec507f2d 14271 if (!rs6000_sched_groups)
79ae11c4
DN
14272 return 0;
14273
14274 if (!insn
14275 || insn == NULL_RTX
14276 || GET_CODE (insn) == NOTE
14277 || GET_CODE (PATTERN (insn)) == USE
14278 || GET_CODE (PATTERN (insn)) == CLOBBER)
14279 return 0;
14280
14281 type = get_attr_type (insn);
14282
ec507f2d
DE
14283 switch (type)
14284 {
14285 case TYPE_MFCR:
14286 case TYPE_MFCRF:
14287 case TYPE_MTCR:
14288 case TYPE_DELAYED_CR:
14289 case TYPE_CR_LOGICAL:
14290 case TYPE_MTJMPR:
14291 case TYPE_MFJMPR:
14292 return 1;
14293 case TYPE_IDIV:
14294 case TYPE_LDIV:
14295 return 2;
14296 default:
14297 if (rs6000_cpu == PROCESSOR_POWER5
14298 && is_cracked_insn (insn))
14299 return 2;
14300 return 0;
14301 }
79ae11c4
DN
14302}
14303
cbe26ab8
DN
14304/* The function returns true if INSN is cracked into 2 instructions
14305 by the processor (and therefore occupies 2 issue slots). */
14306
14307static bool
14308is_cracked_insn (rtx insn)
14309{
14310 if (!insn || !INSN_P (insn)
14311 || GET_CODE (PATTERN (insn)) == USE
14312 || GET_CODE (PATTERN (insn)) == CLOBBER)
14313 return false;
14314
ec507f2d 14315 if (rs6000_sched_groups)
cbe26ab8
DN
14316 {
14317 enum attr_type type = get_attr_type (insn);
14318 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
14319 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
14320 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
14321 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
14322 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
14323 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
14324 || type == TYPE_IDIV || type == TYPE_LDIV
14325 || type == TYPE_INSERT_WORD)
14326 return true;
14327 }
14328
14329 return false;
14330}
14331
14332/* The function returns true if INSN can be issued only from
a3c9585f 14333 the branch slot. */
cbe26ab8
DN
14334
14335static bool
14336is_branch_slot_insn (rtx insn)
14337{
14338 if (!insn || !INSN_P (insn)
14339 || GET_CODE (PATTERN (insn)) == USE
14340 || GET_CODE (PATTERN (insn)) == CLOBBER)
14341 return false;
14342
ec507f2d 14343 if (rs6000_sched_groups)
cbe26ab8
DN
14344 {
14345 enum attr_type type = get_attr_type (insn);
14346 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
14347 return true;
14348 return false;
14349 }
14350
14351 return false;
14352}
79ae11c4 14353
a4f6c312 14354/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
14355 priority INSN_PRIORITY (INSN). Increase the priority to execute the
14356 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
14357 define this macro if you do not need to adjust the scheduling
14358 priorities of insns. */
bef84347 14359
c237e94a 14360static int
a2369ed3 14361rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 14362{
a4f6c312
SS
14363 /* On machines (like the 750) which have asymmetric integer units,
14364 where one integer unit can do multiply and divides and the other
14365 can't, reduce the priority of multiply/divide so it is scheduled
14366 before other integer operations. */
bef84347
VM
14367
14368#if 0
2c3c49de 14369 if (! INSN_P (insn))
bef84347
VM
14370 return priority;
14371
14372 if (GET_CODE (PATTERN (insn)) == USE)
14373 return priority;
14374
14375 switch (rs6000_cpu_attr) {
14376 case CPU_PPC750:
14377 switch (get_attr_type (insn))
14378 {
14379 default:
14380 break;
14381
14382 case TYPE_IMUL:
14383 case TYPE_IDIV:
3cb999d8
DE
14384 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
14385 priority, priority);
bef84347
VM
14386 if (priority >= 0 && priority < 0x01000000)
14387 priority >>= 3;
14388 break;
14389 }
14390 }
14391#endif
14392
79ae11c4
DN
14393 if (is_dispatch_slot_restricted (insn)
14394 && reload_completed
14395 && current_sched_info->sched_max_insns_priority
14396 && rs6000_sched_restricted_insns_priority)
14397 {
14398
14399 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
14400 if (rs6000_sched_restricted_insns_priority == 1)
14401 /* Attach highest priority to insn. This means that in
14402 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
14403 precede 'priority' (critical path) considerations. */
14404 return current_sched_info->sched_max_insns_priority;
14405 else if (rs6000_sched_restricted_insns_priority == 2)
14406 /* Increase priority of insn by a minimal amount. This means that in
14407 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
14408 precede dispatch-slot restriction considerations. */
14409 return (priority + 1);
14410 }
14411
bef84347
VM
14412 return priority;
14413}
14414
a4f6c312
SS
14415/* Return how many instructions the machine can issue per cycle. */
14416
c237e94a 14417static int
863d938c 14418rs6000_issue_rate (void)
b6c9286a 14419{
3317bab1
DE
14420 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
14421 if (!reload_completed)
14422 return 1;
14423
b6c9286a 14424 switch (rs6000_cpu_attr) {
3cb999d8
DE
14425 case CPU_RIOS1: /* ? */
14426 case CPU_RS64A:
14427 case CPU_PPC601: /* ? */
ed947a96 14428 case CPU_PPC7450:
3cb999d8 14429 return 3;
b54cf83a 14430 case CPU_PPC440:
b6c9286a 14431 case CPU_PPC603:
bef84347 14432 case CPU_PPC750:
ed947a96 14433 case CPU_PPC7400:
be12c2b0 14434 case CPU_PPC8540:
bef84347 14435 return 2;
3cb999d8 14436 case CPU_RIOS2:
b6c9286a 14437 case CPU_PPC604:
19684119 14438 case CPU_PPC604E:
b6c9286a 14439 case CPU_PPC620:
3cb999d8 14440 case CPU_PPC630:
b6c9286a 14441 return 4;
cbe26ab8 14442 case CPU_POWER4:
ec507f2d 14443 case CPU_POWER5:
cbe26ab8 14444 return 5;
b6c9286a
MM
14445 default:
14446 return 1;
14447 }
14448}
14449
be12c2b0
VM
14450/* Return how many instructions to look ahead for better insn
14451 scheduling. */
14452
14453static int
863d938c 14454rs6000_use_sched_lookahead (void)
be12c2b0
VM
14455{
14456 if (rs6000_cpu_attr == CPU_PPC8540)
14457 return 4;
14458 return 0;
14459}
14460
569fa502
DN
14461/* Determine is PAT refers to memory. */
14462
14463static bool
14464is_mem_ref (rtx pat)
14465{
14466 const char * fmt;
14467 int i, j;
14468 bool ret = false;
14469
14470 if (GET_CODE (pat) == MEM)
14471 return true;
14472
14473 /* Recursively process the pattern. */
14474 fmt = GET_RTX_FORMAT (GET_CODE (pat));
14475
14476 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
14477 {
14478 if (fmt[i] == 'e')
14479 ret |= is_mem_ref (XEXP (pat, i));
14480 else if (fmt[i] == 'E')
14481 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
14482 ret |= is_mem_ref (XVECEXP (pat, i, j));
14483 }
14484
14485 return ret;
14486}
14487
14488/* Determine if PAT is a PATTERN of a load insn. */
14489
14490static bool
14491is_load_insn1 (rtx pat)
14492{
14493 if (!pat || pat == NULL_RTX)
14494 return false;
14495
14496 if (GET_CODE (pat) == SET)
14497 return is_mem_ref (SET_SRC (pat));
14498
14499 if (GET_CODE (pat) == PARALLEL)
14500 {
14501 int i;
14502
14503 for (i = 0; i < XVECLEN (pat, 0); i++)
14504 if (is_load_insn1 (XVECEXP (pat, 0, i)))
14505 return true;
14506 }
14507
14508 return false;
14509}
14510
14511/* Determine if INSN loads from memory. */
14512
14513static bool
14514is_load_insn (rtx insn)
14515{
14516 if (!insn || !INSN_P (insn))
14517 return false;
14518
14519 if (GET_CODE (insn) == CALL_INSN)
14520 return false;
14521
14522 return is_load_insn1 (PATTERN (insn));
14523}
14524
14525/* Determine if PAT is a PATTERN of a store insn. */
14526
14527static bool
14528is_store_insn1 (rtx pat)
14529{
14530 if (!pat || pat == NULL_RTX)
14531 return false;
14532
14533 if (GET_CODE (pat) == SET)
14534 return is_mem_ref (SET_DEST (pat));
14535
14536 if (GET_CODE (pat) == PARALLEL)
14537 {
14538 int i;
14539
14540 for (i = 0; i < XVECLEN (pat, 0); i++)
14541 if (is_store_insn1 (XVECEXP (pat, 0, i)))
14542 return true;
14543 }
14544
14545 return false;
14546}
14547
14548/* Determine if INSN stores to memory. */
14549
14550static bool
14551is_store_insn (rtx insn)
14552{
14553 if (!insn || !INSN_P (insn))
14554 return false;
14555
14556 return is_store_insn1 (PATTERN (insn));
14557}
14558
14559/* Returns whether the dependence between INSN and NEXT is considered
14560 costly by the given target. */
14561
14562static bool
14563rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
14564{
14565 /* If the flag is not enbled - no dependence is considered costly;
14566 allow all dependent insns in the same group.
14567 This is the most aggressive option. */
14568 if (rs6000_sched_costly_dep == no_dep_costly)
14569 return false;
14570
14571 /* If the flag is set to 1 - a dependence is always considered costly;
14572 do not allow dependent instructions in the same group.
14573 This is the most conservative option. */
14574 if (rs6000_sched_costly_dep == all_deps_costly)
14575 return true;
14576
14577 if (rs6000_sched_costly_dep == store_to_load_dep_costly
14578 && is_load_insn (next)
14579 && is_store_insn (insn))
14580 /* Prevent load after store in the same group. */
14581 return true;
14582
14583 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
14584 && is_load_insn (next)
14585 && is_store_insn (insn)
14586 && (!link || (int) REG_NOTE_KIND (link) == 0))
14587 /* Prevent load after store in the same group if it is a true dependence. */
14588 return true;
14589
14590 /* The flag is set to X; dependences with latency >= X are considered costly,
14591 and will not be scheduled in the same group. */
14592 if (rs6000_sched_costly_dep <= max_dep_latency
14593 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
14594 return true;
14595
14596 return false;
14597}
14598
cbe26ab8
DN
14599/* Return the next insn after INSN that is found before TAIL is reached,
14600 skipping any "non-active" insns - insns that will not actually occupy
14601 an issue slot. Return NULL_RTX if such an insn is not found. */
14602
14603static rtx
14604get_next_active_insn (rtx insn, rtx tail)
14605{
14606 rtx next_insn;
14607
14608 if (!insn || insn == tail)
14609 return NULL_RTX;
14610
14611 next_insn = NEXT_INSN (insn);
14612
14613 while (next_insn
14614 && next_insn != tail
14615 && (GET_CODE(next_insn) == NOTE
14616 || GET_CODE (PATTERN (next_insn)) == USE
14617 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
14618 {
14619 next_insn = NEXT_INSN (next_insn);
14620 }
14621
14622 if (!next_insn || next_insn == tail)
14623 return NULL_RTX;
14624
14625 return next_insn;
14626}
14627
839a4992 14628/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
14629 of group WHICH_GROUP.
14630
14631 If WHICH_GROUP == current_group, this function will return true if INSN
14632 causes the termination of the current group (i.e, the dispatch group to
14633 which INSN belongs). This means that INSN will be the last insn in the
14634 group it belongs to.
14635
14636 If WHICH_GROUP == previous_group, this function will return true if INSN
14637 causes the termination of the previous group (i.e, the dispatch group that
14638 precedes the group to which INSN belongs). This means that INSN will be
14639 the first insn in the group it belongs to). */
14640
14641static bool
14642insn_terminates_group_p (rtx insn, enum group_termination which_group)
14643{
14644 enum attr_type type;
14645
14646 if (! insn)
14647 return false;
569fa502 14648
cbe26ab8
DN
14649 type = get_attr_type (insn);
14650
14651 if (is_microcoded_insn (insn))
14652 return true;
14653
14654 if (which_group == current_group)
14655 {
14656 if (is_branch_slot_insn (insn))
14657 return true;
14658 return false;
14659 }
14660 else if (which_group == previous_group)
14661 {
14662 if (is_dispatch_slot_restricted (insn))
14663 return true;
14664 return false;
14665 }
14666
14667 return false;
14668}
14669
839a4992 14670/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
14671 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
14672
14673static bool
14674is_costly_group (rtx *group_insns, rtx next_insn)
14675{
14676 int i;
14677 rtx link;
14678 int cost;
14679 int issue_rate = rs6000_issue_rate ();
14680
14681 for (i = 0; i < issue_rate; i++)
14682 {
14683 rtx insn = group_insns[i];
14684 if (!insn)
14685 continue;
14686 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
14687 {
14688 rtx next = XEXP (link, 0);
14689 if (next == next_insn)
14690 {
14691 cost = insn_cost (insn, link, next_insn);
14692 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
14693 return true;
14694 }
14695 }
14696 }
14697
14698 return false;
14699}
14700
14701/* Utility of the function redefine_groups.
14702 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
14703 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
14704 to keep it "far" (in a separate group) from GROUP_INSNS, following
14705 one of the following schemes, depending on the value of the flag
14706 -minsert_sched_nops = X:
14707 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 14708 in order to force NEXT_INSN into a separate group.
cbe26ab8
DN
14709 (2) X < sched_finish_regroup_exact: insert exactly X nops.
14710 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
14711 insertion (has a group just ended, how many vacant issue slots remain in the
14712 last group, and how many dispatch groups were encountered so far). */
14713
14714static int
14715force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
14716 bool *group_end, int can_issue_more, int *group_count)
14717{
14718 rtx nop;
14719 bool force;
14720 int issue_rate = rs6000_issue_rate ();
14721 bool end = *group_end;
14722 int i;
14723
14724 if (next_insn == NULL_RTX)
14725 return can_issue_more;
14726
14727 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
14728 return can_issue_more;
14729
14730 force = is_costly_group (group_insns, next_insn);
14731 if (!force)
14732 return can_issue_more;
14733
14734 if (sched_verbose > 6)
14735 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
14736 *group_count ,can_issue_more);
14737
14738 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
14739 {
14740 if (*group_end)
14741 can_issue_more = 0;
14742
14743 /* Since only a branch can be issued in the last issue_slot, it is
14744 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
14745 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
14746 in this case the last nop will start a new group and the branch will be
14747 forced to the new group. */
14748 if (can_issue_more && !is_branch_slot_insn (next_insn))
14749 can_issue_more--;
14750
14751 while (can_issue_more > 0)
14752 {
14753 nop = gen_nop();
14754 emit_insn_before (nop, next_insn);
14755 can_issue_more--;
14756 }
14757
14758 *group_end = true;
14759 return 0;
14760 }
14761
14762 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
14763 {
14764 int n_nops = rs6000_sched_insert_nops;
14765
14766 /* Nops can't be issued from the branch slot, so the effective
14767 issue_rate for nops is 'issue_rate - 1'. */
14768 if (can_issue_more == 0)
14769 can_issue_more = issue_rate;
14770 can_issue_more--;
14771 if (can_issue_more == 0)
14772 {
14773 can_issue_more = issue_rate - 1;
14774 (*group_count)++;
14775 end = true;
14776 for (i = 0; i < issue_rate; i++)
14777 {
14778 group_insns[i] = 0;
14779 }
14780 }
14781
14782 while (n_nops > 0)
14783 {
14784 nop = gen_nop ();
14785 emit_insn_before (nop, next_insn);
14786 if (can_issue_more == issue_rate - 1) /* new group begins */
14787 end = false;
14788 can_issue_more--;
14789 if (can_issue_more == 0)
14790 {
14791 can_issue_more = issue_rate - 1;
14792 (*group_count)++;
14793 end = true;
14794 for (i = 0; i < issue_rate; i++)
14795 {
14796 group_insns[i] = 0;
14797 }
14798 }
14799 n_nops--;
14800 }
14801
14802 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
14803 can_issue_more++;
14804
14805 *group_end = /* Is next_insn going to start a new group? */
14806 (end
14807 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14808 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14809 || (can_issue_more < issue_rate &&
14810 insn_terminates_group_p (next_insn, previous_group)));
14811 if (*group_end && end)
14812 (*group_count)--;
14813
14814 if (sched_verbose > 6)
14815 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
14816 *group_count, can_issue_more);
14817 return can_issue_more;
14818 }
14819
14820 return can_issue_more;
14821}
14822
14823/* This function tries to synch the dispatch groups that the compiler "sees"
14824 with the dispatch groups that the processor dispatcher is expected to
14825 form in practice. It tries to achieve this synchronization by forcing the
14826 estimated processor grouping on the compiler (as opposed to the function
14827 'pad_goups' which tries to force the scheduler's grouping on the processor).
14828
14829 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
14830 examines the (estimated) dispatch groups that will be formed by the processor
14831 dispatcher. It marks these group boundaries to reflect the estimated
14832 processor grouping, overriding the grouping that the scheduler had marked.
14833 Depending on the value of the flag '-minsert-sched-nops' this function can
14834 force certain insns into separate groups or force a certain distance between
14835 them by inserting nops, for example, if there exists a "costly dependence"
14836 between the insns.
14837
14838 The function estimates the group boundaries that the processor will form as
14839 folllows: It keeps track of how many vacant issue slots are available after
14840 each insn. A subsequent insn will start a new group if one of the following
14841 4 cases applies:
14842 - no more vacant issue slots remain in the current dispatch group.
14843 - only the last issue slot, which is the branch slot, is vacant, but the next
14844 insn is not a branch.
14845 - only the last 2 or less issue slots, including the branch slot, are vacant,
14846 which means that a cracked insn (which occupies two issue slots) can't be
14847 issued in this group.
14848 - less than 'issue_rate' slots are vacant, and the next insn always needs to
14849 start a new group. */
14850
14851static int
14852redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14853{
14854 rtx insn, next_insn;
14855 int issue_rate;
14856 int can_issue_more;
14857 int slot, i;
14858 bool group_end;
14859 int group_count = 0;
14860 rtx *group_insns;
14861
14862 /* Initialize. */
14863 issue_rate = rs6000_issue_rate ();
14864 group_insns = alloca (issue_rate * sizeof (rtx));
14865 for (i = 0; i < issue_rate; i++)
14866 {
14867 group_insns[i] = 0;
14868 }
14869 can_issue_more = issue_rate;
14870 slot = 0;
14871 insn = get_next_active_insn (prev_head_insn, tail);
14872 group_end = false;
14873
14874 while (insn != NULL_RTX)
14875 {
14876 slot = (issue_rate - can_issue_more);
14877 group_insns[slot] = insn;
14878 can_issue_more =
14879 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14880 if (insn_terminates_group_p (insn, current_group))
14881 can_issue_more = 0;
14882
14883 next_insn = get_next_active_insn (insn, tail);
14884 if (next_insn == NULL_RTX)
14885 return group_count + 1;
14886
14887 group_end = /* Is next_insn going to start a new group? */
14888 (can_issue_more == 0
14889 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14890 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14891 || (can_issue_more < issue_rate &&
14892 insn_terminates_group_p (next_insn, previous_group)));
14893
14894 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
14895 next_insn, &group_end, can_issue_more, &group_count);
14896
14897 if (group_end)
14898 {
14899 group_count++;
14900 can_issue_more = 0;
14901 for (i = 0; i < issue_rate; i++)
14902 {
14903 group_insns[i] = 0;
14904 }
14905 }
14906
14907 if (GET_MODE (next_insn) == TImode && can_issue_more)
14908 PUT_MODE(next_insn, VOIDmode);
14909 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
14910 PUT_MODE (next_insn, TImode);
14911
14912 insn = next_insn;
14913 if (can_issue_more == 0)
14914 can_issue_more = issue_rate;
14915 } /* while */
14916
14917 return group_count;
14918}
14919
14920/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
14921 dispatch group boundaries that the scheduler had marked. Pad with nops
14922 any dispatch groups which have vacant issue slots, in order to force the
14923 scheduler's grouping on the processor dispatcher. The function
14924 returns the number of dispatch groups found. */
14925
14926static int
14927pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14928{
14929 rtx insn, next_insn;
14930 rtx nop;
14931 int issue_rate;
14932 int can_issue_more;
14933 int group_end;
14934 int group_count = 0;
14935
14936 /* Initialize issue_rate. */
14937 issue_rate = rs6000_issue_rate ();
14938 can_issue_more = issue_rate;
14939
14940 insn = get_next_active_insn (prev_head_insn, tail);
14941 next_insn = get_next_active_insn (insn, tail);
14942
14943 while (insn != NULL_RTX)
14944 {
14945 can_issue_more =
14946 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14947
14948 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
14949
14950 if (next_insn == NULL_RTX)
14951 break;
14952
14953 if (group_end)
14954 {
14955 /* If the scheduler had marked group termination at this location
14956 (between insn and next_indn), and neither insn nor next_insn will
14957 force group termination, pad the group with nops to force group
14958 termination. */
14959 if (can_issue_more
14960 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
14961 && !insn_terminates_group_p (insn, current_group)
14962 && !insn_terminates_group_p (next_insn, previous_group))
14963 {
14964 if (!is_branch_slot_insn(next_insn))
14965 can_issue_more--;
14966
14967 while (can_issue_more)
14968 {
14969 nop = gen_nop ();
14970 emit_insn_before (nop, next_insn);
14971 can_issue_more--;
14972 }
14973 }
14974
14975 can_issue_more = issue_rate;
14976 group_count++;
14977 }
14978
14979 insn = next_insn;
14980 next_insn = get_next_active_insn (insn, tail);
14981 }
14982
14983 return group_count;
14984}
14985
14986/* The following function is called at the end of scheduling BB.
14987 After reload, it inserts nops at insn group bundling. */
14988
14989static void
38f391a5 14990rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
14991{
14992 int n_groups;
14993
14994 if (sched_verbose)
14995 fprintf (dump, "=== Finishing schedule.\n");
14996
ec507f2d 14997 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
14998 {
14999 if (rs6000_sched_insert_nops == sched_finish_none)
15000 return;
15001
15002 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
15003 n_groups = pad_groups (dump, sched_verbose,
15004 current_sched_info->prev_head,
15005 current_sched_info->next_tail);
15006 else
15007 n_groups = redefine_groups (dump, sched_verbose,
15008 current_sched_info->prev_head,
15009 current_sched_info->next_tail);
15010
15011 if (sched_verbose >= 6)
15012 {
15013 fprintf (dump, "ngroups = %d\n", n_groups);
15014 print_rtl (dump, current_sched_info->prev_head);
15015 fprintf (dump, "Done finish_sched\n");
15016 }
15017 }
15018}
b6c9286a 15019\f
b6c9286a
MM
15020/* Length in units of the trampoline for entering a nested function. */
15021
15022int
863d938c 15023rs6000_trampoline_size (void)
b6c9286a
MM
15024{
15025 int ret = 0;
15026
15027 switch (DEFAULT_ABI)
15028 {
15029 default:
15030 abort ();
15031
15032 case ABI_AIX:
8f802bfb 15033 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
15034 break;
15035
4dabc42d 15036 case ABI_DARWIN:
b6c9286a 15037 case ABI_V4:
03a7e1a5 15038 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 15039 break;
b6c9286a
MM
15040 }
15041
15042 return ret;
15043}
15044
15045/* Emit RTL insns to initialize the variable parts of a trampoline.
15046 FNADDR is an RTX for the address of the function's pure code.
15047 CXT is an RTX for the static chain value for the function. */
15048
15049void
a2369ed3 15050rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 15051{
ac2a93a1 15052 enum machine_mode pmode = Pmode;
8bd04c56
MM
15053 int regsize = (TARGET_32BIT) ? 4 : 8;
15054 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
15055
15056 switch (DEFAULT_ABI)
15057 {
15058 default:
15059 abort ();
15060
8bd04c56 15061/* Macros to shorten the code expansions below. */
39403d82 15062#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
15063#define MEM_PLUS(addr,offset) \
15064 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 15065
b6c9286a
MM
15066 /* Under AIX, just build the 3 word function descriptor */
15067 case ABI_AIX:
8bd04c56
MM
15068 {
15069 rtx fn_reg = gen_reg_rtx (pmode);
15070 rtx toc_reg = gen_reg_rtx (pmode);
15071 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 15072 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
15073 emit_move_insn (MEM_DEREF (addr), fn_reg);
15074 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
15075 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
15076 }
b6c9286a
MM
15077 break;
15078
4dabc42d
TC
15079 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
15080 case ABI_DARWIN:
b6c9286a 15081 case ABI_V4:
39403d82 15082 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
15083 FALSE, VOIDmode, 4,
15084 addr, pmode,
15085 GEN_INT (rs6000_trampoline_size ()), SImode,
15086 fnaddr, pmode,
15087 ctx_reg, pmode);
b6c9286a 15088 break;
b6c9286a
MM
15089 }
15090
15091 return;
15092}
7509c759
MM
15093
15094\f
91d231cb 15095/* Table of valid machine attributes. */
a4f6c312 15096
91d231cb 15097const struct attribute_spec rs6000_attribute_table[] =
7509c759 15098{
91d231cb 15099 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 15100 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
15101 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
15102 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
15103 { NULL, 0, 0, false, false, false, NULL }
91d231cb 15104};
7509c759 15105
8bb418a3
ZL
15106/* Handle the "altivec" attribute. The attribute may have
15107 arguments as follows:
15108
15109 __attribute__((altivec(vector__)))
15110 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
15111 __attribute__((altivec(bool__))) (always followed by 'unsigned')
15112
15113 and may appear more than once (e.g., 'vector bool char') in a
15114 given declaration. */
15115
15116static tree
15117rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
15118 int flags ATTRIBUTE_UNUSED,
15119 bool *no_add_attrs)
15120{
15121 tree type = *node, result = NULL_TREE;
15122 enum machine_mode mode;
15123 int unsigned_p;
15124 char altivec_type
15125 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
15126 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
15127 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
15128 : '?');
15129
15130 while (POINTER_TYPE_P (type)
15131 || TREE_CODE (type) == FUNCTION_TYPE
15132 || TREE_CODE (type) == METHOD_TYPE
15133 || TREE_CODE (type) == ARRAY_TYPE)
15134 type = TREE_TYPE (type);
15135
15136 mode = TYPE_MODE (type);
15137
15138 if (rs6000_warn_altivec_long
15139 && (type == long_unsigned_type_node || type == long_integer_type_node))
15140 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
15141
15142 switch (altivec_type)
15143 {
15144 case 'v':
8df83eae 15145 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
15146 switch (mode)
15147 {
15148 case SImode:
15149 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
15150 break;
15151 case HImode:
15152 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
15153 break;
15154 case QImode:
15155 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
15156 break;
15157 case SFmode: result = V4SF_type_node; break;
15158 /* If the user says 'vector int bool', we may be handed the 'bool'
15159 attribute _before_ the 'vector' attribute, and so select the proper
15160 type in the 'b' case below. */
15161 case V4SImode: case V8HImode: case V16QImode: result = type;
15162 default: break;
15163 }
15164 break;
15165 case 'b':
15166 switch (mode)
15167 {
15168 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
15169 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
15170 case QImode: case V16QImode: result = bool_V16QI_type_node;
15171 default: break;
15172 }
15173 break;
15174 case 'p':
15175 switch (mode)
15176 {
15177 case V8HImode: result = pixel_V8HI_type_node;
15178 default: break;
15179 }
15180 default: break;
15181 }
15182
7958a2a6
FJ
15183 if (result && result != type && TYPE_READONLY (type))
15184 result = build_qualified_type (result, TYPE_QUAL_CONST);
15185
8bb418a3
ZL
15186 *no_add_attrs = true; /* No need to hang on to the attribute. */
15187
15188 if (!result)
15189 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
15190 else
15191 *node = reconstruct_complex_type (*node, result);
15192
15193 return NULL_TREE;
15194}
15195
f18eca82
ZL
15196/* AltiVec defines four built-in scalar types that serve as vector
15197 elements; we must teach the compiler how to mangle them. */
15198
15199static const char *
15200rs6000_mangle_fundamental_type (tree type)
15201{
15202 if (type == bool_char_type_node) return "U6__boolc";
15203 if (type == bool_short_type_node) return "U6__bools";
15204 if (type == pixel_type_node) return "u7__pixel";
15205 if (type == bool_int_type_node) return "U6__booli";
15206
15207 /* For all other types, use normal C++ mangling. */
15208 return NULL;
15209}
15210
a5c76ee6
ZW
15211/* Handle a "longcall" or "shortcall" attribute; arguments as in
15212 struct attribute_spec.handler. */
a4f6c312 15213
91d231cb 15214static tree
a2369ed3
DJ
15215rs6000_handle_longcall_attribute (tree *node, tree name,
15216 tree args ATTRIBUTE_UNUSED,
15217 int flags ATTRIBUTE_UNUSED,
15218 bool *no_add_attrs)
91d231cb
JM
15219{
15220 if (TREE_CODE (*node) != FUNCTION_TYPE
15221 && TREE_CODE (*node) != FIELD_DECL
15222 && TREE_CODE (*node) != TYPE_DECL)
15223 {
15224 warning ("`%s' attribute only applies to functions",
15225 IDENTIFIER_POINTER (name));
15226 *no_add_attrs = true;
15227 }
6a4cee5f 15228
91d231cb 15229 return NULL_TREE;
7509c759
MM
15230}
15231
a5c76ee6
ZW
15232/* Set longcall attributes on all functions declared when
15233 rs6000_default_long_calls is true. */
15234static void
a2369ed3 15235rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
15236{
15237 if (rs6000_default_long_calls
15238 && (TREE_CODE (type) == FUNCTION_TYPE
15239 || TREE_CODE (type) == METHOD_TYPE))
15240 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
15241 NULL_TREE,
15242 TYPE_ATTRIBUTES (type));
15243}
15244
3cb999d8
DE
15245/* Return a reference suitable for calling a function with the
15246 longcall attribute. */
a4f6c312 15247
6a4cee5f 15248struct rtx_def *
a2369ed3 15249rs6000_longcall_ref (rtx call_ref)
6a4cee5f 15250{
d330fd93 15251 const char *call_name;
6a4cee5f
MM
15252 tree node;
15253
15254 if (GET_CODE (call_ref) != SYMBOL_REF)
15255 return call_ref;
15256
15257 /* System V adds '.' to the internal name, so skip them. */
15258 call_name = XSTR (call_ref, 0);
15259 if (*call_name == '.')
15260 {
15261 while (*call_name == '.')
15262 call_name++;
15263
15264 node = get_identifier (call_name);
39403d82 15265 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
15266 }
15267
15268 return force_reg (Pmode, call_ref);
15269}
7509c759 15270\f
b64a1b53
RH
15271#ifdef USING_ELFOS_H
15272
7509c759
MM
15273/* A C statement or statements to switch to the appropriate section
15274 for output of RTX in mode MODE. You can assume that RTX is some
15275 kind of constant in RTL. The argument MODE is redundant except in
15276 the case of a `const_int' rtx. Select the section by calling
15277 `text_section' or one of the alternatives for other sections.
15278
15279 Do not define this macro if you put all constants in the read-only
15280 data section. */
15281
b64a1b53 15282static void
a2369ed3
DJ
15283rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
15284 unsigned HOST_WIDE_INT align)
7509c759 15285{
a9098fd0 15286 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 15287 toc_section ();
7509c759 15288 else
b64a1b53 15289 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
15290}
15291
15292/* A C statement or statements to switch to the appropriate
15293 section for output of DECL. DECL is either a `VAR_DECL' node
15294 or a constant of some sort. RELOC indicates whether forming
15295 the initial value of DECL requires link-time relocations. */
15296
ae46c4e0 15297static void
a2369ed3
DJ
15298rs6000_elf_select_section (tree decl, int reloc,
15299 unsigned HOST_WIDE_INT align)
7509c759 15300{
f1384257
AM
15301 /* Pretend that we're always building for a shared library when
15302 ABI_AIX, because otherwise we end up with dynamic relocations
15303 in read-only sections. This happens for function pointers,
15304 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
15305 default_elf_select_section_1 (decl, reloc, align,
15306 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
15307}
15308
15309/* A C statement to build up a unique section name, expressed as a
15310 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
15311 RELOC indicates whether the initial value of EXP requires
15312 link-time relocations. If you do not define this macro, GCC will use
15313 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 15314 macro can now be called for uninitialized data items as well as
4912a07c 15315 initialized data and functions. */
63019373 15316
ae46c4e0 15317static void
a2369ed3 15318rs6000_elf_unique_section (tree decl, int reloc)
63019373 15319{
f1384257
AM
15320 /* As above, pretend that we're always building for a shared library
15321 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
15322 default_unique_section_1 (decl, reloc,
15323 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 15324}
d9407988 15325\f
d1908feb
JJ
15326/* For a SYMBOL_REF, set generic flags and then perform some
15327 target-specific processing.
15328
d1908feb
JJ
15329 When the AIX ABI is requested on a non-AIX system, replace the
15330 function name with the real name (with a leading .) rather than the
15331 function descriptor name. This saves a lot of overriding code to
15332 read the prefixes. */
d9407988 15333
fb49053f 15334static void
a2369ed3 15335rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 15336{
d1908feb 15337 default_encode_section_info (decl, rtl, first);
b2003250 15338
d1908feb
JJ
15339 if (first
15340 && TREE_CODE (decl) == FUNCTION_DECL
15341 && !TARGET_AIX
15342 && DEFAULT_ABI == ABI_AIX)
d9407988 15343 {
c6a2438a 15344 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
15345 size_t len = strlen (XSTR (sym_ref, 0));
15346 char *str = alloca (len + 2);
15347 str[0] = '.';
15348 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
15349 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 15350 }
d9407988
MM
15351}
15352
0e5dbd9b 15353static bool
a2369ed3 15354rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
15355{
15356 if (rs6000_sdata == SDATA_NONE)
15357 return false;
15358
15359 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
15360 {
15361 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
15362 if (strcmp (section, ".sdata") == 0
15363 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
15364 || strcmp (section, ".sbss") == 0
15365 || strcmp (section, ".sbss2") == 0
15366 || strcmp (section, ".PPC.EMB.sdata0") == 0
15367 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
15368 return true;
15369 }
15370 else
15371 {
15372 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
15373
15374 if (size > 0
307b599c 15375 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
15376 /* If it's not public, and we're not going to reference it there,
15377 there's no need to put it in the small data section. */
0e5dbd9b
DE
15378 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
15379 return true;
15380 }
15381
15382 return false;
15383}
15384
b91da81f 15385#endif /* USING_ELFOS_H */
000034eb 15386
a6c2a102 15387\f
000034eb 15388/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
15389 ADDR can be effectively incremented by incrementing REG.
15390
15391 r0 is special and we must not select it as an address
15392 register by this routine since our caller will try to
15393 increment the returned register via an "la" instruction. */
000034eb
DE
15394
15395struct rtx_def *
a2369ed3 15396find_addr_reg (rtx addr)
000034eb
DE
15397{
15398 while (GET_CODE (addr) == PLUS)
15399 {
02441cd6
JL
15400 if (GET_CODE (XEXP (addr, 0)) == REG
15401 && REGNO (XEXP (addr, 0)) != 0)
000034eb 15402 addr = XEXP (addr, 0);
02441cd6
JL
15403 else if (GET_CODE (XEXP (addr, 1)) == REG
15404 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
15405 addr = XEXP (addr, 1);
15406 else if (CONSTANT_P (XEXP (addr, 0)))
15407 addr = XEXP (addr, 1);
15408 else if (CONSTANT_P (XEXP (addr, 1)))
15409 addr = XEXP (addr, 0);
15410 else
15411 abort ();
15412 }
02441cd6 15413 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
15414 return addr;
15415 abort ();
15416}
15417
a6c2a102 15418void
a2369ed3 15419rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
15420{
15421 fatal_insn ("bad address", op);
15422}
c8023011 15423
ee890fe2
SS
15424#if TARGET_MACHO
15425
15426#if 0
15427/* Returns 1 if OP is either a symbol reference or a sum of a symbol
15428 reference and a constant. */
15429
15430int
a2369ed3 15431symbolic_operand (rtx op)
ee890fe2
SS
15432{
15433 switch (GET_CODE (op))
15434 {
15435 case SYMBOL_REF:
15436 case LABEL_REF:
15437 return 1;
15438 case CONST:
15439 op = XEXP (op, 0);
15440 return (GET_CODE (op) == SYMBOL_REF ||
15441 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
15442 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
15443 && GET_CODE (XEXP (op, 1)) == CONST_INT);
15444 default:
15445 return 0;
15446 }
c8023011 15447}
ee890fe2
SS
15448#endif
15449
efdba735 15450#if TARGET_MACHO
ee890fe2 15451
efdba735 15452static tree branch_island_list = 0;
ee890fe2 15453
efdba735
SH
15454/* Remember to generate a branch island for far calls to the given
15455 function. */
ee890fe2 15456
efdba735
SH
15457static void
15458add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 15459{
efdba735
SH
15460 tree branch_island = build_tree_list (function_name, label_name);
15461 TREE_TYPE (branch_island) = build_int_2 (line_number, 0);
15462 TREE_CHAIN (branch_island) = branch_island_list;
15463 branch_island_list = branch_island;
ee890fe2
SS
15464}
15465
efdba735
SH
15466#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
15467#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
15468#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
15469 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 15470
efdba735
SH
15471/* Generate far-jump branch islands for everything on the
15472 branch_island_list. Invoked immediately after the last instruction
15473 of the epilogue has been emitted; the branch-islands must be
15474 appended to, and contiguous with, the function body. Mach-O stubs
15475 are generated in machopic_output_stub(). */
ee890fe2 15476
efdba735
SH
15477static void
15478macho_branch_islands (void)
15479{
15480 char tmp_buf[512];
15481 tree branch_island;
15482
15483 for (branch_island = branch_island_list;
15484 branch_island;
15485 branch_island = TREE_CHAIN (branch_island))
15486 {
15487 const char *label =
15488 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
15489 const char *name =
15490 darwin_strip_name_encoding (
15491 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)));
15492 char name_buf[512];
15493 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
15494 if (name[0] == '*' || name[0] == '&')
15495 strcpy (name_buf, name+1);
15496 else
15497 {
15498 name_buf[0] = '_';
15499 strcpy (name_buf+1, name);
15500 }
15501 strcpy (tmp_buf, "\n");
15502 strcat (tmp_buf, label);
ee890fe2 15503#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15504 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15505 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15506 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 15507#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
15508 if (flag_pic)
15509 {
15510 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
15511 strcat (tmp_buf, label);
15512 strcat (tmp_buf, "_pic\n");
15513 strcat (tmp_buf, label);
15514 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
15515
15516 strcat (tmp_buf, "\taddis r11,r11,ha16(");
15517 strcat (tmp_buf, name_buf);
15518 strcat (tmp_buf, " - ");
15519 strcat (tmp_buf, label);
15520 strcat (tmp_buf, "_pic)\n");
15521
15522 strcat (tmp_buf, "\tmtlr r0\n");
15523
15524 strcat (tmp_buf, "\taddi r12,r11,lo16(");
15525 strcat (tmp_buf, name_buf);
15526 strcat (tmp_buf, " - ");
15527 strcat (tmp_buf, label);
15528 strcat (tmp_buf, "_pic)\n");
15529
15530 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
15531 }
15532 else
15533 {
15534 strcat (tmp_buf, ":\nlis r12,hi16(");
15535 strcat (tmp_buf, name_buf);
15536 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
15537 strcat (tmp_buf, name_buf);
15538 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
15539 }
15540 output_asm_insn (tmp_buf, 0);
ee890fe2 15541#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15542 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15543 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15544 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 15545#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 15546 }
ee890fe2 15547
efdba735 15548 branch_island_list = 0;
ee890fe2
SS
15549}
15550
15551/* NO_PREVIOUS_DEF checks in the link list whether the function name is
15552 already there or not. */
15553
efdba735 15554static int
a2369ed3 15555no_previous_def (tree function_name)
ee890fe2 15556{
efdba735
SH
15557 tree branch_island;
15558 for (branch_island = branch_island_list;
15559 branch_island;
15560 branch_island = TREE_CHAIN (branch_island))
15561 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
15562 return 0;
15563 return 1;
15564}
15565
15566/* GET_PREV_LABEL gets the label name from the previous definition of
15567 the function. */
15568
efdba735 15569static tree
a2369ed3 15570get_prev_label (tree function_name)
ee890fe2 15571{
efdba735
SH
15572 tree branch_island;
15573 for (branch_island = branch_island_list;
15574 branch_island;
15575 branch_island = TREE_CHAIN (branch_island))
15576 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
15577 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
15578 return 0;
15579}
15580
15581/* INSN is either a function call or a millicode call. It may have an
15582 unconditional jump in its delay slot.
15583
15584 CALL_DEST is the routine we are calling. */
15585
15586char *
efdba735 15587output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
15588{
15589 static char buf[256];
efdba735
SH
15590 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
15591 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
15592 {
15593 tree labelname;
efdba735 15594 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
ee890fe2
SS
15595
15596 if (no_previous_def (funname))
15597 {
308c142a 15598 int line_number = 0;
ee890fe2
SS
15599 rtx label_rtx = gen_label_rtx ();
15600 char *label_buf, temp_buf[256];
15601 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
15602 CODE_LABEL_NUMBER (label_rtx));
15603 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
15604 labelname = get_identifier (label_buf);
15605 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
15606 if (insn)
15607 line_number = NOTE_LINE_NUMBER (insn);
efdba735 15608 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
15609 }
15610 else
15611 labelname = get_prev_label (funname);
15612
efdba735
SH
15613 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
15614 instruction will reach 'foo', otherwise link as 'bl L42'".
15615 "L42" should be a 'branch island', that will do a far jump to
15616 'foo'. Branch islands are generated in
15617 macho_branch_islands(). */
ee890fe2 15618 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 15619 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
15620 }
15621 else
efdba735
SH
15622 sprintf (buf, "bl %%z%d", dest_operand_number);
15623 return buf;
ee890fe2
SS
15624}
15625
efdba735 15626#endif /* TARGET_MACHO */
ee890fe2 15627
ee890fe2
SS
15628/* Generate PIC and indirect symbol stubs. */
15629
15630void
a2369ed3 15631machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
15632{
15633 unsigned int length;
a4f6c312
SS
15634 char *symbol_name, *lazy_ptr_name;
15635 char *local_label_0;
ee890fe2
SS
15636 static int label = 0;
15637
df56a27f 15638 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 15639 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 15640
ee890fe2 15641
ee890fe2
SS
15642 length = strlen (symb);
15643 symbol_name = alloca (length + 32);
15644 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
15645
15646 lazy_ptr_name = alloca (length + 32);
15647 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
15648
ee890fe2 15649 if (flag_pic == 2)
d3c300d2 15650 machopic_picsymbol_stub1_section ();
ee890fe2 15651 else
d3c300d2
DJ
15652 machopic_symbol_stub1_section ();
15653 fprintf (file, "\t.align 2\n");
ee890fe2
SS
15654
15655 fprintf (file, "%s:\n", stub);
15656 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15657
15658 if (flag_pic == 2)
15659 {
876455fa
AP
15660 label++;
15661 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
15662 sprintf (local_label_0, "\"L%011d$spb\"", label);
15663
ee890fe2
SS
15664 fprintf (file, "\tmflr r0\n");
15665 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
15666 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
15667 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
15668 lazy_ptr_name, local_label_0);
15669 fprintf (file, "\tmtlr r0\n");
d3c300d2 15670 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
15671 lazy_ptr_name, local_label_0);
15672 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
15673 fprintf (file, "\tbctr\n");
15674 }
15675 else
ab82a49f
AP
15676 {
15677 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
15678 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
15679 fprintf (file, "\tmtctr r12\n");
15680 fprintf (file, "\tbctr\n");
15681 }
ee890fe2
SS
15682
15683 machopic_lazy_symbol_ptr_section ();
15684 fprintf (file, "%s:\n", lazy_ptr_name);
15685 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15686 fprintf (file, "\t.long dyld_stub_binding_helper\n");
15687}
15688
15689/* Legitimize PIC addresses. If the address is already
15690 position-independent, we return ORIG. Newly generated
15691 position-independent addresses go into a reg. This is REG if non
15692 zero, otherwise we allocate register(s) as necessary. */
15693
c859cda6 15694#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
15695
15696rtx
a2369ed3
DJ
15697rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
15698 rtx reg)
ee890fe2
SS
15699{
15700 rtx base, offset;
15701
15702 if (reg == NULL && ! reload_in_progress && ! reload_completed)
15703 reg = gen_reg_rtx (Pmode);
15704
15705 if (GET_CODE (orig) == CONST)
15706 {
15707 if (GET_CODE (XEXP (orig, 0)) == PLUS
15708 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
15709 return orig;
15710
15711 if (GET_CODE (XEXP (orig, 0)) == PLUS)
15712 {
2cf520bf 15713 /* Use a different reg for the intermediate value, as
a3c9585f 15714 it will be marked UNCHANGING. */
2cf520bf
GK
15715 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
15716
a4f6c312
SS
15717 base =
15718 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 15719 Pmode, reg_temp);
a4f6c312
SS
15720 offset =
15721 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
15722 Pmode, reg);
ee890fe2
SS
15723 }
15724 else
15725 abort ();
15726
15727 if (GET_CODE (offset) == CONST_INT)
15728 {
15729 if (SMALL_INT (offset))
ed8908e7 15730 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
15731 else if (! reload_in_progress && ! reload_completed)
15732 offset = force_reg (Pmode, offset);
15733 else
c859cda6
DJ
15734 {
15735 rtx mem = force_const_mem (Pmode, orig);
15736 return machopic_legitimize_pic_address (mem, Pmode, reg);
15737 }
ee890fe2 15738 }
f1c25d3b 15739 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
15740 }
15741
15742 /* Fall back on generic machopic code. */
15743 return machopic_legitimize_pic_address (orig, mode, reg);
15744}
15745
15746/* This is just a placeholder to make linking work without having to
15747 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
15748 ever needed for Darwin (not too likely!) this would have to get a
15749 real definition. */
15750
15751void
863d938c 15752toc_section (void)
ee890fe2
SS
15753{
15754}
15755
15756#endif /* TARGET_MACHO */
7c262518
RH
15757
15758#if TARGET_ELF
15759static unsigned int
a2369ed3 15760rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 15761{
1ff8f81a
AM
15762 return default_section_type_flags_1 (decl, name, reloc,
15763 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 15764}
d9f6800d
RH
15765
15766/* Record an element in the table of global constructors. SYMBOL is
15767 a SYMBOL_REF of the function to be called; PRIORITY is a number
15768 between 0 and MAX_INIT_PRIORITY.
15769
15770 This differs from default_named_section_asm_out_constructor in
15771 that we have special handling for -mrelocatable. */
15772
15773static void
a2369ed3 15774rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
15775{
15776 const char *section = ".ctors";
15777 char buf[16];
15778
15779 if (priority != DEFAULT_INIT_PRIORITY)
15780 {
15781 sprintf (buf, ".ctors.%.5u",
15782 /* Invert the numbering so the linker puts us in the proper
15783 order; constructors are run from right to left, and the
15784 linker sorts in increasing order. */
15785 MAX_INIT_PRIORITY - priority);
15786 section = buf;
15787 }
15788
715bdd29
RH
15789 named_section_flags (section, SECTION_WRITE);
15790 assemble_align (POINTER_SIZE);
d9f6800d
RH
15791
15792 if (TARGET_RELOCATABLE)
15793 {
15794 fputs ("\t.long (", asm_out_file);
15795 output_addr_const (asm_out_file, symbol);
15796 fputs (")@fixup\n", asm_out_file);
15797 }
15798 else
c8af3574 15799 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
15800}
15801
15802static void
a2369ed3 15803rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
15804{
15805 const char *section = ".dtors";
15806 char buf[16];
15807
15808 if (priority != DEFAULT_INIT_PRIORITY)
15809 {
15810 sprintf (buf, ".dtors.%.5u",
15811 /* Invert the numbering so the linker puts us in the proper
15812 order; constructors are run from right to left, and the
15813 linker sorts in increasing order. */
15814 MAX_INIT_PRIORITY - priority);
15815 section = buf;
15816 }
15817
715bdd29
RH
15818 named_section_flags (section, SECTION_WRITE);
15819 assemble_align (POINTER_SIZE);
d9f6800d
RH
15820
15821 if (TARGET_RELOCATABLE)
15822 {
15823 fputs ("\t.long (", asm_out_file);
15824 output_addr_const (asm_out_file, symbol);
15825 fputs (")@fixup\n", asm_out_file);
15826 }
15827 else
c8af3574 15828 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 15829}
9739c90c
JJ
15830
15831void
a2369ed3 15832rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
15833{
15834 if (TARGET_64BIT)
15835 {
15836 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
15837 ASM_OUTPUT_LABEL (file, name);
15838 fputs (DOUBLE_INT_ASM_OP, file);
15839 putc ('.', file);
15840 assemble_name (file, name);
15841 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
15842 assemble_name (file, name);
15843 fputs (",24\n\t.type\t.", file);
15844 assemble_name (file, name);
15845 fputs (",@function\n", file);
15846 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
15847 {
15848 fputs ("\t.globl\t.", file);
15849 assemble_name (file, name);
15850 putc ('\n', file);
15851 }
15852 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15853 putc ('.', file);
15854 ASM_OUTPUT_LABEL (file, name);
15855 return;
15856 }
15857
15858 if (TARGET_RELOCATABLE
15859 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 15860 && uses_TOC ())
9739c90c
JJ
15861 {
15862 char buf[256];
15863
15864 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
15865
15866 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
15867 fprintf (file, "\t.long ");
15868 assemble_name (file, buf);
15869 putc ('-', file);
15870 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
15871 assemble_name (file, buf);
15872 putc ('\n', file);
15873 }
15874
15875 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
15876 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15877
15878 if (DEFAULT_ABI == ABI_AIX)
15879 {
15880 const char *desc_name, *orig_name;
15881
15882 orig_name = (*targetm.strip_name_encoding) (name);
15883 desc_name = orig_name;
15884 while (*desc_name == '.')
15885 desc_name++;
15886
15887 if (TREE_PUBLIC (decl))
15888 fprintf (file, "\t.globl %s\n", desc_name);
15889
15890 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
15891 fprintf (file, "%s:\n", desc_name);
15892 fprintf (file, "\t.long %s\n", orig_name);
15893 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
15894 if (DEFAULT_ABI == ABI_AIX)
15895 fputs ("\t.long 0\n", file);
15896 fprintf (file, "\t.previous\n");
15897 }
15898 ASM_OUTPUT_LABEL (file, name);
15899}
7c262518
RH
15900#endif
15901
cbaaba19 15902#if TARGET_XCOFF
7c262518 15903static void
a2369ed3 15904rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
15905{
15906 fputs (GLOBAL_ASM_OP, stream);
15907 RS6000_OUTPUT_BASENAME (stream, name);
15908 putc ('\n', stream);
15909}
15910
15911static void
a2369ed3 15912rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 15913{
0e5dbd9b
DE
15914 int smclass;
15915 static const char * const suffix[3] = { "PR", "RO", "RW" };
15916
15917 if (flags & SECTION_CODE)
15918 smclass = 0;
15919 else if (flags & SECTION_WRITE)
15920 smclass = 2;
15921 else
15922 smclass = 1;
15923
5b5198f7 15924 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 15925 (flags & SECTION_CODE) ? "." : "",
5b5198f7 15926 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 15927}
ae46c4e0
RH
15928
15929static void
a2369ed3
DJ
15930rs6000_xcoff_select_section (tree decl, int reloc,
15931 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 15932{
5add3202 15933 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 15934 {
0e5dbd9b 15935 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15936 read_only_data_section ();
15937 else
15938 read_only_private_data_section ();
15939 }
15940 else
15941 {
0e5dbd9b 15942 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15943 data_section ();
15944 else
15945 private_data_section ();
15946 }
15947}
15948
15949static void
a2369ed3 15950rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
15951{
15952 const char *name;
ae46c4e0 15953
5b5198f7
DE
15954 /* Use select_section for private and uninitialized data. */
15955 if (!TREE_PUBLIC (decl)
15956 || DECL_COMMON (decl)
0e5dbd9b
DE
15957 || DECL_INITIAL (decl) == NULL_TREE
15958 || DECL_INITIAL (decl) == error_mark_node
15959 || (flag_zero_initialized_in_bss
15960 && initializer_zerop (DECL_INITIAL (decl))))
15961 return;
15962
15963 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15964 name = (*targetm.strip_name_encoding) (name);
15965 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 15966}
b64a1b53 15967
fb49053f
RH
15968/* Select section for constant in constant pool.
15969
15970 On RS/6000, all constants are in the private read-only data area.
15971 However, if this is being placed in the TOC it must be output as a
15972 toc entry. */
15973
b64a1b53 15974static void
a2369ed3
DJ
15975rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
15976 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
15977{
15978 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
15979 toc_section ();
15980 else
15981 read_only_private_data_section ();
15982}
772c5265
RH
15983
15984/* Remove any trailing [DS] or the like from the symbol name. */
15985
15986static const char *
a2369ed3 15987rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
15988{
15989 size_t len;
15990 if (*name == '*')
15991 name++;
15992 len = strlen (name);
15993 if (name[len - 1] == ']')
15994 return ggc_alloc_string (name, len - 4);
15995 else
15996 return name;
15997}
15998
5add3202
DE
15999/* Section attributes. AIX is always PIC. */
16000
16001static unsigned int
a2369ed3 16002rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 16003{
5b5198f7
DE
16004 unsigned int align;
16005 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
16006
16007 /* Align to at least UNIT size. */
16008 if (flags & SECTION_CODE)
16009 align = MIN_UNITS_PER_WORD;
16010 else
16011 /* Increase alignment of large objects if not already stricter. */
16012 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
16013 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
16014 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
16015
16016 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 16017}
a5fe455b 16018
1bc7c5b6
ZW
16019/* Output at beginning of assembler file.
16020
16021 Initialize the section names for the RS/6000 at this point.
16022
16023 Specify filename, including full path, to assembler.
16024
16025 We want to go into the TOC section so at least one .toc will be emitted.
16026 Also, in order to output proper .bs/.es pairs, we need at least one static
16027 [RW] section emitted.
16028
16029 Finally, declare mcount when profiling to make the assembler happy. */
16030
16031static void
863d938c 16032rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
16033{
16034 rs6000_gen_section_name (&xcoff_bss_section_name,
16035 main_input_filename, ".bss_");
16036 rs6000_gen_section_name (&xcoff_private_data_section_name,
16037 main_input_filename, ".rw_");
16038 rs6000_gen_section_name (&xcoff_read_only_section_name,
16039 main_input_filename, ".ro_");
16040
16041 fputs ("\t.file\t", asm_out_file);
16042 output_quoted_string (asm_out_file, main_input_filename);
16043 fputc ('\n', asm_out_file);
16044 toc_section ();
16045 if (write_symbols != NO_DEBUG)
16046 private_data_section ();
16047 text_section ();
16048 if (profile_flag)
16049 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
16050 rs6000_file_start ();
16051}
16052
a5fe455b
ZW
16053/* Output at end of assembler file.
16054 On the RS/6000, referencing data should automatically pull in text. */
16055
16056static void
863d938c 16057rs6000_xcoff_file_end (void)
a5fe455b
ZW
16058{
16059 text_section ();
16060 fputs ("_section_.text:\n", asm_out_file);
16061 data_section ();
16062 fputs (TARGET_32BIT
16063 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
16064 asm_out_file);
16065}
f1384257 16066#endif /* TARGET_XCOFF */
0e5dbd9b 16067
f1384257
AM
16068#if TARGET_MACHO
16069/* Cross-module name binding. Darwin does not support overriding
7f3d8013 16070 functions at dynamic-link time. */
0e5dbd9b 16071
2bcc50d0 16072static bool
a2369ed3 16073rs6000_binds_local_p (tree decl)
0e5dbd9b 16074{
f1384257 16075 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 16076}
f1384257 16077#endif
34bb030a 16078
3c50106f
RH
16079/* Compute a (partial) cost for rtx X. Return true if the complete
16080 cost has been computed, and false if subexpressions should be
16081 scanned. In either case, *TOTAL contains the cost result. */
16082
16083static bool
a2369ed3
DJ
16084rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
16085 int *total)
3c50106f
RH
16086{
16087 switch (code)
16088 {
16089 /* On the RS/6000, if it is valid in the insn, it is free.
16090 So this always returns 0. */
16091 case CONST_INT:
16092 case CONST:
16093 case LABEL_REF:
16094 case SYMBOL_REF:
16095 case CONST_DOUBLE:
16096 case HIGH:
16097 *total = 0;
16098 return true;
16099
16100 case PLUS:
16101 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
16102 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
16103 + 0x8000) >= 0x10000)
16104 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
16105 ? COSTS_N_INSNS (2)
16106 : COSTS_N_INSNS (1));
16107 return true;
16108
16109 case AND:
16110 case IOR:
16111 case XOR:
16112 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
16113 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
16114 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
16115 ? COSTS_N_INSNS (2)
16116 : COSTS_N_INSNS (1));
16117 return true;
16118
16119 case MULT:
16120 if (optimize_size)
16121 {
16122 *total = COSTS_N_INSNS (2);
16123 return true;
16124 }
16125 switch (rs6000_cpu)
16126 {
16127 case PROCESSOR_RIOS1:
16128 case PROCESSOR_PPC405:
16129 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16130 ? COSTS_N_INSNS (5)
16131 : (INTVAL (XEXP (x, 1)) >= -256
16132 && INTVAL (XEXP (x, 1)) <= 255)
16133 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
16134 return true;
16135
02ca7595
DE
16136 case PROCESSOR_PPC440:
16137 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16138 ? COSTS_N_INSNS (3)
16139 : COSTS_N_INSNS (2));
16140 return true;
16141
3c50106f
RH
16142 case PROCESSOR_RS64A:
16143 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16144 ? GET_MODE (XEXP (x, 1)) != DImode
16145 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
16146 : (INTVAL (XEXP (x, 1)) >= -256
16147 && INTVAL (XEXP (x, 1)) <= 255)
16148 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
16149 return true;
16150
16151 case PROCESSOR_RIOS2:
16152 case PROCESSOR_MPCCORE:
16153 case PROCESSOR_PPC604e:
16154 *total = COSTS_N_INSNS (2);
16155 return true;
16156
16157 case PROCESSOR_PPC601:
16158 *total = COSTS_N_INSNS (5);
16159 return true;
16160
16161 case PROCESSOR_PPC603:
16162 case PROCESSOR_PPC7400:
16163 case PROCESSOR_PPC750:
16164 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16165 ? COSTS_N_INSNS (5)
16166 : (INTVAL (XEXP (x, 1)) >= -256
16167 && INTVAL (XEXP (x, 1)) <= 255)
16168 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
16169 return true;
16170
16171 case PROCESSOR_PPC7450:
16172 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16173 ? COSTS_N_INSNS (4)
16174 : COSTS_N_INSNS (3));
16175 return true;
16176
16177 case PROCESSOR_PPC403:
16178 case PROCESSOR_PPC604:
16179 case PROCESSOR_PPC8540:
16180 *total = COSTS_N_INSNS (4);
16181 return true;
16182
16183 case PROCESSOR_PPC620:
16184 case PROCESSOR_PPC630:
3c50106f
RH
16185 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16186 ? GET_MODE (XEXP (x, 1)) != DImode
16187 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
16188 : (INTVAL (XEXP (x, 1)) >= -256
16189 && INTVAL (XEXP (x, 1)) <= 255)
16190 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
16191 return true;
16192
9259f3b0 16193 case PROCESSOR_POWER4:
ec507f2d 16194 case PROCESSOR_POWER5:
9259f3b0
DE
16195 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16196 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
16197 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
16198 : COSTS_N_INSNS (2));
9259f3b0
DE
16199 return true;
16200
3c50106f
RH
16201 default:
16202 abort ();
16203 }
16204
16205 case DIV:
16206 case MOD:
16207 if (GET_CODE (XEXP (x, 1)) == CONST_INT
16208 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
16209 {
16210 *total = COSTS_N_INSNS (2);
16211 return true;
16212 }
5efb1046 16213 /* FALLTHRU */
3c50106f
RH
16214
16215 case UDIV:
16216 case UMOD:
16217 switch (rs6000_cpu)
16218 {
16219 case PROCESSOR_RIOS1:
16220 *total = COSTS_N_INSNS (19);
16221 return true;
16222
16223 case PROCESSOR_RIOS2:
16224 *total = COSTS_N_INSNS (13);
16225 return true;
16226
16227 case PROCESSOR_RS64A:
16228 *total = (GET_MODE (XEXP (x, 1)) != DImode
16229 ? COSTS_N_INSNS (65)
16230 : COSTS_N_INSNS (67));
16231 return true;
16232
16233 case PROCESSOR_MPCCORE:
16234 *total = COSTS_N_INSNS (6);
16235 return true;
16236
16237 case PROCESSOR_PPC403:
16238 *total = COSTS_N_INSNS (33);
16239 return true;
16240
16241 case PROCESSOR_PPC405:
16242 *total = COSTS_N_INSNS (35);
16243 return true;
16244
02ca7595
DE
16245 case PROCESSOR_PPC440:
16246 *total = COSTS_N_INSNS (34);
16247 return true;
16248
3c50106f
RH
16249 case PROCESSOR_PPC601:
16250 *total = COSTS_N_INSNS (36);
16251 return true;
16252
16253 case PROCESSOR_PPC603:
16254 *total = COSTS_N_INSNS (37);
16255 return true;
16256
16257 case PROCESSOR_PPC604:
16258 case PROCESSOR_PPC604e:
16259 *total = COSTS_N_INSNS (20);
16260 return true;
16261
16262 case PROCESSOR_PPC620:
16263 case PROCESSOR_PPC630:
3c50106f
RH
16264 *total = (GET_MODE (XEXP (x, 1)) != DImode
16265 ? COSTS_N_INSNS (21)
16266 : COSTS_N_INSNS (37));
16267 return true;
16268
16269 case PROCESSOR_PPC750:
16270 case PROCESSOR_PPC8540:
16271 case PROCESSOR_PPC7400:
16272 *total = COSTS_N_INSNS (19);
16273 return true;
16274
16275 case PROCESSOR_PPC7450:
16276 *total = COSTS_N_INSNS (23);
16277 return true;
984e25ac
DE
16278
16279 case PROCESSOR_POWER4:
ec507f2d 16280 case PROCESSOR_POWER5:
984e25ac
DE
16281 *total = (GET_MODE (XEXP (x, 1)) != DImode
16282 ? COSTS_N_INSNS (18)
16283 : COSTS_N_INSNS (34));
16284 return true;
3c50106f
RH
16285
16286 default:
16287 abort ();
16288 }
16289
16290 case FFS:
16291 *total = COSTS_N_INSNS (4);
16292 return true;
16293
16294 case MEM:
a3c9585f 16295 /* MEM should be slightly more expensive than (plus (reg) (const)). */
3c50106f
RH
16296 *total = 5;
16297 return true;
16298
16299 default:
16300 return false;
16301 }
16302}
16303
34bb030a
DE
16304/* A C expression returning the cost of moving data from a register of class
16305 CLASS1 to one of CLASS2. */
16306
16307int
a2369ed3
DJ
16308rs6000_register_move_cost (enum machine_mode mode,
16309 enum reg_class from, enum reg_class to)
34bb030a
DE
16310{
16311 /* Moves from/to GENERAL_REGS. */
16312 if (reg_classes_intersect_p (to, GENERAL_REGS)
16313 || reg_classes_intersect_p (from, GENERAL_REGS))
16314 {
16315 if (! reg_classes_intersect_p (to, GENERAL_REGS))
16316 from = to;
16317
16318 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
16319 return (rs6000_memory_move_cost (mode, from, 0)
16320 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
16321
a3c9585f 16322/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
16323 else if (from == CR_REGS)
16324 return 4;
16325
16326 else
16327/* A move will cost one instruction per GPR moved. */
16328 return 2 * HARD_REGNO_NREGS (0, mode);
16329 }
16330
16331/* Moving between two similar registers is just one instruction. */
16332 else if (reg_classes_intersect_p (to, from))
16333 return mode == TFmode ? 4 : 2;
16334
16335/* Everything else has to go through GENERAL_REGS. */
16336 else
16337 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
16338 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
16339}
16340
16341/* A C expressions returning the cost of moving data of MODE from a register to
16342 or from memory. */
16343
16344int
a2369ed3
DJ
16345rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
16346 int in ATTRIBUTE_UNUSED)
34bb030a
DE
16347{
16348 if (reg_classes_intersect_p (class, GENERAL_REGS))
16349 return 4 * HARD_REGNO_NREGS (0, mode);
16350 else if (reg_classes_intersect_p (class, FLOAT_REGS))
16351 return 4 * HARD_REGNO_NREGS (32, mode);
16352 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
16353 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
16354 else
16355 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
16356}
16357
ded9bf77
AH
16358/* Return an RTX representing where to find the function value of a
16359 function returning MODE. */
16360static rtx
16361rs6000_complex_function_value (enum machine_mode mode)
16362{
16363 unsigned int regno;
16364 rtx r1, r2;
16365 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 16366 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77 16367
4ed78545 16368 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
ded9bf77
AH
16369 regno = FP_ARG_RETURN;
16370 else
16371 {
16372 regno = GP_ARG_RETURN;
16373
16374 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 16375 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
16376 return gen_rtx_REG (mode, regno);
16377 }
16378
fb7e4164
AM
16379 if (inner_bytes >= 8)
16380 return gen_rtx_REG (mode, regno);
16381
ded9bf77
AH
16382 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
16383 const0_rtx);
16384 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 16385 GEN_INT (inner_bytes));
ded9bf77
AH
16386 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
16387}
16388
a6ebc39a
AH
16389/* Define how to find the value returned by a function.
16390 VALTYPE is the data type of the value (as a tree).
16391 If the precise function being called is known, FUNC is its FUNCTION_DECL;
16392 otherwise, FUNC is 0.
16393
16394 On the SPE, both FPs and vectors are returned in r3.
16395
16396 On RS/6000 an integer value is in r3 and a floating-point value is in
16397 fp1, unless -msoft-float. */
16398
16399rtx
16400rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
16401{
16402 enum machine_mode mode;
2a8fa26c 16403 unsigned int regno;
a6ebc39a 16404
0e67400a
FJ
16405 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
16406 {
16407 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
16408 return gen_rtx_PARALLEL (DImode,
16409 gen_rtvec (2,
16410 gen_rtx_EXPR_LIST (VOIDmode,
16411 gen_rtx_REG (SImode, GP_ARG_RETURN),
16412 const0_rtx),
16413 gen_rtx_EXPR_LIST (VOIDmode,
16414 gen_rtx_REG (SImode,
16415 GP_ARG_RETURN + 1),
16416 GEN_INT (4))));
16417 }
16418
a6ebc39a
AH
16419 if ((INTEGRAL_TYPE_P (valtype)
16420 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
16421 || POINTER_TYPE_P (valtype))
b78d48dd 16422 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
16423 else
16424 mode = TYPE_MODE (valtype);
16425
4ed78545 16426 if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS)
2a8fa26c 16427 regno = FP_ARG_RETURN;
ded9bf77 16428 else if (TREE_CODE (valtype) == COMPLEX_TYPE
42ba5130 16429 && targetm.calls.split_complex_arg)
ded9bf77 16430 return rs6000_complex_function_value (mode);
44688022
AM
16431 else if (TREE_CODE (valtype) == VECTOR_TYPE
16432 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
a6ebc39a
AH
16433 regno = ALTIVEC_ARG_RETURN;
16434 else
16435 regno = GP_ARG_RETURN;
16436
16437 return gen_rtx_REG (mode, regno);
16438}
16439
ded9bf77
AH
16440/* Define how to find the value returned by a library function
16441 assuming the value has mode MODE. */
16442rtx
16443rs6000_libcall_value (enum machine_mode mode)
16444{
16445 unsigned int regno;
16446
16447 if (GET_MODE_CLASS (mode) == MODE_FLOAT
16448 && TARGET_HARD_FLOAT && TARGET_FPRS)
16449 regno = FP_ARG_RETURN;
44688022
AM
16450 else if (ALTIVEC_VECTOR_MODE (mode)
16451 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
ded9bf77 16452 regno = ALTIVEC_ARG_RETURN;
42ba5130 16453 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
16454 return rs6000_complex_function_value (mode);
16455 else
16456 regno = GP_ARG_RETURN;
16457
16458 return gen_rtx_REG (mode, regno);
16459}
16460
d1d0c603
JJ
16461/* Define the offset between two registers, FROM to be eliminated and its
16462 replacement TO, at the start of a routine. */
16463HOST_WIDE_INT
16464rs6000_initial_elimination_offset (int from, int to)
16465{
16466 rs6000_stack_t *info = rs6000_stack_info ();
16467 HOST_WIDE_INT offset;
16468
16469 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16470 offset = info->push_p ? 0 : -info->total_size;
16471 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
16472 offset = info->total_size;
16473 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16474 offset = info->push_p ? info->total_size : 0;
16475 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
16476 offset = 0;
16477 else
16478 abort ();
16479
16480 return offset;
16481}
16482
62e1dfcf
NC
16483/* Return true if TYPE is of type __ev64_opaque__. */
16484
c8e4f0e9 16485static bool
a2369ed3 16486is_ev64_opaque_type (tree type)
62e1dfcf 16487{
c8e4f0e9 16488 return (TARGET_SPE
2abe3e28
AH
16489 && (type == opaque_V2SI_type_node
16490 || type == opaque_V2SF_type_node
36252949 16491 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
16492}
16493
96714395 16494static rtx
a2369ed3 16495rs6000_dwarf_register_span (rtx reg)
96714395
AH
16496{
16497 unsigned regno;
16498
16499 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
16500 return NULL_RTX;
16501
16502 regno = REGNO (reg);
16503
16504 /* The duality of the SPE register size wreaks all kinds of havoc.
16505 This is a way of distinguishing r0 in 32-bits from r0 in
16506 64-bits. */
16507 return
16508 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
16509 BYTES_BIG_ENDIAN
16510 ? gen_rtvec (2,
16511 gen_rtx_REG (SImode, regno + 1200),
16512 gen_rtx_REG (SImode, regno))
16513 : gen_rtvec (2,
16514 gen_rtx_REG (SImode, regno),
16515 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
16516}
16517
93c9d1ba
AM
16518/* Map internal gcc register numbers to DWARF2 register numbers. */
16519
16520unsigned int
16521rs6000_dbx_register_number (unsigned int regno)
16522{
16523 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
16524 return regno;
16525 if (regno == MQ_REGNO)
16526 return 100;
16527 if (regno == LINK_REGISTER_REGNUM)
16528 return 108;
16529 if (regno == COUNT_REGISTER_REGNUM)
16530 return 109;
16531 if (CR_REGNO_P (regno))
16532 return regno - CR0_REGNO + 86;
16533 if (regno == XER_REGNO)
16534 return 101;
16535 if (ALTIVEC_REGNO_P (regno))
16536 return regno - FIRST_ALTIVEC_REGNO + 1124;
16537 if (regno == VRSAVE_REGNO)
16538 return 356;
16539 if (regno == VSCR_REGNO)
16540 return 67;
16541 if (regno == SPE_ACC_REGNO)
16542 return 99;
16543 if (regno == SPEFSCR_REGNO)
16544 return 612;
16545 /* SPE high reg number. We get these values of regno from
16546 rs6000_dwarf_register_span. */
16547 if (regno >= 1200 && regno < 1232)
16548 return regno;
16549
16550 abort ();
16551}
16552
17211ab5 16553#include "gt-rs6000.h"