]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/rs6000.c
darwin.c, [...]: Fix comment formatting.
[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
DJ
3838init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
3839 rtx libname ATTRIBUTE_UNUSED, int incoming, int libcall)
4697a36c
MM
3840{
3841 static CUMULATIVE_ARGS zero_cumulative;
3842
3843 *cum = zero_cumulative;
3844 cum->words = 0;
3845 cum->fregno = FP_ARG_MIN_REG;
0ac081f6 3846 cum->vregno = ALTIVEC_ARG_MIN_REG;
4697a36c 3847 cum->prototype = (fntype && TYPE_ARG_TYPES (fntype));
ddcc8263
DE
3848 cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
3849 ? CALL_LIBCALL : CALL_NORMAL);
4cc833b7 3850 cum->sysv_gregno = GP_ARG_MIN_REG;
a6c9bed4
AH
3851 cum->stdarg = fntype
3852 && (TYPE_ARG_TYPES (fntype) != 0
3853 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
3854 != void_type_node));
4697a36c
MM
3855
3856 if (incoming)
bd227acc 3857 cum->nargs_prototype = 1000; /* don't return a PARALLEL */
4697a36c
MM
3858
3859 else if (cum->prototype)
3860 cum->nargs_prototype = (list_length (TYPE_ARG_TYPES (fntype)) - 1
3861 + (TYPE_MODE (TREE_TYPE (fntype)) == BLKmode
c6e8c921
GK
3862 || rs6000_return_in_memory (TREE_TYPE (fntype),
3863 fntype)));
4697a36c
MM
3864
3865 else
3866 cum->nargs_prototype = 0;
3867
a5c76ee6
ZW
3868 /* Check for a longcall attribute. */
3869 if (fntype
3870 && lookup_attribute ("longcall", TYPE_ATTRIBUTES (fntype))
3871 && !lookup_attribute ("shortcall", TYPE_ATTRIBUTES (fntype)))
6a4cee5f
MM
3872 cum->call_cookie = CALL_LONG;
3873
4697a36c
MM
3874 if (TARGET_DEBUG_ARG)
3875 {
3876 fprintf (stderr, "\ninit_cumulative_args:");
3877 if (fntype)
3878 {
3879 tree ret_type = TREE_TYPE (fntype);
3880 fprintf (stderr, " ret code = %s,",
3881 tree_code_name[ (int)TREE_CODE (ret_type) ]);
3882 }
3883
6a4cee5f
MM
3884 if (cum->call_cookie & CALL_LONG)
3885 fprintf (stderr, " longcall,");
3886
4697a36c
MM
3887 fprintf (stderr, " proto = %d, nargs = %d\n",
3888 cum->prototype, cum->nargs_prototype);
3889 }
3890}
3891\f
c229cba9
DE
3892/* If defined, a C expression which determines whether, and in which
3893 direction, to pad out an argument with extra space. The value
3894 should be of type `enum direction': either `upward' to pad above
3895 the argument, `downward' to pad below, or `none' to inhibit
3896 padding.
3897
3898 For the AIX ABI structs are always stored left shifted in their
3899 argument slot. */
3900
9ebbca7d 3901enum direction
a2369ed3 3902function_arg_padding (enum machine_mode mode, tree type)
c229cba9 3903{
6e985040
AM
3904#ifndef AGGREGATE_PADDING_FIXED
3905#define AGGREGATE_PADDING_FIXED 0
3906#endif
3907#ifndef AGGREGATES_PAD_UPWARD_ALWAYS
3908#define AGGREGATES_PAD_UPWARD_ALWAYS 0
3909#endif
3910
3911 if (!AGGREGATE_PADDING_FIXED)
3912 {
3913 /* GCC used to pass structures of the same size as integer types as
3914 if they were in fact integers, ignoring FUNCTION_ARG_PADDING.
3915 ie. Structures of size 1 or 2 (or 4 when TARGET_64BIT) were
3916 passed padded downward, except that -mstrict-align further
3917 muddied the water in that multi-component structures of 2 and 4
3918 bytes in size were passed padded upward.
3919
3920 The following arranges for best compatibility with previous
3921 versions of gcc, but removes the -mstrict-align dependency. */
3922 if (BYTES_BIG_ENDIAN)
3923 {
3924 HOST_WIDE_INT size = 0;
3925
3926 if (mode == BLKmode)
3927 {
3928 if (type && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
3929 size = int_size_in_bytes (type);
3930 }
3931 else
3932 size = GET_MODE_SIZE (mode);
3933
3934 if (size == 1 || size == 2 || size == 4)
3935 return downward;
3936 }
3937 return upward;
3938 }
3939
3940 if (AGGREGATES_PAD_UPWARD_ALWAYS)
3941 {
3942 if (type != 0 && AGGREGATE_TYPE_P (type))
3943 return upward;
3944 }
c229cba9 3945
d3704c46
KH
3946 /* Fall back to the default. */
3947 return DEFAULT_FUNCTION_ARG_PADDING (mode, type);
c229cba9
DE
3948}
3949
b6c9286a
MM
3950/* If defined, a C expression that gives the alignment boundary, in bits,
3951 of an argument with the specified mode and type. If it is not defined,
3952 PARM_BOUNDARY is used for all arguments.
3953
2310f99a 3954 V.4 wants long longs to be double word aligned. */
b6c9286a
MM
3955
3956int
a2369ed3 3957function_arg_boundary (enum machine_mode mode, tree type ATTRIBUTE_UNUSED)
b6c9286a 3958{
f607bc57 3959 if (DEFAULT_ABI == ABI_V4 && (mode == DImode || mode == DFmode))
e1f83b4d 3960 return 64;
a3170dc6
AH
3961 else if (SPE_VECTOR_MODE (mode))
3962 return 64;
0ac081f6
AH
3963 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3964 return 128;
9ebbca7d 3965 else
b6c9286a 3966 return PARM_BOUNDARY;
b6c9286a
MM
3967}
3968\f
4697a36c
MM
3969/* Update the data in CUM to advance over an argument
3970 of mode MODE and data type TYPE.
3971 (TYPE is null for libcalls where that information may not be available.) */
3972
3973void
a2369ed3
DJ
3974function_arg_advance (CUMULATIVE_ARGS *cum, enum machine_mode mode,
3975 tree type, int named)
4697a36c
MM
3976{
3977 cum->nargs_prototype--;
3978
0ac081f6
AH
3979 if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
3980 {
2858f73a 3981 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
0ac081f6 3982 cum->vregno++;
2858f73a 3983
c72d6c26
HP
3984 /* PowerPC64 Linux and AIX allocates GPRs for a vector argument
3985 even if it is going to be passed in a vector register.
3986 Darwin does the same for variable-argument functions. */
3987 if ((DEFAULT_ABI == ABI_AIX && TARGET_64BIT)
3988 || (cum->stdarg && DEFAULT_ABI != ABI_V4))
3989 {
a594a19c
GK
3990 int align;
3991
2858f73a
GK
3992 /* Vector parameters must be 16-byte aligned. This places
3993 them at 2 mod 4 in terms of words in 32-bit mode, since
3994 the parameter save area starts at offset 24 from the
3995 stack. In 64-bit mode, they just have to start on an
3996 even word, since the parameter save area is 16-byte
3997 aligned. Space for GPRs is reserved even if the argument
3998 will be passed in memory. */
3999 if (TARGET_32BIT)
4000 align = ((6 - (cum->words & 3)) & 3);
4001 else
4002 align = cum->words & 1;
a594a19c 4003 cum->words += align + RS6000_ARG_SIZE (mode, type);
2858f73a 4004
a594a19c
GK
4005 if (TARGET_DEBUG_ARG)
4006 {
4007 fprintf (stderr, "function_adv: words = %2d, align=%d, ",
4008 cum->words, align);
4009 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s\n",
2858f73a
GK
4010 cum->nargs_prototype, cum->prototype,
4011 GET_MODE_NAME (mode));
a594a19c
GK
4012 }
4013 }
0ac081f6 4014 }
a4b0320c 4015 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode)
a6c9bed4
AH
4016 && !cum->stdarg
4017 && cum->sysv_gregno <= GP_ARG_MAX_REG)
a4b0320c 4018 cum->sysv_gregno++;
f607bc57 4019 else if (DEFAULT_ABI == ABI_V4)
4697a36c 4020 {
a3170dc6 4021 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7 4022 && (mode == SFmode || mode == DFmode))
4697a36c 4023 {
4cc833b7
RH
4024 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4025 cum->fregno++;
4026 else
4027 {
4028 if (mode == DFmode)
4029 cum->words += cum->words & 1;
d34c5b80 4030 cum->words += RS6000_ARG_SIZE (mode, type);
4cc833b7 4031 }
4697a36c 4032 }
4cc833b7
RH
4033 else
4034 {
4035 int n_words;
4036 int gregno = cum->sysv_gregno;
4037
4038 /* Aggregates and IEEE quad get passed by reference. */
4039 if ((type && AGGREGATE_TYPE_P (type))
4040 || mode == TFmode)
4041 n_words = 1;
4042 else
d34c5b80 4043 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 4044
a4b0320c 4045 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4046 if (n_words == 2 && (gregno & 1) == 0)
4047 gregno += 1;
4048
a4b0320c
AH
4049 /* Long long and SPE vectors are not split between registers
4050 and stack. */
4cc833b7
RH
4051 if (gregno + n_words - 1 > GP_ARG_MAX_REG)
4052 {
4053 /* Long long is aligned on the stack. */
4054 if (n_words == 2)
4055 cum->words += cum->words & 1;
4056 cum->words += n_words;
4057 }
4697a36c 4058
4cc833b7
RH
4059 /* Note: continuing to accumulate gregno past when we've started
4060 spilling to the stack indicates the fact that we've started
4061 spilling to the stack to expand_builtin_saveregs. */
4062 cum->sysv_gregno = gregno + n_words;
4063 }
4697a36c 4064
4cc833b7
RH
4065 if (TARGET_DEBUG_ARG)
4066 {
4067 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4068 cum->words, cum->fregno);
4069 fprintf (stderr, "gregno = %2d, nargs = %4d, proto = %d, ",
4070 cum->sysv_gregno, cum->nargs_prototype, cum->prototype);
4071 fprintf (stderr, "mode = %4s, named = %d\n",
4072 GET_MODE_NAME (mode), named);
4073 }
4697a36c
MM
4074 }
4075 else
4cc833b7
RH
4076 {
4077 int align = (TARGET_32BIT && (cum->words & 1) != 0
4078 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
a4f6c312 4079
d34c5b80 4080 cum->words += align + RS6000_ARG_SIZE (mode, type);
4697a36c 4081
a3170dc6
AH
4082 if (GET_MODE_CLASS (mode) == MODE_FLOAT
4083 && TARGET_HARD_FLOAT && TARGET_FPRS)
fcce224d 4084 cum->fregno += (mode == TFmode ? 2 : 1);
4cc833b7
RH
4085
4086 if (TARGET_DEBUG_ARG)
4087 {
4088 fprintf (stderr, "function_adv: words = %2d, fregno = %2d, ",
4089 cum->words, cum->fregno);
4090 fprintf (stderr, "nargs = %4d, proto = %d, mode = %4s, ",
4091 cum->nargs_prototype, cum->prototype, GET_MODE_NAME (mode));
4092 fprintf (stderr, "named = %d, align = %d\n", named, align);
4093 }
4094 }
4697a36c 4095}
a6c9bed4
AH
4096
4097/* Determine where to put a SIMD argument on the SPE. */
b78d48dd 4098
a6c9bed4 4099static rtx
a2369ed3
DJ
4100rs6000_spe_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4101 tree type)
a6c9bed4
AH
4102{
4103 if (cum->stdarg)
4104 {
4105 int gregno = cum->sysv_gregno;
4106 int n_words = RS6000_ARG_SIZE (mode, type);
4107
4108 /* SPE vectors are put in odd registers. */
4109 if (n_words == 2 && (gregno & 1) == 0)
4110 gregno += 1;
4111
4112 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
4113 {
4114 rtx r1, r2;
4115 enum machine_mode m = SImode;
4116
4117 r1 = gen_rtx_REG (m, gregno);
4118 r1 = gen_rtx_EXPR_LIST (m, r1, const0_rtx);
4119 r2 = gen_rtx_REG (m, gregno + 1);
4120 r2 = gen_rtx_EXPR_LIST (m, r2, GEN_INT (4));
4121 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
4122 }
4123 else
b78d48dd 4124 return NULL_RTX;
a6c9bed4
AH
4125 }
4126 else
4127 {
4128 if (cum->sysv_gregno <= GP_ARG_MAX_REG)
4129 return gen_rtx_REG (mode, cum->sysv_gregno);
4130 else
b78d48dd 4131 return NULL_RTX;
a6c9bed4
AH
4132 }
4133}
4134
b78d48dd
FJ
4135/* Determine where to place an argument in 64-bit mode with 32-bit ABI. */
4136
4137static rtx
4138rs6000_mixed_function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4139 tree type, int align_words)
4140{
4141 if (mode == DFmode)
4142 {
4143 /* -mpowerpc64 with 32bit ABI splits up a DFmode argument
4144 in vararg list into zero, one or two GPRs */
4145 if (align_words >= GP_ARG_NUM_REG)
4146 return gen_rtx_PARALLEL (DFmode,
4147 gen_rtvec (2,
4148 gen_rtx_EXPR_LIST (VOIDmode,
4149 NULL_RTX, const0_rtx),
4150 gen_rtx_EXPR_LIST (VOIDmode,
4151 gen_rtx_REG (mode,
4152 cum->fregno),
4153 const0_rtx)));
4154 else if (align_words + RS6000_ARG_SIZE (mode, type)
4155 > GP_ARG_NUM_REG)
4156 /* If this is partially on the stack, then we only
a3c9585f 4157 include the portion actually in registers here. */
b78d48dd
FJ
4158 return gen_rtx_PARALLEL (DFmode,
4159 gen_rtvec (2,
4160 gen_rtx_EXPR_LIST (VOIDmode,
4161 gen_rtx_REG (SImode,
4162 GP_ARG_MIN_REG
4163 + align_words),
4164 const0_rtx),
4165 gen_rtx_EXPR_LIST (VOIDmode,
4166 gen_rtx_REG (mode,
4167 cum->fregno),
4168 const0_rtx)));
4169
4170 /* split a DFmode arg into two GPRs */
4171 return gen_rtx_PARALLEL (DFmode,
4172 gen_rtvec (3,
4173 gen_rtx_EXPR_LIST (VOIDmode,
4174 gen_rtx_REG (SImode,
4175 GP_ARG_MIN_REG
4176 + align_words),
4177 const0_rtx),
4178 gen_rtx_EXPR_LIST (VOIDmode,
4179 gen_rtx_REG (SImode,
4180 GP_ARG_MIN_REG
4181 + align_words + 1),
4182 GEN_INT (4)),
4183 gen_rtx_EXPR_LIST (VOIDmode,
4184 gen_rtx_REG (mode, cum->fregno),
4185 const0_rtx)));
4186 }
4187 /* -mpowerpc64 with 32bit ABI splits up a DImode argument into one
4188 or two GPRs */
4189 else if (mode == DImode)
4190 {
4191 if (align_words < GP_ARG_NUM_REG - 1)
4192 return gen_rtx_PARALLEL (DImode,
4193 gen_rtvec (2,
4194 gen_rtx_EXPR_LIST (VOIDmode,
4195 gen_rtx_REG (SImode,
4196 GP_ARG_MIN_REG
4197 + align_words),
4198 const0_rtx),
4199 gen_rtx_EXPR_LIST (VOIDmode,
4200 gen_rtx_REG (SImode,
4201 GP_ARG_MIN_REG
4202 + align_words + 1),
4203 GEN_INT (4))));
4204 else if (align_words == GP_ARG_NUM_REG - 1)
4205 return gen_rtx_PARALLEL (DImode,
4206 gen_rtvec (2,
4207 gen_rtx_EXPR_LIST (VOIDmode,
4208 NULL_RTX, const0_rtx),
4209 gen_rtx_EXPR_LIST (VOIDmode,
4210 gen_rtx_REG (SImode,
4211 GP_ARG_MIN_REG
4212 + align_words),
4213 const0_rtx)));
4214 }
4215 else if (mode == BLKmode && align_words <= (GP_ARG_NUM_REG - 1))
4216 {
4217 int k;
4218 int size = int_size_in_bytes (type);
2f7b62ef 4219 int no_units = ((size - 1) / 4) + 1;
b78d48dd
FJ
4220 int max_no_words = GP_ARG_NUM_REG - align_words;
4221 int rtlvec_len = no_units < max_no_words ? no_units : max_no_words;
4222 rtx *rtlvec = (rtx *) alloca (rtlvec_len * sizeof (rtx));
4223
4224 memset ((char *) rtlvec, 0, rtlvec_len * sizeof (rtx));
4225
4226 for (k=0; k < rtlvec_len; k++)
4227 rtlvec[k] = gen_rtx_EXPR_LIST (VOIDmode,
4228 gen_rtx_REG (SImode,
4229 GP_ARG_MIN_REG
4230 + align_words + k),
4231 k == 0 ? const0_rtx : GEN_INT (k*4));
4232
4233 return gen_rtx_PARALLEL (BLKmode, gen_rtvec_v (k, rtlvec));
4234 }
4235
4236 return NULL_RTX;
4237}
4238
4697a36c
MM
4239/* Determine where to put an argument to a function.
4240 Value is zero to push the argument on the stack,
4241 or a hard register in which to store the argument.
4242
4243 MODE is the argument's machine mode.
4244 TYPE is the data type of the argument (as a tree).
4245 This is null for libcalls where that information may
4246 not be available.
4247 CUM is a variable of type CUMULATIVE_ARGS which gives info about
4248 the preceding args and about the function being called.
4249 NAMED is nonzero if this argument is a named parameter
4250 (otherwise it is an extra parameter matching an ellipsis).
4251
4252 On RS/6000 the first eight words of non-FP are normally in registers
4253 and the rest are pushed. Under AIX, the first 13 FP args are in registers.
4254 Under V.4, the first 8 FP args are in registers.
4255
4256 If this is floating-point and no prototype is specified, we use
4257 both an FP and integer register (or possibly FP reg and stack). Library
b9599e46 4258 functions (when CALL_LIBCALL is set) always have the proper types for args,
4697a36c 4259 so we can pass the FP value just in one register. emit_library_function
1c20ae99 4260 doesn't support PARALLEL anyway. */
4697a36c
MM
4261
4262struct rtx_def *
a2369ed3
DJ
4263function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4264 tree type, int named)
4697a36c 4265{
4cc833b7 4266 enum rs6000_abi abi = DEFAULT_ABI;
4697a36c 4267
a4f6c312
SS
4268 /* Return a marker to indicate whether CR1 needs to set or clear the
4269 bit that V.4 uses to say fp args were passed in registers.
4270 Assume that we don't need the marker for software floating point,
4271 or compiler generated library calls. */
4697a36c
MM
4272 if (mode == VOIDmode)
4273 {
f607bc57 4274 if (abi == ABI_V4
7509c759 4275 && cum->nargs_prototype < 0
b9599e46
FS
4276 && (cum->call_cookie & CALL_LIBCALL) == 0
4277 && (cum->prototype || TARGET_NO_PROTOTYPE))
7509c759 4278 {
a3170dc6
AH
4279 /* For the SPE, we need to crxor CR6 always. */
4280 if (TARGET_SPE_ABI)
4281 return GEN_INT (cum->call_cookie | CALL_V4_SET_FP_ARGS);
4282 else if (TARGET_HARD_FLOAT && TARGET_FPRS)
4283 return GEN_INT (cum->call_cookie
4284 | ((cum->fregno == FP_ARG_MIN_REG)
4285 ? CALL_V4_SET_FP_ARGS
4286 : CALL_V4_CLEAR_FP_ARGS));
7509c759 4287 }
4697a36c 4288
7509c759 4289 return GEN_INT (cum->call_cookie);
4697a36c
MM
4290 }
4291
2858f73a 4292 if (USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
c72d6c26
HP
4293 if (TARGET_64BIT && ! cum->prototype)
4294 {
4295 /* Vector parameters get passed in vector register
4296 and also in GPRs or memory, in absence of prototype. */
4297 int align_words;
4298 rtx slot;
4299 align_words = (cum->words + 1) & ~1;
4300
4301 if (align_words >= GP_ARG_NUM_REG)
4302 {
4303 slot = NULL_RTX;
4304 }
4305 else
4306 {
4307 slot = gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4308 }
4309 return gen_rtx_PARALLEL (mode,
4310 gen_rtvec (2,
4311 gen_rtx_EXPR_LIST (VOIDmode,
4312 slot, const0_rtx),
4313 gen_rtx_EXPR_LIST (VOIDmode,
4314 gen_rtx_REG (mode, cum->vregno),
4315 const0_rtx)));
4316 }
4317 else
4318 return gen_rtx_REG (mode, cum->vregno);
2858f73a 4319 else if (TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
0ac081f6 4320 {
2858f73a 4321 if (named || abi == ABI_V4)
a594a19c 4322 return NULL_RTX;
0ac081f6 4323 else
a594a19c
GK
4324 {
4325 /* Vector parameters to varargs functions under AIX or Darwin
4326 get passed in memory and possibly also in GPRs. */
4327 int align, align_words;
2858f73a 4328 enum machine_mode part_mode = mode;
a594a19c
GK
4329
4330 /* Vector parameters must be 16-byte aligned. This places them at
2858f73a
GK
4331 2 mod 4 in terms of words in 32-bit mode, since the parameter
4332 save area starts at offset 24 from the stack. In 64-bit mode,
4333 they just have to start on an even word, since the parameter
4334 save area is 16-byte aligned. */
4335 if (TARGET_32BIT)
4336 align = ((6 - (cum->words & 3)) & 3);
4337 else
4338 align = cum->words & 1;
a594a19c
GK
4339 align_words = cum->words + align;
4340
4341 /* Out of registers? Memory, then. */
4342 if (align_words >= GP_ARG_NUM_REG)
4343 return NULL_RTX;
4344
2858f73a
GK
4345 /* The vector value goes in GPRs. Only the part of the
4346 value in GPRs is reported here. */
4347 if (align_words + CLASS_MAX_NREGS (mode, GENERAL_REGS)
4348 > GP_ARG_NUM_REG)
839a4992 4349 /* Fortunately, there are only two possibilities, the value
2858f73a
GK
4350 is either wholly in GPRs or half in GPRs and half not. */
4351 part_mode = DImode;
4352
4353 return gen_rtx_REG (part_mode, GP_ARG_MIN_REG + align_words);
a594a19c 4354 }
0ac081f6 4355 }
a6c9bed4
AH
4356 else if (TARGET_SPE_ABI && TARGET_SPE && SPE_VECTOR_MODE (mode))
4357 return rs6000_spe_function_arg (cum, mode, type);
f607bc57 4358 else if (abi == ABI_V4)
4697a36c 4359 {
a3170dc6 4360 if (TARGET_HARD_FLOAT && TARGET_FPRS
4cc833b7
RH
4361 && (mode == SFmode || mode == DFmode))
4362 {
4363 if (cum->fregno <= FP_ARG_V4_MAX_REG)
4364 return gen_rtx_REG (mode, cum->fregno);
4365 else
b78d48dd 4366 return NULL_RTX;
4cc833b7
RH
4367 }
4368 else
4369 {
4370 int n_words;
4371 int gregno = cum->sysv_gregno;
4372
4373 /* Aggregates and IEEE quad get passed by reference. */
4374 if ((type && AGGREGATE_TYPE_P (type))
4375 || mode == TFmode)
4376 n_words = 1;
4377 else
d34c5b80 4378 n_words = RS6000_ARG_SIZE (mode, type);
4cc833b7 4379
a4b0320c 4380 /* Long long and SPE vectors are put in odd registers. */
4cc833b7
RH
4381 if (n_words == 2 && (gregno & 1) == 0)
4382 gregno += 1;
4383
a6c9bed4 4384 /* Long long do not split between registers and stack. */
4cc833b7 4385 if (gregno + n_words - 1 <= GP_ARG_MAX_REG)
a6c9bed4 4386 return gen_rtx_REG (mode, gregno);
4cc833b7 4387 else
b78d48dd 4388 return NULL_RTX;
4cc833b7 4389 }
4697a36c 4390 }
4cc833b7
RH
4391 else
4392 {
4393 int align = (TARGET_32BIT && (cum->words & 1) != 0
4394 && function_arg_boundary (mode, type) == 64) ? 1 : 0;
4395 int align_words = cum->words + align;
4697a36c 4396
4cc833b7
RH
4397 if (type && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
4398 return NULL_RTX;
4399
b78d48dd
FJ
4400 if (TARGET_32BIT && TARGET_POWERPC64
4401 && (mode == DFmode || mode == DImode || mode == BLKmode))
4402 return rs6000_mixed_function_arg (cum, mode, type, align_words);
4403
2858f73a 4404 if (USE_FP_FOR_ARG_P (cum, mode, type))
4cc833b7
RH
4405 {
4406 if (! type
4407 || ((cum->nargs_prototype > 0)
4408 /* IBM AIX extended its linkage convention definition always
4409 to require FP args after register save area hole on the
4410 stack. */
4411 && (DEFAULT_ABI != ABI_AIX
4412 || ! TARGET_XL_CALL
4413 || (align_words < GP_ARG_NUM_REG))))
4414 return gen_rtx_REG (mode, cum->fregno);
4415
4416 return gen_rtx_PARALLEL (mode,
4417 gen_rtvec (2,
39403d82 4418 gen_rtx_EXPR_LIST (VOIDmode,
1c20ae99
JW
4419 ((align_words >= GP_ARG_NUM_REG)
4420 ? NULL_RTX
4421 : (align_words
d34c5b80 4422 + RS6000_ARG_SIZE (mode, type)
1c20ae99
JW
4423 > GP_ARG_NUM_REG
4424 /* If this is partially on the stack, then
4425 we only include the portion actually
4426 in registers here. */
39403d82 4427 ? gen_rtx_REG (SImode,
1c20ae99 4428 GP_ARG_MIN_REG + align_words)
39403d82 4429 : gen_rtx_REG (mode,
1c20ae99
JW
4430 GP_ARG_MIN_REG + align_words))),
4431 const0_rtx),
39403d82
DE
4432 gen_rtx_EXPR_LIST (VOIDmode,
4433 gen_rtx_REG (mode, cum->fregno),
1c20ae99 4434 const0_rtx)));
4cc833b7
RH
4435 }
4436 else if (align_words < GP_ARG_NUM_REG)
4437 return gen_rtx_REG (mode, GP_ARG_MIN_REG + align_words);
4438 else
4439 return NULL_RTX;
4697a36c 4440 }
4697a36c
MM
4441}
4442\f
4443/* For an arg passed partly in registers and partly in memory,
4444 this is the number of registers used.
4445 For args passed entirely in registers or entirely in memory, zero. */
4446
4447int
a2369ed3 4448function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
2858f73a 4449 tree type, int named)
4697a36c 4450{
f607bc57 4451 if (DEFAULT_ABI == ABI_V4)
4697a36c 4452 return 0;
4697a36c 4453
2858f73a
GK
4454 if (USE_FP_FOR_ARG_P (cum, mode, type)
4455 || USE_ALTIVEC_FOR_ARG_P (cum, mode, type, named))
4697a36c
MM
4456 {
4457 if (cum->nargs_prototype >= 0)
4458 return 0;
4459 }
4460
4461 if (cum->words < GP_ARG_NUM_REG
d34c5b80 4462 && GP_ARG_NUM_REG < (cum->words + RS6000_ARG_SIZE (mode, type)))
4697a36c
MM
4463 {
4464 int ret = GP_ARG_NUM_REG - cum->words;
4465 if (ret && TARGET_DEBUG_ARG)
4466 fprintf (stderr, "function_arg_partial_nregs: %d\n", ret);
4467
4468 return ret;
4469 }
4470
4471 return 0;
4472}
4473\f
4474/* A C expression that indicates when an argument must be passed by
4475 reference. If nonzero for an argument, a copy of that argument is
4476 made in memory and a pointer to the argument is passed instead of
4477 the argument itself. The pointer is passed in whatever way is
4478 appropriate for passing a pointer to that type.
4479
c8c99a68
DE
4480 Under V.4, structures and unions are passed by reference.
4481
4482 As an extension to all ABIs, variable sized types are passed by
4483 reference. */
4697a36c
MM
4484
4485int
a2369ed3
DJ
4486function_arg_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
4487 enum machine_mode mode ATTRIBUTE_UNUSED,
d779d0dc 4488 tree type, int named ATTRIBUTE_UNUSED)
4697a36c 4489{
f607bc57 4490 if (DEFAULT_ABI == ABI_V4
4cc833b7
RH
4491 && ((type && AGGREGATE_TYPE_P (type))
4492 || mode == TFmode))
4697a36c
MM
4493 {
4494 if (TARGET_DEBUG_ARG)
4495 fprintf (stderr, "function_arg_pass_by_reference: aggregate\n");
4496
4497 return 1;
4498 }
fff2cb99 4499 return type && int_size_in_bytes (type) < 0;
4697a36c 4500}
5985c7a6
FJ
4501
4502static void
2d9db8eb 4503rs6000_move_block_from_reg (int regno, rtx x, int nregs)
5985c7a6
FJ
4504{
4505 int i;
4506 enum machine_mode reg_mode = TARGET_32BIT ? SImode : DImode;
4507
4508 if (nregs == 0)
4509 return;
4510
4511 for (i = 0; i < nregs; i++)
4512 {
4513 rtx tem = adjust_address_nv (x, reg_mode, i*GET_MODE_SIZE(reg_mode));
4514 if (reload_completed)
4515 {
4516 if (! strict_memory_address_p (reg_mode, XEXP (tem, 0)))
4517 tem = NULL_RTX;
4518 else
4519 tem = simplify_gen_subreg (reg_mode, x, BLKmode,
4520 i * GET_MODE_SIZE(reg_mode));
4521 }
4522 else
4523 tem = replace_equiv_address (tem, XEXP (tem, 0));
4524
4525 if (tem == NULL_RTX)
4526 abort ();
4527
4528 emit_move_insn (tem, gen_rtx_REG (reg_mode, regno + i));
4529 }
4530}
4531
4697a36c
MM
4532\f
4533/* Perform any needed actions needed for a function that is receiving a
4534 variable number of arguments.
4535
4536 CUM is as above.
4537
4538 MODE and TYPE are the mode and type of the current parameter.
4539
4540 PRETEND_SIZE is a variable that should be set to the amount of stack
4541 that must be pushed by the prolog to pretend that our caller pushed
4542 it.
4543
4544 Normally, this macro will push all remaining incoming registers on the
4545 stack and set PRETEND_SIZE to the length of the registers pushed. */
4546
c6e8c921 4547static void
a2369ed3
DJ
4548setup_incoming_varargs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
4549 tree type, int *pretend_size ATTRIBUTE_UNUSED, int no_rtl)
4697a36c 4550{
4cc833b7
RH
4551 CUMULATIVE_ARGS next_cum;
4552 int reg_size = TARGET_32BIT ? 4 : 8;
ca5adc63 4553 rtx save_area = NULL_RTX, mem;
dfafc897 4554 int first_reg_offset, set;
4697a36c 4555
f31bf321 4556 /* Skip the last named argument. */
d34c5b80 4557 next_cum = *cum;
f31bf321 4558 function_arg_advance (&next_cum, mode, type, 1);
4cc833b7 4559
f607bc57 4560 if (DEFAULT_ABI == ABI_V4)
d34c5b80 4561 {
4cc833b7 4562 /* Indicate to allocate space on the stack for varargs save area. */
00dba523 4563 cfun->machine->sysv_varargs_p = 1;
60e2d0ca 4564 if (! no_rtl)
2c4974b7 4565 save_area = plus_constant (virtual_stack_vars_rtx,
bd227acc 4566 - RS6000_VARARGS_SIZE);
4cc833b7
RH
4567
4568 first_reg_offset = next_cum.sysv_gregno - GP_ARG_MIN_REG;
4697a36c 4569 }
60e2d0ca 4570 else
4697a36c 4571 {
d34c5b80 4572 first_reg_offset = next_cum.words;
4cc833b7 4573 save_area = virtual_incoming_args_rtx;
00dba523 4574 cfun->machine->sysv_varargs_p = 0;
4697a36c
MM
4575
4576 if (MUST_PASS_IN_STACK (mode, type))
d34c5b80 4577 first_reg_offset += RS6000_ARG_SIZE (TYPE_MODE (type), type);
4cc833b7 4578 }
4697a36c 4579
dfafc897 4580 set = get_varargs_alias_set ();
c81fc13e 4581 if (! no_rtl && first_reg_offset < GP_ARG_NUM_REG)
4cc833b7 4582 {
dfafc897
FS
4583 mem = gen_rtx_MEM (BLKmode,
4584 plus_constant (save_area,
4585 first_reg_offset * reg_size)),
ba4828e0 4586 set_mem_alias_set (mem, set);
8ac61af7 4587 set_mem_align (mem, BITS_PER_WORD);
dfafc897 4588
5985c7a6
FJ
4589 rs6000_move_block_from_reg (GP_ARG_MIN_REG + first_reg_offset, mem,
4590 GP_ARG_NUM_REG - first_reg_offset);
4697a36c
MM
4591 }
4592
4697a36c 4593 /* Save FP registers if needed. */
f607bc57 4594 if (DEFAULT_ABI == ABI_V4
a3170dc6
AH
4595 && TARGET_HARD_FLOAT && TARGET_FPRS
4596 && ! no_rtl
4cc833b7 4597 && next_cum.fregno <= FP_ARG_V4_MAX_REG)
4697a36c 4598 {
4cc833b7 4599 int fregno = next_cum.fregno;
9ebbca7d 4600 rtx cr1 = gen_rtx_REG (CCmode, CR1_REGNO);
4cc833b7
RH
4601 rtx lab = gen_label_rtx ();
4602 int off = (GP_ARG_NUM_REG * reg_size) + ((fregno - FP_ARG_MIN_REG) * 8);
4697a36c 4603
4cc833b7 4604 emit_jump_insn (gen_rtx_SET (VOIDmode,
4697a36c 4605 pc_rtx,
39403d82 4606 gen_rtx_IF_THEN_ELSE (VOIDmode,
4cc833b7
RH
4607 gen_rtx_NE (VOIDmode, cr1,
4608 const0_rtx),
39403d82 4609 gen_rtx_LABEL_REF (VOIDmode, lab),
4697a36c
MM
4610 pc_rtx)));
4611
4cc833b7
RH
4612 while (fregno <= FP_ARG_V4_MAX_REG)
4613 {
dfafc897 4614 mem = gen_rtx_MEM (DFmode, plus_constant (save_area, off));
ba4828e0 4615 set_mem_alias_set (mem, set);
dfafc897 4616 emit_move_insn (mem, gen_rtx_REG (DFmode, fregno));
4cc833b7
RH
4617 fregno++;
4618 off += 8;
4697a36c 4619 }
4cc833b7
RH
4620
4621 emit_label (lab);
4697a36c 4622 }
4697a36c 4623}
4697a36c 4624
dfafc897 4625/* Create the va_list data type. */
2c4974b7 4626
c35d187f
RH
4627static tree
4628rs6000_build_builtin_va_list (void)
dfafc897 4629{
64c2816f 4630 tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
4697a36c 4631
9ebbca7d
GK
4632 /* For AIX, prefer 'char *' because that's what the system
4633 header files like. */
f607bc57 4634 if (DEFAULT_ABI != ABI_V4)
9ebbca7d 4635 return build_pointer_type (char_type_node);
dfafc897 4636
f1e639b1 4637 record = (*lang_hooks.types.make_type) (RECORD_TYPE);
bab45a51 4638 type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
0f4fd75d 4639
9ebbca7d
GK
4640 f_gpr = build_decl (FIELD_DECL, get_identifier ("gpr"),
4641 unsigned_char_type_node);
4642 f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"),
4643 unsigned_char_type_node);
64c2816f
DT
4644 /* Give the two bytes of padding a name, so that -Wpadded won't warn on
4645 every user file. */
4646 f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
4647 short_unsigned_type_node);
dfafc897
FS
4648 f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
4649 ptr_type_node);
4650 f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
4651 ptr_type_node);
4652
4653 DECL_FIELD_CONTEXT (f_gpr) = record;
4654 DECL_FIELD_CONTEXT (f_fpr) = record;
64c2816f 4655 DECL_FIELD_CONTEXT (f_res) = record;
dfafc897
FS
4656 DECL_FIELD_CONTEXT (f_ovf) = record;
4657 DECL_FIELD_CONTEXT (f_sav) = record;
4658
bab45a51
FS
4659 TREE_CHAIN (record) = type_decl;
4660 TYPE_NAME (record) = type_decl;
dfafc897
FS
4661 TYPE_FIELDS (record) = f_gpr;
4662 TREE_CHAIN (f_gpr) = f_fpr;
64c2816f
DT
4663 TREE_CHAIN (f_fpr) = f_res;
4664 TREE_CHAIN (f_res) = f_ovf;
dfafc897
FS
4665 TREE_CHAIN (f_ovf) = f_sav;
4666
4667 layout_type (record);
4668
4669 /* The correct type is an array type of one element. */
4670 return build_array_type (record, build_index_type (size_zero_node));
4671}
4672
4673/* Implement va_start. */
4674
4675void
a2369ed3 4676rs6000_va_start (tree valist, rtx nextarg)
4697a36c 4677{
dfafc897 4678 HOST_WIDE_INT words, n_gpr, n_fpr;
c566f9bd 4679 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897 4680 tree gpr, fpr, ovf, sav, t;
2c4974b7 4681
dfafc897 4682 /* Only SVR4 needs something special. */
f607bc57 4683 if (DEFAULT_ABI != ABI_V4)
dfafc897 4684 {
e5faf155 4685 std_expand_builtin_va_start (valist, nextarg);
dfafc897
FS
4686 return;
4687 }
4688
973a648b 4689 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4690 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4691 f_res = TREE_CHAIN (f_fpr);
4692 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4693 f_sav = TREE_CHAIN (f_ovf);
4694
8ebecc3b 4695 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4696 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4697 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4698 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4699 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4700
4701 /* Count number of gp and fp argument registers used. */
4cc833b7 4702 words = current_function_args_info.words;
dfafc897
FS
4703 n_gpr = current_function_args_info.sysv_gregno - GP_ARG_MIN_REG;
4704 n_fpr = current_function_args_info.fregno - FP_ARG_MIN_REG;
4705
4706 if (TARGET_DEBUG_ARG)
4a0a75dd
KG
4707 fprintf (stderr, "va_start: words = "HOST_WIDE_INT_PRINT_DEC", n_gpr = "
4708 HOST_WIDE_INT_PRINT_DEC", n_fpr = "HOST_WIDE_INT_PRINT_DEC"\n",
4709 words, n_gpr, n_fpr);
dfafc897
FS
4710
4711 t = build (MODIFY_EXPR, TREE_TYPE (gpr), gpr, build_int_2 (n_gpr, 0));
4712 TREE_SIDE_EFFECTS (t) = 1;
4713 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4714
4715 t = build (MODIFY_EXPR, TREE_TYPE (fpr), fpr, build_int_2 (n_fpr, 0));
4716 TREE_SIDE_EFFECTS (t) = 1;
4717 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4718
4719 /* Find the overflow area. */
4720 t = make_tree (TREE_TYPE (ovf), virtual_incoming_args_rtx);
4721 if (words != 0)
4722 t = build (PLUS_EXPR, TREE_TYPE (ovf), t,
4723 build_int_2 (words * UNITS_PER_WORD, 0));
4724 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4725 TREE_SIDE_EFFECTS (t) = 1;
4726 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4727
4728 /* Find the register save area. */
4729 t = make_tree (TREE_TYPE (sav), virtual_stack_vars_rtx);
4730 t = build (PLUS_EXPR, TREE_TYPE (sav), t,
4731 build_int_2 (-RS6000_VARARGS_SIZE, -1));
4732 t = build (MODIFY_EXPR, TREE_TYPE (sav), sav, t);
4733 TREE_SIDE_EFFECTS (t) = 1;
4734 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4735}
4736
4737/* Implement va_arg. */
4738
4739rtx
a2369ed3 4740rs6000_va_arg (tree valist, tree type)
dfafc897 4741{
c566f9bd 4742 tree f_gpr, f_fpr, f_res, f_ovf, f_sav;
dfafc897
FS
4743 tree gpr, fpr, ovf, sav, reg, t, u;
4744 int indirect_p, size, rsize, n_reg, sav_ofs, sav_scale;
4745 rtx lab_false, lab_over, addr_rtx, r;
4746
f607bc57 4747 if (DEFAULT_ABI != ABI_V4)
c8c99a68
DE
4748 {
4749 /* Variable sized types are passed by reference. */
fff2cb99 4750 if (int_size_in_bytes (type) < 0)
c8c99a68
DE
4751 {
4752 u = build_pointer_type (type);
4753
4754 /* Args grow upward. */
4755 t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist,
4756 build_int_2 (POINTER_SIZE / BITS_PER_UNIT, 0));
4757 TREE_SIDE_EFFECTS (t) = 1;
4758
4759 t = build1 (NOP_EXPR, build_pointer_type (u), t);
4760 TREE_SIDE_EFFECTS (t) = 1;
4761
4762 t = build1 (INDIRECT_REF, u, t);
4763 TREE_SIDE_EFFECTS (t) = 1;
4764
4765 return expand_expr (t, NULL_RTX, VOIDmode, EXPAND_NORMAL);
4766 }
4767 else
b0fadda7 4768 return std_expand_builtin_va_arg (valist, type);
c8c99a68 4769 }
dfafc897 4770
973a648b 4771 f_gpr = TYPE_FIELDS (TREE_TYPE (va_list_type_node));
dfafc897 4772 f_fpr = TREE_CHAIN (f_gpr);
c566f9bd
DT
4773 f_res = TREE_CHAIN (f_fpr);
4774 f_ovf = TREE_CHAIN (f_res);
dfafc897
FS
4775 f_sav = TREE_CHAIN (f_ovf);
4776
8ebecc3b 4777 valist = build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (valist)), valist);
dfafc897
FS
4778 gpr = build (COMPONENT_REF, TREE_TYPE (f_gpr), valist, f_gpr);
4779 fpr = build (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr);
4780 ovf = build (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf);
4781 sav = build (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav);
4782
4783 size = int_size_in_bytes (type);
4784 rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
4cc833b7 4785
dfafc897 4786 if (AGGREGATE_TYPE_P (type) || TYPE_MODE (type) == TFmode)
4cc833b7 4787 {
dfafc897
FS
4788 /* Aggregates and long doubles are passed by reference. */
4789 indirect_p = 1;
4790 reg = gpr;
4791 n_reg = 1;
4792 sav_ofs = 0;
4793 sav_scale = 4;
d3294cd9
FS
4794 size = UNITS_PER_WORD;
4795 rsize = 1;
dfafc897 4796 }
a3170dc6 4797 else if (FLOAT_TYPE_P (type) && TARGET_HARD_FLOAT && TARGET_FPRS)
dfafc897
FS
4798 {
4799 /* FP args go in FP registers, if present. */
4800 indirect_p = 0;
4801 reg = fpr;
4802 n_reg = 1;
4803 sav_ofs = 8*4;
4804 sav_scale = 8;
4cc833b7 4805 }
dfafc897
FS
4806 else
4807 {
4808 /* Otherwise into GP registers. */
4809 indirect_p = 0;
4810 reg = gpr;
4811 n_reg = rsize;
4812 sav_ofs = 0;
4813 sav_scale = 4;
4814 }
4815
a3c9585f 4816 /* Pull the value out of the saved registers.... */
dfafc897
FS
4817
4818 lab_false = gen_label_rtx ();
4819 lab_over = gen_label_rtx ();
4820 addr_rtx = gen_reg_rtx (Pmode);
4821
16861f33
AH
4822 /* AltiVec vectors never go in registers. */
4823 if (!TARGET_ALTIVEC || TREE_CODE (type) != VECTOR_TYPE)
2c4974b7 4824 {
41daaf0e
AH
4825 TREE_THIS_VOLATILE (reg) = 1;
4826 emit_cmp_and_jump_insns
4827 (expand_expr (reg, NULL_RTX, QImode, EXPAND_NORMAL),
4828 GEN_INT (8 - n_reg + 1), GE, const1_rtx, QImode, 1,
4829 lab_false);
dfafc897 4830
41daaf0e
AH
4831 /* Long long is aligned in the registers. */
4832 if (n_reg > 1)
4833 {
4834 u = build (BIT_AND_EXPR, TREE_TYPE (reg), reg,
4835 build_int_2 (n_reg - 1, 0));
4836 u = build (PLUS_EXPR, TREE_TYPE (reg), reg, u);
4837 u = build (MODIFY_EXPR, TREE_TYPE (reg), reg, u);
4838 TREE_SIDE_EFFECTS (u) = 1;
4839 expand_expr (u, const0_rtx, VOIDmode, EXPAND_NORMAL);
4840 }
2c4974b7 4841
41daaf0e
AH
4842 if (sav_ofs)
4843 t = build (PLUS_EXPR, ptr_type_node, sav, build_int_2 (sav_ofs, 0));
4844 else
4845 t = sav;
2c4974b7 4846
41daaf0e
AH
4847 u = build (POSTINCREMENT_EXPR, TREE_TYPE (reg), reg,
4848 build_int_2 (n_reg, 0));
4849 TREE_SIDE_EFFECTS (u) = 1;
2c4974b7 4850
41daaf0e
AH
4851 u = build1 (CONVERT_EXPR, integer_type_node, u);
4852 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4853
41daaf0e
AH
4854 u = build (MULT_EXPR, integer_type_node, u, build_int_2 (sav_scale, 0));
4855 TREE_SIDE_EFFECTS (u) = 1;
dfafc897 4856
41daaf0e
AH
4857 t = build (PLUS_EXPR, ptr_type_node, t, u);
4858 TREE_SIDE_EFFECTS (t) = 1;
4859
4860 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4861 if (r != addr_rtx)
4862 emit_move_insn (addr_rtx, r);
4863
4864 emit_jump_insn (gen_jump (lab_over));
4865 emit_barrier ();
4866 }
dfafc897 4867
dfafc897
FS
4868 emit_label (lab_false);
4869
a4f6c312 4870 /* ... otherwise out of the overflow area. */
dfafc897 4871
41daaf0e
AH
4872 /* Make sure we don't find reg 7 for the next int arg.
4873
4874 All AltiVec vectors go in the overflow area. So in the AltiVec
4875 case we need to get the vectors from the overflow area, but
4876 remember where the GPRs and FPRs are. */
16861f33
AH
4877 if (n_reg > 1 && (TREE_CODE (type) != VECTOR_TYPE
4878 || !TARGET_ALTIVEC))
dfafc897
FS
4879 {
4880 t = build (MODIFY_EXPR, TREE_TYPE (reg), reg, build_int_2 (8, 0));
4881 TREE_SIDE_EFFECTS (t) = 1;
4882 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4883 }
4884
4885 /* Care for on-stack alignment if needed. */
4886 if (rsize <= 1)
4887 t = ovf;
4888 else
4889 {
41daaf0e
AH
4890 int align;
4891
16861f33
AH
4892 /* AltiVec vectors are 16 byte aligned. */
4893 if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE)
41daaf0e
AH
4894 align = 15;
4895 else
4896 align = 7;
4897
4898 t = build (PLUS_EXPR, TREE_TYPE (ovf), ovf, build_int_2 (align, 0));
4899 t = build (BIT_AND_EXPR, TREE_TYPE (t), t, build_int_2 (-align-1, -1));
dfafc897
FS
4900 }
4901 t = save_expr (t);
4902
4903 r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
4904 if (r != addr_rtx)
4905 emit_move_insn (addr_rtx, r);
4906
4907 t = build (PLUS_EXPR, TREE_TYPE (t), t, build_int_2 (size, 0));
4908 t = build (MODIFY_EXPR, TREE_TYPE (ovf), ovf, t);
4909 TREE_SIDE_EFFECTS (t) = 1;
4910 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
4911
4912 emit_label (lab_over);
4913
4914 if (indirect_p)
4915 {
4916 r = gen_rtx_MEM (Pmode, addr_rtx);
ba4828e0 4917 set_mem_alias_set (r, get_varargs_alias_set ());
dfafc897
FS
4918 emit_move_insn (addr_rtx, r);
4919 }
4920
4921 return addr_rtx;
4697a36c 4922}
0ac081f6
AH
4923
4924/* Builtins. */
4925
6a2dd09a
RS
4926#define def_builtin(MASK, NAME, TYPE, CODE) \
4927do { \
4928 if ((MASK) & target_flags) \
4929 builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, \
4930 NULL, NULL_TREE); \
0ac081f6
AH
4931} while (0)
4932
24408032
AH
4933/* Simple ternary operations: VECd = foo (VECa, VECb, VECc). */
4934
2212663f 4935static const struct builtin_description bdesc_3arg[] =
24408032
AH
4936{
4937 { MASK_ALTIVEC, CODE_FOR_altivec_vmaddfp, "__builtin_altivec_vmaddfp", ALTIVEC_BUILTIN_VMADDFP },
4938 { MASK_ALTIVEC, CODE_FOR_altivec_vmhaddshs, "__builtin_altivec_vmhaddshs", ALTIVEC_BUILTIN_VMHADDSHS },
4939 { MASK_ALTIVEC, CODE_FOR_altivec_vmhraddshs, "__builtin_altivec_vmhraddshs", ALTIVEC_BUILTIN_VMHRADDSHS },
4940 { MASK_ALTIVEC, CODE_FOR_altivec_vmladduhm, "__builtin_altivec_vmladduhm", ALTIVEC_BUILTIN_VMLADDUHM},
4941 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumubm, "__builtin_altivec_vmsumubm", ALTIVEC_BUILTIN_VMSUMUBM },
4942 { MASK_ALTIVEC, CODE_FOR_altivec_vmsummbm, "__builtin_altivec_vmsummbm", ALTIVEC_BUILTIN_VMSUMMBM },
4943 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhm, "__builtin_altivec_vmsumuhm", ALTIVEC_BUILTIN_VMSUMUHM },
4944 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshm, "__builtin_altivec_vmsumshm", ALTIVEC_BUILTIN_VMSUMSHM },
4945 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumuhs, "__builtin_altivec_vmsumuhs", ALTIVEC_BUILTIN_VMSUMUHS },
4946 { MASK_ALTIVEC, CODE_FOR_altivec_vmsumshs, "__builtin_altivec_vmsumshs", ALTIVEC_BUILTIN_VMSUMSHS },
4947 { MASK_ALTIVEC, CODE_FOR_altivec_vnmsubfp, "__builtin_altivec_vnmsubfp", ALTIVEC_BUILTIN_VNMSUBFP },
4948 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4sf, "__builtin_altivec_vperm_4sf", ALTIVEC_BUILTIN_VPERM_4SF },
4949 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_4si, "__builtin_altivec_vperm_4si", ALTIVEC_BUILTIN_VPERM_4SI },
4950 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_8hi, "__builtin_altivec_vperm_8hi", ALTIVEC_BUILTIN_VPERM_8HI },
4951 { MASK_ALTIVEC, CODE_FOR_altivec_vperm_16qi, "__builtin_altivec_vperm_16qi", ALTIVEC_BUILTIN_VPERM_16QI },
4952 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4sf, "__builtin_altivec_vsel_4sf", ALTIVEC_BUILTIN_VSEL_4SF },
4953 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_4si, "__builtin_altivec_vsel_4si", ALTIVEC_BUILTIN_VSEL_4SI },
4954 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_8hi, "__builtin_altivec_vsel_8hi", ALTIVEC_BUILTIN_VSEL_8HI },
4955 { MASK_ALTIVEC, CODE_FOR_altivec_vsel_16qi, "__builtin_altivec_vsel_16qi", ALTIVEC_BUILTIN_VSEL_16QI },
4956 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_16qi, "__builtin_altivec_vsldoi_16qi", ALTIVEC_BUILTIN_VSLDOI_16QI },
4957 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_8hi, "__builtin_altivec_vsldoi_8hi", ALTIVEC_BUILTIN_VSLDOI_8HI },
4958 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4si, "__builtin_altivec_vsldoi_4si", ALTIVEC_BUILTIN_VSLDOI_4SI },
4959 { MASK_ALTIVEC, CODE_FOR_altivec_vsldoi_4sf, "__builtin_altivec_vsldoi_4sf", ALTIVEC_BUILTIN_VSLDOI_4SF },
4960};
2212663f 4961
95385cbb
AH
4962/* DST operations: void foo (void *, const int, const char). */
4963
4964static const struct builtin_description bdesc_dst[] =
4965{
4966 { MASK_ALTIVEC, CODE_FOR_altivec_dst, "__builtin_altivec_dst", ALTIVEC_BUILTIN_DST },
4967 { MASK_ALTIVEC, CODE_FOR_altivec_dstt, "__builtin_altivec_dstt", ALTIVEC_BUILTIN_DSTT },
4968 { MASK_ALTIVEC, CODE_FOR_altivec_dstst, "__builtin_altivec_dstst", ALTIVEC_BUILTIN_DSTST },
4969 { MASK_ALTIVEC, CODE_FOR_altivec_dststt, "__builtin_altivec_dststt", ALTIVEC_BUILTIN_DSTSTT }
4970};
4971
2212663f 4972/* Simple binary operations: VECc = foo (VECa, VECb). */
24408032 4973
a3170dc6 4974static struct builtin_description bdesc_2arg[] =
0ac081f6 4975{
f18c054f
DB
4976 { MASK_ALTIVEC, CODE_FOR_addv16qi3, "__builtin_altivec_vaddubm", ALTIVEC_BUILTIN_VADDUBM },
4977 { MASK_ALTIVEC, CODE_FOR_addv8hi3, "__builtin_altivec_vadduhm", ALTIVEC_BUILTIN_VADDUHM },
4978 { MASK_ALTIVEC, CODE_FOR_addv4si3, "__builtin_altivec_vadduwm", ALTIVEC_BUILTIN_VADDUWM },
4979 { MASK_ALTIVEC, CODE_FOR_addv4sf3, "__builtin_altivec_vaddfp", ALTIVEC_BUILTIN_VADDFP },
0ac081f6
AH
4980 { MASK_ALTIVEC, CODE_FOR_altivec_vaddcuw, "__builtin_altivec_vaddcuw", ALTIVEC_BUILTIN_VADDCUW },
4981 { MASK_ALTIVEC, CODE_FOR_altivec_vaddubs, "__builtin_altivec_vaddubs", ALTIVEC_BUILTIN_VADDUBS },
4982 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsbs, "__builtin_altivec_vaddsbs", ALTIVEC_BUILTIN_VADDSBS },
4983 { MASK_ALTIVEC, CODE_FOR_altivec_vadduhs, "__builtin_altivec_vadduhs", ALTIVEC_BUILTIN_VADDUHS },
4984 { MASK_ALTIVEC, CODE_FOR_altivec_vaddshs, "__builtin_altivec_vaddshs", ALTIVEC_BUILTIN_VADDSHS },
4985 { MASK_ALTIVEC, CODE_FOR_altivec_vadduws, "__builtin_altivec_vadduws", ALTIVEC_BUILTIN_VADDUWS },
4986 { MASK_ALTIVEC, CODE_FOR_altivec_vaddsws, "__builtin_altivec_vaddsws", ALTIVEC_BUILTIN_VADDSWS },
f18c054f 4987 { MASK_ALTIVEC, CODE_FOR_andv4si3, "__builtin_altivec_vand", ALTIVEC_BUILTIN_VAND },
0ac081f6
AH
4988 { MASK_ALTIVEC, CODE_FOR_altivec_vandc, "__builtin_altivec_vandc", ALTIVEC_BUILTIN_VANDC },
4989 { MASK_ALTIVEC, CODE_FOR_altivec_vavgub, "__builtin_altivec_vavgub", ALTIVEC_BUILTIN_VAVGUB },
4990 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsb, "__builtin_altivec_vavgsb", ALTIVEC_BUILTIN_VAVGSB },
4991 { MASK_ALTIVEC, CODE_FOR_altivec_vavguh, "__builtin_altivec_vavguh", ALTIVEC_BUILTIN_VAVGUH },
4992 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsh, "__builtin_altivec_vavgsh", ALTIVEC_BUILTIN_VAVGSH },
4993 { MASK_ALTIVEC, CODE_FOR_altivec_vavguw, "__builtin_altivec_vavguw", ALTIVEC_BUILTIN_VAVGUW },
4994 { MASK_ALTIVEC, CODE_FOR_altivec_vavgsw, "__builtin_altivec_vavgsw", ALTIVEC_BUILTIN_VAVGSW },
617e0e1d
DB
4995 { MASK_ALTIVEC, CODE_FOR_altivec_vcfux, "__builtin_altivec_vcfux", ALTIVEC_BUILTIN_VCFUX },
4996 { MASK_ALTIVEC, CODE_FOR_altivec_vcfsx, "__builtin_altivec_vcfsx", ALTIVEC_BUILTIN_VCFSX },
0ac081f6
AH
4997 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpbfp, "__builtin_altivec_vcmpbfp", ALTIVEC_BUILTIN_VCMPBFP },
4998 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequb, "__builtin_altivec_vcmpequb", ALTIVEC_BUILTIN_VCMPEQUB },
4999 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequh, "__builtin_altivec_vcmpequh", ALTIVEC_BUILTIN_VCMPEQUH },
5000 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpequw, "__builtin_altivec_vcmpequw", ALTIVEC_BUILTIN_VCMPEQUW },
5001 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpeqfp, "__builtin_altivec_vcmpeqfp", ALTIVEC_BUILTIN_VCMPEQFP },
5002 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgefp, "__builtin_altivec_vcmpgefp", ALTIVEC_BUILTIN_VCMPGEFP },
5003 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtub, "__builtin_altivec_vcmpgtub", ALTIVEC_BUILTIN_VCMPGTUB },
5004 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsb, "__builtin_altivec_vcmpgtsb", ALTIVEC_BUILTIN_VCMPGTSB },
5005 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuh, "__builtin_altivec_vcmpgtuh", ALTIVEC_BUILTIN_VCMPGTUH },
5006 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsh, "__builtin_altivec_vcmpgtsh", ALTIVEC_BUILTIN_VCMPGTSH },
5007 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtuw, "__builtin_altivec_vcmpgtuw", ALTIVEC_BUILTIN_VCMPGTUW },
5008 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtsw, "__builtin_altivec_vcmpgtsw", ALTIVEC_BUILTIN_VCMPGTSW },
5009 { MASK_ALTIVEC, CODE_FOR_altivec_vcmpgtfp, "__builtin_altivec_vcmpgtfp", ALTIVEC_BUILTIN_VCMPGTFP },
617e0e1d
DB
5010 { MASK_ALTIVEC, CODE_FOR_altivec_vctsxs, "__builtin_altivec_vctsxs", ALTIVEC_BUILTIN_VCTSXS },
5011 { MASK_ALTIVEC, CODE_FOR_altivec_vctuxs, "__builtin_altivec_vctuxs", ALTIVEC_BUILTIN_VCTUXS },
f18c054f
DB
5012 { MASK_ALTIVEC, CODE_FOR_umaxv16qi3, "__builtin_altivec_vmaxub", ALTIVEC_BUILTIN_VMAXUB },
5013 { MASK_ALTIVEC, CODE_FOR_smaxv16qi3, "__builtin_altivec_vmaxsb", ALTIVEC_BUILTIN_VMAXSB },
df966bff
AH
5014 { MASK_ALTIVEC, CODE_FOR_umaxv8hi3, "__builtin_altivec_vmaxuh", ALTIVEC_BUILTIN_VMAXUH },
5015 { MASK_ALTIVEC, CODE_FOR_smaxv8hi3, "__builtin_altivec_vmaxsh", ALTIVEC_BUILTIN_VMAXSH },
5016 { MASK_ALTIVEC, CODE_FOR_umaxv4si3, "__builtin_altivec_vmaxuw", ALTIVEC_BUILTIN_VMAXUW },
5017 { MASK_ALTIVEC, CODE_FOR_smaxv4si3, "__builtin_altivec_vmaxsw", ALTIVEC_BUILTIN_VMAXSW },
5018 { MASK_ALTIVEC, CODE_FOR_smaxv4sf3, "__builtin_altivec_vmaxfp", ALTIVEC_BUILTIN_VMAXFP },
0ac081f6
AH
5019 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghb, "__builtin_altivec_vmrghb", ALTIVEC_BUILTIN_VMRGHB },
5020 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghh, "__builtin_altivec_vmrghh", ALTIVEC_BUILTIN_VMRGHH },
5021 { MASK_ALTIVEC, CODE_FOR_altivec_vmrghw, "__builtin_altivec_vmrghw", ALTIVEC_BUILTIN_VMRGHW },
5022 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglb, "__builtin_altivec_vmrglb", ALTIVEC_BUILTIN_VMRGLB },
5023 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglh, "__builtin_altivec_vmrglh", ALTIVEC_BUILTIN_VMRGLH },
5024 { MASK_ALTIVEC, CODE_FOR_altivec_vmrglw, "__builtin_altivec_vmrglw", ALTIVEC_BUILTIN_VMRGLW },
f18c054f
DB
5025 { MASK_ALTIVEC, CODE_FOR_uminv16qi3, "__builtin_altivec_vminub", ALTIVEC_BUILTIN_VMINUB },
5026 { MASK_ALTIVEC, CODE_FOR_sminv16qi3, "__builtin_altivec_vminsb", ALTIVEC_BUILTIN_VMINSB },
5027 { MASK_ALTIVEC, CODE_FOR_uminv8hi3, "__builtin_altivec_vminuh", ALTIVEC_BUILTIN_VMINUH },
5028 { MASK_ALTIVEC, CODE_FOR_sminv8hi3, "__builtin_altivec_vminsh", ALTIVEC_BUILTIN_VMINSH },
5029 { MASK_ALTIVEC, CODE_FOR_uminv4si3, "__builtin_altivec_vminuw", ALTIVEC_BUILTIN_VMINUW },
5030 { MASK_ALTIVEC, CODE_FOR_sminv4si3, "__builtin_altivec_vminsw", ALTIVEC_BUILTIN_VMINSW },
5031 { MASK_ALTIVEC, CODE_FOR_sminv4sf3, "__builtin_altivec_vminfp", ALTIVEC_BUILTIN_VMINFP },
0ac081f6
AH
5032 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleub, "__builtin_altivec_vmuleub", ALTIVEC_BUILTIN_VMULEUB },
5033 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesb, "__builtin_altivec_vmulesb", ALTIVEC_BUILTIN_VMULESB },
5034 { MASK_ALTIVEC, CODE_FOR_altivec_vmuleuh, "__builtin_altivec_vmuleuh", ALTIVEC_BUILTIN_VMULEUH },
5035 { MASK_ALTIVEC, CODE_FOR_altivec_vmulesh, "__builtin_altivec_vmulesh", ALTIVEC_BUILTIN_VMULESH },
5036 { MASK_ALTIVEC, CODE_FOR_altivec_vmuloub, "__builtin_altivec_vmuloub", ALTIVEC_BUILTIN_VMULOUB },
5037 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosb, "__builtin_altivec_vmulosb", ALTIVEC_BUILTIN_VMULOSB },
5038 { MASK_ALTIVEC, CODE_FOR_altivec_vmulouh, "__builtin_altivec_vmulouh", ALTIVEC_BUILTIN_VMULOUH },
5039 { MASK_ALTIVEC, CODE_FOR_altivec_vmulosh, "__builtin_altivec_vmulosh", ALTIVEC_BUILTIN_VMULOSH },
5040 { MASK_ALTIVEC, CODE_FOR_altivec_vnor, "__builtin_altivec_vnor", ALTIVEC_BUILTIN_VNOR },
f18c054f 5041 { MASK_ALTIVEC, CODE_FOR_iorv4si3, "__builtin_altivec_vor", ALTIVEC_BUILTIN_VOR },
0ac081f6
AH
5042 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhum, "__builtin_altivec_vpkuhum", ALTIVEC_BUILTIN_VPKUHUM },
5043 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwum, "__builtin_altivec_vpkuwum", ALTIVEC_BUILTIN_VPKUWUM },
5044 { MASK_ALTIVEC, CODE_FOR_altivec_vpkpx, "__builtin_altivec_vpkpx", ALTIVEC_BUILTIN_VPKPX },
5045 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhss, "__builtin_altivec_vpkuhss", ALTIVEC_BUILTIN_VPKUHSS },
5046 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshss, "__builtin_altivec_vpkshss", ALTIVEC_BUILTIN_VPKSHSS },
5047 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwss, "__builtin_altivec_vpkuwss", ALTIVEC_BUILTIN_VPKUWSS },
5048 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswss, "__builtin_altivec_vpkswss", ALTIVEC_BUILTIN_VPKSWSS },
5049 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuhus, "__builtin_altivec_vpkuhus", ALTIVEC_BUILTIN_VPKUHUS },
5050 { MASK_ALTIVEC, CODE_FOR_altivec_vpkshus, "__builtin_altivec_vpkshus", ALTIVEC_BUILTIN_VPKSHUS },
5051 { MASK_ALTIVEC, CODE_FOR_altivec_vpkuwus, "__builtin_altivec_vpkuwus", ALTIVEC_BUILTIN_VPKUWUS },
5052 { MASK_ALTIVEC, CODE_FOR_altivec_vpkswus, "__builtin_altivec_vpkswus", ALTIVEC_BUILTIN_VPKSWUS },
5053 { MASK_ALTIVEC, CODE_FOR_altivec_vrlb, "__builtin_altivec_vrlb", ALTIVEC_BUILTIN_VRLB },
5054 { MASK_ALTIVEC, CODE_FOR_altivec_vrlh, "__builtin_altivec_vrlh", ALTIVEC_BUILTIN_VRLH },
5055 { MASK_ALTIVEC, CODE_FOR_altivec_vrlw, "__builtin_altivec_vrlw", ALTIVEC_BUILTIN_VRLW },
5056 { MASK_ALTIVEC, CODE_FOR_altivec_vslb, "__builtin_altivec_vslb", ALTIVEC_BUILTIN_VSLB },
5057 { MASK_ALTIVEC, CODE_FOR_altivec_vslh, "__builtin_altivec_vslh", ALTIVEC_BUILTIN_VSLH },
5058 { MASK_ALTIVEC, CODE_FOR_altivec_vslw, "__builtin_altivec_vslw", ALTIVEC_BUILTIN_VSLW },
5059 { MASK_ALTIVEC, CODE_FOR_altivec_vsl, "__builtin_altivec_vsl", ALTIVEC_BUILTIN_VSL },
5060 { MASK_ALTIVEC, CODE_FOR_altivec_vslo, "__builtin_altivec_vslo", ALTIVEC_BUILTIN_VSLO },
2212663f
DB
5061 { MASK_ALTIVEC, CODE_FOR_altivec_vspltb, "__builtin_altivec_vspltb", ALTIVEC_BUILTIN_VSPLTB },
5062 { MASK_ALTIVEC, CODE_FOR_altivec_vsplth, "__builtin_altivec_vsplth", ALTIVEC_BUILTIN_VSPLTH },
5063 { MASK_ALTIVEC, CODE_FOR_altivec_vspltw, "__builtin_altivec_vspltw", ALTIVEC_BUILTIN_VSPLTW },
0ac081f6 5064 { MASK_ALTIVEC, CODE_FOR_altivec_vsrb, "__builtin_altivec_vsrb", ALTIVEC_BUILTIN_VSRB },
f18c054f
DB
5065 { MASK_ALTIVEC, CODE_FOR_altivec_vsrh, "__builtin_altivec_vsrh", ALTIVEC_BUILTIN_VSRH },
5066 { MASK_ALTIVEC, CODE_FOR_altivec_vsrw, "__builtin_altivec_vsrw", ALTIVEC_BUILTIN_VSRW },
0ac081f6
AH
5067 { MASK_ALTIVEC, CODE_FOR_altivec_vsrab, "__builtin_altivec_vsrab", ALTIVEC_BUILTIN_VSRAB },
5068 { MASK_ALTIVEC, CODE_FOR_altivec_vsrah, "__builtin_altivec_vsrah", ALTIVEC_BUILTIN_VSRAH },
5069 { MASK_ALTIVEC, CODE_FOR_altivec_vsraw, "__builtin_altivec_vsraw", ALTIVEC_BUILTIN_VSRAW },
5070 { MASK_ALTIVEC, CODE_FOR_altivec_vsr, "__builtin_altivec_vsr", ALTIVEC_BUILTIN_VSR },
5071 { MASK_ALTIVEC, CODE_FOR_altivec_vsro, "__builtin_altivec_vsro", ALTIVEC_BUILTIN_VSRO },
f18c054f
DB
5072 { MASK_ALTIVEC, CODE_FOR_subv16qi3, "__builtin_altivec_vsububm", ALTIVEC_BUILTIN_VSUBUBM },
5073 { MASK_ALTIVEC, CODE_FOR_subv8hi3, "__builtin_altivec_vsubuhm", ALTIVEC_BUILTIN_VSUBUHM },
5074 { MASK_ALTIVEC, CODE_FOR_subv4si3, "__builtin_altivec_vsubuwm", ALTIVEC_BUILTIN_VSUBUWM },
5075 { MASK_ALTIVEC, CODE_FOR_subv4sf3, "__builtin_altivec_vsubfp", ALTIVEC_BUILTIN_VSUBFP },
0ac081f6
AH
5076 { MASK_ALTIVEC, CODE_FOR_altivec_vsubcuw, "__builtin_altivec_vsubcuw", ALTIVEC_BUILTIN_VSUBCUW },
5077 { MASK_ALTIVEC, CODE_FOR_altivec_vsububs, "__builtin_altivec_vsububs", ALTIVEC_BUILTIN_VSUBUBS },
5078 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsbs, "__builtin_altivec_vsubsbs", ALTIVEC_BUILTIN_VSUBSBS },
5079 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuhs, "__builtin_altivec_vsubuhs", ALTIVEC_BUILTIN_VSUBUHS },
5080 { MASK_ALTIVEC, CODE_FOR_altivec_vsubshs, "__builtin_altivec_vsubshs", ALTIVEC_BUILTIN_VSUBSHS },
5081 { MASK_ALTIVEC, CODE_FOR_altivec_vsubuws, "__builtin_altivec_vsubuws", ALTIVEC_BUILTIN_VSUBUWS },
5082 { MASK_ALTIVEC, CODE_FOR_altivec_vsubsws, "__builtin_altivec_vsubsws", ALTIVEC_BUILTIN_VSUBSWS },
5083 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4ubs, "__builtin_altivec_vsum4ubs", ALTIVEC_BUILTIN_VSUM4UBS },
5084 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4sbs, "__builtin_altivec_vsum4sbs", ALTIVEC_BUILTIN_VSUM4SBS },
5085 { MASK_ALTIVEC, CODE_FOR_altivec_vsum4shs, "__builtin_altivec_vsum4shs", ALTIVEC_BUILTIN_VSUM4SHS },
5086 { MASK_ALTIVEC, CODE_FOR_altivec_vsum2sws, "__builtin_altivec_vsum2sws", ALTIVEC_BUILTIN_VSUM2SWS },
5087 { MASK_ALTIVEC, CODE_FOR_altivec_vsumsws, "__builtin_altivec_vsumsws", ALTIVEC_BUILTIN_VSUMSWS },
f18c054f 5088 { MASK_ALTIVEC, CODE_FOR_xorv4si3, "__builtin_altivec_vxor", ALTIVEC_BUILTIN_VXOR },
a3170dc6
AH
5089
5090 /* Place holder, leave as first spe builtin. */
5091 { 0, CODE_FOR_spe_evaddw, "__builtin_spe_evaddw", SPE_BUILTIN_EVADDW },
5092 { 0, CODE_FOR_spe_evand, "__builtin_spe_evand", SPE_BUILTIN_EVAND },
5093 { 0, CODE_FOR_spe_evandc, "__builtin_spe_evandc", SPE_BUILTIN_EVANDC },
5094 { 0, CODE_FOR_spe_evdivws, "__builtin_spe_evdivws", SPE_BUILTIN_EVDIVWS },
5095 { 0, CODE_FOR_spe_evdivwu, "__builtin_spe_evdivwu", SPE_BUILTIN_EVDIVWU },
5096 { 0, CODE_FOR_spe_eveqv, "__builtin_spe_eveqv", SPE_BUILTIN_EVEQV },
5097 { 0, CODE_FOR_spe_evfsadd, "__builtin_spe_evfsadd", SPE_BUILTIN_EVFSADD },
5098 { 0, CODE_FOR_spe_evfsdiv, "__builtin_spe_evfsdiv", SPE_BUILTIN_EVFSDIV },
5099 { 0, CODE_FOR_spe_evfsmul, "__builtin_spe_evfsmul", SPE_BUILTIN_EVFSMUL },
5100 { 0, CODE_FOR_spe_evfssub, "__builtin_spe_evfssub", SPE_BUILTIN_EVFSSUB },
5101 { 0, CODE_FOR_spe_evmergehi, "__builtin_spe_evmergehi", SPE_BUILTIN_EVMERGEHI },
5102 { 0, CODE_FOR_spe_evmergehilo, "__builtin_spe_evmergehilo", SPE_BUILTIN_EVMERGEHILO },
5103 { 0, CODE_FOR_spe_evmergelo, "__builtin_spe_evmergelo", SPE_BUILTIN_EVMERGELO },
5104 { 0, CODE_FOR_spe_evmergelohi, "__builtin_spe_evmergelohi", SPE_BUILTIN_EVMERGELOHI },
5105 { 0, CODE_FOR_spe_evmhegsmfaa, "__builtin_spe_evmhegsmfaa", SPE_BUILTIN_EVMHEGSMFAA },
5106 { 0, CODE_FOR_spe_evmhegsmfan, "__builtin_spe_evmhegsmfan", SPE_BUILTIN_EVMHEGSMFAN },
5107 { 0, CODE_FOR_spe_evmhegsmiaa, "__builtin_spe_evmhegsmiaa", SPE_BUILTIN_EVMHEGSMIAA },
5108 { 0, CODE_FOR_spe_evmhegsmian, "__builtin_spe_evmhegsmian", SPE_BUILTIN_EVMHEGSMIAN },
5109 { 0, CODE_FOR_spe_evmhegumiaa, "__builtin_spe_evmhegumiaa", SPE_BUILTIN_EVMHEGUMIAA },
5110 { 0, CODE_FOR_spe_evmhegumian, "__builtin_spe_evmhegumian", SPE_BUILTIN_EVMHEGUMIAN },
5111 { 0, CODE_FOR_spe_evmhesmf, "__builtin_spe_evmhesmf", SPE_BUILTIN_EVMHESMF },
5112 { 0, CODE_FOR_spe_evmhesmfa, "__builtin_spe_evmhesmfa", SPE_BUILTIN_EVMHESMFA },
5113 { 0, CODE_FOR_spe_evmhesmfaaw, "__builtin_spe_evmhesmfaaw", SPE_BUILTIN_EVMHESMFAAW },
5114 { 0, CODE_FOR_spe_evmhesmfanw, "__builtin_spe_evmhesmfanw", SPE_BUILTIN_EVMHESMFANW },
5115 { 0, CODE_FOR_spe_evmhesmi, "__builtin_spe_evmhesmi", SPE_BUILTIN_EVMHESMI },
5116 { 0, CODE_FOR_spe_evmhesmia, "__builtin_spe_evmhesmia", SPE_BUILTIN_EVMHESMIA },
5117 { 0, CODE_FOR_spe_evmhesmiaaw, "__builtin_spe_evmhesmiaaw", SPE_BUILTIN_EVMHESMIAAW },
5118 { 0, CODE_FOR_spe_evmhesmianw, "__builtin_spe_evmhesmianw", SPE_BUILTIN_EVMHESMIANW },
5119 { 0, CODE_FOR_spe_evmhessf, "__builtin_spe_evmhessf", SPE_BUILTIN_EVMHESSF },
5120 { 0, CODE_FOR_spe_evmhessfa, "__builtin_spe_evmhessfa", SPE_BUILTIN_EVMHESSFA },
5121 { 0, CODE_FOR_spe_evmhessfaaw, "__builtin_spe_evmhessfaaw", SPE_BUILTIN_EVMHESSFAAW },
5122 { 0, CODE_FOR_spe_evmhessfanw, "__builtin_spe_evmhessfanw", SPE_BUILTIN_EVMHESSFANW },
5123 { 0, CODE_FOR_spe_evmhessiaaw, "__builtin_spe_evmhessiaaw", SPE_BUILTIN_EVMHESSIAAW },
5124 { 0, CODE_FOR_spe_evmhessianw, "__builtin_spe_evmhessianw", SPE_BUILTIN_EVMHESSIANW },
5125 { 0, CODE_FOR_spe_evmheumi, "__builtin_spe_evmheumi", SPE_BUILTIN_EVMHEUMI },
5126 { 0, CODE_FOR_spe_evmheumia, "__builtin_spe_evmheumia", SPE_BUILTIN_EVMHEUMIA },
5127 { 0, CODE_FOR_spe_evmheumiaaw, "__builtin_spe_evmheumiaaw", SPE_BUILTIN_EVMHEUMIAAW },
5128 { 0, CODE_FOR_spe_evmheumianw, "__builtin_spe_evmheumianw", SPE_BUILTIN_EVMHEUMIANW },
5129 { 0, CODE_FOR_spe_evmheusiaaw, "__builtin_spe_evmheusiaaw", SPE_BUILTIN_EVMHEUSIAAW },
5130 { 0, CODE_FOR_spe_evmheusianw, "__builtin_spe_evmheusianw", SPE_BUILTIN_EVMHEUSIANW },
5131 { 0, CODE_FOR_spe_evmhogsmfaa, "__builtin_spe_evmhogsmfaa", SPE_BUILTIN_EVMHOGSMFAA },
5132 { 0, CODE_FOR_spe_evmhogsmfan, "__builtin_spe_evmhogsmfan", SPE_BUILTIN_EVMHOGSMFAN },
5133 { 0, CODE_FOR_spe_evmhogsmiaa, "__builtin_spe_evmhogsmiaa", SPE_BUILTIN_EVMHOGSMIAA },
5134 { 0, CODE_FOR_spe_evmhogsmian, "__builtin_spe_evmhogsmian", SPE_BUILTIN_EVMHOGSMIAN },
5135 { 0, CODE_FOR_spe_evmhogumiaa, "__builtin_spe_evmhogumiaa", SPE_BUILTIN_EVMHOGUMIAA },
5136 { 0, CODE_FOR_spe_evmhogumian, "__builtin_spe_evmhogumian", SPE_BUILTIN_EVMHOGUMIAN },
5137 { 0, CODE_FOR_spe_evmhosmf, "__builtin_spe_evmhosmf", SPE_BUILTIN_EVMHOSMF },
5138 { 0, CODE_FOR_spe_evmhosmfa, "__builtin_spe_evmhosmfa", SPE_BUILTIN_EVMHOSMFA },
5139 { 0, CODE_FOR_spe_evmhosmfaaw, "__builtin_spe_evmhosmfaaw", SPE_BUILTIN_EVMHOSMFAAW },
5140 { 0, CODE_FOR_spe_evmhosmfanw, "__builtin_spe_evmhosmfanw", SPE_BUILTIN_EVMHOSMFANW },
5141 { 0, CODE_FOR_spe_evmhosmi, "__builtin_spe_evmhosmi", SPE_BUILTIN_EVMHOSMI },
5142 { 0, CODE_FOR_spe_evmhosmia, "__builtin_spe_evmhosmia", SPE_BUILTIN_EVMHOSMIA },
5143 { 0, CODE_FOR_spe_evmhosmiaaw, "__builtin_spe_evmhosmiaaw", SPE_BUILTIN_EVMHOSMIAAW },
5144 { 0, CODE_FOR_spe_evmhosmianw, "__builtin_spe_evmhosmianw", SPE_BUILTIN_EVMHOSMIANW },
5145 { 0, CODE_FOR_spe_evmhossf, "__builtin_spe_evmhossf", SPE_BUILTIN_EVMHOSSF },
5146 { 0, CODE_FOR_spe_evmhossfa, "__builtin_spe_evmhossfa", SPE_BUILTIN_EVMHOSSFA },
5147 { 0, CODE_FOR_spe_evmhossfaaw, "__builtin_spe_evmhossfaaw", SPE_BUILTIN_EVMHOSSFAAW },
5148 { 0, CODE_FOR_spe_evmhossfanw, "__builtin_spe_evmhossfanw", SPE_BUILTIN_EVMHOSSFANW },
5149 { 0, CODE_FOR_spe_evmhossiaaw, "__builtin_spe_evmhossiaaw", SPE_BUILTIN_EVMHOSSIAAW },
5150 { 0, CODE_FOR_spe_evmhossianw, "__builtin_spe_evmhossianw", SPE_BUILTIN_EVMHOSSIANW },
5151 { 0, CODE_FOR_spe_evmhoumi, "__builtin_spe_evmhoumi", SPE_BUILTIN_EVMHOUMI },
5152 { 0, CODE_FOR_spe_evmhoumia, "__builtin_spe_evmhoumia", SPE_BUILTIN_EVMHOUMIA },
5153 { 0, CODE_FOR_spe_evmhoumiaaw, "__builtin_spe_evmhoumiaaw", SPE_BUILTIN_EVMHOUMIAAW },
5154 { 0, CODE_FOR_spe_evmhoumianw, "__builtin_spe_evmhoumianw", SPE_BUILTIN_EVMHOUMIANW },
5155 { 0, CODE_FOR_spe_evmhousiaaw, "__builtin_spe_evmhousiaaw", SPE_BUILTIN_EVMHOUSIAAW },
5156 { 0, CODE_FOR_spe_evmhousianw, "__builtin_spe_evmhousianw", SPE_BUILTIN_EVMHOUSIANW },
5157 { 0, CODE_FOR_spe_evmwhsmf, "__builtin_spe_evmwhsmf", SPE_BUILTIN_EVMWHSMF },
5158 { 0, CODE_FOR_spe_evmwhsmfa, "__builtin_spe_evmwhsmfa", SPE_BUILTIN_EVMWHSMFA },
5159 { 0, CODE_FOR_spe_evmwhsmi, "__builtin_spe_evmwhsmi", SPE_BUILTIN_EVMWHSMI },
5160 { 0, CODE_FOR_spe_evmwhsmia, "__builtin_spe_evmwhsmia", SPE_BUILTIN_EVMWHSMIA },
5161 { 0, CODE_FOR_spe_evmwhssf, "__builtin_spe_evmwhssf", SPE_BUILTIN_EVMWHSSF },
5162 { 0, CODE_FOR_spe_evmwhssfa, "__builtin_spe_evmwhssfa", SPE_BUILTIN_EVMWHSSFA },
5163 { 0, CODE_FOR_spe_evmwhumi, "__builtin_spe_evmwhumi", SPE_BUILTIN_EVMWHUMI },
5164 { 0, CODE_FOR_spe_evmwhumia, "__builtin_spe_evmwhumia", SPE_BUILTIN_EVMWHUMIA },
a3170dc6
AH
5165 { 0, CODE_FOR_spe_evmwlsmiaaw, "__builtin_spe_evmwlsmiaaw", SPE_BUILTIN_EVMWLSMIAAW },
5166 { 0, CODE_FOR_spe_evmwlsmianw, "__builtin_spe_evmwlsmianw", SPE_BUILTIN_EVMWLSMIANW },
a3170dc6
AH
5167 { 0, CODE_FOR_spe_evmwlssiaaw, "__builtin_spe_evmwlssiaaw", SPE_BUILTIN_EVMWLSSIAAW },
5168 { 0, CODE_FOR_spe_evmwlssianw, "__builtin_spe_evmwlssianw", SPE_BUILTIN_EVMWLSSIANW },
5169 { 0, CODE_FOR_spe_evmwlumi, "__builtin_spe_evmwlumi", SPE_BUILTIN_EVMWLUMI },
5170 { 0, CODE_FOR_spe_evmwlumia, "__builtin_spe_evmwlumia", SPE_BUILTIN_EVMWLUMIA },
5171 { 0, CODE_FOR_spe_evmwlumiaaw, "__builtin_spe_evmwlumiaaw", SPE_BUILTIN_EVMWLUMIAAW },
5172 { 0, CODE_FOR_spe_evmwlumianw, "__builtin_spe_evmwlumianw", SPE_BUILTIN_EVMWLUMIANW },
5173 { 0, CODE_FOR_spe_evmwlusiaaw, "__builtin_spe_evmwlusiaaw", SPE_BUILTIN_EVMWLUSIAAW },
5174 { 0, CODE_FOR_spe_evmwlusianw, "__builtin_spe_evmwlusianw", SPE_BUILTIN_EVMWLUSIANW },
5175 { 0, CODE_FOR_spe_evmwsmf, "__builtin_spe_evmwsmf", SPE_BUILTIN_EVMWSMF },
5176 { 0, CODE_FOR_spe_evmwsmfa, "__builtin_spe_evmwsmfa", SPE_BUILTIN_EVMWSMFA },
5177 { 0, CODE_FOR_spe_evmwsmfaa, "__builtin_spe_evmwsmfaa", SPE_BUILTIN_EVMWSMFAA },
5178 { 0, CODE_FOR_spe_evmwsmfan, "__builtin_spe_evmwsmfan", SPE_BUILTIN_EVMWSMFAN },
5179 { 0, CODE_FOR_spe_evmwsmi, "__builtin_spe_evmwsmi", SPE_BUILTIN_EVMWSMI },
5180 { 0, CODE_FOR_spe_evmwsmia, "__builtin_spe_evmwsmia", SPE_BUILTIN_EVMWSMIA },
5181 { 0, CODE_FOR_spe_evmwsmiaa, "__builtin_spe_evmwsmiaa", SPE_BUILTIN_EVMWSMIAA },
5182 { 0, CODE_FOR_spe_evmwsmian, "__builtin_spe_evmwsmian", SPE_BUILTIN_EVMWSMIAN },
5183 { 0, CODE_FOR_spe_evmwssf, "__builtin_spe_evmwssf", SPE_BUILTIN_EVMWSSF },
5184 { 0, CODE_FOR_spe_evmwssfa, "__builtin_spe_evmwssfa", SPE_BUILTIN_EVMWSSFA },
5185 { 0, CODE_FOR_spe_evmwssfaa, "__builtin_spe_evmwssfaa", SPE_BUILTIN_EVMWSSFAA },
5186 { 0, CODE_FOR_spe_evmwssfan, "__builtin_spe_evmwssfan", SPE_BUILTIN_EVMWSSFAN },
5187 { 0, CODE_FOR_spe_evmwumi, "__builtin_spe_evmwumi", SPE_BUILTIN_EVMWUMI },
5188 { 0, CODE_FOR_spe_evmwumia, "__builtin_spe_evmwumia", SPE_BUILTIN_EVMWUMIA },
5189 { 0, CODE_FOR_spe_evmwumiaa, "__builtin_spe_evmwumiaa", SPE_BUILTIN_EVMWUMIAA },
5190 { 0, CODE_FOR_spe_evmwumian, "__builtin_spe_evmwumian", SPE_BUILTIN_EVMWUMIAN },
5191 { 0, CODE_FOR_spe_evnand, "__builtin_spe_evnand", SPE_BUILTIN_EVNAND },
5192 { 0, CODE_FOR_spe_evnor, "__builtin_spe_evnor", SPE_BUILTIN_EVNOR },
5193 { 0, CODE_FOR_spe_evor, "__builtin_spe_evor", SPE_BUILTIN_EVOR },
5194 { 0, CODE_FOR_spe_evorc, "__builtin_spe_evorc", SPE_BUILTIN_EVORC },
5195 { 0, CODE_FOR_spe_evrlw, "__builtin_spe_evrlw", SPE_BUILTIN_EVRLW },
5196 { 0, CODE_FOR_spe_evslw, "__builtin_spe_evslw", SPE_BUILTIN_EVSLW },
5197 { 0, CODE_FOR_spe_evsrws, "__builtin_spe_evsrws", SPE_BUILTIN_EVSRWS },
5198 { 0, CODE_FOR_spe_evsrwu, "__builtin_spe_evsrwu", SPE_BUILTIN_EVSRWU },
5199 { 0, CODE_FOR_spe_evsubfw, "__builtin_spe_evsubfw", SPE_BUILTIN_EVSUBFW },
5200
5201 /* SPE binary operations expecting a 5-bit unsigned literal. */
5202 { 0, CODE_FOR_spe_evaddiw, "__builtin_spe_evaddiw", SPE_BUILTIN_EVADDIW },
5203
5204 { 0, CODE_FOR_spe_evrlwi, "__builtin_spe_evrlwi", SPE_BUILTIN_EVRLWI },
5205 { 0, CODE_FOR_spe_evslwi, "__builtin_spe_evslwi", SPE_BUILTIN_EVSLWI },
5206 { 0, CODE_FOR_spe_evsrwis, "__builtin_spe_evsrwis", SPE_BUILTIN_EVSRWIS },
5207 { 0, CODE_FOR_spe_evsrwiu, "__builtin_spe_evsrwiu", SPE_BUILTIN_EVSRWIU },
5208 { 0, CODE_FOR_spe_evsubifw, "__builtin_spe_evsubifw", SPE_BUILTIN_EVSUBIFW },
5209 { 0, CODE_FOR_spe_evmwhssfaa, "__builtin_spe_evmwhssfaa", SPE_BUILTIN_EVMWHSSFAA },
5210 { 0, CODE_FOR_spe_evmwhssmaa, "__builtin_spe_evmwhssmaa", SPE_BUILTIN_EVMWHSSMAA },
5211 { 0, CODE_FOR_spe_evmwhsmfaa, "__builtin_spe_evmwhsmfaa", SPE_BUILTIN_EVMWHSMFAA },
5212 { 0, CODE_FOR_spe_evmwhsmiaa, "__builtin_spe_evmwhsmiaa", SPE_BUILTIN_EVMWHSMIAA },
5213 { 0, CODE_FOR_spe_evmwhusiaa, "__builtin_spe_evmwhusiaa", SPE_BUILTIN_EVMWHUSIAA },
5214 { 0, CODE_FOR_spe_evmwhumiaa, "__builtin_spe_evmwhumiaa", SPE_BUILTIN_EVMWHUMIAA },
5215 { 0, CODE_FOR_spe_evmwhssfan, "__builtin_spe_evmwhssfan", SPE_BUILTIN_EVMWHSSFAN },
5216 { 0, CODE_FOR_spe_evmwhssian, "__builtin_spe_evmwhssian", SPE_BUILTIN_EVMWHSSIAN },
5217 { 0, CODE_FOR_spe_evmwhsmfan, "__builtin_spe_evmwhsmfan", SPE_BUILTIN_EVMWHSMFAN },
5218 { 0, CODE_FOR_spe_evmwhsmian, "__builtin_spe_evmwhsmian", SPE_BUILTIN_EVMWHSMIAN },
5219 { 0, CODE_FOR_spe_evmwhusian, "__builtin_spe_evmwhusian", SPE_BUILTIN_EVMWHUSIAN },
5220 { 0, CODE_FOR_spe_evmwhumian, "__builtin_spe_evmwhumian", SPE_BUILTIN_EVMWHUMIAN },
5221 { 0, CODE_FOR_spe_evmwhgssfaa, "__builtin_spe_evmwhgssfaa", SPE_BUILTIN_EVMWHGSSFAA },
5222 { 0, CODE_FOR_spe_evmwhgsmfaa, "__builtin_spe_evmwhgsmfaa", SPE_BUILTIN_EVMWHGSMFAA },
5223 { 0, CODE_FOR_spe_evmwhgsmiaa, "__builtin_spe_evmwhgsmiaa", SPE_BUILTIN_EVMWHGSMIAA },
5224 { 0, CODE_FOR_spe_evmwhgumiaa, "__builtin_spe_evmwhgumiaa", SPE_BUILTIN_EVMWHGUMIAA },
5225 { 0, CODE_FOR_spe_evmwhgssfan, "__builtin_spe_evmwhgssfan", SPE_BUILTIN_EVMWHGSSFAN },
5226 { 0, CODE_FOR_spe_evmwhgsmfan, "__builtin_spe_evmwhgsmfan", SPE_BUILTIN_EVMWHGSMFAN },
5227 { 0, CODE_FOR_spe_evmwhgsmian, "__builtin_spe_evmwhgsmian", SPE_BUILTIN_EVMWHGSMIAN },
5228 { 0, CODE_FOR_spe_evmwhgumian, "__builtin_spe_evmwhgumian", SPE_BUILTIN_EVMWHGUMIAN },
5229 { 0, CODE_FOR_spe_brinc, "__builtin_spe_brinc", SPE_BUILTIN_BRINC },
5230
5231 /* Place-holder. Leave as last binary SPE builtin. */
17edbda5 5232 { 0, CODE_FOR_xorv2si3, "__builtin_spe_evxor", SPE_BUILTIN_EVXOR },
ae4b4a02
AH
5233};
5234
5235/* AltiVec predicates. */
5236
5237struct builtin_description_predicates
5238{
5239 const unsigned int mask;
5240 const enum insn_code icode;
5241 const char *opcode;
5242 const char *const name;
5243 const enum rs6000_builtins code;
5244};
5245
5246static const struct builtin_description_predicates bdesc_altivec_preds[] =
5247{
5248 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpbfp.", "__builtin_altivec_vcmpbfp_p", ALTIVEC_BUILTIN_VCMPBFP_P },
5249 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpeqfp.", "__builtin_altivec_vcmpeqfp_p", ALTIVEC_BUILTIN_VCMPEQFP_P },
5250 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgefp.", "__builtin_altivec_vcmpgefp_p", ALTIVEC_BUILTIN_VCMPGEFP_P },
5251 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4sf, "*vcmpgtfp.", "__builtin_altivec_vcmpgtfp_p", ALTIVEC_BUILTIN_VCMPGTFP_P },
5252 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpequw.", "__builtin_altivec_vcmpequw_p", ALTIVEC_BUILTIN_VCMPEQUW_P },
5253 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtsw.", "__builtin_altivec_vcmpgtsw_p", ALTIVEC_BUILTIN_VCMPGTSW_P },
5254 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v4si, "*vcmpgtuw.", "__builtin_altivec_vcmpgtuw_p", ALTIVEC_BUILTIN_VCMPGTUW_P },
5255 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtuh.", "__builtin_altivec_vcmpgtuh_p", ALTIVEC_BUILTIN_VCMPGTUH_P },
5256 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpgtsh.", "__builtin_altivec_vcmpgtsh_p", ALTIVEC_BUILTIN_VCMPGTSH_P },
5257 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v8hi, "*vcmpequh.", "__builtin_altivec_vcmpequh_p", ALTIVEC_BUILTIN_VCMPEQUH_P },
5258 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpequb.", "__builtin_altivec_vcmpequb_p", ALTIVEC_BUILTIN_VCMPEQUB_P },
5259 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtsb.", "__builtin_altivec_vcmpgtsb_p", ALTIVEC_BUILTIN_VCMPGTSB_P },
5260 { MASK_ALTIVEC, CODE_FOR_altivec_predicate_v16qi, "*vcmpgtub.", "__builtin_altivec_vcmpgtub_p", ALTIVEC_BUILTIN_VCMPGTUB_P }
0ac081f6 5261};
24408032 5262
a3170dc6
AH
5263/* SPE predicates. */
5264static struct builtin_description bdesc_spe_predicates[] =
5265{
5266 /* Place-holder. Leave as first. */
5267 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evcmpeq", SPE_BUILTIN_EVCMPEQ },
5268 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evcmpgts", SPE_BUILTIN_EVCMPGTS },
5269 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evcmpgtu", SPE_BUILTIN_EVCMPGTU },
5270 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evcmplts", SPE_BUILTIN_EVCMPLTS },
5271 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evcmpltu", SPE_BUILTIN_EVCMPLTU },
5272 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evfscmpeq", SPE_BUILTIN_EVFSCMPEQ },
5273 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evfscmpgt", SPE_BUILTIN_EVFSCMPGT },
5274 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evfscmplt", SPE_BUILTIN_EVFSCMPLT },
5275 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evfststeq", SPE_BUILTIN_EVFSTSTEQ },
5276 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evfststgt", SPE_BUILTIN_EVFSTSTGT },
5277 /* Place-holder. Leave as last. */
5278 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evfststlt", SPE_BUILTIN_EVFSTSTLT },
5279};
5280
5281/* SPE evsel predicates. */
5282static struct builtin_description bdesc_spe_evsel[] =
5283{
5284 /* Place-holder. Leave as first. */
5285 { 0, CODE_FOR_spe_evcmpgts, "__builtin_spe_evsel_gts", SPE_BUILTIN_EVSEL_CMPGTS },
5286 { 0, CODE_FOR_spe_evcmpgtu, "__builtin_spe_evsel_gtu", SPE_BUILTIN_EVSEL_CMPGTU },
5287 { 0, CODE_FOR_spe_evcmplts, "__builtin_spe_evsel_lts", SPE_BUILTIN_EVSEL_CMPLTS },
5288 { 0, CODE_FOR_spe_evcmpltu, "__builtin_spe_evsel_ltu", SPE_BUILTIN_EVSEL_CMPLTU },
5289 { 0, CODE_FOR_spe_evcmpeq, "__builtin_spe_evsel_eq", SPE_BUILTIN_EVSEL_CMPEQ },
5290 { 0, CODE_FOR_spe_evfscmpgt, "__builtin_spe_evsel_fsgt", SPE_BUILTIN_EVSEL_FSCMPGT },
5291 { 0, CODE_FOR_spe_evfscmplt, "__builtin_spe_evsel_fslt", SPE_BUILTIN_EVSEL_FSCMPLT },
5292 { 0, CODE_FOR_spe_evfscmpeq, "__builtin_spe_evsel_fseq", SPE_BUILTIN_EVSEL_FSCMPEQ },
5293 { 0, CODE_FOR_spe_evfststgt, "__builtin_spe_evsel_fststgt", SPE_BUILTIN_EVSEL_FSTSTGT },
5294 { 0, CODE_FOR_spe_evfststlt, "__builtin_spe_evsel_fststlt", SPE_BUILTIN_EVSEL_FSTSTLT },
5295 /* Place-holder. Leave as last. */
5296 { 0, CODE_FOR_spe_evfststeq, "__builtin_spe_evsel_fststeq", SPE_BUILTIN_EVSEL_FSTSTEQ },
5297};
5298
b6d08ca1 5299/* ABS* operations. */
100c4561
AH
5300
5301static const struct builtin_description bdesc_abs[] =
5302{
5303 { MASK_ALTIVEC, CODE_FOR_absv4si2, "__builtin_altivec_abs_v4si", ALTIVEC_BUILTIN_ABS_V4SI },
5304 { MASK_ALTIVEC, CODE_FOR_absv8hi2, "__builtin_altivec_abs_v8hi", ALTIVEC_BUILTIN_ABS_V8HI },
5305 { MASK_ALTIVEC, CODE_FOR_absv4sf2, "__builtin_altivec_abs_v4sf", ALTIVEC_BUILTIN_ABS_V4SF },
5306 { MASK_ALTIVEC, CODE_FOR_absv16qi2, "__builtin_altivec_abs_v16qi", ALTIVEC_BUILTIN_ABS_V16QI },
5307 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v4si, "__builtin_altivec_abss_v4si", ALTIVEC_BUILTIN_ABSS_V4SI },
5308 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v8hi, "__builtin_altivec_abss_v8hi", ALTIVEC_BUILTIN_ABSS_V8HI },
5309 { MASK_ALTIVEC, CODE_FOR_altivec_abss_v16qi, "__builtin_altivec_abss_v16qi", ALTIVEC_BUILTIN_ABSS_V16QI }
5310};
5311
617e0e1d
DB
5312/* Simple unary operations: VECb = foo (unsigned literal) or VECb =
5313 foo (VECa). */
24408032 5314
a3170dc6 5315static struct builtin_description bdesc_1arg[] =
2212663f 5316{
617e0e1d
DB
5317 { MASK_ALTIVEC, CODE_FOR_altivec_vexptefp, "__builtin_altivec_vexptefp", ALTIVEC_BUILTIN_VEXPTEFP },
5318 { MASK_ALTIVEC, CODE_FOR_altivec_vlogefp, "__builtin_altivec_vlogefp", ALTIVEC_BUILTIN_VLOGEFP },
5319 { MASK_ALTIVEC, CODE_FOR_altivec_vrefp, "__builtin_altivec_vrefp", ALTIVEC_BUILTIN_VREFP },
5320 { MASK_ALTIVEC, CODE_FOR_altivec_vrfim, "__builtin_altivec_vrfim", ALTIVEC_BUILTIN_VRFIM },
5321 { MASK_ALTIVEC, CODE_FOR_altivec_vrfin, "__builtin_altivec_vrfin", ALTIVEC_BUILTIN_VRFIN },
5322 { MASK_ALTIVEC, CODE_FOR_altivec_vrfip, "__builtin_altivec_vrfip", ALTIVEC_BUILTIN_VRFIP },
5323 { MASK_ALTIVEC, CODE_FOR_ftruncv4sf2, "__builtin_altivec_vrfiz", ALTIVEC_BUILTIN_VRFIZ },
5324 { MASK_ALTIVEC, CODE_FOR_altivec_vrsqrtefp, "__builtin_altivec_vrsqrtefp", ALTIVEC_BUILTIN_VRSQRTEFP },
2212663f
DB
5325 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisb, "__builtin_altivec_vspltisb", ALTIVEC_BUILTIN_VSPLTISB },
5326 { MASK_ALTIVEC, CODE_FOR_altivec_vspltish, "__builtin_altivec_vspltish", ALTIVEC_BUILTIN_VSPLTISH },
5327 { MASK_ALTIVEC, CODE_FOR_altivec_vspltisw, "__builtin_altivec_vspltisw", ALTIVEC_BUILTIN_VSPLTISW },
20e26713
AH
5328 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsb, "__builtin_altivec_vupkhsb", ALTIVEC_BUILTIN_VUPKHSB },
5329 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhpx, "__builtin_altivec_vupkhpx", ALTIVEC_BUILTIN_VUPKHPX },
5330 { MASK_ALTIVEC, CODE_FOR_altivec_vupkhsh, "__builtin_altivec_vupkhsh", ALTIVEC_BUILTIN_VUPKHSH },
5331 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsb, "__builtin_altivec_vupklsb", ALTIVEC_BUILTIN_VUPKLSB },
5332 { MASK_ALTIVEC, CODE_FOR_altivec_vupklpx, "__builtin_altivec_vupklpx", ALTIVEC_BUILTIN_VUPKLPX },
5333 { MASK_ALTIVEC, CODE_FOR_altivec_vupklsh, "__builtin_altivec_vupklsh", ALTIVEC_BUILTIN_VUPKLSH },
a3170dc6
AH
5334
5335 /* The SPE unary builtins must start with SPE_BUILTIN_EVABS and
5336 end with SPE_BUILTIN_EVSUBFUSIAAW. */
5337 { 0, CODE_FOR_spe_evabs, "__builtin_spe_evabs", SPE_BUILTIN_EVABS },
5338 { 0, CODE_FOR_spe_evaddsmiaaw, "__builtin_spe_evaddsmiaaw", SPE_BUILTIN_EVADDSMIAAW },
5339 { 0, CODE_FOR_spe_evaddssiaaw, "__builtin_spe_evaddssiaaw", SPE_BUILTIN_EVADDSSIAAW },
5340 { 0, CODE_FOR_spe_evaddumiaaw, "__builtin_spe_evaddumiaaw", SPE_BUILTIN_EVADDUMIAAW },
5341 { 0, CODE_FOR_spe_evaddusiaaw, "__builtin_spe_evaddusiaaw", SPE_BUILTIN_EVADDUSIAAW },
5342 { 0, CODE_FOR_spe_evcntlsw, "__builtin_spe_evcntlsw", SPE_BUILTIN_EVCNTLSW },
5343 { 0, CODE_FOR_spe_evcntlzw, "__builtin_spe_evcntlzw", SPE_BUILTIN_EVCNTLZW },
5344 { 0, CODE_FOR_spe_evextsb, "__builtin_spe_evextsb", SPE_BUILTIN_EVEXTSB },
5345 { 0, CODE_FOR_spe_evextsh, "__builtin_spe_evextsh", SPE_BUILTIN_EVEXTSH },
5346 { 0, CODE_FOR_spe_evfsabs, "__builtin_spe_evfsabs", SPE_BUILTIN_EVFSABS },
5347 { 0, CODE_FOR_spe_evfscfsf, "__builtin_spe_evfscfsf", SPE_BUILTIN_EVFSCFSF },
5348 { 0, CODE_FOR_spe_evfscfsi, "__builtin_spe_evfscfsi", SPE_BUILTIN_EVFSCFSI },
5349 { 0, CODE_FOR_spe_evfscfuf, "__builtin_spe_evfscfuf", SPE_BUILTIN_EVFSCFUF },
5350 { 0, CODE_FOR_spe_evfscfui, "__builtin_spe_evfscfui", SPE_BUILTIN_EVFSCFUI },
5351 { 0, CODE_FOR_spe_evfsctsf, "__builtin_spe_evfsctsf", SPE_BUILTIN_EVFSCTSF },
5352 { 0, CODE_FOR_spe_evfsctsi, "__builtin_spe_evfsctsi", SPE_BUILTIN_EVFSCTSI },
5353 { 0, CODE_FOR_spe_evfsctsiz, "__builtin_spe_evfsctsiz", SPE_BUILTIN_EVFSCTSIZ },
5354 { 0, CODE_FOR_spe_evfsctuf, "__builtin_spe_evfsctuf", SPE_BUILTIN_EVFSCTUF },
5355 { 0, CODE_FOR_spe_evfsctui, "__builtin_spe_evfsctui", SPE_BUILTIN_EVFSCTUI },
5356 { 0, CODE_FOR_spe_evfsctuiz, "__builtin_spe_evfsctuiz", SPE_BUILTIN_EVFSCTUIZ },
5357 { 0, CODE_FOR_spe_evfsnabs, "__builtin_spe_evfsnabs", SPE_BUILTIN_EVFSNABS },
5358 { 0, CODE_FOR_spe_evfsneg, "__builtin_spe_evfsneg", SPE_BUILTIN_EVFSNEG },
5359 { 0, CODE_FOR_spe_evmra, "__builtin_spe_evmra", SPE_BUILTIN_EVMRA },
5360 { 0, CODE_FOR_spe_evneg, "__builtin_spe_evneg", SPE_BUILTIN_EVNEG },
5361 { 0, CODE_FOR_spe_evrndw, "__builtin_spe_evrndw", SPE_BUILTIN_EVRNDW },
5362 { 0, CODE_FOR_spe_evsubfsmiaaw, "__builtin_spe_evsubfsmiaaw", SPE_BUILTIN_EVSUBFSMIAAW },
5363 { 0, CODE_FOR_spe_evsubfssiaaw, "__builtin_spe_evsubfssiaaw", SPE_BUILTIN_EVSUBFSSIAAW },
5364 { 0, CODE_FOR_spe_evsubfumiaaw, "__builtin_spe_evsubfumiaaw", SPE_BUILTIN_EVSUBFUMIAAW },
a3170dc6
AH
5365
5366 /* Place-holder. Leave as last unary SPE builtin. */
5367 { 0, CODE_FOR_spe_evsubfusiaaw, "__builtin_spe_evsubfusiaaw", SPE_BUILTIN_EVSUBFUSIAAW },
2212663f
DB
5368};
5369
5370static rtx
a2369ed3 5371rs6000_expand_unop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5372{
5373 rtx pat;
5374 tree arg0 = TREE_VALUE (arglist);
5375 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5376 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5377 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5378
0559cc77
DE
5379 if (icode == CODE_FOR_nothing)
5380 /* Builtin not supported on this processor. */
5381 return 0;
5382
20e26713
AH
5383 /* If we got invalid arguments bail out before generating bad rtl. */
5384 if (arg0 == error_mark_node)
9a171fcd 5385 return const0_rtx;
20e26713 5386
0559cc77
DE
5387 if (icode == CODE_FOR_altivec_vspltisb
5388 || icode == CODE_FOR_altivec_vspltish
5389 || icode == CODE_FOR_altivec_vspltisw
5390 || icode == CODE_FOR_spe_evsplatfi
5391 || icode == CODE_FOR_spe_evsplati)
b44140e7
AH
5392 {
5393 /* Only allow 5-bit *signed* literals. */
b44140e7
AH
5394 if (GET_CODE (op0) != CONST_INT
5395 || INTVAL (op0) > 0x1f
5396 || INTVAL (op0) < -0x1f)
5397 {
5398 error ("argument 1 must be a 5-bit signed literal");
9a171fcd 5399 return const0_rtx;
b44140e7 5400 }
b44140e7
AH
5401 }
5402
c62f2db5 5403 if (target == 0
2212663f
DB
5404 || GET_MODE (target) != tmode
5405 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5406 target = gen_reg_rtx (tmode);
5407
5408 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5409 op0 = copy_to_mode_reg (mode0, op0);
5410
5411 pat = GEN_FCN (icode) (target, op0);
5412 if (! pat)
5413 return 0;
5414 emit_insn (pat);
0ac081f6 5415
2212663f
DB
5416 return target;
5417}
ae4b4a02 5418
100c4561 5419static rtx
a2369ed3 5420altivec_expand_abs_builtin (enum insn_code icode, tree arglist, rtx target)
100c4561
AH
5421{
5422 rtx pat, scratch1, scratch2;
5423 tree arg0 = TREE_VALUE (arglist);
5424 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5425 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5426 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5427
5428 /* If we have invalid arguments, bail out before generating bad rtl. */
5429 if (arg0 == error_mark_node)
9a171fcd 5430 return const0_rtx;
100c4561
AH
5431
5432 if (target == 0
5433 || GET_MODE (target) != tmode
5434 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5435 target = gen_reg_rtx (tmode);
5436
5437 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5438 op0 = copy_to_mode_reg (mode0, op0);
5439
5440 scratch1 = gen_reg_rtx (mode0);
5441 scratch2 = gen_reg_rtx (mode0);
5442
5443 pat = GEN_FCN (icode) (target, op0, scratch1, scratch2);
5444 if (! pat)
5445 return 0;
5446 emit_insn (pat);
5447
5448 return target;
5449}
5450
0ac081f6 5451static rtx
a2369ed3 5452rs6000_expand_binop_builtin (enum insn_code icode, tree arglist, rtx target)
0ac081f6
AH
5453{
5454 rtx pat;
5455 tree arg0 = TREE_VALUE (arglist);
5456 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5457 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5458 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5459 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5460 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5461 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5462
0559cc77
DE
5463 if (icode == CODE_FOR_nothing)
5464 /* Builtin not supported on this processor. */
5465 return 0;
5466
20e26713
AH
5467 /* If we got invalid arguments bail out before generating bad rtl. */
5468 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5469 return const0_rtx;
20e26713 5470
0559cc77
DE
5471 if (icode == CODE_FOR_altivec_vcfux
5472 || icode == CODE_FOR_altivec_vcfsx
5473 || icode == CODE_FOR_altivec_vctsxs
5474 || icode == CODE_FOR_altivec_vctuxs
5475 || icode == CODE_FOR_altivec_vspltb
5476 || icode == CODE_FOR_altivec_vsplth
5477 || icode == CODE_FOR_altivec_vspltw
5478 || icode == CODE_FOR_spe_evaddiw
5479 || icode == CODE_FOR_spe_evldd
5480 || icode == CODE_FOR_spe_evldh
5481 || icode == CODE_FOR_spe_evldw
5482 || icode == CODE_FOR_spe_evlhhesplat
5483 || icode == CODE_FOR_spe_evlhhossplat
5484 || icode == CODE_FOR_spe_evlhhousplat
5485 || icode == CODE_FOR_spe_evlwhe
5486 || icode == CODE_FOR_spe_evlwhos
5487 || icode == CODE_FOR_spe_evlwhou
5488 || icode == CODE_FOR_spe_evlwhsplat
5489 || icode == CODE_FOR_spe_evlwwsplat
5490 || icode == CODE_FOR_spe_evrlwi
5491 || icode == CODE_FOR_spe_evslwi
5492 || icode == CODE_FOR_spe_evsrwis
f5119d10 5493 || icode == CODE_FOR_spe_evsubifw
0559cc77 5494 || icode == CODE_FOR_spe_evsrwiu)
b44140e7
AH
5495 {
5496 /* Only allow 5-bit unsigned literals. */
b44140e7
AH
5497 if (TREE_CODE (arg1) != INTEGER_CST
5498 || TREE_INT_CST_LOW (arg1) & ~0x1f)
5499 {
5500 error ("argument 2 must be a 5-bit unsigned literal");
9a171fcd 5501 return const0_rtx;
b44140e7 5502 }
b44140e7
AH
5503 }
5504
c62f2db5 5505 if (target == 0
0ac081f6
AH
5506 || GET_MODE (target) != tmode
5507 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5508 target = gen_reg_rtx (tmode);
5509
5510 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5511 op0 = copy_to_mode_reg (mode0, op0);
5512 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5513 op1 = copy_to_mode_reg (mode1, op1);
5514
5515 pat = GEN_FCN (icode) (target, op0, op1);
5516 if (! pat)
5517 return 0;
5518 emit_insn (pat);
5519
5520 return target;
5521}
6525c0e7 5522
ae4b4a02 5523static rtx
a2369ed3
DJ
5524altivec_expand_predicate_builtin (enum insn_code icode, const char *opcode,
5525 tree arglist, rtx target)
ae4b4a02
AH
5526{
5527 rtx pat, scratch;
5528 tree cr6_form = TREE_VALUE (arglist);
5529 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
5530 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5531 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5532 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5533 enum machine_mode tmode = SImode;
5534 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5535 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5536 int cr6_form_int;
5537
5538 if (TREE_CODE (cr6_form) != INTEGER_CST)
5539 {
5540 error ("argument 1 of __builtin_altivec_predicate must be a constant");
9a171fcd 5541 return const0_rtx;
ae4b4a02
AH
5542 }
5543 else
5544 cr6_form_int = TREE_INT_CST_LOW (cr6_form);
5545
5546 if (mode0 != mode1)
5547 abort ();
5548
5549 /* If we have invalid arguments, bail out before generating bad rtl. */
5550 if (arg0 == error_mark_node || arg1 == error_mark_node)
9a171fcd 5551 return const0_rtx;
ae4b4a02
AH
5552
5553 if (target == 0
5554 || GET_MODE (target) != tmode
5555 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5556 target = gen_reg_rtx (tmode);
5557
5558 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5559 op0 = copy_to_mode_reg (mode0, op0);
5560 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5561 op1 = copy_to_mode_reg (mode1, op1);
5562
5563 scratch = gen_reg_rtx (mode0);
5564
5565 pat = GEN_FCN (icode) (scratch, op0, op1,
f1c25d3b 5566 gen_rtx_SYMBOL_REF (Pmode, opcode));
ae4b4a02
AH
5567 if (! pat)
5568 return 0;
5569 emit_insn (pat);
5570
5571 /* The vec_any* and vec_all* predicates use the same opcodes for two
5572 different operations, but the bits in CR6 will be different
5573 depending on what information we want. So we have to play tricks
5574 with CR6 to get the right bits out.
5575
5576 If you think this is disgusting, look at the specs for the
5577 AltiVec predicates. */
5578
5579 switch (cr6_form_int)
5580 {
5581 case 0:
5582 emit_insn (gen_cr6_test_for_zero (target));
5583 break;
5584 case 1:
5585 emit_insn (gen_cr6_test_for_zero_reverse (target));
5586 break;
5587 case 2:
5588 emit_insn (gen_cr6_test_for_lt (target));
5589 break;
5590 case 3:
5591 emit_insn (gen_cr6_test_for_lt_reverse (target));
5592 break;
5593 default:
5594 error ("argument 1 of __builtin_altivec_predicate is out of range");
5595 break;
5596 }
5597
5598 return target;
5599}
5600
b4a62fa0 5601static rtx
38f391a5 5602altivec_expand_lv_builtin (enum insn_code icode, tree arglist, rtx target)
b4a62fa0
SB
5603{
5604 rtx pat, addr;
5605 tree arg0 = TREE_VALUE (arglist);
5606 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5607 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5608 enum machine_mode mode0 = Pmode;
5609 enum machine_mode mode1 = Pmode;
5610 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5611 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5612
5613 if (icode == CODE_FOR_nothing)
5614 /* Builtin not supported on this processor. */
5615 return 0;
5616
5617 /* If we got invalid arguments bail out before generating bad rtl. */
5618 if (arg0 == error_mark_node || arg1 == error_mark_node)
5619 return const0_rtx;
5620
5621 if (target == 0
5622 || GET_MODE (target) != tmode
5623 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5624 target = gen_reg_rtx (tmode);
5625
5626 op1 = copy_to_mode_reg (mode1, op1);
5627
5628 if (op0 == const0_rtx)
5629 {
5630 addr = gen_rtx_MEM (tmode, op1);
5631 }
5632 else
5633 {
5634 op0 = copy_to_mode_reg (mode0, op0);
5635 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op0, op1));
5636 }
5637
5638 pat = GEN_FCN (icode) (target, addr);
5639
5640 if (! pat)
5641 return 0;
5642 emit_insn (pat);
5643
5644 return target;
5645}
5646
6525c0e7 5647static rtx
a2369ed3 5648altivec_expand_stv_builtin (enum insn_code icode, tree arglist)
6525c0e7
AH
5649{
5650 tree arg0 = TREE_VALUE (arglist);
5651 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5652 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5653 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5654 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5655 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
b4a62fa0
SB
5656 rtx pat, addr;
5657 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5658 enum machine_mode mode1 = Pmode;
5659 enum machine_mode mode2 = Pmode;
6525c0e7
AH
5660
5661 /* Invalid arguments. Bail before doing anything stoopid! */
5662 if (arg0 == error_mark_node
5663 || arg1 == error_mark_node
5664 || arg2 == error_mark_node)
9a171fcd 5665 return const0_rtx;
6525c0e7 5666
b4a62fa0
SB
5667 if (! (*insn_data[icode].operand[1].predicate) (op0, tmode))
5668 op0 = copy_to_mode_reg (tmode, op0);
5669
5670 op2 = copy_to_mode_reg (mode2, op2);
5671
5672 if (op1 == const0_rtx)
5673 {
5674 addr = gen_rtx_MEM (tmode, op2);
5675 }
5676 else
5677 {
5678 op1 = copy_to_mode_reg (mode1, op1);
5679 addr = gen_rtx_MEM (tmode, gen_rtx_PLUS (Pmode, op1, op2));
5680 }
6525c0e7 5681
b4a62fa0 5682 pat = GEN_FCN (icode) (addr, op0);
6525c0e7
AH
5683 if (pat)
5684 emit_insn (pat);
5685 return NULL_RTX;
5686}
5687
2212663f 5688static rtx
a2369ed3 5689rs6000_expand_ternop_builtin (enum insn_code icode, tree arglist, rtx target)
2212663f
DB
5690{
5691 rtx pat;
5692 tree arg0 = TREE_VALUE (arglist);
5693 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5694 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5695 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5696 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5697 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5698 enum machine_mode tmode = insn_data[icode].operand[0].mode;
5699 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
5700 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
5701 enum machine_mode mode2 = insn_data[icode].operand[3].mode;
0ac081f6 5702
774b5662
DE
5703 if (icode == CODE_FOR_nothing)
5704 /* Builtin not supported on this processor. */
5705 return 0;
5706
20e26713
AH
5707 /* If we got invalid arguments bail out before generating bad rtl. */
5708 if (arg0 == error_mark_node
5709 || arg1 == error_mark_node
5710 || arg2 == error_mark_node)
9a171fcd 5711 return const0_rtx;
20e26713 5712
774b5662
DE
5713 if (icode == CODE_FOR_altivec_vsldoi_4sf
5714 || icode == CODE_FOR_altivec_vsldoi_4si
5715 || icode == CODE_FOR_altivec_vsldoi_8hi
5716 || icode == CODE_FOR_altivec_vsldoi_16qi)
b44140e7
AH
5717 {
5718 /* Only allow 4-bit unsigned literals. */
b44140e7
AH
5719 if (TREE_CODE (arg2) != INTEGER_CST
5720 || TREE_INT_CST_LOW (arg2) & ~0xf)
5721 {
5722 error ("argument 3 must be a 4-bit unsigned literal");
e3277ffb 5723 return const0_rtx;
b44140e7 5724 }
b44140e7
AH
5725 }
5726
c62f2db5 5727 if (target == 0
2212663f
DB
5728 || GET_MODE (target) != tmode
5729 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5730 target = gen_reg_rtx (tmode);
5731
5732 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5733 op0 = copy_to_mode_reg (mode0, op0);
5734 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
5735 op1 = copy_to_mode_reg (mode1, op1);
5736 if (! (*insn_data[icode].operand[3].predicate) (op2, mode2))
5737 op2 = copy_to_mode_reg (mode2, op2);
5738
5739 pat = GEN_FCN (icode) (target, op0, op1, op2);
5740 if (! pat)
5741 return 0;
5742 emit_insn (pat);
5743
5744 return target;
5745}
92898235 5746
3a9b8c7e 5747/* Expand the lvx builtins. */
0ac081f6 5748static rtx
a2369ed3 5749altivec_expand_ld_builtin (tree exp, rtx target, bool *expandedp)
0ac081f6 5750{
0ac081f6
AH
5751 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5752 tree arglist = TREE_OPERAND (exp, 1);
0ac081f6 5753 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
3a9b8c7e
AH
5754 tree arg0;
5755 enum machine_mode tmode, mode0;
7c3abc73 5756 rtx pat, op0;
3a9b8c7e 5757 enum insn_code icode;
92898235 5758
0ac081f6
AH
5759 switch (fcode)
5760 {
f18c054f
DB
5761 case ALTIVEC_BUILTIN_LD_INTERNAL_16qi:
5762 icode = CODE_FOR_altivec_lvx_16qi;
3a9b8c7e 5763 break;
f18c054f
DB
5764 case ALTIVEC_BUILTIN_LD_INTERNAL_8hi:
5765 icode = CODE_FOR_altivec_lvx_8hi;
3a9b8c7e
AH
5766 break;
5767 case ALTIVEC_BUILTIN_LD_INTERNAL_4si:
5768 icode = CODE_FOR_altivec_lvx_4si;
5769 break;
5770 case ALTIVEC_BUILTIN_LD_INTERNAL_4sf:
5771 icode = CODE_FOR_altivec_lvx_4sf;
5772 break;
5773 default:
5774 *expandedp = false;
5775 return NULL_RTX;
5776 }
0ac081f6 5777
3a9b8c7e 5778 *expandedp = true;
f18c054f 5779
3a9b8c7e
AH
5780 arg0 = TREE_VALUE (arglist);
5781 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5782 tmode = insn_data[icode].operand[0].mode;
5783 mode0 = insn_data[icode].operand[1].mode;
f18c054f 5784
3a9b8c7e
AH
5785 if (target == 0
5786 || GET_MODE (target) != tmode
5787 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5788 target = gen_reg_rtx (tmode);
24408032 5789
3a9b8c7e
AH
5790 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
5791 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
f18c054f 5792
3a9b8c7e
AH
5793 pat = GEN_FCN (icode) (target, op0);
5794 if (! pat)
5795 return 0;
5796 emit_insn (pat);
5797 return target;
5798}
f18c054f 5799
3a9b8c7e
AH
5800/* Expand the stvx builtins. */
5801static rtx
a2369ed3
DJ
5802altivec_expand_st_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5803 bool *expandedp)
3a9b8c7e
AH
5804{
5805 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5806 tree arglist = TREE_OPERAND (exp, 1);
5807 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5808 tree arg0, arg1;
5809 enum machine_mode mode0, mode1;
7c3abc73 5810 rtx pat, op0, op1;
3a9b8c7e 5811 enum insn_code icode;
f18c054f 5812
3a9b8c7e
AH
5813 switch (fcode)
5814 {
5815 case ALTIVEC_BUILTIN_ST_INTERNAL_16qi:
5816 icode = CODE_FOR_altivec_stvx_16qi;
5817 break;
5818 case ALTIVEC_BUILTIN_ST_INTERNAL_8hi:
5819 icode = CODE_FOR_altivec_stvx_8hi;
5820 break;
5821 case ALTIVEC_BUILTIN_ST_INTERNAL_4si:
5822 icode = CODE_FOR_altivec_stvx_4si;
5823 break;
5824 case ALTIVEC_BUILTIN_ST_INTERNAL_4sf:
5825 icode = CODE_FOR_altivec_stvx_4sf;
5826 break;
5827 default:
5828 *expandedp = false;
5829 return NULL_RTX;
5830 }
24408032 5831
3a9b8c7e
AH
5832 arg0 = TREE_VALUE (arglist);
5833 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5834 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5835 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5836 mode0 = insn_data[icode].operand[0].mode;
5837 mode1 = insn_data[icode].operand[1].mode;
f18c054f 5838
3a9b8c7e
AH
5839 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5840 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
5841 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
5842 op1 = copy_to_mode_reg (mode1, op1);
f18c054f 5843
3a9b8c7e
AH
5844 pat = GEN_FCN (icode) (op0, op1);
5845 if (pat)
5846 emit_insn (pat);
f18c054f 5847
3a9b8c7e
AH
5848 *expandedp = true;
5849 return NULL_RTX;
5850}
f18c054f 5851
3a9b8c7e
AH
5852/* Expand the dst builtins. */
5853static rtx
a2369ed3
DJ
5854altivec_expand_dst_builtin (tree exp, rtx target ATTRIBUTE_UNUSED,
5855 bool *expandedp)
3a9b8c7e
AH
5856{
5857 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5858 tree arglist = TREE_OPERAND (exp, 1);
5859 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
5860 tree arg0, arg1, arg2;
5861 enum machine_mode mode0, mode1, mode2;
7c3abc73 5862 rtx pat, op0, op1, op2;
3a9b8c7e 5863 struct builtin_description *d;
a3170dc6 5864 size_t i;
f18c054f 5865
3a9b8c7e 5866 *expandedp = false;
f18c054f 5867
3a9b8c7e
AH
5868 /* Handle DST variants. */
5869 d = (struct builtin_description *) bdesc_dst;
5870 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
5871 if (d->code == fcode)
5872 {
5873 arg0 = TREE_VALUE (arglist);
5874 arg1 = TREE_VALUE (TREE_CHAIN (arglist));
5875 arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
5876 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5877 op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
5878 op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
5879 mode0 = insn_data[d->icode].operand[0].mode;
5880 mode1 = insn_data[d->icode].operand[1].mode;
5881 mode2 = insn_data[d->icode].operand[2].mode;
24408032 5882
3a9b8c7e
AH
5883 /* Invalid arguments, bail out before generating bad rtl. */
5884 if (arg0 == error_mark_node
5885 || arg1 == error_mark_node
5886 || arg2 == error_mark_node)
5887 return const0_rtx;
f18c054f 5888
3a9b8c7e
AH
5889 if (TREE_CODE (arg2) != INTEGER_CST
5890 || TREE_INT_CST_LOW (arg2) & ~0x3)
5891 {
5892 error ("argument to `%s' must be a 2-bit unsigned literal", d->name);
5893 return const0_rtx;
5894 }
f18c054f 5895
3a9b8c7e 5896 if (! (*insn_data[d->icode].operand[0].predicate) (op0, mode0))
b4a62fa0 5897 op0 = gen_rtx_MEM (mode0, copy_to_mode_reg (Pmode, op0));
3a9b8c7e
AH
5898 if (! (*insn_data[d->icode].operand[1].predicate) (op1, mode1))
5899 op1 = copy_to_mode_reg (mode1, op1);
24408032 5900
3a9b8c7e
AH
5901 pat = GEN_FCN (d->icode) (op0, op1, op2);
5902 if (pat != 0)
5903 emit_insn (pat);
f18c054f 5904
3a9b8c7e
AH
5905 *expandedp = true;
5906 return NULL_RTX;
5907 }
f18c054f 5908
3a9b8c7e
AH
5909 return NULL_RTX;
5910}
24408032 5911
3a9b8c7e
AH
5912/* Expand the builtin in EXP and store the result in TARGET. Store
5913 true in *EXPANDEDP if we found a builtin to expand. */
5914static rtx
a2369ed3 5915altivec_expand_builtin (tree exp, rtx target, bool *expandedp)
3a9b8c7e
AH
5916{
5917 struct builtin_description *d;
5918 struct builtin_description_predicates *dp;
5919 size_t i;
5920 enum insn_code icode;
5921 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
5922 tree arglist = TREE_OPERAND (exp, 1);
7c3abc73
AH
5923 tree arg0;
5924 rtx op0, pat;
5925 enum machine_mode tmode, mode0;
3a9b8c7e 5926 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
0ac081f6 5927
3a9b8c7e
AH
5928 target = altivec_expand_ld_builtin (exp, target, expandedp);
5929 if (*expandedp)
5930 return target;
0ac081f6 5931
3a9b8c7e
AH
5932 target = altivec_expand_st_builtin (exp, target, expandedp);
5933 if (*expandedp)
5934 return target;
5935
5936 target = altivec_expand_dst_builtin (exp, target, expandedp);
5937 if (*expandedp)
5938 return target;
5939
5940 *expandedp = true;
95385cbb 5941
3a9b8c7e
AH
5942 switch (fcode)
5943 {
6525c0e7
AH
5944 case ALTIVEC_BUILTIN_STVX:
5945 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvx, arglist);
5946 case ALTIVEC_BUILTIN_STVEBX:
5947 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvebx, arglist);
5948 case ALTIVEC_BUILTIN_STVEHX:
5949 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvehx, arglist);
5950 case ALTIVEC_BUILTIN_STVEWX:
5951 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvewx, arglist);
5952 case ALTIVEC_BUILTIN_STVXL:
5953 return altivec_expand_stv_builtin (CODE_FOR_altivec_stvxl, arglist);
3a9b8c7e 5954
95385cbb
AH
5955 case ALTIVEC_BUILTIN_MFVSCR:
5956 icode = CODE_FOR_altivec_mfvscr;
5957 tmode = insn_data[icode].operand[0].mode;
5958
5959 if (target == 0
5960 || GET_MODE (target) != tmode
5961 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
5962 target = gen_reg_rtx (tmode);
5963
5964 pat = GEN_FCN (icode) (target);
0ac081f6
AH
5965 if (! pat)
5966 return 0;
5967 emit_insn (pat);
95385cbb
AH
5968 return target;
5969
5970 case ALTIVEC_BUILTIN_MTVSCR:
5971 icode = CODE_FOR_altivec_mtvscr;
5972 arg0 = TREE_VALUE (arglist);
5973 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5974 mode0 = insn_data[icode].operand[0].mode;
5975
5976 /* If we got invalid arguments bail out before generating bad rtl. */
5977 if (arg0 == error_mark_node)
9a171fcd 5978 return const0_rtx;
95385cbb
AH
5979
5980 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
5981 op0 = copy_to_mode_reg (mode0, op0);
5982
5983 pat = GEN_FCN (icode) (op0);
5984 if (pat)
5985 emit_insn (pat);
5986 return NULL_RTX;
3a9b8c7e 5987
95385cbb
AH
5988 case ALTIVEC_BUILTIN_DSSALL:
5989 emit_insn (gen_altivec_dssall ());
5990 return NULL_RTX;
5991
5992 case ALTIVEC_BUILTIN_DSS:
5993 icode = CODE_FOR_altivec_dss;
5994 arg0 = TREE_VALUE (arglist);
5995 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
5996 mode0 = insn_data[icode].operand[0].mode;
5997
5998 /* If we got invalid arguments bail out before generating bad rtl. */
5999 if (arg0 == error_mark_node)
9a171fcd 6000 return const0_rtx;
95385cbb 6001
b44140e7
AH
6002 if (TREE_CODE (arg0) != INTEGER_CST
6003 || TREE_INT_CST_LOW (arg0) & ~0x3)
6004 {
6005 error ("argument to dss must be a 2-bit unsigned literal");
9a171fcd 6006 return const0_rtx;
b44140e7
AH
6007 }
6008
95385cbb
AH
6009 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6010 op0 = copy_to_mode_reg (mode0, op0);
6011
6012 emit_insn (gen_altivec_dss (op0));
0ac081f6
AH
6013 return NULL_RTX;
6014 }
24408032 6015
100c4561
AH
6016 /* Expand abs* operations. */
6017 d = (struct builtin_description *) bdesc_abs;
ca7558fc 6018 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
100c4561
AH
6019 if (d->code == fcode)
6020 return altivec_expand_abs_builtin (d->icode, arglist, target);
6021
ae4b4a02
AH
6022 /* Expand the AltiVec predicates. */
6023 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
ca7558fc 6024 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
ae4b4a02
AH
6025 if (dp->code == fcode)
6026 return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
6027
6525c0e7
AH
6028 /* LV* are funky. We initialized them differently. */
6029 switch (fcode)
6030 {
6031 case ALTIVEC_BUILTIN_LVSL:
b4a62fa0 6032 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsl,
6525c0e7
AH
6033 arglist, target);
6034 case ALTIVEC_BUILTIN_LVSR:
b4a62fa0 6035 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvsr,
92898235 6036 arglist, target);
6525c0e7 6037 case ALTIVEC_BUILTIN_LVEBX:
b4a62fa0 6038 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvebx,
92898235 6039 arglist, target);
6525c0e7 6040 case ALTIVEC_BUILTIN_LVEHX:
b4a62fa0 6041 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvehx,
92898235 6042 arglist, target);
6525c0e7 6043 case ALTIVEC_BUILTIN_LVEWX:
b4a62fa0 6044 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvewx,
92898235 6045 arglist, target);
6525c0e7 6046 case ALTIVEC_BUILTIN_LVXL:
b4a62fa0 6047 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvxl,
92898235 6048 arglist, target);
6525c0e7 6049 case ALTIVEC_BUILTIN_LVX:
b4a62fa0 6050 return altivec_expand_lv_builtin (CODE_FOR_altivec_lvx,
92898235 6051 arglist, target);
6525c0e7
AH
6052 default:
6053 break;
6054 /* Fall through. */
6055 }
95385cbb 6056
92898235 6057 *expandedp = false;
0ac081f6
AH
6058 return NULL_RTX;
6059}
6060
a3170dc6
AH
6061/* Binops that need to be initialized manually, but can be expanded
6062 automagically by rs6000_expand_binop_builtin. */
6063static struct builtin_description bdesc_2arg_spe[] =
6064{
6065 { 0, CODE_FOR_spe_evlddx, "__builtin_spe_evlddx", SPE_BUILTIN_EVLDDX },
6066 { 0, CODE_FOR_spe_evldwx, "__builtin_spe_evldwx", SPE_BUILTIN_EVLDWX },
6067 { 0, CODE_FOR_spe_evldhx, "__builtin_spe_evldhx", SPE_BUILTIN_EVLDHX },
6068 { 0, CODE_FOR_spe_evlwhex, "__builtin_spe_evlwhex", SPE_BUILTIN_EVLWHEX },
6069 { 0, CODE_FOR_spe_evlwhoux, "__builtin_spe_evlwhoux", SPE_BUILTIN_EVLWHOUX },
6070 { 0, CODE_FOR_spe_evlwhosx, "__builtin_spe_evlwhosx", SPE_BUILTIN_EVLWHOSX },
6071 { 0, CODE_FOR_spe_evlwwsplatx, "__builtin_spe_evlwwsplatx", SPE_BUILTIN_EVLWWSPLATX },
6072 { 0, CODE_FOR_spe_evlwhsplatx, "__builtin_spe_evlwhsplatx", SPE_BUILTIN_EVLWHSPLATX },
6073 { 0, CODE_FOR_spe_evlhhesplatx, "__builtin_spe_evlhhesplatx", SPE_BUILTIN_EVLHHESPLATX },
6074 { 0, CODE_FOR_spe_evlhhousplatx, "__builtin_spe_evlhhousplatx", SPE_BUILTIN_EVLHHOUSPLATX },
6075 { 0, CODE_FOR_spe_evlhhossplatx, "__builtin_spe_evlhhossplatx", SPE_BUILTIN_EVLHHOSSPLATX },
6076 { 0, CODE_FOR_spe_evldd, "__builtin_spe_evldd", SPE_BUILTIN_EVLDD },
6077 { 0, CODE_FOR_spe_evldw, "__builtin_spe_evldw", SPE_BUILTIN_EVLDW },
6078 { 0, CODE_FOR_spe_evldh, "__builtin_spe_evldh", SPE_BUILTIN_EVLDH },
6079 { 0, CODE_FOR_spe_evlwhe, "__builtin_spe_evlwhe", SPE_BUILTIN_EVLWHE },
6080 { 0, CODE_FOR_spe_evlwhou, "__builtin_spe_evlwhou", SPE_BUILTIN_EVLWHOU },
6081 { 0, CODE_FOR_spe_evlwhos, "__builtin_spe_evlwhos", SPE_BUILTIN_EVLWHOS },
6082 { 0, CODE_FOR_spe_evlwwsplat, "__builtin_spe_evlwwsplat", SPE_BUILTIN_EVLWWSPLAT },
6083 { 0, CODE_FOR_spe_evlwhsplat, "__builtin_spe_evlwhsplat", SPE_BUILTIN_EVLWHSPLAT },
6084 { 0, CODE_FOR_spe_evlhhesplat, "__builtin_spe_evlhhesplat", SPE_BUILTIN_EVLHHESPLAT },
6085 { 0, CODE_FOR_spe_evlhhousplat, "__builtin_spe_evlhhousplat", SPE_BUILTIN_EVLHHOUSPLAT },
6086 { 0, CODE_FOR_spe_evlhhossplat, "__builtin_spe_evlhhossplat", SPE_BUILTIN_EVLHHOSSPLAT }
6087};
6088
6089/* Expand the builtin in EXP and store the result in TARGET. Store
6090 true in *EXPANDEDP if we found a builtin to expand.
6091
6092 This expands the SPE builtins that are not simple unary and binary
6093 operations. */
6094static rtx
a2369ed3 6095spe_expand_builtin (tree exp, rtx target, bool *expandedp)
a3170dc6
AH
6096{
6097 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6098 tree arglist = TREE_OPERAND (exp, 1);
6099 tree arg1, arg0;
6100 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6101 enum insn_code icode;
6102 enum machine_mode tmode, mode0;
6103 rtx pat, op0;
6104 struct builtin_description *d;
6105 size_t i;
6106
6107 *expandedp = true;
6108
6109 /* Syntax check for a 5-bit unsigned immediate. */
6110 switch (fcode)
6111 {
6112 case SPE_BUILTIN_EVSTDD:
6113 case SPE_BUILTIN_EVSTDH:
6114 case SPE_BUILTIN_EVSTDW:
6115 case SPE_BUILTIN_EVSTWHE:
6116 case SPE_BUILTIN_EVSTWHO:
6117 case SPE_BUILTIN_EVSTWWE:
6118 case SPE_BUILTIN_EVSTWWO:
6119 arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6120 if (TREE_CODE (arg1) != INTEGER_CST
6121 || TREE_INT_CST_LOW (arg1) & ~0x1f)
6122 {
6123 error ("argument 2 must be a 5-bit unsigned literal");
6124 return const0_rtx;
6125 }
6126 break;
6127 default:
6128 break;
6129 }
6130
00332c9f
AH
6131 /* The evsplat*i instructions are not quite generic. */
6132 switch (fcode)
6133 {
6134 case SPE_BUILTIN_EVSPLATFI:
6135 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplatfi,
6136 arglist, target);
6137 case SPE_BUILTIN_EVSPLATI:
6138 return rs6000_expand_unop_builtin (CODE_FOR_spe_evsplati,
6139 arglist, target);
6140 default:
6141 break;
6142 }
6143
a3170dc6
AH
6144 d = (struct builtin_description *) bdesc_2arg_spe;
6145 for (i = 0; i < ARRAY_SIZE (bdesc_2arg_spe); ++i, ++d)
6146 if (d->code == fcode)
6147 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6148
6149 d = (struct builtin_description *) bdesc_spe_predicates;
6150 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, ++d)
6151 if (d->code == fcode)
6152 return spe_expand_predicate_builtin (d->icode, arglist, target);
6153
6154 d = (struct builtin_description *) bdesc_spe_evsel;
6155 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, ++d)
6156 if (d->code == fcode)
6157 return spe_expand_evsel_builtin (d->icode, arglist, target);
6158
6159 switch (fcode)
6160 {
6161 case SPE_BUILTIN_EVSTDDX:
6162 return altivec_expand_stv_builtin (CODE_FOR_spe_evstddx, arglist);
6163 case SPE_BUILTIN_EVSTDHX:
6164 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdhx, arglist);
6165 case SPE_BUILTIN_EVSTDWX:
6166 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdwx, arglist);
6167 case SPE_BUILTIN_EVSTWHEX:
6168 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhex, arglist);
6169 case SPE_BUILTIN_EVSTWHOX:
6170 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhox, arglist);
6171 case SPE_BUILTIN_EVSTWWEX:
6172 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwex, arglist);
6173 case SPE_BUILTIN_EVSTWWOX:
6174 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwox, arglist);
6175 case SPE_BUILTIN_EVSTDD:
6176 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdd, arglist);
6177 case SPE_BUILTIN_EVSTDH:
6178 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdh, arglist);
6179 case SPE_BUILTIN_EVSTDW:
6180 return altivec_expand_stv_builtin (CODE_FOR_spe_evstdw, arglist);
6181 case SPE_BUILTIN_EVSTWHE:
6182 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwhe, arglist);
6183 case SPE_BUILTIN_EVSTWHO:
6184 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwho, arglist);
6185 case SPE_BUILTIN_EVSTWWE:
6186 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwe, arglist);
6187 case SPE_BUILTIN_EVSTWWO:
6188 return altivec_expand_stv_builtin (CODE_FOR_spe_evstwwo, arglist);
6189 case SPE_BUILTIN_MFSPEFSCR:
6190 icode = CODE_FOR_spe_mfspefscr;
6191 tmode = insn_data[icode].operand[0].mode;
6192
6193 if (target == 0
6194 || GET_MODE (target) != tmode
6195 || ! (*insn_data[icode].operand[0].predicate) (target, tmode))
6196 target = gen_reg_rtx (tmode);
6197
6198 pat = GEN_FCN (icode) (target);
6199 if (! pat)
6200 return 0;
6201 emit_insn (pat);
6202 return target;
6203 case SPE_BUILTIN_MTSPEFSCR:
6204 icode = CODE_FOR_spe_mtspefscr;
6205 arg0 = TREE_VALUE (arglist);
6206 op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6207 mode0 = insn_data[icode].operand[0].mode;
6208
6209 if (arg0 == error_mark_node)
6210 return const0_rtx;
6211
6212 if (! (*insn_data[icode].operand[0].predicate) (op0, mode0))
6213 op0 = copy_to_mode_reg (mode0, op0);
6214
6215 pat = GEN_FCN (icode) (op0);
6216 if (pat)
6217 emit_insn (pat);
6218 return NULL_RTX;
6219 default:
6220 break;
6221 }
6222
6223 *expandedp = false;
6224 return NULL_RTX;
6225}
6226
6227static rtx
a2369ed3 6228spe_expand_predicate_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6229{
6230 rtx pat, scratch, tmp;
6231 tree form = TREE_VALUE (arglist);
6232 tree arg0 = TREE_VALUE (TREE_CHAIN (arglist));
6233 tree arg1 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6234 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6235 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6236 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6237 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6238 int form_int;
6239 enum rtx_code code;
6240
6241 if (TREE_CODE (form) != INTEGER_CST)
6242 {
6243 error ("argument 1 of __builtin_spe_predicate must be a constant");
6244 return const0_rtx;
6245 }
6246 else
6247 form_int = TREE_INT_CST_LOW (form);
6248
6249 if (mode0 != mode1)
6250 abort ();
6251
6252 if (arg0 == error_mark_node || arg1 == error_mark_node)
6253 return const0_rtx;
6254
6255 if (target == 0
6256 || GET_MODE (target) != SImode
6257 || ! (*insn_data[icode].operand[0].predicate) (target, SImode))
6258 target = gen_reg_rtx (SImode);
6259
6260 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6261 op0 = copy_to_mode_reg (mode0, op0);
6262 if (! (*insn_data[icode].operand[2].predicate) (op1, mode1))
6263 op1 = copy_to_mode_reg (mode1, op1);
6264
6265 scratch = gen_reg_rtx (CCmode);
6266
6267 pat = GEN_FCN (icode) (scratch, op0, op1);
6268 if (! pat)
6269 return const0_rtx;
6270 emit_insn (pat);
6271
6272 /* There are 4 variants for each predicate: _any_, _all_, _upper_,
6273 _lower_. We use one compare, but look in different bits of the
6274 CR for each variant.
6275
6276 There are 2 elements in each SPE simd type (upper/lower). The CR
6277 bits are set as follows:
6278
6279 BIT0 | BIT 1 | BIT 2 | BIT 3
6280 U | L | (U | L) | (U & L)
6281
6282 So, for an "all" relationship, BIT 3 would be set.
6283 For an "any" relationship, BIT 2 would be set. Etc.
6284
6285 Following traditional nomenclature, these bits map to:
6286
6287 BIT0 | BIT 1 | BIT 2 | BIT 3
6288 LT | GT | EQ | OV
6289
6290 Later, we will generate rtl to look in the LT/EQ/EQ/OV bits.
6291 */
6292
6293 switch (form_int)
6294 {
6295 /* All variant. OV bit. */
6296 case 0:
6297 /* We need to get to the OV bit, which is the ORDERED bit. We
6298 could generate (ordered:SI (reg:CC xx) (const_int 0)), but
6299 that's ugly and will trigger a validate_condition_mode abort.
6300 So let's just use another pattern. */
6301 emit_insn (gen_move_from_CR_ov_bit (target, scratch));
6302 return target;
6303 /* Any variant. EQ bit. */
6304 case 1:
6305 code = EQ;
6306 break;
6307 /* Upper variant. LT bit. */
6308 case 2:
6309 code = LT;
6310 break;
6311 /* Lower variant. GT bit. */
6312 case 3:
6313 code = GT;
6314 break;
6315 default:
6316 error ("argument 1 of __builtin_spe_predicate is out of range");
6317 return const0_rtx;
6318 }
6319
6320 tmp = gen_rtx_fmt_ee (code, SImode, scratch, const0_rtx);
6321 emit_move_insn (target, tmp);
6322
6323 return target;
6324}
6325
6326/* The evsel builtins look like this:
6327
6328 e = __builtin_spe_evsel_OP (a, b, c, d);
6329
6330 and work like this:
6331
6332 e[upper] = a[upper] *OP* b[upper] ? c[upper] : d[upper];
6333 e[lower] = a[lower] *OP* b[lower] ? c[lower] : d[lower];
6334*/
6335
6336static rtx
a2369ed3 6337spe_expand_evsel_builtin (enum insn_code icode, tree arglist, rtx target)
a3170dc6
AH
6338{
6339 rtx pat, scratch;
6340 tree arg0 = TREE_VALUE (arglist);
6341 tree arg1 = TREE_VALUE (TREE_CHAIN (arglist));
6342 tree arg2 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (arglist)));
6343 tree arg3 = TREE_VALUE (TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (arglist))));
6344 rtx op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0);
6345 rtx op1 = expand_expr (arg1, NULL_RTX, VOIDmode, 0);
6346 rtx op2 = expand_expr (arg2, NULL_RTX, VOIDmode, 0);
6347 rtx op3 = expand_expr (arg3, NULL_RTX, VOIDmode, 0);
6348 enum machine_mode mode0 = insn_data[icode].operand[1].mode;
6349 enum machine_mode mode1 = insn_data[icode].operand[2].mode;
6350
6351 if (mode0 != mode1)
6352 abort ();
6353
6354 if (arg0 == error_mark_node || arg1 == error_mark_node
6355 || arg2 == error_mark_node || arg3 == error_mark_node)
6356 return const0_rtx;
6357
6358 if (target == 0
6359 || GET_MODE (target) != mode0
6360 || ! (*insn_data[icode].operand[0].predicate) (target, mode0))
6361 target = gen_reg_rtx (mode0);
6362
6363 if (! (*insn_data[icode].operand[1].predicate) (op0, mode0))
6364 op0 = copy_to_mode_reg (mode0, op0);
6365 if (! (*insn_data[icode].operand[1].predicate) (op1, mode1))
6366 op1 = copy_to_mode_reg (mode0, op1);
6367 if (! (*insn_data[icode].operand[1].predicate) (op2, mode1))
6368 op2 = copy_to_mode_reg (mode0, op2);
6369 if (! (*insn_data[icode].operand[1].predicate) (op3, mode1))
6370 op3 = copy_to_mode_reg (mode0, op3);
6371
6372 /* Generate the compare. */
6373 scratch = gen_reg_rtx (CCmode);
6374 pat = GEN_FCN (icode) (scratch, op0, op1);
6375 if (! pat)
6376 return const0_rtx;
6377 emit_insn (pat);
6378
6379 if (mode0 == V2SImode)
6380 emit_insn (gen_spe_evsel (target, op2, op3, scratch));
6381 else
6382 emit_insn (gen_spe_evsel_fs (target, op2, op3, scratch));
6383
6384 return target;
6385}
6386
0ac081f6
AH
6387/* Expand an expression EXP that calls a built-in function,
6388 with result going to TARGET if that's convenient
6389 (and in mode MODE if that's convenient).
6390 SUBTARGET may be used as the target for computing one of EXP's operands.
6391 IGNORE is nonzero if the value is to be ignored. */
6392
6393static rtx
a2369ed3
DJ
6394rs6000_expand_builtin (tree exp, rtx target, rtx subtarget ATTRIBUTE_UNUSED,
6395 enum machine_mode mode ATTRIBUTE_UNUSED,
6396 int ignore ATTRIBUTE_UNUSED)
0ac081f6 6397{
92898235
AH
6398 tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
6399 tree arglist = TREE_OPERAND (exp, 1);
6400 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
6401 struct builtin_description *d;
6402 size_t i;
6403 rtx ret;
6404 bool success;
6405
0ac081f6 6406 if (TARGET_ALTIVEC)
92898235
AH
6407 {
6408 ret = altivec_expand_builtin (exp, target, &success);
6409
a3170dc6
AH
6410 if (success)
6411 return ret;
6412 }
6413 if (TARGET_SPE)
6414 {
6415 ret = spe_expand_builtin (exp, target, &success);
6416
92898235
AH
6417 if (success)
6418 return ret;
6419 }
6420
0559cc77
DE
6421 if (TARGET_ALTIVEC || TARGET_SPE)
6422 {
6423 /* Handle simple unary operations. */
6424 d = (struct builtin_description *) bdesc_1arg;
6425 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
6426 if (d->code == fcode)
6427 return rs6000_expand_unop_builtin (d->icode, arglist, target);
6428
6429 /* Handle simple binary operations. */
6430 d = (struct builtin_description *) bdesc_2arg;
6431 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
6432 if (d->code == fcode)
6433 return rs6000_expand_binop_builtin (d->icode, arglist, target);
6434
6435 /* Handle simple ternary operations. */
6436 d = (struct builtin_description *) bdesc_3arg;
6437 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
6438 if (d->code == fcode)
6439 return rs6000_expand_ternop_builtin (d->icode, arglist, target);
6440 }
0ac081f6
AH
6441
6442 abort ();
92898235 6443 return NULL_RTX;
0ac081f6
AH
6444}
6445
6446static void
863d938c 6447rs6000_init_builtins (void)
0ac081f6 6448{
3fdaa45a
AH
6449 opaque_V2SI_type_node = copy_node (V2SI_type_node);
6450 opaque_V2SF_type_node = copy_node (V2SF_type_node);
6035d635 6451 opaque_p_V2SI_type_node = build_pointer_type (opaque_V2SI_type_node);
3fdaa45a 6452
a3170dc6 6453 if (TARGET_SPE)
3fdaa45a 6454 spe_init_builtins ();
0ac081f6
AH
6455 if (TARGET_ALTIVEC)
6456 altivec_init_builtins ();
0559cc77
DE
6457 if (TARGET_ALTIVEC || TARGET_SPE)
6458 rs6000_common_init_builtins ();
0ac081f6
AH
6459}
6460
a3170dc6
AH
6461/* Search through a set of builtins and enable the mask bits.
6462 DESC is an array of builtins.
b6d08ca1 6463 SIZE is the total number of builtins.
a3170dc6
AH
6464 START is the builtin enum at which to start.
6465 END is the builtin enum at which to end. */
0ac081f6 6466static void
a2369ed3
DJ
6467enable_mask_for_builtins (struct builtin_description *desc, int size,
6468 enum rs6000_builtins start,
6469 enum rs6000_builtins end)
a3170dc6
AH
6470{
6471 int i;
6472
6473 for (i = 0; i < size; ++i)
6474 if (desc[i].code == start)
6475 break;
6476
6477 if (i == size)
6478 return;
6479
6480 for (; i < size; ++i)
6481 {
6482 /* Flip all the bits on. */
6483 desc[i].mask = target_flags;
6484 if (desc[i].code == end)
6485 break;
6486 }
6487}
6488
6489static void
863d938c 6490spe_init_builtins (void)
0ac081f6 6491{
a3170dc6
AH
6492 tree endlink = void_list_node;
6493 tree puint_type_node = build_pointer_type (unsigned_type_node);
6494 tree pushort_type_node = build_pointer_type (short_unsigned_type_node);
ae4b4a02 6495 struct builtin_description *d;
0ac081f6
AH
6496 size_t i;
6497
a3170dc6
AH
6498 tree v2si_ftype_4_v2si
6499 = build_function_type
3fdaa45a
AH
6500 (opaque_V2SI_type_node,
6501 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6502 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6503 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6504 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6505 endlink)))));
6506
6507 tree v2sf_ftype_4_v2sf
6508 = build_function_type
3fdaa45a
AH
6509 (opaque_V2SF_type_node,
6510 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6511 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6512 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6513 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6514 endlink)))));
6515
6516 tree int_ftype_int_v2si_v2si
6517 = build_function_type
6518 (integer_type_node,
6519 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6520 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6521 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6522 endlink))));
6523
6524 tree int_ftype_int_v2sf_v2sf
6525 = build_function_type
6526 (integer_type_node,
6527 tree_cons (NULL_TREE, integer_type_node,
3fdaa45a
AH
6528 tree_cons (NULL_TREE, opaque_V2SF_type_node,
6529 tree_cons (NULL_TREE, opaque_V2SF_type_node,
a3170dc6
AH
6530 endlink))));
6531
6532 tree void_ftype_v2si_puint_int
6533 = build_function_type (void_type_node,
3fdaa45a 6534 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6535 tree_cons (NULL_TREE, puint_type_node,
6536 tree_cons (NULL_TREE,
6537 integer_type_node,
6538 endlink))));
6539
6540 tree void_ftype_v2si_puint_char
6541 = build_function_type (void_type_node,
3fdaa45a 6542 tree_cons (NULL_TREE, opaque_V2SI_type_node,
a3170dc6
AH
6543 tree_cons (NULL_TREE, puint_type_node,
6544 tree_cons (NULL_TREE,
6545 char_type_node,
6546 endlink))));
6547
6548 tree void_ftype_v2si_pv2si_int
6549 = build_function_type (void_type_node,
3fdaa45a 6550 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6551 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6552 tree_cons (NULL_TREE,
6553 integer_type_node,
6554 endlink))));
6555
6556 tree void_ftype_v2si_pv2si_char
6557 = build_function_type (void_type_node,
3fdaa45a 6558 tree_cons (NULL_TREE, opaque_V2SI_type_node,
6035d635 6559 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6560 tree_cons (NULL_TREE,
6561 char_type_node,
6562 endlink))));
6563
6564 tree void_ftype_int
6565 = build_function_type (void_type_node,
6566 tree_cons (NULL_TREE, integer_type_node, endlink));
6567
6568 tree int_ftype_void
36e8d515 6569 = build_function_type (integer_type_node, endlink);
a3170dc6
AH
6570
6571 tree v2si_ftype_pv2si_int
3fdaa45a 6572 = build_function_type (opaque_V2SI_type_node,
6035d635 6573 tree_cons (NULL_TREE, opaque_p_V2SI_type_node,
a3170dc6
AH
6574 tree_cons (NULL_TREE, integer_type_node,
6575 endlink)));
6576
6577 tree v2si_ftype_puint_int
3fdaa45a 6578 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6579 tree_cons (NULL_TREE, puint_type_node,
6580 tree_cons (NULL_TREE, integer_type_node,
6581 endlink)));
6582
6583 tree v2si_ftype_pushort_int
3fdaa45a 6584 = build_function_type (opaque_V2SI_type_node,
a3170dc6
AH
6585 tree_cons (NULL_TREE, pushort_type_node,
6586 tree_cons (NULL_TREE, integer_type_node,
6587 endlink)));
6588
00332c9f
AH
6589 tree v2si_ftype_signed_char
6590 = build_function_type (opaque_V2SI_type_node,
6591 tree_cons (NULL_TREE, signed_char_type_node,
6592 endlink));
6593
a3170dc6
AH
6594 /* The initialization of the simple binary and unary builtins is
6595 done in rs6000_common_init_builtins, but we have to enable the
6596 mask bits here manually because we have run out of `target_flags'
6597 bits. We really need to redesign this mask business. */
6598
6599 enable_mask_for_builtins ((struct builtin_description *) bdesc_2arg,
6600 ARRAY_SIZE (bdesc_2arg),
6601 SPE_BUILTIN_EVADDW,
6602 SPE_BUILTIN_EVXOR);
6603 enable_mask_for_builtins ((struct builtin_description *) bdesc_1arg,
6604 ARRAY_SIZE (bdesc_1arg),
6605 SPE_BUILTIN_EVABS,
6606 SPE_BUILTIN_EVSUBFUSIAAW);
6607 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_predicates,
6608 ARRAY_SIZE (bdesc_spe_predicates),
6609 SPE_BUILTIN_EVCMPEQ,
6610 SPE_BUILTIN_EVFSTSTLT);
6611 enable_mask_for_builtins ((struct builtin_description *) bdesc_spe_evsel,
6612 ARRAY_SIZE (bdesc_spe_evsel),
6613 SPE_BUILTIN_EVSEL_CMPGTS,
6614 SPE_BUILTIN_EVSEL_FSTSTEQ);
6615
36252949
AH
6616 (*lang_hooks.decls.pushdecl)
6617 (build_decl (TYPE_DECL, get_identifier ("__ev64_opaque__"),
6618 opaque_V2SI_type_node));
6619
a3170dc6
AH
6620 /* Initialize irregular SPE builtins. */
6621
6622 def_builtin (target_flags, "__builtin_spe_mtspefscr", void_ftype_int, SPE_BUILTIN_MTSPEFSCR);
6623 def_builtin (target_flags, "__builtin_spe_mfspefscr", int_ftype_void, SPE_BUILTIN_MFSPEFSCR);
6624 def_builtin (target_flags, "__builtin_spe_evstddx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDDX);
6625 def_builtin (target_flags, "__builtin_spe_evstdhx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDHX);
6626 def_builtin (target_flags, "__builtin_spe_evstdwx", void_ftype_v2si_pv2si_int, SPE_BUILTIN_EVSTDWX);
6627 def_builtin (target_flags, "__builtin_spe_evstwhex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHEX);
6628 def_builtin (target_flags, "__builtin_spe_evstwhox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWHOX);
6629 def_builtin (target_flags, "__builtin_spe_evstwwex", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWEX);
6630 def_builtin (target_flags, "__builtin_spe_evstwwox", void_ftype_v2si_puint_int, SPE_BUILTIN_EVSTWWOX);
6631 def_builtin (target_flags, "__builtin_spe_evstdd", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDD);
6632 def_builtin (target_flags, "__builtin_spe_evstdh", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDH);
6633 def_builtin (target_flags, "__builtin_spe_evstdw", void_ftype_v2si_pv2si_char, SPE_BUILTIN_EVSTDW);
6634 def_builtin (target_flags, "__builtin_spe_evstwhe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHE);
6635 def_builtin (target_flags, "__builtin_spe_evstwho", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWHO);
6636 def_builtin (target_flags, "__builtin_spe_evstwwe", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWE);
6637 def_builtin (target_flags, "__builtin_spe_evstwwo", void_ftype_v2si_puint_char, SPE_BUILTIN_EVSTWWO);
00332c9f
AH
6638 def_builtin (target_flags, "__builtin_spe_evsplatfi", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATFI);
6639 def_builtin (target_flags, "__builtin_spe_evsplati", v2si_ftype_signed_char, SPE_BUILTIN_EVSPLATI);
a3170dc6
AH
6640
6641 /* Loads. */
6642 def_builtin (target_flags, "__builtin_spe_evlddx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDDX);
6643 def_builtin (target_flags, "__builtin_spe_evldwx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDWX);
6644 def_builtin (target_flags, "__builtin_spe_evldhx", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDHX);
6645 def_builtin (target_flags, "__builtin_spe_evlwhex", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHEX);
6646 def_builtin (target_flags, "__builtin_spe_evlwhoux", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOUX);
6647 def_builtin (target_flags, "__builtin_spe_evlwhosx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOSX);
6648 def_builtin (target_flags, "__builtin_spe_evlwwsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLATX);
6649 def_builtin (target_flags, "__builtin_spe_evlwhsplatx", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLATX);
6650 def_builtin (target_flags, "__builtin_spe_evlhhesplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLATX);
6651 def_builtin (target_flags, "__builtin_spe_evlhhousplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLATX);
6652 def_builtin (target_flags, "__builtin_spe_evlhhossplatx", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLATX);
6653 def_builtin (target_flags, "__builtin_spe_evldd", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDD);
6654 def_builtin (target_flags, "__builtin_spe_evldw", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDW);
6655 def_builtin (target_flags, "__builtin_spe_evldh", v2si_ftype_pv2si_int, SPE_BUILTIN_EVLDH);
6656 def_builtin (target_flags, "__builtin_spe_evlhhesplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHESPLAT);
6657 def_builtin (target_flags, "__builtin_spe_evlhhossplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOSSPLAT);
6658 def_builtin (target_flags, "__builtin_spe_evlhhousplat", v2si_ftype_pushort_int, SPE_BUILTIN_EVLHHOUSPLAT);
6659 def_builtin (target_flags, "__builtin_spe_evlwhe", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHE);
6660 def_builtin (target_flags, "__builtin_spe_evlwhos", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOS);
6661 def_builtin (target_flags, "__builtin_spe_evlwhou", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHOU);
6662 def_builtin (target_flags, "__builtin_spe_evlwhsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWHSPLAT);
6663 def_builtin (target_flags, "__builtin_spe_evlwwsplat", v2si_ftype_puint_int, SPE_BUILTIN_EVLWWSPLAT);
6664
6665 /* Predicates. */
6666 d = (struct builtin_description *) bdesc_spe_predicates;
6667 for (i = 0; i < ARRAY_SIZE (bdesc_spe_predicates); ++i, d++)
6668 {
6669 tree type;
6670
6671 switch (insn_data[d->icode].operand[1].mode)
6672 {
6673 case V2SImode:
6674 type = int_ftype_int_v2si_v2si;
6675 break;
6676 case V2SFmode:
6677 type = int_ftype_int_v2sf_v2sf;
6678 break;
6679 default:
6680 abort ();
6681 }
6682
6683 def_builtin (d->mask, d->name, type, d->code);
6684 }
6685
6686 /* Evsel predicates. */
6687 d = (struct builtin_description *) bdesc_spe_evsel;
6688 for (i = 0; i < ARRAY_SIZE (bdesc_spe_evsel); ++i, d++)
6689 {
6690 tree type;
6691
6692 switch (insn_data[d->icode].operand[1].mode)
6693 {
6694 case V2SImode:
6695 type = v2si_ftype_4_v2si;
6696 break;
6697 case V2SFmode:
6698 type = v2sf_ftype_4_v2sf;
6699 break;
6700 default:
6701 abort ();
6702 }
6703
6704 def_builtin (d->mask, d->name, type, d->code);
6705 }
6706}
6707
6708static void
863d938c 6709altivec_init_builtins (void)
a3170dc6
AH
6710{
6711 struct builtin_description *d;
6712 struct builtin_description_predicates *dp;
6713 size_t i;
6714 tree pfloat_type_node = build_pointer_type (float_type_node);
6715 tree pint_type_node = build_pointer_type (integer_type_node);
6716 tree pshort_type_node = build_pointer_type (short_integer_type_node);
6717 tree pchar_type_node = build_pointer_type (char_type_node);
6718
6719 tree pvoid_type_node = build_pointer_type (void_type_node);
6720
0dbc3651
ZW
6721 tree pcfloat_type_node = build_pointer_type (build_qualified_type (float_type_node, TYPE_QUAL_CONST));
6722 tree pcint_type_node = build_pointer_type (build_qualified_type (integer_type_node, TYPE_QUAL_CONST));
6723 tree pcshort_type_node = build_pointer_type (build_qualified_type (short_integer_type_node, TYPE_QUAL_CONST));
6724 tree pcchar_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST));
6725
6726 tree pcvoid_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST));
6727
a3170dc6
AH
6728 tree int_ftype_int_v4si_v4si
6729 = build_function_type_list (integer_type_node,
6730 integer_type_node, V4SI_type_node,
6731 V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6732 tree v4sf_ftype_pcfloat
6733 = build_function_type_list (V4SF_type_node, pcfloat_type_node, NULL_TREE);
a3170dc6 6734 tree void_ftype_pfloat_v4sf
b4de2f7d 6735 = build_function_type_list (void_type_node,
a3170dc6 6736 pfloat_type_node, V4SF_type_node, NULL_TREE);
0dbc3651
ZW
6737 tree v4si_ftype_pcint
6738 = build_function_type_list (V4SI_type_node, pcint_type_node, NULL_TREE);
6739 tree void_ftype_pint_v4si
b4de2f7d
AH
6740 = build_function_type_list (void_type_node,
6741 pint_type_node, V4SI_type_node, NULL_TREE);
0dbc3651
ZW
6742 tree v8hi_ftype_pcshort
6743 = build_function_type_list (V8HI_type_node, pcshort_type_node, NULL_TREE);
f18c054f 6744 tree void_ftype_pshort_v8hi
b4de2f7d
AH
6745 = build_function_type_list (void_type_node,
6746 pshort_type_node, V8HI_type_node, NULL_TREE);
0dbc3651
ZW
6747 tree v16qi_ftype_pcchar
6748 = build_function_type_list (V16QI_type_node, pcchar_type_node, NULL_TREE);
f18c054f 6749 tree void_ftype_pchar_v16qi
b4de2f7d
AH
6750 = build_function_type_list (void_type_node,
6751 pchar_type_node, V16QI_type_node, NULL_TREE);
95385cbb 6752 tree void_ftype_v4si
b4de2f7d 6753 = build_function_type_list (void_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
6754 tree v8hi_ftype_void
6755 = build_function_type (V8HI_type_node, void_list_node);
6756 tree void_ftype_void
6757 = build_function_type (void_type_node, void_list_node);
6758 tree void_ftype_qi
6759 = build_function_type_list (void_type_node, char_type_node, NULL_TREE);
0dbc3651 6760
b4a62fa0 6761 tree v16qi_ftype_long_pcvoid
a3170dc6 6762 = build_function_type_list (V16QI_type_node,
b4a62fa0
SB
6763 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6764 tree v8hi_ftype_long_pcvoid
a3170dc6 6765 = build_function_type_list (V8HI_type_node,
b4a62fa0
SB
6766 long_integer_type_node, pcvoid_type_node, NULL_TREE);
6767 tree v4si_ftype_long_pcvoid
a3170dc6 6768 = build_function_type_list (V4SI_type_node,
b4a62fa0 6769 long_integer_type_node, pcvoid_type_node, NULL_TREE);
0dbc3651 6770
b4a62fa0 6771 tree void_ftype_v4si_long_pvoid
b4de2f7d 6772 = build_function_type_list (void_type_node,
b4a62fa0 6773 V4SI_type_node, long_integer_type_node,
b4de2f7d 6774 pvoid_type_node, NULL_TREE);
b4a62fa0 6775 tree void_ftype_v16qi_long_pvoid
b4de2f7d 6776 = build_function_type_list (void_type_node,
b4a62fa0 6777 V16QI_type_node, long_integer_type_node,
b4de2f7d 6778 pvoid_type_node, NULL_TREE);
b4a62fa0 6779 tree void_ftype_v8hi_long_pvoid
b4de2f7d 6780 = build_function_type_list (void_type_node,
b4a62fa0 6781 V8HI_type_node, long_integer_type_node,
b4de2f7d 6782 pvoid_type_node, NULL_TREE);
a3170dc6
AH
6783 tree int_ftype_int_v8hi_v8hi
6784 = build_function_type_list (integer_type_node,
6785 integer_type_node, V8HI_type_node,
6786 V8HI_type_node, NULL_TREE);
6787 tree int_ftype_int_v16qi_v16qi
6788 = build_function_type_list (integer_type_node,
6789 integer_type_node, V16QI_type_node,
6790 V16QI_type_node, NULL_TREE);
6791 tree int_ftype_int_v4sf_v4sf
6792 = build_function_type_list (integer_type_node,
6793 integer_type_node, V4SF_type_node,
6794 V4SF_type_node, NULL_TREE);
6795 tree v4si_ftype_v4si
6796 = build_function_type_list (V4SI_type_node, V4SI_type_node, NULL_TREE);
6797 tree v8hi_ftype_v8hi
6798 = build_function_type_list (V8HI_type_node, V8HI_type_node, NULL_TREE);
6799 tree v16qi_ftype_v16qi
6800 = build_function_type_list (V16QI_type_node, V16QI_type_node, NULL_TREE);
6801 tree v4sf_ftype_v4sf
6802 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
0dbc3651 6803 tree void_ftype_pcvoid_int_char
a3170dc6 6804 = build_function_type_list (void_type_node,
0dbc3651 6805 pcvoid_type_node, integer_type_node,
a3170dc6 6806 char_type_node, NULL_TREE);
0dbc3651
ZW
6807
6808 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4sf", v4sf_ftype_pcfloat,
6809 ALTIVEC_BUILTIN_LD_INTERNAL_4sf);
6810 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4sf", void_ftype_pfloat_v4sf,
6811 ALTIVEC_BUILTIN_ST_INTERNAL_4sf);
6812 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_4si", v4si_ftype_pcint,
6813 ALTIVEC_BUILTIN_LD_INTERNAL_4si);
6814 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_4si", void_ftype_pint_v4si,
6815 ALTIVEC_BUILTIN_ST_INTERNAL_4si);
6816 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_8hi", v8hi_ftype_pcshort,
6817 ALTIVEC_BUILTIN_LD_INTERNAL_8hi);
6818 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_8hi", void_ftype_pshort_v8hi,
6819 ALTIVEC_BUILTIN_ST_INTERNAL_8hi);
6820 def_builtin (MASK_ALTIVEC, "__builtin_altivec_ld_internal_16qi", v16qi_ftype_pcchar,
6821 ALTIVEC_BUILTIN_LD_INTERNAL_16qi);
6822 def_builtin (MASK_ALTIVEC, "__builtin_altivec_st_internal_16qi", void_ftype_pchar_v16qi,
6823 ALTIVEC_BUILTIN_ST_INTERNAL_16qi);
a3170dc6
AH
6824 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mtvscr", void_ftype_v4si, ALTIVEC_BUILTIN_MTVSCR);
6825 def_builtin (MASK_ALTIVEC, "__builtin_altivec_mfvscr", v8hi_ftype_void, ALTIVEC_BUILTIN_MFVSCR);
6826 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dssall", void_ftype_void, ALTIVEC_BUILTIN_DSSALL);
6827 def_builtin (MASK_ALTIVEC, "__builtin_altivec_dss", void_ftype_qi, ALTIVEC_BUILTIN_DSS);
b4a62fa0
SB
6828 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsl", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSL);
6829 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvsr", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVSR);
6830 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvebx", v16qi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEBX);
6831 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvehx", v8hi_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEHX);
6832 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvewx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVEWX);
6833 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvxl", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVXL);
6834 def_builtin (MASK_ALTIVEC, "__builtin_altivec_lvx", v4si_ftype_long_pcvoid, ALTIVEC_BUILTIN_LVX);
6835 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVX);
6836 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvewx", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVEWX);
6837 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvxl", void_ftype_v4si_long_pvoid, ALTIVEC_BUILTIN_STVXL);
6838 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvebx", void_ftype_v16qi_long_pvoid, ALTIVEC_BUILTIN_STVEBX);
6839 def_builtin (MASK_ALTIVEC, "__builtin_altivec_stvehx", void_ftype_v8hi_long_pvoid, ALTIVEC_BUILTIN_STVEHX);
a3170dc6
AH
6840
6841 /* Add the DST variants. */
6842 d = (struct builtin_description *) bdesc_dst;
6843 for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
0dbc3651 6844 def_builtin (d->mask, d->name, void_ftype_pcvoid_int_char, d->code);
a3170dc6
AH
6845
6846 /* Initialize the predicates. */
6847 dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
6848 for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
6849 {
6850 enum machine_mode mode1;
6851 tree type;
6852
6853 mode1 = insn_data[dp->icode].operand[1].mode;
6854
6855 switch (mode1)
6856 {
6857 case V4SImode:
6858 type = int_ftype_int_v4si_v4si;
6859 break;
6860 case V8HImode:
6861 type = int_ftype_int_v8hi_v8hi;
6862 break;
6863 case V16QImode:
6864 type = int_ftype_int_v16qi_v16qi;
6865 break;
6866 case V4SFmode:
6867 type = int_ftype_int_v4sf_v4sf;
6868 break;
6869 default:
6870 abort ();
6871 }
6872
6873 def_builtin (dp->mask, dp->name, type, dp->code);
6874 }
6875
6876 /* Initialize the abs* operators. */
6877 d = (struct builtin_description *) bdesc_abs;
6878 for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
6879 {
6880 enum machine_mode mode0;
6881 tree type;
6882
6883 mode0 = insn_data[d->icode].operand[0].mode;
6884
6885 switch (mode0)
6886 {
6887 case V4SImode:
6888 type = v4si_ftype_v4si;
6889 break;
6890 case V8HImode:
6891 type = v8hi_ftype_v8hi;
6892 break;
6893 case V16QImode:
6894 type = v16qi_ftype_v16qi;
6895 break;
6896 case V4SFmode:
6897 type = v4sf_ftype_v4sf;
6898 break;
6899 default:
6900 abort ();
6901 }
6902
6903 def_builtin (d->mask, d->name, type, d->code);
6904 }
6905}
6906
6907static void
863d938c 6908rs6000_common_init_builtins (void)
a3170dc6
AH
6909{
6910 struct builtin_description *d;
6911 size_t i;
6912
6913 tree v4sf_ftype_v4sf_v4sf_v16qi
6914 = build_function_type_list (V4SF_type_node,
6915 V4SF_type_node, V4SF_type_node,
6916 V16QI_type_node, NULL_TREE);
6917 tree v4si_ftype_v4si_v4si_v16qi
6918 = build_function_type_list (V4SI_type_node,
6919 V4SI_type_node, V4SI_type_node,
6920 V16QI_type_node, NULL_TREE);
6921 tree v8hi_ftype_v8hi_v8hi_v16qi
6922 = build_function_type_list (V8HI_type_node,
6923 V8HI_type_node, V8HI_type_node,
6924 V16QI_type_node, NULL_TREE);
6925 tree v16qi_ftype_v16qi_v16qi_v16qi
6926 = build_function_type_list (V16QI_type_node,
6927 V16QI_type_node, V16QI_type_node,
6928 V16QI_type_node, NULL_TREE);
6929 tree v4si_ftype_char
6930 = build_function_type_list (V4SI_type_node, char_type_node, NULL_TREE);
6931 tree v8hi_ftype_char
6932 = build_function_type_list (V8HI_type_node, char_type_node, NULL_TREE);
6933 tree v16qi_ftype_char
6934 = build_function_type_list (V16QI_type_node, char_type_node, NULL_TREE);
6935 tree v8hi_ftype_v16qi
6936 = build_function_type_list (V8HI_type_node, V16QI_type_node, NULL_TREE);
6937 tree v4sf_ftype_v4sf
6938 = build_function_type_list (V4SF_type_node, V4SF_type_node, NULL_TREE);
6939
6940 tree v2si_ftype_v2si_v2si
2abe3e28
AH
6941 = build_function_type_list (opaque_V2SI_type_node,
6942 opaque_V2SI_type_node,
6943 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6944
6945 tree v2sf_ftype_v2sf_v2sf
2abe3e28
AH
6946 = build_function_type_list (opaque_V2SF_type_node,
6947 opaque_V2SF_type_node,
6948 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6949
6950 tree v2si_ftype_int_int
2abe3e28 6951 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6952 integer_type_node, integer_type_node,
6953 NULL_TREE);
6954
6955 tree v2si_ftype_v2si
2abe3e28
AH
6956 = build_function_type_list (opaque_V2SI_type_node,
6957 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6958
6959 tree v2sf_ftype_v2sf
2abe3e28
AH
6960 = build_function_type_list (opaque_V2SF_type_node,
6961 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6962
6963 tree v2sf_ftype_v2si
2abe3e28
AH
6964 = build_function_type_list (opaque_V2SF_type_node,
6965 opaque_V2SI_type_node, NULL_TREE);
a3170dc6
AH
6966
6967 tree v2si_ftype_v2sf
2abe3e28
AH
6968 = build_function_type_list (opaque_V2SI_type_node,
6969 opaque_V2SF_type_node, NULL_TREE);
a3170dc6
AH
6970
6971 tree v2si_ftype_v2si_char
2abe3e28
AH
6972 = build_function_type_list (opaque_V2SI_type_node,
6973 opaque_V2SI_type_node,
6974 char_type_node, NULL_TREE);
a3170dc6
AH
6975
6976 tree v2si_ftype_int_char
2abe3e28 6977 = build_function_type_list (opaque_V2SI_type_node,
a3170dc6
AH
6978 integer_type_node, char_type_node, NULL_TREE);
6979
6980 tree v2si_ftype_char
2abe3e28
AH
6981 = build_function_type_list (opaque_V2SI_type_node,
6982 char_type_node, NULL_TREE);
a3170dc6
AH
6983
6984 tree int_ftype_int_int
6985 = build_function_type_list (integer_type_node,
6986 integer_type_node, integer_type_node,
6987 NULL_TREE);
95385cbb 6988
0ac081f6 6989 tree v4si_ftype_v4si_v4si
b4de2f7d
AH
6990 = build_function_type_list (V4SI_type_node,
6991 V4SI_type_node, V4SI_type_node, NULL_TREE);
617e0e1d 6992 tree v4sf_ftype_v4si_char
b4de2f7d
AH
6993 = build_function_type_list (V4SF_type_node,
6994 V4SI_type_node, char_type_node, NULL_TREE);
617e0e1d 6995 tree v4si_ftype_v4sf_char
b4de2f7d
AH
6996 = build_function_type_list (V4SI_type_node,
6997 V4SF_type_node, char_type_node, NULL_TREE);
2212663f 6998 tree v4si_ftype_v4si_char
b4de2f7d
AH
6999 = build_function_type_list (V4SI_type_node,
7000 V4SI_type_node, char_type_node, NULL_TREE);
2212663f 7001 tree v8hi_ftype_v8hi_char
b4de2f7d
AH
7002 = build_function_type_list (V8HI_type_node,
7003 V8HI_type_node, char_type_node, NULL_TREE);
2212663f 7004 tree v16qi_ftype_v16qi_char
b4de2f7d
AH
7005 = build_function_type_list (V16QI_type_node,
7006 V16QI_type_node, char_type_node, NULL_TREE);
24408032 7007 tree v16qi_ftype_v16qi_v16qi_char
b4de2f7d
AH
7008 = build_function_type_list (V16QI_type_node,
7009 V16QI_type_node, V16QI_type_node,
7010 char_type_node, NULL_TREE);
24408032 7011 tree v8hi_ftype_v8hi_v8hi_char
b4de2f7d
AH
7012 = build_function_type_list (V8HI_type_node,
7013 V8HI_type_node, V8HI_type_node,
7014 char_type_node, NULL_TREE);
24408032 7015 tree v4si_ftype_v4si_v4si_char
b4de2f7d
AH
7016 = build_function_type_list (V4SI_type_node,
7017 V4SI_type_node, V4SI_type_node,
7018 char_type_node, NULL_TREE);
24408032 7019 tree v4sf_ftype_v4sf_v4sf_char
b4de2f7d
AH
7020 = build_function_type_list (V4SF_type_node,
7021 V4SF_type_node, V4SF_type_node,
7022 char_type_node, NULL_TREE);
0ac081f6 7023 tree v4sf_ftype_v4sf_v4sf
b4de2f7d
AH
7024 = build_function_type_list (V4SF_type_node,
7025 V4SF_type_node, V4SF_type_node, NULL_TREE);
617e0e1d 7026 tree v4sf_ftype_v4sf_v4sf_v4si
b4de2f7d
AH
7027 = build_function_type_list (V4SF_type_node,
7028 V4SF_type_node, V4SF_type_node,
7029 V4SI_type_node, NULL_TREE);
2212663f 7030 tree v4sf_ftype_v4sf_v4sf_v4sf
b4de2f7d
AH
7031 = build_function_type_list (V4SF_type_node,
7032 V4SF_type_node, V4SF_type_node,
7033 V4SF_type_node, NULL_TREE);
617e0e1d 7034 tree v4si_ftype_v4si_v4si_v4si
b4de2f7d
AH
7035 = build_function_type_list (V4SI_type_node,
7036 V4SI_type_node, V4SI_type_node,
7037 V4SI_type_node, NULL_TREE);
0ac081f6 7038 tree v8hi_ftype_v8hi_v8hi
b4de2f7d
AH
7039 = build_function_type_list (V8HI_type_node,
7040 V8HI_type_node, V8HI_type_node, NULL_TREE);
2212663f 7041 tree v8hi_ftype_v8hi_v8hi_v8hi
b4de2f7d
AH
7042 = build_function_type_list (V8HI_type_node,
7043 V8HI_type_node, V8HI_type_node,
7044 V8HI_type_node, NULL_TREE);
2212663f 7045 tree v4si_ftype_v8hi_v8hi_v4si
b4de2f7d
AH
7046 = build_function_type_list (V4SI_type_node,
7047 V8HI_type_node, V8HI_type_node,
7048 V4SI_type_node, NULL_TREE);
2212663f 7049 tree v4si_ftype_v16qi_v16qi_v4si
b4de2f7d
AH
7050 = build_function_type_list (V4SI_type_node,
7051 V16QI_type_node, V16QI_type_node,
7052 V4SI_type_node, NULL_TREE);
0ac081f6 7053 tree v16qi_ftype_v16qi_v16qi
b4de2f7d
AH
7054 = build_function_type_list (V16QI_type_node,
7055 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7056 tree v4si_ftype_v4sf_v4sf
b4de2f7d
AH
7057 = build_function_type_list (V4SI_type_node,
7058 V4SF_type_node, V4SF_type_node, NULL_TREE);
0ac081f6 7059 tree v8hi_ftype_v16qi_v16qi
b4de2f7d
AH
7060 = build_function_type_list (V8HI_type_node,
7061 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7062 tree v4si_ftype_v8hi_v8hi
b4de2f7d
AH
7063 = build_function_type_list (V4SI_type_node,
7064 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7065 tree v8hi_ftype_v4si_v4si
b4de2f7d
AH
7066 = build_function_type_list (V8HI_type_node,
7067 V4SI_type_node, V4SI_type_node, NULL_TREE);
0ac081f6 7068 tree v16qi_ftype_v8hi_v8hi
b4de2f7d
AH
7069 = build_function_type_list (V16QI_type_node,
7070 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7071 tree v4si_ftype_v16qi_v4si
b4de2f7d
AH
7072 = build_function_type_list (V4SI_type_node,
7073 V16QI_type_node, V4SI_type_node, NULL_TREE);
fa066a23 7074 tree v4si_ftype_v16qi_v16qi
b4de2f7d
AH
7075 = build_function_type_list (V4SI_type_node,
7076 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7077 tree v4si_ftype_v8hi_v4si
b4de2f7d
AH
7078 = build_function_type_list (V4SI_type_node,
7079 V8HI_type_node, V4SI_type_node, NULL_TREE);
a3170dc6
AH
7080 tree v4si_ftype_v8hi
7081 = build_function_type_list (V4SI_type_node, V8HI_type_node, NULL_TREE);
7082 tree int_ftype_v4si_v4si
7083 = build_function_type_list (integer_type_node,
7084 V4SI_type_node, V4SI_type_node, NULL_TREE);
7085 tree int_ftype_v4sf_v4sf
7086 = build_function_type_list (integer_type_node,
7087 V4SF_type_node, V4SF_type_node, NULL_TREE);
7088 tree int_ftype_v16qi_v16qi
7089 = build_function_type_list (integer_type_node,
7090 V16QI_type_node, V16QI_type_node, NULL_TREE);
0ac081f6 7091 tree int_ftype_v8hi_v8hi
b4de2f7d
AH
7092 = build_function_type_list (integer_type_node,
7093 V8HI_type_node, V8HI_type_node, NULL_TREE);
0ac081f6 7094
6f317ef3 7095 /* Add the simple ternary operators. */
2212663f 7096 d = (struct builtin_description *) bdesc_3arg;
ca7558fc 7097 for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
2212663f
DB
7098 {
7099
7100 enum machine_mode mode0, mode1, mode2, mode3;
7101 tree type;
7102
0559cc77 7103 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7104 continue;
7105
7106 mode0 = insn_data[d->icode].operand[0].mode;
7107 mode1 = insn_data[d->icode].operand[1].mode;
7108 mode2 = insn_data[d->icode].operand[2].mode;
7109 mode3 = insn_data[d->icode].operand[3].mode;
7110
7111 /* When all four are of the same mode. */
7112 if (mode0 == mode1 && mode1 == mode2 && mode2 == mode3)
7113 {
7114 switch (mode0)
7115 {
617e0e1d
DB
7116 case V4SImode:
7117 type = v4si_ftype_v4si_v4si_v4si;
7118 break;
2212663f
DB
7119 case V4SFmode:
7120 type = v4sf_ftype_v4sf_v4sf_v4sf;
7121 break;
7122 case V8HImode:
7123 type = v8hi_ftype_v8hi_v8hi_v8hi;
7124 break;
7125 case V16QImode:
7126 type = v16qi_ftype_v16qi_v16qi_v16qi;
7127 break;
7128 default:
7129 abort();
7130 }
7131 }
7132 else if (mode0 == mode1 && mode1 == mode2 && mode3 == V16QImode)
7133 {
7134 switch (mode0)
7135 {
7136 case V4SImode:
7137 type = v4si_ftype_v4si_v4si_v16qi;
7138 break;
7139 case V4SFmode:
7140 type = v4sf_ftype_v4sf_v4sf_v16qi;
7141 break;
7142 case V8HImode:
7143 type = v8hi_ftype_v8hi_v8hi_v16qi;
7144 break;
7145 case V16QImode:
7146 type = v16qi_ftype_v16qi_v16qi_v16qi;
7147 break;
7148 default:
7149 abort();
7150 }
7151 }
7152 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode
7153 && mode3 == V4SImode)
24408032 7154 type = v4si_ftype_v16qi_v16qi_v4si;
2212663f
DB
7155 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode
7156 && mode3 == V4SImode)
24408032 7157 type = v4si_ftype_v8hi_v8hi_v4si;
617e0e1d
DB
7158 else if (mode0 == V4SFmode && mode1 == V4SFmode && mode2 == V4SFmode
7159 && mode3 == V4SImode)
24408032
AH
7160 type = v4sf_ftype_v4sf_v4sf_v4si;
7161
7162 /* vchar, vchar, vchar, 4 bit literal. */
7163 else if (mode0 == V16QImode && mode1 == mode0 && mode2 == mode0
7164 && mode3 == QImode)
7165 type = v16qi_ftype_v16qi_v16qi_char;
7166
7167 /* vshort, vshort, vshort, 4 bit literal. */
7168 else if (mode0 == V8HImode && mode1 == mode0 && mode2 == mode0
7169 && mode3 == QImode)
7170 type = v8hi_ftype_v8hi_v8hi_char;
7171
7172 /* vint, vint, vint, 4 bit literal. */
7173 else if (mode0 == V4SImode && mode1 == mode0 && mode2 == mode0
7174 && mode3 == QImode)
7175 type = v4si_ftype_v4si_v4si_char;
7176
7177 /* vfloat, vfloat, vfloat, 4 bit literal. */
7178 else if (mode0 == V4SFmode && mode1 == mode0 && mode2 == mode0
7179 && mode3 == QImode)
7180 type = v4sf_ftype_v4sf_v4sf_char;
7181
2212663f
DB
7182 else
7183 abort ();
7184
7185 def_builtin (d->mask, d->name, type, d->code);
7186 }
7187
0ac081f6 7188 /* Add the simple binary operators. */
00b960c7 7189 d = (struct builtin_description *) bdesc_2arg;
ca7558fc 7190 for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
0ac081f6
AH
7191 {
7192 enum machine_mode mode0, mode1, mode2;
7193 tree type;
7194
0559cc77 7195 if (d->name == 0 || d->icode == CODE_FOR_nothing)
0ac081f6
AH
7196 continue;
7197
7198 mode0 = insn_data[d->icode].operand[0].mode;
7199 mode1 = insn_data[d->icode].operand[1].mode;
7200 mode2 = insn_data[d->icode].operand[2].mode;
7201
7202 /* When all three operands are of the same mode. */
7203 if (mode0 == mode1 && mode1 == mode2)
7204 {
7205 switch (mode0)
7206 {
7207 case V4SFmode:
7208 type = v4sf_ftype_v4sf_v4sf;
7209 break;
7210 case V4SImode:
7211 type = v4si_ftype_v4si_v4si;
7212 break;
7213 case V16QImode:
7214 type = v16qi_ftype_v16qi_v16qi;
7215 break;
7216 case V8HImode:
7217 type = v8hi_ftype_v8hi_v8hi;
7218 break;
a3170dc6
AH
7219 case V2SImode:
7220 type = v2si_ftype_v2si_v2si;
7221 break;
7222 case V2SFmode:
7223 type = v2sf_ftype_v2sf_v2sf;
7224 break;
7225 case SImode:
7226 type = int_ftype_int_int;
7227 break;
0ac081f6
AH
7228 default:
7229 abort ();
7230 }
7231 }
7232
7233 /* A few other combos we really don't want to do manually. */
7234
7235 /* vint, vfloat, vfloat. */
7236 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == V4SFmode)
7237 type = v4si_ftype_v4sf_v4sf;
7238
7239 /* vshort, vchar, vchar. */
7240 else if (mode0 == V8HImode && mode1 == V16QImode && mode2 == V16QImode)
7241 type = v8hi_ftype_v16qi_v16qi;
7242
7243 /* vint, vshort, vshort. */
7244 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V8HImode)
7245 type = v4si_ftype_v8hi_v8hi;
7246
7247 /* vshort, vint, vint. */
7248 else if (mode0 == V8HImode && mode1 == V4SImode && mode2 == V4SImode)
7249 type = v8hi_ftype_v4si_v4si;
7250
7251 /* vchar, vshort, vshort. */
7252 else if (mode0 == V16QImode && mode1 == V8HImode && mode2 == V8HImode)
7253 type = v16qi_ftype_v8hi_v8hi;
7254
7255 /* vint, vchar, vint. */
7256 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V4SImode)
7257 type = v4si_ftype_v16qi_v4si;
7258
fa066a23
AH
7259 /* vint, vchar, vchar. */
7260 else if (mode0 == V4SImode && mode1 == V16QImode && mode2 == V16QImode)
7261 type = v4si_ftype_v16qi_v16qi;
7262
0ac081f6
AH
7263 /* vint, vshort, vint. */
7264 else if (mode0 == V4SImode && mode1 == V8HImode && mode2 == V4SImode)
7265 type = v4si_ftype_v8hi_v4si;
2212663f
DB
7266
7267 /* vint, vint, 5 bit literal. */
7268 else if (mode0 == V4SImode && mode1 == V4SImode && mode2 == QImode)
7269 type = v4si_ftype_v4si_char;
7270
7271 /* vshort, vshort, 5 bit literal. */
7272 else if (mode0 == V8HImode && mode1 == V8HImode && mode2 == QImode)
7273 type = v8hi_ftype_v8hi_char;
7274
7275 /* vchar, vchar, 5 bit literal. */
7276 else if (mode0 == V16QImode && mode1 == V16QImode && mode2 == QImode)
7277 type = v16qi_ftype_v16qi_char;
0ac081f6 7278
617e0e1d
DB
7279 /* vfloat, vint, 5 bit literal. */
7280 else if (mode0 == V4SFmode && mode1 == V4SImode && mode2 == QImode)
7281 type = v4sf_ftype_v4si_char;
7282
7283 /* vint, vfloat, 5 bit literal. */
7284 else if (mode0 == V4SImode && mode1 == V4SFmode && mode2 == QImode)
7285 type = v4si_ftype_v4sf_char;
7286
a3170dc6
AH
7287 else if (mode0 == V2SImode && mode1 == SImode && mode2 == SImode)
7288 type = v2si_ftype_int_int;
7289
7290 else if (mode0 == V2SImode && mode1 == V2SImode && mode2 == QImode)
7291 type = v2si_ftype_v2si_char;
7292
7293 else if (mode0 == V2SImode && mode1 == SImode && mode2 == QImode)
7294 type = v2si_ftype_int_char;
7295
0ac081f6
AH
7296 /* int, x, x. */
7297 else if (mode0 == SImode)
7298 {
7299 switch (mode1)
7300 {
7301 case V4SImode:
7302 type = int_ftype_v4si_v4si;
7303 break;
7304 case V4SFmode:
7305 type = int_ftype_v4sf_v4sf;
7306 break;
7307 case V16QImode:
7308 type = int_ftype_v16qi_v16qi;
7309 break;
7310 case V8HImode:
7311 type = int_ftype_v8hi_v8hi;
7312 break;
7313 default:
7314 abort ();
7315 }
7316 }
7317
7318 else
7319 abort ();
7320
2212663f
DB
7321 def_builtin (d->mask, d->name, type, d->code);
7322 }
24408032 7323
2212663f
DB
7324 /* Add the simple unary operators. */
7325 d = (struct builtin_description *) bdesc_1arg;
ca7558fc 7326 for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
2212663f
DB
7327 {
7328 enum machine_mode mode0, mode1;
7329 tree type;
7330
0559cc77 7331 if (d->name == 0 || d->icode == CODE_FOR_nothing)
2212663f
DB
7332 continue;
7333
7334 mode0 = insn_data[d->icode].operand[0].mode;
7335 mode1 = insn_data[d->icode].operand[1].mode;
7336
7337 if (mode0 == V4SImode && mode1 == QImode)
7338 type = v4si_ftype_char;
7339 else if (mode0 == V8HImode && mode1 == QImode)
7340 type = v8hi_ftype_char;
7341 else if (mode0 == V16QImode && mode1 == QImode)
7342 type = v16qi_ftype_char;
617e0e1d
DB
7343 else if (mode0 == V4SFmode && mode1 == V4SFmode)
7344 type = v4sf_ftype_v4sf;
20e26713
AH
7345 else if (mode0 == V8HImode && mode1 == V16QImode)
7346 type = v8hi_ftype_v16qi;
7347 else if (mode0 == V4SImode && mode1 == V8HImode)
7348 type = v4si_ftype_v8hi;
a3170dc6
AH
7349 else if (mode0 == V2SImode && mode1 == V2SImode)
7350 type = v2si_ftype_v2si;
7351 else if (mode0 == V2SFmode && mode1 == V2SFmode)
7352 type = v2sf_ftype_v2sf;
7353 else if (mode0 == V2SFmode && mode1 == V2SImode)
7354 type = v2sf_ftype_v2si;
7355 else if (mode0 == V2SImode && mode1 == V2SFmode)
7356 type = v2si_ftype_v2sf;
7357 else if (mode0 == V2SImode && mode1 == QImode)
7358 type = v2si_ftype_char;
2212663f
DB
7359 else
7360 abort ();
7361
0ac081f6
AH
7362 def_builtin (d->mask, d->name, type, d->code);
7363 }
7364}
7365
c15c90bb
ZW
7366static void
7367rs6000_init_libfuncs (void)
7368{
7369 if (!TARGET_HARD_FLOAT)
7370 return;
7371
c9034561 7372 if (DEFAULT_ABI != ABI_V4)
c15c90bb 7373 {
c9034561 7374 if (TARGET_XCOFF && ! TARGET_POWER2 && ! TARGET_POWERPC)
c15c90bb 7375 {
c9034561 7376 /* AIX library routines for float->int conversion. */
85363ca0
ZW
7377 set_conv_libfunc (sfix_optab, SImode, DFmode, "__itrunc");
7378 set_conv_libfunc (ufix_optab, SImode, DFmode, "__uitrunc");
4274207b
DE
7379 set_conv_libfunc (sfix_optab, SImode, TFmode, "_qitrunc");
7380 set_conv_libfunc (ufix_optab, SImode, TFmode, "_quitrunc");
c15c90bb
ZW
7381 }
7382
c9034561 7383 /* Standard AIX/Darwin/64-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7384 set_optab_libfunc (add_optab, TFmode, "_xlqadd");
7385 set_optab_libfunc (sub_optab, TFmode, "_xlqsub");
7386 set_optab_libfunc (smul_optab, TFmode, "_xlqmul");
7387 set_optab_libfunc (sdiv_optab, TFmode, "_xlqdiv");
7388 }
c9034561 7389 else
c15c90bb 7390 {
c9034561 7391 /* 32-bit SVR4 quad floating point routines. */
c15c90bb
ZW
7392
7393 set_optab_libfunc (add_optab, TFmode, "_q_add");
7394 set_optab_libfunc (sub_optab, TFmode, "_q_sub");
7395 set_optab_libfunc (neg_optab, TFmode, "_q_neg");
7396 set_optab_libfunc (smul_optab, TFmode, "_q_mul");
7397 set_optab_libfunc (sdiv_optab, TFmode, "_q_div");
7398 if (TARGET_PPC_GPOPT || TARGET_POWER2)
7399 set_optab_libfunc (sqrt_optab, TFmode, "_q_sqrt");
7400
c9034561
ZW
7401 set_optab_libfunc (eq_optab, TFmode, "_q_feq");
7402 set_optab_libfunc (ne_optab, TFmode, "_q_fne");
7403 set_optab_libfunc (gt_optab, TFmode, "_q_fgt");
7404 set_optab_libfunc (ge_optab, TFmode, "_q_fge");
7405 set_optab_libfunc (lt_optab, TFmode, "_q_flt");
7406 set_optab_libfunc (le_optab, TFmode, "_q_fle");
7407
85363ca0
ZW
7408 set_conv_libfunc (sext_optab, TFmode, SFmode, "_q_stoq");
7409 set_conv_libfunc (sext_optab, TFmode, DFmode, "_q_dtoq");
7410 set_conv_libfunc (trunc_optab, SFmode, TFmode, "_q_qtos");
7411 set_conv_libfunc (trunc_optab, DFmode, TFmode, "_q_qtod");
7412 set_conv_libfunc (sfix_optab, SImode, TFmode, "_q_qtoi");
7413 set_conv_libfunc (ufix_optab, SImode, TFmode, "_q_qtou");
7414 set_conv_libfunc (sfloat_optab, TFmode, SImode, "_q_itoq");
c15c90bb
ZW
7415 }
7416}
35aff10b 7417\f
7e69e155
MM
7418/* Expand a block move operation, and return 1 if successful. Return 0
7419 if we should let the compiler generate normal code.
7420
7421 operands[0] is the destination
7422 operands[1] is the source
7423 operands[2] is the length
7424 operands[3] is the alignment */
7425
3933e0e1
MM
7426#define MAX_MOVE_REG 4
7427
7e69e155 7428int
a2369ed3 7429expand_block_move (rtx operands[])
7e69e155 7430{
b6c9286a
MM
7431 rtx orig_dest = operands[0];
7432 rtx orig_src = operands[1];
7e69e155 7433 rtx bytes_rtx = operands[2];
7e69e155 7434 rtx align_rtx = operands[3];
3933e0e1 7435 int constp = (GET_CODE (bytes_rtx) == CONST_INT);
5ee95df6 7436 int align;
3933e0e1
MM
7437 int bytes;
7438 int offset;
7e69e155 7439 int move_bytes;
cabfd258
GK
7440 rtx stores[MAX_MOVE_REG];
7441 int num_reg = 0;
7e69e155 7442
3933e0e1 7443 /* If this is not a fixed size move, just call memcpy */
cc0d9ba8 7444 if (! constp)
3933e0e1
MM
7445 return 0;
7446
5ee95df6
FS
7447 /* If this is not a fixed size alignment, abort */
7448 if (GET_CODE (align_rtx) != CONST_INT)
7449 abort ();
7450 align = INTVAL (align_rtx);
7451
7e69e155 7452 /* Anything to move? */
3933e0e1
MM
7453 bytes = INTVAL (bytes_rtx);
7454 if (bytes <= 0)
7e69e155
MM
7455 return 1;
7456
ea9982a8 7457 /* store_one_arg depends on expand_block_move to handle at least the size of
6f317ef3 7458 reg_parm_stack_space. */
ea9982a8 7459 if (bytes > (TARGET_POWERPC64 ? 64 : 32))
7e69e155
MM
7460 return 0;
7461
cabfd258 7462 for (offset = 0; bytes > 0; offset += move_bytes, bytes -= move_bytes)
7e69e155 7463 {
cabfd258 7464 union {
a2369ed3
DJ
7465 rtx (*movstrsi) (rtx, rtx, rtx, rtx);
7466 rtx (*mov) (rtx, rtx);
cabfd258
GK
7467 } gen_func;
7468 enum machine_mode mode = BLKmode;
7469 rtx src, dest;
7470
7471 if (TARGET_STRING
7472 && bytes > 24 /* move up to 32 bytes at a time */
7473 && ! fixed_regs[5]
7474 && ! fixed_regs[6]
7475 && ! fixed_regs[7]
7476 && ! fixed_regs[8]
7477 && ! fixed_regs[9]
7478 && ! fixed_regs[10]
7479 && ! fixed_regs[11]
7480 && ! fixed_regs[12])
7e69e155 7481 {
cabfd258
GK
7482 move_bytes = (bytes > 32) ? 32 : bytes;
7483 gen_func.movstrsi = gen_movstrsi_8reg;
7484 }
7485 else if (TARGET_STRING
7486 && bytes > 16 /* move up to 24 bytes at a time */
7487 && ! fixed_regs[5]
7488 && ! fixed_regs[6]
7489 && ! fixed_regs[7]
7490 && ! fixed_regs[8]
7491 && ! fixed_regs[9]
7492 && ! fixed_regs[10])
7493 {
7494 move_bytes = (bytes > 24) ? 24 : bytes;
7495 gen_func.movstrsi = gen_movstrsi_6reg;
7496 }
7497 else if (TARGET_STRING
7498 && bytes > 8 /* move up to 16 bytes at a time */
7499 && ! fixed_regs[5]
7500 && ! fixed_regs[6]
7501 && ! fixed_regs[7]
7502 && ! fixed_regs[8])
7503 {
7504 move_bytes = (bytes > 16) ? 16 : bytes;
7505 gen_func.movstrsi = gen_movstrsi_4reg;
7506 }
7507 else if (bytes >= 8 && TARGET_POWERPC64
7508 /* 64-bit loads and stores require word-aligned
7509 displacements. */
7510 && (align >= 8 || (! STRICT_ALIGNMENT && align >= 4)))
7511 {
7512 move_bytes = 8;
7513 mode = DImode;
7514 gen_func.mov = gen_movdi;
7515 }
7516 else if (TARGET_STRING && bytes > 4 && !TARGET_POWERPC64)
7517 { /* move up to 8 bytes at a time */
7518 move_bytes = (bytes > 8) ? 8 : bytes;
7519 gen_func.movstrsi = gen_movstrsi_2reg;
7520 }
7521 else if (bytes >= 4 && (align >= 4 || ! STRICT_ALIGNMENT))
7522 { /* move 4 bytes */
7523 move_bytes = 4;
7524 mode = SImode;
7525 gen_func.mov = gen_movsi;
7526 }
7527 else if (bytes == 2 && (align >= 2 || ! STRICT_ALIGNMENT))
7528 { /* move 2 bytes */
7529 move_bytes = 2;
7530 mode = HImode;
7531 gen_func.mov = gen_movhi;
7532 }
7533 else if (TARGET_STRING && bytes > 1)
7534 { /* move up to 4 bytes at a time */
7535 move_bytes = (bytes > 4) ? 4 : bytes;
7536 gen_func.movstrsi = gen_movstrsi_1reg;
7537 }
7538 else /* move 1 byte at a time */
7539 {
7540 move_bytes = 1;
7541 mode = QImode;
7542 gen_func.mov = gen_movqi;
7543 }
7544
7545 src = adjust_address (orig_src, mode, offset);
7546 dest = adjust_address (orig_dest, mode, offset);
7547
7548 if (mode != BLKmode)
7549 {
7550 rtx tmp_reg = gen_reg_rtx (mode);
7551
7552 emit_insn ((*gen_func.mov) (tmp_reg, src));
7553 stores[num_reg++] = (*gen_func.mov) (dest, tmp_reg);
4c64a852 7554 }
3933e0e1 7555
cabfd258
GK
7556 if (mode == BLKmode || num_reg >= MAX_MOVE_REG || bytes == move_bytes)
7557 {
7558 int i;
7559 for (i = 0; i < num_reg; i++)
7560 emit_insn (stores[i]);
7561 num_reg = 0;
7562 }
35aff10b 7563
cabfd258 7564 if (mode == BLKmode)
7e69e155 7565 {
cabfd258
GK
7566 /* Move the address into scratch registers. The movstrsi
7567 patterns require zero offset. */
7568 if (!REG_P (XEXP (src, 0)))
b6c9286a 7569 {
cabfd258
GK
7570 rtx src_reg = copy_addr_to_reg (XEXP (src, 0));
7571 src = replace_equiv_address (src, src_reg);
b6c9286a 7572 }
cabfd258
GK
7573 set_mem_size (src, GEN_INT (move_bytes));
7574
7575 if (!REG_P (XEXP (dest, 0)))
3933e0e1 7576 {
cabfd258
GK
7577 rtx dest_reg = copy_addr_to_reg (XEXP (dest, 0));
7578 dest = replace_equiv_address (dest, dest_reg);
7e69e155 7579 }
cabfd258
GK
7580 set_mem_size (dest, GEN_INT (move_bytes));
7581
7582 emit_insn ((*gen_func.movstrsi) (dest, src,
7583 GEN_INT (move_bytes & 31),
7584 align_rtx));
7e69e155 7585 }
7e69e155
MM
7586 }
7587
7588 return 1;
7589}
7590
9878760c
RK
7591\f
7592/* Return 1 if OP is a load multiple operation. It is known to be a
7593 PARALLEL and the first section will be tested. */
7594
7595int
a2369ed3 7596load_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7597{
7598 int count = XVECLEN (op, 0);
e2c953b6 7599 unsigned int dest_regno;
9878760c
RK
7600 rtx src_addr;
7601 int i;
7602
7603 /* Perform a quick check so we don't blow up below. */
7604 if (count <= 1
7605 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7606 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7607 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7608 return 0;
7609
7610 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7611 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7612
7613 for (i = 1; i < count; i++)
7614 {
7615 rtx elt = XVECEXP (op, 0, i);
7616
7617 if (GET_CODE (elt) != SET
7618 || GET_CODE (SET_DEST (elt)) != REG
7619 || GET_MODE (SET_DEST (elt)) != SImode
7620 || REGNO (SET_DEST (elt)) != dest_regno + i
7621 || GET_CODE (SET_SRC (elt)) != MEM
7622 || GET_MODE (SET_SRC (elt)) != SImode
7623 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
7624 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
7625 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
7626 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
7627 return 0;
7628 }
7629
7630 return 1;
7631}
7632
7633/* Similar, but tests for store multiple. Here, the second vector element
7634 is a CLOBBER. It will be tested later. */
7635
7636int
a2369ed3 7637store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
7638{
7639 int count = XVECLEN (op, 0) - 1;
e2c953b6 7640 unsigned int src_regno;
9878760c
RK
7641 rtx dest_addr;
7642 int i;
7643
7644 /* Perform a quick check so we don't blow up below. */
7645 if (count <= 1
7646 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7647 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7648 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7649 return 0;
7650
7651 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7652 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7653
7654 for (i = 1; i < count; i++)
7655 {
7656 rtx elt = XVECEXP (op, 0, i + 1);
7657
7658 if (GET_CODE (elt) != SET
7659 || GET_CODE (SET_SRC (elt)) != REG
7660 || GET_MODE (SET_SRC (elt)) != SImode
7661 || REGNO (SET_SRC (elt)) != src_regno + i
7662 || GET_CODE (SET_DEST (elt)) != MEM
7663 || GET_MODE (SET_DEST (elt)) != SImode
7664 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
7665 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
7666 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
7667 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
7668 return 0;
7669 }
7670
7671 return 1;
7672}
9ebbca7d 7673
9caa3eb2
DE
7674/* Return a string to perform a load_multiple operation.
7675 operands[0] is the vector.
7676 operands[1] is the source address.
7677 operands[2] is the first destination register. */
7678
7679const char *
a2369ed3 7680rs6000_output_load_multiple (rtx operands[3])
9caa3eb2
DE
7681{
7682 /* We have to handle the case where the pseudo used to contain the address
7683 is assigned to one of the output registers. */
7684 int i, j;
7685 int words = XVECLEN (operands[0], 0);
7686 rtx xop[10];
7687
7688 if (XVECLEN (operands[0], 0) == 1)
7689 return "{l|lwz} %2,0(%1)";
7690
7691 for (i = 0; i < words; i++)
7692 if (refers_to_regno_p (REGNO (operands[2]) + i,
7693 REGNO (operands[2]) + i + 1, operands[1], 0))
7694 {
7695 if (i == words-1)
7696 {
7697 xop[0] = GEN_INT (4 * (words-1));
7698 xop[1] = operands[1];
7699 xop[2] = operands[2];
7700 output_asm_insn ("{lsi|lswi} %2,%1,%0\n\t{l|lwz} %1,%0(%1)", xop);
7701 return "";
7702 }
7703 else if (i == 0)
7704 {
7705 xop[0] = GEN_INT (4 * (words-1));
7706 xop[1] = operands[1];
7707 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + 1);
7708 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);
7709 return "";
7710 }
7711 else
7712 {
7713 for (j = 0; j < words; j++)
7714 if (j != i)
7715 {
7716 xop[0] = GEN_INT (j * 4);
7717 xop[1] = operands[1];
7718 xop[2] = gen_rtx_REG (SImode, REGNO (operands[2]) + j);
7719 output_asm_insn ("{l|lwz} %2,%0(%1)", xop);
7720 }
7721 xop[0] = GEN_INT (i * 4);
7722 xop[1] = operands[1];
7723 output_asm_insn ("{l|lwz} %1,%0(%1)", xop);
7724 return "";
7725 }
7726 }
7727
7728 return "{lsi|lswi} %2,%1,%N0";
7729}
7730
00b960c7
AH
7731/* Return 1 for a parallel vrsave operation. */
7732
7733int
a2369ed3 7734vrsave_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
00b960c7
AH
7735{
7736 int count = XVECLEN (op, 0);
7737 unsigned int dest_regno, src_regno;
7738 int i;
7739
7740 if (count <= 1
7741 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7742 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
a004eb82 7743 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE)
00b960c7
AH
7744 return 0;
7745
7746 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7747 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7748
7749 if (dest_regno != VRSAVE_REGNO
7750 && src_regno != VRSAVE_REGNO)
7751 return 0;
7752
7753 for (i = 1; i < count; i++)
7754 {
7755 rtx elt = XVECEXP (op, 0, i);
7756
9aa86737
AH
7757 if (GET_CODE (elt) != CLOBBER
7758 && GET_CODE (elt) != SET)
00b960c7
AH
7759 return 0;
7760 }
7761
7762 return 1;
7763}
7764
2c4a9cff
DE
7765/* Return 1 for an PARALLEL suitable for mfcr. */
7766
7767int
a2369ed3 7768mfcr_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
2c4a9cff
DE
7769{
7770 int count = XVECLEN (op, 0);
7771 int i;
7772
7773 /* Perform a quick check so we don't blow up below. */
7774 if (count < 1
7775 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7776 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7777 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
7778 return 0;
7779
7780 for (i = 0; i < count; i++)
7781 {
7782 rtx exp = XVECEXP (op, 0, i);
7783 rtx unspec;
7784 int maskval;
7785 rtx src_reg;
7786
7787 src_reg = XVECEXP (SET_SRC (exp), 0, 0);
7788
7789 if (GET_CODE (src_reg) != REG
7790 || GET_MODE (src_reg) != CCmode
7791 || ! CR_REGNO_P (REGNO (src_reg)))
7792 return 0;
7793
7794 if (GET_CODE (exp) != SET
7795 || GET_CODE (SET_DEST (exp)) != REG
7796 || GET_MODE (SET_DEST (exp)) != SImode
7797 || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
7798 return 0;
7799 unspec = SET_SRC (exp);
7800 maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
7801
7802 if (GET_CODE (unspec) != UNSPEC
7803 || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
7804 || XVECLEN (unspec, 0) != 2
7805 || XVECEXP (unspec, 0, 0) != src_reg
7806 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7807 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7808 return 0;
7809 }
7810 return 1;
7811}
7812
a4f6c312 7813/* Return 1 for an PARALLEL suitable for mtcrf. */
9ebbca7d
GK
7814
7815int
a2369ed3 7816mtcrf_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7817{
7818 int count = XVECLEN (op, 0);
7819 int i;
9ebbca7d
GK
7820 rtx src_reg;
7821
7822 /* Perform a quick check so we don't blow up below. */
e35b9579
GK
7823 if (count < 1
7824 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7825 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
7826 || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
9ebbca7d 7827 return 0;
e35b9579 7828 src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
9ebbca7d
GK
7829
7830 if (GET_CODE (src_reg) != REG
7831 || GET_MODE (src_reg) != SImode
7832 || ! INT_REGNO_P (REGNO (src_reg)))
7833 return 0;
7834
e35b9579 7835 for (i = 0; i < count; i++)
9ebbca7d
GK
7836 {
7837 rtx exp = XVECEXP (op, 0, i);
7838 rtx unspec;
7839 int maskval;
7840
7841 if (GET_CODE (exp) != SET
7842 || GET_CODE (SET_DEST (exp)) != REG
7843 || GET_MODE (SET_DEST (exp)) != CCmode
7844 || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
7845 return 0;
7846 unspec = SET_SRC (exp);
7847 maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
9ebbca7d
GK
7848
7849 if (GET_CODE (unspec) != UNSPEC
615158e2 7850 || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
9ebbca7d
GK
7851 || XVECLEN (unspec, 0) != 2
7852 || XVECEXP (unspec, 0, 0) != src_reg
7853 || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
7854 || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
7855 return 0;
7856 }
e35b9579 7857 return 1;
9ebbca7d
GK
7858}
7859
a4f6c312 7860/* Return 1 for an PARALLEL suitable for lmw. */
9ebbca7d
GK
7861
7862int
a2369ed3 7863lmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7864{
7865 int count = XVECLEN (op, 0);
e2c953b6 7866 unsigned int dest_regno;
9ebbca7d 7867 rtx src_addr;
e2c953b6 7868 unsigned int base_regno;
9ebbca7d
GK
7869 HOST_WIDE_INT offset;
7870 int i;
7871
7872 /* Perform a quick check so we don't blow up below. */
7873 if (count <= 1
7874 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7875 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
7876 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
7877 return 0;
7878
7879 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
7880 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
7881
7882 if (dest_regno > 31
e2c953b6 7883 || count != 32 - (int) dest_regno)
9ebbca7d
GK
7884 return 0;
7885
4d588c14 7886 if (legitimate_indirect_address_p (src_addr, 0))
9ebbca7d
GK
7887 {
7888 offset = 0;
7889 base_regno = REGNO (src_addr);
7890 if (base_regno == 0)
7891 return 0;
7892 }
4d588c14 7893 else if (legitimate_offset_address_p (SImode, src_addr, 0))
9ebbca7d
GK
7894 {
7895 offset = INTVAL (XEXP (src_addr, 1));
7896 base_regno = REGNO (XEXP (src_addr, 0));
7897 }
7898 else
7899 return 0;
7900
7901 for (i = 0; i < count; i++)
7902 {
7903 rtx elt = XVECEXP (op, 0, i);
7904 rtx newaddr;
7905 rtx addr_reg;
7906 HOST_WIDE_INT newoffset;
7907
7908 if (GET_CODE (elt) != SET
7909 || GET_CODE (SET_DEST (elt)) != REG
7910 || GET_MODE (SET_DEST (elt)) != SImode
7911 || REGNO (SET_DEST (elt)) != dest_regno + i
7912 || GET_CODE (SET_SRC (elt)) != MEM
7913 || GET_MODE (SET_SRC (elt)) != SImode)
7914 return 0;
7915 newaddr = XEXP (SET_SRC (elt), 0);
4d588c14 7916 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7917 {
7918 newoffset = 0;
7919 addr_reg = newaddr;
7920 }
4d588c14 7921 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7922 {
7923 addr_reg = XEXP (newaddr, 0);
7924 newoffset = INTVAL (XEXP (newaddr, 1));
7925 }
7926 else
7927 return 0;
7928 if (REGNO (addr_reg) != base_regno
7929 || newoffset != offset + 4 * i)
7930 return 0;
7931 }
7932
7933 return 1;
7934}
7935
a4f6c312 7936/* Return 1 for an PARALLEL suitable for stmw. */
9ebbca7d
GK
7937
7938int
a2369ed3 7939stmw_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9ebbca7d
GK
7940{
7941 int count = XVECLEN (op, 0);
e2c953b6 7942 unsigned int src_regno;
9ebbca7d 7943 rtx dest_addr;
e2c953b6 7944 unsigned int base_regno;
9ebbca7d
GK
7945 HOST_WIDE_INT offset;
7946 int i;
7947
7948 /* Perform a quick check so we don't blow up below. */
7949 if (count <= 1
7950 || GET_CODE (XVECEXP (op, 0, 0)) != SET
7951 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
7952 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
7953 return 0;
7954
7955 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
7956 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
7957
7958 if (src_regno > 31
e2c953b6 7959 || count != 32 - (int) src_regno)
9ebbca7d
GK
7960 return 0;
7961
4d588c14 7962 if (legitimate_indirect_address_p (dest_addr, 0))
9ebbca7d
GK
7963 {
7964 offset = 0;
7965 base_regno = REGNO (dest_addr);
7966 if (base_regno == 0)
7967 return 0;
7968 }
4d588c14 7969 else if (legitimate_offset_address_p (SImode, dest_addr, 0))
9ebbca7d
GK
7970 {
7971 offset = INTVAL (XEXP (dest_addr, 1));
7972 base_regno = REGNO (XEXP (dest_addr, 0));
7973 }
7974 else
7975 return 0;
7976
7977 for (i = 0; i < count; i++)
7978 {
7979 rtx elt = XVECEXP (op, 0, i);
7980 rtx newaddr;
7981 rtx addr_reg;
7982 HOST_WIDE_INT newoffset;
7983
7984 if (GET_CODE (elt) != SET
7985 || GET_CODE (SET_SRC (elt)) != REG
7986 || GET_MODE (SET_SRC (elt)) != SImode
7987 || REGNO (SET_SRC (elt)) != src_regno + i
7988 || GET_CODE (SET_DEST (elt)) != MEM
7989 || GET_MODE (SET_DEST (elt)) != SImode)
7990 return 0;
7991 newaddr = XEXP (SET_DEST (elt), 0);
4d588c14 7992 if (legitimate_indirect_address_p (newaddr, 0))
9ebbca7d
GK
7993 {
7994 newoffset = 0;
7995 addr_reg = newaddr;
7996 }
4d588c14 7997 else if (legitimate_offset_address_p (SImode, newaddr, 0))
9ebbca7d
GK
7998 {
7999 addr_reg = XEXP (newaddr, 0);
8000 newoffset = INTVAL (XEXP (newaddr, 1));
8001 }
8002 else
8003 return 0;
8004 if (REGNO (addr_reg) != base_regno
8005 || newoffset != offset + 4 * i)
8006 return 0;
8007 }
8008
8009 return 1;
8010}
9878760c 8011\f
a4f6c312
SS
8012/* A validation routine: say whether CODE, a condition code, and MODE
8013 match. The other alternatives either don't make sense or should
8014 never be generated. */
39a10a29 8015
39a10a29 8016static void
a2369ed3 8017validate_condition_mode (enum rtx_code code, enum machine_mode mode)
39a10a29
GK
8018{
8019 if (GET_RTX_CLASS (code) != '<'
8020 || GET_MODE_CLASS (mode) != MODE_CC)
8021 abort ();
8022
8023 /* These don't make sense. */
8024 if ((code == GT || code == LT || code == GE || code == LE)
8025 && mode == CCUNSmode)
8026 abort ();
8027
8028 if ((code == GTU || code == LTU || code == GEU || code == LEU)
8029 && mode != CCUNSmode)
8030 abort ();
8031
8032 if (mode != CCFPmode
8033 && (code == ORDERED || code == UNORDERED
8034 || code == UNEQ || code == LTGT
8035 || code == UNGT || code == UNLT
8036 || code == UNGE || code == UNLE))
a4f6c312 8037 abort ();
39a10a29 8038
de6c5979 8039 /* These should never be generated except for
bc9ec0e0 8040 flag_finite_math_only. */
39a10a29 8041 if (mode == CCFPmode
ad72b533 8042 && ! flag_finite_math_only
39a10a29
GK
8043 && (code == LE || code == GE
8044 || code == UNEQ || code == LTGT
8045 || code == UNGT || code == UNLT))
8046 abort ();
8047
8048 /* These are invalid; the information is not there. */
8049 if (mode == CCEQmode
8050 && code != EQ && code != NE)
8051 abort ();
8052}
8053
9878760c
RK
8054/* Return 1 if OP is a comparison operation that is valid for a branch insn.
8055 We only check the opcode against the mode of the CC value here. */
8056
8057int
a2369ed3 8058branch_comparison_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
9878760c
RK
8059{
8060 enum rtx_code code = GET_CODE (op);
8061 enum machine_mode cc_mode;
8062
8063 if (GET_RTX_CLASS (code) != '<')
8064 return 0;
8065
8066 cc_mode = GET_MODE (XEXP (op, 0));
8067 if (GET_MODE_CLASS (cc_mode) != MODE_CC)
8068 return 0;
8069
39a10a29 8070 validate_condition_mode (code, cc_mode);
9878760c 8071
39a10a29
GK
8072 return 1;
8073}
8074
8075/* Return 1 if OP is a comparison operation that is valid for a branch
8076 insn and which is true if the corresponding bit in the CC register
8077 is set. */
8078
8079int
a2369ed3 8080branch_positive_comparison_operator (rtx op, enum machine_mode mode)
39a10a29
GK
8081{
8082 enum rtx_code code;
8083
8daf2e65 8084 if (! branch_comparison_operator (op, mode))
9878760c
RK
8085 return 0;
8086
39a10a29
GK
8087 code = GET_CODE (op);
8088 return (code == EQ || code == LT || code == GT
993f19a8 8089 || (TARGET_E500 && TARGET_HARD_FLOAT && !TARGET_FPRS && code == NE)
39a10a29
GK
8090 || code == LTU || code == GTU
8091 || code == UNORDERED);
9878760c
RK
8092}
8093
b7053a3f
GK
8094/* Return 1 if OP is a comparison operation that is valid for an scc
8095 insn: it must be a positive comparison. */
9878760c
RK
8096
8097int
a2369ed3 8098scc_comparison_operator (rtx op, enum machine_mode mode)
9878760c 8099{
b7053a3f 8100 return branch_positive_comparison_operator (op, mode);
9878760c 8101}
e0cd0770
JC
8102
8103int
a2369ed3 8104trap_comparison_operator (rtx op, enum machine_mode mode)
e0cd0770
JC
8105{
8106 if (mode != VOIDmode && mode != GET_MODE (op))
8107 return 0;
39a10a29 8108 return GET_RTX_CLASS (GET_CODE (op)) == '<';
e0cd0770 8109}
dfbdccdb
GK
8110
8111int
a2369ed3 8112boolean_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
dfbdccdb
GK
8113{
8114 enum rtx_code code = GET_CODE (op);
8115 return (code == AND || code == IOR || code == XOR);
8116}
1d328b19
GK
8117
8118int
a2369ed3 8119boolean_or_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1d328b19
GK
8120{
8121 enum rtx_code code = GET_CODE (op);
8122 return (code == IOR || code == XOR);
8123}
50a0b056
GK
8124
8125int
a2369ed3 8126min_max_operator (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
50a0b056
GK
8127{
8128 enum rtx_code code = GET_CODE (op);
8129 return (code == SMIN || code == SMAX || code == UMIN || code == UMAX);
8130}
9878760c
RK
8131\f
8132/* Return 1 if ANDOP is a mask that has no bits on that are not in the
8133 mask required to convert the result of a rotate insn into a shift
b1765bde 8134 left insn of SHIFTOP bits. Both are known to be SImode CONST_INT. */
9878760c
RK
8135
8136int
a2369ed3 8137includes_lshift_p (rtx shiftop, rtx andop)
9878760c 8138{
e2c953b6
DE
8139 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
8140
8141 shift_mask <<= INTVAL (shiftop);
9878760c 8142
b1765bde 8143 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
9878760c
RK
8144}
8145
8146/* Similar, but for right shift. */
8147
8148int
a2369ed3 8149includes_rshift_p (rtx shiftop, rtx andop)
9878760c 8150{
a7653a2c 8151 unsigned HOST_WIDE_INT shift_mask = ~(unsigned HOST_WIDE_INT) 0;
9878760c
RK
8152
8153 shift_mask >>= INTVAL (shiftop);
8154
b1765bde 8155 return (INTVAL (andop) & 0xffffffff & ~shift_mask) == 0;
e2c953b6
DE
8156}
8157
c5059423
AM
8158/* Return 1 if ANDOP is a mask suitable for use with an rldic insn
8159 to perform a left shift. It must have exactly SHIFTOP least
b6d08ca1 8160 significant 0's, then one or more 1's, then zero or more 0's. */
e2c953b6
DE
8161
8162int
a2369ed3 8163includes_rldic_lshift_p (rtx shiftop, rtx andop)
e2c953b6 8164{
c5059423
AM
8165 if (GET_CODE (andop) == CONST_INT)
8166 {
02071907 8167 HOST_WIDE_INT c, lsb, shift_mask;
e2c953b6 8168
c5059423 8169 c = INTVAL (andop);
02071907 8170 if (c == 0 || c == ~0)
c5059423 8171 return 0;
e2c953b6 8172
02071907 8173 shift_mask = ~0;
c5059423
AM
8174 shift_mask <<= INTVAL (shiftop);
8175
b6d08ca1 8176 /* Find the least significant one bit. */
c5059423
AM
8177 lsb = c & -c;
8178
8179 /* It must coincide with the LSB of the shift mask. */
8180 if (-lsb != shift_mask)
8181 return 0;
e2c953b6 8182
c5059423
AM
8183 /* Invert to look for the next transition (if any). */
8184 c = ~c;
8185
8186 /* Remove the low group of ones (originally low group of zeros). */
8187 c &= -lsb;
8188
8189 /* Again find the lsb, and check we have all 1's above. */
8190 lsb = c & -c;
8191 return c == -lsb;
8192 }
8193 else if (GET_CODE (andop) == CONST_DOUBLE
8194 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8195 {
02071907
AM
8196 HOST_WIDE_INT low, high, lsb;
8197 HOST_WIDE_INT shift_mask_low, shift_mask_high;
c5059423
AM
8198
8199 low = CONST_DOUBLE_LOW (andop);
8200 if (HOST_BITS_PER_WIDE_INT < 64)
8201 high = CONST_DOUBLE_HIGH (andop);
8202
8203 if ((low == 0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == 0))
02071907 8204 || (low == ~0 && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0)))
c5059423
AM
8205 return 0;
8206
8207 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8208 {
02071907 8209 shift_mask_high = ~0;
c5059423
AM
8210 if (INTVAL (shiftop) > 32)
8211 shift_mask_high <<= INTVAL (shiftop) - 32;
8212
8213 lsb = high & -high;
8214
8215 if (-lsb != shift_mask_high || INTVAL (shiftop) < 32)
8216 return 0;
8217
8218 high = ~high;
8219 high &= -lsb;
8220
8221 lsb = high & -high;
8222 return high == -lsb;
8223 }
8224
02071907 8225 shift_mask_low = ~0;
c5059423
AM
8226 shift_mask_low <<= INTVAL (shiftop);
8227
8228 lsb = low & -low;
8229
8230 if (-lsb != shift_mask_low)
8231 return 0;
8232
8233 if (HOST_BITS_PER_WIDE_INT < 64)
8234 high = ~high;
8235 low = ~low;
8236 low &= -lsb;
8237
8238 if (HOST_BITS_PER_WIDE_INT < 64 && low == 0)
8239 {
8240 lsb = high & -high;
8241 return high == -lsb;
8242 }
8243
8244 lsb = low & -low;
8245 return low == -lsb && (HOST_BITS_PER_WIDE_INT >= 64 || high == ~0);
8246 }
8247 else
8248 return 0;
8249}
e2c953b6 8250
c5059423
AM
8251/* Return 1 if ANDOP is a mask suitable for use with an rldicr insn
8252 to perform a left shift. It must have SHIFTOP or more least
c1207243 8253 significant 0's, with the remainder of the word 1's. */
e2c953b6 8254
c5059423 8255int
a2369ed3 8256includes_rldicr_lshift_p (rtx shiftop, rtx andop)
c5059423 8257{
e2c953b6 8258 if (GET_CODE (andop) == CONST_INT)
c5059423 8259 {
02071907 8260 HOST_WIDE_INT c, lsb, shift_mask;
c5059423 8261
02071907 8262 shift_mask = ~0;
c5059423
AM
8263 shift_mask <<= INTVAL (shiftop);
8264 c = INTVAL (andop);
8265
c1207243 8266 /* Find the least significant one bit. */
c5059423
AM
8267 lsb = c & -c;
8268
8269 /* It must be covered by the shift mask.
a4f6c312 8270 This test also rejects c == 0. */
c5059423
AM
8271 if ((lsb & shift_mask) == 0)
8272 return 0;
8273
8274 /* Check we have all 1's above the transition, and reject all 1's. */
8275 return c == -lsb && lsb != 1;
8276 }
8277 else if (GET_CODE (andop) == CONST_DOUBLE
8278 && (GET_MODE (andop) == VOIDmode || GET_MODE (andop) == DImode))
8279 {
02071907 8280 HOST_WIDE_INT low, lsb, shift_mask_low;
c5059423
AM
8281
8282 low = CONST_DOUBLE_LOW (andop);
8283
8284 if (HOST_BITS_PER_WIDE_INT < 64)
8285 {
02071907 8286 HOST_WIDE_INT high, shift_mask_high;
c5059423
AM
8287
8288 high = CONST_DOUBLE_HIGH (andop);
8289
8290 if (low == 0)
8291 {
02071907 8292 shift_mask_high = ~0;
c5059423
AM
8293 if (INTVAL (shiftop) > 32)
8294 shift_mask_high <<= INTVAL (shiftop) - 32;
8295
8296 lsb = high & -high;
8297
8298 if ((lsb & shift_mask_high) == 0)
8299 return 0;
8300
8301 return high == -lsb;
8302 }
8303 if (high != ~0)
8304 return 0;
8305 }
8306
02071907 8307 shift_mask_low = ~0;
c5059423
AM
8308 shift_mask_low <<= INTVAL (shiftop);
8309
8310 lsb = low & -low;
8311
8312 if ((lsb & shift_mask_low) == 0)
8313 return 0;
8314
8315 return low == -lsb && lsb != 1;
8316 }
e2c953b6 8317 else
c5059423 8318 return 0;
9878760c 8319}
35068b43
RK
8320
8321/* Return 1 if REGNO (reg1) == REGNO (reg2) - 1 making them candidates
8322 for lfq and stfq insns.
8323
8324 Note reg1 and reg2 *must* be hard registers. To be sure we will
8325 abort if we are passed pseudo registers. */
8326
8327int
a2369ed3 8328registers_ok_for_quad_peep (rtx reg1, rtx reg2)
35068b43
RK
8329{
8330 /* We might have been passed a SUBREG. */
8331 if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG)
8332 return 0;
8333
8334 return (REGNO (reg1) == REGNO (reg2) - 1);
8335}
8336
a4f6c312
SS
8337/* Return 1 if addr1 and addr2 are suitable for lfq or stfq insn.
8338 addr1 and addr2 must be in consecutive memory locations
8339 (addr2 == addr1 + 8). */
35068b43
RK
8340
8341int
a2369ed3 8342addrs_ok_for_quad_peep (rtx addr1, rtx addr2)
35068b43 8343{
e2c953b6 8344 unsigned int reg1;
35068b43
RK
8345 int offset1;
8346
8347 /* Extract an offset (if used) from the first addr. */
8348 if (GET_CODE (addr1) == PLUS)
8349 {
8350 /* If not a REG, return zero. */
8351 if (GET_CODE (XEXP (addr1, 0)) != REG)
8352 return 0;
8353 else
8354 {
8355 reg1 = REGNO (XEXP (addr1, 0));
8356 /* The offset must be constant! */
8357 if (GET_CODE (XEXP (addr1, 1)) != CONST_INT)
8358 return 0;
8359 offset1 = INTVAL (XEXP (addr1, 1));
8360 }
8361 }
8362 else if (GET_CODE (addr1) != REG)
8363 return 0;
8364 else
8365 {
8366 reg1 = REGNO (addr1);
8367 /* This was a simple (mem (reg)) expression. Offset is 0. */
8368 offset1 = 0;
8369 }
8370
a2369ed3
DJ
8371 /* Make sure the second address is a (mem (plus (reg) (const_int)))
8372 or if it is (mem (reg)) then make sure that offset1 is -8 and the same
8373 register as addr1. */
984e25ac
DE
8374 if (offset1 == -8 && GET_CODE (addr2) == REG && reg1 == REGNO (addr2))
8375 return 1;
35068b43
RK
8376 if (GET_CODE (addr2) != PLUS)
8377 return 0;
8378
8379 if (GET_CODE (XEXP (addr2, 0)) != REG
8380 || GET_CODE (XEXP (addr2, 1)) != CONST_INT)
8381 return 0;
8382
8383 if (reg1 != REGNO (XEXP (addr2, 0)))
8384 return 0;
8385
8386 /* The offset for the second addr must be 8 more than the first addr. */
8387 if (INTVAL (XEXP (addr2, 1)) != offset1 + 8)
8388 return 0;
8389
8390 /* All the tests passed. addr1 and addr2 are valid for lfq or stfq
8391 instructions. */
8392 return 1;
8393}
9878760c
RK
8394\f
8395/* Return the register class of a scratch register needed to copy IN into
8396 or out of a register in CLASS in MODE. If it can be done directly,
8397 NO_REGS is returned. */
8398
8399enum reg_class
a2369ed3 8400secondary_reload_class (enum reg_class class,
a9baceb1
GK
8401 enum machine_mode mode ATTRIBUTE_UNUSED,
8402 rtx in)
9878760c 8403{
5accd822 8404 int regno;
9878760c 8405
ab82a49f
AP
8406 if (TARGET_ELF || (DEFAULT_ABI == ABI_DARWIN
8407#if TARGET_MACHO
8408 && MACHOPIC_INDIRECT
8409#endif
8410 ))
46fad5b7
DJ
8411 {
8412 /* We cannot copy a symbolic operand directly into anything
8413 other than BASE_REGS for TARGET_ELF. So indicate that a
8414 register from BASE_REGS is needed as an intermediate
8415 register.
8416
8417 On Darwin, pic addresses require a load from memory, which
8418 needs a base register. */
8419 if (class != BASE_REGS
8420 && (GET_CODE (in) == SYMBOL_REF
8421 || GET_CODE (in) == HIGH
8422 || GET_CODE (in) == LABEL_REF
8423 || GET_CODE (in) == CONST))
8424 return BASE_REGS;
8425 }
e7b7998a 8426
5accd822
DE
8427 if (GET_CODE (in) == REG)
8428 {
8429 regno = REGNO (in);
8430 if (regno >= FIRST_PSEUDO_REGISTER)
8431 {
8432 regno = true_regnum (in);
8433 if (regno >= FIRST_PSEUDO_REGISTER)
8434 regno = -1;
8435 }
8436 }
8437 else if (GET_CODE (in) == SUBREG)
8438 {
8439 regno = true_regnum (in);
8440 if (regno >= FIRST_PSEUDO_REGISTER)
8441 regno = -1;
8442 }
8443 else
8444 regno = -1;
8445
9878760c
RK
8446 /* We can place anything into GENERAL_REGS and can put GENERAL_REGS
8447 into anything. */
8448 if (class == GENERAL_REGS || class == BASE_REGS
8449 || (regno >= 0 && INT_REGNO_P (regno)))
8450 return NO_REGS;
8451
8452 /* Constants, memory, and FP registers can go into FP registers. */
8453 if ((regno == -1 || FP_REGNO_P (regno))
8454 && (class == FLOAT_REGS || class == NON_SPECIAL_REGS))
8455 return NO_REGS;
8456
0ac081f6
AH
8457 /* Memory, and AltiVec registers can go into AltiVec registers. */
8458 if ((regno == -1 || ALTIVEC_REGNO_P (regno))
8459 && class == ALTIVEC_REGS)
8460 return NO_REGS;
8461
9878760c
RK
8462 /* We can copy among the CR registers. */
8463 if ((class == CR_REGS || class == CR0_REGS)
8464 && regno >= 0 && CR_REGNO_P (regno))
8465 return NO_REGS;
8466
8467 /* Otherwise, we need GENERAL_REGS. */
8468 return GENERAL_REGS;
8469}
8470\f
8471/* Given a comparison operation, return the bit number in CCR to test. We
8472 know this is a valid comparison.
8473
8474 SCC_P is 1 if this is for an scc. That means that %D will have been
8475 used instead of %C, so the bits will be in different places.
8476
b4ac57ab 8477 Return -1 if OP isn't a valid comparison for some reason. */
9878760c
RK
8478
8479int
a2369ed3 8480ccr_bit (rtx op, int scc_p)
9878760c
RK
8481{
8482 enum rtx_code code = GET_CODE (op);
8483 enum machine_mode cc_mode;
8484 int cc_regnum;
8485 int base_bit;
9ebbca7d 8486 rtx reg;
9878760c
RK
8487
8488 if (GET_RTX_CLASS (code) != '<')
8489 return -1;
8490
9ebbca7d
GK
8491 reg = XEXP (op, 0);
8492
8493 if (GET_CODE (reg) != REG
8494 || ! CR_REGNO_P (REGNO (reg)))
8495 abort ();
8496
8497 cc_mode = GET_MODE (reg);
8498 cc_regnum = REGNO (reg);
8499 base_bit = 4 * (cc_regnum - CR0_REGNO);
9878760c 8500
39a10a29 8501 validate_condition_mode (code, cc_mode);
c5defebb 8502
b7053a3f
GK
8503 /* When generating a sCOND operation, only positive conditions are
8504 allowed. */
8505 if (scc_p && code != EQ && code != GT && code != LT && code != UNORDERED
8506 && code != GTU && code != LTU)
8507 abort ();
8508
9878760c
RK
8509 switch (code)
8510 {
8511 case NE:
993f19a8
AH
8512 if (TARGET_E500 && !TARGET_FPRS
8513 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8514 return base_bit + 1;
9878760c
RK
8515 return scc_p ? base_bit + 3 : base_bit + 2;
8516 case EQ:
993f19a8
AH
8517 if (TARGET_E500 && !TARGET_FPRS
8518 && TARGET_HARD_FLOAT && cc_mode == CCFPmode)
a3170dc6 8519 return base_bit + 1;
9878760c 8520 return base_bit + 2;
1c882ea4 8521 case GT: case GTU: case UNLE:
9878760c 8522 return base_bit + 1;
1c882ea4 8523 case LT: case LTU: case UNGE:
9878760c 8524 return base_bit;
1c882ea4
GK
8525 case ORDERED: case UNORDERED:
8526 return base_bit + 3;
9878760c
RK
8527
8528 case GE: case GEU:
39a10a29 8529 /* If scc, we will have done a cror to put the bit in the
9878760c
RK
8530 unordered position. So test that bit. For integer, this is ! LT
8531 unless this is an scc insn. */
39a10a29 8532 return scc_p ? base_bit + 3 : base_bit;
9878760c
RK
8533
8534 case LE: case LEU:
39a10a29 8535 return scc_p ? base_bit + 3 : base_bit + 1;
1c882ea4 8536
9878760c
RK
8537 default:
8538 abort ();
8539 }
8540}
1ff7789b 8541\f
8d30c4ee 8542/* Return the GOT register. */
1ff7789b
MM
8543
8544struct rtx_def *
a2369ed3 8545rs6000_got_register (rtx value ATTRIBUTE_UNUSED)
1ff7789b 8546{
a4f6c312
SS
8547 /* The second flow pass currently (June 1999) can't update
8548 regs_ever_live without disturbing other parts of the compiler, so
8549 update it here to make the prolog/epilogue code happy. */
1db02437
FS
8550 if (no_new_pseudos && ! regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM])
8551 regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM] = 1;
1ff7789b 8552
8d30c4ee 8553 current_function_uses_pic_offset_table = 1;
3cb999d8 8554
1ff7789b
MM
8555 return pic_offset_table_rtx;
8556}
a7df97e6 8557\f
e2500fed
GK
8558/* Function to init struct machine_function.
8559 This will be called, via a pointer variable,
8560 from push_function_context. */
a7df97e6 8561
e2500fed 8562static struct machine_function *
863d938c 8563rs6000_init_machine_status (void)
a7df97e6 8564{
e2500fed 8565 return ggc_alloc_cleared (sizeof (machine_function));
a7df97e6 8566}
9878760c 8567\f
0ba1b2ff
AM
8568/* These macros test for integers and extract the low-order bits. */
8569#define INT_P(X) \
8570((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
8571 && GET_MODE (X) == VOIDmode)
8572
8573#define INT_LOWPART(X) \
8574 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
8575
8576int
a2369ed3 8577extract_MB (rtx op)
0ba1b2ff
AM
8578{
8579 int i;
8580 unsigned long val = INT_LOWPART (op);
8581
8582 /* If the high bit is zero, the value is the first 1 bit we find
8583 from the left. */
8584 if ((val & 0x80000000) == 0)
8585 {
8586 if ((val & 0xffffffff) == 0)
8587 abort ();
8588
8589 i = 1;
8590 while (((val <<= 1) & 0x80000000) == 0)
8591 ++i;
8592 return i;
8593 }
8594
8595 /* If the high bit is set and the low bit is not, or the mask is all
8596 1's, the value is zero. */
8597 if ((val & 1) == 0 || (val & 0xffffffff) == 0xffffffff)
8598 return 0;
8599
8600 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8601 from the right. */
8602 i = 31;
8603 while (((val >>= 1) & 1) != 0)
8604 --i;
8605
8606 return i;
8607}
8608
8609int
a2369ed3 8610extract_ME (rtx op)
0ba1b2ff
AM
8611{
8612 int i;
8613 unsigned long val = INT_LOWPART (op);
8614
8615 /* If the low bit is zero, the value is the first 1 bit we find from
8616 the right. */
8617 if ((val & 1) == 0)
8618 {
8619 if ((val & 0xffffffff) == 0)
8620 abort ();
8621
8622 i = 30;
8623 while (((val >>= 1) & 1) == 0)
8624 --i;
8625
8626 return i;
8627 }
8628
8629 /* If the low bit is set and the high bit is not, or the mask is all
8630 1's, the value is 31. */
8631 if ((val & 0x80000000) == 0 || (val & 0xffffffff) == 0xffffffff)
8632 return 31;
8633
8634 /* Otherwise we have a wrap-around mask. Look for the first 0 bit
8635 from the left. */
8636 i = 0;
8637 while (((val <<= 1) & 0x80000000) != 0)
8638 ++i;
8639
8640 return i;
8641}
8642
c4501e62
JJ
8643/* Locate some local-dynamic symbol still in use by this function
8644 so that we can print its name in some tls_ld pattern. */
8645
8646static const char *
863d938c 8647rs6000_get_some_local_dynamic_name (void)
c4501e62
JJ
8648{
8649 rtx insn;
8650
8651 if (cfun->machine->some_ld_name)
8652 return cfun->machine->some_ld_name;
8653
8654 for (insn = get_insns (); insn ; insn = NEXT_INSN (insn))
8655 if (INSN_P (insn)
8656 && for_each_rtx (&PATTERN (insn),
8657 rs6000_get_some_local_dynamic_name_1, 0))
8658 return cfun->machine->some_ld_name;
8659
8660 abort ();
8661}
8662
8663/* Helper function for rs6000_get_some_local_dynamic_name. */
8664
8665static int
a2369ed3 8666rs6000_get_some_local_dynamic_name_1 (rtx *px, void *data ATTRIBUTE_UNUSED)
c4501e62
JJ
8667{
8668 rtx x = *px;
8669
8670 if (GET_CODE (x) == SYMBOL_REF)
8671 {
8672 const char *str = XSTR (x, 0);
8673 if (SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC)
8674 {
8675 cfun->machine->some_ld_name = str;
8676 return 1;
8677 }
8678 }
8679
8680 return 0;
8681}
8682
9878760c
RK
8683/* Print an operand. Recognize special options, documented below. */
8684
38c1f2d7 8685#if TARGET_ELF
d9407988 8686#define SMALL_DATA_RELOC ((rs6000_sdata == SDATA_EABI) ? "sda21" : "sdarel")
8fbd2dc7 8687#define SMALL_DATA_REG ((rs6000_sdata == SDATA_EABI) ? 0 : 13)
ba5e43aa
MM
8688#else
8689#define SMALL_DATA_RELOC "sda21"
8fbd2dc7 8690#define SMALL_DATA_REG 0
ba5e43aa
MM
8691#endif
8692
9878760c 8693void
a2369ed3 8694print_operand (FILE *file, rtx x, int code)
9878760c
RK
8695{
8696 int i;
a260abc9 8697 HOST_WIDE_INT val;
0ba1b2ff 8698 unsigned HOST_WIDE_INT uval;
9878760c
RK
8699
8700 switch (code)
8701 {
a8b3aeda 8702 case '.':
a85d226b
RK
8703 /* Write out an instruction after the call which may be replaced
8704 with glue code by the loader. This depends on the AIX version. */
8705 asm_fprintf (file, RS6000_CALL_GLUE);
a8b3aeda
RK
8706 return;
8707
81eace42
GK
8708 /* %a is output_address. */
8709
9854d9ed
RK
8710 case 'A':
8711 /* If X is a constant integer whose low-order 5 bits are zero,
8712 write 'l'. Otherwise, write 'r'. This is a kludge to fix a bug
76229ac8 8713 in the AIX assembler where "sri" with a zero shift count
20e26713 8714 writes a trash instruction. */
9854d9ed 8715 if (GET_CODE (x) == CONST_INT && (INTVAL (x) & 31) == 0)
76229ac8 8716 putc ('l', file);
9854d9ed 8717 else
76229ac8 8718 putc ('r', file);
9854d9ed
RK
8719 return;
8720
8721 case 'b':
e2c953b6
DE
8722 /* If constant, low-order 16 bits of constant, unsigned.
8723 Otherwise, write normally. */
8724 if (INT_P (x))
8725 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 0xffff);
8726 else
8727 print_operand (file, x, 0);
cad12a8d
RK
8728 return;
8729
a260abc9
DE
8730 case 'B':
8731 /* If the low-order bit is zero, write 'r'; otherwise, write 'l'
8732 for 64-bit mask direction. */
296b8152 8733 putc (((INT_LOWPART(x) & 1) == 0 ? 'r' : 'l'), file);
a238cd8b 8734 return;
a260abc9 8735
81eace42
GK
8736 /* %c is output_addr_const if a CONSTANT_ADDRESS_P, otherwise
8737 output_operand. */
8738
9854d9ed 8739 case 'E':
39a10a29 8740 /* X is a CR register. Print the number of the EQ bit of the CR */
9854d9ed
RK
8741 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8742 output_operand_lossage ("invalid %%E value");
78fbdbf7 8743 else
39a10a29 8744 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO) + 2);
a85d226b 8745 return;
9854d9ed
RK
8746
8747 case 'f':
8748 /* X is a CR register. Print the shift count needed to move it
8749 to the high-order four bits. */
8750 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8751 output_operand_lossage ("invalid %%f value");
8752 else
9ebbca7d 8753 fprintf (file, "%d", 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8754 return;
8755
8756 case 'F':
8757 /* Similar, but print the count for the rotate in the opposite
8758 direction. */
8759 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8760 output_operand_lossage ("invalid %%F value");
8761 else
9ebbca7d 8762 fprintf (file, "%d", 32 - 4 * (REGNO (x) - CR0_REGNO));
9854d9ed
RK
8763 return;
8764
8765 case 'G':
8766 /* X is a constant integer. If it is negative, print "m",
43aa4e05 8767 otherwise print "z". This is to make an aze or ame insn. */
9854d9ed
RK
8768 if (GET_CODE (x) != CONST_INT)
8769 output_operand_lossage ("invalid %%G value");
8770 else if (INTVAL (x) >= 0)
76229ac8 8771 putc ('z', file);
9854d9ed 8772 else
76229ac8 8773 putc ('m', file);
9854d9ed 8774 return;
e2c953b6 8775
9878760c 8776 case 'h':
a4f6c312
SS
8777 /* If constant, output low-order five bits. Otherwise, write
8778 normally. */
9878760c 8779 if (INT_P (x))
5f59ecb7 8780 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 31);
9878760c
RK
8781 else
8782 print_operand (file, x, 0);
8783 return;
8784
64305719 8785 case 'H':
a4f6c312
SS
8786 /* If constant, output low-order six bits. Otherwise, write
8787 normally. */
64305719 8788 if (INT_P (x))
5f59ecb7 8789 fprintf (file, HOST_WIDE_INT_PRINT_DEC, INT_LOWPART (x) & 63);
64305719
DE
8790 else
8791 print_operand (file, x, 0);
8792 return;
8793
9854d9ed
RK
8794 case 'I':
8795 /* Print `i' if this is a constant, else nothing. */
9878760c 8796 if (INT_P (x))
76229ac8 8797 putc ('i', file);
9878760c
RK
8798 return;
8799
9854d9ed
RK
8800 case 'j':
8801 /* Write the bit number in CCR for jump. */
8802 i = ccr_bit (x, 0);
8803 if (i == -1)
8804 output_operand_lossage ("invalid %%j code");
9878760c 8805 else
9854d9ed 8806 fprintf (file, "%d", i);
9878760c
RK
8807 return;
8808
9854d9ed
RK
8809 case 'J':
8810 /* Similar, but add one for shift count in rlinm for scc and pass
8811 scc flag to `ccr_bit'. */
8812 i = ccr_bit (x, 1);
8813 if (i == -1)
8814 output_operand_lossage ("invalid %%J code");
8815 else
a0466a68
RK
8816 /* If we want bit 31, write a shift count of zero, not 32. */
8817 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9878760c
RK
8818 return;
8819
9854d9ed
RK
8820 case 'k':
8821 /* X must be a constant. Write the 1's complement of the
8822 constant. */
9878760c 8823 if (! INT_P (x))
9854d9ed 8824 output_operand_lossage ("invalid %%k value");
e2c953b6
DE
8825 else
8826 fprintf (file, HOST_WIDE_INT_PRINT_DEC, ~ INT_LOWPART (x));
9878760c
RK
8827 return;
8828
81eace42 8829 case 'K':
9ebbca7d
GK
8830 /* X must be a symbolic constant on ELF. Write an
8831 expression suitable for an 'addi' that adds in the low 16
8832 bits of the MEM. */
8833 if (GET_CODE (x) != CONST)
8834 {
8835 print_operand_address (file, x);
8836 fputs ("@l", file);
8837 }
8838 else
8839 {
8840 if (GET_CODE (XEXP (x, 0)) != PLUS
8841 || (GET_CODE (XEXP (XEXP (x, 0), 0)) != SYMBOL_REF
8842 && GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
8843 || GET_CODE (XEXP (XEXP (x, 0), 1)) != CONST_INT)
53cd5d6c 8844 output_operand_lossage ("invalid %%K value");
9ebbca7d
GK
8845 print_operand_address (file, XEXP (XEXP (x, 0), 0));
8846 fputs ("@l", file);
ed8d2920
MM
8847 /* For GNU as, there must be a non-alphanumeric character
8848 between 'l' and the number. The '-' is added by
8849 print_operand() already. */
8850 if (INTVAL (XEXP (XEXP (x, 0), 1)) >= 0)
8851 fputs ("+", file);
9ebbca7d
GK
8852 print_operand (file, XEXP (XEXP (x, 0), 1), 0);
8853 }
81eace42
GK
8854 return;
8855
8856 /* %l is output_asm_label. */
9ebbca7d 8857
9854d9ed
RK
8858 case 'L':
8859 /* Write second word of DImode or DFmode reference. Works on register
8860 or non-indexed memory only. */
8861 if (GET_CODE (x) == REG)
5ebfb2ba 8862 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
9854d9ed
RK
8863 else if (GET_CODE (x) == MEM)
8864 {
8865 /* Handle possible auto-increment. Since it is pre-increment and
1427100a 8866 we have already done it, we can just use an offset of word. */
9854d9ed
RK
8867 if (GET_CODE (XEXP (x, 0)) == PRE_INC
8868 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
ed8908e7
RK
8869 output_address (plus_constant (XEXP (XEXP (x, 0), 0),
8870 UNITS_PER_WORD));
9854d9ed 8871 else
d7624dc0
RK
8872 output_address (XEXP (adjust_address_nv (x, SImode,
8873 UNITS_PER_WORD),
8874 0));
ed8908e7 8875
ba5e43aa 8876 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
8877 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
8878 reg_names[SMALL_DATA_REG]);
9854d9ed 8879 }
9878760c 8880 return;
9854d9ed 8881
9878760c
RK
8882 case 'm':
8883 /* MB value for a mask operand. */
b1765bde 8884 if (! mask_operand (x, SImode))
9878760c
RK
8885 output_operand_lossage ("invalid %%m value");
8886
0ba1b2ff 8887 fprintf (file, "%d", extract_MB (x));
9878760c
RK
8888 return;
8889
8890 case 'M':
8891 /* ME value for a mask operand. */
b1765bde 8892 if (! mask_operand (x, SImode))
a260abc9 8893 output_operand_lossage ("invalid %%M value");
9878760c 8894
0ba1b2ff 8895 fprintf (file, "%d", extract_ME (x));
9878760c
RK
8896 return;
8897
81eace42
GK
8898 /* %n outputs the negative of its operand. */
8899
9878760c
RK
8900 case 'N':
8901 /* Write the number of elements in the vector times 4. */
8902 if (GET_CODE (x) != PARALLEL)
8903 output_operand_lossage ("invalid %%N value");
e2c953b6
DE
8904 else
8905 fprintf (file, "%d", XVECLEN (x, 0) * 4);
9878760c
RK
8906 return;
8907
8908 case 'O':
8909 /* Similar, but subtract 1 first. */
8910 if (GET_CODE (x) != PARALLEL)
1427100a 8911 output_operand_lossage ("invalid %%O value");
e2c953b6
DE
8912 else
8913 fprintf (file, "%d", (XVECLEN (x, 0) - 1) * 4);
9878760c
RK
8914 return;
8915
9854d9ed
RK
8916 case 'p':
8917 /* X is a CONST_INT that is a power of two. Output the logarithm. */
8918 if (! INT_P (x)
2bfcf297 8919 || INT_LOWPART (x) < 0
9854d9ed
RK
8920 || (i = exact_log2 (INT_LOWPART (x))) < 0)
8921 output_operand_lossage ("invalid %%p value");
e2c953b6
DE
8922 else
8923 fprintf (file, "%d", i);
9854d9ed
RK
8924 return;
8925
9878760c
RK
8926 case 'P':
8927 /* The operand must be an indirect memory reference. The result
a4f6c312 8928 is the register number. */
9878760c
RK
8929 if (GET_CODE (x) != MEM || GET_CODE (XEXP (x, 0)) != REG
8930 || REGNO (XEXP (x, 0)) >= 32)
8931 output_operand_lossage ("invalid %%P value");
e2c953b6
DE
8932 else
8933 fprintf (file, "%d", REGNO (XEXP (x, 0)));
9878760c
RK
8934 return;
8935
dfbdccdb
GK
8936 case 'q':
8937 /* This outputs the logical code corresponding to a boolean
8938 expression. The expression may have one or both operands
39a10a29
GK
8939 negated (if one, only the first one). For condition register
8940 logical operations, it will also treat the negated
8941 CR codes as NOTs, but not handle NOTs of them. */
dfbdccdb 8942 {
63bc1d05 8943 const char *const *t = 0;
dfbdccdb
GK
8944 const char *s;
8945 enum rtx_code code = GET_CODE (x);
8946 static const char * const tbl[3][3] = {
8947 { "and", "andc", "nor" },
8948 { "or", "orc", "nand" },
8949 { "xor", "eqv", "xor" } };
8950
8951 if (code == AND)
8952 t = tbl[0];
8953 else if (code == IOR)
8954 t = tbl[1];
8955 else if (code == XOR)
8956 t = tbl[2];
8957 else
8958 output_operand_lossage ("invalid %%q value");
8959
8960 if (GET_CODE (XEXP (x, 0)) != NOT)
8961 s = t[0];
8962 else
8963 {
8964 if (GET_CODE (XEXP (x, 1)) == NOT)
8965 s = t[2];
8966 else
8967 s = t[1];
8968 }
8969
8970 fputs (s, file);
8971 }
8972 return;
8973
2c4a9cff
DE
8974 case 'Q':
8975 if (TARGET_MFCRF)
8976 fputc (',',file);
59b9a953 8977 /* Fall through. */
2c4a9cff
DE
8978 else
8979 return;
8980
9854d9ed
RK
8981 case 'R':
8982 /* X is a CR register. Print the mask for `mtcrf'. */
8983 if (GET_CODE (x) != REG || ! CR_REGNO_P (REGNO (x)))
8984 output_operand_lossage ("invalid %%R value");
8985 else
9ebbca7d 8986 fprintf (file, "%d", 128 >> (REGNO (x) - CR0_REGNO));
9878760c 8987 return;
9854d9ed
RK
8988
8989 case 's':
8990 /* Low 5 bits of 32 - value */
8991 if (! INT_P (x))
8992 output_operand_lossage ("invalid %%s value");
e2c953b6
DE
8993 else
8994 fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INT_LOWPART (x)) & 31);
9878760c 8995 return;
9854d9ed 8996
a260abc9 8997 case 'S':
0ba1b2ff 8998 /* PowerPC64 mask position. All 0's is excluded.
a260abc9
DE
8999 CONST_INT 32-bit mask is considered sign-extended so any
9000 transition must occur within the CONST_INT, not on the boundary. */
b1765bde 9001 if (! mask64_operand (x, DImode))
a260abc9
DE
9002 output_operand_lossage ("invalid %%S value");
9003
0ba1b2ff 9004 uval = INT_LOWPART (x);
a260abc9 9005
0ba1b2ff 9006 if (uval & 1) /* Clear Left */
a260abc9 9007 {
f099d360
GK
9008#if HOST_BITS_PER_WIDE_INT > 64
9009 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9010#endif
0ba1b2ff 9011 i = 64;
a260abc9 9012 }
0ba1b2ff 9013 else /* Clear Right */
a260abc9 9014 {
0ba1b2ff 9015 uval = ~uval;
f099d360
GK
9016#if HOST_BITS_PER_WIDE_INT > 64
9017 uval &= ((unsigned HOST_WIDE_INT) 1 << 64) - 1;
9018#endif
0ba1b2ff 9019 i = 63;
a260abc9 9020 }
0ba1b2ff
AM
9021 while (uval != 0)
9022 --i, uval >>= 1;
9023 if (i < 0)
9024 abort ();
9025 fprintf (file, "%d", i);
9026 return;
a260abc9 9027
a3170dc6
AH
9028 case 't':
9029 /* Like 'J' but get to the OVERFLOW/UNORDERED bit. */
9030 if (GET_CODE (x) != REG || GET_MODE (x) != CCmode)
9031 abort ();
9032
9033 /* Bit 3 is OV bit. */
9034 i = 4 * (REGNO (x) - CR0_REGNO) + 3;
9035
9036 /* If we want bit 31, write a shift count of zero, not 32. */
9037 fprintf (file, "%d", i == 31 ? 0 : i + 1);
9038 return;
9039
cccf3bdc
DE
9040 case 'T':
9041 /* Print the symbolic name of a branch target register. */
9042 if (GET_CODE (x) != REG || (REGNO (x) != LINK_REGISTER_REGNUM
9043 && REGNO (x) != COUNT_REGISTER_REGNUM))
9044 output_operand_lossage ("invalid %%T value");
e2c953b6 9045 else if (REGNO (x) == LINK_REGISTER_REGNUM)
cccf3bdc
DE
9046 fputs (TARGET_NEW_MNEMONICS ? "lr" : "r", file);
9047 else
9048 fputs ("ctr", file);
9049 return;
9050
9854d9ed 9051 case 'u':
802a0058 9052 /* High-order 16 bits of constant for use in unsigned operand. */
9854d9ed
RK
9053 if (! INT_P (x))
9054 output_operand_lossage ("invalid %%u value");
e2c953b6
DE
9055 else
9056 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9057 (INT_LOWPART (x) >> 16) & 0xffff);
9878760c
RK
9058 return;
9059
802a0058
MM
9060 case 'v':
9061 /* High-order 16 bits of constant for use in signed operand. */
9062 if (! INT_P (x))
9063 output_operand_lossage ("invalid %%v value");
e2c953b6 9064 else
134c32f6
DE
9065 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
9066 (INT_LOWPART (x) >> 16) & 0xffff);
9067 return;
802a0058 9068
9854d9ed
RK
9069 case 'U':
9070 /* Print `u' if this has an auto-increment or auto-decrement. */
9071 if (GET_CODE (x) == MEM
9072 && (GET_CODE (XEXP (x, 0)) == PRE_INC
9073 || GET_CODE (XEXP (x, 0)) == PRE_DEC))
76229ac8 9074 putc ('u', file);
9854d9ed 9075 return;
9878760c 9076
e0cd0770
JC
9077 case 'V':
9078 /* Print the trap code for this operand. */
9079 switch (GET_CODE (x))
9080 {
9081 case EQ:
9082 fputs ("eq", file); /* 4 */
9083 break;
9084 case NE:
9085 fputs ("ne", file); /* 24 */
9086 break;
9087 case LT:
9088 fputs ("lt", file); /* 16 */
9089 break;
9090 case LE:
9091 fputs ("le", file); /* 20 */
9092 break;
9093 case GT:
9094 fputs ("gt", file); /* 8 */
9095 break;
9096 case GE:
9097 fputs ("ge", file); /* 12 */
9098 break;
9099 case LTU:
9100 fputs ("llt", file); /* 2 */
9101 break;
9102 case LEU:
9103 fputs ("lle", file); /* 6 */
9104 break;
9105 case GTU:
9106 fputs ("lgt", file); /* 1 */
9107 break;
9108 case GEU:
9109 fputs ("lge", file); /* 5 */
9110 break;
9111 default:
9112 abort ();
9113 }
9114 break;
9115
9854d9ed
RK
9116 case 'w':
9117 /* If constant, low-order 16 bits of constant, signed. Otherwise, write
9118 normally. */
9119 if (INT_P (x))
5f59ecb7
DE
9120 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
9121 ((INT_LOWPART (x) & 0xffff) ^ 0x8000) - 0x8000);
9854d9ed
RK
9122 else
9123 print_operand (file, x, 0);
9878760c
RK
9124 return;
9125
9854d9ed 9126 case 'W':
e2c953b6 9127 /* MB value for a PowerPC64 rldic operand. */
e2c953b6
DE
9128 val = (GET_CODE (x) == CONST_INT
9129 ? INTVAL (x) : CONST_DOUBLE_HIGH (x));
9130
9131 if (val < 0)
9132 i = -1;
9854d9ed 9133 else
e2c953b6
DE
9134 for (i = 0; i < HOST_BITS_PER_WIDE_INT; i++)
9135 if ((val <<= 1) < 0)
9136 break;
9137
9138#if HOST_BITS_PER_WIDE_INT == 32
9139 if (GET_CODE (x) == CONST_INT && i >= 0)
9140 i += 32; /* zero-extend high-part was all 0's */
9141 else if (GET_CODE (x) == CONST_DOUBLE && i == 32)
9142 {
9143 val = CONST_DOUBLE_LOW (x);
9144
9145 if (val == 0)
a4f6c312 9146 abort ();
e2c953b6
DE
9147 else if (val < 0)
9148 --i;
9149 else
9150 for ( ; i < 64; i++)
9151 if ((val <<= 1) < 0)
9152 break;
9153 }
9154#endif
9155
9156 fprintf (file, "%d", i + 1);
9854d9ed 9157 return;
9878760c 9158
9854d9ed
RK
9159 case 'X':
9160 if (GET_CODE (x) == MEM
4d588c14 9161 && legitimate_indexed_address_p (XEXP (x, 0), 0))
76229ac8 9162 putc ('x', file);
9854d9ed 9163 return;
9878760c 9164
9854d9ed
RK
9165 case 'Y':
9166 /* Like 'L', for third word of TImode */
9167 if (GET_CODE (x) == REG)
5ebfb2ba 9168 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
9854d9ed 9169 else if (GET_CODE (x) == MEM)
9878760c 9170 {
9854d9ed
RK
9171 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9172 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9173 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 8));
9854d9ed 9174 else
d7624dc0 9175 output_address (XEXP (adjust_address_nv (x, SImode, 8), 0));
ba5e43aa 9176 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9177 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9178 reg_names[SMALL_DATA_REG]);
9878760c
RK
9179 }
9180 return;
9854d9ed 9181
9878760c 9182 case 'z':
b4ac57ab
RS
9183 /* X is a SYMBOL_REF. Write out the name preceded by a
9184 period and without any trailing data in brackets. Used for function
4d30c363
MM
9185 names. If we are configured for System V (or the embedded ABI) on
9186 the PowerPC, do not emit the period, since those systems do not use
9187 TOCs and the like. */
9878760c
RK
9188 if (GET_CODE (x) != SYMBOL_REF)
9189 abort ();
9190
b6c9286a
MM
9191 if (XSTR (x, 0)[0] != '.')
9192 {
9193 switch (DEFAULT_ABI)
9194 {
9195 default:
9196 abort ();
9197
9198 case ABI_AIX:
9199 putc ('.', file);
9200 break;
9201
9202 case ABI_V4:
ee890fe2 9203 case ABI_DARWIN:
b6c9286a 9204 break;
b6c9286a
MM
9205 }
9206 }
9739c90c
JJ
9207 if (TARGET_AIX)
9208 RS6000_OUTPUT_BASENAME (file, XSTR (x, 0));
9209 else
9210 assemble_name (file, XSTR (x, 0));
9878760c
RK
9211 return;
9212
9854d9ed
RK
9213 case 'Z':
9214 /* Like 'L', for last word of TImode. */
9215 if (GET_CODE (x) == REG)
5ebfb2ba 9216 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
9854d9ed
RK
9217 else if (GET_CODE (x) == MEM)
9218 {
9219 if (GET_CODE (XEXP (x, 0)) == PRE_INC
9220 || GET_CODE (XEXP (x, 0)) == PRE_DEC)
a54d04b7 9221 output_address (plus_constant (XEXP (XEXP (x, 0), 0), 12));
9854d9ed 9222 else
d7624dc0 9223 output_address (XEXP (adjust_address_nv (x, SImode, 12), 0));
ba5e43aa 9224 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9225 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9226 reg_names[SMALL_DATA_REG]);
9854d9ed 9227 }
5c23c401 9228 return;
0ac081f6 9229
a3170dc6 9230 /* Print AltiVec or SPE memory operand. */
0ac081f6
AH
9231 case 'y':
9232 {
9233 rtx tmp;
9234
9235 if (GET_CODE (x) != MEM)
9236 abort ();
9237
9238 tmp = XEXP (x, 0);
9239
993f19a8 9240 if (TARGET_E500)
a3170dc6
AH
9241 {
9242 /* Handle [reg]. */
9243 if (GET_CODE (tmp) == REG)
9244 {
9245 fprintf (file, "0(%s)", reg_names[REGNO (tmp)]);
9246 break;
9247 }
9248 /* Handle [reg+UIMM]. */
9249 else if (GET_CODE (tmp) == PLUS &&
9250 GET_CODE (XEXP (tmp, 1)) == CONST_INT)
9251 {
9252 int x;
9253
9254 if (GET_CODE (XEXP (tmp, 0)) != REG)
9255 abort ();
9256
9257 x = INTVAL (XEXP (tmp, 1));
9258 fprintf (file, "%d(%s)", x, reg_names[REGNO (XEXP (tmp, 0))]);
9259 break;
9260 }
9261
9262 /* Fall through. Must be [reg+reg]. */
9263 }
0ac081f6 9264 if (GET_CODE (tmp) == REG)
c62f2db5 9265 fprintf (file, "0,%s", reg_names[REGNO (tmp)]);
0ac081f6
AH
9266 else if (GET_CODE (tmp) == PLUS && GET_CODE (XEXP (tmp, 1)) == REG)
9267 {
9268 if (REGNO (XEXP (tmp, 0)) == 0)
9269 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 1)) ],
9270 reg_names[ REGNO (XEXP (tmp, 0)) ]);
9271 else
9272 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (tmp, 0)) ],
9273 reg_names[ REGNO (XEXP (tmp, 1)) ]);
9274 }
9275 else
9276 abort ();
9277 break;
9278 }
9854d9ed 9279
9878760c
RK
9280 case 0:
9281 if (GET_CODE (x) == REG)
9282 fprintf (file, "%s", reg_names[REGNO (x)]);
9283 else if (GET_CODE (x) == MEM)
9284 {
9285 /* We need to handle PRE_INC and PRE_DEC here, since we need to
9286 know the width from the mode. */
9287 if (GET_CODE (XEXP (x, 0)) == PRE_INC)
79ba6d34
MM
9288 fprintf (file, "%d(%s)", GET_MODE_SIZE (GET_MODE (x)),
9289 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9290 else if (GET_CODE (XEXP (x, 0)) == PRE_DEC)
79ba6d34
MM
9291 fprintf (file, "%d(%s)", - GET_MODE_SIZE (GET_MODE (x)),
9292 reg_names[REGNO (XEXP (XEXP (x, 0), 0))]);
9878760c 9293 else
a54d04b7 9294 output_address (XEXP (x, 0));
9878760c
RK
9295 }
9296 else
a54d04b7 9297 output_addr_const (file, x);
a85d226b 9298 return;
9878760c 9299
c4501e62
JJ
9300 case '&':
9301 assemble_name (file, rs6000_get_some_local_dynamic_name ());
9302 return;
9303
9878760c
RK
9304 default:
9305 output_operand_lossage ("invalid %%xn code");
9306 }
9307}
9308\f
9309/* Print the address of an operand. */
9310
9311void
a2369ed3 9312print_operand_address (FILE *file, rtx x)
9878760c
RK
9313{
9314 if (GET_CODE (x) == REG)
4697a36c 9315 fprintf (file, "0(%s)", reg_names[ REGNO (x) ]);
9ebbca7d
GK
9316 else if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == CONST
9317 || GET_CODE (x) == LABEL_REF)
9878760c
RK
9318 {
9319 output_addr_const (file, x);
ba5e43aa 9320 if (small_data_operand (x, GET_MODE (x)))
8fbd2dc7
MM
9321 fprintf (file, "@%s(%s)", SMALL_DATA_RELOC,
9322 reg_names[SMALL_DATA_REG]);
9ebbca7d 9323 else if (TARGET_TOC)
a4f6c312 9324 abort ();
9878760c
RK
9325 }
9326 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG)
9327 {
9328 if (REGNO (XEXP (x, 0)) == 0)
4697a36c
MM
9329 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 1)) ],
9330 reg_names[ REGNO (XEXP (x, 0)) ]);
9878760c 9331 else
4697a36c
MM
9332 fprintf (file, "%s,%s", reg_names[ REGNO (XEXP (x, 0)) ],
9333 reg_names[ REGNO (XEXP (x, 1)) ]);
9878760c
RK
9334 }
9335 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
4a0a75dd
KG
9336 fprintf (file, HOST_WIDE_INT_PRINT_DEC "(%s)",
9337 INTVAL (XEXP (x, 1)), reg_names[ REGNO (XEXP (x, 0)) ]);
3cb999d8
DE
9338#if TARGET_ELF
9339 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9340 && CONSTANT_P (XEXP (x, 1)))
4697a36c
MM
9341 {
9342 output_addr_const (file, XEXP (x, 1));
9343 fprintf (file, "@l(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9344 }
c859cda6
DJ
9345#endif
9346#if TARGET_MACHO
9347 else if (GET_CODE (x) == LO_SUM && GET_CODE (XEXP (x, 0)) == REG
9348 && CONSTANT_P (XEXP (x, 1)))
9349 {
9350 fprintf (file, "lo16(");
9351 output_addr_const (file, XEXP (x, 1));
9352 fprintf (file, ")(%s)", reg_names[ REGNO (XEXP (x, 0)) ]);
9353 }
3cb999d8 9354#endif
4d588c14 9355 else if (legitimate_constant_pool_address_p (x))
9ebbca7d 9356 {
2bfcf297 9357 if (TARGET_AIX && (!TARGET_ELF || !TARGET_MINIMAL_TOC))
9ebbca7d 9358 {
2bfcf297
DB
9359 rtx contains_minus = XEXP (x, 1);
9360 rtx minus, symref;
9361 const char *name;
9ebbca7d
GK
9362
9363 /* Find the (minus (sym) (toc)) buried in X, and temporarily
a4f6c312 9364 turn it into (sym) for output_addr_const. */
9ebbca7d
GK
9365 while (GET_CODE (XEXP (contains_minus, 0)) != MINUS)
9366 contains_minus = XEXP (contains_minus, 0);
9367
2bfcf297
DB
9368 minus = XEXP (contains_minus, 0);
9369 symref = XEXP (minus, 0);
9370 XEXP (contains_minus, 0) = symref;
9371 if (TARGET_ELF)
9372 {
9373 char *newname;
9374
9375 name = XSTR (symref, 0);
9376 newname = alloca (strlen (name) + sizeof ("@toc"));
9377 strcpy (newname, name);
9378 strcat (newname, "@toc");
9379 XSTR (symref, 0) = newname;
9380 }
9381 output_addr_const (file, XEXP (x, 1));
9382 if (TARGET_ELF)
9383 XSTR (symref, 0) = name;
9ebbca7d
GK
9384 XEXP (contains_minus, 0) = minus;
9385 }
9386 else
9387 output_addr_const (file, XEXP (x, 1));
9388
9389 fprintf (file, "(%s)", reg_names[REGNO (XEXP (x, 0))]);
9390 }
9878760c
RK
9391 else
9392 abort ();
9393}
9394\f
88cad84b 9395/* Target hook for assembling integer objects. The PowerPC version has
301d03af
RS
9396 to handle fixup entries for relocatable code if RELOCATABLE_NEEDS_FIXUP
9397 is defined. It also needs to handle DI-mode objects on 64-bit
9398 targets. */
9399
9400static bool
a2369ed3 9401rs6000_assemble_integer (rtx x, unsigned int size, int aligned_p)
301d03af
RS
9402{
9403#ifdef RELOCATABLE_NEEDS_FIXUP
9404 /* Special handling for SI values. */
9405 if (size == 4 && aligned_p)
9406 {
a2369ed3 9407 extern int in_toc_section (void);
301d03af
RS
9408 static int recurse = 0;
9409
9410 /* For -mrelocatable, we mark all addresses that need to be fixed up
9411 in the .fixup section. */
9412 if (TARGET_RELOCATABLE
9413 && !in_toc_section ()
9414 && !in_text_section ()
9415 && !recurse
9416 && GET_CODE (x) != CONST_INT
9417 && GET_CODE (x) != CONST_DOUBLE
9418 && CONSTANT_P (x))
9419 {
9420 char buf[256];
9421
9422 recurse = 1;
9423 ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", fixuplabelno);
9424 fixuplabelno++;
9425 ASM_OUTPUT_LABEL (asm_out_file, buf);
9426 fprintf (asm_out_file, "\t.long\t(");
9427 output_addr_const (asm_out_file, x);
9428 fprintf (asm_out_file, ")@fixup\n");
9429 fprintf (asm_out_file, "\t.section\t\".fixup\",\"aw\"\n");
9430 ASM_OUTPUT_ALIGN (asm_out_file, 2);
9431 fprintf (asm_out_file, "\t.long\t");
9432 assemble_name (asm_out_file, buf);
9433 fprintf (asm_out_file, "\n\t.previous\n");
9434 recurse = 0;
9435 return true;
9436 }
9437 /* Remove initial .'s to turn a -mcall-aixdesc function
9438 address into the address of the descriptor, not the function
9439 itself. */
9440 else if (GET_CODE (x) == SYMBOL_REF
9441 && XSTR (x, 0)[0] == '.'
9442 && DEFAULT_ABI == ABI_AIX)
9443 {
9444 const char *name = XSTR (x, 0);
9445 while (*name == '.')
9446 name++;
9447
9448 fprintf (asm_out_file, "\t.long\t%s\n", name);
9449 return true;
9450 }
9451 }
9452#endif /* RELOCATABLE_NEEDS_FIXUP */
9453 return default_assemble_integer (x, size, aligned_p);
9454}
93638d7a
AM
9455
9456#ifdef HAVE_GAS_HIDDEN
9457/* Emit an assembler directive to set symbol visibility for DECL to
9458 VISIBILITY_TYPE. */
9459
5add3202 9460static void
a2369ed3 9461rs6000_assemble_visibility (tree decl, int vis)
93638d7a 9462{
93638d7a
AM
9463 /* Functions need to have their entry point symbol visibility set as
9464 well as their descriptor symbol visibility. */
9465 if (DEFAULT_ABI == ABI_AIX && TREE_CODE (decl) == FUNCTION_DECL)
9466 {
25fdb4dc
RH
9467 static const char * const visibility_types[] = {
9468 NULL, "internal", "hidden", "protected"
9469 };
9470
9471 const char *name, *type;
93638d7a
AM
9472
9473 name = ((* targetm.strip_name_encoding)
9474 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
25fdb4dc 9475 type = visibility_types[vis];
93638d7a 9476
25fdb4dc
RH
9477 fprintf (asm_out_file, "\t.%s\t%s\n", type, name);
9478 fprintf (asm_out_file, "\t.%s\t.%s\n", type, name);
93638d7a 9479 }
25fdb4dc
RH
9480 else
9481 default_assemble_visibility (decl, vis);
93638d7a
AM
9482}
9483#endif
301d03af 9484\f
39a10a29 9485enum rtx_code
a2369ed3 9486rs6000_reverse_condition (enum machine_mode mode, enum rtx_code code)
39a10a29
GK
9487{
9488 /* Reversal of FP compares takes care -- an ordered compare
9489 becomes an unordered compare and vice versa. */
bc9ec0e0
GK
9490 if (mode == CCFPmode
9491 && (!flag_finite_math_only
9492 || code == UNLT || code == UNLE || code == UNGT || code == UNGE
9493 || code == UNEQ || code == LTGT))
bab6226b 9494 return reverse_condition_maybe_unordered (code);
39a10a29 9495 else
bab6226b 9496 return reverse_condition (code);
39a10a29
GK
9497}
9498
39a10a29
GK
9499/* Generate a compare for CODE. Return a brand-new rtx that
9500 represents the result of the compare. */
a4f6c312 9501
39a10a29 9502static rtx
a2369ed3 9503rs6000_generate_compare (enum rtx_code code)
39a10a29
GK
9504{
9505 enum machine_mode comp_mode;
9506 rtx compare_result;
9507
9508 if (rs6000_compare_fp_p)
9509 comp_mode = CCFPmode;
9510 else if (code == GTU || code == LTU
9511 || code == GEU || code == LEU)
9512 comp_mode = CCUNSmode;
9513 else
9514 comp_mode = CCmode;
9515
9516 /* First, the compare. */
9517 compare_result = gen_reg_rtx (comp_mode);
a3170dc6
AH
9518
9519 /* SPE FP compare instructions on the GPRs. Yuck! */
993f19a8
AH
9520 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT)
9521 && rs6000_compare_fp_p)
a3170dc6
AH
9522 {
9523 rtx cmp, or1, or2, or_result, compare_result2;
9524
9525 switch (code)
9526 {
9527 case EQ:
9528 case UNEQ:
9529 case NE:
9530 case LTGT:
bc9ec0e0 9531 cmp = flag_finite_math_only
a3170dc6
AH
9532 ? gen_tstsfeq_gpr (compare_result, rs6000_compare_op0,
9533 rs6000_compare_op1)
9534 : gen_cmpsfeq_gpr (compare_result, rs6000_compare_op0,
9535 rs6000_compare_op1);
9536 break;
9537 case GT:
9538 case GTU:
9539 case UNGT:
9540 case UNGE:
9541 case GE:
9542 case GEU:
bc9ec0e0 9543 cmp = flag_finite_math_only
a3170dc6
AH
9544 ? gen_tstsfgt_gpr (compare_result, rs6000_compare_op0,
9545 rs6000_compare_op1)
9546 : gen_cmpsfgt_gpr (compare_result, rs6000_compare_op0,
9547 rs6000_compare_op1);
9548 break;
9549 case LT:
9550 case LTU:
9551 case UNLT:
9552 case UNLE:
9553 case LE:
9554 case LEU:
bc9ec0e0 9555 cmp = flag_finite_math_only
a3170dc6
AH
9556 ? gen_tstsflt_gpr (compare_result, rs6000_compare_op0,
9557 rs6000_compare_op1)
9558 : gen_cmpsflt_gpr (compare_result, rs6000_compare_op0,
9559 rs6000_compare_op1);
9560 break;
9561 default:
9562 abort ();
9563 }
9564
9565 /* Synthesize LE and GE from LT/GT || EQ. */
9566 if (code == LE || code == GE || code == LEU || code == GEU)
9567 {
9568 /* Synthesize GE/LE frome GT/LT || EQ. */
9569
9570 emit_insn (cmp);
9571
9572 switch (code)
9573 {
9574 case LE: code = LT; break;
9575 case GE: code = GT; break;
9576 case LEU: code = LT; break;
9577 case GEU: code = GT; break;
9578 default: abort ();
9579 }
9580
9581 or1 = gen_reg_rtx (SImode);
9582 or2 = gen_reg_rtx (SImode);
9583 or_result = gen_reg_rtx (CCEQmode);
9584 compare_result2 = gen_reg_rtx (CCFPmode);
9585
9586 /* Do the EQ. */
bc9ec0e0 9587 cmp = flag_finite_math_only
a3170dc6
AH
9588 ? gen_tstsfeq_gpr (compare_result2, rs6000_compare_op0,
9589 rs6000_compare_op1)
9590 : gen_cmpsfeq_gpr (compare_result2, rs6000_compare_op0,
9591 rs6000_compare_op1);
9592 emit_insn (cmp);
9593
9594 /* The MC8540 FP compare instructions set the CR bits
9595 differently than other PPC compare instructions. For
9596 that matter, there is no generic test instruction, but a
9597 testgt, testlt, and testeq. For a true condition, bit 2
9598 is set (x1xx) in the CR. Following the traditional CR
9599 values:
9600
9601 LT GT EQ OV
9602 bit3 bit2 bit1 bit0
9603
9604 ... bit 2 would be a GT CR alias, so later on we
b6d08ca1 9605 look in the GT bits for the branch instructions.
a3170dc6
AH
9606 However, we must be careful to emit correct RTL in
9607 the meantime, so optimizations don't get confused. */
9608
f1c25d3b
KH
9609 or1 = gen_rtx_NE (SImode, compare_result, const0_rtx);
9610 or2 = gen_rtx_NE (SImode, compare_result2, const0_rtx);
a3170dc6
AH
9611
9612 /* OR them together. */
9613 cmp = gen_rtx_SET (VOIDmode, or_result,
9614 gen_rtx_COMPARE (CCEQmode,
9615 gen_rtx_IOR (SImode, or1, or2),
9616 const_true_rtx));
9617 compare_result = or_result;
9618 code = EQ;
9619 }
9620 else
9621 {
9622 /* We only care about 1 bit (x1xx), so map everything to NE to
9623 maintain rtl sanity. We'll get to the right bit (x1xx) at
9624 code output time. */
9625 if (code == NE || code == LTGT)
9626 /* Do the inverse here because we have no cmpne
9627 instruction. We use the cmpeq instruction and expect
9628 to get a 0 instead. */
9629 code = EQ;
9630 else
9631 code = NE;
9632 }
9633
9634 emit_insn (cmp);
9635 }
9636 else
9637 emit_insn (gen_rtx_SET (VOIDmode, compare_result,
9638 gen_rtx_COMPARE (comp_mode,
9639 rs6000_compare_op0,
9640 rs6000_compare_op1)));
39a10a29 9641
ca5adc63 9642 /* Some kinds of FP comparisons need an OR operation;
bc9ec0e0 9643 under flag_finite_math_only we don't bother. */
39a10a29 9644 if (rs6000_compare_fp_p
bc9ec0e0 9645 && ! flag_finite_math_only
993f19a8 9646 && ! (TARGET_HARD_FLOAT && TARGET_E500 && !TARGET_FPRS)
39a10a29
GK
9647 && (code == LE || code == GE
9648 || code == UNEQ || code == LTGT
9649 || code == UNGT || code == UNLT))
9650 {
9651 enum rtx_code or1, or2;
9652 rtx or1_rtx, or2_rtx, compare2_rtx;
9653 rtx or_result = gen_reg_rtx (CCEQmode);
9654
9655 switch (code)
9656 {
9657 case LE: or1 = LT; or2 = EQ; break;
9658 case GE: or1 = GT; or2 = EQ; break;
9659 case UNEQ: or1 = UNORDERED; or2 = EQ; break;
9660 case LTGT: or1 = LT; or2 = GT; break;
9661 case UNGT: or1 = UNORDERED; or2 = GT; break;
9662 case UNLT: or1 = UNORDERED; or2 = LT; break;
9663 default: abort ();
9664 }
9665 validate_condition_mode (or1, comp_mode);
9666 validate_condition_mode (or2, comp_mode);
1c563bed
KH
9667 or1_rtx = gen_rtx_fmt_ee (or1, SImode, compare_result, const0_rtx);
9668 or2_rtx = gen_rtx_fmt_ee (or2, SImode, compare_result, const0_rtx);
39a10a29
GK
9669 compare2_rtx = gen_rtx_COMPARE (CCEQmode,
9670 gen_rtx_IOR (SImode, or1_rtx, or2_rtx),
9671 const_true_rtx);
9672 emit_insn (gen_rtx_SET (VOIDmode, or_result, compare2_rtx));
9673
9674 compare_result = or_result;
9675 code = EQ;
9676 }
9677
9678 validate_condition_mode (code, GET_MODE (compare_result));
9679
1c563bed 9680 return gen_rtx_fmt_ee (code, VOIDmode, compare_result, const0_rtx);
39a10a29
GK
9681}
9682
9683
9684/* Emit the RTL for an sCOND pattern. */
9685
9686void
a2369ed3 9687rs6000_emit_sCOND (enum rtx_code code, rtx result)
39a10a29
GK
9688{
9689 rtx condition_rtx;
9690 enum machine_mode op_mode;
b7053a3f 9691 enum rtx_code cond_code;
39a10a29
GK
9692
9693 condition_rtx = rs6000_generate_compare (code);
b7053a3f
GK
9694 cond_code = GET_CODE (condition_rtx);
9695
9696 if (cond_code == NE
9697 || cond_code == GE || cond_code == LE
9698 || cond_code == GEU || cond_code == LEU
9699 || cond_code == ORDERED || cond_code == UNGE || cond_code == UNLE)
9700 {
9701 rtx not_result = gen_reg_rtx (CCEQmode);
9702 rtx not_op, rev_cond_rtx;
9703 enum machine_mode cc_mode;
9704
9705 cc_mode = GET_MODE (XEXP (condition_rtx, 0));
9706
1c563bed 9707 rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (cc_mode, cond_code),
0f4c242b 9708 SImode, XEXP (condition_rtx, 0), const0_rtx);
b7053a3f
GK
9709 not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx);
9710 emit_insn (gen_rtx_SET (VOIDmode, not_result, not_op));
9711 condition_rtx = gen_rtx_EQ (VOIDmode, not_result, const0_rtx);
9712 }
39a10a29
GK
9713
9714 op_mode = GET_MODE (rs6000_compare_op0);
9715 if (op_mode == VOIDmode)
9716 op_mode = GET_MODE (rs6000_compare_op1);
9717
9718 if (TARGET_POWERPC64 && (op_mode == DImode || rs6000_compare_fp_p))
9719 {
9720 PUT_MODE (condition_rtx, DImode);
9721 convert_move (result, condition_rtx, 0);
9722 }
9723 else
9724 {
9725 PUT_MODE (condition_rtx, SImode);
9726 emit_insn (gen_rtx_SET (VOIDmode, result, condition_rtx));
9727 }
9728}
9729
39a10a29
GK
9730/* Emit a branch of kind CODE to location LOC. */
9731
9732void
a2369ed3 9733rs6000_emit_cbranch (enum rtx_code code, rtx loc)
39a10a29
GK
9734{
9735 rtx condition_rtx, loc_ref;
9736
9737 condition_rtx = rs6000_generate_compare (code);
9738 loc_ref = gen_rtx_LABEL_REF (VOIDmode, loc);
9739 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
9740 gen_rtx_IF_THEN_ELSE (VOIDmode, condition_rtx,
9741 loc_ref, pc_rtx)));
9742}
9743
12a4e8c5
GK
9744/* Return the string to output a conditional branch to LABEL, which is
9745 the operand number of the label, or -1 if the branch is really a
9746 conditional return.
9747
9748 OP is the conditional expression. XEXP (OP, 0) is assumed to be a
9749 condition code register and its mode specifies what kind of
9750 comparison we made.
9751
a0ab749a 9752 REVERSED is nonzero if we should reverse the sense of the comparison.
12a4e8c5
GK
9753
9754 INSN is the insn. */
9755
9756char *
a2369ed3 9757output_cbranch (rtx op, const char *label, int reversed, rtx insn)
12a4e8c5
GK
9758{
9759 static char string[64];
9760 enum rtx_code code = GET_CODE (op);
9761 rtx cc_reg = XEXP (op, 0);
9762 enum machine_mode mode = GET_MODE (cc_reg);
9763 int cc_regno = REGNO (cc_reg) - CR0_REGNO;
39a10a29 9764 int need_longbranch = label != NULL && get_attr_length (insn) == 8;
12a4e8c5
GK
9765 int really_reversed = reversed ^ need_longbranch;
9766 char *s = string;
9767 const char *ccode;
9768 const char *pred;
9769 rtx note;
9770
39a10a29
GK
9771 validate_condition_mode (code, mode);
9772
9773 /* Work out which way this really branches. We could use
9774 reverse_condition_maybe_unordered here always but this
9775 makes the resulting assembler clearer. */
12a4e8c5 9776 if (really_reversed)
de40e1df
DJ
9777 {
9778 /* Reversal of FP compares takes care -- an ordered compare
9779 becomes an unordered compare and vice versa. */
9780 if (mode == CCFPmode)
9781 code = reverse_condition_maybe_unordered (code);
9782 else
9783 code = reverse_condition (code);
9784 }
12a4e8c5 9785
993f19a8 9786 if ((TARGET_E500 && !TARGET_FPRS && TARGET_HARD_FLOAT) && mode == CCFPmode)
a3170dc6
AH
9787 {
9788 /* The efscmp/tst* instructions twiddle bit 2, which maps nicely
9789 to the GT bit. */
9790 if (code == EQ)
9791 /* Opposite of GT. */
9792 code = UNLE;
9793 else if (code == NE)
9794 code = GT;
9795 else
9796 abort ();
9797 }
9798
39a10a29 9799 switch (code)
12a4e8c5
GK
9800 {
9801 /* Not all of these are actually distinct opcodes, but
9802 we distinguish them for clarity of the resulting assembler. */
50a0b056
GK
9803 case NE: case LTGT:
9804 ccode = "ne"; break;
9805 case EQ: case UNEQ:
9806 ccode = "eq"; break;
9807 case GE: case GEU:
9808 ccode = "ge"; break;
9809 case GT: case GTU: case UNGT:
9810 ccode = "gt"; break;
9811 case LE: case LEU:
9812 ccode = "le"; break;
9813 case LT: case LTU: case UNLT:
9814 ccode = "lt"; break;
12a4e8c5
GK
9815 case UNORDERED: ccode = "un"; break;
9816 case ORDERED: ccode = "nu"; break;
9817 case UNGE: ccode = "nl"; break;
9818 case UNLE: ccode = "ng"; break;
9819 default:
a4f6c312 9820 abort ();
12a4e8c5
GK
9821 }
9822
94a54f47
GK
9823 /* Maybe we have a guess as to how likely the branch is.
9824 The old mnemonics don't have a way to specify this information. */
f4857b9b 9825 pred = "";
12a4e8c5
GK
9826 note = find_reg_note (insn, REG_BR_PROB, NULL_RTX);
9827 if (note != NULL_RTX)
9828 {
9829 /* PROB is the difference from 50%. */
9830 int prob = INTVAL (XEXP (note, 0)) - REG_BR_PROB_BASE / 2;
f4857b9b
AM
9831 bool always_hint = rs6000_cpu != PROCESSOR_POWER4;
9832
9833 /* Only hint for highly probable/improbable branches on newer
9834 cpus as static prediction overrides processor dynamic
9835 prediction. For older cpus we may as well always hint, but
9836 assume not taken for branches that are very close to 50% as a
9837 mispredicted taken branch is more expensive than a
9838 mispredicted not-taken branch. */
9839 if (always_hint
9840 || abs (prob) > REG_BR_PROB_BASE / 100 * 48)
9841 {
9842 if (abs (prob) > REG_BR_PROB_BASE / 20
9843 && ((prob > 0) ^ need_longbranch))
7f3d8013 9844 pred = "+";
f4857b9b
AM
9845 else
9846 pred = "-";
9847 }
12a4e8c5 9848 }
12a4e8c5
GK
9849
9850 if (label == NULL)
94a54f47 9851 s += sprintf (s, "{b%sr|b%slr%s} ", ccode, ccode, pred);
12a4e8c5 9852 else
94a54f47 9853 s += sprintf (s, "{b%s|b%s%s} ", ccode, ccode, pred);
12a4e8c5 9854
37c67319 9855 /* We need to escape any '%' characters in the reg_names string.
a3c9585f 9856 Assume they'd only be the first character.... */
37c67319
GK
9857 if (reg_names[cc_regno + CR0_REGNO][0] == '%')
9858 *s++ = '%';
94a54f47 9859 s += sprintf (s, "%s", reg_names[cc_regno + CR0_REGNO]);
12a4e8c5
GK
9860
9861 if (label != NULL)
9862 {
9863 /* If the branch distance was too far, we may have to use an
9864 unconditional branch to go the distance. */
9865 if (need_longbranch)
44518ddd 9866 s += sprintf (s, ",$+8\n\tb %s", label);
12a4e8c5
GK
9867 else
9868 s += sprintf (s, ",%s", label);
9869 }
9870
9871 return string;
9872}
50a0b056
GK
9873
9874/* Emit a conditional move: move TRUE_COND to DEST if OP of the
9875 operands of the last comparison is nonzero/true, FALSE_COND if it
9876 is zero/false. Return 0 if the hardware has no such operation. */
a4f6c312 9877
50a0b056 9878int
a2369ed3 9879rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
50a0b056
GK
9880{
9881 enum rtx_code code = GET_CODE (op);
9882 rtx op0 = rs6000_compare_op0;
9883 rtx op1 = rs6000_compare_op1;
9884 REAL_VALUE_TYPE c1;
3148ad6d
DJ
9885 enum machine_mode compare_mode = GET_MODE (op0);
9886 enum machine_mode result_mode = GET_MODE (dest);
50a0b056
GK
9887 rtx temp;
9888
a3c9585f 9889 /* These modes should always match. */
a3170dc6
AH
9890 if (GET_MODE (op1) != compare_mode
9891 /* In the isel case however, we can use a compare immediate, so
9892 op1 may be a small constant. */
9893 && (!TARGET_ISEL || !short_cint_operand (op1, VOIDmode)))
3148ad6d 9894 return 0;
178c3eff 9895 if (GET_MODE (true_cond) != result_mode)
3148ad6d 9896 return 0;
178c3eff 9897 if (GET_MODE (false_cond) != result_mode)
3148ad6d
DJ
9898 return 0;
9899
50a0b056 9900 /* First, work out if the hardware can do this at all, or
a3c9585f 9901 if it's too slow.... */
50a0b056 9902 if (! rs6000_compare_fp_p)
a3170dc6
AH
9903 {
9904 if (TARGET_ISEL)
9905 return rs6000_emit_int_cmove (dest, op, true_cond, false_cond);
9906 return 0;
9907 }
50a0b056
GK
9908
9909 /* Eliminate half of the comparisons by switching operands, this
9910 makes the remaining code simpler. */
9911 if (code == UNLT || code == UNGT || code == UNORDERED || code == NE
bc9ec0e0 9912 || code == LTGT || code == LT || code == UNLE)
50a0b056
GK
9913 {
9914 code = reverse_condition_maybe_unordered (code);
9915 temp = true_cond;
9916 true_cond = false_cond;
9917 false_cond = temp;
9918 }
9919
9920 /* UNEQ and LTGT take four instructions for a comparison with zero,
9921 it'll probably be faster to use a branch here too. */
bc9ec0e0 9922 if (code == UNEQ && HONOR_NANS (compare_mode))
50a0b056
GK
9923 return 0;
9924
9925 if (GET_CODE (op1) == CONST_DOUBLE)
9926 REAL_VALUE_FROM_CONST_DOUBLE (c1, op1);
9927
b6d08ca1 9928 /* We're going to try to implement comparisons by performing
50a0b056
GK
9929 a subtract, then comparing against zero. Unfortunately,
9930 Inf - Inf is NaN which is not zero, and so if we don't
27d30956 9931 know that the operand is finite and the comparison
50a0b056 9932 would treat EQ different to UNORDERED, we can't do it. */
bc9ec0e0 9933 if (HONOR_INFINITIES (compare_mode)
50a0b056 9934 && code != GT && code != UNGE
045572c7 9935 && (GET_CODE (op1) != CONST_DOUBLE || real_isinf (&c1))
50a0b056
GK
9936 /* Constructs of the form (a OP b ? a : b) are safe. */
9937 && ((! rtx_equal_p (op0, false_cond) && ! rtx_equal_p (op1, false_cond))
9938 || (! rtx_equal_p (op0, true_cond)
9939 && ! rtx_equal_p (op1, true_cond))))
9940 return 0;
9941 /* At this point we know we can use fsel. */
9942
9943 /* Reduce the comparison to a comparison against zero. */
3148ad6d 9944 temp = gen_reg_rtx (compare_mode);
50a0b056 9945 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 9946 gen_rtx_MINUS (compare_mode, op0, op1)));
50a0b056 9947 op0 = temp;
3148ad6d 9948 op1 = CONST0_RTX (compare_mode);
50a0b056
GK
9949
9950 /* If we don't care about NaNs we can reduce some of the comparisons
9951 down to faster ones. */
bc9ec0e0 9952 if (! HONOR_NANS (compare_mode))
50a0b056
GK
9953 switch (code)
9954 {
9955 case GT:
9956 code = LE;
9957 temp = true_cond;
9958 true_cond = false_cond;
9959 false_cond = temp;
9960 break;
9961 case UNGE:
9962 code = GE;
9963 break;
9964 case UNEQ:
9965 code = EQ;
9966 break;
9967 default:
9968 break;
9969 }
9970
9971 /* Now, reduce everything down to a GE. */
9972 switch (code)
9973 {
9974 case GE:
9975 break;
9976
9977 case LE:
3148ad6d
DJ
9978 temp = gen_reg_rtx (compare_mode);
9979 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
9980 op0 = temp;
9981 break;
9982
9983 case ORDERED:
3148ad6d
DJ
9984 temp = gen_reg_rtx (compare_mode);
9985 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_ABS (compare_mode, op0)));
50a0b056
GK
9986 op0 = temp;
9987 break;
9988
9989 case EQ:
3148ad6d 9990 temp = gen_reg_rtx (compare_mode);
50a0b056 9991 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d
DJ
9992 gen_rtx_NEG (compare_mode,
9993 gen_rtx_ABS (compare_mode, op0))));
50a0b056
GK
9994 op0 = temp;
9995 break;
9996
9997 case UNGE:
bc9ec0e0 9998 /* a UNGE 0 <-> (a GE 0 || -a UNLT 0) */
3148ad6d 9999 temp = gen_reg_rtx (result_mode);
50a0b056 10000 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10001 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10002 gen_rtx_GE (VOIDmode,
10003 op0, op1),
10004 true_cond, false_cond)));
bc9ec0e0
GK
10005 false_cond = true_cond;
10006 true_cond = temp;
50a0b056 10007
3148ad6d
DJ
10008 temp = gen_reg_rtx (compare_mode);
10009 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10010 op0 = temp;
10011 break;
10012
10013 case GT:
bc9ec0e0 10014 /* a GT 0 <-> (a GE 0 && -a UNLT 0) */
3148ad6d 10015 temp = gen_reg_rtx (result_mode);
50a0b056 10016 emit_insn (gen_rtx_SET (VOIDmode, temp,
3148ad6d 10017 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10018 gen_rtx_GE (VOIDmode,
10019 op0, op1),
10020 true_cond, false_cond)));
bc9ec0e0
GK
10021 true_cond = false_cond;
10022 false_cond = temp;
50a0b056 10023
3148ad6d
DJ
10024 temp = gen_reg_rtx (compare_mode);
10025 emit_insn (gen_rtx_SET (VOIDmode, temp, gen_rtx_NEG (compare_mode, op0)));
50a0b056
GK
10026 op0 = temp;
10027 break;
10028
10029 default:
10030 abort ();
10031 }
10032
10033 emit_insn (gen_rtx_SET (VOIDmode, dest,
3148ad6d 10034 gen_rtx_IF_THEN_ELSE (result_mode,
50a0b056
GK
10035 gen_rtx_GE (VOIDmode,
10036 op0, op1),
10037 true_cond, false_cond)));
10038 return 1;
10039}
10040
a3170dc6
AH
10041/* Same as above, but for ints (isel). */
10042
10043static int
a2369ed3 10044rs6000_emit_int_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
a3170dc6
AH
10045{
10046 rtx condition_rtx, cr;
10047
10048 /* All isel implementations thus far are 32-bits. */
10049 if (GET_MODE (rs6000_compare_op0) != SImode)
10050 return 0;
10051
10052 /* We still have to do the compare, because isel doesn't do a
10053 compare, it just looks at the CRx bits set by a previous compare
10054 instruction. */
10055 condition_rtx = rs6000_generate_compare (GET_CODE (op));
10056 cr = XEXP (condition_rtx, 0);
10057
10058 if (GET_MODE (cr) == CCmode)
10059 emit_insn (gen_isel_signed (dest, condition_rtx,
10060 true_cond, false_cond, cr));
10061 else
10062 emit_insn (gen_isel_unsigned (dest, condition_rtx,
10063 true_cond, false_cond, cr));
10064
10065 return 1;
10066}
10067
10068const char *
a2369ed3 10069output_isel (rtx *operands)
a3170dc6
AH
10070{
10071 enum rtx_code code;
10072
10073 code = GET_CODE (operands[1]);
10074 if (code == GE || code == GEU || code == LE || code == LEU || code == NE)
10075 {
10076 PUT_CODE (operands[1], reverse_condition (code));
10077 return "isel %0,%3,%2,%j1";
10078 }
10079 else
10080 return "isel %0,%2,%3,%j1";
10081}
10082
50a0b056 10083void
a2369ed3 10084rs6000_emit_minmax (rtx dest, enum rtx_code code, rtx op0, rtx op1)
50a0b056
GK
10085{
10086 enum machine_mode mode = GET_MODE (op0);
5dc8d536 10087 enum rtx_code c;
50a0b056 10088 rtx target;
5dc8d536
AH
10089
10090 if (code == SMAX || code == SMIN)
10091 c = GE;
10092 else
10093 c = GEU;
10094
50a0b056 10095 if (code == SMAX || code == UMAX)
5dc8d536 10096 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10097 op0, op1, mode, 0);
10098 else
5dc8d536 10099 target = emit_conditional_move (dest, c, op0, op1, mode,
50a0b056
GK
10100 op1, op0, mode, 0);
10101 if (target == NULL_RTX)
10102 abort ();
10103 if (target != dest)
10104 emit_move_insn (dest, target);
10105}
46c07df8 10106
a9baceb1
GK
10107/* Emit instructions to move SRC to DST. Called by splitters for
10108 multi-register moves. It will emit at most one instruction for
10109 each register that is accessed; that is, it won't emit li/lis pairs
10110 (or equivalent for 64-bit code). One of SRC or DST must be a hard
10111 register. */
46c07df8 10112
46c07df8 10113void
a9baceb1 10114rs6000_split_multireg_move (rtx dst, rtx src)
46c07df8 10115{
a9baceb1
GK
10116 /* The register number of the first register being moved. */
10117 int reg;
10118 /* The mode that is to be moved. */
10119 enum machine_mode mode;
10120 /* The mode that the move is being done in, and its size. */
10121 enum machine_mode reg_mode;
10122 int reg_mode_size;
10123 /* The number of registers that will be moved. */
10124 int nregs;
10125
10126 reg = REG_P (dst) ? REGNO (dst) : REGNO (src);
10127 mode = GET_MODE (dst);
10128 nregs = HARD_REGNO_NREGS (reg, mode);
10129 if (FP_REGNO_P (reg))
10130 reg_mode = DFmode;
10131 else if (ALTIVEC_REGNO_P (reg))
10132 reg_mode = V16QImode;
10133 else
10134 reg_mode = word_mode;
10135 reg_mode_size = GET_MODE_SIZE (reg_mode);
46c07df8 10136
a9baceb1
GK
10137 if (reg_mode_size * nregs != GET_MODE_SIZE (mode))
10138 abort ();
10139
10140 if (REG_P (src) && REG_P (dst) && (REGNO (src) < REGNO (dst)))
10141 {
10142 /* Move register range backwards, if we might have destructive
10143 overlap. */
10144 int i;
10145 for (i = nregs - 1; i >= 0; i--)
10146 emit_insn (gen_rtx_SET (VOIDmode,
10147 simplify_gen_subreg (reg_mode, dst, mode,
10148 i * reg_mode_size),
10149 simplify_gen_subreg (reg_mode, src, mode,
10150 i * reg_mode_size)));
10151 }
46c07df8
HP
10152 else
10153 {
a9baceb1
GK
10154 int i;
10155 int j = -1;
10156 bool used_update = false;
46c07df8 10157
a9baceb1 10158 if (GET_CODE (src) == MEM && INT_REGNO_P (reg))
46c07df8
HP
10159 {
10160 rtx breg;
3a1f863f 10161
a9baceb1
GK
10162 if (GET_CODE (XEXP (src, 0)) == PRE_INC
10163 || GET_CODE (XEXP (src, 0)) == PRE_DEC)
3a1f863f
DE
10164 {
10165 rtx delta_rtx;
a9baceb1
GK
10166 breg = XEXP (XEXP (src, 0), 0);
10167 delta_rtx = GET_CODE (XEXP (src, 0)) == PRE_INC
10168 ? GEN_INT (GET_MODE_SIZE (GET_MODE (src)))
10169 : GEN_INT (-GET_MODE_SIZE (GET_MODE (src)));
10170 emit_insn (TARGET_32BIT
10171 ? gen_addsi3 (breg, breg, delta_rtx)
10172 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10173 src = gen_rtx_MEM (mode, breg);
10174 }
10175
10176 /* We have now address involving an base register only.
10177 If we use one of the registers to address memory,
10178 we have change that register last. */
10179
10180 breg = (GET_CODE (XEXP (src, 0)) == PLUS
10181 ? XEXP (XEXP (src, 0), 0)
10182 : XEXP (src, 0));
10183
10184 if (!REG_P (breg))
10185 abort();
10186
10187 if (REGNO (breg) >= REGNO (dst)
10188 && REGNO (breg) < REGNO (dst) + nregs)
10189 j = REGNO (breg) - REGNO (dst);
46c07df8
HP
10190 }
10191
a9baceb1 10192 if (GET_CODE (dst) == MEM && INT_REGNO_P (reg))
3a1f863f
DE
10193 {
10194 rtx breg;
10195
a9baceb1
GK
10196 if (GET_CODE (XEXP (dst, 0)) == PRE_INC
10197 || GET_CODE (XEXP (dst, 0)) == PRE_DEC)
3a1f863f
DE
10198 {
10199 rtx delta_rtx;
a9baceb1
GK
10200 breg = XEXP (XEXP (dst, 0), 0);
10201 delta_rtx = GET_CODE (XEXP (dst, 0)) == PRE_INC
10202 ? GEN_INT (GET_MODE_SIZE (GET_MODE (dst)))
10203 : GEN_INT (-GET_MODE_SIZE (GET_MODE (dst)));
3a1f863f
DE
10204
10205 /* We have to update the breg before doing the store.
10206 Use store with update, if available. */
10207
10208 if (TARGET_UPDATE)
10209 {
a9baceb1
GK
10210 rtx nsrc = simplify_gen_subreg (reg_mode, src, mode, 0);
10211 emit_insn (TARGET_32BIT
10212 ? gen_movsi_update (breg, breg, delta_rtx, nsrc)
10213 : gen_movdi_update (breg, breg, delta_rtx, nsrc));
10214 used_update = true;
3a1f863f
DE
10215 }
10216 else
a9baceb1
GK
10217 emit_insn (TARGET_32BIT
10218 ? gen_addsi3 (breg, breg, delta_rtx)
10219 : gen_adddi3 (breg, breg, delta_rtx));
3a1f863f
DE
10220 dst = gen_rtx_MEM (mode, breg);
10221 }
10222 }
10223
46c07df8 10224 for (i = 0; i < nregs; i++)
3a1f863f
DE
10225 {
10226 /* Calculate index to next subword. */
10227 ++j;
10228 if (j == nregs)
10229 j = 0;
46c07df8 10230
a9baceb1
GK
10231 /* If compiler already emited move of first word by
10232 store with update, no need to do anything. */
3a1f863f 10233 if (j == 0 && used_update)
a9baceb1
GK
10234 continue;
10235
10236 emit_insn (gen_rtx_SET (VOIDmode,
10237 simplify_gen_subreg (reg_mode, dst, mode,
10238 j * reg_mode_size),
10239 simplify_gen_subreg (reg_mode, src, mode,
10240 j * reg_mode_size)));
3a1f863f 10241 }
46c07df8
HP
10242 }
10243}
10244
12a4e8c5 10245\f
a4f6c312
SS
10246/* This page contains routines that are used to determine what the
10247 function prologue and epilogue code will do and write them out. */
9878760c 10248
a4f6c312
SS
10249/* Return the first fixed-point register that is required to be
10250 saved. 32 if none. */
9878760c
RK
10251
10252int
863d938c 10253first_reg_to_save (void)
9878760c
RK
10254{
10255 int first_reg;
10256
10257 /* Find lowest numbered live register. */
10258 for (first_reg = 13; first_reg <= 31; first_reg++)
a38d360d
GK
10259 if (regs_ever_live[first_reg]
10260 && (! call_used_regs[first_reg]
1db02437 10261 || (first_reg == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 10262 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 10263 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)))))
9878760c
RK
10264 break;
10265
ee890fe2 10266#if TARGET_MACHO
93638d7a
AM
10267 if (flag_pic
10268 && current_function_uses_pic_offset_table
10269 && first_reg > RS6000_PIC_OFFSET_TABLE_REGNUM)
1db02437 10270 return RS6000_PIC_OFFSET_TABLE_REGNUM;
ee890fe2
SS
10271#endif
10272
9878760c
RK
10273 return first_reg;
10274}
10275
10276/* Similar, for FP regs. */
10277
10278int
863d938c 10279first_fp_reg_to_save (void)
9878760c
RK
10280{
10281 int first_reg;
10282
10283 /* Find lowest numbered live register. */
10284 for (first_reg = 14 + 32; first_reg <= 63; first_reg++)
10285 if (regs_ever_live[first_reg])
10286 break;
10287
10288 return first_reg;
10289}
00b960c7
AH
10290
10291/* Similar, for AltiVec regs. */
10292
10293static int
863d938c 10294first_altivec_reg_to_save (void)
00b960c7
AH
10295{
10296 int i;
10297
10298 /* Stack frame remains as is unless we are in AltiVec ABI. */
10299 if (! TARGET_ALTIVEC_ABI)
10300 return LAST_ALTIVEC_REGNO + 1;
10301
10302 /* Find lowest numbered live register. */
10303 for (i = FIRST_ALTIVEC_REGNO + 20; i <= LAST_ALTIVEC_REGNO; ++i)
10304 if (regs_ever_live[i])
10305 break;
10306
10307 return i;
10308}
10309
10310/* Return a 32-bit mask of the AltiVec registers we need to set in
10311 VRSAVE. Bit n of the return value is 1 if Vn is live. The MSB in
10312 the 32-bit word is 0. */
10313
10314static unsigned int
863d938c 10315compute_vrsave_mask (void)
00b960c7
AH
10316{
10317 unsigned int i, mask = 0;
10318
10319 /* First, find out if we use _any_ altivec registers. */
10320 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
10321 if (regs_ever_live[i])
10322 mask |= ALTIVEC_REG_BIT (i);
10323
10324 if (mask == 0)
10325 return mask;
10326
00b960c7
AH
10327 /* Next, remove the argument registers from the set. These must
10328 be in the VRSAVE mask set by the caller, so we don't need to add
10329 them in again. More importantly, the mask we compute here is
10330 used to generate CLOBBERs in the set_vrsave insn, and we do not
10331 wish the argument registers to die. */
a6cf80f2 10332 for (i = cfun->args_info.vregno - 1; i >= ALTIVEC_ARG_MIN_REG; --i)
00b960c7
AH
10333 mask &= ~ALTIVEC_REG_BIT (i);
10334
10335 /* Similarly, remove the return value from the set. */
10336 {
10337 bool yes = false;
10338 diddle_return_value (is_altivec_return_reg, &yes);
10339 if (yes)
10340 mask &= ~ALTIVEC_REG_BIT (ALTIVEC_ARG_RETURN);
10341 }
10342
10343 return mask;
10344}
10345
10346static void
a2369ed3 10347is_altivec_return_reg (rtx reg, void *xyes)
00b960c7
AH
10348{
10349 bool *yes = (bool *) xyes;
10350 if (REGNO (reg) == ALTIVEC_ARG_RETURN)
10351 *yes = true;
10352}
10353
4697a36c
MM
10354\f
10355/* Calculate the stack information for the current function. This is
10356 complicated by having two separate calling sequences, the AIX calling
10357 sequence and the V.4 calling sequence.
10358
592696dd 10359 AIX (and Darwin/Mac OS X) stack frames look like:
a260abc9 10360 32-bit 64-bit
4697a36c 10361 SP----> +---------------------------------------+
a260abc9 10362 | back chain to caller | 0 0
4697a36c 10363 +---------------------------------------+
a260abc9 10364 | saved CR | 4 8 (8-11)
4697a36c 10365 +---------------------------------------+
a260abc9 10366 | saved LR | 8 16
4697a36c 10367 +---------------------------------------+
a260abc9 10368 | reserved for compilers | 12 24
4697a36c 10369 +---------------------------------------+
a260abc9 10370 | reserved for binders | 16 32
4697a36c 10371 +---------------------------------------+
a260abc9 10372 | saved TOC pointer | 20 40
4697a36c 10373 +---------------------------------------+
a260abc9 10374 | Parameter save area (P) | 24 48
4697a36c 10375 +---------------------------------------+
a260abc9 10376 | Alloca space (A) | 24+P etc.
802a0058 10377 +---------------------------------------+
a7df97e6 10378 | Local variable space (L) | 24+P+A
4697a36c 10379 +---------------------------------------+
a7df97e6 10380 | Float/int conversion temporary (X) | 24+P+A+L
4697a36c 10381 +---------------------------------------+
00b960c7
AH
10382 | Save area for AltiVec registers (W) | 24+P+A+L+X
10383 +---------------------------------------+
10384 | AltiVec alignment padding (Y) | 24+P+A+L+X+W
10385 +---------------------------------------+
10386 | Save area for VRSAVE register (Z) | 24+P+A+L+X+W+Y
4697a36c 10387 +---------------------------------------+
00b960c7
AH
10388 | Save area for GP registers (G) | 24+P+A+X+L+X+W+Y+Z
10389 +---------------------------------------+
10390 | Save area for FP registers (F) | 24+P+A+X+L+X+W+Y+Z+G
4697a36c
MM
10391 +---------------------------------------+
10392 old SP->| back chain to caller's caller |
10393 +---------------------------------------+
10394
5376a30c
KR
10395 The required alignment for AIX configurations is two words (i.e., 8
10396 or 16 bytes).
10397
10398
4697a36c
MM
10399 V.4 stack frames look like:
10400
10401 SP----> +---------------------------------------+
10402 | back chain to caller | 0
10403 +---------------------------------------+
5eb387b8 10404 | caller's saved LR | 4
4697a36c
MM
10405 +---------------------------------------+
10406 | Parameter save area (P) | 8
10407 +---------------------------------------+
a7df97e6
MM
10408 | Alloca space (A) | 8+P
10409 +---------------------------------------+
10410 | Varargs save area (V) | 8+P+A
10411 +---------------------------------------+
10412 | Local variable space (L) | 8+P+A+V
10413 +---------------------------------------+
10414 | Float/int conversion temporary (X) | 8+P+A+V+L
4697a36c 10415 +---------------------------------------+
00b960c7
AH
10416 | Save area for AltiVec registers (W) | 8+P+A+V+L+X
10417 +---------------------------------------+
10418 | AltiVec alignment padding (Y) | 8+P+A+V+L+X+W
10419 +---------------------------------------+
10420 | Save area for VRSAVE register (Z) | 8+P+A+V+L+X+W+Y
10421 +---------------------------------------+
a3170dc6
AH
10422 | SPE: area for 64-bit GP registers |
10423 +---------------------------------------+
10424 | SPE alignment padding |
10425 +---------------------------------------+
00b960c7 10426 | saved CR (C) | 8+P+A+V+L+X+W+Y+Z
a7df97e6 10427 +---------------------------------------+
00b960c7 10428 | Save area for GP registers (G) | 8+P+A+V+L+X+W+Y+Z+C
a7df97e6 10429 +---------------------------------------+
00b960c7 10430 | Save area for FP registers (F) | 8+P+A+V+L+X+W+Y+Z+C+G
4697a36c
MM
10431 +---------------------------------------+
10432 old SP->| back chain to caller's caller |
10433 +---------------------------------------+
b6c9286a 10434
5376a30c
KR
10435 The required alignment for V.4 is 16 bytes, or 8 bytes if -meabi is
10436 given. (But note below and in sysv4.h that we require only 8 and
10437 may round up the size of our stack frame anyways. The historical
10438 reason is early versions of powerpc-linux which didn't properly
10439 align the stack at program startup. A happy side-effect is that
10440 -mno-eabi libraries can be used with -meabi programs.)
10441
50d440bc 10442 The EABI configuration defaults to the V.4 layout. However,
5376a30c
KR
10443 the stack alignment requirements may differ. If -mno-eabi is not
10444 given, the required stack alignment is 8 bytes; if -mno-eabi is
10445 given, the required alignment is 16 bytes. (But see V.4 comment
10446 above.) */
4697a36c 10447
61b2fbe7
MM
10448#ifndef ABI_STACK_BOUNDARY
10449#define ABI_STACK_BOUNDARY STACK_BOUNDARY
10450#endif
10451
d1d0c603 10452static rs6000_stack_t *
863d938c 10453rs6000_stack_info (void)
4697a36c
MM
10454{
10455 static rs6000_stack_t info, zero_info;
10456 rs6000_stack_t *info_ptr = &info;
9ebbca7d 10457 int reg_size = TARGET_POWERPC64 ? 8 : 4;
83720594 10458 int ehrd_size;
d1d0c603 10459 HOST_WIDE_INT total_raw_size;
4697a36c 10460
a4f6c312 10461 /* Zero all fields portably. */
4697a36c
MM
10462 info = zero_info;
10463
c19de7aa
AH
10464 if (TARGET_SPE)
10465 {
10466 /* Cache value so we don't rescan instruction chain over and over. */
9b7b447f
AH
10467 if (cfun->machine->insn_chain_scanned_p == 0)
10468 {
10469 cfun->machine->insn_chain_scanned_p = 1;
10470 info_ptr->spe_64bit_regs_used = (int) spe_func_has_64bit_regs_p ();
10471 }
c19de7aa
AH
10472 }
10473
a4f6c312 10474 /* Select which calling sequence. */
178274da 10475 info_ptr->abi = DEFAULT_ABI;
9878760c 10476
a4f6c312 10477 /* Calculate which registers need to be saved & save area size. */
4697a36c 10478 info_ptr->first_gp_reg_save = first_reg_to_save ();
1db02437 10479 /* Assume that we will have to save RS6000_PIC_OFFSET_TABLE_REGNUM,
906fb125 10480 even if it currently looks like we won't. */
2bfcf297 10481 if (((TARGET_TOC && TARGET_MINIMAL_TOC)
178274da
AM
10482 || (flag_pic == 1 && DEFAULT_ABI == ABI_V4)
10483 || (flag_pic && DEFAULT_ABI == ABI_DARWIN))
1db02437
FS
10484 && info_ptr->first_gp_reg_save > RS6000_PIC_OFFSET_TABLE_REGNUM)
10485 info_ptr->gp_size = reg_size * (32 - RS6000_PIC_OFFSET_TABLE_REGNUM);
906fb125
GK
10486 else
10487 info_ptr->gp_size = reg_size * (32 - info_ptr->first_gp_reg_save);
4697a36c 10488
a3170dc6
AH
10489 /* For the SPE, we have an additional upper 32-bits on each GPR.
10490 Ideally we should save the entire 64-bits only when the upper
10491 half is used in SIMD instructions. Since we only record
10492 registers live (not the size they are used in), this proves
10493 difficult because we'd have to traverse the instruction chain at
10494 the right time, taking reload into account. This is a real pain,
c19de7aa
AH
10495 so we opt to save the GPRs in 64-bits always if but one register
10496 gets used in 64-bits. Otherwise, all the registers in the frame
10497 get saved in 32-bits.
a3170dc6 10498
c19de7aa 10499 So... since when we save all GPRs (except the SP) in 64-bits, the
a3170dc6 10500 traditional GP save area will be empty. */
c19de7aa 10501 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10502 info_ptr->gp_size = 0;
10503
4697a36c
MM
10504 info_ptr->first_fp_reg_save = first_fp_reg_to_save ();
10505 info_ptr->fp_size = 8 * (64 - info_ptr->first_fp_reg_save);
10506
00b960c7
AH
10507 info_ptr->first_altivec_reg_save = first_altivec_reg_to_save ();
10508 info_ptr->altivec_size = 16 * (LAST_ALTIVEC_REGNO + 1
10509 - info_ptr->first_altivec_reg_save);
10510
592696dd 10511 /* Does this function call anything? */
71f123ca
FS
10512 info_ptr->calls_p = (! current_function_is_leaf
10513 || cfun->machine->ra_needs_full_frame);
b6c9286a 10514
a4f6c312 10515 /* Determine if we need to save the link register. */
71f123ca 10516 if (rs6000_ra_ever_killed ()
ffcfcb5f
AM
10517 || (DEFAULT_ABI == ABI_AIX
10518 && current_function_profile
10519 && !TARGET_PROFILE_KERNEL)
4697a36c
MM
10520#ifdef TARGET_RELOCATABLE
10521 || (TARGET_RELOCATABLE && (get_pool_size () != 0))
10522#endif
10523 || (info_ptr->first_fp_reg_save != 64
10524 && !FP_SAVE_INLINE (info_ptr->first_fp_reg_save))
00b960c7 10525 || info_ptr->first_altivec_reg_save <= LAST_ALTIVEC_REGNO
178274da 10526 || (DEFAULT_ABI == ABI_V4 && current_function_calls_alloca)
a4f6c312
SS
10527 || (DEFAULT_ABI == ABI_DARWIN
10528 && flag_pic
10529 && current_function_uses_pic_offset_table)
4697a36c
MM
10530 || info_ptr->calls_p)
10531 {
10532 info_ptr->lr_save_p = 1;
9ebbca7d 10533 regs_ever_live[LINK_REGISTER_REGNUM] = 1;
4697a36c
MM
10534 }
10535
9ebbca7d
GK
10536 /* Determine if we need to save the condition code registers. */
10537 if (regs_ever_live[CR2_REGNO]
10538 || regs_ever_live[CR3_REGNO]
10539 || regs_ever_live[CR4_REGNO])
4697a36c
MM
10540 {
10541 info_ptr->cr_save_p = 1;
178274da 10542 if (DEFAULT_ABI == ABI_V4)
4697a36c
MM
10543 info_ptr->cr_size = reg_size;
10544 }
10545
83720594
RH
10546 /* If the current function calls __builtin_eh_return, then we need
10547 to allocate stack space for registers that will hold data for
10548 the exception handler. */
10549 if (current_function_calls_eh_return)
10550 {
10551 unsigned int i;
10552 for (i = 0; EH_RETURN_DATA_REGNO (i) != INVALID_REGNUM; ++i)
10553 continue;
a3170dc6
AH
10554
10555 /* SPE saves EH registers in 64-bits. */
c19de7aa
AH
10556 ehrd_size = i * (TARGET_SPE_ABI
10557 && info_ptr->spe_64bit_regs_used != 0
10558 ? UNITS_PER_SPE_WORD : UNITS_PER_WORD);
83720594
RH
10559 }
10560 else
10561 ehrd_size = 0;
10562
592696dd 10563 /* Determine various sizes. */
4697a36c
MM
10564 info_ptr->reg_size = reg_size;
10565 info_ptr->fixed_size = RS6000_SAVE_AREA;
10566 info_ptr->varargs_size = RS6000_VARARGS_AREA;
189e03e3 10567 info_ptr->vars_size = RS6000_ALIGN (get_frame_size (), 8);
a4f6c312
SS
10568 info_ptr->parm_size = RS6000_ALIGN (current_function_outgoing_args_size,
10569 8);
00b960c7 10570
c19de7aa 10571 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10572 info_ptr->spe_gp_size = 8 * (32 - info_ptr->first_gp_reg_save);
10573 else
10574 info_ptr->spe_gp_size = 0;
10575
4d774ff8
HP
10576 if (TARGET_ALTIVEC_ABI)
10577 info_ptr->vrsave_mask = compute_vrsave_mask ();
00b960c7 10578 else
4d774ff8
HP
10579 info_ptr->vrsave_mask = 0;
10580
10581 if (TARGET_ALTIVEC_VRSAVE && info_ptr->vrsave_mask)
10582 info_ptr->vrsave_size = 4;
10583 else
10584 info_ptr->vrsave_size = 0;
b6c9286a 10585
592696dd 10586 /* Calculate the offsets. */
178274da 10587 switch (DEFAULT_ABI)
4697a36c 10588 {
b6c9286a 10589 case ABI_NONE:
24d304eb 10590 default:
b6c9286a
MM
10591 abort ();
10592
10593 case ABI_AIX:
ee890fe2 10594 case ABI_DARWIN:
b6c9286a
MM
10595 info_ptr->fp_save_offset = - info_ptr->fp_size;
10596 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
00b960c7
AH
10597
10598 if (TARGET_ALTIVEC_ABI)
10599 {
10600 info_ptr->vrsave_save_offset
10601 = info_ptr->gp_save_offset - info_ptr->vrsave_size;
10602
10603 /* Align stack so vector save area is on a quadword boundary. */
10604 if (info_ptr->altivec_size != 0)
10605 info_ptr->altivec_padding_size
10606 = 16 - (-info_ptr->vrsave_save_offset % 16);
10607 else
10608 info_ptr->altivec_padding_size = 0;
10609
10610 info_ptr->altivec_save_offset
10611 = info_ptr->vrsave_save_offset
10612 - info_ptr->altivec_padding_size
10613 - info_ptr->altivec_size;
10614
10615 /* Adjust for AltiVec case. */
10616 info_ptr->ehrd_offset = info_ptr->altivec_save_offset - ehrd_size;
10617 }
10618 else
10619 info_ptr->ehrd_offset = info_ptr->gp_save_offset - ehrd_size;
a260abc9
DE
10620 info_ptr->cr_save_offset = reg_size; /* first word when 64-bit. */
10621 info_ptr->lr_save_offset = 2*reg_size;
24d304eb
RK
10622 break;
10623
10624 case ABI_V4:
b6c9286a
MM
10625 info_ptr->fp_save_offset = - info_ptr->fp_size;
10626 info_ptr->gp_save_offset = info_ptr->fp_save_offset - info_ptr->gp_size;
a7df97e6 10627 info_ptr->cr_save_offset = info_ptr->gp_save_offset - info_ptr->cr_size;
00b960c7 10628
c19de7aa 10629 if (TARGET_SPE_ABI && info_ptr->spe_64bit_regs_used != 0)
a3170dc6
AH
10630 {
10631 /* Align stack so SPE GPR save area is aligned on a
10632 double-word boundary. */
10633 if (info_ptr->spe_gp_size != 0)
10634 info_ptr->spe_padding_size
10635 = 8 - (-info_ptr->cr_save_offset % 8);
10636 else
10637 info_ptr->spe_padding_size = 0;
10638
10639 info_ptr->spe_gp_save_offset
10640 = info_ptr->cr_save_offset
10641 - info_ptr->spe_padding_size
10642 - info_ptr->spe_gp_size;
10643
10644 /* Adjust for SPE case. */
10645 info_ptr->toc_save_offset
10646 = info_ptr->spe_gp_save_offset - info_ptr->toc_size;
10647 }
10648 else if (TARGET_ALTIVEC_ABI)
00b960c7
AH
10649 {
10650 info_ptr->vrsave_save_offset
10651 = info_ptr->cr_save_offset - info_ptr->vrsave_size;
10652
10653 /* Align stack so vector save area is on a quadword boundary. */
10654 if (info_ptr->altivec_size != 0)
10655 info_ptr->altivec_padding_size
10656 = 16 - (-info_ptr->vrsave_save_offset % 16);
10657 else
10658 info_ptr->altivec_padding_size = 0;
10659
10660 info_ptr->altivec_save_offset
10661 = info_ptr->vrsave_save_offset
10662 - info_ptr->altivec_padding_size
10663 - info_ptr->altivec_size;
10664
10665 /* Adjust for AltiVec case. */
10666 info_ptr->toc_save_offset
10667 = info_ptr->altivec_save_offset - info_ptr->toc_size;
10668 }
10669 else
10670 info_ptr->toc_save_offset = info_ptr->cr_save_offset - info_ptr->toc_size;
83720594 10671 info_ptr->ehrd_offset = info_ptr->toc_save_offset - ehrd_size;
b6c9286a
MM
10672 info_ptr->lr_save_offset = reg_size;
10673 break;
4697a36c
MM
10674 }
10675
00b960c7
AH
10676 info_ptr->save_size = RS6000_ALIGN (info_ptr->fp_size
10677 + info_ptr->gp_size
10678 + info_ptr->altivec_size
10679 + info_ptr->altivec_padding_size
a3170dc6
AH
10680 + info_ptr->spe_gp_size
10681 + info_ptr->spe_padding_size
00b960c7
AH
10682 + ehrd_size
10683 + info_ptr->cr_size
10684 + info_ptr->lr_size
10685 + info_ptr->vrsave_size
10686 + info_ptr->toc_size,
10687 (TARGET_ALTIVEC_ABI || ABI_DARWIN)
10688 ? 16 : 8);
10689
ff381587
MM
10690 total_raw_size = (info_ptr->vars_size
10691 + info_ptr->parm_size
ff381587
MM
10692 + info_ptr->save_size
10693 + info_ptr->varargs_size
10694 + info_ptr->fixed_size);
10695
a4f6c312
SS
10696 info_ptr->total_size =
10697 RS6000_ALIGN (total_raw_size, ABI_STACK_BOUNDARY / BITS_PER_UNIT);
ff381587
MM
10698
10699 /* Determine if we need to allocate any stack frame:
10700
a4f6c312
SS
10701 For AIX we need to push the stack if a frame pointer is needed
10702 (because the stack might be dynamically adjusted), if we are
10703 debugging, if we make calls, or if the sum of fp_save, gp_save,
10704 and local variables are more than the space needed to save all
10705 non-volatile registers: 32-bit: 18*8 + 19*4 = 220 or 64-bit: 18*8
10706 + 18*8 = 288 (GPR13 reserved).
ff381587 10707
a4f6c312
SS
10708 For V.4 we don't have the stack cushion that AIX uses, but assume
10709 that the debugger can handle stackless frames. */
ff381587
MM
10710
10711 if (info_ptr->calls_p)
10712 info_ptr->push_p = 1;
10713
178274da 10714 else if (DEFAULT_ABI == ABI_V4)
e72247f4 10715 info_ptr->push_p = total_raw_size > info_ptr->fixed_size;
ff381587 10716
178274da
AM
10717 else if (frame_pointer_needed)
10718 info_ptr->push_p = 1;
10719
10720 else if (TARGET_XCOFF && write_symbols != NO_DEBUG)
10721 info_ptr->push_p = 1;
10722
ff381587 10723 else
178274da
AM
10724 info_ptr->push_p
10725 = total_raw_size - info_ptr->fixed_size > (TARGET_32BIT ? 220 : 288);
ff381587 10726
a4f6c312 10727 /* Zero offsets if we're not saving those registers. */
8dda1a21 10728 if (info_ptr->fp_size == 0)
4697a36c
MM
10729 info_ptr->fp_save_offset = 0;
10730
8dda1a21 10731 if (info_ptr->gp_size == 0)
4697a36c
MM
10732 info_ptr->gp_save_offset = 0;
10733
00b960c7
AH
10734 if (! TARGET_ALTIVEC_ABI || info_ptr->altivec_size == 0)
10735 info_ptr->altivec_save_offset = 0;
10736
10737 if (! TARGET_ALTIVEC_ABI || info_ptr->vrsave_mask == 0)
10738 info_ptr->vrsave_save_offset = 0;
10739
c19de7aa
AH
10740 if (! TARGET_SPE_ABI
10741 || info_ptr->spe_64bit_regs_used == 0
10742 || info_ptr->spe_gp_size == 0)
a3170dc6
AH
10743 info_ptr->spe_gp_save_offset = 0;
10744
c81fc13e 10745 if (! info_ptr->lr_save_p)
4697a36c
MM
10746 info_ptr->lr_save_offset = 0;
10747
c81fc13e 10748 if (! info_ptr->cr_save_p)
4697a36c
MM
10749 info_ptr->cr_save_offset = 0;
10750
c81fc13e 10751 if (! info_ptr->toc_save_p)
b6c9286a
MM
10752 info_ptr->toc_save_offset = 0;
10753
4697a36c
MM
10754 return info_ptr;
10755}
10756
c19de7aa
AH
10757/* Return true if the current function uses any GPRs in 64-bit SIMD
10758 mode. */
10759
10760static bool
863d938c 10761spe_func_has_64bit_regs_p (void)
c19de7aa
AH
10762{
10763 rtx insns, insn;
10764
10765 /* Functions that save and restore all the call-saved registers will
10766 need to save/restore the registers in 64-bits. */
10767 if (current_function_calls_eh_return
10768 || current_function_calls_setjmp
10769 || current_function_has_nonlocal_goto)
10770 return true;
10771
10772 insns = get_insns ();
10773
10774 for (insn = NEXT_INSN (insns); insn != NULL_RTX; insn = NEXT_INSN (insn))
10775 {
10776 if (INSN_P (insn))
10777 {
10778 rtx i;
10779
10780 i = PATTERN (insn);
10781 if (GET_CODE (i) == SET
10782 && SPE_VECTOR_MODE (GET_MODE (SET_SRC (i))))
10783 return true;
10784 }
10785 }
10786
10787 return false;
10788}
10789
d1d0c603 10790static void
a2369ed3 10791debug_stack_info (rs6000_stack_t *info)
9878760c 10792{
d330fd93 10793 const char *abi_string;
24d304eb 10794
c81fc13e 10795 if (! info)
4697a36c
MM
10796 info = rs6000_stack_info ();
10797
10798 fprintf (stderr, "\nStack information for function %s:\n",
10799 ((current_function_decl && DECL_NAME (current_function_decl))
10800 ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl))
10801 : "<unknown>"));
10802
24d304eb
RK
10803 switch (info->abi)
10804 {
b6c9286a
MM
10805 default: abi_string = "Unknown"; break;
10806 case ABI_NONE: abi_string = "NONE"; break;
50d440bc 10807 case ABI_AIX: abi_string = "AIX"; break;
ee890fe2 10808 case ABI_DARWIN: abi_string = "Darwin"; break;
b6c9286a 10809 case ABI_V4: abi_string = "V.4"; break;
24d304eb
RK
10810 }
10811
10812 fprintf (stderr, "\tABI = %5s\n", abi_string);
10813
00b960c7
AH
10814 if (TARGET_ALTIVEC_ABI)
10815 fprintf (stderr, "\tALTIVEC ABI extensions enabled.\n");
10816
a3170dc6
AH
10817 if (TARGET_SPE_ABI)
10818 fprintf (stderr, "\tSPE ABI extensions enabled.\n");
10819
4697a36c
MM
10820 if (info->first_gp_reg_save != 32)
10821 fprintf (stderr, "\tfirst_gp_reg_save = %5d\n", info->first_gp_reg_save);
10822
10823 if (info->first_fp_reg_save != 64)
10824 fprintf (stderr, "\tfirst_fp_reg_save = %5d\n", info->first_fp_reg_save);
9878760c 10825
00b960c7
AH
10826 if (info->first_altivec_reg_save <= LAST_ALTIVEC_REGNO)
10827 fprintf (stderr, "\tfirst_altivec_reg_save = %5d\n",
10828 info->first_altivec_reg_save);
10829
4697a36c
MM
10830 if (info->lr_save_p)
10831 fprintf (stderr, "\tlr_save_p = %5d\n", info->lr_save_p);
9878760c 10832
4697a36c
MM
10833 if (info->cr_save_p)
10834 fprintf (stderr, "\tcr_save_p = %5d\n", info->cr_save_p);
10835
b6c9286a
MM
10836 if (info->toc_save_p)
10837 fprintf (stderr, "\ttoc_save_p = %5d\n", info->toc_save_p);
10838
00b960c7
AH
10839 if (info->vrsave_mask)
10840 fprintf (stderr, "\tvrsave_mask = 0x%x\n", info->vrsave_mask);
10841
4697a36c
MM
10842 if (info->push_p)
10843 fprintf (stderr, "\tpush_p = %5d\n", info->push_p);
10844
10845 if (info->calls_p)
10846 fprintf (stderr, "\tcalls_p = %5d\n", info->calls_p);
10847
4697a36c
MM
10848 if (info->gp_save_offset)
10849 fprintf (stderr, "\tgp_save_offset = %5d\n", info->gp_save_offset);
10850
10851 if (info->fp_save_offset)
10852 fprintf (stderr, "\tfp_save_offset = %5d\n", info->fp_save_offset);
10853
00b960c7
AH
10854 if (info->altivec_save_offset)
10855 fprintf (stderr, "\taltivec_save_offset = %5d\n",
10856 info->altivec_save_offset);
10857
a3170dc6
AH
10858 if (info->spe_gp_save_offset)
10859 fprintf (stderr, "\tspe_gp_save_offset = %5d\n",
10860 info->spe_gp_save_offset);
10861
00b960c7
AH
10862 if (info->vrsave_save_offset)
10863 fprintf (stderr, "\tvrsave_save_offset = %5d\n",
10864 info->vrsave_save_offset);
10865
4697a36c
MM
10866 if (info->lr_save_offset)
10867 fprintf (stderr, "\tlr_save_offset = %5d\n", info->lr_save_offset);
10868
10869 if (info->cr_save_offset)
10870 fprintf (stderr, "\tcr_save_offset = %5d\n", info->cr_save_offset);
10871
b6c9286a
MM
10872 if (info->toc_save_offset)
10873 fprintf (stderr, "\ttoc_save_offset = %5d\n", info->toc_save_offset);
10874
4697a36c
MM
10875 if (info->varargs_save_offset)
10876 fprintf (stderr, "\tvarargs_save_offset = %5d\n", info->varargs_save_offset);
10877
10878 if (info->total_size)
d1d0c603
JJ
10879 fprintf (stderr, "\ttotal_size = "HOST_WIDE_INT_PRINT_DEC"\n",
10880 info->total_size);
4697a36c
MM
10881
10882 if (info->varargs_size)
10883 fprintf (stderr, "\tvarargs_size = %5d\n", info->varargs_size);
10884
10885 if (info->vars_size)
d1d0c603
JJ
10886 fprintf (stderr, "\tvars_size = "HOST_WIDE_INT_PRINT_DEC"\n",
10887 info->vars_size);
4697a36c
MM
10888
10889 if (info->parm_size)
10890 fprintf (stderr, "\tparm_size = %5d\n", info->parm_size);
10891
10892 if (info->fixed_size)
10893 fprintf (stderr, "\tfixed_size = %5d\n", info->fixed_size);
10894
10895 if (info->gp_size)
10896 fprintf (stderr, "\tgp_size = %5d\n", info->gp_size);
10897
a3170dc6
AH
10898 if (info->spe_gp_size)
10899 fprintf (stderr, "\tspe_gp_size = %5d\n", info->spe_gp_size);
10900
4697a36c
MM
10901 if (info->fp_size)
10902 fprintf (stderr, "\tfp_size = %5d\n", info->fp_size);
10903
00b960c7
AH
10904 if (info->altivec_size)
10905 fprintf (stderr, "\taltivec_size = %5d\n", info->altivec_size);
10906
10907 if (info->vrsave_size)
10908 fprintf (stderr, "\tvrsave_size = %5d\n", info->vrsave_size);
10909
10910 if (info->altivec_padding_size)
10911 fprintf (stderr, "\taltivec_padding_size= %5d\n",
10912 info->altivec_padding_size);
10913
a3170dc6
AH
10914 if (info->spe_padding_size)
10915 fprintf (stderr, "\tspe_padding_size = %5d\n",
10916 info->spe_padding_size);
10917
a4f6c312 10918 if (info->lr_size)
ed947a96 10919 fprintf (stderr, "\tlr_size = %5d\n", info->lr_size);
b6c9286a 10920
4697a36c
MM
10921 if (info->cr_size)
10922 fprintf (stderr, "\tcr_size = %5d\n", info->cr_size);
10923
a4f6c312 10924 if (info->toc_size)
b6c9286a
MM
10925 fprintf (stderr, "\ttoc_size = %5d\n", info->toc_size);
10926
4697a36c
MM
10927 if (info->save_size)
10928 fprintf (stderr, "\tsave_size = %5d\n", info->save_size);
10929
10930 if (info->reg_size != 4)
10931 fprintf (stderr, "\treg_size = %5d\n", info->reg_size);
10932
10933 fprintf (stderr, "\n");
9878760c 10934}
71f123ca
FS
10935
10936rtx
a2369ed3 10937rs6000_return_addr (int count, rtx frame)
71f123ca 10938{
a4f6c312
SS
10939 /* Currently we don't optimize very well between prolog and body
10940 code and for PIC code the code can be actually quite bad, so
10941 don't try to be too clever here. */
f1384257 10942 if (count != 0 || (DEFAULT_ABI != ABI_AIX && flag_pic))
71f123ca
FS
10943 {
10944 cfun->machine->ra_needs_full_frame = 1;
8ac61af7
RK
10945
10946 return
10947 gen_rtx_MEM
10948 (Pmode,
10949 memory_address
10950 (Pmode,
10951 plus_constant (copy_to_reg
10952 (gen_rtx_MEM (Pmode,
10953 memory_address (Pmode, frame))),
10954 RETURN_ADDRESS_OFFSET)));
71f123ca
FS
10955 }
10956
8c29550d 10957 cfun->machine->ra_need_lr = 1;
9e2f7ec7 10958 return get_hard_reg_initial_val (Pmode, LINK_REGISTER_REGNUM);
71f123ca
FS
10959}
10960
5e1bf043
DJ
10961/* Say whether a function is a candidate for sibcall handling or not.
10962 We do not allow indirect calls to be optimized into sibling calls.
10963 Also, we can't do it if there are any vector parameters; there's
10964 nowhere to put the VRsave code so it works; note that functions with
10965 vector parameters are required to have a prototype, so the argument
10966 type info must be available here. (The tail recursion case can work
10967 with vector parameters, but there's no way to distinguish here.) */
4977bab6 10968static bool
a2369ed3 10969rs6000_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
5e1bf043
DJ
10970{
10971 tree type;
4977bab6 10972 if (decl)
5e1bf043
DJ
10973 {
10974 if (TARGET_ALTIVEC_VRSAVE)
10975 {
4977bab6 10976 for (type = TYPE_ARG_TYPES (TREE_TYPE (decl));
5e1bf043
DJ
10977 type; type = TREE_CHAIN (type))
10978 {
c15b529f 10979 if (TREE_CODE (TREE_VALUE (type)) == VECTOR_TYPE)
4977bab6 10980 return false;
5e1bf043
DJ
10981 }
10982 }
10983 if (DEFAULT_ABI == ABI_DARWIN
4977bab6 10984 || (*targetm.binds_local_p) (decl))
2bcc50d0 10985 {
4977bab6 10986 tree attr_list = TYPE_ATTRIBUTES (TREE_TYPE (decl));
2bcc50d0
AM
10987
10988 if (!lookup_attribute ("longcall", attr_list)
10989 || lookup_attribute ("shortcall", attr_list))
4977bab6 10990 return true;
2bcc50d0 10991 }
5e1bf043 10992 }
4977bab6 10993 return false;
5e1bf043
DJ
10994}
10995
71f123ca 10996static int
863d938c 10997rs6000_ra_ever_killed (void)
71f123ca
FS
10998{
10999 rtx top;
5e1bf043
DJ
11000 rtx reg;
11001 rtx insn;
71f123ca 11002
dd292d0a 11003 if (current_function_is_thunk)
71f123ca 11004 return 0;
eb0424da 11005
36f7e964
AH
11006 /* regs_ever_live has LR marked as used if any sibcalls are present,
11007 but this should not force saving and restoring in the
11008 pro/epilogue. Likewise, reg_set_between_p thinks a sibcall
a3c9585f 11009 clobbers LR, so that is inappropriate. */
36f7e964 11010
5e1bf043
DJ
11011 /* Also, the prologue can generate a store into LR that
11012 doesn't really count, like this:
36f7e964 11013
5e1bf043
DJ
11014 move LR->R0
11015 bcl to set PIC register
11016 move LR->R31
11017 move R0->LR
36f7e964
AH
11018
11019 When we're called from the epilogue, we need to avoid counting
11020 this as a store. */
5e1bf043 11021
71f123ca
FS
11022 push_topmost_sequence ();
11023 top = get_insns ();
11024 pop_topmost_sequence ();
5e1bf043 11025 reg = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
71f123ca 11026
5e1bf043
DJ
11027 for (insn = NEXT_INSN (top); insn != NULL_RTX; insn = NEXT_INSN (insn))
11028 {
11029 if (INSN_P (insn))
11030 {
11031 if (FIND_REG_INC_NOTE (insn, reg))
11032 return 1;
11033 else if (GET_CODE (insn) == CALL_INSN
c15b529f 11034 && !SIBLING_CALL_P (insn))
5e1bf043 11035 return 1;
36f7e964
AH
11036 else if (set_of (reg, insn) != NULL_RTX
11037 && !prologue_epilogue_contains (insn))
5e1bf043
DJ
11038 return 1;
11039 }
11040 }
11041 return 0;
71f123ca 11042}
4697a36c 11043\f
8cd8f856
GK
11044/* Add a REG_MAYBE_DEAD note to the insn. */
11045static void
a2369ed3 11046rs6000_maybe_dead (rtx insn)
8cd8f856
GK
11047{
11048 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
11049 const0_rtx,
11050 REG_NOTES (insn));
11051}
11052
9ebbca7d 11053/* Emit instructions needed to load the TOC register.
c7ca610e 11054 This is only needed when TARGET_TOC, TARGET_MINIMAL_TOC, and there is
9ebbca7d 11055 a constant pool; or for SVR4 -fpic. */
c7ca610e
RK
11056
11057void
a2369ed3 11058rs6000_emit_load_toc_table (int fromprolog)
c7ca610e 11059{
027fbf43 11060 rtx dest, insn;
1db02437 11061 dest = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
c7ca610e 11062
20b71b17
AM
11063 if (TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11064 {
11065 rtx temp = (fromprolog
11066 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11067 : gen_reg_rtx (Pmode));
027fbf43
JJ
11068 insn = emit_insn (gen_load_toc_v4_pic_si (temp));
11069 if (fromprolog)
11070 rs6000_maybe_dead (insn);
11071 insn = emit_move_insn (dest, temp);
11072 if (fromprolog)
11073 rs6000_maybe_dead (insn);
20b71b17
AM
11074 }
11075 else if (TARGET_ELF && DEFAULT_ABI != ABI_AIX && flag_pic == 2)
11076 {
11077 char buf[30];
11078 rtx tempLR = (fromprolog
11079 ? gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)
11080 : gen_reg_rtx (Pmode));
11081 rtx temp0 = (fromprolog
11082 ? gen_rtx_REG (Pmode, 0)
11083 : gen_reg_rtx (Pmode));
11084 rtx symF;
11085
11086 /* possibly create the toc section */
11087 if (! toc_initialized)
38c1f2d7 11088 {
20b71b17
AM
11089 toc_section ();
11090 function_section (current_function_decl);
38c1f2d7 11091 }
9ebbca7d 11092
20b71b17
AM
11093 if (fromprolog)
11094 {
11095 rtx symL;
38c1f2d7 11096
20b71b17
AM
11097 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
11098 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
9ebbca7d 11099
20b71b17
AM
11100 ASM_GENERATE_INTERNAL_LABEL (buf, "LCL", rs6000_pic_labelno);
11101 symL = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11102
11103 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_1 (tempLR,
11104 symF)));
11105 rs6000_maybe_dead (emit_move_insn (dest, tempLR));
11106 rs6000_maybe_dead (emit_insn (gen_load_toc_v4_PIC_2 (temp0, dest,
11107 symL,
11108 symF)));
9ebbca7d
GK
11109 }
11110 else
20b71b17
AM
11111 {
11112 rtx tocsym;
11113 static int reload_toc_labelno = 0;
11114
11115 tocsym = gen_rtx_SYMBOL_REF (Pmode, toc_label_name);
11116
11117 ASM_GENERATE_INTERNAL_LABEL (buf, "LCG", reload_toc_labelno++);
11118 symF = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11119
027fbf43
JJ
11120 emit_insn (gen_load_toc_v4_PIC_1b (tempLR, symF, tocsym));
11121 emit_move_insn (dest, tempLR);
11122 emit_move_insn (temp0, gen_rtx_MEM (Pmode, dest));
20b71b17 11123 }
027fbf43
JJ
11124 insn = emit_insn (gen_addsi3 (dest, temp0, dest));
11125 if (fromprolog)
11126 rs6000_maybe_dead (insn);
9ebbca7d 11127 }
20b71b17
AM
11128 else if (TARGET_ELF && !TARGET_AIX && flag_pic == 0 && TARGET_MINIMAL_TOC)
11129 {
11130 /* This is for AIX code running in non-PIC ELF32. */
11131 char buf[30];
11132 rtx realsym;
11133 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11134 realsym = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11135
027fbf43
JJ
11136 insn = emit_insn (gen_elf_high (dest, realsym));
11137 if (fromprolog)
11138 rs6000_maybe_dead (insn);
11139 insn = emit_insn (gen_elf_low (dest, dest, realsym));
11140 if (fromprolog)
11141 rs6000_maybe_dead (insn);
20b71b17
AM
11142 }
11143 else if (DEFAULT_ABI == ABI_AIX)
9ebbca7d
GK
11144 {
11145 if (TARGET_32BIT)
027fbf43 11146 insn = emit_insn (gen_load_toc_aix_si (dest));
9ebbca7d 11147 else
027fbf43
JJ
11148 insn = emit_insn (gen_load_toc_aix_di (dest));
11149 if (fromprolog)
11150 rs6000_maybe_dead (insn);
9ebbca7d 11151 }
20b71b17
AM
11152 else
11153 abort ();
9ebbca7d
GK
11154}
11155
d1d0c603
JJ
11156/* Emit instructions to restore the link register after determining where
11157 its value has been stored. */
11158
11159void
11160rs6000_emit_eh_reg_restore (rtx source, rtx scratch)
11161{
11162 rs6000_stack_t *info = rs6000_stack_info ();
11163 rtx operands[2];
11164
11165 operands[0] = source;
11166 operands[1] = scratch;
11167
11168 if (info->lr_save_p)
11169 {
11170 rtx frame_rtx = stack_pointer_rtx;
11171 HOST_WIDE_INT sp_offset = 0;
11172 rtx tmp;
11173
11174 if (frame_pointer_needed
11175 || current_function_calls_alloca
11176 || info->total_size > 32767)
11177 {
11178 emit_move_insn (operands[1], gen_rtx_MEM (Pmode, frame_rtx));
11179 frame_rtx = operands[1];
11180 }
11181 else if (info->push_p)
11182 sp_offset = info->total_size;
11183
11184 tmp = plus_constant (frame_rtx, info->lr_save_offset + sp_offset);
11185 tmp = gen_rtx_MEM (Pmode, tmp);
11186 emit_move_insn (tmp, operands[0]);
11187 }
11188 else
11189 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM), operands[0]);
11190}
11191
f103e34d
GK
11192static GTY(()) int set = -1;
11193
9ebbca7d 11194int
863d938c 11195get_TOC_alias_set (void)
9ebbca7d 11196{
f103e34d
GK
11197 if (set == -1)
11198 set = new_alias_set ();
11199 return set;
9ebbca7d
GK
11200}
11201
c1207243 11202/* This returns nonzero if the current function uses the TOC. This is
3c9eb5f4
AM
11203 determined by the presence of (use (unspec ... UNSPEC_TOC)), which
11204 is generated by the ABI_V4 load_toc_* patterns. */
c954844a 11205#if TARGET_ELF
3c9eb5f4 11206static int
38f391a5 11207uses_TOC (void)
9ebbca7d 11208{
c4501e62 11209 rtx insn;
38c1f2d7 11210
c4501e62
JJ
11211 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
11212 if (INSN_P (insn))
11213 {
11214 rtx pat = PATTERN (insn);
11215 int i;
9ebbca7d 11216
c4501e62
JJ
11217 if (GET_CODE (pat) == PARALLEL)
11218 for (i = 0; i < XVECLEN (pat, 0); i++)
11219 {
11220 rtx sub = XVECEXP (pat, 0, i);
11221 if (GET_CODE (sub) == USE)
11222 {
11223 sub = XEXP (sub, 0);
11224 if (GET_CODE (sub) == UNSPEC
11225 && XINT (sub, 1) == UNSPEC_TOC)
11226 return 1;
11227 }
11228 }
11229 }
11230 return 0;
9ebbca7d 11231}
c954844a 11232#endif
38c1f2d7 11233
9ebbca7d 11234rtx
a2369ed3 11235create_TOC_reference (rtx symbol)
9ebbca7d 11236{
a8a05998
ZW
11237 return gen_rtx_PLUS (Pmode,
11238 gen_rtx_REG (Pmode, TOC_REGISTER),
11239 gen_rtx_CONST (Pmode,
11240 gen_rtx_MINUS (Pmode, symbol,
b999aaeb 11241 gen_rtx_SYMBOL_REF (Pmode, toc_label_name))));
9ebbca7d 11242}
38c1f2d7 11243
fc4767bb
JJ
11244/* If _Unwind_* has been called from within the same module,
11245 toc register is not guaranteed to be saved to 40(1) on function
11246 entry. Save it there in that case. */
c7ca610e 11247
9ebbca7d 11248void
863d938c 11249rs6000_aix_emit_builtin_unwind_init (void)
9ebbca7d
GK
11250{
11251 rtx mem;
11252 rtx stack_top = gen_reg_rtx (Pmode);
11253 rtx opcode_addr = gen_reg_rtx (Pmode);
fc4767bb
JJ
11254 rtx opcode = gen_reg_rtx (SImode);
11255 rtx tocompare = gen_reg_rtx (SImode);
11256 rtx no_toc_save_needed = gen_label_rtx ();
9ebbca7d
GK
11257
11258 mem = gen_rtx_MEM (Pmode, hard_frame_pointer_rtx);
11259 emit_move_insn (stack_top, mem);
11260
fc4767bb
JJ
11261 mem = gen_rtx_MEM (Pmode,
11262 gen_rtx_PLUS (Pmode, stack_top,
9ebbca7d
GK
11263 GEN_INT (2 * GET_MODE_SIZE (Pmode))));
11264 emit_move_insn (opcode_addr, mem);
fc4767bb
JJ
11265 emit_move_insn (opcode, gen_rtx_MEM (SImode, opcode_addr));
11266 emit_move_insn (tocompare, gen_int_mode (TARGET_32BIT ? 0x80410014
2496c7bd 11267 : 0xE8410028, SImode));
9ebbca7d 11268
fc4767bb 11269 do_compare_rtx_and_jump (opcode, tocompare, EQ, 1,
06f4e019 11270 SImode, NULL_RTX, NULL_RTX,
fc4767bb 11271 no_toc_save_needed);
9ebbca7d 11272
fc4767bb
JJ
11273 mem = gen_rtx_MEM (Pmode,
11274 gen_rtx_PLUS (Pmode, stack_top,
11275 GEN_INT (5 * GET_MODE_SIZE (Pmode))));
11276 emit_move_insn (mem, gen_rtx_REG (Pmode, 2));
11277 emit_label (no_toc_save_needed);
9ebbca7d 11278}
38c1f2d7 11279\f
ba4828e0
RK
11280/* This ties together stack memory (MEM with an alias set of
11281 rs6000_sr_alias_set) and the change to the stack pointer. */
11282
9ebbca7d 11283static void
863d938c 11284rs6000_emit_stack_tie (void)
9ebbca7d 11285{
ba4828e0
RK
11286 rtx mem = gen_rtx_MEM (BLKmode, gen_rtx_REG (Pmode, STACK_POINTER_REGNUM));
11287
11288 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11289 emit_insn (gen_stack_tie (mem));
11290}
38c1f2d7 11291
9ebbca7d
GK
11292/* Emit the correct code for allocating stack space, as insns.
11293 If COPY_R12, make sure a copy of the old frame is left in r12.
11294 The generated code may use hard register 0 as a temporary. */
11295
11296static void
a2369ed3 11297rs6000_emit_allocate_stack (HOST_WIDE_INT size, int copy_r12)
38c1f2d7 11298{
9ebbca7d
GK
11299 rtx insn;
11300 rtx stack_reg = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11301 rtx tmp_reg = gen_rtx_REG (Pmode, 0);
11302 rtx todec = GEN_INT (-size);
a157febd
GK
11303
11304 if (current_function_limit_stack)
11305 {
11306 if (REG_P (stack_limit_rtx)
11307 && REGNO (stack_limit_rtx) > 1
11308 && REGNO (stack_limit_rtx) <= 31)
11309 {
5b71a4e7 11310 emit_insn (TARGET_32BIT
9ebbca7d
GK
11311 ? gen_addsi3 (tmp_reg,
11312 stack_limit_rtx,
11313 GEN_INT (size))
11314 : gen_adddi3 (tmp_reg,
11315 stack_limit_rtx,
11316 GEN_INT (size)));
5b71a4e7 11317
9ebbca7d
GK
11318 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11319 const0_rtx));
a157febd
GK
11320 }
11321 else if (GET_CODE (stack_limit_rtx) == SYMBOL_REF
9ebbca7d 11322 && TARGET_32BIT
f607bc57 11323 && DEFAULT_ABI == ABI_V4)
a157febd 11324 {
9ebbca7d
GK
11325 rtx toload = gen_rtx_CONST (VOIDmode,
11326 gen_rtx_PLUS (Pmode,
11327 stack_limit_rtx,
11328 GEN_INT (size)));
5b71a4e7 11329
9ebbca7d
GK
11330 emit_insn (gen_elf_high (tmp_reg, toload));
11331 emit_insn (gen_elf_low (tmp_reg, tmp_reg, toload));
11332 emit_insn (gen_cond_trap (LTU, stack_reg, tmp_reg,
11333 const0_rtx));
a157febd
GK
11334 }
11335 else
11336 warning ("stack limit expression is not supported");
11337 }
11338
9ebbca7d
GK
11339 if (copy_r12 || ! TARGET_UPDATE)
11340 emit_move_insn (gen_rtx_REG (Pmode, 12), stack_reg);
11341
38c1f2d7
MM
11342 if (TARGET_UPDATE)
11343 {
9ebbca7d 11344 if (size > 32767)
38c1f2d7 11345 {
9ebbca7d
GK
11346 /* Need a note here so that try_split doesn't get confused. */
11347 if (get_last_insn() == NULL_RTX)
2e040219 11348 emit_note (NOTE_INSN_DELETED);
9ebbca7d
GK
11349 insn = emit_move_insn (tmp_reg, todec);
11350 try_split (PATTERN (insn), insn, 0);
11351 todec = tmp_reg;
38c1f2d7 11352 }
5b71a4e7
DE
11353
11354 insn = emit_insn (TARGET_32BIT
11355 ? gen_movsi_update (stack_reg, stack_reg,
11356 todec, stack_reg)
11357 : gen_movdi_update (stack_reg, stack_reg,
9ebbca7d 11358 todec, stack_reg));
38c1f2d7
MM
11359 }
11360 else
11361 {
5b71a4e7
DE
11362 insn = emit_insn (TARGET_32BIT
11363 ? gen_addsi3 (stack_reg, stack_reg, todec)
11364 : gen_adddi3 (stack_reg, stack_reg, todec));
9ebbca7d
GK
11365 emit_move_insn (gen_rtx_MEM (Pmode, stack_reg),
11366 gen_rtx_REG (Pmode, 12));
11367 }
5b71a4e7 11368
9ebbca7d
GK
11369 RTX_FRAME_RELATED_P (insn) = 1;
11370 REG_NOTES (insn) =
11371 gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11372 gen_rtx_SET (VOIDmode, stack_reg,
11373 gen_rtx_PLUS (Pmode, stack_reg,
11374 GEN_INT (-size))),
11375 REG_NOTES (insn));
11376}
11377
a4f6c312
SS
11378/* Add to 'insn' a note which is PATTERN (INSN) but with REG replaced
11379 with (plus:P (reg 1) VAL), and with REG2 replaced with RREG if REG2
11380 is not NULL. It would be nice if dwarf2out_frame_debug_expr could
11381 deduce these equivalences by itself so it wasn't necessary to hold
11382 its hand so much. */
9ebbca7d
GK
11383
11384static void
a2369ed3
DJ
11385rs6000_frame_related (rtx insn, rtx reg, HOST_WIDE_INT val,
11386 rtx reg2, rtx rreg)
9ebbca7d
GK
11387{
11388 rtx real, temp;
11389
e56c4463
JL
11390 /* copy_rtx will not make unique copies of registers, so we need to
11391 ensure we don't have unwanted sharing here. */
11392 if (reg == reg2)
11393 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11394
11395 if (reg == rreg)
11396 reg = gen_raw_REG (GET_MODE (reg), REGNO (reg));
11397
9ebbca7d
GK
11398 real = copy_rtx (PATTERN (insn));
11399
89e7058f
AH
11400 if (reg2 != NULL_RTX)
11401 real = replace_rtx (real, reg2, rreg);
11402
9ebbca7d
GK
11403 real = replace_rtx (real, reg,
11404 gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode,
11405 STACK_POINTER_REGNUM),
11406 GEN_INT (val)));
11407
11408 /* We expect that 'real' is either a SET or a PARALLEL containing
11409 SETs (and possibly other stuff). In a PARALLEL, all the SETs
11410 are important so they all have to be marked RTX_FRAME_RELATED_P. */
11411
11412 if (GET_CODE (real) == SET)
11413 {
11414 rtx set = real;
11415
11416 temp = simplify_rtx (SET_SRC (set));
11417 if (temp)
11418 SET_SRC (set) = temp;
11419 temp = simplify_rtx (SET_DEST (set));
11420 if (temp)
11421 SET_DEST (set) = temp;
11422 if (GET_CODE (SET_DEST (set)) == MEM)
38c1f2d7 11423 {
9ebbca7d
GK
11424 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11425 if (temp)
11426 XEXP (SET_DEST (set), 0) = temp;
38c1f2d7 11427 }
38c1f2d7 11428 }
9ebbca7d
GK
11429 else if (GET_CODE (real) == PARALLEL)
11430 {
11431 int i;
11432 for (i = 0; i < XVECLEN (real, 0); i++)
11433 if (GET_CODE (XVECEXP (real, 0, i)) == SET)
11434 {
11435 rtx set = XVECEXP (real, 0, i);
11436
11437 temp = simplify_rtx (SET_SRC (set));
11438 if (temp)
11439 SET_SRC (set) = temp;
11440 temp = simplify_rtx (SET_DEST (set));
11441 if (temp)
11442 SET_DEST (set) = temp;
11443 if (GET_CODE (SET_DEST (set)) == MEM)
11444 {
11445 temp = simplify_rtx (XEXP (SET_DEST (set), 0));
11446 if (temp)
11447 XEXP (SET_DEST (set), 0) = temp;
11448 }
11449 RTX_FRAME_RELATED_P (set) = 1;
11450 }
11451 }
11452 else
a4f6c312 11453 abort ();
c19de7aa
AH
11454
11455 if (TARGET_SPE)
11456 real = spe_synthesize_frame_save (real);
11457
9ebbca7d
GK
11458 RTX_FRAME_RELATED_P (insn) = 1;
11459 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
11460 real,
11461 REG_NOTES (insn));
38c1f2d7
MM
11462}
11463
c19de7aa
AH
11464/* Given an SPE frame note, return a PARALLEL of SETs with the
11465 original note, plus a synthetic register save. */
11466
11467static rtx
a2369ed3 11468spe_synthesize_frame_save (rtx real)
c19de7aa
AH
11469{
11470 rtx synth, offset, reg, real2;
11471
11472 if (GET_CODE (real) != SET
11473 || GET_MODE (SET_SRC (real)) != V2SImode)
11474 return real;
11475
11476 /* For the SPE, registers saved in 64-bits, get a PARALLEL for their
11477 frame related note. The parallel contains a set of the register
41f3a930 11478 being saved, and another set to a synthetic register (n+1200).
c19de7aa
AH
11479 This is so we can differentiate between 64-bit and 32-bit saves.
11480 Words cannot describe this nastiness. */
11481
11482 if (GET_CODE (SET_DEST (real)) != MEM
11483 || GET_CODE (XEXP (SET_DEST (real), 0)) != PLUS
11484 || GET_CODE (SET_SRC (real)) != REG)
11485 abort ();
11486
11487 /* Transform:
11488 (set (mem (plus (reg x) (const y)))
11489 (reg z))
11490 into:
11491 (set (mem (plus (reg x) (const y+4)))
41f3a930 11492 (reg z+1200))
c19de7aa
AH
11493 */
11494
11495 real2 = copy_rtx (real);
11496 PUT_MODE (SET_DEST (real2), SImode);
11497 reg = SET_SRC (real2);
11498 real2 = replace_rtx (real2, reg, gen_rtx_REG (SImode, REGNO (reg)));
11499 synth = copy_rtx (real2);
11500
11501 if (BYTES_BIG_ENDIAN)
11502 {
11503 offset = XEXP (XEXP (SET_DEST (real2), 0), 1);
11504 real2 = replace_rtx (real2, offset, GEN_INT (INTVAL (offset) + 4));
11505 }
11506
11507 reg = SET_SRC (synth);
41f3a930 11508
c19de7aa 11509 synth = replace_rtx (synth, reg,
41f3a930 11510 gen_rtx_REG (SImode, REGNO (reg) + 1200));
c19de7aa
AH
11511
11512 offset = XEXP (XEXP (SET_DEST (synth), 0), 1);
11513 synth = replace_rtx (synth, offset,
11514 GEN_INT (INTVAL (offset)
11515 + (BYTES_BIG_ENDIAN ? 0 : 4)));
11516
11517 RTX_FRAME_RELATED_P (synth) = 1;
11518 RTX_FRAME_RELATED_P (real2) = 1;
11519 if (BYTES_BIG_ENDIAN)
11520 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, synth, real2));
11521 else
11522 real = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, real2, synth));
11523
11524 return real;
11525}
11526
00b960c7
AH
11527/* Returns an insn that has a vrsave set operation with the
11528 appropriate CLOBBERs. */
11529
11530static rtx
a2369ed3 11531generate_set_vrsave (rtx reg, rs6000_stack_t *info, int epiloguep)
00b960c7
AH
11532{
11533 int nclobs, i;
11534 rtx insn, clobs[TOTAL_ALTIVEC_REGS + 1];
a004eb82 11535 rtx vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
00b960c7 11536
a004eb82
AH
11537 clobs[0]
11538 = gen_rtx_SET (VOIDmode,
11539 vrsave,
11540 gen_rtx_UNSPEC_VOLATILE (SImode,
11541 gen_rtvec (2, reg, vrsave),
11542 30));
00b960c7
AH
11543
11544 nclobs = 1;
11545
9aa86737
AH
11546 /* We need to clobber the registers in the mask so the scheduler
11547 does not move sets to VRSAVE before sets of AltiVec registers.
11548
11549 However, if the function receives nonlocal gotos, reload will set
11550 all call saved registers live. We will end up with:
11551
11552 (set (reg 999) (mem))
11553 (parallel [ (set (reg vrsave) (unspec blah))
11554 (clobber (reg 999))])
11555
11556 The clobber will cause the store into reg 999 to be dead, and
11557 flow will attempt to delete an epilogue insn. In this case, we
11558 need an unspec use/set of the register. */
00b960c7
AH
11559
11560 for (i = FIRST_ALTIVEC_REGNO; i <= LAST_ALTIVEC_REGNO; ++i)
11561 if (info->vrsave_mask != 0 && ALTIVEC_REG_BIT (i) != 0)
9aa86737
AH
11562 {
11563 if (!epiloguep || call_used_regs [i])
11564 clobs[nclobs++] = gen_rtx_CLOBBER (VOIDmode,
11565 gen_rtx_REG (V4SImode, i));
11566 else
11567 {
11568 rtx reg = gen_rtx_REG (V4SImode, i);
9aa86737
AH
11569
11570 clobs[nclobs++]
a004eb82
AH
11571 = gen_rtx_SET (VOIDmode,
11572 reg,
11573 gen_rtx_UNSPEC (V4SImode,
11574 gen_rtvec (1, reg), 27));
9aa86737
AH
11575 }
11576 }
00b960c7
AH
11577
11578 insn = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nclobs));
11579
11580 for (i = 0; i < nclobs; ++i)
11581 XVECEXP (insn, 0, i) = clobs[i];
11582
11583 return insn;
11584}
11585
89e7058f
AH
11586/* Save a register into the frame, and emit RTX_FRAME_RELATED_P notes.
11587 Save REGNO into [FRAME_REG + OFFSET] in mode MODE. */
11588
11589static void
a2369ed3 11590emit_frame_save (rtx frame_reg, rtx frame_ptr, enum machine_mode mode,
d1d0c603 11591 unsigned int regno, int offset, HOST_WIDE_INT total_size)
89e7058f
AH
11592{
11593 rtx reg, offset_rtx, insn, mem, addr, int_rtx;
11594 rtx replacea, replaceb;
11595
11596 int_rtx = GEN_INT (offset);
11597
11598 /* Some cases that need register indexed addressing. */
11599 if ((TARGET_ALTIVEC_ABI && ALTIVEC_VECTOR_MODE (mode))
a3170dc6
AH
11600 || (TARGET_SPE_ABI
11601 && SPE_VECTOR_MODE (mode)
11602 && !SPE_CONST_OFFSET_OK (offset)))
89e7058f
AH
11603 {
11604 /* Whomever calls us must make sure r11 is available in the
11605 flow path of instructions in the prologue. */
11606 offset_rtx = gen_rtx_REG (Pmode, 11);
11607 emit_move_insn (offset_rtx, int_rtx);
11608
11609 replacea = offset_rtx;
11610 replaceb = int_rtx;
11611 }
11612 else
11613 {
11614 offset_rtx = int_rtx;
11615 replacea = NULL_RTX;
11616 replaceb = NULL_RTX;
11617 }
11618
11619 reg = gen_rtx_REG (mode, regno);
11620 addr = gen_rtx_PLUS (Pmode, frame_reg, offset_rtx);
11621 mem = gen_rtx_MEM (mode, addr);
11622 set_mem_alias_set (mem, rs6000_sr_alias_set);
11623
11624 insn = emit_move_insn (mem, reg);
11625
11626 rs6000_frame_related (insn, frame_ptr, total_size, replacea, replaceb);
11627}
11628
a3170dc6
AH
11629/* Emit an offset memory reference suitable for a frame store, while
11630 converting to a valid addressing mode. */
11631
11632static rtx
a2369ed3 11633gen_frame_mem_offset (enum machine_mode mode, rtx reg, int offset)
a3170dc6
AH
11634{
11635 rtx int_rtx, offset_rtx;
11636
11637 int_rtx = GEN_INT (offset);
11638
11639 if (TARGET_SPE_ABI && SPE_VECTOR_MODE (mode))
11640 {
11641 offset_rtx = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11642 emit_move_insn (offset_rtx, int_rtx);
11643 }
11644 else
11645 offset_rtx = int_rtx;
11646
11647 return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, reg, offset_rtx));
11648}
11649
9ebbca7d
GK
11650/* Emit function prologue as insns. */
11651
9878760c 11652void
863d938c 11653rs6000_emit_prologue (void)
9878760c 11654{
4697a36c 11655 rs6000_stack_t *info = rs6000_stack_info ();
0e67400a
FJ
11656 enum machine_mode reg_mode = Pmode;
11657 int reg_size = UNITS_PER_WORD;
9ebbca7d
GK
11658 rtx sp_reg_rtx = gen_rtx_REG (Pmode, STACK_POINTER_REGNUM);
11659 rtx frame_ptr_rtx = gen_rtx_REG (Pmode, 12);
11660 rtx frame_reg_rtx = sp_reg_rtx;
b78d48dd 11661 rtx cr_save_rtx = NULL_RTX;
9ebbca7d
GK
11662 rtx insn;
11663 int saving_FPRs_inline;
11664 int using_store_multiple;
11665 HOST_WIDE_INT sp_offset = 0;
11666
c19de7aa 11667 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11668 {
11669 reg_mode = V2SImode;
11670 reg_size = 8;
11671 }
11672
9ebbca7d 11673 using_store_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
11674 && (!TARGET_SPE_ABI
11675 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
11676 && info->first_gp_reg_save < 31);
11677 saving_FPRs_inline = (info->first_fp_reg_save == 64
8c29550d 11678 || FP_SAVE_INLINE (info->first_fp_reg_save)
acd0b319 11679 || current_function_calls_eh_return
8c29550d 11680 || cfun->machine->ra_need_lr);
9ebbca7d
GK
11681
11682 /* For V.4, update stack before we do any saving and set back pointer. */
fc4767bb 11683 if (info->push_p
acd0b319
AM
11684 && (DEFAULT_ABI == ABI_V4
11685 || current_function_calls_eh_return))
9ebbca7d
GK
11686 {
11687 if (info->total_size < 32767)
11688 sp_offset = info->total_size;
11689 else
11690 frame_reg_rtx = frame_ptr_rtx;
11691 rs6000_emit_allocate_stack (info->total_size,
11692 (frame_reg_rtx != sp_reg_rtx
11693 && (info->cr_save_p
11694 || info->lr_save_p
11695 || info->first_fp_reg_save < 64
11696 || info->first_gp_reg_save < 32
11697 )));
11698 if (frame_reg_rtx != sp_reg_rtx)
11699 rs6000_emit_stack_tie ();
11700 }
11701
9aa86737
AH
11702 /* Save AltiVec registers if needed. */
11703 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
11704 {
11705 int i;
11706
11707 /* There should be a non inline version of this, for when we
11708 are saving lots of vector registers. */
11709 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
11710 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
11711 {
11712 rtx areg, savereg, mem;
11713 int offset;
11714
11715 offset = info->altivec_save_offset + sp_offset
11716 + 16 * (i - info->first_altivec_reg_save);
11717
11718 savereg = gen_rtx_REG (V4SImode, i);
11719
11720 areg = gen_rtx_REG (Pmode, 0);
11721 emit_move_insn (areg, GEN_INT (offset));
11722
11723 /* AltiVec addressing mode is [reg+reg]. */
11724 mem = gen_rtx_MEM (V4SImode,
11725 gen_rtx_PLUS (Pmode, frame_reg_rtx, areg));
11726
11727 set_mem_alias_set (mem, rs6000_sr_alias_set);
11728
11729 insn = emit_move_insn (mem, savereg);
11730
5c242421
SB
11731 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11732 areg, GEN_INT (offset));
9aa86737
AH
11733 }
11734 }
11735
11736 /* VRSAVE is a bit vector representing which AltiVec registers
11737 are used. The OS uses this to determine which vector
11738 registers to save on a context switch. We need to save
11739 VRSAVE on the stack frame, add whatever AltiVec registers we
11740 used in this function, and do the corresponding magic in the
11741 epilogue. */
11742
4d774ff8
HP
11743 if (TARGET_ALTIVEC && TARGET_ALTIVEC_VRSAVE
11744 && info->vrsave_mask != 0)
9aa86737 11745 {
a004eb82 11746 rtx reg, mem, vrsave;
9aa86737
AH
11747 int offset;
11748
11749 /* Get VRSAVE onto a GPR. */
11750 reg = gen_rtx_REG (SImode, 12);
a004eb82 11751 vrsave = gen_rtx_REG (SImode, VRSAVE_REGNO);
b188f760
AH
11752 if (TARGET_MACHO)
11753 emit_insn (gen_get_vrsave_internal (reg));
11754 else
11755 emit_insn (gen_rtx_SET (VOIDmode, reg, vrsave));
9aa86737
AH
11756
11757 /* Save VRSAVE. */
11758 offset = info->vrsave_save_offset + sp_offset;
11759 mem
11760 = gen_rtx_MEM (SImode,
11761 gen_rtx_PLUS (Pmode, frame_reg_rtx, GEN_INT (offset)));
11762 set_mem_alias_set (mem, rs6000_sr_alias_set);
11763 insn = emit_move_insn (mem, reg);
11764
11765 /* Include the registers in the mask. */
11766 emit_insn (gen_iorsi3 (reg, reg, GEN_INT ((int) info->vrsave_mask)));
11767
11768 insn = emit_insn (generate_set_vrsave (reg, info, 0));
11769 }
11770
9ebbca7d
GK
11771 /* If we use the link register, get it into r0. */
11772 if (info->lr_save_p)
71f123ca 11773 emit_move_insn (gen_rtx_REG (Pmode, 0),
9ebbca7d
GK
11774 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11775
11776 /* If we need to save CR, put it into r12. */
11777 if (info->cr_save_p && frame_reg_rtx != frame_ptr_rtx)
11778 {
11779 cr_save_rtx = gen_rtx_REG (SImode, 12);
11780 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11781 }
11782
a4f6c312
SS
11783 /* Do any required saving of fpr's. If only one or two to save, do
11784 it ourselves. Otherwise, call function. */
9ebbca7d
GK
11785 if (saving_FPRs_inline)
11786 {
11787 int i;
11788 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11789 if ((regs_ever_live[info->first_fp_reg_save+i]
11790 && ! call_used_regs[info->first_fp_reg_save+i]))
89e7058f
AH
11791 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, DFmode,
11792 info->first_fp_reg_save + i,
11793 info->fp_save_offset + sp_offset + 8 * i,
11794 info->total_size);
9ebbca7d
GK
11795 }
11796 else if (info->first_fp_reg_save != 64)
11797 {
11798 int i;
11799 char rname[30];
520a57c8 11800 const char *alloc_rname;
9ebbca7d
GK
11801 rtvec p;
11802 p = rtvec_alloc (2 + 64 - info->first_fp_reg_save);
11803
11804 RTVEC_ELT (p, 0) = gen_rtx_CLOBBER (VOIDmode,
11805 gen_rtx_REG (Pmode,
11806 LINK_REGISTER_REGNUM));
11807 sprintf (rname, "%s%d%s", SAVE_FP_PREFIX,
11808 info->first_fp_reg_save - 32, SAVE_FP_SUFFIX);
a8a05998 11809 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
11810 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
11811 gen_rtx_SYMBOL_REF (Pmode,
11812 alloc_rname));
11813 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
11814 {
11815 rtx addr, reg, mem;
11816 reg = gen_rtx_REG (DFmode, info->first_fp_reg_save + i);
11817 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11818 GEN_INT (info->fp_save_offset
11819 + sp_offset + 8*i));
11820 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 11821 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11822
11823 RTVEC_ELT (p, i + 2) = gen_rtx_SET (VOIDmode, mem, reg);
11824 }
11825 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11826 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11827 NULL_RTX, NULL_RTX);
11828 }
b6c9286a 11829
9ebbca7d
GK
11830 /* Save GPRs. This is done as a PARALLEL if we are using
11831 the store-multiple instructions. */
11832 if (using_store_multiple)
b6c9286a 11833 {
308c142a 11834 rtvec p;
9ebbca7d
GK
11835 int i;
11836 p = rtvec_alloc (32 - info->first_gp_reg_save);
9ebbca7d
GK
11837 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11838 {
11839 rtx addr, reg, mem;
11840 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11841 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11842 GEN_INT (info->gp_save_offset
11843 + sp_offset
11844 + reg_size * i));
11845 mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 11846 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11847
11848 RTVEC_ELT (p, i) = gen_rtx_SET (VOIDmode, mem, reg);
11849 }
11850 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
11851 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11852 NULL_RTX, NULL_RTX);
b6c9286a
MM
11853 }
11854 else
11855 {
9ebbca7d
GK
11856 int i;
11857 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
11858 if ((regs_ever_live[info->first_gp_reg_save+i]
11859 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 11860 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 11861 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 11862 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
a3170dc6
AH
11863 {
11864 rtx addr, reg, mem;
11865 reg = gen_rtx_REG (reg_mode, info->first_gp_reg_save + i);
11866
c19de7aa 11867 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
11868 {
11869 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
11870 rtx b;
11871
11872 if (!SPE_CONST_OFFSET_OK (offset))
11873 {
11874 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
11875 emit_move_insn (b, GEN_INT (offset));
11876 }
11877 else
11878 b = GEN_INT (offset);
11879
11880 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
11881 mem = gen_rtx_MEM (V2SImode, addr);
11882 set_mem_alias_set (mem, rs6000_sr_alias_set);
11883 insn = emit_move_insn (mem, reg);
11884
11885 if (GET_CODE (b) == CONST_INT)
11886 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11887 NULL_RTX, NULL_RTX);
11888 else
11889 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11890 b, GEN_INT (offset));
11891 }
11892 else
11893 {
11894 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11895 GEN_INT (info->gp_save_offset
11896 + sp_offset
11897 + reg_size * i));
11898 mem = gen_rtx_MEM (reg_mode, addr);
11899 set_mem_alias_set (mem, rs6000_sr_alias_set);
11900
11901 insn = emit_move_insn (mem, reg);
11902 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11903 NULL_RTX, NULL_RTX);
11904 }
11905 }
9ebbca7d
GK
11906 }
11907
83720594
RH
11908 /* ??? There's no need to emit actual instructions here, but it's the
11909 easiest way to get the frame unwind information emitted. */
11910 if (current_function_calls_eh_return)
11911 {
78e1b90d
DE
11912 unsigned int i, regno;
11913
fc4767bb
JJ
11914 /* In AIX ABI we need to pretend we save r2 here. */
11915 if (TARGET_AIX)
11916 {
11917 rtx addr, reg, mem;
11918
11919 reg = gen_rtx_REG (reg_mode, 2);
11920 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11921 GEN_INT (sp_offset + 5 * reg_size));
11922 mem = gen_rtx_MEM (reg_mode, addr);
11923 set_mem_alias_set (mem, rs6000_sr_alias_set);
11924
11925 insn = emit_move_insn (mem, reg);
11926 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11927 NULL_RTX, NULL_RTX);
11928 PATTERN (insn) = gen_blockage ();
11929 }
11930
83720594
RH
11931 for (i = 0; ; ++i)
11932 {
83720594
RH
11933 regno = EH_RETURN_DATA_REGNO (i);
11934 if (regno == INVALID_REGNUM)
11935 break;
11936
89e7058f
AH
11937 emit_frame_save (frame_reg_rtx, frame_ptr_rtx, reg_mode, regno,
11938 info->ehrd_offset + sp_offset
11939 + reg_size * (int) i,
11940 info->total_size);
83720594
RH
11941 }
11942 }
11943
9ebbca7d
GK
11944 /* Save lr if we used it. */
11945 if (info->lr_save_p)
11946 {
11947 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11948 GEN_INT (info->lr_save_offset + sp_offset));
11949 rtx reg = gen_rtx_REG (Pmode, 0);
11950 rtx mem = gen_rtx_MEM (Pmode, addr);
11951 /* This should not be of rs6000_sr_alias_set, because of
11952 __builtin_return_address. */
11953
11954 insn = emit_move_insn (mem, reg);
11955 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
11956 reg, gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM));
11957 }
11958
11959 /* Save CR if we use any that must be preserved. */
11960 if (info->cr_save_p)
11961 {
11962 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
11963 GEN_INT (info->cr_save_offset + sp_offset));
11964 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
11965
11966 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
11967
11968 /* If r12 was used to hold the original sp, copy cr into r0 now
11969 that it's free. */
11970 if (REGNO (frame_reg_rtx) == 12)
11971 {
11972 cr_save_rtx = gen_rtx_REG (SImode, 0);
11973 emit_insn (gen_movesi_from_cr (cr_save_rtx));
11974 }
11975 insn = emit_move_insn (mem, cr_save_rtx);
11976
11977 /* Now, there's no way that dwarf2out_frame_debug_expr is going
615158e2
JJ
11978 to understand '(unspec:SI [(reg:CC 68) ...] UNSPEC_MOVESI_FROM_CR)'.
11979 But that's OK. All we have to do is specify that _one_ condition
11980 code register is saved in this stack slot. The thrower's epilogue
a1dc9455
FS
11981 will then restore all the call-saved registers.
11982 We use CR2_REGNO (70) to be compatible with gcc-2.95 on Linux. */
9ebbca7d 11983 rs6000_frame_related (insn, frame_ptr_rtx, info->total_size,
a1dc9455 11984 cr_save_rtx, gen_rtx_REG (SImode, CR2_REGNO));
9ebbca7d
GK
11985 }
11986
11987 /* Update stack and set back pointer unless this is V.4,
11988 for which it was done previously. */
fc4767bb
JJ
11989 if (info->push_p
11990 && !(DEFAULT_ABI == ABI_V4 || current_function_calls_eh_return))
9ebbca7d
GK
11991 rs6000_emit_allocate_stack (info->total_size, FALSE);
11992
11993 /* Set frame pointer, if needed. */
11994 if (frame_pointer_needed)
11995 {
a3170dc6 11996 insn = emit_move_insn (gen_rtx_REG (Pmode, FRAME_POINTER_REGNUM),
9ebbca7d
GK
11997 sp_reg_rtx);
11998 RTX_FRAME_RELATED_P (insn) = 1;
b6c9286a 11999 }
9878760c 12000
1db02437 12001 /* If we are using RS6000_PIC_OFFSET_TABLE_REGNUM, we need to set it up. */
9ebbca7d 12002 if ((TARGET_TOC && TARGET_MINIMAL_TOC && get_pool_size () != 0)
f607bc57 12003 || (DEFAULT_ABI == ABI_V4 && flag_pic == 1
1db02437 12004 && regs_ever_live[RS6000_PIC_OFFSET_TABLE_REGNUM]))
9ebbca7d
GK
12005 {
12006 /* If emit_load_toc_table will use the link register, we need to save
c4501e62 12007 it. We use R12 for this purpose because emit_load_toc_table
9ebbca7d
GK
12008 can use register 0. This allows us to use a plain 'blr' to return
12009 from the procedure more often. */
f1384257
AM
12010 int save_LR_around_toc_setup = (TARGET_ELF
12011 && DEFAULT_ABI != ABI_AIX
12012 && flag_pic
d5fa86ba
GK
12013 && ! info->lr_save_p
12014 && EXIT_BLOCK_PTR->pred != NULL);
9ebbca7d 12015 if (save_LR_around_toc_setup)
c4501e62
JJ
12016 {
12017 rtx lr = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
12018 rs6000_maybe_dead (emit_move_insn (frame_ptr_rtx, lr));
12019 rs6000_emit_load_toc_table (TRUE);
12020 rs6000_maybe_dead (emit_move_insn (lr, frame_ptr_rtx));
12021 }
12022 else
12023 rs6000_emit_load_toc_table (TRUE);
9ebbca7d 12024 }
ee890fe2 12025
fcce224d 12026#if TARGET_MACHO
ee890fe2
SS
12027 if (DEFAULT_ABI == ABI_DARWIN
12028 && flag_pic && current_function_uses_pic_offset_table)
12029 {
12030 rtx dest = gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM);
f099d360 12031 const char *picbase = machopic_function_base_name ();
6788f5ca 12032 rtx src = gen_rtx_SYMBOL_REF (Pmode, picbase);
ee890fe2 12033
f51eee6a 12034 rs6000_maybe_dead (emit_insn (gen_load_macho_picbase (dest, src)));
ee890fe2
SS
12035
12036 rs6000_maybe_dead (
1db02437 12037 emit_move_insn (gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM),
ee890fe2
SS
12038 gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM)));
12039 }
fcce224d 12040#endif
9ebbca7d
GK
12041}
12042
9ebbca7d 12043/* Write function prologue. */
a4f6c312 12044
08c148a8 12045static void
a2369ed3
DJ
12046rs6000_output_function_prologue (FILE *file,
12047 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9ebbca7d
GK
12048{
12049 rs6000_stack_t *info = rs6000_stack_info ();
12050
4697a36c
MM
12051 if (TARGET_DEBUG_STACK)
12052 debug_stack_info (info);
9878760c 12053
a4f6c312
SS
12054 /* Write .extern for any function we will call to save and restore
12055 fp values. */
12056 if (info->first_fp_reg_save < 64
12057 && !FP_SAVE_INLINE (info->first_fp_reg_save))
4d30c363 12058 fprintf (file, "\t.extern %s%d%s\n\t.extern %s%d%s\n",
4697a36c 12059 SAVE_FP_PREFIX, info->first_fp_reg_save - 32, SAVE_FP_SUFFIX,
a4f6c312
SS
12060 RESTORE_FP_PREFIX, info->first_fp_reg_save - 32,
12061 RESTORE_FP_SUFFIX);
9878760c 12062
c764f757
RK
12063 /* Write .extern for AIX common mode routines, if needed. */
12064 if (! TARGET_POWER && ! TARGET_POWERPC && ! common_mode_defined)
12065 {
f6709c70
JW
12066 fputs ("\t.extern __mulh\n", file);
12067 fputs ("\t.extern __mull\n", file);
12068 fputs ("\t.extern __divss\n", file);
12069 fputs ("\t.extern __divus\n", file);
12070 fputs ("\t.extern __quoss\n", file);
12071 fputs ("\t.extern __quous\n", file);
c764f757
RK
12072 common_mode_defined = 1;
12073 }
9878760c 12074
9ebbca7d 12075 if (! HAVE_prologue)
979721f8 12076 {
9ebbca7d 12077 start_sequence ();
9dda4cc8 12078
a4f6c312
SS
12079 /* A NOTE_INSN_DELETED is supposed to be at the start and end of
12080 the "toplevel" insn chain. */
2e040219 12081 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12082 rs6000_emit_prologue ();
2e040219 12083 emit_note (NOTE_INSN_DELETED);
178c3eff 12084
a3c9585f 12085 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12086 {
12087 rtx insn;
12088 unsigned addr = 0;
12089 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12090 {
12091 INSN_ADDRESSES_NEW (insn, addr);
12092 addr += 4;
12093 }
12094 }
9dda4cc8 12095
9ebbca7d 12096 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12097 debug_rtx_list (get_insns (), 100);
12098 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12099 end_sequence ();
979721f8
MM
12100 }
12101
9ebbca7d
GK
12102 rs6000_pic_labelno++;
12103}
12104
12105/* Emit function epilogue as insns.
9878760c 12106
9ebbca7d
GK
12107 At present, dwarf2out_frame_debug_expr doesn't understand
12108 register restores, so we don't bother setting RTX_FRAME_RELATED_P
12109 anywhere in the epilogue. Most of the insns below would in any case
12110 need special notes to explain where r11 is in relation to the stack. */
9878760c 12111
9ebbca7d 12112void
a2369ed3 12113rs6000_emit_epilogue (int sibcall)
9ebbca7d
GK
12114{
12115 rs6000_stack_t *info;
12116 int restoring_FPRs_inline;
12117 int using_load_multiple;
12118 int using_mfcr_multiple;
12119 int use_backchain_to_restore_sp;
12120 int sp_offset = 0;
12121 rtx sp_reg_rtx = gen_rtx_REG (Pmode, 1);
12122 rtx frame_reg_rtx = sp_reg_rtx;
0e67400a
FJ
12123 enum machine_mode reg_mode = Pmode;
12124 int reg_size = UNITS_PER_WORD;
9ebbca7d
GK
12125 int i;
12126
c19de7aa
AH
12127 info = rs6000_stack_info ();
12128
12129 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12130 {
12131 reg_mode = V2SImode;
12132 reg_size = 8;
12133 }
12134
9ebbca7d 12135 using_load_multiple = (TARGET_MULTIPLE && ! TARGET_POWERPC64
c19de7aa
AH
12136 && (!TARGET_SPE_ABI
12137 || info->spe_64bit_regs_used == 0)
9ebbca7d
GK
12138 && info->first_gp_reg_save < 31);
12139 restoring_FPRs_inline = (sibcall
83720594 12140 || current_function_calls_eh_return
9ebbca7d
GK
12141 || info->first_fp_reg_save == 64
12142 || FP_SAVE_INLINE (info->first_fp_reg_save));
12143 use_backchain_to_restore_sp = (frame_pointer_needed
12144 || current_function_calls_alloca
12145 || info->total_size > 32767);
12146 using_mfcr_multiple = (rs6000_cpu == PROCESSOR_PPC601
12147 || rs6000_cpu == PROCESSOR_PPC603
12148 || rs6000_cpu == PROCESSOR_PPC750
12149 || optimize_size);
12150
12151 /* If we have a frame pointer, a call to alloca, or a large stack
12152 frame, restore the old stack pointer using the backchain. Otherwise,
12153 we know what size to update it with. */
12154 if (use_backchain_to_restore_sp)
bacbde18 12155 {
9ebbca7d
GK
12156 /* Under V.4, don't reset the stack pointer until after we're done
12157 loading the saved registers. */
f607bc57 12158 if (DEFAULT_ABI == ABI_V4)
9ebbca7d 12159 frame_reg_rtx = gen_rtx_REG (Pmode, 11);
4697a36c 12160
9ebbca7d
GK
12161 emit_move_insn (frame_reg_rtx,
12162 gen_rtx_MEM (Pmode, sp_reg_rtx));
12163
bacbde18 12164 }
9ebbca7d 12165 else if (info->push_p)
85638c0d 12166 {
fc4767bb
JJ
12167 if (DEFAULT_ABI == ABI_V4
12168 || current_function_calls_eh_return)
9ebbca7d
GK
12169 sp_offset = info->total_size;
12170 else
12171 {
12172 emit_insn (TARGET_32BIT
12173 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12174 GEN_INT (info->total_size))
12175 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12176 GEN_INT (info->total_size)));
12177 }
85638c0d 12178 }
9ebbca7d 12179
9aa86737
AH
12180 /* Restore AltiVec registers if needed. */
12181 if (TARGET_ALTIVEC_ABI && info->altivec_size != 0)
12182 {
12183 int i;
12184
12185 for (i = info->first_altivec_reg_save; i <= LAST_ALTIVEC_REGNO; ++i)
12186 if (info->vrsave_mask & ALTIVEC_REG_BIT (i))
12187 {
12188 rtx addr, areg, mem;
12189
12190 areg = gen_rtx_REG (Pmode, 0);
12191 emit_move_insn
12192 (areg, GEN_INT (info->altivec_save_offset
12193 + sp_offset
12194 + 16 * (i - info->first_altivec_reg_save)));
12195
12196 /* AltiVec addressing mode is [reg+reg]. */
12197 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, areg);
12198 mem = gen_rtx_MEM (V4SImode, addr);
12199 set_mem_alias_set (mem, rs6000_sr_alias_set);
12200
12201 emit_move_insn (gen_rtx_REG (V4SImode, i), mem);
12202 }
12203 }
12204
12205 /* Restore VRSAVE if needed. */
4d774ff8
HP
12206 if (TARGET_ALTIVEC_ABI && TARGET_ALTIVEC_VRSAVE
12207 && info->vrsave_mask != 0)
9aa86737
AH
12208 {
12209 rtx addr, mem, reg;
12210
12211 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12212 GEN_INT (info->vrsave_save_offset + sp_offset));
12213 mem = gen_rtx_MEM (SImode, addr);
12214 set_mem_alias_set (mem, rs6000_sr_alias_set);
12215 reg = gen_rtx_REG (SImode, 12);
12216 emit_move_insn (reg, mem);
12217
12218 emit_insn (generate_set_vrsave (reg, info, 1));
12219 }
12220
9ebbca7d
GK
12221 /* Get the old lr if we saved it. */
12222 if (info->lr_save_p)
b6c9286a 12223 {
a3170dc6
AH
12224 rtx mem = gen_frame_mem_offset (Pmode, frame_reg_rtx,
12225 info->lr_save_offset + sp_offset);
ba4828e0
RK
12226
12227 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12228
9ebbca7d 12229 emit_move_insn (gen_rtx_REG (Pmode, 0), mem);
b6c9286a 12230 }
9ebbca7d
GK
12231
12232 /* Get the old cr if we saved it. */
12233 if (info->cr_save_p)
12234 {
12235 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12236 GEN_INT (info->cr_save_offset + sp_offset));
12237 rtx mem = gen_rtx_MEM (SImode, addr);
ba4828e0
RK
12238
12239 set_mem_alias_set (mem, rs6000_sr_alias_set);
b6c9286a 12240
9ebbca7d
GK
12241 emit_move_insn (gen_rtx_REG (SImode, 12), mem);
12242 }
12243
12244 /* Set LR here to try to overlap restores below. */
4697a36c 12245 if (info->lr_save_p)
9ebbca7d
GK
12246 emit_move_insn (gen_rtx_REG (Pmode, LINK_REGISTER_REGNUM),
12247 gen_rtx_REG (Pmode, 0));
12248
83720594
RH
12249 /* Load exception handler data registers, if needed. */
12250 if (current_function_calls_eh_return)
12251 {
78e1b90d
DE
12252 unsigned int i, regno;
12253
fc4767bb
JJ
12254 if (TARGET_AIX)
12255 {
12256 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12257 GEN_INT (sp_offset + 5 * reg_size));
12258 rtx mem = gen_rtx_MEM (reg_mode, addr);
12259
12260 set_mem_alias_set (mem, rs6000_sr_alias_set);
12261
12262 emit_move_insn (gen_rtx_REG (reg_mode, 2), mem);
12263 }
12264
83720594
RH
12265 for (i = 0; ; ++i)
12266 {
a3170dc6 12267 rtx mem;
83720594
RH
12268
12269 regno = EH_RETURN_DATA_REGNO (i);
12270 if (regno == INVALID_REGNUM)
12271 break;
12272
a3170dc6
AH
12273 mem = gen_frame_mem_offset (reg_mode, frame_reg_rtx,
12274 info->ehrd_offset + sp_offset
12275 + reg_size * (int) i);
ba4828e0 12276 set_mem_alias_set (mem, rs6000_sr_alias_set);
83720594
RH
12277
12278 emit_move_insn (gen_rtx_REG (reg_mode, regno), mem);
12279 }
12280 }
9ebbca7d
GK
12281
12282 /* Restore GPRs. This is done as a PARALLEL if we are using
12283 the load-multiple instructions. */
12284 if (using_load_multiple)
979721f8 12285 {
9ebbca7d
GK
12286 rtvec p;
12287 p = rtvec_alloc (32 - info->first_gp_reg_save);
12288 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
979721f8 12289 {
9ebbca7d
GK
12290 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12291 GEN_INT (info->gp_save_offset
12292 + sp_offset
12293 + reg_size * i));
12294 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0
RK
12295
12296 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12297
12298 RTVEC_ELT (p, i) =
12299 gen_rtx_SET (VOIDmode,
12300 gen_rtx_REG (reg_mode, info->first_gp_reg_save + i),
12301 mem);
979721f8 12302 }
9ebbca7d 12303 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
979721f8 12304 }
9ebbca7d
GK
12305 else
12306 for (i = 0; i < 32 - info->first_gp_reg_save; i++)
12307 if ((regs_ever_live[info->first_gp_reg_save+i]
12308 && ! call_used_regs[info->first_gp_reg_save+i])
1db02437 12309 || (i+info->first_gp_reg_save == RS6000_PIC_OFFSET_TABLE_REGNUM
14f00213 12310 && ((DEFAULT_ABI == ABI_V4 && flag_pic != 0)
f607bc57 12311 || (DEFAULT_ABI == ABI_DARWIN && flag_pic))))
9ebbca7d
GK
12312 {
12313 rtx addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12314 GEN_INT (info->gp_save_offset
12315 + sp_offset
12316 + reg_size * i));
12317 rtx mem = gen_rtx_MEM (reg_mode, addr);
ba4828e0 12318
a3170dc6 12319 /* Restore 64-bit quantities for SPE. */
c19de7aa 12320 if (TARGET_SPE_ABI && info->spe_64bit_regs_used != 0)
a3170dc6
AH
12321 {
12322 int offset = info->spe_gp_save_offset + sp_offset + 8 * i;
12323 rtx b;
12324
12325 if (!SPE_CONST_OFFSET_OK (offset))
12326 {
12327 b = gen_rtx_REG (Pmode, FIXED_SCRATCH);
12328 emit_move_insn (b, GEN_INT (offset));
12329 }
12330 else
12331 b = GEN_INT (offset);
12332
12333 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx, b);
12334 mem = gen_rtx_MEM (V2SImode, addr);
12335 }
12336
ba4828e0 12337 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12338
12339 emit_move_insn (gen_rtx_REG (reg_mode,
a3170dc6 12340 info->first_gp_reg_save + i), mem);
9ebbca7d 12341 }
9878760c 12342
9ebbca7d
GK
12343 /* Restore fpr's if we need to do it without calling a function. */
12344 if (restoring_FPRs_inline)
12345 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12346 if ((regs_ever_live[info->first_fp_reg_save+i]
12347 && ! call_used_regs[info->first_fp_reg_save+i]))
12348 {
12349 rtx addr, mem;
12350 addr = gen_rtx_PLUS (Pmode, frame_reg_rtx,
12351 GEN_INT (info->fp_save_offset
12352 + sp_offset
a4f6c312 12353 + 8 * i));
9ebbca7d 12354 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12355 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12356
12357 emit_move_insn (gen_rtx_REG (DFmode,
12358 info->first_fp_reg_save + i),
12359 mem);
12360 }
8d30c4ee 12361
9ebbca7d
GK
12362 /* If we saved cr, restore it here. Just those that were used. */
12363 if (info->cr_save_p)
979721f8 12364 {
9ebbca7d 12365 rtx r12_rtx = gen_rtx_REG (SImode, 12);
e35b9579 12366 int count = 0;
9ebbca7d
GK
12367
12368 if (using_mfcr_multiple)
979721f8 12369 {
9ebbca7d
GK
12370 for (i = 0; i < 8; i++)
12371 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
e35b9579 12372 count++;
9ebbca7d 12373 if (count == 0)
e35b9579
GK
12374 abort ();
12375 }
12376
12377 if (using_mfcr_multiple && count > 1)
12378 {
12379 rtvec p;
12380 int ndx;
9ebbca7d 12381
e35b9579 12382 p = rtvec_alloc (count);
9ebbca7d 12383
e35b9579 12384 ndx = 0;
9ebbca7d
GK
12385 for (i = 0; i < 8; i++)
12386 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
12387 {
12388 rtvec r = rtvec_alloc (2);
12389 RTVEC_ELT (r, 0) = r12_rtx;
12390 RTVEC_ELT (r, 1) = GEN_INT (1 << (7-i));
e35b9579 12391 RTVEC_ELT (p, ndx) =
9ebbca7d 12392 gen_rtx_SET (VOIDmode, gen_rtx_REG (CCmode, CR0_REGNO+i),
615158e2 12393 gen_rtx_UNSPEC (CCmode, r, UNSPEC_MOVESI_TO_CR));
e35b9579 12394 ndx++;
9ebbca7d
GK
12395 }
12396 emit_insn (gen_rtx_PARALLEL (VOIDmode, p));
e35b9579
GK
12397 if (ndx != count)
12398 abort ();
979721f8
MM
12399 }
12400 else
9ebbca7d
GK
12401 for (i = 0; i < 8; i++)
12402 if (regs_ever_live[CR0_REGNO+i] && ! call_used_regs[CR0_REGNO+i])
979721f8 12403 {
9ebbca7d
GK
12404 emit_insn (gen_movsi_to_cr_one (gen_rtx_REG (CCmode,
12405 CR0_REGNO+i),
12406 r12_rtx));
979721f8 12407 }
979721f8
MM
12408 }
12409
9ebbca7d
GK
12410 /* If this is V.4, unwind the stack pointer after all of the loads
12411 have been done. We need to emit a block here so that sched
12412 doesn't decide to move the sp change before the register restores
12413 (which may not have any obvious dependency on the stack). This
12414 doesn't hurt performance, because there is no scheduling that can
12415 be done after this point. */
fc4767bb
JJ
12416 if (DEFAULT_ABI == ABI_V4
12417 || current_function_calls_eh_return)
b6c9286a 12418 {
9ebbca7d
GK
12419 if (frame_reg_rtx != sp_reg_rtx)
12420 rs6000_emit_stack_tie ();
b6c9286a 12421
9ebbca7d 12422 if (use_backchain_to_restore_sp)
b6c9286a 12423 {
9ebbca7d 12424 emit_move_insn (sp_reg_rtx, frame_reg_rtx);
b6c9286a 12425 }
9ebbca7d 12426 else if (sp_offset != 0)
13f1623b 12427 {
5b71a4e7 12428 emit_insn (TARGET_32BIT
9ebbca7d
GK
12429 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx,
12430 GEN_INT (sp_offset))
12431 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx,
12432 GEN_INT (sp_offset)));
13f1623b 12433 }
9ebbca7d 12434 }
b6c9286a 12435
83720594
RH
12436 if (current_function_calls_eh_return)
12437 {
12438 rtx sa = EH_RETURN_STACKADJ_RTX;
5b71a4e7 12439 emit_insn (TARGET_32BIT
83720594
RH
12440 ? gen_addsi3 (sp_reg_rtx, sp_reg_rtx, sa)
12441 : gen_adddi3 (sp_reg_rtx, sp_reg_rtx, sa));
12442 }
12443
9ebbca7d
GK
12444 if (!sibcall)
12445 {
12446 rtvec p;
12447 if (! restoring_FPRs_inline)
12448 p = rtvec_alloc (3 + 64 - info->first_fp_reg_save);
12449 else
12450 p = rtvec_alloc (2);
b6c9286a 12451
e35b9579
GK
12452 RTVEC_ELT (p, 0) = gen_rtx_RETURN (VOIDmode);
12453 RTVEC_ELT (p, 1) = gen_rtx_USE (VOIDmode,
9ebbca7d
GK
12454 gen_rtx_REG (Pmode,
12455 LINK_REGISTER_REGNUM));
9ebbca7d
GK
12456
12457 /* If we have to restore more than two FP registers, branch to the
12458 restore function. It will return to our caller. */
12459 if (! restoring_FPRs_inline)
12460 {
12461 int i;
12462 char rname[30];
520a57c8 12463 const char *alloc_rname;
979721f8 12464
9ebbca7d
GK
12465 sprintf (rname, "%s%d%s", RESTORE_FP_PREFIX,
12466 info->first_fp_reg_save - 32, RESTORE_FP_SUFFIX);
a8a05998 12467 alloc_rname = ggc_strdup (rname);
9ebbca7d
GK
12468 RTVEC_ELT (p, 2) = gen_rtx_USE (VOIDmode,
12469 gen_rtx_SYMBOL_REF (Pmode,
12470 alloc_rname));
b6c9286a 12471
9ebbca7d
GK
12472 for (i = 0; i < 64 - info->first_fp_reg_save; i++)
12473 {
12474 rtx addr, mem;
12475 addr = gen_rtx_PLUS (Pmode, sp_reg_rtx,
12476 GEN_INT (info->fp_save_offset + 8*i));
12477 mem = gen_rtx_MEM (DFmode, addr);
ba4828e0 12478 set_mem_alias_set (mem, rs6000_sr_alias_set);
9ebbca7d
GK
12479
12480 RTVEC_ELT (p, i+3) =
12481 gen_rtx_SET (VOIDmode,
12482 gen_rtx_REG (DFmode, info->first_fp_reg_save + i),
12483 mem);
b6c9286a
MM
12484 }
12485 }
9ebbca7d
GK
12486
12487 emit_jump_insn (gen_rtx_PARALLEL (VOIDmode, p));
3daf36a4 12488 }
9878760c
RK
12489}
12490
12491/* Write function epilogue. */
12492
08c148a8 12493static void
a2369ed3
DJ
12494rs6000_output_function_epilogue (FILE *file,
12495 HOST_WIDE_INT size ATTRIBUTE_UNUSED)
9878760c 12496{
4697a36c 12497 rs6000_stack_t *info = rs6000_stack_info ();
9878760c 12498
9ebbca7d 12499 if (! HAVE_epilogue)
9878760c 12500 {
9ebbca7d
GK
12501 rtx insn = get_last_insn ();
12502 /* If the last insn was a BARRIER, we don't have to write anything except
12503 the trace table. */
12504 if (GET_CODE (insn) == NOTE)
12505 insn = prev_nonnote_insn (insn);
12506 if (insn == 0 || GET_CODE (insn) != BARRIER)
4697a36c 12507 {
9ebbca7d
GK
12508 /* This is slightly ugly, but at least we don't have two
12509 copies of the epilogue-emitting code. */
12510 start_sequence ();
12511
12512 /* A NOTE_INSN_DELETED is supposed to be at the start
12513 and end of the "toplevel" insn chain. */
2e040219 12514 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12515 rs6000_emit_epilogue (FALSE);
2e040219 12516 emit_note (NOTE_INSN_DELETED);
9ebbca7d 12517
a3c9585f 12518 /* Expand INSN_ADDRESSES so final() doesn't crash. */
178c3eff
DJ
12519 {
12520 rtx insn;
12521 unsigned addr = 0;
12522 for (insn = get_insns (); insn != 0; insn = NEXT_INSN (insn))
12523 {
12524 INSN_ADDRESSES_NEW (insn, addr);
12525 addr += 4;
12526 }
12527 }
12528
9ebbca7d 12529 if (TARGET_DEBUG_STACK)
a4f6c312
SS
12530 debug_rtx_list (get_insns (), 100);
12531 final (get_insns (), file, FALSE, FALSE);
9ebbca7d 12532 end_sequence ();
4697a36c 12533 }
9878760c 12534 }
b4ac57ab 12535
efdba735
SH
12536#if TARGET_MACHO
12537 macho_branch_islands ();
0e5da0be
GK
12538 /* Mach-O doesn't support labels at the end of objects, so if
12539 it looks like we might want one, insert a NOP. */
12540 {
12541 rtx insn = get_last_insn ();
12542 while (insn
12543 && NOTE_P (insn)
12544 && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED_LABEL)
12545 insn = PREV_INSN (insn);
12546 if (insn
12547 && (LABEL_P (insn)
12548 || (NOTE_P (insn)
12549 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
12550 fputs ("\tnop\n", file);
12551 }
12552#endif
12553
9b30bae2 12554 /* Output a traceback table here. See /usr/include/sys/debug.h for info
314fc5a9
ILT
12555 on its format.
12556
12557 We don't output a traceback table if -finhibit-size-directive was
12558 used. The documentation for -finhibit-size-directive reads
12559 ``don't output a @code{.size} assembler directive, or anything
12560 else that would cause trouble if the function is split in the
12561 middle, and the two halves are placed at locations far apart in
12562 memory.'' The traceback table has this property, since it
12563 includes the offset from the start of the function to the
4d30c363
MM
12564 traceback table itself.
12565
12566 System V.4 Powerpc's (and the embedded ABI derived from it) use a
b6c9286a 12567 different traceback table. */
57ac7be9
AM
12568 if (DEFAULT_ABI == ABI_AIX && ! flag_inhibit_size_directive
12569 && rs6000_traceback != traceback_none)
9b30bae2 12570 {
69c75916 12571 const char *fname = NULL;
3ac88239 12572 const char *language_string = lang_hooks.name;
6041bf2f 12573 int fixed_parms = 0, float_parms = 0, parm_info = 0;
314fc5a9 12574 int i;
57ac7be9
AM
12575 int optional_tbtab;
12576
12577 if (rs6000_traceback == traceback_full)
12578 optional_tbtab = 1;
12579 else if (rs6000_traceback == traceback_part)
12580 optional_tbtab = 0;
12581 else
12582 optional_tbtab = !optimize_size && !TARGET_ELF;
314fc5a9 12583
69c75916
AM
12584 if (optional_tbtab)
12585 {
12586 fname = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
12587 while (*fname == '.') /* V.4 encodes . in the name */
12588 fname++;
12589
12590 /* Need label immediately before tbtab, so we can compute
12591 its offset from the function start. */
12592 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
12593 ASM_OUTPUT_LABEL (file, fname);
12594 }
314fc5a9
ILT
12595
12596 /* The .tbtab pseudo-op can only be used for the first eight
12597 expressions, since it can't handle the possibly variable
12598 length fields that follow. However, if you omit the optional
12599 fields, the assembler outputs zeros for all optional fields
12600 anyways, giving each variable length field is minimum length
12601 (as defined in sys/debug.h). Thus we can not use the .tbtab
12602 pseudo-op at all. */
12603
12604 /* An all-zero word flags the start of the tbtab, for debuggers
12605 that have to find it by searching forward from the entry
12606 point or from the current pc. */
19d2d16f 12607 fputs ("\t.long 0\n", file);
314fc5a9
ILT
12608
12609 /* Tbtab format type. Use format type 0. */
19d2d16f 12610 fputs ("\t.byte 0,", file);
314fc5a9 12611
5fc921c1
DE
12612 /* Language type. Unfortunately, there does not seem to be any
12613 official way to discover the language being compiled, so we
12614 use language_string.
12615 C is 0. Fortran is 1. Pascal is 2. Ada is 3. C++ is 9.
12616 Java is 13. Objective-C is 14. */
12617 if (! strcmp (language_string, "GNU C"))
314fc5a9
ILT
12618 i = 0;
12619 else if (! strcmp (language_string, "GNU F77"))
12620 i = 1;
8b83775b 12621 else if (! strcmp (language_string, "GNU Pascal"))
314fc5a9 12622 i = 2;
5fc921c1
DE
12623 else if (! strcmp (language_string, "GNU Ada"))
12624 i = 3;
314fc5a9
ILT
12625 else if (! strcmp (language_string, "GNU C++"))
12626 i = 9;
9517ead8
AG
12627 else if (! strcmp (language_string, "GNU Java"))
12628 i = 13;
5fc921c1
DE
12629 else if (! strcmp (language_string, "GNU Objective-C"))
12630 i = 14;
314fc5a9
ILT
12631 else
12632 abort ();
12633 fprintf (file, "%d,", i);
12634
12635 /* 8 single bit fields: global linkage (not set for C extern linkage,
12636 apparently a PL/I convention?), out-of-line epilogue/prologue, offset
12637 from start of procedure stored in tbtab, internal function, function
12638 has controlled storage, function has no toc, function uses fp,
12639 function logs/aborts fp operations. */
12640 /* Assume that fp operations are used if any fp reg must be saved. */
6041bf2f
DE
12641 fprintf (file, "%d,",
12642 (optional_tbtab << 5) | ((info->first_fp_reg_save != 64) << 1));
314fc5a9
ILT
12643
12644 /* 6 bitfields: function is interrupt handler, name present in
12645 proc table, function calls alloca, on condition directives
12646 (controls stack walks, 3 bits), saves condition reg, saves
12647 link reg. */
12648 /* The `function calls alloca' bit seems to be set whenever reg 31 is
12649 set up as a frame pointer, even when there is no alloca call. */
12650 fprintf (file, "%d,",
6041bf2f
DE
12651 ((optional_tbtab << 6)
12652 | ((optional_tbtab & frame_pointer_needed) << 5)
12653 | (info->cr_save_p << 1)
12654 | (info->lr_save_p)));
314fc5a9 12655
6041bf2f 12656 /* 3 bitfields: saves backchain, fixup code, number of fpr saved
314fc5a9
ILT
12657 (6 bits). */
12658 fprintf (file, "%d,",
4697a36c 12659 (info->push_p << 7) | (64 - info->first_fp_reg_save));
314fc5a9
ILT
12660
12661 /* 2 bitfields: spare bits (2 bits), number of gpr saved (6 bits). */
12662 fprintf (file, "%d,", (32 - first_reg_to_save ()));
12663
6041bf2f
DE
12664 if (optional_tbtab)
12665 {
12666 /* Compute the parameter info from the function decl argument
12667 list. */
12668 tree decl;
12669 int next_parm_info_bit = 31;
314fc5a9 12670
6041bf2f
DE
12671 for (decl = DECL_ARGUMENTS (current_function_decl);
12672 decl; decl = TREE_CHAIN (decl))
12673 {
12674 rtx parameter = DECL_INCOMING_RTL (decl);
12675 enum machine_mode mode = GET_MODE (parameter);
314fc5a9 12676
6041bf2f
DE
12677 if (GET_CODE (parameter) == REG)
12678 {
12679 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
12680 {
12681 int bits;
12682
12683 float_parms++;
12684
12685 if (mode == SFmode)
12686 bits = 0x2;
fcce224d 12687 else if (mode == DFmode || mode == TFmode)
6041bf2f
DE
12688 bits = 0x3;
12689 else
12690 abort ();
12691
12692 /* If only one bit will fit, don't or in this entry. */
12693 if (next_parm_info_bit > 0)
12694 parm_info |= (bits << (next_parm_info_bit - 1));
12695 next_parm_info_bit -= 2;
12696 }
12697 else
12698 {
12699 fixed_parms += ((GET_MODE_SIZE (mode)
12700 + (UNITS_PER_WORD - 1))
12701 / UNITS_PER_WORD);
12702 next_parm_info_bit -= 1;
12703 }
12704 }
12705 }
12706 }
314fc5a9
ILT
12707
12708 /* Number of fixed point parameters. */
12709 /* This is actually the number of words of fixed point parameters; thus
12710 an 8 byte struct counts as 2; and thus the maximum value is 8. */
12711 fprintf (file, "%d,", fixed_parms);
12712
12713 /* 2 bitfields: number of floating point parameters (7 bits), parameters
12714 all on stack. */
12715 /* This is actually the number of fp registers that hold parameters;
12716 and thus the maximum value is 13. */
12717 /* Set parameters on stack bit if parameters are not in their original
12718 registers, regardless of whether they are on the stack? Xlc
12719 seems to set the bit when not optimizing. */
12720 fprintf (file, "%d\n", ((float_parms << 1) | (! optimize)));
12721
6041bf2f
DE
12722 if (! optional_tbtab)
12723 return;
12724
314fc5a9
ILT
12725 /* Optional fields follow. Some are variable length. */
12726
12727 /* Parameter types, left adjusted bit fields: 0 fixed, 10 single float,
12728 11 double float. */
12729 /* There is an entry for each parameter in a register, in the order that
12730 they occur in the parameter list. Any intervening arguments on the
12731 stack are ignored. If the list overflows a long (max possible length
12732 34 bits) then completely leave off all elements that don't fit. */
12733 /* Only emit this long if there was at least one parameter. */
12734 if (fixed_parms || float_parms)
12735 fprintf (file, "\t.long %d\n", parm_info);
12736
12737 /* Offset from start of code to tb table. */
19d2d16f 12738 fputs ("\t.long ", file);
314fc5a9 12739 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LT");
54ee9799
DE
12740#if TARGET_AIX
12741 RS6000_OUTPUT_BASENAME (file, fname);
12742#else
9ebbca7d 12743 assemble_name (file, fname);
54ee9799 12744#endif
19d2d16f 12745 fputs ("-.", file);
54ee9799
DE
12746#if TARGET_AIX
12747 RS6000_OUTPUT_BASENAME (file, fname);
12748#else
9ebbca7d 12749 assemble_name (file, fname);
54ee9799 12750#endif
19d2d16f 12751 putc ('\n', file);
314fc5a9
ILT
12752
12753 /* Interrupt handler mask. */
12754 /* Omit this long, since we never set the interrupt handler bit
12755 above. */
12756
12757 /* Number of CTL (controlled storage) anchors. */
12758 /* Omit this long, since the has_ctl bit is never set above. */
12759
12760 /* Displacement into stack of each CTL anchor. */
12761 /* Omit this list of longs, because there are no CTL anchors. */
12762
12763 /* Length of function name. */
69c75916
AM
12764 if (*fname == '*')
12765 ++fname;
296b8152 12766 fprintf (file, "\t.short %d\n", (int) strlen (fname));
314fc5a9
ILT
12767
12768 /* Function name. */
12769 assemble_string (fname, strlen (fname));
12770
12771 /* Register for alloca automatic storage; this is always reg 31.
12772 Only emit this if the alloca bit was set above. */
12773 if (frame_pointer_needed)
19d2d16f 12774 fputs ("\t.byte 31\n", file);
b1765bde
DE
12775
12776 fputs ("\t.align 2\n", file);
9b30bae2 12777 }
9878760c 12778}
17167fd8 12779\f
a4f6c312
SS
12780/* A C compound statement that outputs the assembler code for a thunk
12781 function, used to implement C++ virtual function calls with
12782 multiple inheritance. The thunk acts as a wrapper around a virtual
12783 function, adjusting the implicit object parameter before handing
12784 control off to the real function.
12785
12786 First, emit code to add the integer DELTA to the location that
12787 contains the incoming first argument. Assume that this argument
12788 contains a pointer, and is the one used to pass the `this' pointer
12789 in C++. This is the incoming argument *before* the function
12790 prologue, e.g. `%o0' on a sparc. The addition must preserve the
12791 values of all other incoming arguments.
17167fd8
MM
12792
12793 After the addition, emit code to jump to FUNCTION, which is a
a4f6c312
SS
12794 `FUNCTION_DECL'. This is a direct pure jump, not a call, and does
12795 not touch the return address. Hence returning from FUNCTION will
12796 return to whoever called the current `thunk'.
17167fd8 12797
a4f6c312
SS
12798 The effect must be as if FUNCTION had been called directly with the
12799 adjusted first argument. This macro is responsible for emitting
12800 all of the code for a thunk function; output_function_prologue()
12801 and output_function_epilogue() are not invoked.
17167fd8 12802
a4f6c312
SS
12803 The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already
12804 been extracted from it.) It might possibly be useful on some
12805 targets, but probably not.
17167fd8 12806
a4f6c312
SS
12807 If you do not define this macro, the target-independent code in the
12808 C++ frontend will generate a less efficient heavyweight thunk that
12809 calls FUNCTION instead of jumping to it. The generic approach does
12810 not support varargs. */
17167fd8 12811
3961e8fe 12812static void
a2369ed3
DJ
12813rs6000_output_mi_thunk (FILE *file, tree thunk_fndecl ATTRIBUTE_UNUSED,
12814 HOST_WIDE_INT delta, HOST_WIDE_INT vcall_offset,
12815 tree function)
17167fd8 12816{
5b71a4e7 12817 rtx this, insn, funexp;
17167fd8 12818
5b71a4e7 12819 reload_completed = 1;
fe3ad572 12820 epilogue_completed = 1;
5b71a4e7 12821 no_new_pseudos = 1;
56a7189a 12822
5b71a4e7 12823 /* Mark the end of the (empty) prologue. */
2e040219 12824 emit_note (NOTE_INSN_PROLOGUE_END);
17167fd8 12825
5b71a4e7
DE
12826 /* Find the "this" pointer. If the function returns a structure,
12827 the structure return pointer is in r3. */
61f71b34 12828 if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function)), function))
5b71a4e7 12829 this = gen_rtx_REG (Pmode, 4);
56a7189a 12830 else
5b71a4e7 12831 this = gen_rtx_REG (Pmode, 3);
17167fd8 12832
5b71a4e7
DE
12833 /* Apply the constant offset, if required. */
12834 if (delta)
12835 {
12836 rtx delta_rtx = GEN_INT (delta);
12837 emit_insn (TARGET_32BIT
12838 ? gen_addsi3 (this, this, delta_rtx)
12839 : gen_adddi3 (this, this, delta_rtx));
17167fd8
MM
12840 }
12841
5b71a4e7
DE
12842 /* Apply the offset from the vtable, if required. */
12843 if (vcall_offset)
17167fd8 12844 {
5b71a4e7
DE
12845 rtx vcall_offset_rtx = GEN_INT (vcall_offset);
12846 rtx tmp = gen_rtx_REG (Pmode, 12);
17167fd8 12847
5b71a4e7 12848 emit_move_insn (tmp, gen_rtx_MEM (Pmode, this));
eeff9307
JJ
12849 if (((unsigned HOST_WIDE_INT) vcall_offset) + 0x8000 >= 0x10000)
12850 {
12851 emit_insn (TARGET_32BIT
12852 ? gen_addsi3 (tmp, tmp, vcall_offset_rtx)
12853 : gen_adddi3 (tmp, tmp, vcall_offset_rtx));
12854 emit_move_insn (tmp, gen_rtx_MEM (Pmode, tmp));
12855 }
12856 else
12857 {
12858 rtx loc = gen_rtx_PLUS (Pmode, tmp, vcall_offset_rtx);
12859
12860 emit_move_insn (tmp, gen_rtx_MEM (Pmode, loc));
12861 }
5b71a4e7
DE
12862 emit_insn (TARGET_32BIT
12863 ? gen_addsi3 (this, this, tmp)
12864 : gen_adddi3 (this, this, tmp));
17167fd8
MM
12865 }
12866
5b71a4e7
DE
12867 /* Generate a tail call to the target function. */
12868 if (!TREE_USED (function))
12869 {
12870 assemble_external (function);
12871 TREE_USED (function) = 1;
12872 }
12873 funexp = XEXP (DECL_RTL (function), 0);
5b71a4e7 12874 funexp = gen_rtx_MEM (FUNCTION_MODE, funexp);
ee890fe2
SS
12875
12876#if TARGET_MACHO
ab82a49f 12877 if (MACHOPIC_INDIRECT)
5b71a4e7 12878 funexp = machopic_indirect_call_target (funexp);
ee890fe2 12879#endif
5b71a4e7
DE
12880
12881 /* gen_sibcall expects reload to convert scratch pseudo to LR so we must
12882 generate sibcall RTL explicitly to avoid constraint abort. */
12883 insn = emit_call_insn (
12884 gen_rtx_PARALLEL (VOIDmode,
12885 gen_rtvec (4,
12886 gen_rtx_CALL (VOIDmode,
12887 funexp, const0_rtx),
12888 gen_rtx_USE (VOIDmode, const0_rtx),
12889 gen_rtx_USE (VOIDmode,
12890 gen_rtx_REG (SImode,
12891 LINK_REGISTER_REGNUM)),
12892 gen_rtx_RETURN (VOIDmode))));
12893 SIBLING_CALL_P (insn) = 1;
12894 emit_barrier ();
12895
12896 /* Run just enough of rest_of_compilation to get the insns emitted.
12897 There's not really enough bulk here to make other passes such as
12898 instruction scheduling worth while. Note that use_thunk calls
12899 assemble_start_function and assemble_end_function. */
12900 insn = get_insns ();
a2855205 12901 insn_locators_initialize ();
5b71a4e7
DE
12902 shorten_branches (insn);
12903 final_start_function (insn, file, 1);
12904 final (insn, file, 1, 0);
12905 final_end_function ();
12906
12907 reload_completed = 0;
fe3ad572 12908 epilogue_completed = 0;
5b71a4e7 12909 no_new_pseudos = 0;
9ebbca7d 12910}
9ebbca7d
GK
12911\f
12912/* A quick summary of the various types of 'constant-pool tables'
12913 under PowerPC:
12914
12915 Target Flags Name One table per
12916 AIX (none) AIX TOC object file
12917 AIX -mfull-toc AIX TOC object file
12918 AIX -mminimal-toc AIX minimal TOC translation unit
12919 SVR4/EABI (none) SVR4 SDATA object file
12920 SVR4/EABI -fpic SVR4 pic object file
12921 SVR4/EABI -fPIC SVR4 PIC translation unit
12922 SVR4/EABI -mrelocatable EABI TOC function
12923 SVR4/EABI -maix AIX TOC object file
12924 SVR4/EABI -maix -mminimal-toc
12925 AIX minimal TOC translation unit
12926
12927 Name Reg. Set by entries contains:
12928 made by addrs? fp? sum?
12929
12930 AIX TOC 2 crt0 as Y option option
12931 AIX minimal TOC 30 prolog gcc Y Y option
12932 SVR4 SDATA 13 crt0 gcc N Y N
12933 SVR4 pic 30 prolog ld Y not yet N
12934 SVR4 PIC 30 prolog gcc Y option option
12935 EABI TOC 30 prolog gcc Y option option
12936
12937*/
12938
9ebbca7d
GK
12939/* Hash functions for the hash table. */
12940
12941static unsigned
a2369ed3 12942rs6000_hash_constant (rtx k)
9ebbca7d 12943{
46b33600
RH
12944 enum rtx_code code = GET_CODE (k);
12945 enum machine_mode mode = GET_MODE (k);
12946 unsigned result = (code << 3) ^ mode;
12947 const char *format;
12948 int flen, fidx;
9ebbca7d 12949
46b33600
RH
12950 format = GET_RTX_FORMAT (code);
12951 flen = strlen (format);
12952 fidx = 0;
9ebbca7d 12953
46b33600
RH
12954 switch (code)
12955 {
12956 case LABEL_REF:
12957 return result * 1231 + (unsigned) INSN_UID (XEXP (k, 0));
12958
12959 case CONST_DOUBLE:
12960 if (mode != VOIDmode)
12961 return real_hash (CONST_DOUBLE_REAL_VALUE (k)) * result;
12962 flen = 2;
12963 break;
12964
12965 case CODE_LABEL:
12966 fidx = 3;
12967 break;
12968
12969 default:
12970 break;
12971 }
9ebbca7d
GK
12972
12973 for (; fidx < flen; fidx++)
12974 switch (format[fidx])
12975 {
12976 case 's':
12977 {
12978 unsigned i, len;
12979 const char *str = XSTR (k, fidx);
12980 len = strlen (str);
12981 result = result * 613 + len;
12982 for (i = 0; i < len; i++)
12983 result = result * 613 + (unsigned) str[i];
17167fd8
MM
12984 break;
12985 }
9ebbca7d
GK
12986 case 'u':
12987 case 'e':
12988 result = result * 1231 + rs6000_hash_constant (XEXP (k, fidx));
12989 break;
12990 case 'i':
12991 case 'n':
12992 result = result * 613 + (unsigned) XINT (k, fidx);
12993 break;
12994 case 'w':
12995 if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT))
12996 result = result * 613 + (unsigned) XWINT (k, fidx);
12997 else
12998 {
12999 size_t i;
13000 for (i = 0; i < sizeof(HOST_WIDE_INT)/sizeof(unsigned); i++)
13001 result = result * 613 + (unsigned) (XWINT (k, fidx)
13002 >> CHAR_BIT * i);
13003 }
13004 break;
09501938
DE
13005 case '0':
13006 break;
9ebbca7d 13007 default:
a4f6c312 13008 abort ();
9ebbca7d 13009 }
46b33600 13010
9ebbca7d
GK
13011 return result;
13012}
13013
13014static unsigned
a2369ed3 13015toc_hash_function (const void *hash_entry)
9ebbca7d 13016{
a9098fd0
GK
13017 const struct toc_hash_struct *thc =
13018 (const struct toc_hash_struct *) hash_entry;
13019 return rs6000_hash_constant (thc->key) ^ thc->key_mode;
9ebbca7d
GK
13020}
13021
13022/* Compare H1 and H2 for equivalence. */
13023
13024static int
a2369ed3 13025toc_hash_eq (const void *h1, const void *h2)
9ebbca7d
GK
13026{
13027 rtx r1 = ((const struct toc_hash_struct *) h1)->key;
13028 rtx r2 = ((const struct toc_hash_struct *) h2)->key;
13029
a9098fd0
GK
13030 if (((const struct toc_hash_struct *) h1)->key_mode
13031 != ((const struct toc_hash_struct *) h2)->key_mode)
13032 return 0;
13033
5692c7bc 13034 return rtx_equal_p (r1, r2);
9ebbca7d
GK
13035}
13036
28e510bd
MM
13037/* These are the names given by the C++ front-end to vtables, and
13038 vtable-like objects. Ideally, this logic should not be here;
13039 instead, there should be some programmatic way of inquiring as
13040 to whether or not an object is a vtable. */
13041
13042#define VTABLE_NAME_P(NAME) \
13043 (strncmp ("_vt.", name, strlen("_vt.")) == 0 \
13044 || strncmp ("_ZTV", name, strlen ("_ZTV")) == 0 \
13045 || strncmp ("_ZTT", name, strlen ("_ZTT")) == 0 \
13046 || strncmp ("_ZTC", name, strlen ("_ZTC")) == 0)
13047
13048void
a2369ed3 13049rs6000_output_symbol_ref (FILE *file, rtx x)
28e510bd
MM
13050{
13051 /* Currently C++ toc references to vtables can be emitted before it
13052 is decided whether the vtable is public or private. If this is
13053 the case, then the linker will eventually complain that there is
13054 a reference to an unknown section. Thus, for vtables only,
13055 we emit the TOC reference to reference the symbol and not the
13056 section. */
13057 const char *name = XSTR (x, 0);
54ee9799
DE
13058
13059 if (VTABLE_NAME_P (name))
13060 {
13061 RS6000_OUTPUT_BASENAME (file, name);
13062 }
13063 else
13064 assemble_name (file, name);
28e510bd
MM
13065}
13066
a4f6c312
SS
13067/* Output a TOC entry. We derive the entry name from what is being
13068 written. */
9878760c
RK
13069
13070void
a2369ed3 13071output_toc (FILE *file, rtx x, int labelno, enum machine_mode mode)
9878760c
RK
13072{
13073 char buf[256];
3cce094d 13074 const char *name = buf;
ec940faa 13075 const char *real_name;
9878760c
RK
13076 rtx base = x;
13077 int offset = 0;
13078
4697a36c
MM
13079 if (TARGET_NO_TOC)
13080 abort ();
13081
9ebbca7d
GK
13082 /* When the linker won't eliminate them, don't output duplicate
13083 TOC entries (this happens on AIX if there is any kind of TOC,
17211ab5
GK
13084 and on SVR4 under -fPIC or -mrelocatable). Don't do this for
13085 CODE_LABELs. */
13086 if (TARGET_TOC && GET_CODE (x) != LABEL_REF)
9ebbca7d
GK
13087 {
13088 struct toc_hash_struct *h;
13089 void * * found;
13090
17211ab5 13091 /* Create toc_hash_table. This can't be done at OVERRIDE_OPTIONS
39e3f58c 13092 time because GGC is not initialized at that point. */
17211ab5
GK
13093 if (toc_hash_table == NULL)
13094 toc_hash_table = htab_create_ggc (1021, toc_hash_function,
13095 toc_hash_eq, NULL);
13096
9ebbca7d
GK
13097 h = ggc_alloc (sizeof (*h));
13098 h->key = x;
a9098fd0 13099 h->key_mode = mode;
9ebbca7d
GK
13100 h->labelno = labelno;
13101
13102 found = htab_find_slot (toc_hash_table, h, 1);
13103 if (*found == NULL)
13104 *found = h;
13105 else /* This is indeed a duplicate.
13106 Set this label equal to that label. */
13107 {
13108 fputs ("\t.set ", file);
13109 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13110 fprintf (file, "%d,", labelno);
13111 ASM_OUTPUT_INTERNAL_LABEL_PREFIX (file, "LC");
13112 fprintf (file, "%d\n", ((*(const struct toc_hash_struct **)
13113 found)->labelno));
13114 return;
13115 }
13116 }
13117
13118 /* If we're going to put a double constant in the TOC, make sure it's
13119 aligned properly when strict alignment is on. */
ff1720ed
RK
13120 if (GET_CODE (x) == CONST_DOUBLE
13121 && STRICT_ALIGNMENT
a9098fd0 13122 && GET_MODE_BITSIZE (mode) >= 64
ff1720ed
RK
13123 && ! (TARGET_NO_FP_IN_TOC && ! TARGET_MINIMAL_TOC)) {
13124 ASM_OUTPUT_ALIGN (file, 3);
13125 }
13126
4977bab6 13127 (*targetm.asm_out.internal_label) (file, "LC", labelno);
9878760c 13128
37c37a57
RK
13129 /* Handle FP constants specially. Note that if we have a minimal
13130 TOC, things we put here aren't actually in the TOC, so we can allow
13131 FP constants. */
fcce224d
DE
13132 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == TFmode)
13133 {
13134 REAL_VALUE_TYPE rv;
13135 long k[4];
13136
13137 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13138 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
13139
13140 if (TARGET_64BIT)
13141 {
13142 if (TARGET_MINIMAL_TOC)
13143 fputs (DOUBLE_INT_ASM_OP, file);
13144 else
13145 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13146 k[0] & 0xffffffff, k[1] & 0xffffffff,
13147 k[2] & 0xffffffff, k[3] & 0xffffffff);
13148 fprintf (file, "0x%lx%08lx,0x%lx%08lx\n",
13149 k[0] & 0xffffffff, k[1] & 0xffffffff,
13150 k[2] & 0xffffffff, k[3] & 0xffffffff);
13151 return;
13152 }
13153 else
13154 {
13155 if (TARGET_MINIMAL_TOC)
13156 fputs ("\t.long ", file);
13157 else
13158 fprintf (file, "\t.tc FT_%lx_%lx_%lx_%lx[TC],",
13159 k[0] & 0xffffffff, k[1] & 0xffffffff,
13160 k[2] & 0xffffffff, k[3] & 0xffffffff);
13161 fprintf (file, "0x%lx,0x%lx,0x%lx,0x%lx\n",
13162 k[0] & 0xffffffff, k[1] & 0xffffffff,
13163 k[2] & 0xffffffff, k[3] & 0xffffffff);
13164 return;
13165 }
13166 }
13167 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
9878760c 13168 {
042259f2
DE
13169 REAL_VALUE_TYPE rv;
13170 long k[2];
0adc764e 13171
042259f2
DE
13172 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13173 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
31bfaa0b 13174
13ded975
DE
13175 if (TARGET_64BIT)
13176 {
13177 if (TARGET_MINIMAL_TOC)
2bfcf297 13178 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13179 else
2f0552b6
AM
13180 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13181 k[0] & 0xffffffff, k[1] & 0xffffffff);
13182 fprintf (file, "0x%lx%08lx\n",
13183 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13184 return;
13185 }
1875cc88 13186 else
13ded975
DE
13187 {
13188 if (TARGET_MINIMAL_TOC)
2bfcf297 13189 fputs ("\t.long ", file);
13ded975 13190 else
2f0552b6
AM
13191 fprintf (file, "\t.tc FD_%lx_%lx[TC],",
13192 k[0] & 0xffffffff, k[1] & 0xffffffff);
13193 fprintf (file, "0x%lx,0x%lx\n",
13194 k[0] & 0xffffffff, k[1] & 0xffffffff);
13ded975
DE
13195 return;
13196 }
9878760c 13197 }
a9098fd0 13198 else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
9878760c 13199 {
042259f2
DE
13200 REAL_VALUE_TYPE rv;
13201 long l;
9878760c 13202
042259f2
DE
13203 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
13204 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
13205
31bfaa0b
DE
13206 if (TARGET_64BIT)
13207 {
13208 if (TARGET_MINIMAL_TOC)
2bfcf297 13209 fputs (DOUBLE_INT_ASM_OP, file);
31bfaa0b 13210 else
2f0552b6
AM
13211 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13212 fprintf (file, "0x%lx00000000\n", l & 0xffffffff);
31bfaa0b
DE
13213 return;
13214 }
042259f2 13215 else
31bfaa0b
DE
13216 {
13217 if (TARGET_MINIMAL_TOC)
2bfcf297 13218 fputs ("\t.long ", file);
31bfaa0b 13219 else
2f0552b6
AM
13220 fprintf (file, "\t.tc FS_%lx[TC],", l & 0xffffffff);
13221 fprintf (file, "0x%lx\n", l & 0xffffffff);
31bfaa0b
DE
13222 return;
13223 }
042259f2 13224 }
f176e826 13225 else if (GET_MODE (x) == VOIDmode
a9098fd0 13226 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
042259f2 13227 {
e2c953b6 13228 unsigned HOST_WIDE_INT low;
042259f2
DE
13229 HOST_WIDE_INT high;
13230
13231 if (GET_CODE (x) == CONST_DOUBLE)
13232 {
13233 low = CONST_DOUBLE_LOW (x);
13234 high = CONST_DOUBLE_HIGH (x);
13235 }
13236 else
13237#if HOST_BITS_PER_WIDE_INT == 32
13238 {
13239 low = INTVAL (x);
0858c623 13240 high = (low & 0x80000000) ? ~0 : 0;
042259f2
DE
13241 }
13242#else
13243 {
0858c623 13244 low = INTVAL (x) & 0xffffffff;
042259f2
DE
13245 high = (HOST_WIDE_INT) INTVAL (x) >> 32;
13246 }
13247#endif
9878760c 13248
a9098fd0
GK
13249 /* TOC entries are always Pmode-sized, but since this
13250 is a bigendian machine then if we're putting smaller
13251 integer constants in the TOC we have to pad them.
13252 (This is still a win over putting the constants in
13253 a separate constant pool, because then we'd have
02a4ec28
FS
13254 to have both a TOC entry _and_ the actual constant.)
13255
13256 For a 32-bit target, CONST_INT values are loaded and shifted
13257 entirely within `low' and can be stored in one TOC entry. */
13258
13259 if (TARGET_64BIT && POINTER_SIZE < GET_MODE_BITSIZE (mode))
a9098fd0 13260 abort ();/* It would be easy to make this work, but it doesn't now. */
02a4ec28
FS
13261
13262 if (POINTER_SIZE > GET_MODE_BITSIZE (mode))
fb52d8de
AM
13263 {
13264#if HOST_BITS_PER_WIDE_INT == 32
13265 lshift_double (low, high, POINTER_SIZE - GET_MODE_BITSIZE (mode),
13266 POINTER_SIZE, &low, &high, 0);
13267#else
13268 low |= high << 32;
13269 low <<= POINTER_SIZE - GET_MODE_BITSIZE (mode);
13270 high = (HOST_WIDE_INT) low >> 32;
13271 low &= 0xffffffff;
13272#endif
13273 }
a9098fd0 13274
13ded975
DE
13275 if (TARGET_64BIT)
13276 {
13277 if (TARGET_MINIMAL_TOC)
2bfcf297 13278 fputs (DOUBLE_INT_ASM_OP, file);
13ded975 13279 else
2f0552b6
AM
13280 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
13281 (long) high & 0xffffffff, (long) low & 0xffffffff);
13282 fprintf (file, "0x%lx%08lx\n",
13283 (long) high & 0xffffffff, (long) low & 0xffffffff);
13ded975
DE
13284 return;
13285 }
1875cc88 13286 else
13ded975 13287 {
02a4ec28
FS
13288 if (POINTER_SIZE < GET_MODE_BITSIZE (mode))
13289 {
13290 if (TARGET_MINIMAL_TOC)
2bfcf297 13291 fputs ("\t.long ", file);
02a4ec28 13292 else
2bfcf297 13293 fprintf (file, "\t.tc ID_%lx_%lx[TC],",
2f0552b6
AM
13294 (long) high & 0xffffffff, (long) low & 0xffffffff);
13295 fprintf (file, "0x%lx,0x%lx\n",
13296 (long) high & 0xffffffff, (long) low & 0xffffffff);
02a4ec28 13297 }
13ded975 13298 else
02a4ec28
FS
13299 {
13300 if (TARGET_MINIMAL_TOC)
2bfcf297 13301 fputs ("\t.long ", file);
02a4ec28 13302 else
2f0552b6
AM
13303 fprintf (file, "\t.tc IS_%lx[TC],", (long) low & 0xffffffff);
13304 fprintf (file, "0x%lx\n", (long) low & 0xffffffff);
02a4ec28 13305 }
13ded975
DE
13306 return;
13307 }
9878760c
RK
13308 }
13309
13310 if (GET_CODE (x) == CONST)
13311 {
2bfcf297
DB
13312 if (GET_CODE (XEXP (x, 0)) != PLUS)
13313 abort ();
13314
9878760c
RK
13315 base = XEXP (XEXP (x, 0), 0);
13316 offset = INTVAL (XEXP (XEXP (x, 0), 1));
13317 }
13318
13319 if (GET_CODE (base) == SYMBOL_REF)
13320 name = XSTR (base, 0);
13321 else if (GET_CODE (base) == LABEL_REF)
13322 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (XEXP (base, 0)));
13323 else if (GET_CODE (base) == CODE_LABEL)
13324 ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (base));
13325 else
13326 abort ();
13327
772c5265 13328 real_name = (*targetm.strip_name_encoding) (name);
1875cc88 13329 if (TARGET_MINIMAL_TOC)
2bfcf297 13330 fputs (TARGET_32BIT ? "\t.long " : DOUBLE_INT_ASM_OP, file);
1875cc88
JW
13331 else
13332 {
b6c9286a 13333 fprintf (file, "\t.tc %s", real_name);
9878760c 13334
1875cc88
JW
13335 if (offset < 0)
13336 fprintf (file, ".N%d", - offset);
13337 else if (offset)
13338 fprintf (file, ".P%d", offset);
9878760c 13339
19d2d16f 13340 fputs ("[TC],", file);
1875cc88 13341 }
581bc4de
MM
13342
13343 /* Currently C++ toc references to vtables can be emitted before it
13344 is decided whether the vtable is public or private. If this is
13345 the case, then the linker will eventually complain that there is
13346 a TOC reference to an unknown section. Thus, for vtables only,
13347 we emit the TOC reference to reference the symbol and not the
13348 section. */
28e510bd 13349 if (VTABLE_NAME_P (name))
581bc4de 13350 {
54ee9799 13351 RS6000_OUTPUT_BASENAME (file, name);
581bc4de
MM
13352 if (offset < 0)
13353 fprintf (file, "%d", offset);
13354 else if (offset > 0)
13355 fprintf (file, "+%d", offset);
13356 }
13357 else
13358 output_addr_const (file, x);
19d2d16f 13359 putc ('\n', file);
9878760c
RK
13360}
13361\f
13362/* Output an assembler pseudo-op to write an ASCII string of N characters
13363 starting at P to FILE.
13364
13365 On the RS/6000, we have to do this using the .byte operation and
13366 write out special characters outside the quoted string.
13367 Also, the assembler is broken; very long strings are truncated,
a4f6c312 13368 so we must artificially break them up early. */
9878760c
RK
13369
13370void
a2369ed3 13371output_ascii (FILE *file, const char *p, int n)
9878760c
RK
13372{
13373 char c;
13374 int i, count_string;
d330fd93
KG
13375 const char *for_string = "\t.byte \"";
13376 const char *for_decimal = "\t.byte ";
13377 const char *to_close = NULL;
9878760c
RK
13378
13379 count_string = 0;
13380 for (i = 0; i < n; i++)
13381 {
13382 c = *p++;
13383 if (c >= ' ' && c < 0177)
13384 {
13385 if (for_string)
13386 fputs (for_string, file);
13387 putc (c, file);
13388
13389 /* Write two quotes to get one. */
13390 if (c == '"')
13391 {
13392 putc (c, file);
13393 ++count_string;
13394 }
13395
13396 for_string = NULL;
13397 for_decimal = "\"\n\t.byte ";
13398 to_close = "\"\n";
13399 ++count_string;
13400
13401 if (count_string >= 512)
13402 {
13403 fputs (to_close, file);
13404
13405 for_string = "\t.byte \"";
13406 for_decimal = "\t.byte ";
13407 to_close = NULL;
13408 count_string = 0;
13409 }
13410 }
13411 else
13412 {
13413 if (for_decimal)
13414 fputs (for_decimal, file);
13415 fprintf (file, "%d", c);
13416
13417 for_string = "\n\t.byte \"";
13418 for_decimal = ", ";
13419 to_close = "\n";
13420 count_string = 0;
13421 }
13422 }
13423
13424 /* Now close the string if we have written one. Then end the line. */
13425 if (to_close)
9ebbca7d 13426 fputs (to_close, file);
9878760c
RK
13427}
13428\f
13429/* Generate a unique section name for FILENAME for a section type
13430 represented by SECTION_DESC. Output goes into BUF.
13431
13432 SECTION_DESC can be any string, as long as it is different for each
13433 possible section type.
13434
13435 We name the section in the same manner as xlc. The name begins with an
13436 underscore followed by the filename (after stripping any leading directory
11e5fe42
RK
13437 names) with the last period replaced by the string SECTION_DESC. If
13438 FILENAME does not contain a period, SECTION_DESC is appended to the end of
13439 the name. */
9878760c
RK
13440
13441void
a2369ed3
DJ
13442rs6000_gen_section_name (char **buf, const char *filename,
13443 const char *section_desc)
9878760c 13444{
9ebbca7d 13445 const char *q, *after_last_slash, *last_period = 0;
9878760c
RK
13446 char *p;
13447 int len;
9878760c
RK
13448
13449 after_last_slash = filename;
13450 for (q = filename; *q; q++)
11e5fe42
RK
13451 {
13452 if (*q == '/')
13453 after_last_slash = q + 1;
13454 else if (*q == '.')
13455 last_period = q;
13456 }
9878760c 13457
11e5fe42 13458 len = strlen (after_last_slash) + strlen (section_desc) + 2;
6d9f628e 13459 *buf = (char *) xmalloc (len);
9878760c
RK
13460
13461 p = *buf;
13462 *p++ = '_';
13463
13464 for (q = after_last_slash; *q; q++)
13465 {
11e5fe42 13466 if (q == last_period)
9878760c
RK
13467 {
13468 strcpy (p, section_desc);
13469 p += strlen (section_desc);
e3981aab 13470 break;
9878760c
RK
13471 }
13472
e9a780ec 13473 else if (ISALNUM (*q))
9878760c
RK
13474 *p++ = *q;
13475 }
13476
11e5fe42 13477 if (last_period == 0)
9878760c
RK
13478 strcpy (p, section_desc);
13479 else
13480 *p = '\0';
13481}
e165f3f0 13482\f
a4f6c312 13483/* Emit profile function. */
411707f4 13484
411707f4 13485void
a2369ed3 13486output_profile_hook (int labelno ATTRIBUTE_UNUSED)
411707f4 13487{
ffcfcb5f
AM
13488 if (TARGET_PROFILE_KERNEL)
13489 return;
13490
8480e480
CC
13491 if (DEFAULT_ABI == ABI_AIX)
13492 {
9739c90c
JJ
13493#ifndef NO_PROFILE_COUNTERS
13494# define NO_PROFILE_COUNTERS 0
13495#endif
13496 if (NO_PROFILE_COUNTERS)
13497 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 0);
13498 else
13499 {
13500 char buf[30];
13501 const char *label_name;
13502 rtx fun;
411707f4 13503
9739c90c
JJ
13504 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
13505 label_name = (*targetm.strip_name_encoding) (ggc_strdup (buf));
13506 fun = gen_rtx_SYMBOL_REF (Pmode, label_name);
411707f4 13507
9739c90c
JJ
13508 emit_library_call (init_one_libfunc (RS6000_MCOUNT), 0, VOIDmode, 1,
13509 fun, Pmode);
13510 }
8480e480 13511 }
ee890fe2
SS
13512 else if (DEFAULT_ABI == ABI_DARWIN)
13513 {
d5fa86ba 13514 const char *mcount_name = RS6000_MCOUNT;
ee890fe2
SS
13515 int caller_addr_regno = LINK_REGISTER_REGNUM;
13516
13517 /* Be conservative and always set this, at least for now. */
13518 current_function_uses_pic_offset_table = 1;
13519
13520#if TARGET_MACHO
13521 /* For PIC code, set up a stub and collect the caller's address
13522 from r0, which is where the prologue puts it. */
ab82a49f 13523 if (MACHOPIC_INDIRECT)
ee890fe2
SS
13524 {
13525 mcount_name = machopic_stub_name (mcount_name);
13526 if (current_function_uses_pic_offset_table)
13527 caller_addr_regno = 0;
13528 }
13529#endif
13530 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, mcount_name),
13531 0, VOIDmode, 1,
13532 gen_rtx_REG (Pmode, caller_addr_regno), Pmode);
13533 }
411707f4
CC
13534}
13535
a4f6c312 13536/* Write function profiler code. */
e165f3f0
RK
13537
13538void
a2369ed3 13539output_function_profiler (FILE *file, int labelno)
e165f3f0 13540{
3daf36a4 13541 char buf[100];
09eeeacb 13542 int save_lr = 8;
e165f3f0 13543
38c1f2d7 13544 switch (DEFAULT_ABI)
3daf36a4 13545 {
38c1f2d7
MM
13546 default:
13547 abort ();
13548
13549 case ABI_V4:
09eeeacb 13550 save_lr = 4;
09eeeacb
AM
13551 if (!TARGET_32BIT)
13552 {
13553 warning ("no profiling of 64-bit code for this ABI");
13554 return;
13555 }
ffcfcb5f 13556 ASM_GENERATE_INTERNAL_LABEL (buf, "LP", labelno);
38c1f2d7
MM
13557 fprintf (file, "\tmflr %s\n", reg_names[0]);
13558 if (flag_pic == 1)
13559 {
dfdfa60f 13560 fputs ("\tbl _GLOBAL_OFFSET_TABLE_@local-4\n", file);
09eeeacb
AM
13561 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13562 reg_names[0], save_lr, reg_names[1]);
17167fd8 13563 asm_fprintf (file, "\tmflr %s\n", reg_names[12]);
dfdfa60f 13564 asm_fprintf (file, "\t{l|lwz} %s,", reg_names[0]);
38c1f2d7 13565 assemble_name (file, buf);
17167fd8 13566 asm_fprintf (file, "@got(%s)\n", reg_names[12]);
38c1f2d7 13567 }
9ebbca7d 13568 else if (flag_pic > 1)
38c1f2d7 13569 {
09eeeacb
AM
13570 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13571 reg_names[0], save_lr, reg_names[1]);
9ebbca7d
GK
13572 /* Now, we need to get the address of the label. */
13573 fputs ("\tbl 1f\n\t.long ", file);
034e84c4 13574 assemble_name (file, buf);
9ebbca7d
GK
13575 fputs ("-.\n1:", file);
13576 asm_fprintf (file, "\tmflr %s\n", reg_names[11]);
13577 asm_fprintf (file, "\t{l|lwz} %s,0(%s)\n",
13578 reg_names[0], reg_names[11]);
13579 asm_fprintf (file, "\t{cax|add} %s,%s,%s\n",
13580 reg_names[0], reg_names[0], reg_names[11]);
38c1f2d7 13581 }
38c1f2d7
MM
13582 else
13583 {
17167fd8 13584 asm_fprintf (file, "\t{liu|lis} %s,", reg_names[12]);
38c1f2d7 13585 assemble_name (file, buf);
dfdfa60f 13586 fputs ("@ha\n", file);
09eeeacb
AM
13587 asm_fprintf (file, "\t{st|stw} %s,%d(%s)\n",
13588 reg_names[0], save_lr, reg_names[1]);
a260abc9 13589 asm_fprintf (file, "\t{cal|la} %s,", reg_names[0]);
38c1f2d7 13590 assemble_name (file, buf);
17167fd8 13591 asm_fprintf (file, "@l(%s)\n", reg_names[12]);
38c1f2d7
MM
13592 }
13593
50d440bc
NC
13594 /* ABI_V4 saves the static chain reg with ASM_OUTPUT_REG_PUSH. */
13595 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
38c1f2d7
MM
13596 break;
13597
13598 case ABI_AIX:
ee890fe2 13599 case ABI_DARWIN:
ffcfcb5f
AM
13600 if (!TARGET_PROFILE_KERNEL)
13601 {
a3c9585f 13602 /* Don't do anything, done in output_profile_hook (). */
ffcfcb5f
AM
13603 }
13604 else
13605 {
13606 if (TARGET_32BIT)
13607 abort ();
13608
13609 asm_fprintf (file, "\tmflr %s\n", reg_names[0]);
13610 asm_fprintf (file, "\tstd %s,16(%s)\n", reg_names[0], reg_names[1]);
13611
13612 if (current_function_needs_context)
13613 {
13614 asm_fprintf (file, "\tstd %s,24(%s)\n",
13615 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13616 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13617 asm_fprintf (file, "\tld %s,24(%s)\n",
13618 reg_names[STATIC_CHAIN_REGNUM], reg_names[1]);
13619 }
13620 else
13621 fprintf (file, "\tbl %s\n", RS6000_MCOUNT);
13622 }
38c1f2d7
MM
13623 break;
13624 }
e165f3f0 13625}
a251ffd0 13626
b54cf83a
DE
13627\f
13628static int
863d938c 13629rs6000_use_dfa_pipeline_interface (void)
b54cf83a
DE
13630{
13631 return 1;
13632}
13633
b54cf83a
DE
13634/* Power4 load update and store update instructions are cracked into a
13635 load or store and an integer insn which are executed in the same cycle.
13636 Branches have their own dispatch slot which does not count against the
13637 GCC issue rate, but it changes the program flow so there are no other
13638 instructions to issue in this cycle. */
13639
13640static int
a2369ed3
DJ
13641rs6000_variable_issue (FILE *stream ATTRIBUTE_UNUSED,
13642 int verbose ATTRIBUTE_UNUSED,
13643 rtx insn, int more)
b54cf83a
DE
13644{
13645 if (GET_CODE (PATTERN (insn)) == USE
13646 || GET_CODE (PATTERN (insn)) == CLOBBER)
13647 return more;
13648
13649 if (rs6000_cpu == PROCESSOR_POWER4)
13650 {
cbe26ab8
DN
13651 if (is_microcoded_insn (insn))
13652 return 0;
13653 else if (is_cracked_insn (insn))
13654 return more > 2 ? more - 2 : 0;
b54cf83a 13655 }
165b263e
DE
13656
13657 return more - 1;
b54cf83a
DE
13658}
13659
a251ffd0
TG
13660/* Adjust the cost of a scheduling dependency. Return the new cost of
13661 a dependency LINK or INSN on DEP_INSN. COST is the current cost. */
13662
c237e94a 13663static int
a2369ed3
DJ
13664rs6000_adjust_cost (rtx insn, rtx link, rtx dep_insn ATTRIBUTE_UNUSED,
13665 int cost)
a251ffd0
TG
13666{
13667 if (! recog_memoized (insn))
13668 return 0;
13669
13670 if (REG_NOTE_KIND (link) != 0)
13671 return 0;
13672
13673 if (REG_NOTE_KIND (link) == 0)
13674 {
ed947a96
DJ
13675 /* Data dependency; DEP_INSN writes a register that INSN reads
13676 some cycles later. */
13677 switch (get_attr_type (insn))
13678 {
13679 case TYPE_JMPREG:
309323c2 13680 /* Tell the first scheduling pass about the latency between
ed947a96
DJ
13681 a mtctr and bctr (and mtlr and br/blr). The first
13682 scheduling pass will not know about this latency since
13683 the mtctr instruction, which has the latency associated
13684 to it, will be generated by reload. */
309323c2 13685 return TARGET_POWER ? 5 : 4;
ed947a96
DJ
13686 case TYPE_BRANCH:
13687 /* Leave some extra cycles between a compare and its
13688 dependent branch, to inhibit expensive mispredicts. */
309323c2
DE
13689 if ((rs6000_cpu_attr == CPU_PPC603
13690 || rs6000_cpu_attr == CPU_PPC604
13691 || rs6000_cpu_attr == CPU_PPC604E
13692 || rs6000_cpu_attr == CPU_PPC620
13693 || rs6000_cpu_attr == CPU_PPC630
13694 || rs6000_cpu_attr == CPU_PPC750
13695 || rs6000_cpu_attr == CPU_PPC7400
13696 || rs6000_cpu_attr == CPU_PPC7450
13697 || rs6000_cpu_attr == CPU_POWER4)
ed947a96
DJ
13698 && recog_memoized (dep_insn)
13699 && (INSN_CODE (dep_insn) >= 0)
b54cf83a
DE
13700 && (get_attr_type (dep_insn) == TYPE_CMP
13701 || get_attr_type (dep_insn) == TYPE_COMPARE
ed947a96 13702 || get_attr_type (dep_insn) == TYPE_DELAYED_COMPARE
9259f3b0
DE
13703 || get_attr_type (dep_insn) == TYPE_IMUL_COMPARE
13704 || get_attr_type (dep_insn) == TYPE_LMUL_COMPARE
ed947a96 13705 || get_attr_type (dep_insn) == TYPE_FPCOMPARE
b54cf83a
DE
13706 || get_attr_type (dep_insn) == TYPE_CR_LOGICAL
13707 || get_attr_type (dep_insn) == TYPE_DELAYED_CR))
ed947a96
DJ
13708 return cost + 2;
13709 default:
13710 break;
13711 }
a251ffd0
TG
13712 /* Fall out to return default cost. */
13713 }
13714
13715 return cost;
13716}
b6c9286a 13717
cbe26ab8 13718/* The function returns a true if INSN is microcoded.
839a4992 13719 Return false otherwise. */
cbe26ab8
DN
13720
13721static bool
13722is_microcoded_insn (rtx insn)
13723{
13724 if (!insn || !INSN_P (insn)
13725 || GET_CODE (PATTERN (insn)) == USE
13726 || GET_CODE (PATTERN (insn)) == CLOBBER)
13727 return false;
13728
13729 if (rs6000_cpu == PROCESSOR_POWER4)
13730 {
13731 enum attr_type type = get_attr_type (insn);
13732 if (type == TYPE_LOAD_EXT_U
13733 || type == TYPE_LOAD_EXT_UX
13734 || type == TYPE_LOAD_UX
13735 || type == TYPE_STORE_UX
13736 || type == TYPE_MFCR)
13737 return true;
13738 }
13739
13740 return false;
13741}
13742
5c425df5 13743/* The function returns a nonzero value if INSN can be scheduled only
cbe26ab8
DN
13744 as the first insn in a dispatch group ("dispatch-slot restricted").
13745 In this case, the returned value indicates how many dispatch slots
13746 the insn occupies (at the beginning of the group).
79ae11c4
DN
13747 Return 0 otherwise. */
13748
cbe26ab8 13749static int
79ae11c4
DN
13750is_dispatch_slot_restricted (rtx insn)
13751{
13752 enum attr_type type;
13753
13754 if (rs6000_cpu != PROCESSOR_POWER4)
13755 return 0;
13756
13757 if (!insn
13758 || insn == NULL_RTX
13759 || GET_CODE (insn) == NOTE
13760 || GET_CODE (PATTERN (insn)) == USE
13761 || GET_CODE (PATTERN (insn)) == CLOBBER)
13762 return 0;
13763
13764 type = get_attr_type (insn);
13765
13766 switch (type){
13767 case TYPE_MFCR:
13768 case TYPE_MFCRF:
13769 case TYPE_MTCR:
13770 case TYPE_DELAYED_CR:
13771 case TYPE_CR_LOGICAL:
13772 case TYPE_MTJMPR:
13773 case TYPE_MFJMPR:
13774 return 1;
13775 case TYPE_IDIV:
13776 case TYPE_LDIV:
13777 return 2;
13778 default:
13779 return 0;
13780 }
13781}
13782
cbe26ab8
DN
13783/* The function returns true if INSN is cracked into 2 instructions
13784 by the processor (and therefore occupies 2 issue slots). */
13785
13786static bool
13787is_cracked_insn (rtx insn)
13788{
13789 if (!insn || !INSN_P (insn)
13790 || GET_CODE (PATTERN (insn)) == USE
13791 || GET_CODE (PATTERN (insn)) == CLOBBER)
13792 return false;
13793
13794 if (rs6000_cpu == PROCESSOR_POWER4)
13795 {
13796 enum attr_type type = get_attr_type (insn);
13797 if (type == TYPE_LOAD_U || type == TYPE_STORE_U
13798 || type == TYPE_FPLOAD_U || type == TYPE_FPSTORE_U
13799 || type == TYPE_FPLOAD_UX || type == TYPE_FPSTORE_UX
13800 || type == TYPE_LOAD_EXT || type == TYPE_DELAYED_CR
13801 || type == TYPE_COMPARE || type == TYPE_DELAYED_COMPARE
13802 || type == TYPE_IMUL_COMPARE || type == TYPE_LMUL_COMPARE
13803 || type == TYPE_IDIV || type == TYPE_LDIV
13804 || type == TYPE_INSERT_WORD)
13805 return true;
13806 }
13807
13808 return false;
13809}
13810
13811/* The function returns true if INSN can be issued only from
a3c9585f 13812 the branch slot. */
cbe26ab8
DN
13813
13814static bool
13815is_branch_slot_insn (rtx insn)
13816{
13817 if (!insn || !INSN_P (insn)
13818 || GET_CODE (PATTERN (insn)) == USE
13819 || GET_CODE (PATTERN (insn)) == CLOBBER)
13820 return false;
13821
13822 if (rs6000_cpu == PROCESSOR_POWER4)
13823 {
13824 enum attr_type type = get_attr_type (insn);
13825 if (type == TYPE_BRANCH || type == TYPE_JMPREG)
13826 return true;
13827 return false;
13828 }
13829
13830 return false;
13831}
79ae11c4 13832
a4f6c312 13833/* A C statement (sans semicolon) to update the integer scheduling
79ae11c4
DN
13834 priority INSN_PRIORITY (INSN). Increase the priority to execute the
13835 INSN earlier, reduce the priority to execute INSN later. Do not
a4f6c312
SS
13836 define this macro if you do not need to adjust the scheduling
13837 priorities of insns. */
bef84347 13838
c237e94a 13839static int
a2369ed3 13840rs6000_adjust_priority (rtx insn ATTRIBUTE_UNUSED, int priority)
bef84347 13841{
a4f6c312
SS
13842 /* On machines (like the 750) which have asymmetric integer units,
13843 where one integer unit can do multiply and divides and the other
13844 can't, reduce the priority of multiply/divide so it is scheduled
13845 before other integer operations. */
bef84347
VM
13846
13847#if 0
2c3c49de 13848 if (! INSN_P (insn))
bef84347
VM
13849 return priority;
13850
13851 if (GET_CODE (PATTERN (insn)) == USE)
13852 return priority;
13853
13854 switch (rs6000_cpu_attr) {
13855 case CPU_PPC750:
13856 switch (get_attr_type (insn))
13857 {
13858 default:
13859 break;
13860
13861 case TYPE_IMUL:
13862 case TYPE_IDIV:
3cb999d8
DE
13863 fprintf (stderr, "priority was %#x (%d) before adjustment\n",
13864 priority, priority);
bef84347
VM
13865 if (priority >= 0 && priority < 0x01000000)
13866 priority >>= 3;
13867 break;
13868 }
13869 }
13870#endif
13871
79ae11c4
DN
13872 if (is_dispatch_slot_restricted (insn)
13873 && reload_completed
13874 && current_sched_info->sched_max_insns_priority
13875 && rs6000_sched_restricted_insns_priority)
13876 {
13877
13878 /* Prioritize insns that can be dispatched only in the first dispatch slot. */
13879 if (rs6000_sched_restricted_insns_priority == 1)
13880 /* Attach highest priority to insn. This means that in
13881 haifa-sched.c:ready_sort(), dispatch-slot restriction considerations
13882 precede 'priority' (critical path) considerations. */
13883 return current_sched_info->sched_max_insns_priority;
13884 else if (rs6000_sched_restricted_insns_priority == 2)
13885 /* Increase priority of insn by a minimal amount. This means that in
13886 haifa-sched.c:ready_sort(), only 'priority' (critical path) considerations
13887 precede dispatch-slot restriction considerations. */
13888 return (priority + 1);
13889 }
13890
bef84347
VM
13891 return priority;
13892}
13893
a4f6c312
SS
13894/* Return how many instructions the machine can issue per cycle. */
13895
c237e94a 13896static int
863d938c 13897rs6000_issue_rate (void)
b6c9286a 13898{
3317bab1
DE
13899 /* Use issue rate of 1 for first scheduling pass to decrease degradation. */
13900 if (!reload_completed)
13901 return 1;
13902
b6c9286a 13903 switch (rs6000_cpu_attr) {
3cb999d8
DE
13904 case CPU_RIOS1: /* ? */
13905 case CPU_RS64A:
13906 case CPU_PPC601: /* ? */
ed947a96 13907 case CPU_PPC7450:
3cb999d8 13908 return 3;
b54cf83a 13909 case CPU_PPC440:
b6c9286a 13910 case CPU_PPC603:
bef84347 13911 case CPU_PPC750:
ed947a96 13912 case CPU_PPC7400:
be12c2b0 13913 case CPU_PPC8540:
bef84347 13914 return 2;
3cb999d8 13915 case CPU_RIOS2:
b6c9286a 13916 case CPU_PPC604:
19684119 13917 case CPU_PPC604E:
b6c9286a 13918 case CPU_PPC620:
3cb999d8 13919 case CPU_PPC630:
b6c9286a 13920 return 4;
cbe26ab8
DN
13921 case CPU_POWER4:
13922 return 5;
b6c9286a
MM
13923 default:
13924 return 1;
13925 }
13926}
13927
be12c2b0
VM
13928/* Return how many instructions to look ahead for better insn
13929 scheduling. */
13930
13931static int
863d938c 13932rs6000_use_sched_lookahead (void)
be12c2b0
VM
13933{
13934 if (rs6000_cpu_attr == CPU_PPC8540)
13935 return 4;
13936 return 0;
13937}
13938
569fa502
DN
13939/* Determine is PAT refers to memory. */
13940
13941static bool
13942is_mem_ref (rtx pat)
13943{
13944 const char * fmt;
13945 int i, j;
13946 bool ret = false;
13947
13948 if (GET_CODE (pat) == MEM)
13949 return true;
13950
13951 /* Recursively process the pattern. */
13952 fmt = GET_RTX_FORMAT (GET_CODE (pat));
13953
13954 for (i = GET_RTX_LENGTH (GET_CODE (pat)) - 1; i >= 0 && !ret; i--)
13955 {
13956 if (fmt[i] == 'e')
13957 ret |= is_mem_ref (XEXP (pat, i));
13958 else if (fmt[i] == 'E')
13959 for (j = XVECLEN (pat, i) - 1; j >= 0; j--)
13960 ret |= is_mem_ref (XVECEXP (pat, i, j));
13961 }
13962
13963 return ret;
13964}
13965
13966/* Determine if PAT is a PATTERN of a load insn. */
13967
13968static bool
13969is_load_insn1 (rtx pat)
13970{
13971 if (!pat || pat == NULL_RTX)
13972 return false;
13973
13974 if (GET_CODE (pat) == SET)
13975 return is_mem_ref (SET_SRC (pat));
13976
13977 if (GET_CODE (pat) == PARALLEL)
13978 {
13979 int i;
13980
13981 for (i = 0; i < XVECLEN (pat, 0); i++)
13982 if (is_load_insn1 (XVECEXP (pat, 0, i)))
13983 return true;
13984 }
13985
13986 return false;
13987}
13988
13989/* Determine if INSN loads from memory. */
13990
13991static bool
13992is_load_insn (rtx insn)
13993{
13994 if (!insn || !INSN_P (insn))
13995 return false;
13996
13997 if (GET_CODE (insn) == CALL_INSN)
13998 return false;
13999
14000 return is_load_insn1 (PATTERN (insn));
14001}
14002
14003/* Determine if PAT is a PATTERN of a store insn. */
14004
14005static bool
14006is_store_insn1 (rtx pat)
14007{
14008 if (!pat || pat == NULL_RTX)
14009 return false;
14010
14011 if (GET_CODE (pat) == SET)
14012 return is_mem_ref (SET_DEST (pat));
14013
14014 if (GET_CODE (pat) == PARALLEL)
14015 {
14016 int i;
14017
14018 for (i = 0; i < XVECLEN (pat, 0); i++)
14019 if (is_store_insn1 (XVECEXP (pat, 0, i)))
14020 return true;
14021 }
14022
14023 return false;
14024}
14025
14026/* Determine if INSN stores to memory. */
14027
14028static bool
14029is_store_insn (rtx insn)
14030{
14031 if (!insn || !INSN_P (insn))
14032 return false;
14033
14034 return is_store_insn1 (PATTERN (insn));
14035}
14036
14037/* Returns whether the dependence between INSN and NEXT is considered
14038 costly by the given target. */
14039
14040static bool
14041rs6000_is_costly_dependence (rtx insn, rtx next, rtx link, int cost, int distance)
14042{
14043 /* If the flag is not enbled - no dependence is considered costly;
14044 allow all dependent insns in the same group.
14045 This is the most aggressive option. */
14046 if (rs6000_sched_costly_dep == no_dep_costly)
14047 return false;
14048
14049 /* If the flag is set to 1 - a dependence is always considered costly;
14050 do not allow dependent instructions in the same group.
14051 This is the most conservative option. */
14052 if (rs6000_sched_costly_dep == all_deps_costly)
14053 return true;
14054
14055 if (rs6000_sched_costly_dep == store_to_load_dep_costly
14056 && is_load_insn (next)
14057 && is_store_insn (insn))
14058 /* Prevent load after store in the same group. */
14059 return true;
14060
14061 if (rs6000_sched_costly_dep == true_store_to_load_dep_costly
14062 && is_load_insn (next)
14063 && is_store_insn (insn)
14064 && (!link || (int) REG_NOTE_KIND (link) == 0))
14065 /* Prevent load after store in the same group if it is a true dependence. */
14066 return true;
14067
14068 /* The flag is set to X; dependences with latency >= X are considered costly,
14069 and will not be scheduled in the same group. */
14070 if (rs6000_sched_costly_dep <= max_dep_latency
14071 && ((cost - distance) >= (int)rs6000_sched_costly_dep))
14072 return true;
14073
14074 return false;
14075}
14076
cbe26ab8
DN
14077/* Return the next insn after INSN that is found before TAIL is reached,
14078 skipping any "non-active" insns - insns that will not actually occupy
14079 an issue slot. Return NULL_RTX if such an insn is not found. */
14080
14081static rtx
14082get_next_active_insn (rtx insn, rtx tail)
14083{
14084 rtx next_insn;
14085
14086 if (!insn || insn == tail)
14087 return NULL_RTX;
14088
14089 next_insn = NEXT_INSN (insn);
14090
14091 while (next_insn
14092 && next_insn != tail
14093 && (GET_CODE(next_insn) == NOTE
14094 || GET_CODE (PATTERN (next_insn)) == USE
14095 || GET_CODE (PATTERN (next_insn)) == CLOBBER))
14096 {
14097 next_insn = NEXT_INSN (next_insn);
14098 }
14099
14100 if (!next_insn || next_insn == tail)
14101 return NULL_RTX;
14102
14103 return next_insn;
14104}
14105
839a4992 14106/* Return whether the presence of INSN causes a dispatch group termination
cbe26ab8
DN
14107 of group WHICH_GROUP.
14108
14109 If WHICH_GROUP == current_group, this function will return true if INSN
14110 causes the termination of the current group (i.e, the dispatch group to
14111 which INSN belongs). This means that INSN will be the last insn in the
14112 group it belongs to.
14113
14114 If WHICH_GROUP == previous_group, this function will return true if INSN
14115 causes the termination of the previous group (i.e, the dispatch group that
14116 precedes the group to which INSN belongs). This means that INSN will be
14117 the first insn in the group it belongs to). */
14118
14119static bool
14120insn_terminates_group_p (rtx insn, enum group_termination which_group)
14121{
14122 enum attr_type type;
14123
14124 if (! insn)
14125 return false;
569fa502 14126
cbe26ab8
DN
14127 type = get_attr_type (insn);
14128
14129 if (is_microcoded_insn (insn))
14130 return true;
14131
14132 if (which_group == current_group)
14133 {
14134 if (is_branch_slot_insn (insn))
14135 return true;
14136 return false;
14137 }
14138 else if (which_group == previous_group)
14139 {
14140 if (is_dispatch_slot_restricted (insn))
14141 return true;
14142 return false;
14143 }
14144
14145 return false;
14146}
14147
839a4992 14148/* Return true if it is recommended to keep NEXT_INSN "far" (in a separate
cbe26ab8
DN
14149 dispatch group) from the insns in GROUP_INSNS. Return false otherwise. */
14150
14151static bool
14152is_costly_group (rtx *group_insns, rtx next_insn)
14153{
14154 int i;
14155 rtx link;
14156 int cost;
14157 int issue_rate = rs6000_issue_rate ();
14158
14159 for (i = 0; i < issue_rate; i++)
14160 {
14161 rtx insn = group_insns[i];
14162 if (!insn)
14163 continue;
14164 for (link = INSN_DEPEND (insn); link != 0; link = XEXP (link, 1))
14165 {
14166 rtx next = XEXP (link, 0);
14167 if (next == next_insn)
14168 {
14169 cost = insn_cost (insn, link, next_insn);
14170 if (rs6000_is_costly_dependence (insn, next_insn, link, cost, 0))
14171 return true;
14172 }
14173 }
14174 }
14175
14176 return false;
14177}
14178
14179/* Utility of the function redefine_groups.
14180 Check if it is too costly to schedule NEXT_INSN together with GROUP_INSNS
14181 in the same dispatch group. If so, insert nops before NEXT_INSN, in order
14182 to keep it "far" (in a separate group) from GROUP_INSNS, following
14183 one of the following schemes, depending on the value of the flag
14184 -minsert_sched_nops = X:
14185 (1) X == sched_finish_regroup_exact: insert exactly as many nops as needed
839a4992 14186 in order to force NEXT_INSN into a separate group.
cbe26ab8
DN
14187 (2) X < sched_finish_regroup_exact: insert exactly X nops.
14188 GROUP_END, CAN_ISSUE_MORE and GROUP_COUNT record the state after nop
14189 insertion (has a group just ended, how many vacant issue slots remain in the
14190 last group, and how many dispatch groups were encountered so far). */
14191
14192static int
14193force_new_group (int sched_verbose, FILE *dump, rtx *group_insns, rtx next_insn,
14194 bool *group_end, int can_issue_more, int *group_count)
14195{
14196 rtx nop;
14197 bool force;
14198 int issue_rate = rs6000_issue_rate ();
14199 bool end = *group_end;
14200 int i;
14201
14202 if (next_insn == NULL_RTX)
14203 return can_issue_more;
14204
14205 if (rs6000_sched_insert_nops > sched_finish_regroup_exact)
14206 return can_issue_more;
14207
14208 force = is_costly_group (group_insns, next_insn);
14209 if (!force)
14210 return can_issue_more;
14211
14212 if (sched_verbose > 6)
14213 fprintf (dump,"force: group count = %d, can_issue_more = %d\n",
14214 *group_count ,can_issue_more);
14215
14216 if (rs6000_sched_insert_nops == sched_finish_regroup_exact)
14217 {
14218 if (*group_end)
14219 can_issue_more = 0;
14220
14221 /* Since only a branch can be issued in the last issue_slot, it is
14222 sufficient to insert 'can_issue_more - 1' nops if next_insn is not
14223 a branch. If next_insn is a branch, we insert 'can_issue_more' nops;
14224 in this case the last nop will start a new group and the branch will be
14225 forced to the new group. */
14226 if (can_issue_more && !is_branch_slot_insn (next_insn))
14227 can_issue_more--;
14228
14229 while (can_issue_more > 0)
14230 {
14231 nop = gen_nop();
14232 emit_insn_before (nop, next_insn);
14233 can_issue_more--;
14234 }
14235
14236 *group_end = true;
14237 return 0;
14238 }
14239
14240 if (rs6000_sched_insert_nops < sched_finish_regroup_exact)
14241 {
14242 int n_nops = rs6000_sched_insert_nops;
14243
14244 /* Nops can't be issued from the branch slot, so the effective
14245 issue_rate for nops is 'issue_rate - 1'. */
14246 if (can_issue_more == 0)
14247 can_issue_more = issue_rate;
14248 can_issue_more--;
14249 if (can_issue_more == 0)
14250 {
14251 can_issue_more = issue_rate - 1;
14252 (*group_count)++;
14253 end = true;
14254 for (i = 0; i < issue_rate; i++)
14255 {
14256 group_insns[i] = 0;
14257 }
14258 }
14259
14260 while (n_nops > 0)
14261 {
14262 nop = gen_nop ();
14263 emit_insn_before (nop, next_insn);
14264 if (can_issue_more == issue_rate - 1) /* new group begins */
14265 end = false;
14266 can_issue_more--;
14267 if (can_issue_more == 0)
14268 {
14269 can_issue_more = issue_rate - 1;
14270 (*group_count)++;
14271 end = true;
14272 for (i = 0; i < issue_rate; i++)
14273 {
14274 group_insns[i] = 0;
14275 }
14276 }
14277 n_nops--;
14278 }
14279
14280 /* Scale back relative to 'issue_rate' (instead of 'issue_rate - 1'). */
14281 can_issue_more++;
14282
14283 *group_end = /* Is next_insn going to start a new group? */
14284 (end
14285 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14286 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14287 || (can_issue_more < issue_rate &&
14288 insn_terminates_group_p (next_insn, previous_group)));
14289 if (*group_end && end)
14290 (*group_count)--;
14291
14292 if (sched_verbose > 6)
14293 fprintf (dump, "done force: group count = %d, can_issue_more = %d\n",
14294 *group_count, can_issue_more);
14295 return can_issue_more;
14296 }
14297
14298 return can_issue_more;
14299}
14300
14301/* This function tries to synch the dispatch groups that the compiler "sees"
14302 with the dispatch groups that the processor dispatcher is expected to
14303 form in practice. It tries to achieve this synchronization by forcing the
14304 estimated processor grouping on the compiler (as opposed to the function
14305 'pad_goups' which tries to force the scheduler's grouping on the processor).
14306
14307 The function scans the insn sequence between PREV_HEAD_INSN and TAIL and
14308 examines the (estimated) dispatch groups that will be formed by the processor
14309 dispatcher. It marks these group boundaries to reflect the estimated
14310 processor grouping, overriding the grouping that the scheduler had marked.
14311 Depending on the value of the flag '-minsert-sched-nops' this function can
14312 force certain insns into separate groups or force a certain distance between
14313 them by inserting nops, for example, if there exists a "costly dependence"
14314 between the insns.
14315
14316 The function estimates the group boundaries that the processor will form as
14317 folllows: It keeps track of how many vacant issue slots are available after
14318 each insn. A subsequent insn will start a new group if one of the following
14319 4 cases applies:
14320 - no more vacant issue slots remain in the current dispatch group.
14321 - only the last issue slot, which is the branch slot, is vacant, but the next
14322 insn is not a branch.
14323 - only the last 2 or less issue slots, including the branch slot, are vacant,
14324 which means that a cracked insn (which occupies two issue slots) can't be
14325 issued in this group.
14326 - less than 'issue_rate' slots are vacant, and the next insn always needs to
14327 start a new group. */
14328
14329static int
14330redefine_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14331{
14332 rtx insn, next_insn;
14333 int issue_rate;
14334 int can_issue_more;
14335 int slot, i;
14336 bool group_end;
14337 int group_count = 0;
14338 rtx *group_insns;
14339
14340 /* Initialize. */
14341 issue_rate = rs6000_issue_rate ();
14342 group_insns = alloca (issue_rate * sizeof (rtx));
14343 for (i = 0; i < issue_rate; i++)
14344 {
14345 group_insns[i] = 0;
14346 }
14347 can_issue_more = issue_rate;
14348 slot = 0;
14349 insn = get_next_active_insn (prev_head_insn, tail);
14350 group_end = false;
14351
14352 while (insn != NULL_RTX)
14353 {
14354 slot = (issue_rate - can_issue_more);
14355 group_insns[slot] = insn;
14356 can_issue_more =
14357 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14358 if (insn_terminates_group_p (insn, current_group))
14359 can_issue_more = 0;
14360
14361 next_insn = get_next_active_insn (insn, tail);
14362 if (next_insn == NULL_RTX)
14363 return group_count + 1;
14364
14365 group_end = /* Is next_insn going to start a new group? */
14366 (can_issue_more == 0
14367 || (can_issue_more == 1 && !is_branch_slot_insn (next_insn))
14368 || (can_issue_more <= 2 && is_cracked_insn (next_insn))
14369 || (can_issue_more < issue_rate &&
14370 insn_terminates_group_p (next_insn, previous_group)));
14371
14372 can_issue_more = force_new_group (sched_verbose, dump, group_insns,
14373 next_insn, &group_end, can_issue_more, &group_count);
14374
14375 if (group_end)
14376 {
14377 group_count++;
14378 can_issue_more = 0;
14379 for (i = 0; i < issue_rate; i++)
14380 {
14381 group_insns[i] = 0;
14382 }
14383 }
14384
14385 if (GET_MODE (next_insn) == TImode && can_issue_more)
14386 PUT_MODE(next_insn, VOIDmode);
14387 else if (!can_issue_more && GET_MODE (next_insn) != TImode)
14388 PUT_MODE (next_insn, TImode);
14389
14390 insn = next_insn;
14391 if (can_issue_more == 0)
14392 can_issue_more = issue_rate;
14393 } /* while */
14394
14395 return group_count;
14396}
14397
14398/* Scan the insn sequence between PREV_HEAD_INSN and TAIL and examine the
14399 dispatch group boundaries that the scheduler had marked. Pad with nops
14400 any dispatch groups which have vacant issue slots, in order to force the
14401 scheduler's grouping on the processor dispatcher. The function
14402 returns the number of dispatch groups found. */
14403
14404static int
14405pad_groups (FILE *dump, int sched_verbose, rtx prev_head_insn, rtx tail)
14406{
14407 rtx insn, next_insn;
14408 rtx nop;
14409 int issue_rate;
14410 int can_issue_more;
14411 int group_end;
14412 int group_count = 0;
14413
14414 /* Initialize issue_rate. */
14415 issue_rate = rs6000_issue_rate ();
14416 can_issue_more = issue_rate;
14417
14418 insn = get_next_active_insn (prev_head_insn, tail);
14419 next_insn = get_next_active_insn (insn, tail);
14420
14421 while (insn != NULL_RTX)
14422 {
14423 can_issue_more =
14424 rs6000_variable_issue (dump, sched_verbose, insn, can_issue_more);
14425
14426 group_end = (next_insn == NULL_RTX || GET_MODE (next_insn) == TImode);
14427
14428 if (next_insn == NULL_RTX)
14429 break;
14430
14431 if (group_end)
14432 {
14433 /* If the scheduler had marked group termination at this location
14434 (between insn and next_indn), and neither insn nor next_insn will
14435 force group termination, pad the group with nops to force group
14436 termination. */
14437 if (can_issue_more
14438 && (rs6000_sched_insert_nops == sched_finish_pad_groups)
14439 && !insn_terminates_group_p (insn, current_group)
14440 && !insn_terminates_group_p (next_insn, previous_group))
14441 {
14442 if (!is_branch_slot_insn(next_insn))
14443 can_issue_more--;
14444
14445 while (can_issue_more)
14446 {
14447 nop = gen_nop ();
14448 emit_insn_before (nop, next_insn);
14449 can_issue_more--;
14450 }
14451 }
14452
14453 can_issue_more = issue_rate;
14454 group_count++;
14455 }
14456
14457 insn = next_insn;
14458 next_insn = get_next_active_insn (insn, tail);
14459 }
14460
14461 return group_count;
14462}
14463
14464/* The following function is called at the end of scheduling BB.
14465 After reload, it inserts nops at insn group bundling. */
14466
14467static void
38f391a5 14468rs6000_sched_finish (FILE *dump, int sched_verbose)
cbe26ab8
DN
14469{
14470 int n_groups;
14471
14472 if (sched_verbose)
14473 fprintf (dump, "=== Finishing schedule.\n");
14474
14475 if (reload_completed && rs6000_cpu == PROCESSOR_POWER4)
14476 {
14477 if (rs6000_sched_insert_nops == sched_finish_none)
14478 return;
14479
14480 if (rs6000_sched_insert_nops == sched_finish_pad_groups)
14481 n_groups = pad_groups (dump, sched_verbose,
14482 current_sched_info->prev_head,
14483 current_sched_info->next_tail);
14484 else
14485 n_groups = redefine_groups (dump, sched_verbose,
14486 current_sched_info->prev_head,
14487 current_sched_info->next_tail);
14488
14489 if (sched_verbose >= 6)
14490 {
14491 fprintf (dump, "ngroups = %d\n", n_groups);
14492 print_rtl (dump, current_sched_info->prev_head);
14493 fprintf (dump, "Done finish_sched\n");
14494 }
14495 }
14496}
b6c9286a 14497\f
b6c9286a
MM
14498/* Length in units of the trampoline for entering a nested function. */
14499
14500int
863d938c 14501rs6000_trampoline_size (void)
b6c9286a
MM
14502{
14503 int ret = 0;
14504
14505 switch (DEFAULT_ABI)
14506 {
14507 default:
14508 abort ();
14509
14510 case ABI_AIX:
8f802bfb 14511 ret = (TARGET_32BIT) ? 12 : 24;
b6c9286a
MM
14512 break;
14513
4dabc42d 14514 case ABI_DARWIN:
b6c9286a 14515 case ABI_V4:
03a7e1a5 14516 ret = (TARGET_32BIT) ? 40 : 48;
b6c9286a 14517 break;
b6c9286a
MM
14518 }
14519
14520 return ret;
14521}
14522
14523/* Emit RTL insns to initialize the variable parts of a trampoline.
14524 FNADDR is an RTX for the address of the function's pure code.
14525 CXT is an RTX for the static chain value for the function. */
14526
14527void
a2369ed3 14528rs6000_initialize_trampoline (rtx addr, rtx fnaddr, rtx cxt)
b6c9286a 14529{
ac2a93a1 14530 enum machine_mode pmode = Pmode;
8bd04c56
MM
14531 int regsize = (TARGET_32BIT) ? 4 : 8;
14532 rtx ctx_reg = force_reg (pmode, cxt);
b6c9286a
MM
14533
14534 switch (DEFAULT_ABI)
14535 {
14536 default:
14537 abort ();
14538
8bd04c56 14539/* Macros to shorten the code expansions below. */
39403d82 14540#define MEM_DEREF(addr) gen_rtx_MEM (pmode, memory_address (pmode, addr))
c5c76735
JL
14541#define MEM_PLUS(addr,offset) \
14542 gen_rtx_MEM (pmode, memory_address (pmode, plus_constant (addr, offset)))
7c59dc5d 14543
b6c9286a
MM
14544 /* Under AIX, just build the 3 word function descriptor */
14545 case ABI_AIX:
8bd04c56
MM
14546 {
14547 rtx fn_reg = gen_reg_rtx (pmode);
14548 rtx toc_reg = gen_reg_rtx (pmode);
14549 emit_move_insn (fn_reg, MEM_DEREF (fnaddr));
1cb18e3c 14550 emit_move_insn (toc_reg, MEM_PLUS (fnaddr, regsize));
8bd04c56
MM
14551 emit_move_insn (MEM_DEREF (addr), fn_reg);
14552 emit_move_insn (MEM_PLUS (addr, regsize), toc_reg);
14553 emit_move_insn (MEM_PLUS (addr, 2*regsize), ctx_reg);
14554 }
b6c9286a
MM
14555 break;
14556
4dabc42d
TC
14557 /* Under V.4/eabi/darwin, __trampoline_setup does the real work. */
14558 case ABI_DARWIN:
b6c9286a 14559 case ABI_V4:
39403d82 14560 emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"),
eaf1bcf1
MM
14561 FALSE, VOIDmode, 4,
14562 addr, pmode,
14563 GEN_INT (rs6000_trampoline_size ()), SImode,
14564 fnaddr, pmode,
14565 ctx_reg, pmode);
b6c9286a 14566 break;
b6c9286a
MM
14567 }
14568
14569 return;
14570}
7509c759
MM
14571
14572\f
91d231cb 14573/* Table of valid machine attributes. */
a4f6c312 14574
91d231cb 14575const struct attribute_spec rs6000_attribute_table[] =
7509c759 14576{
91d231cb 14577 /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
a5c76ee6
ZW
14578 { "longcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14579 { "shortcall", 0, 0, false, true, true, rs6000_handle_longcall_attribute },
14580 { NULL, 0, 0, false, false, false, NULL }
91d231cb 14581};
7509c759 14582
a5c76ee6
ZW
14583/* Handle a "longcall" or "shortcall" attribute; arguments as in
14584 struct attribute_spec.handler. */
a4f6c312 14585
91d231cb 14586static tree
a2369ed3
DJ
14587rs6000_handle_longcall_attribute (tree *node, tree name,
14588 tree args ATTRIBUTE_UNUSED,
14589 int flags ATTRIBUTE_UNUSED,
14590 bool *no_add_attrs)
91d231cb
JM
14591{
14592 if (TREE_CODE (*node) != FUNCTION_TYPE
14593 && TREE_CODE (*node) != FIELD_DECL
14594 && TREE_CODE (*node) != TYPE_DECL)
14595 {
14596 warning ("`%s' attribute only applies to functions",
14597 IDENTIFIER_POINTER (name));
14598 *no_add_attrs = true;
14599 }
6a4cee5f 14600
91d231cb 14601 return NULL_TREE;
7509c759
MM
14602}
14603
a5c76ee6
ZW
14604/* Set longcall attributes on all functions declared when
14605 rs6000_default_long_calls is true. */
14606static void
a2369ed3 14607rs6000_set_default_type_attributes (tree type)
a5c76ee6
ZW
14608{
14609 if (rs6000_default_long_calls
14610 && (TREE_CODE (type) == FUNCTION_TYPE
14611 || TREE_CODE (type) == METHOD_TYPE))
14612 TYPE_ATTRIBUTES (type) = tree_cons (get_identifier ("longcall"),
14613 NULL_TREE,
14614 TYPE_ATTRIBUTES (type));
14615}
14616
3cb999d8
DE
14617/* Return a reference suitable for calling a function with the
14618 longcall attribute. */
a4f6c312 14619
6a4cee5f 14620struct rtx_def *
a2369ed3 14621rs6000_longcall_ref (rtx call_ref)
6a4cee5f 14622{
d330fd93 14623 const char *call_name;
6a4cee5f
MM
14624 tree node;
14625
14626 if (GET_CODE (call_ref) != SYMBOL_REF)
14627 return call_ref;
14628
14629 /* System V adds '.' to the internal name, so skip them. */
14630 call_name = XSTR (call_ref, 0);
14631 if (*call_name == '.')
14632 {
14633 while (*call_name == '.')
14634 call_name++;
14635
14636 node = get_identifier (call_name);
39403d82 14637 call_ref = gen_rtx_SYMBOL_REF (VOIDmode, IDENTIFIER_POINTER (node));
6a4cee5f
MM
14638 }
14639
14640 return force_reg (Pmode, call_ref);
14641}
7509c759 14642\f
b64a1b53
RH
14643#ifdef USING_ELFOS_H
14644
7509c759
MM
14645/* A C statement or statements to switch to the appropriate section
14646 for output of RTX in mode MODE. You can assume that RTX is some
14647 kind of constant in RTL. The argument MODE is redundant except in
14648 the case of a `const_int' rtx. Select the section by calling
14649 `text_section' or one of the alternatives for other sections.
14650
14651 Do not define this macro if you put all constants in the read-only
14652 data section. */
14653
b64a1b53 14654static void
a2369ed3
DJ
14655rs6000_elf_select_rtx_section (enum machine_mode mode, rtx x,
14656 unsigned HOST_WIDE_INT align)
7509c759 14657{
a9098fd0 14658 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
7509c759 14659 toc_section ();
7509c759 14660 else
b64a1b53 14661 default_elf_select_rtx_section (mode, x, align);
7509c759
MM
14662}
14663
14664/* A C statement or statements to switch to the appropriate
14665 section for output of DECL. DECL is either a `VAR_DECL' node
14666 or a constant of some sort. RELOC indicates whether forming
14667 the initial value of DECL requires link-time relocations. */
14668
ae46c4e0 14669static void
a2369ed3
DJ
14670rs6000_elf_select_section (tree decl, int reloc,
14671 unsigned HOST_WIDE_INT align)
7509c759 14672{
f1384257
AM
14673 /* Pretend that we're always building for a shared library when
14674 ABI_AIX, because otherwise we end up with dynamic relocations
14675 in read-only sections. This happens for function pointers,
14676 references to vtables in typeinfo, and probably other cases. */
0e5dbd9b
DE
14677 default_elf_select_section_1 (decl, reloc, align,
14678 flag_pic || DEFAULT_ABI == ABI_AIX);
63019373
GK
14679}
14680
14681/* A C statement to build up a unique section name, expressed as a
14682 STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
14683 RELOC indicates whether the initial value of EXP requires
14684 link-time relocations. If you do not define this macro, GCC will use
14685 the symbol name prefixed by `.' as the section name. Note - this
f5143c46 14686 macro can now be called for uninitialized data items as well as
4912a07c 14687 initialized data and functions. */
63019373 14688
ae46c4e0 14689static void
a2369ed3 14690rs6000_elf_unique_section (tree decl, int reloc)
63019373 14691{
f1384257
AM
14692 /* As above, pretend that we're always building for a shared library
14693 when ABI_AIX, to avoid dynamic relocations in read-only sections. */
0e5dbd9b
DE
14694 default_unique_section_1 (decl, reloc,
14695 flag_pic || DEFAULT_ABI == ABI_AIX);
7509c759 14696}
d9407988 14697\f
d1908feb
JJ
14698/* For a SYMBOL_REF, set generic flags and then perform some
14699 target-specific processing.
14700
d1908feb
JJ
14701 When the AIX ABI is requested on a non-AIX system, replace the
14702 function name with the real name (with a leading .) rather than the
14703 function descriptor name. This saves a lot of overriding code to
14704 read the prefixes. */
d9407988 14705
fb49053f 14706static void
a2369ed3 14707rs6000_elf_encode_section_info (tree decl, rtx rtl, int first)
d9407988 14708{
d1908feb 14709 default_encode_section_info (decl, rtl, first);
b2003250 14710
d1908feb
JJ
14711 if (first
14712 && TREE_CODE (decl) == FUNCTION_DECL
14713 && !TARGET_AIX
14714 && DEFAULT_ABI == ABI_AIX)
d9407988 14715 {
c6a2438a 14716 rtx sym_ref = XEXP (rtl, 0);
d1908feb
JJ
14717 size_t len = strlen (XSTR (sym_ref, 0));
14718 char *str = alloca (len + 2);
14719 str[0] = '.';
14720 memcpy (str + 1, XSTR (sym_ref, 0), len + 1);
14721 XSTR (sym_ref, 0) = ggc_alloc_string (str, len + 1);
d9407988 14722 }
d9407988
MM
14723}
14724
0e5dbd9b 14725static bool
a2369ed3 14726rs6000_elf_in_small_data_p (tree decl)
0e5dbd9b
DE
14727{
14728 if (rs6000_sdata == SDATA_NONE)
14729 return false;
14730
14731 if (TREE_CODE (decl) == VAR_DECL && DECL_SECTION_NAME (decl))
14732 {
14733 const char *section = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
14734 if (strcmp (section, ".sdata") == 0
14735 || strcmp (section, ".sdata2") == 0
20bfcd69
GK
14736 || strcmp (section, ".sbss") == 0
14737 || strcmp (section, ".sbss2") == 0
14738 || strcmp (section, ".PPC.EMB.sdata0") == 0
14739 || strcmp (section, ".PPC.EMB.sbss0") == 0)
0e5dbd9b
DE
14740 return true;
14741 }
14742 else
14743 {
14744 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
14745
14746 if (size > 0
307b599c 14747 && (unsigned HOST_WIDE_INT) size <= g_switch_value
20bfcd69
GK
14748 /* If it's not public, and we're not going to reference it there,
14749 there's no need to put it in the small data section. */
0e5dbd9b
DE
14750 && (rs6000_sdata != SDATA_DATA || TREE_PUBLIC (decl)))
14751 return true;
14752 }
14753
14754 return false;
14755}
14756
b91da81f 14757#endif /* USING_ELFOS_H */
000034eb 14758
a6c2a102 14759\f
000034eb 14760/* Return a REG that occurs in ADDR with coefficient 1.
02441cd6
JL
14761 ADDR can be effectively incremented by incrementing REG.
14762
14763 r0 is special and we must not select it as an address
14764 register by this routine since our caller will try to
14765 increment the returned register via an "la" instruction. */
000034eb
DE
14766
14767struct rtx_def *
a2369ed3 14768find_addr_reg (rtx addr)
000034eb
DE
14769{
14770 while (GET_CODE (addr) == PLUS)
14771 {
02441cd6
JL
14772 if (GET_CODE (XEXP (addr, 0)) == REG
14773 && REGNO (XEXP (addr, 0)) != 0)
000034eb 14774 addr = XEXP (addr, 0);
02441cd6
JL
14775 else if (GET_CODE (XEXP (addr, 1)) == REG
14776 && REGNO (XEXP (addr, 1)) != 0)
000034eb
DE
14777 addr = XEXP (addr, 1);
14778 else if (CONSTANT_P (XEXP (addr, 0)))
14779 addr = XEXP (addr, 1);
14780 else if (CONSTANT_P (XEXP (addr, 1)))
14781 addr = XEXP (addr, 0);
14782 else
14783 abort ();
14784 }
02441cd6 14785 if (GET_CODE (addr) == REG && REGNO (addr) != 0)
000034eb
DE
14786 return addr;
14787 abort ();
14788}
14789
a6c2a102 14790void
a2369ed3 14791rs6000_fatal_bad_address (rtx op)
a6c2a102
DE
14792{
14793 fatal_insn ("bad address", op);
14794}
c8023011 14795
ee890fe2
SS
14796#if TARGET_MACHO
14797
14798#if 0
14799/* Returns 1 if OP is either a symbol reference or a sum of a symbol
14800 reference and a constant. */
14801
14802int
a2369ed3 14803symbolic_operand (rtx op)
ee890fe2
SS
14804{
14805 switch (GET_CODE (op))
14806 {
14807 case SYMBOL_REF:
14808 case LABEL_REF:
14809 return 1;
14810 case CONST:
14811 op = XEXP (op, 0);
14812 return (GET_CODE (op) == SYMBOL_REF ||
14813 (GET_CODE (XEXP (op, 0)) == SYMBOL_REF
14814 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
14815 && GET_CODE (XEXP (op, 1)) == CONST_INT);
14816 default:
14817 return 0;
14818 }
c8023011 14819}
ee890fe2
SS
14820#endif
14821
efdba735 14822#if TARGET_MACHO
ee890fe2 14823
efdba735 14824static tree branch_island_list = 0;
ee890fe2 14825
efdba735
SH
14826/* Remember to generate a branch island for far calls to the given
14827 function. */
ee890fe2 14828
efdba735
SH
14829static void
14830add_compiler_branch_island (tree label_name, tree function_name, int line_number)
ee890fe2 14831{
efdba735
SH
14832 tree branch_island = build_tree_list (function_name, label_name);
14833 TREE_TYPE (branch_island) = build_int_2 (line_number, 0);
14834 TREE_CHAIN (branch_island) = branch_island_list;
14835 branch_island_list = branch_island;
ee890fe2
SS
14836}
14837
efdba735
SH
14838#define BRANCH_ISLAND_LABEL_NAME(BRANCH_ISLAND) TREE_VALUE (BRANCH_ISLAND)
14839#define BRANCH_ISLAND_FUNCTION_NAME(BRANCH_ISLAND) TREE_PURPOSE (BRANCH_ISLAND)
14840#define BRANCH_ISLAND_LINE_NUMBER(BRANCH_ISLAND) \
14841 TREE_INT_CST_LOW (TREE_TYPE (BRANCH_ISLAND))
ee890fe2 14842
efdba735
SH
14843/* Generate far-jump branch islands for everything on the
14844 branch_island_list. Invoked immediately after the last instruction
14845 of the epilogue has been emitted; the branch-islands must be
14846 appended to, and contiguous with, the function body. Mach-O stubs
14847 are generated in machopic_output_stub(). */
ee890fe2 14848
efdba735
SH
14849static void
14850macho_branch_islands (void)
14851{
14852 char tmp_buf[512];
14853 tree branch_island;
14854
14855 for (branch_island = branch_island_list;
14856 branch_island;
14857 branch_island = TREE_CHAIN (branch_island))
14858 {
14859 const char *label =
14860 IDENTIFIER_POINTER (BRANCH_ISLAND_LABEL_NAME (branch_island));
14861 const char *name =
14862 darwin_strip_name_encoding (
14863 IDENTIFIER_POINTER (BRANCH_ISLAND_FUNCTION_NAME (branch_island)));
14864 char name_buf[512];
14865 /* Cheap copy of the details from the Darwin ASM_OUTPUT_LABELREF(). */
14866 if (name[0] == '*' || name[0] == '&')
14867 strcpy (name_buf, name+1);
14868 else
14869 {
14870 name_buf[0] = '_';
14871 strcpy (name_buf+1, name);
14872 }
14873 strcpy (tmp_buf, "\n");
14874 strcat (tmp_buf, label);
ee890fe2 14875#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 14876 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 14877 fprintf (asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 14878 BRANCH_ISLAND_LINE_NUMBER(branch_island));
ee890fe2 14879#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735
SH
14880 if (flag_pic)
14881 {
14882 strcat (tmp_buf, ":\n\tmflr r0\n\tbcl 20,31,");
14883 strcat (tmp_buf, label);
14884 strcat (tmp_buf, "_pic\n");
14885 strcat (tmp_buf, label);
14886 strcat (tmp_buf, "_pic:\n\tmflr r11\n");
14887
14888 strcat (tmp_buf, "\taddis r11,r11,ha16(");
14889 strcat (tmp_buf, name_buf);
14890 strcat (tmp_buf, " - ");
14891 strcat (tmp_buf, label);
14892 strcat (tmp_buf, "_pic)\n");
14893
14894 strcat (tmp_buf, "\tmtlr r0\n");
14895
14896 strcat (tmp_buf, "\taddi r12,r11,lo16(");
14897 strcat (tmp_buf, name_buf);
14898 strcat (tmp_buf, " - ");
14899 strcat (tmp_buf, label);
14900 strcat (tmp_buf, "_pic)\n");
14901
14902 strcat (tmp_buf, "\tmtctr r12\n\tbctr\n");
14903 }
14904 else
14905 {
14906 strcat (tmp_buf, ":\nlis r12,hi16(");
14907 strcat (tmp_buf, name_buf);
14908 strcat (tmp_buf, ")\n\tori r12,r12,lo16(");
14909 strcat (tmp_buf, name_buf);
14910 strcat (tmp_buf, ")\n\tmtctr r12\n\tbctr");
14911 }
14912 output_asm_insn (tmp_buf, 0);
ee890fe2 14913#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
efdba735 14914 if (write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
f7efd730 14915 fprintf(asm_out_file, "\t.stabd 68,0," HOST_WIDE_INT_PRINT_UNSIGNED "\n",
efdba735 14916 BRANCH_ISLAND_LINE_NUMBER (branch_island));
ee890fe2 14917#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
efdba735 14918 }
ee890fe2 14919
efdba735 14920 branch_island_list = 0;
ee890fe2
SS
14921}
14922
14923/* NO_PREVIOUS_DEF checks in the link list whether the function name is
14924 already there or not. */
14925
efdba735 14926static int
a2369ed3 14927no_previous_def (tree function_name)
ee890fe2 14928{
efdba735
SH
14929 tree branch_island;
14930 for (branch_island = branch_island_list;
14931 branch_island;
14932 branch_island = TREE_CHAIN (branch_island))
14933 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
ee890fe2
SS
14934 return 0;
14935 return 1;
14936}
14937
14938/* GET_PREV_LABEL gets the label name from the previous definition of
14939 the function. */
14940
efdba735 14941static tree
a2369ed3 14942get_prev_label (tree function_name)
ee890fe2 14943{
efdba735
SH
14944 tree branch_island;
14945 for (branch_island = branch_island_list;
14946 branch_island;
14947 branch_island = TREE_CHAIN (branch_island))
14948 if (function_name == BRANCH_ISLAND_FUNCTION_NAME (branch_island))
14949 return BRANCH_ISLAND_LABEL_NAME (branch_island);
ee890fe2
SS
14950 return 0;
14951}
14952
14953/* INSN is either a function call or a millicode call. It may have an
14954 unconditional jump in its delay slot.
14955
14956 CALL_DEST is the routine we are calling. */
14957
14958char *
efdba735 14959output_call (rtx insn, rtx *operands, int dest_operand_number, int cookie_operand_number)
ee890fe2
SS
14960{
14961 static char buf[256];
efdba735
SH
14962 if (GET_CODE (operands[dest_operand_number]) == SYMBOL_REF
14963 && (INTVAL (operands[cookie_operand_number]) & CALL_LONG))
ee890fe2
SS
14964 {
14965 tree labelname;
efdba735 14966 tree funname = get_identifier (XSTR (operands[dest_operand_number], 0));
ee890fe2
SS
14967
14968 if (no_previous_def (funname))
14969 {
308c142a 14970 int line_number = 0;
ee890fe2
SS
14971 rtx label_rtx = gen_label_rtx ();
14972 char *label_buf, temp_buf[256];
14973 ASM_GENERATE_INTERNAL_LABEL (temp_buf, "L",
14974 CODE_LABEL_NUMBER (label_rtx));
14975 label_buf = temp_buf[0] == '*' ? temp_buf + 1 : temp_buf;
14976 labelname = get_identifier (label_buf);
14977 for (; insn && GET_CODE (insn) != NOTE; insn = PREV_INSN (insn));
14978 if (insn)
14979 line_number = NOTE_LINE_NUMBER (insn);
efdba735 14980 add_compiler_branch_island (labelname, funname, line_number);
ee890fe2
SS
14981 }
14982 else
14983 labelname = get_prev_label (funname);
14984
efdba735
SH
14985 /* "jbsr foo, L42" is Mach-O for "Link as 'bl foo' if a 'bl'
14986 instruction will reach 'foo', otherwise link as 'bl L42'".
14987 "L42" should be a 'branch island', that will do a far jump to
14988 'foo'. Branch islands are generated in
14989 macho_branch_islands(). */
ee890fe2 14990 sprintf (buf, "jbsr %%z%d,%.246s",
efdba735 14991 dest_operand_number, IDENTIFIER_POINTER (labelname));
ee890fe2
SS
14992 }
14993 else
efdba735
SH
14994 sprintf (buf, "bl %%z%d", dest_operand_number);
14995 return buf;
ee890fe2
SS
14996}
14997
efdba735 14998#endif /* TARGET_MACHO */
ee890fe2 14999
ee890fe2
SS
15000/* Generate PIC and indirect symbol stubs. */
15001
15002void
a2369ed3 15003machopic_output_stub (FILE *file, const char *symb, const char *stub)
ee890fe2
SS
15004{
15005 unsigned int length;
a4f6c312
SS
15006 char *symbol_name, *lazy_ptr_name;
15007 char *local_label_0;
ee890fe2
SS
15008 static int label = 0;
15009
df56a27f 15010 /* Lose our funky encoding stuff so it doesn't contaminate the stub. */
772c5265 15011 symb = (*targetm.strip_name_encoding) (symb);
df56a27f 15012
ee890fe2 15013
ee890fe2
SS
15014 length = strlen (symb);
15015 symbol_name = alloca (length + 32);
15016 GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
15017
15018 lazy_ptr_name = alloca (length + 32);
15019 GEN_LAZY_PTR_NAME_FOR_SYMBOL (lazy_ptr_name, symb, length);
15020
ee890fe2 15021 if (flag_pic == 2)
d3c300d2 15022 machopic_picsymbol_stub1_section ();
ee890fe2 15023 else
d3c300d2
DJ
15024 machopic_symbol_stub1_section ();
15025 fprintf (file, "\t.align 2\n");
ee890fe2
SS
15026
15027 fprintf (file, "%s:\n", stub);
15028 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15029
15030 if (flag_pic == 2)
15031 {
876455fa
AP
15032 label++;
15033 local_label_0 = alloca (sizeof("\"L0000000000$spb\""));
15034 sprintf (local_label_0, "\"L%011d$spb\"", label);
15035
ee890fe2
SS
15036 fprintf (file, "\tmflr r0\n");
15037 fprintf (file, "\tbcl 20,31,%s\n", local_label_0);
15038 fprintf (file, "%s:\n\tmflr r11\n", local_label_0);
15039 fprintf (file, "\taddis r11,r11,ha16(%s-%s)\n",
15040 lazy_ptr_name, local_label_0);
15041 fprintf (file, "\tmtlr r0\n");
d3c300d2 15042 fprintf (file, "\tlwzu r12,lo16(%s-%s)(r11)\n",
ee890fe2
SS
15043 lazy_ptr_name, local_label_0);
15044 fprintf (file, "\tmtctr r12\n");
ee890fe2
SS
15045 fprintf (file, "\tbctr\n");
15046 }
15047 else
ab82a49f
AP
15048 {
15049 fprintf (file, "\tlis r11,ha16(%s)\n", lazy_ptr_name);
15050 fprintf (file, "\tlwzu r12,lo16(%s)(r11)\n", lazy_ptr_name);
15051 fprintf (file, "\tmtctr r12\n");
15052 fprintf (file, "\tbctr\n");
15053 }
ee890fe2
SS
15054
15055 machopic_lazy_symbol_ptr_section ();
15056 fprintf (file, "%s:\n", lazy_ptr_name);
15057 fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
15058 fprintf (file, "\t.long dyld_stub_binding_helper\n");
15059}
15060
15061/* Legitimize PIC addresses. If the address is already
15062 position-independent, we return ORIG. Newly generated
15063 position-independent addresses go into a reg. This is REG if non
15064 zero, otherwise we allocate register(s) as necessary. */
15065
c859cda6 15066#define SMALL_INT(X) ((unsigned) (INTVAL(X) + 0x8000) < 0x10000)
ee890fe2
SS
15067
15068rtx
a2369ed3
DJ
15069rs6000_machopic_legitimize_pic_address (rtx orig, enum machine_mode mode,
15070 rtx reg)
ee890fe2
SS
15071{
15072 rtx base, offset;
15073
15074 if (reg == NULL && ! reload_in_progress && ! reload_completed)
15075 reg = gen_reg_rtx (Pmode);
15076
15077 if (GET_CODE (orig) == CONST)
15078 {
15079 if (GET_CODE (XEXP (orig, 0)) == PLUS
15080 && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx)
15081 return orig;
15082
15083 if (GET_CODE (XEXP (orig, 0)) == PLUS)
15084 {
2cf520bf 15085 /* Use a different reg for the intermediate value, as
a3c9585f 15086 it will be marked UNCHANGING. */
2cf520bf
GK
15087 rtx reg_temp = no_new_pseudos ? reg : gen_reg_rtx (Pmode);
15088
a4f6c312
SS
15089 base =
15090 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 0),
2cf520bf 15091 Pmode, reg_temp);
a4f6c312
SS
15092 offset =
15093 rs6000_machopic_legitimize_pic_address (XEXP (XEXP (orig, 0), 1),
15094 Pmode, reg);
ee890fe2
SS
15095 }
15096 else
15097 abort ();
15098
15099 if (GET_CODE (offset) == CONST_INT)
15100 {
15101 if (SMALL_INT (offset))
ed8908e7 15102 return plus_constant (base, INTVAL (offset));
ee890fe2
SS
15103 else if (! reload_in_progress && ! reload_completed)
15104 offset = force_reg (Pmode, offset);
15105 else
c859cda6
DJ
15106 {
15107 rtx mem = force_const_mem (Pmode, orig);
15108 return machopic_legitimize_pic_address (mem, Pmode, reg);
15109 }
ee890fe2 15110 }
f1c25d3b 15111 return gen_rtx_PLUS (Pmode, base, offset);
ee890fe2
SS
15112 }
15113
15114 /* Fall back on generic machopic code. */
15115 return machopic_legitimize_pic_address (orig, mode, reg);
15116}
15117
15118/* This is just a placeholder to make linking work without having to
15119 add this to the generic Darwin EXTRA_SECTIONS. If -mcall-aix is
15120 ever needed for Darwin (not too likely!) this would have to get a
15121 real definition. */
15122
15123void
863d938c 15124toc_section (void)
ee890fe2
SS
15125{
15126}
15127
15128#endif /* TARGET_MACHO */
7c262518
RH
15129
15130#if TARGET_ELF
15131static unsigned int
a2369ed3 15132rs6000_elf_section_type_flags (tree decl, const char *name, int reloc)
7c262518 15133{
1ff8f81a
AM
15134 return default_section_type_flags_1 (decl, name, reloc,
15135 flag_pic || DEFAULT_ABI == ABI_AIX);
7c262518 15136}
d9f6800d
RH
15137
15138/* Record an element in the table of global constructors. SYMBOL is
15139 a SYMBOL_REF of the function to be called; PRIORITY is a number
15140 between 0 and MAX_INIT_PRIORITY.
15141
15142 This differs from default_named_section_asm_out_constructor in
15143 that we have special handling for -mrelocatable. */
15144
15145static void
a2369ed3 15146rs6000_elf_asm_out_constructor (rtx symbol, int priority)
d9f6800d
RH
15147{
15148 const char *section = ".ctors";
15149 char buf[16];
15150
15151 if (priority != DEFAULT_INIT_PRIORITY)
15152 {
15153 sprintf (buf, ".ctors.%.5u",
15154 /* Invert the numbering so the linker puts us in the proper
15155 order; constructors are run from right to left, and the
15156 linker sorts in increasing order. */
15157 MAX_INIT_PRIORITY - priority);
15158 section = buf;
15159 }
15160
715bdd29
RH
15161 named_section_flags (section, SECTION_WRITE);
15162 assemble_align (POINTER_SIZE);
d9f6800d
RH
15163
15164 if (TARGET_RELOCATABLE)
15165 {
15166 fputs ("\t.long (", asm_out_file);
15167 output_addr_const (asm_out_file, symbol);
15168 fputs (")@fixup\n", asm_out_file);
15169 }
15170 else
c8af3574 15171 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d
RH
15172}
15173
15174static void
a2369ed3 15175rs6000_elf_asm_out_destructor (rtx symbol, int priority)
d9f6800d
RH
15176{
15177 const char *section = ".dtors";
15178 char buf[16];
15179
15180 if (priority != DEFAULT_INIT_PRIORITY)
15181 {
15182 sprintf (buf, ".dtors.%.5u",
15183 /* Invert the numbering so the linker puts us in the proper
15184 order; constructors are run from right to left, and the
15185 linker sorts in increasing order. */
15186 MAX_INIT_PRIORITY - priority);
15187 section = buf;
15188 }
15189
715bdd29
RH
15190 named_section_flags (section, SECTION_WRITE);
15191 assemble_align (POINTER_SIZE);
d9f6800d
RH
15192
15193 if (TARGET_RELOCATABLE)
15194 {
15195 fputs ("\t.long (", asm_out_file);
15196 output_addr_const (asm_out_file, symbol);
15197 fputs (")@fixup\n", asm_out_file);
15198 }
15199 else
c8af3574 15200 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
d9f6800d 15201}
9739c90c
JJ
15202
15203void
a2369ed3 15204rs6000_elf_declare_function_name (FILE *file, const char *name, tree decl)
9739c90c
JJ
15205{
15206 if (TARGET_64BIT)
15207 {
15208 fputs ("\t.section\t\".opd\",\"aw\"\n\t.align 3\n", file);
15209 ASM_OUTPUT_LABEL (file, name);
15210 fputs (DOUBLE_INT_ASM_OP, file);
15211 putc ('.', file);
15212 assemble_name (file, name);
15213 fputs (",.TOC.@tocbase,0\n\t.previous\n\t.size\t", file);
15214 assemble_name (file, name);
15215 fputs (",24\n\t.type\t.", file);
15216 assemble_name (file, name);
15217 fputs (",@function\n", file);
15218 if (TREE_PUBLIC (decl) && ! DECL_WEAK (decl))
15219 {
15220 fputs ("\t.globl\t.", file);
15221 assemble_name (file, name);
15222 putc ('\n', file);
15223 }
15224 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15225 putc ('.', file);
15226 ASM_OUTPUT_LABEL (file, name);
15227 return;
15228 }
15229
15230 if (TARGET_RELOCATABLE
15231 && (get_pool_size () != 0 || current_function_profile)
3c9eb5f4 15232 && uses_TOC ())
9739c90c
JJ
15233 {
15234 char buf[256];
15235
15236 (*targetm.asm_out.internal_label) (file, "LCL", rs6000_pic_labelno);
15237
15238 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
15239 fprintf (file, "\t.long ");
15240 assemble_name (file, buf);
15241 putc ('-', file);
15242 ASM_GENERATE_INTERNAL_LABEL (buf, "LCF", rs6000_pic_labelno);
15243 assemble_name (file, buf);
15244 putc ('\n', file);
15245 }
15246
15247 ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
15248 ASM_DECLARE_RESULT (file, DECL_RESULT (decl));
15249
15250 if (DEFAULT_ABI == ABI_AIX)
15251 {
15252 const char *desc_name, *orig_name;
15253
15254 orig_name = (*targetm.strip_name_encoding) (name);
15255 desc_name = orig_name;
15256 while (*desc_name == '.')
15257 desc_name++;
15258
15259 if (TREE_PUBLIC (decl))
15260 fprintf (file, "\t.globl %s\n", desc_name);
15261
15262 fprintf (file, "%s\n", MINIMAL_TOC_SECTION_ASM_OP);
15263 fprintf (file, "%s:\n", desc_name);
15264 fprintf (file, "\t.long %s\n", orig_name);
15265 fputs ("\t.long _GLOBAL_OFFSET_TABLE_\n", file);
15266 if (DEFAULT_ABI == ABI_AIX)
15267 fputs ("\t.long 0\n", file);
15268 fprintf (file, "\t.previous\n");
15269 }
15270 ASM_OUTPUT_LABEL (file, name);
15271}
7c262518
RH
15272#endif
15273
cbaaba19 15274#if TARGET_XCOFF
7c262518 15275static void
a2369ed3 15276rs6000_xcoff_asm_globalize_label (FILE *stream, const char *name)
b275d088
DE
15277{
15278 fputs (GLOBAL_ASM_OP, stream);
15279 RS6000_OUTPUT_BASENAME (stream, name);
15280 putc ('\n', stream);
15281}
15282
15283static void
a2369ed3 15284rs6000_xcoff_asm_named_section (const char *name, unsigned int flags)
7c262518 15285{
0e5dbd9b
DE
15286 int smclass;
15287 static const char * const suffix[3] = { "PR", "RO", "RW" };
15288
15289 if (flags & SECTION_CODE)
15290 smclass = 0;
15291 else if (flags & SECTION_WRITE)
15292 smclass = 2;
15293 else
15294 smclass = 1;
15295
5b5198f7 15296 fprintf (asm_out_file, "\t.csect %s%s[%s],%u\n",
0e5dbd9b 15297 (flags & SECTION_CODE) ? "." : "",
5b5198f7 15298 name, suffix[smclass], flags & SECTION_ENTSIZE);
7c262518 15299}
ae46c4e0
RH
15300
15301static void
a2369ed3
DJ
15302rs6000_xcoff_select_section (tree decl, int reloc,
15303 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
ae46c4e0 15304{
5add3202 15305 if (decl_readonly_section_1 (decl, reloc, 1))
ae46c4e0 15306 {
0e5dbd9b 15307 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15308 read_only_data_section ();
15309 else
15310 read_only_private_data_section ();
15311 }
15312 else
15313 {
0e5dbd9b 15314 if (TREE_PUBLIC (decl))
ae46c4e0
RH
15315 data_section ();
15316 else
15317 private_data_section ();
15318 }
15319}
15320
15321static void
a2369ed3 15322rs6000_xcoff_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
ae46c4e0
RH
15323{
15324 const char *name;
ae46c4e0 15325
5b5198f7
DE
15326 /* Use select_section for private and uninitialized data. */
15327 if (!TREE_PUBLIC (decl)
15328 || DECL_COMMON (decl)
0e5dbd9b
DE
15329 || DECL_INITIAL (decl) == NULL_TREE
15330 || DECL_INITIAL (decl) == error_mark_node
15331 || (flag_zero_initialized_in_bss
15332 && initializer_zerop (DECL_INITIAL (decl))))
15333 return;
15334
15335 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
15336 name = (*targetm.strip_name_encoding) (name);
15337 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
ae46c4e0 15338}
b64a1b53 15339
fb49053f
RH
15340/* Select section for constant in constant pool.
15341
15342 On RS/6000, all constants are in the private read-only data area.
15343 However, if this is being placed in the TOC it must be output as a
15344 toc entry. */
15345
b64a1b53 15346static void
a2369ed3
DJ
15347rs6000_xcoff_select_rtx_section (enum machine_mode mode, rtx x,
15348 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
b64a1b53
RH
15349{
15350 if (ASM_OUTPUT_SPECIAL_POOL_ENTRY_P (x, mode))
15351 toc_section ();
15352 else
15353 read_only_private_data_section ();
15354}
772c5265
RH
15355
15356/* Remove any trailing [DS] or the like from the symbol name. */
15357
15358static const char *
a2369ed3 15359rs6000_xcoff_strip_name_encoding (const char *name)
772c5265
RH
15360{
15361 size_t len;
15362 if (*name == '*')
15363 name++;
15364 len = strlen (name);
15365 if (name[len - 1] == ']')
15366 return ggc_alloc_string (name, len - 4);
15367 else
15368 return name;
15369}
15370
5add3202
DE
15371/* Section attributes. AIX is always PIC. */
15372
15373static unsigned int
a2369ed3 15374rs6000_xcoff_section_type_flags (tree decl, const char *name, int reloc)
5add3202 15375{
5b5198f7
DE
15376 unsigned int align;
15377 unsigned int flags = default_section_type_flags_1 (decl, name, reloc, 1);
15378
15379 /* Align to at least UNIT size. */
15380 if (flags & SECTION_CODE)
15381 align = MIN_UNITS_PER_WORD;
15382 else
15383 /* Increase alignment of large objects if not already stricter. */
15384 align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
15385 int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
15386 ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
15387
15388 return flags | (exact_log2 (align) & SECTION_ENTSIZE);
5add3202 15389}
a5fe455b 15390
1bc7c5b6
ZW
15391/* Output at beginning of assembler file.
15392
15393 Initialize the section names for the RS/6000 at this point.
15394
15395 Specify filename, including full path, to assembler.
15396
15397 We want to go into the TOC section so at least one .toc will be emitted.
15398 Also, in order to output proper .bs/.es pairs, we need at least one static
15399 [RW] section emitted.
15400
15401 Finally, declare mcount when profiling to make the assembler happy. */
15402
15403static void
863d938c 15404rs6000_xcoff_file_start (void)
1bc7c5b6
ZW
15405{
15406 rs6000_gen_section_name (&xcoff_bss_section_name,
15407 main_input_filename, ".bss_");
15408 rs6000_gen_section_name (&xcoff_private_data_section_name,
15409 main_input_filename, ".rw_");
15410 rs6000_gen_section_name (&xcoff_read_only_section_name,
15411 main_input_filename, ".ro_");
15412
15413 fputs ("\t.file\t", asm_out_file);
15414 output_quoted_string (asm_out_file, main_input_filename);
15415 fputc ('\n', asm_out_file);
15416 toc_section ();
15417 if (write_symbols != NO_DEBUG)
15418 private_data_section ();
15419 text_section ();
15420 if (profile_flag)
15421 fprintf (asm_out_file, "\t.extern %s\n", RS6000_MCOUNT);
15422 rs6000_file_start ();
15423}
15424
a5fe455b
ZW
15425/* Output at end of assembler file.
15426 On the RS/6000, referencing data should automatically pull in text. */
15427
15428static void
863d938c 15429rs6000_xcoff_file_end (void)
a5fe455b
ZW
15430{
15431 text_section ();
15432 fputs ("_section_.text:\n", asm_out_file);
15433 data_section ();
15434 fputs (TARGET_32BIT
15435 ? "\t.long _section_.text\n" : "\t.llong _section_.text\n",
15436 asm_out_file);
15437}
f1384257 15438#endif /* TARGET_XCOFF */
0e5dbd9b 15439
f1384257
AM
15440#if TARGET_MACHO
15441/* Cross-module name binding. Darwin does not support overriding
7f3d8013 15442 functions at dynamic-link time. */
0e5dbd9b 15443
2bcc50d0 15444static bool
a2369ed3 15445rs6000_binds_local_p (tree decl)
0e5dbd9b 15446{
f1384257 15447 return default_binds_local_p_1 (decl, 0);
0e5dbd9b 15448}
f1384257 15449#endif
34bb030a 15450
3c50106f
RH
15451/* Compute a (partial) cost for rtx X. Return true if the complete
15452 cost has been computed, and false if subexpressions should be
15453 scanned. In either case, *TOTAL contains the cost result. */
15454
15455static bool
a2369ed3
DJ
15456rs6000_rtx_costs (rtx x, int code, int outer_code ATTRIBUTE_UNUSED,
15457 int *total)
3c50106f
RH
15458{
15459 switch (code)
15460 {
15461 /* On the RS/6000, if it is valid in the insn, it is free.
15462 So this always returns 0. */
15463 case CONST_INT:
15464 case CONST:
15465 case LABEL_REF:
15466 case SYMBOL_REF:
15467 case CONST_DOUBLE:
15468 case HIGH:
15469 *total = 0;
15470 return true;
15471
15472 case PLUS:
15473 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15474 && ((unsigned HOST_WIDE_INT) (INTVAL (XEXP (x, 1))
15475 + 0x8000) >= 0x10000)
15476 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15477 ? COSTS_N_INSNS (2)
15478 : COSTS_N_INSNS (1));
15479 return true;
15480
15481 case AND:
15482 case IOR:
15483 case XOR:
15484 *total = ((GET_CODE (XEXP (x, 1)) == CONST_INT
15485 && (INTVAL (XEXP (x, 1)) & (~ (HOST_WIDE_INT) 0xffff)) != 0
15486 && ((INTVAL (XEXP (x, 1)) & 0xffff) != 0))
15487 ? COSTS_N_INSNS (2)
15488 : COSTS_N_INSNS (1));
15489 return true;
15490
15491 case MULT:
15492 if (optimize_size)
15493 {
15494 *total = COSTS_N_INSNS (2);
15495 return true;
15496 }
15497 switch (rs6000_cpu)
15498 {
15499 case PROCESSOR_RIOS1:
15500 case PROCESSOR_PPC405:
15501 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15502 ? COSTS_N_INSNS (5)
15503 : (INTVAL (XEXP (x, 1)) >= -256
15504 && INTVAL (XEXP (x, 1)) <= 255)
15505 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15506 return true;
15507
02ca7595
DE
15508 case PROCESSOR_PPC440:
15509 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15510 ? COSTS_N_INSNS (3)
15511 : COSTS_N_INSNS (2));
15512 return true;
15513
3c50106f
RH
15514 case PROCESSOR_RS64A:
15515 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15516 ? GET_MODE (XEXP (x, 1)) != DImode
15517 ? COSTS_N_INSNS (20) : COSTS_N_INSNS (34)
15518 : (INTVAL (XEXP (x, 1)) >= -256
15519 && INTVAL (XEXP (x, 1)) <= 255)
15520 ? COSTS_N_INSNS (8) : COSTS_N_INSNS (12));
15521 return true;
15522
15523 case PROCESSOR_RIOS2:
15524 case PROCESSOR_MPCCORE:
15525 case PROCESSOR_PPC604e:
15526 *total = COSTS_N_INSNS (2);
15527 return true;
15528
15529 case PROCESSOR_PPC601:
15530 *total = COSTS_N_INSNS (5);
15531 return true;
15532
15533 case PROCESSOR_PPC603:
15534 case PROCESSOR_PPC7400:
15535 case PROCESSOR_PPC750:
15536 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15537 ? COSTS_N_INSNS (5)
15538 : (INTVAL (XEXP (x, 1)) >= -256
15539 && INTVAL (XEXP (x, 1)) <= 255)
15540 ? COSTS_N_INSNS (2) : COSTS_N_INSNS (3));
15541 return true;
15542
15543 case PROCESSOR_PPC7450:
15544 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15545 ? COSTS_N_INSNS (4)
15546 : COSTS_N_INSNS (3));
15547 return true;
15548
15549 case PROCESSOR_PPC403:
15550 case PROCESSOR_PPC604:
15551 case PROCESSOR_PPC8540:
15552 *total = COSTS_N_INSNS (4);
15553 return true;
15554
15555 case PROCESSOR_PPC620:
15556 case PROCESSOR_PPC630:
3c50106f
RH
15557 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15558 ? GET_MODE (XEXP (x, 1)) != DImode
15559 ? COSTS_N_INSNS (5) : COSTS_N_INSNS (7)
15560 : (INTVAL (XEXP (x, 1)) >= -256
15561 && INTVAL (XEXP (x, 1)) <= 255)
15562 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4));
15563 return true;
15564
9259f3b0
DE
15565 case PROCESSOR_POWER4:
15566 *total = (GET_CODE (XEXP (x, 1)) != CONST_INT
15567 ? GET_MODE (XEXP (x, 1)) != DImode
984e25ac
DE
15568 ? COSTS_N_INSNS (3) : COSTS_N_INSNS (4)
15569 : COSTS_N_INSNS (2));
9259f3b0
DE
15570 return true;
15571
3c50106f
RH
15572 default:
15573 abort ();
15574 }
15575
15576 case DIV:
15577 case MOD:
15578 if (GET_CODE (XEXP (x, 1)) == CONST_INT
15579 && exact_log2 (INTVAL (XEXP (x, 1))) >= 0)
15580 {
15581 *total = COSTS_N_INSNS (2);
15582 return true;
15583 }
59b9a953 15584 /* Fall through. */
3c50106f
RH
15585
15586 case UDIV:
15587 case UMOD:
15588 switch (rs6000_cpu)
15589 {
15590 case PROCESSOR_RIOS1:
15591 *total = COSTS_N_INSNS (19);
15592 return true;
15593
15594 case PROCESSOR_RIOS2:
15595 *total = COSTS_N_INSNS (13);
15596 return true;
15597
15598 case PROCESSOR_RS64A:
15599 *total = (GET_MODE (XEXP (x, 1)) != DImode
15600 ? COSTS_N_INSNS (65)
15601 : COSTS_N_INSNS (67));
15602 return true;
15603
15604 case PROCESSOR_MPCCORE:
15605 *total = COSTS_N_INSNS (6);
15606 return true;
15607
15608 case PROCESSOR_PPC403:
15609 *total = COSTS_N_INSNS (33);
15610 return true;
15611
15612 case PROCESSOR_PPC405:
15613 *total = COSTS_N_INSNS (35);
15614 return true;
15615
02ca7595
DE
15616 case PROCESSOR_PPC440:
15617 *total = COSTS_N_INSNS (34);
15618 return true;
15619
3c50106f
RH
15620 case PROCESSOR_PPC601:
15621 *total = COSTS_N_INSNS (36);
15622 return true;
15623
15624 case PROCESSOR_PPC603:
15625 *total = COSTS_N_INSNS (37);
15626 return true;
15627
15628 case PROCESSOR_PPC604:
15629 case PROCESSOR_PPC604e:
15630 *total = COSTS_N_INSNS (20);
15631 return true;
15632
15633 case PROCESSOR_PPC620:
15634 case PROCESSOR_PPC630:
3c50106f
RH
15635 *total = (GET_MODE (XEXP (x, 1)) != DImode
15636 ? COSTS_N_INSNS (21)
15637 : COSTS_N_INSNS (37));
15638 return true;
15639
15640 case PROCESSOR_PPC750:
15641 case PROCESSOR_PPC8540:
15642 case PROCESSOR_PPC7400:
15643 *total = COSTS_N_INSNS (19);
15644 return true;
15645
15646 case PROCESSOR_PPC7450:
15647 *total = COSTS_N_INSNS (23);
15648 return true;
984e25ac
DE
15649
15650 case PROCESSOR_POWER4:
15651 *total = (GET_MODE (XEXP (x, 1)) != DImode
15652 ? COSTS_N_INSNS (18)
15653 : COSTS_N_INSNS (34));
15654 return true;
3c50106f
RH
15655
15656 default:
15657 abort ();
15658 }
15659
15660 case FFS:
15661 *total = COSTS_N_INSNS (4);
15662 return true;
15663
15664 case MEM:
a3c9585f 15665 /* MEM should be slightly more expensive than (plus (reg) (const)). */
3c50106f
RH
15666 *total = 5;
15667 return true;
15668
15669 default:
15670 return false;
15671 }
15672}
15673
34bb030a
DE
15674/* A C expression returning the cost of moving data from a register of class
15675 CLASS1 to one of CLASS2. */
15676
15677int
a2369ed3
DJ
15678rs6000_register_move_cost (enum machine_mode mode,
15679 enum reg_class from, enum reg_class to)
34bb030a
DE
15680{
15681 /* Moves from/to GENERAL_REGS. */
15682 if (reg_classes_intersect_p (to, GENERAL_REGS)
15683 || reg_classes_intersect_p (from, GENERAL_REGS))
15684 {
15685 if (! reg_classes_intersect_p (to, GENERAL_REGS))
15686 from = to;
15687
15688 if (from == FLOAT_REGS || from == ALTIVEC_REGS)
15689 return (rs6000_memory_move_cost (mode, from, 0)
15690 + rs6000_memory_move_cost (mode, GENERAL_REGS, 0));
15691
a3c9585f 15692/* It's more expensive to move CR_REGS than CR0_REGS because of the shift.... */
34bb030a
DE
15693 else if (from == CR_REGS)
15694 return 4;
15695
15696 else
15697/* A move will cost one instruction per GPR moved. */
15698 return 2 * HARD_REGNO_NREGS (0, mode);
15699 }
15700
15701/* Moving between two similar registers is just one instruction. */
15702 else if (reg_classes_intersect_p (to, from))
15703 return mode == TFmode ? 4 : 2;
15704
15705/* Everything else has to go through GENERAL_REGS. */
15706 else
15707 return (rs6000_register_move_cost (mode, GENERAL_REGS, to)
15708 + rs6000_register_move_cost (mode, from, GENERAL_REGS));
15709}
15710
15711/* A C expressions returning the cost of moving data of MODE from a register to
15712 or from memory. */
15713
15714int
a2369ed3
DJ
15715rs6000_memory_move_cost (enum machine_mode mode, enum reg_class class,
15716 int in ATTRIBUTE_UNUSED)
34bb030a
DE
15717{
15718 if (reg_classes_intersect_p (class, GENERAL_REGS))
15719 return 4 * HARD_REGNO_NREGS (0, mode);
15720 else if (reg_classes_intersect_p (class, FLOAT_REGS))
15721 return 4 * HARD_REGNO_NREGS (32, mode);
15722 else if (reg_classes_intersect_p (class, ALTIVEC_REGS))
15723 return 4 * HARD_REGNO_NREGS (FIRST_ALTIVEC_REGNO, mode);
15724 else
15725 return 4 + rs6000_register_move_cost (mode, class, GENERAL_REGS);
15726}
15727
ded9bf77
AH
15728/* Return an RTX representing where to find the function value of a
15729 function returning MODE. */
15730static rtx
15731rs6000_complex_function_value (enum machine_mode mode)
15732{
15733 unsigned int regno;
15734 rtx r1, r2;
15735 enum machine_mode inner = GET_MODE_INNER (mode);
15736
15737 if (FLOAT_MODE_P (mode))
15738 regno = FP_ARG_RETURN;
15739 else
15740 {
15741 regno = GP_ARG_RETURN;
15742
15743 /* 32-bit is OK since it'll go in r3/r4. */
165848da
AH
15744 if (TARGET_32BIT
15745 && GET_MODE_BITSIZE (inner) >= 32)
ded9bf77
AH
15746 return gen_rtx_REG (mode, regno);
15747 }
15748
15749 r1 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno),
15750 const0_rtx);
15751 r2 = gen_rtx_EXPR_LIST (inner, gen_rtx_REG (inner, regno + 1),
15752 GEN_INT (GET_MODE_UNIT_SIZE (inner)));
15753 return gen_rtx_PARALLEL (mode, gen_rtvec (2, r1, r2));
15754}
15755
a6ebc39a
AH
15756/* Define how to find the value returned by a function.
15757 VALTYPE is the data type of the value (as a tree).
15758 If the precise function being called is known, FUNC is its FUNCTION_DECL;
15759 otherwise, FUNC is 0.
15760
15761 On the SPE, both FPs and vectors are returned in r3.
15762
15763 On RS/6000 an integer value is in r3 and a floating-point value is in
15764 fp1, unless -msoft-float. */
15765
15766rtx
15767rs6000_function_value (tree valtype, tree func ATTRIBUTE_UNUSED)
15768{
15769 enum machine_mode mode;
2a8fa26c 15770 unsigned int regno;
a6ebc39a 15771
0e67400a
FJ
15772 if (TARGET_32BIT && TARGET_POWERPC64 && TYPE_MODE (valtype) == DImode)
15773 {
15774 /* Long long return value need be split in -mpowerpc64, 32bit ABI. */
15775 return gen_rtx_PARALLEL (DImode,
15776 gen_rtvec (2,
15777 gen_rtx_EXPR_LIST (VOIDmode,
15778 gen_rtx_REG (SImode, GP_ARG_RETURN),
15779 const0_rtx),
15780 gen_rtx_EXPR_LIST (VOIDmode,
15781 gen_rtx_REG (SImode,
15782 GP_ARG_RETURN + 1),
15783 GEN_INT (4))));
15784 }
15785
a6ebc39a
AH
15786 if ((INTEGRAL_TYPE_P (valtype)
15787 && TYPE_PRECISION (valtype) < BITS_PER_WORD)
15788 || POINTER_TYPE_P (valtype))
b78d48dd 15789 mode = TARGET_32BIT ? SImode : DImode;
a6ebc39a
AH
15790 else
15791 mode = TYPE_MODE (valtype);
15792
2a8fa26c
DE
15793 if (TREE_CODE (valtype) == REAL_TYPE && TARGET_HARD_FLOAT && TARGET_FPRS)
15794 regno = FP_ARG_RETURN;
ded9bf77
AH
15795 else if (TREE_CODE (valtype) == COMPLEX_TYPE
15796 && TARGET_HARD_FLOAT
15797 && SPLIT_COMPLEX_ARGS)
15798 return rs6000_complex_function_value (mode);
2a8fa26c 15799 else if (TREE_CODE (valtype) == VECTOR_TYPE && TARGET_ALTIVEC)
a6ebc39a
AH
15800 regno = ALTIVEC_ARG_RETURN;
15801 else
15802 regno = GP_ARG_RETURN;
15803
15804 return gen_rtx_REG (mode, regno);
15805}
15806
ded9bf77
AH
15807/* Define how to find the value returned by a library function
15808 assuming the value has mode MODE. */
15809rtx
15810rs6000_libcall_value (enum machine_mode mode)
15811{
15812 unsigned int regno;
15813
15814 if (GET_MODE_CLASS (mode) == MODE_FLOAT
15815 && TARGET_HARD_FLOAT && TARGET_FPRS)
15816 regno = FP_ARG_RETURN;
15817 else if (ALTIVEC_VECTOR_MODE (mode))
15818 regno = ALTIVEC_ARG_RETURN;
15819 else if (COMPLEX_MODE_P (mode) && SPLIT_COMPLEX_ARGS)
15820 return rs6000_complex_function_value (mode);
15821 else
15822 regno = GP_ARG_RETURN;
15823
15824 return gen_rtx_REG (mode, regno);
15825}
15826
d1d0c603
JJ
15827/* Define the offset between two registers, FROM to be eliminated and its
15828 replacement TO, at the start of a routine. */
15829HOST_WIDE_INT
15830rs6000_initial_elimination_offset (int from, int to)
15831{
15832 rs6000_stack_t *info = rs6000_stack_info ();
15833 HOST_WIDE_INT offset;
15834
15835 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
15836 offset = info->push_p ? 0 : -info->total_size;
15837 else if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
15838 offset = info->total_size;
15839 else if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
15840 offset = info->push_p ? info->total_size : 0;
15841 else if (from == RS6000_PIC_OFFSET_TABLE_REGNUM)
15842 offset = 0;
15843 else
15844 abort ();
15845
15846 return offset;
15847}
15848
62e1dfcf
NC
15849/* Return true if TYPE is of type __ev64_opaque__. */
15850
c8e4f0e9 15851static bool
a2369ed3 15852is_ev64_opaque_type (tree type)
62e1dfcf 15853{
c8e4f0e9 15854 return (TARGET_SPE
2abe3e28
AH
15855 && (type == opaque_V2SI_type_node
15856 || type == opaque_V2SF_type_node
36252949 15857 || type == opaque_p_V2SI_type_node));
62e1dfcf
NC
15858}
15859
96714395 15860static rtx
a2369ed3 15861rs6000_dwarf_register_span (rtx reg)
96714395
AH
15862{
15863 unsigned regno;
15864
15865 if (!TARGET_SPE || !SPE_VECTOR_MODE (GET_MODE (reg)))
15866 return NULL_RTX;
15867
15868 regno = REGNO (reg);
15869
15870 /* The duality of the SPE register size wreaks all kinds of havoc.
15871 This is a way of distinguishing r0 in 32-bits from r0 in
15872 64-bits. */
15873 return
15874 gen_rtx_PARALLEL (VOIDmode,
3bd104d1
AH
15875 BYTES_BIG_ENDIAN
15876 ? gen_rtvec (2,
15877 gen_rtx_REG (SImode, regno + 1200),
15878 gen_rtx_REG (SImode, regno))
15879 : gen_rtvec (2,
15880 gen_rtx_REG (SImode, regno),
15881 gen_rtx_REG (SImode, regno + 1200)));
96714395
AH
15882}
15883
93c9d1ba
AM
15884/* Map internal gcc register numbers to DWARF2 register numbers. */
15885
15886unsigned int
15887rs6000_dbx_register_number (unsigned int regno)
15888{
15889 if (regno <= 63 || write_symbols != DWARF2_DEBUG)
15890 return regno;
15891 if (regno == MQ_REGNO)
15892 return 100;
15893 if (regno == LINK_REGISTER_REGNUM)
15894 return 108;
15895 if (regno == COUNT_REGISTER_REGNUM)
15896 return 109;
15897 if (CR_REGNO_P (regno))
15898 return regno - CR0_REGNO + 86;
15899 if (regno == XER_REGNO)
15900 return 101;
15901 if (ALTIVEC_REGNO_P (regno))
15902 return regno - FIRST_ALTIVEC_REGNO + 1124;
15903 if (regno == VRSAVE_REGNO)
15904 return 356;
15905 if (regno == VSCR_REGNO)
15906 return 67;
15907 if (regno == SPE_ACC_REGNO)
15908 return 99;
15909 if (regno == SPEFSCR_REGNO)
15910 return 612;
15911 /* SPE high reg number. We get these values of regno from
15912 rs6000_dwarf_register_span. */
15913 if (regno >= 1200 && regno < 1232)
15914 return regno;
15915
15916 abort ();
15917}
15918
17211ab5 15919#include "gt-rs6000.h"