]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
tm.texi (INIT_CUMULATIVE_ARGS): Update doco.
[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;
2abe3e28 219
57ac7be9
AM
220const char *rs6000_traceback_name;
221static enum {
222 traceback_default = 0,
223 traceback_none,
224 traceback_part,
225 traceback_full
226} rs6000_traceback;
227
38c1f2d7
MM
228/* Flag to say the TOC is initialized */
229int toc_initialized;
9ebbca7d 230char toc_label_name[10];
38c1f2d7 231
9ebbca7d 232/* Alias set for saves and restores from the rs6000 stack. */
f103e34d 233static GTY(()) int rs6000_sr_alias_set;
c8023011 234
a5c76ee6
ZW
235/* Call distance, overridden by -mlongcall and #pragma longcall(1).
236 The only place that looks at this is rs6000_set_default_type_attributes;
237 everywhere else should rely on the presence or absence of a longcall
238 attribute on the function declaration. */
239int rs6000_default_long_calls;
240const char *rs6000_longcall_switch;
241
a3c9585f
KH
242/* Control alignment for fields within structures. */
243/* String from -malign-XXXXX. */
025d9908
KH
244const char *rs6000_alignment_string;
245int rs6000_alignment_flags;
246
a3170dc6
AH
247struct builtin_description
248{
249 /* mask is not const because we're going to alter it below. This
250 nonsense will go away when we rewrite the -march infrastructure
251 to give us more target flag bits. */
252 unsigned int mask;
253 const enum insn_code icode;
254 const char *const name;
255 const enum rs6000_builtins code;
256};
257
a2369ed3
DJ
258static bool rs6000_function_ok_for_sibcall (tree, tree);
259static int num_insns_constant_wide (HOST_WIDE_INT);
260static void validate_condition_mode (enum rtx_code, enum machine_mode);
261static rtx rs6000_generate_compare (enum rtx_code);
262static void rs6000_maybe_dead (rtx);
263static void rs6000_emit_stack_tie (void);
264static void rs6000_frame_related (rtx, rtx, HOST_WIDE_INT, rtx, rtx);
265static rtx spe_synthesize_frame_save (rtx);
266static bool spe_func_has_64bit_regs_p (void);
b20a9cca 267static void emit_frame_save (rtx, rtx, enum machine_mode, unsigned int,
d1d0c603 268 int, HOST_WIDE_INT);
a2369ed3
DJ
269static rtx gen_frame_mem_offset (enum machine_mode, rtx, int);
270static void rs6000_emit_allocate_stack (HOST_WIDE_INT, int);
271static unsigned rs6000_hash_constant (rtx);
272static unsigned toc_hash_function (const void *);
273static int toc_hash_eq (const void *, const void *);
274static int constant_pool_expr_1 (rtx, int *, int *);
275static bool constant_pool_expr_p (rtx);
276static bool toc_relative_expr_p (rtx);
277static bool legitimate_small_data_p (enum machine_mode, rtx);
278static bool legitimate_offset_address_p (enum machine_mode, rtx, int);
279static bool legitimate_indexed_address_p (rtx, int);
280static bool legitimate_indirect_address_p (rtx, int);
4c81e946 281static bool macho_lo_sum_memory_operand (rtx x, enum machine_mode mode);
a2369ed3
DJ
282static bool legitimate_lo_sum_address_p (enum machine_mode, rtx, int);
283static struct machine_function * rs6000_init_machine_status (void);
284static bool rs6000_assemble_integer (rtx, unsigned int, int);
5add3202 285#ifdef HAVE_GAS_HIDDEN
a2369ed3 286static void rs6000_assemble_visibility (tree, int);
5add3202 287#endif
a2369ed3
DJ
288static int rs6000_ra_ever_killed (void);
289static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *);
b86fe7b4 290extern const struct attribute_spec rs6000_attribute_table[];
a2369ed3
DJ
291static void rs6000_set_default_type_attributes (tree);
292static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT);
293static void rs6000_output_function_epilogue (FILE *, HOST_WIDE_INT);
b20a9cca
AM
294static void rs6000_output_mi_thunk (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT,
295 tree);
a2369ed3 296static rtx rs6000_emit_set_long_const (rtx, HOST_WIDE_INT, HOST_WIDE_INT);
c6e8c921 297static bool rs6000_return_in_memory (tree, tree);
a2369ed3 298static void rs6000_file_start (void);
7c262518 299#if TARGET_ELF
a2369ed3
DJ
300static unsigned int rs6000_elf_section_type_flags (tree, const char *, int);
301static void rs6000_elf_asm_out_constructor (rtx, int);
302static void rs6000_elf_asm_out_destructor (rtx, int);
303static void rs6000_elf_select_section (tree, int, unsigned HOST_WIDE_INT);
304static void rs6000_elf_unique_section (tree, int);
305static void rs6000_elf_select_rtx_section (enum machine_mode, rtx,
b20a9cca 306 unsigned HOST_WIDE_INT);
a56d7372 307static void rs6000_elf_encode_section_info (tree, rtx, int)
0e5dbd9b 308 ATTRIBUTE_UNUSED;
a2369ed3 309static bool rs6000_elf_in_small_data_p (tree);
7c262518 310#endif
cbaaba19 311#if TARGET_XCOFF
a2369ed3
DJ
312static void rs6000_xcoff_asm_globalize_label (FILE *, const char *);
313static void rs6000_xcoff_asm_named_section (const char *, unsigned int);
314static void rs6000_xcoff_select_section (tree, int, unsigned HOST_WIDE_INT);
315static void rs6000_xcoff_unique_section (tree, int);
316static void rs6000_xcoff_select_rtx_section (enum machine_mode, rtx,
b20a9cca 317 unsigned HOST_WIDE_INT);
a2369ed3
DJ
318static const char * rs6000_xcoff_strip_name_encoding (const char *);
319static unsigned int rs6000_xcoff_section_type_flags (tree, const char *, int);
320static void rs6000_xcoff_file_start (void);
321static void rs6000_xcoff_file_end (void);
f1384257
AM
322#endif
323#if TARGET_MACHO
a2369ed3 324static bool rs6000_binds_local_p (tree);
f1384257 325#endif
a2369ed3
DJ
326static int rs6000_use_dfa_pipeline_interface (void);
327static int rs6000_variable_issue (FILE *, int, rtx, int);
328static bool rs6000_rtx_costs (rtx, int, int, int *);
329static int rs6000_adjust_cost (rtx, rtx, rtx, int);
cbe26ab8 330static bool is_microcoded_insn (rtx);
79ae11c4 331static int is_dispatch_slot_restricted (rtx);
cbe26ab8
DN
332static bool is_cracked_insn (rtx);
333static bool is_branch_slot_insn (rtx);
a2369ed3
DJ
334static int rs6000_adjust_priority (rtx, int);
335static int rs6000_issue_rate (void);
569fa502 336static bool rs6000_is_costly_dependence (rtx, rtx, rtx, int, int);
cbe26ab8
DN
337static rtx get_next_active_insn (rtx, rtx);
338static bool insn_terminates_group_p (rtx , enum group_termination);
339static bool is_costly_group (rtx *, rtx);
340static int force_new_group (int, FILE *, rtx *, rtx, bool *, int, int *);
341static int redefine_groups (FILE *, int, rtx, rtx);
342static int pad_groups (FILE *, int, rtx, rtx);
343static void rs6000_sched_finish (FILE *, int);
a2369ed3
DJ
344static int rs6000_use_sched_lookahead (void);
345
346static void rs6000_init_builtins (void);
347static rtx rs6000_expand_unop_builtin (enum insn_code, tree, rtx);
348static rtx rs6000_expand_binop_builtin (enum insn_code, tree, rtx);
349static rtx rs6000_expand_ternop_builtin (enum insn_code, tree, rtx);
350static rtx rs6000_expand_builtin (tree, rtx, rtx, enum machine_mode, int);
351static void altivec_init_builtins (void);
352static void rs6000_common_init_builtins (void);
c15c90bb 353static void rs6000_init_libfuncs (void);
a2369ed3 354
b20a9cca
AM
355static void enable_mask_for_builtins (struct builtin_description *, int,
356 enum rs6000_builtins,
357 enum rs6000_builtins);
a2369ed3
DJ
358static void spe_init_builtins (void);
359static rtx spe_expand_builtin (tree, rtx, bool *);
360static rtx spe_expand_predicate_builtin (enum insn_code, tree, rtx);
361static rtx spe_expand_evsel_builtin (enum insn_code, tree, rtx);
362static int rs6000_emit_int_cmove (rtx, rtx, rtx, rtx);
d1d0c603
JJ
363static rs6000_stack_t *rs6000_stack_info (void);
364static void debug_stack_info (rs6000_stack_t *);
a2369ed3
DJ
365
366static rtx altivec_expand_builtin (tree, rtx, bool *);
367static rtx altivec_expand_ld_builtin (tree, rtx, bool *);
368static rtx altivec_expand_st_builtin (tree, rtx, bool *);
369static rtx altivec_expand_dst_builtin (tree, rtx, bool *);
370static rtx altivec_expand_abs_builtin (enum insn_code, tree, rtx);
371static rtx altivec_expand_predicate_builtin (enum insn_code,
372 const char *, tree, rtx);
b4a62fa0 373static rtx altivec_expand_lv_builtin (enum insn_code, tree, rtx);
a2369ed3
DJ
374static rtx altivec_expand_stv_builtin (enum insn_code, tree);
375static void rs6000_parse_abi_options (void);
376static void rs6000_parse_alignment_option (void);
377static void rs6000_parse_tls_size_option (void);
5da702b1 378static void rs6000_parse_yes_no_option (const char *, const char *, int *);
a2369ed3
DJ
379static int first_altivec_reg_to_save (void);
380static unsigned int compute_vrsave_mask (void);
381static void is_altivec_return_reg (rtx, void *);
382static rtx generate_set_vrsave (rtx, rs6000_stack_t *, int);
383int easy_vector_constant (rtx, enum machine_mode);
384static int easy_vector_same (rtx, enum machine_mode);
385static bool is_ev64_opaque_type (tree);
386static rtx rs6000_dwarf_register_span (rtx);
387static rtx rs6000_legitimize_tls_address (rtx, enum tls_model);
388static rtx rs6000_tls_get_addr (void);
389static rtx rs6000_got_sym (void);
390static inline int rs6000_tls_symbol_ref_1 (rtx *, void *);
391static const char *rs6000_get_some_local_dynamic_name (void);
392static int rs6000_get_some_local_dynamic_name_1 (rtx *, void *);
ded9bf77 393static rtx rs6000_complex_function_value (enum machine_mode);
b20a9cca 394static rtx rs6000_spe_function_arg (CUMULATIVE_ARGS *,
a2369ed3 395 enum machine_mode, tree);
b78d48dd
FJ
396static rtx rs6000_mixed_function_arg (CUMULATIVE_ARGS *,
397 enum machine_mode, tree, int);
5985c7a6 398static void rs6000_move_block_from_reg(int regno, rtx x, int nregs);
c6e8c921
GK
399static void setup_incoming_varargs (CUMULATIVE_ARGS *,
400 enum machine_mode, tree,
401 int *, int);
efdba735
SH
402#if TARGET_MACHO
403static void macho_branch_islands (void);
404static void add_compiler_branch_island (tree, tree, int);
405static int no_previous_def (tree function_name);
406static tree get_prev_label (tree function_name);
407#endif
408
c35d187f 409static tree rs6000_build_builtin_va_list (void);
17211ab5
GK
410
411/* Hash table stuff for keeping track of TOC entries. */
412
413struct toc_hash_struct GTY(())
414{
415 /* `key' will satisfy CONSTANT_P; in fact, it will satisfy
416 ASM_OUTPUT_SPECIAL_POOL_ENTRY_P. */
417 rtx key;
418 enum machine_mode key_mode;
419 int labelno;
420};
421
422static GTY ((param_is (struct toc_hash_struct))) htab_t toc_hash_table;
c81bebd7
MM
423\f
424/* Default register names. */
425char rs6000_reg_names[][8] =
426{
802a0058
MM
427 "0", "1", "2", "3", "4", "5", "6", "7",
428 "8", "9", "10", "11", "12", "13", "14", "15",
429 "16", "17", "18", "19", "20", "21", "22", "23",
430 "24", "25", "26", "27", "28", "29", "30", "31",
431 "0", "1", "2", "3", "4", "5", "6", "7",
432 "8", "9", "10", "11", "12", "13", "14", "15",
433 "16", "17", "18", "19", "20", "21", "22", "23",
434 "24", "25", "26", "27", "28", "29", "30", "31",
435 "mq", "lr", "ctr","ap",
436 "0", "1", "2", "3", "4", "5", "6", "7",
0ac081f6
AH
437 "xer",
438 /* AltiVec registers. */
0cd5e3a1
AH
439 "0", "1", "2", "3", "4", "5", "6", "7",
440 "8", "9", "10", "11", "12", "13", "14", "15",
441 "16", "17", "18", "19", "20", "21", "22", "23",
442 "24", "25", "26", "27", "28", "29", "30", "31",
59a4c851
AH
443 "vrsave", "vscr",
444 /* SPE registers. */
445 "spe_acc", "spefscr"
c81bebd7
MM
446};
447
448#ifdef TARGET_REGNAMES
8b60264b 449static const char alt_reg_names[][8] =
c81bebd7 450{
802a0058
MM
451 "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
452 "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",
453 "%r16", "%r17", "%r18", "%r19", "%r20", "%r21", "%r22", "%r23",
454 "%r24", "%r25", "%r26", "%r27", "%r28", "%r29", "%r30", "%r31",
455 "%f0", "%f1", "%f2", "%f3", "%f4", "%f5", "%f6", "%f7",
456 "%f8", "%f9", "%f10", "%f11", "%f12", "%f13", "%f14", "%f15",
457 "%f16", "%f17", "%f18", "%f19", "%f20", "%f21", "%f22", "%f23",
458 "%f24", "%f25", "%f26", "%f27", "%f28", "%f29", "%f30", "%f31",
459 "mq", "lr", "ctr", "ap",
460 "%cr0", "%cr1", "%cr2", "%cr3", "%cr4", "%cr5", "%cr6", "%cr7",
0ac081f6 461 "xer",
59a4c851 462 /* AltiVec registers. */
0ac081f6 463 "%v0", "%v1", "%v2", "%v3", "%v4", "%v5", "%v6", "%v7",
59a4c851
AH
464 "%v8", "%v9", "%v10", "%v11", "%v12", "%v13", "%v14", "%v15",
465 "%v16", "%v17", "%v18", "%v19", "%v20", "%v21", "%v22", "%v23",
466 "%v24", "%v25", "%v26", "%v27", "%v28", "%v29", "%v30", "%v31",
467 "vrsave", "vscr",
468 /* SPE registers. */
469 "spe_acc", "spefscr"
c81bebd7
MM
470};
471#endif
9878760c 472\f
daf11973
MM
473#ifndef MASK_STRICT_ALIGN
474#define MASK_STRICT_ALIGN 0
475#endif
ffcfcb5f
AM
476#ifndef TARGET_PROFILE_KERNEL
477#define TARGET_PROFILE_KERNEL 0
478#endif
3961e8fe
RH
479
480/* The VRSAVE bitmask puts bit %v0 as the most significant bit. */
481#define ALTIVEC_REG_BIT(REGNO) (0x80000000 >> ((REGNO) - FIRST_ALTIVEC_REGNO))
c4501e62
JJ
482
483/* Return 1 for a symbol ref for a thread-local storage symbol. */
484#define RS6000_SYMBOL_REF_TLS_P(RTX) \
485 (GET_CODE (RTX) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (RTX) != 0)
672a6f42
NB
486\f
487/* Initialize the GCC target structure. */
91d231cb
JM
488#undef TARGET_ATTRIBUTE_TABLE
489#define TARGET_ATTRIBUTE_TABLE rs6000_attribute_table
a5c76ee6
ZW
490#undef TARGET_SET_DEFAULT_TYPE_ATTRIBUTES
491#define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES rs6000_set_default_type_attributes
daf11973 492
301d03af
RS
493#undef TARGET_ASM_ALIGNED_DI_OP
494#define TARGET_ASM_ALIGNED_DI_OP DOUBLE_INT_ASM_OP
495
496/* Default unaligned ops are only provided for ELF. Find the ops needed
497 for non-ELF systems. */
498#ifndef OBJECT_FORMAT_ELF
cbaaba19 499#if TARGET_XCOFF
ae6c1efd 500/* For XCOFF. rs6000_assemble_integer will handle unaligned DIs on
301d03af
RS
501 64-bit targets. */
502#undef TARGET_ASM_UNALIGNED_HI_OP
503#define TARGET_ASM_UNALIGNED_HI_OP "\t.vbyte\t2,"
504#undef TARGET_ASM_UNALIGNED_SI_OP
505#define TARGET_ASM_UNALIGNED_SI_OP "\t.vbyte\t4,"
506#undef TARGET_ASM_UNALIGNED_DI_OP
507#define TARGET_ASM_UNALIGNED_DI_OP "\t.vbyte\t8,"
508#else
509/* For Darwin. */
510#undef TARGET_ASM_UNALIGNED_HI_OP
511#define TARGET_ASM_UNALIGNED_HI_OP "\t.short\t"
512#undef TARGET_ASM_UNALIGNED_SI_OP
513#define TARGET_ASM_UNALIGNED_SI_OP "\t.long\t"
514#endif
515#endif
516
517/* This hook deals with fixups for relocatable code and DI-mode objects
518 in 64-bit code. */
519#undef TARGET_ASM_INTEGER
520#define TARGET_ASM_INTEGER rs6000_assemble_integer
521
93638d7a
AM
522#ifdef HAVE_GAS_HIDDEN
523#undef TARGET_ASM_ASSEMBLE_VISIBILITY
524#define TARGET_ASM_ASSEMBLE_VISIBILITY rs6000_assemble_visibility
525#endif
526
c4501e62
JJ
527#undef TARGET_HAVE_TLS
528#define TARGET_HAVE_TLS HAVE_AS_TLS
529
530#undef TARGET_CANNOT_FORCE_CONST_MEM
531#define TARGET_CANNOT_FORCE_CONST_MEM rs6000_tls_referenced_p
532
08c148a8
NB
533#undef TARGET_ASM_FUNCTION_PROLOGUE
534#define TARGET_ASM_FUNCTION_PROLOGUE rs6000_output_function_prologue
535#undef TARGET_ASM_FUNCTION_EPILOGUE
536#define TARGET_ASM_FUNCTION_EPILOGUE rs6000_output_function_epilogue
537
b54cf83a
DE
538#undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE
539#define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE rs6000_use_dfa_pipeline_interface
b54cf83a
DE
540#undef TARGET_SCHED_VARIABLE_ISSUE
541#define TARGET_SCHED_VARIABLE_ISSUE rs6000_variable_issue
542
c237e94a
ZW
543#undef TARGET_SCHED_ISSUE_RATE
544#define TARGET_SCHED_ISSUE_RATE rs6000_issue_rate
545#undef TARGET_SCHED_ADJUST_COST
546#define TARGET_SCHED_ADJUST_COST rs6000_adjust_cost
547#undef TARGET_SCHED_ADJUST_PRIORITY
548#define TARGET_SCHED_ADJUST_PRIORITY rs6000_adjust_priority
569fa502
DN
549#undef TARGET_SCHED_IS_COSTLY_DEPENDENCE
550#define TARGET_SCHED_IS_COSTLY_DEPENDENCE rs6000_is_costly_dependence
cbe26ab8
DN
551#undef TARGET_SCHED_FINISH
552#define TARGET_SCHED_FINISH rs6000_sched_finish
c237e94a 553
be12c2b0
VM
554#undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
555#define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD rs6000_use_sched_lookahead
556
0ac081f6
AH
557#undef TARGET_INIT_BUILTINS
558#define TARGET_INIT_BUILTINS rs6000_init_builtins
559
560#undef TARGET_EXPAND_BUILTIN
561#define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
562
c15c90bb
ZW
563#undef TARGET_INIT_LIBFUNCS
564#define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs
565
f1384257 566#if TARGET_MACHO
0e5dbd9b
DE
567#undef TARGET_BINDS_LOCAL_P
568#define TARGET_BINDS_LOCAL_P rs6000_binds_local_p
f1384257 569#endif
0e5dbd9b 570
3961e8fe
RH
571#undef TARGET_ASM_OUTPUT_MI_THUNK
572#define TARGET_ASM_OUTPUT_MI_THUNK rs6000_output_mi_thunk
573
3961e8fe 574#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
5b71a4e7 575#define TARGET_ASM_CAN_OUTPUT_MI_THUNK hook_bool_tree_hwi_hwi_tree_true
00b960c7 576
4977bab6
ZW
577#undef TARGET_FUNCTION_OK_FOR_SIBCALL
578#define TARGET_FUNCTION_OK_FOR_SIBCALL rs6000_function_ok_for_sibcall
579
3c50106f
RH
580#undef TARGET_RTX_COSTS
581#define TARGET_RTX_COSTS rs6000_rtx_costs
dcefdf67
RH
582#undef TARGET_ADDRESS_COST
583#define TARGET_ADDRESS_COST hook_int_rtx_0
3c50106f 584
c8e4f0e9
AH
585#undef TARGET_VECTOR_OPAQUE_P
586#define TARGET_VECTOR_OPAQUE_P is_ev64_opaque_type
62e1dfcf 587
96714395
AH
588#undef TARGET_DWARF_REGISTER_SPAN
589#define TARGET_DWARF_REGISTER_SPAN rs6000_dwarf_register_span
590
c6e8c921
GK
591/* On rs6000, function arguments are promoted, as are function return
592 values. */
593#undef TARGET_PROMOTE_FUNCTION_ARGS
594#define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
595#undef TARGET_PROMOTE_FUNCTION_RETURN
596#define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_true
597
598/* Structure return values are passed as an extra parameter. */
599#undef TARGET_STRUCT_VALUE_RTX
600#define TARGET_STRUCT_VALUE_RTX hook_rtx_tree_int_null
601
602#undef TARGET_RETURN_IN_MEMORY
603#define TARGET_RETURN_IN_MEMORY rs6000_return_in_memory
604
605#undef TARGET_SETUP_INCOMING_VARARGS
606#define TARGET_SETUP_INCOMING_VARARGS setup_incoming_varargs
607
608/* Always strict argument naming on rs6000. */
609#undef TARGET_STRICT_ARGUMENT_NAMING
610#define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
611#undef TARGET_PRETEND_OUTGOING_VARARGS_NAMED
612#define TARGET_PRETEND_OUTGOING_VARARGS_NAMED hook_bool_CUMULATIVE_ARGS_true
613
c35d187f
RH
614#undef TARGET_BUILD_BUILTIN_VA_LIST
615#define TARGET_BUILD_BUILTIN_VA_LIST rs6000_build_builtin_va_list
616
f6897b10 617struct gcc_target targetm = TARGET_INITIALIZER;
672a6f42 618\f
5248c961
RK
619/* Override command line options. Mostly we process the processor
620 type and sometimes adjust other TARGET_ options. */
621
622void
d779d0dc 623rs6000_override_options (const char *default_cpu)
5248c961 624{
c4d38ccb 625 size_t i, j;
8e3f41e7 626 struct rs6000_cpu_select *ptr;
66188a7e 627 int set_masks;
5248c961 628
66188a7e 629 /* Simplifications for entries below. */
85638c0d 630
66188a7e
GK
631 enum {
632 POWERPC_BASE_MASK = MASK_POWERPC | MASK_NEW_MNEMONICS,
633 POWERPC_7400_MASK = POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_ALTIVEC
634 };
85638c0d 635
66188a7e
GK
636 /* This table occasionally claims that a processor does not support
637 a particular feature even though it does, but the feature is slower
638 than the alternative. Thus, it shouldn't be relied on as a
639 complete description of the processor's support.
640
641 Please keep this list in order, and don't forget to update the
642 documentation in invoke.texi when adding a new processor or
643 flag. */
5248c961
RK
644 static struct ptt
645 {
8b60264b
KG
646 const char *const name; /* Canonical processor name. */
647 const enum processor_type processor; /* Processor type enum value. */
648 const int target_enable; /* Target flags to enable. */
8b60264b 649 } const processor_target_table[]
66188a7e 650 = {{"401", PROCESSOR_PPC403, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
49a0b204 651 {"403", PROCESSOR_PPC403,
66188a7e
GK
652 POWERPC_BASE_MASK | MASK_SOFT_FLOAT | MASK_STRICT_ALIGN},
653 {"405", PROCESSOR_PPC405, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
654 {"405fp", PROCESSOR_PPC405, POWERPC_BASE_MASK},
655 {"440", PROCESSOR_PPC440, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
656 {"440fp", PROCESSOR_PPC440, POWERPC_BASE_MASK},
657 {"505", PROCESSOR_MPCCORE, POWERPC_BASE_MASK},
5248c961 658 {"601", PROCESSOR_PPC601,
66188a7e
GK
659 MASK_POWER | POWERPC_BASE_MASK | MASK_MULTIPLE | MASK_STRING},
660 {"602", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
661 {"603", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
662 {"603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
663 {"604", PROCESSOR_PPC604, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
664 {"604e", PROCESSOR_PPC604e, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
7ddb6568
AM
665 {"620", PROCESSOR_PPC620,
666 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
667 {"630", PROCESSOR_PPC630,
668 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
669 {"740", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
670 {"7400", PROCESSOR_PPC7400, POWERPC_7400_MASK},
671 {"7450", PROCESSOR_PPC7450, POWERPC_7400_MASK},
672 {"750", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
673 {"801", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
674 {"821", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
675 {"823", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
676 {"8540", PROCESSOR_PPC8540, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
677 {"860", PROCESSOR_MPCCORE, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
7177e720 678 {"970", PROCESSOR_POWER4,
66188a7e
GK
679 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
680 {"common", PROCESSOR_COMMON, MASK_NEW_MNEMONICS},
681 {"ec603e", PROCESSOR_PPC603, POWERPC_BASE_MASK | MASK_SOFT_FLOAT},
682 {"G3", PROCESSOR_PPC750, POWERPC_BASE_MASK | MASK_PPC_GFXOPT},
683 {"G4", PROCESSOR_PPC7450, POWERPC_7400_MASK},
49ffe578 684 {"G5", PROCESSOR_POWER4,
66188a7e
GK
685 POWERPC_7400_MASK | MASK_PPC_GPOPT | MASK_MFCRF | MASK_POWERPC64},
686 {"power", PROCESSOR_POWER, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
687 {"power2", PROCESSOR_POWER,
688 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
7ddb6568
AM
689 {"power3", PROCESSOR_PPC630,
690 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
691 {"power4", PROCESSOR_POWER4,
692 POWERPC_BASE_MASK | MASK_PPC_GFXOPT | MASK_POWERPC64},
66188a7e
GK
693 {"powerpc", PROCESSOR_POWERPC, POWERPC_BASE_MASK},
694 {"powerpc64", PROCESSOR_POWERPC64,
695 POWERPC_BASE_MASK | MASK_POWERPC64},
696 {"rios", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
697 {"rios1", PROCESSOR_RIOS1, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
698 {"rios2", PROCESSOR_RIOS2,
699 MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING},
700 {"rsc", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
701 {"rsc1", PROCESSOR_PPC601, MASK_POWER | MASK_MULTIPLE | MASK_STRING},
7ddb6568 702 {"rs64a", PROCESSOR_RS64A, POWERPC_BASE_MASK | MASK_POWERPC64},
66188a7e 703 };
5248c961 704
ca7558fc 705 const size_t ptt_size = ARRAY_SIZE (processor_target_table);
5248c961 706
a4f6c312
SS
707 /* Save current -mmultiple/-mno-multiple status. */
708 int multiple = TARGET_MULTIPLE;
709 /* Save current -mstring/-mno-string status. */
710 int string = TARGET_STRING;
8a61d227 711
66188a7e
GK
712 /* Some OSs don't support saving the high part of 64-bit registers on
713 context switch. Other OSs don't support saving Altivec registers.
714 On those OSs, we don't touch the MASK_POWERPC64 or MASK_ALTIVEC
715 settings; if the user wants either, the user must explicitly specify
716 them and we won't interfere with the user's specification. */
717
718 enum {
719 POWER_MASKS = MASK_POWER | MASK_POWER2 | MASK_MULTIPLE | MASK_STRING,
720 POWERPC_MASKS = (POWERPC_BASE_MASK | MASK_PPC_GPOPT
721 | MASK_PPC_GFXOPT | MASK_POWERPC64 | MASK_ALTIVEC
722 | MASK_MFCRF)
723 };
724 set_masks = POWER_MASKS | POWERPC_MASKS | MASK_SOFT_FLOAT;
725#ifdef OS_MISSING_POWERPC64
726 if (OS_MISSING_POWERPC64)
727 set_masks &= ~MASK_POWERPC64;
728#endif
729#ifdef OS_MISSING_ALTIVEC
730 if (OS_MISSING_ALTIVEC)
731 set_masks &= ~MASK_ALTIVEC;
732#endif
733
a4f6c312 734 /* Identify the processor type. */
8e3f41e7 735 rs6000_select[0].string = default_cpu;
3cb999d8 736 rs6000_cpu = TARGET_POWERPC64 ? PROCESSOR_DEFAULT64 : PROCESSOR_DEFAULT;
8e3f41e7 737
b6a1cbae 738 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
5248c961 739 {
8e3f41e7
MM
740 ptr = &rs6000_select[i];
741 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
5248c961 742 {
8e3f41e7
MM
743 for (j = 0; j < ptt_size; j++)
744 if (! strcmp (ptr->string, processor_target_table[j].name))
745 {
746 if (ptr->set_tune_p)
747 rs6000_cpu = processor_target_table[j].processor;
748
749 if (ptr->set_arch_p)
750 {
66188a7e
GK
751 target_flags &= ~set_masks;
752 target_flags |= (processor_target_table[j].target_enable
753 & set_masks);
8e3f41e7
MM
754 }
755 break;
756 }
757
4406229e 758 if (j == ptt_size)
8e3f41e7 759 error ("bad value (%s) for %s switch", ptr->string, ptr->name);
5248c961
RK
760 }
761 }
8a61d227 762
993f19a8 763 if (TARGET_E500)
a3170dc6
AH
764 rs6000_isel = 1;
765
dff9f1b6
DE
766 /* If we are optimizing big endian systems for space, use the load/store
767 multiple and string instructions. */
ef792183 768 if (BYTES_BIG_ENDIAN && optimize_size)
dff9f1b6 769 target_flags |= MASK_MULTIPLE | MASK_STRING;
ef792183 770
8a61d227
MM
771 /* If -mmultiple or -mno-multiple was explicitly used, don't
772 override with the processor default */
b21fb038 773 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
8a61d227 774 target_flags = (target_flags & ~MASK_MULTIPLE) | multiple;
7e69e155 775
a4f6c312
SS
776 /* If -mstring or -mno-string was explicitly used, don't override
777 with the processor default. */
b21fb038 778 if ((target_flags_explicit & MASK_STRING) != 0)
1f5515bf 779 target_flags = (target_flags & ~MASK_STRING) | string;
938937d8 780
a4f6c312
SS
781 /* Don't allow -mmultiple or -mstring on little endian systems
782 unless the cpu is a 750, because the hardware doesn't support the
783 instructions used in little endian mode, and causes an alignment
784 trap. The 750 does not cause an alignment trap (except when the
785 target is unaligned). */
bef84347 786
b21fb038 787 if (!BYTES_BIG_ENDIAN && rs6000_cpu != PROCESSOR_PPC750)
7e69e155
MM
788 {
789 if (TARGET_MULTIPLE)
790 {
791 target_flags &= ~MASK_MULTIPLE;
b21fb038 792 if ((target_flags_explicit & MASK_MULTIPLE) != 0)
7e69e155
MM
793 warning ("-mmultiple is not supported on little endian systems");
794 }
795
796 if (TARGET_STRING)
797 {
798 target_flags &= ~MASK_STRING;
b21fb038 799 if ((target_flags_explicit & MASK_STRING) != 0)
938937d8 800 warning ("-mstring is not supported on little endian systems");
7e69e155
MM
801 }
802 }
3933e0e1 803
38c1f2d7
MM
804 /* Set debug flags */
805 if (rs6000_debug_name)
806 {
bfc79d3b 807 if (! strcmp (rs6000_debug_name, "all"))
38c1f2d7 808 rs6000_debug_stack = rs6000_debug_arg = 1;
bfc79d3b 809 else if (! strcmp (rs6000_debug_name, "stack"))
38c1f2d7 810 rs6000_debug_stack = 1;
bfc79d3b 811 else if (! strcmp (rs6000_debug_name, "arg"))
38c1f2d7
MM
812 rs6000_debug_arg = 1;
813 else
c725bd79 814 error ("unknown -mdebug-%s switch", rs6000_debug_name);
38c1f2d7
MM
815 }
816
57ac7be9
AM
817 if (rs6000_traceback_name)
818 {
819 if (! strncmp (rs6000_traceback_name, "full", 4))
820 rs6000_traceback = traceback_full;
821 else if (! strncmp (rs6000_traceback_name, "part", 4))
822 rs6000_traceback = traceback_part;
823 else if (! strncmp (rs6000_traceback_name, "no", 2))
824 rs6000_traceback = traceback_none;
825 else
826 error ("unknown -mtraceback arg `%s'; expecting `full', `partial' or `none'",
827 rs6000_traceback_name);
828 }
829
6fa3f289
ZW
830 /* Set size of long double */
831 rs6000_long_double_type_size = 64;
832 if (rs6000_long_double_size_string)
833 {
834 char *tail;
835 int size = strtol (rs6000_long_double_size_string, &tail, 10);
836 if (*tail != '\0' || (size != 64 && size != 128))
837 error ("Unknown switch -mlong-double-%s",
838 rs6000_long_double_size_string);
839 else
840 rs6000_long_double_type_size = size;
841 }
842
0ac081f6
AH
843 /* Handle -mabi= options. */
844 rs6000_parse_abi_options ();
845
025d9908
KH
846 /* Handle -malign-XXXXX option. */
847 rs6000_parse_alignment_option ();
848
5da702b1
AH
849 /* Handle generic -mFOO=YES/NO options. */
850 rs6000_parse_yes_no_option ("vrsave", rs6000_altivec_vrsave_string,
851 &rs6000_altivec_vrsave);
852 rs6000_parse_yes_no_option ("isel", rs6000_isel_string,
853 &rs6000_isel);
854 rs6000_parse_yes_no_option ("spe", rs6000_spe_string, &rs6000_spe);
855 rs6000_parse_yes_no_option ("float-gprs", rs6000_float_gprs_string,
856 &rs6000_float_gprs);
993f19a8 857
c4501e62
JJ
858 /* Handle -mtls-size option. */
859 rs6000_parse_tls_size_option ();
860
a7ae18e2
AH
861#ifdef SUBTARGET_OVERRIDE_OPTIONS
862 SUBTARGET_OVERRIDE_OPTIONS;
863#endif
864#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
865 SUBSUBTARGET_OVERRIDE_OPTIONS;
866#endif
867
5da702b1
AH
868 if (TARGET_E500)
869 {
870 /* The e500 does not have string instructions, and we set
871 MASK_STRING above when optimizing for size. */
872 if ((target_flags & MASK_STRING) != 0)
873 target_flags = target_flags & ~MASK_STRING;
b6e59a3a
AH
874
875 /* No SPE means 64-bit long doubles, even if an E500. */
876 if (rs6000_spe_string != 0
877 && !strcmp (rs6000_spe_string, "no"))
878 rs6000_long_double_type_size = 64;
5da702b1
AH
879 }
880 else if (rs6000_select[1].string != NULL)
881 {
882 /* For the powerpc-eabispe configuration, we set all these by
883 default, so let's unset them if we manually set another
884 CPU that is not the E500. */
885 if (rs6000_abi_string == 0)
886 rs6000_spe_abi = 0;
887 if (rs6000_spe_string == 0)
888 rs6000_spe = 0;
889 if (rs6000_float_gprs_string == 0)
890 rs6000_float_gprs = 0;
891 if (rs6000_isel_string == 0)
892 rs6000_isel = 0;
b6e59a3a
AH
893 if (rs6000_long_double_size_string == 0)
894 rs6000_long_double_type_size = 64;
5da702b1 895 }
b5044283 896
a5c76ee6
ZW
897 /* Handle -m(no-)longcall option. This is a bit of a cheap hack,
898 using TARGET_OPTIONS to handle a toggle switch, but we're out of
899 bits in target_flags so TARGET_SWITCHES cannot be used.
900 Assumption here is that rs6000_longcall_switch points into the
901 text of the complete option, rather than being a copy, so we can
902 scan back for the presence or absence of the no- modifier. */
903 if (rs6000_longcall_switch)
904 {
905 const char *base = rs6000_longcall_switch;
906 while (base[-1] != 'm') base--;
907
908 if (*rs6000_longcall_switch != '\0')
909 error ("invalid option `%s'", base);
910 rs6000_default_long_calls = (base[0] != 'n');
911 }
912
cbe26ab8 913 /* Handle -mprioritize-restricted-insns option. */
79ae11c4
DN
914 rs6000_sched_restricted_insns_priority = DEFAULT_RESTRICTED_INSNS_PRIORITY;
915 if (rs6000_sched_restricted_insns_priority_str)
916 rs6000_sched_restricted_insns_priority =
917 atoi (rs6000_sched_restricted_insns_priority_str);
918
569fa502
DN
919 /* Handle -msched-costly-dep option. */
920 rs6000_sched_costly_dep = DEFAULT_SCHED_COSTLY_DEP;
921 if (rs6000_sched_costly_dep_str)
922 {
923 if (! strcmp (rs6000_sched_costly_dep_str, "no"))
924 rs6000_sched_costly_dep = no_dep_costly;
925 else if (! strcmp (rs6000_sched_costly_dep_str, "all"))
926 rs6000_sched_costly_dep = all_deps_costly;
927 else if (! strcmp (rs6000_sched_costly_dep_str, "true_store_to_load"))
928 rs6000_sched_costly_dep = true_store_to_load_dep_costly;
929 else if (! strcmp (rs6000_sched_costly_dep_str, "store_to_load"))
930 rs6000_sched_costly_dep = store_to_load_dep_costly;
cbe26ab8
DN
931 else
932 rs6000_sched_costly_dep = atoi (rs6000_sched_costly_dep_str);
933 }
934
935 /* Handle -minsert-sched-nops option. */
936 rs6000_sched_insert_nops = DEFAULT_SCHED_FINISH_NOP_INSERTION_SCHEME;
937 if (rs6000_sched_insert_nops_str)
938 {
939 if (! strcmp (rs6000_sched_insert_nops_str, "no"))
940 rs6000_sched_insert_nops = sched_finish_none;
941 else if (! strcmp (rs6000_sched_insert_nops_str, "pad"))
942 rs6000_sched_insert_nops = sched_finish_pad_groups;
943 else if (! strcmp (rs6000_sched_insert_nops_str, "regroup_exact"))
944 rs6000_sched_insert_nops = sched_finish_regroup_exact;
945 else
946 rs6000_sched_insert_nops = atoi (rs6000_sched_insert_nops_str);
569fa502
DN
947 }
948
c81bebd7 949#ifdef TARGET_REGNAMES
a4f6c312
SS
950 /* If the user desires alternate register names, copy in the
951 alternate names now. */
c81bebd7 952 if (TARGET_REGNAMES)
4e135bdd 953 memcpy (rs6000_reg_names, alt_reg_names, sizeof (rs6000_reg_names));
c81bebd7
MM
954#endif
955
6fa3f289
ZW
956 /* Set TARGET_AIX_STRUCT_RET last, after the ABI is determined.
957 If -maix-struct-return or -msvr4-struct-return was explicitly
958 used, don't override with the ABI default. */
b21fb038 959 if ((target_flags_explicit & MASK_AIX_STRUCT_RET) == 0)
6fa3f289
ZW
960 {
961 if (DEFAULT_ABI == ABI_V4 && !DRAFT_V4_STRUCT_RET)
962 target_flags = (target_flags & ~MASK_AIX_STRUCT_RET);
963 else
964 target_flags |= MASK_AIX_STRUCT_RET;
965 }
966
fcce224d
DE
967 if (TARGET_LONG_DOUBLE_128
968 && (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN))
70a01792 969 REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
fcce224d 970
9ebbca7d
GK
971 /* Allocate an alias set for register saves & restores from stack. */
972 rs6000_sr_alias_set = new_alias_set ();
973
974 if (TARGET_TOC)
975 ASM_GENERATE_INTERNAL_LABEL (toc_label_name, "LCTOC", 1);
71f123ca 976
301d03af
RS
977 /* We can only guarantee the availability of DI pseudo-ops when
978 assembling for 64-bit targets. */
ae6c1efd 979 if (!TARGET_64BIT)
301d03af
RS
980 {
981 targetm.asm_out.aligned_op.di = NULL;
982 targetm.asm_out.unaligned_op.di = NULL;
983 }
984
2792d578
DE
985 /* Set maximum branch target alignment at two instructions, eight bytes. */
986 align_jumps_max_skip = 8;
987 align_loops_max_skip = 8;
988
71f123ca
FS
989 /* Arrange to save and restore machine status around nested functions. */
990 init_machine_status = rs6000_init_machine_status;
5248c961 991}
5accd822 992
5da702b1
AH
993/* Handle generic options of the form -mfoo=yes/no.
994 NAME is the option name.
995 VALUE is the option value.
996 FLAG is the pointer to the flag where to store a 1 or 0, depending on
997 whether the option value is 'yes' or 'no' respectively. */
993f19a8 998static void
5da702b1 999rs6000_parse_yes_no_option (const char *name, const char *value, int *flag)
993f19a8 1000{
5da702b1 1001 if (value == 0)
993f19a8 1002 return;
5da702b1
AH
1003 else if (!strcmp (value, "yes"))
1004 *flag = 1;
1005 else if (!strcmp (value, "no"))
1006 *flag = 0;
08b57fb3 1007 else
5da702b1 1008 error ("unknown -m%s= option specified: '%s'", name, value);
08b57fb3
AH
1009}
1010
0ac081f6 1011/* Handle -mabi= options. */
00b960c7 1012static void
863d938c 1013rs6000_parse_abi_options (void)
0ac081f6
AH
1014{
1015 if (rs6000_abi_string == 0)
1016 return;
1017 else if (! strcmp (rs6000_abi_string, "altivec"))
6fa3f289 1018 rs6000_altivec_abi = 1;
76a773f3
AH
1019 else if (! strcmp (rs6000_abi_string, "no-altivec"))
1020 rs6000_altivec_abi = 0;
a3170dc6 1021 else if (! strcmp (rs6000_abi_string, "spe"))
01f4962d
NS
1022 {
1023 rs6000_spe_abi = 1;
1024 if (!TARGET_SPE_ABI)
1025 error ("not configured for ABI: '%s'", rs6000_abi_string);
1026 }
1027
a3170dc6
AH
1028 else if (! strcmp (rs6000_abi_string, "no-spe"))
1029 rs6000_spe_abi = 0;
0ac081f6 1030 else
c725bd79 1031 error ("unknown ABI specified: '%s'", rs6000_abi_string);
0ac081f6
AH
1032}
1033
025d9908
KH
1034/* Handle -malign-XXXXXX options. */
1035static void
863d938c 1036rs6000_parse_alignment_option (void)
025d9908 1037{
b20a9cca
AM
1038 if (rs6000_alignment_string == 0)
1039 return;
1040 else if (! strcmp (rs6000_alignment_string, "power"))
025d9908
KH
1041 rs6000_alignment_flags = MASK_ALIGN_POWER;
1042 else if (! strcmp (rs6000_alignment_string, "natural"))
1043 rs6000_alignment_flags = MASK_ALIGN_NATURAL;
1044 else
1045 error ("unknown -malign-XXXXX option specified: '%s'",
1046 rs6000_alignment_string);
1047}
1048
c4501e62
JJ
1049/* Validate and record the size specified with the -mtls-size option. */
1050
1051static void
863d938c 1052rs6000_parse_tls_size_option (void)
c4501e62
JJ
1053{
1054 if (rs6000_tls_size_string == 0)
1055 return;
1056 else if (strcmp (rs6000_tls_size_string, "16") == 0)
1057 rs6000_tls_size = 16;
1058 else if (strcmp (rs6000_tls_size_string, "32") == 0)
1059 rs6000_tls_size = 32;
1060 else if (strcmp (rs6000_tls_size_string, "64") == 0)
1061 rs6000_tls_size = 64;
1062 else
1063 error ("bad value `%s' for -mtls-size switch", rs6000_tls_size_string);
1064}
1065
5accd822 1066void
a2369ed3 1067optimization_options (int level ATTRIBUTE_UNUSED, int size ATTRIBUTE_UNUSED)
5accd822 1068{
5accd822 1069}
3cfa4909
MM
1070\f
1071/* Do anything needed at the start of the asm file. */
1072
1bc7c5b6 1073static void
863d938c 1074rs6000_file_start (void)
3cfa4909 1075{
c4d38ccb 1076 size_t i;
3cfa4909 1077 char buffer[80];
d330fd93 1078 const char *start = buffer;
3cfa4909 1079 struct rs6000_cpu_select *ptr;
1bc7c5b6
ZW
1080 const char *default_cpu = TARGET_CPU_DEFAULT;
1081 FILE *file = asm_out_file;
1082
1083 default_file_start ();
1084
1085#ifdef TARGET_BI_ARCH
1086 if ((TARGET_DEFAULT ^ target_flags) & MASK_64BIT)
1087 default_cpu = 0;
1088#endif
3cfa4909
MM
1089
1090 if (flag_verbose_asm)
1091 {
1092 sprintf (buffer, "\n%s rs6000/powerpc options:", ASM_COMMENT_START);
1093 rs6000_select[0].string = default_cpu;
1094
b6a1cbae 1095 for (i = 0; i < ARRAY_SIZE (rs6000_select); i++)
3cfa4909
MM
1096 {
1097 ptr = &rs6000_select[i];
1098 if (ptr->string != (char *)0 && ptr->string[0] != '\0')
1099 {
1100 fprintf (file, "%s %s%s", start, ptr->name, ptr->string);
1101 start = "";
1102 }
1103 }
1104
b91da81f 1105#ifdef USING_ELFOS_H
3cfa4909
MM
1106 switch (rs6000_sdata)
1107 {
1108 case SDATA_NONE: fprintf (file, "%s -msdata=none", start); start = ""; break;
1109 case SDATA_DATA: fprintf (file, "%s -msdata=data", start); start = ""; break;
1110 case SDATA_SYSV: fprintf (file, "%s -msdata=sysv", start); start = ""; break;
1111 case SDATA_EABI: fprintf (file, "%s -msdata=eabi", start); start = ""; break;
1112 }
1113
1114 if (rs6000_sdata && g_switch_value)
1115 {
307b599c
MK
1116 fprintf (file, "%s -G " HOST_WIDE_INT_PRINT_UNSIGNED, start,
1117 g_switch_value);
3cfa4909
MM
1118 start = "";
1119 }
1120#endif
1121
1122 if (*start == '\0')
949ea356 1123 putc ('\n', file);
3cfa4909
MM
1124 }
1125}
5248c961 1126\f
a0ab749a 1127/* Return nonzero if this function is known to have a null epilogue. */
9878760c
RK
1128
1129int
863d938c 1130direct_return (void)
9878760c 1131{
4697a36c
MM
1132 if (reload_completed)
1133 {
1134 rs6000_stack_t *info = rs6000_stack_info ();
1135
1136 if (info->first_gp_reg_save == 32
1137 && info->first_fp_reg_save == 64
00b960c7 1138 && info->first_altivec_reg_save == LAST_ALTIVEC_REGNO + 1
c81fc13e
DE
1139 && ! info->lr_save_p
1140 && ! info->cr_save_p
00b960c7 1141 && info->vrsave_mask == 0
c81fc13e 1142 && ! info->push_p)
4697a36c
MM
1143 return 1;
1144 }
1145
1146 return 0;
9878760c
RK
1147}
1148
1149/* Returns 1 always. */
1150
1151int
a2369ed3
DJ
1152any_operand (rtx op ATTRIBUTE_UNUSED,
1153 enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
1154{
1155 return 1;
1156}
1157
a4f6c312 1158/* Returns 1 if op is the count register. */
38c1f2d7 1159int
a2369ed3 1160count_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
b6c9286a
MM
1161{
1162 if (GET_CODE (op) != REG)
1163 return 0;
1164
1165 if (REGNO (op) == COUNT_REGISTER_REGNUM)
1166 return 1;
1167
1168 if (REGNO (op) > FIRST_PSEUDO_REGISTER)
1169 return 1;
1170
1171 return 0;
1172}
1173
0ec4e2a8
AH
1174/* Returns 1 if op is an altivec register. */
1175int
a2369ed3 1176altivec_register_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ec4e2a8
AH
1177{
1178
1179 return (register_operand (op, mode)
1180 && (GET_CODE (op) != REG
1181 || REGNO (op) > FIRST_PSEUDO_REGISTER
1182 || ALTIVEC_REGNO_P (REGNO (op))));
1183}
1184
38c1f2d7 1185int
a2369ed3 1186xer_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
802a0058
MM
1187{
1188 if (GET_CODE (op) != REG)
1189 return 0;
1190
9ebbca7d 1191 if (XER_REGNO_P (REGNO (op)))
802a0058
MM
1192 return 1;
1193
802a0058
MM
1194 return 0;
1195}
1196
c859cda6 1197/* Return 1 if OP is a signed 8-bit constant. Int multiplication
6f317ef3 1198 by such constants completes more quickly. */
c859cda6
DJ
1199
1200int
a2369ed3 1201s8bit_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
c859cda6
DJ
1202{
1203 return ( GET_CODE (op) == CONST_INT
1204 && (INTVAL (op) >= -128 && INTVAL (op) <= 127));
1205}
1206
9878760c
RK
1207/* Return 1 if OP is a constant that can fit in a D field. */
1208
1209int
a2369ed3 1210short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1211{
5f59ecb7
DE
1212 return (GET_CODE (op) == CONST_INT
1213 && CONST_OK_FOR_LETTER_P (INTVAL (op), 'I'));
9878760c
RK
1214}
1215
5519a4f9 1216/* Similar for an unsigned D field. */
9878760c
RK
1217
1218int
a2369ed3 1219u_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1220{
19684119 1221 return (GET_CODE (op) == CONST_INT
c1f11548 1222 && CONST_OK_FOR_LETTER_P (INTVAL (op) & GET_MODE_MASK (mode), 'K'));
9878760c
RK
1223}
1224
dcfedcd0
RK
1225/* Return 1 if OP is a CONST_INT that cannot fit in a signed D field. */
1226
1227int
a2369ed3 1228non_short_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1229{
1230 return (GET_CODE (op) == CONST_INT
a7653a2c 1231 && (unsigned HOST_WIDE_INT) (INTVAL (op) + 0x8000) >= 0x10000);
dcfedcd0
RK
1232}
1233
2bfcf297
DB
1234/* Returns 1 if OP is a CONST_INT that is a positive value
1235 and an exact power of 2. */
1236
1237int
a2369ed3 1238exact_log2_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2bfcf297
DB
1239{
1240 return (GET_CODE (op) == CONST_INT
1241 && INTVAL (op) > 0
1242 && exact_log2 (INTVAL (op)) >= 0);
1243}
1244
9878760c
RK
1245/* Returns 1 if OP is a register that is not special (i.e., not MQ,
1246 ctr, or lr). */
1247
1248int
a2369ed3 1249gpc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1250{
1251 return (register_operand (op, mode)
802a0058 1252 && (GET_CODE (op) != REG
9ebbca7d
GK
1253 || (REGNO (op) >= ARG_POINTER_REGNUM
1254 && !XER_REGNO_P (REGNO (op)))
1255 || REGNO (op) < MQ_REGNO));
9878760c
RK
1256}
1257
1258/* Returns 1 if OP is either a pseudo-register or a register denoting a
1259 CR field. */
1260
1261int
a2369ed3 1262cc_reg_operand (rtx op, enum machine_mode mode)
9878760c
RK
1263{
1264 return (register_operand (op, mode)
1265 && (GET_CODE (op) != REG
1266 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1267 || CR_REGNO_P (REGNO (op))));
1268}
1269
815cdc52
MM
1270/* Returns 1 if OP is either a pseudo-register or a register denoting a
1271 CR field that isn't CR0. */
1272
1273int
a2369ed3 1274cc_reg_not_cr0_operand (rtx op, enum machine_mode mode)
815cdc52
MM
1275{
1276 return (register_operand (op, mode)
1277 && (GET_CODE (op) != REG
1278 || REGNO (op) >= FIRST_PSEUDO_REGISTER
1279 || CR_REGNO_NOT_CR0_P (REGNO (op))));
1280}
1281
a4f6c312
SS
1282/* Returns 1 if OP is either a constant integer valid for a D-field or
1283 a non-special register. If a register, it must be in the proper
1284 mode unless MODE is VOIDmode. */
9878760c
RK
1285
1286int
a2369ed3 1287reg_or_short_operand (rtx op, enum machine_mode mode)
9878760c 1288{
f5a28898 1289 return short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1290}
1291
a4f6c312
SS
1292/* Similar, except check if the negation of the constant would be
1293 valid for a D-field. */
9878760c
RK
1294
1295int
a2369ed3 1296reg_or_neg_short_operand (rtx op, enum machine_mode mode)
9878760c
RK
1297{
1298 if (GET_CODE (op) == CONST_INT)
1299 return CONST_OK_FOR_LETTER_P (INTVAL (op), 'P');
1300
cd2b37d9 1301 return gpc_reg_operand (op, mode);
9878760c
RK
1302}
1303
768070a0
TR
1304/* Returns 1 if OP is either a constant integer valid for a DS-field or
1305 a non-special register. If a register, it must be in the proper
1306 mode unless MODE is VOIDmode. */
1307
1308int
a2369ed3 1309reg_or_aligned_short_operand (rtx op, enum machine_mode mode)
768070a0
TR
1310{
1311 if (gpc_reg_operand (op, mode))
1312 return 1;
1313 else if (short_cint_operand (op, mode) && !(INTVAL (op) & 3))
1314 return 1;
1315
1316 return 0;
1317}
1318
1319
a4f6c312
SS
1320/* Return 1 if the operand is either a register or an integer whose
1321 high-order 16 bits are zero. */
9878760c
RK
1322
1323int
a2369ed3 1324reg_or_u_short_operand (rtx op, enum machine_mode mode)
9878760c 1325{
e675f625 1326 return u_short_cint_operand (op, mode) || gpc_reg_operand (op, mode);
9878760c
RK
1327}
1328
1329/* Return 1 is the operand is either a non-special register or ANY
1330 constant integer. */
1331
1332int
a2369ed3 1333reg_or_cint_operand (rtx op, enum machine_mode mode)
9878760c 1334{
a4f6c312 1335 return (GET_CODE (op) == CONST_INT || gpc_reg_operand (op, mode));
f6bf7de2
DE
1336}
1337
1338/* Return 1 is the operand is either a non-special register or ANY
1339 32-bit signed constant integer. */
1340
1341int
a2369ed3 1342reg_or_arith_cint_operand (rtx op, enum machine_mode mode)
f6bf7de2 1343{
a4f6c312
SS
1344 return (gpc_reg_operand (op, mode)
1345 || (GET_CODE (op) == CONST_INT
f6bf7de2 1346#if HOST_BITS_PER_WIDE_INT != 32
a4f6c312
SS
1347 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80000000)
1348 < (unsigned HOST_WIDE_INT) 0x100000000ll)
f6bf7de2 1349#endif
a4f6c312 1350 ));
9878760c
RK
1351}
1352
2bfcf297
DB
1353/* Return 1 is the operand is either a non-special register or a 32-bit
1354 signed constant integer valid for 64-bit addition. */
1355
1356int
a2369ed3 1357reg_or_add_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1358{
a4f6c312
SS
1359 return (gpc_reg_operand (op, mode)
1360 || (GET_CODE (op) == CONST_INT
a65c591c 1361#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1362 && INTVAL (op) < 0x7fff8000
a65c591c 1363#else
a4f6c312
SS
1364 && ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
1365 < 0x100000000ll)
2bfcf297 1366#endif
a4f6c312 1367 ));
2bfcf297
DB
1368}
1369
1370/* Return 1 is the operand is either a non-special register or a 32-bit
1371 signed constant integer valid for 64-bit subtraction. */
1372
1373int
a2369ed3 1374reg_or_sub_cint64_operand (rtx op, enum machine_mode mode)
2bfcf297 1375{
a4f6c312
SS
1376 return (gpc_reg_operand (op, mode)
1377 || (GET_CODE (op) == CONST_INT
a65c591c 1378#if HOST_BITS_PER_WIDE_INT == 32
a4f6c312 1379 && (- INTVAL (op)) < 0x7fff8000
a65c591c 1380#else
a4f6c312
SS
1381 && ((unsigned HOST_WIDE_INT) ((- INTVAL (op)) + 0x80008000)
1382 < 0x100000000ll)
2bfcf297 1383#endif
a4f6c312 1384 ));
2bfcf297
DB
1385}
1386
9ebbca7d
GK
1387/* Return 1 is the operand is either a non-special register or ANY
1388 32-bit unsigned constant integer. */
1389
1390int
a2369ed3 1391reg_or_logical_cint_operand (rtx op, enum machine_mode mode)
9ebbca7d 1392{
1d328b19
GK
1393 if (GET_CODE (op) == CONST_INT)
1394 {
1395 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
1396 {
1397 if (GET_MODE_BITSIZE (mode) <= 32)
a4f6c312 1398 abort ();
1d328b19
GK
1399
1400 if (INTVAL (op) < 0)
1401 return 0;
1402 }
1403
1404 return ((INTVAL (op) & GET_MODE_MASK (mode)
0858c623 1405 & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0);
1d328b19
GK
1406 }
1407 else if (GET_CODE (op) == CONST_DOUBLE)
1408 {
1409 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
1410 || mode != DImode)
a4f6c312 1411 abort ();
1d328b19
GK
1412
1413 return CONST_DOUBLE_HIGH (op) == 0;
1414 }
1415 else
1416 return gpc_reg_operand (op, mode);
9ebbca7d
GK
1417}
1418
51d3e7d6 1419/* Return 1 if the operand is an operand that can be loaded via the GOT. */
766a866c
MM
1420
1421int
a2369ed3 1422got_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
766a866c
MM
1423{
1424 return (GET_CODE (op) == SYMBOL_REF
1425 || GET_CODE (op) == CONST
1426 || GET_CODE (op) == LABEL_REF);
1427}
1428
38c1f2d7
MM
1429/* Return 1 if the operand is a simple references that can be loaded via
1430 the GOT (labels involving addition aren't allowed). */
1431
1432int
a2369ed3 1433got_no_const_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
38c1f2d7
MM
1434{
1435 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF);
1436}
1437
4e74d8ec
MM
1438/* Return the number of instructions it takes to form a constant in an
1439 integer register. */
1440
1441static int
a2369ed3 1442num_insns_constant_wide (HOST_WIDE_INT value)
4e74d8ec
MM
1443{
1444 /* signed constant loadable with {cal|addi} */
5f59ecb7 1445 if (CONST_OK_FOR_LETTER_P (value, 'I'))
0865c631
GK
1446 return 1;
1447
4e74d8ec 1448 /* constant loadable with {cau|addis} */
5f59ecb7 1449 else if (CONST_OK_FOR_LETTER_P (value, 'L'))
4e74d8ec
MM
1450 return 1;
1451
5f59ecb7 1452#if HOST_BITS_PER_WIDE_INT == 64
c81fc13e 1453 else if (TARGET_POWERPC64)
4e74d8ec 1454 {
a65c591c
DE
1455 HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000;
1456 HOST_WIDE_INT high = value >> 31;
4e74d8ec 1457
a65c591c 1458 if (high == 0 || high == -1)
4e74d8ec
MM
1459 return 2;
1460
a65c591c 1461 high >>= 1;
4e74d8ec 1462
a65c591c 1463 if (low == 0)
4e74d8ec 1464 return num_insns_constant_wide (high) + 1;
4e74d8ec
MM
1465 else
1466 return (num_insns_constant_wide (high)
e396202a 1467 + num_insns_constant_wide (low) + 1);
4e74d8ec
MM
1468 }
1469#endif
1470
1471 else
1472 return 2;
1473}
1474
1475int
a2369ed3 1476num_insns_constant (rtx op, enum machine_mode mode)
4e74d8ec 1477{
4e74d8ec 1478 if (GET_CODE (op) == CONST_INT)
0d30d435
DE
1479 {
1480#if HOST_BITS_PER_WIDE_INT == 64
4e2c1c44
DE
1481 if ((INTVAL (op) >> 31) != 0 && (INTVAL (op) >> 31) != -1
1482 && mask64_operand (op, mode))
0d30d435
DE
1483 return 2;
1484 else
1485#endif
1486 return num_insns_constant_wide (INTVAL (op));
1487 }
4e74d8ec 1488
6fc48950
MM
1489 else if (GET_CODE (op) == CONST_DOUBLE && mode == SFmode)
1490 {
1491 long l;
1492 REAL_VALUE_TYPE rv;
1493
1494 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1495 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
e72247f4 1496 return num_insns_constant_wide ((HOST_WIDE_INT) l);
6fc48950
MM
1497 }
1498
47ad8c61 1499 else if (GET_CODE (op) == CONST_DOUBLE)
4e74d8ec 1500 {
47ad8c61
MM
1501 HOST_WIDE_INT low;
1502 HOST_WIDE_INT high;
1503 long l[2];
1504 REAL_VALUE_TYPE rv;
1505 int endian = (WORDS_BIG_ENDIAN == 0);
4e74d8ec 1506
47ad8c61
MM
1507 if (mode == VOIDmode || mode == DImode)
1508 {
1509 high = CONST_DOUBLE_HIGH (op);
1510 low = CONST_DOUBLE_LOW (op);
1511 }
1512 else
1513 {
1514 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1515 REAL_VALUE_TO_TARGET_DOUBLE (rv, l);
1516 high = l[endian];
1517 low = l[1 - endian];
1518 }
4e74d8ec 1519
47ad8c61
MM
1520 if (TARGET_32BIT)
1521 return (num_insns_constant_wide (low)
1522 + num_insns_constant_wide (high));
4e74d8ec
MM
1523
1524 else
47ad8c61 1525 {
e72247f4 1526 if (high == 0 && low >= 0)
47ad8c61
MM
1527 return num_insns_constant_wide (low);
1528
e72247f4 1529 else if (high == -1 && low < 0)
47ad8c61
MM
1530 return num_insns_constant_wide (low);
1531
a260abc9
DE
1532 else if (mask64_operand (op, mode))
1533 return 2;
1534
47ad8c61
MM
1535 else if (low == 0)
1536 return num_insns_constant_wide (high) + 1;
1537
1538 else
1539 return (num_insns_constant_wide (high)
1540 + num_insns_constant_wide (low) + 1);
1541 }
4e74d8ec
MM
1542 }
1543
1544 else
1545 abort ();
1546}
1547
a4f6c312
SS
1548/* Return 1 if the operand is a CONST_DOUBLE and it can be put into a
1549 register with one instruction per word. We only do this if we can
1550 safely read CONST_DOUBLE_{LOW,HIGH}. */
9878760c
RK
1551
1552int
a2369ed3 1553easy_fp_constant (rtx op, enum machine_mode mode)
9878760c 1554{
9878760c
RK
1555 if (GET_CODE (op) != CONST_DOUBLE
1556 || GET_MODE (op) != mode
4e74d8ec 1557 || (GET_MODE_CLASS (mode) != MODE_FLOAT && mode != DImode))
9878760c
RK
1558 return 0;
1559
a4f6c312 1560 /* Consider all constants with -msoft-float to be easy. */
a3170dc6
AH
1561 if ((TARGET_SOFT_FLOAT || !TARGET_FPRS)
1562 && mode != DImode)
b6c9286a
MM
1563 return 1;
1564
a4f6c312 1565 /* If we are using V.4 style PIC, consider all constants to be hard. */
f607bc57 1566 if (flag_pic && DEFAULT_ABI == ABI_V4)
a7273471
MM
1567 return 0;
1568
5ae4759c 1569#ifdef TARGET_RELOCATABLE
a4f6c312
SS
1570 /* Similarly if we are using -mrelocatable, consider all constants
1571 to be hard. */
5ae4759c
MM
1572 if (TARGET_RELOCATABLE)
1573 return 0;
1574#endif
1575
fcce224d
DE
1576 if (mode == TFmode)
1577 {
1578 long k[4];
1579 REAL_VALUE_TYPE rv;
1580
1581 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1582 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1583
1584 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1585 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
1586 && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
1587 && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
1588 }
1589
1590 else if (mode == DFmode)
042259f2
DE
1591 {
1592 long k[2];
1593 REAL_VALUE_TYPE rv;
1594
1595 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1596 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
9878760c 1597
a65c591c
DE
1598 return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
1599 && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
042259f2 1600 }
4e74d8ec
MM
1601
1602 else if (mode == SFmode)
042259f2
DE
1603 {
1604 long l;
1605 REAL_VALUE_TYPE rv;
1606
1607 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1608 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
9878760c 1609
4e74d8ec 1610 return num_insns_constant_wide (l) == 1;
042259f2 1611 }
4e74d8ec 1612
a260abc9 1613 else if (mode == DImode)
c81fc13e 1614 return ((TARGET_POWERPC64
a260abc9
DE
1615 && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
1616 || (num_insns_constant (op, DImode) <= 2));
4e74d8ec 1617
a9098fd0
GK
1618 else if (mode == SImode)
1619 return 1;
4e74d8ec
MM
1620 else
1621 abort ();
9878760c 1622}
8f75773e 1623
72ac76be 1624/* Return nonzero if all elements of a vector have the same value. */
69ef87e2
AH
1625
1626static int
a2369ed3 1627easy_vector_same (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
d744e06e
AH
1628{
1629 int units, i, cst;
1630
1631 units = CONST_VECTOR_NUNITS (op);
1632
1633 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1634 for (i = 1; i < units; ++i)
1635 if (INTVAL (CONST_VECTOR_ELT (op, i)) != cst)
1636 break;
1637 if (i == units)
1638 return 1;
1639 return 0;
1640}
1641
1642/* Return 1 if the operand is a CONST_INT and can be put into a
1643 register without using memory. */
1644
1645int
a2369ed3 1646easy_vector_constant (rtx op, enum machine_mode mode)
69ef87e2 1647{
d744e06e 1648 int cst, cst2;
69ef87e2 1649
d744e06e
AH
1650 if (GET_CODE (op) != CONST_VECTOR
1651 || (!TARGET_ALTIVEC
1652 && !TARGET_SPE))
69ef87e2
AH
1653 return 0;
1654
d744e06e
AH
1655 if (zero_constant (op, mode)
1656 && ((TARGET_ALTIVEC && ALTIVEC_VECTOR_MODE (mode))
1657 || (TARGET_SPE && SPE_VECTOR_MODE (mode))))
1658 return 1;
69ef87e2 1659
d744e06e
AH
1660 if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
1661 return 0;
1662
f5119d10
AH
1663 if (TARGET_SPE && mode == V1DImode)
1664 return 0;
1665
d744e06e
AH
1666 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1667 cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
1668
1669 /* Limit SPE vectors to 15 bits signed. These we can generate with:
1670 li r0, CONSTANT1
1671 evmergelo r0, r0, r0
1672 li r0, CONSTANT2
1673
1674 I don't know how efficient it would be to allow bigger constants,
1675 considering we'll have an extra 'ori' for every 'li'. I doubt 5
1676 instructions is better than a 64-bit memory load, but I don't
1677 have the e500 timing specs. */
1678 if (TARGET_SPE && mode == V2SImode
1679 && cst >= -0x7fff && cst <= 0x7fff
f5119d10 1680 && cst2 >= -0x7fff && cst2 <= 0x7fff)
d744e06e
AH
1681 return 1;
1682
ce1f50b2
HP
1683 if (TARGET_ALTIVEC)
1684 switch (mode)
1685 {
1686 case V4SImode:
1687 if (EASY_VECTOR_15 (cst, op, mode))
1688 return 1;
1689 if ((cst & 0xffff) != ((cst >> 16) & 0xffff))
1690 break;
1691 cst = cst >> 16;
1692 case V8HImode:
1693 if (EASY_VECTOR_15 (cst, op, mode))
1694 return 1;
1695 if ((cst & 0xff) != ((cst >> 8) & 0xff))
1696 break;
1697 cst = cst >> 8;
1698 case V16QImode:
1699 if (EASY_VECTOR_15 (cst, op, mode))
1700 return 1;
1701 default:
1702 break;
1703 }
d744e06e
AH
1704
1705 if (TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode))
1706 return 1;
1707
1708 return 0;
1709}
1710
1711/* Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF. */
1712
1713int
a2369ed3 1714easy_vector_constant_add_self (rtx op, enum machine_mode mode)
d744e06e
AH
1715{
1716 int cst;
1717
1718 if (!easy_vector_constant (op, mode))
1719 return 0;
1720
1721 cst = INTVAL (CONST_VECTOR_ELT (op, 0));
1722
1723 return TARGET_ALTIVEC && EASY_VECTOR_15_ADD_SELF (cst, op, mode);
1724}
1725
1726const char *
a2369ed3 1727output_vec_const_move (rtx *operands)
d744e06e
AH
1728{
1729 int cst, cst2;
1730 enum machine_mode mode;
1731 rtx dest, vec;
1732
1733 dest = operands[0];
1734 vec = operands[1];
69ef87e2 1735
d744e06e
AH
1736 cst = INTVAL (CONST_VECTOR_ELT (vec, 0));
1737 cst2 = INTVAL (CONST_VECTOR_ELT (vec, 1));
1738 mode = GET_MODE (dest);
69ef87e2 1739
d744e06e
AH
1740 if (TARGET_ALTIVEC)
1741 {
1742 if (zero_constant (vec, mode))
1743 return "vxor %0,%0,%0";
ce1f50b2
HP
1744 else if (EASY_VECTOR_15_ADD_SELF (cst, vec, mode))
1745 return "#";
1746 else if (easy_vector_constant (vec, mode))
98ef3137 1747 {
d744e06e
AH
1748 operands[1] = GEN_INT (cst);
1749 switch (mode)
1750 {
1751 case V4SImode:
ce1f50b2
HP
1752 if (EASY_VECTOR_15 (cst, vec, mode))
1753 {
1754 operands[1] = GEN_INT (cst);
1755 return "vspltisw %0,%1";
1756 }
1757 cst = cst >> 16;
d744e06e 1758 case V8HImode:
ce1f50b2
HP
1759 if (EASY_VECTOR_15 (cst, vec, mode))
1760 {
1761 operands[1] = GEN_INT (cst);
1762 return "vspltish %0,%1";
1763 }
1764 cst = cst >> 8;
d744e06e 1765 case V16QImode:
ce1f50b2
HP
1766 if (EASY_VECTOR_15 (cst, vec, mode))
1767 {
1768 operands[1] = GEN_INT (cst);
1769 return "vspltisb %0,%1";
1770 }
d744e06e
AH
1771 default:
1772 abort ();
1773 }
98ef3137 1774 }
d744e06e
AH
1775 else
1776 abort ();
69ef87e2
AH
1777 }
1778
d744e06e
AH
1779 if (TARGET_SPE)
1780 {
1781 /* Vector constant 0 is handled as a splitter of V2SI, and in the
1782 pattern of V1DI, V4HI, and V2SF.
1783
c1207243 1784 FIXME: We should probably return # and add post reload
d744e06e
AH
1785 splitters for these, but this way is so easy ;-).
1786 */
1787 operands[1] = GEN_INT (cst);
1788 operands[2] = GEN_INT (cst2);
1789 if (cst == cst2)
1790 return "li %0,%1\n\tevmergelo %0,%0,%0";
1791 else
1792 return "li %0,%1\n\tevmergelo %0,%0,%0\n\tli %0,%2";
1793 }
1794
1795 abort ();
69ef87e2
AH
1796}
1797
1798/* Return 1 if the operand is the constant 0. This works for scalars
1799 as well as vectors. */
1800int
a2369ed3 1801zero_constant (rtx op, enum machine_mode mode)
69ef87e2
AH
1802{
1803 return op == CONST0_RTX (mode);
1804}
1805
50a0b056
GK
1806/* Return 1 if the operand is 0.0. */
1807int
a2369ed3 1808zero_fp_constant (rtx op, enum machine_mode mode)
50a0b056
GK
1809{
1810 return GET_MODE_CLASS (mode) == MODE_FLOAT && op == CONST0_RTX (mode);
1811}
1812
a4f6c312
SS
1813/* Return 1 if the operand is in volatile memory. Note that during
1814 the RTL generation phase, memory_operand does not return TRUE for
b6c9286a
MM
1815 volatile memory references. So this function allows us to
1816 recognize volatile references where its safe. */
1817
1818int
a2369ed3 1819volatile_mem_operand (rtx op, enum machine_mode mode)
b6c9286a
MM
1820{
1821 if (GET_CODE (op) != MEM)
1822 return 0;
1823
1824 if (!MEM_VOLATILE_P (op))
1825 return 0;
1826
1827 if (mode != GET_MODE (op))
1828 return 0;
1829
1830 if (reload_completed)
1831 return memory_operand (op, mode);
1832
1833 if (reload_in_progress)
1834 return strict_memory_address_p (mode, XEXP (op, 0));
1835
1836 return memory_address_p (mode, XEXP (op, 0));
1837}
1838
97f6e72f 1839/* Return 1 if the operand is an offsettable memory operand. */
914c2e77
RK
1840
1841int
a2369ed3 1842offsettable_mem_operand (rtx op, enum machine_mode mode)
914c2e77 1843{
97f6e72f 1844 return ((GET_CODE (op) == MEM)
677a9668 1845 && offsettable_address_p (reload_completed || reload_in_progress,
97f6e72f 1846 mode, XEXP (op, 0)));
914c2e77
RK
1847}
1848
9878760c
RK
1849/* Return 1 if the operand is either an easy FP constant (see above) or
1850 memory. */
1851
1852int
a2369ed3 1853mem_or_easy_const_operand (rtx op, enum machine_mode mode)
9878760c
RK
1854{
1855 return memory_operand (op, mode) || easy_fp_constant (op, mode);
1856}
1857
1858/* Return 1 if the operand is either a non-special register or an item
5f59ecb7 1859 that can be used as the operand of a `mode' add insn. */
9878760c
RK
1860
1861int
a2369ed3 1862add_operand (rtx op, enum machine_mode mode)
9878760c 1863{
2bfcf297 1864 if (GET_CODE (op) == CONST_INT)
e72247f4
DE
1865 return (CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1866 || CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
2bfcf297
DB
1867
1868 return gpc_reg_operand (op, mode);
9878760c
RK
1869}
1870
dcfedcd0
RK
1871/* Return 1 if OP is a constant but not a valid add_operand. */
1872
1873int
a2369ed3 1874non_add_cint_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dcfedcd0
RK
1875{
1876 return (GET_CODE (op) == CONST_INT
e72247f4
DE
1877 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'I')
1878 && !CONST_OK_FOR_LETTER_P (INTVAL (op), 'L'));
dcfedcd0
RK
1879}
1880
9878760c
RK
1881/* Return 1 if the operand is a non-special register or a constant that
1882 can be used as the operand of an OR or XOR insn on the RS/6000. */
1883
1884int
a2369ed3 1885logical_operand (rtx op, enum machine_mode mode)
9878760c 1886{
40501e5f 1887 HOST_WIDE_INT opl, oph;
1d328b19 1888
dfbdccdb
GK
1889 if (gpc_reg_operand (op, mode))
1890 return 1;
1d328b19 1891
dfbdccdb 1892 if (GET_CODE (op) == CONST_INT)
40501e5f
AM
1893 {
1894 opl = INTVAL (op) & GET_MODE_MASK (mode);
1895
1896#if HOST_BITS_PER_WIDE_INT <= 32
1897 if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
1898 return 0;
1899#endif
1900 }
dfbdccdb
GK
1901 else if (GET_CODE (op) == CONST_DOUBLE)
1902 {
1d328b19 1903 if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
40501e5f 1904 abort ();
1d328b19
GK
1905
1906 opl = CONST_DOUBLE_LOW (op);
1907 oph = CONST_DOUBLE_HIGH (op);
40501e5f 1908 if (oph != 0)
38886f37 1909 return 0;
dfbdccdb
GK
1910 }
1911 else
1912 return 0;
1d328b19 1913
40501e5f
AM
1914 return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
1915 || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
9878760c
RK
1916}
1917
dcfedcd0 1918/* Return 1 if C is a constant that is not a logical operand (as
1d328b19 1919 above), but could be split into one. */
dcfedcd0
RK
1920
1921int
a2369ed3 1922non_logical_cint_operand (rtx op, enum machine_mode mode)
dcfedcd0 1923{
dfbdccdb 1924 return ((GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE)
1d328b19
GK
1925 && ! logical_operand (op, mode)
1926 && reg_or_logical_cint_operand (op, mode));
dcfedcd0
RK
1927}
1928
19ba8161 1929/* Return 1 if C is a constant that can be encoded in a 32-bit mask on the
9878760c
RK
1930 RS/6000. It is if there are no more than two 1->0 or 0->1 transitions.
1931 Reject all ones and all zeros, since these should have been optimized
1932 away and confuse the making of MB and ME. */
1933
1934int
a2369ed3 1935mask_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c 1936{
02071907 1937 HOST_WIDE_INT c, lsb;
9878760c 1938
19ba8161
DE
1939 if (GET_CODE (op) != CONST_INT)
1940 return 0;
1941
1942 c = INTVAL (op);
1943
57deb3a1
AM
1944 /* Fail in 64-bit mode if the mask wraps around because the upper
1945 32-bits of the mask will all be 1s, contrary to GCC's internal view. */
1946 if (TARGET_POWERPC64 && (c & 0x80000001) == 0x80000001)
1947 return 0;
1948
c5059423
AM
1949 /* We don't change the number of transitions by inverting,
1950 so make sure we start with the LS bit zero. */
1951 if (c & 1)
1952 c = ~c;
1953
1954 /* Reject all zeros or all ones. */
1955 if (c == 0)
9878760c
RK
1956 return 0;
1957
c5059423
AM
1958 /* Find the first transition. */
1959 lsb = c & -c;
1960
1961 /* Invert to look for a second transition. */
1962 c = ~c;
9878760c 1963
c5059423
AM
1964 /* Erase first transition. */
1965 c &= -lsb;
9878760c 1966
c5059423
AM
1967 /* Find the second transition (if any). */
1968 lsb = c & -c;
1969
1970 /* Match if all the bits above are 1's (or c is zero). */
1971 return c == -lsb;
9878760c
RK
1972}
1973
0ba1b2ff
AM
1974/* Return 1 for the PowerPC64 rlwinm corner case. */
1975
1976int
a2369ed3 1977mask_operand_wrap (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
1978{
1979 HOST_WIDE_INT c, lsb;
1980
1981 if (GET_CODE (op) != CONST_INT)
1982 return 0;
1983
1984 c = INTVAL (op);
1985
1986 if ((c & 0x80000001) != 0x80000001)
1987 return 0;
1988
1989 c = ~c;
1990 if (c == 0)
1991 return 0;
1992
1993 lsb = c & -c;
1994 c = ~c;
1995 c &= -lsb;
1996 lsb = c & -c;
1997 return c == -lsb;
1998}
1999
a260abc9
DE
2000/* Return 1 if the operand is a constant that is a PowerPC64 mask.
2001 It is if there are no more than one 1->0 or 0->1 transitions.
0ba1b2ff
AM
2002 Reject all zeros, since zero should have been optimized away and
2003 confuses the making of MB and ME. */
9878760c
RK
2004
2005int
a2369ed3 2006mask64_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
a260abc9
DE
2007{
2008 if (GET_CODE (op) == CONST_INT)
2009 {
02071907 2010 HOST_WIDE_INT c, lsb;
a260abc9 2011
c5059423 2012 c = INTVAL (op);
a260abc9 2013
0ba1b2ff 2014 /* Reject all zeros. */
c5059423 2015 if (c == 0)
e2c953b6
DE
2016 return 0;
2017
0ba1b2ff
AM
2018 /* We don't change the number of transitions by inverting,
2019 so make sure we start with the LS bit zero. */
2020 if (c & 1)
2021 c = ~c;
2022
c5059423
AM
2023 /* Find the transition, and check that all bits above are 1's. */
2024 lsb = c & -c;
e3981aab
DE
2025
2026 /* Match if all the bits above are 1's (or c is zero). */
c5059423 2027 return c == -lsb;
e2c953b6 2028 }
0ba1b2ff
AM
2029 return 0;
2030}
2031
2032/* Like mask64_operand, but allow up to three transitions. This
2033 predicate is used by insn patterns that generate two rldicl or
2034 rldicr machine insns. */
2035
2036int
a2369ed3 2037mask64_2_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
0ba1b2ff
AM
2038{
2039 if (GET_CODE (op) == CONST_INT)
a260abc9 2040 {
0ba1b2ff 2041 HOST_WIDE_INT c, lsb;
a260abc9 2042
0ba1b2ff 2043 c = INTVAL (op);
a260abc9 2044
0ba1b2ff
AM
2045 /* Disallow all zeros. */
2046 if (c == 0)
2047 return 0;
a260abc9 2048
0ba1b2ff
AM
2049 /* We don't change the number of transitions by inverting,
2050 so make sure we start with the LS bit zero. */
2051 if (c & 1)
2052 c = ~c;
a260abc9 2053
0ba1b2ff
AM
2054 /* Find the first transition. */
2055 lsb = c & -c;
a260abc9 2056
0ba1b2ff
AM
2057 /* Invert to look for a second transition. */
2058 c = ~c;
2059
2060 /* Erase first transition. */
2061 c &= -lsb;
2062
2063 /* Find the second transition. */
2064 lsb = c & -c;
2065
2066 /* Invert to look for a third transition. */
2067 c = ~c;
2068
2069 /* Erase second transition. */
2070 c &= -lsb;
2071
2072 /* Find the third transition (if any). */
2073 lsb = c & -c;
2074
2075 /* Match if all the bits above are 1's (or c is zero). */
2076 return c == -lsb;
2077 }
2078 return 0;
2079}
2080
2081/* Generates shifts and masks for a pair of rldicl or rldicr insns to
2082 implement ANDing by the mask IN. */
2083void
a2369ed3 2084build_mask64_2_operands (rtx in, rtx *out)
0ba1b2ff
AM
2085{
2086#if HOST_BITS_PER_WIDE_INT >= 64
2087 unsigned HOST_WIDE_INT c, lsb, m1, m2;
2088 int shift;
2089
2090 if (GET_CODE (in) != CONST_INT)
2091 abort ();
2092
2093 c = INTVAL (in);
2094 if (c & 1)
2095 {
2096 /* Assume c initially something like 0x00fff000000fffff. The idea
2097 is to rotate the word so that the middle ^^^^^^ group of zeros
2098 is at the MS end and can be cleared with an rldicl mask. We then
2099 rotate back and clear off the MS ^^ group of zeros with a
2100 second rldicl. */
2101 c = ~c; /* c == 0xff000ffffff00000 */
2102 lsb = c & -c; /* lsb == 0x0000000000100000 */
2103 m1 = -lsb; /* m1 == 0xfffffffffff00000 */
2104 c = ~c; /* c == 0x00fff000000fffff */
2105 c &= -lsb; /* c == 0x00fff00000000000 */
2106 lsb = c & -c; /* lsb == 0x0000100000000000 */
2107 c = ~c; /* c == 0xff000fffffffffff */
2108 c &= -lsb; /* c == 0xff00000000000000 */
2109 shift = 0;
2110 while ((lsb >>= 1) != 0)
2111 shift++; /* shift == 44 on exit from loop */
2112 m1 <<= 64 - shift; /* m1 == 0xffffff0000000000 */
2113 m1 = ~m1; /* m1 == 0x000000ffffffffff */
2114 m2 = ~c; /* m2 == 0x00ffffffffffffff */
a260abc9
DE
2115 }
2116 else
0ba1b2ff
AM
2117 {
2118 /* Assume c initially something like 0xff000f0000000000. The idea
2119 is to rotate the word so that the ^^^ middle group of zeros
2120 is at the LS end and can be cleared with an rldicr mask. We then
2121 rotate back and clear off the LS group of ^^^^^^^^^^ zeros with
2122 a second rldicr. */
2123 lsb = c & -c; /* lsb == 0x0000010000000000 */
2124 m2 = -lsb; /* m2 == 0xffffff0000000000 */
2125 c = ~c; /* c == 0x00fff0ffffffffff */
2126 c &= -lsb; /* c == 0x00fff00000000000 */
2127 lsb = c & -c; /* lsb == 0x0000100000000000 */
2128 c = ~c; /* c == 0xff000fffffffffff */
2129 c &= -lsb; /* c == 0xff00000000000000 */
2130 shift = 0;
2131 while ((lsb >>= 1) != 0)
2132 shift++; /* shift == 44 on exit from loop */
2133 m1 = ~c; /* m1 == 0x00ffffffffffffff */
2134 m1 >>= shift; /* m1 == 0x0000000000000fff */
2135 m1 = ~m1; /* m1 == 0xfffffffffffff000 */
2136 }
2137
2138 /* Note that when we only have two 0->1 and 1->0 transitions, one of the
2139 masks will be all 1's. We are guaranteed more than one transition. */
2140 out[0] = GEN_INT (64 - shift);
2141 out[1] = GEN_INT (m1);
2142 out[2] = GEN_INT (shift);
2143 out[3] = GEN_INT (m2);
2144#else
045572c7
GK
2145 (void)in;
2146 (void)out;
0ba1b2ff
AM
2147 abort ();
2148#endif
a260abc9
DE
2149}
2150
2151/* Return 1 if the operand is either a non-special register or a constant
2152 that can be used as the operand of a PowerPC64 logical AND insn. */
2153
2154int
a2369ed3 2155and64_operand (rtx op, enum machine_mode mode)
9878760c 2156{
a4f6c312 2157 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2158 return (gpc_reg_operand (op, mode) || mask64_operand (op, mode));
2159
2160 return (logical_operand (op, mode) || mask64_operand (op, mode));
9878760c
RK
2161}
2162
0ba1b2ff
AM
2163/* Like the above, but also match constants that can be implemented
2164 with two rldicl or rldicr insns. */
2165
2166int
a2369ed3 2167and64_2_operand (rtx op, enum machine_mode mode)
0ba1b2ff 2168{
a3c9585f 2169 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
0ba1b2ff
AM
2170 return gpc_reg_operand (op, mode) || mask64_2_operand (op, mode);
2171
2172 return logical_operand (op, mode) || mask64_2_operand (op, mode);
2173}
2174
a260abc9
DE
2175/* Return 1 if the operand is either a non-special register or a
2176 constant that can be used as the operand of an RS/6000 logical AND insn. */
dcfedcd0
RK
2177
2178int
a2369ed3 2179and_operand (rtx op, enum machine_mode mode)
dcfedcd0 2180{
a4f6c312 2181 if (fixed_regs[CR0_REGNO]) /* CR0 not available, don't do andi./andis. */
52d3af72
DE
2182 return (gpc_reg_operand (op, mode) || mask_operand (op, mode));
2183
2184 return (logical_operand (op, mode) || mask_operand (op, mode));
dcfedcd0
RK
2185}
2186
9878760c
RK
2187/* Return 1 if the operand is a general register or memory operand. */
2188
2189int
a2369ed3 2190reg_or_mem_operand (rtx op, enum machine_mode mode)
9878760c 2191{
b6c9286a
MM
2192 return (gpc_reg_operand (op, mode)
2193 || memory_operand (op, mode)
4c81e946 2194 || macho_lo_sum_memory_operand (op, mode)
b6c9286a 2195 || volatile_mem_operand (op, mode));
9878760c
RK
2196}
2197
a7a813f7 2198/* Return 1 if the operand is a general register or memory operand without
3cb999d8 2199 pre_inc or pre_dec which produces invalid form of PowerPC lwa
a7a813f7
RK
2200 instruction. */
2201
2202int
a2369ed3 2203lwa_operand (rtx op, enum machine_mode mode)
a7a813f7
RK
2204{
2205 rtx inner = op;
2206
2207 if (reload_completed && GET_CODE (inner) == SUBREG)
2208 inner = SUBREG_REG (inner);
2209
2210 return gpc_reg_operand (inner, mode)
2211 || (memory_operand (inner, mode)
2212 && GET_CODE (XEXP (inner, 0)) != PRE_INC
6a40a9d6
DE
2213 && GET_CODE (XEXP (inner, 0)) != PRE_DEC
2214 && (GET_CODE (XEXP (inner, 0)) != PLUS
e903c96a
DE
2215 || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
2216 || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
a7a813f7
RK
2217}
2218
cc4d5fec
JH
2219/* Return 1 if the operand, used inside a MEM, is a SYMBOL_REF. */
2220
2221int
a2369ed3 2222symbol_ref_operand (rtx op, enum machine_mode mode)
cc4d5fec
JH
2223{
2224 if (mode != VOIDmode && GET_MODE (op) != mode)
2225 return 0;
2226
473f51b6
DE
2227 return (GET_CODE (op) == SYMBOL_REF
2228 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op)));
cc4d5fec
JH
2229}
2230
9878760c 2231/* Return 1 if the operand, used inside a MEM, is a valid first argument
cc4d5fec 2232 to CALL. This is a SYMBOL_REF, a pseudo-register, LR or CTR. */
9878760c
RK
2233
2234int
a2369ed3 2235call_operand (rtx op, enum machine_mode mode)
9878760c
RK
2236{
2237 if (mode != VOIDmode && GET_MODE (op) != mode)
2238 return 0;
2239
2240 return (GET_CODE (op) == SYMBOL_REF
cc4d5fec
JH
2241 || (GET_CODE (op) == REG
2242 && (REGNO (op) == LINK_REGISTER_REGNUM
2243 || REGNO (op) == COUNT_REGISTER_REGNUM
2244 || REGNO (op) >= FIRST_PSEUDO_REGISTER)));
9878760c
RK
2245}
2246
2af3d377 2247/* Return 1 if the operand is a SYMBOL_REF for a function known to be in
d1908feb 2248 this file. */
2af3d377
RK
2249
2250int
a2369ed3
DJ
2251current_file_function_operand (rtx op,
2252 enum machine_mode mode ATTRIBUTE_UNUSED)
2af3d377 2253{
473f51b6
DE
2254 return (GET_CODE (op) == SYMBOL_REF
2255 && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
2256 && (SYMBOL_REF_LOCAL_P (op)
2257 || (op == XEXP (DECL_RTL (current_function_decl), 0))));
2af3d377
RK
2258}
2259
9878760c
RK
2260/* Return 1 if this operand is a valid input for a move insn. */
2261
2262int
a2369ed3 2263input_operand (rtx op, enum machine_mode mode)
9878760c 2264{
eb4e8003 2265 /* Memory is always valid. */
9878760c
RK
2266 if (memory_operand (op, mode))
2267 return 1;
2268
34792e82 2269 /* Only a tiny bit of handling for CONSTANT_P_RTX is necessary. */
01b4cf2b 2270 if (GET_CODE (op) == CONSTANT_P_RTX)
34792e82
JL
2271 return 1;
2272
eb4e8003
RK
2273 /* For floating-point, easy constants are valid. */
2274 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2275 && CONSTANT_P (op)
2276 && easy_fp_constant (op, mode))
2277 return 1;
2278
4e74d8ec
MM
2279 /* Allow any integer constant. */
2280 if (GET_MODE_CLASS (mode) == MODE_INT
e675f625 2281 && (GET_CODE (op) == CONST_INT
e675f625 2282 || GET_CODE (op) == CONST_DOUBLE))
4e74d8ec
MM
2283 return 1;
2284
d744e06e
AH
2285 /* Allow easy vector constants. */
2286 if (GET_CODE (op) == CONST_VECTOR
2287 && easy_vector_constant (op, mode))
2288 return 1;
2289
eb4e8003
RK
2290 /* For floating-point or multi-word mode, the only remaining valid type
2291 is a register. */
9878760c
RK
2292 if (GET_MODE_CLASS (mode) == MODE_FLOAT
2293 || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
eb4e8003 2294 return register_operand (op, mode);
9878760c 2295
88fe15a1
RK
2296 /* The only cases left are integral modes one word or smaller (we
2297 do not get called for MODE_CC values). These can be in any
2298 register. */
2299 if (register_operand (op, mode))
a8b3aeda 2300 return 1;
88fe15a1 2301
84cf9dda 2302 /* A SYMBOL_REF referring to the TOC is valid. */
4d588c14 2303 if (legitimate_constant_pool_address_p (op))
84cf9dda
RK
2304 return 1;
2305
9ebbca7d 2306 /* A constant pool expression (relative to the TOC) is valid */
4d588c14 2307 if (toc_relative_expr_p (op))
b6c9286a
MM
2308 return 1;
2309
88228c4b
MM
2310 /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
2311 to be valid. */
f607bc57 2312 if (DEFAULT_ABI == ABI_V4
88228c4b
MM
2313 && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
2314 && small_data_operand (op, Pmode))
2315 return 1;
2316
042259f2 2317 return 0;
9878760c 2318}
7509c759 2319
95727fb8
AP
2320
2321/* Darwin, AIX increases natural record alignment to doubleword if the first
2322 field is an FP double while the FP fields remain word aligned. */
2323
19d66194 2324unsigned int
95727fb8
AP
2325rs6000_special_round_type_align (tree type, int computed, int specified)
2326{
2327 tree field = TYPE_FIELDS (type);
95727fb8
AP
2328
2329 /* Skip all the static variables only if ABI is greater than
2330 1 or equal to 0. */
3ce5437a 2331 while (field != NULL && TREE_CODE (field) == VAR_DECL)
95727fb8
AP
2332 field = TREE_CHAIN (field);
2333
3ce5437a 2334 if (field == NULL || field == type || DECL_MODE (field) != DFmode)
95727fb8
AP
2335 return MAX (computed, specified);
2336
2337 return MAX (MAX (computed, specified), 64);
2338}
2339
a4f6c312 2340/* Return 1 for an operand in small memory on V.4/eabi. */
7509c759
MM
2341
2342int
a2369ed3
DJ
2343small_data_operand (rtx op ATTRIBUTE_UNUSED,
2344 enum machine_mode mode ATTRIBUTE_UNUSED)
7509c759 2345{
38c1f2d7 2346#if TARGET_ELF
5f59ecb7 2347 rtx sym_ref;
7509c759 2348
d9407988 2349 if (rs6000_sdata == SDATA_NONE || rs6000_sdata == SDATA_DATA)
a54d04b7 2350 return 0;
a54d04b7 2351
f607bc57 2352 if (DEFAULT_ABI != ABI_V4)
7509c759
MM
2353 return 0;
2354
88228c4b
MM
2355 if (GET_CODE (op) == SYMBOL_REF)
2356 sym_ref = op;
2357
2358 else if (GET_CODE (op) != CONST
2359 || GET_CODE (XEXP (op, 0)) != PLUS
2360 || GET_CODE (XEXP (XEXP (op, 0), 0)) != SYMBOL_REF
2361 || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT)
7509c759
MM
2362 return 0;
2363
88228c4b 2364 else
dbf55e53
MM
2365 {
2366 rtx sum = XEXP (op, 0);
2367 HOST_WIDE_INT summand;
2368
2369 /* We have to be careful here, because it is the referenced address
2370 that must be 32k from _SDA_BASE_, not just the symbol. */
2371 summand = INTVAL (XEXP (sum, 1));
307b599c 2372 if (summand < 0 || (unsigned HOST_WIDE_INT) summand > g_switch_value)
dbf55e53
MM
2373 return 0;
2374
2375 sym_ref = XEXP (sum, 0);
2376 }
88228c4b 2377
20bfcd69 2378 return SYMBOL_REF_SMALL_P (sym_ref);
d9407988
MM
2379#else
2380 return 0;
2381#endif
7509c759 2382}
46c07df8 2383
d2288d5d
HP
2384/* Return true, if operand is a memory operand and has a
2385 displacement divisible by 4. */
2386
2387int
2388word_offset_memref_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2389{
2390 rtx addr;
2391 int off = 0;
2392
2393 if (!memory_operand (op, mode))
2394 return 0;
2395
2396 addr = XEXP (op, 0);
2397 if (GET_CODE (addr) == PLUS
2398 && GET_CODE (XEXP (addr, 0)) == REG
2399 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2400 off = INTVAL (XEXP (addr, 1));
2401
2402 return (off % 4) == 0;
2403}
2404
3a1f863f 2405/* Return true if either operand is a general purpose register. */
46c07df8 2406
3a1f863f
DE
2407bool
2408gpr_or_gpr_p (rtx op0, rtx op1)
46c07df8 2409{
3a1f863f
DE
2410 return ((REG_P (op0) && INT_REGNO_P (REGNO (op0)))
2411 || (REG_P (op1) && INT_REGNO_P (REGNO (op1))));
46c07df8
HP
2412}
2413
9ebbca7d 2414\f
4d588c14
RH
2415/* Subroutines of rs6000_legitimize_address and rs6000_legitimate_address. */
2416
9ebbca7d 2417static int
a2369ed3 2418constant_pool_expr_1 (rtx op, int *have_sym, int *have_toc)
9ebbca7d
GK
2419{
2420 switch (GET_CODE(op))
2421 {
2422 case SYMBOL_REF:
c4501e62
JJ
2423 if (RS6000_SYMBOL_REF_TLS_P (op))
2424 return 0;
2425 else if (CONSTANT_POOL_ADDRESS_P (op))
a4f6c312
SS
2426 {
2427 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (op), Pmode))
2428 {
2429 *have_sym = 1;
2430 return 1;
2431 }
2432 else
2433 return 0;
2434 }
2435 else if (! strcmp (XSTR (op, 0), toc_label_name))
2436 {
2437 *have_toc = 1;
2438 return 1;
2439 }
2440 else
2441 return 0;
9ebbca7d
GK
2442 case PLUS:
2443 case MINUS:
c1f11548
DE
2444 return (constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc)
2445 && constant_pool_expr_1 (XEXP (op, 1), have_sym, have_toc));
9ebbca7d 2446 case CONST:
a4f6c312 2447 return constant_pool_expr_1 (XEXP (op, 0), have_sym, have_toc);
9ebbca7d 2448 case CONST_INT:
a4f6c312 2449 return 1;
9ebbca7d 2450 default:
a4f6c312 2451 return 0;
9ebbca7d
GK
2452 }
2453}
2454
4d588c14 2455static bool
a2369ed3 2456constant_pool_expr_p (rtx op)
9ebbca7d
GK
2457{
2458 int have_sym = 0;
2459 int have_toc = 0;
2460 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_sym;
2461}
2462
4d588c14 2463static bool
a2369ed3 2464toc_relative_expr_p (rtx op)
9ebbca7d 2465{
4d588c14
RH
2466 int have_sym = 0;
2467 int have_toc = 0;
2468 return constant_pool_expr_1 (op, &have_sym, &have_toc) && have_toc;
2469}
2470
2471/* SPE offset addressing is limited to 5-bits worth of double words. */
2472#define SPE_CONST_OFFSET_OK(x) (((x) & ~0xf8) == 0)
2473
2474bool
a2369ed3 2475legitimate_constant_pool_address_p (rtx x)
4d588c14
RH
2476{
2477 return (TARGET_TOC
2478 && GET_CODE (x) == PLUS
2479 && GET_CODE (XEXP (x, 0)) == REG
2480 && (TARGET_MINIMAL_TOC || REGNO (XEXP (x, 0)) == TOC_REGISTER)
2481 && constant_pool_expr_p (XEXP (x, 1)));
2482}
2483
2484static bool
a2369ed3 2485legitimate_small_data_p (enum machine_mode mode, rtx x)
4d588c14
RH
2486{
2487 return (DEFAULT_ABI == ABI_V4
2488 && !flag_pic && !TARGET_TOC
2489 && (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST)
2490 && small_data_operand (x, mode));
2491}
2492
2493static bool
a2369ed3 2494legitimate_offset_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2495{
2496 unsigned HOST_WIDE_INT offset, extra;
2497
2498 if (GET_CODE (x) != PLUS)
2499 return false;
2500 if (GET_CODE (XEXP (x, 0)) != REG)
2501 return false;
2502 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2503 return false;
2504 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2505 return false;
2506
2507 offset = INTVAL (XEXP (x, 1));
2508 extra = 0;
2509 switch (mode)
2510 {
2511 case V16QImode:
2512 case V8HImode:
2513 case V4SFmode:
2514 case V4SImode:
2515 /* AltiVec vector modes. Only reg+reg addressing is valid here,
2516 which leaves the only valid constant offset of zero, which by
2517 canonicalization rules is also invalid. */
2518 return false;
2519
2520 case V4HImode:
2521 case V2SImode:
2522 case V1DImode:
2523 case V2SFmode:
2524 /* SPE vector modes. */
2525 return SPE_CONST_OFFSET_OK (offset);
2526
2527 case DFmode:
2528 case DImode:
3364872d 2529 if (mode == DFmode || !TARGET_POWERPC64)
4d588c14
RH
2530 extra = 4;
2531 else if (offset & 3)
2532 return false;
2533 break;
2534
2535 case TFmode:
2536 case TImode:
3364872d 2537 if (mode == TFmode || !TARGET_POWERPC64)
4d588c14
RH
2538 extra = 12;
2539 else if (offset & 3)
2540 return false;
2541 else
2542 extra = 8;
2543 break;
2544
2545 default:
2546 break;
2547 }
2548
2549 return (offset + extra >= offset) && (offset + extra + 0x8000 < 0x10000);
2550}
2551
2552static bool
a2369ed3 2553legitimate_indexed_address_p (rtx x, int strict)
4d588c14
RH
2554{
2555 rtx op0, op1;
2556
2557 if (GET_CODE (x) != PLUS)
2558 return false;
2559 op0 = XEXP (x, 0);
2560 op1 = XEXP (x, 1);
2561
2562 if (!REG_P (op0) || !REG_P (op1))
2563 return false;
2564
2565 return ((INT_REG_OK_FOR_BASE_P (op0, strict)
2566 && INT_REG_OK_FOR_INDEX_P (op1, strict))
2567 || (INT_REG_OK_FOR_BASE_P (op1, strict)
2568 && INT_REG_OK_FOR_INDEX_P (op0, strict)));
9ebbca7d
GK
2569}
2570
4d588c14 2571static inline bool
a2369ed3 2572legitimate_indirect_address_p (rtx x, int strict)
4d588c14
RH
2573{
2574 return GET_CODE (x) == REG && INT_REG_OK_FOR_BASE_P (x, strict);
2575}
2576
4c81e946
FJ
2577static bool
2578macho_lo_sum_memory_operand (rtx x, enum machine_mode mode)
2579{
2580 if (!TARGET_MACHO || !flag_pic
2581 || mode != SImode || GET_CODE(x) != MEM)
2582 return false;
2583 x = XEXP (x, 0);
2584
2585 if (GET_CODE (x) != LO_SUM)
2586 return false;
2587 if (GET_CODE (XEXP (x, 0)) != REG)
2588 return false;
2589 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), 0))
2590 return false;
2591 x = XEXP (x, 1);
2592
2593 return CONSTANT_P (x);
2594}
2595
4d588c14 2596static bool
a2369ed3 2597legitimate_lo_sum_address_p (enum machine_mode mode, rtx x, int strict)
4d588c14
RH
2598{
2599 if (GET_CODE (x) != LO_SUM)
2600 return false;
2601 if (GET_CODE (XEXP (x, 0)) != REG)
2602 return false;
2603 if (!INT_REG_OK_FOR_BASE_P (XEXP (x, 0), strict))
2604 return false;
2605 x = XEXP (x, 1);
2606
8622e235 2607 if (TARGET_ELF || TARGET_MACHO)
4d588c14 2608 {
a29077da 2609 if (DEFAULT_ABI != ABI_AIX && DEFAULT_ABI != ABI_DARWIN && flag_pic)
4d588c14
RH
2610 return false;
2611 if (TARGET_TOC)
2612 return false;
2613 if (GET_MODE_NUNITS (mode) != 1)
2614 return false;
2615 if (GET_MODE_BITSIZE (mode) > 32
2616 && !(TARGET_HARD_FLOAT && TARGET_FPRS && mode == DFmode))
2617 return false;
2618
2619 return CONSTANT_P (x);
2620 }
2621
2622 return false;
2623}
2624
2625
9ebbca7d
GK
2626/* Try machine-dependent ways of modifying an illegitimate address
2627 to be legitimate. If we find one, return the new, valid address.
2628 This is used from only one place: `memory_address' in explow.c.
2629
a4f6c312
SS
2630 OLDX is the address as it was before break_out_memory_refs was
2631 called. In some cases it is useful to look at this to decide what
2632 needs to be done.
9ebbca7d 2633
a4f6c312 2634 MODE is passed so that this function can use GO_IF_LEGITIMATE_ADDRESS.
9ebbca7d 2635
a4f6c312
SS
2636 It is always safe for this function to do nothing. It exists to
2637 recognize opportunities to optimize the output.
9ebbca7d
GK
2638
2639 On RS/6000, first check for the sum of a register with a constant
2640 integer that is out of range. If so, generate code to add the
2641 constant with the low-order 16 bits masked to the register and force
2642 this result into another register (this can be done with `cau').
2643 Then generate an address of REG+(CONST&0xffff), allowing for the
2644 possibility of bit 16 being a one.
2645
2646 Then check for the sum of a register and something not constant, try to
2647 load the other things into a register and return the sum. */
4d588c14 2648
9ebbca7d 2649rtx
a2369ed3
DJ
2650rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
2651 enum machine_mode mode)
0ac081f6 2652{
c4501e62
JJ
2653 if (GET_CODE (x) == SYMBOL_REF)
2654 {
2655 enum tls_model model = SYMBOL_REF_TLS_MODEL (x);
2656 if (model != 0)
2657 return rs6000_legitimize_tls_address (x, model);
2658 }
2659
9ebbca7d
GK
2660 if (GET_CODE (x) == PLUS
2661 && GET_CODE (XEXP (x, 0)) == REG
2662 && GET_CODE (XEXP (x, 1)) == CONST_INT
2663 && (unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1)) + 0x8000) >= 0x10000)
2664 {
2665 HOST_WIDE_INT high_int, low_int;
2666 rtx sum;
a65c591c
DE
2667 low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000;
2668 high_int = INTVAL (XEXP (x, 1)) - low_int;
9ebbca7d
GK
2669 sum = force_operand (gen_rtx_PLUS (Pmode, XEXP (x, 0),
2670 GEN_INT (high_int)), 0);
2671 return gen_rtx_PLUS (Pmode, sum, GEN_INT (low_int));
2672 }
2673 else if (GET_CODE (x) == PLUS
2674 && GET_CODE (XEXP (x, 0)) == REG
2675 && GET_CODE (XEXP (x, 1)) != CONST_INT
6ac7bf2c 2676 && GET_MODE_NUNITS (mode) == 1
a3170dc6
AH
2677 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
2678 || TARGET_POWERPC64
fcce224d 2679 || (mode != DFmode && mode != TFmode))
9ebbca7d
GK
2680 && (TARGET_POWERPC64 || mode != DImode)
2681 && mode != TImode)
2682 {
2683 return gen_rtx_PLUS (Pmode, XEXP (x, 0),
2684 force_reg (Pmode, force_operand (XEXP (x, 1), 0)));
2685 }
0ac081f6
AH
2686 else if (ALTIVEC_VECTOR_MODE (mode))
2687 {
2688 rtx reg;
2689
2690 /* Make sure both operands are registers. */
2691 if (GET_CODE (x) == PLUS)
9f85ed45 2692 return gen_rtx_PLUS (Pmode, force_reg (Pmode, XEXP (x, 0)),
0ac081f6
AH
2693 force_reg (Pmode, XEXP (x, 1)));
2694
2695 reg = force_reg (Pmode, x);
2696 return reg;
2697 }
a3170dc6
AH
2698 else if (SPE_VECTOR_MODE (mode))
2699 {
2700 /* We accept [reg + reg] and [reg + OFFSET]. */
2701
2702 if (GET_CODE (x) == PLUS)
2703 {
2704 rtx op1 = XEXP (x, 0);
2705 rtx op2 = XEXP (x, 1);
2706
2707 op1 = force_reg (Pmode, op1);
2708
2709 if (GET_CODE (op2) != REG
2710 && (GET_CODE (op2) != CONST_INT
2711 || !SPE_CONST_OFFSET_OK (INTVAL (op2))))
2712 op2 = force_reg (Pmode, op2);
2713
2714 return gen_rtx_PLUS (Pmode, op1, op2);
2715 }
2716
2717 return force_reg (Pmode, x);
2718 }
f1384257
AM
2719 else if (TARGET_ELF
2720 && TARGET_32BIT
2721 && TARGET_NO_TOC
2722 && ! flag_pic
9ebbca7d
GK
2723 && GET_CODE (x) != CONST_INT
2724 && GET_CODE (x) != CONST_DOUBLE
2725 && CONSTANT_P (x)
6ac7bf2c
GK
2726 && GET_MODE_NUNITS (mode) == 1
2727 && (GET_MODE_BITSIZE (mode) <= 32
a3170dc6 2728 || ((TARGET_HARD_FLOAT && TARGET_FPRS) && mode == DFmode)))
9ebbca7d
GK
2729 {
2730 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2731 emit_insn (gen_elf_high (reg, x));
2732 return gen_rtx_LO_SUM (Pmode, reg, x);
9ebbca7d 2733 }
ee890fe2
SS
2734 else if (TARGET_MACHO && TARGET_32BIT && TARGET_NO_TOC
2735 && ! flag_pic
ab82a49f
AP
2736#if TARGET_MACHO
2737 && ! MACHO_DYNAMIC_NO_PIC_P
2738#endif
ee890fe2
SS
2739 && GET_CODE (x) != CONST_INT
2740 && GET_CODE (x) != CONST_DOUBLE
2741 && CONSTANT_P (x)
a3170dc6 2742 && ((TARGET_HARD_FLOAT && TARGET_FPRS) || mode != DFmode)
ee890fe2
SS
2743 && mode != DImode
2744 && mode != TImode)
2745 {
2746 rtx reg = gen_reg_rtx (Pmode);
8a1977f3
GK
2747 emit_insn (gen_macho_high (reg, x));
2748 return gen_rtx_LO_SUM (Pmode, reg, x);
ee890fe2 2749 }
9ebbca7d 2750 else if (TARGET_TOC
4d588c14 2751 && constant_pool_expr_p (x)
a9098fd0 2752 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), Pmode))
9ebbca7d
GK
2753 {
2754 return create_TOC_reference (x);
2755 }
2756 else
2757 return NULL_RTX;
2758}
258bfae2 2759
c4501e62
JJ
2760/* Construct the SYMBOL_REF for the tls_get_addr function. */
2761
2762static GTY(()) rtx rs6000_tls_symbol;
2763static rtx
863d938c 2764rs6000_tls_get_addr (void)
c4501e62
JJ
2765{
2766 if (!rs6000_tls_symbol)
2767 rs6000_tls_symbol = init_one_libfunc ("__tls_get_addr");
2768
2769 return rs6000_tls_symbol;
2770}
2771
2772/* Construct the SYMBOL_REF for TLS GOT references. */
2773
2774static GTY(()) rtx rs6000_got_symbol;
2775static rtx
863d938c 2776rs6000_got_sym (void)
c4501e62
JJ
2777{
2778 if (!rs6000_got_symbol)
2779 {
2780 rs6000_got_symbol = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_");
2781 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_LOCAL;
2782 SYMBOL_REF_FLAGS (rs6000_got_symbol) |= SYMBOL_FLAG_EXTERNAL;
2783 }
2784
2785 return rs6000_got_symbol;
2786}
2787
2788/* ADDR contains a thread-local SYMBOL_REF. Generate code to compute
2789 this (thread-local) address. */
2790
2791static rtx
a2369ed3 2792rs6000_legitimize_tls_address (rtx addr, enum tls_model model)
c4501e62
JJ
2793{
2794 rtx dest, insn;
2795
2796 dest = gen_reg_rtx (Pmode);
2797 if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 16)
2798 {
2799 rtx tlsreg;
2800
2801 if (TARGET_64BIT)
2802 {
2803 tlsreg = gen_rtx_REG (Pmode, 13);
2804 insn = gen_tls_tprel_64 (dest, tlsreg, addr);
2805 }
2806 else
2807 {
2808 tlsreg = gen_rtx_REG (Pmode, 2);
2809 insn = gen_tls_tprel_32 (dest, tlsreg, addr);
2810 }
2811 emit_insn (insn);
2812 }
2813 else if (model == TLS_MODEL_LOCAL_EXEC && rs6000_tls_size == 32)
2814 {
2815 rtx tlsreg, tmp;
2816
2817 tmp = gen_reg_rtx (Pmode);
2818 if (TARGET_64BIT)
2819 {
2820 tlsreg = gen_rtx_REG (Pmode, 13);
2821 insn = gen_tls_tprel_ha_64 (tmp, tlsreg, addr);
2822 }
2823 else
2824 {
2825 tlsreg = gen_rtx_REG (Pmode, 2);
2826 insn = gen_tls_tprel_ha_32 (tmp, tlsreg, addr);
2827 }
2828 emit_insn (insn);
2829 if (TARGET_64BIT)
2830 insn = gen_tls_tprel_lo_64 (dest, tmp, addr);
2831 else
2832 insn = gen_tls_tprel_lo_32 (dest, tmp, addr);
2833 emit_insn (insn);
2834 }
2835 else
2836 {
2837 rtx r3, got, tga, tmp1, tmp2, eqv;
2838
2839 if (TARGET_64BIT)
2840 got = gen_rtx_REG (Pmode, TOC_REGISTER);
2841 else
2842 {
2843 if (flag_pic == 1)
2844 got = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
2845 else
2846 {
2847 rtx gsym = rs6000_got_sym ();
2848 got = gen_reg_rtx (Pmode);
2849 if (flag_pic == 0)
2850 rs6000_emit_move (got, gsym, Pmode);
2851 else
2852 {
2853 char buf[30];
2854 static int tls_got_labelno = 0;
2855 rtx tempLR, lab, tmp3, mem;
2856 rtx first, last;
2857
2858 ASM_GENERATE_INTERNAL_LABEL (buf, "LTLS", tls_got_labelno++);
2859 lab = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
2860 tempLR = gen_reg_rtx (Pmode);
2861 tmp1 = gen_reg_rtx (Pmode);
2862 tmp2 = gen_reg_rtx (Pmode);
2863 tmp3 = gen_reg_rtx (Pmode);
2864 mem = gen_rtx_MEM (Pmode, tmp1);
2865 RTX_UNCHANGING_P (mem) = 1;
2866
2867 first = emit_insn (gen_load_toc_v4_PIC_1b (tempLR, lab,
2868 gsym));
2869 emit_move_insn (tmp1, tempLR);
2870 emit_move_insn (tmp2, mem);
2871 emit_insn (gen_addsi3 (tmp3, tmp1, tmp2));
2872 last = emit_move_insn (got, tmp3);
2873 REG_NOTES (last) = gen_rtx_EXPR_LIST (REG_EQUAL, gsym,
2874 REG_NOTES (last));
2875 REG_NOTES (first) = gen_rtx_INSN_LIST (REG_LIBCALL, last,
2876 REG_NOTES (first));
2877 REG_NOTES (last) = gen_rtx_INSN_LIST (REG_RETVAL, first,
2878 REG_NOTES (last));
2879 }
2880 }
2881 }
2882
2883 if (model == TLS_MODEL_GLOBAL_DYNAMIC)
2884 {
2885 r3 = gen_rtx_REG (Pmode, 3);
2886 if (TARGET_64BIT)
2887 insn = gen_tls_gd_64 (r3, got, addr);
2888 else
2889 insn = gen_tls_gd_32 (r3, got, addr);
2890 start_sequence ();
2891 emit_insn (insn);
2892 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2893 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2894 insn = emit_call_insn (insn);
2895 CONST_OR_PURE_CALL_P (insn) = 1;
2896 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2897 insn = get_insns ();
2898 end_sequence ();
2899 emit_libcall_block (insn, dest, r3, addr);
2900 }
2901 else if (model == TLS_MODEL_LOCAL_DYNAMIC)
2902 {
2903 r3 = gen_rtx_REG (Pmode, 3);
2904 if (TARGET_64BIT)
2905 insn = gen_tls_ld_64 (r3, got);
2906 else
2907 insn = gen_tls_ld_32 (r3, got);
2908 start_sequence ();
2909 emit_insn (insn);
2910 tga = gen_rtx_MEM (Pmode, rs6000_tls_get_addr ());
2911 insn = gen_call_value (r3, tga, const0_rtx, const0_rtx);
2912 insn = emit_call_insn (insn);
2913 CONST_OR_PURE_CALL_P (insn) = 1;
2914 use_reg (&CALL_INSN_FUNCTION_USAGE (insn), r3);
2915 insn = get_insns ();
2916 end_sequence ();
2917 tmp1 = gen_reg_rtx (Pmode);
2918 eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
2919 UNSPEC_TLSLD);
2920 emit_libcall_block (insn, tmp1, r3, eqv);
2921 if (rs6000_tls_size == 16)
2922 {
2923 if (TARGET_64BIT)
2924 insn = gen_tls_dtprel_64 (dest, tmp1, addr);
2925 else
2926 insn = gen_tls_dtprel_32 (dest, tmp1, addr);
2927 }
2928 else if (rs6000_tls_size == 32)
2929 {
2930 tmp2 = gen_reg_rtx (Pmode);
2931 if (TARGET_64BIT)
2932 insn = gen_tls_dtprel_ha_64 (tmp2, tmp1, addr);
2933 else
2934 insn = gen_tls_dtprel_ha_32 (tmp2, tmp1, addr);
2935 emit_insn (insn);
2936 if (TARGET_64BIT)
2937 insn = gen_tls_dtprel_lo_64 (dest, tmp2, addr);
2938 else
2939 insn = gen_tls_dtprel_lo_32 (dest, tmp2, addr);
2940 }
2941 else
2942 {
2943 tmp2 = gen_reg_rtx (Pmode);
2944 if (TARGET_64BIT)
2945 insn = gen_tls_got_dtprel_64 (tmp2, got, addr);
2946 else
2947 insn = gen_tls_got_dtprel_32 (tmp2, got, addr);
2948 emit_insn (insn);
2949 insn = gen_rtx_SET (Pmode, dest,
2950 gen_rtx_PLUS (Pmode, tmp2, tmp1));
2951 }
2952 emit_insn (insn);
2953 }
2954 else
2955 {
2956 /* IE, or 64 bit offset LE. */
2957 tmp2 = gen_reg_rtx (Pmode);
2958 if (TARGET_64BIT)
2959 insn = gen_tls_got_tprel_64 (tmp2, got, addr);
2960 else
2961 insn = gen_tls_got_tprel_32 (tmp2, got, addr);
2962 emit_insn (insn);
2963 if (TARGET_64BIT)
2964 insn = gen_tls_tls_64 (dest, tmp2, addr);
2965 else
2966 insn = gen_tls_tls_32 (dest, tmp2, addr);
2967 emit_insn (insn);
2968 }
2969 }
2970
2971 return dest;
2972}
2973
2974/* Return 1 if X is a SYMBOL_REF for a TLS symbol. This is used in
2975 instruction definitions. */
2976
2977int
a2369ed3 2978rs6000_tls_symbol_ref (rtx x, enum machine_mode mode ATTRIBUTE_UNUSED)
c4501e62
JJ
2979{
2980 return RS6000_SYMBOL_REF_TLS_P (x);
2981}
2982
2983/* Return 1 if X contains a thread-local symbol. */
2984
2985bool
a2369ed3 2986rs6000_tls_referenced_p (rtx x)
c4501e62 2987{
cd413cab
AP
2988 if (! TARGET_HAVE_TLS)
2989 return false;
2990
c4501e62
JJ
2991 return for_each_rtx (&x, &rs6000_tls_symbol_ref_1, 0);
2992}
2993
2994/* Return 1 if *X is a thread-local symbol. This is the same as
2995 rs6000_tls_symbol_ref except for the type of the unused argument. */
2996
2997static inline int
a2369ed3 2998rs6000_tls_symbol_ref_1 (rtx *x, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
2999{
3000 return RS6000_SYMBOL_REF_TLS_P (*x);
3001}
3002
24ea750e
DJ
3003/* The convention appears to be to define this wherever it is used.
3004 With legitimize_reload_address now defined here, REG_MODE_OK_FOR_BASE_P
3005 is now used here. */
3006#ifndef REG_MODE_OK_FOR_BASE_P
3007#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO)
3008#endif
3009
3010/* Our implementation of LEGITIMIZE_RELOAD_ADDRESS. Returns a value to
3011 replace the input X, or the original X if no replacement is called for.
3012 The output parameter *WIN is 1 if the calling macro should goto WIN,
3013 0 if it should not.
3014
3015 For RS/6000, we wish to handle large displacements off a base
3016 register by splitting the addend across an addiu/addis and the mem insn.
3017 This cuts number of extra insns needed from 3 to 1.
3018
3019 On Darwin, we use this to generate code for floating point constants.
3020 A movsf_low is generated so we wind up with 2 instructions rather than 3.
3021 The Darwin code is inside #if TARGET_MACHO because only then is
3022 machopic_function_base_name() defined. */
3023rtx
a2369ed3
DJ
3024rs6000_legitimize_reload_address (rtx x, enum machine_mode mode,
3025 int opnum, int type, int ind_levels ATTRIBUTE_UNUSED, int *win)
24ea750e
DJ
3026{
3027 /* We must recognize output that we have already generated ourselves. */
3028 if (GET_CODE (x) == PLUS
3029 && GET_CODE (XEXP (x, 0)) == PLUS
3030 && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
3031 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT
3032 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3033 {
3034 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3035 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3036 opnum, (enum reload_type)type);
3037 *win = 1;
3038 return x;
3039 }
3deb2758 3040
24ea750e
DJ
3041#if TARGET_MACHO
3042 if (DEFAULT_ABI == ABI_DARWIN && flag_pic
3043 && GET_CODE (x) == LO_SUM
3044 && GET_CODE (XEXP (x, 0)) == PLUS
3045 && XEXP (XEXP (x, 0), 0) == pic_offset_table_rtx
3046 && GET_CODE (XEXP (XEXP (x, 0), 1)) == HIGH
3047 && GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 0)) == CONST
3048 && XEXP (XEXP (XEXP (x, 0), 1), 0) == XEXP (x, 1)
3049 && GET_CODE (XEXP (XEXP (x, 1), 0)) == MINUS
3050 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 0)) == SYMBOL_REF
3051 && GET_CODE (XEXP (XEXP (XEXP (x, 1), 0), 1)) == SYMBOL_REF)
3052 {
3053 /* Result of previous invocation of this function on Darwin
6f317ef3 3054 floating point constant. */
24ea750e
DJ
3055 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3056 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3057 opnum, (enum reload_type)type);
3058 *win = 1;
3059 return x;
3060 }
3061#endif
3062 if (GET_CODE (x) == PLUS
3063 && GET_CODE (XEXP (x, 0)) == REG
3064 && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
3065 && REG_MODE_OK_FOR_BASE_P (XEXP (x, 0), mode)
78c875e8 3066 && GET_CODE (XEXP (x, 1)) == CONST_INT
93638d7a 3067 && !SPE_VECTOR_MODE (mode)
78c875e8 3068 && !ALTIVEC_VECTOR_MODE (mode))
24ea750e
DJ
3069 {
3070 HOST_WIDE_INT val = INTVAL (XEXP (x, 1));
3071 HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000;
3072 HOST_WIDE_INT high
3073 = (((val - low) & 0xffffffff) ^ 0x80000000) - 0x80000000;
3074
3075 /* Check for 32-bit overflow. */
3076 if (high + low != val)
3077 {
3078 *win = 0;
3079 return x;
3080 }
3081
3082 /* Reload the high part into a base reg; leave the low part
3083 in the mem directly. */
3084
3085 x = gen_rtx_PLUS (GET_MODE (x),
3086 gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0),
3087 GEN_INT (high)),
3088 GEN_INT (low));
3089
3090 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
3091 BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
3092 opnum, (enum reload_type)type);
3093 *win = 1;
3094 return x;
3095 }
3096#if TARGET_MACHO
3097 if (GET_CODE (x) == SYMBOL_REF
3098 && DEFAULT_ABI == ABI_DARWIN
69ef87e2 3099 && !ALTIVEC_VECTOR_MODE (mode)
a29077da
GK
3100 && (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
3101 /* Don't do this for TFmode, since the result isn't offsettable. */
3102 && mode != TFmode)
24ea750e 3103 {
a29077da
GK
3104 if (flag_pic)
3105 {
3106 rtx offset = gen_rtx_CONST (Pmode,
3107 gen_rtx_MINUS (Pmode, x,
3108 gen_rtx_SYMBOL_REF (Pmode,
3109 machopic_function_base_name ())));
3110 x = gen_rtx_LO_SUM (GET_MODE (x),
3111 gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
3112 gen_rtx_HIGH (Pmode, offset)), offset);
3113 }
3114 else
3115 x = gen_rtx_LO_SUM (GET_MODE (x),
3116 gen_rtx_HIGH (Pmode, x), x);
3117
24ea750e 3118 push_reload (XEXP (x, 0), NULL_RTX, &XEXP (x, 0), NULL,
a29077da
GK
3119 BASE_REG_CLASS, Pmode, VOIDmode, 0, 0,
3120 opnum, (enum reload_type)type);
24ea750e
DJ
3121 *win = 1;
3122 return x;
3123 }
3124#endif
3125 if (TARGET_TOC
4d588c14 3126 && constant_pool_expr_p (x)
c1f11548 3127 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (x), mode))
24ea750e
DJ
3128 {
3129 (x) = create_TOC_reference (x);
3130 *win = 1;
3131 return x;
3132 }
3133 *win = 0;
3134 return x;
3135}
3136
258bfae2
FS
3137/* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
3138 that is a valid memory address for an instruction.
3139 The MODE argument is the machine mode for the MEM expression
3140 that wants to use this address.
3141
3142 On the RS/6000, there are four valid address: a SYMBOL_REF that
3143 refers to a constant pool entry of an address (or the sum of it
3144 plus a constant), a short (16-bit signed) constant plus a register,
3145 the sum of two registers, or a register indirect, possibly with an
5bdc5878 3146 auto-increment. For DFmode and DImode with a constant plus register,
258bfae2
FS
3147 we must ensure that both words are addressable or PowerPC64 with offset
3148 word aligned.
3149
3150 For modes spanning multiple registers (DFmode in 32-bit GPRs,
3151 32-bit DImode, TImode), indexed addressing cannot be used because
3152 adjacent memory cells are accessed by adding word-sized offsets
3153 during assembly output. */
3154int
a2369ed3 3155rs6000_legitimate_address (enum machine_mode mode, rtx x, int reg_ok_strict)
258bfae2 3156{
c4501e62
JJ
3157 if (RS6000_SYMBOL_REF_TLS_P (x))
3158 return 0;
4d588c14 3159 if (legitimate_indirect_address_p (x, reg_ok_strict))
258bfae2
FS
3160 return 1;
3161 if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC)
0d6d6892 3162 && !ALTIVEC_VECTOR_MODE (mode)
a3170dc6 3163 && !SPE_VECTOR_MODE (mode)
258bfae2 3164 && TARGET_UPDATE
4d588c14 3165 && legitimate_indirect_address_p (XEXP (x, 0), reg_ok_strict))
258bfae2 3166 return 1;
4d588c14 3167 if (legitimate_small_data_p (mode, x))
258bfae2 3168 return 1;
4d588c14 3169 if (legitimate_constant_pool_address_p (x))
258bfae2
FS
3170 return 1;
3171 /* If not REG_OK_STRICT (before reload) let pass any stack offset. */
3172 if (! reg_ok_strict
3173 && GET_CODE (x) == PLUS
3174 && GET_CODE (XEXP (x, 0)) == REG
3175 && XEXP (x, 0) == virtual_stack_vars_rtx
3176 && GET_CODE (XEXP (x, 1)) == CONST_INT)
3177 return 1;
4d588c14 3178 if (legitimate_offset_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3179 return 1;
3180 if (mode != TImode
a3170dc6
AH
3181 && ((TARGET_HARD_FLOAT && TARGET_FPRS)
3182 || TARGET_POWERPC64
fcce224d 3183 || (mode != DFmode && mode != TFmode))
258bfae2 3184 && (TARGET_POWERPC64 || mode != DImode)
4d588c14 3185 && legitimate_indexed_address_p (x, reg_ok_strict))
258bfae2 3186 return 1;
4d588c14 3187 if (legitimate_lo_sum_address_p (mode, x, reg_ok_strict))
258bfae2
FS
3188 return 1;
3189 return 0;
3190}
4d588c14
RH
3191
3192/* Go to LABEL if ADDR (a legitimate address expression)
3193 has an effect that depends on the machine mode it is used for.
3194
3195 On the RS/6000 this is true of all integral offsets (since AltiVec
3196 modes don't allow them) or is a pre-increment or decrement.
3197
3198 ??? Except that due to conceptual problems in offsettable_address_p
3199 we can't really report the problems of integral offsets. So leave
3200 this assuming that the adjustable offset must be valid for the
3201 sub-words of a TFmode operand, which is what we had before. */
3202
3203bool
a2369ed3 3204rs6000_mode_dependent_address (rtx addr)
4d588c14
RH
3205{
3206 switch (GET_CODE (addr))
3207 {
3208 case PLUS:
3209 if (GET_CODE (XEXP (addr, 1)) == CONST_INT)
3210 {
3211 unsigned HOST_WIDE_INT val = INTVAL (XEXP (addr, 1));
3212 return val + 12 + 0x8000 >= 0x10000;
3213 }
3214 break;
3215
3216 case LO_SUM:
3217 return true;
3218
3219 case PRE_INC:
3220 case PRE_DEC:
3221 return TARGET_UPDATE;
3222
3223 default:
3224 break;
3225 }
3226
3227 return false;
3228}
fb4d4348 3229\f
a4f6c312
SS
3230/* Try to output insns to set TARGET equal to the constant C if it can
3231 be done in less than N insns. Do all computations in MODE.
3232 Returns the place where the output has been placed if it can be
3233 done and the insns have been emitted. If it would take more than N
3234 insns, zero is returned and no insns and emitted. */
2bfcf297
DB
3235
3236rtx
a2369ed3
DJ
3237rs6000_emit_set_const (rtx dest, enum machine_mode mode,
3238 rtx source, int n ATTRIBUTE_UNUSED)
2bfcf297 3239{
af8cb5c5 3240 rtx result, insn, set;
2bfcf297
DB
3241 HOST_WIDE_INT c0, c1;
3242
af8cb5c5 3243 if (mode == QImode || mode == HImode)
2bfcf297
DB
3244 {
3245 if (dest == NULL)
3246 dest = gen_reg_rtx (mode);
3247 emit_insn (gen_rtx_SET (VOIDmode, dest, source));
3248 return dest;
3249 }
af8cb5c5 3250 else if (mode == SImode)
2bfcf297 3251 {
af8cb5c5
DE
3252 result = no_new_pseudos ? dest : gen_reg_rtx (SImode);
3253
3254 emit_insn (gen_rtx_SET (VOIDmode, result,
3255 GEN_INT (INTVAL (source)
3256 & (~ (HOST_WIDE_INT) 0xffff))));
3257 emit_insn (gen_rtx_SET (VOIDmode, dest,
3258 gen_rtx_IOR (SImode, result,
3259 GEN_INT (INTVAL (source) & 0xffff))));
3260 result = dest;
2bfcf297 3261 }
af8cb5c5 3262 else if (mode == DImode)
2bfcf297 3263 {
af8cb5c5
DE
3264 if (GET_CODE (source) == CONST_INT)
3265 {
3266 c0 = INTVAL (source);
3267 c1 = -(c0 < 0);
3268 }
3269 else if (GET_CODE (source) == CONST_DOUBLE)
3270 {
2bfcf297 3271#if HOST_BITS_PER_WIDE_INT >= 64
af8cb5c5
DE
3272 c0 = CONST_DOUBLE_LOW (source);
3273 c1 = -(c0 < 0);
2bfcf297 3274#else
af8cb5c5
DE
3275 c0 = CONST_DOUBLE_LOW (source);
3276 c1 = CONST_DOUBLE_HIGH (source);
2bfcf297 3277#endif
af8cb5c5
DE
3278 }
3279 else
3280 abort ();
3281
3282 result = rs6000_emit_set_long_const (dest, c0, c1);
2bfcf297
DB
3283 }
3284 else
a4f6c312 3285 abort ();
2bfcf297 3286
af8cb5c5
DE
3287 insn = get_last_insn ();
3288 set = single_set (insn);
3289 if (! CONSTANT_P (SET_SRC (set)))
3290 set_unique_reg_note (insn, REG_EQUAL, source);
3291
3292 return result;
2bfcf297
DB
3293}
3294
3295/* Having failed to find a 3 insn sequence in rs6000_emit_set_const,
3296 fall back to a straight forward decomposition. We do this to avoid
3297 exponential run times encountered when looking for longer sequences
3298 with rs6000_emit_set_const. */
3299static rtx
a2369ed3 3300rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c1, HOST_WIDE_INT c2)
2bfcf297
DB
3301{
3302 if (!TARGET_POWERPC64)
3303 {
3304 rtx operand1, operand2;
3305
3306 operand1 = operand_subword_force (dest, WORDS_BIG_ENDIAN == 0,
3307 DImode);
3308 operand2 = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0,
3309 DImode);
3310 emit_move_insn (operand1, GEN_INT (c1));
3311 emit_move_insn (operand2, GEN_INT (c2));
3312 }
3313 else
3314 {
bc06712d 3315 HOST_WIDE_INT ud1, ud2, ud3, ud4;
252b88f7 3316
bc06712d 3317 ud1 = c1 & 0xffff;
f921c9c9 3318 ud2 = (c1 & 0xffff0000) >> 16;
2bfcf297 3319#if HOST_BITS_PER_WIDE_INT >= 64
bc06712d 3320 c2 = c1 >> 32;
2bfcf297 3321#endif
bc06712d 3322 ud3 = c2 & 0xffff;
f921c9c9 3323 ud4 = (c2 & 0xffff0000) >> 16;
2bfcf297 3324
bc06712d
TR
3325 if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000))
3326 || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000)))
2bfcf297 3327 {
bc06712d 3328 if (ud1 & 0x8000)
b78d48dd 3329 emit_move_insn (dest, GEN_INT (((ud1 ^ 0x8000) - 0x8000)));
bc06712d
TR
3330 else
3331 emit_move_insn (dest, GEN_INT (ud1));
2bfcf297 3332 }
2bfcf297 3333
bc06712d
TR
3334 else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000))
3335 || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000)))
252b88f7 3336 {
bc06712d
TR
3337 if (ud2 & 0x8000)
3338 emit_move_insn (dest, GEN_INT (((ud2 << 16) ^ 0x80000000)
3339 - 0x80000000));
252b88f7 3340 else
bc06712d
TR
3341 emit_move_insn (dest, GEN_INT (ud2 << 16));
3342 if (ud1 != 0)
3343 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
252b88f7 3344 }
bc06712d
TR
3345 else if ((ud4 == 0xffff && (ud3 & 0x8000))
3346 || (ud4 == 0 && ! (ud3 & 0x8000)))
3347 {
3348 if (ud3 & 0x8000)
3349 emit_move_insn (dest, GEN_INT (((ud3 << 16) ^ 0x80000000)
3350 - 0x80000000));
3351 else
3352 emit_move_insn (dest, GEN_INT (ud3 << 16));
3353
3354 if (ud2 != 0)
3355 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud2)));
3356 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (16)));
3357 if (ud1 != 0)
3358 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3359 }
3360 else
3361 {
3362 if (ud4 & 0x8000)
3363 emit_move_insn (dest, GEN_INT (((ud4 << 16) ^ 0x80000000)
3364 - 0x80000000));
3365 else
3366 emit_move_insn (dest, GEN_INT (ud4 << 16));
3367
3368 if (ud3 != 0)
3369 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud3)));
2bfcf297 3370
bc06712d
TR
3371 emit_move_insn (dest, gen_rtx_ASHIFT (DImode, dest, GEN_INT (32)));
3372 if (ud2 != 0)
3373 emit_move_insn (dest, gen_rtx_IOR (DImode, dest,
3374 GEN_INT (ud2 << 16)));
3375 if (ud1 != 0)
3376 emit_move_insn (dest, gen_rtx_IOR (DImode, dest, GEN_INT (ud1)));
3377 }
3378 }
2bfcf297
DB
3379 return dest;
3380}
3381
fb4d4348
GK
3382/* Emit a move from SOURCE to DEST in mode MODE. */
3383void
a2369ed3 3384rs6000_emit_move (rtx dest, rtx source, enum machine_mode mode)
fb4d4348
GK
3385{
3386 rtx operands[2];
3387 operands[0] = dest;
3388 operands[1] = source;
3389
3390 /* Sanity checks. Check that we get CONST_DOUBLE only when we should. */
3391 if (GET_CODE (operands[1]) == CONST_DOUBLE
3392 && ! FLOAT_MODE_P (mode)
3393 && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
3394 {
3395 /* FIXME. This should never happen. */
3396 /* Since it seems that it does, do the safe thing and convert
3397 to a CONST_INT. */
2496c7bd 3398 operands[1] = gen_int_mode (CONST_DOUBLE_LOW (operands[1]), mode);
fb4d4348
GK
3399 }
3400 if (GET_CODE (operands[1]) == CONST_DOUBLE
3401 && ! FLOAT_MODE_P (mode)
3402 && ((CONST_DOUBLE_HIGH (operands[1]) == 0
3403 && CONST_DOUBLE_LOW (operands[1]) >= 0)
3404 || (CONST_DOUBLE_HIGH (operands[1]) == -1
3405 && CONST_DOUBLE_LOW (operands[1]) < 0)))
3406 abort ();
c9e8cb32
DD
3407
3408 /* Check if GCC is setting up a block move that will end up using FP
3409 registers as temporaries. We must make sure this is acceptable. */
3410 if (GET_CODE (operands[0]) == MEM
3411 && GET_CODE (operands[1]) == MEM
3412 && mode == DImode
41543739
GK
3413 && (SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[0]))
3414 || SLOW_UNALIGNED_ACCESS (DImode, MEM_ALIGN (operands[1])))
3415 && ! (SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[0]) > 32
3416 ? 32 : MEM_ALIGN (operands[0])))
3417 || SLOW_UNALIGNED_ACCESS (SImode, (MEM_ALIGN (operands[1]) > 32
3418 ? 32
3419 : MEM_ALIGN (operands[1]))))
3420 && ! MEM_VOLATILE_P (operands [0])
3421 && ! MEM_VOLATILE_P (operands [1]))
c9e8cb32 3422 {
41543739
GK
3423 emit_move_insn (adjust_address (operands[0], SImode, 0),
3424 adjust_address (operands[1], SImode, 0));
3425 emit_move_insn (adjust_address (operands[0], SImode, 4),
3426 adjust_address (operands[1], SImode, 4));
c9e8cb32
DD
3427 return;
3428 }
630d42a0
DE
3429 else if (mode == DImode && TARGET_POWERPC64
3430 && GET_CODE (operands[0]) == REG
3431 && GET_CODE (operands[1]) == MEM && optimize > 0
3432 && SLOW_UNALIGNED_ACCESS (DImode,
3433 MEM_ALIGN (operands[1]) > 32
3434 ? 32
3435 : MEM_ALIGN (operands[1]))
3436 && !no_new_pseudos)
3437 {
3438 rtx reg = gen_reg_rtx (SImode);
3439 emit_insn (gen_rtx_SET (SImode, reg,
3440 adjust_address (operands[1], SImode, 0)));
3441 reg = simplify_gen_subreg (DImode, reg, SImode, 0);
3442 emit_insn (gen_insvdi (operands[0], GEN_INT (32), const0_rtx, reg));
3443 reg = gen_reg_rtx (SImode);
3444 emit_insn (gen_rtx_SET (SImode, reg,
3445 adjust_address (operands[1], SImode, 4)));
3446 reg = simplify_gen_subreg (DImode, reg, SImode, 0);
3447 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32), reg));
3448 return;
3449 }
3450 else if (mode == DImode && TARGET_POWERPC64
3451 && GET_CODE (operands[1]) == REG
3452 && GET_CODE (operands[0]) == MEM && optimize > 0
3453 && SLOW_UNALIGNED_ACCESS (DImode,
3454 MEM_ALIGN (operands[0]) > 32
3455 ? 32
3456 : MEM_ALIGN (operands[0]))
3457 && !no_new_pseudos)
d9b7db12 3458 {
630d42a0
DE
3459 rtx reg = gen_reg_rtx (DImode);
3460 emit_move_insn (reg,
2d9db8eb 3461 gen_rtx_LSHIFTRT (DImode, operands[1], GEN_INT (32)));
630d42a0 3462 emit_move_insn (adjust_address (operands[0], SImode, 0),
2d9db8eb 3463 simplify_gen_subreg (SImode, reg, DImode, 0));
630d42a0
DE
3464 emit_move_insn (reg, operands[1]);
3465 emit_move_insn (adjust_address (operands[0], SImode, 4),
be77d9e7 3466 simplify_gen_subreg (SImode, reg, DImode, 0));
630d42a0 3467 return;
d9b7db12 3468 }
630d42a0 3469
67cef334
DE
3470 if (!no_new_pseudos)
3471 {
3472 if (GET_CODE (operands[1]) == MEM && optimize > 0
3473 && (mode == QImode || mode == HImode || mode == SImode)
3474 && GET_MODE_SIZE (mode) < GET_MODE_SIZE (word_mode))
3475 {
3476 rtx reg = gen_reg_rtx (word_mode);
3477
3478 emit_insn (gen_rtx_SET (word_mode, reg,
3479 gen_rtx_ZERO_EXTEND (word_mode,
3480 operands[1])));
3481 operands[1] = gen_lowpart (mode, reg);
3482 }
3483 if (GET_CODE (operands[0]) != REG)
3484 operands[1] = force_reg (mode, operands[1]);
3485 }
a9098fd0 3486
a3170dc6
AH
3487 if (mode == SFmode && ! TARGET_POWERPC
3488 && TARGET_HARD_FLOAT && TARGET_FPRS
ffc14f31 3489 && GET_CODE (operands[0]) == MEM)
fb4d4348 3490 {
ffc14f31
GK
3491 int regnum;
3492
3493 if (reload_in_progress || reload_completed)
3494 regnum = true_regnum (operands[1]);
3495 else if (GET_CODE (operands[1]) == REG)
3496 regnum = REGNO (operands[1]);
3497 else
3498 regnum = -1;
fb4d4348
GK
3499
3500 /* If operands[1] is a register, on POWER it may have
3501 double-precision data in it, so truncate it to single
3502 precision. */
3503 if (FP_REGNO_P (regnum) || regnum >= FIRST_PSEUDO_REGISTER)
3504 {
3505 rtx newreg;
3506 newreg = (no_new_pseudos ? operands[1] : gen_reg_rtx (mode));
3507 emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
3508 operands[1] = newreg;
3509 }
3510 }
3511
c4501e62
JJ
3512 /* Recognize the case where operand[1] is a reference to thread-local
3513 data and load its address to a register. */
3514 if (GET_CODE (operands[1]) == SYMBOL_REF)
3515 {
3516 enum tls_model model = SYMBOL_REF_TLS_MODEL (operands[1]);
3517 if (model != 0)
3518 operands[1] = rs6000_legitimize_tls_address (operands[1], model);
3519 }
3520
8f4e6caf
RH
3521 /* Handle the case where reload calls us with an invalid address. */
3522 if (reload_in_progress && mode == Pmode
69ef87e2 3523 && (! general_operand (operands[1], mode)
8f4e6caf
RH
3524 || ! nonimmediate_operand (operands[0], mode)))
3525 goto emit_set;
3526
3527 /* Handle the case of CONSTANT_P_RTX. */
3528 if (GET_CODE (operands[1]) == CONSTANT_P_RTX)
3529 goto emit_set;
a9baceb1
GK
3530
3531 /* 128-bit constant floating-point values on Darwin should really be
3532 loaded as two parts. */
3533 if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_DARWIN)
3534 && TARGET_HARD_FLOAT && TARGET_FPRS && TARGET_LONG_DOUBLE_128
3535 && mode == TFmode && GET_CODE (operands[1]) == CONST_DOUBLE)
3536 {
3537 /* DImode is used, not DFmode, because simplify_gen_subreg doesn't
3538 know how to get a DFmode SUBREG of a TFmode. */
3539 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode, 0),
3540 simplify_gen_subreg (DImode, operands[1], mode, 0),
3541 DImode);
3542 rs6000_emit_move (simplify_gen_subreg (DImode, operands[0], mode,
3543 GET_MODE_SIZE (DImode)),
3544 simplify_gen_subreg (DImode, operands[1], mode,
3545 GET_MODE_SIZE (DImode)),
3546 DImode);
3547 return;
3548 }
3549
fb4d4348
GK
3550 /* FIXME: In the long term, this switch statement should go away
3551 and be replaced by a sequence of tests based on things like
3552 mode == Pmode. */
3553 switch (mode)
3554 {
3555 case HImode:
3556 case QImode:
3557 if (CONSTANT_P (operands[1])
3558 && GET_CODE (operands[1]) != CONST_INT)
a9098fd0 3559 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3560 break;
3561
06f4e019 3562 case TFmode:
fb4d4348
GK
3563 case DFmode:
3564 case SFmode:
3565 if (CONSTANT_P (operands[1])
3566 && ! easy_fp_constant (operands[1], mode))
a9098fd0 3567 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3568 break;
3569
0ac081f6
AH
3570 case V16QImode:
3571 case V8HImode:
3572 case V4SFmode:
3573 case V4SImode:
a3170dc6
AH
3574 case V4HImode:
3575 case V2SFmode:
3576 case V2SImode:
00a892b8 3577 case V1DImode:
69ef87e2 3578 if (CONSTANT_P (operands[1])
d744e06e 3579 && !easy_vector_constant (operands[1], mode))
0ac081f6
AH
3580 operands[1] = force_const_mem (mode, operands[1]);
3581 break;
3582
fb4d4348 3583 case SImode:
a9098fd0 3584 case DImode:
fb4d4348
GK
3585 /* Use default pattern for address of ELF small data */
3586 if (TARGET_ELF
a9098fd0 3587 && mode == Pmode
f607bc57 3588 && DEFAULT_ABI == ABI_V4
a9098fd0
GK
3589 && (GET_CODE (operands[1]) == SYMBOL_REF
3590 || GET_CODE (operands[1]) == CONST)
3591 && small_data_operand (operands[1], mode))
fb4d4348
GK
3592 {
3593 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3594 return;
3595 }
3596
f607bc57 3597 if (DEFAULT_ABI == ABI_V4
a9098fd0
GK
3598 && mode == Pmode && mode == SImode
3599 && flag_pic == 1 && got_operand (operands[1], mode))
fb4d4348
GK
3600 {
3601 emit_insn (gen_movsi_got (operands[0], operands[1]));
3602 return;
3603 }
3604
ee890fe2 3605 if ((TARGET_ELF || DEFAULT_ABI == ABI_DARWIN)
f1384257
AM
3606 && TARGET_NO_TOC
3607 && ! flag_pic
a9098fd0 3608 && mode == Pmode
fb4d4348
GK
3609 && CONSTANT_P (operands[1])
3610 && GET_CODE (operands[1]) != HIGH
3611 && GET_CODE (operands[1]) != CONST_INT)
3612 {
a9098fd0 3613 rtx target = (no_new_pseudos ? operands[0] : gen_reg_rtx (mode));
fb4d4348
GK
3614
3615 /* If this is a function address on -mcall-aixdesc,
3616 convert it to the address of the descriptor. */
3617 if (DEFAULT_ABI == ABI_AIX
3618 && GET_CODE (operands[1]) == SYMBOL_REF
3619 && XSTR (operands[1], 0)[0] == '.')
3620 {
3621 const char *name = XSTR (operands[1], 0);
3622 rtx new_ref;
3623 while (*name == '.')
3624 name++;
3625 new_ref = gen_rtx_SYMBOL_REF (Pmode, name);
3626 CONSTANT_POOL_ADDRESS_P (new_ref)
3627 = CONSTANT_POOL_ADDRESS_P (operands[1]);
d1908feb 3628 SYMBOL_REF_FLAGS (new_ref) = SYMBOL_REF_FLAGS (operands[1]);
fb4d4348 3629 SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
d1908feb 3630 SYMBOL_REF_DECL (new_ref) = SYMBOL_REF_DECL (operands[1]);
fb4d4348
GK
3631 operands[1] = new_ref;
3632 }
7509c759 3633
ee890fe2
SS
3634 if (DEFAULT_ABI == ABI_DARWIN)
3635 {
ab82a49f
AP
3636#if TARGET_MACHO
3637 if (MACHO_DYNAMIC_NO_PIC_P)
3638 {
3639 /* Take care of any required data indirection. */
3640 operands[1] = rs6000_machopic_legitimize_pic_address (
3641 operands[1], mode, operands[0]);
3642 if (operands[0] != operands[1])
3643 emit_insn (gen_rtx_SET (VOIDmode,
3644 operands[0], operands[1]));
3645 return;
3646 }
3647#endif
ee890fe2
SS
3648 emit_insn (gen_macho_high (target, operands[1]));
3649 emit_insn (gen_macho_low (operands[0], target, operands[1]));
3650 return;
3651 }
3652
fb4d4348
GK
3653 emit_insn (gen_elf_high (target, operands[1]));
3654 emit_insn (gen_elf_low (operands[0], target, operands[1]));
3655 return;
3656 }
3657
a9098fd0
GK
3658 /* If this is a SYMBOL_REF that refers to a constant pool entry,
3659 and we have put it in the TOC, we just need to make a TOC-relative
3660 reference to it. */
3661 if (TARGET_TOC
3662 && GET_CODE (operands[1]) == SYMBOL_REF
4d588c14 3663 && constant_pool_expr_p (operands[1])
a9098fd0
GK
3664 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (get_pool_constant (operands[1]),
3665 get_pool_mode (operands[1])))
fb4d4348 3666 {
a9098fd0 3667 operands[1] = create_TOC_reference (operands[1]);
fb4d4348 3668 }
a9098fd0
GK
3669 else if (mode == Pmode
3670 && CONSTANT_P (operands[1])
38886f37
AO
3671 && ((GET_CODE (operands[1]) != CONST_INT
3672 && ! easy_fp_constant (operands[1], mode))
3673 || (GET_CODE (operands[1]) == CONST_INT
3674 && num_insns_constant (operands[1], mode) > 2)
3675 || (GET_CODE (operands[0]) == REG
3676 && FP_REGNO_P (REGNO (operands[0]))))
a9098fd0 3677 && GET_CODE (operands[1]) != HIGH
4d588c14
RH
3678 && ! legitimate_constant_pool_address_p (operands[1])
3679 && ! toc_relative_expr_p (operands[1]))
fb4d4348
GK
3680 {
3681 /* Emit a USE operation so that the constant isn't deleted if
3682 expensive optimizations are turned on because nobody
3683 references it. This should only be done for operands that
3684 contain SYMBOL_REFs with CONSTANT_POOL_ADDRESS_P set.
3685 This should not be done for operands that contain LABEL_REFs.
3686 For now, we just handle the obvious case. */
3687 if (GET_CODE (operands[1]) != LABEL_REF)
3688 emit_insn (gen_rtx_USE (VOIDmode, operands[1]));
3689
c859cda6 3690#if TARGET_MACHO
ee890fe2 3691 /* Darwin uses a special PIC legitimizer. */
ab82a49f 3692 if (DEFAULT_ABI == ABI_DARWIN && MACHOPIC_INDIRECT)
ee890fe2 3693 {
ee890fe2
SS
3694 operands[1] =
3695 rs6000_machopic_legitimize_pic_address (operands[1], mode,
c859cda6
DJ
3696 operands[0]);
3697 if (operands[0] != operands[1])
3698 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
ee890fe2
SS
3699 return;
3700 }
c859cda6 3701#endif
ee890fe2 3702
fb4d4348
GK
3703 /* If we are to limit the number of things we put in the TOC and
3704 this is a symbol plus a constant we can add in one insn,
3705 just put the symbol in the TOC and add the constant. Don't do
3706 this if reload is in progress. */
3707 if (GET_CODE (operands[1]) == CONST
3708 && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
3709 && GET_CODE (XEXP (operands[1], 0)) == PLUS
a9098fd0 3710 && add_operand (XEXP (XEXP (operands[1], 0), 1), mode)
fb4d4348
GK
3711 && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
3712 || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
3713 && ! side_effects_p (operands[0]))
3714 {
a4f6c312
SS
3715 rtx sym =
3716 force_const_mem (mode, XEXP (XEXP (operands[1], 0), 0));
fb4d4348
GK
3717 rtx other = XEXP (XEXP (operands[1], 0), 1);
3718
a9098fd0
GK
3719 sym = force_reg (mode, sym);
3720 if (mode == SImode)
3721 emit_insn (gen_addsi3 (operands[0], sym, other));
3722 else
3723 emit_insn (gen_adddi3 (operands[0], sym, other));
fb4d4348
GK
3724 return;
3725 }
3726
a9098fd0 3727 operands[1] = force_const_mem (mode, operands[1]);
fb4d4348
GK
3728
3729 if (TARGET_TOC
4d588c14 3730 && constant_pool_expr_p (XEXP (operands[1], 0))
d34c5b80
DE
3731 && ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (
3732 get_pool_constant (XEXP (operands[1], 0)),
3733 get_pool_mode (XEXP (operands[1], 0))))
a9098fd0 3734 {
ba4828e0
RK
3735 operands[1]
3736 = gen_rtx_MEM (mode,
3737 create_TOC_reference (XEXP (operands[1], 0)));
3738 set_mem_alias_set (operands[1], get_TOC_alias_set ());
fb4d4348 3739 RTX_UNCHANGING_P (operands[1]) = 1;
a9098fd0 3740 }
fb4d4348
GK
3741 }
3742 break;
a9098fd0 3743
fb4d4348
GK
3744 case TImode:
3745 if (GET_CODE (operands[0]) == MEM
3746 && GET_CODE (XEXP (operands[0], 0)) != REG
3747 && ! reload_in_progress)
792760b9
RK
3748 operands[0]
3749 = replace_equiv_address (operands[0],
3750 copy_addr_to_reg (XEXP (operands[0], 0)));
fb4d4348
GK
3751
3752 if (GET_CODE (operands[1]) == MEM
3753 && GET_CODE (XEXP (operands[1], 0)) != REG
3754 && ! reload_in_progress)
792760b9
RK
3755 operands[1]
3756 = replace_equiv_address (operands[1],
3757 copy_addr_to_reg (XEXP (operands[1], 0)));
27dc0551
DE
3758 if (TARGET_POWER)
3759 {
3760 emit_insn (gen_rtx_PARALLEL (VOIDmode,
3761 gen_rtvec (2,
3762 gen_rtx_SET (VOIDmode,
3763 operands[0], operands[1]),
3764 gen_rtx_CLOBBER (VOIDmode,
3765 gen_rtx_SCRATCH (SImode)))));
3766 return;
3767 }
fb4d4348
GK
3768 break;
3769
3770 default:
3771 abort ();
3772 }
3773
a9098fd0
GK
3774 /* Above, we may have called force_const_mem which may have returned
3775 an invalid address. If we can, fix this up; otherwise, reload will
3776 have to deal with it. */
8f4e6caf
RH
3777 if (GET_CODE (operands[1]) == MEM && ! reload_in_progress)
3778 operands[1] = validize_mem (operands[1]);
a9098fd0 3779
8f4e6caf 3780 emit_set:
fb4d4348
GK
3781 emit_insn (gen_rtx_SET (VOIDmode, operands[0], operands[1]));
3782}
4697a36c 3783\f
2858f73a
GK
3784/* Nonzero if we can use a floating-point register to pass this arg. */
3785#define USE_FP_FOR_ARG_P(CUM,MODE,TYPE) \
3786 (GET_MODE_CLASS (MODE) == MODE_FLOAT \
3787 && (CUM)->fregno <= FP_ARG_MAX_REG \
3788 && TARGET_HARD_FLOAT && TARGET_FPRS)
3789
3790/* Nonzero if we can use an AltiVec register to pass this arg. */
3791#define USE_ALTIVEC_FOR_ARG_P(CUM,MODE,TYPE,NAMED) \
3792 (ALTIVEC_VECTOR_MODE (MODE) \
3793 && (CUM)->vregno <= ALTIVEC_ARG_MAX_REG \
3794 && TARGET_ALTIVEC_ABI \
83953138 3795 && (NAMED))
2858f73a 3796
c6e8c921
GK
3797/* Return a nonzero value to say to return the function value in
3798 memory, just as large structures are always returned. TYPE will be
3799 the data type of the value, and FNTYPE will be the type of the
3800 function doing the returning, or @code{NULL} for libcalls.
3801
3802 The AIX ABI for the RS/6000 specifies that all structures are
3803 returned in memory. The Darwin ABI does the same. The SVR4 ABI
3804 specifies that structures <= 8 bytes are returned in r3/r4, but a
3805 draft put them in memory, and GCC used to implement the draft
3806 instead of the final standard. Therefore, TARGET_AIX_STRUCT_RET
3807 controls this instead of DEFAULT_ABI; V.4 targets needing backward
3808 compatibility can change DRAFT_V4_STRUCT_RET to override the
3809 default, and -m switches get the final word. See
3810 rs6000_override_options for more details.
3811
3812 The PPC32 SVR4 ABI uses IEEE double extended for long double, if 128-bit
3813 long double support is enabled. These values are returned in memory.
3814
3815 int_size_in_bytes returns -1 for variable size objects, which go in
3816 memory always. The cast to unsigned makes -1 > 8. */
3817
3818static bool
3819rs6000_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
3820{
3821 if (AGGREGATE_TYPE_P (type)
3822 && (TARGET_AIX_STRUCT_RET
3823 || (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 8))
3824 return true;
3825 if (DEFAULT_ABI == ABI_V4 && TYPE_MODE (type) == TFmode)
3826 return true;
3827 return false;
3828}
3829
4697a36c
MM
3830/* Initialize a variable CUM of type CUMULATIVE_ARGS
3831 for a call to a function whose data type is FNTYPE.
3832 For a library call, FNTYPE is 0.
3833
3834 For incoming args we set the number of arguments in the prototype large
1c20ae99 3835 so we never return a PARALLEL. */
4697a36c
MM
3836
3837void
a2369ed3 3838init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
0f6937fe
AM
3839 rtx libname ATTRIBUTE_UNUSED, int incoming,
3840 int libcall, int n_named_args)
4697a36c
MM
3841{
3842 static CUMULATIVE_ARGS zero_cumulative;
3843
3844 *cum = zero_cumulative;
3845 cum->words = 0;
3846 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 3847 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 3848 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
3849 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
3850 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 3851 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
3852 cum->stdarg = fntype
3853 && (TYPE_ARG_TYPES (fntype) != 0
3854 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3855 != void_type_node));
4697a36c 3856
0f6937fe
AM
3857 cum->nargs_prototype = 0;
3858 if (incoming || cum->prototype)
3859 cum->nargs_prototype = n_named_args;
4697a36c 3860
a5c76ee6
ZW
3861 /* Check for a longcall attribute. */
3862 if (fntype
3863 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
3864 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
3865 cum->call_cookie = CALL_LONG;
3866
4697a36c
MM
3867 if (TARGET_DEBUG_ARG)
3868 {
3869 fprintf (stderr, "\ninit_cumulative_args:");
3870 if (fntype)
3871 {
3872 tree ret_type = TREE_TYPE (fntype);
3873 fprintf (stderr, " ret code = %s,",
3874 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3875 }
3876
6a4cee5f
MM
3877 if (cum->call_cookie & CALL_LONG)
3878 fprintf (stderr, " longcall,");
3879
4697a36c
MM
3880 fprintf (stderr, " proto = %d, nargs = %d\n",
3881 cum->prototype, cum->nargs_prototype);
3882 }
3883}
3884\f
c229cba9
DE
3885/* If defined, a C expression which determines whether, and in which
3886 direction, to pad out an argument with extra space. The value
3887 should be of type `enum direction': either `upward' to pad above
3888 the argument, `downward' to pad below, or `none' to inhibit
3889 padding.
3890
3891 For the AIX ABI structs are always stored left shifted in their
3892 argument slot. */
3893
9ebbca7d 3894enum direction
a2369ed3 3895function_arg_padding (enum machine_mode mode, tree type)
c229cba9 3896{
6e985040
AM
3897#ifndef AGGREGATE_PADDING_FIXED
3898#define AGGREGATE_PADDING_FIXED 0
3899#endif
3900#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
3901#define AGGREGATES_PAD_UPWARD_ALWAYS 0
3902#endif
3903
3904 if (!AGGREGATE_PADDING_FIXED)
3905 {
3906 /* GCC used to pass structures of the same size as integer types as
3907 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
3908 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
3909 passed padded downward, except that -mstrict-align further
3910 muddied the water in that multi-component structures of 2 and 4
3911 bytes in size were passed padded upward.
3912
3913 The following arranges for best compatibility with previous
3914 versions of gcc, but removes the -mstrict-align dependency. */
3915 if (BYTES_BIG_ENDIAN)
3916 {
3917 HOST_WIDE_INT size = 0;
3918
3919 if (mode == BLKmode)
3920 {
3921 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
3922 size = int_size_in_bytes (type);
3923 }
3924 else
3925 size = GET_MODE_SIZE (mode);
3926
3927 if (size == 1 || size == 2 || size == 4)
3928 return downward;
3929 }
3930 return upward;
3931 }
3932
3933 if (AGGREGATES_PAD_UPWARD_ALWAYS)
3934 {
3935 if (type != 0 && AGGREGATE_TYPE_P (type))
3936 return upward;
3937 }
c229cba9 3938
d3704c46
KH
3939 /* Fall back to the default. */
3940 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
3941}
3942
b6c9286a
MM
3943/* If defined, a C expression that gives the alignment boundary, in bits,
3944 of an argument with the specified mode and type. If it is not defined,
3945 PARM_BOUNDARY is used for all arguments.
3946
2310f99a 3947 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3948
3949int
a2369ed3 3950function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 3951{
f607bc57 3952 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3953 return 64;
a3170dc6
AH
3954 else if (SPE_VECTOR_MODE (mode))
3955 return 64;
0ac081f6
AH
3956 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3957 return 128;
9ebbca7d 3958 else
b6c9286a 3959 return PARM_BOUNDARY;
b6c9286a
MM
3960}
3961\f
4697a36c
MM
3962/* Update the data in CUM to advance over an argument
3963 of mode MODE and data type TYPE.
3964 (TYPE is null for libcalls where that information may not be available.) */
3965
3966void
a2369ed3
DJ
3967function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3968 tree type, int named)
4697a36c
MM
3969{
3970 cum->nargs_prototype--;
3971
0ac081f6
AH
3972 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3973 {
2858f73a 3974 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
0ac081f6 3975 cum->vregno++;
2858f73a 3976
c72d6c26
HP
3977 /* PowerPC64 Linux and AIX allocates GPRs for a vector argument
3978 even if it is going to be passed in a vector register.
3979 Darwin does the same for variable-argument functions. */
3980 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
3981 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
3982 {
a594a19c
GK
3983 int align;
3984
2858f73a
GK
3985 /* Vector parameters must be 16-byte aligned. This places
3986 them at 2 mod 4 in terms of words in 32-bit mode, since
3987 the parameter save area starts at offset 24 from the
3988 stack. In 64-bit mode, they just have to start on an
3989 even word, since the parameter save area is 16-byte
3990 aligned. Space for GPRs is reserved even if the argument
3991 will be passed in memory. */
3992 if (TARGET_32BIT)
3993 align = ((6 - (cum->words & 3)) & 3);
3994 else
3995 align = cum->words & 1;
a594a19c 3996 cum->words += align + RS6000_ARG_SIZE (mode, type);
2858f73a 3997
a594a19c
GK
3998 if (TARGET_DEBUG_ARG)
3999 {
4000 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
4001 cum->words, align);
4002 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
2858f73a
GK
4003 cum->nargs_prototype, cum->prototype,
4004 GET_MODE_NAME (mode));
a594a19c
GK
4005 }
4006 }
0ac081f6 4007 }
a4b0320c 4008 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4009 && !cum->stdarg
4010 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4011 cum->sysv_gregno++;
f607bc57 4012 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4013 {
a3170dc6 4014 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4015 && (mode == SFmode || mode == DFmode))
4697a36c 4016 {
4cc833b7
RH
4017 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4018 cum->fregno++;
4019 else
4020 {
4021 if (mode == DFmode)
4022 cum->words += cum->words & 1;
d34c5b80 4023 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 4024 }
4697a36c 4025 }
4cc833b7
RH
4026 else
4027 {
4028 int n_words;
4029 int gregno = cum->sysv_gregno;
4030
4031 /* Aggregates and IEEE quad get passed by reference. */
4032 if ((type && AGGREGATE_TYPE_P (type))
4033 || mode == TFmode)
4034 n_words = 1;
4035 else
d34c5b80 4036 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 4037
a4b0320c 4038 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4039 if (n_words == 2 && (gregno & 1) == 0)
4040 gregno += 1;
4041
a4b0320c
AH
4042 /* Long long and SPE vectors are not split between registers
4043 and stack. */
4cc833b7
RH
4044 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4045 {
4046 /* Long long is aligned on the stack. */
4047 if (n_words == 2)
4048 cum->words += cum->words & 1;
4049 cum->words += n_words;
4050 }
4697a36c 4051
4cc833b7
RH
4052 /* Note: continuing to accumulate gregno past when we've started
4053 spilling to the stack indicates the fact that we've started
4054 spilling to the stack to expand_builtin_saveregs. */
4055 cum->sysv_gregno = gregno + n_words;
4056 }
4697a36c 4057
4cc833b7
RH
4058 if (TARGET_DEBUG_ARG)
4059 {
4060 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4061 cum->words, cum->fregno);
4062 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4063 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4064 fprintf (stderr, "mode = %4s, named = %d\n",
4065 GET_MODE_NAME (mode), named);
4066 }
4697a36c
MM
4067 }
4068 else
4cc833b7
RH
4069 {
4070 int align = (TARGET_32BIT && (cum->words & 1) != 0
4071 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 4072
d34c5b80 4073 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 4074
a3170dc6
AH
4075 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4076 && TARGET_HARD_FLOAT && TARGET_FPRS)
fcce224d 4077 cum->fregno += (mode == TFmode ? 2 : 1);
4cc833b7
RH
4078
4079 if (TARGET_DEBUG_ARG)
4080 {
4081 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4082 cum->words, cum->fregno);
4083 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4084 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4085 fprintf (stderr, "named = %d, align = %d\n", named, align);
4086 }
4087 }
4697a36c 4088}
a6c9bed4
AH
4089
4090/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4091
a6c9bed4 4092static rtx
a2369ed3
DJ
4093rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4094 tree type)
a6c9bed4
AH
4095{
4096 if (cum->stdarg)
4097 {
4098 int gregno = cum->sysv_gregno;
4099 int n_words = RS6000_ARG_SIZE (mode, type);
4100
4101 /* SPE vectors are put in odd registers. */
4102 if (n_words == 2 && (gregno & 1) == 0)
4103 gregno += 1;
4104
4105 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4106 {
4107 rtx r1, r2;
4108 enum machine_mode m = SImode;
4109
4110 r1 = gen_rtx_REG (m, gregno);
4111 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4112 r2 = gen_rtx_REG (m, gregno + 1);
4113 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4114 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4115 }
4116 else
b78d48dd 4117 return NULL_RTX;
a6c9bed4
AH
4118 }
4119 else
4120 {
4121 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4122 return gen_rtx_REG (mode, cum->sysv_gregno);
4123 else
b78d48dd 4124 return NULL_RTX;
a6c9bed4
AH
4125 }
4126}
4127
b78d48dd
FJ
4128/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4129
4130static rtx
4131rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4132 tree type, int align_words)
4133{
4134 if (mode == DFmode)
4135 {
4136 /* -mpowerpc64 with 32bit ABI splits up a DFmode argument
4137 in vararg list into zero, one or two GPRs */
4138 if (align_words >= GP_ARG_NUM_REG)
4139 return gen_rtx_PARALLEL (DFmode,
4140 gen_rtvec (2,
4141 gen_rtx_EXPR_LIST (VOIDmode,
4142 NULL_RTX, const0_rtx),
4143 gen_rtx_EXPR_LIST (VOIDmode,
4144 gen_rtx_REG (mode,
4145 cum->fregno),
4146 const0_rtx)));
4147 else if (align_words + RS6000_ARG_SIZE (mode, type)
4148 > GP_ARG_NUM_REG)
4149 /* If this is partially on the stack, then we only
a3c9585f 4150 include the portion actually in registers here. */
b78d48dd
FJ
4151 return gen_rtx_PARALLEL (DFmode,
4152 gen_rtvec (2,
4153 gen_rtx_EXPR_LIST (VOIDmode,
4154 gen_rtx_REG (SImode,
4155 GP_ARG_MIN_REG
4156 + align_words),
4157 const0_rtx),
4158 gen_rtx_EXPR_LIST (VOIDmode,
4159 gen_rtx_REG (mode,
4160 cum->fregno),
4161 const0_rtx)));
4162
4163 /* split a DFmode arg into two GPRs */
4164 return gen_rtx_PARALLEL (DFmode,
4165 gen_rtvec (3,
4166 gen_rtx_EXPR_LIST (VOIDmode,
4167 gen_rtx_REG (SImode,
4168 GP_ARG_MIN_REG
4169 + align_words),
4170 const0_rtx),
4171 gen_rtx_EXPR_LIST (VOIDmode,
4172 gen_rtx_REG (SImode,
4173 GP_ARG_MIN_REG
4174 + align_words + 1),
4175 GEN_INT (4)),
4176 gen_rtx_EXPR_LIST (VOIDmode,
4177 gen_rtx_REG (mode, cum->fregno),
4178 const0_rtx)));
4179 }
4180 /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one
4181 or two GPRs */
4182 else if (mode == DImode)
4183 {
4184 if (align_words < GP_ARG_NUM_REG - 1)
4185 return gen_rtx_PARALLEL (DImode,
4186 gen_rtvec (2,
4187 gen_rtx_EXPR_LIST (VOIDmode,
4188 gen_rtx_REG (SImode,
4189 GP_ARG_MIN_REG
4190 + align_words),
4191 const0_rtx),
4192 gen_rtx_EXPR_LIST (VOIDmode,
4193 gen_rtx_REG (SImode,
4194 GP_ARG_MIN_REG
4195 + align_words + 1),
4196 GEN_INT (4))));
4197 else if (align_words == GP_ARG_NUM_REG - 1)
4198 return gen_rtx_PARALLEL (DImode,
4199 gen_rtvec (2,
4200 gen_rtx_EXPR_LIST (VOIDmode,
4201 NULL_RTX, const0_rtx),
4202 gen_rtx_EXPR_LIST (VOIDmode,
4203 gen_rtx_REG (SImode,
4204 GP_ARG_MIN_REG
4205 + align_words),
4206 const0_rtx)));
4207 }
4208 else if (mode == BLKmode && align_words <= (GP_ARG_NUM_REG - 1))
4209 {
4210 int k;
4211 int size = int_size_in_bytes (type);
2f7b62ef 4212 int no_units = ((size - 1) / 4) + 1;
b78d48dd
FJ
4213 int max_no_words = GP_ARG_NUM_REG - align_words;
4214 int rtlvec_len = no_units < max_no_words ? no_units : max_no_words;
4215 rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx));
4216
4217 memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx));
4218
4219 for (k=0; k < rtlvec_len; k++)
4220 rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode,
4221 gen_rtx_REG (SImode,
4222 GP_ARG_MIN_REG
4223 + align_words + k),
4224 k == 0 ? const0_rtx : GEN_INT (k*4));
4225
4226 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (k, rtlvec));
4227 }
4228
4229 return NULL_RTX;
4230}
4231
4697a36c
MM
4232/* Determine where to put an argument to a function.
4233 Value is zero to push the argument on the stack,
4234 or a hard register in which to store the argument.
4235
4236 MODE is the argument's machine mode.
4237 TYPE is the data type of the argument (as a tree).
4238 This is null for libcalls where that information may
4239 not be available.
4240 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4241 the preceding args and about the function being called.
4242 NAMED is nonzero if this argument is a named parameter
4243 (otherwise it is an extra parameter matching an ellipsis).
4244
4245 On RS/6000 the first eight words of non-FP are normally in registers
4246 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4247 Under V.4, the first 8 FP args are in registers.
4248
4249 If this is floating-point and no prototype is specified, we use
4250 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4251 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4252 so we can pass the FP value just in one register. emit_library_function
1c20ae99 4253 doesn't support PARALLEL anyway. */
4697a36c
MM
4254
4255struct rtx_def *
a2369ed3
DJ
4256function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4257 tree type, int named)
4697a36c 4258{
4cc833b7 4259 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4260
a4f6c312
SS
4261 /* Return a marker to indicate whether CR1 needs to set or clear the
4262 bit that V.4 uses to say fp args were passed in registers.
4263 Assume that we don't need the marker for software floating point,
4264 or compiler generated library calls. */
4697a36c
MM
4265 if (mode == VOIDmode)
4266 {
f607bc57 4267 if (abi == ABI_V4
7509c759 4268 && cum->nargs_prototype < 0
b9599e46
FS
4269 && (cum->call_cookie & CALL_LIBCALL) == 0
4270 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4271 {
a3170dc6
AH
4272 /* For the SPE, we need to crxor CR6 always. */
4273 if (TARGET_SPE_ABI)
4274 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4275 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4276 return GEN_INT (cum->call_cookie
4277 | ((cum->fregno == FP_ARG_MIN_REG)
4278 ? CALL_V4_SET_FP_ARGS
4279 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4280 }
4697a36c 4281
7509c759 4282 return GEN_INT (cum->call_cookie);
4697a36c
MM
4283 }
4284
2858f73a 4285 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4286 if (TARGET_64BIT && ! cum->prototype)
4287 {
4288 /* Vector parameters get passed in vector register
4289 and also in GPRs or memory, in absence of prototype. */
4290 int align_words;
4291 rtx slot;
4292 align_words = (cum->words + 1) & ~1;
4293
4294 if (align_words >= GP_ARG_NUM_REG)
4295 {
4296 slot = NULL_RTX;
4297 }
4298 else
4299 {
4300 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4301 }
4302 return gen_rtx_PARALLEL (mode,
4303 gen_rtvec (2,
4304 gen_rtx_EXPR_LIST (VOIDmode,
4305 slot, const0_rtx),
4306 gen_rtx_EXPR_LIST (VOIDmode,
4307 gen_rtx_REG (mode, cum->vregno),
4308 const0_rtx)));
4309 }
4310 else
4311 return gen_rtx_REG (mode, cum->vregno);
2858f73a 4312 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4313 {
2858f73a 4314 if (named || abi == ABI_V4)
a594a19c 4315 return NULL_RTX;
0ac081f6 4316 else
a594a19c
GK
4317 {
4318 /* Vector parameters to varargs functions under AIX or Darwin
4319 get passed in memory and possibly also in GPRs. */
4320 int align, align_words;
2858f73a 4321 enum machine_mode part_mode = mode;
a594a19c
GK
4322
4323 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
4324 2 mod 4 in terms of words in 32-bit mode, since the parameter
4325 save area starts at offset 24 from the stack. In 64-bit mode,
4326 they just have to start on an even word, since the parameter
4327 save area is 16-byte aligned. */
4328 if (TARGET_32BIT)
4329 align = ((6 - (cum->words & 3)) & 3);
4330 else
4331 align = cum->words & 1;
a594a19c
GK
4332 align_words = cum->words + align;
4333
4334 /* Out of registers? Memory, then. */
4335 if (align_words >= GP_ARG_NUM_REG)
4336 return NULL_RTX;
4337
2858f73a
GK
4338 /* The vector value goes in GPRs. Only the part of the
4339 value in GPRs is reported here. */
4340 if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS)
4341 > GP_ARG_NUM_REG)
839a4992 4342 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
4343 is either wholly in GPRs or half in GPRs and half not. */
4344 part_mode = DImode;
4345
4346 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 4347 }
0ac081f6 4348 }
a6c9bed4
AH
4349 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4350 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4351 else if (abi == ABI_V4)
4697a36c 4352 {
a3170dc6 4353 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4354 && (mode == SFmode || mode == DFmode))
4355 {
4356 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4357 return gen_rtx_REG (mode, cum->fregno);
4358 else
b78d48dd 4359 return NULL_RTX;
4cc833b7
RH
4360 }
4361 else
4362 {
4363 int n_words;
4364 int gregno = cum->sysv_gregno;
4365
4366 /* Aggregates and IEEE quad get passed by reference. */
4367 if ((type && AGGREGATE_TYPE_P (type))
4368 || mode == TFmode)
4369 n_words = 1;
4370 else
d34c5b80 4371 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 4372
a4b0320c 4373 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4374 if (n_words == 2 && (gregno & 1) == 0)
4375 gregno += 1;
4376
a6c9bed4 4377 /* Long long do not split between registers and stack. */
4cc833b7 4378 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4379 return gen_rtx_REG (mode, gregno);
4cc833b7 4380 else
b78d48dd 4381 return NULL_RTX;
4cc833b7 4382 }
4697a36c 4383 }
4cc833b7
RH
4384 else
4385 {
4386 int align = (TARGET_32BIT && (cum->words & 1) != 0
4387 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
4388 int align_words = cum->words + align;
4697a36c 4389
4cc833b7
RH
4390 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4391 return NULL_RTX;
4392
b78d48dd
FJ
4393 if (TARGET_32BIT && TARGET_POWERPC64
4394 && (mode == DFmode || mode == DImode || mode == BLKmode))
4395 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4396
2858f73a 4397 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7
RH
4398 {
4399 if (! type
4400 || ((cum->nargs_prototype > 0)
4401 /* IBM AIX extended its linkage convention definition always
4402 to require FP args after register save area hole on the
4403 stack. */
4404 && (DEFAULT_ABI != ABI_AIX
4405 || ! TARGET_XL_CALL
4406 || (align_words < GP_ARG_NUM_REG))))
4407 return gen_rtx_REG (mode, cum->fregno);
4408
4409 return gen_rtx_PARALLEL (mode,
4410 gen_rtvec (2,
39403d82 4411 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
4412 ((align_words >= GP_ARG_NUM_REG)
4413 ? NULL_RTX
4414 : (align_words
d34c5b80 4415 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
4416 > GP_ARG_NUM_REG
4417 /* If this is partially on the stack, then
4418 we only include the portion actually
4419 in registers here. */
39403d82 4420 ? gen_rtx_REG (SImode,
1c20ae99 4421 GP_ARG_MIN_REG + align_words)
39403d82 4422 : gen_rtx_REG (mode,
1c20ae99
JW
4423 GP_ARG_MIN_REG + align_words))),
4424 const0_rtx),
39403d82
DE
4425 gen_rtx_EXPR_LIST (VOIDmode,
4426 gen_rtx_REG (mode, cum->fregno),
1c20ae99 4427 const0_rtx)));
4cc833b7
RH
4428 }
4429 else if (align_words < GP_ARG_NUM_REG)
4430 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4431 else
4432 return NULL_RTX;
4697a36c 4433 }
4697a36c
MM
4434}
4435\f
4436/* For an arg passed partly in registers and partly in memory,
4437 this is the number of registers used.
4438 For args passed entirely in registers or entirely in memory, zero. */
4439
4440int
a2369ed3 4441function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 4442 tree type, int named)
4697a36c 4443{
f607bc57 4444 if (DEFAULT_ABI == ABI_V4)
4697a36c 4445 return 0;
4697a36c 4446
2858f73a
GK
4447 if (USE_FP_FOR_ARG_P (cum, mode, type)
4448 || USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
4697a36c
MM
4449 {
4450 if (cum->nargs_prototype >= 0)
4451 return 0;
4452 }
4453
4454 if (cum->words < GP_ARG_NUM_REG
d34c5b80 4455 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
4456 {
4457 int ret = GP_ARG_NUM_REG - cum->words;
4458 if (ret && TARGET_DEBUG_ARG)
4459 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4460
4461 return ret;
4462 }
4463
4464 return 0;
4465}
4466\f
4467/* A C expression that indicates when an argument must be passed by
4468 reference. If nonzero for an argument, a copy of that argument is
4469 made in memory and a pointer to the argument is passed instead of
4470 the argument itself. The pointer is passed in whatever way is
4471 appropriate for passing a pointer to that type.
4472
c8c99a68
DE
4473 Under V.4, structures and unions are passed by reference.
4474
4475 As an extension to all ABIs, variable sized types are passed by
4476 reference. */
4697a36c
MM
4477
4478int
a2369ed3
DJ
4479function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4480 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 4481 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 4482{
f607bc57 4483 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
4484 && ((type && AGGREGATE_TYPE_P (type))
4485 || mode == TFmode))
4697a36c
MM
4486 {
4487 if (TARGET_DEBUG_ARG)
4488 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
4489
4490 return 1;
4491 }
fff2cb99 4492 return type && int_size_in_bytes (type) < 0;
4697a36c 4493}
5985c7a6
FJ
4494
4495static void
2d9db8eb 4496rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
4497{
4498 int i;
4499 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
4500
4501 if (nregs == 0)
4502 return;
4503
4504 for (i = 0; i < nregs; i++)
4505 {
4506 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
4507 if (reload_completed)
4508 {
4509 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
4510 tem = NULL_RTX;
4511 else
4512 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
4513 i * GET_MODE_SIZE(reg_mode));
4514 }
4515 else
4516 tem = replace_equiv_address (tem, XEXP (tem, 0));
4517
4518 if (tem == NULL_RTX)
4519 abort ();
4520
4521 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
4522 }
4523}
4524
4697a36c
MM
4525\f
4526/* Perform any needed actions needed for a function that is receiving a
4527 variable number of arguments.
4528
4529 CUM is as above.
4530
4531 MODE and TYPE are the mode and type of the current parameter.
4532
4533 PRETEND_SIZE is a variable that should be set to the amount of stack
4534 that must be pushed by the prolog to pretend that our caller pushed
4535 it.
4536
4537 Normally, this macro will push all remaining incoming registers on the
4538 stack and set PRETEND_SIZE to the length of the registers pushed. */
4539
c6e8c921 4540static void
a2369ed3
DJ
4541setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4542 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4543{
4cc833b7
RH
4544 CUMULATIVE_ARGS next_cum;
4545 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4546 rtx save_area = NULL_RTX, mem;
dfafc897 4547 int first_reg_offset, set;
4697a36c 4548
f31bf321 4549 /* Skip the last named argument. */
d34c5b80 4550 next_cum = *cum;
f31bf321 4551 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4552
f607bc57 4553 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4554 {
4cc833b7 4555 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4556 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4557 if (! no_rtl)
2c4974b7 4558 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4559 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4560
4561 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4562 }
60e2d0ca 4563 else
4697a36c 4564 {
d34c5b80 4565 first_reg_offset = next_cum.words;
4cc833b7 4566 save_area = virtual_incoming_args_rtx;
00dba523 4567 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4568
4569 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 4570 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 4571 }
4697a36c 4572
dfafc897 4573 set = get_varargs_alias_set ();
c81fc13e 4574 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4575 {
dfafc897
FS
4576 mem = gen_rtx_MEM (BLKmode,
4577 plus_constant (save_area,
4578 first_reg_offset * reg_size)),
ba4828e0 4579 set_mem_alias_set (mem, set);
8ac61af7 4580 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4581
5985c7a6
FJ
4582 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4583 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4584 }
4585
4697a36c 4586 /* Save FP registers if needed. */
f607bc57 4587 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4588 && TARGET_HARD_FLOAT && TARGET_FPRS
4589 && ! no_rtl
4cc833b7 4590 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4591 {
4cc833b7 4592 int fregno = next_cum.fregno;
9ebbca7d 4593 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4594 rtx lab = gen_label_rtx ();
4595 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4596
4cc833b7 4597 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4598 pc_rtx,
39403d82 4599 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4600 gen_rtx_NE (VOIDmode, cr1,
4601 const0_rtx),
39403d82 4602 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4603 pc_rtx)));
4604
4cc833b7
RH
4605 while (fregno <= FP_ARG_V4_MAX_REG)
4606 {
dfafc897 4607 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4608 set_mem_alias_set (mem, set);
dfafc897 4609 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4610 fregno++;
4611 off += 8;
4697a36c 4612 }
4cc833b7
RH
4613
4614 emit_label (lab);
4697a36c 4615 }
4697a36c 4616}
4697a36c 4617
dfafc897 4618/* Create the va_list data type. */
2c4974b7 4619
c35d187f
RH
4620static tree
4621rs6000_build_builtin_va_list (void)
dfafc897 4622{
64c2816f 4623 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4624
9ebbca7d
GK
4625 /* For AIX, prefer 'char *' because that's what the system
4626 header files like. */
f607bc57 4627 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4628 return build_pointer_type (char_type_node);
dfafc897 4629
f1e639b1 4630 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4631 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4632
9ebbca7d
GK
4633 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4634 unsigned_char_type_node);
4635 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4636 unsigned_char_type_node);
64c2816f
DT
4637 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4638 every user file. */
4639 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4640 short_unsigned_type_node);
dfafc897
FS
4641 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4642 ptr_type_node);
4643 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4644 ptr_type_node);
4645
4646 DECL_FIELD_CONTEXT (f_gpr) = record;
4647 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4648 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4649 DECL_FIELD_CONTEXT (f_ovf) = record;
4650 DECL_FIELD_CONTEXT (f_sav) = record;
4651
bab45a51
FS
4652 TREE_CHAIN (record) = type_decl;
4653 TYPE_NAME (record) = type_decl;
dfafc897
FS
4654 TYPE_FIELDS (record) = f_gpr;
4655 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4656 TREE_CHAIN (f_fpr) = f_res;
4657 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4658 TREE_CHAIN (f_ovf) = f_sav;
4659
4660 layout_type (record);
4661
4662 /* The correct type is an array type of one element. */
4663 return build_array_type (record, build_index_type (size_zero_node));
4664}
4665
4666/* Implement va_start. */
4667
4668void
a2369ed3 4669rs6000_va_start (tree valist, rtx nextarg)
4697a36c 4670{
dfafc897 4671 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 4672 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 4673 tree gpr, fpr, ovf, sav, t;
2c4974b7 4674
dfafc897 4675 /* Only SVR4 needs something special. */
f607bc57 4676 if (DEFAULT_ABI != ABI_V4)
dfafc897 4677 {
e5faf155 4678 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
4679 return;
4680 }
4681
973a648b 4682 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4683 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4684 f_res = TREE_CHAIN (f_fpr);
4685 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4686 f_sav = TREE_CHAIN (f_ovf);
4687
8ebecc3b 4688 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4689 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4690 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4691 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4692 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4693
4694 /* Count number of gp and fp argument registers used. */
4cc833b7 4695 words = current_function_args_info.words;
dfafc897
FS
4696 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
4697 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
4698
4699 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
4700 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
4701 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
4702 words, n_gpr, n_fpr);
dfafc897
FS
4703
4704 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
4705 TREE_SIDE_EFFECTS (t) = 1;
4706 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4707
4708 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
4709 TREE_SIDE_EFFECTS (t) = 1;
4710 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4711
4712 /* Find the overflow area. */
4713 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
4714 if (words != 0)
4715 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
4716 build_int_2 (words * UNITS_PER_WORD, 0));
4717 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4718 TREE_SIDE_EFFECTS (t) = 1;
4719 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4720
4721 /* Find the register save area. */
4722 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
4723 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
4724 build_int_2 (-RS6000_VARARGS_SIZE, -1));
4725 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
4726 TREE_SIDE_EFFECTS (t) = 1;
4727 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4728}
4729
4730/* Implement va_arg. */
4731
4732rtx
a2369ed3 4733rs6000_va_arg (tree valist, tree type)
dfafc897 4734{
c566f9bd 4735 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
4736 tree gpr, fpr, ovf, sav, reg, t, u;
4737 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
4738 rtx lab_false, lab_over, addr_rtx, r;
4739
f607bc57 4740 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
4741 {
4742 /* Variable sized types are passed by reference. */
fff2cb99 4743 if (int_size_in_bytes (type) < 0)
c8c99a68
DE
4744 {
4745 u = build_pointer_type (type);
4746
4747 /* Args grow upward. */
4748 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
4749 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4750 TREE_SIDE_EFFECTS (t) = 1;
4751
4752 t = build1 (NOP_EXPR, build_pointer_type (u), t);
4753 TREE_SIDE_EFFECTS (t) = 1;
4754
4755 t = build1 (INDIRECT_REF, u, t);
4756 TREE_SIDE_EFFECTS (t) = 1;
4757
4758 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4759 }
4760 else
b0fadda7 4761 return std_expand_builtin_va_arg (valist, type);
c8c99a68 4762 }
dfafc897 4763
973a648b 4764 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4765 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4766 f_res = TREE_CHAIN (f_fpr);
4767 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4768 f_sav = TREE_CHAIN (f_ovf);
4769
8ebecc3b 4770 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4771 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4772 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4773 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4774 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4775
4776 size = int_size_in_bytes (type);
4777 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 4778
dfafc897 4779 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 4780 {
dfafc897
FS
4781 /* Aggregates and long doubles are passed by reference. */
4782 indirect_p = 1;
4783 reg = gpr;
4784 n_reg = 1;
4785 sav_ofs = 0;
4786 sav_scale = 4;
d3294cd9
FS
4787 size = UNITS_PER_WORD;
4788 rsize = 1;
dfafc897 4789 }
a3170dc6 4790 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
4791 {
4792 /* FP args go in FP registers, if present. */
4793 indirect_p = 0;
4794 reg = fpr;
4795 n_reg = 1;
4796 sav_ofs = 8*4;
4797 sav_scale = 8;
4cc833b7 4798 }
dfafc897
FS
4799 else
4800 {
4801 /* Otherwise into GP registers. */
4802 indirect_p = 0;
4803 reg = gpr;
4804 n_reg = rsize;
4805 sav_ofs = 0;
4806 sav_scale = 4;
4807 }
4808
a3c9585f 4809 /* Pull the value out of the saved registers.... */
dfafc897
FS
4810
4811 lab_false = gen_label_rtx ();
4812 lab_over = gen_label_rtx ();
4813 addr_rtx = gen_reg_rtx (Pmode);
4814
16861f33
AH
4815 /* AltiVec vectors never go in registers. */
4816 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 4817 {
41daaf0e
AH
4818 TREE_THIS_VOLATILE (reg) = 1;
4819 emit_cmp_and_jump_insns
4820 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
4821 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
4822 lab_false);
dfafc897 4823
41daaf0e
AH
4824 /* Long long is aligned in the registers. */
4825 if (n_reg > 1)
4826 {
4827 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
4828 build_int_2 (n_reg - 1, 0));
4829 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
4830 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
4831 TREE_SIDE_EFFECTS (u) = 1;
4832 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
4833 }
2c4974b7 4834
41daaf0e
AH
4835 if (sav_ofs)
4836 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
4837 else
4838 t = sav;
2c4974b7 4839
41daaf0e
AH
4840 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
4841 build_int_2 (n_reg, 0));
4842 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 4843
41daaf0e
AH
4844 u = build1 (CONVERT_EXPR, integer_type_node, u);
4845 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4846
41daaf0e
AH
4847 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
4848 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4849
41daaf0e
AH
4850 t = build (PLUS_EXPR, ptr_type_node, t, u);
4851 TREE_SIDE_EFFECTS (t) = 1;
4852
4853 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4854 if (r != addr_rtx)
4855 emit_move_insn (addr_rtx, r);
4856
4857 emit_jump_insn (gen_jump (lab_over));
4858 emit_barrier ();
4859 }
dfafc897 4860
dfafc897
FS
4861 emit_label (lab_false);
4862
a4f6c312 4863 /* ... otherwise out of the overflow area. */
dfafc897 4864
41daaf0e
AH
4865 /* Make sure we don't find reg 7 for the next int arg.
4866
4867 All AltiVec vectors go in the overflow area. So in the AltiVec
4868 case we need to get the vectors from the overflow area, but
4869 remember where the GPRs and FPRs are. */
16861f33
AH
4870 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
4871 || !TARGET_ALTIVEC))
dfafc897
FS
4872 {
4873 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
4874 TREE_SIDE_EFFECTS (t) = 1;
4875 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4876 }
4877
4878 /* Care for on-stack alignment if needed. */
4879 if (rsize <= 1)
4880 t = ovf;
4881 else
4882 {
41daaf0e
AH
4883 int align;
4884
16861f33
AH
4885 /* AltiVec vectors are 16 byte aligned. */
4886 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
4887 align = 15;
4888 else
4889 align = 7;
4890
4891 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
4892 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
4893 }
4894 t = save_expr (t);
4895
4896 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4897 if (r != addr_rtx)
4898 emit_move_insn (addr_rtx, r);
4899
4900 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
4901 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4902 TREE_SIDE_EFFECTS (t) = 1;
4903 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4904
4905 emit_label (lab_over);
4906
4907 if (indirect_p)
4908 {
4909 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 4910 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
4911 emit_move_insn (addr_rtx, r);
4912 }
4913
4914 return addr_rtx;
4697a36c 4915}
0ac081f6
AH
4916
4917/* Builtins. */
4918
6a2dd09a
RS
4919#define def_builtin(MASK, NAME, TYPE, CODE) \
4920do { \
4921 if ((MASK) & target_flags) \
4922 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
4923 NULL, NULL_TREE); \
0ac081f6
AH
4924} while (0)
4925
24408032
AH
4926/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
4927
2212663f 4928static const struct builtin_description bdesc_3arg[] =
24408032
AH
4929{
4930 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
4931 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
4932 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
4933 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
4934 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
4935 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
4936 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
4937 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
4938 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
4939 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
4940 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
4941 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
4942 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
4943 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
4944 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
4945 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
4946 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
4947 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
4948 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
4949 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
4950 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
4951 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
4952 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
4953};
2212663f 4954
95385cbb
AH
4955/* DST operations: void foo (void *, const int, const char). */
4956
4957static const struct builtin_description bdesc_dst[] =
4958{
4959 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
4960 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
4961 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
4962 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
4963};
4964
2212663f 4965/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 4966
a3170dc6 4967static struct builtin_description bdesc_2arg[] =
0ac081f6 4968{
f18c054f
DB
4969 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
4970 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
4971 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
4972 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
4973 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
4974 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
4975 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
4976 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
4977 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
4978 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
4979 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 4980 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
4981 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
4982 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
4983 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
4984 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
4985 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
4986 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
4987 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
4988 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
4989 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
4990 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
4991 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
4992 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
4993 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
4994 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
4995 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
4996 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
4997 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
4998 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
4999 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5000 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5001 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5002 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5003 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5004 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5005 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5006 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5007 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5008 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5009 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5010 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5011 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5012 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5013 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5014 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5015 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5016 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5017 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5018 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5019 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5020 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5021 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5022 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5023 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5024 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5025 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5026 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5027 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5028 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5029 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5030 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5031 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5032 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5033 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5034 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5035 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5036 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5037 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5038 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5039 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5040 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5041 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5042 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5043 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5044 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5045 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5046 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5047 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5048 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5049 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5050 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5051 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5052 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5053 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5054 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5055 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5056 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5057 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5058 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5059 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5060 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5061 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5062 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5063 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5064 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5065 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5066 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5067 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5068 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5069 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5070 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5071 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5072 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5073 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5074 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5075 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5076 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5077 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5078 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5079 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5080 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5081 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5082
5083 /* Place holder, leave as first spe builtin. */
5084 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5085 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5086 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5087 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5088 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5089 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5090 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5091 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5092 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5093 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5094 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5095 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5096 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5097 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5098 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5099 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5100 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5101 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5102 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5103 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5104 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5105 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5106 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5107 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5108 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5109 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5110 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5111 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5112 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5113 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5114 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5115 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5116 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5117 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5118 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5119 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5120 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5121 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5122 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5123 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5124 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5125 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5126 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5127 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5128 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5129 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5130 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5131 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5132 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5133 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5134 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5135 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5136 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5137 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5138 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5139 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5140 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5141 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5142 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5143 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5144 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5145 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5146 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5147 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5148 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5149 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5150 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5151 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5152 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5153 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5154 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5155 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5156 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5157 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5158 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5159 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5160 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5161 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5162 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5163 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5164 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5165 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5166 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5167 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5168 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5169 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5170 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5171 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5172 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5173 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5174 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5175 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5176 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5177 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5178 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5179 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
5180 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
5181 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
5182 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
5183 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
5184 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
5185 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
5186 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
5187 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
5188 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
5189 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
5190 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
5191 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
5192 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
5193
5194 /* SPE binary operations expecting a 5-bit unsigned literal. */
5195 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
5196
5197 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
5198 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
5199 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
5200 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
5201 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
5202 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
5203 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
5204 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
5205 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
5206 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
5207 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
5208 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
5209 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
5210 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
5211 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
5212 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
5213 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
5214 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
5215 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
5216 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
5217 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
5218 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
5219 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
5220 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
5221 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
5222 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
5223
5224 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 5225 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
5226};
5227
5228/* AltiVec predicates. */
5229
5230struct builtin_description_predicates
5231{
5232 const unsigned int mask;
5233 const enum insn_code icode;
5234 const char *opcode;
5235 const char *const name;
5236 const enum rs6000_builtins code;
5237};
5238
5239static const struct builtin_description_predicates bdesc_altivec_preds[] =
5240{
5241 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
5242 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
5243 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
5244 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
5245 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
5246 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
5247 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
5248 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
5249 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
5250 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
5251 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
5252 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
5253 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 5254};
24408032 5255
a3170dc6
AH
5256/* SPE predicates. */
5257static struct builtin_description bdesc_spe_predicates[] =
5258{
5259 /* Place-holder. Leave as first. */
5260 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
5261 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
5262 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
5263 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
5264 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
5265 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
5266 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
5267 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
5268 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
5269 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
5270 /* Place-holder. Leave as last. */
5271 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
5272};
5273
5274/* SPE evsel predicates. */
5275static struct builtin_description bdesc_spe_evsel[] =
5276{
5277 /* Place-holder. Leave as first. */
5278 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
5279 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
5280 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
5281 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
5282 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
5283 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
5284 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
5285 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
5286 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
5287 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
5288 /* Place-holder. Leave as last. */
5289 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
5290};
5291
b6d08ca1 5292/* ABS* operations. */
100c4561
AH
5293
5294static const struct builtin_description bdesc_abs[] =
5295{
5296 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
5297 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
5298 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
5299 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
5300 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
5301 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
5302 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
5303};
5304
617e0e1d
DB
5305/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
5306 foo (VECa). */
24408032 5307
a3170dc6 5308static struct builtin_description bdesc_1arg[] =
2212663f 5309{
617e0e1d
DB
5310 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
5311 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
5312 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
5313 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
5314 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
5315 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
5316 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
5317 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
5318 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
5319 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
5320 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
5321 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
5322 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
5323 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
5324 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
5325 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
5326 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
5327
5328 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
5329 end with SPE_BUILTIN_EVSUBFUSIAAW. */
5330 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
5331 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
5332 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
5333 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
5334 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
5335 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
5336 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
5337 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
5338 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
5339 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
5340 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
5341 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
5342 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
5343 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
5344 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
5345 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
5346 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
5347 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
5348 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
5349 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
5350 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
5351 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
5352 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
5353 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
5354 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
5355 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
5356 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
5357 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
5358
5359 /* Place-holder. Leave as last unary SPE builtin. */
5360 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
5361};
5362
5363static rtx
a2369ed3 5364rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5365{
5366 rtx pat;
5367 tree arg0 = TREE_VALUE (arglist);
5368 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5369 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5370 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5371
0559cc77
DE
5372 if (icode == CODE_FOR_nothing)
5373 /* Builtin not supported on this processor. */
5374 return 0;
5375
20e26713
AH
5376 /* If we got invalid arguments bail out before generating bad rtl. */
5377 if (arg0 == error_mark_node)
9a171fcd 5378 return const0_rtx;
20e26713 5379
0559cc77
DE
5380 if (icode == CODE_FOR_altivec_vspltisb
5381 || icode == CODE_FOR_altivec_vspltish
5382 || icode == CODE_FOR_altivec_vspltisw
5383 || icode == CODE_FOR_spe_evsplatfi
5384 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
5385 {
5386 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
5387 if (GET_CODE (op0) != CONST_INT
5388 || INTVAL (op0) > 0x1f
5389 || INTVAL (op0) < -0x1f)
5390 {
5391 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 5392 return const0_rtx;
b44140e7 5393 }
b44140e7
AH
5394 }
5395
c62f2db5 5396 if (target == 0
2212663f
DB
5397 || GET_MODE (target) != tmode
5398 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5399 target = gen_reg_rtx (tmode);
5400
5401 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5402 op0 = copy_to_mode_reg (mode0, op0);
5403
5404 pat = GEN_FCN (icode) (target, op0);
5405 if (! pat)
5406 return 0;
5407 emit_insn (pat);
0ac081f6 5408
2212663f
DB
5409 return target;
5410}
ae4b4a02 5411
100c4561 5412static rtx
a2369ed3 5413altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
5414{
5415 rtx pat, scratch1, scratch2;
5416 tree arg0 = TREE_VALUE (arglist);
5417 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5418 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5419 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5420
5421 /* If we have invalid arguments, bail out before generating bad rtl. */
5422 if (arg0 == error_mark_node)
9a171fcd 5423 return const0_rtx;
100c4561
AH
5424
5425 if (target == 0
5426 || GET_MODE (target) != tmode
5427 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5428 target = gen_reg_rtx (tmode);
5429
5430 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5431 op0 = copy_to_mode_reg (mode0, op0);
5432
5433 scratch1 = gen_reg_rtx (mode0);
5434 scratch2 = gen_reg_rtx (mode0);
5435
5436 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
5437 if (! pat)
5438 return 0;
5439 emit_insn (pat);
5440
5441 return target;
5442}
5443
0ac081f6 5444static rtx
a2369ed3 5445rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
5446{
5447 rtx pat;
5448 tree arg0 = TREE_VALUE (arglist);
5449 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5450 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5451 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5452 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5453 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5454 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5455
0559cc77
DE
5456 if (icode == CODE_FOR_nothing)
5457 /* Builtin not supported on this processor. */
5458 return 0;
5459
20e26713
AH
5460 /* If we got invalid arguments bail out before generating bad rtl. */
5461 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5462 return const0_rtx;
20e26713 5463
0559cc77
DE
5464 if (icode == CODE_FOR_altivec_vcfux
5465 || icode == CODE_FOR_altivec_vcfsx
5466 || icode == CODE_FOR_altivec_vctsxs
5467 || icode == CODE_FOR_altivec_vctuxs
5468 || icode == CODE_FOR_altivec_vspltb
5469 || icode == CODE_FOR_altivec_vsplth
5470 || icode == CODE_FOR_altivec_vspltw
5471 || icode == CODE_FOR_spe_evaddiw
5472 || icode == CODE_FOR_spe_evldd
5473 || icode == CODE_FOR_spe_evldh
5474 || icode == CODE_FOR_spe_evldw
5475 || icode == CODE_FOR_spe_evlhhesplat
5476 || icode == CODE_FOR_spe_evlhhossplat
5477 || icode == CODE_FOR_spe_evlhhousplat
5478 || icode == CODE_FOR_spe_evlwhe
5479 || icode == CODE_FOR_spe_evlwhos
5480 || icode == CODE_FOR_spe_evlwhou
5481 || icode == CODE_FOR_spe_evlwhsplat
5482 || icode == CODE_FOR_spe_evlwwsplat
5483 || icode == CODE_FOR_spe_evrlwi
5484 || icode == CODE_FOR_spe_evslwi
5485 || icode == CODE_FOR_spe_evsrwis
f5119d10 5486 || icode == CODE_FOR_spe_evsubifw
0559cc77 5487 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
5488 {
5489 /* Only allow 5-bit unsigned literals. */
b44140e7
AH
5490 if (TREE_CODE (arg1) != INTEGER_CST
5491 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5492 {
5493 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 5494 return const0_rtx;
b44140e7 5495 }
b44140e7
AH
5496 }
5497
c62f2db5 5498 if (target == 0
0ac081f6
AH
5499 || GET_MODE (target) != tmode
5500 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5501 target = gen_reg_rtx (tmode);
5502
5503 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5504 op0 = copy_to_mode_reg (mode0, op0);
5505 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5506 op1 = copy_to_mode_reg (mode1, op1);
5507
5508 pat = GEN_FCN (icode) (target, op0, op1);
5509 if (! pat)
5510 return 0;
5511 emit_insn (pat);
5512
5513 return target;
5514}
6525c0e7 5515
ae4b4a02 5516static rtx
a2369ed3
DJ
5517altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
5518 tree arglist, rtx target)
ae4b4a02
AH
5519{
5520 rtx pat, scratch;
5521 tree cr6_form = TREE_VALUE (arglist);
5522 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5523 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5524 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5525 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5526 enum machine_mode tmode = SImode;
5527 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5528 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5529 int cr6_form_int;
5530
5531 if (TREE_CODE (cr6_form) != INTEGER_CST)
5532 {
5533 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5534 return const0_rtx;
ae4b4a02
AH
5535 }
5536 else
5537 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5538
5539 if (mode0 != mode1)
5540 abort ();
5541
5542 /* If we have invalid arguments, bail out before generating bad rtl. */
5543 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5544 return const0_rtx;
ae4b4a02
AH
5545
5546 if (target == 0
5547 || GET_MODE (target) != tmode
5548 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5549 target = gen_reg_rtx (tmode);
5550
5551 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5552 op0 = copy_to_mode_reg (mode0, op0);
5553 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5554 op1 = copy_to_mode_reg (mode1, op1);
5555
5556 scratch = gen_reg_rtx (mode0);
5557
5558 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 5559 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
5560 if (! pat)
5561 return 0;
5562 emit_insn (pat);
5563
5564 /* The vec_any* and vec_all* predicates use the same opcodes for two
5565 different operations, but the bits in CR6 will be different
5566 depending on what information we want. So we have to play tricks
5567 with CR6 to get the right bits out.
5568
5569 If you think this is disgusting, look at the specs for the
5570 AltiVec predicates. */
5571
5572 switch (cr6_form_int)
5573 {
5574 case 0:
5575 emit_insn (gen_cr6_test_for_zero (target));
5576 break;
5577 case 1:
5578 emit_insn (gen_cr6_test_for_zero_reverse (target));
5579 break;
5580 case 2:
5581 emit_insn (gen_cr6_test_for_lt (target));
5582 break;
5583 case 3:
5584 emit_insn (gen_cr6_test_for_lt_reverse (target));
5585 break;
5586 default:
5587 error ("argument 1 of __builtin_altivec_predicate is out of range");
5588 break;
5589 }
5590
5591 return target;
5592}
5593
b4a62fa0 5594static rtx
38f391a5 5595altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
5596{
5597 rtx pat, addr;
5598 tree arg0 = TREE_VALUE (arglist);
5599 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5600 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5601 enum machine_mode mode0 = Pmode;
5602 enum machine_mode mode1 = Pmode;
5603 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5604 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5605
5606 if (icode == CODE_FOR_nothing)
5607 /* Builtin not supported on this processor. */
5608 return 0;
5609
5610 /* If we got invalid arguments bail out before generating bad rtl. */
5611 if (arg0 == error_mark_node || arg1 == error_mark_node)
5612 return const0_rtx;
5613
5614 if (target == 0
5615 || GET_MODE (target) != tmode
5616 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5617 target = gen_reg_rtx (tmode);
5618
5619 op1 = copy_to_mode_reg (mode1, op1);
5620
5621 if (op0 == const0_rtx)
5622 {
5623 addr = gen_rtx_MEM (tmode, op1);
5624 }
5625 else
5626 {
5627 op0 = copy_to_mode_reg (mode0, op0);
5628 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
5629 }
5630
5631 pat = GEN_FCN (icode) (target, addr);
5632
5633 if (! pat)
5634 return 0;
5635 emit_insn (pat);
5636
5637 return target;
5638}
5639
6525c0e7 5640static rtx
a2369ed3 5641altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
5642{
5643 tree arg0 = TREE_VALUE (arglist);
5644 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5645 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5646 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5647 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5648 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
5649 rtx pat, addr;
5650 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5651 enum machine_mode mode1 = Pmode;
5652 enum machine_mode mode2 = Pmode;
6525c0e7
AH
5653
5654 /* Invalid arguments. Bail before doing anything stoopid! */
5655 if (arg0 == error_mark_node
5656 || arg1 == error_mark_node
5657 || arg2 == error_mark_node)
9a171fcd 5658 return const0_rtx;
6525c0e7 5659
b4a62fa0
SB
5660 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
5661 op0 = copy_to_mode_reg (tmode, op0);
5662
5663 op2 = copy_to_mode_reg (mode2, op2);
5664
5665 if (op1 == const0_rtx)
5666 {
5667 addr = gen_rtx_MEM (tmode, op2);
5668 }
5669 else
5670 {
5671 op1 = copy_to_mode_reg (mode1, op1);
5672 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
5673 }
6525c0e7 5674
b4a62fa0 5675 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
5676 if (pat)
5677 emit_insn (pat);
5678 return NULL_RTX;
5679}
5680
2212663f 5681static rtx
a2369ed3 5682rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5683{
5684 rtx pat;
5685 tree arg0 = TREE_VALUE (arglist);
5686 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5687 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5688 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5689 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5690 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5691 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5692 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5693 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5694 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 5695
774b5662
DE
5696 if (icode == CODE_FOR_nothing)
5697 /* Builtin not supported on this processor. */
5698 return 0;
5699
20e26713
AH
5700 /* If we got invalid arguments bail out before generating bad rtl. */
5701 if (arg0 == error_mark_node
5702 || arg1 == error_mark_node
5703 || arg2 == error_mark_node)
9a171fcd 5704 return const0_rtx;
20e26713 5705
774b5662
DE
5706 if (icode == CODE_FOR_altivec_vsldoi_4sf
5707 || icode == CODE_FOR_altivec_vsldoi_4si
5708 || icode == CODE_FOR_altivec_vsldoi_8hi
5709 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
5710 {
5711 /* Only allow 4-bit unsigned literals. */
b44140e7
AH
5712 if (TREE_CODE (arg2) != INTEGER_CST
5713 || TREE_INT_CST_LOW (arg2) & ~0xf)
5714 {
5715 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 5716 return const0_rtx;
b44140e7 5717 }
b44140e7
AH
5718 }
5719
c62f2db5 5720 if (target == 0
2212663f
DB
5721 || GET_MODE (target) != tmode
5722 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5723 target = gen_reg_rtx (tmode);
5724
5725 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5726 op0 = copy_to_mode_reg (mode0, op0);
5727 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5728 op1 = copy_to_mode_reg (mode1, op1);
5729 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
5730 op2 = copy_to_mode_reg (mode2, op2);
5731
5732 pat = GEN_FCN (icode) (target, op0, op1, op2);
5733 if (! pat)
5734 return 0;
5735 emit_insn (pat);
5736
5737 return target;
5738}
92898235 5739
3a9b8c7e 5740/* Expand the lvx builtins. */
0ac081f6 5741static rtx
a2369ed3 5742altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 5743{
0ac081f6
AH
5744 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5745 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 5746 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
5747 tree arg0;
5748 enum machine_mode tmode, mode0;
7c3abc73 5749 rtx pat, op0;
3a9b8c7e 5750 enum insn_code icode;
92898235 5751
0ac081f6
AH
5752 switch (fcode)
5753 {
f18c054f
DB
5754 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
5755 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 5756 break;
f18c054f
DB
5757 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
5758 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
5759 break;
5760 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
5761 icode = CODE_FOR_altivec_lvx_4si;
5762 break;
5763 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
5764 icode = CODE_FOR_altivec_lvx_4sf;
5765 break;
5766 default:
5767 *expandedp = false;
5768 return NULL_RTX;
5769 }
0ac081f6 5770
3a9b8c7e 5771 *expandedp = true;
f18c054f 5772
3a9b8c7e
AH
5773 arg0 = TREE_VALUE (arglist);
5774 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5775 tmode = insn_data[icode].operand[0].mode;
5776 mode0 = insn_data[icode].operand[1].mode;
f18c054f 5777
3a9b8c7e
AH
5778 if (target == 0
5779 || GET_MODE (target) != tmode
5780 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5781 target = gen_reg_rtx (tmode);
24408032 5782
3a9b8c7e
AH
5783 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5784 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 5785
3a9b8c7e
AH
5786 pat = GEN_FCN (icode) (target, op0);
5787 if (! pat)
5788 return 0;
5789 emit_insn (pat);
5790 return target;
5791}
f18c054f 5792
3a9b8c7e
AH
5793/* Expand the stvx builtins. */
5794static rtx
a2369ed3
DJ
5795altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5796 bool *expandedp)
3a9b8c7e
AH
5797{
5798 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5799 tree arglist = TREE_OPERAND (exp, 1);
5800 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5801 tree arg0, arg1;
5802 enum machine_mode mode0, mode1;
7c3abc73 5803 rtx pat, op0, op1;
3a9b8c7e 5804 enum insn_code icode;
f18c054f 5805
3a9b8c7e
AH
5806 switch (fcode)
5807 {
5808 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
5809 icode = CODE_FOR_altivec_stvx_16qi;
5810 break;
5811 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
5812 icode = CODE_FOR_altivec_stvx_8hi;
5813 break;
5814 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
5815 icode = CODE_FOR_altivec_stvx_4si;
5816 break;
5817 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
5818 icode = CODE_FOR_altivec_stvx_4sf;
5819 break;
5820 default:
5821 *expandedp = false;
5822 return NULL_RTX;
5823 }
24408032 5824
3a9b8c7e
AH
5825 arg0 = TREE_VALUE (arglist);
5826 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5827 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5828 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5829 mode0 = insn_data[icode].operand[0].mode;
5830 mode1 = insn_data[icode].operand[1].mode;
f18c054f 5831
3a9b8c7e
AH
5832 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5833 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
5834 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5835 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 5836
3a9b8c7e
AH
5837 pat = GEN_FCN (icode) (op0, op1);
5838 if (pat)
5839 emit_insn (pat);
f18c054f 5840
3a9b8c7e
AH
5841 *expandedp = true;
5842 return NULL_RTX;
5843}
f18c054f 5844
3a9b8c7e
AH
5845/* Expand the dst builtins. */
5846static rtx
a2369ed3
DJ
5847altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5848 bool *expandedp)
3a9b8c7e
AH
5849{
5850 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5851 tree arglist = TREE_OPERAND (exp, 1);
5852 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5853 tree arg0, arg1, arg2;
5854 enum machine_mode mode0, mode1, mode2;
7c3abc73 5855 rtx pat, op0, op1, op2;
3a9b8c7e 5856 struct builtin_description *d;
a3170dc6 5857 size_t i;
f18c054f 5858
3a9b8c7e 5859 *expandedp = false;
f18c054f 5860
3a9b8c7e
AH
5861 /* Handle DST variants. */
5862 d = (struct builtin_description *) bdesc_dst;
5863 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
5864 if (d->code == fcode)
5865 {
5866 arg0 = TREE_VALUE (arglist);
5867 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5868 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5869 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5870 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5871 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5872 mode0 = insn_data[d->icode].operand[0].mode;
5873 mode1 = insn_data[d->icode].operand[1].mode;
5874 mode2 = insn_data[d->icode].operand[2].mode;
24408032 5875
3a9b8c7e
AH
5876 /* Invalid arguments, bail out before generating bad rtl. */
5877 if (arg0 == error_mark_node
5878 || arg1 == error_mark_node
5879 || arg2 == error_mark_node)
5880 return const0_rtx;
f18c054f 5881
3a9b8c7e
AH
5882 if (TREE_CODE (arg2) != INTEGER_CST
5883 || TREE_INT_CST_LOW (arg2) & ~0x3)
5884 {
5885 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
5886 return const0_rtx;
5887 }
f18c054f 5888
3a9b8c7e 5889 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 5890 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
5891 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
5892 op1 = copy_to_mode_reg (mode1, op1);
24408032 5893
3a9b8c7e
AH
5894 pat = GEN_FCN (d->icode) (op0, op1, op2);
5895 if (pat != 0)
5896 emit_insn (pat);
f18c054f 5897
3a9b8c7e
AH
5898 *expandedp = true;
5899 return NULL_RTX;
5900 }
f18c054f 5901
3a9b8c7e
AH
5902 return NULL_RTX;
5903}
24408032 5904
3a9b8c7e
AH
5905/* Expand the builtin in EXP and store the result in TARGET. Store
5906 true in *EXPANDEDP if we found a builtin to expand. */
5907static rtx
a2369ed3 5908altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
5909{
5910 struct builtin_description *d;
5911 struct builtin_description_predicates *dp;
5912 size_t i;
5913 enum insn_code icode;
5914 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5915 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
5916 tree arg0;
5917 rtx op0, pat;
5918 enum machine_mode tmode, mode0;
3a9b8c7e 5919 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 5920
3a9b8c7e
AH
5921 target = altivec_expand_ld_builtin (exp, target, expandedp);
5922 if (*expandedp)
5923 return target;
0ac081f6 5924
3a9b8c7e
AH
5925 target = altivec_expand_st_builtin (exp, target, expandedp);
5926 if (*expandedp)
5927 return target;
5928
5929 target = altivec_expand_dst_builtin (exp, target, expandedp);
5930 if (*expandedp)
5931 return target;
5932
5933 *expandedp = true;
95385cbb 5934
3a9b8c7e
AH
5935 switch (fcode)
5936 {
6525c0e7
AH
5937 case ALTIVEC_BUILTIN_STVX:
5938 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
5939 case ALTIVEC_BUILTIN_STVEBX:
5940 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
5941 case ALTIVEC_BUILTIN_STVEHX:
5942 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
5943 case ALTIVEC_BUILTIN_STVEWX:
5944 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
5945 case ALTIVEC_BUILTIN_STVXL:
5946 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 5947
95385cbb
AH
5948 case ALTIVEC_BUILTIN_MFVSCR:
5949 icode = CODE_FOR_altivec_mfvscr;
5950 tmode = insn_data[icode].operand[0].mode;
5951
5952 if (target == 0
5953 || GET_MODE (target) != tmode
5954 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5955 target = gen_reg_rtx (tmode);
5956
5957 pat = GEN_FCN (icode) (target);
0ac081f6
AH
5958 if (! pat)
5959 return 0;
5960 emit_insn (pat);
95385cbb
AH
5961 return target;
5962
5963 case ALTIVEC_BUILTIN_MTVSCR:
5964 icode = CODE_FOR_altivec_mtvscr;
5965 arg0 = TREE_VALUE (arglist);
5966 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5967 mode0 = insn_data[icode].operand[0].mode;
5968
5969 /* If we got invalid arguments bail out before generating bad rtl. */
5970 if (arg0 == error_mark_node)
9a171fcd 5971 return const0_rtx;
95385cbb
AH
5972
5973 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5974 op0 = copy_to_mode_reg (mode0, op0);
5975
5976 pat = GEN_FCN (icode) (op0);
5977 if (pat)
5978 emit_insn (pat);
5979 return NULL_RTX;
3a9b8c7e 5980
95385cbb
AH
5981 case ALTIVEC_BUILTIN_DSSALL:
5982 emit_insn (gen_altivec_dssall ());
5983 return NULL_RTX;
5984
5985 case ALTIVEC_BUILTIN_DSS:
5986 icode = CODE_FOR_altivec_dss;
5987 arg0 = TREE_VALUE (arglist);
5988 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5989 mode0 = insn_data[icode].operand[0].mode;
5990
5991 /* If we got invalid arguments bail out before generating bad rtl. */
5992 if (arg0 == error_mark_node)
9a171fcd 5993 return const0_rtx;
95385cbb 5994
b44140e7
AH
5995 if (TREE_CODE (arg0) != INTEGER_CST
5996 || TREE_INT_CST_LOW (arg0) & ~0x3)
5997 {
5998 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 5999 return const0_rtx;
b44140e7
AH
6000 }
6001
95385cbb
AH
6002 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6003 op0 = copy_to_mode_reg (mode0, op0);
6004
6005 emit_insn (gen_altivec_dss (op0));
0ac081f6
AH
6006 return NULL_RTX;
6007 }
24408032 6008
100c4561
AH
6009 /* Expand abs* operations. */
6010 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6011 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6012 if (d->code == fcode)
6013 return altivec_expand_abs_builtin (d->icode, arglist, target);
6014
ae4b4a02
AH
6015 /* Expand the AltiVec predicates. */
6016 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6017 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
6018 if (dp->code == fcode)
6019 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
6020
6525c0e7
AH
6021 /* LV* are funky. We initialized them differently. */
6022 switch (fcode)
6023 {
6024 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6025 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
6026 arglist, target);
6027 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6028 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
92898235 6029 arglist, target);
6525c0e7 6030 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6031 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
92898235 6032 arglist, target);
6525c0e7 6033 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6034 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
92898235 6035 arglist, target);
6525c0e7 6036 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6037 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
92898235 6038 arglist, target);
6525c0e7 6039 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6040 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
92898235 6041 arglist, target);
6525c0e7 6042 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6043 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
92898235 6044 arglist, target);
6525c0e7
AH
6045 default:
6046 break;
6047 /* Fall through. */
6048 }
95385cbb 6049
92898235 6050 *expandedp = false;
0ac081f6
AH
6051 return NULL_RTX;
6052}
6053
a3170dc6
AH
6054/* Binops that need to be initialized manually, but can be expanded
6055 automagically by rs6000_expand_binop_builtin. */
6056static struct builtin_description bdesc_2arg_spe[] =
6057{
6058 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6059 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6060 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6061 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6062 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6063 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6064 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6065 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6066 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6067 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6068 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6069 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6070 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6071 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6072 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6073 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6074 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6075 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6076 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6077 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6078 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6079 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6080};
6081
6082/* Expand the builtin in EXP and store the result in TARGET. Store
6083 true in *EXPANDEDP if we found a builtin to expand.
6084
6085 This expands the SPE builtins that are not simple unary and binary
6086 operations. */
6087static rtx
a2369ed3 6088spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6089{
6090 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6091 tree arglist = TREE_OPERAND (exp, 1);
6092 tree arg1, arg0;
6093 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6094 enum insn_code icode;
6095 enum machine_mode tmode, mode0;
6096 rtx pat, op0;
6097 struct builtin_description *d;
6098 size_t i;
6099
6100 *expandedp = true;
6101
6102 /* Syntax check for a 5-bit unsigned immediate. */
6103 switch (fcode)
6104 {
6105 case SPE_BUILTIN_EVSTDD:
6106 case SPE_BUILTIN_EVSTDH:
6107 case SPE_BUILTIN_EVSTDW:
6108 case SPE_BUILTIN_EVSTWHE:
6109 case SPE_BUILTIN_EVSTWHO:
6110 case SPE_BUILTIN_EVSTWWE:
6111 case SPE_BUILTIN_EVSTWWO:
6112 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6113 if (TREE_CODE (arg1) != INTEGER_CST
6114 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6115 {
6116 error ("argument 2 must be a 5-bit unsigned literal");
6117 return const0_rtx;
6118 }
6119 break;
6120 default:
6121 break;
6122 }
6123
00332c9f
AH
6124 /* The evsplat*i instructions are not quite generic. */
6125 switch (fcode)
6126 {
6127 case SPE_BUILTIN_EVSPLATFI:
6128 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6129 arglist, target);
6130 case SPE_BUILTIN_EVSPLATI:
6131 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
6132 arglist, target);
6133 default:
6134 break;
6135 }
6136
a3170dc6
AH
6137 d = (struct builtin_description *) bdesc_2arg_spe;
6138 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
6139 if (d->code == fcode)
6140 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6141
6142 d = (struct builtin_description *) bdesc_spe_predicates;
6143 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
6144 if (d->code == fcode)
6145 return spe_expand_predicate_builtin (d->icode, arglist, target);
6146
6147 d = (struct builtin_description *) bdesc_spe_evsel;
6148 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
6149 if (d->code == fcode)
6150 return spe_expand_evsel_builtin (d->icode, arglist, target);
6151
6152 switch (fcode)
6153 {
6154 case SPE_BUILTIN_EVSTDDX:
6155 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
6156 case SPE_BUILTIN_EVSTDHX:
6157 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
6158 case SPE_BUILTIN_EVSTDWX:
6159 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
6160 case SPE_BUILTIN_EVSTWHEX:
6161 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
6162 case SPE_BUILTIN_EVSTWHOX:
6163 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
6164 case SPE_BUILTIN_EVSTWWEX:
6165 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
6166 case SPE_BUILTIN_EVSTWWOX:
6167 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
6168 case SPE_BUILTIN_EVSTDD:
6169 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
6170 case SPE_BUILTIN_EVSTDH:
6171 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
6172 case SPE_BUILTIN_EVSTDW:
6173 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
6174 case SPE_BUILTIN_EVSTWHE:
6175 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
6176 case SPE_BUILTIN_EVSTWHO:
6177 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
6178 case SPE_BUILTIN_EVSTWWE:
6179 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
6180 case SPE_BUILTIN_EVSTWWO:
6181 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
6182 case SPE_BUILTIN_MFSPEFSCR:
6183 icode = CODE_FOR_spe_mfspefscr;
6184 tmode = insn_data[icode].operand[0].mode;
6185
6186 if (target == 0
6187 || GET_MODE (target) != tmode
6188 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6189 target = gen_reg_rtx (tmode);
6190
6191 pat = GEN_FCN (icode) (target);
6192 if (! pat)
6193 return 0;
6194 emit_insn (pat);
6195 return target;
6196 case SPE_BUILTIN_MTSPEFSCR:
6197 icode = CODE_FOR_spe_mtspefscr;
6198 arg0 = TREE_VALUE (arglist);
6199 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6200 mode0 = insn_data[icode].operand[0].mode;
6201
6202 if (arg0 == error_mark_node)
6203 return const0_rtx;
6204
6205 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6206 op0 = copy_to_mode_reg (mode0, op0);
6207
6208 pat = GEN_FCN (icode) (op0);
6209 if (pat)
6210 emit_insn (pat);
6211 return NULL_RTX;
6212 default:
6213 break;
6214 }
6215
6216 *expandedp = false;
6217 return NULL_RTX;
6218}
6219
6220static rtx
a2369ed3 6221spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6222{
6223 rtx pat, scratch, tmp;
6224 tree form = TREE_VALUE (arglist);
6225 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6226 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6227 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6228 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6229 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6230 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6231 int form_int;
6232 enum rtx_code code;
6233
6234 if (TREE_CODE (form) != INTEGER_CST)
6235 {
6236 error ("argument 1 of __builtin_spe_predicate must be a constant");
6237 return const0_rtx;
6238 }
6239 else
6240 form_int = TREE_INT_CST_LOW (form);
6241
6242 if (mode0 != mode1)
6243 abort ();
6244
6245 if (arg0 == error_mark_node || arg1 == error_mark_node)
6246 return const0_rtx;
6247
6248 if (target == 0
6249 || GET_MODE (target) != SImode
6250 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
6251 target = gen_reg_rtx (SImode);
6252
6253 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6254 op0 = copy_to_mode_reg (mode0, op0);
6255 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6256 op1 = copy_to_mode_reg (mode1, op1);
6257
6258 scratch = gen_reg_rtx (CCmode);
6259
6260 pat = GEN_FCN (icode) (scratch, op0, op1);
6261 if (! pat)
6262 return const0_rtx;
6263 emit_insn (pat);
6264
6265 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
6266 _lower_. We use one compare, but look in different bits of the
6267 CR for each variant.
6268
6269 There are 2 elements in each SPE simd type (upper/lower). The CR
6270 bits are set as follows:
6271
6272 BIT0 | BIT 1 | BIT 2 | BIT 3
6273 U | L | (U | L) | (U & L)
6274
6275 So, for an "all" relationship, BIT 3 would be set.
6276 For an "any" relationship, BIT 2 would be set. Etc.
6277
6278 Following traditional nomenclature, these bits map to:
6279
6280 BIT0 | BIT 1 | BIT 2 | BIT 3
6281 LT | GT | EQ | OV
6282
6283 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
6284 */
6285
6286 switch (form_int)
6287 {
6288 /* All variant. OV bit. */
6289 case 0:
6290 /* We need to get to the OV bit, which is the ORDERED bit. We
6291 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
6292 that's ugly and will trigger a validate_condition_mode abort.
6293 So let's just use another pattern. */
6294 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
6295 return target;
6296 /* Any variant. EQ bit. */
6297 case 1:
6298 code = EQ;
6299 break;
6300 /* Upper variant. LT bit. */
6301 case 2:
6302 code = LT;
6303 break;
6304 /* Lower variant. GT bit. */
6305 case 3:
6306 code = GT;
6307 break;
6308 default:
6309 error ("argument 1 of __builtin_spe_predicate is out of range");
6310 return const0_rtx;
6311 }
6312
6313 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
6314 emit_move_insn (target, tmp);
6315
6316 return target;
6317}
6318
6319/* The evsel builtins look like this:
6320
6321 e = __builtin_spe_evsel_OP (a, b, c, d);
6322
6323 and work like this:
6324
6325 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
6326 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
6327*/
6328
6329static rtx
a2369ed3 6330spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6331{
6332 rtx pat, scratch;
6333 tree arg0 = TREE_VALUE (arglist);
6334 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6335 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6336 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
6337 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6338 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6339 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6340 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
6341 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6342 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6343
6344 if (mode0 != mode1)
6345 abort ();
6346
6347 if (arg0 == error_mark_node || arg1 == error_mark_node
6348 || arg2 == error_mark_node || arg3 == error_mark_node)
6349 return const0_rtx;
6350
6351 if (target == 0
6352 || GET_MODE (target) != mode0
6353 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
6354 target = gen_reg_rtx (mode0);
6355
6356 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6357 op0 = copy_to_mode_reg (mode0, op0);
6358 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6359 op1 = copy_to_mode_reg (mode0, op1);
6360 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6361 op2 = copy_to_mode_reg (mode0, op2);
6362 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
6363 op3 = copy_to_mode_reg (mode0, op3);
6364
6365 /* Generate the compare. */
6366 scratch = gen_reg_rtx (CCmode);
6367 pat = GEN_FCN (icode) (scratch, op0, op1);
6368 if (! pat)
6369 return const0_rtx;
6370 emit_insn (pat);
6371
6372 if (mode0 == V2SImode)
6373 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
6374 else
6375 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
6376
6377 return target;
6378}
6379
0ac081f6
AH
6380/* Expand an expression EXP that calls a built-in function,
6381 with result going to TARGET if that's convenient
6382 (and in mode MODE if that's convenient).
6383 SUBTARGET may be used as the target for computing one of EXP's operands.
6384 IGNORE is nonzero if the value is to be ignored. */
6385
6386static rtx
a2369ed3
DJ
6387rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
6388 enum machine_mode mode ATTRIBUTE_UNUSED,
6389 int ignore ATTRIBUTE_UNUSED)
0ac081f6 6390{
92898235
AH
6391 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6392 tree arglist = TREE_OPERAND (exp, 1);
6393 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6394 struct builtin_description *d;
6395 size_t i;
6396 rtx ret;
6397 bool success;
6398
0ac081f6 6399 if (TARGET_ALTIVEC)
92898235
AH
6400 {
6401 ret = altivec_expand_builtin (exp, target, &success);
6402
a3170dc6
AH
6403 if (success)
6404 return ret;
6405 }
6406 if (TARGET_SPE)
6407 {
6408 ret = spe_expand_builtin (exp, target, &success);
6409
92898235
AH
6410 if (success)
6411 return ret;
6412 }
6413
0559cc77
DE
6414 if (TARGET_ALTIVEC || TARGET_SPE)
6415 {
6416 /* Handle simple unary operations. */
6417 d = (struct builtin_description *) bdesc_1arg;
6418 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
6419 if (d->code == fcode)
6420 return rs6000_expand_unop_builtin (d->icode, arglist, target);
6421
6422 /* Handle simple binary operations. */
6423 d = (struct builtin_description *) bdesc_2arg;
6424 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
6425 if (d->code == fcode)
6426 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6427
6428 /* Handle simple ternary operations. */
6429 d = (struct builtin_description *) bdesc_3arg;
6430 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
6431 if (d->code == fcode)
6432 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
6433 }
0ac081f6
AH
6434
6435 abort ();
92898235 6436 return NULL_RTX;
0ac081f6
AH
6437}
6438
6439static void
863d938c 6440rs6000_init_builtins (void)
0ac081f6 6441{
3fdaa45a
AH
6442 opaque_V2SI_type_node = copy_node (V2SI_type_node);
6443 opaque_V2SF_type_node = copy_node (V2SF_type_node);
6035d635 6444 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 6445
a3170dc6 6446 if (TARGET_SPE)
3fdaa45a 6447 spe_init_builtins ();
0ac081f6
AH
6448 if (TARGET_ALTIVEC)
6449 altivec_init_builtins ();
0559cc77
DE
6450 if (TARGET_ALTIVEC || TARGET_SPE)
6451 rs6000_common_init_builtins ();
0ac081f6
AH
6452}
6453
a3170dc6
AH
6454/* Search through a set of builtins and enable the mask bits.
6455 DESC is an array of builtins.
b6d08ca1 6456 SIZE is the total number of builtins.
a3170dc6
AH
6457 START is the builtin enum at which to start.
6458 END is the builtin enum at which to end. */
0ac081f6 6459static void
a2369ed3
DJ
6460enable_mask_for_builtins (struct builtin_description *desc, int size,
6461 enum rs6000_builtins start,
6462 enum rs6000_builtins end)
a3170dc6
AH
6463{
6464 int i;
6465
6466 for (i = 0; i < size; ++i)
6467 if (desc[i].code == start)
6468 break;
6469
6470 if (i == size)
6471 return;
6472
6473 for (; i < size; ++i)
6474 {
6475 /* Flip all the bits on. */
6476 desc[i].mask = target_flags;
6477 if (desc[i].code == end)
6478 break;
6479 }
6480}
6481
6482static void
863d938c 6483spe_init_builtins (void)
0ac081f6 6484{
a3170dc6
AH
6485 tree endlink = void_list_node;
6486 tree puint_type_node = build_pointer_type (unsigned_type_node);
6487 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 6488 struct builtin_description *d;
0ac081f6
AH
6489 size_t i;
6490
a3170dc6
AH
6491 tree v2si_ftype_4_v2si
6492 = build_function_type
3fdaa45a
AH
6493 (opaque_V2SI_type_node,
6494 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6495 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6496 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6497 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6498 endlink)))));
6499
6500 tree v2sf_ftype_4_v2sf
6501 = build_function_type
3fdaa45a
AH
6502 (opaque_V2SF_type_node,
6503 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6504 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6505 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6506 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6507 endlink)))));
6508
6509 tree int_ftype_int_v2si_v2si
6510 = build_function_type
6511 (integer_type_node,
6512 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6513 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6514 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6515 endlink))));
6516
6517 tree int_ftype_int_v2sf_v2sf
6518 = build_function_type
6519 (integer_type_node,
6520 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6521 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6522 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6523 endlink))));
6524
6525 tree void_ftype_v2si_puint_int
6526 = build_function_type (void_type_node,
3fdaa45a 6527 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6528 tree_cons (NULL_TREE, puint_type_node,
6529 tree_cons (NULL_TREE,
6530 integer_type_node,
6531 endlink))));
6532
6533 tree void_ftype_v2si_puint_char
6534 = build_function_type (void_type_node,
3fdaa45a 6535 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6536 tree_cons (NULL_TREE, puint_type_node,
6537 tree_cons (NULL_TREE,
6538 char_type_node,
6539 endlink))));
6540
6541 tree void_ftype_v2si_pv2si_int
6542 = build_function_type (void_type_node,
3fdaa45a 6543 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6544 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6545 tree_cons (NULL_TREE,
6546 integer_type_node,
6547 endlink))));
6548
6549 tree void_ftype_v2si_pv2si_char
6550 = build_function_type (void_type_node,
3fdaa45a 6551 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6552 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6553 tree_cons (NULL_TREE,
6554 char_type_node,
6555 endlink))));
6556
6557 tree void_ftype_int
6558 = build_function_type (void_type_node,
6559 tree_cons (NULL_TREE, integer_type_node, endlink));
6560
6561 tree int_ftype_void
36e8d515 6562 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
6563
6564 tree v2si_ftype_pv2si_int
3fdaa45a 6565 = build_function_type (opaque_V2SI_type_node,
6035d635 6566 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6567 tree_cons (NULL_TREE, integer_type_node,
6568 endlink)));
6569
6570 tree v2si_ftype_puint_int
3fdaa45a 6571 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6572 tree_cons (NULL_TREE, puint_type_node,
6573 tree_cons (NULL_TREE, integer_type_node,
6574 endlink)));
6575
6576 tree v2si_ftype_pushort_int
3fdaa45a 6577 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6578 tree_cons (NULL_TREE, pushort_type_node,
6579 tree_cons (NULL_TREE, integer_type_node,
6580 endlink)));
6581
00332c9f
AH
6582 tree v2si_ftype_signed_char
6583 = build_function_type (opaque_V2SI_type_node,
6584 tree_cons (NULL_TREE, signed_char_type_node,
6585 endlink));
6586
a3170dc6
AH
6587 /* The initialization of the simple binary and unary builtins is
6588 done in rs6000_common_init_builtins, but we have to enable the
6589 mask bits here manually because we have run out of `target_flags'
6590 bits. We really need to redesign this mask business. */
6591
6592 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
6593 ARRAY_SIZE (bdesc_2arg),
6594 SPE_BUILTIN_EVADDW,
6595 SPE_BUILTIN_EVXOR);
6596 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
6597 ARRAY_SIZE (bdesc_1arg),
6598 SPE_BUILTIN_EVABS,
6599 SPE_BUILTIN_EVSUBFUSIAAW);
6600 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
6601 ARRAY_SIZE (bdesc_spe_predicates),
6602 SPE_BUILTIN_EVCMPEQ,
6603 SPE_BUILTIN_EVFSTSTLT);
6604 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
6605 ARRAY_SIZE (bdesc_spe_evsel),
6606 SPE_BUILTIN_EVSEL_CMPGTS,
6607 SPE_BUILTIN_EVSEL_FSTSTEQ);
6608
36252949
AH
6609 (*lang_hooks.decls.pushdecl)
6610 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
6611 opaque_V2SI_type_node));
6612
a3170dc6
AH
6613 /* Initialize irregular SPE builtins. */
6614
6615 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
6616 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
6617 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
6618 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
6619 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
6620 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
6621 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
6622 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
6623 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
6624 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
6625 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
6626 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
6627 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
6628 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
6629 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
6630 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
6631 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
6632 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
6633
6634 /* Loads. */
6635 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
6636 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
6637 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
6638 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
6639 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
6640 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
6641 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
6642 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
6643 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
6644 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
6645 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
6646 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
6647 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
6648 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
6649 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
6650 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
6651 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
6652 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
6653 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
6654 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
6655 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
6656 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
6657
6658 /* Predicates. */
6659 d = (struct builtin_description *) bdesc_spe_predicates;
6660 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
6661 {
6662 tree type;
6663
6664 switch (insn_data[d->icode].operand[1].mode)
6665 {
6666 case V2SImode:
6667 type = int_ftype_int_v2si_v2si;
6668 break;
6669 case V2SFmode:
6670 type = int_ftype_int_v2sf_v2sf;
6671 break;
6672 default:
6673 abort ();
6674 }
6675
6676 def_builtin (d->mask, d->name, type, d->code);
6677 }
6678
6679 /* Evsel predicates. */
6680 d = (struct builtin_description *) bdesc_spe_evsel;
6681 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
6682 {
6683 tree type;
6684
6685 switch (insn_data[d->icode].operand[1].mode)
6686 {
6687 case V2SImode:
6688 type = v2si_ftype_4_v2si;
6689 break;
6690 case V2SFmode:
6691 type = v2sf_ftype_4_v2sf;
6692 break;
6693 default:
6694 abort ();
6695 }
6696
6697 def_builtin (d->mask, d->name, type, d->code);
6698 }
6699}
6700
6701static void
863d938c 6702altivec_init_builtins (void)
a3170dc6
AH
6703{
6704 struct builtin_description *d;
6705 struct builtin_description_predicates *dp;
6706 size_t i;
6707 tree pfloat_type_node = build_pointer_type (float_type_node);
6708 tree pint_type_node = build_pointer_type (integer_type_node);
6709 tree pshort_type_node = build_pointer_type (short_integer_type_node);
6710 tree pchar_type_node = build_pointer_type (char_type_node);
6711
6712 tree pvoid_type_node = build_pointer_type (void_type_node);
6713
0dbc3651
ZW
6714 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
6715 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
6716 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
6717 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
6718
6719 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
6720
a3170dc6
AH
6721 tree int_ftype_int_v4si_v4si
6722 = build_function_type_list (integer_type_node,
6723 integer_type_node, V4SI_type_node,
6724 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6725 tree v4sf_ftype_pcfloat
6726 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 6727 tree void_ftype_pfloat_v4sf
b4de2f7d 6728 = build_function_type_list (void_type_node,
a3170dc6 6729 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
6730 tree v4si_ftype_pcint
6731 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
6732 tree void_ftype_pint_v4si
b4de2f7d
AH
6733 = build_function_type_list (void_type_node,
6734 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6735 tree v8hi_ftype_pcshort
6736 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 6737 tree void_ftype_pshort_v8hi
b4de2f7d
AH
6738 = build_function_type_list (void_type_node,
6739 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
6740 tree v16qi_ftype_pcchar
6741 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 6742 tree void_ftype_pchar_v16qi
b4de2f7d
AH
6743 = build_function_type_list (void_type_node,
6744 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 6745 tree void_ftype_v4si
b4de2f7d 6746 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6747 tree v8hi_ftype_void
6748 = build_function_type (V8HI_type_node, void_list_node);
6749 tree void_ftype_void
6750 = build_function_type (void_type_node, void_list_node);
6751 tree void_ftype_qi
6752 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651 6753
b4a62fa0 6754 tree v16qi_ftype_long_pcvoid
a3170dc6 6755 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
6756 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6757 tree v8hi_ftype_long_pcvoid
a3170dc6 6758 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
6759 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6760 tree v4si_ftype_long_pcvoid
a3170dc6 6761 = build_function_type_list (V4SI_type_node,
b4a62fa0 6762 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 6763
b4a62fa0 6764 tree void_ftype_v4si_long_pvoid
b4de2f7d 6765 = build_function_type_list (void_type_node,
b4a62fa0 6766 V4SI_type_node, long_integer_type_node,
b4de2f7d 6767 pvoid_type_node, NULL_TREE);
b4a62fa0 6768 tree void_ftype_v16qi_long_pvoid
b4de2f7d 6769 = build_function_type_list (void_type_node,
b4a62fa0 6770 V16QI_type_node, long_integer_type_node,
b4de2f7d 6771 pvoid_type_node, NULL_TREE);
b4a62fa0 6772 tree void_ftype_v8hi_long_pvoid
b4de2f7d 6773 = build_function_type_list (void_type_node,
b4a62fa0 6774 V8HI_type_node, long_integer_type_node,
b4de2f7d 6775 pvoid_type_node, NULL_TREE);
a3170dc6
AH
6776 tree int_ftype_int_v8hi_v8hi
6777 = build_function_type_list (integer_type_node,
6778 integer_type_node, V8HI_type_node,
6779 V8HI_type_node, NULL_TREE);
6780 tree int_ftype_int_v16qi_v16qi
6781 = build_function_type_list (integer_type_node,
6782 integer_type_node, V16QI_type_node,
6783 V16QI_type_node, NULL_TREE);
6784 tree int_ftype_int_v4sf_v4sf
6785 = build_function_type_list (integer_type_node,
6786 integer_type_node, V4SF_type_node,
6787 V4SF_type_node, NULL_TREE);
6788 tree v4si_ftype_v4si
6789 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
6790 tree v8hi_ftype_v8hi
6791 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
6792 tree v16qi_ftype_v16qi
6793 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
6794 tree v4sf_ftype_v4sf
6795 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
0dbc3651 6796 tree void_ftype_pcvoid_int_char
a3170dc6 6797 = build_function_type_list (void_type_node,
0dbc3651 6798 pcvoid_type_node, integer_type_node,
a3170dc6 6799 char_type_node, NULL_TREE);
0dbc3651
ZW
6800
6801 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
6802 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
6803 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
6804 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
6805 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
6806 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
6807 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
6808 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
6809 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
6810 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
6811 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
6812 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
6813 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
6814 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
6815 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
6816 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
6817 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
6818 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
6819 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
6820 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
6821 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
6822 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
6823 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
6824 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
6825 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
6826 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
6827 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
6828 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
6829 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
6830 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
6831 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
6832 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6
AH
6833
6834 /* Add the DST variants. */
6835 d = (struct builtin_description *) bdesc_dst;
6836 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
0dbc3651 6837 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code);
a3170dc6
AH
6838
6839 /* Initialize the predicates. */
6840 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
6841 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
6842 {
6843 enum machine_mode mode1;
6844 tree type;
6845
6846 mode1 = insn_data[dp->icode].operand[1].mode;
6847
6848 switch (mode1)
6849 {
6850 case V4SImode:
6851 type = int_ftype_int_v4si_v4si;
6852 break;
6853 case V8HImode:
6854 type = int_ftype_int_v8hi_v8hi;
6855 break;
6856 case V16QImode:
6857 type = int_ftype_int_v16qi_v16qi;
6858 break;
6859 case V4SFmode:
6860 type = int_ftype_int_v4sf_v4sf;
6861 break;
6862 default:
6863 abort ();
6864 }
6865
6866 def_builtin (dp->mask, dp->name, type, dp->code);
6867 }
6868
6869 /* Initialize the abs* operators. */
6870 d = (struct builtin_description *) bdesc_abs;
6871 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
6872 {
6873 enum machine_mode mode0;
6874 tree type;
6875
6876 mode0 = insn_data[d->icode].operand[0].mode;
6877
6878 switch (mode0)
6879 {
6880 case V4SImode:
6881 type = v4si_ftype_v4si;
6882 break;
6883 case V8HImode:
6884 type = v8hi_ftype_v8hi;
6885 break;
6886 case V16QImode:
6887 type = v16qi_ftype_v16qi;
6888 break;
6889 case V4SFmode:
6890 type = v4sf_ftype_v4sf;
6891 break;
6892 default:
6893 abort ();
6894 }
6895
6896 def_builtin (d->mask, d->name, type, d->code);
6897 }
6898}
6899
6900static void
863d938c 6901rs6000_common_init_builtins (void)
a3170dc6
AH
6902{
6903 struct builtin_description *d;
6904 size_t i;
6905
6906 tree v4sf_ftype_v4sf_v4sf_v16qi
6907 = build_function_type_list (V4SF_type_node,
6908 V4SF_type_node, V4SF_type_node,
6909 V16QI_type_node, NULL_TREE);
6910 tree v4si_ftype_v4si_v4si_v16qi
6911 = build_function_type_list (V4SI_type_node,
6912 V4SI_type_node, V4SI_type_node,
6913 V16QI_type_node, NULL_TREE);
6914 tree v8hi_ftype_v8hi_v8hi_v16qi
6915 = build_function_type_list (V8HI_type_node,
6916 V8HI_type_node, V8HI_type_node,
6917 V16QI_type_node, NULL_TREE);
6918 tree v16qi_ftype_v16qi_v16qi_v16qi
6919 = build_function_type_list (V16QI_type_node,
6920 V16QI_type_node, V16QI_type_node,
6921 V16QI_type_node, NULL_TREE);
6922 tree v4si_ftype_char
6923 = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE);
6924 tree v8hi_ftype_char
6925 = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE);
6926 tree v16qi_ftype_char
6927 = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE);
6928 tree v8hi_ftype_v16qi
6929 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
6930 tree v4sf_ftype_v4sf
6931 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
6932
6933 tree v2si_ftype_v2si_v2si
2abe3e28
AH
6934 = build_function_type_list (opaque_V2SI_type_node,
6935 opaque_V2SI_type_node,
6936 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6937
6938 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
6939 = build_function_type_list (opaque_V2SF_type_node,
6940 opaque_V2SF_type_node,
6941 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6942
6943 tree v2si_ftype_int_int
2abe3e28 6944 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6945 integer_type_node, integer_type_node,
6946 NULL_TREE);
6947
6948 tree v2si_ftype_v2si
2abe3e28
AH
6949 = build_function_type_list (opaque_V2SI_type_node,
6950 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6951
6952 tree v2sf_ftype_v2sf
2abe3e28
AH
6953 = build_function_type_list (opaque_V2SF_type_node,
6954 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6955
6956 tree v2sf_ftype_v2si
2abe3e28
AH
6957 = build_function_type_list (opaque_V2SF_type_node,
6958 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6959
6960 tree v2si_ftype_v2sf
2abe3e28
AH
6961 = build_function_type_list (opaque_V2SI_type_node,
6962 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6963
6964 tree v2si_ftype_v2si_char
2abe3e28
AH
6965 = build_function_type_list (opaque_V2SI_type_node,
6966 opaque_V2SI_type_node,
6967 char_type_node, NULL_TREE);
a3170dc6
AH
6968
6969 tree v2si_ftype_int_char
2abe3e28 6970 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6971 integer_type_node, char_type_node, NULL_TREE);
6972
6973 tree v2si_ftype_char
2abe3e28
AH
6974 = build_function_type_list (opaque_V2SI_type_node,
6975 char_type_node, NULL_TREE);
a3170dc6
AH
6976
6977 tree int_ftype_int_int
6978 = build_function_type_list (integer_type_node,
6979 integer_type_node, integer_type_node,
6980 NULL_TREE);
95385cbb 6981
0ac081f6 6982 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
6983 = build_function_type_list (V4SI_type_node,
6984 V4SI_type_node, V4SI_type_node, NULL_TREE);
617e0e1d 6985 tree v4sf_ftype_v4si_char
b4de2f7d
AH
6986 = build_function_type_list (V4SF_type_node,
6987 V4SI_type_node, char_type_node, NULL_TREE);
617e0e1d 6988 tree v4si_ftype_v4sf_char
b4de2f7d
AH
6989 = build_function_type_list (V4SI_type_node,
6990 V4SF_type_node, char_type_node, NULL_TREE);
2212663f 6991 tree v4si_ftype_v4si_char
b4de2f7d
AH
6992 = build_function_type_list (V4SI_type_node,
6993 V4SI_type_node, char_type_node, NULL_TREE);
2212663f 6994 tree v8hi_ftype_v8hi_char
b4de2f7d
AH
6995 = build_function_type_list (V8HI_type_node,
6996 V8HI_type_node, char_type_node, NULL_TREE);
2212663f 6997 tree v16qi_ftype_v16qi_char
b4de2f7d
AH
6998 = build_function_type_list (V16QI_type_node,
6999 V16QI_type_node, char_type_node, NULL_TREE);
24408032 7000 tree v16qi_ftype_v16qi_v16qi_char
b4de2f7d
AH
7001 = build_function_type_list (V16QI_type_node,
7002 V16QI_type_node, V16QI_type_node,
7003 char_type_node, NULL_TREE);
24408032 7004 tree v8hi_ftype_v8hi_v8hi_char
b4de2f7d
AH
7005 = build_function_type_list (V8HI_type_node,
7006 V8HI_type_node, V8HI_type_node,
7007 char_type_node, NULL_TREE);
24408032 7008 tree v4si_ftype_v4si_v4si_char
b4de2f7d
AH
7009 = build_function_type_list (V4SI_type_node,
7010 V4SI_type_node, V4SI_type_node,
7011 char_type_node, NULL_TREE);
24408032 7012 tree v4sf_ftype_v4sf_v4sf_char
b4de2f7d
AH
7013 = build_function_type_list (V4SF_type_node,
7014 V4SF_type_node, V4SF_type_node,
7015 char_type_node, NULL_TREE);
0ac081f6 7016 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
7017 = build_function_type_list (V4SF_type_node,
7018 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 7019 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
7020 = build_function_type_list (V4SF_type_node,
7021 V4SF_type_node, V4SF_type_node,
7022 V4SI_type_node, NULL_TREE);
2212663f 7023 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
7024 = build_function_type_list (V4SF_type_node,
7025 V4SF_type_node, V4SF_type_node,
7026 V4SF_type_node, NULL_TREE);
617e0e1d 7027 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
7028 = build_function_type_list (V4SI_type_node,
7029 V4SI_type_node, V4SI_type_node,
7030 V4SI_type_node, NULL_TREE);
0ac081f6 7031 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
7032 = build_function_type_list (V8HI_type_node,
7033 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 7034 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
7035 = build_function_type_list (V8HI_type_node,
7036 V8HI_type_node, V8HI_type_node,
7037 V8HI_type_node, NULL_TREE);
2212663f 7038 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
7039 = build_function_type_list (V4SI_type_node,
7040 V8HI_type_node, V8HI_type_node,
7041 V4SI_type_node, NULL_TREE);
2212663f 7042 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
7043 = build_function_type_list (V4SI_type_node,
7044 V16QI_type_node, V16QI_type_node,
7045 V4SI_type_node, NULL_TREE);
0ac081f6 7046 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
7047 = build_function_type_list (V16QI_type_node,
7048 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7049 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
7050 = build_function_type_list (V4SI_type_node,
7051 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 7052 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
7053 = build_function_type_list (V8HI_type_node,
7054 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7055 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
7056 = build_function_type_list (V4SI_type_node,
7057 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7058 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
7059 = build_function_type_list (V8HI_type_node,
7060 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 7061 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
7062 = build_function_type_list (V16QI_type_node,
7063 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7064 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
7065 = build_function_type_list (V4SI_type_node,
7066 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 7067 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
7068 = build_function_type_list (V4SI_type_node,
7069 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7070 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
7071 = build_function_type_list (V4SI_type_node,
7072 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7073 tree v4si_ftype_v8hi
7074 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
7075 tree int_ftype_v4si_v4si
7076 = build_function_type_list (integer_type_node,
7077 V4SI_type_node, V4SI_type_node, NULL_TREE);
7078 tree int_ftype_v4sf_v4sf
7079 = build_function_type_list (integer_type_node,
7080 V4SF_type_node, V4SF_type_node, NULL_TREE);
7081 tree int_ftype_v16qi_v16qi
7082 = build_function_type_list (integer_type_node,
7083 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7084 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
7085 = build_function_type_list (integer_type_node,
7086 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7087
6f317ef3 7088 /* Add the simple ternary operators. */
2212663f 7089 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 7090 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
7091 {
7092
7093 enum machine_mode mode0, mode1, mode2, mode3;
7094 tree type;
7095
0559cc77 7096 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7097 continue;
7098
7099 mode0 = insn_data[d->icode].operand[0].mode;
7100 mode1 = insn_data[d->icode].operand[1].mode;
7101 mode2 = insn_data[d->icode].operand[2].mode;
7102 mode3 = insn_data[d->icode].operand[3].mode;
7103
7104 /* When all four are of the same mode. */
7105 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
7106 {
7107 switch (mode0)
7108 {
617e0e1d
DB
7109 case V4SImode:
7110 type = v4si_ftype_v4si_v4si_v4si;
7111 break;
2212663f
DB
7112 case V4SFmode:
7113 type = v4sf_ftype_v4sf_v4sf_v4sf;
7114 break;
7115 case V8HImode:
7116 type = v8hi_ftype_v8hi_v8hi_v8hi;
7117 break;
7118 case V16QImode:
7119 type = v16qi_ftype_v16qi_v16qi_v16qi;
7120 break;
7121 default:
7122 abort();
7123 }
7124 }
7125 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
7126 {
7127 switch (mode0)
7128 {
7129 case V4SImode:
7130 type = v4si_ftype_v4si_v4si_v16qi;
7131 break;
7132 case V4SFmode:
7133 type = v4sf_ftype_v4sf_v4sf_v16qi;
7134 break;
7135 case V8HImode:
7136 type = v8hi_ftype_v8hi_v8hi_v16qi;
7137 break;
7138 case V16QImode:
7139 type = v16qi_ftype_v16qi_v16qi_v16qi;
7140 break;
7141 default:
7142 abort();
7143 }
7144 }
7145 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
7146 && mode3 == V4SImode)
24408032 7147 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
7148 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
7149 && mode3 == V4SImode)
24408032 7150 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
7151 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
7152 && mode3 == V4SImode)
24408032
AH
7153 type = v4sf_ftype_v4sf_v4sf_v4si;
7154
7155 /* vchar, vchar, vchar, 4 bit literal. */
7156 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
7157 && mode3 == QImode)
7158 type = v16qi_ftype_v16qi_v16qi_char;
7159
7160 /* vshort, vshort, vshort, 4 bit literal. */
7161 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
7162 && mode3 == QImode)
7163 type = v8hi_ftype_v8hi_v8hi_char;
7164
7165 /* vint, vint, vint, 4 bit literal. */
7166 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
7167 && mode3 == QImode)
7168 type = v4si_ftype_v4si_v4si_char;
7169
7170 /* vfloat, vfloat, vfloat, 4 bit literal. */
7171 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
7172 && mode3 == QImode)
7173 type = v4sf_ftype_v4sf_v4sf_char;
7174
2212663f
DB
7175 else
7176 abort ();
7177
7178 def_builtin (d->mask, d->name, type, d->code);
7179 }
7180
0ac081f6 7181 /* Add the simple binary operators. */
00b960c7 7182 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 7183 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
7184 {
7185 enum machine_mode mode0, mode1, mode2;
7186 tree type;
7187
0559cc77 7188 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
7189 continue;
7190
7191 mode0 = insn_data[d->icode].operand[0].mode;
7192 mode1 = insn_data[d->icode].operand[1].mode;
7193 mode2 = insn_data[d->icode].operand[2].mode;
7194
7195 /* When all three operands are of the same mode. */
7196 if (mode0 == mode1 && mode1 == mode2)
7197 {
7198 switch (mode0)
7199 {
7200 case V4SFmode:
7201 type = v4sf_ftype_v4sf_v4sf;
7202 break;
7203 case V4SImode:
7204 type = v4si_ftype_v4si_v4si;
7205 break;
7206 case V16QImode:
7207 type = v16qi_ftype_v16qi_v16qi;
7208 break;
7209 case V8HImode:
7210 type = v8hi_ftype_v8hi_v8hi;
7211 break;
a3170dc6
AH
7212 case V2SImode:
7213 type = v2si_ftype_v2si_v2si;
7214 break;
7215 case V2SFmode:
7216 type = v2sf_ftype_v2sf_v2sf;
7217 break;
7218 case SImode:
7219 type = int_ftype_int_int;
7220 break;
0ac081f6
AH
7221 default:
7222 abort ();
7223 }
7224 }
7225
7226 /* A few other combos we really don't want to do manually. */
7227
7228 /* vint, vfloat, vfloat. */
7229 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
7230 type = v4si_ftype_v4sf_v4sf;
7231
7232 /* vshort, vchar, vchar. */
7233 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
7234 type = v8hi_ftype_v16qi_v16qi;
7235
7236 /* vint, vshort, vshort. */
7237 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
7238 type = v4si_ftype_v8hi_v8hi;
7239
7240 /* vshort, vint, vint. */
7241 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
7242 type = v8hi_ftype_v4si_v4si;
7243
7244 /* vchar, vshort, vshort. */
7245 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
7246 type = v16qi_ftype_v8hi_v8hi;
7247
7248 /* vint, vchar, vint. */
7249 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
7250 type = v4si_ftype_v16qi_v4si;
7251
fa066a23
AH
7252 /* vint, vchar, vchar. */
7253 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
7254 type = v4si_ftype_v16qi_v16qi;
7255
0ac081f6
AH
7256 /* vint, vshort, vint. */
7257 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
7258 type = v4si_ftype_v8hi_v4si;
2212663f
DB
7259
7260 /* vint, vint, 5 bit literal. */
7261 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
7262 type = v4si_ftype_v4si_char;
7263
7264 /* vshort, vshort, 5 bit literal. */
7265 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
7266 type = v8hi_ftype_v8hi_char;
7267
7268 /* vchar, vchar, 5 bit literal. */
7269 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
7270 type = v16qi_ftype_v16qi_char;
0ac081f6 7271
617e0e1d
DB
7272 /* vfloat, vint, 5 bit literal. */
7273 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
7274 type = v4sf_ftype_v4si_char;
7275
7276 /* vint, vfloat, 5 bit literal. */
7277 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
7278 type = v4si_ftype_v4sf_char;
7279
a3170dc6
AH
7280 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
7281 type = v2si_ftype_int_int;
7282
7283 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
7284 type = v2si_ftype_v2si_char;
7285
7286 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
7287 type = v2si_ftype_int_char;
7288
0ac081f6
AH
7289 /* int, x, x. */
7290 else if (mode0 == SImode)
7291 {
7292 switch (mode1)
7293 {
7294 case V4SImode:
7295 type = int_ftype_v4si_v4si;
7296 break;
7297 case V4SFmode:
7298 type = int_ftype_v4sf_v4sf;
7299 break;
7300 case V16QImode:
7301 type = int_ftype_v16qi_v16qi;
7302 break;
7303 case V8HImode:
7304 type = int_ftype_v8hi_v8hi;
7305 break;
7306 default:
7307 abort ();
7308 }
7309 }
7310
7311 else
7312 abort ();
7313
2212663f
DB
7314 def_builtin (d->mask, d->name, type, d->code);
7315 }
24408032 7316
2212663f
DB
7317 /* Add the simple unary operators. */
7318 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 7319 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
7320 {
7321 enum machine_mode mode0, mode1;
7322 tree type;
7323
0559cc77 7324 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7325 continue;
7326
7327 mode0 = insn_data[d->icode].operand[0].mode;
7328 mode1 = insn_data[d->icode].operand[1].mode;
7329
7330 if (mode0 == V4SImode && mode1 == QImode)
7331 type = v4si_ftype_char;
7332 else if (mode0 == V8HImode && mode1 == QImode)
7333 type = v8hi_ftype_char;
7334 else if (mode0 == V16QImode && mode1 == QImode)
7335 type = v16qi_ftype_char;
617e0e1d
DB
7336 else if (mode0 == V4SFmode && mode1 == V4SFmode)
7337 type = v4sf_ftype_v4sf;
20e26713
AH
7338 else if (mode0 == V8HImode && mode1 == V16QImode)
7339 type = v8hi_ftype_v16qi;
7340 else if (mode0 == V4SImode && mode1 == V8HImode)
7341 type = v4si_ftype_v8hi;
a3170dc6
AH
7342 else if (mode0 == V2SImode && mode1 == V2SImode)
7343 type = v2si_ftype_v2si;
7344 else if (mode0 == V2SFmode && mode1 == V2SFmode)
7345 type = v2sf_ftype_v2sf;
7346 else if (mode0 == V2SFmode && mode1 == V2SImode)
7347 type = v2sf_ftype_v2si;
7348 else if (mode0 == V2SImode && mode1 == V2SFmode)
7349 type = v2si_ftype_v2sf;
7350 else if (mode0 == V2SImode && mode1 == QImode)
7351 type = v2si_ftype_char;
2212663f
DB
7352 else
7353 abort ();
7354
0ac081f6
AH
7355 def_builtin (d->mask, d->name, type, d->code);
7356 }
7357}
7358
c15c90bb
ZW
7359static void
7360rs6000_init_libfuncs (void)
7361{
7362 if (!TARGET_HARD_FLOAT)
7363 return;
7364
c9034561 7365 if (DEFAULT_ABI != ABI_V4)
c15c90bb 7366 {
c9034561 7367 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 7368 {
c9034561 7369 /* AIX library routines for float->int conversion. */
85363ca0
ZW
7370 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
7371 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
7372 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
7373 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
7374 }
7375
c9034561 7376 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7377 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
7378 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
7379 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
7380 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
7381 }
c9034561 7382 else
c15c90bb 7383 {
c9034561 7384 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7385
7386 set_optab_libfunc (add_optab, TFmode, "_q_add");
7387 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
7388 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
7389 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
7390 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
7391 if (TARGET_PPC_GPOPT || TARGET_POWER2)
7392 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
7393
c9034561
ZW
7394 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
7395 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
7396 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
7397 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
7398 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
7399 set_optab_libfunc (le_optab, TFmode, "_q_fle");
7400
85363ca0
ZW
7401 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
7402 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
7403 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
7404 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
7405 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
7406 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
7407 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
7408 }
7409}
35aff10b 7410\f
7e69e155
MM
7411/* Expand a block move operation, and return 1 if successful. Return 0
7412 if we should let the compiler generate normal code.
7413
7414 operands[0] is the destination
7415 operands[1] is the source
7416 operands[2] is the length
7417 operands[3] is the alignment */
7418
3933e0e1
MM
7419#define MAX_MOVE_REG 4
7420
7e69e155 7421int
a2369ed3 7422expand_block_move (rtx operands[])
7e69e155 7423{
b6c9286a
MM
7424 rtx orig_dest = operands[0];
7425 rtx orig_src = operands[1];
7e69e155 7426 rtx bytes_rtx = operands[2];
7e69e155 7427 rtx align_rtx = operands[3];
3933e0e1 7428 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 7429 int align;
3933e0e1
MM
7430 int bytes;
7431 int offset;
7e69e155 7432 int move_bytes;
cabfd258
GK
7433 rtx stores[MAX_MOVE_REG];
7434 int num_reg = 0;
7e69e155 7435
3933e0e1 7436 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 7437 if (! constp)
3933e0e1
MM
7438 return 0;
7439
5ee95df6
FS
7440 /* If this is not a fixed size alignment, abort */
7441 if (GET_CODE (align_rtx) != CONST_INT)
7442 abort ();
7443 align = INTVAL (align_rtx);
7444
7e69e155 7445 /* Anything to move? */
3933e0e1
MM
7446 bytes = INTVAL (bytes_rtx);
7447 if (bytes <= 0)
7e69e155
MM
7448 return 1;
7449
ea9982a8 7450 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 7451 reg_parm_stack_space. */
ea9982a8 7452 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
7453 return 0;
7454
cabfd258 7455 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 7456 {
cabfd258 7457 union {
a2369ed3
DJ
7458 rtx (*movstrsi) (rtx, rtx, rtx, rtx);
7459 rtx (*mov) (rtx, rtx);
cabfd258
GK
7460 } gen_func;
7461 enum machine_mode mode = BLKmode;
7462 rtx src, dest;
7463
7464 if (TARGET_STRING
7465 && bytes > 24 /* move up to 32 bytes at a time */
7466 && ! fixed_regs[5]
7467 && ! fixed_regs[6]
7468 && ! fixed_regs[7]
7469 && ! fixed_regs[8]
7470 && ! fixed_regs[9]
7471 && ! fixed_regs[10]
7472 && ! fixed_regs[11]
7473 && ! fixed_regs[12])
7e69e155 7474 {
cabfd258
GK
7475 move_bytes = (bytes > 32) ? 32 : bytes;
7476 gen_func.movstrsi = gen_movstrsi_8reg;
7477 }
7478 else if (TARGET_STRING
7479 && bytes > 16 /* move up to 24 bytes at a time */
7480 && ! fixed_regs[5]
7481 && ! fixed_regs[6]
7482 && ! fixed_regs[7]
7483 && ! fixed_regs[8]
7484 && ! fixed_regs[9]
7485 && ! fixed_regs[10])
7486 {
7487 move_bytes = (bytes > 24) ? 24 : bytes;
7488 gen_func.movstrsi = gen_movstrsi_6reg;
7489 }
7490 else if (TARGET_STRING
7491 && bytes > 8 /* move up to 16 bytes at a time */
7492 && ! fixed_regs[5]
7493 && ! fixed_regs[6]
7494 && ! fixed_regs[7]
7495 && ! fixed_regs[8])
7496 {
7497 move_bytes = (bytes > 16) ? 16 : bytes;
7498 gen_func.movstrsi = gen_movstrsi_4reg;
7499 }
7500 else if (bytes >= 8 && TARGET_POWERPC64
7501 /* 64-bit loads and stores require word-aligned
7502 displacements. */
7503 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
7504 {
7505 move_bytes = 8;
7506 mode = DImode;
7507 gen_func.mov = gen_movdi;
7508 }
7509 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
7510 { /* move up to 8 bytes at a time */
7511 move_bytes = (bytes > 8) ? 8 : bytes;
7512 gen_func.movstrsi = gen_movstrsi_2reg;
7513 }
7514 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
7515 { /* move 4 bytes */
7516 move_bytes = 4;
7517 mode = SImode;
7518 gen_func.mov = gen_movsi;
7519 }
7520 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
7521 { /* move 2 bytes */
7522 move_bytes = 2;
7523 mode = HImode;
7524 gen_func.mov = gen_movhi;
7525 }
7526 else if (TARGET_STRING && bytes > 1)
7527 { /* move up to 4 bytes at a time */
7528 move_bytes = (bytes > 4) ? 4 : bytes;
7529 gen_func.movstrsi = gen_movstrsi_1reg;
7530 }
7531 else /* move 1 byte at a time */
7532 {
7533 move_bytes = 1;
7534 mode = QImode;
7535 gen_func.mov = gen_movqi;
7536 }
7537
7538 src = adjust_address (orig_src, mode, offset);
7539 dest = adjust_address (orig_dest, mode, offset);
7540
7541 if (mode != BLKmode)
7542 {
7543 rtx tmp_reg = gen_reg_rtx (mode);
7544
7545 emit_insn ((*gen_func.mov) (tmp_reg, src));
7546 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 7547 }
3933e0e1 7548
cabfd258
GK
7549 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
7550 {
7551 int i;
7552 for (i = 0; i < num_reg; i++)
7553 emit_insn (stores[i]);
7554 num_reg = 0;
7555 }
35aff10b 7556
cabfd258 7557 if (mode == BLKmode)
7e69e155 7558 {
cabfd258
GK
7559 /* Move the address into scratch registers. The movstrsi
7560 patterns require zero offset. */
7561 if (!REG_P (XEXP (src, 0)))
b6c9286a 7562 {
cabfd258
GK
7563 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
7564 src = replace_equiv_address (src, src_reg);
b6c9286a 7565 }
cabfd258
GK
7566 set_mem_size (src, GEN_INT (move_bytes));
7567
7568 if (!REG_P (XEXP (dest, 0)))
3933e0e1 7569 {
cabfd258
GK
7570 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
7571 dest = replace_equiv_address (dest, dest_reg);
7e69e155 7572 }
cabfd258
GK
7573 set_mem_size (dest, GEN_INT (move_bytes));
7574
7575 emit_insn ((*gen_func.movstrsi) (dest, src,
7576 GEN_INT (move_bytes & 31),
7577 align_rtx));
7e69e155 7578 }
7e69e155
MM
7579 }
7580
7581 return 1;
7582}
7583
9878760c
RK
7584\f
7585/* Return 1 if OP is a load multiple operation. It is known to be a
7586 PARALLEL and the first section will be tested. */
7587
7588int
a2369ed3 7589load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7590{
7591 int count = XVECLEN (op, 0);
e2c953b6 7592 unsigned int dest_regno;
9878760c
RK
7593 rtx src_addr;
7594 int i;
7595
7596 /* Perform a quick check so we don't blow up below. */
7597 if (count <= 1
7598 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7599 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7600 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7601 return 0;
7602
7603 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7604 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7605
7606 for (i = 1; i < count; i++)
7607 {
7608 rtx elt = XVECEXP (op, 0, i);
7609
7610 if (GET_CODE (elt) != SET
7611 || GET_CODE (SET_DEST (elt)) != REG
7612 || GET_MODE (SET_DEST (elt)) != SImode
7613 || REGNO (SET_DEST (elt)) != dest_regno + i
7614 || GET_CODE (SET_SRC (elt)) != MEM
7615 || GET_MODE (SET_SRC (elt)) != SImode
7616 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
7617 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
7618 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
7619 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
7620 return 0;
7621 }
7622
7623 return 1;
7624}
7625
7626/* Similar, but tests for store multiple. Here, the second vector element
7627 is a CLOBBER. It will be tested later. */
7628
7629int
a2369ed3 7630store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7631{
7632 int count = XVECLEN (op, 0) - 1;
e2c953b6 7633 unsigned int src_regno;
9878760c
RK
7634 rtx dest_addr;
7635 int i;
7636
7637 /* Perform a quick check so we don't blow up below. */
7638 if (count <= 1
7639 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7640 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7641 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7642 return 0;
7643
7644 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7645 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7646
7647 for (i = 1; i < count; i++)
7648 {
7649 rtx elt = XVECEXP (op, 0, i + 1);
7650
7651 if (GET_CODE (elt) != SET
7652 || GET_CODE (SET_SRC (elt)) != REG
7653 || GET_MODE (SET_SRC (elt)) != SImode
7654 || REGNO (SET_SRC (elt)) != src_regno + i
7655 || GET_CODE (SET_DEST (elt)) != MEM
7656 || GET_MODE (SET_DEST (elt)) != SImode
7657 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
7658 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
7659 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
7660 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
7661 return 0;
7662 }
7663
7664 return 1;
7665}
9ebbca7d 7666
9caa3eb2
DE
7667/* Return a string to perform a load_multiple operation.
7668 operands[0] is the vector.
7669 operands[1] is the source address.
7670 operands[2] is the first destination register. */
7671
7672const char *
a2369ed3 7673rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
7674{
7675 /* We have to handle the case where the pseudo used to contain the address
7676 is assigned to one of the output registers. */
7677 int i, j;
7678 int words = XVECLEN (operands[0], 0);
7679 rtx xop[10];
7680
7681 if (XVECLEN (operands[0], 0) == 1)
7682 return "{l|lwz} %2,0(%1)";
7683
7684 for (i = 0; i < words; i++)
7685 if (refers_to_regno_p (REGNO (operands[2]) + i,
7686 REGNO (operands[2]) + i + 1, operands[1], 0))
7687 {
7688 if (i == words-1)
7689 {
7690 xop[0] = GEN_INT (4 * (words-1));
7691 xop[1] = operands[1];
7692 xop[2] = operands[2];
7693 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
7694 return "";
7695 }
7696 else if (i == 0)
7697 {
7698 xop[0] = GEN_INT (4 * (words-1));
7699 xop[1] = operands[1];
7700 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
7701 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);
7702 return "";
7703 }
7704 else
7705 {
7706 for (j = 0; j < words; j++)
7707 if (j != i)
7708 {
7709 xop[0] = GEN_INT (j * 4);
7710 xop[1] = operands[1];
7711 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
7712 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
7713 }
7714 xop[0] = GEN_INT (i * 4);
7715 xop[1] = operands[1];
7716 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
7717 return "";
7718 }
7719 }
7720
7721 return "{lsi|lswi} %2,%1,%N0";
7722}
7723
00b960c7
AH
7724/* Return 1 for a parallel vrsave operation. */
7725
7726int
a2369ed3 7727vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
7728{
7729 int count = XVECLEN (op, 0);
7730 unsigned int dest_regno, src_regno;
7731 int i;
7732
7733 if (count <= 1
7734 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7735 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 7736 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
7737 return 0;
7738
7739 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7740 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7741
7742 if (dest_regno != VRSAVE_REGNO
7743 && src_regno != VRSAVE_REGNO)
7744 return 0;
7745
7746 for (i = 1; i < count; i++)
7747 {
7748 rtx elt = XVECEXP (op, 0, i);
7749
9aa86737
AH
7750 if (GET_CODE (elt) != CLOBBER
7751 && GET_CODE (elt) != SET)
00b960c7
AH
7752 return 0;
7753 }
7754
7755 return 1;
7756}
7757
2c4a9cff
DE
7758/* Return 1 for an PARALLEL suitable for mfcr. */
7759
7760int
a2369ed3 7761mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
7762{
7763 int count = XVECLEN (op, 0);
7764 int i;
7765
7766 /* Perform a quick check so we don't blow up below. */
7767 if (count < 1
7768 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7769 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7770 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
7771 return 0;
7772
7773 for (i = 0; i < count; i++)
7774 {
7775 rtx exp = XVECEXP (op, 0, i);
7776 rtx unspec;
7777 int maskval;
7778 rtx src_reg;
7779
7780 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
7781
7782 if (GET_CODE (src_reg) != REG
7783 || GET_MODE (src_reg) != CCmode
7784 || ! CR_REGNO_P (REGNO (src_reg)))
7785 return 0;
7786
7787 if (GET_CODE (exp) != SET
7788 || GET_CODE (SET_DEST (exp)) != REG
7789 || GET_MODE (SET_DEST (exp)) != SImode
7790 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
7791 return 0;
7792 unspec = SET_SRC (exp);
7793 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
7794
7795 if (GET_CODE (unspec) != UNSPEC
7796 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
7797 || XVECLEN (unspec, 0) != 2
7798 || XVECEXP (unspec, 0, 0) != src_reg
7799 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7800 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7801 return 0;
7802 }
7803 return 1;
7804}
7805
a4f6c312 7806/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
7807
7808int
a2369ed3 7809mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7810{
7811 int count = XVECLEN (op, 0);
7812 int i;
9ebbca7d
GK
7813 rtx src_reg;
7814
7815 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
7816 if (count < 1
7817 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7818 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7819 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 7820 return 0;
e35b9579 7821 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
7822
7823 if (GET_CODE (src_reg) != REG
7824 || GET_MODE (src_reg) != SImode
7825 || ! INT_REGNO_P (REGNO (src_reg)))
7826 return 0;
7827
e35b9579 7828 for (i = 0; i < count; i++)
9ebbca7d
GK
7829 {
7830 rtx exp = XVECEXP (op, 0, i);
7831 rtx unspec;
7832 int maskval;
7833
7834 if (GET_CODE (exp) != SET
7835 || GET_CODE (SET_DEST (exp)) != REG
7836 || GET_MODE (SET_DEST (exp)) != CCmode
7837 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
7838 return 0;
7839 unspec = SET_SRC (exp);
7840 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
7841
7842 if (GET_CODE (unspec) != UNSPEC
615158e2 7843 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
7844 || XVECLEN (unspec, 0) != 2
7845 || XVECEXP (unspec, 0, 0) != src_reg
7846 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7847 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7848 return 0;
7849 }
e35b9579 7850 return 1;
9ebbca7d
GK
7851}
7852
a4f6c312 7853/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
7854
7855int
a2369ed3 7856lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7857{
7858 int count = XVECLEN (op, 0);
e2c953b6 7859 unsigned int dest_regno;
9ebbca7d 7860 rtx src_addr;
e2c953b6 7861 unsigned int base_regno;
9ebbca7d
GK
7862 HOST_WIDE_INT offset;
7863 int i;
7864
7865 /* Perform a quick check so we don't blow up below. */
7866 if (count <= 1
7867 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7868 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7869 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7870 return 0;
7871
7872 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7873 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7874
7875 if (dest_regno > 31
e2c953b6 7876 || count != 32 - (int) dest_regno)
9ebbca7d
GK
7877 return 0;
7878
4d588c14 7879 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
7880 {
7881 offset = 0;
7882 base_regno = REGNO (src_addr);
7883 if (base_regno == 0)
7884 return 0;
7885 }
4d588c14 7886 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
7887 {
7888 offset = INTVAL (XEXP (src_addr, 1));
7889 base_regno = REGNO (XEXP (src_addr, 0));
7890 }
7891 else
7892 return 0;
7893
7894 for (i = 0; i < count; i++)
7895 {
7896 rtx elt = XVECEXP (op, 0, i);
7897 rtx newaddr;
7898 rtx addr_reg;
7899 HOST_WIDE_INT newoffset;
7900
7901 if (GET_CODE (elt) != SET
7902 || GET_CODE (SET_DEST (elt)) != REG
7903 || GET_MODE (SET_DEST (elt)) != SImode
7904 || REGNO (SET_DEST (elt)) != dest_regno + i
7905 || GET_CODE (SET_SRC (elt)) != MEM
7906 || GET_MODE (SET_SRC (elt)) != SImode)
7907 return 0;
7908 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 7909 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7910 {
7911 newoffset = 0;
7912 addr_reg = newaddr;
7913 }
4d588c14 7914 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7915 {
7916 addr_reg = XEXP (newaddr, 0);
7917 newoffset = INTVAL (XEXP (newaddr, 1));
7918 }
7919 else
7920 return 0;
7921 if (REGNO (addr_reg) != base_regno
7922 || newoffset != offset + 4 * i)
7923 return 0;
7924 }
7925
7926 return 1;
7927}
7928
a4f6c312 7929/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
7930
7931int
a2369ed3 7932stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7933{
7934 int count = XVECLEN (op, 0);
e2c953b6 7935 unsigned int src_regno;
9ebbca7d 7936 rtx dest_addr;
e2c953b6 7937 unsigned int base_regno;
9ebbca7d
GK
7938 HOST_WIDE_INT offset;
7939 int i;
7940
7941 /* Perform a quick check so we don't blow up below. */
7942 if (count <= 1
7943 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7944 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7945 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7946 return 0;
7947
7948 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7949 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7950
7951 if (src_regno > 31
e2c953b6 7952 || count != 32 - (int) src_regno)
9ebbca7d
GK
7953 return 0;
7954
4d588c14 7955 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
7956 {
7957 offset = 0;
7958 base_regno = REGNO (dest_addr);
7959 if (base_regno == 0)
7960 return 0;
7961 }
4d588c14 7962 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
7963 {
7964 offset = INTVAL (XEXP (dest_addr, 1));
7965 base_regno = REGNO (XEXP (dest_addr, 0));
7966 }
7967 else
7968 return 0;
7969
7970 for (i = 0; i < count; i++)
7971 {
7972 rtx elt = XVECEXP (op, 0, i);
7973 rtx newaddr;
7974 rtx addr_reg;
7975 HOST_WIDE_INT newoffset;
7976
7977 if (GET_CODE (elt) != SET
7978 || GET_CODE (SET_SRC (elt)) != REG
7979 || GET_MODE (SET_SRC (elt)) != SImode
7980 || REGNO (SET_SRC (elt)) != src_regno + i
7981 || GET_CODE (SET_DEST (elt)) != MEM
7982 || GET_MODE (SET_DEST (elt)) != SImode)
7983 return 0;
7984 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 7985 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7986 {
7987 newoffset = 0;
7988 addr_reg = newaddr;
7989 }
4d588c14 7990 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7991 {
7992 addr_reg = XEXP (newaddr, 0);
7993 newoffset = INTVAL (XEXP (newaddr, 1));
7994 }
7995 else
7996 return 0;
7997 if (REGNO (addr_reg) != base_regno
7998 || newoffset != offset + 4 * i)
7999 return 0;
8000 }
8001
8002 return 1;
8003}
9878760c 8004\f
a4f6c312
SS
8005/* A validation routine: say whether CODE, a condition code, and MODE
8006 match. The other alternatives either don't make sense or should
8007 never be generated. */
39a10a29 8008
39a10a29 8009static void
a2369ed3 8010validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29
GK
8011{
8012 if (GET_RTX_CLASS (code) != '<'
8013 || GET_MODE_CLASS (mode) != MODE_CC)
8014 abort ();
8015
8016 /* These don't make sense. */
8017 if ((code == GT || code == LT || code == GE || code == LE)
8018 && mode == CCUNSmode)
8019 abort ();
8020
8021 if ((code == GTU || code == LTU || code == GEU || code == LEU)
8022 && mode != CCUNSmode)
8023 abort ();
8024
8025 if (mode != CCFPmode
8026 && (code == ORDERED || code == UNORDERED
8027 || code == UNEQ || code == LTGT
8028 || code == UNGT || code == UNLT
8029 || code == UNGE || code == UNLE))
a4f6c312 8030 abort ();
39a10a29 8031
de6c5979 8032 /* These should never be generated except for
bc9ec0e0 8033 flag_finite_math_only. */
39a10a29 8034 if (mode == CCFPmode
ad72b533 8035 && ! flag_finite_math_only
39a10a29
GK
8036 && (code == LE || code == GE
8037 || code == UNEQ || code == LTGT
8038 || code == UNGT || code == UNLT))
8039 abort ();
8040
8041 /* These are invalid; the information is not there. */
8042 if (mode == CCEQmode
8043 && code != EQ && code != NE)
8044 abort ();
8045}
8046
9878760c
RK
8047/* Return 1 if OP is a comparison operation that is valid for a branch insn.
8048 We only check the opcode against the mode of the CC value here. */
8049
8050int
a2369ed3 8051branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8052{
8053 enum rtx_code code = GET_CODE (op);
8054 enum machine_mode cc_mode;
8055
8056 if (GET_RTX_CLASS (code) != '<')
8057 return 0;
8058
8059 cc_mode = GET_MODE (XEXP (op, 0));
8060 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
8061 return 0;
8062
39a10a29 8063 validate_condition_mode (code, cc_mode);
9878760c 8064
39a10a29
GK
8065 return 1;
8066}
8067
8068/* Return 1 if OP is a comparison operation that is valid for a branch
8069 insn and which is true if the corresponding bit in the CC register
8070 is set. */
8071
8072int
a2369ed3 8073branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
8074{
8075 enum rtx_code code;
8076
8daf2e65 8077 if (! branch_comparison_operator (op, mode))
9878760c
RK
8078 return 0;
8079
39a10a29
GK
8080 code = GET_CODE (op);
8081 return (code == EQ || code == LT || code == GT
993f19a8 8082 || (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
8083 || code == LTU || code == GTU
8084 || code == UNORDERED);
9878760c
RK
8085}
8086
b7053a3f
GK
8087/* Return 1 if OP is a comparison operation that is valid for an scc
8088 insn: it must be a positive comparison. */
9878760c
RK
8089
8090int
a2369ed3 8091scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 8092{
b7053a3f 8093 return branch_positive_comparison_operator (op, mode);
9878760c 8094}
e0cd0770
JC
8095
8096int
a2369ed3 8097trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
8098{
8099 if (mode != VOIDmode && mode != GET_MODE (op))
8100 return 0;
39a10a29 8101 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 8102}
dfbdccdb
GK
8103
8104int
a2369ed3 8105boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
8106{
8107 enum rtx_code code = GET_CODE (op);
8108 return (code == AND || code == IOR || code == XOR);
8109}
1d328b19
GK
8110
8111int
a2369ed3 8112boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
8113{
8114 enum rtx_code code = GET_CODE (op);
8115 return (code == IOR || code == XOR);
8116}
50a0b056
GK
8117
8118int
a2369ed3 8119min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
8120{
8121 enum rtx_code code = GET_CODE (op);
8122 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
8123}
9878760c
RK
8124\f
8125/* Return 1 if ANDOP is a mask that has no bits on that are not in the
8126 mask required to convert the result of a rotate insn into a shift
b1765bde 8127 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
8128
8129int
a2369ed3 8130includes_lshift_p (rtx shiftop, rtx andop)
9878760c 8131{
e2c953b6
DE
8132 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
8133
8134 shift_mask <<= INTVAL (shiftop);
9878760c 8135
b1765bde 8136 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
8137}
8138
8139/* Similar, but for right shift. */
8140
8141int
a2369ed3 8142includes_rshift_p (rtx shiftop, rtx andop)
9878760c 8143{
a7653a2c 8144 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
8145
8146 shift_mask >>= INTVAL (shiftop);
8147
b1765bde 8148 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
8149}
8150
c5059423
AM
8151/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
8152 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 8153 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
8154
8155int
a2369ed3 8156includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 8157{
c5059423
AM
8158 if (GET_CODE (andop) == CONST_INT)
8159 {
02071907 8160 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 8161
c5059423 8162 c = INTVAL (andop);
02071907 8163 if (c == 0 || c == ~0)
c5059423 8164 return 0;
e2c953b6 8165
02071907 8166 shift_mask = ~0;
c5059423
AM
8167 shift_mask <<= INTVAL (shiftop);
8168
b6d08ca1 8169 /* Find the least significant one bit. */
c5059423
AM
8170 lsb = c & -c;
8171
8172 /* It must coincide with the LSB of the shift mask. */
8173 if (-lsb != shift_mask)
8174 return 0;
e2c953b6 8175
c5059423
AM
8176 /* Invert to look for the next transition (if any). */
8177 c = ~c;
8178
8179 /* Remove the low group of ones (originally low group of zeros). */
8180 c &= -lsb;
8181
8182 /* Again find the lsb, and check we have all 1's above. */
8183 lsb = c & -c;
8184 return c == -lsb;
8185 }
8186 else if (GET_CODE (andop) == CONST_DOUBLE
8187 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8188 {
02071907
AM
8189 HOST_WIDE_INT low, high, lsb;
8190 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
8191
8192 low = CONST_DOUBLE_LOW (andop);
8193 if (HOST_BITS_PER_WIDE_INT < 64)
8194 high = CONST_DOUBLE_HIGH (andop);
8195
8196 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 8197 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
8198 return 0;
8199
8200 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8201 {
02071907 8202 shift_mask_high = ~0;
c5059423
AM
8203 if (INTVAL (shiftop) > 32)
8204 shift_mask_high <<= INTVAL (shiftop) - 32;
8205
8206 lsb = high & -high;
8207
8208 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
8209 return 0;
8210
8211 high = ~high;
8212 high &= -lsb;
8213
8214 lsb = high & -high;
8215 return high == -lsb;
8216 }
8217
02071907 8218 shift_mask_low = ~0;
c5059423
AM
8219 shift_mask_low <<= INTVAL (shiftop);
8220
8221 lsb = low & -low;
8222
8223 if (-lsb != shift_mask_low)
8224 return 0;
8225
8226 if (HOST_BITS_PER_WIDE_INT < 64)
8227 high = ~high;
8228 low = ~low;
8229 low &= -lsb;
8230
8231 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8232 {
8233 lsb = high & -high;
8234 return high == -lsb;
8235 }
8236
8237 lsb = low & -low;
8238 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
8239 }
8240 else
8241 return 0;
8242}
e2c953b6 8243
c5059423
AM
8244/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
8245 to perform a left shift. It must have SHIFTOP or more least
c1207243 8246 significant 0's, with the remainder of the word 1's. */
e2c953b6 8247
c5059423 8248int
a2369ed3 8249includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 8250{
e2c953b6 8251 if (GET_CODE (andop) == CONST_INT)
c5059423 8252 {
02071907 8253 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 8254
02071907 8255 shift_mask = ~0;
c5059423
AM
8256 shift_mask <<= INTVAL (shiftop);
8257 c = INTVAL (andop);
8258
c1207243 8259 /* Find the least significant one bit. */
c5059423
AM
8260 lsb = c & -c;
8261
8262 /* It must be covered by the shift mask.
a4f6c312 8263 This test also rejects c == 0. */
c5059423
AM
8264 if ((lsb & shift_mask) == 0)
8265 return 0;
8266
8267 /* Check we have all 1's above the transition, and reject all 1's. */
8268 return c == -lsb && lsb != 1;
8269 }
8270 else if (GET_CODE (andop) == CONST_DOUBLE
8271 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8272 {
02071907 8273 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
8274
8275 low = CONST_DOUBLE_LOW (andop);
8276
8277 if (HOST_BITS_PER_WIDE_INT < 64)
8278 {
02071907 8279 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
8280
8281 high = CONST_DOUBLE_HIGH (andop);
8282
8283 if (low == 0)
8284 {
02071907 8285 shift_mask_high = ~0;
c5059423
AM
8286 if (INTVAL (shiftop) > 32)
8287 shift_mask_high <<= INTVAL (shiftop) - 32;
8288
8289 lsb = high & -high;
8290
8291 if ((lsb & shift_mask_high) == 0)
8292 return 0;
8293
8294 return high == -lsb;
8295 }
8296 if (high != ~0)
8297 return 0;
8298 }
8299
02071907 8300 shift_mask_low = ~0;
c5059423
AM
8301 shift_mask_low <<= INTVAL (shiftop);
8302
8303 lsb = low & -low;
8304
8305 if ((lsb & shift_mask_low) == 0)
8306 return 0;
8307
8308 return low == -lsb && lsb != 1;
8309 }
e2c953b6 8310 else
c5059423 8311 return 0;
9878760c 8312}
35068b43
RK
8313
8314/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
8315 for lfq and stfq insns.
8316
8317 Note reg1 and reg2 *must* be hard registers. To be sure we will
8318 abort if we are passed pseudo registers. */
8319
8320int
a2369ed3 8321registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
8322{
8323 /* We might have been passed a SUBREG. */
8324 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8325 return 0;
8326
8327 return (REGNO (reg1) == REGNO (reg2) - 1);
8328}
8329
a4f6c312
SS
8330/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
8331 addr1 and addr2 must be in consecutive memory locations
8332 (addr2 == addr1 + 8). */
35068b43
RK
8333
8334int
a2369ed3 8335addrs_ok_for_quad_peep (rtx addr1, rtx addr2)
35068b43 8336{
e2c953b6 8337 unsigned int reg1;
35068b43
RK
8338 int offset1;
8339
8340 /* Extract an offset (if used) from the first addr. */
8341 if (GET_CODE (addr1) == PLUS)
8342 {
8343 /* If not a REG, return zero. */
8344 if (GET_CODE (XEXP (addr1, 0)) != REG)
8345 return 0;
8346 else
8347 {
8348 reg1 = REGNO (XEXP (addr1, 0));
8349 /* The offset must be constant! */
8350 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8351 return 0;
8352 offset1 = INTVAL (XEXP (addr1, 1));
8353 }
8354 }
8355 else if (GET_CODE (addr1) != REG)
8356 return 0;
8357 else
8358 {
8359 reg1 = REGNO (addr1);
8360 /* This was a simple (mem (reg)) expression. Offset is 0. */
8361 offset1 = 0;
8362 }
8363
a2369ed3 8364 /* Make sure the second address is a (mem (plus (reg) (const_int)))
0f6937fe
AM
8365 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
8366 register as addr1. */
984e25ac 8367 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
0f6937fe 8368 return 1;
35068b43
RK
8369 if (GET_CODE (addr2) != PLUS)
8370 return 0;
8371
8372 if (GET_CODE (XEXP (addr2, 0)) != REG
8373 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8374 return 0;
8375
8376 if (reg1 != REGNO (XEXP (addr2, 0)))
8377 return 0;
8378
8379 /* The offset for the second addr must be 8 more than the first addr. */
8380 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
8381 return 0;
8382
8383 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
8384 instructions. */
8385 return 1;
8386}
9878760c
RK
8387\f
8388/* Return the register class of a scratch register needed to copy IN into
8389 or out of a register in CLASS in MODE. If it can be done directly,
8390 NO_REGS is returned. */
8391
8392enum reg_class
a2369ed3 8393secondary_reload_class (enum reg_class class,
a9baceb1
GK
8394 enum machine_mode mode ATTRIBUTE_UNUSED,
8395 rtx in)
9878760c 8396{
5accd822 8397 int regno;
9878760c 8398
ab82a49f
AP
8399 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
8400#if TARGET_MACHO
8401 && MACHOPIC_INDIRECT
8402#endif
8403 ))
46fad5b7
DJ
8404 {
8405 /* We cannot copy a symbolic operand directly into anything
8406 other than BASE_REGS for TARGET_ELF. So indicate that a
8407 register from BASE_REGS is needed as an intermediate
8408 register.
8409
8410 On Darwin, pic addresses require a load from memory, which
8411 needs a base register. */
8412 if (class != BASE_REGS
8413 && (GET_CODE (in) == SYMBOL_REF
8414 || GET_CODE (in) == HIGH
8415 || GET_CODE (in) == LABEL_REF
8416 || GET_CODE (in) == CONST))
8417 return BASE_REGS;
8418 }
e7b7998a 8419
5accd822
DE
8420 if (GET_CODE (in) == REG)
8421 {
8422 regno = REGNO (in);
8423 if (regno >= FIRST_PSEUDO_REGISTER)
8424 {
8425 regno = true_regnum (in);
8426 if (regno >= FIRST_PSEUDO_REGISTER)
8427 regno = -1;
8428 }
8429 }
8430 else if (GET_CODE (in) == SUBREG)
8431 {
8432 regno = true_regnum (in);
8433 if (regno >= FIRST_PSEUDO_REGISTER)
8434 regno = -1;
8435 }
8436 else
8437 regno = -1;
8438
9878760c
RK
8439 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
8440 into anything. */
8441 if (class == GENERAL_REGS || class == BASE_REGS
8442 || (regno >= 0 && INT_REGNO_P (regno)))
8443 return NO_REGS;
8444
8445 /* Constants, memory, and FP registers can go into FP registers. */
8446 if ((regno == -1 || FP_REGNO_P (regno))
8447 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
8448 return NO_REGS;
8449
0ac081f6
AH
8450 /* Memory, and AltiVec registers can go into AltiVec registers. */
8451 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
8452 && class == ALTIVEC_REGS)
8453 return NO_REGS;
8454
9878760c
RK
8455 /* We can copy among the CR registers. */
8456 if ((class == CR_REGS || class == CR0_REGS)
8457 && regno >= 0 && CR_REGNO_P (regno))
8458 return NO_REGS;
8459
8460 /* Otherwise, we need GENERAL_REGS. */
8461 return GENERAL_REGS;
8462}
8463\f
8464/* Given a comparison operation, return the bit number in CCR to test. We
8465 know this is a valid comparison.
8466
8467 SCC_P is 1 if this is for an scc. That means that %D will have been
8468 used instead of %C, so the bits will be in different places.
8469
b4ac57ab 8470 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
8471
8472int
a2369ed3 8473ccr_bit (rtx op, int scc_p)
9878760c
RK
8474{
8475 enum rtx_code code = GET_CODE (op);
8476 enum machine_mode cc_mode;
8477 int cc_regnum;
8478 int base_bit;
9ebbca7d 8479 rtx reg;
9878760c
RK
8480
8481 if (GET_RTX_CLASS (code) != '<')
8482 return -1;
8483
9ebbca7d
GK
8484 reg = XEXP (op, 0);
8485
8486 if (GET_CODE (reg) != REG
8487 || ! CR_REGNO_P (REGNO (reg)))
8488 abort ();
8489
8490 cc_mode = GET_MODE (reg);
8491 cc_regnum = REGNO (reg);
8492 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 8493
39a10a29 8494 validate_condition_mode (code, cc_mode);
c5defebb 8495
b7053a3f
GK
8496 /* When generating a sCOND operation, only positive conditions are
8497 allowed. */
8498 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
8499 && code != GTU && code != LTU)
8500 abort ();
8501
9878760c
RK
8502 switch (code)
8503 {
8504 case NE:
993f19a8
AH
8505 if (TARGET_E500 && !TARGET_FPRS
8506 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8507 return base_bit + 1;
9878760c
RK
8508 return scc_p ? base_bit + 3 : base_bit + 2;
8509 case EQ:
993f19a8
AH
8510 if (TARGET_E500 && !TARGET_FPRS
8511 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8512 return base_bit + 1;
9878760c 8513 return base_bit + 2;
1c882ea4 8514 case GT: case GTU: case UNLE:
9878760c 8515 return base_bit + 1;
1c882ea4 8516 case LT: case LTU: case UNGE:
9878760c 8517 return base_bit;
1c882ea4
GK
8518 case ORDERED: case UNORDERED:
8519 return base_bit + 3;
9878760c
RK
8520
8521 case GE: case GEU:
39a10a29 8522 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
8523 unordered position. So test that bit. For integer, this is ! LT
8524 unless this is an scc insn. */
39a10a29 8525 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
8526
8527 case LE: case LEU:
39a10a29 8528 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 8529
9878760c
RK
8530 default:
8531 abort ();
8532 }
8533}
1ff7789b 8534\f
8d30c4ee 8535/* Return the GOT register. */
1ff7789b
MM
8536
8537struct rtx_def *
a2369ed3 8538rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 8539{
a4f6c312
SS
8540 /* The second flow pass currently (June 1999) can't update
8541 regs_ever_live without disturbing other parts of the compiler, so
8542 update it here to make the prolog/epilogue code happy. */
1db02437
FS
8543 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
8544 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 8545
8d30c4ee 8546 current_function_uses_pic_offset_table = 1;
3cb999d8 8547
1ff7789b
MM
8548 return pic_offset_table_rtx;
8549}
a7df97e6 8550\f
e2500fed
GK
8551/* Function to init struct machine_function.
8552 This will be called, via a pointer variable,
8553 from push_function_context. */
a7df97e6 8554
e2500fed 8555static struct machine_function *
863d938c 8556rs6000_init_machine_status (void)
a7df97e6 8557{
e2500fed 8558 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 8559}
9878760c 8560\f
0ba1b2ff
AM
8561/* These macros test for integers and extract the low-order bits. */
8562#define INT_P(X) \
8563((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
8564 && GET_MODE (X) == VOIDmode)
8565
8566#define INT_LOWPART(X) \
8567 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
8568
8569int
a2369ed3 8570extract_MB (rtx op)
0ba1b2ff
AM
8571{
8572 int i;
8573 unsigned long val = INT_LOWPART (op);
8574
8575 /* If the high bit is zero, the value is the first 1 bit we find
8576 from the left. */
8577 if ((val & 0x80000000) == 0)
8578 {
8579 if ((val & 0xffffffff) == 0)
8580 abort ();
8581
8582 i = 1;
8583 while (((val <<= 1) & 0x80000000) == 0)
8584 ++i;
8585 return i;
8586 }
8587
8588 /* If the high bit is set and the low bit is not, or the mask is all
8589 1's, the value is zero. */
8590 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
8591 return 0;
8592
8593 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8594 from the right. */
8595 i = 31;
8596 while (((val >>= 1) & 1) != 0)
8597 --i;
8598
8599 return i;
8600}
8601
8602int
a2369ed3 8603extract_ME (rtx op)
0ba1b2ff
AM
8604{
8605 int i;
8606 unsigned long val = INT_LOWPART (op);
8607
8608 /* If the low bit is zero, the value is the first 1 bit we find from
8609 the right. */
8610 if ((val & 1) == 0)
8611 {
8612 if ((val & 0xffffffff) == 0)
8613 abort ();
8614
8615 i = 30;
8616 while (((val >>= 1) & 1) == 0)
8617 --i;
8618
8619 return i;
8620 }
8621
8622 /* If the low bit is set and the high bit is not, or the mask is all
8623 1's, the value is 31. */
8624 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
8625 return 31;
8626
8627 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8628 from the left. */
8629 i = 0;
8630 while (((val <<= 1) & 0x80000000) != 0)
8631 ++i;
8632
8633 return i;
8634}
8635
c4501e62
JJ
8636/* Locate some local-dynamic symbol still in use by this function
8637 so that we can print its name in some tls_ld pattern. */
8638
8639static const char *
863d938c 8640rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
8641{
8642 rtx insn;
8643
8644 if (cfun->machine->some_ld_name)
8645 return cfun->machine->some_ld_name;
8646
8647 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8648 if (INSN_P (insn)
8649 && for_each_rtx (&PATTERN (insn),
8650 rs6000_get_some_local_dynamic_name_1, 0))
8651 return cfun->machine->some_ld_name;
8652
8653 abort ();
8654}
8655
8656/* Helper function for rs6000_get_some_local_dynamic_name. */
8657
8658static int
a2369ed3 8659rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
8660{
8661 rtx x = *px;
8662
8663 if (GET_CODE (x) == SYMBOL_REF)
8664 {
8665 const char *str = XSTR (x, 0);
8666 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8667 {
8668 cfun->machine->some_ld_name = str;
8669 return 1;
8670 }
8671 }
8672
8673 return 0;
8674}
8675
9878760c
RK
8676/* Print an operand. Recognize special options, documented below. */
8677
38c1f2d7 8678#if TARGET_ELF
d9407988 8679#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 8680#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
8681#else
8682#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 8683#define SMALL_DATA_REG 0
ba5e43aa
MM
8684#endif
8685
9878760c 8686void
a2369ed3 8687print_operand (FILE *file, rtx x, int code)
9878760c
RK
8688{
8689 int i;
a260abc9 8690 HOST_WIDE_INT val;
0ba1b2ff 8691 unsigned HOST_WIDE_INT uval;
9878760c
RK
8692
8693 switch (code)
8694 {
a8b3aeda 8695 case '.':
a85d226b
RK
8696 /* Write out an instruction after the call which may be replaced
8697 with glue code by the loader. This depends on the AIX version. */
8698 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
8699 return;
8700
81eace42
GK
8701 /* %a is output_address. */
8702
9854d9ed
RK
8703 case 'A':
8704 /* If X is a constant integer whose low-order 5 bits are zero,
8705 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 8706 in the AIX assembler where "sri" with a zero shift count
20e26713 8707 writes a trash instruction. */
9854d9ed 8708 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 8709 putc ('l', file);
9854d9ed 8710 else
76229ac8 8711 putc ('r', file);
9854d9ed
RK
8712 return;
8713
8714 case 'b':
e2c953b6
DE
8715 /* If constant, low-order 16 bits of constant, unsigned.
8716 Otherwise, write normally. */
8717 if (INT_P (x))
8718 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
8719 else
8720 print_operand (file, x, 0);
cad12a8d
RK
8721 return;
8722
a260abc9
DE
8723 case 'B':
8724 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
8725 for 64-bit mask direction. */
296b8152 8726 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 8727 return;
a260abc9 8728
81eace42
GK
8729 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
8730 output_operand. */
8731
9854d9ed 8732 case 'E':
39a10a29 8733 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
8734 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8735 output_operand_lossage ("invalid %%E value");
78fbdbf7 8736 else
39a10a29 8737 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 8738 return;
9854d9ed
RK
8739
8740 case 'f':
8741 /* X is a CR register. Print the shift count needed to move it
8742 to the high-order four bits. */
8743 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8744 output_operand_lossage ("invalid %%f value");
8745 else
9ebbca7d 8746 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8747 return;
8748
8749 case 'F':
8750 /* Similar, but print the count for the rotate in the opposite
8751 direction. */
8752 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8753 output_operand_lossage ("invalid %%F value");
8754 else
9ebbca7d 8755 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8756 return;
8757
8758 case 'G':
8759 /* X is a constant integer. If it is negative, print "m",
43aa4e05 8760 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
8761 if (GET_CODE (x) != CONST_INT)
8762 output_operand_lossage ("invalid %%G value");
8763 else if (INTVAL (x) >= 0)
76229ac8 8764 putc ('z', file);
9854d9ed 8765 else
76229ac8 8766 putc ('m', file);
9854d9ed 8767 return;
e2c953b6 8768
9878760c 8769 case 'h':
a4f6c312
SS
8770 /* If constant, output low-order five bits. Otherwise, write
8771 normally. */
9878760c 8772 if (INT_P (x))
5f59ecb7 8773 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
8774 else
8775 print_operand (file, x, 0);
8776 return;
8777
64305719 8778 case 'H':
a4f6c312
SS
8779 /* If constant, output low-order six bits. Otherwise, write
8780 normally. */
64305719 8781 if (INT_P (x))
5f59ecb7 8782 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
8783 else
8784 print_operand (file, x, 0);
8785 return;
8786
9854d9ed
RK
8787 case 'I':
8788 /* Print `i' if this is a constant, else nothing. */
9878760c 8789 if (INT_P (x))
76229ac8 8790 putc ('i', file);
9878760c
RK
8791 return;
8792
9854d9ed
RK
8793 case 'j':
8794 /* Write the bit number in CCR for jump. */
8795 i = ccr_bit (x, 0);
8796 if (i == -1)
8797 output_operand_lossage ("invalid %%j code");
9878760c 8798 else
9854d9ed 8799 fprintf (file, "%d", i);
9878760c
RK
8800 return;
8801
9854d9ed
RK
8802 case 'J':
8803 /* Similar, but add one for shift count in rlinm for scc and pass
8804 scc flag to `ccr_bit'. */
8805 i = ccr_bit (x, 1);
8806 if (i == -1)
8807 output_operand_lossage ("invalid %%J code");
8808 else
a0466a68
RK
8809 /* If we want bit 31, write a shift count of zero, not 32. */
8810 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
8811 return;
8812
9854d9ed
RK
8813 case 'k':
8814 /* X must be a constant. Write the 1's complement of the
8815 constant. */
9878760c 8816 if (! INT_P (x))
9854d9ed 8817 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
8818 else
8819 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
8820 return;
8821
81eace42 8822 case 'K':
9ebbca7d
GK
8823 /* X must be a symbolic constant on ELF. Write an
8824 expression suitable for an 'addi' that adds in the low 16
8825 bits of the MEM. */
8826 if (GET_CODE (x) != CONST)
8827 {
8828 print_operand_address (file, x);
8829 fputs ("@l", file);
8830 }
8831 else
8832 {
8833 if (GET_CODE (XEXP (x, 0)) != PLUS
8834 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
8835 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
8836 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 8837 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
8838 print_operand_address (file, XEXP (XEXP (x, 0), 0));
8839 fputs ("@l", file);
ed8d2920
MM
8840 /* For GNU as, there must be a non-alphanumeric character
8841 between 'l' and the number. The '-' is added by
8842 print_operand() already. */
8843 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
8844 fputs ("+", file);
9ebbca7d
GK
8845 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
8846 }
81eace42
GK
8847 return;
8848
8849 /* %l is output_asm_label. */
9ebbca7d 8850
9854d9ed
RK
8851 case 'L':
8852 /* Write second word of DImode or DFmode reference. Works on register
8853 or non-indexed memory only. */
8854 if (GET_CODE (x) == REG)
5ebfb2ba 8855 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
8856 else if (GET_CODE (x) == MEM)
8857 {
8858 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 8859 we have already done it, we can just use an offset of word. */
9854d9ed
RK
8860 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8861 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
8862 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
8863 UNITS_PER_WORD));
9854d9ed 8864 else
d7624dc0
RK
8865 output_address (XEXP (adjust_address_nv (x, SImode,
8866 UNITS_PER_WORD),
8867 0));
ed8908e7 8868
ba5e43aa 8869 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8870 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8871 reg_names[SMALL_DATA_REG]);
9854d9ed 8872 }
9878760c 8873 return;
9854d9ed 8874
9878760c
RK
8875 case 'm':
8876 /* MB value for a mask operand. */
b1765bde 8877 if (! mask_operand (x, SImode))
9878760c
RK
8878 output_operand_lossage ("invalid %%m value");
8879
0ba1b2ff 8880 fprintf (file, "%d", extract_MB (x));
9878760c
RK
8881 return;
8882
8883 case 'M':
8884 /* ME value for a mask operand. */
b1765bde 8885 if (! mask_operand (x, SImode))
a260abc9 8886 output_operand_lossage ("invalid %%M value");
9878760c 8887
0ba1b2ff 8888 fprintf (file, "%d", extract_ME (x));
9878760c
RK
8889 return;
8890
81eace42
GK
8891 /* %n outputs the negative of its operand. */
8892
9878760c
RK
8893 case 'N':
8894 /* Write the number of elements in the vector times 4. */
8895 if (GET_CODE (x) != PARALLEL)
8896 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
8897 else
8898 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
8899 return;
8900
8901 case 'O':
8902 /* Similar, but subtract 1 first. */
8903 if (GET_CODE (x) != PARALLEL)
1427100a 8904 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
8905 else
8906 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
8907 return;
8908
9854d9ed
RK
8909 case 'p':
8910 /* X is a CONST_INT that is a power of two. Output the logarithm. */
8911 if (! INT_P (x)
2bfcf297 8912 || INT_LOWPART (x) < 0
9854d9ed
RK
8913 || (i = exact_log2 (INT_LOWPART (x))) < 0)
8914 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
8915 else
8916 fprintf (file, "%d", i);
9854d9ed
RK
8917 return;
8918
9878760c
RK
8919 case 'P':
8920 /* The operand must be an indirect memory reference. The result
a4f6c312 8921 is the register number. */
9878760c
RK
8922 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
8923 || REGNO (XEXP (x, 0)) >= 32)
8924 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
8925 else
8926 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
8927 return;
8928
dfbdccdb
GK
8929 case 'q':
8930 /* This outputs the logical code corresponding to a boolean
8931 expression. The expression may have one or both operands
39a10a29
GK
8932 negated (if one, only the first one). For condition register
8933 logical operations, it will also treat the negated
8934 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 8935 {
63bc1d05 8936 const char *const *t = 0;
dfbdccdb
GK
8937 const char *s;
8938 enum rtx_code code = GET_CODE (x);
8939 static const char * const tbl[3][3] = {
8940 { "and", "andc", "nor" },
8941 { "or", "orc", "nand" },
8942 { "xor", "eqv", "xor" } };
8943
8944 if (code == AND)
8945 t = tbl[0];
8946 else if (code == IOR)
8947 t = tbl[1];
8948 else if (code == XOR)
8949 t = tbl[2];
8950 else
8951 output_operand_lossage ("invalid %%q value");
8952
8953 if (GET_CODE (XEXP (x, 0)) != NOT)
8954 s = t[0];
8955 else
8956 {
8957 if (GET_CODE (XEXP (x, 1)) == NOT)
8958 s = t[2];
8959 else
8960 s = t[1];
8961 }
8962
8963 fputs (s, file);
8964 }
8965 return;
8966
2c4a9cff
DE
8967 case 'Q':
8968 if (TARGET_MFCRF)
8969 fputc (',',file);
5efb1046 8970 /* FALLTHRU */
2c4a9cff
DE
8971 else
8972 return;
8973
9854d9ed
RK
8974 case 'R':
8975 /* X is a CR register. Print the mask for `mtcrf'. */
8976 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8977 output_operand_lossage ("invalid %%R value");
8978 else
9ebbca7d 8979 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 8980 return;
9854d9ed
RK
8981
8982 case 's':
8983 /* Low 5 bits of 32 - value */
8984 if (! INT_P (x))
8985 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
8986 else
8987 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 8988 return;
9854d9ed 8989
a260abc9 8990 case 'S':
0ba1b2ff 8991 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
8992 CONST_INT 32-bit mask is considered sign-extended so any
8993 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 8994 if (! mask64_operand (x, DImode))
a260abc9
DE
8995 output_operand_lossage ("invalid %%S value");
8996
0ba1b2ff 8997 uval = INT_LOWPART (x);
a260abc9 8998
0ba1b2ff 8999 if (uval & 1) /* Clear Left */
a260abc9 9000 {
f099d360
GK
9001#if HOST_BITS_PER_WIDE_INT > 64
9002 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9003#endif
0ba1b2ff 9004 i = 64;
a260abc9 9005 }
0ba1b2ff 9006 else /* Clear Right */
a260abc9 9007 {
0ba1b2ff 9008 uval = ~uval;
f099d360
GK
9009#if HOST_BITS_PER_WIDE_INT > 64
9010 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9011#endif
0ba1b2ff 9012 i = 63;
a260abc9 9013 }
0ba1b2ff
AM
9014 while (uval != 0)
9015 --i, uval >>= 1;
9016 if (i < 0)
9017 abort ();
9018 fprintf (file, "%d", i);
9019 return;
a260abc9 9020
a3170dc6
AH
9021 case 't':
9022 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
9023 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
9024 abort ();
9025
9026 /* Bit 3 is OV bit. */
9027 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
9028
9029 /* If we want bit 31, write a shift count of zero, not 32. */
9030 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9031 return;
9032
cccf3bdc
DE
9033 case 'T':
9034 /* Print the symbolic name of a branch target register. */
9035 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
9036 && REGNO (x) != COUNT_REGISTER_REGNUM))
9037 output_operand_lossage ("invalid %%T value");
e2c953b6 9038 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
9039 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
9040 else
9041 fputs ("ctr", file);
9042 return;
9043
9854d9ed 9044 case 'u':
802a0058 9045 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
9046 if (! INT_P (x))
9047 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
9048 else
9049 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9050 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
9051 return;
9052
802a0058
MM
9053 case 'v':
9054 /* High-order 16 bits of constant for use in signed operand. */
9055 if (! INT_P (x))
9056 output_operand_lossage ("invalid %%v value");
e2c953b6 9057 else
134c32f6
DE
9058 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9059 (INT_LOWPART (x) >> 16) & 0xffff);
9060 return;
802a0058 9061
9854d9ed
RK
9062 case 'U':
9063 /* Print `u' if this has an auto-increment or auto-decrement. */
9064 if (GET_CODE (x) == MEM
9065 && (GET_CODE (XEXP (x, 0)) == PRE_INC
9066 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 9067 putc ('u', file);
9854d9ed 9068 return;
9878760c 9069
e0cd0770
JC
9070 case 'V':
9071 /* Print the trap code for this operand. */
9072 switch (GET_CODE (x))
9073 {
9074 case EQ:
9075 fputs ("eq", file); /* 4 */
9076 break;
9077 case NE:
9078 fputs ("ne", file); /* 24 */
9079 break;
9080 case LT:
9081 fputs ("lt", file); /* 16 */
9082 break;
9083 case LE:
9084 fputs ("le", file); /* 20 */
9085 break;
9086 case GT:
9087 fputs ("gt", file); /* 8 */
9088 break;
9089 case GE:
9090 fputs ("ge", file); /* 12 */
9091 break;
9092 case LTU:
9093 fputs ("llt", file); /* 2 */
9094 break;
9095 case LEU:
9096 fputs ("lle", file); /* 6 */
9097 break;
9098 case GTU:
9099 fputs ("lgt", file); /* 1 */
9100 break;
9101 case GEU:
9102 fputs ("lge", file); /* 5 */
9103 break;
9104 default:
9105 abort ();
9106 }
9107 break;
9108
9854d9ed
RK
9109 case 'w':
9110 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
9111 normally. */
9112 if (INT_P (x))
5f59ecb7
DE
9113 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
9114 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
9115 else
9116 print_operand (file, x, 0);
9878760c
RK
9117 return;
9118
9854d9ed 9119 case 'W':
e2c953b6 9120 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
9121 val = (GET_CODE (x) == CONST_INT
9122 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
9123
9124 if (val < 0)
9125 i = -1;
9854d9ed 9126 else
e2c953b6
DE
9127 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
9128 if ((val <<= 1) < 0)
9129 break;
9130
9131#if HOST_BITS_PER_WIDE_INT == 32
9132 if (GET_CODE (x) == CONST_INT && i >= 0)
9133 i += 32; /* zero-extend high-part was all 0's */
9134 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
9135 {
9136 val = CONST_DOUBLE_LOW (x);
9137
9138 if (val == 0)
a4f6c312 9139 abort ();
e2c953b6
DE
9140 else if (val < 0)
9141 --i;
9142 else
9143 for ( ; i < 64; i++)
9144 if ((val <<= 1) < 0)
9145 break;
9146 }
9147#endif
9148
9149 fprintf (file, "%d", i + 1);
9854d9ed 9150 return;
9878760c 9151
9854d9ed
RK
9152 case 'X':
9153 if (GET_CODE (x) == MEM
4d588c14 9154 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 9155 putc ('x', file);
9854d9ed 9156 return;
9878760c 9157
9854d9ed
RK
9158 case 'Y':
9159 /* Like 'L', for third word of TImode */
9160 if (GET_CODE (x) == REG)
5ebfb2ba 9161 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 9162 else if (GET_CODE (x) == MEM)
9878760c 9163 {
9854d9ed
RK
9164 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9165 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9166 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 9167 else
d7624dc0 9168 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 9169 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9170 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9171 reg_names[SMALL_DATA_REG]);
9878760c
RK
9172 }
9173 return;
9854d9ed 9174
9878760c 9175 case 'z':
b4ac57ab
RS
9176 /* X is a SYMBOL_REF. Write out the name preceded by a
9177 period and without any trailing data in brackets. Used for function
4d30c363
MM
9178 names. If we are configured for System V (or the embedded ABI) on
9179 the PowerPC, do not emit the period, since those systems do not use
9180 TOCs and the like. */
9878760c
RK
9181 if (GET_CODE (x) != SYMBOL_REF)
9182 abort ();
9183
b6c9286a
MM
9184 if (XSTR (x, 0)[0] != '.')
9185 {
9186 switch (DEFAULT_ABI)
9187 {
9188 default:
9189 abort ();
9190
9191 case ABI_AIX:
9192 putc ('.', file);
9193 break;
9194
9195 case ABI_V4:
ee890fe2 9196 case ABI_DARWIN:
b6c9286a 9197 break;
b6c9286a
MM
9198 }
9199 }
9739c90c
JJ
9200 if (TARGET_AIX)
9201 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9202 else
9203 assemble_name (file, XSTR (x, 0));
9878760c
RK
9204 return;
9205
9854d9ed
RK
9206 case 'Z':
9207 /* Like 'L', for last word of TImode. */
9208 if (GET_CODE (x) == REG)
5ebfb2ba 9209 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
9210 else if (GET_CODE (x) == MEM)
9211 {
9212 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9213 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9214 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 9215 else
d7624dc0 9216 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 9217 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9218 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9219 reg_names[SMALL_DATA_REG]);
9854d9ed 9220 }
5c23c401 9221 return;
0ac081f6 9222
a3170dc6 9223 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
9224 case 'y':
9225 {
9226 rtx tmp;
9227
9228 if (GET_CODE (x) != MEM)
9229 abort ();
9230
9231 tmp = XEXP (x, 0);
9232
993f19a8 9233 if (TARGET_E500)
a3170dc6
AH
9234 {
9235 /* Handle [reg]. */
9236 if (GET_CODE (tmp) == REG)
9237 {
9238 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
9239 break;
9240 }
9241 /* Handle [reg+UIMM]. */
9242 else if (GET_CODE (tmp) == PLUS &&
9243 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
9244 {
9245 int x;
9246
9247 if (GET_CODE (XEXP (tmp, 0)) != REG)
9248 abort ();
9249
9250 x = INTVAL (XEXP (tmp, 1));
9251 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
9252 break;
9253 }
9254
9255 /* Fall through. Must be [reg+reg]. */
9256 }
0ac081f6 9257 if (GET_CODE (tmp) == REG)
c62f2db5 9258 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
9259 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
9260 {
9261 if (REGNO (XEXP (tmp, 0)) == 0)
9262 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
9263 reg_names[ REGNO (XEXP (tmp, 0)) ]);
9264 else
9265 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
9266 reg_names[ REGNO (XEXP (tmp, 1)) ]);
9267 }
9268 else
9269 abort ();
9270 break;
9271 }
9854d9ed 9272
9878760c
RK
9273 case 0:
9274 if (GET_CODE (x) == REG)
9275 fprintf (file, "%s", reg_names[REGNO (x)]);
9276 else if (GET_CODE (x) == MEM)
9277 {
9278 /* We need to handle PRE_INC and PRE_DEC here, since we need to
9279 know the width from the mode. */
9280 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
9281 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
9282 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9283 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
9284 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
9285 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9286 else
a54d04b7 9287 output_address (XEXP (x, 0));
9878760c
RK
9288 }
9289 else
a54d04b7 9290 output_addr_const (file, x);
a85d226b 9291 return;
9878760c 9292
c4501e62
JJ
9293 case '&':
9294 assemble_name (file, rs6000_get_some_local_dynamic_name ());
9295 return;
9296
9878760c
RK
9297 default:
9298 output_operand_lossage ("invalid %%xn code");
9299 }
9300}
9301\f
9302/* Print the address of an operand. */
9303
9304void
a2369ed3 9305print_operand_address (FILE *file, rtx x)
9878760c
RK
9306{
9307 if (GET_CODE (x) == REG)
4697a36c 9308 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
9309 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
9310 || GET_CODE (x) == LABEL_REF)
9878760c
RK
9311 {
9312 output_addr_const (file, x);
ba5e43aa 9313 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9314 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9315 reg_names[SMALL_DATA_REG]);
9ebbca7d 9316 else if (TARGET_TOC)
a4f6c312 9317 abort ();
9878760c
RK
9318 }
9319 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
9320 {
9321 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
9322 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
9323 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 9324 else
4697a36c
MM
9325 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
9326 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
9327 }
9328 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
9329 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
9330 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
9331#if TARGET_ELF
9332 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9333 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
9334 {
9335 output_addr_const (file, XEXP (x, 1));
9336 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9337 }
c859cda6
DJ
9338#endif
9339#if TARGET_MACHO
9340 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9341 && CONSTANT_P (XEXP (x, 1)))
9342 {
9343 fprintf (file, "lo16(");
9344 output_addr_const (file, XEXP (x, 1));
9345 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9346 }
3cb999d8 9347#endif
4d588c14 9348 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 9349 {
2bfcf297 9350 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 9351 {
2bfcf297
DB
9352 rtx contains_minus = XEXP (x, 1);
9353 rtx minus, symref;
9354 const char *name;
9ebbca7d
GK
9355
9356 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 9357 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
9358 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
9359 contains_minus = XEXP (contains_minus, 0);
9360
2bfcf297
DB
9361 minus = XEXP (contains_minus, 0);
9362 symref = XEXP (minus, 0);
9363 XEXP (contains_minus, 0) = symref;
9364 if (TARGET_ELF)
9365 {
9366 char *newname;
9367
9368 name = XSTR (symref, 0);
9369 newname = alloca (strlen (name) + sizeof ("@toc"));
9370 strcpy (newname, name);
9371 strcat (newname, "@toc");
9372 XSTR (symref, 0) = newname;
9373 }
9374 output_addr_const (file, XEXP (x, 1));
9375 if (TARGET_ELF)
9376 XSTR (symref, 0) = name;
9ebbca7d
GK
9377 XEXP (contains_minus, 0) = minus;
9378 }
9379 else
9380 output_addr_const (file, XEXP (x, 1));
9381
9382 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9383 }
9878760c
RK
9384 else
9385 abort ();
9386}
9387\f
88cad84b 9388/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9389 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9390 is defined. It also needs to handle DI-mode objects on 64-bit
9391 targets. */
9392
9393static bool
a2369ed3 9394rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
9395{
9396#ifdef RELOCATABLE_NEEDS_FIXUP
9397 /* Special handling for SI values. */
9398 if (size == 4 && aligned_p)
9399 {
a2369ed3 9400 extern int in_toc_section (void);
301d03af
RS
9401 static int recurse = 0;
9402
9403 /* For -mrelocatable, we mark all addresses that need to be fixed up
9404 in the .fixup section. */
9405 if (TARGET_RELOCATABLE
9406 && !in_toc_section ()
9407 && !in_text_section ()
9408 && !recurse
9409 && GET_CODE (x) != CONST_INT
9410 && GET_CODE (x) != CONST_DOUBLE
9411 && CONSTANT_P (x))
9412 {
9413 char buf[256];
9414
9415 recurse = 1;
9416 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9417 fixuplabelno++;
9418 ASM_OUTPUT_LABEL (asm_out_file, buf);
9419 fprintf (asm_out_file, "\t.long\t(");
9420 output_addr_const (asm_out_file, x);
9421 fprintf (asm_out_file, ")@fixup\n");
9422 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9423 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9424 fprintf (asm_out_file, "\t.long\t");
9425 assemble_name (asm_out_file, buf);
9426 fprintf (asm_out_file, "\n\t.previous\n");
9427 recurse = 0;
9428 return true;
9429 }
9430 /* Remove initial .'s to turn a -mcall-aixdesc function
9431 address into the address of the descriptor, not the function
9432 itself. */
9433 else if (GET_CODE (x) == SYMBOL_REF
9434 && XSTR (x, 0)[0] == '.'
9435 && DEFAULT_ABI == ABI_AIX)
9436 {
9437 const char *name = XSTR (x, 0);
9438 while (*name == '.')
9439 name++;
9440
9441 fprintf (asm_out_file, "\t.long\t%s\n", name);
9442 return true;
9443 }
9444 }
9445#endif /* RELOCATABLE_NEEDS_FIXUP */
9446 return default_assemble_integer (x, size, aligned_p);
9447}
93638d7a
AM
9448
9449#ifdef HAVE_GAS_HIDDEN
9450/* Emit an assembler directive to set symbol visibility for DECL to
9451 VISIBILITY_TYPE. */
9452
5add3202 9453static void
a2369ed3 9454rs6000_assemble_visibility (tree decl, int vis)
93638d7a 9455{
93638d7a
AM
9456 /* Functions need to have their entry point symbol visibility set as
9457 well as their descriptor symbol visibility. */
9458 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9459 {
25fdb4dc
RH
9460 static const char * const visibility_types[] = {
9461 NULL, "internal", "hidden", "protected"
9462 };
9463
9464 const char *name, *type;
93638d7a
AM
9465
9466 name = ((* targetm.strip_name_encoding)
9467 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9468 type = visibility_types[vis];
93638d7a 9469
25fdb4dc
RH
9470 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9471 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9472 }
25fdb4dc
RH
9473 else
9474 default_assemble_visibility (decl, vis);
93638d7a
AM
9475}
9476#endif
301d03af 9477\f
39a10a29 9478enum rtx_code
a2369ed3 9479rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
9480{
9481 /* Reversal of FP compares takes care -- an ordered compare
9482 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9483 if (mode == CCFPmode
9484 && (!flag_finite_math_only
9485 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
9486 || code == UNEQ || code == LTGT))
bab6226b 9487 return reverse_condition_maybe_unordered (code);
39a10a29 9488 else
bab6226b 9489 return reverse_condition (code);
39a10a29
GK
9490}
9491
39a10a29
GK
9492/* Generate a compare for CODE. Return a brand-new rtx that
9493 represents the result of the compare. */
a4f6c312 9494
39a10a29 9495static rtx
a2369ed3 9496rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
9497{
9498 enum machine_mode comp_mode;
9499 rtx compare_result;
9500
9501 if (rs6000_compare_fp_p)
9502 comp_mode = CCFPmode;
9503 else if (code == GTU || code == LTU
9504 || code == GEU || code == LEU)
9505 comp_mode = CCUNSmode;
9506 else
9507 comp_mode = CCmode;
9508
9509 /* First, the compare. */
9510 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
9511
9512 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
9513 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
9514 && rs6000_compare_fp_p)
a3170dc6
AH
9515 {
9516 rtx cmp, or1, or2, or_result, compare_result2;
9517
9518 switch (code)
9519 {
9520 case EQ:
9521 case UNEQ:
9522 case NE:
9523 case LTGT:
bc9ec0e0 9524 cmp = flag_finite_math_only
a3170dc6
AH
9525 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
9526 rs6000_compare_op1)
9527 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
9528 rs6000_compare_op1);
9529 break;
9530 case GT:
9531 case GTU:
9532 case UNGT:
9533 case UNGE:
9534 case GE:
9535 case GEU:
bc9ec0e0 9536 cmp = flag_finite_math_only
a3170dc6
AH
9537 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
9538 rs6000_compare_op1)
9539 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
9540 rs6000_compare_op1);
9541 break;
9542 case LT:
9543 case LTU:
9544 case UNLT:
9545 case UNLE:
9546 case LE:
9547 case LEU:
bc9ec0e0 9548 cmp = flag_finite_math_only
a3170dc6
AH
9549 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
9550 rs6000_compare_op1)
9551 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
9552 rs6000_compare_op1);
9553 break;
9554 default:
9555 abort ();
9556 }
9557
9558 /* Synthesize LE and GE from LT/GT || EQ. */
9559 if (code == LE || code == GE || code == LEU || code == GEU)
9560 {
9561 /* Synthesize GE/LE frome GT/LT || EQ. */
9562
9563 emit_insn (cmp);
9564
9565 switch (code)
9566 {
9567 case LE: code = LT; break;
9568 case GE: code = GT; break;
9569 case LEU: code = LT; break;
9570 case GEU: code = GT; break;
9571 default: abort ();
9572 }
9573
9574 or1 = gen_reg_rtx (SImode);
9575 or2 = gen_reg_rtx (SImode);
9576 or_result = gen_reg_rtx (CCEQmode);
9577 compare_result2 = gen_reg_rtx (CCFPmode);
9578
9579 /* Do the EQ. */
bc9ec0e0 9580 cmp = flag_finite_math_only
a3170dc6
AH
9581 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
9582 rs6000_compare_op1)
9583 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
9584 rs6000_compare_op1);
9585 emit_insn (cmp);
9586
9587 /* The MC8540 FP compare instructions set the CR bits
9588 differently than other PPC compare instructions. For
9589 that matter, there is no generic test instruction, but a
9590 testgt, testlt, and testeq. For a true condition, bit 2
9591 is set (x1xx) in the CR. Following the traditional CR
9592 values:
9593
9594 LT GT EQ OV
9595 bit3 bit2 bit1 bit0
9596
9597 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 9598 look in the GT bits for the branch instructions.
a3170dc6
AH
9599 However, we must be careful to emit correct RTL in
9600 the meantime, so optimizations don't get confused. */
9601
f1c25d3b
KH
9602 or1 = gen_rtx_NE (SImode, compare_result, const0_rtx);
9603 or2 = gen_rtx_NE (SImode, compare_result2, const0_rtx);
a3170dc6
AH
9604
9605 /* OR them together. */
9606 cmp = gen_rtx_SET (VOIDmode, or_result,
9607 gen_rtx_COMPARE (CCEQmode,
9608 gen_rtx_IOR (SImode, or1, or2),
9609 const_true_rtx));
9610 compare_result = or_result;
9611 code = EQ;
9612 }
9613 else
9614 {
9615 /* We only care about 1 bit (x1xx), so map everything to NE to
9616 maintain rtl sanity. We'll get to the right bit (x1xx) at
9617 code output time. */
9618 if (code == NE || code == LTGT)
9619 /* Do the inverse here because we have no cmpne
9620 instruction. We use the cmpeq instruction and expect
9621 to get a 0 instead. */
9622 code = EQ;
9623 else
9624 code = NE;
9625 }
9626
9627 emit_insn (cmp);
9628 }
9629 else
9630 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
9631 gen_rtx_COMPARE (comp_mode,
9632 rs6000_compare_op0,
9633 rs6000_compare_op1)));
39a10a29 9634
ca5adc63 9635 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 9636 under flag_finite_math_only we don't bother. */
39a10a29 9637 if (rs6000_compare_fp_p
bc9ec0e0 9638 && ! flag_finite_math_only
993f19a8 9639 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
9640 && (code == LE || code == GE
9641 || code == UNEQ || code == LTGT
9642 || code == UNGT || code == UNLT))
9643 {
9644 enum rtx_code or1, or2;
9645 rtx or1_rtx, or2_rtx, compare2_rtx;
9646 rtx or_result = gen_reg_rtx (CCEQmode);
9647
9648 switch (code)
9649 {
9650 case LE: or1 = LT; or2 = EQ; break;
9651 case GE: or1 = GT; or2 = EQ; break;
9652 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
9653 case LTGT: or1 = LT; or2 = GT; break;
9654 case UNGT: or1 = UNORDERED; or2 = GT; break;
9655 case UNLT: or1 = UNORDERED; or2 = LT; break;
9656 default: abort ();
9657 }
9658 validate_condition_mode (or1, comp_mode);
9659 validate_condition_mode (or2, comp_mode);
1c563bed
KH
9660 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
9661 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
9662 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
9663 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
9664 const_true_rtx);
9665 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
9666
9667 compare_result = or_result;
9668 code = EQ;
9669 }
9670
9671 validate_condition_mode (code, GET_MODE (compare_result));
9672
1c563bed 9673 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
9674}
9675
9676
9677/* Emit the RTL for an sCOND pattern. */
9678
9679void
a2369ed3 9680rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
9681{
9682 rtx condition_rtx;
9683 enum machine_mode op_mode;
b7053a3f 9684 enum rtx_code cond_code;
39a10a29
GK
9685
9686 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
9687 cond_code = GET_CODE (condition_rtx);
9688
9689 if (cond_code == NE
9690 || cond_code == GE || cond_code == LE
9691 || cond_code == GEU || cond_code == LEU
9692 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
9693 {
9694 rtx not_result = gen_reg_rtx (CCEQmode);
9695 rtx not_op, rev_cond_rtx;
9696 enum machine_mode cc_mode;
9697
9698 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
9699
1c563bed 9700 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 9701 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
9702 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
9703 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
9704 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
9705 }
39a10a29
GK
9706
9707 op_mode = GET_MODE (rs6000_compare_op0);
9708 if (op_mode == VOIDmode)
9709 op_mode = GET_MODE (rs6000_compare_op1);
9710
9711 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
9712 {
9713 PUT_MODE (condition_rtx, DImode);
9714 convert_move (result, condition_rtx, 0);
9715 }
9716 else
9717 {
9718 PUT_MODE (condition_rtx, SImode);
9719 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
9720 }
9721}
9722
39a10a29
GK
9723/* Emit a branch of kind CODE to location LOC. */
9724
9725void
a2369ed3 9726rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
9727{
9728 rtx condition_rtx, loc_ref;
9729
9730 condition_rtx = rs6000_generate_compare (code);
9731 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
9732 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
9733 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
9734 loc_ref, pc_rtx)));
9735}
9736
12a4e8c5
GK
9737/* Return the string to output a conditional branch to LABEL, which is
9738 the operand number of the label, or -1 if the branch is really a
9739 conditional return.
9740
9741 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
9742 condition code register and its mode specifies what kind of
9743 comparison we made.
9744
a0ab749a 9745 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
9746
9747 INSN is the insn. */
9748
9749char *
a2369ed3 9750output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
9751{
9752 static char string[64];
9753 enum rtx_code code = GET_CODE (op);
9754 rtx cc_reg = XEXP (op, 0);
9755 enum machine_mode mode = GET_MODE (cc_reg);
9756 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 9757 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
9758 int really_reversed = reversed ^ need_longbranch;
9759 char *s = string;
9760 const char *ccode;
9761 const char *pred;
9762 rtx note;
9763
39a10a29
GK
9764 validate_condition_mode (code, mode);
9765
9766 /* Work out which way this really branches. We could use
9767 reverse_condition_maybe_unordered here always but this
9768 makes the resulting assembler clearer. */
12a4e8c5 9769 if (really_reversed)
de40e1df
DJ
9770 {
9771 /* Reversal of FP compares takes care -- an ordered compare
9772 becomes an unordered compare and vice versa. */
9773 if (mode == CCFPmode)
9774 code = reverse_condition_maybe_unordered (code);
9775 else
9776 code = reverse_condition (code);
9777 }
12a4e8c5 9778
993f19a8 9779 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
9780 {
9781 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
9782 to the GT bit. */
9783 if (code == EQ)
9784 /* Opposite of GT. */
9785 code = UNLE;
9786 else if (code == NE)
9787 code = GT;
9788 else
9789 abort ();
9790 }
9791
39a10a29 9792 switch (code)
12a4e8c5
GK
9793 {
9794 /* Not all of these are actually distinct opcodes, but
9795 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
9796 case NE: case LTGT:
9797 ccode = "ne"; break;
9798 case EQ: case UNEQ:
9799 ccode = "eq"; break;
9800 case GE: case GEU:
9801 ccode = "ge"; break;
9802 case GT: case GTU: case UNGT:
9803 ccode = "gt"; break;
9804 case LE: case LEU:
9805 ccode = "le"; break;
9806 case LT: case LTU: case UNLT:
9807 ccode = "lt"; break;
12a4e8c5
GK
9808 case UNORDERED: ccode = "un"; break;
9809 case ORDERED: ccode = "nu"; break;
9810 case UNGE: ccode = "nl"; break;
9811 case UNLE: ccode = "ng"; break;
9812 default:
a4f6c312 9813 abort ();
12a4e8c5
GK
9814 }
9815
94a54f47
GK
9816 /* Maybe we have a guess as to how likely the branch is.
9817 The old mnemonics don't have a way to specify this information. */
f4857b9b 9818 pred = "";
12a4e8c5
GK
9819 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
9820 if (note != NULL_RTX)
9821 {
9822 /* PROB is the difference from 50%. */
9823 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
9824 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
9825
9826 /* Only hint for highly probable/improbable branches on newer
9827 cpus as static prediction overrides processor dynamic
9828 prediction. For older cpus we may as well always hint, but
9829 assume not taken for branches that are very close to 50% as a
9830 mispredicted taken branch is more expensive than a
9831 mispredicted not-taken branch. */
9832 if (always_hint
9833 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
9834 {
9835 if (abs (prob) > REG_BR_PROB_BASE / 20
9836 && ((prob > 0) ^ need_longbranch))
7f3d8013 9837 pred = "+";
f4857b9b
AM
9838 else
9839 pred = "-";
9840 }
12a4e8c5 9841 }
12a4e8c5
GK
9842
9843 if (label == NULL)
94a54f47 9844 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 9845 else
94a54f47 9846 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 9847
37c67319 9848 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 9849 Assume they'd only be the first character.... */
37c67319
GK
9850 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
9851 *s++ = '%';
94a54f47 9852 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
9853
9854 if (label != NULL)
9855 {
9856 /* If the branch distance was too far, we may have to use an
9857 unconditional branch to go the distance. */
9858 if (need_longbranch)
44518ddd 9859 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
9860 else
9861 s += sprintf (s, ",%s", label);
9862 }
9863
9864 return string;
9865}
50a0b056
GK
9866
9867/* Emit a conditional move: move TRUE_COND to DEST if OP of the
9868 operands of the last comparison is nonzero/true, FALSE_COND if it
9869 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 9870
50a0b056 9871int
a2369ed3 9872rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
9873{
9874 enum rtx_code code = GET_CODE (op);
9875 rtx op0 = rs6000_compare_op0;
9876 rtx op1 = rs6000_compare_op1;
9877 REAL_VALUE_TYPE c1;
3148ad6d
DJ
9878 enum machine_mode compare_mode = GET_MODE (op0);
9879 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
9880 rtx temp;
9881
a3c9585f 9882 /* These modes should always match. */
a3170dc6
AH
9883 if (GET_MODE (op1) != compare_mode
9884 /* In the isel case however, we can use a compare immediate, so
9885 op1 may be a small constant. */
9886 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 9887 return 0;
178c3eff 9888 if (GET_MODE (true_cond) != result_mode)
3148ad6d 9889 return 0;
178c3eff 9890 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
9891 return 0;
9892
50a0b056 9893 /* First, work out if the hardware can do this at all, or
a3c9585f 9894 if it's too slow.... */
50a0b056 9895 if (! rs6000_compare_fp_p)
a3170dc6
AH
9896 {
9897 if (TARGET_ISEL)
9898 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
9899 return 0;
9900 }
50a0b056
GK
9901
9902 /* Eliminate half of the comparisons by switching operands, this
9903 makes the remaining code simpler. */
9904 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 9905 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
9906 {
9907 code = reverse_condition_maybe_unordered (code);
9908 temp = true_cond;
9909 true_cond = false_cond;
9910 false_cond = temp;
9911 }
9912
9913 /* UNEQ and LTGT take four instructions for a comparison with zero,
9914 it'll probably be faster to use a branch here too. */
bc9ec0e0 9915 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
9916 return 0;
9917
9918 if (GET_CODE (op1) == CONST_DOUBLE)
9919 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
9920
b6d08ca1 9921 /* We're going to try to implement comparisons by performing
50a0b056
GK
9922 a subtract, then comparing against zero. Unfortunately,
9923 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 9924 know that the operand is finite and the comparison
50a0b056 9925 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 9926 if (HONOR_INFINITIES (compare_mode)
50a0b056 9927 && code != GT && code != UNGE
045572c7 9928 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
9929 /* Constructs of the form (a OP b ? a : b) are safe. */
9930 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
9931 || (! rtx_equal_p (op0, true_cond)
9932 && ! rtx_equal_p (op1, true_cond))))
9933 return 0;
9934 /* At this point we know we can use fsel. */
9935
9936 /* Reduce the comparison to a comparison against zero. */
3148ad6d 9937 temp = gen_reg_rtx (compare_mode);
50a0b056 9938 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9939 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 9940 op0 = temp;
3148ad6d 9941 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
9942
9943 /* If we don't care about NaNs we can reduce some of the comparisons
9944 down to faster ones. */
bc9ec0e0 9945 if (! HONOR_NANS (compare_mode))
50a0b056
GK
9946 switch (code)
9947 {
9948 case GT:
9949 code = LE;
9950 temp = true_cond;
9951 true_cond = false_cond;
9952 false_cond = temp;
9953 break;
9954 case UNGE:
9955 code = GE;
9956 break;
9957 case UNEQ:
9958 code = EQ;
9959 break;
9960 default:
9961 break;
9962 }
9963
9964 /* Now, reduce everything down to a GE. */
9965 switch (code)
9966 {
9967 case GE:
9968 break;
9969
9970 case LE:
3148ad6d
DJ
9971 temp = gen_reg_rtx (compare_mode);
9972 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9973 op0 = temp;
9974 break;
9975
9976 case ORDERED:
3148ad6d
DJ
9977 temp = gen_reg_rtx (compare_mode);
9978 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
9979 op0 = temp;
9980 break;
9981
9982 case EQ:
3148ad6d 9983 temp = gen_reg_rtx (compare_mode);
50a0b056 9984 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
9985 gen_rtx_NEG (compare_mode,
9986 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
9987 op0 = temp;
9988 break;
9989
9990 case UNGE:
bc9ec0e0 9991 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 9992 temp = gen_reg_rtx (result_mode);
50a0b056 9993 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9994 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
9995 gen_rtx_GE (VOIDmode,
9996 op0, op1),
9997 true_cond, false_cond)));
bc9ec0e0
GK
9998 false_cond = true_cond;
9999 true_cond = temp;
50a0b056 10000
3148ad6d
DJ
10001 temp = gen_reg_rtx (compare_mode);
10002 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10003 op0 = temp;
10004 break;
10005
10006 case GT:
bc9ec0e0 10007 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 10008 temp = gen_reg_rtx (result_mode);
50a0b056 10009 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10010 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10011 gen_rtx_GE (VOIDmode,
10012 op0, op1),
10013 true_cond, false_cond)));
bc9ec0e0
GK
10014 true_cond = false_cond;
10015 false_cond = temp;
50a0b056 10016
3148ad6d
DJ
10017 temp = gen_reg_rtx (compare_mode);
10018 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10019 op0 = temp;
10020 break;
10021
10022 default:
10023 abort ();
10024 }
10025
10026 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 10027 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10028 gen_rtx_GE (VOIDmode,
10029 op0, op1),
10030 true_cond, false_cond)));
10031 return 1;
10032}
10033
a3170dc6
AH
10034/* Same as above, but for ints (isel). */
10035
10036static int
a2369ed3 10037rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
10038{
10039 rtx condition_rtx, cr;
10040
10041 /* All isel implementations thus far are 32-bits. */
10042 if (GET_MODE (rs6000_compare_op0) != SImode)
10043 return 0;
10044
10045 /* We still have to do the compare, because isel doesn't do a
10046 compare, it just looks at the CRx bits set by a previous compare
10047 instruction. */
10048 condition_rtx = rs6000_generate_compare (GET_CODE (op));
10049 cr = XEXP (condition_rtx, 0);
10050
10051 if (GET_MODE (cr) == CCmode)
10052 emit_insn (gen_isel_signed (dest, condition_rtx,
10053 true_cond, false_cond, cr));
10054 else
10055 emit_insn (gen_isel_unsigned (dest, condition_rtx,
10056 true_cond, false_cond, cr));
10057
10058 return 1;
10059}
10060
10061const char *
a2369ed3 10062output_isel (rtx *operands)
a3170dc6
AH
10063{
10064 enum rtx_code code;
10065
10066 code = GET_CODE (operands[1]);
10067 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
10068 {
10069 PUT_CODE (operands[1], reverse_condition (code));
10070 return "isel %0,%3,%2,%j1";
10071 }
10072 else
10073 return "isel %0,%2,%3,%j1";
10074}
10075
50a0b056 10076void
a2369ed3 10077rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
10078{
10079 enum machine_mode mode = GET_MODE (op0);
5dc8d536 10080 enum rtx_code c;
50a0b056 10081 rtx target;
5dc8d536
AH
10082
10083 if (code == SMAX || code == SMIN)
10084 c = GE;
10085 else
10086 c = GEU;
10087
50a0b056 10088 if (code == SMAX || code == UMAX)
5dc8d536 10089 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10090 op0, op1, mode, 0);
10091 else
5dc8d536 10092 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10093 op1, op0, mode, 0);
10094 if (target == NULL_RTX)
10095 abort ();
10096 if (target != dest)
10097 emit_move_insn (dest, target);
10098}
46c07df8 10099
a9baceb1
GK
10100/* Emit instructions to move SRC to DST. Called by splitters for
10101 multi-register moves. It will emit at most one instruction for
10102 each register that is accessed; that is, it won't emit li/lis pairs
10103 (or equivalent for 64-bit code). One of SRC or DST must be a hard
10104 register. */
46c07df8 10105
46c07df8 10106void
a9baceb1 10107rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 10108{
a9baceb1
GK
10109 /* The register number of the first register being moved. */
10110 int reg;
10111 /* The mode that is to be moved. */
10112 enum machine_mode mode;
10113 /* The mode that the move is being done in, and its size. */
10114 enum machine_mode reg_mode;
10115 int reg_mode_size;
10116 /* The number of registers that will be moved. */
10117 int nregs;
10118
10119 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
10120 mode = GET_MODE (dst);
10121 nregs = HARD_REGNO_NREGS (reg, mode);
10122 if (FP_REGNO_P (reg))
10123 reg_mode = DFmode;
10124 else if (ALTIVEC_REGNO_P (reg))
10125 reg_mode = V16QImode;
10126 else
10127 reg_mode = word_mode;
10128 reg_mode_size = GET_MODE_SIZE (reg_mode);
46c07df8 10129
a9baceb1
GK
10130 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
10131 abort ();
10132
10133 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
10134 {
10135 /* Move register range backwards, if we might have destructive
10136 overlap. */
10137 int i;
10138 for (i = nregs - 1; i >= 0; i--)
10139 emit_insn (gen_rtx_SET (VOIDmode,
10140 simplify_gen_subreg (reg_mode, dst, mode,
10141 i * reg_mode_size),
10142 simplify_gen_subreg (reg_mode, src, mode,
10143 i * reg_mode_size)));
10144 }
46c07df8
HP
10145 else
10146 {
a9baceb1
GK
10147 int i;
10148 int j = -1;
10149 bool used_update = false;
46c07df8 10150
a9baceb1 10151 if (GET_CODE (src) == MEM && INT_REGNO_P (reg))
46c07df8
HP
10152 {
10153 rtx breg;
3a1f863f 10154
a9baceb1
GK
10155 if (GET_CODE (XEXP (src, 0)) == PRE_INC
10156 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
10157 {
10158 rtx delta_rtx;
a9baceb1
GK
10159 breg = XEXP (XEXP (src, 0), 0);
10160 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
10161 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
10162 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
10163 emit_insn (TARGET_32BIT
10164 ? gen_addsi3 (breg, breg, delta_rtx)
10165 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10166 src = gen_rtx_MEM (mode, breg);
10167 }
10168
10169 /* We have now address involving an base register only.
10170 If we use one of the registers to address memory,
10171 we have change that register last. */
10172
10173 breg = (GET_CODE (XEXP (src, 0)) == PLUS
10174 ? XEXP (XEXP (src, 0), 0)
10175 : XEXP (src, 0));
10176
10177 if (!REG_P (breg))
10178 abort();
10179
10180 if (REGNO (breg) >= REGNO (dst)
10181 && REGNO (breg) < REGNO (dst) + nregs)
10182 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
10183 }
10184
a9baceb1 10185 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
10186 {
10187 rtx breg;
10188
a9baceb1
GK
10189 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
10190 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
10191 {
10192 rtx delta_rtx;
a9baceb1
GK
10193 breg = XEXP (XEXP (dst, 0), 0);
10194 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
10195 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
10196 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
10197
10198 /* We have to update the breg before doing the store.
10199 Use store with update, if available. */
10200
10201 if (TARGET_UPDATE)
10202 {
a9baceb1
GK
10203 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
10204 emit_insn (TARGET_32BIT
10205 ? gen_movsi_update (breg, breg, delta_rtx, nsrc)
10206 : gen_movdi_update (breg, breg, delta_rtx, nsrc));
10207 used_update = true;
3a1f863f
DE
10208 }
10209 else
a9baceb1
GK
10210 emit_insn (TARGET_32BIT
10211 ? gen_addsi3 (breg, breg, delta_rtx)
10212 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10213 dst = gen_rtx_MEM (mode, breg);
10214 }
10215 }
10216
46c07df8 10217 for (i = 0; i < nregs; i++)
3a1f863f
DE
10218 {
10219 /* Calculate index to next subword. */
10220 ++j;
10221 if (j == nregs)
10222 j = 0;
46c07df8 10223
a9baceb1
GK
10224 /* If compiler already emited move of first word by
10225 store with update, no need to do anything. */
3a1f863f 10226 if (j == 0 && used_update)
a9baceb1
GK
10227 continue;
10228
10229 emit_insn (gen_rtx_SET (VOIDmode,
10230 simplify_gen_subreg (reg_mode, dst, mode,
10231 j * reg_mode_size),
10232 simplify_gen_subreg (reg_mode, src, mode,
10233 j * reg_mode_size)));
3a1f863f 10234 }
46c07df8
HP
10235 }
10236}
10237
12a4e8c5 10238\f
a4f6c312
SS
10239/* This page contains routines that are used to determine what the
10240 function prologue and epilogue code will do and write them out. */
9878760c 10241
a4f6c312
SS
10242/* Return the first fixed-point register that is required to be
10243 saved. 32 if none. */
9878760c
RK
10244
10245int
863d938c 10246first_reg_to_save (void)
9878760c
RK
10247{
10248 int first_reg;
10249
10250 /* Find lowest numbered live register. */
10251 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
10252 if (regs_ever_live[first_reg]
10253 && (! call_used_regs[first_reg]
1db02437 10254 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10255 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10256 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
10257 break;
10258
ee890fe2 10259#if TARGET_MACHO
93638d7a
AM
10260 if (flag_pic
10261 && current_function_uses_pic_offset_table
10262 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 10263 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
10264#endif
10265
9878760c
RK
10266 return first_reg;
10267}
10268
10269/* Similar, for FP regs. */
10270
10271int
863d938c 10272first_fp_reg_to_save (void)
9878760c
RK
10273{
10274 int first_reg;
10275
10276 /* Find lowest numbered live register. */
10277 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
10278 if (regs_ever_live[first_reg])
10279 break;
10280
10281 return first_reg;
10282}
00b960c7
AH
10283
10284/* Similar, for AltiVec regs. */
10285
10286static int
863d938c 10287first_altivec_reg_to_save (void)
00b960c7
AH
10288{
10289 int i;
10290
10291 /* Stack frame remains as is unless we are in AltiVec ABI. */
10292 if (! TARGET_ALTIVEC_ABI)
10293 return LAST_ALTIVEC_REGNO + 1;
10294
10295 /* Find lowest numbered live register. */
10296 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
10297 if (regs_ever_live[i])
10298 break;
10299
10300 return i;
10301}
10302
10303/* Return a 32-bit mask of the AltiVec registers we need to set in
10304 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
10305 the 32-bit word is 0. */
10306
10307static unsigned int
863d938c 10308compute_vrsave_mask (void)
00b960c7
AH
10309{
10310 unsigned int i, mask = 0;
10311
10312 /* First, find out if we use _any_ altivec registers. */
10313 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10314 if (regs_ever_live[i])
10315 mask |= ALTIVEC_REG_BIT (i);
10316
10317 if (mask == 0)
10318 return mask;
10319
00b960c7
AH
10320 /* Next, remove the argument registers from the set. These must
10321 be in the VRSAVE mask set by the caller, so we don't need to add
10322 them in again. More importantly, the mask we compute here is
10323 used to generate CLOBBERs in the set_vrsave insn, and we do not
10324 wish the argument registers to die. */
a6cf80f2 10325 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
10326 mask &= ~ALTIVEC_REG_BIT (i);
10327
10328 /* Similarly, remove the return value from the set. */
10329 {
10330 bool yes = false;
10331 diddle_return_value (is_altivec_return_reg, &yes);
10332 if (yes)
10333 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
10334 }
10335
10336 return mask;
10337}
10338
10339static void
a2369ed3 10340is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
10341{
10342 bool *yes = (bool *) xyes;
10343 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
10344 *yes = true;
10345}
10346
4697a36c
MM
10347\f
10348/* Calculate the stack information for the current function. This is
10349 complicated by having two separate calling sequences, the AIX calling
10350 sequence and the V.4 calling sequence.
10351
592696dd 10352 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 10353 32-bit 64-bit
4697a36c 10354 SP----> +---------------------------------------+
a260abc9 10355 | back chain to caller | 0 0
4697a36c 10356 +---------------------------------------+
a260abc9 10357 | saved CR | 4 8 (8-11)
4697a36c 10358 +---------------------------------------+
a260abc9 10359 | saved LR | 8 16
4697a36c 10360 +---------------------------------------+
a260abc9 10361 | reserved for compilers | 12 24
4697a36c 10362 +---------------------------------------+
a260abc9 10363 | reserved for binders | 16 32
4697a36c 10364 +---------------------------------------+
a260abc9 10365 | saved TOC pointer | 20 40
4697a36c 10366 +---------------------------------------+
a260abc9 10367 | Parameter save area (P) | 24 48
4697a36c 10368 +---------------------------------------+
a260abc9 10369 | Alloca space (A) | 24+P etc.
802a0058 10370 +---------------------------------------+
a7df97e6 10371 | Local variable space (L) | 24+P+A
4697a36c 10372 +---------------------------------------+
a7df97e6 10373 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 10374 +---------------------------------------+
00b960c7
AH
10375 | Save area for AltiVec registers (W) | 24+P+A+L+X
10376 +---------------------------------------+
10377 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
10378 +---------------------------------------+
10379 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 10380 +---------------------------------------+
00b960c7
AH
10381 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
10382 +---------------------------------------+
10383 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
10384 +---------------------------------------+
10385 old SP->| back chain to caller's caller |
10386 +---------------------------------------+
10387
5376a30c
KR
10388 The required alignment for AIX configurations is two words (i.e., 8
10389 or 16 bytes).
10390
10391
4697a36c
MM
10392 V.4 stack frames look like:
10393
10394 SP----> +---------------------------------------+
10395 | back chain to caller | 0
10396 +---------------------------------------+
5eb387b8 10397 | caller's saved LR | 4
4697a36c
MM
10398 +---------------------------------------+
10399 | Parameter save area (P) | 8
10400 +---------------------------------------+
a7df97e6
MM
10401 | Alloca space (A) | 8+P
10402 +---------------------------------------+
10403 | Varargs save area (V) | 8+P+A
10404 +---------------------------------------+
10405 | Local variable space (L) | 8+P+A+V
10406 +---------------------------------------+
10407 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10408 +---------------------------------------+
00b960c7
AH
10409 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10410 +---------------------------------------+
10411 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10412 +---------------------------------------+
10413 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10414 +---------------------------------------+
a3170dc6
AH
10415 | SPE: area for 64-bit GP registers |
10416 +---------------------------------------+
10417 | SPE alignment padding |
10418 +---------------------------------------+
00b960c7 10419 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10420 +---------------------------------------+
00b960c7 10421 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10422 +---------------------------------------+
00b960c7 10423 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10424 +---------------------------------------+
10425 old SP->| back chain to caller's caller |
10426 +---------------------------------------+
b6c9286a 10427
5376a30c
KR
10428 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10429 given. (But note below and in sysv4.h that we require only 8 and
10430 may round up the size of our stack frame anyways. The historical
10431 reason is early versions of powerpc-linux which didn't properly
10432 align the stack at program startup. A happy side-effect is that
10433 -mno-eabi libraries can be used with -meabi programs.)
10434
50d440bc 10435 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10436 the stack alignment requirements may differ. If -mno-eabi is not
10437 given, the required stack alignment is 8 bytes; if -mno-eabi is
10438 given, the required alignment is 16 bytes. (But see V.4 comment
10439 above.) */
4697a36c 10440
61b2fbe7
MM
10441#ifndef ABI_STACK_BOUNDARY
10442#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10443#endif
10444
d1d0c603 10445static rs6000_stack_t *
863d938c 10446rs6000_stack_info (void)
4697a36c
MM
10447{
10448 static rs6000_stack_t info, zero_info;
10449 rs6000_stack_t *info_ptr = &info;
9ebbca7d 10450 int reg_size = TARGET_POWERPC64 ? 8 : 4;
83720594 10451 int ehrd_size;
d1d0c603 10452 HOST_WIDE_INT total_raw_size;
4697a36c 10453
a4f6c312 10454 /* Zero all fields portably. */
4697a36c
MM
10455 info = zero_info;
10456
c19de7aa
AH
10457 if (TARGET_SPE)
10458 {
10459 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10460 if (cfun->machine->insn_chain_scanned_p == 0)
10461 {
10462 cfun->machine->insn_chain_scanned_p = 1;
10463 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10464 }
c19de7aa
AH
10465 }
10466
a4f6c312 10467 /* Select which calling sequence. */
178274da 10468 info_ptr->abi = DEFAULT_ABI;
9878760c 10469
a4f6c312 10470 /* Calculate which registers need to be saved & save area size. */
4697a36c 10471 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10472 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10473 even if it currently looks like we won't. */
2bfcf297 10474 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10475 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10476 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10477 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
10478 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
10479 else
10480 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 10481
a3170dc6
AH
10482 /* For the SPE, we have an additional upper 32-bits on each GPR.
10483 Ideally we should save the entire 64-bits only when the upper
10484 half is used in SIMD instructions. Since we only record
10485 registers live (not the size they are used in), this proves
10486 difficult because we'd have to traverse the instruction chain at
10487 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
10488 so we opt to save the GPRs in 64-bits always if but one register
10489 gets used in 64-bits. Otherwise, all the registers in the frame
10490 get saved in 32-bits.
a3170dc6 10491
c19de7aa 10492 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 10493 traditional GP save area will be empty. */
c19de7aa 10494 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10495 info_ptr->gp_size = 0;
10496
4697a36c
MM
10497 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
10498 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
10499
00b960c7
AH
10500 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
10501 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
10502 - info_ptr->first_altivec_reg_save);
10503
592696dd 10504 /* Does this function call anything? */
71f123ca
FS
10505 info_ptr->calls_p = (! current_function_is_leaf
10506 || cfun->machine->ra_needs_full_frame);
b6c9286a 10507
a4f6c312 10508 /* Determine if we need to save the link register. */
71f123ca 10509 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
10510 || (DEFAULT_ABI == ABI_AIX
10511 && current_function_profile
10512 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
10513#ifdef TARGET_RELOCATABLE
10514 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
10515#endif
10516 || (info_ptr->first_fp_reg_save != 64
10517 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 10518 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 10519 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
10520 || (DEFAULT_ABI == ABI_DARWIN
10521 && flag_pic
10522 && current_function_uses_pic_offset_table)
4697a36c
MM
10523 || info_ptr->calls_p)
10524 {
10525 info_ptr->lr_save_p = 1;
9ebbca7d 10526 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
10527 }
10528
9ebbca7d
GK
10529 /* Determine if we need to save the condition code registers. */
10530 if (regs_ever_live[CR2_REGNO]
10531 || regs_ever_live[CR3_REGNO]
10532 || regs_ever_live[CR4_REGNO])
4697a36c
MM
10533 {
10534 info_ptr->cr_save_p = 1;
178274da 10535 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
10536 info_ptr->cr_size = reg_size;
10537 }
10538
83720594
RH
10539 /* If the current function calls __builtin_eh_return, then we need
10540 to allocate stack space for registers that will hold data for
10541 the exception handler. */
10542 if (current_function_calls_eh_return)
10543 {
10544 unsigned int i;
10545 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
10546 continue;
a3170dc6
AH
10547
10548 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
10549 ehrd_size = i * (TARGET_SPE_ABI
10550 && info_ptr->spe_64bit_regs_used != 0
10551 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
10552 }
10553 else
10554 ehrd_size = 0;
10555
592696dd 10556 /* Determine various sizes. */
4697a36c
MM
10557 info_ptr->reg_size = reg_size;
10558 info_ptr->fixed_size = RS6000_SAVE_AREA;
10559 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 10560 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
10561 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
10562 8);
00b960c7 10563
c19de7aa 10564 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10565 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
10566 else
10567 info_ptr->spe_gp_size = 0;
10568
4d774ff8
HP
10569 if (TARGET_ALTIVEC_ABI)
10570 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 10571 else
4d774ff8
HP
10572 info_ptr->vrsave_mask = 0;
10573
10574 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
10575 info_ptr->vrsave_size = 4;
10576 else
10577 info_ptr->vrsave_size = 0;
b6c9286a 10578
592696dd 10579 /* Calculate the offsets. */
178274da 10580 switch (DEFAULT_ABI)
4697a36c 10581 {
b6c9286a 10582 case ABI_NONE:
24d304eb 10583 default:
b6c9286a
MM
10584 abort ();
10585
10586 case ABI_AIX:
ee890fe2 10587 case ABI_DARWIN:
b6c9286a
MM
10588 info_ptr->fp_save_offset = - info_ptr->fp_size;
10589 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
10590
10591 if (TARGET_ALTIVEC_ABI)
10592 {
10593 info_ptr->vrsave_save_offset
10594 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
10595
10596 /* Align stack so vector save area is on a quadword boundary. */
10597 if (info_ptr->altivec_size != 0)
10598 info_ptr->altivec_padding_size
10599 = 16 - (-info_ptr->vrsave_save_offset % 16);
10600 else
10601 info_ptr->altivec_padding_size = 0;
10602
10603 info_ptr->altivec_save_offset
10604 = info_ptr->vrsave_save_offset
10605 - info_ptr->altivec_padding_size
10606 - info_ptr->altivec_size;
10607
10608 /* Adjust for AltiVec case. */
10609 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
10610 }
10611 else
10612 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
10613 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
10614 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
10615 break;
10616
10617 case ABI_V4:
b6c9286a
MM
10618 info_ptr->fp_save_offset = - info_ptr->fp_size;
10619 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 10620 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 10621
c19de7aa 10622 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10623 {
10624 /* Align stack so SPE GPR save area is aligned on a
10625 double-word boundary. */
10626 if (info_ptr->spe_gp_size != 0)
10627 info_ptr->spe_padding_size
10628 = 8 - (-info_ptr->cr_save_offset % 8);
10629 else
10630 info_ptr->spe_padding_size = 0;
10631
10632 info_ptr->spe_gp_save_offset
10633 = info_ptr->cr_save_offset
10634 - info_ptr->spe_padding_size
10635 - info_ptr->spe_gp_size;
10636
10637 /* Adjust for SPE case. */
10638 info_ptr->toc_save_offset
10639 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
10640 }
10641 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
10642 {
10643 info_ptr->vrsave_save_offset
10644 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
10645
10646 /* Align stack so vector save area is on a quadword boundary. */
10647 if (info_ptr->altivec_size != 0)
10648 info_ptr->altivec_padding_size
10649 = 16 - (-info_ptr->vrsave_save_offset % 16);
10650 else
10651 info_ptr->altivec_padding_size = 0;
10652
10653 info_ptr->altivec_save_offset
10654 = info_ptr->vrsave_save_offset
10655 - info_ptr->altivec_padding_size
10656 - info_ptr->altivec_size;
10657
10658 /* Adjust for AltiVec case. */
10659 info_ptr->toc_save_offset
10660 = info_ptr->altivec_save_offset - info_ptr->toc_size;
10661 }
10662 else
10663 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 10664 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
10665 info_ptr->lr_save_offset = reg_size;
10666 break;
4697a36c
MM
10667 }
10668
00b960c7
AH
10669 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
10670 + info_ptr->gp_size
10671 + info_ptr->altivec_size
10672 + info_ptr->altivec_padding_size
a3170dc6
AH
10673 + info_ptr->spe_gp_size
10674 + info_ptr->spe_padding_size
00b960c7
AH
10675 + ehrd_size
10676 + info_ptr->cr_size
10677 + info_ptr->lr_size
10678 + info_ptr->vrsave_size
10679 + info_ptr->toc_size,
10680 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
10681 ? 16 : 8);
10682
ff381587
MM
10683 total_raw_size = (info_ptr->vars_size
10684 + info_ptr->parm_size
ff381587
MM
10685 + info_ptr->save_size
10686 + info_ptr->varargs_size
10687 + info_ptr->fixed_size);
10688
a4f6c312
SS
10689 info_ptr->total_size =
10690 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
10691
10692 /* Determine if we need to allocate any stack frame:
10693
a4f6c312
SS
10694 For AIX we need to push the stack if a frame pointer is needed
10695 (because the stack might be dynamically adjusted), if we are
10696 debugging, if we make calls, or if the sum of fp_save, gp_save,
10697 and local variables are more than the space needed to save all
10698 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
10699 + 18*8 = 288 (GPR13 reserved).
ff381587 10700
a4f6c312
SS
10701 For V.4 we don't have the stack cushion that AIX uses, but assume
10702 that the debugger can handle stackless frames. */
ff381587
MM
10703
10704 if (info_ptr->calls_p)
10705 info_ptr->push_p = 1;
10706
178274da 10707 else if (DEFAULT_ABI == ABI_V4)
e72247f4 10708 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587 10709
178274da
AM
10710 else if (frame_pointer_needed)
10711 info_ptr->push_p = 1;
10712
10713 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
10714 info_ptr->push_p = 1;
10715
ff381587 10716 else
178274da
AM
10717 info_ptr->push_p
10718 = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 10719
a4f6c312 10720 /* Zero offsets if we're not saving those registers. */
8dda1a21 10721 if (info_ptr->fp_size == 0)
4697a36c
MM
10722 info_ptr->fp_save_offset = 0;
10723
8dda1a21 10724 if (info_ptr->gp_size == 0)
4697a36c
MM
10725 info_ptr->gp_save_offset = 0;
10726
00b960c7
AH
10727 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
10728 info_ptr->altivec_save_offset = 0;
10729
10730 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
10731 info_ptr->vrsave_save_offset = 0;
10732
c19de7aa
AH
10733 if (! TARGET_SPE_ABI
10734 || info_ptr->spe_64bit_regs_used == 0
10735 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
10736 info_ptr->spe_gp_save_offset = 0;
10737
c81fc13e 10738 if (! info_ptr->lr_save_p)
4697a36c
MM
10739 info_ptr->lr_save_offset = 0;
10740
c81fc13e 10741 if (! info_ptr->cr_save_p)
4697a36c
MM
10742 info_ptr->cr_save_offset = 0;
10743
c81fc13e 10744 if (! info_ptr->toc_save_p)
b6c9286a
MM
10745 info_ptr->toc_save_offset = 0;
10746
4697a36c
MM
10747 return info_ptr;
10748}
10749
c19de7aa
AH
10750/* Return true if the current function uses any GPRs in 64-bit SIMD
10751 mode. */
10752
10753static bool
863d938c 10754spe_func_has_64bit_regs_p (void)
c19de7aa
AH
10755{
10756 rtx insns, insn;
10757
10758 /* Functions that save and restore all the call-saved registers will
10759 need to save/restore the registers in 64-bits. */
10760 if (current_function_calls_eh_return
10761 || current_function_calls_setjmp
10762 || current_function_has_nonlocal_goto)
10763 return true;
10764
10765 insns = get_insns ();
10766
10767 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
10768 {
10769 if (INSN_P (insn))
10770 {
10771 rtx i;
10772
10773 i = PATTERN (insn);
10774 if (GET_CODE (i) == SET
10775 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
10776 return true;
10777 }
10778 }
10779
10780 return false;
10781}
10782
d1d0c603 10783static void
a2369ed3 10784debug_stack_info (rs6000_stack_t *info)
9878760c 10785{
d330fd93 10786 const char *abi_string;
24d304eb 10787
c81fc13e 10788 if (! info)
4697a36c
MM
10789 info = rs6000_stack_info ();
10790
10791 fprintf (stderr, "\nStack information for function %s:\n",
10792 ((current_function_decl && DECL_NAME (current_function_decl))
10793 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
10794 : "<unknown>"));
10795
24d304eb
RK
10796 switch (info->abi)
10797 {
b6c9286a
MM
10798 default: abi_string = "Unknown"; break;
10799 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 10800 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 10801 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 10802 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
10803 }
10804
10805 fprintf (stderr, "\tABI = %5s\n", abi_string);
10806
00b960c7
AH
10807 if (TARGET_ALTIVEC_ABI)
10808 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
10809
a3170dc6
AH
10810 if (TARGET_SPE_ABI)
10811 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
10812
4697a36c
MM
10813 if (info->first_gp_reg_save != 32)
10814 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
10815
10816 if (info->first_fp_reg_save != 64)
10817 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 10818
00b960c7
AH
10819 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
10820 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
10821 info->first_altivec_reg_save);
10822
4697a36c
MM
10823 if (info->lr_save_p)
10824 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 10825
4697a36c
MM
10826 if (info->cr_save_p)
10827 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
10828
b6c9286a
MM
10829 if (info->toc_save_p)
10830 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
10831
00b960c7
AH
10832 if (info->vrsave_mask)
10833 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
10834
4697a36c
MM
10835 if (info->push_p)
10836 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
10837
10838 if (info->calls_p)
10839 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
10840
4697a36c
MM
10841 if (info->gp_save_offset)
10842 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
10843
10844 if (info->fp_save_offset)
10845 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
10846
00b960c7
AH
10847 if (info->altivec_save_offset)
10848 fprintf (stderr, "\taltivec_save_offset = %5d\n",
10849 info->altivec_save_offset);
10850
a3170dc6
AH
10851 if (info->spe_gp_save_offset)
10852 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
10853 info->spe_gp_save_offset);
10854
00b960c7
AH
10855 if (info->vrsave_save_offset)
10856 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
10857 info->vrsave_save_offset);
10858
4697a36c
MM
10859 if (info->lr_save_offset)
10860 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
10861
10862 if (info->cr_save_offset)
10863 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
10864
b6c9286a
MM
10865 if (info->toc_save_offset)
10866 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
10867
4697a36c
MM
10868 if (info->varargs_save_offset)
10869 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
10870
10871 if (info->total_size)
d1d0c603
JJ
10872 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
10873 info->total_size);
4697a36c
MM
10874
10875 if (info->varargs_size)
10876 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
10877
10878 if (info->vars_size)
d1d0c603
JJ
10879 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
10880 info->vars_size);
4697a36c
MM
10881
10882 if (info->parm_size)
10883 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
10884
10885 if (info->fixed_size)
10886 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
10887
10888 if (info->gp_size)
10889 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
10890
a3170dc6
AH
10891 if (info->spe_gp_size)
10892 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
10893
4697a36c
MM
10894 if (info->fp_size)
10895 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
10896
00b960c7
AH
10897 if (info->altivec_size)
10898 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
10899
10900 if (info->vrsave_size)
10901 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
10902
10903 if (info->altivec_padding_size)
10904 fprintf (stderr, "\taltivec_padding_size= %5d\n",
10905 info->altivec_padding_size);
10906
a3170dc6
AH
10907 if (info->spe_padding_size)
10908 fprintf (stderr, "\tspe_padding_size = %5d\n",
10909 info->spe_padding_size);
10910
a4f6c312 10911 if (info->lr_size)
ed947a96 10912 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 10913
4697a36c
MM
10914 if (info->cr_size)
10915 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
10916
a4f6c312 10917 if (info->toc_size)
b6c9286a
MM
10918 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
10919
4697a36c
MM
10920 if (info->save_size)
10921 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
10922
10923 if (info->reg_size != 4)
10924 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
10925
10926 fprintf (stderr, "\n");
9878760c 10927}
71f123ca
FS
10928
10929rtx
a2369ed3 10930rs6000_return_addr (int count, rtx frame)
71f123ca 10931{
a4f6c312
SS
10932 /* Currently we don't optimize very well between prolog and body
10933 code and for PIC code the code can be actually quite bad, so
10934 don't try to be too clever here. */
f1384257 10935 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
10936 {
10937 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
10938
10939 return
10940 gen_rtx_MEM
10941 (Pmode,
10942 memory_address
10943 (Pmode,
10944 plus_constant (copy_to_reg
10945 (gen_rtx_MEM (Pmode,
10946 memory_address (Pmode, frame))),
10947 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
10948 }
10949
8c29550d 10950 cfun->machine->ra_need_lr = 1;
9e2f7ec7 10951 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
10952}
10953
5e1bf043
DJ
10954/* Say whether a function is a candidate for sibcall handling or not.
10955 We do not allow indirect calls to be optimized into sibling calls.
10956 Also, we can't do it if there are any vector parameters; there's
10957 nowhere to put the VRsave code so it works; note that functions with
10958 vector parameters are required to have a prototype, so the argument
10959 type info must be available here. (The tail recursion case can work
10960 with vector parameters, but there's no way to distinguish here.) */
4977bab6 10961static bool
a2369ed3 10962rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
10963{
10964 tree type;
4977bab6 10965 if (decl)
5e1bf043
DJ
10966 {
10967 if (TARGET_ALTIVEC_VRSAVE)
10968 {
4977bab6 10969 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
10970 type; type = TREE_CHAIN (type))
10971 {
c15b529f 10972 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 10973 return false;
5e1bf043
DJ
10974 }
10975 }
10976 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 10977 || (*targetm.binds_local_p) (decl))
2bcc50d0 10978 {
4977bab6 10979 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
10980
10981 if (!lookup_attribute ("longcall", attr_list)
10982 || lookup_attribute ("shortcall", attr_list))
4977bab6 10983 return true;
2bcc50d0 10984 }
5e1bf043 10985 }
4977bab6 10986 return false;
5e1bf043
DJ
10987}
10988
71f123ca 10989static int
863d938c 10990rs6000_ra_ever_killed (void)
71f123ca
FS
10991{
10992 rtx top;
5e1bf043
DJ
10993 rtx reg;
10994 rtx insn;
71f123ca 10995
dd292d0a 10996 if (current_function_is_thunk)
71f123ca 10997 return 0;
eb0424da 10998
36f7e964
AH
10999 /* regs_ever_live has LR marked as used if any sibcalls are present,
11000 but this should not force saving and restoring in the
11001 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 11002 clobbers LR, so that is inappropriate. */
36f7e964 11003
5e1bf043
DJ
11004 /* Also, the prologue can generate a store into LR that
11005 doesn't really count, like this:
36f7e964 11006
5e1bf043
DJ
11007 move LR->R0
11008 bcl to set PIC register
11009 move LR->R31
11010 move R0->LR
36f7e964
AH
11011
11012 When we're called from the epilogue, we need to avoid counting
11013 this as a store. */
5e1bf043 11014
71f123ca
FS
11015 push_topmost_sequence ();
11016 top = get_insns ();
11017 pop_topmost_sequence ();
5e1bf043 11018 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 11019
5e1bf043
DJ
11020 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
11021 {
11022 if (INSN_P (insn))
11023 {
11024 if (FIND_REG_INC_NOTE (insn, reg))
11025 return 1;
11026 else if (GET_CODE (insn) == CALL_INSN
c15b529f 11027 && !SIBLING_CALL_P (insn))
5e1bf043 11028 return 1;
36f7e964
AH
11029 else if (set_of (reg, insn) != NULL_RTX
11030 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
11031 return 1;
11032 }
11033 }
11034 return 0;
71f123ca 11035}
4697a36c 11036\f
8cd8f856
GK
11037/* Add a REG_MAYBE_DEAD note to the insn. */
11038static void
a2369ed3 11039rs6000_maybe_dead (rtx insn)
8cd8f856
GK
11040{
11041 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
11042 const0_rtx,
11043 REG_NOTES (insn));
11044}
11045
9ebbca7d 11046/* Emit instructions needed to load the TOC register.
c7ca610e 11047 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 11048 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
11049
11050void
a2369ed3 11051rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 11052{
027fbf43 11053 rtx dest, insn;
1db02437 11054 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 11055
20b71b17
AM
11056 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11057 {
11058 rtx temp = (fromprolog
11059 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11060 : gen_reg_rtx (Pmode));
027fbf43
JJ
11061 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
11062 if (fromprolog)
11063 rs6000_maybe_dead (insn);
11064 insn = emit_move_insn (dest, temp);
11065 if (fromprolog)
11066 rs6000_maybe_dead (insn);
20b71b17
AM
11067 }
11068 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
11069 {
11070 char buf[30];
11071 rtx tempLR = (fromprolog
11072 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11073 : gen_reg_rtx (Pmode));
11074 rtx temp0 = (fromprolog
11075 ? gen_rtx_REG (Pmode, 0)
11076 : gen_reg_rtx (Pmode));
11077 rtx symF;
11078
11079 /* possibly create the toc section */
11080 if (! toc_initialized)
38c1f2d7 11081 {
20b71b17
AM
11082 toc_section ();
11083 function_section (current_function_decl);
38c1f2d7 11084 }
9ebbca7d 11085
20b71b17
AM
11086 if (fromprolog)
11087 {
11088 rtx symL;
38c1f2d7 11089
20b71b17
AM
11090 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
11091 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 11092
20b71b17
AM
11093 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
11094 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11095
11096 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
11097 symF)));
11098 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
11099 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
11100 symL,
11101 symF)));
9ebbca7d
GK
11102 }
11103 else
20b71b17
AM
11104 {
11105 rtx tocsym;
11106 static int reload_toc_labelno = 0;
11107
11108 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
11109
11110 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
11111 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11112
027fbf43
JJ
11113 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
11114 emit_move_insn (dest, tempLR);
11115 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 11116 }
027fbf43
JJ
11117 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
11118 if (fromprolog)
11119 rs6000_maybe_dead (insn);
9ebbca7d 11120 }
20b71b17
AM
11121 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
11122 {
11123 /* This is for AIX code running in non-PIC ELF32. */
11124 char buf[30];
11125 rtx realsym;
11126 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11127 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11128
027fbf43
JJ
11129 insn = emit_insn (gen_elf_high (dest, realsym));
11130 if (fromprolog)
11131 rs6000_maybe_dead (insn);
11132 insn = emit_insn (gen_elf_low (dest, dest, realsym));
11133 if (fromprolog)
11134 rs6000_maybe_dead (insn);
20b71b17
AM
11135 }
11136 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
11137 {
11138 if (TARGET_32BIT)
027fbf43 11139 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 11140 else
027fbf43
JJ
11141 insn = emit_insn (gen_load_toc_aix_di (dest));
11142 if (fromprolog)
11143 rs6000_maybe_dead (insn);
9ebbca7d 11144 }
20b71b17
AM
11145 else
11146 abort ();
9ebbca7d
GK
11147}
11148
d1d0c603
JJ
11149/* Emit instructions to restore the link register after determining where
11150 its value has been stored. */
11151
11152void
11153rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
11154{
11155 rs6000_stack_t *info = rs6000_stack_info ();
11156 rtx operands[2];
11157
11158 operands[0] = source;
11159 operands[1] = scratch;
11160
11161 if (info->lr_save_p)
11162 {
11163 rtx frame_rtx = stack_pointer_rtx;
11164 HOST_WIDE_INT sp_offset = 0;
11165 rtx tmp;
11166
11167 if (frame_pointer_needed
11168 || current_function_calls_alloca
11169 || info->total_size > 32767)
11170 {
11171 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
11172 frame_rtx = operands[1];
11173 }
11174 else if (info->push_p)
11175 sp_offset = info->total_size;
11176
11177 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
11178 tmp = gen_rtx_MEM (Pmode, tmp);
11179 emit_move_insn (tmp, operands[0]);
11180 }
11181 else
11182 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
11183}
11184
f103e34d
GK
11185static GTY(()) int set = -1;
11186
9ebbca7d 11187int
863d938c 11188get_TOC_alias_set (void)
9ebbca7d 11189{
f103e34d
GK
11190 if (set == -1)
11191 set = new_alias_set ();
11192 return set;
9ebbca7d
GK
11193}
11194
c1207243 11195/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
11196 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
11197 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 11198#if TARGET_ELF
3c9eb5f4 11199static int
38f391a5 11200uses_TOC (void)
9ebbca7d 11201{
c4501e62 11202 rtx insn;
38c1f2d7 11203
c4501e62
JJ
11204 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11205 if (INSN_P (insn))
11206 {
11207 rtx pat = PATTERN (insn);
11208 int i;
9ebbca7d 11209
c4501e62
JJ
11210 if (GET_CODE (pat) == PARALLEL)
11211 for (i = 0; i < XVECLEN (pat, 0); i++)
11212 {
11213 rtx sub = XVECEXP (pat, 0, i);
11214 if (GET_CODE (sub) == USE)
11215 {
11216 sub = XEXP (sub, 0);
11217 if (GET_CODE (sub) == UNSPEC
11218 && XINT (sub, 1) == UNSPEC_TOC)
11219 return 1;
11220 }
11221 }
11222 }
11223 return 0;
9ebbca7d 11224}
c954844a 11225#endif
38c1f2d7 11226
9ebbca7d 11227rtx
a2369ed3 11228create_TOC_reference (rtx symbol)
9ebbca7d 11229{
a8a05998
ZW
11230 return gen_rtx_PLUS (Pmode,
11231 gen_rtx_REG (Pmode, TOC_REGISTER),
11232 gen_rtx_CONST (Pmode,
11233 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 11234 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 11235}
38c1f2d7 11236
fc4767bb
JJ
11237/* If _Unwind_* has been called from within the same module,
11238 toc register is not guaranteed to be saved to 40(1) on function
11239 entry. Save it there in that case. */
c7ca610e 11240
9ebbca7d 11241void
863d938c 11242rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
11243{
11244 rtx mem;
11245 rtx stack_top = gen_reg_rtx (Pmode);
11246 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
11247 rtx opcode = gen_reg_rtx (SImode);
11248 rtx tocompare = gen_reg_rtx (SImode);
11249 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
11250
11251 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
11252 emit_move_insn (stack_top, mem);
11253
fc4767bb
JJ
11254 mem = gen_rtx_MEM (Pmode,
11255 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
11256 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
11257 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
11258 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
11259 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 11260 : 0xE8410028, SImode));
9ebbca7d 11261
fc4767bb 11262 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 11263 SImode, NULL_RTX, NULL_RTX,
fc4767bb 11264 no_toc_save_needed);
9ebbca7d 11265
fc4767bb
JJ
11266 mem = gen_rtx_MEM (Pmode,
11267 gen_rtx_PLUS (Pmode, stack_top,
11268 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
11269 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
11270 emit_label (no_toc_save_needed);
9ebbca7d 11271}
38c1f2d7 11272\f
ba4828e0
RK
11273/* This ties together stack memory (MEM with an alias set of
11274 rs6000_sr_alias_set) and the change to the stack pointer. */
11275
9ebbca7d 11276static void
863d938c 11277rs6000_emit_stack_tie (void)
9ebbca7d 11278{
ba4828e0
RK
11279 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
11280
11281 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11282 emit_insn (gen_stack_tie (mem));
11283}
38c1f2d7 11284
9ebbca7d
GK
11285/* Emit the correct code for allocating stack space, as insns.
11286 If COPY_R12, make sure a copy of the old frame is left in r12.
11287 The generated code may use hard register 0 as a temporary. */
11288
11289static void
a2369ed3 11290rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 11291{
9ebbca7d
GK
11292 rtx insn;
11293 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11294 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
11295 rtx todec = GEN_INT (-size);
a157febd
GK
11296
11297 if (current_function_limit_stack)
11298 {
11299 if (REG_P (stack_limit_rtx)
11300 && REGNO (stack_limit_rtx) > 1
11301 && REGNO (stack_limit_rtx) <= 31)
11302 {
5b71a4e7 11303 emit_insn (TARGET_32BIT
9ebbca7d
GK
11304 ? gen_addsi3 (tmp_reg,
11305 stack_limit_rtx,
11306 GEN_INT (size))
11307 : gen_adddi3 (tmp_reg,
11308 stack_limit_rtx,
11309 GEN_INT (size)));
5b71a4e7 11310
9ebbca7d
GK
11311 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11312 const0_rtx));
a157febd
GK
11313 }
11314 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 11315 && TARGET_32BIT
f607bc57 11316 && DEFAULT_ABI == ABI_V4)
a157febd 11317 {
9ebbca7d
GK
11318 rtx toload = gen_rtx_CONST (VOIDmode,
11319 gen_rtx_PLUS (Pmode,
11320 stack_limit_rtx,
11321 GEN_INT (size)));
5b71a4e7 11322
9ebbca7d
GK
11323 emit_insn (gen_elf_high (tmp_reg, toload));
11324 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
11325 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11326 const0_rtx));
a157febd
GK
11327 }
11328 else
11329 warning ("stack limit expression is not supported");
11330 }
11331
9ebbca7d
GK
11332 if (copy_r12 || ! TARGET_UPDATE)
11333 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
11334
38c1f2d7
MM
11335 if (TARGET_UPDATE)
11336 {
9ebbca7d 11337 if (size > 32767)
38c1f2d7 11338 {
9ebbca7d
GK
11339 /* Need a note here so that try_split doesn't get confused. */
11340 if (get_last_insn() == NULL_RTX)
2e040219 11341 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
11342 insn = emit_move_insn (tmp_reg, todec);
11343 try_split (PATTERN (insn), insn, 0);
11344 todec = tmp_reg;
38c1f2d7 11345 }
5b71a4e7
DE
11346
11347 insn = emit_insn (TARGET_32BIT
11348 ? gen_movsi_update (stack_reg, stack_reg,
11349 todec, stack_reg)
11350 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 11351 todec, stack_reg));
38c1f2d7
MM
11352 }
11353 else
11354 {
5b71a4e7
DE
11355 insn = emit_insn (TARGET_32BIT
11356 ? gen_addsi3 (stack_reg, stack_reg, todec)
11357 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
11358 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
11359 gen_rtx_REG (Pmode, 12));
11360 }
5b71a4e7 11361
9ebbca7d
GK
11362 RTX_FRAME_RELATED_P (insn) = 1;
11363 REG_NOTES (insn) =
11364 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11365 gen_rtx_SET (VOIDmode, stack_reg,
11366 gen_rtx_PLUS (Pmode, stack_reg,
11367 GEN_INT (-size))),
11368 REG_NOTES (insn));
11369}
11370
a4f6c312
SS
11371/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
11372 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
11373 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
11374 deduce these equivalences by itself so it wasn't necessary to hold
11375 its hand so much. */
9ebbca7d
GK
11376
11377static void
a2369ed3
DJ
11378rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
11379 rtx reg2, rtx rreg)
9ebbca7d
GK
11380{
11381 rtx real, temp;
11382
e56c4463
JL
11383 /* copy_rtx will not make unique copies of registers, so we need to
11384 ensure we don't have unwanted sharing here. */
11385 if (reg == reg2)
11386 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11387
11388 if (reg == rreg)
11389 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11390
9ebbca7d
GK
11391 real = copy_rtx (PATTERN (insn));
11392
89e7058f
AH
11393 if (reg2 != NULL_RTX)
11394 real = replace_rtx (real, reg2, rreg);
11395
9ebbca7d
GK
11396 real = replace_rtx (real, reg,
11397 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
11398 STACK_POINTER_REGNUM),
11399 GEN_INT (val)));
11400
11401 /* We expect that 'real' is either a SET or a PARALLEL containing
11402 SETs (and possibly other stuff). In a PARALLEL, all the SETs
11403 are important so they all have to be marked RTX_FRAME_RELATED_P. */
11404
11405 if (GET_CODE (real) == SET)
11406 {
11407 rtx set = real;
11408
11409 temp = simplify_rtx (SET_SRC (set));
11410 if (temp)
11411 SET_SRC (set) = temp;
11412 temp = simplify_rtx (SET_DEST (set));
11413 if (temp)
11414 SET_DEST (set) = temp;
11415 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 11416 {
9ebbca7d
GK
11417 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11418 if (temp)
11419 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 11420 }
38c1f2d7 11421 }
9ebbca7d
GK
11422 else if (GET_CODE (real) == PARALLEL)
11423 {
11424 int i;
11425 for (i = 0; i < XVECLEN (real, 0); i++)
11426 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11427 {
11428 rtx set = XVECEXP (real, 0, i);
11429
11430 temp = simplify_rtx (SET_SRC (set));
11431 if (temp)
11432 SET_SRC (set) = temp;
11433 temp = simplify_rtx (SET_DEST (set));
11434 if (temp)
11435 SET_DEST (set) = temp;
11436 if (GET_CODE (SET_DEST (set)) == MEM)
11437 {
11438 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11439 if (temp)
11440 XEXP (SET_DEST (set), 0) = temp;
11441 }
11442 RTX_FRAME_RELATED_P (set) = 1;
11443 }
11444 }
11445 else
a4f6c312 11446 abort ();
c19de7aa
AH
11447
11448 if (TARGET_SPE)
11449 real = spe_synthesize_frame_save (real);
11450
9ebbca7d
GK
11451 RTX_FRAME_RELATED_P (insn) = 1;
11452 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11453 real,
11454 REG_NOTES (insn));
38c1f2d7
MM
11455}
11456
c19de7aa
AH
11457/* Given an SPE frame note, return a PARALLEL of SETs with the
11458 original note, plus a synthetic register save. */
11459
11460static rtx
a2369ed3 11461spe_synthesize_frame_save (rtx real)
c19de7aa
AH
11462{
11463 rtx synth, offset, reg, real2;
11464
11465 if (GET_CODE (real) != SET
11466 || GET_MODE (SET_SRC (real)) != V2SImode)
11467 return real;
11468
11469 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11470 frame related note. The parallel contains a set of the register
41f3a930 11471 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11472 This is so we can differentiate between 64-bit and 32-bit saves.
11473 Words cannot describe this nastiness. */
11474
11475 if (GET_CODE (SET_DEST (real)) != MEM
11476 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11477 || GET_CODE (SET_SRC (real)) != REG)
11478 abort ();
11479
11480 /* Transform:
11481 (set (mem (plus (reg x) (const y)))
11482 (reg z))
11483 into:
11484 (set (mem (plus (reg x) (const y+4)))
41f3a930 11485 (reg z+1200))
c19de7aa
AH
11486 */
11487
11488 real2 = copy_rtx (real);
11489 PUT_MODE (SET_DEST (real2), SImode);
11490 reg = SET_SRC (real2);
11491 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
11492 synth = copy_rtx (real2);
11493
11494 if (BYTES_BIG_ENDIAN)
11495 {
11496 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
11497 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
11498 }
11499
11500 reg = SET_SRC (synth);
41f3a930 11501
c19de7aa 11502 synth = replace_rtx (synth, reg,
41f3a930 11503 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
11504
11505 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
11506 synth = replace_rtx (synth, offset,
11507 GEN_INT (INTVAL (offset)
11508 + (BYTES_BIG_ENDIAN ? 0 : 4)));
11509
11510 RTX_FRAME_RELATED_P (synth) = 1;
11511 RTX_FRAME_RELATED_P (real2) = 1;
11512 if (BYTES_BIG_ENDIAN)
11513 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
11514 else
11515 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
11516
11517 return real;
11518}
11519
00b960c7
AH
11520/* Returns an insn that has a vrsave set operation with the
11521 appropriate CLOBBERs. */
11522
11523static rtx
a2369ed3 11524generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
11525{
11526 int nclobs, i;
11527 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 11528 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 11529
a004eb82
AH
11530 clobs[0]
11531 = gen_rtx_SET (VOIDmode,
11532 vrsave,
11533 gen_rtx_UNSPEC_VOLATILE (SImode,
11534 gen_rtvec (2, reg, vrsave),
11535 30));
00b960c7
AH
11536
11537 nclobs = 1;
11538
9aa86737
AH
11539 /* We need to clobber the registers in the mask so the scheduler
11540 does not move sets to VRSAVE before sets of AltiVec registers.
11541
11542 However, if the function receives nonlocal gotos, reload will set
11543 all call saved registers live. We will end up with:
11544
11545 (set (reg 999) (mem))
11546 (parallel [ (set (reg vrsave) (unspec blah))
11547 (clobber (reg 999))])
11548
11549 The clobber will cause the store into reg 999 to be dead, and
11550 flow will attempt to delete an epilogue insn. In this case, we
11551 need an unspec use/set of the register. */
00b960c7
AH
11552
11553 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11554 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
11555 {
11556 if (!epiloguep || call_used_regs [i])
11557 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
11558 gen_rtx_REG (V4SImode, i));
11559 else
11560 {
11561 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
11562
11563 clobs[nclobs++]
a004eb82
AH
11564 = gen_rtx_SET (VOIDmode,
11565 reg,
11566 gen_rtx_UNSPEC (V4SImode,
11567 gen_rtvec (1, reg), 27));
9aa86737
AH
11568 }
11569 }
00b960c7
AH
11570
11571 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
11572
11573 for (i = 0; i < nclobs; ++i)
11574 XVECEXP (insn, 0, i) = clobs[i];
11575
11576 return insn;
11577}
11578
89e7058f
AH
11579/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
11580 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
11581
11582static void
a2369ed3 11583emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 11584 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
11585{
11586 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
11587 rtx replacea, replaceb;
11588
11589 int_rtx = GEN_INT (offset);
11590
11591 /* Some cases that need register indexed addressing. */
11592 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
11593 || (TARGET_SPE_ABI
11594 && SPE_VECTOR_MODE (mode)
11595 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
11596 {
11597 /* Whomever calls us must make sure r11 is available in the
11598 flow path of instructions in the prologue. */
11599 offset_rtx = gen_rtx_REG (Pmode, 11);
11600 emit_move_insn (offset_rtx, int_rtx);
11601
11602 replacea = offset_rtx;
11603 replaceb = int_rtx;
11604 }
11605 else
11606 {
11607 offset_rtx = int_rtx;
11608 replacea = NULL_RTX;
11609 replaceb = NULL_RTX;
11610 }
11611
11612 reg = gen_rtx_REG (mode, regno);
11613 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
11614 mem = gen_rtx_MEM (mode, addr);
11615 set_mem_alias_set (mem, rs6000_sr_alias_set);
11616
11617 insn = emit_move_insn (mem, reg);
11618
11619 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
11620}
11621
a3170dc6
AH
11622/* Emit an offset memory reference suitable for a frame store, while
11623 converting to a valid addressing mode. */
11624
11625static rtx
a2369ed3 11626gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
11627{
11628 rtx int_rtx, offset_rtx;
11629
11630 int_rtx = GEN_INT (offset);
11631
11632 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
11633 {
11634 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11635 emit_move_insn (offset_rtx, int_rtx);
11636 }
11637 else
11638 offset_rtx = int_rtx;
11639
11640 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
11641}
11642
9ebbca7d
GK
11643/* Emit function prologue as insns. */
11644
9878760c 11645void
863d938c 11646rs6000_emit_prologue (void)
9878760c 11647{
4697a36c 11648 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a
FJ
11649 enum machine_mode reg_mode = Pmode;
11650 int reg_size = UNITS_PER_WORD;
9ebbca7d
GK
11651 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11652 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
11653 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 11654 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
11655 rtx insn;
11656 int saving_FPRs_inline;
11657 int using_store_multiple;
11658 HOST_WIDE_INT sp_offset = 0;
11659
c19de7aa 11660 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11661 {
11662 reg_mode = V2SImode;
11663 reg_size = 8;
11664 }
11665
9ebbca7d 11666 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11667 && (!TARGET_SPE_ABI
11668 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11669 && info->first_gp_reg_save < 31);
11670 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 11671 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 11672 || current_function_calls_eh_return
8c29550d 11673 || cfun->machine->ra_need_lr);
9ebbca7d
GK
11674
11675 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 11676 if (info->push_p
acd0b319
AM
11677 && (DEFAULT_ABI == ABI_V4
11678 || current_function_calls_eh_return))
9ebbca7d
GK
11679 {
11680 if (info->total_size < 32767)
11681 sp_offset = info->total_size;
11682 else
11683 frame_reg_rtx = frame_ptr_rtx;
11684 rs6000_emit_allocate_stack (info->total_size,
11685 (frame_reg_rtx != sp_reg_rtx
11686 && (info->cr_save_p
11687 || info->lr_save_p
11688 || info->first_fp_reg_save < 64
11689 || info->first_gp_reg_save < 32
11690 )));
11691 if (frame_reg_rtx != sp_reg_rtx)
11692 rs6000_emit_stack_tie ();
11693 }
11694
9aa86737
AH
11695 /* Save AltiVec registers if needed. */
11696 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11697 {
11698 int i;
11699
11700 /* There should be a non inline version of this, for when we
11701 are saving lots of vector registers. */
11702 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11703 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11704 {
11705 rtx areg, savereg, mem;
11706 int offset;
11707
11708 offset = info->altivec_save_offset + sp_offset
11709 + 16 * (i - info->first_altivec_reg_save);
11710
11711 savereg = gen_rtx_REG (V4SImode, i);
11712
11713 areg = gen_rtx_REG (Pmode, 0);
11714 emit_move_insn (areg, GEN_INT (offset));
11715
11716 /* AltiVec addressing mode is [reg+reg]. */
11717 mem = gen_rtx_MEM (V4SImode,
11718 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
11719
11720 set_mem_alias_set (mem, rs6000_sr_alias_set);
11721
11722 insn = emit_move_insn (mem, savereg);
11723
5c242421
SB
11724 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11725 areg, GEN_INT (offset));
9aa86737
AH
11726 }
11727 }
11728
11729 /* VRSAVE is a bit vector representing which AltiVec registers
11730 are used. The OS uses this to determine which vector
11731 registers to save on a context switch. We need to save
11732 VRSAVE on the stack frame, add whatever AltiVec registers we
11733 used in this function, and do the corresponding magic in the
11734 epilogue. */
11735
4d774ff8
HP
11736 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
11737 && info->vrsave_mask != 0)
9aa86737 11738 {
a004eb82 11739 rtx reg, mem, vrsave;
9aa86737
AH
11740 int offset;
11741
11742 /* Get VRSAVE onto a GPR. */
11743 reg = gen_rtx_REG (SImode, 12);
a004eb82 11744 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
11745 if (TARGET_MACHO)
11746 emit_insn (gen_get_vrsave_internal (reg));
11747 else
11748 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
11749
11750 /* Save VRSAVE. */
11751 offset = info->vrsave_save_offset + sp_offset;
11752 mem
11753 = gen_rtx_MEM (SImode,
11754 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
11755 set_mem_alias_set (mem, rs6000_sr_alias_set);
11756 insn = emit_move_insn (mem, reg);
11757
11758 /* Include the registers in the mask. */
11759 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
11760
11761 insn = emit_insn (generate_set_vrsave (reg, info, 0));
11762 }
11763
9ebbca7d
GK
11764 /* If we use the link register, get it into r0. */
11765 if (info->lr_save_p)
71f123ca 11766 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
11767 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11768
11769 /* If we need to save CR, put it into r12. */
11770 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
11771 {
11772 cr_save_rtx = gen_rtx_REG (SImode, 12);
11773 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11774 }
11775
a4f6c312
SS
11776 /* Do any required saving of fpr's. If only one or two to save, do
11777 it ourselves. Otherwise, call function. */
9ebbca7d
GK
11778 if (saving_FPRs_inline)
11779 {
11780 int i;
11781 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11782 if ((regs_ever_live[info->first_fp_reg_save+i]
11783 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
11784 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
11785 info->first_fp_reg_save + i,
11786 info->fp_save_offset + sp_offset + 8 * i,
11787 info->total_size);
9ebbca7d
GK
11788 }
11789 else if (info->first_fp_reg_save != 64)
11790 {
11791 int i;
11792 char rname[30];
520a57c8 11793 const char *alloc_rname;
9ebbca7d
GK
11794 rtvec p;
11795 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
11796
11797 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
11798 gen_rtx_REG (Pmode,
11799 LINK_REGISTER_REGNUM));
11800 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
11801 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 11802 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11803 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
11804 gen_rtx_SYMBOL_REF (Pmode,
11805 alloc_rname));
11806 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11807 {
11808 rtx addr, reg, mem;
11809 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
11810 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11811 GEN_INT (info->fp_save_offset
11812 + sp_offset + 8*i));
11813 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11814 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11815
11816 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
11817 }
11818 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11819 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11820 NULL_RTX, NULL_RTX);
11821 }
b6c9286a 11822
9ebbca7d
GK
11823 /* Save GPRs. This is done as a PARALLEL if we are using
11824 the store-multiple instructions. */
11825 if (using_store_multiple)
b6c9286a 11826 {
308c142a 11827 rtvec p;
9ebbca7d
GK
11828 int i;
11829 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
11830 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11831 {
11832 rtx addr, reg, mem;
11833 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11834 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11835 GEN_INT (info->gp_save_offset
11836 + sp_offset
11837 + reg_size * i));
11838 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11839 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11840
11841 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
11842 }
11843 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11844 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11845 NULL_RTX, NULL_RTX);
b6c9286a
MM
11846 }
11847 else
11848 {
9ebbca7d
GK
11849 int i;
11850 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11851 if ((regs_ever_live[info->first_gp_reg_save+i]
11852 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11853 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11854 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11855 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
11856 {
11857 rtx addr, reg, mem;
11858 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11859
c19de7aa 11860 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11861 {
11862 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11863 rtx b;
11864
11865 if (!SPE_CONST_OFFSET_OK (offset))
11866 {
11867 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11868 emit_move_insn (b, GEN_INT (offset));
11869 }
11870 else
11871 b = GEN_INT (offset);
11872
11873 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11874 mem = gen_rtx_MEM (V2SImode, addr);
11875 set_mem_alias_set (mem, rs6000_sr_alias_set);
11876 insn = emit_move_insn (mem, reg);
11877
11878 if (GET_CODE (b) == CONST_INT)
11879 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11880 NULL_RTX, NULL_RTX);
11881 else
11882 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11883 b, GEN_INT (offset));
11884 }
11885 else
11886 {
11887 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11888 GEN_INT (info->gp_save_offset
11889 + sp_offset
11890 + reg_size * i));
11891 mem = gen_rtx_MEM (reg_mode, addr);
11892 set_mem_alias_set (mem, rs6000_sr_alias_set);
11893
11894 insn = emit_move_insn (mem, reg);
11895 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11896 NULL_RTX, NULL_RTX);
11897 }
11898 }
9ebbca7d
GK
11899 }
11900
83720594
RH
11901 /* ??? There's no need to emit actual instructions here, but it's the
11902 easiest way to get the frame unwind information emitted. */
11903 if (current_function_calls_eh_return)
11904 {
78e1b90d
DE
11905 unsigned int i, regno;
11906
fc4767bb
JJ
11907 /* In AIX ABI we need to pretend we save r2 here. */
11908 if (TARGET_AIX)
11909 {
11910 rtx addr, reg, mem;
11911
11912 reg = gen_rtx_REG (reg_mode, 2);
11913 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11914 GEN_INT (sp_offset + 5 * reg_size));
11915 mem = gen_rtx_MEM (reg_mode, addr);
11916 set_mem_alias_set (mem, rs6000_sr_alias_set);
11917
11918 insn = emit_move_insn (mem, reg);
11919 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11920 NULL_RTX, NULL_RTX);
11921 PATTERN (insn) = gen_blockage ();
11922 }
11923
83720594
RH
11924 for (i = 0; ; ++i)
11925 {
83720594
RH
11926 regno = EH_RETURN_DATA_REGNO (i);
11927 if (regno == INVALID_REGNUM)
11928 break;
11929
89e7058f
AH
11930 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
11931 info->ehrd_offset + sp_offset
11932 + reg_size * (int) i,
11933 info->total_size);
83720594
RH
11934 }
11935 }
11936
9ebbca7d
GK
11937 /* Save lr if we used it. */
11938 if (info->lr_save_p)
11939 {
11940 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11941 GEN_INT (info->lr_save_offset + sp_offset));
11942 rtx reg = gen_rtx_REG (Pmode, 0);
11943 rtx mem = gen_rtx_MEM (Pmode, addr);
11944 /* This should not be of rs6000_sr_alias_set, because of
11945 __builtin_return_address. */
11946
11947 insn = emit_move_insn (mem, reg);
11948 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11949 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11950 }
11951
11952 /* Save CR if we use any that must be preserved. */
11953 if (info->cr_save_p)
11954 {
11955 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11956 GEN_INT (info->cr_save_offset + sp_offset));
11957 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
11958
11959 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11960
11961 /* If r12 was used to hold the original sp, copy cr into r0 now
11962 that it's free. */
11963 if (REGNO (frame_reg_rtx) == 12)
11964 {
11965 cr_save_rtx = gen_rtx_REG (SImode, 0);
11966 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11967 }
11968 insn = emit_move_insn (mem, cr_save_rtx);
11969
11970 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
11971 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
11972 But that's OK. All we have to do is specify that _one_ condition
11973 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
11974 will then restore all the call-saved registers.
11975 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 11976 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 11977 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
11978 }
11979
11980 /* Update stack and set back pointer unless this is V.4,
11981 for which it was done previously. */
fc4767bb
JJ
11982 if (info->push_p
11983 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
11984 rs6000_emit_allocate_stack (info->total_size, FALSE);
11985
11986 /* Set frame pointer, if needed. */
11987 if (frame_pointer_needed)
11988 {
a3170dc6 11989 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
11990 sp_reg_rtx);
11991 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 11992 }
9878760c 11993
1db02437 11994 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 11995 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 11996 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 11997 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
11998 {
11999 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 12000 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
12001 can use register 0. This allows us to use a plain 'blr' to return
12002 from the procedure more often. */
f1384257
AM
12003 int save_LR_around_toc_setup = (TARGET_ELF
12004 && DEFAULT_ABI != ABI_AIX
12005 && flag_pic
d5fa86ba
GK
12006 && ! info->lr_save_p
12007 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 12008 if (save_LR_around_toc_setup)
c4501e62
JJ
12009 {
12010 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
12011 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
12012 rs6000_emit_load_toc_table (TRUE);
12013 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
12014 }
12015 else
12016 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 12017 }
ee890fe2 12018
fcce224d 12019#if TARGET_MACHO
ee890fe2
SS
12020 if (DEFAULT_ABI == ABI_DARWIN
12021 && flag_pic && current_function_uses_pic_offset_table)
12022 {
12023 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 12024 const char *picbase = machopic_function_base_name ();
6788f5ca 12025 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 12026
f51eee6a 12027 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
12028
12029 rs6000_maybe_dead (
1db02437 12030 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
12031 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
12032 }
fcce224d 12033#endif
9ebbca7d
GK
12034}
12035
9ebbca7d 12036/* Write function prologue. */
a4f6c312 12037
08c148a8 12038static void
a2369ed3
DJ
12039rs6000_output_function_prologue (FILE *file,
12040 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
12041{
12042 rs6000_stack_t *info = rs6000_stack_info ();
12043
4697a36c
MM
12044 if (TARGET_DEBUG_STACK)
12045 debug_stack_info (info);
9878760c 12046
a4f6c312
SS
12047 /* Write .extern for any function we will call to save and restore
12048 fp values. */
12049 if (info->first_fp_reg_save < 64
12050 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 12051 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 12052 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
12053 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
12054 RESTORE_FP_SUFFIX);
9878760c 12055
c764f757
RK
12056 /* Write .extern for AIX common mode routines, if needed. */
12057 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
12058 {
f6709c70
JW
12059 fputs ("\t.extern __mulh\n", file);
12060 fputs ("\t.extern __mull\n", file);
12061 fputs ("\t.extern __divss\n", file);
12062 fputs ("\t.extern __divus\n", file);
12063 fputs ("\t.extern __quoss\n", file);
12064 fputs ("\t.extern __quous\n", file);
c764f757
RK
12065 common_mode_defined = 1;
12066 }
9878760c 12067
9ebbca7d 12068 if (! HAVE_prologue)
979721f8 12069 {
9ebbca7d 12070 start_sequence ();
9dda4cc8 12071
a4f6c312
SS
12072 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
12073 the "toplevel" insn chain. */
2e040219 12074 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12075 rs6000_emit_prologue ();
2e040219 12076 emit_note (NOTE_INSN_DELETED);
178c3eff 12077
a3c9585f 12078 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12079 {
12080 rtx insn;
12081 unsigned addr = 0;
12082 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12083 {
12084 INSN_ADDRESSES_NEW (insn, addr);
12085 addr += 4;
12086 }
12087 }
9dda4cc8 12088
9ebbca7d 12089 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12090 debug_rtx_list (get_insns (), 100);
12091 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12092 end_sequence ();
979721f8
MM
12093 }
12094
9ebbca7d
GK
12095 rs6000_pic_labelno++;
12096}
12097
12098/* Emit function epilogue as insns.
9878760c 12099
9ebbca7d
GK
12100 At present, dwarf2out_frame_debug_expr doesn't understand
12101 register restores, so we don't bother setting RTX_FRAME_RELATED_P
12102 anywhere in the epilogue. Most of the insns below would in any case
12103 need special notes to explain where r11 is in relation to the stack. */
9878760c 12104
9ebbca7d 12105void
a2369ed3 12106rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
12107{
12108 rs6000_stack_t *info;
12109 int restoring_FPRs_inline;
12110 int using_load_multiple;
12111 int using_mfcr_multiple;
12112 int use_backchain_to_restore_sp;
12113 int sp_offset = 0;
12114 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
12115 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a
FJ
12116 enum machine_mode reg_mode = Pmode;
12117 int reg_size = UNITS_PER_WORD;
9ebbca7d
GK
12118 int i;
12119
c19de7aa
AH
12120 info = rs6000_stack_info ();
12121
12122 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12123 {
12124 reg_mode = V2SImode;
12125 reg_size = 8;
12126 }
12127
9ebbca7d 12128 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12129 && (!TARGET_SPE_ABI
12130 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12131 && info->first_gp_reg_save < 31);
12132 restoring_FPRs_inline = (sibcall
83720594 12133 || current_function_calls_eh_return
9ebbca7d
GK
12134 || info->first_fp_reg_save == 64
12135 || FP_SAVE_INLINE (info->first_fp_reg_save));
12136 use_backchain_to_restore_sp = (frame_pointer_needed
12137 || current_function_calls_alloca
12138 || info->total_size > 32767);
12139 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
12140 || rs6000_cpu == PROCESSOR_PPC603
12141 || rs6000_cpu == PROCESSOR_PPC750
12142 || optimize_size);
12143
12144 /* If we have a frame pointer, a call to alloca, or a large stack
12145 frame, restore the old stack pointer using the backchain. Otherwise,
12146 we know what size to update it with. */
12147 if (use_backchain_to_restore_sp)
bacbde18 12148 {
9ebbca7d
GK
12149 /* Under V.4, don't reset the stack pointer until after we're done
12150 loading the saved registers. */
f607bc57 12151 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 12152 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 12153
9ebbca7d
GK
12154 emit_move_insn (frame_reg_rtx,
12155 gen_rtx_MEM (Pmode, sp_reg_rtx));
12156
bacbde18 12157 }
9ebbca7d 12158 else if (info->push_p)
85638c0d 12159 {
fc4767bb
JJ
12160 if (DEFAULT_ABI == ABI_V4
12161 || current_function_calls_eh_return)
9ebbca7d
GK
12162 sp_offset = info->total_size;
12163 else
12164 {
12165 emit_insn (TARGET_32BIT
12166 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12167 GEN_INT (info->total_size))
12168 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12169 GEN_INT (info->total_size)));
12170 }
85638c0d 12171 }
9ebbca7d 12172
9aa86737
AH
12173 /* Restore AltiVec registers if needed. */
12174 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12175 {
12176 int i;
12177
12178 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12179 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12180 {
12181 rtx addr, areg, mem;
12182
12183 areg = gen_rtx_REG (Pmode, 0);
12184 emit_move_insn
12185 (areg, GEN_INT (info->altivec_save_offset
12186 + sp_offset
12187 + 16 * (i - info->first_altivec_reg_save)));
12188
12189 /* AltiVec addressing mode is [reg+reg]. */
12190 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
12191 mem = gen_rtx_MEM (V4SImode, addr);
12192 set_mem_alias_set (mem, rs6000_sr_alias_set);
12193
12194 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
12195 }
12196 }
12197
12198 /* Restore VRSAVE if needed. */
4d774ff8
HP
12199 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE
12200 && info->vrsave_mask != 0)
9aa86737
AH
12201 {
12202 rtx addr, mem, reg;
12203
12204 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12205 GEN_INT (info->vrsave_save_offset + sp_offset));
12206 mem = gen_rtx_MEM (SImode, addr);
12207 set_mem_alias_set (mem, rs6000_sr_alias_set);
12208 reg = gen_rtx_REG (SImode, 12);
12209 emit_move_insn (reg, mem);
12210
12211 emit_insn (generate_set_vrsave (reg, info, 1));
12212 }
12213
9ebbca7d
GK
12214 /* Get the old lr if we saved it. */
12215 if (info->lr_save_p)
b6c9286a 12216 {
a3170dc6
AH
12217 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
12218 info->lr_save_offset + sp_offset);
ba4828e0
RK
12219
12220 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12221
9ebbca7d 12222 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 12223 }
9ebbca7d
GK
12224
12225 /* Get the old cr if we saved it. */
12226 if (info->cr_save_p)
12227 {
12228 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12229 GEN_INT (info->cr_save_offset + sp_offset));
12230 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12231
12232 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12233
9ebbca7d
GK
12234 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
12235 }
12236
12237 /* Set LR here to try to overlap restores below. */
4697a36c 12238 if (info->lr_save_p)
9ebbca7d
GK
12239 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
12240 gen_rtx_REG (Pmode, 0));
12241
83720594
RH
12242 /* Load exception handler data registers, if needed. */
12243 if (current_function_calls_eh_return)
12244 {
78e1b90d
DE
12245 unsigned int i, regno;
12246
fc4767bb
JJ
12247 if (TARGET_AIX)
12248 {
12249 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12250 GEN_INT (sp_offset + 5 * reg_size));
12251 rtx mem = gen_rtx_MEM (reg_mode, addr);
12252
12253 set_mem_alias_set (mem, rs6000_sr_alias_set);
12254
12255 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
12256 }
12257
83720594
RH
12258 for (i = 0; ; ++i)
12259 {
a3170dc6 12260 rtx mem;
83720594
RH
12261
12262 regno = EH_RETURN_DATA_REGNO (i);
12263 if (regno == INVALID_REGNUM)
12264 break;
12265
a3170dc6
AH
12266 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
12267 info->ehrd_offset + sp_offset
12268 + reg_size * (int) i);
ba4828e0 12269 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
12270
12271 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
12272 }
12273 }
9ebbca7d
GK
12274
12275 /* Restore GPRs. This is done as a PARALLEL if we are using
12276 the load-multiple instructions. */
12277 if (using_load_multiple)
979721f8 12278 {
9ebbca7d
GK
12279 rtvec p;
12280 p = rtvec_alloc (32 - info->first_gp_reg_save);
12281 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 12282 {
9ebbca7d
GK
12283 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12284 GEN_INT (info->gp_save_offset
12285 + sp_offset
12286 + reg_size * i));
12287 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
12288
12289 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12290
12291 RTVEC_ELT (p, i) =
12292 gen_rtx_SET (VOIDmode,
12293 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
12294 mem);
979721f8 12295 }
9ebbca7d 12296 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 12297 }
9ebbca7d
GK
12298 else
12299 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12300 if ((regs_ever_live[info->first_gp_reg_save+i]
12301 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12302 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12303 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12304 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
12305 {
12306 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12307 GEN_INT (info->gp_save_offset
12308 + sp_offset
12309 + reg_size * i));
12310 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12311
a3170dc6 12312 /* Restore 64-bit quantities for SPE. */
c19de7aa 12313 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12314 {
12315 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12316 rtx b;
12317
12318 if (!SPE_CONST_OFFSET_OK (offset))
12319 {
12320 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12321 emit_move_insn (b, GEN_INT (offset));
12322 }
12323 else
12324 b = GEN_INT (offset);
12325
12326 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12327 mem = gen_rtx_MEM (V2SImode, addr);
12328 }
12329
ba4828e0 12330 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12331
12332 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 12333 info->first_gp_reg_save + i), mem);
9ebbca7d 12334 }
9878760c 12335
9ebbca7d
GK
12336 /* Restore fpr's if we need to do it without calling a function. */
12337 if (restoring_FPRs_inline)
12338 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12339 if ((regs_ever_live[info->first_fp_reg_save+i]
12340 && ! call_used_regs[info->first_fp_reg_save+i]))
12341 {
12342 rtx addr, mem;
12343 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12344 GEN_INT (info->fp_save_offset
12345 + sp_offset
a4f6c312 12346 + 8 * i));
9ebbca7d 12347 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12348 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12349
12350 emit_move_insn (gen_rtx_REG (DFmode,
12351 info->first_fp_reg_save + i),
12352 mem);
12353 }
8d30c4ee 12354
9ebbca7d
GK
12355 /* If we saved cr, restore it here. Just those that were used. */
12356 if (info->cr_save_p)
979721f8 12357 {
9ebbca7d 12358 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 12359 int count = 0;
9ebbca7d
GK
12360
12361 if (using_mfcr_multiple)
979721f8 12362 {
9ebbca7d
GK
12363 for (i = 0; i < 8; i++)
12364 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 12365 count++;
9ebbca7d 12366 if (count == 0)
e35b9579
GK
12367 abort ();
12368 }
12369
12370 if (using_mfcr_multiple && count > 1)
12371 {
12372 rtvec p;
12373 int ndx;
9ebbca7d 12374
e35b9579 12375 p = rtvec_alloc (count);
9ebbca7d 12376
e35b9579 12377 ndx = 0;
9ebbca7d
GK
12378 for (i = 0; i < 8; i++)
12379 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
12380 {
12381 rtvec r = rtvec_alloc (2);
12382 RTVEC_ELT (r, 0) = r12_rtx;
12383 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 12384 RTVEC_ELT (p, ndx) =
9ebbca7d 12385 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 12386 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 12387 ndx++;
9ebbca7d
GK
12388 }
12389 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
12390 if (ndx != count)
12391 abort ();
979721f8
MM
12392 }
12393 else
9ebbca7d
GK
12394 for (i = 0; i < 8; i++)
12395 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 12396 {
9ebbca7d
GK
12397 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
12398 CR0_REGNO+i),
12399 r12_rtx));
979721f8 12400 }
979721f8
MM
12401 }
12402
9ebbca7d
GK
12403 /* If this is V.4, unwind the stack pointer after all of the loads
12404 have been done. We need to emit a block here so that sched
12405 doesn't decide to move the sp change before the register restores
12406 (which may not have any obvious dependency on the stack). This
12407 doesn't hurt performance, because there is no scheduling that can
12408 be done after this point. */
fc4767bb
JJ
12409 if (DEFAULT_ABI == ABI_V4
12410 || current_function_calls_eh_return)
b6c9286a 12411 {
9ebbca7d
GK
12412 if (frame_reg_rtx != sp_reg_rtx)
12413 rs6000_emit_stack_tie ();
b6c9286a 12414
9ebbca7d 12415 if (use_backchain_to_restore_sp)
b6c9286a 12416 {
9ebbca7d 12417 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12418 }
9ebbca7d 12419 else if (sp_offset != 0)
13f1623b 12420 {
5b71a4e7 12421 emit_insn (TARGET_32BIT
9ebbca7d
GK
12422 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12423 GEN_INT (sp_offset))
12424 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12425 GEN_INT (sp_offset)));
13f1623b 12426 }
9ebbca7d 12427 }
b6c9286a 12428
83720594
RH
12429 if (current_function_calls_eh_return)
12430 {
12431 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12432 emit_insn (TARGET_32BIT
83720594
RH
12433 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12434 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12435 }
12436
9ebbca7d
GK
12437 if (!sibcall)
12438 {
12439 rtvec p;
12440 if (! restoring_FPRs_inline)
12441 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12442 else
12443 p = rtvec_alloc (2);
b6c9286a 12444
e35b9579
GK
12445 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12446 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12447 gen_rtx_REG (Pmode,
12448 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12449
12450 /* If we have to restore more than two FP registers, branch to the
12451 restore function. It will return to our caller. */
12452 if (! restoring_FPRs_inline)
12453 {
12454 int i;
12455 char rname[30];
520a57c8 12456 const char *alloc_rname;
979721f8 12457
9ebbca7d
GK
12458 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12459 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12460 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12461 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12462 gen_rtx_SYMBOL_REF (Pmode,
12463 alloc_rname));
b6c9286a 12464
9ebbca7d
GK
12465 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12466 {
12467 rtx addr, mem;
12468 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12469 GEN_INT (info->fp_save_offset + 8*i));
12470 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12471 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12472
12473 RTVEC_ELT (p, i+3) =
12474 gen_rtx_SET (VOIDmode,
12475 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12476 mem);
b6c9286a
MM
12477 }
12478 }
9ebbca7d
GK
12479
12480 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 12481 }
9878760c
RK
12482}
12483
12484/* Write function epilogue. */
12485
08c148a8 12486static void
a2369ed3
DJ
12487rs6000_output_function_epilogue (FILE *file,
12488 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 12489{
4697a36c 12490 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 12491
9ebbca7d 12492 if (! HAVE_epilogue)
9878760c 12493 {
9ebbca7d
GK
12494 rtx insn = get_last_insn ();
12495 /* If the last insn was a BARRIER, we don't have to write anything except
12496 the trace table. */
12497 if (GET_CODE (insn) == NOTE)
12498 insn = prev_nonnote_insn (insn);
12499 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 12500 {
9ebbca7d
GK
12501 /* This is slightly ugly, but at least we don't have two
12502 copies of the epilogue-emitting code. */
12503 start_sequence ();
12504
12505 /* A NOTE_INSN_DELETED is supposed to be at the start
12506 and end of the "toplevel" insn chain. */
2e040219 12507 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12508 rs6000_emit_epilogue (FALSE);
2e040219 12509 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12510
a3c9585f 12511 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12512 {
12513 rtx insn;
12514 unsigned addr = 0;
12515 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12516 {
12517 INSN_ADDRESSES_NEW (insn, addr);
12518 addr += 4;
12519 }
12520 }
12521
9ebbca7d 12522 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12523 debug_rtx_list (get_insns (), 100);
12524 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12525 end_sequence ();
4697a36c 12526 }
9878760c 12527 }
b4ac57ab 12528
efdba735
SH
12529#if TARGET_MACHO
12530 macho_branch_islands ();
0e5da0be
GK
12531 /* Mach-O doesn't support labels at the end of objects, so if
12532 it looks like we might want one, insert a NOP. */
12533 {
12534 rtx insn = get_last_insn ();
12535 while (insn
12536 && NOTE_P (insn)
12537 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
12538 insn = PREV_INSN (insn);
12539 if (insn
12540 && (LABEL_P (insn)
12541 || (NOTE_P (insn)
12542 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
12543 fputs ("\tnop\n", file);
12544 }
12545#endif
12546
9b30bae2 12547 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
12548 on its format.
12549
12550 We don't output a traceback table if -finhibit-size-directive was
12551 used. The documentation for -finhibit-size-directive reads
12552 ``don't output a @code{.size} assembler directive, or anything
12553 else that would cause trouble if the function is split in the
12554 middle, and the two halves are placed at locations far apart in
12555 memory.'' The traceback table has this property, since it
12556 includes the offset from the start of the function to the
4d30c363
MM
12557 traceback table itself.
12558
12559 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 12560 different traceback table. */
57ac7be9
AM
12561 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
12562 && rs6000_traceback != traceback_none)
9b30bae2 12563 {
69c75916 12564 const char *fname = NULL;
3ac88239 12565 const char *language_string = lang_hooks.name;
6041bf2f 12566 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 12567 int i;
57ac7be9
AM
12568 int optional_tbtab;
12569
12570 if (rs6000_traceback == traceback_full)
12571 optional_tbtab = 1;
12572 else if (rs6000_traceback == traceback_part)
12573 optional_tbtab = 0;
12574 else
12575 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 12576
69c75916
AM
12577 if (optional_tbtab)
12578 {
12579 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
12580 while (*fname == '.') /* V.4 encodes . in the name */
12581 fname++;
12582
12583 /* Need label immediately before tbtab, so we can compute
12584 its offset from the function start. */
12585 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
12586 ASM_OUTPUT_LABEL (file, fname);
12587 }
314fc5a9
ILT
12588
12589 /* The .tbtab pseudo-op can only be used for the first eight
12590 expressions, since it can't handle the possibly variable
12591 length fields that follow. However, if you omit the optional
12592 fields, the assembler outputs zeros for all optional fields
12593 anyways, giving each variable length field is minimum length
12594 (as defined in sys/debug.h). Thus we can not use the .tbtab
12595 pseudo-op at all. */
12596
12597 /* An all-zero word flags the start of the tbtab, for debuggers
12598 that have to find it by searching forward from the entry
12599 point or from the current pc. */
19d2d16f 12600 fputs ("\t.long 0\n", file);
314fc5a9
ILT
12601
12602 /* Tbtab format type. Use format type 0. */
19d2d16f 12603 fputs ("\t.byte 0,", file);
314fc5a9 12604
5fc921c1
DE
12605 /* Language type. Unfortunately, there does not seem to be any
12606 official way to discover the language being compiled, so we
12607 use language_string.
12608 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
12609 Java is 13. Objective-C is 14. */
12610 if (! strcmp (language_string, "GNU C"))
314fc5a9
ILT
12611 i = 0;
12612 else if (! strcmp (language_string, "GNU F77"))
12613 i = 1;
8b83775b 12614 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 12615 i = 2;
5fc921c1
DE
12616 else if (! strcmp (language_string, "GNU Ada"))
12617 i = 3;
314fc5a9
ILT
12618 else if (! strcmp (language_string, "GNU C++"))
12619 i = 9;
9517ead8
AG
12620 else if (! strcmp (language_string, "GNU Java"))
12621 i = 13;
5fc921c1
DE
12622 else if (! strcmp (language_string, "GNU Objective-C"))
12623 i = 14;
314fc5a9
ILT
12624 else
12625 abort ();
12626 fprintf (file, "%d,", i);
12627
12628 /* 8 single bit fields: global linkage (not set for C extern linkage,
12629 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
12630 from start of procedure stored in tbtab, internal function, function
12631 has controlled storage, function has no toc, function uses fp,
12632 function logs/aborts fp operations. */
12633 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
12634 fprintf (file, "%d,",
12635 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
12636
12637 /* 6 bitfields: function is interrupt handler, name present in
12638 proc table, function calls alloca, on condition directives
12639 (controls stack walks, 3 bits), saves condition reg, saves
12640 link reg. */
12641 /* The `function calls alloca' bit seems to be set whenever reg 31 is
12642 set up as a frame pointer, even when there is no alloca call. */
12643 fprintf (file, "%d,",
6041bf2f
DE
12644 ((optional_tbtab << 6)
12645 | ((optional_tbtab & frame_pointer_needed) << 5)
12646 | (info->cr_save_p << 1)
12647 | (info->lr_save_p)));
314fc5a9 12648
6041bf2f 12649 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
12650 (6 bits). */
12651 fprintf (file, "%d,",
4697a36c 12652 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
12653
12654 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
12655 fprintf (file, "%d,", (32 - first_reg_to_save ()));
12656
6041bf2f
DE
12657 if (optional_tbtab)
12658 {
12659 /* Compute the parameter info from the function decl argument
12660 list. */
12661 tree decl;
12662 int next_parm_info_bit = 31;
314fc5a9 12663
6041bf2f
DE
12664 for (decl = DECL_ARGUMENTS (current_function_decl);
12665 decl; decl = TREE_CHAIN (decl))
12666 {
12667 rtx parameter = DECL_INCOMING_RTL (decl);
12668 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 12669
6041bf2f
DE
12670 if (GET_CODE (parameter) == REG)
12671 {
12672 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
12673 {
12674 int bits;
12675
12676 float_parms++;
12677
12678 if (mode == SFmode)
12679 bits = 0x2;
fcce224d 12680 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
12681 bits = 0x3;
12682 else
12683 abort ();
12684
12685 /* If only one bit will fit, don't or in this entry. */
12686 if (next_parm_info_bit > 0)
12687 parm_info |= (bits << (next_parm_info_bit - 1));
12688 next_parm_info_bit -= 2;
12689 }
12690 else
12691 {
12692 fixed_parms += ((GET_MODE_SIZE (mode)
12693 + (UNITS_PER_WORD - 1))
12694 / UNITS_PER_WORD);
12695 next_parm_info_bit -= 1;
12696 }
12697 }
12698 }
12699 }
314fc5a9
ILT
12700
12701 /* Number of fixed point parameters. */
12702 /* This is actually the number of words of fixed point parameters; thus
12703 an 8 byte struct counts as 2; and thus the maximum value is 8. */
12704 fprintf (file, "%d,", fixed_parms);
12705
12706 /* 2 bitfields: number of floating point parameters (7 bits), parameters
12707 all on stack. */
12708 /* This is actually the number of fp registers that hold parameters;
12709 and thus the maximum value is 13. */
12710 /* Set parameters on stack bit if parameters are not in their original
12711 registers, regardless of whether they are on the stack? Xlc
12712 seems to set the bit when not optimizing. */
12713 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
12714
6041bf2f
DE
12715 if (! optional_tbtab)
12716 return;
12717
314fc5a9
ILT
12718 /* Optional fields follow. Some are variable length. */
12719
12720 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
12721 11 double float. */
12722 /* There is an entry for each parameter in a register, in the order that
12723 they occur in the parameter list. Any intervening arguments on the
12724 stack are ignored. If the list overflows a long (max possible length
12725 34 bits) then completely leave off all elements that don't fit. */
12726 /* Only emit this long if there was at least one parameter. */
12727 if (fixed_parms || float_parms)
12728 fprintf (file, "\t.long %d\n", parm_info);
12729
12730 /* Offset from start of code to tb table. */
19d2d16f 12731 fputs ("\t.long ", file);
314fc5a9 12732 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
12733#if TARGET_AIX
12734 RS6000_OUTPUT_BASENAME (file, fname);
12735#else
9ebbca7d 12736 assemble_name (file, fname);
54ee9799 12737#endif
19d2d16f 12738 fputs ("-.", file);
54ee9799
DE
12739#if TARGET_AIX
12740 RS6000_OUTPUT_BASENAME (file, fname);
12741#else
9ebbca7d 12742 assemble_name (file, fname);
54ee9799 12743#endif
19d2d16f 12744 putc ('\n', file);
314fc5a9
ILT
12745
12746 /* Interrupt handler mask. */
12747 /* Omit this long, since we never set the interrupt handler bit
12748 above. */
12749
12750 /* Number of CTL (controlled storage) anchors. */
12751 /* Omit this long, since the has_ctl bit is never set above. */
12752
12753 /* Displacement into stack of each CTL anchor. */
12754 /* Omit this list of longs, because there are no CTL anchors. */
12755
12756 /* Length of function name. */
69c75916
AM
12757 if (*fname == '*')
12758 ++fname;
296b8152 12759 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
12760
12761 /* Function name. */
12762 assemble_string (fname, strlen (fname));
12763
12764 /* Register for alloca automatic storage; this is always reg 31.
12765 Only emit this if the alloca bit was set above. */
12766 if (frame_pointer_needed)
19d2d16f 12767 fputs ("\t.byte 31\n", file);
b1765bde
DE
12768
12769 fputs ("\t.align 2\n", file);
9b30bae2 12770 }
9878760c 12771}
17167fd8 12772\f
a4f6c312
SS
12773/* A C compound statement that outputs the assembler code for a thunk
12774 function, used to implement C++ virtual function calls with
12775 multiple inheritance. The thunk acts as a wrapper around a virtual
12776 function, adjusting the implicit object parameter before handing
12777 control off to the real function.
12778
12779 First, emit code to add the integer DELTA to the location that
12780 contains the incoming first argument. Assume that this argument
12781 contains a pointer, and is the one used to pass the `this' pointer
12782 in C++. This is the incoming argument *before* the function
12783 prologue, e.g. `%o0' on a sparc. The addition must preserve the
12784 values of all other incoming arguments.
17167fd8
MM
12785
12786 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
12787 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
12788 not touch the return address. Hence returning from FUNCTION will
12789 return to whoever called the current `thunk'.
17167fd8 12790
a4f6c312
SS
12791 The effect must be as if FUNCTION had been called directly with the
12792 adjusted first argument. This macro is responsible for emitting
12793 all of the code for a thunk function; output_function_prologue()
12794 and output_function_epilogue() are not invoked.
17167fd8 12795
a4f6c312
SS
12796 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
12797 been extracted from it.) It might possibly be useful on some
12798 targets, but probably not.
17167fd8 12799
a4f6c312
SS
12800 If you do not define this macro, the target-independent code in the
12801 C++ frontend will generate a less efficient heavyweight thunk that
12802 calls FUNCTION instead of jumping to it. The generic approach does
12803 not support varargs. */
17167fd8 12804
3961e8fe 12805static void
a2369ed3
DJ
12806rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
12807 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
12808 tree function)
17167fd8 12809{
5b71a4e7 12810 rtx this, insn, funexp;
17167fd8 12811
5b71a4e7 12812 reload_completed = 1;
fe3ad572 12813 epilogue_completed = 1;
5b71a4e7 12814 no_new_pseudos = 1;
56a7189a 12815
5b71a4e7 12816 /* Mark the end of the (empty) prologue. */
2e040219 12817 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 12818
5b71a4e7
DE
12819 /* Find the "this" pointer. If the function returns a structure,
12820 the structure return pointer is in r3. */
61f71b34 12821 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 12822 this = gen_rtx_REG (Pmode, 4);
56a7189a 12823 else
5b71a4e7 12824 this = gen_rtx_REG (Pmode, 3);
17167fd8 12825
5b71a4e7
DE
12826 /* Apply the constant offset, if required. */
12827 if (delta)
12828 {
12829 rtx delta_rtx = GEN_INT (delta);
12830 emit_insn (TARGET_32BIT
12831 ? gen_addsi3 (this, this, delta_rtx)
12832 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
12833 }
12834
5b71a4e7
DE
12835 /* Apply the offset from the vtable, if required. */
12836 if (vcall_offset)
17167fd8 12837 {
5b71a4e7
DE
12838 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
12839 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 12840
5b71a4e7 12841 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
12842 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
12843 {
12844 emit_insn (TARGET_32BIT
12845 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
12846 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
12847 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
12848 }
12849 else
12850 {
12851 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
12852
12853 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
12854 }
5b71a4e7
DE
12855 emit_insn (TARGET_32BIT
12856 ? gen_addsi3 (this, this, tmp)
12857 : gen_adddi3 (this, this, tmp));
17167fd8
MM
12858 }
12859
5b71a4e7
DE
12860 /* Generate a tail call to the target function. */
12861 if (!TREE_USED (function))
12862 {
12863 assemble_external (function);
12864 TREE_USED (function) = 1;
12865 }
12866 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 12867 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
12868
12869#if TARGET_MACHO
ab82a49f 12870 if (MACHOPIC_INDIRECT)
5b71a4e7 12871 funexp = machopic_indirect_call_target (funexp);
ee890fe2 12872#endif
5b71a4e7
DE
12873
12874 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
12875 generate sibcall RTL explicitly to avoid constraint abort. */
12876 insn = emit_call_insn (
12877 gen_rtx_PARALLEL (VOIDmode,
12878 gen_rtvec (4,
12879 gen_rtx_CALL (VOIDmode,
12880 funexp, const0_rtx),
12881 gen_rtx_USE (VOIDmode, const0_rtx),
12882 gen_rtx_USE (VOIDmode,
12883 gen_rtx_REG (SImode,
12884 LINK_REGISTER_REGNUM)),
12885 gen_rtx_RETURN (VOIDmode))));
12886 SIBLING_CALL_P (insn) = 1;
12887 emit_barrier ();
12888
12889 /* Run just enough of rest_of_compilation to get the insns emitted.
12890 There's not really enough bulk here to make other passes such as
12891 instruction scheduling worth while. Note that use_thunk calls
12892 assemble_start_function and assemble_end_function. */
12893 insn = get_insns ();
a2855205 12894 insn_locators_initialize ();
5b71a4e7
DE
12895 shorten_branches (insn);
12896 final_start_function (insn, file, 1);
12897 final (insn, file, 1, 0);
12898 final_end_function ();
12899
12900 reload_completed = 0;
fe3ad572 12901 epilogue_completed = 0;
5b71a4e7 12902 no_new_pseudos = 0;
9ebbca7d 12903}
9ebbca7d
GK
12904\f
12905/* A quick summary of the various types of 'constant-pool tables'
12906 under PowerPC:
12907
12908 Target Flags Name One table per
12909 AIX (none) AIX TOC object file
12910 AIX -mfull-toc AIX TOC object file
12911 AIX -mminimal-toc AIX minimal TOC translation unit
12912 SVR4/EABI (none) SVR4 SDATA object file
12913 SVR4/EABI -fpic SVR4 pic object file
12914 SVR4/EABI -fPIC SVR4 PIC translation unit
12915 SVR4/EABI -mrelocatable EABI TOC function
12916 SVR4/EABI -maix AIX TOC object file
12917 SVR4/EABI -maix -mminimal-toc
12918 AIX minimal TOC translation unit
12919
12920 Name Reg. Set by entries contains:
12921 made by addrs? fp? sum?
12922
12923 AIX TOC 2 crt0 as Y option option
12924 AIX minimal TOC 30 prolog gcc Y Y option
12925 SVR4 SDATA 13 crt0 gcc N Y N
12926 SVR4 pic 30 prolog ld Y not yet N
12927 SVR4 PIC 30 prolog gcc Y option option
12928 EABI TOC 30 prolog gcc Y option option
12929
12930*/
12931
9ebbca7d
GK
12932/* Hash functions for the hash table. */
12933
12934static unsigned
a2369ed3 12935rs6000_hash_constant (rtx k)
9ebbca7d 12936{
46b33600
RH
12937 enum rtx_code code = GET_CODE (k);
12938 enum machine_mode mode = GET_MODE (k);
12939 unsigned result = (code << 3) ^ mode;
12940 const char *format;
12941 int flen, fidx;
9ebbca7d 12942
46b33600
RH
12943 format = GET_RTX_FORMAT (code);
12944 flen = strlen (format);
12945 fidx = 0;
9ebbca7d 12946
46b33600
RH
12947 switch (code)
12948 {
12949 case LABEL_REF:
12950 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
12951
12952 case CONST_DOUBLE:
12953 if (mode != VOIDmode)
12954 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
12955 flen = 2;
12956 break;
12957
12958 case CODE_LABEL:
12959 fidx = 3;
12960 break;
12961
12962 default:
12963 break;
12964 }
9ebbca7d
GK
12965
12966 for (; fidx < flen; fidx++)
12967 switch (format[fidx])
12968 {
12969 case 's':
12970 {
12971 unsigned i, len;
12972 const char *str = XSTR (k, fidx);
12973 len = strlen (str);
12974 result = result * 613 + len;
12975 for (i = 0; i < len; i++)
12976 result = result * 613 + (unsigned) str[i];
17167fd8
MM
12977 break;
12978 }
9ebbca7d
GK
12979 case 'u':
12980 case 'e':
12981 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
12982 break;
12983 case 'i':
12984 case 'n':
12985 result = result * 613 + (unsigned) XINT (k, fidx);
12986 break;
12987 case 'w':
12988 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
12989 result = result * 613 + (unsigned) XWINT (k, fidx);
12990 else
12991 {
12992 size_t i;
12993 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
12994 result = result * 613 + (unsigned) (XWINT (k, fidx)
12995 >> CHAR_BIT * i);
12996 }
12997 break;
09501938
DE
12998 case '0':
12999 break;
9ebbca7d 13000 default:
a4f6c312 13001 abort ();
9ebbca7d 13002 }
46b33600 13003
9ebbca7d
GK
13004 return result;
13005}
13006
13007static unsigned
a2369ed3 13008toc_hash_function (const void *hash_entry)
9ebbca7d 13009{
a9098fd0
GK
13010 const struct toc_hash_struct *thc =
13011 (const struct toc_hash_struct *) hash_entry;
13012 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
13013}
13014
13015/* Compare H1 and H2 for equivalence. */
13016
13017static int
a2369ed3 13018toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
13019{
13020 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
13021 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
13022
a9098fd0
GK
13023 if (((const struct toc_hash_struct *) h1)->key_mode
13024 != ((const struct toc_hash_struct *) h2)->key_mode)
13025 return 0;
13026
5692c7bc 13027 return rtx_equal_p (r1, r2);
9ebbca7d
GK
13028}
13029
28e510bd
MM
13030/* These are the names given by the C++ front-end to vtables, and
13031 vtable-like objects. Ideally, this logic should not be here;
13032 instead, there should be some programmatic way of inquiring as
13033 to whether or not an object is a vtable. */
13034
13035#define VTABLE_NAME_P(NAME) \
13036 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
13037 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
13038 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
13039 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
13040
13041void
a2369ed3 13042rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
13043{
13044 /* Currently C++ toc references to vtables can be emitted before it
13045 is decided whether the vtable is public or private. If this is
13046 the case, then the linker will eventually complain that there is
13047 a reference to an unknown section. Thus, for vtables only,
13048 we emit the TOC reference to reference the symbol and not the
13049 section. */
13050 const char *name = XSTR (x, 0);
54ee9799
DE
13051
13052 if (VTABLE_NAME_P (name))
13053 {
13054 RS6000_OUTPUT_BASENAME (file, name);
13055 }
13056 else
13057 assemble_name (file, name);
28e510bd
MM
13058}
13059
a4f6c312
SS
13060/* Output a TOC entry. We derive the entry name from what is being
13061 written. */
9878760c
RK
13062
13063void
a2369ed3 13064output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
13065{
13066 char buf[256];
3cce094d 13067 const char *name = buf;
ec940faa 13068 const char *real_name;
9878760c
RK
13069 rtx base = x;
13070 int offset = 0;
13071
4697a36c
MM
13072 if (TARGET_NO_TOC)
13073 abort ();
13074
9ebbca7d
GK
13075 /* When the linker won't eliminate them, don't output duplicate
13076 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
13077 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
13078 CODE_LABELs. */
13079 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
13080 {
13081 struct toc_hash_struct *h;
13082 void * * found;
13083
17211ab5 13084 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 13085 time because GGC is not initialized at that point. */
17211ab5
GK
13086 if (toc_hash_table == NULL)
13087 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
13088 toc_hash_eq, NULL);
13089
9ebbca7d
GK
13090 h = ggc_alloc (sizeof (*h));
13091 h->key = x;
a9098fd0 13092 h->key_mode = mode;
9ebbca7d
GK
13093 h->labelno = labelno;
13094
13095 found = htab_find_slot (toc_hash_table, h, 1);
13096 if (*found == NULL)
13097 *found = h;
13098 else /* This is indeed a duplicate.
13099 Set this label equal to that label. */
13100 {
13101 fputs ("\t.set ", file);
13102 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13103 fprintf (file, "%d,", labelno);
13104 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13105 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
13106 found)->labelno));
13107 return;
13108 }
13109 }
13110
13111 /* If we're going to put a double constant in the TOC, make sure it's
13112 aligned properly when strict alignment is on. */
ff1720ed
RK
13113 if (GET_CODE (x) == CONST_DOUBLE
13114 && STRICT_ALIGNMENT
a9098fd0 13115 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
13116 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
13117 ASM_OUTPUT_ALIGN (file, 3);
13118 }
13119
4977bab6 13120 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 13121
37c37a57
RK
13122 /* Handle FP constants specially. Note that if we have a minimal
13123 TOC, things we put here aren't actually in the TOC, so we can allow
13124 FP constants. */
fcce224d
DE
13125 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
13126 {
13127 REAL_VALUE_TYPE rv;
13128 long k[4];
13129
13130 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13131 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
13132
13133 if (TARGET_64BIT)
13134 {
13135 if (TARGET_MINIMAL_TOC)
13136 fputs (DOUBLE_INT_ASM_OP, file);
13137 else
13138 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13139 k[0] & 0xffffffff, k[1] & 0xffffffff,
13140 k[2] & 0xffffffff, k[3] & 0xffffffff);
13141 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
13142 k[0] & 0xffffffff, k[1] & 0xffffffff,
13143 k[2] & 0xffffffff, k[3] & 0xffffffff);
13144 return;
13145 }
13146 else
13147 {
13148 if (TARGET_MINIMAL_TOC)
13149 fputs ("\t.long ", file);
13150 else
13151 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13152 k[0] & 0xffffffff, k[1] & 0xffffffff,
13153 k[2] & 0xffffffff, k[3] & 0xffffffff);
13154 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
13155 k[0] & 0xffffffff, k[1] & 0xffffffff,
13156 k[2] & 0xffffffff, k[3] & 0xffffffff);
13157 return;
13158 }
13159 }
13160 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 13161 {
042259f2
DE
13162 REAL_VALUE_TYPE rv;
13163 long k[2];
0adc764e 13164
042259f2
DE
13165 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13166 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 13167
13ded975
DE
13168 if (TARGET_64BIT)
13169 {
13170 if (TARGET_MINIMAL_TOC)
2bfcf297 13171 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13172 else
2f0552b6
AM
13173 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13174 k[0] & 0xffffffff, k[1] & 0xffffffff);
13175 fprintf (file, "0x%lx%08lx\n",
13176 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13177 return;
13178 }
1875cc88 13179 else
13ded975
DE
13180 {
13181 if (TARGET_MINIMAL_TOC)
2bfcf297 13182 fputs ("\t.long ", file);
13ded975 13183 else
2f0552b6
AM
13184 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13185 k[0] & 0xffffffff, k[1] & 0xffffffff);
13186 fprintf (file, "0x%lx,0x%lx\n",
13187 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13188 return;
13189 }
9878760c 13190 }
a9098fd0 13191 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 13192 {
042259f2
DE
13193 REAL_VALUE_TYPE rv;
13194 long l;
9878760c 13195
042259f2
DE
13196 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13197 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
13198
31bfaa0b
DE
13199 if (TARGET_64BIT)
13200 {
13201 if (TARGET_MINIMAL_TOC)
2bfcf297 13202 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 13203 else
2f0552b6
AM
13204 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13205 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
13206 return;
13207 }
042259f2 13208 else
31bfaa0b
DE
13209 {
13210 if (TARGET_MINIMAL_TOC)
2bfcf297 13211 fputs ("\t.long ", file);
31bfaa0b 13212 else
2f0552b6
AM
13213 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13214 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
13215 return;
13216 }
042259f2 13217 }
f176e826 13218 else if (GET_MODE (x) == VOIDmode
a9098fd0 13219 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 13220 {
e2c953b6 13221 unsigned HOST_WIDE_INT low;
042259f2
DE
13222 HOST_WIDE_INT high;
13223
13224 if (GET_CODE (x) == CONST_DOUBLE)
13225 {
13226 low = CONST_DOUBLE_LOW (x);
13227 high = CONST_DOUBLE_HIGH (x);
13228 }
13229 else
13230#if HOST_BITS_PER_WIDE_INT == 32
13231 {
13232 low = INTVAL (x);
0858c623 13233 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
13234 }
13235#else
13236 {
0858c623 13237 low = INTVAL (x) & 0xffffffff;
042259f2
DE
13238 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
13239 }
13240#endif
9878760c 13241
a9098fd0
GK
13242 /* TOC entries are always Pmode-sized, but since this
13243 is a bigendian machine then if we're putting smaller
13244 integer constants in the TOC we have to pad them.
13245 (This is still a win over putting the constants in
13246 a separate constant pool, because then we'd have
02a4ec28
FS
13247 to have both a TOC entry _and_ the actual constant.)
13248
13249 For a 32-bit target, CONST_INT values are loaded and shifted
13250 entirely within `low' and can be stored in one TOC entry. */
13251
13252 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 13253 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
13254
13255 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
13256 {
13257#if HOST_BITS_PER_WIDE_INT == 32
13258 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
13259 POINTER_SIZE, &low, &high, 0);
13260#else
13261 low |= high << 32;
13262 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
13263 high = (HOST_WIDE_INT) low >> 32;
13264 low &= 0xffffffff;
13265#endif
13266 }
a9098fd0 13267
13ded975
DE
13268 if (TARGET_64BIT)
13269 {
13270 if (TARGET_MINIMAL_TOC)
2bfcf297 13271 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13272 else
2f0552b6
AM
13273 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
13274 (long) high & 0xffffffff, (long) low & 0xffffffff);
13275 fprintf (file, "0x%lx%08lx\n",
13276 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
13277 return;
13278 }
1875cc88 13279 else
13ded975 13280 {
02a4ec28
FS
13281 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
13282 {
13283 if (TARGET_MINIMAL_TOC)
2bfcf297 13284 fputs ("\t.long ", file);
02a4ec28 13285 else
2bfcf297 13286 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
13287 (long) high & 0xffffffff, (long) low & 0xffffffff);
13288 fprintf (file, "0x%lx,0x%lx\n",
13289 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 13290 }
13ded975 13291 else
02a4ec28
FS
13292 {
13293 if (TARGET_MINIMAL_TOC)
2bfcf297 13294 fputs ("\t.long ", file);
02a4ec28 13295 else
2f0552b6
AM
13296 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
13297 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 13298 }
13ded975
DE
13299 return;
13300 }
9878760c
RK
13301 }
13302
13303 if (GET_CODE (x) == CONST)
13304 {
2bfcf297
DB
13305 if (GET_CODE (XEXP (x, 0)) != PLUS)
13306 abort ();
13307
9878760c
RK
13308 base = XEXP (XEXP (x, 0), 0);
13309 offset = INTVAL (XEXP (XEXP (x, 0), 1));
13310 }
13311
13312 if (GET_CODE (base) == SYMBOL_REF)
13313 name = XSTR (base, 0);
13314 else if (GET_CODE (base) == LABEL_REF)
13315 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
13316 else if (GET_CODE (base) == CODE_LABEL)
13317 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
13318 else
13319 abort ();
13320
772c5265 13321 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 13322 if (TARGET_MINIMAL_TOC)
2bfcf297 13323 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
13324 else
13325 {
b6c9286a 13326 fprintf (file, "\t.tc %s", real_name);
9878760c 13327
1875cc88
JW
13328 if (offset < 0)
13329 fprintf (file, ".N%d", - offset);
13330 else if (offset)
13331 fprintf (file, ".P%d", offset);
9878760c 13332
19d2d16f 13333 fputs ("[TC],", file);
1875cc88 13334 }
581bc4de
MM
13335
13336 /* Currently C++ toc references to vtables can be emitted before it
13337 is decided whether the vtable is public or private. If this is
13338 the case, then the linker will eventually complain that there is
13339 a TOC reference to an unknown section. Thus, for vtables only,
13340 we emit the TOC reference to reference the symbol and not the
13341 section. */
28e510bd 13342 if (VTABLE_NAME_P (name))
581bc4de 13343 {
54ee9799 13344 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
13345 if (offset < 0)
13346 fprintf (file, "%d", offset);
13347 else if (offset > 0)
13348 fprintf (file, "+%d", offset);
13349 }
13350 else
13351 output_addr_const (file, x);
19d2d16f 13352 putc ('\n', file);
9878760c
RK
13353}
13354\f
13355/* Output an assembler pseudo-op to write an ASCII string of N characters
13356 starting at P to FILE.
13357
13358 On the RS/6000, we have to do this using the .byte operation and
13359 write out special characters outside the quoted string.
13360 Also, the assembler is broken; very long strings are truncated,
a4f6c312 13361 so we must artificially break them up early. */
9878760c
RK
13362
13363void
a2369ed3 13364output_ascii (FILE *file, const char *p, int n)
9878760c
RK
13365{
13366 char c;
13367 int i, count_string;
d330fd93
KG
13368 const char *for_string = "\t.byte \"";
13369 const char *for_decimal = "\t.byte ";
13370 const char *to_close = NULL;
9878760c
RK
13371
13372 count_string = 0;
13373 for (i = 0; i < n; i++)
13374 {
13375 c = *p++;
13376 if (c >= ' ' && c < 0177)
13377 {
13378 if (for_string)
13379 fputs (for_string, file);
13380 putc (c, file);
13381
13382 /* Write two quotes to get one. */
13383 if (c == '"')
13384 {
13385 putc (c, file);
13386 ++count_string;
13387 }
13388
13389 for_string = NULL;
13390 for_decimal = "\"\n\t.byte ";
13391 to_close = "\"\n";
13392 ++count_string;
13393
13394 if (count_string >= 512)
13395 {
13396 fputs (to_close, file);
13397
13398 for_string = "\t.byte \"";
13399 for_decimal = "\t.byte ";
13400 to_close = NULL;
13401 count_string = 0;
13402 }
13403 }
13404 else
13405 {
13406 if (for_decimal)
13407 fputs (for_decimal, file);
13408 fprintf (file, "%d", c);
13409
13410 for_string = "\n\t.byte \"";
13411 for_decimal = ", ";
13412 to_close = "\n";
13413 count_string = 0;
13414 }
13415 }
13416
13417 /* Now close the string if we have written one. Then end the line. */
13418 if (to_close)
9ebbca7d 13419 fputs (to_close, file);
9878760c
RK
13420}
13421\f
13422/* Generate a unique section name for FILENAME for a section type
13423 represented by SECTION_DESC. Output goes into BUF.
13424
13425 SECTION_DESC can be any string, as long as it is different for each
13426 possible section type.
13427
13428 We name the section in the same manner as xlc. The name begins with an
13429 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13430 names) with the last period replaced by the string SECTION_DESC. If
13431 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13432 the name. */
9878760c
RK
13433
13434void
a2369ed3
DJ
13435rs6000_gen_section_name (char **buf, const char *filename,
13436 const char *section_desc)
9878760c 13437{
9ebbca7d 13438 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13439 char *p;
13440 int len;
9878760c
RK
13441
13442 after_last_slash = filename;
13443 for (q = filename; *q; q++)
11e5fe42
RK
13444 {
13445 if (*q == '/')
13446 after_last_slash = q + 1;
13447 else if (*q == '.')
13448 last_period = q;
13449 }
9878760c 13450
11e5fe42 13451 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13452 *buf = (char *) xmalloc (len);
9878760c
RK
13453
13454 p = *buf;
13455 *p++ = '_';
13456
13457 for (q = after_last_slash; *q; q++)
13458 {
11e5fe42 13459 if (q == last_period)
9878760c
RK
13460 {
13461 strcpy (p, section_desc);
13462 p += strlen (section_desc);
e3981aab 13463 break;
9878760c
RK
13464 }
13465
e9a780ec 13466 else if (ISALNUM (*q))
9878760c
RK
13467 *p++ = *q;
13468 }
13469
11e5fe42 13470 if (last_period == 0)
9878760c
RK
13471 strcpy (p, section_desc);
13472 else
13473 *p = '\0';
13474}
e165f3f0 13475\f
a4f6c312 13476/* Emit profile function. */
411707f4 13477
411707f4 13478void
a2369ed3 13479output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 13480{
ffcfcb5f
AM
13481 if (TARGET_PROFILE_KERNEL)
13482 return;
13483
8480e480
CC
13484 if (DEFAULT_ABI == ABI_AIX)
13485 {
9739c90c
JJ
13486#ifndef NO_PROFILE_COUNTERS
13487# define NO_PROFILE_COUNTERS 0
13488#endif
13489 if (NO_PROFILE_COUNTERS)
13490 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
13491 else
13492 {
13493 char buf[30];
13494 const char *label_name;
13495 rtx fun;
411707f4 13496
9739c90c
JJ
13497 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
13498 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
13499 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 13500
9739c90c
JJ
13501 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
13502 fun, Pmode);
13503 }
8480e480 13504 }
ee890fe2
SS
13505 else if (DEFAULT_ABI == ABI_DARWIN)
13506 {
d5fa86ba 13507 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
13508 int caller_addr_regno = LINK_REGISTER_REGNUM;
13509
13510 /* Be conservative and always set this, at least for now. */
13511 current_function_uses_pic_offset_table = 1;
13512
13513#if TARGET_MACHO
13514 /* For PIC code, set up a stub and collect the caller's address
13515 from r0, which is where the prologue puts it. */
ab82a49f 13516 if (MACHOPIC_INDIRECT)
ee890fe2
SS
13517 {
13518 mcount_name = machopic_stub_name (mcount_name);
13519 if (current_function_uses_pic_offset_table)
13520 caller_addr_regno = 0;
13521 }
13522#endif
13523 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
13524 0, VOIDmode, 1,
13525 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
13526 }
411707f4
CC
13527}
13528
a4f6c312 13529/* Write function profiler code. */
e165f3f0
RK
13530
13531void
a2369ed3 13532output_function_profiler (FILE *file, int labelno)
e165f3f0 13533{
3daf36a4 13534 char buf[100];
09eeeacb 13535 int save_lr = 8;
e165f3f0 13536
38c1f2d7 13537 switch (DEFAULT_ABI)
3daf36a4 13538 {
38c1f2d7
MM
13539 default:
13540 abort ();
13541
13542 case ABI_V4:
09eeeacb 13543 save_lr = 4;
09eeeacb
AM
13544 if (!TARGET_32BIT)
13545 {
13546 warning ("no profiling of 64-bit code for this ABI");
13547 return;
13548 }
ffcfcb5f 13549 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
13550 fprintf (file, "\tmflr %s\n", reg_names[0]);
13551 if (flag_pic == 1)
13552 {
dfdfa60f 13553 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
13554 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13555 reg_names[0], save_lr, reg_names[1]);
17167fd8 13556 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 13557 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 13558 assemble_name (file, buf);
17167fd8 13559 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 13560 }
9ebbca7d 13561 else if (flag_pic > 1)
38c1f2d7 13562 {
09eeeacb
AM
13563 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13564 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
13565 /* Now, we need to get the address of the label. */
13566 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 13567 assemble_name (file, buf);
9ebbca7d
GK
13568 fputs ("-.\n1:", file);
13569 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
13570 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
13571 reg_names[0], reg_names[11]);
13572 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
13573 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 13574 }
38c1f2d7
MM
13575 else
13576 {
17167fd8 13577 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 13578 assemble_name (file, buf);
dfdfa60f 13579 fputs ("@ha\n", file);
09eeeacb
AM
13580 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13581 reg_names[0], save_lr, reg_names[1]);
a260abc9 13582 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 13583 assemble_name (file, buf);
17167fd8 13584 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
13585 }
13586
50d440bc
NC
13587 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
13588 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
38c1f2d7
MM
13589 break;
13590
13591 case ABI_AIX:
ee890fe2 13592 case ABI_DARWIN:
ffcfcb5f
AM
13593 if (!TARGET_PROFILE_KERNEL)
13594 {
a3c9585f 13595 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
13596 }
13597 else
13598 {
13599 if (TARGET_32BIT)
13600 abort ();
13601
13602 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
13603 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
13604
13605 if (current_function_needs_context)
13606 {
13607 asm_fprintf (file, "\tstd %s,24(%s)\n",
13608 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13609 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13610 asm_fprintf (file, "\tld %s,24(%s)\n",
13611 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13612 }
13613 else
13614 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13615 }
38c1f2d7
MM
13616 break;
13617 }
e165f3f0 13618}
a251ffd0 13619
b54cf83a
DE
13620\f
13621static int
863d938c 13622rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
13623{
13624 return 1;
13625}
13626
b54cf83a
DE
13627/* Power4 load update and store update instructions are cracked into a
13628 load or store and an integer insn which are executed in the same cycle.
13629 Branches have their own dispatch slot which does not count against the
13630 GCC issue rate, but it changes the program flow so there are no other
13631 instructions to issue in this cycle. */
13632
13633static int
a2369ed3
DJ
13634rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
13635 int verbose ATTRIBUTE_UNUSED,
13636 rtx insn, int more)
b54cf83a
DE
13637{
13638 if (GET_CODE (PATTERN (insn)) == USE
13639 || GET_CODE (PATTERN (insn)) == CLOBBER)
13640 return more;
13641
13642 if (rs6000_cpu == PROCESSOR_POWER4)
13643 {
cbe26ab8
DN
13644 if (is_microcoded_insn (insn))
13645 return 0;
13646 else if (is_cracked_insn (insn))
13647 return more > 2 ? more - 2 : 0;
b54cf83a 13648 }
165b263e
DE
13649
13650 return more - 1;
b54cf83a
DE
13651}
13652
a251ffd0
TG
13653/* Adjust the cost of a scheduling dependency. Return the new cost of
13654 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
13655
c237e94a 13656static int
a2369ed3
DJ
13657rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
13658 int cost)
a251ffd0
TG
13659{
13660 if (! recog_memoized (insn))
13661 return 0;
13662
13663 if (REG_NOTE_KIND (link) != 0)
13664 return 0;
13665
13666 if (REG_NOTE_KIND (link) == 0)
13667 {
ed947a96
DJ
13668 /* Data dependency; DEP_INSN writes a register that INSN reads
13669 some cycles later. */
13670 switch (get_attr_type (insn))
13671 {
13672 case TYPE_JMPREG:
309323c2 13673 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
13674 a mtctr and bctr (and mtlr and br/blr). The first
13675 scheduling pass will not know about this latency since
13676 the mtctr instruction, which has the latency associated
13677 to it, will be generated by reload. */
309323c2 13678 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
13679 case TYPE_BRANCH:
13680 /* Leave some extra cycles between a compare and its
13681 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
13682 if ((rs6000_cpu_attr == CPU_PPC603
13683 || rs6000_cpu_attr == CPU_PPC604
13684 || rs6000_cpu_attr == CPU_PPC604E
13685 || rs6000_cpu_attr == CPU_PPC620
13686 || rs6000_cpu_attr == CPU_PPC630
13687 || rs6000_cpu_attr == CPU_PPC750
13688 || rs6000_cpu_attr == CPU_PPC7400
13689 || rs6000_cpu_attr == CPU_PPC7450
13690 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
13691 && recog_memoized (dep_insn)
13692 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
13693 && (get_attr_type (dep_insn) == TYPE_CMP
13694 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 13695 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
13696 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
13697 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 13698 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
13699 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
13700 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
13701 return cost + 2;
13702 default:
13703 break;
13704 }
a251ffd0
TG
13705 /* Fall out to return default cost. */
13706 }
13707
13708 return cost;
13709}
b6c9286a 13710
cbe26ab8 13711/* The function returns a true if INSN is microcoded.
839a4992 13712 Return false otherwise. */
cbe26ab8
DN
13713
13714static bool
13715is_microcoded_insn (rtx insn)
13716{
13717 if (!insn || !INSN_P (insn)
13718 || GET_CODE (PATTERN (insn)) == USE
13719 || GET_CODE (PATTERN (insn)) == CLOBBER)
13720 return false;
13721
13722 if (rs6000_cpu == PROCESSOR_POWER4)
13723 {
13724 enum attr_type type = get_attr_type (insn);
13725 if (type == TYPE_LOAD_EXT_U
13726 || type == TYPE_LOAD_EXT_UX
13727 || type == TYPE_LOAD_UX
13728 || type == TYPE_STORE_UX
13729 || type == TYPE_MFCR)
13730 return true;
13731 }
13732
13733 return false;
13734}
13735
5c425df5 13736/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
13737 as the first insn in a dispatch group ("dispatch-slot restricted").
13738 In this case, the returned value indicates how many dispatch slots
13739 the insn occupies (at the beginning of the group).
79ae11c4
DN
13740 Return 0 otherwise. */
13741
cbe26ab8 13742static int
79ae11c4
DN
13743is_dispatch_slot_restricted (rtx insn)
13744{
13745 enum attr_type type;
13746
13747 if (rs6000_cpu != PROCESSOR_POWER4)
13748 return 0;
13749
13750 if (!insn
13751 || insn == NULL_RTX
13752 || GET_CODE (insn) == NOTE
13753 || GET_CODE (PATTERN (insn)) == USE
13754 || GET_CODE (PATTERN (insn)) == CLOBBER)
13755 return 0;
13756
13757 type = get_attr_type (insn);
13758
13759 switch (type){
13760 case TYPE_MFCR:
13761 case TYPE_MFCRF:
13762 case TYPE_MTCR:
13763 case TYPE_DELAYED_CR:
13764 case TYPE_CR_LOGICAL:
13765 case TYPE_MTJMPR:
13766 case TYPE_MFJMPR:
13767 return 1;
13768 case TYPE_IDIV:
13769 case TYPE_LDIV:
13770 return 2;
13771 default:
13772 return 0;
13773 }
13774}
13775
cbe26ab8
DN
13776/* The function returns true if INSN is cracked into 2 instructions
13777 by the processor (and therefore occupies 2 issue slots). */
13778
13779static bool
13780is_cracked_insn (rtx insn)
13781{
13782 if (!insn || !INSN_P (insn)
13783 || GET_CODE (PATTERN (insn)) == USE
13784 || GET_CODE (PATTERN (insn)) == CLOBBER)
13785 return false;
13786
13787 if (rs6000_cpu == PROCESSOR_POWER4)
13788 {
13789 enum attr_type type = get_attr_type (insn);
13790 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
13791 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
13792 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
13793 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
13794 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
13795 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
13796 || type == TYPE_IDIV || type == TYPE_LDIV
13797 || type == TYPE_INSERT_WORD)
13798 return true;
13799 }
13800
13801 return false;
13802}
13803
13804/* The function returns true if INSN can be issued only from
a3c9585f 13805 the branch slot. */
cbe26ab8
DN
13806
13807static bool
13808is_branch_slot_insn (rtx insn)
13809{
13810 if (!insn || !INSN_P (insn)
13811 || GET_CODE (PATTERN (insn)) == USE
13812 || GET_CODE (PATTERN (insn)) == CLOBBER)
13813 return false;
13814
13815 if (rs6000_cpu == PROCESSOR_POWER4)
13816 {
13817 enum attr_type type = get_attr_type (insn);
13818 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
13819 return true;
13820 return false;
13821 }
13822
13823 return false;
13824}
79ae11c4 13825
a4f6c312 13826/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
13827 priority INSN_PRIORITY (INSN). Increase the priority to execute the
13828 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
13829 define this macro if you do not need to adjust the scheduling
13830 priorities of insns. */
bef84347 13831
c237e94a 13832static int
a2369ed3 13833rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 13834{
a4f6c312
SS
13835 /* On machines (like the 750) which have asymmetric integer units,
13836 where one integer unit can do multiply and divides and the other
13837 can't, reduce the priority of multiply/divide so it is scheduled
13838 before other integer operations. */
bef84347
VM
13839
13840#if 0
2c3c49de 13841 if (! INSN_P (insn))
bef84347
VM
13842 return priority;
13843
13844 if (GET_CODE (PATTERN (insn)) == USE)
13845 return priority;
13846
13847 switch (rs6000_cpu_attr) {
13848 case CPU_PPC750:
13849 switch (get_attr_type (insn))
13850 {
13851 default:
13852 break;
13853
13854 case TYPE_IMUL:
13855 case TYPE_IDIV:
3cb999d8
DE
13856 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
13857 priority, priority);
bef84347
VM
13858 if (priority >= 0 && priority < 0x01000000)
13859 priority >>= 3;
13860 break;
13861 }
13862 }
13863#endif
13864
79ae11c4
DN
13865 if (is_dispatch_slot_restricted (insn)
13866 && reload_completed
13867 && current_sched_info->sched_max_insns_priority
13868 && rs6000_sched_restricted_insns_priority)
13869 {
13870
13871 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
13872 if (rs6000_sched_restricted_insns_priority == 1)
13873 /* Attach highest priority to insn. This means that in
13874 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
13875 precede 'priority' (critical path) considerations. */
13876 return current_sched_info->sched_max_insns_priority;
13877 else if (rs6000_sched_restricted_insns_priority == 2)
13878 /* Increase priority of insn by a minimal amount. This means that in
13879 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
13880 precede dispatch-slot restriction considerations. */
13881 return (priority + 1);
13882 }
13883
bef84347
VM
13884 return priority;
13885}
13886
a4f6c312
SS
13887/* Return how many instructions the machine can issue per cycle. */
13888
c237e94a 13889static int
863d938c 13890rs6000_issue_rate (void)
b6c9286a 13891{
3317bab1
DE
13892 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
13893 if (!reload_completed)
13894 return 1;
13895
b6c9286a 13896 switch (rs6000_cpu_attr) {
3cb999d8
DE
13897 case CPU_RIOS1: /* ? */
13898 case CPU_RS64A:
13899 case CPU_PPC601: /* ? */
ed947a96 13900 case CPU_PPC7450:
3cb999d8 13901 return 3;
b54cf83a 13902 case CPU_PPC440:
b6c9286a 13903 case CPU_PPC603:
bef84347 13904 case CPU_PPC750:
ed947a96 13905 case CPU_PPC7400:
be12c2b0 13906 case CPU_PPC8540:
bef84347 13907 return 2;
3cb999d8 13908 case CPU_RIOS2:
b6c9286a 13909 case CPU_PPC604:
19684119 13910 case CPU_PPC604E:
b6c9286a 13911 case CPU_PPC620:
3cb999d8 13912 case CPU_PPC630:
b6c9286a 13913 return 4;
cbe26ab8
DN
13914 case CPU_POWER4:
13915 return 5;
b6c9286a
MM
13916 default:
13917 return 1;
13918 }
13919}
13920
be12c2b0
VM
13921/* Return how many instructions to look ahead for better insn
13922 scheduling. */
13923
13924static int
863d938c 13925rs6000_use_sched_lookahead (void)
be12c2b0
VM
13926{
13927 if (rs6000_cpu_attr == CPU_PPC8540)
13928 return 4;
13929 return 0;
13930}
13931
569fa502
DN
13932/* Determine is PAT refers to memory. */
13933
13934static bool
13935is_mem_ref (rtx pat)
13936{
13937 const char * fmt;
13938 int i, j;
13939 bool ret = false;
13940
13941 if (GET_CODE (pat) == MEM)
13942 return true;
13943
13944 /* Recursively process the pattern. */
13945 fmt = GET_RTX_FORMAT (GET_CODE (pat));
13946
13947 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
13948 {
13949 if (fmt[i] == 'e')
13950 ret |= is_mem_ref (XEXP (pat, i));
13951 else if (fmt[i] == 'E')
13952 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
13953 ret |= is_mem_ref (XVECEXP (pat, i, j));
13954 }
13955
13956 return ret;
13957}
13958
13959/* Determine if PAT is a PATTERN of a load insn. */
13960
13961static bool
13962is_load_insn1 (rtx pat)
13963{
13964 if (!pat || pat == NULL_RTX)
13965 return false;
13966
13967 if (GET_CODE (pat) == SET)
13968 return is_mem_ref (SET_SRC (pat));
13969
13970 if (GET_CODE (pat) == PARALLEL)
13971 {
13972 int i;
13973
13974 for (i = 0; i < XVECLEN (pat, 0); i++)
13975 if (is_load_insn1 (XVECEXP (pat, 0, i)))
13976 return true;
13977 }
13978
13979 return false;
13980}
13981
13982/* Determine if INSN loads from memory. */
13983
13984static bool
13985is_load_insn (rtx insn)
13986{
13987 if (!insn || !INSN_P (insn))
13988 return false;
13989
13990 if (GET_CODE (insn) == CALL_INSN)
13991 return false;
13992
13993 return is_load_insn1 (PATTERN (insn));
13994}
13995
13996/* Determine if PAT is a PATTERN of a store insn. */
13997
13998static bool
13999is_store_insn1 (rtx pat)
14000{
14001 if (!pat || pat == NULL_RTX)
14002 return false;
14003
14004 if (GET_CODE (pat) == SET)
14005 return is_mem_ref (SET_DEST (pat));
14006
14007 if (GET_CODE (pat) == PARALLEL)
14008 {
14009 int i;
14010
14011 for (i = 0; i < XVECLEN (pat, 0); i++)
14012 if (is_store_insn1 (XVECEXP (pat, 0, i)))
14013 return true;
14014 }
14015
14016 return false;
14017}
14018
14019/* Determine if INSN stores to memory. */
14020
14021static bool
14022is_store_insn (rtx insn)
14023{
14024 if (!insn || !INSN_P (insn))
14025 return false;
14026
14027 return is_store_insn1 (PATTERN (insn));
14028}
14029
14030/* Returns whether the dependence between INSN and NEXT is considered
14031 costly by the given target. */
14032
14033static bool
14034rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
14035{
14036 /* If the flag is not enbled - no dependence is considered costly;
14037 allow all dependent insns in the same group.
14038 This is the most aggressive option. */
14039 if (rs6000_sched_costly_dep == no_dep_costly)
14040 return false;
14041
14042 /* If the flag is set to 1 - a dependence is always considered costly;
14043 do not allow dependent instructions in the same group.
14044 This is the most conservative option. */
14045 if (rs6000_sched_costly_dep == all_deps_costly)
14046 return true;
14047
14048 if (rs6000_sched_costly_dep == store_to_load_dep_costly
14049 && is_load_insn (next)
14050 && is_store_insn (insn))
14051 /* Prevent load after store in the same group. */
14052 return true;
14053
14054 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
14055 && is_load_insn (next)
14056 && is_store_insn (insn)
14057 && (!link || (int) REG_NOTE_KIND (link) == 0))
14058 /* Prevent load after store in the same group if it is a true dependence. */
14059 return true;
14060
14061 /* The flag is set to X; dependences with latency >= X are considered costly,
14062 and will not be scheduled in the same group. */
14063 if (rs6000_sched_costly_dep <= max_dep_latency
14064 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
14065 return true;
14066
14067 return false;
14068}
14069
cbe26ab8
DN
14070/* Return the next insn after INSN that is found before TAIL is reached,
14071 skipping any "non-active" insns - insns that will not actually occupy
14072 an issue slot. Return NULL_RTX if such an insn is not found. */
14073
14074static rtx
14075get_next_active_insn (rtx insn, rtx tail)
14076{
14077 rtx next_insn;
14078
14079 if (!insn || insn == tail)
14080 return NULL_RTX;
14081
14082 next_insn = NEXT_INSN (insn);
14083
14084 while (next_insn
14085 && next_insn != tail
14086 && (GET_CODE(next_insn) == NOTE
14087 || GET_CODE (PATTERN (next_insn)) == USE
14088 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
14089 {
14090 next_insn = NEXT_INSN (next_insn);
14091 }
14092
14093 if (!next_insn || next_insn == tail)
14094 return NULL_RTX;
14095
14096 return next_insn;
14097}
14098
839a4992 14099/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
14100 of group WHICH_GROUP.
14101
14102 If WHICH_GROUP == current_group, this function will return true if INSN
14103 causes the termination of the current group (i.e, the dispatch group to
14104 which INSN belongs). This means that INSN will be the last insn in the
14105 group it belongs to.
14106
14107 If WHICH_GROUP == previous_group, this function will return true if INSN
14108 causes the termination of the previous group (i.e, the dispatch group that
14109 precedes the group to which INSN belongs). This means that INSN will be
14110 the first insn in the group it belongs to). */
14111
14112static bool
14113insn_terminates_group_p (rtx insn, enum group_termination which_group)
14114{
14115 enum attr_type type;
14116
14117 if (! insn)
14118 return false;
569fa502 14119
cbe26ab8
DN
14120 type = get_attr_type (insn);
14121
14122 if (is_microcoded_insn (insn))
14123 return true;
14124
14125 if (which_group == current_group)
14126 {
14127 if (is_branch_slot_insn (insn))
14128 return true;
14129 return false;
14130 }
14131 else if (which_group == previous_group)
14132 {
14133 if (is_dispatch_slot_restricted (insn))
14134 return true;
14135 return false;
14136 }
14137
14138 return false;
14139}
14140
839a4992 14141/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
14142 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
14143
14144static bool
14145is_costly_group (rtx *group_insns, rtx next_insn)
14146{
14147 int i;
14148 rtx link;
14149 int cost;
14150 int issue_rate = rs6000_issue_rate ();
14151
14152 for (i = 0; i < issue_rate; i++)
14153 {
14154 rtx insn = group_insns[i];
14155 if (!insn)
14156 continue;
14157 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
14158 {
14159 rtx next = XEXP (link, 0);
14160 if (next == next_insn)
14161 {
14162 cost = insn_cost (insn, link, next_insn);
14163 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
14164 return true;
14165 }
14166 }
14167 }
14168
14169 return false;
14170}
14171
14172/* Utility of the function redefine_groups.
14173 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
14174 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
14175 to keep it "far" (in a separate group) from GROUP_INSNS, following
14176 one of the following schemes, depending on the value of the flag
14177 -minsert_sched_nops = X:
14178 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 14179 in order to force NEXT_INSN into a separate group.
cbe26ab8
DN
14180 (2) X < sched_finish_regroup_exact: insert exactly X nops.
14181 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
14182 insertion (has a group just ended, how many vacant issue slots remain in the
14183 last group, and how many dispatch groups were encountered so far). */
14184
14185static int
14186force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
14187 bool *group_end, int can_issue_more, int *group_count)
14188{
14189 rtx nop;
14190 bool force;
14191 int issue_rate = rs6000_issue_rate ();
14192 bool end = *group_end;
14193 int i;
14194
14195 if (next_insn == NULL_RTX)
14196 return can_issue_more;
14197
14198 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
14199 return can_issue_more;
14200
14201 force = is_costly_group (group_insns, next_insn);
14202 if (!force)
14203 return can_issue_more;
14204
14205 if (sched_verbose > 6)
14206 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
14207 *group_count ,can_issue_more);
14208
14209 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
14210 {
14211 if (*group_end)
14212 can_issue_more = 0;
14213
14214 /* Since only a branch can be issued in the last issue_slot, it is
14215 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
14216 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
14217 in this case the last nop will start a new group and the branch will be
14218 forced to the new group. */
14219 if (can_issue_more && !is_branch_slot_insn (next_insn))
14220 can_issue_more--;
14221
14222 while (can_issue_more > 0)
14223 {
14224 nop = gen_nop();
14225 emit_insn_before (nop, next_insn);
14226 can_issue_more--;
14227 }
14228
14229 *group_end = true;
14230 return 0;
14231 }
14232
14233 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
14234 {
14235 int n_nops = rs6000_sched_insert_nops;
14236
14237 /* Nops can't be issued from the branch slot, so the effective
14238 issue_rate for nops is 'issue_rate - 1'. */
14239 if (can_issue_more == 0)
14240 can_issue_more = issue_rate;
14241 can_issue_more--;
14242 if (can_issue_more == 0)
14243 {
14244 can_issue_more = issue_rate - 1;
14245 (*group_count)++;
14246 end = true;
14247 for (i = 0; i < issue_rate; i++)
14248 {
14249 group_insns[i] = 0;
14250 }
14251 }
14252
14253 while (n_nops > 0)
14254 {
14255 nop = gen_nop ();
14256 emit_insn_before (nop, next_insn);
14257 if (can_issue_more == issue_rate - 1) /* new group begins */
14258 end = false;
14259 can_issue_more--;
14260 if (can_issue_more == 0)
14261 {
14262 can_issue_more = issue_rate - 1;
14263 (*group_count)++;
14264 end = true;
14265 for (i = 0; i < issue_rate; i++)
14266 {
14267 group_insns[i] = 0;
14268 }
14269 }
14270 n_nops--;
14271 }
14272
14273 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
14274 can_issue_more++;
14275
14276 *group_end = /* Is next_insn going to start a new group? */
14277 (end
14278 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14279 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14280 || (can_issue_more < issue_rate &&
14281 insn_terminates_group_p (next_insn, previous_group)));
14282 if (*group_end && end)
14283 (*group_count)--;
14284
14285 if (sched_verbose > 6)
14286 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
14287 *group_count, can_issue_more);
14288 return can_issue_more;
14289 }
14290
14291 return can_issue_more;
14292}
14293
14294/* This function tries to synch the dispatch groups that the compiler "sees"
14295 with the dispatch groups that the processor dispatcher is expected to
14296 form in practice. It tries to achieve this synchronization by forcing the
14297 estimated processor grouping on the compiler (as opposed to the function
14298 'pad_goups' which tries to force the scheduler's grouping on the processor).
14299
14300 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
14301 examines the (estimated) dispatch groups that will be formed by the processor
14302 dispatcher. It marks these group boundaries to reflect the estimated
14303 processor grouping, overriding the grouping that the scheduler had marked.
14304 Depending on the value of the flag '-minsert-sched-nops' this function can
14305 force certain insns into separate groups or force a certain distance between
14306 them by inserting nops, for example, if there exists a "costly dependence"
14307 between the insns.
14308
14309 The function estimates the group boundaries that the processor will form as
14310 folllows: It keeps track of how many vacant issue slots are available after
14311 each insn. A subsequent insn will start a new group if one of the following
14312 4 cases applies:
14313 - no more vacant issue slots remain in the current dispatch group.
14314 - only the last issue slot, which is the branch slot, is vacant, but the next
14315 insn is not a branch.
14316 - only the last 2 or less issue slots, including the branch slot, are vacant,
14317 which means that a cracked insn (which occupies two issue slots) can't be
14318 issued in this group.
14319 - less than 'issue_rate' slots are vacant, and the next insn always needs to
14320 start a new group. */
14321
14322static int
14323redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14324{
14325 rtx insn, next_insn;
14326 int issue_rate;
14327 int can_issue_more;
14328 int slot, i;
14329 bool group_end;
14330 int group_count = 0;
14331 rtx *group_insns;
14332
14333 /* Initialize. */
14334 issue_rate = rs6000_issue_rate ();
14335 group_insns = alloca (issue_rate * sizeof (rtx));
14336 for (i = 0; i < issue_rate; i++)
14337 {
14338 group_insns[i] = 0;
14339 }
14340 can_issue_more = issue_rate;
14341 slot = 0;
14342 insn = get_next_active_insn (prev_head_insn, tail);
14343 group_end = false;
14344
14345 while (insn != NULL_RTX)
14346 {
14347 slot = (issue_rate - can_issue_more);
14348 group_insns[slot] = insn;
14349 can_issue_more =
14350 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14351 if (insn_terminates_group_p (insn, current_group))
14352 can_issue_more = 0;
14353
14354 next_insn = get_next_active_insn (insn, tail);
14355 if (next_insn == NULL_RTX)
14356 return group_count + 1;
14357
14358 group_end = /* Is next_insn going to start a new group? */
14359 (can_issue_more == 0
14360 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14361 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14362 || (can_issue_more < issue_rate &&
14363 insn_terminates_group_p (next_insn, previous_group)));
14364
14365 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
14366 next_insn, &group_end, can_issue_more, &group_count);
14367
14368 if (group_end)
14369 {
14370 group_count++;
14371 can_issue_more = 0;
14372 for (i = 0; i < issue_rate; i++)
14373 {
14374 group_insns[i] = 0;
14375 }
14376 }
14377
14378 if (GET_MODE (next_insn) == TImode && can_issue_more)
14379 PUT_MODE(next_insn, VOIDmode);
14380 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
14381 PUT_MODE (next_insn, TImode);
14382
14383 insn = next_insn;
14384 if (can_issue_more == 0)
14385 can_issue_more = issue_rate;
14386 } /* while */
14387
14388 return group_count;
14389}
14390
14391/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
14392 dispatch group boundaries that the scheduler had marked. Pad with nops
14393 any dispatch groups which have vacant issue slots, in order to force the
14394 scheduler's grouping on the processor dispatcher. The function
14395 returns the number of dispatch groups found. */
14396
14397static int
14398pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14399{
14400 rtx insn, next_insn;
14401 rtx nop;
14402 int issue_rate;
14403 int can_issue_more;
14404 int group_end;
14405 int group_count = 0;
14406
14407 /* Initialize issue_rate. */
14408 issue_rate = rs6000_issue_rate ();
14409 can_issue_more = issue_rate;
14410
14411 insn = get_next_active_insn (prev_head_insn, tail);
14412 next_insn = get_next_active_insn (insn, tail);
14413
14414 while (insn != NULL_RTX)
14415 {
14416 can_issue_more =
14417 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14418
14419 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
14420
14421 if (next_insn == NULL_RTX)
14422 break;
14423
14424 if (group_end)
14425 {
14426 /* If the scheduler had marked group termination at this location
14427 (between insn and next_indn), and neither insn nor next_insn will
14428 force group termination, pad the group with nops to force group
14429 termination. */
14430 if (can_issue_more
14431 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
14432 && !insn_terminates_group_p (insn, current_group)
14433 && !insn_terminates_group_p (next_insn, previous_group))
14434 {
14435 if (!is_branch_slot_insn(next_insn))
14436 can_issue_more--;
14437
14438 while (can_issue_more)
14439 {
14440 nop = gen_nop ();
14441 emit_insn_before (nop, next_insn);
14442 can_issue_more--;
14443 }
14444 }
14445
14446 can_issue_more = issue_rate;
14447 group_count++;
14448 }
14449
14450 insn = next_insn;
14451 next_insn = get_next_active_insn (insn, tail);
14452 }
14453
14454 return group_count;
14455}
14456
14457/* The following function is called at the end of scheduling BB.
14458 After reload, it inserts nops at insn group bundling. */
14459
14460static void
38f391a5 14461rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
14462{
14463 int n_groups;
14464
14465 if (sched_verbose)
14466 fprintf (dump, "=== Finishing schedule.\n");
14467
14468 if (reload_completed && rs6000_cpu == PROCESSOR_POWER4)
14469 {
14470 if (rs6000_sched_insert_nops == sched_finish_none)
14471 return;
14472
14473 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
14474 n_groups = pad_groups (dump, sched_verbose,
14475 current_sched_info->prev_head,
14476 current_sched_info->next_tail);
14477 else
14478 n_groups = redefine_groups (dump, sched_verbose,
14479 current_sched_info->prev_head,
14480 current_sched_info->next_tail);
14481
14482 if (sched_verbose >= 6)
14483 {
14484 fprintf (dump, "ngroups = %d\n", n_groups);
14485 print_rtl (dump, current_sched_info->prev_head);
14486 fprintf (dump, "Done finish_sched\n");
14487 }
14488 }
14489}
b6c9286a 14490\f
b6c9286a
MM
14491/* Length in units of the trampoline for entering a nested function. */
14492
14493int
863d938c 14494rs6000_trampoline_size (void)
b6c9286a
MM
14495{
14496 int ret = 0;
14497
14498 switch (DEFAULT_ABI)
14499 {
14500 default:
14501 abort ();
14502
14503 case ABI_AIX:
8f802bfb 14504 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
14505 break;
14506
4dabc42d 14507 case ABI_DARWIN:
b6c9286a 14508 case ABI_V4:
03a7e1a5 14509 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 14510 break;
b6c9286a
MM
14511 }
14512
14513 return ret;
14514}
14515
14516/* Emit RTL insns to initialize the variable parts of a trampoline.
14517 FNADDR is an RTX for the address of the function's pure code.
14518 CXT is an RTX for the static chain value for the function. */
14519
14520void
a2369ed3 14521rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 14522{
ac2a93a1 14523 enum machine_mode pmode = Pmode;
8bd04c56
MM
14524 int regsize = (TARGET_32BIT) ? 4 : 8;
14525 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
14526
14527 switch (DEFAULT_ABI)
14528 {
14529 default:
14530 abort ();
14531
8bd04c56 14532/* Macros to shorten the code expansions below. */
39403d82 14533#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
14534#define MEM_PLUS(addr,offset) \
14535 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 14536
b6c9286a
MM
14537 /* Under AIX, just build the 3 word function descriptor */
14538 case ABI_AIX:
8bd04c56
MM
14539 {
14540 rtx fn_reg = gen_reg_rtx (pmode);
14541 rtx toc_reg = gen_reg_rtx (pmode);
14542 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 14543 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
14544 emit_move_insn (MEM_DEREF (addr), fn_reg);
14545 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
14546 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
14547 }
b6c9286a
MM
14548 break;
14549
4dabc42d
TC
14550 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
14551 case ABI_DARWIN:
b6c9286a 14552 case ABI_V4:
39403d82 14553 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
14554 FALSE, VOIDmode, 4,
14555 addr, pmode,
14556 GEN_INT (rs6000_trampoline_size ()), SImode,
14557 fnaddr, pmode,
14558 ctx_reg, pmode);
b6c9286a 14559 break;
b6c9286a
MM
14560 }
14561
14562 return;
14563}
7509c759
MM
14564
14565\f
91d231cb 14566/* Table of valid machine attributes. */
a4f6c312 14567
91d231cb 14568const struct attribute_spec rs6000_attribute_table[] =
7509c759 14569{
91d231cb 14570 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
a5c76ee6
ZW
14571 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14572 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14573 { NULL, 0, 0, false, false, false, NULL }
91d231cb 14574};
7509c759 14575
a5c76ee6
ZW
14576/* Handle a "longcall" or "shortcall" attribute; arguments as in
14577 struct attribute_spec.handler. */
a4f6c312 14578
91d231cb 14579static tree
a2369ed3
DJ
14580rs6000_handle_longcall_attribute (tree *node, tree name,
14581 tree args ATTRIBUTE_UNUSED,
14582 int flags ATTRIBUTE_UNUSED,
14583 bool *no_add_attrs)
91d231cb
JM
14584{
14585 if (TREE_CODE (*node) != FUNCTION_TYPE
14586 && TREE_CODE (*node) != FIELD_DECL
14587 && TREE_CODE (*node) != TYPE_DECL)
14588 {
14589 warning ("`%s' attribute only applies to functions",
14590 IDENTIFIER_POINTER (name));
14591 *no_add_attrs = true;
14592 }
6a4cee5f 14593
91d231cb 14594 return NULL_TREE;
7509c759
MM
14595}
14596
a5c76ee6
ZW
14597/* Set longcall attributes on all functions declared when
14598 rs6000_default_long_calls is true. */
14599static void
a2369ed3 14600rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
14601{
14602 if (rs6000_default_long_calls
14603 && (TREE_CODE (type) == FUNCTION_TYPE
14604 || TREE_CODE (type) == METHOD_TYPE))
14605 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
14606 NULL_TREE,
14607 TYPE_ATTRIBUTES (type));
14608}
14609
3cb999d8
DE
14610/* Return a reference suitable for calling a function with the
14611 longcall attribute. */
a4f6c312 14612
6a4cee5f 14613struct rtx_def *
a2369ed3 14614rs6000_longcall_ref (rtx call_ref)
6a4cee5f 14615{
d330fd93 14616 const char *call_name;
6a4cee5f
MM
14617 tree node;
14618
14619 if (GET_CODE (call_ref) != SYMBOL_REF)
14620 return call_ref;
14621
14622 /* System V adds '.' to the internal name, so skip them. */
14623 call_name = XSTR (call_ref, 0);
14624 if (*call_name == '.')
14625 {
14626 while (*call_name == '.')
14627 call_name++;
14628
14629 node = get_identifier (call_name);
39403d82 14630 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
14631 }
14632
14633 return force_reg (Pmode, call_ref);
14634}
7509c759 14635\f
b64a1b53
RH
14636#ifdef USING_ELFOS_H
14637
7509c759
MM
14638/* A C statement or statements to switch to the appropriate section
14639 for output of RTX in mode MODE. You can assume that RTX is some
14640 kind of constant in RTL. The argument MODE is redundant except in
14641 the case of a `const_int' rtx. Select the section by calling
14642 `text_section' or one of the alternatives for other sections.
14643
14644 Do not define this macro if you put all constants in the read-only
14645 data section. */
14646
b64a1b53 14647static void
a2369ed3
DJ
14648rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
14649 unsigned HOST_WIDE_INT align)
7509c759 14650{
a9098fd0 14651 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 14652 toc_section ();
7509c759 14653 else
b64a1b53 14654 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
14655}
14656
14657/* A C statement or statements to switch to the appropriate
14658 section for output of DECL. DECL is either a `VAR_DECL' node
14659 or a constant of some sort. RELOC indicates whether forming
14660 the initial value of DECL requires link-time relocations. */
14661
ae46c4e0 14662static void
a2369ed3
DJ
14663rs6000_elf_select_section (tree decl, int reloc,
14664 unsigned HOST_WIDE_INT align)
7509c759 14665{
f1384257
AM
14666 /* Pretend that we're always building for a shared library when
14667 ABI_AIX, because otherwise we end up with dynamic relocations
14668 in read-only sections. This happens for function pointers,
14669 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
14670 default_elf_select_section_1 (decl, reloc, align,
14671 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
14672}
14673
14674/* A C statement to build up a unique section name, expressed as a
14675 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
14676 RELOC indicates whether the initial value of EXP requires
14677 link-time relocations. If you do not define this macro, GCC will use
14678 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 14679 macro can now be called for uninitialized data items as well as
4912a07c 14680 initialized data and functions. */
63019373 14681
ae46c4e0 14682static void
a2369ed3 14683rs6000_elf_unique_section (tree decl, int reloc)
63019373 14684{
f1384257
AM
14685 /* As above, pretend that we're always building for a shared library
14686 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
14687 default_unique_section_1 (decl, reloc,
14688 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 14689}
d9407988 14690\f
d1908feb
JJ
14691/* For a SYMBOL_REF, set generic flags and then perform some
14692 target-specific processing.
14693
d1908feb
JJ
14694 When the AIX ABI is requested on a non-AIX system, replace the
14695 function name with the real name (with a leading .) rather than the
14696 function descriptor name. This saves a lot of overriding code to
14697 read the prefixes. */
d9407988 14698
fb49053f 14699static void
a2369ed3 14700rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 14701{
d1908feb 14702 default_encode_section_info (decl, rtl, first);
b2003250 14703
d1908feb
JJ
14704 if (first
14705 && TREE_CODE (decl) == FUNCTION_DECL
14706 && !TARGET_AIX
14707 && DEFAULT_ABI == ABI_AIX)
d9407988 14708 {
c6a2438a 14709 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
14710 size_t len = strlen (XSTR (sym_ref, 0));
14711 char *str = alloca (len + 2);
14712 str[0] = '.';
14713 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
14714 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 14715 }
d9407988
MM
14716}
14717
0e5dbd9b 14718static bool
a2369ed3 14719rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
14720{
14721 if (rs6000_sdata == SDATA_NONE)
14722 return false;
14723
14724 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
14725 {
14726 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
14727 if (strcmp (section, ".sdata") == 0
14728 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
14729 || strcmp (section, ".sbss") == 0
14730 || strcmp (section, ".sbss2") == 0
14731 || strcmp (section, ".PPC.EMB.sdata0") == 0
14732 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
14733 return true;
14734 }
14735 else
14736 {
14737 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
14738
14739 if (size > 0
307b599c 14740 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
14741 /* If it's not public, and we're not going to reference it there,
14742 there's no need to put it in the small data section. */
0e5dbd9b
DE
14743 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
14744 return true;
14745 }
14746
14747 return false;
14748}
14749
b91da81f 14750#endif /* USING_ELFOS_H */
000034eb 14751
a6c2a102 14752\f
000034eb 14753/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
14754 ADDR can be effectively incremented by incrementing REG.
14755
14756 r0 is special and we must not select it as an address
14757 register by this routine since our caller will try to
14758 increment the returned register via an "la" instruction. */
000034eb
DE
14759
14760struct rtx_def *
a2369ed3 14761find_addr_reg (rtx addr)
000034eb
DE
14762{
14763 while (GET_CODE (addr) == PLUS)
14764 {
02441cd6
JL
14765 if (GET_CODE (XEXP (addr, 0)) == REG
14766 && REGNO (XEXP (addr, 0)) != 0)
000034eb 14767 addr = XEXP (addr, 0);
02441cd6
JL
14768 else if (GET_CODE (XEXP (addr, 1)) == REG
14769 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
14770 addr = XEXP (addr, 1);
14771 else if (CONSTANT_P (XEXP (addr, 0)))
14772 addr = XEXP (addr, 1);
14773 else if (CONSTANT_P (XEXP (addr, 1)))
14774 addr = XEXP (addr, 0);
14775 else
14776 abort ();
14777 }
02441cd6 14778 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
14779 return addr;
14780 abort ();
14781}
14782
a6c2a102 14783void
a2369ed3 14784rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
14785{
14786 fatal_insn ("bad address", op);
14787}
c8023011 14788
ee890fe2
SS
14789#if TARGET_MACHO
14790
14791#if 0
14792/* Returns 1 if OP is either a symbol reference or a sum of a symbol
14793 reference and a constant. */
14794
14795int
a2369ed3 14796symbolic_operand (rtx op)
ee890fe2
SS
14797{
14798 switch (GET_CODE (op))
14799 {
14800 case SYMBOL_REF:
14801 case LABEL_REF:
14802 return 1;
14803 case CONST:
14804 op = XEXP (op, 0);
14805 return (GET_CODE (op) == SYMBOL_REF ||
14806 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
14807 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
14808 && GET_CODE (XEXP (op, 1)) == CONST_INT);
14809 default:
14810 return 0;
14811 }
c8023011 14812}
ee890fe2
SS
14813#endif
14814
efdba735 14815#if TARGET_MACHO
ee890fe2 14816
efdba735 14817static tree branch_island_list = 0;
ee890fe2 14818
efdba735
SH
14819/* Remember to generate a branch island for far calls to the given
14820 function. */
ee890fe2 14821
efdba735
SH
14822static void
14823add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 14824{
efdba735
SH
14825 tree branch_island = build_tree_list (function_name, label_name);
14826 TREE_TYPE (branch_island) = build_int_2 (line_number, 0);
14827 TREE_CHAIN (branch_island) = branch_island_list;
14828 branch_island_list = branch_island;
ee890fe2
SS
14829}
14830
efdba735
SH
14831#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
14832#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
14833#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
14834 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 14835
efdba735
SH
14836/* Generate far-jump branch islands for everything on the
14837 branch_island_list. Invoked immediately after the last instruction
14838 of the epilogue has been emitted; the branch-islands must be
14839 appended to, and contiguous with, the function body. Mach-O stubs
14840 are generated in machopic_output_stub(). */
ee890fe2 14841
efdba735
SH
14842static void
14843macho_branch_islands (void)
14844{
14845 char tmp_buf[512];
14846 tree branch_island;
14847
14848 for (branch_island = branch_island_list;
14849 branch_island;
14850 branch_island = TREE_CHAIN (branch_island))
14851 {
14852 const char *label =
14853 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
14854 const char *name =
14855 darwin_strip_name_encoding (
14856 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)));
14857 char name_buf[512];
14858 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
14859 if (name[0] == '*' || name[0] == '&')
14860 strcpy (name_buf, name+1);
14861 else
14862 {
14863 name_buf[0] = '_';
14864 strcpy (name_buf+1, name);
14865 }
14866 strcpy (tmp_buf, "\n");
14867 strcat (tmp_buf, label);
ee890fe2 14868#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 14869 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 14870 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 14871 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 14872#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
14873 if (flag_pic)
14874 {
14875 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
14876 strcat (tmp_buf, label);
14877 strcat (tmp_buf, "_pic\n");
14878 strcat (tmp_buf, label);
14879 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
14880
14881 strcat (tmp_buf, "\taddis r11,r11,ha16(");
14882 strcat (tmp_buf, name_buf);
14883 strcat (tmp_buf, " - ");
14884 strcat (tmp_buf, label);
14885 strcat (tmp_buf, "_pic)\n");
14886
14887 strcat (tmp_buf, "\tmtlr r0\n");
14888
14889 strcat (tmp_buf, "\taddi r12,r11,lo16(");
14890 strcat (tmp_buf, name_buf);
14891 strcat (tmp_buf, " - ");
14892 strcat (tmp_buf, label);
14893 strcat (tmp_buf, "_pic)\n");
14894
14895 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
14896 }
14897 else
14898 {
14899 strcat (tmp_buf, ":\nlis r12,hi16(");
14900 strcat (tmp_buf, name_buf);
14901 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
14902 strcat (tmp_buf, name_buf);
14903 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
14904 }
14905 output_asm_insn (tmp_buf, 0);
ee890fe2 14906#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 14907 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 14908 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 14909 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 14910#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 14911 }
ee890fe2 14912
efdba735 14913 branch_island_list = 0;
ee890fe2
SS
14914}
14915
14916/* NO_PREVIOUS_DEF checks in the link list whether the function name is
14917 already there or not. */
14918
efdba735 14919static int
a2369ed3 14920no_previous_def (tree function_name)
ee890fe2 14921{
efdba735
SH
14922 tree branch_island;
14923 for (branch_island = branch_island_list;
14924 branch_island;
14925 branch_island = TREE_CHAIN (branch_island))
14926 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
14927 return 0;
14928 return 1;
14929}
14930
14931/* GET_PREV_LABEL gets the label name from the previous definition of
14932 the function. */
14933
efdba735 14934static tree
a2369ed3 14935get_prev_label (tree function_name)
ee890fe2 14936{
efdba735
SH
14937 tree branch_island;
14938 for (branch_island = branch_island_list;
14939 branch_island;
14940 branch_island = TREE_CHAIN (branch_island))
14941 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
14942 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
14943 return 0;
14944}
14945
14946/* INSN is either a function call or a millicode call. It may have an
14947 unconditional jump in its delay slot.
14948
14949 CALL_DEST is the routine we are calling. */
14950
14951char *
efdba735 14952output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
14953{
14954 static char buf[256];
efdba735
SH
14955 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
14956 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
14957 {
14958 tree labelname;
efdba735 14959 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
ee890fe2
SS
14960
14961 if (no_previous_def (funname))
14962 {
308c142a 14963 int line_number = 0;
ee890fe2
SS
14964 rtx label_rtx = gen_label_rtx ();
14965 char *label_buf, temp_buf[256];
14966 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
14967 CODE_LABEL_NUMBER (label_rtx));
14968 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
14969 labelname = get_identifier (label_buf);
14970 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
14971 if (insn)
14972 line_number = NOTE_LINE_NUMBER (insn);
efdba735 14973 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
14974 }
14975 else
14976 labelname = get_prev_label (funname);
14977
efdba735
SH
14978 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
14979 instruction will reach 'foo', otherwise link as 'bl L42'".
14980 "L42" should be a 'branch island', that will do a far jump to
14981 'foo'. Branch islands are generated in
14982 macho_branch_islands(). */
ee890fe2 14983 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 14984 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
14985 }
14986 else
efdba735
SH
14987 sprintf (buf, "bl %%z%d", dest_operand_number);
14988 return buf;
ee890fe2
SS
14989}
14990
efdba735 14991#endif /* TARGET_MACHO */
ee890fe2 14992
ee890fe2
SS
14993/* Generate PIC and indirect symbol stubs. */
14994
14995void
a2369ed3 14996machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
14997{
14998 unsigned int length;
a4f6c312
SS
14999 char *symbol_name, *lazy_ptr_name;
15000 char *local_label_0;
ee890fe2
SS
15001 static int label = 0;
15002
df56a27f 15003 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 15004 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 15005
ee890fe2 15006
ee890fe2
SS
15007 length = strlen (symb);
15008 symbol_name = alloca (length + 32);
15009 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
15010
15011 lazy_ptr_name = alloca (length + 32);
15012 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
15013
ee890fe2 15014 if (flag_pic == 2)
d3c300d2 15015 machopic_picsymbol_stub1_section ();
ee890fe2 15016 else
d3c300d2
DJ
15017 machopic_symbol_stub1_section ();
15018 fprintf (file, "\t.align 2\n");
ee890fe2
SS
15019
15020 fprintf (file, "%s:\n", stub);
15021 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15022
15023 if (flag_pic == 2)
15024 {
876455fa
AP
15025 label++;
15026 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
15027 sprintf (local_label_0, "\"L%011d$spb\"", label);
15028
ee890fe2
SS
15029 fprintf (file, "\tmflr r0\n");
15030 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
15031 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
15032 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
15033 lazy_ptr_name, local_label_0);
15034 fprintf (file, "\tmtlr r0\n");
d3c300d2 15035 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
15036 lazy_ptr_name, local_label_0);
15037 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
15038 fprintf (file, "\tbctr\n");
15039 }
15040 else
ab82a49f
AP
15041 {
15042 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
15043 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
15044 fprintf (file, "\tmtctr r12\n");
15045 fprintf (file, "\tbctr\n");
15046 }
ee890fe2
SS
15047
15048 machopic_lazy_symbol_ptr_section ();
15049 fprintf (file, "%s:\n", lazy_ptr_name);
15050 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15051 fprintf (file, "\t.long dyld_stub_binding_helper\n");
15052}
15053
15054/* Legitimize PIC addresses. If the address is already
15055 position-independent, we return ORIG. Newly generated
15056 position-independent addresses go into a reg. This is REG if non
15057 zero, otherwise we allocate register(s) as necessary. */
15058
c859cda6 15059#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
15060
15061rtx
a2369ed3
DJ
15062rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
15063 rtx reg)
ee890fe2
SS
15064{
15065 rtx base, offset;
15066
15067 if (reg == NULL && ! reload_in_progress && ! reload_completed)
15068 reg = gen_reg_rtx (Pmode);
15069
15070 if (GET_CODE (orig) == CONST)
15071 {
15072 if (GET_CODE (XEXP (orig, 0)) == PLUS
15073 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
15074 return orig;
15075
15076 if (GET_CODE (XEXP (orig, 0)) == PLUS)
15077 {
2cf520bf 15078 /* Use a different reg for the intermediate value, as
a3c9585f 15079 it will be marked UNCHANGING. */
2cf520bf
GK
15080 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
15081
a4f6c312
SS
15082 base =
15083 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 15084 Pmode, reg_temp);
a4f6c312
SS
15085 offset =
15086 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
15087 Pmode, reg);
ee890fe2
SS
15088 }
15089 else
15090 abort ();
15091
15092 if (GET_CODE (offset) == CONST_INT)
15093 {
15094 if (SMALL_INT (offset))
ed8908e7 15095 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
15096 else if (! reload_in_progress && ! reload_completed)
15097 offset = force_reg (Pmode, offset);
15098 else
c859cda6
DJ
15099 {
15100 rtx mem = force_const_mem (Pmode, orig);
15101 return machopic_legitimize_pic_address (mem, Pmode, reg);
15102 }
ee890fe2 15103 }
f1c25d3b 15104 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
15105 }
15106
15107 /* Fall back on generic machopic code. */
15108 return machopic_legitimize_pic_address (orig, mode, reg);
15109}
15110
15111/* This is just a placeholder to make linking work without having to
15112 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
15113 ever needed for Darwin (not too likely!) this would have to get a
15114 real definition. */
15115
15116void
863d938c 15117toc_section (void)
ee890fe2
SS
15118{
15119}
15120
15121#endif /* TARGET_MACHO */
7c262518
RH
15122
15123#if TARGET_ELF
15124static unsigned int
a2369ed3 15125rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 15126{
1ff8f81a
AM
15127 return default_section_type_flags_1 (decl, name, reloc,
15128 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 15129}
d9f6800d
RH
15130
15131/* Record an element in the table of global constructors. SYMBOL is
15132 a SYMBOL_REF of the function to be called; PRIORITY is a number
15133 between 0 and MAX_INIT_PRIORITY.
15134
15135 This differs from default_named_section_asm_out_constructor in
15136 that we have special handling for -mrelocatable. */
15137
15138static void
a2369ed3 15139rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
15140{
15141 const char *section = ".ctors";
15142 char buf[16];
15143
15144 if (priority != DEFAULT_INIT_PRIORITY)
15145 {
15146 sprintf (buf, ".ctors.%.5u",
15147 /* Invert the numbering so the linker puts us in the proper
15148 order; constructors are run from right to left, and the
15149 linker sorts in increasing order. */
15150 MAX_INIT_PRIORITY - priority);
15151 section = buf;
15152 }
15153
715bdd29
RH
15154 named_section_flags (section, SECTION_WRITE);
15155 assemble_align (POINTER_SIZE);
d9f6800d
RH
15156
15157 if (TARGET_RELOCATABLE)
15158 {
15159 fputs ("\t.long (", asm_out_file);
15160 output_addr_const (asm_out_file, symbol);
15161 fputs (")@fixup\n", asm_out_file);
15162 }
15163 else
c8af3574 15164 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
15165}
15166
15167static void
a2369ed3 15168rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
15169{
15170 const char *section = ".dtors";
15171 char buf[16];
15172
15173 if (priority != DEFAULT_INIT_PRIORITY)
15174 {
15175 sprintf (buf, ".dtors.%.5u",
15176 /* Invert the numbering so the linker puts us in the proper
15177 order; constructors are run from right to left, and the
15178 linker sorts in increasing order. */
15179 MAX_INIT_PRIORITY - priority);
15180 section = buf;
15181 }
15182
715bdd29
RH
15183 named_section_flags (section, SECTION_WRITE);
15184 assemble_align (POINTER_SIZE);
d9f6800d
RH
15185
15186 if (TARGET_RELOCATABLE)
15187 {
15188 fputs ("\t.long (", asm_out_file);
15189 output_addr_const (asm_out_file, symbol);
15190 fputs (")@fixup\n", asm_out_file);
15191 }
15192 else
c8af3574 15193 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 15194}
9739c90c
JJ
15195
15196void
a2369ed3 15197rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
15198{
15199 if (TARGET_64BIT)
15200 {
15201 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
15202 ASM_OUTPUT_LABEL (file, name);
15203 fputs (DOUBLE_INT_ASM_OP, file);
15204 putc ('.', file);
15205 assemble_name (file, name);
15206 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
15207 assemble_name (file, name);
15208 fputs (",24\n\t.type\t.", file);
15209 assemble_name (file, name);
15210 fputs (",@function\n", file);
15211 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
15212 {
15213 fputs ("\t.globl\t.", file);
15214 assemble_name (file, name);
15215 putc ('\n', file);
15216 }
15217 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15218 putc ('.', file);
15219 ASM_OUTPUT_LABEL (file, name);
15220 return;
15221 }
15222
15223 if (TARGET_RELOCATABLE
15224 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 15225 && uses_TOC ())
9739c90c
JJ
15226 {
15227 char buf[256];
15228
15229 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
15230
15231 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
15232 fprintf (file, "\t.long ");
15233 assemble_name (file, buf);
15234 putc ('-', file);
15235 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
15236 assemble_name (file, buf);
15237 putc ('\n', file);
15238 }
15239
15240 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
15241 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15242
15243 if (DEFAULT_ABI == ABI_AIX)
15244 {
15245 const char *desc_name, *orig_name;
15246
15247 orig_name = (*targetm.strip_name_encoding) (name);
15248 desc_name = orig_name;
15249 while (*desc_name == '.')
15250 desc_name++;
15251
15252 if (TREE_PUBLIC (decl))
15253 fprintf (file, "\t.globl %s\n", desc_name);
15254
15255 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
15256 fprintf (file, "%s:\n", desc_name);
15257 fprintf (file, "\t.long %s\n", orig_name);
15258 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
15259 if (DEFAULT_ABI == ABI_AIX)
15260 fputs ("\t.long 0\n", file);
15261 fprintf (file, "\t.previous\n");
15262 }
15263 ASM_OUTPUT_LABEL (file, name);
15264}
7c262518
RH
15265#endif
15266
cbaaba19 15267#if TARGET_XCOFF
7c262518 15268static void
a2369ed3 15269rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
15270{
15271 fputs (GLOBAL_ASM_OP, stream);
15272 RS6000_OUTPUT_BASENAME (stream, name);
15273 putc ('\n', stream);
15274}
15275
15276static void
a2369ed3 15277rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 15278{
0e5dbd9b
DE
15279 int smclass;
15280 static const char * const suffix[3] = { "PR", "RO", "RW" };
15281
15282 if (flags & SECTION_CODE)
15283 smclass = 0;
15284 else if (flags & SECTION_WRITE)
15285 smclass = 2;
15286 else
15287 smclass = 1;
15288
5b5198f7 15289 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 15290 (flags & SECTION_CODE) ? "." : "",
5b5198f7 15291 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 15292}
ae46c4e0
RH
15293
15294static void
a2369ed3
DJ
15295rs6000_xcoff_select_section (tree decl, int reloc,
15296 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 15297{
5add3202 15298 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 15299 {
0e5dbd9b 15300 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15301 read_only_data_section ();
15302 else
15303 read_only_private_data_section ();
15304 }
15305 else
15306 {
0e5dbd9b 15307 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15308 data_section ();
15309 else
15310 private_data_section ();
15311 }
15312}
15313
15314static void
a2369ed3 15315rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
15316{
15317 const char *name;
ae46c4e0 15318
5b5198f7
DE
15319 /* Use select_section for private and uninitialized data. */
15320 if (!TREE_PUBLIC (decl)
15321 || DECL_COMMON (decl)
0e5dbd9b
DE
15322 || DECL_INITIAL (decl) == NULL_TREE
15323 || DECL_INITIAL (decl) == error_mark_node
15324 || (flag_zero_initialized_in_bss
15325 && initializer_zerop (DECL_INITIAL (decl))))
15326 return;
15327
15328 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15329 name = (*targetm.strip_name_encoding) (name);
15330 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 15331}
b64a1b53 15332
fb49053f
RH
15333/* Select section for constant in constant pool.
15334
15335 On RS/6000, all constants are in the private read-only data area.
15336 However, if this is being placed in the TOC it must be output as a
15337 toc entry. */
15338
b64a1b53 15339static void
a2369ed3
DJ
15340rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
15341 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
15342{
15343 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
15344 toc_section ();
15345 else
15346 read_only_private_data_section ();
15347}
772c5265
RH
15348
15349/* Remove any trailing [DS] or the like from the symbol name. */
15350
15351static const char *
a2369ed3 15352rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
15353{
15354 size_t len;
15355 if (*name == '*')
15356 name++;
15357 len = strlen (name);
15358 if (name[len - 1] == ']')
15359 return ggc_alloc_string (name, len - 4);
15360 else
15361 return name;
15362}
15363
5add3202
DE
15364/* Section attributes. AIX is always PIC. */
15365
15366static unsigned int
a2369ed3 15367rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 15368{
5b5198f7
DE
15369 unsigned int align;
15370 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
15371
15372 /* Align to at least UNIT size. */
15373 if (flags & SECTION_CODE)
15374 align = MIN_UNITS_PER_WORD;
15375 else
15376 /* Increase alignment of large objects if not already stricter. */
15377 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
15378 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
15379 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
15380
15381 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 15382}
a5fe455b 15383
1bc7c5b6
ZW
15384/* Output at beginning of assembler file.
15385
15386 Initialize the section names for the RS/6000 at this point.
15387
15388 Specify filename, including full path, to assembler.
15389
15390 We want to go into the TOC section so at least one .toc will be emitted.
15391 Also, in order to output proper .bs/.es pairs, we need at least one static
15392 [RW] section emitted.
15393
15394 Finally, declare mcount when profiling to make the assembler happy. */
15395
15396static void
863d938c 15397rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
15398{
15399 rs6000_gen_section_name (&xcoff_bss_section_name,
15400 main_input_filename, ".bss_");
15401 rs6000_gen_section_name (&xcoff_private_data_section_name,
15402 main_input_filename, ".rw_");
15403 rs6000_gen_section_name (&xcoff_read_only_section_name,
15404 main_input_filename, ".ro_");
15405
15406 fputs ("\t.file\t", asm_out_file);
15407 output_quoted_string (asm_out_file, main_input_filename);
15408 fputc ('\n', asm_out_file);
15409 toc_section ();
15410 if (write_symbols != NO_DEBUG)
15411 private_data_section ();
15412 text_section ();
15413 if (profile_flag)
15414 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
15415 rs6000_file_start ();
15416}
15417
a5fe455b
ZW
15418/* Output at end of assembler file.
15419 On the RS/6000, referencing data should automatically pull in text. */
15420
15421static void
863d938c 15422rs6000_xcoff_file_end (void)
a5fe455b
ZW
15423{
15424 text_section ();
15425 fputs ("_section_.text:\n", asm_out_file);
15426 data_section ();
15427 fputs (TARGET_32BIT
15428 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
15429 asm_out_file);
15430}
f1384257 15431#endif /* TARGET_XCOFF */
0e5dbd9b 15432
f1384257
AM
15433#if TARGET_MACHO
15434/* Cross-module name binding. Darwin does not support overriding
7f3d8013 15435 functions at dynamic-link time. */
0e5dbd9b 15436
2bcc50d0 15437static bool
a2369ed3 15438rs6000_binds_local_p (tree decl)
0e5dbd9b 15439{
f1384257 15440 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 15441}
f1384257 15442#endif
34bb030a 15443
3c50106f
RH
15444/* Compute a (partial) cost for rtx X. Return true if the complete
15445 cost has been computed, and false if subexpressions should be
15446 scanned. In either case, *TOTAL contains the cost result. */
15447
15448static bool
a2369ed3
DJ
15449rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
15450 int *total)
3c50106f
RH
15451{
15452 switch (code)
15453 {
15454 /* On the RS/6000, if it is valid in the insn, it is free.
15455 So this always returns 0. */
15456 case CONST_INT:
15457 case CONST:
15458 case LABEL_REF:
15459 case SYMBOL_REF:
15460 case CONST_DOUBLE:
15461 case HIGH:
15462 *total = 0;
15463 return true;
15464
15465 case PLUS:
15466 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15467 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
15468 + 0x8000) >= 0x10000)
15469 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15470 ? COSTS_N_INSNS (2)
15471 : COSTS_N_INSNS (1));
15472 return true;
15473
15474 case AND:
15475 case IOR:
15476 case XOR:
15477 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15478 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
15479 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15480 ? COSTS_N_INSNS (2)
15481 : COSTS_N_INSNS (1));
15482 return true;
15483
15484 case MULT:
15485 if (optimize_size)
15486 {
15487 *total = COSTS_N_INSNS (2);
15488 return true;
15489 }
15490 switch (rs6000_cpu)
15491 {
15492 case PROCESSOR_RIOS1:
15493 case PROCESSOR_PPC405:
15494 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15495 ? COSTS_N_INSNS (5)
15496 : (INTVAL (XEXP (x, 1)) >= -256
15497 && INTVAL (XEXP (x, 1)) <= 255)
15498 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15499 return true;
15500
02ca7595
DE
15501 case PROCESSOR_PPC440:
15502 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15503 ? COSTS_N_INSNS (3)
15504 : COSTS_N_INSNS (2));
15505 return true;
15506
3c50106f
RH
15507 case PROCESSOR_RS64A:
15508 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15509 ? GET_MODE (XEXP (x, 1)) != DImode
15510 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
15511 : (INTVAL (XEXP (x, 1)) >= -256
15512 && INTVAL (XEXP (x, 1)) <= 255)
15513 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
15514 return true;
15515
15516 case PROCESSOR_RIOS2:
15517 case PROCESSOR_MPCCORE:
15518 case PROCESSOR_PPC604e:
15519 *total = COSTS_N_INSNS (2);
15520 return true;
15521
15522 case PROCESSOR_PPC601:
15523 *total = COSTS_N_INSNS (5);
15524 return true;
15525
15526 case PROCESSOR_PPC603:
15527 case PROCESSOR_PPC7400:
15528 case PROCESSOR_PPC750:
15529 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15530 ? COSTS_N_INSNS (5)
15531 : (INTVAL (XEXP (x, 1)) >= -256
15532 && INTVAL (XEXP (x, 1)) <= 255)
15533 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
15534 return true;
15535
15536 case PROCESSOR_PPC7450:
15537 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15538 ? COSTS_N_INSNS (4)
15539 : COSTS_N_INSNS (3));
15540 return true;
15541
15542 case PROCESSOR_PPC403:
15543 case PROCESSOR_PPC604:
15544 case PROCESSOR_PPC8540:
15545 *total = COSTS_N_INSNS (4);
15546 return true;
15547
15548 case PROCESSOR_PPC620:
15549 case PROCESSOR_PPC630:
3c50106f
RH
15550 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15551 ? GET_MODE (XEXP (x, 1)) != DImode
15552 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
15553 : (INTVAL (XEXP (x, 1)) >= -256
15554 && INTVAL (XEXP (x, 1)) <= 255)
15555 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15556 return true;
15557
9259f3b0
DE
15558 case PROCESSOR_POWER4:
15559 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15560 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
15561 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
15562 : COSTS_N_INSNS (2));
9259f3b0
DE
15563 return true;
15564
3c50106f
RH
15565 default:
15566 abort ();
15567 }
15568
15569 case DIV:
15570 case MOD:
15571 if (GET_CODE (XEXP (x, 1)) == CONST_INT
15572 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
15573 {
15574 *total = COSTS_N_INSNS (2);
15575 return true;
15576 }
5efb1046 15577 /* FALLTHRU */
3c50106f
RH
15578
15579 case UDIV:
15580 case UMOD:
15581 switch (rs6000_cpu)
15582 {
15583 case PROCESSOR_RIOS1:
15584 *total = COSTS_N_INSNS (19);
15585 return true;
15586
15587 case PROCESSOR_RIOS2:
15588 *total = COSTS_N_INSNS (13);
15589 return true;
15590
15591 case PROCESSOR_RS64A:
15592 *total = (GET_MODE (XEXP (x, 1)) != DImode
15593 ? COSTS_N_INSNS (65)
15594 : COSTS_N_INSNS (67));
15595 return true;
15596
15597 case PROCESSOR_MPCCORE:
15598 *total = COSTS_N_INSNS (6);
15599 return true;
15600
15601 case PROCESSOR_PPC403:
15602 *total = COSTS_N_INSNS (33);
15603 return true;
15604
15605 case PROCESSOR_PPC405:
15606 *total = COSTS_N_INSNS (35);
15607 return true;
15608
02ca7595
DE
15609 case PROCESSOR_PPC440:
15610 *total = COSTS_N_INSNS (34);
15611 return true;
15612
3c50106f
RH
15613 case PROCESSOR_PPC601:
15614 *total = COSTS_N_INSNS (36);
15615 return true;
15616
15617 case PROCESSOR_PPC603:
15618 *total = COSTS_N_INSNS (37);
15619 return true;
15620
15621 case PROCESSOR_PPC604:
15622 case PROCESSOR_PPC604e:
15623 *total = COSTS_N_INSNS (20);
15624 return true;
15625
15626 case PROCESSOR_PPC620:
15627 case PROCESSOR_PPC630:
3c50106f
RH
15628 *total = (GET_MODE (XEXP (x, 1)) != DImode
15629 ? COSTS_N_INSNS (21)
15630 : COSTS_N_INSNS (37));
15631 return true;
15632
15633 case PROCESSOR_PPC750:
15634 case PROCESSOR_PPC8540:
15635 case PROCESSOR_PPC7400:
15636 *total = COSTS_N_INSNS (19);
15637 return true;
15638
15639 case PROCESSOR_PPC7450:
15640 *total = COSTS_N_INSNS (23);
15641 return true;
984e25ac
DE
15642
15643 case PROCESSOR_POWER4:
15644 *total = (GET_MODE (XEXP (x, 1)) != DImode
15645 ? COSTS_N_INSNS (18)
15646 : COSTS_N_INSNS (34));
15647 return true;
3c50106f
RH
15648
15649 default:
15650 abort ();
15651 }
15652
15653 case FFS:
15654 *total = COSTS_N_INSNS (4);
15655 return true;
15656
15657 case MEM:
a3c9585f 15658 /* MEM should be slightly more expensive than (plus (reg) (const)). */
3c50106f
RH
15659 *total = 5;
15660 return true;
15661
15662 default:
15663 return false;
15664 }
15665}
15666
34bb030a
DE
15667/* A C expression returning the cost of moving data from a register of class
15668 CLASS1 to one of CLASS2. */
15669
15670int
a2369ed3
DJ
15671rs6000_register_move_cost (enum machine_mode mode,
15672 enum reg_class from, enum reg_class to)
34bb030a
DE
15673{
15674 /* Moves from/to GENERAL_REGS. */
15675 if (reg_classes_intersect_p (to, GENERAL_REGS)
15676 || reg_classes_intersect_p (from, GENERAL_REGS))
15677 {
15678 if (! reg_classes_intersect_p (to, GENERAL_REGS))
15679 from = to;
15680
15681 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
15682 return (rs6000_memory_move_cost (mode, from, 0)
15683 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
15684
a3c9585f 15685/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
15686 else if (from == CR_REGS)
15687 return 4;
15688
15689 else
15690/* A move will cost one instruction per GPR moved. */
15691 return 2 * HARD_REGNO_NREGS (0, mode);
15692 }
15693
15694/* Moving between two similar registers is just one instruction. */
15695 else if (reg_classes_intersect_p (to, from))
15696 return mode == TFmode ? 4 : 2;
15697
15698/* Everything else has to go through GENERAL_REGS. */
15699 else
15700 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
15701 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
15702}
15703
15704/* A C expressions returning the cost of moving data of MODE from a register to
15705 or from memory. */
15706
15707int
a2369ed3
DJ
15708rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
15709 int in ATTRIBUTE_UNUSED)
34bb030a
DE
15710{
15711 if (reg_classes_intersect_p (class, GENERAL_REGS))
15712 return 4 * HARD_REGNO_NREGS (0, mode);
15713 else if (reg_classes_intersect_p (class, FLOAT_REGS))
15714 return 4 * HARD_REGNO_NREGS (32, mode);
15715 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
15716 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
15717 else
15718 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
15719}
15720
ded9bf77
AH
15721/* Return an RTX representing where to find the function value of a
15722 function returning MODE. */
15723static rtx
15724rs6000_complex_function_value (enum machine_mode mode)
15725{
15726 unsigned int regno;
15727 rtx r1, r2;
15728 enum machine_mode inner = GET_MODE_INNER (mode);
15729
15730 if (FLOAT_MODE_P (mode))
15731 regno = FP_ARG_RETURN;
15732 else
15733 {
15734 regno = GP_ARG_RETURN;
15735
15736 /* 32-bit is OK since it'll go in r3/r4. */
165848da
AH
15737 if (TARGET_32BIT
15738 && GET_MODE_BITSIZE (inner) >= 32)
ded9bf77
AH
15739 return gen_rtx_REG (mode, regno);
15740 }
15741
15742 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
15743 const0_rtx);
15744 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
15745 GEN_INT (GET_MODE_UNIT_SIZE (inner)));
15746 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
15747}
15748
a6ebc39a
AH
15749/* Define how to find the value returned by a function.
15750 VALTYPE is the data type of the value (as a tree).
15751 If the precise function being called is known, FUNC is its FUNCTION_DECL;
15752 otherwise, FUNC is 0.
15753
15754 On the SPE, both FPs and vectors are returned in r3.
15755
15756 On RS/6000 an integer value is in r3 and a floating-point value is in
15757 fp1, unless -msoft-float. */
15758
15759rtx
15760rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
15761{
15762 enum machine_mode mode;
2a8fa26c 15763 unsigned int regno;
a6ebc39a 15764
0e67400a
FJ
15765 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
15766 {
15767 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
15768 return gen_rtx_PARALLEL (DImode,
15769 gen_rtvec (2,
15770 gen_rtx_EXPR_LIST (VOIDmode,
15771 gen_rtx_REG (SImode, GP_ARG_RETURN),
15772 const0_rtx),
15773 gen_rtx_EXPR_LIST (VOIDmode,
15774 gen_rtx_REG (SImode,
15775 GP_ARG_RETURN + 1),
15776 GEN_INT (4))));
15777 }
15778
a6ebc39a
AH
15779 if ((INTEGRAL_TYPE_P (valtype)
15780 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
15781 || POINTER_TYPE_P (valtype))
b78d48dd 15782 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
15783 else
15784 mode = TYPE_MODE (valtype);
15785
2a8fa26c
DE
15786 if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS)
15787 regno = FP_ARG_RETURN;
ded9bf77
AH
15788 else if (TREE_CODE (valtype) == COMPLEX_TYPE
15789 && TARGET_HARD_FLOAT
15790 && SPLIT_COMPLEX_ARGS)
15791 return rs6000_complex_function_value (mode);
2a8fa26c 15792 else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC)
a6ebc39a
AH
15793 regno = ALTIVEC_ARG_RETURN;
15794 else
15795 regno = GP_ARG_RETURN;
15796
15797 return gen_rtx_REG (mode, regno);
15798}
15799
ded9bf77
AH
15800/* Define how to find the value returned by a library function
15801 assuming the value has mode MODE. */
15802rtx
15803rs6000_libcall_value (enum machine_mode mode)
15804{
15805 unsigned int regno;
15806
15807 if (GET_MODE_CLASS (mode) == MODE_FLOAT
15808 && TARGET_HARD_FLOAT && TARGET_FPRS)
15809 regno = FP_ARG_RETURN;
15810 else if (ALTIVEC_VECTOR_MODE (mode))
15811 regno = ALTIVEC_ARG_RETURN;
15812 else if (COMPLEX_MODE_P (mode) && SPLIT_COMPLEX_ARGS)
15813 return rs6000_complex_function_value (mode);
15814 else
15815 regno = GP_ARG_RETURN;
15816
15817 return gen_rtx_REG (mode, regno);
15818}
15819
d1d0c603
JJ
15820/* Define the offset between two registers, FROM to be eliminated and its
15821 replacement TO, at the start of a routine. */
15822HOST_WIDE_INT
15823rs6000_initial_elimination_offset (int from, int to)
15824{
15825 rs6000_stack_t *info = rs6000_stack_info ();
15826 HOST_WIDE_INT offset;
15827
15828 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
15829 offset = info->push_p ? 0 : -info->total_size;
15830 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
15831 offset = info->total_size;
15832 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
15833 offset = info->push_p ? info->total_size : 0;
15834 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
15835 offset = 0;
15836 else
15837 abort ();
15838
15839 return offset;
15840}
15841
62e1dfcf
NC
15842/* Return true if TYPE is of type __ev64_opaque__. */
15843
c8e4f0e9 15844static bool
a2369ed3 15845is_ev64_opaque_type (tree type)
62e1dfcf 15846{
c8e4f0e9 15847 return (TARGET_SPE
2abe3e28
AH
15848 && (type == opaque_V2SI_type_node
15849 || type == opaque_V2SF_type_node
36252949 15850 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
15851}
15852
96714395 15853static rtx
a2369ed3 15854rs6000_dwarf_register_span (rtx reg)
96714395
AH
15855{
15856 unsigned regno;
15857
15858 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
15859 return NULL_RTX;
15860
15861 regno = REGNO (reg);
15862
15863 /* The duality of the SPE register size wreaks all kinds of havoc.
15864 This is a way of distinguishing r0 in 32-bits from r0 in
15865 64-bits. */
15866 return
15867 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
15868 BYTES_BIG_ENDIAN
15869 ? gen_rtvec (2,
15870 gen_rtx_REG (SImode, regno + 1200),
15871 gen_rtx_REG (SImode, regno))
15872 : gen_rtvec (2,
15873 gen_rtx_REG (SImode, regno),
15874 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
15875}
15876
93c9d1ba
AM
15877/* Map internal gcc register numbers to DWARF2 register numbers. */
15878
15879unsigned int
15880rs6000_dbx_register_number (unsigned int regno)
15881{
15882 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
15883 return regno;
15884 if (regno == MQ_REGNO)
15885 return 100;
15886 if (regno == LINK_REGISTER_REGNUM)
15887 return 108;
15888 if (regno == COUNT_REGISTER_REGNUM)
15889 return 109;
15890 if (CR_REGNO_P (regno))
15891 return regno - CR0_REGNO + 86;
15892 if (regno == XER_REGNO)
15893 return 101;
15894 if (ALTIVEC_REGNO_P (regno))
15895 return regno - FIRST_ALTIVEC_REGNO + 1124;
15896 if (regno == VRSAVE_REGNO)
15897 return 356;
15898 if (regno == VSCR_REGNO)
15899 return 67;
15900 if (regno == SPE_ACC_REGNO)
15901 return 99;
15902 if (regno == SPEFSCR_REGNO)
15903 return 612;
15904 /* SPE high reg number. We get these values of regno from
15905 rs6000_dwarf_register_span. */
15906 if (regno >= 1200 && regno < 1232)
15907 return regno;
15908
15909 abort ();
15910}
15911
17211ab5 15912#include "gt-rs6000.h"