]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
2004-05-11 Michael Koch <konqueror@gmx.de>
[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
34792e82 2422 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 2423 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
2424 return 1;
2425
eb4e8003
RK
2426 /* For floating-point, easy constants are valid. */
2427 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2428 && CONSTANT_P (op)
2429 && easy_fp_constant (op, mode))
2430 return 1;
2431
4e74d8ec
MM
2432 /* Allow any integer constant. */
2433 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2434 && (GET_CODE (op) == CONST_INT
e675f625 2435 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2436 return 1;
2437
d744e06e
AH
2438 /* Allow easy vector constants. */
2439 if (GET_CODE (op) == CONST_VECTOR
2440 && easy_vector_constant (op, mode))
2441 return 1;
2442
eb4e8003
RK
2443 /* For floating-point or multi-word mode, the only remaining valid type
2444 is a register. */
9878760c
RK
2445 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2446 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2447 return register_operand (op, mode);
9878760c 2448
88fe15a1
RK
2449 /* The only cases left are integral modes one word or smaller (we
2450 do not get called for MODE_CC values). These can be in any
2451 register. */
2452 if (register_operand (op, mode))
a8b3aeda 2453 return 1;
88fe15a1 2454
84cf9dda 2455 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2456 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2457 return 1;
2458
9ebbca7d 2459 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2460 if (toc_relative_expr_p (op))
b6c9286a
MM
2461 return 1;
2462
88228c4b
MM
2463 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2464 to be valid. */
f607bc57 2465 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2466 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2467 && small_data_operand (op, Pmode))
2468 return 1;
2469
042259f2 2470 return 0;
9878760c 2471}
7509c759 2472
95727fb8
AP
2473
2474/* Darwin, AIX increases natural record alignment to doubleword if the first
2475 field is an FP double while the FP fields remain word aligned. */
2476
19d66194 2477unsigned int
95727fb8
AP
2478rs6000_special_round_type_align (tree type, int computed, int specified)
2479{
2480 tree field = TYPE_FIELDS (type);
95727fb8
AP
2481
2482 /* Skip all the static variables only if ABI is greater than
71cc389b 2483 1 or equal to 0. */
3ce5437a 2484 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2485 field = TREE_CHAIN (field);
2486
3ce5437a 2487 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2488 return MAX (computed, specified);
2489
2490 return MAX (MAX (computed, specified), 64);
2491}
2492
a4f6c312 2493/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2494
2495int
a2369ed3
DJ
2496small_data_operand (rtx op ATTRIBUTE_UNUSED,
2497 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2498{
38c1f2d7 2499#if TARGET_ELF
5f59ecb7 2500 rtx sym_ref;
7509c759 2501
d9407988 2502 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2503 return 0;
a54d04b7 2504
f607bc57 2505 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2506 return 0;
2507
88228c4b
MM
2508 if (GET_CODE (op) == SYMBOL_REF)
2509 sym_ref = op;
2510
2511 else if (GET_CODE (op) != CONST
2512 || GET_CODE (XEXP (op, 0)) != PLUS
2513 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2514 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2515 return 0;
2516
88228c4b 2517 else
dbf55e53
MM
2518 {
2519 rtx sum = XEXP (op, 0);
2520 HOST_WIDE_INT summand;
2521
2522 /* We have to be careful here, because it is the referenced address
2523 that must be 32k from _SDA_BASE_, not just the symbol. */
2524 summand = INTVAL (XEXP (sum, 1));
307b599c 2525 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2526 return 0;
2527
2528 sym_ref = XEXP (sum, 0);
2529 }
88228c4b 2530
20bfcd69 2531 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2532#else
2533 return 0;
2534#endif
7509c759 2535}
46c07df8 2536
d2288d5d
HP
2537/* Return true, if operand is a memory operand and has a
2538 displacement divisible by 4. */
2539
2540int
2541word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2542{
2543 rtx addr;
2544 int off = 0;
2545
2546 if (!memory_operand (op, mode))
2547 return 0;
2548
2549 addr = XEXP (op, 0);
2550 if (GET_CODE (addr) == PLUS
2551 && GET_CODE (XEXP (addr, 0)) == REG
2552 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2553 off = INTVAL (XEXP (addr, 1));
2554
2555 return (off % 4) == 0;
2556}
2557
3a1f863f 2558/* Return true if either operand is a general purpose register. */
46c07df8 2559
3a1f863f
DE
2560bool
2561gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 2562{
3a1f863f
DE
2563 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2564 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
2565}
2566
9ebbca7d 2567\f
4d588c14
RH
2568/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2569
9ebbca7d 2570static int
a2369ed3 2571constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d
GK
2572{
2573 switch (GET_CODE(op))
2574 {
2575 case SYMBOL_REF:
c4501e62
JJ
2576 if (RS6000_SYMBOL_REF_TLS_P (op))
2577 return 0;
2578 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2579 {
2580 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2581 {
2582 *have_sym = 1;
2583 return 1;
2584 }
2585 else
2586 return 0;
2587 }
2588 else if (! strcmp (XSTR (op, 0), toc_label_name))
2589 {
2590 *have_toc = 1;
2591 return 1;
2592 }
2593 else
2594 return 0;
9ebbca7d
GK
2595 case PLUS:
2596 case MINUS:
c1f11548
DE
2597 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2598 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2599 case CONST:
a4f6c312 2600 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2601 case CONST_INT:
a4f6c312 2602 return 1;
9ebbca7d 2603 default:
a4f6c312 2604 return 0;
9ebbca7d
GK
2605 }
2606}
2607
4d588c14 2608static bool
a2369ed3 2609constant_pool_expr_p (rtx op)
9ebbca7d
GK
2610{
2611 int have_sym = 0;
2612 int have_toc = 0;
2613 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2614}
2615
4d588c14 2616static bool
a2369ed3 2617toc_relative_expr_p (rtx op)
9ebbca7d 2618{
4d588c14
RH
2619 int have_sym = 0;
2620 int have_toc = 0;
2621 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2622}
2623
2624/* SPE offset addressing is limited to 5-bits worth of double words. */
2625#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2626
2627bool
a2369ed3 2628legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
2629{
2630 return (TARGET_TOC
2631 && GET_CODE (x) == PLUS
2632 && GET_CODE (XEXP (x, 0)) == REG
2633 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2634 && constant_pool_expr_p (XEXP (x, 1)));
2635}
2636
2637static bool
a2369ed3 2638legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
2639{
2640 return (DEFAULT_ABI == ABI_V4
2641 && !flag_pic && !TARGET_TOC
2642 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2643 && small_data_operand (x, mode));
2644}
2645
2646static bool
a2369ed3 2647legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2648{
2649 unsigned HOST_WIDE_INT offset, extra;
2650
2651 if (GET_CODE (x) != PLUS)
2652 return false;
2653 if (GET_CODE (XEXP (x, 0)) != REG)
2654 return false;
2655 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2656 return false;
2657 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2658 return false;
2659
2660 offset = INTVAL (XEXP (x, 1));
2661 extra = 0;
2662 switch (mode)
2663 {
2664 case V16QImode:
2665 case V8HImode:
2666 case V4SFmode:
2667 case V4SImode:
2668 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2669 which leaves the only valid constant offset of zero, which by
2670 canonicalization rules is also invalid. */
2671 return false;
2672
2673 case V4HImode:
2674 case V2SImode:
2675 case V1DImode:
2676 case V2SFmode:
2677 /* SPE vector modes. */
2678 return SPE_CONST_OFFSET_OK (offset);
2679
2680 case DFmode:
2681 case DImode:
3364872d 2682 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
2683 extra = 4;
2684 else if (offset & 3)
2685 return false;
2686 break;
2687
2688 case TFmode:
2689 case TImode:
3364872d 2690 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
2691 extra = 12;
2692 else if (offset & 3)
2693 return false;
2694 else
2695 extra = 8;
2696 break;
2697
2698 default:
2699 break;
2700 }
2701
b1917422
AM
2702 offset += 0x8000;
2703 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
2704}
2705
2706static bool
a2369ed3 2707legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
2708{
2709 rtx op0, op1;
2710
2711 if (GET_CODE (x) != PLUS)
2712 return false;
2713 op0 = XEXP (x, 0);
2714 op1 = XEXP (x, 1);
2715
2716 if (!REG_P (op0) || !REG_P (op1))
2717 return false;
2718
2719 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2720 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2721 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2722 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2723}
2724
4d588c14 2725static inline bool
a2369ed3 2726legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
2727{
2728 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2729}
2730
4c81e946
FJ
2731static bool
2732macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
2733{
2734 if (!TARGET_MACHO || !flag_pic
2735 || mode != SImode || GET_CODE(x) != MEM)
2736 return false;
2737 x = XEXP (x, 0);
2738
2739 if (GET_CODE (x) != LO_SUM)
2740 return false;
2741 if (GET_CODE (XEXP (x, 0)) != REG)
2742 return false;
2743 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
2744 return false;
2745 x = XEXP (x, 1);
2746
2747 return CONSTANT_P (x);
2748}
2749
4d588c14 2750static bool
a2369ed3 2751legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2752{
2753 if (GET_CODE (x) != LO_SUM)
2754 return false;
2755 if (GET_CODE (XEXP (x, 0)) != REG)
2756 return false;
2757 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2758 return false;
2759 x = XEXP (x, 1);
2760
8622e235 2761 if (TARGET_ELF || TARGET_MACHO)
4d588c14 2762 {
a29077da 2763 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
2764 return false;
2765 if (TARGET_TOC)
2766 return false;
2767 if (GET_MODE_NUNITS (mode) != 1)
2768 return false;
2769 if (GET_MODE_BITSIZE (mode) > 32
2770 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2771 return false;
2772
2773 return CONSTANT_P (x);
2774 }
2775
2776 return false;
2777}
2778
2779
9ebbca7d
GK
2780/* Try machine-dependent ways of modifying an illegitimate address
2781 to be legitimate. If we find one, return the new, valid address.
2782 This is used from only one place: `memory_address' in explow.c.
2783
a4f6c312
SS
2784 OLDX is the address as it was before break_out_memory_refs was
2785 called. In some cases it is useful to look at this to decide what
2786 needs to be done.
9ebbca7d 2787
a4f6c312 2788 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2789
a4f6c312
SS
2790 It is always safe for this function to do nothing. It exists to
2791 recognize opportunities to optimize the output.
9ebbca7d
GK
2792
2793 On RS/6000, first check for the sum of a register with a constant
2794 integer that is out of range. If so, generate code to add the
2795 constant with the low-order 16 bits masked to the register and force
2796 this result into another register (this can be done with `cau').
2797 Then generate an address of REG+(CONST&0xffff), allowing for the
2798 possibility of bit 16 being a one.
2799
2800 Then check for the sum of a register and something not constant, try to
2801 load the other things into a register and return the sum. */
4d588c14 2802
9ebbca7d 2803rtx
a2369ed3
DJ
2804rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2805 enum machine_mode mode)
0ac081f6 2806{
c4501e62
JJ
2807 if (GET_CODE (x) == SYMBOL_REF)
2808 {
2809 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2810 if (model != 0)
2811 return rs6000_legitimize_tls_address (x, model);
2812 }
2813
9ebbca7d
GK
2814 if (GET_CODE (x) == PLUS
2815 && GET_CODE (XEXP (x, 0)) == REG
2816 && GET_CODE (XEXP (x, 1)) == CONST_INT
2817 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2818 {
2819 HOST_WIDE_INT high_int, low_int;
2820 rtx sum;
a65c591c
DE
2821 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2822 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2823 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2824 GEN_INT (high_int)), 0);
2825 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2826 }
2827 else if (GET_CODE (x) == PLUS
2828 && GET_CODE (XEXP (x, 0)) == REG
2829 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2830 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2831 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2832 || TARGET_POWERPC64
fcce224d 2833 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2834 && (TARGET_POWERPC64 || mode != DImode)
2835 && mode != TImode)
2836 {
2837 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2838 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2839 }
0ac081f6
AH
2840 else if (ALTIVEC_VECTOR_MODE (mode))
2841 {
2842 rtx reg;
2843
2844 /* Make sure both operands are registers. */
2845 if (GET_CODE (x) == PLUS)
9f85ed45 2846 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2847 force_reg (Pmode, XEXP (x, 1)));
2848
2849 reg = force_reg (Pmode, x);
2850 return reg;
2851 }
a3170dc6
AH
2852 else if (SPE_VECTOR_MODE (mode))
2853 {
2854 /* We accept [reg + reg] and [reg + OFFSET]. */
2855
2856 if (GET_CODE (x) == PLUS)
2857 {
2858 rtx op1 = XEXP (x, 0);
2859 rtx op2 = XEXP (x, 1);
2860
2861 op1 = force_reg (Pmode, op1);
2862
2863 if (GET_CODE (op2) != REG
2864 && (GET_CODE (op2) != CONST_INT
2865 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2866 op2 = force_reg (Pmode, op2);
2867
2868 return gen_rtx_PLUS (Pmode, op1, op2);
2869 }
2870
2871 return force_reg (Pmode, x);
2872 }
f1384257
AM
2873 else if (TARGET_ELF
2874 && TARGET_32BIT
2875 && TARGET_NO_TOC
2876 && ! flag_pic
9ebbca7d
GK
2877 && GET_CODE (x) != CONST_INT
2878 && GET_CODE (x) != CONST_DOUBLE
2879 && CONSTANT_P (x)
6ac7bf2c
GK
2880 && GET_MODE_NUNITS (mode) == 1
2881 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2882 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2883 {
2884 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2885 emit_insn (gen_elf_high (reg, x));
2886 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 2887 }
ee890fe2
SS
2888 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2889 && ! flag_pic
ab82a49f
AP
2890#if TARGET_MACHO
2891 && ! MACHO_DYNAMIC_NO_PIC_P
2892#endif
ee890fe2
SS
2893 && GET_CODE (x) != CONST_INT
2894 && GET_CODE (x) != CONST_DOUBLE
2895 && CONSTANT_P (x)
a3170dc6 2896 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2897 && mode != DImode
2898 && mode != TImode)
2899 {
2900 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2901 emit_insn (gen_macho_high (reg, x));
2902 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 2903 }
9ebbca7d 2904 else if (TARGET_TOC
4d588c14 2905 && constant_pool_expr_p (x)
a9098fd0 2906 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2907 {
2908 return create_TOC_reference (x);
2909 }
2910 else
2911 return NULL_RTX;
2912}
258bfae2 2913
c973d557
JJ
2914/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
2915 We need to emit DTP-relative relocations. */
2916
2917void
2918rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
2919{
2920 switch (size)
2921 {
2922 case 4:
2923 fputs ("\t.long\t", file);
2924 break;
2925 case 8:
2926 fputs (DOUBLE_INT_ASM_OP, file);
2927 break;
2928 default:
2929 abort ();
2930 }
2931 output_addr_const (file, x);
2932 fputs ("@dtprel+0x8000", file);
2933}
2934
c4501e62
JJ
2935/* Construct the SYMBOL_REF for the tls_get_addr function. */
2936
2937static GTY(()) rtx rs6000_tls_symbol;
2938static rtx
863d938c 2939rs6000_tls_get_addr (void)
c4501e62
JJ
2940{
2941 if (!rs6000_tls_symbol)
2942 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2943
2944 return rs6000_tls_symbol;
2945}
2946
2947/* Construct the SYMBOL_REF for TLS GOT references. */
2948
2949static GTY(()) rtx rs6000_got_symbol;
2950static rtx
863d938c 2951rs6000_got_sym (void)
c4501e62
JJ
2952{
2953 if (!rs6000_got_symbol)
2954 {
2955 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2956 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2957 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2958 }
2959
2960 return rs6000_got_symbol;
2961}
2962
2963/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2964 this (thread-local) address. */
2965
2966static rtx
a2369ed3 2967rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
2968{
2969 rtx dest, insn;
2970
2971 dest = gen_reg_rtx (Pmode);
2972 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2973 {
2974 rtx tlsreg;
2975
2976 if (TARGET_64BIT)
2977 {
2978 tlsreg = gen_rtx_REG (Pmode, 13);
2979 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2980 }
2981 else
2982 {
2983 tlsreg = gen_rtx_REG (Pmode, 2);
2984 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2985 }
2986 emit_insn (insn);
2987 }
2988 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2989 {
2990 rtx tlsreg, tmp;
2991
2992 tmp = gen_reg_rtx (Pmode);
2993 if (TARGET_64BIT)
2994 {
2995 tlsreg = gen_rtx_REG (Pmode, 13);
2996 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2997 }
2998 else
2999 {
3000 tlsreg = gen_rtx_REG (Pmode, 2);
3001 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
3002 }
3003 emit_insn (insn);
3004 if (TARGET_64BIT)
3005 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
3006 else
3007 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
3008 emit_insn (insn);
3009 }
3010 else
3011 {
3012 rtx r3, got, tga, tmp1, tmp2, eqv;
3013
3014 if (TARGET_64BIT)
3015 got = gen_rtx_REG (Pmode, TOC_REGISTER);
3016 else
3017 {
3018 if (flag_pic == 1)
3019 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
3020 else
3021 {
3022 rtx gsym = rs6000_got_sym ();
3023 got = gen_reg_rtx (Pmode);
3024 if (flag_pic == 0)
3025 rs6000_emit_move (got, gsym, Pmode);
3026 else
3027 {
3028 char buf[30];
3029 static int tls_got_labelno = 0;
3030 rtx tempLR, lab, tmp3, mem;
3031 rtx first, last;
3032
3033 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
3034 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
3035 tempLR = gen_reg_rtx (Pmode);
3036 tmp1 = gen_reg_rtx (Pmode);
3037 tmp2 = gen_reg_rtx (Pmode);
3038 tmp3 = gen_reg_rtx (Pmode);
3039 mem = gen_rtx_MEM (Pmode, tmp1);
3040 RTX_UNCHANGING_P (mem) = 1;
3041
3042 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
3043 gsym));
3044 emit_move_insn (tmp1, tempLR);
3045 emit_move_insn (tmp2, mem);
3046 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
3047 last = emit_move_insn (got, tmp3);
3048 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
3049 REG_NOTES (last));
3050 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
3051 REG_NOTES (first));
3052 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
3053 REG_NOTES (last));
3054 }
3055 }
3056 }
3057
3058 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
3059 {
3060 r3 = gen_rtx_REG (Pmode, 3);
3061 if (TARGET_64BIT)
3062 insn = gen_tls_gd_64 (r3, got, addr);
3063 else
3064 insn = gen_tls_gd_32 (r3, got, addr);
3065 start_sequence ();
3066 emit_insn (insn);
3067 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3068 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3069 insn = emit_call_insn (insn);
3070 CONST_OR_PURE_CALL_P (insn) = 1;
3071 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3072 insn = get_insns ();
3073 end_sequence ();
3074 emit_libcall_block (insn, dest, r3, addr);
3075 }
3076 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
3077 {
3078 r3 = gen_rtx_REG (Pmode, 3);
3079 if (TARGET_64BIT)
3080 insn = gen_tls_ld_64 (r3, got);
3081 else
3082 insn = gen_tls_ld_32 (r3, got);
3083 start_sequence ();
3084 emit_insn (insn);
3085 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
3086 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
3087 insn = emit_call_insn (insn);
3088 CONST_OR_PURE_CALL_P (insn) = 1;
3089 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
3090 insn = get_insns ();
3091 end_sequence ();
3092 tmp1 = gen_reg_rtx (Pmode);
3093 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
3094 UNSPEC_TLSLD);
3095 emit_libcall_block (insn, tmp1, r3, eqv);
3096 if (rs6000_tls_size == 16)
3097 {
3098 if (TARGET_64BIT)
3099 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3100 else
3101 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3102 }
3103 else if (rs6000_tls_size == 32)
3104 {
3105 tmp2 = gen_reg_rtx (Pmode);
3106 if (TARGET_64BIT)
3107 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3108 else
3109 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3110 emit_insn (insn);
3111 if (TARGET_64BIT)
3112 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3113 else
3114 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3115 }
3116 else
3117 {
3118 tmp2 = gen_reg_rtx (Pmode);
3119 if (TARGET_64BIT)
3120 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3121 else
3122 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3123 emit_insn (insn);
3124 insn = gen_rtx_SET (Pmode, dest,
3125 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3126 }
3127 emit_insn (insn);
3128 }
3129 else
3130 {
3131 /* IE, or 64 bit offset LE. */
3132 tmp2 = gen_reg_rtx (Pmode);
3133 if (TARGET_64BIT)
3134 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3135 else
3136 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3137 emit_insn (insn);
3138 if (TARGET_64BIT)
3139 insn = gen_tls_tls_64 (dest, tmp2, addr);
3140 else
3141 insn = gen_tls_tls_32 (dest, tmp2, addr);
3142 emit_insn (insn);
3143 }
3144 }
3145
3146 return dest;
3147}
3148
3149/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3150 instruction definitions. */
3151
3152int
a2369ed3 3153rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3154{
3155 return RS6000_SYMBOL_REF_TLS_P (x);
3156}
3157
3158/* Return 1 if X contains a thread-local symbol. */
3159
3160bool
a2369ed3 3161rs6000_tls_referenced_p (rtx x)
c4501e62 3162{
cd413cab
AP
3163 if (! TARGET_HAVE_TLS)
3164 return false;
3165
c4501e62
JJ
3166 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3167}
3168
3169/* Return 1 if *X is a thread-local symbol. This is the same as
3170 rs6000_tls_symbol_ref except for the type of the unused argument. */
3171
3172static inline int
a2369ed3 3173rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3174{
3175 return RS6000_SYMBOL_REF_TLS_P (*x);
3176}
3177
24ea750e
DJ
3178/* The convention appears to be to define this wherever it is used.
3179 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3180 is now used here. */
3181#ifndef REG_MODE_OK_FOR_BASE_P
3182#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3183#endif
3184
3185/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3186 replace the input X, or the original X if no replacement is called for.
3187 The output parameter *WIN is 1 if the calling macro should goto WIN,
3188 0 if it should not.
3189
3190 For RS/6000, we wish to handle large displacements off a base
3191 register by splitting the addend across an addiu/addis and the mem insn.
3192 This cuts number of extra insns needed from 3 to 1.
3193
3194 On Darwin, we use this to generate code for floating point constants.
3195 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3196 The Darwin code is inside #if TARGET_MACHO because only then is
3197 machopic_function_base_name() defined. */
3198rtx
a2369ed3
DJ
3199rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
3200 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e
DJ
3201{
3202 /* We must recognize output that we have already generated ourselves. */
3203 if (GET_CODE (x) == PLUS
3204 && GET_CODE (XEXP (x, 0)) == PLUS
3205 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3206 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3207 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3208 {
3209 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3210 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3211 opnum, (enum reload_type)type);
3212 *win = 1;
3213 return x;
3214 }
3deb2758 3215
24ea750e
DJ
3216#if TARGET_MACHO
3217 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3218 && GET_CODE (x) == LO_SUM
3219 && GET_CODE (XEXP (x, 0)) == PLUS
3220 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3221 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3222 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3223 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3224 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3225 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3226 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3227 {
3228 /* Result of previous invocation of this function on Darwin
6f317ef3 3229 floating point constant. */
24ea750e
DJ
3230 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3231 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3232 opnum, (enum reload_type)type);
3233 *win = 1;
3234 return x;
3235 }
3236#endif
3237 if (GET_CODE (x) == PLUS
3238 && GET_CODE (XEXP (x, 0)) == REG
3239 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3240 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3241 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3242 && !SPE_VECTOR_MODE (mode)
78c875e8 3243 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3244 {
3245 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3246 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3247 HOST_WIDE_INT high
3248 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3249
3250 /* Check for 32-bit overflow. */
3251 if (high + low != val)
3252 {
3253 *win = 0;
3254 return x;
3255 }
3256
3257 /* Reload the high part into a base reg; leave the low part
3258 in the mem directly. */
3259
3260 x = gen_rtx_PLUS (GET_MODE (x),
3261 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3262 GEN_INT (high)),
3263 GEN_INT (low));
3264
3265 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3266 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3267 opnum, (enum reload_type)type);
3268 *win = 1;
3269 return x;
3270 }
3271#if TARGET_MACHO
3272 if (GET_CODE (x) == SYMBOL_REF
3273 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3274 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3275 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3276 /* Don't do this for TFmode, since the result isn't offsettable. */
3277 && mode != TFmode)
24ea750e 3278 {
a29077da
GK
3279 if (flag_pic)
3280 {
3281 rtx offset = gen_rtx_CONST (Pmode,
3282 gen_rtx_MINUS (Pmode, x,
3283 gen_rtx_SYMBOL_REF (Pmode,
3284 machopic_function_base_name ())));
3285 x = gen_rtx_LO_SUM (GET_MODE (x),
3286 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3287 gen_rtx_HIGH (Pmode, offset)), offset);
3288 }
3289 else
3290 x = gen_rtx_LO_SUM (GET_MODE (x),
3291 gen_rtx_HIGH (Pmode, x), x);
3292
24ea750e 3293 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3294 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3295 opnum, (enum reload_type)type);
24ea750e
DJ
3296 *win = 1;
3297 return x;
3298 }
3299#endif
3300 if (TARGET_TOC
4d588c14 3301 && constant_pool_expr_p (x)
c1f11548 3302 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3303 {
3304 (x) = create_TOC_reference (x);
3305 *win = 1;
3306 return x;
3307 }
3308 *win = 0;
3309 return x;
3310}
3311
258bfae2
FS
3312/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3313 that is a valid memory address for an instruction.
3314 The MODE argument is the machine mode for the MEM expression
3315 that wants to use this address.
3316
3317 On the RS/6000, there are four valid address: a SYMBOL_REF that
3318 refers to a constant pool entry of an address (or the sum of it
3319 plus a constant), a short (16-bit signed) constant plus a register,
3320 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3321 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3322 we must ensure that both words are addressable or PowerPC64 with offset
3323 word aligned.
3324
3325 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3326 32-bit DImode, TImode), indexed addressing cannot be used because
3327 adjacent memory cells are accessed by adding word-sized offsets
3328 during assembly output. */
3329int
a2369ed3 3330rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3331{
c4501e62
JJ
3332 if (RS6000_SYMBOL_REF_TLS_P (x))
3333 return 0;
4d588c14 3334 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3335 return 1;
3336 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3337 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3338 && !SPE_VECTOR_MODE (mode)
258bfae2 3339 && TARGET_UPDATE
4d588c14 3340 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3341 return 1;
4d588c14 3342 if (legitimate_small_data_p (mode, x))
258bfae2 3343 return 1;
4d588c14 3344 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3345 return 1;
3346 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3347 if (! reg_ok_strict
3348 && GET_CODE (x) == PLUS
3349 && GET_CODE (XEXP (x, 0)) == REG
708d2456
HP
3350 && (XEXP (x, 0) == virtual_stack_vars_rtx
3351 || XEXP (x, 0) == arg_pointer_rtx)
258bfae2
FS
3352 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3353 return 1;
4d588c14 3354 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3355 return 1;
3356 if (mode != TImode
a3170dc6
AH
3357 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3358 || TARGET_POWERPC64
fcce224d 3359 || (mode != DFmode && mode != TFmode))
258bfae2 3360 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3361 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3362 return 1;
4d588c14 3363 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3364 return 1;
3365 return 0;
3366}
4d588c14
RH
3367
3368/* Go to LABEL if ADDR (a legitimate address expression)
3369 has an effect that depends on the machine mode it is used for.
3370
3371 On the RS/6000 this is true of all integral offsets (since AltiVec
3372 modes don't allow them) or is a pre-increment or decrement.
3373
3374 ??? Except that due to conceptual problems in offsettable_address_p
3375 we can't really report the problems of integral offsets. So leave
3376 this assuming that the adjustable offset must be valid for the
3377 sub-words of a TFmode operand, which is what we had before. */
3378
3379bool
a2369ed3 3380rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3381{
3382 switch (GET_CODE (addr))
3383 {
3384 case PLUS:
3385 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3386 {
3387 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3388 return val + 12 + 0x8000 >= 0x10000;
3389 }
3390 break;
3391
3392 case LO_SUM:
3393 return true;
3394
3395 case PRE_INC:
3396 case PRE_DEC:
3397 return TARGET_UPDATE;
3398
3399 default:
3400 break;
3401 }
3402
3403 return false;
3404}
d8ecbcdb
AH
3405
3406/* Return number of consecutive hard regs needed starting at reg REGNO
3407 to hold something of mode MODE.
3408 This is ordinarily the length in words of a value of mode MODE
3409 but can be less for certain modes in special long registers.
3410
3411 For the SPE, GPRs are 64 bits but only 32 bits are visible in
3412 scalar instructions. The upper 32 bits are only available to the
3413 SIMD instructions.
3414
3415 POWER and PowerPC GPRs hold 32 bits worth;
3416 PowerPC64 GPRs and FPRs point register holds 64 bits worth. */
3417
3418int
3419rs6000_hard_regno_nregs (int regno, enum machine_mode mode)
3420{
3421 if (FP_REGNO_P (regno))
3422 return (GET_MODE_SIZE (mode) + UNITS_PER_FP_WORD - 1) / UNITS_PER_FP_WORD;
3423
3424 if (SPE_SIMD_REGNO_P (regno) && TARGET_SPE && SPE_VECTOR_MODE (mode))
3425 return (GET_MODE_SIZE (mode) + UNITS_PER_SPE_WORD - 1) / UNITS_PER_SPE_WORD;
3426
3427 if (ALTIVEC_REGNO_P (regno))
3428 return
3429 (GET_MODE_SIZE (mode) + UNITS_PER_ALTIVEC_WORD - 1) / UNITS_PER_ALTIVEC_WORD;
3430
3431 return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
3432}
2aa4498c
AH
3433
3434/* Change register usage conditional on target flags. */
3435void
3436rs6000_conditional_register_usage (void)
3437{
3438 int i;
3439
3440 /* Set MQ register fixed (already call_used) if not POWER
3441 architecture (RIOS1, RIOS2, RSC, and PPC601) so that it will not
3442 be allocated. */
3443 if (! TARGET_POWER)
3444 fixed_regs[64] = 1;
3445
3446 /* 64-bit AIX reserves GPR13 for thread-private data. */
3447 if (TARGET_64BIT)
3448 fixed_regs[13] = call_used_regs[13]
3449 = call_really_used_regs[13] = 1;
3450
3451 /* Conditionally disable FPRs. */
3452 if (TARGET_SOFT_FLOAT || !TARGET_FPRS)
3453 for (i = 32; i < 64; i++)
3454 fixed_regs[i] = call_used_regs[i]
3455 = call_really_used_regs[i] = 1;
3456
3457 if (DEFAULT_ABI == ABI_V4
3458 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3459 && flag_pic == 2)
3460 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3461
3462 if (DEFAULT_ABI == ABI_V4
3463 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM
3464 && flag_pic == 1)
3465 fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3466 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3467 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3468
3469 if (DEFAULT_ABI == ABI_DARWIN
3470 && PIC_OFFSET_TABLE_REGNUM != INVALID_REGNUM)
3471 global_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3472 = fixed_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3473 = call_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM]
3474 = call_really_used_regs[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
3475
3476 if (TARGET_ALTIVEC)
3477 global_regs[VSCR_REGNO] = 1;
3478
3479 if (TARGET_SPE)
3480 {
3481 global_regs[SPEFSCR_REGNO] = 1;
3482 fixed_regs[FIXED_SCRATCH]
3483 = call_used_regs[FIXED_SCRATCH]
3484 = call_really_used_regs[FIXED_SCRATCH] = 1;
3485 }
3486
3487 if (! TARGET_ALTIVEC)
3488 {
3489 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
3490 fixed_regs[i] = call_used_regs[i] = call_really_used_regs[i] = 1;
3491 call_really_used_regs[VRSAVE_REGNO] = 1;
3492 }
3493
3494 if (TARGET_ALTIVEC_ABI)
3495 for (i = FIRST_ALTIVEC_REGNO; i < FIRST_ALTIVEC_REGNO + 20; ++i)
3496 call_used_regs[i] = call_really_used_regs[i] = 1;
3497}
fb4d4348 3498\f
a4f6c312
SS
3499/* Try to output insns to set TARGET equal to the constant C if it can
3500 be done in less than N insns. Do all computations in MODE.
3501 Returns the place where the output has been placed if it can be
3502 done and the insns have been emitted. If it would take more than N
3503 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3504
3505rtx
a2369ed3
DJ
3506rs6000_emit_set_const (rtx dest, enum machine_mode mode,
3507 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3508{
af8cb5c5 3509 rtx result, insn, set;
2bfcf297
DB
3510 HOST_WIDE_INT c0, c1;
3511
af8cb5c5 3512 if (mode == QImode || mode == HImode)
2bfcf297
DB
3513 {
3514 if (dest == NULL)
3515 dest = gen_reg_rtx (mode);
3516 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3517 return dest;
3518 }
af8cb5c5 3519 else if (mode == SImode)
2bfcf297 3520 {
af8cb5c5
DE
3521 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3522
3523 emit_insn (gen_rtx_SET (VOIDmode, result,
3524 GEN_INT (INTVAL (source)
3525 & (~ (HOST_WIDE_INT) 0xffff))));
3526 emit_insn (gen_rtx_SET (VOIDmode, dest,
3527 gen_rtx_IOR (SImode, result,
3528 GEN_INT (INTVAL (source) & 0xffff))));
3529 result = dest;
2bfcf297 3530 }
af8cb5c5 3531 else if (mode == DImode)
2bfcf297 3532 {
af8cb5c5
DE
3533 if (GET_CODE (source) == CONST_INT)
3534 {
3535 c0 = INTVAL (source);
3536 c1 = -(c0 < 0);
3537 }
3538 else if (GET_CODE (source) == CONST_DOUBLE)
3539 {
2bfcf297 3540#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3541 c0 = CONST_DOUBLE_LOW (source);
3542 c1 = -(c0 < 0);
2bfcf297 3543#else
af8cb5c5
DE
3544 c0 = CONST_DOUBLE_LOW (source);
3545 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3546#endif
af8cb5c5
DE
3547 }
3548 else
3549 abort ();
3550
3551 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3552 }
3553 else
a4f6c312 3554 abort ();
2bfcf297 3555
af8cb5c5
DE
3556 insn = get_last_insn ();
3557 set = single_set (insn);
3558 if (! CONSTANT_P (SET_SRC (set)))
3559 set_unique_reg_note (insn, REG_EQUAL, source);
3560
3561 return result;
2bfcf297
DB
3562}
3563
3564/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3565 fall back to a straight forward decomposition. We do this to avoid
3566 exponential run times encountered when looking for longer sequences
3567 with rs6000_emit_set_const. */
3568static rtx
a2369ed3 3569rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
3570{
3571 if (!TARGET_POWERPC64)
3572 {
3573 rtx operand1, operand2;
3574
3575 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3576 DImode);
3577 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3578 DImode);
3579 emit_move_insn (operand1, GEN_INT (c1));
3580 emit_move_insn (operand2, GEN_INT (c2));
3581 }
3582 else
3583 {
bc06712d 3584 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3585
bc06712d 3586 ud1 = c1 & 0xffff;
f921c9c9 3587 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3588#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3589 c2 = c1 >> 32;
2bfcf297 3590#endif
bc06712d 3591 ud3 = c2 & 0xffff;
f921c9c9 3592 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3593
bc06712d
TR
3594 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3595 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3596 {
bc06712d 3597 if (ud1 & 0x8000)
b78d48dd 3598 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
3599 else
3600 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3601 }
2bfcf297 3602
bc06712d
TR
3603 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3604 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3605 {
bc06712d
TR
3606 if (ud2 & 0x8000)
3607 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3608 - 0x80000000));
252b88f7 3609 else
bc06712d
TR
3610 emit_move_insn (dest, GEN_INT (ud2 << 16));
3611 if (ud1 != 0)
3612 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3613 }
bc06712d
TR
3614 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3615 || (ud4 == 0 && ! (ud3 & 0x8000)))
3616 {
3617 if (ud3 & 0x8000)
3618 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3619 - 0x80000000));
3620 else
3621 emit_move_insn (dest, GEN_INT (ud3 << 16));
3622
3623 if (ud2 != 0)
3624 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3625 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3626 if (ud1 != 0)
3627 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3628 }
3629 else
3630 {
3631 if (ud4 & 0x8000)
3632 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3633 - 0x80000000));
3634 else
3635 emit_move_insn (dest, GEN_INT (ud4 << 16));
3636
3637 if (ud3 != 0)
3638 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3639
bc06712d
TR
3640 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3641 if (ud2 != 0)
3642 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3643 GEN_INT (ud2 << 16)));
3644 if (ud1 != 0)
3645 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3646 }
3647 }
2bfcf297
DB
3648 return dest;
3649}
3650
fb4d4348
GK
3651/* Emit a move from SOURCE to DEST in mode MODE. */
3652void
a2369ed3 3653rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
3654{
3655 rtx operands[2];
3656 operands[0] = dest;
3657 operands[1] = source;
3658
3659 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3660 if (GET_CODE (operands[1]) == CONST_DOUBLE
3661 && ! FLOAT_MODE_P (mode)
3662 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3663 {
3664 /* FIXME. This should never happen. */
3665 /* Since it seems that it does, do the safe thing and convert
3666 to a CONST_INT. */
2496c7bd 3667 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3668 }
3669 if (GET_CODE (operands[1]) == CONST_DOUBLE
3670 && ! FLOAT_MODE_P (mode)
3671 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3672 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3673 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3674 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3675 abort ();
c9e8cb32
DD
3676
3677 /* Check if GCC is setting up a block move that will end up using FP
3678 registers as temporaries. We must make sure this is acceptable. */
3679 if (GET_CODE (operands[0]) == MEM
3680 && GET_CODE (operands[1]) == MEM
3681 && mode == DImode
41543739
GK
3682 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3683 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3684 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3685 ? 32 : MEM_ALIGN (operands[0])))
3686 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3687 ? 32
3688 : MEM_ALIGN (operands[1]))))
3689 && ! MEM_VOLATILE_P (operands [0])
3690 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3691 {
41543739
GK
3692 emit_move_insn (adjust_address (operands[0], SImode, 0),
3693 adjust_address (operands[1], SImode, 0));
3694 emit_move_insn (adjust_address (operands[0], SImode, 4),
3695 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3696 return;
3697 }
630d42a0 3698
67cef334
DE
3699 if (!no_new_pseudos)
3700 {
3701 if (GET_CODE (operands[1]) == MEM && optimize > 0
3702 && (mode == QImode || mode == HImode || mode == SImode)
3703 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3704 {
3705 rtx reg = gen_reg_rtx (word_mode);
3706
3707 emit_insn (gen_rtx_SET (word_mode, reg,
3708 gen_rtx_ZERO_EXTEND (word_mode,
3709 operands[1])));
3710 operands[1] = gen_lowpart (mode, reg);
3711 }
3712 if (GET_CODE (operands[0]) != REG)
3713 operands[1] = force_reg (mode, operands[1]);
3714 }
a9098fd0 3715
a3170dc6
AH
3716 if (mode == SFmode && ! TARGET_POWERPC
3717 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3718 && GET_CODE (operands[0]) == MEM)
fb4d4348 3719 {
ffc14f31
GK
3720 int regnum;
3721
3722 if (reload_in_progress || reload_completed)
3723 regnum = true_regnum (operands[1]);
3724 else if (GET_CODE (operands[1]) == REG)
3725 regnum = REGNO (operands[1]);
3726 else
3727 regnum = -1;
fb4d4348
GK
3728
3729 /* If operands[1] is a register, on POWER it may have
3730 double-precision data in it, so truncate it to single
3731 precision. */
3732 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3733 {
3734 rtx newreg;
3735 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3736 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3737 operands[1] = newreg;
3738 }
3739 }
3740
c4501e62
JJ
3741 /* Recognize the case where operand[1] is a reference to thread-local
3742 data and load its address to a register. */
3743 if (GET_CODE (operands[1]) == SYMBOL_REF)
3744 {
3745 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3746 if (model != 0)
3747 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3748 }
3749
8f4e6caf
RH
3750 /* Handle the case where reload calls us with an invalid address. */
3751 if (reload_in_progress && mode == Pmode
69ef87e2 3752 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3753 || ! nonimmediate_operand (operands[0], mode)))
3754 goto emit_set;
3755
3756 /* Handle the case of CONSTANT_P_RTX. */
3757 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3758 goto emit_set;
a9baceb1
GK
3759
3760 /* 128-bit constant floating-point values on Darwin should really be
3761 loaded as two parts. */
3762 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
3763 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
3764 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
3765 {
3766 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
3767 know how to get a DFmode SUBREG of a TFmode. */
3768 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
3769 simplify_gen_subreg (DImode, operands[1], mode, 0),
3770 DImode);
3771 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
3772 GET_MODE_SIZE (DImode)),
3773 simplify_gen_subreg (DImode, operands[1], mode,
3774 GET_MODE_SIZE (DImode)),
3775 DImode);
3776 return;
3777 }
3778
fb4d4348
GK
3779 /* FIXME: In the long term, this switch statement should go away
3780 and be replaced by a sequence of tests based on things like
3781 mode == Pmode. */
3782 switch (mode)
3783 {
3784 case HImode:
3785 case QImode:
3786 if (CONSTANT_P (operands[1])
3787 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3788 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3789 break;
3790
06f4e019 3791 case TFmode:
fb4d4348
GK
3792 case DFmode:
3793 case SFmode:
3794 if (CONSTANT_P (operands[1])
3795 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3796 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3797 break;
3798
0ac081f6
AH
3799 case V16QImode:
3800 case V8HImode:
3801 case V4SFmode:
3802 case V4SImode:
a3170dc6
AH
3803 case V4HImode:
3804 case V2SFmode:
3805 case V2SImode:
00a892b8 3806 case V1DImode:
69ef87e2 3807 if (CONSTANT_P (operands[1])
d744e06e 3808 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3809 operands[1] = force_const_mem (mode, operands[1]);
3810 break;
3811
fb4d4348 3812 case SImode:
a9098fd0 3813 case DImode:
fb4d4348
GK
3814 /* Use default pattern for address of ELF small data */
3815 if (TARGET_ELF
a9098fd0 3816 && mode == Pmode
f607bc57 3817 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3818 && (GET_CODE (operands[1]) == SYMBOL_REF
3819 || GET_CODE (operands[1]) == CONST)
3820 && small_data_operand (operands[1], mode))
fb4d4348
GK
3821 {
3822 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3823 return;
3824 }
3825
f607bc57 3826 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3827 && mode == Pmode && mode == SImode
3828 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3829 {
3830 emit_insn (gen_movsi_got (operands[0], operands[1]));
3831 return;
3832 }
3833
ee890fe2 3834 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3835 && TARGET_NO_TOC
3836 && ! flag_pic
a9098fd0 3837 && mode == Pmode
fb4d4348
GK
3838 && CONSTANT_P (operands[1])
3839 && GET_CODE (operands[1]) != HIGH
3840 && GET_CODE (operands[1]) != CONST_INT)
3841 {
a9098fd0 3842 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3843
3844 /* If this is a function address on -mcall-aixdesc,
3845 convert it to the address of the descriptor. */
3846 if (DEFAULT_ABI == ABI_AIX
3847 && GET_CODE (operands[1]) == SYMBOL_REF
3848 && XSTR (operands[1], 0)[0] == '.')
3849 {
3850 const char *name = XSTR (operands[1], 0);
3851 rtx new_ref;
3852 while (*name == '.')
3853 name++;
3854 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3855 CONSTANT_POOL_ADDRESS_P (new_ref)
3856 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3857 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3858 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3859 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3860 operands[1] = new_ref;
3861 }
7509c759 3862
ee890fe2
SS
3863 if (DEFAULT_ABI == ABI_DARWIN)
3864 {
ab82a49f
AP
3865#if TARGET_MACHO
3866 if (MACHO_DYNAMIC_NO_PIC_P)
3867 {
3868 /* Take care of any required data indirection. */
3869 operands[1] = rs6000_machopic_legitimize_pic_address (
3870 operands[1], mode, operands[0]);
3871 if (operands[0] != operands[1])
3872 emit_insn (gen_rtx_SET (VOIDmode,
3873 operands[0], operands[1]));
3874 return;
3875 }
3876#endif
ee890fe2
SS
3877 emit_insn (gen_macho_high (target, operands[1]));
3878 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3879 return;
3880 }
3881
fb4d4348
GK
3882 emit_insn (gen_elf_high (target, operands[1]));
3883 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3884 return;
3885 }
3886
a9098fd0
GK
3887 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3888 and we have put it in the TOC, we just need to make a TOC-relative
3889 reference to it. */
3890 if (TARGET_TOC
3891 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3892 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3893 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3894 get_pool_mode (operands[1])))
fb4d4348 3895 {
a9098fd0 3896 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3897 }
a9098fd0
GK
3898 else if (mode == Pmode
3899 && CONSTANT_P (operands[1])
38886f37
AO
3900 && ((GET_CODE (operands[1]) != CONST_INT
3901 && ! easy_fp_constant (operands[1], mode))
3902 || (GET_CODE (operands[1]) == CONST_INT
3903 && num_insns_constant (operands[1], mode) > 2)
3904 || (GET_CODE (operands[0]) == REG
3905 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3906 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3907 && ! legitimate_constant_pool_address_p (operands[1])
3908 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3909 {
3910 /* Emit a USE operation so that the constant isn't deleted if
3911 expensive optimizations are turned on because nobody
3912 references it. This should only be done for operands that
3913 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3914 This should not be done for operands that contain LABEL_REFs.
3915 For now, we just handle the obvious case. */
3916 if (GET_CODE (operands[1]) != LABEL_REF)
3917 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3918
c859cda6 3919#if TARGET_MACHO
ee890fe2 3920 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3921 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3922 {
ee890fe2
SS
3923 operands[1] =
3924 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3925 operands[0]);
3926 if (operands[0] != operands[1])
3927 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3928 return;
3929 }
c859cda6 3930#endif
ee890fe2 3931
fb4d4348
GK
3932 /* If we are to limit the number of things we put in the TOC and
3933 this is a symbol plus a constant we can add in one insn,
3934 just put the symbol in the TOC and add the constant. Don't do
3935 this if reload is in progress. */
3936 if (GET_CODE (operands[1]) == CONST
3937 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3938 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3939 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3940 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3941 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3942 && ! side_effects_p (operands[0]))
3943 {
a4f6c312
SS
3944 rtx sym =
3945 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3946 rtx other = XEXP (XEXP (operands[1], 0), 1);
3947
a9098fd0
GK
3948 sym = force_reg (mode, sym);
3949 if (mode == SImode)
3950 emit_insn (gen_addsi3 (operands[0], sym, other));
3951 else
3952 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3953 return;
3954 }
3955
a9098fd0 3956 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3957
3958 if (TARGET_TOC
4d588c14 3959 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3960 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3961 get_pool_constant (XEXP (operands[1], 0)),
3962 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3963 {
ba4828e0
RK
3964 operands[1]
3965 = gen_rtx_MEM (mode,
3966 create_TOC_reference (XEXP (operands[1], 0)));
3967 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3968 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3969 }
fb4d4348
GK
3970 }
3971 break;
a9098fd0 3972
fb4d4348
GK
3973 case TImode:
3974 if (GET_CODE (operands[0]) == MEM
3975 && GET_CODE (XEXP (operands[0], 0)) != REG
3976 && ! reload_in_progress)
792760b9
RK
3977 operands[0]
3978 = replace_equiv_address (operands[0],
3979 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3980
3981 if (GET_CODE (operands[1]) == MEM
3982 && GET_CODE (XEXP (operands[1], 0)) != REG
3983 && ! reload_in_progress)
792760b9
RK
3984 operands[1]
3985 = replace_equiv_address (operands[1],
3986 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3987 if (TARGET_POWER)
3988 {
3989 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3990 gen_rtvec (2,
3991 gen_rtx_SET (VOIDmode,
3992 operands[0], operands[1]),
3993 gen_rtx_CLOBBER (VOIDmode,
3994 gen_rtx_SCRATCH (SImode)))));
3995 return;
3996 }
fb4d4348
GK
3997 break;
3998
3999 default:
4000 abort ();
4001 }
4002
a9098fd0
GK
4003 /* Above, we may have called force_const_mem which may have returned
4004 an invalid address. If we can, fix this up; otherwise, reload will
4005 have to deal with it. */
8f4e6caf
RH
4006 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
4007 operands[1] = validize_mem (operands[1]);
a9098fd0 4008
8f4e6caf 4009 emit_set:
fb4d4348
GK
4010 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
4011}
4697a36c 4012\f
2858f73a
GK
4013/* Nonzero if we can use a floating-point register to pass this arg. */
4014#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
4015 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
4016 && (CUM)->fregno <= FP_ARG_MAX_REG \
4017 && TARGET_HARD_FLOAT && TARGET_FPRS)
4018
4019/* Nonzero if we can use an AltiVec register to pass this arg. */
4020#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
4021 (ALTIVEC_VECTOR_MODE (MODE) \
4022 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
4023 && TARGET_ALTIVEC_ABI \
83953138 4024 && (NAMED))
2858f73a 4025
c6e8c921
GK
4026/* Return a nonzero value to say to return the function value in
4027 memory, just as large structures are always returned. TYPE will be
4028 the data type of the value, and FNTYPE will be the type of the
4029 function doing the returning, or @code{NULL} for libcalls.
4030
4031 The AIX ABI for the RS/6000 specifies that all structures are
4032 returned in memory. The Darwin ABI does the same. The SVR4 ABI
4033 specifies that structures <= 8 bytes are returned in r3/r4, but a
4034 draft put them in memory, and GCC used to implement the draft
4035 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
4036 controls this instead of DEFAULT_ABI; V.4 targets needing backward
4037 compatibility can change DRAFT_V4_STRUCT_RET to override the
4038 default, and -m switches get the final word. See
4039 rs6000_override_options for more details.
4040
4041 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
4042 long double support is enabled. These values are returned in memory.
4043
4044 int_size_in_bytes returns -1 for variable size objects, which go in
4045 memory always. The cast to unsigned makes -1 > 8. */
4046
4047static bool
4048rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
4049{
4050 if (AGGREGATE_TYPE_P (type)
4051 && (TARGET_AIX_STRUCT_RET
4052 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
4053 return true;
4054 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
4055 return true;
4056 return false;
4057}
4058
4697a36c
MM
4059/* Initialize a variable CUM of type CUMULATIVE_ARGS
4060 for a call to a function whose data type is FNTYPE.
4061 For a library call, FNTYPE is 0.
4062
4063 For incoming args we set the number of arguments in the prototype large
1c20ae99 4064 so we never return a PARALLEL. */
4697a36c
MM
4065
4066void
a2369ed3 4067init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
4068 rtx libname ATTRIBUTE_UNUSED, int incoming,
4069 int libcall, int n_named_args)
4697a36c
MM
4070{
4071 static CUMULATIVE_ARGS zero_cumulative;
4072
4073 *cum = zero_cumulative;
4074 cum->words = 0;
4075 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 4076 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 4077 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
4078 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
4079 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 4080 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
4081 cum->stdarg = fntype
4082 && (TYPE_ARG_TYPES (fntype) != 0
4083 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
4084 != void_type_node));
4697a36c 4085
0f6937fe
AM
4086 cum->nargs_prototype = 0;
4087 if (incoming || cum->prototype)
4088 cum->nargs_prototype = n_named_args;
4697a36c 4089
a5c76ee6
ZW
4090 /* Check for a longcall attribute. */
4091 if (fntype
4092 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
4093 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
4094 cum->call_cookie = CALL_LONG;
4095
4697a36c
MM
4096 if (TARGET_DEBUG_ARG)
4097 {
4098 fprintf (stderr, "\ninit_cumulative_args:");
4099 if (fntype)
4100 {
4101 tree ret_type = TREE_TYPE (fntype);
4102 fprintf (stderr, " ret code = %s,",
4103 tree_code_name[ (int)TREE_CODE (ret_type) ]);
4104 }
4105
6a4cee5f
MM
4106 if (cum->call_cookie & CALL_LONG)
4107 fprintf (stderr, " longcall,");
4108
4697a36c
MM
4109 fprintf (stderr, " proto = %d, nargs = %d\n",
4110 cum->prototype, cum->nargs_prototype);
4111 }
6d0ef01e
HP
4112
4113 if (fntype
4114 && !TARGET_ALTIVEC
4115 && TARGET_ALTIVEC_ABI
4116 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
4117 {
4118 error ("Cannot return value in vector register because"
4119 " altivec instructions are disabled, use -maltivec"
4120 " to enable them.");
4121 }
4697a36c
MM
4122}
4123\f
c229cba9
DE
4124/* If defined, a C expression which determines whether, and in which
4125 direction, to pad out an argument with extra space. The value
4126 should be of type `enum direction': either `upward' to pad above
4127 the argument, `downward' to pad below, or `none' to inhibit
4128 padding.
4129
4130 For the AIX ABI structs are always stored left shifted in their
4131 argument slot. */
4132
9ebbca7d 4133enum direction
a2369ed3 4134function_arg_padding (enum machine_mode mode, tree type)
c229cba9 4135{
6e985040
AM
4136#ifndef AGGREGATE_PADDING_FIXED
4137#define AGGREGATE_PADDING_FIXED 0
4138#endif
4139#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
4140#define AGGREGATES_PAD_UPWARD_ALWAYS 0
4141#endif
4142
4143 if (!AGGREGATE_PADDING_FIXED)
4144 {
4145 /* GCC used to pass structures of the same size as integer types as
4146 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
4147 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
4148 passed padded downward, except that -mstrict-align further
4149 muddied the water in that multi-component structures of 2 and 4
4150 bytes in size were passed padded upward.
4151
4152 The following arranges for best compatibility with previous
4153 versions of gcc, but removes the -mstrict-align dependency. */
4154 if (BYTES_BIG_ENDIAN)
4155 {
4156 HOST_WIDE_INT size = 0;
4157
4158 if (mode == BLKmode)
4159 {
4160 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
4161 size = int_size_in_bytes (type);
4162 }
4163 else
4164 size = GET_MODE_SIZE (mode);
4165
4166 if (size == 1 || size == 2 || size == 4)
4167 return downward;
4168 }
4169 return upward;
4170 }
4171
4172 if (AGGREGATES_PAD_UPWARD_ALWAYS)
4173 {
4174 if (type != 0 && AGGREGATE_TYPE_P (type))
4175 return upward;
4176 }
c229cba9 4177
d3704c46
KH
4178 /* Fall back to the default. */
4179 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
4180}
4181
b6c9286a
MM
4182/* If defined, a C expression that gives the alignment boundary, in bits,
4183 of an argument with the specified mode and type. If it is not defined,
4184 PARM_BOUNDARY is used for all arguments.
4185
2310f99a 4186 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
4187
4188int
a2369ed3 4189function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 4190{
4ed78545
AM
4191 if (DEFAULT_ABI == ABI_V4 && GET_MODE_SIZE (mode) == 8)
4192 return 64;
4193 else if (SPE_VECTOR_MODE (mode))
e1f83b4d 4194 return 64;
b2d04ecf 4195 else if (ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4196 return 128;
9ebbca7d 4197 else
b6c9286a 4198 return PARM_BOUNDARY;
b6c9286a 4199}
c53bdcf5
AM
4200
4201/* Compute the size (in words) of a function argument. */
4202
4203static unsigned long
4204rs6000_arg_size (enum machine_mode mode, tree type)
4205{
4206 unsigned long size;
4207
4208 if (mode != BLKmode)
4209 size = GET_MODE_SIZE (mode);
4210 else
4211 size = int_size_in_bytes (type);
4212
4213 if (TARGET_32BIT)
4214 return (size + 3) >> 2;
4215 else
4216 return (size + 7) >> 3;
4217}
b6c9286a 4218\f
4697a36c
MM
4219/* Update the data in CUM to advance over an argument
4220 of mode MODE and data type TYPE.
b2d04ecf
AM
4221 (TYPE is null for libcalls where that information may not be available.)
4222
4223 Note that for args passed by reference, function_arg will be called
4224 with MODE and TYPE set to that of the pointer to the arg, not the arg
4225 itself. */
4697a36c
MM
4226
4227void
a2369ed3
DJ
4228function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4229 tree type, int named)
4697a36c
MM
4230{
4231 cum->nargs_prototype--;
4232
0ac081f6
AH
4233 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4234 {
4ed78545
AM
4235 bool stack = false;
4236
2858f73a 4237 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
6d0ef01e
HP
4238 {
4239 cum->vregno++;
4240 if (!TARGET_ALTIVEC)
4241 error ("Cannot pass argument in vector register because"
4242 " altivec instructions are disabled, use -maltivec"
4243 " to enable them.");
4ed78545
AM
4244
4245 /* PowerPC64 Linux and AIX allocate GPRs for a vector argument
4246 even if it is going to be passed in a vector register.
4247 Darwin does the same for variable-argument functions. */
4248 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4249 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4250 stack = true;
6d0ef01e 4251 }
4ed78545
AM
4252 else
4253 stack = true;
4254
4255 if (stack)
c72d6c26 4256 {
a594a19c
GK
4257 int align;
4258
2858f73a
GK
4259 /* Vector parameters must be 16-byte aligned. This places
4260 them at 2 mod 4 in terms of words in 32-bit mode, since
4261 the parameter save area starts at offset 24 from the
4262 stack. In 64-bit mode, they just have to start on an
4263 even word, since the parameter save area is 16-byte
4264 aligned. Space for GPRs is reserved even if the argument
4265 will be passed in memory. */
4266 if (TARGET_32BIT)
4ed78545 4267 align = (2 - cum->words) & 3;
2858f73a
GK
4268 else
4269 align = cum->words & 1;
c53bdcf5 4270 cum->words += align + rs6000_arg_size (mode, type);
2858f73a 4271
a594a19c
GK
4272 if (TARGET_DEBUG_ARG)
4273 {
4274 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
4275 cum->words, align);
4276 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
2858f73a
GK
4277 cum->nargs_prototype, cum->prototype,
4278 GET_MODE_NAME (mode));
a594a19c
GK
4279 }
4280 }
0ac081f6 4281 }
a4b0320c 4282 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4283 && !cum->stdarg
4284 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4285 cum->sysv_gregno++;
f607bc57 4286 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4287 {
a3170dc6 4288 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4289 && (mode == SFmode || mode == DFmode))
4697a36c 4290 {
4cc833b7
RH
4291 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4292 cum->fregno++;
4293 else
4294 {
4295 if (mode == DFmode)
4296 cum->words += cum->words & 1;
c53bdcf5 4297 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4298 }
4697a36c 4299 }
4cc833b7
RH
4300 else
4301 {
b2d04ecf 4302 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4303 int gregno = cum->sysv_gregno;
4304
4ed78545
AM
4305 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4306 (r7,r8) or (r9,r10). As does any other 2 word item such
4307 as complex int due to a historical mistake. */
4308 if (n_words == 2)
4309 gregno += (1 - gregno) & 1;
4cc833b7 4310
4ed78545 4311 /* Multi-reg args are not split between registers and stack. */
4cc833b7
RH
4312 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4313 {
4ed78545
AM
4314 /* Long long and SPE vectors are aligned on the stack.
4315 So are other 2 word items such as complex int due to
4316 a historical mistake. */
4cc833b7
RH
4317 if (n_words == 2)
4318 cum->words += cum->words & 1;
4319 cum->words += n_words;
4320 }
4697a36c 4321
4cc833b7
RH
4322 /* Note: continuing to accumulate gregno past when we've started
4323 spilling to the stack indicates the fact that we've started
4324 spilling to the stack to expand_builtin_saveregs. */
4325 cum->sysv_gregno = gregno + n_words;
4326 }
4697a36c 4327
4cc833b7
RH
4328 if (TARGET_DEBUG_ARG)
4329 {
4330 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4331 cum->words, cum->fregno);
4332 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4333 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4334 fprintf (stderr, "mode = %4s, named = %d\n",
4335 GET_MODE_NAME (mode), named);
4336 }
4697a36c
MM
4337 }
4338 else
4cc833b7 4339 {
b2d04ecf
AM
4340 int n_words = rs6000_arg_size (mode, type);
4341 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
a4f6c312 4342
b2d04ecf
AM
4343 /* The simple alignment calculation here works because
4344 function_arg_boundary / PARM_BOUNDARY will only be 1 or 2.
4345 If we ever want to handle alignments larger than 8 bytes for
4346 32-bit or 16 bytes for 64-bit, then we'll need to take into
4347 account the offset to the start of the parm save area. */
4348 align &= cum->words;
4349 cum->words += align + n_words;
4697a36c 4350
a3170dc6
AH
4351 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4352 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4353 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4354
4355 if (TARGET_DEBUG_ARG)
4356 {
4357 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4358 cum->words, cum->fregno);
4359 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4360 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4361 fprintf (stderr, "named = %d, align = %d\n", named, align);
4362 }
4363 }
4697a36c 4364}
a6c9bed4
AH
4365
4366/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4367
a6c9bed4 4368static rtx
a2369ed3
DJ
4369rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4370 tree type)
a6c9bed4
AH
4371{
4372 if (cum->stdarg)
4373 {
4374 int gregno = cum->sysv_gregno;
c53bdcf5 4375 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4376
4377 /* SPE vectors are put in odd registers. */
4378 if (n_words == 2 && (gregno & 1) == 0)
4379 gregno += 1;
4380
4381 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4382 {
4383 rtx r1, r2;
4384 enum machine_mode m = SImode;
4385
4386 r1 = gen_rtx_REG (m, gregno);
4387 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4388 r2 = gen_rtx_REG (m, gregno + 1);
4389 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4390 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4391 }
4392 else
b78d48dd 4393 return NULL_RTX;
a6c9bed4
AH
4394 }
4395 else
4396 {
4397 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4398 return gen_rtx_REG (mode, cum->sysv_gregno);
4399 else
b78d48dd 4400 return NULL_RTX;
a6c9bed4
AH
4401 }
4402}
4403
b78d48dd
FJ
4404/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4405
4406static rtx
4407rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4408 tree type, int align_words)
4409{
4410 if (mode == DFmode)
4411 {
4412 /* -mpowerpc64 with 32bit ABI splits up a DFmode argument
4413 in vararg list into zero, one or two GPRs */
4414 if (align_words >= GP_ARG_NUM_REG)
4415 return gen_rtx_PARALLEL (DFmode,
4416 gen_rtvec (2,
4417 gen_rtx_EXPR_LIST (VOIDmode,
4418 NULL_RTX, const0_rtx),
4419 gen_rtx_EXPR_LIST (VOIDmode,
4420 gen_rtx_REG (mode,
4421 cum->fregno),
4422 const0_rtx)));
c53bdcf5 4423 else if (align_words + rs6000_arg_size (mode, type)
b78d48dd
FJ
4424 > GP_ARG_NUM_REG)
4425 /* If this is partially on the stack, then we only
a3c9585f 4426 include the portion actually in registers here. */
b78d48dd
FJ
4427 return gen_rtx_PARALLEL (DFmode,
4428 gen_rtvec (2,
4429 gen_rtx_EXPR_LIST (VOIDmode,
4430 gen_rtx_REG (SImode,
4431 GP_ARG_MIN_REG
4432 + align_words),
4433 const0_rtx),
4434 gen_rtx_EXPR_LIST (VOIDmode,
4435 gen_rtx_REG (mode,
4436 cum->fregno),
4437 const0_rtx)));
4438
4439 /* split a DFmode arg into two GPRs */
4440 return gen_rtx_PARALLEL (DFmode,
4441 gen_rtvec (3,
4442 gen_rtx_EXPR_LIST (VOIDmode,
4443 gen_rtx_REG (SImode,
4444 GP_ARG_MIN_REG
4445 + align_words),
4446 const0_rtx),
4447 gen_rtx_EXPR_LIST (VOIDmode,
4448 gen_rtx_REG (SImode,
4449 GP_ARG_MIN_REG
4450 + align_words + 1),
4451 GEN_INT (4)),
4452 gen_rtx_EXPR_LIST (VOIDmode,
4453 gen_rtx_REG (mode, cum->fregno),
4454 const0_rtx)));
4455 }
4456 /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one
4457 or two GPRs */
4458 else if (mode == DImode)
4459 {
4460 if (align_words < GP_ARG_NUM_REG - 1)
4461 return gen_rtx_PARALLEL (DImode,
4462 gen_rtvec (2,
4463 gen_rtx_EXPR_LIST (VOIDmode,
4464 gen_rtx_REG (SImode,
4465 GP_ARG_MIN_REG
4466 + align_words),
4467 const0_rtx),
4468 gen_rtx_EXPR_LIST (VOIDmode,
4469 gen_rtx_REG (SImode,
4470 GP_ARG_MIN_REG
4471 + align_words + 1),
4472 GEN_INT (4))));
4473 else if (align_words == GP_ARG_NUM_REG - 1)
4474 return gen_rtx_PARALLEL (DImode,
4475 gen_rtvec (2,
4476 gen_rtx_EXPR_LIST (VOIDmode,
4477 NULL_RTX, const0_rtx),
4478 gen_rtx_EXPR_LIST (VOIDmode,
4479 gen_rtx_REG (SImode,
4480 GP_ARG_MIN_REG
4481 + align_words),
4482 const0_rtx)));
4483 }
36a454e1 4484 else if (ALTIVEC_VECTOR_MODE (mode) && align_words == GP_ARG_NUM_REG - 2)
b78d48dd 4485 {
36a454e1
FJ
4486 /* Varargs vector regs must be saved in R9-R10. */
4487 return gen_rtx_PARALLEL (mode,
4488 gen_rtvec (3,
4489 gen_rtx_EXPR_LIST (VOIDmode,
4490 NULL_RTX, const0_rtx),
4491 gen_rtx_EXPR_LIST (VOIDmode,
4492 gen_rtx_REG (SImode,
4493 GP_ARG_MIN_REG
4494 + align_words),
4495 const0_rtx),
4496 gen_rtx_EXPR_LIST (VOIDmode,
4497 gen_rtx_REG (SImode,
4498 GP_ARG_MIN_REG
4499 + align_words + 1),
4500 GEN_INT (4))));
4501 }
4502 else if ((mode == BLKmode || ALTIVEC_VECTOR_MODE (mode))
4503 && align_words <= (GP_ARG_NUM_REG - 1))
4504 {
4505 /* AltiVec vector regs are saved in R5-R8. */
b78d48dd
FJ
4506 int k;
4507 int size = int_size_in_bytes (type);
2f7b62ef 4508 int no_units = ((size - 1) / 4) + 1;
b78d48dd
FJ
4509 int max_no_words = GP_ARG_NUM_REG - align_words;
4510 int rtlvec_len = no_units < max_no_words ? no_units : max_no_words;
4511 rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx));
4512
4513 memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx));
4514
4515 for (k=0; k < rtlvec_len; k++)
4516 rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode,
4517 gen_rtx_REG (SImode,
4518 GP_ARG_MIN_REG
4519 + align_words + k),
4520 k == 0 ? const0_rtx : GEN_INT (k*4));
4521
36a454e1
FJ
4522 return gen_rtx_PARALLEL (mode, gen_rtvec_v (k, rtlvec));
4523 }
b78d48dd
FJ
4524 return NULL_RTX;
4525}
4526
4697a36c
MM
4527/* Determine where to put an argument to a function.
4528 Value is zero to push the argument on the stack,
4529 or a hard register in which to store the argument.
4530
4531 MODE is the argument's machine mode.
4532 TYPE is the data type of the argument (as a tree).
4533 This is null for libcalls where that information may
4534 not be available.
4535 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4536 the preceding args and about the function being called.
4537 NAMED is nonzero if this argument is a named parameter
4538 (otherwise it is an extra parameter matching an ellipsis).
4539
4540 On RS/6000 the first eight words of non-FP are normally in registers
4541 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4542 Under V.4, the first 8 FP args are in registers.
4543
4544 If this is floating-point and no prototype is specified, we use
4545 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4546 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4547 so we can pass the FP value just in one register. emit_library_function
b2d04ecf
AM
4548 doesn't support PARALLEL anyway.
4549
4550 Note that for args passed by reference, function_arg will be called
4551 with MODE and TYPE set to that of the pointer to the arg, not the arg
4552 itself. */
4697a36c
MM
4553
4554struct rtx_def *
a2369ed3
DJ
4555function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4556 tree type, int named)
4697a36c 4557{
4cc833b7 4558 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4559
a4f6c312
SS
4560 /* Return a marker to indicate whether CR1 needs to set or clear the
4561 bit that V.4 uses to say fp args were passed in registers.
4562 Assume that we don't need the marker for software floating point,
4563 or compiler generated library calls. */
4697a36c
MM
4564 if (mode == VOIDmode)
4565 {
f607bc57 4566 if (abi == ABI_V4
7509c759 4567 && cum->nargs_prototype < 0
b9599e46
FS
4568 && (cum->call_cookie & CALL_LIBCALL) == 0
4569 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4570 {
a3170dc6
AH
4571 /* For the SPE, we need to crxor CR6 always. */
4572 if (TARGET_SPE_ABI)
4573 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4574 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4575 return GEN_INT (cum->call_cookie
4576 | ((cum->fregno == FP_ARG_MIN_REG)
4577 ? CALL_V4_SET_FP_ARGS
4578 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4579 }
4697a36c 4580
7509c759 4581 return GEN_INT (cum->call_cookie);
4697a36c
MM
4582 }
4583
2858f73a 4584 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4585 if (TARGET_64BIT && ! cum->prototype)
4586 {
4587 /* Vector parameters get passed in vector register
4588 and also in GPRs or memory, in absence of prototype. */
4589 int align_words;
4590 rtx slot;
4591 align_words = (cum->words + 1) & ~1;
4592
4593 if (align_words >= GP_ARG_NUM_REG)
4594 {
4595 slot = NULL_RTX;
4596 }
4597 else
4598 {
4599 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4600 }
4601 return gen_rtx_PARALLEL (mode,
4602 gen_rtvec (2,
4603 gen_rtx_EXPR_LIST (VOIDmode,
4604 slot, const0_rtx),
4605 gen_rtx_EXPR_LIST (VOIDmode,
4606 gen_rtx_REG (mode, cum->vregno),
4607 const0_rtx)));
4608 }
4609 else
4610 return gen_rtx_REG (mode, cum->vregno);
2858f73a 4611 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4612 {
2858f73a 4613 if (named || abi == ABI_V4)
a594a19c 4614 return NULL_RTX;
0ac081f6 4615 else
a594a19c
GK
4616 {
4617 /* Vector parameters to varargs functions under AIX or Darwin
4618 get passed in memory and possibly also in GPRs. */
4619 int align, align_words;
2858f73a 4620 enum machine_mode part_mode = mode;
a594a19c
GK
4621
4622 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
4623 2 mod 4 in terms of words in 32-bit mode, since the parameter
4624 save area starts at offset 24 from the stack. In 64-bit mode,
4625 they just have to start on an even word, since the parameter
4626 save area is 16-byte aligned. */
4627 if (TARGET_32BIT)
4ed78545 4628 align = (2 - cum->words) & 3;
2858f73a
GK
4629 else
4630 align = cum->words & 1;
a594a19c
GK
4631 align_words = cum->words + align;
4632
4633 /* Out of registers? Memory, then. */
4634 if (align_words >= GP_ARG_NUM_REG)
4635 return NULL_RTX;
4636
2858f73a
GK
4637 /* The vector value goes in GPRs. Only the part of the
4638 value in GPRs is reported here. */
4639 if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS)
4640 > GP_ARG_NUM_REG)
839a4992 4641 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
4642 is either wholly in GPRs or half in GPRs and half not. */
4643 part_mode = DImode;
4644
36a454e1
FJ
4645 if (TARGET_32BIT
4646 && (TARGET_POWERPC64 || (align_words == GP_ARG_NUM_REG - 2)))
4647 return rs6000_mixed_function_arg (cum, part_mode, type, align_words);
4648 else
4649 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 4650 }
0ac081f6 4651 }
a6c9bed4
AH
4652 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4653 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4654 else if (abi == ABI_V4)
4697a36c 4655 {
a3170dc6 4656 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4657 && (mode == SFmode || mode == DFmode))
4658 {
4659 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4660 return gen_rtx_REG (mode, cum->fregno);
4661 else
b78d48dd 4662 return NULL_RTX;
4cc833b7
RH
4663 }
4664 else
4665 {
b2d04ecf 4666 int n_words = rs6000_arg_size (mode, type);
4cc833b7
RH
4667 int gregno = cum->sysv_gregno;
4668
4ed78545
AM
4669 /* Long long and SPE vectors are put in (r3,r4), (r5,r6),
4670 (r7,r8) or (r9,r10). As does any other 2 word item such
4671 as complex int due to a historical mistake. */
4672 if (n_words == 2)
4673 gregno += (1 - gregno) & 1;
4cc833b7 4674
4ed78545 4675 /* Multi-reg args are not split between registers and stack. */
4cc833b7 4676 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4677 return gen_rtx_REG (mode, gregno);
4cc833b7 4678 else
b78d48dd 4679 return NULL_RTX;
4cc833b7 4680 }
4697a36c 4681 }
4cc833b7
RH
4682 else
4683 {
b2d04ecf
AM
4684 int align = function_arg_boundary (mode, type) / PARM_BOUNDARY - 1;
4685 int align_words = cum->words + (cum->words & align);
b78d48dd 4686
2858f73a 4687 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 4688 {
c53bdcf5
AM
4689 rtx fpr[2];
4690 rtx *r;
4691 bool needs_psave;
4692 enum machine_mode fmode = mode;
4693 int n;
4694 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
4695
4696 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
4697 {
4698 /* Long double split over regs and memory. */
4699 if (fmode == TFmode)
4700 fmode = DFmode;
4701
4702 /* Currently, we only ever need one reg here because complex
4703 doubles are split. */
4704 if (cum->fregno != FP_ARG_MAX_REG - 1)
4705 abort ();
4706 }
4707 fpr[1] = gen_rtx_REG (fmode, cum->fregno);
4708
4709 /* Do we also need to pass this arg in the parameter save
4710 area? */
4711 needs_psave = (type
4712 && (cum->nargs_prototype <= 0
4713 || (DEFAULT_ABI == ABI_AIX
4714 && TARGET_XL_CALL
4715 && align_words >= GP_ARG_NUM_REG)));
4716
4717 if (!needs_psave && mode == fmode)
4718 return fpr[1];
4cc833b7 4719
e91fa876
FJ
4720 if (TARGET_32BIT && TARGET_POWERPC64
4721 && mode == DFmode && cum->stdarg)
4722 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4723
c53bdcf5
AM
4724 /* Describe where this piece goes. */
4725 r = fpr + 1;
4726 *r = gen_rtx_EXPR_LIST (VOIDmode, *r, const0_rtx);
4727 n = 1;
4728
4729 if (needs_psave)
4730 {
4731 /* Now describe the part that goes in gprs or the stack.
4732 This piece must come first, before the fprs. */
4733 rtx reg = NULL_RTX;
4734 if (align_words < GP_ARG_NUM_REG)
4735 {
4736 unsigned long n_words = rs6000_arg_size (mode, type);
4737 enum machine_mode rmode = mode;
4738
4739 if (align_words + n_words > GP_ARG_NUM_REG)
4740 /* If this is partially on the stack, then we only
4741 include the portion actually in registers here.
4742 We know this can only be one register because
4743 complex doubles are splt. */
4744 rmode = Pmode;
4745 reg = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words);
4746 }
4747 *--r = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4748 ++n;
4749 }
4750
4751 return gen_rtx_PARALLEL (mode, gen_rtvec_v (n, r));
4cc833b7
RH
4752 }
4753 else if (align_words < GP_ARG_NUM_REG)
b2d04ecf
AM
4754 {
4755 if (TARGET_32BIT && TARGET_POWERPC64
4756 && (mode == DImode || mode == BLKmode))
4757 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4758
4759 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4760 }
4cc833b7
RH
4761 else
4762 return NULL_RTX;
4697a36c 4763 }
4697a36c
MM
4764}
4765\f
4766/* For an arg passed partly in registers and partly in memory,
4767 this is the number of registers used.
4768 For args passed entirely in registers or entirely in memory, zero. */
4769
4770int
a2369ed3 4771function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 4772 tree type, int named)
4697a36c 4773{
c53bdcf5
AM
4774 int ret = 0;
4775
f607bc57 4776 if (DEFAULT_ABI == ABI_V4)
4697a36c 4777 return 0;
4697a36c 4778
c53bdcf5
AM
4779 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
4780 && cum->nargs_prototype >= 0)
4781 return 0;
4782
4783 if (USE_FP_FOR_ARG_P (cum, mode, type))
4697a36c 4784 {
c53bdcf5
AM
4785 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
4786 ret = FP_ARG_MAX_REG - cum->fregno;
4787 else if (cum->nargs_prototype >= 0)
4697a36c
MM
4788 return 0;
4789 }
4790
4791 if (cum->words < GP_ARG_NUM_REG
c53bdcf5
AM
4792 && GP_ARG_NUM_REG < cum->words + rs6000_arg_size (mode, type))
4793 ret = GP_ARG_NUM_REG - cum->words;
4697a36c 4794
c53bdcf5
AM
4795 if (ret != 0 && TARGET_DEBUG_ARG)
4796 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 4797
c53bdcf5 4798 return ret;
4697a36c
MM
4799}
4800\f
4801/* A C expression that indicates when an argument must be passed by
4802 reference. If nonzero for an argument, a copy of that argument is
4803 made in memory and a pointer to the argument is passed instead of
4804 the argument itself. The pointer is passed in whatever way is
4805 appropriate for passing a pointer to that type.
4806
b2d04ecf
AM
4807 Under V.4, aggregates and long double are passed by reference.
4808
4809 As an extension to all 32-bit ABIs, AltiVec vectors are passed by
4810 reference unless the AltiVec vector extension ABI is in force.
c8c99a68
DE
4811
4812 As an extension to all ABIs, variable sized types are passed by
4813 reference. */
4697a36c
MM
4814
4815int
a2369ed3
DJ
4816function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4817 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 4818 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 4819{
b2d04ecf
AM
4820 if ((DEFAULT_ABI == ABI_V4
4821 && ((type && AGGREGATE_TYPE_P (type))
4822 || mode == TFmode))
4823 || (TARGET_32BIT && !TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4824 || (type && int_size_in_bytes (type) < 0))
4697a36c
MM
4825 {
4826 if (TARGET_DEBUG_ARG)
b2d04ecf 4827 fprintf (stderr, "function_arg_pass_by_reference\n");
4697a36c
MM
4828
4829 return 1;
4830 }
b2d04ecf 4831 return 0;
4697a36c 4832}
5985c7a6
FJ
4833
4834static void
2d9db8eb 4835rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
4836{
4837 int i;
4838 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
4839
4840 if (nregs == 0)
4841 return;
4842
4843 for (i = 0; i < nregs; i++)
4844 {
4845 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
4846 if (reload_completed)
4847 {
4848 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
4849 tem = NULL_RTX;
4850 else
4851 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
4852 i * GET_MODE_SIZE(reg_mode));
4853 }
4854 else
4855 tem = replace_equiv_address (tem, XEXP (tem, 0));
4856
4857 if (tem == NULL_RTX)
4858 abort ();
4859
4860 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
4861 }
4862}
4863
4697a36c
MM
4864\f
4865/* Perform any needed actions needed for a function that is receiving a
4866 variable number of arguments.
4867
4868 CUM is as above.
4869
4870 MODE and TYPE are the mode and type of the current parameter.
4871
4872 PRETEND_SIZE is a variable that should be set to the amount of stack
4873 that must be pushed by the prolog to pretend that our caller pushed
4874 it.
4875
4876 Normally, this macro will push all remaining incoming registers on the
4877 stack and set PRETEND_SIZE to the length of the registers pushed. */
4878
c6e8c921 4879static void
a2369ed3
DJ
4880setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4881 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4882{
4cc833b7
RH
4883 CUMULATIVE_ARGS next_cum;
4884 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4885 rtx save_area = NULL_RTX, mem;
dfafc897 4886 int first_reg_offset, set;
4697a36c 4887
f31bf321 4888 /* Skip the last named argument. */
d34c5b80 4889 next_cum = *cum;
f31bf321 4890 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4891
f607bc57 4892 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4893 {
4cc833b7 4894 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4895 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4896 if (! no_rtl)
2c4974b7 4897 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4898 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4899
4900 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4901 }
60e2d0ca 4902 else
4697a36c 4903 {
d34c5b80 4904 first_reg_offset = next_cum.words;
4cc833b7 4905 save_area = virtual_incoming_args_rtx;
00dba523 4906 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4907
4908 if (MUST_PASS_IN_STACK (mode, type))
c53bdcf5 4909 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 4910 }
4697a36c 4911
dfafc897 4912 set = get_varargs_alias_set ();
c81fc13e 4913 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4914 {
dfafc897
FS
4915 mem = gen_rtx_MEM (BLKmode,
4916 plus_constant (save_area,
4917 first_reg_offset * reg_size)),
ba4828e0 4918 set_mem_alias_set (mem, set);
8ac61af7 4919 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4920
5985c7a6
FJ
4921 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4922 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4923 }
4924
4697a36c 4925 /* Save FP registers if needed. */
f607bc57 4926 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4927 && TARGET_HARD_FLOAT && TARGET_FPRS
4928 && ! no_rtl
4cc833b7 4929 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4930 {
4cc833b7 4931 int fregno = next_cum.fregno;
9ebbca7d 4932 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4933 rtx lab = gen_label_rtx ();
4934 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4935
4cc833b7 4936 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4937 pc_rtx,
39403d82 4938 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4939 gen_rtx_NE (VOIDmode, cr1,
4940 const0_rtx),
39403d82 4941 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4942 pc_rtx)));
4943
4cc833b7
RH
4944 while (fregno <= FP_ARG_V4_MAX_REG)
4945 {
dfafc897 4946 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4947 set_mem_alias_set (mem, set);
dfafc897 4948 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4949 fregno++;
4950 off += 8;
4697a36c 4951 }
4cc833b7
RH
4952
4953 emit_label (lab);
4697a36c 4954 }
4697a36c 4955}
4697a36c 4956
dfafc897 4957/* Create the va_list data type. */
2c4974b7 4958
c35d187f
RH
4959static tree
4960rs6000_build_builtin_va_list (void)
dfafc897 4961{
64c2816f 4962 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4963
9ebbca7d
GK
4964 /* For AIX, prefer 'char *' because that's what the system
4965 header files like. */
f607bc57 4966 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4967 return build_pointer_type (char_type_node);
dfafc897 4968
f1e639b1 4969 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4970 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4971
9ebbca7d
GK
4972 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4973 unsigned_char_type_node);
4974 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4975 unsigned_char_type_node);
64c2816f
DT
4976 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4977 every user file. */
4978 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4979 short_unsigned_type_node);
dfafc897
FS
4980 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4981 ptr_type_node);
4982 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4983 ptr_type_node);
4984
4985 DECL_FIELD_CONTEXT (f_gpr) = record;
4986 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4987 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4988 DECL_FIELD_CONTEXT (f_ovf) = record;
4989 DECL_FIELD_CONTEXT (f_sav) = record;
4990
bab45a51
FS
4991 TREE_CHAIN (record) = type_decl;
4992 TYPE_NAME (record) = type_decl;
dfafc897
FS
4993 TYPE_FIELDS (record) = f_gpr;
4994 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4995 TREE_CHAIN (f_fpr) = f_res;
4996 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4997 TREE_CHAIN (f_ovf) = f_sav;
4998
4999 layout_type (record);
5000
5001 /* The correct type is an array type of one element. */
5002 return build_array_type (record, build_index_type (size_zero_node));
5003}
5004
5005/* Implement va_start. */
5006
5007void
a2369ed3 5008rs6000_va_start (tree valist, rtx nextarg)
4697a36c 5009{
dfafc897 5010 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 5011 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 5012 tree gpr, fpr, ovf, sav, t;
2c4974b7 5013
dfafc897 5014 /* Only SVR4 needs something special. */
f607bc57 5015 if (DEFAULT_ABI != ABI_V4)
dfafc897 5016 {
e5faf155 5017 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
5018 return;
5019 }
5020
973a648b 5021 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5022 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5023 f_res = TREE_CHAIN (f_fpr);
5024 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5025 f_sav = TREE_CHAIN (f_ovf);
5026
8ebecc3b 5027 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
5028 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
5029 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
5030 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
5031 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
5032
5033 /* Count number of gp and fp argument registers used. */
4cc833b7 5034 words = current_function_args_info.words;
dfafc897
FS
5035 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
5036 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
5037
5038 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
5039 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
5040 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
5041 words, n_gpr, n_fpr);
dfafc897
FS
5042
5043 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
5044 TREE_SIDE_EFFECTS (t) = 1;
5045 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5046
5047 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
5048 TREE_SIDE_EFFECTS (t) = 1;
5049 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5050
5051 /* Find the overflow area. */
5052 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
5053 if (words != 0)
5054 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
5055 build_int_2 (words * UNITS_PER_WORD, 0));
5056 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5057 TREE_SIDE_EFFECTS (t) = 1;
5058 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5059
5060 /* Find the register save area. */
5061 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
5062 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
5063 build_int_2 (-RS6000_VARARGS_SIZE, -1));
5064 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
5065 TREE_SIDE_EFFECTS (t) = 1;
5066 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5067}
5068
5069/* Implement va_arg. */
5070
5071rtx
a2369ed3 5072rs6000_va_arg (tree valist, tree type)
dfafc897 5073{
c566f9bd 5074 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
5075 tree gpr, fpr, ovf, sav, reg, t, u;
5076 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
5077 rtx lab_false, lab_over, addr_rtx, r;
4ed78545 5078 int align;
dfafc897 5079
f607bc57 5080 if (DEFAULT_ABI != ABI_V4)
c8c99a68 5081 {
b2d04ecf
AM
5082 /* Variable sized types are passed by reference, as are AltiVec
5083 vectors when 32-bit and not using the AltiVec ABI extension. */
5084 if (int_size_in_bytes (type) < 0
5085 || (TARGET_32BIT
5086 && !TARGET_ALTIVEC_ABI
5087 && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))))
c8c99a68
DE
5088 {
5089 u = build_pointer_type (type);
5090
5091 /* Args grow upward. */
5092 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
5093 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
5094 TREE_SIDE_EFFECTS (t) = 1;
5095
5096 t = build1 (NOP_EXPR, build_pointer_type (u), t);
5097 TREE_SIDE_EFFECTS (t) = 1;
5098
5099 t = build1 (INDIRECT_REF, u, t);
5100 TREE_SIDE_EFFECTS (t) = 1;
5101
5102 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
5103 }
fa78dbea 5104 if (targetm.calls.split_complex_arg
c53bdcf5
AM
5105 && TREE_CODE (type) == COMPLEX_TYPE)
5106 {
5107 tree elem_type = TREE_TYPE (type);
5108 enum machine_mode elem_mode = TYPE_MODE (elem_type);
5109 int elem_size = GET_MODE_SIZE (elem_mode);
5110
5111 if (elem_size < UNITS_PER_WORD)
5112 {
5113 rtx real_part, imag_part, dest_real, rr;
5114
5115 real_part = rs6000_va_arg (valist, elem_type);
5116 imag_part = rs6000_va_arg (valist, elem_type);
5117
5118 /* We're not returning the value here, but the address.
5119 real_part and imag_part are not contiguous, and we know
5120 there is space available to pack real_part next to
5121 imag_part. float _Complex is not promoted to
5122 double _Complex by the default promotion rules that
5123 promote float to double. */
5124 if (2 * elem_size > UNITS_PER_WORD)
5125 abort ();
5126
5127 real_part = gen_rtx_MEM (elem_mode, real_part);
5128 imag_part = gen_rtx_MEM (elem_mode, imag_part);
5129
5130 dest_real = adjust_address (imag_part, elem_mode, -elem_size);
5131 rr = gen_reg_rtx (elem_mode);
5132 emit_move_insn (rr, real_part);
5133 emit_move_insn (dest_real, rr);
5134
5135 return XEXP (dest_real, 0);
5136 }
5137 }
5138
5139 return std_expand_builtin_va_arg (valist, type);
c8c99a68 5140 }
dfafc897 5141
973a648b 5142 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 5143 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
5144 f_res = TREE_CHAIN (f_fpr);
5145 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
5146 f_sav = TREE_CHAIN (f_ovf);
5147
8ebecc3b 5148 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
5149 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
5150 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
5151 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
5152 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
5153
5154 size = int_size_in_bytes (type);
5155 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4ed78545 5156 align = 1;
4cc833b7 5157
4ed78545
AM
5158 if (AGGREGATE_TYPE_P (type)
5159 || TYPE_MODE (type) == TFmode
5160 || (!TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type))))
4cc833b7 5161 {
4ed78545
AM
5162 /* Aggregates, long doubles, and AltiVec vectors are passed by
5163 reference. */
dfafc897
FS
5164 indirect_p = 1;
5165 reg = gpr;
5166 n_reg = 1;
5167 sav_ofs = 0;
5168 sav_scale = 4;
d3294cd9
FS
5169 size = UNITS_PER_WORD;
5170 rsize = 1;
dfafc897 5171 }
4ed78545
AM
5172 else if (TARGET_HARD_FLOAT && TARGET_FPRS
5173 && (TYPE_MODE (type) == SFmode || TYPE_MODE (type) == DFmode))
dfafc897
FS
5174 {
5175 /* FP args go in FP registers, if present. */
5176 indirect_p = 0;
5177 reg = fpr;
5178 n_reg = 1;
5179 sav_ofs = 8*4;
5180 sav_scale = 8;
4ed78545
AM
5181 if (TYPE_MODE (type) == DFmode)
5182 align = 8;
4cc833b7 5183 }
dfafc897
FS
5184 else
5185 {
5186 /* Otherwise into GP registers. */
5187 indirect_p = 0;
5188 reg = gpr;
5189 n_reg = rsize;
5190 sav_ofs = 0;
5191 sav_scale = 4;
4ed78545
AM
5192 if (n_reg == 2)
5193 align = 8;
dfafc897
FS
5194 }
5195
a3c9585f 5196 /* Pull the value out of the saved registers.... */
dfafc897 5197
4ed78545 5198 lab_over = NULL_RTX;
dfafc897
FS
5199 addr_rtx = gen_reg_rtx (Pmode);
5200
4ed78545
AM
5201 /* AltiVec vectors never go in registers when -mabi=altivec. */
5202 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (TYPE_MODE (type)))
5203 align = 16;
5204 else
2c4974b7 5205 {
4ed78545
AM
5206 lab_false = gen_label_rtx ();
5207 lab_over = gen_label_rtx ();
dfafc897 5208
4ed78545
AM
5209 /* Long long and SPE vectors are aligned in the registers.
5210 As are any other 2 gpr item such as complex int due to a
5211 historical mistake. */
5212 u = reg;
5213 if (n_reg == 2)
41daaf0e
AH
5214 {
5215 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
5216 build_int_2 (n_reg - 1, 0));
4ed78545 5217 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg, u);
41daaf0e 5218 TREE_SIDE_EFFECTS (u) = 1;
41daaf0e 5219 }
2c4974b7 5220
4ed78545
AM
5221 emit_cmp_and_jump_insns
5222 (expand_expr (u, NULL_RTX, QImode, EXPAND_NORMAL),
5223 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
5224 lab_false);
5225
5226 t = sav;
41daaf0e
AH
5227 if (sav_ofs)
5228 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
2c4974b7 5229
41daaf0e
AH
5230 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
5231 build_int_2 (n_reg, 0));
5232 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 5233
41daaf0e
AH
5234 u = build1 (CONVERT_EXPR, integer_type_node, u);
5235 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 5236
41daaf0e
AH
5237 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
5238 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 5239
41daaf0e
AH
5240 t = build (PLUS_EXPR, ptr_type_node, t, u);
5241 TREE_SIDE_EFFECTS (t) = 1;
5242
5243 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
5244 if (r != addr_rtx)
5245 emit_move_insn (addr_rtx, r);
5246
5247 emit_jump_insn (gen_jump (lab_over));
5248 emit_barrier ();
dfafc897 5249
4ed78545
AM
5250 emit_label (lab_false);
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 },
5722 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
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
b6c9286a
MM
9685 if (XSTR (x, 0)[0] != '.')
9686 {
9687 switch (DEFAULT_ABI)
9688 {
9689 default:
9690 abort ();
9691
9692 case ABI_AIX:
9693 putc ('.', file);
9694 break;
9695
9696 case ABI_V4:
ee890fe2 9697 case ABI_DARWIN:
b6c9286a 9698 break;
b6c9286a
MM
9699 }
9700 }
f9da97f0
AP
9701 /* For macho, we need to check it see if we need a stub. */
9702 if (TARGET_MACHO)
9703 {
9704 const char *name = XSTR (x, 0);
a031e781 9705#if TARGET_MACHO
f9da97f0
AP
9706 if (machopic_classify_name (name) == MACHOPIC_UNDEFINED_FUNCTION)
9707 name = machopic_stub_name (name);
9708#endif
9709 assemble_name (file, name);
9710 }
9711 else if (TARGET_AIX)
9739c90c
JJ
9712 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9713 else
9714 assemble_name (file, XSTR (x, 0));
9878760c
RK
9715 return;
9716
9854d9ed
RK
9717 case 'Z':
9718 /* Like 'L', for last word of TImode. */
9719 if (GET_CODE (x) == REG)
5ebfb2ba 9720 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
9721 else if (GET_CODE (x) == MEM)
9722 {
9723 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9724 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9725 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 9726 else
d7624dc0 9727 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 9728 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9729 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9730 reg_names[SMALL_DATA_REG]);
9854d9ed 9731 }
5c23c401 9732 return;
0ac081f6 9733
a3170dc6 9734 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
9735 case 'y':
9736 {
9737 rtx tmp;
9738
9739 if (GET_CODE (x) != MEM)
9740 abort ();
9741
9742 tmp = XEXP (x, 0);
9743
993f19a8 9744 if (TARGET_E500)
a3170dc6
AH
9745 {
9746 /* Handle [reg]. */
9747 if (GET_CODE (tmp) == REG)
9748 {
9749 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
9750 break;
9751 }
9752 /* Handle [reg+UIMM]. */
9753 else if (GET_CODE (tmp) == PLUS &&
9754 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
9755 {
9756 int x;
9757
9758 if (GET_CODE (XEXP (tmp, 0)) != REG)
9759 abort ();
9760
9761 x = INTVAL (XEXP (tmp, 1));
9762 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
9763 break;
9764 }
9765
9766 /* Fall through. Must be [reg+reg]. */
9767 }
0ac081f6 9768 if (GET_CODE (tmp) == REG)
c62f2db5 9769 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
9770 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
9771 {
9772 if (REGNO (XEXP (tmp, 0)) == 0)
9773 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
9774 reg_names[ REGNO (XEXP (tmp, 0)) ]);
9775 else
9776 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
9777 reg_names[ REGNO (XEXP (tmp, 1)) ]);
9778 }
9779 else
9780 abort ();
9781 break;
9782 }
9854d9ed 9783
9878760c
RK
9784 case 0:
9785 if (GET_CODE (x) == REG)
9786 fprintf (file, "%s", reg_names[REGNO (x)]);
9787 else if (GET_CODE (x) == MEM)
9788 {
9789 /* We need to handle PRE_INC and PRE_DEC here, since we need to
9790 know the width from the mode. */
9791 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
9792 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
9793 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9794 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
9795 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
9796 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9797 else
a54d04b7 9798 output_address (XEXP (x, 0));
9878760c
RK
9799 }
9800 else
a54d04b7 9801 output_addr_const (file, x);
a85d226b 9802 return;
9878760c 9803
c4501e62
JJ
9804 case '&':
9805 assemble_name (file, rs6000_get_some_local_dynamic_name ());
9806 return;
9807
9878760c
RK
9808 default:
9809 output_operand_lossage ("invalid %%xn code");
9810 }
9811}
9812\f
9813/* Print the address of an operand. */
9814
9815void
a2369ed3 9816print_operand_address (FILE *file, rtx x)
9878760c
RK
9817{
9818 if (GET_CODE (x) == REG)
4697a36c 9819 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
9820 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
9821 || GET_CODE (x) == LABEL_REF)
9878760c
RK
9822 {
9823 output_addr_const (file, x);
ba5e43aa 9824 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9825 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9826 reg_names[SMALL_DATA_REG]);
9ebbca7d 9827 else if (TARGET_TOC)
a4f6c312 9828 abort ();
9878760c
RK
9829 }
9830 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
9831 {
9832 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
9833 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
9834 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 9835 else
4697a36c
MM
9836 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
9837 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
9838 }
9839 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
9840 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
9841 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
9842#if TARGET_ELF
9843 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9844 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
9845 {
9846 output_addr_const (file, XEXP (x, 1));
9847 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9848 }
c859cda6
DJ
9849#endif
9850#if TARGET_MACHO
9851 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9852 && CONSTANT_P (XEXP (x, 1)))
9853 {
9854 fprintf (file, "lo16(");
9855 output_addr_const (file, XEXP (x, 1));
9856 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9857 }
3cb999d8 9858#endif
4d588c14 9859 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 9860 {
2bfcf297 9861 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 9862 {
2bfcf297
DB
9863 rtx contains_minus = XEXP (x, 1);
9864 rtx minus, symref;
9865 const char *name;
9ebbca7d
GK
9866
9867 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 9868 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
9869 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
9870 contains_minus = XEXP (contains_minus, 0);
9871
2bfcf297
DB
9872 minus = XEXP (contains_minus, 0);
9873 symref = XEXP (minus, 0);
9874 XEXP (contains_minus, 0) = symref;
9875 if (TARGET_ELF)
9876 {
9877 char *newname;
9878
9879 name = XSTR (symref, 0);
9880 newname = alloca (strlen (name) + sizeof ("@toc"));
9881 strcpy (newname, name);
9882 strcat (newname, "@toc");
9883 XSTR (symref, 0) = newname;
9884 }
9885 output_addr_const (file, XEXP (x, 1));
9886 if (TARGET_ELF)
9887 XSTR (symref, 0) = name;
9ebbca7d
GK
9888 XEXP (contains_minus, 0) = minus;
9889 }
9890 else
9891 output_addr_const (file, XEXP (x, 1));
9892
9893 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9894 }
9878760c
RK
9895 else
9896 abort ();
9897}
9898\f
88cad84b 9899/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9900 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9901 is defined. It also needs to handle DI-mode objects on 64-bit
9902 targets. */
9903
9904static bool
a2369ed3 9905rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
9906{
9907#ifdef RELOCATABLE_NEEDS_FIXUP
9908 /* Special handling for SI values. */
9909 if (size == 4 && aligned_p)
9910 {
a2369ed3 9911 extern int in_toc_section (void);
301d03af
RS
9912 static int recurse = 0;
9913
9914 /* For -mrelocatable, we mark all addresses that need to be fixed up
9915 in the .fixup section. */
9916 if (TARGET_RELOCATABLE
9917 && !in_toc_section ()
9918 && !in_text_section ()
642af3be 9919 && !in_unlikely_text_section ()
301d03af
RS
9920 && !recurse
9921 && GET_CODE (x) != CONST_INT
9922 && GET_CODE (x) != CONST_DOUBLE
9923 && CONSTANT_P (x))
9924 {
9925 char buf[256];
9926
9927 recurse = 1;
9928 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9929 fixuplabelno++;
9930 ASM_OUTPUT_LABEL (asm_out_file, buf);
9931 fprintf (asm_out_file, "\t.long\t(");
9932 output_addr_const (asm_out_file, x);
9933 fprintf (asm_out_file, ")@fixup\n");
9934 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9935 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9936 fprintf (asm_out_file, "\t.long\t");
9937 assemble_name (asm_out_file, buf);
9938 fprintf (asm_out_file, "\n\t.previous\n");
9939 recurse = 0;
9940 return true;
9941 }
9942 /* Remove initial .'s to turn a -mcall-aixdesc function
9943 address into the address of the descriptor, not the function
9944 itself. */
9945 else if (GET_CODE (x) == SYMBOL_REF
9946 && XSTR (x, 0)[0] == '.'
9947 && DEFAULT_ABI == ABI_AIX)
9948 {
9949 const char *name = XSTR (x, 0);
9950 while (*name == '.')
9951 name++;
9952
9953 fprintf (asm_out_file, "\t.long\t%s\n", name);
9954 return true;
9955 }
9956 }
9957#endif /* RELOCATABLE_NEEDS_FIXUP */
9958 return default_assemble_integer (x, size, aligned_p);
9959}
93638d7a
AM
9960
9961#ifdef HAVE_GAS_HIDDEN
9962/* Emit an assembler directive to set symbol visibility for DECL to
9963 VISIBILITY_TYPE. */
9964
5add3202 9965static void
a2369ed3 9966rs6000_assemble_visibility (tree decl, int vis)
93638d7a 9967{
93638d7a
AM
9968 /* Functions need to have their entry point symbol visibility set as
9969 well as their descriptor symbol visibility. */
9970 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9971 {
25fdb4dc
RH
9972 static const char * const visibility_types[] = {
9973 NULL, "internal", "hidden", "protected"
9974 };
9975
9976 const char *name, *type;
93638d7a
AM
9977
9978 name = ((* targetm.strip_name_encoding)
9979 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9980 type = visibility_types[vis];
93638d7a 9981
25fdb4dc
RH
9982 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9983 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9984 }
25fdb4dc
RH
9985 else
9986 default_assemble_visibility (decl, vis);
93638d7a
AM
9987}
9988#endif
301d03af 9989\f
39a10a29 9990enum rtx_code
a2369ed3 9991rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
9992{
9993 /* Reversal of FP compares takes care -- an ordered compare
9994 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9995 if (mode == CCFPmode
9996 && (!flag_finite_math_only
9997 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
9998 || code == UNEQ || code == LTGT))
bab6226b 9999 return reverse_condition_maybe_unordered (code);
39a10a29 10000 else
bab6226b 10001 return reverse_condition (code);
39a10a29
GK
10002}
10003
39a10a29
GK
10004/* Generate a compare for CODE. Return a brand-new rtx that
10005 represents the result of the compare. */
a4f6c312 10006
39a10a29 10007static rtx
a2369ed3 10008rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
10009{
10010 enum machine_mode comp_mode;
10011 rtx compare_result;
10012
10013 if (rs6000_compare_fp_p)
10014 comp_mode = CCFPmode;
10015 else if (code == GTU || code == LTU
10016 || code == GEU || code == LEU)
10017 comp_mode = CCUNSmode;
10018 else
10019 comp_mode = CCmode;
10020
10021 /* First, the compare. */
10022 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
10023
10024 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
10025 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10026 && rs6000_compare_fp_p)
a3170dc6
AH
10027 {
10028 rtx cmp, or1, or2, or_result, compare_result2;
10029
423c1189
AH
10030 /* Note: The E500 comparison instructions set the GT bit (x +
10031 1), on success. This explains the mess. */
10032
a3170dc6
AH
10033 switch (code)
10034 {
423c1189 10035 case EQ: case UNEQ: case NE: case LTGT:
bc9ec0e0 10036 cmp = flag_finite_math_only
a3170dc6
AH
10037 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
10038 rs6000_compare_op1)
10039 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
10040 rs6000_compare_op1);
10041 break;
423c1189 10042 case GT: case GTU: case UNGT: case UNGE: case GE: case GEU:
bc9ec0e0 10043 cmp = flag_finite_math_only
a3170dc6
AH
10044 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
10045 rs6000_compare_op1)
10046 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
10047 rs6000_compare_op1);
10048 break;
423c1189 10049 case LT: case LTU: case UNLT: case UNLE: case LE: case LEU:
bc9ec0e0 10050 cmp = flag_finite_math_only
a3170dc6
AH
10051 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
10052 rs6000_compare_op1)
10053 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
10054 rs6000_compare_op1);
10055 break;
10056 default:
10057 abort ();
10058 }
10059
10060 /* Synthesize LE and GE from LT/GT || EQ. */
10061 if (code == LE || code == GE || code == LEU || code == GEU)
10062 {
a3170dc6
AH
10063 emit_insn (cmp);
10064
10065 switch (code)
10066 {
10067 case LE: code = LT; break;
10068 case GE: code = GT; break;
10069 case LEU: code = LT; break;
10070 case GEU: code = GT; break;
10071 default: abort ();
10072 }
10073
10074 or1 = gen_reg_rtx (SImode);
10075 or2 = gen_reg_rtx (SImode);
10076 or_result = gen_reg_rtx (CCEQmode);
10077 compare_result2 = gen_reg_rtx (CCFPmode);
10078
10079 /* Do the EQ. */
bc9ec0e0 10080 cmp = flag_finite_math_only
a3170dc6
AH
10081 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
10082 rs6000_compare_op1)
10083 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
10084 rs6000_compare_op1);
10085 emit_insn (cmp);
10086
423c1189
AH
10087 or1 = gen_rtx_GT (SImode, compare_result, const0_rtx);
10088 or2 = gen_rtx_GT (SImode, compare_result2, const0_rtx);
a3170dc6
AH
10089
10090 /* OR them together. */
10091 cmp = gen_rtx_SET (VOIDmode, or_result,
10092 gen_rtx_COMPARE (CCEQmode,
10093 gen_rtx_IOR (SImode, or1, or2),
10094 const_true_rtx));
10095 compare_result = or_result;
10096 code = EQ;
10097 }
10098 else
10099 {
a3170dc6 10100 if (code == NE || code == LTGT)
a3170dc6 10101 code = NE;
423c1189
AH
10102 else
10103 code = EQ;
a3170dc6
AH
10104 }
10105
10106 emit_insn (cmp);
10107 }
10108 else
10109 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
10110 gen_rtx_COMPARE (comp_mode,
10111 rs6000_compare_op0,
10112 rs6000_compare_op1)));
39a10a29 10113
ca5adc63 10114 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 10115 under flag_finite_math_only we don't bother. */
39a10a29 10116 if (rs6000_compare_fp_p
bc9ec0e0 10117 && ! flag_finite_math_only
993f19a8 10118 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
10119 && (code == LE || code == GE
10120 || code == UNEQ || code == LTGT
10121 || code == UNGT || code == UNLT))
10122 {
10123 enum rtx_code or1, or2;
10124 rtx or1_rtx, or2_rtx, compare2_rtx;
10125 rtx or_result = gen_reg_rtx (CCEQmode);
10126
10127 switch (code)
10128 {
10129 case LE: or1 = LT; or2 = EQ; break;
10130 case GE: or1 = GT; or2 = EQ; break;
10131 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
10132 case LTGT: or1 = LT; or2 = GT; break;
10133 case UNGT: or1 = UNORDERED; or2 = GT; break;
10134 case UNLT: or1 = UNORDERED; or2 = LT; break;
10135 default: abort ();
10136 }
10137 validate_condition_mode (or1, comp_mode);
10138 validate_condition_mode (or2, comp_mode);
1c563bed
KH
10139 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
10140 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
10141 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
10142 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
10143 const_true_rtx);
10144 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
10145
10146 compare_result = or_result;
10147 code = EQ;
10148 }
10149
10150 validate_condition_mode (code, GET_MODE (compare_result));
10151
1c563bed 10152 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
10153}
10154
10155
10156/* Emit the RTL for an sCOND pattern. */
10157
10158void
a2369ed3 10159rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
10160{
10161 rtx condition_rtx;
10162 enum machine_mode op_mode;
b7053a3f 10163 enum rtx_code cond_code;
39a10a29
GK
10164
10165 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
10166 cond_code = GET_CODE (condition_rtx);
10167
423c1189
AH
10168 if (TARGET_E500 && rs6000_compare_fp_p
10169 && !TARGET_FPRS && TARGET_HARD_FLOAT)
10170 {
10171 rtx t;
10172
10173 PUT_MODE (condition_rtx, SImode);
10174 t = XEXP (condition_rtx, 0);
10175
10176 if (cond_code != NE && cond_code != EQ)
10177 abort ();
10178
10179 if (cond_code == NE)
10180 emit_insn (gen_e500_flip_gt_bit (t, t));
10181
10182 emit_insn (gen_move_from_CR_gt_bit (result, t));
10183 return;
10184 }
10185
b7053a3f
GK
10186 if (cond_code == NE
10187 || cond_code == GE || cond_code == LE
10188 || cond_code == GEU || cond_code == LEU
10189 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
10190 {
10191 rtx not_result = gen_reg_rtx (CCEQmode);
10192 rtx not_op, rev_cond_rtx;
10193 enum machine_mode cc_mode;
10194
10195 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
10196
1c563bed 10197 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 10198 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
10199 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
10200 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
10201 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
10202 }
39a10a29
GK
10203
10204 op_mode = GET_MODE (rs6000_compare_op0);
10205 if (op_mode == VOIDmode)
10206 op_mode = GET_MODE (rs6000_compare_op1);
10207
10208 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
10209 {
10210 PUT_MODE (condition_rtx, DImode);
10211 convert_move (result, condition_rtx, 0);
10212 }
10213 else
10214 {
10215 PUT_MODE (condition_rtx, SImode);
10216 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
10217 }
10218}
10219
39a10a29
GK
10220/* Emit a branch of kind CODE to location LOC. */
10221
10222void
a2369ed3 10223rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
10224{
10225 rtx condition_rtx, loc_ref;
10226
10227 condition_rtx = rs6000_generate_compare (code);
10228 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
10229 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
10230 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
10231 loc_ref, pc_rtx)));
10232}
10233
12a4e8c5
GK
10234/* Return the string to output a conditional branch to LABEL, which is
10235 the operand number of the label, or -1 if the branch is really a
10236 conditional return.
10237
10238 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
10239 condition code register and its mode specifies what kind of
10240 comparison we made.
10241
a0ab749a 10242 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
10243
10244 INSN is the insn. */
10245
10246char *
a2369ed3 10247output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
10248{
10249 static char string[64];
10250 enum rtx_code code = GET_CODE (op);
10251 rtx cc_reg = XEXP (op, 0);
10252 enum machine_mode mode = GET_MODE (cc_reg);
10253 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 10254 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
10255 int really_reversed = reversed ^ need_longbranch;
10256 char *s = string;
10257 const char *ccode;
10258 const char *pred;
10259 rtx note;
10260
39a10a29
GK
10261 validate_condition_mode (code, mode);
10262
10263 /* Work out which way this really branches. We could use
10264 reverse_condition_maybe_unordered here always but this
10265 makes the resulting assembler clearer. */
12a4e8c5 10266 if (really_reversed)
de40e1df
DJ
10267 {
10268 /* Reversal of FP compares takes care -- an ordered compare
10269 becomes an unordered compare and vice versa. */
10270 if (mode == CCFPmode)
10271 code = reverse_condition_maybe_unordered (code);
10272 else
10273 code = reverse_condition (code);
10274 }
12a4e8c5 10275
993f19a8 10276 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
10277 {
10278 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
10279 to the GT bit. */
10280 if (code == EQ)
10281 /* Opposite of GT. */
a3170dc6 10282 code = GT;
423c1189
AH
10283 else if (code == NE)
10284 code = UNLE;
a3170dc6
AH
10285 else
10286 abort ();
10287 }
10288
39a10a29 10289 switch (code)
12a4e8c5
GK
10290 {
10291 /* Not all of these are actually distinct opcodes, but
10292 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
10293 case NE: case LTGT:
10294 ccode = "ne"; break;
10295 case EQ: case UNEQ:
10296 ccode = "eq"; break;
10297 case GE: case GEU:
10298 ccode = "ge"; break;
10299 case GT: case GTU: case UNGT:
10300 ccode = "gt"; break;
10301 case LE: case LEU:
10302 ccode = "le"; break;
10303 case LT: case LTU: case UNLT:
10304 ccode = "lt"; break;
12a4e8c5
GK
10305 case UNORDERED: ccode = "un"; break;
10306 case ORDERED: ccode = "nu"; break;
10307 case UNGE: ccode = "nl"; break;
10308 case UNLE: ccode = "ng"; break;
10309 default:
a4f6c312 10310 abort ();
12a4e8c5
GK
10311 }
10312
94a54f47
GK
10313 /* Maybe we have a guess as to how likely the branch is.
10314 The old mnemonics don't have a way to specify this information. */
f4857b9b 10315 pred = "";
12a4e8c5
GK
10316 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
10317 if (note != NULL_RTX)
10318 {
10319 /* PROB is the difference from 50%. */
10320 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
10321
10322 /* Only hint for highly probable/improbable branches on newer
10323 cpus as static prediction overrides processor dynamic
10324 prediction. For older cpus we may as well always hint, but
10325 assume not taken for branches that are very close to 50% as a
10326 mispredicted taken branch is more expensive than a
10327 mispredicted not-taken branch. */
ec507f2d 10328 if (rs6000_always_hint
f4857b9b
AM
10329 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
10330 {
10331 if (abs (prob) > REG_BR_PROB_BASE / 20
10332 && ((prob > 0) ^ need_longbranch))
7f3d8013 10333 pred = "+";
f4857b9b
AM
10334 else
10335 pred = "-";
10336 }
12a4e8c5 10337 }
12a4e8c5
GK
10338
10339 if (label == NULL)
94a54f47 10340 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 10341 else
94a54f47 10342 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 10343
37c67319 10344 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 10345 Assume they'd only be the first character.... */
37c67319
GK
10346 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
10347 *s++ = '%';
94a54f47 10348 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
10349
10350 if (label != NULL)
10351 {
10352 /* If the branch distance was too far, we may have to use an
10353 unconditional branch to go the distance. */
10354 if (need_longbranch)
44518ddd 10355 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
10356 else
10357 s += sprintf (s, ",%s", label);
10358 }
10359
10360 return string;
10361}
50a0b056 10362
423c1189
AH
10363/* Return the string to flip the GT bit on a CR. */
10364char *
10365output_e500_flip_gt_bit (rtx dst, rtx src)
10366{
10367 static char string[64];
10368 int a, b;
10369
10370 if (GET_CODE (dst) != REG || ! CR_REGNO_P (REGNO (dst))
10371 || GET_CODE (src) != REG || ! CR_REGNO_P (REGNO (src)))
10372 abort ();
10373
10374 /* GT bit. */
10375 a = 4 * (REGNO (dst) - CR0_REGNO) + 1;
10376 b = 4 * (REGNO (src) - CR0_REGNO) + 1;
10377
10378 sprintf (string, "crnot %d,%d", a, b);
10379 return string;
10380}
10381
50a0b056
GK
10382/* Emit a conditional move: move TRUE_COND to DEST if OP of the
10383 operands of the last comparison is nonzero/true, FALSE_COND if it
10384 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 10385
50a0b056 10386int
a2369ed3 10387rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
10388{
10389 enum rtx_code code = GET_CODE (op);
10390 rtx op0 = rs6000_compare_op0;
10391 rtx op1 = rs6000_compare_op1;
10392 REAL_VALUE_TYPE c1;
3148ad6d
DJ
10393 enum machine_mode compare_mode = GET_MODE (op0);
10394 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
10395 rtx temp;
10396
a3c9585f 10397 /* These modes should always match. */
a3170dc6
AH
10398 if (GET_MODE (op1) != compare_mode
10399 /* In the isel case however, we can use a compare immediate, so
10400 op1 may be a small constant. */
10401 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 10402 return 0;
178c3eff 10403 if (GET_MODE (true_cond) != result_mode)
3148ad6d 10404 return 0;
178c3eff 10405 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
10406 return 0;
10407
50a0b056 10408 /* First, work out if the hardware can do this at all, or
a3c9585f 10409 if it's too slow.... */
50a0b056 10410 if (! rs6000_compare_fp_p)
a3170dc6
AH
10411 {
10412 if (TARGET_ISEL)
10413 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
10414 return 0;
10415 }
fef98bf2
AH
10416 else if (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS
10417 && GET_MODE_CLASS (compare_mode) == MODE_FLOAT)
10418 return 0;
50a0b056
GK
10419
10420 /* Eliminate half of the comparisons by switching operands, this
10421 makes the remaining code simpler. */
10422 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 10423 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
10424 {
10425 code = reverse_condition_maybe_unordered (code);
10426 temp = true_cond;
10427 true_cond = false_cond;
10428 false_cond = temp;
10429 }
10430
10431 /* UNEQ and LTGT take four instructions for a comparison with zero,
10432 it'll probably be faster to use a branch here too. */
bc9ec0e0 10433 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
10434 return 0;
10435
10436 if (GET_CODE (op1) == CONST_DOUBLE)
10437 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
10438
b6d08ca1 10439 /* We're going to try to implement comparisons by performing
50a0b056
GK
10440 a subtract, then comparing against zero. Unfortunately,
10441 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 10442 know that the operand is finite and the comparison
50a0b056 10443 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 10444 if (HONOR_INFINITIES (compare_mode)
50a0b056 10445 && code != GT && code != UNGE
045572c7 10446 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
10447 /* Constructs of the form (a OP b ? a : b) are safe. */
10448 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
10449 || (! rtx_equal_p (op0, true_cond)
10450 && ! rtx_equal_p (op1, true_cond))))
10451 return 0;
10452 /* At this point we know we can use fsel. */
10453
10454 /* Reduce the comparison to a comparison against zero. */
3148ad6d 10455 temp = gen_reg_rtx (compare_mode);
50a0b056 10456 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10457 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 10458 op0 = temp;
3148ad6d 10459 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
10460
10461 /* If we don't care about NaNs we can reduce some of the comparisons
10462 down to faster ones. */
bc9ec0e0 10463 if (! HONOR_NANS (compare_mode))
50a0b056
GK
10464 switch (code)
10465 {
10466 case GT:
10467 code = LE;
10468 temp = true_cond;
10469 true_cond = false_cond;
10470 false_cond = temp;
10471 break;
10472 case UNGE:
10473 code = GE;
10474 break;
10475 case UNEQ:
10476 code = EQ;
10477 break;
10478 default:
10479 break;
10480 }
10481
10482 /* Now, reduce everything down to a GE. */
10483 switch (code)
10484 {
10485 case GE:
10486 break;
10487
10488 case LE:
3148ad6d
DJ
10489 temp = gen_reg_rtx (compare_mode);
10490 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10491 op0 = temp;
10492 break;
10493
10494 case ORDERED:
3148ad6d
DJ
10495 temp = gen_reg_rtx (compare_mode);
10496 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
10497 op0 = temp;
10498 break;
10499
10500 case EQ:
3148ad6d 10501 temp = gen_reg_rtx (compare_mode);
50a0b056 10502 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
10503 gen_rtx_NEG (compare_mode,
10504 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
10505 op0 = temp;
10506 break;
10507
10508 case UNGE:
bc9ec0e0 10509 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 10510 temp = gen_reg_rtx (result_mode);
50a0b056 10511 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10512 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10513 gen_rtx_GE (VOIDmode,
10514 op0, op1),
10515 true_cond, false_cond)));
bc9ec0e0
GK
10516 false_cond = true_cond;
10517 true_cond = temp;
50a0b056 10518
3148ad6d
DJ
10519 temp = gen_reg_rtx (compare_mode);
10520 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10521 op0 = temp;
10522 break;
10523
10524 case GT:
bc9ec0e0 10525 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 10526 temp = gen_reg_rtx (result_mode);
50a0b056 10527 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10528 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10529 gen_rtx_GE (VOIDmode,
10530 op0, op1),
10531 true_cond, false_cond)));
bc9ec0e0
GK
10532 true_cond = false_cond;
10533 false_cond = temp;
50a0b056 10534
3148ad6d
DJ
10535 temp = gen_reg_rtx (compare_mode);
10536 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10537 op0 = temp;
10538 break;
10539
10540 default:
10541 abort ();
10542 }
10543
10544 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 10545 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10546 gen_rtx_GE (VOIDmode,
10547 op0, op1),
10548 true_cond, false_cond)));
10549 return 1;
10550}
10551
a3170dc6
AH
10552/* Same as above, but for ints (isel). */
10553
10554static int
a2369ed3 10555rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
10556{
10557 rtx condition_rtx, cr;
10558
10559 /* All isel implementations thus far are 32-bits. */
10560 if (GET_MODE (rs6000_compare_op0) != SImode)
10561 return 0;
10562
10563 /* We still have to do the compare, because isel doesn't do a
10564 compare, it just looks at the CRx bits set by a previous compare
10565 instruction. */
10566 condition_rtx = rs6000_generate_compare (GET_CODE (op));
10567 cr = XEXP (condition_rtx, 0);
10568
10569 if (GET_MODE (cr) == CCmode)
10570 emit_insn (gen_isel_signed (dest, condition_rtx,
10571 true_cond, false_cond, cr));
10572 else
10573 emit_insn (gen_isel_unsigned (dest, condition_rtx,
10574 true_cond, false_cond, cr));
10575
10576 return 1;
10577}
10578
10579const char *
a2369ed3 10580output_isel (rtx *operands)
a3170dc6
AH
10581{
10582 enum rtx_code code;
10583
10584 code = GET_CODE (operands[1]);
10585 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
10586 {
10587 PUT_CODE (operands[1], reverse_condition (code));
10588 return "isel %0,%3,%2,%j1";
10589 }
10590 else
10591 return "isel %0,%2,%3,%j1";
10592}
10593
50a0b056 10594void
a2369ed3 10595rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
10596{
10597 enum machine_mode mode = GET_MODE (op0);
5dc8d536 10598 enum rtx_code c;
50a0b056 10599 rtx target;
5dc8d536
AH
10600
10601 if (code == SMAX || code == SMIN)
10602 c = GE;
10603 else
10604 c = GEU;
10605
50a0b056 10606 if (code == SMAX || code == UMAX)
5dc8d536 10607 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10608 op0, op1, mode, 0);
10609 else
5dc8d536 10610 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10611 op1, op0, mode, 0);
10612 if (target == NULL_RTX)
10613 abort ();
10614 if (target != dest)
10615 emit_move_insn (dest, target);
10616}
46c07df8 10617
a9baceb1
GK
10618/* Emit instructions to move SRC to DST. Called by splitters for
10619 multi-register moves. It will emit at most one instruction for
10620 each register that is accessed; that is, it won't emit li/lis pairs
10621 (or equivalent for 64-bit code). One of SRC or DST must be a hard
10622 register. */
46c07df8 10623
46c07df8 10624void
a9baceb1 10625rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 10626{
a9baceb1
GK
10627 /* The register number of the first register being moved. */
10628 int reg;
10629 /* The mode that is to be moved. */
10630 enum machine_mode mode;
10631 /* The mode that the move is being done in, and its size. */
10632 enum machine_mode reg_mode;
10633 int reg_mode_size;
10634 /* The number of registers that will be moved. */
10635 int nregs;
10636
10637 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
10638 mode = GET_MODE (dst);
10639 nregs = HARD_REGNO_NREGS (reg, mode);
10640 if (FP_REGNO_P (reg))
10641 reg_mode = DFmode;
10642 else if (ALTIVEC_REGNO_P (reg))
10643 reg_mode = V16QImode;
10644 else
10645 reg_mode = word_mode;
10646 reg_mode_size = GET_MODE_SIZE (reg_mode);
46c07df8 10647
a9baceb1
GK
10648 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
10649 abort ();
10650
10651 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
10652 {
10653 /* Move register range backwards, if we might have destructive
10654 overlap. */
10655 int i;
10656 for (i = nregs - 1; i >= 0; i--)
10657 emit_insn (gen_rtx_SET (VOIDmode,
10658 simplify_gen_subreg (reg_mode, dst, mode,
10659 i * reg_mode_size),
10660 simplify_gen_subreg (reg_mode, src, mode,
10661 i * reg_mode_size)));
10662 }
46c07df8
HP
10663 else
10664 {
a9baceb1
GK
10665 int i;
10666 int j = -1;
10667 bool used_update = false;
46c07df8 10668
a9baceb1 10669 if (GET_CODE (src) == MEM && INT_REGNO_P (reg))
46c07df8
HP
10670 {
10671 rtx breg;
3a1f863f 10672
a9baceb1
GK
10673 if (GET_CODE (XEXP (src, 0)) == PRE_INC
10674 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
10675 {
10676 rtx delta_rtx;
a9baceb1
GK
10677 breg = XEXP (XEXP (src, 0), 0);
10678 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
10679 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
10680 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
10681 emit_insn (TARGET_32BIT
10682 ? gen_addsi3 (breg, breg, delta_rtx)
10683 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10684 src = gen_rtx_MEM (mode, breg);
10685 }
10686
10687 /* We have now address involving an base register only.
10688 If we use one of the registers to address memory,
10689 we have change that register last. */
10690
10691 breg = (GET_CODE (XEXP (src, 0)) == PLUS
10692 ? XEXP (XEXP (src, 0), 0)
10693 : XEXP (src, 0));
10694
10695 if (!REG_P (breg))
10696 abort();
10697
10698 if (REGNO (breg) >= REGNO (dst)
10699 && REGNO (breg) < REGNO (dst) + nregs)
10700 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
10701 }
10702
a9baceb1 10703 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
10704 {
10705 rtx breg;
10706
a9baceb1
GK
10707 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
10708 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
10709 {
10710 rtx delta_rtx;
a9baceb1
GK
10711 breg = XEXP (XEXP (dst, 0), 0);
10712 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
10713 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
10714 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
10715
10716 /* We have to update the breg before doing the store.
10717 Use store with update, if available. */
10718
10719 if (TARGET_UPDATE)
10720 {
a9baceb1
GK
10721 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
10722 emit_insn (TARGET_32BIT
10723 ? gen_movsi_update (breg, breg, delta_rtx, nsrc)
10724 : gen_movdi_update (breg, breg, delta_rtx, nsrc));
10725 used_update = true;
3a1f863f
DE
10726 }
10727 else
a9baceb1
GK
10728 emit_insn (TARGET_32BIT
10729 ? gen_addsi3 (breg, breg, delta_rtx)
10730 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10731 dst = gen_rtx_MEM (mode, breg);
10732 }
10733 }
10734
46c07df8 10735 for (i = 0; i < nregs; i++)
3a1f863f
DE
10736 {
10737 /* Calculate index to next subword. */
10738 ++j;
10739 if (j == nregs)
10740 j = 0;
46c07df8 10741
a9baceb1
GK
10742 /* If compiler already emited move of first word by
10743 store with update, no need to do anything. */
3a1f863f 10744 if (j == 0 && used_update)
a9baceb1
GK
10745 continue;
10746
10747 emit_insn (gen_rtx_SET (VOIDmode,
10748 simplify_gen_subreg (reg_mode, dst, mode,
10749 j * reg_mode_size),
10750 simplify_gen_subreg (reg_mode, src, mode,
10751 j * reg_mode_size)));
3a1f863f 10752 }
46c07df8
HP
10753 }
10754}
10755
12a4e8c5 10756\f
a4f6c312
SS
10757/* This page contains routines that are used to determine what the
10758 function prologue and epilogue code will do and write them out. */
9878760c 10759
a4f6c312
SS
10760/* Return the first fixed-point register that is required to be
10761 saved. 32 if none. */
9878760c
RK
10762
10763int
863d938c 10764first_reg_to_save (void)
9878760c
RK
10765{
10766 int first_reg;
10767
10768 /* Find lowest numbered live register. */
10769 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
10770 if (regs_ever_live[first_reg]
10771 && (! call_used_regs[first_reg]
1db02437 10772 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10773 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10774 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
10775 break;
10776
ee890fe2 10777#if TARGET_MACHO
93638d7a
AM
10778 if (flag_pic
10779 && current_function_uses_pic_offset_table
10780 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 10781 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
10782#endif
10783
9878760c
RK
10784 return first_reg;
10785}
10786
10787/* Similar, for FP regs. */
10788
10789int
863d938c 10790first_fp_reg_to_save (void)
9878760c
RK
10791{
10792 int first_reg;
10793
10794 /* Find lowest numbered live register. */
10795 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
10796 if (regs_ever_live[first_reg])
10797 break;
10798
10799 return first_reg;
10800}
00b960c7
AH
10801
10802/* Similar, for AltiVec regs. */
10803
10804static int
863d938c 10805first_altivec_reg_to_save (void)
00b960c7
AH
10806{
10807 int i;
10808
10809 /* Stack frame remains as is unless we are in AltiVec ABI. */
10810 if (! TARGET_ALTIVEC_ABI)
10811 return LAST_ALTIVEC_REGNO + 1;
10812
10813 /* Find lowest numbered live register. */
10814 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
10815 if (regs_ever_live[i])
10816 break;
10817
10818 return i;
10819}
10820
10821/* Return a 32-bit mask of the AltiVec registers we need to set in
10822 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
10823 the 32-bit word is 0. */
10824
10825static unsigned int
863d938c 10826compute_vrsave_mask (void)
00b960c7
AH
10827{
10828 unsigned int i, mask = 0;
10829
10830 /* First, find out if we use _any_ altivec registers. */
10831 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10832 if (regs_ever_live[i])
10833 mask |= ALTIVEC_REG_BIT (i);
10834
10835 if (mask == 0)
10836 return mask;
10837
00b960c7
AH
10838 /* Next, remove the argument registers from the set. These must
10839 be in the VRSAVE mask set by the caller, so we don't need to add
10840 them in again. More importantly, the mask we compute here is
10841 used to generate CLOBBERs in the set_vrsave insn, and we do not
10842 wish the argument registers to die. */
a6cf80f2 10843 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
10844 mask &= ~ALTIVEC_REG_BIT (i);
10845
10846 /* Similarly, remove the return value from the set. */
10847 {
10848 bool yes = false;
10849 diddle_return_value (is_altivec_return_reg, &yes);
10850 if (yes)
10851 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
10852 }
10853
10854 return mask;
10855}
10856
10857static void
a2369ed3 10858is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
10859{
10860 bool *yes = (bool *) xyes;
10861 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
10862 *yes = true;
10863}
10864
4697a36c
MM
10865\f
10866/* Calculate the stack information for the current function. This is
10867 complicated by having two separate calling sequences, the AIX calling
10868 sequence and the V.4 calling sequence.
10869
592696dd 10870 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 10871 32-bit 64-bit
4697a36c 10872 SP----> +---------------------------------------+
a260abc9 10873 | back chain to caller | 0 0
4697a36c 10874 +---------------------------------------+
a260abc9 10875 | saved CR | 4 8 (8-11)
4697a36c 10876 +---------------------------------------+
a260abc9 10877 | saved LR | 8 16
4697a36c 10878 +---------------------------------------+
a260abc9 10879 | reserved for compilers | 12 24
4697a36c 10880 +---------------------------------------+
a260abc9 10881 | reserved for binders | 16 32
4697a36c 10882 +---------------------------------------+
a260abc9 10883 | saved TOC pointer | 20 40
4697a36c 10884 +---------------------------------------+
a260abc9 10885 | Parameter save area (P) | 24 48
4697a36c 10886 +---------------------------------------+
a260abc9 10887 | Alloca space (A) | 24+P etc.
802a0058 10888 +---------------------------------------+
a7df97e6 10889 | Local variable space (L) | 24+P+A
4697a36c 10890 +---------------------------------------+
a7df97e6 10891 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 10892 +---------------------------------------+
00b960c7
AH
10893 | Save area for AltiVec registers (W) | 24+P+A+L+X
10894 +---------------------------------------+
10895 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
10896 +---------------------------------------+
10897 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 10898 +---------------------------------------+
00b960c7
AH
10899 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
10900 +---------------------------------------+
10901 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
10902 +---------------------------------------+
10903 old SP->| back chain to caller's caller |
10904 +---------------------------------------+
10905
5376a30c
KR
10906 The required alignment for AIX configurations is two words (i.e., 8
10907 or 16 bytes).
10908
10909
4697a36c
MM
10910 V.4 stack frames look like:
10911
10912 SP----> +---------------------------------------+
10913 | back chain to caller | 0
10914 +---------------------------------------+
5eb387b8 10915 | caller's saved LR | 4
4697a36c
MM
10916 +---------------------------------------+
10917 | Parameter save area (P) | 8
10918 +---------------------------------------+
a7df97e6
MM
10919 | Alloca space (A) | 8+P
10920 +---------------------------------------+
10921 | Varargs save area (V) | 8+P+A
10922 +---------------------------------------+
10923 | Local variable space (L) | 8+P+A+V
10924 +---------------------------------------+
10925 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10926 +---------------------------------------+
00b960c7
AH
10927 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10928 +---------------------------------------+
10929 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10930 +---------------------------------------+
10931 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10932 +---------------------------------------+
a3170dc6
AH
10933 | SPE: area for 64-bit GP registers |
10934 +---------------------------------------+
10935 | SPE alignment padding |
10936 +---------------------------------------+
00b960c7 10937 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10938 +---------------------------------------+
00b960c7 10939 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10940 +---------------------------------------+
00b960c7 10941 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10942 +---------------------------------------+
10943 old SP->| back chain to caller's caller |
10944 +---------------------------------------+
b6c9286a 10945
5376a30c
KR
10946 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10947 given. (But note below and in sysv4.h that we require only 8 and
10948 may round up the size of our stack frame anyways. The historical
10949 reason is early versions of powerpc-linux which didn't properly
10950 align the stack at program startup. A happy side-effect is that
10951 -mno-eabi libraries can be used with -meabi programs.)
10952
50d440bc 10953 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10954 the stack alignment requirements may differ. If -mno-eabi is not
10955 given, the required stack alignment is 8 bytes; if -mno-eabi is
10956 given, the required alignment is 16 bytes. (But see V.4 comment
10957 above.) */
4697a36c 10958
61b2fbe7
MM
10959#ifndef ABI_STACK_BOUNDARY
10960#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10961#endif
10962
d1d0c603 10963static rs6000_stack_t *
863d938c 10964rs6000_stack_info (void)
4697a36c
MM
10965{
10966 static rs6000_stack_t info, zero_info;
10967 rs6000_stack_t *info_ptr = &info;
327e5343 10968 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 10969 int ehrd_size;
44688022 10970 HOST_WIDE_INT non_fixed_size;
4697a36c 10971
a4f6c312 10972 /* Zero all fields portably. */
4697a36c
MM
10973 info = zero_info;
10974
c19de7aa
AH
10975 if (TARGET_SPE)
10976 {
10977 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10978 if (cfun->machine->insn_chain_scanned_p == 0)
10979 {
10980 cfun->machine->insn_chain_scanned_p = 1;
10981 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10982 }
c19de7aa
AH
10983 }
10984
a4f6c312 10985 /* Select which calling sequence. */
178274da 10986 info_ptr->abi = DEFAULT_ABI;
9878760c 10987
a4f6c312 10988 /* Calculate which registers need to be saved & save area size. */
4697a36c 10989 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10990 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10991 even if it currently looks like we won't. */
2bfcf297 10992 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10993 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10994 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10995 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
10996 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
10997 else
10998 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 10999
a3170dc6
AH
11000 /* For the SPE, we have an additional upper 32-bits on each GPR.
11001 Ideally we should save the entire 64-bits only when the upper
11002 half is used in SIMD instructions. Since we only record
11003 registers live (not the size they are used in), this proves
11004 difficult because we'd have to traverse the instruction chain at
11005 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
11006 so we opt to save the GPRs in 64-bits always if but one register
11007 gets used in 64-bits. Otherwise, all the registers in the frame
11008 get saved in 32-bits.
a3170dc6 11009
c19de7aa 11010 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 11011 traditional GP save area will be empty. */
c19de7aa 11012 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11013 info_ptr->gp_size = 0;
11014
4697a36c
MM
11015 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
11016 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
11017
00b960c7
AH
11018 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
11019 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
11020 - info_ptr->first_altivec_reg_save);
11021
592696dd 11022 /* Does this function call anything? */
71f123ca
FS
11023 info_ptr->calls_p = (! current_function_is_leaf
11024 || cfun->machine->ra_needs_full_frame);
b6c9286a 11025
a4f6c312 11026 /* Determine if we need to save the link register. */
71f123ca 11027 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
11028 || (DEFAULT_ABI == ABI_AIX
11029 && current_function_profile
11030 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
11031#ifdef TARGET_RELOCATABLE
11032 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
11033#endif
11034 || (info_ptr->first_fp_reg_save != 64
11035 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 11036 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 11037 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
11038 || (DEFAULT_ABI == ABI_DARWIN
11039 && flag_pic
11040 && current_function_uses_pic_offset_table)
4697a36c
MM
11041 || info_ptr->calls_p)
11042 {
11043 info_ptr->lr_save_p = 1;
9ebbca7d 11044 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
11045 }
11046
9ebbca7d
GK
11047 /* Determine if we need to save the condition code registers. */
11048 if (regs_ever_live[CR2_REGNO]
11049 || regs_ever_live[CR3_REGNO]
11050 || regs_ever_live[CR4_REGNO])
4697a36c
MM
11051 {
11052 info_ptr->cr_save_p = 1;
178274da 11053 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
11054 info_ptr->cr_size = reg_size;
11055 }
11056
83720594
RH
11057 /* If the current function calls __builtin_eh_return, then we need
11058 to allocate stack space for registers that will hold data for
11059 the exception handler. */
11060 if (current_function_calls_eh_return)
11061 {
11062 unsigned int i;
11063 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
11064 continue;
a3170dc6
AH
11065
11066 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
11067 ehrd_size = i * (TARGET_SPE_ABI
11068 && info_ptr->spe_64bit_regs_used != 0
11069 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
11070 }
11071 else
11072 ehrd_size = 0;
11073
592696dd 11074 /* Determine various sizes. */
4697a36c
MM
11075 info_ptr->reg_size = reg_size;
11076 info_ptr->fixed_size = RS6000_SAVE_AREA;
11077 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 11078 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312 11079 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
03e007d7 11080 TARGET_ALTIVEC ? 16 : 8);
00b960c7 11081
c19de7aa 11082 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11083 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
11084 else
11085 info_ptr->spe_gp_size = 0;
11086
4d774ff8
HP
11087 if (TARGET_ALTIVEC_ABI)
11088 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 11089 else
4d774ff8
HP
11090 info_ptr->vrsave_mask = 0;
11091
11092 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
11093 info_ptr->vrsave_size = 4;
11094 else
11095 info_ptr->vrsave_size = 0;
b6c9286a 11096
592696dd 11097 /* Calculate the offsets. */
178274da 11098 switch (DEFAULT_ABI)
4697a36c 11099 {
b6c9286a 11100 case ABI_NONE:
24d304eb 11101 default:
b6c9286a
MM
11102 abort ();
11103
11104 case ABI_AIX:
ee890fe2 11105 case ABI_DARWIN:
b6c9286a
MM
11106 info_ptr->fp_save_offset = - info_ptr->fp_size;
11107 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
11108
11109 if (TARGET_ALTIVEC_ABI)
11110 {
11111 info_ptr->vrsave_save_offset
11112 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
11113
11114 /* Align stack so vector save area is on a quadword boundary. */
11115 if (info_ptr->altivec_size != 0)
11116 info_ptr->altivec_padding_size
11117 = 16 - (-info_ptr->vrsave_save_offset % 16);
11118 else
11119 info_ptr->altivec_padding_size = 0;
11120
11121 info_ptr->altivec_save_offset
11122 = info_ptr->vrsave_save_offset
11123 - info_ptr->altivec_padding_size
11124 - info_ptr->altivec_size;
11125
11126 /* Adjust for AltiVec case. */
11127 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
11128 }
11129 else
11130 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
11131 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
11132 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
11133 break;
11134
11135 case ABI_V4:
b6c9286a
MM
11136 info_ptr->fp_save_offset = - info_ptr->fp_size;
11137 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 11138 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 11139
c19de7aa 11140 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
11141 {
11142 /* Align stack so SPE GPR save area is aligned on a
11143 double-word boundary. */
11144 if (info_ptr->spe_gp_size != 0)
11145 info_ptr->spe_padding_size
11146 = 8 - (-info_ptr->cr_save_offset % 8);
11147 else
11148 info_ptr->spe_padding_size = 0;
11149
11150 info_ptr->spe_gp_save_offset
11151 = info_ptr->cr_save_offset
11152 - info_ptr->spe_padding_size
11153 - info_ptr->spe_gp_size;
11154
11155 /* Adjust for SPE case. */
11156 info_ptr->toc_save_offset
11157 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
11158 }
11159 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
11160 {
11161 info_ptr->vrsave_save_offset
11162 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
11163
11164 /* Align stack so vector save area is on a quadword boundary. */
11165 if (info_ptr->altivec_size != 0)
11166 info_ptr->altivec_padding_size
11167 = 16 - (-info_ptr->vrsave_save_offset % 16);
11168 else
11169 info_ptr->altivec_padding_size = 0;
11170
11171 info_ptr->altivec_save_offset
11172 = info_ptr->vrsave_save_offset
11173 - info_ptr->altivec_padding_size
11174 - info_ptr->altivec_size;
11175
11176 /* Adjust for AltiVec case. */
11177 info_ptr->toc_save_offset
11178 = info_ptr->altivec_save_offset - info_ptr->toc_size;
11179 }
11180 else
11181 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 11182 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
11183 info_ptr->lr_save_offset = reg_size;
11184 break;
4697a36c
MM
11185 }
11186
00b960c7
AH
11187 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
11188 + info_ptr->gp_size
11189 + info_ptr->altivec_size
11190 + info_ptr->altivec_padding_size
a3170dc6
AH
11191 + info_ptr->spe_gp_size
11192 + info_ptr->spe_padding_size
00b960c7
AH
11193 + ehrd_size
11194 + info_ptr->cr_size
11195 + info_ptr->lr_size
11196 + info_ptr->vrsave_size
11197 + info_ptr->toc_size,
11198 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
11199 ? 16 : 8);
11200
44688022 11201 non_fixed_size = (info_ptr->vars_size
ff381587 11202 + info_ptr->parm_size
ff381587 11203 + info_ptr->save_size
44688022 11204 + info_ptr->varargs_size);
ff381587 11205
44688022
AM
11206 info_ptr->total_size = RS6000_ALIGN (non_fixed_size + info_ptr->fixed_size,
11207 ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
11208
11209 /* Determine if we need to allocate any stack frame:
11210
a4f6c312
SS
11211 For AIX we need to push the stack if a frame pointer is needed
11212 (because the stack might be dynamically adjusted), if we are
11213 debugging, if we make calls, or if the sum of fp_save, gp_save,
11214 and local variables are more than the space needed to save all
11215 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
11216 + 18*8 = 288 (GPR13 reserved).
ff381587 11217
a4f6c312
SS
11218 For V.4 we don't have the stack cushion that AIX uses, but assume
11219 that the debugger can handle stackless frames. */
ff381587
MM
11220
11221 if (info_ptr->calls_p)
11222 info_ptr->push_p = 1;
11223
178274da 11224 else if (DEFAULT_ABI == ABI_V4)
44688022 11225 info_ptr->push_p = non_fixed_size != 0;
ff381587 11226
178274da
AM
11227 else if (frame_pointer_needed)
11228 info_ptr->push_p = 1;
11229
11230 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
11231 info_ptr->push_p = 1;
11232
ff381587 11233 else
44688022 11234 info_ptr->push_p = non_fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 11235
a4f6c312 11236 /* Zero offsets if we're not saving those registers. */
8dda1a21 11237 if (info_ptr->fp_size == 0)
4697a36c
MM
11238 info_ptr->fp_save_offset = 0;
11239
8dda1a21 11240 if (info_ptr->gp_size == 0)
4697a36c
MM
11241 info_ptr->gp_save_offset = 0;
11242
00b960c7
AH
11243 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
11244 info_ptr->altivec_save_offset = 0;
11245
11246 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
11247 info_ptr->vrsave_save_offset = 0;
11248
c19de7aa
AH
11249 if (! TARGET_SPE_ABI
11250 || info_ptr->spe_64bit_regs_used == 0
11251 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
11252 info_ptr->spe_gp_save_offset = 0;
11253
c81fc13e 11254 if (! info_ptr->lr_save_p)
4697a36c
MM
11255 info_ptr->lr_save_offset = 0;
11256
c81fc13e 11257 if (! info_ptr->cr_save_p)
4697a36c
MM
11258 info_ptr->cr_save_offset = 0;
11259
c81fc13e 11260 if (! info_ptr->toc_save_p)
b6c9286a
MM
11261 info_ptr->toc_save_offset = 0;
11262
4697a36c
MM
11263 return info_ptr;
11264}
11265
c19de7aa
AH
11266/* Return true if the current function uses any GPRs in 64-bit SIMD
11267 mode. */
11268
11269static bool
863d938c 11270spe_func_has_64bit_regs_p (void)
c19de7aa
AH
11271{
11272 rtx insns, insn;
11273
11274 /* Functions that save and restore all the call-saved registers will
11275 need to save/restore the registers in 64-bits. */
11276 if (current_function_calls_eh_return
11277 || current_function_calls_setjmp
11278 || current_function_has_nonlocal_goto)
11279 return true;
11280
11281 insns = get_insns ();
11282
11283 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
11284 {
11285 if (INSN_P (insn))
11286 {
11287 rtx i;
11288
11289 i = PATTERN (insn);
11290 if (GET_CODE (i) == SET
11291 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
11292 return true;
11293 }
11294 }
11295
11296 return false;
11297}
11298
d1d0c603 11299static void
a2369ed3 11300debug_stack_info (rs6000_stack_t *info)
9878760c 11301{
d330fd93 11302 const char *abi_string;
24d304eb 11303
c81fc13e 11304 if (! info)
4697a36c
MM
11305 info = rs6000_stack_info ();
11306
11307 fprintf (stderr, "\nStack information for function %s:\n",
11308 ((current_function_decl && DECL_NAME (current_function_decl))
11309 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
11310 : "<unknown>"));
11311
24d304eb
RK
11312 switch (info->abi)
11313 {
b6c9286a
MM
11314 default: abi_string = "Unknown"; break;
11315 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 11316 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 11317 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 11318 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
11319 }
11320
11321 fprintf (stderr, "\tABI = %5s\n", abi_string);
11322
00b960c7
AH
11323 if (TARGET_ALTIVEC_ABI)
11324 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
11325
a3170dc6
AH
11326 if (TARGET_SPE_ABI)
11327 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
11328
4697a36c
MM
11329 if (info->first_gp_reg_save != 32)
11330 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
11331
11332 if (info->first_fp_reg_save != 64)
11333 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 11334
00b960c7
AH
11335 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
11336 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
11337 info->first_altivec_reg_save);
11338
4697a36c
MM
11339 if (info->lr_save_p)
11340 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 11341
4697a36c
MM
11342 if (info->cr_save_p)
11343 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
11344
b6c9286a
MM
11345 if (info->toc_save_p)
11346 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
11347
00b960c7
AH
11348 if (info->vrsave_mask)
11349 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
11350
4697a36c
MM
11351 if (info->push_p)
11352 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
11353
11354 if (info->calls_p)
11355 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
11356
4697a36c
MM
11357 if (info->gp_save_offset)
11358 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
11359
11360 if (info->fp_save_offset)
11361 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
11362
00b960c7
AH
11363 if (info->altivec_save_offset)
11364 fprintf (stderr, "\taltivec_save_offset = %5d\n",
11365 info->altivec_save_offset);
11366
a3170dc6
AH
11367 if (info->spe_gp_save_offset)
11368 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
11369 info->spe_gp_save_offset);
11370
00b960c7
AH
11371 if (info->vrsave_save_offset)
11372 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
11373 info->vrsave_save_offset);
11374
4697a36c
MM
11375 if (info->lr_save_offset)
11376 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
11377
11378 if (info->cr_save_offset)
11379 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
11380
b6c9286a
MM
11381 if (info->toc_save_offset)
11382 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
11383
4697a36c
MM
11384 if (info->varargs_save_offset)
11385 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
11386
11387 if (info->total_size)
d1d0c603
JJ
11388 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11389 info->total_size);
4697a36c
MM
11390
11391 if (info->varargs_size)
11392 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
11393
11394 if (info->vars_size)
d1d0c603
JJ
11395 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11396 info->vars_size);
4697a36c
MM
11397
11398 if (info->parm_size)
11399 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
11400
11401 if (info->fixed_size)
11402 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
11403
11404 if (info->gp_size)
11405 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
11406
a3170dc6
AH
11407 if (info->spe_gp_size)
11408 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
11409
4697a36c
MM
11410 if (info->fp_size)
11411 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
11412
00b960c7
AH
11413 if (info->altivec_size)
11414 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
11415
11416 if (info->vrsave_size)
11417 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
11418
11419 if (info->altivec_padding_size)
11420 fprintf (stderr, "\taltivec_padding_size= %5d\n",
11421 info->altivec_padding_size);
11422
a3170dc6
AH
11423 if (info->spe_padding_size)
11424 fprintf (stderr, "\tspe_padding_size = %5d\n",
11425 info->spe_padding_size);
11426
a4f6c312 11427 if (info->lr_size)
ed947a96 11428 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 11429
4697a36c
MM
11430 if (info->cr_size)
11431 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
11432
a4f6c312 11433 if (info->toc_size)
b6c9286a
MM
11434 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
11435
4697a36c
MM
11436 if (info->save_size)
11437 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
11438
11439 if (info->reg_size != 4)
11440 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
11441
11442 fprintf (stderr, "\n");
9878760c 11443}
71f123ca
FS
11444
11445rtx
a2369ed3 11446rs6000_return_addr (int count, rtx frame)
71f123ca 11447{
a4f6c312
SS
11448 /* Currently we don't optimize very well between prolog and body
11449 code and for PIC code the code can be actually quite bad, so
11450 don't try to be too clever here. */
f1384257 11451 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
11452 {
11453 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
11454
11455 return
11456 gen_rtx_MEM
11457 (Pmode,
11458 memory_address
11459 (Pmode,
11460 plus_constant (copy_to_reg
11461 (gen_rtx_MEM (Pmode,
11462 memory_address (Pmode, frame))),
11463 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
11464 }
11465
8c29550d 11466 cfun->machine->ra_need_lr = 1;
9e2f7ec7 11467 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
11468}
11469
5e1bf043
DJ
11470/* Say whether a function is a candidate for sibcall handling or not.
11471 We do not allow indirect calls to be optimized into sibling calls.
11472 Also, we can't do it if there are any vector parameters; there's
11473 nowhere to put the VRsave code so it works; note that functions with
11474 vector parameters are required to have a prototype, so the argument
11475 type info must be available here. (The tail recursion case can work
11476 with vector parameters, but there's no way to distinguish here.) */
4977bab6 11477static bool
a2369ed3 11478rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
11479{
11480 tree type;
4977bab6 11481 if (decl)
5e1bf043
DJ
11482 {
11483 if (TARGET_ALTIVEC_VRSAVE)
11484 {
4977bab6 11485 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
11486 type; type = TREE_CHAIN (type))
11487 {
c15b529f 11488 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 11489 return false;
5e1bf043
DJ
11490 }
11491 }
11492 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 11493 || (*targetm.binds_local_p) (decl))
2bcc50d0 11494 {
4977bab6 11495 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
11496
11497 if (!lookup_attribute ("longcall", attr_list)
11498 || lookup_attribute ("shortcall", attr_list))
4977bab6 11499 return true;
2bcc50d0 11500 }
5e1bf043 11501 }
4977bab6 11502 return false;
5e1bf043
DJ
11503}
11504
71f123ca 11505static int
863d938c 11506rs6000_ra_ever_killed (void)
71f123ca
FS
11507{
11508 rtx top;
5e1bf043
DJ
11509 rtx reg;
11510 rtx insn;
71f123ca 11511
dd292d0a 11512 if (current_function_is_thunk)
71f123ca 11513 return 0;
eb0424da 11514
36f7e964
AH
11515 /* regs_ever_live has LR marked as used if any sibcalls are present,
11516 but this should not force saving and restoring in the
11517 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 11518 clobbers LR, so that is inappropriate. */
36f7e964 11519
5e1bf043
DJ
11520 /* Also, the prologue can generate a store into LR that
11521 doesn't really count, like this:
36f7e964 11522
5e1bf043
DJ
11523 move LR->R0
11524 bcl to set PIC register
11525 move LR->R31
11526 move R0->LR
36f7e964
AH
11527
11528 When we're called from the epilogue, we need to avoid counting
11529 this as a store. */
5e1bf043 11530
71f123ca
FS
11531 push_topmost_sequence ();
11532 top = get_insns ();
11533 pop_topmost_sequence ();
5e1bf043 11534 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 11535
5e1bf043
DJ
11536 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
11537 {
11538 if (INSN_P (insn))
11539 {
11540 if (FIND_REG_INC_NOTE (insn, reg))
11541 return 1;
11542 else if (GET_CODE (insn) == CALL_INSN
c15b529f 11543 && !SIBLING_CALL_P (insn))
5e1bf043 11544 return 1;
36f7e964
AH
11545 else if (set_of (reg, insn) != NULL_RTX
11546 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
11547 return 1;
11548 }
11549 }
11550 return 0;
71f123ca 11551}
4697a36c 11552\f
8cd8f856
GK
11553/* Add a REG_MAYBE_DEAD note to the insn. */
11554static void
a2369ed3 11555rs6000_maybe_dead (rtx insn)
8cd8f856
GK
11556{
11557 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
11558 const0_rtx,
11559 REG_NOTES (insn));
11560}
11561
9ebbca7d 11562/* Emit instructions needed to load the TOC register.
c7ca610e 11563 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 11564 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
11565
11566void
a2369ed3 11567rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 11568{
027fbf43 11569 rtx dest, insn;
1db02437 11570 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 11571
20b71b17
AM
11572 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11573 {
11574 rtx temp = (fromprolog
11575 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11576 : gen_reg_rtx (Pmode));
027fbf43
JJ
11577 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
11578 if (fromprolog)
11579 rs6000_maybe_dead (insn);
11580 insn = emit_move_insn (dest, temp);
11581 if (fromprolog)
11582 rs6000_maybe_dead (insn);
20b71b17
AM
11583 }
11584 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
11585 {
11586 char buf[30];
11587 rtx tempLR = (fromprolog
11588 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11589 : gen_reg_rtx (Pmode));
11590 rtx temp0 = (fromprolog
11591 ? gen_rtx_REG (Pmode, 0)
11592 : gen_reg_rtx (Pmode));
11593 rtx symF;
11594
11595 /* possibly create the toc section */
11596 if (! toc_initialized)
38c1f2d7 11597 {
20b71b17
AM
11598 toc_section ();
11599 function_section (current_function_decl);
38c1f2d7 11600 }
9ebbca7d 11601
20b71b17
AM
11602 if (fromprolog)
11603 {
11604 rtx symL;
38c1f2d7 11605
20b71b17
AM
11606 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
11607 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 11608
20b71b17
AM
11609 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
11610 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11611
11612 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
11613 symF)));
11614 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
11615 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
11616 symL,
11617 symF)));
9ebbca7d
GK
11618 }
11619 else
20b71b17
AM
11620 {
11621 rtx tocsym;
11622 static int reload_toc_labelno = 0;
11623
11624 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
11625
11626 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
11627 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11628
027fbf43
JJ
11629 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
11630 emit_move_insn (dest, tempLR);
11631 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 11632 }
027fbf43
JJ
11633 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
11634 if (fromprolog)
11635 rs6000_maybe_dead (insn);
9ebbca7d 11636 }
20b71b17
AM
11637 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
11638 {
11639 /* This is for AIX code running in non-PIC ELF32. */
11640 char buf[30];
11641 rtx realsym;
11642 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11643 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11644
027fbf43
JJ
11645 insn = emit_insn (gen_elf_high (dest, realsym));
11646 if (fromprolog)
11647 rs6000_maybe_dead (insn);
11648 insn = emit_insn (gen_elf_low (dest, dest, realsym));
11649 if (fromprolog)
11650 rs6000_maybe_dead (insn);
20b71b17
AM
11651 }
11652 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
11653 {
11654 if (TARGET_32BIT)
027fbf43 11655 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 11656 else
027fbf43
JJ
11657 insn = emit_insn (gen_load_toc_aix_di (dest));
11658 if (fromprolog)
11659 rs6000_maybe_dead (insn);
9ebbca7d 11660 }
20b71b17
AM
11661 else
11662 abort ();
9ebbca7d
GK
11663}
11664
d1d0c603
JJ
11665/* Emit instructions to restore the link register after determining where
11666 its value has been stored. */
11667
11668void
11669rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
11670{
11671 rs6000_stack_t *info = rs6000_stack_info ();
11672 rtx operands[2];
11673
11674 operands[0] = source;
11675 operands[1] = scratch;
11676
11677 if (info->lr_save_p)
11678 {
11679 rtx frame_rtx = stack_pointer_rtx;
11680 HOST_WIDE_INT sp_offset = 0;
11681 rtx tmp;
11682
11683 if (frame_pointer_needed
11684 || current_function_calls_alloca
11685 || info->total_size > 32767)
11686 {
11687 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
11688 frame_rtx = operands[1];
11689 }
11690 else if (info->push_p)
11691 sp_offset = info->total_size;
11692
11693 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
11694 tmp = gen_rtx_MEM (Pmode, tmp);
11695 emit_move_insn (tmp, operands[0]);
11696 }
11697 else
11698 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
11699}
11700
f103e34d
GK
11701static GTY(()) int set = -1;
11702
9ebbca7d 11703int
863d938c 11704get_TOC_alias_set (void)
9ebbca7d 11705{
f103e34d
GK
11706 if (set == -1)
11707 set = new_alias_set ();
11708 return set;
9ebbca7d
GK
11709}
11710
c1207243 11711/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
11712 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
11713 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 11714#if TARGET_ELF
3c9eb5f4 11715static int
38f391a5 11716uses_TOC (void)
9ebbca7d 11717{
c4501e62 11718 rtx insn;
38c1f2d7 11719
c4501e62
JJ
11720 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11721 if (INSN_P (insn))
11722 {
11723 rtx pat = PATTERN (insn);
11724 int i;
9ebbca7d 11725
c4501e62
JJ
11726 if (GET_CODE (pat) == PARALLEL)
11727 for (i = 0; i < XVECLEN (pat, 0); i++)
11728 {
11729 rtx sub = XVECEXP (pat, 0, i);
11730 if (GET_CODE (sub) == USE)
11731 {
11732 sub = XEXP (sub, 0);
11733 if (GET_CODE (sub) == UNSPEC
11734 && XINT (sub, 1) == UNSPEC_TOC)
11735 return 1;
11736 }
11737 }
11738 }
11739 return 0;
9ebbca7d 11740}
c954844a 11741#endif
38c1f2d7 11742
9ebbca7d 11743rtx
a2369ed3 11744create_TOC_reference (rtx symbol)
9ebbca7d 11745{
a8a05998
ZW
11746 return gen_rtx_PLUS (Pmode,
11747 gen_rtx_REG (Pmode, TOC_REGISTER),
11748 gen_rtx_CONST (Pmode,
11749 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 11750 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 11751}
38c1f2d7 11752
fc4767bb
JJ
11753/* If _Unwind_* has been called from within the same module,
11754 toc register is not guaranteed to be saved to 40(1) on function
11755 entry. Save it there in that case. */
c7ca610e 11756
9ebbca7d 11757void
863d938c 11758rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
11759{
11760 rtx mem;
11761 rtx stack_top = gen_reg_rtx (Pmode);
11762 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
11763 rtx opcode = gen_reg_rtx (SImode);
11764 rtx tocompare = gen_reg_rtx (SImode);
11765 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
11766
11767 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
11768 emit_move_insn (stack_top, mem);
11769
fc4767bb
JJ
11770 mem = gen_rtx_MEM (Pmode,
11771 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
11772 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
11773 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
11774 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
11775 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 11776 : 0xE8410028, SImode));
9ebbca7d 11777
fc4767bb 11778 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 11779 SImode, NULL_RTX, NULL_RTX,
fc4767bb 11780 no_toc_save_needed);
9ebbca7d 11781
fc4767bb
JJ
11782 mem = gen_rtx_MEM (Pmode,
11783 gen_rtx_PLUS (Pmode, stack_top,
11784 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
11785 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
11786 emit_label (no_toc_save_needed);
9ebbca7d 11787}
38c1f2d7 11788\f
ba4828e0
RK
11789/* This ties together stack memory (MEM with an alias set of
11790 rs6000_sr_alias_set) and the change to the stack pointer. */
11791
9ebbca7d 11792static void
863d938c 11793rs6000_emit_stack_tie (void)
9ebbca7d 11794{
ba4828e0
RK
11795 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
11796
11797 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11798 emit_insn (gen_stack_tie (mem));
11799}
38c1f2d7 11800
9ebbca7d
GK
11801/* Emit the correct code for allocating stack space, as insns.
11802 If COPY_R12, make sure a copy of the old frame is left in r12.
11803 The generated code may use hard register 0 as a temporary. */
11804
11805static void
a2369ed3 11806rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 11807{
9ebbca7d
GK
11808 rtx insn;
11809 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11810 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
11811 rtx todec = GEN_INT (-size);
a157febd
GK
11812
11813 if (current_function_limit_stack)
11814 {
11815 if (REG_P (stack_limit_rtx)
11816 && REGNO (stack_limit_rtx) > 1
11817 && REGNO (stack_limit_rtx) <= 31)
11818 {
5b71a4e7 11819 emit_insn (TARGET_32BIT
9ebbca7d
GK
11820 ? gen_addsi3 (tmp_reg,
11821 stack_limit_rtx,
11822 GEN_INT (size))
11823 : gen_adddi3 (tmp_reg,
11824 stack_limit_rtx,
11825 GEN_INT (size)));
5b71a4e7 11826
9ebbca7d
GK
11827 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11828 const0_rtx));
a157febd
GK
11829 }
11830 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 11831 && TARGET_32BIT
f607bc57 11832 && DEFAULT_ABI == ABI_V4)
a157febd 11833 {
9ebbca7d
GK
11834 rtx toload = gen_rtx_CONST (VOIDmode,
11835 gen_rtx_PLUS (Pmode,
11836 stack_limit_rtx,
11837 GEN_INT (size)));
5b71a4e7 11838
9ebbca7d
GK
11839 emit_insn (gen_elf_high (tmp_reg, toload));
11840 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
11841 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11842 const0_rtx));
a157febd
GK
11843 }
11844 else
11845 warning ("stack limit expression is not supported");
11846 }
11847
9ebbca7d
GK
11848 if (copy_r12 || ! TARGET_UPDATE)
11849 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
11850
38c1f2d7
MM
11851 if (TARGET_UPDATE)
11852 {
9ebbca7d 11853 if (size > 32767)
38c1f2d7 11854 {
9ebbca7d
GK
11855 /* Need a note here so that try_split doesn't get confused. */
11856 if (get_last_insn() == NULL_RTX)
2e040219 11857 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
11858 insn = emit_move_insn (tmp_reg, todec);
11859 try_split (PATTERN (insn), insn, 0);
11860 todec = tmp_reg;
38c1f2d7 11861 }
5b71a4e7
DE
11862
11863 insn = emit_insn (TARGET_32BIT
11864 ? gen_movsi_update (stack_reg, stack_reg,
11865 todec, stack_reg)
11866 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 11867 todec, stack_reg));
38c1f2d7
MM
11868 }
11869 else
11870 {
5b71a4e7
DE
11871 insn = emit_insn (TARGET_32BIT
11872 ? gen_addsi3 (stack_reg, stack_reg, todec)
11873 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
11874 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
11875 gen_rtx_REG (Pmode, 12));
11876 }
5b71a4e7 11877
9ebbca7d
GK
11878 RTX_FRAME_RELATED_P (insn) = 1;
11879 REG_NOTES (insn) =
11880 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11881 gen_rtx_SET (VOIDmode, stack_reg,
11882 gen_rtx_PLUS (Pmode, stack_reg,
11883 GEN_INT (-size))),
11884 REG_NOTES (insn));
11885}
11886
a4f6c312
SS
11887/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
11888 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
11889 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
11890 deduce these equivalences by itself so it wasn't necessary to hold
11891 its hand so much. */
9ebbca7d
GK
11892
11893static void
a2369ed3
DJ
11894rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
11895 rtx reg2, rtx rreg)
9ebbca7d
GK
11896{
11897 rtx real, temp;
11898
e56c4463
JL
11899 /* copy_rtx will not make unique copies of registers, so we need to
11900 ensure we don't have unwanted sharing here. */
11901 if (reg == reg2)
11902 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11903
11904 if (reg == rreg)
11905 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11906
9ebbca7d
GK
11907 real = copy_rtx (PATTERN (insn));
11908
89e7058f
AH
11909 if (reg2 != NULL_RTX)
11910 real = replace_rtx (real, reg2, rreg);
11911
9ebbca7d
GK
11912 real = replace_rtx (real, reg,
11913 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
11914 STACK_POINTER_REGNUM),
11915 GEN_INT (val)));
11916
11917 /* We expect that 'real' is either a SET or a PARALLEL containing
11918 SETs (and possibly other stuff). In a PARALLEL, all the SETs
11919 are important so they all have to be marked RTX_FRAME_RELATED_P. */
11920
11921 if (GET_CODE (real) == SET)
11922 {
11923 rtx set = real;
11924
11925 temp = simplify_rtx (SET_SRC (set));
11926 if (temp)
11927 SET_SRC (set) = temp;
11928 temp = simplify_rtx (SET_DEST (set));
11929 if (temp)
11930 SET_DEST (set) = temp;
11931 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 11932 {
9ebbca7d
GK
11933 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11934 if (temp)
11935 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 11936 }
38c1f2d7 11937 }
9ebbca7d
GK
11938 else if (GET_CODE (real) == PARALLEL)
11939 {
11940 int i;
11941 for (i = 0; i < XVECLEN (real, 0); i++)
11942 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11943 {
11944 rtx set = XVECEXP (real, 0, i);
11945
11946 temp = simplify_rtx (SET_SRC (set));
11947 if (temp)
11948 SET_SRC (set) = temp;
11949 temp = simplify_rtx (SET_DEST (set));
11950 if (temp)
11951 SET_DEST (set) = temp;
11952 if (GET_CODE (SET_DEST (set)) == MEM)
11953 {
11954 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11955 if (temp)
11956 XEXP (SET_DEST (set), 0) = temp;
11957 }
11958 RTX_FRAME_RELATED_P (set) = 1;
11959 }
11960 }
11961 else
a4f6c312 11962 abort ();
c19de7aa
AH
11963
11964 if (TARGET_SPE)
11965 real = spe_synthesize_frame_save (real);
11966
9ebbca7d
GK
11967 RTX_FRAME_RELATED_P (insn) = 1;
11968 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11969 real,
11970 REG_NOTES (insn));
38c1f2d7
MM
11971}
11972
c19de7aa
AH
11973/* Given an SPE frame note, return a PARALLEL of SETs with the
11974 original note, plus a synthetic register save. */
11975
11976static rtx
a2369ed3 11977spe_synthesize_frame_save (rtx real)
c19de7aa
AH
11978{
11979 rtx synth, offset, reg, real2;
11980
11981 if (GET_CODE (real) != SET
11982 || GET_MODE (SET_SRC (real)) != V2SImode)
11983 return real;
11984
11985 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11986 frame related note. The parallel contains a set of the register
41f3a930 11987 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11988 This is so we can differentiate between 64-bit and 32-bit saves.
11989 Words cannot describe this nastiness. */
11990
11991 if (GET_CODE (SET_DEST (real)) != MEM
11992 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11993 || GET_CODE (SET_SRC (real)) != REG)
11994 abort ();
11995
11996 /* Transform:
11997 (set (mem (plus (reg x) (const y)))
11998 (reg z))
11999 into:
12000 (set (mem (plus (reg x) (const y+4)))
41f3a930 12001 (reg z+1200))
c19de7aa
AH
12002 */
12003
12004 real2 = copy_rtx (real);
12005 PUT_MODE (SET_DEST (real2), SImode);
12006 reg = SET_SRC (real2);
12007 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
12008 synth = copy_rtx (real2);
12009
12010 if (BYTES_BIG_ENDIAN)
12011 {
12012 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
12013 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
12014 }
12015
12016 reg = SET_SRC (synth);
41f3a930 12017
c19de7aa 12018 synth = replace_rtx (synth, reg,
41f3a930 12019 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
12020
12021 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
12022 synth = replace_rtx (synth, offset,
12023 GEN_INT (INTVAL (offset)
12024 + (BYTES_BIG_ENDIAN ? 0 : 4)));
12025
12026 RTX_FRAME_RELATED_P (synth) = 1;
12027 RTX_FRAME_RELATED_P (real2) = 1;
12028 if (BYTES_BIG_ENDIAN)
12029 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
12030 else
12031 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
12032
12033 return real;
12034}
12035
00b960c7
AH
12036/* Returns an insn that has a vrsave set operation with the
12037 appropriate CLOBBERs. */
12038
12039static rtx
a2369ed3 12040generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
12041{
12042 int nclobs, i;
12043 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 12044 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 12045
a004eb82
AH
12046 clobs[0]
12047 = gen_rtx_SET (VOIDmode,
12048 vrsave,
12049 gen_rtx_UNSPEC_VOLATILE (SImode,
12050 gen_rtvec (2, reg, vrsave),
12051 30));
00b960c7
AH
12052
12053 nclobs = 1;
12054
9aa86737
AH
12055 /* We need to clobber the registers in the mask so the scheduler
12056 does not move sets to VRSAVE before sets of AltiVec registers.
12057
12058 However, if the function receives nonlocal gotos, reload will set
12059 all call saved registers live. We will end up with:
12060
12061 (set (reg 999) (mem))
12062 (parallel [ (set (reg vrsave) (unspec blah))
12063 (clobber (reg 999))])
12064
12065 The clobber will cause the store into reg 999 to be dead, and
12066 flow will attempt to delete an epilogue insn. In this case, we
12067 need an unspec use/set of the register. */
00b960c7
AH
12068
12069 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
44688022 12070 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
9aa86737
AH
12071 {
12072 if (!epiloguep || call_used_regs [i])
12073 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
12074 gen_rtx_REG (V4SImode, i));
12075 else
12076 {
12077 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
12078
12079 clobs[nclobs++]
a004eb82
AH
12080 = gen_rtx_SET (VOIDmode,
12081 reg,
12082 gen_rtx_UNSPEC (V4SImode,
12083 gen_rtvec (1, reg), 27));
9aa86737
AH
12084 }
12085 }
00b960c7
AH
12086
12087 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
12088
12089 for (i = 0; i < nclobs; ++i)
12090 XVECEXP (insn, 0, i) = clobs[i];
12091
12092 return insn;
12093}
12094
89e7058f
AH
12095/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
12096 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
12097
12098static void
a2369ed3 12099emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 12100 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
12101{
12102 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
12103 rtx replacea, replaceb;
12104
12105 int_rtx = GEN_INT (offset);
12106
12107 /* Some cases that need register indexed addressing. */
12108 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
12109 || (TARGET_SPE_ABI
12110 && SPE_VECTOR_MODE (mode)
12111 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
12112 {
12113 /* Whomever calls us must make sure r11 is available in the
12114 flow path of instructions in the prologue. */
12115 offset_rtx = gen_rtx_REG (Pmode, 11);
12116 emit_move_insn (offset_rtx, int_rtx);
12117
12118 replacea = offset_rtx;
12119 replaceb = int_rtx;
12120 }
12121 else
12122 {
12123 offset_rtx = int_rtx;
12124 replacea = NULL_RTX;
12125 replaceb = NULL_RTX;
12126 }
12127
12128 reg = gen_rtx_REG (mode, regno);
12129 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
12130 mem = gen_rtx_MEM (mode, addr);
12131 set_mem_alias_set (mem, rs6000_sr_alias_set);
12132
12133 insn = emit_move_insn (mem, reg);
12134
12135 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
12136}
12137
a3170dc6
AH
12138/* Emit an offset memory reference suitable for a frame store, while
12139 converting to a valid addressing mode. */
12140
12141static rtx
a2369ed3 12142gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
12143{
12144 rtx int_rtx, offset_rtx;
12145
12146 int_rtx = GEN_INT (offset);
12147
12148 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
12149 {
12150 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12151 emit_move_insn (offset_rtx, int_rtx);
12152 }
12153 else
12154 offset_rtx = int_rtx;
12155
12156 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
12157}
12158
9ebbca7d
GK
12159/* Emit function prologue as insns. */
12160
9878760c 12161void
863d938c 12162rs6000_emit_prologue (void)
9878760c 12163{
4697a36c 12164 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 12165 enum machine_mode reg_mode = Pmode;
327e5343 12166 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12167 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
12168 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
12169 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 12170 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
12171 rtx insn;
12172 int saving_FPRs_inline;
12173 int using_store_multiple;
12174 HOST_WIDE_INT sp_offset = 0;
12175
c19de7aa 12176 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12177 {
12178 reg_mode = V2SImode;
12179 reg_size = 8;
12180 }
12181
9ebbca7d 12182 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12183 && (!TARGET_SPE_ABI
12184 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12185 && info->first_gp_reg_save < 31);
12186 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 12187 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 12188 || current_function_calls_eh_return
8c29550d 12189 || cfun->machine->ra_need_lr);
9ebbca7d
GK
12190
12191 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 12192 if (info->push_p
acd0b319
AM
12193 && (DEFAULT_ABI == ABI_V4
12194 || current_function_calls_eh_return))
9ebbca7d
GK
12195 {
12196 if (info->total_size < 32767)
12197 sp_offset = info->total_size;
12198 else
12199 frame_reg_rtx = frame_ptr_rtx;
12200 rs6000_emit_allocate_stack (info->total_size,
12201 (frame_reg_rtx != sp_reg_rtx
12202 && (info->cr_save_p
12203 || info->lr_save_p
12204 || info->first_fp_reg_save < 64
12205 || info->first_gp_reg_save < 32
12206 )));
12207 if (frame_reg_rtx != sp_reg_rtx)
12208 rs6000_emit_stack_tie ();
12209 }
12210
9aa86737
AH
12211 /* Save AltiVec registers if needed. */
12212 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12213 {
12214 int i;
12215
12216 /* There should be a non inline version of this, for when we
12217 are saving lots of vector registers. */
12218 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12219 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12220 {
12221 rtx areg, savereg, mem;
12222 int offset;
12223
12224 offset = info->altivec_save_offset + sp_offset
12225 + 16 * (i - info->first_altivec_reg_save);
12226
12227 savereg = gen_rtx_REG (V4SImode, i);
12228
12229 areg = gen_rtx_REG (Pmode, 0);
12230 emit_move_insn (areg, GEN_INT (offset));
12231
12232 /* AltiVec addressing mode is [reg+reg]. */
12233 mem = gen_rtx_MEM (V4SImode,
12234 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
12235
12236 set_mem_alias_set (mem, rs6000_sr_alias_set);
12237
12238 insn = emit_move_insn (mem, savereg);
12239
5c242421
SB
12240 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12241 areg, GEN_INT (offset));
9aa86737
AH
12242 }
12243 }
12244
12245 /* VRSAVE is a bit vector representing which AltiVec registers
12246 are used. The OS uses this to determine which vector
12247 registers to save on a context switch. We need to save
12248 VRSAVE on the stack frame, add whatever AltiVec registers we
12249 used in this function, and do the corresponding magic in the
12250 epilogue. */
12251
4d774ff8
HP
12252 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
12253 && info->vrsave_mask != 0)
9aa86737 12254 {
a004eb82 12255 rtx reg, mem, vrsave;
9aa86737
AH
12256 int offset;
12257
12258 /* Get VRSAVE onto a GPR. */
12259 reg = gen_rtx_REG (SImode, 12);
a004eb82 12260 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
12261 if (TARGET_MACHO)
12262 emit_insn (gen_get_vrsave_internal (reg));
12263 else
12264 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
12265
12266 /* Save VRSAVE. */
12267 offset = info->vrsave_save_offset + sp_offset;
12268 mem
12269 = gen_rtx_MEM (SImode,
12270 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
12271 set_mem_alias_set (mem, rs6000_sr_alias_set);
12272 insn = emit_move_insn (mem, reg);
12273
12274 /* Include the registers in the mask. */
12275 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
12276
12277 insn = emit_insn (generate_set_vrsave (reg, info, 0));
12278 }
12279
9ebbca7d
GK
12280 /* If we use the link register, get it into r0. */
12281 if (info->lr_save_p)
71f123ca 12282 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
12283 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12284
12285 /* If we need to save CR, put it into r12. */
12286 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
12287 {
12288 cr_save_rtx = gen_rtx_REG (SImode, 12);
12289 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12290 }
12291
a4f6c312
SS
12292 /* Do any required saving of fpr's. If only one or two to save, do
12293 it ourselves. Otherwise, call function. */
9ebbca7d
GK
12294 if (saving_FPRs_inline)
12295 {
12296 int i;
12297 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12298 if ((regs_ever_live[info->first_fp_reg_save+i]
12299 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
12300 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
12301 info->first_fp_reg_save + i,
12302 info->fp_save_offset + sp_offset + 8 * i,
12303 info->total_size);
9ebbca7d
GK
12304 }
12305 else if (info->first_fp_reg_save != 64)
12306 {
12307 int i;
12308 char rname[30];
520a57c8 12309 const char *alloc_rname;
9ebbca7d
GK
12310 rtvec p;
12311 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
12312
12313 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
12314 gen_rtx_REG (Pmode,
12315 LINK_REGISTER_REGNUM));
12316 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
12317 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 12318 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12319 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
12320 gen_rtx_SYMBOL_REF (Pmode,
12321 alloc_rname));
12322 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12323 {
12324 rtx addr, reg, mem;
12325 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
12326 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12327 GEN_INT (info->fp_save_offset
12328 + sp_offset + 8*i));
12329 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12330 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12331
12332 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
12333 }
12334 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12335 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12336 NULL_RTX, NULL_RTX);
12337 }
b6c9286a 12338
9ebbca7d
GK
12339 /* Save GPRs. This is done as a PARALLEL if we are using
12340 the store-multiple instructions. */
12341 if (using_store_multiple)
b6c9286a 12342 {
308c142a 12343 rtvec p;
9ebbca7d
GK
12344 int i;
12345 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
12346 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12347 {
12348 rtx addr, reg, mem;
12349 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12350 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12351 GEN_INT (info->gp_save_offset
12352 + sp_offset
12353 + reg_size * i));
12354 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12355 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12356
12357 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
12358 }
12359 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12360 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12361 NULL_RTX, NULL_RTX);
b6c9286a
MM
12362 }
12363 else
12364 {
9ebbca7d
GK
12365 int i;
12366 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12367 if ((regs_ever_live[info->first_gp_reg_save+i]
12368 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12369 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12370 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12371 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
12372 {
12373 rtx addr, reg, mem;
12374 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12375
c19de7aa 12376 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12377 {
12378 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12379 rtx b;
12380
12381 if (!SPE_CONST_OFFSET_OK (offset))
12382 {
12383 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12384 emit_move_insn (b, GEN_INT (offset));
12385 }
12386 else
12387 b = GEN_INT (offset);
12388
12389 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12390 mem = gen_rtx_MEM (V2SImode, addr);
12391 set_mem_alias_set (mem, rs6000_sr_alias_set);
12392 insn = emit_move_insn (mem, reg);
12393
12394 if (GET_CODE (b) == CONST_INT)
12395 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12396 NULL_RTX, NULL_RTX);
12397 else
12398 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12399 b, GEN_INT (offset));
12400 }
12401 else
12402 {
12403 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12404 GEN_INT (info->gp_save_offset
12405 + sp_offset
12406 + reg_size * i));
12407 mem = gen_rtx_MEM (reg_mode, addr);
12408 set_mem_alias_set (mem, rs6000_sr_alias_set);
12409
12410 insn = emit_move_insn (mem, reg);
12411 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12412 NULL_RTX, NULL_RTX);
12413 }
12414 }
9ebbca7d
GK
12415 }
12416
83720594
RH
12417 /* ??? There's no need to emit actual instructions here, but it's the
12418 easiest way to get the frame unwind information emitted. */
12419 if (current_function_calls_eh_return)
12420 {
78e1b90d
DE
12421 unsigned int i, regno;
12422
fc4767bb
JJ
12423 /* In AIX ABI we need to pretend we save r2 here. */
12424 if (TARGET_AIX)
12425 {
12426 rtx addr, reg, mem;
12427
12428 reg = gen_rtx_REG (reg_mode, 2);
12429 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12430 GEN_INT (sp_offset + 5 * reg_size));
12431 mem = gen_rtx_MEM (reg_mode, addr);
12432 set_mem_alias_set (mem, rs6000_sr_alias_set);
12433
12434 insn = emit_move_insn (mem, reg);
12435 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12436 NULL_RTX, NULL_RTX);
12437 PATTERN (insn) = gen_blockage ();
12438 }
12439
83720594
RH
12440 for (i = 0; ; ++i)
12441 {
83720594
RH
12442 regno = EH_RETURN_DATA_REGNO (i);
12443 if (regno == INVALID_REGNUM)
12444 break;
12445
89e7058f
AH
12446 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
12447 info->ehrd_offset + sp_offset
12448 + reg_size * (int) i,
12449 info->total_size);
83720594
RH
12450 }
12451 }
12452
9ebbca7d
GK
12453 /* Save lr if we used it. */
12454 if (info->lr_save_p)
12455 {
12456 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12457 GEN_INT (info->lr_save_offset + sp_offset));
12458 rtx reg = gen_rtx_REG (Pmode, 0);
12459 rtx mem = gen_rtx_MEM (Pmode, addr);
12460 /* This should not be of rs6000_sr_alias_set, because of
12461 __builtin_return_address. */
12462
12463 insn = emit_move_insn (mem, reg);
12464 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12465 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12466 }
12467
12468 /* Save CR if we use any that must be preserved. */
12469 if (info->cr_save_p)
12470 {
12471 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12472 GEN_INT (info->cr_save_offset + sp_offset));
12473 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12474
12475 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12476
12477 /* If r12 was used to hold the original sp, copy cr into r0 now
12478 that it's free. */
12479 if (REGNO (frame_reg_rtx) == 12)
12480 {
12481 cr_save_rtx = gen_rtx_REG (SImode, 0);
12482 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12483 }
12484 insn = emit_move_insn (mem, cr_save_rtx);
12485
12486 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
12487 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
12488 But that's OK. All we have to do is specify that _one_ condition
12489 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
12490 will then restore all the call-saved registers.
12491 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 12492 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 12493 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
12494 }
12495
12496 /* Update stack and set back pointer unless this is V.4,
12497 for which it was done previously. */
fc4767bb
JJ
12498 if (info->push_p
12499 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
12500 rs6000_emit_allocate_stack (info->total_size, FALSE);
12501
12502 /* Set frame pointer, if needed. */
12503 if (frame_pointer_needed)
12504 {
a3170dc6 12505 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
12506 sp_reg_rtx);
12507 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 12508 }
9878760c 12509
1db02437 12510 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 12511 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 12512 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 12513 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
12514 {
12515 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 12516 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
12517 can use register 0. This allows us to use a plain 'blr' to return
12518 from the procedure more often. */
f1384257
AM
12519 int save_LR_around_toc_setup = (TARGET_ELF
12520 && DEFAULT_ABI != ABI_AIX
12521 && flag_pic
d5fa86ba
GK
12522 && ! info->lr_save_p
12523 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 12524 if (save_LR_around_toc_setup)
c4501e62
JJ
12525 {
12526 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
12527 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
12528 rs6000_emit_load_toc_table (TRUE);
12529 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
12530 }
12531 else
12532 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 12533 }
ee890fe2 12534
fcce224d 12535#if TARGET_MACHO
ee890fe2
SS
12536 if (DEFAULT_ABI == ABI_DARWIN
12537 && flag_pic && current_function_uses_pic_offset_table)
12538 {
12539 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 12540 const char *picbase = machopic_function_base_name ();
6788f5ca 12541 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 12542
f51eee6a 12543 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
12544
12545 rs6000_maybe_dead (
1db02437 12546 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
12547 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
12548 }
fcce224d 12549#endif
9ebbca7d
GK
12550}
12551
9ebbca7d 12552/* Write function prologue. */
a4f6c312 12553
08c148a8 12554static void
a2369ed3
DJ
12555rs6000_output_function_prologue (FILE *file,
12556 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
12557{
12558 rs6000_stack_t *info = rs6000_stack_info ();
12559
4697a36c
MM
12560 if (TARGET_DEBUG_STACK)
12561 debug_stack_info (info);
9878760c 12562
a4f6c312
SS
12563 /* Write .extern for any function we will call to save and restore
12564 fp values. */
12565 if (info->first_fp_reg_save < 64
12566 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 12567 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 12568 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
12569 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
12570 RESTORE_FP_SUFFIX);
9878760c 12571
c764f757
RK
12572 /* Write .extern for AIX common mode routines, if needed. */
12573 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
12574 {
f6709c70
JW
12575 fputs ("\t.extern __mulh\n", file);
12576 fputs ("\t.extern __mull\n", file);
12577 fputs ("\t.extern __divss\n", file);
12578 fputs ("\t.extern __divus\n", file);
12579 fputs ("\t.extern __quoss\n", file);
12580 fputs ("\t.extern __quous\n", file);
c764f757
RK
12581 common_mode_defined = 1;
12582 }
9878760c 12583
9ebbca7d 12584 if (! HAVE_prologue)
979721f8 12585 {
9ebbca7d 12586 start_sequence ();
9dda4cc8 12587
a4f6c312
SS
12588 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
12589 the "toplevel" insn chain. */
2e040219 12590 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12591 rs6000_emit_prologue ();
2e040219 12592 emit_note (NOTE_INSN_DELETED);
178c3eff 12593
a3c9585f 12594 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12595 {
12596 rtx insn;
12597 unsigned addr = 0;
12598 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12599 {
12600 INSN_ADDRESSES_NEW (insn, addr);
12601 addr += 4;
12602 }
12603 }
9dda4cc8 12604
9ebbca7d 12605 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12606 debug_rtx_list (get_insns (), 100);
12607 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12608 end_sequence ();
979721f8
MM
12609 }
12610
9ebbca7d
GK
12611 rs6000_pic_labelno++;
12612}
12613
12614/* Emit function epilogue as insns.
9878760c 12615
9ebbca7d
GK
12616 At present, dwarf2out_frame_debug_expr doesn't understand
12617 register restores, so we don't bother setting RTX_FRAME_RELATED_P
12618 anywhere in the epilogue. Most of the insns below would in any case
12619 need special notes to explain where r11 is in relation to the stack. */
9878760c 12620
9ebbca7d 12621void
a2369ed3 12622rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
12623{
12624 rs6000_stack_t *info;
12625 int restoring_FPRs_inline;
12626 int using_load_multiple;
12627 int using_mfcr_multiple;
12628 int use_backchain_to_restore_sp;
12629 int sp_offset = 0;
12630 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
12631 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 12632 enum machine_mode reg_mode = Pmode;
327e5343 12633 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12634 int i;
12635
c19de7aa
AH
12636 info = rs6000_stack_info ();
12637
12638 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12639 {
12640 reg_mode = V2SImode;
12641 reg_size = 8;
12642 }
12643
9ebbca7d 12644 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12645 && (!TARGET_SPE_ABI
12646 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12647 && info->first_gp_reg_save < 31);
12648 restoring_FPRs_inline = (sibcall
83720594 12649 || current_function_calls_eh_return
9ebbca7d
GK
12650 || info->first_fp_reg_save == 64
12651 || FP_SAVE_INLINE (info->first_fp_reg_save));
12652 use_backchain_to_restore_sp = (frame_pointer_needed
12653 || current_function_calls_alloca
12654 || info->total_size > 32767);
12655 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
12656 || rs6000_cpu == PROCESSOR_PPC603
12657 || rs6000_cpu == PROCESSOR_PPC750
12658 || optimize_size);
12659
12660 /* If we have a frame pointer, a call to alloca, or a large stack
12661 frame, restore the old stack pointer using the backchain. Otherwise,
12662 we know what size to update it with. */
12663 if (use_backchain_to_restore_sp)
bacbde18 12664 {
9ebbca7d
GK
12665 /* Under V.4, don't reset the stack pointer until after we're done
12666 loading the saved registers. */
f607bc57 12667 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 12668 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 12669
9ebbca7d
GK
12670 emit_move_insn (frame_reg_rtx,
12671 gen_rtx_MEM (Pmode, sp_reg_rtx));
12672
bacbde18 12673 }
9ebbca7d 12674 else if (info->push_p)
85638c0d 12675 {
fc4767bb
JJ
12676 if (DEFAULT_ABI == ABI_V4
12677 || current_function_calls_eh_return)
9ebbca7d
GK
12678 sp_offset = info->total_size;
12679 else
12680 {
12681 emit_insn (TARGET_32BIT
12682 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12683 GEN_INT (info->total_size))
12684 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12685 GEN_INT (info->total_size)));
12686 }
85638c0d 12687 }
9ebbca7d 12688
9aa86737
AH
12689 /* Restore AltiVec registers if needed. */
12690 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12691 {
12692 int i;
12693
12694 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12695 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12696 {
12697 rtx addr, areg, mem;
12698
12699 areg = gen_rtx_REG (Pmode, 0);
12700 emit_move_insn
12701 (areg, GEN_INT (info->altivec_save_offset
12702 + sp_offset
12703 + 16 * (i - info->first_altivec_reg_save)));
12704
12705 /* AltiVec addressing mode is [reg+reg]. */
12706 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
12707 mem = gen_rtx_MEM (V4SImode, addr);
12708 set_mem_alias_set (mem, rs6000_sr_alias_set);
12709
12710 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
12711 }
12712 }
12713
12714 /* Restore VRSAVE if needed. */
44688022 12715 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
4d774ff8 12716 && info->vrsave_mask != 0)
9aa86737
AH
12717 {
12718 rtx addr, mem, reg;
12719
12720 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12721 GEN_INT (info->vrsave_save_offset + sp_offset));
12722 mem = gen_rtx_MEM (SImode, addr);
12723 set_mem_alias_set (mem, rs6000_sr_alias_set);
12724 reg = gen_rtx_REG (SImode, 12);
12725 emit_move_insn (reg, mem);
12726
12727 emit_insn (generate_set_vrsave (reg, info, 1));
12728 }
12729
9ebbca7d
GK
12730 /* Get the old lr if we saved it. */
12731 if (info->lr_save_p)
b6c9286a 12732 {
a3170dc6
AH
12733 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
12734 info->lr_save_offset + sp_offset);
ba4828e0
RK
12735
12736 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12737
9ebbca7d 12738 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 12739 }
9ebbca7d
GK
12740
12741 /* Get the old cr if we saved it. */
12742 if (info->cr_save_p)
12743 {
12744 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12745 GEN_INT (info->cr_save_offset + sp_offset));
12746 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12747
12748 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12749
9ebbca7d
GK
12750 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
12751 }
12752
12753 /* Set LR here to try to overlap restores below. */
4697a36c 12754 if (info->lr_save_p)
9ebbca7d
GK
12755 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
12756 gen_rtx_REG (Pmode, 0));
12757
83720594
RH
12758 /* Load exception handler data registers, if needed. */
12759 if (current_function_calls_eh_return)
12760 {
78e1b90d
DE
12761 unsigned int i, regno;
12762
fc4767bb
JJ
12763 if (TARGET_AIX)
12764 {
12765 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12766 GEN_INT (sp_offset + 5 * reg_size));
12767 rtx mem = gen_rtx_MEM (reg_mode, addr);
12768
12769 set_mem_alias_set (mem, rs6000_sr_alias_set);
12770
12771 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
12772 }
12773
83720594
RH
12774 for (i = 0; ; ++i)
12775 {
a3170dc6 12776 rtx mem;
83720594
RH
12777
12778 regno = EH_RETURN_DATA_REGNO (i);
12779 if (regno == INVALID_REGNUM)
12780 break;
12781
a3170dc6
AH
12782 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
12783 info->ehrd_offset + sp_offset
12784 + reg_size * (int) i);
ba4828e0 12785 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
12786
12787 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
12788 }
12789 }
9ebbca7d
GK
12790
12791 /* Restore GPRs. This is done as a PARALLEL if we are using
12792 the load-multiple instructions. */
12793 if (using_load_multiple)
979721f8 12794 {
9ebbca7d
GK
12795 rtvec p;
12796 p = rtvec_alloc (32 - info->first_gp_reg_save);
12797 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 12798 {
9ebbca7d
GK
12799 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12800 GEN_INT (info->gp_save_offset
12801 + sp_offset
12802 + reg_size * i));
12803 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
12804
12805 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12806
12807 RTVEC_ELT (p, i) =
12808 gen_rtx_SET (VOIDmode,
12809 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
12810 mem);
979721f8 12811 }
9ebbca7d 12812 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 12813 }
9ebbca7d
GK
12814 else
12815 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12816 if ((regs_ever_live[info->first_gp_reg_save+i]
12817 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12818 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12819 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12820 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
12821 {
12822 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12823 GEN_INT (info->gp_save_offset
12824 + sp_offset
12825 + reg_size * i));
12826 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12827
a3170dc6 12828 /* Restore 64-bit quantities for SPE. */
c19de7aa 12829 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12830 {
12831 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12832 rtx b;
12833
12834 if (!SPE_CONST_OFFSET_OK (offset))
12835 {
12836 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12837 emit_move_insn (b, GEN_INT (offset));
12838 }
12839 else
12840 b = GEN_INT (offset);
12841
12842 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12843 mem = gen_rtx_MEM (V2SImode, addr);
12844 }
12845
ba4828e0 12846 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12847
12848 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 12849 info->first_gp_reg_save + i), mem);
9ebbca7d 12850 }
9878760c 12851
9ebbca7d
GK
12852 /* Restore fpr's if we need to do it without calling a function. */
12853 if (restoring_FPRs_inline)
12854 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12855 if ((regs_ever_live[info->first_fp_reg_save+i]
12856 && ! call_used_regs[info->first_fp_reg_save+i]))
12857 {
12858 rtx addr, mem;
12859 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12860 GEN_INT (info->fp_save_offset
12861 + sp_offset
a4f6c312 12862 + 8 * i));
9ebbca7d 12863 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12864 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12865
12866 emit_move_insn (gen_rtx_REG (DFmode,
12867 info->first_fp_reg_save + i),
12868 mem);
12869 }
8d30c4ee 12870
9ebbca7d
GK
12871 /* If we saved cr, restore it here. Just those that were used. */
12872 if (info->cr_save_p)
979721f8 12873 {
9ebbca7d 12874 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 12875 int count = 0;
9ebbca7d
GK
12876
12877 if (using_mfcr_multiple)
979721f8 12878 {
9ebbca7d
GK
12879 for (i = 0; i < 8; i++)
12880 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 12881 count++;
9ebbca7d 12882 if (count == 0)
e35b9579
GK
12883 abort ();
12884 }
12885
12886 if (using_mfcr_multiple && count > 1)
12887 {
12888 rtvec p;
12889 int ndx;
9ebbca7d 12890
e35b9579 12891 p = rtvec_alloc (count);
9ebbca7d 12892
e35b9579 12893 ndx = 0;
9ebbca7d
GK
12894 for (i = 0; i < 8; i++)
12895 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
12896 {
12897 rtvec r = rtvec_alloc (2);
12898 RTVEC_ELT (r, 0) = r12_rtx;
12899 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 12900 RTVEC_ELT (p, ndx) =
9ebbca7d 12901 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 12902 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 12903 ndx++;
9ebbca7d
GK
12904 }
12905 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
12906 if (ndx != count)
12907 abort ();
979721f8
MM
12908 }
12909 else
9ebbca7d
GK
12910 for (i = 0; i < 8; i++)
12911 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 12912 {
9ebbca7d
GK
12913 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
12914 CR0_REGNO+i),
12915 r12_rtx));
979721f8 12916 }
979721f8
MM
12917 }
12918
9ebbca7d
GK
12919 /* If this is V.4, unwind the stack pointer after all of the loads
12920 have been done. We need to emit a block here so that sched
12921 doesn't decide to move the sp change before the register restores
12922 (which may not have any obvious dependency on the stack). This
12923 doesn't hurt performance, because there is no scheduling that can
12924 be done after this point. */
fc4767bb
JJ
12925 if (DEFAULT_ABI == ABI_V4
12926 || current_function_calls_eh_return)
b6c9286a 12927 {
9ebbca7d
GK
12928 if (frame_reg_rtx != sp_reg_rtx)
12929 rs6000_emit_stack_tie ();
b6c9286a 12930
9ebbca7d 12931 if (use_backchain_to_restore_sp)
b6c9286a 12932 {
9ebbca7d 12933 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12934 }
9ebbca7d 12935 else if (sp_offset != 0)
13f1623b 12936 {
5b71a4e7 12937 emit_insn (TARGET_32BIT
9ebbca7d
GK
12938 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12939 GEN_INT (sp_offset))
12940 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12941 GEN_INT (sp_offset)));
13f1623b 12942 }
9ebbca7d 12943 }
b6c9286a 12944
83720594
RH
12945 if (current_function_calls_eh_return)
12946 {
12947 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12948 emit_insn (TARGET_32BIT
83720594
RH
12949 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12950 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12951 }
12952
9ebbca7d
GK
12953 if (!sibcall)
12954 {
12955 rtvec p;
12956 if (! restoring_FPRs_inline)
12957 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12958 else
12959 p = rtvec_alloc (2);
b6c9286a 12960
e35b9579
GK
12961 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12962 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12963 gen_rtx_REG (Pmode,
12964 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12965
12966 /* If we have to restore more than two FP registers, branch to the
12967 restore function. It will return to our caller. */
12968 if (! restoring_FPRs_inline)
12969 {
12970 int i;
12971 char rname[30];
520a57c8 12972 const char *alloc_rname;
979721f8 12973
9ebbca7d
GK
12974 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12975 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12976 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12977 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12978 gen_rtx_SYMBOL_REF (Pmode,
12979 alloc_rname));
b6c9286a 12980
9ebbca7d
GK
12981 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12982 {
12983 rtx addr, mem;
12984 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12985 GEN_INT (info->fp_save_offset + 8*i));
12986 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12987 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12988
12989 RTVEC_ELT (p, i+3) =
12990 gen_rtx_SET (VOIDmode,
12991 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12992 mem);
b6c9286a
MM
12993 }
12994 }
9ebbca7d
GK
12995
12996 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 12997 }
9878760c
RK
12998}
12999
13000/* Write function epilogue. */
13001
08c148a8 13002static void
a2369ed3
DJ
13003rs6000_output_function_epilogue (FILE *file,
13004 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 13005{
4697a36c 13006 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 13007
9ebbca7d 13008 if (! HAVE_epilogue)
9878760c 13009 {
9ebbca7d
GK
13010 rtx insn = get_last_insn ();
13011 /* If the last insn was a BARRIER, we don't have to write anything except
13012 the trace table. */
13013 if (GET_CODE (insn) == NOTE)
13014 insn = prev_nonnote_insn (insn);
13015 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 13016 {
9ebbca7d
GK
13017 /* This is slightly ugly, but at least we don't have two
13018 copies of the epilogue-emitting code. */
13019 start_sequence ();
13020
13021 /* A NOTE_INSN_DELETED is supposed to be at the start
13022 and end of the "toplevel" insn chain. */
2e040219 13023 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13024 rs6000_emit_epilogue (FALSE);
2e040219 13025 emit_note (NOTE_INSN_DELETED);
9ebbca7d 13026
a3c9585f 13027 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
13028 {
13029 rtx insn;
13030 unsigned addr = 0;
13031 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
13032 {
13033 INSN_ADDRESSES_NEW (insn, addr);
13034 addr += 4;
13035 }
13036 }
13037
9ebbca7d 13038 if (TARGET_DEBUG_STACK)
a4f6c312
SS
13039 debug_rtx_list (get_insns (), 100);
13040 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 13041 end_sequence ();
4697a36c 13042 }
9878760c 13043 }
b4ac57ab 13044
efdba735
SH
13045#if TARGET_MACHO
13046 macho_branch_islands ();
0e5da0be
GK
13047 /* Mach-O doesn't support labels at the end of objects, so if
13048 it looks like we might want one, insert a NOP. */
13049 {
13050 rtx insn = get_last_insn ();
13051 while (insn
13052 && NOTE_P (insn)
13053 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
13054 insn = PREV_INSN (insn);
13055 if (insn
13056 && (LABEL_P (insn)
13057 || (NOTE_P (insn)
13058 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
13059 fputs ("\tnop\n", file);
13060 }
13061#endif
13062
9b30bae2 13063 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
13064 on its format.
13065
13066 We don't output a traceback table if -finhibit-size-directive was
13067 used. The documentation for -finhibit-size-directive reads
13068 ``don't output a @code{.size} assembler directive, or anything
13069 else that would cause trouble if the function is split in the
13070 middle, and the two halves are placed at locations far apart in
13071 memory.'' The traceback table has this property, since it
13072 includes the offset from the start of the function to the
4d30c363
MM
13073 traceback table itself.
13074
13075 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 13076 different traceback table. */
57ac7be9
AM
13077 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
13078 && rs6000_traceback != traceback_none)
9b30bae2 13079 {
69c75916 13080 const char *fname = NULL;
3ac88239 13081 const char *language_string = lang_hooks.name;
6041bf2f 13082 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 13083 int i;
57ac7be9
AM
13084 int optional_tbtab;
13085
13086 if (rs6000_traceback == traceback_full)
13087 optional_tbtab = 1;
13088 else if (rs6000_traceback == traceback_part)
13089 optional_tbtab = 0;
13090 else
13091 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 13092
69c75916
AM
13093 if (optional_tbtab)
13094 {
13095 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
13096 while (*fname == '.') /* V.4 encodes . in the name */
13097 fname++;
13098
13099 /* Need label immediately before tbtab, so we can compute
13100 its offset from the function start. */
13101 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
13102 ASM_OUTPUT_LABEL (file, fname);
13103 }
314fc5a9
ILT
13104
13105 /* The .tbtab pseudo-op can only be used for the first eight
13106 expressions, since it can't handle the possibly variable
13107 length fields that follow. However, if you omit the optional
13108 fields, the assembler outputs zeros for all optional fields
13109 anyways, giving each variable length field is minimum length
13110 (as defined in sys/debug.h). Thus we can not use the .tbtab
13111 pseudo-op at all. */
13112
13113 /* An all-zero word flags the start of the tbtab, for debuggers
13114 that have to find it by searching forward from the entry
13115 point or from the current pc. */
19d2d16f 13116 fputs ("\t.long 0\n", file);
314fc5a9
ILT
13117
13118 /* Tbtab format type. Use format type 0. */
19d2d16f 13119 fputs ("\t.byte 0,", file);
314fc5a9 13120
5fc921c1
DE
13121 /* Language type. Unfortunately, there does not seem to be any
13122 official way to discover the language being compiled, so we
13123 use language_string.
13124 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
13125 Java is 13. Objective-C is 14. */
13126 if (! strcmp (language_string, "GNU C"))
314fc5a9
ILT
13127 i = 0;
13128 else if (! strcmp (language_string, "GNU F77"))
13129 i = 1;
8b83775b 13130 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 13131 i = 2;
5fc921c1
DE
13132 else if (! strcmp (language_string, "GNU Ada"))
13133 i = 3;
314fc5a9
ILT
13134 else if (! strcmp (language_string, "GNU C++"))
13135 i = 9;
9517ead8
AG
13136 else if (! strcmp (language_string, "GNU Java"))
13137 i = 13;
5fc921c1
DE
13138 else if (! strcmp (language_string, "GNU Objective-C"))
13139 i = 14;
314fc5a9
ILT
13140 else
13141 abort ();
13142 fprintf (file, "%d,", i);
13143
13144 /* 8 single bit fields: global linkage (not set for C extern linkage,
13145 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
13146 from start of procedure stored in tbtab, internal function, function
13147 has controlled storage, function has no toc, function uses fp,
13148 function logs/aborts fp operations. */
13149 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
13150 fprintf (file, "%d,",
13151 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
13152
13153 /* 6 bitfields: function is interrupt handler, name present in
13154 proc table, function calls alloca, on condition directives
13155 (controls stack walks, 3 bits), saves condition reg, saves
13156 link reg. */
13157 /* The `function calls alloca' bit seems to be set whenever reg 31 is
13158 set up as a frame pointer, even when there is no alloca call. */
13159 fprintf (file, "%d,",
6041bf2f
DE
13160 ((optional_tbtab << 6)
13161 | ((optional_tbtab & frame_pointer_needed) << 5)
13162 | (info->cr_save_p << 1)
13163 | (info->lr_save_p)));
314fc5a9 13164
6041bf2f 13165 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
13166 (6 bits). */
13167 fprintf (file, "%d,",
4697a36c 13168 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
13169
13170 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
13171 fprintf (file, "%d,", (32 - first_reg_to_save ()));
13172
6041bf2f
DE
13173 if (optional_tbtab)
13174 {
13175 /* Compute the parameter info from the function decl argument
13176 list. */
13177 tree decl;
13178 int next_parm_info_bit = 31;
314fc5a9 13179
6041bf2f
DE
13180 for (decl = DECL_ARGUMENTS (current_function_decl);
13181 decl; decl = TREE_CHAIN (decl))
13182 {
13183 rtx parameter = DECL_INCOMING_RTL (decl);
13184 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 13185
6041bf2f
DE
13186 if (GET_CODE (parameter) == REG)
13187 {
13188 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
13189 {
13190 int bits;
13191
13192 float_parms++;
13193
13194 if (mode == SFmode)
13195 bits = 0x2;
fcce224d 13196 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
13197 bits = 0x3;
13198 else
13199 abort ();
13200
13201 /* If only one bit will fit, don't or in this entry. */
13202 if (next_parm_info_bit > 0)
13203 parm_info |= (bits << (next_parm_info_bit - 1));
13204 next_parm_info_bit -= 2;
13205 }
13206 else
13207 {
13208 fixed_parms += ((GET_MODE_SIZE (mode)
13209 + (UNITS_PER_WORD - 1))
13210 / UNITS_PER_WORD);
13211 next_parm_info_bit -= 1;
13212 }
13213 }
13214 }
13215 }
314fc5a9
ILT
13216
13217 /* Number of fixed point parameters. */
13218 /* This is actually the number of words of fixed point parameters; thus
13219 an 8 byte struct counts as 2; and thus the maximum value is 8. */
13220 fprintf (file, "%d,", fixed_parms);
13221
13222 /* 2 bitfields: number of floating point parameters (7 bits), parameters
13223 all on stack. */
13224 /* This is actually the number of fp registers that hold parameters;
13225 and thus the maximum value is 13. */
13226 /* Set parameters on stack bit if parameters are not in their original
13227 registers, regardless of whether they are on the stack? Xlc
13228 seems to set the bit when not optimizing. */
13229 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
13230
6041bf2f
DE
13231 if (! optional_tbtab)
13232 return;
13233
314fc5a9
ILT
13234 /* Optional fields follow. Some are variable length. */
13235
13236 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
13237 11 double float. */
13238 /* There is an entry for each parameter in a register, in the order that
13239 they occur in the parameter list. Any intervening arguments on the
13240 stack are ignored. If the list overflows a long (max possible length
13241 34 bits) then completely leave off all elements that don't fit. */
13242 /* Only emit this long if there was at least one parameter. */
13243 if (fixed_parms || float_parms)
13244 fprintf (file, "\t.long %d\n", parm_info);
13245
13246 /* Offset from start of code to tb table. */
19d2d16f 13247 fputs ("\t.long ", file);
314fc5a9 13248 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
13249#if TARGET_AIX
13250 RS6000_OUTPUT_BASENAME (file, fname);
13251#else
9ebbca7d 13252 assemble_name (file, fname);
54ee9799 13253#endif
19d2d16f 13254 fputs ("-.", file);
54ee9799
DE
13255#if TARGET_AIX
13256 RS6000_OUTPUT_BASENAME (file, fname);
13257#else
9ebbca7d 13258 assemble_name (file, fname);
54ee9799 13259#endif
19d2d16f 13260 putc ('\n', file);
314fc5a9
ILT
13261
13262 /* Interrupt handler mask. */
13263 /* Omit this long, since we never set the interrupt handler bit
13264 above. */
13265
13266 /* Number of CTL (controlled storage) anchors. */
13267 /* Omit this long, since the has_ctl bit is never set above. */
13268
13269 /* Displacement into stack of each CTL anchor. */
13270 /* Omit this list of longs, because there are no CTL anchors. */
13271
13272 /* Length of function name. */
69c75916
AM
13273 if (*fname == '*')
13274 ++fname;
296b8152 13275 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
13276
13277 /* Function name. */
13278 assemble_string (fname, strlen (fname));
13279
13280 /* Register for alloca automatic storage; this is always reg 31.
13281 Only emit this if the alloca bit was set above. */
13282 if (frame_pointer_needed)
19d2d16f 13283 fputs ("\t.byte 31\n", file);
b1765bde
DE
13284
13285 fputs ("\t.align 2\n", file);
9b30bae2 13286 }
9878760c 13287}
17167fd8 13288\f
a4f6c312
SS
13289/* A C compound statement that outputs the assembler code for a thunk
13290 function, used to implement C++ virtual function calls with
13291 multiple inheritance. The thunk acts as a wrapper around a virtual
13292 function, adjusting the implicit object parameter before handing
13293 control off to the real function.
13294
13295 First, emit code to add the integer DELTA to the location that
13296 contains the incoming first argument. Assume that this argument
13297 contains a pointer, and is the one used to pass the `this' pointer
13298 in C++. This is the incoming argument *before* the function
13299 prologue, e.g. `%o0' on a sparc. The addition must preserve the
13300 values of all other incoming arguments.
17167fd8
MM
13301
13302 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
13303 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
13304 not touch the return address. Hence returning from FUNCTION will
13305 return to whoever called the current `thunk'.
17167fd8 13306
a4f6c312
SS
13307 The effect must be as if FUNCTION had been called directly with the
13308 adjusted first argument. This macro is responsible for emitting
13309 all of the code for a thunk function; output_function_prologue()
13310 and output_function_epilogue() are not invoked.
17167fd8 13311
a4f6c312
SS
13312 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
13313 been extracted from it.) It might possibly be useful on some
13314 targets, but probably not.
17167fd8 13315
a4f6c312
SS
13316 If you do not define this macro, the target-independent code in the
13317 C++ frontend will generate a less efficient heavyweight thunk that
13318 calls FUNCTION instead of jumping to it. The generic approach does
13319 not support varargs. */
17167fd8 13320
3961e8fe 13321static void
a2369ed3
DJ
13322rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
13323 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
13324 tree function)
17167fd8 13325{
5b71a4e7 13326 rtx this, insn, funexp;
17167fd8 13327
5b71a4e7 13328 reload_completed = 1;
fe3ad572 13329 epilogue_completed = 1;
5b71a4e7 13330 no_new_pseudos = 1;
56a7189a 13331
5b71a4e7 13332 /* Mark the end of the (empty) prologue. */
2e040219 13333 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 13334
5b71a4e7
DE
13335 /* Find the "this" pointer. If the function returns a structure,
13336 the structure return pointer is in r3. */
61f71b34 13337 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 13338 this = gen_rtx_REG (Pmode, 4);
56a7189a 13339 else
5b71a4e7 13340 this = gen_rtx_REG (Pmode, 3);
17167fd8 13341
5b71a4e7
DE
13342 /* Apply the constant offset, if required. */
13343 if (delta)
13344 {
13345 rtx delta_rtx = GEN_INT (delta);
13346 emit_insn (TARGET_32BIT
13347 ? gen_addsi3 (this, this, delta_rtx)
13348 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
13349 }
13350
5b71a4e7
DE
13351 /* Apply the offset from the vtable, if required. */
13352 if (vcall_offset)
17167fd8 13353 {
5b71a4e7
DE
13354 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
13355 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 13356
5b71a4e7 13357 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
13358 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
13359 {
13360 emit_insn (TARGET_32BIT
13361 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
13362 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
13363 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
13364 }
13365 else
13366 {
13367 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
13368
13369 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
13370 }
5b71a4e7
DE
13371 emit_insn (TARGET_32BIT
13372 ? gen_addsi3 (this, this, tmp)
13373 : gen_adddi3 (this, this, tmp));
17167fd8
MM
13374 }
13375
5b71a4e7
DE
13376 /* Generate a tail call to the target function. */
13377 if (!TREE_USED (function))
13378 {
13379 assemble_external (function);
13380 TREE_USED (function) = 1;
13381 }
13382 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 13383 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
13384
13385#if TARGET_MACHO
ab82a49f 13386 if (MACHOPIC_INDIRECT)
5b71a4e7 13387 funexp = machopic_indirect_call_target (funexp);
ee890fe2 13388#endif
5b71a4e7
DE
13389
13390 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
13391 generate sibcall RTL explicitly to avoid constraint abort. */
13392 insn = emit_call_insn (
13393 gen_rtx_PARALLEL (VOIDmode,
13394 gen_rtvec (4,
13395 gen_rtx_CALL (VOIDmode,
13396 funexp, const0_rtx),
13397 gen_rtx_USE (VOIDmode, const0_rtx),
13398 gen_rtx_USE (VOIDmode,
13399 gen_rtx_REG (SImode,
13400 LINK_REGISTER_REGNUM)),
13401 gen_rtx_RETURN (VOIDmode))));
13402 SIBLING_CALL_P (insn) = 1;
13403 emit_barrier ();
13404
13405 /* Run just enough of rest_of_compilation to get the insns emitted.
13406 There's not really enough bulk here to make other passes such as
13407 instruction scheduling worth while. Note that use_thunk calls
13408 assemble_start_function and assemble_end_function. */
13409 insn = get_insns ();
a2855205 13410 insn_locators_initialize ();
5b71a4e7
DE
13411 shorten_branches (insn);
13412 final_start_function (insn, file, 1);
13413 final (insn, file, 1, 0);
13414 final_end_function ();
13415
13416 reload_completed = 0;
fe3ad572 13417 epilogue_completed = 0;
5b71a4e7 13418 no_new_pseudos = 0;
9ebbca7d 13419}
9ebbca7d
GK
13420\f
13421/* A quick summary of the various types of 'constant-pool tables'
13422 under PowerPC:
13423
13424 Target Flags Name One table per
13425 AIX (none) AIX TOC object file
13426 AIX -mfull-toc AIX TOC object file
13427 AIX -mminimal-toc AIX minimal TOC translation unit
13428 SVR4/EABI (none) SVR4 SDATA object file
13429 SVR4/EABI -fpic SVR4 pic object file
13430 SVR4/EABI -fPIC SVR4 PIC translation unit
13431 SVR4/EABI -mrelocatable EABI TOC function
13432 SVR4/EABI -maix AIX TOC object file
13433 SVR4/EABI -maix -mminimal-toc
13434 AIX minimal TOC translation unit
13435
13436 Name Reg. Set by entries contains:
13437 made by addrs? fp? sum?
13438
13439 AIX TOC 2 crt0 as Y option option
13440 AIX minimal TOC 30 prolog gcc Y Y option
13441 SVR4 SDATA 13 crt0 gcc N Y N
13442 SVR4 pic 30 prolog ld Y not yet N
13443 SVR4 PIC 30 prolog gcc Y option option
13444 EABI TOC 30 prolog gcc Y option option
13445
13446*/
13447
9ebbca7d
GK
13448/* Hash functions for the hash table. */
13449
13450static unsigned
a2369ed3 13451rs6000_hash_constant (rtx k)
9ebbca7d 13452{
46b33600
RH
13453 enum rtx_code code = GET_CODE (k);
13454 enum machine_mode mode = GET_MODE (k);
13455 unsigned result = (code << 3) ^ mode;
13456 const char *format;
13457 int flen, fidx;
9ebbca7d 13458
46b33600
RH
13459 format = GET_RTX_FORMAT (code);
13460 flen = strlen (format);
13461 fidx = 0;
9ebbca7d 13462
46b33600
RH
13463 switch (code)
13464 {
13465 case LABEL_REF:
13466 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
13467
13468 case CONST_DOUBLE:
13469 if (mode != VOIDmode)
13470 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
13471 flen = 2;
13472 break;
13473
13474 case CODE_LABEL:
13475 fidx = 3;
13476 break;
13477
13478 default:
13479 break;
13480 }
9ebbca7d
GK
13481
13482 for (; fidx < flen; fidx++)
13483 switch (format[fidx])
13484 {
13485 case 's':
13486 {
13487 unsigned i, len;
13488 const char *str = XSTR (k, fidx);
13489 len = strlen (str);
13490 result = result * 613 + len;
13491 for (i = 0; i < len; i++)
13492 result = result * 613 + (unsigned) str[i];
17167fd8
MM
13493 break;
13494 }
9ebbca7d
GK
13495 case 'u':
13496 case 'e':
13497 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
13498 break;
13499 case 'i':
13500 case 'n':
13501 result = result * 613 + (unsigned) XINT (k, fidx);
13502 break;
13503 case 'w':
13504 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
13505 result = result * 613 + (unsigned) XWINT (k, fidx);
13506 else
13507 {
13508 size_t i;
13509 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
13510 result = result * 613 + (unsigned) (XWINT (k, fidx)
13511 >> CHAR_BIT * i);
13512 }
13513 break;
09501938
DE
13514 case '0':
13515 break;
9ebbca7d 13516 default:
a4f6c312 13517 abort ();
9ebbca7d 13518 }
46b33600 13519
9ebbca7d
GK
13520 return result;
13521}
13522
13523static unsigned
a2369ed3 13524toc_hash_function (const void *hash_entry)
9ebbca7d 13525{
a9098fd0
GK
13526 const struct toc_hash_struct *thc =
13527 (const struct toc_hash_struct *) hash_entry;
13528 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
13529}
13530
13531/* Compare H1 and H2 for equivalence. */
13532
13533static int
a2369ed3 13534toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
13535{
13536 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
13537 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
13538
a9098fd0
GK
13539 if (((const struct toc_hash_struct *) h1)->key_mode
13540 != ((const struct toc_hash_struct *) h2)->key_mode)
13541 return 0;
13542
5692c7bc 13543 return rtx_equal_p (r1, r2);
9ebbca7d
GK
13544}
13545
28e510bd
MM
13546/* These are the names given by the C++ front-end to vtables, and
13547 vtable-like objects. Ideally, this logic should not be here;
13548 instead, there should be some programmatic way of inquiring as
13549 to whether or not an object is a vtable. */
13550
13551#define VTABLE_NAME_P(NAME) \
13552 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
13553 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
13554 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
26be75db 13555 || strncmp ("_ZTI", name, strlen ("_ZTI")) == 0 \
28e510bd
MM
13556 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
13557
13558void
a2369ed3 13559rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
13560{
13561 /* Currently C++ toc references to vtables can be emitted before it
13562 is decided whether the vtable is public or private. If this is
13563 the case, then the linker will eventually complain that there is
13564 a reference to an unknown section. Thus, for vtables only,
13565 we emit the TOC reference to reference the symbol and not the
13566 section. */
13567 const char *name = XSTR (x, 0);
54ee9799
DE
13568
13569 if (VTABLE_NAME_P (name))
13570 {
13571 RS6000_OUTPUT_BASENAME (file, name);
13572 }
13573 else
13574 assemble_name (file, name);
28e510bd
MM
13575}
13576
a4f6c312
SS
13577/* Output a TOC entry. We derive the entry name from what is being
13578 written. */
9878760c
RK
13579
13580void
a2369ed3 13581output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
13582{
13583 char buf[256];
3cce094d 13584 const char *name = buf;
ec940faa 13585 const char *real_name;
9878760c
RK
13586 rtx base = x;
13587 int offset = 0;
13588
4697a36c
MM
13589 if (TARGET_NO_TOC)
13590 abort ();
13591
9ebbca7d
GK
13592 /* When the linker won't eliminate them, don't output duplicate
13593 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
13594 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
13595 CODE_LABELs. */
13596 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
13597 {
13598 struct toc_hash_struct *h;
13599 void * * found;
13600
17211ab5 13601 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 13602 time because GGC is not initialized at that point. */
17211ab5
GK
13603 if (toc_hash_table == NULL)
13604 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
13605 toc_hash_eq, NULL);
13606
9ebbca7d
GK
13607 h = ggc_alloc (sizeof (*h));
13608 h->key = x;
a9098fd0 13609 h->key_mode = mode;
9ebbca7d
GK
13610 h->labelno = labelno;
13611
13612 found = htab_find_slot (toc_hash_table, h, 1);
13613 if (*found == NULL)
13614 *found = h;
13615 else /* This is indeed a duplicate.
13616 Set this label equal to that label. */
13617 {
13618 fputs ("\t.set ", file);
13619 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13620 fprintf (file, "%d,", labelno);
13621 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13622 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
13623 found)->labelno));
13624 return;
13625 }
13626 }
13627
13628 /* If we're going to put a double constant in the TOC, make sure it's
13629 aligned properly when strict alignment is on. */
ff1720ed
RK
13630 if (GET_CODE (x) == CONST_DOUBLE
13631 && STRICT_ALIGNMENT
a9098fd0 13632 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
13633 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
13634 ASM_OUTPUT_ALIGN (file, 3);
13635 }
13636
4977bab6 13637 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 13638
37c37a57
RK
13639 /* Handle FP constants specially. Note that if we have a minimal
13640 TOC, things we put here aren't actually in the TOC, so we can allow
13641 FP constants. */
fcce224d
DE
13642 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
13643 {
13644 REAL_VALUE_TYPE rv;
13645 long k[4];
13646
13647 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13648 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
13649
13650 if (TARGET_64BIT)
13651 {
13652 if (TARGET_MINIMAL_TOC)
13653 fputs (DOUBLE_INT_ASM_OP, file);
13654 else
13655 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13656 k[0] & 0xffffffff, k[1] & 0xffffffff,
13657 k[2] & 0xffffffff, k[3] & 0xffffffff);
13658 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
13659 k[0] & 0xffffffff, k[1] & 0xffffffff,
13660 k[2] & 0xffffffff, k[3] & 0xffffffff);
13661 return;
13662 }
13663 else
13664 {
13665 if (TARGET_MINIMAL_TOC)
13666 fputs ("\t.long ", file);
13667 else
13668 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13669 k[0] & 0xffffffff, k[1] & 0xffffffff,
13670 k[2] & 0xffffffff, k[3] & 0xffffffff);
13671 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
13672 k[0] & 0xffffffff, k[1] & 0xffffffff,
13673 k[2] & 0xffffffff, k[3] & 0xffffffff);
13674 return;
13675 }
13676 }
13677 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 13678 {
042259f2
DE
13679 REAL_VALUE_TYPE rv;
13680 long k[2];
0adc764e 13681
042259f2
DE
13682 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13683 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 13684
13ded975
DE
13685 if (TARGET_64BIT)
13686 {
13687 if (TARGET_MINIMAL_TOC)
2bfcf297 13688 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13689 else
2f0552b6
AM
13690 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13691 k[0] & 0xffffffff, k[1] & 0xffffffff);
13692 fprintf (file, "0x%lx%08lx\n",
13693 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13694 return;
13695 }
1875cc88 13696 else
13ded975
DE
13697 {
13698 if (TARGET_MINIMAL_TOC)
2bfcf297 13699 fputs ("\t.long ", file);
13ded975 13700 else
2f0552b6
AM
13701 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13702 k[0] & 0xffffffff, k[1] & 0xffffffff);
13703 fprintf (file, "0x%lx,0x%lx\n",
13704 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13705 return;
13706 }
9878760c 13707 }
a9098fd0 13708 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 13709 {
042259f2
DE
13710 REAL_VALUE_TYPE rv;
13711 long l;
9878760c 13712
042259f2
DE
13713 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13714 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
13715
31bfaa0b
DE
13716 if (TARGET_64BIT)
13717 {
13718 if (TARGET_MINIMAL_TOC)
2bfcf297 13719 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 13720 else
2f0552b6
AM
13721 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13722 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
13723 return;
13724 }
042259f2 13725 else
31bfaa0b
DE
13726 {
13727 if (TARGET_MINIMAL_TOC)
2bfcf297 13728 fputs ("\t.long ", file);
31bfaa0b 13729 else
2f0552b6
AM
13730 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13731 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
13732 return;
13733 }
042259f2 13734 }
f176e826 13735 else if (GET_MODE (x) == VOIDmode
a9098fd0 13736 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 13737 {
e2c953b6 13738 unsigned HOST_WIDE_INT low;
042259f2
DE
13739 HOST_WIDE_INT high;
13740
13741 if (GET_CODE (x) == CONST_DOUBLE)
13742 {
13743 low = CONST_DOUBLE_LOW (x);
13744 high = CONST_DOUBLE_HIGH (x);
13745 }
13746 else
13747#if HOST_BITS_PER_WIDE_INT == 32
13748 {
13749 low = INTVAL (x);
0858c623 13750 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
13751 }
13752#else
13753 {
0858c623 13754 low = INTVAL (x) & 0xffffffff;
042259f2
DE
13755 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
13756 }
13757#endif
9878760c 13758
a9098fd0
GK
13759 /* TOC entries are always Pmode-sized, but since this
13760 is a bigendian machine then if we're putting smaller
13761 integer constants in the TOC we have to pad them.
13762 (This is still a win over putting the constants in
13763 a separate constant pool, because then we'd have
02a4ec28
FS
13764 to have both a TOC entry _and_ the actual constant.)
13765
13766 For a 32-bit target, CONST_INT values are loaded and shifted
13767 entirely within `low' and can be stored in one TOC entry. */
13768
13769 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 13770 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
13771
13772 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
13773 {
13774#if HOST_BITS_PER_WIDE_INT == 32
13775 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
13776 POINTER_SIZE, &low, &high, 0);
13777#else
13778 low |= high << 32;
13779 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
13780 high = (HOST_WIDE_INT) low >> 32;
13781 low &= 0xffffffff;
13782#endif
13783 }
a9098fd0 13784
13ded975
DE
13785 if (TARGET_64BIT)
13786 {
13787 if (TARGET_MINIMAL_TOC)
2bfcf297 13788 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13789 else
2f0552b6
AM
13790 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
13791 (long) high & 0xffffffff, (long) low & 0xffffffff);
13792 fprintf (file, "0x%lx%08lx\n",
13793 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
13794 return;
13795 }
1875cc88 13796 else
13ded975 13797 {
02a4ec28
FS
13798 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
13799 {
13800 if (TARGET_MINIMAL_TOC)
2bfcf297 13801 fputs ("\t.long ", file);
02a4ec28 13802 else
2bfcf297 13803 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
13804 (long) high & 0xffffffff, (long) low & 0xffffffff);
13805 fprintf (file, "0x%lx,0x%lx\n",
13806 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 13807 }
13ded975 13808 else
02a4ec28
FS
13809 {
13810 if (TARGET_MINIMAL_TOC)
2bfcf297 13811 fputs ("\t.long ", file);
02a4ec28 13812 else
2f0552b6
AM
13813 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
13814 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 13815 }
13ded975
DE
13816 return;
13817 }
9878760c
RK
13818 }
13819
13820 if (GET_CODE (x) == CONST)
13821 {
2bfcf297
DB
13822 if (GET_CODE (XEXP (x, 0)) != PLUS)
13823 abort ();
13824
9878760c
RK
13825 base = XEXP (XEXP (x, 0), 0);
13826 offset = INTVAL (XEXP (XEXP (x, 0), 1));
13827 }
13828
13829 if (GET_CODE (base) == SYMBOL_REF)
13830 name = XSTR (base, 0);
13831 else if (GET_CODE (base) == LABEL_REF)
13832 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
13833 else if (GET_CODE (base) == CODE_LABEL)
13834 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
13835 else
13836 abort ();
13837
772c5265 13838 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 13839 if (TARGET_MINIMAL_TOC)
2bfcf297 13840 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
13841 else
13842 {
b6c9286a 13843 fprintf (file, "\t.tc %s", real_name);
9878760c 13844
1875cc88
JW
13845 if (offset < 0)
13846 fprintf (file, ".N%d", - offset);
13847 else if (offset)
13848 fprintf (file, ".P%d", offset);
9878760c 13849
19d2d16f 13850 fputs ("[TC],", file);
1875cc88 13851 }
581bc4de
MM
13852
13853 /* Currently C++ toc references to vtables can be emitted before it
13854 is decided whether the vtable is public or private. If this is
13855 the case, then the linker will eventually complain that there is
13856 a TOC reference to an unknown section. Thus, for vtables only,
13857 we emit the TOC reference to reference the symbol and not the
13858 section. */
28e510bd 13859 if (VTABLE_NAME_P (name))
581bc4de 13860 {
54ee9799 13861 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
13862 if (offset < 0)
13863 fprintf (file, "%d", offset);
13864 else if (offset > 0)
13865 fprintf (file, "+%d", offset);
13866 }
13867 else
13868 output_addr_const (file, x);
19d2d16f 13869 putc ('\n', file);
9878760c
RK
13870}
13871\f
13872/* Output an assembler pseudo-op to write an ASCII string of N characters
13873 starting at P to FILE.
13874
13875 On the RS/6000, we have to do this using the .byte operation and
13876 write out special characters outside the quoted string.
13877 Also, the assembler is broken; very long strings are truncated,
a4f6c312 13878 so we must artificially break them up early. */
9878760c
RK
13879
13880void
a2369ed3 13881output_ascii (FILE *file, const char *p, int n)
9878760c
RK
13882{
13883 char c;
13884 int i, count_string;
d330fd93
KG
13885 const char *for_string = "\t.byte \"";
13886 const char *for_decimal = "\t.byte ";
13887 const char *to_close = NULL;
9878760c
RK
13888
13889 count_string = 0;
13890 for (i = 0; i < n; i++)
13891 {
13892 c = *p++;
13893 if (c >= ' ' && c < 0177)
13894 {
13895 if (for_string)
13896 fputs (for_string, file);
13897 putc (c, file);
13898
13899 /* Write two quotes to get one. */
13900 if (c == '"')
13901 {
13902 putc (c, file);
13903 ++count_string;
13904 }
13905
13906 for_string = NULL;
13907 for_decimal = "\"\n\t.byte ";
13908 to_close = "\"\n";
13909 ++count_string;
13910
13911 if (count_string >= 512)
13912 {
13913 fputs (to_close, file);
13914
13915 for_string = "\t.byte \"";
13916 for_decimal = "\t.byte ";
13917 to_close = NULL;
13918 count_string = 0;
13919 }
13920 }
13921 else
13922 {
13923 if (for_decimal)
13924 fputs (for_decimal, file);
13925 fprintf (file, "%d", c);
13926
13927 for_string = "\n\t.byte \"";
13928 for_decimal = ", ";
13929 to_close = "\n";
13930 count_string = 0;
13931 }
13932 }
13933
13934 /* Now close the string if we have written one. Then end the line. */
13935 if (to_close)
9ebbca7d 13936 fputs (to_close, file);
9878760c
RK
13937}
13938\f
13939/* Generate a unique section name for FILENAME for a section type
13940 represented by SECTION_DESC. Output goes into BUF.
13941
13942 SECTION_DESC can be any string, as long as it is different for each
13943 possible section type.
13944
13945 We name the section in the same manner as xlc. The name begins with an
13946 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13947 names) with the last period replaced by the string SECTION_DESC. If
13948 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13949 the name. */
9878760c
RK
13950
13951void
a2369ed3
DJ
13952rs6000_gen_section_name (char **buf, const char *filename,
13953 const char *section_desc)
9878760c 13954{
9ebbca7d 13955 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13956 char *p;
13957 int len;
9878760c
RK
13958
13959 after_last_slash = filename;
13960 for (q = filename; *q; q++)
11e5fe42
RK
13961 {
13962 if (*q == '/')
13963 after_last_slash = q + 1;
13964 else if (*q == '.')
13965 last_period = q;
13966 }
9878760c 13967
11e5fe42 13968 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13969 *buf = (char *) xmalloc (len);
9878760c
RK
13970
13971 p = *buf;
13972 *p++ = '_';
13973
13974 for (q = after_last_slash; *q; q++)
13975 {
11e5fe42 13976 if (q == last_period)
9878760c
RK
13977 {
13978 strcpy (p, section_desc);
13979 p += strlen (section_desc);
e3981aab 13980 break;
9878760c
RK
13981 }
13982
e9a780ec 13983 else if (ISALNUM (*q))
9878760c
RK
13984 *p++ = *q;
13985 }
13986
11e5fe42 13987 if (last_period == 0)
9878760c
RK
13988 strcpy (p, section_desc);
13989 else
13990 *p = '\0';
13991}
e165f3f0 13992\f
a4f6c312 13993/* Emit profile function. */
411707f4 13994
411707f4 13995void
a2369ed3 13996output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 13997{
ffcfcb5f
AM
13998 if (TARGET_PROFILE_KERNEL)
13999 return;
14000
8480e480
CC
14001 if (DEFAULT_ABI == ABI_AIX)
14002 {
9739c90c
JJ
14003#ifndef NO_PROFILE_COUNTERS
14004# define NO_PROFILE_COUNTERS 0
14005#endif
14006 if (NO_PROFILE_COUNTERS)
14007 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
14008 else
14009 {
14010 char buf[30];
14011 const char *label_name;
14012 rtx fun;
411707f4 14013
9739c90c
JJ
14014 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
14015 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
14016 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 14017
9739c90c
JJ
14018 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
14019 fun, Pmode);
14020 }
8480e480 14021 }
ee890fe2
SS
14022 else if (DEFAULT_ABI == ABI_DARWIN)
14023 {
d5fa86ba 14024 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
14025 int caller_addr_regno = LINK_REGISTER_REGNUM;
14026
14027 /* Be conservative and always set this, at least for now. */
14028 current_function_uses_pic_offset_table = 1;
14029
14030#if TARGET_MACHO
14031 /* For PIC code, set up a stub and collect the caller's address
14032 from r0, which is where the prologue puts it. */
ab82a49f 14033 if (MACHOPIC_INDIRECT)
ee890fe2
SS
14034 {
14035 mcount_name = machopic_stub_name (mcount_name);
14036 if (current_function_uses_pic_offset_table)
14037 caller_addr_regno = 0;
14038 }
14039#endif
14040 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
14041 0, VOIDmode, 1,
14042 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
14043 }
411707f4
CC
14044}
14045
a4f6c312 14046/* Write function profiler code. */
e165f3f0
RK
14047
14048void
a2369ed3 14049output_function_profiler (FILE *file, int labelno)
e165f3f0 14050{
3daf36a4 14051 char buf[100];
09eeeacb 14052 int save_lr = 8;
e165f3f0 14053
38c1f2d7 14054 switch (DEFAULT_ABI)
3daf36a4 14055 {
38c1f2d7
MM
14056 default:
14057 abort ();
14058
14059 case ABI_V4:
09eeeacb 14060 save_lr = 4;
09eeeacb
AM
14061 if (!TARGET_32BIT)
14062 {
14063 warning ("no profiling of 64-bit code for this ABI");
14064 return;
14065 }
ffcfcb5f 14066 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
14067 fprintf (file, "\tmflr %s\n", reg_names[0]);
14068 if (flag_pic == 1)
14069 {
dfdfa60f 14070 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
14071 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
14072 reg_names[0], save_lr, reg_names[1]);
17167fd8 14073 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 14074 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 14075 assemble_name (file, buf);
17167fd8 14076 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 14077 }
9ebbca7d 14078 else if (flag_pic > 1)
38c1f2d7 14079 {
09eeeacb
AM
14080 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
14081 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
14082 /* Now, we need to get the address of the label. */
14083 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 14084 assemble_name (file, buf);
9ebbca7d
GK
14085 fputs ("-.\n1:", file);
14086 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
14087 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
14088 reg_names[0], reg_names[11]);
14089 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
14090 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 14091 }
38c1f2d7
MM
14092 else
14093 {
17167fd8 14094 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 14095 assemble_name (file, buf);
dfdfa60f 14096 fputs ("@ha\n", file);
09eeeacb
AM
14097 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
14098 reg_names[0], save_lr, reg_names[1]);
a260abc9 14099 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 14100 assemble_name (file, buf);
17167fd8 14101 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
14102 }
14103
50d440bc 14104 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
14105 fprintf (file, "\tbl %s%s\n",
14106 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
14107 break;
14108
14109 case ABI_AIX:
ee890fe2 14110 case ABI_DARWIN:
ffcfcb5f
AM
14111 if (!TARGET_PROFILE_KERNEL)
14112 {
a3c9585f 14113 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
14114 }
14115 else
14116 {
14117 if (TARGET_32BIT)
14118 abort ();
14119
14120 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
14121 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
14122
14123 if (current_function_needs_context)
14124 {
14125 asm_fprintf (file, "\tstd %s,24(%s)\n",
14126 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
14127 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
14128 asm_fprintf (file, "\tld %s,24(%s)\n",
14129 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
14130 }
14131 else
14132 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
14133 }
38c1f2d7
MM
14134 break;
14135 }
e165f3f0 14136}
a251ffd0 14137
b54cf83a
DE
14138\f
14139static int
863d938c 14140rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
14141{
14142 return 1;
14143}
14144
b54cf83a
DE
14145/* Power4 load update and store update instructions are cracked into a
14146 load or store and an integer insn which are executed in the same cycle.
14147 Branches have their own dispatch slot which does not count against the
14148 GCC issue rate, but it changes the program flow so there are no other
14149 instructions to issue in this cycle. */
14150
14151static int
a2369ed3
DJ
14152rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
14153 int verbose ATTRIBUTE_UNUSED,
14154 rtx insn, int more)
b54cf83a
DE
14155{
14156 if (GET_CODE (PATTERN (insn)) == USE
14157 || GET_CODE (PATTERN (insn)) == CLOBBER)
14158 return more;
14159
ec507f2d 14160 if (rs6000_sched_groups)
b54cf83a 14161 {
cbe26ab8
DN
14162 if (is_microcoded_insn (insn))
14163 return 0;
14164 else if (is_cracked_insn (insn))
14165 return more > 2 ? more - 2 : 0;
b54cf83a 14166 }
165b263e
DE
14167
14168 return more - 1;
b54cf83a
DE
14169}
14170
a251ffd0
TG
14171/* Adjust the cost of a scheduling dependency. Return the new cost of
14172 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
14173
c237e94a 14174static int
a2369ed3
DJ
14175rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
14176 int cost)
a251ffd0
TG
14177{
14178 if (! recog_memoized (insn))
14179 return 0;
14180
14181 if (REG_NOTE_KIND (link) != 0)
14182 return 0;
14183
14184 if (REG_NOTE_KIND (link) == 0)
14185 {
ed947a96
DJ
14186 /* Data dependency; DEP_INSN writes a register that INSN reads
14187 some cycles later. */
14188 switch (get_attr_type (insn))
14189 {
14190 case TYPE_JMPREG:
309323c2 14191 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
14192 a mtctr and bctr (and mtlr and br/blr). The first
14193 scheduling pass will not know about this latency since
14194 the mtctr instruction, which has the latency associated
14195 to it, will be generated by reload. */
309323c2 14196 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
14197 case TYPE_BRANCH:
14198 /* Leave some extra cycles between a compare and its
14199 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
14200 if ((rs6000_cpu_attr == CPU_PPC603
14201 || rs6000_cpu_attr == CPU_PPC604
14202 || rs6000_cpu_attr == CPU_PPC604E
14203 || rs6000_cpu_attr == CPU_PPC620
14204 || rs6000_cpu_attr == CPU_PPC630
14205 || rs6000_cpu_attr == CPU_PPC750
14206 || rs6000_cpu_attr == CPU_PPC7400
14207 || rs6000_cpu_attr == CPU_PPC7450
ec507f2d
DE
14208 || rs6000_cpu_attr == CPU_POWER4
14209 || rs6000_cpu_attr == CPU_POWER5)
ed947a96
DJ
14210 && recog_memoized (dep_insn)
14211 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
14212 && (get_attr_type (dep_insn) == TYPE_CMP
14213 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 14214 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
14215 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
14216 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 14217 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
14218 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
14219 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
14220 return cost + 2;
14221 default:
14222 break;
14223 }
a251ffd0
TG
14224 /* Fall out to return default cost. */
14225 }
14226
14227 return cost;
14228}
b6c9286a 14229
cbe26ab8 14230/* The function returns a true if INSN is microcoded.
839a4992 14231 Return false otherwise. */
cbe26ab8
DN
14232
14233static bool
14234is_microcoded_insn (rtx insn)
14235{
14236 if (!insn || !INSN_P (insn)
14237 || GET_CODE (PATTERN (insn)) == USE
14238 || GET_CODE (PATTERN (insn)) == CLOBBER)
14239 return false;
14240
ec507f2d 14241 if (rs6000_sched_groups)
cbe26ab8
DN
14242 {
14243 enum attr_type type = get_attr_type (insn);
14244 if (type == TYPE_LOAD_EXT_U
14245 || type == TYPE_LOAD_EXT_UX
14246 || type == TYPE_LOAD_UX
14247 || type == TYPE_STORE_UX
14248 || type == TYPE_MFCR)
14249 return true;
14250 }
14251
14252 return false;
14253}
14254
5c425df5 14255/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
14256 as the first insn in a dispatch group ("dispatch-slot restricted").
14257 In this case, the returned value indicates how many dispatch slots
14258 the insn occupies (at the beginning of the group).
79ae11c4
DN
14259 Return 0 otherwise. */
14260
cbe26ab8 14261static int
79ae11c4
DN
14262is_dispatch_slot_restricted (rtx insn)
14263{
14264 enum attr_type type;
14265
ec507f2d 14266 if (!rs6000_sched_groups)
79ae11c4
DN
14267 return 0;
14268
14269 if (!insn
14270 || insn == NULL_RTX
14271 || GET_CODE (insn) == NOTE
14272 || GET_CODE (PATTERN (insn)) == USE
14273 || GET_CODE (PATTERN (insn)) == CLOBBER)
14274 return 0;
14275
14276 type = get_attr_type (insn);
14277
ec507f2d
DE
14278 switch (type)
14279 {
14280 case TYPE_MFCR:
14281 case TYPE_MFCRF:
14282 case TYPE_MTCR:
14283 case TYPE_DELAYED_CR:
14284 case TYPE_CR_LOGICAL:
14285 case TYPE_MTJMPR:
14286 case TYPE_MFJMPR:
14287 return 1;
14288 case TYPE_IDIV:
14289 case TYPE_LDIV:
14290 return 2;
14291 default:
14292 if (rs6000_cpu == PROCESSOR_POWER5
14293 && is_cracked_insn (insn))
14294 return 2;
14295 return 0;
14296 }
79ae11c4
DN
14297}
14298
cbe26ab8
DN
14299/* The function returns true if INSN is cracked into 2 instructions
14300 by the processor (and therefore occupies 2 issue slots). */
14301
14302static bool
14303is_cracked_insn (rtx insn)
14304{
14305 if (!insn || !INSN_P (insn)
14306 || GET_CODE (PATTERN (insn)) == USE
14307 || GET_CODE (PATTERN (insn)) == CLOBBER)
14308 return false;
14309
ec507f2d 14310 if (rs6000_sched_groups)
cbe26ab8
DN
14311 {
14312 enum attr_type type = get_attr_type (insn);
14313 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
14314 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
14315 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
14316 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
14317 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
14318 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
14319 || type == TYPE_IDIV || type == TYPE_LDIV
14320 || type == TYPE_INSERT_WORD)
14321 return true;
14322 }
14323
14324 return false;
14325}
14326
14327/* The function returns true if INSN can be issued only from
a3c9585f 14328 the branch slot. */
cbe26ab8
DN
14329
14330static bool
14331is_branch_slot_insn (rtx insn)
14332{
14333 if (!insn || !INSN_P (insn)
14334 || GET_CODE (PATTERN (insn)) == USE
14335 || GET_CODE (PATTERN (insn)) == CLOBBER)
14336 return false;
14337
ec507f2d 14338 if (rs6000_sched_groups)
cbe26ab8
DN
14339 {
14340 enum attr_type type = get_attr_type (insn);
14341 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
14342 return true;
14343 return false;
14344 }
14345
14346 return false;
14347}
79ae11c4 14348
a4f6c312 14349/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
14350 priority INSN_PRIORITY (INSN). Increase the priority to execute the
14351 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
14352 define this macro if you do not need to adjust the scheduling
14353 priorities of insns. */
bef84347 14354
c237e94a 14355static int
a2369ed3 14356rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 14357{
a4f6c312
SS
14358 /* On machines (like the 750) which have asymmetric integer units,
14359 where one integer unit can do multiply and divides and the other
14360 can't, reduce the priority of multiply/divide so it is scheduled
14361 before other integer operations. */
bef84347
VM
14362
14363#if 0
2c3c49de 14364 if (! INSN_P (insn))
bef84347
VM
14365 return priority;
14366
14367 if (GET_CODE (PATTERN (insn)) == USE)
14368 return priority;
14369
14370 switch (rs6000_cpu_attr) {
14371 case CPU_PPC750:
14372 switch (get_attr_type (insn))
14373 {
14374 default:
14375 break;
14376
14377 case TYPE_IMUL:
14378 case TYPE_IDIV:
3cb999d8
DE
14379 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
14380 priority, priority);
bef84347
VM
14381 if (priority >= 0 && priority < 0x01000000)
14382 priority >>= 3;
14383 break;
14384 }
14385 }
14386#endif
14387
79ae11c4
DN
14388 if (is_dispatch_slot_restricted (insn)
14389 && reload_completed
14390 && current_sched_info->sched_max_insns_priority
14391 && rs6000_sched_restricted_insns_priority)
14392 {
14393
14394 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
14395 if (rs6000_sched_restricted_insns_priority == 1)
14396 /* Attach highest priority to insn. This means that in
14397 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
14398 precede 'priority' (critical path) considerations. */
14399 return current_sched_info->sched_max_insns_priority;
14400 else if (rs6000_sched_restricted_insns_priority == 2)
14401 /* Increase priority of insn by a minimal amount. This means that in
14402 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
14403 precede dispatch-slot restriction considerations. */
14404 return (priority + 1);
14405 }
14406
bef84347
VM
14407 return priority;
14408}
14409
a4f6c312
SS
14410/* Return how many instructions the machine can issue per cycle. */
14411
c237e94a 14412static int
863d938c 14413rs6000_issue_rate (void)
b6c9286a 14414{
3317bab1
DE
14415 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
14416 if (!reload_completed)
14417 return 1;
14418
b6c9286a 14419 switch (rs6000_cpu_attr) {
3cb999d8
DE
14420 case CPU_RIOS1: /* ? */
14421 case CPU_RS64A:
14422 case CPU_PPC601: /* ? */
ed947a96 14423 case CPU_PPC7450:
3cb999d8 14424 return 3;
b54cf83a 14425 case CPU_PPC440:
b6c9286a 14426 case CPU_PPC603:
bef84347 14427 case CPU_PPC750:
ed947a96 14428 case CPU_PPC7400:
be12c2b0 14429 case CPU_PPC8540:
bef84347 14430 return 2;
3cb999d8 14431 case CPU_RIOS2:
b6c9286a 14432 case CPU_PPC604:
19684119 14433 case CPU_PPC604E:
b6c9286a 14434 case CPU_PPC620:
3cb999d8 14435 case CPU_PPC630:
b6c9286a 14436 return 4;
cbe26ab8 14437 case CPU_POWER4:
ec507f2d 14438 case CPU_POWER5:
cbe26ab8 14439 return 5;
b6c9286a
MM
14440 default:
14441 return 1;
14442 }
14443}
14444
be12c2b0
VM
14445/* Return how many instructions to look ahead for better insn
14446 scheduling. */
14447
14448static int
863d938c 14449rs6000_use_sched_lookahead (void)
be12c2b0
VM
14450{
14451 if (rs6000_cpu_attr == CPU_PPC8540)
14452 return 4;
14453 return 0;
14454}
14455
569fa502
DN
14456/* Determine is PAT refers to memory. */
14457
14458static bool
14459is_mem_ref (rtx pat)
14460{
14461 const char * fmt;
14462 int i, j;
14463 bool ret = false;
14464
14465 if (GET_CODE (pat) == MEM)
14466 return true;
14467
14468 /* Recursively process the pattern. */
14469 fmt = GET_RTX_FORMAT (GET_CODE (pat));
14470
14471 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
14472 {
14473 if (fmt[i] == 'e')
14474 ret |= is_mem_ref (XEXP (pat, i));
14475 else if (fmt[i] == 'E')
14476 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
14477 ret |= is_mem_ref (XVECEXP (pat, i, j));
14478 }
14479
14480 return ret;
14481}
14482
14483/* Determine if PAT is a PATTERN of a load insn. */
14484
14485static bool
14486is_load_insn1 (rtx pat)
14487{
14488 if (!pat || pat == NULL_RTX)
14489 return false;
14490
14491 if (GET_CODE (pat) == SET)
14492 return is_mem_ref (SET_SRC (pat));
14493
14494 if (GET_CODE (pat) == PARALLEL)
14495 {
14496 int i;
14497
14498 for (i = 0; i < XVECLEN (pat, 0); i++)
14499 if (is_load_insn1 (XVECEXP (pat, 0, i)))
14500 return true;
14501 }
14502
14503 return false;
14504}
14505
14506/* Determine if INSN loads from memory. */
14507
14508static bool
14509is_load_insn (rtx insn)
14510{
14511 if (!insn || !INSN_P (insn))
14512 return false;
14513
14514 if (GET_CODE (insn) == CALL_INSN)
14515 return false;
14516
14517 return is_load_insn1 (PATTERN (insn));
14518}
14519
14520/* Determine if PAT is a PATTERN of a store insn. */
14521
14522static bool
14523is_store_insn1 (rtx pat)
14524{
14525 if (!pat || pat == NULL_RTX)
14526 return false;
14527
14528 if (GET_CODE (pat) == SET)
14529 return is_mem_ref (SET_DEST (pat));
14530
14531 if (GET_CODE (pat) == PARALLEL)
14532 {
14533 int i;
14534
14535 for (i = 0; i < XVECLEN (pat, 0); i++)
14536 if (is_store_insn1 (XVECEXP (pat, 0, i)))
14537 return true;
14538 }
14539
14540 return false;
14541}
14542
14543/* Determine if INSN stores to memory. */
14544
14545static bool
14546is_store_insn (rtx insn)
14547{
14548 if (!insn || !INSN_P (insn))
14549 return false;
14550
14551 return is_store_insn1 (PATTERN (insn));
14552}
14553
14554/* Returns whether the dependence between INSN and NEXT is considered
14555 costly by the given target. */
14556
14557static bool
14558rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
14559{
14560 /* If the flag is not enbled - no dependence is considered costly;
14561 allow all dependent insns in the same group.
14562 This is the most aggressive option. */
14563 if (rs6000_sched_costly_dep == no_dep_costly)
14564 return false;
14565
14566 /* If the flag is set to 1 - a dependence is always considered costly;
14567 do not allow dependent instructions in the same group.
14568 This is the most conservative option. */
14569 if (rs6000_sched_costly_dep == all_deps_costly)
14570 return true;
14571
14572 if (rs6000_sched_costly_dep == store_to_load_dep_costly
14573 && is_load_insn (next)
14574 && is_store_insn (insn))
14575 /* Prevent load after store in the same group. */
14576 return true;
14577
14578 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
14579 && is_load_insn (next)
14580 && is_store_insn (insn)
14581 && (!link || (int) REG_NOTE_KIND (link) == 0))
14582 /* Prevent load after store in the same group if it is a true dependence. */
14583 return true;
14584
14585 /* The flag is set to X; dependences with latency >= X are considered costly,
14586 and will not be scheduled in the same group. */
14587 if (rs6000_sched_costly_dep <= max_dep_latency
14588 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
14589 return true;
14590
14591 return false;
14592}
14593
cbe26ab8
DN
14594/* Return the next insn after INSN that is found before TAIL is reached,
14595 skipping any "non-active" insns - insns that will not actually occupy
14596 an issue slot. Return NULL_RTX if such an insn is not found. */
14597
14598static rtx
14599get_next_active_insn (rtx insn, rtx tail)
14600{
14601 rtx next_insn;
14602
14603 if (!insn || insn == tail)
14604 return NULL_RTX;
14605
14606 next_insn = NEXT_INSN (insn);
14607
14608 while (next_insn
14609 && next_insn != tail
14610 && (GET_CODE(next_insn) == NOTE
14611 || GET_CODE (PATTERN (next_insn)) == USE
14612 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
14613 {
14614 next_insn = NEXT_INSN (next_insn);
14615 }
14616
14617 if (!next_insn || next_insn == tail)
14618 return NULL_RTX;
14619
14620 return next_insn;
14621}
14622
839a4992 14623/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
14624 of group WHICH_GROUP.
14625
14626 If WHICH_GROUP == current_group, this function will return true if INSN
14627 causes the termination of the current group (i.e, the dispatch group to
14628 which INSN belongs). This means that INSN will be the last insn in the
14629 group it belongs to.
14630
14631 If WHICH_GROUP == previous_group, this function will return true if INSN
14632 causes the termination of the previous group (i.e, the dispatch group that
14633 precedes the group to which INSN belongs). This means that INSN will be
14634 the first insn in the group it belongs to). */
14635
14636static bool
14637insn_terminates_group_p (rtx insn, enum group_termination which_group)
14638{
14639 enum attr_type type;
14640
14641 if (! insn)
14642 return false;
569fa502 14643
cbe26ab8
DN
14644 type = get_attr_type (insn);
14645
14646 if (is_microcoded_insn (insn))
14647 return true;
14648
14649 if (which_group == current_group)
14650 {
14651 if (is_branch_slot_insn (insn))
14652 return true;
14653 return false;
14654 }
14655 else if (which_group == previous_group)
14656 {
14657 if (is_dispatch_slot_restricted (insn))
14658 return true;
14659 return false;
14660 }
14661
14662 return false;
14663}
14664
839a4992 14665/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
14666 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
14667
14668static bool
14669is_costly_group (rtx *group_insns, rtx next_insn)
14670{
14671 int i;
14672 rtx link;
14673 int cost;
14674 int issue_rate = rs6000_issue_rate ();
14675
14676 for (i = 0; i < issue_rate; i++)
14677 {
14678 rtx insn = group_insns[i];
14679 if (!insn)
14680 continue;
14681 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
14682 {
14683 rtx next = XEXP (link, 0);
14684 if (next == next_insn)
14685 {
14686 cost = insn_cost (insn, link, next_insn);
14687 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
14688 return true;
14689 }
14690 }
14691 }
14692
14693 return false;
14694}
14695
14696/* Utility of the function redefine_groups.
14697 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
14698 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
14699 to keep it "far" (in a separate group) from GROUP_INSNS, following
14700 one of the following schemes, depending on the value of the flag
14701 -minsert_sched_nops = X:
14702 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 14703 in order to force NEXT_INSN into a separate group.
cbe26ab8
DN
14704 (2) X < sched_finish_regroup_exact: insert exactly X nops.
14705 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
14706 insertion (has a group just ended, how many vacant issue slots remain in the
14707 last group, and how many dispatch groups were encountered so far). */
14708
14709static int
14710force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
14711 bool *group_end, int can_issue_more, int *group_count)
14712{
14713 rtx nop;
14714 bool force;
14715 int issue_rate = rs6000_issue_rate ();
14716 bool end = *group_end;
14717 int i;
14718
14719 if (next_insn == NULL_RTX)
14720 return can_issue_more;
14721
14722 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
14723 return can_issue_more;
14724
14725 force = is_costly_group (group_insns, next_insn);
14726 if (!force)
14727 return can_issue_more;
14728
14729 if (sched_verbose > 6)
14730 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
14731 *group_count ,can_issue_more);
14732
14733 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
14734 {
14735 if (*group_end)
14736 can_issue_more = 0;
14737
14738 /* Since only a branch can be issued in the last issue_slot, it is
14739 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
14740 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
14741 in this case the last nop will start a new group and the branch will be
14742 forced to the new group. */
14743 if (can_issue_more && !is_branch_slot_insn (next_insn))
14744 can_issue_more--;
14745
14746 while (can_issue_more > 0)
14747 {
14748 nop = gen_nop();
14749 emit_insn_before (nop, next_insn);
14750 can_issue_more--;
14751 }
14752
14753 *group_end = true;
14754 return 0;
14755 }
14756
14757 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
14758 {
14759 int n_nops = rs6000_sched_insert_nops;
14760
14761 /* Nops can't be issued from the branch slot, so the effective
14762 issue_rate for nops is 'issue_rate - 1'. */
14763 if (can_issue_more == 0)
14764 can_issue_more = issue_rate;
14765 can_issue_more--;
14766 if (can_issue_more == 0)
14767 {
14768 can_issue_more = issue_rate - 1;
14769 (*group_count)++;
14770 end = true;
14771 for (i = 0; i < issue_rate; i++)
14772 {
14773 group_insns[i] = 0;
14774 }
14775 }
14776
14777 while (n_nops > 0)
14778 {
14779 nop = gen_nop ();
14780 emit_insn_before (nop, next_insn);
14781 if (can_issue_more == issue_rate - 1) /* new group begins */
14782 end = false;
14783 can_issue_more--;
14784 if (can_issue_more == 0)
14785 {
14786 can_issue_more = issue_rate - 1;
14787 (*group_count)++;
14788 end = true;
14789 for (i = 0; i < issue_rate; i++)
14790 {
14791 group_insns[i] = 0;
14792 }
14793 }
14794 n_nops--;
14795 }
14796
14797 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
14798 can_issue_more++;
14799
14800 *group_end = /* Is next_insn going to start a new group? */
14801 (end
14802 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14803 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14804 || (can_issue_more < issue_rate &&
14805 insn_terminates_group_p (next_insn, previous_group)));
14806 if (*group_end && end)
14807 (*group_count)--;
14808
14809 if (sched_verbose > 6)
14810 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
14811 *group_count, can_issue_more);
14812 return can_issue_more;
14813 }
14814
14815 return can_issue_more;
14816}
14817
14818/* This function tries to synch the dispatch groups that the compiler "sees"
14819 with the dispatch groups that the processor dispatcher is expected to
14820 form in practice. It tries to achieve this synchronization by forcing the
14821 estimated processor grouping on the compiler (as opposed to the function
14822 'pad_goups' which tries to force the scheduler's grouping on the processor).
14823
14824 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
14825 examines the (estimated) dispatch groups that will be formed by the processor
14826 dispatcher. It marks these group boundaries to reflect the estimated
14827 processor grouping, overriding the grouping that the scheduler had marked.
14828 Depending on the value of the flag '-minsert-sched-nops' this function can
14829 force certain insns into separate groups or force a certain distance between
14830 them by inserting nops, for example, if there exists a "costly dependence"
14831 between the insns.
14832
14833 The function estimates the group boundaries that the processor will form as
14834 folllows: It keeps track of how many vacant issue slots are available after
14835 each insn. A subsequent insn will start a new group if one of the following
14836 4 cases applies:
14837 - no more vacant issue slots remain in the current dispatch group.
14838 - only the last issue slot, which is the branch slot, is vacant, but the next
14839 insn is not a branch.
14840 - only the last 2 or less issue slots, including the branch slot, are vacant,
14841 which means that a cracked insn (which occupies two issue slots) can't be
14842 issued in this group.
14843 - less than 'issue_rate' slots are vacant, and the next insn always needs to
14844 start a new group. */
14845
14846static int
14847redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14848{
14849 rtx insn, next_insn;
14850 int issue_rate;
14851 int can_issue_more;
14852 int slot, i;
14853 bool group_end;
14854 int group_count = 0;
14855 rtx *group_insns;
14856
14857 /* Initialize. */
14858 issue_rate = rs6000_issue_rate ();
14859 group_insns = alloca (issue_rate * sizeof (rtx));
14860 for (i = 0; i < issue_rate; i++)
14861 {
14862 group_insns[i] = 0;
14863 }
14864 can_issue_more = issue_rate;
14865 slot = 0;
14866 insn = get_next_active_insn (prev_head_insn, tail);
14867 group_end = false;
14868
14869 while (insn != NULL_RTX)
14870 {
14871 slot = (issue_rate - can_issue_more);
14872 group_insns[slot] = insn;
14873 can_issue_more =
14874 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14875 if (insn_terminates_group_p (insn, current_group))
14876 can_issue_more = 0;
14877
14878 next_insn = get_next_active_insn (insn, tail);
14879 if (next_insn == NULL_RTX)
14880 return group_count + 1;
14881
14882 group_end = /* Is next_insn going to start a new group? */
14883 (can_issue_more == 0
14884 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14885 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14886 || (can_issue_more < issue_rate &&
14887 insn_terminates_group_p (next_insn, previous_group)));
14888
14889 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
14890 next_insn, &group_end, can_issue_more, &group_count);
14891
14892 if (group_end)
14893 {
14894 group_count++;
14895 can_issue_more = 0;
14896 for (i = 0; i < issue_rate; i++)
14897 {
14898 group_insns[i] = 0;
14899 }
14900 }
14901
14902 if (GET_MODE (next_insn) == TImode && can_issue_more)
14903 PUT_MODE(next_insn, VOIDmode);
14904 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
14905 PUT_MODE (next_insn, TImode);
14906
14907 insn = next_insn;
14908 if (can_issue_more == 0)
14909 can_issue_more = issue_rate;
14910 } /* while */
14911
14912 return group_count;
14913}
14914
14915/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
14916 dispatch group boundaries that the scheduler had marked. Pad with nops
14917 any dispatch groups which have vacant issue slots, in order to force the
14918 scheduler's grouping on the processor dispatcher. The function
14919 returns the number of dispatch groups found. */
14920
14921static int
14922pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14923{
14924 rtx insn, next_insn;
14925 rtx nop;
14926 int issue_rate;
14927 int can_issue_more;
14928 int group_end;
14929 int group_count = 0;
14930
14931 /* Initialize issue_rate. */
14932 issue_rate = rs6000_issue_rate ();
14933 can_issue_more = issue_rate;
14934
14935 insn = get_next_active_insn (prev_head_insn, tail);
14936 next_insn = get_next_active_insn (insn, tail);
14937
14938 while (insn != NULL_RTX)
14939 {
14940 can_issue_more =
14941 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14942
14943 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
14944
14945 if (next_insn == NULL_RTX)
14946 break;
14947
14948 if (group_end)
14949 {
14950 /* If the scheduler had marked group termination at this location
14951 (between insn and next_indn), and neither insn nor next_insn will
14952 force group termination, pad the group with nops to force group
14953 termination. */
14954 if (can_issue_more
14955 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
14956 && !insn_terminates_group_p (insn, current_group)
14957 && !insn_terminates_group_p (next_insn, previous_group))
14958 {
14959 if (!is_branch_slot_insn(next_insn))
14960 can_issue_more--;
14961
14962 while (can_issue_more)
14963 {
14964 nop = gen_nop ();
14965 emit_insn_before (nop, next_insn);
14966 can_issue_more--;
14967 }
14968 }
14969
14970 can_issue_more = issue_rate;
14971 group_count++;
14972 }
14973
14974 insn = next_insn;
14975 next_insn = get_next_active_insn (insn, tail);
14976 }
14977
14978 return group_count;
14979}
14980
14981/* The following function is called at the end of scheduling BB.
14982 After reload, it inserts nops at insn group bundling. */
14983
14984static void
38f391a5 14985rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
14986{
14987 int n_groups;
14988
14989 if (sched_verbose)
14990 fprintf (dump, "=== Finishing schedule.\n");
14991
ec507f2d 14992 if (reload_completed && rs6000_sched_groups)
cbe26ab8
DN
14993 {
14994 if (rs6000_sched_insert_nops == sched_finish_none)
14995 return;
14996
14997 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
14998 n_groups = pad_groups (dump, sched_verbose,
14999 current_sched_info->prev_head,
15000 current_sched_info->next_tail);
15001 else
15002 n_groups = redefine_groups (dump, sched_verbose,
15003 current_sched_info->prev_head,
15004 current_sched_info->next_tail);
15005
15006 if (sched_verbose >= 6)
15007 {
15008 fprintf (dump, "ngroups = %d\n", n_groups);
15009 print_rtl (dump, current_sched_info->prev_head);
15010 fprintf (dump, "Done finish_sched\n");
15011 }
15012 }
15013}
b6c9286a 15014\f
b6c9286a
MM
15015/* Length in units of the trampoline for entering a nested function. */
15016
15017int
863d938c 15018rs6000_trampoline_size (void)
b6c9286a
MM
15019{
15020 int ret = 0;
15021
15022 switch (DEFAULT_ABI)
15023 {
15024 default:
15025 abort ();
15026
15027 case ABI_AIX:
8f802bfb 15028 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
15029 break;
15030
4dabc42d 15031 case ABI_DARWIN:
b6c9286a 15032 case ABI_V4:
03a7e1a5 15033 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 15034 break;
b6c9286a
MM
15035 }
15036
15037 return ret;
15038}
15039
15040/* Emit RTL insns to initialize the variable parts of a trampoline.
15041 FNADDR is an RTX for the address of the function's pure code.
15042 CXT is an RTX for the static chain value for the function. */
15043
15044void
a2369ed3 15045rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 15046{
ac2a93a1 15047 enum machine_mode pmode = Pmode;
8bd04c56
MM
15048 int regsize = (TARGET_32BIT) ? 4 : 8;
15049 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
15050
15051 switch (DEFAULT_ABI)
15052 {
15053 default:
15054 abort ();
15055
8bd04c56 15056/* Macros to shorten the code expansions below. */
39403d82 15057#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
15058#define MEM_PLUS(addr,offset) \
15059 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 15060
b6c9286a
MM
15061 /* Under AIX, just build the 3 word function descriptor */
15062 case ABI_AIX:
8bd04c56
MM
15063 {
15064 rtx fn_reg = gen_reg_rtx (pmode);
15065 rtx toc_reg = gen_reg_rtx (pmode);
15066 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 15067 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
15068 emit_move_insn (MEM_DEREF (addr), fn_reg);
15069 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
15070 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
15071 }
b6c9286a
MM
15072 break;
15073
4dabc42d
TC
15074 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
15075 case ABI_DARWIN:
b6c9286a 15076 case ABI_V4:
39403d82 15077 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
15078 FALSE, VOIDmode, 4,
15079 addr, pmode,
15080 GEN_INT (rs6000_trampoline_size ()), SImode,
15081 fnaddr, pmode,
15082 ctx_reg, pmode);
b6c9286a 15083 break;
b6c9286a
MM
15084 }
15085
15086 return;
15087}
7509c759
MM
15088
15089\f
91d231cb 15090/* Table of valid machine attributes. */
a4f6c312 15091
91d231cb 15092const struct attribute_spec rs6000_attribute_table[] =
7509c759 15093{
91d231cb 15094 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 15095 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
15096 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
15097 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
15098 { NULL, 0, 0, false, false, false, NULL }
91d231cb 15099};
7509c759 15100
8bb418a3
ZL
15101/* Handle the "altivec" attribute. The attribute may have
15102 arguments as follows:
15103
15104 __attribute__((altivec(vector__)))
15105 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
15106 __attribute__((altivec(bool__))) (always followed by 'unsigned')
15107
15108 and may appear more than once (e.g., 'vector bool char') in a
15109 given declaration. */
15110
15111static tree
15112rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
15113 int flags ATTRIBUTE_UNUSED,
15114 bool *no_add_attrs)
15115{
15116 tree type = *node, result = NULL_TREE;
15117 enum machine_mode mode;
15118 int unsigned_p;
15119 char altivec_type
15120 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
15121 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
15122 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
15123 : '?');
15124
15125 while (POINTER_TYPE_P (type)
15126 || TREE_CODE (type) == FUNCTION_TYPE
15127 || TREE_CODE (type) == METHOD_TYPE
15128 || TREE_CODE (type) == ARRAY_TYPE)
15129 type = TREE_TYPE (type);
15130
15131 mode = TYPE_MODE (type);
15132
15133 if (rs6000_warn_altivec_long
15134 && (type == long_unsigned_type_node || type == long_integer_type_node))
15135 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
15136
15137 switch (altivec_type)
15138 {
15139 case 'v':
8df83eae 15140 unsigned_p = TYPE_UNSIGNED (type);
8bb418a3
ZL
15141 switch (mode)
15142 {
15143 case SImode:
15144 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
15145 break;
15146 case HImode:
15147 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
15148 break;
15149 case QImode:
15150 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
15151 break;
15152 case SFmode: result = V4SF_type_node; break;
15153 /* If the user says 'vector int bool', we may be handed the 'bool'
15154 attribute _before_ the 'vector' attribute, and so select the proper
15155 type in the 'b' case below. */
15156 case V4SImode: case V8HImode: case V16QImode: result = type;
15157 default: break;
15158 }
15159 break;
15160 case 'b':
15161 switch (mode)
15162 {
15163 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
15164 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
15165 case QImode: case V16QImode: result = bool_V16QI_type_node;
15166 default: break;
15167 }
15168 break;
15169 case 'p':
15170 switch (mode)
15171 {
15172 case V8HImode: result = pixel_V8HI_type_node;
15173 default: break;
15174 }
15175 default: break;
15176 }
15177
15178 *no_add_attrs = true; /* No need to hang on to the attribute. */
15179
15180 if (!result)
15181 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
15182 else
15183 *node = reconstruct_complex_type (*node, result);
15184
15185 return NULL_TREE;
15186}
15187
f18eca82
ZL
15188/* AltiVec defines four built-in scalar types that serve as vector
15189 elements; we must teach the compiler how to mangle them. */
15190
15191static const char *
15192rs6000_mangle_fundamental_type (tree type)
15193{
15194 if (type == bool_char_type_node) return "U6__boolc";
15195 if (type == bool_short_type_node) return "U6__bools";
15196 if (type == pixel_type_node) return "u7__pixel";
15197 if (type == bool_int_type_node) return "U6__booli";
15198
15199 /* For all other types, use normal C++ mangling. */
15200 return NULL;
15201}
15202
a5c76ee6
ZW
15203/* Handle a "longcall" or "shortcall" attribute; arguments as in
15204 struct attribute_spec.handler. */
a4f6c312 15205
91d231cb 15206static tree
a2369ed3
DJ
15207rs6000_handle_longcall_attribute (tree *node, tree name,
15208 tree args ATTRIBUTE_UNUSED,
15209 int flags ATTRIBUTE_UNUSED,
15210 bool *no_add_attrs)
91d231cb
JM
15211{
15212 if (TREE_CODE (*node) != FUNCTION_TYPE
15213 && TREE_CODE (*node) != FIELD_DECL
15214 && TREE_CODE (*node) != TYPE_DECL)
15215 {
15216 warning ("`%s' attribute only applies to functions",
15217 IDENTIFIER_POINTER (name));
15218 *no_add_attrs = true;
15219 }
6a4cee5f 15220
91d231cb 15221 return NULL_TREE;
7509c759
MM
15222}
15223
a5c76ee6
ZW
15224/* Set longcall attributes on all functions declared when
15225 rs6000_default_long_calls is true. */
15226static void
a2369ed3 15227rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
15228{
15229 if (rs6000_default_long_calls
15230 && (TREE_CODE (type) == FUNCTION_TYPE
15231 || TREE_CODE (type) == METHOD_TYPE))
15232 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
15233 NULL_TREE,
15234 TYPE_ATTRIBUTES (type));
15235}
15236
3cb999d8
DE
15237/* Return a reference suitable for calling a function with the
15238 longcall attribute. */
a4f6c312 15239
6a4cee5f 15240struct rtx_def *
a2369ed3 15241rs6000_longcall_ref (rtx call_ref)
6a4cee5f 15242{
d330fd93 15243 const char *call_name;
6a4cee5f
MM
15244 tree node;
15245
15246 if (GET_CODE (call_ref) != SYMBOL_REF)
15247 return call_ref;
15248
15249 /* System V adds '.' to the internal name, so skip them. */
15250 call_name = XSTR (call_ref, 0);
15251 if (*call_name == '.')
15252 {
15253 while (*call_name == '.')
15254 call_name++;
15255
15256 node = get_identifier (call_name);
39403d82 15257 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
15258 }
15259
15260 return force_reg (Pmode, call_ref);
15261}
7509c759 15262\f
b64a1b53
RH
15263#ifdef USING_ELFOS_H
15264
7509c759
MM
15265/* A C statement or statements to switch to the appropriate section
15266 for output of RTX in mode MODE. You can assume that RTX is some
15267 kind of constant in RTL. The argument MODE is redundant except in
15268 the case of a `const_int' rtx. Select the section by calling
15269 `text_section' or one of the alternatives for other sections.
15270
15271 Do not define this macro if you put all constants in the read-only
15272 data section. */
15273
b64a1b53 15274static void
a2369ed3
DJ
15275rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
15276 unsigned HOST_WIDE_INT align)
7509c759 15277{
a9098fd0 15278 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 15279 toc_section ();
7509c759 15280 else
b64a1b53 15281 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
15282}
15283
15284/* A C statement or statements to switch to the appropriate
15285 section for output of DECL. DECL is either a `VAR_DECL' node
15286 or a constant of some sort. RELOC indicates whether forming
15287 the initial value of DECL requires link-time relocations. */
15288
ae46c4e0 15289static void
a2369ed3
DJ
15290rs6000_elf_select_section (tree decl, int reloc,
15291 unsigned HOST_WIDE_INT align)
7509c759 15292{
f1384257
AM
15293 /* Pretend that we're always building for a shared library when
15294 ABI_AIX, because otherwise we end up with dynamic relocations
15295 in read-only sections. This happens for function pointers,
15296 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
15297 default_elf_select_section_1 (decl, reloc, align,
15298 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
15299}
15300
15301/* A C statement to build up a unique section name, expressed as a
15302 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
15303 RELOC indicates whether the initial value of EXP requires
15304 link-time relocations. If you do not define this macro, GCC will use
15305 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 15306 macro can now be called for uninitialized data items as well as
4912a07c 15307 initialized data and functions. */
63019373 15308
ae46c4e0 15309static void
a2369ed3 15310rs6000_elf_unique_section (tree decl, int reloc)
63019373 15311{
f1384257
AM
15312 /* As above, pretend that we're always building for a shared library
15313 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
15314 default_unique_section_1 (decl, reloc,
15315 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 15316}
d9407988 15317\f
d1908feb
JJ
15318/* For a SYMBOL_REF, set generic flags and then perform some
15319 target-specific processing.
15320
d1908feb
JJ
15321 When the AIX ABI is requested on a non-AIX system, replace the
15322 function name with the real name (with a leading .) rather than the
15323 function descriptor name. This saves a lot of overriding code to
15324 read the prefixes. */
d9407988 15325
fb49053f 15326static void
a2369ed3 15327rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 15328{
d1908feb 15329 default_encode_section_info (decl, rtl, first);
b2003250 15330
d1908feb
JJ
15331 if (first
15332 && TREE_CODE (decl) == FUNCTION_DECL
15333 && !TARGET_AIX
15334 && DEFAULT_ABI == ABI_AIX)
d9407988 15335 {
c6a2438a 15336 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
15337 size_t len = strlen (XSTR (sym_ref, 0));
15338 char *str = alloca (len + 2);
15339 str[0] = '.';
15340 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
15341 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 15342 }
d9407988
MM
15343}
15344
0e5dbd9b 15345static bool
a2369ed3 15346rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
15347{
15348 if (rs6000_sdata == SDATA_NONE)
15349 return false;
15350
15351 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
15352 {
15353 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
15354 if (strcmp (section, ".sdata") == 0
15355 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
15356 || strcmp (section, ".sbss") == 0
15357 || strcmp (section, ".sbss2") == 0
15358 || strcmp (section, ".PPC.EMB.sdata0") == 0
15359 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
15360 return true;
15361 }
15362 else
15363 {
15364 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
15365
15366 if (size > 0
307b599c 15367 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
15368 /* If it's not public, and we're not going to reference it there,
15369 there's no need to put it in the small data section. */
0e5dbd9b
DE
15370 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
15371 return true;
15372 }
15373
15374 return false;
15375}
15376
b91da81f 15377#endif /* USING_ELFOS_H */
000034eb 15378
a6c2a102 15379\f
000034eb 15380/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
15381 ADDR can be effectively incremented by incrementing REG.
15382
15383 r0 is special and we must not select it as an address
15384 register by this routine since our caller will try to
15385 increment the returned register via an "la" instruction. */
000034eb
DE
15386
15387struct rtx_def *
a2369ed3 15388find_addr_reg (rtx addr)
000034eb
DE
15389{
15390 while (GET_CODE (addr) == PLUS)
15391 {
02441cd6
JL
15392 if (GET_CODE (XEXP (addr, 0)) == REG
15393 && REGNO (XEXP (addr, 0)) != 0)
000034eb 15394 addr = XEXP (addr, 0);
02441cd6
JL
15395 else if (GET_CODE (XEXP (addr, 1)) == REG
15396 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
15397 addr = XEXP (addr, 1);
15398 else if (CONSTANT_P (XEXP (addr, 0)))
15399 addr = XEXP (addr, 1);
15400 else if (CONSTANT_P (XEXP (addr, 1)))
15401 addr = XEXP (addr, 0);
15402 else
15403 abort ();
15404 }
02441cd6 15405 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
15406 return addr;
15407 abort ();
15408}
15409
a6c2a102 15410void
a2369ed3 15411rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
15412{
15413 fatal_insn ("bad address", op);
15414}
c8023011 15415
ee890fe2
SS
15416#if TARGET_MACHO
15417
15418#if 0
15419/* Returns 1 if OP is either a symbol reference or a sum of a symbol
15420 reference and a constant. */
15421
15422int
a2369ed3 15423symbolic_operand (rtx op)
ee890fe2
SS
15424{
15425 switch (GET_CODE (op))
15426 {
15427 case SYMBOL_REF:
15428 case LABEL_REF:
15429 return 1;
15430 case CONST:
15431 op = XEXP (op, 0);
15432 return (GET_CODE (op) == SYMBOL_REF ||
15433 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
15434 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
15435 && GET_CODE (XEXP (op, 1)) == CONST_INT);
15436 default:
15437 return 0;
15438 }
c8023011 15439}
ee890fe2
SS
15440#endif
15441
efdba735 15442#if TARGET_MACHO
ee890fe2 15443
efdba735 15444static tree branch_island_list = 0;
ee890fe2 15445
efdba735
SH
15446/* Remember to generate a branch island for far calls to the given
15447 function. */
ee890fe2 15448
efdba735
SH
15449static void
15450add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 15451{
efdba735
SH
15452 tree branch_island = build_tree_list (function_name, label_name);
15453 TREE_TYPE (branch_island) = build_int_2 (line_number, 0);
15454 TREE_CHAIN (branch_island) = branch_island_list;
15455 branch_island_list = branch_island;
ee890fe2
SS
15456}
15457
efdba735
SH
15458#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
15459#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
15460#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
15461 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 15462
efdba735
SH
15463/* Generate far-jump branch islands for everything on the
15464 branch_island_list. Invoked immediately after the last instruction
15465 of the epilogue has been emitted; the branch-islands must be
15466 appended to, and contiguous with, the function body. Mach-O stubs
15467 are generated in machopic_output_stub(). */
ee890fe2 15468
efdba735
SH
15469static void
15470macho_branch_islands (void)
15471{
15472 char tmp_buf[512];
15473 tree branch_island;
15474
15475 for (branch_island = branch_island_list;
15476 branch_island;
15477 branch_island = TREE_CHAIN (branch_island))
15478 {
15479 const char *label =
15480 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
15481 const char *name =
15482 darwin_strip_name_encoding (
15483 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)));
15484 char name_buf[512];
15485 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
15486 if (name[0] == '*' || name[0] == '&')
15487 strcpy (name_buf, name+1);
15488 else
15489 {
15490 name_buf[0] = '_';
15491 strcpy (name_buf+1, name);
15492 }
15493 strcpy (tmp_buf, "\n");
15494 strcat (tmp_buf, label);
ee890fe2 15495#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15496 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15497 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15498 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 15499#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
15500 if (flag_pic)
15501 {
15502 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
15503 strcat (tmp_buf, label);
15504 strcat (tmp_buf, "_pic\n");
15505 strcat (tmp_buf, label);
15506 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
15507
15508 strcat (tmp_buf, "\taddis r11,r11,ha16(");
15509 strcat (tmp_buf, name_buf);
15510 strcat (tmp_buf, " - ");
15511 strcat (tmp_buf, label);
15512 strcat (tmp_buf, "_pic)\n");
15513
15514 strcat (tmp_buf, "\tmtlr r0\n");
15515
15516 strcat (tmp_buf, "\taddi r12,r11,lo16(");
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, "\tmtctr r12\n\tbctr\n");
15523 }
15524 else
15525 {
15526 strcat (tmp_buf, ":\nlis r12,hi16(");
15527 strcat (tmp_buf, name_buf);
15528 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
15529 strcat (tmp_buf, name_buf);
15530 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
15531 }
15532 output_asm_insn (tmp_buf, 0);
ee890fe2 15533#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15534 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15535 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15536 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 15537#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 15538 }
ee890fe2 15539
efdba735 15540 branch_island_list = 0;
ee890fe2
SS
15541}
15542
15543/* NO_PREVIOUS_DEF checks in the link list whether the function name is
15544 already there or not. */
15545
efdba735 15546static int
a2369ed3 15547no_previous_def (tree function_name)
ee890fe2 15548{
efdba735
SH
15549 tree branch_island;
15550 for (branch_island = branch_island_list;
15551 branch_island;
15552 branch_island = TREE_CHAIN (branch_island))
15553 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
15554 return 0;
15555 return 1;
15556}
15557
15558/* GET_PREV_LABEL gets the label name from the previous definition of
15559 the function. */
15560
efdba735 15561static tree
a2369ed3 15562get_prev_label (tree function_name)
ee890fe2 15563{
efdba735
SH
15564 tree branch_island;
15565 for (branch_island = branch_island_list;
15566 branch_island;
15567 branch_island = TREE_CHAIN (branch_island))
15568 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
15569 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
15570 return 0;
15571}
15572
15573/* INSN is either a function call or a millicode call. It may have an
15574 unconditional jump in its delay slot.
15575
15576 CALL_DEST is the routine we are calling. */
15577
15578char *
efdba735 15579output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
15580{
15581 static char buf[256];
efdba735
SH
15582 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
15583 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
15584 {
15585 tree labelname;
efdba735 15586 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
ee890fe2
SS
15587
15588 if (no_previous_def (funname))
15589 {
308c142a 15590 int line_number = 0;
ee890fe2
SS
15591 rtx label_rtx = gen_label_rtx ();
15592 char *label_buf, temp_buf[256];
15593 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
15594 CODE_LABEL_NUMBER (label_rtx));
15595 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
15596 labelname = get_identifier (label_buf);
15597 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
15598 if (insn)
15599 line_number = NOTE_LINE_NUMBER (insn);
efdba735 15600 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
15601 }
15602 else
15603 labelname = get_prev_label (funname);
15604
efdba735
SH
15605 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
15606 instruction will reach 'foo', otherwise link as 'bl L42'".
15607 "L42" should be a 'branch island', that will do a far jump to
15608 'foo'. Branch islands are generated in
15609 macho_branch_islands(). */
ee890fe2 15610 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 15611 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
15612 }
15613 else
efdba735
SH
15614 sprintf (buf, "bl %%z%d", dest_operand_number);
15615 return buf;
ee890fe2
SS
15616}
15617
efdba735 15618#endif /* TARGET_MACHO */
ee890fe2 15619
ee890fe2
SS
15620/* Generate PIC and indirect symbol stubs. */
15621
15622void
a2369ed3 15623machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
15624{
15625 unsigned int length;
a4f6c312
SS
15626 char *symbol_name, *lazy_ptr_name;
15627 char *local_label_0;
ee890fe2
SS
15628 static int label = 0;
15629
df56a27f 15630 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 15631 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 15632
ee890fe2 15633
ee890fe2
SS
15634 length = strlen (symb);
15635 symbol_name = alloca (length + 32);
15636 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
15637
15638 lazy_ptr_name = alloca (length + 32);
15639 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
15640
ee890fe2 15641 if (flag_pic == 2)
d3c300d2 15642 machopic_picsymbol_stub1_section ();
ee890fe2 15643 else
d3c300d2
DJ
15644 machopic_symbol_stub1_section ();
15645 fprintf (file, "\t.align 2\n");
ee890fe2
SS
15646
15647 fprintf (file, "%s:\n", stub);
15648 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15649
15650 if (flag_pic == 2)
15651 {
876455fa
AP
15652 label++;
15653 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
15654 sprintf (local_label_0, "\"L%011d$spb\"", label);
15655
ee890fe2
SS
15656 fprintf (file, "\tmflr r0\n");
15657 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
15658 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
15659 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
15660 lazy_ptr_name, local_label_0);
15661 fprintf (file, "\tmtlr r0\n");
d3c300d2 15662 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
15663 lazy_ptr_name, local_label_0);
15664 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
15665 fprintf (file, "\tbctr\n");
15666 }
15667 else
ab82a49f
AP
15668 {
15669 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
15670 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
15671 fprintf (file, "\tmtctr r12\n");
15672 fprintf (file, "\tbctr\n");
15673 }
ee890fe2
SS
15674
15675 machopic_lazy_symbol_ptr_section ();
15676 fprintf (file, "%s:\n", lazy_ptr_name);
15677 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15678 fprintf (file, "\t.long dyld_stub_binding_helper\n");
15679}
15680
15681/* Legitimize PIC addresses. If the address is already
15682 position-independent, we return ORIG. Newly generated
15683 position-independent addresses go into a reg. This is REG if non
15684 zero, otherwise we allocate register(s) as necessary. */
15685
c859cda6 15686#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
15687
15688rtx
a2369ed3
DJ
15689rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
15690 rtx reg)
ee890fe2
SS
15691{
15692 rtx base, offset;
15693
15694 if (reg == NULL && ! reload_in_progress && ! reload_completed)
15695 reg = gen_reg_rtx (Pmode);
15696
15697 if (GET_CODE (orig) == CONST)
15698 {
15699 if (GET_CODE (XEXP (orig, 0)) == PLUS
15700 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
15701 return orig;
15702
15703 if (GET_CODE (XEXP (orig, 0)) == PLUS)
15704 {
2cf520bf 15705 /* Use a different reg for the intermediate value, as
a3c9585f 15706 it will be marked UNCHANGING. */
2cf520bf
GK
15707 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
15708
a4f6c312
SS
15709 base =
15710 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 15711 Pmode, reg_temp);
a4f6c312
SS
15712 offset =
15713 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
15714 Pmode, reg);
ee890fe2
SS
15715 }
15716 else
15717 abort ();
15718
15719 if (GET_CODE (offset) == CONST_INT)
15720 {
15721 if (SMALL_INT (offset))
ed8908e7 15722 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
15723 else if (! reload_in_progress && ! reload_completed)
15724 offset = force_reg (Pmode, offset);
15725 else
c859cda6
DJ
15726 {
15727 rtx mem = force_const_mem (Pmode, orig);
15728 return machopic_legitimize_pic_address (mem, Pmode, reg);
15729 }
ee890fe2 15730 }
f1c25d3b 15731 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
15732 }
15733
15734 /* Fall back on generic machopic code. */
15735 return machopic_legitimize_pic_address (orig, mode, reg);
15736}
15737
15738/* This is just a placeholder to make linking work without having to
15739 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
15740 ever needed for Darwin (not too likely!) this would have to get a
15741 real definition. */
15742
15743void
863d938c 15744toc_section (void)
ee890fe2
SS
15745{
15746}
15747
15748#endif /* TARGET_MACHO */
7c262518
RH
15749
15750#if TARGET_ELF
15751static unsigned int
a2369ed3 15752rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 15753{
1ff8f81a
AM
15754 return default_section_type_flags_1 (decl, name, reloc,
15755 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 15756}
d9f6800d
RH
15757
15758/* Record an element in the table of global constructors. SYMBOL is
15759 a SYMBOL_REF of the function to be called; PRIORITY is a number
15760 between 0 and MAX_INIT_PRIORITY.
15761
15762 This differs from default_named_section_asm_out_constructor in
15763 that we have special handling for -mrelocatable. */
15764
15765static void
a2369ed3 15766rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
15767{
15768 const char *section = ".ctors";
15769 char buf[16];
15770
15771 if (priority != DEFAULT_INIT_PRIORITY)
15772 {
15773 sprintf (buf, ".ctors.%.5u",
15774 /* Invert the numbering so the linker puts us in the proper
15775 order; constructors are run from right to left, and the
15776 linker sorts in increasing order. */
15777 MAX_INIT_PRIORITY - priority);
15778 section = buf;
15779 }
15780
715bdd29
RH
15781 named_section_flags (section, SECTION_WRITE);
15782 assemble_align (POINTER_SIZE);
d9f6800d
RH
15783
15784 if (TARGET_RELOCATABLE)
15785 {
15786 fputs ("\t.long (", asm_out_file);
15787 output_addr_const (asm_out_file, symbol);
15788 fputs (")@fixup\n", asm_out_file);
15789 }
15790 else
c8af3574 15791 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
15792}
15793
15794static void
a2369ed3 15795rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
15796{
15797 const char *section = ".dtors";
15798 char buf[16];
15799
15800 if (priority != DEFAULT_INIT_PRIORITY)
15801 {
15802 sprintf (buf, ".dtors.%.5u",
15803 /* Invert the numbering so the linker puts us in the proper
15804 order; constructors are run from right to left, and the
15805 linker sorts in increasing order. */
15806 MAX_INIT_PRIORITY - priority);
15807 section = buf;
15808 }
15809
715bdd29
RH
15810 named_section_flags (section, SECTION_WRITE);
15811 assemble_align (POINTER_SIZE);
d9f6800d
RH
15812
15813 if (TARGET_RELOCATABLE)
15814 {
15815 fputs ("\t.long (", asm_out_file);
15816 output_addr_const (asm_out_file, symbol);
15817 fputs (")@fixup\n", asm_out_file);
15818 }
15819 else
c8af3574 15820 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 15821}
9739c90c
JJ
15822
15823void
a2369ed3 15824rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
15825{
15826 if (TARGET_64BIT)
15827 {
15828 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
15829 ASM_OUTPUT_LABEL (file, name);
15830 fputs (DOUBLE_INT_ASM_OP, file);
15831 putc ('.', file);
15832 assemble_name (file, name);
15833 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
15834 assemble_name (file, name);
15835 fputs (",24\n\t.type\t.", file);
15836 assemble_name (file, name);
15837 fputs (",@function\n", file);
15838 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
15839 {
15840 fputs ("\t.globl\t.", file);
15841 assemble_name (file, name);
15842 putc ('\n', file);
15843 }
15844 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15845 putc ('.', file);
15846 ASM_OUTPUT_LABEL (file, name);
15847 return;
15848 }
15849
15850 if (TARGET_RELOCATABLE
15851 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 15852 && uses_TOC ())
9739c90c
JJ
15853 {
15854 char buf[256];
15855
15856 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
15857
15858 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
15859 fprintf (file, "\t.long ");
15860 assemble_name (file, buf);
15861 putc ('-', file);
15862 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
15863 assemble_name (file, buf);
15864 putc ('\n', file);
15865 }
15866
15867 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
15868 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15869
15870 if (DEFAULT_ABI == ABI_AIX)
15871 {
15872 const char *desc_name, *orig_name;
15873
15874 orig_name = (*targetm.strip_name_encoding) (name);
15875 desc_name = orig_name;
15876 while (*desc_name == '.')
15877 desc_name++;
15878
15879 if (TREE_PUBLIC (decl))
15880 fprintf (file, "\t.globl %s\n", desc_name);
15881
15882 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
15883 fprintf (file, "%s:\n", desc_name);
15884 fprintf (file, "\t.long %s\n", orig_name);
15885 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
15886 if (DEFAULT_ABI == ABI_AIX)
15887 fputs ("\t.long 0\n", file);
15888 fprintf (file, "\t.previous\n");
15889 }
15890 ASM_OUTPUT_LABEL (file, name);
15891}
7c262518
RH
15892#endif
15893
cbaaba19 15894#if TARGET_XCOFF
7c262518 15895static void
a2369ed3 15896rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
15897{
15898 fputs (GLOBAL_ASM_OP, stream);
15899 RS6000_OUTPUT_BASENAME (stream, name);
15900 putc ('\n', stream);
15901}
15902
15903static void
a2369ed3 15904rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 15905{
0e5dbd9b
DE
15906 int smclass;
15907 static const char * const suffix[3] = { "PR", "RO", "RW" };
15908
15909 if (flags & SECTION_CODE)
15910 smclass = 0;
15911 else if (flags & SECTION_WRITE)
15912 smclass = 2;
15913 else
15914 smclass = 1;
15915
5b5198f7 15916 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 15917 (flags & SECTION_CODE) ? "." : "",
5b5198f7 15918 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 15919}
ae46c4e0
RH
15920
15921static void
a2369ed3
DJ
15922rs6000_xcoff_select_section (tree decl, int reloc,
15923 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 15924{
5add3202 15925 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 15926 {
0e5dbd9b 15927 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15928 read_only_data_section ();
15929 else
15930 read_only_private_data_section ();
15931 }
15932 else
15933 {
0e5dbd9b 15934 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15935 data_section ();
15936 else
15937 private_data_section ();
15938 }
15939}
15940
15941static void
a2369ed3 15942rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
15943{
15944 const char *name;
ae46c4e0 15945
5b5198f7
DE
15946 /* Use select_section for private and uninitialized data. */
15947 if (!TREE_PUBLIC (decl)
15948 || DECL_COMMON (decl)
0e5dbd9b
DE
15949 || DECL_INITIAL (decl) == NULL_TREE
15950 || DECL_INITIAL (decl) == error_mark_node
15951 || (flag_zero_initialized_in_bss
15952 && initializer_zerop (DECL_INITIAL (decl))))
15953 return;
15954
15955 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15956 name = (*targetm.strip_name_encoding) (name);
15957 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 15958}
b64a1b53 15959
fb49053f
RH
15960/* Select section for constant in constant pool.
15961
15962 On RS/6000, all constants are in the private read-only data area.
15963 However, if this is being placed in the TOC it must be output as a
15964 toc entry. */
15965
b64a1b53 15966static void
a2369ed3
DJ
15967rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
15968 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
15969{
15970 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
15971 toc_section ();
15972 else
15973 read_only_private_data_section ();
15974}
772c5265
RH
15975
15976/* Remove any trailing [DS] or the like from the symbol name. */
15977
15978static const char *
a2369ed3 15979rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
15980{
15981 size_t len;
15982 if (*name == '*')
15983 name++;
15984 len = strlen (name);
15985 if (name[len - 1] == ']')
15986 return ggc_alloc_string (name, len - 4);
15987 else
15988 return name;
15989}
15990
5add3202
DE
15991/* Section attributes. AIX is always PIC. */
15992
15993static unsigned int
a2369ed3 15994rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 15995{
5b5198f7
DE
15996 unsigned int align;
15997 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
15998
15999 /* Align to at least UNIT size. */
16000 if (flags & SECTION_CODE)
16001 align = MIN_UNITS_PER_WORD;
16002 else
16003 /* Increase alignment of large objects if not already stricter. */
16004 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
16005 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
16006 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
16007
16008 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 16009}
a5fe455b 16010
1bc7c5b6
ZW
16011/* Output at beginning of assembler file.
16012
16013 Initialize the section names for the RS/6000 at this point.
16014
16015 Specify filename, including full path, to assembler.
16016
16017 We want to go into the TOC section so at least one .toc will be emitted.
16018 Also, in order to output proper .bs/.es pairs, we need at least one static
16019 [RW] section emitted.
16020
16021 Finally, declare mcount when profiling to make the assembler happy. */
16022
16023static void
863d938c 16024rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
16025{
16026 rs6000_gen_section_name (&xcoff_bss_section_name,
16027 main_input_filename, ".bss_");
16028 rs6000_gen_section_name (&xcoff_private_data_section_name,
16029 main_input_filename, ".rw_");
16030 rs6000_gen_section_name (&xcoff_read_only_section_name,
16031 main_input_filename, ".ro_");
16032
16033 fputs ("\t.file\t", asm_out_file);
16034 output_quoted_string (asm_out_file, main_input_filename);
16035 fputc ('\n', asm_out_file);
16036 toc_section ();
16037 if (write_symbols != NO_DEBUG)
16038 private_data_section ();
16039 text_section ();
16040 if (profile_flag)
16041 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
16042 rs6000_file_start ();
16043}
16044
a5fe455b
ZW
16045/* Output at end of assembler file.
16046 On the RS/6000, referencing data should automatically pull in text. */
16047
16048static void
863d938c 16049rs6000_xcoff_file_end (void)
a5fe455b
ZW
16050{
16051 text_section ();
16052 fputs ("_section_.text:\n", asm_out_file);
16053 data_section ();
16054 fputs (TARGET_32BIT
16055 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
16056 asm_out_file);
16057}
f1384257 16058#endif /* TARGET_XCOFF */
0e5dbd9b 16059
f1384257
AM
16060#if TARGET_MACHO
16061/* Cross-module name binding. Darwin does not support overriding
7f3d8013 16062 functions at dynamic-link time. */
0e5dbd9b 16063
2bcc50d0 16064static bool
a2369ed3 16065rs6000_binds_local_p (tree decl)
0e5dbd9b 16066{
f1384257 16067 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 16068}
f1384257 16069#endif
34bb030a 16070
3c50106f
RH
16071/* Compute a (partial) cost for rtx X. Return true if the complete
16072 cost has been computed, and false if subexpressions should be
16073 scanned. In either case, *TOTAL contains the cost result. */
16074
16075static bool
a2369ed3
DJ
16076rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
16077 int *total)
3c50106f
RH
16078{
16079 switch (code)
16080 {
16081 /* On the RS/6000, if it is valid in the insn, it is free.
16082 So this always returns 0. */
16083 case CONST_INT:
16084 case CONST:
16085 case LABEL_REF:
16086 case SYMBOL_REF:
16087 case CONST_DOUBLE:
16088 case HIGH:
16089 *total = 0;
16090 return true;
16091
16092 case PLUS:
16093 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
16094 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
16095 + 0x8000) >= 0x10000)
16096 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
16097 ? COSTS_N_INSNS (2)
16098 : COSTS_N_INSNS (1));
16099 return true;
16100
16101 case AND:
16102 case IOR:
16103 case XOR:
16104 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
16105 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
16106 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
16107 ? COSTS_N_INSNS (2)
16108 : COSTS_N_INSNS (1));
16109 return true;
16110
16111 case MULT:
16112 if (optimize_size)
16113 {
16114 *total = COSTS_N_INSNS (2);
16115 return true;
16116 }
16117 switch (rs6000_cpu)
16118 {
16119 case PROCESSOR_RIOS1:
16120 case PROCESSOR_PPC405:
16121 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16122 ? COSTS_N_INSNS (5)
16123 : (INTVAL (XEXP (x, 1)) >= -256
16124 && INTVAL (XEXP (x, 1)) <= 255)
16125 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
16126 return true;
16127
02ca7595
DE
16128 case PROCESSOR_PPC440:
16129 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16130 ? COSTS_N_INSNS (3)
16131 : COSTS_N_INSNS (2));
16132 return true;
16133
3c50106f
RH
16134 case PROCESSOR_RS64A:
16135 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16136 ? GET_MODE (XEXP (x, 1)) != DImode
16137 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
16138 : (INTVAL (XEXP (x, 1)) >= -256
16139 && INTVAL (XEXP (x, 1)) <= 255)
16140 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
16141 return true;
16142
16143 case PROCESSOR_RIOS2:
16144 case PROCESSOR_MPCCORE:
16145 case PROCESSOR_PPC604e:
16146 *total = COSTS_N_INSNS (2);
16147 return true;
16148
16149 case PROCESSOR_PPC601:
16150 *total = COSTS_N_INSNS (5);
16151 return true;
16152
16153 case PROCESSOR_PPC603:
16154 case PROCESSOR_PPC7400:
16155 case PROCESSOR_PPC750:
16156 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16157 ? COSTS_N_INSNS (5)
16158 : (INTVAL (XEXP (x, 1)) >= -256
16159 && INTVAL (XEXP (x, 1)) <= 255)
16160 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
16161 return true;
16162
16163 case PROCESSOR_PPC7450:
16164 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16165 ? COSTS_N_INSNS (4)
16166 : COSTS_N_INSNS (3));
16167 return true;
16168
16169 case PROCESSOR_PPC403:
16170 case PROCESSOR_PPC604:
16171 case PROCESSOR_PPC8540:
16172 *total = COSTS_N_INSNS (4);
16173 return true;
16174
16175 case PROCESSOR_PPC620:
16176 case PROCESSOR_PPC630:
3c50106f
RH
16177 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16178 ? GET_MODE (XEXP (x, 1)) != DImode
16179 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
16180 : (INTVAL (XEXP (x, 1)) >= -256
16181 && INTVAL (XEXP (x, 1)) <= 255)
16182 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
16183 return true;
16184
9259f3b0 16185 case PROCESSOR_POWER4:
ec507f2d 16186 case PROCESSOR_POWER5:
9259f3b0
DE
16187 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
16188 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
16189 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
16190 : COSTS_N_INSNS (2));
9259f3b0
DE
16191 return true;
16192
3c50106f
RH
16193 default:
16194 abort ();
16195 }
16196
16197 case DIV:
16198 case MOD:
16199 if (GET_CODE (XEXP (x, 1)) == CONST_INT
16200 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
16201 {
16202 *total = COSTS_N_INSNS (2);
16203 return true;
16204 }
5efb1046 16205 /* FALLTHRU */
3c50106f
RH
16206
16207 case UDIV:
16208 case UMOD:
16209 switch (rs6000_cpu)
16210 {
16211 case PROCESSOR_RIOS1:
16212 *total = COSTS_N_INSNS (19);
16213 return true;
16214
16215 case PROCESSOR_RIOS2:
16216 *total = COSTS_N_INSNS (13);
16217 return true;
16218
16219 case PROCESSOR_RS64A:
16220 *total = (GET_MODE (XEXP (x, 1)) != DImode
16221 ? COSTS_N_INSNS (65)
16222 : COSTS_N_INSNS (67));
16223 return true;
16224
16225 case PROCESSOR_MPCCORE:
16226 *total = COSTS_N_INSNS (6);
16227 return true;
16228
16229 case PROCESSOR_PPC403:
16230 *total = COSTS_N_INSNS (33);
16231 return true;
16232
16233 case PROCESSOR_PPC405:
16234 *total = COSTS_N_INSNS (35);
16235 return true;
16236
02ca7595
DE
16237 case PROCESSOR_PPC440:
16238 *total = COSTS_N_INSNS (34);
16239 return true;
16240
3c50106f
RH
16241 case PROCESSOR_PPC601:
16242 *total = COSTS_N_INSNS (36);
16243 return true;
16244
16245 case PROCESSOR_PPC603:
16246 *total = COSTS_N_INSNS (37);
16247 return true;
16248
16249 case PROCESSOR_PPC604:
16250 case PROCESSOR_PPC604e:
16251 *total = COSTS_N_INSNS (20);
16252 return true;
16253
16254 case PROCESSOR_PPC620:
16255 case PROCESSOR_PPC630:
3c50106f
RH
16256 *total = (GET_MODE (XEXP (x, 1)) != DImode
16257 ? COSTS_N_INSNS (21)
16258 : COSTS_N_INSNS (37));
16259 return true;
16260
16261 case PROCESSOR_PPC750:
16262 case PROCESSOR_PPC8540:
16263 case PROCESSOR_PPC7400:
16264 *total = COSTS_N_INSNS (19);
16265 return true;
16266
16267 case PROCESSOR_PPC7450:
16268 *total = COSTS_N_INSNS (23);
16269 return true;
984e25ac
DE
16270
16271 case PROCESSOR_POWER4:
ec507f2d 16272 case PROCESSOR_POWER5:
984e25ac
DE
16273 *total = (GET_MODE (XEXP (x, 1)) != DImode
16274 ? COSTS_N_INSNS (18)
16275 : COSTS_N_INSNS (34));
16276 return true;
3c50106f
RH
16277
16278 default:
16279 abort ();
16280 }
16281
16282 case FFS:
16283 *total = COSTS_N_INSNS (4);
16284 return true;
16285
16286 case MEM:
a3c9585f 16287 /* MEM should be slightly more expensive than (plus (reg) (const)). */
3c50106f
RH
16288 *total = 5;
16289 return true;
16290
16291 default:
16292 return false;
16293 }
16294}
16295
34bb030a
DE
16296/* A C expression returning the cost of moving data from a register of class
16297 CLASS1 to one of CLASS2. */
16298
16299int
a2369ed3
DJ
16300rs6000_register_move_cost (enum machine_mode mode,
16301 enum reg_class from, enum reg_class to)
34bb030a
DE
16302{
16303 /* Moves from/to GENERAL_REGS. */
16304 if (reg_classes_intersect_p (to, GENERAL_REGS)
16305 || reg_classes_intersect_p (from, GENERAL_REGS))
16306 {
16307 if (! reg_classes_intersect_p (to, GENERAL_REGS))
16308 from = to;
16309
16310 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
16311 return (rs6000_memory_move_cost (mode, from, 0)
16312 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
16313
a3c9585f 16314/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
16315 else if (from == CR_REGS)
16316 return 4;
16317
16318 else
16319/* A move will cost one instruction per GPR moved. */
16320 return 2 * HARD_REGNO_NREGS (0, mode);
16321 }
16322
16323/* Moving between two similar registers is just one instruction. */
16324 else if (reg_classes_intersect_p (to, from))
16325 return mode == TFmode ? 4 : 2;
16326
16327/* Everything else has to go through GENERAL_REGS. */
16328 else
16329 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
16330 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
16331}
16332
16333/* A C expressions returning the cost of moving data of MODE from a register to
16334 or from memory. */
16335
16336int
a2369ed3
DJ
16337rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
16338 int in ATTRIBUTE_UNUSED)
34bb030a
DE
16339{
16340 if (reg_classes_intersect_p (class, GENERAL_REGS))
16341 return 4 * HARD_REGNO_NREGS (0, mode);
16342 else if (reg_classes_intersect_p (class, FLOAT_REGS))
16343 return 4 * HARD_REGNO_NREGS (32, mode);
16344 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
16345 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
16346 else
16347 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
16348}
16349
ded9bf77
AH
16350/* Return an RTX representing where to find the function value of a
16351 function returning MODE. */
16352static rtx
16353rs6000_complex_function_value (enum machine_mode mode)
16354{
16355 unsigned int regno;
16356 rtx r1, r2;
16357 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 16358 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77 16359
4ed78545 16360 if (FLOAT_MODE_P (mode) && TARGET_HARD_FLOAT && TARGET_FPRS)
ded9bf77
AH
16361 regno = FP_ARG_RETURN;
16362 else
16363 {
16364 regno = GP_ARG_RETURN;
16365
16366 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 16367 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
16368 return gen_rtx_REG (mode, regno);
16369 }
16370
fb7e4164
AM
16371 if (inner_bytes >= 8)
16372 return gen_rtx_REG (mode, regno);
16373
ded9bf77
AH
16374 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
16375 const0_rtx);
16376 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 16377 GEN_INT (inner_bytes));
ded9bf77
AH
16378 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
16379}
16380
a6ebc39a
AH
16381/* Define how to find the value returned by a function.
16382 VALTYPE is the data type of the value (as a tree).
16383 If the precise function being called is known, FUNC is its FUNCTION_DECL;
16384 otherwise, FUNC is 0.
16385
16386 On the SPE, both FPs and vectors are returned in r3.
16387
16388 On RS/6000 an integer value is in r3 and a floating-point value is in
16389 fp1, unless -msoft-float. */
16390
16391rtx
16392rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
16393{
16394 enum machine_mode mode;
2a8fa26c 16395 unsigned int regno;
a6ebc39a 16396
0e67400a
FJ
16397 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
16398 {
16399 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
16400 return gen_rtx_PARALLEL (DImode,
16401 gen_rtvec (2,
16402 gen_rtx_EXPR_LIST (VOIDmode,
16403 gen_rtx_REG (SImode, GP_ARG_RETURN),
16404 const0_rtx),
16405 gen_rtx_EXPR_LIST (VOIDmode,
16406 gen_rtx_REG (SImode,
16407 GP_ARG_RETURN + 1),
16408 GEN_INT (4))));
16409 }
16410
a6ebc39a
AH
16411 if ((INTEGRAL_TYPE_P (valtype)
16412 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
16413 || POINTER_TYPE_P (valtype))
b78d48dd 16414 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
16415 else
16416 mode = TYPE_MODE (valtype);
16417
4ed78545 16418 if (SCALAR_FLOAT_TYPE_P (valtype) && TARGET_HARD_FLOAT && TARGET_FPRS)
2a8fa26c 16419 regno = FP_ARG_RETURN;
ded9bf77 16420 else if (TREE_CODE (valtype) == COMPLEX_TYPE
42ba5130 16421 && targetm.calls.split_complex_arg)
ded9bf77 16422 return rs6000_complex_function_value (mode);
44688022
AM
16423 else if (TREE_CODE (valtype) == VECTOR_TYPE
16424 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
a6ebc39a
AH
16425 regno = ALTIVEC_ARG_RETURN;
16426 else
16427 regno = GP_ARG_RETURN;
16428
16429 return gen_rtx_REG (mode, regno);
16430}
16431
ded9bf77
AH
16432/* Define how to find the value returned by a library function
16433 assuming the value has mode MODE. */
16434rtx
16435rs6000_libcall_value (enum machine_mode mode)
16436{
16437 unsigned int regno;
16438
16439 if (GET_MODE_CLASS (mode) == MODE_FLOAT
16440 && TARGET_HARD_FLOAT && TARGET_FPRS)
16441 regno = FP_ARG_RETURN;
44688022
AM
16442 else if (ALTIVEC_VECTOR_MODE (mode)
16443 && TARGET_ALTIVEC && TARGET_ALTIVEC_ABI)
ded9bf77 16444 regno = ALTIVEC_ARG_RETURN;
42ba5130 16445 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
16446 return rs6000_complex_function_value (mode);
16447 else
16448 regno = GP_ARG_RETURN;
16449
16450 return gen_rtx_REG (mode, regno);
16451}
16452
d1d0c603
JJ
16453/* Define the offset between two registers, FROM to be eliminated and its
16454 replacement TO, at the start of a routine. */
16455HOST_WIDE_INT
16456rs6000_initial_elimination_offset (int from, int to)
16457{
16458 rs6000_stack_t *info = rs6000_stack_info ();
16459 HOST_WIDE_INT offset;
16460
16461 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16462 offset = info->push_p ? 0 : -info->total_size;
16463 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
16464 offset = info->total_size;
16465 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16466 offset = info->push_p ? info->total_size : 0;
16467 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
16468 offset = 0;
16469 else
16470 abort ();
16471
16472 return offset;
16473}
16474
62e1dfcf
NC
16475/* Return true if TYPE is of type __ev64_opaque__. */
16476
c8e4f0e9 16477static bool
a2369ed3 16478is_ev64_opaque_type (tree type)
62e1dfcf 16479{
c8e4f0e9 16480 return (TARGET_SPE
2abe3e28
AH
16481 && (type == opaque_V2SI_type_node
16482 || type == opaque_V2SF_type_node
36252949 16483 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
16484}
16485
96714395 16486static rtx
a2369ed3 16487rs6000_dwarf_register_span (rtx reg)
96714395
AH
16488{
16489 unsigned regno;
16490
16491 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
16492 return NULL_RTX;
16493
16494 regno = REGNO (reg);
16495
16496 /* The duality of the SPE register size wreaks all kinds of havoc.
16497 This is a way of distinguishing r0 in 32-bits from r0 in
16498 64-bits. */
16499 return
16500 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
16501 BYTES_BIG_ENDIAN
16502 ? gen_rtvec (2,
16503 gen_rtx_REG (SImode, regno + 1200),
16504 gen_rtx_REG (SImode, regno))
16505 : gen_rtvec (2,
16506 gen_rtx_REG (SImode, regno),
16507 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
16508}
16509
93c9d1ba
AM
16510/* Map internal gcc register numbers to DWARF2 register numbers. */
16511
16512unsigned int
16513rs6000_dbx_register_number (unsigned int regno)
16514{
16515 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
16516 return regno;
16517 if (regno == MQ_REGNO)
16518 return 100;
16519 if (regno == LINK_REGISTER_REGNUM)
16520 return 108;
16521 if (regno == COUNT_REGISTER_REGNUM)
16522 return 109;
16523 if (CR_REGNO_P (regno))
16524 return regno - CR0_REGNO + 86;
16525 if (regno == XER_REGNO)
16526 return 101;
16527 if (ALTIVEC_REGNO_P (regno))
16528 return regno - FIRST_ALTIVEC_REGNO + 1124;
16529 if (regno == VRSAVE_REGNO)
16530 return 356;
16531 if (regno == VSCR_REGNO)
16532 return 67;
16533 if (regno == SPE_ACC_REGNO)
16534 return 99;
16535 if (regno == SPEFSCR_REGNO)
16536 return 612;
16537 /* SPE high reg number. We get these values of regno from
16538 rs6000_dwarf_register_span. */
16539 if (regno >= 1200 && regno < 1232)
16540 return regno;
16541
16542 abort ();
16543}
16544
17211ab5 16545#include "gt-rs6000.h"