]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
stl_list.h: Created a _List_impl class and made it derive from the allocator...
[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
d744e06e
AH
63#define EASY_VECTOR_15(n, x, y) ((n) >= -16 && (n) <= 15 \
64 && easy_vector_same (x, y))
65
66#define EASY_VECTOR_15_ADD_SELF(n, x, y) ((n) >= 0x10 && (n) <= 0x1e \
67 && !((n) & 1) \
68 && easy_vector_same (x, y))
69
9878760c
RK
70#define min(A,B) ((A) < (B) ? (A) : (B))
71#define max(A,B) ((A) > (B) ? (A) : (B))
72
d1d0c603
JJ
73/* Structure used to define the rs6000 stack */
74typedef struct rs6000_stack {
75 int first_gp_reg_save; /* first callee saved GP register used */
76 int first_fp_reg_save; /* first callee saved FP register used */
77 int first_altivec_reg_save; /* first callee saved AltiVec register used */
78 int lr_save_p; /* true if the link reg needs to be saved */
79 int cr_save_p; /* true if the CR reg needs to be saved */
80 unsigned int vrsave_mask; /* mask of vec registers to save */
81 int toc_save_p; /* true if the TOC needs to be saved */
82 int push_p; /* true if we need to allocate stack space */
83 int calls_p; /* true if the function makes any calls */
84 enum rs6000_abi abi; /* which ABI to use */
85 int gp_save_offset; /* offset to save GP regs from initial SP */
86 int fp_save_offset; /* offset to save FP regs from initial SP */
87 int altivec_save_offset; /* offset to save AltiVec regs from initial SP */
88 int lr_save_offset; /* offset to save LR from initial SP */
89 int cr_save_offset; /* offset to save CR from initial SP */
90 int vrsave_save_offset; /* offset to save VRSAVE from initial SP */
91 int spe_gp_save_offset; /* offset to save spe 64-bit gprs */
92 int toc_save_offset; /* offset to save the TOC pointer */
93 int varargs_save_offset; /* offset to save the varargs registers */
94 int ehrd_offset; /* offset to EH return data */
95 int reg_size; /* register size (4 or 8) */
96 int varargs_size; /* size to hold V.4 args passed in regs */
97 HOST_WIDE_INT vars_size; /* variable save area size */
98 int parm_size; /* outgoing parameter size */
99 int save_size; /* save area size */
100 int fixed_size; /* fixed size of stack frame */
101 int gp_size; /* size of saved GP registers */
102 int fp_size; /* size of saved FP registers */
103 int altivec_size; /* size of saved AltiVec registers */
104 int cr_size; /* size to hold CR if not in save_size */
105 int lr_size; /* size to hold LR if not in save_size */
106 int vrsave_size; /* size to hold VRSAVE if not in save_size */
107 int altivec_padding_size; /* size of altivec alignment padding if
108 not in save_size */
109 int spe_gp_size; /* size of 64-bit GPR save size for SPE */
110 int spe_padding_size;
111 int toc_size; /* size to hold TOC if not in save_size */
112 HOST_WIDE_INT total_size; /* total bytes allocated for stack */
113 int spe_64bit_regs_used;
114} rs6000_stack_t;
115
5248c961
RK
116/* Target cpu type */
117
118enum processor_type rs6000_cpu;
8e3f41e7
MM
119struct rs6000_cpu_select rs6000_select[3] =
120{
815cdc52
MM
121 /* switch name, tune arch */
122 { (const char *)0, "--with-cpu=", 1, 1 },
123 { (const char *)0, "-mcpu=", 1, 1 },
124 { (const char *)0, "-mtune=", 1, 0 },
8e3f41e7 125};
5248c961 126
79ae11c4
DN
127/* Support adjust_priority scheduler hook
128 and -mprioritize-restricted-insns= option. */
129const char *rs6000_sched_restricted_insns_priority_str;
130int rs6000_sched_restricted_insns_priority;
131
569fa502
DN
132/* Support for -msched-costly-dep option. */
133const char *rs6000_sched_costly_dep_str;
134enum rs6000_dependence_cost rs6000_sched_costly_dep;
135
cbe26ab8
DN
136/* Support for -minsert-sched-nops option. */
137const char *rs6000_sched_insert_nops_str;
138enum rs6000_nop_insertion rs6000_sched_insert_nops;
139
6fa3f289
ZW
140/* Size of long double */
141const char *rs6000_long_double_size_string;
142int rs6000_long_double_type_size;
143
144/* Whether -mabi=altivec has appeared */
145int rs6000_altivec_abi;
146
08b57fb3
AH
147/* Whether VRSAVE instructions should be generated. */
148int rs6000_altivec_vrsave;
149
150/* String from -mvrsave= option. */
151const char *rs6000_altivec_vrsave_string;
152
a3170dc6
AH
153/* Nonzero if we want SPE ABI extensions. */
154int rs6000_spe_abi;
155
156/* Whether isel instructions should be generated. */
157int rs6000_isel;
158
993f19a8
AH
159/* Whether SPE simd instructions should be generated. */
160int rs6000_spe;
161
5da702b1
AH
162/* Nonzero if floating point operations are done in the GPRs. */
163int rs6000_float_gprs = 0;
164
165/* String from -mfloat-gprs=. */
166const char *rs6000_float_gprs_string;
a3170dc6
AH
167
168/* String from -misel=. */
169const char *rs6000_isel_string;
170
993f19a8
AH
171/* String from -mspe=. */
172const char *rs6000_spe_string;
173
a0ab749a 174/* Set to nonzero once AIX common-mode calls have been defined. */
bbfb86aa 175static GTY(()) int common_mode_defined;
c81bebd7 176
9878760c
RK
177/* Save information from a "cmpxx" operation until the branch or scc is
178 emitted. */
9878760c
RK
179rtx rs6000_compare_op0, rs6000_compare_op1;
180int rs6000_compare_fp_p;
874a0744 181
874a0744
MM
182/* Label number of label created for -mrelocatable, to call to so we can
183 get the address of the GOT section */
184int rs6000_pic_labelno;
c81bebd7 185
b91da81f 186#ifdef USING_ELFOS_H
c81bebd7 187/* Which abi to adhere to */
9739c90c 188const char *rs6000_abi_name;
d9407988
MM
189
190/* Semantics of the small data area */
191enum rs6000_sdata_type rs6000_sdata = SDATA_DATA;
192
193/* Which small data model to use */
815cdc52 194const char *rs6000_sdata_name = (char *)0;
9ebbca7d
GK
195
196/* Counter for labels which are to be placed in .fixup. */
197int fixuplabelno = 0;
874a0744 198#endif
4697a36c 199
c4501e62
JJ
200/* Bit size of immediate TLS offsets and string from which it is decoded. */
201int rs6000_tls_size = 32;
202const char *rs6000_tls_size_string;
203
b6c9286a
MM
204/* ABI enumeration available for subtarget to use. */
205enum rs6000_abi rs6000_current_abi;
206
0ac081f6
AH
207/* ABI string from -mabi= option. */
208const char *rs6000_abi_string;
209
38c1f2d7 210/* Debug flags */
815cdc52 211const char *rs6000_debug_name;
38c1f2d7
MM
212int rs6000_debug_stack; /* debug stack applications */
213int rs6000_debug_arg; /* debug argument handling */
214
6035d635 215/* Opaque types. */
2abe3e28 216static GTY(()) tree opaque_V2SI_type_node;
2abe3e28 217static GTY(()) tree opaque_V2SF_type_node;
6035d635 218static GTY(()) tree opaque_p_V2SI_type_node;
4a5eab38
PB
219static GTY(()) tree V16QI_type_node;
220static GTY(()) tree V2SI_type_node;
221static GTY(()) tree V2SF_type_node;
222static GTY(()) tree V4HI_type_node;
223static GTY(()) tree V4SI_type_node;
224static GTY(()) tree V4SF_type_node;
225static GTY(()) tree V8HI_type_node;
226static GTY(()) tree unsigned_V16QI_type_node;
227static GTY(()) tree unsigned_V8HI_type_node;
228static GTY(()) tree unsigned_V4SI_type_node;
8bb418a3
ZL
229static GTY(()) tree bool_char_type_node; /* __bool char */
230static GTY(()) tree bool_short_type_node; /* __bool short */
231static GTY(()) tree bool_int_type_node; /* __bool int */
232static GTY(()) tree pixel_type_node; /* __pixel */
233static GTY(()) tree bool_V16QI_type_node; /* __vector __bool char */
234static GTY(()) tree bool_V8HI_type_node; /* __vector __bool short */
235static GTY(()) tree bool_V4SI_type_node; /* __vector __bool int */
236static GTY(()) tree pixel_V8HI_type_node; /* __vector __pixel */
237
238int rs6000_warn_altivec_long = 1; /* On by default. */
239const char *rs6000_warn_altivec_long_switch;
240
57ac7be9
AM
241const char *rs6000_traceback_name;
242static enum {
243 traceback_default = 0,
244 traceback_none,
245 traceback_part,
246 traceback_full
247} rs6000_traceback;
248
38c1f2d7
MM
249/* Flag to say the TOC is initialized */
250int toc_initialized;
9ebbca7d 251char toc_label_name[10];
38c1f2d7 252
9ebbca7d 253/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 254static GTY(()) int rs6000_sr_alias_set;
c8023011 255
a5c76ee6
ZW
256/* Call distance, overridden by -mlongcall and #pragma longcall(1).
257 The only place that looks at this is rs6000_set_default_type_attributes;
258 everywhere else should rely on the presence or absence of a longcall
259 attribute on the function declaration. */
260int rs6000_default_long_calls;
261const char *rs6000_longcall_switch;
262
a3c9585f
KH
263/* Control alignment for fields within structures. */
264/* String from -malign-XXXXX. */
025d9908
KH
265const char *rs6000_alignment_string;
266int rs6000_alignment_flags;
267
a3170dc6
AH
268struct builtin_description
269{
270 /* mask is not const because we're going to alter it below. This
271 nonsense will go away when we rewrite the -march infrastructure
272 to give us more target flag bits. */
273 unsigned int mask;
274 const enum insn_code icode;
275 const char *const name;
276 const enum rs6000_builtins code;
277};
278
a2369ed3
DJ
279static bool rs6000_function_ok_for_sibcall (tree, tree);
280static int num_insns_constant_wide (HOST_WIDE_INT);
281static void validate_condition_mode (enum rtx_code, enum machine_mode);
282static rtx rs6000_generate_compare (enum rtx_code);
283static void rs6000_maybe_dead (rtx);
284static void rs6000_emit_stack_tie (void);
285static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
286static rtx spe_synthesize_frame_save (rtx);
287static bool spe_func_has_64bit_regs_p (void);
b20a9cca 288static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 289 int, HOST_WIDE_INT);
a2369ed3
DJ
290static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
291static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
292static unsigned rs6000_hash_constant (rtx);
293static unsigned toc_hash_function (const void *);
294static int toc_hash_eq (const void *, const void *);
295static int constant_pool_expr_1 (rtx, int *, int *);
296static bool constant_pool_expr_p (rtx);
297static bool toc_relative_expr_p (rtx);
298static bool legitimate_small_data_p (enum machine_mode, rtx);
299static bool legitimate_offset_address_p (enum machine_mode, rtx, int);
300static bool legitimate_indexed_address_p (rtx, int);
301static bool legitimate_indirect_address_p (rtx, int);
4c81e946 302static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
303static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
304static struct machine_function * rs6000_init_machine_status (void);
305static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 306#ifdef HAVE_GAS_HIDDEN
a2369ed3 307static void rs6000_assemble_visibility (tree, int);
5add3202 308#endif
a2369ed3
DJ
309static int rs6000_ra_ever_killed (void);
310static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
8bb418a3 311static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *);
f18eca82 312static const char *rs6000_mangle_fundamental_type (tree);
b86fe7b4 313extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
314static void rs6000_set_default_type_attributes (tree);
315static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
316static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
317static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
318 tree);
a2369ed3 319static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 320static bool rs6000_return_in_memory (tree, tree);
a2369ed3 321static void rs6000_file_start (void);
7c262518 322#if TARGET_ELF
a2369ed3
DJ
323static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
324static void rs6000_elf_asm_out_constructor (rtx, int);
325static void rs6000_elf_asm_out_destructor (rtx, int);
326static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
327static void rs6000_elf_unique_section (tree, int);
328static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 329 unsigned HOST_WIDE_INT);
a56d7372 330static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 331 ATTRIBUTE_UNUSED;
a2369ed3 332static bool rs6000_elf_in_small_data_p (tree);
7c262518 333#endif
cbaaba19 334#if TARGET_XCOFF
a2369ed3
DJ
335static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
336static void rs6000_xcoff_asm_named_section (const char *, unsigned int);
337static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
338static void rs6000_xcoff_unique_section (tree, int);
339static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 340 unsigned HOST_WIDE_INT);
a2369ed3
DJ
341static const char * rs6000_xcoff_strip_name_encoding (const char *);
342static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
343static void rs6000_xcoff_file_start (void);
344static void rs6000_xcoff_file_end (void);
f1384257
AM
345#endif
346#if TARGET_MACHO
a2369ed3 347static bool rs6000_binds_local_p (tree);
f1384257 348#endif
a2369ed3
DJ
349static int rs6000_use_dfa_pipeline_interface (void);
350static int rs6000_variable_issue (FILE *, int, rtx, int);
351static bool rs6000_rtx_costs (rtx, int, int, int *);
352static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 353static bool is_microcoded_insn (rtx);
79ae11c4 354static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
355static bool is_cracked_insn (rtx);
356static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
357static int rs6000_adjust_priority (rtx, int);
358static int rs6000_issue_rate (void);
569fa502 359static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
360static rtx get_next_active_insn (rtx, rtx);
361static bool insn_terminates_group_p (rtx , enum group_termination);
362static bool is_costly_group (rtx *, rtx);
363static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
364static int redefine_groups (FILE *, int, rtx, rtx);
365static int pad_groups (FILE *, int, rtx, rtx);
366static void rs6000_sched_finish (FILE *, int);
a2369ed3
DJ
367static int rs6000_use_sched_lookahead (void);
368
369static void rs6000_init_builtins (void);
370static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
371static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
372static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
373static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
374static void altivec_init_builtins (void);
375static void rs6000_common_init_builtins (void);
c15c90bb 376static void rs6000_init_libfuncs (void);
a2369ed3 377
b20a9cca
AM
378static void enable_mask_for_builtins (struct builtin_description *, int,
379 enum rs6000_builtins,
380 enum rs6000_builtins);
a2369ed3
DJ
381static void spe_init_builtins (void);
382static rtx spe_expand_builtin (tree, rtx, bool *);
383static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
384static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
385static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
386static rs6000_stack_t *rs6000_stack_info (void);
387static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
388
389static rtx altivec_expand_builtin (tree, rtx, bool *);
390static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
391static rtx altivec_expand_st_builtin (tree, rtx, bool *);
392static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
393static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
394static rtx altivec_expand_predicate_builtin (enum insn_code,
395 const char *, tree, rtx);
b4a62fa0 396static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
397static rtx altivec_expand_stv_builtin (enum insn_code, tree);
398static void rs6000_parse_abi_options (void);
399static void rs6000_parse_alignment_option (void);
400static void rs6000_parse_tls_size_option (void);
5da702b1 401static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
402static int first_altivec_reg_to_save (void);
403static unsigned int compute_vrsave_mask (void);
404static void is_altivec_return_reg (rtx, void *);
405static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
406int easy_vector_constant (rtx, enum machine_mode);
407static int easy_vector_same (rtx, enum machine_mode);
408static bool is_ev64_opaque_type (tree);
409static rtx rs6000_dwarf_register_span (rtx);
410static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
411static rtx rs6000_tls_get_addr (void);
412static rtx rs6000_got_sym (void);
413static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
414static const char *rs6000_get_some_local_dynamic_name (void);
415static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 416static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 417static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 418 enum machine_mode, tree);
b78d48dd
FJ
419static rtx rs6000_mixed_function_arg (CUMULATIVE_ARGS *,
420 enum machine_mode, tree, int);
b1917422 421static void rs6000_move_block_from_reg (int regno, rtx x, int nregs);
c6e8c921
GK
422static void setup_incoming_varargs (CUMULATIVE_ARGS *,
423 enum machine_mode, tree,
424 int *, int);
efdba735
SH
425#if TARGET_MACHO
426static void macho_branch_islands (void);
427static void add_compiler_branch_island (tree, tree, int);
428static int no_previous_def (tree function_name);
429static tree get_prev_label (tree function_name);
430#endif
431
c35d187f 432static tree rs6000_build_builtin_va_list (void);
17211ab5
GK
433
434/* Hash table stuff for keeping track of TOC entries. */
435
436struct toc_hash_struct GTY(())
437{
438 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
439 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
440 rtx key;
441 enum machine_mode key_mode;
442 int labelno;
443};
444
445static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
446\f
447/* Default register names. */
448char rs6000_reg_names[][8] =
449{
802a0058
MM
450 "0", "1", "2", "3", "4", "5", "6", "7",
451 "8", "9", "10", "11", "12", "13", "14", "15",
452 "16", "17", "18", "19", "20", "21", "22", "23",
453 "24", "25", "26", "27", "28", "29", "30", "31",
454 "0", "1", "2", "3", "4", "5", "6", "7",
455 "8", "9", "10", "11", "12", "13", "14", "15",
456 "16", "17", "18", "19", "20", "21", "22", "23",
457 "24", "25", "26", "27", "28", "29", "30", "31",
458 "mq", "lr", "ctr","ap",
459 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
460 "xer",
461 /* AltiVec registers. */
0cd5e3a1
AH
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",
59a4c851
AH
466 "vrsave", "vscr",
467 /* SPE registers. */
468 "spe_acc", "spefscr"
c81bebd7
MM
469};
470
471#ifdef TARGET_REGNAMES
8b60264b 472static const char alt_reg_names[][8] =
c81bebd7 473{
802a0058
MM
474 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
475 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
476 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
477 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
478 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
479 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
480 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
481 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
482 "mq", "lr", "ctr", "ap",
483 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 484 "xer",
59a4c851 485 /* AltiVec registers. */
0ac081f6 486 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
487 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
488 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
489 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
490 "vrsave", "vscr",
491 /* SPE registers. */
492 "spe_acc", "spefscr"
c81bebd7
MM
493};
494#endif
9878760c 495\f
daf11973
MM
496#ifndef MASK_STRICT_ALIGN
497#define MASK_STRICT_ALIGN 0
498#endif
ffcfcb5f
AM
499#ifndef TARGET_PROFILE_KERNEL
500#define TARGET_PROFILE_KERNEL 0
501#endif
3961e8fe
RH
502
503/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
504#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
505
506/* Return 1 for a symbol ref for a thread-local storage symbol. */
507#define RS6000_SYMBOL_REF_TLS_P(RTX) \
508 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
509\f
510/* Initialize the GCC target structure. */
91d231cb
JM
511#undef TARGET_ATTRIBUTE_TABLE
512#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
513#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
514#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 515
301d03af
RS
516#undef TARGET_ASM_ALIGNED_DI_OP
517#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
518
519/* Default unaligned ops are only provided for ELF. Find the ops needed
520 for non-ELF systems. */
521#ifndef OBJECT_FORMAT_ELF
cbaaba19 522#if TARGET_XCOFF
ae6c1efd 523/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
524 64-bit targets. */
525#undef TARGET_ASM_UNALIGNED_HI_OP
526#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
527#undef TARGET_ASM_UNALIGNED_SI_OP
528#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
529#undef TARGET_ASM_UNALIGNED_DI_OP
530#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
531#else
532/* For Darwin. */
533#undef TARGET_ASM_UNALIGNED_HI_OP
534#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
535#undef TARGET_ASM_UNALIGNED_SI_OP
536#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
537#endif
538#endif
539
540/* This hook deals with fixups for relocatable code and DI-mode objects
541 in 64-bit code. */
542#undef TARGET_ASM_INTEGER
543#define TARGET_ASM_INTEGER rs6000_assemble_integer
544
93638d7a
AM
545#ifdef HAVE_GAS_HIDDEN
546#undef TARGET_ASM_ASSEMBLE_VISIBILITY
547#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
548#endif
549
c4501e62
JJ
550#undef TARGET_HAVE_TLS
551#define TARGET_HAVE_TLS HAVE_AS_TLS
552
553#undef TARGET_CANNOT_FORCE_CONST_MEM
554#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
555
08c148a8
NB
556#undef TARGET_ASM_FUNCTION_PROLOGUE
557#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
558#undef TARGET_ASM_FUNCTION_EPILOGUE
559#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
560
b54cf83a
DE
561#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
562#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
563#undef TARGET_SCHED_VARIABLE_ISSUE
564#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
565
c237e94a
ZW
566#undef TARGET_SCHED_ISSUE_RATE
567#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
568#undef TARGET_SCHED_ADJUST_COST
569#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
570#undef TARGET_SCHED_ADJUST_PRIORITY
571#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
569fa502
DN
572#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
573#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
574#undef TARGET_SCHED_FINISH
575#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 576
be12c2b0
VM
577#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
578#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
579
0ac081f6
AH
580#undef TARGET_INIT_BUILTINS
581#define TARGET_INIT_BUILTINS rs6000_init_builtins
582
583#undef TARGET_EXPAND_BUILTIN
584#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
585
f18eca82
ZL
586#undef TARGET_MANGLE_FUNDAMENTAL_TYPE
587#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type
588
c15c90bb
ZW
589#undef TARGET_INIT_LIBFUNCS
590#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
591
f1384257 592#if TARGET_MACHO
0e5dbd9b
DE
593#undef TARGET_BINDS_LOCAL_P
594#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 595#endif
0e5dbd9b 596
3961e8fe
RH
597#undef TARGET_ASM_OUTPUT_MI_THUNK
598#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
599
3961e8fe 600#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 601#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 602
4977bab6
ZW
603#undef TARGET_FUNCTION_OK_FOR_SIBCALL
604#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
605
3c50106f
RH
606#undef TARGET_RTX_COSTS
607#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
608#undef TARGET_ADDRESS_COST
609#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 610
c8e4f0e9
AH
611#undef TARGET_VECTOR_OPAQUE_P
612#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 613
96714395
AH
614#undef TARGET_DWARF_REGISTER_SPAN
615#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
616
c6e8c921
GK
617/* On rs6000, function arguments are promoted, as are function return
618 values. */
619#undef TARGET_PROMOTE_FUNCTION_ARGS
620#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
621#undef TARGET_PROMOTE_FUNCTION_RETURN
622#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
623
c6e8c921
GK
624#undef TARGET_RETURN_IN_MEMORY
625#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
626
627#undef TARGET_SETUP_INCOMING_VARARGS
628#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
629
630/* Always strict argument naming on rs6000. */
631#undef TARGET_STRICT_ARGUMENT_NAMING
632#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
633#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
634#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
42ba5130
RH
635#undef TARGET_SPLIT_COMPLEX_ARG
636#define TARGET_SPLIT_COMPLEX_ARG hook_bool_tree_true
c6e8c921 637
c35d187f
RH
638#undef TARGET_BUILD_BUILTIN_VA_LIST
639#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
640
f6897b10 641struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 642\f
5248c961
RK
643/* Override command line options. Mostly we process the processor
644 type and sometimes adjust other TARGET_ options. */
645
646void
d779d0dc 647rs6000_override_options (const char *default_cpu)
5248c961 648{
c4d38ccb 649 size_t i, j;
8e3f41e7 650 struct rs6000_cpu_select *ptr;
66188a7e 651 int set_masks;
5248c961 652
66188a7e 653 /* Simplifications for entries below. */
85638c0d 654
66188a7e
GK
655 enum {
656 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
657 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
658 };
85638c0d 659
66188a7e
GK
660 /* This table occasionally claims that a processor does not support
661 a particular feature even though it does, but the feature is slower
662 than the alternative. Thus, it shouldn't be relied on as a
663 complete description of the processor's support.
664
665 Please keep this list in order, and don't forget to update the
666 documentation in invoke.texi when adding a new processor or
667 flag. */
5248c961
RK
668 static struct ptt
669 {
8b60264b
KG
670 const char *const name; /* Canonical processor name. */
671 const enum processor_type processor; /* Processor type enum value. */
672 const int target_enable; /* Target flags to enable. */
8b60264b 673 } const processor_target_table[]
66188a7e 674 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 675 {"403", PROCESSOR_PPC403,
66188a7e
GK
676 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
677 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
678 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
679 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
680 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
681 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 682 {"601", PROCESSOR_PPC601,
66188a7e
GK
683 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
684 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
685 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
686 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
687 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
688 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
689 {"620", PROCESSOR_PPC620,
690 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
691 {"630", PROCESSOR_PPC630,
692 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
693 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
694 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
695 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
696 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
697 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
698 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
699 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
700 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
701 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 702 {"970", PROCESSOR_POWER4,
66188a7e
GK
703 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
704 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
705 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
706 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
707 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 708 {"G5", PROCESSOR_POWER4,
66188a7e
GK
709 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
710 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
711 {"power2", PROCESSOR_POWER,
712 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
713 {"power3", PROCESSOR_PPC630,
714 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
715 {"power4", PROCESSOR_POWER4,
716 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
717 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
718 {"powerpc64", PROCESSOR_POWERPC64,
719 POWERPC_BASE_MASK | MASK_POWERPC64},
720 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
721 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
722 {"rios2", PROCESSOR_RIOS2,
723 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
724 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
725 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 726 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 727 };
5248c961 728
ca7558fc 729 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 730
66188a7e
GK
731 /* Some OSs don't support saving the high part of 64-bit registers on
732 context switch. Other OSs don't support saving Altivec registers.
733 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
734 settings; if the user wants either, the user must explicitly specify
735 them and we won't interfere with the user's specification. */
736
737 enum {
738 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
739 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
740 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
741 | MASK_MFCRF)
742 };
743 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
744#ifdef OS_MISSING_POWERPC64
745 if (OS_MISSING_POWERPC64)
746 set_masks &= ~MASK_POWERPC64;
747#endif
748#ifdef OS_MISSING_ALTIVEC
749 if (OS_MISSING_ALTIVEC)
750 set_masks &= ~MASK_ALTIVEC;
751#endif
752
957211c3
AM
753 /* Don't override these by the processor default if given explicitly. */
754 set_masks &= ~(target_flags_explicit
755 & (MASK_MULTIPLE | MASK_STRING | MASK_SOFT_FLOAT));
756
a4f6c312 757 /* Identify the processor type. */
8e3f41e7 758 rs6000_select[0].string = default_cpu;
3cb999d8 759 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 760
b6a1cbae 761 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 762 {
8e3f41e7
MM
763 ptr = &rs6000_select[i];
764 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 765 {
8e3f41e7
MM
766 for (j = 0; j < ptt_size; j++)
767 if (! strcmp (ptr->string, processor_target_table[j].name))
768 {
769 if (ptr->set_tune_p)
770 rs6000_cpu = processor_target_table[j].processor;
771
772 if (ptr->set_arch_p)
773 {
66188a7e
GK
774 target_flags &= ~set_masks;
775 target_flags |= (processor_target_table[j].target_enable
776 & set_masks);
8e3f41e7
MM
777 }
778 break;
779 }
780
4406229e 781 if (j == ptt_size)
8e3f41e7 782 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
783 }
784 }
8a61d227 785
993f19a8 786 if (TARGET_E500)
a3170dc6
AH
787 rs6000_isel = 1;
788
dff9f1b6
DE
789 /* If we are optimizing big endian systems for space, use the load/store
790 multiple and string instructions. */
ef792183 791 if (BYTES_BIG_ENDIAN && optimize_size)
957211c3 792 target_flags |= ~target_flags_explicit & (MASK_MULTIPLE | MASK_STRING);
938937d8 793
a4f6c312
SS
794 /* Don't allow -mmultiple or -mstring on little endian systems
795 unless the cpu is a 750, because the hardware doesn't support the
796 instructions used in little endian mode, and causes an alignment
797 trap. The 750 does not cause an alignment trap (except when the
798 target is unaligned). */
bef84347 799
b21fb038 800 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
801 {
802 if (TARGET_MULTIPLE)
803 {
804 target_flags &= ~MASK_MULTIPLE;
b21fb038 805 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
806 warning ("-mmultiple is not supported on little endian systems");
807 }
808
809 if (TARGET_STRING)
810 {
811 target_flags &= ~MASK_STRING;
b21fb038 812 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 813 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
814 }
815 }
3933e0e1 816
38c1f2d7
MM
817 /* Set debug flags */
818 if (rs6000_debug_name)
819 {
bfc79d3b 820 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 821 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 822 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 823 rs6000_debug_stack = 1;
bfc79d3b 824 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
825 rs6000_debug_arg = 1;
826 else
c725bd79 827 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
828 }
829
57ac7be9
AM
830 if (rs6000_traceback_name)
831 {
832 if (! strncmp (rs6000_traceback_name, "full", 4))
833 rs6000_traceback = traceback_full;
834 else if (! strncmp (rs6000_traceback_name, "part", 4))
835 rs6000_traceback = traceback_part;
836 else if (! strncmp (rs6000_traceback_name, "no", 2))
837 rs6000_traceback = traceback_none;
838 else
839 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
840 rs6000_traceback_name);
841 }
842
6fa3f289
ZW
843 /* Set size of long double */
844 rs6000_long_double_type_size = 64;
845 if (rs6000_long_double_size_string)
846 {
847 char *tail;
848 int size = strtol (rs6000_long_double_size_string, &tail, 10);
849 if (*tail != '\0' || (size != 64 && size != 128))
850 error ("Unknown switch -mlong-double-%s",
851 rs6000_long_double_size_string);
852 else
853 rs6000_long_double_type_size = size;
854 }
855
6d0ef01e
HP
856 /* Set Altivec ABI as default for powerpc64 linux. */
857 if (TARGET_ELF && TARGET_64BIT)
858 {
859 rs6000_altivec_abi = 1;
860 rs6000_altivec_vrsave = 1;
861 }
862
0ac081f6
AH
863 /* Handle -mabi= options. */
864 rs6000_parse_abi_options ();
865
025d9908
KH
866 /* Handle -malign-XXXXX option. */
867 rs6000_parse_alignment_option ();
868
5da702b1
AH
869 /* Handle generic -mFOO=YES/NO options. */
870 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
871 &rs6000_altivec_vrsave);
872 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
873 &rs6000_isel);
874 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
875 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
876 &rs6000_float_gprs);
993f19a8 877
c4501e62
JJ
878 /* Handle -mtls-size option. */
879 rs6000_parse_tls_size_option ();
880
a7ae18e2
AH
881#ifdef SUBTARGET_OVERRIDE_OPTIONS
882 SUBTARGET_OVERRIDE_OPTIONS;
883#endif
884#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
885 SUBSUBTARGET_OVERRIDE_OPTIONS;
886#endif
887
5da702b1
AH
888 if (TARGET_E500)
889 {
890 /* The e500 does not have string instructions, and we set
891 MASK_STRING above when optimizing for size. */
892 if ((target_flags & MASK_STRING) != 0)
893 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
894
895 /* No SPE means 64-bit long doubles, even if an E500. */
896 if (rs6000_spe_string != 0
897 && !strcmp (rs6000_spe_string, "no"))
898 rs6000_long_double_type_size = 64;
5da702b1
AH
899 }
900 else if (rs6000_select[1].string != NULL)
901 {
902 /* For the powerpc-eabispe configuration, we set all these by
903 default, so let's unset them if we manually set another
904 CPU that is not the E500. */
905 if (rs6000_abi_string == 0)
906 rs6000_spe_abi = 0;
907 if (rs6000_spe_string == 0)
908 rs6000_spe = 0;
909 if (rs6000_float_gprs_string == 0)
910 rs6000_float_gprs = 0;
911 if (rs6000_isel_string == 0)
912 rs6000_isel = 0;
b6e59a3a
AH
913 if (rs6000_long_double_size_string == 0)
914 rs6000_long_double_type_size = 64;
5da702b1 915 }
b5044283 916
a5c76ee6
ZW
917 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
918 using TARGET_OPTIONS to handle a toggle switch, but we're out of
919 bits in target_flags so TARGET_SWITCHES cannot be used.
920 Assumption here is that rs6000_longcall_switch points into the
921 text of the complete option, rather than being a copy, so we can
922 scan back for the presence or absence of the no- modifier. */
923 if (rs6000_longcall_switch)
924 {
925 const char *base = rs6000_longcall_switch;
926 while (base[-1] != 'm') base--;
927
928 if (*rs6000_longcall_switch != '\0')
929 error ("invalid option `%s'", base);
930 rs6000_default_long_calls = (base[0] != 'n');
931 }
932
8bb418a3
ZL
933 /* Handle -m(no-)warn-altivec-long similarly. */
934 if (rs6000_warn_altivec_long_switch)
935 {
936 const char *base = rs6000_warn_altivec_long_switch;
937 while (base[-1] != 'm') base--;
938
939 if (*rs6000_warn_altivec_long_switch != '\0')
940 error ("invalid option `%s'", base);
941 rs6000_warn_altivec_long = (base[0] != 'n');
942 }
943
cbe26ab8 944 /* Handle -mprioritize-restricted-insns option. */
79ae11c4
DN
945 rs6000_sched_restricted_insns_priority = DEFAULT_RESTRICTED_INSNS_PRIORITY;
946 if (rs6000_sched_restricted_insns_priority_str)
947 rs6000_sched_restricted_insns_priority =
948 atoi (rs6000_sched_restricted_insns_priority_str);
949
569fa502
DN
950 /* Handle -msched-costly-dep option. */
951 rs6000_sched_costly_dep = DEFAULT_SCHED_COSTLY_DEP;
952 if (rs6000_sched_costly_dep_str)
953 {
954 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
955 rs6000_sched_costly_dep = no_dep_costly;
956 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
957 rs6000_sched_costly_dep = all_deps_costly;
958 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
959 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
960 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
961 rs6000_sched_costly_dep = store_to_load_dep_costly;
cbe26ab8
DN
962 else
963 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
964 }
965
966 /* Handle -minsert-sched-nops option. */
967 rs6000_sched_insert_nops = DEFAULT_SCHED_FINISH_NOP_INSERTION_SCHEME;
968 if (rs6000_sched_insert_nops_str)
969 {
970 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
971 rs6000_sched_insert_nops = sched_finish_none;
972 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
973 rs6000_sched_insert_nops = sched_finish_pad_groups;
974 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
975 rs6000_sched_insert_nops = sched_finish_regroup_exact;
976 else
977 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
978 }
979
c81bebd7 980#ifdef TARGET_REGNAMES
a4f6c312
SS
981 /* If the user desires alternate register names, copy in the
982 alternate names now. */
c81bebd7 983 if (TARGET_REGNAMES)
4e135bdd 984 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
985#endif
986
6fa3f289
ZW
987 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
988 If -maix-struct-return or -msvr4-struct-return was explicitly
989 used, don't override with the ABI default. */
b21fb038 990 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
991 {
992 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
993 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
994 else
995 target_flags |= MASK_AIX_STRUCT_RET;
996 }
997
fcce224d
DE
998 if (TARGET_LONG_DOUBLE_128
999 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 1000 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 1001
9ebbca7d
GK
1002 /* Allocate an alias set for register saves & restores from stack. */
1003 rs6000_sr_alias_set = new_alias_set ();
1004
1005 if (TARGET_TOC)
1006 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 1007
301d03af
RS
1008 /* We can only guarantee the availability of DI pseudo-ops when
1009 assembling for 64-bit targets. */
ae6c1efd 1010 if (!TARGET_64BIT)
301d03af
RS
1011 {
1012 targetm.asm_out.aligned_op.di = NULL;
1013 targetm.asm_out.unaligned_op.di = NULL;
1014 }
1015
2792d578
DE
1016 /* Set maximum branch target alignment at two instructions, eight bytes. */
1017 align_jumps_max_skip = 8;
1018 align_loops_max_skip = 8;
1019
71f123ca
FS
1020 /* Arrange to save and restore machine status around nested functions. */
1021 init_machine_status = rs6000_init_machine_status;
42ba5130
RH
1022
1023 /* We should always be splitting complex arguments, but we can't break
1024 Linux and Darwin ABIs at the moment. For now, only AIX is fixed. */
1025 if (DEFAULT_ABI != ABI_AIX)
1026 targetm.calls.split_complex_arg = NULL;
5248c961 1027}
5accd822 1028
5da702b1
AH
1029/* Handle generic options of the form -mfoo=yes/no.
1030 NAME is the option name.
1031 VALUE is the option value.
1032 FLAG is the pointer to the flag where to store a 1 or 0, depending on
1033 whether the option value is 'yes' or 'no' respectively. */
993f19a8 1034static void
5da702b1 1035rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1036{
5da702b1 1037 if (value == 0)
993f19a8 1038 return;
5da702b1
AH
1039 else if (!strcmp (value, "yes"))
1040 *flag = 1;
1041 else if (!strcmp (value, "no"))
1042 *flag = 0;
08b57fb3 1043 else
5da702b1 1044 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1045}
1046
0ac081f6 1047/* Handle -mabi= options. */
00b960c7 1048static void
863d938c 1049rs6000_parse_abi_options (void)
0ac081f6
AH
1050{
1051 if (rs6000_abi_string == 0)
1052 return;
1053 else if (! strcmp (rs6000_abi_string, "altivec"))
5cc73f91
AH
1054 {
1055 rs6000_altivec_abi = 1;
1056 rs6000_spe_abi = 0;
1057 }
76a773f3
AH
1058 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1059 rs6000_altivec_abi = 0;
a3170dc6 1060 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1061 {
1062 rs6000_spe_abi = 1;
5cc73f91 1063 rs6000_altivec_abi = 0;
01f4962d
NS
1064 if (!TARGET_SPE_ABI)
1065 error ("not configured for ABI: '%s'", rs6000_abi_string);
1066 }
1067
a3170dc6
AH
1068 else if (! strcmp (rs6000_abi_string, "no-spe"))
1069 rs6000_spe_abi = 0;
0ac081f6 1070 else
c725bd79 1071 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1072}
1073
025d9908
KH
1074/* Handle -malign-XXXXXX options. */
1075static void
863d938c 1076rs6000_parse_alignment_option (void)
025d9908 1077{
b20a9cca
AM
1078 if (rs6000_alignment_string == 0)
1079 return;
1080 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1081 rs6000_alignment_flags = MASK_ALIGN_POWER;
1082 else if (! strcmp (rs6000_alignment_string, "natural"))
1083 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1084 else
1085 error ("unknown -malign-XXXXX option specified: '%s'",
1086 rs6000_alignment_string);
1087}
1088
c4501e62
JJ
1089/* Validate and record the size specified with the -mtls-size option. */
1090
1091static void
863d938c 1092rs6000_parse_tls_size_option (void)
c4501e62
JJ
1093{
1094 if (rs6000_tls_size_string == 0)
1095 return;
1096 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1097 rs6000_tls_size = 16;
1098 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1099 rs6000_tls_size = 32;
1100 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1101 rs6000_tls_size = 64;
1102 else
1103 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1104}
1105
5accd822 1106void
a2369ed3 1107optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1108{
5accd822 1109}
3cfa4909
MM
1110\f
1111/* Do anything needed at the start of the asm file. */
1112
1bc7c5b6 1113static void
863d938c 1114rs6000_file_start (void)
3cfa4909 1115{
c4d38ccb 1116 size_t i;
3cfa4909 1117 char buffer[80];
d330fd93 1118 const char *start = buffer;
3cfa4909 1119 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1120 const char *default_cpu = TARGET_CPU_DEFAULT;
1121 FILE *file = asm_out_file;
1122
1123 default_file_start ();
1124
1125#ifdef TARGET_BI_ARCH
1126 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1127 default_cpu = 0;
1128#endif
3cfa4909
MM
1129
1130 if (flag_verbose_asm)
1131 {
1132 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1133 rs6000_select[0].string = default_cpu;
1134
b6a1cbae 1135 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1136 {
1137 ptr = &rs6000_select[i];
1138 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1139 {
1140 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1141 start = "";
1142 }
1143 }
1144
b91da81f 1145#ifdef USING_ELFOS_H
3cfa4909
MM
1146 switch (rs6000_sdata)
1147 {
1148 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1149 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1150 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1151 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1152 }
1153
1154 if (rs6000_sdata && g_switch_value)
1155 {
307b599c
MK
1156 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1157 g_switch_value);
3cfa4909
MM
1158 start = "";
1159 }
1160#endif
1161
1162 if (*start == '\0')
949ea356 1163 putc ('\n', file);
3cfa4909
MM
1164 }
1165}
5248c961 1166\f
a0ab749a 1167/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1168
1169int
863d938c 1170direct_return (void)
9878760c 1171{
4697a36c
MM
1172 if (reload_completed)
1173 {
1174 rs6000_stack_t *info = rs6000_stack_info ();
1175
1176 if (info->first_gp_reg_save == 32
1177 && info->first_fp_reg_save == 64
00b960c7 1178 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1179 && ! info->lr_save_p
1180 && ! info->cr_save_p
00b960c7 1181 && info->vrsave_mask == 0
c81fc13e 1182 && ! info->push_p)
4697a36c
MM
1183 return 1;
1184 }
1185
1186 return 0;
9878760c
RK
1187}
1188
1189/* Returns 1 always. */
1190
1191int
a2369ed3
DJ
1192any_operand (rtx op ATTRIBUTE_UNUSED,
1193 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1194{
1195 return 1;
1196}
1197
a4f6c312 1198/* Returns 1 if op is the count register. */
38c1f2d7 1199int
a2369ed3 1200count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1201{
1202 if (GET_CODE (op) != REG)
1203 return 0;
1204
1205 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1206 return 1;
1207
1208 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1209 return 1;
1210
1211 return 0;
1212}
1213
0ec4e2a8
AH
1214/* Returns 1 if op is an altivec register. */
1215int
a2369ed3 1216altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8
AH
1217{
1218
1219 return (register_operand (op, mode)
1220 && (GET_CODE (op) != REG
1221 || REGNO (op) > FIRST_PSEUDO_REGISTER
1222 || ALTIVEC_REGNO_P (REGNO (op))));
1223}
1224
38c1f2d7 1225int
a2369ed3 1226xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1227{
1228 if (GET_CODE (op) != REG)
1229 return 0;
1230
9ebbca7d 1231 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1232 return 1;
1233
802a0058
MM
1234 return 0;
1235}
1236
c859cda6 1237/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1238 by such constants completes more quickly. */
c859cda6
DJ
1239
1240int
a2369ed3 1241s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6
DJ
1242{
1243 return ( GET_CODE (op) == CONST_INT
1244 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1245}
1246
9878760c
RK
1247/* Return 1 if OP is a constant that can fit in a D field. */
1248
1249int
a2369ed3 1250short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1251{
5f59ecb7
DE
1252 return (GET_CODE (op) == CONST_INT
1253 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1254}
1255
5519a4f9 1256/* Similar for an unsigned D field. */
9878760c
RK
1257
1258int
a2369ed3 1259u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1260{
19684119 1261 return (GET_CODE (op) == CONST_INT
c1f11548 1262 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1263}
1264
dcfedcd0
RK
1265/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1266
1267int
a2369ed3 1268non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1269{
1270 return (GET_CODE (op) == CONST_INT
a7653a2c 1271 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1272}
1273
2bfcf297
DB
1274/* Returns 1 if OP is a CONST_INT that is a positive value
1275 and an exact power of 2. */
1276
1277int
a2369ed3 1278exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1279{
1280 return (GET_CODE (op) == CONST_INT
1281 && INTVAL (op) > 0
1282 && exact_log2 (INTVAL (op)) >= 0);
1283}
1284
9878760c
RK
1285/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1286 ctr, or lr). */
1287
1288int
a2369ed3 1289gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1290{
1291 return (register_operand (op, mode)
802a0058 1292 && (GET_CODE (op) != REG
9ebbca7d
GK
1293 || (REGNO (op) >= ARG_POINTER_REGNUM
1294 && !XER_REGNO_P (REGNO (op)))
1295 || REGNO (op) < MQ_REGNO));
9878760c
RK
1296}
1297
1298/* Returns 1 if OP is either a pseudo-register or a register denoting a
1299 CR field. */
1300
1301int
a2369ed3 1302cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1303{
1304 return (register_operand (op, mode)
1305 && (GET_CODE (op) != REG
1306 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1307 || CR_REGNO_P (REGNO (op))));
1308}
1309
815cdc52
MM
1310/* Returns 1 if OP is either a pseudo-register or a register denoting a
1311 CR field that isn't CR0. */
1312
1313int
a2369ed3 1314cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1315{
1316 return (register_operand (op, mode)
1317 && (GET_CODE (op) != REG
1318 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1319 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1320}
1321
a4f6c312
SS
1322/* Returns 1 if OP is either a constant integer valid for a D-field or
1323 a non-special register. If a register, it must be in the proper
1324 mode unless MODE is VOIDmode. */
9878760c
RK
1325
1326int
a2369ed3 1327reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1328{
f5a28898 1329 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1330}
1331
a4f6c312
SS
1332/* Similar, except check if the negation of the constant would be
1333 valid for a D-field. */
9878760c
RK
1334
1335int
a2369ed3 1336reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1337{
1338 if (GET_CODE (op) == CONST_INT)
1339 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1340
cd2b37d9 1341 return gpc_reg_operand (op, mode);
9878760c
RK
1342}
1343
768070a0
TR
1344/* Returns 1 if OP is either a constant integer valid for a DS-field or
1345 a non-special register. If a register, it must be in the proper
1346 mode unless MODE is VOIDmode. */
1347
1348int
a2369ed3 1349reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1350{
1351 if (gpc_reg_operand (op, mode))
1352 return 1;
1353 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1354 return 1;
1355
1356 return 0;
1357}
1358
1359
a4f6c312
SS
1360/* Return 1 if the operand is either a register or an integer whose
1361 high-order 16 bits are zero. */
9878760c
RK
1362
1363int
a2369ed3 1364reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1365{
e675f625 1366 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1367}
1368
1369/* Return 1 is the operand is either a non-special register or ANY
1370 constant integer. */
1371
1372int
a2369ed3 1373reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1374{
a4f6c312 1375 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1376}
1377
1378/* Return 1 is the operand is either a non-special register or ANY
1379 32-bit signed constant integer. */
1380
1381int
a2369ed3 1382reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1383{
a4f6c312
SS
1384 return (gpc_reg_operand (op, mode)
1385 || (GET_CODE (op) == CONST_INT
f6bf7de2 1386#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1387 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1388 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1389#endif
a4f6c312 1390 ));
9878760c
RK
1391}
1392
2bfcf297
DB
1393/* Return 1 is the operand is either a non-special register or a 32-bit
1394 signed constant integer valid for 64-bit addition. */
1395
1396int
a2369ed3 1397reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1398{
a4f6c312
SS
1399 return (gpc_reg_operand (op, mode)
1400 || (GET_CODE (op) == CONST_INT
a65c591c 1401#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1402 && INTVAL (op) < 0x7fff8000
a65c591c 1403#else
a4f6c312
SS
1404 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1405 < 0x100000000ll)
2bfcf297 1406#endif
a4f6c312 1407 ));
2bfcf297
DB
1408}
1409
1410/* Return 1 is the operand is either a non-special register or a 32-bit
1411 signed constant integer valid for 64-bit subtraction. */
1412
1413int
a2369ed3 1414reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1415{
a4f6c312
SS
1416 return (gpc_reg_operand (op, mode)
1417 || (GET_CODE (op) == CONST_INT
a65c591c 1418#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1419 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1420#else
a4f6c312
SS
1421 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1422 < 0x100000000ll)
2bfcf297 1423#endif
a4f6c312 1424 ));
2bfcf297
DB
1425}
1426
9ebbca7d
GK
1427/* Return 1 is the operand is either a non-special register or ANY
1428 32-bit unsigned constant integer. */
1429
1430int
a2369ed3 1431reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1432{
1d328b19
GK
1433 if (GET_CODE (op) == CONST_INT)
1434 {
1435 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1436 {
1437 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1438 abort ();
1d328b19
GK
1439
1440 if (INTVAL (op) < 0)
1441 return 0;
1442 }
1443
1444 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1445 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1446 }
1447 else if (GET_CODE (op) == CONST_DOUBLE)
1448 {
1449 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1450 || mode != DImode)
a4f6c312 1451 abort ();
1d328b19
GK
1452
1453 return CONST_DOUBLE_HIGH (op) == 0;
1454 }
1455 else
1456 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1457}
1458
51d3e7d6 1459/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1460
1461int
a2369ed3 1462got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
1463{
1464 return (GET_CODE (op) == SYMBOL_REF
1465 || GET_CODE (op) == CONST
1466 || GET_CODE (op) == LABEL_REF);
1467}
1468
38c1f2d7
MM
1469/* Return 1 if the operand is a simple references that can be loaded via
1470 the GOT (labels involving addition aren't allowed). */
1471
1472int
a2369ed3 1473got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
1474{
1475 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1476}
1477
4e74d8ec
MM
1478/* Return the number of instructions it takes to form a constant in an
1479 integer register. */
1480
1481static int
a2369ed3 1482num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
1483{
1484 /* signed constant loadable with {cal|addi} */
5f59ecb7 1485 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1486 return 1;
1487
4e74d8ec 1488 /* constant loadable with {cau|addis} */
5f59ecb7 1489 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1490 return 1;
1491
5f59ecb7 1492#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1493 else if (TARGET_POWERPC64)
4e74d8ec 1494 {
a65c591c
DE
1495 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1496 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1497
a65c591c 1498 if (high == 0 || high == -1)
4e74d8ec
MM
1499 return 2;
1500
a65c591c 1501 high >>= 1;
4e74d8ec 1502
a65c591c 1503 if (low == 0)
4e74d8ec 1504 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1505 else
1506 return (num_insns_constant_wide (high)
e396202a 1507 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1508 }
1509#endif
1510
1511 else
1512 return 2;
1513}
1514
1515int
a2369ed3 1516num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 1517{
4e74d8ec 1518 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1519 {
1520#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1521 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1522 && mask64_operand (op, mode))
0d30d435
DE
1523 return 2;
1524 else
1525#endif
1526 return num_insns_constant_wide (INTVAL (op));
1527 }
4e74d8ec 1528
6fc48950
MM
1529 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1530 {
1531 long l;
1532 REAL_VALUE_TYPE rv;
1533
1534 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1535 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1536 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1537 }
1538
47ad8c61 1539 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1540 {
47ad8c61
MM
1541 HOST_WIDE_INT low;
1542 HOST_WIDE_INT high;
1543 long l[2];
1544 REAL_VALUE_TYPE rv;
1545 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1546
47ad8c61
MM
1547 if (mode == VOIDmode || mode == DImode)
1548 {
1549 high = CONST_DOUBLE_HIGH (op);
1550 low = CONST_DOUBLE_LOW (op);
1551 }
1552 else
1553 {
1554 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1555 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1556 high = l[endian];
1557 low = l[1 - endian];
1558 }
4e74d8ec 1559
47ad8c61
MM
1560 if (TARGET_32BIT)
1561 return (num_insns_constant_wide (low)
1562 + num_insns_constant_wide (high));
4e74d8ec
MM
1563
1564 else
47ad8c61 1565 {
e72247f4 1566 if (high == 0 && low >= 0)
47ad8c61
MM
1567 return num_insns_constant_wide (low);
1568
e72247f4 1569 else if (high == -1 && low < 0)
47ad8c61
MM
1570 return num_insns_constant_wide (low);
1571
a260abc9
DE
1572 else if (mask64_operand (op, mode))
1573 return 2;
1574
47ad8c61
MM
1575 else if (low == 0)
1576 return num_insns_constant_wide (high) + 1;
1577
1578 else
1579 return (num_insns_constant_wide (high)
1580 + num_insns_constant_wide (low) + 1);
1581 }
4e74d8ec
MM
1582 }
1583
1584 else
1585 abort ();
1586}
1587
a4f6c312
SS
1588/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1589 register with one instruction per word. We only do this if we can
1590 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1591
1592int
a2369ed3 1593easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 1594{
9878760c
RK
1595 if (GET_CODE (op) != CONST_DOUBLE
1596 || GET_MODE (op) != mode
4e74d8ec 1597 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1598 return 0;
1599
a4f6c312 1600 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1601 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1602 && mode != DImode)
b6c9286a
MM
1603 return 1;
1604
a4f6c312 1605 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1606 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1607 return 0;
1608
5ae4759c 1609#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1610 /* Similarly if we are using -mrelocatable, consider all constants
1611 to be hard. */
5ae4759c
MM
1612 if (TARGET_RELOCATABLE)
1613 return 0;
1614#endif
1615
fcce224d
DE
1616 if (mode == TFmode)
1617 {
1618 long k[4];
1619 REAL_VALUE_TYPE rv;
1620
1621 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1622 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1623
1624 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1625 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1626 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1627 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1628 }
1629
1630 else if (mode == DFmode)
042259f2
DE
1631 {
1632 long k[2];
1633 REAL_VALUE_TYPE rv;
1634
1635 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1636 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1637
a65c591c
DE
1638 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1639 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1640 }
4e74d8ec
MM
1641
1642 else if (mode == SFmode)
042259f2
DE
1643 {
1644 long l;
1645 REAL_VALUE_TYPE rv;
1646
1647 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1648 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1649
4e74d8ec 1650 return num_insns_constant_wide (l) == 1;
042259f2 1651 }
4e74d8ec 1652
a260abc9 1653 else if (mode == DImode)
c81fc13e 1654 return ((TARGET_POWERPC64
a260abc9
DE
1655 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1656 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1657
a9098fd0
GK
1658 else if (mode == SImode)
1659 return 1;
4e74d8ec
MM
1660 else
1661 abort ();
9878760c 1662}
8f75773e 1663
72ac76be 1664/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
1665
1666static int
a2369ed3 1667easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
1668{
1669 int units, i, cst;
1670
1671 units = CONST_VECTOR_NUNITS (op);
1672
1673 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1674 for (i = 1; i < units; ++i)
1675 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1676 break;
1677 if (i == units)
1678 return 1;
1679 return 0;
1680}
1681
1682/* Return 1 if the operand is a CONST_INT and can be put into a
1683 register without using memory. */
1684
1685int
a2369ed3 1686easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 1687{
d744e06e 1688 int cst, cst2;
69ef87e2 1689
d744e06e
AH
1690 if (GET_CODE (op) != CONST_VECTOR
1691 || (!TARGET_ALTIVEC
1692 && !TARGET_SPE))
69ef87e2
AH
1693 return 0;
1694
d744e06e
AH
1695 if (zero_constant (op, mode)
1696 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1697 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1698 return 1;
69ef87e2 1699
d744e06e
AH
1700 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1701 return 0;
1702
f5119d10
AH
1703 if (TARGET_SPE && mode == V1DImode)
1704 return 0;
1705
d744e06e
AH
1706 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1707 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1708
1709 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1710 li r0, CONSTANT1
1711 evmergelo r0, r0, r0
1712 li r0, CONSTANT2
1713
1714 I don't know how efficient it would be to allow bigger constants,
1715 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1716 instructions is better than a 64-bit memory load, but I don't
1717 have the e500 timing specs. */
1718 if (TARGET_SPE && mode == V2SImode
1719 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 1720 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
1721 return 1;
1722
ce1f50b2
HP
1723 if (TARGET_ALTIVEC)
1724 switch (mode)
1725 {
1726 case V4SImode:
1727 if (EASY_VECTOR_15 (cst, op, mode))
1728 return 1;
1729 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
1730 break;
1731 cst = cst >> 16;
1732 case V8HImode:
1733 if (EASY_VECTOR_15 (cst, op, mode))
1734 return 1;
1735 if ((cst & 0xff) != ((cst >> 8) & 0xff))
1736 break;
1737 cst = cst >> 8;
1738 case V16QImode:
1739 if (EASY_VECTOR_15 (cst, op, mode))
1740 return 1;
1741 default:
1742 break;
1743 }
d744e06e
AH
1744
1745 if (TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode))
1746 return 1;
1747
1748 return 0;
1749}
1750
1751/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1752
1753int
a2369ed3 1754easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
1755{
1756 int cst;
1757
1758 if (!easy_vector_constant (op, mode))
1759 return 0;
1760
1761 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1762
1763 return TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode);
1764}
1765
1766const char *
a2369ed3 1767output_vec_const_move (rtx *operands)
d744e06e
AH
1768{
1769 int cst, cst2;
1770 enum machine_mode mode;
1771 rtx dest, vec;
1772
1773 dest = operands[0];
1774 vec = operands[1];
69ef87e2 1775
d744e06e
AH
1776 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1777 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1778 mode = GET_MODE (dest);
69ef87e2 1779
d744e06e
AH
1780 if (TARGET_ALTIVEC)
1781 {
1782 if (zero_constant (vec, mode))
1783 return "vxor %0,%0,%0";
ce1f50b2
HP
1784 else if (EASY_VECTOR_15_ADD_SELF (cst, vec, mode))
1785 return "#";
1786 else if (easy_vector_constant (vec, mode))
98ef3137 1787 {
d744e06e
AH
1788 operands[1] = GEN_INT (cst);
1789 switch (mode)
1790 {
1791 case V4SImode:
ce1f50b2
HP
1792 if (EASY_VECTOR_15 (cst, vec, mode))
1793 {
1794 operands[1] = GEN_INT (cst);
1795 return "vspltisw %0,%1";
1796 }
1797 cst = cst >> 16;
d744e06e 1798 case V8HImode:
ce1f50b2
HP
1799 if (EASY_VECTOR_15 (cst, vec, mode))
1800 {
1801 operands[1] = GEN_INT (cst);
1802 return "vspltish %0,%1";
1803 }
1804 cst = cst >> 8;
d744e06e 1805 case V16QImode:
ce1f50b2
HP
1806 if (EASY_VECTOR_15 (cst, vec, mode))
1807 {
1808 operands[1] = GEN_INT (cst);
1809 return "vspltisb %0,%1";
1810 }
d744e06e
AH
1811 default:
1812 abort ();
1813 }
98ef3137 1814 }
d744e06e
AH
1815 else
1816 abort ();
69ef87e2
AH
1817 }
1818
d744e06e
AH
1819 if (TARGET_SPE)
1820 {
1821 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1822 pattern of V1DI, V4HI, and V2SF.
1823
c1207243 1824 FIXME: We should probably return # and add post reload
d744e06e
AH
1825 splitters for these, but this way is so easy ;-).
1826 */
1827 operands[1] = GEN_INT (cst);
1828 operands[2] = GEN_INT (cst2);
1829 if (cst == cst2)
1830 return "li %0,%1\n\tevmergelo %0,%0,%0";
1831 else
1832 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1833 }
1834
1835 abort ();
69ef87e2
AH
1836}
1837
1838/* Return 1 if the operand is the constant 0. This works for scalars
1839 as well as vectors. */
1840int
a2369ed3 1841zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
1842{
1843 return op == CONST0_RTX (mode);
1844}
1845
50a0b056
GK
1846/* Return 1 if the operand is 0.0. */
1847int
a2369ed3 1848zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
1849{
1850 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1851}
1852
a4f6c312
SS
1853/* Return 1 if the operand is in volatile memory. Note that during
1854 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1855 volatile memory references. So this function allows us to
1856 recognize volatile references where its safe. */
1857
1858int
a2369ed3 1859volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
1860{
1861 if (GET_CODE (op) != MEM)
1862 return 0;
1863
1864 if (!MEM_VOLATILE_P (op))
1865 return 0;
1866
1867 if (mode != GET_MODE (op))
1868 return 0;
1869
1870 if (reload_completed)
1871 return memory_operand (op, mode);
1872
1873 if (reload_in_progress)
1874 return strict_memory_address_p (mode, XEXP (op, 0));
1875
1876 return memory_address_p (mode, XEXP (op, 0));
1877}
1878
97f6e72f 1879/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1880
1881int
a2369ed3 1882offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 1883{
97f6e72f 1884 return ((GET_CODE (op) == MEM)
677a9668 1885 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1886 mode, XEXP (op, 0)));
914c2e77
RK
1887}
1888
9878760c
RK
1889/* Return 1 if the operand is either an easy FP constant (see above) or
1890 memory. */
1891
1892int
a2369ed3 1893mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
1894{
1895 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1896}
1897
1898/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1899 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1900
1901int
a2369ed3 1902add_operand (rtx op, enum machine_mode mode)
9878760c 1903{
2bfcf297 1904 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1905 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1906 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1907
1908 return gpc_reg_operand (op, mode);
9878760c
RK
1909}
1910
dcfedcd0
RK
1911/* Return 1 if OP is a constant but not a valid add_operand. */
1912
1913int
a2369ed3 1914non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1915{
1916 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1917 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1918 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1919}
1920
9878760c
RK
1921/* Return 1 if the operand is a non-special register or a constant that
1922 can be used as the operand of an OR or XOR insn on the RS/6000. */
1923
1924int
a2369ed3 1925logical_operand (rtx op, enum machine_mode mode)
9878760c 1926{
40501e5f 1927 HOST_WIDE_INT opl, oph;
1d328b19 1928
dfbdccdb
GK
1929 if (gpc_reg_operand (op, mode))
1930 return 1;
1d328b19 1931
dfbdccdb 1932 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1933 {
1934 opl = INTVAL (op) & GET_MODE_MASK (mode);
1935
1936#if HOST_BITS_PER_WIDE_INT <= 32
1937 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1938 return 0;
1939#endif
1940 }
dfbdccdb
GK
1941 else if (GET_CODE (op) == CONST_DOUBLE)
1942 {
1d328b19 1943 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1944 abort ();
1d328b19
GK
1945
1946 opl = CONST_DOUBLE_LOW (op);
1947 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1948 if (oph != 0)
38886f37 1949 return 0;
dfbdccdb
GK
1950 }
1951 else
1952 return 0;
1d328b19 1953
40501e5f
AM
1954 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1955 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1956}
1957
dcfedcd0 1958/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1959 above), but could be split into one. */
dcfedcd0
RK
1960
1961int
a2369ed3 1962non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 1963{
dfbdccdb 1964 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1965 && ! logical_operand (op, mode)
1966 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1967}
1968
19ba8161 1969/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1970 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1971 Reject all ones and all zeros, since these should have been optimized
1972 away and confuse the making of MB and ME. */
1973
1974int
a2369ed3 1975mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1976{
02071907 1977 HOST_WIDE_INT c, lsb;
9878760c 1978
19ba8161
DE
1979 if (GET_CODE (op) != CONST_INT)
1980 return 0;
1981
1982 c = INTVAL (op);
1983
57deb3a1
AM
1984 /* Fail in 64-bit mode if the mask wraps around because the upper
1985 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1986 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1987 return 0;
1988
c5059423
AM
1989 /* We don't change the number of transitions by inverting,
1990 so make sure we start with the LS bit zero. */
1991 if (c & 1)
1992 c = ~c;
1993
1994 /* Reject all zeros or all ones. */
1995 if (c == 0)
9878760c
RK
1996 return 0;
1997
c5059423
AM
1998 /* Find the first transition. */
1999 lsb = c & -c;
2000
2001 /* Invert to look for a second transition. */
2002 c = ~c;
9878760c 2003
c5059423
AM
2004 /* Erase first transition. */
2005 c &= -lsb;
9878760c 2006
c5059423
AM
2007 /* Find the second transition (if any). */
2008 lsb = c & -c;
2009
2010 /* Match if all the bits above are 1's (or c is zero). */
2011 return c == -lsb;
9878760c
RK
2012}
2013
0ba1b2ff
AM
2014/* Return 1 for the PowerPC64 rlwinm corner case. */
2015
2016int
a2369ed3 2017mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2018{
2019 HOST_WIDE_INT c, lsb;
2020
2021 if (GET_CODE (op) != CONST_INT)
2022 return 0;
2023
2024 c = INTVAL (op);
2025
2026 if ((c & 0x80000001) != 0x80000001)
2027 return 0;
2028
2029 c = ~c;
2030 if (c == 0)
2031 return 0;
2032
2033 lsb = c & -c;
2034 c = ~c;
2035 c &= -lsb;
2036 lsb = c & -c;
2037 return c == -lsb;
2038}
2039
a260abc9
DE
2040/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2041 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2042 Reject all zeros, since zero should have been optimized away and
2043 confuses the making of MB and ME. */
9878760c
RK
2044
2045int
a2369ed3 2046mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2047{
2048 if (GET_CODE (op) == CONST_INT)
2049 {
02071907 2050 HOST_WIDE_INT c, lsb;
a260abc9 2051
c5059423 2052 c = INTVAL (op);
a260abc9 2053
0ba1b2ff 2054 /* Reject all zeros. */
c5059423 2055 if (c == 0)
e2c953b6
DE
2056 return 0;
2057
0ba1b2ff
AM
2058 /* We don't change the number of transitions by inverting,
2059 so make sure we start with the LS bit zero. */
2060 if (c & 1)
2061 c = ~c;
2062
c5059423
AM
2063 /* Find the transition, and check that all bits above are 1's. */
2064 lsb = c & -c;
e3981aab
DE
2065
2066 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2067 return c == -lsb;
e2c953b6 2068 }
0ba1b2ff
AM
2069 return 0;
2070}
2071
2072/* Like mask64_operand, but allow up to three transitions. This
2073 predicate is used by insn patterns that generate two rldicl or
2074 rldicr machine insns. */
2075
2076int
a2369ed3 2077mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2078{
2079 if (GET_CODE (op) == CONST_INT)
a260abc9 2080 {
0ba1b2ff 2081 HOST_WIDE_INT c, lsb;
a260abc9 2082
0ba1b2ff 2083 c = INTVAL (op);
a260abc9 2084
0ba1b2ff
AM
2085 /* Disallow all zeros. */
2086 if (c == 0)
2087 return 0;
a260abc9 2088
0ba1b2ff
AM
2089 /* We don't change the number of transitions by inverting,
2090 so make sure we start with the LS bit zero. */
2091 if (c & 1)
2092 c = ~c;
a260abc9 2093
0ba1b2ff
AM
2094 /* Find the first transition. */
2095 lsb = c & -c;
a260abc9 2096
0ba1b2ff
AM
2097 /* Invert to look for a second transition. */
2098 c = ~c;
2099
2100 /* Erase first transition. */
2101 c &= -lsb;
2102
2103 /* Find the second transition. */
2104 lsb = c & -c;
2105
2106 /* Invert to look for a third transition. */
2107 c = ~c;
2108
2109 /* Erase second transition. */
2110 c &= -lsb;
2111
2112 /* Find the third transition (if any). */
2113 lsb = c & -c;
2114
2115 /* Match if all the bits above are 1's (or c is zero). */
2116 return c == -lsb;
2117 }
2118 return 0;
2119}
2120
2121/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2122 implement ANDing by the mask IN. */
2123void
a2369ed3 2124build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2125{
2126#if HOST_BITS_PER_WIDE_INT >= 64
2127 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2128 int shift;
2129
2130 if (GET_CODE (in) != CONST_INT)
2131 abort ();
2132
2133 c = INTVAL (in);
2134 if (c & 1)
2135 {
2136 /* Assume c initially something like 0x00fff000000fffff. The idea
2137 is to rotate the word so that the middle ^^^^^^ group of zeros
2138 is at the MS end and can be cleared with an rldicl mask. We then
2139 rotate back and clear off the MS ^^ group of zeros with a
2140 second rldicl. */
2141 c = ~c; /* c == 0xff000ffffff00000 */
2142 lsb = c & -c; /* lsb == 0x0000000000100000 */
2143 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2144 c = ~c; /* c == 0x00fff000000fffff */
2145 c &= -lsb; /* c == 0x00fff00000000000 */
2146 lsb = c & -c; /* lsb == 0x0000100000000000 */
2147 c = ~c; /* c == 0xff000fffffffffff */
2148 c &= -lsb; /* c == 0xff00000000000000 */
2149 shift = 0;
2150 while ((lsb >>= 1) != 0)
2151 shift++; /* shift == 44 on exit from loop */
2152 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2153 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2154 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2155 }
2156 else
0ba1b2ff
AM
2157 {
2158 /* Assume c initially something like 0xff000f0000000000. The idea
2159 is to rotate the word so that the ^^^ middle group of zeros
2160 is at the LS end and can be cleared with an rldicr mask. We then
2161 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2162 a second rldicr. */
2163 lsb = c & -c; /* lsb == 0x0000010000000000 */
2164 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2165 c = ~c; /* c == 0x00fff0ffffffffff */
2166 c &= -lsb; /* c == 0x00fff00000000000 */
2167 lsb = c & -c; /* lsb == 0x0000100000000000 */
2168 c = ~c; /* c == 0xff000fffffffffff */
2169 c &= -lsb; /* c == 0xff00000000000000 */
2170 shift = 0;
2171 while ((lsb >>= 1) != 0)
2172 shift++; /* shift == 44 on exit from loop */
2173 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2174 m1 >>= shift; /* m1 == 0x0000000000000fff */
2175 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2176 }
2177
2178 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2179 masks will be all 1's. We are guaranteed more than one transition. */
2180 out[0] = GEN_INT (64 - shift);
2181 out[1] = GEN_INT (m1);
2182 out[2] = GEN_INT (shift);
2183 out[3] = GEN_INT (m2);
2184#else
045572c7
GK
2185 (void)in;
2186 (void)out;
0ba1b2ff
AM
2187 abort ();
2188#endif
a260abc9
DE
2189}
2190
2191/* Return 1 if the operand is either a non-special register or a constant
2192 that can be used as the operand of a PowerPC64 logical AND insn. */
2193
2194int
a2369ed3 2195and64_operand (rtx op, enum machine_mode mode)
9878760c 2196{
a4f6c312 2197 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2198 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2199
2200 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2201}
2202
0ba1b2ff
AM
2203/* Like the above, but also match constants that can be implemented
2204 with two rldicl or rldicr insns. */
2205
2206int
a2369ed3 2207and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2208{
a3c9585f 2209 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2210 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2211
2212 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2213}
2214
a260abc9
DE
2215/* Return 1 if the operand is either a non-special register or a
2216 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2217
2218int
a2369ed3 2219and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2220{
a4f6c312 2221 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2222 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2223
2224 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2225}
2226
9878760c
RK
2227/* Return 1 if the operand is a general register or memory operand. */
2228
2229int
a2369ed3 2230reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2231{
b6c9286a
MM
2232 return (gpc_reg_operand (op, mode)
2233 || memory_operand (op, mode)
4c81e946 2234 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2235 || volatile_mem_operand (op, mode));
9878760c
RK
2236}
2237
a7a813f7 2238/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2239 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2240 instruction. */
2241
2242int
a2369ed3 2243lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2244{
2245 rtx inner = op;
2246
2247 if (reload_completed && GET_CODE (inner) == SUBREG)
2248 inner = SUBREG_REG (inner);
2249
2250 return gpc_reg_operand (inner, mode)
2251 || (memory_operand (inner, mode)
2252 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2253 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2254 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2255 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2256 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2257}
2258
cc4d5fec
JH
2259/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2260
2261int
a2369ed3 2262symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2263{
2264 if (mode != VOIDmode && GET_MODE (op) != mode)
2265 return 0;
2266
aa6d25c9
AP
2267#if TARGET_MACHO
2268 if (GET_CODE (op) == SYMBOL_REF && TARGET_MACHO && MACHOPIC_INDIRECT)
2269 {
2270 /* Macho says it has to go through a stub or be local
2271 when indirect mode. Stubs are considered local. */
2272 const char *t = XSTR (op, 0);
2273 /* "&" means that it is it a local defined symbol
2274 so it is okay to call to. */
2275 if (t[0] == '&')
2276 return true;
2277
2278 /* "!T" means that the function is local defined. */
2279 return (t[0] == '!' && t[1] == 'T');
2280 }
2281#endif
2282
2283
473f51b6
DE
2284 return (GET_CODE (op) == SYMBOL_REF
2285 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2286}
2287
9878760c 2288/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2289 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2290
2291int
a2369ed3 2292call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2293{
2294 if (mode != VOIDmode && GET_MODE (op) != mode)
2295 return 0;
2296
2297 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2298 || (GET_CODE (op) == REG
2299 && (REGNO (op) == LINK_REGISTER_REGNUM
2300 || REGNO (op) == COUNT_REGISTER_REGNUM
2301 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2302}
2303
2af3d377 2304/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2305 this file. */
2af3d377
RK
2306
2307int
a2369ed3
DJ
2308current_file_function_operand (rtx op,
2309 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2310{
473f51b6
DE
2311 return (GET_CODE (op) == SYMBOL_REF
2312 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2313 && (SYMBOL_REF_LOCAL_P (op)
2314 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2315}
2316
9878760c
RK
2317/* Return 1 if this operand is a valid input for a move insn. */
2318
2319int
a2369ed3 2320input_operand (rtx op, enum machine_mode mode)
9878760c 2321{
eb4e8003 2322 /* Memory is always valid. */
9878760c
RK
2323 if (memory_operand (op, mode))
2324 return 1;
2325
34792e82 2326 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 2327 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
2328 return 1;
2329
eb4e8003
RK
2330 /* For floating-point, easy constants are valid. */
2331 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2332 && CONSTANT_P (op)
2333 && easy_fp_constant (op, mode))
2334 return 1;
2335
4e74d8ec
MM
2336 /* Allow any integer constant. */
2337 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2338 && (GET_CODE (op) == CONST_INT
e675f625 2339 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2340 return 1;
2341
d744e06e
AH
2342 /* Allow easy vector constants. */
2343 if (GET_CODE (op) == CONST_VECTOR
2344 && easy_vector_constant (op, mode))
2345 return 1;
2346
eb4e8003
RK
2347 /* For floating-point or multi-word mode, the only remaining valid type
2348 is a register. */
9878760c
RK
2349 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2350 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2351 return register_operand (op, mode);
9878760c 2352
88fe15a1
RK
2353 /* The only cases left are integral modes one word or smaller (we
2354 do not get called for MODE_CC values). These can be in any
2355 register. */
2356 if (register_operand (op, mode))
a8b3aeda 2357 return 1;
88fe15a1 2358
84cf9dda 2359 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2360 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2361 return 1;
2362
9ebbca7d 2363 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2364 if (toc_relative_expr_p (op))
b6c9286a
MM
2365 return 1;
2366
88228c4b
MM
2367 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2368 to be valid. */
f607bc57 2369 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2370 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2371 && small_data_operand (op, Pmode))
2372 return 1;
2373
042259f2 2374 return 0;
9878760c 2375}
7509c759 2376
95727fb8
AP
2377
2378/* Darwin, AIX increases natural record alignment to doubleword if the first
2379 field is an FP double while the FP fields remain word aligned. */
2380
19d66194 2381unsigned int
95727fb8
AP
2382rs6000_special_round_type_align (tree type, int computed, int specified)
2383{
2384 tree field = TYPE_FIELDS (type);
95727fb8
AP
2385
2386 /* Skip all the static variables only if ABI is greater than
71cc389b 2387 1 or equal to 0. */
3ce5437a 2388 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2389 field = TREE_CHAIN (field);
2390
3ce5437a 2391 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2392 return MAX (computed, specified);
2393
2394 return MAX (MAX (computed, specified), 64);
2395}
2396
a4f6c312 2397/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2398
2399int
a2369ed3
DJ
2400small_data_operand (rtx op ATTRIBUTE_UNUSED,
2401 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2402{
38c1f2d7 2403#if TARGET_ELF
5f59ecb7 2404 rtx sym_ref;
7509c759 2405
d9407988 2406 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2407 return 0;
a54d04b7 2408
f607bc57 2409 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2410 return 0;
2411
88228c4b
MM
2412 if (GET_CODE (op) == SYMBOL_REF)
2413 sym_ref = op;
2414
2415 else if (GET_CODE (op) != CONST
2416 || GET_CODE (XEXP (op, 0)) != PLUS
2417 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2418 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2419 return 0;
2420
88228c4b 2421 else
dbf55e53
MM
2422 {
2423 rtx sum = XEXP (op, 0);
2424 HOST_WIDE_INT summand;
2425
2426 /* We have to be careful here, because it is the referenced address
2427 that must be 32k from _SDA_BASE_, not just the symbol. */
2428 summand = INTVAL (XEXP (sum, 1));
307b599c 2429 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2430 return 0;
2431
2432 sym_ref = XEXP (sum, 0);
2433 }
88228c4b 2434
20bfcd69 2435 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2436#else
2437 return 0;
2438#endif
7509c759 2439}
46c07df8 2440
d2288d5d
HP
2441/* Return true, if operand is a memory operand and has a
2442 displacement divisible by 4. */
2443
2444int
2445word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2446{
2447 rtx addr;
2448 int off = 0;
2449
2450 if (!memory_operand (op, mode))
2451 return 0;
2452
2453 addr = XEXP (op, 0);
2454 if (GET_CODE (addr) == PLUS
2455 && GET_CODE (XEXP (addr, 0)) == REG
2456 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2457 off = INTVAL (XEXP (addr, 1));
2458
2459 return (off % 4) == 0;
2460}
2461
3a1f863f 2462/* Return true if either operand is a general purpose register. */
46c07df8 2463
3a1f863f
DE
2464bool
2465gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 2466{
3a1f863f
DE
2467 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2468 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
2469}
2470
9ebbca7d 2471\f
4d588c14
RH
2472/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2473
9ebbca7d 2474static int
a2369ed3 2475constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d
GK
2476{
2477 switch (GET_CODE(op))
2478 {
2479 case SYMBOL_REF:
c4501e62
JJ
2480 if (RS6000_SYMBOL_REF_TLS_P (op))
2481 return 0;
2482 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2483 {
2484 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2485 {
2486 *have_sym = 1;
2487 return 1;
2488 }
2489 else
2490 return 0;
2491 }
2492 else if (! strcmp (XSTR (op, 0), toc_label_name))
2493 {
2494 *have_toc = 1;
2495 return 1;
2496 }
2497 else
2498 return 0;
9ebbca7d
GK
2499 case PLUS:
2500 case MINUS:
c1f11548
DE
2501 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2502 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2503 case CONST:
a4f6c312 2504 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2505 case CONST_INT:
a4f6c312 2506 return 1;
9ebbca7d 2507 default:
a4f6c312 2508 return 0;
9ebbca7d
GK
2509 }
2510}
2511
4d588c14 2512static bool
a2369ed3 2513constant_pool_expr_p (rtx op)
9ebbca7d
GK
2514{
2515 int have_sym = 0;
2516 int have_toc = 0;
2517 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2518}
2519
4d588c14 2520static bool
a2369ed3 2521toc_relative_expr_p (rtx op)
9ebbca7d 2522{
4d588c14
RH
2523 int have_sym = 0;
2524 int have_toc = 0;
2525 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2526}
2527
2528/* SPE offset addressing is limited to 5-bits worth of double words. */
2529#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2530
2531bool
a2369ed3 2532legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
2533{
2534 return (TARGET_TOC
2535 && GET_CODE (x) == PLUS
2536 && GET_CODE (XEXP (x, 0)) == REG
2537 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2538 && constant_pool_expr_p (XEXP (x, 1)));
2539}
2540
2541static bool
a2369ed3 2542legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
2543{
2544 return (DEFAULT_ABI == ABI_V4
2545 && !flag_pic && !TARGET_TOC
2546 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2547 && small_data_operand (x, mode));
2548}
2549
2550static bool
a2369ed3 2551legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2552{
2553 unsigned HOST_WIDE_INT offset, extra;
2554
2555 if (GET_CODE (x) != PLUS)
2556 return false;
2557 if (GET_CODE (XEXP (x, 0)) != REG)
2558 return false;
2559 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2560 return false;
2561 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2562 return false;
2563
2564 offset = INTVAL (XEXP (x, 1));
2565 extra = 0;
2566 switch (mode)
2567 {
2568 case V16QImode:
2569 case V8HImode:
2570 case V4SFmode:
2571 case V4SImode:
2572 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2573 which leaves the only valid constant offset of zero, which by
2574 canonicalization rules is also invalid. */
2575 return false;
2576
2577 case V4HImode:
2578 case V2SImode:
2579 case V1DImode:
2580 case V2SFmode:
2581 /* SPE vector modes. */
2582 return SPE_CONST_OFFSET_OK (offset);
2583
2584 case DFmode:
2585 case DImode:
3364872d 2586 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
2587 extra = 4;
2588 else if (offset & 3)
2589 return false;
2590 break;
2591
2592 case TFmode:
2593 case TImode:
3364872d 2594 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
2595 extra = 12;
2596 else if (offset & 3)
2597 return false;
2598 else
2599 extra = 8;
2600 break;
2601
2602 default:
2603 break;
2604 }
2605
b1917422
AM
2606 offset += 0x8000;
2607 return (offset < 0x10000) && (offset + extra < 0x10000);
4d588c14
RH
2608}
2609
2610static bool
a2369ed3 2611legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
2612{
2613 rtx op0, op1;
2614
2615 if (GET_CODE (x) != PLUS)
2616 return false;
2617 op0 = XEXP (x, 0);
2618 op1 = XEXP (x, 1);
2619
2620 if (!REG_P (op0) || !REG_P (op1))
2621 return false;
2622
2623 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2624 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2625 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2626 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2627}
2628
4d588c14 2629static inline bool
a2369ed3 2630legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
2631{
2632 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2633}
2634
4c81e946
FJ
2635static bool
2636macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
2637{
2638 if (!TARGET_MACHO || !flag_pic
2639 || mode != SImode || GET_CODE(x) != MEM)
2640 return false;
2641 x = XEXP (x, 0);
2642
2643 if (GET_CODE (x) != LO_SUM)
2644 return false;
2645 if (GET_CODE (XEXP (x, 0)) != REG)
2646 return false;
2647 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
2648 return false;
2649 x = XEXP (x, 1);
2650
2651 return CONSTANT_P (x);
2652}
2653
4d588c14 2654static bool
a2369ed3 2655legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2656{
2657 if (GET_CODE (x) != LO_SUM)
2658 return false;
2659 if (GET_CODE (XEXP (x, 0)) != REG)
2660 return false;
2661 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2662 return false;
2663 x = XEXP (x, 1);
2664
8622e235 2665 if (TARGET_ELF || TARGET_MACHO)
4d588c14 2666 {
a29077da 2667 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
2668 return false;
2669 if (TARGET_TOC)
2670 return false;
2671 if (GET_MODE_NUNITS (mode) != 1)
2672 return false;
2673 if (GET_MODE_BITSIZE (mode) > 32
2674 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2675 return false;
2676
2677 return CONSTANT_P (x);
2678 }
2679
2680 return false;
2681}
2682
2683
9ebbca7d
GK
2684/* Try machine-dependent ways of modifying an illegitimate address
2685 to be legitimate. If we find one, return the new, valid address.
2686 This is used from only one place: `memory_address' in explow.c.
2687
a4f6c312
SS
2688 OLDX is the address as it was before break_out_memory_refs was
2689 called. In some cases it is useful to look at this to decide what
2690 needs to be done.
9ebbca7d 2691
a4f6c312 2692 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2693
a4f6c312
SS
2694 It is always safe for this function to do nothing. It exists to
2695 recognize opportunities to optimize the output.
9ebbca7d
GK
2696
2697 On RS/6000, first check for the sum of a register with a constant
2698 integer that is out of range. If so, generate code to add the
2699 constant with the low-order 16 bits masked to the register and force
2700 this result into another register (this can be done with `cau').
2701 Then generate an address of REG+(CONST&0xffff), allowing for the
2702 possibility of bit 16 being a one.
2703
2704 Then check for the sum of a register and something not constant, try to
2705 load the other things into a register and return the sum. */
4d588c14 2706
9ebbca7d 2707rtx
a2369ed3
DJ
2708rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2709 enum machine_mode mode)
0ac081f6 2710{
c4501e62
JJ
2711 if (GET_CODE (x) == SYMBOL_REF)
2712 {
2713 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2714 if (model != 0)
2715 return rs6000_legitimize_tls_address (x, model);
2716 }
2717
9ebbca7d
GK
2718 if (GET_CODE (x) == PLUS
2719 && GET_CODE (XEXP (x, 0)) == REG
2720 && GET_CODE (XEXP (x, 1)) == CONST_INT
2721 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2722 {
2723 HOST_WIDE_INT high_int, low_int;
2724 rtx sum;
a65c591c
DE
2725 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2726 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2727 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2728 GEN_INT (high_int)), 0);
2729 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2730 }
2731 else if (GET_CODE (x) == PLUS
2732 && GET_CODE (XEXP (x, 0)) == REG
2733 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2734 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2735 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2736 || TARGET_POWERPC64
fcce224d 2737 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2738 && (TARGET_POWERPC64 || mode != DImode)
2739 && mode != TImode)
2740 {
2741 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2742 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2743 }
0ac081f6
AH
2744 else if (ALTIVEC_VECTOR_MODE (mode))
2745 {
2746 rtx reg;
2747
2748 /* Make sure both operands are registers. */
2749 if (GET_CODE (x) == PLUS)
9f85ed45 2750 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2751 force_reg (Pmode, XEXP (x, 1)));
2752
2753 reg = force_reg (Pmode, x);
2754 return reg;
2755 }
a3170dc6
AH
2756 else if (SPE_VECTOR_MODE (mode))
2757 {
2758 /* We accept [reg + reg] and [reg + OFFSET]. */
2759
2760 if (GET_CODE (x) == PLUS)
2761 {
2762 rtx op1 = XEXP (x, 0);
2763 rtx op2 = XEXP (x, 1);
2764
2765 op1 = force_reg (Pmode, op1);
2766
2767 if (GET_CODE (op2) != REG
2768 && (GET_CODE (op2) != CONST_INT
2769 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2770 op2 = force_reg (Pmode, op2);
2771
2772 return gen_rtx_PLUS (Pmode, op1, op2);
2773 }
2774
2775 return force_reg (Pmode, x);
2776 }
f1384257
AM
2777 else if (TARGET_ELF
2778 && TARGET_32BIT
2779 && TARGET_NO_TOC
2780 && ! flag_pic
9ebbca7d
GK
2781 && GET_CODE (x) != CONST_INT
2782 && GET_CODE (x) != CONST_DOUBLE
2783 && CONSTANT_P (x)
6ac7bf2c
GK
2784 && GET_MODE_NUNITS (mode) == 1
2785 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2786 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2787 {
2788 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2789 emit_insn (gen_elf_high (reg, x));
2790 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 2791 }
ee890fe2
SS
2792 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2793 && ! flag_pic
ab82a49f
AP
2794#if TARGET_MACHO
2795 && ! MACHO_DYNAMIC_NO_PIC_P
2796#endif
ee890fe2
SS
2797 && GET_CODE (x) != CONST_INT
2798 && GET_CODE (x) != CONST_DOUBLE
2799 && CONSTANT_P (x)
a3170dc6 2800 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2801 && mode != DImode
2802 && mode != TImode)
2803 {
2804 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2805 emit_insn (gen_macho_high (reg, x));
2806 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 2807 }
9ebbca7d 2808 else if (TARGET_TOC
4d588c14 2809 && constant_pool_expr_p (x)
a9098fd0 2810 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2811 {
2812 return create_TOC_reference (x);
2813 }
2814 else
2815 return NULL_RTX;
2816}
258bfae2 2817
c973d557
JJ
2818/* This is called from dwarf2out.c via ASM_OUTPUT_DWARF_DTPREL.
2819 We need to emit DTP-relative relocations. */
2820
2821void
2822rs6000_output_dwarf_dtprel (FILE *file, int size, rtx x)
2823{
2824 switch (size)
2825 {
2826 case 4:
2827 fputs ("\t.long\t", file);
2828 break;
2829 case 8:
2830 fputs (DOUBLE_INT_ASM_OP, file);
2831 break;
2832 default:
2833 abort ();
2834 }
2835 output_addr_const (file, x);
2836 fputs ("@dtprel+0x8000", file);
2837}
2838
c4501e62
JJ
2839/* Construct the SYMBOL_REF for the tls_get_addr function. */
2840
2841static GTY(()) rtx rs6000_tls_symbol;
2842static rtx
863d938c 2843rs6000_tls_get_addr (void)
c4501e62
JJ
2844{
2845 if (!rs6000_tls_symbol)
2846 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2847
2848 return rs6000_tls_symbol;
2849}
2850
2851/* Construct the SYMBOL_REF for TLS GOT references. */
2852
2853static GTY(()) rtx rs6000_got_symbol;
2854static rtx
863d938c 2855rs6000_got_sym (void)
c4501e62
JJ
2856{
2857 if (!rs6000_got_symbol)
2858 {
2859 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2860 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2861 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2862 }
2863
2864 return rs6000_got_symbol;
2865}
2866
2867/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2868 this (thread-local) address. */
2869
2870static rtx
a2369ed3 2871rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
2872{
2873 rtx dest, insn;
2874
2875 dest = gen_reg_rtx (Pmode);
2876 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2877 {
2878 rtx tlsreg;
2879
2880 if (TARGET_64BIT)
2881 {
2882 tlsreg = gen_rtx_REG (Pmode, 13);
2883 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2884 }
2885 else
2886 {
2887 tlsreg = gen_rtx_REG (Pmode, 2);
2888 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2889 }
2890 emit_insn (insn);
2891 }
2892 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2893 {
2894 rtx tlsreg, tmp;
2895
2896 tmp = gen_reg_rtx (Pmode);
2897 if (TARGET_64BIT)
2898 {
2899 tlsreg = gen_rtx_REG (Pmode, 13);
2900 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2901 }
2902 else
2903 {
2904 tlsreg = gen_rtx_REG (Pmode, 2);
2905 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2906 }
2907 emit_insn (insn);
2908 if (TARGET_64BIT)
2909 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
2910 else
2911 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
2912 emit_insn (insn);
2913 }
2914 else
2915 {
2916 rtx r3, got, tga, tmp1, tmp2, eqv;
2917
2918 if (TARGET_64BIT)
2919 got = gen_rtx_REG (Pmode, TOC_REGISTER);
2920 else
2921 {
2922 if (flag_pic == 1)
2923 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
2924 else
2925 {
2926 rtx gsym = rs6000_got_sym ();
2927 got = gen_reg_rtx (Pmode);
2928 if (flag_pic == 0)
2929 rs6000_emit_move (got, gsym, Pmode);
2930 else
2931 {
2932 char buf[30];
2933 static int tls_got_labelno = 0;
2934 rtx tempLR, lab, tmp3, mem;
2935 rtx first, last;
2936
2937 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
2938 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
2939 tempLR = gen_reg_rtx (Pmode);
2940 tmp1 = gen_reg_rtx (Pmode);
2941 tmp2 = gen_reg_rtx (Pmode);
2942 tmp3 = gen_reg_rtx (Pmode);
2943 mem = gen_rtx_MEM (Pmode, tmp1);
2944 RTX_UNCHANGING_P (mem) = 1;
2945
2946 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
2947 gsym));
2948 emit_move_insn (tmp1, tempLR);
2949 emit_move_insn (tmp2, mem);
2950 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
2951 last = emit_move_insn (got, tmp3);
2952 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
2953 REG_NOTES (last));
2954 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
2955 REG_NOTES (first));
2956 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
2957 REG_NOTES (last));
2958 }
2959 }
2960 }
2961
2962 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
2963 {
2964 r3 = gen_rtx_REG (Pmode, 3);
2965 if (TARGET_64BIT)
2966 insn = gen_tls_gd_64 (r3, got, addr);
2967 else
2968 insn = gen_tls_gd_32 (r3, got, addr);
2969 start_sequence ();
2970 emit_insn (insn);
2971 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2972 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2973 insn = emit_call_insn (insn);
2974 CONST_OR_PURE_CALL_P (insn) = 1;
2975 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2976 insn = get_insns ();
2977 end_sequence ();
2978 emit_libcall_block (insn, dest, r3, addr);
2979 }
2980 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
2981 {
2982 r3 = gen_rtx_REG (Pmode, 3);
2983 if (TARGET_64BIT)
2984 insn = gen_tls_ld_64 (r3, got);
2985 else
2986 insn = gen_tls_ld_32 (r3, got);
2987 start_sequence ();
2988 emit_insn (insn);
2989 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2990 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2991 insn = emit_call_insn (insn);
2992 CONST_OR_PURE_CALL_P (insn) = 1;
2993 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2994 insn = get_insns ();
2995 end_sequence ();
2996 tmp1 = gen_reg_rtx (Pmode);
2997 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2998 UNSPEC_TLSLD);
2999 emit_libcall_block (insn, tmp1, r3, eqv);
3000 if (rs6000_tls_size == 16)
3001 {
3002 if (TARGET_64BIT)
3003 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
3004 else
3005 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
3006 }
3007 else if (rs6000_tls_size == 32)
3008 {
3009 tmp2 = gen_reg_rtx (Pmode);
3010 if (TARGET_64BIT)
3011 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
3012 else
3013 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
3014 emit_insn (insn);
3015 if (TARGET_64BIT)
3016 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
3017 else
3018 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
3019 }
3020 else
3021 {
3022 tmp2 = gen_reg_rtx (Pmode);
3023 if (TARGET_64BIT)
3024 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
3025 else
3026 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
3027 emit_insn (insn);
3028 insn = gen_rtx_SET (Pmode, dest,
3029 gen_rtx_PLUS (Pmode, tmp2, tmp1));
3030 }
3031 emit_insn (insn);
3032 }
3033 else
3034 {
3035 /* IE, or 64 bit offset LE. */
3036 tmp2 = gen_reg_rtx (Pmode);
3037 if (TARGET_64BIT)
3038 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
3039 else
3040 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
3041 emit_insn (insn);
3042 if (TARGET_64BIT)
3043 insn = gen_tls_tls_64 (dest, tmp2, addr);
3044 else
3045 insn = gen_tls_tls_32 (dest, tmp2, addr);
3046 emit_insn (insn);
3047 }
3048 }
3049
3050 return dest;
3051}
3052
3053/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
3054 instruction definitions. */
3055
3056int
a2369ed3 3057rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
3058{
3059 return RS6000_SYMBOL_REF_TLS_P (x);
3060}
3061
3062/* Return 1 if X contains a thread-local symbol. */
3063
3064bool
a2369ed3 3065rs6000_tls_referenced_p (rtx x)
c4501e62 3066{
cd413cab
AP
3067 if (! TARGET_HAVE_TLS)
3068 return false;
3069
c4501e62
JJ
3070 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
3071}
3072
3073/* Return 1 if *X is a thread-local symbol. This is the same as
3074 rs6000_tls_symbol_ref except for the type of the unused argument. */
3075
3076static inline int
a2369ed3 3077rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
3078{
3079 return RS6000_SYMBOL_REF_TLS_P (*x);
3080}
3081
24ea750e
DJ
3082/* The convention appears to be to define this wherever it is used.
3083 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3084 is now used here. */
3085#ifndef REG_MODE_OK_FOR_BASE_P
3086#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3087#endif
3088
3089/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3090 replace the input X, or the original X if no replacement is called for.
3091 The output parameter *WIN is 1 if the calling macro should goto WIN,
3092 0 if it should not.
3093
3094 For RS/6000, we wish to handle large displacements off a base
3095 register by splitting the addend across an addiu/addis and the mem insn.
3096 This cuts number of extra insns needed from 3 to 1.
3097
3098 On Darwin, we use this to generate code for floating point constants.
3099 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3100 The Darwin code is inside #if TARGET_MACHO because only then is
3101 machopic_function_base_name() defined. */
3102rtx
a2369ed3
DJ
3103rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
3104 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e
DJ
3105{
3106 /* We must recognize output that we have already generated ourselves. */
3107 if (GET_CODE (x) == PLUS
3108 && GET_CODE (XEXP (x, 0)) == PLUS
3109 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3110 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3111 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3112 {
3113 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3114 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3115 opnum, (enum reload_type)type);
3116 *win = 1;
3117 return x;
3118 }
3deb2758 3119
24ea750e
DJ
3120#if TARGET_MACHO
3121 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3122 && GET_CODE (x) == LO_SUM
3123 && GET_CODE (XEXP (x, 0)) == PLUS
3124 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3125 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3126 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3127 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3128 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3129 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3130 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3131 {
3132 /* Result of previous invocation of this function on Darwin
6f317ef3 3133 floating point constant. */
24ea750e
DJ
3134 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3135 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3136 opnum, (enum reload_type)type);
3137 *win = 1;
3138 return x;
3139 }
3140#endif
3141 if (GET_CODE (x) == PLUS
3142 && GET_CODE (XEXP (x, 0)) == REG
3143 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3144 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3145 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3146 && !SPE_VECTOR_MODE (mode)
78c875e8 3147 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3148 {
3149 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3150 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3151 HOST_WIDE_INT high
3152 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3153
3154 /* Check for 32-bit overflow. */
3155 if (high + low != val)
3156 {
3157 *win = 0;
3158 return x;
3159 }
3160
3161 /* Reload the high part into a base reg; leave the low part
3162 in the mem directly. */
3163
3164 x = gen_rtx_PLUS (GET_MODE (x),
3165 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3166 GEN_INT (high)),
3167 GEN_INT (low));
3168
3169 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3170 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3171 opnum, (enum reload_type)type);
3172 *win = 1;
3173 return x;
3174 }
3175#if TARGET_MACHO
3176 if (GET_CODE (x) == SYMBOL_REF
3177 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3178 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3179 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3180 /* Don't do this for TFmode, since the result isn't offsettable. */
3181 && mode != TFmode)
24ea750e 3182 {
a29077da
GK
3183 if (flag_pic)
3184 {
3185 rtx offset = gen_rtx_CONST (Pmode,
3186 gen_rtx_MINUS (Pmode, x,
3187 gen_rtx_SYMBOL_REF (Pmode,
3188 machopic_function_base_name ())));
3189 x = gen_rtx_LO_SUM (GET_MODE (x),
3190 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3191 gen_rtx_HIGH (Pmode, offset)), offset);
3192 }
3193 else
3194 x = gen_rtx_LO_SUM (GET_MODE (x),
3195 gen_rtx_HIGH (Pmode, x), x);
3196
24ea750e 3197 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3198 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3199 opnum, (enum reload_type)type);
24ea750e
DJ
3200 *win = 1;
3201 return x;
3202 }
3203#endif
3204 if (TARGET_TOC
4d588c14 3205 && constant_pool_expr_p (x)
c1f11548 3206 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3207 {
3208 (x) = create_TOC_reference (x);
3209 *win = 1;
3210 return x;
3211 }
3212 *win = 0;
3213 return x;
3214}
3215
258bfae2
FS
3216/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3217 that is a valid memory address for an instruction.
3218 The MODE argument is the machine mode for the MEM expression
3219 that wants to use this address.
3220
3221 On the RS/6000, there are four valid address: a SYMBOL_REF that
3222 refers to a constant pool entry of an address (or the sum of it
3223 plus a constant), a short (16-bit signed) constant plus a register,
3224 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3225 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3226 we must ensure that both words are addressable or PowerPC64 with offset
3227 word aligned.
3228
3229 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3230 32-bit DImode, TImode), indexed addressing cannot be used because
3231 adjacent memory cells are accessed by adding word-sized offsets
3232 during assembly output. */
3233int
a2369ed3 3234rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3235{
c4501e62
JJ
3236 if (RS6000_SYMBOL_REF_TLS_P (x))
3237 return 0;
4d588c14 3238 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3239 return 1;
3240 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3241 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3242 && !SPE_VECTOR_MODE (mode)
258bfae2 3243 && TARGET_UPDATE
4d588c14 3244 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3245 return 1;
4d588c14 3246 if (legitimate_small_data_p (mode, x))
258bfae2 3247 return 1;
4d588c14 3248 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3249 return 1;
3250 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3251 if (! reg_ok_strict
3252 && GET_CODE (x) == PLUS
3253 && GET_CODE (XEXP (x, 0)) == REG
3254 && XEXP (x, 0) == virtual_stack_vars_rtx
3255 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3256 return 1;
4d588c14 3257 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3258 return 1;
3259 if (mode != TImode
a3170dc6
AH
3260 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3261 || TARGET_POWERPC64
fcce224d 3262 || (mode != DFmode && mode != TFmode))
258bfae2 3263 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3264 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3265 return 1;
4d588c14 3266 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3267 return 1;
3268 return 0;
3269}
4d588c14
RH
3270
3271/* Go to LABEL if ADDR (a legitimate address expression)
3272 has an effect that depends on the machine mode it is used for.
3273
3274 On the RS/6000 this is true of all integral offsets (since AltiVec
3275 modes don't allow them) or is a pre-increment or decrement.
3276
3277 ??? Except that due to conceptual problems in offsettable_address_p
3278 we can't really report the problems of integral offsets. So leave
3279 this assuming that the adjustable offset must be valid for the
3280 sub-words of a TFmode operand, which is what we had before. */
3281
3282bool
a2369ed3 3283rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3284{
3285 switch (GET_CODE (addr))
3286 {
3287 case PLUS:
3288 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3289 {
3290 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3291 return val + 12 + 0x8000 >= 0x10000;
3292 }
3293 break;
3294
3295 case LO_SUM:
3296 return true;
3297
3298 case PRE_INC:
3299 case PRE_DEC:
3300 return TARGET_UPDATE;
3301
3302 default:
3303 break;
3304 }
3305
3306 return false;
3307}
fb4d4348 3308\f
a4f6c312
SS
3309/* Try to output insns to set TARGET equal to the constant C if it can
3310 be done in less than N insns. Do all computations in MODE.
3311 Returns the place where the output has been placed if it can be
3312 done and the insns have been emitted. If it would take more than N
3313 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3314
3315rtx
a2369ed3
DJ
3316rs6000_emit_set_const (rtx dest, enum machine_mode mode,
3317 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3318{
af8cb5c5 3319 rtx result, insn, set;
2bfcf297
DB
3320 HOST_WIDE_INT c0, c1;
3321
af8cb5c5 3322 if (mode == QImode || mode == HImode)
2bfcf297
DB
3323 {
3324 if (dest == NULL)
3325 dest = gen_reg_rtx (mode);
3326 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3327 return dest;
3328 }
af8cb5c5 3329 else if (mode == SImode)
2bfcf297 3330 {
af8cb5c5
DE
3331 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3332
3333 emit_insn (gen_rtx_SET (VOIDmode, result,
3334 GEN_INT (INTVAL (source)
3335 & (~ (HOST_WIDE_INT) 0xffff))));
3336 emit_insn (gen_rtx_SET (VOIDmode, dest,
3337 gen_rtx_IOR (SImode, result,
3338 GEN_INT (INTVAL (source) & 0xffff))));
3339 result = dest;
2bfcf297 3340 }
af8cb5c5 3341 else if (mode == DImode)
2bfcf297 3342 {
af8cb5c5
DE
3343 if (GET_CODE (source) == CONST_INT)
3344 {
3345 c0 = INTVAL (source);
3346 c1 = -(c0 < 0);
3347 }
3348 else if (GET_CODE (source) == CONST_DOUBLE)
3349 {
2bfcf297 3350#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3351 c0 = CONST_DOUBLE_LOW (source);
3352 c1 = -(c0 < 0);
2bfcf297 3353#else
af8cb5c5
DE
3354 c0 = CONST_DOUBLE_LOW (source);
3355 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3356#endif
af8cb5c5
DE
3357 }
3358 else
3359 abort ();
3360
3361 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3362 }
3363 else
a4f6c312 3364 abort ();
2bfcf297 3365
af8cb5c5
DE
3366 insn = get_last_insn ();
3367 set = single_set (insn);
3368 if (! CONSTANT_P (SET_SRC (set)))
3369 set_unique_reg_note (insn, REG_EQUAL, source);
3370
3371 return result;
2bfcf297
DB
3372}
3373
3374/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3375 fall back to a straight forward decomposition. We do this to avoid
3376 exponential run times encountered when looking for longer sequences
3377 with rs6000_emit_set_const. */
3378static rtx
a2369ed3 3379rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
3380{
3381 if (!TARGET_POWERPC64)
3382 {
3383 rtx operand1, operand2;
3384
3385 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3386 DImode);
3387 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3388 DImode);
3389 emit_move_insn (operand1, GEN_INT (c1));
3390 emit_move_insn (operand2, GEN_INT (c2));
3391 }
3392 else
3393 {
bc06712d 3394 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3395
bc06712d 3396 ud1 = c1 & 0xffff;
f921c9c9 3397 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3398#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3399 c2 = c1 >> 32;
2bfcf297 3400#endif
bc06712d 3401 ud3 = c2 & 0xffff;
f921c9c9 3402 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3403
bc06712d
TR
3404 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3405 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3406 {
bc06712d 3407 if (ud1 & 0x8000)
b78d48dd 3408 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
3409 else
3410 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3411 }
2bfcf297 3412
bc06712d
TR
3413 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3414 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3415 {
bc06712d
TR
3416 if (ud2 & 0x8000)
3417 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3418 - 0x80000000));
252b88f7 3419 else
bc06712d
TR
3420 emit_move_insn (dest, GEN_INT (ud2 << 16));
3421 if (ud1 != 0)
3422 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3423 }
bc06712d
TR
3424 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3425 || (ud4 == 0 && ! (ud3 & 0x8000)))
3426 {
3427 if (ud3 & 0x8000)
3428 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3429 - 0x80000000));
3430 else
3431 emit_move_insn (dest, GEN_INT (ud3 << 16));
3432
3433 if (ud2 != 0)
3434 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3435 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3436 if (ud1 != 0)
3437 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3438 }
3439 else
3440 {
3441 if (ud4 & 0x8000)
3442 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3443 - 0x80000000));
3444 else
3445 emit_move_insn (dest, GEN_INT (ud4 << 16));
3446
3447 if (ud3 != 0)
3448 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3449
bc06712d
TR
3450 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3451 if (ud2 != 0)
3452 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3453 GEN_INT (ud2 << 16)));
3454 if (ud1 != 0)
3455 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3456 }
3457 }
2bfcf297
DB
3458 return dest;
3459}
3460
fb4d4348
GK
3461/* Emit a move from SOURCE to DEST in mode MODE. */
3462void
a2369ed3 3463rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
3464{
3465 rtx operands[2];
3466 operands[0] = dest;
3467 operands[1] = source;
3468
3469 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3470 if (GET_CODE (operands[1]) == CONST_DOUBLE
3471 && ! FLOAT_MODE_P (mode)
3472 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3473 {
3474 /* FIXME. This should never happen. */
3475 /* Since it seems that it does, do the safe thing and convert
3476 to a CONST_INT. */
2496c7bd 3477 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3478 }
3479 if (GET_CODE (operands[1]) == CONST_DOUBLE
3480 && ! FLOAT_MODE_P (mode)
3481 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3482 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3483 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3484 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3485 abort ();
c9e8cb32
DD
3486
3487 /* Check if GCC is setting up a block move that will end up using FP
3488 registers as temporaries. We must make sure this is acceptable. */
3489 if (GET_CODE (operands[0]) == MEM
3490 && GET_CODE (operands[1]) == MEM
3491 && mode == DImode
41543739
GK
3492 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3493 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3494 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3495 ? 32 : MEM_ALIGN (operands[0])))
3496 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3497 ? 32
3498 : MEM_ALIGN (operands[1]))))
3499 && ! MEM_VOLATILE_P (operands [0])
3500 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3501 {
41543739
GK
3502 emit_move_insn (adjust_address (operands[0], SImode, 0),
3503 adjust_address (operands[1], SImode, 0));
3504 emit_move_insn (adjust_address (operands[0], SImode, 4),
3505 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3506 return;
3507 }
630d42a0 3508
67cef334
DE
3509 if (!no_new_pseudos)
3510 {
3511 if (GET_CODE (operands[1]) == MEM && optimize > 0
3512 && (mode == QImode || mode == HImode || mode == SImode)
3513 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3514 {
3515 rtx reg = gen_reg_rtx (word_mode);
3516
3517 emit_insn (gen_rtx_SET (word_mode, reg,
3518 gen_rtx_ZERO_EXTEND (word_mode,
3519 operands[1])));
3520 operands[1] = gen_lowpart (mode, reg);
3521 }
3522 if (GET_CODE (operands[0]) != REG)
3523 operands[1] = force_reg (mode, operands[1]);
3524 }
a9098fd0 3525
a3170dc6
AH
3526 if (mode == SFmode && ! TARGET_POWERPC
3527 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3528 && GET_CODE (operands[0]) == MEM)
fb4d4348 3529 {
ffc14f31
GK
3530 int regnum;
3531
3532 if (reload_in_progress || reload_completed)
3533 regnum = true_regnum (operands[1]);
3534 else if (GET_CODE (operands[1]) == REG)
3535 regnum = REGNO (operands[1]);
3536 else
3537 regnum = -1;
fb4d4348
GK
3538
3539 /* If operands[1] is a register, on POWER it may have
3540 double-precision data in it, so truncate it to single
3541 precision. */
3542 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3543 {
3544 rtx newreg;
3545 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3546 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3547 operands[1] = newreg;
3548 }
3549 }
3550
c4501e62
JJ
3551 /* Recognize the case where operand[1] is a reference to thread-local
3552 data and load its address to a register. */
3553 if (GET_CODE (operands[1]) == SYMBOL_REF)
3554 {
3555 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3556 if (model != 0)
3557 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3558 }
3559
8f4e6caf
RH
3560 /* Handle the case where reload calls us with an invalid address. */
3561 if (reload_in_progress && mode == Pmode
69ef87e2 3562 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3563 || ! nonimmediate_operand (operands[0], mode)))
3564 goto emit_set;
3565
3566 /* Handle the case of CONSTANT_P_RTX. */
3567 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3568 goto emit_set;
a9baceb1
GK
3569
3570 /* 128-bit constant floating-point values on Darwin should really be
3571 loaded as two parts. */
3572 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
3573 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
3574 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
3575 {
3576 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
3577 know how to get a DFmode SUBREG of a TFmode. */
3578 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
3579 simplify_gen_subreg (DImode, operands[1], mode, 0),
3580 DImode);
3581 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
3582 GET_MODE_SIZE (DImode)),
3583 simplify_gen_subreg (DImode, operands[1], mode,
3584 GET_MODE_SIZE (DImode)),
3585 DImode);
3586 return;
3587 }
3588
fb4d4348
GK
3589 /* FIXME: In the long term, this switch statement should go away
3590 and be replaced by a sequence of tests based on things like
3591 mode == Pmode. */
3592 switch (mode)
3593 {
3594 case HImode:
3595 case QImode:
3596 if (CONSTANT_P (operands[1])
3597 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3598 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3599 break;
3600
06f4e019 3601 case TFmode:
fb4d4348
GK
3602 case DFmode:
3603 case SFmode:
3604 if (CONSTANT_P (operands[1])
3605 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3606 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3607 break;
3608
0ac081f6
AH
3609 case V16QImode:
3610 case V8HImode:
3611 case V4SFmode:
3612 case V4SImode:
a3170dc6
AH
3613 case V4HImode:
3614 case V2SFmode:
3615 case V2SImode:
00a892b8 3616 case V1DImode:
69ef87e2 3617 if (CONSTANT_P (operands[1])
d744e06e 3618 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3619 operands[1] = force_const_mem (mode, operands[1]);
3620 break;
3621
fb4d4348 3622 case SImode:
a9098fd0 3623 case DImode:
fb4d4348
GK
3624 /* Use default pattern for address of ELF small data */
3625 if (TARGET_ELF
a9098fd0 3626 && mode == Pmode
f607bc57 3627 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3628 && (GET_CODE (operands[1]) == SYMBOL_REF
3629 || GET_CODE (operands[1]) == CONST)
3630 && small_data_operand (operands[1], mode))
fb4d4348
GK
3631 {
3632 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3633 return;
3634 }
3635
f607bc57 3636 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3637 && mode == Pmode && mode == SImode
3638 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3639 {
3640 emit_insn (gen_movsi_got (operands[0], operands[1]));
3641 return;
3642 }
3643
ee890fe2 3644 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3645 && TARGET_NO_TOC
3646 && ! flag_pic
a9098fd0 3647 && mode == Pmode
fb4d4348
GK
3648 && CONSTANT_P (operands[1])
3649 && GET_CODE (operands[1]) != HIGH
3650 && GET_CODE (operands[1]) != CONST_INT)
3651 {
a9098fd0 3652 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3653
3654 /* If this is a function address on -mcall-aixdesc,
3655 convert it to the address of the descriptor. */
3656 if (DEFAULT_ABI == ABI_AIX
3657 && GET_CODE (operands[1]) == SYMBOL_REF
3658 && XSTR (operands[1], 0)[0] == '.')
3659 {
3660 const char *name = XSTR (operands[1], 0);
3661 rtx new_ref;
3662 while (*name == '.')
3663 name++;
3664 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3665 CONSTANT_POOL_ADDRESS_P (new_ref)
3666 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3667 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3668 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3669 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3670 operands[1] = new_ref;
3671 }
7509c759 3672
ee890fe2
SS
3673 if (DEFAULT_ABI == ABI_DARWIN)
3674 {
ab82a49f
AP
3675#if TARGET_MACHO
3676 if (MACHO_DYNAMIC_NO_PIC_P)
3677 {
3678 /* Take care of any required data indirection. */
3679 operands[1] = rs6000_machopic_legitimize_pic_address (
3680 operands[1], mode, operands[0]);
3681 if (operands[0] != operands[1])
3682 emit_insn (gen_rtx_SET (VOIDmode,
3683 operands[0], operands[1]));
3684 return;
3685 }
3686#endif
ee890fe2
SS
3687 emit_insn (gen_macho_high (target, operands[1]));
3688 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3689 return;
3690 }
3691
fb4d4348
GK
3692 emit_insn (gen_elf_high (target, operands[1]));
3693 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3694 return;
3695 }
3696
a9098fd0
GK
3697 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3698 and we have put it in the TOC, we just need to make a TOC-relative
3699 reference to it. */
3700 if (TARGET_TOC
3701 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3702 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3703 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3704 get_pool_mode (operands[1])))
fb4d4348 3705 {
a9098fd0 3706 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3707 }
a9098fd0
GK
3708 else if (mode == Pmode
3709 && CONSTANT_P (operands[1])
38886f37
AO
3710 && ((GET_CODE (operands[1]) != CONST_INT
3711 && ! easy_fp_constant (operands[1], mode))
3712 || (GET_CODE (operands[1]) == CONST_INT
3713 && num_insns_constant (operands[1], mode) > 2)
3714 || (GET_CODE (operands[0]) == REG
3715 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3716 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3717 && ! legitimate_constant_pool_address_p (operands[1])
3718 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3719 {
3720 /* Emit a USE operation so that the constant isn't deleted if
3721 expensive optimizations are turned on because nobody
3722 references it. This should only be done for operands that
3723 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3724 This should not be done for operands that contain LABEL_REFs.
3725 For now, we just handle the obvious case. */
3726 if (GET_CODE (operands[1]) != LABEL_REF)
3727 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3728
c859cda6 3729#if TARGET_MACHO
ee890fe2 3730 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3731 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3732 {
ee890fe2
SS
3733 operands[1] =
3734 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3735 operands[0]);
3736 if (operands[0] != operands[1])
3737 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3738 return;
3739 }
c859cda6 3740#endif
ee890fe2 3741
fb4d4348
GK
3742 /* If we are to limit the number of things we put in the TOC and
3743 this is a symbol plus a constant we can add in one insn,
3744 just put the symbol in the TOC and add the constant. Don't do
3745 this if reload is in progress. */
3746 if (GET_CODE (operands[1]) == CONST
3747 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3748 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3749 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3750 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3751 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3752 && ! side_effects_p (operands[0]))
3753 {
a4f6c312
SS
3754 rtx sym =
3755 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3756 rtx other = XEXP (XEXP (operands[1], 0), 1);
3757
a9098fd0
GK
3758 sym = force_reg (mode, sym);
3759 if (mode == SImode)
3760 emit_insn (gen_addsi3 (operands[0], sym, other));
3761 else
3762 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3763 return;
3764 }
3765
a9098fd0 3766 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3767
3768 if (TARGET_TOC
4d588c14 3769 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3770 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3771 get_pool_constant (XEXP (operands[1], 0)),
3772 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3773 {
ba4828e0
RK
3774 operands[1]
3775 = gen_rtx_MEM (mode,
3776 create_TOC_reference (XEXP (operands[1], 0)));
3777 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3778 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3779 }
fb4d4348
GK
3780 }
3781 break;
a9098fd0 3782
fb4d4348
GK
3783 case TImode:
3784 if (GET_CODE (operands[0]) == MEM
3785 && GET_CODE (XEXP (operands[0], 0)) != REG
3786 && ! reload_in_progress)
792760b9
RK
3787 operands[0]
3788 = replace_equiv_address (operands[0],
3789 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3790
3791 if (GET_CODE (operands[1]) == MEM
3792 && GET_CODE (XEXP (operands[1], 0)) != REG
3793 && ! reload_in_progress)
792760b9
RK
3794 operands[1]
3795 = replace_equiv_address (operands[1],
3796 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3797 if (TARGET_POWER)
3798 {
3799 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3800 gen_rtvec (2,
3801 gen_rtx_SET (VOIDmode,
3802 operands[0], operands[1]),
3803 gen_rtx_CLOBBER (VOIDmode,
3804 gen_rtx_SCRATCH (SImode)))));
3805 return;
3806 }
fb4d4348
GK
3807 break;
3808
3809 default:
3810 abort ();
3811 }
3812
a9098fd0
GK
3813 /* Above, we may have called force_const_mem which may have returned
3814 an invalid address. If we can, fix this up; otherwise, reload will
3815 have to deal with it. */
8f4e6caf
RH
3816 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
3817 operands[1] = validize_mem (operands[1]);
a9098fd0 3818
8f4e6caf 3819 emit_set:
fb4d4348
GK
3820 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3821}
4697a36c 3822\f
2858f73a
GK
3823/* Nonzero if we can use a floating-point register to pass this arg. */
3824#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
3825 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
3826 && (CUM)->fregno <= FP_ARG_MAX_REG \
3827 && TARGET_HARD_FLOAT && TARGET_FPRS)
3828
3829/* Nonzero if we can use an AltiVec register to pass this arg. */
3830#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
3831 (ALTIVEC_VECTOR_MODE (MODE) \
3832 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
3833 && TARGET_ALTIVEC_ABI \
83953138 3834 && (NAMED))
2858f73a 3835
c6e8c921
GK
3836/* Return a nonzero value to say to return the function value in
3837 memory, just as large structures are always returned. TYPE will be
3838 the data type of the value, and FNTYPE will be the type of the
3839 function doing the returning, or @code{NULL} for libcalls.
3840
3841 The AIX ABI for the RS/6000 specifies that all structures are
3842 returned in memory. The Darwin ABI does the same. The SVR4 ABI
3843 specifies that structures <= 8 bytes are returned in r3/r4, but a
3844 draft put them in memory, and GCC used to implement the draft
3845 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
3846 controls this instead of DEFAULT_ABI; V.4 targets needing backward
3847 compatibility can change DRAFT_V4_STRUCT_RET to override the
3848 default, and -m switches get the final word. See
3849 rs6000_override_options for more details.
3850
3851 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
3852 long double support is enabled. These values are returned in memory.
3853
3854 int_size_in_bytes returns -1 for variable size objects, which go in
3855 memory always. The cast to unsigned makes -1 > 8. */
3856
3857static bool
3858rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
3859{
3860 if (AGGREGATE_TYPE_P (type)
3861 && (TARGET_AIX_STRUCT_RET
3862 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
3863 return true;
3864 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
3865 return true;
3866 return false;
3867}
3868
4697a36c
MM
3869/* Initialize a variable CUM of type CUMULATIVE_ARGS
3870 for a call to a function whose data type is FNTYPE.
3871 For a library call, FNTYPE is 0.
3872
3873 For incoming args we set the number of arguments in the prototype large
1c20ae99 3874 so we never return a PARALLEL. */
4697a36c
MM
3875
3876void
a2369ed3 3877init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
3878 rtx libname ATTRIBUTE_UNUSED, int incoming,
3879 int libcall, int n_named_args)
4697a36c
MM
3880{
3881 static CUMULATIVE_ARGS zero_cumulative;
3882
3883 *cum = zero_cumulative;
3884 cum->words = 0;
3885 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 3886 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 3887 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
3888 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
3889 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 3890 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
3891 cum->stdarg = fntype
3892 && (TYPE_ARG_TYPES (fntype) != 0
3893 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3894 != void_type_node));
4697a36c 3895
0f6937fe
AM
3896 cum->nargs_prototype = 0;
3897 if (incoming || cum->prototype)
3898 cum->nargs_prototype = n_named_args;
4697a36c 3899
a5c76ee6
ZW
3900 /* Check for a longcall attribute. */
3901 if (fntype
3902 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
3903 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
3904 cum->call_cookie = CALL_LONG;
3905
4697a36c
MM
3906 if (TARGET_DEBUG_ARG)
3907 {
3908 fprintf (stderr, "\ninit_cumulative_args:");
3909 if (fntype)
3910 {
3911 tree ret_type = TREE_TYPE (fntype);
3912 fprintf (stderr, " ret code = %s,",
3913 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3914 }
3915
6a4cee5f
MM
3916 if (cum->call_cookie & CALL_LONG)
3917 fprintf (stderr, " longcall,");
3918
4697a36c
MM
3919 fprintf (stderr, " proto = %d, nargs = %d\n",
3920 cum->prototype, cum->nargs_prototype);
3921 }
6d0ef01e
HP
3922
3923 if (fntype
3924 && !TARGET_ALTIVEC
3925 && TARGET_ALTIVEC_ABI
3926 && ALTIVEC_VECTOR_MODE (TYPE_MODE (TREE_TYPE (fntype))))
3927 {
3928 error ("Cannot return value in vector register because"
3929 " altivec instructions are disabled, use -maltivec"
3930 " to enable them.");
3931 }
4697a36c
MM
3932}
3933\f
c229cba9
DE
3934/* If defined, a C expression which determines whether, and in which
3935 direction, to pad out an argument with extra space. The value
3936 should be of type `enum direction': either `upward' to pad above
3937 the argument, `downward' to pad below, or `none' to inhibit
3938 padding.
3939
3940 For the AIX ABI structs are always stored left shifted in their
3941 argument slot. */
3942
9ebbca7d 3943enum direction
a2369ed3 3944function_arg_padding (enum machine_mode mode, tree type)
c229cba9 3945{
6e985040
AM
3946#ifndef AGGREGATE_PADDING_FIXED
3947#define AGGREGATE_PADDING_FIXED 0
3948#endif
3949#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
3950#define AGGREGATES_PAD_UPWARD_ALWAYS 0
3951#endif
3952
3953 if (!AGGREGATE_PADDING_FIXED)
3954 {
3955 /* GCC used to pass structures of the same size as integer types as
3956 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
3957 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
3958 passed padded downward, except that -mstrict-align further
3959 muddied the water in that multi-component structures of 2 and 4
3960 bytes in size were passed padded upward.
3961
3962 The following arranges for best compatibility with previous
3963 versions of gcc, but removes the -mstrict-align dependency. */
3964 if (BYTES_BIG_ENDIAN)
3965 {
3966 HOST_WIDE_INT size = 0;
3967
3968 if (mode == BLKmode)
3969 {
3970 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
3971 size = int_size_in_bytes (type);
3972 }
3973 else
3974 size = GET_MODE_SIZE (mode);
3975
3976 if (size == 1 || size == 2 || size == 4)
3977 return downward;
3978 }
3979 return upward;
3980 }
3981
3982 if (AGGREGATES_PAD_UPWARD_ALWAYS)
3983 {
3984 if (type != 0 && AGGREGATE_TYPE_P (type))
3985 return upward;
3986 }
c229cba9 3987
d3704c46
KH
3988 /* Fall back to the default. */
3989 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
3990}
3991
b6c9286a
MM
3992/* If defined, a C expression that gives the alignment boundary, in bits,
3993 of an argument with the specified mode and type. If it is not defined,
3994 PARM_BOUNDARY is used for all arguments.
3995
2310f99a 3996 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3997
3998int
a2369ed3 3999function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 4000{
f607bc57 4001 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 4002 return 64;
a3170dc6
AH
4003 else if (SPE_VECTOR_MODE (mode))
4004 return 64;
0ac081f6
AH
4005 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4006 return 128;
9ebbca7d 4007 else
b6c9286a 4008 return PARM_BOUNDARY;
b6c9286a 4009}
c53bdcf5
AM
4010
4011/* Compute the size (in words) of a function argument. */
4012
4013static unsigned long
4014rs6000_arg_size (enum machine_mode mode, tree type)
4015{
4016 unsigned long size;
4017
4018 if (mode != BLKmode)
4019 size = GET_MODE_SIZE (mode);
4020 else
4021 size = int_size_in_bytes (type);
4022
4023 if (TARGET_32BIT)
4024 return (size + 3) >> 2;
4025 else
4026 return (size + 7) >> 3;
4027}
b6c9286a 4028\f
4697a36c
MM
4029/* Update the data in CUM to advance over an argument
4030 of mode MODE and data type TYPE.
4031 (TYPE is null for libcalls where that information may not be available.) */
4032
4033void
a2369ed3
DJ
4034function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4035 tree type, int named)
4697a36c
MM
4036{
4037 cum->nargs_prototype--;
4038
0ac081f6
AH
4039 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
4040 {
2858f73a 4041 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
6d0ef01e
HP
4042 {
4043 cum->vregno++;
4044 if (!TARGET_ALTIVEC)
4045 error ("Cannot pass argument in vector register because"
4046 " altivec instructions are disabled, use -maltivec"
4047 " to enable them.");
4048 }
c72d6c26
HP
4049 /* PowerPC64 Linux and AIX allocates GPRs for a vector argument
4050 even if it is going to be passed in a vector register.
4051 Darwin does the same for variable-argument functions. */
4052 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
4053 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
4054 {
a594a19c
GK
4055 int align;
4056
2858f73a
GK
4057 /* Vector parameters must be 16-byte aligned. This places
4058 them at 2 mod 4 in terms of words in 32-bit mode, since
4059 the parameter save area starts at offset 24 from the
4060 stack. In 64-bit mode, they just have to start on an
4061 even word, since the parameter save area is 16-byte
4062 aligned. Space for GPRs is reserved even if the argument
4063 will be passed in memory. */
4064 if (TARGET_32BIT)
4065 align = ((6 - (cum->words & 3)) & 3);
4066 else
4067 align = cum->words & 1;
c53bdcf5 4068 cum->words += align + rs6000_arg_size (mode, type);
2858f73a 4069
a594a19c
GK
4070 if (TARGET_DEBUG_ARG)
4071 {
4072 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
4073 cum->words, align);
4074 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
2858f73a
GK
4075 cum->nargs_prototype, cum->prototype,
4076 GET_MODE_NAME (mode));
a594a19c
GK
4077 }
4078 }
0ac081f6 4079 }
a4b0320c 4080 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4081 && !cum->stdarg
4082 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4083 cum->sysv_gregno++;
f607bc57 4084 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4085 {
a3170dc6 4086 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4087 && (mode == SFmode || mode == DFmode))
4697a36c 4088 {
4cc833b7
RH
4089 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4090 cum->fregno++;
4091 else
4092 {
4093 if (mode == DFmode)
4094 cum->words += cum->words & 1;
c53bdcf5 4095 cum->words += rs6000_arg_size (mode, type);
4cc833b7 4096 }
4697a36c 4097 }
4cc833b7
RH
4098 else
4099 {
4100 int n_words;
4101 int gregno = cum->sysv_gregno;
4102
4103 /* Aggregates and IEEE quad get passed by reference. */
4104 if ((type && AGGREGATE_TYPE_P (type))
4105 || mode == TFmode)
4106 n_words = 1;
4107 else
c53bdcf5 4108 n_words = rs6000_arg_size (mode, type);
4cc833b7 4109
a4b0320c 4110 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4111 if (n_words == 2 && (gregno & 1) == 0)
4112 gregno += 1;
4113
a4b0320c
AH
4114 /* Long long and SPE vectors are not split between registers
4115 and stack. */
4cc833b7
RH
4116 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4117 {
4118 /* Long long is aligned on the stack. */
4119 if (n_words == 2)
4120 cum->words += cum->words & 1;
4121 cum->words += n_words;
4122 }
4697a36c 4123
4cc833b7
RH
4124 /* Note: continuing to accumulate gregno past when we've started
4125 spilling to the stack indicates the fact that we've started
4126 spilling to the stack to expand_builtin_saveregs. */
4127 cum->sysv_gregno = gregno + n_words;
4128 }
4697a36c 4129
4cc833b7
RH
4130 if (TARGET_DEBUG_ARG)
4131 {
4132 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4133 cum->words, cum->fregno);
4134 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4135 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4136 fprintf (stderr, "mode = %4s, named = %d\n",
4137 GET_MODE_NAME (mode), named);
4138 }
4697a36c
MM
4139 }
4140 else
4cc833b7
RH
4141 {
4142 int align = (TARGET_32BIT && (cum->words & 1) != 0
4143 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 4144
c53bdcf5 4145 cum->words += align + rs6000_arg_size (mode, type);
4697a36c 4146
a3170dc6
AH
4147 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4148 && TARGET_HARD_FLOAT && TARGET_FPRS)
c53bdcf5 4149 cum->fregno += (GET_MODE_SIZE (mode) + 7) >> 3;
4cc833b7
RH
4150
4151 if (TARGET_DEBUG_ARG)
4152 {
4153 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4154 cum->words, cum->fregno);
4155 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4156 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4157 fprintf (stderr, "named = %d, align = %d\n", named, align);
4158 }
4159 }
4697a36c 4160}
a6c9bed4
AH
4161
4162/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4163
a6c9bed4 4164static rtx
a2369ed3
DJ
4165rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4166 tree type)
a6c9bed4
AH
4167{
4168 if (cum->stdarg)
4169 {
4170 int gregno = cum->sysv_gregno;
c53bdcf5 4171 int n_words = rs6000_arg_size (mode, type);
a6c9bed4
AH
4172
4173 /* SPE vectors are put in odd registers. */
4174 if (n_words == 2 && (gregno & 1) == 0)
4175 gregno += 1;
4176
4177 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4178 {
4179 rtx r1, r2;
4180 enum machine_mode m = SImode;
4181
4182 r1 = gen_rtx_REG (m, gregno);
4183 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4184 r2 = gen_rtx_REG (m, gregno + 1);
4185 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4186 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4187 }
4188 else
b78d48dd 4189 return NULL_RTX;
a6c9bed4
AH
4190 }
4191 else
4192 {
4193 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4194 return gen_rtx_REG (mode, cum->sysv_gregno);
4195 else
b78d48dd 4196 return NULL_RTX;
a6c9bed4
AH
4197 }
4198}
4199
b78d48dd
FJ
4200/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4201
4202static rtx
4203rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4204 tree type, int align_words)
4205{
4206 if (mode == DFmode)
4207 {
4208 /* -mpowerpc64 with 32bit ABI splits up a DFmode argument
4209 in vararg list into zero, one or two GPRs */
4210 if (align_words >= GP_ARG_NUM_REG)
4211 return gen_rtx_PARALLEL (DFmode,
4212 gen_rtvec (2,
4213 gen_rtx_EXPR_LIST (VOIDmode,
4214 NULL_RTX, const0_rtx),
4215 gen_rtx_EXPR_LIST (VOIDmode,
4216 gen_rtx_REG (mode,
4217 cum->fregno),
4218 const0_rtx)));
c53bdcf5 4219 else if (align_words + rs6000_arg_size (mode, type)
b78d48dd
FJ
4220 > GP_ARG_NUM_REG)
4221 /* If this is partially on the stack, then we only
a3c9585f 4222 include the portion actually in registers here. */
b78d48dd
FJ
4223 return gen_rtx_PARALLEL (DFmode,
4224 gen_rtvec (2,
4225 gen_rtx_EXPR_LIST (VOIDmode,
4226 gen_rtx_REG (SImode,
4227 GP_ARG_MIN_REG
4228 + align_words),
4229 const0_rtx),
4230 gen_rtx_EXPR_LIST (VOIDmode,
4231 gen_rtx_REG (mode,
4232 cum->fregno),
4233 const0_rtx)));
4234
4235 /* split a DFmode arg into two GPRs */
4236 return gen_rtx_PARALLEL (DFmode,
4237 gen_rtvec (3,
4238 gen_rtx_EXPR_LIST (VOIDmode,
4239 gen_rtx_REG (SImode,
4240 GP_ARG_MIN_REG
4241 + align_words),
4242 const0_rtx),
4243 gen_rtx_EXPR_LIST (VOIDmode,
4244 gen_rtx_REG (SImode,
4245 GP_ARG_MIN_REG
4246 + align_words + 1),
4247 GEN_INT (4)),
4248 gen_rtx_EXPR_LIST (VOIDmode,
4249 gen_rtx_REG (mode, cum->fregno),
4250 const0_rtx)));
4251 }
4252 /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one
4253 or two GPRs */
4254 else if (mode == DImode)
4255 {
4256 if (align_words < GP_ARG_NUM_REG - 1)
4257 return gen_rtx_PARALLEL (DImode,
4258 gen_rtvec (2,
4259 gen_rtx_EXPR_LIST (VOIDmode,
4260 gen_rtx_REG (SImode,
4261 GP_ARG_MIN_REG
4262 + align_words),
4263 const0_rtx),
4264 gen_rtx_EXPR_LIST (VOIDmode,
4265 gen_rtx_REG (SImode,
4266 GP_ARG_MIN_REG
4267 + align_words + 1),
4268 GEN_INT (4))));
4269 else if (align_words == GP_ARG_NUM_REG - 1)
4270 return gen_rtx_PARALLEL (DImode,
4271 gen_rtvec (2,
4272 gen_rtx_EXPR_LIST (VOIDmode,
4273 NULL_RTX, const0_rtx),
4274 gen_rtx_EXPR_LIST (VOIDmode,
4275 gen_rtx_REG (SImode,
4276 GP_ARG_MIN_REG
4277 + align_words),
4278 const0_rtx)));
4279 }
4280 else if (mode == BLKmode && align_words <= (GP_ARG_NUM_REG - 1))
4281 {
4282 int k;
4283 int size = int_size_in_bytes (type);
2f7b62ef 4284 int no_units = ((size - 1) / 4) + 1;
b78d48dd
FJ
4285 int max_no_words = GP_ARG_NUM_REG - align_words;
4286 int rtlvec_len = no_units < max_no_words ? no_units : max_no_words;
4287 rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx));
4288
4289 memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx));
4290
4291 for (k=0; k < rtlvec_len; k++)
4292 rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode,
4293 gen_rtx_REG (SImode,
4294 GP_ARG_MIN_REG
4295 + align_words + k),
4296 k == 0 ? const0_rtx : GEN_INT (k*4));
4297
4298 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (k, rtlvec));
4299 }
4300
4301 return NULL_RTX;
4302}
4303
4697a36c
MM
4304/* Determine where to put an argument to a function.
4305 Value is zero to push the argument on the stack,
4306 or a hard register in which to store the argument.
4307
4308 MODE is the argument's machine mode.
4309 TYPE is the data type of the argument (as a tree).
4310 This is null for libcalls where that information may
4311 not be available.
4312 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4313 the preceding args and about the function being called.
4314 NAMED is nonzero if this argument is a named parameter
4315 (otherwise it is an extra parameter matching an ellipsis).
4316
4317 On RS/6000 the first eight words of non-FP are normally in registers
4318 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4319 Under V.4, the first 8 FP args are in registers.
4320
4321 If this is floating-point and no prototype is specified, we use
4322 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4323 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4324 so we can pass the FP value just in one register. emit_library_function
1c20ae99 4325 doesn't support PARALLEL anyway. */
4697a36c
MM
4326
4327struct rtx_def *
a2369ed3
DJ
4328function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4329 tree type, int named)
4697a36c 4330{
4cc833b7 4331 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4332
a4f6c312
SS
4333 /* Return a marker to indicate whether CR1 needs to set or clear the
4334 bit that V.4 uses to say fp args were passed in registers.
4335 Assume that we don't need the marker for software floating point,
4336 or compiler generated library calls. */
4697a36c
MM
4337 if (mode == VOIDmode)
4338 {
f607bc57 4339 if (abi == ABI_V4
7509c759 4340 && cum->nargs_prototype < 0
b9599e46
FS
4341 && (cum->call_cookie & CALL_LIBCALL) == 0
4342 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4343 {
a3170dc6
AH
4344 /* For the SPE, we need to crxor CR6 always. */
4345 if (TARGET_SPE_ABI)
4346 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4347 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4348 return GEN_INT (cum->call_cookie
4349 | ((cum->fregno == FP_ARG_MIN_REG)
4350 ? CALL_V4_SET_FP_ARGS
4351 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4352 }
4697a36c 4353
7509c759 4354 return GEN_INT (cum->call_cookie);
4697a36c
MM
4355 }
4356
2858f73a 4357 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4358 if (TARGET_64BIT && ! cum->prototype)
4359 {
4360 /* Vector parameters get passed in vector register
4361 and also in GPRs or memory, in absence of prototype. */
4362 int align_words;
4363 rtx slot;
4364 align_words = (cum->words + 1) & ~1;
4365
4366 if (align_words >= GP_ARG_NUM_REG)
4367 {
4368 slot = NULL_RTX;
4369 }
4370 else
4371 {
4372 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4373 }
4374 return gen_rtx_PARALLEL (mode,
4375 gen_rtvec (2,
4376 gen_rtx_EXPR_LIST (VOIDmode,
4377 slot, const0_rtx),
4378 gen_rtx_EXPR_LIST (VOIDmode,
4379 gen_rtx_REG (mode, cum->vregno),
4380 const0_rtx)));
4381 }
4382 else
4383 return gen_rtx_REG (mode, cum->vregno);
2858f73a 4384 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4385 {
2858f73a 4386 if (named || abi == ABI_V4)
a594a19c 4387 return NULL_RTX;
0ac081f6 4388 else
a594a19c
GK
4389 {
4390 /* Vector parameters to varargs functions under AIX or Darwin
4391 get passed in memory and possibly also in GPRs. */
4392 int align, align_words;
2858f73a 4393 enum machine_mode part_mode = mode;
a594a19c
GK
4394
4395 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
4396 2 mod 4 in terms of words in 32-bit mode, since the parameter
4397 save area starts at offset 24 from the stack. In 64-bit mode,
4398 they just have to start on an even word, since the parameter
4399 save area is 16-byte aligned. */
4400 if (TARGET_32BIT)
4401 align = ((6 - (cum->words & 3)) & 3);
4402 else
4403 align = cum->words & 1;
a594a19c
GK
4404 align_words = cum->words + align;
4405
4406 /* Out of registers? Memory, then. */
4407 if (align_words >= GP_ARG_NUM_REG)
4408 return NULL_RTX;
4409
2858f73a
GK
4410 /* The vector value goes in GPRs. Only the part of the
4411 value in GPRs is reported here. */
4412 if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS)
4413 > GP_ARG_NUM_REG)
839a4992 4414 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
4415 is either wholly in GPRs or half in GPRs and half not. */
4416 part_mode = DImode;
4417
4418 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 4419 }
0ac081f6 4420 }
a6c9bed4
AH
4421 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4422 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4423 else if (abi == ABI_V4)
4697a36c 4424 {
a3170dc6 4425 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4426 && (mode == SFmode || mode == DFmode))
4427 {
4428 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4429 return gen_rtx_REG (mode, cum->fregno);
4430 else
b78d48dd 4431 return NULL_RTX;
4cc833b7
RH
4432 }
4433 else
4434 {
4435 int n_words;
4436 int gregno = cum->sysv_gregno;
4437
4438 /* Aggregates and IEEE quad get passed by reference. */
4439 if ((type && AGGREGATE_TYPE_P (type))
4440 || mode == TFmode)
4441 n_words = 1;
4442 else
c53bdcf5 4443 n_words = rs6000_arg_size (mode, type);
4cc833b7 4444
a4b0320c 4445 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4446 if (n_words == 2 && (gregno & 1) == 0)
4447 gregno += 1;
4448
c53bdcf5 4449 /* Long long does not split between registers and stack. */
4cc833b7 4450 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4451 return gen_rtx_REG (mode, gregno);
4cc833b7 4452 else
b78d48dd 4453 return NULL_RTX;
4cc833b7 4454 }
4697a36c 4455 }
4cc833b7
RH
4456 else
4457 {
4458 int align = (TARGET_32BIT && (cum->words & 1) != 0
4459 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
4460 int align_words = cum->words + align;
4697a36c 4461
4cc833b7
RH
4462 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4463 return NULL_RTX;
4464
b78d48dd 4465 if (TARGET_32BIT && TARGET_POWERPC64
e91fa876 4466 && (mode == DImode || mode == BLKmode))
b78d48dd
FJ
4467 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4468
2858f73a 4469 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7 4470 {
c53bdcf5
AM
4471 rtx fpr[2];
4472 rtx *r;
4473 bool needs_psave;
4474 enum machine_mode fmode = mode;
4475 int n;
4476 unsigned long n_fpreg = (GET_MODE_SIZE (mode) + 7) >> 3;
4477
4478 if (cum->fregno + n_fpreg > FP_ARG_MAX_REG + 1)
4479 {
4480 /* Long double split over regs and memory. */
4481 if (fmode == TFmode)
4482 fmode = DFmode;
4483
4484 /* Currently, we only ever need one reg here because complex
4485 doubles are split. */
4486 if (cum->fregno != FP_ARG_MAX_REG - 1)
4487 abort ();
4488 }
4489 fpr[1] = gen_rtx_REG (fmode, cum->fregno);
4490
4491 /* Do we also need to pass this arg in the parameter save
4492 area? */
4493 needs_psave = (type
4494 && (cum->nargs_prototype <= 0
4495 || (DEFAULT_ABI == ABI_AIX
4496 && TARGET_XL_CALL
4497 && align_words >= GP_ARG_NUM_REG)));
4498
4499 if (!needs_psave && mode == fmode)
4500 return fpr[1];
4cc833b7 4501
e91fa876
FJ
4502 if (TARGET_32BIT && TARGET_POWERPC64
4503 && mode == DFmode && cum->stdarg)
4504 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4505
c53bdcf5
AM
4506 /* Describe where this piece goes. */
4507 r = fpr + 1;
4508 *r = gen_rtx_EXPR_LIST (VOIDmode, *r, const0_rtx);
4509 n = 1;
4510
4511 if (needs_psave)
4512 {
4513 /* Now describe the part that goes in gprs or the stack.
4514 This piece must come first, before the fprs. */
4515 rtx reg = NULL_RTX;
4516 if (align_words < GP_ARG_NUM_REG)
4517 {
4518 unsigned long n_words = rs6000_arg_size (mode, type);
4519 enum machine_mode rmode = mode;
4520
4521 if (align_words + n_words > GP_ARG_NUM_REG)
4522 /* If this is partially on the stack, then we only
4523 include the portion actually in registers here.
4524 We know this can only be one register because
4525 complex doubles are splt. */
4526 rmode = Pmode;
4527 reg = gen_rtx_REG (rmode, GP_ARG_MIN_REG + align_words);
4528 }
4529 *--r = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx);
4530 ++n;
4531 }
4532
4533 return gen_rtx_PARALLEL (mode, gen_rtvec_v (n, r));
4cc833b7
RH
4534 }
4535 else if (align_words < GP_ARG_NUM_REG)
4536 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4537 else
4538 return NULL_RTX;
4697a36c 4539 }
4697a36c
MM
4540}
4541\f
4542/* For an arg passed partly in registers and partly in memory,
4543 this is the number of registers used.
4544 For args passed entirely in registers or entirely in memory, zero. */
4545
4546int
a2369ed3 4547function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 4548 tree type, int named)
4697a36c 4549{
c53bdcf5
AM
4550 int ret = 0;
4551
f607bc57 4552 if (DEFAULT_ABI == ABI_V4)
4697a36c 4553 return 0;
4697a36c 4554
c53bdcf5
AM
4555 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named)
4556 && cum->nargs_prototype >= 0)
4557 return 0;
4558
4559 if (USE_FP_FOR_ARG_P (cum, mode, type))
4697a36c 4560 {
c53bdcf5
AM
4561 if (cum->fregno + ((GET_MODE_SIZE (mode) + 7) >> 3) > FP_ARG_MAX_REG + 1)
4562 ret = FP_ARG_MAX_REG - cum->fregno;
4563 else if (cum->nargs_prototype >= 0)
4697a36c
MM
4564 return 0;
4565 }
4566
4567 if (cum->words < GP_ARG_NUM_REG
c53bdcf5
AM
4568 && GP_ARG_NUM_REG < cum->words + rs6000_arg_size (mode, type))
4569 ret = GP_ARG_NUM_REG - cum->words;
4697a36c 4570
c53bdcf5
AM
4571 if (ret != 0 && TARGET_DEBUG_ARG)
4572 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4697a36c 4573
c53bdcf5 4574 return ret;
4697a36c
MM
4575}
4576\f
4577/* A C expression that indicates when an argument must be passed by
4578 reference. If nonzero for an argument, a copy of that argument is
4579 made in memory and a pointer to the argument is passed instead of
4580 the argument itself. The pointer is passed in whatever way is
4581 appropriate for passing a pointer to that type.
4582
c8c99a68
DE
4583 Under V.4, structures and unions are passed by reference.
4584
4585 As an extension to all ABIs, variable sized types are passed by
4586 reference. */
4697a36c
MM
4587
4588int
a2369ed3
DJ
4589function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4590 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 4591 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 4592{
f607bc57 4593 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
4594 && ((type && AGGREGATE_TYPE_P (type))
4595 || mode == TFmode))
4697a36c
MM
4596 {
4597 if (TARGET_DEBUG_ARG)
4598 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
4599
4600 return 1;
4601 }
fff2cb99 4602 return type && int_size_in_bytes (type) < 0;
4697a36c 4603}
5985c7a6
FJ
4604
4605static void
2d9db8eb 4606rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
4607{
4608 int i;
4609 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
4610
4611 if (nregs == 0)
4612 return;
4613
4614 for (i = 0; i < nregs; i++)
4615 {
4616 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
4617 if (reload_completed)
4618 {
4619 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
4620 tem = NULL_RTX;
4621 else
4622 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
4623 i * GET_MODE_SIZE(reg_mode));
4624 }
4625 else
4626 tem = replace_equiv_address (tem, XEXP (tem, 0));
4627
4628 if (tem == NULL_RTX)
4629 abort ();
4630
4631 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
4632 }
4633}
4634
4697a36c
MM
4635\f
4636/* Perform any needed actions needed for a function that is receiving a
4637 variable number of arguments.
4638
4639 CUM is as above.
4640
4641 MODE and TYPE are the mode and type of the current parameter.
4642
4643 PRETEND_SIZE is a variable that should be set to the amount of stack
4644 that must be pushed by the prolog to pretend that our caller pushed
4645 it.
4646
4647 Normally, this macro will push all remaining incoming registers on the
4648 stack and set PRETEND_SIZE to the length of the registers pushed. */
4649
c6e8c921 4650static void
a2369ed3
DJ
4651setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4652 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4653{
4cc833b7
RH
4654 CUMULATIVE_ARGS next_cum;
4655 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4656 rtx save_area = NULL_RTX, mem;
dfafc897 4657 int first_reg_offset, set;
4697a36c 4658
f31bf321 4659 /* Skip the last named argument. */
d34c5b80 4660 next_cum = *cum;
f31bf321 4661 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4662
f607bc57 4663 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4664 {
4cc833b7 4665 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4666 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4667 if (! no_rtl)
2c4974b7 4668 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4669 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4670
4671 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4672 }
60e2d0ca 4673 else
4697a36c 4674 {
d34c5b80 4675 first_reg_offset = next_cum.words;
4cc833b7 4676 save_area = virtual_incoming_args_rtx;
00dba523 4677 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4678
4679 if (MUST_PASS_IN_STACK (mode, type))
c53bdcf5 4680 first_reg_offset += rs6000_arg_size (TYPE_MODE (type), type);
4cc833b7 4681 }
4697a36c 4682
dfafc897 4683 set = get_varargs_alias_set ();
c81fc13e 4684 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4685 {
dfafc897
FS
4686 mem = gen_rtx_MEM (BLKmode,
4687 plus_constant (save_area,
4688 first_reg_offset * reg_size)),
ba4828e0 4689 set_mem_alias_set (mem, set);
8ac61af7 4690 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4691
5985c7a6
FJ
4692 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4693 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4694 }
4695
4697a36c 4696 /* Save FP registers if needed. */
f607bc57 4697 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4698 && TARGET_HARD_FLOAT && TARGET_FPRS
4699 && ! no_rtl
4cc833b7 4700 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4701 {
4cc833b7 4702 int fregno = next_cum.fregno;
9ebbca7d 4703 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4704 rtx lab = gen_label_rtx ();
4705 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4706
4cc833b7 4707 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4708 pc_rtx,
39403d82 4709 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4710 gen_rtx_NE (VOIDmode, cr1,
4711 const0_rtx),
39403d82 4712 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4713 pc_rtx)));
4714
4cc833b7
RH
4715 while (fregno <= FP_ARG_V4_MAX_REG)
4716 {
dfafc897 4717 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4718 set_mem_alias_set (mem, set);
dfafc897 4719 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4720 fregno++;
4721 off += 8;
4697a36c 4722 }
4cc833b7
RH
4723
4724 emit_label (lab);
4697a36c 4725 }
4697a36c 4726}
4697a36c 4727
dfafc897 4728/* Create the va_list data type. */
2c4974b7 4729
c35d187f
RH
4730static tree
4731rs6000_build_builtin_va_list (void)
dfafc897 4732{
64c2816f 4733 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4734
9ebbca7d
GK
4735 /* For AIX, prefer 'char *' because that's what the system
4736 header files like. */
f607bc57 4737 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4738 return build_pointer_type (char_type_node);
dfafc897 4739
f1e639b1 4740 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4741 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4742
9ebbca7d
GK
4743 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4744 unsigned_char_type_node);
4745 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4746 unsigned_char_type_node);
64c2816f
DT
4747 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4748 every user file. */
4749 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4750 short_unsigned_type_node);
dfafc897
FS
4751 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4752 ptr_type_node);
4753 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4754 ptr_type_node);
4755
4756 DECL_FIELD_CONTEXT (f_gpr) = record;
4757 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4758 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4759 DECL_FIELD_CONTEXT (f_ovf) = record;
4760 DECL_FIELD_CONTEXT (f_sav) = record;
4761
bab45a51
FS
4762 TREE_CHAIN (record) = type_decl;
4763 TYPE_NAME (record) = type_decl;
dfafc897
FS
4764 TYPE_FIELDS (record) = f_gpr;
4765 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4766 TREE_CHAIN (f_fpr) = f_res;
4767 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4768 TREE_CHAIN (f_ovf) = f_sav;
4769
4770 layout_type (record);
4771
4772 /* The correct type is an array type of one element. */
4773 return build_array_type (record, build_index_type (size_zero_node));
4774}
4775
4776/* Implement va_start. */
4777
4778void
a2369ed3 4779rs6000_va_start (tree valist, rtx nextarg)
4697a36c 4780{
dfafc897 4781 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 4782 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 4783 tree gpr, fpr, ovf, sav, t;
2c4974b7 4784
dfafc897 4785 /* Only SVR4 needs something special. */
f607bc57 4786 if (DEFAULT_ABI != ABI_V4)
dfafc897 4787 {
e5faf155 4788 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
4789 return;
4790 }
4791
973a648b 4792 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4793 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4794 f_res = TREE_CHAIN (f_fpr);
4795 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4796 f_sav = TREE_CHAIN (f_ovf);
4797
8ebecc3b 4798 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4799 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4800 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4801 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4802 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4803
4804 /* Count number of gp and fp argument registers used. */
4cc833b7 4805 words = current_function_args_info.words;
dfafc897
FS
4806 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
4807 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
4808
4809 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
4810 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
4811 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
4812 words, n_gpr, n_fpr);
dfafc897
FS
4813
4814 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
4815 TREE_SIDE_EFFECTS (t) = 1;
4816 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4817
4818 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
4819 TREE_SIDE_EFFECTS (t) = 1;
4820 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4821
4822 /* Find the overflow area. */
4823 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
4824 if (words != 0)
4825 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
4826 build_int_2 (words * UNITS_PER_WORD, 0));
4827 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4828 TREE_SIDE_EFFECTS (t) = 1;
4829 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4830
4831 /* Find the register save area. */
4832 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
4833 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
4834 build_int_2 (-RS6000_VARARGS_SIZE, -1));
4835 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
4836 TREE_SIDE_EFFECTS (t) = 1;
4837 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4838}
4839
4840/* Implement va_arg. */
4841
4842rtx
a2369ed3 4843rs6000_va_arg (tree valist, tree type)
dfafc897 4844{
c566f9bd 4845 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
4846 tree gpr, fpr, ovf, sav, reg, t, u;
4847 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
4848 rtx lab_false, lab_over, addr_rtx, r;
4849
f607bc57 4850 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
4851 {
4852 /* Variable sized types are passed by reference. */
fff2cb99 4853 if (int_size_in_bytes (type) < 0)
c8c99a68
DE
4854 {
4855 u = build_pointer_type (type);
4856
4857 /* Args grow upward. */
4858 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
4859 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4860 TREE_SIDE_EFFECTS (t) = 1;
4861
4862 t = build1 (NOP_EXPR, build_pointer_type (u), t);
4863 TREE_SIDE_EFFECTS (t) = 1;
4864
4865 t = build1 (INDIRECT_REF, u, t);
4866 TREE_SIDE_EFFECTS (t) = 1;
4867
4868 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4869 }
fa78dbea 4870 if (targetm.calls.split_complex_arg
c53bdcf5
AM
4871 && TREE_CODE (type) == COMPLEX_TYPE)
4872 {
4873 tree elem_type = TREE_TYPE (type);
4874 enum machine_mode elem_mode = TYPE_MODE (elem_type);
4875 int elem_size = GET_MODE_SIZE (elem_mode);
4876
4877 if (elem_size < UNITS_PER_WORD)
4878 {
4879 rtx real_part, imag_part, dest_real, rr;
4880
4881 real_part = rs6000_va_arg (valist, elem_type);
4882 imag_part = rs6000_va_arg (valist, elem_type);
4883
4884 /* We're not returning the value here, but the address.
4885 real_part and imag_part are not contiguous, and we know
4886 there is space available to pack real_part next to
4887 imag_part. float _Complex is not promoted to
4888 double _Complex by the default promotion rules that
4889 promote float to double. */
4890 if (2 * elem_size > UNITS_PER_WORD)
4891 abort ();
4892
4893 real_part = gen_rtx_MEM (elem_mode, real_part);
4894 imag_part = gen_rtx_MEM (elem_mode, imag_part);
4895
4896 dest_real = adjust_address (imag_part, elem_mode, -elem_size);
4897 rr = gen_reg_rtx (elem_mode);
4898 emit_move_insn (rr, real_part);
4899 emit_move_insn (dest_real, rr);
4900
4901 return XEXP (dest_real, 0);
4902 }
4903 }
4904
4905 return std_expand_builtin_va_arg (valist, type);
c8c99a68 4906 }
dfafc897 4907
973a648b 4908 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4909 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4910 f_res = TREE_CHAIN (f_fpr);
4911 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4912 f_sav = TREE_CHAIN (f_ovf);
4913
8ebecc3b 4914 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4915 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4916 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4917 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4918 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4919
4920 size = int_size_in_bytes (type);
4921 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 4922
dfafc897 4923 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 4924 {
dfafc897
FS
4925 /* Aggregates and long doubles are passed by reference. */
4926 indirect_p = 1;
4927 reg = gpr;
4928 n_reg = 1;
4929 sav_ofs = 0;
4930 sav_scale = 4;
d3294cd9
FS
4931 size = UNITS_PER_WORD;
4932 rsize = 1;
dfafc897 4933 }
a3170dc6 4934 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
4935 {
4936 /* FP args go in FP registers, if present. */
4937 indirect_p = 0;
4938 reg = fpr;
4939 n_reg = 1;
4940 sav_ofs = 8*4;
4941 sav_scale = 8;
4cc833b7 4942 }
dfafc897
FS
4943 else
4944 {
4945 /* Otherwise into GP registers. */
4946 indirect_p = 0;
4947 reg = gpr;
4948 n_reg = rsize;
4949 sav_ofs = 0;
4950 sav_scale = 4;
4951 }
4952
a3c9585f 4953 /* Pull the value out of the saved registers.... */
dfafc897
FS
4954
4955 lab_false = gen_label_rtx ();
4956 lab_over = gen_label_rtx ();
4957 addr_rtx = gen_reg_rtx (Pmode);
4958
16861f33
AH
4959 /* AltiVec vectors never go in registers. */
4960 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 4961 {
41daaf0e
AH
4962 TREE_THIS_VOLATILE (reg) = 1;
4963 emit_cmp_and_jump_insns
4964 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
4965 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
4966 lab_false);
dfafc897 4967
41daaf0e
AH
4968 /* Long long is aligned in the registers. */
4969 if (n_reg > 1)
4970 {
4971 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
4972 build_int_2 (n_reg - 1, 0));
4973 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
4974 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
4975 TREE_SIDE_EFFECTS (u) = 1;
4976 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
4977 }
2c4974b7 4978
41daaf0e
AH
4979 if (sav_ofs)
4980 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
4981 else
4982 t = sav;
2c4974b7 4983
41daaf0e
AH
4984 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
4985 build_int_2 (n_reg, 0));
4986 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 4987
41daaf0e
AH
4988 u = build1 (CONVERT_EXPR, integer_type_node, u);
4989 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4990
41daaf0e
AH
4991 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
4992 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4993
41daaf0e
AH
4994 t = build (PLUS_EXPR, ptr_type_node, t, u);
4995 TREE_SIDE_EFFECTS (t) = 1;
4996
4997 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4998 if (r != addr_rtx)
4999 emit_move_insn (addr_rtx, r);
5000
5001 emit_jump_insn (gen_jump (lab_over));
5002 emit_barrier ();
5003 }
dfafc897 5004
dfafc897
FS
5005 emit_label (lab_false);
5006
a4f6c312 5007 /* ... otherwise out of the overflow area. */
dfafc897 5008
41daaf0e
AH
5009 /* Make sure we don't find reg 7 for the next int arg.
5010
5011 All AltiVec vectors go in the overflow area. So in the AltiVec
5012 case we need to get the vectors from the overflow area, but
5013 remember where the GPRs and FPRs are. */
16861f33
AH
5014 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
5015 || !TARGET_ALTIVEC))
dfafc897
FS
5016 {
5017 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
5018 TREE_SIDE_EFFECTS (t) = 1;
5019 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5020 }
5021
5022 /* Care for on-stack alignment if needed. */
5023 if (rsize <= 1)
5024 t = ovf;
5025 else
5026 {
41daaf0e
AH
5027 int align;
5028
16861f33
AH
5029 /* AltiVec vectors are 16 byte aligned. */
5030 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
5031 align = 15;
5032 else
5033 align = 7;
5034
5035 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
5036 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
5037 }
5038 t = save_expr (t);
5039
5040 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
5041 if (r != addr_rtx)
5042 emit_move_insn (addr_rtx, r);
5043
5044 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
5045 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
5046 TREE_SIDE_EFFECTS (t) = 1;
5047 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
5048
5049 emit_label (lab_over);
5050
5051 if (indirect_p)
5052 {
5053 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 5054 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
5055 emit_move_insn (addr_rtx, r);
5056 }
5057
5058 return addr_rtx;
4697a36c 5059}
0ac081f6
AH
5060
5061/* Builtins. */
5062
6a2dd09a
RS
5063#define def_builtin(MASK, NAME, TYPE, CODE) \
5064do { \
5065 if ((MASK) & target_flags) \
5066 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
5067 NULL, NULL_TREE); \
0ac081f6
AH
5068} while (0)
5069
24408032
AH
5070/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
5071
2212663f 5072static const struct builtin_description bdesc_3arg[] =
24408032
AH
5073{
5074 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
5075 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
5076 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
5077 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
5078 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
5079 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
5080 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
5081 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
5082 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
5083 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
5084 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
5085 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
5086 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
5087 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
5088 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
5089 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
5090 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
5091 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
5092 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
5093 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
5094 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
5095 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
5096 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
5097};
2212663f 5098
95385cbb
AH
5099/* DST operations: void foo (void *, const int, const char). */
5100
5101static const struct builtin_description bdesc_dst[] =
5102{
5103 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
5104 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
5105 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
5106 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
5107};
5108
2212663f 5109/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 5110
a3170dc6 5111static struct builtin_description bdesc_2arg[] =
0ac081f6 5112{
f18c054f
DB
5113 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
5114 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
5115 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
5116 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
5117 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
5118 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
5119 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
5120 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
5121 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
5122 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
5123 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 5124 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
5125 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
5126 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
5127 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
5128 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
5129 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
5130 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
5131 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
5132 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
5133 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
5134 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
5135 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
5136 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5137 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5138 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5139 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5140 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5141 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5142 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5143 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5144 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5145 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5146 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5147 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5148 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5149 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5150 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5151 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5152 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5153 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5154 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5155 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5156 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5157 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5158 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5159 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5160 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5161 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5162 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5163 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5164 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5165 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5166 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5167 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5168 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5169 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5170 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5171 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5172 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5173 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5174 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5175 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5176 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5177 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5178 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5179 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5180 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5181 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5182 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5183 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5184 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5185 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5186 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5187 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5188 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5189 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5190 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5191 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5192 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5193 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5194 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5195 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5196 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5197 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5198 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5199 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5200 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5201 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5202 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5203 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5204 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5205 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5206 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5207 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5208 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5209 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5210 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5211 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5212 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5213 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5214 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5215 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5216 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5217 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5218 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5219 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5220 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5221 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5222 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5223 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5224 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5225 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5226
5227 /* Place holder, leave as first spe builtin. */
5228 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5229 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5230 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5231 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5232 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5233 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5234 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5235 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5236 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5237 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5238 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5239 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5240 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5241 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5242 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5243 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5244 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5245 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5246 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5247 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5248 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5249 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5250 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5251 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5252 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5253 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5254 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5255 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5256 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5257 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5258 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5259 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5260 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5261 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5262 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5263 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5264 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5265 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5266 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5267 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5268 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5269 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5270 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5271 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5272 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5273 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5274 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5275 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5276 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5277 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5278 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5279 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5280 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5281 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5282 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5283 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5284 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5285 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5286 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5287 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5288 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5289 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5290 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5291 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5292 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5293 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5294 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5295 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5296 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5297 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5298 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5299 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5300 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5301 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5302 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5303 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5304 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5305 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5306 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5307 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5308 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5309 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5310 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5311 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5312 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5313 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5314 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5315 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5316 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5317 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5318 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5319 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5320 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5321 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5322 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5323 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
5324 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
5325 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
5326 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
5327 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
5328 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
5329 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
5330 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
5331 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
5332 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
5333 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
5334 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
5335 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
5336 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
5337
5338 /* SPE binary operations expecting a 5-bit unsigned literal. */
5339 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
5340
5341 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
5342 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
5343 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
5344 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
5345 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
5346 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
5347 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
5348 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
5349 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
5350 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
5351 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
5352 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
5353 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
5354 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
5355 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
5356 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
5357 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
5358 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
5359 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
5360 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
5361 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
5362 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
5363 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
5364 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
5365 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
5366 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
5367
5368 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 5369 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
5370};
5371
5372/* AltiVec predicates. */
5373
5374struct builtin_description_predicates
5375{
5376 const unsigned int mask;
5377 const enum insn_code icode;
5378 const char *opcode;
5379 const char *const name;
5380 const enum rs6000_builtins code;
5381};
5382
5383static const struct builtin_description_predicates bdesc_altivec_preds[] =
5384{
5385 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
5386 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
5387 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
5388 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
5389 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
5390 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
5391 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
5392 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
5393 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
5394 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
5395 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
5396 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
5397 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 5398};
24408032 5399
a3170dc6
AH
5400/* SPE predicates. */
5401static struct builtin_description bdesc_spe_predicates[] =
5402{
5403 /* Place-holder. Leave as first. */
5404 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
5405 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
5406 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
5407 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
5408 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
5409 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
5410 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
5411 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
5412 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
5413 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
5414 /* Place-holder. Leave as last. */
5415 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
5416};
5417
5418/* SPE evsel predicates. */
5419static struct builtin_description bdesc_spe_evsel[] =
5420{
5421 /* Place-holder. Leave as first. */
5422 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
5423 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
5424 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
5425 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
5426 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
5427 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
5428 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
5429 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
5430 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
5431 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
5432 /* Place-holder. Leave as last. */
5433 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
5434};
5435
b6d08ca1 5436/* ABS* operations. */
100c4561
AH
5437
5438static const struct builtin_description bdesc_abs[] =
5439{
5440 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
5441 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
5442 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
5443 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
5444 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
5445 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
5446 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
5447};
5448
617e0e1d
DB
5449/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
5450 foo (VECa). */
24408032 5451
a3170dc6 5452static struct builtin_description bdesc_1arg[] =
2212663f 5453{
617e0e1d
DB
5454 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
5455 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
5456 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
5457 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
5458 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
5459 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
5460 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
5461 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
5462 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
5463 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
5464 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
5465 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
5466 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
5467 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
5468 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
5469 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
5470 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
5471
5472 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
5473 end with SPE_BUILTIN_EVSUBFUSIAAW. */
5474 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
5475 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
5476 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
5477 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
5478 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
5479 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
5480 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
5481 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
5482 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
5483 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
5484 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
5485 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
5486 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
5487 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
5488 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
5489 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
5490 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
5491 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
5492 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
5493 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
5494 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
5495 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
5496 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
5497 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
5498 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
5499 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
5500 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
5501 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
5502
5503 /* Place-holder. Leave as last unary SPE builtin. */
5504 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
5505};
5506
5507static rtx
a2369ed3 5508rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5509{
5510 rtx pat;
5511 tree arg0 = TREE_VALUE (arglist);
5512 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5513 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5514 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5515
0559cc77
DE
5516 if (icode == CODE_FOR_nothing)
5517 /* Builtin not supported on this processor. */
5518 return 0;
5519
20e26713
AH
5520 /* If we got invalid arguments bail out before generating bad rtl. */
5521 if (arg0 == error_mark_node)
9a171fcd 5522 return const0_rtx;
20e26713 5523
0559cc77
DE
5524 if (icode == CODE_FOR_altivec_vspltisb
5525 || icode == CODE_FOR_altivec_vspltish
5526 || icode == CODE_FOR_altivec_vspltisw
5527 || icode == CODE_FOR_spe_evsplatfi
5528 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
5529 {
5530 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
5531 if (GET_CODE (op0) != CONST_INT
5532 || INTVAL (op0) > 0x1f
5533 || INTVAL (op0) < -0x1f)
5534 {
5535 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 5536 return const0_rtx;
b44140e7 5537 }
b44140e7
AH
5538 }
5539
c62f2db5 5540 if (target == 0
2212663f
DB
5541 || GET_MODE (target) != tmode
5542 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5543 target = gen_reg_rtx (tmode);
5544
5545 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5546 op0 = copy_to_mode_reg (mode0, op0);
5547
5548 pat = GEN_FCN (icode) (target, op0);
5549 if (! pat)
5550 return 0;
5551 emit_insn (pat);
0ac081f6 5552
2212663f
DB
5553 return target;
5554}
ae4b4a02 5555
100c4561 5556static rtx
a2369ed3 5557altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
5558{
5559 rtx pat, scratch1, scratch2;
5560 tree arg0 = TREE_VALUE (arglist);
5561 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5562 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5563 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5564
5565 /* If we have invalid arguments, bail out before generating bad rtl. */
5566 if (arg0 == error_mark_node)
9a171fcd 5567 return const0_rtx;
100c4561
AH
5568
5569 if (target == 0
5570 || GET_MODE (target) != tmode
5571 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5572 target = gen_reg_rtx (tmode);
5573
5574 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5575 op0 = copy_to_mode_reg (mode0, op0);
5576
5577 scratch1 = gen_reg_rtx (mode0);
5578 scratch2 = gen_reg_rtx (mode0);
5579
5580 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
5581 if (! pat)
5582 return 0;
5583 emit_insn (pat);
5584
5585 return target;
5586}
5587
0ac081f6 5588static rtx
a2369ed3 5589rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
5590{
5591 rtx pat;
5592 tree arg0 = TREE_VALUE (arglist);
5593 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5594 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5595 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5596 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5597 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5598 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5599
0559cc77
DE
5600 if (icode == CODE_FOR_nothing)
5601 /* Builtin not supported on this processor. */
5602 return 0;
5603
20e26713
AH
5604 /* If we got invalid arguments bail out before generating bad rtl. */
5605 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5606 return const0_rtx;
20e26713 5607
0559cc77
DE
5608 if (icode == CODE_FOR_altivec_vcfux
5609 || icode == CODE_FOR_altivec_vcfsx
5610 || icode == CODE_FOR_altivec_vctsxs
5611 || icode == CODE_FOR_altivec_vctuxs
5612 || icode == CODE_FOR_altivec_vspltb
5613 || icode == CODE_FOR_altivec_vsplth
5614 || icode == CODE_FOR_altivec_vspltw
5615 || icode == CODE_FOR_spe_evaddiw
5616 || icode == CODE_FOR_spe_evldd
5617 || icode == CODE_FOR_spe_evldh
5618 || icode == CODE_FOR_spe_evldw
5619 || icode == CODE_FOR_spe_evlhhesplat
5620 || icode == CODE_FOR_spe_evlhhossplat
5621 || icode == CODE_FOR_spe_evlhhousplat
5622 || icode == CODE_FOR_spe_evlwhe
5623 || icode == CODE_FOR_spe_evlwhos
5624 || icode == CODE_FOR_spe_evlwhou
5625 || icode == CODE_FOR_spe_evlwhsplat
5626 || icode == CODE_FOR_spe_evlwwsplat
5627 || icode == CODE_FOR_spe_evrlwi
5628 || icode == CODE_FOR_spe_evslwi
5629 || icode == CODE_FOR_spe_evsrwis
f5119d10 5630 || icode == CODE_FOR_spe_evsubifw
0559cc77 5631 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
5632 {
5633 /* Only allow 5-bit unsigned literals. */
8bb418a3 5634 STRIP_NOPS (arg1);
b44140e7
AH
5635 if (TREE_CODE (arg1) != INTEGER_CST
5636 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5637 {
5638 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 5639 return const0_rtx;
b44140e7 5640 }
b44140e7
AH
5641 }
5642
c62f2db5 5643 if (target == 0
0ac081f6
AH
5644 || GET_MODE (target) != tmode
5645 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5646 target = gen_reg_rtx (tmode);
5647
5648 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5649 op0 = copy_to_mode_reg (mode0, op0);
5650 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5651 op1 = copy_to_mode_reg (mode1, op1);
5652
5653 pat = GEN_FCN (icode) (target, op0, op1);
5654 if (! pat)
5655 return 0;
5656 emit_insn (pat);
5657
5658 return target;
5659}
6525c0e7 5660
ae4b4a02 5661static rtx
a2369ed3
DJ
5662altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
5663 tree arglist, rtx target)
ae4b4a02
AH
5664{
5665 rtx pat, scratch;
5666 tree cr6_form = TREE_VALUE (arglist);
5667 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5668 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5669 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5670 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5671 enum machine_mode tmode = SImode;
5672 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5673 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5674 int cr6_form_int;
5675
5676 if (TREE_CODE (cr6_form) != INTEGER_CST)
5677 {
5678 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5679 return const0_rtx;
ae4b4a02
AH
5680 }
5681 else
5682 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5683
5684 if (mode0 != mode1)
5685 abort ();
5686
5687 /* If we have invalid arguments, bail out before generating bad rtl. */
5688 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5689 return const0_rtx;
ae4b4a02
AH
5690
5691 if (target == 0
5692 || GET_MODE (target) != tmode
5693 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5694 target = gen_reg_rtx (tmode);
5695
5696 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5697 op0 = copy_to_mode_reg (mode0, op0);
5698 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5699 op1 = copy_to_mode_reg (mode1, op1);
5700
5701 scratch = gen_reg_rtx (mode0);
5702
5703 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 5704 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
5705 if (! pat)
5706 return 0;
5707 emit_insn (pat);
5708
5709 /* The vec_any* and vec_all* predicates use the same opcodes for two
5710 different operations, but the bits in CR6 will be different
5711 depending on what information we want. So we have to play tricks
5712 with CR6 to get the right bits out.
5713
5714 If you think this is disgusting, look at the specs for the
5715 AltiVec predicates. */
5716
5717 switch (cr6_form_int)
5718 {
5719 case 0:
5720 emit_insn (gen_cr6_test_for_zero (target));
5721 break;
5722 case 1:
5723 emit_insn (gen_cr6_test_for_zero_reverse (target));
5724 break;
5725 case 2:
5726 emit_insn (gen_cr6_test_for_lt (target));
5727 break;
5728 case 3:
5729 emit_insn (gen_cr6_test_for_lt_reverse (target));
5730 break;
5731 default:
5732 error ("argument 1 of __builtin_altivec_predicate is out of range");
5733 break;
5734 }
5735
5736 return target;
5737}
5738
b4a62fa0 5739static rtx
38f391a5 5740altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
5741{
5742 rtx pat, addr;
5743 tree arg0 = TREE_VALUE (arglist);
5744 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5745 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5746 enum machine_mode mode0 = Pmode;
5747 enum machine_mode mode1 = Pmode;
5748 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5749 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5750
5751 if (icode == CODE_FOR_nothing)
5752 /* Builtin not supported on this processor. */
5753 return 0;
5754
5755 /* If we got invalid arguments bail out before generating bad rtl. */
5756 if (arg0 == error_mark_node || arg1 == error_mark_node)
5757 return const0_rtx;
5758
5759 if (target == 0
5760 || GET_MODE (target) != tmode
5761 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5762 target = gen_reg_rtx (tmode);
5763
5764 op1 = copy_to_mode_reg (mode1, op1);
5765
5766 if (op0 == const0_rtx)
5767 {
5768 addr = gen_rtx_MEM (tmode, op1);
5769 }
5770 else
5771 {
5772 op0 = copy_to_mode_reg (mode0, op0);
5773 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
5774 }
5775
5776 pat = GEN_FCN (icode) (target, addr);
5777
5778 if (! pat)
5779 return 0;
5780 emit_insn (pat);
5781
5782 return target;
5783}
5784
6525c0e7 5785static rtx
a2369ed3 5786altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
5787{
5788 tree arg0 = TREE_VALUE (arglist);
5789 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5790 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5791 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5792 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5793 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
5794 rtx pat, addr;
5795 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5796 enum machine_mode mode1 = Pmode;
5797 enum machine_mode mode2 = Pmode;
6525c0e7
AH
5798
5799 /* Invalid arguments. Bail before doing anything stoopid! */
5800 if (arg0 == error_mark_node
5801 || arg1 == error_mark_node
5802 || arg2 == error_mark_node)
9a171fcd 5803 return const0_rtx;
6525c0e7 5804
b4a62fa0
SB
5805 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
5806 op0 = copy_to_mode_reg (tmode, op0);
5807
5808 op2 = copy_to_mode_reg (mode2, op2);
5809
5810 if (op1 == const0_rtx)
5811 {
5812 addr = gen_rtx_MEM (tmode, op2);
5813 }
5814 else
5815 {
5816 op1 = copy_to_mode_reg (mode1, op1);
5817 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
5818 }
6525c0e7 5819
b4a62fa0 5820 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
5821 if (pat)
5822 emit_insn (pat);
5823 return NULL_RTX;
5824}
5825
2212663f 5826static rtx
a2369ed3 5827rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5828{
5829 rtx pat;
5830 tree arg0 = TREE_VALUE (arglist);
5831 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5832 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5833 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5834 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5835 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5836 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5837 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5838 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5839 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 5840
774b5662
DE
5841 if (icode == CODE_FOR_nothing)
5842 /* Builtin not supported on this processor. */
5843 return 0;
5844
20e26713
AH
5845 /* If we got invalid arguments bail out before generating bad rtl. */
5846 if (arg0 == error_mark_node
5847 || arg1 == error_mark_node
5848 || arg2 == error_mark_node)
9a171fcd 5849 return const0_rtx;
20e26713 5850
774b5662
DE
5851 if (icode == CODE_FOR_altivec_vsldoi_4sf
5852 || icode == CODE_FOR_altivec_vsldoi_4si
5853 || icode == CODE_FOR_altivec_vsldoi_8hi
5854 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
5855 {
5856 /* Only allow 4-bit unsigned literals. */
8bb418a3 5857 STRIP_NOPS (arg2);
b44140e7
AH
5858 if (TREE_CODE (arg2) != INTEGER_CST
5859 || TREE_INT_CST_LOW (arg2) & ~0xf)
5860 {
5861 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 5862 return const0_rtx;
b44140e7 5863 }
b44140e7
AH
5864 }
5865
c62f2db5 5866 if (target == 0
2212663f
DB
5867 || GET_MODE (target) != tmode
5868 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5869 target = gen_reg_rtx (tmode);
5870
5871 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5872 op0 = copy_to_mode_reg (mode0, op0);
5873 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5874 op1 = copy_to_mode_reg (mode1, op1);
5875 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
5876 op2 = copy_to_mode_reg (mode2, op2);
5877
5878 pat = GEN_FCN (icode) (target, op0, op1, op2);
5879 if (! pat)
5880 return 0;
5881 emit_insn (pat);
5882
5883 return target;
5884}
92898235 5885
3a9b8c7e 5886/* Expand the lvx builtins. */
0ac081f6 5887static rtx
a2369ed3 5888altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 5889{
0ac081f6
AH
5890 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5891 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 5892 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
5893 tree arg0;
5894 enum machine_mode tmode, mode0;
7c3abc73 5895 rtx pat, op0;
3a9b8c7e 5896 enum insn_code icode;
92898235 5897
0ac081f6
AH
5898 switch (fcode)
5899 {
f18c054f
DB
5900 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
5901 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 5902 break;
f18c054f
DB
5903 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
5904 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
5905 break;
5906 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
5907 icode = CODE_FOR_altivec_lvx_4si;
5908 break;
5909 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
5910 icode = CODE_FOR_altivec_lvx_4sf;
5911 break;
5912 default:
5913 *expandedp = false;
5914 return NULL_RTX;
5915 }
0ac081f6 5916
3a9b8c7e 5917 *expandedp = true;
f18c054f 5918
3a9b8c7e
AH
5919 arg0 = TREE_VALUE (arglist);
5920 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5921 tmode = insn_data[icode].operand[0].mode;
5922 mode0 = insn_data[icode].operand[1].mode;
f18c054f 5923
3a9b8c7e
AH
5924 if (target == 0
5925 || GET_MODE (target) != tmode
5926 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5927 target = gen_reg_rtx (tmode);
24408032 5928
3a9b8c7e
AH
5929 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5930 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 5931
3a9b8c7e
AH
5932 pat = GEN_FCN (icode) (target, op0);
5933 if (! pat)
5934 return 0;
5935 emit_insn (pat);
5936 return target;
5937}
f18c054f 5938
3a9b8c7e
AH
5939/* Expand the stvx builtins. */
5940static rtx
a2369ed3
DJ
5941altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5942 bool *expandedp)
3a9b8c7e
AH
5943{
5944 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5945 tree arglist = TREE_OPERAND (exp, 1);
5946 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5947 tree arg0, arg1;
5948 enum machine_mode mode0, mode1;
7c3abc73 5949 rtx pat, op0, op1;
3a9b8c7e 5950 enum insn_code icode;
f18c054f 5951
3a9b8c7e
AH
5952 switch (fcode)
5953 {
5954 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
5955 icode = CODE_FOR_altivec_stvx_16qi;
5956 break;
5957 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
5958 icode = CODE_FOR_altivec_stvx_8hi;
5959 break;
5960 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
5961 icode = CODE_FOR_altivec_stvx_4si;
5962 break;
5963 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
5964 icode = CODE_FOR_altivec_stvx_4sf;
5965 break;
5966 default:
5967 *expandedp = false;
5968 return NULL_RTX;
5969 }
24408032 5970
3a9b8c7e
AH
5971 arg0 = TREE_VALUE (arglist);
5972 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5973 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5974 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5975 mode0 = insn_data[icode].operand[0].mode;
5976 mode1 = insn_data[icode].operand[1].mode;
f18c054f 5977
3a9b8c7e
AH
5978 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5979 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
5980 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5981 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 5982
3a9b8c7e
AH
5983 pat = GEN_FCN (icode) (op0, op1);
5984 if (pat)
5985 emit_insn (pat);
f18c054f 5986
3a9b8c7e
AH
5987 *expandedp = true;
5988 return NULL_RTX;
5989}
f18c054f 5990
3a9b8c7e
AH
5991/* Expand the dst builtins. */
5992static rtx
a2369ed3
DJ
5993altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5994 bool *expandedp)
3a9b8c7e
AH
5995{
5996 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5997 tree arglist = TREE_OPERAND (exp, 1);
5998 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5999 tree arg0, arg1, arg2;
6000 enum machine_mode mode0, mode1, mode2;
7c3abc73 6001 rtx pat, op0, op1, op2;
3a9b8c7e 6002 struct builtin_description *d;
a3170dc6 6003 size_t i;
f18c054f 6004
3a9b8c7e 6005 *expandedp = false;
f18c054f 6006
3a9b8c7e
AH
6007 /* Handle DST variants. */
6008 d = (struct builtin_description *) bdesc_dst;
6009 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
6010 if (d->code == fcode)
6011 {
6012 arg0 = TREE_VALUE (arglist);
6013 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6014 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6015 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6016 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6017 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6018 mode0 = insn_data[d->icode].operand[0].mode;
6019 mode1 = insn_data[d->icode].operand[1].mode;
6020 mode2 = insn_data[d->icode].operand[2].mode;
24408032 6021
3a9b8c7e
AH
6022 /* Invalid arguments, bail out before generating bad rtl. */
6023 if (arg0 == error_mark_node
6024 || arg1 == error_mark_node
6025 || arg2 == error_mark_node)
6026 return const0_rtx;
f18c054f 6027
86e7df90 6028 *expandedp = true;
8bb418a3 6029 STRIP_NOPS (arg2);
3a9b8c7e
AH
6030 if (TREE_CODE (arg2) != INTEGER_CST
6031 || TREE_INT_CST_LOW (arg2) & ~0x3)
6032 {
6033 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
6034 return const0_rtx;
6035 }
f18c054f 6036
3a9b8c7e 6037 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 6038 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
6039 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
6040 op1 = copy_to_mode_reg (mode1, op1);
24408032 6041
3a9b8c7e
AH
6042 pat = GEN_FCN (d->icode) (op0, op1, op2);
6043 if (pat != 0)
6044 emit_insn (pat);
f18c054f 6045
3a9b8c7e
AH
6046 return NULL_RTX;
6047 }
f18c054f 6048
3a9b8c7e
AH
6049 return NULL_RTX;
6050}
24408032 6051
3a9b8c7e
AH
6052/* Expand the builtin in EXP and store the result in TARGET. Store
6053 true in *EXPANDEDP if we found a builtin to expand. */
6054static rtx
a2369ed3 6055altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
6056{
6057 struct builtin_description *d;
6058 struct builtin_description_predicates *dp;
6059 size_t i;
6060 enum insn_code icode;
6061 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6062 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
6063 tree arg0;
6064 rtx op0, pat;
6065 enum machine_mode tmode, mode0;
3a9b8c7e 6066 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 6067
3a9b8c7e
AH
6068 target = altivec_expand_ld_builtin (exp, target, expandedp);
6069 if (*expandedp)
6070 return target;
0ac081f6 6071
3a9b8c7e
AH
6072 target = altivec_expand_st_builtin (exp, target, expandedp);
6073 if (*expandedp)
6074 return target;
6075
6076 target = altivec_expand_dst_builtin (exp, target, expandedp);
6077 if (*expandedp)
6078 return target;
6079
6080 *expandedp = true;
95385cbb 6081
3a9b8c7e
AH
6082 switch (fcode)
6083 {
6525c0e7
AH
6084 case ALTIVEC_BUILTIN_STVX:
6085 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
6086 case ALTIVEC_BUILTIN_STVEBX:
6087 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
6088 case ALTIVEC_BUILTIN_STVEHX:
6089 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
6090 case ALTIVEC_BUILTIN_STVEWX:
6091 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
6092 case ALTIVEC_BUILTIN_STVXL:
6093 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 6094
95385cbb
AH
6095 case ALTIVEC_BUILTIN_MFVSCR:
6096 icode = CODE_FOR_altivec_mfvscr;
6097 tmode = insn_data[icode].operand[0].mode;
6098
6099 if (target == 0
6100 || GET_MODE (target) != tmode
6101 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6102 target = gen_reg_rtx (tmode);
6103
6104 pat = GEN_FCN (icode) (target);
0ac081f6
AH
6105 if (! pat)
6106 return 0;
6107 emit_insn (pat);
95385cbb
AH
6108 return target;
6109
6110 case ALTIVEC_BUILTIN_MTVSCR:
6111 icode = CODE_FOR_altivec_mtvscr;
6112 arg0 = TREE_VALUE (arglist);
6113 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6114 mode0 = insn_data[icode].operand[0].mode;
6115
6116 /* If we got invalid arguments bail out before generating bad rtl. */
6117 if (arg0 == error_mark_node)
9a171fcd 6118 return const0_rtx;
95385cbb
AH
6119
6120 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6121 op0 = copy_to_mode_reg (mode0, op0);
6122
6123 pat = GEN_FCN (icode) (op0);
6124 if (pat)
6125 emit_insn (pat);
6126 return NULL_RTX;
3a9b8c7e 6127
95385cbb
AH
6128 case ALTIVEC_BUILTIN_DSSALL:
6129 emit_insn (gen_altivec_dssall ());
6130 return NULL_RTX;
6131
6132 case ALTIVEC_BUILTIN_DSS:
6133 icode = CODE_FOR_altivec_dss;
6134 arg0 = TREE_VALUE (arglist);
8bb418a3 6135 STRIP_NOPS (arg0);
95385cbb
AH
6136 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6137 mode0 = insn_data[icode].operand[0].mode;
6138
6139 /* If we got invalid arguments bail out before generating bad rtl. */
6140 if (arg0 == error_mark_node)
9a171fcd 6141 return const0_rtx;
95385cbb 6142
b44140e7
AH
6143 if (TREE_CODE (arg0) != INTEGER_CST
6144 || TREE_INT_CST_LOW (arg0) & ~0x3)
6145 {
6146 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6147 return const0_rtx;
b44140e7
AH
6148 }
6149
95385cbb
AH
6150 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6151 op0 = copy_to_mode_reg (mode0, op0);
6152
6153 emit_insn (gen_altivec_dss (op0));
0ac081f6 6154 return NULL_RTX;
8bb418a3
ZL
6155
6156 case ALTIVEC_BUILTIN_COMPILETIME_ERROR:
6157 arg0 = TREE_VALUE (arglist);
6158 while (TREE_CODE (arg0) == NOP_EXPR || TREE_CODE (arg0) == ADDR_EXPR)
6159 arg0 = TREE_OPERAND (arg0, 0);
6160 error ("invalid parameter combination for `%s' AltiVec intrinsic",
6161 TREE_STRING_POINTER (arg0));
6162
6163 return const0_rtx;
0ac081f6 6164 }
24408032 6165
100c4561
AH
6166 /* Expand abs* operations. */
6167 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6168 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6169 if (d->code == fcode)
6170 return altivec_expand_abs_builtin (d->icode, arglist, target);
6171
ae4b4a02
AH
6172 /* Expand the AltiVec predicates. */
6173 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6174 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
6175 if (dp->code == fcode)
6176 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
6177
6525c0e7
AH
6178 /* LV* are funky. We initialized them differently. */
6179 switch (fcode)
6180 {
6181 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6182 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
6183 arglist, target);
6184 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6185 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
92898235 6186 arglist, target);
6525c0e7 6187 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6188 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
92898235 6189 arglist, target);
6525c0e7 6190 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6191 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
92898235 6192 arglist, target);
6525c0e7 6193 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6194 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
92898235 6195 arglist, target);
6525c0e7 6196 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6197 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
92898235 6198 arglist, target);
6525c0e7 6199 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6200 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
92898235 6201 arglist, target);
6525c0e7
AH
6202 default:
6203 break;
6204 /* Fall through. */
6205 }
95385cbb 6206
92898235 6207 *expandedp = false;
0ac081f6
AH
6208 return NULL_RTX;
6209}
6210
a3170dc6
AH
6211/* Binops that need to be initialized manually, but can be expanded
6212 automagically by rs6000_expand_binop_builtin. */
6213static struct builtin_description bdesc_2arg_spe[] =
6214{
6215 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6216 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6217 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6218 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6219 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6220 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6221 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6222 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6223 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6224 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6225 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6226 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6227 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6228 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6229 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6230 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6231 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6232 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6233 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6234 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6235 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6236 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6237};
6238
6239/* Expand the builtin in EXP and store the result in TARGET. Store
6240 true in *EXPANDEDP if we found a builtin to expand.
6241
6242 This expands the SPE builtins that are not simple unary and binary
6243 operations. */
6244static rtx
a2369ed3 6245spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6246{
6247 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6248 tree arglist = TREE_OPERAND (exp, 1);
6249 tree arg1, arg0;
6250 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6251 enum insn_code icode;
6252 enum machine_mode tmode, mode0;
6253 rtx pat, op0;
6254 struct builtin_description *d;
6255 size_t i;
6256
6257 *expandedp = true;
6258
6259 /* Syntax check for a 5-bit unsigned immediate. */
6260 switch (fcode)
6261 {
6262 case SPE_BUILTIN_EVSTDD:
6263 case SPE_BUILTIN_EVSTDH:
6264 case SPE_BUILTIN_EVSTDW:
6265 case SPE_BUILTIN_EVSTWHE:
6266 case SPE_BUILTIN_EVSTWHO:
6267 case SPE_BUILTIN_EVSTWWE:
6268 case SPE_BUILTIN_EVSTWWO:
6269 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6270 if (TREE_CODE (arg1) != INTEGER_CST
6271 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6272 {
6273 error ("argument 2 must be a 5-bit unsigned literal");
6274 return const0_rtx;
6275 }
6276 break;
6277 default:
6278 break;
6279 }
6280
00332c9f
AH
6281 /* The evsplat*i instructions are not quite generic. */
6282 switch (fcode)
6283 {
6284 case SPE_BUILTIN_EVSPLATFI:
6285 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6286 arglist, target);
6287 case SPE_BUILTIN_EVSPLATI:
6288 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
6289 arglist, target);
6290 default:
6291 break;
6292 }
6293
a3170dc6
AH
6294 d = (struct builtin_description *) bdesc_2arg_spe;
6295 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
6296 if (d->code == fcode)
6297 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6298
6299 d = (struct builtin_description *) bdesc_spe_predicates;
6300 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
6301 if (d->code == fcode)
6302 return spe_expand_predicate_builtin (d->icode, arglist, target);
6303
6304 d = (struct builtin_description *) bdesc_spe_evsel;
6305 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
6306 if (d->code == fcode)
6307 return spe_expand_evsel_builtin (d->icode, arglist, target);
6308
6309 switch (fcode)
6310 {
6311 case SPE_BUILTIN_EVSTDDX:
6312 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
6313 case SPE_BUILTIN_EVSTDHX:
6314 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
6315 case SPE_BUILTIN_EVSTDWX:
6316 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
6317 case SPE_BUILTIN_EVSTWHEX:
6318 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
6319 case SPE_BUILTIN_EVSTWHOX:
6320 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
6321 case SPE_BUILTIN_EVSTWWEX:
6322 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
6323 case SPE_BUILTIN_EVSTWWOX:
6324 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
6325 case SPE_BUILTIN_EVSTDD:
6326 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
6327 case SPE_BUILTIN_EVSTDH:
6328 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
6329 case SPE_BUILTIN_EVSTDW:
6330 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
6331 case SPE_BUILTIN_EVSTWHE:
6332 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
6333 case SPE_BUILTIN_EVSTWHO:
6334 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
6335 case SPE_BUILTIN_EVSTWWE:
6336 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
6337 case SPE_BUILTIN_EVSTWWO:
6338 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
6339 case SPE_BUILTIN_MFSPEFSCR:
6340 icode = CODE_FOR_spe_mfspefscr;
6341 tmode = insn_data[icode].operand[0].mode;
6342
6343 if (target == 0
6344 || GET_MODE (target) != tmode
6345 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6346 target = gen_reg_rtx (tmode);
6347
6348 pat = GEN_FCN (icode) (target);
6349 if (! pat)
6350 return 0;
6351 emit_insn (pat);
6352 return target;
6353 case SPE_BUILTIN_MTSPEFSCR:
6354 icode = CODE_FOR_spe_mtspefscr;
6355 arg0 = TREE_VALUE (arglist);
6356 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6357 mode0 = insn_data[icode].operand[0].mode;
6358
6359 if (arg0 == error_mark_node)
6360 return const0_rtx;
6361
6362 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6363 op0 = copy_to_mode_reg (mode0, op0);
6364
6365 pat = GEN_FCN (icode) (op0);
6366 if (pat)
6367 emit_insn (pat);
6368 return NULL_RTX;
6369 default:
6370 break;
6371 }
6372
6373 *expandedp = false;
6374 return NULL_RTX;
6375}
6376
6377static rtx
a2369ed3 6378spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6379{
6380 rtx pat, scratch, tmp;
6381 tree form = TREE_VALUE (arglist);
6382 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6383 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6384 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6385 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6386 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6387 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6388 int form_int;
6389 enum rtx_code code;
6390
6391 if (TREE_CODE (form) != INTEGER_CST)
6392 {
6393 error ("argument 1 of __builtin_spe_predicate must be a constant");
6394 return const0_rtx;
6395 }
6396 else
6397 form_int = TREE_INT_CST_LOW (form);
6398
6399 if (mode0 != mode1)
6400 abort ();
6401
6402 if (arg0 == error_mark_node || arg1 == error_mark_node)
6403 return const0_rtx;
6404
6405 if (target == 0
6406 || GET_MODE (target) != SImode
6407 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
6408 target = gen_reg_rtx (SImode);
6409
6410 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6411 op0 = copy_to_mode_reg (mode0, op0);
6412 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6413 op1 = copy_to_mode_reg (mode1, op1);
6414
6415 scratch = gen_reg_rtx (CCmode);
6416
6417 pat = GEN_FCN (icode) (scratch, op0, op1);
6418 if (! pat)
6419 return const0_rtx;
6420 emit_insn (pat);
6421
6422 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
6423 _lower_. We use one compare, but look in different bits of the
6424 CR for each variant.
6425
6426 There are 2 elements in each SPE simd type (upper/lower). The CR
6427 bits are set as follows:
6428
6429 BIT0 | BIT 1 | BIT 2 | BIT 3
6430 U | L | (U | L) | (U & L)
6431
6432 So, for an "all" relationship, BIT 3 would be set.
6433 For an "any" relationship, BIT 2 would be set. Etc.
6434
6435 Following traditional nomenclature, these bits map to:
6436
6437 BIT0 | BIT 1 | BIT 2 | BIT 3
6438 LT | GT | EQ | OV
6439
6440 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
6441 */
6442
6443 switch (form_int)
6444 {
6445 /* All variant. OV bit. */
6446 case 0:
6447 /* We need to get to the OV bit, which is the ORDERED bit. We
6448 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
6449 that's ugly and will trigger a validate_condition_mode abort.
6450 So let's just use another pattern. */
6451 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
6452 return target;
6453 /* Any variant. EQ bit. */
6454 case 1:
6455 code = EQ;
6456 break;
6457 /* Upper variant. LT bit. */
6458 case 2:
6459 code = LT;
6460 break;
6461 /* Lower variant. GT bit. */
6462 case 3:
6463 code = GT;
6464 break;
6465 default:
6466 error ("argument 1 of __builtin_spe_predicate is out of range");
6467 return const0_rtx;
6468 }
6469
6470 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
6471 emit_move_insn (target, tmp);
6472
6473 return target;
6474}
6475
6476/* The evsel builtins look like this:
6477
6478 e = __builtin_spe_evsel_OP (a, b, c, d);
6479
6480 and work like this:
6481
6482 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
6483 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
6484*/
6485
6486static rtx
a2369ed3 6487spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6488{
6489 rtx pat, scratch;
6490 tree arg0 = TREE_VALUE (arglist);
6491 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6492 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6493 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
6494 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6495 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6496 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6497 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
6498 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6499 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6500
6501 if (mode0 != mode1)
6502 abort ();
6503
6504 if (arg0 == error_mark_node || arg1 == error_mark_node
6505 || arg2 == error_mark_node || arg3 == error_mark_node)
6506 return const0_rtx;
6507
6508 if (target == 0
6509 || GET_MODE (target) != mode0
6510 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
6511 target = gen_reg_rtx (mode0);
6512
6513 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6514 op0 = copy_to_mode_reg (mode0, op0);
6515 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6516 op1 = copy_to_mode_reg (mode0, op1);
6517 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6518 op2 = copy_to_mode_reg (mode0, op2);
6519 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
6520 op3 = copy_to_mode_reg (mode0, op3);
6521
6522 /* Generate the compare. */
6523 scratch = gen_reg_rtx (CCmode);
6524 pat = GEN_FCN (icode) (scratch, op0, op1);
6525 if (! pat)
6526 return const0_rtx;
6527 emit_insn (pat);
6528
6529 if (mode0 == V2SImode)
6530 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
6531 else
6532 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
6533
6534 return target;
6535}
6536
0ac081f6
AH
6537/* Expand an expression EXP that calls a built-in function,
6538 with result going to TARGET if that's convenient
6539 (and in mode MODE if that's convenient).
6540 SUBTARGET may be used as the target for computing one of EXP's operands.
6541 IGNORE is nonzero if the value is to be ignored. */
6542
6543static rtx
a2369ed3
DJ
6544rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
6545 enum machine_mode mode ATTRIBUTE_UNUSED,
6546 int ignore ATTRIBUTE_UNUSED)
0ac081f6 6547{
92898235
AH
6548 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6549 tree arglist = TREE_OPERAND (exp, 1);
6550 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6551 struct builtin_description *d;
6552 size_t i;
6553 rtx ret;
6554 bool success;
6555
0ac081f6 6556 if (TARGET_ALTIVEC)
92898235
AH
6557 {
6558 ret = altivec_expand_builtin (exp, target, &success);
6559
a3170dc6
AH
6560 if (success)
6561 return ret;
6562 }
6563 if (TARGET_SPE)
6564 {
6565 ret = spe_expand_builtin (exp, target, &success);
6566
92898235
AH
6567 if (success)
6568 return ret;
6569 }
6570
0559cc77
DE
6571 if (TARGET_ALTIVEC || TARGET_SPE)
6572 {
6573 /* Handle simple unary operations. */
6574 d = (struct builtin_description *) bdesc_1arg;
6575 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
6576 if (d->code == fcode)
6577 return rs6000_expand_unop_builtin (d->icode, arglist, target);
6578
6579 /* Handle simple binary operations. */
6580 d = (struct builtin_description *) bdesc_2arg;
6581 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
6582 if (d->code == fcode)
6583 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6584
6585 /* Handle simple ternary operations. */
6586 d = (struct builtin_description *) bdesc_3arg;
6587 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
6588 if (d->code == fcode)
6589 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
6590 }
0ac081f6
AH
6591
6592 abort ();
92898235 6593 return NULL_RTX;
0ac081f6
AH
6594}
6595
6596static void
863d938c 6597rs6000_init_builtins (void)
0ac081f6 6598{
4a5eab38
PB
6599 V2SI_type_node = build_vector_type (intSI_type_node, 2);
6600 V2SF_type_node = build_vector_type (float_type_node, 2);
6601 V4HI_type_node = build_vector_type (intHI_type_node, 4);
6602 V4SI_type_node = build_vector_type (intSI_type_node, 4);
6603 V4SF_type_node = build_vector_type (float_type_node, 4);
7e463bda 6604 V8HI_type_node = build_vector_type (intHI_type_node, 8);
4a5eab38
PB
6605 V16QI_type_node = build_vector_type (intQI_type_node, 16);
6606
6607 unsigned_V16QI_type_node = build_vector_type (unsigned_intQI_type_node, 16);
6608 unsigned_V8HI_type_node = build_vector_type (unsigned_intHI_type_node, 8);
6609 unsigned_V4SI_type_node = build_vector_type (unsigned_intSI_type_node, 4);
6610
3fdaa45a
AH
6611 opaque_V2SI_type_node = copy_node (V2SI_type_node);
6612 opaque_V2SF_type_node = copy_node (V2SF_type_node);
6035d635 6613 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 6614
8bb418a3
ZL
6615 /* The 'vector bool ...' types must be kept distinct from 'vector unsigned ...'
6616 types, especially in C++ land. Similarly, 'vector pixel' is distinct from
6617 'vector unsigned short'. */
6618
6619 bool_char_type_node = copy_node (unsigned_intQI_type_node);
6620 TYPE_MAIN_VARIANT (bool_char_type_node) = bool_char_type_node;
6621 bool_short_type_node = copy_node (unsigned_intHI_type_node);
6622 TYPE_MAIN_VARIANT (bool_short_type_node) = bool_short_type_node;
6623 bool_int_type_node = copy_node (unsigned_intSI_type_node);
6624 TYPE_MAIN_VARIANT (bool_int_type_node) = bool_int_type_node;
6625 pixel_type_node = copy_node (unsigned_intHI_type_node);
6626 TYPE_MAIN_VARIANT (pixel_type_node) = pixel_type_node;
6627
6628 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6629 get_identifier ("__bool char"),
6630 bool_char_type_node));
6631 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6632 get_identifier ("__bool short"),
6633 bool_short_type_node));
6634 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6635 get_identifier ("__bool int"),
6636 bool_int_type_node));
6637 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6638 get_identifier ("__pixel"),
6639 pixel_type_node));
6640
4a5eab38
PB
6641 bool_V16QI_type_node = build_vector_type (bool_char_type_node, 16);
6642 bool_V8HI_type_node = build_vector_type (bool_short_type_node, 8);
6643 bool_V4SI_type_node = build_vector_type (bool_int_type_node, 4);
6644 pixel_V8HI_type_node = build_vector_type (pixel_type_node, 8);
8bb418a3
ZL
6645
6646 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6647 get_identifier ("__vector unsigned char"),
6648 unsigned_V16QI_type_node));
6649 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6650 get_identifier ("__vector signed char"),
6651 V16QI_type_node));
6652 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6653 get_identifier ("__vector __bool char"),
6654 bool_V16QI_type_node));
6655
6656 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6657 get_identifier ("__vector unsigned short"),
6658 unsigned_V8HI_type_node));
6659 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6660 get_identifier ("__vector signed short"),
6661 V8HI_type_node));
6662 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6663 get_identifier ("__vector __bool short"),
6664 bool_V8HI_type_node));
6665
6666 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6667 get_identifier ("__vector unsigned int"),
6668 unsigned_V4SI_type_node));
6669 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6670 get_identifier ("__vector signed int"),
6671 V4SI_type_node));
6672 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6673 get_identifier ("__vector __bool int"),
6674 bool_V4SI_type_node));
6675
6676 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6677 get_identifier ("__vector float"),
6678 V4SF_type_node));
6679 (*lang_hooks.decls.pushdecl) (build_decl (TYPE_DECL,
6680 get_identifier ("__vector __pixel"),
6681 pixel_V8HI_type_node));
6682
a3170dc6 6683 if (TARGET_SPE)
3fdaa45a 6684 spe_init_builtins ();
0ac081f6
AH
6685 if (TARGET_ALTIVEC)
6686 altivec_init_builtins ();
0559cc77
DE
6687 if (TARGET_ALTIVEC || TARGET_SPE)
6688 rs6000_common_init_builtins ();
0ac081f6
AH
6689}
6690
a3170dc6
AH
6691/* Search through a set of builtins and enable the mask bits.
6692 DESC is an array of builtins.
b6d08ca1 6693 SIZE is the total number of builtins.
a3170dc6
AH
6694 START is the builtin enum at which to start.
6695 END is the builtin enum at which to end. */
0ac081f6 6696static void
a2369ed3
DJ
6697enable_mask_for_builtins (struct builtin_description *desc, int size,
6698 enum rs6000_builtins start,
6699 enum rs6000_builtins end)
a3170dc6
AH
6700{
6701 int i;
6702
6703 for (i = 0; i < size; ++i)
6704 if (desc[i].code == start)
6705 break;
6706
6707 if (i == size)
6708 return;
6709
6710 for (; i < size; ++i)
6711 {
6712 /* Flip all the bits on. */
6713 desc[i].mask = target_flags;
6714 if (desc[i].code == end)
6715 break;
6716 }
6717}
6718
6719static void
863d938c 6720spe_init_builtins (void)
0ac081f6 6721{
a3170dc6
AH
6722 tree endlink = void_list_node;
6723 tree puint_type_node = build_pointer_type (unsigned_type_node);
6724 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 6725 struct builtin_description *d;
0ac081f6
AH
6726 size_t i;
6727
a3170dc6
AH
6728 tree v2si_ftype_4_v2si
6729 = build_function_type
3fdaa45a
AH
6730 (opaque_V2SI_type_node,
6731 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6732 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6733 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6734 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6735 endlink)))));
6736
6737 tree v2sf_ftype_4_v2sf
6738 = build_function_type
3fdaa45a
AH
6739 (opaque_V2SF_type_node,
6740 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6741 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6742 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6743 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6744 endlink)))));
6745
6746 tree int_ftype_int_v2si_v2si
6747 = build_function_type
6748 (integer_type_node,
6749 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6750 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6751 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6752 endlink))));
6753
6754 tree int_ftype_int_v2sf_v2sf
6755 = build_function_type
6756 (integer_type_node,
6757 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6758 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6759 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6760 endlink))));
6761
6762 tree void_ftype_v2si_puint_int
6763 = build_function_type (void_type_node,
3fdaa45a 6764 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6765 tree_cons (NULL_TREE, puint_type_node,
6766 tree_cons (NULL_TREE,
6767 integer_type_node,
6768 endlink))));
6769
6770 tree void_ftype_v2si_puint_char
6771 = build_function_type (void_type_node,
3fdaa45a 6772 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6773 tree_cons (NULL_TREE, puint_type_node,
6774 tree_cons (NULL_TREE,
6775 char_type_node,
6776 endlink))));
6777
6778 tree void_ftype_v2si_pv2si_int
6779 = build_function_type (void_type_node,
3fdaa45a 6780 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6781 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6782 tree_cons (NULL_TREE,
6783 integer_type_node,
6784 endlink))));
6785
6786 tree void_ftype_v2si_pv2si_char
6787 = build_function_type (void_type_node,
3fdaa45a 6788 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6789 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6790 tree_cons (NULL_TREE,
6791 char_type_node,
6792 endlink))));
6793
6794 tree void_ftype_int
6795 = build_function_type (void_type_node,
6796 tree_cons (NULL_TREE, integer_type_node, endlink));
6797
6798 tree int_ftype_void
36e8d515 6799 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
6800
6801 tree v2si_ftype_pv2si_int
3fdaa45a 6802 = build_function_type (opaque_V2SI_type_node,
6035d635 6803 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6804 tree_cons (NULL_TREE, integer_type_node,
6805 endlink)));
6806
6807 tree v2si_ftype_puint_int
3fdaa45a 6808 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6809 tree_cons (NULL_TREE, puint_type_node,
6810 tree_cons (NULL_TREE, integer_type_node,
6811 endlink)));
6812
6813 tree v2si_ftype_pushort_int
3fdaa45a 6814 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6815 tree_cons (NULL_TREE, pushort_type_node,
6816 tree_cons (NULL_TREE, integer_type_node,
6817 endlink)));
6818
00332c9f
AH
6819 tree v2si_ftype_signed_char
6820 = build_function_type (opaque_V2SI_type_node,
6821 tree_cons (NULL_TREE, signed_char_type_node,
6822 endlink));
6823
a3170dc6
AH
6824 /* The initialization of the simple binary and unary builtins is
6825 done in rs6000_common_init_builtins, but we have to enable the
6826 mask bits here manually because we have run out of `target_flags'
6827 bits. We really need to redesign this mask business. */
6828
6829 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
6830 ARRAY_SIZE (bdesc_2arg),
6831 SPE_BUILTIN_EVADDW,
6832 SPE_BUILTIN_EVXOR);
6833 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
6834 ARRAY_SIZE (bdesc_1arg),
6835 SPE_BUILTIN_EVABS,
6836 SPE_BUILTIN_EVSUBFUSIAAW);
6837 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
6838 ARRAY_SIZE (bdesc_spe_predicates),
6839 SPE_BUILTIN_EVCMPEQ,
6840 SPE_BUILTIN_EVFSTSTLT);
6841 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
6842 ARRAY_SIZE (bdesc_spe_evsel),
6843 SPE_BUILTIN_EVSEL_CMPGTS,
6844 SPE_BUILTIN_EVSEL_FSTSTEQ);
6845
36252949
AH
6846 (*lang_hooks.decls.pushdecl)
6847 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
6848 opaque_V2SI_type_node));
6849
a3170dc6
AH
6850 /* Initialize irregular SPE builtins. */
6851
6852 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
6853 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
6854 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
6855 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
6856 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
6857 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
6858 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
6859 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
6860 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
6861 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
6862 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
6863 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
6864 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
6865 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
6866 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
6867 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
6868 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
6869 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
6870
6871 /* Loads. */
6872 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
6873 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
6874 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
6875 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
6876 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
6877 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
6878 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
6879 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
6880 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
6881 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
6882 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
6883 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
6884 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
6885 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
6886 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
6887 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
6888 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
6889 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
6890 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
6891 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
6892 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
6893 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
6894
6895 /* Predicates. */
6896 d = (struct builtin_description *) bdesc_spe_predicates;
6897 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
6898 {
6899 tree type;
6900
6901 switch (insn_data[d->icode].operand[1].mode)
6902 {
6903 case V2SImode:
6904 type = int_ftype_int_v2si_v2si;
6905 break;
6906 case V2SFmode:
6907 type = int_ftype_int_v2sf_v2sf;
6908 break;
6909 default:
6910 abort ();
6911 }
6912
6913 def_builtin (d->mask, d->name, type, d->code);
6914 }
6915
6916 /* Evsel predicates. */
6917 d = (struct builtin_description *) bdesc_spe_evsel;
6918 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
6919 {
6920 tree type;
6921
6922 switch (insn_data[d->icode].operand[1].mode)
6923 {
6924 case V2SImode:
6925 type = v2si_ftype_4_v2si;
6926 break;
6927 case V2SFmode:
6928 type = v2sf_ftype_4_v2sf;
6929 break;
6930 default:
6931 abort ();
6932 }
6933
6934 def_builtin (d->mask, d->name, type, d->code);
6935 }
6936}
6937
6938static void
863d938c 6939altivec_init_builtins (void)
a3170dc6
AH
6940{
6941 struct builtin_description *d;
6942 struct builtin_description_predicates *dp;
6943 size_t i;
6944 tree pfloat_type_node = build_pointer_type (float_type_node);
6945 tree pint_type_node = build_pointer_type (integer_type_node);
6946 tree pshort_type_node = build_pointer_type (short_integer_type_node);
6947 tree pchar_type_node = build_pointer_type (char_type_node);
6948
6949 tree pvoid_type_node = build_pointer_type (void_type_node);
6950
0dbc3651
ZW
6951 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
6952 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
6953 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
6954 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
6955
6956 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
6957
a3170dc6
AH
6958 tree int_ftype_int_v4si_v4si
6959 = build_function_type_list (integer_type_node,
6960 integer_type_node, V4SI_type_node,
6961 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6962 tree v4sf_ftype_pcfloat
6963 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 6964 tree void_ftype_pfloat_v4sf
b4de2f7d 6965 = build_function_type_list (void_type_node,
a3170dc6 6966 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
6967 tree v4si_ftype_pcint
6968 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
6969 tree void_ftype_pint_v4si
b4de2f7d
AH
6970 = build_function_type_list (void_type_node,
6971 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6972 tree v8hi_ftype_pcshort
6973 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 6974 tree void_ftype_pshort_v8hi
b4de2f7d
AH
6975 = build_function_type_list (void_type_node,
6976 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
6977 tree v16qi_ftype_pcchar
6978 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 6979 tree void_ftype_pchar_v16qi
b4de2f7d
AH
6980 = build_function_type_list (void_type_node,
6981 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 6982 tree void_ftype_v4si
b4de2f7d 6983 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6984 tree v8hi_ftype_void
6985 = build_function_type (V8HI_type_node, void_list_node);
6986 tree void_ftype_void
6987 = build_function_type (void_type_node, void_list_node);
6988 tree void_ftype_qi
6989 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651 6990
b4a62fa0 6991 tree v16qi_ftype_long_pcvoid
a3170dc6 6992 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
6993 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6994 tree v8hi_ftype_long_pcvoid
a3170dc6 6995 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
6996 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6997 tree v4si_ftype_long_pcvoid
a3170dc6 6998 = build_function_type_list (V4SI_type_node,
b4a62fa0 6999 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 7000
b4a62fa0 7001 tree void_ftype_v4si_long_pvoid
b4de2f7d 7002 = build_function_type_list (void_type_node,
b4a62fa0 7003 V4SI_type_node, long_integer_type_node,
b4de2f7d 7004 pvoid_type_node, NULL_TREE);
b4a62fa0 7005 tree void_ftype_v16qi_long_pvoid
b4de2f7d 7006 = build_function_type_list (void_type_node,
b4a62fa0 7007 V16QI_type_node, long_integer_type_node,
b4de2f7d 7008 pvoid_type_node, NULL_TREE);
b4a62fa0 7009 tree void_ftype_v8hi_long_pvoid
b4de2f7d 7010 = build_function_type_list (void_type_node,
b4a62fa0 7011 V8HI_type_node, long_integer_type_node,
b4de2f7d 7012 pvoid_type_node, NULL_TREE);
a3170dc6
AH
7013 tree int_ftype_int_v8hi_v8hi
7014 = build_function_type_list (integer_type_node,
7015 integer_type_node, V8HI_type_node,
7016 V8HI_type_node, NULL_TREE);
7017 tree int_ftype_int_v16qi_v16qi
7018 = build_function_type_list (integer_type_node,
7019 integer_type_node, V16QI_type_node,
7020 V16QI_type_node, NULL_TREE);
7021 tree int_ftype_int_v4sf_v4sf
7022 = build_function_type_list (integer_type_node,
7023 integer_type_node, V4SF_type_node,
7024 V4SF_type_node, NULL_TREE);
7025 tree v4si_ftype_v4si
7026 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
7027 tree v8hi_ftype_v8hi
7028 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
7029 tree v16qi_ftype_v16qi
7030 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
7031 tree v4sf_ftype_v4sf
7032 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
8bb418a3 7033 tree void_ftype_pcvoid_int_int
a3170dc6 7034 = build_function_type_list (void_type_node,
0dbc3651 7035 pcvoid_type_node, integer_type_node,
8bb418a3
ZL
7036 integer_type_node, NULL_TREE);
7037 tree int_ftype_pcchar
7038 = build_function_type_list (integer_type_node,
7039 pcchar_type_node, NULL_TREE);
7040
0dbc3651
ZW
7041 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
7042 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
7043 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
7044 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
7045 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
7046 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
7047 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
7048 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
7049 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
7050 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
7051 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
7052 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
7053 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
7054 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
7055 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
7056 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
7057 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
7058 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
7059 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
7060 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
7061 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
7062 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
7063 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
7064 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
7065 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
7066 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
7067 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
7068 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
7069 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
7070 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
7071 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
7072 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6 7073
8bb418a3
ZL
7074 /* See altivec.h for usage of "__builtin_altivec_compiletime_error". */
7075 def_builtin (MASK_ALTIVEC, "__builtin_altivec_compiletime_error", int_ftype_pcchar,
7076 ALTIVEC_BUILTIN_COMPILETIME_ERROR);
7077
a3170dc6
AH
7078 /* Add the DST variants. */
7079 d = (struct builtin_description *) bdesc_dst;
7080 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
8bb418a3 7081 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_int, d->code);
a3170dc6
AH
7082
7083 /* Initialize the predicates. */
7084 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
7085 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
7086 {
7087 enum machine_mode mode1;
7088 tree type;
7089
7090 mode1 = insn_data[dp->icode].operand[1].mode;
7091
7092 switch (mode1)
7093 {
7094 case V4SImode:
7095 type = int_ftype_int_v4si_v4si;
7096 break;
7097 case V8HImode:
7098 type = int_ftype_int_v8hi_v8hi;
7099 break;
7100 case V16QImode:
7101 type = int_ftype_int_v16qi_v16qi;
7102 break;
7103 case V4SFmode:
7104 type = int_ftype_int_v4sf_v4sf;
7105 break;
7106 default:
7107 abort ();
7108 }
7109
7110 def_builtin (dp->mask, dp->name, type, dp->code);
7111 }
7112
7113 /* Initialize the abs* operators. */
7114 d = (struct builtin_description *) bdesc_abs;
7115 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
7116 {
7117 enum machine_mode mode0;
7118 tree type;
7119
7120 mode0 = insn_data[d->icode].operand[0].mode;
7121
7122 switch (mode0)
7123 {
7124 case V4SImode:
7125 type = v4si_ftype_v4si;
7126 break;
7127 case V8HImode:
7128 type = v8hi_ftype_v8hi;
7129 break;
7130 case V16QImode:
7131 type = v16qi_ftype_v16qi;
7132 break;
7133 case V4SFmode:
7134 type = v4sf_ftype_v4sf;
7135 break;
7136 default:
7137 abort ();
7138 }
7139
7140 def_builtin (d->mask, d->name, type, d->code);
7141 }
7142}
7143
7144static void
863d938c 7145rs6000_common_init_builtins (void)
a3170dc6
AH
7146{
7147 struct builtin_description *d;
7148 size_t i;
7149
7150 tree v4sf_ftype_v4sf_v4sf_v16qi
7151 = build_function_type_list (V4SF_type_node,
7152 V4SF_type_node, V4SF_type_node,
7153 V16QI_type_node, NULL_TREE);
7154 tree v4si_ftype_v4si_v4si_v16qi
7155 = build_function_type_list (V4SI_type_node,
7156 V4SI_type_node, V4SI_type_node,
7157 V16QI_type_node, NULL_TREE);
7158 tree v8hi_ftype_v8hi_v8hi_v16qi
7159 = build_function_type_list (V8HI_type_node,
7160 V8HI_type_node, V8HI_type_node,
7161 V16QI_type_node, NULL_TREE);
7162 tree v16qi_ftype_v16qi_v16qi_v16qi
7163 = build_function_type_list (V16QI_type_node,
7164 V16QI_type_node, V16QI_type_node,
7165 V16QI_type_node, NULL_TREE);
b9e4e5d1
ZL
7166 tree v4si_ftype_int
7167 = build_function_type_list (V4SI_type_node, integer_type_node, NULL_TREE);
7168 tree v8hi_ftype_int
7169 = build_function_type_list (V8HI_type_node, integer_type_node, NULL_TREE);
7170 tree v16qi_ftype_int
7171 = build_function_type_list (V16QI_type_node, integer_type_node, NULL_TREE);
a3170dc6
AH
7172 tree v8hi_ftype_v16qi
7173 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
7174 tree v4sf_ftype_v4sf
7175 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
7176
7177 tree v2si_ftype_v2si_v2si
2abe3e28
AH
7178 = build_function_type_list (opaque_V2SI_type_node,
7179 opaque_V2SI_type_node,
7180 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7181
7182 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
7183 = build_function_type_list (opaque_V2SF_type_node,
7184 opaque_V2SF_type_node,
7185 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7186
7187 tree v2si_ftype_int_int
2abe3e28 7188 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7189 integer_type_node, integer_type_node,
7190 NULL_TREE);
7191
7192 tree v2si_ftype_v2si
2abe3e28
AH
7193 = build_function_type_list (opaque_V2SI_type_node,
7194 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7195
7196 tree v2sf_ftype_v2sf
2abe3e28
AH
7197 = build_function_type_list (opaque_V2SF_type_node,
7198 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7199
7200 tree v2sf_ftype_v2si
2abe3e28
AH
7201 = build_function_type_list (opaque_V2SF_type_node,
7202 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
7203
7204 tree v2si_ftype_v2sf
2abe3e28
AH
7205 = build_function_type_list (opaque_V2SI_type_node,
7206 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
7207
7208 tree v2si_ftype_v2si_char
2abe3e28
AH
7209 = build_function_type_list (opaque_V2SI_type_node,
7210 opaque_V2SI_type_node,
7211 char_type_node, NULL_TREE);
a3170dc6
AH
7212
7213 tree v2si_ftype_int_char
2abe3e28 7214 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
7215 integer_type_node, char_type_node, NULL_TREE);
7216
7217 tree v2si_ftype_char
2abe3e28
AH
7218 = build_function_type_list (opaque_V2SI_type_node,
7219 char_type_node, NULL_TREE);
a3170dc6
AH
7220
7221 tree int_ftype_int_int
7222 = build_function_type_list (integer_type_node,
7223 integer_type_node, integer_type_node,
7224 NULL_TREE);
95385cbb 7225
0ac081f6 7226 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
7227 = build_function_type_list (V4SI_type_node,
7228 V4SI_type_node, V4SI_type_node, NULL_TREE);
b9e4e5d1 7229 tree v4sf_ftype_v4si_int
b4de2f7d 7230 = build_function_type_list (V4SF_type_node,
b9e4e5d1
ZL
7231 V4SI_type_node, integer_type_node, NULL_TREE);
7232 tree v4si_ftype_v4sf_int
b4de2f7d 7233 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7234 V4SF_type_node, integer_type_node, NULL_TREE);
7235 tree v4si_ftype_v4si_int
b4de2f7d 7236 = build_function_type_list (V4SI_type_node,
b9e4e5d1
ZL
7237 V4SI_type_node, integer_type_node, NULL_TREE);
7238 tree v8hi_ftype_v8hi_int
b4de2f7d 7239 = build_function_type_list (V8HI_type_node,
b9e4e5d1
ZL
7240 V8HI_type_node, integer_type_node, NULL_TREE);
7241 tree v16qi_ftype_v16qi_int
b4de2f7d 7242 = build_function_type_list (V16QI_type_node,
b9e4e5d1
ZL
7243 V16QI_type_node, integer_type_node, NULL_TREE);
7244 tree v16qi_ftype_v16qi_v16qi_int
b4de2f7d
AH
7245 = build_function_type_list (V16QI_type_node,
7246 V16QI_type_node, V16QI_type_node,
b9e4e5d1
ZL
7247 integer_type_node, NULL_TREE);
7248 tree v8hi_ftype_v8hi_v8hi_int
b4de2f7d
AH
7249 = build_function_type_list (V8HI_type_node,
7250 V8HI_type_node, V8HI_type_node,
b9e4e5d1
ZL
7251 integer_type_node, NULL_TREE);
7252 tree v4si_ftype_v4si_v4si_int
b4de2f7d
AH
7253 = build_function_type_list (V4SI_type_node,
7254 V4SI_type_node, V4SI_type_node,
b9e4e5d1
ZL
7255 integer_type_node, NULL_TREE);
7256 tree v4sf_ftype_v4sf_v4sf_int
b4de2f7d
AH
7257 = build_function_type_list (V4SF_type_node,
7258 V4SF_type_node, V4SF_type_node,
b9e4e5d1 7259 integer_type_node, NULL_TREE);
0ac081f6 7260 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
7261 = build_function_type_list (V4SF_type_node,
7262 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 7263 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
7264 = build_function_type_list (V4SF_type_node,
7265 V4SF_type_node, V4SF_type_node,
7266 V4SI_type_node, NULL_TREE);
2212663f 7267 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
7268 = build_function_type_list (V4SF_type_node,
7269 V4SF_type_node, V4SF_type_node,
7270 V4SF_type_node, NULL_TREE);
617e0e1d 7271 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
7272 = build_function_type_list (V4SI_type_node,
7273 V4SI_type_node, V4SI_type_node,
7274 V4SI_type_node, NULL_TREE);
0ac081f6 7275 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
7276 = build_function_type_list (V8HI_type_node,
7277 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 7278 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
7279 = build_function_type_list (V8HI_type_node,
7280 V8HI_type_node, V8HI_type_node,
7281 V8HI_type_node, NULL_TREE);
2212663f 7282 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
7283 = build_function_type_list (V4SI_type_node,
7284 V8HI_type_node, V8HI_type_node,
7285 V4SI_type_node, NULL_TREE);
2212663f 7286 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
7287 = build_function_type_list (V4SI_type_node,
7288 V16QI_type_node, V16QI_type_node,
7289 V4SI_type_node, NULL_TREE);
0ac081f6 7290 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
7291 = build_function_type_list (V16QI_type_node,
7292 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7293 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
7294 = build_function_type_list (V4SI_type_node,
7295 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 7296 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
7297 = build_function_type_list (V8HI_type_node,
7298 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7299 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
7300 = build_function_type_list (V4SI_type_node,
7301 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7302 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
7303 = build_function_type_list (V8HI_type_node,
7304 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 7305 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
7306 = build_function_type_list (V16QI_type_node,
7307 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7308 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
7309 = build_function_type_list (V4SI_type_node,
7310 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 7311 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
7312 = build_function_type_list (V4SI_type_node,
7313 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7314 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
7315 = build_function_type_list (V4SI_type_node,
7316 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7317 tree v4si_ftype_v8hi
7318 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
7319 tree int_ftype_v4si_v4si
7320 = build_function_type_list (integer_type_node,
7321 V4SI_type_node, V4SI_type_node, NULL_TREE);
7322 tree int_ftype_v4sf_v4sf
7323 = build_function_type_list (integer_type_node,
7324 V4SF_type_node, V4SF_type_node, NULL_TREE);
7325 tree int_ftype_v16qi_v16qi
7326 = build_function_type_list (integer_type_node,
7327 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7328 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
7329 = build_function_type_list (integer_type_node,
7330 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7331
6f317ef3 7332 /* Add the simple ternary operators. */
2212663f 7333 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 7334 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
7335 {
7336
7337 enum machine_mode mode0, mode1, mode2, mode3;
7338 tree type;
7339
0559cc77 7340 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7341 continue;
7342
7343 mode0 = insn_data[d->icode].operand[0].mode;
7344 mode1 = insn_data[d->icode].operand[1].mode;
7345 mode2 = insn_data[d->icode].operand[2].mode;
7346 mode3 = insn_data[d->icode].operand[3].mode;
7347
7348 /* When all four are of the same mode. */
7349 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
7350 {
7351 switch (mode0)
7352 {
617e0e1d
DB
7353 case V4SImode:
7354 type = v4si_ftype_v4si_v4si_v4si;
7355 break;
2212663f
DB
7356 case V4SFmode:
7357 type = v4sf_ftype_v4sf_v4sf_v4sf;
7358 break;
7359 case V8HImode:
7360 type = v8hi_ftype_v8hi_v8hi_v8hi;
7361 break;
7362 case V16QImode:
7363 type = v16qi_ftype_v16qi_v16qi_v16qi;
7364 break;
7365 default:
7366 abort();
7367 }
7368 }
7369 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
7370 {
7371 switch (mode0)
7372 {
7373 case V4SImode:
7374 type = v4si_ftype_v4si_v4si_v16qi;
7375 break;
7376 case V4SFmode:
7377 type = v4sf_ftype_v4sf_v4sf_v16qi;
7378 break;
7379 case V8HImode:
7380 type = v8hi_ftype_v8hi_v8hi_v16qi;
7381 break;
7382 case V16QImode:
7383 type = v16qi_ftype_v16qi_v16qi_v16qi;
7384 break;
7385 default:
7386 abort();
7387 }
7388 }
7389 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
7390 && mode3 == V4SImode)
24408032 7391 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
7392 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
7393 && mode3 == V4SImode)
24408032 7394 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
7395 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
7396 && mode3 == V4SImode)
24408032
AH
7397 type = v4sf_ftype_v4sf_v4sf_v4si;
7398
7399 /* vchar, vchar, vchar, 4 bit literal. */
7400 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
7401 && mode3 == QImode)
b9e4e5d1 7402 type = v16qi_ftype_v16qi_v16qi_int;
24408032
AH
7403
7404 /* vshort, vshort, vshort, 4 bit literal. */
7405 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
7406 && mode3 == QImode)
b9e4e5d1 7407 type = v8hi_ftype_v8hi_v8hi_int;
24408032
AH
7408
7409 /* vint, vint, vint, 4 bit literal. */
7410 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
7411 && mode3 == QImode)
b9e4e5d1 7412 type = v4si_ftype_v4si_v4si_int;
24408032
AH
7413
7414 /* vfloat, vfloat, vfloat, 4 bit literal. */
7415 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
7416 && mode3 == QImode)
b9e4e5d1 7417 type = v4sf_ftype_v4sf_v4sf_int;
24408032 7418
2212663f
DB
7419 else
7420 abort ();
7421
7422 def_builtin (d->mask, d->name, type, d->code);
7423 }
7424
0ac081f6 7425 /* Add the simple binary operators. */
00b960c7 7426 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 7427 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
7428 {
7429 enum machine_mode mode0, mode1, mode2;
7430 tree type;
7431
0559cc77 7432 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
7433 continue;
7434
7435 mode0 = insn_data[d->icode].operand[0].mode;
7436 mode1 = insn_data[d->icode].operand[1].mode;
7437 mode2 = insn_data[d->icode].operand[2].mode;
7438
7439 /* When all three operands are of the same mode. */
7440 if (mode0 == mode1 && mode1 == mode2)
7441 {
7442 switch (mode0)
7443 {
7444 case V4SFmode:
7445 type = v4sf_ftype_v4sf_v4sf;
7446 break;
7447 case V4SImode:
7448 type = v4si_ftype_v4si_v4si;
7449 break;
7450 case V16QImode:
7451 type = v16qi_ftype_v16qi_v16qi;
7452 break;
7453 case V8HImode:
7454 type = v8hi_ftype_v8hi_v8hi;
7455 break;
a3170dc6
AH
7456 case V2SImode:
7457 type = v2si_ftype_v2si_v2si;
7458 break;
7459 case V2SFmode:
7460 type = v2sf_ftype_v2sf_v2sf;
7461 break;
7462 case SImode:
7463 type = int_ftype_int_int;
7464 break;
0ac081f6
AH
7465 default:
7466 abort ();
7467 }
7468 }
7469
7470 /* A few other combos we really don't want to do manually. */
7471
7472 /* vint, vfloat, vfloat. */
7473 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
7474 type = v4si_ftype_v4sf_v4sf;
7475
7476 /* vshort, vchar, vchar. */
7477 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
7478 type = v8hi_ftype_v16qi_v16qi;
7479
7480 /* vint, vshort, vshort. */
7481 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
7482 type = v4si_ftype_v8hi_v8hi;
7483
7484 /* vshort, vint, vint. */
7485 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
7486 type = v8hi_ftype_v4si_v4si;
7487
7488 /* vchar, vshort, vshort. */
7489 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
7490 type = v16qi_ftype_v8hi_v8hi;
7491
7492 /* vint, vchar, vint. */
7493 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
7494 type = v4si_ftype_v16qi_v4si;
7495
fa066a23
AH
7496 /* vint, vchar, vchar. */
7497 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
7498 type = v4si_ftype_v16qi_v16qi;
7499
0ac081f6
AH
7500 /* vint, vshort, vint. */
7501 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
7502 type = v4si_ftype_v8hi_v4si;
2212663f
DB
7503
7504 /* vint, vint, 5 bit literal. */
7505 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7506 type = v4si_ftype_v4si_int;
2212663f
DB
7507
7508 /* vshort, vshort, 5 bit literal. */
7509 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
b9e4e5d1 7510 type = v8hi_ftype_v8hi_int;
2212663f
DB
7511
7512 /* vchar, vchar, 5 bit literal. */
7513 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
b9e4e5d1 7514 type = v16qi_ftype_v16qi_int;
0ac081f6 7515
617e0e1d
DB
7516 /* vfloat, vint, 5 bit literal. */
7517 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
b9e4e5d1 7518 type = v4sf_ftype_v4si_int;
617e0e1d
DB
7519
7520 /* vint, vfloat, 5 bit literal. */
7521 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
b9e4e5d1 7522 type = v4si_ftype_v4sf_int;
617e0e1d 7523
a3170dc6
AH
7524 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
7525 type = v2si_ftype_int_int;
7526
7527 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
7528 type = v2si_ftype_v2si_char;
7529
7530 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
7531 type = v2si_ftype_int_char;
7532
0ac081f6
AH
7533 /* int, x, x. */
7534 else if (mode0 == SImode)
7535 {
7536 switch (mode1)
7537 {
7538 case V4SImode:
7539 type = int_ftype_v4si_v4si;
7540 break;
7541 case V4SFmode:
7542 type = int_ftype_v4sf_v4sf;
7543 break;
7544 case V16QImode:
7545 type = int_ftype_v16qi_v16qi;
7546 break;
7547 case V8HImode:
7548 type = int_ftype_v8hi_v8hi;
7549 break;
7550 default:
7551 abort ();
7552 }
7553 }
7554
7555 else
7556 abort ();
7557
2212663f
DB
7558 def_builtin (d->mask, d->name, type, d->code);
7559 }
24408032 7560
2212663f
DB
7561 /* Add the simple unary operators. */
7562 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 7563 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
7564 {
7565 enum machine_mode mode0, mode1;
7566 tree type;
7567
0559cc77 7568 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7569 continue;
7570
7571 mode0 = insn_data[d->icode].operand[0].mode;
7572 mode1 = insn_data[d->icode].operand[1].mode;
7573
7574 if (mode0 == V4SImode && mode1 == QImode)
b9e4e5d1 7575 type = v4si_ftype_int;
2212663f 7576 else if (mode0 == V8HImode && mode1 == QImode)
b9e4e5d1 7577 type = v8hi_ftype_int;
2212663f 7578 else if (mode0 == V16QImode && mode1 == QImode)
b9e4e5d1 7579 type = v16qi_ftype_int;
617e0e1d
DB
7580 else if (mode0 == V4SFmode && mode1 == V4SFmode)
7581 type = v4sf_ftype_v4sf;
20e26713
AH
7582 else if (mode0 == V8HImode && mode1 == V16QImode)
7583 type = v8hi_ftype_v16qi;
7584 else if (mode0 == V4SImode && mode1 == V8HImode)
7585 type = v4si_ftype_v8hi;
a3170dc6
AH
7586 else if (mode0 == V2SImode && mode1 == V2SImode)
7587 type = v2si_ftype_v2si;
7588 else if (mode0 == V2SFmode && mode1 == V2SFmode)
7589 type = v2sf_ftype_v2sf;
7590 else if (mode0 == V2SFmode && mode1 == V2SImode)
7591 type = v2sf_ftype_v2si;
7592 else if (mode0 == V2SImode && mode1 == V2SFmode)
7593 type = v2si_ftype_v2sf;
7594 else if (mode0 == V2SImode && mode1 == QImode)
7595 type = v2si_ftype_char;
2212663f
DB
7596 else
7597 abort ();
7598
0ac081f6
AH
7599 def_builtin (d->mask, d->name, type, d->code);
7600 }
7601}
7602
c15c90bb
ZW
7603static void
7604rs6000_init_libfuncs (void)
7605{
7606 if (!TARGET_HARD_FLOAT)
7607 return;
7608
c9034561 7609 if (DEFAULT_ABI != ABI_V4)
c15c90bb 7610 {
c9034561 7611 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 7612 {
c9034561 7613 /* AIX library routines for float->int conversion. */
85363ca0
ZW
7614 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
7615 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
7616 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
7617 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
7618 }
7619
c9034561 7620 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7621 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
7622 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
7623 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
7624 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
7625 }
c9034561 7626 else
c15c90bb 7627 {
c9034561 7628 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7629
7630 set_optab_libfunc (add_optab, TFmode, "_q_add");
7631 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
7632 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
7633 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
7634 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
7635 if (TARGET_PPC_GPOPT || TARGET_POWER2)
7636 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
7637
c9034561
ZW
7638 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
7639 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
7640 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
7641 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
7642 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
7643 set_optab_libfunc (le_optab, TFmode, "_q_fle");
7644
85363ca0
ZW
7645 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
7646 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
7647 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
7648 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
7649 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
7650 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
7651 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
7652 }
7653}
35aff10b 7654\f
7e69e155
MM
7655/* Expand a block move operation, and return 1 if successful. Return 0
7656 if we should let the compiler generate normal code.
7657
7658 operands[0] is the destination
7659 operands[1] is the source
7660 operands[2] is the length
7661 operands[3] is the alignment */
7662
3933e0e1
MM
7663#define MAX_MOVE_REG 4
7664
7e69e155 7665int
a2369ed3 7666expand_block_move (rtx operands[])
7e69e155 7667{
b6c9286a
MM
7668 rtx orig_dest = operands[0];
7669 rtx orig_src = operands[1];
7e69e155 7670 rtx bytes_rtx = operands[2];
7e69e155 7671 rtx align_rtx = operands[3];
3933e0e1 7672 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 7673 int align;
3933e0e1
MM
7674 int bytes;
7675 int offset;
7e69e155 7676 int move_bytes;
cabfd258
GK
7677 rtx stores[MAX_MOVE_REG];
7678 int num_reg = 0;
7e69e155 7679
3933e0e1 7680 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 7681 if (! constp)
3933e0e1
MM
7682 return 0;
7683
5ee95df6
FS
7684 /* If this is not a fixed size alignment, abort */
7685 if (GET_CODE (align_rtx) != CONST_INT)
7686 abort ();
7687 align = INTVAL (align_rtx);
7688
7e69e155 7689 /* Anything to move? */
3933e0e1
MM
7690 bytes = INTVAL (bytes_rtx);
7691 if (bytes <= 0)
7e69e155
MM
7692 return 1;
7693
ea9982a8 7694 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 7695 reg_parm_stack_space. */
ea9982a8 7696 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
7697 return 0;
7698
cabfd258 7699 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 7700 {
cabfd258 7701 union {
a2369ed3
DJ
7702 rtx (*movstrsi) (rtx, rtx, rtx, rtx);
7703 rtx (*mov) (rtx, rtx);
cabfd258
GK
7704 } gen_func;
7705 enum machine_mode mode = BLKmode;
7706 rtx src, dest;
7707
7708 if (TARGET_STRING
7709 && bytes > 24 /* move up to 32 bytes at a time */
7710 && ! fixed_regs[5]
7711 && ! fixed_regs[6]
7712 && ! fixed_regs[7]
7713 && ! fixed_regs[8]
7714 && ! fixed_regs[9]
7715 && ! fixed_regs[10]
7716 && ! fixed_regs[11]
7717 && ! fixed_regs[12])
7e69e155 7718 {
cabfd258
GK
7719 move_bytes = (bytes > 32) ? 32 : bytes;
7720 gen_func.movstrsi = gen_movstrsi_8reg;
7721 }
7722 else if (TARGET_STRING
7723 && bytes > 16 /* move up to 24 bytes at a time */
7724 && ! fixed_regs[5]
7725 && ! fixed_regs[6]
7726 && ! fixed_regs[7]
7727 && ! fixed_regs[8]
7728 && ! fixed_regs[9]
7729 && ! fixed_regs[10])
7730 {
7731 move_bytes = (bytes > 24) ? 24 : bytes;
7732 gen_func.movstrsi = gen_movstrsi_6reg;
7733 }
7734 else if (TARGET_STRING
7735 && bytes > 8 /* move up to 16 bytes at a time */
7736 && ! fixed_regs[5]
7737 && ! fixed_regs[6]
7738 && ! fixed_regs[7]
7739 && ! fixed_regs[8])
7740 {
7741 move_bytes = (bytes > 16) ? 16 : bytes;
7742 gen_func.movstrsi = gen_movstrsi_4reg;
7743 }
7744 else if (bytes >= 8 && TARGET_POWERPC64
7745 /* 64-bit loads and stores require word-aligned
7746 displacements. */
7747 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
7748 {
7749 move_bytes = 8;
7750 mode = DImode;
7751 gen_func.mov = gen_movdi;
7752 }
7753 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
7754 { /* move up to 8 bytes at a time */
7755 move_bytes = (bytes > 8) ? 8 : bytes;
7756 gen_func.movstrsi = gen_movstrsi_2reg;
7757 }
7758 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
7759 { /* move 4 bytes */
7760 move_bytes = 4;
7761 mode = SImode;
7762 gen_func.mov = gen_movsi;
7763 }
7764 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
7765 { /* move 2 bytes */
7766 move_bytes = 2;
7767 mode = HImode;
7768 gen_func.mov = gen_movhi;
7769 }
7770 else if (TARGET_STRING && bytes > 1)
7771 { /* move up to 4 bytes at a time */
7772 move_bytes = (bytes > 4) ? 4 : bytes;
7773 gen_func.movstrsi = gen_movstrsi_1reg;
7774 }
7775 else /* move 1 byte at a time */
7776 {
7777 move_bytes = 1;
7778 mode = QImode;
7779 gen_func.mov = gen_movqi;
7780 }
7781
7782 src = adjust_address (orig_src, mode, offset);
7783 dest = adjust_address (orig_dest, mode, offset);
7784
7785 if (mode != BLKmode)
7786 {
7787 rtx tmp_reg = gen_reg_rtx (mode);
7788
7789 emit_insn ((*gen_func.mov) (tmp_reg, src));
7790 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 7791 }
3933e0e1 7792
cabfd258
GK
7793 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
7794 {
7795 int i;
7796 for (i = 0; i < num_reg; i++)
7797 emit_insn (stores[i]);
7798 num_reg = 0;
7799 }
35aff10b 7800
cabfd258 7801 if (mode == BLKmode)
7e69e155 7802 {
cabfd258
GK
7803 /* Move the address into scratch registers. The movstrsi
7804 patterns require zero offset. */
7805 if (!REG_P (XEXP (src, 0)))
b6c9286a 7806 {
cabfd258
GK
7807 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
7808 src = replace_equiv_address (src, src_reg);
b6c9286a 7809 }
cabfd258
GK
7810 set_mem_size (src, GEN_INT (move_bytes));
7811
7812 if (!REG_P (XEXP (dest, 0)))
3933e0e1 7813 {
cabfd258
GK
7814 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
7815 dest = replace_equiv_address (dest, dest_reg);
7e69e155 7816 }
cabfd258
GK
7817 set_mem_size (dest, GEN_INT (move_bytes));
7818
7819 emit_insn ((*gen_func.movstrsi) (dest, src,
7820 GEN_INT (move_bytes & 31),
7821 align_rtx));
7e69e155 7822 }
7e69e155
MM
7823 }
7824
7825 return 1;
7826}
7827
9878760c
RK
7828\f
7829/* Return 1 if OP is a load multiple operation. It is known to be a
7830 PARALLEL and the first section will be tested. */
7831
7832int
a2369ed3 7833load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7834{
7835 int count = XVECLEN (op, 0);
e2c953b6 7836 unsigned int dest_regno;
9878760c
RK
7837 rtx src_addr;
7838 int i;
7839
7840 /* Perform a quick check so we don't blow up below. */
7841 if (count <= 1
7842 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7843 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7844 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7845 return 0;
7846
7847 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7848 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7849
7850 for (i = 1; i < count; i++)
7851 {
7852 rtx elt = XVECEXP (op, 0, i);
7853
7854 if (GET_CODE (elt) != SET
7855 || GET_CODE (SET_DEST (elt)) != REG
7856 || GET_MODE (SET_DEST (elt)) != SImode
7857 || REGNO (SET_DEST (elt)) != dest_regno + i
7858 || GET_CODE (SET_SRC (elt)) != MEM
7859 || GET_MODE (SET_SRC (elt)) != SImode
7860 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
7861 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
7862 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
7863 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
7864 return 0;
7865 }
7866
7867 return 1;
7868}
7869
7870/* Similar, but tests for store multiple. Here, the second vector element
7871 is a CLOBBER. It will be tested later. */
7872
7873int
a2369ed3 7874store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7875{
7876 int count = XVECLEN (op, 0) - 1;
e2c953b6 7877 unsigned int src_regno;
9878760c
RK
7878 rtx dest_addr;
7879 int i;
7880
7881 /* Perform a quick check so we don't blow up below. */
7882 if (count <= 1
7883 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7884 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7885 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7886 return 0;
7887
7888 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7889 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7890
7891 for (i = 1; i < count; i++)
7892 {
7893 rtx elt = XVECEXP (op, 0, i + 1);
7894
7895 if (GET_CODE (elt) != SET
7896 || GET_CODE (SET_SRC (elt)) != REG
7897 || GET_MODE (SET_SRC (elt)) != SImode
7898 || REGNO (SET_SRC (elt)) != src_regno + i
7899 || GET_CODE (SET_DEST (elt)) != MEM
7900 || GET_MODE (SET_DEST (elt)) != SImode
7901 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
7902 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
7903 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
7904 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
7905 return 0;
7906 }
7907
7908 return 1;
7909}
9ebbca7d 7910
9caa3eb2
DE
7911/* Return a string to perform a load_multiple operation.
7912 operands[0] is the vector.
7913 operands[1] is the source address.
7914 operands[2] is the first destination register. */
7915
7916const char *
a2369ed3 7917rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
7918{
7919 /* We have to handle the case where the pseudo used to contain the address
7920 is assigned to one of the output registers. */
7921 int i, j;
7922 int words = XVECLEN (operands[0], 0);
7923 rtx xop[10];
7924
7925 if (XVECLEN (operands[0], 0) == 1)
7926 return "{l|lwz} %2,0(%1)";
7927
7928 for (i = 0; i < words; i++)
7929 if (refers_to_regno_p (REGNO (operands[2]) + i,
7930 REGNO (operands[2]) + i + 1, operands[1], 0))
7931 {
7932 if (i == words-1)
7933 {
7934 xop[0] = GEN_INT (4 * (words-1));
7935 xop[1] = operands[1];
7936 xop[2] = operands[2];
7937 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
7938 return "";
7939 }
7940 else if (i == 0)
7941 {
7942 xop[0] = GEN_INT (4 * (words-1));
7943 xop[1] = operands[1];
7944 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
7945 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);
7946 return "";
7947 }
7948 else
7949 {
7950 for (j = 0; j < words; j++)
7951 if (j != i)
7952 {
7953 xop[0] = GEN_INT (j * 4);
7954 xop[1] = operands[1];
7955 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
7956 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
7957 }
7958 xop[0] = GEN_INT (i * 4);
7959 xop[1] = operands[1];
7960 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
7961 return "";
7962 }
7963 }
7964
7965 return "{lsi|lswi} %2,%1,%N0";
7966}
7967
00b960c7
AH
7968/* Return 1 for a parallel vrsave operation. */
7969
7970int
a2369ed3 7971vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
7972{
7973 int count = XVECLEN (op, 0);
7974 unsigned int dest_regno, src_regno;
7975 int i;
7976
7977 if (count <= 1
7978 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7979 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 7980 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
7981 return 0;
7982
7983 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7984 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7985
7986 if (dest_regno != VRSAVE_REGNO
7987 && src_regno != VRSAVE_REGNO)
7988 return 0;
7989
7990 for (i = 1; i < count; i++)
7991 {
7992 rtx elt = XVECEXP (op, 0, i);
7993
9aa86737
AH
7994 if (GET_CODE (elt) != CLOBBER
7995 && GET_CODE (elt) != SET)
00b960c7
AH
7996 return 0;
7997 }
7998
7999 return 1;
8000}
8001
2c4a9cff
DE
8002/* Return 1 for an PARALLEL suitable for mfcr. */
8003
8004int
a2369ed3 8005mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
8006{
8007 int count = XVECLEN (op, 0);
8008 int i;
8009
8010 /* Perform a quick check so we don't blow up below. */
8011 if (count < 1
8012 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8013 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8014 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
8015 return 0;
8016
8017 for (i = 0; i < count; i++)
8018 {
8019 rtx exp = XVECEXP (op, 0, i);
8020 rtx unspec;
8021 int maskval;
8022 rtx src_reg;
8023
8024 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
8025
8026 if (GET_CODE (src_reg) != REG
8027 || GET_MODE (src_reg) != CCmode
8028 || ! CR_REGNO_P (REGNO (src_reg)))
8029 return 0;
8030
8031 if (GET_CODE (exp) != SET
8032 || GET_CODE (SET_DEST (exp)) != REG
8033 || GET_MODE (SET_DEST (exp)) != SImode
8034 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
8035 return 0;
8036 unspec = SET_SRC (exp);
8037 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
8038
8039 if (GET_CODE (unspec) != UNSPEC
8040 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
8041 || XVECLEN (unspec, 0) != 2
8042 || XVECEXP (unspec, 0, 0) != src_reg
8043 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8044 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8045 return 0;
8046 }
8047 return 1;
8048}
8049
a4f6c312 8050/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
8051
8052int
a2369ed3 8053mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8054{
8055 int count = XVECLEN (op, 0);
8056 int i;
9ebbca7d
GK
8057 rtx src_reg;
8058
8059 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
8060 if (count < 1
8061 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8062 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
8063 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 8064 return 0;
e35b9579 8065 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
8066
8067 if (GET_CODE (src_reg) != REG
8068 || GET_MODE (src_reg) != SImode
8069 || ! INT_REGNO_P (REGNO (src_reg)))
8070 return 0;
8071
e35b9579 8072 for (i = 0; i < count; i++)
9ebbca7d
GK
8073 {
8074 rtx exp = XVECEXP (op, 0, i);
8075 rtx unspec;
8076 int maskval;
8077
8078 if (GET_CODE (exp) != SET
8079 || GET_CODE (SET_DEST (exp)) != REG
8080 || GET_MODE (SET_DEST (exp)) != CCmode
8081 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
8082 return 0;
8083 unspec = SET_SRC (exp);
8084 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
8085
8086 if (GET_CODE (unspec) != UNSPEC
615158e2 8087 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
8088 || XVECLEN (unspec, 0) != 2
8089 || XVECEXP (unspec, 0, 0) != src_reg
8090 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
8091 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
8092 return 0;
8093 }
e35b9579 8094 return 1;
9ebbca7d
GK
8095}
8096
a4f6c312 8097/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
8098
8099int
a2369ed3 8100lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8101{
8102 int count = XVECLEN (op, 0);
e2c953b6 8103 unsigned int dest_regno;
9ebbca7d 8104 rtx src_addr;
e2c953b6 8105 unsigned int base_regno;
9ebbca7d
GK
8106 HOST_WIDE_INT offset;
8107 int i;
8108
8109 /* Perform a quick check so we don't blow up below. */
8110 if (count <= 1
8111 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8112 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
8113 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
8114 return 0;
8115
8116 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
8117 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
8118
8119 if (dest_regno > 31
e2c953b6 8120 || count != 32 - (int) dest_regno)
9ebbca7d
GK
8121 return 0;
8122
4d588c14 8123 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
8124 {
8125 offset = 0;
8126 base_regno = REGNO (src_addr);
8127 if (base_regno == 0)
8128 return 0;
8129 }
4d588c14 8130 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
8131 {
8132 offset = INTVAL (XEXP (src_addr, 1));
8133 base_regno = REGNO (XEXP (src_addr, 0));
8134 }
8135 else
8136 return 0;
8137
8138 for (i = 0; i < count; i++)
8139 {
8140 rtx elt = XVECEXP (op, 0, i);
8141 rtx newaddr;
8142 rtx addr_reg;
8143 HOST_WIDE_INT newoffset;
8144
8145 if (GET_CODE (elt) != SET
8146 || GET_CODE (SET_DEST (elt)) != REG
8147 || GET_MODE (SET_DEST (elt)) != SImode
8148 || REGNO (SET_DEST (elt)) != dest_regno + i
8149 || GET_CODE (SET_SRC (elt)) != MEM
8150 || GET_MODE (SET_SRC (elt)) != SImode)
8151 return 0;
8152 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 8153 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8154 {
8155 newoffset = 0;
8156 addr_reg = newaddr;
8157 }
4d588c14 8158 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8159 {
8160 addr_reg = XEXP (newaddr, 0);
8161 newoffset = INTVAL (XEXP (newaddr, 1));
8162 }
8163 else
8164 return 0;
8165 if (REGNO (addr_reg) != base_regno
8166 || newoffset != offset + 4 * i)
8167 return 0;
8168 }
8169
8170 return 1;
8171}
8172
a4f6c312 8173/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
8174
8175int
a2369ed3 8176stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
8177{
8178 int count = XVECLEN (op, 0);
e2c953b6 8179 unsigned int src_regno;
9ebbca7d 8180 rtx dest_addr;
e2c953b6 8181 unsigned int base_regno;
9ebbca7d
GK
8182 HOST_WIDE_INT offset;
8183 int i;
8184
8185 /* Perform a quick check so we don't blow up below. */
8186 if (count <= 1
8187 || GET_CODE (XVECEXP (op, 0, 0)) != SET
8188 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
8189 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
8190 return 0;
8191
8192 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
8193 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
8194
8195 if (src_regno > 31
e2c953b6 8196 || count != 32 - (int) src_regno)
9ebbca7d
GK
8197 return 0;
8198
4d588c14 8199 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
8200 {
8201 offset = 0;
8202 base_regno = REGNO (dest_addr);
8203 if (base_regno == 0)
8204 return 0;
8205 }
4d588c14 8206 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
8207 {
8208 offset = INTVAL (XEXP (dest_addr, 1));
8209 base_regno = REGNO (XEXP (dest_addr, 0));
8210 }
8211 else
8212 return 0;
8213
8214 for (i = 0; i < count; i++)
8215 {
8216 rtx elt = XVECEXP (op, 0, i);
8217 rtx newaddr;
8218 rtx addr_reg;
8219 HOST_WIDE_INT newoffset;
8220
8221 if (GET_CODE (elt) != SET
8222 || GET_CODE (SET_SRC (elt)) != REG
8223 || GET_MODE (SET_SRC (elt)) != SImode
8224 || REGNO (SET_SRC (elt)) != src_regno + i
8225 || GET_CODE (SET_DEST (elt)) != MEM
8226 || GET_MODE (SET_DEST (elt)) != SImode)
8227 return 0;
8228 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 8229 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
8230 {
8231 newoffset = 0;
8232 addr_reg = newaddr;
8233 }
4d588c14 8234 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
8235 {
8236 addr_reg = XEXP (newaddr, 0);
8237 newoffset = INTVAL (XEXP (newaddr, 1));
8238 }
8239 else
8240 return 0;
8241 if (REGNO (addr_reg) != base_regno
8242 || newoffset != offset + 4 * i)
8243 return 0;
8244 }
8245
8246 return 1;
8247}
9878760c 8248\f
a4f6c312
SS
8249/* A validation routine: say whether CODE, a condition code, and MODE
8250 match. The other alternatives either don't make sense or should
8251 never be generated. */
39a10a29 8252
39a10a29 8253static void
a2369ed3 8254validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29 8255{
ec8e098d
PB
8256 if ((GET_RTX_CLASS (code) != RTX_COMPARE
8257 && GET_RTX_CLASS (code) != RTX_COMM_COMPARE)
39a10a29
GK
8258 || GET_MODE_CLASS (mode) != MODE_CC)
8259 abort ();
8260
8261 /* These don't make sense. */
8262 if ((code == GT || code == LT || code == GE || code == LE)
8263 && mode == CCUNSmode)
8264 abort ();
8265
8266 if ((code == GTU || code == LTU || code == GEU || code == LEU)
8267 && mode != CCUNSmode)
8268 abort ();
8269
8270 if (mode != CCFPmode
8271 && (code == ORDERED || code == UNORDERED
8272 || code == UNEQ || code == LTGT
8273 || code == UNGT || code == UNLT
8274 || code == UNGE || code == UNLE))
a4f6c312 8275 abort ();
39a10a29 8276
de6c5979 8277 /* These should never be generated except for
bc9ec0e0 8278 flag_finite_math_only. */
39a10a29 8279 if (mode == CCFPmode
ad72b533 8280 && ! flag_finite_math_only
39a10a29
GK
8281 && (code == LE || code == GE
8282 || code == UNEQ || code == LTGT
8283 || code == UNGT || code == UNLT))
8284 abort ();
8285
8286 /* These are invalid; the information is not there. */
8287 if (mode == CCEQmode
8288 && code != EQ && code != NE)
8289 abort ();
8290}
8291
9878760c
RK
8292/* Return 1 if OP is a comparison operation that is valid for a branch insn.
8293 We only check the opcode against the mode of the CC value here. */
8294
8295int
a2369ed3 8296branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8297{
8298 enum rtx_code code = GET_CODE (op);
8299 enum machine_mode cc_mode;
8300
ec8e098d 8301 if (!COMPARISON_P (op))
9878760c
RK
8302 return 0;
8303
8304 cc_mode = GET_MODE (XEXP (op, 0));
8305 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
8306 return 0;
8307
39a10a29 8308 validate_condition_mode (code, cc_mode);
9878760c 8309
39a10a29
GK
8310 return 1;
8311}
8312
8313/* Return 1 if OP is a comparison operation that is valid for a branch
8314 insn and which is true if the corresponding bit in the CC register
8315 is set. */
8316
8317int
a2369ed3 8318branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
8319{
8320 enum rtx_code code;
8321
8daf2e65 8322 if (! branch_comparison_operator (op, mode))
9878760c
RK
8323 return 0;
8324
39a10a29
GK
8325 code = GET_CODE (op);
8326 return (code == EQ || code == LT || code == GT
993f19a8 8327 || (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
8328 || code == LTU || code == GTU
8329 || code == UNORDERED);
9878760c
RK
8330}
8331
b7053a3f
GK
8332/* Return 1 if OP is a comparison operation that is valid for an scc
8333 insn: it must be a positive comparison. */
9878760c
RK
8334
8335int
a2369ed3 8336scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 8337{
b7053a3f 8338 return branch_positive_comparison_operator (op, mode);
9878760c 8339}
e0cd0770
JC
8340
8341int
a2369ed3 8342trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
8343{
8344 if (mode != VOIDmode && mode != GET_MODE (op))
8345 return 0;
ec8e098d 8346 return COMPARISON_P (op);
e0cd0770 8347}
dfbdccdb
GK
8348
8349int
a2369ed3 8350boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
8351{
8352 enum rtx_code code = GET_CODE (op);
8353 return (code == AND || code == IOR || code == XOR);
8354}
1d328b19
GK
8355
8356int
a2369ed3 8357boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
8358{
8359 enum rtx_code code = GET_CODE (op);
8360 return (code == IOR || code == XOR);
8361}
50a0b056
GK
8362
8363int
a2369ed3 8364min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
8365{
8366 enum rtx_code code = GET_CODE (op);
8367 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
8368}
9878760c
RK
8369\f
8370/* Return 1 if ANDOP is a mask that has no bits on that are not in the
8371 mask required to convert the result of a rotate insn into a shift
b1765bde 8372 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
8373
8374int
a2369ed3 8375includes_lshift_p (rtx shiftop, rtx andop)
9878760c 8376{
e2c953b6
DE
8377 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
8378
8379 shift_mask <<= INTVAL (shiftop);
9878760c 8380
b1765bde 8381 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
8382}
8383
8384/* Similar, but for right shift. */
8385
8386int
a2369ed3 8387includes_rshift_p (rtx shiftop, rtx andop)
9878760c 8388{
a7653a2c 8389 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
8390
8391 shift_mask >>= INTVAL (shiftop);
8392
b1765bde 8393 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
8394}
8395
c5059423
AM
8396/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
8397 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 8398 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
8399
8400int
a2369ed3 8401includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 8402{
c5059423
AM
8403 if (GET_CODE (andop) == CONST_INT)
8404 {
02071907 8405 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 8406
c5059423 8407 c = INTVAL (andop);
02071907 8408 if (c == 0 || c == ~0)
c5059423 8409 return 0;
e2c953b6 8410
02071907 8411 shift_mask = ~0;
c5059423
AM
8412 shift_mask <<= INTVAL (shiftop);
8413
b6d08ca1 8414 /* Find the least significant one bit. */
c5059423
AM
8415 lsb = c & -c;
8416
8417 /* It must coincide with the LSB of the shift mask. */
8418 if (-lsb != shift_mask)
8419 return 0;
e2c953b6 8420
c5059423
AM
8421 /* Invert to look for the next transition (if any). */
8422 c = ~c;
8423
8424 /* Remove the low group of ones (originally low group of zeros). */
8425 c &= -lsb;
8426
8427 /* Again find the lsb, and check we have all 1's above. */
8428 lsb = c & -c;
8429 return c == -lsb;
8430 }
8431 else if (GET_CODE (andop) == CONST_DOUBLE
8432 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8433 {
02071907
AM
8434 HOST_WIDE_INT low, high, lsb;
8435 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
8436
8437 low = CONST_DOUBLE_LOW (andop);
8438 if (HOST_BITS_PER_WIDE_INT < 64)
8439 high = CONST_DOUBLE_HIGH (andop);
8440
8441 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 8442 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
8443 return 0;
8444
8445 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8446 {
02071907 8447 shift_mask_high = ~0;
c5059423
AM
8448 if (INTVAL (shiftop) > 32)
8449 shift_mask_high <<= INTVAL (shiftop) - 32;
8450
8451 lsb = high & -high;
8452
8453 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
8454 return 0;
8455
8456 high = ~high;
8457 high &= -lsb;
8458
8459 lsb = high & -high;
8460 return high == -lsb;
8461 }
8462
02071907 8463 shift_mask_low = ~0;
c5059423
AM
8464 shift_mask_low <<= INTVAL (shiftop);
8465
8466 lsb = low & -low;
8467
8468 if (-lsb != shift_mask_low)
8469 return 0;
8470
8471 if (HOST_BITS_PER_WIDE_INT < 64)
8472 high = ~high;
8473 low = ~low;
8474 low &= -lsb;
8475
8476 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8477 {
8478 lsb = high & -high;
8479 return high == -lsb;
8480 }
8481
8482 lsb = low & -low;
8483 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
8484 }
8485 else
8486 return 0;
8487}
e2c953b6 8488
c5059423
AM
8489/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
8490 to perform a left shift. It must have SHIFTOP or more least
c1207243 8491 significant 0's, with the remainder of the word 1's. */
e2c953b6 8492
c5059423 8493int
a2369ed3 8494includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 8495{
e2c953b6 8496 if (GET_CODE (andop) == CONST_INT)
c5059423 8497 {
02071907 8498 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 8499
02071907 8500 shift_mask = ~0;
c5059423
AM
8501 shift_mask <<= INTVAL (shiftop);
8502 c = INTVAL (andop);
8503
c1207243 8504 /* Find the least significant one bit. */
c5059423
AM
8505 lsb = c & -c;
8506
8507 /* It must be covered by the shift mask.
a4f6c312 8508 This test also rejects c == 0. */
c5059423
AM
8509 if ((lsb & shift_mask) == 0)
8510 return 0;
8511
8512 /* Check we have all 1's above the transition, and reject all 1's. */
8513 return c == -lsb && lsb != 1;
8514 }
8515 else if (GET_CODE (andop) == CONST_DOUBLE
8516 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8517 {
02071907 8518 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
8519
8520 low = CONST_DOUBLE_LOW (andop);
8521
8522 if (HOST_BITS_PER_WIDE_INT < 64)
8523 {
02071907 8524 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
8525
8526 high = CONST_DOUBLE_HIGH (andop);
8527
8528 if (low == 0)
8529 {
02071907 8530 shift_mask_high = ~0;
c5059423
AM
8531 if (INTVAL (shiftop) > 32)
8532 shift_mask_high <<= INTVAL (shiftop) - 32;
8533
8534 lsb = high & -high;
8535
8536 if ((lsb & shift_mask_high) == 0)
8537 return 0;
8538
8539 return high == -lsb;
8540 }
8541 if (high != ~0)
8542 return 0;
8543 }
8544
02071907 8545 shift_mask_low = ~0;
c5059423
AM
8546 shift_mask_low <<= INTVAL (shiftop);
8547
8548 lsb = low & -low;
8549
8550 if ((lsb & shift_mask_low) == 0)
8551 return 0;
8552
8553 return low == -lsb && lsb != 1;
8554 }
e2c953b6 8555 else
c5059423 8556 return 0;
9878760c 8557}
35068b43
RK
8558
8559/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
8560 for lfq and stfq insns.
8561
8562 Note reg1 and reg2 *must* be hard registers. To be sure we will
8563 abort if we are passed pseudo registers. */
8564
8565int
a2369ed3 8566registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
8567{
8568 /* We might have been passed a SUBREG. */
8569 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8570 return 0;
8571
8572 return (REGNO (reg1) == REGNO (reg2) - 1);
8573}
8574
a4f6c312
SS
8575/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
8576 addr1 and addr2 must be in consecutive memory locations
8577 (addr2 == addr1 + 8). */
35068b43
RK
8578
8579int
a2369ed3 8580addrs_ok_for_quad_peep (rtx addr1, rtx addr2)
35068b43 8581{
e2c953b6 8582 unsigned int reg1;
35068b43
RK
8583 int offset1;
8584
8585 /* Extract an offset (if used) from the first addr. */
8586 if (GET_CODE (addr1) == PLUS)
8587 {
8588 /* If not a REG, return zero. */
8589 if (GET_CODE (XEXP (addr1, 0)) != REG)
8590 return 0;
8591 else
8592 {
8593 reg1 = REGNO (XEXP (addr1, 0));
8594 /* The offset must be constant! */
8595 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8596 return 0;
8597 offset1 = INTVAL (XEXP (addr1, 1));
8598 }
8599 }
8600 else if (GET_CODE (addr1) != REG)
8601 return 0;
8602 else
8603 {
8604 reg1 = REGNO (addr1);
8605 /* This was a simple (mem (reg)) expression. Offset is 0. */
8606 offset1 = 0;
8607 }
8608
a2369ed3 8609 /* Make sure the second address is a (mem (plus (reg) (const_int)))
0f6937fe
AM
8610 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
8611 register as addr1. */
984e25ac 8612 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 8613 return 1;
35068b43
RK
8614 if (GET_CODE (addr2) != PLUS)
8615 return 0;
8616
8617 if (GET_CODE (XEXP (addr2, 0)) != REG
8618 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8619 return 0;
8620
8621 if (reg1 != REGNO (XEXP (addr2, 0)))
8622 return 0;
8623
8624 /* The offset for the second addr must be 8 more than the first addr. */
8625 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
8626 return 0;
8627
8628 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
8629 instructions. */
8630 return 1;
8631}
9878760c
RK
8632\f
8633/* Return the register class of a scratch register needed to copy IN into
8634 or out of a register in CLASS in MODE. If it can be done directly,
8635 NO_REGS is returned. */
8636
8637enum reg_class
a2369ed3 8638secondary_reload_class (enum reg_class class,
a9baceb1
GK
8639 enum machine_mode mode ATTRIBUTE_UNUSED,
8640 rtx in)
9878760c 8641{
5accd822 8642 int regno;
9878760c 8643
ab82a49f
AP
8644 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
8645#if TARGET_MACHO
8646 && MACHOPIC_INDIRECT
8647#endif
8648 ))
46fad5b7
DJ
8649 {
8650 /* We cannot copy a symbolic operand directly into anything
8651 other than BASE_REGS for TARGET_ELF. So indicate that a
8652 register from BASE_REGS is needed as an intermediate
8653 register.
8654
8655 On Darwin, pic addresses require a load from memory, which
8656 needs a base register. */
8657 if (class != BASE_REGS
8658 && (GET_CODE (in) == SYMBOL_REF
8659 || GET_CODE (in) == HIGH
8660 || GET_CODE (in) == LABEL_REF
8661 || GET_CODE (in) == CONST))
8662 return BASE_REGS;
8663 }
e7b7998a 8664
5accd822
DE
8665 if (GET_CODE (in) == REG)
8666 {
8667 regno = REGNO (in);
8668 if (regno >= FIRST_PSEUDO_REGISTER)
8669 {
8670 regno = true_regnum (in);
8671 if (regno >= FIRST_PSEUDO_REGISTER)
8672 regno = -1;
8673 }
8674 }
8675 else if (GET_CODE (in) == SUBREG)
8676 {
8677 regno = true_regnum (in);
8678 if (regno >= FIRST_PSEUDO_REGISTER)
8679 regno = -1;
8680 }
8681 else
8682 regno = -1;
8683
9878760c
RK
8684 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
8685 into anything. */
8686 if (class == GENERAL_REGS || class == BASE_REGS
8687 || (regno >= 0 && INT_REGNO_P (regno)))
8688 return NO_REGS;
8689
8690 /* Constants, memory, and FP registers can go into FP registers. */
8691 if ((regno == -1 || FP_REGNO_P (regno))
8692 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
8693 return NO_REGS;
8694
0ac081f6
AH
8695 /* Memory, and AltiVec registers can go into AltiVec registers. */
8696 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
8697 && class == ALTIVEC_REGS)
8698 return NO_REGS;
8699
9878760c
RK
8700 /* We can copy among the CR registers. */
8701 if ((class == CR_REGS || class == CR0_REGS)
8702 && regno >= 0 && CR_REGNO_P (regno))
8703 return NO_REGS;
8704
8705 /* Otherwise, we need GENERAL_REGS. */
8706 return GENERAL_REGS;
8707}
8708\f
8709/* Given a comparison operation, return the bit number in CCR to test. We
8710 know this is a valid comparison.
8711
8712 SCC_P is 1 if this is for an scc. That means that %D will have been
8713 used instead of %C, so the bits will be in different places.
8714
b4ac57ab 8715 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
8716
8717int
a2369ed3 8718ccr_bit (rtx op, int scc_p)
9878760c
RK
8719{
8720 enum rtx_code code = GET_CODE (op);
8721 enum machine_mode cc_mode;
8722 int cc_regnum;
8723 int base_bit;
9ebbca7d 8724 rtx reg;
9878760c 8725
ec8e098d 8726 if (!COMPARISON_P (op))
9878760c
RK
8727 return -1;
8728
9ebbca7d
GK
8729 reg = XEXP (op, 0);
8730
8731 if (GET_CODE (reg) != REG
8732 || ! CR_REGNO_P (REGNO (reg)))
8733 abort ();
8734
8735 cc_mode = GET_MODE (reg);
8736 cc_regnum = REGNO (reg);
8737 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 8738
39a10a29 8739 validate_condition_mode (code, cc_mode);
c5defebb 8740
b7053a3f
GK
8741 /* When generating a sCOND operation, only positive conditions are
8742 allowed. */
8743 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
8744 && code != GTU && code != LTU)
8745 abort ();
8746
9878760c
RK
8747 switch (code)
8748 {
8749 case NE:
993f19a8
AH
8750 if (TARGET_E500 && !TARGET_FPRS
8751 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8752 return base_bit + 1;
9878760c
RK
8753 return scc_p ? base_bit + 3 : base_bit + 2;
8754 case EQ:
993f19a8
AH
8755 if (TARGET_E500 && !TARGET_FPRS
8756 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8757 return base_bit + 1;
9878760c 8758 return base_bit + 2;
1c882ea4 8759 case GT: case GTU: case UNLE:
9878760c 8760 return base_bit + 1;
1c882ea4 8761 case LT: case LTU: case UNGE:
9878760c 8762 return base_bit;
1c882ea4
GK
8763 case ORDERED: case UNORDERED:
8764 return base_bit + 3;
9878760c
RK
8765
8766 case GE: case GEU:
39a10a29 8767 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
8768 unordered position. So test that bit. For integer, this is ! LT
8769 unless this is an scc insn. */
39a10a29 8770 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
8771
8772 case LE: case LEU:
39a10a29 8773 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 8774
9878760c
RK
8775 default:
8776 abort ();
8777 }
8778}
1ff7789b 8779\f
8d30c4ee 8780/* Return the GOT register. */
1ff7789b
MM
8781
8782struct rtx_def *
a2369ed3 8783rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 8784{
a4f6c312
SS
8785 /* The second flow pass currently (June 1999) can't update
8786 regs_ever_live without disturbing other parts of the compiler, so
8787 update it here to make the prolog/epilogue code happy. */
1db02437
FS
8788 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
8789 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 8790
8d30c4ee 8791 current_function_uses_pic_offset_table = 1;
3cb999d8 8792
1ff7789b
MM
8793 return pic_offset_table_rtx;
8794}
a7df97e6 8795\f
e2500fed
GK
8796/* Function to init struct machine_function.
8797 This will be called, via a pointer variable,
8798 from push_function_context. */
a7df97e6 8799
e2500fed 8800static struct machine_function *
863d938c 8801rs6000_init_machine_status (void)
a7df97e6 8802{
e2500fed 8803 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 8804}
9878760c 8805\f
0ba1b2ff
AM
8806/* These macros test for integers and extract the low-order bits. */
8807#define INT_P(X) \
8808((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
8809 && GET_MODE (X) == VOIDmode)
8810
8811#define INT_LOWPART(X) \
8812 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
8813
8814int
a2369ed3 8815extract_MB (rtx op)
0ba1b2ff
AM
8816{
8817 int i;
8818 unsigned long val = INT_LOWPART (op);
8819
8820 /* If the high bit is zero, the value is the first 1 bit we find
8821 from the left. */
8822 if ((val & 0x80000000) == 0)
8823 {
8824 if ((val & 0xffffffff) == 0)
8825 abort ();
8826
8827 i = 1;
8828 while (((val <<= 1) & 0x80000000) == 0)
8829 ++i;
8830 return i;
8831 }
8832
8833 /* If the high bit is set and the low bit is not, or the mask is all
8834 1's, the value is zero. */
8835 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
8836 return 0;
8837
8838 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8839 from the right. */
8840 i = 31;
8841 while (((val >>= 1) & 1) != 0)
8842 --i;
8843
8844 return i;
8845}
8846
8847int
a2369ed3 8848extract_ME (rtx op)
0ba1b2ff
AM
8849{
8850 int i;
8851 unsigned long val = INT_LOWPART (op);
8852
8853 /* If the low bit is zero, the value is the first 1 bit we find from
8854 the right. */
8855 if ((val & 1) == 0)
8856 {
8857 if ((val & 0xffffffff) == 0)
8858 abort ();
8859
8860 i = 30;
8861 while (((val >>= 1) & 1) == 0)
8862 --i;
8863
8864 return i;
8865 }
8866
8867 /* If the low bit is set and the high bit is not, or the mask is all
8868 1's, the value is 31. */
8869 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
8870 return 31;
8871
8872 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8873 from the left. */
8874 i = 0;
8875 while (((val <<= 1) & 0x80000000) != 0)
8876 ++i;
8877
8878 return i;
8879}
8880
c4501e62
JJ
8881/* Locate some local-dynamic symbol still in use by this function
8882 so that we can print its name in some tls_ld pattern. */
8883
8884static const char *
863d938c 8885rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
8886{
8887 rtx insn;
8888
8889 if (cfun->machine->some_ld_name)
8890 return cfun->machine->some_ld_name;
8891
8892 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8893 if (INSN_P (insn)
8894 && for_each_rtx (&PATTERN (insn),
8895 rs6000_get_some_local_dynamic_name_1, 0))
8896 return cfun->machine->some_ld_name;
8897
8898 abort ();
8899}
8900
8901/* Helper function for rs6000_get_some_local_dynamic_name. */
8902
8903static int
a2369ed3 8904rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
8905{
8906 rtx x = *px;
8907
8908 if (GET_CODE (x) == SYMBOL_REF)
8909 {
8910 const char *str = XSTR (x, 0);
8911 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8912 {
8913 cfun->machine->some_ld_name = str;
8914 return 1;
8915 }
8916 }
8917
8918 return 0;
8919}
8920
9878760c
RK
8921/* Print an operand. Recognize special options, documented below. */
8922
38c1f2d7 8923#if TARGET_ELF
d9407988 8924#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 8925#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
8926#else
8927#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 8928#define SMALL_DATA_REG 0
ba5e43aa
MM
8929#endif
8930
9878760c 8931void
a2369ed3 8932print_operand (FILE *file, rtx x, int code)
9878760c
RK
8933{
8934 int i;
a260abc9 8935 HOST_WIDE_INT val;
0ba1b2ff 8936 unsigned HOST_WIDE_INT uval;
9878760c
RK
8937
8938 switch (code)
8939 {
a8b3aeda 8940 case '.':
a85d226b
RK
8941 /* Write out an instruction after the call which may be replaced
8942 with glue code by the loader. This depends on the AIX version. */
8943 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
8944 return;
8945
81eace42
GK
8946 /* %a is output_address. */
8947
9854d9ed
RK
8948 case 'A':
8949 /* If X is a constant integer whose low-order 5 bits are zero,
8950 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 8951 in the AIX assembler where "sri" with a zero shift count
20e26713 8952 writes a trash instruction. */
9854d9ed 8953 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 8954 putc ('l', file);
9854d9ed 8955 else
76229ac8 8956 putc ('r', file);
9854d9ed
RK
8957 return;
8958
8959 case 'b':
e2c953b6
DE
8960 /* If constant, low-order 16 bits of constant, unsigned.
8961 Otherwise, write normally. */
8962 if (INT_P (x))
8963 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
8964 else
8965 print_operand (file, x, 0);
cad12a8d
RK
8966 return;
8967
a260abc9
DE
8968 case 'B':
8969 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
8970 for 64-bit mask direction. */
296b8152 8971 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 8972 return;
a260abc9 8973
81eace42
GK
8974 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
8975 output_operand. */
8976
9854d9ed 8977 case 'E':
39a10a29 8978 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
8979 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8980 output_operand_lossage ("invalid %%E value");
78fbdbf7 8981 else
39a10a29 8982 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 8983 return;
9854d9ed
RK
8984
8985 case 'f':
8986 /* X is a CR register. Print the shift count needed to move it
8987 to the high-order four bits. */
8988 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8989 output_operand_lossage ("invalid %%f value");
8990 else
9ebbca7d 8991 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8992 return;
8993
8994 case 'F':
8995 /* Similar, but print the count for the rotate in the opposite
8996 direction. */
8997 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8998 output_operand_lossage ("invalid %%F value");
8999 else
9ebbca7d 9000 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
9001 return;
9002
9003 case 'G':
9004 /* X is a constant integer. If it is negative, print "m",
43aa4e05 9005 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
9006 if (GET_CODE (x) != CONST_INT)
9007 output_operand_lossage ("invalid %%G value");
9008 else if (INTVAL (x) >= 0)
76229ac8 9009 putc ('z', file);
9854d9ed 9010 else
76229ac8 9011 putc ('m', file);
9854d9ed 9012 return;
e2c953b6 9013
9878760c 9014 case 'h':
a4f6c312
SS
9015 /* If constant, output low-order five bits. Otherwise, write
9016 normally. */
9878760c 9017 if (INT_P (x))
5f59ecb7 9018 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
9019 else
9020 print_operand (file, x, 0);
9021 return;
9022
64305719 9023 case 'H':
a4f6c312
SS
9024 /* If constant, output low-order six bits. Otherwise, write
9025 normally. */
64305719 9026 if (INT_P (x))
5f59ecb7 9027 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
9028 else
9029 print_operand (file, x, 0);
9030 return;
9031
9854d9ed
RK
9032 case 'I':
9033 /* Print `i' if this is a constant, else nothing. */
9878760c 9034 if (INT_P (x))
76229ac8 9035 putc ('i', file);
9878760c
RK
9036 return;
9037
9854d9ed
RK
9038 case 'j':
9039 /* Write the bit number in CCR for jump. */
9040 i = ccr_bit (x, 0);
9041 if (i == -1)
9042 output_operand_lossage ("invalid %%j code");
9878760c 9043 else
9854d9ed 9044 fprintf (file, "%d", i);
9878760c
RK
9045 return;
9046
9854d9ed
RK
9047 case 'J':
9048 /* Similar, but add one for shift count in rlinm for scc and pass
9049 scc flag to `ccr_bit'. */
9050 i = ccr_bit (x, 1);
9051 if (i == -1)
9052 output_operand_lossage ("invalid %%J code");
9053 else
a0466a68
RK
9054 /* If we want bit 31, write a shift count of zero, not 32. */
9055 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
9056 return;
9057
9854d9ed
RK
9058 case 'k':
9059 /* X must be a constant. Write the 1's complement of the
9060 constant. */
9878760c 9061 if (! INT_P (x))
9854d9ed 9062 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
9063 else
9064 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
9065 return;
9066
81eace42 9067 case 'K':
9ebbca7d
GK
9068 /* X must be a symbolic constant on ELF. Write an
9069 expression suitable for an 'addi' that adds in the low 16
9070 bits of the MEM. */
9071 if (GET_CODE (x) != CONST)
9072 {
9073 print_operand_address (file, x);
9074 fputs ("@l", file);
9075 }
9076 else
9077 {
9078 if (GET_CODE (XEXP (x, 0)) != PLUS
9079 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
9080 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
9081 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 9082 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
9083 print_operand_address (file, XEXP (XEXP (x, 0), 0));
9084 fputs ("@l", file);
ed8d2920
MM
9085 /* For GNU as, there must be a non-alphanumeric character
9086 between 'l' and the number. The '-' is added by
9087 print_operand() already. */
9088 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
9089 fputs ("+", file);
9ebbca7d
GK
9090 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
9091 }
81eace42
GK
9092 return;
9093
9094 /* %l is output_asm_label. */
9ebbca7d 9095
9854d9ed
RK
9096 case 'L':
9097 /* Write second word of DImode or DFmode reference. Works on register
9098 or non-indexed memory only. */
9099 if (GET_CODE (x) == REG)
5ebfb2ba 9100 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
9101 else if (GET_CODE (x) == MEM)
9102 {
9103 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 9104 we have already done it, we can just use an offset of word. */
9854d9ed
RK
9105 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9106 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
9107 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
9108 UNITS_PER_WORD));
9854d9ed 9109 else
d7624dc0
RK
9110 output_address (XEXP (adjust_address_nv (x, SImode,
9111 UNITS_PER_WORD),
9112 0));
ed8908e7 9113
ba5e43aa 9114 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9115 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9116 reg_names[SMALL_DATA_REG]);
9854d9ed 9117 }
9878760c 9118 return;
9854d9ed 9119
9878760c
RK
9120 case 'm':
9121 /* MB value for a mask operand. */
b1765bde 9122 if (! mask_operand (x, SImode))
9878760c
RK
9123 output_operand_lossage ("invalid %%m value");
9124
0ba1b2ff 9125 fprintf (file, "%d", extract_MB (x));
9878760c
RK
9126 return;
9127
9128 case 'M':
9129 /* ME value for a mask operand. */
b1765bde 9130 if (! mask_operand (x, SImode))
a260abc9 9131 output_operand_lossage ("invalid %%M value");
9878760c 9132
0ba1b2ff 9133 fprintf (file, "%d", extract_ME (x));
9878760c
RK
9134 return;
9135
81eace42
GK
9136 /* %n outputs the negative of its operand. */
9137
9878760c
RK
9138 case 'N':
9139 /* Write the number of elements in the vector times 4. */
9140 if (GET_CODE (x) != PARALLEL)
9141 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
9142 else
9143 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
9144 return;
9145
9146 case 'O':
9147 /* Similar, but subtract 1 first. */
9148 if (GET_CODE (x) != PARALLEL)
1427100a 9149 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
9150 else
9151 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
9152 return;
9153
9854d9ed
RK
9154 case 'p':
9155 /* X is a CONST_INT that is a power of two. Output the logarithm. */
9156 if (! INT_P (x)
2bfcf297 9157 || INT_LOWPART (x) < 0
9854d9ed
RK
9158 || (i = exact_log2 (INT_LOWPART (x))) < 0)
9159 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
9160 else
9161 fprintf (file, "%d", i);
9854d9ed
RK
9162 return;
9163
9878760c
RK
9164 case 'P':
9165 /* The operand must be an indirect memory reference. The result
8bb418a3 9166 is the register name. */
9878760c
RK
9167 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
9168 || REGNO (XEXP (x, 0)) >= 32)
9169 output_operand_lossage ("invalid %%P value");
e2c953b6 9170 else
8bb418a3 9171 fprintf (file, "%s", reg_names[REGNO (XEXP (x, 0))]);
9878760c
RK
9172 return;
9173
dfbdccdb
GK
9174 case 'q':
9175 /* This outputs the logical code corresponding to a boolean
9176 expression. The expression may have one or both operands
39a10a29
GK
9177 negated (if one, only the first one). For condition register
9178 logical operations, it will also treat the negated
9179 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 9180 {
63bc1d05 9181 const char *const *t = 0;
dfbdccdb
GK
9182 const char *s;
9183 enum rtx_code code = GET_CODE (x);
9184 static const char * const tbl[3][3] = {
9185 { "and", "andc", "nor" },
9186 { "or", "orc", "nand" },
9187 { "xor", "eqv", "xor" } };
9188
9189 if (code == AND)
9190 t = tbl[0];
9191 else if (code == IOR)
9192 t = tbl[1];
9193 else if (code == XOR)
9194 t = tbl[2];
9195 else
9196 output_operand_lossage ("invalid %%q value");
9197
9198 if (GET_CODE (XEXP (x, 0)) != NOT)
9199 s = t[0];
9200 else
9201 {
9202 if (GET_CODE (XEXP (x, 1)) == NOT)
9203 s = t[2];
9204 else
9205 s = t[1];
9206 }
9207
9208 fputs (s, file);
9209 }
9210 return;
9211
2c4a9cff
DE
9212 case 'Q':
9213 if (TARGET_MFCRF)
3b6ce0af 9214 fputc (',', file);
5efb1046 9215 /* FALLTHRU */
2c4a9cff
DE
9216 else
9217 return;
9218
9854d9ed
RK
9219 case 'R':
9220 /* X is a CR register. Print the mask for `mtcrf'. */
9221 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
9222 output_operand_lossage ("invalid %%R value");
9223 else
9ebbca7d 9224 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 9225 return;
9854d9ed
RK
9226
9227 case 's':
9228 /* Low 5 bits of 32 - value */
9229 if (! INT_P (x))
9230 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
9231 else
9232 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 9233 return;
9854d9ed 9234
a260abc9 9235 case 'S':
0ba1b2ff 9236 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
9237 CONST_INT 32-bit mask is considered sign-extended so any
9238 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 9239 if (! mask64_operand (x, DImode))
a260abc9
DE
9240 output_operand_lossage ("invalid %%S value");
9241
0ba1b2ff 9242 uval = INT_LOWPART (x);
a260abc9 9243
0ba1b2ff 9244 if (uval & 1) /* Clear Left */
a260abc9 9245 {
f099d360
GK
9246#if HOST_BITS_PER_WIDE_INT > 64
9247 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9248#endif
0ba1b2ff 9249 i = 64;
a260abc9 9250 }
0ba1b2ff 9251 else /* Clear Right */
a260abc9 9252 {
0ba1b2ff 9253 uval = ~uval;
f099d360
GK
9254#if HOST_BITS_PER_WIDE_INT > 64
9255 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9256#endif
0ba1b2ff 9257 i = 63;
a260abc9 9258 }
0ba1b2ff
AM
9259 while (uval != 0)
9260 --i, uval >>= 1;
9261 if (i < 0)
9262 abort ();
9263 fprintf (file, "%d", i);
9264 return;
a260abc9 9265
a3170dc6
AH
9266 case 't':
9267 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
9268 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
9269 abort ();
9270
9271 /* Bit 3 is OV bit. */
9272 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
9273
9274 /* If we want bit 31, write a shift count of zero, not 32. */
9275 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9276 return;
9277
cccf3bdc
DE
9278 case 'T':
9279 /* Print the symbolic name of a branch target register. */
9280 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
9281 && REGNO (x) != COUNT_REGISTER_REGNUM))
9282 output_operand_lossage ("invalid %%T value");
e2c953b6 9283 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
9284 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
9285 else
9286 fputs ("ctr", file);
9287 return;
9288
9854d9ed 9289 case 'u':
802a0058 9290 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
9291 if (! INT_P (x))
9292 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
9293 else
9294 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9295 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
9296 return;
9297
802a0058
MM
9298 case 'v':
9299 /* High-order 16 bits of constant for use in signed operand. */
9300 if (! INT_P (x))
9301 output_operand_lossage ("invalid %%v value");
e2c953b6 9302 else
134c32f6
DE
9303 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9304 (INT_LOWPART (x) >> 16) & 0xffff);
9305 return;
802a0058 9306
9854d9ed
RK
9307 case 'U':
9308 /* Print `u' if this has an auto-increment or auto-decrement. */
9309 if (GET_CODE (x) == MEM
9310 && (GET_CODE (XEXP (x, 0)) == PRE_INC
9311 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 9312 putc ('u', file);
9854d9ed 9313 return;
9878760c 9314
e0cd0770
JC
9315 case 'V':
9316 /* Print the trap code for this operand. */
9317 switch (GET_CODE (x))
9318 {
9319 case EQ:
9320 fputs ("eq", file); /* 4 */
9321 break;
9322 case NE:
9323 fputs ("ne", file); /* 24 */
9324 break;
9325 case LT:
9326 fputs ("lt", file); /* 16 */
9327 break;
9328 case LE:
9329 fputs ("le", file); /* 20 */
9330 break;
9331 case GT:
9332 fputs ("gt", file); /* 8 */
9333 break;
9334 case GE:
9335 fputs ("ge", file); /* 12 */
9336 break;
9337 case LTU:
9338 fputs ("llt", file); /* 2 */
9339 break;
9340 case LEU:
9341 fputs ("lle", file); /* 6 */
9342 break;
9343 case GTU:
9344 fputs ("lgt", file); /* 1 */
9345 break;
9346 case GEU:
9347 fputs ("lge", file); /* 5 */
9348 break;
9349 default:
9350 abort ();
9351 }
9352 break;
9353
9854d9ed
RK
9354 case 'w':
9355 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
9356 normally. */
9357 if (INT_P (x))
5f59ecb7
DE
9358 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
9359 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
9360 else
9361 print_operand (file, x, 0);
9878760c
RK
9362 return;
9363
9854d9ed 9364 case 'W':
e2c953b6 9365 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
9366 val = (GET_CODE (x) == CONST_INT
9367 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
9368
9369 if (val < 0)
9370 i = -1;
9854d9ed 9371 else
e2c953b6
DE
9372 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
9373 if ((val <<= 1) < 0)
9374 break;
9375
9376#if HOST_BITS_PER_WIDE_INT == 32
9377 if (GET_CODE (x) == CONST_INT && i >= 0)
9378 i += 32; /* zero-extend high-part was all 0's */
9379 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
9380 {
9381 val = CONST_DOUBLE_LOW (x);
9382
9383 if (val == 0)
a4f6c312 9384 abort ();
e2c953b6
DE
9385 else if (val < 0)
9386 --i;
9387 else
9388 for ( ; i < 64; i++)
9389 if ((val <<= 1) < 0)
9390 break;
9391 }
9392#endif
9393
9394 fprintf (file, "%d", i + 1);
9854d9ed 9395 return;
9878760c 9396
9854d9ed
RK
9397 case 'X':
9398 if (GET_CODE (x) == MEM
4d588c14 9399 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 9400 putc ('x', file);
9854d9ed 9401 return;
9878760c 9402
9854d9ed
RK
9403 case 'Y':
9404 /* Like 'L', for third word of TImode */
9405 if (GET_CODE (x) == REG)
5ebfb2ba 9406 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 9407 else if (GET_CODE (x) == MEM)
9878760c 9408 {
9854d9ed
RK
9409 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9410 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9411 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 9412 else
d7624dc0 9413 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 9414 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9415 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9416 reg_names[SMALL_DATA_REG]);
9878760c
RK
9417 }
9418 return;
9854d9ed 9419
9878760c 9420 case 'z':
b4ac57ab
RS
9421 /* X is a SYMBOL_REF. Write out the name preceded by a
9422 period and without any trailing data in brackets. Used for function
4d30c363
MM
9423 names. If we are configured for System V (or the embedded ABI) on
9424 the PowerPC, do not emit the period, since those systems do not use
9425 TOCs and the like. */
9878760c
RK
9426 if (GET_CODE (x) != SYMBOL_REF)
9427 abort ();
9428
b6c9286a
MM
9429 if (XSTR (x, 0)[0] != '.')
9430 {
9431 switch (DEFAULT_ABI)
9432 {
9433 default:
9434 abort ();
9435
9436 case ABI_AIX:
9437 putc ('.', file);
9438 break;
9439
9440 case ABI_V4:
ee890fe2 9441 case ABI_DARWIN:
b6c9286a 9442 break;
b6c9286a
MM
9443 }
9444 }
9739c90c
JJ
9445 if (TARGET_AIX)
9446 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9447 else
9448 assemble_name (file, XSTR (x, 0));
9878760c
RK
9449 return;
9450
9854d9ed
RK
9451 case 'Z':
9452 /* Like 'L', for last word of TImode. */
9453 if (GET_CODE (x) == REG)
5ebfb2ba 9454 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
9455 else if (GET_CODE (x) == MEM)
9456 {
9457 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9458 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9459 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 9460 else
d7624dc0 9461 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 9462 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9463 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9464 reg_names[SMALL_DATA_REG]);
9854d9ed 9465 }
5c23c401 9466 return;
0ac081f6 9467
a3170dc6 9468 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
9469 case 'y':
9470 {
9471 rtx tmp;
9472
9473 if (GET_CODE (x) != MEM)
9474 abort ();
9475
9476 tmp = XEXP (x, 0);
9477
993f19a8 9478 if (TARGET_E500)
a3170dc6
AH
9479 {
9480 /* Handle [reg]. */
9481 if (GET_CODE (tmp) == REG)
9482 {
9483 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
9484 break;
9485 }
9486 /* Handle [reg+UIMM]. */
9487 else if (GET_CODE (tmp) == PLUS &&
9488 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
9489 {
9490 int x;
9491
9492 if (GET_CODE (XEXP (tmp, 0)) != REG)
9493 abort ();
9494
9495 x = INTVAL (XEXP (tmp, 1));
9496 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
9497 break;
9498 }
9499
9500 /* Fall through. Must be [reg+reg]. */
9501 }
0ac081f6 9502 if (GET_CODE (tmp) == REG)
c62f2db5 9503 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
9504 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
9505 {
9506 if (REGNO (XEXP (tmp, 0)) == 0)
9507 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
9508 reg_names[ REGNO (XEXP (tmp, 0)) ]);
9509 else
9510 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
9511 reg_names[ REGNO (XEXP (tmp, 1)) ]);
9512 }
9513 else
9514 abort ();
9515 break;
9516 }
9854d9ed 9517
9878760c
RK
9518 case 0:
9519 if (GET_CODE (x) == REG)
9520 fprintf (file, "%s", reg_names[REGNO (x)]);
9521 else if (GET_CODE (x) == MEM)
9522 {
9523 /* We need to handle PRE_INC and PRE_DEC here, since we need to
9524 know the width from the mode. */
9525 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
9526 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
9527 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9528 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
9529 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
9530 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9531 else
a54d04b7 9532 output_address (XEXP (x, 0));
9878760c
RK
9533 }
9534 else
a54d04b7 9535 output_addr_const (file, x);
a85d226b 9536 return;
9878760c 9537
c4501e62
JJ
9538 case '&':
9539 assemble_name (file, rs6000_get_some_local_dynamic_name ());
9540 return;
9541
9878760c
RK
9542 default:
9543 output_operand_lossage ("invalid %%xn code");
9544 }
9545}
9546\f
9547/* Print the address of an operand. */
9548
9549void
a2369ed3 9550print_operand_address (FILE *file, rtx x)
9878760c
RK
9551{
9552 if (GET_CODE (x) == REG)
4697a36c 9553 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
9554 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
9555 || GET_CODE (x) == LABEL_REF)
9878760c
RK
9556 {
9557 output_addr_const (file, x);
ba5e43aa 9558 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9559 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9560 reg_names[SMALL_DATA_REG]);
9ebbca7d 9561 else if (TARGET_TOC)
a4f6c312 9562 abort ();
9878760c
RK
9563 }
9564 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
9565 {
9566 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
9567 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
9568 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 9569 else
4697a36c
MM
9570 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
9571 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
9572 }
9573 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
9574 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
9575 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
9576#if TARGET_ELF
9577 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9578 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
9579 {
9580 output_addr_const (file, XEXP (x, 1));
9581 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9582 }
c859cda6
DJ
9583#endif
9584#if TARGET_MACHO
9585 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9586 && CONSTANT_P (XEXP (x, 1)))
9587 {
9588 fprintf (file, "lo16(");
9589 output_addr_const (file, XEXP (x, 1));
9590 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9591 }
3cb999d8 9592#endif
4d588c14 9593 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 9594 {
2bfcf297 9595 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 9596 {
2bfcf297
DB
9597 rtx contains_minus = XEXP (x, 1);
9598 rtx minus, symref;
9599 const char *name;
9ebbca7d
GK
9600
9601 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 9602 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
9603 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
9604 contains_minus = XEXP (contains_minus, 0);
9605
2bfcf297
DB
9606 minus = XEXP (contains_minus, 0);
9607 symref = XEXP (minus, 0);
9608 XEXP (contains_minus, 0) = symref;
9609 if (TARGET_ELF)
9610 {
9611 char *newname;
9612
9613 name = XSTR (symref, 0);
9614 newname = alloca (strlen (name) + sizeof ("@toc"));
9615 strcpy (newname, name);
9616 strcat (newname, "@toc");
9617 XSTR (symref, 0) = newname;
9618 }
9619 output_addr_const (file, XEXP (x, 1));
9620 if (TARGET_ELF)
9621 XSTR (symref, 0) = name;
9ebbca7d
GK
9622 XEXP (contains_minus, 0) = minus;
9623 }
9624 else
9625 output_addr_const (file, XEXP (x, 1));
9626
9627 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9628 }
9878760c
RK
9629 else
9630 abort ();
9631}
9632\f
88cad84b 9633/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9634 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9635 is defined. It also needs to handle DI-mode objects on 64-bit
9636 targets. */
9637
9638static bool
a2369ed3 9639rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
9640{
9641#ifdef RELOCATABLE_NEEDS_FIXUP
9642 /* Special handling for SI values. */
9643 if (size == 4 && aligned_p)
9644 {
a2369ed3 9645 extern int in_toc_section (void);
301d03af
RS
9646 static int recurse = 0;
9647
9648 /* For -mrelocatable, we mark all addresses that need to be fixed up
9649 in the .fixup section. */
9650 if (TARGET_RELOCATABLE
9651 && !in_toc_section ()
9652 && !in_text_section ()
9653 && !recurse
9654 && GET_CODE (x) != CONST_INT
9655 && GET_CODE (x) != CONST_DOUBLE
9656 && CONSTANT_P (x))
9657 {
9658 char buf[256];
9659
9660 recurse = 1;
9661 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9662 fixuplabelno++;
9663 ASM_OUTPUT_LABEL (asm_out_file, buf);
9664 fprintf (asm_out_file, "\t.long\t(");
9665 output_addr_const (asm_out_file, x);
9666 fprintf (asm_out_file, ")@fixup\n");
9667 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9668 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9669 fprintf (asm_out_file, "\t.long\t");
9670 assemble_name (asm_out_file, buf);
9671 fprintf (asm_out_file, "\n\t.previous\n");
9672 recurse = 0;
9673 return true;
9674 }
9675 /* Remove initial .'s to turn a -mcall-aixdesc function
9676 address into the address of the descriptor, not the function
9677 itself. */
9678 else if (GET_CODE (x) == SYMBOL_REF
9679 && XSTR (x, 0)[0] == '.'
9680 && DEFAULT_ABI == ABI_AIX)
9681 {
9682 const char *name = XSTR (x, 0);
9683 while (*name == '.')
9684 name++;
9685
9686 fprintf (asm_out_file, "\t.long\t%s\n", name);
9687 return true;
9688 }
9689 }
9690#endif /* RELOCATABLE_NEEDS_FIXUP */
9691 return default_assemble_integer (x, size, aligned_p);
9692}
93638d7a
AM
9693
9694#ifdef HAVE_GAS_HIDDEN
9695/* Emit an assembler directive to set symbol visibility for DECL to
9696 VISIBILITY_TYPE. */
9697
5add3202 9698static void
a2369ed3 9699rs6000_assemble_visibility (tree decl, int vis)
93638d7a 9700{
93638d7a
AM
9701 /* Functions need to have their entry point symbol visibility set as
9702 well as their descriptor symbol visibility. */
9703 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9704 {
25fdb4dc
RH
9705 static const char * const visibility_types[] = {
9706 NULL, "internal", "hidden", "protected"
9707 };
9708
9709 const char *name, *type;
93638d7a
AM
9710
9711 name = ((* targetm.strip_name_encoding)
9712 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9713 type = visibility_types[vis];
93638d7a 9714
25fdb4dc
RH
9715 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9716 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9717 }
25fdb4dc
RH
9718 else
9719 default_assemble_visibility (decl, vis);
93638d7a
AM
9720}
9721#endif
301d03af 9722\f
39a10a29 9723enum rtx_code
a2369ed3 9724rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
9725{
9726 /* Reversal of FP compares takes care -- an ordered compare
9727 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9728 if (mode == CCFPmode
9729 && (!flag_finite_math_only
9730 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
9731 || code == UNEQ || code == LTGT))
bab6226b 9732 return reverse_condition_maybe_unordered (code);
39a10a29 9733 else
bab6226b 9734 return reverse_condition (code);
39a10a29
GK
9735}
9736
39a10a29
GK
9737/* Generate a compare for CODE. Return a brand-new rtx that
9738 represents the result of the compare. */
a4f6c312 9739
39a10a29 9740static rtx
a2369ed3 9741rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
9742{
9743 enum machine_mode comp_mode;
9744 rtx compare_result;
9745
9746 if (rs6000_compare_fp_p)
9747 comp_mode = CCFPmode;
9748 else if (code == GTU || code == LTU
9749 || code == GEU || code == LEU)
9750 comp_mode = CCUNSmode;
9751 else
9752 comp_mode = CCmode;
9753
9754 /* First, the compare. */
9755 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
9756
9757 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
9758 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
9759 && rs6000_compare_fp_p)
a3170dc6
AH
9760 {
9761 rtx cmp, or1, or2, or_result, compare_result2;
9762
9763 switch (code)
9764 {
9765 case EQ:
9766 case UNEQ:
9767 case NE:
9768 case LTGT:
bc9ec0e0 9769 cmp = flag_finite_math_only
a3170dc6
AH
9770 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
9771 rs6000_compare_op1)
9772 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
9773 rs6000_compare_op1);
9774 break;
9775 case GT:
9776 case GTU:
9777 case UNGT:
9778 case UNGE:
9779 case GE:
9780 case GEU:
bc9ec0e0 9781 cmp = flag_finite_math_only
a3170dc6
AH
9782 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
9783 rs6000_compare_op1)
9784 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
9785 rs6000_compare_op1);
9786 break;
9787 case LT:
9788 case LTU:
9789 case UNLT:
9790 case UNLE:
9791 case LE:
9792 case LEU:
bc9ec0e0 9793 cmp = flag_finite_math_only
a3170dc6
AH
9794 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
9795 rs6000_compare_op1)
9796 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
9797 rs6000_compare_op1);
9798 break;
9799 default:
9800 abort ();
9801 }
9802
9803 /* Synthesize LE and GE from LT/GT || EQ. */
9804 if (code == LE || code == GE || code == LEU || code == GEU)
9805 {
9806 /* Synthesize GE/LE frome GT/LT || EQ. */
9807
9808 emit_insn (cmp);
9809
9810 switch (code)
9811 {
9812 case LE: code = LT; break;
9813 case GE: code = GT; break;
9814 case LEU: code = LT; break;
9815 case GEU: code = GT; break;
9816 default: abort ();
9817 }
9818
9819 or1 = gen_reg_rtx (SImode);
9820 or2 = gen_reg_rtx (SImode);
9821 or_result = gen_reg_rtx (CCEQmode);
9822 compare_result2 = gen_reg_rtx (CCFPmode);
9823
9824 /* Do the EQ. */
bc9ec0e0 9825 cmp = flag_finite_math_only
a3170dc6
AH
9826 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
9827 rs6000_compare_op1)
9828 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
9829 rs6000_compare_op1);
9830 emit_insn (cmp);
9831
9832 /* The MC8540 FP compare instructions set the CR bits
9833 differently than other PPC compare instructions. For
9834 that matter, there is no generic test instruction, but a
9835 testgt, testlt, and testeq. For a true condition, bit 2
9836 is set (x1xx) in the CR. Following the traditional CR
9837 values:
9838
9839 LT GT EQ OV
9840 bit3 bit2 bit1 bit0
9841
9842 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 9843 look in the GT bits for the branch instructions.
a3170dc6
AH
9844 However, we must be careful to emit correct RTL in
9845 the meantime, so optimizations don't get confused. */
9846
f1c25d3b
KH
9847 or1 = gen_rtx_NE (SImode, compare_result, const0_rtx);
9848 or2 = gen_rtx_NE (SImode, compare_result2, const0_rtx);
a3170dc6
AH
9849
9850 /* OR them together. */
9851 cmp = gen_rtx_SET (VOIDmode, or_result,
9852 gen_rtx_COMPARE (CCEQmode,
9853 gen_rtx_IOR (SImode, or1, or2),
9854 const_true_rtx));
9855 compare_result = or_result;
9856 code = EQ;
9857 }
9858 else
9859 {
9860 /* We only care about 1 bit (x1xx), so map everything to NE to
9861 maintain rtl sanity. We'll get to the right bit (x1xx) at
9862 code output time. */
9863 if (code == NE || code == LTGT)
9864 /* Do the inverse here because we have no cmpne
9865 instruction. We use the cmpeq instruction and expect
9866 to get a 0 instead. */
9867 code = EQ;
9868 else
9869 code = NE;
9870 }
9871
9872 emit_insn (cmp);
9873 }
9874 else
9875 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
9876 gen_rtx_COMPARE (comp_mode,
9877 rs6000_compare_op0,
9878 rs6000_compare_op1)));
39a10a29 9879
ca5adc63 9880 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 9881 under flag_finite_math_only we don't bother. */
39a10a29 9882 if (rs6000_compare_fp_p
bc9ec0e0 9883 && ! flag_finite_math_only
993f19a8 9884 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
9885 && (code == LE || code == GE
9886 || code == UNEQ || code == LTGT
9887 || code == UNGT || code == UNLT))
9888 {
9889 enum rtx_code or1, or2;
9890 rtx or1_rtx, or2_rtx, compare2_rtx;
9891 rtx or_result = gen_reg_rtx (CCEQmode);
9892
9893 switch (code)
9894 {
9895 case LE: or1 = LT; or2 = EQ; break;
9896 case GE: or1 = GT; or2 = EQ; break;
9897 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
9898 case LTGT: or1 = LT; or2 = GT; break;
9899 case UNGT: or1 = UNORDERED; or2 = GT; break;
9900 case UNLT: or1 = UNORDERED; or2 = LT; break;
9901 default: abort ();
9902 }
9903 validate_condition_mode (or1, comp_mode);
9904 validate_condition_mode (or2, comp_mode);
1c563bed
KH
9905 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
9906 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
9907 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
9908 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
9909 const_true_rtx);
9910 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
9911
9912 compare_result = or_result;
9913 code = EQ;
9914 }
9915
9916 validate_condition_mode (code, GET_MODE (compare_result));
9917
1c563bed 9918 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
9919}
9920
9921
9922/* Emit the RTL for an sCOND pattern. */
9923
9924void
a2369ed3 9925rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
9926{
9927 rtx condition_rtx;
9928 enum machine_mode op_mode;
b7053a3f 9929 enum rtx_code cond_code;
39a10a29
GK
9930
9931 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
9932 cond_code = GET_CODE (condition_rtx);
9933
9934 if (cond_code == NE
9935 || cond_code == GE || cond_code == LE
9936 || cond_code == GEU || cond_code == LEU
9937 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
9938 {
9939 rtx not_result = gen_reg_rtx (CCEQmode);
9940 rtx not_op, rev_cond_rtx;
9941 enum machine_mode cc_mode;
9942
9943 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
9944
1c563bed 9945 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 9946 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
9947 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
9948 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
9949 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
9950 }
39a10a29
GK
9951
9952 op_mode = GET_MODE (rs6000_compare_op0);
9953 if (op_mode == VOIDmode)
9954 op_mode = GET_MODE (rs6000_compare_op1);
9955
9956 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
9957 {
9958 PUT_MODE (condition_rtx, DImode);
9959 convert_move (result, condition_rtx, 0);
9960 }
9961 else
9962 {
9963 PUT_MODE (condition_rtx, SImode);
9964 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
9965 }
9966}
9967
39a10a29
GK
9968/* Emit a branch of kind CODE to location LOC. */
9969
9970void
a2369ed3 9971rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
9972{
9973 rtx condition_rtx, loc_ref;
9974
9975 condition_rtx = rs6000_generate_compare (code);
9976 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
9977 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
9978 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
9979 loc_ref, pc_rtx)));
9980}
9981
12a4e8c5
GK
9982/* Return the string to output a conditional branch to LABEL, which is
9983 the operand number of the label, or -1 if the branch is really a
9984 conditional return.
9985
9986 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
9987 condition code register and its mode specifies what kind of
9988 comparison we made.
9989
a0ab749a 9990 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
9991
9992 INSN is the insn. */
9993
9994char *
a2369ed3 9995output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
9996{
9997 static char string[64];
9998 enum rtx_code code = GET_CODE (op);
9999 rtx cc_reg = XEXP (op, 0);
10000 enum machine_mode mode = GET_MODE (cc_reg);
10001 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 10002 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
10003 int really_reversed = reversed ^ need_longbranch;
10004 char *s = string;
10005 const char *ccode;
10006 const char *pred;
10007 rtx note;
10008
39a10a29
GK
10009 validate_condition_mode (code, mode);
10010
10011 /* Work out which way this really branches. We could use
10012 reverse_condition_maybe_unordered here always but this
10013 makes the resulting assembler clearer. */
12a4e8c5 10014 if (really_reversed)
de40e1df
DJ
10015 {
10016 /* Reversal of FP compares takes care -- an ordered compare
10017 becomes an unordered compare and vice versa. */
10018 if (mode == CCFPmode)
10019 code = reverse_condition_maybe_unordered (code);
10020 else
10021 code = reverse_condition (code);
10022 }
12a4e8c5 10023
993f19a8 10024 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
10025 {
10026 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
10027 to the GT bit. */
10028 if (code == EQ)
10029 /* Opposite of GT. */
10030 code = UNLE;
10031 else if (code == NE)
10032 code = GT;
10033 else
10034 abort ();
10035 }
10036
39a10a29 10037 switch (code)
12a4e8c5
GK
10038 {
10039 /* Not all of these are actually distinct opcodes, but
10040 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
10041 case NE: case LTGT:
10042 ccode = "ne"; break;
10043 case EQ: case UNEQ:
10044 ccode = "eq"; break;
10045 case GE: case GEU:
10046 ccode = "ge"; break;
10047 case GT: case GTU: case UNGT:
10048 ccode = "gt"; break;
10049 case LE: case LEU:
10050 ccode = "le"; break;
10051 case LT: case LTU: case UNLT:
10052 ccode = "lt"; break;
12a4e8c5
GK
10053 case UNORDERED: ccode = "un"; break;
10054 case ORDERED: ccode = "nu"; break;
10055 case UNGE: ccode = "nl"; break;
10056 case UNLE: ccode = "ng"; break;
10057 default:
a4f6c312 10058 abort ();
12a4e8c5
GK
10059 }
10060
94a54f47
GK
10061 /* Maybe we have a guess as to how likely the branch is.
10062 The old mnemonics don't have a way to specify this information. */
f4857b9b 10063 pred = "";
12a4e8c5
GK
10064 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
10065 if (note != NULL_RTX)
10066 {
10067 /* PROB is the difference from 50%. */
10068 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
10069 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
10070
10071 /* Only hint for highly probable/improbable branches on newer
10072 cpus as static prediction overrides processor dynamic
10073 prediction. For older cpus we may as well always hint, but
10074 assume not taken for branches that are very close to 50% as a
10075 mispredicted taken branch is more expensive than a
10076 mispredicted not-taken branch. */
10077 if (always_hint
10078 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
10079 {
10080 if (abs (prob) > REG_BR_PROB_BASE / 20
10081 && ((prob > 0) ^ need_longbranch))
7f3d8013 10082 pred = "+";
f4857b9b
AM
10083 else
10084 pred = "-";
10085 }
12a4e8c5 10086 }
12a4e8c5
GK
10087
10088 if (label == NULL)
94a54f47 10089 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 10090 else
94a54f47 10091 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 10092
37c67319 10093 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 10094 Assume they'd only be the first character.... */
37c67319
GK
10095 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
10096 *s++ = '%';
94a54f47 10097 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
10098
10099 if (label != NULL)
10100 {
10101 /* If the branch distance was too far, we may have to use an
10102 unconditional branch to go the distance. */
10103 if (need_longbranch)
44518ddd 10104 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
10105 else
10106 s += sprintf (s, ",%s", label);
10107 }
10108
10109 return string;
10110}
50a0b056
GK
10111
10112/* Emit a conditional move: move TRUE_COND to DEST if OP of the
10113 operands of the last comparison is nonzero/true, FALSE_COND if it
10114 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 10115
50a0b056 10116int
a2369ed3 10117rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
10118{
10119 enum rtx_code code = GET_CODE (op);
10120 rtx op0 = rs6000_compare_op0;
10121 rtx op1 = rs6000_compare_op1;
10122 REAL_VALUE_TYPE c1;
3148ad6d
DJ
10123 enum machine_mode compare_mode = GET_MODE (op0);
10124 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
10125 rtx temp;
10126
a3c9585f 10127 /* These modes should always match. */
a3170dc6
AH
10128 if (GET_MODE (op1) != compare_mode
10129 /* In the isel case however, we can use a compare immediate, so
10130 op1 may be a small constant. */
10131 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 10132 return 0;
178c3eff 10133 if (GET_MODE (true_cond) != result_mode)
3148ad6d 10134 return 0;
178c3eff 10135 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
10136 return 0;
10137
50a0b056 10138 /* First, work out if the hardware can do this at all, or
a3c9585f 10139 if it's too slow.... */
50a0b056 10140 if (! rs6000_compare_fp_p)
a3170dc6
AH
10141 {
10142 if (TARGET_ISEL)
10143 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
10144 return 0;
10145 }
50a0b056
GK
10146
10147 /* Eliminate half of the comparisons by switching operands, this
10148 makes the remaining code simpler. */
10149 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 10150 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
10151 {
10152 code = reverse_condition_maybe_unordered (code);
10153 temp = true_cond;
10154 true_cond = false_cond;
10155 false_cond = temp;
10156 }
10157
10158 /* UNEQ and LTGT take four instructions for a comparison with zero,
10159 it'll probably be faster to use a branch here too. */
bc9ec0e0 10160 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
10161 return 0;
10162
10163 if (GET_CODE (op1) == CONST_DOUBLE)
10164 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
10165
b6d08ca1 10166 /* We're going to try to implement comparisons by performing
50a0b056
GK
10167 a subtract, then comparing against zero. Unfortunately,
10168 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 10169 know that the operand is finite and the comparison
50a0b056 10170 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 10171 if (HONOR_INFINITIES (compare_mode)
50a0b056 10172 && code != GT && code != UNGE
045572c7 10173 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
10174 /* Constructs of the form (a OP b ? a : b) are safe. */
10175 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
10176 || (! rtx_equal_p (op0, true_cond)
10177 && ! rtx_equal_p (op1, true_cond))))
10178 return 0;
10179 /* At this point we know we can use fsel. */
10180
10181 /* Reduce the comparison to a comparison against zero. */
3148ad6d 10182 temp = gen_reg_rtx (compare_mode);
50a0b056 10183 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10184 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 10185 op0 = temp;
3148ad6d 10186 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
10187
10188 /* If we don't care about NaNs we can reduce some of the comparisons
10189 down to faster ones. */
bc9ec0e0 10190 if (! HONOR_NANS (compare_mode))
50a0b056
GK
10191 switch (code)
10192 {
10193 case GT:
10194 code = LE;
10195 temp = true_cond;
10196 true_cond = false_cond;
10197 false_cond = temp;
10198 break;
10199 case UNGE:
10200 code = GE;
10201 break;
10202 case UNEQ:
10203 code = EQ;
10204 break;
10205 default:
10206 break;
10207 }
10208
10209 /* Now, reduce everything down to a GE. */
10210 switch (code)
10211 {
10212 case GE:
10213 break;
10214
10215 case LE:
3148ad6d
DJ
10216 temp = gen_reg_rtx (compare_mode);
10217 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10218 op0 = temp;
10219 break;
10220
10221 case ORDERED:
3148ad6d
DJ
10222 temp = gen_reg_rtx (compare_mode);
10223 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
10224 op0 = temp;
10225 break;
10226
10227 case EQ:
3148ad6d 10228 temp = gen_reg_rtx (compare_mode);
50a0b056 10229 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
10230 gen_rtx_NEG (compare_mode,
10231 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
10232 op0 = temp;
10233 break;
10234
10235 case UNGE:
bc9ec0e0 10236 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 10237 temp = gen_reg_rtx (result_mode);
50a0b056 10238 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10239 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10240 gen_rtx_GE (VOIDmode,
10241 op0, op1),
10242 true_cond, false_cond)));
bc9ec0e0
GK
10243 false_cond = true_cond;
10244 true_cond = temp;
50a0b056 10245
3148ad6d
DJ
10246 temp = gen_reg_rtx (compare_mode);
10247 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10248 op0 = temp;
10249 break;
10250
10251 case GT:
bc9ec0e0 10252 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 10253 temp = gen_reg_rtx (result_mode);
50a0b056 10254 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10255 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10256 gen_rtx_GE (VOIDmode,
10257 op0, op1),
10258 true_cond, false_cond)));
bc9ec0e0
GK
10259 true_cond = false_cond;
10260 false_cond = temp;
50a0b056 10261
3148ad6d
DJ
10262 temp = gen_reg_rtx (compare_mode);
10263 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10264 op0 = temp;
10265 break;
10266
10267 default:
10268 abort ();
10269 }
10270
10271 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 10272 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10273 gen_rtx_GE (VOIDmode,
10274 op0, op1),
10275 true_cond, false_cond)));
10276 return 1;
10277}
10278
a3170dc6
AH
10279/* Same as above, but for ints (isel). */
10280
10281static int
a2369ed3 10282rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
10283{
10284 rtx condition_rtx, cr;
10285
10286 /* All isel implementations thus far are 32-bits. */
10287 if (GET_MODE (rs6000_compare_op0) != SImode)
10288 return 0;
10289
10290 /* We still have to do the compare, because isel doesn't do a
10291 compare, it just looks at the CRx bits set by a previous compare
10292 instruction. */
10293 condition_rtx = rs6000_generate_compare (GET_CODE (op));
10294 cr = XEXP (condition_rtx, 0);
10295
10296 if (GET_MODE (cr) == CCmode)
10297 emit_insn (gen_isel_signed (dest, condition_rtx,
10298 true_cond, false_cond, cr));
10299 else
10300 emit_insn (gen_isel_unsigned (dest, condition_rtx,
10301 true_cond, false_cond, cr));
10302
10303 return 1;
10304}
10305
10306const char *
a2369ed3 10307output_isel (rtx *operands)
a3170dc6
AH
10308{
10309 enum rtx_code code;
10310
10311 code = GET_CODE (operands[1]);
10312 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
10313 {
10314 PUT_CODE (operands[1], reverse_condition (code));
10315 return "isel %0,%3,%2,%j1";
10316 }
10317 else
10318 return "isel %0,%2,%3,%j1";
10319}
10320
50a0b056 10321void
a2369ed3 10322rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
10323{
10324 enum machine_mode mode = GET_MODE (op0);
5dc8d536 10325 enum rtx_code c;
50a0b056 10326 rtx target;
5dc8d536
AH
10327
10328 if (code == SMAX || code == SMIN)
10329 c = GE;
10330 else
10331 c = GEU;
10332
50a0b056 10333 if (code == SMAX || code == UMAX)
5dc8d536 10334 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10335 op0, op1, mode, 0);
10336 else
5dc8d536 10337 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10338 op1, op0, mode, 0);
10339 if (target == NULL_RTX)
10340 abort ();
10341 if (target != dest)
10342 emit_move_insn (dest, target);
10343}
46c07df8 10344
a9baceb1
GK
10345/* Emit instructions to move SRC to DST. Called by splitters for
10346 multi-register moves. It will emit at most one instruction for
10347 each register that is accessed; that is, it won't emit li/lis pairs
10348 (or equivalent for 64-bit code). One of SRC or DST must be a hard
10349 register. */
46c07df8 10350
46c07df8 10351void
a9baceb1 10352rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 10353{
a9baceb1
GK
10354 /* The register number of the first register being moved. */
10355 int reg;
10356 /* The mode that is to be moved. */
10357 enum machine_mode mode;
10358 /* The mode that the move is being done in, and its size. */
10359 enum machine_mode reg_mode;
10360 int reg_mode_size;
10361 /* The number of registers that will be moved. */
10362 int nregs;
10363
10364 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
10365 mode = GET_MODE (dst);
10366 nregs = HARD_REGNO_NREGS (reg, mode);
10367 if (FP_REGNO_P (reg))
10368 reg_mode = DFmode;
10369 else if (ALTIVEC_REGNO_P (reg))
10370 reg_mode = V16QImode;
10371 else
10372 reg_mode = word_mode;
10373 reg_mode_size = GET_MODE_SIZE (reg_mode);
46c07df8 10374
a9baceb1
GK
10375 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
10376 abort ();
10377
10378 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
10379 {
10380 /* Move register range backwards, if we might have destructive
10381 overlap. */
10382 int i;
10383 for (i = nregs - 1; i >= 0; i--)
10384 emit_insn (gen_rtx_SET (VOIDmode,
10385 simplify_gen_subreg (reg_mode, dst, mode,
10386 i * reg_mode_size),
10387 simplify_gen_subreg (reg_mode, src, mode,
10388 i * reg_mode_size)));
10389 }
46c07df8
HP
10390 else
10391 {
a9baceb1
GK
10392 int i;
10393 int j = -1;
10394 bool used_update = false;
46c07df8 10395
a9baceb1 10396 if (GET_CODE (src) == MEM && INT_REGNO_P (reg))
46c07df8
HP
10397 {
10398 rtx breg;
3a1f863f 10399
a9baceb1
GK
10400 if (GET_CODE (XEXP (src, 0)) == PRE_INC
10401 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
10402 {
10403 rtx delta_rtx;
a9baceb1
GK
10404 breg = XEXP (XEXP (src, 0), 0);
10405 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
10406 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
10407 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
10408 emit_insn (TARGET_32BIT
10409 ? gen_addsi3 (breg, breg, delta_rtx)
10410 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10411 src = gen_rtx_MEM (mode, breg);
10412 }
10413
10414 /* We have now address involving an base register only.
10415 If we use one of the registers to address memory,
10416 we have change that register last. */
10417
10418 breg = (GET_CODE (XEXP (src, 0)) == PLUS
10419 ? XEXP (XEXP (src, 0), 0)
10420 : XEXP (src, 0));
10421
10422 if (!REG_P (breg))
10423 abort();
10424
10425 if (REGNO (breg) >= REGNO (dst)
10426 && REGNO (breg) < REGNO (dst) + nregs)
10427 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
10428 }
10429
a9baceb1 10430 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
10431 {
10432 rtx breg;
10433
a9baceb1
GK
10434 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
10435 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
10436 {
10437 rtx delta_rtx;
a9baceb1
GK
10438 breg = XEXP (XEXP (dst, 0), 0);
10439 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
10440 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
10441 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
10442
10443 /* We have to update the breg before doing the store.
10444 Use store with update, if available. */
10445
10446 if (TARGET_UPDATE)
10447 {
a9baceb1
GK
10448 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
10449 emit_insn (TARGET_32BIT
10450 ? gen_movsi_update (breg, breg, delta_rtx, nsrc)
10451 : gen_movdi_update (breg, breg, delta_rtx, nsrc));
10452 used_update = true;
3a1f863f
DE
10453 }
10454 else
a9baceb1
GK
10455 emit_insn (TARGET_32BIT
10456 ? gen_addsi3 (breg, breg, delta_rtx)
10457 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10458 dst = gen_rtx_MEM (mode, breg);
10459 }
10460 }
10461
46c07df8 10462 for (i = 0; i < nregs; i++)
3a1f863f
DE
10463 {
10464 /* Calculate index to next subword. */
10465 ++j;
10466 if (j == nregs)
10467 j = 0;
46c07df8 10468
a9baceb1
GK
10469 /* If compiler already emited move of first word by
10470 store with update, no need to do anything. */
3a1f863f 10471 if (j == 0 && used_update)
a9baceb1
GK
10472 continue;
10473
10474 emit_insn (gen_rtx_SET (VOIDmode,
10475 simplify_gen_subreg (reg_mode, dst, mode,
10476 j * reg_mode_size),
10477 simplify_gen_subreg (reg_mode, src, mode,
10478 j * reg_mode_size)));
3a1f863f 10479 }
46c07df8
HP
10480 }
10481}
10482
12a4e8c5 10483\f
a4f6c312
SS
10484/* This page contains routines that are used to determine what the
10485 function prologue and epilogue code will do and write them out. */
9878760c 10486
a4f6c312
SS
10487/* Return the first fixed-point register that is required to be
10488 saved. 32 if none. */
9878760c
RK
10489
10490int
863d938c 10491first_reg_to_save (void)
9878760c
RK
10492{
10493 int first_reg;
10494
10495 /* Find lowest numbered live register. */
10496 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
10497 if (regs_ever_live[first_reg]
10498 && (! call_used_regs[first_reg]
1db02437 10499 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10500 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10501 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
10502 break;
10503
ee890fe2 10504#if TARGET_MACHO
93638d7a
AM
10505 if (flag_pic
10506 && current_function_uses_pic_offset_table
10507 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 10508 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
10509#endif
10510
9878760c
RK
10511 return first_reg;
10512}
10513
10514/* Similar, for FP regs. */
10515
10516int
863d938c 10517first_fp_reg_to_save (void)
9878760c
RK
10518{
10519 int first_reg;
10520
10521 /* Find lowest numbered live register. */
10522 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
10523 if (regs_ever_live[first_reg])
10524 break;
10525
10526 return first_reg;
10527}
00b960c7
AH
10528
10529/* Similar, for AltiVec regs. */
10530
10531static int
863d938c 10532first_altivec_reg_to_save (void)
00b960c7
AH
10533{
10534 int i;
10535
10536 /* Stack frame remains as is unless we are in AltiVec ABI. */
10537 if (! TARGET_ALTIVEC_ABI)
10538 return LAST_ALTIVEC_REGNO + 1;
10539
10540 /* Find lowest numbered live register. */
10541 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
10542 if (regs_ever_live[i])
10543 break;
10544
10545 return i;
10546}
10547
10548/* Return a 32-bit mask of the AltiVec registers we need to set in
10549 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
10550 the 32-bit word is 0. */
10551
10552static unsigned int
863d938c 10553compute_vrsave_mask (void)
00b960c7
AH
10554{
10555 unsigned int i, mask = 0;
10556
10557 /* First, find out if we use _any_ altivec registers. */
10558 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10559 if (regs_ever_live[i])
10560 mask |= ALTIVEC_REG_BIT (i);
10561
10562 if (mask == 0)
10563 return mask;
10564
00b960c7
AH
10565 /* Next, remove the argument registers from the set. These must
10566 be in the VRSAVE mask set by the caller, so we don't need to add
10567 them in again. More importantly, the mask we compute here is
10568 used to generate CLOBBERs in the set_vrsave insn, and we do not
10569 wish the argument registers to die. */
a6cf80f2 10570 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
10571 mask &= ~ALTIVEC_REG_BIT (i);
10572
10573 /* Similarly, remove the return value from the set. */
10574 {
10575 bool yes = false;
10576 diddle_return_value (is_altivec_return_reg, &yes);
10577 if (yes)
10578 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
10579 }
10580
10581 return mask;
10582}
10583
10584static void
a2369ed3 10585is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
10586{
10587 bool *yes = (bool *) xyes;
10588 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
10589 *yes = true;
10590}
10591
4697a36c
MM
10592\f
10593/* Calculate the stack information for the current function. This is
10594 complicated by having two separate calling sequences, the AIX calling
10595 sequence and the V.4 calling sequence.
10596
592696dd 10597 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 10598 32-bit 64-bit
4697a36c 10599 SP----> +---------------------------------------+
a260abc9 10600 | back chain to caller | 0 0
4697a36c 10601 +---------------------------------------+
a260abc9 10602 | saved CR | 4 8 (8-11)
4697a36c 10603 +---------------------------------------+
a260abc9 10604 | saved LR | 8 16
4697a36c 10605 +---------------------------------------+
a260abc9 10606 | reserved for compilers | 12 24
4697a36c 10607 +---------------------------------------+
a260abc9 10608 | reserved for binders | 16 32
4697a36c 10609 +---------------------------------------+
a260abc9 10610 | saved TOC pointer | 20 40
4697a36c 10611 +---------------------------------------+
a260abc9 10612 | Parameter save area (P) | 24 48
4697a36c 10613 +---------------------------------------+
a260abc9 10614 | Alloca space (A) | 24+P etc.
802a0058 10615 +---------------------------------------+
a7df97e6 10616 | Local variable space (L) | 24+P+A
4697a36c 10617 +---------------------------------------+
a7df97e6 10618 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 10619 +---------------------------------------+
00b960c7
AH
10620 | Save area for AltiVec registers (W) | 24+P+A+L+X
10621 +---------------------------------------+
10622 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
10623 +---------------------------------------+
10624 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 10625 +---------------------------------------+
00b960c7
AH
10626 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
10627 +---------------------------------------+
10628 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
10629 +---------------------------------------+
10630 old SP->| back chain to caller's caller |
10631 +---------------------------------------+
10632
5376a30c
KR
10633 The required alignment for AIX configurations is two words (i.e., 8
10634 or 16 bytes).
10635
10636
4697a36c
MM
10637 V.4 stack frames look like:
10638
10639 SP----> +---------------------------------------+
10640 | back chain to caller | 0
10641 +---------------------------------------+
5eb387b8 10642 | caller's saved LR | 4
4697a36c
MM
10643 +---------------------------------------+
10644 | Parameter save area (P) | 8
10645 +---------------------------------------+
a7df97e6
MM
10646 | Alloca space (A) | 8+P
10647 +---------------------------------------+
10648 | Varargs save area (V) | 8+P+A
10649 +---------------------------------------+
10650 | Local variable space (L) | 8+P+A+V
10651 +---------------------------------------+
10652 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10653 +---------------------------------------+
00b960c7
AH
10654 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10655 +---------------------------------------+
10656 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10657 +---------------------------------------+
10658 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10659 +---------------------------------------+
a3170dc6
AH
10660 | SPE: area for 64-bit GP registers |
10661 +---------------------------------------+
10662 | SPE alignment padding |
10663 +---------------------------------------+
00b960c7 10664 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10665 +---------------------------------------+
00b960c7 10666 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10667 +---------------------------------------+
00b960c7 10668 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10669 +---------------------------------------+
10670 old SP->| back chain to caller's caller |
10671 +---------------------------------------+
b6c9286a 10672
5376a30c
KR
10673 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10674 given. (But note below and in sysv4.h that we require only 8 and
10675 may round up the size of our stack frame anyways. The historical
10676 reason is early versions of powerpc-linux which didn't properly
10677 align the stack at program startup. A happy side-effect is that
10678 -mno-eabi libraries can be used with -meabi programs.)
10679
50d440bc 10680 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10681 the stack alignment requirements may differ. If -mno-eabi is not
10682 given, the required stack alignment is 8 bytes; if -mno-eabi is
10683 given, the required alignment is 16 bytes. (But see V.4 comment
10684 above.) */
4697a36c 10685
61b2fbe7
MM
10686#ifndef ABI_STACK_BOUNDARY
10687#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10688#endif
10689
d1d0c603 10690static rs6000_stack_t *
863d938c 10691rs6000_stack_info (void)
4697a36c
MM
10692{
10693 static rs6000_stack_t info, zero_info;
10694 rs6000_stack_t *info_ptr = &info;
327e5343 10695 int reg_size = TARGET_32BIT ? 4 : 8;
83720594 10696 int ehrd_size;
d1d0c603 10697 HOST_WIDE_INT total_raw_size;
4697a36c 10698
a4f6c312 10699 /* Zero all fields portably. */
4697a36c
MM
10700 info = zero_info;
10701
c19de7aa
AH
10702 if (TARGET_SPE)
10703 {
10704 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10705 if (cfun->machine->insn_chain_scanned_p == 0)
10706 {
10707 cfun->machine->insn_chain_scanned_p = 1;
10708 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10709 }
c19de7aa
AH
10710 }
10711
a4f6c312 10712 /* Select which calling sequence. */
178274da 10713 info_ptr->abi = DEFAULT_ABI;
9878760c 10714
a4f6c312 10715 /* Calculate which registers need to be saved & save area size. */
4697a36c 10716 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10717 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10718 even if it currently looks like we won't. */
2bfcf297 10719 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10720 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10721 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10722 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
10723 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
10724 else
10725 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 10726
a3170dc6
AH
10727 /* For the SPE, we have an additional upper 32-bits on each GPR.
10728 Ideally we should save the entire 64-bits only when the upper
10729 half is used in SIMD instructions. Since we only record
10730 registers live (not the size they are used in), this proves
10731 difficult because we'd have to traverse the instruction chain at
10732 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
10733 so we opt to save the GPRs in 64-bits always if but one register
10734 gets used in 64-bits. Otherwise, all the registers in the frame
10735 get saved in 32-bits.
a3170dc6 10736
c19de7aa 10737 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 10738 traditional GP save area will be empty. */
c19de7aa 10739 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10740 info_ptr->gp_size = 0;
10741
4697a36c
MM
10742 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
10743 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
10744
00b960c7
AH
10745 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
10746 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
10747 - info_ptr->first_altivec_reg_save);
10748
592696dd 10749 /* Does this function call anything? */
71f123ca
FS
10750 info_ptr->calls_p = (! current_function_is_leaf
10751 || cfun->machine->ra_needs_full_frame);
b6c9286a 10752
a4f6c312 10753 /* Determine if we need to save the link register. */
71f123ca 10754 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
10755 || (DEFAULT_ABI == ABI_AIX
10756 && current_function_profile
10757 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
10758#ifdef TARGET_RELOCATABLE
10759 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
10760#endif
10761 || (info_ptr->first_fp_reg_save != 64
10762 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 10763 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 10764 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
10765 || (DEFAULT_ABI == ABI_DARWIN
10766 && flag_pic
10767 && current_function_uses_pic_offset_table)
4697a36c
MM
10768 || info_ptr->calls_p)
10769 {
10770 info_ptr->lr_save_p = 1;
9ebbca7d 10771 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
10772 }
10773
9ebbca7d
GK
10774 /* Determine if we need to save the condition code registers. */
10775 if (regs_ever_live[CR2_REGNO]
10776 || regs_ever_live[CR3_REGNO]
10777 || regs_ever_live[CR4_REGNO])
4697a36c
MM
10778 {
10779 info_ptr->cr_save_p = 1;
178274da 10780 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
10781 info_ptr->cr_size = reg_size;
10782 }
10783
83720594
RH
10784 /* If the current function calls __builtin_eh_return, then we need
10785 to allocate stack space for registers that will hold data for
10786 the exception handler. */
10787 if (current_function_calls_eh_return)
10788 {
10789 unsigned int i;
10790 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
10791 continue;
a3170dc6
AH
10792
10793 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
10794 ehrd_size = i * (TARGET_SPE_ABI
10795 && info_ptr->spe_64bit_regs_used != 0
10796 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
10797 }
10798 else
10799 ehrd_size = 0;
10800
592696dd 10801 /* Determine various sizes. */
4697a36c
MM
10802 info_ptr->reg_size = reg_size;
10803 info_ptr->fixed_size = RS6000_SAVE_AREA;
10804 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 10805 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
10806 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
10807 8);
00b960c7 10808
c19de7aa 10809 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10810 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
10811 else
10812 info_ptr->spe_gp_size = 0;
10813
4d774ff8
HP
10814 if (TARGET_ALTIVEC_ABI)
10815 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 10816 else
4d774ff8
HP
10817 info_ptr->vrsave_mask = 0;
10818
10819 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
10820 info_ptr->vrsave_size = 4;
10821 else
10822 info_ptr->vrsave_size = 0;
b6c9286a 10823
592696dd 10824 /* Calculate the offsets. */
178274da 10825 switch (DEFAULT_ABI)
4697a36c 10826 {
b6c9286a 10827 case ABI_NONE:
24d304eb 10828 default:
b6c9286a
MM
10829 abort ();
10830
10831 case ABI_AIX:
ee890fe2 10832 case ABI_DARWIN:
b6c9286a
MM
10833 info_ptr->fp_save_offset = - info_ptr->fp_size;
10834 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
10835
10836 if (TARGET_ALTIVEC_ABI)
10837 {
10838 info_ptr->vrsave_save_offset
10839 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
10840
10841 /* Align stack so vector save area is on a quadword boundary. */
10842 if (info_ptr->altivec_size != 0)
10843 info_ptr->altivec_padding_size
10844 = 16 - (-info_ptr->vrsave_save_offset % 16);
10845 else
10846 info_ptr->altivec_padding_size = 0;
10847
10848 info_ptr->altivec_save_offset
10849 = info_ptr->vrsave_save_offset
10850 - info_ptr->altivec_padding_size
10851 - info_ptr->altivec_size;
10852
10853 /* Adjust for AltiVec case. */
10854 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
10855 }
10856 else
10857 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
10858 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
10859 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
10860 break;
10861
10862 case ABI_V4:
b6c9286a
MM
10863 info_ptr->fp_save_offset = - info_ptr->fp_size;
10864 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 10865 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 10866
c19de7aa 10867 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10868 {
10869 /* Align stack so SPE GPR save area is aligned on a
10870 double-word boundary. */
10871 if (info_ptr->spe_gp_size != 0)
10872 info_ptr->spe_padding_size
10873 = 8 - (-info_ptr->cr_save_offset % 8);
10874 else
10875 info_ptr->spe_padding_size = 0;
10876
10877 info_ptr->spe_gp_save_offset
10878 = info_ptr->cr_save_offset
10879 - info_ptr->spe_padding_size
10880 - info_ptr->spe_gp_size;
10881
10882 /* Adjust for SPE case. */
10883 info_ptr->toc_save_offset
10884 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
10885 }
10886 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
10887 {
10888 info_ptr->vrsave_save_offset
10889 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
10890
10891 /* Align stack so vector save area is on a quadword boundary. */
10892 if (info_ptr->altivec_size != 0)
10893 info_ptr->altivec_padding_size
10894 = 16 - (-info_ptr->vrsave_save_offset % 16);
10895 else
10896 info_ptr->altivec_padding_size = 0;
10897
10898 info_ptr->altivec_save_offset
10899 = info_ptr->vrsave_save_offset
10900 - info_ptr->altivec_padding_size
10901 - info_ptr->altivec_size;
10902
10903 /* Adjust for AltiVec case. */
10904 info_ptr->toc_save_offset
10905 = info_ptr->altivec_save_offset - info_ptr->toc_size;
10906 }
10907 else
10908 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 10909 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
10910 info_ptr->lr_save_offset = reg_size;
10911 break;
4697a36c
MM
10912 }
10913
00b960c7
AH
10914 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
10915 + info_ptr->gp_size
10916 + info_ptr->altivec_size
10917 + info_ptr->altivec_padding_size
a3170dc6
AH
10918 + info_ptr->spe_gp_size
10919 + info_ptr->spe_padding_size
00b960c7
AH
10920 + ehrd_size
10921 + info_ptr->cr_size
10922 + info_ptr->lr_size
10923 + info_ptr->vrsave_size
10924 + info_ptr->toc_size,
10925 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
10926 ? 16 : 8);
10927
ff381587
MM
10928 total_raw_size = (info_ptr->vars_size
10929 + info_ptr->parm_size
ff381587
MM
10930 + info_ptr->save_size
10931 + info_ptr->varargs_size
10932 + info_ptr->fixed_size);
10933
a4f6c312
SS
10934 info_ptr->total_size =
10935 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
10936
10937 /* Determine if we need to allocate any stack frame:
10938
a4f6c312
SS
10939 For AIX we need to push the stack if a frame pointer is needed
10940 (because the stack might be dynamically adjusted), if we are
10941 debugging, if we make calls, or if the sum of fp_save, gp_save,
10942 and local variables are more than the space needed to save all
10943 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
10944 + 18*8 = 288 (GPR13 reserved).
ff381587 10945
a4f6c312
SS
10946 For V.4 we don't have the stack cushion that AIX uses, but assume
10947 that the debugger can handle stackless frames. */
ff381587
MM
10948
10949 if (info_ptr->calls_p)
10950 info_ptr->push_p = 1;
10951
178274da 10952 else if (DEFAULT_ABI == ABI_V4)
e72247f4 10953 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587 10954
178274da
AM
10955 else if (frame_pointer_needed)
10956 info_ptr->push_p = 1;
10957
10958 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
10959 info_ptr->push_p = 1;
10960
ff381587 10961 else
178274da
AM
10962 info_ptr->push_p
10963 = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 10964
a4f6c312 10965 /* Zero offsets if we're not saving those registers. */
8dda1a21 10966 if (info_ptr->fp_size == 0)
4697a36c
MM
10967 info_ptr->fp_save_offset = 0;
10968
8dda1a21 10969 if (info_ptr->gp_size == 0)
4697a36c
MM
10970 info_ptr->gp_save_offset = 0;
10971
00b960c7
AH
10972 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
10973 info_ptr->altivec_save_offset = 0;
10974
10975 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
10976 info_ptr->vrsave_save_offset = 0;
10977
c19de7aa
AH
10978 if (! TARGET_SPE_ABI
10979 || info_ptr->spe_64bit_regs_used == 0
10980 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
10981 info_ptr->spe_gp_save_offset = 0;
10982
c81fc13e 10983 if (! info_ptr->lr_save_p)
4697a36c
MM
10984 info_ptr->lr_save_offset = 0;
10985
c81fc13e 10986 if (! info_ptr->cr_save_p)
4697a36c
MM
10987 info_ptr->cr_save_offset = 0;
10988
c81fc13e 10989 if (! info_ptr->toc_save_p)
b6c9286a
MM
10990 info_ptr->toc_save_offset = 0;
10991
4697a36c
MM
10992 return info_ptr;
10993}
10994
c19de7aa
AH
10995/* Return true if the current function uses any GPRs in 64-bit SIMD
10996 mode. */
10997
10998static bool
863d938c 10999spe_func_has_64bit_regs_p (void)
c19de7aa
AH
11000{
11001 rtx insns, insn;
11002
11003 /* Functions that save and restore all the call-saved registers will
11004 need to save/restore the registers in 64-bits. */
11005 if (current_function_calls_eh_return
11006 || current_function_calls_setjmp
11007 || current_function_has_nonlocal_goto)
11008 return true;
11009
11010 insns = get_insns ();
11011
11012 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
11013 {
11014 if (INSN_P (insn))
11015 {
11016 rtx i;
11017
11018 i = PATTERN (insn);
11019 if (GET_CODE (i) == SET
11020 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
11021 return true;
11022 }
11023 }
11024
11025 return false;
11026}
11027
d1d0c603 11028static void
a2369ed3 11029debug_stack_info (rs6000_stack_t *info)
9878760c 11030{
d330fd93 11031 const char *abi_string;
24d304eb 11032
c81fc13e 11033 if (! info)
4697a36c
MM
11034 info = rs6000_stack_info ();
11035
11036 fprintf (stderr, "\nStack information for function %s:\n",
11037 ((current_function_decl && DECL_NAME (current_function_decl))
11038 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
11039 : "<unknown>"));
11040
24d304eb
RK
11041 switch (info->abi)
11042 {
b6c9286a
MM
11043 default: abi_string = "Unknown"; break;
11044 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 11045 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 11046 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 11047 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
11048 }
11049
11050 fprintf (stderr, "\tABI = %5s\n", abi_string);
11051
00b960c7
AH
11052 if (TARGET_ALTIVEC_ABI)
11053 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
11054
a3170dc6
AH
11055 if (TARGET_SPE_ABI)
11056 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
11057
4697a36c
MM
11058 if (info->first_gp_reg_save != 32)
11059 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
11060
11061 if (info->first_fp_reg_save != 64)
11062 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 11063
00b960c7
AH
11064 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
11065 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
11066 info->first_altivec_reg_save);
11067
4697a36c
MM
11068 if (info->lr_save_p)
11069 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 11070
4697a36c
MM
11071 if (info->cr_save_p)
11072 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
11073
b6c9286a
MM
11074 if (info->toc_save_p)
11075 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
11076
00b960c7
AH
11077 if (info->vrsave_mask)
11078 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
11079
4697a36c
MM
11080 if (info->push_p)
11081 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
11082
11083 if (info->calls_p)
11084 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
11085
4697a36c
MM
11086 if (info->gp_save_offset)
11087 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
11088
11089 if (info->fp_save_offset)
11090 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
11091
00b960c7
AH
11092 if (info->altivec_save_offset)
11093 fprintf (stderr, "\taltivec_save_offset = %5d\n",
11094 info->altivec_save_offset);
11095
a3170dc6
AH
11096 if (info->spe_gp_save_offset)
11097 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
11098 info->spe_gp_save_offset);
11099
00b960c7
AH
11100 if (info->vrsave_save_offset)
11101 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
11102 info->vrsave_save_offset);
11103
4697a36c
MM
11104 if (info->lr_save_offset)
11105 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
11106
11107 if (info->cr_save_offset)
11108 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
11109
b6c9286a
MM
11110 if (info->toc_save_offset)
11111 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
11112
4697a36c
MM
11113 if (info->varargs_save_offset)
11114 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
11115
11116 if (info->total_size)
d1d0c603
JJ
11117 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11118 info->total_size);
4697a36c
MM
11119
11120 if (info->varargs_size)
11121 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
11122
11123 if (info->vars_size)
d1d0c603
JJ
11124 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
11125 info->vars_size);
4697a36c
MM
11126
11127 if (info->parm_size)
11128 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
11129
11130 if (info->fixed_size)
11131 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
11132
11133 if (info->gp_size)
11134 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
11135
a3170dc6
AH
11136 if (info->spe_gp_size)
11137 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
11138
4697a36c
MM
11139 if (info->fp_size)
11140 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
11141
00b960c7
AH
11142 if (info->altivec_size)
11143 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
11144
11145 if (info->vrsave_size)
11146 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
11147
11148 if (info->altivec_padding_size)
11149 fprintf (stderr, "\taltivec_padding_size= %5d\n",
11150 info->altivec_padding_size);
11151
a3170dc6
AH
11152 if (info->spe_padding_size)
11153 fprintf (stderr, "\tspe_padding_size = %5d\n",
11154 info->spe_padding_size);
11155
a4f6c312 11156 if (info->lr_size)
ed947a96 11157 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 11158
4697a36c
MM
11159 if (info->cr_size)
11160 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
11161
a4f6c312 11162 if (info->toc_size)
b6c9286a
MM
11163 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
11164
4697a36c
MM
11165 if (info->save_size)
11166 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
11167
11168 if (info->reg_size != 4)
11169 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
11170
11171 fprintf (stderr, "\n");
9878760c 11172}
71f123ca
FS
11173
11174rtx
a2369ed3 11175rs6000_return_addr (int count, rtx frame)
71f123ca 11176{
a4f6c312
SS
11177 /* Currently we don't optimize very well between prolog and body
11178 code and for PIC code the code can be actually quite bad, so
11179 don't try to be too clever here. */
f1384257 11180 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
11181 {
11182 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
11183
11184 return
11185 gen_rtx_MEM
11186 (Pmode,
11187 memory_address
11188 (Pmode,
11189 plus_constant (copy_to_reg
11190 (gen_rtx_MEM (Pmode,
11191 memory_address (Pmode, frame))),
11192 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
11193 }
11194
8c29550d 11195 cfun->machine->ra_need_lr = 1;
9e2f7ec7 11196 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
11197}
11198
5e1bf043
DJ
11199/* Say whether a function is a candidate for sibcall handling or not.
11200 We do not allow indirect calls to be optimized into sibling calls.
11201 Also, we can't do it if there are any vector parameters; there's
11202 nowhere to put the VRsave code so it works; note that functions with
11203 vector parameters are required to have a prototype, so the argument
11204 type info must be available here. (The tail recursion case can work
11205 with vector parameters, but there's no way to distinguish here.) */
4977bab6 11206static bool
a2369ed3 11207rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
11208{
11209 tree type;
4977bab6 11210 if (decl)
5e1bf043
DJ
11211 {
11212 if (TARGET_ALTIVEC_VRSAVE)
11213 {
4977bab6 11214 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
11215 type; type = TREE_CHAIN (type))
11216 {
c15b529f 11217 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 11218 return false;
5e1bf043
DJ
11219 }
11220 }
11221 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 11222 || (*targetm.binds_local_p) (decl))
2bcc50d0 11223 {
4977bab6 11224 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
11225
11226 if (!lookup_attribute ("longcall", attr_list)
11227 || lookup_attribute ("shortcall", attr_list))
4977bab6 11228 return true;
2bcc50d0 11229 }
5e1bf043 11230 }
4977bab6 11231 return false;
5e1bf043
DJ
11232}
11233
71f123ca 11234static int
863d938c 11235rs6000_ra_ever_killed (void)
71f123ca
FS
11236{
11237 rtx top;
5e1bf043
DJ
11238 rtx reg;
11239 rtx insn;
71f123ca 11240
dd292d0a 11241 if (current_function_is_thunk)
71f123ca 11242 return 0;
eb0424da 11243
36f7e964
AH
11244 /* regs_ever_live has LR marked as used if any sibcalls are present,
11245 but this should not force saving and restoring in the
11246 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 11247 clobbers LR, so that is inappropriate. */
36f7e964 11248
5e1bf043
DJ
11249 /* Also, the prologue can generate a store into LR that
11250 doesn't really count, like this:
36f7e964 11251
5e1bf043
DJ
11252 move LR->R0
11253 bcl to set PIC register
11254 move LR->R31
11255 move R0->LR
36f7e964
AH
11256
11257 When we're called from the epilogue, we need to avoid counting
11258 this as a store. */
5e1bf043 11259
71f123ca
FS
11260 push_topmost_sequence ();
11261 top = get_insns ();
11262 pop_topmost_sequence ();
5e1bf043 11263 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 11264
5e1bf043
DJ
11265 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
11266 {
11267 if (INSN_P (insn))
11268 {
11269 if (FIND_REG_INC_NOTE (insn, reg))
11270 return 1;
11271 else if (GET_CODE (insn) == CALL_INSN
c15b529f 11272 && !SIBLING_CALL_P (insn))
5e1bf043 11273 return 1;
36f7e964
AH
11274 else if (set_of (reg, insn) != NULL_RTX
11275 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
11276 return 1;
11277 }
11278 }
11279 return 0;
71f123ca 11280}
4697a36c 11281\f
8cd8f856
GK
11282/* Add a REG_MAYBE_DEAD note to the insn. */
11283static void
a2369ed3 11284rs6000_maybe_dead (rtx insn)
8cd8f856
GK
11285{
11286 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
11287 const0_rtx,
11288 REG_NOTES (insn));
11289}
11290
9ebbca7d 11291/* Emit instructions needed to load the TOC register.
c7ca610e 11292 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 11293 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
11294
11295void
a2369ed3 11296rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 11297{
027fbf43 11298 rtx dest, insn;
1db02437 11299 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 11300
20b71b17
AM
11301 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11302 {
11303 rtx temp = (fromprolog
11304 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11305 : gen_reg_rtx (Pmode));
027fbf43
JJ
11306 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
11307 if (fromprolog)
11308 rs6000_maybe_dead (insn);
11309 insn = emit_move_insn (dest, temp);
11310 if (fromprolog)
11311 rs6000_maybe_dead (insn);
20b71b17
AM
11312 }
11313 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
11314 {
11315 char buf[30];
11316 rtx tempLR = (fromprolog
11317 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11318 : gen_reg_rtx (Pmode));
11319 rtx temp0 = (fromprolog
11320 ? gen_rtx_REG (Pmode, 0)
11321 : gen_reg_rtx (Pmode));
11322 rtx symF;
11323
11324 /* possibly create the toc section */
11325 if (! toc_initialized)
38c1f2d7 11326 {
20b71b17
AM
11327 toc_section ();
11328 function_section (current_function_decl);
38c1f2d7 11329 }
9ebbca7d 11330
20b71b17
AM
11331 if (fromprolog)
11332 {
11333 rtx symL;
38c1f2d7 11334
20b71b17
AM
11335 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
11336 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 11337
20b71b17
AM
11338 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
11339 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11340
11341 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
11342 symF)));
11343 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
11344 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
11345 symL,
11346 symF)));
9ebbca7d
GK
11347 }
11348 else
20b71b17
AM
11349 {
11350 rtx tocsym;
11351 static int reload_toc_labelno = 0;
11352
11353 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
11354
11355 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
11356 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11357
027fbf43
JJ
11358 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
11359 emit_move_insn (dest, tempLR);
11360 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 11361 }
027fbf43
JJ
11362 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
11363 if (fromprolog)
11364 rs6000_maybe_dead (insn);
9ebbca7d 11365 }
20b71b17
AM
11366 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
11367 {
11368 /* This is for AIX code running in non-PIC ELF32. */
11369 char buf[30];
11370 rtx realsym;
11371 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11372 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11373
027fbf43
JJ
11374 insn = emit_insn (gen_elf_high (dest, realsym));
11375 if (fromprolog)
11376 rs6000_maybe_dead (insn);
11377 insn = emit_insn (gen_elf_low (dest, dest, realsym));
11378 if (fromprolog)
11379 rs6000_maybe_dead (insn);
20b71b17
AM
11380 }
11381 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
11382 {
11383 if (TARGET_32BIT)
027fbf43 11384 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 11385 else
027fbf43
JJ
11386 insn = emit_insn (gen_load_toc_aix_di (dest));
11387 if (fromprolog)
11388 rs6000_maybe_dead (insn);
9ebbca7d 11389 }
20b71b17
AM
11390 else
11391 abort ();
9ebbca7d
GK
11392}
11393
d1d0c603
JJ
11394/* Emit instructions to restore the link register after determining where
11395 its value has been stored. */
11396
11397void
11398rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
11399{
11400 rs6000_stack_t *info = rs6000_stack_info ();
11401 rtx operands[2];
11402
11403 operands[0] = source;
11404 operands[1] = scratch;
11405
11406 if (info->lr_save_p)
11407 {
11408 rtx frame_rtx = stack_pointer_rtx;
11409 HOST_WIDE_INT sp_offset = 0;
11410 rtx tmp;
11411
11412 if (frame_pointer_needed
11413 || current_function_calls_alloca
11414 || info->total_size > 32767)
11415 {
11416 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
11417 frame_rtx = operands[1];
11418 }
11419 else if (info->push_p)
11420 sp_offset = info->total_size;
11421
11422 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
11423 tmp = gen_rtx_MEM (Pmode, tmp);
11424 emit_move_insn (tmp, operands[0]);
11425 }
11426 else
11427 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
11428}
11429
f103e34d
GK
11430static GTY(()) int set = -1;
11431
9ebbca7d 11432int
863d938c 11433get_TOC_alias_set (void)
9ebbca7d 11434{
f103e34d
GK
11435 if (set == -1)
11436 set = new_alias_set ();
11437 return set;
9ebbca7d
GK
11438}
11439
c1207243 11440/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
11441 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
11442 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 11443#if TARGET_ELF
3c9eb5f4 11444static int
38f391a5 11445uses_TOC (void)
9ebbca7d 11446{
c4501e62 11447 rtx insn;
38c1f2d7 11448
c4501e62
JJ
11449 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11450 if (INSN_P (insn))
11451 {
11452 rtx pat = PATTERN (insn);
11453 int i;
9ebbca7d 11454
c4501e62
JJ
11455 if (GET_CODE (pat) == PARALLEL)
11456 for (i = 0; i < XVECLEN (pat, 0); i++)
11457 {
11458 rtx sub = XVECEXP (pat, 0, i);
11459 if (GET_CODE (sub) == USE)
11460 {
11461 sub = XEXP (sub, 0);
11462 if (GET_CODE (sub) == UNSPEC
11463 && XINT (sub, 1) == UNSPEC_TOC)
11464 return 1;
11465 }
11466 }
11467 }
11468 return 0;
9ebbca7d 11469}
c954844a 11470#endif
38c1f2d7 11471
9ebbca7d 11472rtx
a2369ed3 11473create_TOC_reference (rtx symbol)
9ebbca7d 11474{
a8a05998
ZW
11475 return gen_rtx_PLUS (Pmode,
11476 gen_rtx_REG (Pmode, TOC_REGISTER),
11477 gen_rtx_CONST (Pmode,
11478 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 11479 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 11480}
38c1f2d7 11481
fc4767bb
JJ
11482/* If _Unwind_* has been called from within the same module,
11483 toc register is not guaranteed to be saved to 40(1) on function
11484 entry. Save it there in that case. */
c7ca610e 11485
9ebbca7d 11486void
863d938c 11487rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
11488{
11489 rtx mem;
11490 rtx stack_top = gen_reg_rtx (Pmode);
11491 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
11492 rtx opcode = gen_reg_rtx (SImode);
11493 rtx tocompare = gen_reg_rtx (SImode);
11494 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
11495
11496 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
11497 emit_move_insn (stack_top, mem);
11498
fc4767bb
JJ
11499 mem = gen_rtx_MEM (Pmode,
11500 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
11501 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
11502 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
11503 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
11504 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 11505 : 0xE8410028, SImode));
9ebbca7d 11506
fc4767bb 11507 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 11508 SImode, NULL_RTX, NULL_RTX,
fc4767bb 11509 no_toc_save_needed);
9ebbca7d 11510
fc4767bb
JJ
11511 mem = gen_rtx_MEM (Pmode,
11512 gen_rtx_PLUS (Pmode, stack_top,
11513 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
11514 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
11515 emit_label (no_toc_save_needed);
9ebbca7d 11516}
38c1f2d7 11517\f
ba4828e0
RK
11518/* This ties together stack memory (MEM with an alias set of
11519 rs6000_sr_alias_set) and the change to the stack pointer. */
11520
9ebbca7d 11521static void
863d938c 11522rs6000_emit_stack_tie (void)
9ebbca7d 11523{
ba4828e0
RK
11524 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
11525
11526 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11527 emit_insn (gen_stack_tie (mem));
11528}
38c1f2d7 11529
9ebbca7d
GK
11530/* Emit the correct code for allocating stack space, as insns.
11531 If COPY_R12, make sure a copy of the old frame is left in r12.
11532 The generated code may use hard register 0 as a temporary. */
11533
11534static void
a2369ed3 11535rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 11536{
9ebbca7d
GK
11537 rtx insn;
11538 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11539 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
11540 rtx todec = GEN_INT (-size);
a157febd
GK
11541
11542 if (current_function_limit_stack)
11543 {
11544 if (REG_P (stack_limit_rtx)
11545 && REGNO (stack_limit_rtx) > 1
11546 && REGNO (stack_limit_rtx) <= 31)
11547 {
5b71a4e7 11548 emit_insn (TARGET_32BIT
9ebbca7d
GK
11549 ? gen_addsi3 (tmp_reg,
11550 stack_limit_rtx,
11551 GEN_INT (size))
11552 : gen_adddi3 (tmp_reg,
11553 stack_limit_rtx,
11554 GEN_INT (size)));
5b71a4e7 11555
9ebbca7d
GK
11556 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11557 const0_rtx));
a157febd
GK
11558 }
11559 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 11560 && TARGET_32BIT
f607bc57 11561 && DEFAULT_ABI == ABI_V4)
a157febd 11562 {
9ebbca7d
GK
11563 rtx toload = gen_rtx_CONST (VOIDmode,
11564 gen_rtx_PLUS (Pmode,
11565 stack_limit_rtx,
11566 GEN_INT (size)));
5b71a4e7 11567
9ebbca7d
GK
11568 emit_insn (gen_elf_high (tmp_reg, toload));
11569 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
11570 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11571 const0_rtx));
a157febd
GK
11572 }
11573 else
11574 warning ("stack limit expression is not supported");
11575 }
11576
9ebbca7d
GK
11577 if (copy_r12 || ! TARGET_UPDATE)
11578 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
11579
38c1f2d7
MM
11580 if (TARGET_UPDATE)
11581 {
9ebbca7d 11582 if (size > 32767)
38c1f2d7 11583 {
9ebbca7d
GK
11584 /* Need a note here so that try_split doesn't get confused. */
11585 if (get_last_insn() == NULL_RTX)
2e040219 11586 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
11587 insn = emit_move_insn (tmp_reg, todec);
11588 try_split (PATTERN (insn), insn, 0);
11589 todec = tmp_reg;
38c1f2d7 11590 }
5b71a4e7
DE
11591
11592 insn = emit_insn (TARGET_32BIT
11593 ? gen_movsi_update (stack_reg, stack_reg,
11594 todec, stack_reg)
11595 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 11596 todec, stack_reg));
38c1f2d7
MM
11597 }
11598 else
11599 {
5b71a4e7
DE
11600 insn = emit_insn (TARGET_32BIT
11601 ? gen_addsi3 (stack_reg, stack_reg, todec)
11602 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
11603 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
11604 gen_rtx_REG (Pmode, 12));
11605 }
5b71a4e7 11606
9ebbca7d
GK
11607 RTX_FRAME_RELATED_P (insn) = 1;
11608 REG_NOTES (insn) =
11609 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11610 gen_rtx_SET (VOIDmode, stack_reg,
11611 gen_rtx_PLUS (Pmode, stack_reg,
11612 GEN_INT (-size))),
11613 REG_NOTES (insn));
11614}
11615
a4f6c312
SS
11616/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
11617 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
11618 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
11619 deduce these equivalences by itself so it wasn't necessary to hold
11620 its hand so much. */
9ebbca7d
GK
11621
11622static void
a2369ed3
DJ
11623rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
11624 rtx reg2, rtx rreg)
9ebbca7d
GK
11625{
11626 rtx real, temp;
11627
e56c4463
JL
11628 /* copy_rtx will not make unique copies of registers, so we need to
11629 ensure we don't have unwanted sharing here. */
11630 if (reg == reg2)
11631 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11632
11633 if (reg == rreg)
11634 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11635
9ebbca7d
GK
11636 real = copy_rtx (PATTERN (insn));
11637
89e7058f
AH
11638 if (reg2 != NULL_RTX)
11639 real = replace_rtx (real, reg2, rreg);
11640
9ebbca7d
GK
11641 real = replace_rtx (real, reg,
11642 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
11643 STACK_POINTER_REGNUM),
11644 GEN_INT (val)));
11645
11646 /* We expect that 'real' is either a SET or a PARALLEL containing
11647 SETs (and possibly other stuff). In a PARALLEL, all the SETs
11648 are important so they all have to be marked RTX_FRAME_RELATED_P. */
11649
11650 if (GET_CODE (real) == SET)
11651 {
11652 rtx set = real;
11653
11654 temp = simplify_rtx (SET_SRC (set));
11655 if (temp)
11656 SET_SRC (set) = temp;
11657 temp = simplify_rtx (SET_DEST (set));
11658 if (temp)
11659 SET_DEST (set) = temp;
11660 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 11661 {
9ebbca7d
GK
11662 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11663 if (temp)
11664 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 11665 }
38c1f2d7 11666 }
9ebbca7d
GK
11667 else if (GET_CODE (real) == PARALLEL)
11668 {
11669 int i;
11670 for (i = 0; i < XVECLEN (real, 0); i++)
11671 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11672 {
11673 rtx set = XVECEXP (real, 0, i);
11674
11675 temp = simplify_rtx (SET_SRC (set));
11676 if (temp)
11677 SET_SRC (set) = temp;
11678 temp = simplify_rtx (SET_DEST (set));
11679 if (temp)
11680 SET_DEST (set) = temp;
11681 if (GET_CODE (SET_DEST (set)) == MEM)
11682 {
11683 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11684 if (temp)
11685 XEXP (SET_DEST (set), 0) = temp;
11686 }
11687 RTX_FRAME_RELATED_P (set) = 1;
11688 }
11689 }
11690 else
a4f6c312 11691 abort ();
c19de7aa
AH
11692
11693 if (TARGET_SPE)
11694 real = spe_synthesize_frame_save (real);
11695
9ebbca7d
GK
11696 RTX_FRAME_RELATED_P (insn) = 1;
11697 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11698 real,
11699 REG_NOTES (insn));
38c1f2d7
MM
11700}
11701
c19de7aa
AH
11702/* Given an SPE frame note, return a PARALLEL of SETs with the
11703 original note, plus a synthetic register save. */
11704
11705static rtx
a2369ed3 11706spe_synthesize_frame_save (rtx real)
c19de7aa
AH
11707{
11708 rtx synth, offset, reg, real2;
11709
11710 if (GET_CODE (real) != SET
11711 || GET_MODE (SET_SRC (real)) != V2SImode)
11712 return real;
11713
11714 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11715 frame related note. The parallel contains a set of the register
41f3a930 11716 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11717 This is so we can differentiate between 64-bit and 32-bit saves.
11718 Words cannot describe this nastiness. */
11719
11720 if (GET_CODE (SET_DEST (real)) != MEM
11721 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11722 || GET_CODE (SET_SRC (real)) != REG)
11723 abort ();
11724
11725 /* Transform:
11726 (set (mem (plus (reg x) (const y)))
11727 (reg z))
11728 into:
11729 (set (mem (plus (reg x) (const y+4)))
41f3a930 11730 (reg z+1200))
c19de7aa
AH
11731 */
11732
11733 real2 = copy_rtx (real);
11734 PUT_MODE (SET_DEST (real2), SImode);
11735 reg = SET_SRC (real2);
11736 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
11737 synth = copy_rtx (real2);
11738
11739 if (BYTES_BIG_ENDIAN)
11740 {
11741 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
11742 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
11743 }
11744
11745 reg = SET_SRC (synth);
41f3a930 11746
c19de7aa 11747 synth = replace_rtx (synth, reg,
41f3a930 11748 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
11749
11750 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
11751 synth = replace_rtx (synth, offset,
11752 GEN_INT (INTVAL (offset)
11753 + (BYTES_BIG_ENDIAN ? 0 : 4)));
11754
11755 RTX_FRAME_RELATED_P (synth) = 1;
11756 RTX_FRAME_RELATED_P (real2) = 1;
11757 if (BYTES_BIG_ENDIAN)
11758 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
11759 else
11760 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
11761
11762 return real;
11763}
11764
00b960c7
AH
11765/* Returns an insn that has a vrsave set operation with the
11766 appropriate CLOBBERs. */
11767
11768static rtx
a2369ed3 11769generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
11770{
11771 int nclobs, i;
11772 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 11773 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 11774
a004eb82
AH
11775 clobs[0]
11776 = gen_rtx_SET (VOIDmode,
11777 vrsave,
11778 gen_rtx_UNSPEC_VOLATILE (SImode,
11779 gen_rtvec (2, reg, vrsave),
11780 30));
00b960c7
AH
11781
11782 nclobs = 1;
11783
9aa86737
AH
11784 /* We need to clobber the registers in the mask so the scheduler
11785 does not move sets to VRSAVE before sets of AltiVec registers.
11786
11787 However, if the function receives nonlocal gotos, reload will set
11788 all call saved registers live. We will end up with:
11789
11790 (set (reg 999) (mem))
11791 (parallel [ (set (reg vrsave) (unspec blah))
11792 (clobber (reg 999))])
11793
11794 The clobber will cause the store into reg 999 to be dead, and
11795 flow will attempt to delete an epilogue insn. In this case, we
11796 need an unspec use/set of the register. */
00b960c7
AH
11797
11798 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11799 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
11800 {
11801 if (!epiloguep || call_used_regs [i])
11802 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
11803 gen_rtx_REG (V4SImode, i));
11804 else
11805 {
11806 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
11807
11808 clobs[nclobs++]
a004eb82
AH
11809 = gen_rtx_SET (VOIDmode,
11810 reg,
11811 gen_rtx_UNSPEC (V4SImode,
11812 gen_rtvec (1, reg), 27));
9aa86737
AH
11813 }
11814 }
00b960c7
AH
11815
11816 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
11817
11818 for (i = 0; i < nclobs; ++i)
11819 XVECEXP (insn, 0, i) = clobs[i];
11820
11821 return insn;
11822}
11823
89e7058f
AH
11824/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
11825 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
11826
11827static void
a2369ed3 11828emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 11829 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
11830{
11831 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
11832 rtx replacea, replaceb;
11833
11834 int_rtx = GEN_INT (offset);
11835
11836 /* Some cases that need register indexed addressing. */
11837 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
11838 || (TARGET_SPE_ABI
11839 && SPE_VECTOR_MODE (mode)
11840 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
11841 {
11842 /* Whomever calls us must make sure r11 is available in the
11843 flow path of instructions in the prologue. */
11844 offset_rtx = gen_rtx_REG (Pmode, 11);
11845 emit_move_insn (offset_rtx, int_rtx);
11846
11847 replacea = offset_rtx;
11848 replaceb = int_rtx;
11849 }
11850 else
11851 {
11852 offset_rtx = int_rtx;
11853 replacea = NULL_RTX;
11854 replaceb = NULL_RTX;
11855 }
11856
11857 reg = gen_rtx_REG (mode, regno);
11858 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
11859 mem = gen_rtx_MEM (mode, addr);
11860 set_mem_alias_set (mem, rs6000_sr_alias_set);
11861
11862 insn = emit_move_insn (mem, reg);
11863
11864 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
11865}
11866
a3170dc6
AH
11867/* Emit an offset memory reference suitable for a frame store, while
11868 converting to a valid addressing mode. */
11869
11870static rtx
a2369ed3 11871gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
11872{
11873 rtx int_rtx, offset_rtx;
11874
11875 int_rtx = GEN_INT (offset);
11876
11877 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
11878 {
11879 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11880 emit_move_insn (offset_rtx, int_rtx);
11881 }
11882 else
11883 offset_rtx = int_rtx;
11884
11885 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
11886}
11887
9ebbca7d
GK
11888/* Emit function prologue as insns. */
11889
9878760c 11890void
863d938c 11891rs6000_emit_prologue (void)
9878760c 11892{
4697a36c 11893 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a 11894 enum machine_mode reg_mode = Pmode;
327e5343 11895 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
11896 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11897 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
11898 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 11899 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
11900 rtx insn;
11901 int saving_FPRs_inline;
11902 int using_store_multiple;
11903 HOST_WIDE_INT sp_offset = 0;
11904
c19de7aa 11905 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11906 {
11907 reg_mode = V2SImode;
11908 reg_size = 8;
11909 }
11910
9ebbca7d 11911 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11912 && (!TARGET_SPE_ABI
11913 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11914 && info->first_gp_reg_save < 31);
11915 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 11916 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 11917 || current_function_calls_eh_return
8c29550d 11918 || cfun->machine->ra_need_lr);
9ebbca7d
GK
11919
11920 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 11921 if (info->push_p
acd0b319
AM
11922 && (DEFAULT_ABI == ABI_V4
11923 || current_function_calls_eh_return))
9ebbca7d
GK
11924 {
11925 if (info->total_size < 32767)
11926 sp_offset = info->total_size;
11927 else
11928 frame_reg_rtx = frame_ptr_rtx;
11929 rs6000_emit_allocate_stack (info->total_size,
11930 (frame_reg_rtx != sp_reg_rtx
11931 && (info->cr_save_p
11932 || info->lr_save_p
11933 || info->first_fp_reg_save < 64
11934 || info->first_gp_reg_save < 32
11935 )));
11936 if (frame_reg_rtx != sp_reg_rtx)
11937 rs6000_emit_stack_tie ();
11938 }
11939
9aa86737
AH
11940 /* Save AltiVec registers if needed. */
11941 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11942 {
11943 int i;
11944
11945 /* There should be a non inline version of this, for when we
11946 are saving lots of vector registers. */
11947 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11948 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11949 {
11950 rtx areg, savereg, mem;
11951 int offset;
11952
11953 offset = info->altivec_save_offset + sp_offset
11954 + 16 * (i - info->first_altivec_reg_save);
11955
11956 savereg = gen_rtx_REG (V4SImode, i);
11957
11958 areg = gen_rtx_REG (Pmode, 0);
11959 emit_move_insn (areg, GEN_INT (offset));
11960
11961 /* AltiVec addressing mode is [reg+reg]. */
11962 mem = gen_rtx_MEM (V4SImode,
11963 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
11964
11965 set_mem_alias_set (mem, rs6000_sr_alias_set);
11966
11967 insn = emit_move_insn (mem, savereg);
11968
5c242421
SB
11969 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11970 areg, GEN_INT (offset));
9aa86737
AH
11971 }
11972 }
11973
11974 /* VRSAVE is a bit vector representing which AltiVec registers
11975 are used. The OS uses this to determine which vector
11976 registers to save on a context switch. We need to save
11977 VRSAVE on the stack frame, add whatever AltiVec registers we
11978 used in this function, and do the corresponding magic in the
11979 epilogue. */
11980
4d774ff8
HP
11981 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
11982 && info->vrsave_mask != 0)
9aa86737 11983 {
a004eb82 11984 rtx reg, mem, vrsave;
9aa86737
AH
11985 int offset;
11986
11987 /* Get VRSAVE onto a GPR. */
11988 reg = gen_rtx_REG (SImode, 12);
a004eb82 11989 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
11990 if (TARGET_MACHO)
11991 emit_insn (gen_get_vrsave_internal (reg));
11992 else
11993 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
11994
11995 /* Save VRSAVE. */
11996 offset = info->vrsave_save_offset + sp_offset;
11997 mem
11998 = gen_rtx_MEM (SImode,
11999 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
12000 set_mem_alias_set (mem, rs6000_sr_alias_set);
12001 insn = emit_move_insn (mem, reg);
12002
12003 /* Include the registers in the mask. */
12004 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
12005
12006 insn = emit_insn (generate_set_vrsave (reg, info, 0));
12007 }
12008
9ebbca7d
GK
12009 /* If we use the link register, get it into r0. */
12010 if (info->lr_save_p)
71f123ca 12011 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
12012 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12013
12014 /* If we need to save CR, put it into r12. */
12015 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
12016 {
12017 cr_save_rtx = gen_rtx_REG (SImode, 12);
12018 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12019 }
12020
a4f6c312
SS
12021 /* Do any required saving of fpr's. If only one or two to save, do
12022 it ourselves. Otherwise, call function. */
9ebbca7d
GK
12023 if (saving_FPRs_inline)
12024 {
12025 int i;
12026 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12027 if ((regs_ever_live[info->first_fp_reg_save+i]
12028 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
12029 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
12030 info->first_fp_reg_save + i,
12031 info->fp_save_offset + sp_offset + 8 * i,
12032 info->total_size);
9ebbca7d
GK
12033 }
12034 else if (info->first_fp_reg_save != 64)
12035 {
12036 int i;
12037 char rname[30];
520a57c8 12038 const char *alloc_rname;
9ebbca7d
GK
12039 rtvec p;
12040 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
12041
12042 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
12043 gen_rtx_REG (Pmode,
12044 LINK_REGISTER_REGNUM));
12045 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
12046 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 12047 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12048 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
12049 gen_rtx_SYMBOL_REF (Pmode,
12050 alloc_rname));
12051 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12052 {
12053 rtx addr, reg, mem;
12054 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
12055 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12056 GEN_INT (info->fp_save_offset
12057 + sp_offset + 8*i));
12058 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12059 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12060
12061 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
12062 }
12063 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12064 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12065 NULL_RTX, NULL_RTX);
12066 }
b6c9286a 12067
9ebbca7d
GK
12068 /* Save GPRs. This is done as a PARALLEL if we are using
12069 the store-multiple instructions. */
12070 if (using_store_multiple)
b6c9286a 12071 {
308c142a 12072 rtvec p;
9ebbca7d
GK
12073 int i;
12074 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
12075 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12076 {
12077 rtx addr, reg, mem;
12078 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12079 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12080 GEN_INT (info->gp_save_offset
12081 + sp_offset
12082 + reg_size * i));
12083 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12084 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12085
12086 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
12087 }
12088 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
12089 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12090 NULL_RTX, NULL_RTX);
b6c9286a
MM
12091 }
12092 else
12093 {
9ebbca7d
GK
12094 int i;
12095 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12096 if ((regs_ever_live[info->first_gp_reg_save+i]
12097 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12098 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12099 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12100 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
12101 {
12102 rtx addr, reg, mem;
12103 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
12104
c19de7aa 12105 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12106 {
12107 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12108 rtx b;
12109
12110 if (!SPE_CONST_OFFSET_OK (offset))
12111 {
12112 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12113 emit_move_insn (b, GEN_INT (offset));
12114 }
12115 else
12116 b = GEN_INT (offset);
12117
12118 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12119 mem = gen_rtx_MEM (V2SImode, addr);
12120 set_mem_alias_set (mem, rs6000_sr_alias_set);
12121 insn = emit_move_insn (mem, reg);
12122
12123 if (GET_CODE (b) == CONST_INT)
12124 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12125 NULL_RTX, NULL_RTX);
12126 else
12127 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12128 b, GEN_INT (offset));
12129 }
12130 else
12131 {
12132 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12133 GEN_INT (info->gp_save_offset
12134 + sp_offset
12135 + reg_size * i));
12136 mem = gen_rtx_MEM (reg_mode, addr);
12137 set_mem_alias_set (mem, rs6000_sr_alias_set);
12138
12139 insn = emit_move_insn (mem, reg);
12140 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12141 NULL_RTX, NULL_RTX);
12142 }
12143 }
9ebbca7d
GK
12144 }
12145
83720594
RH
12146 /* ??? There's no need to emit actual instructions here, but it's the
12147 easiest way to get the frame unwind information emitted. */
12148 if (current_function_calls_eh_return)
12149 {
78e1b90d
DE
12150 unsigned int i, regno;
12151
fc4767bb
JJ
12152 /* In AIX ABI we need to pretend we save r2 here. */
12153 if (TARGET_AIX)
12154 {
12155 rtx addr, reg, mem;
12156
12157 reg = gen_rtx_REG (reg_mode, 2);
12158 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12159 GEN_INT (sp_offset + 5 * reg_size));
12160 mem = gen_rtx_MEM (reg_mode, addr);
12161 set_mem_alias_set (mem, rs6000_sr_alias_set);
12162
12163 insn = emit_move_insn (mem, reg);
12164 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12165 NULL_RTX, NULL_RTX);
12166 PATTERN (insn) = gen_blockage ();
12167 }
12168
83720594
RH
12169 for (i = 0; ; ++i)
12170 {
83720594
RH
12171 regno = EH_RETURN_DATA_REGNO (i);
12172 if (regno == INVALID_REGNUM)
12173 break;
12174
89e7058f
AH
12175 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
12176 info->ehrd_offset + sp_offset
12177 + reg_size * (int) i,
12178 info->total_size);
83720594
RH
12179 }
12180 }
12181
9ebbca7d
GK
12182 /* Save lr if we used it. */
12183 if (info->lr_save_p)
12184 {
12185 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12186 GEN_INT (info->lr_save_offset + sp_offset));
12187 rtx reg = gen_rtx_REG (Pmode, 0);
12188 rtx mem = gen_rtx_MEM (Pmode, addr);
12189 /* This should not be of rs6000_sr_alias_set, because of
12190 __builtin_return_address. */
12191
12192 insn = emit_move_insn (mem, reg);
12193 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
12194 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
12195 }
12196
12197 /* Save CR if we use any that must be preserved. */
12198 if (info->cr_save_p)
12199 {
12200 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12201 GEN_INT (info->cr_save_offset + sp_offset));
12202 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12203
12204 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12205
12206 /* If r12 was used to hold the original sp, copy cr into r0 now
12207 that it's free. */
12208 if (REGNO (frame_reg_rtx) == 12)
12209 {
12210 cr_save_rtx = gen_rtx_REG (SImode, 0);
12211 emit_insn (gen_movesi_from_cr (cr_save_rtx));
12212 }
12213 insn = emit_move_insn (mem, cr_save_rtx);
12214
12215 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
12216 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
12217 But that's OK. All we have to do is specify that _one_ condition
12218 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
12219 will then restore all the call-saved registers.
12220 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 12221 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 12222 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
12223 }
12224
12225 /* Update stack and set back pointer unless this is V.4,
12226 for which it was done previously. */
fc4767bb
JJ
12227 if (info->push_p
12228 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
12229 rs6000_emit_allocate_stack (info->total_size, FALSE);
12230
12231 /* Set frame pointer, if needed. */
12232 if (frame_pointer_needed)
12233 {
a3170dc6 12234 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
12235 sp_reg_rtx);
12236 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 12237 }
9878760c 12238
1db02437 12239 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 12240 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 12241 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 12242 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
12243 {
12244 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 12245 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
12246 can use register 0. This allows us to use a plain 'blr' to return
12247 from the procedure more often. */
f1384257
AM
12248 int save_LR_around_toc_setup = (TARGET_ELF
12249 && DEFAULT_ABI != ABI_AIX
12250 && flag_pic
d5fa86ba
GK
12251 && ! info->lr_save_p
12252 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 12253 if (save_LR_around_toc_setup)
c4501e62
JJ
12254 {
12255 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
12256 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
12257 rs6000_emit_load_toc_table (TRUE);
12258 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
12259 }
12260 else
12261 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 12262 }
ee890fe2 12263
fcce224d 12264#if TARGET_MACHO
ee890fe2
SS
12265 if (DEFAULT_ABI == ABI_DARWIN
12266 && flag_pic && current_function_uses_pic_offset_table)
12267 {
12268 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 12269 const char *picbase = machopic_function_base_name ();
6788f5ca 12270 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 12271
f51eee6a 12272 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
12273
12274 rs6000_maybe_dead (
1db02437 12275 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
12276 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
12277 }
fcce224d 12278#endif
9ebbca7d
GK
12279}
12280
9ebbca7d 12281/* Write function prologue. */
a4f6c312 12282
08c148a8 12283static void
a2369ed3
DJ
12284rs6000_output_function_prologue (FILE *file,
12285 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
12286{
12287 rs6000_stack_t *info = rs6000_stack_info ();
12288
4697a36c
MM
12289 if (TARGET_DEBUG_STACK)
12290 debug_stack_info (info);
9878760c 12291
a4f6c312
SS
12292 /* Write .extern for any function we will call to save and restore
12293 fp values. */
12294 if (info->first_fp_reg_save < 64
12295 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 12296 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 12297 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
12298 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
12299 RESTORE_FP_SUFFIX);
9878760c 12300
c764f757
RK
12301 /* Write .extern for AIX common mode routines, if needed. */
12302 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
12303 {
f6709c70
JW
12304 fputs ("\t.extern __mulh\n", file);
12305 fputs ("\t.extern __mull\n", file);
12306 fputs ("\t.extern __divss\n", file);
12307 fputs ("\t.extern __divus\n", file);
12308 fputs ("\t.extern __quoss\n", file);
12309 fputs ("\t.extern __quous\n", file);
c764f757
RK
12310 common_mode_defined = 1;
12311 }
9878760c 12312
9ebbca7d 12313 if (! HAVE_prologue)
979721f8 12314 {
9ebbca7d 12315 start_sequence ();
9dda4cc8 12316
a4f6c312
SS
12317 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
12318 the "toplevel" insn chain. */
2e040219 12319 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12320 rs6000_emit_prologue ();
2e040219 12321 emit_note (NOTE_INSN_DELETED);
178c3eff 12322
a3c9585f 12323 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12324 {
12325 rtx insn;
12326 unsigned addr = 0;
12327 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12328 {
12329 INSN_ADDRESSES_NEW (insn, addr);
12330 addr += 4;
12331 }
12332 }
9dda4cc8 12333
9ebbca7d 12334 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12335 debug_rtx_list (get_insns (), 100);
12336 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12337 end_sequence ();
979721f8
MM
12338 }
12339
9ebbca7d
GK
12340 rs6000_pic_labelno++;
12341}
12342
12343/* Emit function epilogue as insns.
9878760c 12344
9ebbca7d
GK
12345 At present, dwarf2out_frame_debug_expr doesn't understand
12346 register restores, so we don't bother setting RTX_FRAME_RELATED_P
12347 anywhere in the epilogue. Most of the insns below would in any case
12348 need special notes to explain where r11 is in relation to the stack. */
9878760c 12349
9ebbca7d 12350void
a2369ed3 12351rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
12352{
12353 rs6000_stack_t *info;
12354 int restoring_FPRs_inline;
12355 int using_load_multiple;
12356 int using_mfcr_multiple;
12357 int use_backchain_to_restore_sp;
12358 int sp_offset = 0;
12359 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
12360 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a 12361 enum machine_mode reg_mode = Pmode;
327e5343 12362 int reg_size = TARGET_32BIT ? 4 : 8;
9ebbca7d
GK
12363 int i;
12364
c19de7aa
AH
12365 info = rs6000_stack_info ();
12366
12367 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12368 {
12369 reg_mode = V2SImode;
12370 reg_size = 8;
12371 }
12372
9ebbca7d 12373 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12374 && (!TARGET_SPE_ABI
12375 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12376 && info->first_gp_reg_save < 31);
12377 restoring_FPRs_inline = (sibcall
83720594 12378 || current_function_calls_eh_return
9ebbca7d
GK
12379 || info->first_fp_reg_save == 64
12380 || FP_SAVE_INLINE (info->first_fp_reg_save));
12381 use_backchain_to_restore_sp = (frame_pointer_needed
12382 || current_function_calls_alloca
12383 || info->total_size > 32767);
12384 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
12385 || rs6000_cpu == PROCESSOR_PPC603
12386 || rs6000_cpu == PROCESSOR_PPC750
12387 || optimize_size);
12388
12389 /* If we have a frame pointer, a call to alloca, or a large stack
12390 frame, restore the old stack pointer using the backchain. Otherwise,
12391 we know what size to update it with. */
12392 if (use_backchain_to_restore_sp)
bacbde18 12393 {
9ebbca7d
GK
12394 /* Under V.4, don't reset the stack pointer until after we're done
12395 loading the saved registers. */
f607bc57 12396 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 12397 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 12398
9ebbca7d
GK
12399 emit_move_insn (frame_reg_rtx,
12400 gen_rtx_MEM (Pmode, sp_reg_rtx));
12401
bacbde18 12402 }
9ebbca7d 12403 else if (info->push_p)
85638c0d 12404 {
fc4767bb
JJ
12405 if (DEFAULT_ABI == ABI_V4
12406 || current_function_calls_eh_return)
9ebbca7d
GK
12407 sp_offset = info->total_size;
12408 else
12409 {
12410 emit_insn (TARGET_32BIT
12411 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12412 GEN_INT (info->total_size))
12413 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12414 GEN_INT (info->total_size)));
12415 }
85638c0d 12416 }
9ebbca7d 12417
9aa86737
AH
12418 /* Restore AltiVec registers if needed. */
12419 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12420 {
12421 int i;
12422
12423 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12424 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12425 {
12426 rtx addr, areg, mem;
12427
12428 areg = gen_rtx_REG (Pmode, 0);
12429 emit_move_insn
12430 (areg, GEN_INT (info->altivec_save_offset
12431 + sp_offset
12432 + 16 * (i - info->first_altivec_reg_save)));
12433
12434 /* AltiVec addressing mode is [reg+reg]. */
12435 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
12436 mem = gen_rtx_MEM (V4SImode, addr);
12437 set_mem_alias_set (mem, rs6000_sr_alias_set);
12438
12439 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
12440 }
12441 }
12442
12443 /* Restore VRSAVE if needed. */
4d774ff8
HP
12444 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE
12445 && info->vrsave_mask != 0)
9aa86737
AH
12446 {
12447 rtx addr, mem, reg;
12448
12449 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12450 GEN_INT (info->vrsave_save_offset + sp_offset));
12451 mem = gen_rtx_MEM (SImode, addr);
12452 set_mem_alias_set (mem, rs6000_sr_alias_set);
12453 reg = gen_rtx_REG (SImode, 12);
12454 emit_move_insn (reg, mem);
12455
12456 emit_insn (generate_set_vrsave (reg, info, 1));
12457 }
12458
9ebbca7d
GK
12459 /* Get the old lr if we saved it. */
12460 if (info->lr_save_p)
b6c9286a 12461 {
a3170dc6
AH
12462 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
12463 info->lr_save_offset + sp_offset);
ba4828e0
RK
12464
12465 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12466
9ebbca7d 12467 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 12468 }
9ebbca7d
GK
12469
12470 /* Get the old cr if we saved it. */
12471 if (info->cr_save_p)
12472 {
12473 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12474 GEN_INT (info->cr_save_offset + sp_offset));
12475 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12476
12477 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12478
9ebbca7d
GK
12479 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
12480 }
12481
12482 /* Set LR here to try to overlap restores below. */
4697a36c 12483 if (info->lr_save_p)
9ebbca7d
GK
12484 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
12485 gen_rtx_REG (Pmode, 0));
12486
83720594
RH
12487 /* Load exception handler data registers, if needed. */
12488 if (current_function_calls_eh_return)
12489 {
78e1b90d
DE
12490 unsigned int i, regno;
12491
fc4767bb
JJ
12492 if (TARGET_AIX)
12493 {
12494 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12495 GEN_INT (sp_offset + 5 * reg_size));
12496 rtx mem = gen_rtx_MEM (reg_mode, addr);
12497
12498 set_mem_alias_set (mem, rs6000_sr_alias_set);
12499
12500 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
12501 }
12502
83720594
RH
12503 for (i = 0; ; ++i)
12504 {
a3170dc6 12505 rtx mem;
83720594
RH
12506
12507 regno = EH_RETURN_DATA_REGNO (i);
12508 if (regno == INVALID_REGNUM)
12509 break;
12510
a3170dc6
AH
12511 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
12512 info->ehrd_offset + sp_offset
12513 + reg_size * (int) i);
ba4828e0 12514 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
12515
12516 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
12517 }
12518 }
9ebbca7d
GK
12519
12520 /* Restore GPRs. This is done as a PARALLEL if we are using
12521 the load-multiple instructions. */
12522 if (using_load_multiple)
979721f8 12523 {
9ebbca7d
GK
12524 rtvec p;
12525 p = rtvec_alloc (32 - info->first_gp_reg_save);
12526 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 12527 {
9ebbca7d
GK
12528 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12529 GEN_INT (info->gp_save_offset
12530 + sp_offset
12531 + reg_size * i));
12532 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
12533
12534 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12535
12536 RTVEC_ELT (p, i) =
12537 gen_rtx_SET (VOIDmode,
12538 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
12539 mem);
979721f8 12540 }
9ebbca7d 12541 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 12542 }
9ebbca7d
GK
12543 else
12544 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12545 if ((regs_ever_live[info->first_gp_reg_save+i]
12546 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12547 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12548 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12549 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
12550 {
12551 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12552 GEN_INT (info->gp_save_offset
12553 + sp_offset
12554 + reg_size * i));
12555 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12556
a3170dc6 12557 /* Restore 64-bit quantities for SPE. */
c19de7aa 12558 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12559 {
12560 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12561 rtx b;
12562
12563 if (!SPE_CONST_OFFSET_OK (offset))
12564 {
12565 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12566 emit_move_insn (b, GEN_INT (offset));
12567 }
12568 else
12569 b = GEN_INT (offset);
12570
12571 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12572 mem = gen_rtx_MEM (V2SImode, addr);
12573 }
12574
ba4828e0 12575 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12576
12577 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 12578 info->first_gp_reg_save + i), mem);
9ebbca7d 12579 }
9878760c 12580
9ebbca7d
GK
12581 /* Restore fpr's if we need to do it without calling a function. */
12582 if (restoring_FPRs_inline)
12583 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12584 if ((regs_ever_live[info->first_fp_reg_save+i]
12585 && ! call_used_regs[info->first_fp_reg_save+i]))
12586 {
12587 rtx addr, mem;
12588 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12589 GEN_INT (info->fp_save_offset
12590 + sp_offset
a4f6c312 12591 + 8 * i));
9ebbca7d 12592 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12593 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12594
12595 emit_move_insn (gen_rtx_REG (DFmode,
12596 info->first_fp_reg_save + i),
12597 mem);
12598 }
8d30c4ee 12599
9ebbca7d
GK
12600 /* If we saved cr, restore it here. Just those that were used. */
12601 if (info->cr_save_p)
979721f8 12602 {
9ebbca7d 12603 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 12604 int count = 0;
9ebbca7d
GK
12605
12606 if (using_mfcr_multiple)
979721f8 12607 {
9ebbca7d
GK
12608 for (i = 0; i < 8; i++)
12609 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 12610 count++;
9ebbca7d 12611 if (count == 0)
e35b9579
GK
12612 abort ();
12613 }
12614
12615 if (using_mfcr_multiple && count > 1)
12616 {
12617 rtvec p;
12618 int ndx;
9ebbca7d 12619
e35b9579 12620 p = rtvec_alloc (count);
9ebbca7d 12621
e35b9579 12622 ndx = 0;
9ebbca7d
GK
12623 for (i = 0; i < 8; i++)
12624 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
12625 {
12626 rtvec r = rtvec_alloc (2);
12627 RTVEC_ELT (r, 0) = r12_rtx;
12628 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 12629 RTVEC_ELT (p, ndx) =
9ebbca7d 12630 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 12631 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 12632 ndx++;
9ebbca7d
GK
12633 }
12634 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
12635 if (ndx != count)
12636 abort ();
979721f8
MM
12637 }
12638 else
9ebbca7d
GK
12639 for (i = 0; i < 8; i++)
12640 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 12641 {
9ebbca7d
GK
12642 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
12643 CR0_REGNO+i),
12644 r12_rtx));
979721f8 12645 }
979721f8
MM
12646 }
12647
9ebbca7d
GK
12648 /* If this is V.4, unwind the stack pointer after all of the loads
12649 have been done. We need to emit a block here so that sched
12650 doesn't decide to move the sp change before the register restores
12651 (which may not have any obvious dependency on the stack). This
12652 doesn't hurt performance, because there is no scheduling that can
12653 be done after this point. */
fc4767bb
JJ
12654 if (DEFAULT_ABI == ABI_V4
12655 || current_function_calls_eh_return)
b6c9286a 12656 {
9ebbca7d
GK
12657 if (frame_reg_rtx != sp_reg_rtx)
12658 rs6000_emit_stack_tie ();
b6c9286a 12659
9ebbca7d 12660 if (use_backchain_to_restore_sp)
b6c9286a 12661 {
9ebbca7d 12662 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12663 }
9ebbca7d 12664 else if (sp_offset != 0)
13f1623b 12665 {
5b71a4e7 12666 emit_insn (TARGET_32BIT
9ebbca7d
GK
12667 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12668 GEN_INT (sp_offset))
12669 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12670 GEN_INT (sp_offset)));
13f1623b 12671 }
9ebbca7d 12672 }
b6c9286a 12673
83720594
RH
12674 if (current_function_calls_eh_return)
12675 {
12676 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12677 emit_insn (TARGET_32BIT
83720594
RH
12678 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12679 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12680 }
12681
9ebbca7d
GK
12682 if (!sibcall)
12683 {
12684 rtvec p;
12685 if (! restoring_FPRs_inline)
12686 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12687 else
12688 p = rtvec_alloc (2);
b6c9286a 12689
e35b9579
GK
12690 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12691 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12692 gen_rtx_REG (Pmode,
12693 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12694
12695 /* If we have to restore more than two FP registers, branch to the
12696 restore function. It will return to our caller. */
12697 if (! restoring_FPRs_inline)
12698 {
12699 int i;
12700 char rname[30];
520a57c8 12701 const char *alloc_rname;
979721f8 12702
9ebbca7d
GK
12703 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12704 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12705 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12706 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12707 gen_rtx_SYMBOL_REF (Pmode,
12708 alloc_rname));
b6c9286a 12709
9ebbca7d
GK
12710 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12711 {
12712 rtx addr, mem;
12713 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12714 GEN_INT (info->fp_save_offset + 8*i));
12715 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12716 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12717
12718 RTVEC_ELT (p, i+3) =
12719 gen_rtx_SET (VOIDmode,
12720 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12721 mem);
b6c9286a
MM
12722 }
12723 }
9ebbca7d
GK
12724
12725 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 12726 }
9878760c
RK
12727}
12728
12729/* Write function epilogue. */
12730
08c148a8 12731static void
a2369ed3
DJ
12732rs6000_output_function_epilogue (FILE *file,
12733 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 12734{
4697a36c 12735 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 12736
9ebbca7d 12737 if (! HAVE_epilogue)
9878760c 12738 {
9ebbca7d
GK
12739 rtx insn = get_last_insn ();
12740 /* If the last insn was a BARRIER, we don't have to write anything except
12741 the trace table. */
12742 if (GET_CODE (insn) == NOTE)
12743 insn = prev_nonnote_insn (insn);
12744 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 12745 {
9ebbca7d
GK
12746 /* This is slightly ugly, but at least we don't have two
12747 copies of the epilogue-emitting code. */
12748 start_sequence ();
12749
12750 /* A NOTE_INSN_DELETED is supposed to be at the start
12751 and end of the "toplevel" insn chain. */
2e040219 12752 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12753 rs6000_emit_epilogue (FALSE);
2e040219 12754 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12755
a3c9585f 12756 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12757 {
12758 rtx insn;
12759 unsigned addr = 0;
12760 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12761 {
12762 INSN_ADDRESSES_NEW (insn, addr);
12763 addr += 4;
12764 }
12765 }
12766
9ebbca7d 12767 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12768 debug_rtx_list (get_insns (), 100);
12769 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12770 end_sequence ();
4697a36c 12771 }
9878760c 12772 }
b4ac57ab 12773
efdba735
SH
12774#if TARGET_MACHO
12775 macho_branch_islands ();
0e5da0be
GK
12776 /* Mach-O doesn't support labels at the end of objects, so if
12777 it looks like we might want one, insert a NOP. */
12778 {
12779 rtx insn = get_last_insn ();
12780 while (insn
12781 && NOTE_P (insn)
12782 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
12783 insn = PREV_INSN (insn);
12784 if (insn
12785 && (LABEL_P (insn)
12786 || (NOTE_P (insn)
12787 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
12788 fputs ("\tnop\n", file);
12789 }
12790#endif
12791
9b30bae2 12792 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
12793 on its format.
12794
12795 We don't output a traceback table if -finhibit-size-directive was
12796 used. The documentation for -finhibit-size-directive reads
12797 ``don't output a @code{.size} assembler directive, or anything
12798 else that would cause trouble if the function is split in the
12799 middle, and the two halves are placed at locations far apart in
12800 memory.'' The traceback table has this property, since it
12801 includes the offset from the start of the function to the
4d30c363
MM
12802 traceback table itself.
12803
12804 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 12805 different traceback table. */
57ac7be9
AM
12806 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
12807 && rs6000_traceback != traceback_none)
9b30bae2 12808 {
69c75916 12809 const char *fname = NULL;
3ac88239 12810 const char *language_string = lang_hooks.name;
6041bf2f 12811 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 12812 int i;
57ac7be9
AM
12813 int optional_tbtab;
12814
12815 if (rs6000_traceback == traceback_full)
12816 optional_tbtab = 1;
12817 else if (rs6000_traceback == traceback_part)
12818 optional_tbtab = 0;
12819 else
12820 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 12821
69c75916
AM
12822 if (optional_tbtab)
12823 {
12824 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
12825 while (*fname == '.') /* V.4 encodes . in the name */
12826 fname++;
12827
12828 /* Need label immediately before tbtab, so we can compute
12829 its offset from the function start. */
12830 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
12831 ASM_OUTPUT_LABEL (file, fname);
12832 }
314fc5a9
ILT
12833
12834 /* The .tbtab pseudo-op can only be used for the first eight
12835 expressions, since it can't handle the possibly variable
12836 length fields that follow. However, if you omit the optional
12837 fields, the assembler outputs zeros for all optional fields
12838 anyways, giving each variable length field is minimum length
12839 (as defined in sys/debug.h). Thus we can not use the .tbtab
12840 pseudo-op at all. */
12841
12842 /* An all-zero word flags the start of the tbtab, for debuggers
12843 that have to find it by searching forward from the entry
12844 point or from the current pc. */
19d2d16f 12845 fputs ("\t.long 0\n", file);
314fc5a9
ILT
12846
12847 /* Tbtab format type. Use format type 0. */
19d2d16f 12848 fputs ("\t.byte 0,", file);
314fc5a9 12849
5fc921c1
DE
12850 /* Language type. Unfortunately, there does not seem to be any
12851 official way to discover the language being compiled, so we
12852 use language_string.
12853 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
12854 Java is 13. Objective-C is 14. */
12855 if (! strcmp (language_string, "GNU C"))
314fc5a9
ILT
12856 i = 0;
12857 else if (! strcmp (language_string, "GNU F77"))
12858 i = 1;
8b83775b 12859 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 12860 i = 2;
5fc921c1
DE
12861 else if (! strcmp (language_string, "GNU Ada"))
12862 i = 3;
314fc5a9
ILT
12863 else if (! strcmp (language_string, "GNU C++"))
12864 i = 9;
9517ead8
AG
12865 else if (! strcmp (language_string, "GNU Java"))
12866 i = 13;
5fc921c1
DE
12867 else if (! strcmp (language_string, "GNU Objective-C"))
12868 i = 14;
314fc5a9
ILT
12869 else
12870 abort ();
12871 fprintf (file, "%d,", i);
12872
12873 /* 8 single bit fields: global linkage (not set for C extern linkage,
12874 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
12875 from start of procedure stored in tbtab, internal function, function
12876 has controlled storage, function has no toc, function uses fp,
12877 function logs/aborts fp operations. */
12878 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
12879 fprintf (file, "%d,",
12880 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
12881
12882 /* 6 bitfields: function is interrupt handler, name present in
12883 proc table, function calls alloca, on condition directives
12884 (controls stack walks, 3 bits), saves condition reg, saves
12885 link reg. */
12886 /* The `function calls alloca' bit seems to be set whenever reg 31 is
12887 set up as a frame pointer, even when there is no alloca call. */
12888 fprintf (file, "%d,",
6041bf2f
DE
12889 ((optional_tbtab << 6)
12890 | ((optional_tbtab & frame_pointer_needed) << 5)
12891 | (info->cr_save_p << 1)
12892 | (info->lr_save_p)));
314fc5a9 12893
6041bf2f 12894 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
12895 (6 bits). */
12896 fprintf (file, "%d,",
4697a36c 12897 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
12898
12899 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
12900 fprintf (file, "%d,", (32 - first_reg_to_save ()));
12901
6041bf2f
DE
12902 if (optional_tbtab)
12903 {
12904 /* Compute the parameter info from the function decl argument
12905 list. */
12906 tree decl;
12907 int next_parm_info_bit = 31;
314fc5a9 12908
6041bf2f
DE
12909 for (decl = DECL_ARGUMENTS (current_function_decl);
12910 decl; decl = TREE_CHAIN (decl))
12911 {
12912 rtx parameter = DECL_INCOMING_RTL (decl);
12913 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 12914
6041bf2f
DE
12915 if (GET_CODE (parameter) == REG)
12916 {
12917 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
12918 {
12919 int bits;
12920
12921 float_parms++;
12922
12923 if (mode == SFmode)
12924 bits = 0x2;
fcce224d 12925 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
12926 bits = 0x3;
12927 else
12928 abort ();
12929
12930 /* If only one bit will fit, don't or in this entry. */
12931 if (next_parm_info_bit > 0)
12932 parm_info |= (bits << (next_parm_info_bit - 1));
12933 next_parm_info_bit -= 2;
12934 }
12935 else
12936 {
12937 fixed_parms += ((GET_MODE_SIZE (mode)
12938 + (UNITS_PER_WORD - 1))
12939 / UNITS_PER_WORD);
12940 next_parm_info_bit -= 1;
12941 }
12942 }
12943 }
12944 }
314fc5a9
ILT
12945
12946 /* Number of fixed point parameters. */
12947 /* This is actually the number of words of fixed point parameters; thus
12948 an 8 byte struct counts as 2; and thus the maximum value is 8. */
12949 fprintf (file, "%d,", fixed_parms);
12950
12951 /* 2 bitfields: number of floating point parameters (7 bits), parameters
12952 all on stack. */
12953 /* This is actually the number of fp registers that hold parameters;
12954 and thus the maximum value is 13. */
12955 /* Set parameters on stack bit if parameters are not in their original
12956 registers, regardless of whether they are on the stack? Xlc
12957 seems to set the bit when not optimizing. */
12958 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
12959
6041bf2f
DE
12960 if (! optional_tbtab)
12961 return;
12962
314fc5a9
ILT
12963 /* Optional fields follow. Some are variable length. */
12964
12965 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
12966 11 double float. */
12967 /* There is an entry for each parameter in a register, in the order that
12968 they occur in the parameter list. Any intervening arguments on the
12969 stack are ignored. If the list overflows a long (max possible length
12970 34 bits) then completely leave off all elements that don't fit. */
12971 /* Only emit this long if there was at least one parameter. */
12972 if (fixed_parms || float_parms)
12973 fprintf (file, "\t.long %d\n", parm_info);
12974
12975 /* Offset from start of code to tb table. */
19d2d16f 12976 fputs ("\t.long ", file);
314fc5a9 12977 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
12978#if TARGET_AIX
12979 RS6000_OUTPUT_BASENAME (file, fname);
12980#else
9ebbca7d 12981 assemble_name (file, fname);
54ee9799 12982#endif
19d2d16f 12983 fputs ("-.", file);
54ee9799
DE
12984#if TARGET_AIX
12985 RS6000_OUTPUT_BASENAME (file, fname);
12986#else
9ebbca7d 12987 assemble_name (file, fname);
54ee9799 12988#endif
19d2d16f 12989 putc ('\n', file);
314fc5a9
ILT
12990
12991 /* Interrupt handler mask. */
12992 /* Omit this long, since we never set the interrupt handler bit
12993 above. */
12994
12995 /* Number of CTL (controlled storage) anchors. */
12996 /* Omit this long, since the has_ctl bit is never set above. */
12997
12998 /* Displacement into stack of each CTL anchor. */
12999 /* Omit this list of longs, because there are no CTL anchors. */
13000
13001 /* Length of function name. */
69c75916
AM
13002 if (*fname == '*')
13003 ++fname;
296b8152 13004 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
13005
13006 /* Function name. */
13007 assemble_string (fname, strlen (fname));
13008
13009 /* Register for alloca automatic storage; this is always reg 31.
13010 Only emit this if the alloca bit was set above. */
13011 if (frame_pointer_needed)
19d2d16f 13012 fputs ("\t.byte 31\n", file);
b1765bde
DE
13013
13014 fputs ("\t.align 2\n", file);
9b30bae2 13015 }
9878760c 13016}
17167fd8 13017\f
a4f6c312
SS
13018/* A C compound statement that outputs the assembler code for a thunk
13019 function, used to implement C++ virtual function calls with
13020 multiple inheritance. The thunk acts as a wrapper around a virtual
13021 function, adjusting the implicit object parameter before handing
13022 control off to the real function.
13023
13024 First, emit code to add the integer DELTA to the location that
13025 contains the incoming first argument. Assume that this argument
13026 contains a pointer, and is the one used to pass the `this' pointer
13027 in C++. This is the incoming argument *before* the function
13028 prologue, e.g. `%o0' on a sparc. The addition must preserve the
13029 values of all other incoming arguments.
17167fd8
MM
13030
13031 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
13032 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
13033 not touch the return address. Hence returning from FUNCTION will
13034 return to whoever called the current `thunk'.
17167fd8 13035
a4f6c312
SS
13036 The effect must be as if FUNCTION had been called directly with the
13037 adjusted first argument. This macro is responsible for emitting
13038 all of the code for a thunk function; output_function_prologue()
13039 and output_function_epilogue() are not invoked.
17167fd8 13040
a4f6c312
SS
13041 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
13042 been extracted from it.) It might possibly be useful on some
13043 targets, but probably not.
17167fd8 13044
a4f6c312
SS
13045 If you do not define this macro, the target-independent code in the
13046 C++ frontend will generate a less efficient heavyweight thunk that
13047 calls FUNCTION instead of jumping to it. The generic approach does
13048 not support varargs. */
17167fd8 13049
3961e8fe 13050static void
a2369ed3
DJ
13051rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
13052 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
13053 tree function)
17167fd8 13054{
5b71a4e7 13055 rtx this, insn, funexp;
17167fd8 13056
5b71a4e7 13057 reload_completed = 1;
fe3ad572 13058 epilogue_completed = 1;
5b71a4e7 13059 no_new_pseudos = 1;
56a7189a 13060
5b71a4e7 13061 /* Mark the end of the (empty) prologue. */
2e040219 13062 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 13063
5b71a4e7
DE
13064 /* Find the "this" pointer. If the function returns a structure,
13065 the structure return pointer is in r3. */
61f71b34 13066 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 13067 this = gen_rtx_REG (Pmode, 4);
56a7189a 13068 else
5b71a4e7 13069 this = gen_rtx_REG (Pmode, 3);
17167fd8 13070
5b71a4e7
DE
13071 /* Apply the constant offset, if required. */
13072 if (delta)
13073 {
13074 rtx delta_rtx = GEN_INT (delta);
13075 emit_insn (TARGET_32BIT
13076 ? gen_addsi3 (this, this, delta_rtx)
13077 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
13078 }
13079
5b71a4e7
DE
13080 /* Apply the offset from the vtable, if required. */
13081 if (vcall_offset)
17167fd8 13082 {
5b71a4e7
DE
13083 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
13084 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 13085
5b71a4e7 13086 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
13087 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
13088 {
13089 emit_insn (TARGET_32BIT
13090 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
13091 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
13092 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
13093 }
13094 else
13095 {
13096 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
13097
13098 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
13099 }
5b71a4e7
DE
13100 emit_insn (TARGET_32BIT
13101 ? gen_addsi3 (this, this, tmp)
13102 : gen_adddi3 (this, this, tmp));
17167fd8
MM
13103 }
13104
5b71a4e7
DE
13105 /* Generate a tail call to the target function. */
13106 if (!TREE_USED (function))
13107 {
13108 assemble_external (function);
13109 TREE_USED (function) = 1;
13110 }
13111 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 13112 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
13113
13114#if TARGET_MACHO
ab82a49f 13115 if (MACHOPIC_INDIRECT)
5b71a4e7 13116 funexp = machopic_indirect_call_target (funexp);
ee890fe2 13117#endif
5b71a4e7
DE
13118
13119 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
13120 generate sibcall RTL explicitly to avoid constraint abort. */
13121 insn = emit_call_insn (
13122 gen_rtx_PARALLEL (VOIDmode,
13123 gen_rtvec (4,
13124 gen_rtx_CALL (VOIDmode,
13125 funexp, const0_rtx),
13126 gen_rtx_USE (VOIDmode, const0_rtx),
13127 gen_rtx_USE (VOIDmode,
13128 gen_rtx_REG (SImode,
13129 LINK_REGISTER_REGNUM)),
13130 gen_rtx_RETURN (VOIDmode))));
13131 SIBLING_CALL_P (insn) = 1;
13132 emit_barrier ();
13133
13134 /* Run just enough of rest_of_compilation to get the insns emitted.
13135 There's not really enough bulk here to make other passes such as
13136 instruction scheduling worth while. Note that use_thunk calls
13137 assemble_start_function and assemble_end_function. */
13138 insn = get_insns ();
a2855205 13139 insn_locators_initialize ();
5b71a4e7
DE
13140 shorten_branches (insn);
13141 final_start_function (insn, file, 1);
13142 final (insn, file, 1, 0);
13143 final_end_function ();
13144
13145 reload_completed = 0;
fe3ad572 13146 epilogue_completed = 0;
5b71a4e7 13147 no_new_pseudos = 0;
9ebbca7d 13148}
9ebbca7d
GK
13149\f
13150/* A quick summary of the various types of 'constant-pool tables'
13151 under PowerPC:
13152
13153 Target Flags Name One table per
13154 AIX (none) AIX TOC object file
13155 AIX -mfull-toc AIX TOC object file
13156 AIX -mminimal-toc AIX minimal TOC translation unit
13157 SVR4/EABI (none) SVR4 SDATA object file
13158 SVR4/EABI -fpic SVR4 pic object file
13159 SVR4/EABI -fPIC SVR4 PIC translation unit
13160 SVR4/EABI -mrelocatable EABI TOC function
13161 SVR4/EABI -maix AIX TOC object file
13162 SVR4/EABI -maix -mminimal-toc
13163 AIX minimal TOC translation unit
13164
13165 Name Reg. Set by entries contains:
13166 made by addrs? fp? sum?
13167
13168 AIX TOC 2 crt0 as Y option option
13169 AIX minimal TOC 30 prolog gcc Y Y option
13170 SVR4 SDATA 13 crt0 gcc N Y N
13171 SVR4 pic 30 prolog ld Y not yet N
13172 SVR4 PIC 30 prolog gcc Y option option
13173 EABI TOC 30 prolog gcc Y option option
13174
13175*/
13176
9ebbca7d
GK
13177/* Hash functions for the hash table. */
13178
13179static unsigned
a2369ed3 13180rs6000_hash_constant (rtx k)
9ebbca7d 13181{
46b33600
RH
13182 enum rtx_code code = GET_CODE (k);
13183 enum machine_mode mode = GET_MODE (k);
13184 unsigned result = (code << 3) ^ mode;
13185 const char *format;
13186 int flen, fidx;
9ebbca7d 13187
46b33600
RH
13188 format = GET_RTX_FORMAT (code);
13189 flen = strlen (format);
13190 fidx = 0;
9ebbca7d 13191
46b33600
RH
13192 switch (code)
13193 {
13194 case LABEL_REF:
13195 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
13196
13197 case CONST_DOUBLE:
13198 if (mode != VOIDmode)
13199 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
13200 flen = 2;
13201 break;
13202
13203 case CODE_LABEL:
13204 fidx = 3;
13205 break;
13206
13207 default:
13208 break;
13209 }
9ebbca7d
GK
13210
13211 for (; fidx < flen; fidx++)
13212 switch (format[fidx])
13213 {
13214 case 's':
13215 {
13216 unsigned i, len;
13217 const char *str = XSTR (k, fidx);
13218 len = strlen (str);
13219 result = result * 613 + len;
13220 for (i = 0; i < len; i++)
13221 result = result * 613 + (unsigned) str[i];
17167fd8
MM
13222 break;
13223 }
9ebbca7d
GK
13224 case 'u':
13225 case 'e':
13226 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
13227 break;
13228 case 'i':
13229 case 'n':
13230 result = result * 613 + (unsigned) XINT (k, fidx);
13231 break;
13232 case 'w':
13233 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
13234 result = result * 613 + (unsigned) XWINT (k, fidx);
13235 else
13236 {
13237 size_t i;
13238 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
13239 result = result * 613 + (unsigned) (XWINT (k, fidx)
13240 >> CHAR_BIT * i);
13241 }
13242 break;
09501938
DE
13243 case '0':
13244 break;
9ebbca7d 13245 default:
a4f6c312 13246 abort ();
9ebbca7d 13247 }
46b33600 13248
9ebbca7d
GK
13249 return result;
13250}
13251
13252static unsigned
a2369ed3 13253toc_hash_function (const void *hash_entry)
9ebbca7d 13254{
a9098fd0
GK
13255 const struct toc_hash_struct *thc =
13256 (const struct toc_hash_struct *) hash_entry;
13257 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
13258}
13259
13260/* Compare H1 and H2 for equivalence. */
13261
13262static int
a2369ed3 13263toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
13264{
13265 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
13266 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
13267
a9098fd0
GK
13268 if (((const struct toc_hash_struct *) h1)->key_mode
13269 != ((const struct toc_hash_struct *) h2)->key_mode)
13270 return 0;
13271
5692c7bc 13272 return rtx_equal_p (r1, r2);
9ebbca7d
GK
13273}
13274
28e510bd
MM
13275/* These are the names given by the C++ front-end to vtables, and
13276 vtable-like objects. Ideally, this logic should not be here;
13277 instead, there should be some programmatic way of inquiring as
13278 to whether or not an object is a vtable. */
13279
13280#define VTABLE_NAME_P(NAME) \
13281 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
13282 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
13283 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
13284 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
13285
13286void
a2369ed3 13287rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
13288{
13289 /* Currently C++ toc references to vtables can be emitted before it
13290 is decided whether the vtable is public or private. If this is
13291 the case, then the linker will eventually complain that there is
13292 a reference to an unknown section. Thus, for vtables only,
13293 we emit the TOC reference to reference the symbol and not the
13294 section. */
13295 const char *name = XSTR (x, 0);
54ee9799
DE
13296
13297 if (VTABLE_NAME_P (name))
13298 {
13299 RS6000_OUTPUT_BASENAME (file, name);
13300 }
13301 else
13302 assemble_name (file, name);
28e510bd
MM
13303}
13304
a4f6c312
SS
13305/* Output a TOC entry. We derive the entry name from what is being
13306 written. */
9878760c
RK
13307
13308void
a2369ed3 13309output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
13310{
13311 char buf[256];
3cce094d 13312 const char *name = buf;
ec940faa 13313 const char *real_name;
9878760c
RK
13314 rtx base = x;
13315 int offset = 0;
13316
4697a36c
MM
13317 if (TARGET_NO_TOC)
13318 abort ();
13319
9ebbca7d
GK
13320 /* When the linker won't eliminate them, don't output duplicate
13321 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
13322 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
13323 CODE_LABELs. */
13324 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
13325 {
13326 struct toc_hash_struct *h;
13327 void * * found;
13328
17211ab5 13329 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 13330 time because GGC is not initialized at that point. */
17211ab5
GK
13331 if (toc_hash_table == NULL)
13332 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
13333 toc_hash_eq, NULL);
13334
9ebbca7d
GK
13335 h = ggc_alloc (sizeof (*h));
13336 h->key = x;
a9098fd0 13337 h->key_mode = mode;
9ebbca7d
GK
13338 h->labelno = labelno;
13339
13340 found = htab_find_slot (toc_hash_table, h, 1);
13341 if (*found == NULL)
13342 *found = h;
13343 else /* This is indeed a duplicate.
13344 Set this label equal to that label. */
13345 {
13346 fputs ("\t.set ", file);
13347 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13348 fprintf (file, "%d,", labelno);
13349 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13350 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
13351 found)->labelno));
13352 return;
13353 }
13354 }
13355
13356 /* If we're going to put a double constant in the TOC, make sure it's
13357 aligned properly when strict alignment is on. */
ff1720ed
RK
13358 if (GET_CODE (x) == CONST_DOUBLE
13359 && STRICT_ALIGNMENT
a9098fd0 13360 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
13361 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
13362 ASM_OUTPUT_ALIGN (file, 3);
13363 }
13364
4977bab6 13365 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 13366
37c37a57
RK
13367 /* Handle FP constants specially. Note that if we have a minimal
13368 TOC, things we put here aren't actually in the TOC, so we can allow
13369 FP constants. */
fcce224d
DE
13370 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
13371 {
13372 REAL_VALUE_TYPE rv;
13373 long k[4];
13374
13375 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13376 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
13377
13378 if (TARGET_64BIT)
13379 {
13380 if (TARGET_MINIMAL_TOC)
13381 fputs (DOUBLE_INT_ASM_OP, file);
13382 else
13383 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13384 k[0] & 0xffffffff, k[1] & 0xffffffff,
13385 k[2] & 0xffffffff, k[3] & 0xffffffff);
13386 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
13387 k[0] & 0xffffffff, k[1] & 0xffffffff,
13388 k[2] & 0xffffffff, k[3] & 0xffffffff);
13389 return;
13390 }
13391 else
13392 {
13393 if (TARGET_MINIMAL_TOC)
13394 fputs ("\t.long ", file);
13395 else
13396 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13397 k[0] & 0xffffffff, k[1] & 0xffffffff,
13398 k[2] & 0xffffffff, k[3] & 0xffffffff);
13399 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
13400 k[0] & 0xffffffff, k[1] & 0xffffffff,
13401 k[2] & 0xffffffff, k[3] & 0xffffffff);
13402 return;
13403 }
13404 }
13405 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 13406 {
042259f2
DE
13407 REAL_VALUE_TYPE rv;
13408 long k[2];
0adc764e 13409
042259f2
DE
13410 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13411 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 13412
13ded975
DE
13413 if (TARGET_64BIT)
13414 {
13415 if (TARGET_MINIMAL_TOC)
2bfcf297 13416 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13417 else
2f0552b6
AM
13418 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13419 k[0] & 0xffffffff, k[1] & 0xffffffff);
13420 fprintf (file, "0x%lx%08lx\n",
13421 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13422 return;
13423 }
1875cc88 13424 else
13ded975
DE
13425 {
13426 if (TARGET_MINIMAL_TOC)
2bfcf297 13427 fputs ("\t.long ", file);
13ded975 13428 else
2f0552b6
AM
13429 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13430 k[0] & 0xffffffff, k[1] & 0xffffffff);
13431 fprintf (file, "0x%lx,0x%lx\n",
13432 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13433 return;
13434 }
9878760c 13435 }
a9098fd0 13436 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 13437 {
042259f2
DE
13438 REAL_VALUE_TYPE rv;
13439 long l;
9878760c 13440
042259f2
DE
13441 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13442 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
13443
31bfaa0b
DE
13444 if (TARGET_64BIT)
13445 {
13446 if (TARGET_MINIMAL_TOC)
2bfcf297 13447 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 13448 else
2f0552b6
AM
13449 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13450 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
13451 return;
13452 }
042259f2 13453 else
31bfaa0b
DE
13454 {
13455 if (TARGET_MINIMAL_TOC)
2bfcf297 13456 fputs ("\t.long ", file);
31bfaa0b 13457 else
2f0552b6
AM
13458 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13459 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
13460 return;
13461 }
042259f2 13462 }
f176e826 13463 else if (GET_MODE (x) == VOIDmode
a9098fd0 13464 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 13465 {
e2c953b6 13466 unsigned HOST_WIDE_INT low;
042259f2
DE
13467 HOST_WIDE_INT high;
13468
13469 if (GET_CODE (x) == CONST_DOUBLE)
13470 {
13471 low = CONST_DOUBLE_LOW (x);
13472 high = CONST_DOUBLE_HIGH (x);
13473 }
13474 else
13475#if HOST_BITS_PER_WIDE_INT == 32
13476 {
13477 low = INTVAL (x);
0858c623 13478 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
13479 }
13480#else
13481 {
0858c623 13482 low = INTVAL (x) & 0xffffffff;
042259f2
DE
13483 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
13484 }
13485#endif
9878760c 13486
a9098fd0
GK
13487 /* TOC entries are always Pmode-sized, but since this
13488 is a bigendian machine then if we're putting smaller
13489 integer constants in the TOC we have to pad them.
13490 (This is still a win over putting the constants in
13491 a separate constant pool, because then we'd have
02a4ec28
FS
13492 to have both a TOC entry _and_ the actual constant.)
13493
13494 For a 32-bit target, CONST_INT values are loaded and shifted
13495 entirely within `low' and can be stored in one TOC entry. */
13496
13497 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 13498 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
13499
13500 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
13501 {
13502#if HOST_BITS_PER_WIDE_INT == 32
13503 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
13504 POINTER_SIZE, &low, &high, 0);
13505#else
13506 low |= high << 32;
13507 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
13508 high = (HOST_WIDE_INT) low >> 32;
13509 low &= 0xffffffff;
13510#endif
13511 }
a9098fd0 13512
13ded975
DE
13513 if (TARGET_64BIT)
13514 {
13515 if (TARGET_MINIMAL_TOC)
2bfcf297 13516 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13517 else
2f0552b6
AM
13518 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
13519 (long) high & 0xffffffff, (long) low & 0xffffffff);
13520 fprintf (file, "0x%lx%08lx\n",
13521 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
13522 return;
13523 }
1875cc88 13524 else
13ded975 13525 {
02a4ec28
FS
13526 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
13527 {
13528 if (TARGET_MINIMAL_TOC)
2bfcf297 13529 fputs ("\t.long ", file);
02a4ec28 13530 else
2bfcf297 13531 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
13532 (long) high & 0xffffffff, (long) low & 0xffffffff);
13533 fprintf (file, "0x%lx,0x%lx\n",
13534 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 13535 }
13ded975 13536 else
02a4ec28
FS
13537 {
13538 if (TARGET_MINIMAL_TOC)
2bfcf297 13539 fputs ("\t.long ", file);
02a4ec28 13540 else
2f0552b6
AM
13541 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
13542 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 13543 }
13ded975
DE
13544 return;
13545 }
9878760c
RK
13546 }
13547
13548 if (GET_CODE (x) == CONST)
13549 {
2bfcf297
DB
13550 if (GET_CODE (XEXP (x, 0)) != PLUS)
13551 abort ();
13552
9878760c
RK
13553 base = XEXP (XEXP (x, 0), 0);
13554 offset = INTVAL (XEXP (XEXP (x, 0), 1));
13555 }
13556
13557 if (GET_CODE (base) == SYMBOL_REF)
13558 name = XSTR (base, 0);
13559 else if (GET_CODE (base) == LABEL_REF)
13560 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
13561 else if (GET_CODE (base) == CODE_LABEL)
13562 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
13563 else
13564 abort ();
13565
772c5265 13566 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 13567 if (TARGET_MINIMAL_TOC)
2bfcf297 13568 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
13569 else
13570 {
b6c9286a 13571 fprintf (file, "\t.tc %s", real_name);
9878760c 13572
1875cc88
JW
13573 if (offset < 0)
13574 fprintf (file, ".N%d", - offset);
13575 else if (offset)
13576 fprintf (file, ".P%d", offset);
9878760c 13577
19d2d16f 13578 fputs ("[TC],", file);
1875cc88 13579 }
581bc4de
MM
13580
13581 /* Currently C++ toc references to vtables can be emitted before it
13582 is decided whether the vtable is public or private. If this is
13583 the case, then the linker will eventually complain that there is
13584 a TOC reference to an unknown section. Thus, for vtables only,
13585 we emit the TOC reference to reference the symbol and not the
13586 section. */
28e510bd 13587 if (VTABLE_NAME_P (name))
581bc4de 13588 {
54ee9799 13589 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
13590 if (offset < 0)
13591 fprintf (file, "%d", offset);
13592 else if (offset > 0)
13593 fprintf (file, "+%d", offset);
13594 }
13595 else
13596 output_addr_const (file, x);
19d2d16f 13597 putc ('\n', file);
9878760c
RK
13598}
13599\f
13600/* Output an assembler pseudo-op to write an ASCII string of N characters
13601 starting at P to FILE.
13602
13603 On the RS/6000, we have to do this using the .byte operation and
13604 write out special characters outside the quoted string.
13605 Also, the assembler is broken; very long strings are truncated,
a4f6c312 13606 so we must artificially break them up early. */
9878760c
RK
13607
13608void
a2369ed3 13609output_ascii (FILE *file, const char *p, int n)
9878760c
RK
13610{
13611 char c;
13612 int i, count_string;
d330fd93
KG
13613 const char *for_string = "\t.byte \"";
13614 const char *for_decimal = "\t.byte ";
13615 const char *to_close = NULL;
9878760c
RK
13616
13617 count_string = 0;
13618 for (i = 0; i < n; i++)
13619 {
13620 c = *p++;
13621 if (c >= ' ' && c < 0177)
13622 {
13623 if (for_string)
13624 fputs (for_string, file);
13625 putc (c, file);
13626
13627 /* Write two quotes to get one. */
13628 if (c == '"')
13629 {
13630 putc (c, file);
13631 ++count_string;
13632 }
13633
13634 for_string = NULL;
13635 for_decimal = "\"\n\t.byte ";
13636 to_close = "\"\n";
13637 ++count_string;
13638
13639 if (count_string >= 512)
13640 {
13641 fputs (to_close, file);
13642
13643 for_string = "\t.byte \"";
13644 for_decimal = "\t.byte ";
13645 to_close = NULL;
13646 count_string = 0;
13647 }
13648 }
13649 else
13650 {
13651 if (for_decimal)
13652 fputs (for_decimal, file);
13653 fprintf (file, "%d", c);
13654
13655 for_string = "\n\t.byte \"";
13656 for_decimal = ", ";
13657 to_close = "\n";
13658 count_string = 0;
13659 }
13660 }
13661
13662 /* Now close the string if we have written one. Then end the line. */
13663 if (to_close)
9ebbca7d 13664 fputs (to_close, file);
9878760c
RK
13665}
13666\f
13667/* Generate a unique section name for FILENAME for a section type
13668 represented by SECTION_DESC. Output goes into BUF.
13669
13670 SECTION_DESC can be any string, as long as it is different for each
13671 possible section type.
13672
13673 We name the section in the same manner as xlc. The name begins with an
13674 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13675 names) with the last period replaced by the string SECTION_DESC. If
13676 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13677 the name. */
9878760c
RK
13678
13679void
a2369ed3
DJ
13680rs6000_gen_section_name (char **buf, const char *filename,
13681 const char *section_desc)
9878760c 13682{
9ebbca7d 13683 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13684 char *p;
13685 int len;
9878760c
RK
13686
13687 after_last_slash = filename;
13688 for (q = filename; *q; q++)
11e5fe42
RK
13689 {
13690 if (*q == '/')
13691 after_last_slash = q + 1;
13692 else if (*q == '.')
13693 last_period = q;
13694 }
9878760c 13695
11e5fe42 13696 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13697 *buf = (char *) xmalloc (len);
9878760c
RK
13698
13699 p = *buf;
13700 *p++ = '_';
13701
13702 for (q = after_last_slash; *q; q++)
13703 {
11e5fe42 13704 if (q == last_period)
9878760c
RK
13705 {
13706 strcpy (p, section_desc);
13707 p += strlen (section_desc);
e3981aab 13708 break;
9878760c
RK
13709 }
13710
e9a780ec 13711 else if (ISALNUM (*q))
9878760c
RK
13712 *p++ = *q;
13713 }
13714
11e5fe42 13715 if (last_period == 0)
9878760c
RK
13716 strcpy (p, section_desc);
13717 else
13718 *p = '\0';
13719}
e165f3f0 13720\f
a4f6c312 13721/* Emit profile function. */
411707f4 13722
411707f4 13723void
a2369ed3 13724output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 13725{
ffcfcb5f
AM
13726 if (TARGET_PROFILE_KERNEL)
13727 return;
13728
8480e480
CC
13729 if (DEFAULT_ABI == ABI_AIX)
13730 {
9739c90c
JJ
13731#ifndef NO_PROFILE_COUNTERS
13732# define NO_PROFILE_COUNTERS 0
13733#endif
13734 if (NO_PROFILE_COUNTERS)
13735 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
13736 else
13737 {
13738 char buf[30];
13739 const char *label_name;
13740 rtx fun;
411707f4 13741
9739c90c
JJ
13742 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
13743 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
13744 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 13745
9739c90c
JJ
13746 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
13747 fun, Pmode);
13748 }
8480e480 13749 }
ee890fe2
SS
13750 else if (DEFAULT_ABI == ABI_DARWIN)
13751 {
d5fa86ba 13752 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
13753 int caller_addr_regno = LINK_REGISTER_REGNUM;
13754
13755 /* Be conservative and always set this, at least for now. */
13756 current_function_uses_pic_offset_table = 1;
13757
13758#if TARGET_MACHO
13759 /* For PIC code, set up a stub and collect the caller's address
13760 from r0, which is where the prologue puts it. */
ab82a49f 13761 if (MACHOPIC_INDIRECT)
ee890fe2
SS
13762 {
13763 mcount_name = machopic_stub_name (mcount_name);
13764 if (current_function_uses_pic_offset_table)
13765 caller_addr_regno = 0;
13766 }
13767#endif
13768 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
13769 0, VOIDmode, 1,
13770 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
13771 }
411707f4
CC
13772}
13773
a4f6c312 13774/* Write function profiler code. */
e165f3f0
RK
13775
13776void
a2369ed3 13777output_function_profiler (FILE *file, int labelno)
e165f3f0 13778{
3daf36a4 13779 char buf[100];
09eeeacb 13780 int save_lr = 8;
e165f3f0 13781
38c1f2d7 13782 switch (DEFAULT_ABI)
3daf36a4 13783 {
38c1f2d7
MM
13784 default:
13785 abort ();
13786
13787 case ABI_V4:
09eeeacb 13788 save_lr = 4;
09eeeacb
AM
13789 if (!TARGET_32BIT)
13790 {
13791 warning ("no profiling of 64-bit code for this ABI");
13792 return;
13793 }
ffcfcb5f 13794 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
13795 fprintf (file, "\tmflr %s\n", reg_names[0]);
13796 if (flag_pic == 1)
13797 {
dfdfa60f 13798 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
13799 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13800 reg_names[0], save_lr, reg_names[1]);
17167fd8 13801 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 13802 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 13803 assemble_name (file, buf);
17167fd8 13804 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 13805 }
9ebbca7d 13806 else if (flag_pic > 1)
38c1f2d7 13807 {
09eeeacb
AM
13808 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13809 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
13810 /* Now, we need to get the address of the label. */
13811 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 13812 assemble_name (file, buf);
9ebbca7d
GK
13813 fputs ("-.\n1:", file);
13814 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
13815 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
13816 reg_names[0], reg_names[11]);
13817 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
13818 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 13819 }
38c1f2d7
MM
13820 else
13821 {
17167fd8 13822 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 13823 assemble_name (file, buf);
dfdfa60f 13824 fputs ("@ha\n", file);
09eeeacb
AM
13825 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13826 reg_names[0], save_lr, reg_names[1]);
a260abc9 13827 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 13828 assemble_name (file, buf);
17167fd8 13829 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
13830 }
13831
50d440bc 13832 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
3b6ce0af
DE
13833 fprintf (file, "\tbl %s%s\n",
13834 RS6000_MCOUNT, flag_pic ? "@plt" : "");
38c1f2d7
MM
13835 break;
13836
13837 case ABI_AIX:
ee890fe2 13838 case ABI_DARWIN:
ffcfcb5f
AM
13839 if (!TARGET_PROFILE_KERNEL)
13840 {
a3c9585f 13841 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
13842 }
13843 else
13844 {
13845 if (TARGET_32BIT)
13846 abort ();
13847
13848 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
13849 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
13850
13851 if (current_function_needs_context)
13852 {
13853 asm_fprintf (file, "\tstd %s,24(%s)\n",
13854 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13855 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13856 asm_fprintf (file, "\tld %s,24(%s)\n",
13857 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13858 }
13859 else
13860 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13861 }
38c1f2d7
MM
13862 break;
13863 }
e165f3f0 13864}
a251ffd0 13865
b54cf83a
DE
13866\f
13867static int
863d938c 13868rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
13869{
13870 return 1;
13871}
13872
b54cf83a
DE
13873/* Power4 load update and store update instructions are cracked into a
13874 load or store and an integer insn which are executed in the same cycle.
13875 Branches have their own dispatch slot which does not count against the
13876 GCC issue rate, but it changes the program flow so there are no other
13877 instructions to issue in this cycle. */
13878
13879static int
a2369ed3
DJ
13880rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
13881 int verbose ATTRIBUTE_UNUSED,
13882 rtx insn, int more)
b54cf83a
DE
13883{
13884 if (GET_CODE (PATTERN (insn)) == USE
13885 || GET_CODE (PATTERN (insn)) == CLOBBER)
13886 return more;
13887
13888 if (rs6000_cpu == PROCESSOR_POWER4)
13889 {
cbe26ab8
DN
13890 if (is_microcoded_insn (insn))
13891 return 0;
13892 else if (is_cracked_insn (insn))
13893 return more > 2 ? more - 2 : 0;
b54cf83a 13894 }
165b263e
DE
13895
13896 return more - 1;
b54cf83a
DE
13897}
13898
a251ffd0
TG
13899/* Adjust the cost of a scheduling dependency. Return the new cost of
13900 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
13901
c237e94a 13902static int
a2369ed3
DJ
13903rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
13904 int cost)
a251ffd0
TG
13905{
13906 if (! recog_memoized (insn))
13907 return 0;
13908
13909 if (REG_NOTE_KIND (link) != 0)
13910 return 0;
13911
13912 if (REG_NOTE_KIND (link) == 0)
13913 {
ed947a96
DJ
13914 /* Data dependency; DEP_INSN writes a register that INSN reads
13915 some cycles later. */
13916 switch (get_attr_type (insn))
13917 {
13918 case TYPE_JMPREG:
309323c2 13919 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
13920 a mtctr and bctr (and mtlr and br/blr). The first
13921 scheduling pass will not know about this latency since
13922 the mtctr instruction, which has the latency associated
13923 to it, will be generated by reload. */
309323c2 13924 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
13925 case TYPE_BRANCH:
13926 /* Leave some extra cycles between a compare and its
13927 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
13928 if ((rs6000_cpu_attr == CPU_PPC603
13929 || rs6000_cpu_attr == CPU_PPC604
13930 || rs6000_cpu_attr == CPU_PPC604E
13931 || rs6000_cpu_attr == CPU_PPC620
13932 || rs6000_cpu_attr == CPU_PPC630
13933 || rs6000_cpu_attr == CPU_PPC750
13934 || rs6000_cpu_attr == CPU_PPC7400
13935 || rs6000_cpu_attr == CPU_PPC7450
13936 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
13937 && recog_memoized (dep_insn)
13938 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
13939 && (get_attr_type (dep_insn) == TYPE_CMP
13940 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 13941 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
13942 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
13943 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 13944 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
13945 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
13946 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
13947 return cost + 2;
13948 default:
13949 break;
13950 }
a251ffd0
TG
13951 /* Fall out to return default cost. */
13952 }
13953
13954 return cost;
13955}
b6c9286a 13956
cbe26ab8 13957/* The function returns a true if INSN is microcoded.
839a4992 13958 Return false otherwise. */
cbe26ab8
DN
13959
13960static bool
13961is_microcoded_insn (rtx insn)
13962{
13963 if (!insn || !INSN_P (insn)
13964 || GET_CODE (PATTERN (insn)) == USE
13965 || GET_CODE (PATTERN (insn)) == CLOBBER)
13966 return false;
13967
13968 if (rs6000_cpu == PROCESSOR_POWER4)
13969 {
13970 enum attr_type type = get_attr_type (insn);
13971 if (type == TYPE_LOAD_EXT_U
13972 || type == TYPE_LOAD_EXT_UX
13973 || type == TYPE_LOAD_UX
13974 || type == TYPE_STORE_UX
13975 || type == TYPE_MFCR)
13976 return true;
13977 }
13978
13979 return false;
13980}
13981
5c425df5 13982/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
13983 as the first insn in a dispatch group ("dispatch-slot restricted").
13984 In this case, the returned value indicates how many dispatch slots
13985 the insn occupies (at the beginning of the group).
79ae11c4
DN
13986 Return 0 otherwise. */
13987
cbe26ab8 13988static int
79ae11c4
DN
13989is_dispatch_slot_restricted (rtx insn)
13990{
13991 enum attr_type type;
13992
13993 if (rs6000_cpu != PROCESSOR_POWER4)
13994 return 0;
13995
13996 if (!insn
13997 || insn == NULL_RTX
13998 || GET_CODE (insn) == NOTE
13999 || GET_CODE (PATTERN (insn)) == USE
14000 || GET_CODE (PATTERN (insn)) == CLOBBER)
14001 return 0;
14002
14003 type = get_attr_type (insn);
14004
14005 switch (type){
14006 case TYPE_MFCR:
14007 case TYPE_MFCRF:
14008 case TYPE_MTCR:
14009 case TYPE_DELAYED_CR:
14010 case TYPE_CR_LOGICAL:
14011 case TYPE_MTJMPR:
14012 case TYPE_MFJMPR:
14013 return 1;
14014 case TYPE_IDIV:
14015 case TYPE_LDIV:
14016 return 2;
14017 default:
14018 return 0;
14019 }
14020}
14021
cbe26ab8
DN
14022/* The function returns true if INSN is cracked into 2 instructions
14023 by the processor (and therefore occupies 2 issue slots). */
14024
14025static bool
14026is_cracked_insn (rtx insn)
14027{
14028 if (!insn || !INSN_P (insn)
14029 || GET_CODE (PATTERN (insn)) == USE
14030 || GET_CODE (PATTERN (insn)) == CLOBBER)
14031 return false;
14032
14033 if (rs6000_cpu == PROCESSOR_POWER4)
14034 {
14035 enum attr_type type = get_attr_type (insn);
14036 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
14037 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
14038 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
14039 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
14040 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
14041 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
14042 || type == TYPE_IDIV || type == TYPE_LDIV
14043 || type == TYPE_INSERT_WORD)
14044 return true;
14045 }
14046
14047 return false;
14048}
14049
14050/* The function returns true if INSN can be issued only from
a3c9585f 14051 the branch slot. */
cbe26ab8
DN
14052
14053static bool
14054is_branch_slot_insn (rtx insn)
14055{
14056 if (!insn || !INSN_P (insn)
14057 || GET_CODE (PATTERN (insn)) == USE
14058 || GET_CODE (PATTERN (insn)) == CLOBBER)
14059 return false;
14060
14061 if (rs6000_cpu == PROCESSOR_POWER4)
14062 {
14063 enum attr_type type = get_attr_type (insn);
14064 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
14065 return true;
14066 return false;
14067 }
14068
14069 return false;
14070}
79ae11c4 14071
a4f6c312 14072/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
14073 priority INSN_PRIORITY (INSN). Increase the priority to execute the
14074 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
14075 define this macro if you do not need to adjust the scheduling
14076 priorities of insns. */
bef84347 14077
c237e94a 14078static int
a2369ed3 14079rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 14080{
a4f6c312
SS
14081 /* On machines (like the 750) which have asymmetric integer units,
14082 where one integer unit can do multiply and divides and the other
14083 can't, reduce the priority of multiply/divide so it is scheduled
14084 before other integer operations. */
bef84347
VM
14085
14086#if 0
2c3c49de 14087 if (! INSN_P (insn))
bef84347
VM
14088 return priority;
14089
14090 if (GET_CODE (PATTERN (insn)) == USE)
14091 return priority;
14092
14093 switch (rs6000_cpu_attr) {
14094 case CPU_PPC750:
14095 switch (get_attr_type (insn))
14096 {
14097 default:
14098 break;
14099
14100 case TYPE_IMUL:
14101 case TYPE_IDIV:
3cb999d8
DE
14102 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
14103 priority, priority);
bef84347
VM
14104 if (priority >= 0 && priority < 0x01000000)
14105 priority >>= 3;
14106 break;
14107 }
14108 }
14109#endif
14110
79ae11c4
DN
14111 if (is_dispatch_slot_restricted (insn)
14112 && reload_completed
14113 && current_sched_info->sched_max_insns_priority
14114 && rs6000_sched_restricted_insns_priority)
14115 {
14116
14117 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
14118 if (rs6000_sched_restricted_insns_priority == 1)
14119 /* Attach highest priority to insn. This means that in
14120 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
14121 precede 'priority' (critical path) considerations. */
14122 return current_sched_info->sched_max_insns_priority;
14123 else if (rs6000_sched_restricted_insns_priority == 2)
14124 /* Increase priority of insn by a minimal amount. This means that in
14125 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
14126 precede dispatch-slot restriction considerations. */
14127 return (priority + 1);
14128 }
14129
bef84347
VM
14130 return priority;
14131}
14132
a4f6c312
SS
14133/* Return how many instructions the machine can issue per cycle. */
14134
c237e94a 14135static int
863d938c 14136rs6000_issue_rate (void)
b6c9286a 14137{
3317bab1
DE
14138 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
14139 if (!reload_completed)
14140 return 1;
14141
b6c9286a 14142 switch (rs6000_cpu_attr) {
3cb999d8
DE
14143 case CPU_RIOS1: /* ? */
14144 case CPU_RS64A:
14145 case CPU_PPC601: /* ? */
ed947a96 14146 case CPU_PPC7450:
3cb999d8 14147 return 3;
b54cf83a 14148 case CPU_PPC440:
b6c9286a 14149 case CPU_PPC603:
bef84347 14150 case CPU_PPC750:
ed947a96 14151 case CPU_PPC7400:
be12c2b0 14152 case CPU_PPC8540:
bef84347 14153 return 2;
3cb999d8 14154 case CPU_RIOS2:
b6c9286a 14155 case CPU_PPC604:
19684119 14156 case CPU_PPC604E:
b6c9286a 14157 case CPU_PPC620:
3cb999d8 14158 case CPU_PPC630:
b6c9286a 14159 return 4;
cbe26ab8
DN
14160 case CPU_POWER4:
14161 return 5;
b6c9286a
MM
14162 default:
14163 return 1;
14164 }
14165}
14166
be12c2b0
VM
14167/* Return how many instructions to look ahead for better insn
14168 scheduling. */
14169
14170static int
863d938c 14171rs6000_use_sched_lookahead (void)
be12c2b0
VM
14172{
14173 if (rs6000_cpu_attr == CPU_PPC8540)
14174 return 4;
14175 return 0;
14176}
14177
569fa502
DN
14178/* Determine is PAT refers to memory. */
14179
14180static bool
14181is_mem_ref (rtx pat)
14182{
14183 const char * fmt;
14184 int i, j;
14185 bool ret = false;
14186
14187 if (GET_CODE (pat) == MEM)
14188 return true;
14189
14190 /* Recursively process the pattern. */
14191 fmt = GET_RTX_FORMAT (GET_CODE (pat));
14192
14193 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
14194 {
14195 if (fmt[i] == 'e')
14196 ret |= is_mem_ref (XEXP (pat, i));
14197 else if (fmt[i] == 'E')
14198 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
14199 ret |= is_mem_ref (XVECEXP (pat, i, j));
14200 }
14201
14202 return ret;
14203}
14204
14205/* Determine if PAT is a PATTERN of a load insn. */
14206
14207static bool
14208is_load_insn1 (rtx pat)
14209{
14210 if (!pat || pat == NULL_RTX)
14211 return false;
14212
14213 if (GET_CODE (pat) == SET)
14214 return is_mem_ref (SET_SRC (pat));
14215
14216 if (GET_CODE (pat) == PARALLEL)
14217 {
14218 int i;
14219
14220 for (i = 0; i < XVECLEN (pat, 0); i++)
14221 if (is_load_insn1 (XVECEXP (pat, 0, i)))
14222 return true;
14223 }
14224
14225 return false;
14226}
14227
14228/* Determine if INSN loads from memory. */
14229
14230static bool
14231is_load_insn (rtx insn)
14232{
14233 if (!insn || !INSN_P (insn))
14234 return false;
14235
14236 if (GET_CODE (insn) == CALL_INSN)
14237 return false;
14238
14239 return is_load_insn1 (PATTERN (insn));
14240}
14241
14242/* Determine if PAT is a PATTERN of a store insn. */
14243
14244static bool
14245is_store_insn1 (rtx pat)
14246{
14247 if (!pat || pat == NULL_RTX)
14248 return false;
14249
14250 if (GET_CODE (pat) == SET)
14251 return is_mem_ref (SET_DEST (pat));
14252
14253 if (GET_CODE (pat) == PARALLEL)
14254 {
14255 int i;
14256
14257 for (i = 0; i < XVECLEN (pat, 0); i++)
14258 if (is_store_insn1 (XVECEXP (pat, 0, i)))
14259 return true;
14260 }
14261
14262 return false;
14263}
14264
14265/* Determine if INSN stores to memory. */
14266
14267static bool
14268is_store_insn (rtx insn)
14269{
14270 if (!insn || !INSN_P (insn))
14271 return false;
14272
14273 return is_store_insn1 (PATTERN (insn));
14274}
14275
14276/* Returns whether the dependence between INSN and NEXT is considered
14277 costly by the given target. */
14278
14279static bool
14280rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
14281{
14282 /* If the flag is not enbled - no dependence is considered costly;
14283 allow all dependent insns in the same group.
14284 This is the most aggressive option. */
14285 if (rs6000_sched_costly_dep == no_dep_costly)
14286 return false;
14287
14288 /* If the flag is set to 1 - a dependence is always considered costly;
14289 do not allow dependent instructions in the same group.
14290 This is the most conservative option. */
14291 if (rs6000_sched_costly_dep == all_deps_costly)
14292 return true;
14293
14294 if (rs6000_sched_costly_dep == store_to_load_dep_costly
14295 && is_load_insn (next)
14296 && is_store_insn (insn))
14297 /* Prevent load after store in the same group. */
14298 return true;
14299
14300 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
14301 && is_load_insn (next)
14302 && is_store_insn (insn)
14303 && (!link || (int) REG_NOTE_KIND (link) == 0))
14304 /* Prevent load after store in the same group if it is a true dependence. */
14305 return true;
14306
14307 /* The flag is set to X; dependences with latency >= X are considered costly,
14308 and will not be scheduled in the same group. */
14309 if (rs6000_sched_costly_dep <= max_dep_latency
14310 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
14311 return true;
14312
14313 return false;
14314}
14315
cbe26ab8
DN
14316/* Return the next insn after INSN that is found before TAIL is reached,
14317 skipping any "non-active" insns - insns that will not actually occupy
14318 an issue slot. Return NULL_RTX if such an insn is not found. */
14319
14320static rtx
14321get_next_active_insn (rtx insn, rtx tail)
14322{
14323 rtx next_insn;
14324
14325 if (!insn || insn == tail)
14326 return NULL_RTX;
14327
14328 next_insn = NEXT_INSN (insn);
14329
14330 while (next_insn
14331 && next_insn != tail
14332 && (GET_CODE(next_insn) == NOTE
14333 || GET_CODE (PATTERN (next_insn)) == USE
14334 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
14335 {
14336 next_insn = NEXT_INSN (next_insn);
14337 }
14338
14339 if (!next_insn || next_insn == tail)
14340 return NULL_RTX;
14341
14342 return next_insn;
14343}
14344
839a4992 14345/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
14346 of group WHICH_GROUP.
14347
14348 If WHICH_GROUP == current_group, this function will return true if INSN
14349 causes the termination of the current group (i.e, the dispatch group to
14350 which INSN belongs). This means that INSN will be the last insn in the
14351 group it belongs to.
14352
14353 If WHICH_GROUP == previous_group, this function will return true if INSN
14354 causes the termination of the previous group (i.e, the dispatch group that
14355 precedes the group to which INSN belongs). This means that INSN will be
14356 the first insn in the group it belongs to). */
14357
14358static bool
14359insn_terminates_group_p (rtx insn, enum group_termination which_group)
14360{
14361 enum attr_type type;
14362
14363 if (! insn)
14364 return false;
569fa502 14365
cbe26ab8
DN
14366 type = get_attr_type (insn);
14367
14368 if (is_microcoded_insn (insn))
14369 return true;
14370
14371 if (which_group == current_group)
14372 {
14373 if (is_branch_slot_insn (insn))
14374 return true;
14375 return false;
14376 }
14377 else if (which_group == previous_group)
14378 {
14379 if (is_dispatch_slot_restricted (insn))
14380 return true;
14381 return false;
14382 }
14383
14384 return false;
14385}
14386
839a4992 14387/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
14388 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
14389
14390static bool
14391is_costly_group (rtx *group_insns, rtx next_insn)
14392{
14393 int i;
14394 rtx link;
14395 int cost;
14396 int issue_rate = rs6000_issue_rate ();
14397
14398 for (i = 0; i < issue_rate; i++)
14399 {
14400 rtx insn = group_insns[i];
14401 if (!insn)
14402 continue;
14403 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
14404 {
14405 rtx next = XEXP (link, 0);
14406 if (next == next_insn)
14407 {
14408 cost = insn_cost (insn, link, next_insn);
14409 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
14410 return true;
14411 }
14412 }
14413 }
14414
14415 return false;
14416}
14417
14418/* Utility of the function redefine_groups.
14419 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
14420 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
14421 to keep it "far" (in a separate group) from GROUP_INSNS, following
14422 one of the following schemes, depending on the value of the flag
14423 -minsert_sched_nops = X:
14424 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 14425 in order to force NEXT_INSN into a separate group.
cbe26ab8
DN
14426 (2) X < sched_finish_regroup_exact: insert exactly X nops.
14427 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
14428 insertion (has a group just ended, how many vacant issue slots remain in the
14429 last group, and how many dispatch groups were encountered so far). */
14430
14431static int
14432force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
14433 bool *group_end, int can_issue_more, int *group_count)
14434{
14435 rtx nop;
14436 bool force;
14437 int issue_rate = rs6000_issue_rate ();
14438 bool end = *group_end;
14439 int i;
14440
14441 if (next_insn == NULL_RTX)
14442 return can_issue_more;
14443
14444 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
14445 return can_issue_more;
14446
14447 force = is_costly_group (group_insns, next_insn);
14448 if (!force)
14449 return can_issue_more;
14450
14451 if (sched_verbose > 6)
14452 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
14453 *group_count ,can_issue_more);
14454
14455 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
14456 {
14457 if (*group_end)
14458 can_issue_more = 0;
14459
14460 /* Since only a branch can be issued in the last issue_slot, it is
14461 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
14462 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
14463 in this case the last nop will start a new group and the branch will be
14464 forced to the new group. */
14465 if (can_issue_more && !is_branch_slot_insn (next_insn))
14466 can_issue_more--;
14467
14468 while (can_issue_more > 0)
14469 {
14470 nop = gen_nop();
14471 emit_insn_before (nop, next_insn);
14472 can_issue_more--;
14473 }
14474
14475 *group_end = true;
14476 return 0;
14477 }
14478
14479 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
14480 {
14481 int n_nops = rs6000_sched_insert_nops;
14482
14483 /* Nops can't be issued from the branch slot, so the effective
14484 issue_rate for nops is 'issue_rate - 1'. */
14485 if (can_issue_more == 0)
14486 can_issue_more = issue_rate;
14487 can_issue_more--;
14488 if (can_issue_more == 0)
14489 {
14490 can_issue_more = issue_rate - 1;
14491 (*group_count)++;
14492 end = true;
14493 for (i = 0; i < issue_rate; i++)
14494 {
14495 group_insns[i] = 0;
14496 }
14497 }
14498
14499 while (n_nops > 0)
14500 {
14501 nop = gen_nop ();
14502 emit_insn_before (nop, next_insn);
14503 if (can_issue_more == issue_rate - 1) /* new group begins */
14504 end = false;
14505 can_issue_more--;
14506 if (can_issue_more == 0)
14507 {
14508 can_issue_more = issue_rate - 1;
14509 (*group_count)++;
14510 end = true;
14511 for (i = 0; i < issue_rate; i++)
14512 {
14513 group_insns[i] = 0;
14514 }
14515 }
14516 n_nops--;
14517 }
14518
14519 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
14520 can_issue_more++;
14521
14522 *group_end = /* Is next_insn going to start a new group? */
14523 (end
14524 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14525 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14526 || (can_issue_more < issue_rate &&
14527 insn_terminates_group_p (next_insn, previous_group)));
14528 if (*group_end && end)
14529 (*group_count)--;
14530
14531 if (sched_verbose > 6)
14532 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
14533 *group_count, can_issue_more);
14534 return can_issue_more;
14535 }
14536
14537 return can_issue_more;
14538}
14539
14540/* This function tries to synch the dispatch groups that the compiler "sees"
14541 with the dispatch groups that the processor dispatcher is expected to
14542 form in practice. It tries to achieve this synchronization by forcing the
14543 estimated processor grouping on the compiler (as opposed to the function
14544 'pad_goups' which tries to force the scheduler's grouping on the processor).
14545
14546 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
14547 examines the (estimated) dispatch groups that will be formed by the processor
14548 dispatcher. It marks these group boundaries to reflect the estimated
14549 processor grouping, overriding the grouping that the scheduler had marked.
14550 Depending on the value of the flag '-minsert-sched-nops' this function can
14551 force certain insns into separate groups or force a certain distance between
14552 them by inserting nops, for example, if there exists a "costly dependence"
14553 between the insns.
14554
14555 The function estimates the group boundaries that the processor will form as
14556 folllows: It keeps track of how many vacant issue slots are available after
14557 each insn. A subsequent insn will start a new group if one of the following
14558 4 cases applies:
14559 - no more vacant issue slots remain in the current dispatch group.
14560 - only the last issue slot, which is the branch slot, is vacant, but the next
14561 insn is not a branch.
14562 - only the last 2 or less issue slots, including the branch slot, are vacant,
14563 which means that a cracked insn (which occupies two issue slots) can't be
14564 issued in this group.
14565 - less than 'issue_rate' slots are vacant, and the next insn always needs to
14566 start a new group. */
14567
14568static int
14569redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14570{
14571 rtx insn, next_insn;
14572 int issue_rate;
14573 int can_issue_more;
14574 int slot, i;
14575 bool group_end;
14576 int group_count = 0;
14577 rtx *group_insns;
14578
14579 /* Initialize. */
14580 issue_rate = rs6000_issue_rate ();
14581 group_insns = alloca (issue_rate * sizeof (rtx));
14582 for (i = 0; i < issue_rate; i++)
14583 {
14584 group_insns[i] = 0;
14585 }
14586 can_issue_more = issue_rate;
14587 slot = 0;
14588 insn = get_next_active_insn (prev_head_insn, tail);
14589 group_end = false;
14590
14591 while (insn != NULL_RTX)
14592 {
14593 slot = (issue_rate - can_issue_more);
14594 group_insns[slot] = insn;
14595 can_issue_more =
14596 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14597 if (insn_terminates_group_p (insn, current_group))
14598 can_issue_more = 0;
14599
14600 next_insn = get_next_active_insn (insn, tail);
14601 if (next_insn == NULL_RTX)
14602 return group_count + 1;
14603
14604 group_end = /* Is next_insn going to start a new group? */
14605 (can_issue_more == 0
14606 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14607 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14608 || (can_issue_more < issue_rate &&
14609 insn_terminates_group_p (next_insn, previous_group)));
14610
14611 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
14612 next_insn, &group_end, can_issue_more, &group_count);
14613
14614 if (group_end)
14615 {
14616 group_count++;
14617 can_issue_more = 0;
14618 for (i = 0; i < issue_rate; i++)
14619 {
14620 group_insns[i] = 0;
14621 }
14622 }
14623
14624 if (GET_MODE (next_insn) == TImode && can_issue_more)
14625 PUT_MODE(next_insn, VOIDmode);
14626 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
14627 PUT_MODE (next_insn, TImode);
14628
14629 insn = next_insn;
14630 if (can_issue_more == 0)
14631 can_issue_more = issue_rate;
14632 } /* while */
14633
14634 return group_count;
14635}
14636
14637/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
14638 dispatch group boundaries that the scheduler had marked. Pad with nops
14639 any dispatch groups which have vacant issue slots, in order to force the
14640 scheduler's grouping on the processor dispatcher. The function
14641 returns the number of dispatch groups found. */
14642
14643static int
14644pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14645{
14646 rtx insn, next_insn;
14647 rtx nop;
14648 int issue_rate;
14649 int can_issue_more;
14650 int group_end;
14651 int group_count = 0;
14652
14653 /* Initialize issue_rate. */
14654 issue_rate = rs6000_issue_rate ();
14655 can_issue_more = issue_rate;
14656
14657 insn = get_next_active_insn (prev_head_insn, tail);
14658 next_insn = get_next_active_insn (insn, tail);
14659
14660 while (insn != NULL_RTX)
14661 {
14662 can_issue_more =
14663 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14664
14665 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
14666
14667 if (next_insn == NULL_RTX)
14668 break;
14669
14670 if (group_end)
14671 {
14672 /* If the scheduler had marked group termination at this location
14673 (between insn and next_indn), and neither insn nor next_insn will
14674 force group termination, pad the group with nops to force group
14675 termination. */
14676 if (can_issue_more
14677 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
14678 && !insn_terminates_group_p (insn, current_group)
14679 && !insn_terminates_group_p (next_insn, previous_group))
14680 {
14681 if (!is_branch_slot_insn(next_insn))
14682 can_issue_more--;
14683
14684 while (can_issue_more)
14685 {
14686 nop = gen_nop ();
14687 emit_insn_before (nop, next_insn);
14688 can_issue_more--;
14689 }
14690 }
14691
14692 can_issue_more = issue_rate;
14693 group_count++;
14694 }
14695
14696 insn = next_insn;
14697 next_insn = get_next_active_insn (insn, tail);
14698 }
14699
14700 return group_count;
14701}
14702
14703/* The following function is called at the end of scheduling BB.
14704 After reload, it inserts nops at insn group bundling. */
14705
14706static void
38f391a5 14707rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
14708{
14709 int n_groups;
14710
14711 if (sched_verbose)
14712 fprintf (dump, "=== Finishing schedule.\n");
14713
14714 if (reload_completed && rs6000_cpu == PROCESSOR_POWER4)
14715 {
14716 if (rs6000_sched_insert_nops == sched_finish_none)
14717 return;
14718
14719 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
14720 n_groups = pad_groups (dump, sched_verbose,
14721 current_sched_info->prev_head,
14722 current_sched_info->next_tail);
14723 else
14724 n_groups = redefine_groups (dump, sched_verbose,
14725 current_sched_info->prev_head,
14726 current_sched_info->next_tail);
14727
14728 if (sched_verbose >= 6)
14729 {
14730 fprintf (dump, "ngroups = %d\n", n_groups);
14731 print_rtl (dump, current_sched_info->prev_head);
14732 fprintf (dump, "Done finish_sched\n");
14733 }
14734 }
14735}
b6c9286a 14736\f
b6c9286a
MM
14737/* Length in units of the trampoline for entering a nested function. */
14738
14739int
863d938c 14740rs6000_trampoline_size (void)
b6c9286a
MM
14741{
14742 int ret = 0;
14743
14744 switch (DEFAULT_ABI)
14745 {
14746 default:
14747 abort ();
14748
14749 case ABI_AIX:
8f802bfb 14750 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
14751 break;
14752
4dabc42d 14753 case ABI_DARWIN:
b6c9286a 14754 case ABI_V4:
03a7e1a5 14755 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 14756 break;
b6c9286a
MM
14757 }
14758
14759 return ret;
14760}
14761
14762/* Emit RTL insns to initialize the variable parts of a trampoline.
14763 FNADDR is an RTX for the address of the function's pure code.
14764 CXT is an RTX for the static chain value for the function. */
14765
14766void
a2369ed3 14767rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 14768{
ac2a93a1 14769 enum machine_mode pmode = Pmode;
8bd04c56
MM
14770 int regsize = (TARGET_32BIT) ? 4 : 8;
14771 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
14772
14773 switch (DEFAULT_ABI)
14774 {
14775 default:
14776 abort ();
14777
8bd04c56 14778/* Macros to shorten the code expansions below. */
39403d82 14779#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
14780#define MEM_PLUS(addr,offset) \
14781 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 14782
b6c9286a
MM
14783 /* Under AIX, just build the 3 word function descriptor */
14784 case ABI_AIX:
8bd04c56
MM
14785 {
14786 rtx fn_reg = gen_reg_rtx (pmode);
14787 rtx toc_reg = gen_reg_rtx (pmode);
14788 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 14789 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
14790 emit_move_insn (MEM_DEREF (addr), fn_reg);
14791 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
14792 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
14793 }
b6c9286a
MM
14794 break;
14795
4dabc42d
TC
14796 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
14797 case ABI_DARWIN:
b6c9286a 14798 case ABI_V4:
39403d82 14799 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
14800 FALSE, VOIDmode, 4,
14801 addr, pmode,
14802 GEN_INT (rs6000_trampoline_size ()), SImode,
14803 fnaddr, pmode,
14804 ctx_reg, pmode);
b6c9286a 14805 break;
b6c9286a
MM
14806 }
14807
14808 return;
14809}
7509c759
MM
14810
14811\f
91d231cb 14812/* Table of valid machine attributes. */
a4f6c312 14813
91d231cb 14814const struct attribute_spec rs6000_attribute_table[] =
7509c759 14815{
91d231cb 14816 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
8bb418a3 14817 { "altivec", 1, 1, false, true, false, rs6000_handle_altivec_attribute },
a5c76ee6
ZW
14818 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14819 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14820 { NULL, 0, 0, false, false, false, NULL }
91d231cb 14821};
7509c759 14822
8bb418a3
ZL
14823/* Handle the "altivec" attribute. The attribute may have
14824 arguments as follows:
14825
14826 __attribute__((altivec(vector__)))
14827 __attribute__((altivec(pixel__))) (always followed by 'unsigned short')
14828 __attribute__((altivec(bool__))) (always followed by 'unsigned')
14829
14830 and may appear more than once (e.g., 'vector bool char') in a
14831 given declaration. */
14832
14833static tree
14834rs6000_handle_altivec_attribute (tree *node, tree name, tree args,
14835 int flags ATTRIBUTE_UNUSED,
14836 bool *no_add_attrs)
14837{
14838 tree type = *node, result = NULL_TREE;
14839 enum machine_mode mode;
14840 int unsigned_p;
14841 char altivec_type
14842 = ((args && TREE_CODE (args) == TREE_LIST && TREE_VALUE (args)
14843 && TREE_CODE (TREE_VALUE (args)) == IDENTIFIER_NODE)
14844 ? *IDENTIFIER_POINTER (TREE_VALUE (args))
14845 : '?');
14846
14847 while (POINTER_TYPE_P (type)
14848 || TREE_CODE (type) == FUNCTION_TYPE
14849 || TREE_CODE (type) == METHOD_TYPE
14850 || TREE_CODE (type) == ARRAY_TYPE)
14851 type = TREE_TYPE (type);
14852
14853 mode = TYPE_MODE (type);
14854
14855 if (rs6000_warn_altivec_long
14856 && (type == long_unsigned_type_node || type == long_integer_type_node))
14857 warning ("use of 'long' in AltiVec types is deprecated; use 'int'");
14858
14859 switch (altivec_type)
14860 {
14861 case 'v':
14862 unsigned_p = TREE_UNSIGNED (type);
14863 switch (mode)
14864 {
14865 case SImode:
14866 result = (unsigned_p ? unsigned_V4SI_type_node : V4SI_type_node);
14867 break;
14868 case HImode:
14869 result = (unsigned_p ? unsigned_V8HI_type_node : V8HI_type_node);
14870 break;
14871 case QImode:
14872 result = (unsigned_p ? unsigned_V16QI_type_node : V16QI_type_node);
14873 break;
14874 case SFmode: result = V4SF_type_node; break;
14875 /* If the user says 'vector int bool', we may be handed the 'bool'
14876 attribute _before_ the 'vector' attribute, and so select the proper
14877 type in the 'b' case below. */
14878 case V4SImode: case V8HImode: case V16QImode: result = type;
14879 default: break;
14880 }
14881 break;
14882 case 'b':
14883 switch (mode)
14884 {
14885 case SImode: case V4SImode: result = bool_V4SI_type_node; break;
14886 case HImode: case V8HImode: result = bool_V8HI_type_node; break;
14887 case QImode: case V16QImode: result = bool_V16QI_type_node;
14888 default: break;
14889 }
14890 break;
14891 case 'p':
14892 switch (mode)
14893 {
14894 case V8HImode: result = pixel_V8HI_type_node;
14895 default: break;
14896 }
14897 default: break;
14898 }
14899
14900 *no_add_attrs = true; /* No need to hang on to the attribute. */
14901
14902 if (!result)
14903 warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
14904 else
14905 *node = reconstruct_complex_type (*node, result);
14906
14907 return NULL_TREE;
14908}
14909
f18eca82
ZL
14910/* AltiVec defines four built-in scalar types that serve as vector
14911 elements; we must teach the compiler how to mangle them. */
14912
14913static const char *
14914rs6000_mangle_fundamental_type (tree type)
14915{
14916 if (type == bool_char_type_node) return "U6__boolc";
14917 if (type == bool_short_type_node) return "U6__bools";
14918 if (type == pixel_type_node) return "u7__pixel";
14919 if (type == bool_int_type_node) return "U6__booli";
14920
14921 /* For all other types, use normal C++ mangling. */
14922 return NULL;
14923}
14924
a5c76ee6
ZW
14925/* Handle a "longcall" or "shortcall" attribute; arguments as in
14926 struct attribute_spec.handler. */
a4f6c312 14927
91d231cb 14928static tree
a2369ed3
DJ
14929rs6000_handle_longcall_attribute (tree *node, tree name,
14930 tree args ATTRIBUTE_UNUSED,
14931 int flags ATTRIBUTE_UNUSED,
14932 bool *no_add_attrs)
91d231cb
JM
14933{
14934 if (TREE_CODE (*node) != FUNCTION_TYPE
14935 && TREE_CODE (*node) != FIELD_DECL
14936 && TREE_CODE (*node) != TYPE_DECL)
14937 {
14938 warning ("`%s' attribute only applies to functions",
14939 IDENTIFIER_POINTER (name));
14940 *no_add_attrs = true;
14941 }
6a4cee5f 14942
91d231cb 14943 return NULL_TREE;
7509c759
MM
14944}
14945
a5c76ee6
ZW
14946/* Set longcall attributes on all functions declared when
14947 rs6000_default_long_calls is true. */
14948static void
a2369ed3 14949rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
14950{
14951 if (rs6000_default_long_calls
14952 && (TREE_CODE (type) == FUNCTION_TYPE
14953 || TREE_CODE (type) == METHOD_TYPE))
14954 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
14955 NULL_TREE,
14956 TYPE_ATTRIBUTES (type));
14957}
14958
3cb999d8
DE
14959/* Return a reference suitable for calling a function with the
14960 longcall attribute. */
a4f6c312 14961
6a4cee5f 14962struct rtx_def *
a2369ed3 14963rs6000_longcall_ref (rtx call_ref)
6a4cee5f 14964{
d330fd93 14965 const char *call_name;
6a4cee5f
MM
14966 tree node;
14967
14968 if (GET_CODE (call_ref) != SYMBOL_REF)
14969 return call_ref;
14970
14971 /* System V adds '.' to the internal name, so skip them. */
14972 call_name = XSTR (call_ref, 0);
14973 if (*call_name == '.')
14974 {
14975 while (*call_name == '.')
14976 call_name++;
14977
14978 node = get_identifier (call_name);
39403d82 14979 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
14980 }
14981
14982 return force_reg (Pmode, call_ref);
14983}
7509c759 14984\f
b64a1b53
RH
14985#ifdef USING_ELFOS_H
14986
7509c759
MM
14987/* A C statement or statements to switch to the appropriate section
14988 for output of RTX in mode MODE. You can assume that RTX is some
14989 kind of constant in RTL. The argument MODE is redundant except in
14990 the case of a `const_int' rtx. Select the section by calling
14991 `text_section' or one of the alternatives for other sections.
14992
14993 Do not define this macro if you put all constants in the read-only
14994 data section. */
14995
b64a1b53 14996static void
a2369ed3
DJ
14997rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
14998 unsigned HOST_WIDE_INT align)
7509c759 14999{
a9098fd0 15000 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 15001 toc_section ();
7509c759 15002 else
b64a1b53 15003 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
15004}
15005
15006/* A C statement or statements to switch to the appropriate
15007 section for output of DECL. DECL is either a `VAR_DECL' node
15008 or a constant of some sort. RELOC indicates whether forming
15009 the initial value of DECL requires link-time relocations. */
15010
ae46c4e0 15011static void
a2369ed3
DJ
15012rs6000_elf_select_section (tree decl, int reloc,
15013 unsigned HOST_WIDE_INT align)
7509c759 15014{
f1384257
AM
15015 /* Pretend that we're always building for a shared library when
15016 ABI_AIX, because otherwise we end up with dynamic relocations
15017 in read-only sections. This happens for function pointers,
15018 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
15019 default_elf_select_section_1 (decl, reloc, align,
15020 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
15021}
15022
15023/* A C statement to build up a unique section name, expressed as a
15024 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
15025 RELOC indicates whether the initial value of EXP requires
15026 link-time relocations. If you do not define this macro, GCC will use
15027 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 15028 macro can now be called for uninitialized data items as well as
4912a07c 15029 initialized data and functions. */
63019373 15030
ae46c4e0 15031static void
a2369ed3 15032rs6000_elf_unique_section (tree decl, int reloc)
63019373 15033{
f1384257
AM
15034 /* As above, pretend that we're always building for a shared library
15035 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
15036 default_unique_section_1 (decl, reloc,
15037 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 15038}
d9407988 15039\f
d1908feb
JJ
15040/* For a SYMBOL_REF, set generic flags and then perform some
15041 target-specific processing.
15042
d1908feb
JJ
15043 When the AIX ABI is requested on a non-AIX system, replace the
15044 function name with the real name (with a leading .) rather than the
15045 function descriptor name. This saves a lot of overriding code to
15046 read the prefixes. */
d9407988 15047
fb49053f 15048static void
a2369ed3 15049rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 15050{
d1908feb 15051 default_encode_section_info (decl, rtl, first);
b2003250 15052
d1908feb
JJ
15053 if (first
15054 && TREE_CODE (decl) == FUNCTION_DECL
15055 && !TARGET_AIX
15056 && DEFAULT_ABI == ABI_AIX)
d9407988 15057 {
c6a2438a 15058 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
15059 size_t len = strlen (XSTR (sym_ref, 0));
15060 char *str = alloca (len + 2);
15061 str[0] = '.';
15062 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
15063 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 15064 }
d9407988
MM
15065}
15066
0e5dbd9b 15067static bool
a2369ed3 15068rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
15069{
15070 if (rs6000_sdata == SDATA_NONE)
15071 return false;
15072
15073 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
15074 {
15075 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
15076 if (strcmp (section, ".sdata") == 0
15077 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
15078 || strcmp (section, ".sbss") == 0
15079 || strcmp (section, ".sbss2") == 0
15080 || strcmp (section, ".PPC.EMB.sdata0") == 0
15081 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
15082 return true;
15083 }
15084 else
15085 {
15086 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
15087
15088 if (size > 0
307b599c 15089 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
15090 /* If it's not public, and we're not going to reference it there,
15091 there's no need to put it in the small data section. */
0e5dbd9b
DE
15092 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
15093 return true;
15094 }
15095
15096 return false;
15097}
15098
b91da81f 15099#endif /* USING_ELFOS_H */
000034eb 15100
a6c2a102 15101\f
000034eb 15102/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
15103 ADDR can be effectively incremented by incrementing REG.
15104
15105 r0 is special and we must not select it as an address
15106 register by this routine since our caller will try to
15107 increment the returned register via an "la" instruction. */
000034eb
DE
15108
15109struct rtx_def *
a2369ed3 15110find_addr_reg (rtx addr)
000034eb
DE
15111{
15112 while (GET_CODE (addr) == PLUS)
15113 {
02441cd6
JL
15114 if (GET_CODE (XEXP (addr, 0)) == REG
15115 && REGNO (XEXP (addr, 0)) != 0)
000034eb 15116 addr = XEXP (addr, 0);
02441cd6
JL
15117 else if (GET_CODE (XEXP (addr, 1)) == REG
15118 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
15119 addr = XEXP (addr, 1);
15120 else if (CONSTANT_P (XEXP (addr, 0)))
15121 addr = XEXP (addr, 1);
15122 else if (CONSTANT_P (XEXP (addr, 1)))
15123 addr = XEXP (addr, 0);
15124 else
15125 abort ();
15126 }
02441cd6 15127 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
15128 return addr;
15129 abort ();
15130}
15131
a6c2a102 15132void
a2369ed3 15133rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
15134{
15135 fatal_insn ("bad address", op);
15136}
c8023011 15137
ee890fe2
SS
15138#if TARGET_MACHO
15139
15140#if 0
15141/* Returns 1 if OP is either a symbol reference or a sum of a symbol
15142 reference and a constant. */
15143
15144int
a2369ed3 15145symbolic_operand (rtx op)
ee890fe2
SS
15146{
15147 switch (GET_CODE (op))
15148 {
15149 case SYMBOL_REF:
15150 case LABEL_REF:
15151 return 1;
15152 case CONST:
15153 op = XEXP (op, 0);
15154 return (GET_CODE (op) == SYMBOL_REF ||
15155 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
15156 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
15157 && GET_CODE (XEXP (op, 1)) == CONST_INT);
15158 default:
15159 return 0;
15160 }
c8023011 15161}
ee890fe2
SS
15162#endif
15163
efdba735 15164#if TARGET_MACHO
ee890fe2 15165
efdba735 15166static tree branch_island_list = 0;
ee890fe2 15167
efdba735
SH
15168/* Remember to generate a branch island for far calls to the given
15169 function. */
ee890fe2 15170
efdba735
SH
15171static void
15172add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 15173{
efdba735
SH
15174 tree branch_island = build_tree_list (function_name, label_name);
15175 TREE_TYPE (branch_island) = build_int_2 (line_number, 0);
15176 TREE_CHAIN (branch_island) = branch_island_list;
15177 branch_island_list = branch_island;
ee890fe2
SS
15178}
15179
efdba735
SH
15180#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
15181#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
15182#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
15183 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 15184
efdba735
SH
15185/* Generate far-jump branch islands for everything on the
15186 branch_island_list. Invoked immediately after the last instruction
15187 of the epilogue has been emitted; the branch-islands must be
15188 appended to, and contiguous with, the function body. Mach-O stubs
15189 are generated in machopic_output_stub(). */
ee890fe2 15190
efdba735
SH
15191static void
15192macho_branch_islands (void)
15193{
15194 char tmp_buf[512];
15195 tree branch_island;
15196
15197 for (branch_island = branch_island_list;
15198 branch_island;
15199 branch_island = TREE_CHAIN (branch_island))
15200 {
15201 const char *label =
15202 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
15203 const char *name =
15204 darwin_strip_name_encoding (
15205 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)));
15206 char name_buf[512];
15207 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
15208 if (name[0] == '*' || name[0] == '&')
15209 strcpy (name_buf, name+1);
15210 else
15211 {
15212 name_buf[0] = '_';
15213 strcpy (name_buf+1, name);
15214 }
15215 strcpy (tmp_buf, "\n");
15216 strcat (tmp_buf, label);
ee890fe2 15217#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15218 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15219 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15220 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 15221#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
15222 if (flag_pic)
15223 {
15224 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
15225 strcat (tmp_buf, label);
15226 strcat (tmp_buf, "_pic\n");
15227 strcat (tmp_buf, label);
15228 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
15229
15230 strcat (tmp_buf, "\taddis r11,r11,ha16(");
15231 strcat (tmp_buf, name_buf);
15232 strcat (tmp_buf, " - ");
15233 strcat (tmp_buf, label);
15234 strcat (tmp_buf, "_pic)\n");
15235
15236 strcat (tmp_buf, "\tmtlr r0\n");
15237
15238 strcat (tmp_buf, "\taddi r12,r11,lo16(");
15239 strcat (tmp_buf, name_buf);
15240 strcat (tmp_buf, " - ");
15241 strcat (tmp_buf, label);
15242 strcat (tmp_buf, "_pic)\n");
15243
15244 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
15245 }
15246 else
15247 {
15248 strcat (tmp_buf, ":\nlis r12,hi16(");
15249 strcat (tmp_buf, name_buf);
15250 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
15251 strcat (tmp_buf, name_buf);
15252 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
15253 }
15254 output_asm_insn (tmp_buf, 0);
ee890fe2 15255#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 15256 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 15257 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 15258 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 15259#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 15260 }
ee890fe2 15261
efdba735 15262 branch_island_list = 0;
ee890fe2
SS
15263}
15264
15265/* NO_PREVIOUS_DEF checks in the link list whether the function name is
15266 already there or not. */
15267
efdba735 15268static int
a2369ed3 15269no_previous_def (tree function_name)
ee890fe2 15270{
efdba735
SH
15271 tree branch_island;
15272 for (branch_island = branch_island_list;
15273 branch_island;
15274 branch_island = TREE_CHAIN (branch_island))
15275 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
15276 return 0;
15277 return 1;
15278}
15279
15280/* GET_PREV_LABEL gets the label name from the previous definition of
15281 the function. */
15282
efdba735 15283static tree
a2369ed3 15284get_prev_label (tree function_name)
ee890fe2 15285{
efdba735
SH
15286 tree branch_island;
15287 for (branch_island = branch_island_list;
15288 branch_island;
15289 branch_island = TREE_CHAIN (branch_island))
15290 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
15291 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
15292 return 0;
15293}
15294
15295/* INSN is either a function call or a millicode call. It may have an
15296 unconditional jump in its delay slot.
15297
15298 CALL_DEST is the routine we are calling. */
15299
15300char *
efdba735 15301output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
15302{
15303 static char buf[256];
efdba735
SH
15304 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
15305 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
15306 {
15307 tree labelname;
efdba735 15308 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
ee890fe2
SS
15309
15310 if (no_previous_def (funname))
15311 {
308c142a 15312 int line_number = 0;
ee890fe2
SS
15313 rtx label_rtx = gen_label_rtx ();
15314 char *label_buf, temp_buf[256];
15315 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
15316 CODE_LABEL_NUMBER (label_rtx));
15317 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
15318 labelname = get_identifier (label_buf);
15319 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
15320 if (insn)
15321 line_number = NOTE_LINE_NUMBER (insn);
efdba735 15322 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
15323 }
15324 else
15325 labelname = get_prev_label (funname);
15326
efdba735
SH
15327 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
15328 instruction will reach 'foo', otherwise link as 'bl L42'".
15329 "L42" should be a 'branch island', that will do a far jump to
15330 'foo'. Branch islands are generated in
15331 macho_branch_islands(). */
ee890fe2 15332 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 15333 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
15334 }
15335 else
efdba735
SH
15336 sprintf (buf, "bl %%z%d", dest_operand_number);
15337 return buf;
ee890fe2
SS
15338}
15339
efdba735 15340#endif /* TARGET_MACHO */
ee890fe2 15341
ee890fe2
SS
15342/* Generate PIC and indirect symbol stubs. */
15343
15344void
a2369ed3 15345machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
15346{
15347 unsigned int length;
a4f6c312
SS
15348 char *symbol_name, *lazy_ptr_name;
15349 char *local_label_0;
ee890fe2
SS
15350 static int label = 0;
15351
df56a27f 15352 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 15353 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 15354
ee890fe2 15355
ee890fe2
SS
15356 length = strlen (symb);
15357 symbol_name = alloca (length + 32);
15358 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
15359
15360 lazy_ptr_name = alloca (length + 32);
15361 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
15362
ee890fe2 15363 if (flag_pic == 2)
d3c300d2 15364 machopic_picsymbol_stub1_section ();
ee890fe2 15365 else
d3c300d2
DJ
15366 machopic_symbol_stub1_section ();
15367 fprintf (file, "\t.align 2\n");
ee890fe2
SS
15368
15369 fprintf (file, "%s:\n", stub);
15370 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15371
15372 if (flag_pic == 2)
15373 {
876455fa
AP
15374 label++;
15375 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
15376 sprintf (local_label_0, "\"L%011d$spb\"", label);
15377
ee890fe2
SS
15378 fprintf (file, "\tmflr r0\n");
15379 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
15380 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
15381 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
15382 lazy_ptr_name, local_label_0);
15383 fprintf (file, "\tmtlr r0\n");
d3c300d2 15384 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
15385 lazy_ptr_name, local_label_0);
15386 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
15387 fprintf (file, "\tbctr\n");
15388 }
15389 else
ab82a49f
AP
15390 {
15391 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
15392 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
15393 fprintf (file, "\tmtctr r12\n");
15394 fprintf (file, "\tbctr\n");
15395 }
ee890fe2
SS
15396
15397 machopic_lazy_symbol_ptr_section ();
15398 fprintf (file, "%s:\n", lazy_ptr_name);
15399 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15400 fprintf (file, "\t.long dyld_stub_binding_helper\n");
15401}
15402
15403/* Legitimize PIC addresses. If the address is already
15404 position-independent, we return ORIG. Newly generated
15405 position-independent addresses go into a reg. This is REG if non
15406 zero, otherwise we allocate register(s) as necessary. */
15407
c859cda6 15408#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
15409
15410rtx
a2369ed3
DJ
15411rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
15412 rtx reg)
ee890fe2
SS
15413{
15414 rtx base, offset;
15415
15416 if (reg == NULL && ! reload_in_progress && ! reload_completed)
15417 reg = gen_reg_rtx (Pmode);
15418
15419 if (GET_CODE (orig) == CONST)
15420 {
15421 if (GET_CODE (XEXP (orig, 0)) == PLUS
15422 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
15423 return orig;
15424
15425 if (GET_CODE (XEXP (orig, 0)) == PLUS)
15426 {
2cf520bf 15427 /* Use a different reg for the intermediate value, as
a3c9585f 15428 it will be marked UNCHANGING. */
2cf520bf
GK
15429 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
15430
a4f6c312
SS
15431 base =
15432 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 15433 Pmode, reg_temp);
a4f6c312
SS
15434 offset =
15435 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
15436 Pmode, reg);
ee890fe2
SS
15437 }
15438 else
15439 abort ();
15440
15441 if (GET_CODE (offset) == CONST_INT)
15442 {
15443 if (SMALL_INT (offset))
ed8908e7 15444 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
15445 else if (! reload_in_progress && ! reload_completed)
15446 offset = force_reg (Pmode, offset);
15447 else
c859cda6
DJ
15448 {
15449 rtx mem = force_const_mem (Pmode, orig);
15450 return machopic_legitimize_pic_address (mem, Pmode, reg);
15451 }
ee890fe2 15452 }
f1c25d3b 15453 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
15454 }
15455
15456 /* Fall back on generic machopic code. */
15457 return machopic_legitimize_pic_address (orig, mode, reg);
15458}
15459
15460/* This is just a placeholder to make linking work without having to
15461 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
15462 ever needed for Darwin (not too likely!) this would have to get a
15463 real definition. */
15464
15465void
863d938c 15466toc_section (void)
ee890fe2
SS
15467{
15468}
15469
15470#endif /* TARGET_MACHO */
7c262518
RH
15471
15472#if TARGET_ELF
15473static unsigned int
a2369ed3 15474rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 15475{
1ff8f81a
AM
15476 return default_section_type_flags_1 (decl, name, reloc,
15477 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 15478}
d9f6800d
RH
15479
15480/* Record an element in the table of global constructors. SYMBOL is
15481 a SYMBOL_REF of the function to be called; PRIORITY is a number
15482 between 0 and MAX_INIT_PRIORITY.
15483
15484 This differs from default_named_section_asm_out_constructor in
15485 that we have special handling for -mrelocatable. */
15486
15487static void
a2369ed3 15488rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
15489{
15490 const char *section = ".ctors";
15491 char buf[16];
15492
15493 if (priority != DEFAULT_INIT_PRIORITY)
15494 {
15495 sprintf (buf, ".ctors.%.5u",
15496 /* Invert the numbering so the linker puts us in the proper
15497 order; constructors are run from right to left, and the
15498 linker sorts in increasing order. */
15499 MAX_INIT_PRIORITY - priority);
15500 section = buf;
15501 }
15502
715bdd29
RH
15503 named_section_flags (section, SECTION_WRITE);
15504 assemble_align (POINTER_SIZE);
d9f6800d
RH
15505
15506 if (TARGET_RELOCATABLE)
15507 {
15508 fputs ("\t.long (", asm_out_file);
15509 output_addr_const (asm_out_file, symbol);
15510 fputs (")@fixup\n", asm_out_file);
15511 }
15512 else
c8af3574 15513 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
15514}
15515
15516static void
a2369ed3 15517rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
15518{
15519 const char *section = ".dtors";
15520 char buf[16];
15521
15522 if (priority != DEFAULT_INIT_PRIORITY)
15523 {
15524 sprintf (buf, ".dtors.%.5u",
15525 /* Invert the numbering so the linker puts us in the proper
15526 order; constructors are run from right to left, and the
15527 linker sorts in increasing order. */
15528 MAX_INIT_PRIORITY - priority);
15529 section = buf;
15530 }
15531
715bdd29
RH
15532 named_section_flags (section, SECTION_WRITE);
15533 assemble_align (POINTER_SIZE);
d9f6800d
RH
15534
15535 if (TARGET_RELOCATABLE)
15536 {
15537 fputs ("\t.long (", asm_out_file);
15538 output_addr_const (asm_out_file, symbol);
15539 fputs (")@fixup\n", asm_out_file);
15540 }
15541 else
c8af3574 15542 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 15543}
9739c90c
JJ
15544
15545void
a2369ed3 15546rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
15547{
15548 if (TARGET_64BIT)
15549 {
15550 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
15551 ASM_OUTPUT_LABEL (file, name);
15552 fputs (DOUBLE_INT_ASM_OP, file);
15553 putc ('.', file);
15554 assemble_name (file, name);
15555 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
15556 assemble_name (file, name);
15557 fputs (",24\n\t.type\t.", file);
15558 assemble_name (file, name);
15559 fputs (",@function\n", file);
15560 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
15561 {
15562 fputs ("\t.globl\t.", file);
15563 assemble_name (file, name);
15564 putc ('\n', file);
15565 }
15566 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15567 putc ('.', file);
15568 ASM_OUTPUT_LABEL (file, name);
15569 return;
15570 }
15571
15572 if (TARGET_RELOCATABLE
15573 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 15574 && uses_TOC ())
9739c90c
JJ
15575 {
15576 char buf[256];
15577
15578 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
15579
15580 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
15581 fprintf (file, "\t.long ");
15582 assemble_name (file, buf);
15583 putc ('-', file);
15584 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
15585 assemble_name (file, buf);
15586 putc ('\n', file);
15587 }
15588
15589 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
15590 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15591
15592 if (DEFAULT_ABI == ABI_AIX)
15593 {
15594 const char *desc_name, *orig_name;
15595
15596 orig_name = (*targetm.strip_name_encoding) (name);
15597 desc_name = orig_name;
15598 while (*desc_name == '.')
15599 desc_name++;
15600
15601 if (TREE_PUBLIC (decl))
15602 fprintf (file, "\t.globl %s\n", desc_name);
15603
15604 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
15605 fprintf (file, "%s:\n", desc_name);
15606 fprintf (file, "\t.long %s\n", orig_name);
15607 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
15608 if (DEFAULT_ABI == ABI_AIX)
15609 fputs ("\t.long 0\n", file);
15610 fprintf (file, "\t.previous\n");
15611 }
15612 ASM_OUTPUT_LABEL (file, name);
15613}
7c262518
RH
15614#endif
15615
cbaaba19 15616#if TARGET_XCOFF
7c262518 15617static void
a2369ed3 15618rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
15619{
15620 fputs (GLOBAL_ASM_OP, stream);
15621 RS6000_OUTPUT_BASENAME (stream, name);
15622 putc ('\n', stream);
15623}
15624
15625static void
a2369ed3 15626rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 15627{
0e5dbd9b
DE
15628 int smclass;
15629 static const char * const suffix[3] = { "PR", "RO", "RW" };
15630
15631 if (flags & SECTION_CODE)
15632 smclass = 0;
15633 else if (flags & SECTION_WRITE)
15634 smclass = 2;
15635 else
15636 smclass = 1;
15637
5b5198f7 15638 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 15639 (flags & SECTION_CODE) ? "." : "",
5b5198f7 15640 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 15641}
ae46c4e0
RH
15642
15643static void
a2369ed3
DJ
15644rs6000_xcoff_select_section (tree decl, int reloc,
15645 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 15646{
5add3202 15647 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 15648 {
0e5dbd9b 15649 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15650 read_only_data_section ();
15651 else
15652 read_only_private_data_section ();
15653 }
15654 else
15655 {
0e5dbd9b 15656 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15657 data_section ();
15658 else
15659 private_data_section ();
15660 }
15661}
15662
15663static void
a2369ed3 15664rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
15665{
15666 const char *name;
ae46c4e0 15667
5b5198f7
DE
15668 /* Use select_section for private and uninitialized data. */
15669 if (!TREE_PUBLIC (decl)
15670 || DECL_COMMON (decl)
0e5dbd9b
DE
15671 || DECL_INITIAL (decl) == NULL_TREE
15672 || DECL_INITIAL (decl) == error_mark_node
15673 || (flag_zero_initialized_in_bss
15674 && initializer_zerop (DECL_INITIAL (decl))))
15675 return;
15676
15677 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15678 name = (*targetm.strip_name_encoding) (name);
15679 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 15680}
b64a1b53 15681
fb49053f
RH
15682/* Select section for constant in constant pool.
15683
15684 On RS/6000, all constants are in the private read-only data area.
15685 However, if this is being placed in the TOC it must be output as a
15686 toc entry. */
15687
b64a1b53 15688static void
a2369ed3
DJ
15689rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
15690 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
15691{
15692 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
15693 toc_section ();
15694 else
15695 read_only_private_data_section ();
15696}
772c5265
RH
15697
15698/* Remove any trailing [DS] or the like from the symbol name. */
15699
15700static const char *
a2369ed3 15701rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
15702{
15703 size_t len;
15704 if (*name == '*')
15705 name++;
15706 len = strlen (name);
15707 if (name[len - 1] == ']')
15708 return ggc_alloc_string (name, len - 4);
15709 else
15710 return name;
15711}
15712
5add3202
DE
15713/* Section attributes. AIX is always PIC. */
15714
15715static unsigned int
a2369ed3 15716rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 15717{
5b5198f7
DE
15718 unsigned int align;
15719 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
15720
15721 /* Align to at least UNIT size. */
15722 if (flags & SECTION_CODE)
15723 align = MIN_UNITS_PER_WORD;
15724 else
15725 /* Increase alignment of large objects if not already stricter. */
15726 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
15727 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
15728 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
15729
15730 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 15731}
a5fe455b 15732
1bc7c5b6
ZW
15733/* Output at beginning of assembler file.
15734
15735 Initialize the section names for the RS/6000 at this point.
15736
15737 Specify filename, including full path, to assembler.
15738
15739 We want to go into the TOC section so at least one .toc will be emitted.
15740 Also, in order to output proper .bs/.es pairs, we need at least one static
15741 [RW] section emitted.
15742
15743 Finally, declare mcount when profiling to make the assembler happy. */
15744
15745static void
863d938c 15746rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
15747{
15748 rs6000_gen_section_name (&xcoff_bss_section_name,
15749 main_input_filename, ".bss_");
15750 rs6000_gen_section_name (&xcoff_private_data_section_name,
15751 main_input_filename, ".rw_");
15752 rs6000_gen_section_name (&xcoff_read_only_section_name,
15753 main_input_filename, ".ro_");
15754
15755 fputs ("\t.file\t", asm_out_file);
15756 output_quoted_string (asm_out_file, main_input_filename);
15757 fputc ('\n', asm_out_file);
15758 toc_section ();
15759 if (write_symbols != NO_DEBUG)
15760 private_data_section ();
15761 text_section ();
15762 if (profile_flag)
15763 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
15764 rs6000_file_start ();
15765}
15766
a5fe455b
ZW
15767/* Output at end of assembler file.
15768 On the RS/6000, referencing data should automatically pull in text. */
15769
15770static void
863d938c 15771rs6000_xcoff_file_end (void)
a5fe455b
ZW
15772{
15773 text_section ();
15774 fputs ("_section_.text:\n", asm_out_file);
15775 data_section ();
15776 fputs (TARGET_32BIT
15777 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
15778 asm_out_file);
15779}
f1384257 15780#endif /* TARGET_XCOFF */
0e5dbd9b 15781
f1384257
AM
15782#if TARGET_MACHO
15783/* Cross-module name binding. Darwin does not support overriding
7f3d8013 15784 functions at dynamic-link time. */
0e5dbd9b 15785
2bcc50d0 15786static bool
a2369ed3 15787rs6000_binds_local_p (tree decl)
0e5dbd9b 15788{
f1384257 15789 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 15790}
f1384257 15791#endif
34bb030a 15792
3c50106f
RH
15793/* Compute a (partial) cost for rtx X. Return true if the complete
15794 cost has been computed, and false if subexpressions should be
15795 scanned. In either case, *TOTAL contains the cost result. */
15796
15797static bool
a2369ed3
DJ
15798rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
15799 int *total)
3c50106f
RH
15800{
15801 switch (code)
15802 {
15803 /* On the RS/6000, if it is valid in the insn, it is free.
15804 So this always returns 0. */
15805 case CONST_INT:
15806 case CONST:
15807 case LABEL_REF:
15808 case SYMBOL_REF:
15809 case CONST_DOUBLE:
15810 case HIGH:
15811 *total = 0;
15812 return true;
15813
15814 case PLUS:
15815 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15816 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
15817 + 0x8000) >= 0x10000)
15818 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15819 ? COSTS_N_INSNS (2)
15820 : COSTS_N_INSNS (1));
15821 return true;
15822
15823 case AND:
15824 case IOR:
15825 case XOR:
15826 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15827 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
15828 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15829 ? COSTS_N_INSNS (2)
15830 : COSTS_N_INSNS (1));
15831 return true;
15832
15833 case MULT:
15834 if (optimize_size)
15835 {
15836 *total = COSTS_N_INSNS (2);
15837 return true;
15838 }
15839 switch (rs6000_cpu)
15840 {
15841 case PROCESSOR_RIOS1:
15842 case PROCESSOR_PPC405:
15843 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15844 ? COSTS_N_INSNS (5)
15845 : (INTVAL (XEXP (x, 1)) >= -256
15846 && INTVAL (XEXP (x, 1)) <= 255)
15847 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15848 return true;
15849
02ca7595
DE
15850 case PROCESSOR_PPC440:
15851 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15852 ? COSTS_N_INSNS (3)
15853 : COSTS_N_INSNS (2));
15854 return true;
15855
3c50106f
RH
15856 case PROCESSOR_RS64A:
15857 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15858 ? GET_MODE (XEXP (x, 1)) != DImode
15859 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
15860 : (INTVAL (XEXP (x, 1)) >= -256
15861 && INTVAL (XEXP (x, 1)) <= 255)
15862 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
15863 return true;
15864
15865 case PROCESSOR_RIOS2:
15866 case PROCESSOR_MPCCORE:
15867 case PROCESSOR_PPC604e:
15868 *total = COSTS_N_INSNS (2);
15869 return true;
15870
15871 case PROCESSOR_PPC601:
15872 *total = COSTS_N_INSNS (5);
15873 return true;
15874
15875 case PROCESSOR_PPC603:
15876 case PROCESSOR_PPC7400:
15877 case PROCESSOR_PPC750:
15878 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15879 ? COSTS_N_INSNS (5)
15880 : (INTVAL (XEXP (x, 1)) >= -256
15881 && INTVAL (XEXP (x, 1)) <= 255)
15882 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
15883 return true;
15884
15885 case PROCESSOR_PPC7450:
15886 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15887 ? COSTS_N_INSNS (4)
15888 : COSTS_N_INSNS (3));
15889 return true;
15890
15891 case PROCESSOR_PPC403:
15892 case PROCESSOR_PPC604:
15893 case PROCESSOR_PPC8540:
15894 *total = COSTS_N_INSNS (4);
15895 return true;
15896
15897 case PROCESSOR_PPC620:
15898 case PROCESSOR_PPC630:
3c50106f
RH
15899 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15900 ? GET_MODE (XEXP (x, 1)) != DImode
15901 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
15902 : (INTVAL (XEXP (x, 1)) >= -256
15903 && INTVAL (XEXP (x, 1)) <= 255)
15904 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15905 return true;
15906
9259f3b0
DE
15907 case PROCESSOR_POWER4:
15908 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15909 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
15910 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
15911 : COSTS_N_INSNS (2));
9259f3b0
DE
15912 return true;
15913
3c50106f
RH
15914 default:
15915 abort ();
15916 }
15917
15918 case DIV:
15919 case MOD:
15920 if (GET_CODE (XEXP (x, 1)) == CONST_INT
15921 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
15922 {
15923 *total = COSTS_N_INSNS (2);
15924 return true;
15925 }
5efb1046 15926 /* FALLTHRU */
3c50106f
RH
15927
15928 case UDIV:
15929 case UMOD:
15930 switch (rs6000_cpu)
15931 {
15932 case PROCESSOR_RIOS1:
15933 *total = COSTS_N_INSNS (19);
15934 return true;
15935
15936 case PROCESSOR_RIOS2:
15937 *total = COSTS_N_INSNS (13);
15938 return true;
15939
15940 case PROCESSOR_RS64A:
15941 *total = (GET_MODE (XEXP (x, 1)) != DImode
15942 ? COSTS_N_INSNS (65)
15943 : COSTS_N_INSNS (67));
15944 return true;
15945
15946 case PROCESSOR_MPCCORE:
15947 *total = COSTS_N_INSNS (6);
15948 return true;
15949
15950 case PROCESSOR_PPC403:
15951 *total = COSTS_N_INSNS (33);
15952 return true;
15953
15954 case PROCESSOR_PPC405:
15955 *total = COSTS_N_INSNS (35);
15956 return true;
15957
02ca7595
DE
15958 case PROCESSOR_PPC440:
15959 *total = COSTS_N_INSNS (34);
15960 return true;
15961
3c50106f
RH
15962 case PROCESSOR_PPC601:
15963 *total = COSTS_N_INSNS (36);
15964 return true;
15965
15966 case PROCESSOR_PPC603:
15967 *total = COSTS_N_INSNS (37);
15968 return true;
15969
15970 case PROCESSOR_PPC604:
15971 case PROCESSOR_PPC604e:
15972 *total = COSTS_N_INSNS (20);
15973 return true;
15974
15975 case PROCESSOR_PPC620:
15976 case PROCESSOR_PPC630:
3c50106f
RH
15977 *total = (GET_MODE (XEXP (x, 1)) != DImode
15978 ? COSTS_N_INSNS (21)
15979 : COSTS_N_INSNS (37));
15980 return true;
15981
15982 case PROCESSOR_PPC750:
15983 case PROCESSOR_PPC8540:
15984 case PROCESSOR_PPC7400:
15985 *total = COSTS_N_INSNS (19);
15986 return true;
15987
15988 case PROCESSOR_PPC7450:
15989 *total = COSTS_N_INSNS (23);
15990 return true;
984e25ac
DE
15991
15992 case PROCESSOR_POWER4:
15993 *total = (GET_MODE (XEXP (x, 1)) != DImode
15994 ? COSTS_N_INSNS (18)
15995 : COSTS_N_INSNS (34));
15996 return true;
3c50106f
RH
15997
15998 default:
15999 abort ();
16000 }
16001
16002 case FFS:
16003 *total = COSTS_N_INSNS (4);
16004 return true;
16005
16006 case MEM:
a3c9585f 16007 /* MEM should be slightly more expensive than (plus (reg) (const)). */
3c50106f
RH
16008 *total = 5;
16009 return true;
16010
16011 default:
16012 return false;
16013 }
16014}
16015
34bb030a
DE
16016/* A C expression returning the cost of moving data from a register of class
16017 CLASS1 to one of CLASS2. */
16018
16019int
a2369ed3
DJ
16020rs6000_register_move_cost (enum machine_mode mode,
16021 enum reg_class from, enum reg_class to)
34bb030a
DE
16022{
16023 /* Moves from/to GENERAL_REGS. */
16024 if (reg_classes_intersect_p (to, GENERAL_REGS)
16025 || reg_classes_intersect_p (from, GENERAL_REGS))
16026 {
16027 if (! reg_classes_intersect_p (to, GENERAL_REGS))
16028 from = to;
16029
16030 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
16031 return (rs6000_memory_move_cost (mode, from, 0)
16032 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
16033
a3c9585f 16034/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
16035 else if (from == CR_REGS)
16036 return 4;
16037
16038 else
16039/* A move will cost one instruction per GPR moved. */
16040 return 2 * HARD_REGNO_NREGS (0, mode);
16041 }
16042
16043/* Moving between two similar registers is just one instruction. */
16044 else if (reg_classes_intersect_p (to, from))
16045 return mode == TFmode ? 4 : 2;
16046
16047/* Everything else has to go through GENERAL_REGS. */
16048 else
16049 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
16050 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
16051}
16052
16053/* A C expressions returning the cost of moving data of MODE from a register to
16054 or from memory. */
16055
16056int
a2369ed3
DJ
16057rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
16058 int in ATTRIBUTE_UNUSED)
34bb030a
DE
16059{
16060 if (reg_classes_intersect_p (class, GENERAL_REGS))
16061 return 4 * HARD_REGNO_NREGS (0, mode);
16062 else if (reg_classes_intersect_p (class, FLOAT_REGS))
16063 return 4 * HARD_REGNO_NREGS (32, mode);
16064 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
16065 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
16066 else
16067 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
16068}
16069
ded9bf77
AH
16070/* Return an RTX representing where to find the function value of a
16071 function returning MODE. */
16072static rtx
16073rs6000_complex_function_value (enum machine_mode mode)
16074{
16075 unsigned int regno;
16076 rtx r1, r2;
16077 enum machine_mode inner = GET_MODE_INNER (mode);
fb7e4164 16078 unsigned int inner_bytes = GET_MODE_SIZE (inner);
ded9bf77
AH
16079
16080 if (FLOAT_MODE_P (mode))
16081 regno = FP_ARG_RETURN;
16082 else
16083 {
16084 regno = GP_ARG_RETURN;
16085
16086 /* 32-bit is OK since it'll go in r3/r4. */
fb7e4164 16087 if (TARGET_32BIT && inner_bytes >= 4)
ded9bf77
AH
16088 return gen_rtx_REG (mode, regno);
16089 }
16090
fb7e4164
AM
16091 if (inner_bytes >= 8)
16092 return gen_rtx_REG (mode, regno);
16093
ded9bf77
AH
16094 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
16095 const0_rtx);
16096 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
fb7e4164 16097 GEN_INT (inner_bytes));
ded9bf77
AH
16098 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
16099}
16100
a6ebc39a
AH
16101/* Define how to find the value returned by a function.
16102 VALTYPE is the data type of the value (as a tree).
16103 If the precise function being called is known, FUNC is its FUNCTION_DECL;
16104 otherwise, FUNC is 0.
16105
16106 On the SPE, both FPs and vectors are returned in r3.
16107
16108 On RS/6000 an integer value is in r3 and a floating-point value is in
16109 fp1, unless -msoft-float. */
16110
16111rtx
16112rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
16113{
16114 enum machine_mode mode;
2a8fa26c 16115 unsigned int regno;
a6ebc39a 16116
0e67400a
FJ
16117 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
16118 {
16119 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
16120 return gen_rtx_PARALLEL (DImode,
16121 gen_rtvec (2,
16122 gen_rtx_EXPR_LIST (VOIDmode,
16123 gen_rtx_REG (SImode, GP_ARG_RETURN),
16124 const0_rtx),
16125 gen_rtx_EXPR_LIST (VOIDmode,
16126 gen_rtx_REG (SImode,
16127 GP_ARG_RETURN + 1),
16128 GEN_INT (4))));
16129 }
16130
a6ebc39a
AH
16131 if ((INTEGRAL_TYPE_P (valtype)
16132 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
16133 || POINTER_TYPE_P (valtype))
b78d48dd 16134 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
16135 else
16136 mode = TYPE_MODE (valtype);
16137
2a8fa26c
DE
16138 if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS)
16139 regno = FP_ARG_RETURN;
ded9bf77
AH
16140 else if (TREE_CODE (valtype) == COMPLEX_TYPE
16141 && TARGET_HARD_FLOAT
42ba5130 16142 && targetm.calls.split_complex_arg)
ded9bf77 16143 return rs6000_complex_function_value (mode);
2a8fa26c 16144 else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC)
a6ebc39a
AH
16145 regno = ALTIVEC_ARG_RETURN;
16146 else
16147 regno = GP_ARG_RETURN;
16148
16149 return gen_rtx_REG (mode, regno);
16150}
16151
ded9bf77
AH
16152/* Define how to find the value returned by a library function
16153 assuming the value has mode MODE. */
16154rtx
16155rs6000_libcall_value (enum machine_mode mode)
16156{
16157 unsigned int regno;
16158
16159 if (GET_MODE_CLASS (mode) == MODE_FLOAT
16160 && TARGET_HARD_FLOAT && TARGET_FPRS)
16161 regno = FP_ARG_RETURN;
16162 else if (ALTIVEC_VECTOR_MODE (mode))
16163 regno = ALTIVEC_ARG_RETURN;
42ba5130 16164 else if (COMPLEX_MODE_P (mode) && targetm.calls.split_complex_arg)
ded9bf77
AH
16165 return rs6000_complex_function_value (mode);
16166 else
16167 regno = GP_ARG_RETURN;
16168
16169 return gen_rtx_REG (mode, regno);
16170}
16171
d1d0c603
JJ
16172/* Define the offset between two registers, FROM to be eliminated and its
16173 replacement TO, at the start of a routine. */
16174HOST_WIDE_INT
16175rs6000_initial_elimination_offset (int from, int to)
16176{
16177 rs6000_stack_t *info = rs6000_stack_info ();
16178 HOST_WIDE_INT offset;
16179
16180 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16181 offset = info->push_p ? 0 : -info->total_size;
16182 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
16183 offset = info->total_size;
16184 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
16185 offset = info->push_p ? info->total_size : 0;
16186 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
16187 offset = 0;
16188 else
16189 abort ();
16190
16191 return offset;
16192}
16193
62e1dfcf
NC
16194/* Return true if TYPE is of type __ev64_opaque__. */
16195
c8e4f0e9 16196static bool
a2369ed3 16197is_ev64_opaque_type (tree type)
62e1dfcf 16198{
c8e4f0e9 16199 return (TARGET_SPE
2abe3e28
AH
16200 && (type == opaque_V2SI_type_node
16201 || type == opaque_V2SF_type_node
36252949 16202 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
16203}
16204
96714395 16205static rtx
a2369ed3 16206rs6000_dwarf_register_span (rtx reg)
96714395
AH
16207{
16208 unsigned regno;
16209
16210 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
16211 return NULL_RTX;
16212
16213 regno = REGNO (reg);
16214
16215 /* The duality of the SPE register size wreaks all kinds of havoc.
16216 This is a way of distinguishing r0 in 32-bits from r0 in
16217 64-bits. */
16218 return
16219 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
16220 BYTES_BIG_ENDIAN
16221 ? gen_rtvec (2,
16222 gen_rtx_REG (SImode, regno + 1200),
16223 gen_rtx_REG (SImode, regno))
16224 : gen_rtvec (2,
16225 gen_rtx_REG (SImode, regno),
16226 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
16227}
16228
93c9d1ba
AM
16229/* Map internal gcc register numbers to DWARF2 register numbers. */
16230
16231unsigned int
16232rs6000_dbx_register_number (unsigned int regno)
16233{
16234 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
16235 return regno;
16236 if (regno == MQ_REGNO)
16237 return 100;
16238 if (regno == LINK_REGISTER_REGNUM)
16239 return 108;
16240 if (regno == COUNT_REGISTER_REGNUM)
16241 return 109;
16242 if (CR_REGNO_P (regno))
16243 return regno - CR0_REGNO + 86;
16244 if (regno == XER_REGNO)
16245 return 101;
16246 if (ALTIVEC_REGNO_P (regno))
16247 return regno - FIRST_ALTIVEC_REGNO + 1124;
16248 if (regno == VRSAVE_REGNO)
16249 return 356;
16250 if (regno == VSCR_REGNO)
16251 return 67;
16252 if (regno == SPE_ACC_REGNO)
16253 return 99;
16254 if (regno == SPEFSCR_REGNO)
16255 return 612;
16256 /* SPE high reg number. We get these values of regno from
16257 rs6000_dwarf_register_span. */
16258 if (regno >= 1200 && regno < 1232)
16259 return regno;
16260
16261 abort ();
16262}
16263
17211ab5 16264#include "gt-rs6000.h"